@septkit/shell-lib 0.0.33 → 0.0.35

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/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export type * from './types';
2
2
  export { SHELL_DB_PREFIX, LIBRARY_DB_PREFIX, TEMP_DOCUMENT_PREFIX, TEMP_PROJECT_PREFIX, RESERVED_DB_PREFIXES, isReservedDatabaseName, } from './constants';
3
- export { setShellContext, clearShellContext, getProject, getActiveDocumentId, getCommands, getStorageSources, getPwa, } from './shell-context';
3
+ export { setShellContext, clearShellContext, getProject, getActiveDocumentId, getCommands, getStorageSources, getPwa, getProjectStorage, } from './shell-context';
package/dist/index.js CHANGED
@@ -9,206 +9,588 @@ function a(e) {
9
9
  return i.some((t) => e.startsWith(t));
10
10
  }
11
11
  //#endregion
12
- //#region node_modules/.pnpm/@dialecte+core@0.6.1/node_modules/@dialecte/core/dist/utils-CTBHUFs9.js
13
- var o = {
12
+ //#region node_modules/.pnpm/@dialecte+core@0.9.0/node_modules/@dialecte/core/dist/utils-Cv4oHia0.js
13
+ var o = "https://dialecte.github.io/core", s = /* @__PURE__ */ new Set([
14
+ "throwDialecteError",
15
+ "createDialecteError",
16
+ "invariant",
17
+ "reportFailure"
18
+ ]), c = {
14
19
  UNKNOWN: {
15
20
  code: "D0001",
16
- message: "An unknown error occurred"
21
+ message: "An unknown error occurred",
22
+ explanation: {
23
+ when: "A transaction's callback threw something that is not a structured error (a plain `Error`, a value); the original is its `cause`.",
24
+ fix: "Read `cause` and `detail`; raise your own failures with `throwDialecteError` or `invariant` so callers get a key.",
25
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
26
+ }
17
27
  },
18
28
  ASSERTION_FAILED: {
19
29
  code: "D0002",
20
- message: "Assertion failed"
30
+ message: "Assertion failed",
31
+ explanation: {
32
+ when: "An `invariant` without its own key failed, or core met a state it never expects (a catalogue built wrong, an inconsistent export, a store running on a dependency older than the one it supports).",
33
+ fix: "Read `detail`: it names the condition. Give `invariant` a key of its own when the failure is one a caller should handle.",
34
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
35
+ }
21
36
  },
22
37
  STORE_CONNECTION_FAILED: {
23
38
  code: "D1001",
24
- message: "Failed to open database"
39
+ message: "Failed to open database",
40
+ explanation: {
41
+ when: "The store could not open the project's data, or could not reach what serves it (its database, a worker, a server): it failed to start, was blocked, or went unanswered; the failure is the `cause` when there is one.",
42
+ fix: "Check the browser supports what the store needs and that no other tab holds the project; reload, or open the project with another storage. The store's own docs name what it needs.",
43
+ docs: `${o}/api/project#store-errors`
44
+ }
25
45
  },
26
46
  STORE_COMMIT_FAILED: {
27
47
  code: "D1002",
28
- message: "Failed to commit changes"
48
+ message: "Failed to commit changes",
49
+ explanation: {
50
+ when: "The database refused a transaction's write as it committed (the failure is the `cause`).",
51
+ fix: "Read `cause`; a full disk or a lost connection are the usual reasons. Retry the transaction once the store is back.",
52
+ docs: `${o}/api/project#store-errors`
53
+ }
29
54
  },
30
55
  STORE_RECORD_NOT_FOUND: {
31
56
  code: "D1003",
32
- message: "Record not found in database"
57
+ message: "Record not found in database",
58
+ explanation: {
59
+ when: "A write updated or deleted a record the store does not hold in that document.",
60
+ fix: "Read the record again before writing: it was deleted, or the ref names another document.",
61
+ docs: `${o}/api/project#store-errors`
62
+ }
33
63
  },
34
64
  STORE_BULK_ADD_FAILED: {
35
65
  code: "D1004",
36
- message: "Failed to add records to database"
66
+ message: "Failed to add records to database",
67
+ explanation: {
68
+ when: "The database refused to add a batch of records (import, commit); the failure is the `cause`.",
69
+ fix: "Read `cause`; a full disk or a closed store are the usual reasons.",
70
+ docs: `${o}/api/project#store-errors`
71
+ }
37
72
  },
38
73
  STORE_BULK_UPDATE_FAILED: {
39
74
  code: "D1005",
40
- message: "Failed to update records in database"
75
+ message: "Failed to update records in database",
76
+ explanation: {
77
+ when: "The database refused to update a batch of records; the failure is the `cause`.",
78
+ fix: "Read `cause`; a full disk or a closed store are the usual reasons.",
79
+ docs: `${o}/api/project#store-errors`
80
+ }
41
81
  },
42
82
  STORE_DELETE_FAILED: {
43
83
  code: "D1006",
44
- message: "Failed to delete records from database"
84
+ message: "Failed to delete records from database",
85
+ explanation: {
86
+ when: "The database refused to delete records; the failure is the `cause`.",
87
+ fix: "Read `cause`; a closed store is the usual reason.",
88
+ docs: `${o}/api/project#store-errors`
89
+ }
45
90
  },
46
91
  STORE_NOT_WRITABLE: {
47
92
  code: "D1007",
48
- message: "Store is not writable"
93
+ message: "Store is not writable",
94
+ explanation: {
95
+ when: "A write reached an in-memory store created read-only.",
96
+ fix: "Create the project with `storage: { type: 'inMemory', writable: true }` when the script writes.",
97
+ docs: `${o}/api/project#in-memory-storage`
98
+ }
49
99
  },
50
100
  STORE_BLOB_NOT_FOUND: {
51
101
  code: "D1008",
52
- message: "Blob not found"
102
+ message: "Blob not found",
103
+ explanation: {
104
+ when: "A blob operation named a blob id the store does not hold.",
105
+ fix: "List the blobs (`project.getBlobsByDocument`) and use an id from there.",
106
+ docs: `${o}/api/project#blobs`
107
+ }
108
+ },
109
+ STORE_DUPLICATE_ID: {
110
+ code: "D1009",
111
+ message: "An id is already taken in the store",
112
+ explanation: {
113
+ when: "A write would create a record (or register a document) with an id the store already holds; `meta.recordIds` lists them.",
114
+ fix: "Let core mint ids (omit `id`), or pick ids no record of the document has; `deepClone` mints new ids itself.",
115
+ docs: `${o}/api/project#store-errors`
116
+ }
117
+ },
118
+ STORE_CLOSED: {
119
+ code: "D1010",
120
+ message: "Store is closed",
121
+ explanation: {
122
+ when: "A store operation was still in flight when its store closed, or code holding the store itself (a custom store, a test context) called it after its `close()`. A project closed with `project.close()` answers `PROJECT_NOT_OPENED` instead.",
123
+ fix: "Await every operation before closing the store or the project; open it again before using it.",
124
+ docs: `${o}/api/project#lifecycle`
125
+ }
126
+ },
127
+ STORE_READ_FAILED: {
128
+ code: "D1011",
129
+ message: "Failed to read from database",
130
+ explanation: {
131
+ when: "The store's database failed under a read; the failure is the `cause`.",
132
+ fix: "Read `cause`; reopen the project. A lasting failure means the file is damaged: import its documents again.",
133
+ docs: `${o}/api/project#store-errors`
134
+ }
135
+ },
136
+ STORE_VALUE_NOT_JSON: {
137
+ code: "D1015",
138
+ message: "A value handed to the store is not JSON",
139
+ explanation: {
140
+ when: "A write handed the store a value that is not plain JSON (a function, a Map, undefined, a class instance) in a record or in document metadata.",
141
+ fix: "Pass plain strings, numbers, booleans, arrays and objects; `detail` names the value and the field.",
142
+ docs: `${o}/io/#values-a-store-keeps`
143
+ }
144
+ },
145
+ STORE_UNAVAILABLE: {
146
+ code: "D1016",
147
+ message: "This browser gives the page no storage for a project",
148
+ explanation: {
149
+ when: "The browser gives the page none of the storage the store needs (a private window, an API the browser lacks), so it cannot create, open or destroy the project; nothing is changed.",
150
+ fix: "Open the app in a normal (not private) window of a browser that supports what the project's store needs, or open the project with another storage.",
151
+ docs: `${o}/api/project#store-errors`
152
+ }
153
+ },
154
+ STORE_QUOTA_EXCEEDED: {
155
+ code: "D1017",
156
+ message: "Not enough storage left for the project",
157
+ explanation: {
158
+ when: "The origin has too little storage left for what the call needs (a new project's files, an import's room ahead of it), or the store's storage refused a write for want of space; nothing of the call applied. A store that checks the room it needs answers it; the local (IndexedDB) store answers the failing write's own error (`STORE_COMMIT_FAILED`, `STORE_BULK_ADD_FAILED`, `STORE_BULK_UPDATE_FAILED`; an import `IMPORT_FAILED`); the in-memory store has no limit.",
159
+ fix: "Free storage for the origin (delete projects no longer needed) or import a smaller file, then try again; `meta.needed` and `meta.available` give the sizes when known.",
160
+ docs: `${o}/api/project#store-errors`
161
+ }
162
+ },
163
+ STORE_CONNECTION_LOST: {
164
+ code: "D1018",
165
+ message: "The store lost its connection",
166
+ explanation: {
167
+ when: "A call to a store whose project is served elsewhere (a worker, another realm, a server) lost its connection to what serves it: that went away or gave no answer within its budget, sent nothing for too long while the call waited (the call may still finish), or dropped this view. `meta.reason` is the store's own word for why, listed in its docs; a write's refusal carries `meta.writeId`.",
168
+ fix: "A Document's commit and a Project's import ask the outcome themselves, once: a commit that landed resolves; otherwise the refusal says `meta.outcome` - `not-applied` (make it again if wanted), `running` (what serves the store may still apply it: tell the user, read again later), `unknown` (it could not be asked), or `applied` for an import (its document is in the project; its diagnostics were lost). Elsewhere ask `getWriteOutcome({ writeId })` with `meta.writeId` before writing again; never retry a write blindly. The store's docs say what each `meta.reason` asks of the app.",
169
+ docs: `${o}/api/project#a-lost-connection`
170
+ }
171
+ },
172
+ STORE_KIND_TAKEN: {
173
+ code: "D1021",
174
+ message: "This storage type is registered already by another kind",
175
+ explanation: {
176
+ when: "`registerStorageKind({ type, kind })` named a type a kind of another `id` holds already: the first registration in the realm is kept, nothing replaced (the same `id` again does nothing: a module evaluated twice, or another copy of the package). `meta`: `type`, `registered` (the id kept), `asked` (the id refused).",
177
+ fix: "Register each storage type once, from one package: import the entry that registers it from a single copy, or give the other kind a type of its own.",
178
+ docs: `${o}/guide/development/implementing-a-store#register-a-storage-kind`
179
+ }
53
180
  },
54
181
  ELEMENT_NOT_FOUND: {
55
182
  code: "D2001",
56
- message: "Element not found"
183
+ message: "Element not found",
184
+ explanation: {
185
+ when: "A ref names an element the document does not hold (deleted, never created, or from another document).",
186
+ fix: "Read the ref from a query in the same document (`getRecord`, `findDescendants`) instead of keeping an old one.",
187
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
188
+ }
57
189
  },
58
190
  ROOT_NOT_FOUND: {
59
191
  code: "D2002",
60
- message: "Root element not found"
192
+ message: "Root element not found",
193
+ explanation: {
194
+ when: "The document holds no root element of the dialecte's root tag (an empty or foreign document).",
195
+ fix: "Import a file whose root is the dialecte's root element, or create the document with `project.initEmptyDocument`.",
196
+ docs: `${o}/api/project#initemptydocument`
197
+ }
61
198
  },
62
199
  DUPLICATE_ID: {
63
200
  code: "D2003",
64
- message: "Duplicate element ID"
201
+ message: "Duplicate element ID",
202
+ explanation: {
203
+ when: "Not raised by core itself: a dialecte or app code raises it when two elements carry the same id.",
204
+ fix: "Give each element its own id; let core mint them.",
205
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
206
+ }
65
207
  },
66
208
  ELEMENT_TAGNAME_MISMATCH: {
67
209
  code: "D2004",
68
- message: "Element tagName does not match the expected type"
210
+ message: "Element tagName does not match the expected type",
211
+ explanation: {
212
+ when: "A ref's `tagName` is not the tag of the record its id names.",
213
+ fix: "Build refs with `toRef(record)` from a record you read, never by hand with a guessed tag.",
214
+ docs: `${o}/api/transaction#reforrecord`
215
+ }
69
216
  },
70
217
  INVALID_PARENT_CHILD: {
71
218
  code: "D3001",
72
- message: "Invalid parent-child relationship"
219
+ message: "Invalid parent-child relationship",
220
+ explanation: {
221
+ when: "Not raised by core itself: a dialecte or app code raises it when an element is placed under a parent the schema does not admit.",
222
+ fix: "Read the parent's children in the definition (`query.getDefinition`) and add the element under an admitted parent.",
223
+ docs: `${o}/api/transaction#addchild`
224
+ }
73
225
  },
74
226
  INVALID_ATTRIBUTE: {
75
227
  code: "D3002",
76
- message: "Invalid attribute for element"
228
+ message: "Invalid attribute for element",
229
+ explanation: {
230
+ when: "Not raised by core itself: a dialecte or app code raises it for an attribute the element does not declare.",
231
+ fix: "Use an attribute the element's definition lists.",
232
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
233
+ }
77
234
  },
78
235
  PROTECTED_ROOT: {
79
236
  code: "D3003",
80
- message: "Root element cannot be deleted"
237
+ message: "Root element cannot be deleted",
238
+ explanation: {
239
+ when: "A transaction tried to delete the document's root element.",
240
+ fix: "Delete the root's children instead, or remove the whole document with `project.removeDocument`.",
241
+ docs: `${o}/api/transaction#delete`
242
+ }
81
243
  },
82
244
  REQUIRED_ATTRIBUTE_MISSING: {
83
245
  code: "D3004",
84
- message: "Required attribute is missing"
246
+ message: "Required attribute is missing",
247
+ explanation: {
248
+ when: "Not raised by core itself: a dialecte or app code raises it when a required attribute is absent.",
249
+ fix: "Give the attribute a value when creating the element.",
250
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
251
+ }
85
252
  },
86
253
  UNIQUE_CONSTRAINT_VIOLATION: {
87
254
  code: "D3005",
88
- message: "Value is already used within its scope"
255
+ message: "Value is already used within its scope",
256
+ explanation: {
257
+ when: "Not raised by core itself: a dialecte raises it when a value is already used within the scope where it must be unique.",
258
+ fix: "Pick another value, or let the dialecte's hook name the element.",
259
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
260
+ }
89
261
  },
90
262
  UNKNOWN_NAMESPACE_PREFIX: {
91
263
  code: "D3006",
92
- message: "Unknown namespace prefix on attribute — pass it explicitly as { name, namespace: { prefix, uri } }"
264
+ message: "Unknown namespace prefix on attribute — pass it explicitly as { name, namespace: { prefix, uri } }",
265
+ explanation: {
266
+ when: "An attribute was written with a namespace key or prefix the dialecte does not declare.",
267
+ fix: "Use a namespace key of the dialecte's config, or pass the namespace in full: `{ name, namespace: { prefix, uri } }`.",
268
+ docs: `${o}/api/transaction#addchild`
269
+ }
93
270
  },
94
271
  PREFIXED_ATTRIBUTE_NAME: {
95
272
  code: "D3007",
96
- message: "Authored attribute name must be a local name — pass the namespace separately as { name, namespace }, not a prefixed name"
273
+ message: "Authored attribute name must be a local name — pass the namespace separately as { name, namespace }, not a prefixed name",
274
+ explanation: {
275
+ when: "An attribute was written with a prefixed name (`ext:attr`) on create or update.",
276
+ fix: "Pass the local name and the namespace apart: `{ name: 'attr', namespace }`.",
277
+ docs: `${o}/api/transaction#addchild`
278
+ }
97
279
  },
98
280
  FIXED_VALUE_VIOLATION: {
99
281
  code: "D3008",
100
- message: "Attribute value differs from the schema-fixed value"
282
+ message: "Attribute value differs from the schema-fixed value",
283
+ explanation: {
284
+ when: "A write gave an attribute another value than the one the schema fixes.",
285
+ fix: "Leave the attribute out (core writes the fixed value) or give exactly the fixed value; `getAttributeRules` reads it.",
286
+ docs: `${o}/api/transaction#addchild`
287
+ }
101
288
  },
102
289
  XSI_TYPE_REQUIRED: {
103
290
  code: "D3009",
104
- message: "The element is declared with an abstract type: name a type with xsi:type"
291
+ message: "The element is declared with an abstract type: name a type with xsi:type",
292
+ explanation: {
293
+ when: "An element declared with an abstract type was created without naming a concrete type in `xsi:type`.",
294
+ fix: "Name one of the admitted types: `attributes: { 'xsi:type': '<Type>' }`; `admittedXsiTypes` lists them.",
295
+ docs: `${o}/api/transaction#addchild`
296
+ }
105
297
  },
106
298
  XSI_TYPE_NOT_ADMITTED: {
107
299
  code: "D3010",
108
- message: "The element may not take the type named with xsi:type"
300
+ message: "The element may not take the type named with xsi:type",
301
+ explanation: {
302
+ when: "A write named in `xsi:type` a type the element may not take.",
303
+ fix: "Pick a type from `admittedXsiTypes` for that element.",
304
+ docs: `${o}/api/transaction#addchild`
305
+ }
109
306
  },
110
307
  XSI_TYPE_CHANGE_LEAVES_CONTENT: {
111
308
  code: "D3011",
112
- message: "The new xsi:type does not admit content the element still holds"
309
+ message: "The new xsi:type does not admit content the element still holds",
310
+ explanation: {
311
+ when: "An update changed `xsi:type` to a type that does not admit attributes or children the element still holds.",
312
+ fix: "Remove that content in the same transaction before changing the type, or pick a type that admits it.",
313
+ docs: `${o}/api/transaction#update`
314
+ }
315
+ },
316
+ XML_CHARACTER_NOT_ALLOWED: {
317
+ code: "D3012",
318
+ message: "The text holds a character XML does not allow",
319
+ explanation: {
320
+ when: "A write, an import session's own writes or an export met a character XML does not allow (a control character below U+0020 but tab, line feed and carriage return, U+FFFE, U+FFFF) in a value, a name, a prefix, a namespace URI or an id; nothing was written, no file.",
321
+ fix: "Remove or replace the character named in `meta.character` at `meta.part` of the record `meta.recordId` before writing or exporting it.",
322
+ docs: `${o}/io/#values-a-store-keeps`
323
+ }
113
324
  },
114
325
  ALREADY_COMMITTED: {
115
326
  code: "D4001",
116
- message: "Transaction already committed"
327
+ message: "Transaction already committed",
328
+ explanation: {
329
+ when: "Not raised by core today: kept for a transaction used after its commit.",
330
+ fix: "Start a new `doc.transaction` for further writes.",
331
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
332
+ }
117
333
  },
118
334
  ALREADY_FAILED: {
119
335
  code: "D4002",
120
- message: "Transaction already failed"
336
+ message: "Transaction already failed",
337
+ explanation: {
338
+ when: "Not raised by core today: kept for a transaction used after it failed.",
339
+ fix: "Start a new `doc.transaction`; the failed one wrote nothing.",
340
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
341
+ }
121
342
  },
122
343
  DATABASE_COMMIT_ERROR: {
123
344
  code: "D4003",
124
- message: "An error occurred while committing changes to the database"
345
+ message: "An error occurred while committing changes to the database",
346
+ explanation: {
347
+ when: "Not raised by core today: store commit failures are `STORE_COMMIT_FAILED`.",
348
+ fix: "Read `cause`; see `STORE_COMMIT_FAILED`.",
349
+ docs: `${o}/guide/development/state-and-errors#error-catalog`
350
+ }
125
351
  },
126
352
  CONCURRENT_TRANSACTION: {
127
353
  code: "D4004",
128
- message: "A transaction is already in progress. Concurrent transactions are not supported yet — serialize them or implement a transaction queue."
354
+ message: "A transaction is already in progress. Concurrent transactions are not supported yet — serialize them or implement a transaction queue.",
355
+ explanation: {
356
+ when: "A `doc.transaction` started on a Document while another transaction or `doc.prepare` was still running on it (a missing `await`, or a nested transaction).",
357
+ fix: "Await each transaction before the next; inside a transaction, write through its `tx`, never through `doc.transaction` again.",
358
+ docs: `${o}/api/document`
359
+ }
129
360
  },
130
361
  EXPORT_ROOT_NOT_FOUND: {
131
362
  code: "D5001",
132
- message: "Root element not found in records during export"
363
+ message: "Root element not found in records during export",
364
+ explanation: {
365
+ when: "The export found no root record in the document.",
366
+ fix: "The document is empty or damaged: import it again, or create it with `project.initEmptyDocument`.",
367
+ docs: `${o}/api/project#export`
368
+ }
133
369
  },
134
370
  EXPORT_ORPHAN_CHILD_REF: {
135
371
  code: "D5002",
136
- message: "Parent references non-existent child record"
372
+ message: "Parent references non-existent child record",
373
+ explanation: {
374
+ when: "The export met a parent whose list of children names a record that does not exist.",
375
+ fix: "A hook or a raw write left a dangling child ref: a hook that deletes must also return the parent's `updated` operation.",
376
+ docs: `${o}/api/project#export`
377
+ }
137
378
  },
138
379
  PARSE_ERROR: {
139
380
  code: "D5003",
140
- message: "Failed to parse XML"
381
+ message: "Failed to parse XML",
382
+ explanation: {
383
+ when: "The file given to import (or to `parseXmlDocument`) is not well-formed XML.",
384
+ fix: "Fix the XML where `detail` points (line and column); check the file's encoding.",
385
+ docs: `${o}/api/project#import`
386
+ }
387
+ },
388
+ IMPORT_FAILED: {
389
+ code: "D5004",
390
+ message: "Failed to import the file",
391
+ explanation: {
392
+ when: "Importing a file failed after it was parsed (a hook threw, the store refused the records); nothing of the file remains.",
393
+ fix: "Read `cause` and `detail`; an import hook must not read the store or throw on data it can report as a diagnostic.",
394
+ docs: `${o}/api/project#import`
395
+ }
396
+ },
397
+ IMPORT_ABORTED: {
398
+ code: "D5005",
399
+ message: "The import was aborted",
400
+ explanation: {
401
+ when: "The import's `signal` was aborted; nothing of the file remains.",
402
+ fix: "Nothing to fix when the abort was wanted; import the file again otherwise.",
403
+ docs: `${o}/api/project#import`
404
+ }
405
+ },
406
+ EXPORT_CONFLICT: {
407
+ code: "D5006",
408
+ message: "The document changed while it was exported",
409
+ explanation: {
410
+ when: "The document was written twice while it was being exported, so no consistent file could be read.",
411
+ fix: "Export when no transaction or import is writing the document, or retry.",
412
+ docs: `${o}/api/project#export`
413
+ }
414
+ },
415
+ EXPORT_ABORTED: {
416
+ code: "D5007",
417
+ message: "The export was aborted",
418
+ explanation: {
419
+ when: "The export's `signal` was aborted.",
420
+ fix: "Nothing to fix when the abort was wanted; export again otherwise.",
421
+ docs: `${o}/api/project#export`
422
+ }
141
423
  },
142
424
  EXTENSION_METHOD_COLLISION: {
143
425
  code: "D6001",
144
- message: "Extension method name collision detected"
426
+ message: "Extension method name collision detected",
427
+ explanation: {
428
+ when: "Two extension modules merged under one key define a method of the same name.",
429
+ fix: "Rename your method, or put your module under a key of its own.",
430
+ docs: `${o}/guide/extensions/#registering-extensions`
431
+ }
145
432
  },
146
433
  UNKNOWN_CONFIG_KEY: {
147
434
  code: "D7001",
148
- message: "Unknown config key"
435
+ message: "Unknown config key",
436
+ explanation: {
437
+ when: "A document, a test or a declaration named a config key the dialecte does not declare.",
438
+ fix: "Use a key of the dialecte's `configs` (its `defaultConfigKey` when in doubt).",
439
+ docs: `${o}/api/dialecte#definedialecte`
440
+ }
149
441
  },
150
442
  DOCUMENT_NOT_REGISTERED: {
151
443
  code: "D7002",
152
- message: "Document not registered in project"
444
+ message: "Document not registered in project",
445
+ explanation: {
446
+ when: "A document id names no document of the open project (removed, or from another project).",
447
+ fix: "Use an id from `project.getDocuments()` or from the import result.",
448
+ docs: `${o}/api/project#document-access`
449
+ }
153
450
  },
154
451
  PROJECT_NOT_OPENED: {
155
452
  code: "D7003",
156
- message: "Project not opened"
453
+ message: "Project not opened",
454
+ explanation: {
455
+ when: "The project was used before `open(name)` resolved, or once `close()`, `destroy()` or another `open()` was called on it - a batch import's file whose turn came after that is refused the same.",
456
+ fix: "Keep the instance and await its `open(name)` before using the project; open it again after `close()` or `destroy()`, and await an `open()` of another project before using the Project again.",
457
+ docs: `${o}/api/project#lifecycle`
458
+ }
157
459
  },
158
460
  BLOB_NOT_FOUND: {
159
461
  code: "D7004",
160
- message: "Blob not found in store"
462
+ message: "Blob not found in store",
463
+ explanation: {
464
+ when: "`project.exportBlob` named a blob the project does not hold.",
465
+ fix: "Use an id from `project.getBlobsByDocument` or `getStandaloneBlobs`.",
466
+ docs: `${o}/api/project#blobs`
467
+ }
468
+ },
469
+ PROJECT_DIALECTE_MISMATCH: {
470
+ code: "D7008",
471
+ message: "The project's data is of another dialecte",
472
+ explanation: {
473
+ when: "A project stored by another dialecte was opened (nothing of it written), or what serves the store (a worker, a server) was asked for a project of a dialecte it does not serve. Two dialectes' projects of one name are two projects: opening one never meets the other. `meta`: `project`, `realmDialecteId` (the one asked), and `projectDialecteId` (the project's), or the dialectes served, as the store's docs name them.",
474
+ fix: "Open the project with the dialecte it was created with; serve every dialecte the app opens projects of, as the store's docs say.",
475
+ docs: `${o}/api/project#store-errors`
476
+ }
477
+ },
478
+ PROJECT_DIALECTE_VERSION_MISMATCH: {
479
+ code: "D7009",
480
+ message: "The project's store runs another version of the dialecte",
481
+ explanation: {
482
+ when: "What serves the project's store (a worker, a server) runs another version of the dialecte than this view: another tab's, or one this page runs already for the project (a page runs one version of each dialecte).",
483
+ fix: "Reload every tab of the app so they run the same version.",
484
+ docs: `${o}/api/project#store-errors`
485
+ }
486
+ },
487
+ PROJECT_DESTROY_FAILED: {
488
+ code: "D7010",
489
+ message: "The project could not be deleted",
490
+ explanation: {
491
+ when: "Destroying a project left its data in place: another tab, window or connection still holds it.",
492
+ fix: "Close the other tabs or windows of the app that have the project open, then destroy it again.",
493
+ docs: `${o}/api/project#lifecycle`
494
+ }
495
+ },
496
+ PROJECT_OPEN_ELSEWHERE: {
497
+ code: "D7011",
498
+ message: "The project is open in another tab, window or connection",
499
+ explanation: {
500
+ when: "Another tab or window has the project open and there is no shared connection between them; or a destroy was asked while another connection - a store or project of the name in this page, or another tab - has the project open (`meta.connections`, where the store counts them).",
501
+ fix: "Close the project in the other tab, window or connection, then open or destroy it here again.",
502
+ docs: `${o}/api/project#lifecycle`
503
+ }
504
+ },
505
+ PROJECT_DESTROYED_WHILE_AWAY: {
506
+ code: "D7013",
507
+ message: "The project was deleted while this view was away",
508
+ explanation: {
509
+ when: "A view's connection to a project came back - the page back from a freeze or the back/forward cache, what serves its store started again - and the project it had open was destroyed meanwhile by another tab (and maybe made again under its name): nothing is opened in its place and nothing of it is read. `meta.project` names the project.",
510
+ fix: "Tell the user the project was deleted elsewhere; close it in this view (`project.close()`), then open it again by its name for what is there now, or choose another.",
511
+ docs: `${o}/api/project#lifecycle`
512
+ }
513
+ },
514
+ PROJECT_NAME_INVALID: {
515
+ code: "D7014",
516
+ message: "The project's name cannot name its files",
517
+ explanation: {
518
+ when: "A project's name or its dialecte's id is empty, `.` or `..`: every store refuses it before it is built (a store may name its files after both, which no file can be); nothing was opened or written. `meta.project` and `meta.dialecteId` say which.",
519
+ fix: "Give the project a name of its own (and the dialecte an id) other than an empty one, `.` or `..`.",
520
+ docs: `${o}/api/project#lifecycle`
521
+ }
522
+ },
523
+ PROJECT_STORAGE_NOT_REGISTERED: {
524
+ code: "D7018",
525
+ message: "The project's storage type is not registered",
526
+ explanation: {
527
+ when: "A project was opened (or destroyed by name), or a test asked for a test store, on a `storage.type` no kind is registered for in this realm: core serves `local`, `inMemory` and `custom` itself, every other type comes from the entry that registers it (`registerStorageKind`). Nothing was opened. `meta`: `project`, `type`.",
528
+ fix: "Import the entry that registers the type once in the app's entry (for tests, in the test runner's setup file), before the first project opens on it; or open the project on another storage. Imported already? A kind is shared by every copy of @dialecte/core of the same storage version in the realm: one registered by a copy of another version (a package bringing its own core) is not seen - align the core versions.",
529
+ docs: `${o}/guide/development/implementing-a-store#register-a-storage-kind`
530
+ }
531
+ },
532
+ DOCUMENT_PATH_INVALID: {
533
+ code: "D7030",
534
+ message: "A document's path is not valid",
535
+ explanation: {
536
+ when: "A document's path breaks a rule (empty, `.` or `..` segment, backslash, invisible character, not NFC, too long), names another file than the document's, changes its extension, or was handed to `project.import` of several files; nothing was written. `detail` says which rule.",
537
+ fix: "Write the path relative, joined by `/`, in NFC, ending with the document's file name; pass a path to `importFile`, not to `import`.",
538
+ docs: `${o}/api/project#a-document-s-path`
539
+ }
540
+ },
541
+ DOCUMENT_PATH_TAKEN: {
542
+ code: "D7031",
543
+ message: "A document's path is another document's place",
544
+ explanation: {
545
+ when: "Another document already holds the place (`meta.takenBy`), a document still importing included: the same path, a path under another document's file, or a file at a folder another document's path uses.",
546
+ fix: "Choose a path no other document holds, or move the other document first.",
547
+ docs: `${o}/api/project#a-document-s-path`
548
+ }
161
549
  }
162
550
  };
163
- function s(e, t) {
164
- throw c(e, t);
551
+ new Set(Object.values(c).map((e) => e.code));
552
+ function l(e, t) {
553
+ throw u(e, t);
165
554
  }
166
- function c(e, t) {
555
+ function u(e, t) {
167
556
  let n = typeof e == "string" ? {
168
557
  key: e,
169
- ...o[e]
558
+ ...c[e]
170
559
  } : e, r = {
171
560
  code: n.code,
172
561
  key: n.key,
173
562
  message: t.message ?? n.message,
174
563
  detail: t.detail,
175
- method: u((/* @__PURE__ */ Error()).stack),
564
+ method: d((/* @__PURE__ */ Error()).stack),
176
565
  ref: t.ref,
177
566
  meta: t.meta,
178
567
  cause: t.cause
179
568
  }, i = Error(t.detail);
180
569
  return i.cause = r, i;
181
570
  }
182
- new Set(Object.values(o).map((e) => e.code));
183
- var l = new Set([
184
- "throwDialecteError",
185
- "createDialecteError",
186
- "invariant",
187
- "reportFailure"
188
- ]);
189
- function u(e) {
571
+ function d(e) {
190
572
  if (!e) return "unknown";
191
- let t = e.split("\n").slice(1).map((e) => e.match(/\bat\s+(?:async\s+)?(\S+)(?:\s+\[as\s+[^\]]+\])?\s+\(([^)]+)\)/)).find((e) => !d(e?.[1])), n = t?.[1]?.replace(/^Object\./, ""), r = t?.[2];
573
+ let t = e.split("\n").slice(1).map((e) => e.match(/\bat\s+(?:async\s+)?(\S+)(?:\s+\[as\s+[^\]]+\])?\s+\(([^)]+)\)/)).find((e) => !f(e?.[1])), n = t?.[1]?.replace(/^Object\./, ""), r = t?.[2];
192
574
  if (!r || !n) return n ?? "unknown";
193
575
  let i = r.match(/(\w[\w-]*\/src\/[^?:]+)/);
194
576
  return i ? `${i[1].replace(/\.[^/.]+$/, "")}::${n}` : n;
195
577
  }
196
- function d(e) {
197
- return e ? l.has(e.slice(e.lastIndexOf(".") + 1)) : !1;
578
+ function f(e) {
579
+ return e ? s.has(e.slice(e.lastIndexOf(".") + 1)) : !1;
198
580
  }
199
581
  `${{
200
582
  uri: "http://dialecte.dev/XML/DEV",
201
583
  prefix: "dev"
202
584
  }.prefix}`;
203
- var f = {
585
+ var p = {
204
586
  uri: "http://www.w3.org/2001/XMLSchema-instance",
205
587
  prefix: "xsi"
206
588
  };
207
- `${f.prefix}${f.uri}`;
208
- function p(e, t) {
589
+ `${p.prefix}${p.uri}`;
590
+ function m(e, t) {
209
591
  if (e) return;
210
592
  let { detail: n, key: r = "ASSERTION_FAILED", ref: i, meta: a } = t;
211
- s(r, {
593
+ l(r, {
212
594
  detail: n,
213
595
  ref: i,
214
596
  meta: a
@@ -216,27 +598,30 @@ function p(e, t) {
216
598
  }
217
599
  //#endregion
218
600
  //#region src/shell-context.ts
219
- var m = null;
220
- function h(e) {
221
- m = e;
222
- }
223
- function g() {
224
- m = null;
601
+ var h = null;
602
+ function g(e) {
603
+ h = e;
225
604
  }
226
605
  function _() {
227
- return p(m, { detail: "getProject: shell context not set. Call setShellContext(api) before app.mount()." }), m.project;
606
+ h = null;
228
607
  }
229
608
  function v() {
230
- return p(m, { detail: "getActiveDocumentId: shell context not set. Call setShellContext(api) before app.mount()." }), m.activeDocumentId;
609
+ return m(h, { detail: "getProject: shell context not set. Call setShellContext(api) before app.mount()." }), h.project;
231
610
  }
232
611
  function y() {
233
- return p(m, { detail: "getCommands: shell context not set. Call setShellContext(api) before app.mount()." }), m.commands;
612
+ return m(h, { detail: "getActiveDocumentId: shell context not set. Call setShellContext(api) before app.mount()." }), h.activeDocumentId;
234
613
  }
235
614
  function b() {
236
- return p(m, { detail: "getStorageSources: shell context not set. Call setShellContext(api) before app.mount()." }), p(m.storageSources, { detail: "getStorageSources: no storage sources provided by the shell." }), m.storageSources;
615
+ return m(h, { detail: "getCommands: shell context not set. Call setShellContext(api) before app.mount()." }), h.commands;
237
616
  }
238
617
  function x() {
239
- return p(m, { detail: "getPwa: shell context not set. Call setShellContext(api) before app.mount()." }), p(m.pwa, { detail: "getPwa: no PWA surface provided by the shell." }), m.pwa;
618
+ return m(h, { detail: "getStorageSources: shell context not set. Call setShellContext(api) before app.mount()." }), m(h.storageSources, { detail: "getStorageSources: no storage sources provided by the shell." }), h.storageSources;
619
+ }
620
+ function S() {
621
+ return m(h, { detail: "getPwa: shell context not set. Call setShellContext(api) before app.mount()." }), m(h.pwa, { detail: "getPwa: no PWA surface provided by the shell." }), h.pwa;
622
+ }
623
+ function C() {
624
+ return h?.projectStorage ?? { type: "local" };
240
625
  }
241
626
  //#endregion
242
- export { t as LIBRARY_DB_PREFIX, i as RESERVED_DB_PREFIXES, e as SHELL_DB_PREFIX, n as TEMP_DOCUMENT_PREFIX, r as TEMP_PROJECT_PREFIX, g as clearShellContext, v as getActiveDocumentId, y as getCommands, _ as getProject, x as getPwa, b as getStorageSources, a as isReservedDatabaseName, h as setShellContext };
627
+ export { t as LIBRARY_DB_PREFIX, i as RESERVED_DB_PREFIXES, e as SHELL_DB_PREFIX, n as TEMP_DOCUMENT_PREFIX, r as TEMP_PROJECT_PREFIX, _ as clearShellContext, y as getActiveDocumentId, b as getCommands, v as getProject, C as getProjectStorage, S as getPwa, x as getStorageSources, a as isReservedDatabaseName, g as setShellContext };
@@ -1,5 +1,6 @@
1
1
  import { Scl } from '@dialecte/scl/v2019C1';
2
2
  import { Observable, ShellCommands } from './types/api';
3
+ import { ProjectStorage } from './types/project-storage';
3
4
  import { PwaInstall } from './types/pwa-install';
4
5
  import { StorageSources } from './types/storage-source';
5
6
  interface ShellContext {
@@ -8,6 +9,7 @@ interface ShellContext {
8
9
  commands: ShellCommands;
9
10
  storageSources?: StorageSources;
10
11
  pwa?: PwaInstall;
12
+ projectStorage?: ProjectStorage;
11
13
  }
12
14
  export declare function setShellContext(ctx: ShellContext): void;
13
15
  export declare function clearShellContext(): void;
@@ -16,4 +18,5 @@ export declare function getActiveDocumentId(): Observable<string>;
16
18
  export declare function getCommands(): ShellCommands;
17
19
  export declare function getStorageSources(): StorageSources;
18
20
  export declare function getPwa(): PwaInstall;
21
+ export declare function getProjectStorage(): ProjectStorage;
19
22
  export {};
@@ -1,4 +1,5 @@
1
1
  import { Scl } from '@dialecte/scl/v2019C1';
2
+ import { ProjectStorage } from './project-storage';
2
3
  import { PwaInstall } from './pwa-install';
3
4
  import { StorageSources } from './storage-source';
4
5
  export interface ShellCommands {
@@ -17,4 +18,5 @@ export interface ExtensionAPI {
17
18
  commands: ShellCommands;
18
19
  storageSources?: StorageSources;
19
20
  pwa?: PwaInstall;
21
+ projectStorage?: ProjectStorage;
20
22
  }
@@ -1,3 +1,4 @@
1
1
  export type * from './api';
2
2
  export type * from './storage-source';
3
3
  export type * from './pwa-install';
4
+ export type * from './project-storage';
@@ -0,0 +1,5 @@
1
+ import { StorageParam } from '@dialecte/core';
2
+ export type {} from '@dialecte/core/sqlite';
3
+ export type ProjectStorage = Extract<StorageParam, {
4
+ type: 'local' | 'sqlite';
5
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@septkit/shell-lib",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -13,8 +13,8 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@dialecte/core": "0.6.1",
17
- "@dialecte/scl": "0.8.1"
16
+ "@dialecte/core": "0.9.0",
17
+ "@dialecte/scl": "0.14.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "oxlint": "~1.6.0",