Project format updates

This commit is contained in:
Sander Grootendorst
2026-12-01 14:58:50 +01:00
parent 8d0a531084
commit 9339b7a131
17 changed files with 707 additions and 134 deletions
+23 -20
View File
@@ -55,34 +55,37 @@ For directory-backed collections, initialize the empty collection in the selecte
## Specialist viewers for shared data
A supplier viewer and a price-book viewer can each open on their own dataset. ISA Match and other authorised extensions can display that same data. All readers use the existing file or KV store and its schema. The viewer’s extension ID does not determine ownership of the data.
The dashboard exposes two versioned datasets through ordinary workspace files. Each extension obtains its own launch-scoped grant through `openWorkspaceAsset`. A group supplies the requesting user's access context. The workspace owns the data and its checkpoints.
Use `@isa-warden/isa-project-format/shared-folder` with a folder already authorised for the current launch. For data inside an open project, pass `scope: session.scope`, `folder: session.project` and `assertCurrent: session.assertCurrent`. For a separately shared register, use the host-authorised workspace folder and the immutable launch scope. Host grants are per package. Reopening a linked folder uses its valid grant. A new reader needs its own host authorisation for a folder outside the project.
| Asset | Canonical store | Contents |
| --- | --- | --- |
| `suppliers` | `/shared/suppliers/catalog.kv` | Stable supplier IDs, profiles, overrides, import history and enrichments. `catalog/meta.active` selects the generation. |
| `prices` | `/shared/prices/prices.kv` | Comparable price observations, keyed by stable observation ID in the list `observations/v1`. |
Declare `workspace_asset_suppliers_read` or `workspace_asset_prices_read`, plus `filesystem_read` and `kv_store_read`. Editors also need the corresponding asset write permission, `filesystem_write`, `kv_store_write` and effective write access to the folder. Store a supplier ID on a project line. Resolve the ID against the supplier asset when displaying current details. Keep original offers, recipients and sent messages in the project.
```js
import { createSharedFolderReader } from '@isa-warden/isa-project-format/shared-folder';
import { openWorkspaceAsset } from '@isa-warden/isa-project-format/shared-folder';
import { openPriceAsset } from '@isa-warden/isa-project-format/prices';
const reader = createSharedFolderReader({ bridge, scope, folder, assertCurrent });
const index = await reader.readJson('isa-match-suppliers.json');
if (index.status === 'found') {
const register = index.value;
if (register.format !== 'isa-match-workspace-suppliers-v1' ||
register.workspaceId !== scope.workspaceId ||
typeof register.id !== 'string' || !register.id || !Array.isArray(register.suppliers)) {
throw new Error('Unexpected supplier register');
}
const id = encodeURIComponent(register.id);
// The supplier directory contains stable supplier IDs and public identities.
const suppliers = register.suppliers;
// The price-book viewer reads the published price rows from the same folder.
const snapshot = await reader.readKv('isa-match-prices-' + id + '.kv');
const prices = snapshot.entries.filter(entry => entry.key.startsWith('price/'));
const folder = await openWorkspaceAsset({ bridge, scope, asset: 'suppliers', access: 'read' });
const path = folder.path + '/catalog.kv';
const subscription = await bridge.invoke('kv_store_subscribe', { path, keys: ['catalog/meta'] });
try {
const active = subscription.entries.find(entry => entry.key === 'catalog/meta')?.value?.active;
// Subscribe to catalog/<active>/supplier/<id>/profile for the linked IDs in batches.
// Follow mergedInto on old profiles. Rebind the profile subscription when active changes.
} finally {
await bridge.invoke('kv_store_unsubscribe', { path, subscriptionId: subscription.subscriptionId });
}
const prices = await openPriceAsset({ bridge, scope, access: 'read' });
const page = await prices.query({ search: 'asfalt', limit: 30 });
```
For supplier details, read `isa-match-catalog-<encoded register ID>.kv` and the active generation in `catalog/meta`. Profiles use `catalog/<active>/supplier/<supplier ID>/profile`. Use the active generation to exclude retired and staged records. The prices KV contains the shared price book. The separate ISA Prijzenregister searches published records across the workspace. A viewer that only needs suppliers can skip the prices read entirely.
Price values contain `supplier`, `description`, `specItem`, numeric `unitPrice` (including zero), `unit`, `currency` and `receivedAt` (ISO date or empty). Optional `supplierId` links to the shared supplier and `validUntil` holds an ISO date. A writer assigns one stable observation ID per source observation or quotation version. New writers can use a persisted UUID. Project paths, quotations, review notes and commercial terms belong in the project.
`listFiles()` lists the authorised directory. `readFile` and `readJson` distinguish authoritative absence from a failed read. `readKv` pages a consistent snapshot and checks store identity and revision across pages. These operations use the host’s filesystem or KV read access without creating files, modifying records or granting another extension access.
To add price observations, open the price asset with `access: 'read_write'` and call `importRows([{ id, value }])`. Keep the same ID on retries. Re-imports preserve edited values and can attach a supplier ID to an existing observation. Queries accept date ranges, exact field filters, facets and revision-checked paging. Follow the supplier schema's publication rules to update profiles and indexes together. A read-only viewer should handle a missing dataset as a distinct state and surface authorization or transport errors. For arbitrary files in an authorised project or workspace folder, `createSharedFolderReader` supports relative file reads and consistent KV snapshots.
## ZIP transfer