@anchorlib/svelte 1.0.0-beta.11 → 1.0.0-beta.15

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.
Files changed (57) hide show
  1. package/dist/anchor.d.ts +84 -0
  2. package/dist/anchor.js +19 -0
  3. package/dist/anchor.js.map +1 -0
  4. package/dist/core/index.d.ts +1 -0
  5. package/dist/core/index.js +3 -0
  6. package/dist/core/index.js.map +1 -0
  7. package/dist/derive.d.ts +15 -0
  8. package/dist/derive.js +26 -0
  9. package/dist/derive.js.map +1 -0
  10. package/dist/fetch.d.ts +60 -0
  11. package/dist/fetch.js +12 -0
  12. package/dist/fetch.js.map +1 -0
  13. package/dist/history.d.ts +12 -0
  14. package/dist/history.js +9 -0
  15. package/dist/history.js.map +1 -0
  16. package/dist/immutable.d.ts +47 -0
  17. package/dist/immutable.js +12 -0
  18. package/dist/immutable.js.map +1 -0
  19. package/dist/index.d.ts +11 -305
  20. package/dist/index.js +12 -138
  21. package/dist/index.js.map +1 -1
  22. package/dist/model.d.ts +39 -0
  23. package/dist/model.js +12 -0
  24. package/dist/model.js.map +1 -0
  25. package/dist/observable.d.ts +15 -0
  26. package/dist/observable.js +28 -0
  27. package/dist/observable.js.map +1 -0
  28. package/dist/prop.d.ts +22 -0
  29. package/dist/prop.js +9 -0
  30. package/dist/prop.js.map +1 -0
  31. package/dist/reactive.js +20 -8
  32. package/dist/reactive.js.map +1 -1
  33. package/dist/ref.d.ts +51 -0
  34. package/dist/ref.js +35 -0
  35. package/dist/ref.js.map +1 -0
  36. package/dist/storage/index.d.ts +8 -60
  37. package/dist/storage/index.js +7 -66
  38. package/dist/storage/index.js.map +1 -1
  39. package/dist/storage/kv.d.ts +17 -0
  40. package/dist/storage/kv.js +14 -0
  41. package/dist/storage/kv.js.map +1 -0
  42. package/dist/storage/persistent.d.ts +18 -0
  43. package/dist/storage/persistent.js +14 -0
  44. package/dist/storage/persistent.js.map +1 -0
  45. package/dist/storage/session.d.ts +18 -0
  46. package/dist/storage/session.js +14 -0
  47. package/dist/storage/session.js.map +1 -0
  48. package/dist/storage/table.d.ts +13 -0
  49. package/dist/storage/table.js +45 -0
  50. package/dist/storage/table.js.map +1 -0
  51. package/dist/storage/types.d.ts +15 -0
  52. package/dist/storage/types.js +3 -0
  53. package/dist/storage/types.js.map +1 -0
  54. package/dist/types.d.ts +11 -0
  55. package/dist/types.js +3 -0
  56. package/dist/types.js.map +1 -0
  57. package/package.json +22 -21
package/dist/prop.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { KeyLike, State } from '@anchorlib/core';
2
+ import { ConstantRef } from './types.js';
3
+
4
+ type Props = {
5
+ [key: string]: KeyLike | State;
6
+ };
7
+ type PropsRef<T extends Props> = {
8
+ [K in keyof T]: T[K] extends State ? ConstantRef<T[K]> : T[K];
9
+ };
10
+ /**
11
+ * Creates a reactive state object from the provided props.
12
+ * For each property in the input props:
13
+ * - If the value is a State object, it will be converted to a derived state
14
+ * - Otherwise, the value will be kept as is
15
+ * @deprecated
16
+ * @template T - The type of props extending Props
17
+ * @param {T} props - The input props object containing KeyLike or State values
18
+ * @returns {PropsRef<T>} A new object with State values converted to reactive states
19
+ */
20
+ declare function propsRef<T extends Props>(props: T): T;
21
+
22
+ export { type Props, type PropsRef, propsRef };
package/dist/prop.js ADDED
@@ -0,0 +1,9 @@
1
+ import '@anchorlib/core';
2
+
3
+ function propsRef(props) {
4
+ return props;
5
+ }
6
+
7
+ export { propsRef };
8
+ //# sourceMappingURL=prop.js.map
9
+ //# sourceMappingURL=prop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/prop.ts"],"names":[],"mappings":";;AAqBO,SAAS,SAA0B,KAAA,EAAa;AACrD,EAAA,OAAO,KAAA;AACT","file":"prop.js","sourcesContent":["import { type KeyLike, type State } from '@anchorlib/core';\nimport type { ConstantRef } from './types.js';\n\nexport type Props = {\n [key: string]: KeyLike | State;\n};\n\nexport type PropsRef<T extends Props> = {\n [K in keyof T]: T[K] extends State ? ConstantRef<T[K]> : T[K];\n};\n\n/**\n * Creates a reactive state object from the provided props.\n * For each property in the input props:\n * - If the value is a State object, it will be converted to a derived state\n * - Otherwise, the value will be kept as is\n * @deprecated\n * @template T - The type of props extending Props\n * @param {T} props - The input props object containing KeyLike or State values\n * @returns {PropsRef<T>} A new object with State values converted to reactive states\n */\nexport function propsRef<T extends Props>(props: T): T {\n return props as never;\n}\n"]}
package/dist/reactive.js CHANGED
@@ -1,18 +1,23 @@
1
- import { setTracker, createObserver } from '@anchorlib/core';
1
+ import { setTracker, createObserver, setCleanUpHandler, onGlobalCleanup } from '@anchorlib/core';
2
+ import { onDestroy } from 'svelte';
2
3
  import { createSubscriber } from 'svelte/reactivity';
3
4
 
4
- // src/reactive.ts
5
- var TRACKER_REGISTRY = /* @__PURE__ */ new WeakMap();
6
- var bindingInitialized = false;
5
+ const TRACKER_REGISTRY = /* @__PURE__ */ new WeakMap();
6
+ let bindingInitialized = false;
7
7
  if (!bindingInitialized && typeof window !== "undefined") {
8
8
  bindingInitialized = true;
9
9
  setTracker((init, observers, key) => {
10
10
  if (!TRACKER_REGISTRY.has(init)) {
11
- let track = void 0;
11
+ let track;
12
12
  const subscribe = createSubscriber((update) => {
13
- const observer = createObserver(() => {
14
- update();
15
- });
13
+ const observer = createObserver(
14
+ () => {
15
+ observer.reset();
16
+ update();
17
+ },
18
+ void 0,
19
+ true
20
+ );
16
21
  track = observer.assign(init, observers);
17
22
  return () => {
18
23
  observer.destroy();
@@ -27,6 +32,13 @@ if (!bindingInitialized && typeof window !== "undefined") {
27
32
  }
28
33
  TRACKER_REGISTRY.get(init)?.(key);
29
34
  });
35
+ setCleanUpHandler((handler) => {
36
+ try {
37
+ return onDestroy(handler);
38
+ } catch (_error) {
39
+ return onGlobalCleanup(handler);
40
+ }
41
+ });
30
42
  }
31
43
 
32
44
  export { TRACKER_REGISTRY };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/reactive.ts"],"names":[],"mappings":";;;;AAGO,IAAM,gBAAA,uBAAuB,OAAA;AAEpC,IAAI,kBAAA,GAAqB,KAAA;AAEzB,IAAI,CAAC,kBAAA,IAAsB,OAAO,MAAA,KAAW,WAAA,EAAa;AACxD,EAAA,kBAAA,GAAqB,IAAA;AAWrB,EAAA,UAAA,CAAW,CAAC,IAAA,EAAM,SAAA,EAAW,GAAA,KAAQ;AAEnC,IAAA,IAAI,CAAC,gBAAA,CAAiB,GAAA,CAAI,IAAI,CAAA,EAAG;AAC/B,MAAA,IAAI,KAAA,GAA+C,MAAA;AAGnD,MAAA,MAAM,SAAA,GAAY,gBAAA,CAAiB,CAAC,MAAA,KAAW;AAE7C,QAAA,MAAM,QAAA,GAAW,eAAe,MAAM;AACpC,UAAA,MAAA,EAAO;AAAA,QACT,CAAC,CAAA;AAGD,QAAA,KAAA,GAAQ,QAAA,CAAS,MAAA,CAAO,IAAA,EAAM,SAAS,CAAA;AAGvC,QAAA,OAAO,MAAM;AACX,UAAA,QAAA,CAAS,OAAA,EAAQ;AACjB,UAAA,gBAAA,CAAiB,OAAO,IAAI,CAAA;AAAA,QAC9B,CAAA;AAAA,MACF,CAAC,CAAA;AAGD,MAAA,MAAM,MAAA,GAAS,CAAC,IAAA,KAAkB;AAEhC,QAAA,SAAA,EAAU;AAEV,QAAA,KAAA,GAAQ,IAAI,CAAA;AAAA,MACd,CAAA;AAGA,MAAA,gBAAA,CAAiB,GAAA,CAAI,MAAM,MAAM,CAAA;AAAA,IACnC;AAGA,IAAA,gBAAA,CAAiB,GAAA,CAAI,IAAI,CAAA,GAAI,GAAG,CAAA;AAAA,EAClC,CAAC,CAAA;AACH","file":"reactive.js","sourcesContent":["import { createObserver, type KeyLike, type Linkable, setTracker } from '@anchorlib/core';\nimport { createSubscriber } from 'svelte/reactivity';\n\nexport const TRACKER_REGISTRY = new WeakMap<Linkable, (prop: KeyLike) => void>();\n\nlet bindingInitialized = false;\n\nif (!bindingInitialized && typeof window !== 'undefined') {\n bindingInitialized = true;\n\n /**\n * Sets up a tracker function that integrates Anchor's reactivity system with Svelte's reactivity.\n * This tracker is responsible for creating observers that watch for changes in reactive objects\n * and properly subscribing/unsubscribing to Svelte's reactivity system.\n *\n * @param init - The initial linkable object to track\n * @param observers - The observers collection to use for tracking\n * @param key - The specific key/property to track on the object\n */\n setTracker((init, observers, key) => {\n // Only initialize the tracking setup once per object\n if (!TRACKER_REGISTRY.has(init)) {\n let track: ((prop: KeyLike) => void) | undefined = undefined;\n\n // Create a Svelte subscriber that manages the lifecycle of our observer\n const subscribe = createSubscriber((update) => {\n // Create an Anchor observer that will trigger the Svelte update when changes occur\n const observer = createObserver(() => {\n update();\n });\n\n // Assign the observer to track changes on the init object and its observers\n track = observer.assign(init, observers);\n\n // Return cleanup function to destroy observer and remove from registry\n return () => {\n observer.destroy();\n TRACKER_REGISTRY.delete(init);\n };\n });\n\n // Function to assign tracking to a specific key/property\n const assign = (prop: KeyLike) => {\n // Activate the subscription\n subscribe();\n // Track the specific property\n track?.(prop);\n };\n\n // Store the assign function in the registry for this object\n TRACKER_REGISTRY.set(init, assign);\n }\n\n // Execute the tracking function for the specific key\n TRACKER_REGISTRY.get(init)?.(key);\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/reactive.ts"],"names":[],"mappings":";;;;AAWO,MAAM,gBAAA,uBAAuB,OAAA;AAEpC,IAAI,kBAAA,GAAqB,KAAA;AAEzB,IAAI,CAAC,kBAAA,IAAsB,OAAO,MAAA,KAAW,WAAA,EAAa;AACxD,EAAA,kBAAA,GAAqB,IAAA;AAWrB,EAAA,UAAA,CAAW,CAAC,IAAA,EAAM,SAAA,EAAW,GAAA,KAAQ;AAEnC,IAAA,IAAI,CAAC,gBAAA,CAAiB,GAAA,CAAI,IAAI,CAAA,EAAG;AAC/B,MAAA,IAAI,KAAA;AAGJ,MAAA,MAAM,SAAA,GAAY,gBAAA,CAAiB,CAAC,MAAA,KAAW;AAE7C,QAAA,MAAM,QAAA,GAAW,cAAA;AAAA,UACf,MAAM;AACJ,YAAA,QAAA,CAAS,KAAA,EAAM;AACf,YAAA,MAAA,EAAO;AAAA,UACT,CAAA;AAAA,UACA,MAAA;AAAA,UACA;AAAA,SACF;AAGA,QAAA,KAAA,GAAQ,QAAA,CAAS,MAAA,CAAO,IAAA,EAAM,SAAS,CAAA;AAGvC,QAAA,OAAO,MAAM;AACX,UAAA,QAAA,CAAS,OAAA,EAAQ;AACjB,UAAA,gBAAA,CAAiB,OAAO,IAAI,CAAA;AAAA,QAC9B,CAAA;AAAA,MACF,CAAC,CAAA;AAGD,MAAA,MAAM,MAAA,GAAS,CAAC,IAAA,KAAkB;AAEhC,QAAA,SAAA,EAAU;AAEV,QAAA,KAAA,GAAQ,IAAI,CAAA;AAAA,MACd,CAAA;AAGA,MAAA,gBAAA,CAAiB,GAAA,CAAI,MAAM,MAAM,CAAA;AAAA,IACnC;AAGA,IAAA,gBAAA,CAAiB,GAAA,CAAI,IAAI,CAAA,GAAI,GAAG,CAAA;AAAA,EAClC,CAAC,CAAA;AAED,EAAA,iBAAA,CAAkB,CAAC,OAAA,KAAY;AAC7B,IAAA,IAAI;AACF,MAAA,OAAO,UAAU,OAAO,CAAA;AAAA,IAC1B,SAAS,MAAA,EAAQ;AACf,MAAA,OAAO,gBAAgB,OAAO,CAAA;AAAA,IAChC;AAAA,EACF,CAAC,CAAA;AACH","file":"reactive.js","sourcesContent":["import {\n createObserver,\n type KeyLike,\n type Linkable,\n onGlobalCleanup,\n setCleanUpHandler,\n setTracker,\n} from '@anchorlib/core';\nimport { onDestroy } from 'svelte';\nimport { createSubscriber } from 'svelte/reactivity';\n\nexport const TRACKER_REGISTRY = new WeakMap<Linkable, (prop: KeyLike) => void>();\n\nlet bindingInitialized = false;\n\nif (!bindingInitialized && typeof window !== 'undefined') {\n bindingInitialized = true;\n\n /**\n * Sets up a tracker function that integrates Anchor's reactivity system with Svelte's reactivity.\n * This tracker is responsible for creating observers that watch for changes in reactive objects\n * and properly subscribing/unsubscribing to Svelte's reactivity system.\n *\n * @param init - The initial linkable object to track\n * @param observers - The observers collection to use for tracking\n * @param key - The specific key/property to track on the object\n */\n setTracker((init, observers, key) => {\n // Only initialize the tracking setup once per object\n if (!TRACKER_REGISTRY.has(init)) {\n let track: ((prop: KeyLike) => void) | undefined;\n\n // Create a Svelte subscriber that manages the lifecycle of our observer\n const subscribe = createSubscriber((update) => {\n // Create an Anchor observer that will trigger the Svelte update when changes occur\n const observer = createObserver(\n () => {\n observer.reset();\n update();\n },\n undefined,\n true\n );\n\n // Assign the observer to track changes on the init object and its observers\n track = observer.assign(init, observers);\n\n // Return cleanup function to destroy observer and remove from registry\n return () => {\n observer.destroy();\n TRACKER_REGISTRY.delete(init);\n };\n });\n\n // Function to assign tracking to a specific key/property\n const assign = (prop: KeyLike) => {\n // Activate the subscription\n subscribe();\n // Track the specific property\n track?.(prop);\n };\n\n // Store the assign function in the registry for this object\n TRACKER_REGISTRY.set(init, assign);\n }\n\n // Execute the tracking function for the specific key\n TRACKER_REGISTRY.get(init)?.(key);\n });\n\n setCleanUpHandler((handler) => {\n try {\n return onDestroy(handler);\n } catch (_error) {\n return onGlobalCleanup(handler);\n }\n });\n}\n"]}
package/dist/ref.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { ConstantRef, StateRef, VariableRef } from './types.js';
2
+
3
+ declare const REF_REGISTRY: WeakMap<ConstantRef<unknown>, StateRef<unknown>>;
4
+ /**
5
+ * @deprecated Use 'mutable()' instead.
6
+ * Creates a readable reference that can be subscribed to for reactive updates.
7
+ * This function initializes a reactive reference with a given initial value and provides
8
+ * mechanisms for subscribing to changes and publishing updates to subscribers.
9
+ *
10
+ * @template T The type of the value being referenced
11
+ * @param init - The initial value for the reference
12
+ * @returns A readable reference object with subscribe and publish capabilities
13
+ */
14
+ declare function variableRef<T>(init: T): VariableRef<T>;
15
+ /**
16
+ * @deprecated Use 'mutable()' instead.
17
+ * Creates a constant (read-only) reference that can be subscribed to for reactive updates.
18
+ * This function initializes a reactive reference with a given initial value that cannot be modified
19
+ * after creation.
20
+ *
21
+ * @template T The type of the value being referenced
22
+ * @param init - The initial value for the reference
23
+ * @param constant - If true, the reference will be read-only and cannot be updated.
24
+ * @returns A constant reference object with subscribe capability but no write access
25
+ */
26
+ declare function variableRef<T>(init: T, constant: true): ConstantRef<T>;
27
+ /**
28
+ * @deprecated Use 'immutable()' instead.
29
+ * Creates a constant (read-only) reference that can be subscribed to for reactive updates.
30
+ * This function initializes a reactive reference with a given initial value that cannot be modified
31
+ * after creation. It's useful for values that should remain constant throughout the component lifecycle
32
+ * but still need to be reactively tracked.
33
+ *
34
+ * @template T The type of the value being referenced
35
+ * @param init - The initial value for the constant reference
36
+ * @returns A constant reference object with subscribe capability but no write access
37
+ */
38
+ declare function constantRef<T>(init: T): ConstantRef<T>;
39
+ /**
40
+ * @deprecated Use 'isValueRef()' instead.
41
+ * Checks if a given value is a writable reference.
42
+ * This function uses the REF_REGISTRY to determine if the provided value
43
+ * is a registered writable reference.
44
+ *
45
+ * @template T The type of the value that the reference holds
46
+ * @param ref - The value to check
47
+ * @returns True if the value is a writable reference, false otherwise
48
+ */
49
+ declare function isRef<T>(ref: unknown): ref is VariableRef<T>;
50
+
51
+ export { REF_REGISTRY, constantRef, isRef, variableRef };
package/dist/ref.js ADDED
@@ -0,0 +1,35 @@
1
+ import { anchor } from '@anchorlib/core';
2
+ import { onDestroy } from 'svelte';
3
+
4
+ const REF_REGISTRY = /* @__PURE__ */ new WeakMap();
5
+ function variableRef(init, constant) {
6
+ const valueRef = anchor({ value: init }, { recursive: true });
7
+ const set = (value) => {
8
+ if (constant === true || value === valueRef.value) return;
9
+ valueRef.value = value;
10
+ };
11
+ onDestroy(() => {
12
+ REF_REGISTRY.delete(stateRef);
13
+ anchor.destroy(valueRef);
14
+ });
15
+ const stateRef = {
16
+ get value() {
17
+ return valueRef.value;
18
+ },
19
+ set value(value) {
20
+ set(value);
21
+ }
22
+ };
23
+ REF_REGISTRY.set(stateRef, valueRef);
24
+ return stateRef;
25
+ }
26
+ function constantRef(init) {
27
+ return variableRef(init, true);
28
+ }
29
+ function isRef(ref) {
30
+ return REF_REGISTRY.has(ref);
31
+ }
32
+
33
+ export { REF_REGISTRY, constantRef, isRef, variableRef };
34
+ //# sourceMappingURL=ref.js.map
35
+ //# sourceMappingURL=ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ref.ts"],"names":[],"mappings":";;;AAIO,MAAM,YAAA,uBAAmB,OAAA;AAsCzB,SAAS,WAAA,CAAe,MAAS,QAAA,EAAoB;AAC1D,EAAA,MAAM,QAAA,GAAW,OAAO,EAAE,KAAA,EAAO,MAAK,EAAG,EAAE,SAAA,EAAW,IAAA,EAAM,CAAA;AAE5D,EAAA,MAAM,GAAA,GAAM,CAAC,KAAA,KAAa;AAExB,IAAA,IAAI,QAAA,KAAa,IAAA,IAAQ,KAAA,KAAU,QAAA,CAAS,KAAA,EAAO;AAEnD,IAAA,QAAA,CAAS,KAAA,GAAQ,KAAA;AAAA,EACnB,CAAA;AAEA,EAAA,SAAA,CAAU,MAAM;AAEd,IAAA,YAAA,CAAa,OAAO,QAAgC,CAAA;AAGpD,IAAA,MAAA,CAAO,QAAQ,QAAQ,CAAA;AAAA,EACzB,CAAC,CAAA;AAED,EAAA,MAAM,QAAA,GAAW;AAAA,IACf,IAAI,KAAA,GAAQ;AACV,MAAA,OAAO,QAAA,CAAS,KAAA;AAAA,IAClB,CAAA;AAAA,IACA,IAAI,MAAM,KAAA,EAAU;AAClB,MAAA,GAAA,CAAI,KAAK,CAAA;AAAA,IACX;AAAA,GACF;AAEA,EAAA,YAAA,CAAa,GAAA,CAAI,UAAkC,QAAQ,CAAA;AAE3D,EAAA,OAAO,QAAA;AACT;AAaO,SAAS,YAAe,IAAA,EAAyB;AACtD,EAAA,OAAO,WAAA,CAAY,MAAM,IAAI,CAAA;AAC/B;AAYO,SAAS,MAAS,GAAA,EAAqC;AAC5D,EAAA,OAAO,YAAA,CAAa,IAAI,GAA2B,CAAA;AACrD","file":"ref.js","sourcesContent":["import type { ConstantRef, StateRef, VariableRef } from './types.js';\nimport { anchor } from '@anchorlib/core';\nimport { onDestroy } from 'svelte';\n\nexport const REF_REGISTRY = new WeakMap<ConstantRef<unknown>, StateRef<unknown>>();\n\n/**\n * @deprecated Use 'mutable()' instead.\n * Creates a readable reference that can be subscribed to for reactive updates.\n * This function initializes a reactive reference with a given initial value and provides\n * mechanisms for subscribing to changes and publishing updates to subscribers.\n *\n * @template T The type of the value being referenced\n * @param init - The initial value for the reference\n * @returns A readable reference object with subscribe and publish capabilities\n */\nexport function variableRef<T>(init: T): VariableRef<T>;\n\n/**\n * @deprecated Use 'mutable()' instead.\n * Creates a constant (read-only) reference that can be subscribed to for reactive updates.\n * This function initializes a reactive reference with a given initial value that cannot be modified\n * after creation.\n *\n * @template T The type of the value being referenced\n * @param init - The initial value for the reference\n * @param constant - If true, the reference will be read-only and cannot be updated.\n * @returns A constant reference object with subscribe capability but no write access\n */\nexport function variableRef<T>(init: T, constant: true): ConstantRef<T>;\n\n/**\n * @deprecated Use 'mutable()' instead.\n * Creates a readable reference that can be subscribed to for reactive updates.\n * This function initializes a reactive reference with a given initial value and provides\n * mechanisms for subscribing to changes and publishing updates to subscribers.\n *\n * @template T The type of the value being referenced\n * @param init - The initial value for the reference\n * @param constant - If true, the reference will be read-only and cannot be updated.\n * @returns A readable reference object with subscribe and publish capabilities\n */\nexport function variableRef<T>(init: T, constant?: boolean) {\n const valueRef = anchor({ value: init }, { recursive: true });\n\n const set = (value: T) => {\n // Ignore if the value is the same.\n if (constant === true || value === valueRef.value) return;\n\n valueRef.value = value;\n };\n\n onDestroy(() => {\n // Remove the ref from the registry.\n REF_REGISTRY.delete(stateRef as ConstantRef<unknown>);\n\n // Destroy the ref state.\n anchor.destroy(valueRef);\n });\n\n const stateRef = {\n get value() {\n return valueRef.value;\n },\n set value(value: T) {\n set(value);\n },\n } as never;\n\n REF_REGISTRY.set(stateRef as ConstantRef<unknown>, valueRef);\n\n return stateRef as ConstantRef<T>;\n}\n\n/**\n * @deprecated Use 'immutable()' instead.\n * Creates a constant (read-only) reference that can be subscribed to for reactive updates.\n * This function initializes a reactive reference with a given initial value that cannot be modified\n * after creation. It's useful for values that should remain constant throughout the component lifecycle\n * but still need to be reactively tracked.\n *\n * @template T The type of the value being referenced\n * @param init - The initial value for the constant reference\n * @returns A constant reference object with subscribe capability but no write access\n */\nexport function constantRef<T>(init: T): ConstantRef<T> {\n return variableRef(init, true);\n}\n\n/**\n * @deprecated Use 'isValueRef()' instead.\n * Checks if a given value is a writable reference.\n * This function uses the REF_REGISTRY to determine if the provided value\n * is a registered writable reference.\n *\n * @template T The type of the value that the reference holds\n * @param ref - The value to check\n * @returns True if the value is a writable reference, false otherwise\n */\nexport function isRef<T>(ref: unknown): ref is VariableRef<T> {\n return REF_REGISTRY.has(ref as VariableRef<unknown>);\n}"]}
@@ -1,60 +1,8 @@
1
- import { Storable, KVState, Rec, Row, RowState, FilterFn, RowListState, ReactiveTable, InferRec } from '@anchorlib/storage/db';
2
- import { ObjLike, LinkableSchema, StateOptions } from '@anchorlib/core';
3
-
4
- /**
5
- * Creates a reactive key-value store state.
6
- *
7
- * This function initializes a key-value store with the given name and initial value,
8
- * and automatically cleans up the store subscription when the component is destroyed.
9
- *
10
- * @template T - The type of the stored value, must extend Storable
11
- * @param name - The unique identifier for the key-value store
12
- * @param init - The initial value for the store
13
- * @returns A reactive key-value store state.
14
- */
15
- declare function kvRef<T extends Storable>(name: string, init: T): KVState<T>;
16
-
17
- /**
18
- * Creates a persistent reactive state using the provided name, initial value, and options.
19
- * The persistentRef is tied to the browser's local storage, meaning its value will persist
20
- * across page reloads and browser sessions until explicitly cleared.
21
- *
22
- * @template T - The type of the initial value, must extend object-like structure.
23
- * @template S - The schema type for linkable validation, defaults to LinkableSchema.
24
- * @param name - A unique string identifier for the local storage key.
25
- * @param init - The initial value to be stored in local storage.
26
- * @param options - Optional configuration for state behavior and validation schema.
27
- * @returns A reactive state that provides reactive access and modification capabilities.
28
- */
29
- declare function persistentRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
30
-
31
- /**
32
- * Creates a session-scoped reactive state using the provided name, initial value, and options.
33
- * The sessionRef is tied to the browser's session storage, meaning its value will persist
34
- * across page reloads but not after the session ends (e.g., tab/window closed).
35
- *
36
- * @template T - The type of the initial value, must extend object-like structure.
37
- * @template S - The schema type for linkable validation, defaults to LinkableSchema.
38
- * @param name - A unique string identifier for the session storage key.
39
- * @param init - The initial value to be stored in session storage.
40
- * @param options - Optional configuration for state behavior and validation schema.
41
- * @returns A reactive state that provides reactive access and modification capabilities.
42
- */
43
- declare function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
44
-
45
- interface TableRef<T extends Rec, R extends Row<T> = Row<T>> {
46
- get(id: string): RowState<R>;
47
- add(payload: T): RowState<R>;
48
- remove(id: string): RowState<R>;
49
- list(filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection): RowListState<R>;
50
- listByIndex(name: keyof R, filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection): RowListState<R>;
51
- seed<T extends R[]>(seeds: T): this;
52
- table(): ReactiveTable<T>;
53
- }
54
- type InferRef<T> = T extends TableRef<Rec, infer R> ? R : never;
55
- type InferListRef<T> = T extends TableRef<Rec, infer R> ? R[] : never;
56
-
57
- declare function createTableRef<T extends ReactiveTable<Rec>>(table: T): TableRef<InferRec<T>>;
58
- declare function createTableRef<T extends Rec, R extends Row<T> = Row<T>>(name: string, version?: number, indexes?: (keyof R)[], remIndexes?: (keyof R)[], dbName?: string): TableRef<T, R>;
59
-
60
- export { type InferListRef, type InferRef, type TableRef, createTableRef, kvRef, persistentRef, sessionRef };
1
+ export * from '@anchorlib/storage';
2
+ export { kvRef } from './kv.js';
3
+ export { persistentRef } from './persistent.js';
4
+ export { sessionRef } from './session.js';
5
+ export { createTableRef } from './table.js';
6
+ export { InferListRef, InferRef, TableRef } from './types.js';
7
+ import '@anchorlib/storage/db';
8
+ import '@anchorlib/core';
@@ -1,68 +1,9 @@
1
- import { kv, createTable } from '@anchorlib/storage/db';
2
- import { onDestroy } from 'svelte';
3
- import { persistent, session } from '@anchorlib/storage';
4
-
5
- // src/storage/kv.ts
6
- function kvRef(name, init) {
7
- const state = kv(name, init);
8
- onDestroy(() => {
9
- kv.leave(state);
10
- });
11
- return state;
12
- }
13
- function persistentRef(name, init, options) {
14
- const state = persistent(name, init, options);
15
- onDestroy(() => {
16
- persistent.leave(state);
17
- });
18
- return state;
19
- }
20
- function sessionRef(name, init, options) {
21
- const state = session(name, init, options);
22
- onDestroy(() => {
23
- session.leave(state);
24
- });
25
- return state;
26
- }
27
- function createTableRef(tableName, version = 1, indexes, remIndexes, dbName = tableName) {
28
- if (typeof tableName === "string") {
29
- tableName = createTable(tableName, version, indexes, remIndexes, dbName);
30
- }
31
- const tableRef = tableName;
32
- return {
33
- get(id) {
34
- const state = tableRef.get(id);
35
- onDestroy(() => {
36
- tableRef.leave(id);
37
- });
38
- return state;
39
- },
40
- add(payload) {
41
- const state = tableRef.add(payload);
42
- onDestroy(() => {
43
- tableRef.leave(state.data.id);
44
- });
45
- return state;
46
- },
47
- list(filter, limit, direction) {
48
- return tableRef.list(filter, limit, direction);
49
- },
50
- listByIndex(name, filter, limit, direction) {
51
- return tableRef.listByIndex(name, filter, limit, direction);
52
- },
53
- remove(id) {
54
- return tableRef.remove(id);
55
- },
56
- seed(seeds) {
57
- tableRef.seed(seeds);
58
- return this;
59
- },
60
- table() {
61
- return tableRef;
62
- }
63
- };
64
- }
65
-
66
- export { createTableRef, kvRef, persistentRef, sessionRef };
1
+ import '../reactive.js';
2
+ export * from '@anchorlib/storage';
3
+ export * from './kv.js';
4
+ export * from './persistent.js';
5
+ export * from './session.js';
6
+ export * from './table.js';
7
+ export * from './types.js';
67
8
  //# sourceMappingURL=index.js.map
68
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/storage/kv.ts","../../src/storage/persistent.ts","../../src/storage/session.ts","../../src/storage/table.ts"],"names":["onDestroy"],"mappings":";;;;;AAcO,SAAS,KAAA,CAA0B,MAAc,IAAA,EAAqB;AAC3E,EAAA,MAAM,KAAA,GAAQ,EAAA,CAAG,IAAA,EAAM,IAAI,CAAA;AAE3B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,EAAA,CAAG,MAAM,KAAK,CAAA;AAAA,EAChB,CAAC,CAAA;AAED,EAAA,OAAO,KAAA;AACT;ACNO,SAAS,aAAA,CACd,IAAA,EACA,IAAA,EACA,OAAA,EACG;AACH,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,IAAA,EAAM,IAAA,EAAM,OAAO,CAAA;AAE5C,EAAAA,UAAU,MAAM;AACd,IAAA,UAAA,CAAW,MAAM,KAAK,CAAA;AAAA,EACxB,CAAC,CAAA;AAED,EAAA,OAAO,KAAA;AACT;ACZO,SAAS,UAAA,CACd,IAAA,EACA,IAAA,EACA,OAAA,EACG;AACH,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,IAAA,EAAM,IAAA,EAAM,OAAO,CAAA;AAEzC,EAAAA,UAAU,MAAM;AACd,IAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA,EACrB,CAAC,CAAA;AAED,EAAA,OAAO,KAAA;AACT;ACTO,SAAS,eACd,SAAA,EACA,OAAA,GAAU,GACV,OAAA,EACA,UAAA,EACA,SAAS,SAAA,EACO;AAChB,EAAA,IAAI,OAAO,cAAc,QAAA,EAAU;AACjC,IAAA,SAAA,GAAY,WAAA,CAAkB,SAAA,EAAW,OAAA,EAAS,OAAA,EAAS,YAAY,MAAM,CAAA;AAAA,EAC/E;AAEA,EAAA,MAAM,QAAA,GAAW,SAAA;AAEjB,EAAA,OAAO;AAAA,IACL,IAAI,EAAA,EAAY;AACd,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,GAAA,CAAI,EAAE,CAAA;AAE7B,MAAAA,UAAU,MAAM;AACd,QAAA,QAAA,CAAS,MAAM,EAAE,CAAA;AAAA,MACnB,CAAC,CAAA;AAED,MAAA,OAAO,KAAA;AAAA,IACT,CAAA;AAAA,IACA,IAAI,OAAA,EAAY;AACd,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,GAAA,CAAI,OAAO,CAAA;AAElC,MAAAA,UAAU,MAAM;AACd,QAAA,QAAA,CAAS,KAAA,CAAM,KAAA,CAAM,IAAA,CAAK,EAAE,CAAA;AAAA,MAC9B,CAAC,CAAA;AAED,MAAA,OAAO,KAAA;AAAA,IACT,CAAA;AAAA,IACA,IAAA,CAAK,MAAA,EAAoC,KAAA,EAAgB,SAAA,EAAgC;AACvF,MAAA,OAAO,QAAA,CAAS,IAAA,CAAK,MAAA,EAAQ,KAAA,EAAO,SAAS,CAAA;AAAA,IAC/C,CAAA;AAAA,IACA,WAAA,CAAY,IAAA,EAAe,MAAA,EAAoC,KAAA,EAAgB,SAAA,EAAgC;AAC7G,MAAA,OAAO,QAAA,CAAS,WAAA,CAAY,IAAA,EAAM,MAAA,EAAQ,OAAO,SAAS,CAAA;AAAA,IAC5D,CAAA;AAAA,IACA,OAAO,EAAA,EAAY;AACjB,MAAA,OAAO,QAAA,CAAS,OAAO,EAAE,CAAA;AAAA,IAC3B,CAAA;AAAA,IACA,KAAK,KAAA,EAAY;AACf,MAAA,QAAA,CAAS,KAAK,KAAK,CAAA;AACnB,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,KAAA,GAAQ;AACN,MAAA,OAAO,QAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import { kv, type KVState, type Storable } from '@anchorlib/storage/db';\nimport { onDestroy } from 'svelte';\n\n/**\n * Creates a reactive key-value store state.\n *\n * This function initializes a key-value store with the given name and initial value,\n * and automatically cleans up the store subscription when the component is destroyed.\n *\n * @template T - The type of the stored value, must extend Storable\n * @param name - The unique identifier for the key-value store\n * @param init - The initial value for the store\n * @returns A reactive key-value store state.\n */\nexport function kvRef<T extends Storable>(name: string, init: T): KVState<T> {\n const state = kv(name, init);\n\n onDestroy(() => {\n kv.leave(state);\n });\n\n return state;\n}\n","import type { LinkableSchema, ObjLike, StateOptions } from '@anchorlib/core';\nimport { persistent } from '@anchorlib/storage';\nimport { onDestroy } from 'svelte';\n\n/**\n * Creates a persistent reactive state using the provided name, initial value, and options.\n * The persistentRef is tied to the browser's local storage, meaning its value will persist\n * across page reloads and browser sessions until explicitly cleared.\n *\n * @template T - The type of the initial value, must extend object-like structure.\n * @template S - The schema type for linkable validation, defaults to LinkableSchema.\n * @param name - A unique string identifier for the local storage key.\n * @param init - The initial value to be stored in local storage.\n * @param options - Optional configuration for state behavior and validation schema.\n * @returns A reactive state that provides reactive access and modification capabilities.\n */\nexport function persistentRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(\n name: string,\n init: T,\n options?: StateOptions<S>\n): T {\n const state = persistent(name, init, options);\n\n onDestroy(() => {\n persistent.leave(state);\n });\n\n return state;\n}\n","import type { LinkableSchema, ObjLike, StateOptions } from '@anchorlib/core';\nimport { session } from '@anchorlib/storage';\nimport { onDestroy } from 'svelte';\n\n/**\n * Creates a session-scoped reactive state using the provided name, initial value, and options.\n * The sessionRef is tied to the browser's session storage, meaning its value will persist\n * across page reloads but not after the session ends (e.g., tab/window closed).\n *\n * @template T - The type of the initial value, must extend object-like structure.\n * @template S - The schema type for linkable validation, defaults to LinkableSchema.\n * @param name - A unique string identifier for the session storage key.\n * @param init - The initial value to be stored in session storage.\n * @param options - Optional configuration for state behavior and validation schema.\n * @returns A reactive state that provides reactive access and modification capabilities.\n */\nexport function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(\n name: string,\n init: T,\n options?: StateOptions<S>\n): T {\n const state = session(name, init, options);\n\n onDestroy(() => {\n session.leave(state);\n });\n\n return state;\n}\n","import {\n createTable,\n type FilterFn,\n type InferRec,\n type ReactiveTable,\n type Rec,\n type Row,\n} from '@anchorlib/storage/db';\nimport { onDestroy } from 'svelte';\nimport type { TableRef } from './types.js';\n\nexport function createTableRef<T extends ReactiveTable<Rec>>(table: T): TableRef<InferRec<T>>;\nexport function createTableRef<T extends Rec, R extends Row<T> = Row<T>>(\n name: string,\n version?: number,\n indexes?: (keyof R)[],\n remIndexes?: (keyof R)[],\n dbName?: string\n): TableRef<T, R>;\nexport function createTableRef<T extends Rec, R extends Row<T> = Row<T>>(\n tableName: string | ReactiveTable<T>,\n version = 1,\n indexes?: (keyof R)[],\n remIndexes?: (keyof R)[],\n dbName = tableName as string\n): TableRef<T, R> {\n if (typeof tableName === 'string') {\n tableName = createTable<T, R>(tableName, version, indexes, remIndexes, dbName);\n }\n\n const tableRef = tableName as ReactiveTable<T, R>;\n\n return {\n get(id: string) {\n const state = tableRef.get(id);\n\n onDestroy(() => {\n tableRef.leave(id);\n });\n\n return state;\n },\n add(payload: T) {\n const state = tableRef.add(payload);\n\n onDestroy(() => {\n tableRef.leave(state.data.id);\n });\n\n return state;\n },\n list(filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection) {\n return tableRef.list(filter, limit, direction);\n },\n listByIndex(name: keyof R, filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection) {\n return tableRef.listByIndex(name, filter, limit, direction);\n },\n remove(id: string) {\n return tableRef.remove(id);\n },\n seed(seeds: R[]) {\n tableRef.seed(seeds);\n return this;\n },\n table() {\n return tableRef;\n },\n };\n}\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
@@ -0,0 +1,17 @@
1
+ import { Storable, KVState } from '@anchorlib/storage/db';
2
+
3
+ /**
4
+ * @deprecated Use `kv()` instead.
5
+ * Creates a reactive key-value store state.
6
+ *
7
+ * This function initializes a key-value store with the given name and initial value,
8
+ * and automatically cleans up the store subscription when the component is destroyed.
9
+ *
10
+ * @template T - The type of the stored value, must extend Storable
11
+ * @param name - The unique identifier for the key-value store
12
+ * @param init - The initial value for the store
13
+ * @returns A reactive key-value store state.
14
+ */
15
+ declare function kvRef<T extends Storable>(name: string, init: T): KVState<T>;
16
+
17
+ export { kvRef };
@@ -0,0 +1,14 @@
1
+ import { kv } from '@anchorlib/storage/db';
2
+ import { onDestroy } from 'svelte';
3
+
4
+ function kvRef(name, init) {
5
+ const state = kv(name, init);
6
+ onDestroy(() => {
7
+ kv.leave(state);
8
+ });
9
+ return state;
10
+ }
11
+
12
+ export { kvRef };
13
+ //# sourceMappingURL=kv.js.map
14
+ //# sourceMappingURL=kv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/storage/kv.ts"],"names":[],"mappings":";;;AAeO,SAAS,KAAA,CAA0B,MAAc,IAAA,EAAqB;AAC3E,EAAA,MAAM,KAAA,GAAQ,EAAA,CAAG,IAAA,EAAM,IAAI,CAAA;AAE3B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,EAAA,CAAG,MAAM,KAAK,CAAA;AAAA,EAChB,CAAC,CAAA;AAED,EAAA,OAAO,KAAA;AACT","file":"kv.js","sourcesContent":["import { kv, type KVState, type Storable } from '@anchorlib/storage/db';\nimport { onDestroy } from 'svelte';\n\n/**\n * @deprecated Use `kv()` instead.\n * Creates a reactive key-value store state.\n *\n * This function initializes a key-value store with the given name and initial value,\n * and automatically cleans up the store subscription when the component is destroyed.\n *\n * @template T - The type of the stored value, must extend Storable\n * @param name - The unique identifier for the key-value store\n * @param init - The initial value for the store\n * @returns A reactive key-value store state.\n */\nexport function kvRef<T extends Storable>(name: string, init: T): KVState<T> {\n const state = kv(name, init);\n\n onDestroy(() => {\n kv.leave(state);\n });\n\n return state;\n}"]}
@@ -0,0 +1,18 @@
1
+ import { ObjLike, LinkableSchema, StateOptions } from '@anchorlib/core';
2
+
3
+ /**
4
+ * @deprecated Use `persistent()` instead.
5
+ * Creates a persistent reactive state using the provided name, initial value, and options.
6
+ * The persistentRef is tied to the browser's local storage, meaning its value will persist
7
+ * across page reloads and browser sessions until explicitly cleared.
8
+ *
9
+ * @template T - The type of the initial value, must extend object-like structure.
10
+ * @template S - The schema type for linkable validation, defaults to LinkableSchema.
11
+ * @param name - A unique string identifier for the local storage key.
12
+ * @param init - The initial value to be stored in local storage.
13
+ * @param options - Optional configuration for state behavior and validation schema.
14
+ * @returns A reactive state that provides reactive access and modification capabilities.
15
+ */
16
+ declare function persistentRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
17
+
18
+ export { persistentRef };
@@ -0,0 +1,14 @@
1
+ import { persistent } from '@anchorlib/storage';
2
+ import { onDestroy } from 'svelte';
3
+
4
+ function persistentRef(name, init, options) {
5
+ const state = persistent(name, init, options);
6
+ onDestroy(() => {
7
+ persistent.leave(state);
8
+ });
9
+ return state;
10
+ }
11
+
12
+ export { persistentRef };
13
+ //# sourceMappingURL=persistent.js.map
14
+ //# sourceMappingURL=persistent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/storage/persistent.ts"],"names":[],"mappings":";;;AAiBO,SAAS,aAAA,CACd,IAAA,EACA,IAAA,EACA,OAAA,EACG;AACH,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,IAAA,EAAM,IAAA,EAAM,OAAO,CAAA;AAE5C,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,UAAA,CAAW,MAAM,KAAK,CAAA;AAAA,EACxB,CAAC,CAAA;AAED,EAAA,OAAO,KAAA;AACT","file":"persistent.js","sourcesContent":["import type { LinkableSchema, ObjLike, StateOptions } from '@anchorlib/core';\nimport { persistent } from '@anchorlib/storage';\nimport { onDestroy } from 'svelte';\n\n/**\n * @deprecated Use `persistent()` instead.\n * Creates a persistent reactive state using the provided name, initial value, and options.\n * The persistentRef is tied to the browser's local storage, meaning its value will persist\n * across page reloads and browser sessions until explicitly cleared.\n *\n * @template T - The type of the initial value, must extend object-like structure.\n * @template S - The schema type for linkable validation, defaults to LinkableSchema.\n * @param name - A unique string identifier for the local storage key.\n * @param init - The initial value to be stored in local storage.\n * @param options - Optional configuration for state behavior and validation schema.\n * @returns A reactive state that provides reactive access and modification capabilities.\n */\nexport function persistentRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(\n name: string,\n init: T,\n options?: StateOptions<S>\n): T {\n const state = persistent(name, init, options);\n\n onDestroy(() => {\n persistent.leave(state);\n });\n\n return state;\n}"]}
@@ -0,0 +1,18 @@
1
+ import { ObjLike, LinkableSchema, StateOptions } from '@anchorlib/core';
2
+
3
+ /**
4
+ * @deprecated Use `session()` instead.
5
+ * Creates a session-scoped reactive state using the provided name, initial value, and options.
6
+ * The sessionRef is tied to the browser's session storage, meaning its value will persist
7
+ * across page reloads but not after the session ends (e.g., tab/window closed).
8
+ *
9
+ * @template T - The type of the initial value, must extend object-like structure.
10
+ * @template S - The schema type for linkable validation, defaults to LinkableSchema.
11
+ * @param name - A unique string identifier for the session storage key.
12
+ * @param init - The initial value to be stored in session storage.
13
+ * @param options - Optional configuration for state behavior and validation schema.
14
+ * @returns A reactive state that provides reactive access and modification capabilities.
15
+ */
16
+ declare function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
17
+
18
+ export { sessionRef };
@@ -0,0 +1,14 @@
1
+ import { session } from '@anchorlib/storage';
2
+ import { onDestroy } from 'svelte';
3
+
4
+ function sessionRef(name, init, options) {
5
+ const state = session(name, init, options);
6
+ onDestroy(() => {
7
+ session.leave(state);
8
+ });
9
+ return state;
10
+ }
11
+
12
+ export { sessionRef };
13
+ //# sourceMappingURL=session.js.map
14
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/storage/session.ts"],"names":[],"mappings":";;;AAiBO,SAAS,UAAA,CACd,IAAA,EACA,IAAA,EACA,OAAA,EACG;AACH,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,IAAA,EAAM,IAAA,EAAM,OAAO,CAAA;AAEzC,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA,EACrB,CAAC,CAAA;AAED,EAAA,OAAO,KAAA;AACT","file":"session.js","sourcesContent":["import type { LinkableSchema, ObjLike, StateOptions } from '@anchorlib/core';\nimport { session } from '@anchorlib/storage';\nimport { onDestroy } from 'svelte';\n\n/**\n * @deprecated Use `session()` instead.\n * Creates a session-scoped reactive state using the provided name, initial value, and options.\n * The sessionRef is tied to the browser's session storage, meaning its value will persist\n * across page reloads but not after the session ends (e.g., tab/window closed).\n *\n * @template T - The type of the initial value, must extend object-like structure.\n * @template S - The schema type for linkable validation, defaults to LinkableSchema.\n * @param name - A unique string identifier for the session storage key.\n * @param init - The initial value to be stored in session storage.\n * @param options - Optional configuration for state behavior and validation schema.\n * @returns A reactive state that provides reactive access and modification capabilities.\n */\nexport function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(\n name: string,\n init: T,\n options?: StateOptions<S>\n): T {\n const state = session(name, init, options);\n\n onDestroy(() => {\n session.leave(state);\n });\n\n return state;\n}"]}
@@ -0,0 +1,13 @@
1
+ import { ReactiveTable, Rec, InferRec, Row } from '@anchorlib/storage/db';
2
+ import { TableRef } from './types.js';
3
+
4
+ /**
5
+ * @deprecated Use `createTable()` instead.
6
+ */
7
+ declare function createTableRef<T extends ReactiveTable<Rec>>(table: T): TableRef<InferRec<T>>;
8
+ /**
9
+ * @deprecated Use `createTable()` instead.
10
+ */
11
+ declare function createTableRef<T extends Rec, R extends Row<T> = Row<T>>(name: string, version?: number, indexes?: (keyof R)[], remIndexes?: (keyof R)[], dbName?: string): TableRef<T, R>;
12
+
13
+ export { createTableRef };
@@ -0,0 +1,45 @@
1
+ import { createTable } from '@anchorlib/storage/db';
2
+ import { onDestroy } from 'svelte';
3
+
4
+ function createTableRef(tableName, version = 1, indexes, remIndexes, dbName = tableName) {
5
+ if (typeof tableName === "string") {
6
+ tableName = createTable(tableName, version, indexes, remIndexes, dbName);
7
+ }
8
+ const tableRef = tableName;
9
+ return {
10
+ get(id) {
11
+ const state = tableRef.get(id);
12
+ onDestroy(() => {
13
+ tableRef.leave(id);
14
+ });
15
+ return state;
16
+ },
17
+ add(payload) {
18
+ const state = tableRef.add(payload);
19
+ onDestroy(() => {
20
+ tableRef.leave(state.data.id);
21
+ });
22
+ return state;
23
+ },
24
+ list(filter, limit, direction) {
25
+ return tableRef.list(filter, limit, direction);
26
+ },
27
+ listByIndex(name, filter, limit, direction) {
28
+ return tableRef.listByIndex(name, filter, limit, direction);
29
+ },
30
+ remove(id) {
31
+ return tableRef.remove(id);
32
+ },
33
+ seed(seeds) {
34
+ tableRef.seed(seeds);
35
+ return this;
36
+ },
37
+ table() {
38
+ return tableRef;
39
+ }
40
+ };
41
+ }
42
+
43
+ export { createTableRef };
44
+ //# sourceMappingURL=table.js.map
45
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/storage/table.ts"],"names":[],"mappings":";;;AA4BO,SAAS,eACd,SAAA,EACA,OAAA,GAAU,GACV,OAAA,EACA,UAAA,EACA,SAAS,SAAA,EACO;AAChB,EAAA,IAAI,OAAO,cAAc,QAAA,EAAU;AACjC,IAAA,SAAA,GAAY,WAAA,CAAkB,SAAA,EAAW,OAAA,EAAS,OAAA,EAAS,YAAY,MAAM,CAAA;AAAA,EAC/E;AAEA,EAAA,MAAM,QAAA,GAAW,SAAA;AAEjB,EAAA,OAAO;AAAA,IACL,IAAI,EAAA,EAAY;AACd,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,GAAA,CAAI,EAAE,CAAA;AAE7B,MAAA,SAAA,CAAU,MAAM;AACd,QAAA,QAAA,CAAS,MAAM,EAAE,CAAA;AAAA,MACnB,CAAC,CAAA;AAED,MAAA,OAAO,KAAA;AAAA,IACT,CAAA;AAAA,IACA,IAAI,OAAA,EAAY;AACd,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,GAAA,CAAI,OAAO,CAAA;AAElC,MAAA,SAAA,CAAU,MAAM;AACd,QAAA,QAAA,CAAS,KAAA,CAAM,KAAA,CAAM,IAAA,CAAK,EAAE,CAAA;AAAA,MAC9B,CAAC,CAAA;AAED,MAAA,OAAO,KAAA;AAAA,IACT,CAAA;AAAA,IACA,IAAA,CAAK,MAAA,EAAoC,KAAA,EAAgB,SAAA,EAAgC;AACvF,MAAA,OAAO,QAAA,CAAS,IAAA,CAAK,MAAA,EAAQ,KAAA,EAAO,SAAS,CAAA;AAAA,IAC/C,CAAA;AAAA,IACA,WAAA,CAAY,IAAA,EAAe,MAAA,EAAoC,KAAA,EAAgB,SAAA,EAAgC;AAC7G,MAAA,OAAO,QAAA,CAAS,WAAA,CAAY,IAAA,EAAM,MAAA,EAAQ,OAAO,SAAS,CAAA;AAAA,IAC5D,CAAA;AAAA,IACA,OAAO,EAAA,EAAY;AACjB,MAAA,OAAO,QAAA,CAAS,OAAO,EAAE,CAAA;AAAA,IAC3B,CAAA;AAAA,IACA,KAAK,KAAA,EAAY;AACf,MAAA,QAAA,CAAS,KAAK,KAAK,CAAA;AACnB,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,KAAA,GAAQ;AACN,MAAA,OAAO,QAAA;AAAA,IACT;AAAA,GACF;AACF","file":"table.js","sourcesContent":["import {\n createTable,\n type FilterFn,\n type InferRec,\n type ReactiveTable,\n type Rec,\n type Row,\n} from '@anchorlib/storage/db';\nimport { onDestroy } from 'svelte';\nimport type { TableRef } from './types.js';\n\n/**\n * @deprecated Use `createTable()` instead.\n */\nexport function createTableRef<T extends ReactiveTable<Rec>>(table: T): TableRef<InferRec<T>>;\n/**\n * @deprecated Use `createTable()` instead.\n */\nexport function createTableRef<T extends Rec, R extends Row<T> = Row<T>>(\n name: string,\n version?: number,\n indexes?: (keyof R)[],\n remIndexes?: (keyof R)[],\n dbName?: string\n): TableRef<T, R>;\n/**\n * @deprecated Use `createTable()` instead.\n */\nexport function createTableRef<T extends Rec, R extends Row<T> = Row<T>>(\n tableName: string | ReactiveTable<T>,\n version = 1,\n indexes?: (keyof R)[],\n remIndexes?: (keyof R)[],\n dbName = tableName as string\n): TableRef<T, R> {\n if (typeof tableName === 'string') {\n tableName = createTable<T, R>(tableName, version, indexes, remIndexes, dbName);\n }\n\n const tableRef = tableName as ReactiveTable<T, R>;\n\n return {\n get(id: string) {\n const state = tableRef.get(id);\n\n onDestroy(() => {\n tableRef.leave(id);\n });\n\n return state;\n },\n add(payload: T) {\n const state = tableRef.add(payload);\n\n onDestroy(() => {\n tableRef.leave(state.data.id);\n });\n\n return state;\n },\n list(filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection) {\n return tableRef.list(filter, limit, direction);\n },\n listByIndex(name: keyof R, filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection) {\n return tableRef.listByIndex(name, filter, limit, direction);\n },\n remove(id: string) {\n return tableRef.remove(id);\n },\n seed(seeds: R[]) {\n tableRef.seed(seeds);\n return this;\n },\n table() {\n return tableRef;\n },\n };\n}"]}
@@ -0,0 +1,15 @@
1
+ import { Rec, Row, RowState, FilterFn, RowListState, ReactiveTable } from '@anchorlib/storage/db';
2
+
3
+ interface TableRef<T extends Rec, R extends Row<T> = Row<T>> {
4
+ get(id: string): RowState<R>;
5
+ add(payload: T): RowState<R>;
6
+ remove(id: string): RowState<R>;
7
+ list(filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection): RowListState<R>;
8
+ listByIndex(name: keyof R, filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection): RowListState<R>;
9
+ seed<T extends R[]>(seeds: T): this;
10
+ table(): ReactiveTable<T>;
11
+ }
12
+ type InferRef<T> = T extends TableRef<Rec, infer R> ? R : never;
13
+ type InferListRef<T> = T extends TableRef<Rec, infer R> ? R[] : never;
14
+
15
+ export type { InferListRef, InferRef, TableRef };
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=types.js.map
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
@@ -0,0 +1,11 @@
1
+ type StateRef<T> = {
2
+ value: T;
3
+ };
4
+ type ConstantRef<T> = {
5
+ get value(): T;
6
+ };
7
+ type VariableRef<T> = ConstantRef<T> & {
8
+ set value(value: T);
9
+ };
10
+
11
+ export type { ConstantRef, StateRef, VariableRef };
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=types.js.map
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}