@colyseus/schema 3.0.0-alpha.30 → 3.0.0-alpha.32
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/build/cjs/index.js +389 -354
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +389 -354
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +389 -354
- package/lib/Metadata.d.ts +14 -5
- package/lib/Metadata.js +49 -20
- package/lib/Metadata.js.map +1 -1
- package/lib/Reflection.js +4 -13
- package/lib/Reflection.js.map +1 -1
- package/lib/Schema.js +26 -39
- package/lib/Schema.js.map +1 -1
- package/lib/annotations.d.ts +1 -2
- package/lib/annotations.js +58 -52
- package/lib/annotations.js.map +1 -1
- package/lib/bench_encode.js +25 -22
- package/lib/bench_encode.js.map +1 -1
- package/lib/decoder/DecodeOperation.js +7 -9
- package/lib/decoder/DecodeOperation.js.map +1 -1
- package/lib/decoder/ReferenceTracker.js +3 -2
- package/lib/decoder/ReferenceTracker.js.map +1 -1
- package/lib/decoder/strategy/StateCallbacks.js +4 -3
- package/lib/decoder/strategy/StateCallbacks.js.map +1 -1
- package/lib/encoder/ChangeTree.d.ts +8 -7
- package/lib/encoder/ChangeTree.js +135 -117
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/EncodeOperation.d.ts +1 -4
- package/lib/encoder/EncodeOperation.js +17 -47
- package/lib/encoder/EncodeOperation.js.map +1 -1
- package/lib/encoder/Encoder.js +18 -6
- package/lib/encoder/Encoder.js.map +1 -1
- package/lib/encoder/Root.d.ts +2 -2
- package/lib/encoder/Root.js +18 -6
- package/lib/encoder/Root.js.map +1 -1
- package/lib/encoder/StateView.js +3 -3
- package/lib/encoder/StateView.js.map +1 -1
- package/lib/encoding/assert.d.ts +2 -1
- package/lib/encoding/assert.js +2 -2
- package/lib/encoding/assert.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +11 -10
- package/lib/index.js.map +1 -1
- package/lib/types/TypeContext.js +7 -14
- package/lib/types/TypeContext.js.map +1 -1
- package/lib/types/custom/ArraySchema.js +6 -0
- package/lib/types/custom/ArraySchema.js.map +1 -1
- package/lib/types/custom/CollectionSchema.js +1 -0
- package/lib/types/custom/CollectionSchema.js.map +1 -1
- package/lib/types/custom/MapSchema.js +5 -0
- package/lib/types/custom/MapSchema.js.map +1 -1
- package/lib/types/custom/SetSchema.js +1 -0
- package/lib/types/custom/SetSchema.js.map +1 -1
- package/lib/types/symbols.d.ts +1 -0
- package/lib/types/symbols.js +2 -1
- package/lib/types/symbols.js.map +1 -1
- package/package.json +1 -1
- package/src/Metadata.ts +60 -29
- package/src/Reflection.ts +5 -15
- package/src/Schema.ts +33 -45
- package/src/annotations.ts +75 -67
- package/src/bench_encode.ts +29 -27
- package/src/decoder/DecodeOperation.ts +12 -11
- package/src/decoder/ReferenceTracker.ts +3 -2
- package/src/decoder/strategy/StateCallbacks.ts +4 -3
- package/src/encoder/ChangeTree.ts +154 -138
- package/src/encoder/EncodeOperation.ts +42 -62
- package/src/encoder/Encoder.ts +25 -8
- package/src/encoder/Root.ts +23 -6
- package/src/encoder/StateView.ts +4 -4
- package/src/encoding/assert.ts +4 -3
- package/src/index.ts +1 -4
- package/src/types/TypeContext.ts +10 -15
- package/src/types/custom/ArraySchema.ts +8 -0
- package/src/types/custom/CollectionSchema.ts +1 -0
- package/src/types/custom/MapSchema.ts +6 -0
- package/src/types/custom/SetSchema.ts +1 -0
- package/src/types/symbols.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateView.js","sourceRoot":"","sources":["../../src/encoder/StateView.ts"],"names":[],"mappings":";;;AAOA,gCACC;AAPD,8CAA4C;AAC5C,gDAAkD;AAClD,2CAA6C;AAC7C,0CAAuC;AAGvC,SAAgB,UAAU,CAAC,IAAY;AACvC,CAAC;AAED,MAAa,SAAS;IAAtB;QACI;;WAEG;QACH,UAAK,GAAwB,IAAI,OAAO,EAAc,CAAC;QA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EAAE,EAAE,CAChC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,gBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9C,CAAC;QAED,aAAa;QACb,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACvC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBACpB,kBAAkB;gBAClB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACJ,sBAAsB;gBACtB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAEjB,0CAA0C;gBAC1C,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;oBAClB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACjC,CAAC;YACL,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA9MD,8BA8MC","sourcesContent":["import { ChangeTree, Ref } from \"./ChangeTree\";\nimport { $changes } from \"../types/symbols\";\nimport { DEFAULT_VIEW_TAG } from \"../annotations\";\nimport { OPERATION } from \"../encoding/spec\";\nimport { Metadata } from \"../Metadata\";\nimport type { Schema } from \"../Schema\";\n\nexport function createView(root: Schema) {\n}\n\nexport class StateView {\n /**\n * List of ChangeTree's that are visible to this view\n */\n items: WeakSet<ChangeTree> = new WeakSet<ChangeTree>();\n\n /**\n * List of ChangeTree's that are invisible to this view\n */\n invisible: WeakSet<ChangeTree> = new WeakSet<ChangeTree>();\n\n tags?: WeakMap<ChangeTree, Set<number>>; // TODO: use bit manipulation instead of Set<number> ()\n\n /**\n * Manual \"ADD\" operations for changes per ChangeTree, specific to this view.\n * (This is used to force encoding a property, even if it was not changed)\n */\n changes = new Map<ChangeTree, Map<number, OPERATION>>();\n\n // TODO: allow to set multiple tags at once\n add(obj: Ref, tag: number = DEFAULT_VIEW_TAG, checkIncludeParent: boolean = true) {\n if (!obj[$changes]) {\n console.warn(\"StateView#add(), invalid object:\", obj);\n return this;\n }\n\n // FIXME: ArraySchema/MapSchema does not have metadata\n const metadata: Metadata = obj.constructor[Symbol.metadata];\n const changeTree: ChangeTree = obj[$changes];\n this.items.add(changeTree);\n\n // add parent ChangeTree's\n // - if it was invisible to this view\n // - if it were previously filtered out\n if (checkIncludeParent && changeTree.parent) {\n this.addParent(changeTree.parent[$changes], changeTree.parentIndex, tag);\n }\n\n //\n // TODO: when adding an item of a MapSchema, the changes may not\n // be set (only the parent's changes are set)\n //\n let changes = this.changes.get(changeTree);\n if (changes === undefined) {\n changes = new Map<number, OPERATION>();\n this.changes.set(changeTree, changes)\n }\n\n // set tag\n if (tag !== DEFAULT_VIEW_TAG) {\n if (!this.tags) {\n this.tags = new WeakMap<ChangeTree, Set<number>>();\n }\n let tags: Set<number>;\n if (!this.tags.has(changeTree)) {\n tags = new Set<number>();\n this.tags.set(changeTree, tags);\n } else {\n tags = this.tags.get(changeTree);\n }\n tags.add(tag);\n\n // Ref: add tagged properties\n metadata?.[-3]?.[tag]?.forEach((index) => {\n if (changeTree.getChange(index) !== OPERATION.DELETE) {\n changes.set(index, OPERATION.ADD)\n }\n });\n\n } else {\n const isInvisible = this.invisible.has(changeTree);\n const changeSet = (changeTree.isFiltered || changeTree.isPartiallyFiltered)\n ? changeTree.allFilteredChanges\n : changeTree.allChanges;\n\n changeSet.forEach((op, index) => {\n const tagAtIndex = metadata?.[metadata?.[index]].tag;\n if (\n (\n isInvisible || // if \"invisible\", include all\n tagAtIndex === undefined || // \"all change\" with no tag\n tagAtIndex === tag // tagged property\n ) &&\n op !== OPERATION.DELETE\n ) {\n changes.set(index, op);\n }\n });\n }\n\n // Add children of this ChangeTree to this view\n changeTree.forEachChild((change, index) => {\n // Do not ADD children that don't have the same tag\n if (metadata && metadata[metadata[index]].tag !== tag) {\n return;\n }\n this.add(change.ref, tag, false);\n });\n\n return this;\n }\n\n protected addParent(changeTree: ChangeTree, parentIndex: number, tag: number) {\n // view must have all \"changeTree\" parent tree\n this.items.add(changeTree);\n\n // add parent's parent\n const parentChangeTree = changeTree.parent?.[$changes];\n if (parentChangeTree && (parentChangeTree.isFiltered || parentChangeTree.isPartiallyFiltered)) {\n this.addParent(parentChangeTree, changeTree.parentIndex, tag);\n }\n\n // parent is already available, no need to add it!\n if (!this.invisible.has(changeTree)) {\n return;\n }\n\n // add parent's tag properties\n if (changeTree.getChange(parentIndex) !== OPERATION.DELETE) {\n\n let changes = this.changes.get(changeTree);\n if (changes === undefined) {\n changes = new Map<number, OPERATION>();\n this.changes.set(changeTree, changes);\n }\n\n if (!this.tags) {\n this.tags = new WeakMap<ChangeTree, Set<number>>();\n }\n\n let tags: Set<number>;\n if (!this.tags.has(changeTree)) {\n tags = new Set<number>();\n this.tags.set(changeTree, tags);\n } else {\n tags = this.tags.get(changeTree);\n }\n tags.add(tag);\n\n changes.set(parentIndex, OPERATION.ADD);\n }\n }\n\n remove(obj: Ref, tag: number = DEFAULT_VIEW_TAG) {\n const changeTree = obj[$changes];\n if (!changeTree) {\n console.warn(\"StateView#remove(), invalid object:\", obj);\n return this;\n }\n\n this.items.delete(changeTree);\n\n const ref = changeTree.ref;\n const metadata: Metadata = ref.constructor[Symbol.metadata];\n\n let changes = this.changes.get(changeTree);\n if (changes === undefined) {\n changes = new Map<number, OPERATION>();\n this.changes.set(changeTree, changes)\n }\n\n if (tag === DEFAULT_VIEW_TAG) {\n // parent is collection (Map/Array)\n const parent = changeTree.parent;\n if (!Metadata.isValidInstance(parent)) {\n const parentChangeTree = parent[$changes];\n let changes = this.changes.get(parentChangeTree);\n if (changes === undefined) {\n changes = new Map<number, OPERATION>();\n this.changes.set(parentChangeTree, changes)\n }\n // DELETE / DELETE BY REF ID\n changes.set(changeTree.parentIndex, OPERATION.DELETE);\n\n } else {\n // delete all \"tagged\" properties.\n metadata[-2].forEach((index) =>\n changes.set(index, OPERATION.DELETE));\n }\n\n\n } else {\n // delete only tagged properties\n metadata[-3][tag].forEach((index) =>\n changes.set(index, OPERATION.DELETE));\n }\n\n // remove tag\n if (this.tags && this.tags.has(changeTree)) {\n const tags = this.tags.get(changeTree);\n if (tag === undefined) {\n // delete all tags\n this.tags.delete(changeTree);\n } else {\n // delete specific tag\n tags.delete(tag);\n\n // if tag set is empty, delete it entirely\n if (tags.size === 0) {\n this.tags.delete(changeTree);\n }\n }\n }\n\n return this;\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"StateView.js","sourceRoot":"","sources":["../../src/encoder/StateView.ts"],"names":[],"mappings":";;;AAOA,gCACC;AAPD,8CAA4C;AAC5C,gDAAkD;AAClD,2CAA6C;AAC7C,0CAAuC;AAGvC,SAAgB,UAAU,CAAC,IAAY;AACvC,CAAC;AAED,MAAa,SAAS;IAAtB;QACI;;WAEG;QACH,UAAK,GAAwB,IAAI,OAAO,EAAc,CAAC;QAEvD;;WAEG;QACH,cAAS,GAAwB,IAAI,OAAO,EAAc,CAAC;QAI3D;;;WAGG;QACH,YAAO,GAAG,IAAI,GAAG,EAAsC,CAAC;IA6L5D,CAAC;IA3LG,2CAA2C;IAC3C,GAAG,CAAC,GAAQ,EAAE,MAAc,8BAAgB,EAAE,qBAA8B,IAAI;QAC5E,IAAI,CAAC,GAAG,CAAC,kBAAQ,CAAC,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;YACtD,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,oDAAoD;QACpD,MAAM,QAAQ,GAAa,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5D,MAAM,UAAU,GAAe,GAAG,CAAC,kBAAQ,CAAC,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAE3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,CAAC;gBACjC,CAAC;YACL,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA9MD,8BA8MC","sourcesContent":["import { ChangeTree, Ref } from \"./ChangeTree\";\nimport { $changes } from \"../types/symbols\";\nimport { DEFAULT_VIEW_TAG } from \"../annotations\";\nimport { OPERATION } from \"../encoding/spec\";\nimport { Metadata } from \"../Metadata\";\nimport type { Schema } from \"../Schema\";\n\nexport function createView(root: Schema) {\n}\n\nexport class StateView {\n /**\n * List of ChangeTree's that are visible to this view\n */\n items: WeakSet<ChangeTree> = new WeakSet<ChangeTree>();\n\n /**\n * List of ChangeTree's that are invisible to this view\n */\n invisible: WeakSet<ChangeTree> = new WeakSet<ChangeTree>();\n\n tags?: WeakMap<ChangeTree, Set<number>>; // TODO: use bit manipulation instead of Set<number> ()\n\n /**\n * Manual \"ADD\" operations for changes per ChangeTree, specific to this view.\n * (This is used to force encoding a property, even if it was not changed)\n */\n changes = new Map<ChangeTree, Map<number, OPERATION>>();\n\n // TODO: allow to set multiple tags at once\n add(obj: Ref, tag: number = DEFAULT_VIEW_TAG, checkIncludeParent: boolean = true) {\n if (!obj[$changes]) {\n console.warn(\"StateView#add(), invalid object:\", obj);\n return this;\n }\n\n // FIXME: ArraySchema/MapSchema do not have metadata\n const metadata: Metadata = obj.constructor[Symbol.metadata];\n const changeTree: ChangeTree = obj[$changes];\n this.items.add(changeTree);\n\n // add parent ChangeTree's\n // - if it was invisible to this view\n // - if it were previously filtered out\n if (checkIncludeParent && changeTree.parent) {\n this.addParent(changeTree.parent[$changes], changeTree.parentIndex, tag);\n }\n\n //\n // TODO: when adding an item of a MapSchema, the changes may not\n // be set (only the parent's changes are set)\n //\n let changes = this.changes.get(changeTree);\n if (changes === undefined) {\n changes = new Map<number, OPERATION>();\n this.changes.set(changeTree, changes)\n }\n\n // set tag\n if (tag !== DEFAULT_VIEW_TAG) {\n if (!this.tags) {\n this.tags = new WeakMap<ChangeTree, Set<number>>();\n }\n let tags: Set<number>;\n if (!this.tags.has(changeTree)) {\n tags = new Set<number>();\n this.tags.set(changeTree, tags);\n } else {\n tags = this.tags.get(changeTree);\n }\n tags.add(tag);\n\n // Ref: add tagged properties\n metadata?.[-3]?.[tag]?.forEach((index) => {\n if (changeTree.getChange(index) !== OPERATION.DELETE) {\n changes.set(index, OPERATION.ADD)\n }\n });\n\n } else {\n const isInvisible = this.invisible.has(changeTree);\n const changeSet = (changeTree.isFiltered || changeTree.isPartiallyFiltered)\n ? changeTree.allFilteredChanges\n : changeTree.allChanges;\n\n changeSet.forEach((op, index) => {\n const tagAtIndex = metadata?.[index].tag;\n if (\n (\n isInvisible || // if \"invisible\", include all\n tagAtIndex === undefined || // \"all change\" with no tag\n tagAtIndex === tag // tagged property\n ) &&\n op !== OPERATION.DELETE\n ) {\n changes.set(index, op);\n }\n });\n }\n\n // Add children of this ChangeTree to this view\n changeTree.forEachChild((change, index) => {\n // Do not ADD children that don't have the same tag\n if (metadata && metadata[index].tag !== tag) {\n return;\n }\n this.add(change.ref, tag, false);\n });\n\n return this;\n }\n\n protected addParent(changeTree: ChangeTree, parentIndex: number, tag: number) {\n // view must have all \"changeTree\" parent tree\n this.items.add(changeTree);\n\n // add parent's parent\n const parentChangeTree = changeTree.parent?.[$changes];\n if (parentChangeTree && (parentChangeTree.isFiltered || parentChangeTree.isPartiallyFiltered)) {\n this.addParent(parentChangeTree, changeTree.parentIndex, tag);\n }\n\n // parent is already available, no need to add it!\n if (!this.invisible.has(changeTree)) {\n return;\n }\n\n // add parent's tag properties\n if (changeTree.getChange(parentIndex) !== OPERATION.DELETE) {\n\n let changes = this.changes.get(changeTree);\n if (changes === undefined) {\n changes = new Map<number, OPERATION>();\n this.changes.set(changeTree, changes);\n }\n\n if (!this.tags) {\n this.tags = new WeakMap<ChangeTree, Set<number>>();\n }\n\n let tags: Set<number>;\n if (!this.tags.has(changeTree)) {\n tags = new Set<number>();\n this.tags.set(changeTree, tags);\n } else {\n tags = this.tags.get(changeTree);\n }\n tags.add(tag);\n\n changes.set(parentIndex, OPERATION.ADD);\n }\n }\n\n remove(obj: Ref, tag: number = DEFAULT_VIEW_TAG) {\n const changeTree = obj[$changes];\n if (!changeTree) {\n console.warn(\"StateView#remove(), invalid object:\", obj);\n return this;\n }\n\n this.items.delete(changeTree);\n\n const ref = changeTree.ref;\n const metadata: Metadata = ref.constructor[Symbol.metadata];\n\n let changes = this.changes.get(changeTree);\n if (changes === undefined) {\n changes = new Map<number, OPERATION>();\n this.changes.set(changeTree, changes);\n }\n\n if (tag === DEFAULT_VIEW_TAG) {\n // parent is collection (Map/Array)\n const parent = changeTree.parent;\n if (!Metadata.isValidInstance(parent)) {\n const parentChangeTree = parent[$changes];\n let changes = this.changes.get(parentChangeTree);\n if (changes === undefined) {\n changes = new Map<number, OPERATION>();\n this.changes.set(parentChangeTree, changes)\n }\n // DELETE / DELETE BY REF ID\n changes.set(changeTree.parentIndex, OPERATION.DELETE);\n\n } else {\n // delete all \"tagged\" properties.\n metadata[-2].forEach((index) =>\n changes.set(index, OPERATION.DELETE));\n }\n\n\n } else {\n // delete only tagged properties\n metadata[-3][tag].forEach((index) =>\n changes.set(index, OPERATION.DELETE));\n }\n\n // remove tag\n if (this.tags && this.tags.has(changeTree)) {\n const tags = this.tags.get(changeTree);\n if (tag === undefined) {\n // delete all tags\n this.tags.delete(changeTree);\n } else {\n // delete specific tag\n tags.delete(tag);\n\n // if tag set is empty, delete it entirely\n if (tags.size === 0) {\n this.tags.delete(changeTree);\n }\n }\n }\n\n return this;\n }\n}"]}
|
package/lib/encoding/assert.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { CollectionSchema } from "../types/custom/CollectionSchema";
|
|
|
3
3
|
import { MapSchema } from "../types/custom/MapSchema";
|
|
4
4
|
import { SetSchema } from "../types/custom/SetSchema";
|
|
5
5
|
import { ArraySchema } from "../types/custom/ArraySchema";
|
|
6
|
+
import type { Ref } from "../encoder/ChangeTree";
|
|
6
7
|
export declare class EncodeSchemaError extends Error {
|
|
7
8
|
}
|
|
8
9
|
export declare function assertType(value: any, type: string, klass: Schema, field: string | number): void;
|
|
9
|
-
export declare function assertInstanceType(value:
|
|
10
|
+
export declare function assertInstanceType(value: Ref, type: typeof Schema | typeof ArraySchema | typeof MapSchema | typeof CollectionSchema | typeof SetSchema, instance: Ref, field: string | number): void;
|
package/lib/encoding/assert.js
CHANGED
|
@@ -39,9 +39,9 @@ function assertType(value, type, klass, field) {
|
|
|
39
39
|
throw new EncodeSchemaError(`a '${typeofTarget}' was expected, but ${foundValue} was provided in ${klass.constructor.name}#${field}`);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
function assertInstanceType(value, type,
|
|
42
|
+
function assertInstanceType(value, type, instance, field) {
|
|
43
43
|
if (!(value instanceof type)) {
|
|
44
|
-
throw new EncodeSchemaError(`a '${type.name}' was expected, but '${value && value.constructor.name}' was provided in ${
|
|
44
|
+
throw new EncodeSchemaError(`a '${type.name}' was expected, but '${value && value.constructor.name}' was provided in ${instance.constructor.name}#${field}`);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
//# sourceMappingURL=assert.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/encoding/assert.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/encoding/assert.ts"],"names":[],"mappings":";;;AASA,gCAkCC;AAED,gDAaC;AAnDD,MAAa,iBAAkB,SAAQ,KAAK;CAAG;AAA/C,8CAA+C;AAE/C,SAAgB,UAAU,CAAC,KAAU,EAAE,IAAY,EAAE,KAAa,EAAE,KAAsB;IACtF,IAAI,YAAoB,CAAC;IACzB,IAAI,SAAS,GAAY,KAAK,CAAC;IAE/B,QAAQ,IAAI,EAAE,CAAC;QACX,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO,CAAC;QACb,KAAK,OAAO,CAAC;Q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AAC,WAAW,CAAC,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;IAC1K,CAAC;AACL,CAAC","sourcesContent":["import { Schema } from \"../Schema\";\nimport { CollectionSchema } from \"../types/custom/CollectionSchema\";\nimport { MapSchema } from \"../types/custom/MapSchema\";\nimport { SetSchema } from \"../types/custom/SetSchema\";\nimport { ArraySchema } from \"../types/custom/ArraySchema\";\nimport type { Ref } from \"../encoder/ChangeTree\";\n\nexport class EncodeSchemaError extends Error {}\n\nexport function assertType(value: any, type: string, klass: Schema, field: string | number) {\n let typeofTarget: string;\n let allowNull: boolean = false;\n\n switch (type) {\n case \"number\":\n case \"int8\":\n case \"uint8\":\n case \"int16\":\n case \"uint16\":\n case \"int32\":\n case \"uint32\":\n case \"int64\":\n case \"uint64\":\n case \"float32\":\n case \"float64\":\n typeofTarget = \"number\";\n if (isNaN(value)) {\n console.log(`trying to encode \"NaN\" in ${klass.constructor.name}#${field}`);\n }\n break;\n case \"string\":\n typeofTarget = \"string\";\n allowNull = true;\n break;\n case \"boolean\":\n // boolean is always encoded as true/false based on truthiness\n return;\n }\n\n if (typeof (value) !== typeofTarget && (!allowNull || (allowNull && value !== null))) {\n let foundValue = `'${JSON.stringify(value)}'${(value && value.constructor && ` (${value.constructor.name})`) || ''}`;\n throw new EncodeSchemaError(`a '${typeofTarget}' was expected, but ${foundValue} was provided in ${klass.constructor.name}#${field}`);\n }\n}\n\nexport function assertInstanceType(\n value: Ref,\n type: typeof Schema\n | typeof ArraySchema\n | typeof MapSchema\n | typeof CollectionSchema\n | typeof SetSchema,\n instance: Ref,\n field: string | number,\n) {\n if (!(value instanceof type)) {\n throw new EncodeSchemaError(`a '${type.name}' was expected, but '${value && (value as any).constructor.name}' was provided in ${instance.constructor.name}#${field}`);\n }\n}"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { Schema } from "./Schema";
|
|
2
2
|
export type { DataChange } from "./decoder/DecodeOperation";
|
|
3
|
-
import { $track, $encoder, $decoder, $filter, $getByIndex, $deleteByIndex, $changes, $childType } from "./types/symbols";
|
|
4
|
-
export { $track, $encoder, $decoder, $filter, $getByIndex, $deleteByIndex, $changes, $childType };
|
|
5
3
|
export type { ToJSON } from "./types/HelperTypes";
|
|
6
4
|
import { MapSchema } from "./types/custom/MapSchema";
|
|
7
5
|
export { MapSchema };
|
|
@@ -14,6 +12,7 @@ export { SetSchema };
|
|
|
14
12
|
import { registerType } from "./types/registry";
|
|
15
13
|
export { registerType };
|
|
16
14
|
export { dumpChanges } from "./utils";
|
|
15
|
+
export { $track, $encoder, $decoder, $filter, $getByIndex, $deleteByIndex, $changes, $childType } from "./types/symbols";
|
|
17
16
|
export type { Iterator } from "./encoding/decode";
|
|
18
17
|
import * as encode from "./encoding/encode";
|
|
19
18
|
import * as decode from "./encoding/decode";
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OPERATION = exports.decodeKeyValueOperation = exports.decodeSchemaOperation = exports.Decoder = exports.StateView = exports.ChangeTree = exports.encodeKeyValueOperation = exports.encodeSchemaOperation = exports.Encoder = exports.getRawChangesCallback = exports.getDecoderStateCallbacks = exports.TypeContext = exports.view = exports.defineTypes = exports.deprecated = exports.type = exports.Metadata = exports.ReflectionField = exports.ReflectionType = exports.Reflection = exports.decode = exports.encode = exports
|
|
3
|
+
exports.OPERATION = exports.decodeKeyValueOperation = exports.decodeSchemaOperation = exports.Decoder = exports.StateView = exports.ChangeTree = exports.encodeKeyValueOperation = exports.encodeSchemaOperation = exports.Encoder = exports.getRawChangesCallback = exports.getDecoderStateCallbacks = exports.TypeContext = exports.view = exports.defineTypes = exports.deprecated = exports.type = exports.Metadata = exports.ReflectionField = exports.ReflectionType = exports.Reflection = exports.decode = exports.encode = exports.$childType = exports.$changes = exports.$deleteByIndex = exports.$getByIndex = exports.$filter = exports.$decoder = exports.$encoder = exports.$track = exports.dumpChanges = exports.registerType = exports.SetSchema = exports.CollectionSchema = exports.ArraySchema = exports.MapSchema = exports.Schema = void 0;
|
|
4
4
|
var Schema_1 = require("./Schema");
|
|
5
5
|
Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return Schema_1.Schema; } });
|
|
6
|
-
const symbols_1 = require("./types/symbols");
|
|
7
|
-
Object.defineProperty(exports, "$track", { enumerable: true, get: function () { return symbols_1.$track; } });
|
|
8
|
-
Object.defineProperty(exports, "$encoder", { enumerable: true, get: function () { return symbols_1.$encoder; } });
|
|
9
|
-
Object.defineProperty(exports, "$decoder", { enumerable: true, get: function () { return symbols_1.$decoder; } });
|
|
10
|
-
Object.defineProperty(exports, "$filter", { enumerable: true, get: function () { return symbols_1.$filter; } });
|
|
11
|
-
Object.defineProperty(exports, "$getByIndex", { enumerable: true, get: function () { return symbols_1.$getByIndex; } });
|
|
12
|
-
Object.defineProperty(exports, "$deleteByIndex", { enumerable: true, get: function () { return symbols_1.$deleteByIndex; } });
|
|
13
|
-
Object.defineProperty(exports, "$changes", { enumerable: true, get: function () { return symbols_1.$changes; } });
|
|
14
|
-
Object.defineProperty(exports, "$childType", { enumerable: true, get: function () { return symbols_1.$childType; } });
|
|
15
6
|
const MapSchema_1 = require("./types/custom/MapSchema");
|
|
16
7
|
Object.defineProperty(exports, "MapSchema", { enumerable: true, get: function () { return MapSchema_1.MapSchema; } });
|
|
17
8
|
const ArraySchema_1 = require("./types/custom/ArraySchema");
|
|
@@ -29,6 +20,16 @@ Object.defineProperty(exports, "registerType", { enumerable: true, get: function
|
|
|
29
20
|
// Utils
|
|
30
21
|
var utils_1 = require("./utils");
|
|
31
22
|
Object.defineProperty(exports, "dumpChanges", { enumerable: true, get: function () { return utils_1.dumpChanges; } });
|
|
23
|
+
// Encoder / Decoder
|
|
24
|
+
var symbols_1 = require("./types/symbols");
|
|
25
|
+
Object.defineProperty(exports, "$track", { enumerable: true, get: function () { return symbols_1.$track; } });
|
|
26
|
+
Object.defineProperty(exports, "$encoder", { enumerable: true, get: function () { return symbols_1.$encoder; } });
|
|
27
|
+
Object.defineProperty(exports, "$decoder", { enumerable: true, get: function () { return symbols_1.$decoder; } });
|
|
28
|
+
Object.defineProperty(exports, "$filter", { enumerable: true, get: function () { return symbols_1.$filter; } });
|
|
29
|
+
Object.defineProperty(exports, "$getByIndex", { enumerable: true, get: function () { return symbols_1.$getByIndex; } });
|
|
30
|
+
Object.defineProperty(exports, "$deleteByIndex", { enumerable: true, get: function () { return symbols_1.$deleteByIndex; } });
|
|
31
|
+
Object.defineProperty(exports, "$changes", { enumerable: true, get: function () { return symbols_1.$changes; } });
|
|
32
|
+
Object.defineProperty(exports, "$childType", { enumerable: true, get: function () { return symbols_1.$childType; } });
|
|
32
33
|
const encode = require("./encoding/encode");
|
|
33
34
|
exports.encode = encode;
|
|
34
35
|
const decode = require("./encoding/decode");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAIf,wDAAoD;AAC3C,0FADA,qBAAS,OACA;AAElB,4DAAyD;AAChD,4FADA,yBAAW,OACA;AAEpB,sEAAmE;AAC1D,iGADA,mCAAgB,OACA;AAEzB,wDAAqD;AAC5C,0FADA,qBAAS,OACA;AAElB,+CAAgD;AACvC,6FADA,uBAAY,OACA;AAErB,IAAA,uBAAY,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,qBAAS,EAAE,CAAC,CAAC;AAChD,IAAA,uBAAY,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,yBAAW,EAAE,CAAC,CAAC;AACpD,IAAA,uBAAY,EAAC,KAAK,EAAE,EAAE,WA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ema } from \"./Schema\";\nexport type { DataChange } from \"./decoder/DecodeOperation\";\nexport type { ToJSON } from \"./types/HelperTypes\";\n\nimport { MapSchema } from \"./types/custom/MapSchema\"\nexport { MapSchema };\n\nimport { ArraySchema } from \"./types/custom/ArraySchema\";\nexport { ArraySchema };\n\nimport { CollectionSchema } from \"./types/custom/CollectionSchema\";\nexport { CollectionSchema };\n\nimport { SetSchema } from \"./types/custom/SetSchema\";\nexport { SetSchema };\n\nimport { registerType } from \"./types/registry\";\nexport { registerType };\n\nregisterType(\"map\", { constructor: MapSchema });\nregisterType(\"array\", { constructor: ArraySchema });\nregisterType(\"set\", { constructor: SetSchema });\nregisterType(\"collection\", { constructor: CollectionSchema, });\n\n// Utils\nexport { dumpChanges } from \"./utils\";\n\n// Encoder / Decoder\nexport { $track, $encoder, $decoder, $filter, $getByIndex, $deleteByIndex, $changes, $childType } from \"./types/symbols\";\nexport type { Iterator } from \"./encoding/decode\";\nimport * as encode from \"./encoding/encode\";\nimport * as decode from \"./encoding/decode\";\nexport { encode, decode };\n\n// Reflection\nexport {\n Reflection,\n ReflectionType,\n ReflectionField,\n} from \"./Reflection\";\n\n// Annotations, Metadata and TypeContext\nexport { Metadata } from \"./Metadata\";\nexport { type, deprecated, defineTypes, view, } from \"./annotations\";\nexport { TypeContext } from \"./types/TypeContext\";\n\n// Annotation types\nexport type { DefinitionType, PrimitiveType, Definition, } from \"./annotations\";\n\nexport { getDecoderStateCallbacks, CallbackProxy, GetCallbackProxy } from \"./decoder/strategy/StateCallbacks\";\nexport { getRawChangesCallback } from \"./decoder/strategy/RawChanges\";\n\nexport { Encoder } from \"./encoder/Encoder\";\nexport { encodeSchemaOperation, encodeArray as encodeKeyValueOperation } from \"./encoder/EncodeOperation\";\nexport { ChangeTree, Ref } from \"./encoder/ChangeTree\";\nexport { StateView } from \"./encoder/StateView\";\n\nexport { Decoder } from \"./decoder/Decoder\";\nexport { decodeSchemaOperation, decodeKeyValueOperation } from \"./decoder/DecodeOperation\";\n\nexport { OPERATION } from \"./encoding/spec\";"]}
|
package/lib/types/TypeContext.js
CHANGED
|
@@ -69,27 +69,20 @@ class TypeContext {
|
|
|
69
69
|
if (parentFieldViewTag !== undefined) {
|
|
70
70
|
this.parentFiltered[`${this.schemas.get(klass)}-${parentIndex}`] = true;
|
|
71
71
|
}
|
|
72
|
-
for (const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// if (
|
|
77
|
-
// parentFieldViewTag !== undefined &&
|
|
78
|
-
// metadata[field].tag === undefined
|
|
79
|
-
// ) {
|
|
80
|
-
// metadata[field].tag = parentFieldViewTag;
|
|
81
|
-
// }
|
|
82
|
-
const fieldType = metadata[field].type;
|
|
83
|
-
const viewTag = metadata[field].tag;
|
|
72
|
+
for (const fieldIndex in metadata) {
|
|
73
|
+
const index = fieldIndex;
|
|
74
|
+
const fieldType = metadata[index].type;
|
|
75
|
+
const viewTag = metadata[index].tag;
|
|
84
76
|
if (typeof (fieldType) === "string") {
|
|
85
77
|
continue;
|
|
86
78
|
}
|
|
87
79
|
if (Array.isArray(fieldType)) {
|
|
88
80
|
const type = fieldType[0];
|
|
81
|
+
// skip primitive types
|
|
89
82
|
if (type === "string") {
|
|
90
83
|
continue;
|
|
91
84
|
}
|
|
92
|
-
this.discoverTypes(type,
|
|
85
|
+
this.discoverTypes(type, index, viewTag);
|
|
93
86
|
}
|
|
94
87
|
else if (typeof (fieldType) === "function") {
|
|
95
88
|
this.discoverTypes(fieldType, viewTag);
|
|
@@ -100,7 +93,7 @@ class TypeContext {
|
|
|
100
93
|
if (typeof (type) === "string") {
|
|
101
94
|
continue;
|
|
102
95
|
}
|
|
103
|
-
this.discoverTypes(type,
|
|
96
|
+
this.discoverTypes(type, index, viewTag);
|
|
104
97
|
}
|
|
105
98
|
}
|
|
106
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeContext.js","sourceRoot":"","sources":["../../src/types/TypeContext.ts"],"names":[],"mappings":";;;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,GAAG,IAAI,CAAC;QAC5E,CAAC;QAED,KAAK,MAAM,UAAU,IAAI,QAAQ,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,UAA2B,CAAC;YAE1C,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;YACvC,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;YAEpC,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAClC,SAAS;YACb,CAAC;YAED,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAE1B,uBAAuB;gBACvB,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;oBACpB,SAAS;gBACb,CAAC;gBAED,IAAI,CAAC,aAAa,CAAC,IAAqB,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAE9D,CAAC;iBAAM,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,UAAU,EAAE,CAAC;gBAC3C,IAAI,CAAC,aAAa,CAAC,SAA0B,EAAE,OAAO,CAAC,CAAC;YAE5D,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;gBAEzC,uBAAuB;gBACvB,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;oBAC7B,SAAS;gBACb,CAAC;gBAED,IAAI,CAAC,aAAa,CAAC,IAAqB,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAC9D,CAAC;QACL,CAAC;IACL,CAAC;;AArHL,kCAsHC","sourcesContent":["import { Metadata } from \"../Metadata\";\nimport { Schema } from \"../Schema\";\n\nexport class TypeContext {\n types: { [id: number]: typeof Schema; } = {};\n schemas = new Map<typeof Schema, number>();\n\n hasFilters: boolean = false;\n parentFiltered: {[typeIdAndParentIndex: string]: boolean} = {};\n\n /**\n * For inheritance support\n * Keeps track of which classes extends which. (parent -> children)\n */\n static inheritedTypes = new Map<typeof Schema, Set<typeof Schema>>();\n\n static register(target: typeof Schema) {\n const parent = Object.getPrototypeOf(target);\n if (parent !== Schema) {\n let inherits = TypeContext.inheritedTypes.get(parent);\n if (!inherits) {\n inherits = new Set<typeof Schema>();\n TypeContext.inheritedTypes.set(parent, inherits);\n }\n inherits.add(target);\n }\n }\n\n constructor(rootClass?: typeof Schema) {\n if (rootClass) {\n this.discoverTypes(rootClass);\n }\n }\n\n has(schema: typeof Schema) {\n return this.schemas.has(schema);\n }\n\n get(typeid: number) {\n return this.types[typeid];\n }\n\n add(schema: typeof Schema, typeid: number = this.schemas.size) {\n // skip if already registered\n if (this.schemas.has(schema)) {\n return false;\n }\n\n this.types[typeid] = schema;\n\n //\n // Workaround to allow using an empty Schema (with no `@type()` fields)\n //\n if (schema[Symbol.metadata] === undefined) {\n Metadata.init(schema);\n }\n\n this.schemas.set(schema, typeid);\n return true;\n }\n\n getTypeId(klass: typeof Schema) {\n return this.schemas.get(klass);\n }\n\n private discoverTypes(klass: typeof Schema, parentIndex?: number, parentFieldViewTag?: number) {\n if (!this.add(klass)) {\n return;\n }\n\n // add classes inherited from this base class\n TypeContext.inheritedTypes.get(klass)?.forEach((child) => {\n this.discoverTypes(child, parentIndex, parentFieldViewTag);\n });\n\n const metadata: Metadata = (klass[Symbol.metadata] ??= {});\n\n // if any schema/field has filters, mark \"context\" as having filters.\n if (metadata[-2]) {\n this.hasFilters = true;\n }\n\n if (parentFieldViewTag !== undefined) {\n this.parentFiltered[`${this.schemas.get(klass)}-${parentIndex}`] = true;\n }\n\n for (const fieldIndex in metadata) {\n const index = fieldIndex as any as number;\n\n const fieldType = metadata[index].type;\n const viewTag = metadata[index].tag;\n\n if (typeof (fieldType) === \"string\") {\n continue;\n }\n\n if (Array.isArray(fieldType)) {\n const type = fieldType[0];\n\n // skip primitive types\n if (type === \"string\") {\n continue;\n }\n\n this.discoverTypes(type as typeof Schema, index, viewTag);\n\n } else if (typeof (fieldType) === \"function\") {\n this.discoverTypes(fieldType as typeof Schema, viewTag);\n\n } else {\n const type = Object.values(fieldType)[0];\n\n // skip primitive types\n if (typeof (type) === \"string\") {\n continue;\n }\n\n this.discoverTypes(type as typeof Schema, index, viewTag);\n }\n }\n }\n}\n"]}
|
|
@@ -8,6 +8,7 @@ const spec_1 = require("../../encoding/spec");
|
|
|
8
8
|
const registry_1 = require("../registry");
|
|
9
9
|
const EncodeOperation_1 = require("../../encoder/EncodeOperation");
|
|
10
10
|
const DecodeOperation_1 = require("../../decoder/DecodeOperation");
|
|
11
|
+
const assert_1 = require("../../encoding/assert");
|
|
11
12
|
const DEFAULT_SORT = (a, b) => {
|
|
12
13
|
const A = a.toString();
|
|
13
14
|
const B = b.toString();
|
|
@@ -72,6 +73,7 @@ class ArraySchema {
|
|
|
72
73
|
}
|
|
73
74
|
else {
|
|
74
75
|
if (setValue[symbols_1.$changes]) {
|
|
76
|
+
(0, assert_1.assertInstanceType)(setValue, obj[symbols_1.$childType], obj, key);
|
|
75
77
|
if (obj.items[key] !== undefined) {
|
|
76
78
|
if (setValue[symbols_1.$changes][symbols_1.$isNew]) {
|
|
77
79
|
this[symbols_1.$changes].indexedOperation(Number(key), spec_1.OPERATION.MOVE_AND_ADD);
|
|
@@ -118,6 +120,7 @@ class ArraySchema {
|
|
|
118
120
|
}
|
|
119
121
|
});
|
|
120
122
|
this[symbols_1.$changes] = new ChangeTree_1.ChangeTree(proxy);
|
|
123
|
+
this[symbols_1.$changes].indexes = {};
|
|
121
124
|
this.push.apply(this, items);
|
|
122
125
|
return proxy;
|
|
123
126
|
}
|
|
@@ -142,6 +145,9 @@ class ArraySchema {
|
|
|
142
145
|
if (value === undefined || value === null) {
|
|
143
146
|
return;
|
|
144
147
|
}
|
|
148
|
+
else if (typeof (value) === "object" && this[symbols_1.$childType]) {
|
|
149
|
+
(0, assert_1.assertInstanceType)(value, this[symbols_1.$childType], this, i);
|
|
150
|
+
}
|
|
145
151
|
const changeTree = this[symbols_1.$changes];
|
|
146
152
|
changeTree.indexedOperation(length, spec_1.OPERATION.ADD, this.items.length);
|
|
147
153
|
this.items.push(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArraySchema.js","sourceRoot":"","sources":["../../../src/types/custom/ArraySchema.ts"],"names":[],"mappings":";;;;AAAA,wCAAgJ;AAEhJ,yDAAsD;AACtD,8CAAgD;AAChD,0CAA2C;AAG3C,mEAA4D;AAC5D,mEAA4D;AAG5D,MAAM,YAAY,GAAG,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE;IACpC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvB,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;SAChB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;;QACpB,OAAO,CAAC,CAAA;AACjB,CAAC,CAAA;AAED,MAAa,WAAW;aAOb,QAAU,GAAG,6BAAW,AAAd,CAAe;aACzB,QAAU,GAAG,6BAAW,AAAd,CAAe;IAEhC;;;;;;;;OAQG;IACH,MAAM,CAAC,OAZC,kBAAQ,OACR,kBAAQ,EAWR,iBAAO,EAAC,CAAE,GAAgB,EAAE,KAAa,EAAE,IAAe;QAC9D,mDAAmD;QACnD,OAAO,CACH,CAAC,IAAI;YACL,OAAO,CAAC,GAAG,CAAC,oBAAU,CAAC,CAAC,KAAK,QAAQ;YACrC,oDAAoD;YACpD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,kBAAQ,CAAC,CAAC,CACrD,CAAC;IACN,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAS;QACf,OAAO;QACH,0BA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AC;gBAC5C,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;gBACnB,CAAC,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,EAAE;IACF,qBAAqB;IACrB,EAAE;IACF,KAAK,CAAC,UAAoB;QACtB,IAAI,MAAmB,CAAC;QAExB,IAAI,UAAU,EAAE,CAAC;YACb,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC3B,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAE/B,CAAC;aAAM,CAAC;YACJ,MAAM,GAAG,IAAI,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CACzC,CAAC,IAAI,CAAC,kBAAQ,CAAC,CAAC;gBACZ,CAAC,CAAE,IAAsB,CAAC,KAAK,EAAE;gBACjC,CAAC,CAAC,IAAI,CACb,CAAC,CAAC,CAAC;QACR,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAAA,CAAC;;AAnvBN,kCAqvBC;AAED,IAAA,uBAAY,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $onDecodeEnd, $isNew } from \"../symbols\";\nimport type { Schema } from \"../../Schema\";\nimport { ChangeTree } from \"../../encoder/ChangeTree\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { Collection } from \"../HelperTypes\";\n\nimport { encodeArray } from \"../../encoder/EncodeOperation\";\nimport { decodeArray } from \"../../decoder/DecodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\n\nconst DEFAULT_SORT = (a: any, b: any) => {\n const A = a.toString();\n const B = b.toString();\n if (A < B) return -1;\n else if (A > B) return 1;\n else return 0\n}\n\nexport class ArraySchema<V = any> implements Array<V>, Collection<number, V> {\n [n: number]: V;\n\n protected items: V[] = [];\n protected tmpItems: V[] = [];\n protected deletedIndexes: {[index: number]: boolean} = {};\n\n static [$encoder] = encodeArray;\n static [$decoder] = decodeArray;\n\n /**\n * Determine if a property must be filtered.\n * - If returns false, the property is NOT going to be encoded.\n * - If returns true, the property is going to be encoded.\n *\n * Encoding with \"filters\" happens in two steps:\n * - First, the encoder iterates over all \"not owned\" properties and encodes them.\n * - Then, the encoder iterates over all \"owned\" properties per instance and encodes them.\n */\n static [$filter] (ref: ArraySchema, index: number, view: StateView) {\n // console.log(\"ArraSchema[$filter] VIEW??\", !view)\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n // view.items.has(ref[$getByIndex](index)[$changes])\n view.items.has(ref['tmpItems'][index]?.[$changes])\n );\n }\n\n static is(type: any) {\n return (\n // type format: [\"string\"]\n Array.isArray(type) ||\n\n // type format: { array: \"string\" }\n (type['array'] !== undefined)\n );\n }\n\n constructor (...items: V[]) {\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n\n const proxy = new Proxy(this, {\n get: (obj, prop) => {\n if (\n typeof (prop) !== \"symbol\" &&\n !isNaN(prop as any) // https://stackoverflow.com/a/175787/892698\n ) {\n return this.items[prop];\n\n } else {\n return Reflect.get(obj, prop);\n }\n },\n\n set: (obj, key, setValue) => {\n if (typeof (key) !== \"symbol\" && !isNaN(key as any)) {\n if (setValue === undefined || setValue === null) {\n obj.$deleteAt(key as unknown as number);\n\n } else {\n if (setValue[$changes]) {\n if (obj.items[key as unknown as number] !== undefined) {\n if (setValue[$changes][$isNew]) {\n this[$changes].indexedOperation(Number(key), OPERATION.MOVE_AND_ADD);\n\n } else {\n if ((obj[$changes].getChange(Number(key)) & OPERATION.DELETE) === OPERATION.DELETE) {\n this[$changes].indexedOperation(Number(key), OPERATION.DELETE_AND_MOVE);\n } else {\n this[$changes].indexedOperation(Number(key), OPERATION.MOVE);\n }\n }\n } else if (setValue[$changes][$isNew]) {\n this[$changes].indexedOperation(Number(key), OPERATION.ADD);\n }\n } else {\n obj.$changeAt(Number(key), setValue);\n }\n\n this.items[key as unknown as number] = setValue;\n this.tmpItems[key as unknown as number] = setValue;\n }\n\n return true;\n } else {\n return Reflect.set(obj, key, setValue);\n }\n },\n\n deleteProperty: (obj, prop) => {\n if (typeof (prop) === \"number\") {\n obj.$deleteAt(prop);\n\n } else {\n delete obj[prop];\n }\n\n return true;\n },\n\n has: (obj, key) => {\n if (typeof (key) !== \"symbol\" && !isNaN(Number(key))) {\n return Reflect.has(this.items, key);\n }\n return Reflect.has(obj, key)\n }\n });\n\n this[$changes] = new ChangeTree(proxy);\n this.push.apply(this, items);\n\n return proxy;\n }\n\n set length (newLength: number) {\n if (newLength === 0) {\n this.clear();\n } else if (newLength < this.items.length) {\n this.splice(newLength, this.length - newLength);\n } else {\n console.warn(\"ArraySchema: can't set .length to a higher value than its length.\");\n }\n }\n\n get length() {\n return this.items.length;\n }\n\n push(...values: V[]) {\n let length = this.tmpItems.length;\n\n values.forEach((value, i) => {\n // skip null values\n if (value === undefined || value === null) {\n return;\n }\n\n const changeTree = this[$changes];\n changeTree.indexedOperation(length, OPERATION.ADD, this.items.length);\n\n this.items.push(value);\n this.tmpItems.push(value);\n\n //\n // set value's parent after the value is set\n // (to avoid encoding \"refId\" operations before parent's \"ADD\" operation)\n //\n value[$changes]?.setParent(this, changeTree.root, length);\n\n length++;\n });\n\n return length;\n }\n\n /**\n * Removes the last element from an array and returns it.\n */\n pop(): V | undefined {\n let index: number = -1;\n\n // find last non-undefined index\n for (let i = this.tmpItems.length - 1; i >= 0; i--) {\n // if (this.tmpItems[i] !== undefined) {\n if (this.deletedIndexes[i] !== true) {\n index = i;\n break;\n }\n }\n\n if (index < 0) {\n return undefined;\n }\n\n this[$changes].delete(index, undefined, this.items.length - 1);\n\n // this.tmpItems[index] = undefined;\n this.deletedIndexes[index] = true;\n\n return this.items.pop();\n }\n\n at(index: number) {\n // Allow negative indexing from the end\n if (index < 0) index += this.length;\n return this.items[index];\n }\n\n // encoding only\n protected $changeAt(index: number, value: V) {\n if (value === undefined || value === null) {\n console.error(\"ArraySchema items cannot be null nor undefined; Use `deleteAt(index)` instead.\");\n return;\n }\n\n // skip if the value is the same as cached.\n if (this.items[index] === value) {\n return;\n }\n\n const changeTree = this[$changes];\n const operation = changeTree.indexes?.[index]?.op ?? OPERATION.ADD;\n\n changeTree.change(index, operation);\n\n //\n // set value's parent after the value is set\n // (to avoid encoding \"refId\" operations before parent's \"ADD\" operation)\n //\n value[$changes]?.setParent(this, changeTree.root, index);\n }\n\n // encoding only\n protected $deleteAt(index: number, operation?: OPERATION) {\n this[$changes].delete(index, operation);\n }\n\n // decoding only\n protected $setAt(index: number, value: V, operation: OPERATION) {\n if (\n index === 0 &&\n operation === OPERATION.ADD &&\n this.items[index] !== undefined\n ) {\n // handle decoding unshift\n this.items.unshift(value);\n\n } else if (operation === OPERATION.DELETE_AND_MOVE) {\n this.items.splice(index, 1);\n this.items[index] = value;\n\n } else {\n this.items[index] = value;\n }\n }\n\n clear() {\n // skip if already clear\n if (this.items.length === 0) { return; }\n\n // discard previous operations.\n const changeTree = this[$changes]\n\n // discard children\n changeTree.forEachChild((changeTree, _) => {\n changeTree.discard(true);\n\n //\n // TODO: add tests with instance sharing + .clear()\n // FIXME: this.root? is required because it is being called at decoding time.\n //\n // TODO: do not use [$changes] at decoding time.\n //\n changeTree.root?.changes.delete(changeTree);\n changeTree.root?.allChanges.delete(changeTree);\n changeTree.root?.allFilteredChanges.delete(changeTree);\n });\n\n changeTree.discard(true);\n changeTree.operation(OPERATION.CLEAR);\n\n this.items.length = 0;\n this.tmpItems.length = 0;\n }\n\n /**\n * Combines two or more arrays.\n * @param items Additional items to add to the end of array1.\n */\n // @ts-ignore\n concat(...items: (V | ConcatArray<V>)[]): ArraySchema<V> {\n return new ArraySchema(...this.items.concat(...items));\n }\n\n /**\n * Adds all the elements of an array separated by the specified separator string.\n * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.\n */\n join(separator?: string): string {\n return this.items.join(separator);\n }\n\n /**\n * Reverses the elements in an Array.\n */\n // @ts-ignore\n reverse(): ArraySchema<V> {\n this[$changes].operation(OPERATION.REVERSE);\n this.items.reverse();\n this.tmpItems.reverse();\n return this;\n }\n\n /**\n * Removes the first element from an array and returns it.\n */\n shift(): V | undefined {\n if (this.items.length === 0) { return undefined; }\n\n // const index = Number(Object.keys(changeTree.indexes)[0]);\n const index = this.tmpItems.findIndex((item, i) => item === this.items[0]);\n const changeTree = this[$changes];\n\n changeTree.delete(index);\n changeTree.shiftAllChangeIndexes(-1, index);\n\n return this.items.shift();\n }\n\n /**\n * Returns a section of an array.\n * @param start The beginning of the specified portion of the array.\n * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.\n */\n slice(start?: number, end?: number): V[] {\n const sliced = new ArraySchema<V>();\n sliced.push(...this.items.slice(start, end));\n return sliced as unknown as V[];\n }\n\n /**\n * Sorts an array.\n * @param compareFn Function used to determine the order of the elements. It is expected to return\n * a negative value if first argument is less than second argument, zero if they're equal and a positive\n * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.\n * ```ts\n * [11,2,22,1].sort((a, b) => a - b)\n * ```\n */\n sort(compareFn: (a: V, b: V) => number = DEFAULT_SORT): this {\n const changeTree = this[$changes];\n const sortedItems = this.items.sort(compareFn);\n\n // wouldn't OPERATION.MOVE make more sense here?\n sortedItems.forEach((_, i) => changeTree.change(i, OPERATION.REPLACE));\n\n this.tmpItems.sort(compareFn);\n return this;\n }\n\n /**\n * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.\n * @param start The zero-based location in the array from which to start removing elements.\n * @param deleteCount The number of elements to remove.\n * @param insertItems Elements to insert into the array in place of the deleted elements.\n */\n splice(\n start: number,\n deleteCount: number = this.items.length - start,\n ...insertItems: V[]\n ): V[] {\n const changeTree = this[$changes];\n\n const tmpItemsLength = this.tmpItems.length;\n const insertCount = insertItems.length;\n\n // build up-to-date list of indexes, excluding removed values.\n const indexes: number[] = [];\n for (let i = 0; i < tmpItemsLength; i++) {\n // if (this.tmpItems[i] !== undefined) {\n if (this.deletedIndexes[i] !== true) {\n indexes.push(i);\n }\n }\n\n // delete operations at correct index\n for (let i = start; i < start + deleteCount; i++) {\n const index = indexes[i];\n changeTree.delete(index);\n // this.tmpItems[index] = undefined;\n this.deletedIndexes[index] = true;\n }\n\n // force insert operations\n for (let i = 0; i < insertCount; i++) {\n const addIndex = indexes[start] + i;\n changeTree.indexedOperation(addIndex, OPERATION.ADD);\n\n // set value's parent/root\n insertItems[i][$changes]?.setParent(this, changeTree.root, addIndex);\n }\n\n //\n // delete exceeding indexes from \"allChanges\"\n // (prevent .encodeAll() from encoding non-existing items)\n //\n if (deleteCount > insertCount) {\n changeTree.shiftAllChangeIndexes(-(deleteCount - insertCount), indexes[start + insertCount]);\n }\n\n return this.items.splice(start, deleteCount, ...insertItems);\n }\n\n /**\n * Inserts new elements at the start of an array.\n * @param items Elements to insert at the start of the Array.\n */\n unshift(...items: V[]): number {\n const changeTree = this[$changes];\n\n // shift indexes\n changeTree.shiftChangeIndexes(items.length);\n\n // new index\n if (changeTree.isFiltered) {\n changeTree.filteredChanges.set(this.items.length, OPERATION.ADD);\n } else {\n changeTree.allChanges.set(this.items.length, OPERATION.ADD);\n }\n\n // FIXME: should we use OPERATION.MOVE here instead?\n items.forEach((_, index) => {\n changeTree.change(index, OPERATION.ADD)\n });\n\n this.tmpItems.unshift(...items);\n\n return this.items.unshift(...items);\n }\n\n /**\n * Returns the index of the first occurrence of a value in an array.\n * @param searchElement The value to locate in the array.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\n indexOf(searchElement: V, fromIndex?: number): number {\n return this.items.indexOf(searchElement, fromIndex);\n }\n\n /**\n * Returns the index of the last occurrence of a specified value in an array.\n * @param searchElement The value to locate in the array.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.\n */\n lastIndexOf(searchElement: V, fromIndex: number = this.length - 1): number {\n return this.items.lastIndexOf(searchElement, fromIndex);\n }\n\n /**\n * Determines whether all the members of an array satisfy the specified test.\n * @param callbackfn A function that accepts up to three arguments. The every method calls\n * the callbackfn function for each element in the array until the callbackfn returns a value\n * which is coercible to the Boolean value false, or until the end of the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function.\n * If thisArg is omitted, undefined is used as the this value.\n */\n every<S extends V>(predicate: (value: V, index: number, array: V[]) => value is S, thisArg?: any): this is S[];\n every(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean {\n return this.items.every(callbackfn, thisArg);\n }\n\n /**\n * Determines whether the specified callback function returns true for any element of an array.\n * @param callbackfn A function that accepts up to three arguments. The some method calls\n * the callbackfn function for each element in the array until the callbackfn returns a value\n * which is coercible to the Boolean value true, or until the end of the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function.\n * If thisArg is omitted, undefined is used as the this value.\n */\n some(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean {\n return this.items.some(callbackfn, thisArg);\n }\n\n /**\n * Performs the specified action for each element in an array.\n * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n forEach(callbackfn: (value: V, index: number, array: V[]) => void, thisArg?: any): void {\n return this.items.forEach(callbackfn, thisArg);\n }\n\n /**\n * Calls a defined callback function on each element of an array, and returns an array that contains the results.\n * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n map<U>(callbackfn: (value: V, index: number, array: V[]) => U, thisArg?: any): U[] {\n return this.items.map(callbackfn, thisArg);\n }\n\n /**\n * Returns the elements of an array that meet the condition specified in a callback function.\n * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n filter(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): V[]\n filter<S extends V>(callbackfn: (value: V, index: number, array: V[]) => value is S, thisArg?: any): V[] {\n return this.items.filter(callbackfn, thisArg);\n }\n\n /**\n * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n reduce<U=V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U {\n return this.items.reduce(callbackfn, initialValue);\n }\n\n /**\n * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n reduceRight<U=V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U {\n return this.items.reduceRight(callbackfn, initialValue);\n }\n\n /**\n * Returns the value of the first element in the array where predicate is true, and undefined\n * otherwise.\n * @param predicate find calls predicate once for each element of the array, in ascending\n * order, until it finds one where predicate returns true. If such an element is found, find\n * immediately returns that element value. Otherwise, find returns undefined.\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\n find(predicate: (value: V, index: number, obj: V[]) => boolean, thisArg?: any): V | undefined {\n return this.items.find(predicate, thisArg);\n }\n\n /**\n * Returns the index of the first element in the array where predicate is true, and -1\n * otherwise.\n * @param predicate find calls predicate once for each element of the array, in ascending\n * order, until it finds one where predicate returns true. If such an element is found,\n * findIndex immediately returns that element index. Otherwise, findIndex returns -1.\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\n findIndex(predicate: (value: V, index: number, obj: V[]) => unknown, thisArg?: any): number {\n return this.items.findIndex(predicate, thisArg);\n }\n\n /**\n * Returns the this object after filling the section identified by start and end with value\n * @param value value to fill array section with\n * @param start index to start filling the array at. If start is negative, it is treated as\n * length+start where length is the length of the array.\n * @param end index to stop filling the array at. If end is negative, it is treated as\n * length+end.\n */\n fill(value: V, start?: number, end?: number): this {\n //\n // TODO\n //\n throw new Error(\"ArraySchema#fill() not implemented\");\n // this.$items.fill(value, start, end);\n\n return this;\n }\n\n /**\n * Returns the this object after copying a section of the array identified by start and end\n * to the same array starting at position target\n * @param target If target is negative, it is treated as length+target where length is the\n * length of the array.\n * @param start If start is negative, it is treated as length+start. If end is negative, it\n * is treated as length+end.\n * @param end If not specified, length of the this object is used as its default value.\n */\n copyWithin(target: number, start: number, end?: number): this {\n //\n // TODO\n //\n throw new Error(\"ArraySchema#copyWithin() not implemented\");\n return this;\n }\n\n /**\n * Returns a string representation of an array.\n */\n toString(): string {\n return this.items.toString();\n }\n\n /**\n * Returns a string representation of an array. The elements are converted to string using their toLocalString methods.\n */\n toLocaleString(): string {\n return this.items.toLocaleString()\n };\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<V> {\n return this.items[Symbol.iterator]();\n }\n\n static get [Symbol.species]() {\n return ArraySchema;\n }\n\n // WORKAROUND for compatibility\n // - TypeScript 4 defines @@unscopables as a function\n // - TypeScript 5 defines @@unscopables as an object\n [Symbol.unscopables]: any;\n\n /**\n * Returns an iterable of key, value pairs for every entry in the array\n */\n entries(): IterableIterator<[number, V]> { return this.items.entries(); }\n\n /**\n * Returns an iterable of keys in the array\n */\n keys(): IterableIterator<number> { return this.items.keys(); }\n\n /**\n * Returns an iterable of values in the array\n */\n values(): IterableIterator<V> { return this.items.values(); }\n\n /**\n * Determines whether an array includes a certain element, returning true or false as appropriate.\n * @param searchElement The element to search for.\n * @param fromIndex The position in this array at which to begin searching for searchElement.\n */\n includes(searchElement: V, fromIndex?: number): boolean {\n return this.items.includes(searchElement, fromIndex);\n }\n\n //\n // ES2022\n //\n\n /**\n * Calls a defined callback function on each element of an array. Then, flattens the result into\n * a new array.\n * This is identical to a map followed by flat with depth 1.\n *\n * @param callback A function that accepts up to three arguments. The flatMap method calls the\n * callback function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callback function. If\n * thisArg is omitted, undefined is used as the this value.\n */\n // @ts-ignore\n flatMap<U, This = undefined>(callback: (this: This, value: V, index: number, array: V[]) => U | ReadonlyArray<U>, thisArg?: This): U[] {\n // @ts-ignore\n throw new Error(\"ArraySchema#flatMap() is not supported.\");\n }\n\n /**\n * Returns a new array with all sub-array elements concatenated into it recursively up to the\n * specified depth.\n *\n * @param depth The maximum recursion depth\n */\n // @ts-ignore\n flat<A, D extends number = 1>(this: A, depth?: D): any {\n throw new Error(\"ArraySchema#flat() is not supported.\");\n }\n\n findLast() {\n // @ts-ignore\n return this.items.findLast.apply(this.items, arguments);\n }\n\n findLastIndex(...args) {\n // @ts-ignore\n return this.items.findLastIndex.apply(this.items, arguments);\n }\n\n //\n // ES2023\n //\n with(index: number, value: V): ArraySchema<V> {\n const copy = this.items.slice();\n copy[index] = value;\n return new ArraySchema(...copy);\n }\n toReversed(): V[] {\n return this.items.slice().reverse();\n }\n toSorted(compareFn?: (a: V, b: V) => number): V[] {\n return this.items.slice().sort(compareFn);\n }\n toSpliced(start: number, deleteCount: number, ...items: V[]): V[];\n toSpliced(start: number, deleteCount?: number): V[];\n // @ts-ignore\n toSpliced(start: unknown, deleteCount?: unknown, ...items?: unknown[]): V[] {\n // @ts-ignore\n return this.items.toSpliced.apply(copy, arguments);\n }\n\n protected [$getByIndex](index: number, isEncodeAll: boolean = false) {\n //\n // TODO: avoid unecessary `this.tmpItems` check during decoding.\n //\n // ENCODING uses `this.tmpItems` (or `this.items` if `isEncodeAll` is true)\n // DECODING uses `this.items`\n //\n\n return (isEncodeAll)\n ? this.items[index]\n : this.deletedIndexes[index]\n ? this.items[index]\n : this.tmpItems[index] || this.items[index];\n\n // return (isEncodeAll)\n // ? this.items[index]\n // : this.tmpItems[index] ?? this.items[index];\n }\n\n protected [$deleteByIndex](index: number) {\n this.items[index] = undefined;\n }\n\n protected [$onEncodeEnd]() {\n this.tmpItems = this.items.slice();\n this.deletedIndexes = {};\n }\n\n protected [$onDecodeEnd]() {\n this.items = this.items.filter((item) => item !== undefined);\n }\n\n toArray() {\n return this.items.slice(0);\n }\n\n toJSON() {\n return this.toArray().map((value) => {\n return (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value;\n });\n }\n\n //\n // Decoding utilities\n //\n clone(isDecoding?: boolean): ArraySchema<V> {\n let cloned: ArraySchema;\n\n if (isDecoding) {\n cloned = new ArraySchema();\n cloned.push(...this.items);\n\n } else {\n cloned = new ArraySchema(...this.map(item => (\n (item[$changes])\n ? (item as any as Schema).clone()\n : item\n )));\n }\n\n return cloned;\n };\n\n}\n\nregisterType(\"array\", { constructor: ArraySchema });"]}
|
|
1
|
+
{"version":3,"file":"ArraySchema.js","sourceRoot":"","sources":["../../../src/types/custom/ArraySchema.ts"],"names":[],"mappings":";;;;AAAA,wCAAgJ;AAEhJ,yDAAsD;AACtD,8CAAgD;AAChD,0CAA2C;AAG3C,mEAA4D;AAC5D,mEAA4D;AAE5D,kDAA2D;AAE3D,MAAM,YAAY,GAAG,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE;IACpC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvB,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;SAChB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;;QACpB,OAAO,CAAC,CAAA;AACjB,CAA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AAI,CAAC,KAAK,CAAC,CAAC;QAE/B,CAAC;aAAM,CAAC;YACJ,MAAM,GAAG,IAAI,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CACzC,CAAC,IAAI,CAAC,kBAAQ,CAAC,CAAC;gBACZ,CAAC,CAAE,IAAsB,CAAC,KAAK,EAAE;gBACjC,CAAC,CAAC,IAAI,CACb,CAAC,CAAC,CAAC;QACR,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAAA,CAAC;;AA1vBN,kCA4vBC;AAED,IAAA,uBAAY,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC","sourcesContent":["import { $changes, $childType, $decoder, $deleteByIndex, $onEncodeEnd, $encoder, $filter, $getByIndex, $onDecodeEnd, $isNew } from \"../symbols\";\nimport type { Schema } from \"../../Schema\";\nimport { ChangeTree } from \"../../encoder/ChangeTree\";\nimport { OPERATION } from \"../../encoding/spec\";\nimport { registerType } from \"../registry\";\nimport { Collection } from \"../HelperTypes\";\n\nimport { encodeArray } from \"../../encoder/EncodeOperation\";\nimport { decodeArray } from \"../../decoder/DecodeOperation\";\nimport type { StateView } from \"../../encoder/StateView\";\nimport { assertInstanceType } from \"../../encoding/assert\";\n\nconst DEFAULT_SORT = (a: any, b: any) => {\n const A = a.toString();\n const B = b.toString();\n if (A < B) return -1;\n else if (A > B) return 1;\n else return 0\n}\n\nexport class ArraySchema<V = any> implements Array<V>, Collection<number, V> {\n [n: number]: V;\n\n protected items: V[] = [];\n protected tmpItems: V[] = [];\n protected deletedIndexes: {[index: number]: boolean} = {};\n\n static [$encoder] = encodeArray;\n static [$decoder] = decodeArray;\n\n /**\n * Determine if a property must be filtered.\n * - If returns false, the property is NOT going to be encoded.\n * - If returns true, the property is going to be encoded.\n *\n * Encoding with \"filters\" happens in two steps:\n * - First, the encoder iterates over all \"not owned\" properties and encodes them.\n * - Then, the encoder iterates over all \"owned\" properties per instance and encodes them.\n */\n static [$filter] (ref: ArraySchema, index: number, view: StateView) {\n // console.log(\"ArraSchema[$filter] VIEW??\", !view)\n return (\n !view ||\n typeof (ref[$childType]) === \"string\" ||\n // view.items.has(ref[$getByIndex](index)[$changes])\n view.items.has(ref['tmpItems'][index]?.[$changes])\n );\n }\n\n static is(type: any) {\n return (\n // type format: [\"string\"]\n Array.isArray(type) ||\n\n // type format: { array: \"string\" }\n (type['array'] !== undefined)\n );\n }\n\n constructor (...items: V[]) {\n\n Object.defineProperty(this, $childType, {\n value: undefined,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n\n const proxy = new Proxy(this, {\n get: (obj, prop) => {\n if (\n typeof (prop) !== \"symbol\" &&\n !isNaN(prop as any) // https://stackoverflow.com/a/175787/892698\n ) {\n return this.items[prop];\n\n } else {\n return Reflect.get(obj, prop);\n }\n },\n\n set: (obj, key, setValue) => {\n if (typeof (key) !== \"symbol\" && !isNaN(key as any)) {\n if (setValue === undefined || setValue === null) {\n obj.$deleteAt(key as unknown as number);\n\n } else {\n if (setValue[$changes]) {\n assertInstanceType(setValue, obj[$childType] as typeof Schema, obj, key);\n\n if (obj.items[key as unknown as number] !== undefined) {\n if (setValue[$changes][$isNew]) {\n this[$changes].indexedOperation(Number(key), OPERATION.MOVE_AND_ADD);\n\n } else {\n if ((obj[$changes].getChange(Number(key)) & OPERATION.DELETE) === OPERATION.DELETE) {\n this[$changes].indexedOperation(Number(key), OPERATION.DELETE_AND_MOVE);\n } else {\n this[$changes].indexedOperation(Number(key), OPERATION.MOVE);\n }\n }\n } else if (setValue[$changes][$isNew]) {\n this[$changes].indexedOperation(Number(key), OPERATION.ADD);\n }\n\n } else {\n obj.$changeAt(Number(key), setValue);\n }\n\n this.items[key as unknown as number] = setValue;\n this.tmpItems[key as unknown as number] = setValue;\n }\n\n return true;\n } else {\n return Reflect.set(obj, key, setValue);\n }\n },\n\n deleteProperty: (obj, prop) => {\n if (typeof (prop) === \"number\") {\n obj.$deleteAt(prop);\n\n } else {\n delete obj[prop];\n }\n\n return true;\n },\n\n has: (obj, key) => {\n if (typeof (key) !== \"symbol\" && !isNaN(Number(key))) {\n return Reflect.has(this.items, key);\n }\n return Reflect.has(obj, key)\n }\n });\n\n this[$changes] = new ChangeTree(proxy);\n this[$changes].indexes = {};\n this.push.apply(this, items);\n\n return proxy;\n }\n\n set length (newLength: number) {\n if (newLength === 0) {\n this.clear();\n } else if (newLength < this.items.length) {\n this.splice(newLength, this.length - newLength);\n } else {\n console.warn(\"ArraySchema: can't set .length to a higher value than its length.\");\n }\n }\n\n get length() {\n return this.items.length;\n }\n\n push(...values: V[]) {\n let length = this.tmpItems.length;\n\n values.forEach((value, i) => {\n // skip null values\n if (value === undefined || value === null) {\n return;\n\n } else if (typeof (value) === \"object\" && this[$childType]) {\n assertInstanceType(value as any, this[$childType] as typeof Schema, this, i);\n }\n\n const changeTree = this[$changes];\n changeTree.indexedOperation(length, OPERATION.ADD, this.items.length);\n\n this.items.push(value);\n this.tmpItems.push(value);\n\n //\n // set value's parent after the value is set\n // (to avoid encoding \"refId\" operations before parent's \"ADD\" operation)\n //\n value[$changes]?.setParent(this, changeTree.root, length);\n\n length++;\n });\n\n return length;\n }\n\n /**\n * Removes the last element from an array and returns it.\n */\n pop(): V | undefined {\n let index: number = -1;\n\n // find last non-undefined index\n for (let i = this.tmpItems.length - 1; i >= 0; i--) {\n // if (this.tmpItems[i] !== undefined) {\n if (this.deletedIndexes[i] !== true) {\n index = i;\n break;\n }\n }\n\n if (index < 0) {\n return undefined;\n }\n\n this[$changes].delete(index, undefined, this.items.length - 1);\n\n // this.tmpItems[index] = undefined;\n this.deletedIndexes[index] = true;\n\n return this.items.pop();\n }\n\n at(index: number) {\n // Allow negative indexing from the end\n if (index < 0) index += this.length;\n return this.items[index];\n }\n\n // encoding only\n protected $changeAt(index: number, value: V) {\n if (value === undefined || value === null) {\n console.error(\"ArraySchema items cannot be null nor undefined; Use `deleteAt(index)` instead.\");\n return;\n }\n\n // skip if the value is the same as cached.\n if (this.items[index] === value) {\n return;\n }\n\n const changeTree = this[$changes];\n const operation = changeTree.indexes?.[index]?.op ?? OPERATION.ADD;\n\n changeTree.change(index, operation);\n\n //\n // set value's parent after the value is set\n // (to avoid encoding \"refId\" operations before parent's \"ADD\" operation)\n //\n value[$changes]?.setParent(this, changeTree.root, index);\n }\n\n // encoding only\n protected $deleteAt(index: number, operation?: OPERATION) {\n this[$changes].delete(index, operation);\n }\n\n // decoding only\n protected $setAt(index: number, value: V, operation: OPERATION) {\n if (\n index === 0 &&\n operation === OPERATION.ADD &&\n this.items[index] !== undefined\n ) {\n // handle decoding unshift\n this.items.unshift(value);\n\n } else if (operation === OPERATION.DELETE_AND_MOVE) {\n this.items.splice(index, 1);\n this.items[index] = value;\n\n } else {\n this.items[index] = value;\n }\n }\n\n clear() {\n // skip if already clear\n if (this.items.length === 0) { return; }\n\n // discard previous operations.\n const changeTree = this[$changes]\n\n // discard children\n changeTree.forEachChild((changeTree, _) => {\n changeTree.discard(true);\n\n //\n // TODO: add tests with instance sharing + .clear()\n // FIXME: this.root? is required because it is being called at decoding time.\n //\n // TODO: do not use [$changes] at decoding time.\n //\n changeTree.root?.changes.delete(changeTree);\n changeTree.root?.allChanges.delete(changeTree);\n changeTree.root?.allFilteredChanges.delete(changeTree);\n });\n\n changeTree.discard(true);\n changeTree.operation(OPERATION.CLEAR);\n\n this.items.length = 0;\n this.tmpItems.length = 0;\n }\n\n /**\n * Combines two or more arrays.\n * @param items Additional items to add to the end of array1.\n */\n // @ts-ignore\n concat(...items: (V | ConcatArray<V>)[]): ArraySchema<V> {\n return new ArraySchema(...this.items.concat(...items));\n }\n\n /**\n * Adds all the elements of an array separated by the specified separator string.\n * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.\n */\n join(separator?: string): string {\n return this.items.join(separator);\n }\n\n /**\n * Reverses the elements in an Array.\n */\n // @ts-ignore\n reverse(): ArraySchema<V> {\n this[$changes].operation(OPERATION.REVERSE);\n this.items.reverse();\n this.tmpItems.reverse();\n return this;\n }\n\n /**\n * Removes the first element from an array and returns it.\n */\n shift(): V | undefined {\n if (this.items.length === 0) { return undefined; }\n\n // const index = Number(Object.keys(changeTree.indexes)[0]);\n const index = this.tmpItems.findIndex((item, i) => item === this.items[0]);\n const changeTree = this[$changes];\n\n changeTree.delete(index);\n changeTree.shiftAllChangeIndexes(-1, index);\n\n return this.items.shift();\n }\n\n /**\n * Returns a section of an array.\n * @param start The beginning of the specified portion of the array.\n * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.\n */\n slice(start?: number, end?: number): V[] {\n const sliced = new ArraySchema<V>();\n sliced.push(...this.items.slice(start, end));\n return sliced as unknown as V[];\n }\n\n /**\n * Sorts an array.\n * @param compareFn Function used to determine the order of the elements. It is expected to return\n * a negative value if first argument is less than second argument, zero if they're equal and a positive\n * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.\n * ```ts\n * [11,2,22,1].sort((a, b) => a - b)\n * ```\n */\n sort(compareFn: (a: V, b: V) => number = DEFAULT_SORT): this {\n const changeTree = this[$changes];\n const sortedItems = this.items.sort(compareFn);\n\n // wouldn't OPERATION.MOVE make more sense here?\n sortedItems.forEach((_, i) => changeTree.change(i, OPERATION.REPLACE));\n\n this.tmpItems.sort(compareFn);\n return this;\n }\n\n /**\n * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.\n * @param start The zero-based location in the array from which to start removing elements.\n * @param deleteCount The number of elements to remove.\n * @param insertItems Elements to insert into the array in place of the deleted elements.\n */\n splice(\n start: number,\n deleteCount: number = this.items.length - start,\n ...insertItems: V[]\n ): V[] {\n const changeTree = this[$changes];\n\n const tmpItemsLength = this.tmpItems.length;\n const insertCount = insertItems.length;\n\n // build up-to-date list of indexes, excluding removed values.\n const indexes: number[] = [];\n for (let i = 0; i < tmpItemsLength; i++) {\n // if (this.tmpItems[i] !== undefined) {\n if (this.deletedIndexes[i] !== true) {\n indexes.push(i);\n }\n }\n\n // delete operations at correct index\n for (let i = start; i < start + deleteCount; i++) {\n const index = indexes[i];\n changeTree.delete(index);\n // this.tmpItems[index] = undefined;\n this.deletedIndexes[index] = true;\n }\n\n // force insert operations\n for (let i = 0; i < insertCount; i++) {\n const addIndex = indexes[start] + i;\n changeTree.indexedOperation(addIndex, OPERATION.ADD);\n\n // set value's parent/root\n insertItems[i][$changes]?.setParent(this, changeTree.root, addIndex);\n }\n\n //\n // delete exceeding indexes from \"allChanges\"\n // (prevent .encodeAll() from encoding non-existing items)\n //\n if (deleteCount > insertCount) {\n changeTree.shiftAllChangeIndexes(-(deleteCount - insertCount), indexes[start + insertCount]);\n }\n\n return this.items.splice(start, deleteCount, ...insertItems);\n }\n\n /**\n * Inserts new elements at the start of an array.\n * @param items Elements to insert at the start of the Array.\n */\n unshift(...items: V[]): number {\n const changeTree = this[$changes];\n\n // shift indexes\n changeTree.shiftChangeIndexes(items.length);\n\n // new index\n if (changeTree.isFiltered) {\n changeTree.filteredChanges.set(this.items.length, OPERATION.ADD);\n } else {\n changeTree.allChanges.set(this.items.length, OPERATION.ADD);\n }\n\n // FIXME: should we use OPERATION.MOVE here instead?\n items.forEach((_, index) => {\n changeTree.change(index, OPERATION.ADD)\n });\n\n this.tmpItems.unshift(...items);\n\n return this.items.unshift(...items);\n }\n\n /**\n * Returns the index of the first occurrence of a value in an array.\n * @param searchElement The value to locate in the array.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\n indexOf(searchElement: V, fromIndex?: number): number {\n return this.items.indexOf(searchElement, fromIndex);\n }\n\n /**\n * Returns the index of the last occurrence of a specified value in an array.\n * @param searchElement The value to locate in the array.\n * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.\n */\n lastIndexOf(searchElement: V, fromIndex: number = this.length - 1): number {\n return this.items.lastIndexOf(searchElement, fromIndex);\n }\n\n /**\n * Determines whether all the members of an array satisfy the specified test.\n * @param callbackfn A function that accepts up to three arguments. The every method calls\n * the callbackfn function for each element in the array until the callbackfn returns a value\n * which is coercible to the Boolean value false, or until the end of the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function.\n * If thisArg is omitted, undefined is used as the this value.\n */\n every<S extends V>(predicate: (value: V, index: number, array: V[]) => value is S, thisArg?: any): this is S[];\n every(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean {\n return this.items.every(callbackfn, thisArg);\n }\n\n /**\n * Determines whether the specified callback function returns true for any element of an array.\n * @param callbackfn A function that accepts up to three arguments. The some method calls\n * the callbackfn function for each element in the array until the callbackfn returns a value\n * which is coercible to the Boolean value true, or until the end of the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function.\n * If thisArg is omitted, undefined is used as the this value.\n */\n some(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): boolean {\n return this.items.some(callbackfn, thisArg);\n }\n\n /**\n * Performs the specified action for each element in an array.\n * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n forEach(callbackfn: (value: V, index: number, array: V[]) => void, thisArg?: any): void {\n return this.items.forEach(callbackfn, thisArg);\n }\n\n /**\n * Calls a defined callback function on each element of an array, and returns an array that contains the results.\n * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n map<U>(callbackfn: (value: V, index: number, array: V[]) => U, thisArg?: any): U[] {\n return this.items.map(callbackfn, thisArg);\n }\n\n /**\n * Returns the elements of an array that meet the condition specified in a callback function.\n * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\n filter(callbackfn: (value: V, index: number, array: V[]) => unknown, thisArg?: any): V[]\n filter<S extends V>(callbackfn: (value: V, index: number, array: V[]) => value is S, thisArg?: any): V[] {\n return this.items.filter(callbackfn, thisArg);\n }\n\n /**\n * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n reduce<U=V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U {\n return this.items.reduce(callbackfn, initialValue);\n }\n\n /**\n * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.\n * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.\n * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.\n */\n reduceRight<U=V>(callbackfn: (previousValue: U, currentValue: V, currentIndex: number, array: V[]) => U, initialValue?: U): U {\n return this.items.reduceRight(callbackfn, initialValue);\n }\n\n /**\n * Returns the value of the first element in the array where predicate is true, and undefined\n * otherwise.\n * @param predicate find calls predicate once for each element of the array, in ascending\n * order, until it finds one where predicate returns true. If such an element is found, find\n * immediately returns that element value. Otherwise, find returns undefined.\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\n find(predicate: (value: V, index: number, obj: V[]) => boolean, thisArg?: any): V | undefined {\n return this.items.find(predicate, thisArg);\n }\n\n /**\n * Returns the index of the first element in the array where predicate is true, and -1\n * otherwise.\n * @param predicate find calls predicate once for each element of the array, in ascending\n * order, until it finds one where predicate returns true. If such an element is found,\n * findIndex immediately returns that element index. Otherwise, findIndex returns -1.\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\n findIndex(predicate: (value: V, index: number, obj: V[]) => unknown, thisArg?: any): number {\n return this.items.findIndex(predicate, thisArg);\n }\n\n /**\n * Returns the this object after filling the section identified by start and end with value\n * @param value value to fill array section with\n * @param start index to start filling the array at. If start is negative, it is treated as\n * length+start where length is the length of the array.\n * @param end index to stop filling the array at. If end is negative, it is treated as\n * length+end.\n */\n fill(value: V, start?: number, end?: number): this {\n //\n // TODO\n //\n throw new Error(\"ArraySchema#fill() not implemented\");\n // this.$items.fill(value, start, end);\n\n return this;\n }\n\n /**\n * Returns the this object after copying a section of the array identified by start and end\n * to the same array starting at position target\n * @param target If target is negative, it is treated as length+target where length is the\n * length of the array.\n * @param start If start is negative, it is treated as length+start. If end is negative, it\n * is treated as length+end.\n * @param end If not specified, length of the this object is used as its default value.\n */\n copyWithin(target: number, start: number, end?: number): this {\n //\n // TODO\n //\n throw new Error(\"ArraySchema#copyWithin() not implemented\");\n return this;\n }\n\n /**\n * Returns a string representation of an array.\n */\n toString(): string {\n return this.items.toString();\n }\n\n /**\n * Returns a string representation of an array. The elements are converted to string using their toLocalString methods.\n */\n toLocaleString(): string {\n return this.items.toLocaleString()\n };\n\n /** Iterator */\n [Symbol.iterator](): IterableIterator<V> {\n return this.items[Symbol.iterator]();\n }\n\n static get [Symbol.species]() {\n return ArraySchema;\n }\n\n // WORKAROUND for compatibility\n // - TypeScript 4 defines @@unscopables as a function\n // - TypeScript 5 defines @@unscopables as an object\n [Symbol.unscopables]: any;\n\n /**\n * Returns an iterable of key, value pairs for every entry in the array\n */\n entries(): IterableIterator<[number, V]> { return this.items.entries(); }\n\n /**\n * Returns an iterable of keys in the array\n */\n keys(): IterableIterator<number> { return this.items.keys(); }\n\n /**\n * Returns an iterable of values in the array\n */\n values(): IterableIterator<V> { return this.items.values(); }\n\n /**\n * Determines whether an array includes a certain element, returning true or false as appropriate.\n * @param searchElement The element to search for.\n * @param fromIndex The position in this array at which to begin searching for searchElement.\n */\n includes(searchElement: V, fromIndex?: number): boolean {\n return this.items.includes(searchElement, fromIndex);\n }\n\n //\n // ES2022\n //\n\n /**\n * Calls a defined callback function on each element of an array. Then, flattens the result into\n * a new array.\n * This is identical to a map followed by flat with depth 1.\n *\n * @param callback A function that accepts up to three arguments. The flatMap method calls the\n * callback function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callback function. If\n * thisArg is omitted, undefined is used as the this value.\n */\n // @ts-ignore\n flatMap<U, This = undefined>(callback: (this: This, value: V, index: number, array: V[]) => U | ReadonlyArray<U>, thisArg?: This): U[] {\n // @ts-ignore\n throw new Error(\"ArraySchema#flatMap() is not supported.\");\n }\n\n /**\n * Returns a new array with all sub-array elements concatenated into it recursively up to the\n * specified depth.\n *\n * @param depth The maximum recursion depth\n */\n // @ts-ignore\n flat<A, D extends number = 1>(this: A, depth?: D): any {\n throw new Error(\"ArraySchema#flat() is not supported.\");\n }\n\n findLast() {\n // @ts-ignore\n return this.items.findLast.apply(this.items, arguments);\n }\n\n findLastIndex(...args) {\n // @ts-ignore\n return this.items.findLastIndex.apply(this.items, arguments);\n }\n\n //\n // ES2023\n //\n with(index: number, value: V): ArraySchema<V> {\n const copy = this.items.slice();\n copy[index] = value;\n return new ArraySchema(...copy);\n }\n toReversed(): V[] {\n return this.items.slice().reverse();\n }\n toSorted(compareFn?: (a: V, b: V) => number): V[] {\n return this.items.slice().sort(compareFn);\n }\n toSpliced(start: number, deleteCount: number, ...items: V[]): V[];\n toSpliced(start: number, deleteCount?: number): V[];\n // @ts-ignore\n toSpliced(start: unknown, deleteCount?: unknown, ...items?: unknown[]): V[] {\n // @ts-ignore\n return this.items.toSpliced.apply(copy, arguments);\n }\n\n protected [$getByIndex](index: number, isEncodeAll: boolean = false) {\n //\n // TODO: avoid unecessary `this.tmpItems` check during decoding.\n //\n // ENCODING uses `this.tmpItems` (or `this.items` if `isEncodeAll` is true)\n // DECODING uses `this.items`\n //\n\n return (isEncodeAll)\n ? this.items[index]\n : this.deletedIndexes[index]\n ? this.items[index]\n : this.tmpItems[index] || this.items[index];\n\n // return (isEncodeAll)\n // ? this.items[index]\n // : this.tmpItems[index] ?? this.items[index];\n }\n\n protected [$deleteByIndex](index: number) {\n this.items[index] = undefined;\n }\n\n protected [$onEncodeEnd]() {\n this.tmpItems = this.items.slice();\n this.deletedIndexes = {};\n }\n\n protected [$onDecodeEnd]() {\n this.items = this.items.filter((item) => item !== undefined);\n }\n\n toArray() {\n return this.items.slice(0);\n }\n\n toJSON() {\n return this.toArray().map((value) => {\n return (typeof (value['toJSON']) === \"function\")\n ? value['toJSON']()\n : value;\n });\n }\n\n //\n // Decoding utilities\n //\n clone(isDecoding?: boolean): ArraySchema<V> {\n let cloned: ArraySchema;\n\n if (isDecoding) {\n cloned = new ArraySchema();\n cloned.push(...this.items);\n\n } else {\n cloned = new ArraySchema(...this.map(item => (\n (item[$changes])\n ? (item as any as Schema).clone()\n : item\n )));\n }\n\n return cloned;\n };\n\n}\n\nregisterType(\"array\", { constructor: ArraySchema });"]}
|