ability to query by p as well for dictionary api
This commit is contained in:
parent
685b85bd48
commit
30f51385f3
|
@ -9,7 +9,7 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lingdocs/inflect": "^5.1.8",
|
"@lingdocs/inflect": "5.1.10",
|
||||||
"base64url": "^3.0.1",
|
"base64url": "^3.0.1",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"connect-redis": "^6.0.0",
|
"connect-redis": "^6.0.0",
|
||||||
|
@ -219,9 +219,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lingdocs/inflect": {
|
"node_modules/@lingdocs/inflect": {
|
||||||
"version": "5.1.8",
|
"version": "5.1.10",
|
||||||
"resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz",
|
"resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz",
|
||||||
"integrity": "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==",
|
"integrity": "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pbf": "^3.2.1",
|
"pbf": "^3.2.1",
|
||||||
|
@ -5224,9 +5224,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@lingdocs/inflect": {
|
"@lingdocs/inflect": {
|
||||||
"version": "5.1.8",
|
"version": "5.1.10",
|
||||||
"resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz",
|
"resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz",
|
||||||
"integrity": "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==",
|
"integrity": "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"pbf": "^3.2.1",
|
"pbf": "^3.2.1",
|
||||||
"rambda": "^7.3.0"
|
"rambda": "^7.3.0"
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lingdocs/inflect": "^5.1.8",
|
"@lingdocs/inflect": "5.1.10",
|
||||||
"base64url": "^3.0.1",
|
"base64url": "^3.0.1",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"connect-redis": "^6.0.0",
|
"connect-redis": "^6.0.0",
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
readDictionaryInfo,
|
readDictionaryInfo,
|
||||||
Types as T,
|
Types as T,
|
||||||
typePredicates as tp,
|
typePredicates as tp,
|
||||||
|
entryOfFull,
|
||||||
} from "@lingdocs/inflect"
|
} from "@lingdocs/inflect"
|
||||||
|
|
||||||
export let collection: Collection<any> | undefined = undefined;
|
export let collection: Collection<any> | undefined = undefined;
|
||||||
|
@ -56,15 +57,18 @@ function getOneByTs(ts: number): T.DictionaryEntry {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getEntries(ids: number[]): Promise<{
|
export async function getEntries(ids: (number | string)[]): Promise<{
|
||||||
results: (T.DictionaryEntry | T.VerbEntry)[],
|
results: (T.DictionaryEntry | T.VerbEntry)[],
|
||||||
notFound: number[],
|
notFound: (number | string)[],
|
||||||
}> {
|
}> {
|
||||||
if (!collection) {
|
if (!collection) {
|
||||||
throw new Error("dictionary not initialized");
|
throw new Error("dictionary not initialized");
|
||||||
}
|
}
|
||||||
const results: (T.DictionaryEntry | T.VerbEntry)[] = collection.find({
|
const results: (T.DictionaryEntry | T.VerbEntry)[] = collection.find({
|
||||||
"ts": { "$in": ids },
|
"$or": [
|
||||||
|
{ "ts": { "$in": ids }},
|
||||||
|
{ "p": { "$in": ids }},
|
||||||
|
],
|
||||||
}).map(x => {
|
}).map(x => {
|
||||||
const { $loki, meta, ...entry } = x;
|
const { $loki, meta, ...entry } = x;
|
||||||
return entry;
|
return entry;
|
||||||
|
@ -85,9 +89,10 @@ export async function getEntries(ids: number[]): Promise<{
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
results,
|
results,
|
||||||
notFound: ids.filter(id => !results.find(x => (
|
notFound: ids.filter(id => !results.find(x => {
|
||||||
"entry" in x ? x.entry.ts === id : x.ts === id
|
const entry = entryOfFull(x);
|
||||||
))),
|
return entry.p === id || entry.ts === id;
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ dictionaryRouter.post("/entries", async (req, res, next) => {
|
||||||
if (!collection) {
|
if (!collection) {
|
||||||
return res.send({ ok: false, message: "dictionary not ready" });
|
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)) {
|
if (!Array.isArray(ids)) {
|
||||||
return res.status(400).send({ ok: false, error: "invalid query" });
|
return res.status(400).send({ ok: false, error: "invalid query" });
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,10 @@ dictionaryRouter.get("/entries/:id", async (req, res, next) => {
|
||||||
if (!collection) {
|
if (!collection) {
|
||||||
return res.send({ ok: false, message: "dictionary not ready" });
|
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);
|
const results = await getEntries(ids);
|
||||||
return res.send(results);
|
return res.send(results);
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
POST http://localhost:4000/dictionary/entries
|
||||||
|
content-type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"ids": ["کور", 1527815306]
|
||||||
|
}
|
|
@ -105,10 +105,10 @@
|
||||||
"@jridgewell/resolve-uri" "^3.0.3"
|
"@jridgewell/resolve-uri" "^3.0.3"
|
||||||
"@jridgewell/sourcemap-codec" "^1.4.10"
|
"@jridgewell/sourcemap-codec" "^1.4.10"
|
||||||
|
|
||||||
"@lingdocs/inflect@^5.1.8":
|
"@lingdocs/inflect@5.1.10":
|
||||||
"integrity" "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg=="
|
"integrity" "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA=="
|
||||||
"resolved" "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz"
|
"resolved" "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz"
|
||||||
"version" "5.1.8"
|
"version" "5.1.10"
|
||||||
dependencies:
|
dependencies:
|
||||||
"pbf" "^3.2.1"
|
"pbf" "^3.2.1"
|
||||||
"rambda" "^7.3.0"
|
"rambda" "^7.3.0"
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"name": "functions",
|
"name": "functions",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@google-cloud/storage": "^5.8.1",
|
"@google-cloud/storage": "^5.8.1",
|
||||||
"@lingdocs/inflect": "5.1.8",
|
"@lingdocs/inflect": "5.1.10",
|
||||||
"@types/cors": "^2.8.10",
|
"@types/cors": "^2.8.10",
|
||||||
"@types/google-spreadsheet": "^3.0.2",
|
"@types/google-spreadsheet": "^3.0.2",
|
||||||
"@types/react": "^18.0.21",
|
"@types/react": "^18.0.21",
|
||||||
|
@ -391,9 +391,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lingdocs/inflect": {
|
"node_modules/@lingdocs/inflect": {
|
||||||
"version": "5.1.8",
|
"version": "5.1.10",
|
||||||
"resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz",
|
"resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz",
|
||||||
"integrity": "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==",
|
"integrity": "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pbf": "^3.2.1",
|
"pbf": "^3.2.1",
|
||||||
|
@ -3499,9 +3499,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@lingdocs/inflect": {
|
"@lingdocs/inflect": {
|
||||||
"version": "5.1.8",
|
"version": "5.1.10",
|
||||||
"resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.8.tgz",
|
"resolved": "https://npm.lingdocs.com/@lingdocs%2finflect/-/inflect-5.1.10.tgz",
|
||||||
"integrity": "sha512-jk9qlJvDMFpw6FIQ6XCun3zfv679aG9uoM17P7rIeNDrjOxH00brRbBD3amaVC6UvpU0mxSC9n9dnubncrd9lg==",
|
"integrity": "sha512-LPJqXSnb2zLWLfMXMTCs/1NOGYQnzPHbKu5h/SdvFYobCxnk2tgngtSWcCmeqYbNXKqQvbDwqmseLlcnUZKysA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"pbf": "^3.2.1",
|
"pbf": "^3.2.1",
|
||||||
"rambda": "^7.3.0"
|
"rambda": "^7.3.0"
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"main": "lib/functions/src/index.js",
|
"main": "lib/functions/src/index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@google-cloud/storage": "^5.8.1",
|
"@google-cloud/storage": "^5.8.1",
|
||||||
"@lingdocs/inflect": "5.1.8",
|
"@lingdocs/inflect": "5.1.10",
|
||||||
"@types/cors": "^2.8.10",
|
"@types/cors": "^2.8.10",
|
||||||
"@types/google-spreadsheet": "^3.0.2",
|
"@types/google-spreadsheet": "^3.0.2",
|
||||||
"@types/react": "^18.0.21",
|
"@types/react": "^18.0.21",
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "^5.15.2",
|
"@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/jest-dom": "^5.11.4",
|
||||||
"@testing-library/react": "^11.1.0",
|
"@testing-library/react": "^11.1.0",
|
||||||
"@testing-library/user-event": "^12.1.10",
|
"@testing-library/user-event": "^12.1.10",
|
||||||
|
|
|
@ -2349,10 +2349,10 @@
|
||||||
"@jridgewell/resolve-uri" "^3.0.3"
|
"@jridgewell/resolve-uri" "^3.0.3"
|
||||||
"@jridgewell/sourcemap-codec" "^1.4.10"
|
"@jridgewell/sourcemap-codec" "^1.4.10"
|
||||||
|
|
||||||
"@lingdocs/ps-react@5.1.8":
|
"@lingdocs/ps-react@5.1.10":
|
||||||
version "5.1.8"
|
version "5.1.10"
|
||||||
resolved "https://npm.lingdocs.com/@lingdocs%2fps-react/-/ps-react-5.1.8.tgz#3bdad675ae8d2ea4f77abe572a4b33574e2ce986"
|
resolved "https://npm.lingdocs.com/@lingdocs%2fps-react/-/ps-react-5.1.10.tgz#155646c436c7dc2644c60815cef6b914ba7fef69"
|
||||||
integrity sha512-kcOzjRHjw6rOqX2o0KAv0o1B9apzYwQob9/s0vpl1d4HCV+SbmCnuAy+d0LCzmbhDNhZX5wu0ZZjVhaQMtQ17A==
|
integrity sha512-3PtfEZBmNCa6ptlWezLXpHrngcRmPc8QKguGiXI48TnVxSvAaSH63FTwRQJIDznYasq3bnDSH/7Sta8SX8vvBA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@formkit/auto-animate" "^1.0.0-beta.3"
|
"@formkit/auto-animate" "^1.0.0-beta.3"
|
||||||
classnames "^2.2.6"
|
classnames "^2.2.6"
|
||||||
|
|
Loading…
Reference in New Issue