@anchorlib/svelte 1.0.0-beta.17 → 1.0.0-beta.19

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 (58) hide show
  1. package/dist/anchor.d.ts +6 -4
  2. package/dist/anchor.js +57 -8
  3. package/dist/core/index.d.ts +1 -1
  4. package/dist/core/index.js +1 -3
  5. package/dist/derive.d.ts +5 -3
  6. package/dist/derive.js +30 -22
  7. package/dist/fetch.d.ts +11 -9
  8. package/dist/fetch.js +6 -6
  9. package/dist/history.d.ts +5 -3
  10. package/dist/history.js +12 -5
  11. package/dist/immutable.d.ts +5 -3
  12. package/dist/immutable.js +8 -6
  13. package/dist/index.d.ts +12 -11
  14. package/dist/index.js +13 -14
  15. package/dist/model.d.ts +6 -4
  16. package/dist/model.js +14 -6
  17. package/dist/observable.d.ts +5 -3
  18. package/dist/observable.js +32 -24
  19. package/dist/prop.d.ts +7 -8
  20. package/dist/prop.js +15 -5
  21. package/dist/reactive.d.ts +4 -3
  22. package/dist/reactive.js +45 -40
  23. package/dist/ref.d.ts +4 -3
  24. package/dist/ref.js +58 -26
  25. package/dist/storage/index.d.ts +7 -8
  26. package/dist/storage/index.js +9 -9
  27. package/dist/storage/kv.d.ts +5 -3
  28. package/dist/storage/kv.js +22 -10
  29. package/dist/storage/persistent.d.ts +5 -3
  30. package/dist/storage/persistent.js +23 -10
  31. package/dist/storage/session.d.ts +5 -3
  32. package/dist/storage/session.js +23 -10
  33. package/dist/storage/table.d.ts +6 -4
  34. package/dist/storage/table.js +42 -41
  35. package/dist/storage/types.d.ts +12 -11
  36. package/dist/storage/types.js +0 -3
  37. package/dist/types.d.ts +6 -5
  38. package/dist/types.js +0 -3
  39. package/package.json +7 -7
  40. package/dist/anchor.js.map +0 -1
  41. package/dist/core/index.js.map +0 -1
  42. package/dist/derive.js.map +0 -1
  43. package/dist/fetch.js.map +0 -1
  44. package/dist/history.js.map +0 -1
  45. package/dist/immutable.js.map +0 -1
  46. package/dist/index.js.map +0 -1
  47. package/dist/model.js.map +0 -1
  48. package/dist/observable.js.map +0 -1
  49. package/dist/prop.js.map +0 -1
  50. package/dist/reactive.js.map +0 -1
  51. package/dist/ref.js.map +0 -1
  52. package/dist/storage/index.js.map +0 -1
  53. package/dist/storage/kv.js.map +0 -1
  54. package/dist/storage/persistent.js.map +0 -1
  55. package/dist/storage/session.js.map +0 -1
  56. package/dist/storage/table.js.map +0 -1
  57. package/dist/storage/types.js.map +0 -1
  58. package/dist/types.js.map +0 -1
package/dist/reactive.js CHANGED
@@ -1,46 +1,51 @@
1
- import { setTracker, createObserver, setCleanUpHandler, onGlobalCleanup } from '@anchorlib/core';
2
- import { onDestroy } from 'svelte';
3
- import { createSubscriber } from 'svelte/reactivity';
1
+ import { createObserver, onGlobalCleanup, setCleanUpHandler, setTracker } from "@anchorlib/core";
2
+ import { onDestroy } from "svelte";
3
+ import { createSubscriber } from "svelte/reactivity";
4
4
 
5
+ //#region src/reactive.ts
5
6
  const TRACKER_REGISTRY = /* @__PURE__ */ new WeakMap();
6
7
  let bindingInitialized = false;
7
8
  if (!bindingInitialized && typeof window !== "undefined") {
8
- bindingInitialized = true;
9
- setTracker((init, observers, key) => {
10
- if (!TRACKER_REGISTRY.has(init)) {
11
- let track;
12
- const subscribe = createSubscriber((update) => {
13
- const observer = createObserver(
14
- () => {
15
- observer.reset();
16
- update();
17
- },
18
- void 0,
19
- true
20
- );
21
- track = observer.assign(init, observers);
22
- return () => {
23
- observer.destroy();
24
- TRACKER_REGISTRY.delete(init);
25
- };
26
- });
27
- const assign = (prop) => {
28
- subscribe();
29
- track?.(prop);
30
- };
31
- TRACKER_REGISTRY.set(init, assign);
32
- }
33
- TRACKER_REGISTRY.get(init)?.(key);
34
- });
35
- setCleanUpHandler((handler) => {
36
- try {
37
- return onDestroy(handler);
38
- } catch (_error) {
39
- return onGlobalCleanup(handler);
40
- }
41
- });
9
+ bindingInitialized = true;
10
+ /**
11
+ * Sets up a tracker function that integrates Anchor's reactivity system with Svelte's reactivity.
12
+ * This tracker is responsible for creating observers that watch for changes in reactive objects
13
+ * and properly subscribing/unsubscribing to Svelte's reactivity system.
14
+ *
15
+ * @param init - The initial linkable object to track
16
+ * @param observers - The observers collection to use for tracking
17
+ * @param key - The specific key/property to track on the object
18
+ */
19
+ setTracker((init, observers, key) => {
20
+ if (!TRACKER_REGISTRY.has(init)) {
21
+ let track;
22
+ const subscribe$1 = createSubscriber((update) => {
23
+ const observer = createObserver(() => {
24
+ observer.reset();
25
+ update();
26
+ }, void 0, true);
27
+ track = observer.assign(init, observers);
28
+ return () => {
29
+ observer.destroy();
30
+ TRACKER_REGISTRY.delete(init);
31
+ };
32
+ });
33
+ const assign = (prop) => {
34
+ subscribe$1();
35
+ track?.(prop);
36
+ };
37
+ TRACKER_REGISTRY.set(init, assign);
38
+ }
39
+ TRACKER_REGISTRY.get(init)?.(key);
40
+ });
41
+ setCleanUpHandler((handler) => {
42
+ try {
43
+ return onDestroy(handler);
44
+ } catch (_error) {
45
+ return onGlobalCleanup(handler);
46
+ }
47
+ });
42
48
  }
43
49
 
44
- export { TRACKER_REGISTRY };
45
- //# sourceMappingURL=reactive.js.map
46
- //# sourceMappingURL=reactive.js.map
50
+ //#endregion
51
+ export { TRACKER_REGISTRY };
package/dist/ref.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { ConstantRef, StateRef, VariableRef } from './types.js';
1
+ import { ConstantRef, StateRef, VariableRef } from "./types.js";
2
2
 
3
+ //#region src/ref.d.ts
3
4
  declare const REF_REGISTRY: WeakMap<ConstantRef<unknown>, StateRef<unknown>>;
4
5
  /**
5
6
  * @deprecated Use 'mutable()' instead.
@@ -47,5 +48,5 @@ declare function constantRef<T>(init: T): ConstantRef<T>;
47
48
  * @returns True if the value is a writable reference, false otherwise
48
49
  */
49
50
  declare function isRef<T>(ref: unknown): ref is VariableRef<T>;
50
-
51
- export { REF_REGISTRY, constantRef, isRef, variableRef };
51
+ //#endregion
52
+ export { REF_REGISTRY, constantRef, isRef, variableRef };
package/dist/ref.js CHANGED
@@ -1,35 +1,67 @@
1
- import { anchor } from '@anchorlib/core';
2
- import { onDestroy } from 'svelte';
1
+ import { anchor } from "@anchorlib/core";
2
+ import { onDestroy } from "svelte";
3
3
 
4
+ //#region src/ref.ts
4
5
  const REF_REGISTRY = /* @__PURE__ */ new WeakMap();
6
+ /**
7
+ * @deprecated Use 'mutable()' instead.
8
+ * Creates a readable reference that can be subscribed to for reactive updates.
9
+ * This function initializes a reactive reference with a given initial value and provides
10
+ * mechanisms for subscribing to changes and publishing updates to subscribers.
11
+ *
12
+ * @template T The type of the value being referenced
13
+ * @param init - The initial value for the reference
14
+ * @param constant - If true, the reference will be read-only and cannot be updated.
15
+ * @returns A readable reference object with subscribe and publish capabilities
16
+ */
5
17
  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;
18
+ const valueRef = anchor({ value: init }, { recursive: true });
19
+ const set = (value) => {
20
+ if (constant === true || value === valueRef.value) return;
21
+ valueRef.value = value;
22
+ };
23
+ onDestroy(() => {
24
+ REF_REGISTRY.delete(stateRef);
25
+ anchor.destroy(valueRef);
26
+ });
27
+ const stateRef = {
28
+ get value() {
29
+ return valueRef.value;
30
+ },
31
+ set value(value) {
32
+ set(value);
33
+ }
34
+ };
35
+ REF_REGISTRY.set(stateRef, valueRef);
36
+ return stateRef;
25
37
  }
38
+ /**
39
+ * @deprecated Use 'immutable()' instead.
40
+ * Creates a constant (read-only) reference that can be subscribed to for reactive updates.
41
+ * This function initializes a reactive reference with a given initial value that cannot be modified
42
+ * after creation. It's useful for values that should remain constant throughout the component lifecycle
43
+ * but still need to be reactively tracked.
44
+ *
45
+ * @template T The type of the value being referenced
46
+ * @param init - The initial value for the constant reference
47
+ * @returns A constant reference object with subscribe capability but no write access
48
+ */
26
49
  function constantRef(init) {
27
- return variableRef(init, true);
50
+ return variableRef(init, true);
28
51
  }
52
+ /**
53
+ * @deprecated Use 'isValueRef()' instead.
54
+ * Checks if a given value is a writable reference.
55
+ * This function uses the REF_REGISTRY to determine if the provided value
56
+ * is a registered writable reference.
57
+ *
58
+ * @template T The type of the value that the reference holds
59
+ * @param ref - The value to check
60
+ * @returns True if the value is a writable reference, false otherwise
61
+ */
29
62
  function isRef(ref) {
30
- return REF_REGISTRY.has(ref);
63
+ return REF_REGISTRY.has(ref);
31
64
  }
32
65
 
33
- export { REF_REGISTRY, constantRef, isRef, variableRef };
34
- //# sourceMappingURL=ref.js.map
35
- //# sourceMappingURL=ref.js.map
66
+ //#endregion
67
+ export { REF_REGISTRY, constantRef, isRef, variableRef };
@@ -1,8 +1,7 @@
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
+ import { kvRef } from "./kv.js";
2
+ import { persistentRef } from "./persistent.js";
3
+ import { sessionRef } from "./session.js";
4
+ import { InferListRef, InferRef, TableRef } from "./types.js";
5
+ import { createTableRef } from "./table.js";
6
+ export * from "@anchorlib/storage";
7
+ export { InferListRef, InferRef, TableRef, createTableRef, kvRef, persistentRef, sessionRef };
@@ -1,9 +1,9 @@
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';
8
- //# sourceMappingURL=index.js.map
9
- //# sourceMappingURL=index.js.map
1
+ import "../reactive.js";
2
+ import { kvRef } from "./kv.js";
3
+ import { persistentRef } from "./persistent.js";
4
+ import { sessionRef } from "./session.js";
5
+ import { createTableRef } from "./table.js";
6
+
7
+ export * from "@anchorlib/storage"
8
+
9
+ export { createTableRef, kvRef, persistentRef, sessionRef };
@@ -1,4 +1,6 @@
1
- import { Storable, KVState } from '@anchorlib/storage/db';
1
+ import { KVState, Storable } from "@anchorlib/storage/db";
2
+
3
+ //#region src/storage/kv.d.ts
2
4
 
3
5
  /**
4
6
  * @deprecated Use `kv()` instead.
@@ -13,5 +15,5 @@ import { Storable, KVState } from '@anchorlib/storage/db';
13
15
  * @returns A reactive key-value store state.
14
16
  */
15
17
  declare function kvRef<T extends Storable>(name: string, init: T): KVState<T>;
16
-
17
- export { kvRef };
18
+ //#endregion
19
+ export { kvRef };
@@ -1,14 +1,26 @@
1
- import { kv } from '@anchorlib/storage/db';
2
- import { onDestroy } from 'svelte';
1
+ import { onDestroy } from "svelte";
2
+ import { kv } from "@anchorlib/storage/db";
3
3
 
4
+ //#region src/storage/kv.ts
5
+ /**
6
+ * @deprecated Use `kv()` instead.
7
+ * Creates a reactive key-value store state.
8
+ *
9
+ * This function initializes a key-value store with the given name and initial value,
10
+ * and automatically cleans up the store subscription when the component is destroyed.
11
+ *
12
+ * @template T - The type of the stored value, must extend Storable
13
+ * @param name - The unique identifier for the key-value store
14
+ * @param init - The initial value for the store
15
+ * @returns A reactive key-value store state.
16
+ */
4
17
  function kvRef(name, init) {
5
- const state = kv(name, init);
6
- onDestroy(() => {
7
- kv.leave(state);
8
- });
9
- return state;
18
+ const state = kv(name, init);
19
+ onDestroy(() => {
20
+ kv.leave(state);
21
+ });
22
+ return state;
10
23
  }
11
24
 
12
- export { kvRef };
13
- //# sourceMappingURL=kv.js.map
14
- //# sourceMappingURL=kv.js.map
25
+ //#endregion
26
+ export { kvRef };
@@ -1,4 +1,6 @@
1
- import { ObjLike, LinkableSchema, StateOptions } from '@anchorlib/core';
1
+ import { LinkableSchema, ObjLike, StateOptions } from "@anchorlib/core";
2
+
3
+ //#region src/storage/persistent.d.ts
2
4
 
3
5
  /**
4
6
  * @deprecated Use `persistent()` instead.
@@ -14,5 +16,5 @@ import { ObjLike, LinkableSchema, StateOptions } from '@anchorlib/core';
14
16
  * @returns A reactive state that provides reactive access and modification capabilities.
15
17
  */
16
18
  declare function persistentRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
17
-
18
- export { persistentRef };
19
+ //#endregion
20
+ export { persistentRef };
@@ -1,14 +1,27 @@
1
- import { persistent } from '@anchorlib/storage';
2
- import { onDestroy } from 'svelte';
1
+ import { onDestroy } from "svelte";
2
+ import { persistent } from "@anchorlib/storage";
3
3
 
4
+ //#region src/storage/persistent.ts
5
+ /**
6
+ * @deprecated Use `persistent()` instead.
7
+ * Creates a persistent reactive state using the provided name, initial value, and options.
8
+ * The persistentRef is tied to the browser's local storage, meaning its value will persist
9
+ * across page reloads and browser sessions until explicitly cleared.
10
+ *
11
+ * @template T - The type of the initial value, must extend object-like structure.
12
+ * @template S - The schema type for linkable validation, defaults to LinkableSchema.
13
+ * @param name - A unique string identifier for the local storage key.
14
+ * @param init - The initial value to be stored in local storage.
15
+ * @param options - Optional configuration for state behavior and validation schema.
16
+ * @returns A reactive state that provides reactive access and modification capabilities.
17
+ */
4
18
  function persistentRef(name, init, options) {
5
- const state = persistent(name, init, options);
6
- onDestroy(() => {
7
- persistent.leave(state);
8
- });
9
- return state;
19
+ const state = persistent(name, init, options);
20
+ onDestroy(() => {
21
+ persistent.leave(state);
22
+ });
23
+ return state;
10
24
  }
11
25
 
12
- export { persistentRef };
13
- //# sourceMappingURL=persistent.js.map
14
- //# sourceMappingURL=persistent.js.map
26
+ //#endregion
27
+ export { persistentRef };
@@ -1,4 +1,6 @@
1
- import { ObjLike, LinkableSchema, StateOptions } from '@anchorlib/core';
1
+ import { LinkableSchema, ObjLike, StateOptions } from "@anchorlib/core";
2
+
3
+ //#region src/storage/session.d.ts
2
4
 
3
5
  /**
4
6
  * @deprecated Use `session()` instead.
@@ -14,5 +16,5 @@ import { ObjLike, LinkableSchema, StateOptions } from '@anchorlib/core';
14
16
  * @returns A reactive state that provides reactive access and modification capabilities.
15
17
  */
16
18
  declare function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
17
-
18
- export { sessionRef };
19
+ //#endregion
20
+ export { sessionRef };
@@ -1,14 +1,27 @@
1
- import { session } from '@anchorlib/storage';
2
- import { onDestroy } from 'svelte';
1
+ import { onDestroy } from "svelte";
2
+ import { session } from "@anchorlib/storage";
3
3
 
4
+ //#region src/storage/session.ts
5
+ /**
6
+ * @deprecated Use `session()` instead.
7
+ * Creates a session-scoped reactive state using the provided name, initial value, and options.
8
+ * The sessionRef is tied to the browser's session storage, meaning its value will persist
9
+ * across page reloads but not after the session ends (e.g., tab/window closed).
10
+ *
11
+ * @template T - The type of the initial value, must extend object-like structure.
12
+ * @template S - The schema type for linkable validation, defaults to LinkableSchema.
13
+ * @param name - A unique string identifier for the session storage key.
14
+ * @param init - The initial value to be stored in session storage.
15
+ * @param options - Optional configuration for state behavior and validation schema.
16
+ * @returns A reactive state that provides reactive access and modification capabilities.
17
+ */
4
18
  function sessionRef(name, init, options) {
5
- const state = session(name, init, options);
6
- onDestroy(() => {
7
- session.leave(state);
8
- });
9
- return state;
19
+ const state = session(name, init, options);
20
+ onDestroy(() => {
21
+ session.leave(state);
22
+ });
23
+ return state;
10
24
  }
11
25
 
12
- export { sessionRef };
13
- //# sourceMappingURL=session.js.map
14
- //# sourceMappingURL=session.js.map
26
+ //#endregion
27
+ export { sessionRef };
@@ -1,5 +1,7 @@
1
- import { ReactiveTable, Rec, InferRec, Row } from '@anchorlib/storage/db';
2
- import { TableRef } from './types.js';
1
+ import { TableRef } from "./types.js";
2
+ import { InferRec, ReactiveTable, Rec, Row } from "@anchorlib/storage/db";
3
+
4
+ //#region src/storage/table.d.ts
3
5
 
4
6
  /**
5
7
  * @deprecated Use `createTable()` instead.
@@ -9,5 +11,5 @@ declare function createTableRef<T extends ReactiveTable<Rec>>(table: T): TableRe
9
11
  * @deprecated Use `createTable()` instead.
10
12
  */
11
13
  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 };
14
+ //#endregion
15
+ export { createTableRef };
@@ -1,45 +1,46 @@
1
- import { createTable } from '@anchorlib/storage/db';
2
- import { onDestroy } from 'svelte';
1
+ import { onDestroy } from "svelte";
2
+ import { createTable } from "@anchorlib/storage/db";
3
3
 
4
+ //#region src/storage/table.ts
5
+ /**
6
+ * @deprecated Use `createTable()` instead.
7
+ */
4
8
  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
- };
9
+ if (typeof tableName === "string") tableName = createTable(tableName, version, indexes, remIndexes, dbName);
10
+ const tableRef = tableName;
11
+ return {
12
+ get(id) {
13
+ const state = tableRef.get(id);
14
+ onDestroy(() => {
15
+ tableRef.leave(id);
16
+ });
17
+ return state;
18
+ },
19
+ add(payload) {
20
+ const state = tableRef.add(payload);
21
+ onDestroy(() => {
22
+ tableRef.leave(state.data.id);
23
+ });
24
+ return state;
25
+ },
26
+ list(filter, limit, direction) {
27
+ return tableRef.list(filter, limit, direction);
28
+ },
29
+ listByIndex(name, filter, limit, direction) {
30
+ return tableRef.listByIndex(name, filter, limit, direction);
31
+ },
32
+ remove(id) {
33
+ return tableRef.remove(id);
34
+ },
35
+ seed(seeds) {
36
+ tableRef.seed(seeds);
37
+ return this;
38
+ },
39
+ table() {
40
+ return tableRef;
41
+ }
42
+ };
41
43
  }
42
44
 
43
- export { createTableRef };
44
- //# sourceMappingURL=table.js.map
45
- //# sourceMappingURL=table.js.map
45
+ //#endregion
46
+ export { createTableRef };
@@ -1,15 +1,16 @@
1
- import { Rec, Row, RowState, FilterFn, RowListState, ReactiveTable } from '@anchorlib/storage/db';
1
+ import { FilterFn, ReactiveTable, Rec, Row, RowListState, RowState } from "@anchorlib/storage/db";
2
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>;
3
+ //#region src/storage/types.d.ts
4
+ interface TableRef<T extends Rec, R$1 extends Row<T> = Row<T>> {
5
+ get(id: string): RowState<R$1>;
6
+ add(payload: T): RowState<R$1>;
7
+ remove(id: string): RowState<R$1>;
8
+ list(filter?: IDBKeyRange | FilterFn<R$1>, limit?: number, direction?: IDBCursorDirection): RowListState<R$1>;
9
+ listByIndex(name: keyof R$1, filter?: IDBKeyRange | FilterFn<R$1>, limit?: number, direction?: IDBCursorDirection): RowListState<R$1>;
10
+ seed<T extends R$1[]>(seeds: T): this;
11
+ table(): ReactiveTable<T>;
11
12
  }
12
13
  type InferRef<T> = T extends TableRef<Rec, infer R> ? R : never;
13
14
  type InferListRef<T> = T extends TableRef<Rec, infer R> ? R[] : never;
14
-
15
- export type { InferListRef, InferRef, TableRef };
15
+ //#endregion
16
+ export { InferListRef, InferRef, TableRef };
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
3
- //# sourceMappingURL=types.js.map
package/dist/types.d.ts CHANGED
@@ -1,11 +1,12 @@
1
+ //#region src/types.d.ts
1
2
  type StateRef<T> = {
2
- value: T;
3
+ value: T;
3
4
  };
4
5
  type ConstantRef<T> = {
5
- get value(): T;
6
+ get value(): T;
6
7
  };
7
8
  type VariableRef<T> = ConstantRef<T> & {
8
- set value(value: T);
9
+ set value(value: T);
9
10
  };
10
-
11
- export type { ConstantRef, StateRef, VariableRef };
11
+ //#endregion
12
+ export { ConstantRef, StateRef, VariableRef };
package/dist/types.js CHANGED
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
3
- //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anchorlib/svelte",
3
- "version": "1.0.0-beta.17",
3
+ "version": "1.0.0-beta.19",
4
4
  "description": "Svelte bindings for Anchor reactive state management",
5
5
  "keywords": [
6
6
  "state",
@@ -55,8 +55,8 @@
55
55
  "access": "public"
56
56
  },
57
57
  "dependencies": {
58
- "@anchorlib/core": "^1.0.0-beta.17",
59
- "@anchorlib/storage": "^1.0.0-beta.17"
58
+ "@anchorlib/core": "^1.0.0-beta.19",
59
+ "@anchorlib/storage": "^1.0.0-beta.19"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@biomejs/biome": "2.3.3",
@@ -69,7 +69,7 @@
69
69
  "jsdom": "27.0.1",
70
70
  "publint": "0.3.15",
71
71
  "rimraf": "6.0.1",
72
- "tsup": "8.5.0",
72
+ "tsdown": "0.15.9",
73
73
  "vite": "7.1.12",
74
74
  "vitest": "^3.2.4"
75
75
  },
@@ -78,10 +78,10 @@
78
78
  "typescript": "^5.9.3"
79
79
  },
80
80
  "scripts": {
81
- "dev": "rimraf dist && tsup --watch",
81
+ "dev": "rimraf dist && tsdown --watch",
82
82
  "clean": "rimraf dist",
83
- "build": "rimraf dist && tsup && publint",
84
- "prepublish": "rimraf dist && tsup && publint",
83
+ "build": "rimraf dist && tsdown && publint",
84
+ "prepublish": "rimraf dist && tsdown && publint",
85
85
  "format": "biome format --write",
86
86
  "test": "rimraf coverage && vitest --run",
87
87
  "test:preview": "rimraf coverage && vitest --run && vite preview --outDir coverage"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/anchor.ts"],"names":[],"mappings":";;AAwEO,SAAS,SAAA,CACd,IAAA,EACA,aAAA,EACA,OAAA,EACgD;AAChD,EAAA,OAAO,MAAA,CAAyB,IAAA,EAAuB,aAAA,EAAoB,OAAO,CAAA;AACpF;AAOO,MAAM,WAAA,GAAc;AAapB,SAAS,UAAA,CACd,IAAA,EACA,OAAA,EACA,OAAA,EACG;AACH,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,IAAA,EAAM,OAAA,EAAS,OAAO,CAAA;AAC9C;AAYO,SAAS,OAAA,CAAgE,MAAS,OAAA,EAA8B;AACrH,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,IAAA,EAAM,OAAO,CAAA;AAClC;AAcO,SAAS,MAAA,CACd,MACA,OAAA,EACG;AACH,EAAA,OAAO,MAAA,CAAO,GAAA,CAAI,IAAA,EAAM,OAAO,CAAA;AACjC","file":"anchor.js","sourcesContent":["import {\n anchor,\n type Immutable,\n type Linkable,\n type LinkableSchema,\n type ModelArray,\n type ModelInput,\n type ModelOutput,\n type StateOptions,\n} from '@anchorlib/core';\n\n/**\n * @deprecated Use 'mutable()' instead.\n * Creates a reactive state that can be used to manage state with Anchor.\n * This overload is used when no schema is provided, or when using a LinkableSchema with StateOptions.\n *\n * @template T - The type of the initial value\n * @template S - The schema type, extending LinkableSchema\n * @param init - The initial value for the state\n * @param options - Optional state options for the state\n * @returns A reactive state containing the initial value\n */\nexport function anchorRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(\n init: T,\n options?: StateOptions<S>\n): T;\n\n/**\n * @deprecated Use 'mutable()' instead.\n * Creates a reactive state with a defined schema for validation and type inference.\n *\n * @template S - The schema type, extending LinkableSchema\n * @template T - The type of the initial value, must extend ModelInput of the schema\n * @param init - The initial value for the state\n * @param schema - The schema to validate and type the state\n * @param options - Optional state options for the state\n * @returns A reactive state containing the output model based on the schema\n */\nexport function anchorRef<S extends LinkableSchema, T extends ModelInput<S>>(\n init: T,\n schema?: S,\n options?: StateOptions\n): ModelOutput<S>;\n\n/**\n * @deprecated Use 'mutable()' instead.\n * Creates an immutable reactive state with a defined schema.\n *\n * @template S - The schema type, extending LinkableSchema\n * @template T - The type of the initial value, must extend ModelInput of the schema\n * @param init - The initial value for the state\n * @param schema - The schema to validate and type the state\n * @param options - State options with immutable flag set to true\n * @returns A reactive state containing an immutable output model based on the schema\n */\nexport function anchorRef<S extends LinkableSchema, T extends ModelInput<S>>(\n init: T,\n schema?: S,\n options?: StateOptions & { immutable: true }\n): Immutable<ModelOutput<S>>;\n\n/**\n * @deprecated Use 'mutable()' instead.\n * Creates a reactive state for state management with optional schema validation.\n *\n * @template T - The type of the initial value\n * @template S - The schema type or options\n * @param init - The initial value for the state\n * @param schemaOptions - Either a schema or state options\n * @param options - Additional state options when schema is provided\n * @returns A reactive state containing the managed state\n */\nexport function anchorRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(\n init: T,\n schemaOptions?: S | StateOptions,\n options?: StateOptions\n): T | ModelOutput<S> | Immutable<ModelOutput<S>> {\n return anchor<S, ModelInput<S>>(init as ModelInput<S>, schemaOptions as S, options);\n}\n\n/**\n * @deprecated Use 'mutable()' instead.\n * Reactive state alias for anchorRef.\n * @type {{<T, S=LinkableSchema extends LinkableSchema>(init: T, options?: StateOptions<S>): T, <S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions): ModelOutput<S>, <S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: (StateOptions & {immutable: true})): Immutable<ModelOutput<S>>}}\n */\nexport const reactiveRef = anchorRef;\n\n/**\n * @deprecated Use 'ordered()' instead.\n * Creates a reactive state that maintains a sorted array state based on a comparison function.\n *\n * @template T - The type of elements in the array\n * @template S - The schema type for array elements, extending ModelArray\n * @param init - The initial array value for the state\n * @param compare - A function that defines the sort order of elements\n * @param options - Optional state options for the state\n * @returns A reactive state containing the sorted array\n */\nexport function orderedRef<T extends unknown[], S extends ModelArray = ModelArray>(\n init: T,\n compare: (a: T[number], b: T[number]) => number,\n options?: StateOptions<S>\n): T {\n return anchor.ordered(init, compare, options);\n}\n\n/**\n * @deprecated Use 'flat()' instead.\n * Creates a reactive state that maintains a flat array state.\n *\n * @template T - The type of elements in the array\n * @template S - The schema type for array elements, extending ModelArray\n * @param init - The initial array value for the state\n * @param options - Optional state options for the state\n * @returns A reactive state containing the flat array\n */\nexport function flatRef<T extends unknown[], S extends ModelArray = ModelArray>(init: T, options?: StateOptions<S>): T {\n return anchor.flat(init, options);\n}\n\n/**\n * @deprecated Use 'raw()' instead.\n * Creates a reactive state that mutates the underlying object.\n *\n * Unless you set the global options to `cloned: true`, you don't want to use this.\n *\n * @template T - The type of the initial value\n * @template S - The schema type, extending LinkableSchema\n * @param init - The initial value for the state\n * @param options - Optional state options for the state\n * @returns A reactive state containing the raw value\n */\nexport function rawRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(\n init: T,\n options?: StateOptions<S>\n): T {\n return anchor.raw(init, options);\n}"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/derive.ts"],"names":[],"mappings":";;;;AAeO,SAAS,UAAA,CAAiB,OAAU,MAAA,EAA2C;AACpF,EAAA,MAAM,WAAW,MAAA,CAAO,IAAI,EAAE,SAAA,EAAW,OAAO,CAAA;AAChD,EAAA,MAAM,QAAA,GAAW;AAAA,IACf,IAAI,KAAA,GAAQ;AACV,MAAA,OAAO,QAAA,CAAS,KAAA;AAAA,IAClB;AAAA,GACF;AACA,EAAA,YAAA,CAAa,GAAA,CAAI,UAAU,QAAQ,CAAA;AAEnC,EAAA,MAAM,WAAA,GAAc,SAAA,CAAU,KAAA,EAAO,CAAC,OAAA,KAAY;AAChD,IAAA,QAAA,CAAS,KAAA,GAAQ,OAAO,OAAO,CAAA;AAAA,EACjC,CAAC,CAAA;AAED,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,MAAA,CAAO,QAAQ,QAAQ,CAAA;AACvB,IAAA,WAAA,EAAY;AACZ,IAAA,YAAA,CAAa,OAAO,QAAQ,CAAA;AAAA,EAC9B,CAAC,CAAA;AAED,EAAA,OAAO,QAAA;AACT","file":"derive.js","sourcesContent":["import { anchor, subscribe } from '@anchorlib/core';\nimport type { ConstantRef, StateRef } from './types.js';\nimport { onDestroy } from 'svelte';\nimport { REF_REGISTRY } from './ref.js';\n\n/**\n * @deprecated Use `derived()` instead.\n * Creates a derived state from a source state with an optional transformation.\n *\n * @template T - The type of the input state\n * @template R - The type of the transformed output\n * @param state - The source state\n * @param derive - A function that transforms the current state value\n * @returns A read-only reference containing the derived state value\n */\nexport function derivedRef<T, R>(state: T, derive: (current: T) => R): ConstantRef<R> {\n const valueRef = anchor({}, { recursive: false }) as StateRef<R>;\n const stateRef = {\n get value() {\n return valueRef.value;\n },\n };\n REF_REGISTRY.set(stateRef, valueRef);\n\n const unsubscribe = subscribe(state, (current) => {\n valueRef.value = derive(current);\n });\n\n onDestroy(() => {\n anchor.destroy(valueRef);\n unsubscribe();\n REF_REGISTRY.delete(stateRef);\n });\n\n return stateRef as ConstantRef<R>;\n}"]}