@sweidos/eidos 1.0.24 → 1.0.30
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/README.md +150 -11
- package/dist/action.js +98 -74
- package/dist/action.js.map +1 -1
- package/dist/devtools.d.ts +2 -0
- package/dist/devtools.js +597 -0
- package/dist/eidos.cjs.js +2 -2
- package/dist/eidos.cjs.js.map +1 -1
- package/dist/index.d.ts +64 -7
- package/dist/index.js +29 -27
- package/dist/nextjs.d.ts +2 -0
- package/dist/nextjs.js +12 -0
- package/dist/react/Devtools.d.ts +7 -0
- package/dist/react/hooks.js +41 -32
- package/dist/react/hooks.js.map +1 -1
- package/dist/resource.js +65 -55
- package/dist/resource.js.map +1 -1
- package/dist/runtime.js +12 -12
- package/dist/runtime.js.map +1 -1
- package/dist/store.js +35 -26
- package/dist/store.js.map +1 -1
- package/dist/stores.js +34 -21
- package/dist/stores.js.map +1 -1
- package/dist/sveltekit.d.ts +19 -0
- package/dist/sveltekit.js +9 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +14 -2
package/dist/store.js
CHANGED
|
@@ -1,55 +1,64 @@
|
|
|
1
|
-
let
|
|
1
|
+
let o;
|
|
2
2
|
const n = /* @__PURE__ */ new Set();
|
|
3
|
-
function
|
|
3
|
+
function a() {
|
|
4
4
|
n.forEach((e) => e());
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
6
|
+
function s(e) {
|
|
7
|
+
o = { ...o, ...e(o) }, a();
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
o = {
|
|
10
10
|
isOnline: typeof navigator < "u" ? navigator.onLine : !0,
|
|
11
11
|
swStatus: "idle",
|
|
12
12
|
swError: void 0,
|
|
13
13
|
resources: {},
|
|
14
14
|
queue: [],
|
|
15
|
-
setOnline: (e) =>
|
|
16
|
-
setSwStatus: (e, u) =>
|
|
17
|
-
registerResource: (e, u) =>
|
|
18
|
-
updateResource: (e, u) =>
|
|
15
|
+
setOnline: (e) => s(() => ({ isOnline: e })),
|
|
16
|
+
setSwStatus: (e, u) => s(() => ({ swStatus: e, swError: u })),
|
|
17
|
+
registerResource: (e, u) => s((t) => ({ resources: { ...t.resources, [e]: u } })),
|
|
18
|
+
updateResource: (e, u) => s((t) => ({
|
|
19
19
|
resources: {
|
|
20
20
|
...t.resources,
|
|
21
21
|
[e]: t.resources[e] ? { ...t.resources[e], ...u } : t.resources[e]
|
|
22
22
|
}
|
|
23
23
|
})),
|
|
24
|
-
unregisterResource: (e) =>
|
|
25
|
-
const { [e]: t, ...
|
|
26
|
-
return { resources:
|
|
24
|
+
unregisterResource: (e) => s((u) => {
|
|
25
|
+
const { [e]: t, ...r } = u.resources;
|
|
26
|
+
return { resources: r };
|
|
27
27
|
}),
|
|
28
|
-
addQueueItem: (e) =>
|
|
29
|
-
updateQueueItem: (e, u) =>
|
|
30
|
-
queue: t.queue.map((
|
|
28
|
+
addQueueItem: (e) => s((u) => ({ queue: [...u.queue, e] })),
|
|
29
|
+
updateQueueItem: (e, u) => s((t) => ({
|
|
30
|
+
queue: t.queue.map((r) => r.id === e ? { ...r, ...u } : r)
|
|
31
31
|
})),
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
batchUpdateQueueItems: (e) => s((u) => {
|
|
33
|
+
const t = new Map(e.map((r) => [r.id, r.update]));
|
|
34
|
+
return {
|
|
35
|
+
queue: u.queue.map((r) => {
|
|
36
|
+
const c = t.get(r.id);
|
|
37
|
+
return c ? { ...r, ...c } : r;
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
}),
|
|
41
|
+
removeQueueItem: (e) => s((u) => ({ queue: u.queue.filter((t) => t.id !== e) })),
|
|
42
|
+
hydrateQueue: (e) => s(() => ({ queue: e }))
|
|
34
43
|
};
|
|
35
|
-
function
|
|
36
|
-
return
|
|
44
|
+
function d() {
|
|
45
|
+
return o;
|
|
37
46
|
}
|
|
38
|
-
function
|
|
47
|
+
function i(e) {
|
|
39
48
|
return n.add(e), () => {
|
|
40
49
|
n.delete(e);
|
|
41
50
|
};
|
|
42
51
|
}
|
|
43
|
-
const
|
|
44
|
-
getState:
|
|
45
|
-
subscribe:
|
|
52
|
+
const f = {
|
|
53
|
+
getState: d,
|
|
54
|
+
subscribe: i,
|
|
46
55
|
// Test/devtools helper — merges partial state, preserves action methods.
|
|
47
56
|
setState: (e) => {
|
|
48
|
-
const u = typeof e == "function" ? e(
|
|
49
|
-
|
|
57
|
+
const u = typeof e == "function" ? e(o) : e;
|
|
58
|
+
o = { ...o, ...u }, a();
|
|
50
59
|
}
|
|
51
60
|
};
|
|
52
61
|
export {
|
|
53
|
-
|
|
62
|
+
f as useEidosStore
|
|
54
63
|
};
|
|
55
64
|
//# sourceMappingURL=store.js.map
|
package/dist/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import type { EidosState, ResourceEntry, ActionQueueItem } from './types'\n\nexport interface EidosStore extends EidosState {\n // Online\n setOnline: (online: boolean) => void\n // SW\n setSwStatus: (status: EidosState['swStatus'], error?: string) => void\n // Resources\n registerResource: (url: string, entry: ResourceEntry) => void\n updateResource: (url: string, update: Partial<ResourceEntry>) => void\n unregisterResource: (url: string) => void\n // Queue\n addQueueItem: (item: ActionQueueItem) => void\n updateQueueItem: (id: string, update: Partial<ActionQueueItem>) => void\n removeQueueItem: (id: string) => void\n hydrateQueue: (items: ActionQueueItem[]) => void\n}\n\ntype Listener = () => void\n\nlet _state: EidosStore\nconst _listeners = new Set<Listener>()\n\nfunction _notify() {\n _listeners.forEach((fn) => fn())\n}\n\nfunction _set(updater: (prev: EidosStore) => Partial<EidosStore>) {\n _state = { ..._state, ...updater(_state) }\n _notify()\n}\n\n_state = {\n isOnline: typeof navigator !== 'undefined' ? navigator.onLine : true,\n swStatus: 'idle',\n swError: undefined,\n resources: {},\n queue: [],\n\n setOnline: (isOnline) => _set(() => ({ isOnline })),\n\n setSwStatus: (swStatus, swError) => _set(() => ({ swStatus, swError })),\n\n registerResource: (url, entry) =>\n _set((s) => ({ resources: { ...s.resources, [url]: entry } })),\n\n updateResource: (url, update) =>\n _set((s) => ({\n resources: {\n ...s.resources,\n [url]: s.resources[url] ? { ...s.resources[url], ...update } : s.resources[url],\n },\n })),\n\n unregisterResource: (url) =>\n _set((s) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { [url]: _removed, ...rest } = s.resources\n return { resources: rest }\n }),\n\n addQueueItem: (item) => _set((s) => ({ queue: [...s.queue, item] })),\n\n updateQueueItem: (id, update) =>\n _set((s) => ({\n queue: s.queue.map((item) => (item.id === id ? { ...item, ...update } : item)),\n })),\n\n removeQueueItem: (id) => _set((s) => ({ queue: s.queue.filter((item) => item.id !== id) })),\n\n hydrateQueue: (items) => _set(() => ({ queue: items })),\n}\n\nfunction _getState() {\n return _state\n}\n\nfunction _subscribe(listener: Listener) {\n _listeners.add(listener)\n return () => { _listeners.delete(listener) }\n}\n\nexport const useEidosStore = {\n getState: _getState,\n subscribe: _subscribe,\n // Test/devtools helper — merges partial state, preserves action methods.\n setState: (partial: Partial<EidosStore> | ((s: EidosStore) => Partial<EidosStore>)) => {\n const update = typeof partial === 'function' ? partial(_state) : partial\n _state = { ..._state, ...update }\n _notify()\n },\n}\n"],"names":["_state","_listeners","_notify","fn","_set","updater","isOnline","swStatus","swError","url","entry","s","update","_removed","rest","item","id","items","_getState","_subscribe","listener","useEidosStore","partial"],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import type { EidosState, ResourceEntry, ActionQueueItem } from './types'\n\nexport interface EidosStore extends EidosState {\n // Online\n setOnline: (online: boolean) => void\n // SW\n setSwStatus: (status: EidosState['swStatus'], error?: string) => void\n // Resources\n registerResource: (url: string, entry: ResourceEntry) => void\n updateResource: (url: string, update: Partial<ResourceEntry>) => void\n unregisterResource: (url: string) => void\n // Queue\n addQueueItem: (item: ActionQueueItem) => void\n updateQueueItem: (id: string, update: Partial<ActionQueueItem>) => void\n batchUpdateQueueItems: (updates: Array<{ id: string; update: Partial<ActionQueueItem> }>) => void\n removeQueueItem: (id: string) => void\n hydrateQueue: (items: ActionQueueItem[]) => void\n}\n\ntype Listener = () => void\n\nlet _state: EidosStore\nconst _listeners = new Set<Listener>()\n\nfunction _notify() {\n _listeners.forEach((fn) => fn())\n}\n\nfunction _set(updater: (prev: EidosStore) => Partial<EidosStore>) {\n _state = { ..._state, ...updater(_state) }\n _notify()\n}\n\n_state = {\n isOnline: typeof navigator !== 'undefined' ? navigator.onLine : true,\n swStatus: 'idle',\n swError: undefined,\n resources: {},\n queue: [],\n\n setOnline: (isOnline) => _set(() => ({ isOnline })),\n\n setSwStatus: (swStatus, swError) => _set(() => ({ swStatus, swError })),\n\n registerResource: (url, entry) =>\n _set((s) => ({ resources: { ...s.resources, [url]: entry } })),\n\n updateResource: (url, update) =>\n _set((s) => ({\n resources: {\n ...s.resources,\n [url]: s.resources[url] ? { ...s.resources[url], ...update } : s.resources[url],\n },\n })),\n\n unregisterResource: (url) =>\n _set((s) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { [url]: _removed, ...rest } = s.resources\n return { resources: rest }\n }),\n\n addQueueItem: (item) => _set((s) => ({ queue: [...s.queue, item] })),\n\n updateQueueItem: (id, update) =>\n _set((s) => ({\n queue: s.queue.map((item) => (item.id === id ? { ...item, ...update } : item)),\n })),\n\n batchUpdateQueueItems: (updates) =>\n _set((s) => {\n const map = new Map(updates.map((u) => [u.id, u.update]))\n return {\n queue: s.queue.map((item) => {\n const u = map.get(item.id)\n return u ? { ...item, ...u } : item\n }),\n }\n }),\n\n removeQueueItem: (id) => _set((s) => ({ queue: s.queue.filter((item) => item.id !== id) })),\n\n hydrateQueue: (items) => _set(() => ({ queue: items })),\n}\n\nfunction _getState() {\n return _state\n}\n\nfunction _subscribe(listener: Listener) {\n _listeners.add(listener)\n return () => { _listeners.delete(listener) }\n}\n\nexport const useEidosStore = {\n getState: _getState,\n subscribe: _subscribe,\n // Test/devtools helper — merges partial state, preserves action methods.\n setState: (partial: Partial<EidosStore> | ((s: EidosStore) => Partial<EidosStore>)) => {\n const update = typeof partial === 'function' ? partial(_state) : partial\n _state = { ..._state, ...update }\n _notify()\n },\n}\n"],"names":["_state","_listeners","_notify","fn","_set","updater","isOnline","swStatus","swError","url","entry","s","update","_removed","rest","item","id","updates","map","u","items","_getState","_subscribe","listener","useEidosStore","partial"],"mappings":"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"}
|
package/dist/stores.js
CHANGED
|
@@ -1,36 +1,49 @@
|
|
|
1
1
|
import { useEidosStore as i } from "./store.js";
|
|
2
|
-
function
|
|
2
|
+
function o(e, t) {
|
|
3
|
+
const s = Object.keys(e);
|
|
4
|
+
if (s.length !== Object.keys(t).length) return !1;
|
|
5
|
+
for (const n of s)
|
|
6
|
+
if (e[n] !== t[n]) return !1;
|
|
7
|
+
return !0;
|
|
8
|
+
}
|
|
9
|
+
function u(e, t = Object.is) {
|
|
3
10
|
return {
|
|
4
|
-
subscribe(
|
|
5
|
-
|
|
11
|
+
subscribe(s) {
|
|
12
|
+
let n = e(i.getState());
|
|
13
|
+
return s(n), i.subscribe(() => {
|
|
14
|
+
const r = e(i.getState());
|
|
15
|
+
t(n, r) || (n = r, s(r));
|
|
16
|
+
});
|
|
6
17
|
},
|
|
7
18
|
getState() {
|
|
8
19
|
return e(i.getState());
|
|
9
20
|
}
|
|
10
21
|
};
|
|
11
22
|
}
|
|
12
|
-
const
|
|
13
|
-
isOnline: e.isOnline,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const f = u((e) => e), l = u((e) => e.queue), c = u(
|
|
24
|
+
(e) => ({ isOnline: e.isOnline, swStatus: e.swStatus, swError: e.swError }),
|
|
25
|
+
o
|
|
26
|
+
), d = u(
|
|
27
|
+
(e) => {
|
|
28
|
+
let t = 0, s = 0, n = 0;
|
|
29
|
+
for (const r of e.queue)
|
|
30
|
+
r.status === "pending" ? t++ : r.status === "failed" ? s++ : r.status === "replaying" && n++;
|
|
31
|
+
return { pending: t, failed: s, replaying: n, total: e.queue.length };
|
|
32
|
+
},
|
|
33
|
+
o
|
|
34
|
+
);
|
|
35
|
+
function g(e) {
|
|
36
|
+
return u((t) => t.resources[e]);
|
|
24
37
|
}
|
|
25
38
|
function S(e) {
|
|
26
|
-
return
|
|
39
|
+
return u((t) => t.queue.find((s) => s.id === e));
|
|
27
40
|
}
|
|
28
41
|
export {
|
|
29
42
|
S as eidosAction,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
l as eidosQueue,
|
|
44
|
+
d as eidosQueueStats,
|
|
45
|
+
g as eidosResource,
|
|
46
|
+
c as eidosStatus,
|
|
47
|
+
f as eidosStore
|
|
35
48
|
};
|
|
36
49
|
//# sourceMappingURL=stores.js.map
|
package/dist/stores.js.map
CHANGED
|
@@ -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
|
|
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;
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../src/version.ts"],"sourcesContent":["export const VERSION = '1.0.
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../src/version.ts"],"sourcesContent":["export const VERSION = '1.0.30'\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.
|
|
3
|
+
"version": "1.0.30",
|
|
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,18 @@
|
|
|
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"
|
|
51
63
|
}
|
|
52
64
|
},
|
|
53
65
|
"files": [
|
|
@@ -88,7 +100,7 @@
|
|
|
88
100
|
"vitest": "^2.1.9"
|
|
89
101
|
},
|
|
90
102
|
"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",
|
|
103
|
+
"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 && node scripts/copy-sw.mjs",
|
|
92
104
|
"dev": "vite build --watch",
|
|
93
105
|
"type-check": "tsc --noEmit",
|
|
94
106
|
"test": "vitest run",
|