@reliantlabs/forge-web-runtime 0.13.2 → 0.13.4
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/dist/mock-rules.d.ts +61 -0
- package/dist/mock-rules.js +333 -0
- package/dist/mock-rules.js.map +1 -0
- package/dist/mock-transport.d.ts +8 -0
- package/dist/mock-transport.js +47 -15
- package/dist/mock-transport.js.map +1 -1
- package/dist/mock-values.d.ts +132 -0
- package/dist/mock-values.js +1222 -0
- package/dist/mock-values.js.map +1 -0
- package/dist/telemetry.js +156 -0
- package/dist/telemetry.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-transport.js","sourceRoot":"","sources":["../src/mock-transport.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,yEAAyE;AACzE,+CAA+C;AAC/C,EAAE;AACF,2DAA2D;AAC3D,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,sEAAsE;AACtE,4DAA4D;AAC5D,qEAAqE;AACrE,oEAAoE;AACpE,yEAAyE;AACzE,yEAAyE;AACzE,kDAAkD;AAClD,EAAE;AACF,uEAAuE;AACvE,4EAA4E;AAC5E,uEAAuE;AACvE,0EAA0E;AAC1E,oEAAoE;AACpE,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,yEAAyE;AACzE,sDAAsD;AACtD,uEAAuE;AACvE,gEAAgE;AAChE,sEAAsE;AACtE,uDAAuD;AACvD,EAAE;AACF,wEAAwE;AACxE,6EAA6E;AAC7E,gEAAgE;AAChE,qEAAqE;AACrE,gEAAgE;AAChE,EAAE;AACF,gFAAgF;AAChF,2EAA2E;AAC3E,wEAAwE;AACxE,4EAA4E;AAC5E,WAAW;AACX,OAAO,EACL,MAAM,EACN,SAAS,EACT,UAAU,GAKX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,8BAA8B,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C;AACnB,CAAC","sourcesContent":["// Part of @reliantlabs/forge-web-runtime — the web twin of forge/pkg.\n//\n// The mock transport ENGINE. A generated frontend used to carry this entire\n// pipeline as ~300 lines of Tier-1 scaffold; what varies per project is only\n// the table of entities to dispatch on, so the engine lives here and the\n// project keeps a declarative descriptor list.\n//\n// Dispatch order (unchanged from the scaffolded original):\n//\n// 1. A scenario selected via `?scenario=<name>` (or the auto-generated\n// `default` scenario) gets first crack at every unary RPC. Handlers\n// keyed by `${serviceTypeName}/${methodName}` return typed proto\n// messages and short-circuit the rest of the pipeline.\n// 2. If the active scenario has `passthrough: true` AND a fallback\n// transport was supplied (hybrid mode — VITE_MOCK_API=hybrid /\n// NEXT_PUBLIC_MOCK_API=hybrid), unmatched RPCs are forwarded to the\n// real backend. This lets one scenario stub a single endpoint while\n// everything else exercises the live server.\n//\n// `passthrough: \"first\"` turns that around: EVERY RPC goes to the\n// backend first, and the scenario (then the fixtures) answer only when\n// it fails or exceeds `passthroughTimeoutMs`. That is a demo or a\n// preview on live data that degrades to sample data instead of to an\n// error page — and `onPassthroughFallback` lets the UI say so.\n//\n// 0. Before any of it, `readOnly` refuses every RPC that is not a read\n// (by default: not marked `idempotency_level = NO_SIDE_EFFECTS`) with\n// PermissionDenied, so neither a handler, a fixture nor the backend\n// ever sees a write — a public demo's guarantee.\n// 3. Otherwise RPCs not overridden fall through to the deterministic\n// per-entity fixtures described by the entity descriptors.\n// 4. Anything else rejects with Code.Unimplemented so callers see a\n// clear error instead of a silent empty response.\n//\n// A fixture List answers the way the backend's generated CRUD List does\n// (pkg/crud HandleList), so a filtered table, a paged table and a \"how many\"\n// tile read the same against fixtures as against a server — see\n// `serveList` for the exact contract. Custom (non-CRUD) RPCs are not\n// interpreted at all; they stay hand-written scenario handlers.\n//\n// Imported through the \"@reliantlabs/forge-web-runtime/mock-transport\" subpath,\n// never the barrel: a production bundle must be able to shake the fixtures\n// and this engine out entirely, which is why the generated `connect.ts`\n// reaches its own shim through a dynamic `require()` gated on the mock-mode\n// env var.\nimport {\n create,\n isMessage,\n ScalarType,\n type DescField,\n type DescMessage,\n type DescMethod,\n type MessageInitShape,\n} from \"@bufbuild/protobuf\";\nimport { MethodOptions_IdempotencyLevel } from \"@bufbuild/protobuf/wkt\";\nimport {\n Code,\n ConnectError,\n type Transport,\n type UnaryResponse,\n} from \"@connectrpc/connect\";\n\n/**\n * The shape the generated scenario files satisfy. Structural on purpose: the\n * project's own `Scenario` type (src/mocks/scenario-types.ts) carries a\n * richer, per-RPC-typed `handlers` map, and this is the subset the engine\n * dispatches through.\n */\nexport interface MockScenario {\n name: string;\n /** Per-RPC overrides keyed by `${serviceTypeName}/${methodName}`. */\n handlers: Record<string, ((req: never) => unknown) | undefined>;\n /**\n * `true`: forward RPCs no handler matches to the real backend (hybrid mode\n * only). `\"first\"`: forward EVERY RPC, and answer from the handlers and\n * fixtures only when the backend fails — see the dispatch notes above.\n */\n passthrough?: boolean | \"first\";\n /** Non-RPC side effects, run once before the first RPC fires. */\n setup?: () => void;\n}\n\n/** The generated `src/mocks/scenarios` barrel, as the engine consumes it. */\nexport interface MockScenarioRegistry {\n byName(name: string): MockScenario | undefined;\n defaultScenario: MockScenario;\n}\n\n/**\n * One CRUD arm of an entity's dispatch table.\n *\n * The List arm needs nothing beyond these three fields to honour filters,\n * paging and total_count: the REQUEST schema arrives on every call as the\n * Connect method's `input`, and the entity schema is the element type of\n * `itemsField` on `responseSchema`.\n */\nexport interface MockListRpc {\n rpc: string;\n responseSchema: DescMessage;\n /**\n * The camelCase name of the list response's repeated field — the ACTUAL\n * proto field (e.g. `keys`), not the camelCased entity plural.\n */\n itemsField: string;\n}\n\nexport interface MockGetRpc {\n rpc: string;\n responseSchema: DescMessage;\n /** The camelCase field wrapping the entity on the response message. */\n entityField: string;\n}\n\nexport interface MockWriteRpc extends MockGetRpc {\n /**\n * The camelCase field wrapping the entity on the REQUEST message. AIP-134\n * requests nest the entity ({ item: {...}, updateMask }); the generated\n * forms submit it flattened. Both are accepted.\n */\n requestField: string;\n}\n\nexport interface MockDeleteRpc {\n rpc: string;\n}\n\n/**\n * Everything the engine needs to serve one entity's CRUD quintet from\n * fixtures. Generated into `src/lib/mock-transport.ts` from the project's\n * proto descriptors.\n */\nexport interface MockEntityDescriptor {\n /** Fully-qualified proto service name, e.g. \"demo.v1.ClinicService\". */\n service: string;\n /** Lowercase entity name, used verbatim in the NotFound message. */\n label: string;\n /**\n * The camelCase PRIMARY-KEY field. The session store keys records by this\n * field; hardcoding \"id\" breaks every surrogate-PK entity (a\n * `usage_event_id` PK projects to a message with no `id` field).\n */\n pkField: string;\n /** Deterministic seed rows — the same values the dev database is seeded with. */\n fixtures: readonly unknown[];\n /** The entity message schema. Required by the create/update write paths. */\n entitySchema?: DescMessage;\n list?: MockListRpc;\n get?: MockGetRpc;\n create?: MockWriteRpc;\n update?: MockWriteRpc;\n delete?: MockDeleteRpc;\n}\n\nexport interface CreateMockTransportOptions {\n /** The resolved scenario — see {@link resolveActiveScenario}. */\n scenario: MockScenario;\n /** Per-entity fixture dispatch. Omit for a scenario-only project. */\n entities?: readonly MockEntityDescriptor[];\n /**\n * Optional real Connect transport. When the active scenario declares\n * `passthrough: true`, any RPC not matched by a scenario handler is\n * forwarded here instead of falling through to the fixtures.\n */\n fallback?: Transport;\n /**\n * Refuse every RPC that is not a read, with PermissionDenied, before any\n * handler, fixture or backend sees it. `true` classifies by the proto's\n * `idempotency_level = NO_SIDE_EFFECTS`; a function classifies itself (a\n * contract that does not annotate idempotency, e.g. by method name).\n */\n readOnly?: boolean | ((method: DescMethod) => boolean);\n /** The message a refused write carries. Default names the RPC. */\n readOnlyMessage?: string;\n /**\n * With `passthrough: \"first\"`: the forwarded call's deadline in ms, after\n * which the scenario answers instead. Default: the caller's own timeout.\n * Enforced by the mock transport itself, so a fallback transport that\n * ignores its timeout cannot hold the call open; a server stream must END\n * within it to count as the backend's answer.\n */\n passthroughTimeoutMs?: number;\n /**\n * With `passthrough: \"first\"`: called each time the backend failed (or\n * timed out) and the mock answered instead. A caller's own abort is never\n * a fallback: it rejects as it would against the backend.\n */\n onPassthroughFallback?: (key: string, error: ConnectError) => void;\n}\n\n/** Options for {@link resolveActiveScenario}. */\nexport interface ResolveScenarioOptions {\n /**\n * The scenario to run, chosen by the app (its host, its runtime config)\n * instead of the URL. When the key is present — even as null or \"\" — the\n * `?scenario=` parameter is NOT read; null/\"\"/unknown select the default.\n */\n name?: string | null;\n}\n\n/**\n * Mutable session stores, keyed by descriptor identity.\n *\n * Create/Update/Delete round-trip within one browser session (a created row\n * appears in the next List; a deleted one disappears) and reset to the\n * deterministic fixtures on reload. The scaffolded original got that from\n * module-scope `const store = new Map(...)`; keying off the descriptor\n * object preserves it — a module-level descriptor array hands back the same\n * store on every call, so building the transport twice (hybrid mode, a test\n * swapping transports) does not silently fork the data.\n */\nconst stores = new WeakMap<MockEntityDescriptor, Map<string, unknown>>();\n\nfunction storeFor(entity: MockEntityDescriptor): Map<string, unknown> {\n let store = stores.get(entity);\n if (!store) {\n store = new Map(\n entity.fixtures.map((row) => [\n String((row as Record<string, unknown>)[entity.pkField]),\n row,\n ]),\n );\n stores.set(entity, store);\n }\n return store;\n}\n\n/** Scenarios whose `setup()` has already run. */\nconst initialized = new WeakSet<MockScenario>();\n\n/**\n * Resolve the scenario the app should run under, and run its `setup()` once.\n *\n * Call this at MODULE SCOPE (the generated `src/lib/mock-transport.ts` does).\n * Reading the URL once — rather than on every RPC — means navigating away\n * from `?scenario=` keeps the scenario active until a full reload, matching\n * the agent-driven flow where the URL is the single source of truth.\n *\n * `setup()` is for non-RPC state (localStorage flags, sessionStorage). It is\n * synchronous and makes no network calls.\n */\nexport function resolveActiveScenario(\n registry: MockScenarioRegistry,\n options: ResolveScenarioOptions = {},\n): MockScenario {\n const requested =\n \"name\" in options\n ? (options.name ?? null)\n : typeof globalThis !== \"undefined\" && globalThis.location\n ? new URLSearchParams(globalThis.location.search).get(\"scenario\")\n : null;\n // A ternary, not `&&`: with `??` alone the empty-string falsy branch leaks\n // '' into the inferred union, and '' survives `??` (which only replaces\n // null/undefined), so downstream access on .setup / .handlers would fail\n // under strict tsc.\n const active =\n (requested ? registry.byName(requested) : undefined) ??\n registry.defaultScenario;\n\n if (!initialized.has(active)) {\n initialized.add(active);\n active.setup?.();\n }\n return active;\n}\n\n/**\n * Normalize whatever a streaming scenario handler returns into an\n * AsyncIterable<unknown>. Accepts arrays, iterables, async iterables, and\n * promises that resolve to any of the above. Single (non-iterable) values\n * are wrapped as a one-element stream — handy for handlers that conceptually\n * yield once.\n */\nexport async function* toAsyncIterable(value: unknown): AsyncIterable<unknown> {\n const resolved = await Promise.resolve(value);\n if (resolved == null) return;\n // AsyncIterable\n if (\n typeof (resolved as { [Symbol.asyncIterator]?: unknown })[\n Symbol.asyncIterator\n ] === \"function\"\n ) {\n for await (const m of resolved as AsyncIterable<unknown>) yield m;\n return;\n }\n // Iterable (including arrays)\n if (\n typeof (resolved as { [Symbol.iterator]?: unknown })[Symbol.iterator] ===\n \"function\"\n ) {\n for (const m of resolved as Iterable<unknown>) yield m;\n return;\n }\n // Single value\n yield resolved;\n}\n\nfunction makeUnaryResponse<T>(\n method: { name: string; parent: { typeName: string }; output?: DescMessage },\n message: T,\n): UnaryResponse<never, never> {\n return {\n service: method.parent as never,\n method: method as never,\n stream: false,\n header: new Headers(),\n message: asResponseMessage(method.output, message) as never,\n trailer: new Headers(),\n };\n}\n\n/**\n * A handler may return the response as a plain init object\n * (`{ items: [...] }`) instead of `create(Schema, {...})`. A real client\n * always receives a full message — every repeated field an array, every\n * scalar its zero value — so a plain object is completed against the\n * method's output schema here; without that, `res.items.map` on a field the\n * handler left out throws in the UI and nowhere near the scenario.\n */\nfunction asResponseMessage(\n output: DescMessage | undefined,\n value: unknown,\n): unknown {\n if (!output || value == null || typeof value !== \"object\") return value;\n if (isMessage(value)) return value;\n return create(output, value as MessageInitShape<DescMessage>);\n}\n\n/** The default read-only classification: the proto says the method has no side effects. */\nfunction isRead(method: DescMethod): boolean {\n return method.idempotency === MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS;\n}\n\n/**\n * A fixture-backed handler for one RPC key. `requestSchema` is the Connect\n * method's input descriptor — absent only when a caller hand-builds a method\n * object without one, in which case List serves paging alone.\n */\ntype FixtureHandler = (\n input: unknown,\n requestSchema: DescMessage | undefined,\n) => unknown;\n\n// ── List semantics ─────────────────────────────────────────────────────\n//\n// What the backend's generated List does, and therefore what the fixture\n// List does (pkg/crud HandleList + the generated Filters closure):\n//\n// - Every `optional` request field that is SET filters by equality on the\n// entity field of the same name. Enums compare by value. A field with\n// IMPLICIT presence (no `optional`) is never a filter — the backend\n// generates none for it, so the mock must not invent one.\n// - `search` matches case-insensitively against the entity's string\n// fields and enum value names (enum columns are stored as names).\n// - `order_by` (snake_case column, comma-separated, optional ASC/DESC per\n// column) plus `descending` sorts; an unknown column is InvalidArgument.\n// - `page_size` defaults to 50 and is clamped to 100. `total_count` is the\n// filtered count BEFORE paging. `next_page_token` is minted only for the\n// default (primary-key) order — an ordered list is single-page on the\n// backend, and a mock that paged it would hide that.\n//\n// Paging, ordering and search arrive through these request fields, by the\n// names forge's CRUD List requests declare. They are never equality filters.\nconst LIST_CONTROL_FIELDS = new Set([\n \"pageSize\",\n \"pageToken\",\n \"orderBy\",\n \"descending\",\n \"search\",\n]);\n\n/** pkg/crud ListOp's defaults: 0 means 50, and no page exceeds 100. */\nconst DEFAULT_PAGE_SIZE = 50;\nconst MAX_PAGE_SIZE = 100;\n\n/** FeatureSet_FieldPresence.EXPLICIT — proto3 `optional`, oneofs, messages. */\nconst EXPLICIT_PRESENCE = 1;\n\ntype Row = Record<string, unknown>;\n\n/** The entity message a List response repeats, read off its descriptor. */\nfunction listItemSchema(list: MockListRpc): DescMessage | undefined {\n const items = list.responseSchema.field[list.itemsField];\n return items?.fieldKind === \"list\" && items.listKind === \"message\"\n ? items.message\n : undefined;\n}\n\n/** Scalars and enums compare by value; messages, bytes, lists and maps do not. */\nfunction isComparable(field: DescField): boolean {\n if (field.fieldKind === \"enum\") return true;\n return field.fieldKind === \"scalar\" && field.scalar !== ScalarType.BYTES;\n}\n\nfunction sameValue(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n // A 64-bit field is a bigint — or a string under jstype=JS_STRING — and\n // the two sides are not guaranteed to agree on which.\n if (a == null || b == null) return false;\n return (\n (typeof a === \"bigint\" || typeof b === \"bigint\") && String(a) === String(b)\n );\n}\n\nfunction enumName(field: DescField, value: unknown): string | undefined {\n return field.fieldKind === \"enum\"\n ? field.enum.values.find((v) => v.number === value)?.name\n : undefined;\n}\n\n/** The value a column sorts by, as Postgres would order the stored column. */\nfunction sortKey(field: DescField, value: unknown): unknown {\n if (value == null) return undefined;\n // Enum columns hold the value NAME, so they sort alphabetically by name.\n if (field.fieldKind === \"enum\") return enumName(field, value) ?? \"\";\n if (field.fieldKind === \"scalar\") return value;\n if (\n field.fieldKind === \"message\" &&\n field.message.typeName === \"google.protobuf.Timestamp\"\n ) {\n const ts = value as { seconds: bigint; nanos: number };\n return BigInt(ts.seconds) * 1_000_000_000n + BigInt(ts.nanos);\n }\n return undefined;\n}\n\n/** Postgres's default: NULL sorts after every value ascending. */\nfunction compareKeys(a: unknown, b: unknown): number {\n if (a === undefined || b === undefined) {\n return a === b ? 0 : a === undefined ? 1 : -1;\n }\n const x = a as string | number | bigint | boolean;\n const y = b as string | number | bigint | boolean;\n return x < y ? -1 : x > y ? 1 : 0;\n}\n\nfunction invalidArgument(message: string): ConnectError {\n return new ConnectError(`mock-transport: ${message}`, Code.InvalidArgument);\n}\n\n/** Parse `order_by` the way orm.ValidateOrderBy reads it. */\nfunction parseOrderBy(\n clause: string,\n descending: boolean,\n itemSchema: DescMessage,\n): { field: DescField; desc: boolean }[] {\n return clause.split(\",\").map((part) => {\n const [column = \"\", direction] = part.trim().split(/\\s+/);\n const field = itemSchema.fields.find(\n (f) => f.name === column || f.localName === column,\n );\n if (!field) {\n throw invalidArgument(`unknown order-by column \"${column}\"`);\n }\n const dir = direction?.toUpperCase();\n if (dir !== undefined && dir !== \"ASC\" && dir !== \"DESC\") {\n throw invalidArgument(`invalid order-by direction \"${direction}\"`);\n }\n return { field, desc: dir === undefined ? descending : dir === \"DESC\" };\n });\n}\n\n/** A count in whatever JS type the response's total_count field takes. */\nfunction countValue(field: DescField, n: number): unknown {\n if (field.fieldKind !== \"scalar\") return n;\n switch (field.scalar) {\n case ScalarType.INT64:\n case ScalarType.UINT64:\n case ScalarType.SINT64:\n case ScalarType.FIXED64:\n case ScalarType.SFIXED64:\n return field.longAsString ? String(n) : BigInt(n);\n default:\n return n;\n }\n}\n\n/**\n * Answer one List call from the entity's rows. See the List semantics note\n * above for the contract; the engine's tests pin each clause.\n */\nfunction serveList(\n rows: readonly unknown[],\n list: MockListRpc,\n input: unknown,\n requestSchema: DescMessage | undefined,\n): unknown {\n const req = (input ?? {}) as Row;\n const itemSchema = listItemSchema(list);\n let matched = rows as readonly Row[];\n\n if (itemSchema && requestSchema) {\n for (const filter of requestSchema.fields) {\n if (LIST_CONTROL_FIELDS.has(filter.localName)) continue;\n if (filter.presence !== EXPLICIT_PRESENCE || !isComparable(filter)) {\n continue;\n }\n const want = req[filter.localName];\n if (want == null) continue; // unset: no filter\n const target = itemSchema.field[filter.localName];\n if (!target || !isComparable(target)) continue;\n matched = matched.filter((row) => sameValue(row[filter.localName], want));\n }\n }\n\n const search =\n typeof req.search === \"string\" ? req.search.trim().toLowerCase() : \"\";\n if (itemSchema && search) {\n const searchable = itemSchema.fields.filter(\n (f) =>\n f.fieldKind === \"enum\" ||\n (f.fieldKind === \"scalar\" && f.scalar === ScalarType.STRING),\n );\n matched = matched.filter((row) =>\n searchable.some((f) => {\n const value = row[f.localName];\n const text = f.fieldKind === \"enum\" ? enumName(f, value) : value;\n return typeof text === \"string\" && text.toLowerCase().includes(search);\n }),\n );\n }\n\n const orderBy = typeof req.orderBy === \"string\" ? req.orderBy.trim() : \"\";\n if (itemSchema && orderBy) {\n const keys = parseOrderBy(orderBy, req.descending === true, itemSchema);\n matched = [...matched].sort((a, b) => {\n for (const { field, desc } of keys) {\n const c = compareKeys(\n sortKey(field, a[field.localName]),\n sortKey(field, b[field.localName]),\n );\n if (c !== 0) return desc ? -c : c;\n }\n return 0;\n });\n }\n\n const total = matched.length;\n\n let offset = 0;\n const token = typeof req.pageToken === \"string\" ? req.pageToken : \"\";\n if (token) {\n // The mock's own cursor: an offset into the filtered rows. Opaque to the\n // client, exactly like the backend's keyset cursor.\n if (!/^\\d+$/.test(token)) throw invalidArgument(\"invalid page token\");\n offset = Number(token);\n }\n const requested = Number(req.pageSize ?? 0);\n const pageSize =\n requested > 0 ? Math.min(requested, MAX_PAGE_SIZE) : DEFAULT_PAGE_SIZE;\n const end = offset + pageSize;\n\n const init: Row = { [list.itemsField]: matched.slice(offset, end) };\n const totalField = list.responseSchema.field.totalCount;\n if (totalField) init.totalCount = countValue(totalField, total);\n if (list.responseSchema.field.nextPageToken && !orderBy && end < total) {\n init.nextPageToken = String(end);\n }\n return create(list.responseSchema, init as MessageInitShape<DescMessage>);\n}\n\n/**\n * Compile the entity descriptors into a flat `${service}/${rpc}` → handler\n * map. Building it once per transport keeps per-RPC dispatch to a single\n * lookup, exactly like the generated `switch` it replaces.\n */\nfunction buildFixtureTable(\n entities: readonly MockEntityDescriptor[],\n): Map<string, FixtureHandler> {\n const table = new Map<string, FixtureHandler>();\n\n for (const entity of entities) {\n const pk = entity.pkField;\n const key = (rpc: string) => `${entity.service}/${rpc}`;\n\n if (entity.list) {\n const list = entity.list;\n table.set(key(list.rpc), (input, requestSchema) =>\n serveList(\n Array.from(storeFor(entity).values()),\n list,\n input,\n requestSchema,\n ),\n );\n }\n\n if (entity.get) {\n const { rpc, responseSchema, entityField } = entity.get;\n table.set(key(rpc), (input) => {\n // Read the key off the SAME field the store is keyed by, not a\n // hardcoded `id` — a surrogate-PK entity would otherwise look up\n // String(undefined) and miss every record.\n const req = input as Record<string, unknown> | undefined;\n const found = storeFor(entity).get(String(req?.[pk]));\n if (!found) {\n // A miss is NotFound — exactly what the real backend returns.\n // (Falling back to the first fixture made every detail page\n // \"work\" against the wrong record and hid bad-id bugs.)\n throw new ConnectError(\n `${entity.label} ${String(req?.[pk])} not found`,\n Code.NotFound,\n );\n }\n return create(responseSchema, {\n [entityField]: found,\n } as MessageInitShape<DescMessage>);\n });\n }\n\n if (entity.create && entity.entitySchema) {\n const { rpc, responseSchema, entityField, requestField } = entity.create;\n const entitySchema = entity.entitySchema;\n table.set(key(rpc), (input) => {\n // Create requests carry the entity fields flattened (that's how the\n // generated form submits); a nested { <entity>: {...} } payload is\n // accepted too.\n const req = (input ?? {}) as Record<string, unknown>;\n const init = {\n ...((req[requestField] ?? req) as Record<string, unknown>),\n };\n delete init.$typeName;\n // Mint the primary key on the PK field the store is keyed by — for a\n // surrogate-PK entity this is NOT `id`, and writing a generated `id`\n // would leave the store key undefined so the row never round-trips.\n const id =\n typeof init[pk] === \"string\" && init[pk]\n ? (init[pk] as string)\n : crypto.randomUUID();\n const created = create(entitySchema, {\n ...init,\n [pk]: id,\n } as MessageInitShape<DescMessage>);\n storeFor(entity).set(String(id), created);\n return create(responseSchema, {\n [entityField]: created,\n } as MessageInitShape<DescMessage>);\n });\n }\n\n if (entity.update && entity.entitySchema) {\n const { rpc, responseSchema, entityField, requestField } = entity.update;\n const entitySchema = entity.entitySchema;\n table.set(key(rpc), (input) => {\n const req = (input ?? {}) as Record<string, unknown>;\n // AIP-134 requests wrap the entity ({ <entity>: {...}, updateMask })\n // — the id lives inside the wrapper; flat requests carry it at the\n // top level.\n const patch = {\n ...((req[requestField] ?? req) as Record<string, unknown>),\n };\n delete patch.$typeName;\n const id = String(patch[pk] ?? req[pk] ?? \"\");\n const store = storeFor(entity);\n const existing = store.get(id);\n if (!existing) {\n throw new ConnectError(\n `${entity.label} ${id} not found`,\n Code.NotFound,\n );\n }\n const updated = create(entitySchema, {\n ...(existing as Record<string, unknown>),\n ...patch,\n [pk]: id,\n } as MessageInitShape<DescMessage>);\n store.set(id, updated);\n return create(responseSchema, {\n [entityField]: updated,\n } as MessageInitShape<DescMessage>);\n });\n }\n\n if (entity.delete) {\n table.set(key(entity.delete.rpc), (input) => {\n // Delete by the SAME field the store is keyed by.\n const req = input as Record<string, unknown> | undefined;\n storeFor(entity).delete(String(req?.[pk]));\n // Delete returns an empty response — the standard CRUD shape.\n return {};\n });\n }\n }\n\n return table;\n}\n\n/**\n * Create the mock transport.\n *\n * The generated `src/lib/mock-transport.ts` supplies the resolved scenario\n * and the project's entity descriptors; `connect.ts` supplies the optional\n * real transport when running in hybrid mode.\n */\nexport function createMockTransport(\n options: CreateMockTransportOptions,\n): Transport {\n const {\n scenario,\n entities = [],\n fallback,\n readOnly,\n passthroughTimeoutMs,\n onPassthroughFallback,\n } = options;\n const passthrough = scenario.passthrough === true && fallback != null;\n const first = scenario.passthrough === \"first\" && fallback != null;\n const fixtures = buildFixtureTable(entities);\n const readsOnly = typeof readOnly === \"function\" ? readOnly : isRead;\n\n // 0) The read-only guard: before any dispatch, so a write never reaches a\n // handler, a fixture store or the backend.\n const guard = (method: DescMethod, key: string) => {\n if (readOnly && !readsOnly(method)) {\n throw new ConnectError(\n options.readOnlyMessage ?? `mock-transport: ${key} is not a read`,\n Code.PermissionDenied,\n );\n }\n };\n // \"first\": the backend's answer, or undefined when the mock should answer.\n //\n // The deadline is enforced HERE, not left to the fallback transport: the\n // attempt gets its own signal (aborted by the caller's signal or by the\n // timer) and is raced against that signal, so a transport that ignores\n // both its timeout and its signal still cannot hold the call open. A\n // caller's own abort is rethrown; only the deadline or a failure falls back.\n const tryBackend = async <R>(\n key: string,\n signal: AbortSignal | undefined,\n timeoutMs: number | undefined,\n call: (signal: AbortSignal) => Promise<R>,\n ): Promise<R | undefined> => {\n const attempt = new AbortController();\n const abortAttempt = () => attempt.abort(signal?.reason);\n if (signal?.aborted) abortAttempt();\n signal?.addEventListener(\"abort\", abortAttempt, { once: true });\n const timer =\n timeoutMs != null && timeoutMs > 0\n ? setTimeout(\n () =>\n attempt.abort(\n new ConnectError(\n `mock-transport: ${key} exceeded ${timeoutMs}ms`,\n Code.DeadlineExceeded,\n ),\n ),\n timeoutMs,\n )\n : undefined;\n const abandoned = new Promise<never>((_, reject) => {\n const fail = () => reject(attempt.signal.reason);\n if (attempt.signal.aborted) fail();\n else attempt.signal.addEventListener(\"abort\", fail, { once: true });\n });\n // The race observes it; this keeps the release below from surfacing as\n // an unhandled rejection after the race has settled.\n abandoned.catch(() => undefined);\n try {\n return await Promise.race([call(attempt.signal), abandoned]);\n } catch (err) {\n if (signal?.aborted) throw err;\n onPassthroughFallback?.(key, ConnectError.from(err));\n return undefined;\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n signal?.removeEventListener(\"abort\", abortAttempt);\n // Release whatever the backend attempt still holds (a pending fetch,\n // an unread stream) once it has been answered or abandoned.\n attempt.abort();\n }\n };\n\n // Bind the object literal to a Transport-typed variable rather than\n // casting at the return site. A trailing assertion cast does not propagate\n // Connect's Transport signature backwards into the literal's method\n // bodies, so under `strict` tsc every callback parameter on unary/stream\n // errors with TS7006 (\"implicitly has an 'any' type\").\n const transport: Transport = {\n // Connect v2's Transport.unary signature is\n // (method, signal, timeoutMs, header, input, contextValues)\n // — method first, no separate service arg. `method.parent.typeName` is\n // the fully-qualified service name; that is what handler keys and\n // fixture keys are matched against.\n async unary(method, signal, timeoutMs, header, input, contextValues) {\n const key = `${method.parent.typeName}/${method.name}`;\n guard(method, key);\n\n // 0b) \"first\": the backend answers unless it fails.\n if (first) {\n const deadline = passthroughTimeoutMs ?? timeoutMs;\n const live = await tryBackend(key, signal, deadline, (attempt) =>\n fallback!.unary(\n method,\n attempt,\n deadline,\n header,\n input,\n contextValues,\n ),\n );\n if (live) return live;\n }\n\n // 1) Scenario overlay.\n const handler = scenario.handlers[key];\n if (handler) {\n const result = await handler(input as never);\n return makeUnaryResponse(method, result);\n }\n\n // 2) Passthrough: route to the real backend instead of fixtures.\n // Skips fixtures entirely — in hybrid mode the whole point is\n // \"use real data for anything not explicitly stubbed\".\n if (passthrough) {\n return fallback!.unary(\n method,\n signal,\n timeoutMs,\n header,\n input,\n contextValues,\n );\n }\n\n // 3) Base fixture dispatch, backed by the mutable per-entity stores so\n // writes round-trip within the session. Misses are REAL errors\n // (Code.NotFound), never a silent wrong-record fallback.\n const fixture = fixtures.get(key);\n if (fixture) {\n // `method.input` is typed as always present, but a hand-built method\n // object (a test, a custom harness) may omit it.\n const requestSchema = (method as { input?: DescMessage }).input;\n return makeUnaryResponse(method, fixture(input, requestSchema));\n }\n\n // 4) Nothing matched. Surface a clear error instead of hanging.\n return Promise.reject(\n new ConnectError(\n `mock-transport: no scenario handler or entity fixture for ${key}`,\n Code.Unimplemented,\n ),\n );\n },\n\n // Streaming: a scenario handler can return an array, iterable, async\n // iterable, or a Promise resolving to any of those. The transport adapts\n // it into the AsyncIterable<Response> shape Connect expects. If no\n // handler matches, reject with Unimplemented — base-fixture streaming is\n // intentionally not served (there is no canonical \"list of N messages\"\n // shape for an arbitrary streaming RPC).\n //\n // No explicit return-type annotation: the outer `const transport:\n // Transport` binding lets tsc infer the per-callback signature from\n // Connect's generic Transport.stream<I, O>. Annotating this as\n // Promise<StreamResponse<never, never>> makes the passthrough branch\n // ill-typed (TS2322) because fallback.stream returns StreamResponse<I,O>.\n async stream(method, signal, timeoutMs, header, input, contextValues) {\n const key = `${method.parent.typeName}/${method.name}`;\n guard(method, key);\n // \"first\" forwards server streams only: a client-streaming request is\n // consumed by the attempt and could not be replayed to the handler.\n //\n // The backend's stream is read to its END, within the deadline, before\n // it counts as an answer, then replayed: a stream that fails or stalls\n // after its headers arrived still falls back to the mock, as a unary\n // call does. So \"first\" suits finite server streams; a stream that\n // never ends always answers from the mock once the deadline passes.\n if (first && method.methodKind === \"server_streaming\") {\n const deadline = passthroughTimeoutMs ?? timeoutMs;\n const live = await tryBackend(\n key,\n signal,\n deadline,\n async (attempt) => {\n const res = await fallback!.stream(\n method,\n attempt,\n deadline,\n header,\n input,\n contextValues,\n );\n const messages: unknown[] = [];\n for await (const m of res.message) messages.push(m);\n return {\n ...res,\n message: toAsyncIterable(messages) as typeof res.message,\n };\n },\n );\n if (live) return live;\n }\n const handler = scenario.handlers[key];\n if (!handler) {\n // Passthrough mirrors the unary path: in hybrid mode, unmatched\n // streaming RPCs go to the real backend.\n if (passthrough) {\n return fallback!.stream(\n method,\n signal,\n timeoutMs,\n header,\n input,\n contextValues,\n );\n }\n return Promise.reject(\n new ConnectError(\n `mock-transport: no scenario handler for streaming RPC ${key}`,\n Code.Unimplemented,\n ),\n );\n }\n // Read the request stream eagerly into an array so the scenario handler\n // sees the full client-streaming payload. For server-stream and\n // unary-into-stream-out RPCs this is a single message.\n const requestMessages: unknown[] = [];\n try {\n for await (const m of input as AsyncIterable<unknown>) {\n requestMessages.push(m);\n }\n } catch {\n // Synthetic clients sometimes pass a single value rather than an\n // iterable; treat that as an empty request payload.\n }\n const handlerInput =\n requestMessages.length <= 1 ? requestMessages[0] : requestMessages;\n const result = handler(handlerInput as never);\n return {\n service: method.parent as never,\n method: method as never,\n stream: true,\n header: new Headers(),\n message: toAsyncIterable(result) as AsyncIterable<never>,\n trailer: new Headers(),\n };\n },\n };\n return transport;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mock-transport.js","sourceRoot":"","sources":["../src/mock-transport.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,yEAAyE;AACzE,+CAA+C;AAC/C,EAAE;AACF,2DAA2D;AAC3D,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,sEAAsE;AACtE,4DAA4D;AAC5D,qEAAqE;AACrE,oEAAoE;AACpE,yEAAyE;AACzE,yEAAyE;AACzE,kDAAkD;AAClD,EAAE;AACF,uEAAuE;AACvE,4EAA4E;AAC5E,uEAAuE;AACvE,0EAA0E;AAC1E,oEAAoE;AACpE,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,yEA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C9C,OAAO;gBACL,OAAO,EAAE,MAAM,CAAC,MAAe;gBAC/B,MAAM,EAAE,MAAe;gBACvB,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,IAAI,OAAO,EAAE;gBACrB,OAAO,EAAE,eAAe,CAAC,MAAM,CAAyB;gBACxD,OAAO,EAAE,IAAI,OAAO,EAAE;aACvB,CAAC;QACJ,CAAC;KACF,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Part of @reliantlabs/forge-web-runtime — the web twin of forge/pkg.\n//\n// The mock transport ENGINE. A generated frontend used to carry this entire\n// pipeline as ~300 lines of Tier-1 scaffold; what varies per project is only\n// the table of entities to dispatch on, so the engine lives here and the\n// project keeps a declarative descriptor list.\n//\n// Dispatch order (unchanged from the scaffolded original):\n//\n// 1. A scenario selected via `?scenario=<name>` (or the auto-generated\n// `default` scenario) gets first crack at every unary RPC. Handlers\n// keyed by `${serviceTypeName}/${methodName}` return typed proto\n// messages and short-circuit the rest of the pipeline.\n// 2. If the active scenario has `passthrough: true` AND a fallback\n// transport was supplied (hybrid mode — VITE_MOCK_API=hybrid /\n// NEXT_PUBLIC_MOCK_API=hybrid), unmatched RPCs are forwarded to the\n// real backend. This lets one scenario stub a single endpoint while\n// everything else exercises the live server.\n//\n// `passthrough: \"first\"` turns that around: EVERY RPC goes to the\n// backend first, and the scenario (then the fixtures) answer only when\n// it fails or exceeds `passthroughTimeoutMs`. That is a demo or a\n// preview on live data that degrades to sample data instead of to an\n// error page — and `onPassthroughFallback` lets the UI say so.\n//\n// 0. Before any of it, `readOnly` refuses every RPC that is not a read\n// (by default: not marked `idempotency_level = NO_SIDE_EFFECTS`) with\n// PermissionDenied, so neither a handler, a fixture nor the backend\n// ever sees a write — a public demo's guarantee.\n// 3. Otherwise RPCs not overridden fall through to the deterministic\n// per-entity fixtures described by the entity descriptors.\n// 4. Then to the service DEFAULTS (`services`, see mock-values.ts): a\n// deterministic, schema-valid response built from the RPC's descriptor,\n// for any RPC of any service the app's generated TypeScript covers —\n// custom reads, vendored contracts and streams included.\n// 5. Anything else rejects with Code.Unimplemented so callers see a\n// clear error instead of a silent empty response.\n//\n// A fixture List answers the way the backend's generated CRUD List does\n// (pkg/crud HandleList), so a filtered table, a paged table and a \"how many\"\n// tile read the same against fixtures as against a server — see\n// `serveList` for the exact contract. Custom (non-CRUD) RPCs are not\n// interpreted: their defaults are shape-valid sample data, and what a page\n// needs to SAY is a scenario override (`mockService`, mock-values.ts).\n//\n// Imported through the \"@reliantlabs/forge-web-runtime/mock-transport\" subpath,\n// never the barrel: a production bundle must be able to shake the fixtures\n// and this engine out entirely, which is why the generated `connect.ts`\n// reaches its own shim through a dynamic `require()` gated on the mock-mode\n// env var.\nimport {\n create,\n isMessage,\n ScalarType,\n type DescField,\n type DescMessage,\n type DescMethod,\n type MessageInitShape,\n} from \"@bufbuild/protobuf\";\nimport { MethodOptions_IdempotencyLevel } from \"@bufbuild/protobuf/wkt\";\nimport {\n Code,\n ConnectError,\n type Transport,\n type UnaryResponse,\n} from \"@connectrpc/connect\";\n\nimport type { AnyServiceDefaults } from \"./mock-values.js\";\n\nexport {\n isServiceDefaults,\n mockFactory,\n mockService,\n mockValue,\n patch,\n serviceDefaults,\n type AnyServiceDefaults,\n type DefaultHandler,\n type MockFactory,\n type MockFactoryContext,\n type MockHandlers,\n type MockOverride,\n type MockOverrides,\n type MockRequest,\n type MockResult,\n type MockValueOptions,\n type PatchShape,\n type ServiceDefaults,\n} from \"./mock-values.js\";\n\n/**\n * The shape the generated scenario files satisfy. Structural on purpose: the\n * project's own `Scenario` type (src/mocks/scenario-types.ts) carries a\n * richer, per-RPC-typed `handlers` map, and this is the subset the engine\n * dispatches through.\n */\nexport interface MockScenario {\n name: string;\n /** Per-RPC overrides keyed by `${serviceTypeName}/${methodName}`. */\n handlers: Record<string, ((req: never) => unknown) | undefined>;\n /**\n * `true`: forward RPCs no handler matches to the real backend (hybrid mode\n * only). `\"first\"`: forward EVERY RPC, and answer from the handlers and\n * fixtures only when the backend fails — see the dispatch notes above.\n */\n passthrough?: boolean | \"first\";\n /** Non-RPC side effects, run once before the first RPC fires. */\n setup?: () => void;\n}\n\n/** The generated `src/mocks/scenarios` barrel, as the engine consumes it. */\nexport interface MockScenarioRegistry {\n byName(name: string): MockScenario | undefined;\n defaultScenario: MockScenario;\n}\n\n/**\n * One CRUD arm of an entity's dispatch table.\n *\n * The List arm needs nothing beyond these three fields to honour filters,\n * paging and total_count: the REQUEST schema arrives on every call as the\n * Connect method's `input`, and the entity schema is the element type of\n * `itemsField` on `responseSchema`.\n */\nexport interface MockListRpc {\n rpc: string;\n responseSchema: DescMessage;\n /**\n * The camelCase name of the list response's repeated field — the ACTUAL\n * proto field (e.g. `keys`), not the camelCased entity plural.\n */\n itemsField: string;\n}\n\nexport interface MockGetRpc {\n rpc: string;\n responseSchema: DescMessage;\n /** The camelCase field wrapping the entity on the response message. */\n entityField: string;\n}\n\nexport interface MockWriteRpc extends MockGetRpc {\n /**\n * The camelCase field wrapping the entity on the REQUEST message. AIP-134\n * requests nest the entity ({ item: {...}, updateMask }); the generated\n * forms submit it flattened. Both are accepted.\n */\n requestField: string;\n}\n\nexport interface MockDeleteRpc {\n rpc: string;\n}\n\n/**\n * Everything the engine needs to serve one entity's CRUD quintet from\n * fixtures. Generated into `src/lib/mock-transport.ts` from the project's\n * proto descriptors.\n */\nexport interface MockEntityDescriptor {\n /** Fully-qualified proto service name, e.g. \"demo.v1.ClinicService\". */\n service: string;\n /** Lowercase entity name, used verbatim in the NotFound message. */\n label: string;\n /**\n * The camelCase PRIMARY-KEY field. The session store keys records by this\n * field; hardcoding \"id\" breaks every surrogate-PK entity (a\n * `usage_event_id` PK projects to a message with no `id` field).\n */\n pkField: string;\n /** Deterministic seed rows — the same values the dev database is seeded with. */\n fixtures: readonly unknown[];\n /** The entity message schema. Required by the create/update write paths. */\n entitySchema?: DescMessage;\n list?: MockListRpc;\n get?: MockGetRpc;\n create?: MockWriteRpc;\n update?: MockWriteRpc;\n delete?: MockDeleteRpc;\n}\n\nexport interface CreateMockTransportOptions {\n /** The resolved scenario — see {@link resolveActiveScenario}. */\n scenario: MockScenario;\n /** Per-entity fixture dispatch. Omit for a scenario-only project. */\n entities?: readonly MockEntityDescriptor[];\n /**\n * Default handlers per service (`serviceDefaults(Service)`, one per\n * generated `src/mocks/services/*_gen.ts`): the answer for any RPC that no\n * scenario handler, passthrough or entity fixture took.\n */\n services?: readonly AnyServiceDefaults[];\n /**\n * Optional real Connect transport. When the active scenario declares\n * `passthrough: true`, any RPC not matched by a scenario handler is\n * forwarded here instead of falling through to the fixtures.\n */\n fallback?: Transport;\n /**\n * Refuse every RPC that is not a read, with PermissionDenied, before any\n * handler, fixture or backend sees it. `true` classifies by the proto's\n * `idempotency_level = NO_SIDE_EFFECTS`; a function classifies itself (a\n * contract that does not annotate idempotency, e.g. by method name).\n */\n readOnly?: boolean | ((method: DescMethod) => boolean);\n /** The message a refused write carries. Default names the RPC. */\n readOnlyMessage?: string;\n /**\n * With `passthrough: \"first\"`: the forwarded call's deadline in ms, after\n * which the scenario answers instead. Default: the caller's own timeout.\n * Enforced by the mock transport itself, so a fallback transport that\n * ignores its timeout cannot hold the call open; a server stream must END\n * within it to count as the backend's answer.\n */\n passthroughTimeoutMs?: number;\n /**\n * With `passthrough: \"first\"`: called each time the backend failed (or\n * timed out) and the mock answered instead. A caller's own abort is never\n * a fallback: it rejects as it would against the backend.\n */\n onPassthroughFallback?: (key: string, error: ConnectError) => void;\n}\n\n/** Options for {@link resolveActiveScenario}. */\nexport interface ResolveScenarioOptions {\n /**\n * The scenario to run, chosen by the app (its host, its runtime config)\n * instead of the URL. When the key is present — even as null or \"\" — the\n * `?scenario=` parameter is NOT read; null/\"\"/unknown select the default.\n */\n name?: string | null;\n}\n\n/**\n * Mutable session stores, keyed by descriptor identity.\n *\n * Create/Update/Delete round-trip within one browser session (a created row\n * appears in the next List; a deleted one disappears) and reset to the\n * deterministic fixtures on reload. The scaffolded original got that from\n * module-scope `const store = new Map(...)`; keying off the descriptor\n * object preserves it — a module-level descriptor array hands back the same\n * store on every call, so building the transport twice (hybrid mode, a test\n * swapping transports) does not silently fork the data.\n */\nconst stores = new WeakMap<MockEntityDescriptor, Map<string, unknown>>();\n\nfunction storeFor(entity: MockEntityDescriptor): Map<string, unknown> {\n let store = stores.get(entity);\n if (!store) {\n store = new Map(\n entity.fixtures.map((row) => [\n String((row as Record<string, unknown>)[entity.pkField]),\n row,\n ]),\n );\n stores.set(entity, store);\n }\n return store;\n}\n\n/** Scenarios whose `setup()` has already run. */\nconst initialized = new WeakSet<MockScenario>();\n\n/**\n * Resolve the scenario the app should run under, and run its `setup()` once.\n *\n * Call this at MODULE SCOPE (the generated `src/lib/mock-transport.ts` does).\n * Reading the URL once — rather than on every RPC — means navigating away\n * from `?scenario=` keeps the scenario active until a full reload, matching\n * the agent-driven flow where the URL is the single source of truth.\n *\n * `setup()` is for non-RPC state (localStorage flags, sessionStorage). It is\n * synchronous and makes no network calls.\n */\nexport function resolveActiveScenario(\n registry: MockScenarioRegistry,\n options: ResolveScenarioOptions = {},\n): MockScenario {\n const requested =\n \"name\" in options\n ? (options.name ?? null)\n : typeof globalThis !== \"undefined\" && globalThis.location\n ? new URLSearchParams(globalThis.location.search).get(\"scenario\")\n : null;\n // A ternary, not `&&`: with `??` alone the empty-string falsy branch leaks\n // '' into the inferred union, and '' survives `??` (which only replaces\n // null/undefined), so downstream access on .setup / .handlers would fail\n // under strict tsc.\n const active =\n (requested ? registry.byName(requested) : undefined) ??\n registry.defaultScenario;\n\n if (!initialized.has(active)) {\n initialized.add(active);\n active.setup?.();\n }\n return active;\n}\n\n/**\n * Normalize whatever a streaming scenario handler returns into an\n * AsyncIterable<unknown>. Accepts arrays, iterables, async iterables, and\n * promises that resolve to any of the above. Single (non-iterable) values\n * are wrapped as a one-element stream — handy for handlers that conceptually\n * yield once.\n */\nexport async function* toAsyncIterable(value: unknown): AsyncIterable<unknown> {\n const resolved = await Promise.resolve(value);\n if (resolved == null) return;\n // AsyncIterable\n if (\n typeof (resolved as { [Symbol.asyncIterator]?: unknown })[\n Symbol.asyncIterator\n ] === \"function\"\n ) {\n for await (const m of resolved as AsyncIterable<unknown>) yield m;\n return;\n }\n // Iterable (including arrays)\n if (\n typeof (resolved as { [Symbol.iterator]?: unknown })[Symbol.iterator] ===\n \"function\"\n ) {\n for (const m of resolved as Iterable<unknown>) yield m;\n return;\n }\n // Single value\n yield resolved;\n}\n\nfunction makeUnaryResponse<T>(\n method: { name: string; parent: { typeName: string }; output?: DescMessage },\n message: T,\n): UnaryResponse<never, never> {\n return {\n service: method.parent as never,\n method: method as never,\n stream: false,\n header: new Headers(),\n message: asResponseMessage(method.output, message) as never,\n trailer: new Headers(),\n };\n}\n\n/**\n * A handler may return the response as a plain init object\n * (`{ items: [...] }`) instead of `create(Schema, {...})`. A real client\n * always receives a full message — every repeated field an array, every\n * scalar its zero value — so a plain object is completed against the\n * method's output schema here; without that, `res.items.map` on a field the\n * handler left out throws in the UI and nowhere near the scenario.\n */\nfunction asResponseMessage(\n output: DescMessage | undefined,\n value: unknown,\n): unknown {\n if (!output || value == null || typeof value !== \"object\") return value;\n if (isMessage(value)) return value;\n return create(output, value as MessageInitShape<DescMessage>);\n}\n\n/** The default read-only classification: the proto says the method has no side effects. */\nfunction isRead(method: DescMethod): boolean {\n return method.idempotency === MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS;\n}\n\n/**\n * A fixture-backed handler for one RPC key. `requestSchema` is the Connect\n * method's input descriptor — absent only when a caller hand-builds a method\n * object without one, in which case List serves paging alone.\n */\ntype FixtureHandler = (\n input: unknown,\n requestSchema: DescMessage | undefined,\n) => unknown;\n\n// ── List semantics ─────────────────────────────────────────────────────\n//\n// What the backend's generated List does, and therefore what the fixture\n// List does (pkg/crud HandleList + the generated Filters closure):\n//\n// - Every `optional` request field that is SET filters by equality on the\n// entity field of the same name. Enums compare by value. A field with\n// IMPLICIT presence (no `optional`) is never a filter — the backend\n// generates none for it, so the mock must not invent one.\n// - `search` matches case-insensitively against the entity's string\n// fields and enum value names (enum columns are stored as names).\n// - `order_by` (snake_case column, comma-separated, optional ASC/DESC per\n// column) plus `descending` sorts; an unknown column is InvalidArgument.\n// - `page_size` defaults to 50 and is clamped to 100. `total_count` is the\n// filtered count BEFORE paging. `next_page_token` is minted only for the\n// default (primary-key) order — an ordered list is single-page on the\n// backend, and a mock that paged it would hide that.\n//\n// Paging, ordering and search arrive through these request fields, by the\n// names forge's CRUD List requests declare. They are never equality filters.\nconst LIST_CONTROL_FIELDS = new Set([\n \"pageSize\",\n \"pageToken\",\n \"orderBy\",\n \"descending\",\n \"search\",\n]);\n\n/** pkg/crud ListOp's defaults: 0 means 50, and no page exceeds 100. */\nconst DEFAULT_PAGE_SIZE = 50;\nconst MAX_PAGE_SIZE = 100;\n\n/** FeatureSet_FieldPresence.EXPLICIT — proto3 `optional`, oneofs, messages. */\nconst EXPLICIT_PRESENCE = 1;\n\ntype Row = Record<string, unknown>;\n\n/** The entity message a List response repeats, read off its descriptor. */\nfunction listItemSchema(list: MockListRpc): DescMessage | undefined {\n const items = list.responseSchema.field[list.itemsField];\n return items?.fieldKind === \"list\" && items.listKind === \"message\"\n ? items.message\n : undefined;\n}\n\n/** Scalars and enums compare by value; messages, bytes, lists and maps do not. */\nfunction isComparable(field: DescField): boolean {\n if (field.fieldKind === \"enum\") return true;\n return field.fieldKind === \"scalar\" && field.scalar !== ScalarType.BYTES;\n}\n\nfunction sameValue(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n // A 64-bit field is a bigint — or a string under jstype=JS_STRING — and\n // the two sides are not guaranteed to agree on which.\n if (a == null || b == null) return false;\n return (\n (typeof a === \"bigint\" || typeof b === \"bigint\") && String(a) === String(b)\n );\n}\n\nfunction enumName(field: DescField, value: unknown): string | undefined {\n return field.fieldKind === \"enum\"\n ? field.enum.values.find((v) => v.number === value)?.name\n : undefined;\n}\n\n/** The value a column sorts by, as Postgres would order the stored column. */\nfunction sortKey(field: DescField, value: unknown): unknown {\n if (value == null) return undefined;\n // Enum columns hold the value NAME, so they sort alphabetically by name.\n if (field.fieldKind === \"enum\") return enumName(field, value) ?? \"\";\n if (field.fieldKind === \"scalar\") return value;\n if (\n field.fieldKind === \"message\" &&\n field.message.typeName === \"google.protobuf.Timestamp\"\n ) {\n const ts = value as { seconds: bigint; nanos: number };\n return BigInt(ts.seconds) * 1_000_000_000n + BigInt(ts.nanos);\n }\n return undefined;\n}\n\n/** Postgres's default: NULL sorts after every value ascending. */\nfunction compareKeys(a: unknown, b: unknown): number {\n if (a === undefined || b === undefined) {\n return a === b ? 0 : a === undefined ? 1 : -1;\n }\n const x = a as string | number | bigint | boolean;\n const y = b as string | number | bigint | boolean;\n return x < y ? -1 : x > y ? 1 : 0;\n}\n\nfunction invalidArgument(message: string): ConnectError {\n return new ConnectError(`mock-transport: ${message}`, Code.InvalidArgument);\n}\n\n/** Parse `order_by` the way orm.ValidateOrderBy reads it. */\nfunction parseOrderBy(\n clause: string,\n descending: boolean,\n itemSchema: DescMessage,\n): { field: DescField; desc: boolean }[] {\n return clause.split(\",\").map((part) => {\n const [column = \"\", direction] = part.trim().split(/\\s+/);\n const field = itemSchema.fields.find(\n (f) => f.name === column || f.localName === column,\n );\n if (!field) {\n throw invalidArgument(`unknown order-by column \"${column}\"`);\n }\n const dir = direction?.toUpperCase();\n if (dir !== undefined && dir !== \"ASC\" && dir !== \"DESC\") {\n throw invalidArgument(`invalid order-by direction \"${direction}\"`);\n }\n return { field, desc: dir === undefined ? descending : dir === \"DESC\" };\n });\n}\n\n/** A count in whatever JS type the response's total_count field takes. */\nfunction countValue(field: DescField, n: number): unknown {\n if (field.fieldKind !== \"scalar\") return n;\n switch (field.scalar) {\n case ScalarType.INT64:\n case ScalarType.UINT64:\n case ScalarType.SINT64:\n case ScalarType.FIXED64:\n case ScalarType.SFIXED64:\n return field.longAsString ? String(n) : BigInt(n);\n default:\n return n;\n }\n}\n\n/**\n * Answer one List call from the entity's rows. See the List semantics note\n * above for the contract; the engine's tests pin each clause.\n */\nfunction serveList(\n rows: readonly unknown[],\n list: MockListRpc,\n input: unknown,\n requestSchema: DescMessage | undefined,\n): unknown {\n const req = (input ?? {}) as Row;\n const itemSchema = listItemSchema(list);\n let matched = rows as readonly Row[];\n\n if (itemSchema && requestSchema) {\n for (const filter of requestSchema.fields) {\n if (LIST_CONTROL_FIELDS.has(filter.localName)) continue;\n if (filter.presence !== EXPLICIT_PRESENCE || !isComparable(filter)) {\n continue;\n }\n const want = req[filter.localName];\n if (want == null) continue; // unset: no filter\n const target = itemSchema.field[filter.localName];\n if (!target || !isComparable(target)) continue;\n matched = matched.filter((row) => sameValue(row[filter.localName], want));\n }\n }\n\n const search =\n typeof req.search === \"string\" ? req.search.trim().toLowerCase() : \"\";\n if (itemSchema && search) {\n const searchable = itemSchema.fields.filter(\n (f) =>\n f.fieldKind === \"enum\" ||\n (f.fieldKind === \"scalar\" && f.scalar === ScalarType.STRING),\n );\n matched = matched.filter((row) =>\n searchable.some((f) => {\n const value = row[f.localName];\n const text = f.fieldKind === \"enum\" ? enumName(f, value) : value;\n return typeof text === \"string\" && text.toLowerCase().includes(search);\n }),\n );\n }\n\n const orderBy = typeof req.orderBy === \"string\" ? req.orderBy.trim() : \"\";\n if (itemSchema && orderBy) {\n const keys = parseOrderBy(orderBy, req.descending === true, itemSchema);\n matched = [...matched].sort((a, b) => {\n for (const { field, desc } of keys) {\n const c = compareKeys(\n sortKey(field, a[field.localName]),\n sortKey(field, b[field.localName]),\n );\n if (c !== 0) return desc ? -c : c;\n }\n return 0;\n });\n }\n\n const total = matched.length;\n\n let offset = 0;\n const token = typeof req.pageToken === \"string\" ? req.pageToken : \"\";\n if (token) {\n // The mock's own cursor: an offset into the filtered rows. Opaque to the\n // client, exactly like the backend's keyset cursor.\n if (!/^\\d+$/.test(token)) throw invalidArgument(\"invalid page token\");\n offset = Number(token);\n }\n const requested = Number(req.pageSize ?? 0);\n const pageSize =\n requested > 0 ? Math.min(requested, MAX_PAGE_SIZE) : DEFAULT_PAGE_SIZE;\n const end = offset + pageSize;\n\n const init: Row = { [list.itemsField]: matched.slice(offset, end) };\n const totalField = list.responseSchema.field.totalCount;\n if (totalField) init.totalCount = countValue(totalField, total);\n if (list.responseSchema.field.nextPageToken && !orderBy && end < total) {\n init.nextPageToken = String(end);\n }\n return create(list.responseSchema, init as MessageInitShape<DescMessage>);\n}\n\n/**\n * Compile the entity descriptors into a flat `${service}/${rpc}` → handler\n * map. Building it once per transport keeps per-RPC dispatch to a single\n * lookup, exactly like the generated `switch` it replaces.\n */\nfunction buildFixtureTable(\n entities: readonly MockEntityDescriptor[],\n): Map<string, FixtureHandler> {\n const table = new Map<string, FixtureHandler>();\n\n for (const entity of entities) {\n const pk = entity.pkField;\n const key = (rpc: string) => `${entity.service}/${rpc}`;\n\n if (entity.list) {\n const list = entity.list;\n table.set(key(list.rpc), (input, requestSchema) =>\n serveList(\n Array.from(storeFor(entity).values()),\n list,\n input,\n requestSchema,\n ),\n );\n }\n\n if (entity.get) {\n const { rpc, responseSchema, entityField } = entity.get;\n table.set(key(rpc), (input) => {\n // Read the key off the SAME field the store is keyed by, not a\n // hardcoded `id` — a surrogate-PK entity would otherwise look up\n // String(undefined) and miss every record.\n const req = input as Record<string, unknown> | undefined;\n const found = storeFor(entity).get(String(req?.[pk]));\n if (!found) {\n // A miss is NotFound — exactly what the real backend returns.\n // (Falling back to the first fixture made every detail page\n // \"work\" against the wrong record and hid bad-id bugs.)\n throw new ConnectError(\n `${entity.label} ${String(req?.[pk])} not found`,\n Code.NotFound,\n );\n }\n return create(responseSchema, {\n [entityField]: found,\n } as MessageInitShape<DescMessage>);\n });\n }\n\n if (entity.create && entity.entitySchema) {\n const { rpc, responseSchema, entityField, requestField } = entity.create;\n const entitySchema = entity.entitySchema;\n table.set(key(rpc), (input) => {\n // Create requests carry the entity fields flattened (that's how the\n // generated form submits); a nested { <entity>: {...} } payload is\n // accepted too.\n const req = (input ?? {}) as Record<string, unknown>;\n const init = {\n ...((req[requestField] ?? req) as Record<string, unknown>),\n };\n delete init.$typeName;\n // Mint the primary key on the PK field the store is keyed by — for a\n // surrogate-PK entity this is NOT `id`, and writing a generated `id`\n // would leave the store key undefined so the row never round-trips.\n const id =\n typeof init[pk] === \"string\" && init[pk]\n ? (init[pk] as string)\n : crypto.randomUUID();\n const created = create(entitySchema, {\n ...init,\n [pk]: id,\n } as MessageInitShape<DescMessage>);\n storeFor(entity).set(String(id), created);\n return create(responseSchema, {\n [entityField]: created,\n } as MessageInitShape<DescMessage>);\n });\n }\n\n if (entity.update && entity.entitySchema) {\n const { rpc, responseSchema, entityField, requestField } = entity.update;\n const entitySchema = entity.entitySchema;\n table.set(key(rpc), (input) => {\n const req = (input ?? {}) as Record<string, unknown>;\n // AIP-134 requests wrap the entity ({ <entity>: {...}, updateMask })\n // — the id lives inside the wrapper; flat requests carry it at the\n // top level.\n const patch = {\n ...((req[requestField] ?? req) as Record<string, unknown>),\n };\n delete patch.$typeName;\n const id = String(patch[pk] ?? req[pk] ?? \"\");\n const store = storeFor(entity);\n const existing = store.get(id);\n if (!existing) {\n throw new ConnectError(\n `${entity.label} ${id} not found`,\n Code.NotFound,\n );\n }\n const updated = create(entitySchema, {\n ...(existing as Record<string, unknown>),\n ...patch,\n [pk]: id,\n } as MessageInitShape<DescMessage>);\n store.set(id, updated);\n return create(responseSchema, {\n [entityField]: updated,\n } as MessageInitShape<DescMessage>);\n });\n }\n\n if (entity.delete) {\n table.set(key(entity.delete.rpc), (input) => {\n // Delete by the SAME field the store is keyed by.\n const req = input as Record<string, unknown> | undefined;\n storeFor(entity).delete(String(req?.[pk]));\n // Delete returns an empty response — the standard CRUD shape.\n return {};\n });\n }\n }\n\n return table;\n}\n\n/**\n * Compile service defaults into the same flat `${service}/${rpc}` → handler\n * map the fixtures use. The first service object for a name wins, so an app\n * that lists one twice (a hand-built list beside the generated one) keeps\n * the earlier entry's options.\n */\nfunction buildDefaultsTable(\n services: readonly AnyServiceDefaults[],\n): Map<string, (input: unknown) => unknown> {\n const table = new Map<string, (input: unknown) => unknown>();\n for (const defaults of services) {\n const service = defaults.$service;\n for (const method of service.methods) {\n const key = `${service.typeName}/${method.name}`;\n const handler = (\n defaults as unknown as Record<string, (input: unknown) => unknown>\n )[method.localName];\n if (handler && !table.has(key)) table.set(key, handler);\n }\n }\n return table;\n}\n\n/**\n * Create the mock transport.\n *\n * The generated `src/lib/mock-transport.ts` supplies the resolved scenario\n * and the project's entity descriptors; `connect.ts` supplies the optional\n * real transport when running in hybrid mode.\n */\nexport function createMockTransport(\n options: CreateMockTransportOptions,\n): Transport {\n const {\n scenario,\n entities = [],\n fallback,\n readOnly,\n passthroughTimeoutMs,\n onPassthroughFallback,\n } = options;\n const passthrough = scenario.passthrough === true && fallback != null;\n const first = scenario.passthrough === \"first\" && fallback != null;\n const fixtures = buildFixtureTable(entities);\n const defaults = buildDefaultsTable(options.services ?? []);\n const readsOnly = typeof readOnly === \"function\" ? readOnly : isRead;\n\n // 0) The read-only guard: before any dispatch, so a write never reaches a\n // handler, a fixture store or the backend.\n const guard = (method: DescMethod, key: string) => {\n if (readOnly && !readsOnly(method)) {\n throw new ConnectError(\n options.readOnlyMessage ?? `mock-transport: ${key} is not a read`,\n Code.PermissionDenied,\n );\n }\n };\n // \"first\": the backend's answer, or undefined when the mock should answer.\n //\n // The deadline is enforced HERE, not left to the fallback transport: the\n // attempt gets its own signal (aborted by the caller's signal or by the\n // timer) and is raced against that signal, so a transport that ignores\n // both its timeout and its signal still cannot hold the call open. A\n // caller's own abort is rethrown; only the deadline or a failure falls back.\n const tryBackend = async <R>(\n key: string,\n signal: AbortSignal | undefined,\n timeoutMs: number | undefined,\n call: (signal: AbortSignal) => Promise<R>,\n ): Promise<R | undefined> => {\n const attempt = new AbortController();\n const abortAttempt = () => attempt.abort(signal?.reason);\n if (signal?.aborted) abortAttempt();\n signal?.addEventListener(\"abort\", abortAttempt, { once: true });\n const timer =\n timeoutMs != null && timeoutMs > 0\n ? setTimeout(\n () =>\n attempt.abort(\n new ConnectError(\n `mock-transport: ${key} exceeded ${timeoutMs}ms`,\n Code.DeadlineExceeded,\n ),\n ),\n timeoutMs,\n )\n : undefined;\n const abandoned = new Promise<never>((_, reject) => {\n const fail = () => reject(attempt.signal.reason);\n if (attempt.signal.aborted) fail();\n else attempt.signal.addEventListener(\"abort\", fail, { once: true });\n });\n // The race observes it; this keeps the release below from surfacing as\n // an unhandled rejection after the race has settled.\n abandoned.catch(() => undefined);\n try {\n return await Promise.race([call(attempt.signal), abandoned]);\n } catch (err) {\n if (signal?.aborted) throw err;\n onPassthroughFallback?.(key, ConnectError.from(err));\n return undefined;\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n signal?.removeEventListener(\"abort\", abortAttempt);\n // Release whatever the backend attempt still holds (a pending fetch,\n // an unread stream) once it has been answered or abandoned.\n attempt.abort();\n }\n };\n\n // Bind the object literal to a Transport-typed variable rather than\n // casting at the return site. A trailing assertion cast does not propagate\n // Connect's Transport signature backwards into the literal's method\n // bodies, so under `strict` tsc every callback parameter on unary/stream\n // errors with TS7006 (\"implicitly has an 'any' type\").\n const transport: Transport = {\n // Connect v2's Transport.unary signature is\n // (method, signal, timeoutMs, header, input, contextValues)\n // — method first, no separate service arg. `method.parent.typeName` is\n // the fully-qualified service name; that is what handler keys and\n // fixture keys are matched against.\n async unary(method, signal, timeoutMs, header, input, contextValues) {\n const key = `${method.parent.typeName}/${method.name}`;\n guard(method, key);\n\n // 0b) \"first\": the backend answers unless it fails.\n if (first) {\n const deadline = passthroughTimeoutMs ?? timeoutMs;\n const live = await tryBackend(key, signal, deadline, (attempt) =>\n fallback!.unary(\n method,\n attempt,\n deadline,\n header,\n input,\n contextValues,\n ),\n );\n if (live) return live;\n }\n\n // 1) Scenario overlay.\n const handler = scenario.handlers[key];\n if (handler) {\n const result = await handler(input as never);\n return makeUnaryResponse(method, result);\n }\n\n // 2) Passthrough: route to the real backend instead of fixtures.\n // Skips fixtures entirely — in hybrid mode the whole point is\n // \"use real data for anything not explicitly stubbed\".\n if (passthrough) {\n return fallback!.unary(\n method,\n signal,\n timeoutMs,\n header,\n input,\n contextValues,\n );\n }\n\n // 3) Base fixture dispatch, backed by the mutable per-entity stores so\n // writes round-trip within the session. Misses are REAL errors\n // (Code.NotFound), never a silent wrong-record fallback.\n const fixture = fixtures.get(key);\n if (fixture) {\n // `method.input` is typed as always present, but a hand-built method\n // object (a test, a custom harness) may omit it.\n const requestSchema = (method as { input?: DescMessage }).input;\n return makeUnaryResponse(method, fixture(input, requestSchema));\n }\n\n // 4) The service's default: a schema-valid answer for any RPC.\n const fallbackDefault = defaults.get(key);\n if (fallbackDefault) {\n return makeUnaryResponse(method, fallbackDefault(input));\n }\n\n // 5) Nothing matched. Surface a clear error instead of hanging.\n return Promise.reject(\n new ConnectError(\n `mock-transport: no scenario handler, entity fixture or service default for ${key}`,\n Code.Unimplemented,\n ),\n );\n },\n\n // Streaming: a scenario handler can return an array, iterable, async\n // iterable, or a Promise resolving to any of those. The transport adapts\n // it into the AsyncIterable<Response> shape Connect expects. With no\n // handler, the service default answers (a short deterministic stream for\n // server and bidi streams, one message for client streams); with neither,\n // reject with Unimplemented. Entity fixtures never stream.\n //\n // No explicit return-type annotation: the outer `const transport:\n // Transport` binding lets tsc infer the per-callback signature from\n // Connect's generic Transport.stream<I, O>. Annotating this as\n // Promise<StreamResponse<never, never>> makes the passthrough branch\n // ill-typed (TS2322) because fallback.stream returns StreamResponse<I,O>.\n async stream(method, signal, timeoutMs, header, input, contextValues) {\n const key = `${method.parent.typeName}/${method.name}`;\n guard(method, key);\n // \"first\" forwards server streams only: a client-streaming request is\n // consumed by the attempt and could not be replayed to the handler.\n //\n // The backend's stream is read to its END, within the deadline, before\n // it counts as an answer, then replayed: a stream that fails or stalls\n // after its headers arrived still falls back to the mock, as a unary\n // call does. So \"first\" suits finite server streams; a stream that\n // never ends always answers from the mock once the deadline passes.\n if (first && method.methodKind === \"server_streaming\") {\n const deadline = passthroughTimeoutMs ?? timeoutMs;\n const live = await tryBackend(\n key,\n signal,\n deadline,\n async (attempt) => {\n const res = await fallback!.stream(\n method,\n attempt,\n deadline,\n header,\n input,\n contextValues,\n );\n const messages: unknown[] = [];\n for await (const m of res.message) messages.push(m);\n return {\n ...res,\n message: toAsyncIterable(messages) as typeof res.message,\n };\n },\n );\n if (live) return live;\n }\n const scenarioHandler = scenario.handlers[key];\n // Passthrough mirrors the unary path: in hybrid mode, unmatched\n // streaming RPCs go to the real backend, ahead of the defaults.\n if (!scenarioHandler && passthrough) {\n return fallback!.stream(\n method,\n signal,\n timeoutMs,\n header,\n input,\n contextValues,\n );\n }\n const handler = scenarioHandler ?? defaults.get(key);\n if (!handler) {\n return Promise.reject(\n new ConnectError(\n `mock-transport: no scenario handler or service default for streaming RPC ${key}`,\n Code.Unimplemented,\n ),\n );\n }\n // Read the request stream eagerly into an array so the scenario handler\n // sees the full client-streaming payload. For server-stream and\n // unary-into-stream-out RPCs this is a single message.\n const requestMessages: unknown[] = [];\n try {\n for await (const m of input as AsyncIterable<unknown>) {\n requestMessages.push(m);\n }\n } catch {\n // Synthetic clients sometimes pass a single value rather than an\n // iterable; treat that as an empty request payload.\n }\n const handlerInput =\n requestMessages.length <= 1 ? requestMessages[0] : requestMessages;\n const result = handler(handlerInput as never);\n return {\n service: method.parent as never,\n method: method as never,\n stream: true,\n header: new Headers(),\n message: toAsyncIterable(result) as AsyncIterable<never>,\n trailer: new Headers(),\n };\n },\n };\n return transport;\n}\n"]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type DescMessage, type DescService, type Message, type MessageInitShape, type MessageShape } from "@bufbuild/protobuf";
|
|
2
|
+
/** Change how one message type is generated, wherever it appears. */
|
|
3
|
+
export interface MockFactory<Desc extends DescMessage = DescMessage> {
|
|
4
|
+
readonly schema: Desc;
|
|
5
|
+
readonly build: (ctx: MockFactoryContext<Desc>) => MockResult<Desc>;
|
|
6
|
+
}
|
|
7
|
+
export interface MockFactoryContext<Desc extends DescMessage> {
|
|
8
|
+
/** The default the engine built for this position. */
|
|
9
|
+
readonly base: MessageShape<Desc>;
|
|
10
|
+
/** Position in the enclosing list, or -1 outside one. */
|
|
11
|
+
readonly index: number;
|
|
12
|
+
/** The seed of this position: stable for the same request and path. */
|
|
13
|
+
readonly seed: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A factory's or handler's answer: a full message passes through; a plain
|
|
17
|
+
* object is a PATCH onto the default (factories) or the full response
|
|
18
|
+
* completed with zero values (handlers), as the engine's F5 contract says.
|
|
19
|
+
*/
|
|
20
|
+
export type MockResult<Desc extends DescMessage> = MessageShape<Desc> | MessageInitShape<Desc>;
|
|
21
|
+
/**
|
|
22
|
+
* Typed factory helper: `mockFactory(TraceSummarySchema, ({ base, index }) =>
|
|
23
|
+
* ({ rootService: index % 2 ? "web" : "api" }))` — the result is patched onto
|
|
24
|
+
* the default for every TraceSummary the engine builds.
|
|
25
|
+
*/
|
|
26
|
+
export declare function mockFactory<Desc extends DescMessage>(schema: Desc, build: (ctx: MockFactoryContext<Desc>) => MockResult<Desc>): MockFactory<Desc>;
|
|
27
|
+
export interface MockValueOptions {
|
|
28
|
+
/** Seed of the value. Default: the schema's type name. */
|
|
29
|
+
seed?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The instant "recent" is measured from. Default: the minute the engine was
|
|
32
|
+
* first used in this page, so values hold still for the session.
|
|
33
|
+
*/
|
|
34
|
+
now?: Date | number;
|
|
35
|
+
/** Nesting depth past which messages are left unset and lists empty. Default 6. */
|
|
36
|
+
maxDepth?: number;
|
|
37
|
+
/** Per-message-type overrides, applied wherever that type is built. */
|
|
38
|
+
factories?: readonly MockFactory<DescMessage>[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One deterministic, schema-valid message of `schema` — see the header for
|
|
42
|
+
* what each field becomes. Same options, same message.
|
|
43
|
+
*/
|
|
44
|
+
export declare function mockValue<Desc extends DescMessage>(schema: Desc, options?: MockValueOptions): MessageShape<Desc>;
|
|
45
|
+
type PatchValue<V> = V extends Message ? PatchShape<V> | V : V extends readonly (infer E)[] ? E extends Message ? readonly (E | PatchShape<E>)[] : V : V;
|
|
46
|
+
/** A deep partial of a message: nested messages merge, lists and maps replace. */
|
|
47
|
+
export type PatchShape<T extends Message> = {
|
|
48
|
+
[K in Exclude<keyof T, "$typeName" | "$unknown">]?: PatchValue<T[K]>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Deep-merge `changes` onto `base` and return a NEW message (base is not
|
|
52
|
+
* mutated). A nested message merges field by field; a list, a map, a oneof
|
|
53
|
+
* and a scalar are replaced. Partial list items are completed with zero
|
|
54
|
+
* values, as `create()` would.
|
|
55
|
+
*
|
|
56
|
+
* const res = defaults.listTraces(req);
|
|
57
|
+
* return patch(res, { traces: res.traces.slice(0, 2), red: { errorRate: 0.5 } });
|
|
58
|
+
*/
|
|
59
|
+
export declare function patch<T extends Message>(base: T, changes: PatchShape<T>): T;
|
|
60
|
+
type MethodsOf<S extends DescService> = S["method"];
|
|
61
|
+
type InputOf<M> = M extends {
|
|
62
|
+
input: infer I extends DescMessage;
|
|
63
|
+
} ? I : DescMessage;
|
|
64
|
+
type OutputOf<M> = M extends {
|
|
65
|
+
output: infer O extends DescMessage;
|
|
66
|
+
} ? O : DescMessage;
|
|
67
|
+
type Streams<M> = M extends {
|
|
68
|
+
methodKind: "server_streaming" | "bidi_streaming";
|
|
69
|
+
} ? true : false;
|
|
70
|
+
/** A request as a default handler accepts it: the message, an init shape, or nothing. */
|
|
71
|
+
export type MockRequest<M> = MessageShape<InputOf<M>> | MessageInitShape<InputOf<M>>;
|
|
72
|
+
/** One RPC's default: a response, or — for a server or bidi stream — a short stream of them. */
|
|
73
|
+
export type DefaultHandler<M> = Streams<M> extends true ? (req?: MockRequest<M> | readonly MockRequest<M>[]) => MessageShape<OutputOf<M>>[] : (req?: MockRequest<M> | readonly MockRequest<M>[]) => MessageShape<OutputOf<M>>;
|
|
74
|
+
/**
|
|
75
|
+
* Every RPC of a service, answered from its descriptor. `$service` names the
|
|
76
|
+
* service (non-enumerable, so the object spreads as its handlers alone).
|
|
77
|
+
*/
|
|
78
|
+
export type ServiceDefaults<S extends DescService = DescService> = {
|
|
79
|
+
readonly [K in keyof MethodsOf<S>]: DefaultHandler<MethodsOf<S>[K]>;
|
|
80
|
+
} & {
|
|
81
|
+
readonly $service: S;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* The default handlers of every RPC of `service`: a deterministic,
|
|
85
|
+
* schema-valid response per request (a 3-message stream for server and bidi
|
|
86
|
+
* streams). Generated `src/mocks/services/*_gen.ts` modules export one per
|
|
87
|
+
* service, and the mock transport serves them for any RPC that no scenario,
|
|
88
|
+
* passthrough or entity fixture answered.
|
|
89
|
+
*
|
|
90
|
+
* Without options the result is memoized per service, so every caller shares
|
|
91
|
+
* one object.
|
|
92
|
+
*/
|
|
93
|
+
export declare function serviceDefaults<S extends DescService>(service: S, options?: Omit<MockValueOptions, "seed">): ServiceDefaults<S>;
|
|
94
|
+
/**
|
|
95
|
+
* Any service's defaults, as the transport and the generated registry hold
|
|
96
|
+
* them: a list of ServiceDefaults<S> for different S has only `$service` in
|
|
97
|
+
* common (their handlers' request types differ).
|
|
98
|
+
*/
|
|
99
|
+
export interface AnyServiceDefaults {
|
|
100
|
+
readonly $service: DescService;
|
|
101
|
+
}
|
|
102
|
+
/** True for what {@link serviceDefaults} returns — how the generated registry finds them. */
|
|
103
|
+
export declare function isServiceDefaults(value: unknown): value is AnyServiceDefaults;
|
|
104
|
+
type Awaitable<T> = T | Promise<T>;
|
|
105
|
+
/** One RPC's override: handed the typed request and the service's defaults. */
|
|
106
|
+
export type MockOverride<S extends DescService, M> = Streams<M> extends true ? (req: MessageShape<InputOf<M>>, defaults: ServiceDefaults<S>) => Awaitable<Iterable<MockResult<OutputOf<M>>>> | AsyncIterable<MockResult<OutputOf<M>>> : (req: MessageShape<InputOf<M>>, defaults: ServiceDefaults<S>) => Awaitable<MockResult<OutputOf<M>>>;
|
|
107
|
+
export type MockOverrides<S extends DescService> = {
|
|
108
|
+
readonly [K in keyof MethodsOf<S>]?: MockOverride<S, MethodsOf<S>[K]>;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Scenario handlers, keyed `${serviceTypeName}/${methodName}` — spread into a
|
|
112
|
+
* scenario's `handlers`, or a test's `mockTransport({...})`. The handlers'
|
|
113
|
+
* request parameter is typed by the override that produced them; the map's
|
|
114
|
+
* own type stays open so it spreads into any handler table.
|
|
115
|
+
*/
|
|
116
|
+
export type MockHandlers = Record<string, (req: any) => any>;
|
|
117
|
+
/**
|
|
118
|
+
* Typed overrides for one service, as scenario handlers:
|
|
119
|
+
*
|
|
120
|
+
* handlers: {
|
|
121
|
+
* ...mockService(ObservabilityService, {
|
|
122
|
+
* listTraces: (req, d) => patch(d.listTraces(req), { traces: [] }),
|
|
123
|
+
* }),
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* Each override receives the typed request and the service's defaults (built
|
|
127
|
+
* with `options.factories` when given). Only overridden RPCs get a handler —
|
|
128
|
+
* the rest fall through to the transport's own defaults — unless factories
|
|
129
|
+
* are given, in which case every RPC is answered with them.
|
|
130
|
+
*/
|
|
131
|
+
export declare function mockService<S extends DescService>(service: S, overrides: MockOverrides<S>, options?: Omit<MockValueOptions, "seed">): MockHandlers;
|
|
132
|
+
export {};
|