From 30f51385f3fd0689191d293b9f9cb08e3ee6426f Mon Sep 17 00:00:00 2001 From: adueck Date: Wed, 9 Nov 2022 13:56:42 +0500 Subject: [PATCH] ability to query by p as well for dictionary api --- account/package-lock.json | 14 +++++++------- account/package.json | 2 +- account/src/lib/dictionary.ts | 17 +++++++++++------ account/src/routers/dictionary-router.ts | 7 +++++-- account/src/test.http | 6 ++++++ account/yarn.lock | 8 ++++---- functions/package-lock.json | 14 +++++++------- functions/package.json | 2 +- website/package.json | 2 +- website/yarn.lock | 8 ++++---- 10 files changed, 47 insertions(+), 33 deletions(-) create mode 100644 account/src/test.http diff --git a/account/package-lock.json b/account/package-lock.json index 2dc0d41..ccc8d38 100644 --- a/account/package-lock.json +++ b/account/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@lingdocs/inflect": "^5.1.8", + "@lingdocs/inflect": "5.1.10", "base64url": "^3.0.1", "bcryptjs": "^2.4.3", "connect-redis": "^6.0.0", @@ -219,9 +219,9 @@ } }, "node_modules/@lingdocs/inflect": { - "version": "5.1.8", - "resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz", - "integrity": "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==", + "version": "5.1.10", + "resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz", + "integrity": "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==", "license": "MIT", "dependencies": { "pbf": "^3.2.1", @@ -5224,9 +5224,9 @@ } }, "@lingdocs/inflect": { - "version": "5.1.8", - "resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz", - "integrity": "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==", + "version": "5.1.10", + "resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz", + "integrity": "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==", "requires": { "pbf": "^3.2.1", "rambda": "^7.3.0" diff --git a/account/package.json b/account/package.json index ad49cea..1d28ae9 100644 --- a/account/package.json +++ b/account/package.json @@ -11,7 +11,7 @@ "author": "", "license": "ISC", "dependencies": { - "@lingdocs/inflect": "^5.1.8", + "@lingdocs/inflect": "5.1.10", "base64url": "^3.0.1", "bcryptjs": "^2.4.3", "connect-redis": "^6.0.0", diff --git a/account/src/lib/dictionary.ts b/account/src/lib/dictionary.ts index d1079fb..9ea2f69 100644 --- a/account/src/lib/dictionary.ts +++ b/account/src/lib/dictionary.ts @@ -7,6 +7,7 @@ import { readDictionaryInfo, Types as T, typePredicates as tp, + entryOfFull, } from "@lingdocs/inflect" export let collection: Collection | undefined = undefined; @@ -56,15 +57,18 @@ function getOneByTs(ts: number): T.DictionaryEntry { return entry; } -export async function getEntries(ids: number[]): Promise<{ +export async function getEntries(ids: (number | string)[]): Promise<{ results: (T.DictionaryEntry | T.VerbEntry)[], - notFound: number[], + notFound: (number | string)[], }> { if (!collection) { throw new Error("dictionary not initialized"); } const results: (T.DictionaryEntry | T.VerbEntry)[] = collection.find({ - "ts": { "$in": ids }, + "$or": [ + { "ts": { "$in": ids }}, + { "p": { "$in": ids }}, + ], }).map(x => { const { $loki, meta, ...entry } = x; return entry; @@ -85,9 +89,10 @@ export async function getEntries(ids: number[]): Promise<{ }); return { results, - notFound: ids.filter(id => !results.find(x => ( - "entry" in x ? x.entry.ts === id : x.ts === id - ))), + notFound: ids.filter(id => !results.find(x => { + const entry = entryOfFull(x); + return entry.p === id || entry.ts === id; + })), }; } diff --git a/account/src/routers/dictionary-router.ts b/account/src/routers/dictionary-router.ts index 72890ec..c408bd8 100644 --- a/account/src/routers/dictionary-router.ts +++ b/account/src/routers/dictionary-router.ts @@ -17,7 +17,7 @@ dictionaryRouter.post("/entries", async (req, res, next) => { if (!collection) { return res.send({ ok: false, message: "dictionary not ready" }); } - const ids = req.body.ids as number[]; + const ids = req.body.ids as (number | string)[]; if (!Array.isArray(ids)) { return res.status(400).send({ ok: false, error: "invalid query" }); } @@ -29,7 +29,10 @@ dictionaryRouter.get("/entries/:id", async (req, res, next) => { if (!collection) { return res.send({ ok: false, message: "dictionary not ready" }); } - const ids = req.params.id.split(",").map(unary(parseInt)); + const ids = req.params.id.split(",").map(x => { + const n = parseInt(x); + return Number.isNaN(n) ? x : n; + }); const results = await getEntries(ids); return res.send(results); }); diff --git a/account/src/test.http b/account/src/test.http new file mode 100644 index 0000000..03b35f7 --- /dev/null +++ b/account/src/test.http @@ -0,0 +1,6 @@ +POST http://localhost:4000/dictionary/entries +content-type: application/json + +{ + "ids": ["کور", 1527815306] +} \ No newline at end of file diff --git a/account/yarn.lock b/account/yarn.lock index d389b81..06eaf3f 100644 --- a/account/yarn.lock +++ b/account/yarn.lock @@ -105,10 +105,10 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@lingdocs/inflect@^5.1.8": - "integrity" "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==" - "resolved" "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz" - "version" "5.1.8" +"@lingdocs/inflect@5.1.10": + "integrity" "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==" + "resolved" "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz" + "version" "5.1.10" dependencies: "pbf" "^3.2.1" "rambda" "^7.3.0" diff --git a/functions/package-lock.json b/functions/package-lock.json index b98aa6e..32b5e28 100644 --- a/functions/package-lock.json +++ b/functions/package-lock.json @@ -7,7 +7,7 @@ "name": "functions", "dependencies": { "@google-cloud/storage": "^5.8.1", - "@lingdocs/inflect": "5.1.8", + "@lingdocs/inflect": "5.1.10", "@types/cors": "^2.8.10", "@types/google-spreadsheet": "^3.0.2", "@types/react": "^18.0.21", @@ -391,9 +391,9 @@ } }, "node_modules/@lingdocs/inflect": { - "version": "5.1.8", - "resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz", - "integrity": "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==", + "version": "5.1.10", + "resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz", + "integrity": "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==", "license": "MIT", "dependencies": { "pbf": "^3.2.1", @@ -3499,9 +3499,9 @@ } }, "@lingdocs/inflect": { - "version": "5.1.8", - "resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz", - "integrity": "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==", + "version": "5.1.10", + "resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz", + "integrity": "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==", "requires": { "pbf": "^3.2.1", "rambda": "^7.3.0" diff --git a/functions/package.json b/functions/package.json index a483fd3..05a6616 100644 --- a/functions/package.json +++ b/functions/package.json @@ -14,7 +14,7 @@ "main": "lib/functions/src/index.js", "dependencies": { "@google-cloud/storage": "^5.8.1", - "@lingdocs/inflect": "5.1.8", + "@lingdocs/inflect": "5.1.10", "@types/cors": "^2.8.10", "@types/google-spreadsheet": "^3.0.2", "@types/react": "^18.0.21", diff --git a/website/package.json b/website/package.json index 6afbad0..a31fdfa 100644 --- a/website/package.json +++ b/website/package.json @@ -7,7 +7,7 @@ "private": true, "dependencies": { "@fortawesome/fontawesome-free": "^5.15.2", - "@lingdocs/ps-react": "5.1.8", + "@lingdocs/ps-react": "5.1.10", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", diff --git a/website/yarn.lock b/website/yarn.lock index 9a08d3a..f71f34c 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -2349,10 +2349,10 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@lingdocs/ps-react@5.1.8": - version "5.1.8" - resolved "https://npm.lingdocs.com/@lingdocs%2fps-react/-/ps-react-5.1.8.tgz#3bdad675ae8d2ea4f77abe572a4b33574e2ce986" - integrity sha512-kcOzjRHjw6rOqX2o0KAv0o1B9apzYwQob9/s0vpl1d4HCV+SbmCnuAy+d0LCzmbhDNhZX5wu0ZZjVhaQMtQ17A== +"@lingdocs/ps-react@5.1.10": + version "5.1.10" + resolved "https://npm.lingdocs.com/@lingdocs%2fps-react/-/ps-react-5.1.10.tgz#155646c436c7dc2644c60815cef6b914ba7fef69" + integrity sha512-3PtfEZBmNCa6ptlWezLXpHrngcRmPc8QKguGiXI48TnVxSvAaSH63FTwRQJIDznYasq3bnDSH/7Sta8SX8vvBA== dependencies: "@formkit/auto-animate" "^1.0.0-beta.3" classnames "^2.2.6"