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


TypeScript defaultModelContext.object方法代码示例

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


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

示例1: getKilnUserAuthMetadata

): (u: string, p: string) => Promise<any> {
  const {userExecutor, usernameField, passwordField, passwordOptions} = getKilnUserAuthMetadata(
    options,
  )
  return async (username: string, password: string) => {
    const user = (await userExecutor.findOne({where: {[usernameField]: username}})) as any
    if (!user) return undefined
    const passwordsMatch = await doPasswordsMatch(password, user[passwordField], passwordOptions)
    if (!passwordsMatch) return undefined
    // TODO: limit returned user fields to just those used by auth grants
    return user
  }
}

// see https://tools.ietf.org/html/rfc6749#section-4.3.1
export const oauthTokenRequestModel: IModel = defaultModelContext.object().children({
  // TODO: handle other grant types
  grant_type: defaultModelContext
    .string()
    .required()
    .enum(['password']),
  username: defaultModelContext.string().required(),
  password: defaultModelContext.string().required(),
})

export const oauthTokenResponseModel: IModel = defaultModelContext.object().children({
  access_token: defaultModelContext.string().required(),
  token_type: defaultModelContext
    .string()
    .required()
    .enum(['bearer']),
开发者ID:patrickhulce,项目名称:klay,代码行数:31,代码来源:oauth.ts

示例2: querifyModel

export function querifyModel(original: IModel, options: IQuerifyOptions): IModel {
  const children: any = {}

  forEach(original.spec.children as IModelChild[], child => {
    const filterKeys: string[] = []

    if (isAllowed(options.allowQueryByEquality, [child.path])) {
      filterKeys.push('$eq', '$ne')
      if (child.model.spec.type === 'string') {
        filterKeys.push('$match')
      }
    }

    if (isAllowed(options.allowQueryByRange, [child.path])) {
      filterKeys.push('$lt', '$gt', '$gte', '$lte')
    }

    if (isAllowed(options.allowQueryByInclusion, [child.path])) {
      filterKeys.push('$in', '$nin')
    }

    // TODO: allow nested querying
    if (!filterKeys.length || !includes(ALLOWED_QUERY_TYPES, child.model.spec.type)) return

    const modelForSwagger = defaultModelContext.create(pick(child.model.spec, ['type', 'format']))
    const valueModel = defaultModelContext.create({
      ...pick(child.model.spec, ['type', 'format', 'max', 'min', 'enum']),
      swagger: {
        alternateModel: modelForSwagger,
        alternateQueryModel: modelForSwagger,
      },
    })

    const filterChildren = filterKeys.map(key => {
      let model = valueModel

      if (key === '$match') {
        model = defaultModelContext.create({type: ModelType.String})
      }

      if (key === '$in' || key === '$nin') {
        model = defaultModelContext
          .create({
            type: ModelType.Array,
            children: valueModel,
            swagger: {
              inline: true,
              alternateQueryModel: defaultModelContext.create({type: ModelType.String}),
            },
          })
          .coerce(vr => (typeof vr.value === 'string' ? vr.setValue(vr.value.split(',')) : vr))
      }

      return {path: key, model}
    })

    const typeName = startCase(child.model.spec.type).replace(/ +/g, '')
    // TODO: add format to name if it changes schema
    const schemaName = `${typeName}Filters`
    children[child.path] = defaultModelContext
      .create({
        type: ModelType.Object,
        strict: true,
        children: filterChildren,
        swagger: {schemaName},
      })
      .coerce(parseQueryFilter)
  })

  return defaultModelContext
    .object()
    .children(children)
    .strict()
}
开发者ID:patrickhulce,项目名称:klay,代码行数:74,代码来源:transform-model.ts


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