@anchorlib/svelte 1.0.0-beta.2 → 1.0.0-beta.21
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 +86 -0
- package/dist/anchor.js +68 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/derive.d.ts +17 -0
- package/dist/derive.js +34 -0
- package/dist/fetch.d.ts +62 -0
- package/dist/fetch.js +12 -0
- package/dist/history.d.ts +14 -0
- package/dist/history.js +16 -0
- package/dist/immutable.d.ts +49 -0
- package/dist/immutable.js +14 -0
- package/dist/index.d.ts +12 -304
- package/dist/index.js +12 -206
- package/dist/model.d.ts +41 -0
- package/dist/model.js +20 -0
- package/dist/observable.d.ts +17 -0
- package/dist/observable.js +36 -0
- package/dist/prop.d.ts +21 -0
- package/dist/prop.js +19 -0
- package/dist/reactive.d.ts +6 -0
- package/dist/reactive.js +51 -0
- package/dist/ref.d.ts +52 -0
- package/dist/ref.js +67 -0
- package/dist/storage/index.d.ts +8 -61
- package/dist/storage/index.js +9 -64
- package/dist/storage/kv.d.ts +19 -0
- package/dist/storage/kv.js +26 -0
- package/dist/storage/persistent.d.ts +20 -0
- package/dist/storage/persistent.js +27 -0
- package/dist/storage/session.d.ts +20 -0
- package/dist/storage/session.js +27 -0
- package/dist/storage/table.d.ts +15 -0
- package/dist/storage/table.js +46 -0
- package/dist/storage/types.d.ts +16 -0
- package/dist/storage/types.js +0 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +0 -0
- package/package.json +32 -20
- package/readme.md +7 -16
- package/dist/index.js.map +0 -1
- package/dist/storage/index.js.map +0 -1
- package/dist/types-CsfltB4A.d.ts +0 -16
package/dist/prop.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "@anchorlib/core";
|
|
2
|
+
|
|
3
|
+
//#region src/prop.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a reactive state object from the provided props.
|
|
6
|
+
* For each property in the input props:
|
|
7
|
+
* - If the value is a State object, it will be converted to a derived state
|
|
8
|
+
* - Otherwise, the value will be kept as is
|
|
9
|
+
* @deprecated
|
|
10
|
+
* @template T - The type of props extending Props
|
|
11
|
+
* @param {T} props - The input props object containing KeyLike or State values
|
|
12
|
+
* @returns {PropsRef<T>} A new object with State values converted to reactive states
|
|
13
|
+
*/
|
|
14
|
+
function propsRef(props) {
|
|
15
|
+
return props;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { propsRef };
|
package/dist/reactive.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createObserver, onGlobalCleanup, setCleanUpHandler, setTracker } from "@anchorlib/core";
|
|
2
|
+
import { onDestroy } from "svelte";
|
|
3
|
+
import { createSubscriber } from "svelte/reactivity";
|
|
4
|
+
|
|
5
|
+
//#region src/reactive.ts
|
|
6
|
+
const TRACKER_REGISTRY = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
let bindingInitialized = false;
|
|
8
|
+
if (!bindingInitialized && typeof window !== "undefined") {
|
|
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
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { TRACKER_REGISTRY };
|
package/dist/ref.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ConstantRef, StateRef, VariableRef } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/ref.d.ts
|
|
4
|
+
declare const REF_REGISTRY: WeakMap<ConstantRef<unknown>, StateRef<unknown>>;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use 'mutable()' instead.
|
|
7
|
+
* Creates a readable reference that can be subscribed to for reactive updates.
|
|
8
|
+
* This function initializes a reactive reference with a given initial value and provides
|
|
9
|
+
* mechanisms for subscribing to changes and publishing updates to subscribers.
|
|
10
|
+
*
|
|
11
|
+
* @template T The type of the value being referenced
|
|
12
|
+
* @param init - The initial value for the reference
|
|
13
|
+
* @returns A readable reference object with subscribe and publish capabilities
|
|
14
|
+
*/
|
|
15
|
+
declare function variableRef<T>(init: T): VariableRef<T>;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use 'mutable()' instead.
|
|
18
|
+
* Creates a constant (read-only) reference that can be subscribed to for reactive updates.
|
|
19
|
+
* This function initializes a reactive reference with a given initial value that cannot be modified
|
|
20
|
+
* after creation.
|
|
21
|
+
*
|
|
22
|
+
* @template T The type of the value being referenced
|
|
23
|
+
* @param init - The initial value for the reference
|
|
24
|
+
* @param constant - If true, the reference will be read-only and cannot be updated.
|
|
25
|
+
* @returns A constant reference object with subscribe capability but no write access
|
|
26
|
+
*/
|
|
27
|
+
declare function variableRef<T>(init: T, constant: true): ConstantRef<T>;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use 'immutable()' instead.
|
|
30
|
+
* Creates a constant (read-only) reference that can be subscribed to for reactive updates.
|
|
31
|
+
* This function initializes a reactive reference with a given initial value that cannot be modified
|
|
32
|
+
* after creation. It's useful for values that should remain constant throughout the component lifecycle
|
|
33
|
+
* but still need to be reactively tracked.
|
|
34
|
+
*
|
|
35
|
+
* @template T The type of the value being referenced
|
|
36
|
+
* @param init - The initial value for the constant reference
|
|
37
|
+
* @returns A constant reference object with subscribe capability but no write access
|
|
38
|
+
*/
|
|
39
|
+
declare function constantRef<T>(init: T): ConstantRef<T>;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use 'isValueRef()' instead.
|
|
42
|
+
* Checks if a given value is a writable reference.
|
|
43
|
+
* This function uses the REF_REGISTRY to determine if the provided value
|
|
44
|
+
* is a registered writable reference.
|
|
45
|
+
*
|
|
46
|
+
* @template T The type of the value that the reference holds
|
|
47
|
+
* @param ref - The value to check
|
|
48
|
+
* @returns True if the value is a writable reference, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
declare function isRef<T>(ref: unknown): ref is VariableRef<T>;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { REF_REGISTRY, constantRef, isRef, variableRef };
|
package/dist/ref.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { anchor } from "@anchorlib/core";
|
|
2
|
+
import { onDestroy } from "svelte";
|
|
3
|
+
|
|
4
|
+
//#region src/ref.ts
|
|
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
|
+
*/
|
|
17
|
+
function variableRef(init, constant) {
|
|
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;
|
|
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
|
+
*/
|
|
49
|
+
function constantRef(init) {
|
|
50
|
+
return variableRef(init, true);
|
|
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
|
+
*/
|
|
62
|
+
function isRef(ref) {
|
|
63
|
+
return REF_REGISTRY.has(ref);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { REF_REGISTRY, constantRef, isRef, variableRef };
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,61 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
* and automatically cleans up the store subscription when the component is destroyed.
|
|
10
|
-
*
|
|
11
|
-
* @template T - The type of the stored value, must extend Storable
|
|
12
|
-
* @param name - The unique identifier for the key-value store
|
|
13
|
-
* @param init - The initial value for the store
|
|
14
|
-
* @returns A reactive reference to the key-value store state
|
|
15
|
-
*/
|
|
16
|
-
declare function kvRef<T extends Storable>(name: string, init: T): ConstantRef<KVState<T>>;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a persistent reactive reference using the provided name, initial value, and options.
|
|
20
|
-
* The persistentRef is tied to the browser's local storage, meaning its value will persist
|
|
21
|
-
* across page reloads and browser sessions until explicitly cleared.
|
|
22
|
-
*
|
|
23
|
-
* @template T - The type of the initial value, must extend object-like structure.
|
|
24
|
-
* @template S - The schema type for linkable validation, defaults to LinkableSchema.
|
|
25
|
-
* @param name - A unique string identifier for the local storage key.
|
|
26
|
-
* @param init - The initial value to be stored in local storage.
|
|
27
|
-
* @param options - Optional configuration for state behavior and validation schema.
|
|
28
|
-
* @returns A WritableRef<T> that provides reactive access and modification capabilities.
|
|
29
|
-
*/
|
|
30
|
-
declare function persistentRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): ConstantRef<T>;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a session-scoped reactive reference using the provided name, initial value, and options.
|
|
34
|
-
* The sessionRef is tied to the browser's session storage, meaning its value will persist
|
|
35
|
-
* across page reloads but not after the session ends (e.g., tab/window closed).
|
|
36
|
-
*
|
|
37
|
-
* @template T - The type of the initial value, must extend object-like structure.
|
|
38
|
-
* @template S - The schema type for linkable validation, defaults to LinkableSchema.
|
|
39
|
-
* @param name - A unique string identifier for the session storage key.
|
|
40
|
-
* @param init - The initial value to be stored in session storage.
|
|
41
|
-
* @param options - Optional configuration for state behavior and validation schema.
|
|
42
|
-
* @returns A WritableRef<T> that provides reactive access and modification capabilities.
|
|
43
|
-
*/
|
|
44
|
-
declare function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): ConstantRef<T>;
|
|
45
|
-
|
|
46
|
-
interface TableRef<T extends Rec, R extends Row<T> = Row<T>> {
|
|
47
|
-
get(id: string): ConstantRef<RowState<R>>;
|
|
48
|
-
add(payload: T): ConstantRef<RowState<R>>;
|
|
49
|
-
remove(id: string): ConstantRef<RowState<R>>;
|
|
50
|
-
list(filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection): ConstantRef<RowListState<R>>;
|
|
51
|
-
listByIndex(name: keyof R, filter?: IDBKeyRange | FilterFn<R>, limit?: number, direction?: IDBCursorDirection): ConstantRef<RowListState<R>>;
|
|
52
|
-
seed<T extends R[]>(seeds: T): this;
|
|
53
|
-
table(): ReactiveTable<T>;
|
|
54
|
-
}
|
|
55
|
-
type InferRef<T> = T extends TableRef<Rec, infer R> ? ConstantRef<R> : never;
|
|
56
|
-
type InferListRef<T> = T extends TableRef<Rec, infer R> ? ConstantRef<R[]> : never;
|
|
57
|
-
|
|
58
|
-
declare function createTableRef<T extends ReactiveTable<Rec>>(table: T): TableRef<InferRec<T>>;
|
|
59
|
-
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>;
|
|
60
|
-
|
|
61
|
-
export { type InferListRef, type InferRef, type TableRef, createTableRef, kvRef, persistentRef, sessionRef };
|
|
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 * from "@anchorlib/storage/db";
|
|
8
|
+
export { InferListRef, InferRef, TableRef, createTableRef, kvRef, persistentRef, sessionRef };
|
package/dist/storage/index.js
CHANGED
|
@@ -1,66 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
function kvRef(name, init) {
|
|
8
|
-
const state = kv(name, init);
|
|
9
|
-
onDestroy(() => {
|
|
10
|
-
kv.leave(state);
|
|
11
|
-
});
|
|
12
|
-
return constantRef(state);
|
|
13
|
-
}
|
|
14
|
-
function persistentRef(name, init, options) {
|
|
15
|
-
const state = persistent(name, init, options);
|
|
16
|
-
return constantRef(state);
|
|
17
|
-
}
|
|
18
|
-
function sessionRef(name, init, options) {
|
|
19
|
-
const state = session(name, init, options);
|
|
20
|
-
return constantRef(state);
|
|
21
|
-
}
|
|
22
|
-
function createTableRef(tableName, version = 1, indexes, remIndexes, dbName = tableName) {
|
|
23
|
-
if (typeof tableName === "string") {
|
|
24
|
-
tableName = createTable(tableName, version, indexes, remIndexes, dbName);
|
|
25
|
-
}
|
|
26
|
-
const tableRef = tableName;
|
|
27
|
-
return {
|
|
28
|
-
get(id) {
|
|
29
|
-
const state = tableRef.get(id);
|
|
30
|
-
onDestroy(() => {
|
|
31
|
-
tableRef.leave(id);
|
|
32
|
-
});
|
|
33
|
-
return constantRef(state);
|
|
34
|
-
},
|
|
35
|
-
add(payload) {
|
|
36
|
-
const state = tableRef.add(payload);
|
|
37
|
-
onDestroy(() => {
|
|
38
|
-
tableRef.leave(state.data.id);
|
|
39
|
-
});
|
|
40
|
-
return constantRef(state);
|
|
41
|
-
},
|
|
42
|
-
list(filter, limit, direction) {
|
|
43
|
-
const state = tableRef.list(filter, limit, direction);
|
|
44
|
-
return constantRef(state);
|
|
45
|
-
},
|
|
46
|
-
listByIndex(name, filter, limit, direction) {
|
|
47
|
-
const state = tableRef.listByIndex(name, filter, limit, direction);
|
|
48
|
-
return constantRef(state);
|
|
49
|
-
},
|
|
50
|
-
remove(id) {
|
|
51
|
-
const state = tableRef.remove(id);
|
|
52
|
-
return constantRef(state);
|
|
53
|
-
},
|
|
54
|
-
seed(seeds) {
|
|
55
|
-
tableRef.seed(seeds);
|
|
56
|
-
return this;
|
|
57
|
-
},
|
|
58
|
-
table() {
|
|
59
|
-
return tableRef;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
7
|
+
export * from "@anchorlib/storage"
|
|
63
8
|
|
|
64
|
-
export
|
|
65
|
-
|
|
66
|
-
|
|
9
|
+
export * from "@anchorlib/storage/db"
|
|
10
|
+
|
|
11
|
+
export { createTableRef, kvRef, persistentRef, sessionRef };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { KVState, Storable } from "@anchorlib/storage/db";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/kv.d.ts
|
|
4
|
+
|
|
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
|
+
*/
|
|
17
|
+
declare function kvRef<T extends Storable>(name: string, init: T): KVState<T>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { kvRef };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { onDestroy } from "svelte";
|
|
2
|
+
import { kv } from "@anchorlib/storage/db";
|
|
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
|
+
*/
|
|
17
|
+
function kvRef(name, init) {
|
|
18
|
+
const state = kv(name, init);
|
|
19
|
+
onDestroy(() => {
|
|
20
|
+
kv.leave(state);
|
|
21
|
+
});
|
|
22
|
+
return state;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { kvRef };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LinkableSchema, ObjLike, StateOptions } from "@anchorlib/core";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/persistent.d.ts
|
|
4
|
+
|
|
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
|
+
*/
|
|
18
|
+
declare function persistentRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { persistentRef };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { onDestroy } from "svelte";
|
|
2
|
+
import { persistent } from "@anchorlib/storage";
|
|
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
|
+
*/
|
|
18
|
+
function persistentRef(name, init, options) {
|
|
19
|
+
const state = persistent(name, init, options);
|
|
20
|
+
onDestroy(() => {
|
|
21
|
+
persistent.leave(state);
|
|
22
|
+
});
|
|
23
|
+
return state;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { persistentRef };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LinkableSchema, ObjLike, StateOptions } from "@anchorlib/core";
|
|
2
|
+
|
|
3
|
+
//#region src/storage/session.d.ts
|
|
4
|
+
|
|
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
|
+
*/
|
|
18
|
+
declare function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { sessionRef };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { onDestroy } from "svelte";
|
|
2
|
+
import { session } from "@anchorlib/storage";
|
|
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
|
+
*/
|
|
18
|
+
function sessionRef(name, init, options) {
|
|
19
|
+
const state = session(name, init, options);
|
|
20
|
+
onDestroy(() => {
|
|
21
|
+
session.leave(state);
|
|
22
|
+
});
|
|
23
|
+
return state;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { sessionRef };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TableRef } from "./types.js";
|
|
2
|
+
import { InferRec, ReactiveTable, Rec, Row } from "@anchorlib/storage/db";
|
|
3
|
+
|
|
4
|
+
//#region src/storage/table.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use `createTable()` instead.
|
|
8
|
+
*/
|
|
9
|
+
declare function createTableRef<T extends ReactiveTable<Rec>>(table: T): TableRef<InferRec<T>>;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `createTable()` instead.
|
|
12
|
+
*/
|
|
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>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createTableRef };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { onDestroy } from "svelte";
|
|
2
|
+
import { createTable } from "@anchorlib/storage/db";
|
|
3
|
+
|
|
4
|
+
//#region src/storage/table.ts
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `createTable()` instead.
|
|
7
|
+
*/
|
|
8
|
+
function createTableRef(tableName, version = 1, indexes, remIndexes, dbName = tableName) {
|
|
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
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { createTableRef };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FilterFn, ReactiveTable, Rec, Row, RowListState, RowState } from "@anchorlib/storage/db";
|
|
2
|
+
|
|
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>;
|
|
12
|
+
}
|
|
13
|
+
type InferRef<T> = T extends TableRef<Rec, infer R> ? R : never;
|
|
14
|
+
type InferListRef<T> = T extends TableRef<Rec, infer R> ? R[] : never;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { InferListRef, InferRef, TableRef };
|
|
File without changes
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
File without changes
|