@geode/opengeodeweb-front 11.0.0 → 11.0.1-rc.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.
@@ -13,10 +13,9 @@ import type {
13
13
  ViewerType,
14
14
  ViewerTyped,
15
15
  } from "@ogw_front/types/identifiers";
16
- import type { Table } from "dexie";
17
16
  import type { TreeGroup, TreeNode } from "@ogw_front/types/tree";
18
17
  import { ref, watch } from "vue";
19
- import { database } from "@ogw_internal/database/database";
18
+ import { getTable } from "@ogw_internal/database/database";
20
19
 
21
20
  const PANEL_WIDTH = 300;
22
21
 
@@ -90,12 +89,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
90
89
  const pendingSelectionIds = ref<string[]>([]);
91
90
  const rowHeights = ref<number[]>([]);
92
91
 
93
- // The database's table map is dynamically assembled at runtime (see internal/database/database.ts), so its exported type is a loose `{}`; cast it to the shape it actually has at runtime rather than widening every call site.
94
- type DatabaseTables = Record<string, unknown>;
95
- // oxlint-disable-next-line no-unsafe-type-assertion -- database's table map is dynamically typed at runtime; see comment above.
96
- const typedDatabase = database as unknown as DatabaseTables;
97
- // oxlint-disable-next-line no-unsafe-type-assertion -- database's table map is dynamically typed at runtime; see comment above.
98
- const treeview_config_db = typedDatabase.treeview_config as Table<TreeviewConfigRecord, string>;
92
+ const treeview_config_db = getTable<TreeviewConfigRecord>("treeview_config");
99
93
 
100
94
  async function loadConfig(): Promise<void> {
101
95
  try {
@@ -116,7 +110,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
116
110
  rowHeights.value = config.rowHeights;
117
111
  }
118
112
  } catch (error) {
119
- consola.error("Failed to load treeview config:", error);
113
+ consola.error("Failed to load treeview config:", String(error));
120
114
  }
121
115
  }
122
116
  // oxlint-disable-next-line typescript/no-floating-promises -- loadConfig catches its own errors internally.
@@ -124,7 +118,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
124
118
 
125
119
  watch(
126
120
  [opened_views, panelWidth, additionalPanelWidth, selection, rowHeights],
127
- () => {
121
+ async () => {
128
122
  // oxlint-disable-next-line unicorn/prefer-structured-clone, no-unsafe-type-assertion -- JSON round-trip of a known-shape ref; result matches the source type.
129
123
  const clean_opened_views = JSON.parse(JSON.stringify(opened_views.value)) as OpenedView[];
130
124
  // oxlint-disable-next-line unicorn/prefer-structured-clone, no-unsafe-type-assertion -- JSON round-trip of a known-shape ref; result matches the source type.
@@ -132,15 +126,19 @@ export const useTreeviewStore = defineStore("treeview", () => {
132
126
  // oxlint-disable-next-line unicorn/prefer-structured-clone, no-unsafe-type-assertion -- JSON round-trip of a known-shape ref; result matches the source type.
133
127
  const clean_rowHeights = JSON.parse(JSON.stringify(rowHeights.value)) as number[];
134
128
 
135
- // oxlint-disable-next-line typescript/no-floating-promises -- best-effort persistence; failures aren't actionable here.
136
- treeview_config_db.put({
137
- id: "main",
138
- opened_views: clean_opened_views,
139
- panelWidth: panelWidth.value,
140
- additionalPanelWidth: additionalPanelWidth.value,
141
- selectionIds: clean_selectionIds,
142
- rowHeights: clean_rowHeights,
143
- });
129
+ // Best-effort persistence: a failure is logged, not thrown.
130
+ try {
131
+ await treeview_config_db.put({
132
+ id: "main",
133
+ opened_views: clean_opened_views,
134
+ panelWidth: panelWidth.value,
135
+ additionalPanelWidth: additionalPanelWidth.value,
136
+ selectionIds: clean_selectionIds,
137
+ rowHeights: clean_rowHeights,
138
+ });
139
+ } catch (error) {
140
+ consola.error("Failed to save treeview config:", String(error));
141
+ }
144
142
  },
145
143
  { deep: true },
146
144
  );
@@ -94,27 +94,64 @@ await initialDatabase.clear();
94
94
  // The set of tables is assembled dynamically at runtime (Database.addTable/addTables add stores on the fly), so fully modelling this with Dexie's row generics isn't worth it here: the proxy target is typed loosely as "any table name maps to a Dexie Table of loosely-typed rows".
95
95
  type DatabaseTables = Record<string, Table<Record<string, unknown>, string>>;
96
96
 
97
+ // Database.addTables closes the current instance and opens a new one, so a table taken from an instance must not be kept: a store keeping it would query a closed database.
98
+ // A live table resolves the table of the current instance at each access instead.
99
+ function currentInstance(): Dexie {
100
+ // Set at module load time below; always defined by the time the database is used.
101
+ if (!databaseContainer.instance) {
102
+ throw new Error("The database is not open");
103
+ }
104
+ return databaseContainer.instance;
105
+ }
106
+
107
+ function liveTable<TRow>(tableName: string): Table<TRow, string> {
108
+ const handler: ProxyHandler<object> = {
109
+ get(_target, prop: string | symbol): unknown {
110
+ const table = currentInstance().table(tableName);
111
+ const value: unknown = Reflect.get(table, prop, table);
112
+ if (typeof value === "function") {
113
+ // oxlint-disable-next-line no-unsafe-return
114
+ return value.bind(table);
115
+ }
116
+ return value;
117
+ },
118
+ // Dexie checks that the tables given to a transaction are instances of its Table.
119
+ getPrototypeOf(): object | null {
120
+ return Reflect.getPrototypeOf(currentInstance().table(tableName));
121
+ },
122
+ };
123
+ // oxlint-disable-next-line no-unsafe-type-assertion -- the proxy forwards every access to a Dexie Table.
124
+ return new Proxy({}, handler) as Table<TRow, string>;
125
+ }
126
+
127
+ function isTableName(instance: Dexie, prop: string | symbol): prop is string {
128
+ return typeof prop === "string" && instance.tables.some((table) => table.name === prop);
129
+ }
130
+
97
131
  const database = new Proxy<DatabaseTables>(
98
132
  {},
99
133
  {
100
134
  get(_target, prop: string | symbol): unknown {
135
+ const dexie = currentInstance();
136
+ if (isTableName(dexie, prop)) {
137
+ return liveTable(prop);
138
+ }
101
139
  // The instance is a Dexie subclass whose tables are only known dynamically at runtime.
102
140
  // oxlint-disable-next-line no-unsafe-type-assertion
103
- const instance = databaseContainer.instance as unknown as Record<string | symbol, unknown>;
141
+ const instance = dexie as unknown as Record<string | symbol, unknown>;
104
142
  const value = instance[prop];
105
143
  if (typeof value === "function") {
106
144
  // oxlint-disable-next-line no-unsafe-return
107
- return value.bind(databaseContainer.instance);
145
+ return value.bind(dexie);
108
146
  }
109
147
  return value;
110
148
  },
111
149
  },
112
150
  );
113
151
 
114
- // The proxy only knows the loose DatabaseTables shape; callers cast to the row type they know a given table holds.
152
+ // Callers cast to the row type they know a given table holds.
115
153
  function getTable<TRow>(tableName: string): Table<TRow, string> {
116
- // oxlint-disable-next-line no-unsafe-type-assertion
117
- return database[tableName] as unknown as Table<TRow, string>;
154
+ return liveTable<TRow>(tableName);
118
155
  }
119
156
 
120
157
  export { Database, database, getTable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geode/opengeodeweb-front",
3
- "version": "11.0.0",
3
+ "version": "11.0.1-rc.1",
4
4
  "description": "OpenSource Vue/Nuxt/Pinia/Vuetify framework for web applications",
5
5
  "homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Front",
6
6
  "bugs": {
@@ -64,9 +64,9 @@
64
64
  "prepublishOnly": "npm run build"
65
65
  },
66
66
  "dependencies": {
67
- "@geode/cloud-api": "latest",
68
- "@geode/opengeodeweb-back": "latest",
69
- "@geode/opengeodeweb-viewer": "latest",
67
+ "@geode/cloud-api": "next",
68
+ "@geode/opengeodeweb-back": "next",
69
+ "@geode/opengeodeweb-viewer": "next",
70
70
  "@kitware/vtk.js": "33.3.0",
71
71
  "@mdi/font": "7.4.47",
72
72
  "@msgpack/msgpack": "2.8.0",