Skip to content

Commit d45a9a9

Browse files
committed
MAJOR: Changed all function apis to use object input syntax instead of argument syntax
1 parent 87685b6 commit d45a9a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4930
-1510
lines changed

.changeset/empty-impalas-play.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thinairthings/uix": major
3+
---
4+
5+
Changed all the get apis to use object style inputs instead of argument lists. This is a breaking change

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
## [1.2.5](https://github.com/ThinAirThings/uix/compare/v1.2.4...v1.2.5) (2024-05-23)
22

3+
## 2.4.3
4+
5+
### Patch Changes
6+
7+
- fix uixconfig imports
8+
9+
## 2.4.2
10+
11+
### Patch Changes
12+
13+
- fix: neo4j integers
14+
15+
## 2.4.1
16+
17+
### Patch Changes
18+
19+
- add tests
20+
321
## 2.4.0
422

523
### Minor Changes

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thinairthings/uix",
33
"author": "Dan Lannan",
4-
"version": "2.4.0",
4+
"version": "2.4.3",
55
"type": "module",
66
"types": "./dist/lib/index.d.ts",
77
"bin": {
@@ -14,7 +14,7 @@
1414
"dev": "nodemon",
1515
"build": "tsup-node",
1616
"build:run": "tsup-node && node dist/cli/cli.js",
17-
"test": "dotenvx run -f .env.test -- pnpm build && dotenvx run -f .env.test -- vitest run basic --test-timeout=100000",
17+
"test:basic": "dotenvx run -f .env.test -- pnpm build && dotenvx run -f .env.test -- vitest run basic --test-timeout=100000",
1818
"test:match": "pnpm build && dotenvx run -f .env.test -- vitest run match --test-timeout=100000",
1919
"uix": "dotenvx run -f .env.test -- node ./dist/cli/cli.js --config=./tests/uix/uix.config.ts",
2020
"wipset": "changeset && changeset version && changeset publish"
@@ -48,7 +48,7 @@
4848
"vitest": "^1.6.0"
4949
},
5050
"dependencies": {
51-
"@tanstack/react-query": "^5.32.0",
51+
"@tanstack/react-query": "^5.49.2",
5252
"@thinairthings/utilities": "^0.2.2",
5353
"bundle-n-require": "^1.1.1",
5454
"dedent": "^1.5.3",

src/app/(components)/CommandEnvironment.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Loading } from './Loading';
1111
import { bundleNRequire } from 'bundle-n-require'
1212
import { findConfig } from '../../utilities/findConfig';
1313
import { GraphType } from '../../types/GraphType';
14+
import path from 'path';
1415
export const CommandEnvironment: FC<{
1516
relativePathToConfig?: string
1617
Command: FC<any>
@@ -31,18 +32,19 @@ export const CommandEnvironment: FC<{
3132
const { mod } = await bundleNRequire(pathToConfig, {
3233
interopDefault: true
3334
})
35+
const uixConfigDefinition = mod?.default ?? mod as GenericUixConfigDefinition
3436
const uixConfig = ({
35-
...mod?.default ?? mod,
37+
outdir: path.resolve(uixConfigDefinition.outdir ?? path.join('uix', 'generated')),
38+
graph: new GraphType(uixConfigDefinition.type, uixConfigDefinition.nodeTypeSet),
39+
envPath: path.resolve(uixConfigDefinition.envPath ?? '.env'),
3640
pathToConfig
3741
}) as GenericUixConfig
3842
await new Promise(resolve => setTimeout(resolve, 500))
3943
dotenv.config({ path: uixConfig.envPath ?? '.env' })
4044
applicationStore.setState({ uixConfig })
41-
console.log(uixConfig)
4245
return uixConfig
4346
},
4447
catchOp: (error: Error) => {
45-
console.log(error)
4648
return UixErr({
4749
subtype: UixErrSubtype.UIX_CONFIG_NOT_FOUND,
4850
message: `${error.message}`,

src/app/(stores)/applicationStore.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { createNeo4jClient } from "../../clients/neo4j";
66
import { Box, Newline, Text } from "ink";
77
import Gradient from 'ink-gradient';
88
import BigText from 'ink-big-text';
9+
import { Error } from "../(components)/Error";
10+
import { UixErr, UixErrSubtype } from "../../types/Result";
911

1012
export const applicationStore = createImmerState({
1113
outputMap: new Map<string, {
@@ -25,6 +27,20 @@ export const applicationStore = createImmerState({
2527
uixConfig: null as GenericUixConfig | null,
2628
complete: false as boolean,
2729
neo4jDriver: null as Driver | null,
30+
timeout: (() => {
31+
setTimeout(async () => {
32+
applicationStore.setState(state => {
33+
state.pendingSet.clear()
34+
state.outputMap.set('timeout', {
35+
Component: () => <Error message="Operation timed out" error={UixErr({
36+
subtype: UixErrSubtype.CODE_GENERATION_FAILED,
37+
message: 'System timeout. Check your database connection!',
38+
}).error!} />
39+
})
40+
})
41+
await applicationStore.getState().neo4jDriver?.close()
42+
}, 15 * 1000)
43+
})(),
2844
})
2945

3046
applicationStore.subscribe(
@@ -50,6 +66,7 @@ applicationStore.subscribe(
5066
if (pendingSet.size > 0) return
5167
await new Promise(resolve => setTimeout(resolve, 1000))
5268
await applicationStore.getState().neo4jDriver?.close()
69+
process.exit(0)
5370
}
5471
)
5572

src/app/commands/codegen.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { useNodeSetTemplate } from '../../templates/hooks/useNodeSetTemplate';
1919
import { useNodeIndexTemplate } from '../../templates/hooks/useNodeIndexTemplate';
2020
import { useNodeTypeTemplate } from '../../templates/hooks/useNodeTypeTemplate';
2121
import { option } from 'pastel';
22+
import { UixProviderTemplate } from '../../templates/UixProviderTemplate';
23+
import { clientsTemplate } from '../../templates/clientsTemplate';
2224

2325
export const options = z.object({
2426
config: z.string().optional().describe(
@@ -79,6 +81,14 @@ const Codegen: FC<{
7981
path.join(outDir, 'useNodeType.ts'),
8082
useNodeTypeTemplate()
8183
)
84+
await writeFile(
85+
path.join(outDir, 'UixProvider.tsx'),
86+
UixProviderTemplate()
87+
)
88+
await writeFile(
89+
path.join(outDir, 'clients.ts'),
90+
clientsTemplate()
91+
)
8292
return true
8393
},
8494
catchOp: (error: Error) => UixErr({

src/clients/neo4j.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const createNeo4jClient = (config: {
1212
return neo4j.driver(
1313
config.uri,
1414
neo4j.auth.basic(config.username, config.password),
15-
options
15+
{ ...options, disableLosslessIntegers: true }
1616
)
1717
}
1818

@@ -37,7 +37,6 @@ export const neo4jAction = <
3737
T,
3838
PrevErrType extends AnyErrType,
3939
>(
40-
// fnName: string,
4140
fn: Action<Input, T, PrevErrType>
4241
) => async (
4342
...args: Input
@@ -47,13 +46,11 @@ export const neo4jAction = <
4746
| ErrType<'Neo4jErr', Neo4jErrorSubtype.UNKNOWN, Neo4jError>
4847
>
4948
> => {
50-
// console.log("Running", fnName, "with args", args)
5149
try {
5250
return await fn(...args)
5351
} catch (e) {
5452
if (!(e instanceof Neo4jError)) throw e
5553
return Neo4jErr(
56-
// fnName,
5754
e
5855
)
5956
}

src/config/defineConfig.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ export const defineConfig = <
6666
envPath?: string;
6767
outdir?: string;
6868
}
69-
): UixConfigWithoutPath<Type, NodeTypeSet> => ({
70-
outdir: path.resolve(options.outdir ?? path.join('uix', 'generated')),
71-
graph: new GraphType(options.type, options.nodeTypeSet),
72-
envPath: path.resolve(options.envPath ?? '.env')
69+
): UixConfigDefinition<Type, NodeTypeSet> => ({
70+
...options
7371
})
7472

7573

src/fns/createNodeFactory.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Action } from "../types/Action"
99
import OpenAI from "openai"
1010
import { GenericNodeKey, NodeKey } from "../types/NodeKey"
1111
import { upsertVectorNode } from "../vectors/upsertVectorNode"
12-
import { convertIntegersToNumbers } from "../utilities/convertIntegersToNumbers"
1312

1413

1514
export type GenericCreateNodeAction = Action<
@@ -33,19 +32,24 @@ export const createNodeFactory = <
3332
ParentOfNodeSetType extends ParentOfNodeSetTypes<NodeTypeMap>,
3433
SetNodeType extends SetNodeTypes<NodeTypeMap, ParentOfNodeSetType>,
3534
InitialState extends TypeOf<NodeTypeMap[SetNodeType]['stateSchema']>
36-
>(
35+
>({
36+
parentNodeKeys,
37+
childNodeType,
38+
initialState,
39+
providedNodeId
40+
}: {
3741
parentNodeKeys: NodeKey<NodeTypeMap, ParentOfNodeSetType>[],
3842
childNodeType: SetNodeType,
3943
initialState: InitialState,
40-
nodeId?: string
41-
) => {
44+
providedNodeId?: string
45+
}) => {
4246
// Check Schema
4347
const newNodeStructure = (<GenericNodeType>nodeTypeMap[childNodeType]!)['stateSchema'].extend({
4448
nodeId: z.string(),
4549
nodeType: z.string()
4650
}).parse({
4751
...initialState,
48-
nodeId: nodeId ?? uuid(),
52+
nodeId: providedNodeId ?? uuid(),
4953
nodeType: childNodeType
5054
})
5155
console.log("Creating", parentNodeKeys, childNodeType, newNodeStructure)
@@ -79,5 +83,5 @@ export const createNodeFactory = <
7983
});
8084
// Triggers
8185
await upsertVectorNode(neo4jDriver, openaiClient, node, nodeTypeMap);
82-
return Ok(convertIntegersToNumbers(node))
86+
return Ok(node)
8387
})

src/fns/deleteNodeFactory.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ export const deleteNodeFactory = <
1818
>(
1919
neo4jDriver: Driver,
2020
nodeTypeMap: NodeTypeMap
21-
) => neo4jAction(async (
21+
) => neo4jAction(async ({
22+
nodeKey
23+
}: {
2224
nodeKey: NodeKey<NodeTypeMap, keyof NodeTypeMap>
23-
) => {
25+
}) => {
2426
console.log("Deleting", nodeKey)
2527
// First, retrieve parent node information
2628
const parentNodeKeys = await neo4jDriver.executeQuery<EagerResult<{

src/fns/getAllOfNodeTypeFactory.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Driver, EagerResult, Integer, Node } from "neo4j-driver"
22
import { neo4jAction } from "../clients/neo4j"
33
import { AnyNodeTypeMap, NodeShape } from "../types/NodeType"
44
import { Ok } from "../types/Result"
5-
import { convertIntegersToNumbers } from "../utilities/convertIntegersToNumbers"
65
import neo4j from 'neo4j-driver'
76

87

@@ -16,15 +15,18 @@ export const getAllOfNodeTypeFactory = <
1615
nodeTypeMap: NodeTypeMap,
1716
) => neo4jAction(async <
1817
NodeType extends keyof NodeTypeMap,
19-
>(
18+
>({
19+
nodeType,
20+
options
21+
}: {
2022
nodeType: NodeType,
2123
options?: {
2224
limit?: number
2325
page?: number
2426
orderBy?: 'updatedAt' | 'createdAt';
2527
orderDirection?: 'ASC' | 'DESC';
2628
}
27-
) => {
29+
}) => {
2830
console.log("Getting all nodes of type", nodeType)
2931
// Setup filter
3032
const limit = options?.limit ?? 10;
@@ -44,6 +46,6 @@ export const getAllOfNodeTypeFactory = <
4446
`, {
4547
skip: neo4j.int(skip),
4648
limit: neo4j.int(limit)
47-
}).then(res => res.records.map(record => convertIntegersToNumbers(record.get('node').properties)))
49+
}).then(res => res.records.map(record => record.get('node').properties))
4850
return Ok(nodes)
4951
})

src/fns/getChildNodeSetFactory.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { neo4jAction } from "../clients/neo4j";
33
import { AnyNodeTypeMap, NodeSetParentTypes, NodeShape, NodeSetChildNodeTypes } from "../types/NodeType";
44
import { Ok } from "../types/Result";
55
import { NodeKey } from "../types/NodeKey";
6-
import { convertIntegersToNumbers } from "../utilities/convertIntegersToNumbers";
76

87

98

@@ -16,10 +15,13 @@ export const getChildNodeSetFactory = <
1615
) => neo4jAction(async <
1716
ParentNodeType extends NodeSetParentTypes<NodeTypeMap>,
1817
ChildNodeType extends NodeSetChildNodeTypes<NodeTypeMap, ParentNodeType>,
19-
>(
18+
>({
19+
parentNodeKey,
20+
childNodeType
21+
}: {
2022
parentNodeKey: NodeKey<NodeTypeMap, ParentNodeType>,
2123
childNodeType: ChildNodeType
22-
) => {
24+
}) => {
2325
console.log("Getting child nodes of type", childNodeType, "for node of type", parentNodeKey.nodeType, "with id", parentNodeKey.nodeId)
2426
const result = await neo4jDriver.executeQuery<EagerResult<{
2527
childNode: Node<Integer, NodeShape<NodeTypeMap[ChildNodeType]>>
@@ -29,5 +31,5 @@ export const getChildNodeSetFactory = <
2931
`, {
3032
parentNodeId: parentNodeKey.nodeId,
3133
});
32-
return Ok(result.records.map(record => convertIntegersToNumbers(record.get('childNode').properties)))
34+
return Ok(result.records.map(record => record.get('childNode').properties))
3335
})

src/fns/getNodeByIndexFactory.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Driver, EagerResult, Integer, Node } from "neo4j-driver"
22
import { neo4jAction } from "../clients/neo4j"
33
import { AnyNodeTypeMap, NodeShape } from "../types/NodeType"
44
import { Ok, UixErr, UixErrSubtype } from "../types/Result"
5-
import { convertIntegersToNumbers } from "../utilities/convertIntegersToNumbers"
65

76

87

@@ -15,11 +14,15 @@ export const getNodeByIndexFactory = <
1514
) => neo4jAction(async <
1615
NodeType extends keyof NodeTypeMap,
1716
UniqueIndex extends NodeTypeMap[NodeType]['uniqueIndexes'][number],
18-
>(
17+
>({
18+
nodeType,
19+
indexKey,
20+
indexValue
21+
}: {
1922
nodeType: NodeType,
2023
indexKey: UniqueIndex,
2124
indexValue: string
22-
) => {
25+
}) => {
2326
console.log(`Getting node of type ${nodeType as string} with index ${indexKey} = ${indexValue}`);
2427
const node = await neo4jDriver.executeQuery<EagerResult<{
2528
node: Node<Integer, NodeShape<NodeTypeMap[NodeType]>>
@@ -38,5 +41,5 @@ export const getNodeByIndexFactory = <
3841
indexValue
3942
}
4043
})
41-
return Ok(convertIntegersToNumbers(node))
44+
return Ok(node)
4245
})

src/fns/getNodeByKeyFactory.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { neo4jAction } from "../clients/neo4j";
33
import { AnyNodeTypeMap, NodeShape } from "../types/NodeType";
44
import { UixErr, Ok, UixErrSubtype } from "../types/Result";
55
import { NodeKey } from "../types/NodeKey";
6-
import { convertIntegersToNumbers } from "../utilities/convertIntegersToNumbers";
76

87

98

@@ -21,21 +20,24 @@ export const getNodeByKeyFactory = <
2120
nodeTypeMap: NodeTypeMap,
2221
) => neo4jAction(async <
2322
NodeType extends keyof NodeTypeMap,
24-
>(
23+
>({
24+
nodeKey
25+
}: {
2526
nodeKey: NodeKey<NodeTypeMap, NodeType>
26-
) => {
27+
}) => {
2728
const node = await neo4jDriver.executeQuery<EagerResult<{
2829
node: Node<Integer, NodeShape<NodeTypeMap[NodeType]>>
2930
}>>(/*cypher*/`
3031
match (node:${nodeKey.nodeType as string} {nodeId: $nodeId})
3132
return node
3233
`, { nodeId: nodeKey.nodeId }).then(res => res.records[0]?.get('node').properties)
34+
console.log(node)
3335
if (!node) return UixErr({
3436
subtype: UixErrSubtype.GET_NODE_BY_KEY_FAILED,
3537
message: `Failed to find node of type ${nodeKey.nodeType as string} with id ${nodeKey.nodeId}`,
3638
data: {
3739
nodeKey
3840
}
3941
})
40-
return Ok(convertIntegersToNumbers(node))
42+
return Ok(node)
4143
})

0 commit comments

Comments
 (0)