@prabhask5/stellar-engine 1.1.18 → 1.2.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 (73) hide show
  1. package/README.md +55 -1
  2. package/dist/bin/install-pwa.js +50 -0
  3. package/dist/bin/install-pwa.js.map +1 -1
  4. package/dist/config.d.ts +11 -0
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +8 -2
  7. package/dist/config.js.map +1 -1
  8. package/dist/crdt/awareness.d.ts +128 -0
  9. package/dist/crdt/awareness.d.ts.map +1 -0
  10. package/dist/crdt/awareness.js +284 -0
  11. package/dist/crdt/awareness.js.map +1 -0
  12. package/dist/crdt/channel.d.ts +165 -0
  13. package/dist/crdt/channel.d.ts.map +1 -0
  14. package/dist/crdt/channel.js +522 -0
  15. package/dist/crdt/channel.js.map +1 -0
  16. package/dist/crdt/config.d.ts +58 -0
  17. package/dist/crdt/config.d.ts.map +1 -0
  18. package/dist/crdt/config.js +123 -0
  19. package/dist/crdt/config.js.map +1 -0
  20. package/dist/crdt/helpers.d.ts +104 -0
  21. package/dist/crdt/helpers.d.ts.map +1 -0
  22. package/dist/crdt/helpers.js +116 -0
  23. package/dist/crdt/helpers.js.map +1 -0
  24. package/dist/crdt/offline.d.ts +58 -0
  25. package/dist/crdt/offline.d.ts.map +1 -0
  26. package/dist/crdt/offline.js +130 -0
  27. package/dist/crdt/offline.js.map +1 -0
  28. package/dist/crdt/persistence.d.ts +65 -0
  29. package/dist/crdt/persistence.d.ts.map +1 -0
  30. package/dist/crdt/persistence.js +171 -0
  31. package/dist/crdt/persistence.js.map +1 -0
  32. package/dist/crdt/provider.d.ts +109 -0
  33. package/dist/crdt/provider.d.ts.map +1 -0
  34. package/dist/crdt/provider.js +543 -0
  35. package/dist/crdt/provider.js.map +1 -0
  36. package/dist/crdt/store.d.ts +111 -0
  37. package/dist/crdt/store.d.ts.map +1 -0
  38. package/dist/crdt/store.js +158 -0
  39. package/dist/crdt/store.js.map +1 -0
  40. package/dist/crdt/types.d.ts +281 -0
  41. package/dist/crdt/types.d.ts.map +1 -0
  42. package/dist/crdt/types.js +26 -0
  43. package/dist/crdt/types.js.map +1 -0
  44. package/dist/database.d.ts +1 -1
  45. package/dist/database.d.ts.map +1 -1
  46. package/dist/database.js +28 -7
  47. package/dist/database.js.map +1 -1
  48. package/dist/diagnostics.d.ts +75 -0
  49. package/dist/diagnostics.d.ts.map +1 -1
  50. package/dist/diagnostics.js +114 -2
  51. package/dist/diagnostics.js.map +1 -1
  52. package/dist/engine.d.ts.map +1 -1
  53. package/dist/engine.js +21 -1
  54. package/dist/engine.js.map +1 -1
  55. package/dist/entries/crdt.d.ts +32 -0
  56. package/dist/entries/crdt.d.ts.map +1 -0
  57. package/dist/entries/crdt.js +52 -0
  58. package/dist/entries/crdt.js.map +1 -0
  59. package/dist/entries/types.d.ts +1 -0
  60. package/dist/entries/types.d.ts.map +1 -1
  61. package/dist/index.d.ts +3 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +7 -0
  64. package/dist/index.js.map +1 -1
  65. package/package.json +7 -2
  66. package/dist/operations.d.ts +0 -73
  67. package/dist/operations.d.ts.map +0 -1
  68. package/dist/operations.js +0 -227
  69. package/dist/operations.js.map +0 -1
  70. package/dist/reconnectHandler.d.ts +0 -16
  71. package/dist/reconnectHandler.d.ts.map +0 -1
  72. package/dist/reconnectHandler.js +0 -21
  73. package/dist/reconnectHandler.js.map +0 -1
@@ -1,227 +0,0 @@
1
- /**
2
- * Sync Operation Helpers
3
- *
4
- * Provides utilities for:
5
- * - Transforming operations to Supabase mutations
6
- * - Creating operation items
7
- * - Operation coalescing logic
8
- */
9
- /**
10
- * Transform a SyncOperationItem into a Supabase mutation payload.
11
- * This is called by the sync engine when pushing to Supabase.
12
- *
13
- * @param operation The operation to transform
14
- * @param currentValue The current value of the field (needed for increment operations)
15
- * @returns The payload to send to Supabase
16
- */
17
- export function operationToMutation(operation, currentValue) {
18
- switch (operation.operationType) {
19
- case 'create':
20
- return {
21
- mutationType: 'insert',
22
- payload: {
23
- id: operation.entityId,
24
- ...operation.value
25
- }
26
- };
27
- case 'delete':
28
- return {
29
- mutationType: 'update',
30
- payload: {
31
- deleted: true,
32
- updated_at: operation.timestamp
33
- }
34
- };
35
- case 'increment': {
36
- // For increment, we need to compute the new value
37
- // currentValue should be provided by the caller from the local entity
38
- const base = typeof currentValue === 'number' ? currentValue : 0;
39
- const delta = typeof operation.value === 'number' ? operation.value : 0;
40
- const newValue = base + delta;
41
- if (!operation.field) {
42
- throw new Error('Increment operation requires a field');
43
- }
44
- return {
45
- mutationType: 'update',
46
- payload: {
47
- [operation.field]: newValue,
48
- updated_at: operation.timestamp
49
- }
50
- };
51
- }
52
- case 'set': {
53
- // For set, we either have a single field or a full payload
54
- if (operation.field) {
55
- // Single field set
56
- return {
57
- mutationType: 'update',
58
- payload: {
59
- [operation.field]: operation.value,
60
- updated_at: operation.timestamp
61
- }
62
- };
63
- }
64
- else {
65
- // Full payload set
66
- return {
67
- mutationType: 'update',
68
- payload: {
69
- ...operation.value,
70
- updated_at: operation.timestamp
71
- }
72
- };
73
- }
74
- }
75
- default:
76
- throw new Error(`Unknown operation type: ${operation.operationType}`);
77
- }
78
- }
79
- /**
80
- * Infer the appropriate operation type based on the value and field name.
81
- *
82
- * @param value The value being set
83
- * @param fieldName The name of the field
84
- * @param isIncrement Whether this is a known increment operation
85
- * @returns The inferred operation type
86
- */
87
- export function inferOperationType(_value, _fieldName, isIncrement) {
88
- if (isIncrement) {
89
- return 'increment';
90
- }
91
- // All non-increment operations are 'set'
92
- return 'set';
93
- }
94
- /**
95
- * Create an increment operation item.
96
- */
97
- export function createIncrementOperation(table, entityId, field, delta, timestamp) {
98
- return {
99
- table,
100
- entityId,
101
- operationType: 'increment',
102
- field,
103
- value: delta,
104
- timestamp,
105
- retries: 0
106
- };
107
- }
108
- /**
109
- * Create a set operation item for a single field.
110
- */
111
- export function createSetOperation(table, entityId, field, value, timestamp) {
112
- return {
113
- table,
114
- entityId,
115
- operationType: 'set',
116
- field,
117
- value,
118
- timestamp,
119
- retries: 0
120
- };
121
- }
122
- /**
123
- * Create a set operation item for multiple fields.
124
- */
125
- export function createMultiFieldSetOperation(table, entityId, fields, timestamp) {
126
- return {
127
- table,
128
- entityId,
129
- operationType: 'set',
130
- value: fields,
131
- timestamp,
132
- retries: 0
133
- };
134
- }
135
- /**
136
- * Create a create operation item.
137
- */
138
- export function createCreateOperation(table, entityId, payload, timestamp) {
139
- return {
140
- table,
141
- entityId,
142
- operationType: 'create',
143
- value: payload,
144
- timestamp,
145
- retries: 0
146
- };
147
- }
148
- /**
149
- * Create a delete operation item.
150
- */
151
- export function createDeleteOperation(table, entityId, timestamp) {
152
- return {
153
- table,
154
- entityId,
155
- operationType: 'delete',
156
- timestamp,
157
- retries: 0
158
- };
159
- }
160
- /**
161
- * Check if two operations can be coalesced together.
162
- *
163
- * Coalescing rules:
164
- * - Same table + entityId + operationType can be coalesced
165
- * - Increment operations: can be coalesced if same field (sums deltas)
166
- * - Set operations: can be coalesced (keeps merged/latest values)
167
- * - Create/delete: cannot coalesce (would lose intent)
168
- */
169
- export function canCoalesce(a, b) {
170
- if (a.table !== b.table || a.entityId !== b.entityId) {
171
- return false;
172
- }
173
- // Same operation type on same field can be coalesced
174
- if (a.operationType === b.operationType) {
175
- // Create and delete cannot coalesce (would lose intent)
176
- if (a.operationType === 'create' || a.operationType === 'delete') {
177
- return false;
178
- }
179
- // For increment operations, must be same field
180
- if (a.operationType === 'increment') {
181
- // Both must have a field specified
182
- if (!a.field || !b.field) {
183
- return false;
184
- }
185
- // Must be the same field
186
- return a.field === b.field;
187
- }
188
- // For set operations with a specific field, must be same field
189
- if (a.field && b.field && a.field !== b.field) {
190
- return false;
191
- }
192
- return true;
193
- }
194
- return false;
195
- }
196
- /**
197
- * Coalesce two operations into one.
198
- *
199
- * Coalescing strategy by operation type:
200
- * - Increment: sum the deltas (e.g., +1 and +1 = +2)
201
- * - Set: keep the newer value (last-write-wins)
202
- *
203
- * @param older The older operation
204
- * @param newer The newer operation
205
- * @returns The coalesced operation
206
- */
207
- export function coalesceOperations(older, newer) {
208
- // For increment operations: sum the deltas
209
- if (older.operationType === 'increment' && newer.operationType === 'increment') {
210
- const olderDelta = typeof older.value === 'number' ? older.value : 0;
211
- const newerDelta = typeof newer.value === 'number' ? newer.value : 0;
212
- const summedDelta = olderDelta + newerDelta;
213
- return {
214
- ...older,
215
- // Keep older's id and timestamp for queue management and backoff
216
- value: summedDelta
217
- };
218
- }
219
- // For set operations: keep the newer value but preserve older's id/timestamp
220
- return {
221
- ...newer,
222
- id: older.id,
223
- // Keep oldest timestamp for backoff calculation
224
- timestamp: older.timestamp
225
- };
226
- }
227
- //# sourceMappingURL=operations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"operations.js","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAA4B,EAC5B,YAAsB;IAEtB,QAAQ,SAAS,CAAC,aAAa,EAAE,CAAC;QAChC,KAAK,QAAQ;YACX,OAAO;gBACL,YAAY,EAAE,QAAQ;gBACtB,OAAO,EAAE;oBACP,EAAE,EAAE,SAAS,CAAC,QAAQ;oBACtB,GAAI,SAAS,CAAC,KAAiC;iBAChD;aACF,CAAC;QAEJ,KAAK,QAAQ;YACX,OAAO;gBACL,YAAY,EAAE,QAAQ;gBACtB,OAAO,EAAE;oBACP,OAAO,EAAE,IAAI;oBACb,UAAU,EAAE,SAAS,CAAC,SAAS;iBAChC;aACF,CAAC;QAEJ,KAAK,WAAW,CAAC,CAAC,CAAC;YACjB,kDAAkD;YAClD,sEAAsE;YACtE,MAAM,IAAI,GAAG,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;YACjE,MAAM,KAAK,GAAG,OAAO,SAAS,CAA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K,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,MAAM,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC;QAE5C,OAAO;YACL,GAAG,KAAK;YACR,iEAAiE;YACjE,KAAK,EAAE,WAAW;SACnB,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,OAAO;QACL,GAAG,KAAK;QACR,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,gDAAgD;QAChD,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC;AACJ,CAAC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Reconnect Handler Registry
3
- * Allows layout components to register callbacks for reconnection events
4
- */
5
- type ReconnectHandler = () => Promise<void>;
6
- /**
7
- * Set the reconnect handler (called from layout.svelte)
8
- */
9
- export declare function setReconnectHandler(handler: ReconnectHandler | null): void;
10
- /**
11
- * Call the reconnect handler if one is registered
12
- * Called from the network store on reconnection
13
- */
14
- export declare function callReconnectHandler(): Promise<void>;
15
- export {};
16
- //# sourceMappingURL=reconnectHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reconnectHandler.d.ts","sourceRoot":"","sources":["../src/reconnectHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,KAAK,gBAAgB,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAI5C;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAE1E;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAI1D"}
@@ -1,21 +0,0 @@
1
- /**
2
- * Reconnect Handler Registry
3
- * Allows layout components to register callbacks for reconnection events
4
- */
5
- let reconnectHandler = null;
6
- /**
7
- * Set the reconnect handler (called from layout.svelte)
8
- */
9
- export function setReconnectHandler(handler) {
10
- reconnectHandler = handler;
11
- }
12
- /**
13
- * Call the reconnect handler if one is registered
14
- * Called from the network store on reconnection
15
- */
16
- export async function callReconnectHandler() {
17
- if (reconnectHandler) {
18
- await reconnectHandler();
19
- }
20
- }
21
- //# sourceMappingURL=reconnectHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reconnectHandler.js","sourceRoot":"","sources":["../src/reconnectHandler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,IAAI,gBAAgB,GAA4B,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgC;IAClE,gBAAgB,GAAG,OAAO,CAAC;AAC7B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,gBAAgB,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC"}