From 56ee6c460dd562200931381923e72971681d1390 Mon Sep 17 00:00:00 2001 From: kevinslin Date: Mon, 19 Oct 2020 14:01:34 -0700 Subject: [PATCH] fix(lookup): schema suggestions on namespace --- packages/common-all/src/nodev2.ts | 16 ++- .../__snapshots__/nodev2.spec.ts.snap | 124 ++++++++++++++++++ .../src/__tests__/nodev2.spec.ts | 4 + .../src/components/lookup/LookupProviderV2.ts | 2 +- 4 files changed, 142 insertions(+), 4 deletions(-) diff --git a/packages/common-all/src/nodev2.ts b/packages/common-all/src/nodev2.ts index 6d1c7e47bb..29a49dbb40 100644 --- a/packages/common-all/src/nodev2.ts +++ b/packages/common-all/src/nodev2.ts @@ -734,7 +734,7 @@ export class SchemaUtilsV2 { return { schema: domainSchema, notePath, - namespace: false, + namespace: domainSchema.data.namespace || false, schemaModule: match, }; } @@ -747,6 +747,15 @@ export class SchemaUtilsV2 { } } + /** + * + * @param param0 + * @return + * - schemaModule + * - schema + * - namespace + * - notePath + */ static matchPathWithSchema({ notePath, matched, @@ -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, }; } diff --git a/packages/engine-server/src/__tests__/__snapshots__/nodev2.spec.ts.snap b/packages/engine-server/src/__tests__/__snapshots__/nodev2.spec.ts.snap index 02ac0096b2..2a4c18c686 100644 --- a/packages/engine-server/src/__tests__/__snapshots__/nodev2.spec.ts.snap +++ b/packages/engine-server/src/__tests__/__snapshots__/nodev2.spec.ts.snap @@ -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 diff --git a/packages/engine-server/src/__tests__/nodev2.spec.ts b/packages/engine-server/src/__tests__/nodev2.spec.ts index 5d65fd02a6..348abd6f0f 100644 --- a/packages/engine-server/src/__tests__/nodev2.spec.ts +++ b/packages/engine-server/src/__tests__/nodev2.spec.ts @@ -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 () => { @@ -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(); }); }); diff --git a/packages/plugin-core/src/components/lookup/LookupProviderV2.ts b/packages/plugin-core/src/components/lookup/LookupProviderV2.ts index a172397f1d..ba92ff6ae3 100644 --- a/packages/plugin-core/src/components/lookup/LookupProviderV2.ts +++ b/packages/plugin-core/src/components/lookup/LookupProviderV2.ts @@ -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