@noy-db/hub 0.2.0-pre.30 → 0.2.0-pre.31
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.
- package/dist/adapter/index.d.ts +9 -0
- package/dist/adapter/index.js +14 -0
- package/dist/attestation/index.d.ts +1 -1
- package/dist/attestation/index.js +3 -3
- package/dist/blobs/index.d.ts +3 -3
- package/dist/bundle/index.d.ts +3 -3
- package/dist/bundle/index.js +1 -1
- package/dist/{chunk-Y6YUWZTS.js → chunk-L5HHBOMS.js} +2 -2
- package/dist/{chunk-BVKLJBJJ.js → chunk-W5NVNJDX.js} +2 -1
- package/dist/{chunk-BVKLJBJJ.js.map → chunk-W5NVNJDX.js.map} +1 -1
- package/dist/consent/index.d.ts +2 -2
- package/dist/{decrypt-partition-Mhjh6nnG.d.ts → decrypt-partition-CXS5KopB.d.ts} +1 -1
- package/dist/derivations/index.d.ts +3 -3
- package/dist/{dev-unlock-DJ3IhgY9.d.ts → dev-unlock-CnHTTVea.d.ts} +1 -1
- package/dist/guards/index.d.ts +3 -3
- package/dist/{hash-DLwkYf1d.d.ts → hash-oc5paYl0.d.ts} +1 -1
- package/dist/history/index.d.ts +3 -3
- package/dist/i18n/index.d.ts +2 -2
- package/dist/{index-CMRIx_zx.d.ts → index-BmhGztUi.d.ts} +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +2 -2
- package/dist/kernel/index.d.ts +2 -2
- package/dist/materialized-views/index.d.ts +3 -3
- package/dist/{mime-magic-CacDBwYp.d.ts → mime-magic-JeLKHRng.d.ts} +1 -1
- package/dist/{noydb-5MIBD77B.js → noydb-NAU2DTFP.js} +2 -2
- package/dist/noydb-NAU2DTFP.js.map +1 -0
- package/dist/overlay-views/index.d.ts +3 -3
- package/dist/periods/index.d.ts +2 -2
- package/dist/session/index.d.ts +3 -3
- package/dist/shadow/index.d.ts +2 -2
- package/dist/snapshots/index.d.ts +2 -2
- package/dist/store/index.d.ts +2 -2
- package/dist/sync/index.d.ts +1 -1
- package/dist/team/index.d.ts +2 -2
- package/dist/{transition-guard-J04-jime.d.ts → transition-guard-Dy3NioQr.d.ts} +1 -1
- package/dist/tx/index.d.ts +2 -2
- package/dist/{with-materialized-view-DNfzC5lH.d.ts → with-materialized-view-DIVeez0W.d.ts} +1 -1
- package/dist/{with-overlayed-view-qk3lbhOd.d.ts → with-overlayed-view-DVZrc5Hb.d.ts} +1 -1
- package/dist/{with-rollup-Dd3_ZG4b.d.ts → with-rollup-CbU-O4wP.d.ts} +1 -1
- package/package.json +62 -221
- package/dist/aggregate/index.cjs +0 -1144
- package/dist/aggregate/index.cjs.map +0 -1
- package/dist/aggregate/index.d.cts +0 -39
- package/dist/attestation/index.cjs +0 -305
- package/dist/attestation/index.cjs.map +0 -1
- package/dist/attestation/index.d.cts +0 -54
- package/dist/blobs/index.cjs +0 -1967
- package/dist/blobs/index.cjs.map +0 -1
- package/dist/blobs/index.d.cts +0 -48
- package/dist/bundle/index.cjs +0 -41045
- package/dist/bundle/index.cjs.map +0 -1
- package/dist/bundle/index.d.cts +0 -187
- package/dist/consent/index.cjs +0 -204
- package/dist/consent/index.cjs.map +0 -1
- package/dist/consent/index.d.cts +0 -27
- package/dist/crdt/index.cjs +0 -152
- package/dist/crdt/index.cjs.map +0 -1
- package/dist/crdt/index.d.cts +0 -30
- package/dist/decrypt-partition-C0iDpbSd.d.cts +0 -558
- package/dist/derivations/index.cjs +0 -469
- package/dist/derivations/index.cjs.map +0 -1
- package/dist/derivations/index.d.cts +0 -74
- package/dist/dev-unlock-0Z6yxfS7.d.cts +0 -263
- package/dist/discriminant-BN9REW3o.d.cts +0 -60
- package/dist/errors-BAWO5Z5a.d.cts +0 -1500
- package/dist/forget/index.cjs +0 -43
- package/dist/forget/index.cjs.map +0 -1
- package/dist/forget/index.d.cts +0 -1
- package/dist/guards/index.cjs +0 -455
- package/dist/guards/index.cjs.map +0 -1
- package/dist/guards/index.d.cts +0 -39
- package/dist/hash-Db8ncXGr.d.cts +0 -63
- package/dist/history/index.cjs +0 -1245
- package/dist/history/index.cjs.map +0 -1
- package/dist/history/index.d.cts +0 -65
- package/dist/i18n/index.cjs +0 -1280
- package/dist/i18n/index.cjs.map +0 -1
- package/dist/i18n/index.d.cts +0 -41
- package/dist/index-BMmajblo.d.cts +0 -362
- package/dist/index-C1SC1EPe.d.cts +0 -1325
- package/dist/index-xJEPkvMb.d.cts +0 -93
- package/dist/index.cjs +0 -48100
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1050
- package/dist/indexing/index.cjs +0 -803
- package/dist/indexing/index.cjs.map +0 -1
- package/dist/indexing/index.d.cts +0 -36
- package/dist/kernel/index.cjs +0 -751
- package/dist/kernel/index.cjs.map +0 -1
- package/dist/kernel/index.d.cts +0 -11
- package/dist/lazy-builder-eYZzLEL1.d.cts +0 -304
- package/dist/materialized-views/index.cjs +0 -1518
- package/dist/materialized-views/index.cjs.map +0 -1
- package/dist/materialized-views/index.d.cts +0 -187
- package/dist/mime-magic-sdMzsfVK.d.cts +0 -103
- package/dist/overlay-views/index.cjs +0 -399
- package/dist/overlay-views/index.cjs.map +0 -1
- package/dist/overlay-views/index.d.cts +0 -102
- package/dist/periods/index.cjs +0 -1041
- package/dist/periods/index.cjs.map +0 -1
- package/dist/periods/index.d.cts +0 -24
- package/dist/predicate-BmhBSPCH.d.cts +0 -267
- package/dist/query/index.cjs +0 -3480
- package/dist/query/index.cjs.map +0 -1
- package/dist/query/index.d.cts +0 -4
- package/dist/sealed-record/index.cjs +0 -139
- package/dist/sealed-record/index.cjs.map +0 -1
- package/dist/sealed-record/index.d.cts +0 -123
- package/dist/session/index.cjs +0 -495
- package/dist/session/index.cjs.map +0 -1
- package/dist/session/index.d.cts +0 -48
- package/dist/shadow/index.cjs +0 -133
- package/dist/shadow/index.cjs.map +0 -1
- package/dist/shadow/index.d.cts +0 -19
- package/dist/snapshots/index.cjs +0 -937
- package/dist/snapshots/index.cjs.map +0 -1
- package/dist/snapshots/index.d.cts +0 -30
- package/dist/store/index.cjs +0 -1091
- package/dist/store/index.cjs.map +0 -1
- package/dist/store/index.d.cts +0 -501
- package/dist/strategy-BSxFXGzb.d.cts +0 -110
- package/dist/strategy-mJExw4LQ.d.cts +0 -1069
- package/dist/sync/index.cjs +0 -1062
- package/dist/sync/index.cjs.map +0 -1
- package/dist/sync/index.d.cts +0 -45
- package/dist/team/index.cjs +0 -2805
- package/dist/team/index.cjs.map +0 -1
- package/dist/team/index.d.cts +0 -120
- package/dist/transition-guard-tWZIsaXe.d.cts +0 -165
- package/dist/tx/index.cjs +0 -614
- package/dist/tx/index.cjs.map +0 -1
- package/dist/tx/index.d.cts +0 -39
- package/dist/types-CdVfiQgt.d.cts +0 -15275
- package/dist/ulid-DRH25k3y.d.cts +0 -66
- package/dist/util/index.cjs +0 -237
- package/dist/util/index.cjs.map +0 -1
- package/dist/util/index.d.cts +0 -79
- package/dist/with-materialized-view-DfgPcvi9.d.cts +0 -27
- package/dist/with-overlayed-view-Cvfkx1lg.d.cts +0 -13
- package/dist/with-rollup-nIxo7h9z.d.cts +0 -47
- /package/dist/{noydb-5MIBD77B.js.map → adapter/index.js.map} +0 -0
- /package/dist/{chunk-Y6YUWZTS.js.map → chunk-L5HHBOMS.js.map} +0 -0
- /package/dist/{types-DHn9lEP0.d.ts → index-DHn9lEP0.d.ts} +0 -0
package/dist/i18n/index.cjs
DELETED
|
@@ -1,1280 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/i18n/index.ts
|
|
21
|
-
var i18n_exports = {};
|
|
22
|
-
__export(i18n_exports, {
|
|
23
|
-
DICT_COLLECTION_PREFIX: () => DICT_COLLECTION_PREFIX,
|
|
24
|
-
DictKeyInUseError: () => DictKeyInUseError,
|
|
25
|
-
DictKeyMissingError: () => DictKeyMissingError,
|
|
26
|
-
DictionaryHandle: () => DictionaryHandle,
|
|
27
|
-
LocaleNotSpecifiedError: () => LocaleNotSpecifiedError,
|
|
28
|
-
MissingTranslationError: () => MissingTranslationError,
|
|
29
|
-
ReservedCollectionNameError: () => ReservedCollectionNameError,
|
|
30
|
-
ScriptViolationError: () => ScriptViolationError,
|
|
31
|
-
StaticDictReadonlyError: () => StaticDictReadonlyError,
|
|
32
|
-
TranslatorNotConfiguredError: () => TranslatorNotConfiguredError,
|
|
33
|
-
UnknownDictCodeError: () => UnknownDictCodeError,
|
|
34
|
-
applyI18nLocale: () => applyI18nLocale,
|
|
35
|
-
dictCollectionName: () => dictCollectionName,
|
|
36
|
-
dictKey: () => dictKey,
|
|
37
|
-
enforceScript: () => enforceScript,
|
|
38
|
-
getAtPath: () => getAtPath,
|
|
39
|
-
i18nText: () => i18nText,
|
|
40
|
-
inferScripts: () => inferScripts,
|
|
41
|
-
isDictCollectionName: () => isDictCollectionName,
|
|
42
|
-
isDictKeyDescriptor: () => isDictKeyDescriptor,
|
|
43
|
-
isI18nTextDescriptor: () => isI18nTextDescriptor,
|
|
44
|
-
isStaticDictDescriptor: () => isStaticDictDescriptor,
|
|
45
|
-
resolveI18nText: () => resolveI18nText,
|
|
46
|
-
resolvePolicy: () => resolvePolicy,
|
|
47
|
-
setAtPathInPlace: () => setAtPathInPlace,
|
|
48
|
-
staticDict: () => staticDict,
|
|
49
|
-
stripI18nFilled: () => stripI18nFilled,
|
|
50
|
-
validateI18nTextValue: () => validateI18nTextValue,
|
|
51
|
-
withI18n: () => withI18n
|
|
52
|
-
});
|
|
53
|
-
module.exports = __toCommonJS(i18n_exports);
|
|
54
|
-
|
|
55
|
-
// src/errors.ts
|
|
56
|
-
var NoydbError = class extends Error {
|
|
57
|
-
/** Machine-readable error code. Stable across library versions. */
|
|
58
|
-
code;
|
|
59
|
-
constructor(code, message) {
|
|
60
|
-
super(message);
|
|
61
|
-
this.name = "NoydbError";
|
|
62
|
-
this.code = code;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var DecryptionError = class extends NoydbError {
|
|
66
|
-
constructor(message = "Decryption failed") {
|
|
67
|
-
super("DECRYPTION_FAILED", message);
|
|
68
|
-
this.name = "DecryptionError";
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
var TamperedError = class extends NoydbError {
|
|
72
|
-
constructor(message = "Data integrity check failed \u2014 record may have been tampered with") {
|
|
73
|
-
super("TAMPERED", message);
|
|
74
|
-
this.name = "TamperedError";
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
var PermissionDeniedError = class extends NoydbError {
|
|
78
|
-
constructor(message = "Permission denied \u2014 insufficient role for this operation") {
|
|
79
|
-
super("PERMISSION_DENIED", message);
|
|
80
|
-
this.name = "PermissionDeniedError";
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var ValidationError = class extends NoydbError {
|
|
84
|
-
constructor(message = "Validation error") {
|
|
85
|
-
super("VALIDATION_ERROR", message);
|
|
86
|
-
this.name = "ValidationError";
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
var ReservedCollectionNameError = class extends NoydbError {
|
|
90
|
-
/** The rejected collection name. */
|
|
91
|
-
collectionName;
|
|
92
|
-
constructor(collectionName) {
|
|
93
|
-
super(
|
|
94
|
-
"RESERVED_COLLECTION_NAME",
|
|
95
|
-
`"${collectionName}" is a reserved collection name. Use vault.dictionary("${collectionName.replace(/^_dict_/, "")}") to access dictionary collections.`
|
|
96
|
-
);
|
|
97
|
-
this.name = "ReservedCollectionNameError";
|
|
98
|
-
this.collectionName = collectionName;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
var DictKeyMissingError = class extends NoydbError {
|
|
102
|
-
/** The dictionary name. */
|
|
103
|
-
dictionaryName;
|
|
104
|
-
/** The key that was not found. */
|
|
105
|
-
key;
|
|
106
|
-
constructor(dictionaryName, key) {
|
|
107
|
-
super(
|
|
108
|
-
"DICT_KEY_MISSING",
|
|
109
|
-
`Dictionary "${dictionaryName}" has no entry for key "${key}".`
|
|
110
|
-
);
|
|
111
|
-
this.name = "DictKeyMissingError";
|
|
112
|
-
this.dictionaryName = dictionaryName;
|
|
113
|
-
this.key = key;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
var DictKeyInUseError = class extends NoydbError {
|
|
117
|
-
/** The dictionary name. */
|
|
118
|
-
dictionaryName;
|
|
119
|
-
/** The key that is still referenced. */
|
|
120
|
-
key;
|
|
121
|
-
/** Name of the first collection found to reference this key. */
|
|
122
|
-
usedBy;
|
|
123
|
-
/** Number of records in `usedBy` that reference this key. */
|
|
124
|
-
count;
|
|
125
|
-
constructor(dictionaryName, key, usedBy, count) {
|
|
126
|
-
super(
|
|
127
|
-
"DICT_KEY_IN_USE",
|
|
128
|
-
`Cannot delete key "${key}" from dictionary "${dictionaryName}": ${count} record(s) in "${usedBy}" still reference it. Use dictionary.rename("${key}", newKey) to rewrite references first.`
|
|
129
|
-
);
|
|
130
|
-
this.name = "DictKeyInUseError";
|
|
131
|
-
this.dictionaryName = dictionaryName;
|
|
132
|
-
this.key = key;
|
|
133
|
-
this.usedBy = usedBy;
|
|
134
|
-
this.count = count;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var MissingTranslationError = class extends NoydbError {
|
|
138
|
-
/** The field name whose translation(s) are missing. */
|
|
139
|
-
field;
|
|
140
|
-
/** Locale codes that were required but absent. */
|
|
141
|
-
missing;
|
|
142
|
-
constructor(field, missing, message) {
|
|
143
|
-
super(
|
|
144
|
-
"MISSING_TRANSLATION",
|
|
145
|
-
message ?? `Field "${field}": missing required translation(s): ${missing.join(", ")}.`
|
|
146
|
-
);
|
|
147
|
-
this.name = "MissingTranslationError";
|
|
148
|
-
this.field = field;
|
|
149
|
-
this.missing = missing;
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
var LocaleNotSpecifiedError = class extends NoydbError {
|
|
153
|
-
/** The field name that required a locale. */
|
|
154
|
-
field;
|
|
155
|
-
constructor(field, message) {
|
|
156
|
-
super(
|
|
157
|
-
"LOCALE_NOT_SPECIFIED",
|
|
158
|
-
message ?? `Cannot read i18nText field "${field}" without a locale. Pass { locale } to get()/list()/query() or set a default via openVault(name, { locale }).`
|
|
159
|
-
);
|
|
160
|
-
this.name = "LocaleNotSpecifiedError";
|
|
161
|
-
this.field = field;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
var ScriptViolationError = class extends NoydbError {
|
|
165
|
-
/** The field whose value violated its script constraint. */
|
|
166
|
-
field;
|
|
167
|
-
/** The locale slot (e.g. `'en'`) that was checked. */
|
|
168
|
-
locale;
|
|
169
|
-
/** The Unicode scripts allowed for this slot. */
|
|
170
|
-
expected;
|
|
171
|
-
/** A short sample of the offending characters, for diagnostics. */
|
|
172
|
-
sample;
|
|
173
|
-
constructor(field, locale, expected, sample, message) {
|
|
174
|
-
super(
|
|
175
|
-
"SCRIPT_VIOLATION",
|
|
176
|
-
message ?? `Field "${field}" slot "${locale}" expects script(s) [${expected.join(", ")}] but contains disallowed character(s): "${sample}".`
|
|
177
|
-
);
|
|
178
|
-
this.name = "ScriptViolationError";
|
|
179
|
-
this.field = field;
|
|
180
|
-
this.locale = locale;
|
|
181
|
-
this.expected = expected;
|
|
182
|
-
this.sample = sample;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
var StaticDictReadonlyError = class extends NoydbError {
|
|
186
|
-
/** The static dictionary name that was the target of the mutation. */
|
|
187
|
-
dictionaryName;
|
|
188
|
-
constructor(dictionaryName) {
|
|
189
|
-
super(
|
|
190
|
-
"STATIC_DICT_READONLY",
|
|
191
|
-
`Dictionary "${dictionaryName}" is a staticDict \u2014 its labels are code constants with no mutation surface. put/putAll/rename/delete are not supported; change the label in the staticDict() table and redeploy.`
|
|
192
|
-
);
|
|
193
|
-
this.name = "StaticDictReadonlyError";
|
|
194
|
-
this.dictionaryName = dictionaryName;
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
var UnknownDictCodeError = class extends NoydbError {
|
|
198
|
-
/** The static dictionary name. */
|
|
199
|
-
dictionaryName;
|
|
200
|
-
/** The field that carried the unknown code. */
|
|
201
|
-
field;
|
|
202
|
-
/** The offending code value. */
|
|
203
|
-
code;
|
|
204
|
-
constructor(dictionaryName, field, code) {
|
|
205
|
-
super(
|
|
206
|
-
"UNKNOWN_DICT_CODE",
|
|
207
|
-
`Field "${field}": code "${code}" is not a known key of staticDict "${dictionaryName}". Use a declared code, or pass { validateCodes: false } on the descriptor to allow open codes.`
|
|
208
|
-
);
|
|
209
|
-
this.name = "UnknownDictCodeError";
|
|
210
|
-
this.dictionaryName = dictionaryName;
|
|
211
|
-
this.field = field;
|
|
212
|
-
this.code = code;
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
var TranslatorNotConfiguredError = class extends NoydbError {
|
|
216
|
-
/** The field that requested auto-translation. */
|
|
217
|
-
field;
|
|
218
|
-
/** The collection the put was targeting. */
|
|
219
|
-
collection;
|
|
220
|
-
constructor(field, collection) {
|
|
221
|
-
super(
|
|
222
|
-
"TRANSLATOR_NOT_CONFIGURED",
|
|
223
|
-
`Field "${field}" in collection "${collection}" has autoTranslate: true, but no plaintextTranslator was configured on createNoydb(). Either configure a plaintextTranslator or remove autoTranslate from the schema.`
|
|
224
|
-
);
|
|
225
|
-
this.name = "TranslatorNotConfiguredError";
|
|
226
|
-
this.field = field;
|
|
227
|
-
this.collection = collection;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
// src/i18n/policy.ts
|
|
232
|
-
function resolvePolicy(onMissing, layer) {
|
|
233
|
-
const explicit = onMissing && typeof onMissing === "object" ? onMissing[layer] : void 0;
|
|
234
|
-
const scalar = typeof onMissing === "string" ? onMissing : void 0;
|
|
235
|
-
const layerDefault = layer === "guard" ? "substitute" : void 0;
|
|
236
|
-
return explicit ?? layerDefault ?? scalar ?? "throw";
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// src/i18n/script.ts
|
|
240
|
-
var LATIN_BASE = /* @__PURE__ */ new Set([
|
|
241
|
-
"en",
|
|
242
|
-
"fr",
|
|
243
|
-
"de",
|
|
244
|
-
"es",
|
|
245
|
-
"it",
|
|
246
|
-
"pt",
|
|
247
|
-
"nl",
|
|
248
|
-
"sv",
|
|
249
|
-
"no",
|
|
250
|
-
"da",
|
|
251
|
-
"fi",
|
|
252
|
-
"is",
|
|
253
|
-
"pl",
|
|
254
|
-
"cs",
|
|
255
|
-
"sk",
|
|
256
|
-
"hu",
|
|
257
|
-
"ro",
|
|
258
|
-
"hr",
|
|
259
|
-
"sl",
|
|
260
|
-
"et",
|
|
261
|
-
"lv",
|
|
262
|
-
"lt",
|
|
263
|
-
"tr",
|
|
264
|
-
"vi",
|
|
265
|
-
"id",
|
|
266
|
-
"ms",
|
|
267
|
-
"tl",
|
|
268
|
-
"sw",
|
|
269
|
-
"af",
|
|
270
|
-
"ca",
|
|
271
|
-
"gl",
|
|
272
|
-
"eu",
|
|
273
|
-
"cy",
|
|
274
|
-
"ga"
|
|
275
|
-
]);
|
|
276
|
-
var SCRIPT_TABLE = {
|
|
277
|
-
th: ["Thai"],
|
|
278
|
-
ko: ["Hangul", "Han"],
|
|
279
|
-
ja: ["Han", "Hiragana", "Katakana"],
|
|
280
|
-
zh: ["Han"],
|
|
281
|
-
ar: ["Arabic"],
|
|
282
|
-
fa: ["Arabic"],
|
|
283
|
-
ur: ["Arabic"],
|
|
284
|
-
ru: ["Cyrillic"],
|
|
285
|
-
uk: ["Cyrillic"],
|
|
286
|
-
bg: ["Cyrillic"],
|
|
287
|
-
sr: ["Cyrillic"],
|
|
288
|
-
he: ["Hebrew"],
|
|
289
|
-
el: ["Greek"],
|
|
290
|
-
hi: ["Devanagari"],
|
|
291
|
-
ta: ["Tamil"],
|
|
292
|
-
km: ["Khmer"],
|
|
293
|
-
lo: ["Lao"],
|
|
294
|
-
my: ["Myanmar"]
|
|
295
|
-
};
|
|
296
|
-
var SUBTAG_SCRIPTS = {
|
|
297
|
-
Latn: ["Latin"],
|
|
298
|
-
Cyrl: ["Cyrillic", "Latin"],
|
|
299
|
-
Hans: ["Han", "Latin"],
|
|
300
|
-
Hant: ["Han", "Latin"],
|
|
301
|
-
Thai: ["Thai", "Latin"],
|
|
302
|
-
Arab: ["Arabic", "Latin"]
|
|
303
|
-
};
|
|
304
|
-
function inferScripts(locale) {
|
|
305
|
-
const parts = locale.split("-");
|
|
306
|
-
const subtag = parts.find((t) => /^[A-Z][a-z]{3}$/.test(t));
|
|
307
|
-
if (subtag && SUBTAG_SCRIPTS[subtag]) return SUBTAG_SCRIPTS[subtag];
|
|
308
|
-
const base = (parts[0] ?? "").toLowerCase();
|
|
309
|
-
if (LATIN_BASE.has(base)) return ["Latin"];
|
|
310
|
-
const primary = SCRIPT_TABLE[base];
|
|
311
|
-
if (primary) return [...primary, "Latin"];
|
|
312
|
-
return ["Latin"];
|
|
313
|
-
}
|
|
314
|
-
function allowedFor(descriptor, locale) {
|
|
315
|
-
const script = descriptor.options.script;
|
|
316
|
-
if (script && script !== "auto") {
|
|
317
|
-
const explicit = script[locale];
|
|
318
|
-
if (explicit) return explicit;
|
|
319
|
-
}
|
|
320
|
-
return inferScripts(locale);
|
|
321
|
-
}
|
|
322
|
-
var BASELINE = String.raw`\p{White_Space}\p{Script=Common}\p{Script=Inherited}\p{Mark}`;
|
|
323
|
-
function fullMatcher(scripts) {
|
|
324
|
-
const cls = scripts.map((s) => `\\p{Script=${s}}`).join("");
|
|
325
|
-
return new RegExp(`^[${BASELINE}${cls}]*$`, "u");
|
|
326
|
-
}
|
|
327
|
-
function charMatcher(scripts) {
|
|
328
|
-
const cls = scripts.map((s) => `\\p{Script=${s}}`).join("");
|
|
329
|
-
return new RegExp(`[${BASELINE}${cls}]`, "u");
|
|
330
|
-
}
|
|
331
|
-
function offendingSample(str, scripts) {
|
|
332
|
-
const ok = charMatcher(scripts);
|
|
333
|
-
const bad = [];
|
|
334
|
-
for (const ch of str) {
|
|
335
|
-
if (!ok.test(ch)) bad.push(ch);
|
|
336
|
-
if (bad.length >= 8) break;
|
|
337
|
-
}
|
|
338
|
-
return bad.join("");
|
|
339
|
-
}
|
|
340
|
-
function stripDisallowed(str, scripts) {
|
|
341
|
-
const ok = charMatcher(scripts);
|
|
342
|
-
let out = "";
|
|
343
|
-
for (const ch of str) if (ok.test(ch)) out += ch;
|
|
344
|
-
return out;
|
|
345
|
-
}
|
|
346
|
-
function enforceScript(value, field, descriptor, exempt) {
|
|
347
|
-
const opt = descriptor.options;
|
|
348
|
-
if (!opt.script) return { value, warnings: [] };
|
|
349
|
-
const mode = opt.onScriptViolation ?? "reject";
|
|
350
|
-
const warnings = [];
|
|
351
|
-
let out = value;
|
|
352
|
-
for (const [locale, raw] of Object.entries(value)) {
|
|
353
|
-
if (exempt?.has(locale)) continue;
|
|
354
|
-
if (typeof raw !== "string") continue;
|
|
355
|
-
const allowed = allowedFor(descriptor, locale);
|
|
356
|
-
if (fullMatcher(allowed).test(raw)) continue;
|
|
357
|
-
const sample = offendingSample(raw, allowed);
|
|
358
|
-
if (mode === "reject") {
|
|
359
|
-
throw new ScriptViolationError(field, locale, allowed, sample);
|
|
360
|
-
}
|
|
361
|
-
warnings.push({ field, locale, expected: allowed, sample });
|
|
362
|
-
if (mode === "filter") {
|
|
363
|
-
if (out === value) out = { ...value };
|
|
364
|
-
out[locale] = stripDisallowed(raw, allowed);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return { value: out, warnings };
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// src/i18n/core.ts
|
|
371
|
-
function i18nText(options) {
|
|
372
|
-
if (options.densifyOnWrite === true && hasThrowPolicy(options.onMissing)) {
|
|
373
|
-
throw new Error(
|
|
374
|
-
`i18nText: densifyOnWrite cannot be combined with an explicit onMissing 'throw' policy \u2014 densify fills every empty slot, so a 'throw' would be unreachable. Remove the 'throw' policy or disable densifyOnWrite.`
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
return { _noydbI18nText: true, options };
|
|
378
|
-
}
|
|
379
|
-
function hasThrowPolicy(onMissing) {
|
|
380
|
-
if (onMissing === void 0) return false;
|
|
381
|
-
if (typeof onMissing === "string") return onMissing === "throw";
|
|
382
|
-
return Object.values(onMissing).includes("throw");
|
|
383
|
-
}
|
|
384
|
-
function isI18nTextDescriptor(x) {
|
|
385
|
-
return typeof x === "object" && x !== null && x._noydbI18nText === true;
|
|
386
|
-
}
|
|
387
|
-
function validateI18nTextValue(value, field, descriptor) {
|
|
388
|
-
const { options } = descriptor;
|
|
389
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
390
|
-
throw new MissingTranslationError(
|
|
391
|
-
field,
|
|
392
|
-
options.languages,
|
|
393
|
-
`Field "${field}" must be a { [locale]: string } map, got ${typeof value}.`
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
const map = value;
|
|
397
|
-
for (const [locale, v] of Object.entries(map)) {
|
|
398
|
-
if (typeof v !== "string") {
|
|
399
|
-
throw new MissingTranslationError(
|
|
400
|
-
field,
|
|
401
|
-
[locale],
|
|
402
|
-
`Field "${field}": locale "${locale}" must be a string, got ${typeof v}.`
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
const { required } = options;
|
|
407
|
-
if (required === "all") {
|
|
408
|
-
const missing = options.languages.filter(
|
|
409
|
-
(lang) => !(lang in map) || map[lang] === ""
|
|
410
|
-
);
|
|
411
|
-
if (missing.length > 0) {
|
|
412
|
-
throw new MissingTranslationError(
|
|
413
|
-
field,
|
|
414
|
-
missing,
|
|
415
|
-
`Field "${field}" requires all declared languages. Missing: ${missing.join(", ")}.`
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
} else if (required === "any") {
|
|
419
|
-
const present = options.languages.some(
|
|
420
|
-
(lang) => lang in map && map[lang] !== ""
|
|
421
|
-
);
|
|
422
|
-
if (!present) {
|
|
423
|
-
throw new MissingTranslationError(
|
|
424
|
-
field,
|
|
425
|
-
options.languages,
|
|
426
|
-
`Field "${field}" requires at least one declared language. None present.`
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
} else {
|
|
430
|
-
const requiredList = required;
|
|
431
|
-
const missing = requiredList.filter(
|
|
432
|
-
(lang) => !(lang in map) || map[lang] === ""
|
|
433
|
-
);
|
|
434
|
-
if (missing.length > 0) {
|
|
435
|
-
throw new MissingTranslationError(
|
|
436
|
-
field,
|
|
437
|
-
missing,
|
|
438
|
-
`Field "${field}" requires: ${requiredList.join(", ")}. Missing: ${missing.join(", ")}.`
|
|
439
|
-
);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
function toChain(fallback) {
|
|
444
|
-
return Array.isArray(fallback) ? fallback : fallback ? [fallback] : [];
|
|
445
|
-
}
|
|
446
|
-
function pickFromChain(value, chain) {
|
|
447
|
-
for (const fb of chain) {
|
|
448
|
-
if (fb === "any") {
|
|
449
|
-
const any = Object.values(value).find((v) => v !== "");
|
|
450
|
-
if (any !== void 0) return any;
|
|
451
|
-
} else if (value[fb] !== void 0 && value[fb] !== "") {
|
|
452
|
-
return value[fb];
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
return void 0;
|
|
456
|
-
}
|
|
457
|
-
function resolveI18nText(value, locale, fallback, field, opts) {
|
|
458
|
-
if (locale === "raw") {
|
|
459
|
-
return value;
|
|
460
|
-
}
|
|
461
|
-
if (!locale) {
|
|
462
|
-
throw new LocaleNotSpecifiedError(field ?? "<unknown>");
|
|
463
|
-
}
|
|
464
|
-
if (value[locale] !== void 0 && value[locale] !== "") {
|
|
465
|
-
return value[locale];
|
|
466
|
-
}
|
|
467
|
-
const policy = opts?.policy ?? "throw";
|
|
468
|
-
const callerChain = toChain(fallback);
|
|
469
|
-
const callerHit = pickFromChain(value, callerChain);
|
|
470
|
-
if (callerHit !== void 0) return callerHit;
|
|
471
|
-
if (policy === "substitute") {
|
|
472
|
-
const subHit = pickFromChain(value, toChain(opts?.substitute));
|
|
473
|
-
if (subHit !== void 0) return subHit;
|
|
474
|
-
if (opts?.smartSubstitute) {
|
|
475
|
-
const smartHit = pickNearestScript(value, locale);
|
|
476
|
-
if (smartHit !== void 0) return smartHit;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
if (policy === "throw") {
|
|
480
|
-
throw new LocaleNotSpecifiedError(
|
|
481
|
-
field ?? "<unknown>",
|
|
482
|
-
`No translation available for locale "${locale}"` + (callerChain.length > 0 ? ` or fallback chain [${callerChain.join(", ")}]` : "") + "."
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
return null;
|
|
486
|
-
}
|
|
487
|
-
function pickNearestScript(value, target) {
|
|
488
|
-
const targetScript = inferScripts(target)[0] ?? "Latin";
|
|
489
|
-
let best;
|
|
490
|
-
for (const [loc, v] of Object.entries(value)) {
|
|
491
|
-
if (typeof v !== "string" || v === "") continue;
|
|
492
|
-
const s = inferScripts(loc)[0] ?? "Latin";
|
|
493
|
-
const score = s === targetScript ? 0 : s === "Latin" ? 1 : 2;
|
|
494
|
-
if (best === void 0 || score < best.score) best = { score, v };
|
|
495
|
-
if (score === 0) break;
|
|
496
|
-
}
|
|
497
|
-
return best?.v;
|
|
498
|
-
}
|
|
499
|
-
function getAtPath(obj, path) {
|
|
500
|
-
const arrayIdx = path.indexOf("[].");
|
|
501
|
-
if (arrayIdx !== -1) {
|
|
502
|
-
const arrayKey = path.slice(0, arrayIdx);
|
|
503
|
-
const restPath = path.slice(arrayIdx + 3);
|
|
504
|
-
const arr = obj[arrayKey];
|
|
505
|
-
if (!Array.isArray(arr)) return [];
|
|
506
|
-
return arr.flatMap((item) => {
|
|
507
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) return [];
|
|
508
|
-
return getAtPath(item, restPath);
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
const dotIdx = path.indexOf(".");
|
|
512
|
-
if (dotIdx !== -1) {
|
|
513
|
-
const head = path.slice(0, dotIdx);
|
|
514
|
-
const rest = path.slice(dotIdx + 1);
|
|
515
|
-
const nested = obj[head];
|
|
516
|
-
if (!nested || typeof nested !== "object" || Array.isArray(nested)) return [];
|
|
517
|
-
return getAtPath(nested, rest);
|
|
518
|
-
}
|
|
519
|
-
const val = obj[path];
|
|
520
|
-
return val !== void 0 ? [val] : [];
|
|
521
|
-
}
|
|
522
|
-
function setAtPathInPlace(obj, path, value) {
|
|
523
|
-
const dotIdx = path.indexOf(".");
|
|
524
|
-
if (dotIdx !== -1) {
|
|
525
|
-
const head = path.slice(0, dotIdx);
|
|
526
|
-
const rest = path.slice(dotIdx + 1);
|
|
527
|
-
const nested = obj[head];
|
|
528
|
-
if (!nested || typeof nested !== "object" || Array.isArray(nested)) return;
|
|
529
|
-
setAtPathInPlace(nested, rest, value);
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
obj[path] = value;
|
|
533
|
-
}
|
|
534
|
-
function applyAtPath(obj, path, locale, fallback, opts) {
|
|
535
|
-
const arrayIdx = path.indexOf("[].");
|
|
536
|
-
if (arrayIdx !== -1) {
|
|
537
|
-
const arrayKey = path.slice(0, arrayIdx);
|
|
538
|
-
const restPath = path.slice(arrayIdx + 3);
|
|
539
|
-
const arr = obj[arrayKey];
|
|
540
|
-
if (!Array.isArray(arr)) return obj;
|
|
541
|
-
return {
|
|
542
|
-
...obj,
|
|
543
|
-
[arrayKey]: arr.map((item) => {
|
|
544
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) return item;
|
|
545
|
-
return applyAtPath(item, restPath, locale, fallback, opts);
|
|
546
|
-
})
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
const dotIdx = path.indexOf(".");
|
|
550
|
-
if (dotIdx !== -1) {
|
|
551
|
-
const head = path.slice(0, dotIdx);
|
|
552
|
-
const rest = path.slice(dotIdx + 1);
|
|
553
|
-
const nested = obj[head];
|
|
554
|
-
if (!nested || typeof nested !== "object" || Array.isArray(nested)) return obj;
|
|
555
|
-
return {
|
|
556
|
-
...obj,
|
|
557
|
-
[head]: applyAtPath(nested, rest, locale, fallback, opts)
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
const raw = obj[path];
|
|
561
|
-
if (raw === void 0 || raw === null) return obj;
|
|
562
|
-
if (typeof raw !== "object" || Array.isArray(raw)) return obj;
|
|
563
|
-
return {
|
|
564
|
-
...obj,
|
|
565
|
-
[path]: resolveI18nText(raw, locale, fallback, path, opts)
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
function applyI18nLocale(record, i18nFields, locale, fallback, layer = "read") {
|
|
569
|
-
const fieldNames = Object.keys(i18nFields);
|
|
570
|
-
if (fieldNames.length === 0) return record;
|
|
571
|
-
let result = record;
|
|
572
|
-
for (const [field, descriptor] of Object.entries(i18nFields)) {
|
|
573
|
-
const { onMissing, substitute, smartSubstitute } = descriptor.options;
|
|
574
|
-
const opts = {
|
|
575
|
-
policy: resolvePolicy(onMissing, layer),
|
|
576
|
-
...substitute !== void 0 ? { substitute } : {},
|
|
577
|
-
...smartSubstitute ? { smartSubstitute } : {}
|
|
578
|
-
};
|
|
579
|
-
result = applyAtPath(result, field, locale, fallback, opts);
|
|
580
|
-
}
|
|
581
|
-
result = stripI18nFilled(result);
|
|
582
|
-
return result;
|
|
583
|
-
}
|
|
584
|
-
function stripI18nFilled(record) {
|
|
585
|
-
if (!Object.prototype.hasOwnProperty.call(record, "_i18nFilled")) return record;
|
|
586
|
-
const rest = { ...record };
|
|
587
|
-
delete rest._i18nFilled;
|
|
588
|
-
return rest;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
// src/types.ts
|
|
592
|
-
var NOYDB_FORMAT_VERSION = 1;
|
|
593
|
-
var NOYDB_KEYRING_VERSION = 1;
|
|
594
|
-
|
|
595
|
-
// src/crypto.ts
|
|
596
|
-
var IV_BYTES = 12;
|
|
597
|
-
var KEY_BITS = 256;
|
|
598
|
-
var subtle = globalThis.crypto.subtle;
|
|
599
|
-
async function generateDEK() {
|
|
600
|
-
return subtle.generateKey(
|
|
601
|
-
{ name: "AES-GCM", length: KEY_BITS },
|
|
602
|
-
true,
|
|
603
|
-
// extractable — needed for AES-KW wrapping
|
|
604
|
-
["encrypt", "decrypt"]
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
|
-
async function wrapKey(dek, kek) {
|
|
608
|
-
const wrapped = await subtle.wrapKey("raw", dek, kek, "AES-KW");
|
|
609
|
-
return bufferToBase64(wrapped);
|
|
610
|
-
}
|
|
611
|
-
async function encrypt(plaintext, dek) {
|
|
612
|
-
const iv = generateIV();
|
|
613
|
-
const encoded = new TextEncoder().encode(plaintext);
|
|
614
|
-
const ciphertext = await subtle.encrypt(
|
|
615
|
-
{ name: "AES-GCM", iv },
|
|
616
|
-
dek,
|
|
617
|
-
encoded
|
|
618
|
-
);
|
|
619
|
-
return {
|
|
620
|
-
iv: bufferToBase64(iv),
|
|
621
|
-
data: bufferToBase64(ciphertext)
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
async function decrypt(ivBase64, dataBase64, dek) {
|
|
625
|
-
const iv = base64ToBuffer(ivBase64);
|
|
626
|
-
const ciphertext = base64ToBuffer(dataBase64);
|
|
627
|
-
try {
|
|
628
|
-
const plaintext = await subtle.decrypt(
|
|
629
|
-
{ name: "AES-GCM", iv },
|
|
630
|
-
dek,
|
|
631
|
-
ciphertext
|
|
632
|
-
);
|
|
633
|
-
return new TextDecoder().decode(plaintext);
|
|
634
|
-
} catch (err) {
|
|
635
|
-
if (err instanceof Error && err.name === "OperationError") {
|
|
636
|
-
throw new TamperedError();
|
|
637
|
-
}
|
|
638
|
-
throw new DecryptionError(
|
|
639
|
-
err instanceof Error ? err.message : "Decryption failed"
|
|
640
|
-
);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
function generateIV() {
|
|
644
|
-
return globalThis.crypto.getRandomValues(new Uint8Array(IV_BYTES));
|
|
645
|
-
}
|
|
646
|
-
function bufferToBase64(buffer) {
|
|
647
|
-
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
648
|
-
let binary = "";
|
|
649
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
650
|
-
binary += String.fromCharCode(bytes[i]);
|
|
651
|
-
}
|
|
652
|
-
return btoa(binary);
|
|
653
|
-
}
|
|
654
|
-
function base64ToBuffer(base64) {
|
|
655
|
-
const binary = atob(base64);
|
|
656
|
-
const bytes = new Uint8Array(binary.length);
|
|
657
|
-
for (let i = 0; i < binary.length; i++) {
|
|
658
|
-
bytes[i] = binary.charCodeAt(i);
|
|
659
|
-
}
|
|
660
|
-
return bytes;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// src/team/keyring.ts
|
|
664
|
-
var CANARY_PLAINTEXT_BYTES = new Uint8Array(32);
|
|
665
|
-
var canaryKeyPromise = null;
|
|
666
|
-
function getCanaryKey() {
|
|
667
|
-
if (canaryKeyPromise === null) {
|
|
668
|
-
canaryKeyPromise = globalThis.crypto.subtle.importKey(
|
|
669
|
-
"raw",
|
|
670
|
-
CANARY_PLAINTEXT_BYTES,
|
|
671
|
-
{ name: "AES-GCM", length: 256 },
|
|
672
|
-
true,
|
|
673
|
-
// extractable so AES-KW can wrap it
|
|
674
|
-
["encrypt", "decrypt"]
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
return canaryKeyPromise;
|
|
678
|
-
}
|
|
679
|
-
async function mintKeyringCanary(kek) {
|
|
680
|
-
const canaryKey = await getCanaryKey();
|
|
681
|
-
return wrapKey(canaryKey, kek);
|
|
682
|
-
}
|
|
683
|
-
async function ensureCollectionDEK(adapter, vault, keyring) {
|
|
684
|
-
const inFlight = /* @__PURE__ */ new Map();
|
|
685
|
-
return async (collectionName) => {
|
|
686
|
-
const existing = keyring.deks.get(collectionName);
|
|
687
|
-
if (existing) return existing;
|
|
688
|
-
const pending = inFlight.get(collectionName);
|
|
689
|
-
if (pending) return pending;
|
|
690
|
-
const promise = (async () => {
|
|
691
|
-
const dek = await generateDEK();
|
|
692
|
-
keyring.deks.set(collectionName, dek);
|
|
693
|
-
await persistKeyring(adapter, vault, keyring);
|
|
694
|
-
return dek;
|
|
695
|
-
})();
|
|
696
|
-
inFlight.set(collectionName, promise);
|
|
697
|
-
try {
|
|
698
|
-
return await promise;
|
|
699
|
-
} finally {
|
|
700
|
-
inFlight.delete(collectionName);
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
async function persistKeyring(adapter, vault, keyring) {
|
|
705
|
-
if (!keyring.kek) {
|
|
706
|
-
throw new ValidationError(
|
|
707
|
-
"persistKeyring: keyring.kek is null \u2014 cannot wrap DEKs without the KEK. This typically means the keyring was opened via tier-3 PIN resume, session restore, or a wrap-DEKs tier-2 unlock. Re-authenticate at tier 1 (passphrase) before persisting."
|
|
708
|
-
);
|
|
709
|
-
}
|
|
710
|
-
const wrappedDeks = {};
|
|
711
|
-
for (const [collName, dek] of keyring.deks) {
|
|
712
|
-
wrappedDeks[collName] = await wrapKey(dek, keyring.kek);
|
|
713
|
-
}
|
|
714
|
-
const canary = await mintKeyringCanary(keyring.kek);
|
|
715
|
-
const keyringFile = {
|
|
716
|
-
_noydb_keyring: NOYDB_KEYRING_VERSION,
|
|
717
|
-
user_id: keyring.userId,
|
|
718
|
-
display_name: keyring.displayName,
|
|
719
|
-
role: keyring.role,
|
|
720
|
-
permissions: keyring.permissions,
|
|
721
|
-
deks: wrappedDeks,
|
|
722
|
-
salt: bufferToBase64(keyring.salt),
|
|
723
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
724
|
-
granted_by: keyring.userId,
|
|
725
|
-
canary,
|
|
726
|
-
...keyring.exportCapability !== void 0 && { export_capability: keyring.exportCapability },
|
|
727
|
-
...keyring.importCapability !== void 0 && { import_capability: keyring.importCapability },
|
|
728
|
-
...keyring.authenticators.length > 0 && { authenticators: keyring.authenticators },
|
|
729
|
-
...keyring.policy !== void 0 && { policy: keyring.policy }
|
|
730
|
-
};
|
|
731
|
-
await writeKeyringFile(adapter, vault, keyring.userId, keyringFile);
|
|
732
|
-
}
|
|
733
|
-
async function writeKeyringFile(adapter, vault, userId, keyringFile) {
|
|
734
|
-
const envelope = {
|
|
735
|
-
_noydb: 1,
|
|
736
|
-
_v: 1,
|
|
737
|
-
_ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
738
|
-
_iv: "",
|
|
739
|
-
_data: JSON.stringify(keyringFile)
|
|
740
|
-
};
|
|
741
|
-
await adapter.put(vault, "_keyring", userId, envelope);
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
// src/history/ledger/entry.ts
|
|
745
|
-
async function sha256Hex(input) {
|
|
746
|
-
const bytes = new TextEncoder().encode(input);
|
|
747
|
-
const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
748
|
-
return bytesToHex(new Uint8Array(digest));
|
|
749
|
-
}
|
|
750
|
-
function bytesToHex(bytes) {
|
|
751
|
-
const hex = new Array(bytes.length);
|
|
752
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
753
|
-
hex[i] = (bytes[i] ?? 0).toString(16).padStart(2, "0");
|
|
754
|
-
}
|
|
755
|
-
return hex.join("");
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
// src/history/ledger/hash.ts
|
|
759
|
-
async function envelopePayloadHash(envelope) {
|
|
760
|
-
if (!envelope) return "";
|
|
761
|
-
return sha256Hex(envelope._data);
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
// src/i18n/dictionary.ts
|
|
765
|
-
var DICT_COLLECTION_PREFIX = "_dict_";
|
|
766
|
-
function dictCollectionName(dictionaryName) {
|
|
767
|
-
return `${DICT_COLLECTION_PREFIX}${dictionaryName}`;
|
|
768
|
-
}
|
|
769
|
-
function isDictCollectionName(name) {
|
|
770
|
-
return name.startsWith(DICT_COLLECTION_PREFIX);
|
|
771
|
-
}
|
|
772
|
-
function dictKey(name, keysOrMap, opts) {
|
|
773
|
-
let keys;
|
|
774
|
-
let labels;
|
|
775
|
-
if (Array.isArray(keysOrMap)) {
|
|
776
|
-
keys = keysOrMap;
|
|
777
|
-
labels = opts?.labels;
|
|
778
|
-
} else if (keysOrMap && typeof keysOrMap === "object") {
|
|
779
|
-
keys = Object.keys(keysOrMap);
|
|
780
|
-
labels = keysOrMap;
|
|
781
|
-
} else {
|
|
782
|
-
keys = void 0;
|
|
783
|
-
labels = opts?.labels;
|
|
784
|
-
}
|
|
785
|
-
return {
|
|
786
|
-
_noydbDictKey: true,
|
|
787
|
-
name,
|
|
788
|
-
keys,
|
|
789
|
-
...opts?.onMissing !== void 0 ? { onMissing: opts.onMissing } : {},
|
|
790
|
-
...opts?.substitute !== void 0 ? { substitute: opts.substitute } : {},
|
|
791
|
-
...labels !== void 0 ? { labels } : {}
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
function isDictKeyDescriptor(x) {
|
|
795
|
-
return typeof x === "object" && x !== null && x._noydbDictKey === true;
|
|
796
|
-
}
|
|
797
|
-
function staticDict(name, table, opts) {
|
|
798
|
-
return {
|
|
799
|
-
_noydbStaticDict: true,
|
|
800
|
-
name,
|
|
801
|
-
table,
|
|
802
|
-
keys: Object.keys(table),
|
|
803
|
-
...opts?.displayLocale !== void 0 ? { displayLocale: opts.displayLocale } : {},
|
|
804
|
-
...opts?.onMissing !== void 0 ? { onMissing: opts.onMissing } : {},
|
|
805
|
-
...opts?.substitute !== void 0 ? { substitute: opts.substitute } : {},
|
|
806
|
-
...opts?.validateCodes !== void 0 ? { validateCodes: opts.validateCodes } : {}
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
|
-
function isStaticDictDescriptor(x) {
|
|
810
|
-
return typeof x === "object" && x !== null && x._noydbStaticDict === true;
|
|
811
|
-
}
|
|
812
|
-
var DictionaryHandle = class {
|
|
813
|
-
constructor(adapter, compartmentName, dictionaryName, keyring, getDEK, encrypted, ledger, options, findAndUpdateReferences, emitter) {
|
|
814
|
-
this.adapter = adapter;
|
|
815
|
-
this.compartmentName = compartmentName;
|
|
816
|
-
this.dictionaryName = dictionaryName;
|
|
817
|
-
this.keyring = keyring;
|
|
818
|
-
this.getDEK = getDEK;
|
|
819
|
-
this.encrypted = encrypted;
|
|
820
|
-
this.ledger = ledger;
|
|
821
|
-
this.options = options;
|
|
822
|
-
this.findAndUpdateReferences = findAndUpdateReferences;
|
|
823
|
-
this.emitter = emitter;
|
|
824
|
-
this.collName = dictCollectionName(dictionaryName);
|
|
825
|
-
}
|
|
826
|
-
adapter;
|
|
827
|
-
compartmentName;
|
|
828
|
-
dictionaryName;
|
|
829
|
-
keyring;
|
|
830
|
-
getDEK;
|
|
831
|
-
encrypted;
|
|
832
|
-
ledger;
|
|
833
|
-
options;
|
|
834
|
-
findAndUpdateReferences;
|
|
835
|
-
emitter;
|
|
836
|
-
collName;
|
|
837
|
-
/**
|
|
838
|
-
* Synchronous write-through cache for dict-join support.
|
|
839
|
-
* Populated on every `put()`, `delete()`, and `rename()`. The snapshot
|
|
840
|
-
* is built from this cache by `snapshotEntries()` — the query executor
|
|
841
|
-
* calls this synchronously inside `.toArray()`.
|
|
842
|
-
*
|
|
843
|
-
* `null` means "not yet initialized" — callers should use `list()`
|
|
844
|
-
* to warm the cache before using dict joins on pre-existing data.
|
|
845
|
-
*/
|
|
846
|
-
_syncCache = /* @__PURE__ */ new Map();
|
|
847
|
-
/**
|
|
848
|
-
* Return all cached entries as `{ key, labels, ...labels }` records —
|
|
849
|
-
* usable synchronously by the join executor's `snapshot()` call.
|
|
850
|
-
* Returns an empty array when the cache has never been populated.
|
|
851
|
-
*/
|
|
852
|
-
snapshotEntries() {
|
|
853
|
-
return Array.from(this._syncCache.values()).map((e) => ({
|
|
854
|
-
key: e.key,
|
|
855
|
-
labels: e.labels,
|
|
856
|
-
...e.labels
|
|
857
|
-
}));
|
|
858
|
-
}
|
|
859
|
-
// ─── Access checks ────────────────────────────────────────────────
|
|
860
|
-
requireWriteAccess() {
|
|
861
|
-
const minRole = this.options.writableBy ?? "admin";
|
|
862
|
-
const roleRank = {
|
|
863
|
-
client: 1,
|
|
864
|
-
viewer: 2,
|
|
865
|
-
operator: 3,
|
|
866
|
-
admin: 4,
|
|
867
|
-
owner: 5
|
|
868
|
-
};
|
|
869
|
-
const callerRank = roleRank[this.keyring.role] ?? 0;
|
|
870
|
-
const requiredRank = roleRank[minRole] ?? 4;
|
|
871
|
-
if (callerRank < requiredRank) {
|
|
872
|
-
throw new PermissionDeniedError(
|
|
873
|
-
`Dictionary "${this.dictionaryName}" writes require "${minRole}" role or above. Current role: "${this.keyring.role}".`
|
|
874
|
-
);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
// ─── Internal helpers ─────────────────────────────────────────────
|
|
878
|
-
async getDekForDict() {
|
|
879
|
-
const resolve = await ensureCollectionDEK(
|
|
880
|
-
this.adapter,
|
|
881
|
-
this.compartmentName,
|
|
882
|
-
this.keyring
|
|
883
|
-
);
|
|
884
|
-
return resolve(this.collName);
|
|
885
|
-
}
|
|
886
|
-
async encryptEntry(entry, version) {
|
|
887
|
-
if (!this.encrypted) {
|
|
888
|
-
return {
|
|
889
|
-
_noydb: NOYDB_FORMAT_VERSION,
|
|
890
|
-
_v: version,
|
|
891
|
-
_ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
892
|
-
_iv: "",
|
|
893
|
-
_data: JSON.stringify(entry),
|
|
894
|
-
_by: this.keyring.userId
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
const dek = await this.getDekForDict();
|
|
898
|
-
const { iv, data } = await encrypt(JSON.stringify(entry), dek);
|
|
899
|
-
return {
|
|
900
|
-
_noydb: NOYDB_FORMAT_VERSION,
|
|
901
|
-
_v: version,
|
|
902
|
-
_ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
903
|
-
_iv: iv,
|
|
904
|
-
_data: data,
|
|
905
|
-
_by: this.keyring.userId
|
|
906
|
-
};
|
|
907
|
-
}
|
|
908
|
-
async decryptEntry(envelope) {
|
|
909
|
-
if (!this.encrypted) {
|
|
910
|
-
return JSON.parse(envelope._data);
|
|
911
|
-
}
|
|
912
|
-
const dek = await this.getDekForDict();
|
|
913
|
-
const json = await decrypt(envelope._iv, envelope._data, dek);
|
|
914
|
-
return JSON.parse(json);
|
|
915
|
-
}
|
|
916
|
-
// ─── Public API ───────────────────────────────────────────────────
|
|
917
|
-
/**
|
|
918
|
-
* Add or overwrite a single dictionary entry.
|
|
919
|
-
*
|
|
920
|
-
* @param key The stable key to store (e.g. `'paid'`).
|
|
921
|
-
* @param labels Locale → label map (e.g. `{ en: 'Paid', th: 'ชำระแล้ว' }`).
|
|
922
|
-
*/
|
|
923
|
-
async put(key, labels) {
|
|
924
|
-
this.requireWriteAccess();
|
|
925
|
-
const entry = { key, labels };
|
|
926
|
-
const existing = await this.adapter.get(
|
|
927
|
-
this.compartmentName,
|
|
928
|
-
this.collName,
|
|
929
|
-
key
|
|
930
|
-
);
|
|
931
|
-
const version = existing ? existing._v + 1 : 1;
|
|
932
|
-
const envelope = await this.encryptEntry(entry, version);
|
|
933
|
-
await this.adapter.put(
|
|
934
|
-
this.compartmentName,
|
|
935
|
-
this.collName,
|
|
936
|
-
key,
|
|
937
|
-
envelope,
|
|
938
|
-
existing ? existing._v : void 0
|
|
939
|
-
);
|
|
940
|
-
this._syncCache.set(key, entry);
|
|
941
|
-
this.emitter.emit("change", {
|
|
942
|
-
vault: this.compartmentName,
|
|
943
|
-
collection: this.collName,
|
|
944
|
-
id: key,
|
|
945
|
-
action: "put"
|
|
946
|
-
});
|
|
947
|
-
if (this.ledger) {
|
|
948
|
-
await this.ledger.append({
|
|
949
|
-
op: "put",
|
|
950
|
-
collection: this.collName,
|
|
951
|
-
id: key,
|
|
952
|
-
version,
|
|
953
|
-
actor: this.keyring.userId,
|
|
954
|
-
// — must be the real envelope hash so
|
|
955
|
-
// vault.verifyBackupIntegrity()'s data-cross-check matches.
|
|
956
|
-
payloadHash: await envelopePayloadHash(envelope)
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Batch-add or overwrite multiple dictionary entries in one call.
|
|
962
|
-
*
|
|
963
|
-
* @param entries `{ key: { locale: label } }` map.
|
|
964
|
-
*/
|
|
965
|
-
async putAll(entries) {
|
|
966
|
-
this.requireWriteAccess();
|
|
967
|
-
for (const [key, labels] of Object.entries(entries)) {
|
|
968
|
-
await this.put(key, labels);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* Load the label map for a single key.
|
|
973
|
-
*
|
|
974
|
-
* @returns The label map, or `null` if the key doesn't exist.
|
|
975
|
-
*/
|
|
976
|
-
async get(key) {
|
|
977
|
-
const envelope = await this.adapter.get(
|
|
978
|
-
this.compartmentName,
|
|
979
|
-
this.collName,
|
|
980
|
-
key
|
|
981
|
-
);
|
|
982
|
-
if (!envelope) return null;
|
|
983
|
-
const entry = await this.decryptEntry(envelope);
|
|
984
|
-
return entry.labels;
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Delete a dictionary key.
|
|
988
|
-
*
|
|
989
|
-
* Default mode is `'strict'` — throws `DictKeyInUseError` if any
|
|
990
|
-
* registered collection has a record referencing this key. Pass
|
|
991
|
-
* `{ mode: 'warn' }` to skip the check (dev-mode cleanup only).
|
|
992
|
-
*/
|
|
993
|
-
async delete(key, opts = {}) {
|
|
994
|
-
this.requireWriteAccess();
|
|
995
|
-
const existing = await this.adapter.get(
|
|
996
|
-
this.compartmentName,
|
|
997
|
-
this.collName,
|
|
998
|
-
key
|
|
999
|
-
);
|
|
1000
|
-
if (!existing) {
|
|
1001
|
-
throw new DictKeyMissingError(this.dictionaryName, key);
|
|
1002
|
-
}
|
|
1003
|
-
const mode = opts.mode ?? "strict";
|
|
1004
|
-
if (mode === "strict" && this.findAndUpdateReferences) {
|
|
1005
|
-
}
|
|
1006
|
-
await this.adapter.delete(this.compartmentName, this.collName, key);
|
|
1007
|
-
this._syncCache.delete(key);
|
|
1008
|
-
this.emitter.emit("change", {
|
|
1009
|
-
vault: this.compartmentName,
|
|
1010
|
-
collection: this.collName,
|
|
1011
|
-
id: key,
|
|
1012
|
-
action: "delete"
|
|
1013
|
-
});
|
|
1014
|
-
if (this.ledger) {
|
|
1015
|
-
await this.ledger.append({
|
|
1016
|
-
op: "delete",
|
|
1017
|
-
collection: this.collName,
|
|
1018
|
-
id: key,
|
|
1019
|
-
version: existing._v,
|
|
1020
|
-
actor: this.keyring.userId,
|
|
1021
|
-
// — for delete the prior envelope is what was just
|
|
1022
|
-
// removed; we hash it so the chain captures intent. The
|
|
1023
|
-
// verifyBackupIntegrity data-cross-check skips delete
|
|
1024
|
-
// entries entirely (the live record is gone), but the
|
|
1025
|
-
// chain still benefits from a stable non-empty hash.
|
|
1026
|
-
payloadHash: await envelopePayloadHash(existing)
|
|
1027
|
-
});
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Rename a dictionary key — the only sanctioned mass-mutation path.
|
|
1032
|
-
*
|
|
1033
|
-
* Atomically:
|
|
1034
|
-
* 1. Adds the new key with the same labels as the old key.
|
|
1035
|
-
* 2. Updates every registered record that stores the old key to
|
|
1036
|
-
* store the new key instead.
|
|
1037
|
-
* 3. Deletes the old key.
|
|
1038
|
-
* 4. Appends a single ledger entry recording the rename.
|
|
1039
|
-
*
|
|
1040
|
-
* Respects ACL: throws `PermissionDeniedError` before any mutation
|
|
1041
|
-
* if the caller can't write. The cascade is best-effort atomic
|
|
1042
|
-
* within this call — no two-phase commit across adapter calls.
|
|
1043
|
-
*
|
|
1044
|
-
* Cascade-on-delete is NOT supported. Use `rename()` when you need
|
|
1045
|
-
* to change a key that records reference.
|
|
1046
|
-
*/
|
|
1047
|
-
async rename(oldKey, newKey) {
|
|
1048
|
-
this.requireWriteAccess();
|
|
1049
|
-
const existing = await this.adapter.get(
|
|
1050
|
-
this.compartmentName,
|
|
1051
|
-
this.collName,
|
|
1052
|
-
oldKey
|
|
1053
|
-
);
|
|
1054
|
-
if (!existing) {
|
|
1055
|
-
throw new DictKeyMissingError(this.dictionaryName, oldKey);
|
|
1056
|
-
}
|
|
1057
|
-
const oldEntry = await this.decryptEntry(existing);
|
|
1058
|
-
const newEntry = { key: newKey, labels: oldEntry.labels };
|
|
1059
|
-
const newEnvelope = await this.encryptEntry(newEntry, 1);
|
|
1060
|
-
await this.adapter.put(
|
|
1061
|
-
this.compartmentName,
|
|
1062
|
-
this.collName,
|
|
1063
|
-
newKey,
|
|
1064
|
-
newEnvelope
|
|
1065
|
-
);
|
|
1066
|
-
if (this.findAndUpdateReferences) {
|
|
1067
|
-
await this.findAndUpdateReferences(this.dictionaryName, oldKey, newKey);
|
|
1068
|
-
}
|
|
1069
|
-
await this.adapter.delete(this.compartmentName, this.collName, oldKey);
|
|
1070
|
-
this._syncCache.delete(oldKey);
|
|
1071
|
-
this._syncCache.set(newKey, newEntry);
|
|
1072
|
-
this.emitter.emit("change", {
|
|
1073
|
-
vault: this.compartmentName,
|
|
1074
|
-
collection: this.collName,
|
|
1075
|
-
id: oldKey,
|
|
1076
|
-
action: "delete"
|
|
1077
|
-
});
|
|
1078
|
-
this.emitter.emit("change", {
|
|
1079
|
-
vault: this.compartmentName,
|
|
1080
|
-
collection: this.collName,
|
|
1081
|
-
id: newKey,
|
|
1082
|
-
action: "put"
|
|
1083
|
-
});
|
|
1084
|
-
if (this.ledger) {
|
|
1085
|
-
await this.ledger.append({
|
|
1086
|
-
op: "delete",
|
|
1087
|
-
collection: this.collName,
|
|
1088
|
-
id: oldKey,
|
|
1089
|
-
version: existing._v,
|
|
1090
|
-
actor: this.keyring.userId,
|
|
1091
|
-
payloadHash: await envelopePayloadHash(existing)
|
|
1092
|
-
});
|
|
1093
|
-
await this.ledger.append({
|
|
1094
|
-
op: "put",
|
|
1095
|
-
collection: this.collName,
|
|
1096
|
-
id: newKey,
|
|
1097
|
-
version: 1,
|
|
1098
|
-
actor: this.keyring.userId,
|
|
1099
|
-
payloadHash: await envelopePayloadHash(newEnvelope)
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
/**
|
|
1104
|
-
* List all entries in this dictionary.
|
|
1105
|
-
*
|
|
1106
|
-
* @returns Array of `{ key, labels }` objects.
|
|
1107
|
-
*/
|
|
1108
|
-
async list() {
|
|
1109
|
-
const keys = await this.adapter.list(this.compartmentName, this.collName);
|
|
1110
|
-
const entries = [];
|
|
1111
|
-
for (const key of keys) {
|
|
1112
|
-
const envelope = await this.adapter.get(
|
|
1113
|
-
this.compartmentName,
|
|
1114
|
-
this.collName,
|
|
1115
|
-
key
|
|
1116
|
-
);
|
|
1117
|
-
if (!envelope) continue;
|
|
1118
|
-
const entry = await this.decryptEntry(envelope);
|
|
1119
|
-
entries.push(entry);
|
|
1120
|
-
this._syncCache.set(key, entry);
|
|
1121
|
-
}
|
|
1122
|
-
return entries;
|
|
1123
|
-
}
|
|
1124
|
-
/**
|
|
1125
|
-
* Resolve a key to its label for the given locale.
|
|
1126
|
-
*
|
|
1127
|
-
* Used by the collection's locale-aware read path to populate
|
|
1128
|
-
* `<field>Label` virtual fields. Returns `undefined` when the
|
|
1129
|
-
* key doesn't exist or has no label for the requested locale
|
|
1130
|
-
* (after exhausting the fallback chain).
|
|
1131
|
-
*/
|
|
1132
|
-
async resolveLabel(key, locale, fallback) {
|
|
1133
|
-
const labels = await this.get(key);
|
|
1134
|
-
if (!labels) return void 0;
|
|
1135
|
-
if (labels[locale] !== void 0) return labels[locale];
|
|
1136
|
-
const chain = Array.isArray(fallback) ? fallback : fallback ? [fallback] : [];
|
|
1137
|
-
for (const fb of chain) {
|
|
1138
|
-
if (fb === "any") {
|
|
1139
|
-
const any = Object.values(labels)[0];
|
|
1140
|
-
if (any !== void 0) return any;
|
|
1141
|
-
} else if (labels[fb] !== void 0) {
|
|
1142
|
-
return labels[fb];
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
return void 0;
|
|
1146
|
-
}
|
|
1147
|
-
};
|
|
1148
|
-
|
|
1149
|
-
// src/i18n/densify.ts
|
|
1150
|
-
var MARKER = "_i18nFilled";
|
|
1151
|
-
function priorFilled(prior, field) {
|
|
1152
|
-
if (!prior) return /* @__PURE__ */ new Set();
|
|
1153
|
-
const marker = prior[MARKER];
|
|
1154
|
-
return new Set(marker?.[field] ?? []);
|
|
1155
|
-
}
|
|
1156
|
-
function singleLeaf(record, field) {
|
|
1157
|
-
const leaves = getAtPath(record, field);
|
|
1158
|
-
if (leaves.length !== 1) return void 0;
|
|
1159
|
-
const leaf = leaves[0];
|
|
1160
|
-
if (!leaf || typeof leaf !== "object" || Array.isArray(leaf)) return void 0;
|
|
1161
|
-
return leaf;
|
|
1162
|
-
}
|
|
1163
|
-
function computeExemptFills(prior, incoming, fields) {
|
|
1164
|
-
const out = /* @__PURE__ */ new Map();
|
|
1165
|
-
if (!prior) return out;
|
|
1166
|
-
for (const field of Object.keys(fields)) {
|
|
1167
|
-
const filled = priorFilled(prior, field);
|
|
1168
|
-
if (filled.size === 0) continue;
|
|
1169
|
-
const priorLeaf = singleLeaf(prior, field);
|
|
1170
|
-
const incLeaf = singleLeaf(incoming, field);
|
|
1171
|
-
if (!priorLeaf || !incLeaf) continue;
|
|
1172
|
-
const exempt = /* @__PURE__ */ new Set();
|
|
1173
|
-
for (const loc of filled) {
|
|
1174
|
-
if (incLeaf[loc] !== void 0 && incLeaf[loc] !== "" && incLeaf[loc] === priorLeaf[loc]) {
|
|
1175
|
-
exempt.add(loc);
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
if (exempt.size > 0) out.set(field, exempt);
|
|
1179
|
-
}
|
|
1180
|
-
return out;
|
|
1181
|
-
}
|
|
1182
|
-
function densify(record, prior, fields) {
|
|
1183
|
-
let marker = record[MARKER];
|
|
1184
|
-
for (const [field, descriptor] of Object.entries(fields)) {
|
|
1185
|
-
const leaf = singleLeaf(record, field);
|
|
1186
|
-
if (!leaf) continue;
|
|
1187
|
-
const { languages, substitute, smartSubstitute } = descriptor.options;
|
|
1188
|
-
const filledSet = priorFilled(prior, field);
|
|
1189
|
-
const priorLeaf = singleLeaf(prior ?? {}, field);
|
|
1190
|
-
const isUnchangedFill = (loc) => filledSet.has(loc) && priorLeaf?.[loc] !== void 0 && leaf[loc] === priorLeaf[loc];
|
|
1191
|
-
const authored = {};
|
|
1192
|
-
for (const [loc, val] of Object.entries(leaf)) {
|
|
1193
|
-
if (typeof val === "string" && val !== "" && !isUnchangedFill(loc)) authored[loc] = val;
|
|
1194
|
-
}
|
|
1195
|
-
const filled = [];
|
|
1196
|
-
for (const loc of languages) {
|
|
1197
|
-
if (authored[loc] !== void 0) continue;
|
|
1198
|
-
const sub = resolveI18nText(authored, loc, void 0, field, {
|
|
1199
|
-
policy: "substitute",
|
|
1200
|
-
substitute: substitute ?? ["any"],
|
|
1201
|
-
...smartSubstitute ? { smartSubstitute } : {}
|
|
1202
|
-
});
|
|
1203
|
-
if (typeof sub === "string" && sub !== "") {
|
|
1204
|
-
leaf[loc] = sub;
|
|
1205
|
-
filled.push(loc);
|
|
1206
|
-
} else if (isUnchangedFill(loc)) {
|
|
1207
|
-
delete leaf[loc];
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
if (filled.length > 0) {
|
|
1211
|
-
marker ??= {};
|
|
1212
|
-
marker[field] = filled;
|
|
1213
|
-
} else if (marker) {
|
|
1214
|
-
delete marker[field];
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
if (marker && Object.keys(marker).length > 0) {
|
|
1218
|
-
record[MARKER] = marker;
|
|
1219
|
-
} else {
|
|
1220
|
-
delete record[MARKER];
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
// src/i18n/active.ts
|
|
1225
|
-
function withI18n() {
|
|
1226
|
-
return {
|
|
1227
|
-
applyI18nLocale,
|
|
1228
|
-
validateI18nTextValue,
|
|
1229
|
-
enforceScript,
|
|
1230
|
-
computeExemptFills,
|
|
1231
|
-
densify,
|
|
1232
|
-
buildDictionaryHandle(opts) {
|
|
1233
|
-
return new DictionaryHandle(
|
|
1234
|
-
opts.adapter,
|
|
1235
|
-
opts.compartmentName,
|
|
1236
|
-
opts.dictionaryName,
|
|
1237
|
-
opts.keyring,
|
|
1238
|
-
opts.getDEK,
|
|
1239
|
-
opts.encrypted,
|
|
1240
|
-
opts.ledger,
|
|
1241
|
-
opts.options,
|
|
1242
|
-
opts.findAndUpdateReferences,
|
|
1243
|
-
opts.emitter
|
|
1244
|
-
);
|
|
1245
|
-
}
|
|
1246
|
-
};
|
|
1247
|
-
}
|
|
1248
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1249
|
-
0 && (module.exports = {
|
|
1250
|
-
DICT_COLLECTION_PREFIX,
|
|
1251
|
-
DictKeyInUseError,
|
|
1252
|
-
DictKeyMissingError,
|
|
1253
|
-
DictionaryHandle,
|
|
1254
|
-
LocaleNotSpecifiedError,
|
|
1255
|
-
MissingTranslationError,
|
|
1256
|
-
ReservedCollectionNameError,
|
|
1257
|
-
ScriptViolationError,
|
|
1258
|
-
StaticDictReadonlyError,
|
|
1259
|
-
TranslatorNotConfiguredError,
|
|
1260
|
-
UnknownDictCodeError,
|
|
1261
|
-
applyI18nLocale,
|
|
1262
|
-
dictCollectionName,
|
|
1263
|
-
dictKey,
|
|
1264
|
-
enforceScript,
|
|
1265
|
-
getAtPath,
|
|
1266
|
-
i18nText,
|
|
1267
|
-
inferScripts,
|
|
1268
|
-
isDictCollectionName,
|
|
1269
|
-
isDictKeyDescriptor,
|
|
1270
|
-
isI18nTextDescriptor,
|
|
1271
|
-
isStaticDictDescriptor,
|
|
1272
|
-
resolveI18nText,
|
|
1273
|
-
resolvePolicy,
|
|
1274
|
-
setAtPathInPlace,
|
|
1275
|
-
staticDict,
|
|
1276
|
-
stripI18nFilled,
|
|
1277
|
-
validateI18nTextValue,
|
|
1278
|
-
withI18n
|
|
1279
|
-
});
|
|
1280
|
-
//# sourceMappingURL=index.cjs.map
|