@powerhousedao/codegen 6.0.0-dev.109 → 6.0.0-dev.110

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.
Files changed (153) hide show
  1. package/dist/src/codegen/__tests__/config.d.ts +0 -1
  2. package/dist/src/codegen/__tests__/config.d.ts.map +1 -1
  3. package/dist/src/codegen/__tests__/config.js +0 -1
  4. package/dist/src/codegen/__tests__/config.js.map +1 -1
  5. package/dist/src/codegen/__tests__/generate-doc-model.test.js +0 -1
  6. package/dist/src/codegen/__tests__/generate-doc-model.test.js.map +1 -1
  7. package/dist/src/codegen/__tests__/generate-drive-editor.test.js +0 -5
  8. package/dist/src/codegen/__tests__/generate-drive-editor.test.js.map +1 -1
  9. package/dist/src/codegen/__tests__/generate-editor.test.js +0 -4
  10. package/dist/src/codegen/__tests__/generate-editor.test.js.map +1 -1
  11. package/dist/src/codegen/__tests__/generate-processor.test.js +0 -1
  12. package/dist/src/codegen/__tests__/generate-processor.test.js.map +1 -1
  13. package/dist/src/codegen/__tests__/generate-subgraph.test.d.ts +2 -0
  14. package/dist/src/codegen/__tests__/generate-subgraph.test.d.ts.map +1 -0
  15. package/dist/src/codegen/__tests__/generate-subgraph.test.js +197 -0
  16. package/dist/src/codegen/__tests__/generate-subgraph.test.js.map +1 -0
  17. package/dist/src/codegen/generate.d.ts +10 -17
  18. package/dist/src/codegen/generate.d.ts.map +1 -1
  19. package/dist/src/codegen/generate.js +38 -101
  20. package/dist/src/codegen/generate.js.map +1 -1
  21. package/dist/src/codegen/index.d.ts +0 -1
  22. package/dist/src/codegen/index.d.ts.map +1 -1
  23. package/dist/src/codegen/index.js +0 -1
  24. package/dist/src/codegen/index.js.map +1 -1
  25. package/dist/src/file-builders/index.d.ts +1 -0
  26. package/dist/src/file-builders/index.d.ts.map +1 -1
  27. package/dist/src/file-builders/index.js +1 -0
  28. package/dist/src/file-builders/index.js.map +1 -1
  29. package/dist/src/file-builders/subgraph.d.ts +10 -0
  30. package/dist/src/file-builders/subgraph.d.ts.map +1 -0
  31. package/dist/src/file-builders/subgraph.js +121 -0
  32. package/dist/src/file-builders/subgraph.js.map +1 -0
  33. package/dist/src/templates/index.d.ts +1 -0
  34. package/dist/src/templates/index.d.ts.map +1 -1
  35. package/dist/src/templates/index.js +1 -0
  36. package/dist/src/templates/index.js.map +1 -1
  37. package/dist/src/templates/subgraphs/custom-resolvers.d.ts +5 -0
  38. package/dist/src/templates/subgraphs/custom-resolvers.d.ts.map +1 -0
  39. package/dist/src/{codegen/.hygen/templates/powerhouse/generate-custom-subgraph/resolvers.esm.t → templates/subgraphs/custom-resolvers.js} +6 -6
  40. package/dist/src/templates/subgraphs/custom-resolvers.js.map +1 -0
  41. package/dist/src/templates/subgraphs/custom-schema.d.ts +5 -0
  42. package/dist/src/templates/subgraphs/custom-schema.d.ts.map +1 -0
  43. package/dist/src/templates/subgraphs/custom-schema.js +20 -0
  44. package/dist/src/templates/subgraphs/custom-schema.js.map +1 -0
  45. package/dist/src/templates/subgraphs/document-model-resolvers.d.ts +15 -0
  46. package/dist/src/templates/subgraphs/document-model-resolvers.d.ts.map +1 -0
  47. package/dist/src/{codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/resolvers.esm.t → templates/subgraphs/document-model-resolvers.js} +55 -47
  48. package/dist/src/templates/subgraphs/document-model-resolvers.js.map +1 -0
  49. package/dist/src/templates/subgraphs/document-model-schema.d.ts +12 -0
  50. package/dist/src/templates/subgraphs/document-model-schema.d.ts.map +1 -0
  51. package/dist/src/templates/subgraphs/document-model-schema.js +54 -0
  52. package/dist/src/templates/subgraphs/document-model-schema.js.map +1 -0
  53. package/dist/src/templates/subgraphs/index-file.d.ts +5 -0
  54. package/dist/src/templates/subgraphs/index-file.d.ts.map +1 -0
  55. package/dist/src/{codegen/.hygen/templates/powerhouse/generate-subgraph/index.esm.t → templates/subgraphs/index-file.js} +7 -7
  56. package/dist/src/templates/subgraphs/index-file.js.map +1 -0
  57. package/dist/src/templates/subgraphs/index.d.ts +7 -0
  58. package/dist/src/templates/subgraphs/index.d.ts.map +1 -0
  59. package/dist/src/templates/subgraphs/index.js +7 -0
  60. package/dist/src/templates/subgraphs/index.js.map +1 -0
  61. package/dist/src/templates/subgraphs/lib-file.d.ts +2 -0
  62. package/dist/src/templates/subgraphs/lib-file.d.ts.map +1 -0
  63. package/dist/src/templates/subgraphs/lib-file.js +8 -0
  64. package/dist/src/templates/subgraphs/lib-file.js.map +1 -0
  65. package/dist/src/utils/cli.d.ts +0 -6
  66. package/dist/src/utils/cli.d.ts.map +1 -1
  67. package/dist/src/utils/cli.js +0 -18
  68. package/dist/src/utils/cli.js.map +1 -1
  69. package/dist/src/utils/graphql-type-prefixes.d.ts +10 -0
  70. package/dist/src/utils/graphql-type-prefixes.d.ts.map +1 -0
  71. package/dist/src/utils/graphql-type-prefixes.js +51 -0
  72. package/dist/src/utils/graphql-type-prefixes.js.map +1 -0
  73. package/dist/src/utils/index.d.ts +1 -0
  74. package/dist/src/utils/index.d.ts.map +1 -1
  75. package/dist/src/utils/index.js +1 -0
  76. package/dist/src/utils/index.js.map +1 -1
  77. package/dist/tsconfig.tsbuildinfo +1 -1
  78. package/package.json +9 -18
  79. package/dist/src/codegen/.hygen/package.json +0 -6
  80. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.js +0 -10
  81. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/schema.esm.t +0 -20
  82. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/actions.esm.t +0 -16
  83. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/creators.esm.t +0 -9
  84. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/customUtils.esm.t +0 -5
  85. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/document-schema.esm.t +0 -56
  86. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/document-type.esm.t +0 -6
  87. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModel.esm.t +0 -7
  88. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModelTest.esm.t +0 -121
  89. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/hooks.esm.t +0 -49
  90. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.esm.t +0 -23
  91. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.js +0 -127
  92. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/module.esm.t +0 -22
  93. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/ph-factories.esm.t +0 -93
  94. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +0 -46
  95. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/root-utils.esm.t +0 -11
  96. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootActions.esm.t +0 -13
  97. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootIndex.esm.t +0 -14
  98. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/schema.esm.t +0 -6
  99. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/src-index.esm.t +0 -5
  100. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +0 -31
  101. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +0 -77
  102. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/actions.esm.t +0 -22
  103. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/creators.esm.t +0 -37
  104. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t +0 -44
  105. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t +0 -36
  106. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +0 -71
  107. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/operations.esm.t +0 -17
  108. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/index.js +0 -119
  109. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t +0 -44
  110. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/CreateDocument.esm.t +0 -58
  111. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveContents.esm.t +0 -23
  112. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +0 -32
  113. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EmptyState.esm.t +0 -19
  114. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/Files.esm.t +0 -29
  115. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderTree.esm.t +0 -108
  116. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/Folders.esm.t +0 -28
  117. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/NavigationBreadcrumbs.esm.t +0 -14
  118. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/config.esm.t +0 -11
  119. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +0 -20
  120. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js +0 -25
  121. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/module.esm.t +0 -15
  122. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +0 -80
  123. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +0 -90
  124. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/module.esm.t +0 -16
  125. package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.esm.t +0 -59
  126. package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.js +0 -9
  127. package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/utils.esm.t +0 -100
  128. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/factory.esm.t +0 -22
  129. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.esm.t +0 -62
  130. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.js +0 -12
  131. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.root.esm.t +0 -10
  132. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.root.inject.esm.t +0 -12
  133. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.esm.t +0 -34
  134. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_call.esm.t +0 -7
  135. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_export.esm.t +0 -7
  136. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_import.esm.t +0 -7
  137. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/factory.esm.t +0 -40
  138. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.esm.t +0 -47
  139. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.js +0 -12
  140. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.root.esm.t +0 -10
  141. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.root.inject.esm.t +0 -12
  142. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.esm.t +0 -34
  143. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_call.esm.t +0 -7
  144. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_export.esm.t +0 -9
  145. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_import.esm.t +0 -7
  146. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/migrations.esm.t +0 -23
  147. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/schema.esm.t +0 -13
  148. package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.js +0 -10
  149. package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/lib.esm.t +0 -9
  150. package/dist/src/codegen/hygen.d.ts +0 -47
  151. package/dist/src/codegen/hygen.d.ts.map +0 -1
  152. package/dist/src/codegen/hygen.js +0 -230
  153. package/dist/src/codegen/hygen.js.map +0 -1
@@ -1,46 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/reducer.ts"
3
- force: true
4
- ---
5
- // TODO: remove eslint-disable rules once refactor is done
6
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
7
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
8
- import type { StateReducer } from "document-model";
9
- import { isDocumentAction, createReducer } from "document-model/core";
10
- import type { <%= phStateName %> } from "<%= documentModelDir %>";
11
-
12
- <% modules.forEach(module => { _%>
13
- import { <%= camelCaseDocumentType %><%= h.changeCase.pascal(module.name) %>Operations } from "../src/reducers/<%= h.changeCase.param(module.name) %>.js";
14
- <%_ }); %>
15
-
16
- <% const schemas = modules.flatMap(m =>
17
- m.operations.map(o => `${h.changeCase.pascalCase(o.name)}InputSchema`)
18
- );
19
- %>
20
- import {
21
- <%= schemas.join(',\n ') %>
22
- } from "./schema/zod.js";
23
-
24
- const stateReducer: StateReducer<<%= phStateName %>> =
25
- (state, action, dispatch) => {
26
- if (isDocumentAction(action)) {
27
- return state;
28
- }
29
-
30
- switch (action.type) {
31
- <%-
32
- modules.map(m => m.operations.map(o =>
33
- ' case "' + h.changeCase.constant(o.name) + '":\n' +
34
- ' ' + (o.schema !== null ?
35
- h.changeCase.pascalCase(o.name) + 'InputSchema().parse(action.input);\n' :
36
- 'if (Object.keys(action.input).length > 0) throw new Error("Expected empty input for action ' + h.changeCase.constant(o.name) + '");\n') +
37
- ' ' + camelCaseDocumentType + h.changeCase.pascal(m.name) + 'Operations.' + h.changeCase.camel(o.name) + 'Operation((state as any)[action.scope], action as any, dispatch);\n' +
38
- ' break;\n'
39
- ).join('\n')).join('\n')
40
- %>
41
- default:
42
- return state;
43
- }
44
- }
45
-
46
- export const reducer = createReducer<<%= phStateName %>>(stateReducer);
@@ -1,11 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= paramCaseDocumentType %>/utils.ts"
3
- force: true
4
- ---
5
- import type { DocumentModelUtils } from "document-model";
6
- import type { <%= phStateName %> } from "./gen/types.js";
7
- import { utils as genUtils } from "./gen/utils.js";
8
- import * as customUtils from "./src/utils.js";
9
-
10
- /** Utils for the <%= pascalCaseDocumentType %> document model */
11
- export const utils = { ...genUtils, ...customUtils } satisfies DocumentModelUtils<<%= phStateName %>>;
@@ -1,13 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= paramCaseDocumentType %>/actions.ts"
3
- force: true
4
- ---
5
- import { baseActions } from "document-model";
6
- import { <% modules.forEach(module => { _%>
7
- <%= h.changeCase.camel(module.name) %>Actions,
8
- <% }); _%> } from "./gen/creators.js";
9
-
10
- /** Actions for the <%= pascalCaseDocumentType %> document model */
11
- export const actions = { ...baseActions, <% modules.forEach(module => { _%>
12
- ...<%= h.changeCase.camel(module.name) %>Actions,
13
- <% }); _%> };
@@ -1,14 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= paramCaseDocumentType %>/index.ts"
3
- force: true
4
- ---
5
- /**
6
- * This is a scaffold file meant for customization.
7
- * Delete the file and run the code generator again to have it reset
8
- */
9
-
10
- export * from "./gen/index.js";
11
- export * from "./src/index.js";
12
- export * from "./hooks.js";
13
- export { actions } from "./actions.js";
14
- export { utils } from "./utils.js";
@@ -1,6 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/schema/index.ts"
3
- force: true
4
- ---
5
- export * from "./types.js";
6
- export * from "./zod.js";
@@ -1,5 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= paramCaseDocumentType %>/src/index.ts"
3
- force: true
4
- ---
5
- export * from "./utils.js";
@@ -1,31 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/types.ts"
3
- force: true
4
- ---
5
- import type { PHDocument, PHBaseState } from 'document-model';
6
- import type { <%= actionTypeName %> } from './actions.js';
7
- import type {
8
- <%= stateName %> as <%= globalStateName %>,
9
- <% if(hasLocalSchema) { -%>
10
- <%= localStateName %>,
11
- <%} -%>
12
- } from './schema/types.js';
13
-
14
- <% if(!hasLocalSchema) { -%>
15
- <%= 'type ' + localStateName %> = Record<PropertyKey, never>;
16
- <%} -%>
17
- type <%= phStateName %> = PHBaseState & {
18
- global: <%= globalStateName %>;
19
- local: <%= localStateName %>;
20
- };
21
- type <%= phDocumentTypeName %> = PHDocument<<%= phStateName %>>;
22
-
23
- export * from './schema/types.js';
24
-
25
- export type {
26
- <%= globalStateName %>,
27
- <%= localStateName %>,
28
- <%= phStateName %>,
29
- <%= actionTypeName %>,
30
- <%= phDocumentTypeName %>,
31
- };
@@ -1,77 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/utils.ts"
3
- force: true
4
- ---
5
- import type {
6
- DocumentModelUtils,
7
- } from "document-model";
8
- import {
9
- baseCreateDocument,
10
- baseSaveToFileHandle,
11
- baseLoadFromInput,
12
- defaultBaseState,
13
- generateId,
14
- } from 'document-model/core';
15
- import type {
16
- <%= globalStateName %>,
17
- <%= localStateName %>
18
- } from './types.js';
19
- import type { <%= phStateName %> } from './types.js';
20
- import { reducer } from './reducer.js';
21
- import { <%= documentTypeVariableName %> } from "./document-type.js";
22
- import {
23
- <%= isPhDocumentOfTypeFunctionName %>,
24
- <%= assertIsPhDocumentOfTypeFunctionName %>,
25
- <%= isPhStateOfTypeFunctionName %>,
26
- <%= assertIsPhStateOfTypeFunctionName %>,
27
- } from "./document-schema.js";
28
-
29
- export const initialGlobalState: <%= globalStateName %> = <%- initialGlobalState %>;
30
- export const initialLocalState: <%= localStateName %> = <%- initialLocalState %>;
31
-
32
- export const utils: DocumentModelUtils<<%= phStateName %>> = {
33
- fileExtension: '<%- fileExtension %>',
34
- createState(state) {
35
- return { ...defaultBaseState(), global: { ...initialGlobalState, ...state?.global }, local: { ...initialLocalState, ...state?.local } };
36
- },
37
- createDocument(state) {
38
- const document = baseCreateDocument(
39
- utils.createState,
40
- state
41
- );
42
-
43
- document.header.documentType = <%= documentTypeVariableName %>;
44
-
45
- // for backwards compatibility, but this is NOT a valid signed document id
46
- document.header.id = generateId();
47
-
48
- return document;
49
- },
50
- saveToFileHandle(document, input) {
51
- return baseSaveToFileHandle(document, input);
52
- },
53
- loadFromInput(input) {
54
- return baseLoadFromInput(input, reducer);
55
- },
56
- isStateOfType(state) {
57
- return <%= isPhStateOfTypeFunctionName %>(state);
58
- },
59
- assertIsStateOfType(state) {
60
- return <%= assertIsPhStateOfTypeFunctionName %>(state);
61
- },
62
- isDocumentOfType(document) {
63
- return <%= isPhDocumentOfTypeFunctionName %>(document);
64
- },
65
- assertIsDocumentOfType(document) {
66
- return <%= assertIsPhDocumentOfTypeFunctionName %>(document);
67
- },
68
- };
69
-
70
- export const createDocument = utils.createDocument;
71
- export const createState = utils.createState;
72
- export const saveToFileHandle = utils.saveToFileHandle;
73
- export const loadFromInput = utils.loadFromInput;
74
- export const isStateOfType = utils.isStateOfType;
75
- export const assertIsStateOfType = utils.assertIsStateOfType;
76
- export const isDocumentOfType = utils.isDocumentOfType;
77
- export const assertIsDocumentOfType = utils.assertIsDocumentOfType;
@@ -1,22 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/actions.ts"
3
- force: true
4
- ---
5
- import { type Action<% if (actions.find(a => a.hasAttachment)) {%>, ActionWithAttachment<%}%> } from 'document-model';
6
- import type {
7
- <% actions.filter(a => a.hasInput).forEach(action => { _%>
8
- <%= h.changeCase.pascal(action.name) %>Input,
9
- <% }); _%>
10
- } from '../types.js';
11
-
12
- <% actions.filter(a => a.hasInput).forEach(actionType => { _%>
13
- export <%= 'type ' + h.changeCase.pascal(actionType.name) %>Action = <%if(actionType.hasAttachment){ %>ActionWithAttachment<% } else { %>Action<% } %> & { type: '<%= h.changeCase.constantCase(actionType.name) %>'; input: <%= h.changeCase.pascal(actionType.name) %>Input };
14
- <% }); _%>
15
- <% actions.filter(a => !a.hasInput).forEach(actionType => { _%>
16
- export <%= 'type ' + h.changeCase.pascal(actionType.name) %>Action = Action & { type: '<%= h.changeCase.constantCase(actionType.name) %>'; input: {} };
17
- <% }); _%>
18
-
19
- export <%= 'type ' + h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module) %>Action =
20
- <% actions.forEach(actionType => { _%>
21
- | <%= h.changeCase.pascal(actionType.name) %>Action
22
- <% }); _%>;
@@ -1,37 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/creators.ts"
3
- force: true
4
- ---
5
- import { createAction<% if (actions.find(a => a.hasAttachment)) {%>, AttachmentInput<%}%> } from 'document-model/core';
6
- import {
7
- <% actions.filter(a => a.hasInput).forEach(action => { _%>
8
- <%= h.changeCase.pascal(action.name) %>InputSchema,
9
- <% }); _%>
10
- } from '../schema/zod.js';
11
- import type {
12
- <% actions.filter(a => a.hasInput).forEach(action => { _%>
13
- <%= h.changeCase.pascal(action.name) %>Input,
14
- <% }); _%>
15
- } from '../types.js';
16
- import type {
17
- <% actions.forEach(action => { _%>
18
- <%= h.changeCase.pascal(action.name) %>Action,
19
- <% }); _%>
20
- } from './actions.js';
21
-
22
- <% actions.filter(a => a.hasInput).forEach(action => { _%>
23
- export const <%= h.changeCase.camel(action.name) %> = (input<% if(action.isEmptyInput) { %>: <%= h.changeCase.pascal(action.name) %>Input = {}<% } else { %>: <%= h.changeCase.pascal(action.name) %>Input<% } %><%if(action.hasAttachment){ %>, attachments: AttachmentInput[] <% } %>) =>
24
- createAction<<%= h.changeCase.pascal(action.name) %>Action>(
25
- '<%= h.changeCase.constantCase(action.name) %>',
26
- {...input},
27
- <%if(action.hasAttachment){ %>attachments<% } else { %>undefined<% } %>,
28
- <%= h.changeCase.pascalCase(action.name) %>InputSchema,
29
- '<%= action.scope %>'
30
- );
31
-
32
- <% }); _%>
33
-
34
- <% actions.filter(a => !a.hasInput).forEach(action => { _%>
35
- export const <%= h.changeCase.camel(action.name) %> = () =>
36
- createAction<<%= h.changeCase.pascal(action.name) %>Action>('<%= h.changeCase.constantCase(action.name) %>');
37
- <% }); _%>
@@ -1,44 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/src/tests/<%= module %>.test.ts"
3
- unless_exists: true
4
- ---
5
- /**
6
- * This is a scaffold file meant for customization:
7
- * - change it by adding new tests or modifying the existing ones
8
- */
9
-
10
- import { describe, it, expect } from 'vitest';
11
- import { generateMock } from '@powerhousedao/codegen';
12
- import {
13
- reducer,
14
- utils,
15
- <%= isPhDocumentOfTypeFunctionName %>,
16
- <% actions.forEach(action => { _%>
17
- <%= h.changeCase.camel(action.name) %>,
18
- <%= h.changeCase.pascal(action.name) %>InputSchema,
19
- <% }); _%>
20
- } from "<%= documentModelDir %>";
21
-
22
- describe('<%= h.changeCase.pascal(module) %> Operations', () => {
23
- <% actions.forEach(action => { _%>
24
- it('should handle <%= h.changeCase.camel(action.name) %> operation', () => {
25
- const document = utils.createDocument();
26
- const input = generateMock(
27
- <%= h.changeCase.pascal(action.name) %>InputSchema(),
28
- );
29
-
30
- const updatedDocument = reducer(
31
- document,
32
- <%= h.changeCase.camel(action.name) %>(input),
33
- );
34
-
35
- expect(<%= isPhDocumentOfTypeFunctionName %>(updatedDocument)).toBe(true);
36
- expect(updatedDocument.operations.<%= action.scope %>).toHaveLength(1);
37
- expect(updatedDocument.operations.<%= action.scope %>[0].action.type).toBe(
38
- '<%= h.changeCase.constant(action.name) %>',
39
- );
40
- expect(updatedDocument.operations.<%= action.scope %>[0].action.input).toStrictEqual(input);
41
- expect(updatedDocument.operations.<%= action.scope %>[0].index).toEqual(0);
42
- });
43
- <% }); _%>
44
- });
@@ -1,36 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/error.ts"
3
- force: true
4
- ---
5
- <% if (errors.length > 0) { _%>
6
- export type ErrorCode =
7
- <% errors.forEach((error, errorIndex) => { _%>
8
- | "<%= h.changeCase.pascal(error.name) %>"<% if (errorIndex === errors.length - 1) { %>;<% } %>
9
- <% }); _%>
10
-
11
- export interface ReducerError {
12
- errorCode: ErrorCode;
13
- }
14
-
15
- <% errors.forEach(error => { _%>
16
- export class <%= h.changeCase.pascal(error.name) %> extends Error implements ReducerError {
17
- errorCode = "<%= h.changeCase.pascal(error.name) %>" as ErrorCode;
18
- constructor(message = "<%= h.changeCase.pascal(error.name) %>") {
19
- super(message);
20
- }
21
- }
22
-
23
- <% }); _%>
24
-
25
- <% } _%>
26
- export const errors = {
27
- <% actions.forEach(action => { _%>
28
- <% if(action.errors?.length > 0){ -%>
29
- <%= h.changeCase.pascal(action.name) %>: {
30
- <% action.errors.forEach(error => { _%>
31
- <%= h.changeCase.pascal(error.name) %>,
32
- <% }); _%>
33
- },
34
- <% } -%>
35
- <% }); _%>
36
- };
@@ -1,71 +0,0 @@
1
- // @ts-check
2
- const { kebabCase, pascalCase } = require("change-case");
3
-
4
- module.exports = {
5
- params: ({ args }) => {
6
- const documentModel = JSON.parse(args.documentModel);
7
- const latestSpec =
8
- documentModel.specifications[documentModel.specifications.length - 1];
9
- const filteredModules = latestSpec.modules.filter(
10
- (m) => m.name === args.module,
11
- );
12
-
13
- const actions =
14
- filteredModules.length > 0
15
- ? filteredModules[0].operations.map((a) => ({
16
- name: a.name,
17
- hasInput: a.schema !== null,
18
- isEmptyInput:
19
- a.schema?.includes("_empty") &&
20
- !a.schema.replace(/_empty:\s*Boolean/, "").match(/\w+:\s*\w+/),
21
- hasAttachment: a.schema?.includes(": Attachment"),
22
- scope: a.scope || "global",
23
- state: a.scope === "global" ? "" : a.scope, // the state this action affects
24
- errors: a.errors,
25
- }))
26
- : [];
27
-
28
- const errors = actions.reduce((acc, action) => {
29
- action.errors.forEach((error) => {
30
- // Fallback: If error code is empty, generate it from the error name in PascalCase
31
- const errorCode = error.code || pascalCase(error.name || "");
32
- const normalizedError = { ...error, code: errorCode };
33
-
34
- const existingError = acc.find((e) => e.code === errorCode);
35
- if (!existingError) {
36
- acc.push(normalizedError);
37
- } else if (
38
- JSON.stringify(existingError) !== JSON.stringify(normalizedError)
39
- ) {
40
- console.warn(
41
- `Warning: Duplicate error code "${errorCode}" with different fields found`,
42
- );
43
- }
44
- });
45
- return acc;
46
- }, []);
47
-
48
- const documentType = documentModel.name;
49
- const pascalCaseDocumentType = pascalCase(documentType);
50
- const phDocumentTypeName = `${pascalCaseDocumentType}Document`;
51
- const isPhDocumentOfTypeFunctionName = `is${phDocumentTypeName}`;
52
- const assertIsPhDocumentOfTypeFunctionName = `assertIs${phDocumentTypeName}`;
53
- const kebabCaseDocumentType = kebabCase(documentType);
54
- const packageName = args.packageName;
55
- const documentModelDir = `${packageName}/document-models/${kebabCaseDocumentType}`;
56
- return {
57
- rootDir: args.rootDir,
58
- documentType: documentModel.name,
59
- module: kebabCase(args.module),
60
- actions,
61
- errors,
62
- pascalCaseDocumentType,
63
- kebabCaseDocumentType,
64
- packageName,
65
- documentModelDir,
66
- phDocumentTypeName,
67
- isPhDocumentOfTypeFunctionName,
68
- assertIsPhDocumentOfTypeFunctionName,
69
- };
70
- },
71
- };
@@ -1,17 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/operations.ts"
3
- force: true
4
- ---
5
- import { type SignalDispatch } from 'document-model';
6
- import {
7
- <% actions.forEach(action => { _%>
8
- <%= 'type ' + h.changeCase.pascal(action.name) %>Action,
9
- <% }); _%>
10
- } from './actions.js';
11
- import { <%= actions.map(action => 'type ' + h.changeCase.pascal(h.changeCase.pascal(documentType + '_' + action.state + '_State'))).filter((value, index, self) => self.indexOf(value) === index).join(', ') %> } from '../types.js';
12
-
13
- export interface <%= h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module) %>Operations {
14
- <% actions.forEach(action => { _%>
15
- <%= h.changeCase.camel(action.name) %>Operation: (state: <%= h.changeCase.pascal(documentType + '_' + action.state + '_State') %>, action: <%= h.changeCase.pascal(action.name) %>Action, dispatch?: SignalDispatch) => void,
16
- <% }); _%>
17
- }
@@ -1,119 +0,0 @@
1
- // @ts-check
2
- const { kebabCase, pascalCase, camelCase } = require("change-case");
3
-
4
- /**
5
- * Extract type names from a GraphQL schema.
6
- * @param {string} schema - GraphQL schema string
7
- * @returns {string[]} Array of type names
8
- */
9
- function extractTypeNames(schema) {
10
- const found = schema.match(/(type|enum|union|interface|input)\s+(\w+)\s/g);
11
- if (!found) return [];
12
- return found.map((f) =>
13
- f
14
- .replaceAll("type ", "")
15
- .replaceAll("enum ", "")
16
- .replaceAll("union ", "")
17
- .replaceAll("interface ", "")
18
- .replaceAll("input ", "")
19
- .trim(),
20
- );
21
- }
22
-
23
- /**
24
- * Apply type prefixes to GraphQL schema to namespace types and avoid collisions.
25
- * Inlined from @powerhousedao/common/utils to avoid ES module import issues.
26
- * @param {string} schema - GraphQL schema string
27
- * @param {string} prefix - Prefix to apply to type names
28
- * @param {string[]} externalTypeNames - Type names from other schemas to also prefix
29
- * @returns {string} Schema with prefixed types
30
- */
31
- function applyGraphQLTypePrefixes(schema, prefix, externalTypeNames = []) {
32
- if (!schema || !schema.trim()) {
33
- return schema;
34
- }
35
-
36
- let processedSchema = schema;
37
-
38
- // Find types defined in this schema
39
- const localTypeNames = extractTypeNames(schema);
40
-
41
- // Combine with external type names (remove duplicates)
42
- const allTypeNames = [...new Set([...localTypeNames, ...externalTypeNames])];
43
-
44
- if (allTypeNames.length === 0) {
45
- return schema;
46
- }
47
-
48
- allTypeNames.forEach((typeName) => {
49
- const typeRegex = new RegExp(
50
- // Match type references in various GraphQL contexts
51
- `(?<![_A-Za-z0-9])(${typeName})(?![_A-Za-z0-9])|` +
52
- `\\[(${typeName})\\]|` +
53
- `\\[(${typeName})!\\]|` +
54
- `\\[(${typeName})\\]!|` +
55
- `\\[(${typeName})!\\]!`,
56
- "g",
57
- );
58
-
59
- processedSchema = processedSchema.replace(
60
- typeRegex,
61
- (match, p1, p2, p3, p4, p5) => {
62
- if (match.startsWith("[")) {
63
- return match.replace(
64
- p2 || p3 || p4 || p5,
65
- `${prefix}_${p2 || p3 || p4 || p5}`,
66
- );
67
- }
68
- // Basic type reference
69
- return `${prefix}_${p1}`;
70
- },
71
- );
72
- });
73
-
74
- return processedSchema;
75
- }
76
-
77
- module.exports = {
78
- params: ({ args }) => {
79
- const documentModel = JSON.parse(args.documentModel);
80
- const latestSpec =
81
- documentModel.specifications[documentModel.specifications.length - 1];
82
- const documentType = documentModel.name;
83
- const pascalCaseDocumentType = pascalCase(documentType);
84
- const camelCaseDocumentType = camelCase(documentType);
85
- const phDocumentTypeName = `${pascalCaseDocumentType}Document`;
86
- const documentTypeVariableName = `${camelCaseDocumentType}DocumentType`;
87
- const packageName = args.packageName;
88
- const kebabCaseDocumentType = kebabCase(documentType);
89
- const documentModelDir = `${packageName}/document-models/${kebabCaseDocumentType}`;
90
-
91
- const stateSchema = latestSpec.state.global.schema;
92
- const stateTypeNames = extractTypeNames(stateSchema);
93
-
94
- return {
95
- phDocumentTypeName,
96
- documentTypeVariableName,
97
- pascalCaseDocumentType,
98
- camelCaseDocumentType,
99
- documentModelDir,
100
- rootDir: args.rootDir,
101
- subgraph: args.subgraph,
102
- documentTypeId: documentModel.id,
103
- documentType: documentModel.name,
104
- schema: applyGraphQLTypePrefixes(stateSchema, pascalCaseDocumentType),
105
- modules: latestSpec.modules.map((m) => ({
106
- ...m,
107
- name: kebabCase(m.name),
108
- operations: m.operations.map((op) => ({
109
- ...op,
110
- schema: applyGraphQLTypePrefixes(
111
- op.schema,
112
- pascalCaseDocumentType,
113
- stateTypeNames,
114
- ),
115
- })),
116
- })),
117
- };
118
- },
119
- };
@@ -1,44 +0,0 @@
1
- ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(subgraph) %>/schema.ts"
3
- force: true
4
- ---
5
- import { gql } from "graphql-tag";
6
- import type { DocumentNode } from "graphql";
7
-
8
- export const schema: DocumentNode = gql`
9
- """
10
- Queries: <%= h.changeCase.pascal(documentType) %> Document
11
- """
12
-
13
- type <%- h.changeCase.pascal(documentType) %>Queries {
14
- getDocument(docId: PHID!, driveId: PHID): <%- h.changeCase.pascal(documentType) %>
15
- getDocuments(driveId: String!): [<%- h.changeCase.pascal(documentType) %>!]
16
- }
17
-
18
- type Query {
19
- <%- h.changeCase.pascal(documentType) %>: <%- h.changeCase.pascal(documentType) %>Queries
20
- }
21
-
22
- """
23
- Mutations: <%= h.changeCase.pascal(documentType) %>
24
- """
25
- type Mutation {
26
-
27
- <%- h.changeCase.pascal(documentType) %>_createDocument(name:String!, driveId:String): String
28
-
29
- <% modules.forEach(module => { _%>
30
- <% module.operations.forEach(op => { _%>
31
- <%- h.changeCase.pascal(documentType) + '_' + h.changeCase.camel(op.name)
32
- %>(driveId:String, docId:PHID, input:<%-
33
- h.changeCase.pascal(documentType) + '_' + h.changeCase.pascal(op.name) %>Input): Int
34
- <%_ })}); %>}
35
-
36
- <% modules.forEach(module => { _%>
37
-
38
- """
39
- Module: <%= h.changeCase.pascal(module.name) %>
40
- """
41
- <% module.operations.forEach(op => { _%>
42
- <%- op.schema %>
43
- <%_ })}); %>
44
- `
@@ -1,58 +0,0 @@
1
- ---
2
- to: "<%= driveEditorDir %>/components/CreateDocument.tsx"
3
- unless_exists: true
4
- ---
5
- import type { VetraDocumentModelModule } from "@powerhousedao/reactor-browser";
6
- import {
7
- showCreateDocumentModal,
8
- useAllowedDocumentModelModules,
9
- } from "@powerhousedao/reactor-browser";
10
-
11
- /**
12
- * Document creation UI component.
13
- * Displays available document types as clickable buttons.
14
- */
15
- export function CreateDocument() {
16
- const allowedDocumentModelModules = useAllowedDocumentModelModules();
17
-
18
- return (
19
- <div>
20
- {/* Customize section title here */}
21
- <h3 className="mb-3 mt-4 text-sm font-bold text-gray-600">
22
- Create document
23
- </h3>
24
- {/* Customize layout by changing flex-wrap, gap, or grid layout */}
25
- <div className="flex w-full flex-wrap gap-4">
26
- {allowedDocumentModelModules?.map((documentModelModule) => {
27
- return (
28
- <CreateDocumentButton
29
- key={documentModelModule.documentModel.global.id}
30
- documentModelModule={documentModelModule}
31
- />
32
- );
33
- })}
34
- </div>
35
- </div>
36
- );
37
- }
38
-
39
- type Props = {
40
- documentModelModule: VetraDocumentModelModule;
41
- };
42
- function CreateDocumentButton({ documentModelModule }: Props) {
43
- const documentType = documentModelModule.documentModel.global.id;
44
- const documentModelName =
45
- documentModelModule.documentModel.global.name || documentType;
46
- const documentModelDescription =
47
- documentModelModule.documentModel.global.description;
48
- return (
49
- <button
50
- className="cursor-pointer rounded-md bg-gray-200 py-2 px-3 hover:bg-gray-300"
51
- title={documentModelName}
52
- aria-description={documentModelDescription}
53
- onClick={() => showCreateDocumentModal(documentType)}
54
- >
55
- {documentModelName}
56
- </button>
57
- );
58
- }