@crvouga/mockingbird-service-payload-cms 1.3.0 → 1.5.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 +14 -2
- package/dist/{chunk-VQD2J3NH.js → chunk-3OUYZQTC.js} +3 -2
- package/dist/{chunk-VQD2J3NH.js.map → chunk-3OUYZQTC.js.map} +2 -2
- package/dist/{chunk-BB273WDT.js → chunk-7HS4CTPK.js} +2293 -99
- package/dist/chunk-7HS4CTPK.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +41 -3
- package/dist/index.js +1 -1
- package/dist/server.d.ts +73 -3
- package/dist/server.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-BB273WDT.js.map +0 -7
|
@@ -176,30 +176,30 @@ var createClock = (source = Date.now) => {
|
|
|
176
176
|
var Collection = class {
|
|
177
177
|
sqlite;
|
|
178
178
|
namespace;
|
|
179
|
-
|
|
180
|
-
constructor(sqlite, namespace,
|
|
179
|
+
collectionName;
|
|
180
|
+
constructor(sqlite, namespace, collectionName) {
|
|
181
181
|
this.sqlite = sqlite;
|
|
182
182
|
this.namespace = namespace;
|
|
183
|
-
this.
|
|
183
|
+
this.collectionName = collectionName;
|
|
184
184
|
}
|
|
185
185
|
bumpCollectionSeq() {
|
|
186
|
-
const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.
|
|
186
|
+
const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.collectionName);
|
|
187
187
|
const next = (row?.value ?? 0) + 1;
|
|
188
188
|
this.sqlite.prepare(`INSERT INTO mockingbird_sequences (namespace, name, kind, value) VALUES (?, ?, 'collection', ?)
|
|
189
|
-
ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.
|
|
189
|
+
ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.collectionName, next);
|
|
190
190
|
return next;
|
|
191
191
|
}
|
|
192
192
|
nextSequence() {
|
|
193
193
|
return this.sqlite.transaction(() => this.bumpCollectionSeq());
|
|
194
194
|
}
|
|
195
195
|
get(id) {
|
|
196
|
-
const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
196
|
+
const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
197
197
|
if (!row)
|
|
198
198
|
return void 0;
|
|
199
199
|
return JSON.parse(row.value).value;
|
|
200
200
|
}
|
|
201
201
|
has(id) {
|
|
202
|
-
const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
202
|
+
const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
203
203
|
return row !== void 0;
|
|
204
204
|
}
|
|
205
205
|
/** Insert a new record, assigning it the next sequence number. */
|
|
@@ -209,32 +209,32 @@ var Collection = class {
|
|
|
209
209
|
const stored = { seq, value };
|
|
210
210
|
this.sqlite.prepare(`INSERT INTO mockingbird_records (namespace, collection, id, seq, value)
|
|
211
211
|
VALUES (?, ?, ?, ?, ?)
|
|
212
|
-
ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.
|
|
212
|
+
ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.collectionName, id, seq, JSON.stringify(stored));
|
|
213
213
|
return stored;
|
|
214
214
|
});
|
|
215
215
|
}
|
|
216
216
|
/** Replace an existing record's value, keeping its position. */
|
|
217
217
|
update(id, value) {
|
|
218
218
|
return this.sqlite.transaction(() => {
|
|
219
|
-
const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
219
|
+
const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
220
220
|
if (!row)
|
|
221
221
|
return void 0;
|
|
222
222
|
const stored = { seq: row.seq, value };
|
|
223
|
-
this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.
|
|
223
|
+
this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.collectionName, id);
|
|
224
224
|
return stored;
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
delete(id) {
|
|
228
|
-
const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.
|
|
228
|
+
const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.collectionName, id);
|
|
229
229
|
return result.changes > 0;
|
|
230
230
|
}
|
|
231
231
|
/** How many records the collection holds, without reading them. */
|
|
232
232
|
count() {
|
|
233
|
-
const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.
|
|
233
|
+
const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.collectionName);
|
|
234
234
|
return Number(row?.n ?? 0);
|
|
235
235
|
}
|
|
236
236
|
list(options = {}) {
|
|
237
|
-
const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.
|
|
237
|
+
const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.collectionName);
|
|
238
238
|
const out = [];
|
|
239
239
|
for (const row of rows) {
|
|
240
240
|
const stored = JSON.parse(row.value);
|
|
@@ -491,16 +491,18 @@ var createControlPlane = (context) => {
|
|
|
491
491
|
uptimeMs: context.wallNow() - context.startedAt,
|
|
492
492
|
clock: context.clock.state(),
|
|
493
493
|
namespaces: context.namespaces().length,
|
|
494
|
+
adminUi: `${ADMIN_PREFIX}/ui`,
|
|
494
495
|
...context.describe()
|
|
495
496
|
});
|
|
496
497
|
}
|
|
497
498
|
if (url.pathname !== ADMIN_PREFIX && !url.pathname.startsWith(`${ADMIN_PREFIX}/`)) {
|
|
498
499
|
return void 0;
|
|
499
500
|
}
|
|
500
|
-
|
|
501
|
+
const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
|
|
502
|
+
const shell = request.method === "GET" && (path === "/ui" || path === "/ui/");
|
|
503
|
+
if (!shell && context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
|
|
501
504
|
return adminError(401, `missing or wrong ${ADMIN_KEY_HEADER}`);
|
|
502
505
|
}
|
|
503
|
-
const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
|
|
504
506
|
for (const route of routes) {
|
|
505
507
|
if (route.method !== request.method)
|
|
506
508
|
continue;
|
|
@@ -676,10 +678,10 @@ var OpenAPIReferenceError = class extends Error {
|
|
|
676
678
|
};
|
|
677
679
|
var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
678
680
|
var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
|
|
679
|
-
var resolveRef = (
|
|
681
|
+
var resolveRef = (document3, ref) => {
|
|
680
682
|
if (!ref.startsWith("#/"))
|
|
681
683
|
throw new OpenAPIReferenceError(ref);
|
|
682
|
-
let cursor =
|
|
684
|
+
let cursor = document3;
|
|
683
685
|
for (const raw of ref.slice(2).split("/")) {
|
|
684
686
|
const segment = unescapePointer(raw);
|
|
685
687
|
if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
|
|
@@ -691,14 +693,14 @@ var resolveRef = (document2, ref) => {
|
|
|
691
693
|
throw new OpenAPIReferenceError(ref);
|
|
692
694
|
return cursor;
|
|
693
695
|
};
|
|
694
|
-
var deref = (
|
|
696
|
+
var deref = (document3, value) => {
|
|
695
697
|
let current = value;
|
|
696
698
|
const seen = /* @__PURE__ */ new Set();
|
|
697
699
|
while (isReference(current)) {
|
|
698
700
|
if (seen.has(current.$ref))
|
|
699
701
|
throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
|
|
700
702
|
seen.add(current.$ref);
|
|
701
|
-
current = resolveRef(
|
|
703
|
+
current = resolveRef(document3, current.$ref);
|
|
702
704
|
}
|
|
703
705
|
return current;
|
|
704
706
|
};
|
|
@@ -716,36 +718,36 @@ var HTTP_METHODS = [
|
|
|
716
718
|
];
|
|
717
719
|
|
|
718
720
|
// ../../openapi/core/dist/document.js
|
|
719
|
-
var mergeParameters = (
|
|
721
|
+
var mergeParameters = (document3, item, own) => {
|
|
720
722
|
const merged = /* @__PURE__ */ new Map();
|
|
721
723
|
for (const raw of item.parameters ?? []) {
|
|
722
|
-
const parameter = deref(
|
|
724
|
+
const parameter = deref(document3, raw);
|
|
723
725
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
724
726
|
}
|
|
725
727
|
for (const raw of own ?? []) {
|
|
726
|
-
const parameter = deref(
|
|
728
|
+
const parameter = deref(document3, raw);
|
|
727
729
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
728
730
|
}
|
|
729
731
|
return [...merged.values()];
|
|
730
732
|
};
|
|
731
|
-
var listOperations = (
|
|
733
|
+
var listOperations = (document3) => {
|
|
732
734
|
const operations = [];
|
|
733
|
-
for (const [path, item] of Object.entries(
|
|
735
|
+
for (const [path, item] of Object.entries(document3.paths)) {
|
|
734
736
|
for (const method of HTTP_METHODS) {
|
|
735
737
|
const operation = item[method];
|
|
736
738
|
if (operation?.operationId === void 0)
|
|
737
739
|
continue;
|
|
738
740
|
const responses = {};
|
|
739
741
|
for (const [status, response] of Object.entries(operation.responses)) {
|
|
740
|
-
responses[status] = deref(
|
|
742
|
+
responses[status] = deref(document3, response);
|
|
741
743
|
}
|
|
742
744
|
operations.push({
|
|
743
745
|
operationId: operation.operationId,
|
|
744
746
|
method,
|
|
745
747
|
path,
|
|
746
748
|
operation,
|
|
747
|
-
parameters: mergeParameters(
|
|
748
|
-
requestBody: operation.requestBody === void 0 ? void 0 : deref(
|
|
749
|
+
parameters: mergeParameters(document3, item, operation.parameters),
|
|
750
|
+
requestBody: operation.requestBody === void 0 ? void 0 : deref(document3, operation.requestBody),
|
|
749
751
|
responses
|
|
750
752
|
});
|
|
751
753
|
}
|
|
@@ -1139,6 +1141,1737 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
1139
1141
|
});
|
|
1140
1142
|
};
|
|
1141
1143
|
|
|
1144
|
+
// ../../ui/dist/reset.js
|
|
1145
|
+
var CSS_RESET = `*,
|
|
1146
|
+
*::before,
|
|
1147
|
+
*::after {
|
|
1148
|
+
box-sizing: border-box;
|
|
1149
|
+
margin: 0;
|
|
1150
|
+
padding: 0;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
* {
|
|
1154
|
+
scrollbar-width: thin;
|
|
1155
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
*::-webkit-scrollbar {
|
|
1159
|
+
width: 12px;
|
|
1160
|
+
height: 12px;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
*::-webkit-scrollbar-track,
|
|
1164
|
+
*::-webkit-scrollbar-corner {
|
|
1165
|
+
background: Canvas;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
*::-webkit-scrollbar-thumb {
|
|
1169
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1170
|
+
border: 3px solid Canvas;
|
|
1171
|
+
border-radius: 999px;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
html {
|
|
1175
|
+
hanging-punctuation: first allow-end last;
|
|
1176
|
+
-webkit-text-size-adjust: none;
|
|
1177
|
+
text-size-adjust: none;
|
|
1178
|
+
tab-size: 4;
|
|
1179
|
+
font-family:
|
|
1180
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1181
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1182
|
+
font-size: 16px;
|
|
1183
|
+
line-height: 1.5;
|
|
1184
|
+
-webkit-font-smoothing: antialiased;
|
|
1185
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1186
|
+
text-rendering: optimizeLegibility;
|
|
1187
|
+
-webkit-tap-highlight-color: transparent;
|
|
1188
|
+
scroll-behavior: smooth;
|
|
1189
|
+
background: Canvas;
|
|
1190
|
+
color: CanvasText;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
body {
|
|
1194
|
+
min-height: 100svh;
|
|
1195
|
+
line-height: 1.5;
|
|
1196
|
+
background: Canvas;
|
|
1197
|
+
color: CanvasText;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
h1 {
|
|
1201
|
+
font-size: 2em;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
h2 {
|
|
1205
|
+
font-size: 1.5em;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
h3 {
|
|
1209
|
+
font-size: 1.17em;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
h4 {
|
|
1213
|
+
font-size: 1em;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
h5 {
|
|
1217
|
+
font-size: 0.83em;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
h6 {
|
|
1221
|
+
font-size: 0.67em;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
h1,
|
|
1225
|
+
h2,
|
|
1226
|
+
h3,
|
|
1227
|
+
h4,
|
|
1228
|
+
h5,
|
|
1229
|
+
h6 {
|
|
1230
|
+
font-weight: 700;
|
|
1231
|
+
line-height: 1.2;
|
|
1232
|
+
text-wrap: balance;
|
|
1233
|
+
overflow-wrap: break-word;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
p,
|
|
1237
|
+
li,
|
|
1238
|
+
figcaption,
|
|
1239
|
+
dd,
|
|
1240
|
+
dt,
|
|
1241
|
+
blockquote {
|
|
1242
|
+
overflow-wrap: break-word;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
p,
|
|
1246
|
+
li,
|
|
1247
|
+
figcaption,
|
|
1248
|
+
blockquote {
|
|
1249
|
+
text-wrap: pretty;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
ul,
|
|
1253
|
+
ol,
|
|
1254
|
+
menu {
|
|
1255
|
+
list-style: none;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
a {
|
|
1259
|
+
color: inherit;
|
|
1260
|
+
text-decoration: underline;
|
|
1261
|
+
text-decoration-thickness: 1px;
|
|
1262
|
+
text-underline-offset: 0.15em;
|
|
1263
|
+
text-decoration-skip-ink: auto;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
b,
|
|
1267
|
+
strong {
|
|
1268
|
+
font-weight: 700;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
small {
|
|
1272
|
+
font-size: 0.875em;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
code,
|
|
1276
|
+
kbd,
|
|
1277
|
+
samp,
|
|
1278
|
+
pre {
|
|
1279
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1280
|
+
font-size: 1em;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
sub,
|
|
1284
|
+
sup {
|
|
1285
|
+
font-size: 75%;
|
|
1286
|
+
line-height: 0;
|
|
1287
|
+
position: relative;
|
|
1288
|
+
vertical-align: baseline;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
sub {
|
|
1292
|
+
bottom: -0.25em;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
sup {
|
|
1296
|
+
top: -0.5em;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
abbr[title] {
|
|
1300
|
+
text-decoration: underline dotted;
|
|
1301
|
+
text-underline-offset: 0.15em;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
mark {
|
|
1305
|
+
background: Mark;
|
|
1306
|
+
color: MarkText;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
hr {
|
|
1310
|
+
height: 0;
|
|
1311
|
+
border: 0;
|
|
1312
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1313
|
+
color: inherit;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
img,
|
|
1317
|
+
picture,
|
|
1318
|
+
video,
|
|
1319
|
+
canvas {
|
|
1320
|
+
display: block;
|
|
1321
|
+
max-width: 100%;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
img,
|
|
1325
|
+
video {
|
|
1326
|
+
height: auto;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
svg {
|
|
1330
|
+
overflow: hidden;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
iframe {
|
|
1334
|
+
border: 0;
|
|
1335
|
+
max-width: 100%;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
table {
|
|
1339
|
+
border-collapse: collapse;
|
|
1340
|
+
border-spacing: 0;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
fieldset {
|
|
1344
|
+
border: 0;
|
|
1345
|
+
min-inline-size: 0;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
legend {
|
|
1349
|
+
padding: 0;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
button,
|
|
1353
|
+
input,
|
|
1354
|
+
select,
|
|
1355
|
+
textarea,
|
|
1356
|
+
optgroup {
|
|
1357
|
+
font: inherit;
|
|
1358
|
+
letter-spacing: inherit;
|
|
1359
|
+
color: inherit;
|
|
1360
|
+
margin: 0;
|
|
1361
|
+
vertical-align: middle;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
button,
|
|
1365
|
+
input[type="button"],
|
|
1366
|
+
input[type="submit"],
|
|
1367
|
+
input[type="reset"] {
|
|
1368
|
+
appearance: none;
|
|
1369
|
+
background: none;
|
|
1370
|
+
border: 0;
|
|
1371
|
+
padding: 0;
|
|
1372
|
+
cursor: pointer;
|
|
1373
|
+
text-align: center;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
input,
|
|
1377
|
+
textarea,
|
|
1378
|
+
select {
|
|
1379
|
+
background-color: Canvas;
|
|
1380
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1381
|
+
border-radius: 0;
|
|
1382
|
+
padding: 0.5em 0.65em;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
input[type="checkbox"],
|
|
1386
|
+
input[type="radio"],
|
|
1387
|
+
input[type="range"],
|
|
1388
|
+
input[type="file"],
|
|
1389
|
+
input[type="color"],
|
|
1390
|
+
input[type="button"],
|
|
1391
|
+
input[type="submit"],
|
|
1392
|
+
input[type="reset"],
|
|
1393
|
+
input[type="image"],
|
|
1394
|
+
input[type="hidden"] {
|
|
1395
|
+
background: none;
|
|
1396
|
+
border: 0;
|
|
1397
|
+
padding: 0;
|
|
1398
|
+
border-radius: 0;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
input[type="checkbox"],
|
|
1402
|
+
input[type="radio"] {
|
|
1403
|
+
accent-color: CanvasText;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
input[type="search"] {
|
|
1407
|
+
appearance: none;
|
|
1408
|
+
background-color: Canvas;
|
|
1409
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1413
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1414
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1415
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1416
|
+
-webkit-appearance: none;
|
|
1417
|
+
display: none;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
input[type="number"] {
|
|
1421
|
+
appearance: textfield;
|
|
1422
|
+
background-color: Canvas;
|
|
1423
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1427
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1428
|
+
-webkit-appearance: none;
|
|
1429
|
+
margin: 0;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
textarea {
|
|
1433
|
+
resize: vertical;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
::placeholder {
|
|
1437
|
+
opacity: 1;
|
|
1438
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
:focus-visible {
|
|
1442
|
+
outline: 2px solid CanvasText;
|
|
1443
|
+
outline-offset: 2px;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
:focus:not(:focus-visible) {
|
|
1447
|
+
outline: none;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
:disabled,
|
|
1451
|
+
[disabled] {
|
|
1452
|
+
cursor: default;
|
|
1453
|
+
opacity: 0.6;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
label,
|
|
1457
|
+
summary,
|
|
1458
|
+
select,
|
|
1459
|
+
[role="button"] {
|
|
1460
|
+
cursor: pointer;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
summary {
|
|
1464
|
+
display: list-item;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
details {
|
|
1468
|
+
display: block;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
dialog {
|
|
1472
|
+
margin: auto;
|
|
1473
|
+
padding: 1rem;
|
|
1474
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1475
|
+
background: Canvas;
|
|
1476
|
+
color: CanvasText;
|
|
1477
|
+
max-width: calc(100vw - 2rem);
|
|
1478
|
+
max-height: calc(100svh - 2rem);
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
dialog:not([open]) {
|
|
1482
|
+
display: none;
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
::backdrop {
|
|
1486
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
[hidden] {
|
|
1490
|
+
display: none !important;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
::selection {
|
|
1494
|
+
background: Highlight;
|
|
1495
|
+
color: HighlightText;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1499
|
+
*,
|
|
1500
|
+
*::before,
|
|
1501
|
+
*::after {
|
|
1502
|
+
animation-duration: 0.01ms !important;
|
|
1503
|
+
animation-iteration-count: 1 !important;
|
|
1504
|
+
transition-duration: 0.01ms !important;
|
|
1505
|
+
scroll-behavior: auto !important;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
@media (pointer: coarse) {
|
|
1510
|
+
input,
|
|
1511
|
+
select,
|
|
1512
|
+
textarea {
|
|
1513
|
+
font-size: max(16px, 1em);
|
|
1514
|
+
}
|
|
1515
|
+
}`;
|
|
1516
|
+
|
|
1517
|
+
// ../core/dist/admin-client.js
|
|
1518
|
+
function isRecord2(value) {
|
|
1519
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1520
|
+
}
|
|
1521
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1522
|
+
const clip = (value, max) => {
|
|
1523
|
+
if (typeof value !== "string")
|
|
1524
|
+
return null;
|
|
1525
|
+
const trimmed = value.trim();
|
|
1526
|
+
if (trimmed === "")
|
|
1527
|
+
return null;
|
|
1528
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1529
|
+
};
|
|
1530
|
+
const httpUrl = (value) => {
|
|
1531
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1532
|
+
return null;
|
|
1533
|
+
try {
|
|
1534
|
+
const url = new URL(value);
|
|
1535
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1536
|
+
return null;
|
|
1537
|
+
return url.href;
|
|
1538
|
+
} catch {
|
|
1539
|
+
return null;
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
const hexColor = (value) => {
|
|
1543
|
+
if (typeof value !== "string")
|
|
1544
|
+
return null;
|
|
1545
|
+
const raw = value.trim();
|
|
1546
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1547
|
+
};
|
|
1548
|
+
const hostname = (value) => {
|
|
1549
|
+
try {
|
|
1550
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1551
|
+
} catch {
|
|
1552
|
+
return value;
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
host.replaceChildren();
|
|
1556
|
+
host.hidden = true;
|
|
1557
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1558
|
+
return;
|
|
1559
|
+
const row = catalog[service];
|
|
1560
|
+
if (!isRecord2(row))
|
|
1561
|
+
return;
|
|
1562
|
+
const vendor = clip(row.vendor, 80);
|
|
1563
|
+
const website = httpUrl(row.website);
|
|
1564
|
+
const guide = httpUrl(row.guide);
|
|
1565
|
+
const docs = httpUrl(row.docs);
|
|
1566
|
+
const logo = httpUrl(row.logo);
|
|
1567
|
+
const color = hexColor(row.color);
|
|
1568
|
+
const description = clip(row.description, 280);
|
|
1569
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1570
|
+
return;
|
|
1571
|
+
const add = (node) => {
|
|
1572
|
+
host.append(node);
|
|
1573
|
+
return node;
|
|
1574
|
+
};
|
|
1575
|
+
if (logo !== null) {
|
|
1576
|
+
const img = doc.createElement("img");
|
|
1577
|
+
img.alt = "";
|
|
1578
|
+
img.src = logo;
|
|
1579
|
+
img.width = 16;
|
|
1580
|
+
img.height = 16;
|
|
1581
|
+
img.decoding = "async";
|
|
1582
|
+
img.referrerPolicy = "no-referrer";
|
|
1583
|
+
if (color !== null)
|
|
1584
|
+
img.style.borderColor = color;
|
|
1585
|
+
add(img);
|
|
1586
|
+
}
|
|
1587
|
+
const name = doc.createElement("span");
|
|
1588
|
+
name.className = "vendor-name";
|
|
1589
|
+
name.textContent = vendor;
|
|
1590
|
+
if (description !== null)
|
|
1591
|
+
name.title = description;
|
|
1592
|
+
add(name);
|
|
1593
|
+
const sep = () => {
|
|
1594
|
+
const node = doc.createElement("span");
|
|
1595
|
+
node.className = "vendor-sep";
|
|
1596
|
+
node.setAttribute("aria-hidden", "true");
|
|
1597
|
+
node.textContent = "\xB7";
|
|
1598
|
+
return node;
|
|
1599
|
+
};
|
|
1600
|
+
const link = (href, label, title) => {
|
|
1601
|
+
const node = doc.createElement("a");
|
|
1602
|
+
node.className = "vendor-link";
|
|
1603
|
+
node.href = href;
|
|
1604
|
+
node.target = "_blank";
|
|
1605
|
+
node.rel = "noopener noreferrer";
|
|
1606
|
+
node.referrerPolicy = "no-referrer";
|
|
1607
|
+
node.textContent = label;
|
|
1608
|
+
node.title = title;
|
|
1609
|
+
return node;
|
|
1610
|
+
};
|
|
1611
|
+
if (website !== null) {
|
|
1612
|
+
add(sep());
|
|
1613
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1614
|
+
}
|
|
1615
|
+
if (guide !== null) {
|
|
1616
|
+
add(sep());
|
|
1617
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1618
|
+
}
|
|
1619
|
+
if (docs !== null) {
|
|
1620
|
+
add(sep());
|
|
1621
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1622
|
+
}
|
|
1623
|
+
host.removeAttribute("hidden");
|
|
1624
|
+
host.hidden = false;
|
|
1625
|
+
}
|
|
1626
|
+
function startAdminBrand(env) {
|
|
1627
|
+
const requested = env.params.get("brands");
|
|
1628
|
+
let brandsUrl = env.brandsUrl;
|
|
1629
|
+
if (requested) {
|
|
1630
|
+
try {
|
|
1631
|
+
const url = new URL(requested, env.location.href);
|
|
1632
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1633
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1634
|
+
brandsUrl = url.href;
|
|
1635
|
+
} catch {
|
|
1636
|
+
brandsUrl = env.brandsUrl;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
const vendorHost = env.$("vendor");
|
|
1640
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1641
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1642
|
+
if (vendorHost === null)
|
|
1643
|
+
return;
|
|
1644
|
+
env.fetch(brandsUrl, {
|
|
1645
|
+
headers: { accept: "application/json" },
|
|
1646
|
+
signal: AbortSignal.timeout(5e3)
|
|
1647
|
+
}).then(async (response) => {
|
|
1648
|
+
if (!response.ok)
|
|
1649
|
+
return null;
|
|
1650
|
+
const catalog = await response.json();
|
|
1651
|
+
return catalog;
|
|
1652
|
+
}).then((catalog) => {
|
|
1653
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1654
|
+
}).catch(() => {
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
function faultPresetList(value) {
|
|
1658
|
+
if (!isRecord2(value))
|
|
1659
|
+
throw new Error("Fault presets response was not an object");
|
|
1660
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1661
|
+
return { presets: [] };
|
|
1662
|
+
}
|
|
1663
|
+
if (!Array.isArray(value.presets))
|
|
1664
|
+
throw new Error("Fault presets response was not a list");
|
|
1665
|
+
return {
|
|
1666
|
+
presets: value.presets.flatMap((item) => {
|
|
1667
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1668
|
+
return [];
|
|
1669
|
+
return [{ name: item.name }];
|
|
1670
|
+
})
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
function bootAdmin(config) {
|
|
1674
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1675
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1676
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1677
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1678
|
+
const readJson2 = (text) => {
|
|
1679
|
+
const value = JSON.parse(text);
|
|
1680
|
+
return value;
|
|
1681
|
+
};
|
|
1682
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1683
|
+
switch (char) {
|
|
1684
|
+
case "&":
|
|
1685
|
+
return "&";
|
|
1686
|
+
case "<":
|
|
1687
|
+
return "<";
|
|
1688
|
+
case ">":
|
|
1689
|
+
return ">";
|
|
1690
|
+
case '"':
|
|
1691
|
+
return """;
|
|
1692
|
+
default:
|
|
1693
|
+
return "'";
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
const el = (id, kind) => {
|
|
1697
|
+
const node = document.getElementById(id);
|
|
1698
|
+
if (!(node instanceof kind))
|
|
1699
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1700
|
+
return node;
|
|
1701
|
+
};
|
|
1702
|
+
const errorMessage = (data, fallback) => {
|
|
1703
|
+
if (!isRecord2(data))
|
|
1704
|
+
return fallback;
|
|
1705
|
+
const error = data.error;
|
|
1706
|
+
if (!isRecord2(error) || typeof error.message !== "string" || error.message === "") {
|
|
1707
|
+
return fallback;
|
|
1708
|
+
}
|
|
1709
|
+
return error.message;
|
|
1710
|
+
};
|
|
1711
|
+
const requireList = (value, label) => {
|
|
1712
|
+
if (value === void 0 || value === null)
|
|
1713
|
+
return [];
|
|
1714
|
+
if (!Array.isArray(value))
|
|
1715
|
+
throw new Error(`${label} was not a list`);
|
|
1716
|
+
return value;
|
|
1717
|
+
};
|
|
1718
|
+
const state = {
|
|
1719
|
+
namespace: "default",
|
|
1720
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1721
|
+
view: "overview",
|
|
1722
|
+
collection: "",
|
|
1723
|
+
shape: null,
|
|
1724
|
+
route: null,
|
|
1725
|
+
editing: null
|
|
1726
|
+
};
|
|
1727
|
+
const standard = new Set(config.standardRoutes);
|
|
1728
|
+
const banner = el("banner", HTMLElement);
|
|
1729
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1730
|
+
keyInput.value = state.key;
|
|
1731
|
+
const params = new URLSearchParams(location.search);
|
|
1732
|
+
const queryKey = params.get("key");
|
|
1733
|
+
if (queryKey) {
|
|
1734
|
+
state.key = queryKey;
|
|
1735
|
+
keyInput.value = state.key;
|
|
1736
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1737
|
+
params.delete("key");
|
|
1738
|
+
const next = params.toString();
|
|
1739
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1740
|
+
}
|
|
1741
|
+
const queryNamespace = params.get("namespace");
|
|
1742
|
+
if (queryNamespace)
|
|
1743
|
+
state.namespace = queryNamespace;
|
|
1744
|
+
const showError = (error) => {
|
|
1745
|
+
banner.textContent = error instanceof Error ? error.message : String(error);
|
|
1746
|
+
banner.classList.add("show");
|
|
1747
|
+
};
|
|
1748
|
+
const clearError = () => {
|
|
1749
|
+
banner.classList.remove("show");
|
|
1750
|
+
};
|
|
1751
|
+
const api = async (method, path, body) => {
|
|
1752
|
+
const headers = { accept: "application/json" };
|
|
1753
|
+
if (state.key !== "")
|
|
1754
|
+
headers[config.adminKeyHeader] = state.key;
|
|
1755
|
+
if (state.namespace !== "")
|
|
1756
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
1757
|
+
if (body !== void 0)
|
|
1758
|
+
headers["content-type"] = "application/json";
|
|
1759
|
+
const init = { method, headers };
|
|
1760
|
+
if (body !== void 0)
|
|
1761
|
+
init.body = JSON.stringify(body);
|
|
1762
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
1763
|
+
const text = await response.text();
|
|
1764
|
+
let data = null;
|
|
1765
|
+
if (text !== "") {
|
|
1766
|
+
try {
|
|
1767
|
+
data = readJson2(text);
|
|
1768
|
+
} catch {
|
|
1769
|
+
data = { raw: text };
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
if (response.status === 401) {
|
|
1773
|
+
keyInput.focus();
|
|
1774
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
1775
|
+
}
|
|
1776
|
+
if (!response.ok) {
|
|
1777
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
1778
|
+
}
|
|
1779
|
+
return data;
|
|
1780
|
+
};
|
|
1781
|
+
const originGet = async (path) => {
|
|
1782
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
1783
|
+
if (!response.ok)
|
|
1784
|
+
throw new Error(`${response.status} ${path}`);
|
|
1785
|
+
const value = await response.json();
|
|
1786
|
+
return value;
|
|
1787
|
+
};
|
|
1788
|
+
const panelApi = {
|
|
1789
|
+
get: (path) => api("GET", path),
|
|
1790
|
+
send: (method, path, body) => api(method, path, body),
|
|
1791
|
+
namespace: () => state.namespace
|
|
1792
|
+
};
|
|
1793
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
1794
|
+
const setTheme = (theme) => {
|
|
1795
|
+
if (theme)
|
|
1796
|
+
document.documentElement.dataset.theme = theme;
|
|
1797
|
+
else
|
|
1798
|
+
delete document.documentElement.dataset.theme;
|
|
1799
|
+
};
|
|
1800
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
1801
|
+
if (storedTheme)
|
|
1802
|
+
setTheme(storedTheme);
|
|
1803
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
1804
|
+
const current = document.documentElement.dataset.theme;
|
|
1805
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1806
|
+
const next = dark ? "light" : "dark";
|
|
1807
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
1808
|
+
setTheme(next);
|
|
1809
|
+
});
|
|
1810
|
+
const show = (view) => {
|
|
1811
|
+
state.view = view;
|
|
1812
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
1813
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1814
|
+
continue;
|
|
1815
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
1816
|
+
}
|
|
1817
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
1818
|
+
if (!(section instanceof HTMLElement))
|
|
1819
|
+
continue;
|
|
1820
|
+
section.hidden = section.id !== `view-${view}`;
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
1824
|
+
const target = event.target;
|
|
1825
|
+
if (!(target instanceof Element))
|
|
1826
|
+
return;
|
|
1827
|
+
const button = target.closest("button[data-view]");
|
|
1828
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1829
|
+
return;
|
|
1830
|
+
const view = button.dataset.view;
|
|
1831
|
+
if (view === void 0)
|
|
1832
|
+
return;
|
|
1833
|
+
show(view);
|
|
1834
|
+
refresh().catch(showError);
|
|
1835
|
+
});
|
|
1836
|
+
const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
|
|
1837
|
+
const table = (columns, rows) => {
|
|
1838
|
+
if (rows.length === 0)
|
|
1839
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
1840
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
1841
|
+
const body = rows.map((row) => {
|
|
1842
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
|
|
1843
|
+
const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
|
|
1844
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
1845
|
+
}).join("");
|
|
1846
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
1847
|
+
};
|
|
1848
|
+
const preview = (value) => {
|
|
1849
|
+
const text = JSON.stringify(value) ?? "null";
|
|
1850
|
+
return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
|
|
1851
|
+
};
|
|
1852
|
+
const when = (epoch) => {
|
|
1853
|
+
const date = new Date(epoch);
|
|
1854
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
1855
|
+
};
|
|
1856
|
+
const clockCard = (epoch) => {
|
|
1857
|
+
const date = new Date(epoch);
|
|
1858
|
+
if (Number.isNaN(date.getTime()))
|
|
1859
|
+
return esc(String(epoch));
|
|
1860
|
+
const iso = date.toISOString();
|
|
1861
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
1862
|
+
};
|
|
1863
|
+
const decodeClock = (value) => {
|
|
1864
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
1865
|
+
throw new Error("Clock response was not a clock");
|
|
1866
|
+
}
|
|
1867
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
1868
|
+
};
|
|
1869
|
+
const decodeField = (value) => {
|
|
1870
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
1871
|
+
return void 0;
|
|
1872
|
+
}
|
|
1873
|
+
const field = {
|
|
1874
|
+
name: value.name,
|
|
1875
|
+
kind: value.kind,
|
|
1876
|
+
optional: value.optional === true
|
|
1877
|
+
};
|
|
1878
|
+
if (typeof value.description === "string")
|
|
1879
|
+
field.description = value.description;
|
|
1880
|
+
if (Array.isArray(value.fields)) {
|
|
1881
|
+
field.fields = value.fields.flatMap((item) => {
|
|
1882
|
+
const child = decodeField(item);
|
|
1883
|
+
return child === void 0 ? [] : [child];
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1886
|
+
return field;
|
|
1887
|
+
};
|
|
1888
|
+
const decodeCollection = (value) => {
|
|
1889
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
1890
|
+
return void 0;
|
|
1891
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
1892
|
+
const field = decodeField(item);
|
|
1893
|
+
return field === void 0 ? [] : [field];
|
|
1894
|
+
}) : [];
|
|
1895
|
+
const collection = {
|
|
1896
|
+
name: value.name,
|
|
1897
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
1898
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
1899
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
1900
|
+
fields
|
|
1901
|
+
};
|
|
1902
|
+
if (typeof value.description === "string")
|
|
1903
|
+
collection.description = value.description;
|
|
1904
|
+
return collection;
|
|
1905
|
+
};
|
|
1906
|
+
const decodeState = (value) => {
|
|
1907
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
1908
|
+
throw new Error("State response has no collection list");
|
|
1909
|
+
}
|
|
1910
|
+
return {
|
|
1911
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
1912
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
1913
|
+
collections: value.collections.flatMap((item) => {
|
|
1914
|
+
const collection = decodeCollection(item);
|
|
1915
|
+
return collection === void 0 ? [] : [collection];
|
|
1916
|
+
})
|
|
1917
|
+
};
|
|
1918
|
+
};
|
|
1919
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
1920
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
1921
|
+
return [];
|
|
1922
|
+
return [
|
|
1923
|
+
{
|
|
1924
|
+
id: item.id,
|
|
1925
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
1926
|
+
value: item.value,
|
|
1927
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
1928
|
+
}
|
|
1929
|
+
];
|
|
1930
|
+
});
|
|
1931
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
1932
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
1933
|
+
if (!isRecord2(item))
|
|
1934
|
+
return [];
|
|
1935
|
+
return [
|
|
1936
|
+
{
|
|
1937
|
+
at: textOf(item.at),
|
|
1938
|
+
method: textOf(item.method),
|
|
1939
|
+
path: textOf(item.path),
|
|
1940
|
+
status: textOf(item.status),
|
|
1941
|
+
durationMs: textOf(item.durationMs),
|
|
1942
|
+
operationId: textOf(item.operationId)
|
|
1943
|
+
}
|
|
1944
|
+
];
|
|
1945
|
+
});
|
|
1946
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
1947
|
+
if (!isRecord2(item))
|
|
1948
|
+
return [];
|
|
1949
|
+
return [
|
|
1950
|
+
{
|
|
1951
|
+
id: textOf(item.id),
|
|
1952
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
1953
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
1954
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
1955
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
1956
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
1957
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
1958
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
1959
|
+
}
|
|
1960
|
+
];
|
|
1961
|
+
});
|
|
1962
|
+
const loadNamespaces = async () => {
|
|
1963
|
+
const data = await api("GET", "/namespaces");
|
|
1964
|
+
const select = el("namespace", HTMLSelectElement);
|
|
1965
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
1966
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
1967
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
1968
|
+
if (!names.includes(state.namespace))
|
|
1969
|
+
names.unshift(state.namespace);
|
|
1970
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
1971
|
+
select.value = state.namespace;
|
|
1972
|
+
};
|
|
1973
|
+
const renderOverview = async () => {
|
|
1974
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
1975
|
+
originGet("/health"),
|
|
1976
|
+
api("GET", "/state"),
|
|
1977
|
+
api("GET", "/clock"),
|
|
1978
|
+
api("GET", "/requests?limit=8")
|
|
1979
|
+
]);
|
|
1980
|
+
if (!isRecord2(health))
|
|
1981
|
+
throw new Error("Health response was not an object");
|
|
1982
|
+
const decoded = decodeState(shape);
|
|
1983
|
+
state.shape = decoded;
|
|
1984
|
+
const time = decodeClock(clock);
|
|
1985
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
1986
|
+
{
|
|
1987
|
+
k: "Service",
|
|
1988
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
1989
|
+
},
|
|
1990
|
+
{
|
|
1991
|
+
k: "Status",
|
|
1992
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
1993
|
+
},
|
|
1994
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
1995
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
1996
|
+
{
|
|
1997
|
+
k: "Records",
|
|
1998
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
1999
|
+
},
|
|
2000
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
2001
|
+
]);
|
|
2002
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
2003
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2004
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2005
|
+
{
|
|
2006
|
+
label: "Status",
|
|
2007
|
+
cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
|
|
2008
|
+
},
|
|
2009
|
+
{ label: "Operation", cell: (row) => esc(row.operationId) }
|
|
2010
|
+
], decodeJournal(journal));
|
|
2011
|
+
};
|
|
2012
|
+
const schemaChips = (collection) => {
|
|
2013
|
+
if (collection.fields.length === 0) {
|
|
2014
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
2015
|
+
}
|
|
2016
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
2017
|
+
};
|
|
2018
|
+
const renderState = async () => {
|
|
2019
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
2020
|
+
state.shape = shape;
|
|
2021
|
+
const host = el("collections", HTMLElement);
|
|
2022
|
+
if (shape.collections.length === 0) {
|
|
2023
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
2024
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
2025
|
+
el("records", HTMLElement).innerHTML = "";
|
|
2026
|
+
return;
|
|
2027
|
+
}
|
|
2028
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
2029
|
+
const first = shape.collections[0];
|
|
2030
|
+
if (first === void 0)
|
|
2031
|
+
return;
|
|
2032
|
+
state.collection = first.name;
|
|
2033
|
+
}
|
|
2034
|
+
host.innerHTML = shape.collections.map((item) => `<button type="button" class="collection" data-collection="${esc(item.name)}" aria-current="${item.name === state.collection ? "true" : "false"}"><strong>${esc(item.label)}</strong><small>${esc(item.count)} \xB7 ${esc(item.source)}</small></button>`).join("");
|
|
2035
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
2036
|
+
if (selected === void 0)
|
|
2037
|
+
return;
|
|
2038
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
2039
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
2040
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
2041
|
+
el("records", HTMLElement).innerHTML = table([
|
|
2042
|
+
{ label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
|
|
2043
|
+
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
2044
|
+
{ label: "Value", cell: (row) => preview(row.value) }
|
|
2045
|
+
], decodeRecords(page));
|
|
2046
|
+
};
|
|
2047
|
+
const renderClock = async () => {
|
|
2048
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
2049
|
+
el("clock-readout", HTMLElement).innerHTML = `<div class="k">Now</div><div class="v">${esc(when(clock.now))}</div><p>${esc(clock.now)} ms \xB7 offset ${esc(clock.offsetMs)} ms ${clock.frozen ? "<span class='badge warn'>frozen</span>" : "<span class='badge ok'>live</span>"}</p>`;
|
|
2050
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
2051
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
2052
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
2053
|
+
};
|
|
2054
|
+
const renderFaults = async () => {
|
|
2055
|
+
const [faults, presets] = await Promise.all([
|
|
2056
|
+
api("GET", "/faults"),
|
|
2057
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2058
|
+
]);
|
|
2059
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
2060
|
+
const current = select.value;
|
|
2061
|
+
const list = faultPresetList(presets).presets;
|
|
2062
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
2063
|
+
select.value = current;
|
|
2064
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
2065
|
+
{ label: "Id", cell: (row) => esc(row.id) },
|
|
2066
|
+
{
|
|
2067
|
+
label: "Match",
|
|
2068
|
+
cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
2069
|
+
},
|
|
2070
|
+
{
|
|
2071
|
+
label: "Effect",
|
|
2072
|
+
cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
|
|
2073
|
+
}
|
|
2074
|
+
], decodeFaults(faults));
|
|
2075
|
+
};
|
|
2076
|
+
const renderJournal = async () => {
|
|
2077
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
2078
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
2079
|
+
{ label: "When", cell: (row) => esc(row.at) },
|
|
2080
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2081
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2082
|
+
{ label: "Status", cell: (row) => esc(row.status) },
|
|
2083
|
+
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
2084
|
+
], decodeJournal(journal));
|
|
2085
|
+
};
|
|
2086
|
+
const renderRoutes = async () => {
|
|
2087
|
+
const data = await api("GET", "/");
|
|
2088
|
+
if (!isRecord2(data))
|
|
2089
|
+
throw new Error("Route list was not an object");
|
|
2090
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
2091
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
2092
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
2093
|
+
const parts = route.split(" ");
|
|
2094
|
+
const method = parts[0] ?? "";
|
|
2095
|
+
const path = parts.slice(1).join(" ");
|
|
2096
|
+
return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}">Use</button></div>`;
|
|
2097
|
+
}).join("");
|
|
2098
|
+
};
|
|
2099
|
+
const renderers = {
|
|
2100
|
+
overview: renderOverview,
|
|
2101
|
+
state: renderState,
|
|
2102
|
+
clock: renderClock,
|
|
2103
|
+
faults: renderFaults,
|
|
2104
|
+
journal: renderJournal,
|
|
2105
|
+
routes: renderRoutes
|
|
2106
|
+
};
|
|
2107
|
+
async function refresh() {
|
|
2108
|
+
clearError();
|
|
2109
|
+
const render = renderers[state.view];
|
|
2110
|
+
if (render)
|
|
2111
|
+
await render();
|
|
2112
|
+
}
|
|
2113
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
2114
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
2115
|
+
refresh().catch(showError);
|
|
2116
|
+
});
|
|
2117
|
+
keyInput.addEventListener("change", () => {
|
|
2118
|
+
state.key = keyInput.value.trim();
|
|
2119
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
2120
|
+
refresh().catch(showError);
|
|
2121
|
+
});
|
|
2122
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
2123
|
+
refresh().catch(showError);
|
|
2124
|
+
});
|
|
2125
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
2126
|
+
const target = event.target;
|
|
2127
|
+
if (!(target instanceof Element))
|
|
2128
|
+
return;
|
|
2129
|
+
const button = target.closest("[data-collection]");
|
|
2130
|
+
if (!(button instanceof HTMLElement))
|
|
2131
|
+
return;
|
|
2132
|
+
const collection = button.dataset.collection;
|
|
2133
|
+
if (collection === void 0)
|
|
2134
|
+
return;
|
|
2135
|
+
state.collection = collection;
|
|
2136
|
+
renderState().catch(showError);
|
|
2137
|
+
});
|
|
2138
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
2139
|
+
const target = event.target;
|
|
2140
|
+
if (!(target instanceof Element))
|
|
2141
|
+
return;
|
|
2142
|
+
const row = target.closest("[data-id]");
|
|
2143
|
+
if (!(row instanceof HTMLElement))
|
|
2144
|
+
return;
|
|
2145
|
+
const id = row.dataset.id;
|
|
2146
|
+
if (id === void 0)
|
|
2147
|
+
return;
|
|
2148
|
+
openEditor(id).catch(showError);
|
|
2149
|
+
});
|
|
2150
|
+
const editor = el("editor", HTMLDialogElement);
|
|
2151
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
2152
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
2153
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
2154
|
+
async function openEditor(id) {
|
|
2155
|
+
state.editing = id;
|
|
2156
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
2157
|
+
editorId.value = id ?? "";
|
|
2158
|
+
editorId.readOnly = id !== null;
|
|
2159
|
+
editorDelete.hidden = id === null;
|
|
2160
|
+
if (id) {
|
|
2161
|
+
const record = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
2162
|
+
if (!isRecord2(record))
|
|
2163
|
+
throw new Error("Record response was not an object");
|
|
2164
|
+
editorValue.value = JSON.stringify(record.value, null, 2) ?? "";
|
|
2165
|
+
} else {
|
|
2166
|
+
editorValue.value = "{\n \n}";
|
|
2167
|
+
}
|
|
2168
|
+
editor.showModal();
|
|
2169
|
+
}
|
|
2170
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2171
|
+
openEditor(null).catch(showError);
|
|
2172
|
+
});
|
|
2173
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2174
|
+
const submitter = event.submitter;
|
|
2175
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2176
|
+
return;
|
|
2177
|
+
event.preventDefault();
|
|
2178
|
+
let value;
|
|
2179
|
+
try {
|
|
2180
|
+
value = readJson2(editorValue.value);
|
|
2181
|
+
} catch {
|
|
2182
|
+
showError(new Error("Value is not JSON"));
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
const id = editorId.value.trim();
|
|
2186
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2187
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2188
|
+
request.then(() => {
|
|
2189
|
+
editor.close();
|
|
2190
|
+
return renderState();
|
|
2191
|
+
}).catch(showError);
|
|
2192
|
+
});
|
|
2193
|
+
editorDelete.addEventListener("click", () => {
|
|
2194
|
+
const id = state.editing;
|
|
2195
|
+
if (!id)
|
|
2196
|
+
return;
|
|
2197
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2198
|
+
editor.close();
|
|
2199
|
+
return renderState();
|
|
2200
|
+
}).catch(showError);
|
|
2201
|
+
});
|
|
2202
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2203
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2204
|
+
continue;
|
|
2205
|
+
button.addEventListener("click", () => {
|
|
2206
|
+
const raw = button.dataset.advance;
|
|
2207
|
+
if (raw === void 0)
|
|
2208
|
+
return;
|
|
2209
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2213
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2214
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2215
|
+
});
|
|
2216
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2217
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2218
|
+
});
|
|
2219
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2220
|
+
event.preventDefault();
|
|
2221
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2222
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2223
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2224
|
+
});
|
|
2225
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2226
|
+
event.preventDefault();
|
|
2227
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2228
|
+
if (preset !== "") {
|
|
2229
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2230
|
+
return;
|
|
2231
|
+
}
|
|
2232
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2233
|
+
if (!Number.isFinite(status)) {
|
|
2234
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2235
|
+
return;
|
|
2236
|
+
}
|
|
2237
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2238
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2239
|
+
api("POST", "/faults", {
|
|
2240
|
+
status,
|
|
2241
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2242
|
+
...method !== "" ? { method } : {}
|
|
2243
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2244
|
+
});
|
|
2245
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2246
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2247
|
+
});
|
|
2248
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2249
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2250
|
+
});
|
|
2251
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2252
|
+
const target = event.target;
|
|
2253
|
+
if (!(target instanceof Element))
|
|
2254
|
+
return;
|
|
2255
|
+
const button = target.closest("[data-route]");
|
|
2256
|
+
if (!(button instanceof HTMLElement))
|
|
2257
|
+
return;
|
|
2258
|
+
const route = button.dataset.route;
|
|
2259
|
+
if (route === void 0)
|
|
2260
|
+
return;
|
|
2261
|
+
state.route = route;
|
|
2262
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2263
|
+
const method = route.split(" ")[0] ?? "";
|
|
2264
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2265
|
+
});
|
|
2266
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2267
|
+
event.preventDefault();
|
|
2268
|
+
const send = async () => {
|
|
2269
|
+
if (state.route === null)
|
|
2270
|
+
throw new Error("Choose a route first");
|
|
2271
|
+
const parts = state.route.split(" ");
|
|
2272
|
+
const method = parts[0];
|
|
2273
|
+
const path = parts.slice(1).join(" ");
|
|
2274
|
+
if (method === void 0)
|
|
2275
|
+
throw new Error("Choose a route first");
|
|
2276
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
|
|
2277
|
+
let body;
|
|
2278
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2279
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2280
|
+
try {
|
|
2281
|
+
body = readJson2(routeBody.value);
|
|
2282
|
+
} catch {
|
|
2283
|
+
throw new Error("Body is not JSON");
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
const data = await api(method, concrete, body);
|
|
2287
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2288
|
+
};
|
|
2289
|
+
send().catch(showError);
|
|
2290
|
+
});
|
|
2291
|
+
const decodePanel = (value) => {
|
|
2292
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2293
|
+
return void 0;
|
|
2294
|
+
}
|
|
2295
|
+
const panel = {
|
|
2296
|
+
id: value.id,
|
|
2297
|
+
title: value.title,
|
|
2298
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2299
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2300
|
+
};
|
|
2301
|
+
if (typeof value.script === "string")
|
|
2302
|
+
panel.script = value.script;
|
|
2303
|
+
return panel;
|
|
2304
|
+
};
|
|
2305
|
+
const mountPanels = (panels) => {
|
|
2306
|
+
const nav = el("nav", HTMLElement);
|
|
2307
|
+
const views = el("views", HTMLElement);
|
|
2308
|
+
for (const panel of panels) {
|
|
2309
|
+
const button = document.createElement("button");
|
|
2310
|
+
button.type = "button";
|
|
2311
|
+
button.dataset.view = panel.id;
|
|
2312
|
+
button.textContent = panel.title;
|
|
2313
|
+
nav.append(button);
|
|
2314
|
+
const section = document.createElement("section");
|
|
2315
|
+
section.className = "view";
|
|
2316
|
+
section.id = `view-${panel.id}`;
|
|
2317
|
+
section.hidden = true;
|
|
2318
|
+
const title = document.createElement("h2");
|
|
2319
|
+
title.textContent = panel.title;
|
|
2320
|
+
const lede = document.createElement("p");
|
|
2321
|
+
lede.className = "lede";
|
|
2322
|
+
lede.textContent = panel.description;
|
|
2323
|
+
const body = document.createElement("div");
|
|
2324
|
+
body.className = "panel-body";
|
|
2325
|
+
body.id = `panel-${panel.id}`;
|
|
2326
|
+
body.innerHTML = panel.html;
|
|
2327
|
+
section.append(title, lede, body);
|
|
2328
|
+
views.append(section);
|
|
2329
|
+
if (panel.script === void 0)
|
|
2330
|
+
continue;
|
|
2331
|
+
try {
|
|
2332
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2333
|
+
if (!isPanelScript(compiled))
|
|
2334
|
+
throw new Error("panel script did not compile");
|
|
2335
|
+
compiled(body, panelApi);
|
|
2336
|
+
} catch (error) {
|
|
2337
|
+
const note = document.createElement("p");
|
|
2338
|
+
note.className = "banner show";
|
|
2339
|
+
note.textContent = error instanceof Error ? error.message : String(error);
|
|
2340
|
+
body.append(note);
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
};
|
|
2344
|
+
startAdminBrand({
|
|
2345
|
+
document,
|
|
2346
|
+
$: (id) => document.getElementById(id),
|
|
2347
|
+
params,
|
|
2348
|
+
location: { href: location.href, origin: location.origin },
|
|
2349
|
+
fetch,
|
|
2350
|
+
brandsUrl: config.brandsUrl
|
|
2351
|
+
});
|
|
2352
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2353
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2354
|
+
const decoded = decodePanel(panel);
|
|
2355
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2356
|
+
});
|
|
2357
|
+
mountPanels(panels);
|
|
2358
|
+
return refresh();
|
|
2359
|
+
}).catch(showError);
|
|
2360
|
+
}
|
|
2361
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2362
|
+
var adminClientSource = (config) => {
|
|
2363
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2364
|
+
return `<script>
|
|
2365
|
+
${clientPrelude}
|
|
2366
|
+
bootAdmin(${payload});
|
|
2367
|
+
</script>`;
|
|
2368
|
+
};
|
|
2369
|
+
|
|
2370
|
+
// ../core/dist/surface.js
|
|
2371
|
+
var defineMock = (runtime) => runtime;
|
|
2372
|
+
var STANDARD_ADMIN_ROUTES = [
|
|
2373
|
+
"GET /",
|
|
2374
|
+
"POST /reset",
|
|
2375
|
+
"GET /namespaces",
|
|
2376
|
+
"GET /clock",
|
|
2377
|
+
"POST /clock",
|
|
2378
|
+
"GET /faults",
|
|
2379
|
+
"POST /faults",
|
|
2380
|
+
"DELETE /faults",
|
|
2381
|
+
"POST /snapshots",
|
|
2382
|
+
"POST /snapshots/:id/restore",
|
|
2383
|
+
"DELETE /snapshots/:id",
|
|
2384
|
+
"GET /timeline",
|
|
2385
|
+
"POST /checkpoints",
|
|
2386
|
+
"POST /branches/:name",
|
|
2387
|
+
"POST /branches/:name/checkout",
|
|
2388
|
+
"GET /requests",
|
|
2389
|
+
"DELETE /requests",
|
|
2390
|
+
"GET /metrics",
|
|
2391
|
+
"DELETE /metrics",
|
|
2392
|
+
"GET /credentials",
|
|
2393
|
+
"PUT /credentials",
|
|
2394
|
+
"DELETE /credentials",
|
|
2395
|
+
"GET /state",
|
|
2396
|
+
"GET /state/:collection",
|
|
2397
|
+
"GET /state/:collection/:id",
|
|
2398
|
+
"POST /state/:collection",
|
|
2399
|
+
"PUT /state/:collection/:id",
|
|
2400
|
+
"PATCH /state/:collection/:id",
|
|
2401
|
+
"DELETE /state/:collection/:id",
|
|
2402
|
+
"GET /ui",
|
|
2403
|
+
"GET /ui/",
|
|
2404
|
+
"GET /ui/manifest"
|
|
2405
|
+
];
|
|
2406
|
+
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2407
|
+
var assertAdminUi = (ui) => {
|
|
2408
|
+
if (!ui?.panels)
|
|
2409
|
+
return;
|
|
2410
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2411
|
+
for (const panel of ui.panels) {
|
|
2412
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2413
|
+
throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2414
|
+
}
|
|
2415
|
+
if (seen.has(panel.id))
|
|
2416
|
+
throw new RangeError(`duplicate admin panel id ${panel.id}`);
|
|
2417
|
+
seen.add(panel.id);
|
|
2418
|
+
if (panel.title.trim() === "")
|
|
2419
|
+
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
|
|
2423
|
+
// ../core/dist/admin-ui.js
|
|
2424
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
2425
|
+
switch (char) {
|
|
2426
|
+
case "&":
|
|
2427
|
+
return "&";
|
|
2428
|
+
case "<":
|
|
2429
|
+
return "<";
|
|
2430
|
+
case ">":
|
|
2431
|
+
return ">";
|
|
2432
|
+
case '"':
|
|
2433
|
+
return """;
|
|
2434
|
+
default:
|
|
2435
|
+
return "'";
|
|
2436
|
+
}
|
|
2437
|
+
});
|
|
2438
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
2439
|
+
var renderAdminDocument = (service) => {
|
|
2440
|
+
const name = escapeHtml(service);
|
|
2441
|
+
const script = adminClientSource({
|
|
2442
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2443
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2444
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2445
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2446
|
+
service
|
|
2447
|
+
});
|
|
2448
|
+
return `<!DOCTYPE html>
|
|
2449
|
+
<html lang="en">
|
|
2450
|
+
<head>
|
|
2451
|
+
<meta charset="utf-8">
|
|
2452
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2453
|
+
<meta name="color-scheme" content="light dark">
|
|
2454
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='2' fill='%2327272a'/%3E%3C/svg%3E">
|
|
2455
|
+
<title>${name} admin</title>
|
|
2456
|
+
<style>
|
|
2457
|
+
${CSS_RESET}
|
|
2458
|
+
:root {
|
|
2459
|
+
color-scheme: light;
|
|
2460
|
+
--bg: #fafafa;
|
|
2461
|
+
--bg-elev: #ffffff;
|
|
2462
|
+
--bg-muted: #f4f4f5;
|
|
2463
|
+
--bg-inset: #f4f4f5;
|
|
2464
|
+
--line: #dedee3;
|
|
2465
|
+
--line-strong: #c4c4cc;
|
|
2466
|
+
--ink: #18181b;
|
|
2467
|
+
--muted: #62626b;
|
|
2468
|
+
--faint: #71717a;
|
|
2469
|
+
--accent: #27272a;
|
|
2470
|
+
--accent-ink: #ffffff;
|
|
2471
|
+
--accent-soft: #f4f4f5;
|
|
2472
|
+
--ok: #166534;
|
|
2473
|
+
--ok-soft: #f0fdf4;
|
|
2474
|
+
--warn: #a16207;
|
|
2475
|
+
--warn-soft: #fefce8;
|
|
2476
|
+
--err: #a82d32;
|
|
2477
|
+
--err-soft: #fef2f2;
|
|
2478
|
+
--shadow: none;
|
|
2479
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2480
|
+
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
2481
|
+
--radius: 10px;
|
|
2482
|
+
--header: 56px;
|
|
2483
|
+
--nav: 200px;
|
|
2484
|
+
}
|
|
2485
|
+
:root[data-theme="dark"] {
|
|
2486
|
+
color-scheme: dark;
|
|
2487
|
+
--bg: #111113;
|
|
2488
|
+
--bg-elev: #19191c;
|
|
2489
|
+
--bg-muted: #242428;
|
|
2490
|
+
--bg-inset: #111113;
|
|
2491
|
+
--line: #36363c;
|
|
2492
|
+
--line-strong: #52525b;
|
|
2493
|
+
--ink: #f4f4f5;
|
|
2494
|
+
--muted: #a9a9b2;
|
|
2495
|
+
--faint: #71717a;
|
|
2496
|
+
--accent: #e4e4e7;
|
|
2497
|
+
--accent-ink: #18181b;
|
|
2498
|
+
--accent-soft: #242428;
|
|
2499
|
+
--ok: #86efac;
|
|
2500
|
+
--ok-soft: #14241b;
|
|
2501
|
+
--warn: #fde68a;
|
|
2502
|
+
--warn-soft: #2a2410;
|
|
2503
|
+
--err: #ffaaaa;
|
|
2504
|
+
--err-soft: #2c1516;
|
|
2505
|
+
--shadow: none;
|
|
2506
|
+
}
|
|
2507
|
+
@media (prefers-color-scheme: dark) {
|
|
2508
|
+
:root:not([data-theme="light"]) {
|
|
2509
|
+
color-scheme: dark;
|
|
2510
|
+
--bg: #111113;
|
|
2511
|
+
--bg-elev: #19191c;
|
|
2512
|
+
--bg-muted: #242428;
|
|
2513
|
+
--bg-inset: #111113;
|
|
2514
|
+
--line: #36363c;
|
|
2515
|
+
--line-strong: #52525b;
|
|
2516
|
+
--ink: #f4f4f5;
|
|
2517
|
+
--muted: #a9a9b2;
|
|
2518
|
+
--faint: #71717a;
|
|
2519
|
+
--accent: #e4e4e7;
|
|
2520
|
+
--accent-ink: #18181b;
|
|
2521
|
+
--accent-soft: #242428;
|
|
2522
|
+
--ok: #86efac;
|
|
2523
|
+
--ok-soft: #14241b;
|
|
2524
|
+
--warn: #fde68a;
|
|
2525
|
+
--warn-soft: #2a2410;
|
|
2526
|
+
--err: #ffaaaa;
|
|
2527
|
+
--err-soft: #2c1516;
|
|
2528
|
+
--shadow: none;
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2532
|
+
html { height: 100%; }
|
|
2533
|
+
body {
|
|
2534
|
+
margin: 0;
|
|
2535
|
+
min-height: 100%;
|
|
2536
|
+
display: flex;
|
|
2537
|
+
flex-direction: column;
|
|
2538
|
+
font-family: var(--sans);
|
|
2539
|
+
background: var(--bg);
|
|
2540
|
+
color: var(--ink);
|
|
2541
|
+
line-height: 1.45;
|
|
2542
|
+
padding-left: env(safe-area-inset-left);
|
|
2543
|
+
padding-right: env(safe-area-inset-right);
|
|
2544
|
+
-webkit-text-size-adjust: 100%;
|
|
2545
|
+
}
|
|
2546
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
2547
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
2548
|
+
header.top {
|
|
2549
|
+
position: sticky; top: 0; z-index: 5;
|
|
2550
|
+
display: flex; align-items: center; gap: 12px;
|
|
2551
|
+
min-height: var(--header); padding: 10px 16px;
|
|
2552
|
+
background: var(--bg-elev);
|
|
2553
|
+
border-bottom: 1px solid var(--line);
|
|
2554
|
+
min-width: 0; max-width: 100%;
|
|
2555
|
+
}
|
|
2556
|
+
.brand {
|
|
2557
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2558
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2559
|
+
}
|
|
2560
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2561
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2562
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2563
|
+
.vendor {
|
|
2564
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2565
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2566
|
+
}
|
|
2567
|
+
.vendor[hidden] { display: none; }
|
|
2568
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2569
|
+
.vendor img {
|
|
2570
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2571
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2572
|
+
}
|
|
2573
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2574
|
+
.vendor-sep { color: var(--faint); }
|
|
2575
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2576
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
2577
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
2578
|
+
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
2579
|
+
label.field input, label.field select, .controls input[type="password"] {
|
|
2580
|
+
background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
|
|
2581
|
+
padding: 7px 8px; min-height: 36px;
|
|
2582
|
+
}
|
|
2583
|
+
.icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
|
|
2584
|
+
border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
|
|
2585
|
+
background: var(--bg-elev);
|
|
2586
|
+
}
|
|
2587
|
+
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
|
|
2588
|
+
.btn-quiet { background: transparent; }
|
|
2589
|
+
.btn-danger { color: var(--err); }
|
|
2590
|
+
/* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
|
|
2591
|
+
record or the full nav row would widen the page past the viewport. */
|
|
2592
|
+
.layout {
|
|
2593
|
+
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
2594
|
+
flex: 1 0 auto; min-width: 0;
|
|
2595
|
+
}
|
|
2596
|
+
nav.side {
|
|
2597
|
+
border-right: 1px solid var(--line); padding: 12px;
|
|
2598
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2599
|
+
background: var(--bg-elev);
|
|
2600
|
+
}
|
|
2601
|
+
nav.side button {
|
|
2602
|
+
text-align: left; border: 0; background: transparent; border-radius: 9px;
|
|
2603
|
+
padding: 9px 10px; min-height: 40px; color: var(--muted);
|
|
2604
|
+
}
|
|
2605
|
+
nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
|
2606
|
+
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
2607
|
+
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
2608
|
+
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
2609
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2610
|
+
.card {
|
|
2611
|
+
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
2612
|
+
padding: 14px 16px; box-shadow: var(--shadow);
|
|
2613
|
+
}
|
|
2614
|
+
.card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
2615
|
+
.card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
2616
|
+
.card .v .clock-time { font-size: 14px; color: var(--muted); }
|
|
2617
|
+
.split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
|
|
2618
|
+
.collection {
|
|
2619
|
+
width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
|
|
2620
|
+
border-radius: 10px; padding: 8px 10px; min-height: 44px;
|
|
2621
|
+
}
|
|
2622
|
+
.collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
|
|
2623
|
+
.collection small { display: block; color: var(--faint); }
|
|
2624
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
|
|
2625
|
+
.chip {
|
|
2626
|
+
font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
|
|
2627
|
+
border-radius: 999px; padding: 4px 8px;
|
|
2628
|
+
}
|
|
2629
|
+
.chip i { color: var(--faint); font-style: normal; }
|
|
2630
|
+
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2631
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2632
|
+
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
2633
|
+
tr.clickable { cursor: pointer; }
|
|
2634
|
+
tr.clickable:hover { background: var(--bg-muted); }
|
|
2635
|
+
pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
2636
|
+
pre {
|
|
2637
|
+
margin: 0; white-space: pre-wrap; word-break: break-word;
|
|
2638
|
+
background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
|
|
2639
|
+
}
|
|
2640
|
+
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
|
|
2641
|
+
.banner {
|
|
2642
|
+
display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
|
|
2643
|
+
background: var(--err-soft); color: var(--err);
|
|
2644
|
+
}
|
|
2645
|
+
.banner.show { display: block; }
|
|
2646
|
+
.empty { color: var(--muted); padding: 24px 8px; }
|
|
2647
|
+
dialog {
|
|
2648
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2649
|
+
color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
|
|
2650
|
+
}
|
|
2651
|
+
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
2652
|
+
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
2653
|
+
textarea {
|
|
2654
|
+
width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
|
|
2655
|
+
border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
|
|
2656
|
+
font-family: var(--mono); font-size: 12px;
|
|
2657
|
+
}
|
|
2658
|
+
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
2659
|
+
.badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
|
|
2660
|
+
.badge.ok { background: var(--ok-soft); color: var(--ok); }
|
|
2661
|
+
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
|
2662
|
+
.status-2 { color: var(--ok); }
|
|
2663
|
+
.status-4, .status-5, .status-0 { color: var(--err); }
|
|
2664
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
2665
|
+
.route {
|
|
2666
|
+
display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
|
|
2667
|
+
padding: 8px 0; border-bottom: 1px solid var(--line);
|
|
2668
|
+
}
|
|
2669
|
+
.method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
|
|
2670
|
+
@media (max-width: 800px) {
|
|
2671
|
+
header.top {
|
|
2672
|
+
align-items: stretch; flex-direction: column;
|
|
2673
|
+
padding-top: max(10px, env(safe-area-inset-top));
|
|
2674
|
+
}
|
|
2675
|
+
input, select, textarea { font-size: 16px; }
|
|
2676
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
2677
|
+
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
2678
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
2679
|
+
nav.side {
|
|
2680
|
+
flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
|
|
2681
|
+
border-right: 0; border-bottom: 1px solid var(--line);
|
|
2682
|
+
padding: 8px;
|
|
2683
|
+
}
|
|
2684
|
+
nav.side button { white-space: nowrap; flex: none; }
|
|
2685
|
+
.split { grid-template-columns: minmax(0, 1fr); }
|
|
2686
|
+
main { padding: 14px; }
|
|
2687
|
+
table, thead, tbody, tr, th, td { display: block; }
|
|
2688
|
+
thead { display: none; }
|
|
2689
|
+
tr {
|
|
2690
|
+
border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
|
|
2691
|
+
background: var(--bg-elev); min-width: 0;
|
|
2692
|
+
}
|
|
2693
|
+
td {
|
|
2694
|
+
border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
|
|
2695
|
+
min-width: 0; overflow-wrap: anywhere;
|
|
2696
|
+
}
|
|
2697
|
+
td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
|
|
2698
|
+
.route { grid-template-columns: 72px 1fr; }
|
|
2699
|
+
.route button { grid-column: 1 / -1; }
|
|
2700
|
+
}
|
|
2701
|
+
</style>
|
|
2702
|
+
</head>
|
|
2703
|
+
<body>
|
|
2704
|
+
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
2705
|
+
<header class="top">
|
|
2706
|
+
<div class="brand">
|
|
2707
|
+
<div class="brand-id">
|
|
2708
|
+
<strong>${name}</strong>
|
|
2709
|
+
<span>Admin</span>
|
|
2710
|
+
</div>
|
|
2711
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
2712
|
+
</div>
|
|
2713
|
+
<div class="controls">
|
|
2714
|
+
<label class="field">Namespace
|
|
2715
|
+
<select id="namespace" aria-label="Namespace"></select>
|
|
2716
|
+
</label>
|
|
2717
|
+
<label class="field">Admin key
|
|
2718
|
+
<input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
|
|
2719
|
+
</label>
|
|
2720
|
+
<button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
|
|
2721
|
+
<button class="btn" id="refresh" type="button">Refresh</button>
|
|
2722
|
+
</div>
|
|
2723
|
+
</header>
|
|
2724
|
+
<div class="layout">
|
|
2725
|
+
<nav class="side" id="nav" aria-label="Admin sections">
|
|
2726
|
+
<button type="button" data-view="overview" aria-current="true">Overview</button>
|
|
2727
|
+
<button type="button" data-view="state">State</button>
|
|
2728
|
+
<button type="button" data-view="clock">Clock</button>
|
|
2729
|
+
<button type="button" data-view="faults">Faults</button>
|
|
2730
|
+
<button type="button" data-view="journal">Journal</button>
|
|
2731
|
+
<button type="button" data-view="routes">Routes</button>
|
|
2732
|
+
</nav>
|
|
2733
|
+
<main id="views">
|
|
2734
|
+
<p class="banner" id="banner" role="alert"></p>
|
|
2735
|
+
<section class="view" id="view-overview">
|
|
2736
|
+
<h2>Overview</h2>
|
|
2737
|
+
<p class="lede">Health, clock, and the collections this namespace is holding.</p>
|
|
2738
|
+
<div class="grid" id="overview-cards"></div>
|
|
2739
|
+
<h3>Recent requests</h3>
|
|
2740
|
+
<div id="overview-requests"></div>
|
|
2741
|
+
</section>
|
|
2742
|
+
<section class="view" id="view-state" hidden>
|
|
2743
|
+
<h2>State</h2>
|
|
2744
|
+
<p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
|
|
2745
|
+
<div class="split">
|
|
2746
|
+
<div id="collections"></div>
|
|
2747
|
+
<div>
|
|
2748
|
+
<div id="schema"></div>
|
|
2749
|
+
<div class="row-actions">
|
|
2750
|
+
<button class="btn-primary" id="new-record" type="button">New record</button>
|
|
2751
|
+
</div>
|
|
2752
|
+
<div id="records"></div>
|
|
2753
|
+
</div>
|
|
2754
|
+
</div>
|
|
2755
|
+
</section>
|
|
2756
|
+
<section class="view" id="view-clock" hidden>
|
|
2757
|
+
<h2>Clock</h2>
|
|
2758
|
+
<p class="lede">The clock every timestamp in this mock reads.</p>
|
|
2759
|
+
<div class="card" id="clock-readout"></div>
|
|
2760
|
+
<div class="row-actions">
|
|
2761
|
+
<button class="btn" type="button" data-advance="60000">+1m</button>
|
|
2762
|
+
<button class="btn" type="button" data-advance="900000">+15m</button>
|
|
2763
|
+
<button class="btn" type="button" data-advance="3600000">+1h</button>
|
|
2764
|
+
<button class="btn" type="button" data-advance="86400000">+1d</button>
|
|
2765
|
+
<button class="btn" type="button" data-advance="-3600000">\u22121h</button>
|
|
2766
|
+
<button class="btn" id="freeze" type="button">Freeze</button>
|
|
2767
|
+
<button class="btn-quiet" id="clock-reset" type="button">Reset</button>
|
|
2768
|
+
</div>
|
|
2769
|
+
<form id="clock-set" class="row-actions">
|
|
2770
|
+
<label class="field">Set instant
|
|
2771
|
+
<input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
|
|
2772
|
+
</label>
|
|
2773
|
+
<button class="btn-primary" type="submit">Set</button>
|
|
2774
|
+
</form>
|
|
2775
|
+
</section>
|
|
2776
|
+
<section class="view" id="view-faults" hidden>
|
|
2777
|
+
<h2>Faults</h2>
|
|
2778
|
+
<p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
|
|
2779
|
+
<form id="fault-form" class="card stack">
|
|
2780
|
+
<label class="field">Preset
|
|
2781
|
+
<select id="fault-preset"><option value="">Custom rule</option></select>
|
|
2782
|
+
</label>
|
|
2783
|
+
<label class="field">Status
|
|
2784
|
+
<input id="fault-status" inputmode="numeric" placeholder="503">
|
|
2785
|
+
</label>
|
|
2786
|
+
<label class="field">Path prefix
|
|
2787
|
+
<input id="fault-path" placeholder="/v1">
|
|
2788
|
+
</label>
|
|
2789
|
+
<label class="field">Method
|
|
2790
|
+
<input id="fault-method" placeholder="GET">
|
|
2791
|
+
</label>
|
|
2792
|
+
<div class="dialog-actions">
|
|
2793
|
+
<button class="btn-primary" type="submit">Add fault</button>
|
|
2794
|
+
<button class="btn-danger" id="fault-clear" type="button">Clear all</button>
|
|
2795
|
+
</div>
|
|
2796
|
+
</form>
|
|
2797
|
+
<div id="fault-list"></div>
|
|
2798
|
+
</section>
|
|
2799
|
+
<section class="view" id="view-journal" hidden>
|
|
2800
|
+
<h2>Journal</h2>
|
|
2801
|
+
<p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
|
|
2802
|
+
<div class="row-actions">
|
|
2803
|
+
<button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
|
|
2804
|
+
</div>
|
|
2805
|
+
<div id="journal"></div>
|
|
2806
|
+
</section>
|
|
2807
|
+
<section class="view" id="view-routes" hidden>
|
|
2808
|
+
<h2>Routes</h2>
|
|
2809
|
+
<p class="lede">Shared controls, plus any routes this mock adds. Extra routes are how a bespoke workflow shows up beside the default UI.</p>
|
|
2810
|
+
<div id="route-list"></div>
|
|
2811
|
+
<form id="route-form" class="card stack">
|
|
2812
|
+
<strong id="route-title">Select a route</strong>
|
|
2813
|
+
<label class="field">JSON body
|
|
2814
|
+
<textarea id="route-body" placeholder="{ }"></textarea>
|
|
2815
|
+
</label>
|
|
2816
|
+
<div class="dialog-actions">
|
|
2817
|
+
<button class="btn-primary" type="submit">Send</button>
|
|
2818
|
+
</div>
|
|
2819
|
+
<pre id="route-result">Response will show here.</pre>
|
|
2820
|
+
</form>
|
|
2821
|
+
</section>
|
|
2822
|
+
</main>
|
|
2823
|
+
</div>
|
|
2824
|
+
</div>
|
|
2825
|
+
<dialog id="editor">
|
|
2826
|
+
<form method="dialog" id="editor-form">
|
|
2827
|
+
<strong id="editor-title">Record</strong>
|
|
2828
|
+
<label class="field">Id
|
|
2829
|
+
<input id="editor-id" required>
|
|
2830
|
+
</label>
|
|
2831
|
+
<label class="field">JSON value
|
|
2832
|
+
<textarea id="editor-value"></textarea>
|
|
2833
|
+
</label>
|
|
2834
|
+
<div class="dialog-actions">
|
|
2835
|
+
<button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
|
|
2836
|
+
<button class="btn-quiet" type="submit" value="cancel">Cancel</button>
|
|
2837
|
+
<button class="btn-primary" type="submit" value="save">Save</button>
|
|
2838
|
+
</div>
|
|
2839
|
+
</form>
|
|
2840
|
+
</dialog>
|
|
2841
|
+
${script}
|
|
2842
|
+
</body>
|
|
2843
|
+
</html>`;
|
|
2844
|
+
};
|
|
2845
|
+
var htmlResponse = (body) => new Response(body, {
|
|
2846
|
+
status: 200,
|
|
2847
|
+
headers: {
|
|
2848
|
+
"content-type": "text/html; charset=utf-8",
|
|
2849
|
+
"cache-control": "no-store"
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
var json2 = (body) => new Response(JSON.stringify(body), {
|
|
2853
|
+
status: 200,
|
|
2854
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
2855
|
+
});
|
|
2856
|
+
var adminUiRoutes = (service, ui) => {
|
|
2857
|
+
const shell = () => renderAdminDocument(service);
|
|
2858
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
2859
|
+
return {
|
|
2860
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
2861
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
2862
|
+
"GET /ui/manifest": () => json2({
|
|
2863
|
+
service,
|
|
2864
|
+
panels: (ui?.panels ?? []).map((panel) => ({
|
|
2865
|
+
id: panel.id,
|
|
2866
|
+
title: panel.title,
|
|
2867
|
+
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
2868
|
+
html: panel.html,
|
|
2869
|
+
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
2870
|
+
}))
|
|
2871
|
+
})
|
|
2872
|
+
};
|
|
2873
|
+
};
|
|
2874
|
+
|
|
1142
2875
|
// ../../openapi/metadata/dist/types.js
|
|
1143
2876
|
var EXTENSION_KEYS = {
|
|
1144
2877
|
operation: "x-mockingbird",
|
|
@@ -1151,11 +2884,11 @@ var EXTENSION_KEYS = {
|
|
|
1151
2884
|
};
|
|
1152
2885
|
|
|
1153
2886
|
// ../../openapi/metadata/dist/read.js
|
|
1154
|
-
var
|
|
2887
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1155
2888
|
var extensionOf = (holder, key) => holder[key];
|
|
1156
2889
|
var operationMetadata = (operation) => {
|
|
1157
2890
|
const raw = extensionOf(operation, EXTENSION_KEYS.operation);
|
|
1158
|
-
const ext =
|
|
2891
|
+
const ext = isRecord3(raw) ? raw : {};
|
|
1159
2892
|
const supported = ext.supported ?? true;
|
|
1160
2893
|
const parity = ext.parity ?? {};
|
|
1161
2894
|
return {
|
|
@@ -1191,9 +2924,9 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
1191
2924
|
this.name = "OperationRegistryError";
|
|
1192
2925
|
}
|
|
1193
2926
|
};
|
|
1194
|
-
var verifyOperations = (
|
|
2927
|
+
var verifyOperations = (document3, handlers) => {
|
|
1195
2928
|
const problems = [];
|
|
1196
|
-
const operations = listOperations(
|
|
2929
|
+
const operations = listOperations(document3);
|
|
1197
2930
|
const seen = /* @__PURE__ */ new Set();
|
|
1198
2931
|
for (const operation of operations) {
|
|
1199
2932
|
if (seen.has(operation.operationId))
|
|
@@ -1302,15 +3035,449 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
|
|
|
1302
3035
|
});
|
|
1303
3036
|
};
|
|
1304
3037
|
|
|
3038
|
+
// ../core/dist/state-view.js
|
|
3039
|
+
var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
|
|
3040
|
+
var RECORD_ID = /^[^\s/]{1,256}$/;
|
|
3041
|
+
var SAMPLE = 25;
|
|
3042
|
+
var WALK_LIMIT = 1e4;
|
|
3043
|
+
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
3044
|
+
var fail2 = (status, message) => ({ ok: false, status, message });
|
|
3045
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3046
|
+
var kindOf = (value) => {
|
|
3047
|
+
if (value === null)
|
|
3048
|
+
return "null";
|
|
3049
|
+
if (Array.isArray(value))
|
|
3050
|
+
return "array";
|
|
3051
|
+
switch (typeof value) {
|
|
3052
|
+
case "string":
|
|
3053
|
+
return "string";
|
|
3054
|
+
case "number":
|
|
3055
|
+
return Number.isFinite(value) ? "number" : "unknown";
|
|
3056
|
+
case "boolean":
|
|
3057
|
+
return "boolean";
|
|
3058
|
+
case "object":
|
|
3059
|
+
return "object";
|
|
3060
|
+
default:
|
|
3061
|
+
return "unknown";
|
|
3062
|
+
}
|
|
3063
|
+
};
|
|
3064
|
+
var humanize = (name) => {
|
|
3065
|
+
const words = name.replace(/[@:_-]+/g, " ").trim();
|
|
3066
|
+
if (words === "")
|
|
3067
|
+
return name;
|
|
3068
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3069
|
+
};
|
|
3070
|
+
var jsonValue = (value) => {
|
|
3071
|
+
if (value === void 0)
|
|
3072
|
+
return fail2(400, "value is required");
|
|
3073
|
+
try {
|
|
3074
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
3075
|
+
} catch {
|
|
3076
|
+
return fail2(400, "value must be JSON");
|
|
3077
|
+
}
|
|
3078
|
+
};
|
|
3079
|
+
var ctorName = (value) => {
|
|
3080
|
+
const ctor = value.constructor;
|
|
3081
|
+
return typeof ctor?.name === "string" ? ctor.name : "";
|
|
3082
|
+
};
|
|
3083
|
+
var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
|
|
3084
|
+
var discoverCollections = (root) => {
|
|
3085
|
+
const found = [];
|
|
3086
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3087
|
+
const visit = (value, depth) => {
|
|
3088
|
+
if (found.length + seen.size > WALK_LIMIT)
|
|
3089
|
+
return;
|
|
3090
|
+
if (value === null || typeof value !== "object")
|
|
3091
|
+
return;
|
|
3092
|
+
if (seen.has(value))
|
|
3093
|
+
return;
|
|
3094
|
+
seen.add(value);
|
|
3095
|
+
if (value instanceof Collection) {
|
|
3096
|
+
found.push(value);
|
|
3097
|
+
return;
|
|
3098
|
+
}
|
|
3099
|
+
if (value instanceof Map) {
|
|
3100
|
+
for (const child of value.values())
|
|
3101
|
+
visit(child, depth + 1);
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3104
|
+
if (value instanceof Set) {
|
|
3105
|
+
for (const child of value.values())
|
|
3106
|
+
visit(child, depth + 1);
|
|
3107
|
+
return;
|
|
3108
|
+
}
|
|
3109
|
+
if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
|
|
3110
|
+
return;
|
|
3111
|
+
if (Array.isArray(value)) {
|
|
3112
|
+
const cap = Math.min(value.length, 32);
|
|
3113
|
+
for (let i = 0; i < cap; i++)
|
|
3114
|
+
visit(value[i], depth + 1);
|
|
3115
|
+
return;
|
|
3116
|
+
}
|
|
3117
|
+
let children;
|
|
3118
|
+
try {
|
|
3119
|
+
children = Object.values(value);
|
|
3120
|
+
} catch {
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
for (const child of children)
|
|
3124
|
+
visit(child, depth + 1);
|
|
3125
|
+
};
|
|
3126
|
+
visit(root, 0);
|
|
3127
|
+
return found;
|
|
3128
|
+
};
|
|
3129
|
+
var storedNames = (sqlite, namespace) => {
|
|
3130
|
+
const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
|
|
3131
|
+
const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
|
|
3132
|
+
return [...records, ...sequences].map((row) => row.name);
|
|
3133
|
+
};
|
|
3134
|
+
var blankAccum = (name) => ({
|
|
3135
|
+
name,
|
|
3136
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
3137
|
+
present: 0,
|
|
3138
|
+
nested: /* @__PURE__ */ new Map()
|
|
3139
|
+
});
|
|
3140
|
+
var absorb = (accum, value) => {
|
|
3141
|
+
const kind = kindOf(value);
|
|
3142
|
+
accum.kinds.add(kind);
|
|
3143
|
+
accum.present++;
|
|
3144
|
+
if (!isRecord4(value))
|
|
3145
|
+
return;
|
|
3146
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3147
|
+
const nested = accum.nested.get(key) ?? blankAccum(key);
|
|
3148
|
+
absorb(nested, child);
|
|
3149
|
+
accum.nested.set(key, nested);
|
|
3150
|
+
}
|
|
3151
|
+
};
|
|
3152
|
+
var finishField = (accum, samples) => {
|
|
3153
|
+
const kinds = [...accum.kinds];
|
|
3154
|
+
const kind = kinds.length === 1 ? kinds[0] : "unknown";
|
|
3155
|
+
const field = {
|
|
3156
|
+
name: accum.name,
|
|
3157
|
+
kind,
|
|
3158
|
+
optional: accum.present < samples || kinds.includes("null")
|
|
3159
|
+
};
|
|
3160
|
+
if (accum.nested.size > 0) {
|
|
3161
|
+
field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
|
|
3162
|
+
}
|
|
3163
|
+
return field;
|
|
3164
|
+
};
|
|
3165
|
+
var inferFields = (records) => {
|
|
3166
|
+
if (records.length === 0)
|
|
3167
|
+
return [];
|
|
3168
|
+
const sample = records.slice(0, SAMPLE);
|
|
3169
|
+
const objects = sample.filter((record) => isRecord4(record.value));
|
|
3170
|
+
if (objects.length === 0) {
|
|
3171
|
+
const kinds = new Set(sample.map((record) => kindOf(record.value)));
|
|
3172
|
+
const list = [...kinds];
|
|
3173
|
+
return [
|
|
3174
|
+
{
|
|
3175
|
+
name: "(value)",
|
|
3176
|
+
kind: list.length === 1 ? list[0] : "unknown",
|
|
3177
|
+
optional: false
|
|
3178
|
+
}
|
|
3179
|
+
];
|
|
3180
|
+
}
|
|
3181
|
+
const root = /* @__PURE__ */ new Map();
|
|
3182
|
+
for (const record of objects) {
|
|
3183
|
+
for (const [key, value] of Object.entries(record.value)) {
|
|
3184
|
+
const accum = root.get(key) ?? blankAccum(key);
|
|
3185
|
+
absorb(accum, value);
|
|
3186
|
+
root.set(key, accum);
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
|
|
3190
|
+
};
|
|
3191
|
+
var mergeFields = (declared, inferred) => {
|
|
3192
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3193
|
+
for (const field of inferred)
|
|
3194
|
+
byName.set(field.name, field);
|
|
3195
|
+
const ordered = [];
|
|
3196
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3197
|
+
for (const field of declared ?? []) {
|
|
3198
|
+
const found = byName.get(field.name);
|
|
3199
|
+
seen.add(field.name);
|
|
3200
|
+
if (!found) {
|
|
3201
|
+
ordered.push({ ...field, optional: field.optional });
|
|
3202
|
+
continue;
|
|
3203
|
+
}
|
|
3204
|
+
ordered.push({
|
|
3205
|
+
...found,
|
|
3206
|
+
kind: field.kind === "unknown" ? found.kind : field.kind,
|
|
3207
|
+
optional: field.optional || found.optional,
|
|
3208
|
+
...field.description !== void 0 ? { description: field.description } : {},
|
|
3209
|
+
...field.meta !== void 0 ? { meta: field.meta } : {},
|
|
3210
|
+
...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
|
|
3211
|
+
});
|
|
3212
|
+
}
|
|
3213
|
+
for (const field of inferred) {
|
|
3214
|
+
if (!seen.has(field.name))
|
|
3215
|
+
ordered.push(field);
|
|
3216
|
+
}
|
|
3217
|
+
return ordered;
|
|
3218
|
+
};
|
|
3219
|
+
var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
|
|
3220
|
+
var readRecord = (collection, id) => {
|
|
3221
|
+
const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
|
|
3222
|
+
const row = rows.find((entry) => entry.id === id);
|
|
3223
|
+
return row ? { id: row.id, seq: row.seq, value: row.value } : void 0;
|
|
3224
|
+
};
|
|
3225
|
+
var inspectState = (scope) => {
|
|
3226
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3227
|
+
for (const declaration of scope.declarations ?? []) {
|
|
3228
|
+
if (COLLECTION_NAME.test(declaration.name))
|
|
3229
|
+
declared.set(declaration.name, declaration);
|
|
3230
|
+
}
|
|
3231
|
+
const names = new Set(declared.keys());
|
|
3232
|
+
for (const name of storedNames(scope.sqlite, scope.storageNamespace))
|
|
3233
|
+
names.add(name);
|
|
3234
|
+
for (const collection of discoverCollections(scope.root)) {
|
|
3235
|
+
if (collection.namespace === scope.storageNamespace)
|
|
3236
|
+
names.add(collection.collectionName);
|
|
3237
|
+
}
|
|
3238
|
+
const collections = [];
|
|
3239
|
+
for (const name of names) {
|
|
3240
|
+
if (!COLLECTION_NAME.test(name))
|
|
3241
|
+
continue;
|
|
3242
|
+
const declaration = declared.get(name);
|
|
3243
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3244
|
+
const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row) => ({ id: row.id, seq: row.seq, value: row.value }));
|
|
3245
|
+
const inferred = inferFields(records);
|
|
3246
|
+
const fields = mergeFields(declaration?.fields, inferred);
|
|
3247
|
+
const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
|
|
3248
|
+
collections.push({
|
|
3249
|
+
name,
|
|
3250
|
+
label: declaration?.label ?? humanize(name),
|
|
3251
|
+
...declaration?.description !== void 0 ? { description: declaration.description } : {},
|
|
3252
|
+
count: collection.count(),
|
|
3253
|
+
source,
|
|
3254
|
+
fields,
|
|
3255
|
+
...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
const order = /* @__PURE__ */ new Map();
|
|
3259
|
+
for (const [index, item] of (scope.declarations ?? []).entries())
|
|
3260
|
+
order.set(item.name, index);
|
|
3261
|
+
collections.sort((a, b) => {
|
|
3262
|
+
const left = order.get(a.name);
|
|
3263
|
+
const right = order.get(b.name);
|
|
3264
|
+
if (left !== void 0 && right !== void 0)
|
|
3265
|
+
return left - right;
|
|
3266
|
+
if (left !== void 0)
|
|
3267
|
+
return -1;
|
|
3268
|
+
if (right !== void 0)
|
|
3269
|
+
return 1;
|
|
3270
|
+
return a.name.localeCompare(b.name);
|
|
3271
|
+
});
|
|
3272
|
+
return {
|
|
3273
|
+
namespace: scope.namespace,
|
|
3274
|
+
storageNamespace: scope.storageNamespace,
|
|
3275
|
+
collections
|
|
3276
|
+
};
|
|
3277
|
+
};
|
|
3278
|
+
var pageOf = (sqlite, storageNamespace, name, query) => {
|
|
3279
|
+
if (!COLLECTION_NAME.test(name))
|
|
3280
|
+
return fail2(400, "collection name is not allowed");
|
|
3281
|
+
const limit = query.limit ?? 50;
|
|
3282
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
3283
|
+
return fail2(400, "limit must be an integer from 1 to 200");
|
|
3284
|
+
}
|
|
3285
|
+
const order = query.order ?? "newest";
|
|
3286
|
+
if (order !== "newest" && order !== "oldest")
|
|
3287
|
+
return fail2(400, 'order must be "newest" or "oldest"');
|
|
3288
|
+
const collection = collectionOf(sqlite, storageNamespace, name);
|
|
3289
|
+
const rows = collection.list({ order }).filter((row) => {
|
|
3290
|
+
if (query.after === void 0)
|
|
3291
|
+
return true;
|
|
3292
|
+
return order === "newest" ? row.seq < query.after : row.seq > query.after;
|
|
3293
|
+
});
|
|
3294
|
+
const slice = rows.slice(0, limit);
|
|
3295
|
+
const last = slice.at(-1);
|
|
3296
|
+
return {
|
|
3297
|
+
ok: true,
|
|
3298
|
+
value: {
|
|
3299
|
+
collection: name,
|
|
3300
|
+
count: collection.count(),
|
|
3301
|
+
records: slice.map((row) => ({ id: row.id, seq: row.seq, value: row.value })),
|
|
3302
|
+
next: rows.length > limit && last ? last.seq : null
|
|
3303
|
+
}
|
|
3304
|
+
};
|
|
3305
|
+
};
|
|
3306
|
+
var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
|
|
3307
|
+
var readStateRecord = (scope, name, id) => {
|
|
3308
|
+
if (!COLLECTION_NAME.test(name))
|
|
3309
|
+
return fail2(400, "collection name is not allowed");
|
|
3310
|
+
if (!RECORD_ID.test(id))
|
|
3311
|
+
return fail2(400, "record id is not allowed");
|
|
3312
|
+
const record = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
|
|
3313
|
+
return record ? { ok: true, value: record } : fail2(404, `no record ${id} in ${name}`);
|
|
3314
|
+
};
|
|
3315
|
+
var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail2(400, "id must be a single path segment");
|
|
3316
|
+
var createStateRecord = (scope, name, input) => {
|
|
3317
|
+
if (!COLLECTION_NAME.test(name))
|
|
3318
|
+
return fail2(400, "collection name is not allowed");
|
|
3319
|
+
const parsed = jsonValue(input.value);
|
|
3320
|
+
if (!parsed.ok)
|
|
3321
|
+
return parsed;
|
|
3322
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3323
|
+
const id = input.id ?? `${name}_${collection.nextSequence()}`;
|
|
3324
|
+
const checked = requireId(id);
|
|
3325
|
+
if (!checked.ok)
|
|
3326
|
+
return checked;
|
|
3327
|
+
if (collection.has(checked.value))
|
|
3328
|
+
return fail2(409, `record ${checked.value} already exists`);
|
|
3329
|
+
const stored = collection.insert(checked.value, parsed.value);
|
|
3330
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3331
|
+
};
|
|
3332
|
+
var replaceStateRecord = (scope, name, id, value) => {
|
|
3333
|
+
if (!COLLECTION_NAME.test(name))
|
|
3334
|
+
return fail2(400, "collection name is not allowed");
|
|
3335
|
+
const checked = requireId(id);
|
|
3336
|
+
if (!checked.ok)
|
|
3337
|
+
return checked;
|
|
3338
|
+
const parsed = jsonValue(value);
|
|
3339
|
+
if (!parsed.ok)
|
|
3340
|
+
return parsed;
|
|
3341
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3342
|
+
if (!collection.has(checked.value))
|
|
3343
|
+
return fail2(404, `no record ${checked.value} in ${name}`);
|
|
3344
|
+
const stored = collection.update(checked.value, parsed.value);
|
|
3345
|
+
if (!stored)
|
|
3346
|
+
return fail2(404, `no record ${checked.value} in ${name}`);
|
|
3347
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3348
|
+
};
|
|
3349
|
+
var patchStateRecord = (scope, name, id, value) => {
|
|
3350
|
+
const current = readStateRecord(scope, name, id);
|
|
3351
|
+
if (!current.ok)
|
|
3352
|
+
return current;
|
|
3353
|
+
const parsed = jsonValue(value);
|
|
3354
|
+
if (!parsed.ok)
|
|
3355
|
+
return parsed;
|
|
3356
|
+
const next = isRecord4(current.value.value) && isRecord4(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
3357
|
+
return replaceStateRecord(scope, name, id, next);
|
|
3358
|
+
};
|
|
3359
|
+
var deleteStateRecord = (scope, name, id) => {
|
|
3360
|
+
if (!COLLECTION_NAME.test(name))
|
|
3361
|
+
return fail2(400, "collection name is not allowed");
|
|
3362
|
+
const checked = requireId(id);
|
|
3363
|
+
if (!checked.ok)
|
|
3364
|
+
return checked;
|
|
3365
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3366
|
+
return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail2(404, `no record ${checked.value} in ${name}`);
|
|
3367
|
+
};
|
|
3368
|
+
var json3 = (status, body) => new Response(JSON.stringify(body), {
|
|
3369
|
+
status,
|
|
3370
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3371
|
+
});
|
|
3372
|
+
var adminError2 = (status, message) => json3(status, { error: { type: "mockingbird_admin", message } });
|
|
3373
|
+
var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
|
|
3374
|
+
var integerParam = (value) => {
|
|
3375
|
+
if (value === null)
|
|
3376
|
+
return void 0;
|
|
3377
|
+
if (!/^-?\d+$/.test(value))
|
|
3378
|
+
return "bad";
|
|
3379
|
+
return Number(value);
|
|
3380
|
+
};
|
|
3381
|
+
var stateAdminRoutes = (routes) => {
|
|
3382
|
+
const open = (namespace) => {
|
|
3383
|
+
try {
|
|
3384
|
+
return { ok: true, value: routes.open(namespace) };
|
|
3385
|
+
} catch (error) {
|
|
3386
|
+
return fail2(400, error instanceof Error ? error.message : String(error));
|
|
3387
|
+
}
|
|
3388
|
+
};
|
|
3389
|
+
const wrote = (namespace) => {
|
|
3390
|
+
routes.afterWrite?.(namespace);
|
|
3391
|
+
};
|
|
3392
|
+
return {
|
|
3393
|
+
"GET /state": ({ namespace }) => {
|
|
3394
|
+
const scope = open(namespace);
|
|
3395
|
+
return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
|
|
3396
|
+
},
|
|
3397
|
+
"GET /state/:collection": ({ namespace, params, url }) => {
|
|
3398
|
+
const scope = open(namespace);
|
|
3399
|
+
if (!scope.ok)
|
|
3400
|
+
return fromResult(scope, 200);
|
|
3401
|
+
const limit = integerParam(url.searchParams.get("limit"));
|
|
3402
|
+
const after = integerParam(url.searchParams.get("after"));
|
|
3403
|
+
if (limit === "bad")
|
|
3404
|
+
return adminError2(400, "limit: expected an integer");
|
|
3405
|
+
if (after === "bad")
|
|
3406
|
+
return adminError2(400, "after: expected a sequence number");
|
|
3407
|
+
const order = url.searchParams.get("order");
|
|
3408
|
+
return fromResult(readStatePage(scope.value, params.collection ?? "", {
|
|
3409
|
+
...limit !== void 0 ? { limit } : {},
|
|
3410
|
+
...after !== void 0 ? { after } : {},
|
|
3411
|
+
...order === "newest" || order === "oldest" ? { order } : {}
|
|
3412
|
+
}), 200);
|
|
3413
|
+
},
|
|
3414
|
+
"GET /state/:collection/:id": ({ namespace, params }) => {
|
|
3415
|
+
const scope = open(namespace);
|
|
3416
|
+
if (!scope.ok)
|
|
3417
|
+
return fromResult(scope, 200);
|
|
3418
|
+
return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
|
|
3419
|
+
},
|
|
3420
|
+
"POST /state/:collection": ({ namespace, params, body }) => {
|
|
3421
|
+
const scope = open(namespace);
|
|
3422
|
+
if (!scope.ok)
|
|
3423
|
+
return fromResult(scope, 201);
|
|
3424
|
+
if (!isRecord4(body) || !("value" in body)) {
|
|
3425
|
+
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
3426
|
+
}
|
|
3427
|
+
const id = body.id;
|
|
3428
|
+
if (id !== void 0 && typeof id !== "string")
|
|
3429
|
+
return adminError2(400, "id must be a string");
|
|
3430
|
+
const created = createStateRecord(scope.value, params.collection ?? "", {
|
|
3431
|
+
...typeof id === "string" ? { id } : {},
|
|
3432
|
+
value: body.value
|
|
3433
|
+
});
|
|
3434
|
+
if (created.ok)
|
|
3435
|
+
wrote(namespace);
|
|
3436
|
+
return fromResult(created, 201);
|
|
3437
|
+
},
|
|
3438
|
+
"PUT /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3439
|
+
const scope = open(namespace);
|
|
3440
|
+
if (!scope.ok)
|
|
3441
|
+
return fromResult(scope, 200);
|
|
3442
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3443
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3444
|
+
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3445
|
+
if (replaced.ok)
|
|
3446
|
+
wrote(namespace);
|
|
3447
|
+
return fromResult(replaced, 200);
|
|
3448
|
+
},
|
|
3449
|
+
"PATCH /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3450
|
+
const scope = open(namespace);
|
|
3451
|
+
if (!scope.ok)
|
|
3452
|
+
return fromResult(scope, 200);
|
|
3453
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3454
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3455
|
+
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3456
|
+
if (patched.ok)
|
|
3457
|
+
wrote(namespace);
|
|
3458
|
+
return fromResult(patched, 200);
|
|
3459
|
+
},
|
|
3460
|
+
"DELETE /state/:collection/:id": ({ namespace, params }) => {
|
|
3461
|
+
const scope = open(namespace);
|
|
3462
|
+
if (!scope.ok)
|
|
3463
|
+
return fromResult(scope, 200);
|
|
3464
|
+
const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
|
|
3465
|
+
if (removed.ok)
|
|
3466
|
+
wrote(namespace);
|
|
3467
|
+
return fromResult(removed, 200);
|
|
3468
|
+
}
|
|
3469
|
+
};
|
|
3470
|
+
};
|
|
3471
|
+
|
|
1305
3472
|
// ../core/dist/version.js
|
|
1306
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3473
|
+
var PACKAGE_VERSION = true ? "1.5.0" : UNRELEASED_VERSION;
|
|
1307
3474
|
|
|
1308
3475
|
// ../core/dist/webhooks.js
|
|
1309
|
-
var
|
|
1310
|
-
var
|
|
1311
|
-
var
|
|
3476
|
+
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
3477
|
+
var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
|
|
3478
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1312
3479
|
var parseEndpoint = (value) => {
|
|
1313
|
-
if (!
|
|
3480
|
+
if (!isRecord5(value) || typeof value.url !== "string")
|
|
1314
3481
|
return "each endpoint needs a url";
|
|
1315
3482
|
try {
|
|
1316
3483
|
new URL(value.url);
|
|
@@ -1327,18 +3494,18 @@ var parseEndpoint = (value) => {
|
|
|
1327
3494
|
const events = value.events ?? value.enabledEvents;
|
|
1328
3495
|
if (Array.isArray(events))
|
|
1329
3496
|
endpoint.events = events.map(String);
|
|
1330
|
-
if (
|
|
3497
|
+
if (isRecord5(value.tags)) {
|
|
1331
3498
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
1332
3499
|
}
|
|
1333
3500
|
if (typeof value.account === "string")
|
|
1334
3501
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
1335
|
-
if (
|
|
3502
|
+
if (isRecord5(value.headers)) {
|
|
1336
3503
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
1337
3504
|
}
|
|
1338
3505
|
return endpoint;
|
|
1339
3506
|
};
|
|
1340
3507
|
var webhookAdminRoutes = (hub) => ({
|
|
1341
|
-
"GET /webhooks": ({ url, namespace }) =>
|
|
3508
|
+
"GET /webhooks": ({ url, namespace }) => json4(200, {
|
|
1342
3509
|
deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
|
|
1343
3510
|
const type = url.searchParams.get("type");
|
|
1344
3511
|
return type === null || d.type === type;
|
|
@@ -1346,51 +3513,51 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
1346
3513
|
}),
|
|
1347
3514
|
"GET /webhooks/events": ({ url, namespace }) => {
|
|
1348
3515
|
const type = url.searchParams.get("type");
|
|
1349
|
-
return
|
|
3516
|
+
return json4(200, {
|
|
1350
3517
|
events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
|
|
1351
3518
|
});
|
|
1352
3519
|
},
|
|
1353
3520
|
"POST /webhooks/:id/replay": async ({ params }) => {
|
|
1354
3521
|
const replayed = await hub.replay(params.id);
|
|
1355
|
-
return replayed ?
|
|
3522
|
+
return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
|
|
1356
3523
|
},
|
|
1357
3524
|
"POST /webhooks/flush": async () => {
|
|
1358
3525
|
await hub.flush();
|
|
1359
|
-
return
|
|
3526
|
+
return json4(200, { status: "ok" });
|
|
1360
3527
|
},
|
|
1361
3528
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
1362
|
-
if (!
|
|
1363
|
-
return
|
|
3529
|
+
if (!isRecord5(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
3530
|
+
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
1364
3531
|
}
|
|
1365
3532
|
const fault = { mode: body.mode };
|
|
1366
3533
|
if (typeof body.count === "number")
|
|
1367
3534
|
fault.count = body.count;
|
|
1368
3535
|
hub.fault(namespace, fault);
|
|
1369
|
-
return
|
|
3536
|
+
return json4(201, { namespace, ...fault });
|
|
1370
3537
|
},
|
|
1371
|
-
"GET /webhook-endpoints": ({ namespace }) =>
|
|
3538
|
+
"GET /webhook-endpoints": ({ namespace }) => json4(200, {
|
|
1372
3539
|
endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
|
|
1373
3540
|
...rest,
|
|
1374
3541
|
secret: secret ? "(set)" : null
|
|
1375
3542
|
}))
|
|
1376
3543
|
}),
|
|
1377
3544
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
1378
|
-
const list = Array.isArray(body) ? body :
|
|
3545
|
+
const list = Array.isArray(body) ? body : isRecord5(body) ? body.endpoints : void 0;
|
|
1379
3546
|
if (!Array.isArray(list))
|
|
1380
|
-
return
|
|
3547
|
+
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
1381
3548
|
const parsed = [];
|
|
1382
3549
|
for (const each of list) {
|
|
1383
3550
|
const endpoint = parseEndpoint(each);
|
|
1384
3551
|
if (typeof endpoint === "string")
|
|
1385
|
-
return
|
|
3552
|
+
return adminError3(400, endpoint);
|
|
1386
3553
|
parsed.push(endpoint);
|
|
1387
3554
|
}
|
|
1388
3555
|
const set = hub.setEndpoints(namespace, parsed);
|
|
1389
|
-
return
|
|
3556
|
+
return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
|
|
1390
3557
|
},
|
|
1391
3558
|
"DELETE /webhook-endpoints": ({ namespace }) => {
|
|
1392
3559
|
hub.setEndpoints(namespace, []);
|
|
1393
|
-
return
|
|
3560
|
+
return json4(200, { status: "ok" });
|
|
1394
3561
|
}
|
|
1395
3562
|
});
|
|
1396
3563
|
var parsePayload = (message) => {
|
|
@@ -1445,8 +3612,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
1445
3612
|
this.name = "TypeError";
|
|
1446
3613
|
}
|
|
1447
3614
|
};
|
|
1448
|
-
var operationMatcher = (
|
|
1449
|
-
const matchers = listOperations(
|
|
3615
|
+
var operationMatcher = (document3) => {
|
|
3616
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
1450
3617
|
operationId: operation.operationId,
|
|
1451
3618
|
method: operation.method.toUpperCase(),
|
|
1452
3619
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -1455,6 +3622,7 @@ var operationMatcher = (document2) => {
|
|
|
1455
3622
|
return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
|
|
1456
3623
|
};
|
|
1457
3624
|
var createRuntime = (options) => {
|
|
3625
|
+
assertAdminUi(options.adminUi);
|
|
1458
3626
|
const sqlite = bootSqlite(options.sqlite);
|
|
1459
3627
|
const clock = options.clock ?? createClock();
|
|
1460
3628
|
const rng = createRng(options.seed ?? 0);
|
|
@@ -1540,10 +3708,10 @@ var createRuntime = (options) => {
|
|
|
1540
3708
|
const ensureBranch = (namespace, branch2, at) => {
|
|
1541
3709
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
1542
3710
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
1543
|
-
const
|
|
3711
|
+
const history2 = timeline(namespace);
|
|
1544
3712
|
if (branch2 === "main") {
|
|
1545
3713
|
if (at !== void 0) {
|
|
1546
|
-
const point =
|
|
3714
|
+
const point = history2.checkout("main", at);
|
|
1547
3715
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
1548
3716
|
captured.set(namespace, point.value.snapshot);
|
|
1549
3717
|
rng.setState(point.value.rngState);
|
|
@@ -1556,10 +3724,10 @@ var createRuntime = (options) => {
|
|
|
1556
3724
|
return namespace;
|
|
1557
3725
|
}
|
|
1558
3726
|
const storage = physicalBranch(namespace, branch2);
|
|
1559
|
-
if (!
|
|
3727
|
+
if (!history2.hasBranch(branch2)) {
|
|
1560
3728
|
if (at === void 0)
|
|
1561
|
-
|
|
1562
|
-
const point =
|
|
3729
|
+
history2.commit(capture(namespace));
|
|
3730
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
1563
3731
|
const branchRng = createRng(options.seed ?? 0);
|
|
1564
3732
|
if (point)
|
|
1565
3733
|
branchRng.setState(point.value.rngState);
|
|
@@ -1568,8 +3736,8 @@ var createRuntime = (options) => {
|
|
|
1568
3736
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1569
3737
|
if (point)
|
|
1570
3738
|
captured.set(storage, point.value.snapshot);
|
|
1571
|
-
} else if (at !== void 0 &&
|
|
1572
|
-
const point =
|
|
3739
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
3740
|
+
const point = history2.checkout(branch2, at);
|
|
1573
3741
|
if (!instances.has(storage)) {
|
|
1574
3742
|
const branchRng = createRng(options.seed ?? 0);
|
|
1575
3743
|
branchRng.setState(point.value.rngState);
|
|
@@ -1580,7 +3748,7 @@ var createRuntime = (options) => {
|
|
|
1580
3748
|
captured.set(storage, point.value.snapshot);
|
|
1581
3749
|
} else {
|
|
1582
3750
|
if (!instances.has(storage)) {
|
|
1583
|
-
const point =
|
|
3751
|
+
const point = history2.head(branch2);
|
|
1584
3752
|
const branchRng = createRng(options.seed ?? 0);
|
|
1585
3753
|
if (point)
|
|
1586
3754
|
branchRng.setState(point.value.rngState);
|
|
@@ -1604,8 +3772,8 @@ var createRuntime = (options) => {
|
|
|
1604
3772
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
1605
3773
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
1606
3774
|
const branchName = checkoutOptions.branch ?? "main";
|
|
1607
|
-
const
|
|
1608
|
-
const point =
|
|
3775
|
+
const history2 = timeline(namespace);
|
|
3776
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
1609
3777
|
const storage = ensureBranch(namespace, branchName);
|
|
1610
3778
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1611
3779
|
captured.set(storage, point.value.snapshot);
|
|
@@ -1655,12 +3823,25 @@ var createRuntime = (options) => {
|
|
|
1655
3823
|
instance(name);
|
|
1656
3824
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
1657
3825
|
captured.set(name, from);
|
|
1658
|
-
const
|
|
1659
|
-
if (
|
|
1660
|
-
|
|
3826
|
+
const history2 = timelines.get(name);
|
|
3827
|
+
if (history2)
|
|
3828
|
+
history2.commit(capture(name), { branch: "main" });
|
|
1661
3829
|
else
|
|
1662
3830
|
timeline(name);
|
|
1663
3831
|
};
|
|
3832
|
+
const declarationsFor = (namespace) => {
|
|
3833
|
+
const declared = options.state;
|
|
3834
|
+
if (!declared)
|
|
3835
|
+
return [];
|
|
3836
|
+
return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
|
|
3837
|
+
};
|
|
3838
|
+
const stateScope = (namespace) => ({
|
|
3839
|
+
sqlite,
|
|
3840
|
+
namespace,
|
|
3841
|
+
storageNamespace: storageNamespace(namespace),
|
|
3842
|
+
root: instance(namespace),
|
|
3843
|
+
declarations: declarationsFor(namespace)
|
|
3844
|
+
});
|
|
1664
3845
|
const runtime = {
|
|
1665
3846
|
name: options.name,
|
|
1666
3847
|
sqlite,
|
|
@@ -1699,6 +3880,7 @@ var createRuntime = (options) => {
|
|
|
1699
3880
|
branch,
|
|
1700
3881
|
checkout,
|
|
1701
3882
|
timeline,
|
|
3883
|
+
state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
|
|
1702
3884
|
fetch: async (incoming) => {
|
|
1703
3885
|
let request = incoming;
|
|
1704
3886
|
const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
|
|
@@ -1872,10 +4054,10 @@ var createRuntime = (options) => {
|
|
|
1872
4054
|
},
|
|
1873
4055
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
1874
4056
|
inspect: (name) => {
|
|
1875
|
-
const
|
|
4057
|
+
const history2 = timeline(name);
|
|
1876
4058
|
return {
|
|
1877
|
-
branches:
|
|
1878
|
-
checkpoints:
|
|
4059
|
+
branches: history2.branches(),
|
|
4060
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
1879
4061
|
id,
|
|
1880
4062
|
branch: branchName,
|
|
1881
4063
|
parent,
|
|
@@ -1890,13 +4072,22 @@ var createRuntime = (options) => {
|
|
|
1890
4072
|
} : {},
|
|
1891
4073
|
routes: {
|
|
1892
4074
|
...credentialRoutes(credentials),
|
|
1893
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
1894
4075
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
1895
|
-
...options.admin?.(runtime) ?? {}
|
|
4076
|
+
...options.admin?.(runtime) ?? {},
|
|
4077
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4078
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4079
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
4080
|
+
...stateAdminRoutes({
|
|
4081
|
+
open: stateScope,
|
|
4082
|
+
afterWrite: (namespace) => {
|
|
4083
|
+
checkpoint(namespace, "main");
|
|
4084
|
+
}
|
|
4085
|
+
}),
|
|
4086
|
+
...adminUiRoutes(options.name, options.adminUi)
|
|
1896
4087
|
},
|
|
1897
4088
|
adminKey: options.adminKey
|
|
1898
4089
|
});
|
|
1899
|
-
return runtime;
|
|
4090
|
+
return defineMock(runtime);
|
|
1900
4091
|
};
|
|
1901
4092
|
var mutableResponse = (response) => {
|
|
1902
4093
|
try {
|
|
@@ -1960,9 +4151,12 @@ var credentialRoutes = (registry) => ({
|
|
|
1960
4151
|
}
|
|
1961
4152
|
});
|
|
1962
4153
|
var presetRoutes = (presets, runtime) => ({
|
|
1963
|
-
"GET /faults/presets": () =>
|
|
1964
|
-
|
|
1965
|
-
|
|
4154
|
+
"GET /faults/presets": () => {
|
|
4155
|
+
const body = {
|
|
4156
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4157
|
+
};
|
|
4158
|
+
return adminJson(200, body);
|
|
4159
|
+
},
|
|
1966
4160
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
1967
4161
|
const name = params.name;
|
|
1968
4162
|
if (!presets[name])
|
|
@@ -1973,7 +4167,7 @@ var presetRoutes = (presets, runtime) => ({
|
|
|
1973
4167
|
});
|
|
1974
4168
|
|
|
1975
4169
|
// src/generated/openapi.ts
|
|
1976
|
-
var
|
|
4170
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Payload CMS REST API (Mockingbird subset)","description":"Stateful mock subset of Payload CMS's auto-generated collection REST API: find documents\\n(with a \`where\` query subset, \`limit\`, \`page\`, \`sort\`) and find one by id. Hand-authored\\nfrom Payload's REST API docs and the consumer's response type (payload-cms-response.type.ts).\\n","version":"2","x-mockingbird-upstream":{"note":"Shapes from https://payloadcms.com/docs/rest-api/overview and https://payloadcms.com/docs/queries/overview; the consumer is apps/backend/src/modules/cms/payload-cms/payload-cms.service.ts."}},"servers":[{"url":"https://payload.acme.example"}],"paths":{"/api/{collection}":{"parameters":[{"name":"collection","in":"path","required":true,"schema":{"type":"string","enum":["marketing"]}}],"get":{"operationId":"FindDocuments","description":"Paginated find. \`where[<field>][<operator>]=<value>\` supports equals, not_equals, in, not_in, exists, greater_than(_equal), less_than(_equal), like, contains, and nested \`where[and|or][<i>]\u2026\`. Only the consumer's filters are declared here for parity walks.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"where[type][equals]","in":"query","required":false,"schema":{"type":"string","enum":["referral","banner","email"]}},{"name":"where[isActive][equals]","in":"query","required":false,"schema":{"type":"string","enum":["true","false"]}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","minimum":0,"maximum":100}},{"name":"page","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":20}},{"name":"sort","in":"query","required":false,"schema":{"type":"string","enum":["createdAt","-createdAt","name","-name","id","-id"]}}],"responses":{"200":{"description":"A page of documents","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PaginatedDocs"}}}},"400":{"description":"Invalid query","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Errors"}}}},"404":{"description":"Unknown collection","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Errors"}}}}}}},"/api/{collection}/{id}":{"parameters":[{"name":"collection","in":"path","required":true,"schema":{"type":"string","enum":["marketing"]}},{"name":"id","in":"path","required":true,"schema":{"type":"string","description":"The seeded documents are 1-3; anything else is a 404.","pattern":"^[1-5]$"}}],"get":{"operationId":"FindDocumentById","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The document","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MarketingDoc"}}}},"404":{"description":"Unknown document or collection","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Errors"}}}}}}}},"components":{"schemas":{"MarketingDoc":{"type":"object","required":["id","name","type","createdAt","updatedAt"],"properties":{"id":{"type":"integer","description":"Integer ids, as Payload's Postgres adapter issues them (the consumer types \`id\` as a number)."},"name":{"type":"string"},"type":{"type":"string","enum":["referral","banner","email"]},"isActive":{"type":"boolean"},"cardTitle":{"type":["string","null"]},"cardSubtitle":{"type":["string","null"]},"cardDescription":{"type":["string","null"]},"ctaTitle":{"type":["string","null"]},"ctaActionText":{"type":["string","null"]},"shareMessage":{"type":["string","null"]},"createdAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"updatedAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}}}},"PaginatedDocs":{"type":"object","required":["docs","totalDocs","limit","totalPages","page","pagingCounter","hasPrevPage","hasNextPage","prevPage","nextPage"],"properties":{"docs":{"type":"array","items":{"$ref":"#/components/schemas/MarketingDoc"}},"totalDocs":{"type":"integer"},"limit":{"type":"integer"},"totalPages":{"type":"integer"},"page":{"type":"integer"},"pagingCounter":{"type":"integer"},"hasPrevPage":{"type":"boolean"},"hasNextPage":{"type":"boolean"},"prevPage":{"type":["integer","null"]},"nextPage":{"type":["integer","null"]}}},"Errors":{"type":"object","required":["errors"],"properties":{"errors":{"type":"array","items":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}}}}`);
|
|
1977
4171
|
var operationIds = ["FindDocuments", "FindDocumentById"];
|
|
1978
4172
|
var supportedOperationIds = ["FindDocuments", "FindDocumentById"];
|
|
1979
4173
|
|
|
@@ -2132,11 +4326,11 @@ var PAYLOAD_CMS_PRESETS = {
|
|
|
2132
4326
|
rules: [{ pathPrefix: "/api/", latencyMs: 1e4 }]
|
|
2133
4327
|
}
|
|
2134
4328
|
};
|
|
2135
|
-
var
|
|
2136
|
-
var
|
|
2137
|
-
var
|
|
4329
|
+
var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
4330
|
+
var adminError4 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
|
|
4331
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2138
4332
|
var toDocs = (value, now) => {
|
|
2139
|
-
if (!Array.isArray(value) || !value.every(
|
|
4333
|
+
if (!Array.isArray(value) || !value.every(isRecord6)) return "expected {docs: [{\u2026}]}";
|
|
2140
4334
|
return value.map((doc, index) => ({
|
|
2141
4335
|
createdAt: now,
|
|
2142
4336
|
updatedAt: now,
|
|
@@ -2145,33 +4339,33 @@ var toDocs = (value, now) => {
|
|
|
2145
4339
|
}));
|
|
2146
4340
|
};
|
|
2147
4341
|
var adminRoutes = (runtime) => ({
|
|
2148
|
-
"GET /collections": ({ namespace }) =>
|
|
4342
|
+
"GET /collections": ({ namespace }) => json5(200, { collections: runtime.instance(namespace).collections() }),
|
|
2149
4343
|
"GET /collections/:slug": ({ params, namespace }) => {
|
|
2150
4344
|
const collection = runtime.instance(namespace).state.get(params.slug);
|
|
2151
|
-
return collection ?
|
|
4345
|
+
return collection ? json5(200, collection) : adminError4(404, `no collection ${params.slug}`);
|
|
2152
4346
|
},
|
|
2153
4347
|
"PUT /collections/:slug": ({ params, body, namespace }) => {
|
|
2154
4348
|
const docs = toDocs(
|
|
2155
|
-
|
|
4349
|
+
isRecord6(body) ? body.docs : void 0,
|
|
2156
4350
|
new Date(runtime.clock.now()).toISOString()
|
|
2157
4351
|
);
|
|
2158
|
-
if (typeof docs === "string") return
|
|
2159
|
-
return
|
|
4352
|
+
if (typeof docs === "string") return adminError4(400, docs);
|
|
4353
|
+
return json5(200, runtime.instance(namespace).state.replace(params.slug, docs));
|
|
2160
4354
|
},
|
|
2161
4355
|
"POST /collections/:slug/docs": ({ params, body, namespace }) => {
|
|
2162
|
-
if (!
|
|
2163
|
-
return
|
|
4356
|
+
if (!isRecord6(body)) return adminError4(400, "expected a document object");
|
|
4357
|
+
return json5(201, runtime.instance(namespace).addDoc(params.slug, body));
|
|
2164
4358
|
},
|
|
2165
4359
|
"PATCH /collections/:slug/docs/:id": ({ params, body, namespace }) => {
|
|
2166
|
-
if (!
|
|
4360
|
+
if (!isRecord6(body)) return adminError4(400, "expected a partial document object");
|
|
2167
4361
|
const doc = runtime.instance(namespace).updateDoc(params.slug, Number(params.id), body);
|
|
2168
|
-
return doc ?
|
|
4362
|
+
return doc ? json5(200, doc) : adminError4(404, `no document ${params.slug}/${params.id}`);
|
|
2169
4363
|
},
|
|
2170
|
-
"DELETE /collections/:slug/docs/:id": ({ params, namespace }) => runtime.instance(namespace).deleteDoc(params.slug, Number(params.id)) ?
|
|
4364
|
+
"DELETE /collections/:slug/docs/:id": ({ params, namespace }) => runtime.instance(namespace).deleteDoc(params.slug, Number(params.id)) ? json5(200, { deleted: true }) : adminError4(404, `no document ${params.slug}/${params.id}`)
|
|
2171
4365
|
});
|
|
2172
4366
|
var createRuntime2 = (options = {}) => createRuntime({
|
|
2173
4367
|
name: PAYLOAD_CMS_NAMESPACE,
|
|
2174
|
-
document,
|
|
4368
|
+
document: document2,
|
|
2175
4369
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
2176
4370
|
...options.clock ? { clock: options.clock } : {},
|
|
2177
4371
|
...options.seed !== void 0 ? { seed: options.seed } : {},
|
|
@@ -2210,8 +4404,8 @@ var OPERATORS = [
|
|
|
2210
4404
|
"like",
|
|
2211
4405
|
"contains"
|
|
2212
4406
|
];
|
|
2213
|
-
var
|
|
2214
|
-
var fieldValue = (doc, path) => path.split(".").reduce((value, key) =>
|
|
4407
|
+
var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4408
|
+
var fieldValue = (doc, path) => path.split(".").reduce((value, key) => isRecord7(value) ? value[key] : void 0, doc);
|
|
2215
4409
|
var cast = (raw, sample) => {
|
|
2216
4410
|
if (typeof raw !== "string") return raw;
|
|
2217
4411
|
if (typeof sample === "boolean") return raw === "true" ? true : raw === "false" ? false : raw;
|
|
@@ -2257,11 +4451,11 @@ var test = (operator, actual, raw) => {
|
|
|
2257
4451
|
};
|
|
2258
4452
|
var compileWhere = (where, fields) => {
|
|
2259
4453
|
if (where === void 0) return { ok: true, match: () => true };
|
|
2260
|
-
if (!
|
|
4454
|
+
if (!isRecord7(where)) return { ok: false, message: "The where query is malformed." };
|
|
2261
4455
|
const parts = [];
|
|
2262
4456
|
for (const [key, condition] of Object.entries(where)) {
|
|
2263
4457
|
if (key === "and" || key === "or") {
|
|
2264
|
-
const nested = (Array.isArray(condition) ? condition :
|
|
4458
|
+
const nested = (Array.isArray(condition) ? condition : isRecord7(condition) ? Object.values(condition) : []).map((item) => compileWhere(item, fields));
|
|
2265
4459
|
const failed = nested.find((c) => !c.ok);
|
|
2266
4460
|
if (failed) return failed;
|
|
2267
4461
|
const matchers = nested.map((c) => c.match);
|
|
@@ -2274,7 +4468,7 @@ var compileWhere = (where, fields) => {
|
|
|
2274
4468
|
if (!fields.has(root)) {
|
|
2275
4469
|
return { ok: false, message: `The following path cannot be queried: ${key}` };
|
|
2276
4470
|
}
|
|
2277
|
-
if (!
|
|
4471
|
+
if (!isRecord7(condition))
|
|
2278
4472
|
return { ok: false, message: `The following path cannot be queried: ${key}` };
|
|
2279
4473
|
for (const [operator, value] of Object.entries(condition)) {
|
|
2280
4474
|
if (!OPERATORS.includes(operator)) {
|
|
@@ -2321,7 +4515,7 @@ var PayloadCmsAPI = class {
|
|
|
2321
4515
|
}
|
|
2322
4516
|
});
|
|
2323
4517
|
this.service = createService({
|
|
2324
|
-
document,
|
|
4518
|
+
document: document2,
|
|
2325
4519
|
handlers,
|
|
2326
4520
|
sqlite,
|
|
2327
4521
|
namespace,
|
|
@@ -2430,7 +4624,7 @@ var PayloadCmsAPI = class {
|
|
|
2430
4624
|
};
|
|
2431
4625
|
|
|
2432
4626
|
export {
|
|
2433
|
-
document,
|
|
4627
|
+
document2 as document,
|
|
2434
4628
|
operationIds,
|
|
2435
4629
|
supportedOperationIds,
|
|
2436
4630
|
MARKETING_FIELDS,
|
|
@@ -2443,4 +4637,4 @@ export {
|
|
|
2443
4637
|
compileWhere,
|
|
2444
4638
|
PayloadCmsAPI
|
|
2445
4639
|
};
|
|
2446
|
-
//# sourceMappingURL=chunk-
|
|
4640
|
+
//# sourceMappingURL=chunk-7HS4CTPK.js.map
|