@lango-project/lango-boss 0.0.0-stage → 0.1.1
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/LICENSE +201 -0
- package/NOTICE +2 -0
- package/README.md +118 -2
- package/dist/.lango/bignumber.mjs +3119 -0
- package/dist/.lango/entries/cli.mjs +139 -0
- package/dist/.lango/entries/cli.mjs.map +1 -0
- package/dist/.lango/localization.mjs +108 -0
- package/dist/.lango/runtime.mjs +725 -0
- package/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/dist/.lango/vendor/i18next.mjs +2434 -0
- package/dist/.lango/xmldom/conventions.js +429 -0
- package/dist/.lango/xmldom/dom-parser.js +591 -0
- package/dist/.lango/xmldom/dom.js +3759 -0
- package/dist/.lango/xmldom/entities.js +2171 -0
- package/dist/.lango/xmldom/errors.js +205 -0
- package/dist/.lango/xmldom/grammar.js +559 -0
- package/dist/.lango/xmldom/index.js +41 -0
- package/dist/.lango/xmldom/package.json +1 -0
- package/dist/.lango/xmldom/sax.js +983 -0
- package/dist/.lango/xmldom.LICENSE.md +8 -0
- package/dist/boss.mjs +136 -0
- package/dist/boss.mjs.map +1 -0
- package/dist/claim_watch.mjs +99 -0
- package/dist/claim_watch.mjs.map +1 -0
- package/dist/cli.mjs +7 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/configuration.mjs +58 -0
- package/dist/configuration.mjs.map +1 -0
- package/dist/dispatcher.mjs +108 -0
- package/dist/dispatcher.mjs.map +1 -0
- package/dist/driver.mjs +98 -0
- package/dist/driver.mjs.map +1 -0
- package/dist/envelope.mjs +92 -0
- package/dist/envelope.mjs.map +1 -0
- package/dist/library.mjs +139 -0
- package/dist/library.mjs.map +1 -0
- package/dist/management.mjs +360 -0
- package/dist/management.mjs.map +1 -0
- package/dist/management_transaction.mjs +26 -0
- package/dist/management_transaction.mjs.map +1 -0
- package/dist/namespace.mjs +27 -0
- package/dist/namespace.mjs.map +1 -0
- package/dist/queue.mjs +161 -0
- package/dist/queue.mjs.map +1 -0
- package/dist/reads.mjs +359 -0
- package/dist/reads.mjs.map +1 -0
- package/dist/retention.mjs +133 -0
- package/dist/retention.mjs.map +1 -0
- package/dist/schedule_sync.mjs +222 -0
- package/dist/schedule_sync.mjs.map +1 -0
- package/dist/schedule_transaction.mjs +24 -0
- package/dist/schedule_transaction.mjs.map +1 -0
- package/dist/schedules.mjs +201 -0
- package/dist/schedules.mjs.map +1 -0
- package/dist/transaction.mjs +16 -0
- package/dist/transaction.mjs.map +1 -0
- package/dist/validation.mjs +90 -0
- package/dist/validation.mjs.map +1 -0
- package/dist/worker.mjs +316 -0
- package/dist/worker.mjs.map +1 -0
- package/docs/guide.md +88 -0
- package/docs/management.md +93 -0
- package/docs/producer.md +115 -0
- package/docs/reads.md +107 -0
- package/docs/reference.md +77 -0
- package/docs/release.md +103 -0
- package/docs/retention.md +47 -0
- package/docs/scheduling.md +79 -0
- package/docs/worker.md +90 -0
- package/examples/reports/README.md +118 -0
- package/examples/reports/app.lango +133 -0
- package/examples/reports/deploy.xml +6 -0
- package/examples/reports/dist/.lango/bignumber.mjs +3119 -0
- package/examples/reports/dist/.lango/entries/app.mjs +133 -0
- package/examples/reports/dist/.lango/entries/app.mjs.map +1 -0
- package/examples/reports/dist/.lango/localization.mjs +108 -0
- package/examples/reports/dist/.lango/runtime.mjs +725 -0
- package/examples/reports/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/examples/reports/dist/.lango/vendor/i18next.mjs +2434 -0
- package/examples/reports/dist/.lango/xmldom/conventions.js +429 -0
- package/examples/reports/dist/.lango/xmldom/dom-parser.js +591 -0
- package/examples/reports/dist/.lango/xmldom/dom.js +3759 -0
- package/examples/reports/dist/.lango/xmldom/entities.js +2171 -0
- package/examples/reports/dist/.lango/xmldom/errors.js +205 -0
- package/examples/reports/dist/.lango/xmldom/grammar.js +559 -0
- package/examples/reports/dist/.lango/xmldom/index.js +41 -0
- package/examples/reports/dist/.lango/xmldom/package.json +1 -0
- package/examples/reports/dist/.lango/xmldom/sax.js +983 -0
- package/examples/reports/dist/.lango/xmldom.LICENSE.md +8 -0
- package/examples/reports/dist/app.mjs +7 -0
- package/examples/reports/dist/app.mjs.map +1 -0
- package/examples/reports/dist/handlers.mjs +202 -0
- package/examples/reports/dist/handlers.mjs.map +1 -0
- package/examples/reports/dist/setup.mjs +14 -0
- package/examples/reports/dist/setup.mjs.map +1 -0
- package/examples/reports/handlers.lango +153 -0
- package/examples/reports/jobs.xml +5 -0
- package/examples/reports/package.json +23 -0
- package/examples/reports/routes.xml +4 -0
- package/examples/reports/setup.lango +17 -0
- package/package.json +62 -4
- package/src/boss.lango +92 -0
- package/src/claim_watch.lango +58 -0
- package/src/cli.lango +103 -0
- package/src/configuration.lango +43 -0
- package/src/dispatcher.lango +75 -0
- package/src/driver.lango +72 -0
- package/src/envelope.lango +56 -0
- package/src/library.lango +66 -0
- package/src/management.lango +302 -0
- package/src/management_transaction.lango +28 -0
- package/src/namespace.lango +15 -0
- package/src/queue.lango +115 -0
- package/src/reads.lango +277 -0
- package/src/retention.lango +107 -0
- package/src/schedule_sync.lango +190 -0
- package/src/schedule_transaction.lango +22 -0
- package/src/schedules.lango +165 -0
- package/src/transaction.lango +23 -0
- package/src/validation.lango +45 -0
- package/src/worker.lango +230 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { loadConfiguration } from "../../configuration.mjs";
|
|
2
|
+
import { Worker } from "../../worker.mjs";
|
|
3
|
+
import {
|
|
4
|
+
hostGlobal as __hostGlobal,
|
|
5
|
+
hostGlobalCall as __hostGlobalCall,
|
|
6
|
+
println as __println,
|
|
7
|
+
bindContexts as __bindContexts,
|
|
8
|
+
requireBoolean as __requireBoolean,
|
|
9
|
+
normalize as __normalize,
|
|
10
|
+
numericAdd as __numericAdd,
|
|
11
|
+
boundary as __boundary,
|
|
12
|
+
requireArity as __requireArity,
|
|
13
|
+
withArity as __withArity,
|
|
14
|
+
} from "../runtime.mjs";
|
|
15
|
+
|
|
16
|
+
export function main(args) {
|
|
17
|
+
__requireArity(arguments.length, [0], "main");
|
|
18
|
+
args = __boundary(args);
|
|
19
|
+
let config;
|
|
20
|
+
if (__requireBoolean(__requireBoolean(__normalize(args.length) >= 2) && __requireBoolean(__normalize(args[0]) === "worker"))) {
|
|
21
|
+
return startWorker(args);
|
|
22
|
+
}
|
|
23
|
+
if (__requireBoolean(__requireBoolean(__normalize(args.length) !== 2) || __requireBoolean(__normalize(args[0]) !== "check"))) {
|
|
24
|
+
usage();
|
|
25
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
config = loadConfiguration(__normalize(args[1]));
|
|
30
|
+
__println(`${__normalize(config.application)}: ${config.targets.length} job routes, ${config.schedules.length} schedules; configuration valid`);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
__normalize(__hostGlobal(["process"]).stderr.write(`Lango Boss configuration check failed: ${error}\n`));
|
|
33
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function usage() {
|
|
40
|
+
__normalize(__hostGlobal(["process"]).stderr.write("Usage: lango-boss check <application-directory>\n lango-boss worker <application-directory> --identity-module <module> --identity-handler <export> [--workers <count>] [--verbose]\n"));
|
|
41
|
+
return null;
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function startWorker(args) {
|
|
46
|
+
__requireArity(arguments.length, [0], "startWorker");
|
|
47
|
+
args = __boundary(args);
|
|
48
|
+
let settings;
|
|
49
|
+
let worker = null;
|
|
50
|
+
try {
|
|
51
|
+
settings = parseWorker(args);
|
|
52
|
+
worker = new Worker(__normalize(args[1]), settings);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
__normalize(__hostGlobal(["process"]).stderr.write(`Lango Boss worker configuration failed: ${error}\n`));
|
|
55
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
let state = { stopping: false, stop: null };
|
|
59
|
+
let stop = __bindContexts(() => {
|
|
60
|
+
if (__requireBoolean(__normalize(state.stopping))) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
state.stopping = true;
|
|
64
|
+
return __normalize(worker.close()).catch(__withArity(__bindContexts((error) => {
|
|
65
|
+
error = __boundary(error);
|
|
66
|
+
__normalize(__hostGlobal(["process"]).stderr.write(`Lango Boss shutdown failed: ${error}\n`));
|
|
67
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
68
|
+
return null;
|
|
69
|
+
}), [0], "closure")).finally(__bindContexts(() => {
|
|
70
|
+
removeSignals(__normalize(state.stop));
|
|
71
|
+
return null;
|
|
72
|
+
}));
|
|
73
|
+
return null;
|
|
74
|
+
});
|
|
75
|
+
state.stop = stop;
|
|
76
|
+
__normalize(__hostGlobal(["process"]).once("SIGINT", stop));
|
|
77
|
+
__normalize(__hostGlobal(["process"]).once("SIGTERM", stop));
|
|
78
|
+
return __normalize(worker.start()).then(__withArity(__bindContexts((ignored) => {
|
|
79
|
+
ignored = __boundary(ignored);
|
|
80
|
+
__println("Lango Boss worker started");
|
|
81
|
+
return null;
|
|
82
|
+
return null;
|
|
83
|
+
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
84
|
+
error = __boundary(error);
|
|
85
|
+
__normalize(__hostGlobal(["process"]).stderr.write(`Lango Boss worker startup failed: ${error}\n`));
|
|
86
|
+
__hostGlobal(["process"]).exitCode = 1;
|
|
87
|
+
removeSignals(__normalize(state.stop));
|
|
88
|
+
return null;
|
|
89
|
+
return null;
|
|
90
|
+
}), [0], "closure"));
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function removeSignals(handler) {
|
|
95
|
+
__requireArity(arguments.length, [0], "removeSignals");
|
|
96
|
+
handler = __boundary(handler);
|
|
97
|
+
__normalize(__hostGlobal(["process"]).removeListener("SIGINT", handler));
|
|
98
|
+
__normalize(__hostGlobal(["process"]).removeListener("SIGTERM", handler));
|
|
99
|
+
return null;
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function parseWorker(args) {
|
|
104
|
+
__requireArity(arguments.length, [0], "parseWorker");
|
|
105
|
+
args = __boundary(args);
|
|
106
|
+
let settings = { identity: { } };
|
|
107
|
+
let index = 2;
|
|
108
|
+
let seen = [];
|
|
109
|
+
__loop1: while (__requireBoolean(index < __normalize(args.length))) {
|
|
110
|
+
let flag = __normalize(args[index]);
|
|
111
|
+
if (__requireBoolean(__normalize(seen.includes(flag)))) {
|
|
112
|
+
throw `Duplicate worker option: ${flag}`;
|
|
113
|
+
}
|
|
114
|
+
seen.push(flag);
|
|
115
|
+
if (__requireBoolean(flag === "--verbose")) {
|
|
116
|
+
__hostGlobal(["process"]).env.LANGO_VERBOSE = "1";
|
|
117
|
+
index = __numericAdd(index, 1);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
index = __numericAdd(index, 1);
|
|
121
|
+
if (__requireBoolean(index >= __normalize(args.length))) {
|
|
122
|
+
throw `Missing value for ${flag}`;
|
|
123
|
+
}
|
|
124
|
+
let value = __normalize(args[index]);
|
|
125
|
+
if (flag === "--identity-module") {
|
|
126
|
+
settings.identity.module = value;
|
|
127
|
+
} else if (flag === "--identity-handler") {
|
|
128
|
+
settings.identity.handler = value;
|
|
129
|
+
} else if (flag === "--workers") {
|
|
130
|
+
settings.workers = __hostGlobalCall(["Number"], value);
|
|
131
|
+
} else {
|
|
132
|
+
throw `Unknown worker option: ${flag}`;
|
|
133
|
+
}
|
|
134
|
+
index = __numericAdd(index, 1);
|
|
135
|
+
}
|
|
136
|
+
return settings;
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=cli.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","sources":["cli.lango"],"sourcesContent":["import \"./configuration\"\n loadConfiguration(directory)\nimport \"./worker\"\n class Worker\nimport js global process\nimport js global Number\n\nexport main(args)\n\nmain(args)\n if args.length >= 2 and args[0] == \"worker\"\n return startWorker(args)\n if args.length != 2 or args[0] != \"check\"\n usage()\n process.exitCode = 1\n return null\n try\n config = loadConfiguration(args[1])\n println(\"${config.application}: ${config.targets.length} job routes, ${config.schedules.length} schedules; configuration valid\")\n catch error\n process.stderr.write(\"Lango Boss configuration check failed: ${error}\\n\")\n process.exitCode = 1\n return null\n\nusage()\n process.stderr.write(\"Usage: lango-boss check <application-directory>\\n lango-boss worker <application-directory> --identity-module <module> --identity-handler <export> [--workers <count>] [--verbose]\\n\")\n return null\n\nstartWorker(args)\n worker = null\n try\n settings = parseWorker(args)\n worker = new Worker(args[1], settings)\n catch error\n process.stderr.write(\"Lango Boss worker configuration failed: ${error}\\n\")\n process.exitCode = 1\n return null\n state = {\n stopping: false\n stop: null\n }\n stop = ()\n capture worker\n capture state\n if state.stopping\n return null\n state.stopping = true\n return chain worker.close()\n catch(error)\n process.stderr.write(\"Lango Boss shutdown failed: ${error}\\n\")\n process.exitCode = 1\n finally\n capture state\n removeSignals(state.stop)\n state.stop = stop\n process.once(\"SIGINT\", stop)\n process.once(\"SIGTERM\", stop)\n return chain worker.start()\n then(ignored)\n println(\"Lango Boss worker started\")\n return null\n catch(error)\n capture state\n process.stderr.write(\"Lango Boss worker startup failed: ${error}\\n\")\n process.exitCode = 1\n removeSignals(state.stop)\n return null\n\nremoveSignals(handler)\n process.removeListener(\"SIGINT\", handler)\n process.removeListener(\"SIGTERM\", handler)\n return null\n\nparseWorker(args)\n settings = {\n identity: {}\n }\n index = 2\n seen = []\n loop while index < args.length\n flag = args[index]\n if seen.includes(flag)\n throw \"Duplicate worker option: ${flag}\"\n seen.add(flag)\n if flag == \"--verbose\"\n process.env.LANGO_VERBOSE = \"1\"\n index = index + 1\n continue\n index = index + 1\n if index >= args.length\n throw \"Missing value for ${flag}\"\n value = args[index]\n switch flag\n case \"--identity-module\"\n settings.identity.module = value\n case \"--identity-handler\"\n settings.identity.handler = value\n case \"--workers\"\n settings.workers = Number(value)\n else\n throw \"Unknown worker option: ${flag}\"\n index = index + 1\n return settings\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"d7d03efcd91461f19d83836ad413242c546e830e4f1d2d654a9541fe531de1a8","outputHash":"ca0f263101377aff83004623ab85f1d5486ed3c32c19371765715315d4710237","mapHash":"6327609b379257957c42ce1b142badcd41cf66a918fa2de3dd645e47abf353d9"}}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
}
|