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


TypeScript klay-core.modelAssertions類代碼示例

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


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

示例1: addModel

  public addModel(kilnModel: IKilnModelInput): IKiln {
    modelAssertions.typeof(kilnModel.name, 'string', 'name')
    modelAssertions.ok(kilnModel.model.isKlayModel, 'model must be a klay model')
    modelAssertions.ok(!this._models.has(kilnModel.name), 'model with same name already exists')

    const meta = {plural: `${kilnModel.name}s`, ...kilnModel.meta}
    this._models.set(kilnModel.name, {...kilnModel, meta, extensions: new Map()})
    return this
  }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:9,代碼來源:kiln.ts

示例2: findModel

export function findModel(model: IModel, pathToModel: string[]): IModel {
  let target = model

  const parts = pathToModel.slice()
  while (parts.length) {
    modelAssertions.typeof(target.spec.children, 'array', 'children')
    const nextPath = parts.shift()
    const found = (target.spec.children as IModelChild[]).find(child => child.path === nextPath)
    modelAssertions.ok(found, `could not find model child ${nextPath}`)
    target = found!.model
  }

  return target
}
開發者ID:patrickhulce,項目名稱:klay,代碼行數:14,代碼來源:helpers.ts

示例3: addExtension

  public addExtension(input: IKilnExtensionInput<any>): IKiln {
    const {modelName, extension, defaultOptions} = input
    modelAssertions.typeof(extension.name, 'string', 'name')
    modelAssertions.typeof(extension.defaultOptions, 'object', 'options')
    modelAssertions.typeof(extension.build, 'function', 'build')

    if (modelName) {
      this._getModelOrThrow(modelName).extensions.set(extension.name, {extension, defaultOptions})
    } else {
      for (const kilnModel of this._models.values()) {
        kilnModel.extensions.set(extension.name, {extension, defaultOptions})
      }
    }

    return this
  }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:16,代碼來源:kiln.ts

示例4: forEach

 forEach(rootModel.spec.db!.automanage, item => {
   if (item.phase === ValidationPhase.Database) return
   if (!eventMatches(item.event, event)) return
   modelAssertions.typeof(item.supplyWith, 'function')
   const model = findModel(rootModel, item.property)
   model.coerce(item.supplyWith as ICoerceFunction, item.phase)
 })
開發者ID:patrickhulce,項目名稱:klay,代碼行數:7,代碼來源:helpers.ts

示例5:

 private _getExtensionInputOrThrow<TResult, TOptions>(
   modelName: string,
   extensionName: string,
 ): IKilnExtensionInput<TResult, TOptions> {
   const extension = this._getExtensionInput<TResult, TOptions>(modelName, extensionName)
   modelAssertions.ok(extension, `unable to find extension "${extensionName}"`)
   return extension!
 }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:8,代碼來源:kiln.ts

示例6: index

  public index(properties: IIndexPropertyInput[]): IDatabaseOptions {
    assertions.typeof(properties, 'array', 'index')
    assertions.ok(properties.length, 'must specify at least 1 property for index')
    properties.forEach((item, i) => {
      properties[i] = DatabaseOptions._determineIndex(item, i)
    })

    this.spec.index.push(properties as IIndexProperty[])
    return this
  }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:10,代碼來源:options.ts

示例7: _determineIndex

  private static _determineIndex(property: IIndexPropertyInput, i: number): IIndexProperty {
    if (Array.isArray(property)) {
      return {property, direction: SortDirection.Ascending}
    }

    assertions.typeof(property, 'object')
    assertions.typeof(property.property, 'array', `index.${i}.property`)
    assertions.oneOf(property.direction, values(SortDirection), `index.${i}.property`)
    return property
  }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:10,代碼來源:options.ts

示例8: automanage

  public automanage(property: IAutomanagePropertyInput): IDatabaseOptions {
    assertions.typeof(property, 'object', 'automanage')
    property.property = property.property || []
    property.phase = property.phase || ValidationPhase.Parse
    property.supplyWith = DatabaseOptions._determineSupplyWith(property.supplyWith)

    assertions.typeof(property.property, 'array', 'automanage.propertyPath')
    assertions.oneOf(property.event, values(DatabaseEvent), 'automanage.event')
    assertions.oneOf(property.phase, values(ValidationPhase), 'automanage.phase')

    this.spec.automanage.push(property as IAutomanageProperty)
    return this
  }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:13,代碼來源:options.ts

示例9: constrain

  public constrain(input: IConstraintInput): IDatabaseOptions {
    assertions.typeof(input, 'object', 'constrain')
    input.properties = input.properties || [[]]
    input.meta = input.meta || {}

    assertions.typeof(input.properties, 'array', 'constrain.propertyPaths')
    assertions.ok(input.properties.length, 'must specify at least 1 property for constrain')
    assertions.oneOf(input.type, values(ConstraintType), 'constrain.type')
    assertions.typeof(input.meta, 'object')

    const constrain = input as IConstraint
    constrain.name = DatabaseOptions.computeConstraintName(constrain)
    constrain.meta = DatabaseOptions.computeMetaProperties(constrain)
    this.spec.constrain.push(constrain)
    return this
  }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:16,代碼來源:options.ts

示例10: _determineSupplyWith

  private static _determineSupplyWith(
    supplyWith: ISupplyWithFunction | SupplyWithPreset,
  ): ISupplyWithFunction | SupplyWithPreset {
    if (supplyWith === SupplyWithPreset.AutoIncrement || typeof supplyWith === 'function') {
      return supplyWith
    }

    const supplyWithFunc = supplyWithPresets[supplyWith]
    assertions.ok(supplyWithFunc, 'invalid automanage supplyWith')
    return supplyWithFunc
  }
開發者ID:patrickhulce,項目名稱:klay,代碼行數:11,代碼來源:options.ts


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