@septkit/shell-lib 0.0.25 → 0.0.27

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.
@@ -1,3 +1,6 @@
1
+ export declare const SHELL_DB_PREFIX = "SET-SHELL-";
1
2
  export declare const LIBRARY_DB_PREFIX = "SET-LIBRARY-";
2
3
  export declare const TEMP_DOCUMENT_PREFIX = "TEMP-";
3
4
  export declare const TEMP_PROJECT_PREFIX = "TEMP-PROJECT-";
5
+ export declare const RESERVED_DB_PREFIXES: readonly ["_", "SET-SHELL-", "SET-LIBRARY-", "TEMP-"];
6
+ export declare function isReservedDatabaseName(name: string): boolean;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export type * from './types';
2
- export { LIBRARY_DB_PREFIX, TEMP_DOCUMENT_PREFIX, TEMP_PROJECT_PREFIX } from './constants';
3
- export { setShellContext, clearShellContext, getProject, getActiveDocumentId, getCommands, } from './shell-context';
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';
package/dist/index.js CHANGED
@@ -1,5 +1,16 @@
1
1
  //#region src/constants.ts
2
- var e = "SET-LIBRARY-", t = "TEMP-", n = "TEMP-PROJECT-", r = {
2
+ var e = "SET-SHELL-", t = "SET-LIBRARY-", n = "TEMP-", r = "TEMP-PROJECT-", i = [
3
+ "_",
4
+ e,
5
+ t,
6
+ n
7
+ ];
8
+ function a(e) {
9
+ return i.some((t) => e.startsWith(t));
10
+ }
11
+ //#endregion
12
+ //#region node_modules/.pnpm/@dialecte+core@0.4.12/node_modules/@dialecte/core/dist/utils-C5_11hqg.js
13
+ var o = {
3
14
  UNKNOWN: {
4
15
  code: "D0001",
5
16
  message: "An unknown error occurred"
@@ -137,19 +148,19 @@ var e = "SET-LIBRARY-", t = "TEMP-", n = "TEMP-PROJECT-", r = {
137
148
  message: "Blob not found in store"
138
149
  }
139
150
  };
140
- function i(e, t) {
141
- let n = r[e], i = {
151
+ function s(e, t) {
152
+ let n = o[e], r = {
142
153
  code: n.code,
143
154
  key: e,
144
155
  message: t.message ?? n.message,
145
156
  detail: t.detail,
146
- method: a((/* @__PURE__ */ Error()).stack),
157
+ method: c((/* @__PURE__ */ Error()).stack),
147
158
  ref: t.ref,
148
159
  cause: t.cause
149
- }, o = Error(t.detail);
150
- throw o.cause = i, o;
160
+ }, i = Error(t.detail);
161
+ throw i.cause = r, i;
151
162
  }
152
- function a(e) {
163
+ function c(e) {
153
164
  if (!e) return "unknown";
154
165
  let t = e.split("\n").slice(1).find((e) => !/\b(throwDialecteError|assert)\b/.test(e));
155
166
  if (!t) return "unknown";
@@ -158,31 +169,37 @@ function a(e) {
158
169
  let a = i.match(/(\w[\w-]*\/src\/[^?:]+)/);
159
170
  return a ? `${a[1].replace(/\.[^/.]+$/, "")}::${r}` : r;
160
171
  }
161
- function o(e, t) {
172
+ function l(e, t) {
162
173
  if (e) return;
163
- let { detail: n, key: r = "ASSERTION_FAILED", ref: a } = t;
164
- i(r, {
174
+ let { detail: n, key: r = "ASSERTION_FAILED", ref: i } = t;
175
+ s(r, {
165
176
  detail: n,
166
- ref: a
177
+ ref: i
167
178
  });
168
179
  }
169
180
  //#endregion
170
181
  //#region src/shell-context.ts
171
- var s = null;
172
- function c(e) {
173
- s = e;
182
+ var u = null;
183
+ function d(e) {
184
+ u = e;
174
185
  }
175
- function l() {
176
- s = null;
186
+ function f() {
187
+ u = null;
177
188
  }
178
- function u() {
179
- return o(s, { detail: "getProject: shell context not set. Call setShellContext(api) before app.mount()." }), s.project;
189
+ function p() {
190
+ return l(u, { detail: "getProject: shell context not set. Call setShellContext(api) before app.mount()." }), u.project;
180
191
  }
181
- function d() {
182
- return o(s, { detail: "getActiveDocumentId: shell context not set. Call setShellContext(api) before app.mount()." }), s.activeDocumentId;
192
+ function m() {
193
+ return l(u, { detail: "getActiveDocumentId: shell context not set. Call setShellContext(api) before app.mount()." }), u.activeDocumentId;
183
194
  }
184
- function f() {
185
- return o(s, { detail: "getCommands: shell context not set. Call setShellContext(api) before app.mount()." }), s.commands;
195
+ function h() {
196
+ return l(u, { detail: "getCommands: shell context not set. Call setShellContext(api) before app.mount()." }), u.commands;
197
+ }
198
+ function g() {
199
+ return l(u, { detail: "getStorageSources: shell context not set. Call setShellContext(api) before app.mount()." }), l(u.storageSources, { detail: "getStorageSources: no storage sources provided by the shell." }), u.storageSources;
200
+ }
201
+ function _() {
202
+ return l(u, { detail: "getPwa: shell context not set. Call setShellContext(api) before app.mount()." }), l(u.pwa, { detail: "getPwa: no PWA surface provided by the shell." }), u.pwa;
186
203
  }
187
204
  //#endregion
188
- export { e as LIBRARY_DB_PREFIX, t as TEMP_DOCUMENT_PREFIX, n as TEMP_PROJECT_PREFIX, l as clearShellContext, d as getActiveDocumentId, f as getCommands, u as getProject, c as setShellContext };
205
+ 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, f as clearShellContext, m as getActiveDocumentId, h as getCommands, p as getProject, _ as getPwa, g as getStorageSources, a as isReservedDatabaseName, d as setShellContext };
@@ -1,13 +1,19 @@
1
1
  import { Scl } from '@dialecte/scl/v2019C1';
2
2
  import { Observable, ShellCommands } from './types/api';
3
+ import { PwaInstall } from './types/pwa-install';
4
+ import { StorageSources } from './types/storage-source';
3
5
  interface ShellContext {
4
6
  project: Scl.Project;
5
7
  activeDocumentId: Observable<string>;
6
8
  commands: ShellCommands;
9
+ storageSources?: StorageSources;
10
+ pwa?: PwaInstall;
7
11
  }
8
12
  export declare function setShellContext(ctx: ShellContext): void;
9
13
  export declare function clearShellContext(): void;
10
14
  export declare function getProject(): Scl.Project;
11
15
  export declare function getActiveDocumentId(): Observable<string>;
12
16
  export declare function getCommands(): ShellCommands;
17
+ export declare function getStorageSources(): StorageSources;
18
+ export declare function getPwa(): PwaInstall;
13
19
  export {};
@@ -1,4 +1,6 @@
1
1
  import { Scl } from '@dialecte/scl/v2019C1';
2
+ import { PwaInstall } from './pwa-install';
3
+ import { StorageSources } from './storage-source';
2
4
  export interface ShellCommands {
3
5
  activateDocument: (documentId: string) => Promise<void>;
4
6
  switchProject: (projectName: string) => Promise<void>;
@@ -13,4 +15,6 @@ export interface ExtensionAPI {
13
15
  activeFileName: Observable<string>;
14
16
  activeDocumentId: Observable<string>;
15
17
  commands: ShellCommands;
18
+ storageSources?: StorageSources;
19
+ pwa?: PwaInstall;
16
20
  }
@@ -1 +1,3 @@
1
1
  export type * from './api';
2
+ export type * from './storage-source';
3
+ export type * from './pwa-install';
@@ -0,0 +1,6 @@
1
+ export interface PwaInstall {
2
+ isInstalled(): boolean;
3
+ canInstall(): boolean;
4
+ promptInstall(): Promise<boolean>;
5
+ onChange(listener: () => void): () => void;
6
+ }
@@ -0,0 +1,35 @@
1
+ export interface StorageSources {
2
+ isSupported(): boolean;
3
+ listSources(): Promise<StorageSource[]>;
4
+ attach(options?: {
5
+ mode?: StorageAccessMode;
6
+ }): Promise<StorageSource>;
7
+ requestAccess(id: string): Promise<StorageAccessState>;
8
+ detach(id: string): Promise<void>;
9
+ onChange(listener: (sources: StorageSource[]) => void): Unsubscribe;
10
+ listEntries(id: string, options?: {
11
+ recursive?: boolean;
12
+ }): Promise<StorageEntry[]>;
13
+ readFile(id: string, path: string): Promise<File>;
14
+ writeFile(id: string, path: string, data: Blob | string): Promise<void>;
15
+ deleteFile(id: string, path: string): Promise<void>;
16
+ }
17
+ type Unsubscribe = () => void;
18
+ export type StorageAccessMode = 'read' | 'readwrite';
19
+ export type StorageAccessState = 'granted' | 'prompt' | 'denied';
20
+ export type StorageSource = {
21
+ id: string;
22
+ label: string;
23
+ mode: StorageAccessMode;
24
+ access: StorageAccessState;
25
+ };
26
+ export type StorageEntry = {
27
+ path: string;
28
+ kind: 'file' | 'directory';
29
+ };
30
+ export type StorageErrorReason = 'unsupported' | 'access-denied' | 'cancelled' | 'not-found' | 'io';
31
+ export interface StorageError extends Error {
32
+ reason: StorageErrorReason;
33
+ sourceId?: string;
34
+ }
35
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@septkit/shell-lib",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"