@crvouga/mockingbird-service-textract 1.7.1 → 2.0.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 +37 -0
- package/DISCOVERY.md +55 -0
- package/README.md +1 -1
- package/SUPPORT.md +11 -0
- package/dist/chunk-OLFPWQHN.js +821 -0
- package/dist/chunk-OLFPWQHN.js.map +7 -0
- package/dist/{chunk-U6DWRYJV.js → chunk-US6IQD72.js} +822 -258
- package/dist/chunk-US6IQD72.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +1 -1
- package/dist/server.d.ts +64 -4
- package/dist/server.js +2 -2
- package/openapi.yaml +22 -0
- package/package.json +29 -4
- package/dist/chunk-L7EDVC5O.js +0 -334
- package/dist/chunk-L7EDVC5O.js.map +0 -7
- package/dist/chunk-U6DWRYJV.js.map +0 -7
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -207,6 +207,15 @@ type FaultCandidate = {
|
|
|
207
207
|
namespace: string;
|
|
208
208
|
};
|
|
209
209
|
type FaultRegistry = {
|
|
210
|
+
isolateNamespaces(): void;
|
|
211
|
+
snapshot(namespace: string): {
|
|
212
|
+
rules: (FaultRule & {
|
|
213
|
+
remaining: number | null;
|
|
214
|
+
hits: number;
|
|
215
|
+
position: number;
|
|
216
|
+
})[];
|
|
217
|
+
rngState: number;
|
|
218
|
+
};
|
|
210
219
|
add(rule: FaultRule): FaultRule;
|
|
211
220
|
list(): (FaultRule & {
|
|
212
221
|
remaining: number | null;
|
|
@@ -214,6 +223,14 @@ type FaultRegistry = {
|
|
|
214
223
|
})[];
|
|
215
224
|
remove(id: string): boolean;
|
|
216
225
|
clear(): void;
|
|
226
|
+
restore(namespace: string, state: {
|
|
227
|
+
rules: (FaultRule & {
|
|
228
|
+
remaining: number | null;
|
|
229
|
+
hits: number;
|
|
230
|
+
position: number;
|
|
231
|
+
})[];
|
|
232
|
+
rngState: number;
|
|
233
|
+
}): void;
|
|
217
234
|
/**
|
|
218
235
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
219
236
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
@@ -391,8 +408,8 @@ type MetricsReport = {
|
|
|
391
408
|
};
|
|
392
409
|
type Metrics = {
|
|
393
410
|
record(entry: RequestLog): void;
|
|
394
|
-
report(): MetricsReport;
|
|
395
|
-
reset(): void;
|
|
411
|
+
report(namespace?: string): MetricsReport;
|
|
412
|
+
reset(namespace?: string): void;
|
|
396
413
|
};
|
|
397
414
|
|
|
398
415
|
/** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
|
|
@@ -558,6 +575,9 @@ type PublishInput = {
|
|
|
558
575
|
id?: string;
|
|
559
576
|
};
|
|
560
577
|
type WebhookHub = {
|
|
578
|
+
pending(namespace: string): number;
|
|
579
|
+
snapshot(namespace: string): unknown;
|
|
580
|
+
restore(namespace: string, snapshot: unknown): void;
|
|
561
581
|
publish(input: PublishInput): WebhookMessage;
|
|
562
582
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
563
583
|
setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
|
|
@@ -585,6 +605,8 @@ type ServiceTimelineState = Readonly<{
|
|
|
585
605
|
}>;
|
|
586
606
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
587
607
|
type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
608
|
+
/** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
|
|
609
|
+
stop?(): void;
|
|
588
610
|
readonly name: string;
|
|
589
611
|
readonly sqlite: SqliteClient$1;
|
|
590
612
|
readonly clock: Clock;
|
|
@@ -595,6 +617,13 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
595
617
|
readonly credentials: CredentialRegistry;
|
|
596
618
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
597
619
|
readonly webhooks: WebhookHub | undefined;
|
|
620
|
+
/** Enable independent namespace clocks and PRNGs before serving a fleet. */
|
|
621
|
+
isolateNamespaces(): void;
|
|
622
|
+
namespaceClock(namespace?: string): Clock;
|
|
623
|
+
namespaceOf(request: Request): string;
|
|
624
|
+
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
625
|
+
fleetSnapshot(namespace: string): object;
|
|
626
|
+
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
598
627
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
599
628
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
600
629
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
@@ -873,6 +902,7 @@ type TextractRuntimeOptions = {
|
|
|
873
902
|
sqlite?: SqliteClient;
|
|
874
903
|
clock?: Clock;
|
|
875
904
|
seed?: number | string;
|
|
905
|
+
adminPrefix?: string;
|
|
876
906
|
adminKey?: string;
|
|
877
907
|
onLog?: (entry: RequestLog) => void;
|
|
878
908
|
corpora?: readonly TextractCorpus[];
|
package/dist/index.js
CHANGED
package/dist/server.d.ts
CHANGED
|
@@ -154,6 +154,15 @@ type FaultCandidate$1 = {
|
|
|
154
154
|
namespace: string;
|
|
155
155
|
};
|
|
156
156
|
type FaultRegistry$1 = {
|
|
157
|
+
isolateNamespaces(): void;
|
|
158
|
+
snapshot(namespace: string): {
|
|
159
|
+
rules: (FaultRule$1 & {
|
|
160
|
+
remaining: number | null;
|
|
161
|
+
hits: number;
|
|
162
|
+
position: number;
|
|
163
|
+
})[];
|
|
164
|
+
rngState: number;
|
|
165
|
+
};
|
|
157
166
|
add(rule: FaultRule$1): FaultRule$1;
|
|
158
167
|
list(): (FaultRule$1 & {
|
|
159
168
|
remaining: number | null;
|
|
@@ -161,6 +170,14 @@ type FaultRegistry$1 = {
|
|
|
161
170
|
})[];
|
|
162
171
|
remove(id: string): boolean;
|
|
163
172
|
clear(): void;
|
|
173
|
+
restore(namespace: string, state: {
|
|
174
|
+
rules: (FaultRule$1 & {
|
|
175
|
+
remaining: number | null;
|
|
176
|
+
hits: number;
|
|
177
|
+
position: number;
|
|
178
|
+
})[];
|
|
179
|
+
rngState: number;
|
|
180
|
+
}): void;
|
|
164
181
|
/**
|
|
165
182
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
166
183
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
@@ -325,8 +342,8 @@ type MetricsReport$1 = {
|
|
|
325
342
|
};
|
|
326
343
|
type Metrics$1 = {
|
|
327
344
|
record(entry: RequestLog$1): void;
|
|
328
|
-
report(): MetricsReport$1;
|
|
329
|
-
reset(): void;
|
|
345
|
+
report(namespace?: string): MetricsReport$1;
|
|
346
|
+
reset(namespace?: string): void;
|
|
330
347
|
};
|
|
331
348
|
|
|
332
349
|
/** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
|
|
@@ -480,6 +497,9 @@ type PublishInput$1 = {
|
|
|
480
497
|
id?: string;
|
|
481
498
|
};
|
|
482
499
|
type WebhookHub$1 = {
|
|
500
|
+
pending(namespace: string): number;
|
|
501
|
+
snapshot(namespace: string): unknown;
|
|
502
|
+
restore(namespace: string, snapshot: unknown): void;
|
|
483
503
|
publish(input: PublishInput$1): WebhookMessage$1;
|
|
484
504
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
485
505
|
setEndpoints(namespace: string, endpoints: WebhookEndpoint$1[]): WebhookEndpoint$1[];
|
|
@@ -507,6 +527,8 @@ type ServiceTimelineState$1 = Readonly<{
|
|
|
507
527
|
}>;
|
|
508
528
|
type ServiceCheckpoint$1 = Checkpoint$1<ServiceTimelineState$1>;
|
|
509
529
|
type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$1 & {
|
|
530
|
+
/** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
|
|
531
|
+
stop?(): void;
|
|
510
532
|
readonly name: string;
|
|
511
533
|
readonly sqlite: SqliteClient$2;
|
|
512
534
|
readonly clock: Clock$1;
|
|
@@ -517,6 +539,13 @@ type ServiceRuntime$1<T extends ServiceInstance$1> = FetchAPI$1 & {
|
|
|
517
539
|
readonly credentials: CredentialRegistry$1;
|
|
518
540
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
519
541
|
readonly webhooks: WebhookHub$1 | undefined;
|
|
542
|
+
/** Enable independent namespace clocks and PRNGs before serving a fleet. */
|
|
543
|
+
isolateNamespaces(): void;
|
|
544
|
+
namespaceClock(namespace?: string): Clock$1;
|
|
545
|
+
namespaceOf(request: Request): string;
|
|
546
|
+
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
547
|
+
fleetSnapshot(namespace: string): object;
|
|
548
|
+
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
520
549
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
521
550
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule$1>): FaultRule$1[];
|
|
522
551
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
@@ -563,6 +592,7 @@ type CliOption = {
|
|
|
563
592
|
};
|
|
564
593
|
type CliValues = Record<string, string | boolean | undefined>;
|
|
565
594
|
type CommonServeOptions = {
|
|
595
|
+
adminPrefix?: string;
|
|
566
596
|
adminKey: string | undefined;
|
|
567
597
|
seed: string | undefined;
|
|
568
598
|
onLog: ((entry: RequestLog$1) => void) | undefined;
|
|
@@ -780,6 +810,15 @@ type FaultCandidate = {
|
|
|
780
810
|
namespace: string;
|
|
781
811
|
};
|
|
782
812
|
type FaultRegistry = {
|
|
813
|
+
isolateNamespaces(): void;
|
|
814
|
+
snapshot(namespace: string): {
|
|
815
|
+
rules: (FaultRule & {
|
|
816
|
+
remaining: number | null;
|
|
817
|
+
hits: number;
|
|
818
|
+
position: number;
|
|
819
|
+
})[];
|
|
820
|
+
rngState: number;
|
|
821
|
+
};
|
|
783
822
|
add(rule: FaultRule): FaultRule;
|
|
784
823
|
list(): (FaultRule & {
|
|
785
824
|
remaining: number | null;
|
|
@@ -787,6 +826,14 @@ type FaultRegistry = {
|
|
|
787
826
|
})[];
|
|
788
827
|
remove(id: string): boolean;
|
|
789
828
|
clear(): void;
|
|
829
|
+
restore(namespace: string, state: {
|
|
830
|
+
rules: (FaultRule & {
|
|
831
|
+
remaining: number | null;
|
|
832
|
+
hits: number;
|
|
833
|
+
position: number;
|
|
834
|
+
})[];
|
|
835
|
+
rngState: number;
|
|
836
|
+
}): void;
|
|
790
837
|
/**
|
|
791
838
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
792
839
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
@@ -964,8 +1011,8 @@ type MetricsReport = {
|
|
|
964
1011
|
};
|
|
965
1012
|
type Metrics = {
|
|
966
1013
|
record(entry: RequestLog): void;
|
|
967
|
-
report(): MetricsReport;
|
|
968
|
-
reset(): void;
|
|
1014
|
+
report(namespace?: string): MetricsReport;
|
|
1015
|
+
reset(namespace?: string): void;
|
|
969
1016
|
};
|
|
970
1017
|
|
|
971
1018
|
/** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
|
|
@@ -1131,6 +1178,9 @@ type PublishInput = {
|
|
|
1131
1178
|
id?: string;
|
|
1132
1179
|
};
|
|
1133
1180
|
type WebhookHub = {
|
|
1181
|
+
pending(namespace: string): number;
|
|
1182
|
+
snapshot(namespace: string): unknown;
|
|
1183
|
+
restore(namespace: string, snapshot: unknown): void;
|
|
1134
1184
|
publish(input: PublishInput): WebhookMessage;
|
|
1135
1185
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
1136
1186
|
setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
|
|
@@ -1158,6 +1208,8 @@ type ServiceTimelineState = Readonly<{
|
|
|
1158
1208
|
}>;
|
|
1159
1209
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
1160
1210
|
type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
1211
|
+
/** Stop package-owned lifecycle timers when a supervisor closes the runtime. */
|
|
1212
|
+
stop?(): void;
|
|
1161
1213
|
readonly name: string;
|
|
1162
1214
|
readonly sqlite: SqliteClient$1;
|
|
1163
1215
|
readonly clock: Clock;
|
|
@@ -1168,6 +1220,13 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
1168
1220
|
readonly credentials: CredentialRegistry;
|
|
1169
1221
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
1170
1222
|
readonly webhooks: WebhookHub | undefined;
|
|
1223
|
+
/** Enable independent namespace clocks and PRNGs before serving a fleet. */
|
|
1224
|
+
isolateNamespaces(): void;
|
|
1225
|
+
namespaceClock(namespace?: string): Clock;
|
|
1226
|
+
namespaceOf(request: Request): string;
|
|
1227
|
+
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
1228
|
+
fleetSnapshot(namespace: string): object;
|
|
1229
|
+
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
1171
1230
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
1172
1231
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
1173
1232
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
@@ -1313,6 +1372,7 @@ type TextractRuntimeOptions = {
|
|
|
1313
1372
|
sqlite?: SqliteClient;
|
|
1314
1373
|
clock?: Clock;
|
|
1315
1374
|
seed?: number | string;
|
|
1375
|
+
adminPrefix?: string;
|
|
1316
1376
|
adminKey?: string;
|
|
1317
1377
|
onLog?: (entry: RequestLog) => void;
|
|
1318
1378
|
corpora?: readonly TextractCorpus[];
|
package/dist/server.js
CHANGED
package/openapi.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
openapi: 3.1.0
|
|
2
|
+
info:
|
|
3
|
+
title: Amazon Textract (Mockingbird subset)
|
|
4
|
+
version: "2018-06-27"
|
|
5
|
+
description: AWS JSON contract used by the pinned Textract client.
|
|
6
|
+
servers:
|
|
7
|
+
- url: https://textract.us-east-1.amazonaws.com
|
|
8
|
+
paths:
|
|
9
|
+
/:
|
|
10
|
+
post:
|
|
11
|
+
operationId: TextractRpc
|
|
12
|
+
x-mockingbird: { supported: true, parity: { enabled: true, safe: false } }
|
|
13
|
+
parameters:
|
|
14
|
+
- { name: X-Amz-Target, in: header, required: true, schema: { type: string, pattern: '^Textract\.[A-Za-z]+$' } }
|
|
15
|
+
requestBody:
|
|
16
|
+
required: true
|
|
17
|
+
content:
|
|
18
|
+
application/x-amz-json-1.1: { schema: { type: object, additionalProperties: true } }
|
|
19
|
+
application/json: { schema: { type: object, additionalProperties: true } }
|
|
20
|
+
responses:
|
|
21
|
+
"200": { description: Operation response, content: { application/x-amz-json-1.1: { schema: { type: object, additionalProperties: true } } } }
|
|
22
|
+
"400": { description: Textract exception, content: { application/x-amz-json-1.1: { schema: { type: object, additionalProperties: true } } } }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crvouga/mockingbird-service-textract",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Stateful Amazon Textract mock with document analysis jobs, graph blocks, pagination, and deterministic notifications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"README.md",
|
|
11
|
-
"CHANGELOG.md"
|
|
11
|
+
"CHANGELOG.md",
|
|
12
|
+
"DISCOVERY.md",
|
|
13
|
+
"SUPPORT.md",
|
|
14
|
+
"openapi.yaml"
|
|
12
15
|
],
|
|
13
16
|
"main": "./dist/index.js",
|
|
14
17
|
"types": "./dist/index.d.ts",
|
|
@@ -57,7 +60,29 @@
|
|
|
57
60
|
"docs": "https://docs.aws.amazon.com/textract/latest/dg/API_Reference.html"
|
|
58
61
|
},
|
|
59
62
|
"parity": "Document analysis jobs",
|
|
60
|
-
"parityTier": "cold"
|
|
63
|
+
"parityTier": "cold",
|
|
64
|
+
"discovery": {
|
|
65
|
+
"guide": "DISCOVERY.md",
|
|
66
|
+
"behavior": "README.md",
|
|
67
|
+
"capabilities": "SUPPORT.md",
|
|
68
|
+
"contract": "openapi.yaml",
|
|
69
|
+
"types": "dist/index.d.ts",
|
|
70
|
+
"oracle": {
|
|
71
|
+
"kind": "Live vendor API or sandbox",
|
|
72
|
+
"command": "bun run parity:service -- textract",
|
|
73
|
+
"note": "Run from a Mockingbird checkout; credentials come only from .env.local or GitHub Actions secrets. Missing credentials exit 2."
|
|
74
|
+
},
|
|
75
|
+
"introspection": [
|
|
76
|
+
"GET /__admin/health",
|
|
77
|
+
"GET /__admin",
|
|
78
|
+
"GET /__admin/state",
|
|
79
|
+
"GET /__admin/requests",
|
|
80
|
+
"GET /__admin/metrics",
|
|
81
|
+
"GET /__admin/faults/presets",
|
|
82
|
+
"GET /__admin/ui"
|
|
83
|
+
],
|
|
84
|
+
"reporting": "https://github.com/crvouga/mockingbird/blob/main/docs/REPORTING_ISSUES.md"
|
|
85
|
+
}
|
|
61
86
|
},
|
|
62
87
|
"scripts": {
|
|
63
88
|
"generate": "bun ../../openapi/codegen/dist/cli.js",
|
|
@@ -72,7 +97,7 @@
|
|
|
72
97
|
"pack:check": "bun ../../../scripts/pack-check.ts"
|
|
73
98
|
},
|
|
74
99
|
"dependencies": {
|
|
75
|
-
"@crvouga/mockingbird-service-sqlite": "
|
|
100
|
+
"@crvouga/mockingbird-service-sqlite": "2.0.0"
|
|
76
101
|
},
|
|
77
102
|
"devDependencies": {
|
|
78
103
|
"@aws-sdk/client-textract": "3.1132.0",
|
package/dist/chunk-L7EDVC5O.js
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createRuntime
|
|
3
|
-
} from "./chunk-U6DWRYJV.js";
|
|
4
|
-
|
|
5
|
-
// ../../adapters/node/dist/cli.js
|
|
6
|
-
import { readFile } from "node:fs/promises";
|
|
7
|
-
import { parseArgs } from "node:util";
|
|
8
|
-
|
|
9
|
-
// ../../adapters/node/dist/serve.js
|
|
10
|
-
import { createServer } from "node:http";
|
|
11
|
-
var serve = async (api, options = {}) => {
|
|
12
|
-
const server = createServer(async (req, res) => {
|
|
13
|
-
const chunks = [];
|
|
14
|
-
for await (const chunk of req) {
|
|
15
|
-
chunks.push(Buffer.from(chunk));
|
|
16
|
-
}
|
|
17
|
-
const body = Buffer.concat(chunks);
|
|
18
|
-
const address = server.address();
|
|
19
|
-
const port = typeof address === "object" && address !== null ? address.port : void 0;
|
|
20
|
-
const base = `http://${req.headers.host ?? `localhost:${port ?? 80}`}`;
|
|
21
|
-
const raw = req.url ?? "/";
|
|
22
|
-
const url = new URL(raw.replace(/^\/+/, "/"), base);
|
|
23
|
-
const method = req.method ?? "GET";
|
|
24
|
-
const init = { method, headers: req.headers };
|
|
25
|
-
if (method !== "GET" && method !== "HEAD" && body.length > 0) {
|
|
26
|
-
init.body = body;
|
|
27
|
-
}
|
|
28
|
-
const aborted = new AbortController();
|
|
29
|
-
res.once("close", () => {
|
|
30
|
-
if (!res.writableFinished)
|
|
31
|
-
aborted.abort();
|
|
32
|
-
});
|
|
33
|
-
init.signal = aborted.signal;
|
|
34
|
-
const request = new Request(url, init);
|
|
35
|
-
let response;
|
|
36
|
-
try {
|
|
37
|
-
response = await api.fetch(request);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
if (error.code === "MOCKINGBIRD_DROP") {
|
|
40
|
-
req.socket.destroy();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
res.writeHead(500, { "content-type": "application/json" });
|
|
44
|
-
res.end(JSON.stringify({
|
|
45
|
-
error: {
|
|
46
|
-
type: "mockingbird_internal",
|
|
47
|
-
message: error instanceof Error ? error.message : String(error)
|
|
48
|
-
}
|
|
49
|
-
}));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const headers = Object.fromEntries(response.headers);
|
|
53
|
-
const cookies = response.headers.getSetCookie();
|
|
54
|
-
if (cookies.length > 0)
|
|
55
|
-
headers["set-cookie"] = cookies;
|
|
56
|
-
if (!response.body) {
|
|
57
|
-
res.writeHead(response.status, headers);
|
|
58
|
-
res.end();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
res.writeHead(response.status, headers);
|
|
62
|
-
res.flushHeaders();
|
|
63
|
-
const reader = response.body.getReader();
|
|
64
|
-
try {
|
|
65
|
-
for (; ; ) {
|
|
66
|
-
const { done, value } = await reader.read();
|
|
67
|
-
if (done)
|
|
68
|
-
break;
|
|
69
|
-
if (!res.write(value))
|
|
70
|
-
await new Promise((resolve) => res.once("drain", resolve));
|
|
71
|
-
}
|
|
72
|
-
res.end();
|
|
73
|
-
} catch {
|
|
74
|
-
res.destroy();
|
|
75
|
-
} finally {
|
|
76
|
-
reader.releaseLock();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
await new Promise((resolve, reject) => {
|
|
80
|
-
server.once("error", reject);
|
|
81
|
-
server.listen(options.port ?? 0, options.host, resolve);
|
|
82
|
-
});
|
|
83
|
-
return server;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// ../../adapters/node/dist/listen.js
|
|
87
|
-
var listen = async (api, options = {}) => {
|
|
88
|
-
const host = options.host ?? "127.0.0.1";
|
|
89
|
-
const server = await serve(api, { port: options.port ?? 0, host });
|
|
90
|
-
const address = server.address();
|
|
91
|
-
const port = typeof address === "object" && address !== null ? address.port : options.port ?? 0;
|
|
92
|
-
const shown = host.includes(":") ? `[${host}]` : host;
|
|
93
|
-
return {
|
|
94
|
-
url: `http://${shown}:${port}`,
|
|
95
|
-
port,
|
|
96
|
-
host,
|
|
97
|
-
server,
|
|
98
|
-
close: () => new Promise((resolve, reject) => {
|
|
99
|
-
server.close((error) => {
|
|
100
|
-
if (error && error.code !== "ERR_SERVER_NOT_RUNNING")
|
|
101
|
-
reject(error);
|
|
102
|
-
else
|
|
103
|
-
resolve();
|
|
104
|
-
});
|
|
105
|
-
server.closeAllConnections?.();
|
|
106
|
-
})
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// ../../adapters/node/dist/cli.js
|
|
111
|
-
var optionHelp = (options) => Object.entries(options).map(([name, option]) => {
|
|
112
|
-
const flag = `--${name}${option.type === "string" ? ` ${option.value ?? "<value>"}` : ""}`;
|
|
113
|
-
const fallback = option.default !== void 0 ? ` (default: ${String(option.default)})` : "";
|
|
114
|
-
return ` ${flag.padEnd(30)} ${option.description}${fallback}`;
|
|
115
|
-
});
|
|
116
|
-
var help = (spec) => [
|
|
117
|
-
`${spec.bin} \u2014 ${spec.description}`,
|
|
118
|
-
"",
|
|
119
|
-
"Usage:",
|
|
120
|
-
` ${spec.bin} <command> [options]`,
|
|
121
|
-
"",
|
|
122
|
-
"Commands:",
|
|
123
|
-
...Object.entries(spec.commands).map(([name, c]) => ` ${name.padEnd(30)} ${c.summary}`),
|
|
124
|
-
"",
|
|
125
|
-
`Run \`${spec.bin} <command> --help\` for a command's options.`
|
|
126
|
-
].join("\n");
|
|
127
|
-
var commandHelp = (spec, name, command) => [
|
|
128
|
-
`${spec.bin} ${name} \u2014 ${command.summary}`,
|
|
129
|
-
"",
|
|
130
|
-
"Usage:",
|
|
131
|
-
` ${command.usage ?? `${spec.bin} ${name} [options]`}`,
|
|
132
|
-
...command.options ? ["", "Options:", ...optionHelp(command.options)] : []
|
|
133
|
-
].join("\n");
|
|
134
|
-
var runCli = async (spec, argv) => {
|
|
135
|
-
const pair = argv.length >= 2 ? `${argv[0]} ${argv[1]}` : void 0;
|
|
136
|
-
const words = pair !== void 0 && spec.commands[pair] ? 2 : 1;
|
|
137
|
-
const name = words === 2 ? pair : argv[0];
|
|
138
|
-
const rest = argv.slice(words);
|
|
139
|
-
if (name === void 0 || name === "--help" || name === "-h" || name === "help") {
|
|
140
|
-
console.log(help(spec));
|
|
141
|
-
return 0;
|
|
142
|
-
}
|
|
143
|
-
const command = spec.commands[name];
|
|
144
|
-
if (!command) {
|
|
145
|
-
console.error(`${spec.bin}: unknown command ${JSON.stringify(name)}
|
|
146
|
-
|
|
147
|
-
${help(spec)}`);
|
|
148
|
-
return 2;
|
|
149
|
-
}
|
|
150
|
-
if (rest.includes("--help") || rest.includes("-h")) {
|
|
151
|
-
console.log(commandHelp(spec, name, command));
|
|
152
|
-
return 0;
|
|
153
|
-
}
|
|
154
|
-
let parsed;
|
|
155
|
-
try {
|
|
156
|
-
parsed = parseArgs({
|
|
157
|
-
args: rest,
|
|
158
|
-
allowPositionals: true,
|
|
159
|
-
strict: true,
|
|
160
|
-
options: Object.fromEntries(Object.entries(command.options ?? {}).map(([key, option]) => [
|
|
161
|
-
key,
|
|
162
|
-
{
|
|
163
|
-
type: option.type,
|
|
164
|
-
...option.default !== void 0 ? { default: option.default } : {}
|
|
165
|
-
}
|
|
166
|
-
]))
|
|
167
|
-
});
|
|
168
|
-
} catch (error) {
|
|
169
|
-
console.error(`${spec.bin} ${name}: ${error instanceof Error ? error.message : String(error)}
|
|
170
|
-
|
|
171
|
-
${commandHelp(spec, name, command)}`);
|
|
172
|
-
return 2;
|
|
173
|
-
}
|
|
174
|
-
return command.run(parsed.values, parsed.positionals);
|
|
175
|
-
};
|
|
176
|
-
var COMMON_SERVE_OPTIONS = {
|
|
177
|
-
port: { type: "string", value: "<port>", description: "Port to listen on" },
|
|
178
|
-
host: { type: "string", value: "<host>", description: "Interface to bind", default: "127.0.0.1" },
|
|
179
|
-
"admin-key": {
|
|
180
|
-
type: "string",
|
|
181
|
-
value: "<key>",
|
|
182
|
-
description: "Require x-mockingbird-admin-key on /__admin/* (env MOCKINGBIRD_ADMIN_KEY)"
|
|
183
|
-
},
|
|
184
|
-
seed: { type: "string", value: "<seed>", description: "Seed for every random choice" },
|
|
185
|
-
log: {
|
|
186
|
-
type: "string",
|
|
187
|
-
value: "<pretty|json|off>",
|
|
188
|
-
description: "Request log format",
|
|
189
|
-
default: "pretty"
|
|
190
|
-
},
|
|
191
|
-
"log-requests": {
|
|
192
|
-
type: "boolean",
|
|
193
|
-
description: "One JSON line per request: namespace, operationId, status, ids touched (never bodies). Same as --log json"
|
|
194
|
-
},
|
|
195
|
-
config: {
|
|
196
|
-
type: "string",
|
|
197
|
-
value: "<file>",
|
|
198
|
-
description: "Serve every service in a mockingbird.json config instead"
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
var formatLog = (format) => {
|
|
202
|
-
if (format === "off")
|
|
203
|
-
return void 0;
|
|
204
|
-
if (format === "json")
|
|
205
|
-
return (entry) => console.log(JSON.stringify(entry));
|
|
206
|
-
return (entry) => {
|
|
207
|
-
const op = entry.operationId ?? (entry.unmatched ? "UNMATCHED" : "-");
|
|
208
|
-
const ns = entry.namespace === "default" ? "" : ` [${entry.namespace}]`;
|
|
209
|
-
const fault = entry.faultId ? ` fault=${entry.faultId}` : "";
|
|
210
|
-
const adopted = entry.adopted ? " adopted" : "";
|
|
211
|
-
const received = entry.request ? ` received=${entry.request.bodyBytes === null ? "?" : `${entry.request.bodyBytes}B`} ct=${entry.request.contentType ?? "-"}${entry.request.transferEncoding ? ` te=${entry.request.transferEncoding}` : ""}` : "";
|
|
212
|
-
const issues = entry.issues?.length ? ` issues=${entry.issues.slice(0, 3).map((issue) => `${issue.path || "$"}: ${issue.message}`).join("; ")}${entry.issues.length > 3 ? ` (+${entry.issues.length - 3})` : ""}` : "";
|
|
213
|
-
console.log(`${entry.service} ${entry.method} ${entry.path} ${entry.status} ${op} ${entry.durationMs}ms${ns}${fault}${adopted}${received}${issues}`);
|
|
214
|
-
};
|
|
215
|
-
};
|
|
216
|
-
var asString = (value) => typeof value === "string" ? value : void 0;
|
|
217
|
-
var loadTarget = async (name, own) => {
|
|
218
|
-
if (name === own.name)
|
|
219
|
-
return own;
|
|
220
|
-
const specifier = `@crvouga/mockingbird-service-${name}/server`;
|
|
221
|
-
try {
|
|
222
|
-
const mod = await import(specifier);
|
|
223
|
-
if (!mod.serveTarget)
|
|
224
|
-
throw new Error(`${specifier} exports no serveTarget`);
|
|
225
|
-
return mod.serveTarget;
|
|
226
|
-
} catch (error) {
|
|
227
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
228
|
-
throw new Error(`cannot load service "${name}": ${reason}. Install @crvouga/mockingbird-service-${name}.`);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
var start = async (target, values, config) => {
|
|
232
|
-
const runtime = await target.create(values, {
|
|
233
|
-
adminKey: config.adminKey,
|
|
234
|
-
seed: config.seed,
|
|
235
|
-
onLog: formatLog(config.log)
|
|
236
|
-
});
|
|
237
|
-
const listening = await listen(runtime, { port: config.port, host: config.host });
|
|
238
|
-
target.listening?.(listening);
|
|
239
|
-
console.log(`${target.name} mock listening on ${listening.url}`);
|
|
240
|
-
console.log(`${target.name} health: GET ${listening.url}/health`);
|
|
241
|
-
console.log(`${target.name} admin: ${listening.url}/__admin (${config.adminKey ? "x-mockingbird-admin-key required" : "open \u2014 pass --admin-key to lock"})`);
|
|
242
|
-
console.log(`${target.name} admin ui: ${listening.url}/__admin/ui`);
|
|
243
|
-
for (const line of target.banner?.(runtime) ?? [])
|
|
244
|
-
console.log(`${target.name} ${line}`);
|
|
245
|
-
return listening;
|
|
246
|
-
};
|
|
247
|
-
var untilSignal = async (servers) => new Promise((resolve) => {
|
|
248
|
-
const stop = async () => {
|
|
249
|
-
await Promise.allSettled(servers.map((s) => s.close()));
|
|
250
|
-
resolve(0);
|
|
251
|
-
};
|
|
252
|
-
process.once("SIGINT", stop);
|
|
253
|
-
process.once("SIGTERM", stop);
|
|
254
|
-
});
|
|
255
|
-
var serveCommand = (target) => ({
|
|
256
|
-
summary: `Serve the ${target.name} mock over HTTP`,
|
|
257
|
-
options: { ...COMMON_SERVE_OPTIONS, ...target.options },
|
|
258
|
-
async run(values) {
|
|
259
|
-
const log = values["log-requests"] === true ? "json" : asString(values.log) ?? "pretty";
|
|
260
|
-
if (!["pretty", "json", "off"].includes(log)) {
|
|
261
|
-
console.error(`--log must be pretty, json or off (got ${log})`);
|
|
262
|
-
return 2;
|
|
263
|
-
}
|
|
264
|
-
const configPath = asString(values.config);
|
|
265
|
-
if (configPath !== void 0) {
|
|
266
|
-
const config = JSON.parse(await readFile(configPath, "utf8"));
|
|
267
|
-
const servers = [];
|
|
268
|
-
try {
|
|
269
|
-
for (const [name, entry] of Object.entries(config.services ?? {})) {
|
|
270
|
-
const each = await loadTarget(name, target);
|
|
271
|
-
servers.push(await start(each, entry.options ?? {}, {
|
|
272
|
-
port: entry.port ?? each.defaultPort,
|
|
273
|
-
host: entry.host ?? "127.0.0.1",
|
|
274
|
-
...entry.adminKey !== void 0 ? { adminKey: entry.adminKey } : {},
|
|
275
|
-
...entry.seed !== void 0 ? { seed: entry.seed } : {},
|
|
276
|
-
log: config.log ?? log
|
|
277
|
-
}));
|
|
278
|
-
}
|
|
279
|
-
} catch (error) {
|
|
280
|
-
await Promise.allSettled(servers.map((s) => s.close()));
|
|
281
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
282
|
-
return 1;
|
|
283
|
-
}
|
|
284
|
-
return untilSignal(servers);
|
|
285
|
-
}
|
|
286
|
-
const port = asString(values.port);
|
|
287
|
-
const adminKey = asString(values["admin-key"]) ?? process.env.MOCKINGBIRD_ADMIN_KEY;
|
|
288
|
-
const seed = asString(values.seed);
|
|
289
|
-
let listening;
|
|
290
|
-
try {
|
|
291
|
-
listening = await start(target, values, {
|
|
292
|
-
port: port === void 0 ? target.defaultPort : Number.parseInt(port, 10),
|
|
293
|
-
host: asString(values.host) ?? "127.0.0.1",
|
|
294
|
-
...adminKey !== void 0 ? { adminKey } : {},
|
|
295
|
-
...seed !== void 0 ? { seed } : {},
|
|
296
|
-
log
|
|
297
|
-
});
|
|
298
|
-
} catch (error) {
|
|
299
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
300
|
-
return 1;
|
|
301
|
-
}
|
|
302
|
-
return untilSignal([listening]);
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
// src/server.ts
|
|
307
|
-
var DEFAULT_PORT = 8818;
|
|
308
|
-
var createServer2 = async (options = {}) => {
|
|
309
|
-
const { port, host, ...rest } = options;
|
|
310
|
-
const runtime = createRuntime(rest);
|
|
311
|
-
return { ...await listen(runtime, { port: port ?? 0, ...host ? { host } : {} }), runtime };
|
|
312
|
-
};
|
|
313
|
-
var serveTarget = {
|
|
314
|
-
name: "textract",
|
|
315
|
-
defaultPort: DEFAULT_PORT,
|
|
316
|
-
create: (_values, common) => createRuntime({
|
|
317
|
-
...common.adminKey !== void 0 ? { adminKey: common.adminKey } : {},
|
|
318
|
-
...common.seed !== void 0 ? { seed: common.seed } : {},
|
|
319
|
-
...common.onLog ? { onLog: common.onLog } : {}
|
|
320
|
-
}),
|
|
321
|
-
banner: () => [
|
|
322
|
-
"Point TextractClient endpoint at this URL",
|
|
323
|
-
"admin: seed block graphs and transition analysis jobs"
|
|
324
|
-
]
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
export {
|
|
328
|
-
runCli,
|
|
329
|
-
serveCommand,
|
|
330
|
-
DEFAULT_PORT,
|
|
331
|
-
createServer2 as createServer,
|
|
332
|
-
serveTarget
|
|
333
|
-
};
|
|
334
|
-
//# sourceMappingURL=chunk-L7EDVC5O.js.map
|