@adecore/database 0.23.1 → 0.24.1

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.
Files changed (58) hide show
  1. package/README.md +2 -2
  2. package/dist/client/client.js +31 -11
  3. package/dist/client/types.d.ts +3 -0
  4. package/dist/console/QueryConsole.js +8 -10
  5. package/dist/console/SqlEditor.js +5 -10
  6. package/dist/console/StatementResultView.d.ts +3 -1
  7. package/dist/console/StatementResultView.js +5 -2
  8. package/dist/console/shortcuts.d.ts +3 -0
  9. package/dist/console/shortcuts.js +14 -3
  10. package/dist/grid/DataGrid.d.ts +3 -1
  11. package/dist/grid/DataGrid.js +35 -22
  12. package/dist/grid/GridRowView.js +2 -2
  13. package/dist/grid/RecordView.js +2 -2
  14. package/dist/grid/display.d.ts +2 -0
  15. package/dist/grid/display.js +11 -0
  16. package/dist/grid/whole-cells.d.ts +9 -0
  17. package/dist/grid/whole-cells.js +49 -0
  18. package/dist/host/helper-path.d.ts +2 -1
  19. package/dist/host/helper-path.js +26 -5
  20. package/dist/host/host.js +5 -0
  21. package/dist/host/validate.js +8 -3
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/locales/en.d.ts +601 -0
  25. package/dist/locales/en.js +600 -0
  26. package/dist/locales/nl.d.ts +601 -0
  27. package/dist/locales/nl.js +600 -0
  28. package/dist/locales.js +3 -2
  29. package/dist/protocol/messages.d.ts +4 -1
  30. package/dist/protocol/messages.js +1 -1
  31. package/dist/table/TableView.js +1 -1
  32. package/dist/testing/fake.js +24 -14
  33. package/package.json +8 -8
  34. package/src/client/client.ts +32 -11
  35. package/src/client/types.ts +10 -2
  36. package/src/console/QueryConsole.tsx +10 -9
  37. package/src/console/SqlEditor.tsx +5 -10
  38. package/src/console/StatementResultView.tsx +15 -1
  39. package/src/console/shortcuts.ts +16 -3
  40. package/src/grid/DataGrid.tsx +47 -24
  41. package/src/grid/GridRowView.tsx +2 -2
  42. package/src/grid/RecordView.tsx +2 -2
  43. package/src/grid/display.ts +13 -0
  44. package/src/grid/whole-cells.ts +72 -0
  45. package/src/host/helper-path.ts +42 -4
  46. package/src/host/host.ts +6 -0
  47. package/src/host/validate.ts +9 -3
  48. package/src/index.ts +1 -0
  49. package/src/locales/en.ts +600 -0
  50. package/src/locales/nl.ts +600 -0
  51. package/src/locales.ts +3 -2
  52. package/src/protocol/messages.ts +21 -4
  53. package/src/table/TableView.tsx +2 -1
  54. package/src/testing/fake.ts +29 -14
  55. package/dist/locales/en.json +0 -594
  56. package/dist/locales/nl.json +0 -594
  57. package/src/locales/en.json +0 -594
  58. package/src/locales/nl.json +0 -594
@@ -1,7 +1,8 @@
1
1
  export interface HelperPathOptions {
2
2
  readonly platform?: string;
3
3
  readonly arch?: string;
4
+ readonly env?: Readonly<Record<string, string | undefined>>;
4
5
  readonly resolve?: (specifier: string) => string;
5
6
  readonly exists?: (path: string) => boolean;
6
7
  }
7
- export declare const helperPath: ({ platform, arch, resolve, exists }?: HelperPathOptions) => string | null;
8
+ export declare const helperPath: ({ platform, arch, env, resolve, exists }?: HelperPathOptions) => string | null;
@@ -1,15 +1,27 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { createRequire } from 'node:module';
3
3
  import { dirname, join, sep } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
4
5
  /*
5
- * Finds the prebuilt helper that npm installed for this machine, in the `@adecore/database-<platform>-<arch>`
6
- * package, or null when there is none: an unsupported platform, or an install with optional dependencies off.
6
+ * Finds the helper for this machine, or null when there is none. In order: the path in `ADECORE_DATABASE_HELPER`;
7
+ * the prebuilt binary npm installed in the `@adecore/database-<platform>-<arch>` package, absent on an
8
+ * unsupported platform or an install with optional dependencies off; and, when the package runs from the `src`
9
+ * of a checkout, the release build `helper:build` leaves in that checkout.
7
10
  *
8
11
  * A binary cannot run from inside an Electron archive. The path is mapped from `app.asar` to
9
12
  * `app.asar.unpacked`, so the app must unpack the packages (electron-builder: `asarUnpack` with
10
13
  * `node_modules/@adecore/database-*` followed by `/**`).
11
14
  */
12
- export const helperPath = ({ platform = process.platform, arch = process.arch, resolve = (specifier) => createRequire(import.meta.url).resolve(specifier), exists = existsSync } = {}) => {
15
+ export const helperPath = ({ platform = process.platform, arch = process.arch, env = process.env, resolve = (specifier) => createRequire(import.meta.url).resolve(specifier), exists = existsSync } = {}) => {
16
+ const override = env.ADECORE_DATABASE_HELPER;
17
+ // Not checked for existence: a wrong override fails loudly at spawn instead of quietly running another helper.
18
+ if (override) {
19
+ return override;
20
+ }
21
+ const binary = platform === 'win32' ? 'adecore-database.exe' : 'adecore-database';
22
+ return packagedHelper(platform, arch, binary, resolve, exists) ?? checkoutHelper(binary, exists);
23
+ };
24
+ const packagedHelper = (platform, arch, binary, resolve, exists) => {
13
25
  let manifest;
14
26
  try {
15
27
  manifest = resolve(`@adecore/database-${platform}-${arch}/package.json`);
@@ -17,7 +29,16 @@ export const helperPath = ({ platform = process.platform, arch = process.arch, r
17
29
  catch {
18
30
  return null;
19
31
  }
20
- const binary = join(dirname(manifest), 'bin', platform === 'win32' ? 'adecore-database.exe' : 'adecore-database');
21
- const unpacked = binary.replace(`.asar${sep}`, `.asar.unpacked${sep}`);
32
+ const unpacked = join(dirname(manifest), 'bin', binary).replace(`.asar${sep}`, `.asar.unpacked${sep}`);
22
33
  return exists(unpacked) ? unpacked : null;
23
34
  };
35
+ // The published package ships `src` without `helper`, so `Cargo.toml` is what tells a checkout apart from an install.
36
+ const checkoutHelper = (binary, exists) => {
37
+ const here = new URL('.', import.meta.url);
38
+ if (here.protocol !== 'file:' || !here.pathname.endsWith('/src/host/')) {
39
+ return null;
40
+ }
41
+ const helper = new URL('../../helper/', here);
42
+ const built = fileURLToPath(new URL(`target/release/${binary}`, helper));
43
+ return exists(fileURLToPath(new URL('Cargo.toml', helper))) && exists(built) ? built : null;
44
+ };
package/dist/host/host.js CHANGED
@@ -237,6 +237,11 @@ export const createDatabaseHost = (options) => {
237
237
  if (request.method === 'close') {
238
238
  sessions.delete(request.params.session);
239
239
  }
240
+ // The helper ends a session whose connection to the server was lost.
241
+ const target = sessionOf(request);
242
+ if (target !== null && !response.ok && response.error.code === 'unknown-session') {
243
+ sessions.delete(target);
244
+ }
240
245
  if (request.method !== 'open' || !response.ok) {
241
246
  return { ...response, id: request.id };
242
247
  }
@@ -1,6 +1,7 @@
1
1
  const MAX_ID_LENGTH = 200;
2
2
  const MAX_LIMIT = 10000;
3
3
  const MAX_CELL_LIMIT = 1048576;
4
+ const MAX_BYTES = 67108864;
4
5
  const TLS_MODES = ['disable', 'prefer', 'require', 'verify'];
5
6
  const TRANSACTION_ACTIONS = ['begin', 'commit', 'rollback'];
6
7
  const EXPORT_FORMATS = ['csv', 'tsv', 'json', 'sql'];
@@ -201,6 +202,7 @@ const exportSource = (input, label) => {
201
202
  fail(`"${label}.kind" must be "table" or "query".`);
202
203
  };
203
204
  const cellLimit = (params) => optional(params, 'cellLimit', 'params', (limit, name) => integer(limit, name, 1, MAX_CELL_LIMIT));
205
+ const maxBytes = (params) => optional(params, 'maxBytes', 'params', (limit, name) => integer(limit, name, 1, MAX_BYTES));
204
206
  const table = (params) => {
205
207
  filledText(params.session, 'params.session');
206
208
  filledText(params.schema, 'params.schema');
@@ -219,13 +221,14 @@ const PARAMS = {
219
221
  },
220
222
  structure: (input) => table(shape(input, 'params', TARGET)),
221
223
  rows: (input) => {
222
- const params = shape(input, 'params', [...TARGET, 'offset', 'limit'], ['where', 'orderBy', 'cellLimit']);
224
+ const params = shape(input, 'params', [...TARGET, 'offset', 'limit'], ['where', 'orderBy', 'cellLimit', 'maxBytes']);
223
225
  table(params);
224
226
  optional(params, 'where', 'params', anyText);
225
227
  optional(params, 'orderBy', 'params', anyText);
226
228
  integer(params.offset, 'params.offset', 0, Number.MAX_SAFE_INTEGER);
227
229
  integer(params.limit, 'params.limit', 1, MAX_LIMIT);
228
230
  cellLimit(params);
231
+ maxBytes(params);
229
232
  },
230
233
  count: (input) => {
231
234
  const params = shape(input, 'params', TARGET, ['where']);
@@ -248,21 +251,23 @@ const PARAMS = {
248
251
  params.changes.forEach((change, i) => rowChange(change, `params.changes[${i}]`));
249
252
  },
250
253
  execute: (input) => {
251
- const params = shape(input, 'params', ['session', 'sql'], ['schema', 'limit', 'cellLimit']);
254
+ const params = shape(input, 'params', ['session', 'sql'], ['schema', 'limit', 'cellLimit', 'maxBytes']);
252
255
  filledText(params.session, 'params.session');
253
256
  filledText(params.sql, 'params.sql');
254
257
  optional(params, 'schema', 'params', filledText);
255
258
  optional(params, 'limit', 'params', (limit, name) => integer(limit, name, 1, MAX_LIMIT));
256
259
  cellLimit(params);
260
+ maxBytes(params);
257
261
  },
258
262
  page: (input) => {
259
- const params = shape(input, 'params', ['session', 'sql', 'offset', 'limit'], ['schema', 'cellLimit']);
263
+ const params = shape(input, 'params', ['session', 'sql', 'offset', 'limit'], ['schema', 'cellLimit', 'maxBytes']);
260
264
  filledText(params.session, 'params.session');
261
265
  filledText(params.sql, 'params.sql');
262
266
  optional(params, 'schema', 'params', filledText);
263
267
  integer(params.offset, 'params.offset', 0, Number.MAX_SAFE_INTEGER);
264
268
  integer(params.limit, 'params.limit', 1, MAX_LIMIT);
265
269
  cellLimit(params);
270
+ maxBytes(params);
266
271
  },
267
272
  transaction: (input) => {
268
273
  const params = shape(input, 'params', ['session', 'action']);
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export { useDatabaseClient } from './client-context.ts';
12
12
  export type { NumberNotation } from './grid/display.ts';
13
13
  export { QueryConsole, type QueryConsoleProps } from './console/QueryConsole.tsx';
14
14
  export type { QueryConsoleEditorHandle, QueryConsoleEditorProps, QueryConsoleRunScope } from './console/editor-slot.ts';
15
+ export { RUN_ALL_SHORTCUT, RUN_SHORTCUT, runScopeOf } from './console/shortcuts.ts';
15
16
  export { StructureView, type StructureViewProps } from './structure/StructureView.tsx';
16
17
  export { TableView, type TableViewProps } from './table/TableView.tsx';
17
18
  export { DatabaseWorkbench, type DatabaseWorkbenchProps } from './workbench/DatabaseWorkbench.tsx';
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ export { TableDesigner } from './designer/TableDesigner.js';
9
9
  export { DatabaseProvider } from './DatabaseProvider.js';
10
10
  export { useDatabaseClient } from './client-context.js';
11
11
  export { QueryConsole } from './console/QueryConsole.js';
12
+ export { RUN_ALL_SHORTCUT, RUN_SHORTCUT, runScopeOf } from './console/shortcuts.js';
12
13
  export { StructureView } from './structure/StructureView.js';
13
14
  export { TableView } from './table/TableView.js';
14
15
  export { DatabaseWorkbench } from './workbench/DatabaseWorkbench.js';