@lango-project/lango-server 0.2.4 → 0.2.5
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/README.md +8 -0
- package/dist/body_reader.mjs.map +1 -1
- package/dist/builder.mjs.map +1 -1
- package/dist/cli/server.mjs +3 -838
- package/dist/cli/server.mjs.map +1 -1
- package/dist/client_identity.mjs.map +1 -1
- package/dist/database.mjs.map +1 -1
- package/dist/database_action.mjs.map +1 -1
- package/dist/database_options.mjs.map +1 -1
- package/dist/database_scope.mjs.map +1 -1
- package/dist/endpoint.mjs.map +1 -1
- package/dist/error_details.mjs.map +1 -1
- package/dist/execution_failure.mjs.map +1 -1
- package/dist/execution_identity.mjs.map +1 -1
- package/dist/execution_log.mjs.map +1 -1
- package/dist/execution_runtime.mjs.map +1 -1
- package/dist/execution_worker.mjs.map +1 -1
- package/dist/executor.mjs.map +1 -1
- package/dist/group.mjs.map +1 -1
- package/dist/http_failure.mjs.map +1 -1
- package/dist/job_configuration.mjs.map +1 -1
- package/dist/job_context.mjs.map +1 -1
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll_broker.mjs.map +1 -1
- package/dist/longpoll_options.mjs.map +1 -1
- package/dist/longpoll_session.mjs.map +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/module_loader.mjs.map +1 -1
- package/dist/options.mjs.map +1 -1
- package/dist/origin.mjs.map +1 -1
- package/dist/policy.mjs.map +1 -1
- package/dist/postgres_adapter.mjs.map +1 -1
- package/dist/postgres_worker.mjs.map +1 -1
- package/dist/queue_provider.mjs.map +1 -1
- package/dist/request_identity.mjs.map +1 -1
- package/dist/response.mjs.map +1 -1
- package/dist/route_info.mjs.map +1 -1
- package/dist/route_pattern.mjs.map +1 -1
- package/dist/routes.mjs.map +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/server.mjs.map +1 -1
- package/dist/server_context.mjs.map +1 -1
- package/dist/sqlite_adapter.mjs.map +1 -1
- package/dist/static_files.mjs.map +1 -1
- package/dist/token.mjs.map +1 -1
- package/dist/tokens.mjs.map +1 -1
- package/dist/trace.mjs.map +1 -1
- package/dist/worker.mjs.map +1 -1
- package/examples/security/package.json +1 -1
- package/package.json +6 -4
- package/dist/cli/.lango/bignumber.mjs +0 -3119
- package/dist/cli/.lango/localization.mjs +0 -108
- package/dist/cli/.lango/runtime.mjs +0 -725
- package/dist/cli/.lango/vendor/i18next.LICENSE +0 -21
- package/dist/cli/.lango/vendor/i18next.mjs +0 -2434
- package/dist/cli/.lango/xmldom/conventions.js +0 -429
- package/dist/cli/.lango/xmldom/dom-parser.js +0 -591
- package/dist/cli/.lango/xmldom/dom.js +0 -3759
- package/dist/cli/.lango/xmldom/entities.js +0 -2171
- package/dist/cli/.lango/xmldom/errors.js +0 -205
- package/dist/cli/.lango/xmldom/grammar.js +0 -559
- package/dist/cli/.lango/xmldom/index.js +0 -41
- package/dist/cli/.lango/xmldom/package.json +0 -1
- package/dist/cli/.lango/xmldom/sax.js +0 -983
- package/dist/cli/.lango/xmldom.LICENSE.md +0 -8
- package/dist/cli/body_reader.mjs +0 -180
- package/dist/cli/body_reader.mjs.map +0 -1
- package/dist/cli/client_identity.mjs +0 -250
- package/dist/cli/client_identity.mjs.map +0 -1
- package/dist/cli/database.mjs +0 -116
- package/dist/cli/database.mjs.map +0 -1
- package/dist/cli/database_options.mjs +0 -83
- package/dist/cli/database_options.mjs.map +0 -1
- package/dist/cli/database_scope.mjs +0 -93
- package/dist/cli/database_scope.mjs.map +0 -1
- package/dist/cli/endpoint.mjs +0 -50
- package/dist/cli/endpoint.mjs.map +0 -1
- package/dist/cli/error_details.mjs +0 -45
- package/dist/cli/error_details.mjs.map +0 -1
- package/dist/cli/longpoll_broker.mjs +0 -215
- package/dist/cli/longpoll_broker.mjs.map +0 -1
- package/dist/cli/longpoll_options.mjs +0 -103
- package/dist/cli/longpoll_options.mjs.map +0 -1
- package/dist/cli/longpoll_session.mjs +0 -136
- package/dist/cli/longpoll_session.mjs.map +0 -1
- package/dist/cli/middleware.mjs +0 -25
- package/dist/cli/middleware.mjs.map +0 -1
- package/dist/cli/options.mjs +0 -214
- package/dist/cli/options.mjs.map +0 -1
- package/dist/cli/origin.mjs +0 -87
- package/dist/cli/origin.mjs.map +0 -1
- package/dist/cli/policy.mjs +0 -121
- package/dist/cli/policy.mjs.map +0 -1
- package/dist/cli/postgres_adapter.mjs +0 -178
- package/dist/cli/postgres_adapter.mjs.map +0 -1
- package/dist/cli/route_pattern.mjs +0 -129
- package/dist/cli/route_pattern.mjs.map +0 -1
- package/dist/cli/routes.mjs +0 -360
- package/dist/cli/routes.mjs.map +0 -1
- package/dist/cli/sqlite_adapter.mjs +0 -163
- package/dist/cli/sqlite_adapter.mjs.map +0 -1
- package/dist/cli/static_files.mjs +0 -224
- package/dist/cli/static_files.mjs.map +0 -1
- package/dist/cli/trace.mjs +0 -53
- package/dist/cli/trace.mjs.map +0 -1
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import i18next from "./vendor/i18next.mjs";
|
|
2
|
-
|
|
3
|
-
function record(value, label) {
|
|
4
|
-
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
5
|
-
throw new TypeError(`${label} must be a map`);
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function language(value) {
|
|
10
|
-
if (typeof value !== "string" || value === "") throw new TypeError("locale must be a language tag");
|
|
11
|
-
return Intl.getCanonicalLocales(value)[0];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function numeric(value) {
|
|
15
|
-
// Decimal instances from independently generated runtimes share this backend marker.
|
|
16
|
-
if (value?._isBigNumber === true && typeof value.toFixed === "function") {
|
|
17
|
-
if (!value.isFinite()) throw new TypeError("formatNumber requires a finite value");
|
|
18
|
-
return value.toFixed();
|
|
19
|
-
}
|
|
20
|
-
if (typeof value === "bigint") return value;
|
|
21
|
-
if (typeof value !== "number" || !Number.isFinite(value))
|
|
22
|
-
throw new TypeError("formatNumber requires a finite number or Decimal");
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function dateValue(value) {
|
|
27
|
-
if (typeof value === "string") {
|
|
28
|
-
const parts = /^(\d{4})-(\d{2})-(\d{2})(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2}))?$/.exec(value);
|
|
29
|
-
if (!parts) throw new TypeError("formatDate requires an ISO date or an instant with a time-zone offset");
|
|
30
|
-
const calendar = new Date(0);
|
|
31
|
-
calendar.setUTCFullYear(Number(parts[1]), Number(parts[2]) - 1, Number(parts[3]));
|
|
32
|
-
if (calendar.getUTCMonth() !== Number(parts[2]) - 1 || calendar.getUTCDate() !== Number(parts[3]))
|
|
33
|
-
throw new TypeError("formatDate requires a valid date");
|
|
34
|
-
}
|
|
35
|
-
if (!(value instanceof Date) && typeof value !== "string" && typeof value !== "number")
|
|
36
|
-
throw new TypeError("formatDate requires a Date, ISO string or epoch milliseconds");
|
|
37
|
-
const date = new Date(value);
|
|
38
|
-
if (!Number.isFinite(date.getTime())) throw new TypeError("formatDate requires a valid date");
|
|
39
|
-
return date;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Create an immutable, synchronous translator; catalogs are application-owned data. */
|
|
43
|
-
export function createI18n(options = {}) {
|
|
44
|
-
record(options, "i18n options");
|
|
45
|
-
const locale = language(options.locale ?? "en");
|
|
46
|
-
const fallbackLocale = language(options.fallbackLocale ?? "en");
|
|
47
|
-
const timeZone = new Intl.DateTimeFormat("en", { timeZone: options.timeZone ?? "UTC" }).resolvedOptions().timeZone;
|
|
48
|
-
const currency = options.currency == null ? null : options.currency;
|
|
49
|
-
if (currency !== null) new Intl.NumberFormat("en", { style: "currency", currency });
|
|
50
|
-
const resources = Object.create(null);
|
|
51
|
-
const catalogs = { ...record(options.catalogs ?? {}, "catalogs") };
|
|
52
|
-
if (options.catalog != null) catalogs[locale] = { ...catalogs[locale], ...record(options.catalog, "catalog") };
|
|
53
|
-
for (const [tag, catalog] of Object.entries(catalogs)) {
|
|
54
|
-
const messages = record(catalog, "translation catalog");
|
|
55
|
-
if (Object.values(messages).some(value => typeof value !== "string"))
|
|
56
|
-
throw new TypeError("translation catalog entries must be strings");
|
|
57
|
-
resources[language(tag)] = { translation: { ...messages } };
|
|
58
|
-
}
|
|
59
|
-
const engine = i18next.createInstance();
|
|
60
|
-
// All resources are in memory: no async backend, network lookup, or global language mutation.
|
|
61
|
-
engine.init({
|
|
62
|
-
lng: locale, fallbackLng: fallbackLocale, resources, initAsync: false,
|
|
63
|
-
keySeparator: false, nsSeparator: false, returnNull: false,
|
|
64
|
-
interpolation: { escapeValue: false },
|
|
65
|
-
});
|
|
66
|
-
const fixed = engine.getFixedT(locale);
|
|
67
|
-
const formatNumber = (value, options = null) => {
|
|
68
|
-
const settings = { ...record(options ?? {}, "number format options") };
|
|
69
|
-
if (settings.style === "currency" && settings.currency == null && currency !== null)
|
|
70
|
-
settings.currency = currency;
|
|
71
|
-
return new Intl.NumberFormat(locale, settings).format(numeric(value));
|
|
72
|
-
};
|
|
73
|
-
const formatDate = (value, options = null) => {
|
|
74
|
-
const settings = { timeZone, ...record(options ?? {}, "date format options") };
|
|
75
|
-
return new Intl.DateTimeFormat(locale, settings).format(dateValue(value));
|
|
76
|
-
};
|
|
77
|
-
const translate = (template, values = [], options = null) => {
|
|
78
|
-
if (typeof template !== "string" || !Array.isArray(values))
|
|
79
|
-
throw new TypeError("translation requires a template and a values array");
|
|
80
|
-
const settings = record(options ?? {}, "translation options");
|
|
81
|
-
if (settings.count != null && (typeof settings.count !== "number" || !Number.isFinite(settings.count)))
|
|
82
|
-
throw new TypeError("translation count must be a finite number");
|
|
83
|
-
if (settings.context != null && typeof settings.context !== "string")
|
|
84
|
-
throw new TypeError("translation context must be a string");
|
|
85
|
-
const params = record(settings.formatParams ?? {}, "formatParams");
|
|
86
|
-
const message = fixed(template, {
|
|
87
|
-
defaultValue: template, skipInterpolation: true,
|
|
88
|
-
...(settings.count == null ? {} : { count: settings.count }),
|
|
89
|
-
...(settings.context == null ? {} : { context: settings.context }),
|
|
90
|
-
});
|
|
91
|
-
// Render once: values are data and can never introduce further placeholders or code.
|
|
92
|
-
return message.replace(/{{|}}|{(\d+)(?:,\s*(number|currency|percent|date|datetime))?}/g, (token, index, format) => {
|
|
93
|
-
if (token === "{{") return "{";
|
|
94
|
-
if (token === "}}") return "}";
|
|
95
|
-
if (Number(index) >= values.length) throw new RangeError(`missing translation parameter {${index}}`);
|
|
96
|
-
const value = values[index];
|
|
97
|
-
const options = record(params[index] ?? {}, "parameter format options");
|
|
98
|
-
switch (format) {
|
|
99
|
-
case "number": return formatNumber(value, options);
|
|
100
|
-
case "currency": return formatNumber(value, { ...options, style: "currency" });
|
|
101
|
-
case "percent": return formatNumber(value, { ...options, style: "percent" });
|
|
102
|
-
case "date": case "datetime": return formatDate(value, options);
|
|
103
|
-
default: return String(value);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
return Object.freeze({ locale, fallbackLocale, timeZone, currency, translate, formatNumber, formatDate });
|
|
108
|
-
}
|