@verdant-web/common 1.11.0 → 1.11.1

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 (141) 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 +87 -87
  18. package/dist/cjs/oids.js +374 -374
  19. package/dist/cjs/oids.test.d.ts +1 -1
  20. package/dist/cjs/oids.test.js +245 -245
  21. package/dist/cjs/operation.d.ts +139 -139
  22. package/dist/cjs/operation.js +532 -532
  23. package/dist/cjs/operation.test.d.ts +1 -1
  24. package/dist/cjs/operation.test.js +484 -484
  25. package/dist/cjs/patch.d.ts +26 -26
  26. package/dist/cjs/patch.js +226 -226
  27. package/dist/cjs/presence.d.ts +27 -27
  28. package/dist/cjs/presence.js +2 -2
  29. package/dist/cjs/protocol.d.ts +145 -145
  30. package/dist/cjs/protocol.js +3 -3
  31. package/dist/cjs/refs.d.ts +5 -5
  32. package/dist/cjs/refs.js +21 -21
  33. package/dist/cjs/replica.d.ts +28 -28
  34. package/dist/cjs/replica.js +28 -28
  35. package/dist/cjs/schema/defaults.d.ts +4 -4
  36. package/dist/cjs/schema/defaults.js +71 -71
  37. package/dist/cjs/schema/defaults.test.d.ts +1 -1
  38. package/dist/cjs/schema/defaults.test.js +20 -20
  39. package/dist/cjs/schema/index.d.ts +8 -8
  40. package/dist/cjs/schema/index.js +28 -28
  41. package/dist/cjs/schema/indexFilters.d.ts +6 -6
  42. package/dist/cjs/schema/indexFilters.js +30 -30
  43. package/dist/cjs/schema/types/collection.d.ts +51 -51
  44. package/dist/cjs/schema/types/collection.js +2 -2
  45. package/dist/cjs/schema/types/compounds.d.ts +12 -12
  46. package/dist/cjs/schema/types/compounds.js +2 -2
  47. package/dist/cjs/schema/types/fields.d.ts +59 -59
  48. package/dist/cjs/schema/types/fields.js +2 -2
  49. package/dist/cjs/schema/types/filters.d.ts +29 -29
  50. package/dist/cjs/schema/types/filters.js +2 -2
  51. package/dist/cjs/schema/types/shapes.d.ts +21 -21
  52. package/dist/cjs/schema/types/shapes.js +2 -2
  53. package/dist/cjs/schema/types/synthetics.d.ts +28 -28
  54. package/dist/cjs/schema/types/synthetics.js +2 -2
  55. package/dist/cjs/schema/types.d.ts +18 -18
  56. package/dist/cjs/schema/types.js +22 -22
  57. package/dist/cjs/timestamp.d.ts +48 -48
  58. package/dist/cjs/timestamp.js +243 -243
  59. package/dist/cjs/timestamp.test.d.ts +1 -1
  60. package/dist/cjs/timestamp.test.js +93 -93
  61. package/dist/cjs/undo.d.ts +3 -3
  62. package/dist/cjs/undo.js +198 -198
  63. package/dist/cjs/utils.d.ts +15 -15
  64. package/dist/cjs/utils.js +127 -127
  65. package/dist/cjs/utils.test.d.ts +1 -1
  66. package/dist/cjs/utils.test.js +36 -36
  67. package/dist/esm/EventSubscriber.d.ts +17 -17
  68. package/dist/esm/EventSubscriber.js +62 -62
  69. package/dist/esm/baseline.d.ts +5 -5
  70. package/dist/esm/baseline.js +1 -1
  71. package/dist/esm/batching.d.ts +41 -41
  72. package/dist/esm/batching.js +83 -83
  73. package/dist/esm/files.d.ts +19 -19
  74. package/dist/esm/files.js +12 -12
  75. package/dist/esm/index.d.ts +18 -18
  76. package/dist/esm/index.js +15 -15
  77. package/dist/esm/indexes.d.ts +14 -14
  78. package/dist/esm/indexes.js +105 -105
  79. package/dist/esm/indexes.test.d.ts +1 -1
  80. package/dist/esm/indexes.test.js +125 -125
  81. package/dist/esm/migration.d.ts +98 -98
  82. package/dist/esm/migration.js +121 -121
  83. package/dist/esm/oids.d.ts +87 -87
  84. package/dist/esm/oids.js +347 -347
  85. package/dist/esm/oids.test.d.ts +1 -1
  86. package/dist/esm/oids.test.js +243 -243
  87. package/dist/esm/operation.d.ts +139 -139
  88. package/dist/esm/operation.js +517 -517
  89. package/dist/esm/operation.test.d.ts +1 -1
  90. package/dist/esm/operation.test.js +482 -482
  91. package/dist/esm/patch.d.ts +26 -26
  92. package/dist/esm/patch.js +222 -222
  93. package/dist/esm/presence.d.ts +27 -27
  94. package/dist/esm/presence.js +1 -1
  95. package/dist/esm/protocol.d.ts +145 -145
  96. package/dist/esm/protocol.js +2 -2
  97. package/dist/esm/refs.d.ts +5 -5
  98. package/dist/esm/refs.js +16 -16
  99. package/dist/esm/replica.d.ts +28 -28
  100. package/dist/esm/replica.js +25 -25
  101. package/dist/esm/schema/defaults.d.ts +4 -4
  102. package/dist/esm/schema/defaults.js +65 -65
  103. package/dist/esm/schema/defaults.test.d.ts +1 -1
  104. package/dist/esm/schema/defaults.test.js +18 -18
  105. package/dist/esm/schema/index.d.ts +8 -8
  106. package/dist/esm/schema/index.js +9 -9
  107. package/dist/esm/schema/indexFilters.d.ts +6 -6
  108. package/dist/esm/schema/indexFilters.js +22 -22
  109. package/dist/esm/schema/types/collection.d.ts +51 -51
  110. package/dist/esm/schema/types/collection.js +1 -1
  111. package/dist/esm/schema/types/compounds.d.ts +12 -12
  112. package/dist/esm/schema/types/compounds.js +1 -1
  113. package/dist/esm/schema/types/fields.d.ts +59 -59
  114. package/dist/esm/schema/types/fields.js +1 -1
  115. package/dist/esm/schema/types/filters.d.ts +29 -29
  116. package/dist/esm/schema/types/filters.js +1 -1
  117. package/dist/esm/schema/types/shapes.d.ts +21 -21
  118. package/dist/esm/schema/types/shapes.js +1 -1
  119. package/dist/esm/schema/types/synthetics.d.ts +28 -28
  120. package/dist/esm/schema/types/synthetics.js +1 -1
  121. package/dist/esm/schema/types.d.ts +18 -18
  122. package/dist/esm/schema/types.js +6 -6
  123. package/dist/esm/timestamp.d.ts +48 -48
  124. package/dist/esm/timestamp.js +228 -228
  125. package/dist/esm/timestamp.test.d.ts +1 -1
  126. package/dist/esm/timestamp.test.js +91 -91
  127. package/dist/esm/undo.d.ts +3 -3
  128. package/dist/esm/undo.js +194 -194
  129. package/dist/esm/utils.d.ts +15 -15
  130. package/dist/esm/utils.js +113 -113
  131. package/dist/esm/utils.test.d.ts +1 -1
  132. package/dist/esm/utils.test.js +34 -34
  133. package/dist/tsconfig-cjs.tsbuildinfo +1 -1
  134. package/dist/tsconfig.tsbuildinfo +1 -1
  135. package/package.json +1 -1
  136. package/dist/cjs/files.test.d.ts +0 -1
  137. package/dist/cjs/files.test.js +0 -81
  138. package/dist/cjs/files.test.js.map +0 -1
  139. package/dist/esm/files.test.d.ts +0 -1
  140. package/dist/esm/files.test.js +0 -79
  141. package/dist/esm/files.test.js.map +0 -1
@@ -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,4 +1,4 @@
1
- "use strict";
2
- // client ID, and therefore library ID, is inferred
3
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ // client ID, and therefore library ID, is inferred
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  //# 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/cjs/refs.js CHANGED
@@ -1,22 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compareRefs = exports.isRef = void 0;
4
- const files_js_1 = require("./files.js");
5
- const operation_js_1 = require("./operation.js");
6
- function isRef(obj) {
7
- return (0, operation_js_1.isObjectRef)(obj) || (0, files_js_1.isFileRef)(obj);
8
- }
9
- exports.isRef = isRef;
10
- function compareRefs(a, b) {
11
- if (a === b)
12
- return true;
13
- if (!isRef(a) || !isRef(b))
14
- return false;
15
- if (a['@@type'] !== b['@@type'])
16
- return false;
17
- if (a.id !== b.id)
18
- return false;
19
- return true;
20
- }
21
- exports.compareRefs = compareRefs;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareRefs = exports.isRef = void 0;
4
+ const files_js_1 = require("./files.js");
5
+ const operation_js_1 = require("./operation.js");
6
+ function isRef(obj) {
7
+ return (0, operation_js_1.isObjectRef)(obj) || (0, files_js_1.isFileRef)(obj);
8
+ }
9
+ exports.isRef = isRef;
10
+ function compareRefs(a, b) {
11
+ if (a === b)
12
+ return true;
13
+ if (!isRef(a) || !isRef(b))
14
+ return false;
15
+ if (a['@@type'] !== b['@@type'])
16
+ return false;
17
+ if (a.id !== b.id)
18
+ return false;
19
+ return true;
20
+ }
21
+ exports.compareRefs = compareRefs;
22
22
  //# 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,29 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReplicaType = void 0;
4
- /**
5
- * Different token types allow different replica client behaviors.
6
- * - Realtime: allows the client to subscribe to realtime events.
7
- * - Push: allows the client to push and pull data with HTTP, but not use realtime.
8
- * - PassivePush: allows the client to push and pull data with HTTP, but offline changes
9
- * will be discarded on reconnect.
10
- * - PassiveRealtime: allows the client to subscribe to realtime events, but offline changes
11
- * will be discarded on reconnect.
12
- * - ReadOnlyPull: the client may only pull changes using HTTP. It may not subscribe
13
- * to realtime events or push changes.
14
- * - ReadOnlyRealtime: the client may only subscribe to realtime events or pull from HTTP.
15
- * It may not push changes.
16
- *
17
- * Choosing the right token type can optimize client storage metrics significantly when
18
- * many replicas are connecting to a library.
19
- */
20
- var ReplicaType;
21
- (function (ReplicaType) {
22
- ReplicaType[ReplicaType["Realtime"] = 0] = "Realtime";
23
- ReplicaType[ReplicaType["Push"] = 1] = "Push";
24
- ReplicaType[ReplicaType["PassiveRealtime"] = 2] = "PassiveRealtime";
25
- ReplicaType[ReplicaType["PassivePush"] = 3] = "PassivePush";
26
- ReplicaType[ReplicaType["ReadOnlyPull"] = 4] = "ReadOnlyPull";
27
- ReplicaType[ReplicaType["ReadOnlyRealtime"] = 5] = "ReadOnlyRealtime";
28
- })(ReplicaType = exports.ReplicaType || (exports.ReplicaType = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReplicaType = void 0;
4
+ /**
5
+ * Different token types allow different replica client behaviors.
6
+ * - Realtime: allows the client to subscribe to realtime events.
7
+ * - Push: allows the client to push and pull data with HTTP, but not use realtime.
8
+ * - PassivePush: allows the client to push and pull data with HTTP, but offline changes
9
+ * will be discarded on reconnect.
10
+ * - PassiveRealtime: allows the client to subscribe to realtime events, but offline changes
11
+ * will be discarded on reconnect.
12
+ * - ReadOnlyPull: the client may only pull changes using HTTP. It may not subscribe
13
+ * to realtime events or push changes.
14
+ * - ReadOnlyRealtime: the client may only subscribe to realtime events or pull from HTTP.
15
+ * It may not push changes.
16
+ *
17
+ * Choosing the right token type can optimize client storage metrics significantly when
18
+ * many replicas are connecting to a library.
19
+ */
20
+ var ReplicaType;
21
+ (function (ReplicaType) {
22
+ ReplicaType[ReplicaType["Realtime"] = 0] = "Realtime";
23
+ ReplicaType[ReplicaType["Push"] = 1] = "Push";
24
+ ReplicaType[ReplicaType["PassiveRealtime"] = 2] = "PassiveRealtime";
25
+ ReplicaType[ReplicaType["PassivePush"] = 3] = "PassivePush";
26
+ ReplicaType[ReplicaType["ReadOnlyPull"] = 4] = "ReadOnlyPull";
27
+ ReplicaType[ReplicaType["ReadOnlyRealtime"] = 5] = "ReadOnlyRealtime";
28
+ })(ReplicaType = exports.ReplicaType || (exports.ReplicaType = {}));
29
29
  //# 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,72 +1,72 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFieldDefault = exports.traverseCollectionFieldsAndApplyDefaults = exports.addFieldDefaults = void 0;
4
- const oids_js_1 = require("../oids.js");
5
- function addFieldDefaults(collection, value) {
6
- for (const [key, field] of Object.entries(collection.fields)) {
7
- const defaultValue = getFieldDefault(field);
8
- if (defaultValue !== undefined && value[key] === undefined) {
9
- value[key] = defaultValue;
10
- }
11
- if (value[key]) {
12
- traverseCollectionFieldsAndApplyDefaults(value[key], field);
13
- }
14
- }
15
- return value;
16
- }
17
- exports.addFieldDefaults = addFieldDefaults;
18
- function traverseCollectionFieldsAndApplyDefaults(value, field) {
19
- if (value === undefined || value === null)
20
- return value;
21
- if (field.type === 'object') {
22
- for (const [key, subField] of Object.entries(field.properties)) {
23
- if (value[key] === undefined) {
24
- const defaultValue = getFieldDefault(subField);
25
- if (defaultValue !== undefined) {
26
- value[key] = defaultValue;
27
- }
28
- }
29
- traverseCollectionFieldsAndApplyDefaults(value[key], subField);
30
- }
31
- }
32
- else if (field.type === 'array') {
33
- for (const item of value) {
34
- traverseCollectionFieldsAndApplyDefaults(item, field.items);
35
- }
36
- }
37
- else if (field.type === 'map') {
38
- for (const [key, item] of Object.entries(value)) {
39
- // santiy check to weed out any id field
40
- if (key === oids_js_1.OID_KEY || key === oids_js_1.LEGACY_OID_KEY)
41
- continue;
42
- traverseCollectionFieldsAndApplyDefaults(item, field.values);
43
- }
44
- }
45
- }
46
- exports.traverseCollectionFieldsAndApplyDefaults = traverseCollectionFieldsAndApplyDefaults;
47
- function getFieldDefault(field) {
48
- if (field.type === 'string' ||
49
- field.type === 'number' ||
50
- field.type === 'boolean' ||
51
- field.type === 'any') {
52
- if (field.default && typeof field.default === 'function') {
53
- return field.default();
54
- }
55
- else if (field.default !== undefined) {
56
- // TODO: structuredClone?
57
- return JSON.parse(JSON.stringify(field.default));
58
- }
59
- }
60
- if (field.type === 'array') {
61
- return [];
62
- }
63
- if (field.type === 'map') {
64
- return {};
65
- }
66
- if (field.type !== 'any' && field.nullable) {
67
- return null;
68
- }
69
- return undefined;
70
- }
71
- exports.getFieldDefault = getFieldDefault;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFieldDefault = exports.traverseCollectionFieldsAndApplyDefaults = exports.addFieldDefaults = void 0;
4
+ const oids_js_1 = require("../oids.js");
5
+ function addFieldDefaults(collection, value) {
6
+ for (const [key, field] of Object.entries(collection.fields)) {
7
+ const defaultValue = getFieldDefault(field);
8
+ if (defaultValue !== undefined && value[key] === undefined) {
9
+ value[key] = defaultValue;
10
+ }
11
+ if (value[key]) {
12
+ traverseCollectionFieldsAndApplyDefaults(value[key], field);
13
+ }
14
+ }
15
+ return value;
16
+ }
17
+ exports.addFieldDefaults = addFieldDefaults;
18
+ function traverseCollectionFieldsAndApplyDefaults(value, field) {
19
+ if (value === undefined || value === null)
20
+ return value;
21
+ if (field.type === 'object') {
22
+ for (const [key, subField] of Object.entries(field.properties)) {
23
+ if (value[key] === undefined) {
24
+ const defaultValue = getFieldDefault(subField);
25
+ if (defaultValue !== undefined) {
26
+ value[key] = defaultValue;
27
+ }
28
+ }
29
+ traverseCollectionFieldsAndApplyDefaults(value[key], subField);
30
+ }
31
+ }
32
+ else if (field.type === 'array') {
33
+ for (const item of value) {
34
+ traverseCollectionFieldsAndApplyDefaults(item, field.items);
35
+ }
36
+ }
37
+ else if (field.type === 'map') {
38
+ for (const [key, item] of Object.entries(value)) {
39
+ // santiy check to weed out any id field
40
+ if (key === oids_js_1.OID_KEY || key === oids_js_1.LEGACY_OID_KEY)
41
+ continue;
42
+ traverseCollectionFieldsAndApplyDefaults(item, field.values);
43
+ }
44
+ }
45
+ }
46
+ exports.traverseCollectionFieldsAndApplyDefaults = traverseCollectionFieldsAndApplyDefaults;
47
+ function getFieldDefault(field) {
48
+ if (field.type === 'string' ||
49
+ field.type === 'number' ||
50
+ field.type === 'boolean' ||
51
+ field.type === 'any') {
52
+ if (field.default && typeof field.default === 'function') {
53
+ return field.default();
54
+ }
55
+ else if (field.default !== undefined) {
56
+ // TODO: structuredClone?
57
+ return JSON.parse(JSON.stringify(field.default));
58
+ }
59
+ }
60
+ if (field.type === 'array') {
61
+ return [];
62
+ }
63
+ if (field.type === 'map') {
64
+ return {};
65
+ }
66
+ if (field.type !== 'any' && field.nullable) {
67
+ return null;
68
+ }
69
+ return undefined;
70
+ }
71
+ exports.getFieldDefault = getFieldDefault;
72
72
  //# sourceMappingURL=defaults.js.map
@@ -1 +1 @@
1
- export {};
1
+ export {};