@powerhousedao/codegen 5.0.3 → 5.0.4

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 (180) hide show
  1. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/actions.esm.t +3 -3
  2. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/creators.esm.t +3 -2
  3. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/customUtils.esm.t +1 -1
  4. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/document-models.esm.t +14 -0
  5. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/document-schema.esm.t +56 -0
  6. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/document-type.esm.t +6 -0
  7. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModel.esm.t +1 -1
  8. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModelTest.esm.t +110 -15
  9. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/hooks.esm.t +49 -0
  10. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.esm.t +12 -4
  11. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.js +66 -7
  12. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/lib.esm.t +4 -2
  13. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/module.esm.t +22 -0
  14. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/ph-factories.esm.t +23 -23
  15. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +16 -9
  16. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/root-utils.esm.t +11 -0
  17. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootActions.esm.t +13 -0
  18. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootIndex.esm.t +6 -26
  19. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/schema.esm.t +2 -2
  20. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/src-index.esm.t +5 -0
  21. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +16 -16
  22. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +31 -10
  23. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/creators.esm.t +10 -5
  24. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t +13 -18
  25. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +15 -0
  26. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/index.js +99 -4
  27. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/resolvers.esm.t +21 -10
  28. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t +4 -3
  29. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/CreateDocument.esm.t +26 -29
  30. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveContents.esm.t +23 -0
  31. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +5 -126
  32. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EmptyState.esm.t +19 -0
  33. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/Files.esm.t +29 -0
  34. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderTree.esm.t +1 -1
  35. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/Folders.esm.t +28 -0
  36. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/NavigationBreadcrumbs.esm.t +14 -0
  37. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/config.esm.t +2 -1
  38. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +5 -2
  39. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editors.esm.t +14 -0
  40. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js +26 -3
  41. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/lib.esm.t +4 -2
  42. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/module.esm.t +15 -0
  43. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/edit-name.esm.t +78 -0
  44. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +7 -104
  45. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editors.esm.t +14 -0
  46. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +74 -1
  47. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/lib.esm.t +4 -2
  48. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/module.esm.t +16 -0
  49. package/dist/src/codegen/.hygen/templates/powerhouse/utils.js +46 -0
  50. package/dist/src/codegen/__tests__/config.d.ts +2 -0
  51. package/dist/src/codegen/__tests__/config.d.ts.map +1 -0
  52. package/dist/src/codegen/__tests__/config.js +2 -0
  53. package/dist/src/codegen/__tests__/config.js.map +1 -0
  54. package/dist/src/codegen/__tests__/constants.d.ts +16 -0
  55. package/dist/src/codegen/__tests__/constants.d.ts.map +1 -0
  56. package/dist/src/codegen/__tests__/constants.js +16 -0
  57. package/dist/src/codegen/__tests__/constants.js.map +1 -0
  58. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content-v3.d.ts +2 -0
  59. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content-v3.d.ts.map +1 -0
  60. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content-v3.js +9 -0
  61. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content-v3.js.map +1 -0
  62. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content.d.ts +3 -0
  63. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content.d.ts.map +1 -0
  64. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content.js +33 -0
  65. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content.js.map +1 -0
  66. package/dist/src/codegen/__tests__/fixtures/run-generated-tests.d.ts +2 -0
  67. package/dist/src/codegen/__tests__/fixtures/run-generated-tests.d.ts.map +1 -0
  68. package/dist/src/codegen/__tests__/fixtures/run-generated-tests.js +23 -0
  69. package/dist/src/codegen/__tests__/fixtures/run-generated-tests.js.map +1 -0
  70. package/dist/src/codegen/__tests__/fixtures/typecheck.d.ts +2 -0
  71. package/dist/src/codegen/__tests__/fixtures/typecheck.d.ts.map +1 -0
  72. package/dist/src/codegen/__tests__/fixtures/typecheck.js +23 -0
  73. package/dist/src/codegen/__tests__/fixtures/typecheck.js.map +1 -0
  74. package/dist/src/codegen/__tests__/generate-doc-model.test.d.ts +2 -0
  75. package/dist/src/codegen/__tests__/generate-doc-model.test.d.ts.map +1 -0
  76. package/dist/src/codegen/__tests__/generate-doc-model.test.js +206 -0
  77. package/dist/src/codegen/__tests__/generate-doc-model.test.js.map +1 -0
  78. package/dist/src/codegen/__tests__/generate-drive-editor.test.d.ts +2 -0
  79. package/dist/src/codegen/__tests__/generate-drive-editor.test.d.ts.map +1 -0
  80. package/dist/src/codegen/__tests__/generate-drive-editor.test.js +153 -0
  81. package/dist/src/codegen/__tests__/generate-drive-editor.test.js.map +1 -0
  82. package/dist/src/codegen/__tests__/generate-editor.test.d.ts +2 -0
  83. package/dist/src/codegen/__tests__/generate-editor.test.d.ts.map +1 -0
  84. package/dist/src/codegen/__tests__/generate-editor.test.js +112 -0
  85. package/dist/src/codegen/__tests__/generate-editor.test.js.map +1 -0
  86. package/dist/src/codegen/__tests__/generate-manifest.test.d.ts +2 -0
  87. package/dist/src/codegen/__tests__/generate-manifest.test.d.ts.map +1 -0
  88. package/dist/src/codegen/__tests__/generate-manifest.test.js +192 -0
  89. package/dist/src/codegen/__tests__/generate-manifest.test.js.map +1 -0
  90. package/dist/src/codegen/__tests__/generate-schemas.test.d.ts +2 -0
  91. package/dist/src/codegen/__tests__/generate-schemas.test.d.ts.map +1 -0
  92. package/dist/src/codegen/__tests__/generate-schemas.test.js +143 -0
  93. package/dist/src/codegen/__tests__/generate-schemas.test.js.map +1 -0
  94. package/dist/src/codegen/__tests__/global-setup.d.ts +2 -0
  95. package/dist/src/codegen/__tests__/global-setup.d.ts.map +1 -0
  96. package/dist/src/codegen/__tests__/global-setup.js +21 -0
  97. package/dist/src/codegen/__tests__/global-setup.js.map +1 -0
  98. package/dist/src/codegen/__tests__/ts-morph-generator.test.d.ts +2 -0
  99. package/dist/src/codegen/__tests__/ts-morph-generator.test.d.ts.map +1 -0
  100. package/dist/src/codegen/__tests__/ts-morph-generator.test.js +72 -0
  101. package/dist/src/codegen/__tests__/ts-morph-generator.test.js.map +1 -0
  102. package/dist/src/codegen/__tests__/utils.d.ts +7 -0
  103. package/dist/src/codegen/__tests__/utils.d.ts.map +1 -0
  104. package/dist/src/codegen/__tests__/utils.js +52 -0
  105. package/dist/src/codegen/__tests__/utils.js.map +1 -0
  106. package/dist/src/codegen/generate.d.ts +12 -2
  107. package/dist/src/codegen/generate.d.ts.map +1 -1
  108. package/dist/src/codegen/generate.js +26 -11
  109. package/dist/src/codegen/generate.js.map +1 -1
  110. package/dist/src/codegen/graphql.js +1 -1
  111. package/dist/src/codegen/graphql.js.map +1 -1
  112. package/dist/src/codegen/hygen.d.ts +19 -10
  113. package/dist/src/codegen/hygen.d.ts.map +1 -1
  114. package/dist/src/codegen/hygen.js +62 -16
  115. package/dist/src/codegen/hygen.js.map +1 -1
  116. package/dist/src/create-lib/checkout-project.d.ts +13 -0
  117. package/dist/src/create-lib/checkout-project.d.ts.map +1 -0
  118. package/dist/src/create-lib/checkout-project.js +47 -0
  119. package/dist/src/create-lib/checkout-project.js.map +1 -0
  120. package/dist/src/create-lib/create-project.d.ts +9 -5
  121. package/dist/src/create-lib/create-project.d.ts.map +1 -1
  122. package/dist/src/create-lib/create-project.js +37 -45
  123. package/dist/src/create-lib/create-project.js.map +1 -1
  124. package/dist/src/create-lib/feature-flags.d.ts +4 -0
  125. package/dist/src/create-lib/feature-flags.d.ts.map +1 -0
  126. package/dist/src/create-lib/feature-flags.js +4 -0
  127. package/dist/src/create-lib/feature-flags.js.map +1 -0
  128. package/dist/src/create-lib/index.d.ts +1 -0
  129. package/dist/src/create-lib/index.d.ts.map +1 -1
  130. package/dist/src/create-lib/index.js +1 -0
  131. package/dist/src/create-lib/index.js.map +1 -1
  132. package/dist/src/create-lib/utils.d.ts +7 -0
  133. package/dist/src/create-lib/utils.d.ts.map +1 -0
  134. package/dist/src/create-lib/utils.js +28 -0
  135. package/dist/src/create-lib/utils.js.map +1 -0
  136. package/dist/src/ts-morph-generator/__tests__/ReducerGenerator.test.d.ts +2 -0
  137. package/dist/src/ts-morph-generator/__tests__/ReducerGenerator.test.d.ts.map +1 -0
  138. package/dist/src/ts-morph-generator/__tests__/ReducerGenerator.test.js +491 -0
  139. package/dist/src/ts-morph-generator/__tests__/ReducerGenerator.test.js.map +1 -0
  140. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts +3 -1
  141. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts.map +1 -1
  142. package/dist/src/ts-morph-generator/core/FileGenerator.js +3 -1
  143. package/dist/src/ts-morph-generator/core/FileGenerator.js.map +1 -1
  144. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts +1 -0
  145. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts.map +1 -1
  146. package/dist/src/ts-morph-generator/core/ReducerGenerator.d.ts.map +1 -1
  147. package/dist/src/ts-morph-generator/core/ReducerGenerator.js +14 -7
  148. package/dist/src/ts-morph-generator/core/ReducerGenerator.js.map +1 -1
  149. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts +2 -1
  150. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts.map +1 -1
  151. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js +10 -3
  152. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js.map +1 -1
  153. package/dist/src/ts-morph-generator/utilities/DeclarationManager.d.ts +5 -0
  154. package/dist/src/ts-morph-generator/utilities/DeclarationManager.d.ts.map +1 -0
  155. package/dist/src/ts-morph-generator/utilities/DeclarationManager.js +10 -0
  156. package/dist/src/ts-morph-generator/utilities/DeclarationManager.js.map +1 -0
  157. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts +1 -0
  158. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts.map +1 -1
  159. package/dist/src/ts-morph-generator/utilities/ImportManager.js +13 -3
  160. package/dist/src/ts-morph-generator/utilities/ImportManager.js.map +1 -1
  161. package/dist/src/ts-morph-generator/utilities/index.d.ts +1 -0
  162. package/dist/src/ts-morph-generator/utilities/index.d.ts.map +1 -1
  163. package/dist/src/ts-morph-generator/utilities/index.js +1 -0
  164. package/dist/src/ts-morph-generator/utilities/index.js.map +1 -1
  165. package/dist/src/utils/validation.d.ts.map +1 -1
  166. package/dist/src/utils/validation.js +3 -4
  167. package/dist/src/utils/validation.js.map +1 -1
  168. package/dist/tsconfig.tsbuildinfo +1 -0
  169. package/dist/vitest.config.d.ts +3 -0
  170. package/dist/vitest.config.d.ts.map +1 -0
  171. package/dist/vitest.config.js +16 -0
  172. package/dist/vitest.config.js.map +1 -0
  173. package/package.json +13 -12
  174. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/lib.inject_export.esm.t +0 -7
  175. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.esm.t +0 -15
  176. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/lib.inject_export.esm.t +0 -7
  177. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/hooks.esm.t +0 -16
  178. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +0 -15
  179. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/lib.inject_export.esm.t +0 -7
  180. package/dist/tsconfig.lib.tsbuildinfo +0 -1
@@ -1,5 +1,5 @@
1
1
  ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/index.ts"
2
+ to: "<%= rootDir %>/<%= paramCaseDocumentType %>/index.ts"
3
3
  force: true
4
4
  ---
5
5
  /**
@@ -7,28 +7,8 @@ force: true
7
7
  * Delete the file and run the code generator again to have it reset
8
8
  */
9
9
 
10
- import { createState, type DocumentModelModule, baseActions } from 'document-model';
11
- import { defaultBaseState } from 'document-model/core';
12
- import { actions as <%= h.changeCase.pascal(documentType) %>Actions } from './gen/index.js';
13
- import { reducer } from './gen/reducer.js';
14
- import { documentModel } from './gen/document-model.js';
15
- import genUtils from './gen/utils.js';
16
- import * as customUtils from './src/utils.js';
17
- import type { <%= h.changeCase.pascal(documentType) %>PHState } from './gen/types.js';
18
-
19
- const utils = { ...genUtils, ...customUtils };
20
- const actions = { ...baseActions, ...<%= h.changeCase.pascal(documentType) %>Actions };
21
-
22
- export const module: DocumentModelModule<
23
- <%= h.changeCase.pascal(documentType) %>PHState
24
- > = {
25
- reducer,
26
- actions,
27
- utils,
28
- documentModel: createState(defaultBaseState(), documentModel),
29
- };
30
-
31
- export { reducer, actions, utils, documentModel };
32
-
33
- export * from './gen/types.js';
34
- export * from './src/utils.js';
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 +1,6 @@
1
1
  ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/schema/index.ts"
2
+ to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/schema/index.ts"
3
3
  force: true
4
4
  ---
5
5
  export * from "./types.js";
6
- export * as z from "./zod.js";
6
+ export * from "./zod.js";
@@ -0,0 +1,5 @@
1
+ ---
2
+ to: "<%= rootDir %>/<%= paramCaseDocumentType %>/src/index.ts"
3
+ force: true
4
+ ---
5
+ export * from "./utils.js";
@@ -1,31 +1,31 @@
1
1
  ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/types.ts"
2
+ to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/types.ts"
3
3
  force: true
4
4
  ---
5
5
  import type { PHDocument, PHBaseState } from 'document-model';
6
- import type { <%= h.changeCase.pascal(documentType) %>Action } from './actions.js';
6
+ import type { <%= actionTypeName %> } from './actions.js';
7
7
  import type {
8
- <%= h.changeCase.pascal(documentType) %>State as <%= h.changeCase.pascal(documentType) %>GlobalState,
8
+ <%= stateName %> as <%= globalStateName %>,
9
9
  <% if(hasLocalSchema) { -%>
10
- <%= h.changeCase.pascal(documentType) %>LocalState,
10
+ <%= localStateName %>,
11
11
  <%} -%>
12
12
  } from './schema/types.js';
13
13
 
14
- export { z } from './schema/index.js';
15
- export * from './schema/types.js';
16
14
  <% if(!hasLocalSchema) { -%>
17
- <%= 'type ' + h.changeCase.pascal(documentType) %>LocalState = Record<PropertyKey, never>;
15
+ <%= 'type ' + localStateName %> = Record<PropertyKey, never>;
18
16
  <%} -%>
19
- type <%= h.changeCase.pascal(documentType) %>PHState = PHBaseState & {
20
- global: <%= h.changeCase.pascal(documentType) %>GlobalState;
21
- local: <%= h.changeCase.pascal(documentType) %>LocalState;
17
+ type <%= phStateName %> = PHBaseState & {
18
+ global: <%= globalStateName %>;
19
+ local: <%= localStateName %>;
22
20
  };
23
- type <%= h.changeCase.pascal(documentType) %>Document = PHDocument<<%= h.changeCase.pascal(documentType) %>PHState>;
21
+ type <%= phDocumentTypeName %> = PHDocument<<%= phStateName %>>;
22
+
23
+ export * from './schema/types.js';
24
24
 
25
25
  export type {
26
- <%= h.changeCase.pascal(documentType) %>GlobalState,
27
- <%= h.changeCase.pascal(documentType) %>LocalState,
28
- <%= h.changeCase.pascal(documentType) %>PHState,
29
- <%= h.changeCase.pascal(documentType) %>Action,
30
- <%= h.changeCase.pascal(documentType) %>Document,
26
+ <%= globalStateName %>,
27
+ <%= localStateName %>,
28
+ <%= phStateName %>,
29
+ <%= actionTypeName %>,
30
+ <%= phDocumentTypeName %>,
31
31
  };
@@ -1,5 +1,5 @@
1
1
  ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/utils.ts"
2
+ to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/utils.ts"
3
3
  force: true
4
4
  ---
5
5
  import type {
@@ -13,16 +13,23 @@ import {
13
13
  generateId,
14
14
  } from 'document-model/core';
15
15
  import type {
16
- <%= h.changeCase.pascal(documentType) %>GlobalState,
17
- <%= h.changeCase.pascal(documentType) %>LocalState
16
+ <%= globalStateName %>,
17
+ <%= localStateName %>
18
18
  } from './types.js';
19
- import type { <%= h.changeCase.pascal(documentType) %>PHState } from './types.js';
19
+ import type { <%= phStateName %> } from './types.js';
20
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";
21
28
 
22
- export const initialGlobalState: <%= h.changeCase.pascal(documentType) %>GlobalState = <%- initialGlobalState %>;
23
- export const initialLocalState: <%= h.changeCase.pascal(documentType) %>LocalState = <%- initialLocalState %>;
29
+ export const initialGlobalState: <%= globalStateName %> = <%- initialGlobalState %>;
30
+ export const initialLocalState: <%= localStateName %> = <%- initialLocalState %>;
24
31
 
25
- const utils: DocumentModelUtils<<%= h.changeCase.pascal(documentType) %>PHState> = {
32
+ export const utils: DocumentModelUtils<<%= phStateName %>> = {
26
33
  fileExtension: '<%- fileExtension %>',
27
34
  createState(state) {
28
35
  return { ...defaultBaseState(), global: { ...initialGlobalState, ...state?.global }, local: { ...initialLocalState, ...state?.local } };
@@ -33,7 +40,7 @@ const utils: DocumentModelUtils<<%= h.changeCase.pascal(documentType) %>PHState>
33
40
  state
34
41
  );
35
42
 
36
- document.header.documentType = '<%- documentTypeId %>';
43
+ document.header.documentType = <%= documentTypeVariableName %>;
37
44
 
38
45
  // for backwards compatibility, but this is NOT a valid signed document id
39
46
  document.header.id = generateId();
@@ -46,11 +53,25 @@ const utils: DocumentModelUtils<<%= h.changeCase.pascal(documentType) %>PHState>
46
53
  loadFromInput(input) {
47
54
  return baseLoadFromInput(input, reducer);
48
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
+ },
49
68
  };
50
69
 
51
70
  export const createDocument = utils.createDocument;
52
71
  export const createState = utils.createState;
53
72
  export const saveToFileHandle = utils.saveToFileHandle;
54
73
  export const loadFromInput = utils.loadFromInput;
55
-
56
- export default utils;
74
+ export const isStateOfType = utils.isStateOfType;
75
+ export const assertIsStateOfType = utils.assertIsStateOfType;
76
+ export const isDocumentOfType = utils.isDocumentOfType;
77
+ export const assertIsDocumentOfType = utils.assertIsDocumentOfType;
@@ -3,14 +3,19 @@ to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/cr
3
3
  force: true
4
4
  ---
5
5
  import { createAction<% if (actions.find(a => a.hasAttachment)) {%>, AttachmentInput<%}%> } from 'document-model/core';
6
- import { z,
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 {
7
12
  <% actions.filter(a => a.hasInput).forEach(action => { _%>
8
- <%= 'type ' + h.changeCase.pascal(action.name) %>Input,
13
+ <%= h.changeCase.pascal(action.name) %>Input,
9
14
  <% }); _%>
10
15
  } from '../types.js';
11
- import {
16
+ import type {
12
17
  <% actions.forEach(action => { _%>
13
- <%= 'type ' + h.changeCase.pascal(action.name) %>Action,
18
+ <%= h.changeCase.pascal(action.name) %>Action,
14
19
  <% }); _%>
15
20
  } from './actions.js';
16
21
 
@@ -20,7 +25,7 @@ export const <%= h.changeCase.camel(action.name) %> = (input: <%= h.changeCase.p
20
25
  '<%= h.changeCase.constantCase(action.name) %>',
21
26
  {...input},
22
27
  <%if(action.hasAttachment){ %>attachments<% } else { %>undefined<% } %>,
23
- z.<%= h.changeCase.pascalCase(action.name) %>InputSchema,
28
+ <%= h.changeCase.pascalCase(action.name) %>InputSchema,
24
29
  '<%= action.scope %>'
25
30
  );
26
31
 
@@ -7,37 +7,32 @@ unless_exists: true
7
7
  * - change it by adding new tests or modifying the existing ones
8
8
  */
9
9
 
10
- import { describe, it, expect, beforeEach } from 'vitest';
10
+ import { describe, it, expect } from 'vitest';
11
11
  import { generateMock } from '@powerhousedao/codegen';
12
- import utils from '../../gen/utils.js';
13
12
  import {
14
- z,
15
- <% actions.forEach(action => { _%>
16
- <%= 'type ' + h.changeCase.pascal(action.name) %>Input,
13
+ reducer,
14
+ utils,
15
+ <%= isPhDocumentOfTypeFunctionName %>,
16
+ <% actions.forEach(action => { _%>
17
+ <%= h.changeCase.camel(action.name) %>,
18
+ <%= h.changeCase.pascal(action.name) %>InputSchema,
17
19
  <% }); _%>
18
- } from '../../gen/schema/index.js';
19
- import { reducer } from '../../gen/reducer.js';
20
- import * as creators from '../../gen/<%= module %>/creators.js';
21
- import type { <%= h.changeCase.pascal(documentType) %>Document } from '../../gen/types.js';
20
+ } from "<%= documentModelDir %>";
22
21
 
23
22
  describe('<%= h.changeCase.pascal(module) %> Operations', () => {
24
- let document: <%= h.changeCase.pascal(documentType) %>Document;
25
-
26
- beforeEach(() => {
27
- document = utils.createDocument();
28
- });
29
-
30
23
  <% actions.forEach(action => { _%>
31
24
  it('should handle <%= h.changeCase.camel(action.name) %> operation', () => {
32
- const input: <%= h.changeCase.pascal(action.name) %>Input = generateMock(
33
- z.<%= h.changeCase.pascal(action.name) %>InputSchema(),
25
+ const document = utils.createDocument();
26
+ const input = generateMock(
27
+ <%= h.changeCase.pascal(action.name) %>InputSchema(),
34
28
  );
35
29
 
36
30
  const updatedDocument = reducer(
37
31
  document,
38
- creators.<%= h.changeCase.camel(action.name) %>(input),
32
+ <%= h.changeCase.camel(action.name) %>(input),
39
33
  );
40
34
 
35
+ expect(<%= isPhDocumentOfTypeFunctionName %>(updatedDocument)).toBe(true);
41
36
  expect(updatedDocument.operations.<%= action.scope %>).toHaveLength(1);
42
37
  expect(updatedDocument.operations.<%= action.scope %>[0].action.type).toBe(
43
38
  '<%= h.changeCase.constant(action.name) %>',
@@ -42,12 +42,27 @@ module.exports = {
42
42
  return acc;
43
43
  }, []);
44
44
 
45
+ const documentType = documentModel.name;
46
+ const pascalCaseDocumentType = pascalCase(documentType);
47
+ const phDocumentTypeName = `${pascalCaseDocumentType}Document`;
48
+ const isPhDocumentOfTypeFunctionName = `is${phDocumentTypeName}`;
49
+ const assertIsPhDocumentOfTypeFunctionName = `assertIs${phDocumentTypeName}`;
50
+ const paramCaseDocumentType = paramCase(documentType);
51
+ const packageName = args.packageName;
52
+ const documentModelDir = `${packageName}/document-models/${paramCaseDocumentType}`;
45
53
  return {
46
54
  rootDir: args.rootDir,
47
55
  documentType: documentModel.name,
48
56
  module: paramCase(args.module),
49
57
  actions,
50
58
  errors,
59
+ pascalCaseDocumentType,
60
+ paramCaseDocumentType,
61
+ packageName,
62
+ documentModelDir,
63
+ phDocumentTypeName,
64
+ isPhDocumentOfTypeFunctionName,
65
+ assertIsPhDocumentOfTypeFunctionName,
51
66
  };
52
67
  },
53
68
  };
@@ -1,23 +1,118 @@
1
1
  // @ts-check
2
- const { paramCase } = require("change-case");
2
+ const { paramCase, pascalCase, camelCase } = require("change-case");
3
3
 
4
- const generateDocumentModelMutations = {
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 = {
5
78
  params: ({ args }) => {
6
79
  const documentModel = JSON.parse(args.documentModel);
7
80
  const latestSpec =
8
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 paramCaseDocumentType = paramCase(documentType);
89
+ const documentModelDir = `${packageName}/document-models/${paramCaseDocumentType}`;
90
+
91
+ const stateSchema = latestSpec.state.global.schema;
92
+ const stateTypeNames = extractTypeNames(stateSchema);
9
93
 
10
94
  return {
95
+ phDocumentTypeName,
96
+ documentTypeVariableName,
97
+ pascalCaseDocumentType,
98
+ camelCaseDocumentType,
99
+ documentModelDir,
11
100
  rootDir: args.rootDir,
12
101
  subgraph: args.subgraph,
13
102
  documentTypeId: documentModel.id,
14
103
  documentType: documentModel.name,
15
- schema: latestSpec.state.global.schema,
104
+ schema: applyGraphQLTypePrefixes(
105
+ stateSchema,
106
+ pascalCaseDocumentType
107
+ ),
16
108
  modules: latestSpec.modules.map((m) => ({
17
109
  ...m,
18
110
  name: paramCase(m.name),
111
+ operations: m.operations.map((op) => ({
112
+ ...op,
113
+ schema: applyGraphQLTypePrefixes(op.schema, pascalCaseDocumentType, stateTypeNames),
114
+ })),
19
115
  })),
20
116
  };
21
117
  },
22
118
  };
23
- module.exports = generateDocumentModelMutations;
@@ -4,15 +4,26 @@ force: true
4
4
  ---
5
5
  import type { BaseSubgraph } from "@powerhousedao/reactor-api";
6
6
  import { addFile } from "document-drive";
7
- import { actions <% modules.forEach(module => { %><% module.operations.forEach(op => { %>, type <%- h.changeCase.pascal(op.name) %>Input<%_ })}); %>, type <%- h.changeCase.pascal(documentType) %>Document } from "../../document-models/<%- h.changeCase.param(documentType) %>/index.js";
8
7
  import { setName } from "document-model";
8
+ import {
9
+ actions,
10
+ <%= documentTypeVariableName %>,
11
+ } from "<%= documentModelDir %>";
12
+ <% const inputTypes = modules.flatMap(m =>
13
+ m.operations.map(o => `${h.changeCase.pascalCase(o.name)}Input`)
14
+ );
15
+ %>
16
+ import type {
17
+ <%= phDocumentTypeName %>,
18
+ <%= inputTypes.join(',\n ') %>
19
+ } from "<%= documentModelDir %>";
9
20
 
10
21
  export const getResolvers = (subgraph: BaseSubgraph): Record<string, unknown> => {
11
22
  const reactor = subgraph.reactor;
12
23
 
13
24
  return ({
14
25
  Query: {
15
- <%- h.changeCase.pascal(documentType) %>: async () => {
26
+ <%- pascalCaseDocumentType %>: async () => {
16
27
  return {
17
28
  getDocument: async (args: { docId: string, driveId: string }) => {
18
29
  const { docId, driveId } = args;
@@ -28,7 +39,7 @@ export const getResolvers = (subgraph: BaseSubgraph): Record<string, unknown> =>
28
39
  }
29
40
  }
30
41
 
31
- const doc = await reactor.getDocument<<%- h.changeCase.pascal(documentType) %>Document>(docId);
42
+ const doc = await reactor.getDocument<<%= phDocumentTypeName %>>(docId);
32
43
  return {
33
44
  driveId: driveId,
34
45
  ...doc,
@@ -45,7 +56,7 @@ export const getResolvers = (subgraph: BaseSubgraph): Record<string, unknown> =>
45
56
  const docsIds = await reactor.getDocuments(driveId);
46
57
  const docs = await Promise.all(
47
58
  docsIds.map(async (docId) => {
48
- const doc = await reactor.getDocument<<%- h.changeCase.pascal(documentType) %>Document>(docId);
59
+ const doc = await reactor.getDocument<<%= phDocumentTypeName %>>(docId);
49
60
  return {
50
61
  driveId: driveId,
51
62
  ...doc,
@@ -60,16 +71,16 @@ export const getResolvers = (subgraph: BaseSubgraph): Record<string, unknown> =>
60
71
  );
61
72
 
62
73
  return docs.filter(
63
- (doc) => doc.header.documentType === "<%- documentTypeId %>",
74
+ (doc) => doc.header.documentType === <%= documentTypeVariableName %>,
64
75
  );
65
76
  },
66
77
  };
67
78
  },
68
79
  },
69
80
  Mutation: {
70
- <%- h.changeCase.pascal(documentType) %>_createDocument: async (_: unknown, args: { name: string, driveId?: string }) => {
81
+ <%- pascalCaseDocumentType %>_createDocument: async (_: unknown, args: { name: string, driveId?: string }) => {
71
82
  const { driveId, name } = args;
72
- const document = await reactor.addDocument("<%- documentTypeId %>");
83
+ const document = await reactor.addDocument(<%= documentTypeVariableName %>);
73
84
 
74
85
  if(driveId) {
75
86
  await reactor.addAction(
@@ -77,7 +88,7 @@ export const getResolvers = (subgraph: BaseSubgraph): Record<string, unknown> =>
77
88
  addFile({
78
89
  name,
79
90
  id: document.header.id,
80
- documentType: "<%- documentTypeId %>",
91
+ documentType: <%= documentTypeVariableName %>,
81
92
  }),
82
93
  );
83
94
  }
@@ -94,9 +105,9 @@ export const getResolvers = (subgraph: BaseSubgraph): Record<string, unknown> =>
94
105
 
95
106
  <% modules.forEach(module => { _%>
96
107
  <% module.operations.forEach(op => { _%>
97
- <%- h.changeCase.pascal(documentType) + '_' + h.changeCase.camel(op.name) %>: async (_: unknown, args: { docId: string, input: <%- h.changeCase.pascal(op.name) %>Input}) => {
108
+ <%- pascalCaseDocumentType + '_' + h.changeCase.camel(op.name) %>: async (_: unknown, args: { docId: string, input: <%- h.changeCase.pascal(op.name) %>Input}) => {
98
109
  const { docId, input } = args;
99
- const doc = await reactor.getDocument<<%- h.changeCase.pascal(documentType) %>Document>(docId);
110
+ const doc = await reactor.getDocument<<%- pascalCaseDocumentType %>Document>(docId);
100
111
  if(!doc) {
101
112
  throw new Error("Document not found");
102
113
  }
@@ -28,16 +28,17 @@ type Mutation {
28
28
 
29
29
  <% modules.forEach(module => { _%>
30
30
  <% module.operations.forEach(op => { _%>
31
- <%- h.changeCase.pascal(documentType) + '_' + h.changeCase.camel(op.name)
32
- %>(driveId:String, docId:PHID, input:<%-
31
+ <%- h.changeCase.pascal(documentType) + '_' + h.changeCase.camel(op.name)
32
+ %>(driveId:String, docId:PHID, input:<%-
33
33
  h.changeCase.pascal(documentType) + '_' + h.changeCase.pascal(op.name) %>Input): Int
34
34
  <%_ })}); %>}
35
+
35
36
  <% modules.forEach(module => { _%>
36
37
 
37
38
  """
38
39
  Module: <%= h.changeCase.pascal(module.name) %>
39
40
  """
40
41
  <% module.operations.forEach(op => { _%>
41
- <%- op.schema.replace('input ', 'input ' + h.changeCase.pascal(documentType) + '_').replace('type ', 'type ' + h.changeCase.pascal(documentType) + '_') %>
42
+ <%- op.schema %>
42
43
  <%_ })}); %>
43
44
  `
@@ -1,14 +1,11 @@
1
1
  ---
2
- to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/components/CreateDocument.tsx"
2
+ to: "<%= driveEditorDir %>/components/CreateDocument.tsx"
3
3
  unless_exists: true
4
4
  ---
5
- import { Button } from "@powerhousedao/design-system";
5
+ import type { VetraDocumentModelModule } from "@powerhousedao/reactor-browser";
6
6
  import {
7
7
  showCreateDocumentModal,
8
8
  useAllowedDocumentModelModules,
9
- useDocumentModelModules,
10
- useSelectedDriveId,
11
- type VetraDocumentModelModule,
12
9
  } from "@powerhousedao/reactor-browser";
13
10
 
14
11
  /**
@@ -16,18 +13,8 @@ import {
16
13
  * Displays available document types as clickable buttons.
17
14
  */
18
15
  export function CreateDocument() {
19
- const selectedDriveId = useSelectedDriveId();
20
16
  const allowedDocumentModelModules = useAllowedDocumentModelModules();
21
17
 
22
- function handleAddDocument(module: VetraDocumentModelModule) {
23
- if (!selectedDriveId) {
24
- return;
25
- }
26
-
27
- // Display the Create Document modal on the host app
28
- showCreateDocumentModal(module.documentModel.global.id);
29
- }
30
-
31
18
  return (
32
19
  <div>
33
20
  {/* Customize section title here */}
@@ -38,24 +25,34 @@ export function CreateDocument() {
38
25
  <div className="flex w-full flex-wrap gap-4">
39
26
  {allowedDocumentModelModules?.map((documentModelModule) => {
40
27
  return (
41
- <Button
28
+ <CreateDocumentButton
42
29
  key={documentModelModule.documentModel.global.id}
43
- color="light" // Customize button appearance
44
- className="cursor-pointer bg-gray-200 p-2 hover:bg-gray-300"
45
- title={documentModelModule.documentModel.global.name}
46
- aria-description={
47
- documentModelModule.documentModel.global.description
48
- }
49
- onClick={() => handleAddDocument(documentModelModule)}
50
- >
51
- {/* Customize document type display format */}
52
- <span className="text-sm">
53
- {documentModelModule.documentModel.global.name}
54
- </span>
55
- </Button>
30
+ documentModelModule={documentModelModule}
31
+ />
56
32
  );
57
33
  })}
58
34
  </div>
59
35
  </div>
60
36
  );
61
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
+ }
@@ -0,0 +1,23 @@
1
+ ---
2
+ to: "<%= driveEditorDir %>/components/DriveContents.tsx"
3
+ unless_exists: true
4
+ ---
5
+ import { CreateDocument } from "./CreateDocument.js";
6
+ import { EmptyState } from "./EmptyState.js";
7
+ import { Files } from "./Files.js";
8
+ import { Folders } from "./Folders.js";
9
+ import { NavigationBreadcrumbs } from "./NavigationBreadcrumbs.js";
10
+
11
+ /** Shows the documents and folders in the selected drive */
12
+ export function DriveContents() {
13
+ return (
14
+ <div className="space-y-6 px-6">
15
+ <NavigationBreadcrumbs />
16
+ <Folders />
17
+ <Files />
18
+ <EmptyState />
19
+ <CreateDocument />
20
+ </div>
21
+ );
22
+ }
23
+