当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript defaultModelContext.array方法代码示例

本文整理汇总了TypeScript中klay-core.defaultModelContext.array方法的典型用法代码示例。如果您正苦于以下问题:TypeScript defaultModelContext.array方法的具体用法?TypeScript defaultModelContext.array怎么用?TypeScript defaultModelContext.array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在klay-core.defaultModelContext的用法示例。


在下文中一共展示了defaultModelContext.array方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

 it('should reference schema from cache', () => {
   const arrayModel = defaultModelContext.array().children(model)
   const cache = new Cache()
   const arraySchema = components.getSchema(arrayModel, cache, 'Users')
   expect(arraySchema).toHaveProperty('$ref', '#/definitions/Users')
   const schema = components.getSchema(model, cache)
   expect(schema).toHaveProperty('$ref', '#/definitions/UsersItem')
 })
开发者ID:patrickhulce,项目名称:klay,代码行数:8,代码来源:components.test.ts

示例2: buildSpecification

export function buildSpecification(kiln: IKiln, router: IRouter, overrides?: Partial<Spec>): Spec {
  const schemaCache = new SwaggerSchemaCache()
  for (const kilnModel of kiln.getModels()) {
    const arrayModel = defaultModelContext.array().children(kilnModel.model)
    getSchema(kilnModel.model, schemaCache, startCase(kilnModel.name))
    getSchema(arrayModel, schemaCache, `${startCase(kilnModel.meta.plural)}List`)
  }

  return {
    swagger: '2.0',
    basePath: '/',
    produces: ['application/json'],
    host: 'localhost',
    schemes: ['http'],
    info: {
      title: 'Title',
      version: 'Version',
    },
    paths: buildPaths(router, schemaCache),
    definitions: schemaCache.getUniqueSchemas(),
    ...overrides,
  }
}
开发者ID:patrickhulce,项目名称:klay,代码行数:23,代码来源:spec.ts

示例3: createValidationMiddleware

export function createValidationMiddleware(
  model: IModel,
  pathInReq: ValidateIn = ValidateIn.Body,
  options: IValidationMiddlewareOptions = {},
): IAnontatedHandler {
  const arrayModel = options.allowedAsList && defaultModelContext.array().children(model)

  return function(req: Request, res: Response, next: NextFunction): void {
    const sourceData = req[pathInReq]
    const validated = req.validated || {}
    const result =
      arrayModel && Array.isArray(sourceData)
        ? arrayModel.validate(sourceData)
        : model.validate(sourceData)
    validated[pathInReq] = result.value
    req.validated = validated

    if (result.conforms) {
      next()
    } else {
      next(result.toError())
    }
  }
}
开发者ID:patrickhulce,项目名称:klay,代码行数:24,代码来源:validation.ts

示例4: getAffectedCriteriaValues

    byList: false,
    idParamName: undefined,
  },
  getAffectedCriteriaValues(model: IKilnModel, options: IActionOptions): GetCriteriaValues {
    return function(req: Request, property: string): AuthCriteriaValue[] {
      const incomingItems: any[] = [].concat(req.validated!.body)
      const existingItems: any[] = [].concat(req.actionTarget)
      return incomingItems.concat(existingItems).map(item => item[property])
    }
  },
  paramsModel(kilnModel: IKilnModel, options: IActionOptions): IModel | undefined {
    return options.byId ? paramifyModel(kilnModel.model, options) : undefined
  },
  bodyModel(kilnModel: IKilnModel, options: IActionOptions): IModel {
    const updateModel = updateifyModel(kilnModel.model)
    const arrayUpdateModel = defaultModelContext
      .array()
      .children(updateModel)
      .required()
      .strict()
    return options.byList ? arrayUpdateModel : updateModel
  },
  handler(
    model: IKilnModel,
    options: IActionOptions,
    executor: IDatabaseExecutor,
  ): IAnontatedHandler {
    if (options.byId && options.byList) {
      throw new Error('Cannot update both byId and byList')
    }

    return function(req: Request, res: Response, next: NextFunction): void {
开发者ID:patrickhulce,项目名称:klay,代码行数:32,代码来源:update.ts

示例5: queryModel

      }
    }

    return {permission, getAffectedCriteriaValues}
  },
  queryModel(model: IKilnModel, options: IActionOptions): undefined {
    return undefined
  },
  paramsModel(model: IKilnModel, options: IActionOptions): undefined {
    return undefined
  },
  bodyModel(model: IKilnModel, options: IActionOptions): undefined {
    return undefined
  },
  responseModel(model: IKilnModel, options: IActionOptions): IModel {
    const arrayModel = defaultModelContext
      .array()
      .children(model.model)
      .required()
      .strict()
    return options.byList ? arrayModel : model.model
  },
  lookupActionTarget(
    kilnModel: IKilnModel,
    options: IActionOptions,
    executor: IDatabaseExecutor,
  ): IAnontatedHandler | undefined {
    const actionType = (this as any).type
    if (!actionTypesWithTarget.has(actionType)) return undefined

    const pkField = options.idParamName || getPrimaryKeyField(kilnModel.model)
    const getPkFromItem = (item: any) => (typeof item === 'object' ? item[pkField] : item)
开发者ID:patrickhulce,项目名称:klay,代码行数:32,代码来源:action.ts

示例6: bodyModel

import {IKilnModel} from 'klay-kiln'

import {creatifyModel} from '../helpers/transform-model'
import {ActionType, IAction, IActionOptions, IAnontatedHandler} from '../typedefs'

import {defaultAction} from './action'

export const upsertAction: IAction = {
  ...defaultAction,
  type: ActionType.Upsert,
  defaultOptions: {
    byList: false,
  },
  bodyModel(kilnModel: IKilnModel, options: IActionOptions): IModel {
    const createModel = creatifyModel(kilnModel.model)
    const arrayCreateModel = defaultModelContext
      .array()
      .children(createModel)
      .required()
      .strict()
    return options.byList ? arrayCreateModel : createModel
  },
  handler(
    model: IKilnModel,
    options: IActionOptions,
    executor: IDatabaseExecutor,
  ): IAnontatedHandler {
    // TODO: properly handle actionTarget and permissions
    return function(req: Request, res: Response, next: NextFunction): void {
      const payload = req.validated!.body
      res.promise = options.byList ? executor.upsertAll(payload) : executor.upsert(payload)
      next()
开发者ID:patrickhulce,项目名称:klay,代码行数:32,代码来源:upsert.ts


注:本文中的klay-core.defaultModelContext.array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。