@sweidos/eidos 1.0.25 → 1.0.31

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 +1 @@
1
- {"version":3,"file":"stores.js","sources":["../src/stores.ts"],"sourcesContent":["/**\n * Framework-agnostic reactive stores — compatible with Svelte's store protocol,\n * Vue's watchEffect, RxJS, and vanilla JS. Zero framework dependencies.\n *\n * Svelte: use the `$` prefix — `$eidosQueue`, `$eidosStatus`, etc.\n * Vue: call `.subscribe()` inside a composable with `onUnmounted` cleanup.\n * Vanilla: call `.subscribe(run)` directly; the return value unsubscribes.\n *\n * Each store calls its subscriber whenever any part of the Eidos state changes.\n * For fine-grained subscriptions, use `.getState()` to read the current snapshot\n * and compare manually in the subscriber callback.\n */\n\nimport { useEidosStore } from './store'\nimport type { EidosStore } from './store'\nimport type { ActionQueueItem, ResourceEntry } from './types'\n\n// ── Readable<T> — compatible with Svelte's Readable interface ─────────────────\n\nexport interface EidosReadable<T> {\n /** Subscribe to value changes. Returns an unsubscribe function. */\n subscribe(run: (value: T) => void): () => void\n /** Read the current value synchronously without subscribing. */\n getState(): T\n}\n\nfunction readable<T>(selector: (s: EidosStore) => T): EidosReadable<T> {\n return {\n subscribe(run) {\n // Emit current value immediately (Svelte store contract)\n run(selector(useEidosStore.getState()))\n return useEidosStore.subscribe(() => run(selector(useEidosStore.getState())))\n },\n getState() {\n return selector(useEidosStore.getState())\n },\n }\n}\n\n// ── Static stores (created once at module scope) ──────────────────────────────\n\n/** Full Eidos state snapshot. Prefer the narrower stores below. */\nexport const eidosStore: EidosReadable<EidosStore> = readable((s) => s)\n\n/** The action queue. Re-notifies on every queue mutation. */\nexport const eidosQueue: EidosReadable<ActionQueueItem[]> = readable((s) => s.queue)\n\n/**\n * Online status + SW lifecycle.\n * Object identity changes on every notification — destructure or compare fields\n * in the subscriber if you need to avoid unnecessary work.\n */\nexport const eidosStatus: EidosReadable<{\n isOnline: boolean\n swStatus: EidosStore['swStatus']\n swError: string | undefined\n}> = readable((s) => ({\n isOnline: s.isOnline,\n swStatus: s.swStatus,\n swError: s.swError,\n}))\n\n/**\n * Queue counts. Re-notifies on any queue mutation compare values inside the\n * subscriber callback to skip work when counts haven't changed.\n */\nexport const eidosQueueStats: EidosReadable<{\n pending: number\n failed: number\n replaying: number\n total: number\n}> = readable((s) => {\n // Single pass over the queue — avoids three separate .filter() calls.\n let pending = 0, failed = 0, replaying = 0\n for (const q of s.queue) {\n if (q.status === 'pending') pending++\n else if (q.status === 'failed') failed++\n else if (q.status === 'replaying') replaying++\n }\n return { pending, failed, replaying, total: s.queue.length }\n})\n\n// ── Dynamic stores (created per URL / ID) ─────────────────────────────────────\n\n/**\n * Live cache state for a single registered resource URL.\n * @example\n * // Svelte\n * const entry = eidosResource('/api/products')\n * $: hits = $entry?.cacheHits ?? 0\n */\nexport function eidosResource(url: string): EidosReadable<ResourceEntry | undefined> {\n return readable((s) => s.resources[url])\n}\n\n/**\n * Live state for a single queue item by ID. Returns `undefined` once the item\n * is removed from the queue (after a successful replay or `clearQueue()`).\n * @example\n * // Svelte\n * const item = eidosAction(queuedResult.id)\n * $: status = $item?.status // 'pending' | 'replaying' | 'succeeded' | 'failed' | undefined\n */\nexport function eidosAction(id: string): EidosReadable<ActionQueueItem | undefined> {\n return readable((s) => s.queue.find((item) => item.id === id))\n}\n"],"names":["readable","selector","run","useEidosStore","eidosStore","s","eidosQueue","eidosStatus","eidosQueueStats","pending","failed","replaying","q","eidosResource","url","eidosAction","id","item"],"mappings":";AA0BA,SAASA,EAAYC,GAAkD;AACrE,SAAO;AAAA,IACL,UAAUC,GAAK;AAEb,aAAAA,EAAID,EAASE,EAAc,SAAA,CAAU,CAAC,GAC/BA,EAAc,UAAU,MAAMD,EAAID,EAASE,EAAc,SAAA,CAAU,CAAC,CAAC;AAAA,IAC9E;AAAA,IACA,WAAW;AACT,aAAOF,EAASE,EAAc,UAAU;AAAA,IAC1C;AAAA,EAAA;AAEJ;AAKO,MAAMC,IAAwCJ,EAAS,CAACK,MAAMA,CAAC,GAGzDC,IAA+CN,EAAS,CAACK,MAAMA,EAAE,KAAK,GAOtEE,IAIRP,EAAS,CAACK,OAAO;AAAA,EACpB,UAAUA,EAAE;AAAA,EACZ,UAAUA,EAAE;AAAA,EACZ,SAASA,EAAE;AACb,EAAE,GAMWG,IAKRR,EAAS,CAACK,MAAM;AAEnB,MAAII,IAAU,GAAGC,IAAS,GAAGC,IAAY;AACzC,aAAWC,KAAKP,EAAE;AAChB,IAAIO,EAAE,WAAW,YAAWH,MACnBG,EAAE,WAAW,WAAUF,MACvBE,EAAE,WAAW,eAAaD;AAErC,SAAO,EAAE,SAAAF,GAAS,QAAAC,GAAQ,WAAAC,GAAW,OAAON,EAAE,MAAM,OAAA;AACtD,CAAC;AAWM,SAASQ,EAAcC,GAAuD;AACnF,SAAOd,EAAS,CAACK,MAAMA,EAAE,UAAUS,CAAG,CAAC;AACzC;AAUO,SAASC,EAAYC,GAAwD;AAClF,SAAOhB,EAAS,CAACK,MAAMA,EAAE,MAAM,KAAK,CAACY,MAASA,EAAK,OAAOD,CAAE,CAAC;AAC/D;"}
1
+ {"version":3,"file":"stores.js","sources":["../src/stores.ts"],"sourcesContent":["/**\n * Framework-agnostic reactive stores — compatible with Svelte's store protocol,\n * Vue's watchEffect, RxJS, and vanilla JS. Zero framework dependencies.\n *\n * Svelte: use the `$` prefix — `$eidosQueue`, `$eidosStatus`, etc.\n * Vue: call `.subscribe()` inside a composable with `onUnmounted` cleanup.\n * Vanilla: call `.subscribe(run)` directly; the return value unsubscribes.\n *\n * Each store calls its subscriber whenever any part of the Eidos state changes.\n * For fine-grained subscriptions, use `.getState()` to read the current snapshot\n * and compare manually in the subscriber callback.\n */\n\nimport { useEidosStore } from './store'\nimport type { EidosStore } from './store'\nimport type { ActionQueueItem, ResourceEntry } from './types'\n\n// ── Readable<T> — compatible with Svelte's Readable interface ─────────────────\n\nexport interface EidosReadable<T> {\n /** Subscribe to value changes. Returns an unsubscribe function. */\n subscribe(run: (value: T) => void): () => void\n /** Read the current value synchronously without subscribing. */\n getState(): T\n}\n\nfunction shallowEqual<T extends Record<string, unknown>>(a: T, b: T): boolean {\n const keys = Object.keys(a) as (keyof T)[]\n if (keys.length !== Object.keys(b).length) return false\n for (const k of keys) {\n if (a[k] !== b[k]) return false\n }\n return true\n}\n\nfunction readable<T>(\n selector: (s: EidosStore) => T,\n equal: (a: T, b: T) => boolean = Object.is,\n): EidosReadable<T> {\n return {\n subscribe(run) {\n // Emit current value immediately (Svelte store contract)\n let last = selector(useEidosStore.getState())\n run(last)\n return useEidosStore.subscribe(() => {\n const next = selector(useEidosStore.getState())\n if (!equal(last, next)) {\n last = next\n run(next)\n }\n })\n },\n getState() {\n return selector(useEidosStore.getState())\n },\n }\n}\n\n// ── Static stores (created once at module scope) ──────────────────────────────\n\n/** Full Eidos state snapshot. Prefer the narrower stores below. */\nexport const eidosStore: EidosReadable<EidosStore> = readable((s) => s)\n\n/** The action queue. Re-notifies on every queue mutation. */\nexport const eidosQueue: EidosReadable<ActionQueueItem[]> = readable((s) => s.queue)\n\n/**\n * Online status + SW lifecycle.\n * Only re-emits when isOnline, swStatus, or swError actually changes.\n */\nexport const eidosStatus: EidosReadable<{\n isOnline: boolean\n swStatus: EidosStore['swStatus']\n swError: string | undefined\n}> = readable(\n (s) => ({ isOnline: s.isOnline, swStatus: s.swStatus, swError: s.swError }),\n shallowEqual as (a: { isOnline: boolean; swStatus: EidosStore['swStatus']; swError: string | undefined }, b: { isOnline: boolean; swStatus: EidosStore['swStatus']; swError: string | undefined }) => boolean,\n)\n\n/**\n * Queue counts. Re-emits only when a count actually changes, not on every\n * queue mutation (e.g. a status transition that doesn't change counts is skipped).\n */\nexport const eidosQueueStats: EidosReadable<{\n pending: number\n failed: number\n replaying: number\n total: number\n}> = readable(\n (s) => {\n // Single pass over the queue — avoids three separate .filter() calls.\n let pending = 0, failed = 0, replaying = 0\n for (const q of s.queue) {\n if (q.status === 'pending') pending++\n else if (q.status === 'failed') failed++\n else if (q.status === 'replaying') replaying++\n }\n return { pending, failed, replaying, total: s.queue.length }\n },\n shallowEqual as (a: { pending: number; failed: number; replaying: number; total: number }, b: { pending: number; failed: number; replaying: number; total: number }) => boolean,\n)\n\n// ── Dynamic stores (created per URL / ID) ─────────────────────────────────────\n\n/**\n * Live cache state for a single registered resource URL.\n * @example\n * // Svelte\n * const entry = eidosResource('/api/products')\n * $: hits = $entry?.cacheHits ?? 0\n */\nexport function eidosResource(url: string): EidosReadable<ResourceEntry | undefined> {\n return readable((s) => s.resources[url])\n}\n\n/**\n * Live state for a single queue item by ID. Returns `undefined` once the item\n * is removed from the queue (after a successful replay or `clearQueue()`).\n * @example\n * // Svelte\n * const item = eidosAction(queuedResult.id)\n * $: status = $item?.status // 'pending' | 'replaying' | 'succeeded' | 'failed' | undefined\n */\nexport function eidosAction(id: string): EidosReadable<ActionQueueItem | undefined> {\n return readable((s) => s.queue.find((item) => item.id === id))\n}\n"],"names":["shallowEqual","a","b","keys","k","readable","selector","equal","run","last","useEidosStore","next","eidosStore","s","eidosQueue","eidosStatus","eidosQueueStats","pending","failed","replaying","q","eidosResource","url","eidosAction","id","item"],"mappings":";AA0BA,SAASA,EAAgDC,GAAMC,GAAe;AAC5E,QAAMC,IAAO,OAAO,KAAKF,CAAC;AAC1B,MAAIE,EAAK,WAAW,OAAO,KAAKD,CAAC,EAAE,OAAQ,QAAO;AAClD,aAAWE,KAAKD;AACd,QAAIF,EAAEG,CAAC,MAAMF,EAAEE,CAAC,EAAG,QAAO;AAE5B,SAAO;AACT;AAEA,SAASC,EACPC,GACAC,IAAiC,OAAO,IACtB;AAClB,SAAO;AAAA,IACL,UAAUC,GAAK;AAEb,UAAIC,IAAOH,EAASI,EAAc,SAAA,CAAU;AAC5C,aAAAF,EAAIC,CAAI,GACDC,EAAc,UAAU,MAAM;AACnC,cAAMC,IAAOL,EAASI,EAAc,SAAA,CAAU;AAC9C,QAAKH,EAAME,GAAME,CAAI,MACnBF,IAAOE,GACPH,EAAIG,CAAI;AAAA,MAEZ,CAAC;AAAA,IACH;AAAA,IACA,WAAW;AACT,aAAOL,EAASI,EAAc,UAAU;AAAA,IAC1C;AAAA,EAAA;AAEJ;AAKO,MAAME,IAAwCP,EAAS,CAACQ,MAAMA,CAAC,GAGzDC,IAA+CT,EAAS,CAACQ,MAAMA,EAAE,KAAK,GAMtEE,IAIRV;AAAA,EACH,CAACQ,OAAO,EAAE,UAAUA,EAAE,UAAU,UAAUA,EAAE,UAAU,SAASA,EAAE,QAAA;AAAA,EACjEb;AACF,GAMagB,IAKRX;AAAA,EACH,CAACQ,MAAM;AAEL,QAAII,IAAU,GAAGC,IAAS,GAAGC,IAAY;AACzC,eAAWC,KAAKP,EAAE;AAChB,MAAIO,EAAE,WAAW,YAAWH,MACnBG,EAAE,WAAW,WAAUF,MACvBE,EAAE,WAAW,eAAaD;AAErC,WAAO,EAAE,SAAAF,GAAS,QAAAC,GAAQ,WAAAC,GAAW,OAAON,EAAE,MAAM,OAAA;AAAA,EACtD;AAAA,EACAb;AACF;AAWO,SAASqB,EAAcC,GAAuD;AACnF,SAAOjB,EAAS,CAACQ,MAAMA,EAAE,UAAUS,CAAG,CAAC;AACzC;AAUO,SAASC,EAAYC,GAAwD;AAClF,SAAOnB,EAAS,CAACQ,MAAMA,EAAE,MAAM,KAAK,CAACY,MAASA,EAAK,OAAOD,CAAE,CAAC;AAC/D;"}
@@ -0,0 +1,19 @@
1
+ import { EidosConfig } from './index.ts';
2
+
3
+ /**
4
+ * Returns an `onMount`-compatible callback that initialises the Eidos runtime
5
+ * on the client only. Prevents SSR crashes caused by accessing `indexedDB` or
6
+ * `navigator.serviceWorker` during server-side rendering.
7
+ *
8
+ * Call inside `onMount()` in your root `+layout.svelte`:
9
+ *
10
+ * ```svelte
11
+ * <script>
12
+ * import { onMount } from 'svelte'
13
+ * import { initEidosSvelteKit } from '@sweidos/eidos/sveltekit'
14
+ *
15
+ * onMount(initEidosSvelteKit({ swPath: '/eidos-sw.js' }))
16
+ * </script>
17
+ * ```
18
+ */
19
+ export declare function initEidosSvelteKit(config?: EidosConfig): () => void;
@@ -0,0 +1,9 @@
1
+ import { initEidos } from "@sweidos/eidos";
2
+ function initEidosSvelteKit(config) {
3
+ return () => {
4
+ void initEidos(config);
5
+ };
6
+ }
7
+ export {
8
+ initEidosSvelteKit
9
+ };
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
- const o = "1.0.25";
1
+ const o = "1.0.31";
2
2
  export {
3
3
  o as VERSION
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sources":["../src/version.ts"],"sourcesContent":["export const VERSION = '1.0.25'\n"],"names":["VERSION"],"mappings":"AAAO,MAAMA,IAAU;"}
1
+ {"version":3,"file":"version.js","sources":["../src/version.ts"],"sourcesContent":["export const VERSION = '1.0.31'\n"],"names":["VERSION"],"mappings":"AAAO,MAAMA,IAAU;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sweidos/eidos",
3
- "version": "1.0.25",
3
+ "version": "1.0.31",
4
4
  "description": "Describe intent. The runtime figures out how. An abstraction layer for offline-first web apps.",
5
5
  "author": "Aditya Raj",
6
6
  "license": "MIT",
@@ -48,6 +48,22 @@
48
48
  "import": "./dist/testing.js",
49
49
  "require": "./dist/testing.cjs.js",
50
50
  "types": "./dist/testing.d.ts"
51
+ },
52
+ "./nextjs": {
53
+ "import": "./dist/nextjs.js",
54
+ "types": "./dist/nextjs.d.ts"
55
+ },
56
+ "./sveltekit": {
57
+ "import": "./dist/sveltekit.js",
58
+ "types": "./dist/sveltekit.d.ts"
59
+ },
60
+ "./devtools": {
61
+ "import": "./dist/devtools.js",
62
+ "types": "./dist/devtools.d.ts"
63
+ },
64
+ "./react-native": {
65
+ "import": "./dist/react-native.js",
66
+ "types": "./dist/react-native.d.ts"
51
67
  }
52
68
  },
53
69
  "files": [
@@ -88,7 +104,7 @@
88
104
  "vitest": "^2.1.9"
89
105
  },
90
106
  "scripts": {
91
- "build": "vite build && vite build --config vite.cjs.config.ts && vite build --config vite.plugin.config.ts && vite build --config vite.query.config.ts && vite build --config vite.testing.config.ts && node scripts/copy-sw.mjs",
107
+ "build": "vite build && vite build --config vite.cjs.config.ts && vite build --config vite.plugin.config.ts && vite build --config vite.query.config.ts && vite build --config vite.testing.config.ts && vite build --config vite.nextjs.config.ts && vite build --config vite.sveltekit.config.ts && vite build --config vite.devtools.config.ts && vite build --config vite.react-native.config.ts && node scripts/copy-sw.mjs",
92
108
  "dev": "vite build --watch",
93
109
  "type-check": "tsc --noEmit",
94
110
  "test": "vitest run",