From 80975d5f71956393158bf94c79867aedcb0e46fe Mon Sep 17 00:00:00 2001 From: irishcarbomb777 Date: Fri, 3 May 2024 14:32:59 -0400 Subject: [PATCH] mod --- package.json | 4 +- src/base/defineNode.ts | 10 +--- .../ReactCache/defineReactCacheLayer.ts | 55 ++++++++++--------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index 6e24a1a..d7f89c0 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "format": "npx prettier --write .", "test": "npm run build && jest", "verdaccio": "pm2 start $(which verdaccio) --name verdaccio", - "localpublish": "npm run build && git add . && git commit -m \"mod\" && npm unpublish --registry http://localhost:4873 && npm publish --registry http://localhost:4873" + "localpublish": "npm run build && git add . && git commit --amend --no-edit && npm unpublish --registry http://localhost:4873 && npm publish --registry http://localhost:4873" }, "exports": { ".": { @@ -62,4 +62,4 @@ "tsx": "^4.7.2", "typescript": "^5.4.5" } -} +} \ No newline at end of file diff --git a/src/base/defineNode.ts b/src/base/defineNode.ts index 2938763..5300a92 100644 --- a/src/base/defineNode.ts +++ b/src/base/defineNode.ts @@ -1,10 +1,7 @@ -import { TypeOf, ZodDefault, ZodObject, ZodTypeAny, z } from "zod"; +import { TypeOf, ZodDefault, ZodObject, ZodOptional, ZodTypeAny, z } from "zod"; -// // Note this will extract the actual zod type -type InferZodSchema = { - [P in keyof T]: T[P] extends ZodDefault ? U : never; -}; +type UnwrapZodOptional = T extends ZodOptional ? U : T; // type Concrete> = { // [Property in keyof Type]: Type[Property] extends NonNullable ? U : never; @@ -13,7 +10,6 @@ type Concrete> = { [P in keyof T]: NonNullable; }; -type DefaultType = T extends ZodTypeAny ? InferZodSchema : never; export class NodeDefinition, StateDefaults extends ZodObject = ZodObject<{}>> { nodeType: T; stateDefinition: StateDefinition; @@ -28,7 +24,7 @@ export class NodeDefinition]?: TypeOf[K] }>( defaults: Defaults ): NodeDefinition }>> { const defaultsDefinition = Object.entries(this.stateDefinition.shape).reduce((acc, [key, value]) => ({ ...acc, diff --git a/src/layers/ReactCache/defineReactCacheLayer.ts b/src/layers/ReactCache/defineReactCacheLayer.ts index f75101d..2b5257c 100644 --- a/src/layers/ReactCache/defineReactCacheLayer.ts +++ b/src/layers/ReactCache/defineReactCacheLayer.ts @@ -36,42 +36,43 @@ export const defineReactCacheLayer = < nodeType: T, node?: Node ) => ReturnType> - ? TypeOf<(N[number] & { nodeType: T })['stateDefinition']> + ? (Omit, keyof TypeOf<(N[number] & { nodeType: T })['stateDefaults']>> + & TypeOf<(N[number] & { nodeType: T })['stateDefaults']>) : TypeOf<(N[number] & { nodeType: T })['stateDefaults']> >> -} => { +} => { type ReactCache = { nodeMap: Map> } & Pick< GraphLayer, 'createNode' | 'updateNode' > - const nodeStore = createStore()( - immer( - (set) => ({ - nodeMap: new Map(), - createNode: async (nodeType, initialState) => { - const createNodeResult = await graph.createNode(nodeType, initialState) - if (!createNodeResult.ok) return createNodeResult - const node = createNodeResult.val - set((state) => { - state.nodeMap.set(node.nodeId, node) - }) - return Ok(node) - }, - updateNode: async (nodeKey, state) => { - set((state) => { - state.nodeMap.set(nodeKey.nodeId, { - ...state.nodeMap.get(nodeKey.nodeId)!, - ...state - }) - }) - return await graph.updateNode(nodeKey, state) - }, - }) - ) - ) + // const nodeStore = createStore()( + // immer( + // (set) => ({ + // nodeMap: new Map(), + // createNode: async (nodeType, initialState) => { + // const createNodeResult = await graph.createNode(nodeType, initialState) + // if (!createNodeResult.ok) return createNodeResult + // const node = createNodeResult.val + // set((state) => { + // state.nodeMap.set(node.nodeId, node) + // }) + // return Ok(node) + // }, + // updateNode: async (nodeKey, state) => { + // set((state) => { + // state.nodeMap.set(nodeKey.nodeId, { + // ...state.nodeMap.get(nodeKey.nodeId)!, + // ...state + // }) + // }) + // return await graph.updateNode(nodeKey, state) + // }, + // }) + // ) + // ) return { ...graph, useNodeState: (nodeType, node) => {