effector-storage 7.1.1 → 8.0.0
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/README.md +12 -9
- package/async-storage/index.cjs +1 -1
- package/async-storage/index.cjs.map +1 -1
- package/async-storage/index.d.cts +20 -9
- package/async-storage/index.d.ts +20 -9
- package/async-storage/index.js +1 -1
- package/async-storage/index.js.map +1 -1
- package/broadcast/index.cjs +1 -1
- package/broadcast/index.cjs.map +1 -1
- package/broadcast/index.d.cts +103 -24
- package/broadcast/index.d.ts +103 -24
- package/broadcast/index.js +1 -1
- package/broadcast/index.js.map +1 -1
- package/core/index.cjs +1 -1
- package/core/index.cjs.map +1 -1
- package/core/index.d.cts +97 -19
- package/core/index.d.ts +97 -19
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/package.json +3 -0
- package/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.d.cts +99 -20
- package/index.d.ts +99 -20
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/local/index.cjs +1 -1
- package/local/index.cjs.map +1 -1
- package/local/index.d.cts +103 -24
- package/local/index.d.ts +103 -24
- package/local/index.js +1 -1
- package/local/index.js.map +1 -1
- package/log/index.cjs +1 -1
- package/log/index.cjs.map +1 -1
- package/log/index.d.cts +21 -9
- package/log/index.d.ts +21 -9
- package/log/index.js +1 -1
- package/log/index.js.map +1 -1
- package/memory/index.cjs +1 -1
- package/memory/index.cjs.map +1 -1
- package/memory/index.d.cts +103 -24
- package/memory/index.d.ts +103 -24
- package/memory/index.js +1 -1
- package/memory/index.js.map +1 -1
- package/nil/index.cjs +1 -1
- package/nil/index.cjs.map +1 -1
- package/nil/index.d.cts +20 -9
- package/nil/index.d.ts +20 -9
- package/nil/index.js +1 -1
- package/nil/index.js.map +1 -1
- package/package.json +3 -3
- package/query/index.cjs +1 -1
- package/query/index.cjs.map +1 -1
- package/query/index.d.cts +103 -24
- package/query/index.d.ts +103 -24
- package/query/index.js +1 -1
- package/query/index.js.map +1 -1
- package/session/index.cjs +1 -1
- package/session/index.cjs.map +1 -1
- package/session/index.d.cts +103 -24
- package/session/index.d.ts +103 -24
- package/session/index.js +1 -1
- package/session/index.js.map +1 -1
- package/storage/index.cjs +1 -1
- package/storage/index.cjs.map +1 -1
- package/storage/index.d.cts +20 -9
- package/storage/index.d.ts +20 -9
- package/storage/index.js +1 -1
- package/storage/index.js.map +1 -1
- package/tools/index.cjs +1 -1
- package/tools/index.cjs.map +1 -1
- package/tools/index.d.cts +18 -9
- package/tools/index.d.ts +18 -9
- package/tools/index.js +1 -1
- package/tools/index.js.map +1 -1
- package/tools/package.json +3 -0
- package/async-storage/index.js.flow +0 -37
- package/broadcast/index.js.flow +0 -132
- package/core/index.js.flow +0 -113
- package/index.js.flow +0 -146
- package/local/index.js.flow +0 -140
- package/log/index.js.flow +0 -32
- package/memory/index.js.flow +0 -133
- package/nil/index.js.flow +0 -31
- package/query/index.js.flow +0 -159
- package/session/index.js.flow +0 -140
- package/storage/index.js.flow +0 -36
- package/tools/index.js.flow +0 -104
package/local/index.d.ts
CHANGED
|
@@ -1,21 +1,97 @@
|
|
|
1
|
-
import { Unit, Store, Event, Effect, Subscription } from 'effector';
|
|
1
|
+
import { Unit, UnitTargetable, Store, Event, Effect, StoreWritable, EventCallable, Subscription } from 'effector';
|
|
2
2
|
|
|
3
|
+
/** The Contract interface. */
|
|
4
|
+
interface Contract$1<Raw, Data extends Raw> {
|
|
5
|
+
/**
|
|
6
|
+
* Checks if Raw is Data
|
|
7
|
+
*/
|
|
8
|
+
isData: (prepared: Raw) => prepared is Data;
|
|
9
|
+
/**
|
|
10
|
+
* - empty array is dedicated for valid response
|
|
11
|
+
* - array of string with validation erorrs for invalidDataError
|
|
12
|
+
*/
|
|
13
|
+
getErrorMessages: (prepared: Raw) => string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The Standard Schema interface. */
|
|
17
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
18
|
+
/** The Standard Schema properties. */
|
|
19
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
20
|
+
}
|
|
21
|
+
declare namespace StandardSchemaV1 {
|
|
22
|
+
/** The Standard Schema properties interface. */
|
|
23
|
+
interface Props<Input = unknown, Output = Input> {
|
|
24
|
+
/** The version number of the standard. */
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
/** The vendor name of the schema library. */
|
|
27
|
+
readonly vendor: string;
|
|
28
|
+
/** Validates unknown input values. */
|
|
29
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
30
|
+
/** Inferred types associated with the schema. */
|
|
31
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** The result interface of the validate function. */
|
|
34
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
35
|
+
/** The result interface if validation succeeds. */
|
|
36
|
+
interface SuccessResult<Output> {
|
|
37
|
+
/** The typed output value. */
|
|
38
|
+
readonly value: Output;
|
|
39
|
+
/** A falsy value for `issues` indicates success. */
|
|
40
|
+
readonly issues?: undefined;
|
|
41
|
+
}
|
|
42
|
+
interface Options {
|
|
43
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
44
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
45
|
+
}
|
|
46
|
+
/** The result interface if validation fails. */
|
|
47
|
+
interface FailureResult {
|
|
48
|
+
/** The issues of failed validation. */
|
|
49
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
50
|
+
}
|
|
51
|
+
/** The issue interface of the failure output. */
|
|
52
|
+
interface Issue {
|
|
53
|
+
/** The error message of the issue. */
|
|
54
|
+
readonly message: string;
|
|
55
|
+
/** The path of the issue, if any. */
|
|
56
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
57
|
+
}
|
|
58
|
+
/** The path segment interface of the issue. */
|
|
59
|
+
interface PathSegment {
|
|
60
|
+
/** The key representing a path segment. */
|
|
61
|
+
readonly key: PropertyKey;
|
|
62
|
+
}
|
|
63
|
+
/** The Standard Schema types interface. */
|
|
64
|
+
interface Types<Input = unknown, Output = Input> {
|
|
65
|
+
/** The input type of the schema. */
|
|
66
|
+
readonly input: Input;
|
|
67
|
+
/** The output type of the schema. */
|
|
68
|
+
readonly output: Output;
|
|
69
|
+
}
|
|
70
|
+
/** Infers the input type of a Standard Schema. */
|
|
71
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
72
|
+
/** Infers the output type of a Standard Schema. */
|
|
73
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface Adapter<State> {
|
|
77
|
+
get(this: void, //
|
|
78
|
+
raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
|
|
79
|
+
set(this: void, //
|
|
80
|
+
value: State, ctx?: any): void | Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
interface DisposableAdapter<State> extends Adapter<State> {
|
|
83
|
+
(): void;
|
|
84
|
+
}
|
|
3
85
|
interface StorageAdapter {
|
|
4
|
-
<State>(key: string, update: (raw?: any) => void):
|
|
5
|
-
get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
|
|
6
|
-
set(value: State, ctx?: any): void;
|
|
7
|
-
};
|
|
86
|
+
<State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
|
|
8
87
|
keyArea?: any;
|
|
9
88
|
noop?: boolean;
|
|
10
89
|
}
|
|
11
90
|
interface StorageAdapterFactory<AdapterConfig> {
|
|
12
|
-
(config
|
|
91
|
+
(config: AdapterConfig): StorageAdapter;
|
|
13
92
|
factory: true;
|
|
14
93
|
}
|
|
15
|
-
type Contract<Data> = ((raw: unknown) => raw is Data) |
|
|
16
|
-
isData: (raw: unknown) => raw is Data;
|
|
17
|
-
getErrorMessages: (raw: unknown) => string[];
|
|
18
|
-
};
|
|
94
|
+
type Contract<Data> = ((raw: unknown) => raw is Data) | StandardSchemaV1<unknown, Data> | Contract$1<unknown, Data>;
|
|
19
95
|
type Done<State> = {
|
|
20
96
|
key: string;
|
|
21
97
|
keyPrefix: string;
|
|
@@ -29,11 +105,13 @@ type Fail<Err> = {
|
|
|
29
105
|
error: Err;
|
|
30
106
|
value?: any;
|
|
31
107
|
};
|
|
32
|
-
type
|
|
108
|
+
type FinallyDone<State> = Done<State> & {
|
|
33
109
|
status: 'done';
|
|
34
|
-
}
|
|
110
|
+
};
|
|
111
|
+
type FinallyFail<Err> = Fail<Err> & {
|
|
35
112
|
status: 'fail';
|
|
36
|
-
}
|
|
113
|
+
};
|
|
114
|
+
type Finally<State, Err> = FinallyDone<State> | FinallyFail<Err>;
|
|
37
115
|
interface ConfigPersist$1 {
|
|
38
116
|
pickup?: Unit<any> | Unit<any>[];
|
|
39
117
|
context?: Unit<any>;
|
|
@@ -42,9 +120,9 @@ interface ConfigPersist$1 {
|
|
|
42
120
|
}
|
|
43
121
|
interface ConfigCommon<State, Err = Error> {
|
|
44
122
|
clock?: Unit<any>;
|
|
45
|
-
done?:
|
|
46
|
-
fail?:
|
|
47
|
-
finally?:
|
|
123
|
+
done?: UnitTargetable<Done<State>>;
|
|
124
|
+
fail?: UnitTargetable<Fail<Err>>;
|
|
125
|
+
finally?: UnitTargetable<Finally<State, Err>>;
|
|
48
126
|
pickup?: Unit<any> | Unit<any>[];
|
|
49
127
|
context?: Unit<any>;
|
|
50
128
|
key?: string;
|
|
@@ -52,11 +130,11 @@ interface ConfigCommon<State, Err = Error> {
|
|
|
52
130
|
contract?: Contract<State | undefined>;
|
|
53
131
|
}
|
|
54
132
|
interface ConfigJustStore<State> {
|
|
55
|
-
store:
|
|
133
|
+
store: StoreWritable<State>;
|
|
56
134
|
}
|
|
57
135
|
interface ConfigJustSourceTarget<State> {
|
|
58
136
|
source: Store<State> | Event<State> | Effect<State, any, any>;
|
|
59
|
-
target:
|
|
137
|
+
target: StoreWritable<State> | EventCallable<State> | Effect<State, any, any>;
|
|
60
138
|
}
|
|
61
139
|
interface ConfigStore$1<State, Err = Error> extends ConfigCommon<State, Err>, ConfigJustStore<State> {
|
|
62
140
|
}
|
|
@@ -82,18 +160,19 @@ interface Persist {
|
|
|
82
160
|
<State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription;
|
|
83
161
|
<State, Err = Error>(config: ConfigStore<State, Err>): Subscription;
|
|
84
162
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Creates `localStorage` adapter
|
|
165
|
+
*/
|
|
166
|
+
declare const local: StorageAdapterFactory<LocalStorageConfig | undefined | void>;
|
|
89
167
|
/**
|
|
90
168
|
* Creates custom partially applied `persist`
|
|
91
169
|
* with predefined `localStorage` adapter
|
|
92
170
|
*/
|
|
93
|
-
declare
|
|
171
|
+
declare const createPersist: (defaults?: ConfigPersist) => Persist;
|
|
94
172
|
/**
|
|
95
173
|
* Default partially applied `persist`
|
|
96
174
|
*/
|
|
97
175
|
declare const persist: Persist;
|
|
98
176
|
|
|
99
|
-
export {
|
|
177
|
+
export { createPersist, local, persist };
|
|
178
|
+
export type { Adapter, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, LocalStorageConfig, Persist, StorageAdapter, StorageAdapterFactory };
|
package/local/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{persist as r}from"../core/index.js";import{nil as
|
|
1
|
+
import{persist as r}from"../core/index.js";import{nil as e}from"../nil/index.js";import{storage as o}from"../storage/index.js";var t=r=>(()=>{try{return"undefined"!=typeof localStorage}catch(r){return!0}})()?o({storage:()=>localStorage,sync:!0,...r}):e({keyArea:"local"});t.factory=!0;var a=e=>o=>r({adapter:t,...e,...o}),i=/*#__PURE__*/a();export{a as createPersist,t as local,i as persist};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/local/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/local/index.ts"],"sourcesContent":["import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/local/index.ts"],"sourcesContent":["import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigSourceTarget as BaseConfigSourceTarget,\n ConfigStore as BaseConfigStore,\n StorageAdapterFactory,\n} from '../types'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { storage } from '../storage'\n\nexport type {\n Adapter,\n Contract,\n DisposableAdapter,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n sync?: boolean | 'force'\n timeout?: number\n}\n\nexport interface LocalStorageConfig {\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends LocalStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends LocalStorageConfig,\n BaseConfigSourceTarget<State, Err> {}\n\nexport interface Persist {\n <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription\n <State, Err = Error>(config: ConfigStore<State, Err>): Subscription\n}\n\n/**\n * Function, checking if `localStorage` exists\n */\nconst supports = () => {\n try {\n return typeof localStorage !== 'undefined'\n } catch (_error) {\n // accessing `localStorage` could throw an exception only in one case -\n // when `localStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `localStorage` adapter\n */\nexport const local: StorageAdapterFactory<\n LocalStorageConfig | undefined | void\n> = (config) => {\n return supports()\n ? storage({\n storage: () => localStorage,\n sync: true,\n ...config,\n })\n : nil({ keyArea: 'local' })\n}\n\n// mark as factory\nlocal.factory = true\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `localStorage` adapter\n */\nexport const createPersist =\n (defaults?: ConfigPersist): Persist =>\n (config) =>\n base({\n adapter: local,\n ...defaults,\n ...config,\n })\n\n/**\n * Default partially applied `persist`\n */\nexport const persist: Persist = /*#__PURE__*/ createPersist()\n"],"names":["local","config","supports","localStorage","_error","storage","sync","nil","keyArea","factory","createPersist","defaults","base","adapter","persist"],"mappings":"+HAmDA,IAaaA,EAERC,GAfYC,MACf,IACE,MAA+B,oBAAjBC,YAChB,CAAE,MAAOC,GAGP,OAAO,CACT,GASOF,GACHG,EAAQ,CACNA,QAASA,IAAMF,aACfG,MAAM,KACHL,IAELM,EAAI,CAAEC,QAAS,UAIrBR,EAAMS,SAAU,EAMT,IAAMC,EACVC,GACAV,GACCW,EAAK,CACHC,QAASb,KACNW,KACAV,IAMIa,eAAiCJ"}
|
package/log/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";var e=({keyArea:e="",logger:r=console.log}={})=>{var o=e=>({set(o){r(`[log adapter] set value "${o}" with key "${e}"`)},get(){r(`[log adapter] get value for key "${e}"`)}});return o.keyArea=e,o.noop=!0,o};e.factory=!0,exports.log=e;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/log/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/log/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface LogConfig {\n keyArea?: any\n logger?: (msg: string) => void\n}\n\n/**\n * Log adapter\n * Does nothing, like `nil` adapter, but print messages\n */\
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/log/index.ts"],"sourcesContent":["import type { StorageAdapter, StorageAdapterFactory } from '../types'\n\nexport interface LogConfig {\n keyArea?: any\n logger?: (msg: string) => void\n}\n\n/**\n * Log adapter\n * Does nothing, like `nil` adapter, but print messages\n */\nexport const log: StorageAdapterFactory<LogConfig | undefined | void> = ({\n keyArea = '',\n logger = console.log,\n} = {}) => {\n const adapter: StorageAdapter = (key: string) =>\n ({\n set(value: any) {\n logger(`[log adapter] set value \"${value}\" with key \"${key}\"`)\n },\n get() {\n logger(`[log adapter] get value for key \"${key}\"`)\n },\n }) as any\n\n adapter.keyArea = keyArea\n adapter.noop = true\n return adapter\n}\n\n// mark as factory\nlog.factory = true\n"],"names":["log","keyArea","logger","console","adapter","key","set","value","get","noop","factory"],"mappings":"aAWO,IAAMA,EAA2DA,EACtEC,UAAU,GACVC,SAASC,QAAQH,KACf,MACF,IAAMI,EAA2BC,IAAW,CAExCC,GAAAA,CAAIC,GACFL,EAAO,4BAA4BK,gBAAoBF,KACzD,EACAG,GAAAA,GACEN,EAAO,oCAAoCG,KAC7C,IAKJ,OAFAD,EAAQH,QAAUA,EAClBG,EAAQK,MAAO,EACRL,GAITJ,EAAIU,SAAU"}
|
package/log/index.d.cts
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
|
+
interface Adapter<State> {
|
|
2
|
+
get(this: void, //
|
|
3
|
+
raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
|
|
4
|
+
set(this: void, //
|
|
5
|
+
value: State, ctx?: any): void | Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
interface DisposableAdapter<State> extends Adapter<State> {
|
|
8
|
+
(): void;
|
|
9
|
+
}
|
|
1
10
|
interface StorageAdapter {
|
|
2
|
-
<State>(key: string, update: (raw?: any) => void):
|
|
3
|
-
get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
|
|
4
|
-
set(value: State, ctx?: any): void;
|
|
5
|
-
};
|
|
11
|
+
<State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
|
|
6
12
|
keyArea?: any;
|
|
7
13
|
noop?: boolean;
|
|
8
14
|
}
|
|
15
|
+
interface StorageAdapterFactory<AdapterConfig> {
|
|
16
|
+
(config: AdapterConfig): StorageAdapter;
|
|
17
|
+
factory: true;
|
|
18
|
+
}
|
|
9
19
|
|
|
10
20
|
interface LogConfig {
|
|
11
21
|
keyArea?: any;
|
|
12
22
|
logger?: (msg: string) => void;
|
|
13
23
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Log adapter
|
|
26
|
+
* Does nothing, like `nil` adapter, but print messages
|
|
27
|
+
*/
|
|
28
|
+
declare const log: StorageAdapterFactory<LogConfig | undefined | void>;
|
|
18
29
|
|
|
19
|
-
export {
|
|
30
|
+
export { log };
|
|
31
|
+
export type { LogConfig };
|
package/log/index.d.ts
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
|
+
interface Adapter<State> {
|
|
2
|
+
get(this: void, //
|
|
3
|
+
raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
|
|
4
|
+
set(this: void, //
|
|
5
|
+
value: State, ctx?: any): void | Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
interface DisposableAdapter<State> extends Adapter<State> {
|
|
8
|
+
(): void;
|
|
9
|
+
}
|
|
1
10
|
interface StorageAdapter {
|
|
2
|
-
<State>(key: string, update: (raw?: any) => void):
|
|
3
|
-
get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
|
|
4
|
-
set(value: State, ctx?: any): void;
|
|
5
|
-
};
|
|
11
|
+
<State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
|
|
6
12
|
keyArea?: any;
|
|
7
13
|
noop?: boolean;
|
|
8
14
|
}
|
|
15
|
+
interface StorageAdapterFactory<AdapterConfig> {
|
|
16
|
+
(config: AdapterConfig): StorageAdapter;
|
|
17
|
+
factory: true;
|
|
18
|
+
}
|
|
9
19
|
|
|
10
20
|
interface LogConfig {
|
|
11
21
|
keyArea?: any;
|
|
12
22
|
logger?: (msg: string) => void;
|
|
13
23
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Log adapter
|
|
26
|
+
* Does nothing, like `nil` adapter, but print messages
|
|
27
|
+
*/
|
|
28
|
+
declare const log: StorageAdapterFactory<LogConfig | undefined | void>;
|
|
18
29
|
|
|
19
|
-
export {
|
|
30
|
+
export { log };
|
|
31
|
+
export type { LogConfig };
|
package/log/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var e=({keyArea:e="",logger:r=console.log}={})=>{var a=e=>({set(a){r(`[log adapter] set value "${a}" with key "${e}"`)},get(){r(`[log adapter] get value for key "${e}"`)}});return a.keyArea=e,a.noop=!0,a};e.factory=!0;export{e as log};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/log/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/log/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface LogConfig {\n keyArea?: any\n logger?: (msg: string) => void\n}\n\n/**\n * Log adapter\n * Does nothing, like `nil` adapter, but print messages\n */\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/log/index.ts"],"sourcesContent":["import type { StorageAdapter, StorageAdapterFactory } from '../types'\n\nexport interface LogConfig {\n keyArea?: any\n logger?: (msg: string) => void\n}\n\n/**\n * Log adapter\n * Does nothing, like `nil` adapter, but print messages\n */\nexport const log: StorageAdapterFactory<LogConfig | undefined | void> = ({\n keyArea = '',\n logger = console.log,\n} = {}) => {\n const adapter: StorageAdapter = (key: string) =>\n ({\n set(value: any) {\n logger(`[log adapter] set value \"${value}\" with key \"${key}\"`)\n },\n get() {\n logger(`[log adapter] get value for key \"${key}\"`)\n },\n }) as any\n\n adapter.keyArea = keyArea\n adapter.noop = true\n return adapter\n}\n\n// mark as factory\nlog.factory = true\n"],"names":["log","keyArea","logger","console","adapter","key","set","value","get","noop","factory"],"mappings":"AAWO,IAAMA,EAA2DA,EACtEC,UAAU,GACVC,SAASC,QAAQH,KACf,MACF,IAAMI,EAA2BC,IAAW,CAExCC,GAAAA,CAAIC,GACFL,EAAO,4BAA4BK,gBAAoBF,KACzD,EACAG,GAAAA,GACEN,EAAO,oCAAoCG,KAC7C,IAKJ,OAFAD,EAAQH,QAAUA,EAClBG,EAAQK,MAAO,EACRL,GAITJ,EAAIU,SAAU"}
|
package/memory/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../core/index.cjs"),r=new Map
|
|
1
|
+
"use strict";var e=require("../core/index.cjs"),r=new Map,t=({area:e=r}={})=>{var t=r=>({get:()=>e.get(r),set:t=>{e.set(r,t)}});return t.keyArea=e,t};t.factory=!0;var s=r=>s=>e.persist({adapter:t(),...r,...s}),a=/*#__PURE__*/s();exports.createPersist=s,exports.memory=t,exports.persist=a;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/memory/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/memory/adapter.ts","../../src/memory/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nconst data = new Map<string, any>()\n\nexport interface MemoryConfig {\n area?: Map<string, any>\n}\n\n/**\n * Memory adapter\n */\
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/memory/adapter.ts","../../src/memory/index.ts"],"sourcesContent":["import type { StorageAdapter, StorageAdapterFactory } from '../types'\n\nconst data = new Map<string, any>()\n\nexport interface MemoryConfig {\n area?: Map<string, any>\n}\n\n/**\n * Memory adapter\n */\nexport const adapter: StorageAdapterFactory<\n MemoryConfig | undefined | void\n> = ({ area = data } = {}) => {\n const adapter: StorageAdapter = <State>(key: string) => ({\n get: () => area.get(key),\n set: (value: State) => void area.set(key, value),\n })\n\n adapter.keyArea = area\n return adapter\n}\n\n// mark as factory\nadapter.factory = true\n","import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigSourceTarget as BaseConfigSourceTarget,\n ConfigStore as BaseConfigStore,\n} from '../types'\nimport { persist as base } from '../core'\nimport { adapter } from './adapter'\n\nexport type {\n Adapter,\n Contract,\n DisposableAdapter,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\nexport type { MemoryConfig } from './adapter'\n\nexport interface ConfigPersist extends BaseConfigPersist {}\n\nexport interface ConfigStore<State, Err = Error>\n extends BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends BaseConfigSourceTarget<State, Err> {}\n\nexport interface Persist {\n <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription\n <State, Err = Error>(config: ConfigStore<State, Err>): Subscription\n}\n\n/**\n * Returns memory adapter\n */\nexport { adapter as memory }\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `memory` adapter\n */\nexport const createPersist =\n (defaults?: ConfigPersist): Persist =>\n (config) =>\n base({\n adapter: adapter(),\n ...defaults,\n ...config,\n })\n\n/**\n * Default partially applied `persist`\n */\nexport const persist: Persist = /*#__PURE__*/ createPersist()\n"],"names":["data","Map","adapter","area","key","get","set","value","keyArea","factory","createPersist","defaults","config","base","persist"],"mappings":"gDAEMA,EAAO,IAAIC,IASJC,EAETA,EAAGC,OAAOH,GAAS,MACrB,IAAME,EAAkCE,IAAW,CACjDC,IAAKA,IAAMF,EAAKE,IAAID,GACpBE,IAAMC,IAAsBJ,EAAKG,IAAIF,EAAKG,MAI5C,OADAL,EAAQM,QAAUL,EACXD,GAITA,EAAQO,SAAU,ECmBX,IAAMC,EACVC,GACAC,GACCC,UAAK,CACHX,QAASA,OACNS,KACAC,IAMIE,eAAiCJ"}
|
package/memory/index.d.cts
CHANGED
|
@@ -1,21 +1,97 @@
|
|
|
1
|
-
import { Unit, Store, Event, Effect, Subscription } from 'effector';
|
|
1
|
+
import { Unit, UnitTargetable, Store, Event, Effect, StoreWritable, EventCallable, Subscription } from 'effector';
|
|
2
2
|
|
|
3
|
+
/** The Contract interface. */
|
|
4
|
+
interface Contract$1<Raw, Data extends Raw> {
|
|
5
|
+
/**
|
|
6
|
+
* Checks if Raw is Data
|
|
7
|
+
*/
|
|
8
|
+
isData: (prepared: Raw) => prepared is Data;
|
|
9
|
+
/**
|
|
10
|
+
* - empty array is dedicated for valid response
|
|
11
|
+
* - array of string with validation erorrs for invalidDataError
|
|
12
|
+
*/
|
|
13
|
+
getErrorMessages: (prepared: Raw) => string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The Standard Schema interface. */
|
|
17
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
18
|
+
/** The Standard Schema properties. */
|
|
19
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
20
|
+
}
|
|
21
|
+
declare namespace StandardSchemaV1 {
|
|
22
|
+
/** The Standard Schema properties interface. */
|
|
23
|
+
interface Props<Input = unknown, Output = Input> {
|
|
24
|
+
/** The version number of the standard. */
|
|
25
|
+
readonly version: 1;
|
|
26
|
+
/** The vendor name of the schema library. */
|
|
27
|
+
readonly vendor: string;
|
|
28
|
+
/** Validates unknown input values. */
|
|
29
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
30
|
+
/** Inferred types associated with the schema. */
|
|
31
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** The result interface of the validate function. */
|
|
34
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
35
|
+
/** The result interface if validation succeeds. */
|
|
36
|
+
interface SuccessResult<Output> {
|
|
37
|
+
/** The typed output value. */
|
|
38
|
+
readonly value: Output;
|
|
39
|
+
/** A falsy value for `issues` indicates success. */
|
|
40
|
+
readonly issues?: undefined;
|
|
41
|
+
}
|
|
42
|
+
interface Options {
|
|
43
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
44
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
45
|
+
}
|
|
46
|
+
/** The result interface if validation fails. */
|
|
47
|
+
interface FailureResult {
|
|
48
|
+
/** The issues of failed validation. */
|
|
49
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
50
|
+
}
|
|
51
|
+
/** The issue interface of the failure output. */
|
|
52
|
+
interface Issue {
|
|
53
|
+
/** The error message of the issue. */
|
|
54
|
+
readonly message: string;
|
|
55
|
+
/** The path of the issue, if any. */
|
|
56
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
57
|
+
}
|
|
58
|
+
/** The path segment interface of the issue. */
|
|
59
|
+
interface PathSegment {
|
|
60
|
+
/** The key representing a path segment. */
|
|
61
|
+
readonly key: PropertyKey;
|
|
62
|
+
}
|
|
63
|
+
/** The Standard Schema types interface. */
|
|
64
|
+
interface Types<Input = unknown, Output = Input> {
|
|
65
|
+
/** The input type of the schema. */
|
|
66
|
+
readonly input: Input;
|
|
67
|
+
/** The output type of the schema. */
|
|
68
|
+
readonly output: Output;
|
|
69
|
+
}
|
|
70
|
+
/** Infers the input type of a Standard Schema. */
|
|
71
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
72
|
+
/** Infers the output type of a Standard Schema. */
|
|
73
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface Adapter<State> {
|
|
77
|
+
get(this: void, //
|
|
78
|
+
raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
|
|
79
|
+
set(this: void, //
|
|
80
|
+
value: State, ctx?: any): void | Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
interface DisposableAdapter<State> extends Adapter<State> {
|
|
83
|
+
(): void;
|
|
84
|
+
}
|
|
3
85
|
interface StorageAdapter {
|
|
4
|
-
<State>(key: string, update: (raw?: any) => void):
|
|
5
|
-
get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
|
|
6
|
-
set(value: State, ctx?: any): void;
|
|
7
|
-
};
|
|
86
|
+
<State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
|
|
8
87
|
keyArea?: any;
|
|
9
88
|
noop?: boolean;
|
|
10
89
|
}
|
|
11
90
|
interface StorageAdapterFactory<AdapterConfig> {
|
|
12
|
-
(config
|
|
91
|
+
(config: AdapterConfig): StorageAdapter;
|
|
13
92
|
factory: true;
|
|
14
93
|
}
|
|
15
|
-
type Contract<Data> = ((raw: unknown) => raw is Data) |
|
|
16
|
-
isData: (raw: unknown) => raw is Data;
|
|
17
|
-
getErrorMessages: (raw: unknown) => string[];
|
|
18
|
-
};
|
|
94
|
+
type Contract<Data> = ((raw: unknown) => raw is Data) | StandardSchemaV1<unknown, Data> | Contract$1<unknown, Data>;
|
|
19
95
|
type Done<State> = {
|
|
20
96
|
key: string;
|
|
21
97
|
keyPrefix: string;
|
|
@@ -29,11 +105,13 @@ type Fail<Err> = {
|
|
|
29
105
|
error: Err;
|
|
30
106
|
value?: any;
|
|
31
107
|
};
|
|
32
|
-
type
|
|
108
|
+
type FinallyDone<State> = Done<State> & {
|
|
33
109
|
status: 'done';
|
|
34
|
-
}
|
|
110
|
+
};
|
|
111
|
+
type FinallyFail<Err> = Fail<Err> & {
|
|
35
112
|
status: 'fail';
|
|
36
|
-
}
|
|
113
|
+
};
|
|
114
|
+
type Finally<State, Err> = FinallyDone<State> | FinallyFail<Err>;
|
|
37
115
|
interface ConfigPersist$1 {
|
|
38
116
|
pickup?: Unit<any> | Unit<any>[];
|
|
39
117
|
context?: Unit<any>;
|
|
@@ -42,9 +120,9 @@ interface ConfigPersist$1 {
|
|
|
42
120
|
}
|
|
43
121
|
interface ConfigCommon<State, Err = Error> {
|
|
44
122
|
clock?: Unit<any>;
|
|
45
|
-
done?:
|
|
46
|
-
fail?:
|
|
47
|
-
finally?:
|
|
123
|
+
done?: UnitTargetable<Done<State>>;
|
|
124
|
+
fail?: UnitTargetable<Fail<Err>>;
|
|
125
|
+
finally?: UnitTargetable<Finally<State, Err>>;
|
|
48
126
|
pickup?: Unit<any> | Unit<any>[];
|
|
49
127
|
context?: Unit<any>;
|
|
50
128
|
key?: string;
|
|
@@ -52,11 +130,11 @@ interface ConfigCommon<State, Err = Error> {
|
|
|
52
130
|
contract?: Contract<State | undefined>;
|
|
53
131
|
}
|
|
54
132
|
interface ConfigJustStore<State> {
|
|
55
|
-
store:
|
|
133
|
+
store: StoreWritable<State>;
|
|
56
134
|
}
|
|
57
135
|
interface ConfigJustSourceTarget<State> {
|
|
58
136
|
source: Store<State> | Event<State> | Effect<State, any, any>;
|
|
59
|
-
target:
|
|
137
|
+
target: StoreWritable<State> | EventCallable<State> | Effect<State, any, any>;
|
|
60
138
|
}
|
|
61
139
|
interface ConfigStore$1<State, Err = Error> extends ConfigCommon<State, Err>, ConfigJustStore<State> {
|
|
62
140
|
}
|
|
@@ -66,10 +144,10 @@ interface ConfigSourceTarget$1<State, Err = Error> extends ConfigCommon<State, E
|
|
|
66
144
|
interface MemoryConfig {
|
|
67
145
|
area?: Map<string, any>;
|
|
68
146
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Memory adapter
|
|
149
|
+
*/
|
|
150
|
+
declare const adapter: StorageAdapterFactory<MemoryConfig | undefined | void>;
|
|
73
151
|
|
|
74
152
|
interface ConfigPersist extends ConfigPersist$1 {
|
|
75
153
|
}
|
|
@@ -86,10 +164,11 @@ interface Persist {
|
|
|
86
164
|
* Creates custom partially applied `persist`
|
|
87
165
|
* with predefined `memory` adapter
|
|
88
166
|
*/
|
|
89
|
-
declare
|
|
167
|
+
declare const createPersist: (defaults?: ConfigPersist) => Persist;
|
|
90
168
|
/**
|
|
91
169
|
* Default partially applied `persist`
|
|
92
170
|
*/
|
|
93
171
|
declare const persist: Persist;
|
|
94
172
|
|
|
95
|
-
export {
|
|
173
|
+
export { createPersist, adapter as memory, persist };
|
|
174
|
+
export type { Adapter, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, MemoryConfig, Persist, StorageAdapter, StorageAdapterFactory };
|