@powerhousedao/codegen 4.1.0-dev.5 → 4.1.0-dev.51

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 (92) hide show
  1. package/README.md +0 -1
  2. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.d.ts +14 -0
  3. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.d.ts.map +1 -0
  4. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.js +12 -0
  5. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.js.map +1 -0
  6. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/resolvers.esm.t +17 -0
  7. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/schema.esm.t +16 -0
  8. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.esm.t +9 -1
  9. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/object.esm.t +6 -6
  10. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/ph-factories.esm.t +96 -0
  11. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +7 -3
  12. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootIndex.esm.t +2 -4
  13. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +8 -6
  14. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +45 -38
  15. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t +2 -2
  16. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t +6 -10
  17. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +5 -1
  18. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts.map +1 -1
  19. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +16 -1
  20. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js.map +1 -1
  21. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/object.esm.t +2 -7
  22. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/resolvers.esm.t +63 -50
  23. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t +3 -3
  24. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/CreateDocument.esm.t +38 -24
  25. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +243 -180
  26. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EditorContainer.esm.t +53 -74
  27. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderTree.esm.t +44 -26
  28. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +22 -58
  29. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.d.ts +16 -0
  30. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.d.ts.map +1 -0
  31. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.esm.t +2 -3
  32. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js +12 -0
  33. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js.map +1 -0
  34. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +1 -1
  35. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts +2 -0
  36. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts.map +1 -1
  37. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +2 -5
  38. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +1 -0
  39. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js.map +1 -1
  40. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/factory.esm.t +4 -3
  41. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.esm.t +3 -8
  42. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.esm.t +7 -5
  43. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_call.esm.t +1 -1
  44. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_import.esm.t +1 -1
  45. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/factory.esm.t +4 -3
  46. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.esm.t +3 -9
  47. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.esm.t +8 -9
  48. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_call.esm.t +2 -2
  49. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_import.esm.t +1 -1
  50. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/migrations.esm.t +1 -1
  51. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/schema.esm.t +10 -2
  52. package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.esm.t +2 -33
  53. package/dist/src/codegen/graphql.d.ts +2 -2
  54. package/dist/src/codegen/graphql.d.ts.map +1 -1
  55. package/dist/src/codegen/graphql.js.map +1 -1
  56. package/dist/src/codegen/hygen.d.ts +8 -6
  57. package/dist/src/codegen/hygen.d.ts.map +1 -1
  58. package/dist/src/codegen/hygen.js +35 -8
  59. package/dist/src/codegen/hygen.js.map +1 -1
  60. package/dist/src/codegen/index.d.ts +8 -7
  61. package/dist/src/codegen/index.d.ts.map +1 -1
  62. package/dist/src/codegen/index.js +80 -7
  63. package/dist/src/codegen/index.js.map +1 -1
  64. package/dist/src/codegen/utils.d.ts +1 -1
  65. package/dist/src/codegen/utils.d.ts.map +1 -1
  66. package/dist/src/codegen/utils.js +1 -1
  67. package/dist/src/codegen/utils.js.map +1 -1
  68. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts +3 -3
  69. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts.map +1 -1
  70. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts +9 -7
  71. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts.map +1 -1
  72. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts +3 -2
  73. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts.map +1 -1
  74. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js +9 -7
  75. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js.map +1 -1
  76. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts +4 -1
  77. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts.map +1 -1
  78. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js +86 -15
  79. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js.map +1 -1
  80. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts +2 -2
  81. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts.map +1 -1
  82. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts +1 -1
  83. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts.map +1 -1
  84. package/dist/src/utils/validation.d.ts +1 -1
  85. package/dist/src/utils/validation.d.ts.map +1 -1
  86. package/dist/tsconfig.hygen.tsbuildinfo +1 -1
  87. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  88. package/package.json +13 -6
  89. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FileItemsGrid.esm.t +0 -44
  90. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderItemsGrid.esm.t +0 -96
  91. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/hooks/useSelectedFolderChildren.esm.t +0 -35
  92. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/hooks/useTransformedNodes.esm.t +0 -35
package/README.md CHANGED
@@ -16,7 +16,6 @@ A powerful code generation toolkit for the Powerhouse ecosystem, designed to aut
16
16
  pnpm add @powerhousedao/codegen
17
17
  ```
18
18
 
19
-
20
19
  ## Templates
21
20
 
22
21
  The package supports custom templates for different output formats:
@@ -0,0 +1,14 @@
1
+ export type Args = {
2
+ rootDir: string;
3
+ subgraph: string;
4
+ };
5
+ declare const generateCustomSubgraph: {
6
+ params: ({ args, }: {
7
+ args: Args;
8
+ }) => {
9
+ rootDir: string;
10
+ subgraph: string;
11
+ };
12
+ };
13
+ export default generateCustomSubgraph;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,QAAA,MAAM,sBAAsB;wBAGvB;QACD,IAAI,EAAE,IAAI,CAAC;KACZ,KAAG;QACF,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;KAClB;CAMF,CAAC;AACF,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const generateCustomSubgraph = {
4
+ params: ({ args, }) => {
5
+ return {
6
+ rootDir: args.rootDir,
7
+ subgraph: args.subgraph,
8
+ };
9
+ },
10
+ };
11
+ exports.default = generateCustomSubgraph;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.ts"],"names":[],"mappings":";;AAKA,MAAM,sBAAsB,GAAG;IAC7B,MAAM,EAAE,CAAC,EACP,IAAI,GAGL,EAGC,EAAE;QACF,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC;CACF,CAAC;AACF,kBAAe,sBAAsB,CAAC"}
@@ -0,0 +1,17 @@
1
+ ---
2
+ to: "<%= rootDir %>/<%= h.changeCase.param(subgraph) %>/resolvers.ts"
3
+ force: true
4
+ ---
5
+ import { type Subgraph } from "@powerhousedao/reactor-api";
6
+
7
+ export const getResolvers = (subgraph: Subgraph): Record<string, unknown> => {
8
+ const reactor = subgraph.reactor;
9
+
10
+ return ({
11
+ Query: {
12
+ example: async (parent: unknown, args: { driveId: string }) => {
13
+ return "example";
14
+ },
15
+ },
16
+ });
17
+ };
@@ -0,0 +1,16 @@
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
+ Subgraph definition
11
+ """
12
+ type Query {
13
+ example(driveId: String!): String
14
+ }
15
+
16
+ `
@@ -6,4 +6,12 @@ export * from './actions.js';
6
6
  export * from './document-model.js';
7
7
  export * from './object.js';
8
8
  export * from './types.js';
9
- export * as actions from './creators.js';
9
+ export * as actions from './creators.js';
10
+ export type { <%= h.changeCase.pascal(documentType) %>PHState } from './ph-factories.js';
11
+ export {
12
+ create<%= h.changeCase.pascal(documentType) %>Document,
13
+ createState,
14
+ defaultPHState,
15
+ defaultGlobalState,
16
+ defaultLocalState,
17
+ } from './ph-factories.js';
@@ -2,11 +2,11 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/object.ts"
3
3
  force: true
4
4
  ---
5
- import { BaseDocumentClass, type ExtendedState, type PartialState, applyMixins, type SignalDispatch } from 'document-model';
6
- import { <%= 'type ' + h.changeCase.pascal(documentType) %>State, <%= 'type ' + h.changeCase.pascal(documentType) %>LocalState } from './types.js';
5
+ import { BaseDocumentClass, applyMixins, type SignalDispatch } from 'document-model';
6
+ import { <%= h.changeCase.pascal(documentType) %>PHState } from './ph-factories.js';
7
7
  import { <%= 'type ' + h.changeCase.pascal(documentType) %>Action } from './actions.js';
8
8
  import { reducer } from './reducer.js';
9
- import utils from './utils.js';
9
+ import { createDocument } from './utils.js';
10
10
  <% modules.forEach(module => { _%>
11
11
  import <%= h.changeCase.pascal(documentType) %>_<%= h.changeCase.pascal(module.name) %> from './<%= module.name %>/object.js';
12
12
  <% }); _%>
@@ -20,11 +20,11 @@ interface <%= h.changeCase.pascal(documentType) %> extends
20
20
  <%= modules.map(m => ' ' + h.changeCase.pascal(documentType) + '_' + h.changeCase.pascal(m.name)).join(',\n') %> {}
21
21
 
22
22
  // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
23
- class <%= h.changeCase.pascal(documentType) %> extends BaseDocumentClass<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState, <%= h.changeCase.pascal(documentType) %>Action> {
23
+ class <%= h.changeCase.pascal(documentType) %> extends BaseDocumentClass<<%= h.changeCase.pascal(documentType) %>PHState> {
24
24
  static fileExtension = '<%= extension %>';
25
25
 
26
- constructor(initialState?: Partial<ExtendedState<PartialState<<%= h.changeCase.pascal(documentType) %>State>, PartialState<<%= h.changeCase.pascal(documentType) %>LocalState>>>, dispatch?: SignalDispatch) {
27
- super(reducer, utils.createDocument(initialState), dispatch);
26
+ constructor(initialState?: Partial<<%= h.changeCase.pascal(documentType) %>PHState>, dispatch?: SignalDispatch) {
27
+ super(reducer, createDocument(initialState), dispatch);
28
28
  }
29
29
 
30
30
  public saveToFile(path: string, name?: string) {
@@ -0,0 +1,96 @@
1
+ ---
2
+ to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/ph-factories.ts"
3
+ force: true
4
+ ---
5
+ /**
6
+ * Factory methods for creating <%= h.changeCase.pascal(documentType) %>Document instances
7
+ */
8
+
9
+ import {
10
+ createBaseState,
11
+ defaultBaseState,
12
+ type PHAuthState,
13
+ type PHDocumentState,
14
+ type PHBaseState,
15
+ } from "document-model";
16
+ import type {
17
+ <%= h.changeCase.pascal(documentType) %>Document,
18
+ <%= h.changeCase.pascal(documentType) %>LocalState,
19
+ <%= h.changeCase.pascal(documentType) %>State,
20
+ } from "./types.js";
21
+ import { createDocument } from "./utils.js";
22
+
23
+ export type <%= h.changeCase.pascal(documentType) %>PHState = PHBaseState & {
24
+ global: <%= h.changeCase.pascal(documentType) %>State;
25
+ local: <%= h.changeCase.pascal(documentType) %>LocalState;
26
+ };
27
+
28
+ export function defaultGlobalState(): <%= h.changeCase.pascal(documentType) %>State {
29
+ return <%- initialGlobalState %>;
30
+ }
31
+
32
+ export function defaultLocalState(): <%= h.changeCase.pascal(documentType) %>LocalState {
33
+ return <%- initialLocalState %>;
34
+ }
35
+
36
+ export function defaultPHState(): <%= h.changeCase.pascal(documentType) %>PHState {
37
+ return {
38
+ ...defaultBaseState(),
39
+ global: defaultGlobalState(),
40
+ local: defaultLocalState(),
41
+ };
42
+ }
43
+
44
+ export function createGlobalState(
45
+ state?: Partial<<%= h.changeCase.pascal(documentType) %>State>,
46
+ ): <%= h.changeCase.pascal(documentType) %>State {
47
+ return {
48
+ ...defaultGlobalState(),
49
+ ...(state || {}),
50
+ } as <%= h.changeCase.pascal(documentType) %>State;
51
+ }
52
+
53
+ export function createLocalState(
54
+ state?: Partial<<%= h.changeCase.pascal(documentType) %>LocalState>,
55
+ ): <%= h.changeCase.pascal(documentType) %>LocalState {
56
+ return {
57
+ ...defaultLocalState(),
58
+ ...(state || {}),
59
+ } as <%= h.changeCase.pascal(documentType) %>LocalState;
60
+ }
61
+
62
+ export function createState(
63
+ baseState?: Partial<PHBaseState>,
64
+ globalState?: Partial<<%= h.changeCase.pascal(documentType) %>State>,
65
+ localState?: Partial<<%= h.changeCase.pascal(documentType) %>LocalState>,
66
+ ): <%= h.changeCase.pascal(documentType) %>PHState {
67
+ return {
68
+ ...createBaseState(baseState?.auth, baseState?.document),
69
+ global: createGlobalState(globalState),
70
+ local: createLocalState(localState),
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Creates a <%= h.changeCase.pascal(documentType) %>Document with custom global and local state
76
+ * This properly handles the PHBaseState requirements while allowing
77
+ * document-specific state to be set.
78
+ */
79
+ export function create<%= h.changeCase.pascal(documentType) %>Document(
80
+ state?: Partial<{
81
+ auth?: Partial<PHAuthState>;
82
+ document?: Partial<PHDocumentState>;
83
+ global?: Partial<<%= h.changeCase.pascal(documentType) %>State>;
84
+ local?: Partial<<%= h.changeCase.pascal(documentType) %>LocalState>;
85
+ }>,
86
+ ): <%= h.changeCase.pascal(documentType) %>Document {
87
+ const document = createDocument(
88
+ state ? createState(
89
+ createBaseState(state.auth, state.document),
90
+ state.global,
91
+ state.local,
92
+ ) : undefined
93
+ );
94
+
95
+ return document;
96
+ }
@@ -2,14 +2,18 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/reducer.ts"
3
3
  force: true
4
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 */
5
8
  import { type StateReducer, isDocumentAction, createReducer } from "document-model";
6
- import { <%= 'type ' + h.changeCase.pascal(documentType) %>Document, z } from './types.js';
9
+ import { <%= h.changeCase.pascal(documentType) %>PHState } from './ph-factories.js';
10
+ import { z } from './types.js';
7
11
 
8
12
  <% modules.forEach(m => { _%>
9
13
  import { reducer as <%= h.changeCase.pascal(m.name) %>Reducer } from '../src/reducers/<%= h.changeCase.param(m.name) %>.js';
10
14
  <%_ }); %>
11
15
 
12
- const stateReducer: StateReducer<<%= h.changeCase.pascal(documentType) %>Document> =
16
+ export const stateReducer: StateReducer<<%= h.changeCase.pascal(documentType) %>PHState> =
13
17
  (state, action, dispatch) => {
14
18
  if (isDocumentAction(action)) {
15
19
  return state;
@@ -31,4 +35,4 @@ const stateReducer: StateReducer<<%= h.changeCase.pascal(documentType) %>Documen
31
35
  }
32
36
  }
33
37
 
34
- export const reducer = createReducer<<%= h.changeCase.pascal(documentType) %>Document>(stateReducer);
38
+ export const reducer = createReducer<<%= h.changeCase.pascal(documentType) %>PHState>(stateReducer);
@@ -13,15 +13,13 @@ import { reducer } from './gen/reducer.js';
13
13
  import { documentModel } from './gen/document-model.js';
14
14
  import genUtils from './gen/utils.js';
15
15
  import * as customUtils from './src/utils.js';
16
- import {
17
- <%= 'type ' + h.changeCase.pascal(documentType) %>Document,
18
- } from './gen/types.js';
16
+ import type { <%= h.changeCase.pascal(documentType) %>PHState } from './gen/ph-factories.js';
19
17
 
20
18
  const utils = { ...genUtils, ...customUtils };
21
19
  const actions = { ...BaseActions, ...<%= h.changeCase.pascal(documentType) %>Actions };
22
20
 
23
21
  export const module: DocumentModelModule<
24
- <%= h.changeCase.pascal(documentType) %>Document
22
+ <%= h.changeCase.pascal(documentType) %>PHState
25
23
  > = {
26
24
  reducer,
27
25
  actions,
@@ -2,18 +2,20 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/types.ts"
3
3
  force: true
4
4
  ---
5
- import type { PHDocument, ExtendedState } from 'document-model';
6
- import type { <%= h.changeCase.pascal(documentType) %>State } from './schema/types.js';
5
+ import type { PHDocument } from 'document-model';
6
+ import type { <%= h.changeCase.pascal(documentType) %>Action } from './actions.js';
7
+ import type { <%= h.changeCase.pascal(documentType) %>PHState } from './ph-factories.js';
8
+ import type {
9
+ <%= h.changeCase.pascal(documentType) %>State,
7
10
  <% if(hasLocalSchema) { -%>
8
- import type { <%= h.changeCase.pascal(documentType) %>LocalState } from './schema/types.js';
11
+ <%= h.changeCase.pascal(documentType) %>LocalState,
9
12
  <%} -%>
10
- import type { <%= h.changeCase.pascal(documentType) %>Action } from './actions.js';
13
+ } from './schema/types.js';
11
14
 
12
15
  export { z } from './schema/index.js';
13
16
  export type * from './schema/types.js';
14
17
  <% if(!hasLocalSchema) { -%>
15
18
  <%= 'type ' + h.changeCase.pascal(documentType) %>LocalState = Record<PropertyKey, never>;
16
19
  <%} -%>
17
- export type Extended<%= h.changeCase.pascal(documentType) %>State = ExtendedState<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState>;
18
- export <%= 'type ' + h.changeCase.pascal(documentType) %>Document = PHDocument<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState>;
20
+ export type <%= h.changeCase.pascal(documentType) %>Document = PHDocument<<%= h.changeCase.pascal(documentType) %>PHState>;
19
21
  export type { <%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState, <%= h.changeCase.pascal(documentType) %>Action };
@@ -3,61 +3,68 @@ to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/utils.ts"
3
3
  force: true
4
4
  ---
5
5
  import {
6
- type DocumentModelUtils,
6
+ type CreateDocument,
7
+ type CreateState,
8
+ type LoadFromFile,
9
+ type LoadFromInput,
7
10
  baseCreateDocument,
8
- baseCreateExtendedState,
9
11
  baseSaveToFile,
10
12
  baseSaveToFileHandle,
11
13
  baseLoadFromFile,
12
14
  baseLoadFromInput,
15
+ defaultBaseState,
13
16
  generateId,
14
17
  } from 'document-model';
15
18
  import {
16
- <%= 'type ' + h.changeCase.pascal(documentType) %>Document,
17
19
  <%= 'type ' + h.changeCase.pascal(documentType) %>State,
18
20
  <%= 'type ' + h.changeCase.pascal(documentType) %>LocalState
19
21
  } from './types.js';
22
+ import { <%= h.changeCase.pascal(documentType) %>PHState } from './ph-factories.js';
20
23
  import { reducer } from './reducer.js';
21
24
 
22
25
  export const initialGlobalState: <%= h.changeCase.pascal(documentType) %>State = <%- initialGlobalState %>;
23
26
  export const initialLocalState: <%= h.changeCase.pascal(documentType) %>LocalState = <%- initialLocalState %>;
24
27
 
25
- const utils: DocumentModelUtils<<%= h.changeCase.pascal(documentType) %>Document> = {
28
+ export const createState: CreateState<<%= h.changeCase.pascal(documentType) %>PHState> = (state) => {
29
+ return {
30
+ ...defaultBaseState(),
31
+ global: { ...initialGlobalState, ...(state?.global ?? {}) },
32
+ local: { ...initialLocalState, ...(state?.local ?? {}) }
33
+ };
34
+ };
35
+
36
+ export const createDocument: CreateDocument<<%= h.changeCase.pascal(documentType) %>PHState> = (state) => {
37
+ const document = baseCreateDocument(createState, state);
38
+ document.header.documentType = '<%- documentTypeId %>';
39
+ // for backwards compatibility, but this is NOT a valid signed document id
40
+ document.header.id = generateId();
41
+ return document;
42
+ };
43
+
44
+ export const saveToFile = (document: any, path: string, name?: string) => {
45
+ return baseSaveToFile(document, path, '<%- fileExtension %>', name);
46
+ };
47
+
48
+ export const saveToFileHandle = (document: any, input: any) => {
49
+ return baseSaveToFileHandle(document, input);
50
+ };
51
+
52
+ export const loadFromFile: LoadFromFile<<%= h.changeCase.pascal(documentType) %>PHState> = (path) => {
53
+ return baseLoadFromFile(path, reducer);
54
+ };
55
+
56
+ export const loadFromInput: LoadFromInput<<%= h.changeCase.pascal(documentType) %>PHState> = (input) => {
57
+ return baseLoadFromInput(input, reducer);
58
+ };
59
+
60
+ const utils = {
26
61
  fileExtension: '<%- fileExtension %>',
27
- createState(state) {
28
- return { global: { ...initialGlobalState, ...state?.global }, local: { ...initialLocalState, ...state?.local } };
29
- },
30
- createExtendedState(extendedState) {
31
- return baseCreateExtendedState(
32
- { ...extendedState },
33
- utils.createState
34
- );
35
- },
36
- createDocument(state) {
37
- const document = baseCreateDocument(
38
- utils.createExtendedState(state),
39
- utils.createState
40
- );
41
-
42
- document.header.documentType = '<%- documentTypeId %>';
43
-
44
- // for backwards compatibility, but this is NOT a valid signed document id
45
- document.header.id = generateId();
46
-
47
- return document;
48
- },
49
- saveToFile(document, path, name) {
50
- return baseSaveToFile(document, path, '<%- fileExtension %>', name);
51
- },
52
- saveToFileHandle(document, input) {
53
- return baseSaveToFileHandle(document, input);
54
- },
55
- loadFromFile(path) {
56
- return baseLoadFromFile(path, reducer);
57
- },
58
- loadFromInput(input) {
59
- return baseLoadFromInput(input, reducer);
60
- },
62
+ createState,
63
+ createDocument,
64
+ saveToFile,
65
+ saveToFileHandle,
66
+ loadFromFile,
67
+ loadFromInput,
61
68
  };
62
69
 
63
70
  export default utils;
@@ -39,10 +39,10 @@ describe('<%= h.changeCase.pascal(module) %> Operations', () => {
39
39
  );
40
40
 
41
41
  expect(updatedDocument.operations.<%= action.scope %>).toHaveLength(1);
42
- expect(updatedDocument.operations.<%= action.scope %>[0].type).toBe(
42
+ expect(updatedDocument.operations.<%= action.scope %>[0].action.type).toBe(
43
43
  '<%= h.changeCase.constant(action.name) %>',
44
44
  );
45
- expect(updatedDocument.operations.<%= action.scope %>[0].input).toStrictEqual(input);
45
+ expect(updatedDocument.operations.<%= action.scope %>[0].action.input).toStrictEqual(input);
46
46
  expect(updatedDocument.operations.<%= action.scope %>[0].index).toEqual(0);
47
47
  });
48
48
  <% }); _%>
@@ -2,20 +2,17 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/error.ts"
3
3
  force: true
4
4
  ---
5
- <% if (actions.some(action => action.errors?.length > 0)) { _%>
5
+ <% if (errors.length > 0) { _%>
6
6
  export type ErrorCode =
7
- <% actions.forEach((action, actionIndex) => { _%>
8
- <% action.errors.forEach((error, errorIndex) => { _%>
9
- | '<%= h.changeCase.pascal(error.name) %>'<% if (actionIndex === actions.length - 1 && errorIndex === action.errors.length - 1) { %>;<% } %>
10
- <% }); _%>
7
+ <% errors.forEach((error, errorIndex) => { _%>
8
+ | '<%= h.changeCase.pascal(error.name) %>'<% if (errorIndex === errors.length - 1) { %>;<% } %>
11
9
  <% }); _%>
12
10
 
13
11
  export interface ReducerError {
14
12
  errorCode: ErrorCode;
15
13
  }
16
14
 
17
- <% actions.forEach(action => { _%>
18
- <% action.errors.forEach(error => { _%>
15
+ <% errors.forEach(error => { _%>
19
16
  export class <%= h.changeCase.pascal(error.name) %> extends Error implements ReducerError {
20
17
  errorCode = '<%= h.changeCase.pascal(error.name) %>' as ErrorCode;
21
18
  constructor(message = '<%= h.changeCase.pascal(error.name) %>') {
@@ -23,7 +20,6 @@ export class <%= h.changeCase.pascal(error.name) %> extends Error implements Red
23
20
  }
24
21
  }
25
22
 
26
- <% }); _%>
27
23
  <% }); _%>
28
24
 
29
25
  <% } _%>
@@ -32,9 +28,9 @@ export const errors = {
32
28
  <% if(action.errors?.length > 0){ -%>
33
29
  <%= h.changeCase.pascal(action.name) %>: {
34
30
  <% action.errors.forEach(error => { _%>
35
- <%= h.changeCase.pascal(error.name) %>,
31
+ <%= h.changeCase.pascal(error.name) %>,
36
32
  <% }); _%>
37
- },
33
+ },
38
34
  <% } -%>
39
35
  <% }); _%>
40
36
  };
@@ -1,13 +1,16 @@
1
- import { type Args } from "../generate-document-model/index.js";
1
+ import type { DocumentModelState } from "document-model";
2
+ import type { Args } from "../generate-document-model/index.js";
2
3
  type ModuleArgs = Args & {
3
4
  module: string;
4
5
  };
6
+ type OperationError = DocumentModelState["specifications"][number]["modules"][number]["operations"][number]["errors"][number];
5
7
  type Actions = {
6
8
  name: string | null;
7
9
  hasInput: boolean;
8
10
  hasAttachment: boolean | undefined;
9
11
  scope: string;
10
12
  state: string;
13
+ errors: OperationError[];
11
14
  };
12
15
  declare const _default: {
13
16
  params: ({ args }: {
@@ -17,6 +20,7 @@ declare const _default: {
17
20
  documentType: string;
18
21
  module: string;
19
22
  actions: Actions[];
23
+ errors: import("document-model").DocumentModelOperationError[];
20
24
  };
21
25
  };
22
26
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAEhE,KAAK,UAAU,GAAG,IAAI,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC5C,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;;uBAGmB;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE;;;;;;;AADzC,wBA6BE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAEhE,KAAK,UAAU,GAAG,IAAI,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAC5C,KAAK,cAAc,GACjB,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1G,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B,CAAC;;uBAGmB;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE;;;;;;;;AADzC,wBAiDE"}
@@ -11,17 +11,32 @@ exports.default = {
11
11
  name: a.name,
12
12
  hasInput: a.schema !== null,
13
13
  hasAttachment: a.schema?.includes(": Attachment"),
14
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
15
14
  scope: a.scope || "global",
16
15
  state: a.scope === "global" ? "" : a.scope, // the state this action affects
17
16
  errors: a.errors,
18
17
  }))
19
18
  : [];
19
+ const errors = actions.reduce((acc, action) => {
20
+ action.errors.forEach((error) => {
21
+ // Fallback: If error code is empty, generate it from the error name in PascalCase
22
+ const errorCode = error.code || (0, change_case_1.pascalCase)(error.name || "");
23
+ const normalizedError = { ...error, code: errorCode };
24
+ const existingError = acc.find((e) => e.code === errorCode);
25
+ if (!existingError) {
26
+ acc.push(normalizedError);
27
+ }
28
+ else if (JSON.stringify(existingError) !== JSON.stringify(normalizedError)) {
29
+ console.warn(`Warning: Duplicate error code "${errorCode}" with different fields found`);
30
+ }
31
+ });
32
+ return acc;
33
+ }, []);
20
34
  return {
21
35
  rootDir: args.rootDir,
22
36
  documentType: documentModel.name,
23
37
  module: (0, change_case_1.paramCase)(args.module),
24
38
  actions,
39
+ errors,
25
40
  };
26
41
  },
27
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.ts"],"names":[],"mappings":";;AAAA,6CAAwC;AAaxC,kBAAe;IACb,MAAM,EAAE,CAAC,EAAE,IAAI,EAAwB,EAAE,EAAE;QACzC,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAuB,CAAC;QAC3E,MAAM,UAAU,GACd,aAAa,CAAC,cAAc,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxE,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAC/C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAC9B,CAAC;QAEF,MAAM,OAAO,GACX,eAAe,CAAC,MAAM,GAAG,CAAC;YACxB,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACxC,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,QAAQ,EAAE,CAAC,CAAC,MAAM,KAAK,IAAI;gBAC3B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC;gBACjD,uEAAuE;gBACvE,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,QAAQ;gBAC1B,KAAK,EAAE,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,gCAAgC;gBAC5E,MAAM,EAAE,CAAC,CAAC,MAAM;aACjB,CAAC,CAAC;YACL,CAAC,CAAC,EAAE,CAAC;QAET,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,aAAa,CAAC,IAAI;YAChC,MAAM,EAAE,IAAA,uBAAS,EAAC,IAAI,CAAC,MAAM,CAAC;YAC9B,OAAO;SACR,CAAC;IACJ,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.ts"],"names":[],"mappings":";;AAAA,6CAAoD;AAgBpD,kBAAe;IACb,MAAM,EAAE,CAAC,EAAE,IAAI,EAAwB,EAAE,EAAE;QACzC,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAuB,CAAC;QAC3E,MAAM,UAAU,GACd,aAAa,CAAC,cAAc,CAAC,aAAa,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACxE,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAC/C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAC9B,CAAC;QAEF,MAAM,OAAO,GACX,eAAe,CAAC,MAAM,GAAG,CAAC;YACxB,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACxC,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,QAAQ,EAAE,CAAC,CAAC,MAAM,KAAK,IAAI;gBAC3B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,CAAC;gBACjD,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,QAAQ;gBAC1B,KAAK,EAAE,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,gCAAgC;gBAC5E,MAAM,EAAE,CAAC,CAAC,MAAM;aACjB,CAAC,CAAC;YACL,CAAC,CAAC,EAAE,CAAC;QAET,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;YAC9D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC9B,kFAAkF;gBAClF,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,IAAI,IAAA,wBAAU,EAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;gBAC7D,MAAM,eAAe,GAAG,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;gBAEtD,MAAM,aAAa,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;gBAC5D,IAAI,CAAC,aAAa,EAAE,CAAC;oBACnB,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;gBAC5B,CAAC;qBAAM,IACL,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EACjE,CAAC;oBACD,OAAO,CAAC,IAAI,CACV,kCAAkC,SAAS,+BAA+B,CAC3E,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,aAAa,CAAC,IAAI;YAChC,MAAM,EAAE,IAAA,uBAAS,EAAC,IAAI,CAAC,MAAM,CAAC;YAC9B,OAAO;YACP,MAAM;SACP,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -3,12 +3,11 @@ to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/ob
3
3
  force: true
4
4
  ---
5
5
  import { BaseDocumentClass<% if (actions.find(a => a.hasAttachment)) {%>, AttachmentInput<%}%> } from 'document-model';
6
+ import { <%= h.changeCase.pascal(documentType) %>PHState } from '../ph-factories.js';
6
7
  import {
7
8
  <% actions.filter(action => action.hasInput).forEach(action => { _%>
8
9
  <%= 'type ' + h.changeCase.pascal(action.name) %>Input,
9
10
  <% }); _%>
10
- <%= 'type ' + h.changeCase.pascal(documentType) %>State,
11
- <%= 'type ' + h.changeCase.pascal(documentType) %>LocalState
12
11
  } from '../types.js';
13
12
  import {
14
13
  <% actions.forEach(action => { _%>
@@ -17,11 +16,7 @@ import {
17
16
  } from './creators.js';
18
17
  import { <%= 'type ' + h.changeCase.pascal(documentType) %>Action } from '../actions.js';
19
18
 
20
- export default class <%= h.changeCase.pascal(documentType) %>_<%= h.changeCase.pascal(module) %> extends BaseDocumentClass<
21
- <%= h.changeCase.pascal(documentType) %>State,
22
- <%= h.changeCase.pascal(documentType) %>LocalState,
23
- <%= h.changeCase.pascal(documentType) %>Action
24
- > {
19
+ export default class <%= h.changeCase.pascal(documentType) %>_<%= h.changeCase.pascal(module) %> extends BaseDocumentClass<<%= h.changeCase.pascal(documentType) %>PHState> {
25
20
  <% actions.filter(action => action.hasInput).forEach(action => { _%>
26
21
  public <%= h.changeCase.camel(action.name) %>(input: <%= h.changeCase.pascal(action.name) %>Input<%if(action.hasAttachment){ %>, attachments: AttachmentInput[] <% } %>) {
27
22
  return this.dispatch(<%= h.changeCase.camel(action.name) %>(input<%if(action.hasAttachment){ %>, attachments<% } %>));