@powerhousedao/reactor-api 1.11.0 → 1.11.2

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,24 +1,9 @@
1
- ## 1.11.0 (2024-12-16)
2
-
3
- ### 🚀 Features
4
-
5
- - **reactor-api:** refactor knex and analytics store initialization ([2c19a7aa](https://github.com/powerhouse-inc/powerhouse/commit/2c19a7aa))
6
-
7
- ### 🩹 Fixes
8
-
9
- - **switchboard:** subgraph manager and db instantiation ([874bdc4b](https://github.com/powerhouse-inc/powerhouse/commit/874bdc4b))
10
- - **reactor-api:** datasource for analytics resolvers ([b015437e](https://github.com/powerhouse-inc/powerhouse/commit/b015437e))
11
- - **reactor-api:** build issues ([d0182d5d](https://github.com/powerhouse-inc/powerhouse/commit/d0182d5d))
1
+ ## 1.11.2 (2024-12-16)
12
2
 
13
3
  ### 🧱 Updated Dependencies
14
4
 
15
- - Updated document-model-libs to 1.122.6
16
- - Updated document-drive to 1.11.6
17
-
18
- ### ❤️ Thank You
19
-
20
- - acaldas @acaldas
21
- - Frank
5
+ - Updated document-model-libs to 1.122.8
6
+ - Updated document-drive to 1.11.8
22
7
 
23
8
  ## 1.2.0 (2024-10-29)
24
9
 
package/dist/index.d.ts CHANGED
@@ -359,10 +359,9 @@ declare namespace index$2 {
359
359
  }
360
360
 
361
361
  declare class DriveSubgraph extends Subgraph {
362
- #private;
363
362
  name: string;
364
363
  typeDefs: graphql.DocumentNode;
365
- onSetup(): Promise<void>;
364
+ resolvers: GraphQLResolverMap<Context>;
366
365
  }
367
366
 
368
367
  type index$1_DriveSubgraph = DriveSubgraph;
package/dist/index.js CHANGED
@@ -9957,6 +9957,7 @@ var ProcessorManager = class {
9957
9957
  )
9958
9958
  )
9959
9959
  );
9960
+ console.log(`> Registered ${options.label} processor.`);
9960
9961
  }
9961
9962
  async registerProcessor(module) {
9962
9963
  const args = {
@@ -29028,7 +29029,7 @@ index.documentHelpers;
29028
29029
  // ../document-drive/src/server/listener/transmitter/switchboard-push.ts
29029
29030
  __toESM(require_lib4());
29030
29031
  var DriveSubgraph = class extends Subgraph {
29031
- name = "drive/:driveId";
29032
+ name = "d/:drive";
29032
29033
  typeDefs = gql`
29033
29034
  type Query {
29034
29035
  system: System
@@ -29169,192 +29170,187 @@ var DriveSubgraph = class extends Subgraph {
29169
29170
  strands(listenerId: ID!, since: String): [StrandUpdate!]!
29170
29171
  }
29171
29172
  `;
29172
- async onSetup() {
29173
- await this.#setResolvers();
29174
- }
29175
- async #setResolvers() {
29176
- this.resolvers = {
29177
- Asset: {
29178
- __resolveType: (obj) => {
29179
- return obj.type;
29180
- }
29173
+ resolvers = {
29174
+ Asset: {
29175
+ __resolveType: (obj) => {
29176
+ return obj.type;
29177
+ }
29178
+ },
29179
+ Node: {
29180
+ __resolveType: (obj) => {
29181
+ return obj.documentType ? "FileNode" : "FolderNode";
29182
+ }
29183
+ },
29184
+ Query: {
29185
+ drive: async (_, args, ctx) => {
29186
+ if (!ctx.driveId) throw new Error("Drive ID is required");
29187
+ const drive = await this.reactor.getDrive(ctx.driveId);
29188
+ return drive.state.global;
29181
29189
  },
29182
- Node: {
29183
- __resolveType: (obj) => {
29184
- return obj.documentType ? "FileNode" : "FolderNode";
29185
- }
29190
+ documents: async (_, args, ctx) => {
29191
+ if (!ctx.driveId) throw new Error("Drive ID is required");
29192
+ const documents = await this.reactor.getDocuments(ctx.driveId);
29193
+ return documents;
29186
29194
  },
29187
- Query: {
29188
- drive: async (_, args, ctx) => {
29189
- if (!ctx.driveId) throw new Error("Drive ID is required");
29190
- const drive = await this.reactor.getDrive(ctx.driveId);
29191
- return drive.state.global;
29192
- },
29193
- documents: async (_, args, ctx) => {
29194
- if (!ctx.driveId) throw new Error("Drive ID is required");
29195
- const documents = await this.reactor.getDocuments(ctx.driveId);
29196
- return documents;
29197
- },
29198
- document: async (_, { id }, ctx) => {
29199
- if (!ctx.driveId) throw new Error("Drive ID is required");
29200
- const document = await this.reactor.getDocument(ctx.driveId, id);
29201
- const dms = this.reactor.getDocumentModels();
29202
- const dm = dms.find(
29203
- ({ documentModel: documentModel2 }) => documentModel2.id === document.documentType
29204
- );
29205
- const globalState = document.state.global;
29206
- if (!globalState) throw new Error("Document not found");
29207
- const response = {
29208
- ...document,
29209
- id,
29210
- revision: document.revision.global,
29211
- state: document.state.global,
29212
- operations: document.operations.global.map((op) => ({
29213
- ...op,
29214
- inputText: typeof op.input === "string" ? op.input : JSON.stringify(op.input)
29215
- })),
29216
- initialState: document.initialState.state.global,
29217
- __typename: dm?.documentModel.name
29218
- };
29219
- return response;
29220
- },
29221
- system: () => ({ sync: {} })
29195
+ document: async (_, { id }, ctx) => {
29196
+ if (!ctx.driveId) throw new Error("Drive ID is required");
29197
+ const document = await this.reactor.getDocument(ctx.driveId, id);
29198
+ const dms = this.reactor.getDocumentModels();
29199
+ const dm = dms.find(
29200
+ ({ documentModel: documentModel2 }) => documentModel2.id === document.documentType
29201
+ );
29202
+ const globalState = document.state.global;
29203
+ if (!globalState) throw new Error("Document not found");
29204
+ const response = {
29205
+ ...document,
29206
+ id,
29207
+ revision: document.revision.global,
29208
+ state: document.state.global,
29209
+ operations: document.operations.global.map((op) => ({
29210
+ ...op,
29211
+ inputText: typeof op.input === "string" ? op.input : JSON.stringify(op.input)
29212
+ })),
29213
+ initialState: document.initialState.state.global,
29214
+ __typename: dm?.documentModel.name
29215
+ };
29216
+ return response;
29222
29217
  },
29223
- Mutation: {
29224
- registerPullResponderListener: async (_, { filter }, ctx) => {
29225
- if (!ctx.driveId) throw new Error("Drive ID is required");
29226
- const uuid = generateUUID2();
29227
- const listener = {
29228
- block: false,
29229
- callInfo: {
29230
- data: "",
29231
- name: "PullResponder",
29232
- transmitterType: "PullResponder"
29233
- },
29234
- filter: {
29235
- branch: filter.branch ?? [],
29236
- documentId: filter.documentId ?? [],
29237
- documentType: filter.documentType ?? [],
29238
- scope: filter.scope ?? []
29239
- },
29240
- label: `Pullresponder #${uuid}`,
29241
- listenerId: uuid,
29242
- system: false
29243
- };
29244
- const result = await this.reactor.queueDriveAction(
29245
- ctx.driveId,
29246
- actions.addListener({ listener })
29218
+ system: () => ({ sync: {} })
29219
+ },
29220
+ Mutation: {
29221
+ registerPullResponderListener: async (_, { filter }, ctx) => {
29222
+ if (!ctx.driveId) throw new Error("Drive ID is required");
29223
+ const uuid = generateUUID2();
29224
+ const listener = {
29225
+ block: false,
29226
+ callInfo: {
29227
+ data: "",
29228
+ name: "PullResponder",
29229
+ transmitterType: "PullResponder"
29230
+ },
29231
+ filter: {
29232
+ branch: filter.branch ?? [],
29233
+ documentId: filter.documentId ?? [],
29234
+ documentType: filter.documentType ?? [],
29235
+ scope: filter.scope ?? []
29236
+ },
29237
+ label: `Pullresponder #${uuid}`,
29238
+ listenerId: uuid,
29239
+ system: false
29240
+ };
29241
+ const result = await this.reactor.queueDriveAction(
29242
+ ctx.driveId,
29243
+ actions.addListener({ listener })
29244
+ );
29245
+ if (result.status !== "SUCCESS" && result.error) {
29246
+ throw new Error(
29247
+ `Listener couldn't be registered: ${result.error.message}`
29247
29248
  );
29248
- if (result.status !== "SUCCESS" && result.error) {
29249
- throw new Error(
29250
- `Listener couldn't be registered: ${result.error.message}`
29251
- );
29252
- }
29253
- return listener;
29254
- },
29255
- pushUpdates: async (_, { strands }, ctx) => {
29256
- if (!ctx.driveId) throw new Error("Drive ID is required");
29257
- const listenerRevisions = await Promise.all(
29258
- strands.map(async (s2) => {
29259
- const operations = s2.operations.map((o) => ({
29260
- ...o,
29261
- input: JSON.parse(o.input),
29262
- skip: o.skip ?? 0,
29263
- scope: s2.scope,
29264
- branch: "main"
29265
- })) ?? [];
29266
- const result = await (s2.documentId !== void 0 ? this.reactor.queueOperations(
29267
- s2.driveId,
29268
- s2.documentId,
29269
- operations
29270
- ) : this.reactor.queueDriveOperations(
29271
- s2.driveId,
29272
- operations
29273
- ));
29274
- const scopeOperations = result.document?.operations[s2.scope] ?? [];
29275
- if (scopeOperations.length === 0) {
29276
- return {
29277
- revision: -1,
29278
- branch: s2.branch,
29279
- documentId: s2.documentId ?? "",
29280
- driveId: s2.driveId,
29281
- scope: s2.scope,
29282
- status: result.status
29283
- };
29284
- }
29285
- const revision = scopeOperations.slice().pop()?.index ?? -1;
29249
+ }
29250
+ return listener;
29251
+ },
29252
+ pushUpdates: async (_, { strands }, ctx) => {
29253
+ if (!ctx.driveId) throw new Error("Drive ID is required");
29254
+ const listenerRevisions = await Promise.all(
29255
+ strands.map(async (s2) => {
29256
+ const operations = s2.operations.map((o) => ({
29257
+ ...o,
29258
+ input: JSON.parse(o.input),
29259
+ skip: o.skip ?? 0,
29260
+ scope: s2.scope,
29261
+ branch: "main"
29262
+ })) ?? [];
29263
+ const result = await (s2.documentId !== void 0 ? this.reactor.queueOperations(
29264
+ s2.driveId,
29265
+ s2.documentId,
29266
+ operations
29267
+ ) : this.reactor.queueDriveOperations(
29268
+ s2.driveId,
29269
+ operations
29270
+ ));
29271
+ const scopeOperations = result.document?.operations[s2.scope] ?? [];
29272
+ if (scopeOperations.length === 0) {
29286
29273
  return {
29287
- revision,
29274
+ revision: -1,
29288
29275
  branch: s2.branch,
29289
29276
  documentId: s2.documentId ?? "",
29290
29277
  driveId: s2.driveId,
29291
29278
  scope: s2.scope,
29292
- status: result.status,
29293
- error: result.error?.message || void 0
29279
+ status: result.status
29294
29280
  };
29295
- })
29296
- );
29297
- return listenerRevisions;
29298
- },
29299
- acknowledge: async (_, {
29300
- listenerId,
29301
- revisions
29302
- }, ctx) => {
29303
- if (!listenerId || !revisions) return false;
29304
- if (!ctx.driveId) throw new Error("Drive ID is required");
29305
- const validEntries = revisions.filter((r) => r !== null).map((e) => ({
29306
- driveId: e.driveId,
29307
- documentId: e.documentId,
29308
- scope: e.scope,
29309
- branch: e.branch,
29310
- revision: e.revision,
29311
- status: e.status
29312
- }));
29313
- const transmitter = await this.reactor.getTransmitter(
29314
- ctx.driveId,
29315
- listenerId
29316
- );
29317
- const result = await transmitter.processAcknowledge(
29318
- ctx.driveId ?? "1",
29319
- listenerId,
29320
- validEntries
29321
- );
29322
- return result;
29323
- }
29281
+ }
29282
+ const revision = scopeOperations.slice().pop()?.index ?? -1;
29283
+ return {
29284
+ revision,
29285
+ branch: s2.branch,
29286
+ documentId: s2.documentId ?? "",
29287
+ driveId: s2.driveId,
29288
+ scope: s2.scope,
29289
+ status: result.status,
29290
+ error: result.error?.message || void 0
29291
+ };
29292
+ })
29293
+ );
29294
+ return listenerRevisions;
29324
29295
  },
29325
- System: {},
29326
- Sync: {
29327
- strands: async (_, {
29296
+ acknowledge: async (_, {
29297
+ listenerId,
29298
+ revisions
29299
+ }, ctx) => {
29300
+ if (!listenerId || !revisions) return false;
29301
+ if (!ctx.driveId) throw new Error("Drive ID is required");
29302
+ const validEntries = revisions.filter((r) => r !== null).map((e) => ({
29303
+ driveId: e.driveId,
29304
+ documentId: e.documentId,
29305
+ scope: e.scope,
29306
+ branch: e.branch,
29307
+ revision: e.revision,
29308
+ status: e.status
29309
+ }));
29310
+ const transmitter = await this.reactor.getTransmitter(
29311
+ ctx.driveId,
29312
+ listenerId
29313
+ );
29314
+ const result = await transmitter.processAcknowledge(
29315
+ ctx.driveId ?? "1",
29328
29316
  listenerId,
29329
- since
29330
- }, ctx) => {
29331
- if (!ctx.driveId) throw new Error("Drive ID is required");
29332
- const listener = await this.reactor.getTransmitter(
29333
- ctx.driveId,
29334
- listenerId
29335
- );
29336
- const strands = await listener.getStrands({ since });
29337
- return strands.map((e) => ({
29338
- driveId: e.driveId,
29339
- documentId: e.documentId,
29340
- scope: e.scope,
29341
- branch: e.branch,
29342
- operations: e.operations.map((o) => ({
29343
- index: o.index,
29344
- skip: o.skip,
29345
- name: o.type,
29346
- input: JSON.stringify(o.input),
29347
- hash: o.hash,
29348
- timestamp: o.timestamp,
29349
- type: o.type,
29350
- context: o.context,
29351
- id: o.id
29352
- }))
29353
- }));
29354
- }
29317
+ validEntries
29318
+ );
29319
+ return result;
29355
29320
  }
29356
- };
29357
- }
29321
+ },
29322
+ System: {},
29323
+ Sync: {
29324
+ strands: async (_, {
29325
+ listenerId,
29326
+ since
29327
+ }, ctx) => {
29328
+ if (!ctx.driveId) throw new Error("Drive ID is required");
29329
+ const listener = await this.reactor.getTransmitter(
29330
+ ctx.driveId,
29331
+ listenerId
29332
+ );
29333
+ const strands = await listener.getStrands({ since });
29334
+ return strands.map((e) => ({
29335
+ driveId: e.driveId,
29336
+ documentId: e.documentId,
29337
+ scope: e.scope,
29338
+ branch: e.branch,
29339
+ operations: e.operations.map((o) => ({
29340
+ index: o.index,
29341
+ skip: o.skip,
29342
+ name: o.type,
29343
+ input: JSON.stringify(o.input),
29344
+ hash: o.hash,
29345
+ timestamp: o.timestamp,
29346
+ type: o.type,
29347
+ context: o.context,
29348
+ id: o.id
29349
+ }))
29350
+ }));
29351
+ }
29352
+ }
29353
+ };
29358
29354
  };
29359
29355
 
29360
29356
  // src/subgraphs/system/index.ts
@@ -29487,6 +29483,7 @@ var SubgraphManager = class {
29487
29483
  reactor: this.reactor,
29488
29484
  subgraphManager: this
29489
29485
  });
29486
+ await subgraphInstance.onSetup();
29490
29487
  this.subgraphs.unshift(subgraphInstance);
29491
29488
  console.log(`> Registered ${subgraphInstance.name} subgraph.`);
29492
29489
  await this.updateRouter();