@heswell/vuu-data-engine-local 4.0.0-alpha.20 → 4.0.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.
Files changed (42) hide show
  1. package/91.js +248 -0
  2. package/README.md +198 -25
  3. package/index.js +3752 -3526
  4. package/legacy.js +11 -0
  5. package/package.json +18 -10
  6. package/react.js +64 -0
  7. package/src/EngineDataSource.d.ts +13 -3
  8. package/src/ModuleDataSource.d.ts +3 -3
  9. package/src/UpdateGenerator.d.ts +12 -0
  10. package/src/basket/BasketModule.d.ts +12 -2
  11. package/src/basket/index.d.ts +1 -1
  12. package/src/core/engine/LocalEngine.d.ts +63 -0
  13. package/src/core/filter/PermissionFilter.d.ts +2 -2
  14. package/src/core/module/VuuModule.d.ts +80 -1
  15. package/src/core/module/edit-hooks.d.ts +135 -0
  16. package/src/core/table/TableContainer.d.ts +38 -11
  17. package/src/core/table/defaultTableContainer.d.ts +6 -0
  18. package/src/data-utils.d.ts +7 -0
  19. package/src/demo-modules.d.ts +18 -0
  20. package/src/index.d.ts +6 -3
  21. package/src/legacy.d.ts +12 -0
  22. package/src/local-datasource-provider/LocalDatasourceProvider.d.ts +18 -7
  23. package/src/local-datasource-provider/createDataSourceProvider.d.ts +12 -0
  24. package/src/module-admin/ModuleAdminModule.d.ts +0 -1
  25. package/src/module-admin/index.d.ts +2 -2
  26. package/src/notifications/NotificationModule.d.ts +1 -0
  27. package/src/notifications/index.d.ts +0 -1
  28. package/src/react.d.ts +7 -0
  29. package/src/simul/SimulModule.d.ts +9 -1
  30. package/src/simul/index.d.ts +1 -1
  31. package/src/simul/reference-data/instrument-prices.d.ts +2 -2
  32. package/src/simul/reference-data/instruments-extended.d.ts +1 -1
  33. package/src/simul/reference-data/instruments.d.ts +2 -3
  34. package/src/simul/reference-data/orders.d.ts +2 -3
  35. package/src/simul/reference-data/parent-child-orders.d.ts +15 -4
  36. package/src/simul/reference-data/prices.d.ts +18 -6
  37. package/src/test/TestModule.d.ts +2 -3
  38. package/src/user-admin/UserAdminModule.d.ts +0 -1
  39. package/src/user-admin/index.d.ts +1 -1
  40. package/src/basket/reference-data/prices.d.ts +0 -24
  41. package/src/core/module/ModuleContainer.d.ts +0 -15
  42. package/src/notifications/simulated/notificationsModule.d.ts +0 -5
package/91.js ADDED
@@ -0,0 +1,248 @@
1
+ import { JoinTable, Table } from "@heswell/vuu-table";
2
+ import { EventEmitter } from "@vuu-ui/vuu-utils";
3
+ class Table_Table extends EventEmitter {
4
+ engineTable;
5
+ #dataMap;
6
+ #indexOfKey;
7
+ #updateColumnName;
8
+ constructor(schemaOrEngineTable, data = [], dataMap, updateGenerator){
9
+ super();
10
+ this.engineTable = schemaOrEngineTable instanceof Table ? schemaOrEngineTable : new Table(schemaOrEngineTable);
11
+ this.#dataMap = dataMap ?? this.engineTable.columnMap;
12
+ this.#indexOfKey = this.engineTable.indexOfKeyField;
13
+ for (const row of data)this.engineTable.insert(row);
14
+ this.engineTable.addListener({
15
+ onInsert: (_rowIdx, row)=>this.emit("insert", row),
16
+ onUpdate: (_rowIdx, row)=>this.emit("update", row, this.#updateColumnName),
17
+ onDelete: (_rowIdx, row)=>this.emit("delete", String(row[this.#indexOfKey])),
18
+ onClear: ()=>void 0
19
+ });
20
+ updateGenerator?.setTable(this);
21
+ updateGenerator?.setRange({
22
+ from: 0,
23
+ to: 100
24
+ });
25
+ }
26
+ get data() {
27
+ return this.engineTable.rows;
28
+ }
29
+ get map() {
30
+ return this.#dataMap;
31
+ }
32
+ get schema() {
33
+ return this.engineTable.schema;
34
+ }
35
+ get name() {
36
+ return this.engineTable.name;
37
+ }
38
+ get rowCount() {
39
+ return this.engineTable.rowCount;
40
+ }
41
+ delete(key) {
42
+ if (!this.engineTable.delete(key)) throw Error(`[Table] delete key ${key} not found`);
43
+ }
44
+ insert(row, _emitEvent = true) {
45
+ const ts = Date.now();
46
+ const { vuuCreatedTimestamp, vuuUpdatedTimestamp } = this.#dataMap;
47
+ if (void 0 !== vuuUpdatedTimestamp) row[vuuUpdatedTimestamp] = ts;
48
+ if (void 0 !== vuuCreatedTimestamp) row[vuuCreatedTimestamp] = ts;
49
+ this.engineTable.insert(row);
50
+ }
51
+ findByKey(key) {
52
+ return this.engineTable.getRowAtKey(key, false);
53
+ }
54
+ update(key, columnName, value) {
55
+ const rowIdx = this.engineTable.rowIndexAtKey(key);
56
+ if (-1 !== rowIdx) {
57
+ const newRow = this.engineTable.rows[rowIdx].slice();
58
+ newRow[this.#dataMap[columnName]] = value;
59
+ this.#updateColumnName = columnName;
60
+ try {
61
+ this.engineTable.update(rowIdx, newRow);
62
+ } finally{
63
+ this.#updateColumnName = void 0;
64
+ }
65
+ }
66
+ }
67
+ updateRow(row) {
68
+ const rowIdx = this.engineTable.rowIndexAtKey(String(row[this.#indexOfKey]));
69
+ if (-1 !== rowIdx) this.engineTable.update(rowIdx, row);
70
+ }
71
+ }
72
+ function buildDataColumnMapFromSchema(schema) {
73
+ const map = {};
74
+ schema.columns.forEach((col, index)=>{
75
+ map[col.name] = index;
76
+ });
77
+ return map;
78
+ }
79
+ function buildDataColumnMap(schemas, tableName) {
80
+ return buildDataColumnMapFromSchema(schemas[tableName]);
81
+ }
82
+ const DEFAULT_RANGE_LIMITS = {
83
+ maxRangeEnd: 1000000,
84
+ maxRangeWidth: 1000
85
+ };
86
+ const tableKey = ({ module, table })=>`${module}:${table}`;
87
+ const createTable = (schema, data = [], dataMap = buildDataColumnMapFromSchema(schema), updateGenerator)=>new Table_Table(schema, data, dataMap, updateGenerator);
88
+ const createJoinTable = (joinTable, table1, table2, joinColumn, joinType = "inner")=>{
89
+ const { schema: schema1 } = table1;
90
+ const { schema: schema2 } = table2;
91
+ const combinedColumns = new Set([
92
+ ...schema1.columns,
93
+ ...schema2.columns
94
+ ].map((col)=>col.name).sort());
95
+ const combinedSchema = {
96
+ key: schema1.key,
97
+ table: joinTable,
98
+ rangeLimits: DEFAULT_RANGE_LIMITS,
99
+ columns: Array.from(combinedColumns).map((columnName)=>({
100
+ name: columnName,
101
+ serverDataType: getServerDataType(columnName, schema1, schema2)
102
+ }))
103
+ };
104
+ const engineJoinTable = new JoinTable({
105
+ schema: combinedSchema,
106
+ baseTable: table1.engineTable,
107
+ joinTable: table2.engineTable,
108
+ leftColumn: joinColumn,
109
+ rightColumn: joinColumn,
110
+ joinType
111
+ });
112
+ return new Table_Table(engineJoinTable);
113
+ };
114
+ class TableContainer {
115
+ #tables = new Map();
116
+ createTable = (schema, data = [], dataMap = buildDataColumnMapFromSchema(schema), updateGenerator)=>{
117
+ const table = createTable(schema, data, dataMap, updateGenerator);
118
+ this.addTable(table);
119
+ return table;
120
+ };
121
+ createJoinTable(joinTable, table1, table2, joinColumn, joinType = "inner") {
122
+ const newTable = createJoinTable(joinTable, this.getTable(table1), this.getTable(table2), joinColumn, joinType);
123
+ this.addTable(newTable);
124
+ return newTable;
125
+ }
126
+ addTable(table, as = table.schema.table) {
127
+ this.#tables.set(tableKey(as), table);
128
+ }
129
+ removeTable(table) {
130
+ return this.#tables.delete(tableKey(table));
131
+ }
132
+ hasTable(table) {
133
+ return this.#tables.has(tableKey(table));
134
+ }
135
+ getTable(table) {
136
+ if ("string" == typeof table) {
137
+ const matches = Array.from(this.#tables.keys()).filter((key)=>key.endsWith(`:${table}`));
138
+ if (1 === matches.length) return this.#tables.get(matches[0]);
139
+ if (matches.length > 1) throw Error(`[TableContainer] table name ${table} is ambiguous (${matches.join(", ")}), use {module, table}`);
140
+ throw Error(`[TableContainer] no table ${table}`);
141
+ }
142
+ const found = this.#tables.get(tableKey(table));
143
+ if (found) return found;
144
+ throw Error(`[TableContainer] no table ${tableKey(table)}`);
145
+ }
146
+ get tables() {
147
+ return Array.from(this.#tables.values());
148
+ }
149
+ clear() {
150
+ this.#tables.clear();
151
+ }
152
+ }
153
+ const getServerDataType = (columnName, { columns: cols1, table: t1 }, { columns: cols2, table: t2 })=>{
154
+ const col1 = cols1.find((col)=>col.name === columnName);
155
+ const col2 = cols2.find((col)=>col.name === columnName);
156
+ if (col1 && col2) if (col1.serverDataType === col2.serverDataType) return col1.serverDataType;
157
+ else throw Error(`both tables ${t1.table} and ${t2.table} implement column ${columnName}, but with types differ`);
158
+ if (col1) return col1.serverDataType;
159
+ if (col2) return col2.serverDataType;
160
+ throw Error("how is this possible");
161
+ };
162
+ class LocalEngine {
163
+ tableContainer = new TableContainer();
164
+ #modules = new Map();
165
+ #disposed = false;
166
+ constructor({ modules = [] } = {}){
167
+ for (const module of modules)this.register(module);
168
+ }
169
+ register(module) {
170
+ const existing = this.#modules.get(module.name);
171
+ if (existing === module) return module;
172
+ if (existing) this.unregister(existing.name);
173
+ this.#modules.set(module.name, module);
174
+ for (const [tableName, table] of Object.entries(module.getTables()))this.tableContainer.addTable(table, {
175
+ module: module.name,
176
+ table: tableName
177
+ });
178
+ module.attachEngine(this);
179
+ return module;
180
+ }
181
+ unregister(moduleName) {
182
+ const module = this.#modules.get(moduleName);
183
+ if (module) {
184
+ this.#modules.delete(moduleName);
185
+ for (const tableName of module.getTableList())this.tableContainer.removeTable({
186
+ module: moduleName,
187
+ table: tableName
188
+ });
189
+ module.detachEngine(this);
190
+ return true;
191
+ }
192
+ return false;
193
+ }
194
+ hasModule(moduleName) {
195
+ return this.#modules.has(moduleName);
196
+ }
197
+ getModule(moduleName) {
198
+ const module = this.#modules.get(moduleName);
199
+ if (module) return module;
200
+ throw Error(`[LocalEngine] module ${moduleName} not found`);
201
+ }
202
+ get modules() {
203
+ return Array.from(this.#modules.values());
204
+ }
205
+ get moduleNames() {
206
+ return Array.from(this.#modules.keys());
207
+ }
208
+ getTableList() {
209
+ return this.modules.flatMap((module)=>module.getTableList().map((table)=>({
210
+ module: module.name,
211
+ table
212
+ })));
213
+ }
214
+ getTableSchema({ module, table }) {
215
+ return this.getModule(module).getTableSchema(table);
216
+ }
217
+ createDataSource({ module, table }, viewport, config) {
218
+ return this.getModule(module).createDataSource(table, viewport, config);
219
+ }
220
+ get disposed() {
221
+ return this.#disposed;
222
+ }
223
+ dispose() {
224
+ for (const module of this.modules){
225
+ const owned = module.engine === this;
226
+ this.unregister(module.name);
227
+ if (owned) module.dispose();
228
+ }
229
+ this.tableContainer.clear();
230
+ this.#disposed = true;
231
+ }
232
+ }
233
+ const createLocalEngine = (options)=>new LocalEngine(options);
234
+ let defaultEngine;
235
+ const getDefaultEngine = ()=>{
236
+ if (void 0 === defaultEngine || defaultEngine.disposed) defaultEngine = new LocalEngine();
237
+ return defaultEngine;
238
+ };
239
+ const resetDefaultEngine = ()=>{
240
+ defaultEngine?.dispose();
241
+ defaultEngine = void 0;
242
+ };
243
+ const ensureVuuModule = (module)=>{
244
+ const engine = getDefaultEngine();
245
+ if (!engine.hasModule(module.name)) engine.register(module);
246
+ return module;
247
+ };
248
+ export { LocalEngine, TableContainer, Table_Table as Table, buildDataColumnMap, buildDataColumnMapFromSchema, createJoinTable, createLocalEngine, createTable, ensureVuuModule, getDefaultEngine, resetDefaultEngine };
package/README.md CHANGED
@@ -9,17 +9,189 @@ The package runs alongside `@vuu-ui/vuu-data-test` and has the same public API.
9
9
  meant to replace the `VuuModule` / `TickingArrayDataSource` core in that package. The
10
10
  two packages don't depend on each other.
11
11
 
12
+ ## Peer dependencies
13
+
14
+ All `@vuu-ui` packages are peers declared as `^4.0.0-alpha.20`, so the engine uses the host
15
+ application's single copy of each (a second `@vuu-ui/vuu-utils` or `@vuu-ui/core` would mean
16
+ a second set of React contexts). They are `@vuu-ui/vuu-utils` and `@vuu-ui/vuu-filter-parser`
17
+ (runtime), `@vuu-ui/core` (React provider, `/react` entry only), and the type-only `vuu-data-types`,
18
+ `vuu-filter-types`, `vuu-protocol-types` and `vuu-table-types`.
19
+
12
20
  ## Architecture
13
21
 
14
- | Component | Role |
15
- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
16
- | `Table` | A façade over the engine `Table` that keeps the existing `Table` API. Inserts, updates and deletes go straight to the engine. Every change notifies subscribed viewports. |
17
- | `TableContainer` | A registry of tables, including join tables. |
22
+ | Component | Role |
23
+ | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
24
+ | `Table` | A façade over the engine `Table` that keeps the existing `Table` API. Inserts, updates and deletes go straight to the engine. Every change notifies subscribed viewports. |
25
+ | `LocalEngine` | An isolated in-browser Vuu server: the registered `VuuModule`s and a `TableContainer` of their tables. No React or DOM dependency. |
26
+ | `TableContainer` | A registry of tables, including join tables, keyed by `{module, table}`. Each engine has its own. |
18
27
  | `EngineDataSource` | A `DataSource` implementation backed by an engine `Viewport`. It handles windowing, sort, filter, groupBy, selection (including select-all), freeze, base filter, link filter and permission filter. Row updates are batched per frame. |
19
- | `ModuleDataSource` | Extends `EngineDataSource` with the module features: RPC and menu services, edit sessions, and visual links. `TickingArrayDataSource` is a deprecated alias. |
20
- | `VuuModule` | Creates `ModuleDataSource` instances. Row permissions are passed to the engine as a `permissionFilter` predicate. |
21
- | `RuntimeVisualLink` | When the parent's selection changes, sets the child's engine link filter. |
22
- | `UpdateGenerator` / `TickingGenerator` | Simulated ticking data that writes into the engine tables. |
28
+ | `ModuleDataSource` | Extends `EngineDataSource` with the module features: RPC and menu services, edit sessions, and visual links. `TickingArrayDataSource` is a deprecated alias. |
29
+ | `VuuModule` | Creates `ModuleDataSource` instances. Row permissions are passed to the engine as a `permissionFilter` predicate. Edit sessions can be customised per table with edit hooks. |
30
+ | `RuntimeVisualLink` | When the parent's selection changes, sets the child's engine link filter. |
31
+ | `UpdateGenerator` / `TickingGenerator` | Simulated ticking data that writes into the engine tables. |
32
+
33
+ ## Usage
34
+
35
+ Importing the package has no side effects: no modules, tables or timers are created
36
+ until you ask for them. The main entry needs no DOM, so it runs in plain Node or Bun. The
37
+ React bindings (`createDataSourceProvider`, `createLocalVuuServer`,
38
+ `LocalDataSourceProvider`) are in `@heswell/vuu-data-engine-local/react`, because
39
+ `@vuu-ui/core` needs a DOM (`ResizeObserver`) at import time.
40
+
41
+ ```ts
42
+ import {
43
+ createLocalEngine,
44
+ registerDemoModules,
45
+ } from "@heswell/vuu-data-engine-local";
46
+ import { createLocalVuuServer } from "@heswell/vuu-data-engine-local/react";
47
+
48
+ // Your own modules, in an isolated engine
49
+ const engine = createLocalEngine({ modules: [new OrdersModule()] });
50
+ const dataSource = engine.createDataSource({
51
+ module: "ORDERS",
52
+ table: "parentOrders",
53
+ });
54
+ await dataSource.subscribe({ range: { from: 0, to: 100 } }, callback);
55
+ engine.dispose(); // disposes its modules and stops their timers
56
+
57
+ // A local Vuu server for a local-mode AuthenticationProvider (new engine per server)
58
+ const server = createLocalVuuServer({
59
+ connectionId: "orders",
60
+ modules: [new OrdersModule()],
61
+ });
62
+ // server.DataSourceProvider, server.engine
63
+
64
+ // The demo SIMUL, BASKET and TEST modules
65
+ const { simulModule } = registerDemoModules(createLocalEngine());
66
+ ```
67
+
68
+ ### Engines
69
+
70
+ | API | Description |
71
+ | --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
72
+ | `createLocalEngine({ modules? })` | A new, isolated `LocalEngine`. Two engines, or two modules in one engine, can use the same table names. |
73
+ | `engine.register(module)` / `unregister(name)` | Add or remove a module and its tables. A module is attached to the first engine it is registered with. |
74
+ | `engine.getModule(name)`, `hasModule`, `modules` | Look up modules. |
75
+ | `engine.getTableList()` | `VuuTable[]` (`{module, table}`) for every registered module. |
76
+ | `engine.getTableSchema(vuuTable)` | A table's schema. |
77
+ | `engine.createDataSource(vuuTable, vp?, cfg?)` | A `ModuleDataSource` for a table. |
78
+ | `engine.tableContainer` | The engine's `TableContainer`. Tables are keyed by `{module, table}`; a bare table name is accepted only if exactly one module has a table with that name. |
79
+ | `engine.dispose()` | Unregisters every module and disposes those attached to this engine (stopping ticking data and timers). |
80
+ | `createDataSourceProvider(engine)` (`/react`) | A React provider installing the legacy and core data contexts for the engine. |
81
+ | `createLocalVuuServer({ connectionId, modules, engine? })` (`/react`) | A `LocalVuuServer` (`{connectionId, DataSourceProvider, engine}`). Uses a new engine unless one is passed. |
82
+ | `registerDemoModules(engine?)` | Creates the SIMUL, BASKET and TEST demo modules and registers them with `engine` (default: the default engine). |
83
+ | `getDefaultEngine()` / `resetDefaultEngine()` | The shared engine behind the deprecated globals below. |
84
+
85
+ ### Edit sessions: hooks and service overrides
86
+
87
+ The built-in edit-session RPC services (`createSessionTable`, `editCell`, `addRow`, `deleteRow`,
88
+ `undoRowChange`, `endEditSession`, …) can be overridden by `rpcName`, per module with
89
+ `moduleServices` or per table with `services`. Precedence: table services, then module
90
+ services, then the built-ins. Services registered for a source table also apply to its
91
+ session tables.
92
+
93
+ Most customisation needs only edit hooks, which mirror vuu-server's. Implement them per
94
+ table with `editHooks` (these win), or for every table as protected methods of the module.
95
+
96
+ | Hook | Default |
97
+ | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
98
+ | `canEditSource(column, ctx)` | `true`: editCell may write directly to a source table (outside a session). |
99
+ | `isEditableColumn(table, column, ctx)` | Any column except the key and the system columns (`vuuCreatedTimestamp`, `vuuUpdatedTimestamp`, `vuuMsg`, `vuuAction`). The key of a row added in the session may be edited. |
100
+ | `validateCellEdit(edit)` | Accept. Return an error message to refuse the edit. |
101
+ | `getStaleColumns(sourceTable, sourceRow, change)` | `defaultGetStaleColumns`: for editCell, the edited columns that changed in the source since the row was copied into the session; for deleteRow, any column. |
102
+ | `canSaveSession(prepared, ctx)` | `true`. Return `false` or a reason to refuse the save. May be async. |
103
+ | `applySessionSave(sessionTable, prepared, ctx)` | `defaultApplySessionSave`: writes the changes to the source table atomically. May be async. |
104
+
105
+ ```ts
106
+ class OrdersModule extends VuuModule<"parentOrders" | "childOrders"> {
107
+ protected editHooks = {
108
+ parentOrders: {
109
+ canSaveSession: ({ changes }) =>
110
+ changes.every(({ cellUpdates }) => Number(cellUpdates.qty) > 0) ||
111
+ "qty must be positive",
112
+ // amend orders through the order service instead of writing the table
113
+ applySessionSave: (_sessionTable, { changes }) =>
114
+ orderService.amend(changes),
115
+ },
116
+ };
117
+ // ...
118
+ }
119
+ ```
120
+
121
+ `deleteRow` and `deleteSelectedRows` behave as on vuu-server: they are only valid in an edit
122
+ session, and mark the session row `vuuAction = "deleteRow"` whatever the `mode` (`"hard"`,
123
+ vuu-ui's default, or `"soft"`). The row stays in the session until it is saved, when
124
+ `applySessionSave` receives it as a `deleteRow` change, or `undoRowChange` restores it. A
125
+ row added in the session is simply dropped. Outside a session `deleteRow` returns an error;
126
+ `deleteSourceRow` (protected, not registered) keeps the old direct delete for subclasses
127
+ such as SIMUL's `DELETE_ROW`.
128
+
129
+ `endEditSession({ save: true })`:
130
+
131
+ 1. Rows already handled by `beforeSessionSave` (with a `vuuMsg`) are skipped.
132
+ 2. Changes are prepared. A row added with an existing key fails with `"duplicate key"`; a
133
+ source row that is missing or stale fails with exactly `"stale update"` (vuu-ui's
134
+ `VuuDataSource` matches this string and throws `StaleUpdateError`). Setting
135
+ `params.force` skips the stale check. The affected session rows get a `vuuMsg`
136
+ (`stale:<key>:<columns>`, `<action>:<key>:source row missing`,
137
+ `addRow:<key>:key already exists`).
138
+ 3. `canSaveSession`, then `applySessionSave`. A refusal or failure (`false`, an
139
+ `ERROR_RESULT`, or a thrown error) leaves the session open, so the user can retry or
140
+ cancel. Exported messages: `STALE_UPDATE`, `DUPLICATE_KEY`, `SAVE_NOT_PERMITTED`,
141
+ `SAVE_FAILED`.
142
+ 4. `afterSessionSave`, then the session rows are reset (deleted rows removed, `vuuAction`
143
+ and `vuuMsg` cleared, snapshots refreshed).
144
+
145
+ ### Join tables
146
+
147
+ `createJoinTable(joinTable, table1, table2, joinColumn, joinType = "inner")` (and
148
+ `tableContainer.createJoinTable`) creates a join that is kept up to date as either table
149
+ changes. Pass `"leftOuter"` to keep every `table1` row. For a row with no match, the
150
+ `table2` columns are `null` (not `0`), as on vuu-server, and vuu-ui renders them empty.
151
+ Sort places nulls first when ascending; relational filters (`<`, `>=`, …) never match
152
+ null; and aggregations skip nulls.
153
+
154
+ ### Ranges
155
+
156
+ `subscribe({ range })`, `dataSource.range = …` and `setRange` accept a vuu-utils `Range` or
157
+ a plain `{from, to}`.
158
+
159
+ ### Deprecated globals and the `/legacy` entry
160
+
161
+ `tableContainer`, `LocalDataSourceProvider` and `ensureVuuModule` use the default engine
162
+ (`getDefaultEngine()`). `@heswell/vuu-data-engine-local/legacy` re-exports the main and
163
+ `/react` entries and,
164
+ on import, registers the demo modules with the default engine, exporting the instances
165
+ `simulModule`, `basketModule`, `testModule`, `moduleAdminModule`, `userAdminModule` and
166
+ `notificationsModule` as 2.x did. It is the only entry point with side effects
167
+ (`"sideEffects": ["./src/legacy.ts"]`).
168
+
169
+ ## Migrating from 3.x
170
+
171
+ These are breaking changes; the next release should be 4.0.0.
172
+
173
+ | 3.x | 4.x |
174
+ | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
175
+ | `createDataSourceProvider`, `createLocalVuuServer`, `LocalDataSourceProvider` exported by the main entry. | Import them from `@heswell/vuu-data-engine-local/react` (or `/legacy`). The main entry no longer needs a DOM. |
176
+ | `deleteRow` with `mode: "hard"` removed the session row, so the save never saw the delete. | The row is marked `vuuAction = "deleteRow"` in either mode and applied on save (or restored by `undoRowChange`). |
177
+ | `deleteRow` outside an edit session deleted the source row. | Returns an error, as vuu-server does. Use an edit session, or expose the protected `deleteSourceRow` as a service. |
178
+
179
+ ## Migrating from 2.x
180
+
181
+ These are breaking changes; the next release should be 3.0.0.
182
+
183
+ | 2.x | 3.x |
184
+ | --------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
185
+ | Importing the package created and registered SIMUL, BASKET, TEST, MODULE_DISCOVERY, USER_ADMIN and NOTIFICATIONS, and exported the instances. | Nothing is created on import. Call `registerDemoModules()` or create the modules yourself, or import `/legacy`. |
186
+ | `new SomeModule()` registered itself in a global module container. | Register modules with an engine: `createLocalEngine({ modules })`, `engine.register()`, or `createLocalVuuServer`. |
187
+ | `createLocalVuuServer` registered its modules globally, so `LocalDataSourceProvider` saw them. | Each server has its own engine (`server.engine`). Pass `engine: getDefaultEngine()` to share the default engine. |
188
+ | `tableContainer` was global and keyed by bare table name. | Each engine has its own, keyed by `{module, table}`. The global `tableContainer` is a deprecated alias of the default engine's; a bare name throws if two modules have a table with that name. |
189
+ | `ModuleContainer` / `moduleContainer`. | Removed: use `LocalEngine`. |
190
+ | Module and table `services` were added alongside the built-in edit services. | They override built-in services with the same `rpcName`. |
191
+ | editCell could change the key and system columns, and edit missing or deleted rows. | Refused by default (see `isEditableColumn`). Editing a missing row returns an error. |
192
+ | `endEditSession` saved without checking for concurrent source changes or duplicate keys. | Fails with `"stale update"` or `"duplicate key"` (unless `force`). After a successful save the session rows are reset. |
193
+ | Demo prices and notifications ticked from import. | They start when a data source is created, and stop on `engine.dispose()`. |
194
+ | Reference data (`instrumentsTable`, `pricesTable`, `instrumentsData`, …) was created on import. | Lazy getters and factories (`getInstrumentsData()`, `createPricesTable()`, …). |
23
195
 
24
196
  ## Differences from `@vuu-ui/vuu-data-test`
25
197
 
@@ -38,7 +210,8 @@ npm run showcase:engine # equivalent to: VUU_DATA_ENGINE=local npm run showcas
38
210
  ```
39
211
 
40
212
  This aliases `@vuu-ui/vuu-data-test` to `@heswell/vuu-data-engine-local` in the showcase
41
- rsbuild config. The examples themselves don't change.
213
+ rsbuild config. The examples themselves don't change. The examples use the eagerly created demo
214
+ modules, so from 3.0 the alias should point to `@heswell/vuu-data-engine-local/legacy`.
42
215
 
43
216
  The showcase uses the published package. To publish it from vuu-websocket:
44
217
 
@@ -64,22 +237,22 @@ results for the sort, filter and groupBy scenarios.
64
237
 
65
238
  Mean time per operation, 100k rows, Node 24, Apple Silicon:
66
239
 
67
- | Scenario | legacy | engine | speed-up |
68
- | --------------------------------------------- | -------- | ------- | -------- |
69
- | create + subscribe | 24.1 ms | 8.7 ms | 2.8x |
70
- | sort numeric column | 62.1 ms | 14.1 ms | 4.4x |
71
- | sort two columns | 64.6 ms | 17.1 ms | 3.8x |
72
- | filter | 5.7 ms | 1.3 ms | 4.3x |
73
- | groupBy ccy, set/clear | 1.6 ms | 1.2 ms | 1.3x |
74
- | groupBy ccy + exchange, set/clear | 2.2 ms | 2.0 ms | 1.1x |
75
- | scroll, 100 range changes | 0.82 ms | 0.45 ms | 1.8x |
76
- | 1000 ticks, random rows | 1543 ms | 0.35 ms | ~4400x |
77
- | 1000 ticks, rows in viewport | 0.63 ms | 0.10 ms | 6.6x |
78
- | 1000 ticks, sorted column | 3012 ms | 1.9 ms | ~1600x |
79
- | 1000 ticks, filtered column | 1903 ms | 0.55 ms | ~3400x |
80
- | 1000 ticks, grouped | 1205 ms | 0.39 ms | ~3100x |
81
- | 500 deletes + 500 inserts | 1628 ms | 0.60 ms | ~2700x |
82
- | 500 deletes + 500 inserts, sorted | 2564 ms | 1.57 ms | ~1600x |
240
+ | Scenario | legacy | engine | speed-up |
241
+ | --------------------------------- | ------- | ------- | -------- |
242
+ | create + subscribe | 24.1 ms | 8.7 ms | 2.8x |
243
+ | sort numeric column | 62.1 ms | 14.1 ms | 4.4x |
244
+ | sort two columns | 64.6 ms | 17.1 ms | 3.8x |
245
+ | filter | 5.7 ms | 1.3 ms | 4.3x |
246
+ | groupBy ccy, set/clear | 1.6 ms | 1.2 ms | 1.3x |
247
+ | groupBy ccy + exchange, set/clear | 2.2 ms | 2.0 ms | 1.1x |
248
+ | scroll, 100 range changes | 0.82 ms | 0.45 ms | 1.8x |
249
+ | 1000 ticks, random rows | 1543 ms | 0.35 ms | ~4400x |
250
+ | 1000 ticks, rows in viewport | 0.63 ms | 0.10 ms | 6.6x |
251
+ | 1000 ticks, sorted column | 3012 ms | 1.9 ms | ~1600x |
252
+ | 1000 ticks, filtered column | 1903 ms | 0.55 ms | ~3400x |
253
+ | 1000 ticks, grouped | 1205 ms | 0.39 ms | ~3100x |
254
+ | 500 deletes + 500 inserts | 1628 ms | 0.60 ms | ~2700x |
255
+ | 500 deletes + 500 inserts, sorted | 2564 ms | 1.57 ms | ~1600x |
83
256
 
84
257
  Notes:
85
258