All files / solid/src model.ts

100% Statements 11/11
100% Branches 2/2
100% Functions 2/2
100% Lines 11/11

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 65 66 67 68 691x                                                                                                   1x 1x 1x 1x 1x 1x 1x                 1x 1x 1x  
import {
  anchor,
  type ImmutableOutput,
  type LinkableSchema,
  type ModelInput,
  type ModelOutput,
  type ObjLike,
  type StateBaseOptions,
  type StateExceptionMap,
} from '@anchorlib/core';
 
/**
 * @deprecated Use 'model()' instead.
 * Creates a reactive model reference based on a schema and initial data.
 *
 * @param schema - The schema defining the structure and validation rules for the model
 * @param init - The initial data for the model
 * @param options - Configuration options for the model state
 * @returns A reactive model output that conforms to the provided schema
 */
export function modelRef<S extends LinkableSchema, T extends ModelInput<S>>(
  schema: S,
  init: T,
  options?: StateBaseOptions
): ModelOutput<S>;
 
/**
 * @deprecated Use 'model()' instead.
 * Creates an immutable reactive model reference based on a schema and initial data.
 *
 * @param schema - The schema defining the structure and validation rules for the model
 * @param init - The initial data for the model
 * @param options - Configuration options with immutable flag set to true
 * @returns An immutable model output that conforms to the provided schema
 */
export function modelRef<S extends LinkableSchema, T extends ModelInput<S>>(
  schema: S,
  init: T,
  options: StateBaseOptions & { immutable: true }
): ImmutableOutput<S>;
 
/**
 * @deprecated Use 'model()' instead.
 * Creates a reactive model reference based on a schema and initial data.
 *
 * @param schema - The schema defining the structure and validation rules for the model
 * @param init - The initial data for the model
 * @param options - Configuration options for the model state
 * @returns A reactive model output that conforms to the provided schema
 */
export function modelRef<S extends LinkableSchema, T extends ModelInput<S>>(
  schema: S,
  init: T,
  options?: StateBaseOptions
) {
  return anchor.model(schema, init, options);
}
 
/**
 * @deprecated Use 'exception()' instead.
 * Creates an exception map for handling errors associated with a state object.
 *
 * @param state - The state object to create exception handlers for
 * @returns A map of exception handlers for the provided state
 */
export function exceptionRef<T extends ObjLike | Array<unknown>>(state: T): StateExceptionMap<T> {
  return anchor.catch(state);
}