@powerhousedao/codegen 3.3.0-dev.14 → 3.3.0-dev.15

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.
@@ -7,6 +7,7 @@ force: true
7
7
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
8
8
  import { type Subgraph } from "@powerhousedao/reactor-api";
9
9
  import { addFile } from "document-drive";
10
+ import { DocumentNotFoundError } from "document-drive/server/error";
10
11
  import { actions } from "../../document-models/<%- h.changeCase.param(documentType) %>/index.js";
11
12
  import { generateId } from "document-model";
12
13
 
@@ -23,9 +24,14 @@ export const getResolvers = (subgraph: Subgraph): Record<string, any> => {
23
24
  const driveId: string = args.driveId || DEFAULT_DRIVE_ID;
24
25
  const docId: string = args.docId || "";
25
26
  const doc = await reactor.getDocument(driveId, docId);
26
- return {
27
+ if (!doc) {
28
+ throw new DocumentNotFoundError(docId);
29
+ }
30
+
31
+ return {
27
32
  driveId: driveId,
28
33
  ...doc,
34
+ ...doc.header,
29
35
  state: doc.state.global,
30
36
  stateJSON: doc.state.global,
31
37
  revision: doc.header.revision["global"] ?? 0,
@@ -34,12 +40,21 @@ export const getResolvers = (subgraph: Subgraph): Record<string, any> => {
34
40
  getDocuments: async (args: any) => {
35
41
  const driveId: string = args.driveId || DEFAULT_DRIVE_ID;
36
42
  const docsIds = await reactor.getDocuments(driveId);
43
+ if (!docsIds) {
44
+ throw new DocumentNotFoundError(driveId);
45
+ }
46
+
37
47
  const docs = await Promise.all(
38
48
  docsIds.map(async (docId) => {
39
49
  const doc = await reactor.getDocument(driveId, docId);
50
+ if (!doc) {
51
+ return null;
52
+ }
53
+
40
54
  return {
41
55
  driveId: driveId,
42
56
  ...doc,
57
+ ...doc.header,
43
58
  state: doc.state.global,
44
59
  stateJSON: doc.state.global,
45
60
  revision: doc.header.revision["global"] ?? 0,
@@ -48,7 +63,7 @@ export const getResolvers = (subgraph: Subgraph): Record<string, any> => {
48
63
  );
49
64
 
50
65
  return docs.filter(
51
- (doc) => doc.header.documentType === "<%- documentTypeId %>",
66
+ (doc) => doc && doc.header.documentType === "<%- documentTypeId %>",
52
67
  );
53
68
  },
54
69
  };
@@ -88,6 +103,9 @@ export const getResolvers = (subgraph: Subgraph): Record<string, any> => {
88
103
  const driveId: string = args.driveId || DEFAULT_DRIVE_ID;
89
104
  const docId: string = args.docId || "";
90
105
  const doc = await reactor.getDocument(driveId, docId);
106
+ if (!doc) {
107
+ throw new DocumentNotFoundError(docId);
108
+ }
91
109
 
92
110
  await reactor.addAction(
93
111
  driveId,
@@ -13,19 +13,20 @@ import { type ProcessorRecord, type IProcessorHostModule } from "document-drive/
13
13
 
14
14
  export const processorFactory = (module: IProcessorHostModule) => {
15
15
  // Initialize all processor factories once with the module
16
- const factories: Array<(driveId: string) => ProcessorRecord[]> = [];
16
+ const factories: Array<(driveId: string) => Promise<ProcessorRecord[]>> = [];
17
17
 
18
18
  // Add all processor factories
19
19
 
20
20
  // Add other processors here as they are generated
21
21
 
22
22
  // Return the inner function that will be called for each drive
23
- return (driveId: string): ProcessorRecord[] => {
23
+ return async (driveId: string): Promise<ProcessorRecord[]> => {
24
24
  const processors: ProcessorRecord[] = [];
25
25
 
26
26
  // Call each cached factory with the driveId
27
27
  for (const factory of factories) {
28
- processors.push(...factory(driveId));
28
+ const factoryProcessors = await factory(driveId);
29
+ processors.push(...factoryProcessors);
29
30
  }
30
31
 
31
32
  return processors;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/codegen",
3
- "version": "3.3.0-dev.14",
3
+ "version": "3.3.0-dev.15",
4
4
  "license": "AGPL-3.0-only",
5
5
  "private": false,
6
6
  "type": "module",
@@ -33,8 +33,8 @@
33
33
  "kysely": "^0.28.2",
34
34
  "kysely-pglite": "^0.6.1",
35
35
  "prettier": "^3.4.2",
36
- "@powerhousedao/config": "3.3.0-dev.14",
37
- "document-model": "3.3.0-dev.14"
36
+ "@powerhousedao/config": "3.3.0-dev.15",
37
+ "document-model": "3.3.0-dev.15"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@graphql-codegen/core": "^4.0.2",
@@ -44,8 +44,8 @@
44
44
  "husky": "^8.0.3",
45
45
  "vitest": "^3.1.2",
46
46
  "zod": "^3.24.3",
47
- "document-drive": "3.3.0-dev.14",
48
- "@powerhousedao/reactor-api": "3.3.0-dev.14"
47
+ "document-drive": "3.3.0-dev.15",
48
+ "@powerhousedao/reactor-api": "3.3.0-dev.15"
49
49
  },
50
50
  "scripts": {
51
51
  "build:tsc": "tsc --build",