@verdant-web/common 1.15.2 → 1.15.3-next.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 (163) 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 +42 -42
  6. package/dist/cjs/batching.js +91 -91
  7. package/dist/cjs/files.d.ts +19 -19
  8. package/dist/cjs/files.js +18 -18
  9. package/dist/cjs/files.test.d.ts +1 -0
  10. package/dist/cjs/files.test.js +81 -0
  11. package/dist/cjs/files.test.js.map +1 -0
  12. package/dist/cjs/index.d.ts +19 -18
  13. package/dist/cjs/index.js +41 -36
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/indexes.d.ts +17 -17
  16. package/dist/cjs/indexes.js +142 -142
  17. package/dist/cjs/indexes.test.d.ts +1 -1
  18. package/dist/cjs/indexes.test.js +127 -127
  19. package/dist/cjs/migration.d.ts +172 -172
  20. package/dist/cjs/migration.js +301 -301
  21. package/dist/cjs/oids.d.ts +100 -96
  22. package/dist/cjs/oids.js +457 -439
  23. package/dist/cjs/oids.js.map +1 -1
  24. package/dist/cjs/oids.test.d.ts +1 -1
  25. package/dist/cjs/oids.test.js +348 -272
  26. package/dist/cjs/oids.test.js.map +1 -1
  27. package/dist/cjs/operation.d.ts +139 -139
  28. package/dist/cjs/operation.js +545 -545
  29. package/dist/cjs/operation.test.d.ts +1 -1
  30. package/dist/cjs/operation.test.js +529 -529
  31. package/dist/cjs/patch.d.ts +26 -26
  32. package/dist/cjs/patch.js +226 -226
  33. package/dist/cjs/presence.d.ts +27 -27
  34. package/dist/cjs/presence.js +2 -2
  35. package/dist/cjs/protocol.d.ts +145 -145
  36. package/dist/cjs/protocol.js +3 -3
  37. package/dist/cjs/refs.d.ts +7 -5
  38. package/dist/cjs/refs.js +29 -21
  39. package/dist/cjs/refs.js.map +1 -1
  40. package/dist/cjs/replica.d.ts +28 -28
  41. package/dist/cjs/replica.js +28 -28
  42. package/dist/cjs/schema/defaults.d.ts +4 -0
  43. package/dist/cjs/schema/defaults.js +72 -0
  44. package/dist/cjs/schema/defaults.js.map +1 -0
  45. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  46. package/dist/cjs/schema/defaults.test.js +20 -20
  47. package/dist/cjs/schema/fields.d.ts +9 -9
  48. package/dist/cjs/schema/fields.js +144 -144
  49. package/dist/cjs/schema/index.d.ts +8 -8
  50. package/dist/cjs/schema/index.js +51 -51
  51. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  52. package/dist/cjs/schema/indexFilters.js +30 -30
  53. package/dist/cjs/schema/types/collection.d.ts +23 -23
  54. package/dist/cjs/schema/types/collection.js +2 -2
  55. package/dist/cjs/schema/types/compounds.d.ts +11 -11
  56. package/dist/cjs/schema/types/compounds.js +2 -2
  57. package/dist/cjs/schema/types/fields.d.ts +75 -75
  58. package/dist/cjs/schema/types/fields.js +2 -2
  59. package/dist/cjs/schema/types/filters.d.ts +29 -29
  60. package/dist/cjs/schema/types/filters.js +2 -2
  61. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  62. package/dist/cjs/schema/types/shapes.js +2 -2
  63. package/dist/cjs/schema/types/synthetics.d.ts +37 -37
  64. package/dist/cjs/schema/types/synthetics.js +2 -2
  65. package/dist/cjs/schema/types.d.ts +18 -18
  66. package/dist/cjs/schema/types.js +22 -22
  67. package/dist/cjs/schema/validation.d.ts +3 -3
  68. package/dist/cjs/schema/validation.js +86 -86
  69. package/dist/cjs/timestamp.d.ts +50 -50
  70. package/dist/cjs/timestamp.js +251 -251
  71. package/dist/cjs/timestamp.test.d.ts +1 -1
  72. package/dist/cjs/timestamp.test.js +104 -104
  73. package/dist/cjs/undo.d.ts +3 -3
  74. package/dist/cjs/undo.js +198 -198
  75. package/dist/cjs/utils.d.ts +20 -20
  76. package/dist/cjs/utils.js +145 -145
  77. package/dist/cjs/utils.test.d.ts +1 -1
  78. package/dist/cjs/utils.test.js +36 -36
  79. package/dist/esm/EventSubscriber.d.ts +17 -17
  80. package/dist/esm/EventSubscriber.js +62 -62
  81. package/dist/esm/baseline.d.ts +5 -5
  82. package/dist/esm/baseline.js +1 -1
  83. package/dist/esm/batching.d.ts +42 -42
  84. package/dist/esm/batching.js +86 -86
  85. package/dist/esm/files.d.ts +19 -19
  86. package/dist/esm/files.js +12 -12
  87. package/dist/esm/files.test.d.ts +1 -0
  88. package/dist/esm/files.test.js +79 -0
  89. package/dist/esm/files.test.js.map +1 -0
  90. package/dist/esm/index.d.ts +19 -18
  91. package/dist/esm/index.js +16 -15
  92. package/dist/esm/index.js.map +1 -1
  93. package/dist/esm/indexes.d.ts +17 -17
  94. package/dist/esm/indexes.js +130 -130
  95. package/dist/esm/indexes.test.d.ts +1 -1
  96. package/dist/esm/indexes.test.js +125 -125
  97. package/dist/esm/migration.d.ts +172 -172
  98. package/dist/esm/migration.js +294 -294
  99. package/dist/esm/oids.d.ts +100 -96
  100. package/dist/esm/oids.js +422 -407
  101. package/dist/esm/oids.js.map +1 -1
  102. package/dist/esm/oids.test.d.ts +1 -1
  103. package/dist/esm/oids.test.js +346 -270
  104. package/dist/esm/oids.test.js.map +1 -1
  105. package/dist/esm/operation.d.ts +139 -139
  106. package/dist/esm/operation.js +530 -530
  107. package/dist/esm/operation.test.d.ts +1 -1
  108. package/dist/esm/operation.test.js +527 -527
  109. package/dist/esm/patch.d.ts +26 -26
  110. package/dist/esm/patch.js +222 -222
  111. package/dist/esm/presence.d.ts +27 -27
  112. package/dist/esm/presence.js +1 -1
  113. package/dist/esm/protocol.d.ts +145 -145
  114. package/dist/esm/protocol.js +2 -2
  115. package/dist/esm/refs.d.ts +7 -5
  116. package/dist/esm/refs.js +22 -16
  117. package/dist/esm/refs.js.map +1 -1
  118. package/dist/esm/replica.d.ts +28 -28
  119. package/dist/esm/replica.js +25 -25
  120. package/dist/esm/schema/defaults.d.ts +4 -0
  121. package/dist/esm/schema/defaults.js +66 -0
  122. package/dist/esm/schema/defaults.js.map +1 -0
  123. package/dist/esm/schema/defaults.test.d.ts +1 -1
  124. package/dist/esm/schema/defaults.test.js +18 -18
  125. package/dist/esm/schema/fields.d.ts +9 -9
  126. package/dist/esm/schema/fields.js +133 -133
  127. package/dist/esm/schema/index.d.ts +8 -8
  128. package/dist/esm/schema/index.js +32 -32
  129. package/dist/esm/schema/indexFilters.d.ts +6 -6
  130. package/dist/esm/schema/indexFilters.js +22 -22
  131. package/dist/esm/schema/types/collection.d.ts +23 -23
  132. package/dist/esm/schema/types/collection.js +1 -1
  133. package/dist/esm/schema/types/compounds.d.ts +11 -11
  134. package/dist/esm/schema/types/compounds.js +1 -1
  135. package/dist/esm/schema/types/fields.d.ts +75 -75
  136. package/dist/esm/schema/types/fields.js +1 -1
  137. package/dist/esm/schema/types/filters.d.ts +29 -29
  138. package/dist/esm/schema/types/filters.js +1 -1
  139. package/dist/esm/schema/types/shapes.d.ts +21 -21
  140. package/dist/esm/schema/types/shapes.js +1 -1
  141. package/dist/esm/schema/types/synthetics.d.ts +37 -37
  142. package/dist/esm/schema/types/synthetics.js +1 -1
  143. package/dist/esm/schema/types.d.ts +18 -18
  144. package/dist/esm/schema/types.js +6 -6
  145. package/dist/esm/schema/validation.d.ts +3 -3
  146. package/dist/esm/schema/validation.js +81 -81
  147. package/dist/esm/timestamp.d.ts +50 -50
  148. package/dist/esm/timestamp.js +234 -234
  149. package/dist/esm/timestamp.test.d.ts +1 -1
  150. package/dist/esm/timestamp.test.js +102 -102
  151. package/dist/esm/undo.d.ts +3 -3
  152. package/dist/esm/undo.js +194 -194
  153. package/dist/esm/utils.d.ts +20 -20
  154. package/dist/esm/utils.js +127 -127
  155. package/dist/esm/utils.test.d.ts +1 -1
  156. package/dist/esm/utils.test.js +34 -34
  157. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  158. package/dist/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +1 -1
  160. package/src/index.ts +1 -0
  161. package/src/oids.test.ts +82 -0
  162. package/src/oids.ts +17 -0
  163. package/src/refs.ts +8 -0
@@ -1,145 +1,145 @@
1
- import { DocumentBaseline } from './baseline.js';
2
- import { Operation } from './operation.js';
3
- import { UserInfo } from './presence.js';
4
- export declare type HeartbeatMessage = {
5
- type: 'heartbeat';
6
- timestamp: string;
7
- replicaId: string;
8
- };
9
- export declare type HeartbeatResponseMessage = {
10
- type: 'heartbeat-response';
11
- };
12
- /**
13
- * Used by clients to indicate they have
14
- * successfully applied all operations from the
15
- * server up to this one. Uses the nonce from the
16
- * operation rebroadcast message as the ack.
17
- */
18
- export declare type AckMessage = {
19
- type: 'ack';
20
- replicaId: string;
21
- timestamp?: string;
22
- nonce?: string;
23
- };
24
- export declare type OperationMessage = {
25
- type: 'op';
26
- replicaId: string;
27
- operations: Operation[];
28
- timestamp: string;
29
- };
30
- export declare type OperationRebroadcastMessage = {
31
- type: 'op-re';
32
- operations: Operation[];
33
- baselines: DocumentBaseline[];
34
- replicaId: string;
35
- globalAckTimestamp: string | undefined;
36
- ackThisNonce?: string;
37
- };
38
- export declare type SyncMessage = {
39
- type: 'sync';
40
- /** This client's replica ID */
41
- replicaId: string;
42
- /** the logical time this message was sent */
43
- timestamp: string;
44
- /** Any new operations created since the requested time */
45
- operations: Operation[];
46
- /** Any new baselines created since the requested time */
47
- baselines: DocumentBaseline[];
48
- /** the schema version known by this client */
49
- schemaVersion: number;
50
- /**
51
- * the client may have lost its local data, in which
52
- * case it may set this flag to be treated as a new client
53
- * and receive a full baseline
54
- */
55
- resyncAll?: boolean;
56
- /**
57
- * timestamp of when the replica changes began. null means
58
- * full changeset from start of time
59
- */
60
- since: string | null;
61
- };
62
- export declare type SyncResponseMessage = {
63
- type: 'sync-resp';
64
- operations: Operation[];
65
- baselines: DocumentBaseline[];
66
- /**
67
- * If this flag is set, the client should discard local data
68
- * and reset to incoming data only. Used when a client requested
69
- * resyncAll in its sync message, or for clients which have been
70
- * offline for too long. When specified true, provideChangesSince
71
- * should be ignored.
72
- */
73
- overwriteLocalData: boolean;
74
- /**
75
- * Update client on the global ack
76
- */
77
- globalAckTimestamp: string | undefined;
78
- /**
79
- * A map of connected clients' presences values
80
- */
81
- peerPresence: Record<string, UserInfo<any, any>>;
82
- /**
83
- * The timestamp sent in the original sync message -
84
- * this confirms the server has received the client's
85
- * state up to this point. Subsequent syncs should not
86
- * include operations or baselines older than this timestamp.
87
- */
88
- ackedTimestamp: string;
89
- /**
90
- * The client should respond with a sync-ack containing
91
- * this nonce to confirm it has received this message if
92
- * it is not undefined
93
- */
94
- ackThisNonce?: string;
95
- };
96
- /** @deprecated use ack */
97
- export declare type SyncAckMessage = {
98
- type: 'sync-ack';
99
- /** The client's replica ID */
100
- replicaId: string;
101
- /** the logical time this message was sent */
102
- timestamp: string;
103
- /** the nonce sent in the sync-resp message */
104
- nonce: string;
105
- };
106
- export declare type PresenceUpdateMessage = {
107
- type: 'presence-update';
108
- /** The client's replica ID */
109
- replicaId: string;
110
- /** new presence value */
111
- presence: any;
112
- };
113
- export declare type PresenceChangedMessage = {
114
- type: 'presence-changed';
115
- /** The client's replica ID */
116
- replicaId: string;
117
- userInfo: UserInfo<any, any>;
118
- };
119
- /**
120
- * This is only emitted when all of a user's replicas
121
- * go offline.
122
- */
123
- export declare type PresenceOfflineMessage = {
124
- type: 'presence-offline';
125
- userId: string;
126
- /** The last replicaID seen by the server before the user was offline */
127
- replicaId: string;
128
- };
129
- export declare type GlobalAckMessage = {
130
- type: 'global-ack';
131
- timestamp: string;
132
- };
133
- export declare type ForbiddenMessage = {
134
- type: 'forbidden';
135
- };
136
- export declare type ServerAckMessage = {
137
- type: 'server-ack';
138
- timestamp: string;
139
- };
140
- export declare type ServerNeedSinceMessage = {
141
- type: 'need-since';
142
- since: string | null;
143
- };
144
- export declare type ClientMessage = HeartbeatMessage | SyncMessage | OperationMessage | AckMessage | SyncAckMessage | PresenceUpdateMessage;
145
- export declare type ServerMessage = HeartbeatResponseMessage | SyncResponseMessage | OperationRebroadcastMessage | PresenceChangedMessage | PresenceOfflineMessage | GlobalAckMessage | ForbiddenMessage | ServerAckMessage | ServerNeedSinceMessage;
1
+ import { DocumentBaseline } from './baseline.js';
2
+ import { Operation } from './operation.js';
3
+ import { UserInfo } from './presence.js';
4
+ export declare type HeartbeatMessage = {
5
+ type: 'heartbeat';
6
+ timestamp: string;
7
+ replicaId: string;
8
+ };
9
+ export declare type HeartbeatResponseMessage = {
10
+ type: 'heartbeat-response';
11
+ };
12
+ /**
13
+ * Used by clients to indicate they have
14
+ * successfully applied all operations from the
15
+ * server up to this one. Uses the nonce from the
16
+ * operation rebroadcast message as the ack.
17
+ */
18
+ export declare type AckMessage = {
19
+ type: 'ack';
20
+ replicaId: string;
21
+ timestamp?: string;
22
+ nonce?: string;
23
+ };
24
+ export declare type OperationMessage = {
25
+ type: 'op';
26
+ replicaId: string;
27
+ operations: Operation[];
28
+ timestamp: string;
29
+ };
30
+ export declare type OperationRebroadcastMessage = {
31
+ type: 'op-re';
32
+ operations: Operation[];
33
+ baselines: DocumentBaseline[];
34
+ replicaId: string;
35
+ globalAckTimestamp: string | undefined;
36
+ ackThisNonce?: string;
37
+ };
38
+ export declare type SyncMessage = {
39
+ type: 'sync';
40
+ /** This client's replica ID */
41
+ replicaId: string;
42
+ /** the logical time this message was sent */
43
+ timestamp: string;
44
+ /** Any new operations created since the requested time */
45
+ operations: Operation[];
46
+ /** Any new baselines created since the requested time */
47
+ baselines: DocumentBaseline[];
48
+ /** the schema version known by this client */
49
+ schemaVersion: number;
50
+ /**
51
+ * the client may have lost its local data, in which
52
+ * case it may set this flag to be treated as a new client
53
+ * and receive a full baseline
54
+ */
55
+ resyncAll?: boolean;
56
+ /**
57
+ * timestamp of when the replica changes began. null means
58
+ * full changeset from start of time
59
+ */
60
+ since: string | null;
61
+ };
62
+ export declare type SyncResponseMessage = {
63
+ type: 'sync-resp';
64
+ operations: Operation[];
65
+ baselines: DocumentBaseline[];
66
+ /**
67
+ * If this flag is set, the client should discard local data
68
+ * and reset to incoming data only. Used when a client requested
69
+ * resyncAll in its sync message, or for clients which have been
70
+ * offline for too long. When specified true, provideChangesSince
71
+ * should be ignored.
72
+ */
73
+ overwriteLocalData: boolean;
74
+ /**
75
+ * Update client on the global ack
76
+ */
77
+ globalAckTimestamp: string | undefined;
78
+ /**
79
+ * A map of connected clients' presences values
80
+ */
81
+ peerPresence: Record<string, UserInfo<any, any>>;
82
+ /**
83
+ * The timestamp sent in the original sync message -
84
+ * this confirms the server has received the client's
85
+ * state up to this point. Subsequent syncs should not
86
+ * include operations or baselines older than this timestamp.
87
+ */
88
+ ackedTimestamp: string;
89
+ /**
90
+ * The client should respond with a sync-ack containing
91
+ * this nonce to confirm it has received this message if
92
+ * it is not undefined
93
+ */
94
+ ackThisNonce?: string;
95
+ };
96
+ /** @deprecated use ack */
97
+ export declare type SyncAckMessage = {
98
+ type: 'sync-ack';
99
+ /** The client's replica ID */
100
+ replicaId: string;
101
+ /** the logical time this message was sent */
102
+ timestamp: string;
103
+ /** the nonce sent in the sync-resp message */
104
+ nonce: string;
105
+ };
106
+ export declare type PresenceUpdateMessage = {
107
+ type: 'presence-update';
108
+ /** The client's replica ID */
109
+ replicaId: string;
110
+ /** new presence value */
111
+ presence: any;
112
+ };
113
+ export declare type PresenceChangedMessage = {
114
+ type: 'presence-changed';
115
+ /** The client's replica ID */
116
+ replicaId: string;
117
+ userInfo: UserInfo<any, any>;
118
+ };
119
+ /**
120
+ * This is only emitted when all of a user's replicas
121
+ * go offline.
122
+ */
123
+ export declare type PresenceOfflineMessage = {
124
+ type: 'presence-offline';
125
+ userId: string;
126
+ /** The last replicaID seen by the server before the user was offline */
127
+ replicaId: string;
128
+ };
129
+ export declare type GlobalAckMessage = {
130
+ type: 'global-ack';
131
+ timestamp: string;
132
+ };
133
+ export declare type ForbiddenMessage = {
134
+ type: 'forbidden';
135
+ };
136
+ export declare type ServerAckMessage = {
137
+ type: 'server-ack';
138
+ timestamp: string;
139
+ };
140
+ export declare type ServerNeedSinceMessage = {
141
+ type: 'need-since';
142
+ since: string | null;
143
+ };
144
+ export declare type ClientMessage = HeartbeatMessage | SyncMessage | OperationMessage | AckMessage | SyncAckMessage | PresenceUpdateMessage;
145
+ export declare type ServerMessage = HeartbeatResponseMessage | SyncResponseMessage | OperationRebroadcastMessage | PresenceChangedMessage | PresenceOfflineMessage | GlobalAckMessage | ForbiddenMessage | ServerAckMessage | ServerNeedSinceMessage;
@@ -1,3 +1,3 @@
1
- // client ID, and therefore library ID, is inferred
2
- export {};
1
+ // client ID, and therefore library ID, is inferred
2
+ export {};
3
3
  //# sourceMappingURL=protocol.js.map
@@ -1,5 +1,7 @@
1
- import { FileRef } from './files.js';
2
- import { ObjectRef } from './operation.js';
3
- export declare function isRef(obj: any): boolean;
4
- export declare function compareRefs(a: any, b: any): boolean;
5
- export declare type Ref = ObjectRef | FileRef;
1
+ import { FileRef } from './files.js';
2
+ import { ObjectRef } from './operation.js';
3
+ export declare function isRef(obj: any): boolean;
4
+ export declare function compareRefs(a: any, b: any): boolean;
5
+ export declare type Ref = ObjectRef | FileRef;
6
+ export declare function makeObjectRef(oid: string): ObjectRef;
7
+ export declare function makeFileRef(oid: string): FileRef;
package/dist/esm/refs.js CHANGED
@@ -1,17 +1,23 @@
1
- import { isFileRef } from './files.js';
2
- import { isObjectRef } from './operation.js';
3
- export function isRef(obj) {
4
- return isObjectRef(obj) || isFileRef(obj);
5
- }
6
- export function compareRefs(a, b) {
7
- if (a === b)
8
- return true;
9
- if (!isRef(a) || !isRef(b))
10
- return false;
11
- if (a['@@type'] !== b['@@type'])
12
- return false;
13
- if (a.id !== b.id)
14
- return false;
15
- return true;
16
- }
1
+ import { isFileRef } from './files.js';
2
+ import { isObjectRef } from './operation.js';
3
+ export function isRef(obj) {
4
+ return isObjectRef(obj) || isFileRef(obj);
5
+ }
6
+ export function compareRefs(a, b) {
7
+ if (a === b)
8
+ return true;
9
+ if (!isRef(a) || !isRef(b))
10
+ return false;
11
+ if (a['@@type'] !== b['@@type'])
12
+ return false;
13
+ if (a.id !== b.id)
14
+ return false;
15
+ return true;
16
+ }
17
+ export function makeObjectRef(oid) {
18
+ return { '@@type': 'ref', id: oid };
19
+ }
20
+ export function makeFileRef(oid) {
21
+ return { '@@type': 'file', id: oid };
22
+ }
17
23
  //# sourceMappingURL=refs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,SAAS,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,WAAW,EAAa,MAAM,gBAAgB,CAAC;AAExD,MAAM,UAAU,KAAK,CAAC,GAAQ;IAC7B,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAM,EAAE,CAAM;IACzC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IAChC,OAAO,IAAI,CAAC;AACb,CAAC"}
1
+ {"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,SAAS,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,WAAW,EAAa,MAAM,gBAAgB,CAAC;AAExD,MAAM,UAAU,KAAK,CAAC,GAAQ;IAC7B,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAM,EAAE,CAAM;IACzC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IAChC,OAAO,IAAI,CAAC;AACb,CAAC;AAID,MAAM,UAAU,aAAa,CAAC,GAAW;IACxC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAW;IACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC;AACtC,CAAC"}
@@ -1,28 +1,28 @@
1
- export interface ReplicaInfo {
2
- id: string;
3
- ackedLogicalTime: string | null;
4
- }
5
- /**
6
- * Different token types allow different replica client behaviors.
7
- * - Realtime: allows the client to subscribe to realtime events.
8
- * - Push: allows the client to push and pull data with HTTP, but not use realtime.
9
- * - PassivePush: allows the client to push and pull data with HTTP, but offline changes
10
- * will be discarded on reconnect.
11
- * - PassiveRealtime: allows the client to subscribe to realtime events, but offline changes
12
- * will be discarded on reconnect.
13
- * - ReadOnlyPull: the client may only pull changes using HTTP. It may not subscribe
14
- * to realtime events or push changes.
15
- * - ReadOnlyRealtime: the client may only subscribe to realtime events or pull from HTTP.
16
- * It may not push changes.
17
- *
18
- * Choosing the right token type can optimize client storage metrics significantly when
19
- * many replicas are connecting to a library.
20
- */
21
- export declare enum ReplicaType {
22
- Realtime = 0,
23
- Push = 1,
24
- PassiveRealtime = 2,
25
- PassivePush = 3,
26
- ReadOnlyPull = 4,
27
- ReadOnlyRealtime = 5
28
- }
1
+ export interface ReplicaInfo {
2
+ id: string;
3
+ ackedLogicalTime: string | null;
4
+ }
5
+ /**
6
+ * Different token types allow different replica client behaviors.
7
+ * - Realtime: allows the client to subscribe to realtime events.
8
+ * - Push: allows the client to push and pull data with HTTP, but not use realtime.
9
+ * - PassivePush: allows the client to push and pull data with HTTP, but offline changes
10
+ * will be discarded on reconnect.
11
+ * - PassiveRealtime: allows the client to subscribe to realtime events, but offline changes
12
+ * will be discarded on reconnect.
13
+ * - ReadOnlyPull: the client may only pull changes using HTTP. It may not subscribe
14
+ * to realtime events or push changes.
15
+ * - ReadOnlyRealtime: the client may only subscribe to realtime events or pull from HTTP.
16
+ * It may not push changes.
17
+ *
18
+ * Choosing the right token type can optimize client storage metrics significantly when
19
+ * many replicas are connecting to a library.
20
+ */
21
+ export declare enum ReplicaType {
22
+ Realtime = 0,
23
+ Push = 1,
24
+ PassiveRealtime = 2,
25
+ PassivePush = 3,
26
+ ReadOnlyPull = 4,
27
+ ReadOnlyRealtime = 5
28
+ }
@@ -1,26 +1,26 @@
1
- /**
2
- * Different token types allow different replica client behaviors.
3
- * - Realtime: allows the client to subscribe to realtime events.
4
- * - Push: allows the client to push and pull data with HTTP, but not use realtime.
5
- * - PassivePush: allows the client to push and pull data with HTTP, but offline changes
6
- * will be discarded on reconnect.
7
- * - PassiveRealtime: allows the client to subscribe to realtime events, but offline changes
8
- * will be discarded on reconnect.
9
- * - ReadOnlyPull: the client may only pull changes using HTTP. It may not subscribe
10
- * to realtime events or push changes.
11
- * - ReadOnlyRealtime: the client may only subscribe to realtime events or pull from HTTP.
12
- * It may not push changes.
13
- *
14
- * Choosing the right token type can optimize client storage metrics significantly when
15
- * many replicas are connecting to a library.
16
- */
17
- export var ReplicaType;
18
- (function (ReplicaType) {
19
- ReplicaType[ReplicaType["Realtime"] = 0] = "Realtime";
20
- ReplicaType[ReplicaType["Push"] = 1] = "Push";
21
- ReplicaType[ReplicaType["PassiveRealtime"] = 2] = "PassiveRealtime";
22
- ReplicaType[ReplicaType["PassivePush"] = 3] = "PassivePush";
23
- ReplicaType[ReplicaType["ReadOnlyPull"] = 4] = "ReadOnlyPull";
24
- ReplicaType[ReplicaType["ReadOnlyRealtime"] = 5] = "ReadOnlyRealtime";
25
- })(ReplicaType = ReplicaType || (ReplicaType = {}));
1
+ /**
2
+ * Different token types allow different replica client behaviors.
3
+ * - Realtime: allows the client to subscribe to realtime events.
4
+ * - Push: allows the client to push and pull data with HTTP, but not use realtime.
5
+ * - PassivePush: allows the client to push and pull data with HTTP, but offline changes
6
+ * will be discarded on reconnect.
7
+ * - PassiveRealtime: allows the client to subscribe to realtime events, but offline changes
8
+ * will be discarded on reconnect.
9
+ * - ReadOnlyPull: the client may only pull changes using HTTP. It may not subscribe
10
+ * to realtime events or push changes.
11
+ * - ReadOnlyRealtime: the client may only subscribe to realtime events or pull from HTTP.
12
+ * It may not push changes.
13
+ *
14
+ * Choosing the right token type can optimize client storage metrics significantly when
15
+ * many replicas are connecting to a library.
16
+ */
17
+ export var ReplicaType;
18
+ (function (ReplicaType) {
19
+ ReplicaType[ReplicaType["Realtime"] = 0] = "Realtime";
20
+ ReplicaType[ReplicaType["Push"] = 1] = "Push";
21
+ ReplicaType[ReplicaType["PassiveRealtime"] = 2] = "PassiveRealtime";
22
+ ReplicaType[ReplicaType["PassivePush"] = 3] = "PassivePush";
23
+ ReplicaType[ReplicaType["ReadOnlyPull"] = 4] = "ReadOnlyPull";
24
+ ReplicaType[ReplicaType["ReadOnlyRealtime"] = 5] = "ReadOnlyRealtime";
25
+ })(ReplicaType = ReplicaType || (ReplicaType = {}));
26
26
  //# sourceMappingURL=replica.js.map
@@ -0,0 +1,4 @@
1
+ import type { StorageFieldSchema, StorageCollectionSchema } from './types.js';
2
+ export declare function addFieldDefaults(collection: StorageCollectionSchema, value: any): any;
3
+ export declare function traverseCollectionFieldsAndApplyDefaults(value: any, field: StorageFieldSchema): any;
4
+ export declare function getFieldDefault(field: StorageFieldSchema): any;
@@ -0,0 +1,66 @@
1
+ import { LEGACY_OID_KEY, OID_KEY } from '../oids.js';
2
+ export function addFieldDefaults(collection, value) {
3
+ for (const [key, field] of Object.entries(collection.fields)) {
4
+ const defaultValue = getFieldDefault(field);
5
+ if (defaultValue !== undefined && value[key] === undefined) {
6
+ value[key] = defaultValue;
7
+ }
8
+ if (value[key]) {
9
+ traverseCollectionFieldsAndApplyDefaults(value[key], field);
10
+ }
11
+ }
12
+ return value;
13
+ }
14
+ export function traverseCollectionFieldsAndApplyDefaults(value, field) {
15
+ if (value === undefined || value === null)
16
+ return value;
17
+ if (field.type === 'object') {
18
+ for (const [key, subField] of Object.entries(field.properties)) {
19
+ if (value[key] === undefined) {
20
+ const defaultValue = getFieldDefault(subField);
21
+ if (defaultValue !== undefined) {
22
+ value[key] = defaultValue;
23
+ }
24
+ }
25
+ traverseCollectionFieldsAndApplyDefaults(value[key], subField);
26
+ }
27
+ }
28
+ else if (field.type === 'array') {
29
+ for (const item of value) {
30
+ traverseCollectionFieldsAndApplyDefaults(item, field.items);
31
+ }
32
+ }
33
+ else if (field.type === 'map') {
34
+ for (const [key, item] of Object.entries(value)) {
35
+ // santiy check to weed out any id field
36
+ if (key === OID_KEY || key === LEGACY_OID_KEY)
37
+ continue;
38
+ traverseCollectionFieldsAndApplyDefaults(item, field.values);
39
+ }
40
+ }
41
+ }
42
+ export function getFieldDefault(field) {
43
+ if (field.type === 'string' ||
44
+ field.type === 'number' ||
45
+ field.type === 'boolean' ||
46
+ field.type === 'any') {
47
+ if (field.default && typeof field.default === 'function') {
48
+ return field.default();
49
+ }
50
+ else if (field.default !== undefined) {
51
+ // TODO: structuredClone?
52
+ return JSON.parse(JSON.stringify(field.default));
53
+ }
54
+ }
55
+ if (field.type === 'array') {
56
+ return [];
57
+ }
58
+ if (field.type === 'map') {
59
+ return {};
60
+ }
61
+ if (field.type !== 'any' && field.nullable) {
62
+ return null;
63
+ }
64
+ return undefined;
65
+ }
66
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../../src/schema/defaults.ts"],"names":[],"mappings":"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"}
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,19 +1,19 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getFieldDefault } from './fields.js';
3
- import { assignOid, createOid, maybeGetOid } from '../oids.js';
4
- describe('getting field defaults', () => {
5
- it('does not apply the same oid from the previous application', () => {
6
- const field = {
7
- type: 'any',
8
- default: {
9
- id: '123',
10
- name: 'test',
11
- },
12
- };
13
- const first = getFieldDefault(field);
14
- assignOid(first, createOid('test', '1'));
15
- const second = getFieldDefault(field);
16
- expect(maybeGetOid(second)).toBe(undefined);
17
- });
18
- });
1
+ import { describe, expect, it } from 'vitest';
2
+ import { getFieldDefault } from './fields.js';
3
+ import { assignOid, createOid, maybeGetOid } from '../oids.js';
4
+ describe('getting field defaults', () => {
5
+ it('does not apply the same oid from the previous application', () => {
6
+ const field = {
7
+ type: 'any',
8
+ default: {
9
+ id: '123',
10
+ name: 'test',
11
+ },
12
+ };
13
+ const first = getFieldDefault(field);
14
+ assignOid(first, createOid('test', '1'));
15
+ const second = getFieldDefault(field);
16
+ expect(maybeGetOid(second)).toBe(undefined);
17
+ });
18
+ });
19
19
  //# sourceMappingURL=defaults.test.js.map
@@ -1,9 +1,9 @@
1
- import type { StorageFieldSchema, StorageCollectionSchema } from './types.js';
2
- export declare function isNullable(field: StorageFieldSchema): boolean | undefined;
3
- export declare function hasDefault(field: StorageFieldSchema | undefined): boolean;
4
- export declare function isIndexed(field: StorageFieldSchema): boolean | undefined;
5
- export declare function addFieldDefaults(collection: StorageCollectionSchema, value: any): any;
6
- export declare function traverseCollectionFieldsAndApplyDefaults(value: any, field: StorageFieldSchema): any;
7
- export declare function getFieldDefault(field: StorageFieldSchema): any;
8
- export declare function removeExtraProperties(collection: StorageCollectionSchema, value: any): any;
9
- export declare function traverseCollectionFieldsAndRemoveExtraProperties(value: any, field: StorageFieldSchema): void;
1
+ import type { StorageFieldSchema, StorageCollectionSchema } from './types.js';
2
+ export declare function isNullable(field: StorageFieldSchema): boolean | undefined;
3
+ export declare function hasDefault(field: StorageFieldSchema | undefined): boolean;
4
+ export declare function isIndexed(field: StorageFieldSchema): boolean | undefined;
5
+ export declare function addFieldDefaults(collection: StorageCollectionSchema, value: any): any;
6
+ export declare function traverseCollectionFieldsAndApplyDefaults(value: any, field: StorageFieldSchema): any;
7
+ export declare function getFieldDefault(field: StorageFieldSchema): any;
8
+ export declare function removeExtraProperties(collection: StorageCollectionSchema, value: any): any;
9
+ export declare function traverseCollectionFieldsAndRemoveExtraProperties(value: any, field: StorageFieldSchema): void;