@powerhousedao/codegen 4.1.0-dev.100 → 4.1.0-dev.102

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 (152) 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 +15 -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-drive-editor/components/CreateDocument.esm.t +25 -28
  29. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveContents.esm.t +23 -0
  30. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +4 -125
  31. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EmptyState.esm.t +19 -0
  32. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/Files.esm.t +29 -0
  33. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/Folders.esm.t +28 -0
  34. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/NavigationBreadcrumbs.esm.t +14 -0
  35. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/config.esm.t +1 -0
  36. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +4 -1
  37. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editors.esm.t +14 -0
  38. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js +21 -3
  39. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/lib.esm.t +4 -2
  40. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/module.esm.t +15 -0
  41. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/edit-name.esm.t +78 -0
  42. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +6 -103
  43. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editors.esm.t +14 -0
  44. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +71 -2
  45. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/lib.esm.t +4 -2
  46. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/module.esm.t +16 -0
  47. package/dist/src/codegen/.hygen/templates/powerhouse/utils.js +43 -0
  48. package/dist/src/codegen/__tests__/config.d.ts +2 -0
  49. package/dist/src/codegen/__tests__/config.d.ts.map +1 -0
  50. package/dist/src/codegen/__tests__/config.js +2 -0
  51. package/dist/src/codegen/__tests__/config.js.map +1 -0
  52. package/dist/src/codegen/__tests__/constants.d.ts +16 -0
  53. package/dist/src/codegen/__tests__/constants.d.ts.map +1 -0
  54. package/dist/src/codegen/__tests__/constants.js +16 -0
  55. package/dist/src/codegen/__tests__/constants.js.map +1 -0
  56. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content-v3.d.ts +2 -0
  57. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content-v3.d.ts.map +1 -0
  58. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content-v3.js +9 -0
  59. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content-v3.js.map +1 -0
  60. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content.d.ts +3 -0
  61. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content.d.ts.map +1 -0
  62. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content.js +33 -0
  63. package/dist/src/codegen/__tests__/fixtures/expected-reducer-content.js.map +1 -0
  64. package/dist/src/codegen/__tests__/fixtures/run-generated-tests.d.ts +2 -0
  65. package/dist/src/codegen/__tests__/fixtures/run-generated-tests.d.ts.map +1 -0
  66. package/dist/src/codegen/__tests__/fixtures/run-generated-tests.js +23 -0
  67. package/dist/src/codegen/__tests__/fixtures/run-generated-tests.js.map +1 -0
  68. package/dist/src/codegen/__tests__/fixtures/typecheck.d.ts +2 -0
  69. package/dist/src/codegen/__tests__/fixtures/typecheck.d.ts.map +1 -0
  70. package/dist/src/codegen/__tests__/fixtures/typecheck.js +23 -0
  71. package/dist/src/codegen/__tests__/fixtures/typecheck.js.map +1 -0
  72. package/dist/src/codegen/__tests__/generate-doc-model.test.d.ts +2 -0
  73. package/dist/src/codegen/__tests__/generate-doc-model.test.d.ts.map +1 -0
  74. package/dist/src/codegen/__tests__/generate-doc-model.test.js +220 -0
  75. package/dist/src/codegen/__tests__/generate-doc-model.test.js.map +1 -0
  76. package/dist/src/codegen/__tests__/generate-drive-editor.test.d.ts +2 -0
  77. package/dist/src/codegen/__tests__/generate-drive-editor.test.d.ts.map +1 -0
  78. package/dist/src/codegen/__tests__/generate-drive-editor.test.js +162 -0
  79. package/dist/src/codegen/__tests__/generate-drive-editor.test.js.map +1 -0
  80. package/dist/src/codegen/__tests__/generate-editor.test.d.ts +2 -0
  81. package/dist/src/codegen/__tests__/generate-editor.test.d.ts.map +1 -0
  82. package/dist/src/codegen/__tests__/generate-editor.test.js +103 -0
  83. package/dist/src/codegen/__tests__/generate-editor.test.js.map +1 -0
  84. package/dist/src/codegen/__tests__/generate-manifest.test.d.ts +2 -0
  85. package/dist/src/codegen/__tests__/generate-manifest.test.d.ts.map +1 -0
  86. package/dist/src/codegen/__tests__/generate-manifest.test.js +206 -0
  87. package/dist/src/codegen/__tests__/generate-manifest.test.js.map +1 -0
  88. package/dist/src/codegen/__tests__/generate-schemas.test.d.ts +2 -0
  89. package/dist/src/codegen/__tests__/generate-schemas.test.d.ts.map +1 -0
  90. package/dist/src/codegen/__tests__/generate-schemas.test.js +143 -0
  91. package/dist/src/codegen/__tests__/generate-schemas.test.js.map +1 -0
  92. package/dist/src/codegen/__tests__/ts-morph-generator.test.d.ts +2 -0
  93. package/dist/src/codegen/__tests__/ts-morph-generator.test.d.ts.map +1 -0
  94. package/dist/src/codegen/__tests__/ts-morph-generator.test.js +72 -0
  95. package/dist/src/codegen/__tests__/ts-morph-generator.test.js.map +1 -0
  96. package/dist/src/codegen/__tests__/utils.d.ts +5 -0
  97. package/dist/src/codegen/__tests__/utils.d.ts.map +1 -0
  98. package/dist/src/codegen/__tests__/utils.js +31 -0
  99. package/dist/src/codegen/__tests__/utils.js.map +1 -0
  100. package/dist/src/codegen/generate.d.ts +1 -1
  101. package/dist/src/codegen/generate.d.ts.map +1 -1
  102. package/dist/src/codegen/generate.js +10 -9
  103. package/dist/src/codegen/generate.js.map +1 -1
  104. package/dist/src/codegen/hygen.d.ts +5 -7
  105. package/dist/src/codegen/hygen.d.ts.map +1 -1
  106. package/dist/src/codegen/hygen.js +28 -6
  107. package/dist/src/codegen/hygen.js.map +1 -1
  108. package/dist/src/ts-morph-generator/__tests__/ReducerGenerator.test.d.ts +2 -0
  109. package/dist/src/ts-morph-generator/__tests__/ReducerGenerator.test.d.ts.map +1 -0
  110. package/dist/src/ts-morph-generator/__tests__/ReducerGenerator.test.js +491 -0
  111. package/dist/src/ts-morph-generator/__tests__/ReducerGenerator.test.js.map +1 -0
  112. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts +3 -1
  113. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts.map +1 -1
  114. package/dist/src/ts-morph-generator/core/FileGenerator.js +3 -1
  115. package/dist/src/ts-morph-generator/core/FileGenerator.js.map +1 -1
  116. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts +1 -0
  117. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts.map +1 -1
  118. package/dist/src/ts-morph-generator/core/ReducerGenerator.d.ts.map +1 -1
  119. package/dist/src/ts-morph-generator/core/ReducerGenerator.js +14 -7
  120. package/dist/src/ts-morph-generator/core/ReducerGenerator.js.map +1 -1
  121. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts +2 -1
  122. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts.map +1 -1
  123. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js +8 -3
  124. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js.map +1 -1
  125. package/dist/src/ts-morph-generator/utilities/DeclarationManager.d.ts +5 -0
  126. package/dist/src/ts-morph-generator/utilities/DeclarationManager.d.ts.map +1 -0
  127. package/dist/src/ts-morph-generator/utilities/DeclarationManager.js +10 -0
  128. package/dist/src/ts-morph-generator/utilities/DeclarationManager.js.map +1 -0
  129. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts +1 -0
  130. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts.map +1 -1
  131. package/dist/src/ts-morph-generator/utilities/ImportManager.js +13 -3
  132. package/dist/src/ts-morph-generator/utilities/ImportManager.js.map +1 -1
  133. package/dist/src/ts-morph-generator/utilities/index.d.ts +1 -0
  134. package/dist/src/ts-morph-generator/utilities/index.d.ts.map +1 -1
  135. package/dist/src/ts-morph-generator/utilities/index.js +1 -0
  136. package/dist/src/ts-morph-generator/utilities/index.js.map +1 -1
  137. package/dist/src/utils/validation.d.ts.map +1 -1
  138. package/dist/src/utils/validation.js +3 -4
  139. package/dist/src/utils/validation.js.map +1 -1
  140. package/dist/tsconfig.tsbuildinfo +1 -0
  141. package/dist/vitest.config.d.ts +3 -0
  142. package/dist/vitest.config.d.ts.map +1 -0
  143. package/dist/vitest.config.js +15 -0
  144. package/dist/vitest.config.js.map +1 -0
  145. package/package.json +12 -11
  146. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/lib.inject_export.esm.t +0 -7
  147. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.esm.t +0 -15
  148. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/lib.inject_export.esm.t +0 -7
  149. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/hooks.esm.t +0 -16
  150. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +0 -15
  151. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/lib.inject_export.esm.t +0 -7
  152. 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,13 +1,25 @@
1
1
  // @ts-check
2
- const { paramCase } = require("change-case");
2
+ const { paramCase, pascalCase, camelCase } = require("change-case");
3
3
 
4
- const generateDocumentModelMutations = {
4
+ module.exports = {
5
5
  params: ({ args }) => {
6
6
  const documentModel = JSON.parse(args.documentModel);
7
7
  const latestSpec =
8
8
  documentModel.specifications[documentModel.specifications.length - 1];
9
-
9
+ const documentType = documentModel.name;
10
+ const pascalCaseDocumentType = pascalCase(documentType);
11
+ const camelCaseDocumentType = camelCase(documentType);
12
+ const phDocumentTypeName = `${pascalCaseDocumentType}Document`;
13
+ const documentTypeVariableName = `${camelCaseDocumentType}DocumentType`;
14
+ const packageName = args.packageName;
15
+ const paramCaseDocumentType = paramCase(documentType);
16
+ const documentModelDir = `${packageName}/document-models/${paramCaseDocumentType}`;
10
17
  return {
18
+ phDocumentTypeName,
19
+ documentTypeVariableName,
20
+ pascalCaseDocumentType,
21
+ camelCaseDocumentType,
22
+ documentModelDir,
11
23
  rootDir: args.rootDir,
12
24
  subgraph: args.subgraph,
13
25
  documentTypeId: documentModel.id,
@@ -20,4 +32,3 @@ const generateDocumentModelMutations = {
20
32
  };
21
33
  },
22
34
  };
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
  }
@@ -2,13 +2,10 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/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: "<%= rootDir %>/<%= h.changeCase.param(name) %>/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
+