@powerhousedao/codegen 4.1.0-dev.107 → 4.1.0-dev.109
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-subgraph/index.js
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
const { paramCase, pascalCase, camelCase } = require("change-case");
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Extract type names from a GraphQL schema.
|
|
6
|
+
* @param {string} schema - GraphQL schema string
|
|
7
|
+
* @returns {string[]} Array of type names
|
|
8
|
+
*/
|
|
9
|
+
function extractTypeNames(schema) {
|
|
10
|
+
const found = schema.match(/(type|enum|union|interface|input)\s+(\w+)\s/g);
|
|
11
|
+
if (!found) return [];
|
|
12
|
+
return found.map((f) =>
|
|
13
|
+
f
|
|
14
|
+
.replaceAll("type ", "")
|
|
15
|
+
.replaceAll("enum ", "")
|
|
16
|
+
.replaceAll("union ", "")
|
|
17
|
+
.replaceAll("interface ", "")
|
|
18
|
+
.replaceAll("input ", "")
|
|
19
|
+
.trim()
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Apply type prefixes to GraphQL schema to namespace types and avoid collisions.
|
|
25
|
+
* Inlined from @powerhousedao/common/utils to avoid ES module import issues.
|
|
26
|
+
* @param {string} schema - GraphQL schema string
|
|
27
|
+
* @param {string} prefix - Prefix to apply to type names
|
|
28
|
+
* @param {string[]} externalTypeNames - Type names from other schemas to also prefix
|
|
29
|
+
* @returns {string} Schema with prefixed types
|
|
30
|
+
*/
|
|
31
|
+
function applyGraphQLTypePrefixes(schema, prefix, externalTypeNames = []) {
|
|
32
|
+
if (!schema || !schema.trim()) {
|
|
33
|
+
return schema;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let processedSchema = schema;
|
|
37
|
+
|
|
38
|
+
// Find types defined in this schema
|
|
39
|
+
const localTypeNames = extractTypeNames(schema);
|
|
40
|
+
|
|
41
|
+
// Combine with external type names (remove duplicates)
|
|
42
|
+
const allTypeNames = [...new Set([...localTypeNames, ...externalTypeNames])];
|
|
43
|
+
|
|
44
|
+
if (allTypeNames.length === 0) {
|
|
45
|
+
return schema;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
allTypeNames.forEach((typeName) => {
|
|
49
|
+
const typeRegex = new RegExp(
|
|
50
|
+
// Match type references in various GraphQL contexts
|
|
51
|
+
`(?<![_A-Za-z0-9])(${typeName})(?![_A-Za-z0-9])|` +
|
|
52
|
+
`\\[(${typeName})\\]|` +
|
|
53
|
+
`\\[(${typeName})!\\]|` +
|
|
54
|
+
`\\[(${typeName})\\]!|` +
|
|
55
|
+
`\\[(${typeName})!\\]!`,
|
|
56
|
+
"g",
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
processedSchema = processedSchema.replace(
|
|
60
|
+
typeRegex,
|
|
61
|
+
(match, p1, p2, p3, p4, p5) => {
|
|
62
|
+
if (match.startsWith("[")) {
|
|
63
|
+
return match.replace(
|
|
64
|
+
p2 || p3 || p4 || p5,
|
|
65
|
+
`${prefix}_${p2 || p3 || p4 || p5}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
// Basic type reference
|
|
69
|
+
return `${prefix}_${p1}`;
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return processedSchema;
|
|
75
|
+
}
|
|
76
|
+
|
|
4
77
|
module.exports = {
|
|
5
78
|
params: ({ args }) => {
|
|
6
79
|
const documentModel = JSON.parse(args.documentModel);
|
|
@@ -14,6 +87,10 @@ module.exports = {
|
|
|
14
87
|
const packageName = args.packageName;
|
|
15
88
|
const paramCaseDocumentType = paramCase(documentType);
|
|
16
89
|
const documentModelDir = `${packageName}/document-models/${paramCaseDocumentType}`;
|
|
90
|
+
|
|
91
|
+
const stateSchema = latestSpec.state.global.schema;
|
|
92
|
+
const stateTypeNames = extractTypeNames(stateSchema);
|
|
93
|
+
|
|
17
94
|
return {
|
|
18
95
|
phDocumentTypeName,
|
|
19
96
|
documentTypeVariableName,
|
|
@@ -24,10 +101,17 @@ module.exports = {
|
|
|
24
101
|
subgraph: args.subgraph,
|
|
25
102
|
documentTypeId: documentModel.id,
|
|
26
103
|
documentType: documentModel.name,
|
|
27
|
-
schema:
|
|
104
|
+
schema: applyGraphQLTypePrefixes(
|
|
105
|
+
stateSchema,
|
|
106
|
+
pascalCaseDocumentType
|
|
107
|
+
),
|
|
28
108
|
modules: latestSpec.modules.map((m) => ({
|
|
29
109
|
...m,
|
|
30
110
|
name: paramCase(m.name),
|
|
111
|
+
operations: m.operations.map((op) => ({
|
|
112
|
+
...op,
|
|
113
|
+
schema: applyGraphQLTypePrefixes(op.schema, pascalCaseDocumentType, stateTypeNames),
|
|
114
|
+
})),
|
|
31
115
|
})),
|
|
32
116
|
};
|
|
33
117
|
},
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t
CHANGED
|
@@ -28,16 +28,17 @@ type Mutation {
|
|
|
28
28
|
|
|
29
29
|
<% modules.forEach(module => { _%>
|
|
30
30
|
<% module.operations.forEach(op => { _%>
|
|
31
|
-
<%- h.changeCase.pascal(documentType) + '_' + h.changeCase.camel(op.name)
|
|
32
|
-
%>(driveId:String, docId:PHID, input:<%-
|
|
31
|
+
<%- h.changeCase.pascal(documentType) + '_' + h.changeCase.camel(op.name)
|
|
32
|
+
%>(driveId:String, docId:PHID, input:<%-
|
|
33
33
|
h.changeCase.pascal(documentType) + '_' + h.changeCase.pascal(op.name) %>Input): Int
|
|
34
34
|
<%_ })}); %>}
|
|
35
|
+
|
|
35
36
|
<% modules.forEach(module => { _%>
|
|
36
37
|
|
|
37
38
|
"""
|
|
38
39
|
Module: <%= h.changeCase.pascal(module.name) %>
|
|
39
40
|
"""
|
|
40
41
|
<% module.operations.forEach(op => { _%>
|
|
41
|
-
<%- op.schema
|
|
42
|
+
<%- op.schema %>
|
|
42
43
|
<%_ })}); %>
|
|
43
44
|
`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/codegen",
|
|
3
|
-
"version": "4.1.0-dev.
|
|
3
|
+
"version": "4.1.0-dev.109",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"prettier": "^3.6.2",
|
|
33
33
|
"read-pkg": "^9.0.1",
|
|
34
34
|
"ts-morph": "^26.0.0",
|
|
35
|
-
"@powerhousedao/common": "4.1.0-dev.
|
|
36
|
-
"@powerhousedao/config": "4.1.0-dev.
|
|
37
|
-
"@powerhousedao/design-system": "4.1.0-dev.
|
|
38
|
-
"@powerhousedao/reactor-browser": "4.1.0-dev.
|
|
39
|
-
"document-model": "4.1.0-dev.
|
|
35
|
+
"@powerhousedao/common": "4.1.0-dev.109",
|
|
36
|
+
"@powerhousedao/config": "4.1.0-dev.109",
|
|
37
|
+
"@powerhousedao/design-system": "4.1.0-dev.109",
|
|
38
|
+
"@powerhousedao/reactor-browser": "4.1.0-dev.109",
|
|
39
|
+
"document-model": "4.1.0-dev.109"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@graphql-codegen/core": "^4.0.2",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"react-dom": "^19.2.0",
|
|
51
51
|
"vitest": "^3.2.4",
|
|
52
52
|
"zod": "^3.24.3",
|
|
53
|
-
"document-drive": "4.1.0-dev.
|
|
53
|
+
"document-drive": "4.1.0-dev.109"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"tsc": "tsc",
|