@sequenceholdings/orm 0.1.1 → 0.1.3
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/README.md +12 -2
- package/dist/authoring.cjs +1801 -0
- package/dist/authoring.cjs.map +1 -0
- package/dist/authoring.d.cts +539 -0
- package/dist/authoring.d.ts +539 -0
- package/dist/authoring.js +1759 -0
- package/dist/authoring.js.map +1 -0
- package/dist/canonical.cjs +552 -0
- package/dist/canonical.cjs.map +1 -0
- package/dist/canonical.d.cts +603 -0
- package/dist/canonical.d.ts +603 -0
- package/dist/canonical.js +532 -0
- package/dist/canonical.js.map +1 -0
- package/dist/cli.cjs +7843 -1815
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +8 -1
- package/dist/cli.d.ts +8 -1
- package/dist/cli.js +7854 -1828
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs +120 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +74 -2
- package/dist/client.d.ts +74 -2
- package/dist/client.js +116 -1
- package/dist/client.js.map +1 -1
- package/dist/compiler.cjs +3453 -0
- package/dist/compiler.cjs.map +1 -0
- package/dist/compiler.d.cts +389 -0
- package/dist/compiler.d.ts +389 -0
- package/dist/compiler.js +3396 -0
- package/dist/compiler.js.map +1 -0
- package/dist/drizzle.cjs +14 -0
- package/dist/drizzle.cjs.map +1 -0
- package/dist/drizzle.d.cts +1 -0
- package/dist/drizzle.d.ts +1 -0
- package/dist/drizzle.js +3 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/dynamic-input.cjs +391 -0
- package/dist/dynamic-input.cjs.map +1 -0
- package/dist/dynamic-input.d.cts +111 -0
- package/dist/dynamic-input.d.ts +111 -0
- package/dist/dynamic-input.js +380 -0
- package/dist/dynamic-input.js.map +1 -0
- package/dist/index.cjs +3727 -344
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +236 -59
- package/dist/index.d.ts +236 -59
- package/dist/index.js +3757 -482
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +642 -0
- package/dist/ir.cjs.map +1 -0
- package/dist/ir.d.cts +1119 -0
- package/dist/ir.d.ts +1119 -0
- package/dist/ir.js +623 -0
- package/dist/ir.js.map +1 -0
- package/dist/naming-CTvWSRTf.d.ts +79 -0
- package/dist/naming-DRyinU4u.d.cts +79 -0
- package/dist/predicate-v2.cjs +1093 -0
- package/dist/predicate-v2.cjs.map +1 -0
- package/dist/predicate-v2.d.cts +139 -0
- package/dist/predicate-v2.d.ts +139 -0
- package/dist/predicate-v2.js +1083 -0
- package/dist/predicate-v2.js.map +1 -0
- package/dist/sdl.cjs +1122 -0
- package/dist/sdl.cjs.map +1 -0
- package/dist/sdl.d.cts +94 -0
- package/dist/sdl.d.ts +94 -0
- package/dist/sdl.js +1098 -0
- package/dist/sdl.js.map +1 -0
- package/package.json +51 -3
- package/src/codegen-gql/apollo-hooks.cjs +98 -0
- package/src/codegen-gql/server-fns.cjs +101 -0
- package/templates/README.md +13 -0
- package/templates/orm-namespace/CLAUDE.md +82 -0
- package/templates/orm-namespace/codegen.ts +22 -0
- package/templates/orm-namespace/gitignore +5 -0
- package/templates/orm-namespace/graphql/example/queries.ts +56 -0
- package/templates/orm-namespace/package.json +24 -0
- package/templates/orm-namespace/schema/tables.ts +71 -0
- package/templates/orm-namespace/sequence.config.ts +32 -0
- package/templates/orm-namespace/tsconfig.json +15 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { CanonicalEnum, CanonicalDefinition } from './canonical.cjs';
|
|
2
|
+
import { ClaimKey, PredIr, RootIr, InputRefKind, TableMetaIr, CompiledOperation, CompiledArtifact, VariableIr, OrderIr, SelectionIr } from './ir.cjs';
|
|
3
|
+
import { DocumentNode, OperationDefinitionNode, FragmentDefinitionNode, GraphQLSchema, ValueNode, SelectionSetNode } from 'graphql';
|
|
4
|
+
export { DynamicInputIssue, DynamicInputResult, NormalizedBoolExp, NormalizedOnConflict, NormalizedOrderBy, NormalizedRow, ORDER_BY_DIRECTIONS, ScalarKind, allowedBoolExpOperators, allowedOps, validateAppendInput, validateBoolExpInput, validateInsertInput, validateOnConflictInput, validateOrderByInput, validateSelectColumns, validateSetInput } from './dynamic-input.cjs';
|
|
5
|
+
export { CompilePolicyInput, CompilePredicateInput, POLICY_COMPARE_OPS, POLICY_MAX_LINK_DEPTH, ParsedPolicy, PolicyColumnInfo, PolicyCompareOp, PolicyCompileError, PolicyCompileErrorCode, PolicyLinkInfo, PolicyNode, PolicyOperand, PolicyParseError, PolicyResolver, PolicyTableInfo, assertClaimsOnlyWhen, compilePolicy, compilePredicateV2, parsePolicy, walkPolicy } from './predicate-v2.cjs';
|
|
6
|
+
export { P as PLATFORM_USER_TYPENAME, c as camelCase, e as enumTypeName, p as pascalCase } from './naming-DRyinU4u.cjs';
|
|
7
|
+
import 'zod';
|
|
8
|
+
|
|
9
|
+
type DiagnosticSeverity = 'error' | 'warning';
|
|
10
|
+
interface CompilerDiagnostic {
|
|
11
|
+
severity: DiagnosticSeverity;
|
|
12
|
+
/** Stable machine code, e.g. 'unknown-column', 'unsupported-variable-type'. */
|
|
13
|
+
code: string;
|
|
14
|
+
message: string;
|
|
15
|
+
/** Source document path, when the diagnostic is document-scoped. */
|
|
16
|
+
document?: string;
|
|
17
|
+
/** Operation name, when known. */
|
|
18
|
+
operation?: string;
|
|
19
|
+
/** Table name, for canonical/policy-scoped diagnostics. */
|
|
20
|
+
table?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Thrown internally while compiling one operation; artifact assembly catches
|
|
24
|
+
* it and records a diagnostic, so one broken document never hides the rest.
|
|
25
|
+
*/
|
|
26
|
+
declare class DocumentCompileError extends Error {
|
|
27
|
+
readonly code: string;
|
|
28
|
+
readonly candidates: readonly string[];
|
|
29
|
+
readonly name = "DocumentCompileError";
|
|
30
|
+
constructor(message: string, code: string, candidates?: readonly string[]);
|
|
31
|
+
}
|
|
32
|
+
/** Thrown by compileNamespace when any error-severity diagnostic was produced. */
|
|
33
|
+
declare class NamespaceCompileError extends Error {
|
|
34
|
+
readonly diagnostics: CompilerDiagnostic[];
|
|
35
|
+
readonly name = "NamespaceCompileError";
|
|
36
|
+
constructor(diagnostics: CompilerDiagnostic[]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Inject pass — bake policies into the lowered IR so the artifact is
|
|
41
|
+
* self-contained (plan §4 invariant: execution needs only IR + claims +
|
|
42
|
+
* variables):
|
|
43
|
+
*
|
|
44
|
+
* - read policy AND-ed into every select/byPk/aggregate root `where`, every
|
|
45
|
+
* relation subtree `where`, every aggregate `where`, and — via relation
|
|
46
|
+
* subtrees — mutation `returning`;
|
|
47
|
+
* - document-authored relationship predicates (exists/aggPredicate) get the
|
|
48
|
+
* TARGET table's read policy injected too, so filtering through a link
|
|
49
|
+
* can't become an existence oracle on rows the caller can't read;
|
|
50
|
+
* - write policy AND-ed into update/delete row filters, and set as the
|
|
51
|
+
* insert check for inserts (claims + inserted-values only in v2.0 — an
|
|
52
|
+
* exists() write policy makes a table un-insertable, loudly);
|
|
53
|
+
* - `col = claim(k)` AND-conjuncts of the write policy become pinned columns
|
|
54
|
+
* merged into every inserted row (and excluded from insertable/settable).
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
interface PinnedColumn {
|
|
58
|
+
column: string;
|
|
59
|
+
claim: ClaimKey;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Pins come from `col = claim(k)` comparisons the write policy fixes for EVERY
|
|
63
|
+
* caller, so the server can fill the column and drop it from the insert input.
|
|
64
|
+
*
|
|
65
|
+
* - `and` contributes the UNION of its operands' pins: each conjunct must hold.
|
|
66
|
+
* - `or` contributes their INTERSECTION on (column, claim): a policy with
|
|
67
|
+
* variants is a permissive union (§4c), so only a pin present — and pinned
|
|
68
|
+
* to the same claim — in every arm is fixed regardless of which arm admits
|
|
69
|
+
* the caller. Pinning from one arm alone would silently narrow the others
|
|
70
|
+
* (a `deals-admin` variant that only constrains `org` would lose the ability
|
|
71
|
+
* to insert on another author's behalf).
|
|
72
|
+
* - everything else (not/exists/capability/role/const/dynamic) pins nothing.
|
|
73
|
+
*
|
|
74
|
+
* A column left unpinned is not unprotected: it stays in the insert input and
|
|
75
|
+
* the same policy is enforced as the insert check, so a forged value is
|
|
76
|
+
* rejected with POLICY_CHECK_FAILED. Pinning is about removing the column from
|
|
77
|
+
* the client's reach, not about whether the rule is enforced.
|
|
78
|
+
*/
|
|
79
|
+
declare function collectPinnedColumns(writePolicy: PredIr): PinnedColumn[];
|
|
80
|
+
declare function injectPolicies({ roots, ctx }: {
|
|
81
|
+
roots: RootIr[];
|
|
82
|
+
ctx: CompileContext;
|
|
83
|
+
}): {
|
|
84
|
+
roots: RootIr[];
|
|
85
|
+
tableSet: string[];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Compiler-side naming — a thin adaptor over the CANONICAL naming authority,
|
|
90
|
+
* `src/sdl/naming.ts`. Every type/input/enum/scalar/root name the compiler
|
|
91
|
+
* resolves is derived from the same `tableNames`/`typeName` math the SDL
|
|
92
|
+
* generator emits (singularized PascalCase types, lowercase custom scalars),
|
|
93
|
+
* so the two surfaces can never skew. Pinned by
|
|
94
|
+
* `test/compiler/naming-parity.test.ts`.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Artifact/link key for the built-in platform-users entity (plan §4b). This
|
|
99
|
+
* is the LOGICAL key (`artifact.tables['platformUsers']`, link targets) — the
|
|
100
|
+
* SQL identity of the backing relation is `platform.users_directory` (see
|
|
101
|
+
* `platformUserMeta` in context.ts).
|
|
102
|
+
*/
|
|
103
|
+
declare const PLATFORM_USER_TABLE = "platformUsers";
|
|
104
|
+
|
|
105
|
+
/** GraphQL object type name for a table: `deal_comments` → `DealComment`. */
|
|
106
|
+
declare function typeNameForTable(table: string): string;
|
|
107
|
+
/** Query-root field names for a table — the SDL generator's own root names. */
|
|
108
|
+
declare function queryRootNames(table: string): {
|
|
109
|
+
select: string;
|
|
110
|
+
byPk: string;
|
|
111
|
+
aggregate: string;
|
|
112
|
+
};
|
|
113
|
+
type MutationOp = 'insert' | 'insertOne' | 'update' | 'updateByPk' | 'delete' | 'deleteByPk';
|
|
114
|
+
declare function mutationRootNames(table: string): Record<MutationOp, string>;
|
|
115
|
+
/** Generated input type name for a table, e.g. ('deals', 'boolExp') → 'DealBoolExp'. */
|
|
116
|
+
declare function inputTypeName(table: string, kind: InputRefKind): string;
|
|
117
|
+
/**
|
|
118
|
+
* Map a GraphQL input/enum type name back to `{ input, table }` via the naming
|
|
119
|
+
* rules. Returns undefined when the name doesn't match a generated §4f type
|
|
120
|
+
* for any known table.
|
|
121
|
+
*/
|
|
122
|
+
declare function classifyInputType(name: string, tableByTypename: ReadonlyMap<string, string>): {
|
|
123
|
+
input: InputRefKind;
|
|
124
|
+
table: string;
|
|
125
|
+
} | undefined;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Compile context — everything derived from the canonical definition that the
|
|
129
|
+
* restrict/lower/inject passes need: per-table runtime metadata (TableMetaIr),
|
|
130
|
+
* the root-field and input-type name indexes, and the compiled read/write
|
|
131
|
+
* policies with their pinned columns.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
interface QueryRootInfo {
|
|
135
|
+
kind: 'select' | 'byPk' | 'aggregate';
|
|
136
|
+
table: string;
|
|
137
|
+
}
|
|
138
|
+
interface CrudMutationRootInfo {
|
|
139
|
+
op: MutationOp;
|
|
140
|
+
table: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A declared copy-on-write mutation root (canonical `cowMutations`). Carries
|
|
144
|
+
* everything lowering needs so the executor can generate the SQL — no
|
|
145
|
+
* authored statements anywhere in the pipeline.
|
|
146
|
+
*/
|
|
147
|
+
interface CowMutationRootInfo {
|
|
148
|
+
op: 'cowOverride' | 'cowRevert';
|
|
149
|
+
table: string;
|
|
150
|
+
/** Logical synced twin table (same namespace). */
|
|
151
|
+
synced: string;
|
|
152
|
+
/** Shared single-column primary-key property. */
|
|
153
|
+
pk: string;
|
|
154
|
+
/** Override: overlay properties written by the UPDATE. */
|
|
155
|
+
set: readonly string[];
|
|
156
|
+
/** Override: properties copied INSERT…SELECT from synced (pk included). */
|
|
157
|
+
copyColumns: readonly string[];
|
|
158
|
+
}
|
|
159
|
+
type MutationRootInfo = CrudMutationRootInfo | CowMutationRootInfo;
|
|
160
|
+
interface CompileContext {
|
|
161
|
+
namespace: string;
|
|
162
|
+
tables: Record<string, TableMetaIr>;
|
|
163
|
+
/** GraphQL object type name → table name. */
|
|
164
|
+
tableByTypename: Map<string, string>;
|
|
165
|
+
queryRoots: Map<string, QueryRootInfo>;
|
|
166
|
+
mutationRoots: Map<string, MutationRootInfo>;
|
|
167
|
+
/** GraphQL enum type name → canonical enum (SelectColumn enums are NOT here). */
|
|
168
|
+
enumsByTypeName: Map<string, CanonicalEnum>;
|
|
169
|
+
readPolicies: Map<string, PredIr>;
|
|
170
|
+
/** Legacy combined write policy (mutation row filters when insert/update are absent). */
|
|
171
|
+
writePolicies: Map<string, PredIr>;
|
|
172
|
+
insertPolicies: Map<string, PredIr>;
|
|
173
|
+
updatePolicies: Map<string, PredIr>;
|
|
174
|
+
/** Per-table `col = claim(k)` insert-policy pins (insert-merged, non-insertable). */
|
|
175
|
+
pins: Map<string, PinnedColumn[]>;
|
|
176
|
+
/** Tables with both `insert` and `update` declared (no legacy `write`-only path). */
|
|
177
|
+
splitWritePolicyTables: ReadonlySet<string>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* §4b curated platform-users view — synthesized, never consumer-defined.
|
|
181
|
+
*
|
|
182
|
+
* The SQL identity (`schema`."`table`" — what the executor's tableFrag
|
|
183
|
+
* renders) is the hand-migrated view `platform.users_directory` (atlas
|
|
184
|
+
* migration 0481_platform_users_view.sql), NOT the logical artifact key
|
|
185
|
+
* `platformUsers` that links/tableSets/policies use. Must match
|
|
186
|
+
* atlas/src/server/services/orm/platform-users.ts EXACTLY — import-sharing is
|
|
187
|
+
* impossible across the package boundary, so the two are pinned by tests on
|
|
188
|
+
* both sides (test/compiler/compile-namespace.test.ts §4b and atlas
|
|
189
|
+
* platform-users.test.ts).
|
|
190
|
+
*/
|
|
191
|
+
declare function platformUserMeta(): TableMetaIr;
|
|
192
|
+
interface BuildContextResult {
|
|
193
|
+
ctx: CompileContext;
|
|
194
|
+
diagnostics: CompilerDiagnostic[];
|
|
195
|
+
}
|
|
196
|
+
declare function buildCompileContext(rawCanonical: CanonicalDefinition): BuildContextResult;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Parse pass — build the GraphQLSchema from SDL text and parse + validate the
|
|
200
|
+
* consumer's documents against it with graphql-js's spec rules. Validation
|
|
201
|
+
* failures become diagnostics (never thrown mid-pipeline) so every document
|
|
202
|
+
* reports at once.
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
interface SourceDocument {
|
|
206
|
+
path: string;
|
|
207
|
+
contents: string;
|
|
208
|
+
}
|
|
209
|
+
interface ParsedDocument {
|
|
210
|
+
path: string;
|
|
211
|
+
document: DocumentNode;
|
|
212
|
+
operations: OperationDefinitionNode[];
|
|
213
|
+
/** Fragments are document-scoped — bios colocates them via TS interpolation. */
|
|
214
|
+
fragments: Map<string, FragmentDefinitionNode>;
|
|
215
|
+
}
|
|
216
|
+
declare function parseSdl(sdl: string): GraphQLSchema;
|
|
217
|
+
interface ParseDocumentsResult {
|
|
218
|
+
documents: ParsedDocument[];
|
|
219
|
+
diagnostics: CompilerDiagnostic[];
|
|
220
|
+
}
|
|
221
|
+
declare function parseDocuments({ schema, documents, }: {
|
|
222
|
+
schema: GraphQLSchema;
|
|
223
|
+
documents: SourceDocument[];
|
|
224
|
+
}): ParseDocumentsResult;
|
|
225
|
+
|
|
226
|
+
/** Content hash of the canonical definition — the schema identity ops compile against. */
|
|
227
|
+
declare function computeSchemaHash(canonical: CanonicalDefinition): string;
|
|
228
|
+
interface ClientManifestOperation {
|
|
229
|
+
opHash: string;
|
|
230
|
+
kind: 'query' | 'mutation';
|
|
231
|
+
requires: CompiledOperation['requires'];
|
|
232
|
+
}
|
|
233
|
+
/** What codegen/the client transport needs: name → hash mapping + set identity. */
|
|
234
|
+
interface ClientManifest {
|
|
235
|
+
namespace: string;
|
|
236
|
+
schemaHash: string;
|
|
237
|
+
opsHash: string;
|
|
238
|
+
operations: Record<string, ClientManifestOperation>;
|
|
239
|
+
}
|
|
240
|
+
interface CompileNamespaceInput {
|
|
241
|
+
canonical: CanonicalDefinition;
|
|
242
|
+
/** Generated SDL text (src/sdl once it lands; test-local SDL until then). */
|
|
243
|
+
sdl: string;
|
|
244
|
+
documents: SourceDocument[];
|
|
245
|
+
}
|
|
246
|
+
type CompileNamespaceResult = {
|
|
247
|
+
ok: true;
|
|
248
|
+
artifact: CompiledArtifact;
|
|
249
|
+
manifest: ClientManifest;
|
|
250
|
+
diagnostics: CompilerDiagnostic[];
|
|
251
|
+
} | {
|
|
252
|
+
ok: false;
|
|
253
|
+
diagnostics: CompilerDiagnostic[];
|
|
254
|
+
};
|
|
255
|
+
declare function compileNamespace({ canonical, sdl, documents }: CompileNamespaceInput): CompileNamespaceResult;
|
|
256
|
+
/** compileNamespace that throws on errors — for callers that want the v1-style hard failure. */
|
|
257
|
+
declare function compileNamespaceOrThrow(input: CompileNamespaceInput): {
|
|
258
|
+
artifact: CompiledArtifact;
|
|
259
|
+
manifest: ClientManifest;
|
|
260
|
+
diagnostics: CompilerDiagnostic[];
|
|
261
|
+
};
|
|
262
|
+
/** Per-table `col = claim(k)` write-policy pins — exposed for SDL generation options. */
|
|
263
|
+
declare function computePinnedColumnsByTable(canonical: CanonicalDefinition): Record<string, PinnedColumn[]>;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Flatten pass — inline every fragment spread (and inline fragment) so the
|
|
267
|
+
* lowering pass sees one plain selection tree. The bios corpus uses flat,
|
|
268
|
+
* TS-interpolated fragments only; nested spreads still work here, but cycles
|
|
269
|
+
* and directives-on-spreads are rejected.
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
declare function flattenOperation({ operation, fragments, }: {
|
|
273
|
+
operation: OperationDefinitionNode;
|
|
274
|
+
fragments: ReadonlyMap<string, FragmentDefinitionNode>;
|
|
275
|
+
}): OperationDefinitionNode;
|
|
276
|
+
|
|
277
|
+
/** Bump on any change to lowering semantics — invalidates every op hash. */
|
|
278
|
+
declare const COMPILER_MAJOR = 1;
|
|
279
|
+
/** Canonical print of one flattened operation (fragments already inlined). */
|
|
280
|
+
declare function canonicalOperationText(definition: OperationDefinitionNode): string;
|
|
281
|
+
declare function computeOpHash({ definition, schemaHash, }: {
|
|
282
|
+
definition: OperationDefinitionNode;
|
|
283
|
+
schemaHash: string;
|
|
284
|
+
}): string;
|
|
285
|
+
/** Order-independent set hash over the sorted op hashes. */
|
|
286
|
+
declare function computeOpsHash(opHashes: readonly string[]): string;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Restrict pass — the grammar gate that keeps operations inside the v2.0
|
|
290
|
+
* envelope BEFORE lowering:
|
|
291
|
+
*
|
|
292
|
+
* - operations must be named (the op name keys the registry + manifest);
|
|
293
|
+
* - no subscriptions (post-v1);
|
|
294
|
+
* - every variable must be a scalar, a scalar list, a declared enum, OR one
|
|
295
|
+
* of the §4f generated input types (BoolExp/OrderBy/SelectColumn/
|
|
296
|
+
* InsertInput/SetInput/AppendInput/OnConflict) — mapped back to
|
|
297
|
+
* `{ inputRef kind, table }` via the naming rules. Anything else gets a
|
|
298
|
+
* targeted error naming what IS allowed.
|
|
299
|
+
* - a declared default is validated here and persisted into the IR, so the
|
|
300
|
+
* executor can apply it. A default the IR cannot carry faithfully is a
|
|
301
|
+
* compile error rather than a value that silently becomes NULL.
|
|
302
|
+
*/
|
|
303
|
+
|
|
304
|
+
interface RestrictedOperation {
|
|
305
|
+
name: string;
|
|
306
|
+
kind: 'query' | 'mutation';
|
|
307
|
+
requires: CompiledOperation['requires'];
|
|
308
|
+
variables: VariableIr[];
|
|
309
|
+
definition: OperationDefinitionNode;
|
|
310
|
+
}
|
|
311
|
+
declare function restrictOperation({ operation, ctx, }: {
|
|
312
|
+
operation: OperationDefinitionNode;
|
|
313
|
+
ctx: CompileContext;
|
|
314
|
+
}): RestrictedOperation;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Lower pass — flattened GraphQL selection trees → IR. Document-authored
|
|
318
|
+
* argument literals lower to PredIr/OrderIr (variables allowed in leaf
|
|
319
|
+
* positions as ValueIr variables); whole-variable arguments become §4f
|
|
320
|
+
* dynamic slots keyed by the variable name. Policies are NOT injected here —
|
|
321
|
+
* see inject.ts (this pass emits document-only `where` shapes).
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
declare const DEFAULT_LIMIT = 100;
|
|
325
|
+
declare const MAX_LIMIT = 1000;
|
|
326
|
+
declare class OperationLowerer {
|
|
327
|
+
private readonly ctx;
|
|
328
|
+
private readonly variables;
|
|
329
|
+
constructor(ctx: CompileContext, restricted: RestrictedOperation);
|
|
330
|
+
private meta;
|
|
331
|
+
private column;
|
|
332
|
+
private link;
|
|
333
|
+
private fieldCandidates;
|
|
334
|
+
/** Validate that a whole-variable argument is the declared §4f slot for this table. */
|
|
335
|
+
private slot;
|
|
336
|
+
private lowerValue;
|
|
337
|
+
lowerBoolExp(node: ValueNode, table: string): PredIr;
|
|
338
|
+
private lowerComparison;
|
|
339
|
+
/** Hasura aggregation predicate: `{ count: { predicate: { _gt: 2 }, filter: {…} } }`. */
|
|
340
|
+
private lowerAggPredicate;
|
|
341
|
+
lowerOrderBy(node: ValueNode, table: string): OrderIr[];
|
|
342
|
+
private lowerDirection;
|
|
343
|
+
lowerDistinctOn(node: ValueNode, table: string): string[] | {
|
|
344
|
+
slot: string;
|
|
345
|
+
};
|
|
346
|
+
private lowerLimit;
|
|
347
|
+
private lowerOffset;
|
|
348
|
+
lowerSelection(selectionSet: SelectionSetNode, table: string): SelectionIr;
|
|
349
|
+
/** The `{ aggregate { count sum {…} avg {…} } nodes {…} }` block shared by roots and relations. */
|
|
350
|
+
private lowerAggregateSelection;
|
|
351
|
+
lowerRoots(operation: OperationDefinitionNode, kind: 'query' | 'mutation'): RootIr[];
|
|
352
|
+
private parseRootDirectives;
|
|
353
|
+
private lowerQueryRoot;
|
|
354
|
+
/** byPk-style pk arguments: one argument per primary-key column, exactly. */
|
|
355
|
+
private lowerPkArgs;
|
|
356
|
+
private lowerMutationRoot;
|
|
357
|
+
/**
|
|
358
|
+
* Copy-on-write roots: flat args — the pk plus (override only) every
|
|
359
|
+
* declared set column. Overrides are full snapshots of the set columns, so
|
|
360
|
+
* every set argument must be supplied explicitly (pass null to clear a
|
|
361
|
+
* nullable column); the executor generates the copy/update/delete SQL from
|
|
362
|
+
* the structured fields, never from authored statements.
|
|
363
|
+
*/
|
|
364
|
+
private lowerCowRoot;
|
|
365
|
+
private lowerMutationResponse;
|
|
366
|
+
private lowerInsertObjects;
|
|
367
|
+
private lowerInsertRow;
|
|
368
|
+
private lowerOnConflictArg;
|
|
369
|
+
private lowerWriteValues;
|
|
370
|
+
private lowerColumnEntries;
|
|
371
|
+
private lowerPkColumnsArg;
|
|
372
|
+
}
|
|
373
|
+
declare function lowerOperation({ restricted, ctx }: {
|
|
374
|
+
restricted: RestrictedOperation;
|
|
375
|
+
ctx: CompileContext;
|
|
376
|
+
}): RootIr[];
|
|
377
|
+
|
|
378
|
+
declare const CONST_TRUE: PredIr;
|
|
379
|
+
/**
|
|
380
|
+
* AND predicates together, dropping `const(true)` operands so a policy-less
|
|
381
|
+
* table (or an absent document where) doesn't wrap everything in dead nodes.
|
|
382
|
+
*/
|
|
383
|
+
declare function andPred(...preds: Array<PredIr | undefined>): PredIr;
|
|
384
|
+
declare function walkPred(pred: PredIr, visit: (node: PredIr) => void): void;
|
|
385
|
+
declare function predContainsExists(pred: PredIr): boolean;
|
|
386
|
+
/** Structural containment: does `haystack` carry `needle` as a subtree? */
|
|
387
|
+
declare function predContains(haystack: PredIr, needle: PredIr): boolean;
|
|
388
|
+
|
|
389
|
+
export { type BuildContextResult, COMPILER_MAJOR, CONST_TRUE, type ClientManifest, type ClientManifestOperation, type CompileContext, type CompileNamespaceInput, type CompileNamespaceResult, type CompilerDiagnostic, DEFAULT_LIMIT, type DiagnosticSeverity, DocumentCompileError, MAX_LIMIT, type MutationOp, type MutationRootInfo, NamespaceCompileError, OperationLowerer, PLATFORM_USER_TABLE, type ParseDocumentsResult, type ParsedDocument, type PinnedColumn, type QueryRootInfo, type RestrictedOperation, type SourceDocument, andPred, buildCompileContext, canonicalOperationText, classifyInputType, collectPinnedColumns, compileNamespace, compileNamespaceOrThrow, computeOpHash, computeOpsHash, computePinnedColumnsByTable, computeSchemaHash, flattenOperation, injectPolicies, inputTypeName, lowerOperation, mutationRootNames, parseDocuments, parseSdl, platformUserMeta, predContains, predContainsExists, queryRootNames, restrictOperation, typeNameForTable, walkPred };
|