@powerhousedao/codegen 0.36.0 → 0.37.0
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/cli.js +0 -78
- package/dist/create-lib/index.js +0 -7
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -4
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.d.ts +25 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.d.ts.map +1 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.js +60 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +24 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts.map +1 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +25 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/index.d.ts +22 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/index.d.ts.map +1 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/index.js +19 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts +21 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts.map +1 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +13 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.d.ts +14 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.d.ts.map +1 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.js +8 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.d.ts +21 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.d.ts.map +1 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.js +13 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.d.ts +20 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.d.ts.map +1 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.js +13 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.d.ts +16 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.d.ts.map +1 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.js +9 -0
- package/dist/src/codegen/graphql.d.ts +16 -0
- package/dist/src/codegen/graphql.d.ts.map +1 -0
- package/dist/src/codegen/graphql.js +91 -0
- package/dist/src/codegen/hygen.d.ts +23 -0
- package/dist/src/codegen/hygen.d.ts.map +1 -0
- package/dist/src/codegen/hygen.js +162 -0
- package/dist/src/codegen/index.d.ts +13 -0
- package/dist/src/codegen/index.d.ts.map +1 -0
- package/dist/src/codegen/index.js +123 -0
- package/dist/src/codegen/utils.d.ts +4 -0
- package/dist/src/codegen/utils.d.ts.map +1 -0
- package/dist/src/codegen/utils.js +40 -0
- package/dist/src/create-lib/create-project.d.ts +25 -0
- package/dist/src/create-lib/create-project.d.ts.map +1 -0
- package/dist/src/create-lib/create-project.js +158 -0
- package/dist/src/create-lib/index.d.ts +2 -0
- package/dist/src/create-lib/index.d.ts.map +1 -0
- package/dist/src/create-lib/index.js +1 -0
- package/dist/src/utils/cli.d.ts +26 -0
- package/dist/src/utils/cli.d.ts.map +1 -0
- package/dist/src/utils/cli.js +56 -0
- package/dist/src/utils/index.d.ts +4 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +3 -0
- package/dist/src/utils/mock.d.ts +4 -0
- package/dist/src/utils/mock.d.ts.map +1 -0
- package/dist/src/utils/mock.js +4 -0
- package/dist/src/utils/package-manager.d.ts +5 -0
- package/dist/src/utils/package-manager.d.ts.map +1 -0
- package/dist/src/utils/package-manager.js +16 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +12 -19
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/codegen/.hygen/templates/package.json +0 -3
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/actions.esm.t +0 -16
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/creators.esm.t +0 -8
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/customUtils.esm.t +0 -5
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/documentModel.esm.t +0 -7
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/documentModelTest.esm.t +0 -25
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/index.esm.t +0 -9
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/index.js +0 -73
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/index.js.map +0 -1
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/lib.esm.t +0 -9
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/lib.inject_export.esm.t +0 -7
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/object.esm.t +0 -49
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +0 -35
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/rootIndex.esm.t +0 -41
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/schema.esm.t +0 -6
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +0 -19
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +0 -43
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/actions.esm.t +0 -22
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/creators.esm.t +0 -34
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/customReducers.esm.t +0 -20
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t +0 -53
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t +0 -40
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +0 -33
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js.map +0 -1
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/object.esm.t +0 -37
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/operations.esm.t +0 -17
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/index.js +0 -25
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/index.js.map +0 -1
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/resolvers.esm.t +0 -62
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-mutations/schema.esm.t +0 -31
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +0 -23
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +0 -22
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/index.js +0 -17
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/index.js.map +0 -1
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/lib.esm.t +0 -9
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/lib.inject_export.esm.t +0 -7
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/story.esm.t +0 -31
- package/dist/codegen/.hygen/templates/powerhouse/generate-import-script/index.esm.t +0 -59
- package/dist/codegen/.hygen/templates/powerhouse/generate-import-script/index.js +0 -14
- package/dist/codegen/.hygen/templates/powerhouse/generate-import-script/index.js.map +0 -1
- package/dist/codegen/.hygen/templates/powerhouse/generate-import-script/utils.esm.t +0 -100
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.esm.t +0 -66
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.js +0 -17
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.js.map +0 -1
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.esm.t +0 -9
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_export.esm.t +0 -7
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.esm.t +0 -62
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.js +0 -17
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.js.map +0 -1
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-operational/lib.esm.t +0 -9
- package/dist/codegen/.hygen/templates/powerhouse/generate-processor-operational/lib.inject_export.esm.t +0 -8
- package/dist/codegen/.hygen/templates/powerhouse/generate-subgraph/index.esm.t +0 -61
- package/dist/codegen/.hygen/templates/powerhouse/generate-subgraph/index.js +0 -15
- package/dist/codegen/.hygen/templates/powerhouse/generate-subgraph/index.js.map +0 -1
- package/dist/codegen/.hygen/templates/powerhouse/generate-subgraph/lib.esm.t +0 -9
- package/dist/codegen/.hygen/templates/powerhouse/generate-subgraph/lib.inject_export.esm.t +0 -7
- package/dist/codegen/graphql.js +0 -97
- package/dist/codegen/graphql.js.map +0 -1
- package/dist/codegen/hygen.js +0 -179
- package/dist/codegen/hygen.js.map +0 -1
- package/dist/codegen/index.js +0 -146
- package/dist/codegen/index.js.map +0 -1
- package/dist/codegen/utils.js +0 -38
- package/dist/codegen/utils.js.map +0 -1
- package/dist/create-lib/index.js.map +0 -1
- package/dist/create-lib/init.js +0 -182
- package/dist/create-lib/init.js.map +0 -1
- package/dist/create-lib/utils.js +0 -19
- package/dist/create-lib/utils.js.map +0 -1
- package/dist/create-lib.d.ts +0 -1
- package/dist/graphql.d.ts +0 -18
- package/dist/hygen.d.ts +0 -28
- package/dist/index-DT1dkT-t.d.ts +0 -15
- package/dist/index.js.map +0 -1
- package/dist/utils/cli.js +0 -61
- package/dist/utils/cli.js.map +0 -1
- package/dist/utils/index.js +0 -6
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/mock.js +0 -9
- package/dist/utils/mock.js.map +0 -1
- package/dist/utils.d.ts +0 -59
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/index.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
import { generateId } from "document-model/utils";
|
|
6
|
-
import {
|
|
7
|
-
OperationalProcessor,
|
|
8
|
-
ProcessorOptions,
|
|
9
|
-
ProcessorSetupArgs,
|
|
10
|
-
ProcessorUpdate,
|
|
11
|
-
} from "@powerhousedao/reactor-api";
|
|
12
|
-
<% documentTypes.forEach(type => { _%>
|
|
13
|
-
import { <%= documentTypesMap[type].name %>Document } from "<%= documentTypesMap[type].importPath %>";
|
|
14
|
-
%><% }); _%>
|
|
15
|
-
<% if(documentTypes.length === 0) { %>import { Document } from "document-model/document";<% } %>
|
|
16
|
-
type DocumentType = <% if(documentTypes.length) { %><%= documentTypes.map(type => `${documentTypesMap[type].name}Document`).join(" | ") %> <% } else { %>Document<% } %>;
|
|
17
|
-
|
|
18
|
-
export class <%= pascalName %>Processor extends OperationalProcessor<% if(documentTypes.length) { %><DocumentType><% } %> {
|
|
19
|
-
|
|
20
|
-
protected processorOptions: ProcessorOptions = {
|
|
21
|
-
listenerId: generateId(),
|
|
22
|
-
filter: {
|
|
23
|
-
branch: ["main"],
|
|
24
|
-
documentId: ["*"],
|
|
25
|
-
documentType: [<% if(documentTypes.length) { %><%- documentTypes.map(type => `"${type}"`).join(", ") %><% } else { %>"*"<% } %>],
|
|
26
|
-
scope: ["global"],
|
|
27
|
-
},
|
|
28
|
-
block: false,
|
|
29
|
-
label: "<%= name %>",
|
|
30
|
-
system: true,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
async onStrands(strands: ProcessorUpdate<DocumentType>[]): Promise<void> {
|
|
34
|
-
if (strands.length === 0) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
for (const strand of strands) {
|
|
39
|
-
if (strand.operations.length === 0) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for (const operation of strand.operations) {
|
|
44
|
-
console.log(">>> ", operation.type);
|
|
45
|
-
await this.operationalStore("index_search_op").insert({
|
|
46
|
-
documentId: strand.documentId,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async onSetup(args: ProcessorSetupArgs) {
|
|
53
|
-
await super.onSetup(args);
|
|
54
|
-
await this.operationalStore.schema.createTable("index_search_op", (table) => {
|
|
55
|
-
table.increments("id").primary();
|
|
56
|
-
table.string("documentId").notNullable();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async onDisconnect() {}
|
|
61
|
-
|
|
62
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var generate_processor_operational_default = {
|
|
4
|
-
params: ({ args }) => {
|
|
5
|
-
return {
|
|
6
|
-
rootDir: args.rootDir,
|
|
7
|
-
documentModelsDir: args.documentModelsDir,
|
|
8
|
-
name: args.name,
|
|
9
|
-
documentTypes: args.documentTypes.split(",").filter((type) => type !== ""),
|
|
10
|
-
documentTypesMap: JSON.parse(args.documentTypesMap)
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
module.exports = generate_processor_operational_default;
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
package/dist/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.ts"],"names":[],"mappings":";;AAQA,IAAO,sCAAQ,GAAA;AAAA,EACb,MAAQ,EAAA,CAAC,EAAE,IAAA,EAA2B,KAAA;AACpC,IAAO,OAAA;AAAA,MACL,SAAS,IAAK,CAAA,OAAA;AAAA,MACd,mBAAmB,IAAK,CAAA,iBAAA;AAAA,MACxB,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,aAAA,EAAe,IAAK,CAAA,aAAA,CACjB,KAAM,CAAA,GAAG,EACT,MAAO,CAAA,CAAC,IAAS,KAAA,IAAA,KAAS,EAAE,CAAA;AAAA,MAC/B,gBAAkB,EAAA,IAAA,CAAK,KAAM,CAAA,IAAA,CAAK,gBAAgB;AAAA,KAIpD;AAAA;AAEJ","file":"index.js","sourcesContent":["export type Args = {\n name: string;\n rootDir: string;\n documentModelsDir: string;\n documentTypes: string;\n documentTypesMap: string;\n};\n\nexport default {\n params: ({ args }: { args: Args }) => {\n return {\n rootDir: args.rootDir,\n documentModelsDir: args.documentModelsDir,\n name: args.name,\n documentTypes: args.documentTypes\n .split(\",\")\n .filter((type) => type !== \"\"),\n documentTypesMap: JSON.parse(args.documentTypesMap) as Record<\n string,\n string\n >,\n };\n },\n};\n"]}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/index.ts"
|
|
3
|
-
force: true
|
|
4
|
-
---
|
|
5
|
-
import { Subgraph } from "@powerhousedao/reactor-api";
|
|
6
|
-
import { gql } from "graphql-tag";
|
|
7
|
-
<% if (loadFromFile) { %>
|
|
8
|
-
import { readFileSync } from "fs";
|
|
9
|
-
import path from "path";
|
|
10
|
-
import { getResolvers } from "./resolvers";
|
|
11
|
-
|
|
12
|
-
// TODO: find a better way to import the graphql schema
|
|
13
|
-
const gqlFile = path.join(path.resolve(path.dirname('')), './subgraphs/<%= h.changeCase.param(name) %>/schema.graphql');
|
|
14
|
-
const gqlCode = readFileSync(gqlFile).toString();
|
|
15
|
-
<% } %>
|
|
16
|
-
|
|
17
|
-
export class <%= pascalName %>Subgraph extends Subgraph {
|
|
18
|
-
name = "<%= h.changeCase.param(name) %>";
|
|
19
|
-
<% if (loadFromFile) { %>
|
|
20
|
-
typeDefs = gql`${gqlCode}`;
|
|
21
|
-
|
|
22
|
-
resolvers = getResolvers(this, "powerhouse");
|
|
23
|
-
additionalContextFields = {};
|
|
24
|
-
async onSetup() {}
|
|
25
|
-
async onDisconnect() {}
|
|
26
|
-
<% } else { %>
|
|
27
|
-
|
|
28
|
-
resolvers = {
|
|
29
|
-
Query: {
|
|
30
|
-
example: {
|
|
31
|
-
resolve: async (parent, args, context, info) => {
|
|
32
|
-
return "example";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
typeDefs = gql`
|
|
39
|
-
type Query {
|
|
40
|
-
example(id: ID!): String
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
additionalContextFields = {
|
|
45
|
-
example: "test"
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async onSetup() {
|
|
49
|
-
await this.createOperationalTables();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async createOperationalTables() {
|
|
53
|
-
await this.operationalStore.schema.createTableIfNotExists("example", (table) => {
|
|
54
|
-
table.string("id").primary();
|
|
55
|
-
table.string("name");
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async onDisconnect() {}
|
|
60
|
-
<% } %>
|
|
61
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var generate_subgraph_default = {
|
|
4
|
-
params: ({ args }) => {
|
|
5
|
-
return {
|
|
6
|
-
rootDir: args.rootDir,
|
|
7
|
-
name: args.name,
|
|
8
|
-
loadFromFile: args.loadFromFile
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
module.exports = generate_subgraph_default;
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.ts"],"names":[],"mappings":";;AAMA,IAAO,yBAAQ,GAAA;AAAA,EACb,MAAQ,EAAA,CAAC,EAAE,IAAA,EAA2B,KAAA;AACpC,IAAO,OAAA;AAAA,MACL,SAAS,IAAK,CAAA,OAAA;AAAA,MACd,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,cAAc,IAAK,CAAA;AAAA,KACrB;AAAA;AAEJ","file":"index.js","sourcesContent":["export type Args = {\n name: string;\n rootDir: string;\n loadFromFile: string;\n};\n\nexport default {\n params: ({ args }: { args: Args }) => {\n return {\n rootDir: args.rootDir,\n name: args.name,\n loadFromFile: args.loadFromFile,\n };\n },\n};\n"]}
|
package/dist/codegen/graphql.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { generate } from '@graphql-codegen/cli';
|
|
2
|
-
import { readdirSync } from 'node:fs';
|
|
3
|
-
import { generatorTypeDefs, validationSchema } from '@powerhousedao/scalars';
|
|
4
|
-
import { formatWithPrettierBeforeWrite } from './utils.js';
|
|
5
|
-
|
|
6
|
-
const getDirectories = (source) => readdirSync(source, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
|
|
7
|
-
const tsConfig = {
|
|
8
|
-
strictScalars: true,
|
|
9
|
-
scalars: {
|
|
10
|
-
Unknown: "unknown",
|
|
11
|
-
DateTime: "string",
|
|
12
|
-
Attachment: "string",
|
|
13
|
-
Address: "`${string}:0x${string}`",
|
|
14
|
-
...generatorTypeDefs
|
|
15
|
-
},
|
|
16
|
-
enumsAsTypes: true,
|
|
17
|
-
allowEnumStringTypes: true,
|
|
18
|
-
avoidOptionals: {
|
|
19
|
-
field: true
|
|
20
|
-
},
|
|
21
|
-
skipTypename: true,
|
|
22
|
-
// maybeValue: "T | null | undefined",
|
|
23
|
-
inputMaybeValue: "T | null | undefined"
|
|
24
|
-
};
|
|
25
|
-
const validationConfig = {
|
|
26
|
-
importFrom: `./types`,
|
|
27
|
-
schema: "zod",
|
|
28
|
-
...tsConfig,
|
|
29
|
-
scalarSchemas: {
|
|
30
|
-
Unknown: "z.unknown()",
|
|
31
|
-
DateTime: "z.string().datetime()",
|
|
32
|
-
Attachment: "z.string()",
|
|
33
|
-
Address: "z.custom<`${string}:0x${string}`>((val) => /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/.test(val as string))",
|
|
34
|
-
...validationSchema
|
|
35
|
-
},
|
|
36
|
-
directives: {
|
|
37
|
-
equals: {
|
|
38
|
-
value: ["regex", "/^$1$/"]
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
withObjectType: true
|
|
42
|
-
};
|
|
43
|
-
function schemaConfig(name, dir) {
|
|
44
|
-
return {
|
|
45
|
-
[`${dir}/${name}/gen/schema/types.ts`]: {
|
|
46
|
-
schema: [
|
|
47
|
-
{
|
|
48
|
-
[`${dir}/${name}/schema.graphql`]: {
|
|
49
|
-
skipGraphQLImport: false
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
plugins: ["typescript"],
|
|
54
|
-
config: tsConfig
|
|
55
|
-
},
|
|
56
|
-
[`${dir}/${name}/gen/schema/zod.ts`]: {
|
|
57
|
-
schema: `${dir}/${name}/schema.graphql`,
|
|
58
|
-
plugins: ["@acaldas/graphql-codegen-typescript-validation-schema"],
|
|
59
|
-
config: validationConfig
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
const generateSchema = (model, dir, { watch = false, skipFormat = false } = {}) => {
|
|
64
|
-
const documentModelConfig = schemaConfig(model, dir);
|
|
65
|
-
const config = {
|
|
66
|
-
overwrite: true,
|
|
67
|
-
generates: documentModelConfig,
|
|
68
|
-
watch,
|
|
69
|
-
hooks: {
|
|
70
|
-
beforeOneFileWrite: skipFormat ? [] : [formatWithPrettierBeforeWrite]
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
return generate(config, true);
|
|
74
|
-
};
|
|
75
|
-
const generateSchemas = (dir, { watch = false, skipFormat = false } = {}) => {
|
|
76
|
-
const documentModels = getDirectories(dir);
|
|
77
|
-
const documentModelConfigs = documentModels.reduce(
|
|
78
|
-
(obj, model) => ({
|
|
79
|
-
...obj,
|
|
80
|
-
...schemaConfig(model, dir)
|
|
81
|
-
}),
|
|
82
|
-
{}
|
|
83
|
-
);
|
|
84
|
-
const config = {
|
|
85
|
-
overwrite: true,
|
|
86
|
-
generates: documentModelConfigs,
|
|
87
|
-
watch,
|
|
88
|
-
hooks: {
|
|
89
|
-
beforeOneFileWrite: skipFormat ? [] : [formatWithPrettierBeforeWrite]
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
return generate(config, true);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export { generateSchema, generateSchemas, schemaConfig, tsConfig, validationConfig };
|
|
96
|
-
//# sourceMappingURL=graphql.js.map
|
|
97
|
-
//# sourceMappingURL=graphql.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/codegen/graphql.ts"],"names":[],"mappings":";;;;;AAOA,MAAM,cAAA,GAAiB,CAAC,MACtB,KAAA,WAAA,CAAY,QAAQ,EAAE,aAAA,EAAe,MAAM,CAAA,CACxC,OAAO,CAAC,MAAA,KAAW,OAAO,WAAY,EAAC,EACvC,GAAI,CAAA,CAAC,MAAW,KAAA,MAAA,CAAO,IAAI,CAAA;AAEzB,MAAM,QAAmC,GAAA;AAAA,EAC9C,aAAe,EAAA,IAAA;AAAA,EACf,OAAS,EAAA;AAAA,IACP,OAAS,EAAA,SAAA;AAAA,IACT,QAAU,EAAA,QAAA;AAAA,IACV,UAAY,EAAA,QAAA;AAAA,IACZ,OAAS,EAAA,yBAAA;AAAA,IACT,GAAI;AAAA,GACN;AAAA,EACA,YAAc,EAAA,IAAA;AAAA,EACd,oBAAsB,EAAA,IAAA;AAAA,EACtB,cAAgB,EAAA;AAAA,IACd,KAAO,EAAA;AAAA,GACT;AAAA,EACA,YAAc,EAAA,IAAA;AAAA;AA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,GAAsB,YAAa,CAAA,KAAA,EAAO,GAAG,CAAA;AAEnD,EAAA,MAAM,MAAwB,GAAA;AAAA,IAC5B,SAAW,EAAA,IAAA;AAAA,IACX,SAAW,EAAA,mBAAA;AAAA,IACX,KAAA;AAAA,IACA,KAAO,EAAA;AAAA,MACL,kBAAoB,EAAA,UAAA,GAAa,EAAC,GAAI,CAAC,6BAA6B;AAAA;AACtE,GACF;AACA,EAAO,OAAA,QAAA,CAAS,QAAQ,IAAI,CAAA;AAC9B;AAEa,MAAA,eAAA,GAAkB,CAC7B,GAAA,EACA,EAAE,KAAA,GAAQ,OAAO,UAAa,GAAA,KAAA,EAAU,GAAA,EACrC,KAAA;AACH,EAAM,MAAA,cAAA,GAAiB,eAAe,GAAG,CAAA;AACzC,EAAA,MAAM,uBAAuB,cAAe,CAAA,MAAA;AAAA,IAC1C,CAAC,KAAK,KAAW,MAAA;AAAA,MACf,GAAG,GAAA;AAAA,MACH,GAAG,YAAa,CAAA,KAAA,EAAO,GAAG;AAAA,KAC5B,CAAA;AAAA,IACA;AAAC,GACH;AAEA,EAAA,MAAM,MAAwB,GAAA;AAAA,IAC5B,SAAW,EAAA,IAAA;AAAA,IACX,SAAW,EAAA,oBAAA;AAAA,IACX,KAAA;AAAA,IACA,KAAO,EAAA;AAAA,MACL,kBAAoB,EAAA,UAAA,GAAa,EAAC,GAAI,CAAC,6BAA6B;AAAA;AACtE,GACF;AACA,EAAO,OAAA,QAAA,CAAS,QAAQ,IAAI,CAAA;AAC9B","file":"graphql.js","sourcesContent":["import { type CodegenConfig, generate } from \"@graphql-codegen/cli\";\nimport { TypeScriptPluginConfig } from \"@graphql-codegen/typescript\";\nimport { plugin } from \"@acaldas/graphql-codegen-typescript-validation-schema\";\nimport { readdirSync } from \"node:fs\";\nimport { generatorTypeDefs, validationSchema } from \"@powerhousedao/scalars\";\nimport { formatWithPrettierBeforeWrite } from \"./utils\";\n\nconst getDirectories = (source: string) =>\n readdirSync(source, { withFileTypes: true })\n .filter((dirent) => dirent.isDirectory())\n .map((dirent) => dirent.name);\n\nexport const tsConfig: TypeScriptPluginConfig = {\n strictScalars: true,\n scalars: {\n Unknown: \"unknown\",\n DateTime: \"string\",\n Attachment: \"string\",\n Address: \"`${string}:0x${string}`\",\n ...(generatorTypeDefs as Record<string, string>),\n },\n enumsAsTypes: true,\n allowEnumStringTypes: true,\n avoidOptionals: {\n field: true,\n },\n skipTypename: true,\n // maybeValue: \"T | null | undefined\",\n inputMaybeValue: \"T | null | undefined\",\n};\n\nexport type ValidationSchemaConfigType = Parameters<typeof plugin>[2];\n\nexport const validationConfig: ValidationSchemaConfigType = {\n importFrom: `./types`,\n schema: \"zod\",\n ...tsConfig,\n scalarSchemas: {\n Unknown: \"z.unknown()\",\n DateTime: \"z.string().datetime()\",\n Attachment: \"z.string()\",\n Address:\n \"z.custom<`${string}:0x${string}`>((val) => /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/.test(val as string))\",\n ...(validationSchema as Record<string, string>),\n },\n directives: {\n equals: {\n value: [\"regex\", \"/^$1$/\"],\n },\n },\n withObjectType: true,\n};\n\nexport function schemaConfig(\n name: string,\n dir: string,\n): CodegenConfig[\"generates\"] {\n return {\n [`${dir}/${name}/gen/schema/types.ts`]: {\n schema: [\n {\n [`${dir}/${name}/schema.graphql`]: {\n skipGraphQLImport: false,\n },\n },\n ],\n plugins: [\"typescript\"],\n config: tsConfig,\n },\n [`${dir}/${name}/gen/schema/zod.ts`]: {\n schema: `${dir}/${name}/schema.graphql`,\n plugins: [\"@acaldas/graphql-codegen-typescript-validation-schema\"],\n config: validationConfig,\n },\n };\n}\n\nexport const generateSchema = (\n model: string,\n dir: string,\n { watch = false, skipFormat = false } = {},\n) => {\n const documentModelConfig = schemaConfig(model, dir);\n\n const config: CodegenConfig = {\n overwrite: true,\n generates: documentModelConfig,\n watch,\n hooks: {\n beforeOneFileWrite: skipFormat ? [] : [formatWithPrettierBeforeWrite],\n },\n };\n return generate(config, true);\n};\n\nexport const generateSchemas = (\n dir: string,\n { watch = false, skipFormat = false } = {},\n) => {\n const documentModels = getDirectories(dir);\n const documentModelConfigs = documentModels.reduce(\n (obj, model) => ({\n ...obj,\n ...schemaConfig(model, dir),\n }),\n {},\n );\n\n const config: CodegenConfig = {\n overwrite: true,\n generates: documentModelConfigs,\n watch,\n hooks: {\n beforeOneFileWrite: skipFormat ? [] : [formatWithPrettierBeforeWrite],\n },\n };\n return generate(config, true);\n};\n"]}
|
package/dist/codegen/hygen.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { pascalCase } from 'change-case';
|
|
2
|
-
import { Logger, runner } from 'hygen';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import { createRequire } from 'node:module';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import { loadDocumentModel } from './utils.js';
|
|
8
|
-
|
|
9
|
-
const require2 = createRequire(import.meta.url);
|
|
10
|
-
const __dirname = import.meta.dirname || path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
const logger = new Logger(console.log.bind(console));
|
|
12
|
-
const defaultTemplates = path.join(__dirname, ".hygen", "templates");
|
|
13
|
-
async function run(args, { watch = false, skipFormat = false } = {}) {
|
|
14
|
-
const result = await runner(args, {
|
|
15
|
-
templates: defaultTemplates,
|
|
16
|
-
cwd: process.cwd(),
|
|
17
|
-
logger,
|
|
18
|
-
createPrompter: () => {
|
|
19
|
-
return require2("enquirer");
|
|
20
|
-
},
|
|
21
|
-
exec: (action, body) => {
|
|
22
|
-
const opts = body && body.length > 0 ? { input: body } : {};
|
|
23
|
-
return require2("execa").shell(action, opts);
|
|
24
|
-
},
|
|
25
|
-
debug: !!process.env.DEBUG
|
|
26
|
-
});
|
|
27
|
-
if (!skipFormat) {
|
|
28
|
-
const execa = await import('execa');
|
|
29
|
-
const actions = result.actions;
|
|
30
|
-
actions.filter((action) => ["added", "inject"].includes(action.status)).forEach((action) => {
|
|
31
|
-
execa.$`prettier --ignore-path --write ${action.subject.replace(
|
|
32
|
-
".",
|
|
33
|
-
process.cwd()
|
|
34
|
-
)}`.catch((err) => {
|
|
35
|
-
console.log(err);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
async function generateAll(dir, { watch = false, skipFormat = false } = {}) {
|
|
42
|
-
const files = fs.readdirSync(dir, { withFileTypes: true });
|
|
43
|
-
for (const directory of files.filter((f) => f.isDirectory())) {
|
|
44
|
-
const documentModelPath = path.join(
|
|
45
|
-
dir,
|
|
46
|
-
directory.name,
|
|
47
|
-
`${directory.name}.json`
|
|
48
|
-
);
|
|
49
|
-
if (!fs.existsSync(documentModelPath)) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
const documentModel = await loadDocumentModel(documentModelPath);
|
|
54
|
-
await generateDocumentModel(documentModel, dir, { watch, skipFormat });
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error(directory.name, error);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async function generateDocumentModel(documentModel, dir, { watch = false, skipFormat = false } = {}) {
|
|
61
|
-
await run(
|
|
62
|
-
[
|
|
63
|
-
"powerhouse",
|
|
64
|
-
"generate-document-model",
|
|
65
|
-
"--document-model",
|
|
66
|
-
JSON.stringify(documentModel),
|
|
67
|
-
"--root-dir",
|
|
68
|
-
dir
|
|
69
|
-
],
|
|
70
|
-
{ watch, skipFormat }
|
|
71
|
-
);
|
|
72
|
-
const latestSpec = documentModel.specifications[documentModel.specifications.length - 1];
|
|
73
|
-
for (const module of latestSpec.modules) {
|
|
74
|
-
await run(
|
|
75
|
-
[
|
|
76
|
-
"powerhouse",
|
|
77
|
-
"generate-document-model-module",
|
|
78
|
-
"--document-model",
|
|
79
|
-
JSON.stringify(documentModel),
|
|
80
|
-
"--root-dir",
|
|
81
|
-
dir,
|
|
82
|
-
"--module",
|
|
83
|
-
module.name
|
|
84
|
-
],
|
|
85
|
-
{ watch, skipFormat }
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async function generateEditor(name, documentTypes, documentTypesMap, dir, documentModelsDir, { skipFormat = false } = {}) {
|
|
90
|
-
await run(
|
|
91
|
-
[
|
|
92
|
-
"powerhouse",
|
|
93
|
-
"generate-editor",
|
|
94
|
-
"--name",
|
|
95
|
-
name,
|
|
96
|
-
"--root-dir",
|
|
97
|
-
dir,
|
|
98
|
-
"--document-types",
|
|
99
|
-
documentTypes.join(","),
|
|
100
|
-
"--document-types-map",
|
|
101
|
-
JSON.stringify(documentTypesMap),
|
|
102
|
-
"--document-models-dir",
|
|
103
|
-
documentModelsDir
|
|
104
|
-
],
|
|
105
|
-
{ skipFormat }
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
async function generateProcessor(name, documentTypes, documentTypesMap, dir, documentModelsDir, type = "analytics", { skipFormat = false } = {}) {
|
|
109
|
-
const processorType = type === "operational" ? "operational" : "analytics";
|
|
110
|
-
await run(
|
|
111
|
-
[
|
|
112
|
-
"powerhouse",
|
|
113
|
-
`generate-processor-${processorType}`,
|
|
114
|
-
"--name",
|
|
115
|
-
name,
|
|
116
|
-
"--pascalName",
|
|
117
|
-
pascalCase(name),
|
|
118
|
-
"--root-dir",
|
|
119
|
-
dir,
|
|
120
|
-
"--document-types",
|
|
121
|
-
documentTypes.join(","),
|
|
122
|
-
"--document-types-map",
|
|
123
|
-
JSON.stringify(documentTypesMap),
|
|
124
|
-
"--document-models-dir",
|
|
125
|
-
documentModelsDir
|
|
126
|
-
],
|
|
127
|
-
{ skipFormat }
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
async function generateSubgraph(name, documentModel, dir, { skipFormat = false } = {}) {
|
|
131
|
-
const params = [
|
|
132
|
-
"powerhouse",
|
|
133
|
-
`generate-subgraph`,
|
|
134
|
-
"--name",
|
|
135
|
-
name,
|
|
136
|
-
"--pascalName",
|
|
137
|
-
pascalCase(name),
|
|
138
|
-
"--root-dir",
|
|
139
|
-
dir
|
|
140
|
-
];
|
|
141
|
-
if (documentModel) {
|
|
142
|
-
params.push("--loadFromFile", "1");
|
|
143
|
-
}
|
|
144
|
-
await run(params, { skipFormat });
|
|
145
|
-
if (documentModel) {
|
|
146
|
-
await run(
|
|
147
|
-
[
|
|
148
|
-
"powerhouse",
|
|
149
|
-
"generate-document-model-mutations",
|
|
150
|
-
"--subgraph",
|
|
151
|
-
name,
|
|
152
|
-
"--document-model",
|
|
153
|
-
JSON.stringify(documentModel),
|
|
154
|
-
"--root-dir",
|
|
155
|
-
dir
|
|
156
|
-
],
|
|
157
|
-
{ skipFormat }
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
async function generateImportScript(name, dir, { skipFormat = false } = {}) {
|
|
162
|
-
await run(
|
|
163
|
-
[
|
|
164
|
-
"powerhouse",
|
|
165
|
-
`generate-import-script`,
|
|
166
|
-
"--name",
|
|
167
|
-
name,
|
|
168
|
-
"--pascalName",
|
|
169
|
-
pascalCase(name),
|
|
170
|
-
"--root-dir",
|
|
171
|
-
dir
|
|
172
|
-
],
|
|
173
|
-
{ skipFormat }
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export { generateAll, generateDocumentModel, generateEditor, generateImportScript, generateProcessor, generateSubgraph };
|
|
178
|
-
//# sourceMappingURL=hygen.js.map
|
|
179
|
-
//# sourceMappingURL=hygen.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/codegen/hygen.ts"],"names":["require"],"mappings":";;;;;;;;AAWA,MAAMA,QAAAA,GAAU,aAAc,CAAA,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAE7C,MAAM,SAAA,GACJ,YAAY,OAAW,IAAA,IAAA,CAAK,QAAQ,aAAc,CAAA,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA;AACp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IACJ;AAAA,MACE,YAAA;AAAA,MACA,CAAA,sBAAA,CAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,cAAA;AAAA,MACA,WAAW,IAAI,CAAA;AAAA,MACf,YAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,EAAE,UAAW;AAAA,GACf;AACF","file":"hygen.js","sourcesContent":["import { pascalCase } from \"change-case\";\nimport { DocumentModel } from \"document-model\";\nimport { DocumentModelState } from \"document-model/document-model\";\nimport { Logger, runner } from \"hygen\";\nimport fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { DocumentTypesMap } from \".\";\nimport { loadDocumentModel } from \"./utils\";\n\nconst require = createRequire(import.meta.url);\n\nconst __dirname =\n import.meta.dirname || path.dirname(fileURLToPath(import.meta.url));\nconst logger = new Logger(console.log.bind(console));\nconst defaultTemplates = path.join(__dirname, \".hygen\", \"templates\");\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nasync function run(args: string[], { watch = false, skipFormat = false } = {}) {\n const result = await runner(args, {\n templates: defaultTemplates,\n cwd: process.cwd(),\n logger,\n createPrompter: () => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return require(\"enquirer\");\n },\n exec: (action, body) => {\n const opts = body && body.length > 0 ? { input: body } : {};\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access\n return require(\"execa\").shell(action, opts);\n },\n debug: !!process.env.DEBUG,\n });\n if (!skipFormat) {\n const execa = await import(\"execa\");\n const actions = result.actions as { status: string; subject: string }[];\n actions\n .filter((action) => [\"added\", \"inject\"].includes(action.status))\n .forEach((action) => {\n execa.$`prettier --ignore-path --write ${action.subject.replace(\n \".\",\n process.cwd(),\n )}`.catch((err: unknown) => {\n console.log(err);\n });\n });\n }\n\n return result;\n}\n\nexport async function generateAll(\n dir: string,\n { watch = false, skipFormat = false } = {},\n) {\n const files = fs.readdirSync(dir, { withFileTypes: true });\n for (const directory of files.filter((f) => f.isDirectory())) {\n const documentModelPath = path.join(\n dir,\n directory.name,\n `${directory.name}.json`,\n );\n if (!fs.existsSync(documentModelPath)) {\n continue;\n }\n\n try {\n const documentModel = await loadDocumentModel(documentModelPath);\n await generateDocumentModel(documentModel, dir, { watch, skipFormat });\n } catch (error) {\n console.error(directory.name, error);\n }\n }\n}\n\nexport async function generateDocumentModel(\n documentModel: DocumentModel.DocumentModelState,\n dir: string,\n { watch = false, skipFormat = false } = {},\n) {\n // Generate the singular files for the document model logic\n await run(\n [\n \"powerhouse\",\n \"generate-document-model\",\n \"--document-model\",\n JSON.stringify(documentModel),\n \"--root-dir\",\n dir,\n ],\n { watch, skipFormat },\n );\n\n const latestSpec =\n documentModel.specifications[documentModel.specifications.length - 1];\n\n // Generate the module-specific files for the document model logic\n for (const module of latestSpec.modules) {\n await run(\n [\n \"powerhouse\",\n \"generate-document-model-module\",\n \"--document-model\",\n JSON.stringify(documentModel),\n \"--root-dir\",\n dir,\n \"--module\",\n module.name,\n ],\n { watch, skipFormat },\n );\n }\n}\n\nexport async function generateEditor(\n name: string,\n documentTypes: string[],\n documentTypesMap: DocumentTypesMap,\n dir: string,\n documentModelsDir: string,\n { skipFormat = false } = {},\n) {\n // Generate the singular files for the document model logic\n await run(\n [\n \"powerhouse\",\n \"generate-editor\",\n \"--name\",\n name,\n \"--root-dir\",\n dir,\n \"--document-types\",\n documentTypes.join(\",\"),\n \"--document-types-map\",\n JSON.stringify(documentTypesMap),\n \"--document-models-dir\",\n documentModelsDir,\n ],\n { skipFormat },\n );\n}\n\nexport async function generateProcessor(\n name: string,\n documentTypes: string[],\n documentTypesMap: DocumentTypesMap,\n dir: string,\n documentModelsDir: string,\n type = \"analytics\",\n { skipFormat = false } = {},\n) {\n // Generate the singular files for the document model logic\n const processorType = type === \"operational\" ? \"operational\" : \"analytics\";\n await run(\n [\n \"powerhouse\",\n `generate-processor-${processorType}`,\n \"--name\",\n name,\n \"--pascalName\",\n pascalCase(name),\n \"--root-dir\",\n dir,\n \"--document-types\",\n documentTypes.join(\",\"),\n \"--document-types-map\",\n JSON.stringify(documentTypesMap),\n \"--document-models-dir\",\n documentModelsDir,\n ],\n { skipFormat },\n );\n}\n\nexport async function generateSubgraph(\n name: string,\n documentModel: DocumentModelState | null,\n dir: string,\n { skipFormat = false } = {},\n) {\n const params = [\n \"powerhouse\",\n `generate-subgraph`,\n \"--name\",\n name,\n \"--pascalName\",\n pascalCase(name),\n \"--root-dir\",\n dir,\n ];\n\n if (documentModel) {\n params.push(\"--loadFromFile\", \"1\");\n }\n\n // Generate the singular files for the document model logic\n await run(params, { skipFormat });\n\n if (documentModel) {\n // Generate the GraphQL mutation schemas\n await run(\n [\n \"powerhouse\",\n \"generate-document-model-mutations\",\n \"--subgraph\",\n name,\n \"--document-model\",\n JSON.stringify(documentModel),\n \"--root-dir\",\n dir,\n ],\n { skipFormat },\n );\n }\n}\n\nexport async function generateImportScript(\n name: string,\n dir: string,\n { skipFormat = false } = {},\n) {\n // Generate the singular files for the document model logic\n await run(\n [\n \"powerhouse\",\n `generate-import-script`,\n \"--name\",\n name,\n \"--pascalName\",\n pascalCase(name),\n \"--root-dir\",\n dir,\n ],\n { skipFormat },\n );\n}\n"]}
|
package/dist/codegen/index.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import { typeDefs } from '@powerhousedao/scalars';
|
|
3
|
-
import { paramCase, pascalCase } from 'change-case';
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import { join, resolve } from 'path';
|
|
6
|
-
import { generateSchemas, generateSchema } from './graphql.js';
|
|
7
|
-
import { generateAll, generateDocumentModel, generateEditor as generateEditor$1, generateSubgraph as generateSubgraph$1, generateProcessor as generateProcessor$1, generateImportScript as generateImportScript$1 } from './hygen.js';
|
|
8
|
-
import { loadDocumentModel } from './utils.js';
|
|
9
|
-
|
|
10
|
-
function generateGraphqlSchema(documentModel) {
|
|
11
|
-
const spec = documentModel.specifications[documentModel.specifications.length - 1];
|
|
12
|
-
if (!spec) {
|
|
13
|
-
throw new Error(`No spec found for ${documentModel.id}`);
|
|
14
|
-
}
|
|
15
|
-
const {
|
|
16
|
-
modules,
|
|
17
|
-
state: { global, local }
|
|
18
|
-
} = spec;
|
|
19
|
-
const schemas = [
|
|
20
|
-
global.schema,
|
|
21
|
-
local.schema,
|
|
22
|
-
...modules.map((module) => [
|
|
23
|
-
`# ${module.name}`,
|
|
24
|
-
...module.operations.map((op) => op.schema)
|
|
25
|
-
]).flat().filter((schema) => schema && schema.length > 0)
|
|
26
|
-
];
|
|
27
|
-
return schemas.join("\n\n");
|
|
28
|
-
}
|
|
29
|
-
async function getDocumentTypesMap(dir, pathOrigin = "../../../") {
|
|
30
|
-
const documentTypesMap = {};
|
|
31
|
-
if (fs.existsSync(dir)) {
|
|
32
|
-
fs.readdirSync(dir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name).forEach((name) => {
|
|
33
|
-
const specPath = resolve(dir, name, `${name}.json`);
|
|
34
|
-
if (!fs.existsSync(specPath)) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const specRaw = fs.readFileSync(specPath, "utf-8");
|
|
38
|
-
try {
|
|
39
|
-
const spec = JSON.parse(specRaw);
|
|
40
|
-
if (spec.id) {
|
|
41
|
-
documentTypesMap[spec.id] = {
|
|
42
|
-
name: pascalCase(name),
|
|
43
|
-
importPath: join(pathOrigin, dir, name)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
} catch {
|
|
47
|
-
console.error(`Failed to parse ${specPath}`);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const documentModels = await import('document-model-libs/document-models');
|
|
53
|
-
Object.keys(documentModels).forEach((name) => {
|
|
54
|
-
const documentModel = documentModels[name];
|
|
55
|
-
documentTypesMap[documentModel.documentModel.id] = {
|
|
56
|
-
name,
|
|
57
|
-
importPath: `document-model-libs/${paramCase(name)}`
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
} catch {
|
|
61
|
-
}
|
|
62
|
-
return documentTypesMap;
|
|
63
|
-
}
|
|
64
|
-
async function generate(config) {
|
|
65
|
-
const { skipFormat, watch } = config;
|
|
66
|
-
await generateSchemas(config.documentModelsDir, { skipFormat, watch });
|
|
67
|
-
await generateAll(config.documentModelsDir, { skipFormat, watch });
|
|
68
|
-
}
|
|
69
|
-
async function generateFromFile(path, config) {
|
|
70
|
-
const documentModel = await loadDocumentModel(path);
|
|
71
|
-
const name = paramCase(documentModel.name);
|
|
72
|
-
fs.mkdirSync(join(config.documentModelsDir, name), { recursive: true });
|
|
73
|
-
fs.writeFileSync(
|
|
74
|
-
join(config.documentModelsDir, name, `${name}.json`),
|
|
75
|
-
JSON.stringify(documentModel, null, 4)
|
|
76
|
-
);
|
|
77
|
-
const schemaStr = [
|
|
78
|
-
typeDefs.join("\n"),
|
|
79
|
-
// inject ph scalars
|
|
80
|
-
generateGraphqlSchema(documentModel)
|
|
81
|
-
].join("\n");
|
|
82
|
-
if (schemaStr) {
|
|
83
|
-
fs.writeFileSync(
|
|
84
|
-
join(config.documentModelsDir, name, `schema.graphql`),
|
|
85
|
-
schemaStr
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
await generateSchema(name, config.documentModelsDir, config);
|
|
89
|
-
await generateDocumentModel(documentModel, config.documentModelsDir, config);
|
|
90
|
-
}
|
|
91
|
-
async function generateEditor(name, documentTypes, config) {
|
|
92
|
-
const pathOrigin = "../../";
|
|
93
|
-
const { documentModelsDir, skipFormat } = config;
|
|
94
|
-
const documentTypesMap = await getDocumentTypesMap(
|
|
95
|
-
documentModelsDir,
|
|
96
|
-
pathOrigin
|
|
97
|
-
);
|
|
98
|
-
const invalidType = documentTypes.find(
|
|
99
|
-
(type) => !Object.keys(documentTypesMap).includes(type)
|
|
100
|
-
);
|
|
101
|
-
if (invalidType) {
|
|
102
|
-
throw new Error(`Document model for ${invalidType} not found`);
|
|
103
|
-
}
|
|
104
|
-
return generateEditor$1(
|
|
105
|
-
name,
|
|
106
|
-
documentTypes,
|
|
107
|
-
documentTypesMap,
|
|
108
|
-
config.editorsDir,
|
|
109
|
-
config.documentModelsDir,
|
|
110
|
-
{ skipFormat }
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
async function generateSubgraph(name, file, config) {
|
|
114
|
-
return generateSubgraph$1(
|
|
115
|
-
name,
|
|
116
|
-
file !== null ? await loadDocumentModel(file) : null,
|
|
117
|
-
config.subgraphsDir,
|
|
118
|
-
config
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
async function generateProcessor(name, type, documentTypes, config) {
|
|
122
|
-
const { documentModelsDir, skipFormat } = config;
|
|
123
|
-
const documentTypesMap = await getDocumentTypesMap(documentModelsDir);
|
|
124
|
-
const invalidType = documentTypes.find(
|
|
125
|
-
(type2) => !Object.keys(documentTypesMap).includes(type2)
|
|
126
|
-
);
|
|
127
|
-
if (invalidType) {
|
|
128
|
-
throw new Error(`Document model for ${invalidType} not found`);
|
|
129
|
-
}
|
|
130
|
-
return generateProcessor$1(
|
|
131
|
-
name,
|
|
132
|
-
documentTypes,
|
|
133
|
-
documentTypesMap,
|
|
134
|
-
config.processorsDir,
|
|
135
|
-
config.documentModelsDir,
|
|
136
|
-
type,
|
|
137
|
-
{ skipFormat }
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
async function generateImportScript(name, config) {
|
|
141
|
-
return generateImportScript$1(name, config.importScriptsDir, config);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export { generate, generateEditor, generateFromFile, generateImportScript, generateProcessor, generateSubgraph };
|
|
145
|
-
//# sourceMappingURL=index.js.map
|
|
146
|
-
//# sourceMappingURL=index.js.map
|