Skip to content

Commit

Permalink
Merge pull request #219 from deep-foundation/bugfix/client/idLocal
Browse files Browse the repository at this point in the history
Fix DeepClient.idLocal
  • Loading branch information
FreePhoenix888 authored Sep 7, 2023
2 parents 5e99f52 + 0853faa commit c9a8fb1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
53 changes: 25 additions & 28 deletions imports/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { reserve } from './reserve.js';
import Debug from 'debug';
import { corePckg } from './core.js';
import { BoolExpCan, BoolExpHandler, QueryLink, BoolExpSelector, BoolExpTree, BoolExpValue, MutationInputLink, MutationInputLinkPlain, MutationInputValue } from './client_types.js';
import get from 'get-value';

const debug = Debug('deeplinks:client');
const log = debug.extend('log');
Expand Down Expand Up @@ -840,37 +841,33 @@ export class DeepClient<L = Link<number>> implements DeepClientInstance<L> {
}

idLocal(start: DeepClientStartItem, ...path: DeepClientPathItem[]): number {
if (_ids?.[start]?.[path[0]]) {
return _ids[start][path[0]];
const paths = [start, ...path] as [DeepClientStartItem, ...Array<Exclude<DeepClientPathItem, boolean>>];
if (get(_ids, paths.join('.'))) {
return get(_ids, paths.join('.'));
}
const containTypeLinkId = _ids['@deep-foundation/core'].Contain;
const result = this.minilinks.query({
in: {
type_id: containTypeLinkId,
from: {
...(typeof start === 'number' && {id: start}),
...(typeof start === 'string' && {
string: {
value: {
_eq: start
}
}
}),
},
...(typeof path[0] === 'string' && {
string: {
value: {
_eq: path[0]
}
}
}),
...(typeof path[0] === 'boolean' && {}), // TODO What should we do?

// let result: number;
// if(paths.length === 1) {

// } else {
// result = paths[0] as number;
// for (let i = 1; i < paths.length; i++) {
// result = this.idLocal(result, paths[i] as Exclude<DeepClientPathItem, boolean>);
// }
// }

const [link] = this.minilinks.query({
id: {
_id: paths
}
})
if(result.length > 0) {
return ((result[0] as unknown) as Link<number>).id;
})
const result = (link as Link<number>).id;

if(!result) {
throw new Error(`Id not found by ${JSON.stringify([start, ...path])}`);
} else {
return result as number
}
throw new Error(`Id not found by [${JSON.stringify([start, ...path])}]`);
};

async guest(options: DeepClientGuestOptions = {}): Promise<DeepClientAuthResult> {
Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"electron": "^13.1.9",
"fix-path": "^3.0.0",
"get-port": "^5.1.1",
"get-value": "^3.0.1",
"gists": "^2.0.0",
"graphql": "^15.8.0",
"graphql-playground-middleware-express": "^1.7.23",
Expand Down Expand Up @@ -96,6 +97,7 @@
"@testing-library/react": "^14.0.0",
"@types/debug": "^4.1.8",
"@types/fs-extra": "^11.0.1",
"@types/get-value": "^3.0.3",
"clean-webpack-plugin": "^4.0.0",
"fs-extra": "^11.1.1",
"jest": "^29.5.0",
Expand Down
3 changes: 2 additions & 1 deletion tests/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ describe('client', () => {
}, {returning: deepClient.selectReturning});
deepClient.minilinks.apply([packageLink,containLink,newTypeTypeLink]);
try {
const packageLinkId = deepClient.idLocal(packageName);
assert.equal(packageLinkId, packageLink.id)
const newTypeTypeLinkId = deepClient.idLocal(packageName, "Type");
assert.notEqual(newTypeTypeLinkId, 0);
assert.equal(newTypeTypeLinkId, newTypeTypeLink.id);
} finally {
await deepClient.delete([packageLink.id, newTypeTypeLink.id, containLink.id])
Expand Down

0 comments on commit c9a8fb1

Please sign in to comment.