@ganju/utils 0.0.16 → 0.0.18
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/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +26 -2
- package/dist/customCodeToken.d.ts +15 -0
- package/dist/customCodeToken.d.ts.map +1 -1
- package/dist/customCodeToken.js +49 -1
- package/dist/data.d.ts +6 -0
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +53 -1
- package/dist/dataApi.d.ts +200 -1
- package/dist/dataApi.d.ts.map +1 -1
- package/dist/dataApi.js +106 -1
- package/dist/dataCompiler.d.ts.map +1 -1
- package/dist/dataCompiler.js +5 -1
- package/dist/dataCsv.d.ts +20 -0
- package/dist/dataCsv.d.ts.map +1 -0
- package/dist/dataCsv.js +102 -0
- package/dist/dataDdl.d.ts.map +1 -1
- package/dist/dataDdl.js +3 -1
- package/dist/dataEngine.d.ts.map +1 -1
- package/dist/dataEngine.js +86 -4
- package/dist/dataImport.d.ts +2 -0
- package/dist/dataImport.d.ts.map +1 -1
- package/dist/dataImport.js +4 -1
- package/dist/dataQueries.d.ts +73 -0
- package/dist/dataQueries.d.ts.map +1 -0
- package/dist/dataQueries.js +513 -0
- package/dist/dataRpc.d.ts +44 -0
- package/dist/dataRpc.d.ts.map +1 -1
- package/dist/dataTools.d.ts +40 -0
- package/dist/dataTools.d.ts.map +1 -0
- package/dist/dataTools.js +280 -0
- package/dist/dataTriggers.d.ts +203 -0
- package/dist/dataTriggers.d.ts.map +1 -0
- package/dist/dataTriggers.js +760 -0
- package/dist/dataTypes.d.ts +3 -0
- package/dist/dataTypes.d.ts.map +1 -1
- package/dist/index.d.ts +201 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/localizeDataError.d.ts +18 -0
- package/dist/localizeDataError.d.ts.map +1 -0
- package/dist/localizeDataError.js +359 -0
- package/dist/schema.d.ts +201 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +149 -1
- package/dist/sdkConstants.d.ts +3 -0
- package/dist/sdkConstants.d.ts.map +1 -1
- package/dist/sdkConstants.js +4 -1
- package/package.json +1 -1
- package/src/constants.ts +30 -2
- package/src/customCodeToken.ts +87 -0
- package/src/data.ts +74 -0
- package/src/dataApi.ts +129 -2
- package/src/dataCompiler.ts +5 -1
- package/src/dataCsv.ts +99 -0
- package/src/dataDdl.ts +3 -1
- package/src/dataEngine.ts +94 -4
- package/src/dataImport.ts +3 -0
- package/src/dataQueries.ts +730 -0
- package/src/dataRpc.ts +26 -0
- package/src/dataTools.ts +338 -0
- package/src/dataTriggers.ts +1134 -0
- package/src/dataTypes.ts +9 -0
- package/src/index.ts +11 -1
- package/src/localizeDataError.ts +593 -0
- package/src/schema.ts +158 -1
- package/src/sdkConstants.ts +3 -0
package/dist/dataApi.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.dataOpenApi = exports.DATA_API_ROUTES = exports.DATA_API_BASE = void 0;
|
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const schema_1 = require("./schema");
|
|
9
9
|
exports.DATA_API_BASE = '/organization/:organizationId/project/:projectId/artifact/data';
|
|
10
|
-
const { DATA_DATABASE_CREATE, DATA_DATABASE_DELETE, DATA_TABLE_INPUT, DATA_TABLE_PATCH, DATA_COLUMN_INPUT, DATA_COLUMN_PATCH, DATA_TABLE_DROP_BODY, DATA_ROW_LIST_QUERY, DATA_ROW_GET_QUERY, DATA_ROW_CREATE_BODY, DATA_ROW_UPDATE_BODY, DATA_ROW_DELETE_BODY, DATA_DELETE_PREVIEW_BODY, DATA_WRITE_BODY, DATA_ROW_HISTORY_QUERY, DATA_RESTORE_POINT_BODY, DATA_EXPORT_BODY, DATA_EXPORT_QUERY, DATA_EXPORT_FILE_QUERY, DATA_CHANGE_LIST_QUERY } = schema_1.Schema;
|
|
10
|
+
const { DATA_DATABASE_CREATE, DATA_DATABASE_DELETE, DATA_DATABASE_PATCH, DATA_TABLE_INPUT, DATA_TABLE_PATCH, DATA_COLUMN_INPUT, DATA_COLUMN_PATCH, DATA_TABLE_DROP_BODY, DATA_ROW_LIST_QUERY, DATA_ROW_GET_QUERY, DATA_ROW_CREATE_BODY, DATA_ROW_UPDATE_BODY, DATA_ROW_DELETE_BODY, DATA_DELETE_PREVIEW_BODY, DATA_WRITE_BODY, DATA_ROW_HISTORY_QUERY, DATA_RESTORE_POINT_BODY, DATA_EXPORT_BODY, DATA_EXPORT_QUERY, DATA_EXPORT_FILE_QUERY, DATA_CHANGE_LIST_QUERY, DATA_QUERY_INPUT, DATA_QUERY_RUN_BODY, DATA_TRIGGER_INPUT, DATA_TRIGGER_PATCH, DATA_TRIGGER_DEPLOY_BODY, DATA_TRIGGER_RUN_LIST_QUERY } = schema_1.Schema;
|
|
11
11
|
exports.DATA_API_ROUTES = {
|
|
12
12
|
getDatabase: {
|
|
13
13
|
method: 'get',
|
|
@@ -27,6 +27,15 @@ exports.DATA_API_ROUTES = {
|
|
|
27
27
|
returns: '{ database }',
|
|
28
28
|
status: 201
|
|
29
29
|
},
|
|
30
|
+
updateDatabase: {
|
|
31
|
+
method: 'patch',
|
|
32
|
+
path: '',
|
|
33
|
+
tag: 'Database',
|
|
34
|
+
summary: "Change the database's settings",
|
|
35
|
+
description: '`timeZone`, an IANA zone such as `America/Bogota`, or null for UTC. Datetimes come back in it for callers that send no `timeZone` of their own: the assistant, functions and scripts. Datetimes without an offset are read in it too.',
|
|
36
|
+
body: DATA_DATABASE_PATCH,
|
|
37
|
+
returns: '{ database }'
|
|
38
|
+
},
|
|
30
39
|
remove: {
|
|
31
40
|
method: 'delete',
|
|
32
41
|
path: '',
|
|
@@ -199,6 +208,100 @@ exports.DATA_API_ROUTES = {
|
|
|
199
208
|
body: DATA_WRITE_BODY,
|
|
200
209
|
returns: '{ results }'
|
|
201
210
|
},
|
|
211
|
+
listQueries: {
|
|
212
|
+
method: 'get',
|
|
213
|
+
path: '/query',
|
|
214
|
+
tag: 'Queries',
|
|
215
|
+
summary: 'Named queries',
|
|
216
|
+
description: 'Each with its SQL, parameters, the tables it reads and its plan (`SCAN orders` means it reads the whole table).',
|
|
217
|
+
returns: '{ queries }'
|
|
218
|
+
},
|
|
219
|
+
saveQuery: {
|
|
220
|
+
method: 'post',
|
|
221
|
+
path: '/query',
|
|
222
|
+
tag: 'Queries',
|
|
223
|
+
summary: 'Save a named query',
|
|
224
|
+
description: "One `SELECT` (or `WITH … SELECT`) with named parameters such as `:from`, each declared in `params` with its type. It is compiled, never run, and refused unless it only reads this database's tables. Saving under an existing name replaces it. `assistant: true` lets channel bots run it from data-query.",
|
|
225
|
+
body: DATA_QUERY_INPUT,
|
|
226
|
+
returns: '{ query }',
|
|
227
|
+
status: 201
|
|
228
|
+
},
|
|
229
|
+
dropQuery: {
|
|
230
|
+
method: 'delete',
|
|
231
|
+
path: '/query/:name',
|
|
232
|
+
tag: 'Queries',
|
|
233
|
+
summary: 'Delete a named query',
|
|
234
|
+
returns: '{ dropped }'
|
|
235
|
+
},
|
|
236
|
+
runQuery: {
|
|
237
|
+
method: 'post',
|
|
238
|
+
path: '/query/:name/run',
|
|
239
|
+
tag: 'Queries',
|
|
240
|
+
summary: 'Run a named query',
|
|
241
|
+
description: 'With its `params`, up to `limit` rows (100 by default, 500 at most) and 1 MB; `truncated` says it stopped early. A query that would scan a table over 200,000 rows is refused.',
|
|
242
|
+
body: DATA_QUERY_RUN_BODY,
|
|
243
|
+
returns: '{ query, rows, truncated? }'
|
|
244
|
+
},
|
|
245
|
+
listTriggers: {
|
|
246
|
+
method: 'get',
|
|
247
|
+
path: '/trigger',
|
|
248
|
+
tag: 'Triggers',
|
|
249
|
+
summary: 'Triggers',
|
|
250
|
+
description: 'Each with its table, event, condition and action. `pending` counts events not yet handed to the queue. Webhook secrets are never listed.',
|
|
251
|
+
returns: '{ triggers, pending }'
|
|
252
|
+
},
|
|
253
|
+
saveTrigger: {
|
|
254
|
+
method: 'post',
|
|
255
|
+
path: '/trigger',
|
|
256
|
+
tag: 'Triggers',
|
|
257
|
+
summary: 'Save a trigger',
|
|
258
|
+
description: 'Runs one action when rows of `table` are inserted, updated or deleted, and `when` holds: `{ "status": { "changedTo": "READY" } }` fires on the transition only; `changedFrom`, `changed: true` and `equals` test a column too, and `all` / `any` combine them. The action is one of `function` (a function of this project, given `{ event, table, row, previous, actor, eventId, triggerId }`), `webhook` (an https URL, sent a POST signed in `x-ganju-signature`), `chat` (`{ channelId, chatId, text }`), `email` (`{ to, subject, text }`) or `customer` (`{ text, template? }`, to the row\'s customer on a customer-scoped table). Texts take `{{field}}` from the row, inserted as plain text. Saving under an existing name replaces it, unless `replace` is false; with no `name`, it always creates a new trigger, named from the table, event and action and numbered past those taken. Left out, `enabled` keeps a saved trigger on or off as it was. A new webhook answers with its signing `secret`, shown this once. Delivery is at least once: every event carries an `eventId`.',
|
|
259
|
+
body: DATA_TRIGGER_INPUT,
|
|
260
|
+
returns: '{ trigger, secret? }',
|
|
261
|
+
status: 201
|
|
262
|
+
},
|
|
263
|
+
updateTrigger: {
|
|
264
|
+
method: 'patch',
|
|
265
|
+
path: '/trigger/:name',
|
|
266
|
+
tag: 'Triggers',
|
|
267
|
+
summary: 'Turn a trigger on or off',
|
|
268
|
+
description: 'Turning one back on clears why Ganju turned it off (20 failed runs in a row).',
|
|
269
|
+
body: DATA_TRIGGER_PATCH,
|
|
270
|
+
returns: '{ trigger }'
|
|
271
|
+
},
|
|
272
|
+
dropTrigger: {
|
|
273
|
+
method: 'delete',
|
|
274
|
+
path: '/trigger/:name',
|
|
275
|
+
tag: 'Triggers',
|
|
276
|
+
summary: 'Delete a trigger',
|
|
277
|
+
returns: '{ dropped }'
|
|
278
|
+
},
|
|
279
|
+
deployTriggers: {
|
|
280
|
+
method: 'post',
|
|
281
|
+
path: '/trigger/deploy',
|
|
282
|
+
tag: 'Triggers',
|
|
283
|
+
summary: 'Deploy the triggers of ganju.json',
|
|
284
|
+
description: "What `ganju deploy` sends: every trigger listed is saved as managed by the CLI, and the CLI's earlier ones not listed are deleted. Triggers made in the dashboard are left alone. All or nothing. New webhooks' secrets come back once, by name.",
|
|
285
|
+
body: DATA_TRIGGER_DEPLOY_BODY,
|
|
286
|
+
returns: '{ triggers, removed, secrets }'
|
|
287
|
+
},
|
|
288
|
+
listTriggerRuns: {
|
|
289
|
+
method: 'get',
|
|
290
|
+
path: '/trigger/:name/run',
|
|
291
|
+
tag: 'Triggers',
|
|
292
|
+
summary: "A trigger's recent runs",
|
|
293
|
+
description: 'Newest first, up to 50: `ok`, `failed` with its error, `skipped`, or `running`.',
|
|
294
|
+
query: DATA_TRIGGER_RUN_LIST_QUERY,
|
|
295
|
+
returns: '{ runs }'
|
|
296
|
+
},
|
|
297
|
+
retryTriggerRun: {
|
|
298
|
+
method: 'post',
|
|
299
|
+
path: '/trigger/:name/run/:runId/retry',
|
|
300
|
+
tag: 'Triggers',
|
|
301
|
+
summary: 'Run a failed event again',
|
|
302
|
+
description: 'The same event, with the same `eventId`.',
|
|
303
|
+
returns: '{ run }'
|
|
304
|
+
},
|
|
202
305
|
startExport: {
|
|
203
306
|
method: 'post',
|
|
204
307
|
path: '/export',
|
|
@@ -323,6 +426,8 @@ const dataOpenApi = (serverUrl) => {
|
|
|
323
426
|
{ name: 'Database' },
|
|
324
427
|
{ name: 'Tables' },
|
|
325
428
|
{ name: 'Rows' },
|
|
429
|
+
{ name: 'Queries' },
|
|
430
|
+
{ name: 'Triggers' },
|
|
326
431
|
{ name: 'History and export' }
|
|
327
432
|
],
|
|
328
433
|
paths,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataCompiler.d.ts","sourceRoot":"","sources":["../src/dataCompiler.ts"],"names":[],"mappings":"AAMA,OAAO,EAKL,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,EACV,MAAM,aAAa,CAAC;AAErB,MAAM,MA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,WAAW,YAAY;IAE3B,CAAC,EAAE,MAAM,CAAC;IAEV,CAAC,EAAE,QAAQ,EAAE,CAAC;IAEd,CAAC,CAAC,EAAE,KAAK,CAAC;CACX;AAED,eAAO,MAAM,YAAY,GAAI,QAAQ,YAAY,KAAG,MACX,CAAC;AAE1C,eAAO,MAAM,YAAY,GAAI,KAAK,OAAO,EAAE,WAAW,MAAM,KAAG,YAmB9D,CAAC;AAMF,eAAO,MAAM,eAAe,GAC1B,MAAM,SAAS,OAAO,EAAE,EACxB,QAAQ,SAAS,QAAQ,EAAE,EAC3B,QAAQ,QAAQ,EAAE,KACjB,MA6BF,CAAC;AAKF,eAAO,MAAM,aAAa,GAAI,eAAe,MAAM,KAAG,MACiB,CAAC;AAGxE,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,SAAS,CAAC,EAAE,EAAE,eAAe,MAAM,KAAG,CAAC,EAAE,EAW3E,CAAC;AAuDF,eAAO,MAAM,QAAQ,GAAI,MAAM,OAAO,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAkC9D,CAAC;AAmCF,eAAO,MAAM,gBAAgB,GAC3B,SAAS,OAAO,EAChB,SAAS,UAAU,KAClB,OAmBF,CAAC"}
|
package/dist/dataCompiler.js
CHANGED
|
@@ -43,7 +43,11 @@ const unknownColumn = (table, name) => new dataTypes_1.DataError(`Unknown column
|
|
|
43
43
|
].join(', ')}.`, 'invalid');
|
|
44
44
|
exports.unknownColumn = unknownColumn;
|
|
45
45
|
// Access
|
|
46
|
-
const accessOf = (caller, table) => caller.
|
|
46
|
+
const accessOf = (caller, table) => caller.tables && !caller.tables.includes(table.name)
|
|
47
|
+
? 'none'
|
|
48
|
+
: caller.restricted
|
|
49
|
+
? table.access
|
|
50
|
+
: 'full';
|
|
47
51
|
exports.accessOf = accessOf;
|
|
48
52
|
const visibleTables = (schema, caller) => schema.tables.filter(table => dataTypes_1.DATA_ACCESS_RANK[(0, exports.accessOf)(caller, table)] >= 1);
|
|
49
53
|
exports.visibleTables = visibleTables;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a CSV file into rows of text, with no parser package behind it:
|
|
3
|
+
* the CLI's import and the owner's data-admin tool read files the same way.
|
|
4
|
+
*
|
|
5
|
+
* RFC 4180 plus the two things spreadsheets actually write: a byte-order mark
|
|
6
|
+
* in front, and `;` between fields where the decimal mark is a comma (Excel in
|
|
7
|
+
* Spanish). The separator is read from the header line, so the same file
|
|
8
|
+
* exported from either locale imports the same way.
|
|
9
|
+
*
|
|
10
|
+
* Every cell comes back as text. Deciding what "28.000" means is the shared
|
|
11
|
+
* import code's job, so the CLI and the dashboard decide it the same way.
|
|
12
|
+
*/
|
|
13
|
+
export interface ParsedCsv {
|
|
14
|
+
headers: string[];
|
|
15
|
+
rows: string[][];
|
|
16
|
+
lines: number[];
|
|
17
|
+
}
|
|
18
|
+
export declare const detectSeparator: (text: string) => string;
|
|
19
|
+
export declare const parseCsv: (input: string, separator?: string) => ParsedCsv;
|
|
20
|
+
//# sourceMappingURL=dataCsv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataCsv.d.ts","sourceRoot":"","sources":["../src/dataCsv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IAGjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAKD,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,MAc9C,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,YAAY,MAAM,KAAG,SA0D5D,CAAC"}
|
package/dist/dataCsv.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reading a CSV file into rows of text, with no parser package behind it:
|
|
4
|
+
* the CLI's import and the owner's data-admin tool read files the same way.
|
|
5
|
+
*
|
|
6
|
+
* RFC 4180 plus the two things spreadsheets actually write: a byte-order mark
|
|
7
|
+
* in front, and `;` between fields where the decimal mark is a comma (Excel in
|
|
8
|
+
* Spanish). The separator is read from the header line, so the same file
|
|
9
|
+
* exported from either locale imports the same way.
|
|
10
|
+
*
|
|
11
|
+
* Every cell comes back as text. Deciding what "28.000" means is the shared
|
|
12
|
+
* import code's job, so the CLI and the dashboard decide it the same way.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.parseCsv = exports.detectSeparator = void 0;
|
|
16
|
+
const SEPARATORS = [',', ';', '\t'];
|
|
17
|
+
// The separator that appears most in the first line, outside quotes.
|
|
18
|
+
const detectSeparator = (text) => {
|
|
19
|
+
const counts = new Map(SEPARATORS.map(s => [s, 0]));
|
|
20
|
+
let quoted = false;
|
|
21
|
+
for (const char of text) {
|
|
22
|
+
if (char === '"')
|
|
23
|
+
quoted = !quoted;
|
|
24
|
+
else if (!quoted && (char === '\n' || char === '\r'))
|
|
25
|
+
break;
|
|
26
|
+
else if (!quoted && counts.has(char))
|
|
27
|
+
counts.set(char, counts.get(char) + 1);
|
|
28
|
+
}
|
|
29
|
+
let best = ',';
|
|
30
|
+
for (const [separator, count] of counts) {
|
|
31
|
+
if (count > counts.get(best))
|
|
32
|
+
best = separator;
|
|
33
|
+
}
|
|
34
|
+
return best;
|
|
35
|
+
};
|
|
36
|
+
exports.detectSeparator = detectSeparator;
|
|
37
|
+
const parseCsv = (input, separator) => {
|
|
38
|
+
const text = input.charCodeAt(0) === 0xfeff ? input.slice(1) : input;
|
|
39
|
+
const sep = separator ?? (0, exports.detectSeparator)(text);
|
|
40
|
+
const records = [];
|
|
41
|
+
let cells = [];
|
|
42
|
+
let cell = '';
|
|
43
|
+
let quoted = false;
|
|
44
|
+
let line = 1;
|
|
45
|
+
let startLine = 1;
|
|
46
|
+
const endCell = () => {
|
|
47
|
+
cells.push(cell);
|
|
48
|
+
cell = '';
|
|
49
|
+
};
|
|
50
|
+
const endRecord = () => {
|
|
51
|
+
endCell();
|
|
52
|
+
// A blank line, or one of nothing but separators, is not a row.
|
|
53
|
+
if (cells.some(c => c.trim() !== '')) {
|
|
54
|
+
records.push({ cells, line: startLine });
|
|
55
|
+
}
|
|
56
|
+
cells = [];
|
|
57
|
+
};
|
|
58
|
+
for (let i = 0; i < text.length; i++) {
|
|
59
|
+
const char = text[i];
|
|
60
|
+
if (quoted) {
|
|
61
|
+
if (char === '"') {
|
|
62
|
+
if (text[i + 1] === '"') {
|
|
63
|
+
cell += '"';
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
quoted = false;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (char === '\n')
|
|
71
|
+
line++;
|
|
72
|
+
cell += char;
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (char === '"' && cell === '') {
|
|
77
|
+
quoted = true;
|
|
78
|
+
}
|
|
79
|
+
else if (char === sep) {
|
|
80
|
+
endCell();
|
|
81
|
+
}
|
|
82
|
+
else if (char === '\n' || char === '\r') {
|
|
83
|
+
if (char === '\r' && text[i + 1] === '\n')
|
|
84
|
+
i++;
|
|
85
|
+
endRecord();
|
|
86
|
+
line++;
|
|
87
|
+
startLine = line;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
cell += char;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (cell !== '' || cells.length)
|
|
94
|
+
endRecord();
|
|
95
|
+
const [header, ...body] = records;
|
|
96
|
+
return {
|
|
97
|
+
headers: (header?.cells ?? []).map(h => h.trim()),
|
|
98
|
+
rows: body.map(r => r.cells),
|
|
99
|
+
lines: body.map(r => r.line)
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
exports.parseCsv = parseCsv;
|
package/dist/dataDdl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataDdl.d.ts","sourceRoot":"","sources":["../src/dataDdl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dataDdl.d.ts","sourceRoot":"","sources":["../src/dataDdl.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACV,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,YAAY,0CAA0C,CAAC;AAEpE,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,cAAc,CAOtD,CAAC;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,cAAc,CAGpD,CAAC;AAEH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,cAAc,CAOvD,CAAC;AAEH,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,cAAc,CAWnD,CAAC;AAIH,eAAO,MAAM,UAAU,GAAI,OAAO,gBAAgB,KAAG,MAQpD,CAAC;AAIF,eAAO,MAAM,SAAS,GAAI,OAAO,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,QAAQ,UAAU,WAC3C,CAAC;AAChC,eAAO,MAAM,eAAe,GAC1B,OAAO,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,EAC5B,QAAQ,UAAU,WACc,CAAC;AACnC,eAAO,MAAM,oBAAoB,GAAI,OAAO,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WACnC,CAAC;AAC/B,eAAO,MAAM,YAAY,GAAI,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,WACrC,CAAC;AACvB,eAAO,MAAM,aAAa,GAAI,OAAO,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WACvC,CAAC;AACpB,eAAO,MAAM,mBAAmB,GAAI,QAAQ,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,WAC9C,CAAC;AACrB,eAAO,MAAM,iBAAiB,GAAI,QAAQ,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,WAC5C,CAAC;AAGrB,eAAO,MAAM,aAAa,GACxB,QAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,EAChC,OAAO,gBAAgB,KACtB,gBAKF,CAAC;AA2CF,eAAO,MAAM,mBAAmB,GAAI,QAAQ,UAAU,KAAG,MAuBxD,CAAC;AAKF,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,EACZ,SAAS,SAAS,UAAU,EAAE,KAC7B,MAcW,CAAC;AAEf,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAMD,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,KAAG,cAAc,EA6B/D,CAAC;AAGF,eAAO,MAAM,eAAe,GAAI,QAAQ,UAAU,KAAG,OAI7B,CAAC;AAEzB,eAAO,MAAM,iBAAiB,GAAI,OAAO,SAAS,KAAG,UAAU,EAG5D,CAAC;AAKJ,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,KAAG,MAAM,GAAG,IAQxD,CAAC;AAkGF,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,KAAG,cAAc,EAIhE,CAAC;AAOF,eAAO,MAAM,aAAa,GACxB,UAAU,cAAc,EACxB,IAAI,UAAU,EACd,KAAK,MAAM,KACV,MAgCF,CAAC;AAIF,eAAO,MAAM,yBAAyB,GACpC,IAAI,UAAU,EACd,KAAK,MAAM,EACX,WAAW,MAAM,KAChB,MAyBF,CAAC"}
|
package/dist/dataDdl.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.invalidAfterConversionSql = exports.conversionSql = exports.desiredTrigg
|
|
|
4
4
|
// The SQL a project's database runs to build and change its tables. Pure
|
|
5
5
|
// string building: every name in here passed identifierIssue or is one of
|
|
6
6
|
// ours, and every owner-supplied value is a literal escaped by sqlLiteral.
|
|
7
|
+
const dataTriggers_1 = require("./dataTriggers");
|
|
7
8
|
const dataIdentifiers_1 = require("./dataIdentifiers");
|
|
8
9
|
exports.DATA_NOW_SQL = "strftime('%Y-%m-%dT%H:%M:%SZ', 'now')";
|
|
9
10
|
exports.TEXT_LIKE_TYPES = new Set([
|
|
@@ -286,7 +287,8 @@ const historyTriggers = (table) => {
|
|
|
286
287
|
};
|
|
287
288
|
const desiredTriggers = (table) => [
|
|
288
289
|
...ftsTriggers(table),
|
|
289
|
-
...historyTriggers(table)
|
|
290
|
+
...historyTriggers(table),
|
|
291
|
+
...(0, dataTriggers_1.changeCaptureTriggers)(table)
|
|
290
292
|
];
|
|
291
293
|
exports.desiredTriggers = desiredTriggers;
|
|
292
294
|
// Type changes
|
package/dist/dataEngine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataEngine.d.ts","sourceRoot":"","sources":["../src/dataEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dataEngine.d.ts","sourceRoot":"","sources":["../src/dataEngine.ts"],"names":[],"mappings":"AAiDA,OAAO,KAAK,EAAoC,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EACL,YAAY,EA0BZ,SAAS,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAEV,UAAU,EACV,UAAU,EAGV,gBAAgB,EAChB,gBAAgB,EAEhB,UAAU,EACV,SAAS,EACT,aAAa,EAEd,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE9C,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAC;IAGzD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrE,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG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;AAEF,eAAO,MAAM,UAAU,GACrB,QAAQ,SAAS,EACjB,QAAQ,UAAU,EAClB,QAAQ,UAAU,EAClB,WAAW,MAAM,EACjB,YAAY,MAAM,KACjB,SAoCF,CAAC;AAMF,eAAO,MAAM,UAAU,GACrB,QAAQ,SAAS,EACjB,OAAO,SAAS,EAChB,SAAS,MAAM,KACd,QAAQ,CAAC,MAAM,CAGd,CAAC"}
|
package/dist/dataEngine.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.exportRows = exports.dropColumn = exports.updateColumn = exports.copyTab
|
|
|
6
6
|
// the tests and the tool-design eval. The runner executes; everything about
|
|
7
7
|
// which SQL is allowed and how results look is decided here.
|
|
8
8
|
const dataIdentifiers_1 = require("./dataIdentifiers");
|
|
9
|
+
const dataTriggers_1 = require("./dataTriggers");
|
|
9
10
|
const dataDdl_1 = require("./dataDdl");
|
|
10
11
|
const dataCompiler_1 = require("./dataCompiler");
|
|
11
12
|
const dataTypes_1 = require("./dataTypes");
|
|
@@ -75,6 +76,60 @@ exports.INTERNAL_MIGRATIONS = [
|
|
|
75
76
|
WHERE c.table_id = _ganju_tables.id AND c.type = 'text'
|
|
76
77
|
ORDER BY c.position, c.id LIMIT 1
|
|
77
78
|
) WHERE display_column_id IS NULL AND created_at < '2026-10-24T00:00:00Z'`
|
|
79
|
+
],
|
|
80
|
+
// Named queries: the owner's SELECTs, run by name. `tables` and `plan` are
|
|
81
|
+
// what the check found when each was saved.
|
|
82
|
+
[
|
|
83
|
+
`CREATE TABLE IF NOT EXISTS _ganju_queries (
|
|
84
|
+
name TEXT PRIMARY KEY,
|
|
85
|
+
description TEXT,
|
|
86
|
+
sql TEXT NOT NULL,
|
|
87
|
+
params TEXT NOT NULL DEFAULT '[]',
|
|
88
|
+
assistant INTEGER NOT NULL DEFAULT 0,
|
|
89
|
+
tables TEXT NOT NULL DEFAULT '[]',
|
|
90
|
+
plan TEXT NOT NULL DEFAULT '[]',
|
|
91
|
+
created_at TEXT NOT NULL DEFAULT (${dataDdl_1.DATA_NOW_SQL}),
|
|
92
|
+
updated_at TEXT NOT NULL DEFAULT (${dataDdl_1.DATA_NOW_SQL}),
|
|
93
|
+
updated_by TEXT
|
|
94
|
+
) WITHOUT ROWID`
|
|
95
|
+
],
|
|
96
|
+
// Triggers: the owner's rules, the rows a write changed while one listens
|
|
97
|
+
// (emptied before the write commits), and the events waiting for the queue.
|
|
98
|
+
[
|
|
99
|
+
`CREATE TABLE IF NOT EXISTS _ganju_triggers (
|
|
100
|
+
id TEXT PRIMARY KEY,
|
|
101
|
+
name TEXT NOT NULL UNIQUE,
|
|
102
|
+
description TEXT,
|
|
103
|
+
table_id INTEGER NOT NULL,
|
|
104
|
+
event TEXT NOT NULL,
|
|
105
|
+
condition TEXT,
|
|
106
|
+
action TEXT NOT NULL,
|
|
107
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
108
|
+
disabled_reason TEXT,
|
|
109
|
+
managed TEXT,
|
|
110
|
+
rate_limit INTEGER NOT NULL DEFAULT 60,
|
|
111
|
+
secret TEXT,
|
|
112
|
+
created_at TEXT NOT NULL DEFAULT (${dataDdl_1.DATA_NOW_SQL}),
|
|
113
|
+
updated_at TEXT NOT NULL DEFAULT (${dataDdl_1.DATA_NOW_SQL}),
|
|
114
|
+
updated_by TEXT
|
|
115
|
+
) WITHOUT ROWID`,
|
|
116
|
+
'CREATE INDEX IF NOT EXISTS _ganju_triggers_table ON _ganju_triggers(table_id, event)',
|
|
117
|
+
`CREATE TABLE IF NOT EXISTS _ganju_changes (
|
|
118
|
+
id INTEGER PRIMARY KEY,
|
|
119
|
+
table_id INTEGER NOT NULL,
|
|
120
|
+
event TEXT NOT NULL,
|
|
121
|
+
row_id INTEGER NOT NULL,
|
|
122
|
+
actor TEXT,
|
|
123
|
+
old TEXT,
|
|
124
|
+
new TEXT
|
|
125
|
+
)`,
|
|
126
|
+
`CREATE TABLE IF NOT EXISTS _ganju_outbox (
|
|
127
|
+
seq INTEGER PRIMARY KEY,
|
|
128
|
+
id TEXT NOT NULL UNIQUE,
|
|
129
|
+
trigger_id TEXT NOT NULL,
|
|
130
|
+
message TEXT NOT NULL,
|
|
131
|
+
created_at TEXT NOT NULL DEFAULT (${dataDdl_1.DATA_NOW_SQL})
|
|
132
|
+
)`
|
|
78
133
|
]
|
|
79
134
|
];
|
|
80
135
|
exports.INTERNAL_SCHEMA_VERSION = exports.INTERNAL_MIGRATIONS.length;
|
|
@@ -158,7 +213,8 @@ const loadSchema = (runner) => {
|
|
|
158
213
|
position: Number(c.position)
|
|
159
214
|
};
|
|
160
215
|
})
|
|
161
|
-
}))
|
|
216
|
+
})),
|
|
217
|
+
timeZone: (0, exports.getMeta)(runner, 'time_zone')
|
|
162
218
|
};
|
|
163
219
|
};
|
|
164
220
|
exports.loadSchema = loadSchema;
|
|
@@ -977,9 +1033,10 @@ const insertValues = (table, values, results, index, timeZone) => {
|
|
|
977
1033
|
// A bot may only point a relation at a row it could read: none in a table
|
|
978
1034
|
// hidden from it, and only its own customer's in a scoped one. Otherwise it
|
|
979
1035
|
// could link an order to another customer and read their name back as the
|
|
980
|
-
// label.
|
|
1036
|
+
// label. A caller held to some tables (a function's `data.tables`) may not
|
|
1037
|
+
// point outside them either.
|
|
981
1038
|
const assertRelationsVisible = (runner, schema, caller, table, values) => {
|
|
982
|
-
if (!caller.restricted)
|
|
1039
|
+
if (!caller.restricted && !caller.tables)
|
|
983
1040
|
return;
|
|
984
1041
|
for (const [name, value] of values) {
|
|
985
1042
|
if (value === null)
|
|
@@ -991,7 +1048,9 @@ const assertRelationsVisible = (runner, schema, caller, table, values) => {
|
|
|
991
1048
|
if (!target)
|
|
992
1049
|
continue;
|
|
993
1050
|
if (!(0, dataCompiler_1.canRead)(caller, target)) {
|
|
994
|
-
throw new dataTypes_1.DataError(
|
|
1051
|
+
throw new dataTypes_1.DataError(caller.restricted
|
|
1052
|
+
? `${table.name}.${name} points at a table the assistant can't use.`
|
|
1053
|
+
: `${table.name}.${name} points at ${target.name}, which isn't one of this caller's tables.`, 'forbidden');
|
|
995
1054
|
}
|
|
996
1055
|
if (!(0, dataCompiler_1.isScoped)(caller, target))
|
|
997
1056
|
continue;
|
|
@@ -1289,6 +1348,8 @@ const write = (runner, schema, caller, rawArgs) => {
|
|
|
1289
1348
|
(0, exports.assertWritable)(runner, caller, addsData);
|
|
1290
1349
|
return runner.transaction(() => {
|
|
1291
1350
|
setContextActor(runner, caller.actor);
|
|
1351
|
+
// Rows left by a change that wasn't a write (a schema change) fire nothing.
|
|
1352
|
+
runner.all('DELETE FROM _ganju_changes');
|
|
1292
1353
|
const results = [];
|
|
1293
1354
|
operations.forEach((op, index) => {
|
|
1294
1355
|
try {
|
|
@@ -1302,6 +1363,7 @@ const write = (runner, schema, caller, rawArgs) => {
|
|
|
1302
1363
|
throw error;
|
|
1303
1364
|
}
|
|
1304
1365
|
});
|
|
1366
|
+
(0, dataTriggers_1.collectTriggerEvents)(runner, schema, caller);
|
|
1305
1367
|
return { ok: true, results };
|
|
1306
1368
|
});
|
|
1307
1369
|
};
|
|
@@ -1654,6 +1716,8 @@ const dropTable = (runner, schema, caller, name) => {
|
|
|
1654
1716
|
dropTriggers(runner, table);
|
|
1655
1717
|
runner.all(`DROP TABLE IF EXISTS ${(0, dataIdentifiers_1.quoteIdentifier)((0, dataDdl_1.ftsTableName)(table))}`);
|
|
1656
1718
|
runner.all(`DROP TABLE ${(0, dataIdentifiers_1.quoteIdentifier)(table.name)}`);
|
|
1719
|
+
// Its triggers go with it; a later table of the same name starts with none.
|
|
1720
|
+
runner.all('DELETE FROM _ganju_triggers WHERE table_id = ?', [table.id]);
|
|
1657
1721
|
runner.all('UPDATE _ganju_tables SET display_column_id = NULL WHERE id = ?', [table.id]);
|
|
1658
1722
|
runner.all('DELETE FROM _ganju_columns WHERE table_id = ?', [table.id]);
|
|
1659
1723
|
runner.all('DELETE FROM _ganju_tables WHERE id = ?', [table.id]);
|
|
@@ -1944,6 +2008,16 @@ const copyTableStep = (runner, schema) => {
|
|
|
1944
2008
|
}
|
|
1945
2009
|
};
|
|
1946
2010
|
exports.copyTableStep = copyTableStep;
|
|
2011
|
+
// Triggers name columns in their conditions and texts, checked only when
|
|
2012
|
+
// saved: a column one of them uses can't be dropped under it.
|
|
2013
|
+
const assertNoTriggerUses = (runner, table, column) => {
|
|
2014
|
+
const triggers = (0, dataTriggers_1.triggersUsingColumn)(runner, table.id, column);
|
|
2015
|
+
if (triggers.length === 0)
|
|
2016
|
+
return;
|
|
2017
|
+
throw new dataTypes_1.DataError(triggers.length === 1
|
|
2018
|
+
? `${table.name}.${column} can't be dropped while the trigger ${triggers[0]} uses it; change or delete that trigger first.`
|
|
2019
|
+
: `${table.name}.${column} can't be dropped while the triggers ${triggers.join(', ')} use it; change or delete those triggers first.`, 'constraint', { triggers });
|
|
2020
|
+
};
|
|
1947
2021
|
const updateColumn = (runner, schema, caller, tableName, columnName, patch) => {
|
|
1948
2022
|
assertDdlAllowed(caller);
|
|
1949
2023
|
const table = tableNamed(schema, tableName);
|
|
@@ -1968,6 +2042,12 @@ const updateColumn = (runner, schema, caller, tableName, columnName, patch) => {
|
|
|
1968
2042
|
throw new dataTypes_1.DataError(`${table.name} already has a column "${draft.name}".`, 'conflict');
|
|
1969
2043
|
}
|
|
1970
2044
|
if ((0, exports.columnChangeNeedsRebuild)(schema, table.name, column.name, patch)) {
|
|
2045
|
+
// A rename renames the column in its triggers too; a copy can't, so the
|
|
2046
|
+
// two go one after the other.
|
|
2047
|
+
const triggers = draft.name !== column.name ? (0, dataTriggers_1.triggersUsingColumn)(runner, table.id, column.name) : [];
|
|
2048
|
+
if (triggers.length) {
|
|
2049
|
+
throw new dataTypes_1.DataError(`${table.name}.${column.name} is used by triggers (${triggers.join(', ')}): rename it on its own, then make the other changes.`, 'constraint', { triggers });
|
|
2050
|
+
}
|
|
1971
2051
|
return rebuildTable(runner, schema, caller, table, table.columns.map(c => ({ draft: c.id === column.id ? draft : c, id: c.id })), { column: column.name, kind: 'change' });
|
|
1972
2052
|
}
|
|
1973
2053
|
return runner.transaction(() => {
|
|
@@ -1975,6 +2055,7 @@ const updateColumn = (runner, schema, caller, tableName, columnName, patch) => {
|
|
|
1975
2055
|
dropTriggers(runner, table);
|
|
1976
2056
|
runner.all(`DROP TABLE IF EXISTS ${(0, dataIdentifiers_1.quoteIdentifier)((0, dataDdl_1.ftsTableName)(table))}`);
|
|
1977
2057
|
runner.all(`ALTER TABLE ${(0, dataIdentifiers_1.quoteIdentifier)(table.name)} RENAME COLUMN ${(0, dataIdentifiers_1.quoteIdentifier)(column.name)} TO ${(0, dataIdentifiers_1.quoteIdentifier)(draft.name)}`);
|
|
2058
|
+
(0, dataTriggers_1.renameColumnInTriggers)(runner, table.id, column.name, draft.name);
|
|
1978
2059
|
}
|
|
1979
2060
|
updateColumnMeta(runner, schema, table, column.id, draft);
|
|
1980
2061
|
touchTable(runner, table.id);
|
|
@@ -1991,6 +2072,7 @@ const dropColumn = (runner, schema, caller, tableName, columnName) => {
|
|
|
1991
2072
|
if (table.columns.length === 1) {
|
|
1992
2073
|
throw new dataTypes_1.DataError(`${table.name} needs at least one column; drop the table instead.`);
|
|
1993
2074
|
}
|
|
2075
|
+
assertNoTriggerUses(runner, table, column.name);
|
|
1994
2076
|
if ((0, exports.dropColumnNeedsRebuild)(schema, table.name, column.name)) {
|
|
1995
2077
|
return rebuildTable(runner, schema, caller, table, table.columns.filter(c => c.id !== column.id).map(c => ({ draft: c, id: c.id })), { column: column.name, kind: 'drop' }, column.id);
|
|
1996
2078
|
}
|
package/dist/dataImport.d.ts
CHANGED
|
@@ -74,4 +74,6 @@ export declare const importRows: (table: Pick<DataTable, "name" | "columns">, ma
|
|
|
74
74
|
lines?: number[];
|
|
75
75
|
}) => ImportedRow[];
|
|
76
76
|
export declare const csvLine: (cells: ImportCell[]) => string;
|
|
77
|
+
export { detectSeparator, parseCsv } from './dataCsv';
|
|
78
|
+
export type { ParsedCsv } from './dataCsv';
|
|
77
79
|
//# sourceMappingURL=dataImport.d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AW,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/dataImport.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.csvLine = exports.importRows = exports.importCell = exports.relationKey = exports.matchHeaders = exports.guessColumns = exports.guessColumnType = exports.columnNameFromHeader = exports.normaliseHeader = exports.parseNumber = exports.detectDecimalMark = exports.DATA_IMPORT_BATCH = exports.DATA_IMPORT_SAMPLE_ROWS = exports.toTableInput = exports.isValidIdentifier = exports.identifierIssue = void 0;
|
|
3
|
+
exports.parseCsv = exports.detectSeparator = exports.csvLine = exports.importRows = exports.importCell = exports.relationKey = exports.matchHeaders = exports.guessColumns = exports.guessColumnType = exports.columnNameFromHeader = exports.normaliseHeader = exports.parseNumber = exports.detectDecimalMark = exports.DATA_IMPORT_BATCH = exports.DATA_IMPORT_SAMPLE_ROWS = exports.toTableInput = exports.isValidIdentifier = exports.identifierIssue = void 0;
|
|
4
4
|
// Reading a spreadsheet into a table: the column types guessed for a new
|
|
5
5
|
// table, the headers matched to an existing one's columns, and each cell
|
|
6
6
|
// checked the way the database will check it. The dashboard's import and
|
|
@@ -448,3 +448,6 @@ const csvLine = (cells) => cells
|
|
|
448
448
|
})
|
|
449
449
|
.join(',');
|
|
450
450
|
exports.csvLine = csvLine;
|
|
451
|
+
var dataCsv_1 = require("./dataCsv");
|
|
452
|
+
Object.defineProperty(exports, "detectSeparator", { enumerable: true, get: function () { return dataCsv_1.detectSeparator; } });
|
|
453
|
+
Object.defineProperty(exports, "parseCsv", { enumerable: true, get: function () { return dataCsv_1.parseCsv; } });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { DataCaller, DataSchema } from './dataTypes';
|
|
2
|
+
import type { SqlRow, SqlRunner } from './dataEngine';
|
|
3
|
+
export declare const DATA_QUERY_PARAM_TYPES: readonly ["text", "integer", "decimal", "boolean", "date", "datetime"];
|
|
4
|
+
export type DataQueryParamType = (typeof DATA_QUERY_PARAM_TYPES)[number];
|
|
5
|
+
export interface DataQueryParam {
|
|
6
|
+
name: string;
|
|
7
|
+
type: DataQueryParamType;
|
|
8
|
+
description?: string | null;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface DataQueryInput {
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string | null;
|
|
14
|
+
sql: string;
|
|
15
|
+
params?: DataQueryParam[];
|
|
16
|
+
assistant?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface DataQuery {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string | null;
|
|
21
|
+
sql: string;
|
|
22
|
+
params: DataQueryParam[];
|
|
23
|
+
assistant: boolean;
|
|
24
|
+
tables: string[];
|
|
25
|
+
plan: string[];
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
updatedBy: string | null;
|
|
28
|
+
}
|
|
29
|
+
export declare const DATA_MAX_QUERIES = 100;
|
|
30
|
+
export declare const DATA_MAX_QUERY_SQL = 10000;
|
|
31
|
+
export declare const DATA_MAX_QUERY_PARAMS = 20;
|
|
32
|
+
export declare const DATA_DEFAULT_QUERY_ROWS = 100;
|
|
33
|
+
export interface CompiledQuerySql {
|
|
34
|
+
sql: string;
|
|
35
|
+
params: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Checks a named query's text and compiles its parameters to positions. Pure:
|
|
39
|
+
* what only SQLite can tell (that it reads, and what) is checked when it is
|
|
40
|
+
* saved, by checkQueryPlan.
|
|
41
|
+
*/
|
|
42
|
+
export declare const compileQuerySql: (sql: unknown) => CompiledQuerySql;
|
|
43
|
+
export interface QueryPlanCheck {
|
|
44
|
+
tables: string[];
|
|
45
|
+
plan: string[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Compiles the statement with EXPLAIN (nothing runs) and checks its program:
|
|
49
|
+
* it may not open anything for writing or start a write transaction, and every
|
|
50
|
+
* table it reads must be one of `schema`'s. Returns those tables and the plan.
|
|
51
|
+
*/
|
|
52
|
+
export declare const checkQueryPlan: (runner: SqlRunner, schema: DataSchema, compiled: CompiledQuerySql) => QueryPlanCheck;
|
|
53
|
+
export declare const listQueries: (runner: SqlRunner) => DataQuery[];
|
|
54
|
+
/**
|
|
55
|
+
* Saves a named query, replacing one by the same name. Refused unless it
|
|
56
|
+
* passes both checks; the tables it reads and its plan are kept with it.
|
|
57
|
+
*/
|
|
58
|
+
export declare const saveQuery: (runner: SqlRunner, schema: DataSchema, caller: DataCaller, input: unknown) => DataQuery;
|
|
59
|
+
export declare const dropQuery: (runner: SqlRunner, name: unknown) => {
|
|
60
|
+
dropped: string;
|
|
61
|
+
};
|
|
62
|
+
export declare const queriesFor: (runner: SqlRunner, schema: DataSchema, caller: DataCaller) => DataQuery[];
|
|
63
|
+
/**
|
|
64
|
+
* Runs a named query with `params`, up to `limit` rows (100 by default, 500 at
|
|
65
|
+
* most) and 1 MB. A query that would scan a table over 200,000 rows is refused
|
|
66
|
+
* before it runs: the database serves one request at a time.
|
|
67
|
+
*/
|
|
68
|
+
export declare const runQuery: (runner: SqlRunner, schema: DataSchema, caller: DataCaller, args: unknown) => {
|
|
69
|
+
truncated?: string | undefined;
|
|
70
|
+
query: string;
|
|
71
|
+
rows: SqlRow[];
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=dataQueries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataQueries.d.ts","sourceRoot":"","sources":["../src/dataQueries.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,UAAU,EAEV,UAAU,EAEX,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEtD,eAAO,MAAM,sBAAsB,wEAOzB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM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