@topgunbuild/core 0.2.1 → 0.4.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.
package/dist/index.js CHANGED
@@ -22,14 +22,51 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AuthMessageSchema: () => AuthMessageSchema,
24
24
  BatchMessageSchema: () => BatchMessageSchema,
25
+ BuiltInProcessors: () => BuiltInProcessors,
26
+ BuiltInResolvers: () => BuiltInResolvers,
25
27
  ClientOpMessageSchema: () => ClientOpMessageSchema,
26
28
  ClientOpSchema: () => ClientOpSchema,
29
+ ConflictResolverDefSchema: () => ConflictResolverDefSchema,
30
+ ConflictResolverSchema: () => ConflictResolverSchema,
31
+ ConsistencyLevel: () => ConsistencyLevel,
32
+ CounterRequestSchema: () => CounterRequestSchema,
33
+ CounterResponseSchema: () => CounterResponseSchema,
34
+ CounterSyncSchema: () => CounterSyncSchema,
35
+ CounterUpdateSchema: () => CounterUpdateSchema,
36
+ DEFAULT_BACKUP_COUNT: () => DEFAULT_BACKUP_COUNT,
37
+ DEFAULT_CIRCUIT_BREAKER_CONFIG: () => DEFAULT_CIRCUIT_BREAKER_CONFIG,
38
+ DEFAULT_CONNECTION_POOL_CONFIG: () => DEFAULT_CONNECTION_POOL_CONFIG,
39
+ DEFAULT_EVENT_JOURNAL_CONFIG: () => DEFAULT_EVENT_JOURNAL_CONFIG,
40
+ DEFAULT_MIGRATION_CONFIG: () => DEFAULT_MIGRATION_CONFIG,
41
+ DEFAULT_PARTITION_ROUTER_CONFIG: () => DEFAULT_PARTITION_ROUTER_CONFIG,
42
+ DEFAULT_PROCESSOR_RATE_LIMITS: () => DEFAULT_PROCESSOR_RATE_LIMITS,
43
+ DEFAULT_REPLICATION_CONFIG: () => DEFAULT_REPLICATION_CONFIG,
44
+ DEFAULT_RESOLVER_RATE_LIMITS: () => DEFAULT_RESOLVER_RATE_LIMITS,
27
45
  DEFAULT_WRITE_CONCERN_TIMEOUT: () => DEFAULT_WRITE_CONCERN_TIMEOUT,
46
+ EntryProcessBatchRequestSchema: () => EntryProcessBatchRequestSchema,
47
+ EntryProcessBatchResponseSchema: () => EntryProcessBatchResponseSchema,
48
+ EntryProcessKeyResultSchema: () => EntryProcessKeyResultSchema,
49
+ EntryProcessRequestSchema: () => EntryProcessRequestSchema,
50
+ EntryProcessResponseSchema: () => EntryProcessResponseSchema,
51
+ EntryProcessorDefSchema: () => EntryProcessorDefSchema,
52
+ EntryProcessorSchema: () => EntryProcessorSchema,
53
+ EventJournalImpl: () => EventJournalImpl,
54
+ FORBIDDEN_PATTERNS: () => FORBIDDEN_PATTERNS,
28
55
  HLC: () => HLC,
56
+ JournalEventDataSchema: () => JournalEventDataSchema,
57
+ JournalEventMessageSchema: () => JournalEventMessageSchema,
58
+ JournalEventTypeSchema: () => JournalEventTypeSchema,
59
+ JournalReadRequestSchema: () => JournalReadRequestSchema,
60
+ JournalReadResponseSchema: () => JournalReadResponseSchema,
61
+ JournalSubscribeRequestSchema: () => JournalSubscribeRequestSchema,
62
+ JournalUnsubscribeRequestSchema: () => JournalUnsubscribeRequestSchema,
29
63
  LWWMap: () => LWWMap,
30
64
  LWWRecordSchema: () => LWWRecordSchema,
65
+ ListResolversRequestSchema: () => ListResolversRequestSchema,
66
+ ListResolversResponseSchema: () => ListResolversResponseSchema,
31
67
  LockReleaseSchema: () => LockReleaseSchema,
32
68
  LockRequestSchema: () => LockRequestSchema,
69
+ MergeRejectedMessageSchema: () => MergeRejectedMessageSchema,
33
70
  MerkleReqBucketMessageSchema: () => MerkleReqBucketMessageSchema,
34
71
  MerkleTree: () => MerkleTree,
35
72
  MessageSchema: () => MessageSchema,
@@ -48,6 +85,11 @@ __export(index_exports, {
48
85
  OpBatchMessageSchema: () => OpBatchMessageSchema,
49
86
  OpRejectedMessageSchema: () => OpRejectedMessageSchema,
50
87
  OpResultSchema: () => OpResultSchema,
88
+ PARTITION_COUNT: () => PARTITION_COUNT,
89
+ PNCounterImpl: () => PNCounterImpl,
90
+ PNCounterStateObjectSchema: () => PNCounterStateObjectSchema,
91
+ PartitionMapRequestSchema: () => PartitionMapRequestSchema,
92
+ PartitionState: () => PartitionState,
51
93
  PingMessageSchema: () => PingMessageSchema,
52
94
  PongMessageSchema: () => PongMessageSchema,
53
95
  PredicateNodeSchema: () => PredicateNodeSchema,
@@ -56,6 +98,10 @@ __export(index_exports, {
56
98
  QuerySchema: () => QuerySchema,
57
99
  QuerySubMessageSchema: () => QuerySubMessageSchema,
58
100
  QueryUnsubMessageSchema: () => QueryUnsubMessageSchema,
101
+ RESOLVER_FORBIDDEN_PATTERNS: () => RESOLVER_FORBIDDEN_PATTERNS,
102
+ RegisterResolverRequestSchema: () => RegisterResolverRequestSchema,
103
+ RegisterResolverResponseSchema: () => RegisterResolverResponseSchema,
104
+ Ringbuffer: () => Ringbuffer,
59
105
  SyncInitMessageSchema: () => SyncInitMessageSchema,
60
106
  SyncRespBucketsMessageSchema: () => SyncRespBucketsMessageSchema,
61
107
  SyncRespLeafMessageSchema: () => SyncRespLeafMessageSchema,
@@ -65,11 +111,15 @@ __export(index_exports, {
65
111
  TopicPubSchema: () => TopicPubSchema,
66
112
  TopicSubSchema: () => TopicSubSchema,
67
113
  TopicUnsubSchema: () => TopicUnsubSchema,
114
+ UnregisterResolverRequestSchema: () => UnregisterResolverRequestSchema,
115
+ UnregisterResolverResponseSchema: () => UnregisterResolverResponseSchema,
68
116
  WRITE_CONCERN_ORDER: () => WRITE_CONCERN_ORDER,
69
117
  WriteConcern: () => WriteConcern,
70
118
  WriteConcernSchema: () => WriteConcernSchema,
71
119
  combineHashes: () => combineHashes,
120
+ compareHLCTimestamps: () => compareHLCTimestamps,
72
121
  compareTimestamps: () => compareTimestamps,
122
+ deepMerge: () => deepMerge,
73
123
  deserialize: () => deserialize,
74
124
  disableNativeHash: () => disableNativeHash,
75
125
  evaluatePredicate: () => evaluatePredicate,
@@ -81,7 +131,9 @@ __export(index_exports, {
81
131
  isWriteConcernAchieved: () => isWriteConcernAchieved,
82
132
  resetNativeHash: () => resetNativeHash,
83
133
  serialize: () => serialize,
84
- timestampToString: () => timestampToString
134
+ timestampToString: () => timestampToString,
135
+ validateProcessorCode: () => validateProcessorCode,
136
+ validateResolverCode: () => validateResolverCode
85
137
  });
86
138
  module.exports = __toCommonJS(index_exports);
87
139
 
@@ -1050,6 +1102,935 @@ function deserialize(data) {
1050
1102
  return (0, import_msgpackr.unpack)(buffer);
1051
1103
  }
1052
1104
 
1105
+ // src/PNCounter.ts
1106
+ var PNCounterImpl = class {
1107
+ constructor(config) {
1108
+ this.listeners = /* @__PURE__ */ new Set();
1109
+ this.nodeId = config.nodeId;
1110
+ this.state = config.initialState ?? {
1111
+ positive: /* @__PURE__ */ new Map(),
1112
+ negative: /* @__PURE__ */ new Map()
1113
+ };
1114
+ }
1115
+ /**
1116
+ * Get the current counter value.
1117
+ * Value = sum(positive) - sum(negative)
1118
+ */
1119
+ get() {
1120
+ let sum = 0;
1121
+ for (const v of this.state.positive.values()) sum += v;
1122
+ for (const v of this.state.negative.values()) sum -= v;
1123
+ return sum;
1124
+ }
1125
+ /**
1126
+ * Increment by 1 and return the new value.
1127
+ */
1128
+ increment() {
1129
+ return this.addAndGet(1);
1130
+ }
1131
+ /**
1132
+ * Decrement by 1 and return the new value.
1133
+ */
1134
+ decrement() {
1135
+ return this.addAndGet(-1);
1136
+ }
1137
+ /**
1138
+ * Add a delta (positive or negative) and return the new value.
1139
+ * @param delta The amount to add (can be negative)
1140
+ */
1141
+ addAndGet(delta) {
1142
+ if (delta === 0) return this.get();
1143
+ if (delta > 0) {
1144
+ const current = this.state.positive.get(this.nodeId) ?? 0;
1145
+ this.state.positive.set(this.nodeId, current + delta);
1146
+ } else {
1147
+ const current = this.state.negative.get(this.nodeId) ?? 0;
1148
+ this.state.negative.set(this.nodeId, current + Math.abs(delta));
1149
+ }
1150
+ const newValue = this.get();
1151
+ this.notifyListeners(newValue);
1152
+ return newValue;
1153
+ }
1154
+ /**
1155
+ * Get a copy of the current state for synchronization.
1156
+ */
1157
+ getState() {
1158
+ return {
1159
+ positive: new Map(this.state.positive),
1160
+ negative: new Map(this.state.negative)
1161
+ };
1162
+ }
1163
+ /**
1164
+ * Merge remote state into this counter.
1165
+ * Takes the maximum value for each node in both positive and negative counters.
1166
+ * This operation is commutative, associative, and idempotent (CRDT properties).
1167
+ *
1168
+ * @param remote The remote state to merge
1169
+ */
1170
+ merge(remote) {
1171
+ let changed = false;
1172
+ for (const [nodeId, value] of remote.positive) {
1173
+ const current = this.state.positive.get(nodeId) ?? 0;
1174
+ if (value > current) {
1175
+ this.state.positive.set(nodeId, value);
1176
+ changed = true;
1177
+ }
1178
+ }
1179
+ for (const [nodeId, value] of remote.negative) {
1180
+ const current = this.state.negative.get(nodeId) ?? 0;
1181
+ if (value > current) {
1182
+ this.state.negative.set(nodeId, value);
1183
+ changed = true;
1184
+ }
1185
+ }
1186
+ if (changed) {
1187
+ this.notifyListeners(this.get());
1188
+ }
1189
+ }
1190
+ /**
1191
+ * Subscribe to value changes.
1192
+ * The listener is immediately called with the current value.
1193
+ *
1194
+ * @param listener Callback function receiving the new value
1195
+ * @returns Unsubscribe function
1196
+ */
1197
+ subscribe(listener) {
1198
+ this.listeners.add(listener);
1199
+ listener(this.get());
1200
+ return () => this.listeners.delete(listener);
1201
+ }
1202
+ notifyListeners(value) {
1203
+ for (const listener of this.listeners) {
1204
+ try {
1205
+ listener(value);
1206
+ } catch (e) {
1207
+ }
1208
+ }
1209
+ }
1210
+ /**
1211
+ * Get the node ID of this counter instance.
1212
+ */
1213
+ getNodeId() {
1214
+ return this.nodeId;
1215
+ }
1216
+ // ============================================
1217
+ // Serialization
1218
+ // ============================================
1219
+ /**
1220
+ * Serialize state to binary format (msgpack).
1221
+ */
1222
+ static serialize(state) {
1223
+ const obj = {
1224
+ p: Object.fromEntries(state.positive),
1225
+ n: Object.fromEntries(state.negative)
1226
+ };
1227
+ return serialize(obj);
1228
+ }
1229
+ /**
1230
+ * Deserialize binary data to state.
1231
+ */
1232
+ static deserialize(data) {
1233
+ const obj = deserialize(data);
1234
+ return {
1235
+ positive: new Map(Object.entries(obj.p)),
1236
+ negative: new Map(Object.entries(obj.n))
1237
+ };
1238
+ }
1239
+ /**
1240
+ * Convert state to plain object (for JSON/network).
1241
+ */
1242
+ static stateToObject(state) {
1243
+ return {
1244
+ p: Object.fromEntries(state.positive),
1245
+ n: Object.fromEntries(state.negative)
1246
+ };
1247
+ }
1248
+ /**
1249
+ * Convert plain object to state.
1250
+ */
1251
+ static objectToState(obj) {
1252
+ return {
1253
+ positive: new Map(Object.entries(obj.p)),
1254
+ negative: new Map(Object.entries(obj.n))
1255
+ };
1256
+ }
1257
+ };
1258
+
1259
+ // src/Ringbuffer.ts
1260
+ var Ringbuffer = class {
1261
+ // Next sequence to write
1262
+ constructor(capacity) {
1263
+ this.headSequence = 0n;
1264
+ // Oldest available sequence
1265
+ this.tailSequence = 0n;
1266
+ if (capacity < 1) {
1267
+ throw new Error("Capacity must be >= 1");
1268
+ }
1269
+ this._capacity = capacity;
1270
+ this.buffer = new Array(capacity);
1271
+ }
1272
+ /**
1273
+ * Add item to buffer, returns sequence number.
1274
+ */
1275
+ add(item) {
1276
+ const sequence = this.tailSequence;
1277
+ const index = Number(sequence % BigInt(this._capacity));
1278
+ this.buffer[index] = item;
1279
+ this.tailSequence++;
1280
+ if (this.tailSequence - this.headSequence > this._capacity) {
1281
+ this.headSequence = this.tailSequence - BigInt(this._capacity);
1282
+ }
1283
+ return sequence;
1284
+ }
1285
+ /**
1286
+ * Read item at sequence.
1287
+ * Returns undefined if sequence is out of range.
1288
+ */
1289
+ read(sequence) {
1290
+ if (sequence < this.headSequence || sequence >= this.tailSequence) {
1291
+ return void 0;
1292
+ }
1293
+ const index = Number(sequence % BigInt(this._capacity));
1294
+ return this.buffer[index];
1295
+ }
1296
+ /**
1297
+ * Read range of items (inclusive).
1298
+ * Automatically clamps to available range.
1299
+ */
1300
+ readRange(startSeq, endSeq) {
1301
+ const items = [];
1302
+ const actualStart = startSeq < this.headSequence ? this.headSequence : startSeq;
1303
+ const actualEnd = endSeq >= this.tailSequence ? this.tailSequence - 1n : endSeq;
1304
+ for (let seq = actualStart; seq <= actualEnd; seq++) {
1305
+ const item = this.read(seq);
1306
+ if (item !== void 0) {
1307
+ items.push(item);
1308
+ }
1309
+ }
1310
+ return items;
1311
+ }
1312
+ /**
1313
+ * Read from sequence with limit.
1314
+ */
1315
+ readFrom(startSeq, limit = 100) {
1316
+ const endSeq = startSeq + BigInt(limit) - 1n;
1317
+ return this.readRange(startSeq, endSeq);
1318
+ }
1319
+ /**
1320
+ * Get the oldest available sequence number.
1321
+ */
1322
+ getHeadSequence() {
1323
+ return this.headSequence;
1324
+ }
1325
+ /**
1326
+ * Get the next sequence number to be written.
1327
+ */
1328
+ getTailSequence() {
1329
+ return this.tailSequence;
1330
+ }
1331
+ /**
1332
+ * Get the number of items currently in the buffer.
1333
+ */
1334
+ size() {
1335
+ return Number(this.tailSequence - this.headSequence);
1336
+ }
1337
+ /**
1338
+ * Get the maximum capacity of the buffer.
1339
+ */
1340
+ getCapacity() {
1341
+ return this._capacity;
1342
+ }
1343
+ /**
1344
+ * Clear all items from the buffer.
1345
+ */
1346
+ clear() {
1347
+ this.buffer = new Array(this._capacity);
1348
+ this.headSequence = 0n;
1349
+ this.tailSequence = 0n;
1350
+ }
1351
+ /**
1352
+ * Check if a sequence is available in the buffer.
1353
+ */
1354
+ isAvailable(sequence) {
1355
+ return sequence >= this.headSequence && sequence < this.tailSequence;
1356
+ }
1357
+ /**
1358
+ * Get remaining capacity before oldest entries are overwritten.
1359
+ */
1360
+ remainingCapacity() {
1361
+ return this._capacity - this.size();
1362
+ }
1363
+ };
1364
+
1365
+ // src/EventJournal.ts
1366
+ var DEFAULT_EVENT_JOURNAL_CONFIG = {
1367
+ capacity: 1e4,
1368
+ ttlMs: 0,
1369
+ // Infinite
1370
+ persistent: true,
1371
+ includeMaps: [],
1372
+ excludeMaps: []
1373
+ };
1374
+ var EventJournalImpl = class {
1375
+ constructor(config = {}) {
1376
+ this.listeners = /* @__PURE__ */ new Set();
1377
+ this.config = { ...DEFAULT_EVENT_JOURNAL_CONFIG, ...config };
1378
+ this.buffer = new Ringbuffer(this.config.capacity);
1379
+ if (this.config.ttlMs > 0) {
1380
+ this.startTTLCleanup();
1381
+ }
1382
+ }
1383
+ /**
1384
+ * Append event to journal.
1385
+ * Returns the event with assigned sequence number.
1386
+ * Returns event with sequence -1n if map is filtered out.
1387
+ */
1388
+ append(eventData) {
1389
+ if (!this.shouldCapture(eventData.mapName)) {
1390
+ return { ...eventData, sequence: -1n };
1391
+ }
1392
+ const event = {
1393
+ ...eventData,
1394
+ sequence: 0n
1395
+ // Will be set by buffer
1396
+ };
1397
+ const sequence = this.buffer.add(event);
1398
+ event.sequence = sequence;
1399
+ for (const listener of this.listeners) {
1400
+ try {
1401
+ listener(event);
1402
+ } catch (e) {
1403
+ console.error("EventJournal listener error:", e);
1404
+ }
1405
+ }
1406
+ return event;
1407
+ }
1408
+ /**
1409
+ * Read events from sequence with optional limit.
1410
+ */
1411
+ readFrom(sequence, limit = 100) {
1412
+ return this.buffer.readFrom(sequence, limit);
1413
+ }
1414
+ /**
1415
+ * Read events in range (inclusive).
1416
+ */
1417
+ readRange(startSeq, endSeq) {
1418
+ return this.buffer.readRange(startSeq, endSeq);
1419
+ }
1420
+ /**
1421
+ * Get latest sequence number.
1422
+ * Returns 0n if no events have been added.
1423
+ */
1424
+ getLatestSequence() {
1425
+ const tail = this.buffer.getTailSequence();
1426
+ return tail > 0n ? tail - 1n : 0n;
1427
+ }
1428
+ /**
1429
+ * Get oldest available sequence number.
1430
+ */
1431
+ getOldestSequence() {
1432
+ return this.buffer.getHeadSequence();
1433
+ }
1434
+ /**
1435
+ * Subscribe to new events.
1436
+ * Optionally replay events from a specific sequence.
1437
+ *
1438
+ * @param listener Callback for each event
1439
+ * @param fromSequence Optional sequence to start replay from
1440
+ * @returns Unsubscribe function
1441
+ */
1442
+ subscribe(listener, fromSequence) {
1443
+ if (fromSequence !== void 0) {
1444
+ const events = this.readFrom(fromSequence, this.config.capacity);
1445
+ for (const event of events) {
1446
+ try {
1447
+ listener(event);
1448
+ } catch (e) {
1449
+ console.error("EventJournal replay error:", e);
1450
+ }
1451
+ }
1452
+ }
1453
+ this.listeners.add(listener);
1454
+ return () => this.listeners.delete(listener);
1455
+ }
1456
+ /**
1457
+ * Get capacity information.
1458
+ */
1459
+ getCapacity() {
1460
+ return {
1461
+ used: this.buffer.size(),
1462
+ total: this.buffer.getCapacity()
1463
+ };
1464
+ }
1465
+ /**
1466
+ * Force compaction.
1467
+ * Note: The ringbuffer handles eviction automatically.
1468
+ * This method is provided for explicit cleanup of old events.
1469
+ */
1470
+ async compact() {
1471
+ }
1472
+ /**
1473
+ * Check if a map should be captured.
1474
+ */
1475
+ shouldCapture(mapName) {
1476
+ const { includeMaps, excludeMaps } = this.config;
1477
+ if (excludeMaps && excludeMaps.includes(mapName)) {
1478
+ return false;
1479
+ }
1480
+ if (includeMaps && includeMaps.length > 0) {
1481
+ return includeMaps.includes(mapName);
1482
+ }
1483
+ return true;
1484
+ }
1485
+ /**
1486
+ * Start TTL cleanup timer.
1487
+ */
1488
+ startTTLCleanup() {
1489
+ const interval = Math.min(this.config.ttlMs, 6e4);
1490
+ this.ttlTimer = setInterval(() => {
1491
+ this.compact();
1492
+ }, interval);
1493
+ }
1494
+ /**
1495
+ * Dispose resources.
1496
+ */
1497
+ dispose() {
1498
+ if (this.ttlTimer) {
1499
+ clearInterval(this.ttlTimer);
1500
+ this.ttlTimer = void 0;
1501
+ }
1502
+ this.listeners.clear();
1503
+ }
1504
+ /**
1505
+ * Get all current listeners count (for testing).
1506
+ */
1507
+ getListenerCount() {
1508
+ return this.listeners.size;
1509
+ }
1510
+ /**
1511
+ * Get configuration (for testing).
1512
+ */
1513
+ getConfig() {
1514
+ return { ...this.config };
1515
+ }
1516
+ };
1517
+
1518
+ // src/EntryProcessor.ts
1519
+ var import_zod = require("zod");
1520
+ var EntryProcessorDefSchema = import_zod.z.object({
1521
+ name: import_zod.z.string().min(1).max(100),
1522
+ code: import_zod.z.string().min(1).max(1e4),
1523
+ // Max 10KB code
1524
+ args: import_zod.z.unknown().optional()
1525
+ });
1526
+ var FORBIDDEN_PATTERNS = [
1527
+ /\beval\b/,
1528
+ /\bFunction\b/,
1529
+ /\bprocess\b/,
1530
+ /\bglobal\b/,
1531
+ /\brequire\b/,
1532
+ /\bimport\b/,
1533
+ /\bfetch\b/,
1534
+ /\bXMLHttpRequest\b/,
1535
+ /\bsetTimeout\b/,
1536
+ /\bsetInterval\b/,
1537
+ /\bsetImmediate\b/
1538
+ ];
1539
+ function validateProcessorCode(code) {
1540
+ for (const pattern of FORBIDDEN_PATTERNS) {
1541
+ if (pattern.test(code)) {
1542
+ return {
1543
+ valid: false,
1544
+ error: `Forbidden pattern detected: ${pattern.source}`
1545
+ };
1546
+ }
1547
+ }
1548
+ return { valid: true };
1549
+ }
1550
+ var BuiltInProcessors = {
1551
+ /**
1552
+ * Increment numeric value by delta.
1553
+ * If value doesn't exist, starts from 0.
1554
+ */
1555
+ INCREMENT: (delta = 1) => ({
1556
+ name: "builtin:increment",
1557
+ code: `
1558
+ const current = value ?? 0;
1559
+ const newValue = current + args;
1560
+ return { value: newValue, result: newValue };
1561
+ `,
1562
+ args: delta
1563
+ }),
1564
+ /**
1565
+ * Decrement numeric value by delta.
1566
+ * If value doesn't exist, starts from 0.
1567
+ */
1568
+ DECREMENT: (delta = 1) => ({
1569
+ name: "builtin:decrement",
1570
+ code: `
1571
+ const current = value ?? 0;
1572
+ const newValue = current - args;
1573
+ return { value: newValue, result: newValue };
1574
+ `,
1575
+ args: delta
1576
+ }),
1577
+ /**
1578
+ * Decrement with floor (won't go below 0).
1579
+ * Returns both the new value and whether it was floored.
1580
+ */
1581
+ DECREMENT_FLOOR: (delta = 1) => ({
1582
+ name: "builtin:decrement_floor",
1583
+ code: `
1584
+ const current = value ?? 0;
1585
+ const target = current - args;
1586
+ const newValue = Math.max(0, target);
1587
+ return {
1588
+ value: newValue,
1589
+ result: { newValue, wasFloored: target < 0 }
1590
+ };
1591
+ `,
1592
+ args: delta
1593
+ }),
1594
+ /**
1595
+ * Multiply numeric value by factor.
1596
+ * If value doesn't exist, starts from 1.
1597
+ */
1598
+ MULTIPLY: (factor) => ({
1599
+ name: "builtin:multiply",
1600
+ code: `
1601
+ const current = value ?? 1;
1602
+ const newValue = current * args;
1603
+ return { value: newValue, result: newValue };
1604
+ `,
1605
+ args: factor
1606
+ }),
1607
+ /**
1608
+ * Set value only if key doesn't exist.
1609
+ * Returns true if value was set, false if key already existed.
1610
+ */
1611
+ PUT_IF_ABSENT: (newValue) => ({
1612
+ name: "builtin:put_if_absent",
1613
+ code: `
1614
+ if (value !== undefined) {
1615
+ return { value, result: false };
1616
+ }
1617
+ return { value: args, result: true };
1618
+ `,
1619
+ args: newValue
1620
+ }),
1621
+ /**
1622
+ * Replace value only if key exists.
1623
+ * Returns the old value if replaced, undefined otherwise.
1624
+ */
1625
+ REPLACE: (newValue) => ({
1626
+ name: "builtin:replace",
1627
+ code: `
1628
+ if (value === undefined) {
1629
+ return { value: undefined, result: undefined };
1630
+ }
1631
+ return { value: args, result: value };
1632
+ `,
1633
+ args: newValue
1634
+ }),
1635
+ /**
1636
+ * Replace value only if it matches expected value.
1637
+ * Returns true if replaced, false otherwise.
1638
+ */
1639
+ REPLACE_IF_EQUALS: (expectedValue, newValue) => ({
1640
+ name: "builtin:replace_if_equals",
1641
+ code: `
1642
+ if (JSON.stringify(value) === JSON.stringify(args.expected)) {
1643
+ return { value: args.newValue, result: true };
1644
+ }
1645
+ return { value, result: false };
1646
+ `,
1647
+ args: { expected: expectedValue, newValue }
1648
+ }),
1649
+ /**
1650
+ * Delete entry only if value matches.
1651
+ * Returns true if deleted, false otherwise.
1652
+ */
1653
+ DELETE_IF_EQUALS: (expectedValue) => ({
1654
+ name: "builtin:delete_if_equals",
1655
+ code: `
1656
+ if (JSON.stringify(value) === JSON.stringify(args)) {
1657
+ return { value: undefined, result: true };
1658
+ }
1659
+ return { value, result: false };
1660
+ `,
1661
+ args: expectedValue
1662
+ }),
1663
+ /**
1664
+ * Append item to array.
1665
+ * Creates array if it doesn't exist.
1666
+ * Returns new array length.
1667
+ */
1668
+ ARRAY_PUSH: (item) => ({
1669
+ name: "builtin:array_push",
1670
+ code: `
1671
+ const arr = value ?? [];
1672
+ arr.push(args);
1673
+ return { value: arr, result: arr.length };
1674
+ `,
1675
+ args: item
1676
+ }),
1677
+ /**
1678
+ * Remove last item from array.
1679
+ * Returns the removed item or undefined.
1680
+ */
1681
+ ARRAY_POP: () => ({
1682
+ name: "builtin:array_pop",
1683
+ code: `
1684
+ if (!value || value.length === 0) {
1685
+ return { value: value ?? [], result: undefined };
1686
+ }
1687
+ const removed = value.pop();
1688
+ return { value, result: removed };
1689
+ `
1690
+ }),
1691
+ /**
1692
+ * Remove item from array by value (first occurrence).
1693
+ * Returns true if item was found and removed.
1694
+ */
1695
+ ARRAY_REMOVE: (item) => ({
1696
+ name: "builtin:array_remove",
1697
+ code: `
1698
+ if (!value) {
1699
+ return { value: [], result: false };
1700
+ }
1701
+ const idx = value.findIndex(v => JSON.stringify(v) === JSON.stringify(args));
1702
+ if (idx === -1) {
1703
+ return { value, result: false };
1704
+ }
1705
+ value.splice(idx, 1);
1706
+ return { value, result: true };
1707
+ `,
1708
+ args: item
1709
+ }),
1710
+ /**
1711
+ * Update nested property using dot notation path.
1712
+ * Creates intermediate objects if they don't exist.
1713
+ */
1714
+ SET_PROPERTY: (path, propValue) => ({
1715
+ name: "builtin:set_property",
1716
+ code: `
1717
+ const obj = value ?? {};
1718
+ const parts = args.path.split('.');
1719
+ let current = obj;
1720
+ for (let i = 0; i < parts.length - 1; i++) {
1721
+ current[parts[i]] = current[parts[i]] ?? {};
1722
+ current = current[parts[i]];
1723
+ }
1724
+ current[parts[parts.length - 1]] = args.value;
1725
+ return { value: obj, result: obj };
1726
+ `,
1727
+ args: { path, value: propValue }
1728
+ }),
1729
+ /**
1730
+ * Delete nested property using dot notation path.
1731
+ * Returns the deleted value or undefined.
1732
+ */
1733
+ DELETE_PROPERTY: (path) => ({
1734
+ name: "builtin:delete_property",
1735
+ code: `
1736
+ if (!value) {
1737
+ return { value, result: undefined };
1738
+ }
1739
+ const parts = args.split('.');
1740
+ let current = value;
1741
+ for (let i = 0; i < parts.length - 1; i++) {
1742
+ if (!current[parts[i]]) {
1743
+ return { value, result: undefined };
1744
+ }
1745
+ current = current[parts[i]];
1746
+ }
1747
+ const lastKey = parts[parts.length - 1];
1748
+ const deleted = current[lastKey];
1749
+ delete current[lastKey];
1750
+ return { value, result: deleted };
1751
+ `,
1752
+ args: path
1753
+ }),
1754
+ /**
1755
+ * Get current value without modifying it.
1756
+ * Useful for conditional reads.
1757
+ */
1758
+ GET: () => ({
1759
+ name: "builtin:get",
1760
+ code: `
1761
+ return { value, result: value };
1762
+ `
1763
+ }),
1764
+ /**
1765
+ * Conditional update based on version/timestamp.
1766
+ * Only updates if current version matches expected.
1767
+ * Useful for optimistic locking.
1768
+ */
1769
+ CONDITIONAL_UPDATE: (expectedVersion, newData) => ({
1770
+ name: "builtin:conditional_update",
1771
+ code: `
1772
+ if (!value || value.version !== args.expectedVersion) {
1773
+ return {
1774
+ value,
1775
+ result: { updated: false, conflict: true }
1776
+ };
1777
+ }
1778
+ const updated = {
1779
+ ...value,
1780
+ ...args.newData,
1781
+ version: (value.version ?? 0) + 1,
1782
+ };
1783
+ return {
1784
+ value: updated,
1785
+ result: { updated: true, conflict: false }
1786
+ };
1787
+ `,
1788
+ args: { expectedVersion, newData }
1789
+ }),
1790
+ /**
1791
+ * Merge object properties into existing value.
1792
+ * Shallow merge only.
1793
+ */
1794
+ MERGE: (properties) => ({
1795
+ name: "builtin:merge",
1796
+ code: `
1797
+ const merged = { ...(value ?? {}), ...args };
1798
+ return { value: merged, result: merged };
1799
+ `,
1800
+ args: properties
1801
+ })
1802
+ };
1803
+ var DEFAULT_PROCESSOR_RATE_LIMITS = {
1804
+ maxExecutionsPerSecond: 100,
1805
+ maxCodeSizeBytes: 10240,
1806
+ // 10KB
1807
+ maxArgsSizeBytes: 1048576
1808
+ // 1MB
1809
+ };
1810
+
1811
+ // src/ConflictResolver.ts
1812
+ var import_zod2 = require("zod");
1813
+ var ConflictResolverDefSchema = import_zod2.z.object({
1814
+ name: import_zod2.z.string().min(1).max(100),
1815
+ code: import_zod2.z.string().max(5e4).optional(),
1816
+ priority: import_zod2.z.number().int().min(0).max(100).default(50),
1817
+ keyPattern: import_zod2.z.string().optional()
1818
+ });
1819
+ var RESOLVER_FORBIDDEN_PATTERNS = [
1820
+ /\beval\b/,
1821
+ /\bFunction\b/,
1822
+ /\bprocess\b/,
1823
+ /\bglobal\b/,
1824
+ /\brequire\b/,
1825
+ /\bimport\b/,
1826
+ /\bfetch\b/,
1827
+ /\bXMLHttpRequest\b/,
1828
+ /\bsetTimeout\b/,
1829
+ /\bsetInterval\b/,
1830
+ /\bsetImmediate\b/
1831
+ ];
1832
+ function validateResolverCode(code) {
1833
+ for (const pattern of RESOLVER_FORBIDDEN_PATTERNS) {
1834
+ if (pattern.test(code)) {
1835
+ return {
1836
+ valid: false,
1837
+ error: `Forbidden pattern detected: ${pattern.source}`
1838
+ };
1839
+ }
1840
+ }
1841
+ return { valid: true };
1842
+ }
1843
+ var DEFAULT_RESOLVER_RATE_LIMITS = {
1844
+ maxResolversPerClient: 50,
1845
+ maxCodeSizeBytes: 5e4
1846
+ // 50KB
1847
+ };
1848
+ function compareHLCTimestamps(a, b) {
1849
+ return HLC.compare(a, b);
1850
+ }
1851
+ function deepMerge(target, source) {
1852
+ const result = { ...target };
1853
+ for (const key of Object.keys(source)) {
1854
+ const sourceVal = source[key];
1855
+ const targetVal = target[key];
1856
+ if (typeof sourceVal === "object" && sourceVal !== null && typeof targetVal === "object" && targetVal !== null && !Array.isArray(sourceVal)) {
1857
+ result[key] = deepMerge(
1858
+ targetVal,
1859
+ sourceVal
1860
+ );
1861
+ } else {
1862
+ result[key] = sourceVal;
1863
+ }
1864
+ }
1865
+ return result;
1866
+ }
1867
+ var BuiltInResolvers = {
1868
+ /**
1869
+ * Standard Last-Write-Wins - accept if remote timestamp is newer.
1870
+ */
1871
+ LWW: () => ({
1872
+ name: "builtin:lww",
1873
+ fn: (ctx) => {
1874
+ if (!ctx.localTimestamp) {
1875
+ return { action: "accept", value: ctx.remoteValue };
1876
+ }
1877
+ const cmp = compareHLCTimestamps(ctx.remoteTimestamp, ctx.localTimestamp);
1878
+ if (cmp > 0) {
1879
+ return { action: "accept", value: ctx.remoteValue };
1880
+ }
1881
+ return { action: "local" };
1882
+ },
1883
+ priority: 0
1884
+ // Lowest priority - fallback
1885
+ }),
1886
+ /**
1887
+ * First-Write-Wins - reject if local value exists.
1888
+ * Useful for booking systems, unique constraints.
1889
+ */
1890
+ FIRST_WRITE_WINS: () => ({
1891
+ name: "builtin:first_write_wins",
1892
+ fn: (ctx) => {
1893
+ if (ctx.localValue !== void 0) {
1894
+ return { action: "reject", reason: "Entry already exists" };
1895
+ }
1896
+ return { action: "accept", value: ctx.remoteValue };
1897
+ },
1898
+ priority: 100
1899
+ }),
1900
+ /**
1901
+ * Numeric minimum - keep lowest value.
1902
+ * Useful for auction systems (lowest bid wins).
1903
+ */
1904
+ NUMERIC_MIN: () => ({
1905
+ name: "builtin:numeric_min",
1906
+ fn: (ctx) => {
1907
+ const local = ctx.localValue ?? Infinity;
1908
+ const remote = ctx.remoteValue;
1909
+ return { action: "merge", value: Math.min(local, remote) };
1910
+ },
1911
+ priority: 50
1912
+ }),
1913
+ /**
1914
+ * Numeric maximum - keep highest value.
1915
+ * Useful for high score tracking.
1916
+ */
1917
+ NUMERIC_MAX: () => ({
1918
+ name: "builtin:numeric_max",
1919
+ fn: (ctx) => {
1920
+ const local = ctx.localValue ?? -Infinity;
1921
+ const remote = ctx.remoteValue;
1922
+ return { action: "merge", value: Math.max(local, remote) };
1923
+ },
1924
+ priority: 50
1925
+ }),
1926
+ /**
1927
+ * Non-negative - reject if value would be negative.
1928
+ * Useful for inventory systems.
1929
+ */
1930
+ NON_NEGATIVE: () => ({
1931
+ name: "builtin:non_negative",
1932
+ fn: (ctx) => {
1933
+ if (typeof ctx.remoteValue !== "number" || ctx.remoteValue < 0) {
1934
+ return { action: "reject", reason: "Value cannot be negative" };
1935
+ }
1936
+ return { action: "accept", value: ctx.remoteValue };
1937
+ },
1938
+ priority: 90
1939
+ }),
1940
+ /**
1941
+ * Array union - merge arrays by taking union of elements.
1942
+ * Useful for tags, categories.
1943
+ */
1944
+ ARRAY_UNION: () => ({
1945
+ name: "builtin:array_union",
1946
+ fn: (ctx) => {
1947
+ const local = ctx.localValue ?? [];
1948
+ const remote = ctx.remoteValue ?? [];
1949
+ const merged = [.../* @__PURE__ */ new Set([...local, ...remote])];
1950
+ return { action: "merge", value: merged };
1951
+ },
1952
+ priority: 50
1953
+ }),
1954
+ /**
1955
+ * Deep merge - recursively merge objects.
1956
+ * Remote values take precedence at leaf level.
1957
+ */
1958
+ DEEP_MERGE: () => ({
1959
+ name: "builtin:deep_merge",
1960
+ fn: (ctx) => {
1961
+ const local = ctx.localValue ?? {};
1962
+ const remote = ctx.remoteValue;
1963
+ const merged = deepMerge(local, remote);
1964
+ return { action: "merge", value: merged };
1965
+ },
1966
+ priority: 50
1967
+ }),
1968
+ /**
1969
+ * Server-only - reject all client writes.
1970
+ * Useful for server-controlled state.
1971
+ */
1972
+ SERVER_ONLY: () => ({
1973
+ name: "builtin:server_only",
1974
+ fn: (ctx) => {
1975
+ if (ctx.auth?.roles?.includes("server") || ctx.remoteNodeId.startsWith("server:")) {
1976
+ return { action: "accept", value: ctx.remoteValue };
1977
+ }
1978
+ return { action: "reject", reason: "Only server can write to this entry" };
1979
+ },
1980
+ priority: 100
1981
+ }),
1982
+ /**
1983
+ * Owner-only - only the original creator can modify.
1984
+ * Requires value to have an `ownerId` property.
1985
+ */
1986
+ OWNER_ONLY: () => ({
1987
+ name: "builtin:owner_only",
1988
+ fn: (ctx) => {
1989
+ if (!ctx.localValue) {
1990
+ return { action: "accept", value: ctx.remoteValue };
1991
+ }
1992
+ const ownerId = ctx.localValue.ownerId;
1993
+ if (ownerId && ctx.auth?.userId !== ownerId) {
1994
+ return { action: "reject", reason: "Only owner can modify this entry" };
1995
+ }
1996
+ return { action: "accept", value: ctx.remoteValue };
1997
+ },
1998
+ priority: 95
1999
+ }),
2000
+ /**
2001
+ * Immutable - reject any modifications after initial write.
2002
+ */
2003
+ IMMUTABLE: () => ({
2004
+ name: "builtin:immutable",
2005
+ fn: (ctx) => {
2006
+ if (ctx.localValue !== void 0) {
2007
+ return { action: "reject", reason: "Entry is immutable" };
2008
+ }
2009
+ return { action: "accept", value: ctx.remoteValue };
2010
+ },
2011
+ priority: 100
2012
+ }),
2013
+ /**
2014
+ * Version check - only accept if version increments by 1.
2015
+ * Useful for optimistic locking.
2016
+ */
2017
+ VERSION_INCREMENT: () => ({
2018
+ name: "builtin:version_increment",
2019
+ fn: (ctx) => {
2020
+ const localVersion = ctx.localValue?.version ?? 0;
2021
+ const remoteVersion = ctx.remoteValue?.version ?? 0;
2022
+ if (remoteVersion !== localVersion + 1) {
2023
+ return {
2024
+ action: "reject",
2025
+ reason: `Version conflict: expected ${localVersion + 1}, got ${remoteVersion}`
2026
+ };
2027
+ }
2028
+ return { action: "accept", value: ctx.remoteValue };
2029
+ },
2030
+ priority: 90
2031
+ })
2032
+ };
2033
+
1053
2034
  // src/predicate.ts
1054
2035
  var Predicates = class {
1055
2036
  static equal(attribute, value) {
@@ -1137,31 +2118,31 @@ function evaluatePredicate(predicate, data) {
1137
2118
  }
1138
2119
 
1139
2120
  // src/schemas.ts
1140
- var import_zod = require("zod");
1141
- var WriteConcernSchema = import_zod.z.enum([
2121
+ var import_zod3 = require("zod");
2122
+ var WriteConcernSchema = import_zod3.z.enum([
1142
2123
  "FIRE_AND_FORGET",
1143
2124
  "MEMORY",
1144
2125
  "APPLIED",
1145
2126
  "REPLICATED",
1146
2127
  "PERSISTED"
1147
2128
  ]);
1148
- var TimestampSchema = import_zod.z.object({
1149
- millis: import_zod.z.number(),
1150
- counter: import_zod.z.number(),
1151
- nodeId: import_zod.z.string()
2129
+ var TimestampSchema = import_zod3.z.object({
2130
+ millis: import_zod3.z.union([import_zod3.z.number(), import_zod3.z.bigint()]).transform(Number),
2131
+ counter: import_zod3.z.union([import_zod3.z.number(), import_zod3.z.bigint()]).transform(Number),
2132
+ nodeId: import_zod3.z.string()
1152
2133
  });
1153
- var LWWRecordSchema = import_zod.z.object({
1154
- value: import_zod.z.any().nullable(),
2134
+ var LWWRecordSchema = import_zod3.z.object({
2135
+ value: import_zod3.z.any().nullable(),
1155
2136
  timestamp: TimestampSchema,
1156
- ttlMs: import_zod.z.number().optional()
2137
+ ttlMs: import_zod3.z.number().optional()
1157
2138
  });
1158
- var ORMapRecordSchema = import_zod.z.object({
1159
- value: import_zod.z.any(),
2139
+ var ORMapRecordSchema = import_zod3.z.object({
2140
+ value: import_zod3.z.any(),
1160
2141
  timestamp: TimestampSchema,
1161
- tag: import_zod.z.string(),
1162
- ttlMs: import_zod.z.number().optional()
2142
+ tag: import_zod3.z.string(),
2143
+ ttlMs: import_zod3.z.number().optional()
1163
2144
  });
1164
- var PredicateOpSchema = import_zod.z.enum([
2145
+ var PredicateOpSchema = import_zod3.z.enum([
1165
2146
  "eq",
1166
2147
  "neq",
1167
2148
  "gt",
@@ -1174,266 +2155,438 @@ var PredicateOpSchema = import_zod.z.enum([
1174
2155
  "or",
1175
2156
  "not"
1176
2157
  ]);
1177
- var PredicateNodeSchema = import_zod.z.lazy(() => import_zod.z.object({
2158
+ var PredicateNodeSchema = import_zod3.z.lazy(() => import_zod3.z.object({
1178
2159
  op: PredicateOpSchema,
1179
- attribute: import_zod.z.string().optional(),
1180
- value: import_zod.z.any().optional(),
1181
- children: import_zod.z.array(PredicateNodeSchema).optional()
2160
+ attribute: import_zod3.z.string().optional(),
2161
+ value: import_zod3.z.any().optional(),
2162
+ children: import_zod3.z.array(PredicateNodeSchema).optional()
1182
2163
  }));
1183
- var QuerySchema = import_zod.z.object({
1184
- where: import_zod.z.record(import_zod.z.string(), import_zod.z.any()).optional(),
2164
+ var QuerySchema = import_zod3.z.object({
2165
+ where: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.any()).optional(),
1185
2166
  predicate: PredicateNodeSchema.optional(),
1186
- sort: import_zod.z.record(import_zod.z.string(), import_zod.z.enum(["asc", "desc"])).optional(),
1187
- limit: import_zod.z.number().optional(),
1188
- offset: import_zod.z.number().optional()
1189
- });
1190
- var ClientOpSchema = import_zod.z.object({
1191
- id: import_zod.z.string().optional(),
1192
- mapName: import_zod.z.string(),
1193
- key: import_zod.z.string(),
2167
+ sort: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.enum(["asc", "desc"])).optional(),
2168
+ limit: import_zod3.z.number().optional(),
2169
+ offset: import_zod3.z.number().optional()
2170
+ });
2171
+ var ClientOpSchema = import_zod3.z.object({
2172
+ id: import_zod3.z.string().optional(),
2173
+ mapName: import_zod3.z.string(),
2174
+ key: import_zod3.z.string(),
1194
2175
  // Permissive opType to match ServerCoordinator behavior logic
1195
2176
  // It can be 'REMOVE', 'OR_ADD', 'OR_REMOVE' or undefined/other (implies PUT/LWW)
1196
- opType: import_zod.z.string().optional(),
2177
+ opType: import_zod3.z.string().optional(),
1197
2178
  record: LWWRecordSchema.nullable().optional(),
1198
2179
  orRecord: ORMapRecordSchema.nullable().optional(),
1199
- orTag: import_zod.z.string().nullable().optional(),
2180
+ orTag: import_zod3.z.string().nullable().optional(),
1200
2181
  // Write Concern fields (Phase 5.01)
1201
2182
  writeConcern: WriteConcernSchema.optional(),
1202
- timeout: import_zod.z.number().optional()
2183
+ timeout: import_zod3.z.number().optional()
1203
2184
  });
1204
- var AuthMessageSchema = import_zod.z.object({
1205
- type: import_zod.z.literal("AUTH"),
1206
- token: import_zod.z.string()
2185
+ var AuthMessageSchema = import_zod3.z.object({
2186
+ type: import_zod3.z.literal("AUTH"),
2187
+ token: import_zod3.z.string()
1207
2188
  });
1208
- var QuerySubMessageSchema = import_zod.z.object({
1209
- type: import_zod.z.literal("QUERY_SUB"),
1210
- payload: import_zod.z.object({
1211
- queryId: import_zod.z.string(),
1212
- mapName: import_zod.z.string(),
2189
+ var QuerySubMessageSchema = import_zod3.z.object({
2190
+ type: import_zod3.z.literal("QUERY_SUB"),
2191
+ payload: import_zod3.z.object({
2192
+ queryId: import_zod3.z.string(),
2193
+ mapName: import_zod3.z.string(),
1213
2194
  query: QuerySchema
1214
2195
  })
1215
2196
  });
1216
- var QueryUnsubMessageSchema = import_zod.z.object({
1217
- type: import_zod.z.literal("QUERY_UNSUB"),
1218
- payload: import_zod.z.object({
1219
- queryId: import_zod.z.string()
2197
+ var QueryUnsubMessageSchema = import_zod3.z.object({
2198
+ type: import_zod3.z.literal("QUERY_UNSUB"),
2199
+ payload: import_zod3.z.object({
2200
+ queryId: import_zod3.z.string()
1220
2201
  })
1221
2202
  });
1222
- var ClientOpMessageSchema = import_zod.z.object({
1223
- type: import_zod.z.literal("CLIENT_OP"),
2203
+ var ClientOpMessageSchema = import_zod3.z.object({
2204
+ type: import_zod3.z.literal("CLIENT_OP"),
1224
2205
  payload: ClientOpSchema
1225
2206
  });
1226
- var OpBatchMessageSchema = import_zod.z.object({
1227
- type: import_zod.z.literal("OP_BATCH"),
1228
- payload: import_zod.z.object({
1229
- ops: import_zod.z.array(ClientOpSchema),
2207
+ var OpBatchMessageSchema = import_zod3.z.object({
2208
+ type: import_zod3.z.literal("OP_BATCH"),
2209
+ payload: import_zod3.z.object({
2210
+ ops: import_zod3.z.array(ClientOpSchema),
1230
2211
  // Batch-level Write Concern (can be overridden per-op)
1231
2212
  writeConcern: WriteConcernSchema.optional(),
1232
- timeout: import_zod.z.number().optional()
2213
+ timeout: import_zod3.z.number().optional()
1233
2214
  })
1234
2215
  });
1235
- var SyncInitMessageSchema = import_zod.z.object({
1236
- type: import_zod.z.literal("SYNC_INIT"),
1237
- mapName: import_zod.z.string(),
1238
- lastSyncTimestamp: import_zod.z.number().optional()
2216
+ var SyncInitMessageSchema = import_zod3.z.object({
2217
+ type: import_zod3.z.literal("SYNC_INIT"),
2218
+ mapName: import_zod3.z.string(),
2219
+ lastSyncTimestamp: import_zod3.z.number().optional()
1239
2220
  });
1240
- var SyncRespRootMessageSchema = import_zod.z.object({
1241
- type: import_zod.z.literal("SYNC_RESP_ROOT"),
1242
- payload: import_zod.z.object({
1243
- mapName: import_zod.z.string(),
1244
- rootHash: import_zod.z.number(),
2221
+ var SyncRespRootMessageSchema = import_zod3.z.object({
2222
+ type: import_zod3.z.literal("SYNC_RESP_ROOT"),
2223
+ payload: import_zod3.z.object({
2224
+ mapName: import_zod3.z.string(),
2225
+ rootHash: import_zod3.z.number(),
1245
2226
  timestamp: TimestampSchema
1246
2227
  })
1247
2228
  });
1248
- var SyncRespBucketsMessageSchema = import_zod.z.object({
1249
- type: import_zod.z.literal("SYNC_RESP_BUCKETS"),
1250
- payload: import_zod.z.object({
1251
- mapName: import_zod.z.string(),
1252
- path: import_zod.z.string(),
1253
- buckets: import_zod.z.record(import_zod.z.string(), import_zod.z.number())
2229
+ var SyncRespBucketsMessageSchema = import_zod3.z.object({
2230
+ type: import_zod3.z.literal("SYNC_RESP_BUCKETS"),
2231
+ payload: import_zod3.z.object({
2232
+ mapName: import_zod3.z.string(),
2233
+ path: import_zod3.z.string(),
2234
+ buckets: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number())
1254
2235
  })
1255
2236
  });
1256
- var SyncRespLeafMessageSchema = import_zod.z.object({
1257
- type: import_zod.z.literal("SYNC_RESP_LEAF"),
1258
- payload: import_zod.z.object({
1259
- mapName: import_zod.z.string(),
1260
- path: import_zod.z.string(),
1261
- records: import_zod.z.array(import_zod.z.object({
1262
- key: import_zod.z.string(),
2237
+ var SyncRespLeafMessageSchema = import_zod3.z.object({
2238
+ type: import_zod3.z.literal("SYNC_RESP_LEAF"),
2239
+ payload: import_zod3.z.object({
2240
+ mapName: import_zod3.z.string(),
2241
+ path: import_zod3.z.string(),
2242
+ records: import_zod3.z.array(import_zod3.z.object({
2243
+ key: import_zod3.z.string(),
1263
2244
  record: LWWRecordSchema
1264
2245
  }))
1265
2246
  })
1266
2247
  });
1267
- var MerkleReqBucketMessageSchema = import_zod.z.object({
1268
- type: import_zod.z.literal("MERKLE_REQ_BUCKET"),
1269
- payload: import_zod.z.object({
1270
- mapName: import_zod.z.string(),
1271
- path: import_zod.z.string()
2248
+ var MerkleReqBucketMessageSchema = import_zod3.z.object({
2249
+ type: import_zod3.z.literal("MERKLE_REQ_BUCKET"),
2250
+ payload: import_zod3.z.object({
2251
+ mapName: import_zod3.z.string(),
2252
+ path: import_zod3.z.string()
1272
2253
  })
1273
2254
  });
1274
- var LockRequestSchema = import_zod.z.object({
1275
- type: import_zod.z.literal("LOCK_REQUEST"),
1276
- payload: import_zod.z.object({
1277
- requestId: import_zod.z.string(),
1278
- name: import_zod.z.string(),
1279
- ttl: import_zod.z.number().optional()
2255
+ var LockRequestSchema = import_zod3.z.object({
2256
+ type: import_zod3.z.literal("LOCK_REQUEST"),
2257
+ payload: import_zod3.z.object({
2258
+ requestId: import_zod3.z.string(),
2259
+ name: import_zod3.z.string(),
2260
+ ttl: import_zod3.z.number().optional()
1280
2261
  })
1281
2262
  });
1282
- var LockReleaseSchema = import_zod.z.object({
1283
- type: import_zod.z.literal("LOCK_RELEASE"),
1284
- payload: import_zod.z.object({
1285
- requestId: import_zod.z.string().optional(),
1286
- name: import_zod.z.string(),
1287
- fencingToken: import_zod.z.number()
2263
+ var LockReleaseSchema = import_zod3.z.object({
2264
+ type: import_zod3.z.literal("LOCK_RELEASE"),
2265
+ payload: import_zod3.z.object({
2266
+ requestId: import_zod3.z.string().optional(),
2267
+ name: import_zod3.z.string(),
2268
+ fencingToken: import_zod3.z.number()
1288
2269
  })
1289
2270
  });
1290
- var TopicSubSchema = import_zod.z.object({
1291
- type: import_zod.z.literal("TOPIC_SUB"),
1292
- payload: import_zod.z.object({
1293
- topic: import_zod.z.string()
2271
+ var TopicSubSchema = import_zod3.z.object({
2272
+ type: import_zod3.z.literal("TOPIC_SUB"),
2273
+ payload: import_zod3.z.object({
2274
+ topic: import_zod3.z.string()
1294
2275
  })
1295
2276
  });
1296
- var TopicUnsubSchema = import_zod.z.object({
1297
- type: import_zod.z.literal("TOPIC_UNSUB"),
1298
- payload: import_zod.z.object({
1299
- topic: import_zod.z.string()
2277
+ var TopicUnsubSchema = import_zod3.z.object({
2278
+ type: import_zod3.z.literal("TOPIC_UNSUB"),
2279
+ payload: import_zod3.z.object({
2280
+ topic: import_zod3.z.string()
1300
2281
  })
1301
2282
  });
1302
- var TopicPubSchema = import_zod.z.object({
1303
- type: import_zod.z.literal("TOPIC_PUB"),
1304
- payload: import_zod.z.object({
1305
- topic: import_zod.z.string(),
1306
- data: import_zod.z.any()
2283
+ var TopicPubSchema = import_zod3.z.object({
2284
+ type: import_zod3.z.literal("TOPIC_PUB"),
2285
+ payload: import_zod3.z.object({
2286
+ topic: import_zod3.z.string(),
2287
+ data: import_zod3.z.any()
1307
2288
  })
1308
2289
  });
1309
- var TopicMessageEventSchema = import_zod.z.object({
1310
- type: import_zod.z.literal("TOPIC_MESSAGE"),
1311
- payload: import_zod.z.object({
1312
- topic: import_zod.z.string(),
1313
- data: import_zod.z.any(),
1314
- publisherId: import_zod.z.string().optional(),
1315
- timestamp: import_zod.z.number()
2290
+ var TopicMessageEventSchema = import_zod3.z.object({
2291
+ type: import_zod3.z.literal("TOPIC_MESSAGE"),
2292
+ payload: import_zod3.z.object({
2293
+ topic: import_zod3.z.string(),
2294
+ data: import_zod3.z.any(),
2295
+ publisherId: import_zod3.z.string().optional(),
2296
+ timestamp: import_zod3.z.number()
1316
2297
  })
1317
2298
  });
1318
- var PingMessageSchema = import_zod.z.object({
1319
- type: import_zod.z.literal("PING"),
1320
- timestamp: import_zod.z.number()
2299
+ var PNCounterStateObjectSchema = import_zod3.z.object({
2300
+ p: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number()),
2301
+ // positive counts per node
2302
+ n: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number())
2303
+ // negative counts per node
2304
+ });
2305
+ var CounterRequestSchema = import_zod3.z.object({
2306
+ type: import_zod3.z.literal("COUNTER_REQUEST"),
2307
+ payload: import_zod3.z.object({
2308
+ name: import_zod3.z.string()
2309
+ })
2310
+ });
2311
+ var CounterSyncSchema = import_zod3.z.object({
2312
+ type: import_zod3.z.literal("COUNTER_SYNC"),
2313
+ payload: import_zod3.z.object({
2314
+ name: import_zod3.z.string(),
2315
+ state: PNCounterStateObjectSchema
2316
+ })
2317
+ });
2318
+ var CounterResponseSchema = import_zod3.z.object({
2319
+ type: import_zod3.z.literal("COUNTER_RESPONSE"),
2320
+ payload: import_zod3.z.object({
2321
+ name: import_zod3.z.string(),
2322
+ state: PNCounterStateObjectSchema
2323
+ })
2324
+ });
2325
+ var CounterUpdateSchema = import_zod3.z.object({
2326
+ type: import_zod3.z.literal("COUNTER_UPDATE"),
2327
+ payload: import_zod3.z.object({
2328
+ name: import_zod3.z.string(),
2329
+ state: PNCounterStateObjectSchema
2330
+ })
2331
+ });
2332
+ var PingMessageSchema = import_zod3.z.object({
2333
+ type: import_zod3.z.literal("PING"),
2334
+ timestamp: import_zod3.z.number()
1321
2335
  // Client's Date.now()
1322
2336
  });
1323
- var PongMessageSchema = import_zod.z.object({
1324
- type: import_zod.z.literal("PONG"),
1325
- timestamp: import_zod.z.number(),
2337
+ var PongMessageSchema = import_zod3.z.object({
2338
+ type: import_zod3.z.literal("PONG"),
2339
+ timestamp: import_zod3.z.number(),
1326
2340
  // Echo back client's timestamp
1327
- serverTime: import_zod.z.number()
2341
+ serverTime: import_zod3.z.number()
1328
2342
  // Server's Date.now() (for clock skew detection)
1329
2343
  });
1330
- var BatchMessageSchema = import_zod.z.object({
1331
- type: import_zod.z.literal("BATCH"),
1332
- count: import_zod.z.number(),
1333
- data: import_zod.z.instanceof(Uint8Array)
2344
+ var BatchMessageSchema = import_zod3.z.object({
2345
+ type: import_zod3.z.literal("BATCH"),
2346
+ count: import_zod3.z.number(),
2347
+ data: import_zod3.z.instanceof(Uint8Array)
1334
2348
  });
1335
- var ORMapSyncInitSchema = import_zod.z.object({
1336
- type: import_zod.z.literal("ORMAP_SYNC_INIT"),
1337
- mapName: import_zod.z.string(),
1338
- rootHash: import_zod.z.number(),
1339
- bucketHashes: import_zod.z.record(import_zod.z.string(), import_zod.z.number()),
2349
+ var ORMapSyncInitSchema = import_zod3.z.object({
2350
+ type: import_zod3.z.literal("ORMAP_SYNC_INIT"),
2351
+ mapName: import_zod3.z.string(),
2352
+ rootHash: import_zod3.z.number(),
2353
+ bucketHashes: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number()),
1340
2354
  // path -> hash
1341
- lastSyncTimestamp: import_zod.z.number().optional()
2355
+ lastSyncTimestamp: import_zod3.z.number().optional()
1342
2356
  });
1343
- var ORMapSyncRespRootSchema = import_zod.z.object({
1344
- type: import_zod.z.literal("ORMAP_SYNC_RESP_ROOT"),
1345
- payload: import_zod.z.object({
1346
- mapName: import_zod.z.string(),
1347
- rootHash: import_zod.z.number(),
2357
+ var ORMapSyncRespRootSchema = import_zod3.z.object({
2358
+ type: import_zod3.z.literal("ORMAP_SYNC_RESP_ROOT"),
2359
+ payload: import_zod3.z.object({
2360
+ mapName: import_zod3.z.string(),
2361
+ rootHash: import_zod3.z.number(),
1348
2362
  timestamp: TimestampSchema
1349
2363
  })
1350
2364
  });
1351
- var ORMapSyncRespBucketsSchema = import_zod.z.object({
1352
- type: import_zod.z.literal("ORMAP_SYNC_RESP_BUCKETS"),
1353
- payload: import_zod.z.object({
1354
- mapName: import_zod.z.string(),
1355
- path: import_zod.z.string(),
1356
- buckets: import_zod.z.record(import_zod.z.string(), import_zod.z.number())
2365
+ var ORMapSyncRespBucketsSchema = import_zod3.z.object({
2366
+ type: import_zod3.z.literal("ORMAP_SYNC_RESP_BUCKETS"),
2367
+ payload: import_zod3.z.object({
2368
+ mapName: import_zod3.z.string(),
2369
+ path: import_zod3.z.string(),
2370
+ buckets: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.number())
1357
2371
  })
1358
2372
  });
1359
- var ORMapMerkleReqBucketSchema = import_zod.z.object({
1360
- type: import_zod.z.literal("ORMAP_MERKLE_REQ_BUCKET"),
1361
- payload: import_zod.z.object({
1362
- mapName: import_zod.z.string(),
1363
- path: import_zod.z.string()
2373
+ var ORMapMerkleReqBucketSchema = import_zod3.z.object({
2374
+ type: import_zod3.z.literal("ORMAP_MERKLE_REQ_BUCKET"),
2375
+ payload: import_zod3.z.object({
2376
+ mapName: import_zod3.z.string(),
2377
+ path: import_zod3.z.string()
1364
2378
  })
1365
2379
  });
1366
- var ORMapSyncRespLeafSchema = import_zod.z.object({
1367
- type: import_zod.z.literal("ORMAP_SYNC_RESP_LEAF"),
1368
- payload: import_zod.z.object({
1369
- mapName: import_zod.z.string(),
1370
- path: import_zod.z.string(),
1371
- entries: import_zod.z.array(import_zod.z.object({
1372
- key: import_zod.z.string(),
1373
- records: import_zod.z.array(ORMapRecordSchema),
1374
- tombstones: import_zod.z.array(import_zod.z.string())
2380
+ var ORMapSyncRespLeafSchema = import_zod3.z.object({
2381
+ type: import_zod3.z.literal("ORMAP_SYNC_RESP_LEAF"),
2382
+ payload: import_zod3.z.object({
2383
+ mapName: import_zod3.z.string(),
2384
+ path: import_zod3.z.string(),
2385
+ entries: import_zod3.z.array(import_zod3.z.object({
2386
+ key: import_zod3.z.string(),
2387
+ records: import_zod3.z.array(ORMapRecordSchema),
2388
+ tombstones: import_zod3.z.array(import_zod3.z.string())
1375
2389
  // Tombstone tags for this key's records
1376
2390
  }))
1377
2391
  })
1378
2392
  });
1379
- var ORMapDiffRequestSchema = import_zod.z.object({
1380
- type: import_zod.z.literal("ORMAP_DIFF_REQUEST"),
1381
- payload: import_zod.z.object({
1382
- mapName: import_zod.z.string(),
1383
- keys: import_zod.z.array(import_zod.z.string())
2393
+ var ORMapDiffRequestSchema = import_zod3.z.object({
2394
+ type: import_zod3.z.literal("ORMAP_DIFF_REQUEST"),
2395
+ payload: import_zod3.z.object({
2396
+ mapName: import_zod3.z.string(),
2397
+ keys: import_zod3.z.array(import_zod3.z.string())
1384
2398
  })
1385
2399
  });
1386
- var ORMapDiffResponseSchema = import_zod.z.object({
1387
- type: import_zod.z.literal("ORMAP_DIFF_RESPONSE"),
1388
- payload: import_zod.z.object({
1389
- mapName: import_zod.z.string(),
1390
- entries: import_zod.z.array(import_zod.z.object({
1391
- key: import_zod.z.string(),
1392
- records: import_zod.z.array(ORMapRecordSchema),
1393
- tombstones: import_zod.z.array(import_zod.z.string())
2400
+ var ORMapDiffResponseSchema = import_zod3.z.object({
2401
+ type: import_zod3.z.literal("ORMAP_DIFF_RESPONSE"),
2402
+ payload: import_zod3.z.object({
2403
+ mapName: import_zod3.z.string(),
2404
+ entries: import_zod3.z.array(import_zod3.z.object({
2405
+ key: import_zod3.z.string(),
2406
+ records: import_zod3.z.array(ORMapRecordSchema),
2407
+ tombstones: import_zod3.z.array(import_zod3.z.string())
1394
2408
  }))
1395
2409
  })
1396
2410
  });
1397
- var ORMapPushDiffSchema = import_zod.z.object({
1398
- type: import_zod.z.literal("ORMAP_PUSH_DIFF"),
1399
- payload: import_zod.z.object({
1400
- mapName: import_zod.z.string(),
1401
- entries: import_zod.z.array(import_zod.z.object({
1402
- key: import_zod.z.string(),
1403
- records: import_zod.z.array(ORMapRecordSchema),
1404
- tombstones: import_zod.z.array(import_zod.z.string())
2411
+ var ORMapPushDiffSchema = import_zod3.z.object({
2412
+ type: import_zod3.z.literal("ORMAP_PUSH_DIFF"),
2413
+ payload: import_zod3.z.object({
2414
+ mapName: import_zod3.z.string(),
2415
+ entries: import_zod3.z.array(import_zod3.z.object({
2416
+ key: import_zod3.z.string(),
2417
+ records: import_zod3.z.array(ORMapRecordSchema),
2418
+ tombstones: import_zod3.z.array(import_zod3.z.string())
1405
2419
  }))
1406
2420
  })
1407
2421
  });
1408
- var OpResultSchema = import_zod.z.object({
1409
- opId: import_zod.z.string(),
1410
- success: import_zod.z.boolean(),
2422
+ var PartitionMapRequestSchema = import_zod3.z.object({
2423
+ type: import_zod3.z.literal("PARTITION_MAP_REQUEST"),
2424
+ payload: import_zod3.z.object({
2425
+ currentVersion: import_zod3.z.number().optional()
2426
+ }).optional()
2427
+ });
2428
+ var EntryProcessorSchema = import_zod3.z.object({
2429
+ name: import_zod3.z.string().min(1).max(100),
2430
+ code: import_zod3.z.string().min(1).max(1e4),
2431
+ args: import_zod3.z.unknown().optional()
2432
+ });
2433
+ var EntryProcessRequestSchema = import_zod3.z.object({
2434
+ type: import_zod3.z.literal("ENTRY_PROCESS"),
2435
+ requestId: import_zod3.z.string(),
2436
+ mapName: import_zod3.z.string(),
2437
+ key: import_zod3.z.string(),
2438
+ processor: EntryProcessorSchema
2439
+ });
2440
+ var EntryProcessBatchRequestSchema = import_zod3.z.object({
2441
+ type: import_zod3.z.literal("ENTRY_PROCESS_BATCH"),
2442
+ requestId: import_zod3.z.string(),
2443
+ mapName: import_zod3.z.string(),
2444
+ keys: import_zod3.z.array(import_zod3.z.string()),
2445
+ processor: EntryProcessorSchema
2446
+ });
2447
+ var EntryProcessResponseSchema = import_zod3.z.object({
2448
+ type: import_zod3.z.literal("ENTRY_PROCESS_RESPONSE"),
2449
+ requestId: import_zod3.z.string(),
2450
+ success: import_zod3.z.boolean(),
2451
+ result: import_zod3.z.unknown().optional(),
2452
+ newValue: import_zod3.z.unknown().optional(),
2453
+ error: import_zod3.z.string().optional()
2454
+ });
2455
+ var EntryProcessKeyResultSchema = import_zod3.z.object({
2456
+ success: import_zod3.z.boolean(),
2457
+ result: import_zod3.z.unknown().optional(),
2458
+ newValue: import_zod3.z.unknown().optional(),
2459
+ error: import_zod3.z.string().optional()
2460
+ });
2461
+ var EntryProcessBatchResponseSchema = import_zod3.z.object({
2462
+ type: import_zod3.z.literal("ENTRY_PROCESS_BATCH_RESPONSE"),
2463
+ requestId: import_zod3.z.string(),
2464
+ results: import_zod3.z.record(import_zod3.z.string(), EntryProcessKeyResultSchema)
2465
+ });
2466
+ var JournalEventTypeSchema = import_zod3.z.enum(["PUT", "UPDATE", "DELETE"]);
2467
+ var JournalEventDataSchema = import_zod3.z.object({
2468
+ sequence: import_zod3.z.string(),
2469
+ // bigint as string
2470
+ type: JournalEventTypeSchema,
2471
+ mapName: import_zod3.z.string(),
2472
+ key: import_zod3.z.string(),
2473
+ value: import_zod3.z.unknown().optional(),
2474
+ previousValue: import_zod3.z.unknown().optional(),
2475
+ timestamp: TimestampSchema,
2476
+ nodeId: import_zod3.z.string(),
2477
+ metadata: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).optional()
2478
+ });
2479
+ var JournalSubscribeRequestSchema = import_zod3.z.object({
2480
+ type: import_zod3.z.literal("JOURNAL_SUBSCRIBE"),
2481
+ requestId: import_zod3.z.string(),
2482
+ fromSequence: import_zod3.z.string().optional(),
2483
+ // bigint as string
2484
+ mapName: import_zod3.z.string().optional(),
2485
+ types: import_zod3.z.array(JournalEventTypeSchema).optional()
2486
+ });
2487
+ var JournalUnsubscribeRequestSchema = import_zod3.z.object({
2488
+ type: import_zod3.z.literal("JOURNAL_UNSUBSCRIBE"),
2489
+ subscriptionId: import_zod3.z.string()
2490
+ });
2491
+ var JournalEventMessageSchema = import_zod3.z.object({
2492
+ type: import_zod3.z.literal("JOURNAL_EVENT"),
2493
+ event: JournalEventDataSchema
2494
+ });
2495
+ var JournalReadRequestSchema = import_zod3.z.object({
2496
+ type: import_zod3.z.literal("JOURNAL_READ"),
2497
+ requestId: import_zod3.z.string(),
2498
+ fromSequence: import_zod3.z.string(),
2499
+ limit: import_zod3.z.number().optional(),
2500
+ mapName: import_zod3.z.string().optional()
2501
+ });
2502
+ var JournalReadResponseSchema = import_zod3.z.object({
2503
+ type: import_zod3.z.literal("JOURNAL_READ_RESPONSE"),
2504
+ requestId: import_zod3.z.string(),
2505
+ events: import_zod3.z.array(JournalEventDataSchema),
2506
+ hasMore: import_zod3.z.boolean()
2507
+ });
2508
+ var ConflictResolverSchema = import_zod3.z.object({
2509
+ name: import_zod3.z.string().min(1).max(100),
2510
+ code: import_zod3.z.string().max(5e4),
2511
+ priority: import_zod3.z.number().int().min(0).max(100).optional(),
2512
+ keyPattern: import_zod3.z.string().optional()
2513
+ });
2514
+ var RegisterResolverRequestSchema = import_zod3.z.object({
2515
+ type: import_zod3.z.literal("REGISTER_RESOLVER"),
2516
+ requestId: import_zod3.z.string(),
2517
+ mapName: import_zod3.z.string(),
2518
+ resolver: ConflictResolverSchema
2519
+ });
2520
+ var RegisterResolverResponseSchema = import_zod3.z.object({
2521
+ type: import_zod3.z.literal("REGISTER_RESOLVER_RESPONSE"),
2522
+ requestId: import_zod3.z.string(),
2523
+ success: import_zod3.z.boolean(),
2524
+ error: import_zod3.z.string().optional()
2525
+ });
2526
+ var UnregisterResolverRequestSchema = import_zod3.z.object({
2527
+ type: import_zod3.z.literal("UNREGISTER_RESOLVER"),
2528
+ requestId: import_zod3.z.string(),
2529
+ mapName: import_zod3.z.string(),
2530
+ resolverName: import_zod3.z.string()
2531
+ });
2532
+ var UnregisterResolverResponseSchema = import_zod3.z.object({
2533
+ type: import_zod3.z.literal("UNREGISTER_RESOLVER_RESPONSE"),
2534
+ requestId: import_zod3.z.string(),
2535
+ success: import_zod3.z.boolean(),
2536
+ error: import_zod3.z.string().optional()
2537
+ });
2538
+ var MergeRejectedMessageSchema = import_zod3.z.object({
2539
+ type: import_zod3.z.literal("MERGE_REJECTED"),
2540
+ mapName: import_zod3.z.string(),
2541
+ key: import_zod3.z.string(),
2542
+ attemptedValue: import_zod3.z.unknown(),
2543
+ reason: import_zod3.z.string(),
2544
+ timestamp: TimestampSchema
2545
+ });
2546
+ var ListResolversRequestSchema = import_zod3.z.object({
2547
+ type: import_zod3.z.literal("LIST_RESOLVERS"),
2548
+ requestId: import_zod3.z.string(),
2549
+ mapName: import_zod3.z.string().optional()
2550
+ });
2551
+ var ListResolversResponseSchema = import_zod3.z.object({
2552
+ type: import_zod3.z.literal("LIST_RESOLVERS_RESPONSE"),
2553
+ requestId: import_zod3.z.string(),
2554
+ resolvers: import_zod3.z.array(import_zod3.z.object({
2555
+ mapName: import_zod3.z.string(),
2556
+ name: import_zod3.z.string(),
2557
+ priority: import_zod3.z.number().optional(),
2558
+ keyPattern: import_zod3.z.string().optional()
2559
+ }))
2560
+ });
2561
+ var OpResultSchema = import_zod3.z.object({
2562
+ opId: import_zod3.z.string(),
2563
+ success: import_zod3.z.boolean(),
1411
2564
  achievedLevel: WriteConcernSchema,
1412
- error: import_zod.z.string().optional()
2565
+ error: import_zod3.z.string().optional()
1413
2566
  });
1414
- var OpAckMessageSchema = import_zod.z.object({
1415
- type: import_zod.z.literal("OP_ACK"),
1416
- payload: import_zod.z.object({
2567
+ var OpAckMessageSchema = import_zod3.z.object({
2568
+ type: import_zod3.z.literal("OP_ACK"),
2569
+ payload: import_zod3.z.object({
1417
2570
  /** ID of the last operation in the batch (for backwards compatibility) */
1418
- lastId: import_zod.z.string(),
2571
+ lastId: import_zod3.z.string(),
1419
2572
  /** Write Concern level achieved (for simple ACKs) */
1420
2573
  achievedLevel: WriteConcernSchema.optional(),
1421
2574
  /** Per-operation results (for batch operations with mixed Write Concern) */
1422
- results: import_zod.z.array(OpResultSchema).optional()
2575
+ results: import_zod3.z.array(OpResultSchema).optional()
1423
2576
  })
1424
2577
  });
1425
- var OpRejectedMessageSchema = import_zod.z.object({
1426
- type: import_zod.z.literal("OP_REJECTED"),
1427
- payload: import_zod.z.object({
2578
+ var OpRejectedMessageSchema = import_zod3.z.object({
2579
+ type: import_zod3.z.literal("OP_REJECTED"),
2580
+ payload: import_zod3.z.object({
1428
2581
  /** Operation ID that was rejected */
1429
- opId: import_zod.z.string(),
2582
+ opId: import_zod3.z.string(),
1430
2583
  /** Reason for rejection */
1431
- reason: import_zod.z.string(),
2584
+ reason: import_zod3.z.string(),
1432
2585
  /** Error code */
1433
- code: import_zod.z.number().optional()
2586
+ code: import_zod3.z.number().optional()
1434
2587
  })
1435
2588
  });
1436
- var MessageSchema = import_zod.z.discriminatedUnion("type", [
2589
+ var MessageSchema = import_zod3.z.discriminatedUnion("type", [
1437
2590
  AuthMessageSchema,
1438
2591
  QuerySubMessageSchema,
1439
2592
  QueryUnsubMessageSchema,
@@ -1459,7 +2612,31 @@ var MessageSchema = import_zod.z.discriminatedUnion("type", [
1459
2612
  ORMapSyncRespLeafSchema,
1460
2613
  ORMapDiffRequestSchema,
1461
2614
  ORMapDiffResponseSchema,
1462
- ORMapPushDiffSchema
2615
+ ORMapPushDiffSchema,
2616
+ // Phase 4: Partition Map
2617
+ PartitionMapRequestSchema,
2618
+ // Phase 5.2: PN Counter
2619
+ CounterRequestSchema,
2620
+ CounterSyncSchema,
2621
+ // Phase 5.03: Entry Processor
2622
+ EntryProcessRequestSchema,
2623
+ EntryProcessBatchRequestSchema,
2624
+ EntryProcessResponseSchema,
2625
+ EntryProcessBatchResponseSchema,
2626
+ // Phase 5.04: Event Journal
2627
+ JournalSubscribeRequestSchema,
2628
+ JournalUnsubscribeRequestSchema,
2629
+ JournalEventMessageSchema,
2630
+ JournalReadRequestSchema,
2631
+ JournalReadResponseSchema,
2632
+ // Phase 5.05: Conflict Resolver
2633
+ RegisterResolverRequestSchema,
2634
+ RegisterResolverResponseSchema,
2635
+ UnregisterResolverRequestSchema,
2636
+ UnregisterResolverResponseSchema,
2637
+ MergeRejectedMessageSchema,
2638
+ ListResolversRequestSchema,
2639
+ ListResolversResponseSchema
1463
2640
  ]);
1464
2641
 
1465
2642
  // src/types/WriteConcern.ts
@@ -1494,18 +2671,106 @@ function getHighestWriteConcernLevel(achieved) {
1494
2671
  }
1495
2672
  return "FIRE_AND_FORGET" /* FIRE_AND_FORGET */;
1496
2673
  }
2674
+
2675
+ // src/types/cluster.ts
2676
+ var DEFAULT_CONNECTION_POOL_CONFIG = {
2677
+ maxConnectionsPerNode: 1,
2678
+ connectionTimeoutMs: 5e3,
2679
+ healthCheckIntervalMs: 1e4,
2680
+ reconnectDelayMs: 1e3,
2681
+ maxReconnectDelayMs: 3e4,
2682
+ maxReconnectAttempts: 5
2683
+ };
2684
+ var DEFAULT_PARTITION_ROUTER_CONFIG = {
2685
+ fallbackMode: "forward",
2686
+ mapRefreshIntervalMs: 3e4,
2687
+ maxMapStalenessMs: 6e4
2688
+ };
2689
+ var DEFAULT_CIRCUIT_BREAKER_CONFIG = {
2690
+ failureThreshold: 5,
2691
+ resetTimeoutMs: 3e4
2692
+ };
2693
+ var PartitionState = /* @__PURE__ */ ((PartitionState2) => {
2694
+ PartitionState2["STABLE"] = "STABLE";
2695
+ PartitionState2["MIGRATING"] = "MIGRATING";
2696
+ PartitionState2["SYNC"] = "SYNC";
2697
+ PartitionState2["FAILED"] = "FAILED";
2698
+ return PartitionState2;
2699
+ })(PartitionState || {});
2700
+ var DEFAULT_MIGRATION_CONFIG = {
2701
+ batchSize: 10,
2702
+ batchIntervalMs: 5e3,
2703
+ transferChunkSize: 65536,
2704
+ // 64KB
2705
+ maxRetries: 3,
2706
+ syncTimeoutMs: 3e4,
2707
+ parallelTransfers: 4
2708
+ };
2709
+ var ConsistencyLevel = /* @__PURE__ */ ((ConsistencyLevel2) => {
2710
+ ConsistencyLevel2["STRONG"] = "STRONG";
2711
+ ConsistencyLevel2["QUORUM"] = "QUORUM";
2712
+ ConsistencyLevel2["EVENTUAL"] = "EVENTUAL";
2713
+ return ConsistencyLevel2;
2714
+ })(ConsistencyLevel || {});
2715
+ var DEFAULT_REPLICATION_CONFIG = {
2716
+ defaultConsistency: "EVENTUAL" /* EVENTUAL */,
2717
+ queueSizeLimit: 1e4,
2718
+ batchSize: 100,
2719
+ batchIntervalMs: 50,
2720
+ ackTimeoutMs: 5e3,
2721
+ maxRetries: 3
2722
+ };
2723
+ var PARTITION_COUNT = 271;
2724
+ var DEFAULT_BACKUP_COUNT = 1;
1497
2725
  // Annotate the CommonJS export names for ESM import in node:
1498
2726
  0 && (module.exports = {
1499
2727
  AuthMessageSchema,
1500
2728
  BatchMessageSchema,
2729
+ BuiltInProcessors,
2730
+ BuiltInResolvers,
1501
2731
  ClientOpMessageSchema,
1502
2732
  ClientOpSchema,
2733
+ ConflictResolverDefSchema,
2734
+ ConflictResolverSchema,
2735
+ ConsistencyLevel,
2736
+ CounterRequestSchema,
2737
+ CounterResponseSchema,
2738
+ CounterSyncSchema,
2739
+ CounterUpdateSchema,
2740
+ DEFAULT_BACKUP_COUNT,
2741
+ DEFAULT_CIRCUIT_BREAKER_CONFIG,
2742
+ DEFAULT_CONNECTION_POOL_CONFIG,
2743
+ DEFAULT_EVENT_JOURNAL_CONFIG,
2744
+ DEFAULT_MIGRATION_CONFIG,
2745
+ DEFAULT_PARTITION_ROUTER_CONFIG,
2746
+ DEFAULT_PROCESSOR_RATE_LIMITS,
2747
+ DEFAULT_REPLICATION_CONFIG,
2748
+ DEFAULT_RESOLVER_RATE_LIMITS,
1503
2749
  DEFAULT_WRITE_CONCERN_TIMEOUT,
2750
+ EntryProcessBatchRequestSchema,
2751
+ EntryProcessBatchResponseSchema,
2752
+ EntryProcessKeyResultSchema,
2753
+ EntryProcessRequestSchema,
2754
+ EntryProcessResponseSchema,
2755
+ EntryProcessorDefSchema,
2756
+ EntryProcessorSchema,
2757
+ EventJournalImpl,
2758
+ FORBIDDEN_PATTERNS,
1504
2759
  HLC,
2760
+ JournalEventDataSchema,
2761
+ JournalEventMessageSchema,
2762
+ JournalEventTypeSchema,
2763
+ JournalReadRequestSchema,
2764
+ JournalReadResponseSchema,
2765
+ JournalSubscribeRequestSchema,
2766
+ JournalUnsubscribeRequestSchema,
1505
2767
  LWWMap,
1506
2768
  LWWRecordSchema,
2769
+ ListResolversRequestSchema,
2770
+ ListResolversResponseSchema,
1507
2771
  LockReleaseSchema,
1508
2772
  LockRequestSchema,
2773
+ MergeRejectedMessageSchema,
1509
2774
  MerkleReqBucketMessageSchema,
1510
2775
  MerkleTree,
1511
2776
  MessageSchema,
@@ -1524,6 +2789,11 @@ function getHighestWriteConcernLevel(achieved) {
1524
2789
  OpBatchMessageSchema,
1525
2790
  OpRejectedMessageSchema,
1526
2791
  OpResultSchema,
2792
+ PARTITION_COUNT,
2793
+ PNCounterImpl,
2794
+ PNCounterStateObjectSchema,
2795
+ PartitionMapRequestSchema,
2796
+ PartitionState,
1527
2797
  PingMessageSchema,
1528
2798
  PongMessageSchema,
1529
2799
  PredicateNodeSchema,
@@ -1532,6 +2802,10 @@ function getHighestWriteConcernLevel(achieved) {
1532
2802
  QuerySchema,
1533
2803
  QuerySubMessageSchema,
1534
2804
  QueryUnsubMessageSchema,
2805
+ RESOLVER_FORBIDDEN_PATTERNS,
2806
+ RegisterResolverRequestSchema,
2807
+ RegisterResolverResponseSchema,
2808
+ Ringbuffer,
1535
2809
  SyncInitMessageSchema,
1536
2810
  SyncRespBucketsMessageSchema,
1537
2811
  SyncRespLeafMessageSchema,
@@ -1541,11 +2815,15 @@ function getHighestWriteConcernLevel(achieved) {
1541
2815
  TopicPubSchema,
1542
2816
  TopicSubSchema,
1543
2817
  TopicUnsubSchema,
2818
+ UnregisterResolverRequestSchema,
2819
+ UnregisterResolverResponseSchema,
1544
2820
  WRITE_CONCERN_ORDER,
1545
2821
  WriteConcern,
1546
2822
  WriteConcernSchema,
1547
2823
  combineHashes,
2824
+ compareHLCTimestamps,
1548
2825
  compareTimestamps,
2826
+ deepMerge,
1549
2827
  deserialize,
1550
2828
  disableNativeHash,
1551
2829
  evaluatePredicate,
@@ -1557,6 +2835,8 @@ function getHighestWriteConcernLevel(achieved) {
1557
2835
  isWriteConcernAchieved,
1558
2836
  resetNativeHash,
1559
2837
  serialize,
1560
- timestampToString
2838
+ timestampToString,
2839
+ validateProcessorCode,
2840
+ validateResolverCode
1561
2841
  });
1562
2842
  //# sourceMappingURL=index.js.map