@powerhousedao/codegen 3.3.0-dev.10 → 3.3.0-dev.11

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.
@@ -40,8 +40,6 @@ export class <%= pascalName %>Processor implements IProcessor {
40
40
  }
41
41
 
42
42
  for (const operation of strand.operations) {
43
- console.log(">>> ", operation.type);
44
-
45
43
  // this.inputs.push( ... );
46
44
  }
47
45
  }
@@ -2,16 +2,40 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/factory.ts"
3
3
  force: true
4
4
  ---
5
- import { type ProcessorRecord } from "document-drive/processors/types";
6
- import { type IProcessorHostModule } from "document-drive/processors/types";
5
+ import {
6
+ type ProcessorRecord,
7
+ type IProcessorHostModule
8
+ } from "document-drive/processors/types";
9
+ import {
10
+ createNamespacedDb,
11
+ type OperationalProcessorFilter,
12
+ } from "document-drive/processors/operational-processor";
7
13
  import { <%= pascalName %>Processor } from "./index.js";
8
14
 
9
- export const <%= h.changeCase.camel(name) %>ProcessorFactory = (module: IProcessorHostModule) => (driveId: string): ProcessorRecord[] => {
10
- const processor = new <%= pascalName %>Processor(driveId, module.operationalStore);
15
+ export const <%= h.changeCase.camel(name) %>ProcessorFactory = (module: IProcessorHostModule) => async (driveId: string): Promise<ProcessorRecord[]> => {
16
+ // Create a namespace for the processor and the provided drive id
17
+ const namespace = <%= pascalName %>Processor.getNamespace(driveId);
18
+
19
+ // Create a filter for the processor
20
+ const filter: OperationalProcessorFilter = {
21
+ branch: ["main"],
22
+ documentId: ["*"],
23
+ documentType: [<% if(documentTypes.length) { %><%- documentTypes.map(type => `"${type}"`).join(", ") %><% } else { %>"*"<% } %>],
24
+ scope: ["global"],
25
+ };
26
+
27
+ // Create a namespaced store for the processor
28
+ const store = await createNamespacedDb<<%= pascalName %>Processor>(
29
+ namespace,
30
+ module.operationalStore,
31
+ );
32
+
33
+ // Create the processor
34
+ const processor = new <%= pascalName %>Processor(namespace, filter, store);
11
35
  return [
12
36
  {
13
37
  processor,
14
- filter: processor.filter,
38
+ filter,
15
39
  },
16
40
  ];
17
41
  }
@@ -3,32 +3,28 @@ to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/index.ts"
3
3
  force: true
4
4
  ---
5
5
  import { type IOperationalStore } from "document-drive/processors/types";
6
- import { OperationalProcessor, type OperationalProcessorFilter } from "document-drive/processors/operational-processor";
6
+ import { OperationalProcessor } from "document-drive/processors/operational-processor";
7
7
  import { type InternalTransmitterUpdate } from "document-drive/server/listener/transmitter/internal";
8
- import { up } from "./migrations.js";
9
- import { type DB } from "./schema.js";
10
8
  <% documentTypes.forEach(type => { _%>
11
9
  import type { <%= documentTypesMap[type].name %>Document } from "<%= documentTypesMap[type].importPath %>/index.js";
12
10
  %><% }); _%>
13
11
  <% if(documentTypes.length === 0) { %>import { type PHDocument } from "document-model";<% } %>
12
+ import { up } from "./migrations.js";
13
+ import { type DB } from "./schema.js";
14
+
14
15
  type DocumentType = <% if(documentTypes.length) { %><%= documentTypes.map(type => `${documentTypesMap[type].name}Document`).join(" | ") %> <% } else { %>PHDocument<% } %>;
15
16
 
16
17
  export class <%= pascalName %>Processor extends OperationalProcessor<DB> {
17
-
18
- get filter(): OperationalProcessorFilter {
19
- return {
20
- branch: ["main"],
21
- documentId: ["*"],
22
- documentType: [<% if(documentTypes.length) { %><%- documentTypes.map(type => `"${type}"`).join(", ") %><% } else { %>"*"<% } %>],
23
- scope: ["global"],
24
- }
18
+ static override getNamespace(driveId: string): string {
19
+ // Default namespace: `${this.name}_${driveId.replaceAll("-", "_")}`
20
+ return super.getNamespace(driveId);
25
21
  }
26
22
 
27
- async initAndUpgrade(): Promise<void> {
23
+ override async initAndUpgrade(): Promise<void> {
28
24
  await up(this.operationalStore as IOperationalStore);
29
25
  }
30
26
 
31
- async onStrands(
27
+ override async onStrands(
32
28
  strands: InternalTransmitterUpdate<DocumentType>[],
33
29
  ): Promise<void> {
34
30
  if (strands.length === 0) {
@@ -41,7 +37,6 @@ export class <%= pascalName %>Processor extends OperationalProcessor<DB> {
41
37
  }
42
38
 
43
39
  for (const operation of strand.operations) {
44
- console.log(">>> ", operation.type);
45
40
  await this.operationalStore
46
41
  .insertInto("todo")
47
42
  .values({
@@ -28,7 +28,7 @@ export async function generateDBSchema({ migrationFile, schemaFile, }) {
28
28
  console.log(`Schema types generated at ${outFile}`);
29
29
  }
30
30
  catch (error) {
31
- console.error("Error running kysely-pglite CLI:", error);
31
+ console.error("Error running migration:", error);
32
32
  throw error;
33
33
  }
34
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"kysely.js","sourceRoot":"","sources":["../../../src/codegen/kysely.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,SAAS,UAAU,CACjB,OAAe,EACf,IAAc,EACd,GAAY;IAEZ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE;YACjC,GAAG;YACH,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;gBACf,OAAO,EAAE,CAAC;YACZ,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,KAAK,CAAC,iCAAiC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC1B,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,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