@powerhousedao/codegen 0.49.2-dev.5 → 0.49.2-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.
@@ -17,15 +17,15 @@ export const getResolvers = (subgraph: Subgraph) => {
17
17
 
18
18
  return ({
19
19
  Query: {
20
- <%- h.changeCase.pascal(documentType) %>: async (_: any, args: any) => {
20
+ <%- h.changeCase.pascal(documentType) %>: async (_: any, args: any, ctx: any) => {
21
21
  return {
22
- getDocument: async (_: any, args: any) => {
22
+ getDocument: async (args: any) => {
23
23
  const driveId: string = args.driveId || DEFAULT_DRIVE_ID;
24
24
  const docId: string = args.docId || "";
25
25
  const doc = await reactor.getDocument(driveId, docId);
26
26
  return doc;
27
27
  },
28
- getDocuments: async (_: any, args: any) => {
28
+ getDocuments: async (args: any) => {
29
29
  const driveId: string = args.driveId || DEFAULT_DRIVE_ID;
30
30
  const docsIds = await reactor.getDocuments(driveId);
31
31
  const docs = await Promise.all(
@@ -2,15 +2,16 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/editor.tsx"
3
3
  unless_exists: true
4
4
  ---
5
- import { type EditorProps, hashKey } from "document-model";
5
+ import { type DriveEditorProps } from "@powerhousedao/reactor-browser";
6
+ import { DriveContextProvider } from "@powerhousedao/reactor-browser/hooks/useDriveContext";
6
7
  import { type DocumentDriveDocument, addFolder, deleteNode, updateNode, generateNodesCopy, copyNode } from "document-drive";
7
8
  import { WagmiContext } from "@powerhousedao/design-system";
8
9
  import { DriveExplorer } from "./components/DriveExplorer.js";
9
10
  import { useCallback } from "react";
10
11
 
11
- export type IProps = EditorProps<DocumentDriveDocument>;
12
+ export type IProps = DriveEditorProps<DocumentDriveDocument>;
12
13
 
13
- export default function Editor(props: IProps) {
14
+ export function BaseEditor(props: IProps) {
14
15
  const { dispatch, context } = props;
15
16
 
16
17
  const onAddFolder = useCallback((name: string, parentFolder?: string) => {
@@ -52,17 +53,25 @@ export default function Editor(props: IProps) {
52
53
  className="new-drive-explorer"
53
54
  style={{ height: "100%" }}
54
55
  >
56
+ <DriveExplorer
57
+ driveId={props.document.state.global.id}
58
+ nodes={props.document.state.global.nodes}
59
+ onAddFolder={onAddFolder}
60
+ onDeleteNode={onDeleteNode}
61
+ renameNode={renameNode}
62
+ onCopyNode={onCopyNode}
63
+ context={context}
64
+ />
65
+ </div>
66
+ );
67
+ }
68
+
69
+ export default function Editor(props: IProps) {
70
+ return (
71
+ <DriveContextProvider value={props.context}>
55
72
  <WagmiContext>
56
- <DriveExplorer
57
- driveId={props.document.state.global.id}
58
- nodes={props.document.state.global.nodes}
59
- onAddFolder={onAddFolder}
60
- onDeleteNode={onDeleteNode}
61
- renameNode={renameNode}
62
- onCopyNode={onCopyNode}
63
- context={context}
64
- />
73
+ <BaseEditor {...props} />
65
74
  </WagmiContext>
66
- </div>
75
+ </DriveContextProvider>
67
76
  );
68
- }
77
+ }
@@ -2,11 +2,11 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/index.ts"
3
3
  force: true
4
4
  ---
5
- import { type EditorModule } from "document-model";
6
- import Editor from "./editor.js";
5
+ import { type DriveEditorModule } from "@powerhousedao/reactor-browser";
7
6
  import { type DocumentDriveDocument } from "document-drive";
7
+ import Editor from "./editor.js";
8
8
 
9
- export const module: EditorModule<DocumentDriveDocument> = {
9
+ export const module: DriveEditorModule<DocumentDriveDocument> = {
10
10
  Component: Editor,
11
11
  documentTypes: ["powerhouse/document-drive"],
12
12
  config: {
@@ -2,35 +2,21 @@
2
2
  to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/index.ts"
3
3
  force: true
4
4
  ---
5
- import { generateId } from "document-model";
6
- import type {
7
- AnalyticsProcessor,
8
- ProcessorOptions,
9
- ProcessorUpdate,
10
- AnalyticsPath
11
- } from "@powerhousedao/reactor-api";
5
+ import type { PHDocument } from "document-model";
6
+ import { AnalyticsPath, IAnalyticsStore } from "@powerhousedao/reactor-api";
7
+ import { InternalTransmitterUpdate, IProcessor } from "document-drive";
8
+
12
9
  <% documentTypes.forEach(type => { _%>
13
10
  import type { <%= documentTypesMap[type].name %>Document } from "<%= documentTypesMap[type].importPath %>/index.js";
14
11
  %><% }); _%>
15
- <% if(documentTypes.length === 0) { %>import type { PHDocument } from "document-model";<% } %>
16
- type DocumentType = <% if(documentTypes.length) { %><%= documentTypes.map(type => `${documentTypesMap[type].name}Document`).join(" | ") %> <% } else { %>PHDocument<% } %>;
17
12
 
18
- export class <%= pascalName %>Processor extends AnalyticsProcessor<% if(documentTypes.length) { %><DocumentType><% } %> {
13
+ export class <%= pascalName %>Processor implements IProcessor {
19
14
 
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
- };
15
+ constructor(private readonly analyticsStore: IAnalyticsStore) {
16
+ //
17
+ }
32
18
 
33
- async onStrands(strands: ProcessorUpdate<DocumentType>[]): Promise<void> {
19
+ async onStrands<TDocument extends PHDocument>(strands: InternalTransmitterUpdate<TDocument>[]): Promise<void> {
34
20
  if (strands.length === 0) {
35
21
  return;
36
22
  }
@@ -7,3 +7,19 @@ unless_exists: true
7
7
  * Delete the file and run the code generator again to have it reset
8
8
  */
9
9
 
10
+ import { ProcessorRecord } from "document-drive/processors/types";
11
+ import { <%= pascalName %>Processor } from "./<%= h.changeCase.param(name) %>/index.js";
12
+
13
+ export const processorFactory = (module:any) => (driveId: string):ProcessorRecord[] => {
14
+ return [
15
+ {
16
+ processor: new <%= pascalName %>Processor(module.analyticsStore),
17
+ filter: {
18
+ branch: ["main"],
19
+ documentId: ["*"],
20
+ scope: ["*"],
21
+ documentType: ["*"],
22
+ },
23
+ },
24
+ ];
25
+ }
@@ -1,6 +1,19 @@
1
1
  import { type CodegenConfig } from "@graphql-codegen/cli";
2
2
  import { type TypeScriptPluginConfig } from "@graphql-codegen/typescript";
3
+ export declare const scalars: {
4
+ Unknown: string;
5
+ DateTime: string;
6
+ Attachment: string;
7
+ Address: string;
8
+ };
9
+ export declare const scalarsValidation: {
10
+ Unknown: string;
11
+ DateTime: string;
12
+ Attachment: string;
13
+ Address: string;
14
+ };
3
15
  export declare const tsConfig: TypeScriptPluginConfig;
16
+ export declare const zodConfig: Record<string, unknown>;
4
17
  export declare function schemaConfig(name: string, dir: string): CodegenConfig["generates"];
5
18
  export declare const generateSchema: (model: string, dir: string, { watch, skipFormat }?: {
6
19
  watch?: boolean | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/codegen/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAY,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAU1E,eAAO,MAAM,QAAQ,EAAE,sBAiBtB,CAAC;AAEF,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GACV,aAAa,CAAC,WAAW,CAAC,CAsC5B;AAED,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,EACb,KAAK,MAAM,EACX;;;CAA0C,iBAa3C,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,KAAK,MAAM,EACX;;;CAA0C,iBAoB3C,CAAC"}
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/codegen/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAY,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAU1E,eAAO,MAAM,OAAO;;;;;CAMnB,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;CAO7B,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,sBAWtB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAYpC,CAAC;AAEX,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GACV,aAAa,CAAC,WAAW,CAAC,CAmB5B;AAED,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,EACb,KAAK,MAAM,EACX;;;CAA0C,iBAa3C,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,KAAK,MAAM,EACX;;;CAA0C,iBAoB3C,CAAC"}
@@ -5,15 +5,23 @@ import { formatWithPrettierBeforeWrite } from "./utils.js";
5
5
  const getDirectories = (source) => readdirSync(source, { withFileTypes: true })
6
6
  .filter((dirent) => dirent.isDirectory())
7
7
  .map((dirent) => dirent.name);
8
+ export const scalars = {
9
+ Unknown: "unknown",
10
+ DateTime: "string",
11
+ Attachment: "string",
12
+ Address: "`${string}:0x${string}`",
13
+ ...generatorTypeDefs,
14
+ };
15
+ export const scalarsValidation = {
16
+ Unknown: "z.unknown()",
17
+ DateTime: "z.string().datetime()",
18
+ Attachment: "z.string()",
19
+ Address: "z.custom<`${string}:0x${string}`>((val) => /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/.test(val as string))",
20
+ ...validationSchema,
21
+ };
8
22
  export const tsConfig = {
9
23
  strictScalars: true,
10
- scalars: {
11
- Unknown: "unknown",
12
- DateTime: "string",
13
- Attachment: "string",
14
- Address: "`${string}:0x${string}`",
15
- ...generatorTypeDefs,
16
- },
24
+ scalars,
17
25
  enumsAsTypes: true,
18
26
  allowEnumStringTypes: true,
19
27
  avoidOptionals: {
@@ -23,6 +31,19 @@ export const tsConfig = {
23
31
  // maybeValue: "T | null | undefined",
24
32
  inputMaybeValue: "T | null | undefined",
25
33
  };
34
+ export const zodConfig = {
35
+ ...tsConfig,
36
+ importFrom: `./types.js`,
37
+ schema: "zod",
38
+ useTypeImports: true,
39
+ scalarSchemas: scalarsValidation,
40
+ directives: {
41
+ equals: {
42
+ value: ["regex", "/^$1$/"],
43
+ },
44
+ },
45
+ withObjectType: true,
46
+ };
26
47
  export function schemaConfig(name, dir) {
27
48
  return {
28
49
  [`${dir}/${name}/gen/schema/types.ts`]: {
@@ -39,25 +60,7 @@ export function schemaConfig(name, dir) {
39
60
  [`${dir}/${name}/gen/schema/zod.ts`]: {
40
61
  schema: `${dir}/${name}/schema.graphql`,
41
62
  plugins: ["@acaldas/graphql-codegen-typescript-validation-schema"],
42
- config: {
43
- ...tsConfig,
44
- importFrom: `./types.js`,
45
- schema: "zod",
46
- useTypeImports: true,
47
- scalarSchemas: {
48
- Unknown: "z.unknown()",
49
- DateTime: "z.string().datetime()",
50
- Attachment: "z.string()",
51
- Address: "z.custom<`${string}:0x${string}`>((val) => /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/.test(val as string))",
52
- ...validationSchema,
53
- },
54
- directives: {
55
- equals: {
56
- value: ["regex", "/^$1$/"],
57
- },
58
- },
59
- withObjectType: true,
60
- },
63
+ config: zodConfig,
61
64
  },
62
65
  };
63
66
  }