@crvouga/mockingbird-runtime 0.4.0 → 0.6.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.
@@ -0,0 +1,83 @@
1
+ import {
2
+ Collection,
3
+ IdSequence,
4
+ bodyIssues,
5
+ createRuntime,
6
+ createService,
7
+ defineOperations,
8
+ jsonRes
9
+ } from "./chunk-BK5KDNUE.js";
10
+ import "./chunk-2KDYLZXC.js";
11
+ import "./chunk-GAIPLMRY.js";
12
+ import "./chunk-U36J5GCB.js";
13
+ import "./chunk-EQLY2YOA.js";
14
+ import "./chunk-HU6IOAFC.js";
15
+ import "./chunk-4SAK6MQT.js";
16
+
17
+ // src/authoring.ts
18
+ function defineHttpService(definition) {
19
+ const {
20
+ name,
21
+ version,
22
+ defaultPort = 0,
23
+ document,
24
+ handlers,
25
+ before,
26
+ unsupported,
27
+ notFound = () => Response.json({ error: "not_found" }, { status: 404 }),
28
+ onError = () => Response.json({ error: "internal_error" }, { status: 500 }),
29
+ ...runtimeOptions
30
+ } = definition;
31
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name))
32
+ throw new Error("expected a lowercase hyphenated service name");
33
+ if (!version.trim()) throw new Error("service version is required");
34
+ if (!Number.isInteger(defaultPort) || defaultPort < 0 || defaultPort > 65535)
35
+ throw new Error("defaultPort must be 0-65535");
36
+ const boot = (options = {}) => createRuntime({
37
+ ...options,
38
+ ...runtimeOptions,
39
+ name,
40
+ version,
41
+ document,
42
+ create(context) {
43
+ return createService({
44
+ sqlite: context.sqlite,
45
+ namespace: context.namespace,
46
+ now: context.clock.now,
47
+ document,
48
+ handlers: handlers(context),
49
+ notFound,
50
+ onError,
51
+ ...before && { before },
52
+ ...unsupported && { unsupported }
53
+ });
54
+ }
55
+ });
56
+ return {
57
+ createRuntime: boot,
58
+ serveTarget: {
59
+ name,
60
+ packageVersion: version,
61
+ defaultPort,
62
+ create(_values, common) {
63
+ const { adminKey, adminPrefix, seed, adminControls, onLog } = common;
64
+ return boot({
65
+ ...adminKey !== void 0 && { adminKey },
66
+ ...adminPrefix !== void 0 && { adminPrefix },
67
+ ...seed !== void 0 && { seed },
68
+ ...adminControls !== void 0 && { adminControls },
69
+ ...onLog && { onLog }
70
+ });
71
+ }
72
+ }
73
+ };
74
+ }
75
+ export {
76
+ Collection,
77
+ IdSequence,
78
+ bodyIssues,
79
+ defineHttpService,
80
+ defineOperations,
81
+ jsonRes as jsonResponse
82
+ };
83
+ //# sourceMappingURL=authoring.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/authoring.ts"],
4
+ "sourcesContent": ["import {\n createRuntime,\n createService,\n type InstanceContext,\n type MockCreateOptions,\n type OperationHandlers,\n type RuntimeOptions,\n type Service,\n type ServiceOptions,\n type ServiceRuntime,\n} from \"@crvouga/mockingbird-service\"\n\nexport type { InstanceContext, OperationHandlers } from \"@crvouga/mockingbird-service\"\nexport {\n bodyIssues,\n Collection,\n defineOperations,\n IdSequence,\n jsonResponse,\n} from \"@crvouga/mockingbird-service\"\n\nexport type HttpServiceDefinition = Pick<\n RuntimeOptions<Service>,\n \"name\" | \"presets\" | \"credential\" | \"state\" | \"admin\"\n> &\n Pick<ServiceOptions, \"document\" | \"before\" | \"unsupported\"> &\n Partial<Pick<ServiceOptions, \"onError\" | \"notFound\">> & {\n version: string\n defaultPort?: number\n handlers(context: InstanceContext): OperationHandlers\n }\n\nexport type HttpRuntimeFactory = (\n options?: MockCreateOptions & Pick<RuntimeOptions<Service>, \"onLog\">,\n) => ServiceRuntime<Service>\n\n/** Structural subset of the fleet boot options consumed by HTTP services. */\ntype HttpBootControls = {\n [K in \"adminKey\" | \"adminPrefix\" | \"seed\" | \"adminControls\" | \"onLog\"]?:\n | RuntimeOptions<Service>[K]\n | undefined\n}\n\nexport interface HttpServeTarget {\n name: string\n packageVersion: string\n defaultPort: number\n create(values: unknown, common: HttpBootControls): ServiceRuntime<Service>\n}\n\n/** Define once for Fetch, a Node listener, or a fleet. Each boot owns its storage and clock. */\nexport function defineHttpService(definition: HttpServiceDefinition): {\n createRuntime: HttpRuntimeFactory\n serveTarget: HttpServeTarget\n} {\n const {\n name,\n version,\n defaultPort = 0,\n document,\n handlers,\n before,\n unsupported,\n notFound = () => Response.json({ error: \"not_found\" }, { status: 404 }),\n onError = () => Response.json({ error: \"internal_error\" }, { status: 500 }),\n ...runtimeOptions\n } = definition\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name))\n throw new Error(\"expected a lowercase hyphenated service name\")\n if (!version.trim()) throw new Error(\"service version is required\")\n if (!Number.isInteger(defaultPort) || defaultPort < 0 || defaultPort > 65535)\n throw new Error(\"defaultPort must be 0-65535\")\n const boot = (\n options: MockCreateOptions & Pick<RuntimeOptions<Service>, \"onLog\"> = {},\n ): ServiceRuntime<Service> =>\n createRuntime({\n ...options,\n ...runtimeOptions,\n name,\n version,\n document,\n create(context) {\n return createService({\n sqlite: context.sqlite,\n namespace: context.namespace,\n now: context.clock.now,\n document,\n handlers: handlers(context),\n notFound,\n onError,\n ...(before && { before }),\n ...(unsupported && { unsupported }),\n })\n },\n })\n return {\n createRuntime: boot,\n serveTarget: {\n name,\n packageVersion: version,\n defaultPort,\n create(_values: unknown, common: HttpBootControls) {\n const { adminKey, adminPrefix, seed, adminControls, onLog } = common\n return boot({\n ...(adminKey !== undefined && { adminKey }),\n ...(adminPrefix !== undefined && { adminPrefix }),\n ...(seed !== undefined && { seed }),\n ...(adminControls !== undefined && { adminControls }),\n ...(onLog && { onLog }),\n })\n },\n },\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAmDO,SAAS,kBAAkB,YAGhC;AACA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,MAAM,SAAS,KAAK,EAAE,OAAO,YAAY,GAAG,EAAE,QAAQ,IAAI,CAAC;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