當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。