@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,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=presence.js.map
@@ -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,5 @@
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;
package/dist/esm/refs.js CHANGED
@@ -1,17 +1,17 @@
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
17
  //# sourceMappingURL=refs.js.map
@@ -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 = {}));
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 = {}));
26
26
  //# sourceMappingURL=replica.js.map
@@ -1,4 +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;
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;
@@ -1,66 +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
- }
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
66
  //# sourceMappingURL=defaults.js.map
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,19 +1,19 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getFieldDefault } from './defaults.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 './defaults.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 +1 @@
1
- {"version":3,"file":"defaults.test.js","sourceRoot":"","sources":["../../../src/schema/defaults.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAU,WAAW,EAAE,MAAM,YAAY,CAAC;AAEvE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACvC,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACpE,MAAM,KAAK,GAAG;YACb,IAAI,EAAE,KAAK;YACX,OAAO,EAAE;gBACR,EAAE,EAAE,KAAK;gBACT,IAAI,EAAE,MAAM;aACZ;SACQ,CAAC;QACX,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACrC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACtC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"defaults.test.js","sourceRoot":"","sources":["../../../src/schema/defaults.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAU,WAAW,EAAE,MAAM,YAAY,CAAC;AAEvE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACvC,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACpE,MAAM,KAAK,GAAG;YACb,IAAI,EAAE,KAAK;YACX,OAAO,EAAE;gBACR,EAAE,EAAE,KAAK;gBACT,IAAI,EAAE,MAAM;aACZ;SACQ,CAAC;QACX,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACrC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACtC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}