@adecore/database 0.0.1 → 0.16.0-beta.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/LICENSE +21 -0
- package/README.md +152 -1
- package/dist/DatabaseProvider.d.ts +13 -0
- package/dist/DatabaseProvider.js +17 -0
- package/dist/actions.d.ts +40 -0
- package/dist/actions.js +1 -0
- package/dist/client/client.d.ts +5 -0
- package/dist/client/client.js +245 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/types.d.ts +97 -0
- package/dist/client/types.js +13 -0
- package/dist/client-context.d.ts +16 -0
- package/dist/client-context.js +17 -0
- package/dist/connections/ConnectionForm.d.ts +10 -0
- package/dist/connections/ConnectionForm.js +145 -0
- package/dist/connections/ConnectionManager.d.ts +12 -0
- package/dist/connections/ConnectionManager.js +93 -0
- package/dist/connections/EngineIcon.d.ts +9 -0
- package/dist/connections/EngineIcon.js +7 -0
- package/dist/connections/connection-config.d.ts +16 -0
- package/dist/connections/connection-config.js +107 -0
- package/dist/connections/docker.d.ts +9 -0
- package/dist/connections/docker.js +38 -0
- package/dist/connections/engine-icons.d.ts +3 -0
- package/dist/connections/engine-icons.js +3 -0
- package/dist/connections/use-docker-containers.d.ts +17 -0
- package/dist/connections/use-docker-containers.js +26 -0
- package/dist/console/DestructiveDialog.d.ts +9 -0
- package/dist/console/DestructiveDialog.js +9 -0
- package/dist/console/HistoryPanel.d.ts +10 -0
- package/dist/console/HistoryPanel.js +15 -0
- package/dist/console/QueryConsole.d.ts +14 -0
- package/dist/console/QueryConsole.js +261 -0
- package/dist/console/SchemaPicker.d.ts +11 -0
- package/dist/console/SchemaPicker.js +8 -0
- package/dist/console/SqlEditor.d.ts +12 -0
- package/dist/console/SqlEditor.js +61 -0
- package/dist/console/StatementResultView.d.ts +18 -0
- package/dist/console/StatementResultView.js +32 -0
- package/dist/console/TransactionControls.d.ts +13 -0
- package/dist/console/TransactionControls.js +12 -0
- package/dist/console/destructive.d.ts +7 -0
- package/dist/console/destructive.js +43 -0
- package/dist/console/editing.d.ts +12 -0
- package/dist/console/editing.js +60 -0
- package/dist/console/history.d.ts +13 -0
- package/dist/console/history.js +43 -0
- package/dist/console/labels.d.ts +1 -0
- package/dist/console/labels.js +6 -0
- package/dist/console/outcome.d.ts +6 -0
- package/dist/console/outcome.js +11 -0
- package/dist/console/schemas.d.ts +2 -0
- package/dist/console/schemas.js +5 -0
- package/dist/console/shortcuts.d.ts +2 -0
- package/dist/console/shortcuts.js +3 -0
- package/dist/console/useConsoleHistory.d.ts +7 -0
- package/dist/console/useConsoleHistory.js +22 -0
- package/dist/ddl/alter-mysql.d.ts +4 -0
- package/dist/ddl/alter-mysql.js +79 -0
- package/dist/ddl/alter-sqlite.d.ts +4 -0
- package/dist/ddl/alter-sqlite.js +80 -0
- package/dist/ddl/alter.d.ts +4 -0
- package/dist/ddl/alter.js +24 -0
- package/dist/ddl/column.d.ts +9 -0
- package/dist/ddl/column.js +62 -0
- package/dist/ddl/create.d.ts +12 -0
- package/dist/ddl/create.js +74 -0
- package/dist/ddl/dialect.d.ts +12 -0
- package/dist/ddl/dialect.js +34 -0
- package/dist/ddl/diff.d.ts +34 -0
- package/dist/ddl/diff.js +111 -0
- package/dist/ddl/draft.d.ts +46 -0
- package/dist/ddl/draft.js +70 -0
- package/dist/ddl/index.d.ts +10 -0
- package/dist/ddl/index.js +10 -0
- package/dist/ddl/parse.d.ts +17 -0
- package/dist/ddl/parse.js +131 -0
- package/dist/ddl/statements.d.ts +6 -0
- package/dist/ddl/statements.js +12 -0
- package/dist/ddl/types.d.ts +6 -0
- package/dist/ddl/types.js +52 -0
- package/dist/ddl/validate.d.ts +7 -0
- package/dist/ddl/validate.js +38 -0
- package/dist/designer/ColumnsEditor.d.ts +2 -0
- package/dist/designer/ColumnsEditor.js +24 -0
- package/dist/designer/DesignerView.d.ts +25 -0
- package/dist/designer/DesignerView.js +33 -0
- package/dist/designer/ForeignKeysEditor.d.ts +7 -0
- package/dist/designer/ForeignKeysEditor.js +24 -0
- package/dist/designer/IndexesEditor.d.ts +2 -0
- package/dist/designer/IndexesEditor.js +13 -0
- package/dist/designer/NamePicker.d.ts +11 -0
- package/dist/designer/NamePicker.js +13 -0
- package/dist/designer/OptionsEditor.d.ts +2 -0
- package/dist/designer/OptionsEditor.js +17 -0
- package/dist/designer/SqlPreview.d.ts +12 -0
- package/dist/designer/SqlPreview.js +17 -0
- package/dist/designer/TableDesigner.d.ts +10 -0
- package/dist/designer/TableDesigner.js +103 -0
- package/dist/designer/edit.d.ts +17 -0
- package/dist/designer/edit.js +115 -0
- package/dist/designer/editor-props.d.ts +10 -0
- package/dist/designer/editor-props.js +1 -0
- package/dist/designer/plan.d.ts +9 -0
- package/dist/designer/plan.js +13 -0
- package/dist/designer/recover.d.ts +2 -0
- package/dist/designer/recover.js +18 -0
- package/dist/designer/useReferenceColumns.d.ts +3 -0
- package/dist/designer/useReferenceColumns.js +36 -0
- package/dist/explorer/DatabaseExplorer.d.ts +13 -0
- package/dist/explorer/DatabaseExplorer.js +264 -0
- package/dist/explorer/RowMenu.d.ts +11 -0
- package/dist/explorer/RowMenu.js +89 -0
- package/dist/explorer/TableDialog.d.ts +15 -0
- package/dist/explorer/TableDialog.js +50 -0
- package/dist/explorer/expansion.d.ts +7 -0
- package/dist/explorer/expansion.js +31 -0
- package/dist/explorer/table-statements.d.ts +5 -0
- package/dist/explorer/table-statements.js +12 -0
- package/dist/explorer/tree.d.ts +125 -0
- package/dist/explorer/tree.js +295 -0
- package/dist/explorer/use-explorer-loads.d.ts +12 -0
- package/dist/explorer/use-explorer-loads.js +109 -0
- package/dist/explorer/use-stored-expansion.d.ts +9 -0
- package/dist/explorer/use-stored-expansion.js +47 -0
- package/dist/grid/CellEditor.d.ts +9 -0
- package/dist/grid/CellEditor.js +29 -0
- package/dist/grid/CopyAsMenu.d.ts +7 -0
- package/dist/grid/CopyAsMenu.js +10 -0
- package/dist/grid/DataGrid.d.ts +36 -0
- package/dist/grid/DataGrid.js +512 -0
- package/dist/grid/EnumPicker.d.ts +17 -0
- package/dist/grid/EnumPicker.js +53 -0
- package/dist/grid/GridHeaderCell.d.ts +36 -0
- package/dist/grid/GridHeaderCell.js +69 -0
- package/dist/grid/RecordView.d.ts +20 -0
- package/dist/grid/RecordView.js +126 -0
- package/dist/grid/ValueDock.d.ts +11 -0
- package/dist/grid/ValueDock.js +28 -0
- package/dist/grid/aggregates.d.ts +22 -0
- package/dist/grid/aggregates.js +62 -0
- package/dist/grid/cell-range.d.ts +14 -0
- package/dist/grid/cell-range.js +11 -0
- package/dist/grid/column-layout.d.ts +18 -0
- package/dist/grid/column-layout.js +49 -0
- package/dist/grid/column-selection.d.ts +11 -0
- package/dist/grid/column-selection.js +28 -0
- package/dist/grid/column-view.d.ts +10 -0
- package/dist/grid/column-view.js +23 -0
- package/dist/grid/copy-formats.d.ts +15 -0
- package/dist/grid/copy-formats.js +80 -0
- package/dist/grid/display.d.ts +20 -0
- package/dist/grid/display.js +81 -0
- package/dist/grid/edit-value.d.ts +5 -0
- package/dist/grid/edit-value.js +55 -0
- package/dist/grid/enum-type.d.ts +7 -0
- package/dist/grid/enum-type.js +52 -0
- package/dist/grid/focused-value.d.ts +4 -0
- package/dist/grid/focused-value.js +19 -0
- package/dist/grid/layout.d.ts +22 -0
- package/dist/grid/layout.js +74 -0
- package/dist/grid/navigation.d.ts +15 -0
- package/dist/grid/navigation.js +52 -0
- package/dist/grid/row-selection.d.ts +9 -0
- package/dist/grid/row-selection.js +24 -0
- package/dist/grid/sort.d.ts +7 -0
- package/dist/grid/sort.js +7 -0
- package/dist/grid/types.d.ts +30 -0
- package/dist/grid/types.js +9 -0
- package/dist/host/helper-path.d.ts +7 -0
- package/dist/host/helper-path.js +15 -0
- package/dist/host/host.d.ts +2 -0
- package/dist/host/host.js +343 -0
- package/dist/host/index.d.ts +5 -0
- package/dist/host/index.js +4 -0
- package/dist/host/spawn.d.ts +7 -0
- package/dist/host/spawn.js +98 -0
- package/dist/host/types.d.ts +19 -0
- package/dist/host/types.js +1 -0
- package/dist/host/validate.d.ts +10 -0
- package/dist/host/validate.js +339 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -0
- package/dist/locales/en.json +577 -0
- package/dist/locales/nl.json +577 -0
- package/dist/locales.d.ts +4 -0
- package/dist/locales.js +14 -0
- package/dist/protocol/connection.d.ts +56 -0
- package/dist/protocol/connection.js +1 -0
- package/dist/protocol/errors.d.ts +7 -0
- package/dist/protocol/errors.js +1 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/index.js +3 -0
- package/dist/protocol/messages.d.ts +250 -0
- package/dist/protocol/messages.js +2 -0
- package/dist/protocol/schema.d.ts +53 -0
- package/dist/protocol/schema.js +1 -0
- package/dist/protocol/values.d.ts +21 -0
- package/dist/protocol/values.js +15 -0
- package/dist/sql-split.d.ts +15 -0
- package/dist/sql-split.js +201 -0
- package/dist/sql.d.ts +29 -0
- package/dist/sql.js +104 -0
- package/dist/structure/StructureView.d.ts +14 -0
- package/dist/structure/StructureView.js +99 -0
- package/dist/structure/structure-text.d.ts +2 -0
- package/dist/structure/structure-text.js +2 -0
- package/dist/table/CommandField.d.ts +14 -0
- package/dist/table/CommandField.js +157 -0
- package/dist/table/ImportDialog.d.ts +27 -0
- package/dist/table/ImportDialog.js +28 -0
- package/dist/table/TableStatusBar.d.ts +19 -0
- package/dist/table/TableStatusBar.js +22 -0
- package/dist/table/TableToolbar.d.ts +43 -0
- package/dist/table/TableToolbar.js +16 -0
- package/dist/table/TableView.d.ts +13 -0
- package/dist/table/TableView.js +508 -0
- package/dist/table/command-field.d.ts +57 -0
- package/dist/table/command-field.js +203 -0
- package/dist/table/grid-rows.d.ts +23 -0
- package/dist/table/grid-rows.js +55 -0
- package/dist/table/import-mapping.d.ts +7 -0
- package/dist/table/import-mapping.js +28 -0
- package/dist/table/layout-store.d.ts +13 -0
- package/dist/table/layout-store.js +43 -0
- package/dist/table/paging.d.ts +12 -0
- package/dist/table/paging.js +20 -0
- package/dist/table/pending.d.ts +32 -0
- package/dist/table/pending.js +94 -0
- package/dist/table/references.d.ts +12 -0
- package/dist/table/references.js +21 -0
- package/dist/table/useLoaded.d.ts +7 -0
- package/dist/table/useLoaded.js +36 -0
- package/dist/table/useStoredLayout.d.ts +8 -0
- package/dist/table/useStoredLayout.js +39 -0
- package/dist/table/useTableTransfer.d.ts +51 -0
- package/dist/table/useTableTransfer.js +125 -0
- package/dist/testing/fake.d.ts +21 -0
- package/dist/testing/fake.js +372 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +1 -0
- package/dist/use-popup-press.d.ts +1 -0
- package/dist/use-popup-press.js +24 -0
- package/dist/use-schema-change.d.ts +1 -0
- package/dist/use-schema-change.js +13 -0
- package/dist/use-stable-callback.d.ts +1 -0
- package/dist/use-stable-callback.js +9 -0
- package/dist/value/ValuePanel.d.ts +14 -0
- package/dist/value/ValuePanel.js +103 -0
- package/dist/value/draft.d.ts +33 -0
- package/dist/value/draft.js +44 -0
- package/dist/value/hex.d.ts +14 -0
- package/dist/value/hex.js +46 -0
- package/dist/value/json.d.ts +9 -0
- package/dist/value/json.js +71 -0
- package/dist/value/views.d.ts +22 -0
- package/dist/value/views.js +54 -0
- package/dist/workbench/DatabaseWorkbench.d.ts +9 -0
- package/dist/workbench/DatabaseWorkbench.js +179 -0
- package/dist/workbench/DesignerTab.d.ts +10 -0
- package/dist/workbench/DesignerTab.js +22 -0
- package/dist/workbench/TableTab.d.ts +10 -0
- package/dist/workbench/TableTab.js +8 -0
- package/dist/workbench/tabs.d.ts +42 -0
- package/dist/workbench/tabs.js +139 -0
- package/package.json +79 -3
- package/src/DatabaseProvider.tsx +37 -0
- package/src/actions.ts +34 -0
- package/src/client/client.ts +324 -0
- package/src/client/index.ts +18 -0
- package/src/client/types.ts +161 -0
- package/src/client-context.ts +35 -0
- package/src/connections/ConnectionForm.tsx +474 -0
- package/src/connections/ConnectionManager.tsx +224 -0
- package/src/connections/EngineIcon.tsx +18 -0
- package/src/connections/connection-config.ts +143 -0
- package/src/connections/docker.ts +50 -0
- package/src/connections/engine-icons.ts +5 -0
- package/src/connections/use-docker-containers.ts +41 -0
- package/src/console/DestructiveDialog.tsx +40 -0
- package/src/console/HistoryPanel.tsx +67 -0
- package/src/console/QueryConsole.tsx +439 -0
- package/src/console/SchemaPicker.tsx +32 -0
- package/src/console/SqlEditor.tsx +95 -0
- package/src/console/StatementResultView.tsx +176 -0
- package/src/console/TransactionControls.tsx +53 -0
- package/src/console/destructive.ts +60 -0
- package/src/console/editing.ts +77 -0
- package/src/console/history.ts +62 -0
- package/src/console/labels.ts +7 -0
- package/src/console/outcome.ts +14 -0
- package/src/console/schemas.ts +7 -0
- package/src/console/shortcuts.ts +4 -0
- package/src/console/useConsoleHistory.ts +39 -0
- package/src/ddl/alter-mysql.ts +90 -0
- package/src/ddl/alter-sqlite.ts +93 -0
- package/src/ddl/alter.ts +29 -0
- package/src/ddl/column.ts +74 -0
- package/src/ddl/create.ts +92 -0
- package/src/ddl/dialect.ts +53 -0
- package/src/ddl/diff.ts +164 -0
- package/src/ddl/draft.ts +136 -0
- package/src/ddl/index.ts +10 -0
- package/src/ddl/parse.ts +161 -0
- package/src/ddl/statements.ts +20 -0
- package/src/ddl/types.ts +60 -0
- package/src/ddl/validate.ts +47 -0
- package/src/designer/ColumnsEditor.tsx +204 -0
- package/src/designer/DesignerView.tsx +184 -0
- package/src/designer/ForeignKeysEditor.tsx +132 -0
- package/src/designer/IndexesEditor.tsx +63 -0
- package/src/designer/NamePicker.tsx +44 -0
- package/src/designer/OptionsEditor.tsx +101 -0
- package/src/designer/SqlPreview.tsx +56 -0
- package/src/designer/TableDesigner.tsx +186 -0
- package/src/designer/edit.ts +137 -0
- package/src/designer/editor-props.ts +13 -0
- package/src/designer/plan.ts +25 -0
- package/src/designer/recover.ts +20 -0
- package/src/designer/useReferenceColumns.ts +54 -0
- package/src/explorer/DatabaseExplorer.tsx +450 -0
- package/src/explorer/RowMenu.tsx +134 -0
- package/src/explorer/TableDialog.tsx +80 -0
- package/src/explorer/expansion.ts +47 -0
- package/src/explorer/table-statements.ts +18 -0
- package/src/explorer/tree.ts +453 -0
- package/src/explorer/use-explorer-loads.ts +157 -0
- package/src/explorer/use-stored-expansion.ts +66 -0
- package/src/grid/CellEditor.tsx +53 -0
- package/src/grid/CopyAsMenu.tsx +33 -0
- package/src/grid/DataGrid.tsx +871 -0
- package/src/grid/EnumPicker.tsx +108 -0
- package/src/grid/GridHeaderCell.tsx +243 -0
- package/src/grid/RecordView.tsx +293 -0
- package/src/grid/ValueDock.tsx +52 -0
- package/src/grid/aggregates.ts +94 -0
- package/src/grid/cell-range.ts +26 -0
- package/src/grid/column-layout.ts +71 -0
- package/src/grid/column-selection.ts +42 -0
- package/src/grid/column-view.ts +35 -0
- package/src/grid/copy-formats.ts +108 -0
- package/src/grid/display.ts +109 -0
- package/src/grid/edit-value.ts +60 -0
- package/src/grid/enum-type.ts +62 -0
- package/src/grid/focused-value.ts +23 -0
- package/src/grid/layout.ts +91 -0
- package/src/grid/navigation.ts +74 -0
- package/src/grid/row-selection.ts +35 -0
- package/src/grid/sort.ts +12 -0
- package/src/grid/types.ts +59 -0
- package/src/host/helper-path.ts +41 -0
- package/src/host/host.ts +456 -0
- package/src/host/index.ts +5 -0
- package/src/host/spawn.ts +124 -0
- package/src/host/types.ts +46 -0
- package/src/host/validate.ts +402 -0
- package/src/index.ts +37 -0
- package/src/locales/en.json +577 -0
- package/src/locales/nl.json +577 -0
- package/src/locales.ts +18 -0
- package/src/protocol/connection.ts +86 -0
- package/src/protocol/errors.ts +38 -0
- package/src/protocol/index.ts +33 -0
- package/src/protocol/messages.ts +168 -0
- package/src/protocol/schema.ts +76 -0
- package/src/protocol/values.ts +52 -0
- package/src/sql-split.ts +220 -0
- package/src/sql.ts +152 -0
- package/src/structure/StructureView.tsx +269 -0
- package/src/structure/structure-text.ts +4 -0
- package/src/table/CommandField.tsx +318 -0
- package/src/table/ImportDialog.tsx +168 -0
- package/src/table/TableStatusBar.tsx +91 -0
- package/src/table/TableToolbar.tsx +217 -0
- package/src/table/TableView.tsx +880 -0
- package/src/table/command-field.ts +285 -0
- package/src/table/grid-rows.ts +80 -0
- package/src/table/import-mapping.ts +37 -0
- package/src/table/layout-store.ts +62 -0
- package/src/table/paging.ts +33 -0
- package/src/table/pending.ts +143 -0
- package/src/table/references.ts +38 -0
- package/src/table/useLoaded.ts +58 -0
- package/src/table/useStoredLayout.ts +53 -0
- package/src/table/useTableTransfer.ts +187 -0
- package/src/testing/fake.ts +533 -0
- package/src/testing/index.ts +1 -0
- package/src/use-popup-press.ts +27 -0
- package/src/use-schema-change.ts +19 -0
- package/src/use-stable-callback.ts +12 -0
- package/src/value/ValuePanel.tsx +254 -0
- package/src/value/draft.ts +72 -0
- package/src/value/hex.ts +62 -0
- package/src/value/json.ts +74 -0
- package/src/value/views.ts +68 -0
- package/src/workbench/DatabaseWorkbench.tsx +348 -0
- package/src/workbench/DesignerTab.tsx +37 -0
- package/src/workbench/TableTab.tsx +27 -0
- package/src/workbench/tabs.ts +184 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
const MAX_ID_LENGTH = 200;
|
|
2
|
+
const MAX_LIMIT = 10000;
|
|
3
|
+
const MAX_CELL_LIMIT = 1048576;
|
|
4
|
+
const TLS_MODES = ['disable', 'prefer', 'require', 'verify'];
|
|
5
|
+
const TRANSACTION_ACTIONS = ['begin', 'commit', 'rollback'];
|
|
6
|
+
const EXPORT_FORMATS = ['csv', 'tsv', 'json', 'sql'];
|
|
7
|
+
const DELIMITED_FORMATS = ['csv', 'tsv'];
|
|
8
|
+
const HEX = /^(?:[0-9a-f]{2})*$/;
|
|
9
|
+
const ABSOLUTE_PATH = /^(?:\/|[A-Za-z]:[\\/]|\\\\)/;
|
|
10
|
+
class InvalidRequest extends Error {
|
|
11
|
+
}
|
|
12
|
+
const fail = (message) => {
|
|
13
|
+
throw new InvalidRequest(message);
|
|
14
|
+
};
|
|
15
|
+
const isDict = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
16
|
+
/* Rejects a key nobody asked for, so a typo cannot pass for an option the helper ignores. */
|
|
17
|
+
const shape = (value, label, required, optional = []) => {
|
|
18
|
+
if (!isDict(value)) {
|
|
19
|
+
return fail(`"${label}" must be an object.`);
|
|
20
|
+
}
|
|
21
|
+
for (const key of Object.keys(value)) {
|
|
22
|
+
if (!required.includes(key) && !optional.includes(key)) {
|
|
23
|
+
fail(`"${label}" has an unknown key "${key}".`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const key of required) {
|
|
27
|
+
if (value[key] === undefined) {
|
|
28
|
+
fail(`"${label}" needs "${key}".`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
const text = (value, label) => {
|
|
34
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
35
|
+
fail(`"${label}" must be a non-empty string.`);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const plainText = (value, label) => {
|
|
39
|
+
if (typeof value !== 'string') {
|
|
40
|
+
fail(`"${label}" must be a string.`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const flag = (value, label) => {
|
|
44
|
+
if (typeof value !== 'boolean') {
|
|
45
|
+
fail(`"${label}" must be true or false.`);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const integer = (value, label, min, max) => {
|
|
49
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < min || value > max) {
|
|
50
|
+
fail(`"${label}" must be an integer from ${min} to ${max}.`);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const oneOf = (allowed) => (value, label) => {
|
|
54
|
+
if (typeof value !== 'string' || !allowed.includes(value)) {
|
|
55
|
+
fail(`"${label}" must be one of ${allowed.join(', ')}.`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const absolutePath = (value, label) => {
|
|
59
|
+
text(value, label);
|
|
60
|
+
if (!ABSOLUTE_PATH.test(value)) {
|
|
61
|
+
fail(`"${label}" must be an absolute path.`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const port = (value, label) => integer(value, label, 1, 65535);
|
|
65
|
+
const optional = (source, key, label, check) => {
|
|
66
|
+
if (source[key] !== undefined) {
|
|
67
|
+
check(source[key], `${label}.${key}`);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const value = (input, label) => {
|
|
71
|
+
if (input === null || typeof input === 'boolean' || typeof input === 'string') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (typeof input === 'number') {
|
|
75
|
+
if (!Number.isFinite(input)) {
|
|
76
|
+
fail(`"${label}" must be a finite number.`);
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!isDict(input) || input.kind !== 'binary') {
|
|
81
|
+
fail(`"${label}" must be a value, such as null, a boolean, a number, a string or a binary object.`);
|
|
82
|
+
}
|
|
83
|
+
const binary = shape(input, label, ['kind', 'hex']);
|
|
84
|
+
if (typeof binary.hex !== 'string' || !HEX.test(binary.hex)) {
|
|
85
|
+
fail(`"${label}.hex" must be lowercase hex of whole bytes.`);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const editValue = (input, label) => {
|
|
89
|
+
if (isDict(input) && input.kind === 'default') {
|
|
90
|
+
shape(input, label, ['kind']);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
value(input, label);
|
|
94
|
+
};
|
|
95
|
+
const values = (input, label, check, atLeastOne) => {
|
|
96
|
+
if (!isDict(input)) {
|
|
97
|
+
fail(`"${label}" must be an object.`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const entries = Object.entries(input);
|
|
101
|
+
if (atLeastOne && entries.length === 0) {
|
|
102
|
+
fail(`"${label}" must name at least one column.`);
|
|
103
|
+
}
|
|
104
|
+
for (const [column, entry] of entries) {
|
|
105
|
+
check(entry, `${label}.${column}`);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const tunnel = (input, label) => {
|
|
109
|
+
if (!isDict(input)) {
|
|
110
|
+
fail(`"${label}" must be an object.`);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (input.kind === 'ssh') {
|
|
114
|
+
const config = shape(input, label, ['kind', 'host'], ['port', 'user', 'identityFile']);
|
|
115
|
+
text(config.host, `${label}.host`);
|
|
116
|
+
optional(config, 'port', label, port);
|
|
117
|
+
optional(config, 'user', label, text);
|
|
118
|
+
optional(config, 'identityFile', label, text);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (input.kind === 'docker') {
|
|
122
|
+
const config = shape(input, label, ['kind', 'container'], ['port', 'context']);
|
|
123
|
+
text(config.container, `${label}.container`);
|
|
124
|
+
optional(config, 'port', label, port);
|
|
125
|
+
optional(config, 'context', label, text);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
fail(`"${label}.kind" must be "ssh" or "docker".`);
|
|
129
|
+
};
|
|
130
|
+
const connection = (input, label) => {
|
|
131
|
+
if (!isDict(input)) {
|
|
132
|
+
fail(`"${label}" must be an object.`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (input.engine === 'sqlite') {
|
|
136
|
+
const config = shape(input, label, ['engine', 'path'], ['create', 'readOnly']);
|
|
137
|
+
absolutePath(config.path, `${label}.path`);
|
|
138
|
+
optional(config, 'create', label, flag);
|
|
139
|
+
optional(config, 'readOnly', label, flag);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (input.engine === 'mysql') {
|
|
143
|
+
const config = shape(input, label, ['engine', 'host', 'user'], ['port', 'socket', 'password', 'database', 'tls', 'readOnly', 'tunnel']);
|
|
144
|
+
optional(config, 'tunnel', label, tunnel);
|
|
145
|
+
// A Docker tunnel finds the server by its container, so the host is left empty.
|
|
146
|
+
const viaDocker = isDict(config.tunnel) && config.tunnel.kind === 'docker';
|
|
147
|
+
(viaDocker ? plainText : text)(config.host, `${label}.host`);
|
|
148
|
+
text(config.user, `${label}.user`);
|
|
149
|
+
optional(config, 'port', label, port);
|
|
150
|
+
optional(config, 'socket', label, text);
|
|
151
|
+
optional(config, 'password', label, plainText);
|
|
152
|
+
optional(config, 'database', label, plainText);
|
|
153
|
+
optional(config, 'tls', label, oneOf(TLS_MODES));
|
|
154
|
+
optional(config, 'readOnly', label, flag);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
fail(`"${label}.engine" must be "sqlite" or "mysql".`);
|
|
158
|
+
};
|
|
159
|
+
const rowChange = (input, label) => {
|
|
160
|
+
if (!isDict(input)) {
|
|
161
|
+
fail(`"${label}" must be an object.`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (input.kind === 'insert') {
|
|
165
|
+
const change = shape(input, label, ['kind', 'values']);
|
|
166
|
+
values(change.values, `${label}.values`, editValue, false);
|
|
167
|
+
}
|
|
168
|
+
else if (input.kind === 'update') {
|
|
169
|
+
const change = shape(input, label, ['kind', 'key', 'values']);
|
|
170
|
+
values(change.key, `${label}.key`, value, true);
|
|
171
|
+
values(change.values, `${label}.values`, editValue, true);
|
|
172
|
+
}
|
|
173
|
+
else if (input.kind === 'delete') {
|
|
174
|
+
const change = shape(input, label, ['kind', 'key']);
|
|
175
|
+
values(change.key, `${label}.key`, value, true);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
fail(`"${label}.kind" must be "insert", "update" or "delete".`);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const exportSource = (input, label) => {
|
|
182
|
+
if (!isDict(input)) {
|
|
183
|
+
fail(`"${label}" must be an object.`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (input.kind === 'table') {
|
|
187
|
+
const source = shape(input, label, ['kind', 'schema', 'table'], ['where', 'orderBy']);
|
|
188
|
+
text(source.schema, `${label}.schema`);
|
|
189
|
+
text(source.table, `${label}.table`);
|
|
190
|
+
optional(source, 'where', label, plainText);
|
|
191
|
+
optional(source, 'orderBy', label, plainText);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (input.kind === 'query') {
|
|
195
|
+
const source = shape(input, label, ['kind', 'sql'], ['schema']);
|
|
196
|
+
text(source.sql, `${label}.sql`);
|
|
197
|
+
optional(source, 'schema', label, text);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
fail(`"${label}.kind" must be "table" or "query".`);
|
|
201
|
+
};
|
|
202
|
+
const cellLimit = (params) => optional(params, 'cellLimit', 'params', (limit, name) => integer(limit, name, 1, MAX_CELL_LIMIT));
|
|
203
|
+
const table = (params) => {
|
|
204
|
+
text(params.session, 'params.session');
|
|
205
|
+
text(params.schema, 'params.schema');
|
|
206
|
+
text(params.table, 'params.table');
|
|
207
|
+
};
|
|
208
|
+
const TARGET = ['session', 'schema', 'table'];
|
|
209
|
+
const PARAMS = {
|
|
210
|
+
open: (input) => connection(shape(input, 'params', ['connection']).connection, 'params.connection'),
|
|
211
|
+
test: (input) => connection(shape(input, 'params', ['connection']).connection, 'params.connection'),
|
|
212
|
+
close: (input) => text(shape(input, 'params', ['session']).session, 'params.session'),
|
|
213
|
+
schemas: (input) => text(shape(input, 'params', ['session']).session, 'params.session'),
|
|
214
|
+
tables: (input) => {
|
|
215
|
+
const params = shape(input, 'params', ['session', 'schema']);
|
|
216
|
+
text(params.session, 'params.session');
|
|
217
|
+
text(params.schema, 'params.schema');
|
|
218
|
+
},
|
|
219
|
+
structure: (input) => table(shape(input, 'params', TARGET)),
|
|
220
|
+
rows: (input) => {
|
|
221
|
+
const params = shape(input, 'params', [...TARGET, 'offset', 'limit'], ['where', 'orderBy', 'cellLimit']);
|
|
222
|
+
table(params);
|
|
223
|
+
optional(params, 'where', 'params', plainText);
|
|
224
|
+
optional(params, 'orderBy', 'params', plainText);
|
|
225
|
+
integer(params.offset, 'params.offset', 0, Number.MAX_SAFE_INTEGER);
|
|
226
|
+
integer(params.limit, 'params.limit', 1, MAX_LIMIT);
|
|
227
|
+
cellLimit(params);
|
|
228
|
+
},
|
|
229
|
+
count: (input) => {
|
|
230
|
+
const params = shape(input, 'params', TARGET, ['where']);
|
|
231
|
+
table(params);
|
|
232
|
+
optional(params, 'where', 'params', plainText);
|
|
233
|
+
},
|
|
234
|
+
cell: (input) => {
|
|
235
|
+
const params = shape(input, 'params', [...TARGET, 'key', 'column']);
|
|
236
|
+
table(params);
|
|
237
|
+
values(params.key, 'params.key', value, true);
|
|
238
|
+
text(params.column, 'params.column');
|
|
239
|
+
},
|
|
240
|
+
apply: (input) => {
|
|
241
|
+
const params = shape(input, 'params', [...TARGET, 'changes']);
|
|
242
|
+
table(params);
|
|
243
|
+
if (!Array.isArray(params.changes)) {
|
|
244
|
+
fail('"params.changes" must be a list.');
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
params.changes.forEach((change, i) => rowChange(change, `params.changes[${i}]`));
|
|
248
|
+
},
|
|
249
|
+
execute: (input) => {
|
|
250
|
+
const params = shape(input, 'params', ['session', 'sql'], ['schema', 'limit', 'cellLimit']);
|
|
251
|
+
text(params.session, 'params.session');
|
|
252
|
+
text(params.sql, 'params.sql');
|
|
253
|
+
optional(params, 'schema', 'params', text);
|
|
254
|
+
optional(params, 'limit', 'params', (limit, name) => integer(limit, name, 1, MAX_LIMIT));
|
|
255
|
+
cellLimit(params);
|
|
256
|
+
},
|
|
257
|
+
page: (input) => {
|
|
258
|
+
const params = shape(input, 'params', ['session', 'sql', 'offset', 'limit'], ['schema', 'cellLimit']);
|
|
259
|
+
text(params.session, 'params.session');
|
|
260
|
+
text(params.sql, 'params.sql');
|
|
261
|
+
optional(params, 'schema', 'params', text);
|
|
262
|
+
integer(params.offset, 'params.offset', 0, Number.MAX_SAFE_INTEGER);
|
|
263
|
+
integer(params.limit, 'params.limit', 1, MAX_LIMIT);
|
|
264
|
+
cellLimit(params);
|
|
265
|
+
},
|
|
266
|
+
transaction: (input) => {
|
|
267
|
+
const params = shape(input, 'params', ['session', 'action']);
|
|
268
|
+
text(params.session, 'params.session');
|
|
269
|
+
oneOf(TRANSACTION_ACTIONS)(params.action, 'params.action');
|
|
270
|
+
},
|
|
271
|
+
export: (input) => {
|
|
272
|
+
const params = shape(input, 'params', ['session', 'source', 'format', 'path'], ['header', 'tableName']);
|
|
273
|
+
text(params.session, 'params.session');
|
|
274
|
+
exportSource(params.source, 'params.source');
|
|
275
|
+
oneOf(EXPORT_FORMATS)(params.format, 'params.format');
|
|
276
|
+
absolutePath(params.path, 'params.path');
|
|
277
|
+
optional(params, 'header', 'params', flag);
|
|
278
|
+
optional(params, 'tableName', 'params', text);
|
|
279
|
+
},
|
|
280
|
+
sample: (input) => {
|
|
281
|
+
const params = shape(input, 'params', ['path', 'format', 'header'], ['limit']);
|
|
282
|
+
absolutePath(params.path, 'params.path');
|
|
283
|
+
oneOf(DELIMITED_FORMATS)(params.format, 'params.format');
|
|
284
|
+
flag(params.header, 'params.header');
|
|
285
|
+
optional(params, 'limit', 'params', (limit, name) => integer(limit, name, 1, MAX_LIMIT));
|
|
286
|
+
},
|
|
287
|
+
import: (input) => {
|
|
288
|
+
const params = shape(input, 'params', [...TARGET, 'path', 'format', 'header', 'columns']);
|
|
289
|
+
table(params);
|
|
290
|
+
absolutePath(params.path, 'params.path');
|
|
291
|
+
oneOf(DELIMITED_FORMATS)(params.format, 'params.format');
|
|
292
|
+
flag(params.header, 'params.header');
|
|
293
|
+
if (!Array.isArray(params.columns)) {
|
|
294
|
+
fail('"params.columns" must be a list.');
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
params.columns.forEach((column, i) => {
|
|
298
|
+
if (column !== null) {
|
|
299
|
+
text(column, `params.columns[${i}]`);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
discover: (input) => {
|
|
304
|
+
const params = shape(input, 'params', ['kind'], ['context']);
|
|
305
|
+
oneOf(['docker'])(params.kind, 'params.kind');
|
|
306
|
+
optional(params, 'context', 'params', text);
|
|
307
|
+
},
|
|
308
|
+
cancel: (input) => {
|
|
309
|
+
const params = shape(input, 'params', ['request']);
|
|
310
|
+
if (typeof params.request !== 'string' || params.request.length === 0 || params.request.length > MAX_ID_LENGTH) {
|
|
311
|
+
fail(`"params.request" must be a string of 1 to ${MAX_ID_LENGTH} characters.`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
/* Checks the whole request before anything reaches the helper, which then never has to defend itself against a page. */
|
|
316
|
+
export const parseRequest = (input) => {
|
|
317
|
+
const id = isDict(input) && typeof input.id === 'string' && input.id.length > 0 && input.id.length <= MAX_ID_LENGTH ? input.id : '';
|
|
318
|
+
try {
|
|
319
|
+
const envelope = shape(input, 'request', ['id', 'method', 'params']);
|
|
320
|
+
if (id === '') {
|
|
321
|
+
fail(`"id" must be a string of 1 to ${MAX_ID_LENGTH} characters.`);
|
|
322
|
+
}
|
|
323
|
+
if (typeof envelope.method !== 'string') {
|
|
324
|
+
fail('"method" must be a string.');
|
|
325
|
+
}
|
|
326
|
+
const method = envelope.method;
|
|
327
|
+
if (!Object.hasOwn(PARAMS, method)) {
|
|
328
|
+
fail(`Unknown method ${JSON.stringify(method)}.`);
|
|
329
|
+
}
|
|
330
|
+
PARAMS[method](envelope.params);
|
|
331
|
+
return { ok: true, request: input };
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
if (error instanceof InvalidRequest) {
|
|
335
|
+
return { ok: false, id, error: { code: 'invalid-request', message: error.message } };
|
|
336
|
+
}
|
|
337
|
+
throw error;
|
|
338
|
+
}
|
|
339
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createDatabaseClient, DatabaseRequestError, type Connection, type DatabaseClient, type DatabaseClientOptions, type DatabaseSession, type DatabaseTransport, type ExecuteOptions, type ExecuteResult, type ExportRequest, type ExportResult, type ImportRequest, type PageQuery, type RequestOptions, type RowsQuery, type SchemaChange, type TableRef } from './client/index.ts';
|
|
2
|
+
export type { DatabaseAction, DatabaseFiles, DatabaseStorage, ExplorerSelection } from './actions.ts';
|
|
3
|
+
export { ConnectionForm, type ConnectionFormProps } from './connections/ConnectionForm.tsx';
|
|
4
|
+
export { ConnectionManager, type ConnectionManagerProps } from './connections/ConnectionManager.tsx';
|
|
5
|
+
export { DatabaseExplorer, type DatabaseExplorerProps } from './explorer/DatabaseExplorer.tsx';
|
|
6
|
+
export { TableDesigner, type TableDesignerProps } from './designer/TableDesigner.tsx';
|
|
7
|
+
export { DatabaseProvider, type DatabaseProviderProps } from './DatabaseProvider.tsx';
|
|
8
|
+
export { useDatabaseClient } from './client-context.ts';
|
|
9
|
+
export type { NumberNotation } from './grid/display.ts';
|
|
10
|
+
export { QueryConsole, type QueryConsoleProps } from './console/QueryConsole.tsx';
|
|
11
|
+
export { StructureView, type StructureViewProps } from './structure/StructureView.tsx';
|
|
12
|
+
export { TableView, type TableViewProps } from './table/TableView.tsx';
|
|
13
|
+
export { DatabaseWorkbench, type DatabaseWorkbenchProps } from './workbench/DatabaseWorkbench.tsx';
|
|
14
|
+
export { addDatabaseResources, DATABASE_NAMESPACE, DATABASE_RESOURCES } from './locales.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* The views of the package and the client they read through. Every name here is public API; `exports.test.ts` turns a change to this list into a diff someone has to accept. */
|
|
2
|
+
export { createDatabaseClient, DatabaseRequestError } from './client/index.js';
|
|
3
|
+
export { ConnectionForm } from './connections/ConnectionForm.js';
|
|
4
|
+
export { ConnectionManager } from './connections/ConnectionManager.js';
|
|
5
|
+
export { DatabaseExplorer } from './explorer/DatabaseExplorer.js';
|
|
6
|
+
export { TableDesigner } from './designer/TableDesigner.js';
|
|
7
|
+
export { DatabaseProvider } from './DatabaseProvider.js';
|
|
8
|
+
export { useDatabaseClient } from './client-context.js';
|
|
9
|
+
export { QueryConsole } from './console/QueryConsole.js';
|
|
10
|
+
export { StructureView } from './structure/StructureView.js';
|
|
11
|
+
export { TableView } from './table/TableView.js';
|
|
12
|
+
export { DatabaseWorkbench } from './workbench/DatabaseWorkbench.js';
|
|
13
|
+
export { addDatabaseResources, DATABASE_NAMESPACE, DATABASE_RESOURCES } from './locales.js';
|