@crvouga/mockingbird-service-redis 2.6.0 → 2.8.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/README.md +11 -3
- package/SUPPORT.md +79 -3
- package/dist/{chunk-LHUY4G3I.js → chunk-55PZE5Z4.js} +29 -13
- package/dist/chunk-55PZE5Z4.js.map +7 -0
- package/dist/chunk-TVELGGZ4.js +9519 -0
- package/dist/chunk-TVELGGZ4.js.map +7 -0
- package/dist/cli.js +115 -15
- package/dist/cli.js.map +3 -3
- package/dist/index.d.ts +34 -0
- package/dist/index.js +1 -1
- package/dist/server.d.ts +52 -0
- package/dist/server.js +2 -2
- package/package.json +1 -4
- package/dist/chunk-LHUY4G3I.js.map +0 -7
- package/dist/chunk-Z3XQGVTX.js +0 -5058
- package/dist/chunk-Z3XQGVTX.js.map +0 -7
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createClock,
|
|
5
5
|
normalizeBootControls,
|
|
6
6
|
normalizeControls,
|
|
7
|
+
normalizeIdBase,
|
|
7
8
|
ownedTransport,
|
|
8
9
|
parseDuration,
|
|
9
10
|
parseFaultHeader,
|
|
@@ -11,15 +12,28 @@ import {
|
|
|
11
12
|
restoreClock,
|
|
12
13
|
serve,
|
|
13
14
|
serveTarget
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-55PZE5Z4.js";
|
|
15
16
|
import {
|
|
16
17
|
createRedis
|
|
17
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-TVELGGZ4.js";
|
|
18
19
|
|
|
19
20
|
// ../../adapters/node/dist/cli.js
|
|
20
21
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
21
22
|
import { parseArgs } from "node:util";
|
|
22
23
|
|
|
24
|
+
// ../../adapters/node/dist/boot-settings.js
|
|
25
|
+
var checkSettings = (target, settings, label) => {
|
|
26
|
+
if (!target.parseSettings)
|
|
27
|
+
throw new Error(`${label}: ${target.name} takes no boot settings`);
|
|
28
|
+
try {
|
|
29
|
+
return target.parseSettings(settings);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new Error(`${label}: ${error instanceof Error ? error.message : String(error)}`, {
|
|
32
|
+
cause: error
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
23
37
|
// ../../adapters/node/dist/fleet.js
|
|
24
38
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
25
39
|
import { createHash as createHash4, randomUUID as randomUUID4 } from "node:crypto";
|
|
@@ -2669,6 +2683,9 @@ var fleet_config_schema_default = {
|
|
|
2669
2683
|
adminControls: {
|
|
2670
2684
|
$ref: "#/$defs/controls"
|
|
2671
2685
|
},
|
|
2686
|
+
idBase: {
|
|
2687
|
+
$ref: "#/$defs/idBase"
|
|
2688
|
+
},
|
|
2672
2689
|
namespace: {
|
|
2673
2690
|
type: "string",
|
|
2674
2691
|
pattern: "^[A-Za-z0-9_.-]{1,64}$"
|
|
@@ -2758,6 +2775,12 @@ var fleet_config_schema_default = {
|
|
|
2758
2775
|
adminControls: {
|
|
2759
2776
|
$ref: "#/$defs/controls"
|
|
2760
2777
|
},
|
|
2778
|
+
idBase: {
|
|
2779
|
+
$ref: "#/$defs/idBase"
|
|
2780
|
+
},
|
|
2781
|
+
settings: {
|
|
2782
|
+
type: "object"
|
|
2783
|
+
},
|
|
2761
2784
|
fixtures: {
|
|
2762
2785
|
type: "object"
|
|
2763
2786
|
},
|
|
@@ -2804,6 +2827,18 @@ var fleet_config_schema_default = {
|
|
|
2804
2827
|
}
|
|
2805
2828
|
}
|
|
2806
2829
|
},
|
|
2830
|
+
idBase: {
|
|
2831
|
+
anyOf: [
|
|
2832
|
+
{
|
|
2833
|
+
type: "integer",
|
|
2834
|
+
minimum: 0
|
|
2835
|
+
},
|
|
2836
|
+
{
|
|
2837
|
+
type: "string",
|
|
2838
|
+
pattern: "^(boot|[0-9]+)$"
|
|
2839
|
+
}
|
|
2840
|
+
]
|
|
2841
|
+
},
|
|
2807
2842
|
controls: {
|
|
2808
2843
|
type: "object",
|
|
2809
2844
|
additionalProperties: false,
|
|
@@ -2953,6 +2988,8 @@ async function preflightFleet(config, options) {
|
|
|
2953
2988
|
throw new Error("protected archive policy requires a protected repository; configure its protector before startup");
|
|
2954
2989
|
resolveAdminPrefix(config.adminPrefix);
|
|
2955
2990
|
normalizeBootControls(config.adminControls);
|
|
2991
|
+
if (config.idBase !== void 0)
|
|
2992
|
+
normalizeIdBase(config.idBase, "idBase");
|
|
2956
2993
|
const targets = /* @__PURE__ */ new Map();
|
|
2957
2994
|
const ports = /* @__PURE__ */ new Set();
|
|
2958
2995
|
for (const [name, entry] of Object.entries(config.services)) {
|
|
@@ -2984,6 +3021,13 @@ async function preflightFleet(config, options) {
|
|
|
2984
3021
|
throw new Error("invalid protocol namespace selector");
|
|
2985
3022
|
}
|
|
2986
3023
|
}
|
|
3024
|
+
if (entry.idBase !== void 0)
|
|
3025
|
+
normalizeIdBase(entry.idBase, "idBase");
|
|
3026
|
+
if (entry.settings !== void 0) {
|
|
3027
|
+
if (protocol !== "http" || !("create" in target))
|
|
3028
|
+
throw new Error("settings: only HTTP services take boot settings");
|
|
3029
|
+
checkSettings(target, entry.settings, "settings");
|
|
3030
|
+
}
|
|
2987
3031
|
const port2 = entry.port ?? target.defaultPort;
|
|
2988
3032
|
if (port2 !== 0) {
|
|
2989
3033
|
const key = `${entry.host ?? "127.0.0.1"}:${port2}`;
|
|
@@ -3019,7 +3063,7 @@ async function preflightFleet(config, options) {
|
|
|
3019
3063
|
break;
|
|
3020
3064
|
}
|
|
3021
3065
|
}
|
|
3022
|
-
targets.set(name, { ...target, packageVersion: packageVersion ?? "2.
|
|
3066
|
+
targets.set(name, { ...target, packageVersion: packageVersion ?? "2.8.0" });
|
|
3023
3067
|
} catch (error) {
|
|
3024
3068
|
throw new Error(`service ${name}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
3025
3069
|
}
|
|
@@ -3245,7 +3289,11 @@ var serve2 = async (api, options = {}) => {
|
|
|
3245
3289
|
// ../../adapters/node/dist/listen.js
|
|
3246
3290
|
var listen = async (api, options = {}) => {
|
|
3247
3291
|
const host2 = options.host ?? "127.0.0.1";
|
|
3248
|
-
const server = await serve2(api, {
|
|
3292
|
+
const server = await serve2(api, {
|
|
3293
|
+
port: options.port ?? 0,
|
|
3294
|
+
host: host2,
|
|
3295
|
+
...options.maxBodyBytes !== void 0 ? { maxBodyBytes: options.maxBodyBytes } : {}
|
|
3296
|
+
});
|
|
3249
3297
|
const address = server.address();
|
|
3250
3298
|
const port2 = typeof address === "object" && address !== null ? address.port : options.port ?? 0;
|
|
3251
3299
|
const shown = host2.includes(":") ? `[${host2}]` : host2;
|
|
@@ -3339,6 +3387,7 @@ var httpChild = async (target, entry, options, admission, generation, privateAcc
|
|
|
3339
3387
|
options.onLog?.(entry2);
|
|
3340
3388
|
},
|
|
3341
3389
|
...entry.adminControls !== void 0 ? { adminControls: entry.adminControls } : {},
|
|
3390
|
+
...entry.settings !== void 0 ? { settings: checkSettings(target, entry.settings, "settings") } : {},
|
|
3342
3391
|
...entry.fixtures !== void 0 ? { fixtures: entry.fixtures } : {},
|
|
3343
3392
|
...(advertisedHttpBase(entry) ?? entry.baseUrl) !== void 0 ? { baseUrl: advertisedHttpBase(entry) ?? entry.baseUrl } : {}
|
|
3344
3393
|
});
|
|
@@ -3357,6 +3406,8 @@ var httpChild = async (target, entry, options, admission, generation, privateAcc
|
|
|
3357
3406
|
].some((method) => typeof created[method] !== "function"))
|
|
3358
3407
|
throw new Error("HTTP target does not implement the fleet runtime protocol; build/install matching supported service versions");
|
|
3359
3408
|
const runtime = created;
|
|
3409
|
+
if (entry.idBase !== void 0)
|
|
3410
|
+
runtime.setIdBase?.(entry.idBase);
|
|
3360
3411
|
const unobserve = runtime.webhooks?.observeDeliveries(observer.delivery);
|
|
3361
3412
|
if (options.outbound && runtime.webhooks)
|
|
3362
3413
|
runtime.webhooks.setTransportPolicy(ownedTransport(options.outbound));
|
|
@@ -3441,7 +3492,8 @@ var httpChild = async (target, entry, options, admission, generation, privateAcc
|
|
|
3441
3492
|
try {
|
|
3442
3493
|
server = await listen(api, {
|
|
3443
3494
|
port: entry.port ?? target.defaultPort,
|
|
3444
|
-
host: entry.host ?? "127.0.0.1"
|
|
3495
|
+
host: entry.host ?? "127.0.0.1",
|
|
3496
|
+
...target.maxBodyBytes !== void 0 ? { maxBodyBytes: target.maxBodyBytes } : {}
|
|
3445
3497
|
});
|
|
3446
3498
|
target.listening?.(server);
|
|
3447
3499
|
} catch (error) {
|
|
@@ -3955,6 +4007,7 @@ async function startFleet(config, options) {
|
|
|
3955
4007
|
...entry,
|
|
3956
4008
|
adminPrefix: resolveAdminPrefix(entry.adminPrefix ?? adminPrefix),
|
|
3957
4009
|
...adminKey !== void 0 ? { adminKey } : {},
|
|
4010
|
+
...(entry.idBase ?? config.idBase) !== void 0 ? { idBase: entry.idBase ?? config.idBase } : {},
|
|
3958
4011
|
// Fleet-wide controls, with the service's own keys replacing them.
|
|
3959
4012
|
...config.adminControls !== void 0 || entry.adminControls !== void 0 ? { adminControls: { ...config.adminControls, ...entry.adminControls } } : {}
|
|
3960
4013
|
}, options, (namespace, request) => management?.admit(namespace, request), (namespace) => management?.generation(namespace), (namespace, request) => management?.privateRequest(namespace, request) ?? false, {
|
|
@@ -4639,6 +4692,16 @@ var COMMON_SERVE_OPTIONS = {
|
|
|
4639
4692
|
value: "<seed>",
|
|
4640
4693
|
description: "Seed for every random choice (env MOCKINGBIRD_SEED)"
|
|
4641
4694
|
},
|
|
4695
|
+
"id-base": {
|
|
4696
|
+
type: "string",
|
|
4697
|
+
value: "<n|boot>",
|
|
4698
|
+
description: "Start generated ids at this base so a restart does not reissue the last boot's ids; boot derives one from the clock (env MOCKINGBIRD_ID_BASE; default 0, the same ids every boot)"
|
|
4699
|
+
},
|
|
4700
|
+
settings: {
|
|
4701
|
+
type: "string",
|
|
4702
|
+
value: "<json|file>",
|
|
4703
|
+
description: "Service settings to boot with, as JSON or a JSON file; every namespace starts from them (env MOCKINGBIRD_SETTINGS; only for services that declare settings)"
|
|
4704
|
+
},
|
|
4642
4705
|
"admin-controls": {
|
|
4643
4706
|
type: "string",
|
|
4644
4707
|
value: "<json|file>",
|
|
@@ -4733,19 +4796,40 @@ var readJsonFile = async (path, label) => {
|
|
|
4733
4796
|
}
|
|
4734
4797
|
};
|
|
4735
4798
|
var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4799
|
+
var readJsonOption = async (source, label) => {
|
|
4800
|
+
const trimmed = source.trim();
|
|
4801
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
4802
|
+
try {
|
|
4803
|
+
return JSON.parse(trimmed);
|
|
4804
|
+
} catch {
|
|
4805
|
+
throw new Error(`${label}: not valid JSON`);
|
|
4806
|
+
}
|
|
4807
|
+
}
|
|
4808
|
+
return readJsonFile(source, label);
|
|
4809
|
+
};
|
|
4810
|
+
var resolveServeIdBase = (values, env = process.env) => {
|
|
4811
|
+
const source = asString(values["id-base"]) ?? env.MOCKINGBIRD_ID_BASE;
|
|
4812
|
+
if (source === void 0 || source.trim() === "")
|
|
4813
|
+
return void 0;
|
|
4814
|
+
normalizeIdBase(source.trim(), "--id-base");
|
|
4815
|
+
return source.trim();
|
|
4816
|
+
};
|
|
4817
|
+
var resolveServeSettings = async (target, values, env = process.env) => {
|
|
4818
|
+
const flag = asString(values.settings);
|
|
4819
|
+
const source = flag ?? env.MOCKINGBIRD_SETTINGS;
|
|
4820
|
+
if (source === void 0 || source.trim() === "")
|
|
4821
|
+
return void 0;
|
|
4822
|
+
const label = flag !== void 0 ? "--settings" : "MOCKINGBIRD_SETTINGS";
|
|
4823
|
+
const parsed = await readJsonOption(source, label);
|
|
4824
|
+
if (!isObject2(parsed))
|
|
4825
|
+
throw new Error(`${label}: expected a JSON object`);
|
|
4826
|
+
return checkSettings(target, parsed, label);
|
|
4827
|
+
};
|
|
4736
4828
|
var resolveServeControls = async (values, env = process.env, base) => {
|
|
4737
4829
|
const source = asString(values["admin-controls"]) ?? env.MOCKINGBIRD_ADMIN_CONTROLS;
|
|
4738
4830
|
let document = isObject2(base) ? { ...base } : {};
|
|
4739
4831
|
if (source !== void 0 && source.trim() !== "") {
|
|
4740
|
-
|
|
4741
|
-
if (source.trim().startsWith("{")) {
|
|
4742
|
-
try {
|
|
4743
|
-
parsed = JSON.parse(source);
|
|
4744
|
-
} catch {
|
|
4745
|
-
throw new Error("--admin-controls: not valid JSON");
|
|
4746
|
-
}
|
|
4747
|
-
} else
|
|
4748
|
-
parsed = await readJsonFile(source, "--admin-controls");
|
|
4832
|
+
const parsed = source.trim().startsWith("{") ? await readJsonOption(source, "--admin-controls") : await readJsonFile(source, "--admin-controls");
|
|
4749
4833
|
if (!isObject2(parsed))
|
|
4750
4834
|
throw new Error("--admin-controls: expected a JSON object");
|
|
4751
4835
|
document = { ...document, ...parsed };
|
|
@@ -4795,9 +4879,16 @@ var start = async (target, values, config) => {
|
|
|
4795
4879
|
adminKey: config.adminKey,
|
|
4796
4880
|
seed: config.seed,
|
|
4797
4881
|
onLog: formatLog(config.log),
|
|
4882
|
+
...config.settings !== void 0 ? { settings: config.settings } : {},
|
|
4798
4883
|
...config.adminControls !== void 0 ? { adminControls: config.adminControls } : {}
|
|
4799
4884
|
});
|
|
4800
|
-
|
|
4885
|
+
if (config.idBase !== void 0)
|
|
4886
|
+
runtime.setIdBase?.(config.idBase);
|
|
4887
|
+
const listening2 = await listen(runtime, {
|
|
4888
|
+
port: config.port,
|
|
4889
|
+
host: config.host,
|
|
4890
|
+
...target.maxBodyBytes !== void 0 ? { maxBodyBytes: target.maxBodyBytes } : {}
|
|
4891
|
+
});
|
|
4801
4892
|
target.listening?.(listening2);
|
|
4802
4893
|
console.log(`${target.name} emulator listening on ${listening2.url}`);
|
|
4803
4894
|
console.log(`${target.name} health: GET ${listening2.url}${adminPrefix}/health`);
|
|
@@ -4842,6 +4933,11 @@ var serveCommand = (target) => ({
|
|
|
4842
4933
|
const adminControls = await resolveServeControls(values, process.env, config.adminControls);
|
|
4843
4934
|
if (adminControls !== void 0)
|
|
4844
4935
|
config.adminControls = adminControls;
|
|
4936
|
+
if (values.settings !== void 0)
|
|
4937
|
+
throw new Error("--settings serves a single service; give each service its own `settings` in the config");
|
|
4938
|
+
const idBase = config.idBase ?? resolveServeIdBase(values);
|
|
4939
|
+
if (idBase !== void 0)
|
|
4940
|
+
config.idBase = idBase;
|
|
4845
4941
|
const fleet = await startFleet(config, {
|
|
4846
4942
|
load: (name) => loadTarget(name, target),
|
|
4847
4943
|
onLog: formatLog(config.log ?? log),
|
|
@@ -4871,8 +4967,12 @@ var serveCommand = (target) => ({
|
|
|
4871
4967
|
let listening2;
|
|
4872
4968
|
try {
|
|
4873
4969
|
const adminControls = await resolveServeControls(values);
|
|
4970
|
+
const idBase = resolveServeIdBase(values);
|
|
4971
|
+
const settings = await resolveServeSettings(target, values);
|
|
4874
4972
|
listening2 = await start(target, values, {
|
|
4875
4973
|
...adminControls !== void 0 ? { adminControls } : {},
|
|
4974
|
+
...idBase !== void 0 ? { idBase } : {},
|
|
4975
|
+
...settings !== void 0 ? { settings } : {},
|
|
4876
4976
|
adminPrefix: resolveAdminPrefix(asString(values["admin-prefix"]) ?? process.env.MOCKINGBIRD_ADMIN_PREFIX),
|
|
4877
4977
|
port: port2 === void 0 ? target.defaultPort : Number.parseInt(port2, 10),
|
|
4878
4978
|
host: asString(values.host) ?? "127.0.0.1",
|