@powerhousedao/codegen 4.1.0-dev.31 → 4.1.0-dev.33
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/templates/powerhouse/generate-document-model/object.esm.t +2 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/ph-factories.esm.t +96 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +2 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +11 -11
- package/dist/tsconfig.hygen.tsbuildinfo +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +7 -7
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/object.ts"
|
|
3
3
|
force: true
|
|
4
4
|
---
|
|
5
|
-
import { BaseDocumentClass, type
|
|
5
|
+
import { BaseDocumentClass, type BaseStateFromDocument, type PartialState, applyMixins, type SignalDispatch } from 'document-model';
|
|
6
6
|
import { <%= 'type ' + h.changeCase.pascal(documentType) %>State, <%= 'type ' + h.changeCase.pascal(documentType) %>LocalState, <%= 'type ' + h.changeCase.pascal(documentType) %>Document } from './types.js';
|
|
7
7
|
import { <%= 'type ' + h.changeCase.pascal(documentType) %>Action } from './actions.js';
|
|
8
8
|
import { reducer } from './reducer.js';
|
|
@@ -23,7 +23,7 @@ interface <%= h.changeCase.pascal(documentType) %> extends
|
|
|
23
23
|
class <%= h.changeCase.pascal(documentType) %> extends BaseDocumentClass<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState, <%= h.changeCase.pascal(documentType) %>Action> {
|
|
24
24
|
static fileExtension = '<%= extension %>';
|
|
25
25
|
|
|
26
|
-
constructor(initialState?: Partial<
|
|
26
|
+
constructor(initialState?: Partial<BaseStateFromDocument<<%= h.changeCase.pascal(documentType) %>Document>>, dispatch?: SignalDispatch) {
|
|
27
27
|
super(reducer, utils.createDocument(initialState), dispatch);
|
|
28
28
|
}
|
|
29
29
|
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/ph-factories.esm.t
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/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 "./gen/types.js";
|
|
21
|
+
import { createDocument } from "./gen/utils.js";
|
|
22
|
+
|
|
23
|
+
export function defaultGlobalState(): <%= h.changeCase.pascal(documentType) %>State {
|
|
24
|
+
return <%- initialGlobalState %>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function defaultLocalState(): <%= h.changeCase.pascal(documentType) %>LocalState {
|
|
28
|
+
return <%- initialLocalState %>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function defaultPHState(): <%= h.changeCase.pascal(documentType) %>PHState {
|
|
32
|
+
return {
|
|
33
|
+
...defaultBaseState(),
|
|
34
|
+
global: defaultGlobalState(),
|
|
35
|
+
local: defaultLocalState(),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function createGlobalState(
|
|
40
|
+
state?: Partial<<%= h.changeCase.pascal(documentType) %>State>,
|
|
41
|
+
): <%= h.changeCase.pascal(documentType) %>State {
|
|
42
|
+
return {
|
|
43
|
+
...defaultGlobalState(),
|
|
44
|
+
...(state || {}),
|
|
45
|
+
} as <%= h.changeCase.pascal(documentType) %>State;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createLocalState(
|
|
49
|
+
state?: Partial<<%= h.changeCase.pascal(documentType) %>LocalState>,
|
|
50
|
+
): <%= h.changeCase.pascal(documentType) %>LocalState {
|
|
51
|
+
return {
|
|
52
|
+
...defaultLocalState(),
|
|
53
|
+
...(state || {}),
|
|
54
|
+
} as <%= h.changeCase.pascal(documentType) %>LocalState;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createState(
|
|
58
|
+
baseState?: Partial<PHBaseState>,
|
|
59
|
+
globalState?: Partial<<%= h.changeCase.pascal(documentType) %>State>,
|
|
60
|
+
localState?: Partial<<%= h.changeCase.pascal(documentType) %>LocalState>,
|
|
61
|
+
): <%= h.changeCase.pascal(documentType) %>PHState {
|
|
62
|
+
return {
|
|
63
|
+
...createBaseState(baseState?.auth, baseState?.document),
|
|
64
|
+
global: createGlobalState(globalState),
|
|
65
|
+
local: createLocalState(localState),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type <%= h.changeCase.pascal(documentType) %>PHState = PHBaseState & {
|
|
70
|
+
global: <%= h.changeCase.pascal(documentType) %>State;
|
|
71
|
+
local: <%= h.changeCase.pascal(documentType) %>LocalState;
|
|
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,7 +2,7 @@
|
|
|
2
2
|
to: "<%= rootDir %>/<%= h.changeCase.param(documentType) %>/gen/types.ts"
|
|
3
3
|
force: true
|
|
4
4
|
---
|
|
5
|
-
import type { PHDocument,
|
|
5
|
+
import type { PHDocument, BaseStateFromDocument } from 'document-model';
|
|
6
6
|
import type { <%= h.changeCase.pascal(documentType) %>State } from './schema/types.js';
|
|
7
7
|
<% if(hasLocalSchema) { -%>
|
|
8
8
|
import type { <%= h.changeCase.pascal(documentType) %>LocalState } from './schema/types.js';
|
|
@@ -14,6 +14,6 @@ export type * from './schema/types.js';
|
|
|
14
14
|
<% if(!hasLocalSchema) { -%>
|
|
15
15
|
<%= 'type ' + h.changeCase.pascal(documentType) %>LocalState = Record<PropertyKey, never>;
|
|
16
16
|
<%} -%>
|
|
17
|
-
export type Extended<%= h.changeCase.pascal(documentType) %>State =
|
|
17
|
+
export type Extended<%= h.changeCase.pascal(documentType) %>State = BaseStateFromDocument<<%= h.changeCase.pascal(documentType) %>Document>;
|
|
18
18
|
export <%= 'type ' + h.changeCase.pascal(documentType) %>Document = PHDocument<<%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState>;
|
|
19
19
|
export type { <%= h.changeCase.pascal(documentType) %>State, <%= h.changeCase.pascal(documentType) %>LocalState, <%= h.changeCase.pascal(documentType) %>Action };
|
|
@@ -5,12 +5,11 @@ force: true
|
|
|
5
5
|
import {
|
|
6
6
|
type DocumentModelUtils,
|
|
7
7
|
baseCreateDocument,
|
|
8
|
-
baseCreateExtendedState,
|
|
9
8
|
baseSaveToFile,
|
|
10
9
|
baseSaveToFileHandle,
|
|
11
10
|
baseLoadFromFile,
|
|
12
11
|
baseLoadFromInput,
|
|
13
|
-
|
|
12
|
+
defaultBaseState,
|
|
14
13
|
generateId,
|
|
15
14
|
} from 'document-model';
|
|
16
15
|
import {
|
|
@@ -26,18 +25,12 @@ export const initialLocalState: <%= h.changeCase.pascal(documentType) %>LocalSta
|
|
|
26
25
|
const utils: DocumentModelUtils<<%= h.changeCase.pascal(documentType) %>Document> = {
|
|
27
26
|
fileExtension: '<%- fileExtension %>',
|
|
28
27
|
createState(state) {
|
|
29
|
-
return { ...
|
|
30
|
-
},
|
|
31
|
-
createExtendedState(extendedState) {
|
|
32
|
-
return baseCreateExtendedState(
|
|
33
|
-
{ ...extendedState },
|
|
34
|
-
utils.createState
|
|
35
|
-
);
|
|
28
|
+
return { ...defaultBaseState(), global: { ...initialGlobalState, ...state?.global }, local: { ...initialLocalState, ...state?.local } };
|
|
36
29
|
},
|
|
37
30
|
createDocument(state) {
|
|
38
31
|
const document = baseCreateDocument(
|
|
39
|
-
utils.
|
|
40
|
-
|
|
32
|
+
utils.createState,
|
|
33
|
+
state
|
|
41
34
|
);
|
|
42
35
|
|
|
43
36
|
document.header.documentType = '<%- documentTypeId %>';
|
|
@@ -61,4 +54,11 @@ const utils: DocumentModelUtils<<%= h.changeCase.pascal(documentType) %>Document
|
|
|
61
54
|
},
|
|
62
55
|
};
|
|
63
56
|
|
|
57
|
+
export const createDocument = utils.createDocument;
|
|
58
|
+
export const createState = utils.createState;
|
|
59
|
+
export const saveToFile = utils.saveToFile;
|
|
60
|
+
export const saveToFileHandle = utils.saveToFileHandle;
|
|
61
|
+
export const loadFromFile = utils.loadFromFile;
|
|
62
|
+
export const loadFromInput = utils.loadFromInput;
|
|
63
|
+
|
|
64
64
|
export default utils;
|