@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
|
@@ -379,6 +379,128 @@ var HashType = /*#__PURE__*/ (/* unused pure expression or super */ null && (fun
|
|
|
379
379
|
}({})));
|
|
380
380
|
|
|
381
381
|
|
|
382
|
+
},
|
|
383
|
+
575(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
384
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
385
|
+
l: () => (isArrayValued)
|
|
386
|
+
});
|
|
387
|
+
/* import */ var _types__rspack_import_0 = __webpack_require__(537);
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Types whose runtime value is a JS array.
|
|
391
|
+
*
|
|
392
|
+
* `Array` and `Vector` are the same thing to every layer that copies, compares, hashes or
|
|
393
|
+
* freezes a value — a vector is a list of numbers and nothing more. They differ only where a
|
|
394
|
+
* backend chooses storage, which is the one place that should ask for `SchemaTypes.Vector` by
|
|
395
|
+
* name.
|
|
396
|
+
*
|
|
397
|
+
* This exists so adding a third array-shaped type is one edit rather than a hunt through
|
|
398
|
+
* twelve handlers. Missing one of those is silent in the worst way: a vector that clones by
|
|
399
|
+
* reference is shared with the change tracker's copy, so overwriting an embedding produces no
|
|
400
|
+
* diff and the save reports nothing to do.
|
|
401
|
+
*/ const ARRAY_VALUED_TYPES = new Set([
|
|
402
|
+
_types__rspack_import_0/* .SchemaTypes.Array */.L.Array,
|
|
403
|
+
_types__rspack_import_0/* .SchemaTypes.Vector */.L.Vector
|
|
404
|
+
]);
|
|
405
|
+
/** True when the property's value is a JS array and needs value rather than reference semantics. */ const isArrayValued = (type)=>ARRAY_VALUED_TYPES.has(type);
|
|
406
|
+
/**
|
|
407
|
+
* True when the property's elements are primitives, so a spread is a sufficient copy.
|
|
408
|
+
*
|
|
409
|
+
* A vector is always numbers, so it never needs the per-element deep copy an array of objects
|
|
410
|
+
* or dates does.
|
|
411
|
+
*/ const PRIMITIVE_ELEMENT_TYPES = new Set([
|
|
412
|
+
_types__rspack_import_0/* .SchemaTypes.String */.L.String,
|
|
413
|
+
_types__rspack_import_0/* .SchemaTypes.Number */.L.Number,
|
|
414
|
+
_types__rspack_import_0/* .SchemaTypes.Boolean */.L.Boolean
|
|
415
|
+
]);
|
|
416
|
+
const hasPrimitiveElements = (type, elementType)=>type === SchemaTypes.Vector || PRIMITIVE_ELEMENT_TYPES.has(elementType);
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
},
|
|
420
|
+
894(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
421
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
422
|
+
T: () => (getStorageDateReviver)
|
|
423
|
+
});
|
|
424
|
+
/* import */ var _types__rspack_import_0 = __webpack_require__(537);
|
|
425
|
+
/* import */ var _propertyKind__rspack_import_1 = __webpack_require__(575);
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
const collectDatePaths = (properties, paths)=>{
|
|
429
|
+
for (const property of properties){
|
|
430
|
+
// The stored value belongs to whoever wrote it: a custom serializer, deserializer or
|
|
431
|
+
// transform reads it back, and would be handed a Date it did not expect. Unmapped
|
|
432
|
+
// properties are never stored.
|
|
433
|
+
if (property.valueSerializer != null || property.valueDeserializer != null || property.transform != null || property.isUnmapped) {
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (property.type === _types__rspack_import_0/* .SchemaTypes.Object */.L.Object) {
|
|
437
|
+
collectDatePaths(property.children, paths);
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const isArray = (0,_propertyKind__rspack_import_1/* .isArrayValued */.l)(property.type) && property.innerSchema?.type === _types__rspack_import_0/* .SchemaTypes.Date */.L.Date;
|
|
441
|
+
if (property.type !== _types__rspack_import_0/* .SchemaTypes.Date */.L.Date && isArray === false) {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
paths.push({
|
|
445
|
+
segments: [
|
|
446
|
+
...property.getParentPathArray({
|
|
447
|
+
useFromPropertyName: true
|
|
448
|
+
}),
|
|
449
|
+
property.getResolvedName()
|
|
450
|
+
],
|
|
451
|
+
isArray
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
const reviveAt = (record, path)=>{
|
|
456
|
+
const { segments } = path;
|
|
457
|
+
let parent = record;
|
|
458
|
+
for(let i = 0, length = segments.length - 1; i < length; i++){
|
|
459
|
+
parent = parent[segments[i]];
|
|
460
|
+
// An absent or null parent holds no date
|
|
461
|
+
if (parent == null || typeof parent !== "object") {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
const key = segments[segments.length - 1];
|
|
466
|
+
const value = parent[key];
|
|
467
|
+
if (path.isArray === false) {
|
|
468
|
+
if (typeof value === "string") {
|
|
469
|
+
parent[key] = new Date(value);
|
|
470
|
+
}
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (Array.isArray(value)) {
|
|
474
|
+
for(let i = 0, length = value.length; i < length; i++){
|
|
475
|
+
if (typeof value[i] === "string") {
|
|
476
|
+
value[i] = new Date(value[i]);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
/** Per schema: `null` for a schema with no dates, so a caller can skip the pass. */ const revivers = new WeakMap();
|
|
482
|
+
/**
|
|
483
|
+
* The reviver for `schema`'s records, or `null` when it declares no dates.
|
|
484
|
+
*
|
|
485
|
+
* Built once per compiled schema. A read revives every row it returns, so the paths are resolved
|
|
486
|
+
* here rather than per row.
|
|
487
|
+
*/ const getStorageDateReviver = (schema)=>{
|
|
488
|
+
const cached = revivers.get(schema);
|
|
489
|
+
if (cached !== undefined) {
|
|
490
|
+
return cached;
|
|
491
|
+
}
|
|
492
|
+
const paths = [];
|
|
493
|
+
collectDatePaths(schema.properties, paths);
|
|
494
|
+
const reviver = paths.length === 0 ? null : (record)=>{
|
|
495
|
+
for(let i = 0, length = paths.length; i < length; i++){
|
|
496
|
+
reviveAt(record, paths[i]);
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
revivers.set(schema, reviver);
|
|
500
|
+
return reviver;
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
|
|
382
504
|
},
|
|
383
505
|
618(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
384
506
|
__webpack_require__.d(__webpack_exports__, {
|
|
@@ -531,6 +653,8 @@ class IdSet {
|
|
|
531
653
|
|
|
532
654
|
// EXTERNAL MODULE: ./src/schema/types.ts
|
|
533
655
|
var types = __webpack_require__(537);
|
|
656
|
+
// EXTERNAL MODULE: ./src/schema/utils/storageDates.ts
|
|
657
|
+
var storageDates = __webpack_require__(894);
|
|
534
658
|
// EXTERNAL MODULE: ./src/results/Result.ts
|
|
535
659
|
var Result = __webpack_require__(718);
|
|
536
660
|
// EXTERNAL MODULE: ./src/utilities/uuid.ts
|
|
@@ -596,29 +720,17 @@ class MemoryDataCollection {
|
|
|
596
720
|
}
|
|
597
721
|
throw new Error(`Id Property '${property.name}' must be string or number, found '${property.type}'`);
|
|
598
722
|
}
|
|
599
|
-
_dateColumns;
|
|
600
|
-
/** Date columns, by the name a stored record uses. Nested dates live inside a JSON column. */ get dateColumns() {
|
|
601
|
-
if (this._dateColumns == null) {
|
|
602
|
-
this._dateColumns = this.schema.properties.filter((property)=>property.type === types/* .SchemaTypes.Date */.L.Date && property.getAssignmentPath().includes(".") === false).map((property)=>property.getResolvedName());
|
|
603
|
-
}
|
|
604
|
-
return this._dateColumns;
|
|
605
|
-
}
|
|
606
723
|
/**
|
|
607
724
|
* The record this collection keeps.
|
|
608
725
|
*
|
|
609
726
|
* A copy, so a caller holding the entity cannot write into the store afterwards. Dates are held
|
|
610
|
-
* as Dates: a predicate compares a Date, and a stored ISO
|
|
727
|
+
* as Dates, at the root, in objects and in arrays: a predicate compares a Date, and a stored ISO
|
|
728
|
+
* string never matches one. A durable subclass hydrates parsed JSON through here too.
|
|
611
729
|
*/ toStored(item) {
|
|
612
|
-
const columns = this.dateColumns;
|
|
613
730
|
const stored = {
|
|
614
731
|
...item
|
|
615
732
|
};
|
|
616
|
-
|
|
617
|
-
const value = stored[columns[i]];
|
|
618
|
-
if (typeof value === "string") {
|
|
619
|
-
stored[columns[i]] = new Date(value);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
733
|
+
(0,storageDates/* .getStorageDateReviver */.T)(this.schema)?.(stored);
|
|
622
734
|
return stored;
|
|
623
735
|
}
|
|
624
736
|
seed(items) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections/index.cjs","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/webpack/runtime/make_namespace_object","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))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","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;IA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,OAAOQ,IAA6B,EAAE;QAClC,MAAM5B,KAAK,IAAI,CAAC,mBAAmB,CAAC4B;QACpC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC5B,GAAG,QAAQ;IAChC;IAEA,OAAO4B,IAA6B,EAAE;QAClC,MAAM5B,KAAK,IAAI,CAAC,mBAAmB,CAAC4B;QACpC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC5B,GAAG,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC4B;IAC/C;IAEA,QAAQS,IAA2B,EAAE;QACjC,IAAI,CAAC,gBAAgB,CAAC,KAAK;QAC3B,IAAI,CAAC,IAAI,CAAC,KAAK;QACfA,KAAKxC,qCAAc;IACvB;IAEA,KAAKwC,IAA2B,EAAE;QAC9BA,KAAKxC,qCAAc;IACvB;IAEA,KAAKwC,IAA2B,EAAE;QAC9BA,KAAKxC,qCAAc;IACvB;AACJ;;;;;;;ACxN0B;AACM;AACR;AACe;AACJ;AACQ"}
|
|
1
|
+
{"version":3,"file":"collections/index.cjs","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/webpack/runtime/make_namespace_object","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))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","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":";;;;;;;;;;;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;IACJ;IAEA,IAAY,gBAAgB;QACxB,IAAIE,QAAQ;QAEZ,KAAK,M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D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAID,KAAKA,IAAIC,KAAK,QAAQ;IACnD;IAEA,OAAOO,IAA6B,EAAE;QAClC,MAAMnD,KAAK,IAAI,CAAC,mBAAmB,CAACmD;QACpC,IAAI,CAAC,IAAI,CAAC,MAAM,CAACnD,GAAG,QAAQ;IAChC;IAEA,OAAOmD,IAA6B,EAAE;QAClC,MAAMnD,KAAK,IAAI,CAAC,mBAAmB,CAACmD;QACpC,IAAI,CAAC,IAAI,CAAC,GAAG,CAACnD,GAAG,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAACmD;IAC/C;IAEA,QAAQM,IAA2B,EAAE;QACjC,IAAI,CAAC,gBAAgB,CAAC,KAAK;QAC3B,IAAI,CAAC,IAAI,CAAC,KAAK;QACfA,KAAK5D,qCAAc;IACvB;IAEA,KAAK4D,IAA2B,EAAE;QAC9BA,KAAK5D,qCAAc;IACvB;IAEA,KAAK4D,IAA2B,EAAE;QAC9BA,KAAK5D,qCAAc;IACvB;AACJ;;;;;;;ACpM0B;AACM;AACR;AACe;AACJ;AACQ"}
|
|
@@ -377,6 +377,128 @@ var HashType = /*#__PURE__*/ (/* unused pure expression or super */ null && (fun
|
|
|
377
377
|
}({})));
|
|
378
378
|
|
|
379
379
|
|
|
380
|
+
},
|
|
381
|
+
575(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
382
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
383
|
+
l: () => (isArrayValued)
|
|
384
|
+
});
|
|
385
|
+
/* import */ var _types__rspack_import_0 = __webpack_require__(537);
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Types whose runtime value is a JS array.
|
|
389
|
+
*
|
|
390
|
+
* `Array` and `Vector` are the same thing to every layer that copies, compares, hashes or
|
|
391
|
+
* freezes a value — a vector is a list of numbers and nothing more. They differ only where a
|
|
392
|
+
* backend chooses storage, which is the one place that should ask for `SchemaTypes.Vector` by
|
|
393
|
+
* name.
|
|
394
|
+
*
|
|
395
|
+
* This exists so adding a third array-shaped type is one edit rather than a hunt through
|
|
396
|
+
* twelve handlers. Missing one of those is silent in the worst way: a vector that clones by
|
|
397
|
+
* reference is shared with the change tracker's copy, so overwriting an embedding produces no
|
|
398
|
+
* diff and the save reports nothing to do.
|
|
399
|
+
*/ const ARRAY_VALUED_TYPES = new Set([
|
|
400
|
+
_types__rspack_import_0/* .SchemaTypes.Array */.L.Array,
|
|
401
|
+
_types__rspack_import_0/* .SchemaTypes.Vector */.L.Vector
|
|
402
|
+
]);
|
|
403
|
+
/** True when the property's value is a JS array and needs value rather than reference semantics. */ const isArrayValued = (type)=>ARRAY_VALUED_TYPES.has(type);
|
|
404
|
+
/**
|
|
405
|
+
* True when the property's elements are primitives, so a spread is a sufficient copy.
|
|
406
|
+
*
|
|
407
|
+
* A vector is always numbers, so it never needs the per-element deep copy an array of objects
|
|
408
|
+
* or dates does.
|
|
409
|
+
*/ const PRIMITIVE_ELEMENT_TYPES = new Set([
|
|
410
|
+
_types__rspack_import_0/* .SchemaTypes.String */.L.String,
|
|
411
|
+
_types__rspack_import_0/* .SchemaTypes.Number */.L.Number,
|
|
412
|
+
_types__rspack_import_0/* .SchemaTypes.Boolean */.L.Boolean
|
|
413
|
+
]);
|
|
414
|
+
const hasPrimitiveElements = (type, elementType)=>type === SchemaTypes.Vector || PRIMITIVE_ELEMENT_TYPES.has(elementType);
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
},
|
|
418
|
+
894(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
419
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
420
|
+
T: () => (getStorageDateReviver)
|
|
421
|
+
});
|
|
422
|
+
/* import */ var _types__rspack_import_0 = __webpack_require__(537);
|
|
423
|
+
/* import */ var _propertyKind__rspack_import_1 = __webpack_require__(575);
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
const collectDatePaths = (properties, paths)=>{
|
|
427
|
+
for (const property of properties){
|
|
428
|
+
// The stored value belongs to whoever wrote it: a custom serializer, deserializer or
|
|
429
|
+
// transform reads it back, and would be handed a Date it did not expect. Unmapped
|
|
430
|
+
// properties are never stored.
|
|
431
|
+
if (property.valueSerializer != null || property.valueDeserializer != null || property.transform != null || property.isUnmapped) {
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (property.type === _types__rspack_import_0/* .SchemaTypes.Object */.L.Object) {
|
|
435
|
+
collectDatePaths(property.children, paths);
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
const isArray = (0,_propertyKind__rspack_import_1/* .isArrayValued */.l)(property.type) && property.innerSchema?.type === _types__rspack_import_0/* .SchemaTypes.Date */.L.Date;
|
|
439
|
+
if (property.type !== _types__rspack_import_0/* .SchemaTypes.Date */.L.Date && isArray === false) {
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
paths.push({
|
|
443
|
+
segments: [
|
|
444
|
+
...property.getParentPathArray({
|
|
445
|
+
useFromPropertyName: true
|
|
446
|
+
}),
|
|
447
|
+
property.getResolvedName()
|
|
448
|
+
],
|
|
449
|
+
isArray
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
const reviveAt = (record, path)=>{
|
|
454
|
+
const { segments } = path;
|
|
455
|
+
let parent = record;
|
|
456
|
+
for(let i = 0, length = segments.length - 1; i < length; i++){
|
|
457
|
+
parent = parent[segments[i]];
|
|
458
|
+
// An absent or null parent holds no date
|
|
459
|
+
if (parent == null || typeof parent !== "object") {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const key = segments[segments.length - 1];
|
|
464
|
+
const value = parent[key];
|
|
465
|
+
if (path.isArray === false) {
|
|
466
|
+
if (typeof value === "string") {
|
|
467
|
+
parent[key] = new Date(value);
|
|
468
|
+
}
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (Array.isArray(value)) {
|
|
472
|
+
for(let i = 0, length = value.length; i < length; i++){
|
|
473
|
+
if (typeof value[i] === "string") {
|
|
474
|
+
value[i] = new Date(value[i]);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
/** Per schema: `null` for a schema with no dates, so a caller can skip the pass. */ const revivers = new WeakMap();
|
|
480
|
+
/**
|
|
481
|
+
* The reviver for `schema`'s records, or `null` when it declares no dates.
|
|
482
|
+
*
|
|
483
|
+
* Built once per compiled schema. A read revives every row it returns, so the paths are resolved
|
|
484
|
+
* here rather than per row.
|
|
485
|
+
*/ const getStorageDateReviver = (schema)=>{
|
|
486
|
+
const cached = revivers.get(schema);
|
|
487
|
+
if (cached !== undefined) {
|
|
488
|
+
return cached;
|
|
489
|
+
}
|
|
490
|
+
const paths = [];
|
|
491
|
+
collectDatePaths(schema.properties, paths);
|
|
492
|
+
const reviver = paths.length === 0 ? null : (record)=>{
|
|
493
|
+
for(let i = 0, length = paths.length; i < length; i++){
|
|
494
|
+
reviveAt(record, paths[i]);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
revivers.set(schema, reviver);
|
|
498
|
+
return reviver;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
|
|
380
502
|
},
|
|
381
503
|
618(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
382
504
|
__webpack_require__.d(__webpack_exports__, {
|
|
@@ -517,6 +639,8 @@ class IdSet {
|
|
|
517
639
|
|
|
518
640
|
// EXTERNAL MODULE: ./src/schema/types.ts
|
|
519
641
|
var types = __webpack_require__(537);
|
|
642
|
+
// EXTERNAL MODULE: ./src/schema/utils/storageDates.ts
|
|
643
|
+
var storageDates = __webpack_require__(894);
|
|
520
644
|
// EXTERNAL MODULE: ./src/results/Result.ts
|
|
521
645
|
var Result = __webpack_require__(718);
|
|
522
646
|
// EXTERNAL MODULE: ./src/utilities/uuid.ts
|
|
@@ -582,29 +706,17 @@ class MemoryDataCollection {
|
|
|
582
706
|
}
|
|
583
707
|
throw new Error(`Id Property '${property.name}' must be string or number, found '${property.type}'`);
|
|
584
708
|
}
|
|
585
|
-
_dateColumns;
|
|
586
|
-
/** Date columns, by the name a stored record uses. Nested dates live inside a JSON column. */ get dateColumns() {
|
|
587
|
-
if (this._dateColumns == null) {
|
|
588
|
-
this._dateColumns = this.schema.properties.filter((property)=>property.type === types/* .SchemaTypes.Date */.L.Date && property.getAssignmentPath().includes(".") === false).map((property)=>property.getResolvedName());
|
|
589
|
-
}
|
|
590
|
-
return this._dateColumns;
|
|
591
|
-
}
|
|
592
709
|
/**
|
|
593
710
|
* The record this collection keeps.
|
|
594
711
|
*
|
|
595
712
|
* A copy, so a caller holding the entity cannot write into the store afterwards. Dates are held
|
|
596
|
-
* as Dates: a predicate compares a Date, and a stored ISO
|
|
713
|
+
* as Dates, at the root, in objects and in arrays: a predicate compares a Date, and a stored ISO
|
|
714
|
+
* string never matches one. A durable subclass hydrates parsed JSON through here too.
|
|
597
715
|
*/ toStored(item) {
|
|
598
|
-
const columns = this.dateColumns;
|
|
599
716
|
const stored = {
|
|
600
717
|
...item
|
|
601
718
|
};
|
|
602
|
-
|
|
603
|
-
const value = stored[columns[i]];
|
|
604
|
-
if (typeof value === "string") {
|
|
605
|
-
stored[columns[i]] = new Date(value);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
719
|
+
(0,storageDates/* .getStorageDateReviver */.T)(this.schema)?.(stored);
|
|
608
720
|
return stored;
|
|
609
721
|
}
|
|
610
722
|
seed(items) {
|