@powerhousedao/codegen 0.37.0 → 0.37.1
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.
- package/dist/src/codegen/.hygen/package.json +3 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/actions.esm.t +16 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/creators.esm.t +8 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/customUtils.esm.t +5 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModel.esm.t +7 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModelTest.esm.t +25 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.esm.t +9 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/lib.esm.t +9 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/lib.inject_export.esm.t +7 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/object.esm.t +49 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +35 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootIndex.esm.t +41 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/schema.esm.t +6 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +19 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +43 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/actions.esm.t +22 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/creators.esm.t +34 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customReducers.esm.t +20 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t +53 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t +40 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/object.esm.t +37 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/operations.esm.t +17 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/resolvers.esm.t +62 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/schema.esm.t +31 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +23 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +22 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/lib.esm.t +9 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/lib.inject_export.esm.t +7 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/story.esm.t +31 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.esm.t +59 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/utils.esm.t +100 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.esm.t +66 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.esm.t +9 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_export.esm.t +7 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.esm.t +62 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/lib.esm.t +9 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/lib.inject_export.esm.t +8 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.esm.t +61 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/lib.esm.t +9 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/lib.inject_export.esm.t +7 -0
- package/dist/src/codegen/hygen.d.ts +1 -1
- package/dist/src/codegen/hygen.d.ts.map +1 -1
- package/dist/src/codegen/hygen.js +2 -2
- package/dist/src/codegen/index.d.ts +0 -1
- package/dist/src/codegen/index.d.ts.map +1 -1
- package/dist/src/codegen/index.js +0 -1
- package/dist/tsconfig.hygen.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -5
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.d.ts +0 -25
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.js +0 -60
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +0 -24
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +0 -25
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/index.d.ts +0 -22
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/index.js +0 -19
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts +0 -21
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +0 -13
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.d.ts +0 -14
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.js +0 -8
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.d.ts +0 -21
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.js +0 -13
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.d.ts +0 -20
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.js +0 -13
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.d.ts +0 -16
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.js +0 -9
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/actions.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
<% modules.forEach(module => { _%>
|
|
6
|
+
import { <%= h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module.name) %>Action } from './<%= module.name %>/actions';
|
|
7
|
+
<% }); _%>
|
|
8
|
+
|
|
9
|
+
<% modules.forEach(module => { _%>
|
|
10
|
+
export * from './<%= module.name %>/actions';
|
|
11
|
+
<% }); _%>
|
|
12
|
+
|
|
13
|
+
export type <%= h.changeCase.pascal(documentType) %>Action =
|
|
14
|
+
<% modules.forEach(module => { _%>
|
|
15
|
+
| <%= h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module.name) %>Action
|
|
16
|
+
<% }); _%>;
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModelTest.esm.t
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/src/tests/document-model.test.ts"
|
|
3
|
+
unless_exists: true
|
|
4
|
+
---
|
|
5
|
+
/**
|
|
6
|
+
* This is a scaffold file meant for customization:
|
|
7
|
+
* - change it by adding new tests or modifying the existing ones
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import utils, { initialGlobalState, initialLocalState } from '../../gen/utils';
|
|
11
|
+
|
|
12
|
+
describe('<%= h.changeCase.title(documentType) %> Document Model', () => {
|
|
13
|
+
it('should create a new <%= h.changeCase.title(documentType) %> document', () => {
|
|
14
|
+
const document = utils.createDocument();
|
|
15
|
+
|
|
16
|
+
expect(document).toBeDefined();
|
|
17
|
+
expect(document.documentType).toBe('<%- documentTypeId %>');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should create a new <%= h.changeCase.title(documentType) %> document with a valid initial state', () => {
|
|
21
|
+
const document = utils.createDocument();
|
|
22
|
+
expect(document.state.global).toStrictEqual(initialGlobalState);
|
|
23
|
+
expect(document.state.local).toStrictEqual(initialLocalState);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/object.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
import { BaseDocument, ExtendedState, PartialState, applyMixins, SignalDispatch } from 'document-model/document';
|
|
6
|
+
import { <%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState } from './types';
|
|
7
|
+
import { <%= h.changeCase.pascal(documentType) %>Action } from './actions';
|
|
8
|
+
import { reducer } from './reducer';
|
|
9
|
+
import utils from './utils';
|
|
10
|
+
<% modules.forEach(module => { _%>
|
|
11
|
+
import <%= h.changeCase.pascal(documentType) %>_<%= h.changeCase.pascal(module.name) %> from './<%= module.name %>/object';
|
|
12
|
+
<% }); _%>
|
|
13
|
+
|
|
14
|
+
<% modules.forEach(module => { _%>
|
|
15
|
+
export * from './<%= module.name %>/object';
|
|
16
|
+
<% }); _%>
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
19
|
+
interface <%= h.changeCase.pascal(documentType) %> extends
|
|
20
|
+
<%= modules.map(m => ' ' + h.changeCase.pascal(documentType) + '_' + h.changeCase.pascal(m.name)).join(',\n') %> {}
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
23
|
+
class <%= h.changeCase.pascal(documentType) %> extends BaseDocument<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>Action, <%= h.changeCase.pascal(documentType) %>LocalState> {
|
|
24
|
+
static fileExtension = '<%= extension %>';
|
|
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);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public saveToFile(path: string, name?: string) {
|
|
31
|
+
return super.saveToFile(path, <%= h.changeCase.pascal(documentType) %>.fileExtension, name);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public loadFromFile(path: string) {
|
|
35
|
+
return super.loadFromFile(path);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static async fromFile(path: string) {
|
|
39
|
+
const document = new this();
|
|
40
|
+
await document.loadFromFile(path);
|
|
41
|
+
return document;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
applyMixins(<%= h.changeCase.pascal(documentType) %>, [
|
|
46
|
+
<%= modules.map(m => ' ' + h.changeCase.pascal(documentType) + '_' + h.changeCase.pascal(m.name)).join(',\n') %>
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
export { <%= h.changeCase.pascal(documentType) %> };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/reducer.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
import { ImmutableStateReducer, utils } from "document-model/document";
|
|
6
|
+
import { <%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState, z } from './types';
|
|
7
|
+
import { <%= h.changeCase.pascal(documentType) %>Action } from './actions';
|
|
8
|
+
|
|
9
|
+
<% modules.forEach(m => { _%>
|
|
10
|
+
import { reducer as <%= h.changeCase.pascal(m.name) %>Reducer } from '../src/reducers/<%= h.changeCase.param(m.name) %>';
|
|
11
|
+
<%_ }); %>
|
|
12
|
+
|
|
13
|
+
const stateReducer: ImmutableStateReducer<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>Action, <%= h.changeCase.pascal(documentType) %>LocalState> =
|
|
14
|
+
(state, action, dispatch) => {
|
|
15
|
+
if (utils.isBaseAction(action)) {
|
|
16
|
+
return state;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
switch (action.type) {
|
|
20
|
+
<%-
|
|
21
|
+
modules.map(m => m.operations.map(o =>
|
|
22
|
+
' case "' + h.changeCase.constant(o.name) + '":\n' +
|
|
23
|
+
' ' + (o.schema !== null ?
|
|
24
|
+
'z.' + h.changeCase.pascalCase(o.name) + 'InputSchema().parse(action.input);\n' :
|
|
25
|
+
'if (Object.keys(action.input).length > 0) throw new Error("Expected empty input for action ' + h.changeCase.constant(o.name) + '");\n') +
|
|
26
|
+
' ' + h.changeCase.pascal(m.name) + 'Reducer.' + h.changeCase.camel(o.name) + 'Operation(state[action.scope], action, dispatch);\n' +
|
|
27
|
+
' break;\n'
|
|
28
|
+
).join('\n')).join('\n')
|
|
29
|
+
%>
|
|
30
|
+
default:
|
|
31
|
+
return state;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const reducer = utils.createReducer<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>Action, <%= h.changeCase.pascal(documentType) %>LocalState>(stateReducer);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/index.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
/**
|
|
6
|
+
* This is a scaffold file meant for customization.
|
|
7
|
+
* Delete the file and run the code generator again to have it reset
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { actions as BaseActions, DocumentModel } from 'document-model/document';
|
|
11
|
+
import { actions as <%= h.changeCase.pascal(documentType) %>Actions, <%= h.changeCase.pascal(documentType) %> } from './gen';
|
|
12
|
+
import { reducer } from './gen/reducer';
|
|
13
|
+
import { documentModel } from './gen/document-model';
|
|
14
|
+
import genUtils from './gen/utils';
|
|
15
|
+
import * as customUtils from './src/utils';
|
|
16
|
+
import {
|
|
17
|
+
<%= h.changeCase.pascal(documentType) %>State,
|
|
18
|
+
<%= h.changeCase.pascal(documentType) %>Action,
|
|
19
|
+
<%= h.changeCase.pascal(documentType) %>LocalState,
|
|
20
|
+
} from './gen/types';
|
|
21
|
+
|
|
22
|
+
const Document = <%= h.changeCase.pascal(documentType) %>;
|
|
23
|
+
const utils = { ...genUtils, ...customUtils };
|
|
24
|
+
const actions = { ...BaseActions, ...<%= h.changeCase.pascal(documentType) %>Actions };
|
|
25
|
+
|
|
26
|
+
export const module: DocumentModel<
|
|
27
|
+
<%= h.changeCase.pascal(documentType) %>State,
|
|
28
|
+
<%= h.changeCase.pascal(documentType) %>Action,
|
|
29
|
+
<%= h.changeCase.pascal(documentType) %>LocalState
|
|
30
|
+
> = {
|
|
31
|
+
Document,
|
|
32
|
+
reducer,
|
|
33
|
+
actions,
|
|
34
|
+
utils,
|
|
35
|
+
documentModel,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { <%= h.changeCase.pascal(documentType) %>, Document, reducer, actions, utils, documentModel };
|
|
39
|
+
|
|
40
|
+
export * from './gen/types';
|
|
41
|
+
export * from './src/utils';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/types.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
import type { Document, ExtendedState } from 'document-model/document';
|
|
6
|
+
import type { <%= h.changeCase.pascal(documentType) %>State } from './schema/types';
|
|
7
|
+
<% if(hasLocalSchema) { -%>
|
|
8
|
+
import type { <%= h.changeCase.pascal(documentType) %>LocalState } from './schema/types';
|
|
9
|
+
<%} -%>
|
|
10
|
+
import type { <%= h.changeCase.pascal(documentType) %>Action } from './actions';
|
|
11
|
+
|
|
12
|
+
export { z } from './schema';
|
|
13
|
+
export type * from './schema/types';
|
|
14
|
+
<% if(!hasLocalSchema) { -%>
|
|
15
|
+
type <%= h.changeCase.pascal(documentType) %>LocalState = Record<PropertyKey, never>;
|
|
16
|
+
<%} -%>
|
|
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 = Document<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>Action, <%= h.changeCase.pascal(documentType) %>LocalState>;
|
|
19
|
+
export { <%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState, <%= h.changeCase.pascal(documentType) %>Action };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/utils.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
import { DocumentModelUtils, utils as base } from 'document-model/document';
|
|
6
|
+
import { <%= h.changeCase.pascal(documentType) %>Action, <%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState } from './types';
|
|
7
|
+
import { reducer } from './reducer';
|
|
8
|
+
|
|
9
|
+
export const initialGlobalState: <%= h.changeCase.pascal(documentType) %>State = <%- initialGlobalState %>;
|
|
10
|
+
export const initialLocalState: <%= h.changeCase.pascal(documentType) %>LocalState = <%- initialLocalState %>;
|
|
11
|
+
|
|
12
|
+
const utils: DocumentModelUtils<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>Action, <%= h.changeCase.pascal(documentType) %>LocalState> = {
|
|
13
|
+
fileExtension: '<%- fileExtension %>',
|
|
14
|
+
createState(state) {
|
|
15
|
+
return { global: { ...initialGlobalState, ...state?.global }, local: { ...initialLocalState, ...state?.local } };
|
|
16
|
+
},
|
|
17
|
+
createExtendedState(extendedState) {
|
|
18
|
+
return base.createExtendedState(
|
|
19
|
+
{ ...extendedState, documentType: '<%- documentTypeId %>' },
|
|
20
|
+
utils.createState
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
createDocument(state) {
|
|
24
|
+
return base.createDocument(
|
|
25
|
+
utils.createExtendedState(state),
|
|
26
|
+
utils.createState
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
saveToFile(document, path, name) {
|
|
30
|
+
return base.saveToFile(document, path, '<%- fileExtension %>', name);
|
|
31
|
+
},
|
|
32
|
+
saveToFileHandle(document, input) {
|
|
33
|
+
return base.saveToFileHandle(document, input);
|
|
34
|
+
},
|
|
35
|
+
loadFromFile(path) {
|
|
36
|
+
return base.loadFromFile(path, reducer);
|
|
37
|
+
},
|
|
38
|
+
loadFromInput(input) {
|
|
39
|
+
return base.loadFromInput(input, reducer);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default utils;
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/actions.esm.t
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/actions.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
import { Action<% if (actions.find(a => a.hasAttachment)) {%>, ActionWithAttachment<%}%> } from 'document-model/document';
|
|
6
|
+
import {
|
|
7
|
+
<% actions.filter(a => a.hasInput).forEach(action => { _%>
|
|
8
|
+
<%= h.changeCase.pascal(action.name) %>Input,
|
|
9
|
+
<% }); _%>
|
|
10
|
+
} from '../types';
|
|
11
|
+
|
|
12
|
+
<% actions.filter(a => a.hasInput).forEach(actionType => { _%>
|
|
13
|
+
export type <%= h.changeCase.pascal(actionType.name) %>Action = Action<%if(actionType.hasAttachment){ %>WithAttachment<% } %><'<%= h.changeCase.constantCase(actionType.name) %>', <%= h.changeCase.pascal(actionType.name) %>Input, '<%= actionType.scope %>'>;
|
|
14
|
+
<% }); _%>
|
|
15
|
+
<% actions.filter(a => !a.hasInput).forEach(actionType => { _%>
|
|
16
|
+
export type <%= h.changeCase.pascal(actionType.name) %>Action = Action<'<%= h.changeCase.constantCase(actionType.name) %>', never, '<%= actionType.scope %>'>;
|
|
17
|
+
<% }); _%>
|
|
18
|
+
|
|
19
|
+
export type <%= h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module) %>Action =
|
|
20
|
+
<% actions.forEach(actionType => { _%>
|
|
21
|
+
| <%= h.changeCase.pascal(actionType.name) %>Action
|
|
22
|
+
<% }); _%>;
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/creators.esm.t
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/creators.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
import { utils<% if (actions.find(a => a.hasAttachment)) {%>, AttachmentInput<%}%> } from 'document-model/document';
|
|
6
|
+
import { z,
|
|
7
|
+
<% actions.filter(a => a.hasInput).forEach(action => { _%>
|
|
8
|
+
<%= h.changeCase.pascal(action.name) %>Input,
|
|
9
|
+
<% }); _%>
|
|
10
|
+
} from '../types';
|
|
11
|
+
import {
|
|
12
|
+
<% actions.forEach(action => { _%>
|
|
13
|
+
<%= h.changeCase.pascal(action.name) %>Action,
|
|
14
|
+
<% }); _%>
|
|
15
|
+
} from './actions';
|
|
16
|
+
|
|
17
|
+
const { createAction } = utils;
|
|
18
|
+
|
|
19
|
+
<% actions.filter(a => a.hasInput).forEach(action => { _%>
|
|
20
|
+
export const <%= h.changeCase.camel(action.name) %> = (input: <%= h.changeCase.pascal(action.name) %>Input<%if(action.hasAttachment){ %>, attachments: AttachmentInput[] <% } %>) =>
|
|
21
|
+
createAction<<%= h.changeCase.pascal(action.name) %>Action>(
|
|
22
|
+
'<%= h.changeCase.constantCase(action.name) %>',
|
|
23
|
+
{...input},
|
|
24
|
+
<%if(action.hasAttachment){ %>attachments<% } else { %>undefined<% } %>,
|
|
25
|
+
z.<%= h.changeCase.pascalCase(action.name) %>InputSchema,
|
|
26
|
+
'<%= action.scope %>'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
<% }); _%>
|
|
30
|
+
|
|
31
|
+
<% actions.filter(a => !a.hasInput).forEach(action => { _%>
|
|
32
|
+
export const <%= h.changeCase.camel(action.name) %> = () =>
|
|
33
|
+
createAction<<%= h.changeCase.pascal(action.name) %>Action>('<%= h.changeCase.constantCase(action.name) %>');
|
|
34
|
+
<% }); _%>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/src/reducers/<%= module %>.ts"
|
|
3
|
+
unless_exists: true
|
|
4
|
+
---
|
|
5
|
+
/**
|
|
6
|
+
* This is a scaffold file meant for customization:
|
|
7
|
+
* - modify it by implementing the reducer functions
|
|
8
|
+
* - delete the file and run the code generator again to have it reset
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { <%= h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module) %>Operations } from '../../gen/<%= module %>/operations';
|
|
12
|
+
|
|
13
|
+
export const reducer: <%= h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module) %>Operations = {
|
|
14
|
+
<% actions.forEach(action => { _%>
|
|
15
|
+
<%= h.changeCase.camel(action.name) %>Operation(state, action, dispatch) {
|
|
16
|
+
// TODO: Implement "<%= h.changeCase.camel(action.name) %>Operation" reducer
|
|
17
|
+
throw new Error('Reducer "<%= h.changeCase.camel(action.name) %>Operation" not yet implemented');
|
|
18
|
+
},
|
|
19
|
+
<% }); _%>
|
|
20
|
+
}
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/src/tests/<%= module %>.test.ts"
|
|
3
|
+
unless_exists: true
|
|
4
|
+
---
|
|
5
|
+
/**
|
|
6
|
+
* This is a scaffold file meant for customization:
|
|
7
|
+
* - change it by adding new tests or modifying the existing ones
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { generateMock } from '@powerhousedao/codegen';
|
|
11
|
+
import { utils as documentModelUtils } from 'document-model/document';
|
|
12
|
+
|
|
13
|
+
import utils from '../../gen/utils';
|
|
14
|
+
import {
|
|
15
|
+
z,
|
|
16
|
+
<% actions.forEach(action => { _%>
|
|
17
|
+
<%= h.changeCase.pascal(action.name) %>Input,
|
|
18
|
+
<% }); _%>
|
|
19
|
+
} from '../../gen/schema';
|
|
20
|
+
import { reducer } from '../../gen/reducer';
|
|
21
|
+
import * as creators from '../../gen/<%= module %>/creators';
|
|
22
|
+
import { <%= h.changeCase.pascal(documentType) %>Document } from '../../gen/types';
|
|
23
|
+
|
|
24
|
+
describe('<%= h.changeCase.pascal(module) %> Operations', () => {
|
|
25
|
+
let document: <%= h.changeCase.pascal(documentType) %>Document;
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
document = utils.createDocument();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
<% actions.forEach(action => { _%>
|
|
32
|
+
it('should handle <%= h.changeCase.camel(action.name) %> operation', () => {
|
|
33
|
+
// generate a random id
|
|
34
|
+
// const id = documentModelUtils.hashKey();
|
|
35
|
+
|
|
36
|
+
const input: <%= h.changeCase.pascal(action.name) %>Input = generateMock(
|
|
37
|
+
z.<%= h.changeCase.pascal(action.name) %>InputSchema(),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const updatedDocument = reducer(
|
|
41
|
+
document,
|
|
42
|
+
creators.<%= h.changeCase.camel(action.name) %>(input),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(updatedDocument.operations.<%= action.scope %>).toHaveLength(1);
|
|
46
|
+
expect(updatedDocument.operations.<%= action.scope %>[0].type).toBe(
|
|
47
|
+
'<%= h.changeCase.constant(action.name) %>',
|
|
48
|
+
);
|
|
49
|
+
expect(updatedDocument.operations.<%= action.scope %>[0].input).toStrictEqual(input);
|
|
50
|
+
expect(updatedDocument.operations.<%= action.scope %>[0].index).toEqual(0);
|
|
51
|
+
});
|
|
52
|
+
<% }); _%>
|
|
53
|
+
});
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/error.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
<% if (actions.some(action => action.errors?.length > 0)) { _%>
|
|
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
|
+
<% }); _%>
|
|
11
|
+
<% }); _%>
|
|
12
|
+
|
|
13
|
+
export interface ReducerError {
|
|
14
|
+
errorCode: ErrorCode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
<% actions.forEach(action => { _%>
|
|
18
|
+
<% action.errors.forEach(error => { _%>
|
|
19
|
+
export class <%= h.changeCase.pascal(error.name) %> extends Error implements ReducerError {
|
|
20
|
+
errorCode = '<%= h.changeCase.pascal(error.name) %>' as ErrorCode;
|
|
21
|
+
constructor(message = '<%= h.changeCase.pascal(error.name) %>') {
|
|
22
|
+
super(message);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
<% }); _%>
|
|
27
|
+
<% }); _%>
|
|
28
|
+
|
|
29
|
+
<% } _%>
|
|
30
|
+
export const errors = {
|
|
31
|
+
<% actions.forEach(action => { _%>
|
|
32
|
+
<% if(action.errors?.length > 0){ -%>
|
|
33
|
+
<%= h.changeCase.pascal(action.name) %>: {
|
|
34
|
+
<% action.errors.forEach(error => { _%>
|
|
35
|
+
<%= h.changeCase.pascal(error.name) %>,
|
|
36
|
+
<% }); _%>
|
|
37
|
+
},
|
|
38
|
+
<% } -%>
|
|
39
|
+
<% }); _%>
|
|
40
|
+
};
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/object.esm.t
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/object.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
import { BaseDocument<% if (actions.find(a => a.hasAttachment)) {%>, AttachmentInput<%}%> } from 'document-model/document';
|
|
6
|
+
import {
|
|
7
|
+
<% actions.filter(action => action.hasInput).forEach(action => { _%>
|
|
8
|
+
<%= h.changeCase.pascal(action.name) %>Input,
|
|
9
|
+
<% }); _%>
|
|
10
|
+
<%= h.changeCase.pascal(documentType) %>State,
|
|
11
|
+
<%= h.changeCase.pascal(documentType) %>LocalState
|
|
12
|
+
} from '../types';
|
|
13
|
+
import {
|
|
14
|
+
<% actions.forEach(action => { _%>
|
|
15
|
+
<%= h.changeCase.camel(action.name) %>,
|
|
16
|
+
<% }); _%>
|
|
17
|
+
} from './creators';
|
|
18
|
+
import { <%= h.changeCase.pascal(documentType) %>Action } from '../actions';
|
|
19
|
+
|
|
20
|
+
export default class <%= h.changeCase.pascal(documentType) %>_<%= h.changeCase.pascal(module) %> extends BaseDocument<
|
|
21
|
+
<%= h.changeCase.pascal(documentType) %>State,
|
|
22
|
+
<%= h.changeCase.pascal(documentType) %>Action,
|
|
23
|
+
<%= h.changeCase.pascal(documentType) %>LocalState
|
|
24
|
+
> {
|
|
25
|
+
<% actions.filter(action => action.hasInput).forEach(action => { _%>
|
|
26
|
+
public <%= h.changeCase.camel(action.name) %>(input: <%= h.changeCase.pascal(action.name) %>Input<%if(action.hasAttachment){ %>, attachments: AttachmentInput[] <% } %>) {
|
|
27
|
+
return this.dispatch(<%= h.changeCase.camel(action.name) %>(input<%if(action.hasAttachment){ %>, attachments<% } %>));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
<% }); _%>
|
|
31
|
+
<% actions.filter(action => !action.hasInput).forEach(action => { _%>
|
|
32
|
+
public <%= h.changeCase.camel(action.name) %>() {
|
|
33
|
+
return this.dispatch(<%= h.changeCase.camel(action.name) %>());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
<% }); _%>
|
|
37
|
+
}
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/operations.esm.t
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/<%= module %>/operations.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
import { SignalDispatch } from 'document-model/document';
|
|
6
|
+
import {
|
|
7
|
+
<% actions.forEach(action => { _%>
|
|
8
|
+
<%= h.changeCase.pascal(action.name) %>Action,
|
|
9
|
+
<% }); _%>
|
|
10
|
+
} from './actions';
|
|
11
|
+
import { <%= actions.map(action => h.changeCase.pascal(h.changeCase.pascal(documentType + '_' + action.state + '_State'))).filter((value, index, self) => self.indexOf(value) === index).join(', ') %> } from '../types';
|
|
12
|
+
|
|
13
|
+
export interface <%= h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module) %>Operations {
|
|
14
|
+
<% actions.forEach(action => { _%>
|
|
15
|
+
<%= h.changeCase.camel(action.name) %>Operation: (state: <%= h.changeCase.pascal(documentType + '_' + action.state + '_State') %>, action: <%= h.changeCase.pascal(action.name) %>Action, dispatch?: SignalDispatch) => void,
|
|
16
|
+
<% }); _%>
|
|
17
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(subgraph) %>/resolvers.ts"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
8
|
+
import { Subgraph } from "@powerhousedao/reactor-api";
|
|
9
|
+
import { actions } from "../../document-models/<%- h.changeCase.param(documentType) %>";
|
|
10
|
+
import { actions as driveActions } from "document-model-libs/document-drive";
|
|
11
|
+
import { utils as docUtils } from "document-model/document";
|
|
12
|
+
|
|
13
|
+
export const getResolvers = (subgraph: Subgraph, driveId: string) => {
|
|
14
|
+
const reactor = subgraph.reactor;
|
|
15
|
+
|
|
16
|
+
return ({
|
|
17
|
+
Mutation: {
|
|
18
|
+
|
|
19
|
+
<%- h.changeCase.pascal(documentType) %>_createDocument: async (_: any, args: any) => {
|
|
20
|
+
const docId = docUtils.generateId();
|
|
21
|
+
|
|
22
|
+
await reactor.addDriveAction(driveId, driveActions.addFile({
|
|
23
|
+
id: docId,
|
|
24
|
+
name: args.name,
|
|
25
|
+
documentType: "<%- documentTypeId %>",
|
|
26
|
+
synchronizationUnits:[
|
|
27
|
+
{
|
|
28
|
+
branch: "main",
|
|
29
|
+
scope: "global",
|
|
30
|
+
syncId: docUtils.hashKey(),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
branch: "main",
|
|
34
|
+
scope: "local",
|
|
35
|
+
syncId: docUtils.hashKey(),
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
return docId;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
<% modules.forEach(module => { _%>
|
|
44
|
+
<% module.operations.forEach(op => { _%>
|
|
45
|
+
<%- h.changeCase.pascal(documentType) + '_' + h.changeCase.camel(op.name)
|
|
46
|
+
%>: async (_: any, args: any) => {
|
|
47
|
+
const docId: string = args.docId || "";
|
|
48
|
+
const doc = await reactor.getDocument(driveId, docId);
|
|
49
|
+
|
|
50
|
+
await reactor.addAction(
|
|
51
|
+
driveId,
|
|
52
|
+
docId,
|
|
53
|
+
actions.<%- h.changeCase.camel(op.name) %>({...args.input})
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return doc.revision.global + 1;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
<%_ })}); %>
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/schema.esm.t
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(subgraph) %>/schema.graphql"
|
|
3
|
+
force: true
|
|
4
|
+
---
|
|
5
|
+
"""
|
|
6
|
+
Subgraph definition for <%= h.changeCase.pascal(documentType) %> (<%- documentTypeId %>)
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
<%- schema %>
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
Mutations: <%= h.changeCase.pascal(documentType) %>
|
|
13
|
+
"""
|
|
14
|
+
type Mutation {
|
|
15
|
+
|
|
16
|
+
<%- h.changeCase.pascal(documentType) %>_createDocument(name:String): String
|
|
17
|
+
|
|
18
|
+
<% modules.forEach(module => { _%>
|
|
19
|
+
<% module.operations.forEach(op => { _%>
|
|
20
|
+
<%- h.changeCase.pascal(documentType) + '_' + h.changeCase.camel(op.name)
|
|
21
|
+
%>(docId: PHID, input: <%-
|
|
22
|
+
h.changeCase.pascal(documentType) + '_' + h.changeCase.pascal(op.name) %>Input): Int
|
|
23
|
+
<%_ })}); %>}
|
|
24
|
+
<% modules.forEach(module => { _%>
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
Module: <%= h.changeCase.pascal(module.name) %>
|
|
28
|
+
"""
|
|
29
|
+
<% module.operations.forEach(op => { _%>
|
|
30
|
+
<%- op.schema.replace('input ', 'input ' + h.changeCase.pascal(documentType) + '_') %>
|
|
31
|
+
<%_ })}); %>
|