本文整理匯總了TypeScript中joi.boolean函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript boolean函數的具體用法?TypeScript boolean怎麽用?TypeScript boolean使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了boolean函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: registerDeprecationLoggingRoutes
export function registerDeprecationLoggingRoutes(server: Legacy.Server) {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
server.route({
path: '/api/upgrade_assistant/deprecation_logging',
method: 'GET',
async handler(request) {
try {
return await getDeprecationLoggingStatus(callWithRequest, request);
} catch (e) {
return Boom.boomify(e, { statusCode: 500 });
}
},
});
server.route({
path: '/api/upgrade_assistant/deprecation_logging',
method: 'PUT',
options: {
validate: {
payload: Joi.object({
isEnabled: Joi.boolean(),
}),
},
},
async handler(request) {
try {
const { isEnabled } = request.payload as { isEnabled: boolean };
return await setDeprecationLogging(callWithRequest, request, isEnabled);
} catch (e) {
return Boom.boomify(e, { statusCode: 500 });
}
},
});
}
示例2: upgradeAssistant
export function upgradeAssistant(kibana: any) {
return new kibana.Plugin({
id: 'upgrade_assistant',
configPrefix: 'xpack.upgrade_assistant',
require: ['elasticsearch'],
uiExports: {
managementSections: ['plugins/upgrade_assistant'],
savedObjectSchemas: {
'upgrade-assistant-reindex-operation': {
isNamespaceAgnostic: true,
},
'upgrade-assistant-telemetry': {
isNamespaceAgnostic: true,
},
},
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
mappings,
},
publicDir: resolve(__dirname, 'public'),
config() {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
init(server: Legacy.Server) {
// Add server routes and initialize the plugin here
initServer(server);
},
});
}
示例3: createUser
export function createUser(req: Request, res: Response, next: NextFunction) {
const schema = Joi.object().keys({
name: Joi.string().min(3).required(),
email: Joi.string().email().required(),
password: Joi.string().required().regex(passwordRegex),
agreeTos: Joi.boolean().only(true).required(),
referral: Joi.string().email().options({
language: {
key: '{{!label}}',
string: {
email: 'Not valid referral code'
}
}
}).label(' ') // Joi does not allow empty label but space is working
});
if (req.body.referral) {
req.body.referral = base64decode(req.body.referral);
}
const result = Joi.validate(req.body, schema, options);
if (result.error) {
return res.status(422).json(result);
} else {
return next();
}
}
示例4: it
it("should annotate the class property", function () {
const metadata = Reflect.getMetadata(WORKING_SCHEMA_KEY, MyClass.prototype);
const expected = {
myProperty: Joi.boolean()
};
assert.deepEqual(metadata, expected);
});
示例5: handler
export const createResolveImportErrorsRoute = (
prereqs: Prerequisites,
server: Hapi.Server,
supportedTypes: string[]
) => ({
path: '/api/saved_objects/_resolve_import_errors',
method: 'POST',
config: {
pre: [prereqs.getSavedObjectsClient],
payload: {
maxBytes: server.config().get('savedObjects.maxImportPayloadBytes'),
output: 'stream',
allow: 'multipart/form-data',
},
validate: {
payload: Joi.object({
file: Joi.object().required(),
retries: Joi.array()
.items(
Joi.object({
type: Joi.string().required(),
id: Joi.string().required(),
overwrite: Joi.boolean().default(false),
replaceReferences: Joi.array()
.items(
Joi.object({
type: Joi.string().required(),
from: Joi.string().required(),
to: Joi.string().required(),
})
)
.default([]),
})
)
.required(),
}).default(),
},
},
async handler(request: ImportRequest) {
const { savedObjectsClient } = request.pre;
const { filename } = request.payload.file.hapi;
const fileExtension = extname(filename).toLowerCase();
if (fileExtension !== '.ndjson') {
return Boom.badRequest(`Invalid file extension ${fileExtension}`);
}
return await resolveImportErrors({
supportedTypes,
savedObjectsClient,
readStream: request.payload.file,
retries: request.payload.retries,
objectLimit: request.server.config().get('savedObjects.maxImportExportSize'),
});
},
});
示例6: handler
export const createExportRoute = (
prereqs: Prerequisites,
server: Hapi.Server,
supportedTypes: string[]
) => ({
path: '/api/saved_objects/_export',
method: 'POST',
config: {
pre: [prereqs.getSavedObjectsClient],
validate: {
payload: Joi.object()
.keys({
type: Joi.array()
.items(Joi.string().valid(supportedTypes))
.single()
.optional(),
objects: Joi.array()
.items({
type: Joi.string()
.valid(supportedTypes)
.required(),
id: Joi.string().required(),
})
.max(server.config().get('savedObjects.maxImportExportSize'))
.optional(),
includeReferencesDeep: Joi.boolean().default(false),
})
.xor('type', 'objects')
.default(),
},
async handler(request: ExportRequest, h: Hapi.ResponseToolkit) {
const { savedObjectsClient } = request.pre;
const docsToExport = await getSortedObjectsForExport({
savedObjectsClient,
types: request.payload.type,
objects: request.payload.objects,
exportSizeLimit: server.config().get('savedObjects.maxImportExportSize'),
includeReferencesDeep: request.payload.includeReferencesDeep,
});
return h
.response(docsToExport.map(doc => stringify(doc)).join('\n'))
.header('Content-Disposition', `attachment; filename="export.ndjson"`)
.header('Content-Type', 'application/ndjson');
},
},
});
示例7: handler
export const createCreateRoute = (prereqs: Prerequisites) => {
return {
path: '/api/saved_objects/{type}/{id?}',
method: 'POST',
options: {
pre: [prereqs.getSavedObjectsClient],
validate: {
query: Joi.object()
.keys({
overwrite: Joi.boolean().default(false),
})
.default(),
params: Joi.object()
.keys({
type: Joi.string().required(),
id: Joi.string(),
})
.required(),
payload: Joi.object({
attributes: Joi.object().required(),
migrationVersion: Joi.object().optional(),
references: Joi.array()
.items(
Joi.object().keys({
name: Joi.string().required(),
type: Joi.string().required(),
id: Joi.string().required(),
})
)
.default([]),
}).required(),
},
handler(request: CreateRequest) {
const { savedObjectsClient } = request.pre;
const { type, id } = request.params;
const { overwrite } = request.query;
const { migrationVersion, references } = request.payload;
const options = { id, overwrite, migrationVersion, references };
return savedObjectsClient.create(type, request.payload.attributes, options);
},
},
};
};
示例8: registerTelemetryRoutes
export function registerTelemetryRoutes(server: UpgradeAssistantTelemetryServer) {
server.route({
path: '/api/upgrade_assistant/telemetry/ui_open',
method: 'PUT',
options: {
validate: {
payload: Joi.object({
overview: Joi.boolean().default(false),
cluster: Joi.boolean().default(false),
indices: Joi.boolean().default(false),
}),
},
},
async handler(request) {
try {
return await upsertUIOpenOption(server, request);
} catch (e) {
return Boom.boomify(e, { statusCode: 500 });
}
},
});
server.route({
path: '/api/upgrade_assistant/telemetry/ui_reindex',
method: 'PUT',
options: {
validate: {
payload: Joi.object({
close: Joi.boolean().default(false),
open: Joi.boolean().default(false),
start: Joi.boolean().default(false),
stop: Joi.boolean().default(false),
}),
},
},
async handler(request) {
try {
return await upsertUIReindexOption(server, request);
} catch (e) {
return Boom.boomify(e, { statusCode: 500 });
}
},
});
}
示例9: handler
export const createImportRoute = (
prereqs: Prerequisites,
server: Hapi.Server,
supportedTypes: string[]
) => ({
path: '/api/saved_objects/_import',
method: 'POST',
config: {
pre: [prereqs.getSavedObjectsClient],
payload: {
maxBytes: server.config().get('savedObjects.maxImportPayloadBytes'),
output: 'stream',
allow: 'multipart/form-data',
},
validate: {
query: Joi.object()
.keys({
overwrite: Joi.boolean().default(false),
})
.default(),
payload: Joi.object({
file: Joi.object().required(),
}).default(),
},
},
async handler(request: ImportRequest, h: Hapi.ResponseToolkit) {
const { savedObjectsClient } = request.pre;
const { filename } = request.payload.file.hapi;
const fileExtension = extname(filename).toLowerCase();
if (fileExtension !== '.ndjson') {
return Boom.badRequest(`Invalid file extension ${fileExtension}`);
}
return await importSavedObjects({
supportedTypes,
savedObjectsClient,
readStream: request.payload.file,
objectLimit: request.server.config().get('savedObjects.maxImportExportSize'),
overwrite: request.query.overwrite,
});
},
});
示例10: upgradeAssistant
export function upgradeAssistant(kibana: any) {
return new kibana.Plugin({
id: 'upgrade_assistant',
require: ['elasticsearch'],
uiExports: {
managementSections: ['plugins/upgrade_assistant'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
},
publicDir: resolve(__dirname, 'public'),
config() {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
init(server: Server) {
// Add server routes and initialize the plugin here
initServer(server);
},
});
}