@verdant-web/common 1.11.0 → 1.12.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.
Files changed (159) hide show
  1. package/dist/cjs/EventSubscriber.d.ts +17 -17
  2. package/dist/cjs/EventSubscriber.js +66 -66
  3. package/dist/cjs/baseline.d.ts +5 -5
  4. package/dist/cjs/baseline.js +2 -2
  5. package/dist/cjs/batching.d.ts +41 -41
  6. package/dist/cjs/batching.js +88 -88
  7. package/dist/cjs/files.d.ts +19 -19
  8. package/dist/cjs/files.js +18 -18
  9. package/dist/cjs/index.d.ts +18 -18
  10. package/dist/cjs/index.js +35 -35
  11. package/dist/cjs/indexes.d.ts +14 -14
  12. package/dist/cjs/indexes.js +115 -115
  13. package/dist/cjs/indexes.test.d.ts +1 -1
  14. package/dist/cjs/indexes.test.js +127 -127
  15. package/dist/cjs/migration.d.ts +98 -98
  16. package/dist/cjs/migration.js +127 -127
  17. package/dist/cjs/oids.d.ts +85 -87
  18. package/dist/cjs/oids.js +363 -374
  19. package/dist/cjs/oids.js.map +1 -1
  20. package/dist/cjs/oids.test.d.ts +1 -1
  21. package/dist/cjs/oids.test.js +269 -251
  22. package/dist/cjs/oids.test.js.map +1 -1
  23. package/dist/cjs/operation.d.ts +139 -139
  24. package/dist/cjs/operation.js +532 -532
  25. package/dist/cjs/operation.js.map +1 -1
  26. package/dist/cjs/operation.test.d.ts +1 -1
  27. package/dist/cjs/operation.test.js +505 -505
  28. package/dist/cjs/operation.test.js.map +1 -1
  29. package/dist/cjs/patch.d.ts +26 -26
  30. package/dist/cjs/patch.js +226 -226
  31. package/dist/cjs/patch.js.map +1 -1
  32. package/dist/cjs/presence.d.ts +27 -27
  33. package/dist/cjs/presence.js +2 -2
  34. package/dist/cjs/protocol.d.ts +145 -145
  35. package/dist/cjs/protocol.js +3 -3
  36. package/dist/cjs/refs.d.ts +5 -5
  37. package/dist/cjs/refs.js +21 -21
  38. package/dist/cjs/replica.d.ts +28 -28
  39. package/dist/cjs/replica.js +28 -28
  40. package/dist/cjs/schema/defaults.d.ts +4 -4
  41. package/dist/cjs/schema/defaults.js +71 -71
  42. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  43. package/dist/cjs/schema/defaults.test.js +20 -20
  44. package/dist/cjs/schema/defaults.test.js.map +1 -1
  45. package/dist/cjs/schema/index.d.ts +8 -8
  46. package/dist/cjs/schema/index.js +28 -28
  47. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  48. package/dist/cjs/schema/indexFilters.js +30 -30
  49. package/dist/cjs/schema/types/collection.d.ts +51 -51
  50. package/dist/cjs/schema/types/collection.js +2 -2
  51. package/dist/cjs/schema/types/compounds.d.ts +12 -12
  52. package/dist/cjs/schema/types/compounds.js +2 -2
  53. package/dist/cjs/schema/types/fields.d.ts +59 -59
  54. package/dist/cjs/schema/types/fields.js +2 -2
  55. package/dist/cjs/schema/types/filters.d.ts +29 -29
  56. package/dist/cjs/schema/types/filters.js +2 -2
  57. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  58. package/dist/cjs/schema/types/shapes.js +2 -2
  59. package/dist/cjs/schema/types/synthetics.d.ts +28 -28
  60. package/dist/cjs/schema/types/synthetics.js +2 -2
  61. package/dist/cjs/schema/types.d.ts +18 -18
  62. package/dist/cjs/schema/types.js +22 -22
  63. package/dist/cjs/timestamp.d.ts +48 -48
  64. package/dist/cjs/timestamp.js +243 -243
  65. package/dist/cjs/timestamp.test.d.ts +1 -1
  66. package/dist/cjs/timestamp.test.js +93 -93
  67. package/dist/cjs/undo.d.ts +3 -3
  68. package/dist/cjs/undo.js +198 -198
  69. package/dist/cjs/utils.d.ts +15 -15
  70. package/dist/cjs/utils.js +127 -127
  71. package/dist/cjs/utils.test.d.ts +1 -1
  72. package/dist/cjs/utils.test.js +36 -36
  73. package/dist/esm/EventSubscriber.d.ts +17 -17
  74. package/dist/esm/EventSubscriber.js +62 -62
  75. package/dist/esm/baseline.d.ts +5 -5
  76. package/dist/esm/baseline.js +1 -1
  77. package/dist/esm/batching.d.ts +41 -41
  78. package/dist/esm/batching.js +83 -83
  79. package/dist/esm/files.d.ts +19 -19
  80. package/dist/esm/files.js +12 -12
  81. package/dist/esm/index.d.ts +18 -18
  82. package/dist/esm/index.js +15 -15
  83. package/dist/esm/indexes.d.ts +14 -14
  84. package/dist/esm/indexes.js +105 -105
  85. package/dist/esm/indexes.test.d.ts +1 -1
  86. package/dist/esm/indexes.test.js +125 -125
  87. package/dist/esm/migration.d.ts +98 -98
  88. package/dist/esm/migration.js +121 -121
  89. package/dist/esm/oids.d.ts +85 -87
  90. package/dist/esm/oids.js +336 -347
  91. package/dist/esm/oids.js.map +1 -1
  92. package/dist/esm/oids.test.d.ts +1 -1
  93. package/dist/esm/oids.test.js +267 -249
  94. package/dist/esm/oids.test.js.map +1 -1
  95. package/dist/esm/operation.d.ts +139 -139
  96. package/dist/esm/operation.js +517 -517
  97. package/dist/esm/operation.js.map +1 -1
  98. package/dist/esm/operation.test.d.ts +1 -1
  99. package/dist/esm/operation.test.js +503 -503
  100. package/dist/esm/operation.test.js.map +1 -1
  101. package/dist/esm/patch.d.ts +26 -26
  102. package/dist/esm/patch.js +222 -222
  103. package/dist/esm/patch.js.map +1 -1
  104. package/dist/esm/presence.d.ts +27 -27
  105. package/dist/esm/presence.js +1 -1
  106. package/dist/esm/protocol.d.ts +145 -145
  107. package/dist/esm/protocol.js +2 -2
  108. package/dist/esm/refs.d.ts +5 -5
  109. package/dist/esm/refs.js +16 -16
  110. package/dist/esm/replica.d.ts +28 -28
  111. package/dist/esm/replica.js +25 -25
  112. package/dist/esm/schema/defaults.d.ts +4 -4
  113. package/dist/esm/schema/defaults.js +65 -65
  114. package/dist/esm/schema/defaults.test.d.ts +1 -1
  115. package/dist/esm/schema/defaults.test.js +18 -18
  116. package/dist/esm/schema/defaults.test.js.map +1 -1
  117. package/dist/esm/schema/index.d.ts +8 -8
  118. package/dist/esm/schema/index.js +9 -9
  119. package/dist/esm/schema/indexFilters.d.ts +6 -6
  120. package/dist/esm/schema/indexFilters.js +22 -22
  121. package/dist/esm/schema/types/collection.d.ts +51 -51
  122. package/dist/esm/schema/types/collection.js +1 -1
  123. package/dist/esm/schema/types/compounds.d.ts +12 -12
  124. package/dist/esm/schema/types/compounds.js +1 -1
  125. package/dist/esm/schema/types/fields.d.ts +59 -59
  126. package/dist/esm/schema/types/fields.js +1 -1
  127. package/dist/esm/schema/types/filters.d.ts +29 -29
  128. package/dist/esm/schema/types/filters.js +1 -1
  129. package/dist/esm/schema/types/shapes.d.ts +21 -21
  130. package/dist/esm/schema/types/shapes.js +1 -1
  131. package/dist/esm/schema/types/synthetics.d.ts +28 -28
  132. package/dist/esm/schema/types/synthetics.js +1 -1
  133. package/dist/esm/schema/types.d.ts +18 -18
  134. package/dist/esm/schema/types.js +6 -6
  135. package/dist/esm/timestamp.d.ts +48 -48
  136. package/dist/esm/timestamp.js +228 -228
  137. package/dist/esm/timestamp.test.d.ts +1 -1
  138. package/dist/esm/timestamp.test.js +91 -91
  139. package/dist/esm/undo.d.ts +3 -3
  140. package/dist/esm/undo.js +194 -194
  141. package/dist/esm/utils.d.ts +15 -15
  142. package/dist/esm/utils.js +113 -113
  143. package/dist/esm/utils.test.d.ts +1 -1
  144. package/dist/esm/utils.test.js +34 -34
  145. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  146. package/dist/tsconfig.tsbuildinfo +1 -1
  147. package/package.json +1 -1
  148. package/src/oids.test.ts +62 -51
  149. package/src/oids.ts +7 -26
  150. package/src/operation.test.ts +32 -40
  151. package/src/operation.ts +4 -16
  152. package/src/patch.ts +5 -15
  153. package/src/schema/defaults.test.ts +1 -1
  154. package/dist/cjs/files.test.d.ts +0 -1
  155. package/dist/cjs/files.test.js +0 -81
  156. package/dist/cjs/files.test.js.map +0 -1
  157. package/dist/esm/files.test.d.ts +0 -1
  158. package/dist/esm/files.test.js +0 -79
  159. package/dist/esm/files.test.js.map +0 -1
@@ -1,122 +1,122 @@
1
- import { stableStringify, addFieldDefaults, } from './index.js';
2
- const emptySchema = {
3
- version: 0,
4
- collections: {},
5
- };
6
- export function migrate(oldSchemaOrNewSchema, newSchemaOrProcedure, procedureIfTwoSchemas) {
7
- const isProcedureSecondArgument = typeof newSchemaOrProcedure === 'function';
8
- const oldSchema = isProcedureSecondArgument
9
- ? emptySchema
10
- : oldSchemaOrNewSchema;
11
- const newSchema = isProcedureSecondArgument
12
- ? oldSchemaOrNewSchema
13
- : newSchemaOrProcedure;
14
- const procedure = isProcedureSecondArgument
15
- ? newSchemaOrProcedure
16
- : procedureIfTwoSchemas;
17
- // diff to determine changed collections
18
- const changedCollections = Object.keys(newSchema.collections).filter((key) => oldSchema.collections[key] &&
19
- stableStringify(oldSchema.collections[key]) !==
20
- stableStringify(newSchema.collections[key]));
21
- const removedCollections = Object.keys(oldSchema.collections).filter((key) => !newSchema.collections[key]);
22
- const addedCollections = Object.keys(newSchema.collections).filter((key) => !oldSchema.collections[key]);
23
- const addedIndexes = {};
24
- const removedIndexes = {};
25
- for (const changed of [...changedCollections, ...addedCollections]) {
26
- const oldIndexes = getIndexes(oldSchema.collections[changed]);
27
- const newIndexes = getIndexes(newSchema.collections[changed]);
28
- const added = newIndexes.filter((index) => !oldIndexes.find((i) => i.name === index.name));
29
- const removed = oldIndexes.filter((index) => !newIndexes.find((i) => i.name === index.name));
30
- if (added.length > 0) {
31
- addedIndexes[changed] = added;
32
- }
33
- if (removed.length > 0) {
34
- removedIndexes[changed] = removed;
35
- }
36
- }
37
- return {
38
- version: newSchema.version,
39
- migrate: async (engine) => {
40
- const migratedCollections = [];
41
- await procedure({
42
- migrate: async (collection, strategy) => {
43
- // @ts-ignore
44
- await engine.migrate(collection, strategy);
45
- migratedCollections.push(collection);
46
- },
47
- identity: (val) => val,
48
- withDefaults: (collectionName, val) => {
49
- return addFieldDefaults(newSchema.collections[collectionName], val);
50
- },
51
- info: {
52
- changedCollections,
53
- addedCollections,
54
- removedCollections,
55
- },
56
- queries: engine.queries,
57
- mutations: engine.mutations,
58
- });
59
- const unmigrated = changedCollections.filter((collection) => !migratedCollections.includes(collection));
60
- if (unmigrated.length > 0) {
61
- console.error('Unmigrated changed collections:', unmigrated);
62
- }
63
- },
64
- removedCollections,
65
- addedIndexes,
66
- removedIndexes,
67
- allCollections: Object.keys(newSchema.collections),
68
- changedCollections,
69
- addedCollections,
70
- oldCollections: Object.keys(oldSchema.collections),
71
- oldSchema,
72
- newSchema,
73
- };
74
- }
75
- export function migrationRange(from, to) {
76
- return [...Array(to - from).keys()].map((i) => 1 + i + from);
77
- }
78
- function getIndexes(collection) {
79
- if (!collection)
80
- return [];
81
- const fields = Object.keys(collection.fields)
82
- .filter((key) => collection.fields[key].indexed)
83
- .map((key) => ({
84
- name: key,
85
- multiEntry: collection.fields[key].type === 'array',
86
- synthetic: false,
87
- compound: false,
88
- }));
89
- return [
90
- ...fields,
91
- ...Object.keys(collection.synthetics || {}).map((key) => ({
92
- name: key,
93
- multiEntry: ['array', 'string[]', 'number[]', 'boolean[]'].includes(collection.synthetics[key].type),
94
- synthetic: true,
95
- compound: false,
96
- })),
97
- ...Object.keys(collection.compounds || {}).map((key) => ({
98
- name: key,
99
- multiEntry: collection.compounds[key].of.some((fieldName) => (collection.fields[fieldName] || collection.synthetics[fieldName])
100
- .type === 'array'),
101
- synthetic: false,
102
- compound: true,
103
- })),
104
- ];
105
- }
106
- export function createDefaultMigration(schema, newSchema) {
107
- let oldSchema = newSchema
108
- ? schema
109
- : {
110
- version: 0,
111
- collections: {},
112
- };
113
- return migrate(oldSchema, newSchema || schema, async ({ migrate, withDefaults, info }) => {
114
- if ((newSchema || schema).version === 1)
115
- return;
116
- for (const collection of info.changedCollections) {
117
- // @ts-ignore indefinite type resolution
118
- await migrate(collection, (old) => withDefaults(collection, old));
119
- }
120
- });
121
- }
1
+ import { stableStringify, addFieldDefaults, } from './index.js';
2
+ const emptySchema = {
3
+ version: 0,
4
+ collections: {},
5
+ };
6
+ export function migrate(oldSchemaOrNewSchema, newSchemaOrProcedure, procedureIfTwoSchemas) {
7
+ const isProcedureSecondArgument = typeof newSchemaOrProcedure === 'function';
8
+ const oldSchema = isProcedureSecondArgument
9
+ ? emptySchema
10
+ : oldSchemaOrNewSchema;
11
+ const newSchema = isProcedureSecondArgument
12
+ ? oldSchemaOrNewSchema
13
+ : newSchemaOrProcedure;
14
+ const procedure = isProcedureSecondArgument
15
+ ? newSchemaOrProcedure
16
+ : procedureIfTwoSchemas;
17
+ // diff to determine changed collections
18
+ const changedCollections = Object.keys(newSchema.collections).filter((key) => oldSchema.collections[key] &&
19
+ stableStringify(oldSchema.collections[key]) !==
20
+ stableStringify(newSchema.collections[key]));
21
+ const removedCollections = Object.keys(oldSchema.collections).filter((key) => !newSchema.collections[key]);
22
+ const addedCollections = Object.keys(newSchema.collections).filter((key) => !oldSchema.collections[key]);
23
+ const addedIndexes = {};
24
+ const removedIndexes = {};
25
+ for (const changed of [...changedCollections, ...addedCollections]) {
26
+ const oldIndexes = getIndexes(oldSchema.collections[changed]);
27
+ const newIndexes = getIndexes(newSchema.collections[changed]);
28
+ const added = newIndexes.filter((index) => !oldIndexes.find((i) => i.name === index.name));
29
+ const removed = oldIndexes.filter((index) => !newIndexes.find((i) => i.name === index.name));
30
+ if (added.length > 0) {
31
+ addedIndexes[changed] = added;
32
+ }
33
+ if (removed.length > 0) {
34
+ removedIndexes[changed] = removed;
35
+ }
36
+ }
37
+ return {
38
+ version: newSchema.version,
39
+ migrate: async (engine) => {
40
+ const migratedCollections = [];
41
+ await procedure({
42
+ migrate: async (collection, strategy) => {
43
+ // @ts-ignore
44
+ await engine.migrate(collection, strategy);
45
+ migratedCollections.push(collection);
46
+ },
47
+ identity: (val) => val,
48
+ withDefaults: (collectionName, val) => {
49
+ return addFieldDefaults(newSchema.collections[collectionName], val);
50
+ },
51
+ info: {
52
+ changedCollections,
53
+ addedCollections,
54
+ removedCollections,
55
+ },
56
+ queries: engine.queries,
57
+ mutations: engine.mutations,
58
+ });
59
+ const unmigrated = changedCollections.filter((collection) => !migratedCollections.includes(collection));
60
+ if (unmigrated.length > 0) {
61
+ console.error('Unmigrated changed collections:', unmigrated);
62
+ }
63
+ },
64
+ removedCollections,
65
+ addedIndexes,
66
+ removedIndexes,
67
+ allCollections: Object.keys(newSchema.collections),
68
+ changedCollections,
69
+ addedCollections,
70
+ oldCollections: Object.keys(oldSchema.collections),
71
+ oldSchema,
72
+ newSchema,
73
+ };
74
+ }
75
+ export function migrationRange(from, to) {
76
+ return [...Array(to - from).keys()].map((i) => 1 + i + from);
77
+ }
78
+ function getIndexes(collection) {
79
+ if (!collection)
80
+ return [];
81
+ const fields = Object.keys(collection.fields)
82
+ .filter((key) => collection.fields[key].indexed)
83
+ .map((key) => ({
84
+ name: key,
85
+ multiEntry: collection.fields[key].type === 'array',
86
+ synthetic: false,
87
+ compound: false,
88
+ }));
89
+ return [
90
+ ...fields,
91
+ ...Object.keys(collection.synthetics || {}).map((key) => ({
92
+ name: key,
93
+ multiEntry: ['array', 'string[]', 'number[]', 'boolean[]'].includes(collection.synthetics[key].type),
94
+ synthetic: true,
95
+ compound: false,
96
+ })),
97
+ ...Object.keys(collection.compounds || {}).map((key) => ({
98
+ name: key,
99
+ multiEntry: collection.compounds[key].of.some((fieldName) => (collection.fields[fieldName] || collection.synthetics[fieldName])
100
+ .type === 'array'),
101
+ synthetic: false,
102
+ compound: true,
103
+ })),
104
+ ];
105
+ }
106
+ export function createDefaultMigration(schema, newSchema) {
107
+ let oldSchema = newSchema
108
+ ? schema
109
+ : {
110
+ version: 0,
111
+ collections: {},
112
+ };
113
+ return migrate(oldSchema, newSchema || schema, async ({ migrate, withDefaults, info }) => {
114
+ if ((newSchema || schema).version === 1)
115
+ return;
116
+ for (const collection of info.changedCollections) {
117
+ // @ts-ignore indefinite type resolution
118
+ await migrate(collection, (old) => withDefaults(collection, old));
119
+ }
120
+ });
121
+ }
122
122
  //# sourceMappingURL=migration.js.map
@@ -1,87 +1,85 @@
1
- import { ObjectRef } from './operation.js';
2
- /**
3
- * OIDs
4
- *
5
- * OIDs are used to identify objects in the document. They also encode
6
- * information about the object useful to identifying an object found
7
- * on its own and associating it back to its parent.
8
- *
9
- * An OID is structured as such:
10
- * <collection>/<root id>[/<key paths>]:<random>
11
- *
12
- * OIDs have a few characteristics:
13
- * - They include the collection name of the parent document
14
- * - They include the primary key of the parent document
15
- * - They include the key path of the object within the document
16
- * - They include a random sequence to identify different objects which
17
- * exist at the same key path
18
- *
19
- * Collection name and document key are used to link any isolated
20
- * object back to its parent document.
21
- *
22
- * The key path is used for authorization - to associate the object
23
- * (or an operation related to it by OID) with the field it inhabits
24
- * to utilize authorization rules from that field in the schema.
25
- *
26
- * The random sequence allows the application to encode different
27
- * identities for objects at the same position in a document for
28
- * conflict resolution purposes
29
- */
30
- export declare type ObjectIdentifier = string;
31
- export declare type KeyPath = (string | number)[];
32
- export declare const LEGACY_OID_KEY = "__@@oid_do_not_use";
33
- export declare const OID_KEY = "@@id";
34
- export declare function getOid(obj: any): string;
35
- export declare function maybeGetOid(obj: any): ObjectIdentifier | undefined;
36
- export declare function assignOid(obj: any, oid: ObjectIdentifier): any;
37
- export declare function hasOid(obj: any): boolean;
38
- export declare function removeOid(obj: any): any;
39
- export declare function isOidKey(key: string): boolean;
40
- /**
41
- * For sub-objects, assign a random sub-OID if no OID
42
- * is already assigned.
43
- */
44
- export declare function ensureOid(obj: any, rootOid: ObjectIdentifier, key: string | number, createSubId?: () => string): string;
45
- export declare function createOid(collection: string, documentId: string, keyPath?: KeyPath, subId?: string): string;
46
- export declare function createSubOid(root: ObjectIdentifier, key: string | number, createSubId?: () => string): string;
47
- export declare function decomposeOid(oid: ObjectIdentifier): {
48
- collection: string;
49
- id: string;
50
- subId?: string;
51
- keyPath: KeyPath;
52
- };
53
- export declare function assertAllLevelsHaveOids(obj: any, root?: any): void;
54
- export declare function assignOidsToAllSubObjects(obj: any, createSubId?: () => string): void;
55
- export declare function assignOidProperty(obj: any, oid: ObjectIdentifier): any;
56
- export declare function maybeGetOidProperty(obj: any): any;
57
- /**
58
- * Assigns a special property to all objects in the given object
59
- * which have an OID
60
- */
61
- export declare function assignOidPropertiesToAllSubObjects(obj: any): void;
62
- /**
63
- *
64
- * Removes the special property from all objects in the given object
65
- * which have an OID, transferring the OID from the property to the OID
66
- * system in-memory.
67
- */
68
- export declare function removeOidPropertiesFromAllSubObjects(obj: any): void;
69
- export declare function removeOidsFromAllSubObjects(obj: any): void;
70
- export declare function createOidSubId(): string;
71
- export declare function createRef(oid: ObjectIdentifier): ObjectRef;
72
- export declare function normalize(obj: any, refs?: Map<ObjectIdentifier, any>): Map<ObjectIdentifier, any>;
73
- /**
74
- * Only normalizes direct children. The created map
75
- * of objects will still have nested objects.
76
- */
77
- export declare function normalizeFirstLevel(obj: any): {
78
- refs: Map<string, any>;
79
- oidKeyPairs: Map<string, string | number>;
80
- };
81
- export declare function getOidRoot(oid: ObjectIdentifier): string;
82
- /**
83
- * Returns an inclusive range of OIDs that represent
84
- * a root object and all of its sub-objects.
85
- */
86
- export declare function getOidRange(oid: ObjectIdentifier): string[];
87
- export declare function getRoots(oids: ObjectIdentifier[]): string[];
1
+ import { ObjectRef } from './operation.js';
2
+ /**
3
+ * OIDs
4
+ *
5
+ * OIDs are used to identify objects in the document. They also encode
6
+ * information about the object useful to identifying an object found
7
+ * on its own and associating it back to its parent.
8
+ *
9
+ * An OID is structured as such:
10
+ * <collection>/<root id>[/<key paths>]:<random>
11
+ *
12
+ * OIDs have a few characteristics:
13
+ * - They include the collection name of the parent document
14
+ * - They include the primary key of the parent document
15
+ * - They include the key path of the object within the document
16
+ * - They include a random sequence to identify different objects which
17
+ * exist at the same key path
18
+ *
19
+ * Collection name and document key are used to link any isolated
20
+ * object back to its parent document.
21
+ *
22
+ * The key path is used for authorization - to associate the object
23
+ * (or an operation related to it by OID) with the field it inhabits
24
+ * to utilize authorization rules from that field in the schema.
25
+ *
26
+ * The random sequence allows the application to encode different
27
+ * identities for objects at the same position in a document for
28
+ * conflict resolution purposes
29
+ */
30
+ export declare type ObjectIdentifier = string;
31
+ export declare const LEGACY_OID_KEY = "__@@oid_do_not_use";
32
+ export declare const OID_KEY = "@@id";
33
+ export declare function getOid(obj: any): string;
34
+ export declare function maybeGetOid(obj: any): ObjectIdentifier | undefined;
35
+ export declare function assignOid(obj: any, oid: ObjectIdentifier): any;
36
+ export declare function hasOid(obj: any): boolean;
37
+ export declare function removeOid(obj: any): any;
38
+ export declare function isOidKey(key: string): boolean;
39
+ /**
40
+ * For sub-objects, assign a random sub-OID if no OID
41
+ * is already assigned.
42
+ */
43
+ export declare function ensureOid(obj: any, rootOid: ObjectIdentifier, createSubId?: () => string): string;
44
+ export declare function createOid(collection: string, documentId: string, subId?: string): string;
45
+ export declare function createSubOid(root: ObjectIdentifier, createSubId?: () => string): string;
46
+ export declare function decomposeOid(oid: ObjectIdentifier): {
47
+ collection: string;
48
+ id: string;
49
+ subId?: string;
50
+ };
51
+ export declare function assertAllLevelsHaveOids(obj: any, root?: any): void;
52
+ export declare function assignOidsToAllSubObjects(obj: any, createSubId?: () => string): void;
53
+ export declare function assignOidProperty(obj: any, oid: ObjectIdentifier): any;
54
+ export declare function maybeGetOidProperty(obj: any): any;
55
+ /**
56
+ * Assigns a special property to all objects in the given object
57
+ * which have an OID
58
+ */
59
+ export declare function assignOidPropertiesToAllSubObjects(obj: any): void;
60
+ /**
61
+ *
62
+ * Removes the special property from all objects in the given object
63
+ * which have an OID, transferring the OID from the property to the OID
64
+ * system in-memory.
65
+ */
66
+ export declare function removeOidPropertiesFromAllSubObjects(obj: any): void;
67
+ export declare function removeOidsFromAllSubObjects(obj: any): void;
68
+ export declare function createOidSubId(): string;
69
+ export declare function createRef(oid: ObjectIdentifier): ObjectRef;
70
+ export declare function normalize(obj: any, refs?: Map<ObjectIdentifier, any>): Map<ObjectIdentifier, any>;
71
+ /**
72
+ * Only normalizes direct children. The created map
73
+ * of objects will still have nested objects.
74
+ */
75
+ export declare function normalizeFirstLevel(obj: any): {
76
+ refs: Map<string, any>;
77
+ oidKeyPairs: Map<string, string | number>;
78
+ };
79
+ export declare function getOidRoot(oid: ObjectIdentifier): string;
80
+ /**
81
+ * Returns an inclusive range of OIDs that represent
82
+ * a root object and all of its sub-objects.
83
+ */
84
+ export declare function getOidRange(oid: ObjectIdentifier): string[];
85
+ export declare function getRoots(oids: ObjectIdentifier[]): string[];