@crvouga/mockingbird-service-textract 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/README.md +1 -1
- package/dist/{chunk-D2QCVSP2.js → chunk-JMZ2Q6FS.js} +2275 -81
- package/dist/chunk-JMZ2Q6FS.js.map +7 -0
- package/dist/{chunk-LZYQYGWM.js → chunk-LSPA2KFO.js} +3 -2
- package/dist/{chunk-LZYQYGWM.js.map → chunk-LSPA2KFO.js.map} +2 -2
- 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-D2QCVSP2.js.map +0 -7
|
@@ -38,30 +38,30 @@ var createClock = (source = Date.now) => {
|
|
|
38
38
|
var Collection = class {
|
|
39
39
|
sqlite;
|
|
40
40
|
namespace;
|
|
41
|
-
|
|
42
|
-
constructor(sqlite, namespace,
|
|
41
|
+
collectionName;
|
|
42
|
+
constructor(sqlite, namespace, collectionName) {
|
|
43
43
|
this.sqlite = sqlite;
|
|
44
44
|
this.namespace = namespace;
|
|
45
|
-
this.
|
|
45
|
+
this.collectionName = collectionName;
|
|
46
46
|
}
|
|
47
47
|
bumpCollectionSeq() {
|
|
48
|
-
const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.
|
|
48
|
+
const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.collectionName);
|
|
49
49
|
const next = (row?.value ?? 0) + 1;
|
|
50
50
|
this.sqlite.prepare(`INSERT INTO mockingbird_sequences (namespace, name, kind, value) VALUES (?, ?, 'collection', ?)
|
|
51
|
-
ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.
|
|
51
|
+
ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.collectionName, next);
|
|
52
52
|
return next;
|
|
53
53
|
}
|
|
54
54
|
nextSequence() {
|
|
55
55
|
return this.sqlite.transaction(() => this.bumpCollectionSeq());
|
|
56
56
|
}
|
|
57
57
|
get(id) {
|
|
58
|
-
const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
58
|
+
const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
59
59
|
if (!row)
|
|
60
60
|
return void 0;
|
|
61
61
|
return JSON.parse(row.value).value;
|
|
62
62
|
}
|
|
63
63
|
has(id) {
|
|
64
|
-
const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
64
|
+
const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
65
65
|
return row !== void 0;
|
|
66
66
|
}
|
|
67
67
|
/** Insert a new record, assigning it the next sequence number. */
|
|
@@ -71,32 +71,32 @@ var Collection = class {
|
|
|
71
71
|
const stored = { seq, value };
|
|
72
72
|
this.sqlite.prepare(`INSERT INTO mockingbird_records (namespace, collection, id, seq, value)
|
|
73
73
|
VALUES (?, ?, ?, ?, ?)
|
|
74
|
-
ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.
|
|
74
|
+
ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.collectionName, id, seq, JSON.stringify(stored));
|
|
75
75
|
return stored;
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
/** Replace an existing record's value, keeping its position. */
|
|
79
79
|
update(id, value) {
|
|
80
80
|
return this.sqlite.transaction(() => {
|
|
81
|
-
const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
81
|
+
const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
82
82
|
if (!row)
|
|
83
83
|
return void 0;
|
|
84
84
|
const stored = { seq: row.seq, value };
|
|
85
|
-
this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.
|
|
85
|
+
this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.collectionName, id);
|
|
86
86
|
return stored;
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
delete(id) {
|
|
90
|
-
const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.
|
|
90
|
+
const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.collectionName, id);
|
|
91
91
|
return result.changes > 0;
|
|
92
92
|
}
|
|
93
93
|
/** How many records the collection holds, without reading them. */
|
|
94
94
|
count() {
|
|
95
|
-
const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.
|
|
95
|
+
const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.collectionName);
|
|
96
96
|
return Number(row?.n ?? 0);
|
|
97
97
|
}
|
|
98
98
|
list(options = {}) {
|
|
99
|
-
const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.
|
|
99
|
+
const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.collectionName);
|
|
100
100
|
const out = [];
|
|
101
101
|
for (const row of rows) {
|
|
102
102
|
const stored = JSON.parse(row.value);
|
|
@@ -353,16 +353,18 @@ var createControlPlane = (context) => {
|
|
|
353
353
|
uptimeMs: context.wallNow() - context.startedAt,
|
|
354
354
|
clock: context.clock.state(),
|
|
355
355
|
namespaces: context.namespaces().length,
|
|
356
|
+
adminUi: `${ADMIN_PREFIX}/ui`,
|
|
356
357
|
...context.describe()
|
|
357
358
|
});
|
|
358
359
|
}
|
|
359
360
|
if (url.pathname !== ADMIN_PREFIX && !url.pathname.startsWith(`${ADMIN_PREFIX}/`)) {
|
|
360
361
|
return void 0;
|
|
361
362
|
}
|
|
362
|
-
|
|
363
|
+
const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
|
|
364
|
+
const shell = request.method === "GET" && (path === "/ui" || path === "/ui/");
|
|
365
|
+
if (!shell && context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
|
|
363
366
|
return adminError(401, `missing or wrong ${ADMIN_KEY_HEADER}`);
|
|
364
367
|
}
|
|
365
|
-
const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
|
|
366
368
|
for (const route of routes) {
|
|
367
369
|
if (route.method !== request.method)
|
|
368
370
|
continue;
|
|
@@ -539,10 +541,10 @@ var OpenAPIReferenceError = class extends Error {
|
|
|
539
541
|
};
|
|
540
542
|
var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
541
543
|
var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
|
|
542
|
-
var resolveRef = (
|
|
544
|
+
var resolveRef = (document3, ref) => {
|
|
543
545
|
if (!ref.startsWith("#/"))
|
|
544
546
|
throw new OpenAPIReferenceError(ref);
|
|
545
|
-
let cursor =
|
|
547
|
+
let cursor = document3;
|
|
546
548
|
for (const raw of ref.slice(2).split("/")) {
|
|
547
549
|
const segment = unescapePointer(raw);
|
|
548
550
|
if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
|
|
@@ -554,14 +556,14 @@ var resolveRef = (document2, ref) => {
|
|
|
554
556
|
throw new OpenAPIReferenceError(ref);
|
|
555
557
|
return cursor;
|
|
556
558
|
};
|
|
557
|
-
var deref = (
|
|
559
|
+
var deref = (document3, value) => {
|
|
558
560
|
let current = value;
|
|
559
561
|
const seen = /* @__PURE__ */ new Set();
|
|
560
562
|
while (isReference(current)) {
|
|
561
563
|
if (seen.has(current.$ref))
|
|
562
564
|
throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
|
|
563
565
|
seen.add(current.$ref);
|
|
564
|
-
current = resolveRef(
|
|
566
|
+
current = resolveRef(document3, current.$ref);
|
|
565
567
|
}
|
|
566
568
|
return current;
|
|
567
569
|
};
|
|
@@ -579,36 +581,36 @@ var HTTP_METHODS = [
|
|
|
579
581
|
];
|
|
580
582
|
|
|
581
583
|
// ../../openapi/core/dist/document.js
|
|
582
|
-
var mergeParameters = (
|
|
584
|
+
var mergeParameters = (document3, item, own) => {
|
|
583
585
|
const merged = /* @__PURE__ */ new Map();
|
|
584
586
|
for (const raw of item.parameters ?? []) {
|
|
585
|
-
const parameter = deref(
|
|
587
|
+
const parameter = deref(document3, raw);
|
|
586
588
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
587
589
|
}
|
|
588
590
|
for (const raw of own ?? []) {
|
|
589
|
-
const parameter = deref(
|
|
591
|
+
const parameter = deref(document3, raw);
|
|
590
592
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
591
593
|
}
|
|
592
594
|
return [...merged.values()];
|
|
593
595
|
};
|
|
594
|
-
var listOperations = (
|
|
596
|
+
var listOperations = (document3) => {
|
|
595
597
|
const operations = [];
|
|
596
|
-
for (const [path, item] of Object.entries(
|
|
598
|
+
for (const [path, item] of Object.entries(document3.paths)) {
|
|
597
599
|
for (const method of HTTP_METHODS) {
|
|
598
600
|
const operation = item[method];
|
|
599
601
|
if (operation?.operationId === void 0)
|
|
600
602
|
continue;
|
|
601
603
|
const responses = {};
|
|
602
604
|
for (const [status, response] of Object.entries(operation.responses)) {
|
|
603
|
-
responses[status] = deref(
|
|
605
|
+
responses[status] = deref(document3, response);
|
|
604
606
|
}
|
|
605
607
|
operations.push({
|
|
606
608
|
operationId: operation.operationId,
|
|
607
609
|
method,
|
|
608
610
|
path,
|
|
609
611
|
operation,
|
|
610
|
-
parameters: mergeParameters(
|
|
611
|
-
requestBody: operation.requestBody === void 0 ? void 0 : deref(
|
|
612
|
+
parameters: mergeParameters(document3, item, operation.parameters),
|
|
613
|
+
requestBody: operation.requestBody === void 0 ? void 0 : deref(document3, operation.requestBody),
|
|
612
614
|
responses
|
|
613
615
|
});
|
|
614
616
|
}
|
|
@@ -969,6 +971,1737 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
969
971
|
});
|
|
970
972
|
};
|
|
971
973
|
|
|
974
|
+
// ../../ui/dist/reset.js
|
|
975
|
+
var CSS_RESET = `*,
|
|
976
|
+
*::before,
|
|
977
|
+
*::after {
|
|
978
|
+
box-sizing: border-box;
|
|
979
|
+
margin: 0;
|
|
980
|
+
padding: 0;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
* {
|
|
984
|
+
scrollbar-width: thin;
|
|
985
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
*::-webkit-scrollbar {
|
|
989
|
+
width: 12px;
|
|
990
|
+
height: 12px;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
*::-webkit-scrollbar-track,
|
|
994
|
+
*::-webkit-scrollbar-corner {
|
|
995
|
+
background: Canvas;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
*::-webkit-scrollbar-thumb {
|
|
999
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1000
|
+
border: 3px solid Canvas;
|
|
1001
|
+
border-radius: 999px;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
html {
|
|
1005
|
+
hanging-punctuation: first allow-end last;
|
|
1006
|
+
-webkit-text-size-adjust: none;
|
|
1007
|
+
text-size-adjust: none;
|
|
1008
|
+
tab-size: 4;
|
|
1009
|
+
font-family:
|
|
1010
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1011
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1012
|
+
font-size: 16px;
|
|
1013
|
+
line-height: 1.5;
|
|
1014
|
+
-webkit-font-smoothing: antialiased;
|
|
1015
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1016
|
+
text-rendering: optimizeLegibility;
|
|
1017
|
+
-webkit-tap-highlight-color: transparent;
|
|
1018
|
+
scroll-behavior: smooth;
|
|
1019
|
+
background: Canvas;
|
|
1020
|
+
color: CanvasText;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
body {
|
|
1024
|
+
min-height: 100svh;
|
|
1025
|
+
line-height: 1.5;
|
|
1026
|
+
background: Canvas;
|
|
1027
|
+
color: CanvasText;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
h1 {
|
|
1031
|
+
font-size: 2em;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
h2 {
|
|
1035
|
+
font-size: 1.5em;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
h3 {
|
|
1039
|
+
font-size: 1.17em;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
h4 {
|
|
1043
|
+
font-size: 1em;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
h5 {
|
|
1047
|
+
font-size: 0.83em;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
h6 {
|
|
1051
|
+
font-size: 0.67em;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
h1,
|
|
1055
|
+
h2,
|
|
1056
|
+
h3,
|
|
1057
|
+
h4,
|
|
1058
|
+
h5,
|
|
1059
|
+
h6 {
|
|
1060
|
+
font-weight: 700;
|
|
1061
|
+
line-height: 1.2;
|
|
1062
|
+
text-wrap: balance;
|
|
1063
|
+
overflow-wrap: break-word;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
p,
|
|
1067
|
+
li,
|
|
1068
|
+
figcaption,
|
|
1069
|
+
dd,
|
|
1070
|
+
dt,
|
|
1071
|
+
blockquote {
|
|
1072
|
+
overflow-wrap: break-word;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
p,
|
|
1076
|
+
li,
|
|
1077
|
+
figcaption,
|
|
1078
|
+
blockquote {
|
|
1079
|
+
text-wrap: pretty;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
ul,
|
|
1083
|
+
ol,
|
|
1084
|
+
menu {
|
|
1085
|
+
list-style: none;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
a {
|
|
1089
|
+
color: inherit;
|
|
1090
|
+
text-decoration: underline;
|
|
1091
|
+
text-decoration-thickness: 1px;
|
|
1092
|
+
text-underline-offset: 0.15em;
|
|
1093
|
+
text-decoration-skip-ink: auto;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
b,
|
|
1097
|
+
strong {
|
|
1098
|
+
font-weight: 700;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
small {
|
|
1102
|
+
font-size: 0.875em;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
code,
|
|
1106
|
+
kbd,
|
|
1107
|
+
samp,
|
|
1108
|
+
pre {
|
|
1109
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1110
|
+
font-size: 1em;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
sub,
|
|
1114
|
+
sup {
|
|
1115
|
+
font-size: 75%;
|
|
1116
|
+
line-height: 0;
|
|
1117
|
+
position: relative;
|
|
1118
|
+
vertical-align: baseline;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
sub {
|
|
1122
|
+
bottom: -0.25em;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
sup {
|
|
1126
|
+
top: -0.5em;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
abbr[title] {
|
|
1130
|
+
text-decoration: underline dotted;
|
|
1131
|
+
text-underline-offset: 0.15em;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
mark {
|
|
1135
|
+
background: Mark;
|
|
1136
|
+
color: MarkText;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
hr {
|
|
1140
|
+
height: 0;
|
|
1141
|
+
border: 0;
|
|
1142
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1143
|
+
color: inherit;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
img,
|
|
1147
|
+
picture,
|
|
1148
|
+
video,
|
|
1149
|
+
canvas {
|
|
1150
|
+
display: block;
|
|
1151
|
+
max-width: 100%;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
img,
|
|
1155
|
+
video {
|
|
1156
|
+
height: auto;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
svg {
|
|
1160
|
+
overflow: hidden;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
iframe {
|
|
1164
|
+
border: 0;
|
|
1165
|
+
max-width: 100%;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
table {
|
|
1169
|
+
border-collapse: collapse;
|
|
1170
|
+
border-spacing: 0;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
fieldset {
|
|
1174
|
+
border: 0;
|
|
1175
|
+
min-inline-size: 0;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
legend {
|
|
1179
|
+
padding: 0;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
button,
|
|
1183
|
+
input,
|
|
1184
|
+
select,
|
|
1185
|
+
textarea,
|
|
1186
|
+
optgroup {
|
|
1187
|
+
font: inherit;
|
|
1188
|
+
letter-spacing: inherit;
|
|
1189
|
+
color: inherit;
|
|
1190
|
+
margin: 0;
|
|
1191
|
+
vertical-align: middle;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
button,
|
|
1195
|
+
input[type="button"],
|
|
1196
|
+
input[type="submit"],
|
|
1197
|
+
input[type="reset"] {
|
|
1198
|
+
appearance: none;
|
|
1199
|
+
background: none;
|
|
1200
|
+
border: 0;
|
|
1201
|
+
padding: 0;
|
|
1202
|
+
cursor: pointer;
|
|
1203
|
+
text-align: center;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
input,
|
|
1207
|
+
textarea,
|
|
1208
|
+
select {
|
|
1209
|
+
background-color: Canvas;
|
|
1210
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1211
|
+
border-radius: 0;
|
|
1212
|
+
padding: 0.5em 0.65em;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
input[type="checkbox"],
|
|
1216
|
+
input[type="radio"],
|
|
1217
|
+
input[type="range"],
|
|
1218
|
+
input[type="file"],
|
|
1219
|
+
input[type="color"],
|
|
1220
|
+
input[type="button"],
|
|
1221
|
+
input[type="submit"],
|
|
1222
|
+
input[type="reset"],
|
|
1223
|
+
input[type="image"],
|
|
1224
|
+
input[type="hidden"] {
|
|
1225
|
+
background: none;
|
|
1226
|
+
border: 0;
|
|
1227
|
+
padding: 0;
|
|
1228
|
+
border-radius: 0;
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
input[type="checkbox"],
|
|
1232
|
+
input[type="radio"] {
|
|
1233
|
+
accent-color: CanvasText;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
input[type="search"] {
|
|
1237
|
+
appearance: none;
|
|
1238
|
+
background-color: Canvas;
|
|
1239
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1243
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1244
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1245
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1246
|
+
-webkit-appearance: none;
|
|
1247
|
+
display: none;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
input[type="number"] {
|
|
1251
|
+
appearance: textfield;
|
|
1252
|
+
background-color: Canvas;
|
|
1253
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1257
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1258
|
+
-webkit-appearance: none;
|
|
1259
|
+
margin: 0;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
textarea {
|
|
1263
|
+
resize: vertical;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
::placeholder {
|
|
1267
|
+
opacity: 1;
|
|
1268
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
:focus-visible {
|
|
1272
|
+
outline: 2px solid CanvasText;
|
|
1273
|
+
outline-offset: 2px;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
:focus:not(:focus-visible) {
|
|
1277
|
+
outline: none;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
:disabled,
|
|
1281
|
+
[disabled] {
|
|
1282
|
+
cursor: default;
|
|
1283
|
+
opacity: 0.6;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
label,
|
|
1287
|
+
summary,
|
|
1288
|
+
select,
|
|
1289
|
+
[role="button"] {
|
|
1290
|
+
cursor: pointer;
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
summary {
|
|
1294
|
+
display: list-item;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
details {
|
|
1298
|
+
display: block;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
dialog {
|
|
1302
|
+
margin: auto;
|
|
1303
|
+
padding: 1rem;
|
|
1304
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1305
|
+
background: Canvas;
|
|
1306
|
+
color: CanvasText;
|
|
1307
|
+
max-width: calc(100vw - 2rem);
|
|
1308
|
+
max-height: calc(100svh - 2rem);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
dialog:not([open]) {
|
|
1312
|
+
display: none;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
::backdrop {
|
|
1316
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
[hidden] {
|
|
1320
|
+
display: none !important;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
::selection {
|
|
1324
|
+
background: Highlight;
|
|
1325
|
+
color: HighlightText;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1329
|
+
*,
|
|
1330
|
+
*::before,
|
|
1331
|
+
*::after {
|
|
1332
|
+
animation-duration: 0.01ms !important;
|
|
1333
|
+
animation-iteration-count: 1 !important;
|
|
1334
|
+
transition-duration: 0.01ms !important;
|
|
1335
|
+
scroll-behavior: auto !important;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
@media (pointer: coarse) {
|
|
1340
|
+
input,
|
|
1341
|
+
select,
|
|
1342
|
+
textarea {
|
|
1343
|
+
font-size: max(16px, 1em);
|
|
1344
|
+
}
|
|
1345
|
+
}`;
|
|
1346
|
+
|
|
1347
|
+
// ../core/dist/admin-client.js
|
|
1348
|
+
function isRecord2(value) {
|
|
1349
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1350
|
+
}
|
|
1351
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1352
|
+
const clip = (value, max) => {
|
|
1353
|
+
if (typeof value !== "string")
|
|
1354
|
+
return null;
|
|
1355
|
+
const trimmed = value.trim();
|
|
1356
|
+
if (trimmed === "")
|
|
1357
|
+
return null;
|
|
1358
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1359
|
+
};
|
|
1360
|
+
const httpUrl = (value) => {
|
|
1361
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1362
|
+
return null;
|
|
1363
|
+
try {
|
|
1364
|
+
const url = new URL(value);
|
|
1365
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1366
|
+
return null;
|
|
1367
|
+
return url.href;
|
|
1368
|
+
} catch {
|
|
1369
|
+
return null;
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
const hexColor = (value) => {
|
|
1373
|
+
if (typeof value !== "string")
|
|
1374
|
+
return null;
|
|
1375
|
+
const raw = value.trim();
|
|
1376
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1377
|
+
};
|
|
1378
|
+
const hostname = (value) => {
|
|
1379
|
+
try {
|
|
1380
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1381
|
+
} catch {
|
|
1382
|
+
return value;
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
host.replaceChildren();
|
|
1386
|
+
host.hidden = true;
|
|
1387
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1388
|
+
return;
|
|
1389
|
+
const row = catalog[service];
|
|
1390
|
+
if (!isRecord2(row))
|
|
1391
|
+
return;
|
|
1392
|
+
const vendor = clip(row.vendor, 80);
|
|
1393
|
+
const website = httpUrl(row.website);
|
|
1394
|
+
const guide = httpUrl(row.guide);
|
|
1395
|
+
const docs = httpUrl(row.docs);
|
|
1396
|
+
const logo = httpUrl(row.logo);
|
|
1397
|
+
const color = hexColor(row.color);
|
|
1398
|
+
const description = clip(row.description, 280);
|
|
1399
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1400
|
+
return;
|
|
1401
|
+
const add = (node) => {
|
|
1402
|
+
host.append(node);
|
|
1403
|
+
return node;
|
|
1404
|
+
};
|
|
1405
|
+
if (logo !== null) {
|
|
1406
|
+
const img = doc.createElement("img");
|
|
1407
|
+
img.alt = "";
|
|
1408
|
+
img.src = logo;
|
|
1409
|
+
img.width = 16;
|
|
1410
|
+
img.height = 16;
|
|
1411
|
+
img.decoding = "async";
|
|
1412
|
+
img.referrerPolicy = "no-referrer";
|
|
1413
|
+
if (color !== null)
|
|
1414
|
+
img.style.borderColor = color;
|
|
1415
|
+
add(img);
|
|
1416
|
+
}
|
|
1417
|
+
const name = doc.createElement("span");
|
|
1418
|
+
name.className = "vendor-name";
|
|
1419
|
+
name.textContent = vendor;
|
|
1420
|
+
if (description !== null)
|
|
1421
|
+
name.title = description;
|
|
1422
|
+
add(name);
|
|
1423
|
+
const sep = () => {
|
|
1424
|
+
const node = doc.createElement("span");
|
|
1425
|
+
node.className = "vendor-sep";
|
|
1426
|
+
node.setAttribute("aria-hidden", "true");
|
|
1427
|
+
node.textContent = "\xB7";
|
|
1428
|
+
return node;
|
|
1429
|
+
};
|
|
1430
|
+
const link = (href, label, title) => {
|
|
1431
|
+
const node = doc.createElement("a");
|
|
1432
|
+
node.className = "vendor-link";
|
|
1433
|
+
node.href = href;
|
|
1434
|
+
node.target = "_blank";
|
|
1435
|
+
node.rel = "noopener noreferrer";
|
|
1436
|
+
node.referrerPolicy = "no-referrer";
|
|
1437
|
+
node.textContent = label;
|
|
1438
|
+
node.title = title;
|
|
1439
|
+
return node;
|
|
1440
|
+
};
|
|
1441
|
+
if (website !== null) {
|
|
1442
|
+
add(sep());
|
|
1443
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1444
|
+
}
|
|
1445
|
+
if (guide !== null) {
|
|
1446
|
+
add(sep());
|
|
1447
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1448
|
+
}
|
|
1449
|
+
if (docs !== null) {
|
|
1450
|
+
add(sep());
|
|
1451
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1452
|
+
}
|
|
1453
|
+
host.removeAttribute("hidden");
|
|
1454
|
+
host.hidden = false;
|
|
1455
|
+
}
|
|
1456
|
+
function startAdminBrand(env) {
|
|
1457
|
+
const requested = env.params.get("brands");
|
|
1458
|
+
let brandsUrl = env.brandsUrl;
|
|
1459
|
+
if (requested) {
|
|
1460
|
+
try {
|
|
1461
|
+
const url = new URL(requested, env.location.href);
|
|
1462
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1463
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1464
|
+
brandsUrl = url.href;
|
|
1465
|
+
} catch {
|
|
1466
|
+
brandsUrl = env.brandsUrl;
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
const vendorHost = env.$("vendor");
|
|
1470
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1471
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1472
|
+
if (vendorHost === null)
|
|
1473
|
+
return;
|
|
1474
|
+
env.fetch(brandsUrl, {
|
|
1475
|
+
headers: { accept: "application/json" },
|
|
1476
|
+
signal: AbortSignal.timeout(5e3)
|
|
1477
|
+
}).then(async (response) => {
|
|
1478
|
+
if (!response.ok)
|
|
1479
|
+
return null;
|
|
1480
|
+
const catalog = await response.json();
|
|
1481
|
+
return catalog;
|
|
1482
|
+
}).then((catalog) => {
|
|
1483
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1484
|
+
}).catch(() => {
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
function faultPresetList(value) {
|
|
1488
|
+
if (!isRecord2(value))
|
|
1489
|
+
throw new Error("Fault presets response was not an object");
|
|
1490
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1491
|
+
return { presets: [] };
|
|
1492
|
+
}
|
|
1493
|
+
if (!Array.isArray(value.presets))
|
|
1494
|
+
throw new Error("Fault presets response was not a list");
|
|
1495
|
+
return {
|
|
1496
|
+
presets: value.presets.flatMap((item) => {
|
|
1497
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1498
|
+
return [];
|
|
1499
|
+
return [{ name: item.name }];
|
|
1500
|
+
})
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
function bootAdmin(config) {
|
|
1504
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1505
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1506
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1507
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1508
|
+
const readJson2 = (text) => {
|
|
1509
|
+
const value = JSON.parse(text);
|
|
1510
|
+
return value;
|
|
1511
|
+
};
|
|
1512
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1513
|
+
switch (char) {
|
|
1514
|
+
case "&":
|
|
1515
|
+
return "&";
|
|
1516
|
+
case "<":
|
|
1517
|
+
return "<";
|
|
1518
|
+
case ">":
|
|
1519
|
+
return ">";
|
|
1520
|
+
case '"':
|
|
1521
|
+
return """;
|
|
1522
|
+
default:
|
|
1523
|
+
return "'";
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
const el = (id, kind) => {
|
|
1527
|
+
const node = document.getElementById(id);
|
|
1528
|
+
if (!(node instanceof kind))
|
|
1529
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1530
|
+
return node;
|
|
1531
|
+
};
|
|
1532
|
+
const errorMessage = (data, fallback) => {
|
|
1533
|
+
if (!isRecord2(data))
|
|
1534
|
+
return fallback;
|
|
1535
|
+
const error = data.error;
|
|
1536
|
+
if (!isRecord2(error) || typeof error.message !== "string" || error.message === "") {
|
|
1537
|
+
return fallback;
|
|
1538
|
+
}
|
|
1539
|
+
return error.message;
|
|
1540
|
+
};
|
|
1541
|
+
const requireList = (value, label) => {
|
|
1542
|
+
if (value === void 0 || value === null)
|
|
1543
|
+
return [];
|
|
1544
|
+
if (!Array.isArray(value))
|
|
1545
|
+
throw new Error(`${label} was not a list`);
|
|
1546
|
+
return value;
|
|
1547
|
+
};
|
|
1548
|
+
const state = {
|
|
1549
|
+
namespace: "default",
|
|
1550
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1551
|
+
view: "overview",
|
|
1552
|
+
collection: "",
|
|
1553
|
+
shape: null,
|
|
1554
|
+
route: null,
|
|
1555
|
+
editing: null
|
|
1556
|
+
};
|
|
1557
|
+
const standard = new Set(config.standardRoutes);
|
|
1558
|
+
const banner = el("banner", HTMLElement);
|
|
1559
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1560
|
+
keyInput.value = state.key;
|
|
1561
|
+
const params = new URLSearchParams(location.search);
|
|
1562
|
+
const queryKey = params.get("key");
|
|
1563
|
+
if (queryKey) {
|
|
1564
|
+
state.key = queryKey;
|
|
1565
|
+
keyInput.value = state.key;
|
|
1566
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1567
|
+
params.delete("key");
|
|
1568
|
+
const next = params.toString();
|
|
1569
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1570
|
+
}
|
|
1571
|
+
const queryNamespace = params.get("namespace");
|
|
1572
|
+
if (queryNamespace)
|
|
1573
|
+
state.namespace = queryNamespace;
|
|
1574
|
+
const showError = (error) => {
|
|
1575
|
+
banner.textContent = error instanceof Error ? error.message : String(error);
|
|
1576
|
+
banner.classList.add("show");
|
|
1577
|
+
};
|
|
1578
|
+
const clearError = () => {
|
|
1579
|
+
banner.classList.remove("show");
|
|
1580
|
+
};
|
|
1581
|
+
const api = async (method, path, body) => {
|
|
1582
|
+
const headers = { accept: "application/json" };
|
|
1583
|
+
if (state.key !== "")
|
|
1584
|
+
headers[config.adminKeyHeader] = state.key;
|
|
1585
|
+
if (state.namespace !== "")
|
|
1586
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
1587
|
+
if (body !== void 0)
|
|
1588
|
+
headers["content-type"] = "application/json";
|
|
1589
|
+
const init = { method, headers };
|
|
1590
|
+
if (body !== void 0)
|
|
1591
|
+
init.body = JSON.stringify(body);
|
|
1592
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
1593
|
+
const text = await response.text();
|
|
1594
|
+
let data = null;
|
|
1595
|
+
if (text !== "") {
|
|
1596
|
+
try {
|
|
1597
|
+
data = readJson2(text);
|
|
1598
|
+
} catch {
|
|
1599
|
+
data = { raw: text };
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (response.status === 401) {
|
|
1603
|
+
keyInput.focus();
|
|
1604
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
1605
|
+
}
|
|
1606
|
+
if (!response.ok) {
|
|
1607
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
1608
|
+
}
|
|
1609
|
+
return data;
|
|
1610
|
+
};
|
|
1611
|
+
const originGet = async (path) => {
|
|
1612
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
1613
|
+
if (!response.ok)
|
|
1614
|
+
throw new Error(`${response.status} ${path}`);
|
|
1615
|
+
const value = await response.json();
|
|
1616
|
+
return value;
|
|
1617
|
+
};
|
|
1618
|
+
const panelApi = {
|
|
1619
|
+
get: (path) => api("GET", path),
|
|
1620
|
+
send: (method, path, body) => api(method, path, body),
|
|
1621
|
+
namespace: () => state.namespace
|
|
1622
|
+
};
|
|
1623
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
1624
|
+
const setTheme = (theme) => {
|
|
1625
|
+
if (theme)
|
|
1626
|
+
document.documentElement.dataset.theme = theme;
|
|
1627
|
+
else
|
|
1628
|
+
delete document.documentElement.dataset.theme;
|
|
1629
|
+
};
|
|
1630
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
1631
|
+
if (storedTheme)
|
|
1632
|
+
setTheme(storedTheme);
|
|
1633
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
1634
|
+
const current = document.documentElement.dataset.theme;
|
|
1635
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1636
|
+
const next = dark ? "light" : "dark";
|
|
1637
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
1638
|
+
setTheme(next);
|
|
1639
|
+
});
|
|
1640
|
+
const show = (view) => {
|
|
1641
|
+
state.view = view;
|
|
1642
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
1643
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1644
|
+
continue;
|
|
1645
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
1646
|
+
}
|
|
1647
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
1648
|
+
if (!(section instanceof HTMLElement))
|
|
1649
|
+
continue;
|
|
1650
|
+
section.hidden = section.id !== `view-${view}`;
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1653
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
1654
|
+
const target = event.target;
|
|
1655
|
+
if (!(target instanceof Element))
|
|
1656
|
+
return;
|
|
1657
|
+
const button = target.closest("button[data-view]");
|
|
1658
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1659
|
+
return;
|
|
1660
|
+
const view = button.dataset.view;
|
|
1661
|
+
if (view === void 0)
|
|
1662
|
+
return;
|
|
1663
|
+
show(view);
|
|
1664
|
+
refresh().catch(showError);
|
|
1665
|
+
});
|
|
1666
|
+
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>`;
|
|
1667
|
+
const table = (columns, rows) => {
|
|
1668
|
+
if (rows.length === 0)
|
|
1669
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
1670
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
1671
|
+
const body = rows.map((row) => {
|
|
1672
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
|
|
1673
|
+
const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
|
|
1674
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
1675
|
+
}).join("");
|
|
1676
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
1677
|
+
};
|
|
1678
|
+
const preview = (value) => {
|
|
1679
|
+
const text = JSON.stringify(value) ?? "null";
|
|
1680
|
+
return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
|
|
1681
|
+
};
|
|
1682
|
+
const when = (epoch) => {
|
|
1683
|
+
const date = new Date(epoch);
|
|
1684
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
1685
|
+
};
|
|
1686
|
+
const clockCard = (epoch) => {
|
|
1687
|
+
const date = new Date(epoch);
|
|
1688
|
+
if (Number.isNaN(date.getTime()))
|
|
1689
|
+
return esc(String(epoch));
|
|
1690
|
+
const iso = date.toISOString();
|
|
1691
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
1692
|
+
};
|
|
1693
|
+
const decodeClock = (value) => {
|
|
1694
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
1695
|
+
throw new Error("Clock response was not a clock");
|
|
1696
|
+
}
|
|
1697
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
1698
|
+
};
|
|
1699
|
+
const decodeField = (value) => {
|
|
1700
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
1701
|
+
return void 0;
|
|
1702
|
+
}
|
|
1703
|
+
const field = {
|
|
1704
|
+
name: value.name,
|
|
1705
|
+
kind: value.kind,
|
|
1706
|
+
optional: value.optional === true
|
|
1707
|
+
};
|
|
1708
|
+
if (typeof value.description === "string")
|
|
1709
|
+
field.description = value.description;
|
|
1710
|
+
if (Array.isArray(value.fields)) {
|
|
1711
|
+
field.fields = value.fields.flatMap((item) => {
|
|
1712
|
+
const child = decodeField(item);
|
|
1713
|
+
return child === void 0 ? [] : [child];
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
return field;
|
|
1717
|
+
};
|
|
1718
|
+
const decodeCollection = (value) => {
|
|
1719
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
1720
|
+
return void 0;
|
|
1721
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
1722
|
+
const field = decodeField(item);
|
|
1723
|
+
return field === void 0 ? [] : [field];
|
|
1724
|
+
}) : [];
|
|
1725
|
+
const collection = {
|
|
1726
|
+
name: value.name,
|
|
1727
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
1728
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
1729
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
1730
|
+
fields
|
|
1731
|
+
};
|
|
1732
|
+
if (typeof value.description === "string")
|
|
1733
|
+
collection.description = value.description;
|
|
1734
|
+
return collection;
|
|
1735
|
+
};
|
|
1736
|
+
const decodeState = (value) => {
|
|
1737
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
1738
|
+
throw new Error("State response has no collection list");
|
|
1739
|
+
}
|
|
1740
|
+
return {
|
|
1741
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
1742
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
1743
|
+
collections: value.collections.flatMap((item) => {
|
|
1744
|
+
const collection = decodeCollection(item);
|
|
1745
|
+
return collection === void 0 ? [] : [collection];
|
|
1746
|
+
})
|
|
1747
|
+
};
|
|
1748
|
+
};
|
|
1749
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
1750
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
1751
|
+
return [];
|
|
1752
|
+
return [
|
|
1753
|
+
{
|
|
1754
|
+
id: item.id,
|
|
1755
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
1756
|
+
value: item.value,
|
|
1757
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
1758
|
+
}
|
|
1759
|
+
];
|
|
1760
|
+
});
|
|
1761
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
1762
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
1763
|
+
if (!isRecord2(item))
|
|
1764
|
+
return [];
|
|
1765
|
+
return [
|
|
1766
|
+
{
|
|
1767
|
+
at: textOf(item.at),
|
|
1768
|
+
method: textOf(item.method),
|
|
1769
|
+
path: textOf(item.path),
|
|
1770
|
+
status: textOf(item.status),
|
|
1771
|
+
durationMs: textOf(item.durationMs),
|
|
1772
|
+
operationId: textOf(item.operationId)
|
|
1773
|
+
}
|
|
1774
|
+
];
|
|
1775
|
+
});
|
|
1776
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
1777
|
+
if (!isRecord2(item))
|
|
1778
|
+
return [];
|
|
1779
|
+
return [
|
|
1780
|
+
{
|
|
1781
|
+
id: textOf(item.id),
|
|
1782
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
1783
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
1784
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
1785
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
1786
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
1787
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
1788
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
1789
|
+
}
|
|
1790
|
+
];
|
|
1791
|
+
});
|
|
1792
|
+
const loadNamespaces = async () => {
|
|
1793
|
+
const data = await api("GET", "/namespaces");
|
|
1794
|
+
const select = el("namespace", HTMLSelectElement);
|
|
1795
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
1796
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
1797
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
1798
|
+
if (!names.includes(state.namespace))
|
|
1799
|
+
names.unshift(state.namespace);
|
|
1800
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
1801
|
+
select.value = state.namespace;
|
|
1802
|
+
};
|
|
1803
|
+
const renderOverview = async () => {
|
|
1804
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
1805
|
+
originGet("/health"),
|
|
1806
|
+
api("GET", "/state"),
|
|
1807
|
+
api("GET", "/clock"),
|
|
1808
|
+
api("GET", "/requests?limit=8")
|
|
1809
|
+
]);
|
|
1810
|
+
if (!isRecord2(health))
|
|
1811
|
+
throw new Error("Health response was not an object");
|
|
1812
|
+
const decoded = decodeState(shape);
|
|
1813
|
+
state.shape = decoded;
|
|
1814
|
+
const time = decodeClock(clock);
|
|
1815
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
1816
|
+
{
|
|
1817
|
+
k: "Service",
|
|
1818
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
1819
|
+
},
|
|
1820
|
+
{
|
|
1821
|
+
k: "Status",
|
|
1822
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
1823
|
+
},
|
|
1824
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
1825
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
1826
|
+
{
|
|
1827
|
+
k: "Records",
|
|
1828
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
1829
|
+
},
|
|
1830
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
1831
|
+
]);
|
|
1832
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
1833
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
1834
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
1835
|
+
{
|
|
1836
|
+
label: "Status",
|
|
1837
|
+
cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
|
|
1838
|
+
},
|
|
1839
|
+
{ label: "Operation", cell: (row) => esc(row.operationId) }
|
|
1840
|
+
], decodeJournal(journal));
|
|
1841
|
+
};
|
|
1842
|
+
const schemaChips = (collection) => {
|
|
1843
|
+
if (collection.fields.length === 0) {
|
|
1844
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
1845
|
+
}
|
|
1846
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
1847
|
+
};
|
|
1848
|
+
const renderState = async () => {
|
|
1849
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
1850
|
+
state.shape = shape;
|
|
1851
|
+
const host = el("collections", HTMLElement);
|
|
1852
|
+
if (shape.collections.length === 0) {
|
|
1853
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
1854
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
1855
|
+
el("records", HTMLElement).innerHTML = "";
|
|
1856
|
+
return;
|
|
1857
|
+
}
|
|
1858
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
1859
|
+
const first = shape.collections[0];
|
|
1860
|
+
if (first === void 0)
|
|
1861
|
+
return;
|
|
1862
|
+
state.collection = first.name;
|
|
1863
|
+
}
|
|
1864
|
+
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("");
|
|
1865
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
1866
|
+
if (selected === void 0)
|
|
1867
|
+
return;
|
|
1868
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
1869
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
1870
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
1871
|
+
el("records", HTMLElement).innerHTML = table([
|
|
1872
|
+
{ label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
|
|
1873
|
+
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
1874
|
+
{ label: "Value", cell: (row) => preview(row.value) }
|
|
1875
|
+
], decodeRecords(page));
|
|
1876
|
+
};
|
|
1877
|
+
const renderClock = async () => {
|
|
1878
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
1879
|
+
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>`;
|
|
1880
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
1881
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
1882
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
1883
|
+
};
|
|
1884
|
+
const renderFaults = async () => {
|
|
1885
|
+
const [faults, presets] = await Promise.all([
|
|
1886
|
+
api("GET", "/faults"),
|
|
1887
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
1888
|
+
]);
|
|
1889
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
1890
|
+
const current = select.value;
|
|
1891
|
+
const list = faultPresetList(presets).presets;
|
|
1892
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
1893
|
+
select.value = current;
|
|
1894
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
1895
|
+
{ label: "Id", cell: (row) => esc(row.id) },
|
|
1896
|
+
{
|
|
1897
|
+
label: "Match",
|
|
1898
|
+
cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
1899
|
+
},
|
|
1900
|
+
{
|
|
1901
|
+
label: "Effect",
|
|
1902
|
+
cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
|
|
1903
|
+
}
|
|
1904
|
+
], decodeFaults(faults));
|
|
1905
|
+
};
|
|
1906
|
+
const renderJournal = async () => {
|
|
1907
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
1908
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
1909
|
+
{ label: "When", cell: (row) => esc(row.at) },
|
|
1910
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
1911
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
1912
|
+
{ label: "Status", cell: (row) => esc(row.status) },
|
|
1913
|
+
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
1914
|
+
], decodeJournal(journal));
|
|
1915
|
+
};
|
|
1916
|
+
const renderRoutes = async () => {
|
|
1917
|
+
const data = await api("GET", "/");
|
|
1918
|
+
if (!isRecord2(data))
|
|
1919
|
+
throw new Error("Route list was not an object");
|
|
1920
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
1921
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
1922
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
1923
|
+
const parts = route.split(" ");
|
|
1924
|
+
const method = parts[0] ?? "";
|
|
1925
|
+
const path = parts.slice(1).join(" ");
|
|
1926
|
+
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>`;
|
|
1927
|
+
}).join("");
|
|
1928
|
+
};
|
|
1929
|
+
const renderers = {
|
|
1930
|
+
overview: renderOverview,
|
|
1931
|
+
state: renderState,
|
|
1932
|
+
clock: renderClock,
|
|
1933
|
+
faults: renderFaults,
|
|
1934
|
+
journal: renderJournal,
|
|
1935
|
+
routes: renderRoutes
|
|
1936
|
+
};
|
|
1937
|
+
async function refresh() {
|
|
1938
|
+
clearError();
|
|
1939
|
+
const render = renderers[state.view];
|
|
1940
|
+
if (render)
|
|
1941
|
+
await render();
|
|
1942
|
+
}
|
|
1943
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
1944
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
1945
|
+
refresh().catch(showError);
|
|
1946
|
+
});
|
|
1947
|
+
keyInput.addEventListener("change", () => {
|
|
1948
|
+
state.key = keyInput.value.trim();
|
|
1949
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1950
|
+
refresh().catch(showError);
|
|
1951
|
+
});
|
|
1952
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
1953
|
+
refresh().catch(showError);
|
|
1954
|
+
});
|
|
1955
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
1956
|
+
const target = event.target;
|
|
1957
|
+
if (!(target instanceof Element))
|
|
1958
|
+
return;
|
|
1959
|
+
const button = target.closest("[data-collection]");
|
|
1960
|
+
if (!(button instanceof HTMLElement))
|
|
1961
|
+
return;
|
|
1962
|
+
const collection = button.dataset.collection;
|
|
1963
|
+
if (collection === void 0)
|
|
1964
|
+
return;
|
|
1965
|
+
state.collection = collection;
|
|
1966
|
+
renderState().catch(showError);
|
|
1967
|
+
});
|
|
1968
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
1969
|
+
const target = event.target;
|
|
1970
|
+
if (!(target instanceof Element))
|
|
1971
|
+
return;
|
|
1972
|
+
const row = target.closest("[data-id]");
|
|
1973
|
+
if (!(row instanceof HTMLElement))
|
|
1974
|
+
return;
|
|
1975
|
+
const id = row.dataset.id;
|
|
1976
|
+
if (id === void 0)
|
|
1977
|
+
return;
|
|
1978
|
+
openEditor(id).catch(showError);
|
|
1979
|
+
});
|
|
1980
|
+
const editor = el("editor", HTMLDialogElement);
|
|
1981
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
1982
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
1983
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
1984
|
+
async function openEditor(id) {
|
|
1985
|
+
state.editing = id;
|
|
1986
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
1987
|
+
editorId.value = id ?? "";
|
|
1988
|
+
editorId.readOnly = id !== null;
|
|
1989
|
+
editorDelete.hidden = id === null;
|
|
1990
|
+
if (id) {
|
|
1991
|
+
const record = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
1992
|
+
if (!isRecord2(record))
|
|
1993
|
+
throw new Error("Record response was not an object");
|
|
1994
|
+
editorValue.value = JSON.stringify(record.value, null, 2) ?? "";
|
|
1995
|
+
} else {
|
|
1996
|
+
editorValue.value = "{\n \n}";
|
|
1997
|
+
}
|
|
1998
|
+
editor.showModal();
|
|
1999
|
+
}
|
|
2000
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2001
|
+
openEditor(null).catch(showError);
|
|
2002
|
+
});
|
|
2003
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2004
|
+
const submitter = event.submitter;
|
|
2005
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2006
|
+
return;
|
|
2007
|
+
event.preventDefault();
|
|
2008
|
+
let value;
|
|
2009
|
+
try {
|
|
2010
|
+
value = readJson2(editorValue.value);
|
|
2011
|
+
} catch {
|
|
2012
|
+
showError(new Error("Value is not JSON"));
|
|
2013
|
+
return;
|
|
2014
|
+
}
|
|
2015
|
+
const id = editorId.value.trim();
|
|
2016
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2017
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2018
|
+
request.then(() => {
|
|
2019
|
+
editor.close();
|
|
2020
|
+
return renderState();
|
|
2021
|
+
}).catch(showError);
|
|
2022
|
+
});
|
|
2023
|
+
editorDelete.addEventListener("click", () => {
|
|
2024
|
+
const id = state.editing;
|
|
2025
|
+
if (!id)
|
|
2026
|
+
return;
|
|
2027
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2028
|
+
editor.close();
|
|
2029
|
+
return renderState();
|
|
2030
|
+
}).catch(showError);
|
|
2031
|
+
});
|
|
2032
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2033
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2034
|
+
continue;
|
|
2035
|
+
button.addEventListener("click", () => {
|
|
2036
|
+
const raw = button.dataset.advance;
|
|
2037
|
+
if (raw === void 0)
|
|
2038
|
+
return;
|
|
2039
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2043
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2044
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2045
|
+
});
|
|
2046
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2047
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2048
|
+
});
|
|
2049
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2050
|
+
event.preventDefault();
|
|
2051
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2052
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2053
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2054
|
+
});
|
|
2055
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2056
|
+
event.preventDefault();
|
|
2057
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2058
|
+
if (preset !== "") {
|
|
2059
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2063
|
+
if (!Number.isFinite(status)) {
|
|
2064
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2065
|
+
return;
|
|
2066
|
+
}
|
|
2067
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2068
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2069
|
+
api("POST", "/faults", {
|
|
2070
|
+
status,
|
|
2071
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2072
|
+
...method !== "" ? { method } : {}
|
|
2073
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2074
|
+
});
|
|
2075
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2076
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2077
|
+
});
|
|
2078
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2079
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2080
|
+
});
|
|
2081
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2082
|
+
const target = event.target;
|
|
2083
|
+
if (!(target instanceof Element))
|
|
2084
|
+
return;
|
|
2085
|
+
const button = target.closest("[data-route]");
|
|
2086
|
+
if (!(button instanceof HTMLElement))
|
|
2087
|
+
return;
|
|
2088
|
+
const route = button.dataset.route;
|
|
2089
|
+
if (route === void 0)
|
|
2090
|
+
return;
|
|
2091
|
+
state.route = route;
|
|
2092
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2093
|
+
const method = route.split(" ")[0] ?? "";
|
|
2094
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2095
|
+
});
|
|
2096
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2097
|
+
event.preventDefault();
|
|
2098
|
+
const send = async () => {
|
|
2099
|
+
if (state.route === null)
|
|
2100
|
+
throw new Error("Choose a route first");
|
|
2101
|
+
const parts = state.route.split(" ");
|
|
2102
|
+
const method = parts[0];
|
|
2103
|
+
const path = parts.slice(1).join(" ");
|
|
2104
|
+
if (method === void 0)
|
|
2105
|
+
throw new Error("Choose a route first");
|
|
2106
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
|
|
2107
|
+
let body;
|
|
2108
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2109
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2110
|
+
try {
|
|
2111
|
+
body = readJson2(routeBody.value);
|
|
2112
|
+
} catch {
|
|
2113
|
+
throw new Error("Body is not JSON");
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
const data = await api(method, concrete, body);
|
|
2117
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2118
|
+
};
|
|
2119
|
+
send().catch(showError);
|
|
2120
|
+
});
|
|
2121
|
+
const decodePanel = (value) => {
|
|
2122
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2123
|
+
return void 0;
|
|
2124
|
+
}
|
|
2125
|
+
const panel = {
|
|
2126
|
+
id: value.id,
|
|
2127
|
+
title: value.title,
|
|
2128
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2129
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2130
|
+
};
|
|
2131
|
+
if (typeof value.script === "string")
|
|
2132
|
+
panel.script = value.script;
|
|
2133
|
+
return panel;
|
|
2134
|
+
};
|
|
2135
|
+
const mountPanels = (panels) => {
|
|
2136
|
+
const nav = el("nav", HTMLElement);
|
|
2137
|
+
const views = el("views", HTMLElement);
|
|
2138
|
+
for (const panel of panels) {
|
|
2139
|
+
const button = document.createElement("button");
|
|
2140
|
+
button.type = "button";
|
|
2141
|
+
button.dataset.view = panel.id;
|
|
2142
|
+
button.textContent = panel.title;
|
|
2143
|
+
nav.append(button);
|
|
2144
|
+
const section = document.createElement("section");
|
|
2145
|
+
section.className = "view";
|
|
2146
|
+
section.id = `view-${panel.id}`;
|
|
2147
|
+
section.hidden = true;
|
|
2148
|
+
const title = document.createElement("h2");
|
|
2149
|
+
title.textContent = panel.title;
|
|
2150
|
+
const lede = document.createElement("p");
|
|
2151
|
+
lede.className = "lede";
|
|
2152
|
+
lede.textContent = panel.description;
|
|
2153
|
+
const body = document.createElement("div");
|
|
2154
|
+
body.className = "panel-body";
|
|
2155
|
+
body.id = `panel-${panel.id}`;
|
|
2156
|
+
body.innerHTML = panel.html;
|
|
2157
|
+
section.append(title, lede, body);
|
|
2158
|
+
views.append(section);
|
|
2159
|
+
if (panel.script === void 0)
|
|
2160
|
+
continue;
|
|
2161
|
+
try {
|
|
2162
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2163
|
+
if (!isPanelScript(compiled))
|
|
2164
|
+
throw new Error("panel script did not compile");
|
|
2165
|
+
compiled(body, panelApi);
|
|
2166
|
+
} catch (error) {
|
|
2167
|
+
const note = document.createElement("p");
|
|
2168
|
+
note.className = "banner show";
|
|
2169
|
+
note.textContent = error instanceof Error ? error.message : String(error);
|
|
2170
|
+
body.append(note);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
};
|
|
2174
|
+
startAdminBrand({
|
|
2175
|
+
document,
|
|
2176
|
+
$: (id) => document.getElementById(id),
|
|
2177
|
+
params,
|
|
2178
|
+
location: { href: location.href, origin: location.origin },
|
|
2179
|
+
fetch,
|
|
2180
|
+
brandsUrl: config.brandsUrl
|
|
2181
|
+
});
|
|
2182
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2183
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2184
|
+
const decoded = decodePanel(panel);
|
|
2185
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2186
|
+
});
|
|
2187
|
+
mountPanels(panels);
|
|
2188
|
+
return refresh();
|
|
2189
|
+
}).catch(showError);
|
|
2190
|
+
}
|
|
2191
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2192
|
+
var adminClientSource = (config) => {
|
|
2193
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2194
|
+
return `<script>
|
|
2195
|
+
${clientPrelude}
|
|
2196
|
+
bootAdmin(${payload});
|
|
2197
|
+
</script>`;
|
|
2198
|
+
};
|
|
2199
|
+
|
|
2200
|
+
// ../core/dist/surface.js
|
|
2201
|
+
var defineMock = (runtime) => runtime;
|
|
2202
|
+
var STANDARD_ADMIN_ROUTES = [
|
|
2203
|
+
"GET /",
|
|
2204
|
+
"POST /reset",
|
|
2205
|
+
"GET /namespaces",
|
|
2206
|
+
"GET /clock",
|
|
2207
|
+
"POST /clock",
|
|
2208
|
+
"GET /faults",
|
|
2209
|
+
"POST /faults",
|
|
2210
|
+
"DELETE /faults",
|
|
2211
|
+
"POST /snapshots",
|
|
2212
|
+
"POST /snapshots/:id/restore",
|
|
2213
|
+
"DELETE /snapshots/:id",
|
|
2214
|
+
"GET /timeline",
|
|
2215
|
+
"POST /checkpoints",
|
|
2216
|
+
"POST /branches/:name",
|
|
2217
|
+
"POST /branches/:name/checkout",
|
|
2218
|
+
"GET /requests",
|
|
2219
|
+
"DELETE /requests",
|
|
2220
|
+
"GET /metrics",
|
|
2221
|
+
"DELETE /metrics",
|
|
2222
|
+
"GET /credentials",
|
|
2223
|
+
"PUT /credentials",
|
|
2224
|
+
"DELETE /credentials",
|
|
2225
|
+
"GET /state",
|
|
2226
|
+
"GET /state/:collection",
|
|
2227
|
+
"GET /state/:collection/:id",
|
|
2228
|
+
"POST /state/:collection",
|
|
2229
|
+
"PUT /state/:collection/:id",
|
|
2230
|
+
"PATCH /state/:collection/:id",
|
|
2231
|
+
"DELETE /state/:collection/:id",
|
|
2232
|
+
"GET /ui",
|
|
2233
|
+
"GET /ui/",
|
|
2234
|
+
"GET /ui/manifest"
|
|
2235
|
+
];
|
|
2236
|
+
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2237
|
+
var assertAdminUi = (ui) => {
|
|
2238
|
+
if (!ui?.panels)
|
|
2239
|
+
return;
|
|
2240
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2241
|
+
for (const panel of ui.panels) {
|
|
2242
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2243
|
+
throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2244
|
+
}
|
|
2245
|
+
if (seen.has(panel.id))
|
|
2246
|
+
throw new RangeError(`duplicate admin panel id ${panel.id}`);
|
|
2247
|
+
seen.add(panel.id);
|
|
2248
|
+
if (panel.title.trim() === "")
|
|
2249
|
+
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2250
|
+
}
|
|
2251
|
+
};
|
|
2252
|
+
|
|
2253
|
+
// ../core/dist/admin-ui.js
|
|
2254
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
2255
|
+
switch (char) {
|
|
2256
|
+
case "&":
|
|
2257
|
+
return "&";
|
|
2258
|
+
case "<":
|
|
2259
|
+
return "<";
|
|
2260
|
+
case ">":
|
|
2261
|
+
return ">";
|
|
2262
|
+
case '"':
|
|
2263
|
+
return """;
|
|
2264
|
+
default:
|
|
2265
|
+
return "'";
|
|
2266
|
+
}
|
|
2267
|
+
});
|
|
2268
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
2269
|
+
var renderAdminDocument = (service) => {
|
|
2270
|
+
const name = escapeHtml(service);
|
|
2271
|
+
const script = adminClientSource({
|
|
2272
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2273
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2274
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2275
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2276
|
+
service
|
|
2277
|
+
});
|
|
2278
|
+
return `<!DOCTYPE html>
|
|
2279
|
+
<html lang="en">
|
|
2280
|
+
<head>
|
|
2281
|
+
<meta charset="utf-8">
|
|
2282
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2283
|
+
<meta name="color-scheme" content="light dark">
|
|
2284
|
+
<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">
|
|
2285
|
+
<title>${name} admin</title>
|
|
2286
|
+
<style>
|
|
2287
|
+
${CSS_RESET}
|
|
2288
|
+
:root {
|
|
2289
|
+
color-scheme: light;
|
|
2290
|
+
--bg: #fafafa;
|
|
2291
|
+
--bg-elev: #ffffff;
|
|
2292
|
+
--bg-muted: #f4f4f5;
|
|
2293
|
+
--bg-inset: #f4f4f5;
|
|
2294
|
+
--line: #dedee3;
|
|
2295
|
+
--line-strong: #c4c4cc;
|
|
2296
|
+
--ink: #18181b;
|
|
2297
|
+
--muted: #62626b;
|
|
2298
|
+
--faint: #71717a;
|
|
2299
|
+
--accent: #27272a;
|
|
2300
|
+
--accent-ink: #ffffff;
|
|
2301
|
+
--accent-soft: #f4f4f5;
|
|
2302
|
+
--ok: #166534;
|
|
2303
|
+
--ok-soft: #f0fdf4;
|
|
2304
|
+
--warn: #a16207;
|
|
2305
|
+
--warn-soft: #fefce8;
|
|
2306
|
+
--err: #a82d32;
|
|
2307
|
+
--err-soft: #fef2f2;
|
|
2308
|
+
--shadow: none;
|
|
2309
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2310
|
+
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
2311
|
+
--radius: 10px;
|
|
2312
|
+
--header: 56px;
|
|
2313
|
+
--nav: 200px;
|
|
2314
|
+
}
|
|
2315
|
+
:root[data-theme="dark"] {
|
|
2316
|
+
color-scheme: dark;
|
|
2317
|
+
--bg: #111113;
|
|
2318
|
+
--bg-elev: #19191c;
|
|
2319
|
+
--bg-muted: #242428;
|
|
2320
|
+
--bg-inset: #111113;
|
|
2321
|
+
--line: #36363c;
|
|
2322
|
+
--line-strong: #52525b;
|
|
2323
|
+
--ink: #f4f4f5;
|
|
2324
|
+
--muted: #a9a9b2;
|
|
2325
|
+
--faint: #71717a;
|
|
2326
|
+
--accent: #e4e4e7;
|
|
2327
|
+
--accent-ink: #18181b;
|
|
2328
|
+
--accent-soft: #242428;
|
|
2329
|
+
--ok: #86efac;
|
|
2330
|
+
--ok-soft: #14241b;
|
|
2331
|
+
--warn: #fde68a;
|
|
2332
|
+
--warn-soft: #2a2410;
|
|
2333
|
+
--err: #ffaaaa;
|
|
2334
|
+
--err-soft: #2c1516;
|
|
2335
|
+
--shadow: none;
|
|
2336
|
+
}
|
|
2337
|
+
@media (prefers-color-scheme: dark) {
|
|
2338
|
+
:root:not([data-theme="light"]) {
|
|
2339
|
+
color-scheme: dark;
|
|
2340
|
+
--bg: #111113;
|
|
2341
|
+
--bg-elev: #19191c;
|
|
2342
|
+
--bg-muted: #242428;
|
|
2343
|
+
--bg-inset: #111113;
|
|
2344
|
+
--line: #36363c;
|
|
2345
|
+
--line-strong: #52525b;
|
|
2346
|
+
--ink: #f4f4f5;
|
|
2347
|
+
--muted: #a9a9b2;
|
|
2348
|
+
--faint: #71717a;
|
|
2349
|
+
--accent: #e4e4e7;
|
|
2350
|
+
--accent-ink: #18181b;
|
|
2351
|
+
--accent-soft: #242428;
|
|
2352
|
+
--ok: #86efac;
|
|
2353
|
+
--ok-soft: #14241b;
|
|
2354
|
+
--warn: #fde68a;
|
|
2355
|
+
--warn-soft: #2a2410;
|
|
2356
|
+
--err: #ffaaaa;
|
|
2357
|
+
--err-soft: #2c1516;
|
|
2358
|
+
--shadow: none;
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2362
|
+
html { height: 100%; }
|
|
2363
|
+
body {
|
|
2364
|
+
margin: 0;
|
|
2365
|
+
min-height: 100%;
|
|
2366
|
+
display: flex;
|
|
2367
|
+
flex-direction: column;
|
|
2368
|
+
font-family: var(--sans);
|
|
2369
|
+
background: var(--bg);
|
|
2370
|
+
color: var(--ink);
|
|
2371
|
+
line-height: 1.45;
|
|
2372
|
+
padding-left: env(safe-area-inset-left);
|
|
2373
|
+
padding-right: env(safe-area-inset-right);
|
|
2374
|
+
-webkit-text-size-adjust: 100%;
|
|
2375
|
+
}
|
|
2376
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
2377
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
2378
|
+
header.top {
|
|
2379
|
+
position: sticky; top: 0; z-index: 5;
|
|
2380
|
+
display: flex; align-items: center; gap: 12px;
|
|
2381
|
+
min-height: var(--header); padding: 10px 16px;
|
|
2382
|
+
background: var(--bg-elev);
|
|
2383
|
+
border-bottom: 1px solid var(--line);
|
|
2384
|
+
min-width: 0; max-width: 100%;
|
|
2385
|
+
}
|
|
2386
|
+
.brand {
|
|
2387
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2388
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2389
|
+
}
|
|
2390
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2391
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2392
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2393
|
+
.vendor {
|
|
2394
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2395
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2396
|
+
}
|
|
2397
|
+
.vendor[hidden] { display: none; }
|
|
2398
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2399
|
+
.vendor img {
|
|
2400
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2401
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2402
|
+
}
|
|
2403
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2404
|
+
.vendor-sep { color: var(--faint); }
|
|
2405
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2406
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
2407
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
2408
|
+
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
2409
|
+
label.field input, label.field select, .controls input[type="password"] {
|
|
2410
|
+
background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
|
|
2411
|
+
padding: 7px 8px; min-height: 36px;
|
|
2412
|
+
}
|
|
2413
|
+
.icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
|
|
2414
|
+
border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
|
|
2415
|
+
background: var(--bg-elev);
|
|
2416
|
+
}
|
|
2417
|
+
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
|
|
2418
|
+
.btn-quiet { background: transparent; }
|
|
2419
|
+
.btn-danger { color: var(--err); }
|
|
2420
|
+
/* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
|
|
2421
|
+
record or the full nav row would widen the page past the viewport. */
|
|
2422
|
+
.layout {
|
|
2423
|
+
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
2424
|
+
flex: 1 0 auto; min-width: 0;
|
|
2425
|
+
}
|
|
2426
|
+
nav.side {
|
|
2427
|
+
border-right: 1px solid var(--line); padding: 12px;
|
|
2428
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2429
|
+
background: var(--bg-elev);
|
|
2430
|
+
}
|
|
2431
|
+
nav.side button {
|
|
2432
|
+
text-align: left; border: 0; background: transparent; border-radius: 9px;
|
|
2433
|
+
padding: 9px 10px; min-height: 40px; color: var(--muted);
|
|
2434
|
+
}
|
|
2435
|
+
nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
|
2436
|
+
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
2437
|
+
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
2438
|
+
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
2439
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2440
|
+
.card {
|
|
2441
|
+
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
2442
|
+
padding: 14px 16px; box-shadow: var(--shadow);
|
|
2443
|
+
}
|
|
2444
|
+
.card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
2445
|
+
.card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
2446
|
+
.card .v .clock-time { font-size: 14px; color: var(--muted); }
|
|
2447
|
+
.split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
|
|
2448
|
+
.collection {
|
|
2449
|
+
width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
|
|
2450
|
+
border-radius: 10px; padding: 8px 10px; min-height: 44px;
|
|
2451
|
+
}
|
|
2452
|
+
.collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
|
|
2453
|
+
.collection small { display: block; color: var(--faint); }
|
|
2454
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
|
|
2455
|
+
.chip {
|
|
2456
|
+
font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
|
|
2457
|
+
border-radius: 999px; padding: 4px 8px;
|
|
2458
|
+
}
|
|
2459
|
+
.chip i { color: var(--faint); font-style: normal; }
|
|
2460
|
+
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2461
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2462
|
+
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
2463
|
+
tr.clickable { cursor: pointer; }
|
|
2464
|
+
tr.clickable:hover { background: var(--bg-muted); }
|
|
2465
|
+
pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
2466
|
+
pre {
|
|
2467
|
+
margin: 0; white-space: pre-wrap; word-break: break-word;
|
|
2468
|
+
background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
|
|
2469
|
+
}
|
|
2470
|
+
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
|
|
2471
|
+
.banner {
|
|
2472
|
+
display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
|
|
2473
|
+
background: var(--err-soft); color: var(--err);
|
|
2474
|
+
}
|
|
2475
|
+
.banner.show { display: block; }
|
|
2476
|
+
.empty { color: var(--muted); padding: 24px 8px; }
|
|
2477
|
+
dialog {
|
|
2478
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2479
|
+
color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
|
|
2480
|
+
}
|
|
2481
|
+
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
2482
|
+
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
2483
|
+
textarea {
|
|
2484
|
+
width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
|
|
2485
|
+
border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
|
|
2486
|
+
font-family: var(--mono); font-size: 12px;
|
|
2487
|
+
}
|
|
2488
|
+
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
2489
|
+
.badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
|
|
2490
|
+
.badge.ok { background: var(--ok-soft); color: var(--ok); }
|
|
2491
|
+
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
|
2492
|
+
.status-2 { color: var(--ok); }
|
|
2493
|
+
.status-4, .status-5, .status-0 { color: var(--err); }
|
|
2494
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
2495
|
+
.route {
|
|
2496
|
+
display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
|
|
2497
|
+
padding: 8px 0; border-bottom: 1px solid var(--line);
|
|
2498
|
+
}
|
|
2499
|
+
.method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
|
|
2500
|
+
@media (max-width: 800px) {
|
|
2501
|
+
header.top {
|
|
2502
|
+
align-items: stretch; flex-direction: column;
|
|
2503
|
+
padding-top: max(10px, env(safe-area-inset-top));
|
|
2504
|
+
}
|
|
2505
|
+
input, select, textarea { font-size: 16px; }
|
|
2506
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
2507
|
+
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
2508
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
2509
|
+
nav.side {
|
|
2510
|
+
flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
|
|
2511
|
+
border-right: 0; border-bottom: 1px solid var(--line);
|
|
2512
|
+
padding: 8px;
|
|
2513
|
+
}
|
|
2514
|
+
nav.side button { white-space: nowrap; flex: none; }
|
|
2515
|
+
.split { grid-template-columns: minmax(0, 1fr); }
|
|
2516
|
+
main { padding: 14px; }
|
|
2517
|
+
table, thead, tbody, tr, th, td { display: block; }
|
|
2518
|
+
thead { display: none; }
|
|
2519
|
+
tr {
|
|
2520
|
+
border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
|
|
2521
|
+
background: var(--bg-elev); min-width: 0;
|
|
2522
|
+
}
|
|
2523
|
+
td {
|
|
2524
|
+
border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
|
|
2525
|
+
min-width: 0; overflow-wrap: anywhere;
|
|
2526
|
+
}
|
|
2527
|
+
td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
|
|
2528
|
+
.route { grid-template-columns: 72px 1fr; }
|
|
2529
|
+
.route button { grid-column: 1 / -1; }
|
|
2530
|
+
}
|
|
2531
|
+
</style>
|
|
2532
|
+
</head>
|
|
2533
|
+
<body>
|
|
2534
|
+
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
2535
|
+
<header class="top">
|
|
2536
|
+
<div class="brand">
|
|
2537
|
+
<div class="brand-id">
|
|
2538
|
+
<strong>${name}</strong>
|
|
2539
|
+
<span>Admin</span>
|
|
2540
|
+
</div>
|
|
2541
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
2542
|
+
</div>
|
|
2543
|
+
<div class="controls">
|
|
2544
|
+
<label class="field">Namespace
|
|
2545
|
+
<select id="namespace" aria-label="Namespace"></select>
|
|
2546
|
+
</label>
|
|
2547
|
+
<label class="field">Admin key
|
|
2548
|
+
<input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
|
|
2549
|
+
</label>
|
|
2550
|
+
<button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
|
|
2551
|
+
<button class="btn" id="refresh" type="button">Refresh</button>
|
|
2552
|
+
</div>
|
|
2553
|
+
</header>
|
|
2554
|
+
<div class="layout">
|
|
2555
|
+
<nav class="side" id="nav" aria-label="Admin sections">
|
|
2556
|
+
<button type="button" data-view="overview" aria-current="true">Overview</button>
|
|
2557
|
+
<button type="button" data-view="state">State</button>
|
|
2558
|
+
<button type="button" data-view="clock">Clock</button>
|
|
2559
|
+
<button type="button" data-view="faults">Faults</button>
|
|
2560
|
+
<button type="button" data-view="journal">Journal</button>
|
|
2561
|
+
<button type="button" data-view="routes">Routes</button>
|
|
2562
|
+
</nav>
|
|
2563
|
+
<main id="views">
|
|
2564
|
+
<p class="banner" id="banner" role="alert"></p>
|
|
2565
|
+
<section class="view" id="view-overview">
|
|
2566
|
+
<h2>Overview</h2>
|
|
2567
|
+
<p class="lede">Health, clock, and the collections this namespace is holding.</p>
|
|
2568
|
+
<div class="grid" id="overview-cards"></div>
|
|
2569
|
+
<h3>Recent requests</h3>
|
|
2570
|
+
<div id="overview-requests"></div>
|
|
2571
|
+
</section>
|
|
2572
|
+
<section class="view" id="view-state" hidden>
|
|
2573
|
+
<h2>State</h2>
|
|
2574
|
+
<p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
|
|
2575
|
+
<div class="split">
|
|
2576
|
+
<div id="collections"></div>
|
|
2577
|
+
<div>
|
|
2578
|
+
<div id="schema"></div>
|
|
2579
|
+
<div class="row-actions">
|
|
2580
|
+
<button class="btn-primary" id="new-record" type="button">New record</button>
|
|
2581
|
+
</div>
|
|
2582
|
+
<div id="records"></div>
|
|
2583
|
+
</div>
|
|
2584
|
+
</div>
|
|
2585
|
+
</section>
|
|
2586
|
+
<section class="view" id="view-clock" hidden>
|
|
2587
|
+
<h2>Clock</h2>
|
|
2588
|
+
<p class="lede">The clock every timestamp in this mock reads.</p>
|
|
2589
|
+
<div class="card" id="clock-readout"></div>
|
|
2590
|
+
<div class="row-actions">
|
|
2591
|
+
<button class="btn" type="button" data-advance="60000">+1m</button>
|
|
2592
|
+
<button class="btn" type="button" data-advance="900000">+15m</button>
|
|
2593
|
+
<button class="btn" type="button" data-advance="3600000">+1h</button>
|
|
2594
|
+
<button class="btn" type="button" data-advance="86400000">+1d</button>
|
|
2595
|
+
<button class="btn" type="button" data-advance="-3600000">\u22121h</button>
|
|
2596
|
+
<button class="btn" id="freeze" type="button">Freeze</button>
|
|
2597
|
+
<button class="btn-quiet" id="clock-reset" type="button">Reset</button>
|
|
2598
|
+
</div>
|
|
2599
|
+
<form id="clock-set" class="row-actions">
|
|
2600
|
+
<label class="field">Set instant
|
|
2601
|
+
<input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
|
|
2602
|
+
</label>
|
|
2603
|
+
<button class="btn-primary" type="submit">Set</button>
|
|
2604
|
+
</form>
|
|
2605
|
+
</section>
|
|
2606
|
+
<section class="view" id="view-faults" hidden>
|
|
2607
|
+
<h2>Faults</h2>
|
|
2608
|
+
<p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
|
|
2609
|
+
<form id="fault-form" class="card stack">
|
|
2610
|
+
<label class="field">Preset
|
|
2611
|
+
<select id="fault-preset"><option value="">Custom rule</option></select>
|
|
2612
|
+
</label>
|
|
2613
|
+
<label class="field">Status
|
|
2614
|
+
<input id="fault-status" inputmode="numeric" placeholder="503">
|
|
2615
|
+
</label>
|
|
2616
|
+
<label class="field">Path prefix
|
|
2617
|
+
<input id="fault-path" placeholder="/v1">
|
|
2618
|
+
</label>
|
|
2619
|
+
<label class="field">Method
|
|
2620
|
+
<input id="fault-method" placeholder="GET">
|
|
2621
|
+
</label>
|
|
2622
|
+
<div class="dialog-actions">
|
|
2623
|
+
<button class="btn-primary" type="submit">Add fault</button>
|
|
2624
|
+
<button class="btn-danger" id="fault-clear" type="button">Clear all</button>
|
|
2625
|
+
</div>
|
|
2626
|
+
</form>
|
|
2627
|
+
<div id="fault-list"></div>
|
|
2628
|
+
</section>
|
|
2629
|
+
<section class="view" id="view-journal" hidden>
|
|
2630
|
+
<h2>Journal</h2>
|
|
2631
|
+
<p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
|
|
2632
|
+
<div class="row-actions">
|
|
2633
|
+
<button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
|
|
2634
|
+
</div>
|
|
2635
|
+
<div id="journal"></div>
|
|
2636
|
+
</section>
|
|
2637
|
+
<section class="view" id="view-routes" hidden>
|
|
2638
|
+
<h2>Routes</h2>
|
|
2639
|
+
<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>
|
|
2640
|
+
<div id="route-list"></div>
|
|
2641
|
+
<form id="route-form" class="card stack">
|
|
2642
|
+
<strong id="route-title">Select a route</strong>
|
|
2643
|
+
<label class="field">JSON body
|
|
2644
|
+
<textarea id="route-body" placeholder="{ }"></textarea>
|
|
2645
|
+
</label>
|
|
2646
|
+
<div class="dialog-actions">
|
|
2647
|
+
<button class="btn-primary" type="submit">Send</button>
|
|
2648
|
+
</div>
|
|
2649
|
+
<pre id="route-result">Response will show here.</pre>
|
|
2650
|
+
</form>
|
|
2651
|
+
</section>
|
|
2652
|
+
</main>
|
|
2653
|
+
</div>
|
|
2654
|
+
</div>
|
|
2655
|
+
<dialog id="editor">
|
|
2656
|
+
<form method="dialog" id="editor-form">
|
|
2657
|
+
<strong id="editor-title">Record</strong>
|
|
2658
|
+
<label class="field">Id
|
|
2659
|
+
<input id="editor-id" required>
|
|
2660
|
+
</label>
|
|
2661
|
+
<label class="field">JSON value
|
|
2662
|
+
<textarea id="editor-value"></textarea>
|
|
2663
|
+
</label>
|
|
2664
|
+
<div class="dialog-actions">
|
|
2665
|
+
<button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
|
|
2666
|
+
<button class="btn-quiet" type="submit" value="cancel">Cancel</button>
|
|
2667
|
+
<button class="btn-primary" type="submit" value="save">Save</button>
|
|
2668
|
+
</div>
|
|
2669
|
+
</form>
|
|
2670
|
+
</dialog>
|
|
2671
|
+
${script}
|
|
2672
|
+
</body>
|
|
2673
|
+
</html>`;
|
|
2674
|
+
};
|
|
2675
|
+
var htmlResponse = (body) => new Response(body, {
|
|
2676
|
+
status: 200,
|
|
2677
|
+
headers: {
|
|
2678
|
+
"content-type": "text/html; charset=utf-8",
|
|
2679
|
+
"cache-control": "no-store"
|
|
2680
|
+
}
|
|
2681
|
+
});
|
|
2682
|
+
var json2 = (body) => new Response(JSON.stringify(body), {
|
|
2683
|
+
status: 200,
|
|
2684
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
2685
|
+
});
|
|
2686
|
+
var adminUiRoutes = (service, ui) => {
|
|
2687
|
+
const shell = () => renderAdminDocument(service);
|
|
2688
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
2689
|
+
return {
|
|
2690
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
2691
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
2692
|
+
"GET /ui/manifest": () => json2({
|
|
2693
|
+
service,
|
|
2694
|
+
panels: (ui?.panels ?? []).map((panel) => ({
|
|
2695
|
+
id: panel.id,
|
|
2696
|
+
title: panel.title,
|
|
2697
|
+
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
2698
|
+
html: panel.html,
|
|
2699
|
+
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
2700
|
+
}))
|
|
2701
|
+
})
|
|
2702
|
+
};
|
|
2703
|
+
};
|
|
2704
|
+
|
|
972
2705
|
// ../../../node_modules/.bun/hono@4.11.9/node_modules/hono/dist/request/constants.js
|
|
973
2706
|
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
974
2707
|
|
|
@@ -1436,8 +3169,442 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
|
|
|
1436
3169
|
});
|
|
1437
3170
|
};
|
|
1438
3171
|
|
|
3172
|
+
// ../core/dist/state-view.js
|
|
3173
|
+
var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
|
|
3174
|
+
var RECORD_ID = /^[^\s/]{1,256}$/;
|
|
3175
|
+
var SAMPLE = 25;
|
|
3176
|
+
var WALK_LIMIT = 1e4;
|
|
3177
|
+
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
3178
|
+
var fail = (status, message) => ({ ok: false, status, message });
|
|
3179
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3180
|
+
var kindOf = (value) => {
|
|
3181
|
+
if (value === null)
|
|
3182
|
+
return "null";
|
|
3183
|
+
if (Array.isArray(value))
|
|
3184
|
+
return "array";
|
|
3185
|
+
switch (typeof value) {
|
|
3186
|
+
case "string":
|
|
3187
|
+
return "string";
|
|
3188
|
+
case "number":
|
|
3189
|
+
return Number.isFinite(value) ? "number" : "unknown";
|
|
3190
|
+
case "boolean":
|
|
3191
|
+
return "boolean";
|
|
3192
|
+
case "object":
|
|
3193
|
+
return "object";
|
|
3194
|
+
default:
|
|
3195
|
+
return "unknown";
|
|
3196
|
+
}
|
|
3197
|
+
};
|
|
3198
|
+
var humanize = (name) => {
|
|
3199
|
+
const words = name.replace(/[@:_-]+/g, " ").trim();
|
|
3200
|
+
if (words === "")
|
|
3201
|
+
return name;
|
|
3202
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3203
|
+
};
|
|
3204
|
+
var jsonValue = (value) => {
|
|
3205
|
+
if (value === void 0)
|
|
3206
|
+
return fail(400, "value is required");
|
|
3207
|
+
try {
|
|
3208
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
3209
|
+
} catch {
|
|
3210
|
+
return fail(400, "value must be JSON");
|
|
3211
|
+
}
|
|
3212
|
+
};
|
|
3213
|
+
var ctorName = (value) => {
|
|
3214
|
+
const ctor = value.constructor;
|
|
3215
|
+
return typeof ctor?.name === "string" ? ctor.name : "";
|
|
3216
|
+
};
|
|
3217
|
+
var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
|
|
3218
|
+
var discoverCollections = (root) => {
|
|
3219
|
+
const found = [];
|
|
3220
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3221
|
+
const visit = (value, depth) => {
|
|
3222
|
+
if (found.length + seen.size > WALK_LIMIT)
|
|
3223
|
+
return;
|
|
3224
|
+
if (value === null || typeof value !== "object")
|
|
3225
|
+
return;
|
|
3226
|
+
if (seen.has(value))
|
|
3227
|
+
return;
|
|
3228
|
+
seen.add(value);
|
|
3229
|
+
if (value instanceof Collection) {
|
|
3230
|
+
found.push(value);
|
|
3231
|
+
return;
|
|
3232
|
+
}
|
|
3233
|
+
if (value instanceof Map) {
|
|
3234
|
+
for (const child of value.values())
|
|
3235
|
+
visit(child, depth + 1);
|
|
3236
|
+
return;
|
|
3237
|
+
}
|
|
3238
|
+
if (value instanceof Set) {
|
|
3239
|
+
for (const child of value.values())
|
|
3240
|
+
visit(child, depth + 1);
|
|
3241
|
+
return;
|
|
3242
|
+
}
|
|
3243
|
+
if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
|
|
3244
|
+
return;
|
|
3245
|
+
if (Array.isArray(value)) {
|
|
3246
|
+
const cap = Math.min(value.length, 32);
|
|
3247
|
+
for (let i = 0; i < cap; i++)
|
|
3248
|
+
visit(value[i], depth + 1);
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
3251
|
+
let children;
|
|
3252
|
+
try {
|
|
3253
|
+
children = Object.values(value);
|
|
3254
|
+
} catch {
|
|
3255
|
+
return;
|
|
3256
|
+
}
|
|
3257
|
+
for (const child of children)
|
|
3258
|
+
visit(child, depth + 1);
|
|
3259
|
+
};
|
|
3260
|
+
visit(root, 0);
|
|
3261
|
+
return found;
|
|
3262
|
+
};
|
|
3263
|
+
var storedNames = (sqlite, namespace) => {
|
|
3264
|
+
const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
|
|
3265
|
+
const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
|
|
3266
|
+
return [...records, ...sequences].map((row) => row.name);
|
|
3267
|
+
};
|
|
3268
|
+
var blankAccum = (name) => ({
|
|
3269
|
+
name,
|
|
3270
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
3271
|
+
present: 0,
|
|
3272
|
+
nested: /* @__PURE__ */ new Map()
|
|
3273
|
+
});
|
|
3274
|
+
var absorb = (accum, value) => {
|
|
3275
|
+
const kind = kindOf(value);
|
|
3276
|
+
accum.kinds.add(kind);
|
|
3277
|
+
accum.present++;
|
|
3278
|
+
if (!isRecord3(value))
|
|
3279
|
+
return;
|
|
3280
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3281
|
+
const nested = accum.nested.get(key) ?? blankAccum(key);
|
|
3282
|
+
absorb(nested, child);
|
|
3283
|
+
accum.nested.set(key, nested);
|
|
3284
|
+
}
|
|
3285
|
+
};
|
|
3286
|
+
var finishField = (accum, samples) => {
|
|
3287
|
+
const kinds = [...accum.kinds];
|
|
3288
|
+
const kind = kinds.length === 1 ? kinds[0] : "unknown";
|
|
3289
|
+
const field = {
|
|
3290
|
+
name: accum.name,
|
|
3291
|
+
kind,
|
|
3292
|
+
optional: accum.present < samples || kinds.includes("null")
|
|
3293
|
+
};
|
|
3294
|
+
if (accum.nested.size > 0) {
|
|
3295
|
+
field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
|
|
3296
|
+
}
|
|
3297
|
+
return field;
|
|
3298
|
+
};
|
|
3299
|
+
var inferFields = (records) => {
|
|
3300
|
+
if (records.length === 0)
|
|
3301
|
+
return [];
|
|
3302
|
+
const sample = records.slice(0, SAMPLE);
|
|
3303
|
+
const objects = sample.filter((record) => isRecord3(record.value));
|
|
3304
|
+
if (objects.length === 0) {
|
|
3305
|
+
const kinds = new Set(sample.map((record) => kindOf(record.value)));
|
|
3306
|
+
const list = [...kinds];
|
|
3307
|
+
return [
|
|
3308
|
+
{
|
|
3309
|
+
name: "(value)",
|
|
3310
|
+
kind: list.length === 1 ? list[0] : "unknown",
|
|
3311
|
+
optional: false
|
|
3312
|
+
}
|
|
3313
|
+
];
|
|
3314
|
+
}
|
|
3315
|
+
const root = /* @__PURE__ */ new Map();
|
|
3316
|
+
for (const record of objects) {
|
|
3317
|
+
for (const [key, value] of Object.entries(record.value)) {
|
|
3318
|
+
const accum = root.get(key) ?? blankAccum(key);
|
|
3319
|
+
absorb(accum, value);
|
|
3320
|
+
root.set(key, accum);
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
|
|
3324
|
+
};
|
|
3325
|
+
var mergeFields = (declared, inferred) => {
|
|
3326
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3327
|
+
for (const field of inferred)
|
|
3328
|
+
byName.set(field.name, field);
|
|
3329
|
+
const ordered = [];
|
|
3330
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3331
|
+
for (const field of declared ?? []) {
|
|
3332
|
+
const found = byName.get(field.name);
|
|
3333
|
+
seen.add(field.name);
|
|
3334
|
+
if (!found) {
|
|
3335
|
+
ordered.push({ ...field, optional: field.optional });
|
|
3336
|
+
continue;
|
|
3337
|
+
}
|
|
3338
|
+
ordered.push({
|
|
3339
|
+
...found,
|
|
3340
|
+
kind: field.kind === "unknown" ? found.kind : field.kind,
|
|
3341
|
+
optional: field.optional || found.optional,
|
|
3342
|
+
...field.description !== void 0 ? { description: field.description } : {},
|
|
3343
|
+
...field.meta !== void 0 ? { meta: field.meta } : {},
|
|
3344
|
+
...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
|
|
3345
|
+
});
|
|
3346
|
+
}
|
|
3347
|
+
for (const field of inferred) {
|
|
3348
|
+
if (!seen.has(field.name))
|
|
3349
|
+
ordered.push(field);
|
|
3350
|
+
}
|
|
3351
|
+
return ordered;
|
|
3352
|
+
};
|
|
3353
|
+
var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
|
|
3354
|
+
var readRecord = (collection, id) => {
|
|
3355
|
+
const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
|
|
3356
|
+
const row = rows.find((entry) => entry.id === id);
|
|
3357
|
+
return row ? { id: row.id, seq: row.seq, value: row.value } : void 0;
|
|
3358
|
+
};
|
|
3359
|
+
var inspectState = (scope) => {
|
|
3360
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3361
|
+
for (const declaration of scope.declarations ?? []) {
|
|
3362
|
+
if (COLLECTION_NAME.test(declaration.name))
|
|
3363
|
+
declared.set(declaration.name, declaration);
|
|
3364
|
+
}
|
|
3365
|
+
const names = new Set(declared.keys());
|
|
3366
|
+
for (const name of storedNames(scope.sqlite, scope.storageNamespace))
|
|
3367
|
+
names.add(name);
|
|
3368
|
+
for (const collection of discoverCollections(scope.root)) {
|
|
3369
|
+
if (collection.namespace === scope.storageNamespace)
|
|
3370
|
+
names.add(collection.collectionName);
|
|
3371
|
+
}
|
|
3372
|
+
const collections = [];
|
|
3373
|
+
for (const name of names) {
|
|
3374
|
+
if (!COLLECTION_NAME.test(name))
|
|
3375
|
+
continue;
|
|
3376
|
+
const declaration = declared.get(name);
|
|
3377
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3378
|
+
const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row) => ({ id: row.id, seq: row.seq, value: row.value }));
|
|
3379
|
+
const inferred = inferFields(records);
|
|
3380
|
+
const fields = mergeFields(declaration?.fields, inferred);
|
|
3381
|
+
const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
|
|
3382
|
+
collections.push({
|
|
3383
|
+
name,
|
|
3384
|
+
label: declaration?.label ?? humanize(name),
|
|
3385
|
+
...declaration?.description !== void 0 ? { description: declaration.description } : {},
|
|
3386
|
+
count: collection.count(),
|
|
3387
|
+
source,
|
|
3388
|
+
fields,
|
|
3389
|
+
...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
|
|
3390
|
+
});
|
|
3391
|
+
}
|
|
3392
|
+
const order = /* @__PURE__ */ new Map();
|
|
3393
|
+
for (const [index, item] of (scope.declarations ?? []).entries())
|
|
3394
|
+
order.set(item.name, index);
|
|
3395
|
+
collections.sort((a, b) => {
|
|
3396
|
+
const left = order.get(a.name);
|
|
3397
|
+
const right = order.get(b.name);
|
|
3398
|
+
if (left !== void 0 && right !== void 0)
|
|
3399
|
+
return left - right;
|
|
3400
|
+
if (left !== void 0)
|
|
3401
|
+
return -1;
|
|
3402
|
+
if (right !== void 0)
|
|
3403
|
+
return 1;
|
|
3404
|
+
return a.name.localeCompare(b.name);
|
|
3405
|
+
});
|
|
3406
|
+
return {
|
|
3407
|
+
namespace: scope.namespace,
|
|
3408
|
+
storageNamespace: scope.storageNamespace,
|
|
3409
|
+
collections
|
|
3410
|
+
};
|
|
3411
|
+
};
|
|
3412
|
+
var pageOf = (sqlite, storageNamespace, name, query) => {
|
|
3413
|
+
if (!COLLECTION_NAME.test(name))
|
|
3414
|
+
return fail(400, "collection name is not allowed");
|
|
3415
|
+
const limit = query.limit ?? 50;
|
|
3416
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
3417
|
+
return fail(400, "limit must be an integer from 1 to 200");
|
|
3418
|
+
}
|
|
3419
|
+
const order = query.order ?? "newest";
|
|
3420
|
+
if (order !== "newest" && order !== "oldest")
|
|
3421
|
+
return fail(400, 'order must be "newest" or "oldest"');
|
|
3422
|
+
const collection = collectionOf(sqlite, storageNamespace, name);
|
|
3423
|
+
const rows = collection.list({ order }).filter((row) => {
|
|
3424
|
+
if (query.after === void 0)
|
|
3425
|
+
return true;
|
|
3426
|
+
return order === "newest" ? row.seq < query.after : row.seq > query.after;
|
|
3427
|
+
});
|
|
3428
|
+
const slice = rows.slice(0, limit);
|
|
3429
|
+
const last = slice.at(-1);
|
|
3430
|
+
return {
|
|
3431
|
+
ok: true,
|
|
3432
|
+
value: {
|
|
3433
|
+
collection: name,
|
|
3434
|
+
count: collection.count(),
|
|
3435
|
+
records: slice.map((row) => ({ id: row.id, seq: row.seq, value: row.value })),
|
|
3436
|
+
next: rows.length > limit && last ? last.seq : null
|
|
3437
|
+
}
|
|
3438
|
+
};
|
|
3439
|
+
};
|
|
3440
|
+
var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
|
|
3441
|
+
var readStateRecord = (scope, name, id) => {
|
|
3442
|
+
if (!COLLECTION_NAME.test(name))
|
|
3443
|
+
return fail(400, "collection name is not allowed");
|
|
3444
|
+
if (!RECORD_ID.test(id))
|
|
3445
|
+
return fail(400, "record id is not allowed");
|
|
3446
|
+
const record = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
|
|
3447
|
+
return record ? { ok: true, value: record } : fail(404, `no record ${id} in ${name}`);
|
|
3448
|
+
};
|
|
3449
|
+
var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail(400, "id must be a single path segment");
|
|
3450
|
+
var createStateRecord = (scope, name, input) => {
|
|
3451
|
+
if (!COLLECTION_NAME.test(name))
|
|
3452
|
+
return fail(400, "collection name is not allowed");
|
|
3453
|
+
const parsed = jsonValue(input.value);
|
|
3454
|
+
if (!parsed.ok)
|
|
3455
|
+
return parsed;
|
|
3456
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3457
|
+
const id = input.id ?? `${name}_${collection.nextSequence()}`;
|
|
3458
|
+
const checked = requireId(id);
|
|
3459
|
+
if (!checked.ok)
|
|
3460
|
+
return checked;
|
|
3461
|
+
if (collection.has(checked.value))
|
|
3462
|
+
return fail(409, `record ${checked.value} already exists`);
|
|
3463
|
+
const stored = collection.insert(checked.value, parsed.value);
|
|
3464
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3465
|
+
};
|
|
3466
|
+
var replaceStateRecord = (scope, name, id, value) => {
|
|
3467
|
+
if (!COLLECTION_NAME.test(name))
|
|
3468
|
+
return fail(400, "collection name is not allowed");
|
|
3469
|
+
const checked = requireId(id);
|
|
3470
|
+
if (!checked.ok)
|
|
3471
|
+
return checked;
|
|
3472
|
+
const parsed = jsonValue(value);
|
|
3473
|
+
if (!parsed.ok)
|
|
3474
|
+
return parsed;
|
|
3475
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3476
|
+
if (!collection.has(checked.value))
|
|
3477
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3478
|
+
const stored = collection.update(checked.value, parsed.value);
|
|
3479
|
+
if (!stored)
|
|
3480
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3481
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3482
|
+
};
|
|
3483
|
+
var patchStateRecord = (scope, name, id, value) => {
|
|
3484
|
+
const current = readStateRecord(scope, name, id);
|
|
3485
|
+
if (!current.ok)
|
|
3486
|
+
return current;
|
|
3487
|
+
const parsed = jsonValue(value);
|
|
3488
|
+
if (!parsed.ok)
|
|
3489
|
+
return parsed;
|
|
3490
|
+
const next = isRecord3(current.value.value) && isRecord3(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
3491
|
+
return replaceStateRecord(scope, name, id, next);
|
|
3492
|
+
};
|
|
3493
|
+
var deleteStateRecord = (scope, name, id) => {
|
|
3494
|
+
if (!COLLECTION_NAME.test(name))
|
|
3495
|
+
return fail(400, "collection name is not allowed");
|
|
3496
|
+
const checked = requireId(id);
|
|
3497
|
+
if (!checked.ok)
|
|
3498
|
+
return checked;
|
|
3499
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3500
|
+
return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail(404, `no record ${checked.value} in ${name}`);
|
|
3501
|
+
};
|
|
3502
|
+
var json3 = (status, body) => new Response(JSON.stringify(body), {
|
|
3503
|
+
status,
|
|
3504
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3505
|
+
});
|
|
3506
|
+
var adminError2 = (status, message) => json3(status, { error: { type: "mockingbird_admin", message } });
|
|
3507
|
+
var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
|
|
3508
|
+
var integerParam = (value) => {
|
|
3509
|
+
if (value === null)
|
|
3510
|
+
return void 0;
|
|
3511
|
+
if (!/^-?\d+$/.test(value))
|
|
3512
|
+
return "bad";
|
|
3513
|
+
return Number(value);
|
|
3514
|
+
};
|
|
3515
|
+
var stateAdminRoutes = (routes) => {
|
|
3516
|
+
const open = (namespace) => {
|
|
3517
|
+
try {
|
|
3518
|
+
return { ok: true, value: routes.open(namespace) };
|
|
3519
|
+
} catch (error) {
|
|
3520
|
+
return fail(400, error instanceof Error ? error.message : String(error));
|
|
3521
|
+
}
|
|
3522
|
+
};
|
|
3523
|
+
const wrote = (namespace) => {
|
|
3524
|
+
routes.afterWrite?.(namespace);
|
|
3525
|
+
};
|
|
3526
|
+
return {
|
|
3527
|
+
"GET /state": ({ namespace }) => {
|
|
3528
|
+
const scope = open(namespace);
|
|
3529
|
+
return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
|
|
3530
|
+
},
|
|
3531
|
+
"GET /state/:collection": ({ namespace, params, url }) => {
|
|
3532
|
+
const scope = open(namespace);
|
|
3533
|
+
if (!scope.ok)
|
|
3534
|
+
return fromResult(scope, 200);
|
|
3535
|
+
const limit = integerParam(url.searchParams.get("limit"));
|
|
3536
|
+
const after = integerParam(url.searchParams.get("after"));
|
|
3537
|
+
if (limit === "bad")
|
|
3538
|
+
return adminError2(400, "limit: expected an integer");
|
|
3539
|
+
if (after === "bad")
|
|
3540
|
+
return adminError2(400, "after: expected a sequence number");
|
|
3541
|
+
const order = url.searchParams.get("order");
|
|
3542
|
+
return fromResult(readStatePage(scope.value, params.collection ?? "", {
|
|
3543
|
+
...limit !== void 0 ? { limit } : {},
|
|
3544
|
+
...after !== void 0 ? { after } : {},
|
|
3545
|
+
...order === "newest" || order === "oldest" ? { order } : {}
|
|
3546
|
+
}), 200);
|
|
3547
|
+
},
|
|
3548
|
+
"GET /state/:collection/:id": ({ namespace, params }) => {
|
|
3549
|
+
const scope = open(namespace);
|
|
3550
|
+
if (!scope.ok)
|
|
3551
|
+
return fromResult(scope, 200);
|
|
3552
|
+
return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
|
|
3553
|
+
},
|
|
3554
|
+
"POST /state/:collection": ({ namespace, params, body }) => {
|
|
3555
|
+
const scope = open(namespace);
|
|
3556
|
+
if (!scope.ok)
|
|
3557
|
+
return fromResult(scope, 201);
|
|
3558
|
+
if (!isRecord3(body) || !("value" in body)) {
|
|
3559
|
+
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
3560
|
+
}
|
|
3561
|
+
const id = body.id;
|
|
3562
|
+
if (id !== void 0 && typeof id !== "string")
|
|
3563
|
+
return adminError2(400, "id must be a string");
|
|
3564
|
+
const created = createStateRecord(scope.value, params.collection ?? "", {
|
|
3565
|
+
...typeof id === "string" ? { id } : {},
|
|
3566
|
+
value: body.value
|
|
3567
|
+
});
|
|
3568
|
+
if (created.ok)
|
|
3569
|
+
wrote(namespace);
|
|
3570
|
+
return fromResult(created, 201);
|
|
3571
|
+
},
|
|
3572
|
+
"PUT /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3573
|
+
const scope = open(namespace);
|
|
3574
|
+
if (!scope.ok)
|
|
3575
|
+
return fromResult(scope, 200);
|
|
3576
|
+
if (!isRecord3(body) || !("value" in body))
|
|
3577
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3578
|
+
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3579
|
+
if (replaced.ok)
|
|
3580
|
+
wrote(namespace);
|
|
3581
|
+
return fromResult(replaced, 200);
|
|
3582
|
+
},
|
|
3583
|
+
"PATCH /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3584
|
+
const scope = open(namespace);
|
|
3585
|
+
if (!scope.ok)
|
|
3586
|
+
return fromResult(scope, 200);
|
|
3587
|
+
if (!isRecord3(body) || !("value" in body))
|
|
3588
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3589
|
+
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3590
|
+
if (patched.ok)
|
|
3591
|
+
wrote(namespace);
|
|
3592
|
+
return fromResult(patched, 200);
|
|
3593
|
+
},
|
|
3594
|
+
"DELETE /state/:collection/:id": ({ namespace, params }) => {
|
|
3595
|
+
const scope = open(namespace);
|
|
3596
|
+
if (!scope.ok)
|
|
3597
|
+
return fromResult(scope, 200);
|
|
3598
|
+
const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
|
|
3599
|
+
if (removed.ok)
|
|
3600
|
+
wrote(namespace);
|
|
3601
|
+
return fromResult(removed, 200);
|
|
3602
|
+
}
|
|
3603
|
+
};
|
|
3604
|
+
};
|
|
3605
|
+
|
|
1439
3606
|
// ../core/dist/version.js
|
|
1440
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3607
|
+
var PACKAGE_VERSION = true ? "1.5.0" : UNRELEASED_VERSION;
|
|
1441
3608
|
|
|
1442
3609
|
// ../core/dist/signing.js
|
|
1443
3610
|
var encoder = new TextEncoder();
|
|
@@ -1772,11 +3939,11 @@ var createWebhookHub = (options) => {
|
|
|
1772
3939
|
};
|
|
1773
3940
|
return hub;
|
|
1774
3941
|
};
|
|
1775
|
-
var
|
|
1776
|
-
var
|
|
1777
|
-
var
|
|
3942
|
+
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
3943
|
+
var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
|
|
3944
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1778
3945
|
var parseEndpoint = (value) => {
|
|
1779
|
-
if (!
|
|
3946
|
+
if (!isRecord4(value) || typeof value.url !== "string")
|
|
1780
3947
|
return "each endpoint needs a url";
|
|
1781
3948
|
try {
|
|
1782
3949
|
new URL(value.url);
|
|
@@ -1793,18 +3960,18 @@ var parseEndpoint = (value) => {
|
|
|
1793
3960
|
const events = value.events ?? value.enabledEvents;
|
|
1794
3961
|
if (Array.isArray(events))
|
|
1795
3962
|
endpoint.events = events.map(String);
|
|
1796
|
-
if (
|
|
3963
|
+
if (isRecord4(value.tags)) {
|
|
1797
3964
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
1798
3965
|
}
|
|
1799
3966
|
if (typeof value.account === "string")
|
|
1800
3967
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
1801
|
-
if (
|
|
3968
|
+
if (isRecord4(value.headers)) {
|
|
1802
3969
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
1803
3970
|
}
|
|
1804
3971
|
return endpoint;
|
|
1805
3972
|
};
|
|
1806
3973
|
var webhookAdminRoutes = (hub) => ({
|
|
1807
|
-
"GET /webhooks": ({ url, namespace }) =>
|
|
3974
|
+
"GET /webhooks": ({ url, namespace }) => json4(200, {
|
|
1808
3975
|
deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
|
|
1809
3976
|
const type = url.searchParams.get("type");
|
|
1810
3977
|
return type === null || d.type === type;
|
|
@@ -1812,51 +3979,51 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
1812
3979
|
}),
|
|
1813
3980
|
"GET /webhooks/events": ({ url, namespace }) => {
|
|
1814
3981
|
const type = url.searchParams.get("type");
|
|
1815
|
-
return
|
|
3982
|
+
return json4(200, {
|
|
1816
3983
|
events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
|
|
1817
3984
|
});
|
|
1818
3985
|
},
|
|
1819
3986
|
"POST /webhooks/:id/replay": async ({ params }) => {
|
|
1820
3987
|
const replayed = await hub.replay(params.id);
|
|
1821
|
-
return replayed ?
|
|
3988
|
+
return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
|
|
1822
3989
|
},
|
|
1823
3990
|
"POST /webhooks/flush": async () => {
|
|
1824
3991
|
await hub.flush();
|
|
1825
|
-
return
|
|
3992
|
+
return json4(200, { status: "ok" });
|
|
1826
3993
|
},
|
|
1827
3994
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
1828
|
-
if (!
|
|
1829
|
-
return
|
|
3995
|
+
if (!isRecord4(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
3996
|
+
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
1830
3997
|
}
|
|
1831
3998
|
const fault = { mode: body.mode };
|
|
1832
3999
|
if (typeof body.count === "number")
|
|
1833
4000
|
fault.count = body.count;
|
|
1834
4001
|
hub.fault(namespace, fault);
|
|
1835
|
-
return
|
|
4002
|
+
return json4(201, { namespace, ...fault });
|
|
1836
4003
|
},
|
|
1837
|
-
"GET /webhook-endpoints": ({ namespace }) =>
|
|
4004
|
+
"GET /webhook-endpoints": ({ namespace }) => json4(200, {
|
|
1838
4005
|
endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
|
|
1839
4006
|
...rest,
|
|
1840
4007
|
secret: secret ? "(set)" : null
|
|
1841
4008
|
}))
|
|
1842
4009
|
}),
|
|
1843
4010
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
1844
|
-
const list = Array.isArray(body) ? body :
|
|
4011
|
+
const list = Array.isArray(body) ? body : isRecord4(body) ? body.endpoints : void 0;
|
|
1845
4012
|
if (!Array.isArray(list))
|
|
1846
|
-
return
|
|
4013
|
+
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
1847
4014
|
const parsed = [];
|
|
1848
4015
|
for (const each of list) {
|
|
1849
4016
|
const endpoint = parseEndpoint(each);
|
|
1850
4017
|
if (typeof endpoint === "string")
|
|
1851
|
-
return
|
|
4018
|
+
return adminError3(400, endpoint);
|
|
1852
4019
|
parsed.push(endpoint);
|
|
1853
4020
|
}
|
|
1854
4021
|
const set = hub.setEndpoints(namespace, parsed);
|
|
1855
|
-
return
|
|
4022
|
+
return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
|
|
1856
4023
|
},
|
|
1857
4024
|
"DELETE /webhook-endpoints": ({ namespace }) => {
|
|
1858
4025
|
hub.setEndpoints(namespace, []);
|
|
1859
|
-
return
|
|
4026
|
+
return json4(200, { status: "ok" });
|
|
1860
4027
|
}
|
|
1861
4028
|
});
|
|
1862
4029
|
var parsePayload = (message) => {
|
|
@@ -1909,8 +4076,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
1909
4076
|
this.name = "TypeError";
|
|
1910
4077
|
}
|
|
1911
4078
|
};
|
|
1912
|
-
var operationMatcher = (
|
|
1913
|
-
const matchers = listOperations(
|
|
4079
|
+
var operationMatcher = (document3) => {
|
|
4080
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
1914
4081
|
operationId: operation.operationId,
|
|
1915
4082
|
method: operation.method.toUpperCase(),
|
|
1916
4083
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -1919,6 +4086,7 @@ var operationMatcher = (document2) => {
|
|
|
1919
4086
|
return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
|
|
1920
4087
|
};
|
|
1921
4088
|
var createRuntime = (options) => {
|
|
4089
|
+
assertAdminUi(options.adminUi);
|
|
1922
4090
|
const sqlite = bootSqlite(options.sqlite);
|
|
1923
4091
|
const clock = options.clock ?? createClock();
|
|
1924
4092
|
const rng = createRng(options.seed ?? 0);
|
|
@@ -2004,10 +4172,10 @@ var createRuntime = (options) => {
|
|
|
2004
4172
|
const ensureBranch = (namespace, branch2, at) => {
|
|
2005
4173
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
2006
4174
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
2007
|
-
const
|
|
4175
|
+
const history2 = timeline(namespace);
|
|
2008
4176
|
if (branch2 === "main") {
|
|
2009
4177
|
if (at !== void 0) {
|
|
2010
|
-
const point =
|
|
4178
|
+
const point = history2.checkout("main", at);
|
|
2011
4179
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
2012
4180
|
captured.set(namespace, point.value.snapshot);
|
|
2013
4181
|
rng.setState(point.value.rngState);
|
|
@@ -2020,10 +4188,10 @@ var createRuntime = (options) => {
|
|
|
2020
4188
|
return namespace;
|
|
2021
4189
|
}
|
|
2022
4190
|
const storage = physicalBranch(namespace, branch2);
|
|
2023
|
-
if (!
|
|
4191
|
+
if (!history2.hasBranch(branch2)) {
|
|
2024
4192
|
if (at === void 0)
|
|
2025
|
-
|
|
2026
|
-
const point =
|
|
4193
|
+
history2.commit(capture(namespace));
|
|
4194
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
2027
4195
|
const branchRng = createRng(options.seed ?? 0);
|
|
2028
4196
|
if (point)
|
|
2029
4197
|
branchRng.setState(point.value.rngState);
|
|
@@ -2032,8 +4200,8 @@ var createRuntime = (options) => {
|
|
|
2032
4200
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
2033
4201
|
if (point)
|
|
2034
4202
|
captured.set(storage, point.value.snapshot);
|
|
2035
|
-
} else if (at !== void 0 &&
|
|
2036
|
-
const point =
|
|
4203
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
4204
|
+
const point = history2.checkout(branch2, at);
|
|
2037
4205
|
if (!instances.has(storage)) {
|
|
2038
4206
|
const branchRng = createRng(options.seed ?? 0);
|
|
2039
4207
|
branchRng.setState(point.value.rngState);
|
|
@@ -2044,7 +4212,7 @@ var createRuntime = (options) => {
|
|
|
2044
4212
|
captured.set(storage, point.value.snapshot);
|
|
2045
4213
|
} else {
|
|
2046
4214
|
if (!instances.has(storage)) {
|
|
2047
|
-
const point =
|
|
4215
|
+
const point = history2.head(branch2);
|
|
2048
4216
|
const branchRng = createRng(options.seed ?? 0);
|
|
2049
4217
|
if (point)
|
|
2050
4218
|
branchRng.setState(point.value.rngState);
|
|
@@ -2068,8 +4236,8 @@ var createRuntime = (options) => {
|
|
|
2068
4236
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
2069
4237
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
2070
4238
|
const branchName = checkoutOptions.branch ?? "main";
|
|
2071
|
-
const
|
|
2072
|
-
const point =
|
|
4239
|
+
const history2 = timeline(namespace);
|
|
4240
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
2073
4241
|
const storage = ensureBranch(namespace, branchName);
|
|
2074
4242
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
2075
4243
|
captured.set(storage, point.value.snapshot);
|
|
@@ -2119,12 +4287,25 @@ var createRuntime = (options) => {
|
|
|
2119
4287
|
instance(name);
|
|
2120
4288
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
2121
4289
|
captured.set(name, from);
|
|
2122
|
-
const
|
|
2123
|
-
if (
|
|
2124
|
-
|
|
4290
|
+
const history2 = timelines.get(name);
|
|
4291
|
+
if (history2)
|
|
4292
|
+
history2.commit(capture(name), { branch: "main" });
|
|
2125
4293
|
else
|
|
2126
4294
|
timeline(name);
|
|
2127
4295
|
};
|
|
4296
|
+
const declarationsFor = (namespace) => {
|
|
4297
|
+
const declared = options.state;
|
|
4298
|
+
if (!declared)
|
|
4299
|
+
return [];
|
|
4300
|
+
return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
|
|
4301
|
+
};
|
|
4302
|
+
const stateScope = (namespace) => ({
|
|
4303
|
+
sqlite,
|
|
4304
|
+
namespace,
|
|
4305
|
+
storageNamespace: storageNamespace(namespace),
|
|
4306
|
+
root: instance(namespace),
|
|
4307
|
+
declarations: declarationsFor(namespace)
|
|
4308
|
+
});
|
|
2128
4309
|
const runtime = {
|
|
2129
4310
|
name: options.name,
|
|
2130
4311
|
sqlite,
|
|
@@ -2163,6 +4344,7 @@ var createRuntime = (options) => {
|
|
|
2163
4344
|
branch,
|
|
2164
4345
|
checkout,
|
|
2165
4346
|
timeline,
|
|
4347
|
+
state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
|
|
2166
4348
|
fetch: async (incoming) => {
|
|
2167
4349
|
let request = incoming;
|
|
2168
4350
|
const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
|
|
@@ -2336,10 +4518,10 @@ var createRuntime = (options) => {
|
|
|
2336
4518
|
},
|
|
2337
4519
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
2338
4520
|
inspect: (name) => {
|
|
2339
|
-
const
|
|
4521
|
+
const history2 = timeline(name);
|
|
2340
4522
|
return {
|
|
2341
|
-
branches:
|
|
2342
|
-
checkpoints:
|
|
4523
|
+
branches: history2.branches(),
|
|
4524
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
2343
4525
|
id,
|
|
2344
4526
|
branch: branchName,
|
|
2345
4527
|
parent,
|
|
@@ -2354,13 +4536,22 @@ var createRuntime = (options) => {
|
|
|
2354
4536
|
} : {},
|
|
2355
4537
|
routes: {
|
|
2356
4538
|
...credentialRoutes(credentials),
|
|
2357
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
2358
4539
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
2359
|
-
...options.admin?.(runtime) ?? {}
|
|
4540
|
+
...options.admin?.(runtime) ?? {},
|
|
4541
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4542
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4543
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
4544
|
+
...stateAdminRoutes({
|
|
4545
|
+
open: stateScope,
|
|
4546
|
+
afterWrite: (namespace) => {
|
|
4547
|
+
checkpoint(namespace, "main");
|
|
4548
|
+
}
|
|
4549
|
+
}),
|
|
4550
|
+
...adminUiRoutes(options.name, options.adminUi)
|
|
2360
4551
|
},
|
|
2361
4552
|
adminKey: options.adminKey
|
|
2362
4553
|
});
|
|
2363
|
-
return runtime;
|
|
4554
|
+
return defineMock(runtime);
|
|
2364
4555
|
};
|
|
2365
4556
|
var mutableResponse = (response) => {
|
|
2366
4557
|
try {
|
|
@@ -2424,9 +4615,12 @@ var credentialRoutes = (registry) => ({
|
|
|
2424
4615
|
}
|
|
2425
4616
|
});
|
|
2426
4617
|
var presetRoutes = (presets, runtime) => ({
|
|
2427
|
-
"GET /faults/presets": () =>
|
|
2428
|
-
|
|
2429
|
-
|
|
4618
|
+
"GET /faults/presets": () => {
|
|
4619
|
+
const body = {
|
|
4620
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4621
|
+
};
|
|
4622
|
+
return adminJson(200, body);
|
|
4623
|
+
},
|
|
2430
4624
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
2431
4625
|
const name = params.name;
|
|
2432
4626
|
if (!presets[name])
|
|
@@ -2437,7 +4631,7 @@ var presetRoutes = (presets, runtime) => ({
|
|
|
2437
4631
|
});
|
|
2438
4632
|
|
|
2439
4633
|
// src/generated/openapi.ts
|
|
2440
|
-
var
|
|
4634
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Amazon Textract (Mockingbird subset)","version":"2018-06-27","description":"AWS JSON contract used by the pinned Textract client."},"servers":[{"url":"https://textract.us-east-1.amazonaws.com"}],"paths":{"/":{"post":{"operationId":"TextractRpc","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"name":"X-Amz-Target","in":"header","required":true,"schema":{"type":"string","pattern":"^Textract\\\\.[A-Za-z]+$"}}],"requestBody":{"required":true,"content":{"application/x-amz-json-1.1":{"schema":{"type":"object","additionalProperties":true}},"application/json":{"schema":{"type":"object","additionalProperties":true}}}},"responses":{"200":{"description":"Operation response","content":{"application/x-amz-json-1.1":{"schema":{"type":"object","additionalProperties":true}}}},"400":{"description":"Textract exception","content":{"application/x-amz-json-1.1":{"schema":{"type":"object","additionalProperties":true}}}}}}}}}`);
|
|
2441
4635
|
var operationIds = ["TextractRpc"];
|
|
2442
4636
|
var supportedOperationIds = ["TextractRpc"];
|
|
2443
4637
|
|
|
@@ -2523,7 +4717,7 @@ var createRuntime2 = (options = {}) => {
|
|
|
2523
4717
|
});
|
|
2524
4718
|
const runtime = createRuntime({
|
|
2525
4719
|
name: TEXTRACT_NAMESPACE,
|
|
2526
|
-
document,
|
|
4720
|
+
document: document2,
|
|
2527
4721
|
presets: TEXTRACT_PRESETS,
|
|
2528
4722
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
2529
4723
|
...options.clock ? { clock: options.clock } : {},
|
|
@@ -2621,10 +4815,10 @@ var TextractAPI = class {
|
|
|
2621
4815
|
};
|
|
2622
4816
|
}
|
|
2623
4817
|
corpus(documentLocation) {
|
|
2624
|
-
const
|
|
2625
|
-
if (!
|
|
4818
|
+
const location2 = this.s3(documentLocation);
|
|
4819
|
+
if (!location2) return void 0;
|
|
2626
4820
|
return this.state.corpora.get(
|
|
2627
|
-
this.state.corpusId(
|
|
4821
|
+
this.state.corpusId(location2.bucket, location2.name, location2.version)
|
|
2628
4822
|
);
|
|
2629
4823
|
}
|
|
2630
4824
|
notify(job) {
|
|
@@ -2698,8 +4892,8 @@ var TextractAPI = class {
|
|
|
2698
4892
|
}
|
|
2699
4893
|
if (operation === "StartDocumentAnalysis") {
|
|
2700
4894
|
const documentLocation = read(input, "documentLocation");
|
|
2701
|
-
const
|
|
2702
|
-
if (!
|
|
4895
|
+
const location2 = this.s3(documentLocation);
|
|
4896
|
+
if (!location2)
|
|
2703
4897
|
return this.error("InvalidParameterException", "DocumentLocation.S3Object is required");
|
|
2704
4898
|
const featureTypesInput = read(input, "featureTypes");
|
|
2705
4899
|
const featureTypes = Array.isArray(featureTypesInput) ? featureTypesInput.filter((item) => typeof item === "string") : [];
|
|
@@ -2730,7 +4924,7 @@ var TextractAPI = class {
|
|
|
2730
4924
|
const job = {
|
|
2731
4925
|
id,
|
|
2732
4926
|
status: "IN_PROGRESS",
|
|
2733
|
-
document:
|
|
4927
|
+
document: location2,
|
|
2734
4928
|
featureTypes,
|
|
2735
4929
|
requestFingerprint: fingerprint,
|
|
2736
4930
|
blocks: copy(corpus.blocks),
|
|
@@ -2783,7 +4977,7 @@ var TextractAPI = class {
|
|
|
2783
4977
|
};
|
|
2784
4978
|
|
|
2785
4979
|
export {
|
|
2786
|
-
document,
|
|
4980
|
+
document2 as document,
|
|
2787
4981
|
operationIds,
|
|
2788
4982
|
supportedOperationIds,
|
|
2789
4983
|
TEXTRACT_PRESETS,
|
|
@@ -2792,4 +4986,4 @@ export {
|
|
|
2792
4986
|
accessKeyCredential,
|
|
2793
4987
|
TextractAPI
|
|
2794
4988
|
};
|
|
2795
|
-
//# sourceMappingURL=chunk-
|
|
4989
|
+
//# sourceMappingURL=chunk-JMZ2Q6FS.js.map
|