@anchorlib/svelte 1.0.0-beta.10 → 1.0.0-beta.14

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 (54) hide show
  1. package/dist/anchor.d.ts +77 -0
  2. package/dist/anchor.js +19 -0
  3. package/dist/anchor.js.map +1 -0
  4. package/dist/derive.d.ts +14 -0
  5. package/dist/derive.js +26 -0
  6. package/dist/derive.js.map +1 -0
  7. package/dist/fetch.d.ts +56 -0
  8. package/dist/fetch.js +12 -0
  9. package/dist/fetch.js.map +1 -0
  10. package/dist/history.d.ts +11 -0
  11. package/dist/history.js +9 -0
  12. package/dist/history.js.map +1 -0
  13. package/dist/immutable.d.ts +43 -0
  14. package/dist/immutable.js +12 -0
  15. package/dist/immutable.js.map +1 -0
  16. package/dist/index.d.ts +11 -305
  17. package/dist/index.js +11 -138
  18. package/dist/index.js.map +1 -1
  19. package/dist/model.d.ts +36 -0
  20. package/dist/model.js +12 -0
  21. package/dist/model.js.map +1 -0
  22. package/dist/observable.d.ts +14 -0
  23. package/dist/observable.js +28 -0
  24. package/dist/observable.js.map +1 -0
  25. package/dist/prop.d.ts +22 -0
  26. package/dist/prop.js +9 -0
  27. package/dist/prop.js.map +1 -0
  28. package/dist/reactive.js +2 -3
  29. package/dist/reactive.js.map +1 -1
  30. package/dist/ref.d.ts +47 -0
  31. package/dist/ref.js +35 -0
  32. package/dist/ref.js.map +1 -0
  33. package/dist/storage/index.d.ts +7 -60
  34. package/dist/storage/index.js +5 -66
  35. package/dist/storage/index.js.map +1 -1
  36. package/dist/storage/kv.d.ts +16 -0
  37. package/dist/storage/kv.js +14 -0
  38. package/dist/storage/kv.js.map +1 -0
  39. package/dist/storage/persistent.d.ts +17 -0
  40. package/dist/storage/persistent.js +14 -0
  41. package/dist/storage/persistent.js.map +1 -0
  42. package/dist/storage/session.d.ts +17 -0
  43. package/dist/storage/session.js +14 -0
  44. package/dist/storage/session.js.map +1 -0
  45. package/dist/storage/table.d.ts +7 -0
  46. package/dist/storage/table.js +45 -0
  47. package/dist/storage/table.js.map +1 -0
  48. package/dist/storage/types.d.ts +15 -0
  49. package/dist/storage/types.js +3 -0
  50. package/dist/storage/types.js.map +1 -0
  51. package/dist/types.d.ts +11 -0
  52. package/dist/types.js +3 -0
  53. package/dist/types.js.map +1 -0
  54. package/package.json +17 -21
@@ -0,0 +1,77 @@
1
+ import { Linkable, LinkableSchema, StateOptions, ModelInput, ModelOutput, Immutable, ModelArray } from '@anchorlib/core';
2
+
3
+ /**
4
+ * Creates a reactive state that can be used to manage state with Anchor.
5
+ * This overload is used when no schema is provided, or when using a LinkableSchema with StateOptions.
6
+ *
7
+ * @template T - The type of the initial value
8
+ * @template S - The schema type, extending LinkableSchema
9
+ * @param init - The initial value for the state
10
+ * @param options - Optional state options for the state
11
+ * @returns A reactive state containing the initial value
12
+ */
13
+ declare function anchorRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): T;
14
+ /**
15
+ * Creates a reactive state with a defined schema for validation and type inference.
16
+ *
17
+ * @template S - The schema type, extending LinkableSchema
18
+ * @template T - The type of the initial value, must extend ModelInput of the schema
19
+ * @param init - The initial value for the state
20
+ * @param schema - The schema to validate and type the state
21
+ * @param options - Optional state options for the state
22
+ * @returns A reactive state containing the output model based on the schema
23
+ */
24
+ declare function anchorRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions): ModelOutput<S>;
25
+ /**
26
+ * Creates an immutable reactive state with a defined schema.
27
+ *
28
+ * @template S - The schema type, extending LinkableSchema
29
+ * @template T - The type of the initial value, must extend ModelInput of the schema
30
+ * @param init - The initial value for the state
31
+ * @param schema - The schema to validate and type the state
32
+ * @param options - State options with immutable flag set to true
33
+ * @returns A reactive state containing an immutable output model based on the schema
34
+ */
35
+ declare function anchorRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions & {
36
+ immutable: true;
37
+ }): Immutable<ModelOutput<S>>;
38
+ /**
39
+ * Reactive state alias for anchorRef.
40
+ * @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>>}}
41
+ */
42
+ declare const reactiveRef: typeof anchorRef;
43
+ /**
44
+ * Creates a reactive state that maintains a sorted array state based on a comparison function.
45
+ *
46
+ * @template T - The type of elements in the array
47
+ * @template S - The schema type for array elements, extending ModelArray
48
+ * @param init - The initial array value for the state
49
+ * @param compare - A function that defines the sort order of elements
50
+ * @param options - Optional state options for the state
51
+ * @returns A reactive state containing the sorted array
52
+ */
53
+ declare function orderedRef<T extends unknown[], S extends ModelArray = ModelArray>(init: T, compare: (a: T[number], b: T[number]) => number, options?: StateOptions<S>): T;
54
+ /**
55
+ * Creates a reactive state that maintains a flat array state.
56
+ *
57
+ * @template T - The type of elements in the array
58
+ * @template S - The schema type for array elements, extending ModelArray
59
+ * @param init - The initial array value for the state
60
+ * @param options - Optional state options for the state
61
+ * @returns A reactive state containing the flat array
62
+ */
63
+ declare function flatRef<T extends unknown[], S extends ModelArray = ModelArray>(init: T, options?: StateOptions<S>): T;
64
+ /**
65
+ * Creates a reactive state that mutates the underlying object.
66
+ *
67
+ * Unless you set the global options to `cloned: true`, you don't want to use this.
68
+ *
69
+ * @template T - The type of the initial value
70
+ * @template S - The schema type, extending LinkableSchema
71
+ * @param init - The initial value for the state
72
+ * @param options - Optional state options for the state
73
+ * @returns A reactive state containing the raw value
74
+ */
75
+ declare function rawRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): T;
76
+
77
+ export { anchorRef, flatRef, orderedRef, rawRef, reactiveRef };
package/dist/anchor.js ADDED
@@ -0,0 +1,19 @@
1
+ import { anchor } from '@anchorlib/core';
2
+
3
+ function anchorRef(init, schemaOptions, options) {
4
+ return anchor(init, schemaOptions, options);
5
+ }
6
+ const reactiveRef = anchorRef;
7
+ function orderedRef(init, compare, options) {
8
+ return anchor.ordered(init, compare, options);
9
+ }
10
+ function flatRef(init, options) {
11
+ return anchor.flat(init, options);
12
+ }
13
+ function rawRef(init, options) {
14
+ return anchor.raw(init, options);
15
+ }
16
+
17
+ export { anchorRef, flatRef, orderedRef, rawRef, reactiveRef };
18
+ //# sourceMappingURL=anchor.js.map
19
+ //# sourceMappingURL=anchor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/anchor.ts"],"names":[],"mappings":";;AAoEO,SAAS,SAAA,CACd,IAAA,EACA,aAAA,EACA,OAAA,EACgD;AAChD,EAAA,OAAO,MAAA,CAAyB,IAAA,EAAuB,aAAA,EAAoB,OAAO,CAAA;AACpF;AAMO,MAAM,WAAA,GAAc;AAYpB,SAAS,UAAA,CACd,IAAA,EACA,OAAA,EACA,OAAA,EACG;AACH,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,IAAA,EAAM,OAAA,EAAS,OAAO,CAAA;AAC9C;AAWO,SAAS,OAAA,CAAgE,MAAS,OAAA,EAA8B;AACrH,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,IAAA,EAAM,OAAO,CAAA;AAClC;AAaO,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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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}\n"]}
@@ -0,0 +1,14 @@
1
+ import { ConstantRef } from './types.js';
2
+
3
+ /**
4
+ * Creates a derived state from a source state with an optional transformation.
5
+ *
6
+ * @template T - The type of the input state
7
+ * @template R - The type of the transformed output
8
+ * @param state - The source state
9
+ * @param derive - A function that transforms the current state value
10
+ * @returns A read-only reference containing the derived state value
11
+ */
12
+ declare function derivedRef<T, R>(state: T, derive: (current: T) => R): ConstantRef<R>;
13
+
14
+ export { derivedRef };
package/dist/derive.js ADDED
@@ -0,0 +1,26 @@
1
+ import { anchor, subscribe } from '@anchorlib/core';
2
+ import { onDestroy } from 'svelte';
3
+ import { REF_REGISTRY } from './ref.js';
4
+
5
+ function derivedRef(state, derive) {
6
+ const valueRef = anchor({}, { recursive: false });
7
+ const stateRef = {
8
+ get value() {
9
+ return valueRef.value;
10
+ }
11
+ };
12
+ REF_REGISTRY.set(stateRef, valueRef);
13
+ const unsubscribe = subscribe(state, (current) => {
14
+ valueRef.value = derive(current);
15
+ });
16
+ onDestroy(() => {
17
+ anchor.destroy(valueRef);
18
+ unsubscribe();
19
+ REF_REGISTRY.delete(stateRef);
20
+ });
21
+ return stateRef;
22
+ }
23
+
24
+ export { derivedRef };
25
+ //# sourceMappingURL=derive.js.map
26
+ //# sourceMappingURL=derive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/derive.ts"],"names":[],"mappings":";;;;AAcO,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 * 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}\n"]}
@@ -0,0 +1,56 @@
1
+ import { FetchOptions, FetchState, StreamOptions } from '@anchorlib/core';
2
+
3
+ /**
4
+ * Creates a reactive state that manages the state of a fetch request.
5
+ * This overload is for GET or DELETE requests, which typically do not have a request body.
6
+ *
7
+ * @template R The type of the data expected in the response.
8
+ * @param init The initial value for the fetch state.
9
+ * @param options The options for the fetch request, including the URL and method.
10
+ * @returns A `FetchState` object representing the state of the request.
11
+ */
12
+ declare function fetchRef<R>(init: R, options: FetchOptions & {
13
+ method: 'GET' | 'DELETE';
14
+ }): FetchState<R>;
15
+ /**
16
+ * Creates a readable Svelte store that manages the state of a fetch request.
17
+ * This overload is for POST, PUT, or PATCH requests, which typically include a request body.
18
+ *
19
+ * @template R The type of the data expected in the response.
20
+ * @template P The type of the request body.
21
+ * @param init The initial value for the fetch state.
22
+ * @param options The options for the fetch request, including the URL, method, and body.
23
+ * @returns A `FetchState` object representing the state of the request.
24
+ */
25
+ declare function fetchRef<R, P>(init: R, options: FetchOptions & {
26
+ method: 'POST' | 'PUT' | 'PATCH';
27
+ body: P;
28
+ }): FetchState<R>;
29
+ /**
30
+ * Creates a reactive state that manages the state of a streaming request.
31
+ * This overload is for GET or DELETE requests, which typically do not have a request body.
32
+ *
33
+ * @template R The type of the data expected in the response.
34
+ * @param init The initial value for the fetch state.
35
+ * @param options The options for the stream request, including the URL and method.
36
+ * @returns A `FetchState` object representing the state of the request.
37
+ */
38
+ declare function streamRef<R>(init: R, options: StreamOptions<R> & {
39
+ method: 'GET' | 'DELETE';
40
+ }): FetchState<R>;
41
+ /**
42
+ * Creates a reactive state that manages the state of a streaming request.
43
+ * This overload is for POST, PUT, or PATCH requests, which typically include a request body.
44
+ *
45
+ * @template R The type of the data expected in the response.
46
+ * @template P The type of the request body.
47
+ * @param init The initial value for the fetch state.
48
+ * @param options The options for the stream request, including the URL, method, and body.
49
+ * @returns A `FetchState` object representing the state of the request.
50
+ */
51
+ declare function streamRef<R, P>(init: R, options: StreamOptions<R> & {
52
+ method: 'POST' | 'PUT' | 'PATCH';
53
+ body: P;
54
+ }): FetchState<R>;
55
+
56
+ export { fetchRef, streamRef };
package/dist/fetch.js ADDED
@@ -0,0 +1,12 @@
1
+ import { fetchState, streamState } from '@anchorlib/core';
2
+
3
+ function fetchRef(init, options) {
4
+ return fetchState(init, options);
5
+ }
6
+ function streamRef(init, options) {
7
+ return streamState(init, options);
8
+ }
9
+
10
+ export { fetchRef, streamRef };
11
+ //# sourceMappingURL=fetch.js.map
12
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/fetch.ts"],"names":[],"mappings":";;AA4BO,SAAS,QAAA,CAAY,MAAS,OAAA,EAAsC;AACzE,EAAA,OAAO,UAAA,CAAW,MAAM,OAAO,CAAA;AACjC;AA4BO,SAAS,SAAA,CAAa,MAAS,OAAA,EAA0C;AAC9E,EAAA,OAAO,WAAA,CAAY,MAAM,OAAO,CAAA;AAClC","file":"fetch.js","sourcesContent":["import { type FetchOptions, fetchState, type FetchState, type StreamOptions, streamState } from '@anchorlib/core';\n\n/**\n * Creates a reactive state that manages the state of a fetch request.\n * This overload is for GET or DELETE requests, which typically do not have a request body.\n *\n * @template R The type of the data expected in the response.\n * @param init The initial value for the fetch state.\n * @param options The options for the fetch request, including the URL and method.\n * @returns A `FetchState` object representing the state of the request.\n */\nexport function fetchRef<R>(init: R, options: FetchOptions & { method: 'GET' | 'DELETE' }): FetchState<R>;\n\n/**\n * Creates a readable Svelte store that manages the state of a fetch request.\n * This overload is for POST, PUT, or PATCH requests, which typically include a request body.\n *\n * @template R The type of the data expected in the response.\n * @template P The type of the request body.\n * @param init The initial value for the fetch state.\n * @param options The options for the fetch request, including the URL, method, and body.\n * @returns A `FetchState` object representing the state of the request.\n */\nexport function fetchRef<R, P>(\n init: R,\n options: FetchOptions & { method: 'POST' | 'PUT' | 'PATCH'; body: P }\n): FetchState<R>;\n\nexport function fetchRef<R>(init: R, options: FetchOptions): FetchState<R> {\n return fetchState(init, options);\n}\n\n/**\n * Creates a reactive state that manages the state of a streaming request.\n * This overload is for GET or DELETE requests, which typically do not have a request body.\n *\n * @template R The type of the data expected in the response.\n * @param init The initial value for the fetch state.\n * @param options The options for the stream request, including the URL and method.\n * @returns A `FetchState` object representing the state of the request.\n */\nexport function streamRef<R>(init: R, options: StreamOptions<R> & { method: 'GET' | 'DELETE' }): FetchState<R>;\n\n/**\n * Creates a reactive state that manages the state of a streaming request.\n * This overload is for POST, PUT, or PATCH requests, which typically include a request body.\n *\n * @template R The type of the data expected in the response.\n * @template P The type of the request body.\n * @param init The initial value for the fetch state.\n * @param options The options for the stream request, including the URL, method, and body.\n * @returns A `FetchState` object representing the state of the request.\n */\nexport function streamRef<R, P>(\n init: R,\n options: StreamOptions<R> & { method: 'POST' | 'PUT' | 'PATCH'; body: P }\n): FetchState<R>;\n\nexport function streamRef<R>(init: R, options: StreamOptions<R>): FetchState<R> {\n return streamState(init, options);\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { State, HistoryOptions, HistoryState } from '@anchorlib/core';
2
+
3
+ /**
4
+ * Creates a reactive state that reflects the history state of a given Anchor state.
5
+ * @param state The initial Anchor state.
6
+ * @param options Optional history options.
7
+ * @returns A `HistoryState` object representing the state of the history.
8
+ */
9
+ declare function historyRef<T extends State>(state: T, options?: HistoryOptions): HistoryState;
10
+
11
+ export { historyRef };
@@ -0,0 +1,9 @@
1
+ import { history } from '@anchorlib/core';
2
+
3
+ function historyRef(state, options) {
4
+ return history(state, options);
5
+ }
6
+
7
+ export { historyRef };
8
+ //# sourceMappingURL=history.js.map
9
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/history.ts"],"names":[],"mappings":";;AASO,SAAS,UAAA,CAA4B,OAAU,OAAA,EAAwC;AAC5F,EAAA,OAAO,OAAA,CAAQ,OAAO,OAAO,CAAA;AAC/B","file":"history.js","sourcesContent":["import type { HistoryOptions, HistoryState, State } from '@anchorlib/core';\nimport { history } from '@anchorlib/core';\n\n/**\n * Creates a reactive state that reflects the history state of a given Anchor state.\n * @param state The initial Anchor state.\n * @param options Optional history options.\n * @returns A `HistoryState` object representing the state of the history.\n */\nexport function historyRef<T extends State>(state: T, options?: HistoryOptions): HistoryState {\n return history(state, options);\n}\n"]}
@@ -0,0 +1,43 @@
1
+ import { State, LinkableSchema, StateOptions, Immutable, ModelInput, StateBaseOptions, ImmutableOutput, Mutable, MutationKey, MutablePart } from '@anchorlib/core';
2
+
3
+ /**
4
+ * Creates an immutable state from a state object.
5
+ *
6
+ * @template T The type of the state object.
7
+ * @template S The type of the linkable schema.
8
+ * @param init The initial state object.
9
+ * @param options Optional state options.
10
+ * @returns An immutable state.
11
+ */
12
+ declare function immutableRef<T extends State, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): Immutable<T>;
13
+ /**
14
+ * Creates an immutable state from a model input and a schema.
15
+ *
16
+ * @template S The type of the linkable schema.
17
+ * @template T The type of the model input.
18
+ * @param init The initial model input.
19
+ * @param schema The linkable schema.
20
+ * @param options Optional base state options.
21
+ * @returns An immutable state.
22
+ */
23
+ declare function immutableRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema: S, options?: StateBaseOptions): ImmutableOutput<S>;
24
+ /**
25
+ * Creates a writable state from a state object.
26
+ *
27
+ * @template T The type of the state object.
28
+ * @param state The initial state object.
29
+ * @returns A mutable state.
30
+ */
31
+ declare function writableRef<T extends State>(state: T): Mutable<T>;
32
+ /**
33
+ * Creates a writable state from a state object and a list of contracts.
34
+ *
35
+ * @template T The type of the state object.
36
+ * @template K The type of the mutation keys.
37
+ * @param state The initial state object.
38
+ * @param contracts A list of mutation keys.
39
+ * @returns A mutable part of the state.
40
+ */
41
+ declare function writableRef<T extends State, K extends MutationKey<T>[]>(state: T, contracts: K): MutablePart<T, K>;
42
+
43
+ export { immutableRef, writableRef };
@@ -0,0 +1,12 @@
1
+ import { anchor } from '@anchorlib/core';
2
+
3
+ function immutableRef(init, schemaOptions, options) {
4
+ return anchor.immutable(init, schemaOptions, options);
5
+ }
6
+ function writableRef(state, contracts) {
7
+ return anchor.writable(state, contracts);
8
+ }
9
+
10
+ export { immutableRef, writableRef };
11
+ //# sourceMappingURL=immutable.js.map
12
+ //# sourceMappingURL=immutable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/immutable.ts"],"names":[],"mappings":";;AA6CO,SAAS,YAAA,CACd,IAAA,EACA,aAAA,EACA,OAAA,EACc;AACd,EAAA,OAAO,MAAA,CAAO,SAAA,CAAU,IAAA,EAAe,aAAA,EAAwB,OAAO,CAAA;AACxE;AAuBO,SAAS,WAAA,CAAyD,OAAU,SAAA,EAAkB;AACnG,EAAA,OAAO,MAAA,CAAO,QAAA,CAAS,KAAA,EAAO,SAAS,CAAA;AACzC","file":"immutable.js","sourcesContent":["import {\n anchor,\n type Immutable,\n type ImmutableOutput,\n type LinkableSchema,\n type ModelInput,\n type Mutable,\n type MutablePart,\n type MutationKey,\n type State,\n type StateBaseOptions,\n type StateOptions,\n} from '@anchorlib/core';\n\n/**\n * Creates an immutable state from a state object.\n *\n * @template T The type of the state object.\n * @template S The type of the linkable schema.\n * @param init The initial state object.\n * @param options Optional state options.\n * @returns An immutable state.\n */\nexport function immutableRef<T extends State, S extends LinkableSchema = LinkableSchema>(\n init: T,\n options?: StateOptions<S>\n): Immutable<T>;\n\n/**\n * Creates an immutable state from a model input and a schema.\n *\n * @template S The type of the linkable schema.\n * @template T The type of the model input.\n * @param init The initial model input.\n * @param schema The linkable schema.\n * @param options Optional base state options.\n * @returns An immutable state.\n */\nexport function immutableRef<S extends LinkableSchema, T extends ModelInput<S>>(\n init: T,\n schema: S,\n options?: StateBaseOptions\n): ImmutableOutput<S>;\n\n/** Implementation of `immutableRef` overloads. */\nexport function immutableRef<T extends State, S extends LinkableSchema = LinkableSchema>(\n init: T,\n schemaOptions?: S | StateOptions,\n options?: StateOptions<S>\n): Immutable<T> {\n return anchor.immutable(init as never, schemaOptions as never, options);\n}\n\n/**\n * Creates a writable state from a state object.\n *\n * @template T The type of the state object.\n * @param state The initial state object.\n * @returns A mutable state.\n */\nexport function writableRef<T extends State>(state: T): Mutable<T>;\n\n/**\n * Creates a writable state from a state object and a list of contracts.\n *\n * @template T The type of the state object.\n * @template K The type of the mutation keys.\n * @param state The initial state object.\n * @param contracts A list of mutation keys.\n * @returns A mutable part of the state.\n */\nexport function writableRef<T extends State, K extends MutationKey<T>[]>(state: T, contracts: K): MutablePart<T, K>;\n\n/** Implementation of `writableRef` overloads. */\nexport function writableRef<T extends State, K extends MutationKey<T>[]>(state: T, contracts?: K): T {\n return anchor.writable(state, contracts) as T;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,305 +1,11 @@
1
- import { Linkable, LinkableSchema, StateOptions, ModelInput, ModelOutput, Immutable, ModelArray, FetchOptions, FetchState, StreamOptions, State, HistoryOptions, HistoryState, StateBaseOptions, ImmutableOutput, Mutable, MutationKey, MutablePart, ObjLike, StateExceptionMap, KeyLike } from '@anchorlib/core';
2
-
3
- /**
4
- * Creates a reactive state that can be used to manage state with Anchor.
5
- * This overload is used when no schema is provided, or when using a LinkableSchema with StateOptions.
6
- *
7
- * @template T - The type of the initial value
8
- * @template S - The schema type, extending LinkableSchema
9
- * @param init - The initial value for the state
10
- * @param options - Optional state options for the state
11
- * @returns A reactive state containing the initial value
12
- */
13
- declare function anchorRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): T;
14
- /**
15
- * Creates a reactive state with a defined schema for validation and type inference.
16
- *
17
- * @template S - The schema type, extending LinkableSchema
18
- * @template T - The type of the initial value, must extend ModelInput of the schema
19
- * @param init - The initial value for the state
20
- * @param schema - The schema to validate and type the state
21
- * @param options - Optional state options for the state
22
- * @returns A reactive state containing the output model based on the schema
23
- */
24
- declare function anchorRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions): ModelOutput<S>;
25
- /**
26
- * Creates an immutable reactive state with a defined schema.
27
- *
28
- * @template S - The schema type, extending LinkableSchema
29
- * @template T - The type of the initial value, must extend ModelInput of the schema
30
- * @param init - The initial value for the state
31
- * @param schema - The schema to validate and type the state
32
- * @param options - State options with immutable flag set to true
33
- * @returns A reactive state containing an immutable output model based on the schema
34
- */
35
- declare function anchorRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions & {
36
- immutable: true;
37
- }): Immutable<ModelOutput<S>>;
38
- /**
39
- * Reactive state alias for anchorRef.
40
- * @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>>}}
41
- */
42
- declare const reactiveRef: typeof anchorRef;
43
- /**
44
- * Creates a reactive state that maintains a sorted array state based on a comparison function.
45
- *
46
- * @template T - The type of elements in the array
47
- * @template S - The schema type for array elements, extending ModelArray
48
- * @param init - The initial array value for the state
49
- * @param compare - A function that defines the sort order of elements
50
- * @param options - Optional state options for the state
51
- * @returns A reactive state containing the sorted array
52
- */
53
- declare function orderedRef<T extends unknown[], S extends ModelArray = ModelArray>(init: T, compare: (a: T[number], b: T[number]) => number, options?: StateOptions<S>): T;
54
- /**
55
- * Creates a reactive state that maintains a flat array state.
56
- *
57
- * @template T - The type of elements in the array
58
- * @template S - The schema type for array elements, extending ModelArray
59
- * @param init - The initial array value for the state
60
- * @param options - Optional state options for the state
61
- * @returns A reactive state containing the flat array
62
- */
63
- declare function flatRef<T extends unknown[], S extends ModelArray = ModelArray>(init: T, options?: StateOptions<S>): T;
64
- /**
65
- * Creates a reactive state that mutates the underlying object.
66
- *
67
- * Unless you set the global options to `cloned: true`, you don't want to use this.
68
- *
69
- * @template T - The type of the initial value
70
- * @template S - The schema type, extending LinkableSchema
71
- * @param init - The initial value for the state
72
- * @param options - Optional state options for the state
73
- * @returns A reactive state containing the raw value
74
- */
75
- declare function rawRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): T;
76
-
77
- type StateRef<T> = {
78
- value: T;
79
- };
80
- type ConstantRef<T> = {
81
- get value(): T;
82
- };
83
- type VariableRef<T> = ConstantRef<T> & {
84
- set value(value: T);
85
- };
86
-
87
- /**
88
- * Creates a derived state from a source state with an optional transformation.
89
- *
90
- * @template T - The type of the input state
91
- * @template R - The type of the transformed output
92
- * @param state - The source state
93
- * @param derive - A function that transforms the current state value
94
- * @returns A read-only reference containing the derived state value
95
- */
96
- declare function derivedRef<T, R>(state: T, derive: (current: T) => R): ConstantRef<R>;
97
-
98
- /**
99
- * Creates a reactive state that manages the state of a fetch request.
100
- * This overload is for GET or DELETE requests, which typically do not have a request body.
101
- *
102
- * @template R The type of the data expected in the response.
103
- * @param init The initial value for the fetch state.
104
- * @param options The options for the fetch request, including the URL and method.
105
- * @returns A `FetchState` object representing the state of the request.
106
- */
107
- declare function fetchRef<R>(init: R, options: FetchOptions & {
108
- method: 'GET' | 'DELETE';
109
- }): FetchState<R>;
110
- /**
111
- * Creates a readable Svelte store that manages the state of a fetch request.
112
- * This overload is for POST, PUT, or PATCH requests, which typically include a request body.
113
- *
114
- * @template R The type of the data expected in the response.
115
- * @template P The type of the request body.
116
- * @param init The initial value for the fetch state.
117
- * @param options The options for the fetch request, including the URL, method, and body.
118
- * @returns A `FetchState` object representing the state of the request.
119
- */
120
- declare function fetchRef<R, P>(init: R, options: FetchOptions & {
121
- method: 'POST' | 'PUT' | 'PATCH';
122
- body: P;
123
- }): FetchState<R>;
124
- /**
125
- * Creates a reactive state that manages the state of a streaming request.
126
- * This overload is for GET or DELETE requests, which typically do not have a request body.
127
- *
128
- * @template R The type of the data expected in the response.
129
- * @param init The initial value for the fetch state.
130
- * @param options The options for the stream request, including the URL and method.
131
- * @returns A `FetchState` object representing the state of the request.
132
- */
133
- declare function streamRef<R>(init: R, options: StreamOptions<R> & {
134
- method: 'GET' | 'DELETE';
135
- }): FetchState<R>;
136
- /**
137
- * Creates a reactive state that manages the state of a streaming request.
138
- * This overload is for POST, PUT, or PATCH requests, which typically include a request body.
139
- *
140
- * @template R The type of the data expected in the response.
141
- * @template P The type of the request body.
142
- * @param init The initial value for the fetch state.
143
- * @param options The options for the stream request, including the URL, method, and body.
144
- * @returns A `FetchState` object representing the state of the request.
145
- */
146
- declare function streamRef<R, P>(init: R, options: StreamOptions<R> & {
147
- method: 'POST' | 'PUT' | 'PATCH';
148
- body: P;
149
- }): FetchState<R>;
150
-
151
- /**
152
- * Creates a reactive state that reflects the history state of a given Anchor state.
153
- * @param state The initial Anchor state.
154
- * @param options Optional history options.
155
- * @returns A `HistoryState` object representing the state of the history.
156
- */
157
- declare function historyRef<T extends State>(state: T, options?: HistoryOptions): HistoryState;
158
-
159
- /**
160
- * Creates an immutable state from a state object.
161
- *
162
- * @template T The type of the state object.
163
- * @template S The type of the linkable schema.
164
- * @param init The initial state object.
165
- * @param options Optional state options.
166
- * @returns An immutable state.
167
- */
168
- declare function immutableRef<T extends State, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): Immutable<T>;
169
- /**
170
- * Creates an immutable state from a model input and a schema.
171
- *
172
- * @template S The type of the linkable schema.
173
- * @template T The type of the model input.
174
- * @param init The initial model input.
175
- * @param schema The linkable schema.
176
- * @param options Optional base state options.
177
- * @returns An immutable state.
178
- */
179
- declare function immutableRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema: S, options?: StateBaseOptions): ImmutableOutput<S>;
180
- /**
181
- * Creates a writable state from a state object.
182
- *
183
- * @template T The type of the state object.
184
- * @param state The initial state object.
185
- * @returns A mutable state.
186
- */
187
- declare function writableRef<T extends State>(state: T): Mutable<T>;
188
- /**
189
- * Creates a writable state from a state object and a list of contracts.
190
- *
191
- * @template T The type of the state object.
192
- * @template K The type of the mutation keys.
193
- * @param state The initial state object.
194
- * @param contracts A list of mutation keys.
195
- * @returns A mutable part of the state.
196
- */
197
- declare function writableRef<T extends State, K extends MutationKey<T>[]>(state: T, contracts: K): MutablePart<T, K>;
198
-
199
- /**
200
- * Creates a model with mutable state.
201
- *
202
- * @template S - The linkable schema type
203
- * @template T - The model input type that extends the schema
204
- * @param schema - The schema to use for the model
205
- * @param init - The initial value for the model
206
- * @param options - Optional state configuration
207
- * @returns A model output.
208
- */
209
- declare function modelRef<S extends LinkableSchema, T extends ModelInput<S>>(schema: S, init: T, options?: StateBaseOptions): ModelOutput<S>;
210
- /**
211
- * Creates a model with immutable state.
212
- *
213
- * @template S - The linkable schema type
214
- * @template T - The model input type that extends the schema
215
- * @param schema - The schema to use for the model
216
- * @param init - The initial value for the model
217
- * @param options - State configuration with immutable flag set to true
218
- * @returns An immutable model output.
219
- */
220
- declare function modelRef<S extends LinkableSchema, T extends ModelInput<S>>(schema: S, init: T, options: StateBaseOptions & {
221
- immutable: true;
222
- }): ImmutableOutput<S>;
223
- /**
224
- * Creates a state that maps exceptions for a given state object or array.
225
- *
226
- * @template T - The type of the input state, must be an object-like or array type
227
- * @param state - The input state object or array to create exception mappings for
228
- * @returns A StateExceptionMap for the provided state.
229
- */
230
- declare function exceptionRef<T extends ObjLike | Array<unknown>>(state: T): StateExceptionMap<T>;
231
-
232
- type Props = {
233
- [key: string]: KeyLike | State;
234
- };
235
- type PropsRef<T extends Props> = {
236
- [K in keyof T]: T[K] extends State ? ConstantRef<T[K]> : T[K];
237
- };
238
- /**
239
- * Creates a reactive state object from the provided props.
240
- * For each property in the input props:
241
- * - If the value is a State object, it will be converted to a derived state
242
- * - Otherwise, the value will be kept as is
243
- * @deprecated
244
- * @template T - The type of props extending Props
245
- * @param {T} props - The input props object containing KeyLike or State values
246
- * @returns {PropsRef<T>} A new object with State values converted to reactive states
247
- */
248
- declare function propsRef<T extends Props>(props: T): T;
249
-
250
- /**
251
- * Creates a read-only reference that observes a reactive function and updates its value
252
- * when the observed value changes. The function automatically handles observer lifecycle
253
- * and cleanup using Svelte's onDestroy hook.
254
- *
255
- * @template R - The type of the observed value
256
- * @param observe - A function that returns the value to be observed
257
- * @returns A read-only reference containing the observed value
258
- */
259
- declare function observedRef<R>(observe: () => R): ConstantRef<R>;
260
-
261
- declare const REF_REGISTRY: WeakMap<ConstantRef<unknown>, StateRef<unknown>>;
262
- /**
263
- * Creates a readable reference that can be subscribed to for reactive updates.
264
- * This function initializes a reactive reference with a given initial value and provides
265
- * mechanisms for subscribing to changes and publishing updates to subscribers.
266
- *
267
- * @template T The type of the value being referenced
268
- * @param init - The initial value for the reference
269
- * @returns A readable reference object with subscribe and publish capabilities
270
- */
271
- declare function variableRef<T>(init: T): VariableRef<T>;
272
- /**
273
- * Creates a constant (read-only) reference that can be subscribed to for reactive updates.
274
- * This function initializes a reactive reference with a given initial value that cannot be modified
275
- * after creation.
276
- *
277
- * @template T The type of the value being referenced
278
- * @param init - The initial value for the reference
279
- * @param constant - If true, the reference will be read-only and cannot be updated.
280
- * @returns A constant reference object with subscribe capability but no write access
281
- */
282
- declare function variableRef<T>(init: T, constant: true): ConstantRef<T>;
283
- /**
284
- * Creates a constant (read-only) reference that can be subscribed to for reactive updates.
285
- * This function initializes a reactive reference with a given initial value that cannot be modified
286
- * after creation. It's useful for values that should remain constant throughout the component lifecycle
287
- * but still need to be reactively tracked.
288
- *
289
- * @template T The type of the value being referenced
290
- * @param init - The initial value for the constant reference
291
- * @returns A constant reference object with subscribe capability but no write access
292
- */
293
- declare function constantRef<T>(init: T): ConstantRef<T>;
294
- /**
295
- * Checks if a given value is a writable reference.
296
- * This function uses the REF_REGISTRY to determine if the provided value
297
- * is a registered writable reference.
298
- *
299
- * @template T The type of the value that the reference holds
300
- * @param ref - The value to check
301
- * @returns True if the value is a writable reference, false otherwise
302
- */
303
- declare function isRef<T>(ref: unknown): ref is VariableRef<T>;
304
-
305
- export { type ConstantRef, type Props, type PropsRef, REF_REGISTRY, type StateRef, type VariableRef, anchorRef, constantRef, derivedRef, exceptionRef, fetchRef, flatRef, historyRef, immutableRef, isRef, modelRef, observedRef, orderedRef, propsRef, rawRef, reactiveRef, streamRef, variableRef, writableRef };
1
+ export { anchorRef, flatRef, orderedRef, rawRef, reactiveRef } from './anchor.js';
2
+ export { derivedRef } from './derive.js';
3
+ export { fetchRef, streamRef } from './fetch.js';
4
+ export { historyRef } from './history.js';
5
+ export { immutableRef, writableRef } from './immutable.js';
6
+ export { exceptionRef, modelRef } from './model.js';
7
+ export { Props, PropsRef, propsRef } from './prop.js';
8
+ export { observedRef } from './observable.js';
9
+ export { REF_REGISTRY, constantRef, isRef, variableRef } from './ref.js';
10
+ export { ConstantRef, StateRef, VariableRef } from './types.js';
11
+ import '@anchorlib/core';