@truto/sqlite-builder 1.0.4 → 2.0.2-canary.0
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/index.js +1 -0
- package/package.json +1 -88
- package/LICENSE +0 -21
- package/README.md +0 -893
- package/dist/constants.d.ts +0 -8
- package/dist/constants.d.ts.map +0 -1
- package/dist/filter.d.ts +0 -6
- package/dist/filter.d.ts.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -425
- package/dist/index.js.map +0 -12
- package/dist/sql.d.ts +0 -40
- package/dist/sql.d.ts.map +0 -1
- package/dist/types.d.ts +0 -74
- package/dist/types.d.ts.map +0 -1
package/dist/constants.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common regex patterns used across the codebase
|
|
3
|
-
*/
|
|
4
|
-
export declare const MAX_QUERY_LENGTH = 102400;
|
|
5
|
-
export declare const STACKED_QUERY_REGEX: RegExp;
|
|
6
|
-
export declare const QUALIFIED_IDENTIFIER_REGEX: RegExp;
|
|
7
|
-
export declare const SIMPLE_IDENTIFIER_REGEX: RegExp;
|
|
8
|
-
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,eAAO,MAAM,gBAAgB,SAAS,CAAA;AAGtC,eAAO,MAAM,mBAAmB,QAAe,CAAA;AAG/C,eAAO,MAAM,0BAA0B,QACgB,CAAA;AAGvD,eAAO,MAAM,uBAAuB,QAA6B,CAAA"}
|
package/dist/filter.d.ts
DELETED
package/dist/filter.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,YAAY,EACZ,UAAU,EACX,MAAM,SAAS,CAAA;AA8XhB;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,CAa9D"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* truto-sqlite-builder - Safe, zero-dependency template-literal tag for SQLite queries
|
|
3
|
-
*/
|
|
4
|
-
export { compileFilter } from './filter';
|
|
5
|
-
export { sql } from './sql';
|
|
6
|
-
export type { FilterResult, JsonFilter, SqlQuery } from './types';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/index.js
DELETED
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
// src/constants.ts
|
|
2
|
-
var MAX_QUERY_LENGTH = 102400;
|
|
3
|
-
var STACKED_QUERY_REGEX = /;[\s\S]*\S/;
|
|
4
|
-
var QUALIFIED_IDENTIFIER_REGEX = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/;
|
|
5
|
-
var SIMPLE_IDENTIFIER_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
6
|
-
|
|
7
|
-
// src/sql.ts
|
|
8
|
-
function formatDate(date) {
|
|
9
|
-
const year = date.getFullYear();
|
|
10
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
11
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
12
|
-
const hours = String(date.getHours()).padStart(2, "0");
|
|
13
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
14
|
-
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
15
|
-
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
16
|
-
}
|
|
17
|
-
function sqlValue(value) {
|
|
18
|
-
if (value === null || value === undefined) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
if (typeof value === "string") {
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
25
|
-
return value;
|
|
26
|
-
}
|
|
27
|
-
if (value instanceof Date) {
|
|
28
|
-
return formatDate(value);
|
|
29
|
-
}
|
|
30
|
-
if (value instanceof Buffer || value instanceof Uint8Array) {
|
|
31
|
-
throw new TypeError("Buffer/Uint8Array values must be used with sql.blob() for safe BLOB handling");
|
|
32
|
-
}
|
|
33
|
-
throw new TypeError(`Unsupported value type: ${typeof value}`);
|
|
34
|
-
}
|
|
35
|
-
function quoteSingleIdentifier(identifier) {
|
|
36
|
-
if (!SIMPLE_IDENTIFIER_REGEX.test(identifier)) {
|
|
37
|
-
throw new TypeError(`Invalid identifier part: ${identifier}. Must be a valid ANSI identifier.`);
|
|
38
|
-
}
|
|
39
|
-
return `"${identifier}"`;
|
|
40
|
-
}
|
|
41
|
-
function quoteQualifiedIdentifier(identifier) {
|
|
42
|
-
if (!QUALIFIED_IDENTIFIER_REGEX.test(identifier)) {
|
|
43
|
-
throw new TypeError(`Invalid identifier: ${identifier}. Must be a valid identifier or qualified identifier (e.g., table.column)`);
|
|
44
|
-
}
|
|
45
|
-
const parts = identifier.split(".");
|
|
46
|
-
return parts.map(quoteSingleIdentifier).join(".");
|
|
47
|
-
}
|
|
48
|
-
function sqlIdent(identifier) {
|
|
49
|
-
if (Array.isArray(identifier)) {
|
|
50
|
-
if (identifier.length === 0) {
|
|
51
|
-
throw new TypeError("Identifier array cannot be empty");
|
|
52
|
-
}
|
|
53
|
-
const fragments = [];
|
|
54
|
-
for (const item of identifier) {
|
|
55
|
-
if (item && typeof item === "object" && "text" in item && "values" in item && typeof item.text === "string" && Array.isArray(item.values)) {
|
|
56
|
-
fragments.push(item);
|
|
57
|
-
} else if (typeof item === "string") {
|
|
58
|
-
if (!item) {
|
|
59
|
-
throw new TypeError("All identifiers must be non-empty strings");
|
|
60
|
-
}
|
|
61
|
-
if (!QUALIFIED_IDENTIFIER_REGEX.test(item)) {
|
|
62
|
-
throw new TypeError(`Invalid identifier: ${item}. Must be a valid identifier or qualified identifier (e.g., table.column)`);
|
|
63
|
-
}
|
|
64
|
-
fragments.push({
|
|
65
|
-
text: quoteQualifiedIdentifier(item),
|
|
66
|
-
values: []
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
throw new TypeError("Array items must be strings or SQL fragments");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const text = fragments.map((f) => f.text).join(", ");
|
|
73
|
-
const values = fragments.flatMap((f) => [...f.values]);
|
|
74
|
-
return {
|
|
75
|
-
text,
|
|
76
|
-
values
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
if (!identifier || typeof identifier !== "string") {
|
|
80
|
-
throw new TypeError("Identifier must be a non-empty string");
|
|
81
|
-
}
|
|
82
|
-
if (!QUALIFIED_IDENTIFIER_REGEX.test(identifier)) {
|
|
83
|
-
throw new TypeError(`Invalid identifier: ${identifier}. Must be a valid identifier or qualified identifier (e.g., table.column)`);
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
text: quoteQualifiedIdentifier(identifier),
|
|
87
|
-
values: []
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function sqlIn(array) {
|
|
91
|
-
if (!Array.isArray(array)) {
|
|
92
|
-
throw new TypeError("sql.in() requires an array");
|
|
93
|
-
}
|
|
94
|
-
if (array.length === 0) {
|
|
95
|
-
throw new TypeError("sql.in() cannot be used with empty arrays");
|
|
96
|
-
}
|
|
97
|
-
if (array.length > 1000) {
|
|
98
|
-
console.warn(`sql.in(): Large array with ${array.length} items. Consider using temporary tables for better performance.`);
|
|
99
|
-
}
|
|
100
|
-
const placeholders = array.map(() => "?").join(",");
|
|
101
|
-
const values = array.map(sqlValue);
|
|
102
|
-
return {
|
|
103
|
-
text: `(${placeholders})`,
|
|
104
|
-
values
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function sqlRaw(rawSql) {
|
|
108
|
-
if (typeof rawSql !== "string") {
|
|
109
|
-
throw new TypeError("sql.raw() requires a string");
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
text: rawSql,
|
|
113
|
-
values: []
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function sqlBlob(data) {
|
|
117
|
-
if (!(data instanceof Buffer) && !(data instanceof Uint8Array)) {
|
|
118
|
-
throw new TypeError("sql.blob() requires a Buffer or Uint8Array");
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
text: "?",
|
|
122
|
-
values: [data]
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function sqlJoin(fragments, separator = ", ") {
|
|
126
|
-
if (!Array.isArray(fragments)) {
|
|
127
|
-
throw new TypeError("sql.join() requires an array of fragments");
|
|
128
|
-
}
|
|
129
|
-
if (fragments.length === 0) {
|
|
130
|
-
return { text: "", values: [] };
|
|
131
|
-
}
|
|
132
|
-
const text = fragments.map((f) => f.text).join(separator);
|
|
133
|
-
const values = fragments.flatMap((f) => [...f.values]);
|
|
134
|
-
return { text, values };
|
|
135
|
-
}
|
|
136
|
-
function sql(strings, ...values) {
|
|
137
|
-
let text = strings[0] || "";
|
|
138
|
-
const queryValues = [];
|
|
139
|
-
for (let i = 0;i < values.length; i++) {
|
|
140
|
-
const value = values[i];
|
|
141
|
-
if (value && typeof value === "object" && "text" in value && "values" in value && typeof value.text === "string" && Array.isArray(value.values)) {
|
|
142
|
-
const fragment = value;
|
|
143
|
-
text += fragment.text;
|
|
144
|
-
queryValues.push(...fragment.values);
|
|
145
|
-
} else {
|
|
146
|
-
text += "?";
|
|
147
|
-
queryValues.push(sqlValue(value));
|
|
148
|
-
}
|
|
149
|
-
text += strings[i + 1] || "";
|
|
150
|
-
}
|
|
151
|
-
if (text.length > MAX_QUERY_LENGTH) {
|
|
152
|
-
throw new Error(`Query too long: ${text.length} bytes (max: ${MAX_QUERY_LENGTH})`);
|
|
153
|
-
}
|
|
154
|
-
if (STACKED_QUERY_REGEX.test(text)) {
|
|
155
|
-
throw new Error("Stacked queries are not allowed");
|
|
156
|
-
}
|
|
157
|
-
return Object.freeze({
|
|
158
|
-
text,
|
|
159
|
-
values: Object.freeze([...queryValues])
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
sql.value = sqlValue;
|
|
163
|
-
sql.ident = sqlIdent;
|
|
164
|
-
sql.in = sqlIn;
|
|
165
|
-
sql.raw = sqlRaw;
|
|
166
|
-
sql.blob = sqlBlob;
|
|
167
|
-
sql.join = sqlJoin;
|
|
168
|
-
|
|
169
|
-
// src/filter.ts
|
|
170
|
-
var MAX_NESTING_DEPTH = 10;
|
|
171
|
-
var MAX_OPERATORS = 100;
|
|
172
|
-
var VALID_OPERATORS = new Set([
|
|
173
|
-
"gt",
|
|
174
|
-
"gte",
|
|
175
|
-
"lt",
|
|
176
|
-
"lte",
|
|
177
|
-
"ne",
|
|
178
|
-
"in",
|
|
179
|
-
"nin",
|
|
180
|
-
"like",
|
|
181
|
-
"ilike",
|
|
182
|
-
"regex",
|
|
183
|
-
"exists",
|
|
184
|
-
"and",
|
|
185
|
-
"or"
|
|
186
|
-
]);
|
|
187
|
-
function isJsonPath(field) {
|
|
188
|
-
return field.includes(".");
|
|
189
|
-
}
|
|
190
|
-
function compileJsonPath(field) {
|
|
191
|
-
const parts = field.split(".");
|
|
192
|
-
const columnName = parts[0];
|
|
193
|
-
const jsonPath = parts.slice(1);
|
|
194
|
-
if (!columnName || jsonPath.length === 0 || jsonPath.some((part) => !part)) {
|
|
195
|
-
throw new SyntaxError(`Invalid JSON path: ${field}`);
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
columnName,
|
|
199
|
-
jsonPath: "$." + jsonPath.join(".")
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function isValidSqlIdentifier(identifier) {
|
|
203
|
-
return SIMPLE_IDENTIFIER_REGEX.test(identifier);
|
|
204
|
-
}
|
|
205
|
-
function compileFieldCondition(field, condition, context, alias) {
|
|
206
|
-
if (condition === null || condition === undefined || typeof condition === "string" || typeof condition === "number" || typeof condition === "boolean" || condition instanceof Date) {
|
|
207
|
-
context.operatorCount++;
|
|
208
|
-
if (context.operatorCount > MAX_OPERATORS) {
|
|
209
|
-
throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`);
|
|
210
|
-
}
|
|
211
|
-
if (isJsonPath(field)) {
|
|
212
|
-
const { columnName, jsonPath } = compileJsonPath(field);
|
|
213
|
-
const identFragment2 = sql.ident(columnName);
|
|
214
|
-
const fullFieldExpr = alias ? `${alias}.${identFragment2.text}` : identFragment2.text;
|
|
215
|
-
if (condition === null || condition === undefined) {
|
|
216
|
-
context.values.push(jsonPath);
|
|
217
|
-
return `(json_extract(${fullFieldExpr}, ?) IS NULL)`;
|
|
218
|
-
} else {
|
|
219
|
-
context.values.push(jsonPath, sql.value(condition));
|
|
220
|
-
return `(json_extract(${fullFieldExpr}, ?) = ?)`;
|
|
221
|
-
}
|
|
222
|
-
} else {
|
|
223
|
-
const identFragment2 = sql.ident(field);
|
|
224
|
-
const fullFieldExpr = alias ? `${alias}.${identFragment2.text}` : identFragment2.text;
|
|
225
|
-
if (condition === null || condition === undefined) {
|
|
226
|
-
return `(${fullFieldExpr} IS NULL)`;
|
|
227
|
-
} else {
|
|
228
|
-
context.values.push(sql.value(condition));
|
|
229
|
-
return `(${fullFieldExpr} = ?)`;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (typeof condition !== "object" || condition === null) {
|
|
234
|
-
throw new TypeError("Condition must be a value or operator object");
|
|
235
|
-
}
|
|
236
|
-
const operators = condition;
|
|
237
|
-
const clauses = [];
|
|
238
|
-
for (const op of Object.keys(operators)) {
|
|
239
|
-
if (!VALID_OPERATORS.has(op)) {
|
|
240
|
-
throw new SyntaxError(`Unknown operator: ${op}`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const identFragment = sql.ident(isJsonPath(field) ? compileJsonPath(field).columnName : field);
|
|
244
|
-
const baseFieldExpr = alias ? `${alias}.${identFragment.text}` : identFragment.text;
|
|
245
|
-
const fieldExpr = isJsonPath(field) ? `json_extract(${baseFieldExpr}, ?)` : baseFieldExpr;
|
|
246
|
-
if (isJsonPath(field)) {
|
|
247
|
-
context.values.push(compileJsonPath(field).jsonPath);
|
|
248
|
-
}
|
|
249
|
-
if ("exists" in operators) {
|
|
250
|
-
context.operatorCount++;
|
|
251
|
-
if (context.operatorCount > MAX_OPERATORS) {
|
|
252
|
-
throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`);
|
|
253
|
-
}
|
|
254
|
-
return operators.exists ? `(${fieldExpr} IS NOT NULL)` : `(${fieldExpr} IS NULL)`;
|
|
255
|
-
}
|
|
256
|
-
for (const [op, value] of Object.entries(operators)) {
|
|
257
|
-
context.operatorCount++;
|
|
258
|
-
if (context.operatorCount > MAX_OPERATORS) {
|
|
259
|
-
throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`);
|
|
260
|
-
}
|
|
261
|
-
switch (op) {
|
|
262
|
-
case "gt":
|
|
263
|
-
context.values.push(sql.value(value));
|
|
264
|
-
clauses.push(`${fieldExpr} > ?`);
|
|
265
|
-
break;
|
|
266
|
-
case "gte":
|
|
267
|
-
context.values.push(sql.value(value));
|
|
268
|
-
clauses.push(`${fieldExpr} >= ?`);
|
|
269
|
-
break;
|
|
270
|
-
case "lt":
|
|
271
|
-
context.values.push(sql.value(value));
|
|
272
|
-
clauses.push(`${fieldExpr} < ?`);
|
|
273
|
-
break;
|
|
274
|
-
case "lte":
|
|
275
|
-
context.values.push(sql.value(value));
|
|
276
|
-
clauses.push(`${fieldExpr} <= ?`);
|
|
277
|
-
break;
|
|
278
|
-
case "ne":
|
|
279
|
-
if (value === null || value === undefined) {
|
|
280
|
-
clauses.push(`${fieldExpr} IS NOT NULL`);
|
|
281
|
-
} else {
|
|
282
|
-
context.values.push(sql.value(value));
|
|
283
|
-
clauses.push(`${fieldExpr} <> ?`);
|
|
284
|
-
}
|
|
285
|
-
break;
|
|
286
|
-
case "in": {
|
|
287
|
-
if (!Array.isArray(value)) {
|
|
288
|
-
throw new TypeError("IN operator requires an array");
|
|
289
|
-
}
|
|
290
|
-
if (value.length === 0) {
|
|
291
|
-
throw new TypeError("IN operator cannot be used with empty arrays");
|
|
292
|
-
}
|
|
293
|
-
if (value.length > 999) {
|
|
294
|
-
throw new RangeError("IN operator cannot be used with arrays larger than 999 items");
|
|
295
|
-
}
|
|
296
|
-
const inFragment = sql.in(value);
|
|
297
|
-
context.values.push(...inFragment.values);
|
|
298
|
-
clauses.push(`${fieldExpr} IN ${inFragment.text}`);
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
case "nin": {
|
|
302
|
-
if (!Array.isArray(value)) {
|
|
303
|
-
throw new TypeError("NIN operator requires an array");
|
|
304
|
-
}
|
|
305
|
-
if (value.length === 0) {
|
|
306
|
-
throw new TypeError("NIN operator cannot be used with empty arrays");
|
|
307
|
-
}
|
|
308
|
-
if (value.length > 999) {
|
|
309
|
-
throw new RangeError("NIN operator cannot be used with arrays larger than 999 items");
|
|
310
|
-
}
|
|
311
|
-
const ninFragment = sql.in(value);
|
|
312
|
-
context.values.push(...ninFragment.values);
|
|
313
|
-
clauses.push(`${fieldExpr} NOT IN ${ninFragment.text}`);
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
case "like":
|
|
317
|
-
if (typeof value !== "string") {
|
|
318
|
-
throw new TypeError("LIKE operator requires a string pattern");
|
|
319
|
-
}
|
|
320
|
-
context.values.push(value);
|
|
321
|
-
clauses.push(`${fieldExpr} LIKE ?`);
|
|
322
|
-
break;
|
|
323
|
-
case "ilike":
|
|
324
|
-
if (typeof value !== "string") {
|
|
325
|
-
throw new TypeError("ILIKE operator requires a string pattern");
|
|
326
|
-
}
|
|
327
|
-
context.values.push(value);
|
|
328
|
-
clauses.push(`${fieldExpr} LIKE ? COLLATE NOCASE`);
|
|
329
|
-
break;
|
|
330
|
-
case "regex":
|
|
331
|
-
if (typeof value !== "string") {
|
|
332
|
-
throw new TypeError("REGEX operator requires a string pattern");
|
|
333
|
-
}
|
|
334
|
-
context.values.push(value);
|
|
335
|
-
clauses.push(`${fieldExpr} REGEXP ?`);
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (clauses.length === 0) {
|
|
340
|
-
throw new SyntaxError("Operator object must contain at least one valid operator");
|
|
341
|
-
}
|
|
342
|
-
return clauses.length === 1 ? `(${clauses[0]})` : `(${clauses.join(" AND ")})`;
|
|
343
|
-
}
|
|
344
|
-
function compileFilterRecursive(filter, context, alias) {
|
|
345
|
-
if (context.depth >= MAX_NESTING_DEPTH) {
|
|
346
|
-
throw new RangeError(`Nesting depth too deep (max: ${MAX_NESTING_DEPTH})`);
|
|
347
|
-
}
|
|
348
|
-
if (typeof filter !== "object" || filter === null) {
|
|
349
|
-
throw new TypeError("Filter must be an object");
|
|
350
|
-
}
|
|
351
|
-
context.depth++;
|
|
352
|
-
const clauses = [];
|
|
353
|
-
if ("and" in filter && filter.and) {
|
|
354
|
-
context.operatorCount++;
|
|
355
|
-
if (context.operatorCount > MAX_OPERATORS) {
|
|
356
|
-
throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`);
|
|
357
|
-
}
|
|
358
|
-
if (!Array.isArray(filter.and)) {
|
|
359
|
-
throw new TypeError("AND operator must be an array");
|
|
360
|
-
}
|
|
361
|
-
if (filter.and.length === 0) {
|
|
362
|
-
throw new TypeError("AND operator cannot be used with empty arrays");
|
|
363
|
-
}
|
|
364
|
-
const andClauses = filter.and.map((subFilter) => compileFilterRecursive(subFilter, context, alias));
|
|
365
|
-
clauses.push(`(${andClauses.join(" AND ")})`);
|
|
366
|
-
}
|
|
367
|
-
if ("or" in filter && filter.or) {
|
|
368
|
-
context.operatorCount++;
|
|
369
|
-
if (context.operatorCount > MAX_OPERATORS) {
|
|
370
|
-
throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`);
|
|
371
|
-
}
|
|
372
|
-
if (!Array.isArray(filter.or)) {
|
|
373
|
-
throw new TypeError("OR operator must be an array");
|
|
374
|
-
}
|
|
375
|
-
if (filter.or.length === 0) {
|
|
376
|
-
throw new TypeError("OR operator cannot be used with empty arrays");
|
|
377
|
-
}
|
|
378
|
-
const orClauses = filter.or.map((subFilter) => compileFilterRecursive(subFilter, context, alias));
|
|
379
|
-
clauses.push(`(${orClauses.join(" OR ")})`);
|
|
380
|
-
}
|
|
381
|
-
const fieldEntries = Object.entries(filter).filter(([field, condition]) => field !== "and" && field !== "or" && !field.startsWith("$") && condition !== undefined);
|
|
382
|
-
for (const [field, condition] of fieldEntries) {
|
|
383
|
-
if (Array.isArray(condition)) {
|
|
384
|
-
throw new SyntaxError(`Field '${field}' cannot have array value. Use logical operators 'and'/'or' instead.`);
|
|
385
|
-
}
|
|
386
|
-
clauses.push(compileFieldCondition(field, condition, context, alias));
|
|
387
|
-
}
|
|
388
|
-
const aliasEntries = Object.entries(filter).filter(([key, value]) => key.startsWith("$") && value !== undefined && typeof value === "object" && value !== null);
|
|
389
|
-
for (const [aliasKey, aliasFilter] of aliasEntries) {
|
|
390
|
-
const aliasName = aliasKey.slice(1);
|
|
391
|
-
if (!isValidSqlIdentifier(aliasName)) {
|
|
392
|
-
throw new SyntaxError(`Invalid alias identifier: ${aliasName}`);
|
|
393
|
-
}
|
|
394
|
-
const aliasClause = compileFilterRecursive(aliasFilter, context, aliasName);
|
|
395
|
-
clauses.push(aliasClause);
|
|
396
|
-
}
|
|
397
|
-
context.depth--;
|
|
398
|
-
if (clauses.length === 0) {
|
|
399
|
-
throw new SyntaxError("Filter must contain at least one condition");
|
|
400
|
-
}
|
|
401
|
-
if (clauses.length === 1) {
|
|
402
|
-
return clauses[0];
|
|
403
|
-
} else {
|
|
404
|
-
return `(${clauses.join(" AND ")})`;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
function compileFilter(filter) {
|
|
408
|
-
const context = {
|
|
409
|
-
depth: 0,
|
|
410
|
-
operatorCount: 0,
|
|
411
|
-
values: []
|
|
412
|
-
};
|
|
413
|
-
const text = compileFilterRecursive(filter, context);
|
|
414
|
-
return Object.freeze({
|
|
415
|
-
text: `(${text})`,
|
|
416
|
-
values: Object.freeze([...context.values])
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
export {
|
|
420
|
-
sql,
|
|
421
|
-
compileFilter
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
//# debugId=2601C616902F043764756E2164756E21
|
|
425
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/constants.ts", "../src/sql.ts", "../src/filter.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"/**\n * Common regex patterns used across the codebase\n */\n\n// Maximum query length (100KB)\nexport const MAX_QUERY_LENGTH = 102400\n\n// Regex to detect stacked queries (semicolon followed by non-whitespace)\nexport const STACKED_QUERY_REGEX = /;[\\s\\S]*\\S/\n\n// ANSI identifier validation - supports qualified identifiers (e.g., table.column)\nexport const QUALIFIED_IDENTIFIER_REGEX =\n /^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*$/\n\n// Simple identifier validation (for individual parts)\nexport const SIMPLE_IDENTIFIER_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/\n",
|
|
6
|
-
"import {\n MAX_QUERY_LENGTH,\n QUALIFIED_IDENTIFIER_REGEX,\n SIMPLE_IDENTIFIER_REGEX,\n STACKED_QUERY_REGEX,\n} from './constants'\nimport type { SqlFragment, SqlQuery, SqlValue } from './types'\n\n/**\n * Format a date for SQLite (YYYY-MM-DD HH:MM:SS)\n */\nfunction formatDate(date: Date): string {\n const year = date.getFullYear()\n const month = String(date.getMonth() + 1).padStart(2, '0')\n const day = String(date.getDate()).padStart(2, '0')\n const hours = String(date.getHours()).padStart(2, '0')\n const minutes = String(date.getMinutes()).padStart(2, '0')\n const seconds = String(date.getSeconds()).padStart(2, '0')\n\n return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`\n}\n\n/**\n * Convert a value to its SQLite representation\n */\nfunction sqlValue(value: SqlValue): unknown {\n if (value === null || value === undefined) {\n return null\n }\n\n if (typeof value === 'string') {\n return value\n }\n\n if (typeof value === 'number' || typeof value === 'boolean') {\n return value\n }\n\n if (value instanceof Date) {\n return formatDate(value)\n }\n\n if (value instanceof Buffer || value instanceof Uint8Array) {\n throw new TypeError(\n 'Buffer/Uint8Array values must be used with sql.blob() for safe BLOB handling',\n )\n }\n\n throw new TypeError(`Unsupported value type: ${typeof value}`)\n}\n\n/**\n * Quote a single identifier part\n */\nfunction quoteSingleIdentifier(identifier: string): string {\n if (!SIMPLE_IDENTIFIER_REGEX.test(identifier)) {\n throw new TypeError(\n `Invalid identifier part: ${identifier}. Must be a valid ANSI identifier.`,\n )\n }\n return `\"${identifier}\"`\n}\n\n/**\n * Quote a qualified identifier by splitting on dots and quoting each part\n */\nfunction quoteQualifiedIdentifier(identifier: string): string {\n if (!QUALIFIED_IDENTIFIER_REGEX.test(identifier)) {\n throw new TypeError(\n `Invalid identifier: ${identifier}. Must be a valid identifier or qualified identifier (e.g., table.column)`,\n )\n }\n\n const parts = identifier.split('.')\n return parts.map(quoteSingleIdentifier).join('.')\n}\n\n/**\n * Validate and quote a SQL identifier or array of identifiers/fragments\n */\nfunction sqlIdent(\n identifier: string | readonly (string | SqlFragment)[],\n): SqlFragment {\n // Handle array of identifiers and fragments\n if (Array.isArray(identifier)) {\n if (identifier.length === 0) {\n throw new TypeError('Identifier array cannot be empty')\n }\n\n const fragments: SqlFragment[] = []\n\n for (const item of identifier) {\n // Handle SqlFragment objects (like sql.raw())\n if (\n item &&\n typeof item === 'object' &&\n 'text' in item &&\n 'values' in item &&\n typeof (item as Record<string, unknown>).text === 'string' &&\n Array.isArray((item as Record<string, unknown>).values)\n ) {\n fragments.push(item as SqlFragment)\n } else if (typeof item === 'string') {\n // Handle string identifiers\n if (!item) {\n throw new TypeError('All identifiers must be non-empty strings')\n }\n\n if (!QUALIFIED_IDENTIFIER_REGEX.test(item)) {\n throw new TypeError(\n `Invalid identifier: ${item}. Must be a valid identifier or qualified identifier (e.g., table.column)`,\n )\n }\n\n fragments.push({\n text: quoteQualifiedIdentifier(item),\n values: [],\n })\n } else {\n throw new TypeError('Array items must be strings or SQL fragments')\n }\n }\n\n // Join all fragments\n const text = fragments.map((f) => f.text).join(', ')\n const values = fragments.flatMap((f) => [...f.values])\n\n return {\n text,\n values,\n }\n }\n\n // Handle single identifier (existing behavior)\n if (!identifier || typeof identifier !== 'string') {\n throw new TypeError('Identifier must be a non-empty string')\n }\n\n if (!QUALIFIED_IDENTIFIER_REGEX.test(identifier)) {\n throw new TypeError(\n `Invalid identifier: ${identifier}. Must be a valid identifier or qualified identifier (e.g., table.column)`,\n )\n }\n\n return {\n text: quoteQualifiedIdentifier(identifier),\n values: [],\n }\n}\n\n/**\n * Create SQL IN clause from array\n */\nfunction sqlIn(array: readonly unknown[]): SqlFragment {\n if (!Array.isArray(array)) {\n throw new TypeError('sql.in() requires an array')\n }\n\n if (array.length === 0) {\n throw new TypeError('sql.in() cannot be used with empty arrays')\n }\n\n // Soft warning for large arrays\n if (array.length > 1000) {\n console.warn(\n `sql.in(): Large array with ${array.length} items. Consider using temporary tables for better performance.`,\n )\n }\n\n const placeholders = array.map(() => '?').join(',')\n const values = array.map(sqlValue)\n\n return {\n text: `(${placeholders})`,\n values,\n }\n}\n\n/**\n * Create raw SQL fragment (DANGEROUS - must not contain user input)\n */\nfunction sqlRaw(rawSql: string): SqlFragment {\n if (typeof rawSql !== 'string') {\n throw new TypeError('sql.raw() requires a string')\n }\n\n return {\n text: rawSql,\n values: [],\n }\n}\n\n/**\n * Create SQL fragment for BLOB data (for validated binary data)\n */\nfunction sqlBlob(data: Buffer | Uint8Array): SqlFragment {\n if (!(data instanceof Buffer) && !(data instanceof Uint8Array)) {\n throw new TypeError('sql.blob() requires a Buffer or Uint8Array')\n }\n\n return {\n text: '?',\n values: [data],\n }\n}\n\n/**\n * Join SQL fragments with a separator\n */\nfunction sqlJoin(\n fragments: readonly SqlFragment[],\n separator = ', ',\n): SqlFragment {\n if (!Array.isArray(fragments)) {\n throw new TypeError('sql.join() requires an array of fragments')\n }\n\n if (fragments.length === 0) {\n return { text: '', values: [] }\n }\n\n const text = fragments.map((f: SqlFragment) => f.text).join(separator)\n const values = fragments.flatMap((f: SqlFragment) => [...f.values])\n\n return { text, values }\n}\n\n/**\n * Main SQL tagged template function\n */\nfunction sql(strings: TemplateStringsArray, ...values: unknown[]): SqlQuery {\n // Build the query text and collect values\n let text = strings[0] || ''\n const queryValues: unknown[] = []\n\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n\n // Handle SqlFragment objects (from helper functions)\n if (\n value &&\n typeof value === 'object' &&\n 'text' in value &&\n 'values' in value &&\n typeof (value as Record<string, unknown>).text === 'string' &&\n Array.isArray((value as Record<string, unknown>).values)\n ) {\n const fragment = value as SqlFragment\n text += fragment.text\n queryValues.push(...fragment.values)\n } else {\n // Regular value - add placeholder and collect value\n text += '?'\n queryValues.push(sqlValue(value as SqlValue))\n }\n\n text += strings[i + 1] || ''\n }\n\n // Security checks\n if (text.length > MAX_QUERY_LENGTH) {\n throw new Error(\n `Query too long: ${text.length} bytes (max: ${MAX_QUERY_LENGTH})`,\n )\n }\n\n if (STACKED_QUERY_REGEX.test(text)) {\n throw new Error('Stacked queries are not allowed')\n }\n\n // Return frozen result\n return Object.freeze({\n text,\n values: Object.freeze([...queryValues]),\n })\n}\n\n// Attach helper functions to sql\nsql.value = sqlValue\nsql.ident = sqlIdent\nsql.in = sqlIn\nsql.raw = sqlRaw\nsql.blob = sqlBlob\nsql.join = sqlJoin\n\nexport { sql }\n",
|
|
7
|
-
"import { SIMPLE_IDENTIFIER_REGEX } from './constants'\nimport { sql } from './sql'\nimport type {\n ComparisonOperators,\n FieldCondition,\n FilterResult,\n JsonFilter,\n} from './types'\n\n// Limits to prevent DoS attacks\nconst MAX_NESTING_DEPTH = 10\nconst MAX_OPERATORS = 100\n\n// Valid operators for validation\nconst VALID_OPERATORS = new Set([\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n 'ne',\n 'in',\n 'nin',\n 'like',\n 'ilike',\n 'regex',\n 'exists',\n 'and',\n 'or',\n])\n\n/**\n * Context for tracking compilation state\n */\ninterface CompileContext {\n depth: number\n operatorCount: number\n values: unknown[]\n}\n\n/**\n * Check if a field name represents a JSON path (contains dots)\n */\nfunction isJsonPath(field: string): boolean {\n return field.includes('.')\n}\n\n/**\n * Convert a JSON path field to json_extract expression\n */\nfunction compileJsonPath(field: string): {\n columnName: string\n jsonPath: string\n} {\n const parts = field.split('.')\n const columnName = parts[0]\n const jsonPath = parts.slice(1)\n\n if (!columnName || jsonPath.length === 0 || jsonPath.some((part) => !part)) {\n throw new SyntaxError(`Invalid JSON path: ${field}`)\n }\n\n return {\n columnName,\n jsonPath: '$.' + jsonPath.join('.'),\n }\n}\n\n/**\n * Validate if a string is a valid SQL identifier\n */\nfunction isValidSqlIdentifier(identifier: string): boolean {\n return SIMPLE_IDENTIFIER_REGEX.test(identifier)\n}\n\n/**\n * Compile a single field condition to SQL\n */\nfunction compileFieldCondition(\n field: string,\n condition: FieldCondition,\n context: CompileContext,\n alias?: string,\n): string {\n // Handle direct value (equality)\n if (\n condition === null ||\n condition === undefined ||\n typeof condition === 'string' ||\n typeof condition === 'number' ||\n typeof condition === 'boolean' ||\n condition instanceof Date\n ) {\n context.operatorCount++\n if (context.operatorCount > MAX_OPERATORS) {\n throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`)\n }\n\n if (isJsonPath(field)) {\n const { columnName, jsonPath } = compileJsonPath(field)\n const identFragment = sql.ident(columnName)\n const fullFieldExpr = alias\n ? `${alias}.${identFragment.text}`\n : identFragment.text\n\n if (condition === null || condition === undefined) {\n context.values.push(jsonPath)\n return `(json_extract(${fullFieldExpr}, ?) IS NULL)`\n } else {\n context.values.push(jsonPath, sql.value(condition))\n return `(json_extract(${fullFieldExpr}, ?) = ?)`\n }\n } else {\n const identFragment = sql.ident(field)\n const fullFieldExpr = alias\n ? `${alias}.${identFragment.text}`\n : identFragment.text\n\n if (condition === null || condition === undefined) {\n return `(${fullFieldExpr} IS NULL)`\n } else {\n context.values.push(sql.value(condition))\n return `(${fullFieldExpr} = ?)`\n }\n }\n }\n\n // Handle operator object\n if (typeof condition !== 'object' || condition === null) {\n throw new TypeError('Condition must be a value or operator object')\n }\n\n const operators = condition as ComparisonOperators\n const clauses: string[] = []\n\n // Validate all operators are known\n for (const op of Object.keys(operators)) {\n if (!VALID_OPERATORS.has(op)) {\n throw new SyntaxError(`Unknown operator: ${op}`)\n }\n }\n\n const identFragment = sql.ident(\n isJsonPath(field) ? compileJsonPath(field).columnName : field,\n )\n const baseFieldExpr = alias\n ? `${alias}.${identFragment.text}`\n : identFragment.text\n const fieldExpr = isJsonPath(field)\n ? `json_extract(${baseFieldExpr}, ?)`\n : baseFieldExpr\n\n // Add JSON path to values if needed\n if (isJsonPath(field)) {\n context.values.push(compileJsonPath(field).jsonPath)\n }\n\n // Handle exists operator first (it overrides other operators)\n if ('exists' in operators) {\n context.operatorCount++\n if (context.operatorCount > MAX_OPERATORS) {\n throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`)\n }\n\n return operators.exists\n ? `(${fieldExpr} IS NOT NULL)`\n : `(${fieldExpr} IS NULL)`\n }\n\n // Handle comparison operators\n for (const [op, value] of Object.entries(operators)) {\n context.operatorCount++\n if (context.operatorCount > MAX_OPERATORS) {\n throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`)\n }\n\n switch (op) {\n case 'gt':\n context.values.push(sql.value(value))\n clauses.push(`${fieldExpr} > ?`)\n break\n case 'gte':\n context.values.push(sql.value(value))\n clauses.push(`${fieldExpr} >= ?`)\n break\n case 'lt':\n context.values.push(sql.value(value))\n clauses.push(`${fieldExpr} < ?`)\n break\n case 'lte':\n context.values.push(sql.value(value))\n clauses.push(`${fieldExpr} <= ?`)\n break\n case 'ne':\n if (value === null || value === undefined) {\n clauses.push(`${fieldExpr} IS NOT NULL`)\n } else {\n context.values.push(sql.value(value))\n clauses.push(`${fieldExpr} <> ?`)\n }\n break\n case 'in': {\n if (!Array.isArray(value)) {\n throw new TypeError('IN operator requires an array')\n }\n if (value.length === 0) {\n throw new TypeError('IN operator cannot be used with empty arrays')\n }\n if (value.length > 999) {\n throw new RangeError(\n 'IN operator cannot be used with arrays larger than 999 items',\n )\n }\n\n const inFragment = sql.in(value)\n context.values.push(...inFragment.values)\n clauses.push(`${fieldExpr} IN ${inFragment.text}`)\n break\n }\n case 'nin': {\n if (!Array.isArray(value)) {\n throw new TypeError('NIN operator requires an array')\n }\n if (value.length === 0) {\n throw new TypeError('NIN operator cannot be used with empty arrays')\n }\n if (value.length > 999) {\n throw new RangeError(\n 'NIN operator cannot be used with arrays larger than 999 items',\n )\n }\n\n const ninFragment = sql.in(value)\n context.values.push(...ninFragment.values)\n clauses.push(`${fieldExpr} NOT IN ${ninFragment.text}`)\n break\n }\n case 'like':\n if (typeof value !== 'string') {\n throw new TypeError('LIKE operator requires a string pattern')\n }\n context.values.push(value)\n clauses.push(`${fieldExpr} LIKE ?`)\n break\n case 'ilike':\n if (typeof value !== 'string') {\n throw new TypeError('ILIKE operator requires a string pattern')\n }\n context.values.push(value)\n clauses.push(`${fieldExpr} LIKE ? COLLATE NOCASE`)\n break\n case 'regex':\n if (typeof value !== 'string') {\n throw new TypeError('REGEX operator requires a string pattern')\n }\n context.values.push(value)\n clauses.push(`${fieldExpr} REGEXP ?`)\n break\n }\n }\n\n if (clauses.length === 0) {\n throw new SyntaxError(\n 'Operator object must contain at least one valid operator',\n )\n }\n\n return clauses.length === 1 ? `(${clauses[0]})` : `(${clauses.join(' AND ')})`\n}\n\n/**\n * Compile a JSON filter to SQL recursively\n */\nfunction compileFilterRecursive(\n filter: JsonFilter,\n context: CompileContext,\n alias?: string,\n): string {\n if (context.depth >= MAX_NESTING_DEPTH) {\n throw new RangeError(`Nesting depth too deep (max: ${MAX_NESTING_DEPTH})`)\n }\n\n if (typeof filter !== 'object' || filter === null) {\n throw new TypeError('Filter must be an object')\n }\n\n context.depth++\n const clauses: string[] = []\n\n // Handle logical operators first\n if ('and' in filter && filter.and) {\n context.operatorCount++\n if (context.operatorCount > MAX_OPERATORS) {\n throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`)\n }\n\n if (!Array.isArray(filter.and)) {\n throw new TypeError('AND operator must be an array')\n }\n if (filter.and.length === 0) {\n throw new TypeError('AND operator cannot be used with empty arrays')\n }\n\n const andClauses = filter.and.map((subFilter) =>\n compileFilterRecursive(subFilter, context, alias),\n )\n clauses.push(`(${andClauses.join(' AND ')})`)\n }\n\n if ('or' in filter && filter.or) {\n context.operatorCount++\n if (context.operatorCount > MAX_OPERATORS) {\n throw new RangeError(`Too many operators (max: ${MAX_OPERATORS})`)\n }\n\n if (!Array.isArray(filter.or)) {\n throw new TypeError('OR operator must be an array')\n }\n if (filter.or.length === 0) {\n throw new TypeError('OR operator cannot be used with empty arrays')\n }\n\n const orClauses = filter.or.map((subFilter) =>\n compileFilterRecursive(subFilter, context, alias),\n )\n clauses.push(`(${orClauses.join(' OR ')})`)\n }\n\n // Handle field conditions (implicit AND) first - preserve original order\n const fieldEntries = Object.entries(filter).filter(\n ([field, condition]) =>\n field !== 'and' &&\n field !== 'or' &&\n !field.startsWith('$') &&\n condition !== undefined,\n )\n\n for (const [field, condition] of fieldEntries) {\n // Handle array conditions (for 'and'/'or' at field level)\n if (Array.isArray(condition)) {\n throw new SyntaxError(\n `Field '${field}' cannot have array value. Use logical operators 'and'/'or' instead.`,\n )\n }\n\n clauses.push(\n compileFieldCondition(field, condition as FieldCondition, context, alias),\n )\n }\n\n // Handle alias blocks (keys starting with $) after regular fields\n const aliasEntries = Object.entries(filter).filter(\n ([key, value]) =>\n key.startsWith('$') &&\n value !== undefined &&\n typeof value === 'object' &&\n value !== null,\n )\n\n for (const [aliasKey, aliasFilter] of aliasEntries) {\n const aliasName = aliasKey.slice(1) // Remove the $ prefix\n\n // Validate alias name\n if (!isValidSqlIdentifier(aliasName)) {\n throw new SyntaxError(`Invalid alias identifier: ${aliasName}`)\n }\n\n // Recursively compile the alias block with the alias context\n const aliasClause = compileFilterRecursive(\n aliasFilter as JsonFilter,\n context,\n aliasName,\n )\n clauses.push(aliasClause)\n }\n\n context.depth--\n\n if (clauses.length === 0) {\n throw new SyntaxError('Filter must contain at least one condition')\n }\n\n // Fix: ensure we have at least one clause before accessing clauses[0]\n if (clauses.length === 1) {\n return clauses[0]!\n } else {\n return `(${clauses.join(' AND ')})`\n }\n}\n\n/**\n * Compile a JSON filter to a SQL WHERE clause\n */\nexport function compileFilter(filter: JsonFilter): FilterResult {\n const context: CompileContext = {\n depth: 0,\n operatorCount: 0,\n values: [],\n }\n\n const text = compileFilterRecursive(filter, context)\n\n return Object.freeze({\n text: `(${text})`,\n values: Object.freeze([...context.values]),\n })\n}\n"
|
|
8
|
-
],
|
|
9
|
-
"mappings": ";AAKO,IAAM,mBAAmB;AAGzB,IAAM,sBAAsB;AAG5B,IAAM,6BACX;AAGK,IAAM,0BAA0B;;;ACJvC,SAAS,UAAU,CAAC,MAAoB;AAAA,EACtC,MAAM,OAAO,KAAK,YAAY;AAAA,EAC9B,MAAM,QAAQ,OAAO,KAAK,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,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AAe;AAAA,IACf,QAAQ,CAAC;AAAA,EACX;AAAA,EAEA,MAAM,OAAO,uBAAuB,QAAQ,OAAO;AAAA,EAEnD,OAAO,OAAO,OAAO;AAAA,IACnB,MAAM,IAAI;AAAA,IACV,QAAQ,OAAO,OAAO,CAAC,GAAG,QAAQ,MAAM,CAAC;AAAA,EAC3C,CAAC;AAAA;",
|
|
10
|
-
"debugId": "2601C616902F043764756E2164756E21",
|
|
11
|
-
"names": []
|
|
12
|
-
}
|
package/dist/sql.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { SqlFragment, SqlQuery, SqlValue } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Convert a value to its SQLite representation
|
|
4
|
-
*/
|
|
5
|
-
declare function sqlValue(value: SqlValue): unknown;
|
|
6
|
-
/**
|
|
7
|
-
* Validate and quote a SQL identifier or array of identifiers/fragments
|
|
8
|
-
*/
|
|
9
|
-
declare function sqlIdent(identifier: string | readonly (string | SqlFragment)[]): SqlFragment;
|
|
10
|
-
/**
|
|
11
|
-
* Create SQL IN clause from array
|
|
12
|
-
*/
|
|
13
|
-
declare function sqlIn(array: readonly unknown[]): SqlFragment;
|
|
14
|
-
/**
|
|
15
|
-
* Create raw SQL fragment (DANGEROUS - must not contain user input)
|
|
16
|
-
*/
|
|
17
|
-
declare function sqlRaw(rawSql: string): SqlFragment;
|
|
18
|
-
/**
|
|
19
|
-
* Create SQL fragment for BLOB data (for validated binary data)
|
|
20
|
-
*/
|
|
21
|
-
declare function sqlBlob(data: Buffer | Uint8Array): SqlFragment;
|
|
22
|
-
/**
|
|
23
|
-
* Join SQL fragments with a separator
|
|
24
|
-
*/
|
|
25
|
-
declare function sqlJoin(fragments: readonly SqlFragment[], separator?: string): SqlFragment;
|
|
26
|
-
/**
|
|
27
|
-
* Main SQL tagged template function
|
|
28
|
-
*/
|
|
29
|
-
declare function sql(strings: TemplateStringsArray, ...values: unknown[]): SqlQuery;
|
|
30
|
-
declare namespace sql {
|
|
31
|
-
export var value: typeof sqlValue;
|
|
32
|
-
export var ident: typeof sqlIdent;
|
|
33
|
-
var _a: typeof sqlIn;
|
|
34
|
-
export var raw: typeof sqlRaw;
|
|
35
|
-
export var blob: typeof sqlBlob;
|
|
36
|
-
export var join: typeof sqlJoin;
|
|
37
|
-
export { _a as in };
|
|
38
|
-
}
|
|
39
|
-
export { sql };
|
|
40
|
-
//# sourceMappingURL=sql.d.ts.map
|
package/dist/sql.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAgB9D;;GAEG;AACH,iBAAS,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAwB1C;AA4BD;;GAEG;AACH,iBAAS,QAAQ,CACf,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,GACrD,WAAW,CAkEb;AAED;;GAEG;AACH,iBAAS,KAAK,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,WAAW,CAuBrD;AAED;;GAEG;AACH,iBAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAS3C;AAED;;GAEG;AACH,iBAAS,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,CASvD;AAED;;GAEG;AACH,iBAAS,OAAO,CACd,SAAS,EAAE,SAAS,WAAW,EAAE,EACjC,SAAS,SAAO,GACf,WAAW,CAab;AAED;;GAEG;AACH,iBAAS,GAAG,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CA6C1E;kBA7CQ,GAAG;;;;;;;;;AAuDZ,OAAO,EAAE,GAAG,EAAE,CAAA"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The result of a SQL tagged template
|
|
3
|
-
*/
|
|
4
|
-
export interface SqlQuery {
|
|
5
|
-
readonly text: string;
|
|
6
|
-
readonly values: readonly unknown[];
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Valid SQL value types that can be safely interpolated
|
|
10
|
-
*/
|
|
11
|
-
export type SqlValue = string | number | boolean | null | undefined | Date | Buffer | Uint8Array;
|
|
12
|
-
/**
|
|
13
|
-
* A SQL fragment that can be joined with other fragments
|
|
14
|
-
*/
|
|
15
|
-
export interface SqlFragment {
|
|
16
|
-
readonly text: string;
|
|
17
|
-
readonly values: readonly unknown[];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Comparison operators for JSON filters
|
|
21
|
-
*/
|
|
22
|
-
export interface ComparisonOperators {
|
|
23
|
-
/** Greater than */
|
|
24
|
-
gt?: SqlValue;
|
|
25
|
-
/** Greater than or equal */
|
|
26
|
-
gte?: SqlValue;
|
|
27
|
-
/** Less than */
|
|
28
|
-
lt?: SqlValue;
|
|
29
|
-
/** Less than or equal */
|
|
30
|
-
lte?: SqlValue;
|
|
31
|
-
/** Not equal */
|
|
32
|
-
ne?: SqlValue;
|
|
33
|
-
/** IN array */
|
|
34
|
-
in?: readonly SqlValue[];
|
|
35
|
-
/** NOT IN array */
|
|
36
|
-
nin?: readonly SqlValue[];
|
|
37
|
-
/** LIKE pattern */
|
|
38
|
-
like?: string;
|
|
39
|
-
/** Case-insensitive LIKE */
|
|
40
|
-
ilike?: string;
|
|
41
|
-
/** Regular expression pattern */
|
|
42
|
-
regex?: string;
|
|
43
|
-
/** Field exists check (true = IS NOT NULL, false = IS NULL) */
|
|
44
|
-
exists?: boolean;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* A field condition can be a direct value or an object with operators
|
|
48
|
-
*/
|
|
49
|
-
export type FieldCondition = SqlValue | ComparisonOperators;
|
|
50
|
-
/**
|
|
51
|
-
* Logical operators for combining filters
|
|
52
|
-
*/
|
|
53
|
-
export interface LogicalOperators {
|
|
54
|
-
/** All conditions must match */
|
|
55
|
-
and?: readonly JsonFilter[];
|
|
56
|
-
/** Any condition must match */
|
|
57
|
-
or?: readonly JsonFilter[];
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* A JSON filter for compiling to SQL WHERE clauses
|
|
61
|
-
* Can be a field-to-condition mapping with implicit AND, explicit logical operators,
|
|
62
|
-
* or alias blocks (keys starting with $) containing nested filters
|
|
63
|
-
*/
|
|
64
|
-
export type JsonFilter = LogicalOperators & {
|
|
65
|
-
[field: string]: FieldCondition | readonly JsonFilter[] | JsonFilter | undefined;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Result of compiling a JSON filter to SQL
|
|
69
|
-
*/
|
|
70
|
-
export interface FilterResult {
|
|
71
|
-
readonly text: string;
|
|
72
|
-
readonly values: readonly unknown[];
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAA;CACpC;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,IAAI,GACJ,MAAM,GACN,UAAU,CAAA;AAEd;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAA;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mBAAmB;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