@loaders.gl/core 5.0.0-rc.1 → 5.0.0-rc.2
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/SCAN-README.md +8 -8
- package/dist/arrow-geometry/binary-features.cjs +2 -2
- package/dist/arrow-geometry/binary-features.cjs.map +2 -2
- package/dist/arrow-geometry/binary-features.js +1 -1
- package/dist/arrow-geometry/binary-features.js.map +1 -1
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.cjs +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.cjs.map +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.js +1 -1
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.js.map +1 -1
- package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.cjs +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.cjs.map +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.js +1 -1
- package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.js.map +1 -1
- package/dist/cluster-source.cjs +5 -5
- package/dist/cluster-source.cjs.map +2 -2
- package/dist/dist.dev.js +61 -13
- package/dist/dist.min.js +3 -3
- package/dist/federated-table-scan-source.cjs +8 -96
- package/dist/federated-table-scan-source.cjs.map +3 -3
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs +2 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs.map +2 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js +1 -1
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js.map +1 -1
- package/dist/index.cjs +65 -17
- package/dist/index.cjs.map +1 -1
- package/dist/lib/api/load.js +36 -7
- package/dist/lib/api/load.js.map +1 -1
- package/dist/lib/api/parse.js +5 -2
- package/dist/lib/api/parse.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +38 -14
- package/dist/loader-utils/index.cjs.map +2 -2
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.d.ts +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.js +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.js.map +1 -1
- package/dist/loader-utils/lib/sources/tile-source-adapter.js +1 -1
- package/dist/loader-utils/lib/sources/tile-source-adapter.js.map +1 -1
- package/dist/loader-utils/lib/sources/tile-source.d.ts +1 -1
- package/dist/loader-utils/lib/sources/tile-source.d.ts.map +1 -1
- package/dist/loader-utils/loader-types.d.ts +6 -0
- package/dist/loader-utils/loader-types.d.ts.map +1 -1
- package/dist/loader-utils/loader-types.js.map +1 -1
- package/dist/loader-utils/tile-grid.cjs +5 -5
- package/dist/loader-utils/tile-grid.cjs.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/dist/scan/query-scales.cjs +2 -1
- package/dist/scan/query-scales.cjs.map +2 -2
- package/dist/scan/query-scales.d.ts +2 -1
- package/dist/scan/query-scales.d.ts.map +1 -1
- package/dist/scan/query-scales.js +2 -1
- package/dist/scan/query-scales.js.map +1 -1
- package/dist/scan/scan-engine.cjs.map +1 -1
- package/dist/scan/scan-engine.d.ts +1 -1
- package/dist/scan/scan-engine.js +1 -1
- package/dist/scan/sql-predicate-schema.cjs +10 -94
- package/dist/scan/sql-predicate-schema.cjs.map +3 -3
- package/dist/scan/sql-predicate-schema.d.ts +1 -1
- package/dist/scan/sql-predicate-schema.d.ts.map +1 -1
- package/dist/scan/sql-predicate-schema.js +9 -103
- package/dist/scan/sql-predicate-schema.js.map +1 -1
- package/dist/scan/sql-predicate-zod.cjs.map +1 -1
- package/dist/scan/sql-predicate-zod.d.ts +1 -1
- package/dist/scan/sql-predicate-zod.js +1 -1
- package/dist/vector-table-scan-source.cjs +8 -96
- package/dist/vector-table-scan-source.cjs.map +3 -3
- package/dist/worker-utils/index.cjs +31 -7
- package/dist/worker-utils/index.cjs.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +4 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.js +40 -6
- package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
- package/package.json +24 -104
- package/src/arrow-geometry/binary-features.ts +1 -1
- package/src/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.ts +1 -1
- package/src/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.ts +1 -1
- package/src/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.ts +1 -1
- package/src/lib/api/load.ts +36 -7
- package/src/lib/api/parse.ts +6 -2
- package/src/loader-utils/lib/sources/tile-grid.ts +6 -2
- package/src/loader-utils/lib/sources/tile-source-adapter.ts +1 -1
- package/src/loader-utils/lib/sources/tile-source.ts +1 -1
- package/src/loader-utils/loader-types.ts +6 -0
- package/src/scan/query-scales.ts +3 -4
- package/src/scan/scan-engine.ts +1 -1
- package/src/scan/sql-predicate-schema.ts +14 -125
- package/src/scan/sql-predicate-zod.ts +1 -1
- package/src/worker-utils/lib/worker-api/process-on-worker.ts +39 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/scan/scan-engine.ts"],
|
|
4
|
-
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Table} from 'apache-arrow';\nimport {explainArrowTableQuery, queryArrowTable, type ArrowQueryOptions} from './query-arrow-table';\nimport {type SQLPredicate} from './sql-predicate-types';\nimport type {TableQueryExplain} from '@loaders.gl/core/loader-utils';\n\n/** Names accepted by the optional scan engine factory. */\nexport type ScanBackendName = 'arrow' | (string & {});\n\n/** A backend implementation for the Arrow table query surface. */\nexport type ScanBackend = Readonly<{\n /** Stable backend name reported by the engine. */\n name: ScanBackendName;\n /** Executes a query over one in-memory Arrow table. */\n query(sourceTable: Table, options?: ArrowQueryOptions): Table;\n /** Optional asynchronous execution hook for backends that compile or schedule work. */\n queryAsync?: (sourceTable: Table, options?: ArrowQueryOptions) => Promise<Table>;\n /** Explains a query without evaluating table rows. */\n explain(sourceTable: Table, options?: ArrowQueryOptions): TableQueryExplain<SQLPredicate>;\n}>;\n\n/** Lazy loader used to register an optional scan backend. */\nexport type ScanBackendLoader = () => ScanBackend | Promise<ScanBackend>;\n\n/** Options for creating a scan engine. */\nexport type ScanEngineOptions = Readonly<{\n /** Backend to use. Arrow is the built-in reference backend. */\n backend?: ScanBackendName;\n}>;\n\n/** Stable application-facing scan engine returned by {@link createScanEngine}. */\nexport type ScanEngine = ScanBackend & {\n /** Executes a query asynchronously, allowing backends to schedule remote or compiled work. */\n queryAsync: (sourceTable: Table, options?: ArrowQueryOptions) => Promise<Table>;\n};\n\nconst scanBackends = new Map<ScanBackendName, ScanBackend | ScanBackendLoader>();\n\nconst arrowScanBackend: ScanBackend = Object.freeze({\n name: 'arrow',\n query: queryArrowTable,\n queryAsync: (sourceTable, options) =>\n Promise.resolve().then(() => queryArrowTable(sourceTable, options)),\n explain: explainArrowTableQuery\n});\n\n// Store the built-in backend directly. Apart from avoiding needless indirection, this keeps\n// coverage stable when browser shards transform this shared module independently.\nscanBackends.set('arrow', arrowScanBackend);\n\n/**\n * Registers a lazy scan backend without adding it to the default bundle.\n *\n * This is the extension point for future DuckDB and GPU implementations. The backend package can\n * register a dynamic loader from application code while the public import remains\n * `@loaders.gl/core/
|
|
4
|
+
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Table} from 'apache-arrow';\nimport {explainArrowTableQuery, queryArrowTable, type ArrowQueryOptions} from './query-arrow-table';\nimport {type SQLPredicate} from './sql-predicate-types';\nimport type {TableQueryExplain} from '@loaders.gl/core/loader-utils';\n\n/** Names accepted by the optional scan engine factory. */\nexport type ScanBackendName = 'arrow' | (string & {});\n\n/** A backend implementation for the Arrow table query surface. */\nexport type ScanBackend = Readonly<{\n /** Stable backend name reported by the engine. */\n name: ScanBackendName;\n /** Executes a query over one in-memory Arrow table. */\n query(sourceTable: Table, options?: ArrowQueryOptions): Table;\n /** Optional asynchronous execution hook for backends that compile or schedule work. */\n queryAsync?: (sourceTable: Table, options?: ArrowQueryOptions) => Promise<Table>;\n /** Explains a query without evaluating table rows. */\n explain(sourceTable: Table, options?: ArrowQueryOptions): TableQueryExplain<SQLPredicate>;\n}>;\n\n/** Lazy loader used to register an optional scan backend. */\nexport type ScanBackendLoader = () => ScanBackend | Promise<ScanBackend>;\n\n/** Options for creating a scan engine. */\nexport type ScanEngineOptions = Readonly<{\n /** Backend to use. Arrow is the built-in reference backend. */\n backend?: ScanBackendName;\n}>;\n\n/** Stable application-facing scan engine returned by {@link createScanEngine}. */\nexport type ScanEngine = ScanBackend & {\n /** Executes a query asynchronously, allowing backends to schedule remote or compiled work. */\n queryAsync: (sourceTable: Table, options?: ArrowQueryOptions) => Promise<Table>;\n};\n\nconst scanBackends = new Map<ScanBackendName, ScanBackend | ScanBackendLoader>();\n\nconst arrowScanBackend: ScanBackend = Object.freeze({\n name: 'arrow',\n query: queryArrowTable,\n queryAsync: (sourceTable, options) =>\n Promise.resolve().then(() => queryArrowTable(sourceTable, options)),\n explain: explainArrowTableQuery\n});\n\n// Store the built-in backend directly. Apart from avoiding needless indirection, this keeps\n// coverage stable when browser shards transform this shared module independently.\nscanBackends.set('arrow', arrowScanBackend);\n\n/**\n * Registers a lazy scan backend without adding it to the default bundle.\n *\n * This is the extension point for future DuckDB and GPU implementations. The backend package can\n * register a dynamic loader from application code while the public import remains\n * `@loaders.gl/core/query`.\n */\nexport function registerScanBackend(name: ScanBackendName, loader: ScanBackendLoader): void {\n if (!name || !loader) {\n throw new Error('A scan backend name and loader are required');\n }\n scanBackends.set(name, loader);\n}\n\n/**\n * Creates the configured scan engine.\n *\n * The factory is asynchronous even for Arrow so optional backends can be loaded lazily later\n * without changing the application-facing API.\n */\nexport async function createScanEngine(options: ScanEngineOptions = {}): Promise<ScanEngine> {\n const backendName = options.backend || 'arrow';\n const registeredBackend = scanBackends.get(backendName);\n if (!registeredBackend) {\n throw new Error(\n `Scan backend \"${backendName}\" is not registered. The built-in backend is \"arrow\".`\n );\n }\n const backend =\n typeof registeredBackend === 'function' ? await registeredBackend() : registeredBackend;\n if (backend.name !== backendName) {\n throw new Error(\n `Scan backend loader returned \"${backend.name}\" while \"${backendName}\" was requested.`\n );\n }\n const query = backend.query.bind(backend);\n const explain = backend.explain.bind(backend);\n const queryAsync = backend.queryAsync\n ? backend.queryAsync.bind(backend)\n : async (sourceTable: Table, queryOptions?: ArrowQueryOptions) =>\n backend.query.call(backend, sourceTable, queryOptions);\n return Object.freeze({...backend, query, explain, queryAsync});\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,+BAA8E;AAkC9E,IAAM,eAAe,oBAAI,IAAsD;AAE/E,IAAM,mBAAgC,OAAO,OAAO;AAAA,EAClD,MAAM;AAAA,EACN,OAAO;AAAA,EACP,YAAY,CAAC,aAAa,YACxB,QAAQ,QAAQ,EAAE,KAAK,UAAM,0CAAgB,aAAa,OAAO,CAAC;AAAA,EACpE,SAAS;AACX,CAAC;AAID,aAAa,IAAI,SAAS,gBAAgB;AASnC,SAAS,oBAAoB,MAAuB,QAAiC;AAC1F,MAAI,CAAC,QAAQ,CAAC,QAAQ;AACpB,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AACA,eAAa,IAAI,MAAM,MAAM;AAC/B;AAQA,eAAsB,iBAAiB,UAA6B,CAAC,GAAwB;AAC3F,QAAM,cAAc,QAAQ,WAAW;AACvC,QAAM,oBAAoB,aAAa,IAAI,WAAW;AACtD,MAAI,CAAC,mBAAmB;AACtB,UAAM,IAAI;AAAA,MACR,iBAAiB,WAAW;AAAA,IAC9B;AAAA,EACF;AACA,QAAM,UACJ,OAAO,sBAAsB,aAAa,MAAM,kBAAkB,IAAI;AACxE,MAAI,QAAQ,SAAS,aAAa;AAChC,UAAM,IAAI;AAAA,MACR,iCAAiC,QAAQ,IAAI,YAAY,WAAW;AAAA,IACtE;AAAA,EACF;AACA,QAAM,QAAQ,QAAQ,MAAM,KAAK,OAAO;AACxC,QAAM,UAAU,QAAQ,QAAQ,KAAK,OAAO;AAC5C,QAAM,aAAa,QAAQ,aACvB,QAAQ,WAAW,KAAK,OAAO,IAC/B,OAAO,aAAoB,iBACzB,QAAQ,MAAM,KAAK,SAAS,aAAa,YAAY;AAC3D,SAAO,OAAO,OAAO,EAAC,GAAG,SAAS,OAAO,SAAS,WAAU,CAAC;AAC/D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -32,7 +32,7 @@ export type ScanEngine = ScanBackend & {
|
|
|
32
32
|
*
|
|
33
33
|
* This is the extension point for future DuckDB and GPU implementations. The backend package can
|
|
34
34
|
* register a dynamic loader from application code while the public import remains
|
|
35
|
-
* `@loaders.gl/core/
|
|
35
|
+
* `@loaders.gl/core/query`.
|
|
36
36
|
*/
|
|
37
37
|
export declare function registerScanBackend(name: ScanBackendName, loader: ScanBackendLoader): void;
|
|
38
38
|
/**
|
package/dist/scan/scan-engine.js
CHANGED
|
@@ -17,7 +17,7 @@ scanBackends.set('arrow', arrowScanBackend);
|
|
|
17
17
|
*
|
|
18
18
|
* This is the extension point for future DuckDB and GPU implementations. The backend package can
|
|
19
19
|
* register a dynamic loader from application code while the public import remains
|
|
20
|
-
* `@loaders.gl/core/
|
|
20
|
+
* `@loaders.gl/core/query`.
|
|
21
21
|
*/
|
|
22
22
|
export function registerScanBackend(name, loader) {
|
|
23
23
|
if (!name || !loader) {
|
|
@@ -25,9 +25,7 @@ __export(sql_predicate_schema_exports, {
|
|
|
25
25
|
validateSQLPredicate: () => validateSQLPredicate
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(sql_predicate_schema_exports);
|
|
28
|
-
var
|
|
29
|
-
var MAXIMUM_PREDICATE_DEPTH = 64;
|
|
30
|
-
var MAXIMUM_PREDICATE_NODES = 4096;
|
|
28
|
+
var import_parser = require("@math.gl/sql/parser");
|
|
31
29
|
var SQL_PREDICATE_JSON_SCHEMA = {
|
|
32
30
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
33
31
|
$id: "https://loaders.gl/schemas/sql-predicate.schema.json",
|
|
@@ -134,99 +132,17 @@ function isSQLPredicate(value) {
|
|
|
134
132
|
}
|
|
135
133
|
}
|
|
136
134
|
function validateSQLPredicate(value) {
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
(0, import_parser.validateSQLPredicate)(value);
|
|
136
|
+
rejectPredicateCasts(value, "$");
|
|
139
137
|
}
|
|
140
|
-
function
|
|
141
|
-
if (
|
|
142
|
-
|
|
138
|
+
function rejectPredicateCasts(predicate, path) {
|
|
139
|
+
if (predicate.op === "and" || predicate.op === "or" || predicate.op === "not") {
|
|
140
|
+
predicate.args.forEach(
|
|
141
|
+
(child, index) => rejectPredicateCasts(child, path + ".args[" + index + "]")
|
|
142
|
+
);
|
|
143
|
+
} else if (Object.hasOwn(predicate.args[0], "casts")) {
|
|
144
|
+
throw new Error("SQL predicate " + path + ".args[0] requires a non-empty property reference");
|
|
143
145
|
}
|
|
144
|
-
state.nodes++;
|
|
145
|
-
if (state.nodes > MAXIMUM_PREDICATE_NODES) {
|
|
146
|
-
throw new Error("SQL predicate exceeds the maximum node count");
|
|
147
|
-
}
|
|
148
|
-
if (!isRecord(value) || !hasExactKeys(value, ["op", "args"])) {
|
|
149
|
-
throw new Error(`SQL predicate ${path} must contain only op and args`);
|
|
150
|
-
}
|
|
151
|
-
if (typeof value.op !== "string" || !Array.isArray(value.args)) {
|
|
152
|
-
throw new Error(`SQL predicate ${path} requires string op and array args`);
|
|
153
|
-
}
|
|
154
|
-
switch (value.op) {
|
|
155
|
-
case "and":
|
|
156
|
-
case "or":
|
|
157
|
-
if (value.args.length < 2) {
|
|
158
|
-
throw new Error(`SQL predicate ${path}.${value.op} requires at least two arguments`);
|
|
159
|
-
}
|
|
160
|
-
for (let index = 0; index < value.args.length; index++) {
|
|
161
|
-
validatePredicateNode(value.args[index], `${path}.args[${index}]`, depth + 1, state);
|
|
162
|
-
}
|
|
163
|
-
return;
|
|
164
|
-
case "not":
|
|
165
|
-
if (value.args.length !== 1) {
|
|
166
|
-
throw new Error(`SQL predicate ${path}.not requires exactly one argument`);
|
|
167
|
-
}
|
|
168
|
-
validatePredicateNode(value.args[0], `${path}.args[0]`, depth + 1, state);
|
|
169
|
-
return;
|
|
170
|
-
case "isNull":
|
|
171
|
-
if (value.args.length !== 1) {
|
|
172
|
-
throw new Error(`SQL predicate ${path}.isNull requires exactly one argument`);
|
|
173
|
-
}
|
|
174
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
175
|
-
return;
|
|
176
|
-
case "in":
|
|
177
|
-
if (value.args.length !== 2 || !Array.isArray(value.args[1]) || value.args[1].length === 0) {
|
|
178
|
-
throw new Error(`SQL predicate ${path}.in requires a property and non-empty value list`);
|
|
179
|
-
}
|
|
180
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
181
|
-
value.args[1].forEach(
|
|
182
|
-
(item, index) => validatePredicateValue(item, `${path}.args[1][${index}]`)
|
|
183
|
-
);
|
|
184
|
-
return;
|
|
185
|
-
case "=":
|
|
186
|
-
case "<>":
|
|
187
|
-
case "<":
|
|
188
|
-
case "<=":
|
|
189
|
-
case ">":
|
|
190
|
-
case ">=":
|
|
191
|
-
if (value.args.length !== 2) {
|
|
192
|
-
throw new Error(`SQL predicate ${path}.${value.op} requires exactly two arguments`);
|
|
193
|
-
}
|
|
194
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
195
|
-
validatePredicateValue(value.args[1], `${path}.args[1]`);
|
|
196
|
-
return;
|
|
197
|
-
default:
|
|
198
|
-
throw new Error(`SQL predicate ${path} has unsupported operator ${JSON.stringify(value.op)}`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function validatePredicateProperty(value, path) {
|
|
202
|
-
if (!isRecord(value) || !hasAllowedKeys(value, ["property", "quoted"]) || typeof value.property !== "string" || value.property.length === 0 || value.quoted !== void 0 && typeof value.quoted !== "boolean") {
|
|
203
|
-
throw new Error(`SQL predicate ${path} requires a non-empty property reference`);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
function validatePredicateValue(value, path) {
|
|
207
|
-
if ((0, import_sql_predicate_types.isSQLPredicateParameter)(value)) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
if (typeof value === "boolean" || typeof value === "bigint" || typeof value === "string" || value instanceof Uint8Array) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (value instanceof Date && Number.isFinite(value.getTime())) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
throw new Error(`SQL predicate ${path} contains an unsupported scalar value`);
|
|
220
|
-
}
|
|
221
|
-
function isRecord(value) {
|
|
222
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
223
|
-
}
|
|
224
|
-
function hasExactKeys(value, expectedKeys) {
|
|
225
|
-
const keys = Object.keys(value);
|
|
226
|
-
return keys.length === expectedKeys.length && expectedKeys.every((key) => keys.includes(key));
|
|
227
|
-
}
|
|
228
|
-
function hasAllowedKeys(value, allowedKeys) {
|
|
229
|
-
return Object.keys(value).every((key) => allowedKeys.includes(key));
|
|
230
146
|
}
|
|
231
147
|
// Annotate the CommonJS export names for ESM import in node:
|
|
232
148
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/scan/sql-predicate-schema.ts"],
|
|
4
|
-
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {\n validateSQLPredicate as validateMathSQLPredicate,\n type SQLPredicate as MathSQLPredicate\n} from '@math.gl/sql/parser';\nimport type {SQLPredicate} from './sql-predicate-types';\n\n/**\n * JSON Schema for the JSON-serializable portion of the loaders.gl SQL predicate AST.\n *\n * In-process predicates additionally accept `bigint`, `Date`, and `Uint8Array` values, which JSON\n * Schema cannot represent directly.\n */\nexport const SQL_PREDICATE_JSON_SCHEMA = {\n $schema: 'https://json-schema.org/draft/2020-12/schema',\n $id: 'https://loaders.gl/schemas/sql-predicate.schema.json',\n title: 'loaders.gl SQL predicate',\n oneOf: [\n {$ref: '#/$defs/comparison'},\n {$ref: '#/$defs/in'},\n {$ref: '#/$defs/isNull'},\n {$ref: '#/$defs/logical'},\n {$ref: '#/$defs/not'}\n ],\n $defs: {\n property: {\n type: 'object',\n required: ['property'],\n properties: {\n property: {type: 'string', minLength: 1},\n quoted: {type: 'boolean'}\n },\n additionalProperties: false\n },\n value: {\n oneOf: [\n {type: ['boolean', 'number', 'string']},\n {\n type: 'object',\n required: ['parameter'],\n properties: {parameter: {type: 'string', minLength: 1}},\n additionalProperties: false\n }\n ]\n },\n comparison: {\n type: 'object',\n required: ['op', 'args'],\n properties: {\n op: {enum: ['=', '<>', '<', '<=', '>', '>=']},\n args: {\n type: 'array',\n prefixItems: [{$ref: '#/$defs/property'}, {$ref: '#/$defs/value'}],\n minItems: 2,\n maxItems: 2\n }\n },\n additionalProperties: false\n },\n in: {\n type: 'object',\n required: ['op', 'args'],\n properties: {\n op: {const: 'in'},\n args: {\n type: 'array',\n prefixItems: [\n {$ref: '#/$defs/property'},\n {type: 'array', items: {$ref: '#/$defs/value'}, minItems: 1}\n ],\n minItems: 2,\n maxItems: 2\n }\n },\n additionalProperties: false\n },\n isNull: {\n type: 'object',\n required: ['op', 'args'],\n properties: {\n op: {const: 'isNull'},\n args: {\n type: 'array',\n prefixItems: [{$ref: '#/$defs/property'}],\n minItems: 1,\n maxItems: 1\n }\n },\n additionalProperties: false\n },\n logical: {\n type: 'object',\n required: ['op', 'args'],\n properties: {\n op: {enum: ['and', 'or']},\n args: {type: 'array', items: {$ref: '#'}, minItems: 2}\n },\n additionalProperties: false\n },\n not: {\n type: 'object',\n required: ['op', 'args'],\n properties: {\n op: {const: 'not'},\n args: {type: 'array', prefixItems: [{$ref: '#'}], minItems: 1, maxItems: 1}\n },\n additionalProperties: false\n }\n }\n} as const;\n\n/** Returns whether an unknown value is a valid portable SQL predicate. */\nexport function isSQLPredicate(value: unknown): value is SQLPredicate {\n try {\n validateSQLPredicate(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Validates an unknown portable SQL predicate or throws a path-specific error. */\nexport function validateSQLPredicate(value: unknown): asserts value is SQLPredicate {\n validateMathSQLPredicate(value);\n rejectPredicateCasts(value, '$');\n}\n\n/** Rejects casts after math.gl has validated the structure and bounded its depth. */\nfunction rejectPredicateCasts(predicate: MathSQLPredicate, path: string): void {\n if (predicate.op === 'and' || predicate.op === 'or' || predicate.op === 'not') {\n predicate.args.forEach((child, index) =>\n rejectPredicateCasts(child, path + '.args[' + index + ']')\n );\n } else if (Object.hasOwn(predicate.args[0], 'casts')) {\n throw new Error('SQL predicate ' + path + '.args[0] requires a non-empty property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,eAAe,OAAuC;AACpE,MAAI;AACF,yBAAqB,KAAK;AAC1B,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,qBAAqB,OAA+C;AAClF,oBAAAA,sBAAyB,KAAK;AAC9B,uBAAqB,OAAO,GAAG;AACjC;AAGA,SAAS,qBAAqB,WAA6B,MAAoB;AAC7E,MAAI,UAAU,OAAO,SAAS,UAAU,OAAO,QAAQ,UAAU,OAAO,OAAO;AAC7E,cAAU,KAAK;AAAA,MAAQ,CAAC,OAAO,UAC7B,qBAAqB,OAAO,OAAO,WAAW,QAAQ,GAAG;AAAA,IAC3D;AAAA,EACF,WAAW,OAAO,OAAO,UAAU,KAAK,CAAC,GAAG,OAAO,GAAG;AACpD,UAAM,IAAI,MAAM,mBAAmB,OAAO,kDAAkD;AAAA,EAC9F;AACF;",
|
|
6
|
+
"names": ["validateMathSQLPredicate"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-predicate-schema.d.ts","sourceRoot":"","sources":["../../src/scan/sql-predicate-schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sql-predicate-schema.d.ts","sourceRoot":"","sources":["../../src/scan/sql-predicate-schema.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,YAAY,EAAC,iCAA8B;AAExD;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgG5B,CAAC;AAEX,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAOpE;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAGlF"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// loaders.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import {
|
|
5
|
-
const MAXIMUM_PREDICATE_DEPTH = 64;
|
|
6
|
-
const MAXIMUM_PREDICATE_NODES = 4096;
|
|
4
|
+
import { validateSQLPredicate as validateMathSQLPredicate } from '@math.gl/sql/parser';
|
|
7
5
|
/**
|
|
8
6
|
* JSON Schema for the JSON-serializable portion of the loaders.gl SQL predicate AST.
|
|
9
7
|
*
|
|
@@ -119,108 +117,16 @@ export function isSQLPredicate(value) {
|
|
|
119
117
|
}
|
|
120
118
|
/** Validates an unknown portable SQL predicate or throws a path-specific error. */
|
|
121
119
|
export function validateSQLPredicate(value) {
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
validateMathSQLPredicate(value);
|
|
121
|
+
rejectPredicateCasts(value, '$');
|
|
124
122
|
}
|
|
125
|
-
/**
|
|
126
|
-
function
|
|
127
|
-
if (
|
|
128
|
-
|
|
123
|
+
/** Rejects casts after math.gl has validated the structure and bounded its depth. */
|
|
124
|
+
function rejectPredicateCasts(predicate, path) {
|
|
125
|
+
if (predicate.op === 'and' || predicate.op === 'or' || predicate.op === 'not') {
|
|
126
|
+
predicate.args.forEach((child, index) => rejectPredicateCasts(child, path + '.args[' + index + ']'));
|
|
129
127
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
throw new Error('SQL predicate exceeds the maximum node count');
|
|
128
|
+
else if (Object.hasOwn(predicate.args[0], 'casts')) {
|
|
129
|
+
throw new Error('SQL predicate ' + path + '.args[0] requires a non-empty property reference');
|
|
133
130
|
}
|
|
134
|
-
if (!isRecord(value) || !hasExactKeys(value, ['op', 'args'])) {
|
|
135
|
-
throw new Error(`SQL predicate ${path} must contain only op and args`);
|
|
136
|
-
}
|
|
137
|
-
if (typeof value.op !== 'string' || !Array.isArray(value.args)) {
|
|
138
|
-
throw new Error(`SQL predicate ${path} requires string op and array args`);
|
|
139
|
-
}
|
|
140
|
-
switch (value.op) {
|
|
141
|
-
case 'and':
|
|
142
|
-
case 'or':
|
|
143
|
-
if (value.args.length < 2) {
|
|
144
|
-
throw new Error(`SQL predicate ${path}.${value.op} requires at least two arguments`);
|
|
145
|
-
}
|
|
146
|
-
for (let index = 0; index < value.args.length; index++) {
|
|
147
|
-
validatePredicateNode(value.args[index], `${path}.args[${index}]`, depth + 1, state);
|
|
148
|
-
}
|
|
149
|
-
return;
|
|
150
|
-
case 'not':
|
|
151
|
-
if (value.args.length !== 1) {
|
|
152
|
-
throw new Error(`SQL predicate ${path}.not requires exactly one argument`);
|
|
153
|
-
}
|
|
154
|
-
validatePredicateNode(value.args[0], `${path}.args[0]`, depth + 1, state);
|
|
155
|
-
return;
|
|
156
|
-
case 'isNull':
|
|
157
|
-
if (value.args.length !== 1) {
|
|
158
|
-
throw new Error(`SQL predicate ${path}.isNull requires exactly one argument`);
|
|
159
|
-
}
|
|
160
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
161
|
-
return;
|
|
162
|
-
case 'in':
|
|
163
|
-
if (value.args.length !== 2 || !Array.isArray(value.args[1]) || value.args[1].length === 0) {
|
|
164
|
-
throw new Error(`SQL predicate ${path}.in requires a property and non-empty value list`);
|
|
165
|
-
}
|
|
166
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
167
|
-
value.args[1].forEach((item, index) => validatePredicateValue(item, `${path}.args[1][${index}]`));
|
|
168
|
-
return;
|
|
169
|
-
case '=':
|
|
170
|
-
case '<>':
|
|
171
|
-
case '<':
|
|
172
|
-
case '<=':
|
|
173
|
-
case '>':
|
|
174
|
-
case '>=':
|
|
175
|
-
if (value.args.length !== 2) {
|
|
176
|
-
throw new Error(`SQL predicate ${path}.${value.op} requires exactly two arguments`);
|
|
177
|
-
}
|
|
178
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
179
|
-
validatePredicateValue(value.args[1], `${path}.args[1]`);
|
|
180
|
-
return;
|
|
181
|
-
default:
|
|
182
|
-
throw new Error(`SQL predicate ${path} has unsupported operator ${JSON.stringify(value.op)}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/** Validates one property reference. */
|
|
186
|
-
function validatePredicateProperty(value, path) {
|
|
187
|
-
if (!isRecord(value) ||
|
|
188
|
-
!hasAllowedKeys(value, ['property', 'quoted']) ||
|
|
189
|
-
typeof value.property !== 'string' ||
|
|
190
|
-
value.property.length === 0 ||
|
|
191
|
-
(value.quoted !== undefined && typeof value.quoted !== 'boolean')) {
|
|
192
|
-
throw new Error(`SQL predicate ${path} requires a non-empty property reference`);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
/** Validates one structured-cloneable predicate scalar. */
|
|
196
|
-
function validatePredicateValue(value, path) {
|
|
197
|
-
if (isSQLPredicateParameter(value)) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
if (typeof value === 'boolean' ||
|
|
201
|
-
typeof value === 'bigint' ||
|
|
202
|
-
typeof value === 'string' ||
|
|
203
|
-
value instanceof Uint8Array) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
if (value instanceof Date && Number.isFinite(value.getTime())) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
throw new Error(`SQL predicate ${path} contains an unsupported scalar value`);
|
|
213
|
-
}
|
|
214
|
-
/** Returns whether an unknown value is a non-null object. */
|
|
215
|
-
function isRecord(value) {
|
|
216
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
217
|
-
}
|
|
218
|
-
/** Returns whether an object contains exactly the expected enumerable keys. */
|
|
219
|
-
function hasExactKeys(value, expectedKeys) {
|
|
220
|
-
const keys = Object.keys(value);
|
|
221
|
-
return keys.length === expectedKeys.length && expectedKeys.every(key => keys.includes(key));
|
|
222
|
-
}
|
|
223
|
-
function hasAllowedKeys(value, allowedKeys) {
|
|
224
|
-
return Object.keys(value).every(key => allowedKeys.includes(key));
|
|
225
131
|
}
|
|
226
132
|
//# sourceMappingURL=sql-predicate-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-predicate-schema.js","sourceRoot":"","sources":["../../src/scan/sql-predicate-schema.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"sql-predicate-schema.js","sourceRoot":"","sources":["../../src/scan/sql-predicate-schema.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,oBAAoB,IAAI,wBAAwB,EAEjD,MAAM,qBAAqB,CAAC;AAG7B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,OAAO,EAAE,8CAA8C;IACvD,GAAG,EAAE,sDAAsD;IAC3D,KAAK,EAAE,0BAA0B;IACjC,KAAK,EAAE;QACL,EAAC,IAAI,EAAE,oBAAoB,EAAC;QAC5B,EAAC,IAAI,EAAE,YAAY,EAAC;QACpB,EAAC,IAAI,EAAE,gBAAgB,EAAC;QACxB,EAAC,IAAI,EAAE,iBAAiB,EAAC;QACzB,EAAC,IAAI,EAAE,aAAa,EAAC;KACtB;IACD,KAAK,EAAE;QACL,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,UAAU,CAAC;YACtB,UAAU,EAAE;gBACV,QAAQ,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAC;gBACxC,MAAM,EAAE,EAAC,IAAI,EAAE,SAAS,EAAC;aAC1B;YACD,oBAAoB,EAAE,KAAK;SAC5B;QACD,KAAK,EAAE;YACL,KAAK,EAAE;gBACL,EAAC,IAAI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AC;IACf,CAAC;AACH,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAChC,oBAAoB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,qFAAqF;AACrF,SAAS,oBAAoB,CAAC,SAA2B,EAAE,IAAY;IACrE,IAAI,SAAS,CAAC,EAAE,KAAK,KAAK,IAAI,SAAS,CAAC,EAAE,KAAK,IAAI,IAAI,SAAS,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QAC9E,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CACtC,oBAAoB,CAAC,KAAK,EAAE,IAAI,GAAG,QAAQ,GAAG,KAAK,GAAG,GAAG,CAAC,CAC3D,CAAC;IACJ,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,gBAAgB,GAAG,IAAI,GAAG,kDAAkD,CAAC,CAAC;IAChG,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/scan/sql-predicate-zod.ts"],
|
|
4
|
-
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {z} from 'zod';\n\nimport type {SQLPredicate, SQLPredicateValue} from './sql-predicate-types';\n\n/** Zod schema for scalar values accepted by in-process SQL predicates. */\nexport const SQLPredicateValueSchema: z.ZodType<SQLPredicateValue> = z.union([\n z.boolean(),\n z.number().finite(),\n z.bigint(),\n z.string(),\n z.date(),\n z.instanceof(Uint8Array),\n z.object({parameter: z.string().min(1)}).strict()\n]);\n\nconst SQLPredicatePropertySchema = z\n .object({property: z.string().min(1), quoted: z.boolean().optional()})\n .strict();\n\n/**\n * Optional Zod schema for validating the portable loaders.gl SQL predicate AST.\n *\n * Import from `@loaders.gl/core/
|
|
4
|
+
"sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {z} from 'zod';\n\nimport type {SQLPredicate, SQLPredicateValue} from './sql-predicate-types';\n\n/** Zod schema for scalar values accepted by in-process SQL predicates. */\nexport const SQLPredicateValueSchema: z.ZodType<SQLPredicateValue> = z.union([\n z.boolean(),\n z.number().finite(),\n z.bigint(),\n z.string(),\n z.date(),\n z.instanceof(Uint8Array),\n z.object({parameter: z.string().min(1)}).strict()\n]);\n\nconst SQLPredicatePropertySchema = z\n .object({property: z.string().min(1), quoted: z.boolean().optional()})\n .strict();\n\n/**\n * Optional Zod schema for validating the portable loaders.gl SQL predicate AST.\n *\n * Import from `@loaders.gl/core/query/sql-predicate-zod`; the package root does not load Zod.\n */\nexport const SQLPredicateSchema: z.ZodType<SQLPredicate> = z.lazy(() =>\n z.union([\n z\n .object({\n op: z.enum(['=', '<>', '<', '<=', '>', '>=']),\n args: z.tuple([SQLPredicatePropertySchema, SQLPredicateValueSchema])\n })\n .strict(),\n z\n .object({\n op: z.literal('in'),\n args: z.tuple([SQLPredicatePropertySchema, z.array(SQLPredicateValueSchema).min(1)])\n })\n .strict(),\n z.object({op: z.literal('isNull'), args: z.tuple([SQLPredicatePropertySchema])}).strict(),\n z\n .object({\n op: z.enum(['and', 'or']),\n args: z.array(SQLPredicateSchema).min(2)\n })\n .strict(),\n z.object({op: z.literal('not'), args: z.tuple([SQLPredicateSchema])}).strict()\n ])\n);\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,iBAAgB;AAKT,IAAM,0BAAwD,aAAE,MAAM;AAAA,EAC3E,aAAE,QAAQ;AAAA,EACV,aAAE,OAAO,EAAE,OAAO;AAAA,EAClB,aAAE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 @@ export declare const SQLPredicateValueSchema: z.ZodType<SQLPredicateValue>;
|
|
|
5
5
|
/**
|
|
6
6
|
* Optional Zod schema for validating the portable loaders.gl SQL predicate AST.
|
|
7
7
|
*
|
|
8
|
-
* Import from `@loaders.gl/core/
|
|
8
|
+
* Import from `@loaders.gl/core/query/sql-predicate-zod`; the package root does not load Zod.
|
|
9
9
|
*/
|
|
10
10
|
export declare const SQLPredicateSchema: z.ZodType<SQLPredicate>;
|
|
11
11
|
//# sourceMappingURL=sql-predicate-zod.d.ts.map
|
|
@@ -18,7 +18,7 @@ const SQLPredicatePropertySchema = z
|
|
|
18
18
|
/**
|
|
19
19
|
* Optional Zod schema for validating the portable loaders.gl SQL predicate AST.
|
|
20
20
|
*
|
|
21
|
-
* Import from `@loaders.gl/core/
|
|
21
|
+
* Import from `@loaders.gl/core/query/sql-predicate-zod`; the package root does not load Zod.
|
|
22
22
|
*/
|
|
23
23
|
export const SQLPredicateSchema = z.lazy(() => z.union([
|
|
24
24
|
z
|
|
@@ -1032,106 +1032,18 @@ function convertRowsToArrowTable(rows) {
|
|
|
1032
1032
|
return arrow5.tableFromJSON(rows);
|
|
1033
1033
|
}
|
|
1034
1034
|
|
|
1035
|
-
// dist/scan/sql-predicate-types.js
|
|
1036
|
-
function isSQLPredicateParameter(value) {
|
|
1037
|
-
return isColumnarPredicateParameter(value);
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
1035
|
// dist/scan/sql-predicate-schema.js
|
|
1041
|
-
var
|
|
1042
|
-
var MAXIMUM_PREDICATE_NODES = 4096;
|
|
1036
|
+
var import_parser = require("@math.gl/sql/parser");
|
|
1043
1037
|
function validateSQLPredicate(value) {
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
}
|
|
1047
|
-
function validatePredicateNode(value, path, depth, state) {
|
|
1048
|
-
if (depth > MAXIMUM_PREDICATE_DEPTH) {
|
|
1049
|
-
throw new Error(`SQL predicate ${path} exceeds the maximum nesting depth`);
|
|
1050
|
-
}
|
|
1051
|
-
state.nodes++;
|
|
1052
|
-
if (state.nodes > MAXIMUM_PREDICATE_NODES) {
|
|
1053
|
-
throw new Error("SQL predicate exceeds the maximum node count");
|
|
1054
|
-
}
|
|
1055
|
-
if (!isRecord(value) || !hasExactKeys(value, ["op", "args"])) {
|
|
1056
|
-
throw new Error(`SQL predicate ${path} must contain only op and args`);
|
|
1057
|
-
}
|
|
1058
|
-
if (typeof value.op !== "string" || !Array.isArray(value.args)) {
|
|
1059
|
-
throw new Error(`SQL predicate ${path} requires string op and array args`);
|
|
1060
|
-
}
|
|
1061
|
-
switch (value.op) {
|
|
1062
|
-
case "and":
|
|
1063
|
-
case "or":
|
|
1064
|
-
if (value.args.length < 2) {
|
|
1065
|
-
throw new Error(`SQL predicate ${path}.${value.op} requires at least two arguments`);
|
|
1066
|
-
}
|
|
1067
|
-
for (let index = 0; index < value.args.length; index++) {
|
|
1068
|
-
validatePredicateNode(value.args[index], `${path}.args[${index}]`, depth + 1, state);
|
|
1069
|
-
}
|
|
1070
|
-
return;
|
|
1071
|
-
case "not":
|
|
1072
|
-
if (value.args.length !== 1) {
|
|
1073
|
-
throw new Error(`SQL predicate ${path}.not requires exactly one argument`);
|
|
1074
|
-
}
|
|
1075
|
-
validatePredicateNode(value.args[0], `${path}.args[0]`, depth + 1, state);
|
|
1076
|
-
return;
|
|
1077
|
-
case "isNull":
|
|
1078
|
-
if (value.args.length !== 1) {
|
|
1079
|
-
throw new Error(`SQL predicate ${path}.isNull requires exactly one argument`);
|
|
1080
|
-
}
|
|
1081
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
1082
|
-
return;
|
|
1083
|
-
case "in":
|
|
1084
|
-
if (value.args.length !== 2 || !Array.isArray(value.args[1]) || value.args[1].length === 0) {
|
|
1085
|
-
throw new Error(`SQL predicate ${path}.in requires a property and non-empty value list`);
|
|
1086
|
-
}
|
|
1087
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
1088
|
-
value.args[1].forEach((item, index) => validatePredicateValue(item, `${path}.args[1][${index}]`));
|
|
1089
|
-
return;
|
|
1090
|
-
case "=":
|
|
1091
|
-
case "<>":
|
|
1092
|
-
case "<":
|
|
1093
|
-
case "<=":
|
|
1094
|
-
case ">":
|
|
1095
|
-
case ">=":
|
|
1096
|
-
if (value.args.length !== 2) {
|
|
1097
|
-
throw new Error(`SQL predicate ${path}.${value.op} requires exactly two arguments`);
|
|
1098
|
-
}
|
|
1099
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
1100
|
-
validatePredicateValue(value.args[1], `${path}.args[1]`);
|
|
1101
|
-
return;
|
|
1102
|
-
default:
|
|
1103
|
-
throw new Error(`SQL predicate ${path} has unsupported operator ${JSON.stringify(value.op)}`);
|
|
1104
|
-
}
|
|
1038
|
+
(0, import_parser.validateSQLPredicate)(value);
|
|
1039
|
+
rejectPredicateCasts(value, "$");
|
|
1105
1040
|
}
|
|
1106
|
-
function
|
|
1107
|
-
if (
|
|
1108
|
-
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
function validatePredicateValue(value, path) {
|
|
1112
|
-
if (isSQLPredicateParameter(value)) {
|
|
1113
|
-
return;
|
|
1041
|
+
function rejectPredicateCasts(predicate, path) {
|
|
1042
|
+
if (predicate.op === "and" || predicate.op === "or" || predicate.op === "not") {
|
|
1043
|
+
predicate.args.forEach((child, index) => rejectPredicateCasts(child, path + ".args[" + index + "]"));
|
|
1044
|
+
} else if (Object.hasOwn(predicate.args[0], "casts")) {
|
|
1045
|
+
throw new Error("SQL predicate " + path + ".args[0] requires a non-empty property reference");
|
|
1114
1046
|
}
|
|
1115
|
-
if (typeof value === "boolean" || typeof value === "bigint" || typeof value === "string" || value instanceof Uint8Array) {
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
if (value instanceof Date && Number.isFinite(value.getTime())) {
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1124
|
-
throw new Error(`SQL predicate ${path} contains an unsupported scalar value`);
|
|
1125
|
-
}
|
|
1126
|
-
function isRecord(value) {
|
|
1127
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1128
|
-
}
|
|
1129
|
-
function hasExactKeys(value, expectedKeys) {
|
|
1130
|
-
const keys = Object.keys(value);
|
|
1131
|
-
return keys.length === expectedKeys.length && expectedKeys.every((key) => keys.includes(key));
|
|
1132
|
-
}
|
|
1133
|
-
function hasAllowedKeys(value, allowedKeys) {
|
|
1134
|
-
return Object.keys(value).every((key) => allowedKeys.includes(key));
|
|
1135
1047
|
}
|
|
1136
1048
|
|
|
1137
1049
|
// dist/scan/table-query.js
|