當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript joi.array函數代碼示例

本文整理匯總了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,
開發者ID:TechNottingham,項目名稱:Hack24-API,代碼行數:31,代碼來源:index.ts

示例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
});
開發者ID:DefinitelyTyped,項目名稱:definition-header,代碼行數:29,代碼來源:schema.ts

示例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() // 第三方配置
開發者ID:YangShaoQun,項目名稱:taro,代碼行數:30,代碼來源:configSchema.ts

示例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()
開發者ID:alexsandrocruz,項目名稱:botpress,代碼行數:30,代碼來源:validation.ts

示例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())
開發者ID:elastic,項目名稱:kibana,代碼行數:31,代碼來源:schema.ts

示例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())
開發者ID:alexsandrocruz,項目名稱:botpress,代碼行數:31,代碼來源:validation.ts

示例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
}
開發者ID:Pajn,項目名稱:RAXA,代碼行數:74,代碼來源:validations.ts

示例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;
開發者ID:austec-automation,項目名稱:kibana,代碼行數:30,代碼來源:index.ts

示例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'),
開發者ID:elastic,項目名稱:kibana,代碼行數:31,代碼來源:index.ts

示例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({
開發者ID:Pajn,項目名稱:RAXA,代碼行數:31,代碼來源:validations.ts


注:本文中的joi.array函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。