@stll/anonymize 1.5.0 → 2.0.0
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/ATTRIBUTION.md +70 -0
- package/README.md +86 -48
- package/dist/index.d.mts +3 -1201
- package/dist/index.mjs +3 -16267
- package/dist/index.mjs.map +1 -1
- package/dist/native-node.d.mts +138 -0
- package/dist/native-node.mjs +3 -0
- package/dist/native-node2.d.mts +3 -0
- package/dist/native-node2.mjs +728 -0
- package/dist/native-node2.mjs.map +1 -0
- package/dist/native.d.mts +970 -0
- package/dist/native.mjs +230 -0
- package/dist/native.mjs.map +1 -0
- package/dist/native2.d.mts +2 -0
- package/index.cjs +3 -0
- package/native-pipeline.cs.stlanonpkg +0 -0
- package/native-pipeline.de.stlanonpkg +0 -0
- package/native-pipeline.en.stlanonpkg +0 -0
- package/native-pipeline.stlanonpkg +0 -0
- package/package.json +57 -9
- package/scripts/build-native-pipeline-package.mjs +225 -0
- package/dist/address-boundaries.mjs +0 -195
- package/dist/address-boundaries.mjs.map +0 -1
- package/dist/address-prepositions.mjs +0 -182
- package/dist/address-prepositions.mjs.map +0 -1
- package/dist/address-stop-keywords.mjs +0 -137
- package/dist/address-stop-keywords.mjs.map +0 -1
- package/dist/address-stopwords.mjs +0 -84
- package/dist/address-stopwords.mjs.map +0 -1
- package/dist/allow-list.mjs +0 -196
- package/dist/allow-list.mjs.map +0 -1
- package/dist/clause-noun-heads.mjs +0 -75
- package/dist/clause-noun-heads.mjs.map +0 -1
- package/dist/common-words-en.mjs +0 -9887
- package/dist/common-words-en.mjs.map +0 -1
- package/dist/coreference.cs.mjs +0 -14
- package/dist/coreference.cs.mjs.map +0 -1
- package/dist/coreference.de.mjs +0 -14
- package/dist/coreference.de.mjs.map +0 -1
- package/dist/coreference.en.mjs +0 -14
- package/dist/coreference.en.mjs.map +0 -1
- package/dist/coreference.es.mjs +0 -22
- package/dist/coreference.es.mjs.map +0 -1
- package/dist/coreference.fr.mjs +0 -32
- package/dist/coreference.fr.mjs.map +0 -1
- package/dist/coreference.it.mjs +0 -27
- package/dist/coreference.it.mjs.map +0 -1
- package/dist/coreference.pl.mjs +0 -27
- package/dist/coreference.pl.mjs.map +0 -1
- package/dist/coreference.pt-br.mjs +0 -14
- package/dist/coreference.pt-br.mjs.map +0 -1
- package/dist/coreference.sk.mjs +0 -27
- package/dist/coreference.sk.mjs.map +0 -1
- package/dist/currencies.mjs +0 -231
- package/dist/currencies.mjs.map +0 -1
- package/dist/date-months.mjs +0 -618
- package/dist/date-months.mjs.map +0 -1
- package/dist/document-structure-headings.mjs +0 -90
- package/dist/document-structure-headings.mjs.map +0 -1
- package/dist/generic-roles.mjs +0 -244
- package/dist/generic-roles.mjs.map +0 -1
- package/dist/hotword-rules.mjs +0 -149
- package/dist/hotword-rules.mjs.map +0 -1
- package/dist/legal-form-leading-clauses.mjs +0 -23
- package/dist/legal-form-leading-clauses.mjs.map +0 -1
- package/dist/legal-forms.mjs +0 -2115
- package/dist/legal-forms.mjs.map +0 -1
- package/dist/legal-role-heads.cs.mjs +0 -42
- package/dist/legal-role-heads.cs.mjs.map +0 -1
- package/dist/legal-role-heads.de.mjs +0 -33
- package/dist/legal-role-heads.de.mjs.map +0 -1
- package/dist/legal-role-heads.en.mjs +0 -37
- package/dist/legal-role-heads.en.mjs.map +0 -1
- package/dist/legal-role-heads.es.mjs +0 -54
- package/dist/legal-role-heads.es.mjs.map +0 -1
- package/dist/legal-role-heads.fr.mjs +0 -72
- package/dist/legal-role-heads.fr.mjs.map +0 -1
- package/dist/legal-role-heads.it.mjs +0 -68
- package/dist/legal-role-heads.it.mjs.map +0 -1
- package/dist/legal-role-heads.pl.mjs +0 -84
- package/dist/legal-role-heads.pl.mjs.map +0 -1
- package/dist/legal-role-heads.pt-br.mjs +0 -63
- package/dist/legal-role-heads.pt-br.mjs.map +0 -1
- package/dist/legal-role-heads.sk.mjs +0 -80
- package/dist/legal-role-heads.sk.mjs.map +0 -1
- package/dist/manifest.mjs +0 -69
- package/dist/manifest.mjs.map +0 -1
- package/dist/names-exclusions.mjs +0 -223
- package/dist/names-exclusions.mjs.map +0 -1
- package/dist/names-first.mjs +0 -418
- package/dist/names-first.mjs.map +0 -1
- package/dist/names-nw-ar.mjs +0 -202
- package/dist/names-nw-ar.mjs.map +0 -1
- package/dist/names-nw-excluded-allcaps.mjs +0 -112
- package/dist/names-nw-excluded-allcaps.mjs.map +0 -1
- package/dist/names-nw-fil.mjs +0 -202
- package/dist/names-nw-fil.mjs.map +0 -1
- package/dist/names-nw-id.mjs +0 -210
- package/dist/names-nw-id.mjs.map +0 -1
- package/dist/names-nw-in.mjs +0 -526
- package/dist/names-nw-in.mjs.map +0 -1
- package/dist/names-nw-ja-latn.mjs +0 -260
- package/dist/names-nw-ja-latn.mjs.map +0 -1
- package/dist/names-nw-ko.mjs +0 -162
- package/dist/names-nw-ko.mjs.map +0 -1
- package/dist/names-nw-th.mjs +0 -188
- package/dist/names-nw-th.mjs.map +0 -1
- package/dist/names-nw-vi.mjs +0 -151
- package/dist/names-nw-vi.mjs.map +0 -1
- package/dist/names-nw-zh-latn.mjs +0 -197
- package/dist/names-nw-zh-latn.mjs.map +0 -1
- package/dist/names-surnames.mjs +0 -113
- package/dist/names-surnames.mjs.map +0 -1
- package/dist/names-title-tokens.mjs +0 -40
- package/dist/names-title-tokens.mjs.map +0 -1
- package/dist/person-stopwords.mjs +0 -205
- package/dist/person-stopwords.mjs.map +0 -1
- package/dist/section-headings.mjs +0 -64
- package/dist/section-headings.mjs.map +0 -1
- package/dist/sentence-verb-indicators.mjs +0 -232
- package/dist/sentence-verb-indicators.mjs.map +0 -1
- package/dist/signing-clauses.mjs +0 -78
- package/dist/signing-clauses.mjs.map +0 -1
- package/dist/stopwords.mjs +0 -9915
- package/dist/stopwords.mjs.map +0 -1
- package/dist/structural-single-cap-prefixes.mjs +0 -99
- package/dist/structural-single-cap-prefixes.mjs.map +0 -1
- package/dist/triggers.cs.mjs +0 -569
- package/dist/triggers.cs.mjs.map +0 -1
- package/dist/triggers.de.mjs +0 -139
- package/dist/triggers.de.mjs.map +0 -1
- package/dist/triggers.en.mjs +0 -119
- package/dist/triggers.en.mjs.map +0 -1
- package/dist/triggers.es.mjs +0 -96
- package/dist/triggers.es.mjs.map +0 -1
- package/dist/triggers.fr.mjs +0 -275
- package/dist/triggers.fr.mjs.map +0 -1
- package/dist/triggers.global.mjs +0 -79
- package/dist/triggers.global.mjs.map +0 -1
- package/dist/triggers.hu.mjs +0 -41
- package/dist/triggers.hu.mjs.map +0 -1
- package/dist/triggers.it.mjs +0 -74
- package/dist/triggers.it.mjs.map +0 -1
- package/dist/triggers.pl.mjs +0 -271
- package/dist/triggers.pl.mjs.map +0 -1
- package/dist/triggers.pt-br.mjs +0 -193
- package/dist/triggers.pt-br.mjs.map +0 -1
- package/dist/triggers.ro.mjs +0 -59
- package/dist/triggers.ro.mjs.map +0 -1
- package/dist/triggers.sk.mjs +0 -555
- package/dist/triggers.sk.mjs.map +0 -1
- package/dist/triggers.sv.mjs +0 -58
- package/dist/triggers.sv.mjs.map +0 -1
- package/dist/year-words.mjs +0 -62
- package/dist/year-words.mjs.map +0 -1
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
import { PreparedNativeAnonymizer, PreparedNativePipeline, assertNativeBindingVersion, createNativePipelineFromPackage, diagnostics_json as diagnostics_json$1, diagnostics_stream_json as diagnostics_stream_json$1, load_prepared_package as load_prepared_package$1, native_package_version as native_package_version$1, normalize_for_search as normalize_for_search$1, prepare_search_package as prepare_search_package$1, redact_text as redact_text$1, redact_text_json as redact_text_json$1, redact_text_stream_json as redact_text_stream_json$1, summary_diagnostics_json as summary_diagnostics_json$1 } from "./native.mjs";
|
|
2
|
+
import { DEFAULT_ENTITY_LABELS } from "./constants.mjs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
//#region src/context.ts
|
|
8
|
+
/** Create a fresh, empty pipeline context. */
|
|
9
|
+
const createPipelineContext = () => ({
|
|
10
|
+
nativePipelinePackage: null,
|
|
11
|
+
nativePipelinePackageKey: "",
|
|
12
|
+
nativePipelinePackagePromise: null
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Module-level default context. Used when callers
|
|
16
|
+
* don't provide an explicit context, preserving full
|
|
17
|
+
* backward compatibility with the existing API.
|
|
18
|
+
*/
|
|
19
|
+
const defaultContext = createPipelineContext();
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/language-scope.ts
|
|
22
|
+
const scopeData = {
|
|
23
|
+
_comment: "Default dictionary scopes for content language hints. Lower-level caller config can still override name corpus languages and deny-list countries independently.",
|
|
24
|
+
languages: {
|
|
25
|
+
"cs": {
|
|
26
|
+
"nameCorpusLanguages": ["cs", "sk"],
|
|
27
|
+
"denyListCountries": ["CZ", "SK"]
|
|
28
|
+
},
|
|
29
|
+
"de": {
|
|
30
|
+
"nameCorpusLanguages": ["de"],
|
|
31
|
+
"denyListCountries": [
|
|
32
|
+
"DE",
|
|
33
|
+
"AT",
|
|
34
|
+
"CH"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"en": {
|
|
38
|
+
"nameCorpusLanguages": ["en"],
|
|
39
|
+
"denyListCountries": [
|
|
40
|
+
"US",
|
|
41
|
+
"GB",
|
|
42
|
+
"CA",
|
|
43
|
+
"AU",
|
|
44
|
+
"IE"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
"es": {
|
|
48
|
+
"nameCorpusLanguages": ["es"],
|
|
49
|
+
"denyListCountries": [
|
|
50
|
+
"ES",
|
|
51
|
+
"MX",
|
|
52
|
+
"AR",
|
|
53
|
+
"CL",
|
|
54
|
+
"CO",
|
|
55
|
+
"PE",
|
|
56
|
+
"EC",
|
|
57
|
+
"VE",
|
|
58
|
+
"UY",
|
|
59
|
+
"PY",
|
|
60
|
+
"BO",
|
|
61
|
+
"CR",
|
|
62
|
+
"PA",
|
|
63
|
+
"DO",
|
|
64
|
+
"GT",
|
|
65
|
+
"HN",
|
|
66
|
+
"SV",
|
|
67
|
+
"NI",
|
|
68
|
+
"CU"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
"fr": {
|
|
72
|
+
"nameCorpusLanguages": ["fr"],
|
|
73
|
+
"denyListCountries": [
|
|
74
|
+
"FR",
|
|
75
|
+
"BE",
|
|
76
|
+
"CH",
|
|
77
|
+
"CA",
|
|
78
|
+
"LU",
|
|
79
|
+
"MC"
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"hu": {
|
|
83
|
+
"nameCorpusLanguages": ["hu"],
|
|
84
|
+
"denyListCountries": ["HU"]
|
|
85
|
+
},
|
|
86
|
+
"it": {
|
|
87
|
+
"nameCorpusLanguages": ["it"],
|
|
88
|
+
"denyListCountries": ["IT", "CH"]
|
|
89
|
+
},
|
|
90
|
+
"pl": {
|
|
91
|
+
"nameCorpusLanguages": ["pl"],
|
|
92
|
+
"denyListCountries": ["PL"]
|
|
93
|
+
},
|
|
94
|
+
"pt-br": {
|
|
95
|
+
"nameCorpusLanguages": ["pt-br"],
|
|
96
|
+
"denyListCountries": ["BR"]
|
|
97
|
+
},
|
|
98
|
+
"ro": {
|
|
99
|
+
"nameCorpusLanguages": ["ro"],
|
|
100
|
+
"denyListCountries": ["RO", "MD"]
|
|
101
|
+
},
|
|
102
|
+
"sk": {
|
|
103
|
+
"nameCorpusLanguages": ["sk", "cs"],
|
|
104
|
+
"denyListCountries": ["SK", "CZ"]
|
|
105
|
+
},
|
|
106
|
+
"sv": {
|
|
107
|
+
"nameCorpusLanguages": ["sv"],
|
|
108
|
+
"denyListCountries": ["SE", "FI"]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const normalizeLanguage = (language) => language.trim().toLowerCase();
|
|
113
|
+
const fallbackLanguage = (language) => {
|
|
114
|
+
const index = language.indexOf("-");
|
|
115
|
+
return index === -1 ? null : language.slice(0, index);
|
|
116
|
+
};
|
|
117
|
+
const uniquePush = (target, values) => {
|
|
118
|
+
const seen = new Set(target);
|
|
119
|
+
for (const value of values) {
|
|
120
|
+
if (seen.has(value)) continue;
|
|
121
|
+
seen.add(value);
|
|
122
|
+
target.push(value);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const resolveLanguageScope = (language) => {
|
|
126
|
+
const normalized = normalizeLanguage(language);
|
|
127
|
+
if (normalized.length === 0) return null;
|
|
128
|
+
const exact = scopeData.languages[normalized];
|
|
129
|
+
if (exact !== void 0) return exact;
|
|
130
|
+
const fallback = fallbackLanguage(normalized);
|
|
131
|
+
return fallback === null ? null : scopeData.languages[fallback] ?? null;
|
|
132
|
+
};
|
|
133
|
+
const configuredLanguages = (config) => {
|
|
134
|
+
if (config.languages !== void 0) return config.languages;
|
|
135
|
+
return config.language === void 0 ? [] : [config.language];
|
|
136
|
+
};
|
|
137
|
+
const applyPipelineLanguageScope = (config) => {
|
|
138
|
+
const languages = configuredLanguages(config);
|
|
139
|
+
if (languages.length === 0) return config;
|
|
140
|
+
const nameCorpusLanguages = [];
|
|
141
|
+
const denyListCountries = [];
|
|
142
|
+
for (const language of languages) {
|
|
143
|
+
const scope = resolveLanguageScope(language);
|
|
144
|
+
if (scope === null) continue;
|
|
145
|
+
uniquePush(nameCorpusLanguages, scope.nameCorpusLanguages ?? []);
|
|
146
|
+
uniquePush(denyListCountries, scope.denyListCountries ?? []);
|
|
147
|
+
}
|
|
148
|
+
const next = {};
|
|
149
|
+
if (config.nameCorpusLanguages === void 0 && nameCorpusLanguages.length > 0) next.nameCorpusLanguages = nameCorpusLanguages;
|
|
150
|
+
if (config.denyListCountries === void 0 && denyListCountries.length > 0) next.denyListCountries = denyListCountries;
|
|
151
|
+
return Object.keys(next).length === 0 ? config : {
|
|
152
|
+
...config,
|
|
153
|
+
...next
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/types.ts
|
|
158
|
+
const isLegalFormsEnabled = (config) => config.enableLegalForms !== false;
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/util/language-selection.ts
|
|
161
|
+
const normalizeLanguageCode = (language) => language.trim().toLowerCase();
|
|
162
|
+
const normalizeLanguageSelection = (languages) => languages === void 0 ? [] : languages.map(normalizeLanguageCode).filter((language) => language.length > 0);
|
|
163
|
+
const languageSelectionKey = (languages) => {
|
|
164
|
+
const normalized = normalizeLanguageSelection(languages).toSorted();
|
|
165
|
+
return normalized.length === 0 ? "*" : normalized.join(",");
|
|
166
|
+
};
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/pipeline-cache-key.ts
|
|
169
|
+
const DEFAULT_CUSTOM_REGEX_SCORE = .9;
|
|
170
|
+
const contentLanguageFingerprint = (config) => {
|
|
171
|
+
return languageSelectionKey(config.languages ?? (config.language === void 0 ? [] : [config.language]));
|
|
172
|
+
};
|
|
173
|
+
const pipelineConfigKey = (config, gazetteerEntries) => {
|
|
174
|
+
const legalFormsEnabled = isLegalFormsEnabled(config);
|
|
175
|
+
const customDenyFingerprint = config.enableDenyList && config.customDenyList ? config.customDenyList.map((entry) => JSON.stringify({
|
|
176
|
+
label: entry.label,
|
|
177
|
+
value: entry.value,
|
|
178
|
+
variants: [...entry.variants ?? []].sort()
|
|
179
|
+
})).sort().join("\n") : "";
|
|
180
|
+
const customRegexFingerprint = config.enableRegex && config.customRegexes ? config.customRegexes.map((entry) => JSON.stringify({
|
|
181
|
+
label: entry.label,
|
|
182
|
+
pattern: entry.pattern,
|
|
183
|
+
preparedArtifactPolicy: entry.preparedArtifactPolicy ?? null,
|
|
184
|
+
score: entry.score ?? DEFAULT_CUSTOM_REGEX_SCORE
|
|
185
|
+
})).sort().join("\n") : "";
|
|
186
|
+
const gazFingerprint = config.enableGazetteer && gazetteerEntries.length > 0 ? gazetteerEntries.map((entry) => `${entry.id}:${entry.canonical}:${entry.label}:${[...entry.variants].sort().join(",")}`).toSorted().join(";") : "";
|
|
187
|
+
return `${config.enableDenyList}:${config.enableTriggerPhrases}:${legalFormsEnabled}:${config.enableNameCorpus}:${contentLanguageFingerprint(config)}:${config.nameCorpusLanguages?.toSorted().join(",") ?? ""}:${config.enableRegex}:${config.threshold}:${config.enableConfidenceBoost}:${config.enableHotwordRules === true}:${config.enableCoreference === true}:${config.enableZoneClassification === true}:${config.labels.toSorted().join(",")}:${config.denyListCountries?.toSorted().join(",") ?? ""}:${config.denyListRegions?.toSorted().join(",") ?? ""}:${config.denyListExcludeCategories?.toSorted().join(",") ?? ""}:${customDenyFingerprint}:${customRegexFingerprint}:${config.enableGazetteer}:${gazFingerprint}:${config.enableCountries !== false}`;
|
|
188
|
+
};
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/native-pipeline.ts
|
|
191
|
+
const sharedPackageByDictionaries = /* @__PURE__ */ new WeakMap();
|
|
192
|
+
const sharedPackageWithoutDictionaries = /* @__PURE__ */ new Map();
|
|
193
|
+
const dictionaryCacheIds = /* @__PURE__ */ new WeakMap();
|
|
194
|
+
let nextDictionaryCacheId = 0;
|
|
195
|
+
const dictionaryCacheKey = (dictionaries) => {
|
|
196
|
+
if (dictionaries === void 0) return "none";
|
|
197
|
+
const existing = dictionaryCacheIds.get(dictionaries);
|
|
198
|
+
if (existing !== void 0) return `dict:${existing}`;
|
|
199
|
+
nextDictionaryCacheId += 1;
|
|
200
|
+
dictionaryCacheIds.set(dictionaries, nextDictionaryCacheId);
|
|
201
|
+
return `dict:${nextDictionaryCacheId}`;
|
|
202
|
+
};
|
|
203
|
+
const sharedPackageCacheFor = (dictionaries) => {
|
|
204
|
+
if (dictionaries === void 0) return sharedPackageWithoutDictionaries;
|
|
205
|
+
const cached = sharedPackageByDictionaries.get(dictionaries);
|
|
206
|
+
if (cached !== void 0) return cached;
|
|
207
|
+
const created = /* @__PURE__ */ new Map();
|
|
208
|
+
sharedPackageByDictionaries.set(dictionaries, created);
|
|
209
|
+
return created;
|
|
210
|
+
};
|
|
211
|
+
const getNativePipelineCompatibility = (config) => {
|
|
212
|
+
const unsupportedFeatures = [];
|
|
213
|
+
if (config.enableNer) unsupportedFeatures.push("enableNer");
|
|
214
|
+
if (unsupportedFeatures.length === 0) return { status: "supported" };
|
|
215
|
+
return {
|
|
216
|
+
status: "unsupported",
|
|
217
|
+
unsupportedFeatures
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
const assertNativePipelineSupported = (config) => {
|
|
221
|
+
const compatibility = getNativePipelineCompatibility(config);
|
|
222
|
+
if (compatibility.status === "supported") return;
|
|
223
|
+
throw new Error(`Native pipeline does not yet support: ${compatibility.unsupportedFeatures.join(", ")}`);
|
|
224
|
+
};
|
|
225
|
+
const encoder = new TextEncoder();
|
|
226
|
+
/**
|
|
227
|
+
* Serialize the assembler inputs the Rust binding expects. Dictionaries are
|
|
228
|
+
* stripped from the pipeline config and passed out of band: the assembler reads
|
|
229
|
+
* the separate bundle preferentially, and keeping the (large) dictionaries out
|
|
230
|
+
* of the config JSON avoids serializing them twice.
|
|
231
|
+
*/
|
|
232
|
+
const toAssembleInputs = ({ dictionaries, ...config }, gazetteerEntries) => ({
|
|
233
|
+
pipelineConfigJson: encoder.encode(JSON.stringify(config)),
|
|
234
|
+
dictionariesJson: dictionaries === void 0 ? void 0 : encoder.encode(JSON.stringify(dictionaries)),
|
|
235
|
+
gazetteerJson: gazetteerEntries.length === 0 ? void 0 : encoder.encode(JSON.stringify(gazetteerEntries))
|
|
236
|
+
});
|
|
237
|
+
const assemblePackageBytes = (binding, { pipelineConfigJson, dictionariesJson, gazetteerJson }, compressed) => {
|
|
238
|
+
const assemble = compressed ? binding.assembleStaticSearchCompressedPackageBytes : binding.assembleStaticSearchPackageBytes;
|
|
239
|
+
if (assemble === void 0) throw new Error("Native anonymize binding does not support static-search config assembly");
|
|
240
|
+
return assemble(pipelineConfigJson, dictionariesJson, gazetteerJson);
|
|
241
|
+
};
|
|
242
|
+
const prepareNativePipelineConfig = async ({ binding, config, gazetteerEntries = [] }) => {
|
|
243
|
+
const scopedConfig = applyPipelineLanguageScope(config);
|
|
244
|
+
assertNativePipelineSupported(scopedConfig);
|
|
245
|
+
const assemble = binding.assembleStaticSearchConfigJson;
|
|
246
|
+
if (assemble === void 0) throw new Error("Native anonymize binding does not support static-search config assembly");
|
|
247
|
+
const { pipelineConfigJson, dictionariesJson, gazetteerJson } = toAssembleInputs(scopedConfig, gazetteerEntries);
|
|
248
|
+
const configJson = assemble(pipelineConfigJson, dictionariesJson, gazetteerJson);
|
|
249
|
+
return JSON.parse(new TextDecoder().decode(configJson));
|
|
250
|
+
};
|
|
251
|
+
const prepareNativePipelinePackage = async ({ binding, config, gazetteerEntries = [], context, compressed = false }) => {
|
|
252
|
+
const packageBytes = await getCachedNativePipelinePackage({
|
|
253
|
+
config,
|
|
254
|
+
binding,
|
|
255
|
+
gazetteerEntries,
|
|
256
|
+
...context ? { context } : {},
|
|
257
|
+
compressed
|
|
258
|
+
});
|
|
259
|
+
return new Uint8Array(packageBytes);
|
|
260
|
+
};
|
|
261
|
+
const createNativePipelineFromConfig = async ({ binding, config, gazetteerEntries = [], context }) => {
|
|
262
|
+
return createNativePipelineFromPackage({
|
|
263
|
+
binding,
|
|
264
|
+
packageBytes: await getCachedNativePipelinePackage({
|
|
265
|
+
binding,
|
|
266
|
+
config,
|
|
267
|
+
gazetteerEntries,
|
|
268
|
+
...context ? { context } : {}
|
|
269
|
+
})
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
const getCachedNativePipelinePackage = async ({ binding, config, gazetteerEntries = [], context, compressed = false }) => {
|
|
273
|
+
const scopedConfig = applyPipelineLanguageScope(config);
|
|
274
|
+
assertNativePipelineSupported(scopedConfig);
|
|
275
|
+
const ctx = context ?? defaultContext;
|
|
276
|
+
const key = nativePackageCacheKey({
|
|
277
|
+
binding,
|
|
278
|
+
config: scopedConfig,
|
|
279
|
+
gazetteerEntries,
|
|
280
|
+
compressed
|
|
281
|
+
});
|
|
282
|
+
if (ctx.nativePipelinePackage && ctx.nativePipelinePackageKey === key) return ctx.nativePipelinePackage;
|
|
283
|
+
if (ctx.nativePipelinePackagePromise && ctx.nativePipelinePackageKey === key) return ctx.nativePipelinePackagePromise;
|
|
284
|
+
const sharedCache = sharedPackageCacheFor(scopedConfig.dictionaries);
|
|
285
|
+
const shared = sharedCache.get(key);
|
|
286
|
+
if (shared !== void 0) {
|
|
287
|
+
const packageBytes = await shared;
|
|
288
|
+
ctx.nativePipelinePackage = packageBytes;
|
|
289
|
+
ctx.nativePipelinePackageKey = key;
|
|
290
|
+
ctx.nativePipelinePackagePromise = null;
|
|
291
|
+
return packageBytes;
|
|
292
|
+
}
|
|
293
|
+
ctx.nativePipelinePackage = null;
|
|
294
|
+
ctx.nativePipelinePackageKey = key;
|
|
295
|
+
const promise = buildNativePipelinePackage({
|
|
296
|
+
binding,
|
|
297
|
+
config: scopedConfig,
|
|
298
|
+
gazetteerEntries,
|
|
299
|
+
compressed
|
|
300
|
+
});
|
|
301
|
+
ctx.nativePipelinePackagePromise = promise;
|
|
302
|
+
sharedCache.set(key, promise);
|
|
303
|
+
let packageBytes;
|
|
304
|
+
try {
|
|
305
|
+
packageBytes = await promise;
|
|
306
|
+
} catch (error) {
|
|
307
|
+
if (sharedCache.get(key) === promise) sharedCache.delete(key);
|
|
308
|
+
if (ctx.nativePipelinePackageKey === key && ctx.nativePipelinePackagePromise === promise) {
|
|
309
|
+
ctx.nativePipelinePackage = null;
|
|
310
|
+
ctx.nativePipelinePackagePromise = null;
|
|
311
|
+
}
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
if (sharedCache.get(key) === promise) sharedCache.set(key, packageBytes);
|
|
315
|
+
if (ctx.nativePipelinePackageKey === key) {
|
|
316
|
+
ctx.nativePipelinePackage = packageBytes;
|
|
317
|
+
ctx.nativePipelinePackagePromise = null;
|
|
318
|
+
}
|
|
319
|
+
return packageBytes;
|
|
320
|
+
};
|
|
321
|
+
const buildNativePipelinePackage = async ({ binding, config, gazetteerEntries, compressed }) => assemblePackageBytes(binding, toAssembleInputs(config, gazetteerEntries), compressed);
|
|
322
|
+
const nativePackageCacheKey = ({ binding, config, gazetteerEntries, compressed }) => [
|
|
323
|
+
binding.nativePackageVersion(),
|
|
324
|
+
compressed ? "compressed" : "raw",
|
|
325
|
+
dictionaryCacheKey(config.dictionaries),
|
|
326
|
+
pipelineConfigKey(config, gazetteerEntries)
|
|
327
|
+
].join(":");
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/native-default-config.ts
|
|
330
|
+
const DEFAULT_NATIVE_PIPELINE_CONFIG = {
|
|
331
|
+
threshold: .3,
|
|
332
|
+
enableTriggerPhrases: true,
|
|
333
|
+
enableRegex: true,
|
|
334
|
+
enableLegalForms: true,
|
|
335
|
+
enableNameCorpus: true,
|
|
336
|
+
enableDenyList: true,
|
|
337
|
+
enableGazetteer: false,
|
|
338
|
+
enableCountries: true,
|
|
339
|
+
enableNer: false,
|
|
340
|
+
enableConfidenceBoost: true,
|
|
341
|
+
enableCoreference: true,
|
|
342
|
+
enableHotwordRules: true,
|
|
343
|
+
enableZoneClassification: true,
|
|
344
|
+
labels: [...DEFAULT_ENTITY_LABELS],
|
|
345
|
+
workspaceId: "native-pipeline-default"
|
|
346
|
+
};
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/native-node.ts
|
|
349
|
+
const DEFAULT_NATIVE_PIPELINE_WARMUPS = {
|
|
350
|
+
lazyRegex: "lazy-regex",
|
|
351
|
+
none: "none"
|
|
352
|
+
};
|
|
353
|
+
const LOCAL_NATIVE_LOADER = "../index.cjs";
|
|
354
|
+
const PACKAGE_SPECIFIC_NATIVE_PATH = "STELLA_ANONYMIZE_NATIVE_LIBRARY_PATH";
|
|
355
|
+
const DEFAULT_NATIVE_PIPELINE_PACKAGE_URL = new URL("../native-pipeline.stlanonpkg", import.meta.url);
|
|
356
|
+
const DEFAULT_NATIVE_PIPELINE_PACKAGE_DIR_URL = new URL("../", import.meta.url);
|
|
357
|
+
const DEFAULT_NATIVE_PIPELINE_LANGUAGE_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
358
|
+
const DEFAULT_NATIVE_PIPELINE_LANGUAGE_PACKAGE_PATTERN = /^native-pipeline\.([a-z0-9]+(?:-[a-z0-9]+)*)\.stlanonpkg$/u;
|
|
359
|
+
const DEFAULT_NATIVE_PIPELINE_PACKAGE_CACHE_KEY = "<default>";
|
|
360
|
+
const defaultNativePipelineCache = /* @__PURE__ */ new WeakMap();
|
|
361
|
+
const warmedDefaultNativePipelines = /* @__PURE__ */ new WeakSet();
|
|
362
|
+
const defaultNativePipelineInflightCache = /* @__PURE__ */ new WeakMap();
|
|
363
|
+
const loadNativeAnonymizeBinding = (options = {}) => {
|
|
364
|
+
const requireModule = options.requireModule ?? createRequire(import.meta.url);
|
|
365
|
+
const platform = options.platform ?? process.platform;
|
|
366
|
+
const arch = options.arch ?? process.arch;
|
|
367
|
+
const libc = options.libc ?? detectNativeLibc(platform);
|
|
368
|
+
const specifiers = nativeBindingSpecifiers({
|
|
369
|
+
arch,
|
|
370
|
+
env: options.env ?? process.env,
|
|
371
|
+
libc,
|
|
372
|
+
platform
|
|
373
|
+
});
|
|
374
|
+
const errors = [];
|
|
375
|
+
for (const specifier of specifiers) {
|
|
376
|
+
const binding = tryLoadNativeBinding({
|
|
377
|
+
specifier,
|
|
378
|
+
requireModule,
|
|
379
|
+
errors
|
|
380
|
+
});
|
|
381
|
+
if (!binding) continue;
|
|
382
|
+
if (options.expectedVersion !== void 0) assertNativeBindingVersion({
|
|
383
|
+
binding,
|
|
384
|
+
expectedVersion: options.expectedVersion
|
|
385
|
+
});
|
|
386
|
+
return binding;
|
|
387
|
+
}
|
|
388
|
+
if (nativeBindingPackageName({
|
|
389
|
+
arch,
|
|
390
|
+
libc,
|
|
391
|
+
platform
|
|
392
|
+
}) === null) throw unsupportedNativeTargetError({
|
|
393
|
+
arch,
|
|
394
|
+
errors,
|
|
395
|
+
libc,
|
|
396
|
+
platform
|
|
397
|
+
});
|
|
398
|
+
throw new Error(`Unable to load native anonymize binding for ${platform}/${arch}:\n${errors.join("\n")}`);
|
|
399
|
+
};
|
|
400
|
+
const readNativePipelinePackageFile = (packagePath) => readFileSync(packagePath);
|
|
401
|
+
const readNativePipelinePackageFileAsync = async (packagePath) => readFile(packagePath);
|
|
402
|
+
const native_package_version = (options = {}) => native_package_version$1(resolveNativeSdkBinding(options));
|
|
403
|
+
const normalize_for_search = (text, options = {}) => {
|
|
404
|
+
return normalize_for_search$1({
|
|
405
|
+
binding: resolveNativeSdkBinding(options),
|
|
406
|
+
text
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
const prepare_search_package = (config, { compressed = false, ...options } = {}) => prepare_search_package$1({
|
|
410
|
+
binding: resolveNativeSdkBinding(options),
|
|
411
|
+
config,
|
|
412
|
+
compressed
|
|
413
|
+
});
|
|
414
|
+
const load_prepared_package = (packageBytes, options = {}) => load_prepared_package$1({
|
|
415
|
+
binding: resolveNativeSdkBinding(options),
|
|
416
|
+
packageBytes
|
|
417
|
+
});
|
|
418
|
+
const load_prepared_package_file = (packagePath, options = {}) => load_prepared_package(readNativePipelinePackageFile(packagePath), options);
|
|
419
|
+
const redact_text = (config, fullText, operators, options = {}) => redact_text$1({
|
|
420
|
+
binding: resolveNativeSdkBinding(options),
|
|
421
|
+
config,
|
|
422
|
+
fullText,
|
|
423
|
+
...operators !== void 0 ? { operators } : {}
|
|
424
|
+
});
|
|
425
|
+
const redact_text_json = (config, fullText, operators, options = {}) => redact_text_json$1({
|
|
426
|
+
binding: resolveNativeSdkBinding(options),
|
|
427
|
+
config,
|
|
428
|
+
fullText,
|
|
429
|
+
...operators !== void 0 ? { operators } : {}
|
|
430
|
+
});
|
|
431
|
+
const redact_text_stream_json = (config, fullText, onEvent, operators, options = {}) => redact_text_stream_json$1({
|
|
432
|
+
binding: resolveNativeSdkBinding(options),
|
|
433
|
+
config,
|
|
434
|
+
fullText,
|
|
435
|
+
onEvent,
|
|
436
|
+
...operators !== void 0 ? { operators } : {}
|
|
437
|
+
});
|
|
438
|
+
const diagnostics_json = (config, fullText, operators, options = {}) => diagnostics_json$1({
|
|
439
|
+
binding: resolveNativeSdkBinding(options),
|
|
440
|
+
config,
|
|
441
|
+
fullText,
|
|
442
|
+
...operators !== void 0 ? { operators } : {}
|
|
443
|
+
});
|
|
444
|
+
const diagnostics_stream_json = (config, fullText, onBatch, operators, options = {}) => diagnostics_stream_json$1({
|
|
445
|
+
binding: resolveNativeSdkBinding(options),
|
|
446
|
+
config,
|
|
447
|
+
fullText,
|
|
448
|
+
onBatch,
|
|
449
|
+
...operators !== void 0 ? { operators } : {}
|
|
450
|
+
});
|
|
451
|
+
const summary_diagnostics_json = (config, fullText, operators, options = {}) => summary_diagnostics_json$1({
|
|
452
|
+
binding: resolveNativeSdkBinding(options),
|
|
453
|
+
config,
|
|
454
|
+
fullText,
|
|
455
|
+
...operators !== void 0 ? { operators } : {}
|
|
456
|
+
});
|
|
457
|
+
const readDefaultNativePipelinePackageFile = ({ language } = {}) => {
|
|
458
|
+
const packageUrl = defaultNativePipelinePackageUrl(language);
|
|
459
|
+
try {
|
|
460
|
+
return readFileSync(packageUrl);
|
|
461
|
+
} catch (error) {
|
|
462
|
+
throw new Error(`${defaultNativePipelinePackageDescription(language)} is unavailable: ${formatLoadError(error)}`);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
const read_default_native_pipeline_package_file = (options = {}) => readDefaultNativePipelinePackageFile(options);
|
|
466
|
+
const availableDefaultNativePipelineLanguages = () => {
|
|
467
|
+
const languages = /* @__PURE__ */ new Set();
|
|
468
|
+
try {
|
|
469
|
+
for (const fileName of readdirSync(DEFAULT_NATIVE_PIPELINE_PACKAGE_DIR_URL)) {
|
|
470
|
+
const match = fileName.match(DEFAULT_NATIVE_PIPELINE_LANGUAGE_PACKAGE_PATTERN);
|
|
471
|
+
if (match?.[1] !== void 0) languages.add(match[1]);
|
|
472
|
+
}
|
|
473
|
+
} catch (error) {
|
|
474
|
+
throw new Error(`Default native pipeline package directory is unavailable: ${formatLoadError(error)}`);
|
|
475
|
+
}
|
|
476
|
+
return [...languages].toSorted();
|
|
477
|
+
};
|
|
478
|
+
const available_default_native_pipeline_languages = availableDefaultNativePipelineLanguages;
|
|
479
|
+
const readDefaultNativePipelinePackageFileAsync = async ({ language } = {}) => {
|
|
480
|
+
const packageUrl = defaultNativePipelinePackageUrl(language);
|
|
481
|
+
try {
|
|
482
|
+
return await readFile(packageUrl);
|
|
483
|
+
} catch (error) {
|
|
484
|
+
throw new Error(`${defaultNativePipelinePackageDescription(language)} is unavailable: ${formatLoadError(error)}`);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
const createNativePipelineFromPackageFile = ({ binding, packagePath, expectedVersion, ...loadOptions }) => {
|
|
488
|
+
const resolvedBinding = binding ?? loadNativeAnonymizeBinding({
|
|
489
|
+
...loadOptions,
|
|
490
|
+
...expectedVersion !== void 0 ? { expectedVersion } : {}
|
|
491
|
+
});
|
|
492
|
+
if (binding && expectedVersion !== void 0) assertNativeBindingVersion({
|
|
493
|
+
binding,
|
|
494
|
+
expectedVersion
|
|
495
|
+
});
|
|
496
|
+
return createNativePipelineFromPackage({
|
|
497
|
+
binding: resolvedBinding,
|
|
498
|
+
packageBytes: readNativePipelinePackageFile(packagePath)
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
const createNativePipelineFromDefaultPackage = (options = {}) => {
|
|
502
|
+
const resolvedOptions = resolveDefaultNativePipelineOptions(options);
|
|
503
|
+
return applyDefaultNativePipelineWarmup(createNativePipelineFromResolvedDefaultPackage(resolvedOptions), resolvedOptions.warmup);
|
|
504
|
+
};
|
|
505
|
+
const create_native_pipeline_from_default_package = (options = {}) => createNativePipelineFromDefaultPackage(options);
|
|
506
|
+
const getDefaultNativePipeline = (options = {}) => {
|
|
507
|
+
const resolvedOptions = resolveDefaultNativePipelineOptions(options);
|
|
508
|
+
const cache = defaultPipelineCacheFor(resolvedOptions.binding);
|
|
509
|
+
const key = defaultPipelineCacheKey(resolvedOptions);
|
|
510
|
+
const cached = cache.get(key);
|
|
511
|
+
if (cached !== void 0) return applyDefaultNativePipelineWarmup(cached, resolvedOptions.warmup);
|
|
512
|
+
const pipeline = createNativePipelineFromResolvedDefaultPackage(resolvedOptions);
|
|
513
|
+
cache.set(key, pipeline);
|
|
514
|
+
return applyDefaultNativePipelineWarmup(pipeline, resolvedOptions.warmup);
|
|
515
|
+
};
|
|
516
|
+
const get_default_native_pipeline = (options = {}) => getDefaultNativePipeline(options);
|
|
517
|
+
const preloadDefaultNativePipeline = (options = {}) => {
|
|
518
|
+
return applyDefaultNativePipelineWarmup(getDefaultNativePipeline(options), DEFAULT_NATIVE_PIPELINE_WARMUPS.lazyRegex);
|
|
519
|
+
};
|
|
520
|
+
const preload_default_native_pipeline = (options = {}) => preloadDefaultNativePipeline(options);
|
|
521
|
+
const redactDefaultText = (fullText, operators, options = {}) => getDefaultNativePipeline(options).redactText(fullText, operators);
|
|
522
|
+
const redact_default_text = (fullText, operators, options = {}) => redactDefaultText(fullText, operators, options);
|
|
523
|
+
const redactDefaultTextJson = (fullText, operators, options = {}) => getDefaultNativePipeline(options).redact_text_json(fullText, operators);
|
|
524
|
+
const redact_default_text_json = (fullText, operators, options = {}) => redactDefaultTextJson(fullText, operators, options);
|
|
525
|
+
const preloadDefaultNativePipelineAsync = (options = {}) => {
|
|
526
|
+
const resolvedOptions = {
|
|
527
|
+
...resolveDefaultNativePipelineOptions(options),
|
|
528
|
+
warmup: DEFAULT_NATIVE_PIPELINE_WARMUPS.lazyRegex
|
|
529
|
+
};
|
|
530
|
+
const cache = defaultPipelineCacheFor(resolvedOptions.binding);
|
|
531
|
+
const key = defaultPipelineCacheKey(resolvedOptions);
|
|
532
|
+
const cached = cache.get(key);
|
|
533
|
+
if (cached !== void 0) return Promise.resolve(applyDefaultNativePipelineWarmup(cached, resolvedOptions.warmup));
|
|
534
|
+
const inflightCache = defaultPipelineInflightCacheFor(resolvedOptions.binding);
|
|
535
|
+
const inflight = inflightCache.get(key);
|
|
536
|
+
if (inflight !== void 0) return inflight;
|
|
537
|
+
const promise = createNativePipelineFromResolvedDefaultPackageAsync(resolvedOptions).then((pipeline) => {
|
|
538
|
+
cache.set(key, pipeline);
|
|
539
|
+
return applyDefaultNativePipelineWarmup(pipeline, resolvedOptions.warmup);
|
|
540
|
+
}).finally(() => {
|
|
541
|
+
inflightCache.delete(key);
|
|
542
|
+
});
|
|
543
|
+
inflightCache.set(key, promise);
|
|
544
|
+
return promise;
|
|
545
|
+
};
|
|
546
|
+
const resolveDefaultNativePipelineOptions = ({ binding, language, packagePath, warmup, expectedVersion, ...loadOptions } = {}) => {
|
|
547
|
+
if (language !== void 0 && packagePath !== void 0) throw new Error("Use either language or packagePath, not both");
|
|
548
|
+
const resolvedBinding = binding ?? loadNativeAnonymizeBinding({
|
|
549
|
+
...loadOptions,
|
|
550
|
+
...expectedVersion !== void 0 ? { expectedVersion } : {}
|
|
551
|
+
});
|
|
552
|
+
if (binding && expectedVersion !== void 0) assertNativeBindingVersion({
|
|
553
|
+
binding,
|
|
554
|
+
expectedVersion
|
|
555
|
+
});
|
|
556
|
+
return {
|
|
557
|
+
binding: resolvedBinding,
|
|
558
|
+
warmup: normalizeDefaultNativePipelineWarmup(warmup),
|
|
559
|
+
...language !== void 0 ? { language: resolveDefaultNativePipelineLanguage(language) } : {},
|
|
560
|
+
...packagePath !== void 0 ? { packagePath } : {}
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
const applyDefaultNativePipelineWarmup = (pipeline, warmup) => {
|
|
564
|
+
if (warmup !== DEFAULT_NATIVE_PIPELINE_WARMUPS.lazyRegex) return pipeline;
|
|
565
|
+
if (!warmedDefaultNativePipelines.has(pipeline)) {
|
|
566
|
+
pipeline.warmLazyRegex();
|
|
567
|
+
warmedDefaultNativePipelines.add(pipeline);
|
|
568
|
+
}
|
|
569
|
+
return pipeline;
|
|
570
|
+
};
|
|
571
|
+
const createNativePipelineFromResolvedDefaultPackage = ({ binding, language, packagePath }) => {
|
|
572
|
+
return createNativePipelineFromTrustedDefaultPackage(binding, packagePath === void 0 ? readDefaultNativePipelinePackageFile(defaultPackageFileOptions(language)) : readNativePipelinePackageFile(packagePath));
|
|
573
|
+
};
|
|
574
|
+
const createNativePipelineFromResolvedDefaultPackageAsync = async ({ binding, language, packagePath }) => {
|
|
575
|
+
return createNativePipelineFromTrustedDefaultPackage(binding, packagePath === void 0 ? await readDefaultNativePipelinePackageFileAsync(defaultPackageFileOptions(language)) : await readNativePipelinePackageFileAsync(packagePath));
|
|
576
|
+
};
|
|
577
|
+
const createNativePipelineFromTrustedDefaultPackage = (binding, packageBytes) => new PreparedNativePipeline(new PreparedNativeAnonymizer(binding.NativePreparedSearch.fromTrustedPreparedPackageBytesWithoutCache?.(packageBytes) ?? binding.NativePreparedSearch.fromTrustedPreparedPackageBytes?.(packageBytes) ?? binding.NativePreparedSearch.fromPreparedPackageBytesWithoutCache?.(packageBytes) ?? binding.NativePreparedSearch.fromPreparedPackageBytes(packageBytes)));
|
|
578
|
+
const defaultPackageFileOptions = (language) => language === void 0 ? {} : { language };
|
|
579
|
+
const normalizeDefaultNativePipelineWarmup = (warmup) => {
|
|
580
|
+
if (warmup === void 0) return DEFAULT_NATIVE_PIPELINE_WARMUPS.none;
|
|
581
|
+
switch (warmup) {
|
|
582
|
+
case DEFAULT_NATIVE_PIPELINE_WARMUPS.lazyRegex:
|
|
583
|
+
case DEFAULT_NATIVE_PIPELINE_WARMUPS.none: return warmup;
|
|
584
|
+
}
|
|
585
|
+
throw new Error("Default native pipeline warmup must be \"lazy-regex\" or \"none\"");
|
|
586
|
+
};
|
|
587
|
+
const resolveNativeSdkBinding = ({ binding, expectedVersion, ...loadOptions }) => {
|
|
588
|
+
const resolvedBinding = binding ?? loadNativeAnonymizeBinding({
|
|
589
|
+
...loadOptions,
|
|
590
|
+
...expectedVersion !== void 0 ? { expectedVersion } : {}
|
|
591
|
+
});
|
|
592
|
+
if (binding && expectedVersion !== void 0) assertNativeBindingVersion({
|
|
593
|
+
binding,
|
|
594
|
+
expectedVersion
|
|
595
|
+
});
|
|
596
|
+
return resolvedBinding;
|
|
597
|
+
};
|
|
598
|
+
const defaultPipelineCacheFor = (binding) => {
|
|
599
|
+
const cached = defaultNativePipelineCache.get(binding);
|
|
600
|
+
if (cached !== void 0) return cached;
|
|
601
|
+
const created = /* @__PURE__ */ new Map();
|
|
602
|
+
defaultNativePipelineCache.set(binding, created);
|
|
603
|
+
return created;
|
|
604
|
+
};
|
|
605
|
+
const defaultPipelineInflightCacheFor = (binding) => {
|
|
606
|
+
const cached = defaultNativePipelineInflightCache.get(binding);
|
|
607
|
+
if (cached !== void 0) return cached;
|
|
608
|
+
const created = /* @__PURE__ */ new Map();
|
|
609
|
+
defaultNativePipelineInflightCache.set(binding, created);
|
|
610
|
+
return created;
|
|
611
|
+
};
|
|
612
|
+
const defaultPipelineCacheKey = ({ binding, language, packagePath }) => [binding.nativePackageVersion(), packagePath ?? (language === void 0 ? DEFAULT_NATIVE_PIPELINE_PACKAGE_CACHE_KEY : `language:${language}`)].join("\0");
|
|
613
|
+
const defaultNativePipelinePackageUrl = (language) => {
|
|
614
|
+
if (language === void 0) return DEFAULT_NATIVE_PIPELINE_PACKAGE_URL;
|
|
615
|
+
return defaultNativePipelineLanguagePackageUrl(resolveDefaultNativePipelineLanguage(language));
|
|
616
|
+
};
|
|
617
|
+
const defaultNativePipelineLanguagePackageUrl = (language) => new URL(`../native-pipeline.${language}.stlanonpkg`, import.meta.url);
|
|
618
|
+
const resolveDefaultNativePipelineLanguage = (language) => {
|
|
619
|
+
const normalized = normalizeDefaultNativePipelineLanguage(language);
|
|
620
|
+
if (existsSync(defaultNativePipelineLanguagePackageUrl(normalized))) return normalized;
|
|
621
|
+
const baseLanguage = normalized.split("-").at(0);
|
|
622
|
+
if (baseLanguage === void 0 || baseLanguage === normalized) return normalized;
|
|
623
|
+
if (existsSync(defaultNativePipelineLanguagePackageUrl(baseLanguage))) return baseLanguage;
|
|
624
|
+
return normalized;
|
|
625
|
+
};
|
|
626
|
+
const defaultNativePipelinePackageDescription = (language) => language === void 0 ? "Default native pipeline package" : `Default native pipeline package for language "${resolveDefaultNativePipelineLanguage(language)}"`;
|
|
627
|
+
const normalizeDefaultNativePipelineLanguage = (language) => {
|
|
628
|
+
const normalized = language.trim().toLowerCase();
|
|
629
|
+
if (!DEFAULT_NATIVE_PIPELINE_LANGUAGE_PATTERN.test(normalized)) throw new Error(`Default native pipeline language must match ${DEFAULT_NATIVE_PIPELINE_LANGUAGE_PATTERN.source}`);
|
|
630
|
+
return normalized;
|
|
631
|
+
};
|
|
632
|
+
const nativeBindingSpecifiers = ({ arch, env, libc, platform }) => {
|
|
633
|
+
const specifiers = [];
|
|
634
|
+
const overridePath = env[PACKAGE_SPECIFIC_NATIVE_PATH];
|
|
635
|
+
if (overridePath) specifiers.push(overridePath);
|
|
636
|
+
specifiers.push(LOCAL_NATIVE_LOADER);
|
|
637
|
+
const platformPackage = nativeBindingPackageName({
|
|
638
|
+
arch,
|
|
639
|
+
libc,
|
|
640
|
+
platform
|
|
641
|
+
});
|
|
642
|
+
if (platformPackage !== null) specifiers.push(platformPackage);
|
|
643
|
+
return specifiers;
|
|
644
|
+
};
|
|
645
|
+
const NATIVE_BINDING_TARGETS = [
|
|
646
|
+
{
|
|
647
|
+
platform: "darwin",
|
|
648
|
+
arch: "arm64",
|
|
649
|
+
package: "@stll/anonymize-darwin-arm64"
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
platform: "darwin",
|
|
653
|
+
arch: "x64",
|
|
654
|
+
package: "@stll/anonymize-darwin-x64"
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
platform: "linux",
|
|
658
|
+
arch: "arm64",
|
|
659
|
+
libc: "gnu",
|
|
660
|
+
package: "@stll/anonymize-linux-arm64-gnu"
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
platform: "linux",
|
|
664
|
+
arch: "x64",
|
|
665
|
+
libc: "gnu",
|
|
666
|
+
package: "@stll/anonymize-linux-x64-gnu"
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
platform: "win32",
|
|
670
|
+
arch: "x64",
|
|
671
|
+
package: "@stll/anonymize-win32-x64-msvc"
|
|
672
|
+
}
|
|
673
|
+
];
|
|
674
|
+
const describeNativeTarget = ({ arch, libc, platform }) => libc === void 0 ? `${platform}-${arch}` : `${platform}-${arch}-${libc}`;
|
|
675
|
+
const SUPPORTED_NATIVE_TARGETS = NATIVE_BINDING_TARGETS.map((target) => describeNativeTarget(target));
|
|
676
|
+
const nativeBindingPackageName = ({ arch, libc, platform }) => {
|
|
677
|
+
return NATIVE_BINDING_TARGETS.find((target) => target.platform === platform && target.arch === arch && (target.libc === void 0 || target.libc === libc))?.package ?? null;
|
|
678
|
+
};
|
|
679
|
+
const unsupportedNativeTargetError = ({ arch, errors, libc, platform }) => {
|
|
680
|
+
const target = describeNativeTarget({
|
|
681
|
+
arch,
|
|
682
|
+
libc,
|
|
683
|
+
platform
|
|
684
|
+
});
|
|
685
|
+
const supported = SUPPORTED_NATIVE_TARGETS.join(", ");
|
|
686
|
+
const attempts = errors.length > 0 ? `\n${errors.join("\n")}` : "";
|
|
687
|
+
return /* @__PURE__ */ new Error(`No native anonymize binding is published for ${target}; supported targets: ${supported}. Set ${PACKAGE_SPECIFIC_NATIVE_PATH} to a locally built binding to run on this platform.${attempts}`);
|
|
688
|
+
};
|
|
689
|
+
const detectNativeLibc = (platform) => {
|
|
690
|
+
if (platform !== "linux") return;
|
|
691
|
+
const report = process.report?.getReport();
|
|
692
|
+
return typeof (isPropertyBag(report) && isPropertyBag(report["header"]) ? report["header"] : null)?.["glibcVersionRuntime"] === "string" ? "gnu" : "musl";
|
|
693
|
+
};
|
|
694
|
+
const tryLoadNativeBinding = ({ specifier, requireModule, errors }) => {
|
|
695
|
+
try {
|
|
696
|
+
const binding = toNativeAnonymizeBinding(requireModule(specifier));
|
|
697
|
+
if (binding) return binding;
|
|
698
|
+
errors.push(`${specifier}: module does not match native binding shape`);
|
|
699
|
+
} catch (error) {
|
|
700
|
+
errors.push(`${specifier}: ${formatLoadError(error)}`);
|
|
701
|
+
}
|
|
702
|
+
return null;
|
|
703
|
+
};
|
|
704
|
+
const toNativeAnonymizeBinding = (value) => {
|
|
705
|
+
const candidate = isPropertyBag(value) && isPropertyBag(value["default"]) ? value["default"] : value;
|
|
706
|
+
return isNativeAnonymizeBinding(candidate) ? candidate : null;
|
|
707
|
+
};
|
|
708
|
+
const isNativeAnonymizeBinding = (candidate) => {
|
|
709
|
+
if (!isPropertyBag(candidate)) return false;
|
|
710
|
+
if (typeof candidate["nativePackageVersion"] !== "function") return false;
|
|
711
|
+
if (typeof candidate["normalizeForSearch"] !== "function") return false;
|
|
712
|
+
if (typeof candidate["prepareStaticSearchPackageBytes"] !== "function") return false;
|
|
713
|
+
if (typeof candidate["prepareStaticSearchCompressedPackageBytes"] !== "function") return false;
|
|
714
|
+
const preparedSearch = candidate["NativePreparedSearch"];
|
|
715
|
+
if (!isPropertyBag(preparedSearch)) return false;
|
|
716
|
+
if (typeof preparedSearch["fromConfigJsonBytes"] !== "function") return false;
|
|
717
|
+
if (typeof preparedSearch["fromPreparedPackageBytes"] !== "function") return false;
|
|
718
|
+
return true;
|
|
719
|
+
};
|
|
720
|
+
const isPropertyBag = (value) => typeof value === "object" && value !== null || typeof value === "function";
|
|
721
|
+
const formatLoadError = (error) => {
|
|
722
|
+
if (error instanceof Error) return error.message;
|
|
723
|
+
return String(error);
|
|
724
|
+
};
|
|
725
|
+
//#endregion
|
|
726
|
+
export { redact_text_json as A, readNativePipelinePackageFileAsync as C, redact_default_text as D, redactDefaultTextJson as E, createNativePipelineFromConfig as F, getNativePipelineCompatibility as I, prepareNativePipelineConfig as L, summary_diagnostics_json as M, DEFAULT_NATIVE_PIPELINE_CONFIG as N, redact_default_text_json as O, assertNativePipelineSupported as P, prepareNativePipelinePackage as R, readNativePipelinePackageFile as S, redactDefaultText as T, preloadDefaultNativePipelineAsync as _, createNativePipelineFromPackageFile as a, readDefaultNativePipelinePackageFile as b, diagnostics_stream_json as c, loadNativeAnonymizeBinding as d, load_prepared_package as f, preloadDefaultNativePipeline as g, normalize_for_search as h, createNativePipelineFromDefaultPackage as i, redact_text_stream_json as j, redact_text as k, getDefaultNativePipeline as l, native_package_version as m, availableDefaultNativePipelineLanguages as n, create_native_pipeline_from_default_package as o, load_prepared_package_file as p, available_default_native_pipeline_languages as r, diagnostics_json as s, DEFAULT_NATIVE_PIPELINE_WARMUPS as t, get_default_native_pipeline as u, preload_default_native_pipeline as v, read_default_native_pipeline_package_file as w, readDefaultNativePipelinePackageFileAsync as x, prepare_search_package as y };
|
|
727
|
+
|
|
728
|
+
//# sourceMappingURL=native-node2.mjs.map
|