sh3-core 0.1.0 → 0.2.0

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.

Potentially problematic release.


This version of sh3-core might be problematic. Click here for more details.

Files changed (36) hide show
  1. package/dist/api.d.ts +1 -0
  2. package/dist/assets/icons.svg +1119 -1119
  3. package/dist/auth/auth.svelte.d.ts +6 -0
  4. package/dist/auth/auth.svelte.js +8 -0
  5. package/dist/auth/index.d.ts +1 -1
  6. package/dist/auth/index.js +1 -1
  7. package/dist/createShell.d.ts +31 -0
  8. package/dist/createShell.js +109 -0
  9. package/dist/diagnostic/DiagnosticPanel.svelte +106 -0
  10. package/dist/diagnostic/DiagnosticPanel.svelte.d.ts +3 -0
  11. package/dist/diagnostic/DiagnosticPromptModal.svelte +82 -0
  12. package/dist/diagnostic/DiagnosticPromptModal.svelte.d.ts +8 -0
  13. package/dist/diagnostic/diagnosticApp.d.ts +2 -0
  14. package/dist/diagnostic/diagnosticApp.js +24 -0
  15. package/dist/diagnostic/diagnosticShard.svelte.d.ts +2 -0
  16. package/dist/diagnostic/diagnosticShard.svelte.js +106 -0
  17. package/dist/host-entry.d.ts +4 -1
  18. package/dist/host-entry.js +3 -1
  19. package/dist/host.d.ts +10 -1
  20. package/dist/host.js +34 -22
  21. package/dist/platform/index.d.ts +10 -0
  22. package/dist/platform/index.js +37 -0
  23. package/dist/platform/tauri-backend.d.ts +15 -0
  24. package/dist/platform/tauri-backend.js +58 -0
  25. package/dist/registry/schema.js +5 -0
  26. package/dist/registry/types.d.ts +20 -3
  27. package/dist/server-shard/types.d.ts +67 -0
  28. package/dist/server-shard/types.js +13 -0
  29. package/dist/shards/types.d.ts +8 -0
  30. package/package.json +1 -1
  31. package/dist/registry-shard/RegistryView.svelte +0 -561
  32. package/dist/registry-shard/RegistryView.svelte.d.ts +0 -3
  33. package/dist/registry-shard/registryApp.d.ts +0 -10
  34. package/dist/registry-shard/registryApp.js +0 -24
  35. package/dist/registry-shard/registryShard.svelte.d.ts +0 -45
  36. package/dist/registry-shard/registryShard.svelte.js +0 -125
@@ -0,0 +1,10 @@
1
+ import type { Backend } from '../state/types';
2
+ export interface PlatformBackends {
3
+ workspace: Backend;
4
+ user: Backend;
5
+ }
6
+ export interface PlatformResult {
7
+ backends: PlatformBackends | null;
8
+ localOwner: boolean;
9
+ }
10
+ export declare function resolvePlatform(): Promise<PlatformResult>;
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Platform detection and backend resolution.
3
+ *
4
+ * Called once at boot, before bootstrap(). Detects whether we're running
5
+ * inside a Tauri webview by attempting to dynamically import the Tauri
6
+ * store backend. If the import fails (web build, or Tauri APIs absent),
7
+ * falls back to default localStorage backends.
8
+ *
9
+ * Also resolves localOwner — true in Tauri (user owns the device) or
10
+ * when running a Vite dev server (import.meta.env.DEV). Production web
11
+ * builds are never local-owner.
12
+ *
13
+ * Vite code-splits the Tauri path into a separate chunk that is never
14
+ * loaded in web builds (the dynamic import fails at runtime).
15
+ */
16
+ export async function resolvePlatform() {
17
+ var _a, _b;
18
+ try {
19
+ // The variable indirection prevents Vite from statically analysing
20
+ // the import and failing when the Tauri plugin isn't installed.
21
+ const path = './tauri-backend';
22
+ const { TauriStoreBackend } = await import(/* @vite-ignore */ path);
23
+ const workspace = new TauriStoreBackend('workspace');
24
+ const user = new TauriStoreBackend('user');
25
+ // Ensure stores are loaded from disk before returning.
26
+ await Promise.all([workspace.init(), user.init()]);
27
+ return { backends: { workspace, user }, localOwner: true };
28
+ }
29
+ catch (_c) {
30
+ // Not in Tauri — fall back to default web backends.
31
+ // Local-owner if running Vite dev server.
32
+ // import.meta.env.DEV is injected by Vite at bundle time; guard for
33
+ // non-Vite consumers (the cast avoids a TS error in library builds).
34
+ const isDev = (_b = (_a = import.meta.env) === null || _a === void 0 ? void 0 : _a.DEV) !== null && _b !== void 0 ? _b : false;
35
+ return { backends: null, localOwner: isDev };
36
+ }
37
+ }
@@ -0,0 +1,15 @@
1
+ import type { Backend } from '../state/types';
2
+ export declare class TauriStoreBackend implements Backend {
3
+ #private;
4
+ constructor(zoneName: string);
5
+ read(shardId: string): unknown | undefined;
6
+ write(shardId: string, value: unknown): void;
7
+ delete(shardId: string): void;
8
+ list(): string[];
9
+ /**
10
+ * Load the store from disk into the local cache. Must be called once
11
+ * before read/list return meaningful data. Called by the platform
12
+ * resolver at boot.
13
+ */
14
+ init(): Promise<void>;
15
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ * TauriStoreBackend — implements the sh3 Backend interface using
3
+ * @tauri-apps/plugin-store. Each zone gets its own .json store file
4
+ * (e.g. "workspace.json", "user.json") in Tauri's app data directory.
5
+ *
6
+ * tauri-plugin-store v2 keeps an in-memory cache and flushes to disk
7
+ * automatically. We pre-load the full store into a local Map during
8
+ * init(), then serve reads/lists synchronously from that cache —
9
+ * matching the Backend interface contract. Writes go to both the
10
+ * local cache and the Tauri store (fire-and-forget async).
11
+ */
12
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
13
+ if (kind === "m") throw new TypeError("Private method is not writable");
14
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
15
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
16
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
+ };
18
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
19
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
20
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
21
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
22
+ };
23
+ var _TauriStoreBackend_store, _TauriStoreBackend_cache;
24
+ import { LazyStore } from '@tauri-apps/plugin-store';
25
+ export class TauriStoreBackend {
26
+ constructor(zoneName) {
27
+ _TauriStoreBackend_store.set(this, void 0);
28
+ _TauriStoreBackend_cache.set(this, new Map());
29
+ __classPrivateFieldSet(this, _TauriStoreBackend_store, new LazyStore(`${zoneName}.json`, { defaults: {}, autoSave: true }), "f");
30
+ }
31
+ read(shardId) {
32
+ return __classPrivateFieldGet(this, _TauriStoreBackend_cache, "f").get(shardId);
33
+ }
34
+ write(shardId, value) {
35
+ __classPrivateFieldGet(this, _TauriStoreBackend_cache, "f").set(shardId, value);
36
+ // Fire-and-forget — autoSave flushes to disk.
37
+ __classPrivateFieldGet(this, _TauriStoreBackend_store, "f").set(shardId, value).catch((e) => console.warn('SH3: store write failed', e));
38
+ }
39
+ delete(shardId) {
40
+ __classPrivateFieldGet(this, _TauriStoreBackend_cache, "f").delete(shardId);
41
+ __classPrivateFieldGet(this, _TauriStoreBackend_store, "f").delete(shardId).catch((e) => console.warn('SH3: store delete failed', e));
42
+ }
43
+ list() {
44
+ return [...__classPrivateFieldGet(this, _TauriStoreBackend_cache, "f").keys()];
45
+ }
46
+ /**
47
+ * Load the store from disk into the local cache. Must be called once
48
+ * before read/list return meaningful data. Called by the platform
49
+ * resolver at boot.
50
+ */
51
+ async init() {
52
+ const entries = await __classPrivateFieldGet(this, _TauriStoreBackend_store, "f").entries();
53
+ for (const [key, value] of entries) {
54
+ __classPrivateFieldGet(this, _TauriStoreBackend_cache, "f").set(key, value);
55
+ }
56
+ }
57
+ }
58
+ _TauriStoreBackend_store = new WeakMap(), _TauriStoreBackend_cache = new WeakMap();
@@ -115,6 +115,10 @@ function validatePackageVersion(data, path) {
115
115
  requireString(obj, 'contractVersion', path);
116
116
  requireString(obj, 'bundleUrl', path);
117
117
  requireString(obj, 'integrity', path);
118
+ // Optional server bundle URL
119
+ if ('serverBundleUrl' in obj && obj.serverBundleUrl !== undefined) {
120
+ requireString(obj, 'serverBundleUrl', path);
121
+ }
118
122
  let requires;
119
123
  if (obj['requires'] !== undefined) {
120
124
  if (!Array.isArray(obj['requires'])) {
@@ -127,6 +131,7 @@ function validatePackageVersion(data, path) {
127
131
  contractVersion: obj['contractVersion'],
128
132
  bundleUrl: obj['bundleUrl'],
129
133
  integrity: obj['integrity'],
134
+ serverBundleUrl: typeof obj['serverBundleUrl'] === 'string' ? obj['serverBundleUrl'] : undefined,
130
135
  requires,
131
136
  };
132
137
  }
@@ -92,7 +92,7 @@ export interface PackageVersion {
92
92
  */
93
93
  version: string;
94
94
  /**
95
- * The `sh3-framework` contract version this bundle was built against
95
+ * The `sh3-core` contract version this bundle was built against
96
96
  * (e.g. `"0.1.0"`). The install API checks this against the running
97
97
  * framework version and may warn or block on mismatch.
98
98
  */
@@ -110,6 +110,13 @@ export interface PackageVersion {
110
110
  * See: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
111
111
  */
112
112
  integrity: string;
113
+ /**
114
+ * Optional URL to the server-side bundle for shards that have a backend
115
+ * component. Same resolution rules as `bundleUrl` (absolute or registry-
116
+ * relative). Only present when the shard declares `serverBundle` in its
117
+ * manifest.
118
+ */
119
+ serverBundleUrl?: string;
113
120
  /**
114
121
  * Other shards that must be installed and active before this package
115
122
  * can be loaded. Optional — omit if the package has no dependencies.
@@ -165,7 +172,7 @@ export interface InstalledPackage {
165
172
  */
166
173
  sourceRegistry: string;
167
174
  /**
168
- * The `sh3-framework` contract version the installed bundle was built
175
+ * The `sh3-core` contract version the installed bundle was built
169
176
  * against. Used to detect contract version mismatches after framework
170
177
  * upgrades.
171
178
  */
@@ -225,7 +232,7 @@ export interface PackageMeta {
225
232
  */
226
233
  version: string;
227
234
  /**
228
- * The `sh3-framework` contract version the bundle was built against.
235
+ * The `sh3-core` contract version the bundle was built against.
229
236
  */
230
237
  contractVersion: string;
231
238
  /**
@@ -242,4 +249,14 @@ export interface PackageMeta {
242
249
  * Undefined if no dependencies.
243
250
  */
244
251
  requires?: RequiredDependency[];
252
+ /**
253
+ * SRI hash for the server bundle. Only present when the package has a
254
+ * server component.
255
+ */
256
+ serverIntegrity?: string;
257
+ /**
258
+ * Whether this package includes a server bundle that needs to be pushed
259
+ * to the server after client-side installation.
260
+ */
261
+ hasServerBundle?: boolean;
245
262
  }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Server-side shard contract.
3
+ *
4
+ * A server shard is the optional backend counterpart to a client shard.
5
+ * It runs in Node inside sh3-server and declares routes that are mounted
6
+ * under `/s/<shard-id>/`. Server shards have full Node access — filesystem,
7
+ * child_process, network, etc. — and are trusted by the admin who installed
8
+ * them.
9
+ *
10
+ * The server bundle is a separate ESM file whose default export conforms
11
+ * to the `ServerShard` interface.
12
+ */
13
+ /**
14
+ * Context provided by sh3-server when mounting a server shard's routes.
15
+ */
16
+ export interface ServerShardContext {
17
+ /** The shard id this server bundle belongs to. */
18
+ shardId: string;
19
+ /**
20
+ * Scoped filesystem directory for this shard's persistent data.
21
+ * Created automatically before `routes()` is called.
22
+ * Path: `<dataDir>/shards/<shard-id>/`
23
+ */
24
+ dataDir: string;
25
+ /**
26
+ * Hono middleware that rejects non-admin callers.
27
+ * Apply per-route to protect mutation endpoints. Public read routes
28
+ * should not use this.
29
+ *
30
+ * Usage: `router.post('/publish', ctx.adminOnly, handler)`
31
+ */
32
+ adminOnly: MiddlewareHandler;
33
+ }
34
+ /**
35
+ * The interface a server shard bundle must default-export.
36
+ */
37
+ export interface ServerShard {
38
+ /** Must match the client shard's `manifest.id`. */
39
+ id: string;
40
+ /**
41
+ * Called once at mount time. Register Hono routes on the provided router.
42
+ * Routes are relative to `/s/<shard-id>/` — e.g. `router.get('/data', ...)`
43
+ * becomes `GET /s/<shard-id>/data`.
44
+ *
45
+ * May be async if the shard needs to initialise resources before serving.
46
+ */
47
+ routes: (router: HonoLike, context: ServerShardContext) => void | Promise<void>;
48
+ }
49
+ /**
50
+ * Hono MiddlewareHandler type — duplicated here to avoid importing hono
51
+ * in the framework package (which is browser-targeted). The actual
52
+ * implementation is provided by sh3-server at runtime.
53
+ */
54
+ type MiddlewareHandler = (c: unknown, next: () => Promise<void>) => Promise<void | Response>;
55
+ /**
56
+ * Hono app type — simplified stand-in. The actual Hono instance is
57
+ * provided by sh3-server.
58
+ */
59
+ type HonoLike = {
60
+ get(path: string, ...handlers: unknown[]): unknown;
61
+ post(path: string, ...handlers: unknown[]): unknown;
62
+ put(path: string, ...handlers: unknown[]): unknown;
63
+ patch(path: string, ...handlers: unknown[]): unknown;
64
+ delete(path: string, ...handlers: unknown[]): unknown;
65
+ use(path: string, ...handlers: unknown[]): unknown;
66
+ };
67
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Server-side shard contract.
3
+ *
4
+ * A server shard is the optional backend counterpart to a client shard.
5
+ * It runs in Node inside sh3-server and declares routes that are mounted
6
+ * under `/s/<shard-id>/`. Server shards have full Node access — filesystem,
7
+ * child_process, network, etc. — and are trusted by the admin who installed
8
+ * them.
9
+ *
10
+ * The server bundle is a separate ESM file whose default export conforms
11
+ * to the `ServerShard` interface.
12
+ */
13
+ export {};
@@ -95,6 +95,14 @@ export interface ShardManifest {
95
95
  * predate phase 8 must be updated to declare their views here.
96
96
  */
97
97
  views: ViewDeclaration[];
98
+ /**
99
+ * Optional filename of a server-side bundle for this shard. When present,
100
+ * sh3-server loads the bundle at boot and mounts its routes at
101
+ * `/s/<shard-id>/`. The server bundle runs in Node with full access.
102
+ * Only relevant for shards installed via the package store; framework-
103
+ * shipped shards do not use this field.
104
+ */
105
+ serverBundle?: string;
98
106
  }
99
107
  /**
100
108
  * Handed to `shard.activate`. The shard uses it to declare state and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sh3-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"