@powerhousedao/codegen 3.3.0-dev.5 → 3.3.0-dev.7
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-processor-operational/index.esm.t +2 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/migrations.esm.t +3 -6
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.esm.t +1 -10
- package/dist/src/codegen/kysely.d.ts.map +1 -1
- package/dist/src/codegen/kysely.js +21 -7
- package/dist/src/codegen/kysely.js.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +6 -5
package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/index.esm.t
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/index.ts"
|
|
3
3
|
force: true
|
|
4
4
|
---
|
|
5
|
+
import { type IOperationalStore } from "document-drive/processors/types";
|
|
5
6
|
import { OperationalProcessor, type OperationalProcessorFilter } from "document-drive/processors/operational-processor";
|
|
6
7
|
import { type InternalTransmitterUpdate } from "document-drive/server/listener/transmitter/internal";
|
|
7
8
|
import { up } from "./migrations.js";
|
|
@@ -24,7 +25,7 @@ export class <%= pascalName %>Processor extends OperationalProcessor<DB> {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
async initAndUpgrade(): Promise<void> {
|
|
27
|
-
await up(this.operationalStore);
|
|
28
|
+
await up(this.operationalStore as IOperationalStore);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
async onStrands(
|
package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-operational/migrations.esm.t
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/migrations.ts"
|
|
3
3
|
force: true
|
|
4
4
|
---
|
|
5
|
-
import {
|
|
5
|
+
import { type IOperationalStore } from "document-drive/processors/types"
|
|
6
6
|
|
|
7
|
-
export async function up(db:
|
|
7
|
+
export async function up(db: IOperationalStore): Promise<void> {
|
|
8
8
|
// Create table
|
|
9
9
|
await db.schema
|
|
10
10
|
.createTable("todo")
|
|
@@ -15,12 +15,9 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|
|
15
15
|
])
|
|
16
16
|
.ifNotExists()
|
|
17
17
|
.execute();
|
|
18
|
-
|
|
19
|
-
const tables = await db.introspection.getTables();
|
|
20
|
-
console.log(tables);
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
export async function down(db:
|
|
20
|
+
export async function down(db: IOperationalStore): Promise<void> {
|
|
24
21
|
// drop table
|
|
25
22
|
await db.schema.dropTable("todo").execute();
|
|
26
23
|
}
|
|
@@ -41,16 +41,7 @@ export class <%= pascalName %>Subgraph extends Subgraph {
|
|
|
41
41
|
example: "test"
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
async onSetup() {
|
|
45
|
-
await this.createOperationalTables();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async createOperationalTables() {
|
|
49
|
-
await this.operationalStore.schema.createTableIfNotExists("example", (table) => {
|
|
50
|
-
table.string("id").primary();
|
|
51
|
-
table.string("name");
|
|
52
|
-
});
|
|
53
|
-
}
|
|
44
|
+
async onSetup() {}
|
|
54
45
|
|
|
55
46
|
async onDisconnect() {}
|
|
56
47
|
<% } %>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely.d.ts","sourceRoot":"","sources":["../../../src/codegen/kysely.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kysely.d.ts","sourceRoot":"","sources":["../../../src/codegen/kysely.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,QAAQ;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAgBD,wBAAsB,gBAAgB,CAAC,EACrC,aAAa,EACb,UAAU,GACX,EAAE,QAAQ,iBAoBV"}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
import { generateId } from "document-model";
|
|
2
1
|
import { Kysely } from "kysely";
|
|
3
2
|
import { Codegen, KyselyPGlite } from "kysely-pglite";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { transform } from "sucrase";
|
|
6
|
+
async function loadMigration(file) {
|
|
7
|
+
// read ts code as a string and compile it to a js string
|
|
8
|
+
const code = readFileSync(file, "utf-8");
|
|
9
|
+
const compiledCode = transform(code, {
|
|
10
|
+
transforms: ["typescript"],
|
|
11
|
+
}).code;
|
|
12
|
+
// create esm module from js code
|
|
13
|
+
const base64 = Buffer.from(compiledCode).toString("base64");
|
|
14
|
+
const dataUrl = `data:text/javascript;base64,${base64}`;
|
|
15
|
+
const mod = (await import(dataUrl));
|
|
16
|
+
return mod;
|
|
17
|
+
}
|
|
4
18
|
export async function generateDBSchema({ migrationFile, schemaFile, }) {
|
|
5
|
-
const
|
|
6
|
-
const { dialect } = new KyselyPGlite({ dataDir });
|
|
19
|
+
const { dialect } = new KyselyPGlite("memory://");
|
|
7
20
|
const db = new Kysely({ dialect });
|
|
8
21
|
try {
|
|
9
|
-
const migration =
|
|
22
|
+
const migration = await loadMigration(migrationFile);
|
|
10
23
|
await migration.up(db);
|
|
11
24
|
}
|
|
12
25
|
catch (error) {
|
|
@@ -14,12 +27,13 @@ export async function generateDBSchema({ migrationFile, schemaFile, }) {
|
|
|
14
27
|
throw error;
|
|
15
28
|
}
|
|
16
29
|
const codegen = new Codegen(dialect);
|
|
30
|
+
const outFile = schemaFile ?? resolve(migrationFile, "../schema.ts");
|
|
17
31
|
// TODO: Do not pass in outFile, so we can replace the kysely import
|
|
18
|
-
|
|
32
|
+
await codegen.generate({
|
|
19
33
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
20
34
|
db: db,
|
|
21
|
-
outFile
|
|
35
|
+
outFile,
|
|
22
36
|
});
|
|
23
|
-
console.log(`
|
|
37
|
+
console.log(`Schema types generated at ${outFile}`);
|
|
24
38
|
}
|
|
25
39
|
//# sourceMappingURL=kysely.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely.js","sourceRoot":"","sources":["../../../src/codegen/kysely.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"kysely.js","sourceRoot":"","sources":["../../../src/codegen/kysely.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAOpC,KAAK,UAAU,aAAa,CAAC,IAAY;IACvC,yDAAyD;IACzD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,EAAE;QACnC,UAAU,EAAE,CAAC,YAAY,CAAC;KAC3B,CAAC,CAAC,IAAI,CAAC;IAER,iCAAiC;IACjC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,+BAA+B,MAAM,EAAE,CAAC;IACxD,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAc,CAAC;IACjD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,EACrC,aAAa,EACb,UAAU,GACD;IACT,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,YAAY,CAAC,WAAW,CAAC,CAAC;IAClD,MAAM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