Skip to content

Commit

Permalink
refactor element IDs (#7)
Browse files Browse the repository at this point in the history
* inc version

* use recordId for both edges and vertices

* rename edgeconfig fn

* add todo
  • Loading branch information
noahehall authored Oct 26, 2023
1 parent 1b55f0c commit 4cb1c3d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
- TODO (noah): this will eventually become a proper readme file ;)~

```sh
### add peer deps
bun add type-fest csv gremlin
### add tinkerbuntune
### @see https://bun.sh/docs/cli/install#non-npm-dependencies
# add latest
bun add github:nirv-ai/tinkerbuntune
# or specific branch
bun add github:nirv-ai/tinkerbuntune#bleeding-edge-branch
bun add github:nirv-ai/tinkerbuntune=
# or specific version
bun add github:nirv-ai/tinkerbuntune#0.0.5

# or specific commit
bun add github:nirv-ai/tinkerbunetune#57a7b1a
```

```ts
Expand Down
Binary file modified bun.lockb
Binary file not shown.
8 changes: 5 additions & 3 deletions bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "etl",
"private": true,
"type": "module",
"version": "0.0.6",
"version": "0.1.0",
"module": "index.ts",
"scripts": {
"examples": "bun --watch src/examples/airRoutes.ts",
Expand All @@ -11,12 +11,14 @@
"devDependencies": {
"@types/gremlin": "^3.6.5",
"bun-types": "latest",
"csv": "^6.3.5",
"gremlin": "^3.6.2",
"csv": "^6.3.5"
"type-fest": "^4.6.0"
},
"peerDependencies": {
"typescript": "^5.0.0",
"gremlin": "^3.6.2",
"csv": "^6.3.5"
"csv": "^6.3.5",
"type-fest": "^4.6.0"
}
}
12 changes: 5 additions & 7 deletions bun/src/loader/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
CsvParsed,
NeptuneValue,
NumStr,
PropsAndLabels,
TinkerDataEdge,
TinkerDataVertex,
} from "types";
Expand All @@ -25,7 +26,7 @@ export const transformPropsAndLabels = (
spec: ConfigSpec,
headers: string[],
record: NeptuneValue[]
) => {
): PropsAndLabels => {
const p = { ...(spec.inject?.p || {}) },
l = spec.inject?.l?.slice() ?? [];

Expand Down Expand Up @@ -94,13 +95,10 @@ export const csvToTinkerDataVertex = (
): TinkerDataVertex[] => {
return data.map((recordRaw, i) => {
const record = spec.transformRecord?.(recordRaw) ?? recordRaw;
const pl = transformPropsAndLabels(spec, headers, record);
const recordId = spec.recordId(pl);

const recordId =
typeof spec.colMap.id === "function"
? spec.colMap.id(headers, record, i)
: validateNumStr(record[<number>spec.colMap.id]);

return { recordId, ...transformPropsAndLabels(spec, headers, record) };
return { recordId, ...pl };
});
};

Expand Down
15 changes: 7 additions & 8 deletions bun/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export interface PropsAndLabels {
p?: Record<string, NeptuneValue>;
l?: NumStr[];
}
export type EdgeConfigProp = (pl: PropsAndLabels) => NumStr;
export type PropLabelNumStr = (pl: PropsAndLabels) => NumStr;
export interface EdgeConfig {
f: EdgeConfigProp;
t: EdgeConfigProp;
l: EdgeConfigProp;
recordId: EdgeConfigProp;
f: PropLabelNumStr;
t: PropLabelNumStr;
l: PropLabelNumStr;
recordId: PropLabelNumStr;
p?: (pl: PropsAndLabels) => PropsAndLabels["p"];
}

Expand All @@ -35,7 +35,6 @@ export interface EdgeData {
* @prop default p: property | l: label
* default col assignment for unassigned columns
* will ignore unknown columns if not set
* @prop id column index or fn to use as element ID
* @prop ignoreCols always ignore these columns
* @prop ignoreEmptyCol whether to ignore empty columns
* @prop l map specific col indexes to labels
Expand All @@ -44,7 +43,6 @@ export interface EdgeData {
*/
export type ConfigSpecColMap = {
default?: "p" | "l";
id: NumStr | ((heads: string[], cols: NeptuneValue[], i: number) => NumStr);
ignoreCols?: number[];
ignoreEmptyCol?: boolean;
l?: number[];
Expand Down Expand Up @@ -92,7 +90,8 @@ interface ConfigSpecBase {
*/
export type ConfigSpecVertex = ConfigSpecBase & {
colMap: ConfigSpecColMap;
type: "v";
recordId: PropLabelNumStr;
type: "v"; // TODO (noah): this type flag shouldnt be necessary anymore
};

/**
Expand Down

0 comments on commit 4cb1c3d

Please sign in to comment.