@powerhousedao/reactor-local 1.9.5 → 1.10.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.
package/CHANGELOG.md CHANGED
@@ -1,19 +1,10 @@
1
- ## 1.9.5 (2024-12-10)
2
-
3
- ### 🚀 Features
4
-
5
- - **design-system:** release dspot-scalars components ([881b8995](https://github.com/powerhouse-inc/powerhouse/commit/881b8995))
1
+ ## 1.10.1 (2024-12-11)
6
2
 
7
3
  ### 🧱 Updated Dependencies
8
4
 
9
- - Updated @powerhousedao/general-document-indexer to 1.7.5
10
- - Updated document-model-libs to 1.120.4
11
- - Updated document-drive to 1.8.5
12
- - Updated @powerhousedao/reactor-api to 1.9.5
13
-
14
- ### ❤️ Thank You
15
-
16
- - Guillermo Puente Sandoval @gpuente
5
+ - Updated document-model-libs to 1.121.1
6
+ - Updated document-drive to 1.10.0
7
+ - Updated @powerhousedao/reactor-api to 1.10.1
17
8
 
18
9
  ## 1.1.0 (2024-10-29)
19
10
 
@@ -1,7 +1,4 @@
1
- import { require_main, createServer } from './chunk-2CQEJHCK.js';
2
- import { init_esm_shims, __toESM } from './chunk-JKUWAFT3.js';
3
- import { PGlite } from '@electric-sql/pglite';
4
- import { startAPI } from '@powerhousedao/reactor-api';
1
+ import { startAPI, isProcessorClass } from '@powerhousedao/reactor-api';
5
2
  import * as DocumentDrive from 'document-model-libs/document-drive';
6
3
  import { isFileNode, utils as utils$1, actions, documentModel } from 'document-model-libs/document-drive';
7
4
  import { utils } from 'document-model/document';
@@ -20,18 +17,11 @@ import { module } from 'document-model/document-model';
20
17
  import dotenv from 'dotenv';
21
18
  import path2 from 'node:path';
22
19
  import { fileURLToPath } from 'node:url';
20
+ import { createServer } from 'vite';
23
21
 
24
22
  // src/server.ts
25
- init_esm_shims();
26
-
27
- // ../document-drive/src/index.ts
28
- init_esm_shims();
29
-
30
- // ../document-drive/src/server/index.ts
31
- init_esm_shims();
32
23
 
33
24
  // ../document-drive/src/cache/memory.ts
34
- init_esm_shims();
35
25
  var InMemoryCache = class {
36
26
  cache = /* @__PURE__ */ new Map();
37
27
  async setDocument(drive, id, document) {
@@ -59,14 +49,7 @@ var InMemoryCache = class {
59
49
  };
60
50
  var memory_default = InMemoryCache;
61
51
 
62
- // ../document-drive/src/queue/base.ts
63
- init_esm_shims();
64
-
65
- // ../document-drive/src/utils/index.ts
66
- init_esm_shims();
67
-
68
52
  // ../document-drive/src/server/error.ts
69
- init_esm_shims();
70
53
  var DocumentModelNotFoundError = class extends Error {
71
54
  constructor(id, cause) {
72
55
  super(`Document model "${id}" not found`, { cause });
@@ -115,7 +98,6 @@ var SynchronizationUnitNotFoundError = class extends Error {
115
98
  };
116
99
 
117
100
  // ../document-drive/src/utils/run-asap.ts
118
- init_esm_shims();
119
101
  var RunAsap;
120
102
  ((RunAsap2) => {
121
103
  RunAsap2.useMessageChannel = (() => {
@@ -278,7 +260,6 @@ function isBefore(dateA, dateB) {
278
260
  }
279
261
 
280
262
  // ../document-drive/src/utils/logger.ts
281
- init_esm_shims();
282
263
  var Logger = class {
283
264
  #logger = console;
284
265
  set logger(logger2) {
@@ -307,7 +288,6 @@ var loggerInstance = new Logger();
307
288
  var logger = loggerInstance;
308
289
 
309
290
  // ../document-drive/src/queue/types.ts
310
- init_esm_shims();
311
291
  function isOperationJob(job) {
312
292
  return "operations" in job;
313
293
  }
@@ -544,15 +524,6 @@ var BaseQueueManager = class {
544
524
  return `queue:${driveId}${documentId ? `:${documentId}` : ""}`;
545
525
  }
546
526
  };
547
-
548
- // ../document-drive/src/read-mode/index.ts
549
- init_esm_shims();
550
-
551
- // ../document-drive/src/read-mode/service.ts
552
- init_esm_shims();
553
-
554
- // ../document-drive/src/utils/graphql.ts
555
- init_esm_shims();
556
527
  async function requestGraphql(...args) {
557
528
  const [url, ...requestArgs] = args;
558
529
  const client = new GraphQLClient(url, { fetch });
@@ -725,7 +696,6 @@ async function fetchDocument(url, documentId, documentModelLib) {
725
696
  }
726
697
 
727
698
  // ../document-drive/src/read-mode/errors.ts
728
- init_esm_shims();
729
699
  var ReadDriveError = class extends Error {
730
700
  };
731
701
  var ReadDriveNotFoundError = class extends ReadDriveError {
@@ -868,9 +838,6 @@ var ReadModeService = class {
868
838
  }
869
839
  };
870
840
 
871
- // ../document-drive/src/read-mode/types.ts
872
- init_esm_shims();
873
-
874
841
  // ../document-drive/src/read-mode/index.ts
875
842
  function ReadModeServer(Base) {
876
843
  return class ReadMode extends Base {
@@ -951,7 +918,6 @@ function ReadModeServer(Base) {
951
918
  }
952
919
 
953
920
  // ../document-drive/src/storage/memory.ts
954
- init_esm_shims();
955
921
  var MemoryStorage = class {
956
922
  documents;
957
923
  drives;
@@ -1100,7 +1066,6 @@ var MemoryStorage = class {
1100
1066
  };
1101
1067
 
1102
1068
  // ../document-drive/src/utils/default-drives-manager.ts
1103
- init_esm_shims();
1104
1069
  function isReadModeDriveServer(obj) {
1105
1070
  return typeof obj.getReadDrives === "function";
1106
1071
  }
@@ -1329,9 +1294,6 @@ var DefaultDrivesManager = class {
1329
1294
  }
1330
1295
  }
1331
1296
  };
1332
-
1333
- // ../document-drive/src/utils/document-helpers.ts
1334
- init_esm_shims();
1335
1297
  var {
1336
1298
  attachBranch,
1337
1299
  garbageCollect,
@@ -1352,11 +1314,7 @@ var {
1352
1314
  IntegrityIssueType
1353
1315
  } = utils.documentHelpers;
1354
1316
 
1355
- // ../document-drive/src/server/listener/manager.ts
1356
- init_esm_shims();
1357
-
1358
1317
  // ../document-drive/src/server/types.ts
1359
- init_esm_shims();
1360
1318
  var AbstractDocumentDriveServer = class {
1361
1319
  };
1362
1320
  var DefaultListenerManagerOptions = {
@@ -1374,36 +1332,6 @@ var BaseListenerManager = class {
1374
1332
  }
1375
1333
  };
1376
1334
 
1377
- // ../document-drive/src/server/listener/transmitter/index.ts
1378
- init_esm_shims();
1379
-
1380
- // ../document-drive/src/server/listener/transmitter/internal.ts
1381
- init_esm_shims();
1382
-
1383
- // ../document-drive/src/server/utils.ts
1384
- init_esm_shims();
1385
- function buildRevisionsFilter(strands, driveId, documentId) {
1386
- return strands.reduce((acc, s) => {
1387
- if (!(s.driveId === driveId && s.documentId === documentId)) {
1388
- return acc;
1389
- }
1390
- acc[s.scope] = s.operations[s.operations.length - 1]?.index ?? -1;
1391
- return acc;
1392
- }, {});
1393
- }
1394
- function filterOperationsByRevision(operations, revisions) {
1395
- if (!revisions) {
1396
- return operations;
1397
- }
1398
- return Object.keys(operations).reduce((acc, scope) => {
1399
- const revision = revisions[scope];
1400
- if (revision !== void 0) {
1401
- acc[scope] = operations[scope].filter((op) => op.index <= revision);
1402
- }
1403
- return acc;
1404
- }, operations);
1405
- }
1406
-
1407
1335
  // ../document-drive/src/server/listener/transmitter/internal.ts
1408
1336
  var InternalTransmitter = class {
1409
1337
  drive;
@@ -1413,45 +1341,68 @@ var InternalTransmitter = class {
1413
1341
  this.listener = listener;
1414
1342
  this.drive = drive;
1415
1343
  }
1416
- async transmit(strands) {
1344
+ async #buildInternalOperationUpdate(strand) {
1345
+ const operations = [];
1346
+ const stateByIndex = /* @__PURE__ */ new Map();
1347
+ const getStateByIndex = async (index) => {
1348
+ const state = stateByIndex.get(index);
1349
+ if (state) {
1350
+ return state;
1351
+ }
1352
+ const getDocumentOptions = {
1353
+ revisions: {
1354
+ [strand.scope]: index
1355
+ },
1356
+ checkHashes: false
1357
+ };
1358
+ const document = await (strand.documentId ? this.drive.getDocument(
1359
+ strand.driveId,
1360
+ strand.documentId,
1361
+ getDocumentOptions
1362
+ ) : this.drive.getDrive(strand.driveId, getDocumentOptions));
1363
+ if (index < 0) {
1364
+ stateByIndex.set(index, document.initialState.state[strand.scope]);
1365
+ } else {
1366
+ stateByIndex.set(index, document.state[strand.scope]);
1367
+ }
1368
+ return stateByIndex.get(index);
1369
+ };
1370
+ for (const operation of strand.operations) {
1371
+ operations.push({
1372
+ ...operation,
1373
+ state: await getStateByIndex(operation.index),
1374
+ previousState: await getStateByIndex(operation.index - 1)
1375
+ });
1376
+ }
1377
+ return operations;
1378
+ }
1379
+ async transmit(strands, _source) {
1417
1380
  if (!this.receiver) {
1418
1381
  return [];
1419
1382
  }
1420
- const retrievedDocuments = /* @__PURE__ */ new Map();
1421
1383
  const updates = [];
1422
1384
  for (const strand of strands) {
1423
- let document = retrievedDocuments.get(
1424
- `${strand.driveId}:${strand.documentId}`
1425
- );
1426
- if (!document) {
1427
- const revisions = buildRevisionsFilter(
1428
- strands,
1429
- strand.driveId,
1430
- strand.documentId
1431
- );
1432
- document = await (strand.documentId ? this.drive.getDocument(strand.driveId, strand.documentId, {
1433
- revisions
1434
- }) : this.drive.getDrive(strand.driveId, { revisions }));
1435
- retrievedDocuments.set(
1436
- `${strand.driveId}:${strand.documentId}`,
1437
- document
1438
- );
1439
- }
1440
- updates.push({ ...strand, state: document.state[strand.scope] });
1385
+ const operations = await this.#buildInternalOperationUpdate(strand);
1386
+ const state = operations.at(-1)?.state ?? {};
1387
+ updates.push({
1388
+ ...strand,
1389
+ operations,
1390
+ state
1391
+ });
1441
1392
  }
1442
1393
  try {
1443
- await this.receiver.transmit(updates);
1394
+ await this.receiver.onStrands(updates);
1444
1395
  return strands.map(({ operations, ...s }) => ({
1445
1396
  ...s,
1446
1397
  status: "SUCCESS",
1447
- revision: operations[operations.length - 1]?.index ?? -1
1398
+ revision: operations.at(operations.length - 1)?.index ?? -1
1448
1399
  }));
1449
1400
  } catch (error) {
1450
1401
  logger.error(error);
1451
1402
  return strands.map(({ operations, ...s }) => ({
1452
1403
  ...s,
1453
1404
  status: "ERROR",
1454
- revision: (operations[0]?.index ?? 0) - 1
1405
+ revision: (operations.at(0)?.index ?? 0) - 1
1455
1406
  }));
1456
1407
  }
1457
1408
  }
@@ -1459,12 +1410,14 @@ var InternalTransmitter = class {
1459
1410
  this.receiver = receiver;
1460
1411
  }
1461
1412
  async disconnect() {
1462
- await this.receiver?.disconnect();
1413
+ await this.receiver?.onDisconnect();
1414
+ }
1415
+ getListener() {
1416
+ return this.listener;
1463
1417
  }
1464
1418
  };
1465
1419
 
1466
1420
  // ../document-drive/src/server/listener/transmitter/pull-responder.ts
1467
- init_esm_shims();
1468
1421
  var PullResponderTransmitter = class _PullResponderTransmitter {
1469
1422
  drive;
1470
1423
  listener;
@@ -1729,9 +1682,6 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
1729
1682
  return trigger.type === "PullResponder";
1730
1683
  }
1731
1684
  };
1732
-
1733
- // ../document-drive/src/server/listener/transmitter/switchboard-push.ts
1734
- init_esm_shims();
1735
1685
  var SwitchboardPushTransmitter = class {
1736
1686
  drive;
1737
1687
  listener;
@@ -1790,9 +1740,6 @@ var SwitchboardPushTransmitter = class {
1790
1740
  }
1791
1741
  };
1792
1742
 
1793
- // ../document-drive/src/server/listener/transmitter/types.ts
1794
- init_esm_shims();
1795
-
1796
1743
  // ../document-drive/src/server/listener/manager.ts
1797
1744
  function debounce(func, delay = 250) {
1798
1745
  let timer;
@@ -1854,6 +1801,7 @@ var ListenerManager = class _ListenerManager extends BaseListenerManager {
1854
1801
  const driveTransmitters = this.transmitters[drive] || {};
1855
1802
  driveTransmitters[listener.listenerId] = transmitter;
1856
1803
  this.transmitters[drive] = driveTransmitters;
1804
+ this.triggerUpdate(true, { type: "local" });
1857
1805
  return Promise.resolve(transmitter);
1858
1806
  }
1859
1807
  async removeListener(driveId, listenerId) {
@@ -2181,8 +2129,31 @@ var ListenerManager = class _ListenerManager extends BaseListenerManager {
2181
2129
  }
2182
2130
  };
2183
2131
 
2184
- // ../document-drive/src/server/listener/index.ts
2185
- init_esm_shims();
2132
+ // ../document-drive/src/server/utils.ts
2133
+ function filterOperationsByRevision(operations, revisions) {
2134
+ if (!revisions) {
2135
+ return operations;
2136
+ }
2137
+ return Object.keys(operations).reduce(
2138
+ (acc, scope) => {
2139
+ const revision = revisions[scope];
2140
+ if (revision !== void 0) {
2141
+ acc[scope] = operations[scope].filter((op) => op.index <= revision);
2142
+ }
2143
+ return acc;
2144
+ },
2145
+ { global: [], local: [] }
2146
+ );
2147
+ }
2148
+ function isAtRevision(document, revisions) {
2149
+ return !revisions || Object.entries(revisions).find(([scope, revision]) => {
2150
+ const operation = document.operations[scope].at(-1);
2151
+ if (revision === -1) {
2152
+ return operation !== void 0;
2153
+ }
2154
+ return operation?.index !== revision;
2155
+ }) === void 0;
2156
+ }
2186
2157
 
2187
2158
  // ../document-drive/src/server/index.ts
2188
2159
  var PULL_DRIVE_INTERVAL = 5e3;
@@ -2803,21 +2774,27 @@ var BaseDocumentDriveServer = class extends AbstractDocumentDriveServer {
2803
2774
  return this.storage.getDrives();
2804
2775
  }
2805
2776
  async getDrive(drive, options) {
2777
+ let document;
2806
2778
  try {
2807
- const document2 = await this.cache.getDocument("drives", drive);
2808
- if (document2 && isDocumentDrive(document2)) {
2809
- return document2;
2779
+ const cachedDocument = await this.cache.getDocument("drives", drive);
2780
+ if (cachedDocument && isDocumentDrive(cachedDocument)) {
2781
+ document = cachedDocument;
2782
+ if (isAtRevision(document, options?.revisions)) {
2783
+ return document;
2784
+ }
2810
2785
  }
2811
2786
  } catch (e) {
2812
2787
  logger.error("Error getting drive from cache", e);
2813
2788
  }
2814
- const driveStorage = await this.storage.getDrive(drive);
2815
- const document = this._buildDocument(driveStorage, options);
2816
- if (!isDocumentDrive(document)) {
2789
+ const driveStorage = document ?? await this.storage.getDrive(drive);
2790
+ const result = this._buildDocument(driveStorage, options);
2791
+ if (!isDocumentDrive(result)) {
2817
2792
  throw new Error(`Document with id ${drive} is not a Document Drive`);
2818
2793
  } else {
2819
- this.cache.setDocument("drives", drive, document).catch(logger.error);
2820
- return document;
2794
+ if (!options?.revisions) {
2795
+ this.cache.setDocument("drives", drive, result).catch(logger.error);
2796
+ }
2797
+ return result;
2821
2798
  }
2822
2799
  }
2823
2800
  async getDriveBySlug(slug, options) {
@@ -2839,17 +2816,20 @@ var BaseDocumentDriveServer = class extends AbstractDocumentDriveServer {
2839
2816
  }
2840
2817
  }
2841
2818
  async getDocument(drive, id, options) {
2819
+ let cachedDocument;
2842
2820
  try {
2843
- const document2 = await this.cache.getDocument(drive, id);
2844
- if (document2) {
2845
- return document2;
2821
+ cachedDocument = await this.cache.getDocument(drive, id);
2822
+ if (cachedDocument && isAtRevision(cachedDocument, options?.revisions)) {
2823
+ return cachedDocument;
2846
2824
  }
2847
2825
  } catch (e) {
2848
2826
  logger.error("Error getting document from cache", e);
2849
2827
  }
2850
- const documentStorage = await this.storage.getDocument(drive, id);
2828
+ const documentStorage = cachedDocument ?? await this.storage.getDocument(drive, id);
2851
2829
  const document = this._buildDocument(documentStorage, options);
2852
- this.cache.setDocument(drive, id, document).catch(logger.error);
2830
+ if (!options?.revisions) {
2831
+ this.cache.setDocument(drive, id, document).catch(logger.error);
2832
+ }
2853
2833
  return document;
2854
2834
  }
2855
2835
  getDocuments(drive) {
@@ -3008,7 +2988,7 @@ var BaseDocumentDriveServer = class extends AbstractDocumentDriveServer {
3008
2988
  };
3009
2989
  }
3010
2990
  _buildDocument(documentStorage, options) {
3011
- if (documentStorage.state && (!options || options.checkHashes === false)) {
2991
+ if (documentStorage.state && (!options || options.checkHashes === false) && isAtRevision(documentStorage, options?.revisions)) {
3012
2992
  return documentStorage;
3013
2993
  }
3014
2994
  const documentModel2 = this.getDocumentModel(documentStorage.documentType);
@@ -3742,15 +3722,6 @@ var BaseDocumentDriveServer = class extends AbstractDocumentDriveServer {
3742
3722
  }
3743
3723
  };
3744
3724
  var DocumentDriveServer = ReadModeServer(BaseDocumentDriveServer);
3745
-
3746
- // ../document-drive/src/storage/index.ts
3747
- init_esm_shims();
3748
-
3749
- // ../document-drive/src/storage/base.ts
3750
- init_esm_shims();
3751
-
3752
- // ../document-drive/src/storage/filesystem.ts
3753
- init_esm_shims();
3754
3725
  function ensureDir(dir) {
3755
3726
  if (!existsSync(dir)) {
3756
3727
  mkdirSync(dir, { recursive: true });
@@ -3947,12 +3918,6 @@ var FilesystemStorage = class _FilesystemStorage {
3947
3918
  }, []);
3948
3919
  }
3949
3920
  };
3950
-
3951
- // ../../node_modules/.pnpm/vite@6.0.2_@types+node@22.10.1_jiti@2.4.1_lightningcss@1.28.2_tsx@4.19.2_yaml@2.6.1/node_modules/vite/dist/node/index.js
3952
- init_esm_shims();
3953
- __toESM(require_main(), 1);
3954
-
3955
- // src/server.ts
3956
3921
  var dirname = import.meta.dirname || path2.dirname(fileURLToPath(import.meta.url));
3957
3922
  dotenv.config();
3958
3923
  var DefaultStartServerOptions = {
@@ -4006,42 +3971,17 @@ var startServer = async (options) => {
4006
3971
  }
4007
3972
  }
4008
3973
  try {
4009
- const client = new PGlite(options?.dbPath ?? process.cwd() + "/dev.db");
4010
- const { app, reactorRouterManager } = await startAPI(driveServer, {
3974
+ const api = await startAPI(driveServer, {
4011
3975
  port: serverPort,
4012
- client
3976
+ dbConnection: options?.dbPath ?? process.cwd() + "/dev.db"
4013
3977
  });
4014
3978
  driveUrl = `http://localhost:${serverPort}/${driveId ? `d/${drive.global.slug ?? drive.global.id}` : ""}`;
4015
3979
  console.log(` \u279C Reactor: ${driveUrl}`);
4016
3980
  if (dev) {
4017
- const vite = await createServer({
4018
- server: { middlewareMode: true },
4019
- appType: "custom",
4020
- build: {
4021
- rollupOptions: {
4022
- input: []
4023
- }
4024
- }
4025
- });
4026
- app.use(vite.middlewares);
4027
- const documentModelsPath = path2.join(process.cwd(), "./document-models");
4028
- console.log("Loading document models from", documentModelsPath);
4029
- const localDMs = await vite.ssrLoadModule(documentModelsPath);
4030
- driveServer.setDocumentModels([
4031
- ...baseDocumentModels,
4032
- ...Object.values(localDMs)
4033
- ]);
4034
- const processorsPath = path2.join(process.cwd(), "./processors");
4035
- console.log("Loading processors from", processorsPath);
4036
- const localProcessors = await vite.ssrLoadModule(processorsPath);
4037
- for (const [name, processor] of Object.entries(localProcessors)) {
4038
- await reactorRouterManager.registerProcessor({
4039
- ...processor
4040
- });
4041
- }
3981
+ await startDevMode(api, driveServer);
4042
3982
  }
4043
3983
  } catch (e) {
4044
- console.error("App crashed", e);
3984
+ console.error("Error starting API", e);
4045
3985
  }
4046
3986
  return {
4047
3987
  driveUrl,
@@ -4051,5 +3991,39 @@ var startServer = async (options) => {
4051
3991
  addListener: (driveId2, receiver, options2) => driveServer.addInternalListener(driveId2, receiver, options2)
4052
3992
  };
4053
3993
  };
3994
+ var startDevMode = async (api, driveServer) => {
3995
+ const vite = await createServer({
3996
+ server: { middlewareMode: true, watch: null },
3997
+ appType: "custom",
3998
+ build: {
3999
+ rollupOptions: {
4000
+ input: []
4001
+ }
4002
+ }
4003
+ });
4004
+ api.app.use(vite.middlewares);
4005
+ const documentModelsPath = path2.join(process.cwd(), "./document-models");
4006
+ await loadDocumentModels(documentModelsPath, vite, driveServer);
4007
+ const processorsPath = path2.join(process.cwd(), "./processors");
4008
+ await loadProcessors(processorsPath, vite, api.processorManager);
4009
+ };
4010
+ async function loadDocumentModels(path3, vite, driveServer) {
4011
+ console.log("Loading document models from", path3);
4012
+ const localDMs = await vite.ssrLoadModule(path3);
4013
+ driveServer.setDocumentModels([
4014
+ ...baseDocumentModels,
4015
+ ...Object.values(localDMs)
4016
+ ]);
4017
+ }
4018
+ async function loadProcessors(path3, vite, processorManager) {
4019
+ console.log("Loading processors from", path3);
4020
+ const localProcessors = await vite.ssrLoadModule(path3);
4021
+ for (const [name, processor] of Object.entries(localProcessors)) {
4022
+ const ProcessorClass = processor[name];
4023
+ if (isProcessorClass(ProcessorClass)) {
4024
+ await processorManager.registerProcessor(ProcessorClass);
4025
+ }
4026
+ }
4027
+ }
4054
4028
 
4055
4029
  export { DefaultStartServerOptions, startServer };
package/dist/cli.js CHANGED
@@ -1,12 +1,7 @@
1
1
  #! /usr/bin/env node
2
- import { startServer } from './chunk-4PQSXXV5.js';
3
- import './chunk-2CQEJHCK.js';
4
- import './chunk-XCBQEZL7.js';
5
- import { init_esm_shims } from './chunk-JKUWAFT3.js';
2
+ import { startServer } from './chunk-73W7YM3M.js';
6
3
  import { Command } from 'commander';
7
4
 
8
- // src/cli.ts
9
- init_esm_shims();
10
5
  var reactorLocalAction = (options) => {
11
6
  if (options.port) {
12
7
  process.env.PORT = options.port;
package/dist/index.js CHANGED
@@ -1,11 +1,7 @@
1
- import { startServer } from './chunk-4PQSXXV5.js';
2
- export { DefaultStartServerOptions, startServer } from './chunk-4PQSXXV5.js';
3
- import './chunk-2CQEJHCK.js';
4
- import './chunk-XCBQEZL7.js';
5
- import { init_esm_shims } from './chunk-JKUWAFT3.js';
1
+ import { startServer } from './chunk-73W7YM3M.js';
2
+ export { DefaultStartServerOptions, startServer } from './chunk-73W7YM3M.js';
6
3
 
7
4
  // src/index.ts
8
- init_esm_shims();
9
- startServer().catch((error) => {
5
+ startServer({ dev: true }).catch((error) => {
10
6
  throw error;
11
7
  });
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Trigger, PullResponderTriggerData, DocumentDriveState, DocumentDriveLocalState, ListenerFilter, ListenerCallInfo, DocumentDriveDocument, DocumentDriveAction } from 'document-model-libs/document-drive';
2
- import { Document, OperationScope, Operation, State, ActionContext, DocumentModel, Action, BaseAction, CreateChildDocumentInput, ReducerOptions, Signal } from 'document-model/document';
2
+ import { Operation, Document, OperationScope, State, ActionContext, DocumentModel, Action, BaseAction, CreateChildDocumentInput, ReducerOptions, Signal } from 'document-model/document';
3
3
  import { Unsubscribe } from 'nanoevents';
4
4
 
5
5
  type StrandUpdateSource = {
@@ -17,31 +17,6 @@ type PullResponderTrigger = Omit<Trigger, "data" | "type"> & {
17
17
  type: "PullResponder";
18
18
  };
19
19
 
20
- interface IReceiver {
21
- transmit: (strands: InternalTransmitterUpdate[]) => Promise<void>;
22
- disconnect: () => Promise<void>;
23
- }
24
- type InternalTransmitterUpdate<T extends Document = Document, S extends OperationScope = OperationScope> = {
25
- driveId: string;
26
- documentId: string;
27
- scope: S;
28
- branch: string;
29
- operations: OperationUpdate[];
30
- state: T["state"][S];
31
- };
32
- interface IInternalTransmitter extends ITransmitter {
33
- setReceiver(receiver: IReceiver): void;
34
- }
35
- declare class InternalTransmitter implements ITransmitter {
36
- private drive;
37
- private listener;
38
- private receiver;
39
- constructor(listener: Listener, drive: IBaseDocumentDriveServer);
40
- transmit(strands: InternalTransmitterUpdate[]): Promise<ListenerRevision[]>;
41
- setReceiver(receiver: IReceiver): void;
42
- disconnect(): Promise<void>;
43
- }
44
-
45
20
  declare class OperationError extends Error {
46
21
  status: ErrorStatus;
47
22
  operation: Operation | undefined;
@@ -59,6 +34,39 @@ type DriveInfo = {
59
34
  icon?: string;
60
35
  };
61
36
 
37
+ type InferDocumentOperation<D extends Document> = D extends Document<unknown, infer A> ? A : never;
38
+
39
+ interface IReceiver<T extends Document = Document, S extends OperationScope = OperationScope> {
40
+ onStrands: (strands: InternalTransmitterUpdate<T, S>[]) => Promise<void>;
41
+ onDisconnect: () => Promise<void>;
42
+ }
43
+ type InternalOperationUpdate<D extends Document = Document, S extends OperationScope = OperationScope> = Omit<Operation<InferDocumentOperation<D>>, "scope"> & {
44
+ state: D["state"][S];
45
+ previousState: D["state"][S];
46
+ };
47
+ type InternalTransmitterUpdate<D extends Document = Document, S extends OperationScope = OperationScope> = {
48
+ driveId: string;
49
+ documentId: string;
50
+ scope: S;
51
+ branch: string;
52
+ operations: InternalOperationUpdate<D, S>[];
53
+ state: D["state"][S];
54
+ };
55
+ interface IInternalTransmitter extends ITransmitter {
56
+ setReceiver(receiver: IReceiver): void;
57
+ }
58
+ declare class InternalTransmitter implements ITransmitter {
59
+ #private;
60
+ protected drive: IBaseDocumentDriveServer;
61
+ protected listener: Listener;
62
+ protected receiver: IReceiver | undefined;
63
+ constructor(listener: Listener, drive: IBaseDocumentDriveServer);
64
+ transmit(strands: StrandUpdate[], _source: StrandUpdateSource): Promise<ListenerRevision[]>;
65
+ setReceiver(receiver: IReceiver): void;
66
+ disconnect(): Promise<void>;
67
+ getListener(): Listener;
68
+ }
69
+
62
70
  type DriveInput = State<Omit<DocumentDriveState, "__typename" | "id" | "nodes"> & {
63
71
  id?: string;
64
72
  }, DocumentDriveLocalState>;
package/dist/server.js CHANGED
@@ -1,4 +1 @@
1
- export { DefaultStartServerOptions, startServer } from './chunk-4PQSXXV5.js';
2
- import './chunk-2CQEJHCK.js';
3
- import './chunk-XCBQEZL7.js';
4
- import './chunk-JKUWAFT3.js';
1
+ export { DefaultStartServerOptions, startServer } from './chunk-73W7YM3M.js';