@routier/core 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codegen/blocks.d.ts +17 -1
- package/dist/codegen/handlers/types.d.ts +13 -5
- package/dist/codegen/index.cjs +28 -0
- package/dist/codegen/index.cjs.map +1 -1
- package/dist/codegen/index.js +28 -0
- package/dist/codegen/index.js.map +1 -1
- package/dist/collections/MemoryDataCollection.d.ts +2 -4
- package/dist/collections/index.cjs +127 -15
- package/dist/collections/index.cjs.map +1 -1
- package/dist/collections/index.js +127 -15
- package/dist/collections/index.js.map +1 -1
- package/dist/expressions/index.cjs +226 -4
- package/dist/expressions/index.cjs.map +1 -1
- package/dist/expressions/index.js +228 -5
- package/dist/expressions/index.js.map +1 -1
- package/dist/expressions/parser.d.ts +42 -1
- package/dist/index.cjs +753 -345
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +756 -345
- package/dist/index.js.map +1 -1
- package/dist/plugins/EphemeralDataPlugin.d.ts +8 -0
- package/dist/plugins/index.cjs +566 -49
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.js +566 -48
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/query/QueryOptionsCollection.d.ts +15 -5
- package/dist/plugins/query/index.d.ts +1 -0
- package/dist/plugins/query/renames.d.ts +27 -0
- package/dist/plugins/query/types.d.ts +15 -1
- package/dist/plugins/translators/SqlTranslator.d.ts +15 -0
- package/dist/schema/SchemaDefinition.d.ts +8 -0
- package/dist/schema/changeTracker.d.ts +10 -0
- package/dist/schema/index.cjs +291 -274
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +294 -276
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/types.d.ts +8 -7
- package/dist/schema/utils/storageDates.d.ts +25 -0
- package/dist/transfer/index.cjs.map +1 -1
- package/dist/transfer/index.js.map +1 -1
- package/dist/utilities/index.cjs +74 -29
- package/dist/utilities/index.cjs.map +1 -1
- package/dist/utilities/index.js +74 -29
- package/dist/utilities/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/codegen/utils.d.ts +0 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections/index.js","sources":["webpack://@routier/core/./src/collections/Changes.ts","webpack://@routier/core/./src/collections/ReadonlySchemaCollection.ts","webpack://@routier/core/./src/collections/SchemaCollection.ts","webpack://@routier/core/./src/collections/TagCollection.ts","webpack://@routier/core/./src/results/Result.ts","webpack://@routier/core/./src/schema/types.ts","webpack://@routier/core/./src/utilities/uuid.ts","webpack://@routier/core/webpack/runtime/define_property_getters","webpack://@routier/core/webpack/runtime/has_own_property","webpack://@routier/core/./src/collections/IdSet.ts","webpack://@routier/core/./src/collections/MemoryDataCollection.ts","webpack://@routier/core/./src/collections/index.ts"],"sourcesContent":["import { EntityUpdateInfo } from \"../plugins/types\";\nimport { InferCreateType, InferType, SchemaId } from \"../schema\";\nimport { TagCollection } from \"./TagCollection\";\nexport class BulkPersistResult extends Map<SchemaId, SchemaPersistResult> {\n\n resolve<T extends {} = Record<string, unknown>>(schemaId: SchemaId): SchemaPersistResult<T> {\n if (this.has(schemaId)) {\n return this.get(schemaId);\n }\n\n this.set(schemaId, new SchemaPersistResult<T>());\n\n return this.get(schemaId);\n }\n\n override get<T extends {} = Record<string, unknown>>(schemaId: SchemaId) {\n return super.get(schemaId) as SchemaPersistResult<T>\n }\n\n get aggregate() {\n return {\n size: this.aggregateSize,\n adds: this.aggregateAddsSize,\n updates: this.aggregateUpdatesSize,\n removes: this.aggregateRemovesSize\n }\n }\n\n private get aggregateSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.total;\n }\n\n return count;\n }\n\n private get aggregateAddsSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.adds.length;\n }\n\n return count;\n }\n\n private get aggregateUpdatesSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.updates.length;\n }\n\n return count;\n }\n\n private get aggregateRemovesSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.removes.length;\n }\n\n return count;\n }\n}\n\nexport class BulkPersistChanges extends Map<SchemaId, SchemaPersistChanges> {\n\n resolve<T extends {} = Record<string, unknown>>(schemaId: SchemaId): SchemaPersistChanges<T> {\n if (this.has(schemaId)) {\n return this.get(schemaId);\n }\n\n this.set(schemaId, new SchemaPersistChanges<T>());\n\n return this.get(schemaId);\n }\n\n override get<T extends {} = Record<string, unknown>>(schemaId: SchemaId) {\n return super.get(schemaId) as SchemaPersistChanges<T>\n }\n\n get aggregate() {\n return {\n size: this.aggregateSize,\n adds: this.aggregateAddsSize,\n updates: this.aggregateUpdatesSize,\n removes: this.aggregateRemovesSize\n }\n }\n\n private get aggregateSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.total;\n }\n\n return count;\n }\n\n private get aggregateAddsSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.adds.length;\n }\n\n return count;\n }\n\n private get aggregateUpdatesSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.updates.length;\n }\n\n return count;\n }\n\n private get aggregateRemovesSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.removes.length;\n }\n\n return count;\n }\n\n /**\n * Ensures the result has the same result sets as the change sets\n * @returns \n */\n toResult() {\n const result = new BulkPersistResult();\n\n for (const [schemaId] of this) {\n result.set(schemaId, new SchemaPersistResult());\n }\n\n return result;\n }\n}\n\nexport class SchemaPersistChanges<T extends {} = Record<string, unknown>> {\n adds: InferCreateType<T>[] = [];\n updates: EntityUpdateInfo<T>[] = [];\n removes: InferType<T>[] = [];\n tags: TagCollection = new TagCollection();\n\n get hasItems() {\n return this.total > 0;\n }\n\n get total() {\n return this.adds.length + this.updates.length + this.removes.length;\n }\n}\n\nexport class SchemaPersistResult<T extends {} = Record<string, unknown>> {\n adds: InferType<T>[] = [];\n updates: InferType<T>[] = [];\n removes: InferType<T>[] = [];\n\n get hasItems() {\n return this.total > 0;\n }\n\n get total() {\n return this.adds.length + this.updates.length + this.removes.length;\n }\n}","import { CompiledSchema, SchemaId } from \"../schema\";\n\n/**\n * Collection of schemas with generic typing for type-safe schema retrieval\n */\nexport class ReadonlySchemaCollection {\n\n protected data: Map<SchemaId, CompiledSchema<Record<string, unknown>>>;\n\n constructor(data?: [SchemaId, CompiledSchema<Record<string, unknown>>][]) {\n this.data = new Map<SchemaId, CompiledSchema<Record<string, unknown>>>(data);\n }\n\n get<T>(schemaId: SchemaId): CompiledSchema<T> | undefined {\n return this.data.get(schemaId) as CompiledSchema<T> | undefined;\n }\n\n has(schemaId: SchemaId): boolean {\n return this.data.has(schemaId);\n }\n\n get size(): number {\n return this.data.size;\n }\n\n keys(): IterableIterator<SchemaId> {\n return this.data.keys();\n }\n\n values(): IterableIterator<CompiledSchema<Record<string, unknown>>> {\n return this.data.values();\n }\n\n entries(): IterableIterator<[SchemaId, CompiledSchema<Record<string, unknown>>]> {\n return this.data.entries();\n }\n\n forEach(callbackfn: (value: CompiledSchema<Record<string, unknown>>, key: SchemaId, map: Map<SchemaId, CompiledSchema<Record<string, unknown>>>) => void, thisArg?: any): void {\n this.data.forEach(callbackfn, thisArg);\n }\n\n [Symbol.iterator](): IterableIterator<[SchemaId, CompiledSchema<Record<string, unknown>>]> {\n return this.data[Symbol.iterator]();\n }\n\n getByName<T>(collectionName: string): CompiledSchema<T> | undefined {\n const found = [...this.data].find(x => x[1].collectionName === collectionName);\n\n if (found != null) {\n return found[1] as CompiledSchema<T>;\n }\n\n return undefined;\n }\n}","import { CompiledSchema, SchemaId } from \"../schema\";\nimport { ReadonlySchemaCollection } from \"./ReadonlySchemaCollection\";\n\n/**\n * Collection of schemas with generic typing for type-safe schema retrieval\n */\nexport class SchemaCollection extends ReadonlySchemaCollection {\n\n set<T>(schemaId: SchemaId, schema: CompiledSchema<T>): this {\n this.data.set(schemaId, schema as CompiledSchema<Record<string, unknown>>);\n return this;\n }\n\n delete(schemaId: SchemaId): boolean {\n return this.data.delete(schemaId);\n }\n\n clear(): void {\n this.data.clear();\n }\n}","export class TagCollection implements Disposable {\n\n private data: Map<object, unknown> = new Map<object, unknown>();\n\n // Delegated to the map rather than tracked in a counter field: every mutation path\n // (set, setMany, combine, delete, dispose) would otherwise have to maintain it, and\n // a missed path silently reports a size that disagrees with the contents.\n get size() {\n return this.data.size;\n }\n\n get(key: object) {\n return this.data.get(key);\n }\n\n has(key: object) {\n return this.data.has(key);\n }\n\n set(key: object, tag: unknown) {\n return this.data.set(key, tag);\n }\n\n delete(key: object) {\n return this.data.delete(key);\n }\n\n setMany(keys: object[], tag: unknown) {\n for (let i = 0, length = keys.length; i < length; i++) {\n const key = keys[i];\n this.set(key, tag);\n }\n }\n\n combine(tags: TagCollection) {\n for (const [key, value] of tags) {\n this.set(key, value);\n }\n }\n\n values() {\n return this.data.values();\n }\n\n keys() {\n return this.data.keys();\n }\n\n [Symbol.dispose]() {\n this.data.clear();\n }\n\n [Symbol.iterator]() {\n return this.data[Symbol.iterator]();\n }\n}","import { PartialResultType, PluginEventPartialResultType, PluginEventResultType, ResultType } from \"./types\";\n\nabstract class BaseResult {\n static ERROR = \"error\" as const;\n static SUCCESS = \"success\" as const;\n static PARTIAL = \"partial\" as const;\n\n static resolve<T>(result: ResultType<T> | PartialResultType<T>, resolve: (data: T) => void, reject: (error?: any) => void) {\n if (result.ok === BaseResult.SUCCESS) {\n resolve(result.data);\n return;\n }\n\n if (result.ok === BaseResult.PARTIAL) {\n reject({\n partial: result.data,\n error: result.error\n });\n return;\n }\n\n reject(result.error);\n }\n\n static assertSuccess<T>(result: any): asserts result is { ok: \"success\"; data: T } {\n if (result.ok !== BaseResult.SUCCESS) {\n throw new Error(`Expected success result, but got ${result.ok}: ${result.error}`);\n }\n }\n}\n\nexport class Result extends BaseResult {\n static success<T>(data: T): ResultType<T>;\n static success(): ResultType<never>;\n static success<T>(data?: T): ResultType<T> {\n return {\n ok: Result.SUCCESS,\n data\n }\n }\n\n static error<T>(error: any): ResultType<T> {\n return {\n ok: Result.ERROR,\n error\n }\n }\n\n static partial<T>(data: T, error: any): PartialResultType<T> {\n return {\n ok: Result.PARTIAL,\n data,\n error\n }\n }\n}\n\nexport class PluginEventResult extends BaseResult {\n static success<T>(id: string, data: T): PluginEventResultType<T>;\n static success(id: string): PluginEventResultType<never>;\n static success<T>(id: string, data?: T): PluginEventResultType<T> {\n return {\n id,\n ok: Result.SUCCESS,\n data\n }\n }\n\n static error<T>(id: string, error: any): PluginEventResultType<T> {\n return {\n id,\n ok: Result.ERROR,\n error\n }\n }\n\n static partial<T>(id: string, data: T, error: any): PluginEventPartialResultType<T> {\n return {\n id,\n ok: Result.PARTIAL,\n data,\n error\n }\n }\n\n static assertSuccess<T>(result: PluginEventResultType<T>): asserts result is { ok: \"success\"; data: T; id: string } {\n if (result.ok !== Result.SUCCESS) {\n throw new Error(`Expected success result, but got ${result.ok}: ${result.error}`);\n }\n }\n}\n","import type { SchemaDefinition } from \"./SchemaDefinition\";\nimport type { SchemaBase } from \"./property/base/SchemaBase\";\nimport type { SchemaArray } from \"./property/types/SchemaArray\";\nimport type { SchemaVector } from \"./property/types/SchemaVector\";\nimport type { SchemaObject } from \"./property/types/SchemaObject\";\nimport type { PropertyInfo } from \"./PropertyInfo\";\nimport type { DeepPartial } from \"../types\";\nimport type { SchemaFunction } from \"./table\";\nimport type { SchemaOptional, SchemaTag } from \"./property/modifiers\";\nimport type { Branded } from \"../utilities/types\";\nimport type { SchemaSubscriptionOptions } from \"./communication/broadcast\";\n\nexport type DefaultValue<T, I = never> = T | ((injected: I) => T);\nexport type FunctionBody<TEntity, TResult> = (entity: TEntity, collectionName: CollectionName) => TResult;\nexport type IdType = string | number;\nexport type ForeignKey<T extends {}> = { \n schema: CompiledSchema<T>, \n property: PropertyInfo<T> \n};\n\nexport enum SchemaTypes {\n Array = \"Array\",\n Boolean = \"Boolean\",\n Date = \"Date\",\n Number = \"Number\",\n Object = \"Object\",\n String = \"String\",\n Definition = \"Definition\",\n Function = \"Function\",\n Computed = \"Computed\",\n /**\n * Content in, reference out. The only type whose write shape differs from its stored\n * shape, and a leaf on purpose — see `SchemaFile`.\n */\n File = \"File\",\n /**\n * A fixed-length list of numbers, carrying its dimension count — see `SchemaVector`.\n *\n * Value-shaped exactly like `s.array(s.number())`, which is why every array codegen\n * handler accepts it. It is a distinct type only so a backend can recognise it and store\n * it natively; nothing else needs to tell the two apart.\n */\n Vector = \"Vector\"\n}\n\nexport type ArrayShape = string | number | Date | {};\n\n\n/**\n * What a file property gives back: where the bytes are and what they are.\n *\n * Declared in core so `InferType` can name it. Core never reads or writes the bytes — it only\n * carries this shape — and `@routier/blob-plugin` is what puts one here.\n */\nexport type FileReferenceValue = {\n /** Where the bytes live, content-addressed by the blob plugin. */\n key: string;\n /** Byte length. */\n size: number;\n /** Media type as supplied at upload. */\n contentType: string;\n /** SHA-256 of the bytes, lowercase hex. */\n checksum: string;\n /** The name to show a user. Not part of the key. */\n fileName: string;\n};\n\n/**\n * What a file property ACCEPTS: content, or a reference you already have.\n *\n * `Blob` covers `File`, which is what an `<input type=\"file\">` yields. A reference is accepted\n * too, so re-saving an entity that was read from the database does not have to re-upload it.\n */\nexport type FileContentValue =\n | FileReferenceValue\n | Uint8Array\n | ArrayBuffer\n | Blob\n | string;\n\n/**\n * What a vector property holds, in and out: a plain list of numbers.\n *\n * Named rather than written inline because the inference rules have to recognise it after a\n * modifier has erased which class produced it — the same problem `FileReferenceValue` solves\n * above, and for the same reason.\n */\nexport type VectorValue = number[];\n\n/**\n * What `s.string({ ... })` accepts.\n *\n * Declarations only. Core stores them and never acts on them; a backend that can use one does.\n */\nexport type StringOptions = {\n /**\n * The longest value the property is declared to hold.\n *\n * MySQL uses it for `VARCHAR(maxLength)`; without it every string column is\n * `VARCHAR(255)`, which silently truncates longer values. Other backends ignore it. Core\n * never validates a value against it — see `SchemaBase.maxLength`.\n */\n maxLength?: number;\n};\n\nexport type ExpandedProperty = ExpandedChildProperty & {\n assignmentPath: string;\n selectorPath: string;\n properties: Map<string, ExpandedChildProperty>;\n childDegree: number;\n};\n\nexport type ExpandedChildProperty = {\n propertyName: string;\n type: SchemaTypes;\n isNullableOrOptional: boolean;\n isReadonly: boolean;\n isIdentity: boolean;\n isUnmapped: boolean;\n}\n\nexport enum HashType {\n Ids = \"Ids\",\n Object = \"Object\"\n}\n\nexport type HashFunction<TEntity extends {}> = {\n (entity: InferCreateType<TEntity>, type: HashType.Object): string;\n (entity: InferType<TEntity>, type: HashType.Ids): string;\n}\n\nexport type GetHashTypeFunction<TEntity extends {}> = {\n (entity: InferCreateType<TEntity>): HashType.Object;\n (entity: InferType<TEntity>): HashType.Ids;\n}\n\nexport type ChangeTrackingType = \"proxy\" | \"diff\" | \"immutable\";\n\nexport type IndexType = \"single\" | \"compound\" | \"unique\" | \"primary-key\"\nexport type Index = {\n properties: PropertyInfo<any>[],\n type: IndexType;\n name: string;\n}\n\n/**\n * Represents changes to subscriptions, categorizing them by modifications to\n * entities (additions, updates, removals) or query-driven removals.\n * @template T - The type of the entities in the subscription.\n */\nexport type SubscriptionChanges<T extends {}> = {\n /**\n * Entities that have been added to the subscription.\n */\n adds: InferType<T>[];\n /**\n * Entities that have been updated within the subscription.\n */\n updates: InferType<T>[];\n /**\n * Entities that have been removed from the subscription.\n */\n removals: InferType<T>[];\n /**\n * Entities that have been added/updated/removed from the subscription and it is unknown \n * if the entities have been added/updated/removed.\n */\n unknown: InferType<T>[];\n}\n\nexport interface ISchemaSubscription<T extends {}> extends Disposable {\n send(changes: SubscriptionChanges<T>): void;\n onMessage(callback: (changes: SubscriptionChanges<T>) => void): void;\n}\n\nexport type Enrich<TEntity extends {}> = {\n (entity: InferType<TEntity>, changeTrackingType: ChangeTrackingType): InferType<TEntity>;\n (entity: InferCreateType<TEntity>, changeTrackingType: ChangeTrackingType): InferCreateType<TEntity>;\n}\nexport type Prepare<TEntity extends {}> = {\n (entity: InferCreateType<TEntity>): InferCreateType<TEntity>;\n (entity: InferType<TEntity>): InferType<TEntity>;\n}\nexport type Preprocess<TEntity extends {}> = {\n (entity: InferCreateType<TEntity>): InferType<TEntity>;\n (entity: InferType<TEntity>): InferType<TEntity>;\n}\n\nexport type SetProperties<TEntity extends {}> = (destination: DeepPartial<InferType<TEntity> | InferCreateType<TEntity>>, source: DeepPartial<InferType<TEntity> | InferCreateType<TEntity>>) => void;\n\nexport type CompiledSchemaCore<TEntity extends {}> = Omit<CompiledSchema<TEntity>, \"createSubscription\">;\n\nexport type CompiledSchemaWithMetadata<TEntity extends {}, TMetadata> = {\n readonly metadata: TMetadata;\n} & CompiledSchema<TEntity>;\n\n/**\n * Represents a fully compiled schema with all utilities and metadata for an entity type.\n */\nexport type CompiledSchema<TEntity extends {}> = {\n\n deserializePartial: (item: Record<string, unknown>, properties: PropertyInfo<TEntity>[]) => DeepPartial<InferType<TEntity>>;\n\n createSubscription: (abortSignal?: AbortSignal, scope?: string, options?: SchemaSubscriptionOptions) => ISchemaSubscription<TEntity>;\n /** Returns the property info for a given id (full path) */\n getProperty: (id: string) => PropertyInfo<TEntity>;\n /** Returns the ID of the given entity. */\n getId: (entity: InferType<TEntity>) => IdType;\n /** Returns a deep clone of the given entity. */\n clone: (entity: InferType<TEntity>) => InferType<TEntity>;\n /**\n * Returns a deep clone of a record that is still in the STORAGE shape — renamed properties\n * under their `from` names rather than their in-memory names.\n *\n * `clone` reads in-memory names, so it returns `undefined` for every renamed property of a\n * stored record. Use this when copying rows a store holds before they have been deserialized.\n * Generated on first call; schemas that are never cloned in storage shape never build it.\n */\n cloneStorage: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Removes unmapped or extraneous properties from the entity. */\n strip: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Prepares a new entity for creation, applying defaults and transformations. */\n prepare: Prepare<TEntity>;\n /** Merges the source entity into the destination entity. */\n merge: (destination: InferType<TEntity> | InferCreateType<TEntity>, source: InferType<TEntity>) => InferType<TEntity>;\n /** Indicates if the schema has identity properties. */\n hasIdentities: boolean;\n /** List of properties that are identity keys. */\n idProperties: PropertyInfo<TEntity>[];\n /** All property metadata for the schema. */\n properties: PropertyInfo<TEntity>[],\n /** The hash type used for this schema. */\n hashType: HashType;\n /** Computes a hash for the given entity. */\n hash: HashFunction<TEntity>;\n /** Returns the hash type for the given entity. */\n getHashType: GetHashTypeFunction<TEntity>;\n /** Compares two entities for equality. */\n compare: (a: InferType<TEntity>, fromDb: InferType<TEntity>) => boolean;\n /** Deserializes an entity from storage format. */\n deserialize: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Sets 1 or many properties from the source object onto the destination object with change tracking. */\n set: SetProperties<TEntity>;\n /** Combines serializing and preparing an entity for saving. */\n preprocess: Preprocess<TEntity>;\n /** Combines deserializing and enriching an entity for selection. */\n postprocess: Enrich<TEntity>;\n\n /** Serializes an entity to storage format. */\n serialize: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Unique id for the schema. */\n id: SchemaId,\n /** The name of the collection for this schema. */\n collectionName: CollectionName;\n /** Returns all IDs for the given entity (usually a single-element tuple). */\n getIds: (entity: InferType<TEntity>) => [IdType];\n /** Enriches the entity with change tracking or other metadata. */\n enrich: Enrich<TEntity>;\n /** Indicates if the schema has identity keys. */\n hasIdentityKeys: boolean;\n /** Returns a deeply frozen (immutable) version of the entity. */\n freeze: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Enables change tracking on the entity. */\n enableChangeTracking: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** The schema definition object. */\n definition: SchemaDefinition<TEntity>;\n /** Returns all indexes defined for this schema. */\n getIndexes: () => Index[];\n /** Compares two entities for Id equality. */\n compareIds: (a: InferType<TEntity>, b: InferType<TEntity>) => boolean;\n}\n\nexport type PropertySerializer<T extends any> = (value: T) => string | number;\nexport type PropertyDeserializer<T extends any> = (value: string | number) => T;\n\n/**\n * A two-way transform between the application value and the stored value.\n *\n * Both directions may be async. Held as a live reference rather than stringified, so a\n * closure works and `injected` is a convenience rather than the only way in.\n */\nexport type PropertyTransform<T extends any> = {\n /**\n * Application value to stored value. Runs before the plugin sees it. May be async.\n *\n * `entity` is there for the one-way case: a transform with no `from` derives a value\n * rather than converting one, which is what `computed` does.\n */\n to: (value: T, entity: Record<string, unknown>) => unknown | Promise<unknown>;\n\n /**\n * Stored value back to application value. Runs after the plugin returns it.\n *\n * Optional. Leave it out and the transform is one-way: the stored value is the value.\n */\n from?: (value: unknown) => T | Promise<T>;\n\n /**\n * What the column becomes, when the stored form is not the property's own type.\n *\n * Defaults to the property's own type, so nothing changes unless you say it does. A\n * library that always produces text — a cipher, a compressor — sets this once, and the\n * caller who uses that library never writes it.\n */\n stores?: SchemaTypes;\n\n /**\n * Whether a filter on this property can still run in the database.\n *\n * Defaults to `none`, which rejects the filter rather than returning wrong rows. Set\n * `equality` only when `to` is deterministic.\n */\n comparable?: 'equality' | 'none';\n};\n\nexport type SchemaId = Branded<number, \"SchemaId\">;\nexport type CollectionName = Branded<string, \"CollectionName\">;\n\nexport type SchemaModifiers = \"default\" | \"deserialize\" |\n \"identity\" | \"key\" |\n \"nullable\" | \"optional\" |\n \"readonly\" | \"serialize\" |\n \"unmapped\" | \"computed\" |\n \"distinct\" | \"searchable\";\n\n/**\n * What a tagged property infers to.\n *\n * `tag()` is metadata and must not change a type, but `SchemaTag<T>` carries the same `T` as\n * whatever it wrapped without carrying which class that was. For a string `T` is already\n * `string`; for an object `T` is the map of child schemas, which only the `SchemaObject`\n * branch below knows how to unwrap. Falling through to the generic `SchemaBase` branch\n * therefore handed the raw map back, so `s.object({ key: s.string() }).tag('x')` typed\n * `key` as `SchemaString` instead of `string` — everything ran, and only the types lied.\n *\n * An array is distinguishable because `SchemaArray`'s parameter is the ELEMENT schema, so a\n * tagged array arrives here as a `SchemaBase` rather than a plain map.\n */\ntype InferTagged<C> = ResolveWrapped<C>;\n\n/**\n * What a wrapping modifier's inner type resolves to.\n *\n * `SchemaOptional`, `SchemaNullable` and `SchemaTag` all carry the same `C` as whatever they\n * wrapped, without carrying which class that was, so each has to work out what it is holding.\n * Three shapes are possible:\n *\n * - an already-resolved value (`string` from `s.string()`, a file reference from `s.file()`)\n * - an ELEMENT schema, which is what `SchemaArray` parameterises on\n * - a map of child schemas, which is what `SchemaObject` parameterises on\n *\n * Getting this wrong is silent. The map branch applied to an already-resolved object walks\n * its keys and infers `never` for each, so `s.file().optional()` typed as\n * `{ key: never, size: never, ... }` — which no value can satisfy and no test would catch at\n * runtime.\n */\ntype ResolveWrapped<C> =\n C extends string | number | boolean | Date | FileReferenceValue ? C :\n C extends VectorValue ? C :\n C extends SchemaBase<any, any> ? InferPrimitive<C>[] :\n { [K in keyof C]: InferPrimitive<C[K]> };\n\ntype InferPrimitive<T> =\n T extends SchemaOptional<infer C, infer __> ? ResolveWrapped<C> :\n T extends SchemaTag<infer C, infer __> ? InferTagged<C> :\n // Before the generic `SchemaBase` branch below, which would see `X = number[]` and map\n // the element through `InferPrimitive<number>` — no branch matches a bare `number`, so a\n // vector would type as `never[]`: assignable from nothing, and invisible at runtime.\n T extends SchemaVector<infer __, infer ___> ? VectorValue :\n T extends SchemaArray<infer Y, infer __> ? InferPrimitive<Y>[]\n : T extends SchemaObject<infer Obj, infer _> ?\n { [K in keyof Obj]: InferPrimitive<Obj[K]> } : // Process nested objects\n T extends SchemaFunction<infer F, infer __> ? F : T extends SchemaBase<infer X, infer _> ?\n X extends Array<infer A> ? InferPrimitive<A>[] : X : // Extract the primitive type\n never;\n\nexport type InferType<T> = T extends CompiledSchema<infer R> ? InferCompiledSchema<R> : T extends {} ? InferCompiledSchema<T> : T;\nexport type InferCreateType<T> = T extends CompiledSchema<infer R> ? InferCompiledCreateSchema<R> : T extends {} ? InferCompiledCreateSchema<T> : unknown;\nexport type InferMappedType<T> = T extends SchemaBase<infer K, infer __> ? InferType<K> : InferCompiledSchema<T>;\nexport type InferRoot<T> = T extends CompiledSchema<infer R> ? R : never;\n\ntype HasModifier<T, K extends keyof T, M extends SchemaModifiers> =\n T[K] extends SchemaBase<any, infer Mods> ?\n M extends Mods ? true : false :\n false;\n\ntype IsPlainProperty<T, K extends keyof T> =\n [\n HasModifier<T, K, \"readonly\">,\n HasModifier<T, K, \"optional\">,\n HasModifier<T, K, \"nullable\">\n ] extends [\n false,\n false,\n false\n ] ? true : false;\n\ntype IsCreateExcluded<T, K extends keyof T> =\n [\n HasModifier<T, K, \"identity\">,\n HasModifier<T, K, \"computed\">,\n HasModifier<T, K, \"unmapped\">\n ] extends [\n false,\n false,\n false\n ] ? false : true;\n\ntype IsCreateOptional<T, K extends keyof T> =\n [\n HasModifier<T, K, \"optional\">,\n HasModifier<T, K, \"default\">\n ] extends [\n false,\n false\n ] ? false : true;\n\ntype IsCreateNullable<T, K extends keyof T> =\n HasModifier<T, K, \"nullable\"> extends true ? true : false;\n\n/**\n * What a property ACCEPTS on the way in, which is not always what it gives back.\n *\n * Only a file differs today: you assign content and read a reference. Matching on the read\n * type rather than on `SchemaFile` itself is deliberate — it keeps working through every\n * modifier. `s.file().optional()` is a `SchemaOptional`, `s.file().tag('x')` is a\n * `SchemaTag`, and neither carries the original class, so a check against the class alone\n * would silently stop accepting content the moment anyone added a modifier.\n *\n * Assignability is required in BOTH directions, and the tuple wrappers are load-bearing.\n * One-way `extends` matches `never` — which is assignable to everything — so a generic\n * property over `Record<string, unknown>` resolved to file content and broke the Dexie\n * plugin's types. It also matched any object that merely happens to have these five fields\n * plus more. Mutual assignability admits the reference shape and nothing else, and the\n * tuples stop the conditional distributing over a union.\n */\ntype InferWritePrimitive<T> =\n [InferPrimitive<T>] extends [FileReferenceValue]\n ? [FileReferenceValue] extends [InferPrimitive<T>] ? FileContentValue : InferPrimitive<T>\n : InferPrimitive<T>;\n\ntype InferCreateProperty<T, K extends keyof T> =\n IsCreateNullable<T, K> extends true ? null | InferWritePrimitive<T[K]> : InferWritePrimitive<T[K]>;\n\ntype InferCompiledSchema<T> = CoalesceEmpty<{\n [K in keyof T as IsPlainProperty<T, K> extends true ? K : never]: InferPrimitive<T[K]>\n}, {\n readonly [K in keyof T as HasModifier<T, K, \"readonly\"> extends true ? K : never]: InferPrimitive<T[K]>\n }, {\n [K in keyof T as HasModifier<T, K, \"optional\"> extends true ? K : never]?: InferPrimitive<T[K]>\n }, {\n [K in keyof T as HasModifier<T, K, \"nullable\"> extends true ? K : never]: null | InferPrimitive<T[K]>\n}>;\n\ntype InferCompiledCreateSchema<T> = {\n [K in keyof T as IsCreateExcluded<T, K> extends true ? never\n : IsCreateOptional<T, K> extends true ? K : never]?: InferCreateProperty<T, K>\n} & {\n [K in keyof T as IsCreateExcluded<T, K> extends true ? never\n : IsCreateOptional<T, K> extends true ? never : K]: InferCreateProperty<T, K>\n};\n\ntype IsEmptyObject<T> = keyof T extends never ? true : false;\ntype CoalesceEmpty<T1 extends {}, T2 extends {}, T3 extends {}, T4 extends {}> = (IsEmptyObject<T1> extends true ? {} : T1) & (IsEmptyObject<T2> extends true ? {} : T2) & (IsEmptyObject<T3> extends true ? {} : T3) & (IsEmptyObject<T4> extends true ? {} : T4);\n","export const uuid = (length: number = 16): string => {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n const charLength = chars.length;\n let result = '';\n\n for (let i = 0; i < length; i++) {\n result += chars[Math.random() * charLength | 0];\n }\n return result;\n}\n\nconst HEX_CHARS = '0123456789abcdef';\nconst UUID_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';\n\nconst hasCrypto =\n typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function';\n\nconst hasRandomUUID =\n typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function';\n\nexport const uuidv4 = (): string => {\n if (hasRandomUUID) {\n return crypto.randomUUID();\n }\n\n return uuidv4Fallback();\n};\n\nconst uuidv4Fallback = (): string => {\n let randomBytes: Uint8Array | null = null;\n if (hasCrypto) {\n randomBytes = crypto.getRandomValues(new Uint8Array(16));\n }\n\n let byteIndex = 0;\n let uuid = '';\n\n for (let i = 0; i < UUID_TEMPLATE.length; i++) {\n const c = UUID_TEMPLATE[i];\n if (c === '-') {\n uuid += '-';\n continue;\n }\n\n let r: number;\n if (hasCrypto && randomBytes) {\n // Each byte gives two hex digits (nibbles)\n r =\n (i % 2 === 0\n ? randomBytes[byteIndex] >> 4\n : randomBytes[byteIndex++] & 0x0f);\n } else {\n r = Math.floor(Math.random() * 16);\n }\n\n if (c === 'x') {\n uuid += HEX_CHARS[r];\n } else if (c === 'y') {\n // Variant bits: 8, 9, A, or B\n uuid += HEX_CHARS[(r & 0x3) | 0x8];\n } else if (c === '4') {\n uuid += '4';\n }\n }\n\n return uuid;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import { IdType } from \"../schema\";\n\nexport class IdSet {\n\n readonly ids: readonly IdType[];\n\n constructor(...ids: IdType[]) {\n this.ids = Object.freeze(ids);\n }\n\n equals(other: IdSet): boolean {\n\n if (this.ids.length === 1) {\n return this.ids[0] === other.ids[0];\n }\n\n return this.toString() === other.toString();\n }\n\n toString(): string {\n\n if (this.ids.length === 1) {\n return String(this.ids[0]);\n }\n\n return this.ids.toString();\n }\n}","import { CompiledSchema, IdType, InferType, PropertyInfo, SchemaTypes } from \"../schema\";\nimport { CallbackResult, Result } from \"../results\";\nimport { uuidv4 } from \"../utilities\";\nimport { IdSet } from \"./IdSet\";\n\nexport class MemoryDataCollection {\n\n protected readonly nextNumericalIds: Map<string, number>;\n protected readonly data: Map<string, Record<string, unknown>>;\n protected readonly schema: CompiledSchema<any>;\n protected readonly idProperties: PropertyInfo<any>[];\n\n get size() {\n return this.data.size;\n }\n\n get records() {\n return [...this.data.values()];\n }\n\n /** Iterates stored records without materializing them into an array. */\n values(): IterableIterator<Record<string, unknown>> {\n return this.data.values();\n }\n\n constructor(schema: CompiledSchema<any>) {\n this.data = new Map<string, Record<string, unknown>>();\n this.nextNumericalIds = new Map<string, number>();\n this.schema = schema;\n this.idProperties = schema.idProperties;\n }\n\n private _getNextId(property: PropertyInfo<any>) {\n\n let nextId = 1;\n\n if (this.nextNumericalIds.has(property.id) === true) {\n nextId = this.nextNumericalIds.get(property.id) + 1;\n }\n\n this.nextNumericalIds.set(property.id, nextId);\n\n return nextId;\n }\n\n private resolveId(property: PropertyInfo<any>, value: unknown) {\n if (typeof value !== \"number\") {\n return;\n }\n\n const currentIdForProperty = this.nextNumericalIds.get(property.id);\n\n if (value <= currentIdForProperty) {\n return;\n }\n\n this.nextNumericalIds.set(property.id, value);\n }\n\n private getAndSetId(item: Record<string, unknown>, property: PropertyInfo<any>): IdType {\n if (item[property.name] != null) {\n return item[property.name] as IdType;\n }\n\n if (property.type === SchemaTypes.String) {\n const uuid = uuidv4()\n item[property.name] = uuid;\n return uuid;\n }\n\n if (property.type === SchemaTypes.Number) {\n const id = this._getNextId(property);\n item[property.name] = id;\n return id;\n }\n\n throw new Error(`Id Property '${property.name}' must be string or number, found '${property.type}'`)\n }\n\n private _dateColumns?: string[];\n\n /** Date columns, by the name a stored record uses. Nested dates live inside a JSON column. */\n private get dateColumns(): string[] {\n if (this._dateColumns == null) {\n this._dateColumns = this.schema.properties\n .filter(property => property.type === SchemaTypes.Date\n && property.getAssignmentPath().includes(\".\") === false)\n .map(property => property.getResolvedName());\n }\n\n return this._dateColumns;\n }\n\n /**\n * The record this collection keeps.\n *\n * A copy, so a caller holding the entity cannot write into the store afterwards. Dates are held\n * as Dates: a predicate compares a Date, and a stored ISO string never matches one.\n */\n private toStored(item: Record<string, unknown>): Record<string, unknown> {\n const columns = this.dateColumns;\n const stored = { ...item };\n\n for (let i = 0, length = columns.length; i < length; i++) {\n const value = stored[columns[i]];\n\n if (typeof value === \"string\") {\n stored[columns[i]] = new Date(value);\n }\n }\n\n return stored;\n }\n\n seed(items: Record<string, unknown>[]) {\n for (let i = 0, length = items.length; i < length; i++) {\n const id = this.resolveIdSet(items[i] as InferType<unknown>);\n this.data.set(id.toString(), this.toStored(items[i]));\n }\n }\n\n private resolveCurrentIdSet(item: Record<string, unknown>): IdSet {\n const idProperties = this.schema.idProperties;\n const ids: IdType[] = [];\n // ensure keys\n for (let j = 0, l = idProperties.length; j < l; j++) {\n const property = idProperties[j];\n const value = property.getValue(item);\n\n if (value == null) {\n throw new Error(`Key cannot be null. Key: ${property.name}`);\n }\n\n ids.push(value);\n }\n\n return new IdSet(...ids);\n }\n\n private resolveIdSet(item: Record<string, unknown>): IdSet {\n\n if (this.schema.hasIdentityKeys) {\n const idProperties = this.schema.idProperties;\n const ids: IdType[] = Array.from({ length: idProperties.length });\n\n // Need to make sure we allow for seeding the collection when we call add vs seed\n // There will be an existing id, but the id type could still be identity\n if (idProperties.length === 1) {\n const value = this.getAndSetId(item, idProperties[0]);\n this.resolveId(idProperties[0], value);\n ids[0] = value;\n } else {\n for (let j = 0, l = idProperties.length; j < l; j++) {\n const value = this.getAndSetId(item, idProperties[j]);\n this.resolveId(idProperties[j], value);\n ids[j] = value;\n }\n }\n\n return new IdSet(...ids);\n }\n\n return this.resolveCurrentIdSet(item);\n }\n\n add(item: Record<string, unknown>) {\n const id = this.resolveIdSet(item);\n this.data.set(id.toString(), this.toStored(item));\n }\n\n /**\n * Adds a record only when no record with the same key is present. Durable\n * collections use this to hydrate stored records around in-memory mutations\n * without clobbering them.\n */\n addIfAbsent(item: Record<string, unknown>) {\n const id = this.resolveIdSet(item);\n const key = id.toString();\n\n if (this.data.has(key) === false) {\n this.data.set(key, this.toStored(item));\n }\n }\n\n /**\n * Looks up a single record by its key values without scanning the collection.\n * @param ids Key values in schema id property order\n * @returns The matching record or undefined when no record has the given key\n */\n getByIds(ids: IdType[]): Record<string, unknown> | undefined {\n return this.data.get(new IdSet(...ids).toString());\n }\n\n remove(item: Record<string, unknown>) {\n const id = this.resolveCurrentIdSet(item);\n this.data.delete(id.toString());\n }\n\n update(item: Record<string, unknown>) {\n const id = this.resolveCurrentIdSet(item);\n this.data.set(id.toString(), this.toStored(item));\n }\n\n destroy(done: CallbackResult<never>) {\n this.nextNumericalIds.clear();\n this.data.clear();\n done(Result.success());\n }\n\n load(done: CallbackResult<never>) {\n done(Result.success())\n }\n\n save(done: CallbackResult<never>) {\n done(Result.success())\n }\n}","export * from './Changes';\nexport * from './TagCollection';\nexport * from './IdSet';\nexport * from './MemoryDataCollection';\nexport * from './SchemaCollection';\nexport * from './ReadonlySchemaCollection';"],"names":["TagCollection","BulkPersistResult","Map","schemaId","SchemaPersistResult","count","result","BulkPersistChanges","SchemaPersistChanges","ReadonlySchemaCollection","data","callbackfn","thisArg","Symbol","collectionName","found","x","undefined","SchemaCollection","schema","key","tag","keys","i","length","tags","value","BaseResult","resolve","reject","Error","Result","error","PluginEventResult","id","SchemaTypes","HashType","uuid","chars","charLength","Math","HEX_CHARS","UUID_TEMPLATE","hasCrypto","crypto","hasRandomUUID","uuidv4","uuidv4Fallback","randomBytes","Uint8Array","byteIndex","c","r","IdSet","ids","Object","other","String","MemoryDataCollection","property","nextId","currentIdForProperty","item","columns","stored","Date","items","idProperties","j","l","Array","done"],"mappings":";;;;;;;;;AAEgD;AACzC,MAAMC,0BAA0BC;IAEnC,QAAgDC,QAAkB,EAA0B;QACxF,IAAI,IAAI,CAAC,GAAG,CAACA,WAAW;YACpB,OAAO,IAAI,CAAC,GAAG,CAACA;QACpB;QAEA,IAAI,CAAC,GAAG,CAACA,UAAU,IAAIC;QAEvB,OAAO,IAAI,CAAC,GAAG,CAACD;IACpB;IAES,IAA4CA,QAAkB,EAAE;QACrE,OAAO,KAAK,CAAC,IAAIA;IACrB;IAEA,IAAI,YAAY;QACZ,OAAO;YACH,MAAM,IAAI,CAAC,aAAa;YACxB,MAAM,IAAI,CAAC,iBAAiB;YAC5B,SAAS,IAAI,CAAC,oBAAoB;YAClC,SAAS,IAAI,CAAC,oBAAoB;QACtC;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,KAAKwC,IAA2B,EAAE;QAC9BA,KAAKxC,qCAAc;IACvB;AACJ;;;;;;;ACxN0B;AACM;AACR;AACe;AACJ;AACQ"}
|
|
1
|
+
{"version":3,"file":"collections/index.js","sources":["webpack://@routier/core/./src/collections/Changes.ts","webpack://@routier/core/./src/collections/ReadonlySchemaCollection.ts","webpack://@routier/core/./src/collections/SchemaCollection.ts","webpack://@routier/core/./src/collections/TagCollection.ts","webpack://@routier/core/./src/results/Result.ts","webpack://@routier/core/./src/schema/types.ts","webpack://@routier/core/./src/schema/utils/propertyKind.ts","webpack://@routier/core/./src/schema/utils/storageDates.ts","webpack://@routier/core/./src/utilities/uuid.ts","webpack://@routier/core/webpack/runtime/define_property_getters","webpack://@routier/core/webpack/runtime/has_own_property","webpack://@routier/core/./src/collections/IdSet.ts","webpack://@routier/core/./src/collections/MemoryDataCollection.ts","webpack://@routier/core/./src/collections/index.ts"],"sourcesContent":["import { EntityUpdateInfo } from \"../plugins/types\";\nimport { InferCreateType, InferType, SchemaId } from \"../schema\";\nimport { TagCollection } from \"./TagCollection\";\nexport class BulkPersistResult extends Map<SchemaId, SchemaPersistResult> {\n\n resolve<T extends {} = Record<string, unknown>>(schemaId: SchemaId): SchemaPersistResult<T> {\n if (this.has(schemaId)) {\n return this.get(schemaId);\n }\n\n this.set(schemaId, new SchemaPersistResult<T>());\n\n return this.get(schemaId);\n }\n\n override get<T extends {} = Record<string, unknown>>(schemaId: SchemaId) {\n return super.get(schemaId) as SchemaPersistResult<T>\n }\n\n get aggregate() {\n return {\n size: this.aggregateSize,\n adds: this.aggregateAddsSize,\n updates: this.aggregateUpdatesSize,\n removes: this.aggregateRemovesSize\n }\n }\n\n private get aggregateSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.total;\n }\n\n return count;\n }\n\n private get aggregateAddsSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.adds.length;\n }\n\n return count;\n }\n\n private get aggregateUpdatesSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.updates.length;\n }\n\n return count;\n }\n\n private get aggregateRemovesSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.removes.length;\n }\n\n return count;\n }\n}\n\nexport class BulkPersistChanges extends Map<SchemaId, SchemaPersistChanges> {\n\n resolve<T extends {} = Record<string, unknown>>(schemaId: SchemaId): SchemaPersistChanges<T> {\n if (this.has(schemaId)) {\n return this.get(schemaId);\n }\n\n this.set(schemaId, new SchemaPersistChanges<T>());\n\n return this.get(schemaId);\n }\n\n override get<T extends {} = Record<string, unknown>>(schemaId: SchemaId) {\n return super.get(schemaId) as SchemaPersistChanges<T>\n }\n\n get aggregate() {\n return {\n size: this.aggregateSize,\n adds: this.aggregateAddsSize,\n updates: this.aggregateUpdatesSize,\n removes: this.aggregateRemovesSize\n }\n }\n\n private get aggregateSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.total;\n }\n\n return count;\n }\n\n private get aggregateAddsSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.adds.length;\n }\n\n return count;\n }\n\n private get aggregateUpdatesSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.updates.length;\n }\n\n return count;\n }\n\n private get aggregateRemovesSize() {\n let count = 0;\n\n for (const [, result] of this) {\n count += result.removes.length;\n }\n\n return count;\n }\n\n /**\n * Ensures the result has the same result sets as the change sets\n * @returns \n */\n toResult() {\n const result = new BulkPersistResult();\n\n for (const [schemaId] of this) {\n result.set(schemaId, new SchemaPersistResult());\n }\n\n return result;\n }\n}\n\nexport class SchemaPersistChanges<T extends {} = Record<string, unknown>> {\n adds: InferCreateType<T>[] = [];\n updates: EntityUpdateInfo<T>[] = [];\n removes: InferType<T>[] = [];\n tags: TagCollection = new TagCollection();\n\n get hasItems() {\n return this.total > 0;\n }\n\n get total() {\n return this.adds.length + this.updates.length + this.removes.length;\n }\n}\n\nexport class SchemaPersistResult<T extends {} = Record<string, unknown>> {\n adds: InferType<T>[] = [];\n updates: InferType<T>[] = [];\n removes: InferType<T>[] = [];\n\n get hasItems() {\n return this.total > 0;\n }\n\n get total() {\n return this.adds.length + this.updates.length + this.removes.length;\n }\n}","import { CompiledSchema, SchemaId } from \"../schema\";\n\n/**\n * Collection of schemas with generic typing for type-safe schema retrieval\n */\nexport class ReadonlySchemaCollection {\n\n protected data: Map<SchemaId, CompiledSchema<Record<string, unknown>>>;\n\n constructor(data?: [SchemaId, CompiledSchema<Record<string, unknown>>][]) {\n this.data = new Map<SchemaId, CompiledSchema<Record<string, unknown>>>(data);\n }\n\n get<T>(schemaId: SchemaId): CompiledSchema<T> | undefined {\n return this.data.get(schemaId) as CompiledSchema<T> | undefined;\n }\n\n has(schemaId: SchemaId): boolean {\n return this.data.has(schemaId);\n }\n\n get size(): number {\n return this.data.size;\n }\n\n keys(): IterableIterator<SchemaId> {\n return this.data.keys();\n }\n\n values(): IterableIterator<CompiledSchema<Record<string, unknown>>> {\n return this.data.values();\n }\n\n entries(): IterableIterator<[SchemaId, CompiledSchema<Record<string, unknown>>]> {\n return this.data.entries();\n }\n\n forEach(callbackfn: (value: CompiledSchema<Record<string, unknown>>, key: SchemaId, map: Map<SchemaId, CompiledSchema<Record<string, unknown>>>) => void, thisArg?: any): void {\n this.data.forEach(callbackfn, thisArg);\n }\n\n [Symbol.iterator](): IterableIterator<[SchemaId, CompiledSchema<Record<string, unknown>>]> {\n return this.data[Symbol.iterator]();\n }\n\n getByName<T>(collectionName: string): CompiledSchema<T> | undefined {\n const found = [...this.data].find(x => x[1].collectionName === collectionName);\n\n if (found != null) {\n return found[1] as CompiledSchema<T>;\n }\n\n return undefined;\n }\n}","import { CompiledSchema, SchemaId } from \"../schema\";\nimport { ReadonlySchemaCollection } from \"./ReadonlySchemaCollection\";\n\n/**\n * Collection of schemas with generic typing for type-safe schema retrieval\n */\nexport class SchemaCollection extends ReadonlySchemaCollection {\n\n set<T>(schemaId: SchemaId, schema: CompiledSchema<T>): this {\n this.data.set(schemaId, schema as CompiledSchema<Record<string, unknown>>);\n return this;\n }\n\n delete(schemaId: SchemaId): boolean {\n return this.data.delete(schemaId);\n }\n\n clear(): void {\n this.data.clear();\n }\n}","export class TagCollection implements Disposable {\n\n private data: Map<object, unknown> = new Map<object, unknown>();\n\n // Delegated to the map rather than tracked in a counter field: every mutation path\n // (set, setMany, combine, delete, dispose) would otherwise have to maintain it, and\n // a missed path silently reports a size that disagrees with the contents.\n get size() {\n return this.data.size;\n }\n\n get(key: object) {\n return this.data.get(key);\n }\n\n has(key: object) {\n return this.data.has(key);\n }\n\n set(key: object, tag: unknown) {\n return this.data.set(key, tag);\n }\n\n delete(key: object) {\n return this.data.delete(key);\n }\n\n setMany(keys: object[], tag: unknown) {\n for (let i = 0, length = keys.length; i < length; i++) {\n const key = keys[i];\n this.set(key, tag);\n }\n }\n\n combine(tags: TagCollection) {\n for (const [key, value] of tags) {\n this.set(key, value);\n }\n }\n\n values() {\n return this.data.values();\n }\n\n keys() {\n return this.data.keys();\n }\n\n [Symbol.dispose]() {\n this.data.clear();\n }\n\n [Symbol.iterator]() {\n return this.data[Symbol.iterator]();\n }\n}","import { PartialResultType, PluginEventPartialResultType, PluginEventResultType, ResultType } from \"./types\";\n\nabstract class BaseResult {\n static ERROR = \"error\" as const;\n static SUCCESS = \"success\" as const;\n static PARTIAL = \"partial\" as const;\n\n static resolve<T>(result: ResultType<T> | PartialResultType<T>, resolve: (data: T) => void, reject: (error?: any) => void) {\n if (result.ok === BaseResult.SUCCESS) {\n resolve(result.data);\n return;\n }\n\n if (result.ok === BaseResult.PARTIAL) {\n reject({\n partial: result.data,\n error: result.error\n });\n return;\n }\n\n reject(result.error);\n }\n\n static assertSuccess<T>(result: any): asserts result is { ok: \"success\"; data: T } {\n if (result.ok !== BaseResult.SUCCESS) {\n throw new Error(`Expected success result, but got ${result.ok}: ${result.error}`);\n }\n }\n}\n\nexport class Result extends BaseResult {\n static success<T>(data: T): ResultType<T>;\n static success(): ResultType<never>;\n static success<T>(data?: T): ResultType<T> {\n return {\n ok: Result.SUCCESS,\n data\n }\n }\n\n static error<T>(error: any): ResultType<T> {\n return {\n ok: Result.ERROR,\n error\n }\n }\n\n static partial<T>(data: T, error: any): PartialResultType<T> {\n return {\n ok: Result.PARTIAL,\n data,\n error\n }\n }\n}\n\nexport class PluginEventResult extends BaseResult {\n static success<T>(id: string, data: T): PluginEventResultType<T>;\n static success(id: string): PluginEventResultType<never>;\n static success<T>(id: string, data?: T): PluginEventResultType<T> {\n return {\n id,\n ok: Result.SUCCESS,\n data\n }\n }\n\n static error<T>(id: string, error: any): PluginEventResultType<T> {\n return {\n id,\n ok: Result.ERROR,\n error\n }\n }\n\n static partial<T>(id: string, data: T, error: any): PluginEventPartialResultType<T> {\n return {\n id,\n ok: Result.PARTIAL,\n data,\n error\n }\n }\n\n static assertSuccess<T>(result: PluginEventResultType<T>): asserts result is { ok: \"success\"; data: T; id: string } {\n if (result.ok !== Result.SUCCESS) {\n throw new Error(`Expected success result, but got ${result.ok}: ${result.error}`);\n }\n }\n}\n","import type { SchemaDefinition } from \"./SchemaDefinition\";\nimport type { SchemaBase } from \"./property/base/SchemaBase\";\nimport type { SchemaArray } from \"./property/types/SchemaArray\";\nimport type { SchemaVector } from \"./property/types/SchemaVector\";\nimport type { SchemaObject } from \"./property/types/SchemaObject\";\nimport type { PropertyInfo } from \"./PropertyInfo\";\nimport type { DeepPartial } from \"../types\";\nimport type { SchemaFunction } from \"./table\";\nimport type { SchemaOptional, SchemaTag, SchemaNullable } from \"./property/modifiers\";\nimport type { Branded } from \"../utilities/types\";\nimport type { SchemaSubscriptionOptions } from \"./communication/broadcast\";\n\nexport type DefaultValue<T, I = never> = T | ((injected: I) => T);\nexport type FunctionBody<TEntity, TResult> = (entity: TEntity, collectionName: CollectionName) => TResult;\nexport type IdType = string | number;\nexport type ForeignKey<T extends {}> = { \n schema: CompiledSchema<T>, \n property: PropertyInfo<T> \n};\n\nexport enum SchemaTypes {\n Array = \"Array\",\n Boolean = \"Boolean\",\n Date = \"Date\",\n Number = \"Number\",\n Object = \"Object\",\n String = \"String\",\n Definition = \"Definition\",\n Function = \"Function\",\n Computed = \"Computed\",\n /**\n * Content in, reference out. The only type whose write shape differs from its stored\n * shape, and a leaf on purpose — see `SchemaFile`.\n */\n File = \"File\",\n /**\n * A fixed-length list of numbers, carrying its dimension count — see `SchemaVector`.\n *\n * Value-shaped exactly like `s.array(s.number())`, which is why every array codegen\n * handler accepts it. It is a distinct type only so a backend can recognise it and store\n * it natively; nothing else needs to tell the two apart.\n */\n Vector = \"Vector\"\n}\n\nexport type ArrayShape = string | number | Date | {};\n\n\n/**\n * What a file property gives back: where the bytes are and what they are.\n *\n * Declared in core so `InferType` can name it. Core never reads or writes the bytes — it only\n * carries this shape — and `@routier/blob-plugin` is what puts one here.\n */\nexport type FileReferenceValue = {\n /** Where the bytes live, content-addressed by the blob plugin. */\n key: string;\n /** Byte length. */\n size: number;\n /** Media type as supplied at upload. */\n contentType: string;\n /** SHA-256 of the bytes, lowercase hex. */\n checksum: string;\n /** The name to show a user. Not part of the key. */\n fileName: string;\n};\n\n/**\n * What a file property ACCEPTS: content, or a reference you already have.\n *\n * `Blob` covers `File`, which is what an `<input type=\"file\">` yields. A reference is accepted\n * too, so re-saving an entity that was read from the database does not have to re-upload it.\n */\nexport type FileContentValue =\n | FileReferenceValue\n | Uint8Array\n | ArrayBuffer\n | Blob\n | string;\n\n/**\n * What a vector property holds, in and out: a plain list of numbers.\n *\n * Named rather than written inline because the inference rules have to recognise it after a\n * modifier has erased which class produced it — the same problem `FileReferenceValue` solves\n * above, and for the same reason.\n */\nexport type VectorValue = number[];\n\n/**\n * What `s.string({ ... })` accepts.\n *\n * Declarations only. Core stores them and never acts on them; a backend that can use one does.\n */\nexport type StringOptions = {\n /**\n * The longest value the property is declared to hold.\n *\n * MySQL uses it for `VARCHAR(maxLength)`; without it every string column is\n * `VARCHAR(255)`, which silently truncates longer values. Other backends ignore it. Core\n * never validates a value against it — see `SchemaBase.maxLength`.\n */\n maxLength?: number;\n};\n\nexport type ExpandedProperty = ExpandedChildProperty & {\n assignmentPath: string;\n selectorPath: string;\n properties: Map<string, ExpandedChildProperty>;\n childDegree: number;\n};\n\nexport type ExpandedChildProperty = {\n propertyName: string;\n type: SchemaTypes;\n isNullableOrOptional: boolean;\n isReadonly: boolean;\n isIdentity: boolean;\n isUnmapped: boolean;\n}\n\nexport enum HashType {\n Ids = \"Ids\",\n Object = \"Object\"\n}\n\nexport type HashFunction<TEntity extends {}> = {\n (entity: InferCreateType<TEntity>, type: HashType.Object): string;\n (entity: InferType<TEntity>, type: HashType.Ids): string;\n}\n\nexport type GetHashTypeFunction<TEntity extends {}> = {\n (entity: InferCreateType<TEntity>): HashType.Object;\n (entity: InferType<TEntity>): HashType.Ids;\n}\n\nexport type ChangeTrackingType = \"proxy\" | \"diff\" | \"immutable\";\n\nexport type IndexType = \"single\" | \"compound\" | \"unique\" | \"primary-key\"\nexport type Index = {\n properties: PropertyInfo<any>[],\n type: IndexType;\n name: string;\n}\n\n/**\n * Represents changes to subscriptions, categorizing them by modifications to\n * entities (additions, updates, removals) or query-driven removals.\n * @template T - The type of the entities in the subscription.\n */\nexport type SubscriptionChanges<T extends {}> = {\n /**\n * Entities that have been added to the subscription.\n */\n adds: InferType<T>[];\n /**\n * Entities that have been updated within the subscription.\n */\n updates: InferType<T>[];\n /**\n * Entities that have been removed from the subscription.\n */\n removals: InferType<T>[];\n /**\n * Entities that have been added/updated/removed from the subscription and it is unknown \n * if the entities have been added/updated/removed.\n */\n unknown: InferType<T>[];\n}\n\nexport interface ISchemaSubscription<T extends {}> extends Disposable {\n send(changes: SubscriptionChanges<T>): void;\n onMessage(callback: (changes: SubscriptionChanges<T>) => void): void;\n}\n\nexport type Enrich<TEntity extends {}> = {\n (entity: InferType<TEntity>, changeTrackingType: ChangeTrackingType): InferType<TEntity>;\n (entity: InferCreateType<TEntity>, changeTrackingType: ChangeTrackingType): InferCreateType<TEntity>;\n}\nexport type Prepare<TEntity extends {}> = {\n (entity: InferCreateType<TEntity>): InferCreateType<TEntity>;\n (entity: InferType<TEntity>): InferType<TEntity>;\n}\nexport type Preprocess<TEntity extends {}> = {\n (entity: InferCreateType<TEntity>): InferType<TEntity>;\n (entity: InferType<TEntity>): InferType<TEntity>;\n}\n\nexport type SetProperties<TEntity extends {}> = (destination: DeepPartial<InferType<TEntity> | InferCreateType<TEntity>>, source: DeepPartial<InferType<TEntity> | InferCreateType<TEntity>>) => void;\n\nexport type CompiledSchemaCore<TEntity extends {}> = Omit<CompiledSchema<TEntity>, \"createSubscription\">;\n\nexport type CompiledSchemaWithMetadata<TEntity extends {}, TMetadata> = {\n readonly metadata: TMetadata;\n} & CompiledSchema<TEntity>;\n\n/**\n * Represents a fully compiled schema with all utilities and metadata for an entity type.\n */\nexport type CompiledSchema<TEntity extends {}> = {\n\n deserializePartial: (item: Record<string, unknown>, properties: PropertyInfo<TEntity>[]) => DeepPartial<InferType<TEntity>>;\n\n createSubscription: (abortSignal?: AbortSignal, scope?: string, options?: SchemaSubscriptionOptions) => ISchemaSubscription<TEntity>;\n /** Returns the property info for a given id (full path) */\n getProperty: (id: string) => PropertyInfo<TEntity>;\n /** Returns the ID of the given entity. */\n getId: (entity: InferType<TEntity>) => IdType;\n /** Returns a deep clone of the given entity. */\n clone: (entity: InferType<TEntity>) => InferType<TEntity>;\n /**\n * Returns a deep clone of a record that is still in the STORAGE shape — renamed properties\n * under their `from` names rather than their in-memory names.\n *\n * `clone` reads in-memory names, so it returns `undefined` for every renamed property of a\n * stored record. Use this when copying rows a store holds before they have been deserialized.\n * Generated on first call; schemas that are never cloned in storage shape never build it.\n */\n cloneStorage: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Removes unmapped or extraneous properties from the entity. */\n strip: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Prepares a new entity for creation, applying defaults and transformations. */\n prepare: Prepare<TEntity>;\n /** Merges the source entity into the destination entity. */\n merge: (destination: InferType<TEntity> | InferCreateType<TEntity>, source: InferType<TEntity>) => InferType<TEntity>;\n /** Indicates if the schema has identity properties. */\n hasIdentities: boolean;\n /** List of properties that are identity keys. */\n idProperties: PropertyInfo<TEntity>[];\n /** All property metadata for the schema. */\n properties: PropertyInfo<TEntity>[],\n /** The hash type used for this schema. */\n hashType: HashType;\n /** Computes a hash for the given entity. */\n hash: HashFunction<TEntity>;\n /** Returns the hash type for the given entity. */\n getHashType: GetHashTypeFunction<TEntity>;\n /** Compares two entities for equality. */\n compare: (a: InferType<TEntity>, fromDb: InferType<TEntity>) => boolean;\n /** Deserializes an entity from storage format. */\n deserialize: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Sets 1 or many properties from the source object onto the destination object with change tracking. */\n set: SetProperties<TEntity>;\n /** Combines serializing and preparing an entity for saving. */\n preprocess: Preprocess<TEntity>;\n /** Combines deserializing and enriching an entity for selection. */\n postprocess: Enrich<TEntity>;\n\n /** Serializes an entity to storage format. */\n serialize: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Unique id for the schema. */\n id: SchemaId,\n /** The name of the collection for this schema. */\n collectionName: CollectionName;\n /** Returns all IDs for the given entity (usually a single-element tuple). */\n getIds: (entity: InferType<TEntity>) => [IdType];\n /** Enriches the entity with change tracking or other metadata. */\n enrich: Enrich<TEntity>;\n /** Indicates if the schema has identity keys. */\n hasIdentityKeys: boolean;\n /** Returns a deeply frozen (immutable) version of the entity. */\n freeze: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** Enables change tracking on the entity. */\n enableChangeTracking: (entity: InferType<TEntity>) => InferType<TEntity>;\n /** The schema definition object. */\n definition: SchemaDefinition<TEntity>;\n /** Returns all indexes defined for this schema. */\n getIndexes: () => Index[];\n /** Compares two entities for Id equality. */\n compareIds: (a: InferType<TEntity>, b: InferType<TEntity>) => boolean;\n}\n\nexport type PropertySerializer<T extends any> = (value: T) => string | number;\nexport type PropertyDeserializer<T extends any> = (value: string | number) => T;\n\n/**\n * A two-way transform between the application value and the stored value.\n *\n * Both directions may be async. Held as a live reference rather than stringified, so a\n * closure works and `injected` is a convenience rather than the only way in.\n */\nexport type PropertyTransform<T extends any> = {\n /**\n * Application value to stored value. Runs before the plugin sees it. May be async.\n *\n * `entity` is there for the one-way case: a transform with no `from` derives a value\n * rather than converting one, which is what `computed` does.\n */\n to: (value: T, entity: Record<string, unknown>) => unknown | Promise<unknown>;\n\n /**\n * Stored value back to application value. Runs after the plugin returns it.\n *\n * Optional. Leave it out and the transform is one-way: the stored value is the value.\n */\n from?: (value: unknown) => T | Promise<T>;\n\n /**\n * What the column becomes, when the stored form is not the property's own type.\n *\n * Defaults to the property's own type, so nothing changes unless you say it does. A\n * library that always produces text — a cipher, a compressor — sets this once, and the\n * caller who uses that library never writes it.\n */\n stores?: SchemaTypes;\n\n /**\n * Whether a filter on this property can still run in the database.\n *\n * Defaults to `none`, which rejects the filter rather than returning wrong rows. Set\n * `equality` only when `to` is deterministic.\n */\n comparable?: 'equality' | 'none';\n};\n\nexport type SchemaId = Branded<number, \"SchemaId\">;\nexport type CollectionName = Branded<string, \"CollectionName\">;\n\nexport type SchemaModifiers = \"default\" | \"deserialize\" |\n \"identity\" | \"key\" |\n \"nullable\" | \"optional\" |\n \"readonly\" | \"serialize\" |\n \"unmapped\" | \"computed\" |\n \"distinct\" | \"searchable\";\n\n/**\n * What a tagged property infers to.\n *\n * `tag()` is metadata and must not change a type, but `SchemaTag<T>` carries the same `T` as\n * whatever it wrapped without carrying which class that was. For a string `T` is already\n * `string`; for an object `T` is the map of child schemas, which only the `SchemaObject`\n * branch below knows how to unwrap. Falling through to the generic `SchemaBase` branch\n * therefore handed the raw map back, so `s.object({ key: s.string() }).tag('x')` typed\n * `key` as `SchemaString` instead of `string` — everything ran, and only the types lied.\n *\n * An array is distinguishable because `SchemaArray`'s parameter is the ELEMENT schema, so a\n * tagged array arrives here as a `SchemaBase` rather than a plain map.\n */\ntype InferTagged<C> = ResolveWrapped<C>;\n\n/**\n * What a wrapping modifier's inner type resolves to.\n *\n * `SchemaOptional`, `SchemaNullable` and `SchemaTag` all carry the same `C` as whatever they\n * wrapped, without carrying which class that was, so each has to work out what it is holding.\n * Three shapes are possible:\n *\n * - an already-resolved value (`string` from `s.string()`, a file reference from `s.file()`)\n * - an ELEMENT schema, which is what `SchemaArray` parameterises on\n * - a map of child schemas, which is what `SchemaObject` parameterises on\n *\n * Getting this wrong is silent. The map branch applied to an already-resolved object walks\n * its keys and infers `never` for each, so `s.file().optional()` typed as\n * `{ key: never, size: never, ... }` — which no value can satisfy and no test would catch at\n * runtime.\n *\n * A map of child schemas goes through `InferCompiledSchema`, not a plain key map, so the\n * children's own `.nullable()`, `.optional()` and `.readonly()` survive the way they do at the\n * top level (#42). That branch cannot take an array — `SchemaObject.array().nullable()` wraps\n * `C = SchemaObject[]` — so an array is resolved element by element before it.\n */\ntype ResolveWrapped<C> =\n C extends string | number | boolean | Date | FileReferenceValue ? C :\n C extends VectorValue ? C :\n C extends SchemaBase<any, any> ? InferPrimitive<C>[] :\n C extends Array<infer E> ? InferPrimitive<E>[] :\n InferCompiledSchema<C>;\n\ntype InferPrimitive<T> =\n T extends SchemaOptional<infer C, infer __> ? ResolveWrapped<C> :\n // `null` itself comes from the parent's `nullable` key partition; this resolves what is\n // underneath. Without it a nullable object fell to the generic `SchemaBase` branch below\n // and typed its children as the raw builder classes.\n T extends SchemaNullable<infer C, infer __> ? ResolveWrapped<C> :\n T extends SchemaTag<infer C, infer __> ? InferTagged<C> :\n // Before the generic `SchemaBase` branch below, which would see `X = number[]` and map\n // the element through `InferPrimitive<number>` — no branch matches a bare `number`, so a\n // vector would type as `never[]`: assignable from nothing, and invisible at runtime.\n T extends SchemaVector<infer __, infer ___> ? VectorValue :\n T extends SchemaArray<infer Y, infer __> ? InferPrimitive<Y>[]\n : T extends SchemaObject<infer Obj, infer _> ?\n InferCompiledSchema<Obj> : // Nested objects keep their children's modifiers\n T extends SchemaFunction<infer F, infer __> ? F : T extends SchemaBase<infer X, infer _> ?\n X extends Array<infer A> ? InferPrimitive<A>[] : X : // Extract the primitive type\n never;\n\nexport type InferType<T> = T extends CompiledSchema<infer R> ? InferCompiledSchema<R> : T extends {} ? InferCompiledSchema<T> : T;\nexport type InferCreateType<T> = T extends CompiledSchema<infer R> ? InferCompiledCreateSchema<R> : T extends {} ? InferCompiledCreateSchema<T> : unknown;\nexport type InferMappedType<T> = T extends SchemaBase<infer K, infer __> ? InferType<K> : InferCompiledSchema<T>;\nexport type InferRoot<T> = T extends CompiledSchema<infer R> ? R : never;\n\ntype HasModifier<T, K extends keyof T, M extends SchemaModifiers> =\n T[K] extends SchemaBase<any, infer Mods> ?\n M extends Mods ? true : false :\n false;\n\ntype IsPlainProperty<T, K extends keyof T> =\n [\n HasModifier<T, K, \"readonly\">,\n HasModifier<T, K, \"optional\">,\n HasModifier<T, K, \"nullable\">\n ] extends [\n false,\n false,\n false\n ] ? true : false;\n\ntype IsCreateExcluded<T, K extends keyof T> =\n [\n HasModifier<T, K, \"identity\">,\n HasModifier<T, K, \"computed\">,\n HasModifier<T, K, \"unmapped\">\n ] extends [\n false,\n false,\n false\n ] ? false : true;\n\ntype IsCreateOptional<T, K extends keyof T> =\n [\n HasModifier<T, K, \"optional\">,\n HasModifier<T, K, \"default\">\n ] extends [\n false,\n false\n ] ? false : true;\n\ntype IsCreateNullable<T, K extends keyof T> =\n HasModifier<T, K, \"nullable\"> extends true ? true : false;\n\n/**\n * What a property ACCEPTS on the way in, which is not always what it gives back.\n *\n * Only a file differs today: you assign content and read a reference. Matching on the read\n * type rather than on `SchemaFile` itself is deliberate — it keeps working through every\n * modifier. `s.file().optional()` is a `SchemaOptional`, `s.file().tag('x')` is a\n * `SchemaTag`, and neither carries the original class, so a check against the class alone\n * would silently stop accepting content the moment anyone added a modifier.\n *\n * Assignability is required in BOTH directions, and the tuple wrappers are load-bearing.\n * One-way `extends` matches `never` — which is assignable to everything — so a generic\n * property over `Record<string, unknown>` resolved to file content and broke the Dexie\n * plugin's types. It also matched any object that merely happens to have these five fields\n * plus more. Mutual assignability admits the reference shape and nothing else, and the\n * tuples stop the conditional distributing over a union.\n */\ntype InferWritePrimitive<T> =\n [InferPrimitive<T>] extends [FileReferenceValue]\n ? [FileReferenceValue] extends [InferPrimitive<T>] ? FileContentValue : InferPrimitive<T>\n : InferPrimitive<T>;\n\ntype InferCreateProperty<T, K extends keyof T> =\n IsCreateNullable<T, K> extends true ? null | InferWritePrimitive<T[K]> : InferWritePrimitive<T[K]>;\n\ntype InferCompiledSchema<T> = CoalesceEmpty<{\n [K in keyof T as IsPlainProperty<T, K> extends true ? K : never]: InferPrimitive<T[K]>\n}, {\n readonly [K in keyof T as HasModifier<T, K, \"readonly\"> extends true ? K : never]: InferPrimitive<T[K]>\n }, {\n [K in keyof T as HasModifier<T, K, \"optional\"> extends true ? K : never]?: InferPrimitive<T[K]>\n }, {\n [K in keyof T as HasModifier<T, K, \"nullable\"> extends true ? K : never]: null | InferPrimitive<T[K]>\n}>;\n\ntype InferCompiledCreateSchema<T> = {\n [K in keyof T as IsCreateExcluded<T, K> extends true ? never\n : IsCreateOptional<T, K> extends true ? K : never]?: InferCreateProperty<T, K>\n} & {\n [K in keyof T as IsCreateExcluded<T, K> extends true ? never\n : IsCreateOptional<T, K> extends true ? never : K]: InferCreateProperty<T, K>\n};\n\ntype IsEmptyObject<T> = keyof T extends never ? true : false;\ntype CoalesceEmpty<T1 extends {}, T2 extends {}, T3 extends {}, T4 extends {}> = (IsEmptyObject<T1> extends true ? {} : T1) & (IsEmptyObject<T2> extends true ? {} : T2) & (IsEmptyObject<T3> extends true ? {} : T3) & (IsEmptyObject<T4> extends true ? {} : T4);\n","import { SchemaTypes } from \"../types\";\n\n/**\n * Types whose runtime value is a JS array.\n *\n * `Array` and `Vector` are the same thing to every layer that copies, compares, hashes or\n * freezes a value — a vector is a list of numbers and nothing more. They differ only where a\n * backend chooses storage, which is the one place that should ask for `SchemaTypes.Vector` by\n * name.\n *\n * This exists so adding a third array-shaped type is one edit rather than a hunt through\n * twelve handlers. Missing one of those is silent in the worst way: a vector that clones by\n * reference is shared with the change tracker's copy, so overwriting an embedding produces no\n * diff and the save reports nothing to do.\n */\nconst ARRAY_VALUED_TYPES = new Set<SchemaTypes>([\n SchemaTypes.Array,\n SchemaTypes.Vector,\n]);\n\n/** True when the property's value is a JS array and needs value rather than reference semantics. */\nexport const isArrayValued = (type: SchemaTypes) => ARRAY_VALUED_TYPES.has(type);\n\n/**\n * True when the property's elements are primitives, so a spread is a sufficient copy.\n *\n * A vector is always numbers, so it never needs the per-element deep copy an array of objects\n * or dates does.\n */\nconst PRIMITIVE_ELEMENT_TYPES = new Set<SchemaTypes | undefined>([\n SchemaTypes.String,\n SchemaTypes.Number,\n SchemaTypes.Boolean,\n]);\n\nexport const hasPrimitiveElements = (type: SchemaTypes, elementType: SchemaTypes | undefined) =>\n type === SchemaTypes.Vector || PRIMITIVE_ELEMENT_TYPES.has(elementType);\n","import { PropertyInfo } from \"../PropertyInfo\";\nimport { CompiledSchema, SchemaTypes } from \"../types\";\nimport { isArrayValued } from \"./propertyKind\";\n\n/**\n * Turns the dates on a STORAGE-shape record back into Dates, in place.\n *\n * The datastore serializes a Date to an ISO string, and a store that persists JSON hands the\n * string back. A plugin that runs the caller's lambdas over its own records has to undo that\n * first: a string is never greater than a Date and has no `getTime()`. It is the one thing JSON\n * changed, so it is the one thing undone. Keys stay under their `from` names, because the\n * datastore deserializes the rows the plugin returns, by those names.\n *\n * Not the full `schema.deserialize`, which also moves every key to its in-memory name: rows\n * deserialized twice lose every renamed property.\n *\n * Only a string is converted, so a Date the store kept as a Date is left alone, and so is a\n * record that was already revived. The datastore's own deserialize does the same, so a revived\n * record deserializes to the same entity.\n */\nexport type StorageDateReviver = (record: Record<string, unknown>) => void;\n\ntype DatePath = {\n /** Storage names from the root, the date itself last. */\n readonly segments: readonly string[];\n /** An array of dates rather than one. */\n readonly isArray: boolean;\n};\n\nconst collectDatePaths = (properties: readonly PropertyInfo<any>[], paths: DatePath[]) => {\n for (const property of properties) {\n\n // The stored value belongs to whoever wrote it: a custom serializer, deserializer or\n // transform reads it back, and would be handed a Date it did not expect. Unmapped\n // properties are never stored.\n if (property.valueSerializer != null || property.valueDeserializer != null || property.transform != null || property.isUnmapped) {\n continue;\n }\n\n if (property.type === SchemaTypes.Object) {\n collectDatePaths(property.children, paths);\n continue;\n }\n\n const isArray = isArrayValued(property.type) && property.innerSchema?.type === SchemaTypes.Date;\n\n if (property.type !== SchemaTypes.Date && isArray === false) {\n continue;\n }\n\n paths.push({\n segments: [...property.getParentPathArray({ useFromPropertyName: true }), property.getResolvedName()],\n isArray\n });\n }\n};\n\nconst reviveAt = (record: Record<string, unknown>, path: DatePath) => {\n const { segments } = path;\n let parent: any = record;\n\n for (let i = 0, length = segments.length - 1; i < length; i++) {\n parent = parent[segments[i]];\n\n // An absent or null parent holds no date\n if (parent == null || typeof parent !== \"object\") {\n return;\n }\n }\n\n const key = segments[segments.length - 1];\n const value = parent[key];\n\n if (path.isArray === false) {\n if (typeof value === \"string\") {\n parent[key] = new Date(value);\n }\n\n return;\n }\n\n if (Array.isArray(value)) {\n for (let i = 0, length = value.length; i < length; i++) {\n if (typeof value[i] === \"string\") {\n value[i] = new Date(value[i]);\n }\n }\n }\n};\n\n/** Per schema: `null` for a schema with no dates, so a caller can skip the pass. */\nconst revivers = new WeakMap<object, StorageDateReviver | null>();\n\n/**\n * The reviver for `schema`'s records, or `null` when it declares no dates.\n *\n * Built once per compiled schema. A read revives every row it returns, so the paths are resolved\n * here rather than per row.\n */\nexport const getStorageDateReviver = (schema: CompiledSchema<any>): StorageDateReviver | null => {\n const cached = revivers.get(schema);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const paths: DatePath[] = [];\n\n collectDatePaths(schema.properties, paths);\n\n const reviver: StorageDateReviver | null = paths.length === 0\n ? null\n : record => {\n for (let i = 0, length = paths.length; i < length; i++) {\n reviveAt(record, paths[i]);\n }\n };\n\n revivers.set(schema, reviver);\n\n return reviver;\n};\n","export const uuid = (length: number = 16): string => {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n const charLength = chars.length;\n let result = '';\n\n for (let i = 0; i < length; i++) {\n result += chars[Math.random() * charLength | 0];\n }\n return result;\n}\n\nconst HEX_CHARS = '0123456789abcdef';\nconst UUID_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';\n\nconst hasCrypto =\n typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function';\n\nconst hasRandomUUID =\n typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function';\n\nexport const uuidv4 = (): string => {\n if (hasRandomUUID) {\n return crypto.randomUUID();\n }\n\n return uuidv4Fallback();\n};\n\nconst uuidv4Fallback = (): string => {\n let randomBytes: Uint8Array | null = null;\n if (hasCrypto) {\n randomBytes = crypto.getRandomValues(new Uint8Array(16));\n }\n\n let byteIndex = 0;\n let uuid = '';\n\n for (let i = 0; i < UUID_TEMPLATE.length; i++) {\n const c = UUID_TEMPLATE[i];\n if (c === '-') {\n uuid += '-';\n continue;\n }\n\n let r: number;\n if (hasCrypto && randomBytes) {\n // Each byte gives two hex digits (nibbles)\n r =\n (i % 2 === 0\n ? randomBytes[byteIndex] >> 4\n : randomBytes[byteIndex++] & 0x0f);\n } else {\n r = Math.floor(Math.random() * 16);\n }\n\n if (c === 'x') {\n uuid += HEX_CHARS[r];\n } else if (c === 'y') {\n // Variant bits: 8, 9, A, or B\n uuid += HEX_CHARS[(r & 0x3) | 0x8];\n } else if (c === '4') {\n uuid += '4';\n }\n }\n\n return uuid;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import { IdType } from \"../schema\";\n\nexport class IdSet {\n\n readonly ids: readonly IdType[];\n\n constructor(...ids: IdType[]) {\n this.ids = Object.freeze(ids);\n }\n\n equals(other: IdSet): boolean {\n\n if (this.ids.length === 1) {\n return this.ids[0] === other.ids[0];\n }\n\n return this.toString() === other.toString();\n }\n\n toString(): string {\n\n if (this.ids.length === 1) {\n return String(this.ids[0]);\n }\n\n return this.ids.toString();\n }\n}","import { CompiledSchema, getStorageDateReviver, IdType, InferType, PropertyInfo, SchemaTypes } from \"../schema\";\nimport { CallbackResult, Result } from \"../results\";\nimport { uuidv4 } from \"../utilities\";\nimport { IdSet } from \"./IdSet\";\n\nexport class MemoryDataCollection {\n\n protected readonly nextNumericalIds: Map<string, number>;\n protected readonly data: Map<string, Record<string, unknown>>;\n protected readonly schema: CompiledSchema<any>;\n protected readonly idProperties: PropertyInfo<any>[];\n\n get size() {\n return this.data.size;\n }\n\n get records() {\n return [...this.data.values()];\n }\n\n /** Iterates stored records without materializing them into an array. */\n values(): IterableIterator<Record<string, unknown>> {\n return this.data.values();\n }\n\n constructor(schema: CompiledSchema<any>) {\n this.data = new Map<string, Record<string, unknown>>();\n this.nextNumericalIds = new Map<string, number>();\n this.schema = schema;\n this.idProperties = schema.idProperties;\n }\n\n private _getNextId(property: PropertyInfo<any>) {\n\n let nextId = 1;\n\n if (this.nextNumericalIds.has(property.id) === true) {\n nextId = this.nextNumericalIds.get(property.id) + 1;\n }\n\n this.nextNumericalIds.set(property.id, nextId);\n\n return nextId;\n }\n\n private resolveId(property: PropertyInfo<any>, value: unknown) {\n if (typeof value !== \"number\") {\n return;\n }\n\n const currentIdForProperty = this.nextNumericalIds.get(property.id);\n\n if (value <= currentIdForProperty) {\n return;\n }\n\n this.nextNumericalIds.set(property.id, value);\n }\n\n private getAndSetId(item: Record<string, unknown>, property: PropertyInfo<any>): IdType {\n if (item[property.name] != null) {\n return item[property.name] as IdType;\n }\n\n if (property.type === SchemaTypes.String) {\n const uuid = uuidv4()\n item[property.name] = uuid;\n return uuid;\n }\n\n if (property.type === SchemaTypes.Number) {\n const id = this._getNextId(property);\n item[property.name] = id;\n return id;\n }\n\n throw new Error(`Id Property '${property.name}' must be string or number, found '${property.type}'`)\n }\n\n /**\n * The record this collection keeps.\n *\n * A copy, so a caller holding the entity cannot write into the store afterwards. Dates are held\n * as Dates, at the root, in objects and in arrays: a predicate compares a Date, and a stored ISO\n * string never matches one. A durable subclass hydrates parsed JSON through here too.\n */\n private toStored(item: Record<string, unknown>): Record<string, unknown> {\n const stored = { ...item };\n\n getStorageDateReviver(this.schema)?.(stored);\n\n return stored;\n }\n\n seed(items: Record<string, unknown>[]) {\n for (let i = 0, length = items.length; i < length; i++) {\n const id = this.resolveIdSet(items[i] as InferType<unknown>);\n this.data.set(id.toString(), this.toStored(items[i]));\n }\n }\n\n private resolveCurrentIdSet(item: Record<string, unknown>): IdSet {\n const idProperties = this.schema.idProperties;\n const ids: IdType[] = [];\n // ensure keys\n for (let j = 0, l = idProperties.length; j < l; j++) {\n const property = idProperties[j];\n const value = property.getValue(item);\n\n if (value == null) {\n throw new Error(`Key cannot be null. Key: ${property.name}`);\n }\n\n ids.push(value);\n }\n\n return new IdSet(...ids);\n }\n\n private resolveIdSet(item: Record<string, unknown>): IdSet {\n\n if (this.schema.hasIdentityKeys) {\n const idProperties = this.schema.idProperties;\n const ids: IdType[] = Array.from({ length: idProperties.length });\n\n // Need to make sure we allow for seeding the collection when we call add vs seed\n // There will be an existing id, but the id type could still be identity\n if (idProperties.length === 1) {\n const value = this.getAndSetId(item, idProperties[0]);\n this.resolveId(idProperties[0], value);\n ids[0] = value;\n } else {\n for (let j = 0, l = idProperties.length; j < l; j++) {\n const value = this.getAndSetId(item, idProperties[j]);\n this.resolveId(idProperties[j], value);\n ids[j] = value;\n }\n }\n\n return new IdSet(...ids);\n }\n\n return this.resolveCurrentIdSet(item);\n }\n\n add(item: Record<string, unknown>) {\n const id = this.resolveIdSet(item);\n this.data.set(id.toString(), this.toStored(item));\n }\n\n /**\n * Adds a record only when no record with the same key is present. Durable\n * collections use this to hydrate stored records around in-memory mutations\n * without clobbering them.\n */\n addIfAbsent(item: Record<string, unknown>) {\n const id = this.resolveIdSet(item);\n const key = id.toString();\n\n if (this.data.has(key) === false) {\n this.data.set(key, this.toStored(item));\n }\n }\n\n /**\n * Looks up a single record by its key values without scanning the collection.\n * @param ids Key values in schema id property order\n * @returns The matching record or undefined when no record has the given key\n */\n getByIds(ids: IdType[]): Record<string, unknown> | undefined {\n return this.data.get(new IdSet(...ids).toString());\n }\n\n remove(item: Record<string, unknown>) {\n const id = this.resolveCurrentIdSet(item);\n this.data.delete(id.toString());\n }\n\n update(item: Record<string, unknown>) {\n const id = this.resolveCurrentIdSet(item);\n this.data.set(id.toString(), this.toStored(item));\n }\n\n destroy(done: CallbackResult<never>) {\n this.nextNumericalIds.clear();\n this.data.clear();\n done(Result.success());\n }\n\n load(done: CallbackResult<never>) {\n done(Result.success())\n }\n\n save(done: CallbackResult<never>) {\n done(Result.success())\n }\n}","export * from './Changes';\nexport * from './TagCollection';\nexport * from './IdSet';\nexport * from './MemoryDataCollection';\nexport * from './SchemaCollection';\nexport * from './ReadonlySchemaCollection';"],"names":["TagCollection","BulkPersistResult","Map","schemaId","SchemaPersistResult","count","result","BulkPersistChanges","SchemaPersistChanges","ReadonlySchemaCollection","data","callbackfn","thisArg","Symbol","collectionName","found","x","undefined","SchemaCollection","schema","key","tag","keys","i","length","tags","value","BaseResult","resolve","reject","Error","Result","error","PluginEventResult","id","SchemaTypes","HashType","ARRAY_VALUED_TYPES","Set","isArrayValued","type","PRIMITIVE_ELEMENT_TYPES","hasPrimitiveElements","elementType","collectDatePaths","properties","paths","property","isArray","reviveAt","record","path","segments","parent","Date","Array","revivers","WeakMap","getStorageDateReviver","cached","reviver","uuid","chars","charLength","Math","HEX_CHARS","UUID_TEMPLATE","hasCrypto","crypto","hasRandomUUID","uuidv4","uuidv4Fallback","randomBytes","Uint8Array","byteIndex","c","r","IdSet","ids","Object","other","String","MemoryDataCollection","nextId","currentIdForProperty","item","stored","items","idProperties","j","l","done"],"mappings":";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) {
|
|
723
723
|
__webpack_require__.d(__webpack_exports__, {
|
|
724
724
|
MY: () => (toExpression),
|
|
725
|
+
Pl: () => (parseSelector),
|
|
725
726
|
oH: () => (parseFragment),
|
|
726
727
|
pg: () => (combineExpressions)
|
|
727
728
|
});
|
|
@@ -730,6 +731,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
730
731
|
/* import */ var _schema__rspack_import_2 = __webpack_require__(537);
|
|
731
732
|
/* import */ var _evaluate__rspack_import_3 = __webpack_require__(379);
|
|
732
733
|
/* import */ var _fold__rspack_import_4 = __webpack_require__(43);
|
|
734
|
+
/* import */ var _utils__rspack_import_6 = __webpack_require__(63);
|
|
733
735
|
/* import */ var _types__rspack_import_1 = __webpack_require__(27);
|
|
734
736
|
|
|
735
737
|
|
|
@@ -737,6 +739,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
737
739
|
|
|
738
740
|
|
|
739
741
|
|
|
742
|
+
|
|
740
743
|
// Error message constants
|
|
741
744
|
const ERROR_MESSAGES = {
|
|
742
745
|
PROPERTY_NOT_FOUND: (path)=>`Error parsing query, could not find PropertyInfo for path: ${path}`,
|
|
@@ -1344,6 +1347,9 @@ const COALESCE_OPERATORS = sourceKeyed({
|
|
|
1344
1347
|
// A comparison always names a schema property, so the condition alone settles it
|
|
1345
1348
|
return true;
|
|
1346
1349
|
}
|
|
1350
|
+
if (operand.kind === "opaque") {
|
|
1351
|
+
return operand.reads.some(containsProperty);
|
|
1352
|
+
}
|
|
1347
1353
|
return operand.kind === "arithmetic" && (containsProperty(operand.left) || containsProperty(operand.right) || operand.extra != null && containsProperty(operand.extra));
|
|
1348
1354
|
};
|
|
1349
1355
|
const DECLARATION_KEYWORDS = new Set([
|
|
@@ -1521,13 +1527,18 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
1521
1527
|
scope;
|
|
1522
1528
|
paramsName;
|
|
1523
1529
|
params;
|
|
1530
|
+
/**
|
|
1531
|
+
* Whether this parses a value selector rather than a filter, and so reads a call it has no node for
|
|
1532
|
+
* as an `OpaqueOperand` instead of refusing it.
|
|
1533
|
+
*/ readsValues;
|
|
1524
1534
|
/** Set when a param value shaped the tree itself (e.g. x[p.name]) — such templates cannot be cached. */ structurallyDependsOnParams = false;
|
|
1525
|
-
constructor(schema, stream, scope, paramsName, params){
|
|
1535
|
+
constructor(schema, stream, scope, paramsName, params, readsValues = false){
|
|
1526
1536
|
this.schema = schema;
|
|
1527
1537
|
this.stream = stream;
|
|
1528
1538
|
this.scope = scope;
|
|
1529
1539
|
this.paramsName = paramsName;
|
|
1530
1540
|
this.params = params;
|
|
1541
|
+
this.readsValues = readsValues;
|
|
1531
1542
|
}
|
|
1532
1543
|
parse() {
|
|
1533
1544
|
const expression = this.parseOr();
|
|
@@ -1549,6 +1560,71 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
1549
1560
|
}
|
|
1550
1561
|
return answer;
|
|
1551
1562
|
}
|
|
1563
|
+
/**
|
|
1564
|
+
* What a value selector returns: one value, or the fields of an object literal.
|
|
1565
|
+
*
|
|
1566
|
+
* A block body is read only when it does nothing but return, which is what a transpiler makes of an
|
|
1567
|
+
* arrow function. Anything more is refused, and the caller falls back to running the function.
|
|
1568
|
+
*/ parseSelector() {
|
|
1569
|
+
const block = this.stream.matchPunctuation("{");
|
|
1570
|
+
if (block) {
|
|
1571
|
+
const keyword = this.stream.next();
|
|
1572
|
+
if (keyword.kind !== "identifier" || keyword.value !== "return") {
|
|
1573
|
+
throw new Error(ERROR_MESSAGES.UNSUPPORTED("a selector block that does more than return"));
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
const selected = this.stream.isPunctuation("{") ? this.parseObjectLiteral() : this.stream.isPunctuation("(") && this.stream.isPunctuation("{", 1) ? this.parseBracketedObjectLiteral() : this.parseInterpolation();
|
|
1577
|
+
if (block) {
|
|
1578
|
+
this.stream.matchPunctuation(";");
|
|
1579
|
+
this.stream.expectPunctuation("}");
|
|
1580
|
+
}
|
|
1581
|
+
if (!this.stream.isAtEnd) {
|
|
1582
|
+
throw new Error(ERROR_MESSAGES.UNSUPPORTED(`unexpected token '${this.stream.peek()?.value}'`));
|
|
1583
|
+
}
|
|
1584
|
+
return selected;
|
|
1585
|
+
}
|
|
1586
|
+
/** `({ … })`, the arrow body that returns an object. */ parseBracketedObjectLiteral() {
|
|
1587
|
+
this.stream.expectPunctuation("(");
|
|
1588
|
+
const fields = this.parseObjectLiteral();
|
|
1589
|
+
this.stream.expectPunctuation(")");
|
|
1590
|
+
return fields;
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* The fields of an object literal, each one value.
|
|
1594
|
+
*
|
|
1595
|
+
* A field's value is read without a top-level conditional, which needs brackets here: the look-ahead
|
|
1596
|
+
* for a `?` does not stop at the comma that ends the field.
|
|
1597
|
+
*/ parseObjectLiteral() {
|
|
1598
|
+
this.stream.expectPunctuation("{");
|
|
1599
|
+
const fields = [];
|
|
1600
|
+
while(!this.stream.matchPunctuation("}")){
|
|
1601
|
+
const key = this.stream.next();
|
|
1602
|
+
if (key.kind !== "identifier" && key.kind !== "string") {
|
|
1603
|
+
throw new Error(ERROR_MESSAGES.UNSUPPORTED(`the object key '${key.value}'`));
|
|
1604
|
+
}
|
|
1605
|
+
fields.push({
|
|
1606
|
+
name: key.value,
|
|
1607
|
+
operand: this.stream.matchPunctuation(":") ? this.parseValue() : this.parseShorthand(key)
|
|
1608
|
+
});
|
|
1609
|
+
if (!this.stream.matchPunctuation(",")) {
|
|
1610
|
+
this.stream.expectPunctuation("}");
|
|
1611
|
+
break;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
return fields;
|
|
1615
|
+
}
|
|
1616
|
+
/** `{ name }`, which reads what the parameter list bound `name` to. */ parseShorthand(key) {
|
|
1617
|
+
const binding = key.kind === "identifier" ? this.scope.get(key.value) : undefined;
|
|
1618
|
+
if (binding == null || binding.kind === "inlined") {
|
|
1619
|
+
throw new Error(ERROR_MESSAGES.VARIABLE_VALUE(key.value));
|
|
1620
|
+
}
|
|
1621
|
+
return this.parseChain({
|
|
1622
|
+
kind: binding.kind,
|
|
1623
|
+
path: [
|
|
1624
|
+
...binding.path
|
|
1625
|
+
]
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1552
1628
|
/** The expression a `{ … }` block answers with. */ parseBlock() {
|
|
1553
1629
|
this.stream.expectPunctuation("{");
|
|
1554
1630
|
const answer = this.parseStatements();
|
|
@@ -1812,7 +1888,7 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
1812
1888
|
* A structural dependence found inside propagates outward: the template it belongs to cannot be
|
|
1813
1889
|
* cached either.
|
|
1814
1890
|
*/ parseNested(source) {
|
|
1815
|
-
const nested = new ExpressionParser(this.schema, new TokenStream(tokenize(source)), this.scope, this.paramsName, this.params);
|
|
1891
|
+
const nested = new ExpressionParser(this.schema, new TokenStream(tokenize(source)), this.scope, this.paramsName, this.params, this.readsValues);
|
|
1816
1892
|
const operand = nested.parseInterpolation();
|
|
1817
1893
|
// Leftover tokens mean the interpolation held something this reads only part of. Silently
|
|
1818
1894
|
// keeping the part it understood is the worst outcome available: `${x.age > 5 ? "a" : "b"}`
|
|
@@ -2104,7 +2180,7 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
2104
2180
|
if (argument.kind === "method-call") {
|
|
2105
2181
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED("nested method call inside .includes()"));
|
|
2106
2182
|
}
|
|
2107
|
-
if (argument.kind === "arithmetic" || argument.kind === "conditional") {
|
|
2183
|
+
if (argument.kind === "arithmetic" || argument.kind === "conditional" || argument.kind === "opaque") {
|
|
2108
2184
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED("arithmetic inside .includes()"));
|
|
2109
2185
|
}
|
|
2110
2186
|
return {
|
|
@@ -2198,7 +2274,7 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
2198
2274
|
if (argument.kind === "method-call") {
|
|
2199
2275
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED(`nested method call inside .${method}()`));
|
|
2200
2276
|
}
|
|
2201
|
-
if (argument.kind === "arithmetic" || argument.kind === "conditional") {
|
|
2277
|
+
if (argument.kind === "arithmetic" || argument.kind === "conditional" || argument.kind === "opaque") {
|
|
2202
2278
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED(`arithmetic inside .${method}()`));
|
|
2203
2279
|
}
|
|
2204
2280
|
return {
|
|
@@ -2208,9 +2284,20 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
2208
2284
|
argument
|
|
2209
2285
|
};
|
|
2210
2286
|
}
|
|
2287
|
+
if (this.readsValues) {
|
|
2288
|
+
return this.withGroupCall(this.opaqueCall(this.resolveChain(options.kind, path, transformer, locale)));
|
|
2289
|
+
}
|
|
2211
2290
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED(`method '.${method}()'`));
|
|
2212
2291
|
}
|
|
2213
2292
|
if (transformer != null) {
|
|
2293
|
+
if (this.readsValues) {
|
|
2294
|
+
return this.withGroupCall({
|
|
2295
|
+
kind: "opaque",
|
|
2296
|
+
reads: [
|
|
2297
|
+
this.resolveChain(options.kind, path, transformer, locale)
|
|
2298
|
+
]
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2214
2301
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED("property access after a transform method"));
|
|
2215
2302
|
}
|
|
2216
2303
|
path.push(segment.value);
|
|
@@ -2355,10 +2442,39 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
2355
2442
|
argument
|
|
2356
2443
|
};
|
|
2357
2444
|
}
|
|
2445
|
+
// Any other member or call of a value, which a selector reads through
|
|
2446
|
+
if (this.readsValues) {
|
|
2447
|
+
this.stream.next();
|
|
2448
|
+
this.stream.next();
|
|
2449
|
+
receiver = this.stream.isPunctuation("(") ? this.opaqueCall(receiver) : {
|
|
2450
|
+
kind: "opaque",
|
|
2451
|
+
reads: [
|
|
2452
|
+
receiver
|
|
2453
|
+
]
|
|
2454
|
+
};
|
|
2455
|
+
continue;
|
|
2456
|
+
}
|
|
2358
2457
|
break;
|
|
2359
2458
|
}
|
|
2360
2459
|
return receiver;
|
|
2361
2460
|
}
|
|
2461
|
+
/** A call with no node of its own, from its `(`, kept for what its receiver and arguments read. */ opaqueCall(receiver) {
|
|
2462
|
+
const reads = [
|
|
2463
|
+
receiver
|
|
2464
|
+
];
|
|
2465
|
+
this.stream.expectPunctuation("(");
|
|
2466
|
+
while(!this.stream.matchPunctuation(")")){
|
|
2467
|
+
reads.push(this.parseValue());
|
|
2468
|
+
if (!this.stream.matchPunctuation(",")) {
|
|
2469
|
+
this.stream.expectPunctuation(")");
|
|
2470
|
+
break;
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
return {
|
|
2474
|
+
kind: "opaque",
|
|
2475
|
+
reads
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2362
2478
|
withValueTransformer(operand) {
|
|
2363
2479
|
if (this.stream.isPunctuation(".")) {
|
|
2364
2480
|
const method = this.stream.peek(1);
|
|
@@ -2392,6 +2508,10 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
2392
2508
|
if (right.kind === "method-call") {
|
|
2393
2509
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED("method call on the right side of a comparison"));
|
|
2394
2510
|
}
|
|
2511
|
+
// A comparison is a tree a backend renders, and this operand has no node in one
|
|
2512
|
+
if (left.kind === "opaque" || right.kind === "opaque") {
|
|
2513
|
+
throw new Error(ERROR_MESSAGES.UNSUPPORTED("a call with no expression form inside a comparison"));
|
|
2514
|
+
}
|
|
2395
2515
|
if (needsBrackets(left) || needsBrackets(right)) {
|
|
2396
2516
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED("a bitwise or nullish operator compared without brackets, which JavaScript reads the other way round"));
|
|
2397
2517
|
}
|
|
@@ -2605,6 +2725,9 @@ const resolveParamPath = (paramsName, path, data)=>{
|
|
|
2605
2725
|
if (operand.kind === "method-call") {
|
|
2606
2726
|
throw new Error(ERROR_MESSAGES.UNSUPPORTED("a method call inside arithmetic"));
|
|
2607
2727
|
}
|
|
2728
|
+
if (operand.kind === "opaque") {
|
|
2729
|
+
throw new Error(ERROR_MESSAGES.UNSUPPORTED("a call with no expression form inside arithmetic"));
|
|
2730
|
+
}
|
|
2608
2731
|
return this.createValueExpression(operand, null, /* applyConverter */ false);
|
|
2609
2732
|
}
|
|
2610
2733
|
createPropertyExpression(operand) {
|
|
@@ -2940,6 +3063,104 @@ const toExpression = (schema, fn, params)=>{
|
|
|
2940
3063
|
return _types__rspack_import_1/* .Expression.notParsable */.r4.notParsable(refusalOf(error));
|
|
2941
3064
|
}
|
|
2942
3065
|
};
|
|
3066
|
+
const collectReads = (operand, into)=>{
|
|
3067
|
+
switch(operand.kind){
|
|
3068
|
+
case "property":
|
|
3069
|
+
into.add(operand.property);
|
|
3070
|
+
return;
|
|
3071
|
+
case "method-call":
|
|
3072
|
+
collectReads(operand.target, into);
|
|
3073
|
+
collectReads(operand.argument, into);
|
|
3074
|
+
return;
|
|
3075
|
+
case "arithmetic":
|
|
3076
|
+
collectReads(operand.left, into);
|
|
3077
|
+
collectReads(operand.right, into);
|
|
3078
|
+
if (operand.extra != null) {
|
|
3079
|
+
collectReads(operand.extra, into);
|
|
3080
|
+
}
|
|
3081
|
+
return;
|
|
3082
|
+
case "conditional":
|
|
3083
|
+
for (const property of (0,_utils__rspack_import_6/* .getProperties */.oY)(operand.condition)){
|
|
3084
|
+
into.add(property);
|
|
3085
|
+
}
|
|
3086
|
+
collectReads(operand.whenTrue, into);
|
|
3087
|
+
collectReads(operand.whenFalse, into);
|
|
3088
|
+
return;
|
|
3089
|
+
case "opaque":
|
|
3090
|
+
for (const read of operand.reads){
|
|
3091
|
+
collectReads(read, into);
|
|
3092
|
+
}
|
|
3093
|
+
return;
|
|
3094
|
+
}
|
|
3095
|
+
};
|
|
3096
|
+
const selectedValue = (operand)=>{
|
|
3097
|
+
const found = new Set();
|
|
3098
|
+
collectReads(operand, found);
|
|
3099
|
+
const reads = [
|
|
3100
|
+
...found
|
|
3101
|
+
];
|
|
3102
|
+
return {
|
|
3103
|
+
property: reads.length === 1 ? reads[0] : null,
|
|
3104
|
+
reads,
|
|
3105
|
+
isDirectProperty: operand.kind === "property" && operand.transformer == null
|
|
3106
|
+
};
|
|
3107
|
+
};
|
|
3108
|
+
// Keyed like the template cache. A selector takes no params, so every result is cacheable
|
|
3109
|
+
const selectorCache = new WeakMap();
|
|
3110
|
+
/**
|
|
3111
|
+
* Reads a sort, map, group or `nearest` selector with the grammar filters use, for what its value is
|
|
3112
|
+
* read from.
|
|
3113
|
+
*
|
|
3114
|
+
* Not for evaluating it: the caller's function stays the value, and nothing here renders one. A plugin
|
|
3115
|
+
* decides from the result whether it can run the option. One that orders or projects by column cannot
|
|
3116
|
+
* run a value that is not the property itself, and one that runs the function over stored rows cannot
|
|
3117
|
+
* run it over a renamed property.
|
|
3118
|
+
*
|
|
3119
|
+
* So the grammar is wider here than for a filter. A call it has no node for, such as `getFullYear()`,
|
|
3120
|
+
* is kept for the operands it reads rather than refused, since the function it came from still runs.
|
|
3121
|
+
*
|
|
3122
|
+
* `not-parsable` is not logged. The option runs as it did before the selector was parsed.
|
|
3123
|
+
*
|
|
3124
|
+
* Cached by function source per schema, like `toExpression`. The result is shared, so it is read-only.
|
|
3125
|
+
*/ const parseSelector = (schema, selector)=>{
|
|
3126
|
+
const source = selector.toString();
|
|
3127
|
+
let bySource = selectorCache.get(schema);
|
|
3128
|
+
const cached = bySource?.get(source);
|
|
3129
|
+
if (cached != null) {
|
|
3130
|
+
return cached;
|
|
3131
|
+
}
|
|
3132
|
+
let parsed;
|
|
3133
|
+
try {
|
|
3134
|
+
const shape = resolveFunctionShape(source, false);
|
|
3135
|
+
const parser = new ExpressionParser(schema, new TokenStream(tokenize(shape.body)), shape.scope, null, undefined, true);
|
|
3136
|
+
const selected = parser.parseSelector();
|
|
3137
|
+
parsed = Array.isArray(selected) ? {
|
|
3138
|
+
kind: "object",
|
|
3139
|
+
fields: selected.map((field)=>({
|
|
3140
|
+
name: field.name,
|
|
3141
|
+
...selectedValue(field.operand)
|
|
3142
|
+
}))
|
|
3143
|
+
} : {
|
|
3144
|
+
kind: "value",
|
|
3145
|
+
value: selectedValue(selected)
|
|
3146
|
+
};
|
|
3147
|
+
} catch (error) {
|
|
3148
|
+
parsed = {
|
|
3149
|
+
kind: "not-parsable",
|
|
3150
|
+
reason: refusalOf(error)
|
|
3151
|
+
};
|
|
3152
|
+
}
|
|
3153
|
+
if (bySource == null) {
|
|
3154
|
+
bySource = new Map();
|
|
3155
|
+
selectorCache.set(schema, bySource);
|
|
3156
|
+
}
|
|
3157
|
+
// Stryker disable next-line all: the same resource bound as the template cache's
|
|
3158
|
+
if (bySource.size >= MAX_CACHED_TEMPLATES_PER_SCHEMA) {
|
|
3159
|
+
bySource.clear();
|
|
3160
|
+
}
|
|
3161
|
+
bySource.set(source, parsed);
|
|
3162
|
+
return parsed;
|
|
3163
|
+
}; // #endregion
|
|
2943
3164
|
|
|
2944
3165
|
|
|
2945
3166
|
},
|
|
@@ -3579,6 +3800,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3579
3800
|
getProperties: () => (/* reexport safe */ _utils__rspack_import_5.oY),
|
|
3580
3801
|
operandValue: () => (/* reexport safe */ _evaluate__rspack_import_1.Vv),
|
|
3581
3802
|
parseFragment: () => (/* reexport safe */ _parser__rspack_import_3.oH),
|
|
3803
|
+
parseSelector: () => (/* reexport safe */ _parser__rspack_import_3.Pl),
|
|
3582
3804
|
peelCalls: () => (/* reexport safe */ _utils__rspack_import_5.CC),
|
|
3583
3805
|
renderCallAsJs: () => (/* reexport safe */ _callSource__rspack_import_0.a),
|
|
3584
3806
|
toExpression: () => (/* reexport safe */ _parser__rspack_import_3.MY),
|