@anchorlib/svelte 1.0.0-beta.18 → 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.
- package/dist/anchor.d.ts +6 -4
- package/dist/anchor.js +57 -8
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -3
- package/dist/derive.d.ts +5 -3
- package/dist/derive.js +30 -22
- package/dist/fetch.d.ts +11 -9
- package/dist/fetch.js +6 -6
- package/dist/history.d.ts +5 -3
- package/dist/history.js +12 -5
- package/dist/immutable.d.ts +5 -3
- package/dist/immutable.js +8 -6
- package/dist/index.d.ts +12 -11
- package/dist/index.js +13 -14
- package/dist/model.d.ts +6 -4
- package/dist/model.js +14 -6
- package/dist/observable.d.ts +5 -3
- package/dist/observable.js +32 -24
- package/dist/prop.d.ts +7 -8
- package/dist/prop.js +15 -5
- package/dist/reactive.d.ts +4 -3
- package/dist/reactive.js +45 -40
- package/dist/ref.d.ts +4 -3
- package/dist/ref.js +58 -26
- package/dist/storage/index.d.ts +7 -8
- package/dist/storage/index.js +9 -9
- package/dist/storage/kv.d.ts +5 -3
- package/dist/storage/kv.js +22 -10
- package/dist/storage/persistent.d.ts +5 -3
- package/dist/storage/persistent.js +23 -10
- package/dist/storage/session.d.ts +5 -3
- package/dist/storage/session.js +23 -10
- package/dist/storage/table.d.ts +6 -4
- package/dist/storage/table.js +42 -41
- package/dist/storage/types.d.ts +12 -11
- package/dist/storage/types.js +0 -3
- package/dist/types.d.ts +6 -5
- package/dist/types.js +0 -3
- package/package.json +7 -7
- package/dist/anchor.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/derive.js.map +0 -1
- package/dist/fetch.js.map +0 -1
- package/dist/history.js.map +0 -1
- package/dist/immutable.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/observable.js.map +0 -1
- package/dist/prop.js.map +0 -1
- package/dist/reactive.js.map +0 -1
- package/dist/ref.js.map +0 -1
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/kv.js.map +0 -1
- package/dist/storage/persistent.js.map +0 -1
- package/dist/storage/session.js.map +0 -1
- package/dist/storage/table.js.map +0 -1
- package/dist/storage/types.js.map +0 -1
- package/dist/types.js.map +0 -1
package/dist/reactive.js
CHANGED
|
@@ -1,46 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { onDestroy } from
|
|
3
|
-
import { createSubscriber } from
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
|
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
|
|
2
|
-
import { onDestroy } from
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
63
|
+
return REF_REGISTRY.has(ref);
|
|
31
64
|
}
|
|
32
65
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=ref.js.map
|
|
66
|
+
//#endregion
|
|
67
|
+
export { REF_REGISTRY, constantRef, isRef, variableRef };
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
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 };
|
package/dist/storage/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export * from
|
|
8
|
-
|
|
9
|
-
|
|
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 };
|
package/dist/storage/kv.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
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 };
|
package/dist/storage/kv.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
const state = kv(name, init);
|
|
19
|
+
onDestroy(() => {
|
|
20
|
+
kv.leave(state);
|
|
21
|
+
});
|
|
22
|
+
return state;
|
|
10
23
|
}
|
|
11
24
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=kv.js.map
|
|
25
|
+
//#endregion
|
|
26
|
+
export { kvRef };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
const state = persistent(name, init, options);
|
|
20
|
+
onDestroy(() => {
|
|
21
|
+
persistent.leave(state);
|
|
22
|
+
});
|
|
23
|
+
return state;
|
|
10
24
|
}
|
|
11
25
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=persistent.js.map
|
|
26
|
+
//#endregion
|
|
27
|
+
export { persistentRef };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
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 };
|
package/dist/storage/session.js
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
const state = session(name, init, options);
|
|
20
|
+
onDestroy(() => {
|
|
21
|
+
session.leave(state);
|
|
22
|
+
});
|
|
23
|
+
return state;
|
|
10
24
|
}
|
|
11
25
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=session.js.map
|
|
26
|
+
//#endregion
|
|
27
|
+
export { sessionRef };
|
package/dist/storage/table.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 };
|
package/dist/storage/table.js
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
//# sourceMappingURL=table.js.map
|
|
45
|
+
//#endregion
|
|
46
|
+
export { createTableRef };
|
package/dist/storage/types.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FilterFn, ReactiveTable, Rec, Row, RowListState, RowState } from "@anchorlib/storage/db";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
15
|
+
//#endregion
|
|
16
|
+
export { InferListRef, InferRef, TableRef };
|
package/dist/storage/types.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
type StateRef<T> = {
|
|
2
|
-
|
|
3
|
+
value: T;
|
|
3
4
|
};
|
|
4
5
|
type ConstantRef<T> = {
|
|
5
|
-
|
|
6
|
+
get value(): T;
|
|
6
7
|
};
|
|
7
8
|
type VariableRef<T> = ConstantRef<T> & {
|
|
8
|
-
|
|
9
|
+
set value(value: T);
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
export
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ConstantRef, StateRef, VariableRef };
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anchorlib/svelte",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
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.
|
|
59
|
-
"@anchorlib/storage": "^1.0.0-beta.
|
|
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
|
-
"
|
|
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 &&
|
|
81
|
+
"dev": "rimraf dist && tsdown --watch",
|
|
82
82
|
"clean": "rimraf dist",
|
|
83
|
-
"build": "rimraf dist &&
|
|
84
|
-
"prepublish": "rimraf dist &&
|
|
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"
|
package/dist/anchor.js.map
DELETED
|
@@ -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}"]}
|
package/dist/core/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
package/dist/derive.js.map
DELETED
|
@@ -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}"]}
|