@geode/opengeodeweb-front 12.2.0-rc.4 → 12.2.0-rc.5

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 (115) hide show
  1. package/app/components/ClippingPlanes.vue +1 -1
  2. package/app/components/FactorFilterPanel.vue +1 -1
  3. package/app/components/Launcher.vue +3 -2
  4. package/app/components/ThresholdFilter.vue +1 -2
  5. package/app/components/Viewer/Basemap/CropOptions.vue +7 -8
  6. package/app/components/Viewer/Basemap/OpacityOptions.vue +7 -8
  7. package/app/components/Viewer/ContextMenu/CircularItems.vue +6 -43
  8. package/app/components/Viewer/ContextMenu/ContextMenu.vue +1 -6
  9. package/app/components/Viewer/ContextMenu/ContextMenuItem.vue +14 -16
  10. package/app/components/Viewer/EdgedCurve/PointsOptions.vue +5 -4
  11. package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +10 -13
  12. package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +8 -11
  13. package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +16 -13
  14. package/app/components/Viewer/Generic/Mesh/PointsOptions.vue +28 -31
  15. package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +9 -11
  16. package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +8 -11
  17. package/app/components/Viewer/Generic/Model/BlocksOptions.vue +1 -1
  18. package/app/components/Viewer/Generic/Model/CornersOptions.vue +1 -1
  19. package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +1 -1
  20. package/app/components/Viewer/Generic/Model/EdgesOptions.vue +7 -8
  21. package/app/components/Viewer/Generic/Model/LinesOptions.vue +1 -1
  22. package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +1 -1
  23. package/app/components/Viewer/Generic/Model/ModelEdgesCard.vue +5 -7
  24. package/app/components/Viewer/Generic/Model/ModelPointsCard.vue +5 -7
  25. package/app/components/Viewer/Generic/Model/ModelStyleCard.vue +5 -7
  26. package/app/components/Viewer/Generic/Model/ModelStyleOptions.vue +7 -8
  27. package/app/components/Viewer/Generic/Model/PointsOptions.vue +7 -8
  28. package/app/components/Viewer/Generic/Model/SurfacesOptions.vue +1 -1
  29. package/app/components/Viewer/Grid/2D/CellsOptions.vue +6 -4
  30. package/app/components/Viewer/Grid/2D/EdgesOptions.vue +6 -4
  31. package/app/components/Viewer/Grid/2D/PointsOptions.vue +5 -4
  32. package/app/components/Viewer/Grid/3D/CellsOptions.vue +6 -4
  33. package/app/components/Viewer/Grid/3D/EdgesOptions.vue +6 -4
  34. package/app/components/Viewer/Grid/3D/FacetsOptions.vue +6 -4
  35. package/app/components/Viewer/Grid/3D/PointsOptions.vue +5 -4
  36. package/app/components/Viewer/Image/ImageOptions.vue +10 -13
  37. package/app/components/Viewer/ObjectTree/Base/CommonTreeView.vue +5 -0
  38. package/app/components/Viewer/ObjectTree/Base/ComponentRelations.vue +2 -2
  39. package/app/components/Viewer/ObjectTree/Base/StickyHeader.vue +4 -1
  40. package/app/components/Viewer/ObjectTree/Base/TreeRow.vue +6 -8
  41. package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +10 -15
  42. package/app/components/Viewer/ObjectTree/Views/ModelTree.vue +3 -0
  43. package/app/components/Viewer/PointSet/SpecificPointsOptions.vue +28 -31
  44. package/app/components/Viewer/Scene/BackgroundOptions.vue +4 -7
  45. package/app/components/Viewer/Scene/OrientationWidgetOptions.vue +4 -7
  46. package/app/components/Viewer/Scene/TextOptions.vue +4 -7
  47. package/app/components/Viewer/Solid/EdgesOptions.vue +6 -4
  48. package/app/components/Viewer/Solid/PointsOptions.vue +5 -4
  49. package/app/components/Viewer/Solid/PolygonsOptions.vue +6 -4
  50. package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +8 -11
  51. package/app/components/Viewer/Surface/EdgesOptions.vue +6 -4
  52. package/app/components/Viewer/Surface/PointsOptions.vue +6 -4
  53. package/app/components/Viewer/Surface/PolygonsOptions.vue +8 -11
  54. package/app/components/Viewer/Surface/Triangulated/TrianglesOptions.vue +5 -4
  55. package/app/components/Viewer/TetrahedralSolid/TetrahedraOptions.vue +6 -4
  56. package/app/components/Viewer/TetrahedralSolid/TrianglesOptions.vue +6 -4
  57. package/app/composables/circular_menu.ts +45 -0
  58. package/app/composables/hover_highlight.ts +1 -1
  59. package/app/composables/model_menu_context.ts +7 -11
  60. package/app/composables/model_tree.ts +3 -3
  61. package/app/composables/project_manager_helpers/types.ts +2 -3
  62. package/app/composables/use_overlapping_picker.ts +7 -19
  63. package/app/composables/viewer_context_menu.ts +2 -1
  64. package/app/stores/api.ts +6 -59
  65. package/app/stores/app.ts +21 -55
  66. package/app/stores/back.ts +86 -145
  67. package/app/stores/camera_manager.ts +12 -25
  68. package/app/stores/cloud.ts +21 -101
  69. package/app/stores/crs.ts +3 -2
  70. package/app/stores/data.ts +66 -409
  71. package/app/stores/data_style.ts +99 -93
  72. package/app/stores/feedback.ts +57 -53
  73. package/app/stores/infra.ts +61 -101
  74. package/app/stores/treeview.ts +12 -31
  75. package/app/stores/viewer.ts +9 -29
  76. package/app/stores/viewer_helpers/actions.ts +1 -23
  77. package/app/utils/backend_lifecycle.ts +155 -0
  78. package/app/utils/import_item.ts +5 -4
  79. package/app/utils/threshold_sources.ts +3 -2
  80. package/app/utils/treeview.ts +25 -1
  81. package/app/utils/viewer_object_type.ts +21 -0
  82. package/internal/database/base_database.ts +2 -1
  83. package/internal/database/database.ts +90 -7
  84. package/internal/database/queries.ts +45 -0
  85. package/internal/database/tables/camera_positions.ts +11 -1
  86. package/internal/database/tables/data.ts +20 -1
  87. package/internal/database/tables/data_style.ts +3 -1
  88. package/internal/database/tables/model_component_datastyle.ts +3 -1
  89. package/internal/database/tables/model_component_type_datastyle.ts +3 -1
  90. package/internal/database/tables/model_components.ts +12 -1
  91. package/internal/database/tables/model_components_relation.ts +11 -1
  92. package/internal/database/tables/scene_style.ts +3 -1
  93. package/internal/database/tables/treeview_config.ts +31 -0
  94. package/internal/stores/data/items.ts +110 -0
  95. package/internal/stores/data/model/collections.ts +107 -0
  96. package/internal/stores/data/model/components.ts +129 -0
  97. package/internal/stores/data/model/mesh_components.ts +134 -0
  98. package/internal/stores/data/model/relations.ts +76 -0
  99. package/internal/stores/data/model/types.ts +14 -0
  100. package/internal/stores/data/registration.ts +54 -0
  101. package/internal/stores/data/snapshot.ts +83 -0
  102. package/internal/stores/data/types.ts +26 -0
  103. package/internal/stores/data_style/model/common_mutations.ts +47 -77
  104. package/internal/stores/data_style/model/selection.ts +3 -10
  105. package/internal/stores/data_style/scene.ts +2 -2
  106. package/internal/stores/data_style/state.ts +10 -8
  107. package/internal/stores/data_style/state_shared.ts +10 -7
  108. package/internal/stores/hybrid_viewer/highlight.ts +9 -14
  109. package/internal/stores/hybrid_viewer/scene.ts +1 -1
  110. package/internal/stores/microservice.ts +192 -0
  111. package/package.json +1 -1
  112. package/tests/browser/helpers/data/helpers/attribute.ts +2 -1
  113. package/app/stores/data_helpers/collections.ts +0 -122
  114. package/app/stores/data_helpers/mesh.ts +0 -167
  115. package/app/stores/data_helpers/relations.ts +0 -94
@@ -1,423 +1,78 @@
1
- // oxlint-disable eslint/max-lines
2
- // Third party imports
3
- import type { CRS } from "@geode/opengeodeweb-back/schema_types";
4
- import type { Table } from "dexie";
5
- import { useObservable } from "@vueuse/rxjs";
6
- import viewer_schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_typed_schemas.js";
1
+ import {
2
+ type DataSnapshot,
3
+ clearTables,
4
+ deleteItem,
5
+ exportStores,
6
+ importTables,
7
+ } from "@ogw_internal/stores/data/snapshot";
8
+ import {
9
+ addComponentRelations,
10
+ addComponents,
11
+ getAllModelComponentsViewerIds,
12
+ getComponentByViewerId,
13
+ getComponentsByViewerIds,
14
+ getMeshComponentsViewerIds,
15
+ meshComponentType,
16
+ } from "@ogw_internal/stores/data/model/components";
17
+ import {
18
+ addItem,
19
+ allItems,
20
+ fetchIsViewable,
21
+ item,
22
+ refItem,
23
+ updateItem,
24
+ useDataItems,
25
+ } from "@ogw_internal/stores/data/items";
26
+ import {
27
+ fetchAllCollectionComponents,
28
+ formatedCollectionComponents,
29
+ getAllCollectionComponents,
30
+ hasCollectionComponents,
31
+ refFormatedCollectionComponents,
32
+ } from "@ogw_internal/stores/data/model/collections";
33
+ import {
34
+ fetchAllComponentRelations,
35
+ getComponentRelations,
36
+ } from "@ogw_internal/stores/data/model/relations";
37
+ import {
38
+ fetchAllMeshComponents,
39
+ formatedMeshComponents,
40
+ getAllMeshComponents,
41
+ getBlocksGeodeIds,
42
+ getCornersGeodeIds,
43
+ getLinesGeodeIds,
44
+ getMeshComponentGeodeIds,
45
+ getMeshComponentsByType,
46
+ getSurfacesGeodeIds,
47
+ refFormatedMeshComponents,
48
+ } from "@ogw_internal/stores/data/model/mesh_components";
49
+ import { useDataRegistration } from "@ogw_internal/stores/data/registration";
7
50
 
8
- // Local imports
9
- import type { DataId, GeodeId } from "@geode/opengeodeweb-microservice/schema_types";
10
- import type {
11
- DataIdentified,
12
- GeodeIdentified,
13
- GeodeObjectTyped,
14
- ModelId,
15
- ViewerObjectTyped,
16
- } from "@ogw_front/types/identifiers";
17
- import { type LegacyDataId, fromLegacyDataId } from "@ogw_front/utils/legacy_data_id";
18
- import { type ModelComponentRecord, useDataMesh } from "./data_helpers/mesh.js";
19
- import { type ModelComponentRelationRecord, useDataRelations } from "./data_helpers/relations.js";
20
- import { database } from "@ogw_internal/database/database.js";
21
- import { liveObservable } from "@ogw_front/utils/live_observable";
22
- import { useDataCollections } from "./data_helpers/collections.js";
23
- import { useViewerStore } from "@ogw_front/stores/viewer";
24
-
25
- interface DataItem extends DataIdentified, GeodeIdentified, GeodeObjectTyped, ViewerObjectTyped {
26
- name: string;
27
- visible: boolean;
28
- created_at: string;
29
- is_viewable?: boolean;
30
- binary_light_viewable?: string;
31
- crs?: CRS;
32
- }
33
-
34
- // What the CRS features read of a data: light to copy on each change
35
- type CrsItem = Pick<DataItem, "data_id" | "name" | "crs" | "created_at">;
36
-
37
- interface ModelComponentInput extends GeodeIdentified {
38
- type: string;
39
- viewer_id: string | number;
40
- name: string;
41
- is_active: boolean;
42
- boundaries?: string[];
43
- internals?: string[];
44
- items?: string[];
45
- }
46
-
47
- interface NewDataItem extends DataIdentified, GeodeIdentified, GeodeObjectTyped, ViewerObjectTyped {
48
- name?: string;
49
- is_viewable?: boolean;
50
- binary_light_viewable?: string;
51
- crs?: CRS;
52
- // Set on saved data: kept by the project snapshot
53
- created_at?: string;
54
- mesh_components?: ModelComponentInput[];
55
- collection_components?: ModelComponentInput[];
56
- nb_vertices?: number;
57
- }
58
-
59
- interface ViewableItemLike extends Partial<GeodeObjectTyped> {
60
- is_viewable?: boolean;
61
- binary_light_viewable?: string;
62
- data_id?: DataId;
63
- title?: string;
64
- }
65
-
66
- const viewer_generic_schemas = viewer_schemas.opengeodeweb_viewer.generic;
67
- // 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.
68
- type DatabaseTables = Record<string, unknown>;
69
- // oxlint-disable-next-line no-unsafe-type-assertion -- see comment above.
70
- const typedDatabase = database as unknown as DatabaseTables;
71
- function checkItemViewable(item: ViewableItemLike | undefined | null): boolean {
72
- if (!item || typeof item !== "object") {
73
- return false;
74
- }
75
- if (item.is_viewable !== undefined) {
76
- return item.is_viewable;
77
- }
78
- if (item.binary_light_viewable !== undefined) {
79
- return item.binary_light_viewable !== "not_viewable";
80
- }
81
- if (
82
- item.geode_object_type === "HorizonStack3D" ||
83
- item.data_id === "HorizonStack3D" ||
84
- item.title === "HorizonStack3D"
85
- ) {
86
- return false;
87
- }
88
- return true;
89
- }
90
- function isItemViewable(itemOrId: string | ViewableItemLike): boolean | Promise<boolean> {
91
- if (typeof itemOrId === "string") {
92
- // oxlint-disable-next-line no-unsafe-type-assertion -- database's table map is dynamically typed at runtime; see comment above.
93
- return (typedDatabase.data as Table<DataItem, string>).get(itemOrId).then(checkItemViewable);
94
- }
95
- return checkItemViewable(itemOrId);
96
- }
97
-
98
- // oxlint-disable-next-line max-lines-per-function, max-statements
51
+ // oxlint-disable-next-line max-lines-per-function
99
52
  export const useDataStore = defineStore("data", () => {
100
- const viewerStore = useViewerStore();
101
- // oxlint-disable-next-line no-unsafe-type-assertion -- database's table map is dynamically typed at runtime; see comment above.
102
- const data_db = typedDatabase.data as Table<DataItem, string>;
103
- // oxlint-disable-next-line no-unsafe-type-assertion -- database's table map is dynamically typed at runtime; see comment above.
104
- const model_components_db = typedDatabase.model_components as Table<ModelComponentRecord, string>;
105
- // oxlint-disable-next-line no-unsafe-type-assertion -- database's table map is dynamically typed at runtime; see comment above.
106
- const model_components_relation_db = typedDatabase.model_components_relation as Table<
107
- ModelComponentRelationRecord,
108
- string
109
- >;
110
- const {
111
- formatedMeshComponents,
112
- refFormatedMeshComponents,
113
- getMeshComponentsByType,
114
- getAllMeshComponents,
115
- fetchAllMeshComponents,
116
- getMeshComponentGeodeIds,
117
- getCornersGeodeIds,
118
- getLinesGeodeIds,
119
- getSurfacesGeodeIds,
120
- getBlocksGeodeIds,
121
- } = useDataMesh();
122
- const {
123
- hasCollectionComponents,
124
- getAllCollectionComponents,
125
- fetchAllCollectionComponents,
126
- formatedCollectionComponents,
127
- refFormatedCollectionComponents,
128
- } = useDataCollections();
129
- const { getComponentRelations, fetchAllComponentRelations } = useDataRelations();
130
- // Ids the viewer holds a pipeline for: an item is stored before it is registered, and non viewable items never are
131
- const registeredIds = reactive(new Set<string>());
132
- async function item(dataId: DataId): Promise<DataItem> {
133
- const data_item = await data_db.get(dataId);
134
- if (!data_item) {
135
- throw new Error(`Item not found: ${dataId}`);
136
- }
137
- return data_item;
138
- }
139
- async function allItems(): Promise<DataItem[]> {
140
- const items = await data_db.toArray();
141
- return items;
142
- }
143
- function refItem(dataId: DataId): Ref<DataItem | undefined> {
144
- return useObservable(
145
- liveObservable(async () => {
146
- const data_item = await data_db.get(dataId);
147
- return data_item;
148
- }),
149
- {
150
- // oxlint-disable-next-line no-unsafe-type-assertion -- placeholder until the live query resolves; consumers must treat this as possibly incomplete.
151
- initialValue: {} as DataItem,
152
- },
153
- );
154
- }
155
- // The CRS features only need these fields: the geometry stays out of the copies made on each change
156
- function refCrsItems(): Ref<CrsItem[]> {
157
- return useObservable(
158
- liveObservable(async () => {
159
- const items = await data_db.toArray();
160
- return items.map(({ data_id, name, crs, created_at }) => ({
161
- data_id,
162
- name,
163
- crs,
164
- created_at,
165
- }));
166
- }),
167
- { initialValue: [] as CrsItem[] },
168
- );
169
- }
170
-
171
- function refAllItems(): Ref<DataItem[]> {
172
- return useObservable(
173
- liveObservable(async () => {
174
- const items = await data_db.toArray();
175
- return items;
176
- }),
177
- {
178
- initialValue: [] as DataItem[],
179
- },
180
- );
181
- }
182
- function isRegistered(dataId: DataId): boolean {
183
- return registeredIds.has(dataId);
184
- }
185
- function refRegisteredItems(): ComputedRef<DataItem[]> {
186
- const items = refAllItems();
187
- return computed(() => items.value.filter((data_item) => isRegistered(data_item.data_id)));
188
- }
189
- async function meshComponentType(
190
- modelId: ModelId,
191
- geode_id: GeodeId,
192
- ): Promise<string | undefined> {
193
- const component = await model_components_db
194
- .where("[data_id+geode_id]")
195
- .equals([modelId, geode_id])
196
- .first();
197
- return component?.type;
198
- }
199
- async function registerObject(dataId: DataId, name: string): Promise<unknown> {
200
- const schema = viewer_generic_schemas.register;
201
- const params = {
202
- id: dataId,
203
- name,
204
- };
205
- const result = await viewerStore.request({
206
- schema,
207
- params,
208
- timeout: 0,
209
- });
210
- registeredIds.add(dataId);
211
- return result;
212
- }
213
- async function deregisterObject(dataId: DataId): Promise<unknown> {
214
- const schema = viewer_generic_schemas.deregister;
215
- const params = {
216
- id: dataId,
217
- };
218
- registeredIds.delete(dataId);
219
- const result = await viewerStore.request({
220
- schema,
221
- params,
222
- });
223
- return result;
224
- }
225
- // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
226
- // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
227
- async function addItem(new_item: NewDataItem): Promise<string> {
228
- const itemData: DataItem = {
229
- data_id: new_item.data_id,
230
- geode_id: new_item.geode_id,
231
- name: new_item.name ?? new_item.data_id,
232
- viewer_object_type: new_item.viewer_object_type,
233
- geode_object_type: new_item.geode_object_type,
234
- visible: true,
235
- created_at: new Date().toISOString(),
236
- is_viewable: new_item.is_viewable,
237
- };
238
- if (new_item.binary_light_viewable !== undefined && new_item.binary_light_viewable !== null) {
239
- itemData.binary_light_viewable = new_item.binary_light_viewable;
240
- }
241
- if (new_item.crs !== undefined) {
242
- itemData.crs = new_item.crs;
243
- }
244
- const dataId = await data_db.put(itemData);
245
- return dataId;
246
- }
247
- // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
248
- // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
249
- async function addComponents(new_item: NewDataItem): Promise<string> {
250
- const allComponents: ModelComponentRecord[] = [];
251
- // ModelComponentInput has mutable array fields (boundaries, internals, items), so a readonly
252
- // Array of it can't satisfy prefer-readonly-parameter-types deeply; same limitation as above.
253
- function addModelComponents(components: readonly ModelComponentInput[]): void {
254
- for (const component of components) {
255
- allComponents.push({
256
- data_id: new_item.data_id,
257
- geode_id: component.geode_id,
258
- type: component.type,
259
- viewer_id: component.viewer_id,
260
- name: component.name,
261
- is_active: component.is_active,
262
- });
263
- }
264
- }
265
- if (new_item.mesh_components) {
266
- addModelComponents(new_item.mesh_components);
267
- }
268
- if (new_item.collection_components) {
269
- addModelComponents(new_item.collection_components);
270
- }
271
- const lastKey = await model_components_db.bulkPut(allComponents);
272
- return lastKey;
273
- }
274
- // NewDataItem has mutable array fields (mesh_components, collection_components), so it can't
275
- // Satisfy prefer-readonly-parameter-types deeply; same pattern as app/utils/import_workflow.ts.
276
- async function addComponentRelations(new_item: NewDataItem): Promise<string> {
277
- const relations: ModelComponentRelationRecord[] = [];
278
- function addModelComponentRelations(
279
- components: readonly string[],
280
- parent: string,
281
- type: string,
282
- ): void {
283
- for (const child of components) {
284
- relations.push({
285
- data_id: new_item.data_id,
286
- parent,
287
- child,
288
- type,
289
- });
290
- }
291
- }
292
- if (new_item.mesh_components) {
293
- for (const component of new_item.mesh_components) {
294
- if (component.boundaries) {
295
- addModelComponentRelations(component.boundaries, component.geode_id, "boundary");
296
- }
297
- if (component.internals) {
298
- addModelComponentRelations(component.internals, component.geode_id, "internal");
299
- }
300
- }
301
- }
302
- if (new_item.collection_components) {
303
- for (const component of new_item.collection_components) {
304
- if (component.items) {
305
- addModelComponentRelations(component.items, component.geode_id, "collection");
306
- }
307
- }
308
- }
309
- const lastKey = await model_components_relation_db.bulkPut(relations);
310
- return lastKey;
311
- }
312
- async function getComponentByViewerId(
313
- modelId: ModelId,
314
- viewer_id: string | number,
315
- ): Promise<ModelComponentRecord | undefined> {
316
- const component = await model_components_db
317
- .where("viewer_id")
318
- .equals(Number(viewer_id))
319
- .and((model_component: ModelComponentRecord) => model_component.data_id === modelId)
320
- .first();
321
- return component;
322
- }
323
- async function getComponentsByViewerIds(
324
- modelId: ModelId,
325
- viewer_ids: number[],
326
- ): Promise<ModelComponentRecord[]> {
327
- const components = await model_components_db
328
- .where("viewer_id")
329
- .anyOf(viewer_ids)
330
- .and((model_component: ModelComponentRecord) => model_component.data_id === modelId)
331
- .toArray();
332
- return components;
333
- }
334
- async function deleteModelComponents(modelId: ModelId): Promise<void> {
335
- await model_components_db.where("data_id").equals(modelId).delete();
336
- await model_components_relation_db.where("data_id").equals(modelId).delete();
337
- }
338
-
339
- async function deleteItem(dataId: DataId): Promise<void> {
340
- await data_db.delete(dataId);
341
- await deleteModelComponents(dataId);
342
- }
343
-
344
- async function updateItem(dataId: DataId, changes: Partial<DataItem>): Promise<void> {
345
- await data_db.update(dataId, changes);
346
- }
347
-
348
- async function getAllModelComponentsViewerIds(modelId: ModelId): Promise<number[]> {
349
- const components = await model_components_db.where("data_id").equals(modelId).toArray();
350
- return components.map((component: ModelComponentRecord) =>
351
- Math.trunc(Number(component.viewer_id)),
352
- );
353
- }
354
- async function getMeshComponentsViewerIds(
355
- modelId: ModelId,
356
- meshComponentGeodeIds: readonly string[],
357
- ): Promise<number[]> {
358
- const components = await model_components_db
359
- .where("[data_id+geode_id]")
360
- .anyOf(meshComponentGeodeIds.map((geode_id) => [modelId, geode_id]))
361
- .toArray();
362
- return components.map((component: ModelComponentRecord) =>
363
- Math.trunc(Number(component.viewer_id)),
364
- );
365
- }
366
- async function exportStores(): Promise<{
367
- items: DataItem[];
368
- modelComponents: ModelComponentRecord[];
369
- modelComponentsRelations: ModelComponentRelationRecord[];
370
- }> {
371
- const items = await data_db.toArray();
372
- const modelComponents = await model_components_db.toArray();
373
- const modelComponentsRelations = await model_components_relation_db.toArray();
374
- return {
375
- items,
376
- modelComponents,
377
- modelComponentsRelations,
378
- };
379
- }
53
+ const { items, isViewable } = useDataItems();
54
+ const { registeredItems, isRegistered, registerObject, deregisterObject, clearRegistrations } =
55
+ useDataRegistration(items);
380
56
 
381
57
  async function clear(): Promise<void> {
382
- registeredIds.clear();
383
- await data_db.clear();
384
- await model_components_db.clear();
385
- await model_components_relation_db.clear();
58
+ clearRegistrations();
59
+ await clearTables();
386
60
  }
387
61
 
388
- // Dexie's bulkPut expects mutable arrays, so this snapshot parameter can't deeply satisfy
389
- // The prefer-readonly-parameter-types rule; same pattern as app/utils/import_workflow.ts.
390
- async function importStores(snapshot: {
391
- readonly modelComponents: readonly (
392
- | LegacyDataId<ModelComponentRecord>
393
- | ModelComponentRecord
394
- )[];
395
- readonly modelComponentsRelations: readonly (
396
- | LegacyDataId<ModelComponentRelationRecord>
397
- | ModelComponentRelationRecord
398
- )[];
399
- }): Promise<void> {
400
- await clear();
401
- await model_components_db.bulkPut(
402
- snapshot.modelComponents.map((component) =>
403
- fromLegacyDataId<ModelComponentRecord>(component),
404
- ),
405
- );
406
- await model_components_relation_db.bulkPut(
407
- snapshot.modelComponentsRelations.map((relation) =>
408
- fromLegacyDataId<ModelComponentRelationRecord>(relation),
409
- ),
410
- );
62
+ async function importStores(snapshot: DataSnapshot): Promise<void> {
63
+ clearRegistrations();
64
+ await importTables(snapshot);
411
65
  }
66
+
412
67
  return {
413
- refAllItems,
414
- refCrsItems,
415
- refRegisteredItems,
68
+ items,
69
+ registeredItems,
416
70
  isRegistered,
417
71
  item,
418
72
  allItems,
419
73
  refItem,
420
- isItemViewable,
74
+ isViewable,
75
+ fetchIsViewable,
421
76
  meshComponentType,
422
77
  registerObject,
423
78
  deregisterObject,
@@ -453,4 +108,6 @@ export const useDataStore = defineStore("data", () => {
453
108
  };
454
109
  });
455
110
 
456
- export type { CrsItem, DataItem, NewDataItem, ModelComponentInput };
111
+ export type { CrsItem, NewDataItem } from "@ogw_internal/stores/data/types";
112
+ export type { ModelComponentInput } from "@ogw_internal/stores/data/model/types";
113
+ export type { DataItem } from "@ogw_internal/database/tables/data";