@kulupu-linku/sona 0.3.5 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/.assetsignore +0 -0
  2. package/dist/client-BSyS8F5a.d.ts +1612 -0
  3. package/dist/client-BitJ28pJ.js +10 -0
  4. package/dist/client-CUMo53JZ.d.ts +1612 -0
  5. package/dist/client-DNWH1gFt.js +10 -0
  6. package/dist/index-1jX6YIBj.d.ts +1497 -0
  7. package/dist/index-DObG_APy.d.ts +398 -0
  8. package/dist/index-DsVEVr6r.d.ts +300 -0
  9. package/dist/lib/v1/client.d.ts +3 -0
  10. package/dist/lib/v1/client.js +3 -0
  11. package/dist/lib/v1/client.test.d.ts +31 -0
  12. package/dist/lib/v1/client.test.js +3 -0
  13. package/dist/lib/v1/index.d.ts +2 -0
  14. package/dist/lib/v1/index.js +4 -0
  15. package/dist/lib/v1/types.d.ts +2 -0
  16. package/dist/lib/v1/types.js +1 -0
  17. package/dist/lib/v1/utils.d.ts +26 -0
  18. package/dist/lib/v1/utils.js +3 -0
  19. package/dist/lib/v2/client.d.ts +3 -0
  20. package/dist/lib/v2/client.js +3 -0
  21. package/dist/lib/v2/client.test.d.ts +36 -0
  22. package/dist/lib/v2/client.test.js +3 -0
  23. package/dist/lib/v2/index.d.ts +2 -0
  24. package/dist/lib/v2/index.js +4 -0
  25. package/dist/lib/v2/types.d.ts +2 -0
  26. package/dist/lib/v2/types.js +1 -0
  27. package/dist/lib/v2/utils.d.ts +44 -0
  28. package/dist/lib/v2/utils.js +3 -0
  29. package/dist/server/index.d.ts +2 -684
  30. package/dist/server/index.js +43 -0
  31. package/dist/server/utils.d.ts +22 -15
  32. package/dist/server/utils.js +3 -0
  33. package/dist/server/v1/index.d.ts +863 -639
  34. package/dist/server/v1/index.js +8 -0
  35. package/dist/server/v2/index.d.ts +1112 -0
  36. package/dist/server/v2/index.js +8 -0
  37. package/dist/server/versioning.d.ts +1964 -2369
  38. package/dist/server/versioning.js +8 -0
  39. package/dist/utils-DkAaVBMs.js +33 -0
  40. package/dist/utils-QiKwNnnL.js +37 -0
  41. package/dist/utils-Z1o5sWsW.js +40 -0
  42. package/dist/v1-DkHVwPCI.js +139 -0
  43. package/dist/v1-obRCoWWK.js +267 -0
  44. package/dist/v2-CDtbJFxV.js +194 -0
  45. package/generated/v2/fingerspelling.json +124 -0
  46. package/generated/v2/fingerspellings.json +135 -0
  47. package/generated/v2/font.json +119 -0
  48. package/generated/v2/fonts.json +130 -0
  49. package/generated/v2/glyph.json +160 -0
  50. package/generated/v2/glyphs.json +167 -0
  51. package/generated/v2/language.json +58 -0
  52. package/generated/v2/languages.json +67 -0
  53. package/generated/v2/sign.json +149 -0
  54. package/generated/v2/signs.json +160 -0
  55. package/generated/v2/word.json +306 -0
  56. package/generated/v2/words.json +313 -0
  57. package/package.json +47 -28
  58. package/dist/client.d.ts +0 -1
  59. package/dist/client.js +0 -165
  60. package/dist/index.d.ts +0 -1
  61. package/dist/index.js +0 -223
  62. package/dist/lib/client.d.ts +0 -742
  63. package/dist/lib/client.test.d.ts +0 -28
  64. package/dist/lib/index.d.ts +0 -963
  65. package/dist/lib/types.d.ts +0 -18
  66. package/dist/lib/utils.d.ts +0 -14
  67. package/dist/utils-GfUvEzD4.js +0 -2905
  68. package/dist/utils.d.ts +0 -1
  69. package/dist/utils.js +0 -9
  70. package/generated/words.json +0 -315
  71. /package/generated/{commentary_translation.json → v1/commentary_translation.json} +0 -0
  72. /package/generated/{definition_translation.json → v1/definition_translation.json} +0 -0
  73. /package/generated/{etymology_translation.json → v1/etymology_translation.json} +0 -0
  74. /package/generated/{fingerspelling.json → v1/fingerspelling.json} +0 -0
  75. /package/generated/{fingerspelling_sign.json → v1/fingerspelling_sign.json} +0 -0
  76. /package/generated/{font.json → v1/font.json} +0 -0
  77. /package/generated/{fonts.json → v1/fonts.json} +0 -0
  78. /package/generated/{icon_translation.json → v1/icon_translation.json} +0 -0
  79. /package/generated/{languages.json → v1/languages.json} +0 -0
  80. /package/generated/{parameters_translation.json → v1/parameters_translation.json} +0 -0
  81. /package/generated/{sign.json → v1/sign.json} +0 -0
  82. /package/generated/{signs.json → v1/signs.json} +0 -0
  83. /package/generated/{sitelen_pona_translation.json → v1/sitelen_pona_translation.json} +0 -0
  84. /package/generated/{word.json → v1/word.json} +0 -0
@@ -0,0 +1,8 @@
1
+ import "../utils-QiKwNnnL.js";
2
+ import "../v1-DkHVwPCI.js";
3
+ import "../utils-DkAaVBMs.js";
4
+ import "../utils-Z1o5sWsW.js";
5
+ import "../v2-CDtbJFxV.js";
6
+ import { a as fetchFile, i as apps, o as versions } from "../v1-obRCoWWK.js";
7
+
8
+ export { apps, fetchFile, versions };
@@ -0,0 +1,33 @@
1
+ import { z } from "zod/v4";
2
+ import { zValidator } from "@hono/zod-validator";
3
+
4
+ //#region src/server/utils.ts
5
+ const entries = (o) => {
6
+ return Object.entries(o);
7
+ };
8
+ const keys = (o) => {
9
+ return Object.keys(o);
10
+ };
11
+ const filterObject = (o, predicate) => {
12
+ return Object.fromEntries(entries(o).filter(([key, value]) => predicate([key, value])));
13
+ };
14
+ const langIdCoalesce = (lang, langs) => {
15
+ if (lang in langs) return lang;
16
+ for (const [id, metadata] of Object.entries(langs)) {
17
+ if (lang === metadata.locale) return id;
18
+ for (const [key, name] of Object.entries(metadata.name)) if (lang.toLowerCase() === name?.toLowerCase()) return id;
19
+ }
20
+ };
21
+ const langValidator = zValidator("query", z.object({ lang: z.string().regex(/^([^,]+,)*[^,]+/).optional() }));
22
+ function joinPath(...segments) {
23
+ return segments.filter(Boolean).join("/").replace(/\/{2,}/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
24
+ }
25
+ function mergeToKey(target, tkey, ...sources) {
26
+ if (!sources.length) return target;
27
+ const source = sources.shift();
28
+ for (const key in source) target[key][tkey] = source[key];
29
+ return target;
30
+ }
31
+
32
+ //#endregion
33
+ export { langIdCoalesce as a, keys as i, filterObject as n, langValidator as o, joinPath as r, mergeToKey as s, entries as t };
@@ -0,0 +1,37 @@
1
+ import { z } from "zod/v4";
2
+
3
+ //#region src/lib/v1/utils.ts
4
+ const Book = z.union([
5
+ z.literal("pu"),
6
+ z.literal("ku suli"),
7
+ z.literal("ku lili"),
8
+ z.literal("none")
9
+ ]);
10
+ const CoinedEra = z.union([
11
+ z.literal("pre-pu"),
12
+ z.literal("post-pu"),
13
+ z.literal("post-ku")
14
+ ]);
15
+ const UsageCategory = z.union([
16
+ z.literal("core"),
17
+ z.literal("common"),
18
+ z.literal("uncommon"),
19
+ z.literal("obscure"),
20
+ z.literal("sandbox")
21
+ ]);
22
+ const WritingSystem = z.enum([
23
+ "sitelen pona",
24
+ "sitelen sitelen",
25
+ "alphabet",
26
+ "syllabary",
27
+ "logography",
28
+ "tokiponido alphabet",
29
+ "tokiponido syllabary",
30
+ "tokiponido logography"
31
+ ]);
32
+ function getTranslatedData(data, key, language) {
33
+ return (data.translations[language] ?? data.translations["en"])[key];
34
+ }
35
+
36
+ //#endregion
37
+ export { getTranslatedData as a, WritingSystem as i, CoinedEra as n, UsageCategory as r, Book as t };
@@ -0,0 +1,40 @@
1
+ import { z } from "zod/v4";
2
+
3
+ //#region src/lib/v2/utils.ts
4
+ const Date = z.string().regex(/^(?<year>20\d{2})(?:-(?<month>0[1-9]|1[0-2])(?:-(?<day>0[1-9]|[12]\d|3[01]))?)?$/);
5
+ const OptionalDate = z.string().regex(/^(?:|(?<year>20\d{2})(?:-(?<month>0[1-9]|1[0-2])(?:-(?<day>0[1-9]|[12]\d|3[01]))?)?|(?<startYear>20\d{2})-(?<endYear>20\d{2}))$/);
6
+ const Score = z.number().min(0).max(100);
7
+ const Book = z.enum([
8
+ "pu",
9
+ "ku suli",
10
+ "ku lili",
11
+ "none"
12
+ ]);
13
+ const Era = z.enum([
14
+ "pre-pu",
15
+ "post-pu",
16
+ "post-ku"
17
+ ]);
18
+ const UsageCategory = z.enum([
19
+ "core",
20
+ "common",
21
+ "uncommon",
22
+ "obscure",
23
+ "sandbox"
24
+ ]);
25
+ const WritingSystem = z.enum([
26
+ "sitelen pona",
27
+ "sitelen sitelen",
28
+ "alphabet",
29
+ "syllabary",
30
+ "logography",
31
+ "tokiponido alphabet",
32
+ "tokiponido syllabary",
33
+ "tokiponido logography"
34
+ ]);
35
+ function getTranslatedData(data, key, language) {
36
+ return (data.translations[language] ?? data.translations["en"])[key];
37
+ }
38
+
39
+ //#endregion
40
+ export { Score as a, getTranslatedData as c, OptionalDate as i, Date as n, UsageCategory as o, Era as r, WritingSystem as s, Book as t };
@@ -0,0 +1,139 @@
1
+ import { i as WritingSystem, n as CoinedEra, r as UsageCategory, t as Book } from "./utils-QiKwNnnL.js";
2
+ import { z } from "zod/v4";
3
+
4
+ //#region src/lib/v1/index.ts
5
+ const YearMonth = z.string().regex(/^20\d{2}-(0[1-9]|1[0-2])$/g);
6
+ const Word = z.object({
7
+ id: z.string().min(1).describe(`A unique identifier for the word. Usually the word but may have an integer added in case of a word with multiple definitions (like "we")`),
8
+ author_verbatim: z.string().describe("The author's original definition, taken verbatim in their words"),
9
+ author_verbatim_source: z.string().describe("Where the author's original definition is located (usually Discord)"),
10
+ book: Book.describe("Which official Toki Pona book was this word featured in, if any."),
11
+ coined_era: CoinedEra.or(z.literal("")).describe("When this word was coined (relative to the publication dates of the official Toki Pona books, if known)"),
12
+ coined_year: z.string().describe("The year when this word was coined (if known)"),
13
+ creator: z.array(z.string()).describe("The person who created this word (if known)"),
14
+ ku_data: z.record(z.string().min(1).describe("A translation of the word into English proposed in ku"), z.number().min(0).max(100).describe("The percentage of ku survey respondents who report this translation as accurate to their usage.")).optional().describe("The usage data of the word as described in ku (the official Toki Pona dictionary)"),
15
+ see_also: z.array(z.string()).describe("A list of related words"),
16
+ resources: z.object({
17
+ sona_pona: z.string().url().optional().describe("A link to the word's page on sona.pona.la, a Toki Pona wiki. May redirect for words with references but no dedicated page."),
18
+ lipamanka_semantic: z.string().url().optional().describe("A link to lipamanka's description of the word's semantic space.")
19
+ }).optional().describe("Non-Linku resources related to the specific word, such as wiki links."),
20
+ representations: z.object({
21
+ sitelen_emosi: z.string().emoji().optional().describe("The sitelen emosi representation of this word, a script for writing Toki Pona using emoji"),
22
+ sitelen_jelo: z.array(z.string().emoji()).min(1).optional().describe("One or more example emojis for how the word can be written in sitelen jelo"),
23
+ ligatures: z.array(z.string().min(1)).optional().describe("A list of sitelen Lasina representations of the word, used by ligature fonts to visually convert latin characters into sitelen pona"),
24
+ sitelen_sitelen: z.string().url().optional().describe("A URL pointing to an image of this word's sitelen sitelen hieroglyphic block"),
25
+ ucsur: z.string().regex(/^U\+[\da-fA-F]{4,6}$/g).optional().describe("The word's UCSUR codepoint, as defined in https://www.kreativekorp.com/ucsur/charts/sitelen.html")
26
+ }).optional().describe("Ways of representing this word in the real world, via text/computers"),
27
+ source_language: z.string().describe("The language this word originated from"),
28
+ usage_category: UsageCategory.describe("The word's usage category, according to a survey performed by the Linku Project"),
29
+ word: z.string().describe(`The word's actual text, in case of a word with multiple definitions (like "we")`),
30
+ deprecated: z.boolean().describe("Whether or not the word is considered deprecated by its author."),
31
+ etymology: z.array(z.object({
32
+ word: z.string().optional().describe("One of the root words of this word, as written out in its language of origin"),
33
+ alt: z.string().optional().describe(`A latinized representation of the "word" field`)
34
+ })).describe("Unlocalized etymological values regarding this word's origin"),
35
+ audio: z.array(z.object({
36
+ author: z.string().describe("The author of the audio file in `link`."),
37
+ link: z.string().url().describe("A link to the audio file for the word, pronounced by `author`.")
38
+ }).describe("Audio files of the words pronounced out loud")),
39
+ pu_verbatim: z.object({
40
+ en: z.string().describe("The original definition in the English version of pu"),
41
+ fr: z.string().describe("The original definition in the French version of pu"),
42
+ de: z.string().describe("The original definition in the German version of pu"),
43
+ eo: z.string().describe("The original definition in the Esperanto version of pu")
44
+ }).optional().describe("The original definition of the word in pu, the first official Toki Pona book"),
45
+ usage: z.record(z.string().regex(/^20\d{2}-(0[1-9]|1[0-2])$/g), z.number().min(0).max(100)).describe("The percentage of people in the Toki Pona community who use this word, according to surveys performed by the Linku Project")
46
+ }).describe("General info on a Toki Pona word");
47
+ const CommentaryTranslation = z.record(z.string().min(1), z.string()).describe("Localized commentary regarding Toki Pona words");
48
+ const DefinitionTranslation = z.record(z.string().min(1), z.string().min(1)).describe("Localized definitions of Toki Pona words");
49
+ const SitelenPonaTranslation = z.record(z.string().min(1), z.string()).describe("Localized descriptions of the origins of the sitelen pona glyphs for Toki Pona words");
50
+ const EtymologyTranslation = z.record(z.string().min(1), z.array(z.object({
51
+ definition: z.string().optional().describe("The localized definition of the root word in its origin language"),
52
+ language: z.string().describe("The localized name of the language this word originated from")
53
+ }))).describe("Localized etymological values for Toki Pona words");
54
+ const Sign = z.object({
55
+ definition: z.string().describe("The definition of the sign as a single toki pona word."),
56
+ id: z.string().describe("A globally unique name for the sign which is also a gloss."),
57
+ is_two_handed: z.boolean().describe("Whether the sign is two-handed or not."),
58
+ new_gloss: z.string().describe("The more recent, preferred gloss for this sign."),
59
+ old_gloss: z.string().describe("The older gloss for this sign, similar to `id`."),
60
+ etymology: z.array(z.object({
61
+ language: z.string().describe("The language of the sign."),
62
+ sign: z.string().optional().describe("The name of the sign such that it could be found in a sign language dictionary.")
63
+ })).describe("Unlocalized etymological values regarding this sign's origin"),
64
+ signwriting: z.object({
65
+ fsw: z.string().describe("The [Formal SignWriting](https://en.wikipedia.org/wiki/SignWriting) representation of the sign."),
66
+ swu: z.string().describe("The [SignWriting with Unicode](https://en.wikipedia.org/wiki/SignWriting) representation of the sign.")
67
+ }).describe("Scripts for representing a sign as characters."),
68
+ video: z.object({
69
+ gif: z.string().optional().describe("A link to a gif of the sign being signed."),
70
+ mp4: z.string().optional().describe("a link to an mp4 of the sign being signed.")
71
+ }).describe("Videos of the sign being performed, by format.")
72
+ }).describe("Unlocalized info on a Luka Pona sign");
73
+ const FingerspellingSign = z.object({
74
+ id: z.string().describe("A globally unique name for the sign which is also a gloss."),
75
+ is_two_handed: z.boolean().describe("Whether the sign is two-handed or not."),
76
+ etymology: z.array(z.object({
77
+ language: z.string().describe("The language of the sign."),
78
+ sign: z.string().describe("The name of the sign such that it could be found in a sign language dictionary.")
79
+ })).describe("Unlocalized etymological values regarding this sign's origin"),
80
+ signwriting: z.object({
81
+ fsw: z.string().describe("The Formal Sign Writing representation of the sign."),
82
+ swu: z.string().describe("The Sign Writing with Unicode representation of hte sign.")
83
+ }).describe("Scripts for representing a sign as characters."),
84
+ video: z.object({
85
+ gif: z.string().optional().describe("A link to a gif of the sign being signed."),
86
+ mp4: z.string().optional().describe("a link to an mp4 of the sign being signed.")
87
+ }).describe("Videos of the sign being performed, by format.")
88
+ }).describe("Unlocalized info on a fingerspelling sign.");
89
+ const ParametersTranslation = z.record(z.string().min(1), z.object({
90
+ handshape: z.string().optional().describe("The shape of the hand when signing, identified by its name in ASL. Should not be translated in any language other than Toki Pona"),
91
+ movement: z.string().optional().describe("The motion of the hand when signing."),
92
+ placement: z.string().optional().describe("The placement of the hand when signing."),
93
+ orientation: z.string().optional().describe("The orientation of the hand when signing.")
94
+ })).describe("Partly localized descriptions of how a sign is signed.");
95
+ const IconTranslation = z.record(z.string().min(1), z.string()).describe("Localized descriptions of the thing a sign represents.");
96
+ const Font = z.object({
97
+ id: z.string().min(1).describe("The font's unique ID, identifying it among other fonts"),
98
+ creator: z.array(z.string()).describe("a list of this font's creators"),
99
+ features: z.array(z.string()).describe("a list of features this font supports"),
100
+ filename: z.string().regex(/^(?:.+\.(ttf|otf|woff2|woff))?$/).describe("the name of the file this font is stored in at https://github.com/lipu-linku/ijo"),
101
+ last_updated: YearMonth.optional().describe("the rough date of this font's last update"),
102
+ license: z.string().describe("an SPDX expression describing this font's license: https://spdx.org/licenses/"),
103
+ ligatures: z.boolean().describe("whether this font supports ligatures"),
104
+ name: z.string().min(1).describe("this font's name"),
105
+ style: z.string().min(1).describe("the general style of this font"),
106
+ ucsur: z.boolean().describe("whether this font conforms to the UCSUR standard: https://www.kreativekorp.com/ucsur/charts/sitelen.html"),
107
+ version: z.string().describe("the current version of this font"),
108
+ writing_system: WritingSystem.describe("the writing system this font uses as its script"),
109
+ links: z.object({
110
+ fontfile: z.string().url().optional().describe("a link to the font file published by the original author (not the mirror on the Linku Project's GitHub)"),
111
+ repo: z.string().url().optional().describe("a link to a web hosted repository of this font's source files (usually hosted on GitHub or GitLab)"),
112
+ webpage: z.string().url().optional().describe("a link to this font's home page, usually showcasing its features and usage/installation")
113
+ })
114
+ }).describe("Info on a font for Toki Pona");
115
+ const Words = z.record(z.string().min(1), Word.extend({ translations: z.record(z.string(), z.object({
116
+ commentary: CommentaryTranslation.valueType,
117
+ definition: DefinitionTranslation.valueType,
118
+ etymology: EtymologyTranslation.valueType,
119
+ sp_etymology: SitelenPonaTranslation.valueType
120
+ })) })).describe("A raw data object containing dictionary info about Toki Pona words");
121
+ const Signs = z.record(z.string().min(1), Sign.extend({ translations: z.record(z.string(), z.object({
122
+ parameters: ParametersTranslation.valueType,
123
+ icons: IconTranslation.valueType
124
+ })) })).describe("A raw data object containing information about Luka Pona signs");
125
+ const Fingerspelling = z.record(z.string().min(1), FingerspellingSign.extend({ translations: z.record(z.string(), z.object({ parameters: ParametersTranslation.valueType })) })).describe("A raw data object containing information about Luka Pona fingerspelling signs");
126
+ const Fonts = z.record(z.string(), Font).describe("A raw data object containing all the fonts data in sona");
127
+ const Languages = z.record(z.string().min(2).describe("The language code used by Crowdin. Approximates 2 letter code -> 3 letter code."), z.object({
128
+ id: z.string().min(2).describe("The language code used by Crowdin. Approximates 2 letter code -> 3 letter code."),
129
+ locale: z.string().describe("The locale code corresponding to the language."),
130
+ direction: z.union([z.literal("ltr"), z.literal("rtl")]).describe("The direction of the language's script."),
131
+ name: z.object({
132
+ en: z.string().describe("The name of the language in English."),
133
+ tok: z.string().optional().describe("The name of the language in Toki Pona."),
134
+ endonym: z.string().optional().describe("The name of the language in that language.")
135
+ })
136
+ }).describe("The languages offered by sona Linku."));
137
+
138
+ //#endregion
139
+ export { FingerspellingSign as a, IconTranslation as c, Sign as d, Signs as f, Words as h, Fingerspelling as i, Languages as l, Word as m, DefinitionTranslation as n, Font as o, SitelenPonaTranslation as p, EtymologyTranslation as r, Fonts as s, CommentaryTranslation as t, ParametersTranslation as u };
@@ -0,0 +1,267 @@
1
+ import { f as Signs, h as Words, i as Fingerspelling, l as Languages, s as Fonts } from "./v1-DkHVwPCI.js";
2
+ import { a as langIdCoalesce, i as keys, n as filterObject, o as langValidator, r as joinPath, s as mergeToKey } from "./utils-DkAaVBMs.js";
3
+ import { c as Languages$1, f as Words$1, i as Fonts$1, n as Fingerspellings, o as Glyphs, u as Signs$1 } from "./v2-CDtbJFxV.js";
4
+ import { Hono } from "hono";
5
+ import { z } from "zod/v4";
6
+ import { zValidator } from "@hono/zod-validator";
7
+ import { HTTPException } from "hono/http-exception";
8
+ import PLazy from "p-lazy";
9
+
10
+ //#region src/server/v2/index.ts
11
+ const API_VERSION$1 = "v2";
12
+ const config$1 = {
13
+ words: {
14
+ root: "/",
15
+ filename: "words.json",
16
+ schema: Words$1,
17
+ translations: true
18
+ },
19
+ glyphs: {
20
+ root: "/",
21
+ filename: "glyphs.json",
22
+ schema: Glyphs,
23
+ translations: true
24
+ },
25
+ sandbox_words: {
26
+ root: "sandbox/",
27
+ filename: "words.json",
28
+ schema: Words$1,
29
+ translations: true
30
+ },
31
+ sandbox_glyphs: {
32
+ root: "sandbox/",
33
+ filename: "glyphs.json",
34
+ schema: Glyphs,
35
+ translations: true
36
+ },
37
+ signs: {
38
+ root: "luka_pona/",
39
+ filename: "signs.json",
40
+ schema: Signs$1,
41
+ translations: true
42
+ },
43
+ fingerspellings: {
44
+ root: "luka_pona/",
45
+ filename: "fingerspellings.json",
46
+ schema: Fingerspellings,
47
+ translations: true
48
+ },
49
+ fonts: {
50
+ root: "/",
51
+ filename: "fonts.json",
52
+ schema: Fonts$1,
53
+ translations: false
54
+ },
55
+ languages: {
56
+ root: "/",
57
+ filename: "languages.json",
58
+ schema: Languages$1,
59
+ translations: false
60
+ }
61
+ };
62
+ let CACHE = {};
63
+ const fetchData = async (key, langcode = "en") => {
64
+ if (CACHE && CACHE[key] && CACHE[key][langcode]) return CACHE[key][langcode];
65
+ const file = await fetchFile(API_VERSION$1, config$1[key], langcode);
66
+ if (!file.success) throw new HTTPException(500, { message: z.prettifyError(file.error) });
67
+ CACHE[key] ??= {};
68
+ CACHE[key][langcode] = file.data;
69
+ return file.data;
70
+ };
71
+ const langParamtoLangcode = async (langParam) => {
72
+ if (!langParam) return "en";
73
+ return langIdCoalesce(langParam, await fetchData("languages"));
74
+ };
75
+ const datasetEndpoint = (key) => {
76
+ return async (c) => {
77
+ const data = await fetchData(key, await langParamtoLangcode(c.req.query("lang")));
78
+ return c.json(data, 200);
79
+ };
80
+ };
81
+ const singleItemEndpoint = (key, param, descriptor) => {
82
+ return async (c) => {
83
+ const data = await fetchData(key, await langParamtoLangcode(c.req.query("lang")));
84
+ const id = c.req.param(param);
85
+ const itemData = data[id];
86
+ return itemData ? c.json({
87
+ success: true,
88
+ data: itemData
89
+ }, 200) : c.json({
90
+ success: false,
91
+ message: `Could not find the ${descriptor} ${id}`
92
+ }, 400);
93
+ };
94
+ };
95
+ const app$1 = new Hono().get("/", (c) => c.redirect("/v2/words")).get("/words", langValidator, datasetEndpoint("words")).get("/words/:word", langValidator, zValidator("param", z.object({ word: z.string() })), singleItemEndpoint("words", "word", "word")).get("/glyphs", langValidator, datasetEndpoint("glyphs")).get("/glyphs/:glyph", langValidator, zValidator("param", z.object({ glyph: z.string() })), singleItemEndpoint("glyphs", "glyph", "glyph")).get("/sandbox", (c) => c.redirect("/v2/sandbox/words")).get("/sandbox/words", langValidator, datasetEndpoint("sandbox_words")).get("/sandbox/words/:word", langValidator, zValidator("param", z.object({ word: z.string() })), singleItemEndpoint("sandbox_words", "word", "sandbox word")).get("/sandbox/glyphs", langValidator, datasetEndpoint("sandbox_glyphs")).get("/sandbox/glyphs/:glyph", langValidator, zValidator("param", z.object({ glyph: z.string() })), singleItemEndpoint("sandbox_glyphs", "glyph", "sandbox glyph")).get("/luka_pona/signs", langValidator, datasetEndpoint("signs")).get("/luka_pona/signs/:sign", langValidator, zValidator("param", z.object({ sign: z.string() })), singleItemEndpoint("signs", "sign", "sign")).get("/luka_pona/fingerspellings", langValidator, datasetEndpoint("fingerspellings")).get("/luka_pona/fingerspellings/:fingerspelling", langValidator, zValidator("param", z.object({ sign: z.string() })), singleItemEndpoint("fingerspellings", "fingerspelling", "fingerspelling")).get("/fonts", datasetEndpoint("fonts")).get("/fonts/:font", zValidator("param", z.object({ font: z.string() })), singleItemEndpoint("fonts", "font", "font")).get("/languages", datasetEndpoint("languages")).get("/languages/:language", zValidator("param", z.object({ language: z.string() })), singleItemEndpoint("languages", "language", "language"));
96
+ var v2_default = app$1;
97
+
98
+ //#endregion
99
+ //#region src/server/versioning.ts
100
+ const IMPORT_ROOT = "/src/raw/";
101
+ const DATA = import.meta.glob("@raw/**/*.json", {
102
+ import: "default",
103
+ eager: true
104
+ });
105
+ const versions = {
106
+ v1: config,
107
+ v2: config$1
108
+ };
109
+ const apps = {
110
+ v1: v1_default,
111
+ v2: v2_default
112
+ };
113
+ const assertImport = async (imports, file, path) => {
114
+ if (!file) throw new Error(`Missing file: ${path}. Available: [${Object.keys(imports).slice(0, 10)}]`);
115
+ if (typeof file !== "object") console.error(`Unexpected file type for ${path}:`, typeof file, file);
116
+ };
117
+ const fetchFile = async (version, config$2, langcode = "en") => {
118
+ const { root = "/", filename, schema, translations = false } = config$2;
119
+ let path = "/" + joinPath(IMPORT_ROOT, version, root, filename);
120
+ let file = DATA[path];
121
+ await assertImport(DATA, file, path);
122
+ if (version === "v2" && translations === true) {
123
+ let translationPath = "/" + joinPath(IMPORT_ROOT, version, root, "translations", langcode, filename);
124
+ let translationFile = DATA[translationPath];
125
+ await assertImport(DATA, translationFile, translationPath);
126
+ file = mergeToKey(file, "translations", translationFile);
127
+ }
128
+ const parsed = await schema.safeParseAsync(file);
129
+ if (!parsed.success) throw new Error(`Invalid input in ${filename}: ${parsed.error.message}`);
130
+ return parsed;
131
+ };
132
+
133
+ //#endregion
134
+ //#region src/server/v1/index.ts
135
+ const API_VERSION = "v1";
136
+ const config = {
137
+ words: {
138
+ filename: "words.json",
139
+ schema: Words
140
+ },
141
+ sandbox: {
142
+ filename: "sandbox.json",
143
+ schema: Words
144
+ },
145
+ fingerspellings: {
146
+ filename: "fingerspelling.json",
147
+ schema: Fingerspelling
148
+ },
149
+ signs: {
150
+ filename: "signs.json",
151
+ schema: Signs
152
+ },
153
+ fonts: {
154
+ filename: "fonts.json",
155
+ schema: Fonts
156
+ },
157
+ languages: {
158
+ filename: "languages.json",
159
+ schema: Languages
160
+ }
161
+ };
162
+ const rawData = PLazy.from(async () => {
163
+ const res = {};
164
+ for (const key of keys(config)) {
165
+ const file = await fetchFile(API_VERSION, config[key]);
166
+ if (!file.success) throw new HTTPException(500, { message: z.prettifyError(file.error) });
167
+ res[key] = file.data;
168
+ }
169
+ return res;
170
+ });
171
+ const languagesFilter = (nested) => async (c, next) => {
172
+ await next();
173
+ const body = await c.res.clone().json();
174
+ if ("ok" in body && body.ok === false) return body;
175
+ const requestedLanguages = c.req.query("lang")?.split(",") ?? ["en"];
176
+ if (requestedLanguages.length === 1 && requestedLanguages[0] === "*") return;
177
+ const languages = (await rawData).languages;
178
+ const mappedLangs = requestedLanguages.map((lang) => langIdCoalesce(lang, languages));
179
+ if (mappedLangs.includes(void 0)) throw new HTTPException(400, { message: `Cannot find one or more of the requested languages: ${requestedLanguages.join(", ")}` });
180
+ if (nested) c.res = new Response(JSON.stringify(Object.fromEntries(Object.entries(body).filter((e) => typeof e[1] === "object" && !!e[1] && "translations" in e[1] && typeof e[1]["translations"] === "object").map(([k, v]) => {
181
+ return [k, {
182
+ ...v,
183
+ translations: filterObject(v["translations"], ([k$1]) => mappedLangs.includes(k$1))
184
+ }];
185
+ }))), c.res);
186
+ else c.res = new Response(JSON.stringify({
187
+ ...body.data,
188
+ translations: filterObject(body.data["translations"], ([k]) => mappedLangs.includes(k.toString()))
189
+ }), c.res);
190
+ };
191
+ const app = new Hono().get("/", (c) => c.redirect("/v1/words")).get("/words", langValidator, languagesFilter(true), async (c) => {
192
+ const data = (await rawData).words;
193
+ return c.json(data, 200);
194
+ }).get("/words/:word", langValidator, zValidator("param", z.object({ word: z.string() })), languagesFilter(false), async (c) => {
195
+ const word = (await rawData).words[c.req.param("word")];
196
+ return word ? c.json({
197
+ ok: true,
198
+ data: word
199
+ }, 200) : c.json({
200
+ ok: false,
201
+ message: `Could not find the word ${c.req.param("word")}`
202
+ }, 400);
203
+ }).get("/sandbox", langValidator, languagesFilter(true), async (c) => {
204
+ const data = (await rawData).sandbox;
205
+ return c.json(data, 200);
206
+ }).get("/sandbox/:word", langValidator, zValidator("param", z.object({ word: z.string() })), languagesFilter(false), async (c) => {
207
+ const word = (await rawData).sandbox[c.req.param("word")];
208
+ return word ? c.json({
209
+ ok: true,
210
+ data: word
211
+ }, 200) : c.json({
212
+ ok: false,
213
+ message: `Could not find the sandbox word "${c.req.param("word")}"`
214
+ }, 400);
215
+ }).get("/luka_pona", (c) => {
216
+ return c.redirect("/v1/luka_pona/signs");
217
+ }).get("/luka_pona/fingerspelling", langValidator, languagesFilter(true), async (c) => {
218
+ return c.json((await rawData).fingerspellings, 200);
219
+ }).get("/luka_pona/fingerspelling/:sign", langValidator, zValidator("param", z.object({ sign: z.string() })), languagesFilter(true), async (c) => {
220
+ const sign = (await rawData).fingerspellings[c.req.param("sign")];
221
+ return sign ? c.json({
222
+ ok: true,
223
+ data: sign
224
+ }, 200) : c.json({
225
+ ok: false,
226
+ message: `Could not find a sign named ${sign}`
227
+ }, 400);
228
+ }).get("/luka_pona/signs", langValidator, languagesFilter(true), async (c) => {
229
+ return c.json((await rawData).signs, 200);
230
+ }).get("/luka_pona/signs/:sign", langValidator, zValidator("param", z.object({ sign: z.string() })), languagesFilter(true), async (c) => {
231
+ const sign = (await rawData).signs[c.req.param("sign")];
232
+ return sign ? c.json({
233
+ ok: true,
234
+ data: sign
235
+ }, 200) : c.json({
236
+ ok: false,
237
+ message: `Could not find a sign named ${sign}`
238
+ }, 400);
239
+ }).get("/fonts", async (c) => {
240
+ return c.json((await rawData).fonts, 200);
241
+ }).get("/fonts/:font", zValidator("param", z.object({ font: z.string() })), async (c) => {
242
+ const font = (await rawData).fonts[c.req.param("font")];
243
+ return font ? c.json({
244
+ ok: true,
245
+ data: font
246
+ }, 200) : c.json({
247
+ ok: false,
248
+ message: `Could not find a font named ${font}`
249
+ }, 400);
250
+ }).get("/languages", async (c) => {
251
+ return c.json((await rawData).languages, 200);
252
+ }).get("/languages/:language", zValidator("param", z.object({ language: z.string() })), async (c) => {
253
+ const language = c.req.param("language");
254
+ const languages = (await rawData).languages;
255
+ const langId = langIdCoalesce(language, languages);
256
+ return langId ? c.json({
257
+ ok: true,
258
+ data: languages[langId]
259
+ }, 200) : c.json({
260
+ ok: false,
261
+ message: `Could not find a language named ${language}`
262
+ }, 400);
263
+ });
264
+ var v1_default = app;
265
+
266
+ //#endregion
267
+ export { fetchFile as a, fetchData as c, apps as i, v2_default as l, languagesFilter as n, versions as o, v1_default as r, config$1 as s, config as t };