@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
@@ -759,6 +759,7 @@ function TableBody({ connection, schema, table, toolbarStart, defaultWhere, defa
759
759
  onSelectedKeysChange={setSelected}
760
760
  onCommit={commit}
761
761
  loadValue={loadValue}
762
+ onNotice={(notice) => (onNotice === undefined ? setFailure(notice.description ?? notice.title) : onNotice(notice))}
762
763
  sorts={sorts}
763
764
  onSortsChange={changeSorts}
764
765
  onFocusedCellChange={setFocus}
@@ -784,7 +785,7 @@ function TableBody({ connection, schema, table, toolbarStart, defaultWhere, defa
784
785
  selection={selectionFigures}
785
786
  onCount={() => void countRows()}
786
787
  onPrevious={() => goToPage(offset - pageSize)}
787
- onNext={() => goToPage(offset + pageSize)}
788
+ onNext={() => goToPage(bounds.to)}
788
789
  />
789
790
  </>
790
791
  )}
@@ -93,6 +93,7 @@ const SYSTEM_SCHEMAS = ['information_schema', 'mysql', 'performance_schema', 'sy
93
93
  const DEFAULT_ROWS_CELL_LIMIT = 1024;
94
94
  const DEFAULT_EXECUTE_LIMIT = 500;
95
95
  const DEFAULT_EXECUTE_CELL_LIMIT = 65536;
96
+ const DEFAULT_MAX_BYTES = 8388608;
96
97
 
97
98
  const toTables = (database: FakeDatabase): Map<string, Map<string, Table>> =>
98
99
  new Map(
@@ -188,12 +189,25 @@ const toCell = (value: Value, cellLimit: number): Cell => {
188
189
  const toResultColumns = (table: Table): ResultColumn[] =>
189
190
  table.columns.map(({ name, type, kind }) => ({ name, type, kind, source: { schema: table.schema, table: table.name, column: name } }));
190
191
 
191
- const toRowsResult = (table: Table, rows: readonly (readonly Value[])[], offset: number, limit: number, cellLimit: number): RowsResult => ({
192
- columns: toResultColumns(table),
193
- rows: rows.slice(offset, offset + limit).map((row) => row.map((value) => toCell(value, cellLimit))),
194
- hasMore: rows.length > offset + limit,
195
- elapsedMs: 0
196
- });
192
+ /* What the rows of one response may still take, shared by the results of a script as the helper does. */
193
+ interface ByteBudget {
194
+ left: number;
195
+ }
196
+
197
+ const toRowsResult = (table: Table, rows: readonly (readonly Value[])[], offset: number, limit: number, cellLimit: number, budget: ByteBudget): RowsResult => {
198
+ const page: Cell[][] = [];
199
+ for (const row of rows.slice(offset, offset + limit)) {
200
+ const cells = row.map((value) => toCell(value, cellLimit));
201
+ // Characters rather than bytes: near enough for a fake.
202
+ const size = JSON.stringify(cells).length;
203
+ if (page.length > 0 && size > budget.left) {
204
+ return { columns: toResultColumns(table), rows: page, hasMore: true, elapsedMs: 0 };
205
+ }
206
+ budget.left = Math.max(0, budget.left - size);
207
+ page.push(cells);
208
+ }
209
+ return { columns: toResultColumns(table), rows: page, hasMore: rows.length > offset + limit, elapsedMs: 0 };
210
+ };
197
211
 
198
212
  /* Evaluates the default of a column for a row an insert or an update leaves it out of. */
199
213
  const defaultOf = (column: ColumnInfo, table: Table): Value => {
@@ -314,10 +328,10 @@ const selectedTable = (session: Session, sql: string): Table => {
314
328
  return findTable(session, session.schema ?? session.schemas.keys().next().value ?? '', name);
315
329
  };
316
330
 
317
- const runStatement = (session: Session, sql: string, limit: number, cellLimit: number): StatementResult => {
331
+ const runStatement = (session: Session, sql: string, limit: number, cellLimit: number, budget: ByteBudget): StatementResult => {
318
332
  try {
319
333
  const table = selectedTable(session, sql);
320
- return { kind: 'rows', sql, ...toRowsResult(table, table.rows, 0, limit, cellLimit) };
334
+ return { kind: 'rows', sql, ...toRowsResult(table, table.rows, 0, limit, cellLimit, budget) };
321
335
  } catch (error) {
322
336
  if (error instanceof FakeError) {
323
337
  return {
@@ -422,9 +436,9 @@ export const fakeDatabaseTransport = (options: FakeDatabaseTransportOptions): Da
422
436
  ddl: table.ddl
423
437
  };
424
438
  },
425
- rows: ({ session, schema, table: name, offset, limit, cellLimit }) => {
439
+ rows: ({ session, schema, table: name, offset, limit, cellLimit, maxBytes }) => {
426
440
  const table = findTable(sessionOf(session), schema, name);
427
- return toRowsResult(table, table.rows, offset, limit, cellLimit ?? DEFAULT_ROWS_CELL_LIMIT);
441
+ return toRowsResult(table, table.rows, offset, limit, cellLimit ?? DEFAULT_ROWS_CELL_LIMIT, { left: maxBytes ?? DEFAULT_MAX_BYTES });
428
442
  },
429
443
  count: ({ session, schema, table: name }) => ({ count: findTable(sessionOf(session), schema, name).rows.length }),
430
444
  cell: ({ session, schema, table: name, key, column }) => {
@@ -452,17 +466,18 @@ export const fakeDatabaseTransport = (options: FakeDatabaseTransportOptions): Da
452
466
 
453
467
  return { affected: applyChanges(findTable(target, schema, name), changes) };
454
468
  },
455
- execute: ({ session, sql, schema, limit, cellLimit }) => {
469
+ execute: ({ session, sql, schema, limit, cellLimit, maxBytes }) => {
456
470
  const target = sessionOf(session);
457
471
  selectSchema(target, schema);
458
472
 
459
473
  const results: StatementResult[] = [];
474
+ const budget = { left: maxBytes ?? DEFAULT_MAX_BYTES };
460
475
 
461
476
  for (const statement of sql
462
477
  .split(';')
463
478
  .map((part) => part.trim())
464
479
  .filter((part) => part.length > 0)) {
465
- const result = runStatement(target, statement, limit ?? DEFAULT_EXECUTE_LIMIT, cellLimit ?? DEFAULT_EXECUTE_CELL_LIMIT);
480
+ const result = runStatement(target, statement, limit ?? DEFAULT_EXECUTE_LIMIT, cellLimit ?? DEFAULT_EXECUTE_CELL_LIMIT, budget);
466
481
  results.push(result);
467
482
 
468
483
  if (result.kind === 'error') {
@@ -472,11 +487,11 @@ export const fakeDatabaseTransport = (options: FakeDatabaseTransportOptions): Da
472
487
 
473
488
  return { results, inTransaction: target.inTransaction };
474
489
  },
475
- page: ({ session, sql, schema, offset, limit, cellLimit }) => {
490
+ page: ({ session, sql, schema, offset, limit, cellLimit, maxBytes }) => {
476
491
  const target = sessionOf(session);
477
492
  selectSchema(target, schema);
478
493
  const table = selectedTable(target, sql);
479
- return toRowsResult(table, table.rows, offset, limit, cellLimit ?? DEFAULT_EXECUTE_CELL_LIMIT);
494
+ return toRowsResult(table, table.rows, offset, limit, cellLimit ?? DEFAULT_EXECUTE_CELL_LIMIT, { left: maxBytes ?? DEFAULT_MAX_BYTES });
480
495
  },
481
496
  transaction: ({ session, action }) => {
482
497
  const target = sessionOf(session);