diff --git a/functions/package-lock.json b/functions/package-lock.json index a7719d3..a2d61e9 100644 --- a/functions/package-lock.json +++ b/functions/package-lock.json @@ -200,9 +200,9 @@ } }, "@lingdocs/pashto-inflector": { - "version": "1.0.2", - "resolved": "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.2.tgz", - "integrity": "sha512-voPdIePrMzLc9RNFjyo0RczOPDoOkIhQ/34CxwfnkOrt7k3EwahPikEWvRIN4+JoxKJI8oA+iFKAN9OoGmY3Yg==", + "version": "1.0.5", + "resolved": "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.5.tgz", + "integrity": "sha512-WCBn8x4hag2XwkU03twlZMDOMLIfx+1Div3hzU/lifz/Um3hoFokzdH61CUdpOU/ApEhr242RtzzC0TUjLAFMg==", "requires": { "classnames": "^2.2.6", "pbf": "^3.2.1", diff --git a/functions/package.json b/functions/package.json index 9a30f21..253966e 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/pashto-inflector": "^1.0.2", + "@lingdocs/pashto-inflector": "^1.0.5", "@types/cors": "^2.8.10", "@types/google-spreadsheet": "^3.0.2", "cors": "^2.8.5", diff --git a/functions/src/index.ts b/functions/src/index.ts index 3633731..8bdca12 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -16,7 +16,7 @@ export const publishDictionary = functions.runWith({ try { const response = await publish(); res.send(response); - } catch (e) { + } catch (e: any) { res.status(500).send({ ok: false, error: e.message }); } } @@ -39,7 +39,7 @@ export const submissions = functions.runWith({ const response = await receiveSubmissions(suggestions, req.user.level === "editor"); // TODO: WARN IF ANY OF THE EDITS DIDN'T HAPPEN res.send(response); - } catch (e) { + } catch (e: any) { res.status(500).send({ ok: false, error: e.message }); }; } diff --git a/functions/src/publish.ts b/functions/src/publish.ts index c048d0d..a84e799 100644 --- a/functions/src/publish.ts +++ b/functions/src/publish.ts @@ -5,11 +5,11 @@ import { dictionaryEntryBooleanFields, dictionaryEntryNumberFields, dictionaryEntryTextFields, - standardizePashto, validateEntry, writeDictionary, writeDictionaryInfo, simplifyPhonetics, + standardizeEntry, } from "@lingdocs/pashto-inflector"; // import { // getWordList, @@ -33,14 +33,10 @@ const dictionaryInfoFilename = "dictionary-info"; const url = `${baseUrl}${dictionaryFilename}`; const infoUrl = `${baseUrl}${dictionaryInfoFilename}`; -function standardizePhonetics(f: string): string { - return f.replace(/’/g, "'"); -} - // TODO: Create a seperate function for publishing the Hunspell that can run after the publish function? // to keep the publish function time down -export default async function(): Promise { +export default async function publish(): Promise { const entries = await getRawEntries(); const errors = checkForErrors(entries); if (errors.length) { @@ -106,7 +102,7 @@ async function getRawEntries(): Promise { } function makeEntries(rows: any[]): T.DictionaryEntry[] { - const entries: T.DictionaryEntry[] = rows.map((row, i): T.DictionaryEntry => { + const entries: T.DictionaryEntry[] = rows.map((row): T.DictionaryEntry => { const e: T.DictionaryEntry = { i: 1, ts: parseInt(row.ts), @@ -116,28 +112,20 @@ function makeEntries(rows: any[]): T.DictionaryEntry[] { e: row.e, }; dictionaryEntryNumberFields.forEach((field: T.DictionaryEntryNumberField) => { - if (row[field]) { - e[field] = parseInt(row[field]); - } + if (row[field]) e[field] = parseInt(row[field]); }); dictionaryEntryTextFields.forEach((field: T.DictionaryEntryTextField) => { - if (row[field]) { - const content = field.slice(-1) === "p" ? standardizePashto(row[field]).trim() - : field.slice(-1) === "f" ? standardizePhonetics(row[field]).trim() - : row[field].trim(); - e[field] = content; - } + if (row[field]) e[field] = row[field].trim(); }); dictionaryEntryBooleanFields.forEach((field: T.DictionaryEntryBooleanField) => { - if (row[field]) { - e[field] = true; - } + if (row[field]) e[field] = true; }); - return e; + return standardizeEntry(e); }); // add alphabetical index entries.sort((a, b) => a.p.localeCompare(b.p, "ps")); const entriesLength = entries.length; + // add index for (let i = 0; i < entriesLength; i++) { entries[i].i = i; } diff --git a/functions/src/submissions.ts b/functions/src/submissions.ts index b2f2bfb..a99f50d 100644 --- a/functions/src/submissions.ts +++ b/functions/src/submissions.ts @@ -4,6 +4,7 @@ import { dictionaryEntryTextFields, dictionaryEntryBooleanFields, dictionaryEntryNumberFields, + standardizeEntry, } from "@lingdocs/pashto-inflector"; import * as FT from "../../website/src/types/functions-types"; import * as functions from "firebase-functions"; @@ -94,7 +95,7 @@ export async function receiveSubmissions(e: FT.SubmissionsRequest, editor: boole if (newEntries.length) { newEntries.forEach((n) => { - const entry = { ...n.entry }; + const entry = { ...standardizeEntry(n.entry) }; // @ts-ignore delete entry.i; // i not used in dictionary spreadsheet; added while building it // @ts-ignore diff --git a/website/package.json b/website/package.json index 09a4a90..992646a 100644 --- a/website/package.json +++ b/website/package.json @@ -6,7 +6,7 @@ "private": true, "dependencies": { "@fortawesome/fontawesome-free": "^5.15.2", - "@lingdocs/pashto-inflector": "^1.0.3", + "@lingdocs/pashto-inflector": "^1.0.5", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", diff --git a/website/src/screens/EntryEditor.tsx b/website/src/screens/EntryEditor.tsx index f4608ee..8792068 100644 --- a/website/src/screens/EntryEditor.tsx +++ b/website/src/screens/EntryEditor.tsx @@ -16,6 +16,7 @@ import { Types as T, InlinePs, validateEntry, + standardizeEntry, } from "@lingdocs/pashto-inflector"; import Entry from "../components/Entry"; import * as FT from "../types/functions-types"; diff --git a/website/yarn.lock b/website/yarn.lock index 2095552..9480de4 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -1483,10 +1483,10 @@ "@types/yargs" "^16.0.0" chalk "^4.0.0" -"@lingdocs/pashto-inflector@^1.0.3": - version "1.0.3" - resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.3.tgz#4ba205869f41a540d85d045eee23c484814f1fd8" - integrity sha512-bxz94hmCfVfJg2CthViFZ/14cQmhPHtS+uA/d11vViI6qad5Kl4U33jm1ZfS7AaXHasqmnsKyYW7Qn+y/E0yUA== +"@lingdocs/pashto-inflector@^1.0.5": + version "1.0.5" + resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-1.0.5.tgz#59b928e8ca1727572d661781a8db6b9f753052c4" + integrity sha512-WCBn8x4hag2XwkU03twlZMDOMLIfx+1Div3hzU/lifz/Um3hoFokzdH61CUdpOU/ApEhr242RtzzC0TUjLAFMg== dependencies: classnames "^2.2.6" pbf "^3.2.1"