本文整理汇总了TypeScript中joi.array函数的典型用法代码示例。如果您正苦于以下问题:TypeScript array函数的具体用法?TypeScript array怎么用?TypeScript array使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
import * as Joi from 'joi'
import { PluginRegister } from '../../../hapi.types'
import addTeamMembers from './add-team-members'
import deleteTeamMembers from './delete-team-members'
import getTeamMembers from './get-team-members'
const multipleMembersSchema = Joi.object().keys({
data: Joi.array().items(
Joi.object().keys({
id: Joi.string(),
type: Joi.only('users'),
}),
),
})
const register: PluginRegister = (server, _, next) => {
server.route([
{
method: 'POST',
path: '/teams/{teamId}/members',
handler: {
async: addTeamMembers,
},
config: {
auth: 'attendee',
validate: {
params: {
teamId: Joi.string(),
},
payload: multipleMembersSchema,
示例2:
export let label = Joi.object({
name: Joi.string().regex(regex.nameUTF).required(),
version: Joi.string().allow(null).regex(regex.semverC).description('semver').optional()
}).description('label');
export let project = Joi.object({
url: Joi.string().regex(regex.uri).required()
}).description('project');
export let person = Joi.object({
name: Joi.string().regex(regex.nameUTF).required(),
url: Joi.string().allow(null).regex(regex.uri).optional().default(null)
}).description('person');
export let repository = Joi.object({
// use default?
url: Joi.string().regex(regex.uri).required()
}).description('repository');
export let header = Joi.object({
label: label.required(),
project: Joi.array().min(1).items(project).required(),
repository: repository.required(),
authors: Joi.array().min(1).items(person).required()
}).description('definition-header').options({
allowUnknown: true,
stripUnknown: true,
convert: false
});
示例3:
// NOTE: 考虑是否增加第三方模块的配置检查
'plugins': Joi.object().pattern(
Joi.string(), Joi.object()
),
'env': Joi.object().pattern(
Joi.string(), Joi.string()
),
'defineConstants': Joi.object().pattern(
Joi.string(), Joi.string()
),
'copy': Joi.object().keys({
'patterns': Joi.array().items(Joi.object().keys({
'from': Joi.string().required(),
'to': Joi.string().required(),
'ignore': Joi.string()
})),
'options': Joi.object().keys({
'ignore': Joi.array().items(Joi.string())
})
}),
'weapp': Joi.object().keys({
'compile': Joi.object().keys({
'exclude': Joi.array().items(Joi.string())
}),
'module': Joi.object() // 第三方配置
示例4:
export const BotEditSchema = Joi.object().keys({
name: Joi.string()
.allow('')
.max(50),
// tslint:disable-next-line:no-null-keyword
category: Joi.string().allow(null),
description: Joi.string()
.max(250)
.allow(''),
disabled: Joi.bool(),
private: Joi.bool(),
defaultLanguage: Joi.string()
.min(2)
.max(3),
languages: Joi.array().items(
Joi.string()
.min(2)
.max(3)
),
details: {
website: Joi.string()
.uri()
.optional()
.allow(''),
termsConditions: Joi.string()
.uri()
.optional()
.allow(''),
privacyPolicy: Joi.string()
.uri()
示例5: resolve
Joi.object()
.keys({
pathname: Joi.string().regex(/^\//, 'start with a /'),
hash: Joi.string().regex(/^\//, 'start with a /'),
})
.default();
const defaultRelativeToConfigPath = (path: string) => {
const makeDefault: any = (_: any, options: any) => resolve(dirname(options.context.path), path);
makeDefault.description = `<config.js directory>/${path}`;
return makeDefault;
};
export const schema = Joi.object()
.keys({
testFiles: Joi.array()
.items(Joi.string())
.when('$primary', {
is: true,
then: Joi.required(),
otherwise: Joi.any().default([]),
}),
excludeTestFiles: Joi.array()
.items(Joi.string())
.default([]),
suiteTags: Joi.object()
.keys({
include: Joi.array()
.items(Joi.string())
示例6:
import Joi from 'joi'
export const ID_REGEX = /^[a-zA-Z0-9]+[A-Z0-9_-]{2,}$/i
export const SlotsCreateSchema = Joi.object().keys({
name: Joi.string().required(),
// @deprecated >11
entity: Joi.string().optional(),
entities: Joi.array()
.items(Joi.string())
.required(),
color: Joi.number().required(),
id: Joi.string().required()
})
export const IntentDefCreateSchema = Joi.object().keys({
name: Joi.string().required(),
utterances: Joi.array()
.items(Joi.string())
.default([]),
slots: Joi.array()
.items(SlotsCreateSchema)
.default([]),
contexts: Joi.array()
.items(Joi.string())
.default(['global'])
})
const EntityDefOccurenceSchema = Joi.object().keys({
name: Joi.string().required(),
synonyms: Joi.array().items(Joi.string())
示例7: propertyToJoi
function propertyToJoi(property: Property, optional = false) {
let joiRule
switch (property.type) {
case 'action':
joiRule = joi.alternatives([
joi.object({
type: joi
.string()
.required()
.only('call'),
deviceId: joi.string().required(),
interfaceId: joi.string().required(),
method: joi.string().required(),
arguments: joi.object().required(),
}),
joi.object({
type: joi
.string()
.required()
.only('modification'),
deviceId: joi.string().required(),
interfaceId: joi.string().required(),
statusId: joi.string().required(),
value: joi.any().required(),
}),
])
break
case 'array':
joiRule = joi.array().items(propertyToJoi(property.items, true))
break
case 'boolean':
joiRule = joi.boolean()
break
case 'device':
joiRule = joi.string()
break
case 'enum':
joiRule = joi.alternatives(joi.string(), joi.number())
// .only(property.values.map(value => value.value.toString()))
break
case 'modification':
joiRule = joi.object({
deviceId: joi.string().required(),
interfaceId: joi.string().required(),
statusId: joi.string().required(),
value: joi.any().required(),
})
break
case 'integer':
joiRule = joi.number().integer()
// fall through
case 'number':
let numberJoiRule: joi.NumberSchema = joiRule || joi.number()
if (property.min !== undefined) {
numberJoiRule = numberJoiRule.min(property.min)
}
if (property.max !== undefined) {
numberJoiRule = numberJoiRule.max(property.max)
}
joiRule = numberJoiRule
break
case 'string':
joiRule = joi.string()
break
}
if (!property.optional && !optional) {
joiRule = joiRule.required()
}
return joiRule
}
示例8: coerce
'map.value',
{ entryKey, reason: valueError },
state,
options
);
}
result.set(validatedEntryKey, validatedEntryValue);
}
return result as any;
},
},
],
},
{
name: 'array',
base: Joi.array(),
coerce(value: any, state: State, options: ValidationOptions) {
// If value isn't defined, let Joi handle default value if it's defined.
if (value !== undefined && !Array.isArray(value)) {
return this.createError('array.base', { value }, state, options);
}
return value;
},
rules: [anyCustomRule],
},
]) as JoiRoot;
示例9: beats
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import Joi from 'joi';
import { resolve } from 'path';
import { PLUGIN } from './common/constants';
import { CONFIG_PREFIX } from './common/constants/plugin';
import { initServerWithKibana } from './server/kibana.index';
import { KibanaLegacyServer } from './server/lib/adapters/framework/adapter_types';
const DEFAULT_ENROLLMENT_TOKENS_TTL_S = 10 * 60; // 10 minutes
export const config = Joi.object({
enabled: Joi.boolean().default(true),
defaultUserRoles: Joi.array()
.items(Joi.string())
.default(['superuser']),
encryptionKey: Joi.string().default('xpack_beats_default_encryptionKey'),
enrollmentTokensTtlInSeconds: Joi.number()
.integer()
.min(1)
.max(10 * 60 * 14) // No more then 2 weeks for security reasons
.default(DEFAULT_ENROLLMENT_TOKENS_TTL_S),
}).default();
export function beats(kibana: any) {
return new kibana.Plugin({
id: PLUGIN.ID,
require: ['kibana', 'elasticsearch', 'xpack_main'],
publicDir: resolve(__dirname, 'public'),
示例10:
.only('string', 'integer', 'number', 'boolean', 'object')
.required(),
optional: joi.boolean(),
modifiable: joi.boolean(),
})
.when(joi.ref('type'), {
is: 'boolean',
then: joi.object({
defaultValue: joi.boolean(),
}),
})
.when(joi.ref('type'), {
is: 'device',
then: joi.object({
interfaceIds: joi.array().items(joi.string().required()),
deviceClassIds: joi.array().items(joi.string().required()),
}),
})
.when(joi.ref('type'), {
is: 'number',
then: joi.object({
min: joi.number(),
max: joi.number(),
unit: joi.string(),
defaultValue: joi.number(),
}),
})
.when(joi.ref('type'), {
is: 'integer',
then: joi.object({