UNPKG

@snapdm/model

Version:

An opinionated snapshot oriented modeling system for Cloud Firestore

1 lines 25.5 kB
{"version":3,"file":"index.cjs","sources":["../../../packages/model/src/lib/adapter/index.ts","../../../packages/model/src/lib/initialize.ts","../../../packages/model/src/lib/snapshot.ts","../../../packages/model/src/lib/utils/delegate.ts","../../../packages/model/src/lib/utils/merge.ts","../../../packages/model/src/lib/validator.ts","../../../packages/model/src/lib/model.ts","../../../packages/model/src/lib/model-factory.ts"],"sourcesContent":["import { assertIsDefined } from '@snapdm/preconditions';\nimport { FieldValueFactory } from './field-values';\nimport { IdFactory } from './ids';\nimport { ReferenceFactory } from './references';\nimport { TimestampFactory } from './timestamps';\n\nexport type Adapter = Readonly<{\n /**\n * The IdGenerator to use when\n */\n ids: IdFactory;\n fieldValues: FieldValueFactory;\n timestamps: TimestampFactory;\n references: ReferenceFactory;\n}>;\n\nlet __adapter: Adapter | undefined;\n\nexport function adapter(): Adapter {\n assertIsDefined(\n __adapter,\n \"Adapter not set. Call 'initialize' before creating models.\"\n );\n return __adapter;\n}\n\nexport function setAdapter(adapter: Adapter): void {\n __adapter = adapter;\n}\n","import { Adapter, setAdapter } from './adapter';\n\nexport interface SnapdmOptions {\n readonly adapter: Adapter;\n}\n\nexport function initialize(options: SnapdmOptions): void {\n setAdapter(options.adapter);\n}\n","import { Timestamp } from './adapter/timestamps';\nimport type { DeepPartial } from 'ts-essentials';\nimport { DocumentReference } from './adapter/references';\n\nexport type SnapshotData = object;\n\ntype SnapshotAttributes<T extends SnapshotData = SnapshotData> = Readonly<{\n type: string;\n id: string;\n ref: DocumentReference<Snapshot<T>>;\n createdAt: Timestamp;\n updatedAt: Timestamp;\n}>;\n\n/**\n * A document snapshot model.\n */\nexport type Snapshot<T extends SnapshotData = SnapshotData> =\n SnapshotAttributes<T> & T;\n\nexport function isSnapshot<T extends Snapshot>(value: unknown): value is T {\n const v = value as Partial<Snapshot>;\n return (\n typeof v.type === 'string' &&\n typeof v.id === 'string' &&\n typeof v.ref !== 'undefined' &&\n typeof v.createdAt !== 'undefined' &&\n typeof v.updatedAt !== 'undefined'\n );\n}\n\nexport type SnapshotUpdates<Data = SnapshotData> = {\n readonly updatedAt: Timestamp;\n} & DeepPartial<Data>;\n","export function delegate<T extends object>(\n target: T,\n delegateProperty: string\n): T {\n return new Proxy(target, {\n get: (t, p) => {\n const prop = coerceToString(p);\n if (p in t) {\n return t[prop];\n }\n return applyInScope(t[delegateProperty][prop], (thisArg) =>\n thisArg === t ? t[delegateProperty] : thisArg\n );\n },\n });\n}\n\nfunction applyInScope(value: unknown, scope: (thisArg: any) => any) {\n if (typeof value === 'function') {\n return new Proxy(value, {\n apply: (f, thisArg, args) => {\n return f.apply(scope(thisArg), args);\n },\n });\n }\n return value;\n}\n\nfunction coerceToString(p: string | symbol): string {\n return typeof p === 'string' ? p : p.toString();\n}\n","import __mergeWith from 'lodash/mergeWith';\n\nexport function merge<T1, T2>(t1: T1, t2: T2): T1 & T2;\nexport function merge<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 & T2 & T3;\nexport function merge<T1, T2, T3, T4>(\n t1: T1,\n t2: T2,\n t3: T3,\n t4: T4\n): T1 & T2 & T3 & T4;\nexport function merge(...sources: unknown[]): unknown {\n return __mergeWith({}, ...sources, (obj: unknown, val: unknown) =>\n Array.isArray(obj) ? val : undefined\n );\n}\n","/**\n * An object containing error keys and reasons.\n */\nexport type ValidationErrors = Record<string, any>\n\n/**\n * A validator is a function that takes a value and return null if that value\n * is valid, or an object containing error keys and reasons.\n */\nexport type Validator<T> = (value: T) => ValidationErrors | null\n\n/**\n * Combine the list of validators into a single validator.\n * @param validators List of validators to combine.\n * @returns A single validator applying all the passed in validation.\n */\nexport function combine<T>(validators: Validator<T>[]): Validator<T> {\n return value => validators.reduce((res, next) => {\n const errors = next(value)\n if(errors) {\n return res ? {...res, ...errors} : errors;\n }\n return res\n }, null as ValidationErrors | null)\n}\n","import {\n Snapshot,\n SnapshotData,\n SnapshotUpdates,\n isSnapshot,\n} from './snapshot';\nimport {\n isUndefined,\n assertIsDefined,\n isDefined,\n assert,\n} from '@snapdm/preconditions';\nimport { adapter } from './adapter';\nimport { delegate } from './utils/delegate';\nimport { DocumentReference } from './adapter/references';\nimport { Timestamp } from './adapter/timestamps';\nimport { DeepPartial } from 'ts-essentials';\nimport { merge } from './utils/merge';\nimport { combine, Validator } from './validator';\n\ntype Type<T> = new (...args: any[]) => T;\n\ntype AbstractType<T> = abstract new (...args: any[]) => T;\n\ntype AnyType<T> = Type<T> | AbstractType<T>;\n\ntype ModelIdentifiers = 'type' | 'id' | 'ref';\n\ntype ModelImmutableAttributes = ModelIdentifiers | 'createdAt' | 'updatedAt';\n\nexport type ModelAttributes<Data extends SnapshotData> = Omit<\n Data,\n ModelImmutableAttributes\n>;\n\ntype ModelClassAttributes = Readonly<{\n type?: string;\n collection: string;\n}>;\n\ntype ModelParent<Data extends SnapshotData> = Readonly<{\n // TODO: See if this can be more specific. The additional props are just a soft validation.\n model: Type<AnyModel> & ModelClassAttributes & Readonly<{ parent?: any }>;\n attribute: keyof ModelAttributes<Data>;\n}>;\n\nexport type InitializeFunction<Data extends SnapshotData, Initializer> = (\n init: Initializer\n) => ModelInit<Data>;\n\nexport type LazyInitializeFunction<Data extends SnapshotData> =\n () => ModelInit<Data>;\n\nexport type InitializeFunctionWithBase<\n Base extends RootModel & AnyModel,\n Data extends ModelData<Base>,\n Initializer\n > = (init: Initializer) => ModelInit<Data>;\n\nexport type ModelOptions<\n Data extends SnapshotData,\n Initializer\n > = ModelClassAttributes &\n Readonly<{\n /**\n * Metadata about this model's parent.\n */\n parent?: ModelParent<Data>;\n\n /**\n * An initializing function that converts a model's initializer into\n * its internal data. This method is where data defaults should be\n * set.\n */\n initialize?: InitializeFunction<Data, Initializer>;\n\n /**\n * An optional list of validators to apply to the model's snapshot\n * before writing it to the database.\n */\n validators?: Validator<Data>[];\n }>;\n\ntype ModelData<T extends RootModel & AnyModel> = Omit<\n T['snapshot'],\n ModelImmutableAttributes\n>;\n\ntype ModelWithBaseOptions<\n Base extends RootModel & AnyModel,\n Data extends ModelData<Base>,\n Initializer\n > = Readonly<{\n type?: string;\n /**\n * An initializing function that converts a model's initializer into\n * its internal data. This method is where data defaults should be\n * set.\n */\n initialize?: InitializeFunctionWithBase<Base, Data, Initializer>;\n\n /**\n * An optional list of validators to apply to the model's snapshot\n * before writing it to the database.\n */\n validators?: Validator<Data>[];\n }>;\n\nexport type ExtendedModelOptions<\n Base extends RootModel & AnyModel,\n Data extends ModelData<Base>,\n Initializer\n > = Readonly<{\n extends: AnyType<Base>;\n }> &\n ModelWithBaseOptions<Base, Data, Initializer>;\n\nfunction isExtendModelOptions<\n Base extends AnyModel,\n Data extends ModelData<Base>,\n Initializer\n>(value: unknown): value is ExtendedModelOptions<Base, Data, Initializer> {\n const v = value as Partial<ExtendedModelOptions<Base, Data, Initializer>>;\n return typeof v.extends === 'function';\n}\n\n/**\n * A type that accurately represents the interface of typeof AnyModel.\n */\nexport type ModelClass<T extends AnyModel> = Type<T> &\n Exclude<ModelOptions<T['snapshot'], any>, 'validators'> &\n Readonly<{\n validator: Validator<T['snapshot']>;\n }>;\n\nexport type AnyModelClass<T extends AnyModel> = AnyType<T> &\n Exclude<ModelOptions<T['snapshot'], any>, 'validators'> &\n Readonly<{\n validator: Validator<T['snapshot']>;\n }>;\n\ntype ModelInit<Data extends SnapshotData> = Omit<\n Data,\n ModelImmutableAttributes\n> & {\n type?: string; // should be T[\"type\"] but seems like TS3.9 broke this\n id?: string; // should be T[\"id\"] but seems like TS3.9 broke this\n};\n\n/**\n * A reference to another model.\n */\nexport type ModelRef<T extends AnyModel> = Readonly<{\n type: string;\n id: string;\n ref: DocumentReference<T['snapshot']>;\n}>;\n\nexport interface AnyModel<Data extends SnapshotData = object> {\n readonly type: string;\n readonly id: string;\n readonly ref: DocumentReference<Snapshot<Data>>;\n readonly createdAt: Timestamp;\n readonly updatedAt: Timestamp;\n readonly snapshot: Snapshot<Data>;\n readonly updates?: SnapshotUpdates<Data>;\n readonly isNew: boolean;\n toRef<Keys extends keyof Data>(\n ...includeAttributes: Keys[]\n ): ModelRef<AnyModel<Data>> & Pick<Data, Keys>;\n}\n\ntype ModelCtrOptions<Data extends SnapshotData> = Readonly<{\n updates?: SnapshotUpdates<Data>;\n isNew?: boolean;\n}>;\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ninterface RootModel extends Snapshot { }\n\nabstract class RootModel {\n constructor(initializer);\n constructor(snapshot, options?);\n constructor(initializer, options?) {\n if (isSnapshot<Snapshot>(initializer)) {\n /* @ts-ignore */\n this.isNew = options?.isNew ?? false;\n /* @ts-ignore */\n this.updates = options?.updates;\n /* @ts-ignore */\n this.snapshot = initializer;\n } else {\n /* @ts-ignore */\n this.isNew = true;\n /* @ts-ignore */\n this.snapshot = newSnapshot(this.constructor, initializer) as any; // TODO: Remove typehack.\n }\n return delegate(this, 'snapshot');\n }\n}\n\n/**\n * Mixin function for creating a new model.\n * @param options The options for configuring this model\n * @returns A model class with the provided options mixed int the class.\n */\nexport function Model<\n Data extends ModelData<Base>,\n Initializer,\n Base extends RootModel & AnyModel = any\n>(\n options:\n | ModelOptions<Data, Initializer>\n | ExtendedModelOptions<Base, Data, Initializer>\n) {\n const { type, initialize, validators } = options;\n let baseClass: typeof RootModel;\n let collection: string;\n let parent: ModelParent<Data> | undefined;\n let validator: Validator<Data>;\n if (isExtendModelOptions(options)) {\n baseClass = options.extends;\n collection = (options.extends as any).collection;\n parent = (options.extends as any).parent;\n const extendValidator = (options.extends as any).validator;\n validator = validators\n ? combine([...validators, extendValidator])\n : extendValidator;\n } else {\n baseClass = RootModel;\n collection = options.collection;\n parent = options.parent;\n validator = validators ? combine(validators) : () => null;\n }\n return class Model extends baseClass implements AnyModel<Data> {\n static readonly type = type;\n static readonly collection = collection;\n static readonly parent = parent;\n static readonly initialize = initialize ?? identity;\n static readonly validator = validator;\n\n constructor(init: Initializer);\n constructor(snapshot: Snapshot<Data>, options?: ModelCtrOptions<Data>);\n constructor(\n init: Snapshot<Data> | Initializer,\n options?: ModelCtrOptions<Data>\n ) {\n super(init, options);\n }\n\n /**\n * Get the current snapshot of the underlying JSON document.\n */\n readonly snapshot: Snapshot<Data>;\n\n /**\n * A flag indicating if this model is new i.e. it was created from\n * and initializer and not a snapshot.\n */\n readonly isNew: boolean;\n\n /**\n * An object containing the differences between this object and\n * the object it was copied from. An entity should only be saved if it\n * isNew or its updates are defined. This object can also be used\n * perform a partial update of the underlying document.\n */\n readonly updates?: SnapshotUpdates<Data>;\n\n /**\n * Meta method for getting the constructor of `this` object to access static\n * methods defined on subclasses, or construct instances of subclasses in\n * the base class.\n */\n readonly model: ModelClass<this> = this.constructor as ModelClass<this>;\n\n /**\n * Convert this model into a reference object.\n * @param includeAttributes Optional fields in this model to include in the reference.\n * @returns A ref to this model.\n */\n toRef<Keys extends keyof this['snapshot']>(\n ...includeAttributes: Keys[]\n ): ModelRef<this> & Pick<this['snapshot'], Keys> {\n // TODO: Remove these escape hatches\n const { type, id, ref } = this.snapshot;\n return includeAttributes\n .map((k) => [k, this.snapshot[k as any]])\n .reduce(\n (o, [k, v]) => {\n o[k] = v;\n return o;\n },\n { type, id, ref } as any\n );\n }\n\n /**\n * Creates a new instance of this Model containing the provided\n * updates to the internal snapshot. This method is not intended to be\n * consumed externally to the class and exists primarily to be used as\n * an implementation detail of more domain oriented transformations.\n * @param updates A patch to apply to the current snapshot in creating\n * the new one.\n * @returns A new model with the given patch applied.\n */\n clone(updates?: DeepPartial<Data>): this {\n // If there we no updates, simply copy the entity.\n if (updates === undefined || Object.keys(updates).length === 0) {\n return new this.model({ ...this.snapshot });\n }\n // In the presence of updates, update the the updatedAt timestamp,\n // and set the correct `updates` on the new entity.\n const computedUpdates = merge(this.updates, updates, {\n updatedAt: adapter().fieldValues.serverTimestamp(),\n });\n const newValue = merge(this.snapshot, computedUpdates);\n const newEntity = new this.model(newValue, {\n updates: computedUpdates,\n isNew: this.isNew,\n });\n return newEntity;\n }\n };\n}\n\nfunction newSnapshot<T extends AnyModel>(\n type: ModelClass<T>,\n init: unknown\n): T['snapshot'] {\n const resource = type.initialize(init);\n if (isUndefined(resource.type)) {\n assertIsDefined(type.type, 'must have modelType defined');\n resource.type = type.type;\n }\n if (isUndefined(resource.id)) {\n resource.id = adapter().ids();\n }\n const now = adapter().fieldValues.serverTimestamp();\n return {\n ...resource,\n ref: adapter().references(\n type.collection,\n resource.id,\n resolveParentRef(type, resource)\n ),\n createdAt: now,\n updatedAt: now,\n } as unknown as T;\n}\n\nfunction resolveParentRef<T extends AnyModel>(\n type: ModelClass<T>,\n init: ModelInit<T['snapshot']>\n): DocumentReference | undefined {\n if (type.parent) {\n const parentRef = init[type.parent.attribute];\n assert(\n isModelRef(parentRef),\n `parent.attribute value '${String(\n type.parent.attribute\n )}' does not point to a ModelRef`\n );\n return parentRef.ref;\n }\n return undefined;\n}\n\nfunction isModelRef(value: unknown): value is ModelRef<AnyModel> {\n const v = value as Partial<ModelRef<AnyModel>>;\n return (\n typeof v.type === 'string' && typeof v.id === 'string' && isDefined(v.ref)\n );\n}\n\nfunction identity<T>(e: T): T {\n return e;\n}\n","import { DocumentData } from './adapter/references';\nimport { AnyModel, AnyModelClass, ModelClass } from './model';\n\nexport type ModelFactory<T extends AnyModel> =\n | ModelClass<T>\n | Readonly<{\n type: AnyModelClass<T>;\n factory: (data: DocumentData) => T;\n }>;\n\nexport function buildModel<T extends AnyModel>(\n factory: ModelFactory<T>,\n data: DocumentData\n): T {\n return isModelClass(factory) ? new factory(data) : factory.factory(data);\n}\n\nfunction isModelClass<T extends AnyModel>(\n factory: ModelFactory<T>\n): factory is ModelClass<T> {\n return typeof factory === 'function';\n}\n"],"names":["assertIsDefined","__mergeWith","__defProp","__getOwnPropSymbols","__hasOwnProp","__propIsEnum","__defNormalProp","__spreadValues","isUndefined","assert","isDefined"],"mappings":";;;;;;;;;;;AACA,IAAI,SAAS,CAAC;AACP,SAAS,OAAO,GAAG;AAC1B,EAAEA,6B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