Skip to content

Commit

Permalink
fix(lookup): schema suggestions on namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinslin committed Oct 19, 2020
1 parent 7f3789a commit 56ee6c4
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 4 deletions.
16 changes: 13 additions & 3 deletions packages/common-all/src/nodev2.ts
Expand Up @@ -734,7 +734,7 @@ export class SchemaUtilsV2 {
return {
schema: domainSchema,
notePath,
namespace: false,
namespace: domainSchema.data.namespace || false,
schemaModule: match,
};
}
Expand All @@ -747,6 +747,15 @@ export class SchemaUtilsV2 {
}
}

/**
*
* @param param0
* @return
* - schemaModule
* - schema
* - namespace
* - notePath
*/
static matchPathWithSchema({
notePath,
matched,
Expand Down Expand Up @@ -774,12 +783,13 @@ export class SchemaUtilsV2 {
matchNamespace,
});
if (match) {
const { schema } = match;
const { schema, namespace } = match;
// found a match
if (notePath === nextNotePath) {
return {
schemaModule,
schema,
namespace: false,
namespace,
notePath,
};
}
Expand Down
124 changes: 124 additions & 0 deletions packages/engine-server/src/__tests__/__snapshots__/nodev2.spec.ts.snap
Expand Up @@ -21,6 +21,130 @@ Object {
}
`;

exports[`matchPath match path on domain as namespace 1`] = `
Object {
"namespace": true,
"notePath": "bond",
"schema": Object {
"body": "",
"children": Array [],
"created": "1",
"data": Object {
"namespace": true,
},
"desc": "",
"fname": "bond",
"id": "bond",
"links": Array [],
"parent": "root",
"title": "bond",
"type": "schema",
"updated": "1",
},
"schemaModule": Object {
"fname": "bond",
"imports": Array [],
"root": Object {
"body": "",
"children": Array [],
"created": "1",
"data": Object {
"namespace": true,
},
"desc": "",
"fname": "bond",
"id": "bond",
"links": Array [],
"parent": "root",
"title": "bond",
"type": "schema",
"updated": "1",
},
"schemas": Object {
"bond": Object {
"body": "",
"children": Array [],
"created": "1",
"data": Object {
"namespace": true,
},
"desc": "",
"fname": "bond",
"id": "bond",
"links": Array [],
"parent": "root",
"title": "bond",
"type": "schema",
"updated": "1",
},
},
"version": 1,
},
}
`;

exports[`matchPath match path on domain as namespace, child 1`] = `
Object {
"namespace": false,
"notePath": "bond.foo",
"schema": Object {
"body": "",
"children": Array [],
"created": "1",
"data": Object {
"namespace": true,
},
"desc": "",
"fname": "bond",
"id": "bond",
"links": Array [],
"parent": "root",
"title": "bond",
"type": "schema",
"updated": "1",
},
"schemaModule": Object {
"fname": "bond",
"imports": Array [],
"root": Object {
"body": "",
"children": Array [],
"created": "1",
"data": Object {
"namespace": true,
},
"desc": "",
"fname": "bond",
"id": "bond",
"links": Array [],
"parent": "root",
"title": "bond",
"type": "schema",
"updated": "1",
},
"schemas": Object {
"bond": Object {
"body": "",
"children": Array [],
"created": "1",
"data": Object {
"namespace": true,
},
"desc": "",
"fname": "bond",
"id": "bond",
"links": Array [],
"parent": "root",
"title": "bond",
"type": "schema",
"updated": "1",
},
},
"version": 1,
},
}
`;

exports[`note serialize basic 1`] = `
"---
id: foo
Expand Down
4 changes: 4 additions & 0 deletions packages/engine-server/src/__tests__/nodev2.spec.ts
Expand Up @@ -147,7 +147,9 @@ describe("matchPath", () => {
notePath: "bond",
schemaModDict: engine.schemas,
});
expect(resp).toMatchSnapshot();
expect(resp?.schema.id).toEqual("bond");
expect(resp?.namespace).toBeTruthy();
});

it("match path on domain as namespace, child", async () => {
Expand All @@ -160,7 +162,9 @@ describe("matchPath", () => {
notePath: "bond.foo",
schemaModDict: engine.schemas,
});
expect(resp).toMatchSnapshot();
expect(resp?.schema.id).toEqual("bond");
expect(resp?.namespace).toBeFalsy();
});
});

Expand Down
Expand Up @@ -271,7 +271,7 @@ export class LookupProviderV2 {
schemaModDict: engine.schemas,
});
// since namespace matches everything, we don't do queries on that
if (results && !results.schema.data.namespace) {
if (results && !results.namespace) {
const { schema, schemaModule } = results;
const dirName = DNodeUtilsV2.dirName(queryOrig);
const candidates = schema.children
Expand Down

0 comments on commit 56ee6c4

Please sign in to comment.