All files / src/model instance-lifecycle-services.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                                                                                               
import type { IncludeResolver } from '../associations/include-resolver.ts';
import type { NestedCreator } from '../associations/nested-creator.ts';
import type { SqlCompiler } from '../sql/compile.ts';
import type { InstanceValidator } from '../validation/instance-validator.ts';
import type { AttributeColumns } from './attribute-columns.ts';
import type { DeleteQueryBuilder } from './delete-query-builder.ts';
import type { InsertQueryBuilder } from './insert-query-builder.ts';
import type { ModelRegistry } from './model-registry.ts';
import type { ModelValues } from './model-values.ts';
import type { RowMapper } from './row-mapper.ts';
import type { SelectQueryBuilder } from './select-query-builder.ts';
import type { UpdateQueryBuilder } from './update-query-builder.ts';
 
/**
 * Options of `instance.validate()`.
 *
 * Validation throws `ValidationError` when an attribute is invalid.
 *
 * @see {@link Model.validate}
 *
 * @example
 * ```ts
 * const opts: ValidateOptions = { skip: ['password'], hooks: false };
 * await user.validate(opts);
 * ```
 */
export type ValidateOptions = Readonly<{
  /** Run `beforeValidate` / `afterValidate` / `validationFailed` hooks.
   * @defaultValue true */
  hooks?: boolean;
  /** Attributes to skip. */
  skip?: readonly string[];
  /** Only validate these attributes. */
  fields?: readonly string[];
}>;
 
/** Collaborators of {@link InstanceLifecycle}. */
export type InstanceLifecycleServices = Readonly<{
  /** Model state. */
  registry: ModelRegistry;
  /** Value rules. */
  values: ModelValues;
  /** Row parsing. */
  rows: RowMapper;
  /** Shared column helpers. */
  columns: AttributeColumns;
  /** SELECT builder (`reload`). */
  selects: SelectQueryBuilder;
  /** INSERT builder (`save` of new instances). */
  inserts: InsertQueryBuilder;
  /** UPDATE builder (`save` of loaded instances). */
  updates: UpdateQueryBuilder;
  /** DELETE builder (`destroy`). */
  deletes: DeleteQueryBuilder;
  /** Include tree of nested builds. */
  includes: IncludeResolver;
  /** Nested creation. */
  nested: NestedCreator;
  /** Attribute / model validators. */
  validator: InstanceValidator;
  /** SQL compiler. */
  compiler: SqlCompiler;
}>;