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


TypeScript klay-core.assert类代码示例

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


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

示例1: getPrimaryKeyField

export function getPrimaryKeyField(model: IModel): string {
  const pkConstraint = model.spec.db!.constrain.find(
    constraint => constraint.type === ConstraintType.Primary,
  )!

  assert.ok(pkConstraint, 'missing primary key constraint')
  assert.ok(pkConstraint.properties.length === 1, 'multi-column primary key not supported')
  const propertyPath = pkConstraint.properties[0]
  assert.ok(propertyPath.length === 1, 'primary key cannot be nested')
  return propertyPath[0]
}
开发者ID:patrickhulce,项目名称:klay,代码行数:11,代码来源:constraints.ts

示例2: assertValidCriteria

function assertValidCriteria(criteria: string | ICriteriaDefinition): void {
  if (criteria === '*') return
  assert.ok(
    typeof criteria === 'object' && !Array.isArray(criteria) && Object.keys(criteria).length,
    'invalid criteria',
  )
}
开发者ID:patrickhulce,项目名称:klay,代码行数:7,代码来源:grants.ts

示例3: doPasswordsMatch

export async function doPasswordsMatch(
  plaintext: string,
  hashedPasswordWithSalt: string,
  options: IPasswordOptions,
): Promise<boolean> {
  const [hash, salt] = hashedPasswordWithSalt.split(SALT_DELIMITER)
  assert.ok(hash.length === options.hashedPasswordLength, 'incompatible hash length')
  return hash === (await hashPasswordAsync(plaintext, salt, options))
}
开发者ID:patrickhulce,项目名称:klay,代码行数:9,代码来源:password.ts

示例4: forEachColumn

export function forEachColumn(model: IModel, onEach: ColumnIterator, prefix: string[] = []): void {
  const children = model.spec.children as IModelChild[]
  assert.ok(
    model.spec.type === 'object' && model.spec.strict,
    'can only create datatypes for strict objects',
  )
  assert.ok(children && children.length, 'can only create datatypes for objects with children')

  for (const child of children) {
    const spec = child.model.spec
    const fullPath = prefix.concat(child.path)
    if (spec.type === 'object' && spec.strict) {
      forEachColumn(child.model, onEach, fullPath)
    } else {
      onEach(child.model, fullPath, getFlattenedPath(fullPath))
    }
  }
}
开发者ID:patrickhulce,项目名称:klay,代码行数:18,代码来源:serialization.ts

示例5: async

  return async (req: Request, res: Response, next: NextFunction): Promise<void> => {
    if (!req.grants) return next(new Error('Cannot validate grants without grant middleware'))
    if (!req.grants.userContext) return next(new AuthenticationError())

    try {
      const currentPassword = defaultGetCurrentPassword(req)
      assert.ok(currentPassword, 'did not send current password')

      const isValid = await doPasswordsMatch(
        currentPassword!,
        req.grants.userContext[passwordField],
        passwordOptions,
      )

      assert.ok(isValid, 'current password invalid')
      next()
    } catch (err) {
      next(err)
    }
  }
开发者ID:patrickhulce,项目名称:klay,代码行数:20,代码来源:auth.ts

示例6: hashPassword

export function hashPassword(plaintext: string, salt: string, options: IPasswordOptions): string {
  assert.ok(salt.length === options.saltLength, 'incompatible salt length')

  return crypto
    .pbkdf2Sync(
      plaintext,
      salt + options.secret,
      options.iterations,
      options.hashedPasswordLength / 2,
      options.algorithm,
    )
    .toString('hex')
}
开发者ID:patrickhulce,项目名称:klay,代码行数:13,代码来源:password.ts

示例7:

  const customQueries = customConstraints.map(constraint => {
    assert.ok(constraint.meta.evaluate, 'custom constraint missing evaluation function')

    return constraint.meta!.evaluate!({
      record,
      existing,
      model,
      executor,
      extras,
      event,
      constraint,
    })
  })
开发者ID:patrickhulce,项目名称:klay,代码行数:13,代码来源:constraints.ts

示例8: hashPasswordAsync

export async function hashPasswordAsync(
  plaintext: string,
  salt: string,
  options: IPasswordOptions,
): Promise<string> {
  assert.ok(salt.length === options.saltLength, 'incompatible salt length')

  const hash = await pbkdf2Async(
    plaintext,
    salt + options.secret,
    options.iterations,
    options.hashedPasswordLength / 2,
    options.algorithm,
  )

  return hash.toString('hex')
}
开发者ID:patrickhulce,项目名称:klay,代码行数:17,代码来源:password.ts

示例9: computeAllPermissions

export function computeAllPermissions(permission: string, conf: IAuthConfiguration): string[] {
  const permissions: string[] = []
  const queue = [permission]
  while (queue.length) {
    const permission = queue.shift()!
    const nextpermissions = conf.permissions[permission]
    assert.ok(nextpermissions, `invalid permission: ${permission}`)

    for (const nextpermission of nextpermissions) {
      if (includes(queue, nextpermission) || includes(permissions, nextpermission)) continue
      queue.push(nextpermission)
    }

    permissions.push(permission)
  }

  return permissions
}
开发者ID:patrickhulce,项目名称:klay,代码行数:18,代码来源:grants.ts

示例10: addForeignKeys

export function addForeignKeys(
  modelInProgress: Sequelize.DefineAttributes,
  model: IModel,
  kiln: IKiln,
): void {
  const constraints = model.spec.db!.constrain
  for (const constraint of constraints) {
    if (constraint.type !== ConstraintType.Reference) {
      continue
    }

    assert.ok(constraint.properties.length === 1, 'foreign key must be single field')
    const fkName = getFlattenedPath(constraint.properties[0])
    const fkDefinition = modelInProgress[fkName] as Sequelize.DefineAttributeColumnOptions
    const sqlExecutor = kiln.build<ISQLExecutor>(constraint.meta.referencedModel!, SQL_EXECUTOR)
    fkDefinition.references = {
      key: getPrimaryKeyField(sqlExecutor.kilnModel.model),
      model: sqlExecutor.sequelizeModel,
    }
  }
}
开发者ID:patrickhulce,项目名称:klay,代码行数:21,代码来源:constraints.ts


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