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


TypeScript defaultModelContext.create方法代碼示例

本文整理匯總了TypeScript中klay-core.defaultModelContext.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript defaultModelContext.create方法的具體用法?TypeScript defaultModelContext.create怎麽用?TypeScript defaultModelContext.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在klay-core.defaultModelContext的用法示例。


在下文中一共展示了defaultModelContext.create方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

    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}
    })
開發者ID:patrickhulce,項目名稱:klay,代碼行數:22,代碼來源:transform-model.ts

示例2: forEach

  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)
  })
開發者ID:patrickhulce,項目名稱:klay,代碼行數:65,代碼來源:transform-model.ts


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