@rindle/query-compiler 0.4.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/LICENSE +201 -0
- package/README.md +42 -0
- package/dist/ast.d.ts +2 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +2 -0
- package/dist/ast.js.map +1 -0
- package/dist/catalog.d.ts +51 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +7 -0
- package/dist/catalog.js.map +1 -0
- package/dist/complete-ordering.d.ts +3 -0
- package/dist/complete-ordering.d.ts.map +1 -0
- package/dist/complete-ordering.js +44 -0
- package/dist/complete-ordering.js.map +1 -0
- package/dist/dialect.d.ts +49 -0
- package/dist/dialect.d.ts.map +1 -0
- package/dist/dialect.js +35 -0
- package/dist/dialect.js.map +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/pg-types.d.ts +20 -0
- package/dist/pg-types.d.ts.map +1 -0
- package/dist/pg-types.js +107 -0
- package/dist/pg-types.js.map +1 -0
- package/dist/postgres.d.ts +7 -0
- package/dist/postgres.d.ts.map +1 -0
- package/dist/postgres.js +134 -0
- package/dist/postgres.js.map +1 -0
- package/dist/reject.d.ts +3 -0
- package/dist/reject.d.ts.map +1 -0
- package/dist/reject.js +74 -0
- package/dist/reject.js.map +1 -0
- package/dist/walker.d.ts +11 -0
- package/dist/walker.d.ts.map +1 -0
- package/dist/walker.js +350 -0
- package/dist/walker.js.map +1 -0
- package/package.json +39 -0
- package/src/ast.ts +18 -0
- package/src/catalog.ts +59 -0
- package/src/complete-ordering.ts +48 -0
- package/src/dialect.ts +85 -0
- package/src/errors.ts +30 -0
- package/src/index.ts +74 -0
- package/src/pg-types.ts +119 -0
- package/src/postgres.ts +152 -0
- package/src/reject.ts +71 -0
- package/src/walker.ts +418 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @rindle/query-compiler
|
|
2
|
+
|
|
3
|
+
Compiles a Rindle query **`Ast`** into **one SQL `SELECT`** whose single column
|
|
4
|
+
`"rindle_result"` is the entire nested result tree as JSON — the server-side realization of
|
|
5
|
+
[`203-MUTATOR-READS-DESIGN.md`](../../designs-implemented) Phase 2, specified in
|
|
6
|
+
[`POSTGRES-READ-COMPILER-DESIGN.md`](../../designs/POSTGRES-READ-COMPILER-DESIGN.md).
|
|
7
|
+
|
|
8
|
+
A server mutator runs the compiled SELECT on its **already-open** Postgres transaction, so it
|
|
9
|
+
reads its own uncommitted writes for free (read-your-writes). Compilation is a **pure function
|
|
10
|
+
of `(Ast, Catalog)`** — no database round-trip to plan a read, only to run it.
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
compile(ast, catalog, { dialect: "postgres" }) → { sql, params }
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Design shape
|
|
17
|
+
|
|
18
|
+
- **Port.** The walker skeleton is ported from `rindle-d2s` (`rust/rindle-d2s/`, the SQLite
|
|
19
|
+
AST→SELECT compiler that matches our exact `Ast` and shares `complete_ordering` with the
|
|
20
|
+
engine's builder). The Postgres leaves and the `::text::<type>` cast strategy are ported
|
|
21
|
+
from mono's `z2s`. `rindle-d2s` stays the differential **oracle** (§9), never a runtime dep.
|
|
22
|
+
- **Two dialects, one product.** `postgres` is the product target. `sqlite` exists **only** as
|
|
23
|
+
the offline oracle: it lets the whole walker be proven end-to-end against Node's built-in
|
|
24
|
+
`node:sqlite` with zero infrastructure. It is never wired to a product consumer.
|
|
25
|
+
- **Driver-free.** Emits `{ sql, params }` and imports no Postgres driver — the app's driver
|
|
26
|
+
runs it through the plugger seam (Invariant 7).
|
|
27
|
+
- **The catalog** ([`src/catalog.ts`](src/catalog.ts)) is static and declared (§7): column
|
|
28
|
+
order, primary key, relationship cardinality, and per-column native type detail
|
|
29
|
+
(`{ type, isEnum, isArray }`) for the cast switch. Generated by `rindle pg prepare` from an
|
|
30
|
+
ephemeral migration-built Postgres (Phase B); hand-authored for tests.
|
|
31
|
+
|
|
32
|
+
## Status
|
|
33
|
+
|
|
34
|
+
Phase A (offline, oracle-tested; no api-server wiring). M1 — package scaffold + input
|
|
35
|
+
contracts (`Ast`, `Catalog`) — is in place; the walker (M2), Postgres leaf + casts (M3), and
|
|
36
|
+
edge semantics (M4) follow.
|
|
37
|
+
|
|
38
|
+
## Test
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pnpm --filter @rindle/query-compiler test # tsc --noEmit + node --test (node:sqlite oracle)
|
|
42
|
+
```
|
package/dist/ast.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,SAAS,EACT,GAAG,EACH,KAAK,EACL,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,aAAa,GACd,MAAM,gBAAgB,CAAC"}
|
package/dist/ast.js
ADDED
package/dist/ast.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Whether a relationship yields a single child object (`one`) or an array (`many`). */
|
|
2
|
+
export type Cardinality = "one" | "many";
|
|
3
|
+
/**
|
|
4
|
+
* Per-column type detail the Postgres compiler needs for value-model↔native-type
|
|
5
|
+
* reconciliation (§6.2). Mirrors z2s's `ServerColumnSchema`: the raw Postgres type name
|
|
6
|
+
* plus the two flags the cast switch branches on. The extension over what
|
|
7
|
+
* `rindle-pg-source` derives today (§7, review decision 2): enums and arrays are carried
|
|
8
|
+
* distinctly instead of collapsing into a text fallback.
|
|
9
|
+
*
|
|
10
|
+
* - `type` — the native Postgres type name: `"int4"`, `"text"`, `"bool"`, `"float8"`,
|
|
11
|
+
* `"numeric"`, `"timestamptz"`, `"timestamp"`, `"date"`, `"timetz"`, `"time"`, `"uuid"`,
|
|
12
|
+
* `"json"`/`"jsonb"`, or an **enum type name** (paired with `isEnum: true`).
|
|
13
|
+
* - `isEnum` — `type` names a Postgres enum ⇒ cast via `$N::text::"<type>"`.
|
|
14
|
+
* - `isArray` — the column is an array ⇒ unnest via `jsonb_array_elements_text`.
|
|
15
|
+
*
|
|
16
|
+
* The SQLite oracle dialect ignores this entirely: it binds native values (no casts).
|
|
17
|
+
*/
|
|
18
|
+
export interface ColumnType {
|
|
19
|
+
type: string;
|
|
20
|
+
isEnum: boolean;
|
|
21
|
+
isArray: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Per-table metadata the compiler needs beyond the `Ast`:
|
|
25
|
+
* - `columns` — the projected column list, **in projection order** (the order
|
|
26
|
+
* `json_object`/`jsonb_build_object` enumerates), matching the View's `Schema`.
|
|
27
|
+
* - `primaryKey` — the PK columns, for ordering-completion (§8): the compiler appends the
|
|
28
|
+
* full PK to every `orderBy` at every level for a total order, exactly as the engine's
|
|
29
|
+
* builder does (`rindle::complete_ordering`).
|
|
30
|
+
* - `columnTypes` — per-column native type detail, keyed by column name (§6.2; Postgres
|
|
31
|
+
* dialect only).
|
|
32
|
+
* - `relationships` — declared relationships → cardinality. This is the one structural
|
|
33
|
+
* fact not carried by the `Ast` (the relationship *shape* — correlation keys, nesting,
|
|
34
|
+
* where/order/limit — lives in the `Ast`'s `related` subqueries).
|
|
35
|
+
*/
|
|
36
|
+
export interface TableSchema {
|
|
37
|
+
columns: string[];
|
|
38
|
+
primaryKey: string[];
|
|
39
|
+
columnTypes: Record<string, ColumnType>;
|
|
40
|
+
relationships: Record<string, Cardinality>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The catalog: every table the compiler may reference, keyed by table name. Produced
|
|
44
|
+
* statically by `rindle pg prepare` from an ephemeral migration-built Postgres (§7,
|
|
45
|
+
* Phase B); hand-authored for tests. A pure input — the compiler never touches a database
|
|
46
|
+
* to obtain it.
|
|
47
|
+
*/
|
|
48
|
+
export interface Catalog {
|
|
49
|
+
tables: Record<string, TableSchema>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAMA,wFAAwF;AACxF,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,MAAM,CAAC;AAEzC;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CAC5C;AAED;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CACrC"}
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The static, declared type catalog (POSTGRES-READ-COMPILER-DESIGN.md §7) — the second
|
|
2
|
+
// input to the compiler, beside the `Ast`. Compilation is a pure function of
|
|
3
|
+
// `(Ast, Catalog)`; the catalog carries the facts the AST does not: column order, primary
|
|
4
|
+
// key, relationship cardinality, and — for the Postgres dialect — the per-column native
|
|
5
|
+
// type detail the `::text::<type>` cast strategy (§6.2) branches on.
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,6EAA6E;AAC7E,0FAA0F;AAC1F,wFAAwF;AACxF,qEAAqE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete-ordering.d.ts","sourceRoot":"","sources":["../src/complete-ordering.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,GAAG,EAAa,MAAM,UAAU,CAAC;AAE/C,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,GAAG,IAAI,CASnF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Ordering completion — the parity-critical pass (§8). The engine's builder appends the
|
|
2
|
+
// full primary key (as `asc`) to every `orderBy`, at every level, for a total order; this is
|
|
3
|
+
// a faithful port of `rindle::complete_ordering` (builder.rs:209), which is itself the port
|
|
4
|
+
// of the client builder's `completeOrdering`. Running the *same* completion is what makes the
|
|
5
|
+
// SELECT's row/child order match the engine's `Skip`/`Sort` tie-breaks exactly.
|
|
6
|
+
//
|
|
7
|
+
// Mutates `ast` in place (the caller passes a clone). `getPk(table)` yields a table's PK
|
|
8
|
+
// column names in PK order.
|
|
9
|
+
export function completeOrdering(ast, getPk) {
|
|
10
|
+
const pk = getPk(ast.table);
|
|
11
|
+
for (const csq of ast.related ?? []) {
|
|
12
|
+
completeOrdering(csq.subquery, getPk);
|
|
13
|
+
}
|
|
14
|
+
if (ast.where) {
|
|
15
|
+
completeOrderingInCondition(ast.where, getPk);
|
|
16
|
+
}
|
|
17
|
+
addPrimaryKeys(pk, ast);
|
|
18
|
+
}
|
|
19
|
+
function completeOrderingInCondition(cond, getPk) {
|
|
20
|
+
switch (cond.type) {
|
|
21
|
+
case "simple":
|
|
22
|
+
return;
|
|
23
|
+
case "correlatedSubquery":
|
|
24
|
+
completeOrdering(cond.related.subquery, getPk);
|
|
25
|
+
return;
|
|
26
|
+
case "and":
|
|
27
|
+
case "or":
|
|
28
|
+
for (const c of cond.conditions) {
|
|
29
|
+
completeOrderingInCondition(c, getPk);
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Append each PK column not already present (matched by name), as `asc`, in PK order.
|
|
35
|
+
* Already-present PK columns keep their existing position and direction. */
|
|
36
|
+
function addPrimaryKeys(pk, ast) {
|
|
37
|
+
const order = (ast.orderBy ??= []);
|
|
38
|
+
for (const pkCol of pk) {
|
|
39
|
+
if (!order.some(([field]) => field === pkCol)) {
|
|
40
|
+
order.push([pkCol, "asc"]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=complete-ordering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete-ordering.js","sourceRoot":"","sources":["../src/complete-ordering.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,6FAA6F;AAC7F,4FAA4F;AAC5F,8FAA8F;AAC9F,gFAAgF;AAChF,EAAE;AACF,yFAAyF;AACzF,4BAA4B;AAI5B,MAAM,UAAU,gBAAgB,CAAC,GAAQ,EAAE,KAAkC;IAC3E,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;QACpC,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QACd,2BAA2B,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;IACD,cAAc,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,2BAA2B,CAAC,IAAe,EAAE,KAAkC;IACtF,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO;QACT,KAAK,oBAAoB;YACvB,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC/C,OAAO;QACT,KAAK,KAAK,CAAC;QACX,KAAK,IAAI;YACP,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChC,2BAA2B,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YACxC,CAAC;YACD,OAAO;IACX,CAAC;AACH,CAAC;AAED;6EAC6E;AAC7E,SAAS,cAAc,CAAC,EAAY,EAAE,GAAQ;IAC5C,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC;IACnC,KAAK,MAAM,KAAK,IAAI,EAAE,EAAE,CAAC;QACvB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,EAAE,CAAC;YAC9C,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Dir } from "./ast.ts";
|
|
2
|
+
import type { ColumnType } from "./catalog.ts";
|
|
3
|
+
/** A scalar value bindable as a parameter (an array filter value is split into scalars). */
|
|
4
|
+
export type LitScalar = null | boolean | number | string;
|
|
5
|
+
export interface Dialect {
|
|
6
|
+
readonly name: "postgres" | "sqlite";
|
|
7
|
+
/** `json_object('k', v, …)` | `jsonb_build_object('k', v, …)`. `parts` are the flat
|
|
8
|
+
* `'key', valueExpr` fragments, in order. */
|
|
9
|
+
objectBuild(parts: string[]): string;
|
|
10
|
+
/** The array aggregate over `elem` with `orderSql` (e.g. ` ORDER BY __o0 ASC`) inside:
|
|
11
|
+
* `json_group_array(elem ORDER BY …)` | `jsonb_agg(elem ORDER BY …)`. */
|
|
12
|
+
groupArray(elem: string, orderSql: string): string;
|
|
13
|
+
/** The empty-array default for the `COALESCE` wrapper: `'[]'` | `'[]'::jsonb`. */
|
|
14
|
+
readonly emptyArray: string;
|
|
15
|
+
/** Re-assert the JSON subtype on a value round-tripped through a subquery's `AS` column
|
|
16
|
+
* (`json(x)` in SQLite; identity in Postgres, where `jsonb` is a real type). */
|
|
17
|
+
reassertJson(x: string): string;
|
|
18
|
+
/** The truthy/falsy constants for empty `AND`/`OR` folding and boolean keyword positions:
|
|
19
|
+
* `1`/`0` | `TRUE`/`FALSE`. */
|
|
20
|
+
readonly trueLit: string;
|
|
21
|
+
readonly falseLit: string;
|
|
22
|
+
/** An `ORDER BY` direction with the engine's null-low ordering made explicit where the
|
|
23
|
+
* dialect default differs (§8): SQLite is null-low by default (`ASC`/`DESC`); Postgres's
|
|
24
|
+
* default is the opposite, so it must emit `ASC NULLS FIRST` / `DESC NULLS LAST`. */
|
|
25
|
+
orderDir(dir: Dir): string;
|
|
26
|
+
/** Project a stored column into the value model's representation for the result JSON.
|
|
27
|
+
* Identity in SQLite; the outbound half of §6.2 in Postgres (e.g. timestamptz → epoch-ms). */
|
|
28
|
+
projectColumn(colRef: string, col: ColumnType | null): string;
|
|
29
|
+
/** Bind a scalar filter/paging value as a parameter: push onto `params`, return the
|
|
30
|
+
* placeholder SQL. `col` is the compared column's type when known (drives the Postgres
|
|
31
|
+
* `::text::<type>` casts, §6.2); `null` ⇒ infer from the JS type. SQLite ignores `col`
|
|
32
|
+
* and `isComparison` — it binds natives. */
|
|
33
|
+
bindValue(params: unknown[], value: LitScalar, col: ColumnType | null, isComparison: boolean): string;
|
|
34
|
+
/** Double-quote an identifier, doubling embedded `"`. Identical across dialects (kept on
|
|
35
|
+
* the seam for uniformity). */
|
|
36
|
+
quoteIdent(name: string): string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The SQLite dialect — the daemon backend's session-read target (DAEMON-INTERACTIVE-TXN §5.4)
|
|
40
|
+
* and the offline differential oracle (§9). It binds native values as parameters (no
|
|
41
|
+
* `::text::<type>` casts — SQLite is the canonical store, so there is no driver seam to pin
|
|
42
|
+
* and no second representation to reconcile), relies on SQLite's null-low default ordering
|
|
43
|
+
* (which matches the engine's `null < everything`), and re-asserts the `json()` subtype where
|
|
44
|
+
* objects round-trip through a subquery column. Matches `rindle-d2s`'s raw SQL shapes so the
|
|
45
|
+
* two agree modulo parameterization; the executing connection must run
|
|
46
|
+
* `PRAGMA case_sensitive_like = ON` (every daemon cluster connection does — `open_wal2`).
|
|
47
|
+
*/
|
|
48
|
+
export declare const sqliteDialect: Dialect;
|
|
49
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,4FAA4F;AAC5F,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;IAErC;kDAC8C;IAC9C,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAErC;8EAC0E;IAC1E,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAEnD,kFAAkF;IAClF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;qFACiF;IACjF,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEhC;oCACgC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B;;0FAEsF;IACtF,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC;IAE3B;mGAC+F;IAC/F,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,GAAG,MAAM,CAAC;IAE9D;;;iDAG6C;IAC7C,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,EAAE,YAAY,EAAE,OAAO,GAAG,MAAM,CAAC;IAEtG;oCACgC;IAChC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC;AAMD;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,OAgB3B,CAAC"}
|
package/dist/dialect.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The dialect seam (§6.1). The walker is dialect-independent; only these leaves differ
|
|
2
|
+
// between SQLite and Postgres: the Postgres leaf carries the §6.2 `::text::<type>` casts and
|
|
3
|
+
// explicit NULLS ordering; the SQLite leaf binds natives with NO casts (the canonical store
|
|
4
|
+
// needs no reconciliation — DAEMON-INTERACTIVE-TXN-DESIGN.md §5.4).
|
|
5
|
+
function quoteIdent(name) {
|
|
6
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The SQLite dialect — the daemon backend's session-read target (DAEMON-INTERACTIVE-TXN §5.4)
|
|
10
|
+
* and the offline differential oracle (§9). It binds native values as parameters (no
|
|
11
|
+
* `::text::<type>` casts — SQLite is the canonical store, so there is no driver seam to pin
|
|
12
|
+
* and no second representation to reconcile), relies on SQLite's null-low default ordering
|
|
13
|
+
* (which matches the engine's `null < everything`), and re-asserts the `json()` subtype where
|
|
14
|
+
* objects round-trip through a subquery column. Matches `rindle-d2s`'s raw SQL shapes so the
|
|
15
|
+
* two agree modulo parameterization; the executing connection must run
|
|
16
|
+
* `PRAGMA case_sensitive_like = ON` (every daemon cluster connection does — `open_wal2`).
|
|
17
|
+
*/
|
|
18
|
+
export const sqliteDialect = {
|
|
19
|
+
name: "sqlite",
|
|
20
|
+
objectBuild: (parts) => `json_object(${parts.join(", ")})`,
|
|
21
|
+
groupArray: (elem, orderSql) => `json_group_array(${elem}${orderSql})`,
|
|
22
|
+
emptyArray: "'[]'",
|
|
23
|
+
reassertJson: (x) => `json(${x})`,
|
|
24
|
+
trueLit: "1",
|
|
25
|
+
falseLit: "0",
|
|
26
|
+
orderDir: (dir) => (dir === "asc" ? "ASC" : "DESC"),
|
|
27
|
+
projectColumn: (colRef) => colRef,
|
|
28
|
+
bindValue: (params, value) => {
|
|
29
|
+
// SQLite has no boolean type; its driver binds 1/0. Everything else binds natively.
|
|
30
|
+
params.push(typeof value === "boolean" ? (value ? 1 : 0) : value);
|
|
31
|
+
return "?";
|
|
32
|
+
},
|
|
33
|
+
quoteIdent,
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=dialect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.js","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,6FAA6F;AAC7F,4FAA4F;AAC5F,oEAAoE;AAmDpE,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AACzC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAY;IACpC,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;IAC1D,UAAU,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,oBAAoB,IAAI,GAAG,QAAQ,GAAG;IACtE,UAAU,EAAE,MAAM;IAClB,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG;IACjC,OAAO,EAAE,GAAG;IACZ,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IACnD,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;IACjC,SAAS,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAC3B,oFAAoF;QACpF,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAClE,OAAO,GAAG,CAAC;IACb,CAAC;IACD,UAAU;CACX,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class CompileError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
/** A referenced table is not in the catalog. */
|
|
5
|
+
export declare function unknownTable(table: string): CompileError;
|
|
6
|
+
/** A `related`/EXISTS relationship's cardinality is not declared in the catalog. */
|
|
7
|
+
export declare function unknownRelationship(table: string, rel: string): CompileError;
|
|
8
|
+
/** A `related` subquery is missing an alias (every child must be named). */
|
|
9
|
+
export declare function missingAlias(table: string): CompileError;
|
|
10
|
+
/** An AST feature the compiler does not lower in the position it appears — rejected loudly
|
|
11
|
+
* rather than emitting silently-wrong SQL (e.g. a `start` paging bound inside EXISTS). */
|
|
12
|
+
export declare function unsupported(what: string): CompileError;
|
|
13
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAExD;AAED,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAE5E;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAExD;AAED;2FAC2F;AAC3F,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAEtD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Why a query could not be compiled. Mirrors `rindle-d2s`'s `CompileError` (lib.rs:133) so
|
|
2
|
+
// the two compilers reject the same shapes with the same reasons.
|
|
3
|
+
export class CompileError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "CompileError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** A referenced table is not in the catalog. */
|
|
10
|
+
export function unknownTable(table) {
|
|
11
|
+
return new CompileError(`unknown table \`${table}\``);
|
|
12
|
+
}
|
|
13
|
+
/** A `related`/EXISTS relationship's cardinality is not declared in the catalog. */
|
|
14
|
+
export function unknownRelationship(table, rel) {
|
|
15
|
+
return new CompileError(`unknown relationship \`${rel}\` on table \`${table}\``);
|
|
16
|
+
}
|
|
17
|
+
/** A `related` subquery is missing an alias (every child must be named). */
|
|
18
|
+
export function missingAlias(table) {
|
|
19
|
+
return new CompileError(`related subquery on \`${table}\` has no alias`);
|
|
20
|
+
}
|
|
21
|
+
/** An AST feature the compiler does not lower in the position it appears — rejected loudly
|
|
22
|
+
* rather than emitting silently-wrong SQL (e.g. a `start` paging bound inside EXISTS). */
|
|
23
|
+
export function unsupported(what) {
|
|
24
|
+
return new CompileError(`unsupported AST feature: ${what}`);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,kEAAkE;AAElE,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,gDAAgD;AAChD,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,IAAI,YAAY,CAAC,mBAAmB,KAAK,IAAI,CAAC,CAAC;AACxD,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,GAAW;IAC5D,OAAO,IAAI,YAAY,CAAC,0BAA0B,GAAG,iBAAiB,KAAK,IAAI,CAAC,CAAC;AACnF,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,IAAI,YAAY,CAAC,yBAAyB,KAAK,iBAAiB,CAAC,CAAC;AAC3E,CAAC;AAED;2FAC2F;AAC3F,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,YAAY,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;AAC9D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type { Aggregate, Ast, Bound, Condition, CorrelatedSubquery, Correlation, Dir, ExistsOp, LitValue, OrderPart, SimpleOp, ValuePosition, } from "./ast.ts";
|
|
2
|
+
export type { Cardinality, Catalog, ColumnType, TableSchema } from "./catalog.ts";
|
|
3
|
+
export type { Dialect } from "./dialect.ts";
|
|
4
|
+
export { sqliteDialect } from "./dialect.ts";
|
|
5
|
+
export { postgresDialect } from "./postgres.ts";
|
|
6
|
+
import type { Ast } from "./ast.ts";
|
|
7
|
+
import type { Catalog } from "./catalog.ts";
|
|
8
|
+
/** Which SQL dialect to emit. Both are product targets: `postgres` for the BYO-PG backend,
|
|
9
|
+
* `sqlite` for the daemon backend's session reads (and the offline oracle, §9). */
|
|
10
|
+
export type DialectName = "postgres" | "sqlite";
|
|
11
|
+
export interface CompileOptions {
|
|
12
|
+
dialect: DialectName;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A compiled query: one SQL `SELECT` plus its positional bound parameters. `sql` returns a
|
|
16
|
+
* single row with a single column `"rindle_result"` — the whole nested result as JSON
|
|
17
|
+
* (`jsonb` on Postgres, `json` text on SQLite). No runtime value is ever interpolated into
|
|
18
|
+
* `sql`; every filter/paging value is a bound parameter (Invariant 4).
|
|
19
|
+
*/
|
|
20
|
+
export interface CompiledQuery {
|
|
21
|
+
sql: string;
|
|
22
|
+
/** In order: `$1..$n` for Postgres, `?` for SQLite. */
|
|
23
|
+
params: unknown[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Compile `ast` against `catalog` into `{ sql, params }` (§4). A pure function of its
|
|
27
|
+
* inputs — no database access (Invariant 2). The root is **singular** when `ast.one` is set
|
|
28
|
+
* (a single JSON object or `null`), else **plural** (a JSON array).
|
|
29
|
+
*/
|
|
30
|
+
export declare function compile(ast: Ast, catalog: Catalog, opts: CompileOptions): CompiledQuery;
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,YAAY,EACV,SAAS,EACT,GAAG,EACH,KAAK,EACL,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAClF,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C;oFACoF;AACpF,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,WAAW,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,aAAa,CAQvF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @rindle/query-compiler — compile a Rindle query `Ast` into one SQL `SELECT` whose single
|
|
2
|
+
// column `"rindle_result"` is the entire nested result tree as JSON, run on a live SQL
|
|
3
|
+
// backend inside the caller's open transaction (POSTGRES-READ-COMPILER-DESIGN.md §4).
|
|
4
|
+
//
|
|
5
|
+
// Dialect-parametric, with BOTH dialects product targets:
|
|
6
|
+
// - `postgres` — the BYO-Postgres server mutator read, with the §6.2 `::text::<type>` cast
|
|
7
|
+
// discipline (PG is a second type system whose driver parsing must be pinned + reconciled).
|
|
8
|
+
// - `sqlite` — the daemon-backend mutator read, ridden through an interactive mutation
|
|
9
|
+
// session (DAEMON-INTERACTIVE-TXN-DESIGN.md §5.4). NO casts, by design: SQLite IS the
|
|
10
|
+
// canonical store and results return as raw storage classes over Rindle's own value
|
|
11
|
+
// encoding, so there is no second representation to reconcile — every value binds as a
|
|
12
|
+
// native parameter (`rindle-d2s`, the Rust twin, states the same principle: "Values
|
|
13
|
+
// (minimal — no casting)"). It doubles as the offline differential oracle (§9, §11),
|
|
14
|
+
// which is what proves the shared walker end-to-end against `node:sqlite`.
|
|
15
|
+
export { sqliteDialect } from "./dialect.js";
|
|
16
|
+
export { postgresDialect } from "./postgres.js";
|
|
17
|
+
import { sqliteDialect } from "./dialect.js";
|
|
18
|
+
import { postgresDialect } from "./postgres.js";
|
|
19
|
+
import { compileWith } from "./walker.js";
|
|
20
|
+
/**
|
|
21
|
+
* Compile `ast` against `catalog` into `{ sql, params }` (§4). A pure function of its
|
|
22
|
+
* inputs — no database access (Invariant 2). The root is **singular** when `ast.one` is set
|
|
23
|
+
* (a single JSON object or `null`), else **plural** (a JSON array).
|
|
24
|
+
*/
|
|
25
|
+
export function compile(ast, catalog, opts) {
|
|
26
|
+
const singular = ast.one === true;
|
|
27
|
+
switch (opts.dialect) {
|
|
28
|
+
case "sqlite":
|
|
29
|
+
return compileWith(ast, catalog, sqliteDialect, singular);
|
|
30
|
+
case "postgres":
|
|
31
|
+
return compileWith(ast, catalog, postgresDialect, singular);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,uFAAuF;AACvF,sFAAsF;AACtF,EAAE;AACF,0DAA0D;AAC1D,2FAA2F;AAC3F,8FAA8F;AAC9F,uFAAuF;AACvF,wFAAwF;AACxF,sFAAsF;AACtF,yFAAyF;AACzF,sFAAsF;AACtF,uFAAuF;AACvF,6EAA6E;AAkB7E,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIhD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAsB1C;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,GAAQ,EAAE,OAAgB,EAAE,IAAoB;IACtE,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC;IAClC,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC5D,KAAK,UAAU;YACb,OAAO,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Strips args (the `(32)` in `char(32)`) and lowercases — mono's `formatTypeForLookup`.
|
|
2
|
+
* Every predicate normalizes through this, so `VARCHAR(255)` / `UUID` classify correctly. */
|
|
3
|
+
export declare function formatTypeForLookup(pgType: string): string;
|
|
4
|
+
export declare function isPgNumberType(pgType: string): boolean;
|
|
5
|
+
export declare function isPgNativeStringType(pgType: string): boolean;
|
|
6
|
+
export declare function isPgTextRepresentedType(pgType: string): boolean;
|
|
7
|
+
export declare function isPgStringType(pgType: string): boolean;
|
|
8
|
+
/** A temporal type projected as epoch-ms (outbound) and reconciled via `to_timestamp`/interval
|
|
9
|
+
* (inbound). Everything else projects raw. */
|
|
10
|
+
export declare function isTemporalType(pgType: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether an outbound temporal projection needs the `mod 1 day` normalization. **Deliberately
|
|
13
|
+
* narrower than z2s's `selectIdent`**, which (via a switch fall-through) also normalizes
|
|
14
|
+
* `timestamptz` — that would collapse a full timestamp to time-of-day. The design (§6.2) is
|
|
15
|
+
* explicit that `timestamptz` projects as plain epoch-ms and only the offset-bearing
|
|
16
|
+
* *time-of-day* types are modular-normalized; the §9 parity harness against the engine's value
|
|
17
|
+
* model is the check that keeps this honest.
|
|
18
|
+
*/
|
|
19
|
+
export declare function needsTimeOfDayNormalization(pgType: string): boolean;
|
|
20
|
+
//# sourceMappingURL=pg-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-types.d.ts","sourceRoot":"","sources":["../src/pg-types.ts"],"names":[],"mappings":"AA4DA;8FAC8F;AAC9F,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAI1D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD;AAgBD;+CAC+C;AAC/C,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEtD;AAMD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnE"}
|