Skip to content

Commit 2cfacff

Browse files
committed
fix(spec): follow ADR-0122's author/parsed alias convention on the new types
`QueryWithTransport` is the author state and `QueryWithTransportParsed` the parsed one; `QueryTransportParamsParsed` names the parsed transport bag. `check:spec-parsed-alias` named both, and the test-side engine mock is typed with the parameters it is really called with. Claude-Session: https://claude.ai/code/session_01LvwGppdonww4zGLWZo5rho Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3e4631d commit 2cfacff

5 files changed

Lines changed: 24 additions & 12 deletions

File tree

‎.changeset/16066-query-transport-dialect-declared.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ The query TRANSPORT dialect is declared, and the `findData` fold now derives fro
99

1010
**New in `@objectstack/spec/data`** (8 exports, 0 removed):
1111

12-
- `QueryTransportParamsSchema` / `QueryTransportParams` — the transport parameters, each carrying the value of the canonical slot it folds onto.
12+
- `QueryTransportParamsSchema` / `QueryTransportParams` / `QueryTransportParamsParsed` — the transport parameters, each carrying the value of the canonical slot it folds onto.
1313
- `QUERY_TRANSPORT_ALIAS_SLOTS` — `RPC_QUERY_ALIAS_SLOTS` extended with the transport-only spellings (`filters` / `$filter` onto `where`, `$expand` onto `expand`).
1414
- `QUERY_TRANSPORT_DOLLAR_ALIASES` — the `$`-to-bare pairs that fold in two hops (`$top` onto `top` onto `limit`).
1515
- `QUERY_TRANSPORT_DOLLAR_PARAMS` — the `$` spellings a boundary quotes when it refuses an undeclared one.
16-
- `QueryWithTransportSchema` / `QueryWithTransport` / `QueryWithTransportInput` — the query slot whose declared input is the AST or its transport spelling and whose declared output is the AST.
16+
- `QueryWithTransportSchema` / `QueryWithTransport` / `QueryWithTransportParsed` — the query slot whose declared input is the AST or its transport spelling and whose declared output is the AST.
1717

1818
**`FindDataRequestSchema.query` is that slot now.** Its `z.input` admits the canonical AST, the transport spelling, or a bag carrying both; its `z.output` is still the AST, reached by a transform driven by the two tables. The transport form is declared as the FLATTENED SPELLING of the canonical AST with a 1:1 alias table — never as a second semantics — so `QuerySchema` itself is untouched and still drops a `$` key as unknown.
1919

‎packages/metadata-protocol/src/protocol.query-transport-dialect.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ const SCHEMA = {
113113
const USER_SCHEMA = { name: 'sys_user', nameField: 'name', fields: { name: { name: 'name', type: 'text' } } };
114114

115115
function makeProtocol() {
116-
const find = vi.fn(async () => [] as unknown[]);
116+
// Typed with the parameters the engine is really called with, so the
117+
// option-bag read below is `calls[0][1]` rather than an out-of-range index
118+
// on a zero-arity tuple.
119+
const find = vi.fn(async (_object?: string, _options?: unknown) => [] as unknown[]);
117120
const count = vi.fn(async () => 0);
118121
const engine = {
119122
registry: {

‎packages/spec/api-surface/data.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,10 @@
509509
"QueryInput (type)",
510510
"QuerySchema (const)",
511511
"QueryTransportParams (type)",
512+
"QueryTransportParamsParsed (type)",
512513
"QueryTransportParamsSchema (const)",
513514
"QueryWithTransport (type)",
514-
"QueryWithTransportInput (type)",
515+
"QueryWithTransportParsed (type)",
515516
"QueryWithTransportSchema (const)",
516517
"RAW_FILE_VALUES_CONTEXT_KEY (const)",
517518
"READ_ONLY_BELONGS_ON_DATASOURCE (const)",

‎packages/spec/export-origins/data.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,10 @@
498498
"QueryInput": "src/data/query.zod.ts#QueryInput (type)",
499499
"QuerySchema": "src/data/query.zod.ts#QuerySchema (const)",
500500
"QueryTransportParams": "src/data/data-engine.zod.ts#QueryTransportParams (type)",
501+
"QueryTransportParamsParsed": "src/data/data-engine.zod.ts#QueryTransportParamsParsed (type)",
501502
"QueryTransportParamsSchema": "src/data/data-engine.zod.ts#QueryTransportParamsSchema (const)",
502503
"QueryWithTransport": "src/data/data-engine.zod.ts#QueryWithTransport (type)",
503-
"QueryWithTransportInput": "src/data/data-engine.zod.ts#QueryWithTransportInput (type)",
504+
"QueryWithTransportParsed": "src/data/data-engine.zod.ts#QueryWithTransportParsed (type)",
504505
"QueryWithTransportSchema": "src/data/data-engine.zod.ts#QueryWithTransportSchema (const)",
505506
"RAW_FILE_VALUES_CONTEXT_KEY": "src/data/field-value.zod.ts#RAW_FILE_VALUES_CONTEXT_KEY (const)",
506507
"READ_ONLY_BELONGS_ON_DATASOURCE": "src/data/driver/common.zod.ts#READ_ONLY_BELONGS_ON_DATASOURCE (const)",

‎packages/spec/src/data/data-engine.zod.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,16 @@ function foldQueryTransportBag(
833833
return bag;
834834
}
835835

836-
/** The transport query parameters, as an input shape. */
836+
/** The transport query parameters, as an author writes them (ADR-0122). */
837837
export type QueryTransportParams = z.input<typeof QueryTransportParamsSchema>;
838838

839+
/**
840+
* The transport query parameters after a parse (ADR-0122). Not identical to
841+
* {@link QueryTransportParams}: `$expand`'s record arm carries nested
842+
* `QuerySchema` values, whose author and parsed states differ.
843+
*/
844+
export type QueryTransportParamsParsed = z.infer<typeof QueryTransportParamsSchema>;
845+
839846
/**
840847
* What a query slot that serves a transport boundary DECLARES as its input:
841848
* the canonical QueryAST, the transport spelling, or a bag carrying both.
@@ -847,7 +854,7 @@ export type QueryTransportParams = z.input<typeof QueryTransportParamsSchema>;
847854
* re-created this card's own defect one size down: a shape the door accepts
848855
* that the declaration denies.
849856
*/
850-
export type QueryWithTransportInput = QueryInput & Partial<QueryTransportParams>;
857+
export type QueryWithTransport = QueryInput & Partial<QueryTransportParams>;
851858

852859
/**
853860
* A query slot whose declared INPUT is the canonical AST or its transport
@@ -860,7 +867,7 @@ export type QueryWithTransportInput = QueryInput & Partial<QueryTransportParams>
860867
* widening provably unable to narrow anything: every input that parsed before
861868
* still parses, by the same schema, with the same issues.
862869
*/
863-
export const QueryWithTransportSchema: z.ZodType<QueryAST, QueryWithTransportInput> = lazySchema(() =>
870+
export const QueryWithTransportSchema: z.ZodType<QueryAST, QueryWithTransport> = lazySchema(() =>
864871
z.union([
865872
z.record(z.string(), z.unknown())
866873
.transform((bag, ctx) => foldQueryTransportBag(
@@ -869,15 +876,15 @@ export const QueryWithTransportSchema: z.ZodType<QueryAST, QueryWithTransportInp
869876
))
870877
.pipe(QuerySchema as unknown as z.ZodType<QueryAST, Record<string, unknown>>),
871878
QuerySchema,
872-
]) as unknown as z.ZodType<QueryAST, QueryWithTransportInput>,
879+
]) as unknown as z.ZodType<QueryAST, QueryWithTransport>,
873880
);
874881

875882
/**
876883
* What a transport-aware query slot PARSES TO — the canonical QueryAST, in
877-
* every spelling. The declared output is deliberately the AST alone: a
878-
* consumer reading a parsed query never sees a transport key.
884+
* every spelling (ADR-0122). The declared output is deliberately the AST
885+
* alone: a consumer reading a parsed query never sees a transport key.
879886
*/
880-
export type QueryWithTransport = z.infer<typeof QueryWithTransportSchema>;
887+
export type QueryWithTransportParsed = z.infer<typeof QueryWithTransportSchema>;
881888

882889

883890
export const DataEngineFindRequestSchema = lazySchema(() => z.object({

0 commit comments

Comments
 (0)