@powerhousedao/reactor-api 1.19.0 → 1.20.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/reactor-api",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "author": "",
14
14
  "license": "AGPL-3.0-only",
15
15
  "devDependencies": {
16
- "@powerhousedao/analytics-engine-graphql": "^0.2.1",
16
+ "@powerhousedao/analytics-engine-graphql": "^0.2.2",
17
17
  "@types/body-parser": "^1.19.5",
18
18
  "@types/cors": "^2.8.17",
19
19
  "@types/express": "^5.0.0",
@@ -23,15 +23,15 @@
23
23
  "@types/pg": "^8.11.10",
24
24
  "esbuild": "^0.24.0",
25
25
  "graphql-tag": "^2.12.6",
26
- "@powerhousedao/scalars": "1.21.0",
27
- "document-drive": "1.16.2",
28
- "document-model": "2.18.0"
26
+ "@powerhousedao/scalars": "1.22.0",
27
+ "document-drive": "1.17.0",
28
+ "document-model": "2.19.0"
29
29
  },
30
30
  "dependencies": {
31
31
  "@apollo/server": "^4.11.0",
32
32
  "@apollo/subgraph": "^2.9.2",
33
33
  "@electric-sql/pglite": "^0.2.12",
34
- "@powerhousedao/analytics-engine-core": "^0.3.0",
34
+ "@powerhousedao/analytics-engine-core": "^0.3.2",
35
35
  "@powerhousedao/analytics-engine-knex": "^0.4.0",
36
36
  "body-parser": "^1.20.3",
37
37
  "cors": "^2.8.5",
@@ -51,7 +51,7 @@
51
51
  "uuid": "^9.0.1",
52
52
  "wildcard-match": "^5.1.3",
53
53
  "zod": "^3.24.1",
54
- "document-model-libs": "1.130.0"
54
+ "document-model-libs": "1.131.0"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsup",
package/src/server.ts CHANGED
@@ -7,12 +7,12 @@ import { IDocumentDriveServer } from "document-drive";
7
7
  import express, { Express } from "express";
8
8
  import fs from "node:fs";
9
9
  import https from "node:https";
10
+ import path from "node:path";
10
11
  import { Pool } from "pg";
11
- import { ProcessorManager } from "./processors";
12
+ import { IAnalyticsStore, ProcessorManager } from "./processors";
12
13
  import { SubgraphManager } from "./subgraphs/manager";
13
14
  import { API } from "./types";
14
15
  import { getDbClient } from "./utils/db";
15
- import path from "node:path";
16
16
 
17
17
  type Options = {
18
18
  express?: Express;
@@ -37,7 +37,7 @@ export async function startAPI(
37
37
  const analyticsStore = new KnexAnalyticsStore({
38
38
  executor: new KnexQueryExecutor(),
39
39
  knex: db,
40
- });
40
+ }) as unknown as IAnalyticsStore; // TODO update @powerhousedao/analytics-engine-pg to use @powerhousedao/analytics-engine-core@0.3.2
41
41
  const subgraphManager = new SubgraphManager(
42
42
  "/",
43
43
  app,
@@ -4,9 +4,9 @@ import jwt from "jsonwebtoken";
4
4
  import ms from "ms";
5
5
  import wildcard from "wildcard-match";
6
6
  import z from "zod";
7
- import { Session, SessionInput } from "../types";
8
- import { JWT_EXPIRATION_PERIOD, JWT_SECRET } from "../env";
9
7
  import { Db } from "../../../utils/db";
8
+ import { JWT_EXPIRATION_PERIOD, JWT_SECRET } from "../env";
9
+ import { Session, SessionInput } from "../types";
10
10
  const jwtSchema = z.object({
11
11
  sessionId: z.string(),
12
12
  exp: z.optional(z.number()),
@@ -13,28 +13,30 @@ import {
13
13
  ListenerFilter,
14
14
  TransmitterType,
15
15
  } from "document-model-libs/document-drive";
16
- import { Asset } from "./temp-hack-rwa-type-defs";
17
16
  import { BaseAction, Document, Operation } from "document-model/document";
18
17
  import {
19
18
  DocumentModelInput,
20
19
  DocumentModelState,
21
20
  } from "document-model/document-model";
22
21
  import { gql } from "graphql-tag";
23
- import { Context } from "../types";
24
22
  import { Subgraph } from "../base";
23
+ import { Context } from "../types";
24
+ import { Asset } from "./temp-hack-rwa-type-defs";
25
25
 
26
26
  export class DriveSubgraph extends Subgraph {
27
27
  name = "d/:drive";
28
28
  typeDefs = gql`
29
29
  type Query {
30
30
  system: System
31
- drive: DocumentDriveState
31
+ drive: DocumentDrive_DocumentDriveState
32
32
  document(id: String!): IDocument
33
33
  documents: [String!]!
34
34
  }
35
35
 
36
36
  type Mutation {
37
- registerPullResponderListener(filter: InputListenerFilter!): Listener
37
+ registerPullResponderListener(
38
+ filter: InputListenerFilter!
39
+ ): DocumentDrive_Listener
38
40
  pushUpdates(strands: [InputStrandUpdate!]): [ListenerRevision!]!
39
41
  acknowledge(
40
42
  listenerId: String!
@@ -15,7 +15,9 @@ export class SystemSubgraph extends Subgraph {
15
15
  }
16
16
 
17
17
  type Mutation {
18
- addDrive(global: DocumentDriveStateInput!): DocumentDriveState
18
+ addDrive(
19
+ global: DocumentDriveStateInput!
20
+ ): DocumentDrive_DocumentDriveState
19
21
  deleteDrive(id: ID!): Boolean
20
22
  setDriveIcon(id: String!, icon: String!): Boolean
21
23
  setDriveName(id: String!, name: String!): Boolean
@@ -25,13 +25,11 @@ export const getDocumentModelTypeDefs = (
25
25
  const documentModels = documentDriveServer.getDocumentModels();
26
26
  let dmSchema = "";
27
27
  documentModels.forEach(({ documentModel }) => {
28
- dmSchema += `
28
+ const dmSchemaName = documentModel.name.replaceAll(" ", "");
29
+ let tmpDmSchema = `
29
30
  ${documentModel.specifications
30
31
  .map((specification) =>
31
32
  specification.state.global.schema
32
- .replaceAll(" Account ", ` ${documentModel.name}Account `)
33
- .replaceAll(`: Account`, `: ${documentModel.name}Account`)
34
- .replaceAll(`[Account!]!`, `[${documentModel.name}Account!]!`)
35
33
  .replaceAll("scalar DateTime", "")
36
34
  .replaceAll(/input (.*?) {[\s\S]*?}/g, ""),
37
35
  )
@@ -40,9 +38,6 @@ export const getDocumentModelTypeDefs = (
40
38
  ${documentModel.specifications
41
39
  .map((specification) =>
42
40
  specification.state.local.schema
43
- .replaceAll(" Account ", ` ${documentModel.name}Account `)
44
- .replaceAll(`: Account`, `: ${documentModel.name}Account`)
45
- .replaceAll(`[Account!]!`, `[${documentModel.name}Account!]!`)
46
41
  .replaceAll("scalar DateTime", "")
47
42
  .replaceAll(/input (.*?) {[\s\S]*?}/g, "")
48
43
  .replaceAll("type AccountSnapshotLocalState", "")
@@ -51,7 +46,53 @@ export const getDocumentModelTypeDefs = (
51
46
  )
52
47
  .join("\n")};
53
48
 
54
- type ${documentModel.name} implements IDocument {
49
+ \n`;
50
+
51
+ const found = tmpDmSchema.match(/(type|enum|union)\s+(\w+)\s/g);
52
+ const trimmedFound = found?.map((f) =>
53
+ f
54
+ .replaceAll("type ", "")
55
+ .replaceAll("enum ", "")
56
+ .replaceAll("union ", "")
57
+ .trim(),
58
+ );
59
+ trimmedFound?.forEach((f) => {
60
+ // Create a regex that matches the type name with proper boundaries
61
+ const typeRegex = new RegExp(
62
+ // Match type references in various GraphQL contexts
63
+ `(?<![_A-Za-z0-9])(${f})(?![_A-Za-z0-9])|` + // Basic type references
64
+ `\\[(${f})\\]|` + // Array types without nullability
65
+ `\\[(${f})!\\]|` + // Array of non-null types
66
+ `\\[(${f})\\]!|` + // Non-null array of types
67
+ `\\[(${f})!\\]!`, // Non-null array of non-null types
68
+ "g",
69
+ );
70
+
71
+ tmpDmSchema = tmpDmSchema.replace(
72
+ typeRegex,
73
+ (
74
+ match: string,
75
+ p1: string,
76
+ p2: string,
77
+ p3: string,
78
+ p4: string,
79
+ p5: string,
80
+ ) => {
81
+ // If it's an array type, preserve the brackets and ! while replacing the type name
82
+ if (match.startsWith("[")) {
83
+ return match.replace(
84
+ p2 || p3 || p4 || p5,
85
+ `${dmSchemaName}_${p2 || p3 || p4 || p5}`,
86
+ );
87
+ }
88
+ // Basic type reference
89
+ return `${dmSchemaName}_${p1}`;
90
+ },
91
+ );
92
+ });
93
+ dmSchema += tmpDmSchema;
94
+ dmSchema += `
95
+ type ${dmSchemaName} implements IDocument {
55
96
  id: String!
56
97
  name: String!
57
98
  documentType: String!
@@ -59,8 +100,8 @@ export const getDocumentModelTypeDefs = (
59
100
  revision: Int!
60
101
  created: DateTime!
61
102
  lastModified: DateTime!
62
- ${documentModel.name !== "DocumentModel" ? `initialState: ${documentModel.name}State!` : ""}
63
- ${documentModel.name !== "DocumentModel" ? `state: ${documentModel.name}State!` : ""}
103
+ ${dmSchemaName !== "DocumentModel" ? `initialState: ${dmSchemaName}_${dmSchemaName}State!` : ""}
104
+ ${dmSchemaName !== "DocumentModel" ? `state: ${dmSchemaName}_${dmSchemaName}State!` : ""}
64
105
  }\n`;
65
106
  });
66
107