Skip to content

Commit cfc86d0

Browse files
authored
Merge pull request #221 from thebestnom/feature/all-async
fix default relationships, removed unececry as unkown and full async
2 parents 63ae56c + f5820d7 commit cfc86d0

File tree

8 files changed

+810
-1189
lines changed

8 files changed

+810
-1189
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Setup node
1212
uses: actions/setup-node@v2
1313
with:
14-
node-version: "14"
14+
node-version: "17"
1515
- run: yarn install
1616
- run: yarn eslint
1717
- run: yarn test

dist/neovis-without-dependencies.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/neovis-without-dependencies.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/neovis.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/neovis.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
"uuid": "^8.3.2",
6868
"vis-data": "^7.1.2",
6969
"vis-util": "^5.0.2",
70-
"webpack": "^5.58.1",
71-
"webpack-cli": "^4.9.0"
70+
"webpack": "^5.61.0",
71+
"webpack-cli": "^4.9.1"
7272
},
7373
"dependencies": {
7474
"@babel/runtime-corejs3": "^7.15.4",
7575
"deepmerge": "^4.2.2",
76-
"neo4j-driver": "^4.3.3",
77-
"neo4j-driver-core": "^4.3.3",
76+
"neo4j-driver": "^4.3.4",
77+
"neo4j-driver-core": "^4.3.4",
7878
"vis-network": "^9.1.0"
7979
},
8080
"jest": {

src/neovis.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class NeoVis {
156156
(config as NeovisConfig) = {
157157
...config as NeovisConfig,
158158
relationships: {
159-
...config.labels as Record<string, RelationshipConfig>,
159+
...config.relationships as Record<string, RelationshipConfig>,
160160
[key]: {
161161
...deepmerge(defaultRelationshipConfig as RelationshipConfig, config.relationships?.[key] as RelationshipConfig),
162162
[NEOVIS_ADVANCED_CONFIG]: deepmerge((defaultRelationshipConfig as RelationshipConfig)[NEOVIS_ADVANCED_CONFIG] ?? {}, (config.relationships?.[key] as RelationshipConfig)[NEOVIS_ADVANCED_CONFIG] ?? {}),
@@ -244,33 +244,35 @@ export class NeoVis {
244244
}
245245
}
246246

247-
async #buildCypherObject<VIS_TYPE>(cypherConfig: RecursiveMapTo<VIS_TYPE, Cypher>, object: VIS_TYPE, id: number): Promise<void> {
247+
*#buildCypherObject<VIS_TYPE>(cypherConfig: RecursiveMapTo<VIS_TYPE, Cypher>, object: VIS_TYPE, id: number): Generator<Promise<void>> {
248248
if (cypherConfig && typeof cypherConfig === 'object') {
249249
for (const prop of Object.keys(cypherConfig) as (keyof VIS_TYPE)[]) {
250250
const value = cypherConfig[prop];
251251
if (value && typeof value === 'object') {
252252
if (!object[prop]) {
253253
object[prop as string] = {};
254254
}
255-
await this.#buildCypherObject(value as RecursiveMapTo<VIS_TYPE[keyof VIS_TYPE], Cypher>, object[prop], id);
255+
yield *this.#buildCypherObject(value as RecursiveMapTo<VIS_TYPE[keyof VIS_TYPE], Cypher>, object[prop], id);
256256
} else {
257-
object[prop] = await this.#runCypher(value as string, id) as VIS_TYPE[keyof VIS_TYPE];
257+
const promise = this.#runCypher(value as string, id) as Promise<VIS_TYPE[keyof VIS_TYPE]>;
258+
yield Promise.resolve(promise).then(value => { object[prop] = value; } ) as Promise<void>;
258259
}
259260
}
260261
}
261262
}
262263

263-
async #buildFunctionObject<VIS_TYPE, NEO_TYPE>(functionConfig: RecursiveMapToFunction<VIS_TYPE, NEO_TYPE>, object: VIS_TYPE, neo4jObj: NEO_TYPE): Promise<void> {
264+
*#buildFunctionObject<VIS_TYPE, NEO_TYPE>(functionConfig: RecursiveMapToFunction<VIS_TYPE, NEO_TYPE>, object: VIS_TYPE, neo4jObj: NEO_TYPE): Generator<Promise<void>> {
264265
if (functionConfig && typeof functionConfig === 'object') {
265266
for (const prop of Object.keys(functionConfig) as (keyof VIS_TYPE)[]) {
266267
const func = functionConfig[prop];
267268
if (func && typeof func === 'object') {
268269
if (!object[prop]) {
269270
object[prop as string] = {};
270271
}
271-
await this.#buildFunctionObject(func as RecursiveMapToFunction<VIS_TYPE[keyof VIS_TYPE], NEO_TYPE>, object[prop], neo4jObj);
272+
yield *this.#buildFunctionObject(func as RecursiveMapToFunction<VIS_TYPE[keyof VIS_TYPE], NEO_TYPE>, object[prop], neo4jObj);
272273
} else {
273-
object[prop] = await this.#runFunction(func as (neo: NEO_TYPE) => VIS_TYPE[keyof VIS_TYPE], neo4jObj);
274+
const promise = this.#runFunction(func as (neo: NEO_TYPE) => VIS_TYPE[keyof VIS_TYPE], neo4jObj);
275+
yield Promise.resolve(promise).then(value => { object[prop] = value; } ) as Promise<void>;
274276
}
275277
}
276278
}
@@ -309,8 +311,8 @@ export class NeoVis {
309311
}
310312
this.#buildPropertyNameObject(propertyConfig, baseObject, neo4jObject);
311313
this.#buildStaticObject(staticConfig, baseObject);
312-
await this.#buildCypherObject(cypherConfig, baseObject, id);
313-
await this.#buildFunctionObject(functionConfig, baseObject, neo4jObject);
314+
await Promise.all(this.#buildCypherObject(cypherConfig, baseObject, id));
315+
await Promise.all(this.#buildFunctionObject(functionConfig, baseObject, neo4jObject));
314316
}
315317

316318
/**
@@ -378,19 +380,19 @@ export class NeoVis {
378380
const dataPromises = record.map(async (v: object) => {
379381
this.#consoleLog('Constructor:');
380382
this.#consoleLog(v?.constructor.name);
381-
if ((isNode as unknown as (obj: object) => obj is Neo4jCore.Node)(v)) {
383+
if (isNode(v)) {
382384
const node = await this.#buildNodeVisObject(v);
383385
try {
384386
this.#data.nodes.update(node);
385387
} catch (e) {
386388
this.#consoleLog(e, 'error');
387389
}
388390

389-
} else if ((isRelationship as unknown as (obj: object) => obj is Neo4jCore.Relationship)(v)) {
391+
} else if (isRelationship(v)) {
390392
const edge = await this.#buildEdgeVisObject(v);
391393
this.#data.edges.update(edge);
392394

393-
} else if ((isPath as unknown as (obj: object) => obj is Neo4jCore.Path)(v)) {
395+
} else if (isPath(v)) {
394396
this.#consoleLog('PATH');
395397
this.#consoleLog(v);
396398
const startNode = await this.#buildNodeVisObject(v.start);
@@ -409,11 +411,11 @@ export class NeoVis {
409411
for (const obj of v) {
410412
this.#consoleLog('Array element constructor:');
411413
this.#consoleLog(obj?.constructor.name);
412-
if ((isNode as unknown as (obj: object) => obj is Neo4jCore.Node)(obj)) {
414+
if (isNode(obj)) {
413415
const node = await this.#buildNodeVisObject(obj);
414416
this.#data.nodes.update(node);
415417

416-
} else if ((isRelationship as unknown as (obj: object) => obj is Neo4jCore.Relationship)(obj)) {
418+
} else if (isRelationship(obj)) {
417419
const edge = await this.#buildEdgeVisObject(obj);
418420

419421
this.#data.edges.update(edge);
@@ -448,7 +450,7 @@ export class NeoVis {
448450

449451
// eslint-disable-next-line @typescript-eslint/no-this-alias
450452
const neoVis = this;
451-
this.#network.on('click', function (this: VisNetwork.Network, params: { nodes: Node[], edges: Edge[], pointer: { DOM: VisNetwork.Position }}) {
453+
this.#network.on('click', function (this: VisNetwork.Network, params: { nodes: Node[], edges: Edge[], pointer: { DOM: VisNetwork.Position } }) {
452454
if (params.nodes.length > 0) {
453455
const nodeId = this.getNodeAt(params.pointer.DOM) as number;
454456
neoVis.#events.generateEvent(NeoVisEvents.ClickNodeEvent, {

0 commit comments

Comments
 (0)