@powerhousedao/codegen 6.0.0-dev.109 → 6.0.0-dev.110
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/__tests__/config.d.ts +0 -1
- package/dist/src/codegen/__tests__/config.d.ts.map +1 -1
- package/dist/src/codegen/__tests__/config.js +0 -1
- package/dist/src/codegen/__tests__/config.js.map +1 -1
- package/dist/src/codegen/__tests__/generate-doc-model.test.js +0 -1
- package/dist/src/codegen/__tests__/generate-doc-model.test.js.map +1 -1
- package/dist/src/codegen/__tests__/generate-drive-editor.test.js +0 -5
- package/dist/src/codegen/__tests__/generate-drive-editor.test.js.map +1 -1
- package/dist/src/codegen/__tests__/generate-editor.test.js +0 -4
- package/dist/src/codegen/__tests__/generate-editor.test.js.map +1 -1
- package/dist/src/codegen/__tests__/generate-processor.test.js +0 -1
- package/dist/src/codegen/__tests__/generate-processor.test.js.map +1 -1
- package/dist/src/codegen/__tests__/generate-subgraph.test.d.ts +2 -0
- package/dist/src/codegen/__tests__/generate-subgraph.test.d.ts.map +1 -0
- package/dist/src/codegen/__tests__/generate-subgraph.test.js +197 -0
- package/dist/src/codegen/__tests__/generate-subgraph.test.js.map +1 -0
- package/dist/src/codegen/generate.d.ts +10 -17
- package/dist/src/codegen/generate.d.ts.map +1 -1
- package/dist/src/codegen/generate.js +38 -101
- package/dist/src/codegen/generate.js.map +1 -1
- 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/src/codegen/index.js.map +1 -1
- package/dist/src/file-builders/index.d.ts +1 -0
- package/dist/src/file-builders/index.d.ts.map +1 -1
- package/dist/src/file-builders/index.js +1 -0
- package/dist/src/file-builders/index.js.map +1 -1
- package/dist/src/file-builders/subgraph.d.ts +10 -0
- package/dist/src/file-builders/subgraph.d.ts.map +1 -0
- package/dist/src/file-builders/subgraph.js +121 -0
- package/dist/src/file-builders/subgraph.js.map +1 -0
- package/dist/src/templates/index.d.ts +1 -0
- package/dist/src/templates/index.d.ts.map +1 -1
- package/dist/src/templates/index.js +1 -0
- package/dist/src/templates/index.js.map +1 -1
- package/dist/src/templates/subgraphs/custom-resolvers.d.ts +5 -0
- package/dist/src/templates/subgraphs/custom-resolvers.d.ts.map +1 -0
- package/dist/src/{codegen/.hygen/templates/powerhouse/generate-custom-subgraph/resolvers.esm.t → templates/subgraphs/custom-resolvers.js} +6 -6
- package/dist/src/templates/subgraphs/custom-resolvers.js.map +1 -0
- package/dist/src/templates/subgraphs/custom-schema.d.ts +5 -0
- package/dist/src/templates/subgraphs/custom-schema.d.ts.map +1 -0
- package/dist/src/templates/subgraphs/custom-schema.js +20 -0
- package/dist/src/templates/subgraphs/custom-schema.js.map +1 -0
- package/dist/src/templates/subgraphs/document-model-resolvers.d.ts +15 -0
- package/dist/src/templates/subgraphs/document-model-resolvers.d.ts.map +1 -0
- package/dist/src/{codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/resolvers.esm.t → templates/subgraphs/document-model-resolvers.js} +55 -47
- package/dist/src/templates/subgraphs/document-model-resolvers.js.map +1 -0
- package/dist/src/templates/subgraphs/document-model-schema.d.ts +12 -0
- package/dist/src/templates/subgraphs/document-model-schema.d.ts.map +1 -0
- package/dist/src/templates/subgraphs/document-model-schema.js +54 -0
- package/dist/src/templates/subgraphs/document-model-schema.js.map +1 -0
- package/dist/src/templates/subgraphs/index-file.d.ts +5 -0
- package/dist/src/templates/subgraphs/index-file.d.ts.map +1 -0
- package/dist/src/{codegen/.hygen/templates/powerhouse/generate-subgraph/index.esm.t → templates/subgraphs/index-file.js} +7 -7
- package/dist/src/templates/subgraphs/index-file.js.map +1 -0
- package/dist/src/templates/subgraphs/index.d.ts +7 -0
- package/dist/src/templates/subgraphs/index.d.ts.map +1 -0
- package/dist/src/templates/subgraphs/index.js +7 -0
- package/dist/src/templates/subgraphs/index.js.map +1 -0
- package/dist/src/templates/subgraphs/lib-file.d.ts +2 -0
- package/dist/src/templates/subgraphs/lib-file.d.ts.map +1 -0
- package/dist/src/templates/subgraphs/lib-file.js +8 -0
- package/dist/src/templates/subgraphs/lib-file.js.map +1 -0
- package/dist/src/utils/cli.d.ts +0 -6
- package/dist/src/utils/cli.d.ts.map +1 -1
- package/dist/src/utils/cli.js +0 -18
- package/dist/src/utils/cli.js.map +1 -1
- package/dist/src/utils/graphql-type-prefixes.d.ts +10 -0
- package/dist/src/utils/graphql-type-prefixes.d.ts.map +1 -0
- package/dist/src/utils/graphql-type-prefixes.js +51 -0
- package/dist/src/utils/graphql-type-prefixes.js.map +1 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -18
- package/dist/src/codegen/.hygen/package.json +0 -6
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.js +0 -10
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/schema.esm.t +0 -20
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/actions.esm.t +0 -16
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/creators.esm.t +0 -9
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/customUtils.esm.t +0 -5
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/document-schema.esm.t +0 -56
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/document-type.esm.t +0 -6
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModel.esm.t +0 -7
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModelTest.esm.t +0 -121
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/hooks.esm.t +0 -49
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.esm.t +0 -23
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.js +0 -127
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/module.esm.t +0 -22
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/ph-factories.esm.t +0 -93
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +0 -46
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/root-utils.esm.t +0 -11
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootActions.esm.t +0 -13
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootIndex.esm.t +0 -14
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/schema.esm.t +0 -6
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/src-index.esm.t +0 -5
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +0 -31
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +0 -77
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/actions.esm.t +0 -22
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/creators.esm.t +0 -37
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t +0 -44
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t +0 -36
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +0 -71
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/operations.esm.t +0 -17
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/index.js +0 -119
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t +0 -44
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/CreateDocument.esm.t +0 -58
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveContents.esm.t +0 -23
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +0 -32
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EmptyState.esm.t +0 -19
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/Files.esm.t +0 -29
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderTree.esm.t +0 -108
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/Folders.esm.t +0 -28
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/NavigationBreadcrumbs.esm.t +0 -14
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/config.esm.t +0 -11
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +0 -20
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js +0 -25
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/module.esm.t +0 -15
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +0 -80
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +0 -90
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/module.esm.t +0 -16
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.esm.t +0 -59
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.js +0 -9
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/utils.esm.t +0 -100
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/factory.esm.t +0 -22
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.esm.t +0 -62
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.js +0 -12
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.root.esm.t +0 -10
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.root.inject.esm.t +0 -12
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.esm.t +0 -34
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_call.esm.t +0 -7
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_export.esm.t +0 -7
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_import.esm.t +0 -7
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/factory.esm.t +0 -40
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.esm.t +0 -47
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.js +0 -12
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.root.esm.t +0 -10
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.root.inject.esm.t +0 -12
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.esm.t +0 -34
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_call.esm.t +0 -7
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_export.esm.t +0 -9
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_import.esm.t +0 -7
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/migrations.esm.t +0 -23
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/schema.esm.t +0 -13
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.js +0 -10
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/lib.esm.t +0 -9
- package/dist/src/codegen/hygen.d.ts +0 -47
- package/dist/src/codegen/hygen.d.ts.map +0 -1
- package/dist/src/codegen/hygen.js +0 -230
- package/dist/src/codegen/hygen.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/codegen",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.110",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -43,21 +43,18 @@
|
|
|
43
43
|
"arg": "^5.0.2",
|
|
44
44
|
"chalk": "5.6.2",
|
|
45
45
|
"change-case": "5.4.4",
|
|
46
|
-
"enquirer": "2.4.1",
|
|
47
|
-
"execa": "^8.0.1",
|
|
48
46
|
"graphql": "16.12.0",
|
|
49
47
|
"graphql-codegen-typescript-validation-schema": "0.18.1",
|
|
50
|
-
"hygen": "^6.2.11",
|
|
51
48
|
"package-json-validator": "^0.60.0",
|
|
52
49
|
"prettier": "3.8.1",
|
|
53
50
|
"read-pkg": "10.1.0",
|
|
54
51
|
"semver": "7.7.4",
|
|
55
52
|
"ts-morph": "27.0.2",
|
|
56
53
|
"zocker": "^3.0.0",
|
|
57
|
-
"@powerhousedao/config": "6.0.0-dev.
|
|
58
|
-
"
|
|
59
|
-
"@powerhousedao/
|
|
60
|
-
"
|
|
54
|
+
"@powerhousedao/config": "6.0.0-dev.110",
|
|
55
|
+
"document-model": "6.0.0-dev.110",
|
|
56
|
+
"@powerhousedao/shared": "6.0.0-dev.110",
|
|
57
|
+
"@powerhousedao/common": "6.0.0-dev.110"
|
|
61
58
|
},
|
|
62
59
|
"devDependencies": {
|
|
63
60
|
"@types/bun": "1.3.8",
|
|
@@ -68,25 +65,19 @@
|
|
|
68
65
|
"vite-tsconfig-paths": "6.1.1",
|
|
69
66
|
"vitest": "3.2.4",
|
|
70
67
|
"zod": "4.3.6",
|
|
71
|
-
"@powerhousedao/analytics-engine-core": "6.0.0-dev.
|
|
72
|
-
"@powerhousedao/design-system": "6.0.0-dev.
|
|
73
|
-
"@powerhousedao/reactor-browser": "6.0.0-dev.
|
|
74
|
-
"document-drive": "6.0.0-dev.109"
|
|
68
|
+
"@powerhousedao/analytics-engine-core": "6.0.0-dev.110",
|
|
69
|
+
"@powerhousedao/design-system": "6.0.0-dev.110",
|
|
70
|
+
"@powerhousedao/reactor-browser": "6.0.0-dev.110"
|
|
75
71
|
},
|
|
76
72
|
"scripts": {
|
|
77
73
|
"tsc": "tsc",
|
|
78
74
|
"lint": "eslint",
|
|
79
|
-
"copy-hygen": "rm -rf dist/src/codegen/.hygen && cp -r src/codegen/.hygen dist/src/codegen/",
|
|
80
|
-
"build:misc": "pnpm copy-hygen",
|
|
81
75
|
"build:create-lib": "tsc --project src/create-lib/tsconfig.json",
|
|
82
76
|
"publish:create-lib": "npm publish --cwd ./src/create-lib/",
|
|
83
77
|
"start": "tsx src/cli.ts",
|
|
84
|
-
"pretest": "pnpm build:misc",
|
|
85
78
|
"test:bun": "bun test --concurrent --timeout 1000000",
|
|
86
79
|
"test:vitest": "vitest --run",
|
|
87
80
|
"test": "pnpm test:bun generate-doc-model.test.ts generate-processor.test.ts && pnpm test:vitest",
|
|
88
|
-
"test:keep": "KEEP_TEST_OUTPUT=true pnpm test"
|
|
89
|
-
"test:hygen": "USE_TS_MORPH=false pnpm test",
|
|
90
|
-
"test:keep:hygen": "USE_TS_MORPH=false KEEP_TEST_OUTPUT=true pnpm test"
|
|
81
|
+
"test:keep": "KEEP_TEST_OUTPUT=true pnpm test"
|
|
91
82
|
}
|
|
92
83
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= h.changeCase.param(subgraph) %>/schema.ts"
|
|
3
|
-
unless_exists: true
|
|
4
|
-
---
|
|
5
|
-
import { gql } from "graphql-tag";
|
|
6
|
-
import type { DocumentNode } from "graphql";
|
|
7
|
-
|
|
8
|
-
export const schema: DocumentNode = gql`
|
|
9
|
-
"""
|
|
10
|
-
<%= h.changeCase.pascal(subgraph) %> Queries
|
|
11
|
-
"""
|
|
12
|
-
type <%= h.changeCase.pascal(subgraph) %>Queries {
|
|
13
|
-
example(driveId: String!): String
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type Query {
|
|
17
|
-
<%= h.changeCase.camel(subgraph) %>: <%= h.changeCase.pascal(subgraph) %>Queries!
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
`
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/actions.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
<% modules.forEach(module => { _%>
|
|
6
|
-
import type { <%= h.changeCase.pascal(documentType) %><%= h.changeCase.pascal(module.name) %>Action } from './<%= h.changeCase.param(module.name) %>/actions.js';
|
|
7
|
-
<% }); _%>
|
|
8
|
-
|
|
9
|
-
<% modules.forEach(module => { _%>
|
|
10
|
-
export * from './<%= h.changeCase.param(module.name) %>/actions.js';
|
|
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
|
-
<% }); _%>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/creators.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
<% modules.forEach(module => { _%>
|
|
7
|
-
export * from "./<%= h.changeCase.param(module.name) %>/creators.js";
|
|
8
|
-
export * as <%= h.changeCase.camel(module.name) %>Actions from "./<%= h.changeCase.param(module.name) %>/creators.js";
|
|
9
|
-
<% }); _%>
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/document-schema.esm.t
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/document-schema.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
import {
|
|
6
|
-
BaseDocumentHeaderSchema,
|
|
7
|
-
BaseDocumentStateSchema,
|
|
8
|
-
} from "document-model";
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
import { <%= documentTypeVariableName %> } from "./document-type.js";
|
|
11
|
-
import { <%= stateSchemaName %> } from "./schema/zod.js";
|
|
12
|
-
import type { <%= phDocumentTypeName %>, <%= phStateName %> } from "./types.js";
|
|
13
|
-
|
|
14
|
-
/** Schema for validating the header object of a <%= pascalCaseDocumentType %> document */
|
|
15
|
-
export const <%= phDocumentTypeName %>HeaderSchema = BaseDocumentHeaderSchema.extend({
|
|
16
|
-
documentType: z.literal(<%= documentTypeVariableName %>),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
/** Schema for validating the state object of a <%= pascalCaseDocumentType %> document */
|
|
20
|
-
export const <%= phStateName %>Schema = BaseDocumentStateSchema.extend({
|
|
21
|
-
global: <%= stateSchemaName %>(),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export const <%= phDocumentSchemaName %> = z.object({
|
|
25
|
-
header: <%= phDocumentTypeName %>HeaderSchema,
|
|
26
|
-
state: <%= phStateName %>Schema,
|
|
27
|
-
initialState: <%= phStateName %>Schema,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
/** Simple helper function to check if a state object is a <%= pascalCaseDocumentType %> document state object */
|
|
31
|
-
export function <%= isPhStateOfTypeFunctionName %>(
|
|
32
|
-
state: unknown,
|
|
33
|
-
): state is <%= phStateName %> {
|
|
34
|
-
return <%= phStateName %>Schema.safeParse(state).success;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Simple helper function to assert that a document state object is a <%= pascalCaseDocumentType %> document state object */
|
|
38
|
-
export function <%= assertIsPhStateOfTypeFunctionName %>(
|
|
39
|
-
state: unknown,
|
|
40
|
-
): asserts state is <%= phStateName %> {
|
|
41
|
-
<%= phStateName %>Schema.parse(state);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Simple helper function to check if a document is a <%= pascalCaseDocumentType %> document */
|
|
45
|
-
export function <%= isPhDocumentOfTypeFunctionName %>(
|
|
46
|
-
document: unknown,
|
|
47
|
-
): document is <%= phDocumentTypeName %> {
|
|
48
|
-
return <%= phDocumentSchemaName %>.safeParse(document).success;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Simple helper function to assert that a document is a <%= pascalCaseDocumentType %> document */
|
|
52
|
-
export function <%= assertIsPhDocumentOfTypeFunctionName %>(
|
|
53
|
-
document: unknown,
|
|
54
|
-
): asserts document is <%= phDocumentTypeName %> {
|
|
55
|
-
<%= phDocumentSchemaName %>.parse(document);
|
|
56
|
-
}
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModelTest.esm.t
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= paramCaseDocumentType %>/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
|
-
* This is a scaffold file meant for customization:
|
|
11
|
-
* - change it by adding new tests or modifying the existing ones
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { describe, it, expect } from "vitest";
|
|
15
|
-
import {
|
|
16
|
-
utils,
|
|
17
|
-
initialGlobalState,
|
|
18
|
-
initialLocalState,
|
|
19
|
-
<%= documentTypeVariableName %>,
|
|
20
|
-
<%= isPhDocumentOfTypeFunctionName %>,
|
|
21
|
-
<%= assertIsPhDocumentOfTypeFunctionName %>,
|
|
22
|
-
<%= isPhStateOfTypeFunctionName %>,
|
|
23
|
-
<%= assertIsPhStateOfTypeFunctionName %>,
|
|
24
|
-
} from "<%= documentModelDir %>";
|
|
25
|
-
import { ZodError } from "zod";
|
|
26
|
-
|
|
27
|
-
describe("<%= pascalCaseDocumentType %> Document Model", () => {
|
|
28
|
-
it("should create a new <%= pascalCaseDocumentType %> document", () => {
|
|
29
|
-
const document = utils.createDocument();
|
|
30
|
-
|
|
31
|
-
expect(document).toBeDefined();
|
|
32
|
-
expect(document.header.documentType).toBe(<%= documentTypeVariableName %>);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should create a new <%= pascalCaseDocumentType %> document with a valid initial state", () => {
|
|
36
|
-
const document = utils.createDocument();
|
|
37
|
-
expect(document.state.global).toStrictEqual(initialGlobalState);
|
|
38
|
-
expect(document.state.local).toStrictEqual(initialLocalState);
|
|
39
|
-
expect(<%= isPhDocumentOfTypeFunctionName %>(document)).toBe(true);
|
|
40
|
-
expect(<%= isPhStateOfTypeFunctionName %>(document.state)).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
it("should reject a document that is not a <%= pascalCaseDocumentType %> document", () => {
|
|
43
|
-
const wrongDocumentType = utils.createDocument();
|
|
44
|
-
wrongDocumentType.header.documentType = "the-wrong-thing-1234";
|
|
45
|
-
try {
|
|
46
|
-
expect(<%= assertIsPhDocumentOfTypeFunctionName %>(wrongDocumentType)).toThrow();
|
|
47
|
-
expect(<%= isPhDocumentOfTypeFunctionName %>(wrongDocumentType)).toBe(false);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const wrongState = utils.createDocument();
|
|
53
|
-
// @ts-expect-error - we are testing the error case
|
|
54
|
-
wrongState.state.global = {
|
|
55
|
-
...{ notWhat: "you want" },
|
|
56
|
-
};
|
|
57
|
-
try {
|
|
58
|
-
expect(<%= isPhStateOfTypeFunctionName %>(wrongState.state)).toBe(false);
|
|
59
|
-
expect(<%= assertIsPhStateOfTypeFunctionName %>(wrongState.state)).toThrow();
|
|
60
|
-
expect(<%= isPhDocumentOfTypeFunctionName %>(wrongState)).toBe(false);
|
|
61
|
-
expect(<%= assertIsPhDocumentOfTypeFunctionName %>(wrongState)).toThrow();
|
|
62
|
-
} catch (error) {
|
|
63
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const wrongInitialState = utils.createDocument();
|
|
67
|
-
// @ts-expect-error - we are testing the error case
|
|
68
|
-
wrongInitialState.initialState.global = {
|
|
69
|
-
...{ notWhat: "you want" },
|
|
70
|
-
};
|
|
71
|
-
try {
|
|
72
|
-
expect(<%= isPhStateOfTypeFunctionName %>(wrongInitialState.state)).toBe(false);
|
|
73
|
-
expect(<%= assertIsPhStateOfTypeFunctionName %>(wrongInitialState.state)).toThrow();
|
|
74
|
-
expect(<%= isPhDocumentOfTypeFunctionName %>(wrongInitialState)).toBe(false);
|
|
75
|
-
expect(<%= assertIsPhDocumentOfTypeFunctionName %>(wrongInitialState)).toThrow();
|
|
76
|
-
} catch (error) {
|
|
77
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const missingIdInHeader = utils.createDocument();
|
|
81
|
-
// @ts-expect-error - we are testing the error case
|
|
82
|
-
delete missingIdInHeader.header.id;
|
|
83
|
-
try {
|
|
84
|
-
expect(<%= isPhDocumentOfTypeFunctionName %>(missingIdInHeader)).toBe(false);
|
|
85
|
-
expect(<%= assertIsPhDocumentOfTypeFunctionName %>(missingIdInHeader)).toThrow();
|
|
86
|
-
} catch (error) {
|
|
87
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const missingNameInHeader = utils.createDocument();
|
|
91
|
-
// @ts-expect-error - we are testing the error case
|
|
92
|
-
delete missingNameInHeader.header.name;
|
|
93
|
-
try {
|
|
94
|
-
expect(<%= isPhDocumentOfTypeFunctionName %>(missingNameInHeader)).toBe(false);
|
|
95
|
-
expect(<%= assertIsPhDocumentOfTypeFunctionName %>(missingNameInHeader)).toThrow();
|
|
96
|
-
} catch (error) {
|
|
97
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const missingCreatedAtUtcIsoInHeader = utils.createDocument();
|
|
101
|
-
// @ts-expect-error - we are testing the error case
|
|
102
|
-
delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
|
|
103
|
-
try {
|
|
104
|
-
expect(<%= isPhDocumentOfTypeFunctionName %>(missingCreatedAtUtcIsoInHeader)).toBe(false);
|
|
105
|
-
expect(<%= assertIsPhDocumentOfTypeFunctionName %>(missingCreatedAtUtcIsoInHeader)).toThrow();
|
|
106
|
-
} catch (error) {
|
|
107
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const missingLastModifiedAtUtcIsoInHeader = utils.createDocument();
|
|
111
|
-
// @ts-expect-error - we are testing the error case
|
|
112
|
-
delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
|
|
113
|
-
try {
|
|
114
|
-
expect(<%= isPhDocumentOfTypeFunctionName %>(missingLastModifiedAtUtcIsoInHeader)).toBe(false);
|
|
115
|
-
expect(
|
|
116
|
-
<%= assertIsPhDocumentOfTypeFunctionName %>(missingLastModifiedAtUtcIsoInHeader),
|
|
117
|
-
).toThrow();
|
|
118
|
-
} catch (error) {
|
|
119
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= paramCaseDocumentType %>/hooks.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
import type { DocumentDispatch } from "@powerhousedao/reactor-browser";
|
|
7
|
-
import {
|
|
8
|
-
useDocumentsInSelectedDrive,
|
|
9
|
-
useDocumentsInSelectedFolder,
|
|
10
|
-
useDocumentById,
|
|
11
|
-
useSelectedDocument,
|
|
12
|
-
} from "@powerhousedao/reactor-browser";
|
|
13
|
-
import type {
|
|
14
|
-
<%= phDocumentTypeName %>,
|
|
15
|
-
<%= actionTypeName %>,
|
|
16
|
-
} from "<%= documentModelDir %>";
|
|
17
|
-
import { <%= isPhDocumentOfTypeFunctionName %> } from "./gen/document-schema.js";
|
|
18
|
-
|
|
19
|
-
/** Hook to get a <%= pascalCaseDocumentType %> document by its id */
|
|
20
|
-
export function <%= useByIdHookName %>(
|
|
21
|
-
documentId: string | null | undefined,
|
|
22
|
-
):
|
|
23
|
-
| [<%= phDocumentTypeName %>, DocumentDispatch<<%= actionTypeName %>>]
|
|
24
|
-
| [undefined, undefined] {
|
|
25
|
-
const [document, dispatch] = useDocumentById(documentId);
|
|
26
|
-
if (!<%= isPhDocumentOfTypeFunctionName %>(document)) return [undefined, undefined];
|
|
27
|
-
return [document, dispatch];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Hook to get the selected <%= pascalCaseDocumentType %> document */
|
|
31
|
-
export function <%= useSelectedHookName %>():
|
|
32
|
-
| [<%= phDocumentTypeName %>, DocumentDispatch<<%= actionTypeName %>>]
|
|
33
|
-
| [undefined, undefined] {
|
|
34
|
-
const [document, dispatch] = useSelectedDocument();
|
|
35
|
-
if (!<%= isPhDocumentOfTypeFunctionName %>(document)) return [undefined, undefined];
|
|
36
|
-
return [document, dispatch];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Hook to get all <%= pascalCaseDocumentType %> documents in the selected drive */
|
|
40
|
-
export function <%= useInSelectedDriveHookName %>() {
|
|
41
|
-
const documentsInSelectedDrive = useDocumentsInSelectedDrive();
|
|
42
|
-
return documentsInSelectedDrive?.filter(<%= isPhDocumentOfTypeFunctionName %>);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Hook to get all <%= pascalCaseDocumentType %> documents in the selected folder */
|
|
46
|
-
export function <%= useInSelectedFolderHookName %>() {
|
|
47
|
-
const documentsInSelectedFolder = useDocumentsInSelectedFolder();
|
|
48
|
-
return documentsInSelectedFolder?.filter(<%= isPhDocumentOfTypeFunctionName %>);
|
|
49
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/index.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
export * from './actions.js';
|
|
6
|
-
export * from './document-model.js';
|
|
7
|
-
export * from './types.js';
|
|
8
|
-
export * from './creators.js';
|
|
9
|
-
export {
|
|
10
|
-
create<%= phDocumentTypeName %>,
|
|
11
|
-
createState,
|
|
12
|
-
defaultPHState,
|
|
13
|
-
defaultGlobalState,
|
|
14
|
-
defaultLocalState,
|
|
15
|
-
} from './ph-factories.js';
|
|
16
|
-
export * from "./utils.js";
|
|
17
|
-
export * from "./reducer.js";
|
|
18
|
-
export * from "./schema/index.js";
|
|
19
|
-
export * from "./document-type.js";
|
|
20
|
-
export * from "./document-schema.js";
|
|
21
|
-
<% modules.forEach(module => { _%>
|
|
22
|
-
export * from './<%= h.changeCase.param(module.name) %>/operations.js';
|
|
23
|
-
<% }); _%>
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
const { kebabCase, pascalCase, camelCase } = require("change-case");
|
|
3
|
-
function documentModelToString(documentModel) {
|
|
4
|
-
return JSON.stringify(
|
|
5
|
-
{
|
|
6
|
-
...documentModel,
|
|
7
|
-
specifications: documentModel.specifications.map((s) => ({
|
|
8
|
-
...s,
|
|
9
|
-
state: Object.keys(s.state).reduce((values, scope) => {
|
|
10
|
-
const state = s.state[scope];
|
|
11
|
-
return {
|
|
12
|
-
...values,
|
|
13
|
-
[scope]: {
|
|
14
|
-
...state,
|
|
15
|
-
// initial value has to be stringified twice
|
|
16
|
-
// as it is expected to be a string
|
|
17
|
-
initialValue: JSON.stringify(state.initialValue),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}, {}),
|
|
21
|
-
})),
|
|
22
|
-
},
|
|
23
|
-
null,
|
|
24
|
-
2,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = {
|
|
29
|
-
params: ({ args }) => {
|
|
30
|
-
const documentModel = JSON.parse(args.documentModel);
|
|
31
|
-
const latestSpec =
|
|
32
|
-
documentModel.specifications[documentModel.specifications.length - 1];
|
|
33
|
-
const documentType = documentModel.name;
|
|
34
|
-
const documentTypeId = documentModel.id;
|
|
35
|
-
const rootDir = args.rootDir;
|
|
36
|
-
const kebabCaseDocumentType = kebabCase(documentType);
|
|
37
|
-
const pascalCaseDocumentType = pascalCase(documentType);
|
|
38
|
-
const camelCaseDocumentType = camelCase(documentType);
|
|
39
|
-
const documentTypeVariableName = `${camelCaseDocumentType}DocumentType`;
|
|
40
|
-
const stateName = `${pascalCaseDocumentType}State`;
|
|
41
|
-
const globalStateName = `${pascalCaseDocumentType}GlobalState`;
|
|
42
|
-
const localStateName = `${pascalCaseDocumentType}LocalState`;
|
|
43
|
-
const phStateName = `${pascalCaseDocumentType}PHState`;
|
|
44
|
-
const phDocumentTypeName = `${pascalCaseDocumentType}Document`;
|
|
45
|
-
const actionTypeName = `${pascalCaseDocumentType}Action`;
|
|
46
|
-
const actionsTypeName = `${actionTypeName}s`;
|
|
47
|
-
const actionsName = camelCase(actionsTypeName);
|
|
48
|
-
const packageName = args.packageName;
|
|
49
|
-
const documentModelDir = `${packageName}/document-models/${kebabCaseDocumentType}`;
|
|
50
|
-
const stateSchemaName = `${stateName}Schema`;
|
|
51
|
-
const phDocumentSchemaName = `${phDocumentTypeName}Schema`;
|
|
52
|
-
const isPhStateOfTypeFunctionName = `is${stateName}`;
|
|
53
|
-
const assertIsPhStateOfTypeFunctionName = `assertIs${stateName}`;
|
|
54
|
-
const isPhDocumentOfTypeFunctionName = `is${phDocumentTypeName}`;
|
|
55
|
-
const assertIsPhDocumentOfTypeFunctionName = `assertIs${phDocumentTypeName}`;
|
|
56
|
-
const useByIdHookName = `use${phDocumentTypeName}ById`;
|
|
57
|
-
const useSelectedHookName = `useSelected${phDocumentTypeName}`;
|
|
58
|
-
const useInSelectedDriveHookName = `use${phDocumentTypeName}sInSelectedDrive`;
|
|
59
|
-
const useInSelectedFolderHookName = `use${phDocumentTypeName}sInSelectedFolder`;
|
|
60
|
-
return {
|
|
61
|
-
rootDir,
|
|
62
|
-
packageName,
|
|
63
|
-
useByIdHookName,
|
|
64
|
-
useSelectedHookName,
|
|
65
|
-
useInSelectedDriveHookName,
|
|
66
|
-
useInSelectedFolderHookName,
|
|
67
|
-
documentModel: documentModelToString(documentModel),
|
|
68
|
-
documentTypeVariableName,
|
|
69
|
-
documentTypeId,
|
|
70
|
-
documentType,
|
|
71
|
-
camelCaseDocumentType,
|
|
72
|
-
kebabCaseDocumentType,
|
|
73
|
-
pascalCaseDocumentType,
|
|
74
|
-
stateName,
|
|
75
|
-
globalStateName,
|
|
76
|
-
localStateName,
|
|
77
|
-
phDocumentTypeName,
|
|
78
|
-
phStateName,
|
|
79
|
-
actionTypeName,
|
|
80
|
-
actionsTypeName,
|
|
81
|
-
actionsName,
|
|
82
|
-
stateSchemaName,
|
|
83
|
-
phDocumentSchemaName,
|
|
84
|
-
isPhDocumentOfTypeFunctionName,
|
|
85
|
-
assertIsPhDocumentOfTypeFunctionName,
|
|
86
|
-
isPhStateOfTypeFunctionName,
|
|
87
|
-
assertIsPhStateOfTypeFunctionName,
|
|
88
|
-
documentModelDir,
|
|
89
|
-
extension: documentModel.extension,
|
|
90
|
-
modules: latestSpec.modules.map((m) => ({
|
|
91
|
-
...m,
|
|
92
|
-
name: kebabCase(m.name),
|
|
93
|
-
})),
|
|
94
|
-
fileExtension: documentModel.extension || "",
|
|
95
|
-
hasLocalSchema: latestSpec.state.local.schema !== "",
|
|
96
|
-
...getInitialStates(latestSpec.state),
|
|
97
|
-
};
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
function getInitialStates(scopeState) {
|
|
102
|
-
const { global, local } = scopeState;
|
|
103
|
-
const scopes = { global, local };
|
|
104
|
-
|
|
105
|
-
Object.entries(scopes).forEach(([scope, state]) => {
|
|
106
|
-
if (!isEmptyStateSchema(state.schema) && state.initialValue === "") {
|
|
107
|
-
throw new Error(
|
|
108
|
-
`${
|
|
109
|
-
scope.charAt(0).toLocaleUpperCase() + scope.slice(1)
|
|
110
|
-
} scope has a defined schema but is missing an initial value.`,
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
initialGlobalState: handleEmptyState(global.initialValue),
|
|
117
|
-
initialLocalState: handleEmptyState(local.initialValue),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function isEmptyStateSchema(schema) {
|
|
122
|
-
return schema === "" || !schema.includes("{");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function handleEmptyState(state) {
|
|
126
|
-
return state === "" ? "{}" : state;
|
|
127
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= paramCaseDocumentType %>/module.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
import type { DocumentModelModule } from "document-model";
|
|
6
|
-
import { createState } from "document-model";
|
|
7
|
-
import { defaultBaseState } from "document-model/core";
|
|
8
|
-
import type { <%= phStateName %> } from "<%= documentModelDir %>";
|
|
9
|
-
import {
|
|
10
|
-
actions,
|
|
11
|
-
documentModel,
|
|
12
|
-
reducer,
|
|
13
|
-
utils,
|
|
14
|
-
} from "<%= documentModelDir %>";
|
|
15
|
-
|
|
16
|
-
/** Document model module for the <%= pascalCaseDocumentType %> document type */
|
|
17
|
-
export const <%= pascalCaseDocumentType %>: DocumentModelModule<<%= phStateName %>> = {
|
|
18
|
-
reducer,
|
|
19
|
-
actions,
|
|
20
|
-
utils,
|
|
21
|
-
documentModel: createState(defaultBaseState(), documentModel),
|
|
22
|
-
};
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/ph-factories.esm.t
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= paramCaseDocumentType %>/gen/ph-factories.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
/**
|
|
6
|
-
* Factory methods for creating <%= phDocumentTypeName %> instances
|
|
7
|
-
*/
|
|
8
|
-
import type {
|
|
9
|
-
PHAuthState,
|
|
10
|
-
PHDocumentState,
|
|
11
|
-
PHBaseState,
|
|
12
|
-
} from "document-model";
|
|
13
|
-
import {
|
|
14
|
-
createBaseState,
|
|
15
|
-
defaultBaseState,
|
|
16
|
-
} from "document-model/core";
|
|
17
|
-
import type {
|
|
18
|
-
<%= phDocumentTypeName %>,
|
|
19
|
-
<%= localStateName %>,
|
|
20
|
-
<%= globalStateName %>,
|
|
21
|
-
<%= phStateName %>,
|
|
22
|
-
} from "./types.js";
|
|
23
|
-
import { createDocument } from "./utils.js";
|
|
24
|
-
|
|
25
|
-
export function defaultGlobalState(): <%= globalStateName %> {
|
|
26
|
-
return <%- initialGlobalState %>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function defaultLocalState(): <%= localStateName %> {
|
|
30
|
-
return <%- initialLocalState %>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function defaultPHState(): <%= phStateName %> {
|
|
34
|
-
return {
|
|
35
|
-
...defaultBaseState(),
|
|
36
|
-
global: defaultGlobalState(),
|
|
37
|
-
local: defaultLocalState(),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function createGlobalState(
|
|
42
|
-
state?: Partial<<%= globalStateName %>>,
|
|
43
|
-
): <%= globalStateName %> {
|
|
44
|
-
return {
|
|
45
|
-
...defaultGlobalState(),
|
|
46
|
-
...(state || {}),
|
|
47
|
-
} as <%= globalStateName %>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function createLocalState(
|
|
51
|
-
state?: Partial<<%= localStateName %>>,
|
|
52
|
-
): <%= localStateName %> {
|
|
53
|
-
return {
|
|
54
|
-
...defaultLocalState(),
|
|
55
|
-
...(state || {}),
|
|
56
|
-
} as <%= localStateName %>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function createState(
|
|
60
|
-
baseState?: Partial<PHBaseState>,
|
|
61
|
-
globalState?: Partial<<%= globalStateName %>>,
|
|
62
|
-
localState?: Partial<<%= localStateName %>>,
|
|
63
|
-
): <%= phStateName %> {
|
|
64
|
-
return {
|
|
65
|
-
...createBaseState(baseState?.auth, baseState?.document),
|
|
66
|
-
global: createGlobalState(globalState),
|
|
67
|
-
local: createLocalState(localState),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Creates a <%= phDocumentTypeName %> with custom global and local state
|
|
73
|
-
* This properly handles the PHBaseState requirements while allowing
|
|
74
|
-
* document-specific state to be set.
|
|
75
|
-
*/
|
|
76
|
-
export function create<%= phDocumentTypeName %>(
|
|
77
|
-
state?: Partial<{
|
|
78
|
-
auth?: Partial<PHAuthState>;
|
|
79
|
-
document?: Partial<PHDocumentState>;
|
|
80
|
-
global?: Partial<<%= globalStateName %>>;
|
|
81
|
-
local?: Partial<<%= localStateName %>>;
|
|
82
|
-
}>,
|
|
83
|
-
): <%= phDocumentTypeName %> {
|
|
84
|
-
const document = createDocument(
|
|
85
|
-
state ? createState(
|
|
86
|
-
createBaseState(state.auth, state.document),
|
|
87
|
-
state.global,
|
|
88
|
-
state.local,
|
|
89
|
-
) : undefined
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return document;
|
|
93
|
-
}
|