@crvouga/mockingbird-service-customerio 1.7.1 → 1.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/CHANGELOG.md +15 -0
- package/dist/{chunk-OCBE22Z7.js → chunk-BGWMLNP4.js} +204 -27
- package/dist/chunk-BGWMLNP4.js.map +7 -0
- package/dist/chunk-VNF453F5.js +838 -0
- package/dist/chunk-VNF453F5.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +1 -1
- package/dist/server.d.ts +62 -4
- package/dist/server.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-OCBE22Z7.js.map +0 -7
- package/dist/chunk-QW3WYAVY.js +0 -371
- package/dist/chunk-QW3WYAVY.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog — @crvouga/mockingbird-service-customerio
|
|
2
2
|
|
|
3
|
+
## 1.8.0 (2026-10-02)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- coordinate HTTP and protocol mocks ([3168653](https://github.com/crvouga/mockingbird/commit/31686534c55a9823fdaa92afc9cc456cf741b809))
|
|
8
|
+
|
|
9
|
+
### Fixes and improvements
|
|
10
|
+
|
|
11
|
+
- decouple smoke types from built packages ([a4b31c6](https://github.com/crvouga/mockingbird/commit/a4b31c6205d92aa0c6f7c9de3518d5ae44d38829))
|
|
12
|
+
- protect child admin endpoints ([5410b94](https://github.com/crvouga/mockingbird/commit/5410b948a30dcedc21e9a70e44fd415c1ea25394))
|
|
13
|
+
- harden protocol startup and state ([6f5b557](https://github.com/crvouga/mockingbird/commit/6f5b557e87b48b31985949e04f3b5ef58f51d295))
|
|
14
|
+
- preserve checkpoints and lifecycle ([50e8c32](https://github.com/crvouga/mockingbird/commit/50e8c322feded2f7f45afce9d8cdef43c37ab9ab))
|
|
15
|
+
- clean branch state on reset ([3b714d4](https://github.com/crvouga/mockingbird/commit/3b714d4a5df8e75fee0bb31e98d7c7566e164381))
|
|
16
|
+
- type signal listener cleanup ([5279852](https://github.com/crvouga/mockingbird/commit/5279852e56ea60262ccf17aa6e46b3c31091a34a))
|
|
17
|
+
|
|
3
18
|
## 1.7.1 (2026-10-01)
|
|
4
19
|
|
|
5
20
|
### Fixes and improvements
|
|
@@ -183,29 +183,30 @@ var createControlPlane = (context) => {
|
|
|
183
183
|
return json(200, { status: "ok", reset: target === "*" ? context.namespaces() : [target] });
|
|
184
184
|
},
|
|
185
185
|
"GET /namespaces": () => json(200, { default: context.defaultNamespace, namespaces: context.namespaces() }),
|
|
186
|
-
"GET /clock": () => json(200, context.clock.state()),
|
|
187
|
-
"POST /clock": ({ body }) => {
|
|
186
|
+
"GET /clock": ({ namespace }) => json(200, (context.namespaceClock?.(namespace) ?? context.clock).state()),
|
|
187
|
+
"POST /clock": ({ body, namespace }) => {
|
|
188
|
+
const clock = context.namespaceClock?.(namespace) ?? context.clock;
|
|
188
189
|
if (!isRecord(body))
|
|
189
190
|
return adminError(400, "expected a JSON object");
|
|
190
191
|
if (body.reset === true)
|
|
191
|
-
|
|
192
|
+
clock.reset();
|
|
192
193
|
if (body.freeze === true)
|
|
193
|
-
|
|
194
|
+
clock.freeze();
|
|
194
195
|
if (body.set !== void 0) {
|
|
195
196
|
const instant = parseInstant(body.set);
|
|
196
197
|
if (instant === void 0)
|
|
197
198
|
return adminError(400, "set: expected epoch ms or ISO-8601");
|
|
198
|
-
|
|
199
|
+
clock.set(instant);
|
|
199
200
|
}
|
|
200
201
|
if (body.advance !== void 0) {
|
|
201
202
|
const delta = parseDuration(body.advance);
|
|
202
203
|
if (delta === void 0)
|
|
203
204
|
return adminError(400, 'advance: expected ms or "15m"-style');
|
|
204
|
-
|
|
205
|
+
clock.advance(delta);
|
|
205
206
|
}
|
|
206
207
|
if (body.freeze === false)
|
|
207
|
-
|
|
208
|
-
return json(200,
|
|
208
|
+
clock.unfreeze();
|
|
209
|
+
return json(200, clock.state());
|
|
209
210
|
},
|
|
210
211
|
"GET /faults": () => json(200, { faults: context.faults.list() }),
|
|
211
212
|
"POST /faults": ({ body, namespace }) => {
|
|
@@ -492,7 +493,33 @@ var faultResponse = (rule) => {
|
|
|
492
493
|
};
|
|
493
494
|
var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) => {
|
|
494
495
|
const entries = [];
|
|
496
|
+
let isolated = false;
|
|
497
|
+
const scopedRngs = /* @__PURE__ */ new Map();
|
|
498
|
+
const random = (namespace) => {
|
|
499
|
+
if (!isolated || namespace === "default")
|
|
500
|
+
return rng;
|
|
501
|
+
let scoped = scopedRngs.get(namespace);
|
|
502
|
+
if (!scoped) {
|
|
503
|
+
scoped = createRng(rng.seed);
|
|
504
|
+
scopedRngs.set(namespace, scoped);
|
|
505
|
+
}
|
|
506
|
+
return scoped;
|
|
507
|
+
};
|
|
495
508
|
return {
|
|
509
|
+
isolateNamespaces() {
|
|
510
|
+
isolated = true;
|
|
511
|
+
},
|
|
512
|
+
snapshot(namespace) {
|
|
513
|
+
return {
|
|
514
|
+
rules: structuredClone(entries.map((entry, position) => ({
|
|
515
|
+
...entry.rule,
|
|
516
|
+
remaining: entry.remaining,
|
|
517
|
+
hits: entry.hits,
|
|
518
|
+
position
|
|
519
|
+
})).filter((entry) => entry.namespace === namespace)),
|
|
520
|
+
rngState: random(namespace).state()
|
|
521
|
+
};
|
|
522
|
+
},
|
|
496
523
|
add(rule) {
|
|
497
524
|
const existing = entries.findIndex((e) => e.rule.id === rule.id);
|
|
498
525
|
const entry = { rule, remaining: rule.count ?? null, hits: 0 };
|
|
@@ -512,6 +539,16 @@ var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((reso
|
|
|
512
539
|
},
|
|
513
540
|
clear() {
|
|
514
541
|
entries.length = 0;
|
|
542
|
+
rng.reset();
|
|
543
|
+
scopedRngs.clear();
|
|
544
|
+
},
|
|
545
|
+
restore(namespace, state) {
|
|
546
|
+
for (let i = entries.length - 1; i >= 0; i--)
|
|
547
|
+
if (entries[i]?.rule.namespace === namespace)
|
|
548
|
+
entries.splice(i, 1);
|
|
549
|
+
for (const { remaining, hits, position, ...rule } of state.rules)
|
|
550
|
+
entries.splice(Math.min(position, entries.length), 0, { rule, remaining, hits });
|
|
551
|
+
random(namespace).setState(state.rngState);
|
|
515
552
|
},
|
|
516
553
|
async take(candidate) {
|
|
517
554
|
const hits = [];
|
|
@@ -521,7 +558,7 @@ var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((reso
|
|
|
521
558
|
if (!matches(entry.rule, candidate))
|
|
522
559
|
continue;
|
|
523
560
|
const rate = entry.rule.rate ?? 1;
|
|
524
|
-
if (
|
|
561
|
+
if (random(candidate.namespace).next() >= rate)
|
|
525
562
|
continue;
|
|
526
563
|
entry.hits++;
|
|
527
564
|
if (entry.remaining !== null)
|
|
@@ -1089,7 +1126,8 @@ var annotateResponse = (response, extra) => {
|
|
|
1089
1126
|
var responseNotes = (response) => notes.get(response);
|
|
1090
1127
|
|
|
1091
1128
|
// ../core/dist/metrics.js
|
|
1092
|
-
var createMetrics = () => {
|
|
1129
|
+
var createMetrics = (partition = true) => {
|
|
1130
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
1093
1131
|
let requests = 0;
|
|
1094
1132
|
let faults = 0;
|
|
1095
1133
|
let totalDurationMs = 0;
|
|
@@ -1097,6 +1135,14 @@ var createMetrics = () => {
|
|
|
1097
1135
|
const unmatched = /* @__PURE__ */ new Map();
|
|
1098
1136
|
return {
|
|
1099
1137
|
record(entry) {
|
|
1138
|
+
if (partition) {
|
|
1139
|
+
let scoped = namespaces.get(entry.namespace);
|
|
1140
|
+
if (!scoped) {
|
|
1141
|
+
scoped = createMetrics(false);
|
|
1142
|
+
namespaces.set(entry.namespace, scoped);
|
|
1143
|
+
}
|
|
1144
|
+
scoped.record(entry);
|
|
1145
|
+
}
|
|
1100
1146
|
requests++;
|
|
1101
1147
|
totalDurationMs += entry.durationMs;
|
|
1102
1148
|
if (entry.faultId !== void 0)
|
|
@@ -1108,7 +1154,7 @@ var createMetrics = () => {
|
|
|
1108
1154
|
unmatched.set(route, (unmatched.get(route) ?? 0) + 1);
|
|
1109
1155
|
}
|
|
1110
1156
|
},
|
|
1111
|
-
report: () => ({
|
|
1157
|
+
report: (namespace) => namespace !== void 0 ? (namespaces.get(namespace) ?? createMetrics(false)).report() : {
|
|
1112
1158
|
requests,
|
|
1113
1159
|
byOperation: Object.fromEntries([...byOperation].sort(([a], [b]) => a.localeCompare(b))),
|
|
1114
1160
|
unmatched: [...unmatched].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([route, count]) => {
|
|
@@ -1117,8 +1163,13 @@ var createMetrics = () => {
|
|
|
1117
1163
|
}),
|
|
1118
1164
|
faults,
|
|
1119
1165
|
totalDurationMs
|
|
1120
|
-
}
|
|
1121
|
-
reset() {
|
|
1166
|
+
},
|
|
1167
|
+
reset(namespace) {
|
|
1168
|
+
if (namespace !== void 0) {
|
|
1169
|
+
namespaces.delete(namespace);
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
namespaces.clear();
|
|
1122
1173
|
requests = 0;
|
|
1123
1174
|
faults = 0;
|
|
1124
1175
|
totalDurationMs = 0;
|
|
@@ -4167,7 +4218,7 @@ var stateAdminRoutes = (routes) => {
|
|
|
4167
4218
|
};
|
|
4168
4219
|
|
|
4169
4220
|
// ../core/dist/version.js
|
|
4170
|
-
var PACKAGE_VERSION = true ? "1.
|
|
4221
|
+
var PACKAGE_VERSION = true ? "1.8.0" : UNRELEASED_VERSION;
|
|
4171
4222
|
|
|
4172
4223
|
// ../core/dist/signing.js
|
|
4173
4224
|
var encoder = new TextEncoder();
|
|
@@ -4260,7 +4311,9 @@ var createWebhookHub = (options) => {
|
|
|
4260
4311
|
const faults = /* @__PURE__ */ new Map();
|
|
4261
4312
|
const held = /* @__PURE__ */ new Map();
|
|
4262
4313
|
const inFlight = /* @__PURE__ */ new Set();
|
|
4314
|
+
const controllers = /* @__PURE__ */ new Map();
|
|
4263
4315
|
let immediate = Promise.resolve();
|
|
4316
|
+
const snapshots = /* @__PURE__ */ new WeakMap();
|
|
4264
4317
|
const track = (work) => {
|
|
4265
4318
|
inFlight.add(work);
|
|
4266
4319
|
void work.finally(() => inFlight.delete(work));
|
|
@@ -4281,6 +4334,7 @@ var createWebhookHub = (options) => {
|
|
|
4281
4334
|
responseBody: null
|
|
4282
4335
|
};
|
|
4283
4336
|
const controller = new AbortController();
|
|
4337
|
+
controllers.set(delivery.id, controller);
|
|
4284
4338
|
const timer = scheduleTimer(() => controller.abort(), timeoutMs);
|
|
4285
4339
|
try {
|
|
4286
4340
|
const signed = await options.signer({
|
|
@@ -4310,6 +4364,7 @@ var createWebhookHub = (options) => {
|
|
|
4310
4364
|
} catch (error) {
|
|
4311
4365
|
record.error = controller.signal.aborted ? `timed out after ${timeoutMs}ms` : error instanceof Error ? error.message : String(error);
|
|
4312
4366
|
} finally {
|
|
4367
|
+
controllers.delete(delivery.id);
|
|
4313
4368
|
cancel(timer);
|
|
4314
4369
|
record.durationMs = now() - started;
|
|
4315
4370
|
delivery.attempts.push(record);
|
|
@@ -4327,6 +4382,8 @@ var createWebhookHub = (options) => {
|
|
|
4327
4382
|
if (!payloads.has(delivery.id))
|
|
4328
4383
|
return;
|
|
4329
4384
|
await attempt(delivery).then((ok) => {
|
|
4385
|
+
if (!payloads.has(delivery.id))
|
|
4386
|
+
return;
|
|
4330
4387
|
if (ok)
|
|
4331
4388
|
delivery.state = "delivered";
|
|
4332
4389
|
else
|
|
@@ -4388,6 +4445,37 @@ var createWebhookHub = (options) => {
|
|
|
4388
4445
|
fanOut(message);
|
|
4389
4446
|
};
|
|
4390
4447
|
const hub = {
|
|
4448
|
+
pending(namespace) {
|
|
4449
|
+
return inFlight.size + (held.get(namespace)?.length ?? 0) + [...deliveries.values()].filter((d) => d.namespace === namespace && d.state === "pending").length;
|
|
4450
|
+
},
|
|
4451
|
+
snapshot(namespace) {
|
|
4452
|
+
if (hub.pending(namespace) > 0)
|
|
4453
|
+
throw new Error("webhooks are not quiescent");
|
|
4454
|
+
const handle = {};
|
|
4455
|
+
snapshots.set(handle, structuredClone({
|
|
4456
|
+
namespace,
|
|
4457
|
+
endpoints: own.get(namespace) ?? [],
|
|
4458
|
+
messages: messages.filter((m) => m.namespace === namespace),
|
|
4459
|
+
deliveries: [...deliveries].filter(([, d]) => d.namespace === namespace),
|
|
4460
|
+
payloads: [...payloads].filter(([, p]) => p.message.namespace === namespace),
|
|
4461
|
+
faults: faults.get(namespace) ?? []
|
|
4462
|
+
}));
|
|
4463
|
+
return handle;
|
|
4464
|
+
},
|
|
4465
|
+
restore(namespace, handle) {
|
|
4466
|
+
const point = typeof handle === "object" && handle !== null ? snapshots.get(handle) : void 0;
|
|
4467
|
+
if (!point || point.namespace !== namespace || hub.pending(namespace) > 0)
|
|
4468
|
+
throw new Error("invalid webhook restore");
|
|
4469
|
+
hub.clear(namespace);
|
|
4470
|
+
const copied = structuredClone(point);
|
|
4471
|
+
own.set(namespace, copied.endpoints);
|
|
4472
|
+
messages.push(...copied.messages);
|
|
4473
|
+
for (const [id2, delivery] of copied.deliveries)
|
|
4474
|
+
deliveries.set(id2, delivery);
|
|
4475
|
+
for (const [id2, payload] of copied.payloads)
|
|
4476
|
+
payloads.set(id2, payload);
|
|
4477
|
+
faults.set(namespace, copied.faults);
|
|
4478
|
+
},
|
|
4391
4479
|
publish(input) {
|
|
4392
4480
|
const contentType = input.contentType ?? (input.form ? "application/x-www-form-urlencoded" : "application/json");
|
|
4393
4481
|
const body = typeof input.body === "string" ? input.body : input.form ? new URLSearchParams(input.form).toString() : JSON.stringify(input.body);
|
|
@@ -4478,6 +4566,7 @@ var createWebhookHub = (options) => {
|
|
|
4478
4566
|
for (const [id2, delivery] of deliveries) {
|
|
4479
4567
|
if (namespace !== void 0 && delivery.namespace !== namespace)
|
|
4480
4568
|
continue;
|
|
4569
|
+
controllers.get(id2)?.abort();
|
|
4481
4570
|
const timer = pending.get(id2);
|
|
4482
4571
|
if (timer !== void 0)
|
|
4483
4572
|
cancel(timer);
|
|
@@ -4665,6 +4754,20 @@ var createRuntime = (options) => {
|
|
|
4665
4754
|
const instances = /* @__PURE__ */ new Map();
|
|
4666
4755
|
const publicNamespaces = /* @__PURE__ */ new Set();
|
|
4667
4756
|
const branchRngs = /* @__PURE__ */ new Map();
|
|
4757
|
+
const namespaceClocks = /* @__PURE__ */ new Map();
|
|
4758
|
+
const namespaceForStorage = /* @__PURE__ */ new Map();
|
|
4759
|
+
let isolatedNamespaces = false;
|
|
4760
|
+
const namespaceClock = (name = DEFAULT_NAMESPACE) => {
|
|
4761
|
+
if (!isolatedNamespaces || name === DEFAULT_NAMESPACE)
|
|
4762
|
+
return clock;
|
|
4763
|
+
let found = namespaceClocks.get(name);
|
|
4764
|
+
if (!found) {
|
|
4765
|
+
found = createClock();
|
|
4766
|
+
namespaceClocks.set(name, found);
|
|
4767
|
+
}
|
|
4768
|
+
return found;
|
|
4769
|
+
};
|
|
4770
|
+
const fleetPoints = /* @__PURE__ */ new WeakMap();
|
|
4668
4771
|
const timelines = /* @__PURE__ */ new Map();
|
|
4669
4772
|
const branchStorage = /* @__PURE__ */ new Map();
|
|
4670
4773
|
const captured = /* @__PURE__ */ new Map();
|
|
@@ -4678,17 +4781,21 @@ var createRuntime = (options) => {
|
|
|
4678
4781
|
if (!NAMESPACE_PATTERN.test(key) || !NAMESPACE_PATTERN.test(publicNamespace)) {
|
|
4679
4782
|
throw new RangeError(`namespace must match ${NAMESPACE_PATTERN}: ${JSON.stringify(publicNamespace)}`);
|
|
4680
4783
|
}
|
|
4784
|
+
const createdContextRng = isolatedRng ?? (isolatedNamespaces && key !== DEFAULT_NAMESPACE ? createRng(options.seed ?? 0) : rng);
|
|
4681
4785
|
const created = options.create({
|
|
4682
4786
|
namespace: storageNamespace(key),
|
|
4683
4787
|
publicNamespace,
|
|
4684
4788
|
sqlite,
|
|
4685
|
-
clock,
|
|
4686
|
-
rng:
|
|
4789
|
+
clock: namespaceClock(publicNamespace),
|
|
4790
|
+
rng: createdContextRng
|
|
4687
4791
|
});
|
|
4688
4792
|
instances.set(key, created);
|
|
4793
|
+
namespaceForStorage.set(key, publicNamespace);
|
|
4689
4794
|
publicNamespaces.add(publicNamespace);
|
|
4690
4795
|
if (isolatedRng)
|
|
4691
4796
|
branchRngs.set(key, isolatedRng);
|
|
4797
|
+
else if (isolatedNamespaces && key !== DEFAULT_NAMESPACE)
|
|
4798
|
+
branchRngs.set(key, createdContextRng);
|
|
4692
4799
|
return created;
|
|
4693
4800
|
};
|
|
4694
4801
|
const instance = (name = DEFAULT_NAMESPACE) => instanceFor(name);
|
|
@@ -4706,7 +4813,7 @@ var createRuntime = (options) => {
|
|
|
4706
4813
|
captured.set(storage, snapshot2);
|
|
4707
4814
|
return Object.freeze({
|
|
4708
4815
|
snapshot: snapshot2,
|
|
4709
|
-
clock: Object.freeze(
|
|
4816
|
+
clock: Object.freeze(namespaceClock(namespaceForStorage.get(storage) ?? storage).state()),
|
|
4710
4817
|
rngState: (branchRngs.get(storage) ?? rng).state()
|
|
4711
4818
|
});
|
|
4712
4819
|
};
|
|
@@ -4716,7 +4823,7 @@ var createRuntime = (options) => {
|
|
|
4716
4823
|
return found;
|
|
4717
4824
|
instance(name);
|
|
4718
4825
|
found = new Timeline({
|
|
4719
|
-
now:
|
|
4826
|
+
now: namespaceClock(name).now,
|
|
4720
4827
|
...options.maxCheckpoints !== void 0 ? { maxCheckpoints: options.maxCheckpoints } : {}
|
|
4721
4828
|
});
|
|
4722
4829
|
found.commit(capture(name));
|
|
@@ -4743,12 +4850,13 @@ var createRuntime = (options) => {
|
|
|
4743
4850
|
const point = history2.checkout("main", at);
|
|
4744
4851
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
4745
4852
|
captured.set(namespace, point.value.snapshot);
|
|
4746
|
-
rng.setState(point.value.rngState);
|
|
4747
|
-
|
|
4853
|
+
(branchRngs.get(namespace) ?? rng).setState(point.value.rngState);
|
|
4854
|
+
const selectedClock = namespaceClock(namespace);
|
|
4855
|
+
selectedClock.set(point.value.clock.now);
|
|
4748
4856
|
if (point.value.clock.frozen)
|
|
4749
|
-
|
|
4857
|
+
selectedClock.freeze();
|
|
4750
4858
|
else
|
|
4751
|
-
|
|
4859
|
+
selectedClock.unfreeze();
|
|
4752
4860
|
}
|
|
4753
4861
|
return namespace;
|
|
4754
4862
|
}
|
|
@@ -4806,11 +4914,12 @@ var createRuntime = (options) => {
|
|
|
4806
4914
|
const storage = ensureBranch(namespace, branchName);
|
|
4807
4915
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
4808
4916
|
captured.set(storage, point.value.snapshot);
|
|
4809
|
-
|
|
4917
|
+
const selectedClock = namespaceClock(namespace);
|
|
4918
|
+
selectedClock.set(point.value.clock.now);
|
|
4810
4919
|
if (point.value.clock.frozen)
|
|
4811
|
-
|
|
4920
|
+
selectedClock.freeze();
|
|
4812
4921
|
else
|
|
4813
|
-
|
|
4922
|
+
selectedClock.unfreeze();
|
|
4814
4923
|
(branchRngs.get(storage) ?? rng).setState(point.value.rngState);
|
|
4815
4924
|
};
|
|
4816
4925
|
const reset = async (name = DEFAULT_NAMESPACE) => {
|
|
@@ -4818,10 +4927,21 @@ var createRuntime = (options) => {
|
|
|
4818
4927
|
options.webhooks?.clear();
|
|
4819
4928
|
for (const each of instances.values())
|
|
4820
4929
|
await each.reset();
|
|
4930
|
+
for (const each of branchRngs.values())
|
|
4931
|
+
each.reset();
|
|
4821
4932
|
timelines.clear();
|
|
4933
|
+
for (const storage of branchStorage.values()) {
|
|
4934
|
+
instances.delete(storage);
|
|
4935
|
+
branchRngs.delete(storage);
|
|
4936
|
+
namespaceForStorage.delete(storage);
|
|
4937
|
+
}
|
|
4822
4938
|
branchStorage.clear();
|
|
4823
|
-
branchRngs.clear();
|
|
4824
4939
|
captured.clear();
|
|
4940
|
+
faults.clear();
|
|
4941
|
+
clock.reset();
|
|
4942
|
+
rng.reset();
|
|
4943
|
+
for (const each of namespaceClocks.values())
|
|
4944
|
+
each.reset();
|
|
4825
4945
|
return;
|
|
4826
4946
|
}
|
|
4827
4947
|
options.webhooks?.clear(name);
|
|
@@ -4839,11 +4959,18 @@ var createRuntime = (options) => {
|
|
|
4839
4959
|
else
|
|
4840
4960
|
clearNamespace(sqlite, storageNamespace(storage));
|
|
4841
4961
|
branchStorage.delete(mapping);
|
|
4962
|
+
instances.delete(storage);
|
|
4963
|
+
namespaceForStorage.delete(storage);
|
|
4842
4964
|
branchRngs.delete(storage);
|
|
4843
4965
|
captured.delete(storage);
|
|
4844
4966
|
}
|
|
4845
4967
|
timelines.delete(name);
|
|
4846
4968
|
captured.delete(name);
|
|
4969
|
+
faults.restore(name, { rules: [], rngState: createRng(options.seed ?? 0).state() });
|
|
4970
|
+
namespaceClock(name).reset();
|
|
4971
|
+
(branchRngs.get(name) ?? rng).reset();
|
|
4972
|
+
journal.clear(name);
|
|
4973
|
+
metrics.reset(name);
|
|
4847
4974
|
};
|
|
4848
4975
|
const snapshot = (name = DEFAULT_NAMESPACE) => {
|
|
4849
4976
|
return checkpoint(name, "main").value.snapshot;
|
|
@@ -4881,6 +5008,53 @@ var createRuntime = (options) => {
|
|
|
4881
5008
|
rng,
|
|
4882
5009
|
credentials,
|
|
4883
5010
|
webhooks: options.webhooks,
|
|
5011
|
+
isolateNamespaces() {
|
|
5012
|
+
if (publicNamespaces.size > 1)
|
|
5013
|
+
throw new Error("enable namespace isolation before creating named namespaces");
|
|
5014
|
+
isolatedNamespaces = true;
|
|
5015
|
+
faults.isolateNamespaces();
|
|
5016
|
+
},
|
|
5017
|
+
namespaceClock,
|
|
5018
|
+
namespaceOf(request) {
|
|
5019
|
+
const url = new URL(request.url);
|
|
5020
|
+
const prefixed = PATH_PREFIX.exec(url.pathname);
|
|
5021
|
+
const selected = request.headers.get(NAMESPACE_HEADER) ?? (prefixed ? decodeURIComponent(prefixed[1]) : void 0);
|
|
5022
|
+
const path = prefixed ? prefixed[2] ?? "/" : url.pathname;
|
|
5023
|
+
if (path === "/__admin" || path.startsWith("/__admin/"))
|
|
5024
|
+
return url.searchParams.get("namespace") ?? selected ?? DEFAULT_NAMESPACE;
|
|
5025
|
+
if (selected !== void 0)
|
|
5026
|
+
return selected;
|
|
5027
|
+
const credential = options.credential?.(request);
|
|
5028
|
+
return (credential !== void 0 ? credentials.get(credential) : void 0) ?? DEFAULT_NAMESPACE;
|
|
5029
|
+
},
|
|
5030
|
+
fleetSnapshot(namespace) {
|
|
5031
|
+
instance(namespace);
|
|
5032
|
+
const handle = {};
|
|
5033
|
+
fleetPoints.set(handle, {
|
|
5034
|
+
namespace,
|
|
5035
|
+
state: capture(namespace),
|
|
5036
|
+
faults: faults.snapshot(namespace),
|
|
5037
|
+
webhooks: options.webhooks?.snapshot(namespace)
|
|
5038
|
+
});
|
|
5039
|
+
return handle;
|
|
5040
|
+
},
|
|
5041
|
+
fleetRestore(handle, namespace) {
|
|
5042
|
+
const point = typeof handle === "object" && handle !== null ? fleetPoints.get(handle) : void 0;
|
|
5043
|
+
if (!point || point.namespace !== namespace)
|
|
5044
|
+
throw new Error("invalid fleet checkpoint");
|
|
5045
|
+
restoreNamespace(sqlite, storageNamespace(namespace), point.state.snapshot);
|
|
5046
|
+
captured.set(namespace, point.state.snapshot);
|
|
5047
|
+
const selectedClock = namespaceClock(namespace);
|
|
5048
|
+
selectedClock.freeze();
|
|
5049
|
+
selectedClock.set(point.state.clock.now);
|
|
5050
|
+
if (!point.state.clock.frozen)
|
|
5051
|
+
selectedClock.unfreeze();
|
|
5052
|
+
(branchRngs.get(namespace) ?? rng).setState(point.state.rngState);
|
|
5053
|
+
faults.restore(namespace, point.faults);
|
|
5054
|
+
if (point.webhooks !== void 0)
|
|
5055
|
+
options.webhooks?.restore(namespace, point.webhooks);
|
|
5056
|
+
timelines.delete(namespace);
|
|
5057
|
+
},
|
|
4884
5058
|
applyPreset: (name, namespace = DEFAULT_NAMESPACE, overrides = {}) => {
|
|
4885
5059
|
const preset = options.presets?.[name];
|
|
4886
5060
|
if (!preset)
|
|
@@ -5056,6 +5230,7 @@ var createRuntime = (options) => {
|
|
|
5056
5230
|
startedAt: wallNow(),
|
|
5057
5231
|
wallNow,
|
|
5058
5232
|
clock,
|
|
5233
|
+
namespaceClock,
|
|
5059
5234
|
faults,
|
|
5060
5235
|
metrics,
|
|
5061
5236
|
journal,
|
|
@@ -6185,6 +6360,8 @@ var CustomerIoAPI = class {
|
|
|
6185
6360
|
};
|
|
6186
6361
|
|
|
6187
6362
|
export {
|
|
6363
|
+
createClock,
|
|
6364
|
+
parseDuration,
|
|
6188
6365
|
document2 as document,
|
|
6189
6366
|
operationIds,
|
|
6190
6367
|
supportedOperationIds,
|
|
@@ -6201,4 +6378,4 @@ export {
|
|
|
6201
6378
|
customerIoCredential,
|
|
6202
6379
|
CustomerIoAPI
|
|
6203
6380
|
};
|
|
6204
|
-
//# sourceMappingURL=chunk-
|
|
6381
|
+
//# sourceMappingURL=chunk-BGWMLNP4.js.map
|