effector-storage 7.1.0 → 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.
Files changed (88) hide show
  1. package/README.md +12 -9
  2. package/async-storage/index.cjs +1 -1
  3. package/async-storage/index.cjs.map +1 -1
  4. package/async-storage/index.d.cts +20 -9
  5. package/async-storage/index.d.ts +20 -9
  6. package/async-storage/index.js +1 -1
  7. package/async-storage/index.js.map +1 -1
  8. package/broadcast/index.cjs +1 -1
  9. package/broadcast/index.cjs.map +1 -1
  10. package/broadcast/index.d.cts +105 -26
  11. package/broadcast/index.d.ts +105 -26
  12. package/broadcast/index.js +1 -1
  13. package/broadcast/index.js.map +1 -1
  14. package/core/index.cjs +1 -1
  15. package/core/index.cjs.map +1 -1
  16. package/core/index.d.cts +99 -21
  17. package/core/index.d.ts +99 -21
  18. package/core/index.js +1 -1
  19. package/core/index.js.map +1 -1
  20. package/core/package.json +3 -0
  21. package/index.cjs +1 -1
  22. package/index.cjs.map +1 -1
  23. package/index.d.cts +101 -22
  24. package/index.d.ts +101 -22
  25. package/index.js +1 -1
  26. package/index.js.map +1 -1
  27. package/local/index.cjs +1 -1
  28. package/local/index.cjs.map +1 -1
  29. package/local/index.d.cts +105 -26
  30. package/local/index.d.ts +105 -26
  31. package/local/index.js +1 -1
  32. package/local/index.js.map +1 -1
  33. package/log/index.cjs +1 -1
  34. package/log/index.cjs.map +1 -1
  35. package/log/index.d.cts +21 -9
  36. package/log/index.d.ts +21 -9
  37. package/log/index.js +1 -1
  38. package/log/index.js.map +1 -1
  39. package/memory/index.cjs +1 -1
  40. package/memory/index.cjs.map +1 -1
  41. package/memory/index.d.cts +105 -26
  42. package/memory/index.d.ts +105 -26
  43. package/memory/index.js +1 -1
  44. package/memory/index.js.map +1 -1
  45. package/nil/index.cjs +1 -1
  46. package/nil/index.cjs.map +1 -1
  47. package/nil/index.d.cts +20 -9
  48. package/nil/index.d.ts +20 -9
  49. package/nil/index.js +1 -1
  50. package/nil/index.js.map +1 -1
  51. package/package.json +3 -3
  52. package/query/index.cjs +1 -1
  53. package/query/index.cjs.map +1 -1
  54. package/query/index.d.cts +105 -26
  55. package/query/index.d.ts +105 -26
  56. package/query/index.js +1 -1
  57. package/query/index.js.map +1 -1
  58. package/session/index.cjs +1 -1
  59. package/session/index.cjs.map +1 -1
  60. package/session/index.d.cts +105 -26
  61. package/session/index.d.ts +105 -26
  62. package/session/index.js +1 -1
  63. package/session/index.js.map +1 -1
  64. package/storage/index.cjs +1 -1
  65. package/storage/index.cjs.map +1 -1
  66. package/storage/index.d.cts +20 -9
  67. package/storage/index.d.ts +20 -9
  68. package/storage/index.js +1 -1
  69. package/storage/index.js.map +1 -1
  70. package/tools/index.cjs +1 -1
  71. package/tools/index.cjs.map +1 -1
  72. package/tools/index.d.cts +18 -9
  73. package/tools/index.d.ts +18 -9
  74. package/tools/index.js +1 -1
  75. package/tools/index.js.map +1 -1
  76. package/tools/package.json +3 -0
  77. package/async-storage/index.js.flow +0 -37
  78. package/broadcast/index.js.flow +0 -132
  79. package/core/index.js.flow +0 -113
  80. package/index.js.flow +0 -146
  81. package/local/index.js.flow +0 -140
  82. package/log/index.js.flow +0 -32
  83. package/memory/index.js.flow +0 -133
  84. package/nil/index.js.flow +0 -31
  85. package/query/index.js.flow +0 -159
  86. package/session/index.js.flow +0 -140
  87. package/storage/index.js.flow +0 -36
  88. package/tools/index.js.flow +0 -104
package/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Unit, Subscription, Store, Event, Effect } from 'effector';
1
+ import { Unit, UnitTargetable, Store, Event, Effect, StoreWritable, EventCallable, Subscription } from 'effector';
2
2
  export { AsyncStorageConfig, asyncStorage } from './async-storage';
3
3
  export { BroadcastConfig, broadcast } from './broadcast';
4
4
  export { LocalStorageConfig, local } from './local';
@@ -10,22 +10,98 @@ export { SessionStorageConfig, session } from './session';
10
10
  export { StorageConfig, storage } from './storage';
11
11
  export { async, either, farcached } from './tools';
12
12
 
13
+ /** The Contract interface. */
14
+ interface Contract$1<Raw, Data extends Raw> {
15
+ /**
16
+ * Checks if Raw is Data
17
+ */
18
+ isData: (prepared: Raw) => prepared is Data;
19
+ /**
20
+ * - empty array is dedicated for valid response
21
+ * - array of string with validation erorrs for invalidDataError
22
+ */
23
+ getErrorMessages: (prepared: Raw) => string[];
24
+ }
25
+
26
+ /** The Standard Schema interface. */
27
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
28
+ /** The Standard Schema properties. */
29
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
30
+ }
31
+ declare namespace StandardSchemaV1 {
32
+ /** The Standard Schema properties interface. */
33
+ interface Props<Input = unknown, Output = Input> {
34
+ /** The version number of the standard. */
35
+ readonly version: 1;
36
+ /** The vendor name of the schema library. */
37
+ readonly vendor: string;
38
+ /** Validates unknown input values. */
39
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
40
+ /** Inferred types associated with the schema. */
41
+ readonly types?: Types<Input, Output> | undefined;
42
+ }
43
+ /** The result interface of the validate function. */
44
+ type Result<Output> = SuccessResult<Output> | FailureResult;
45
+ /** The result interface if validation succeeds. */
46
+ interface SuccessResult<Output> {
47
+ /** The typed output value. */
48
+ readonly value: Output;
49
+ /** A falsy value for `issues` indicates success. */
50
+ readonly issues?: undefined;
51
+ }
52
+ interface Options {
53
+ /** Explicit support for additional vendor-specific parameters, if needed. */
54
+ readonly libraryOptions?: Record<string, unknown> | undefined;
55
+ }
56
+ /** The result interface if validation fails. */
57
+ interface FailureResult {
58
+ /** The issues of failed validation. */
59
+ readonly issues: ReadonlyArray<Issue>;
60
+ }
61
+ /** The issue interface of the failure output. */
62
+ interface Issue {
63
+ /** The error message of the issue. */
64
+ readonly message: string;
65
+ /** The path of the issue, if any. */
66
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
67
+ }
68
+ /** The path segment interface of the issue. */
69
+ interface PathSegment {
70
+ /** The key representing a path segment. */
71
+ readonly key: PropertyKey;
72
+ }
73
+ /** The Standard Schema types interface. */
74
+ interface Types<Input = unknown, Output = Input> {
75
+ /** The input type of the schema. */
76
+ readonly input: Input;
77
+ /** The output type of the schema. */
78
+ readonly output: Output;
79
+ }
80
+ /** Infers the input type of a Standard Schema. */
81
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
82
+ /** Infers the output type of a Standard Schema. */
83
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
84
+ }
85
+
86
+ interface Adapter<State> {
87
+ get(this: void, //
88
+ raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
89
+ set(this: void, //
90
+ value: State, ctx?: any): void | Promise<void>;
91
+ }
92
+ interface DisposableAdapter<State> extends Adapter<State> {
93
+ (): void;
94
+ }
13
95
  interface StorageAdapter {
14
- <State>(key: string, update: (raw?: any) => void): {
15
- get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
16
- set(value: State, ctx?: any): void;
17
- };
96
+ <State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
18
97
  keyArea?: any;
19
98
  noop?: boolean;
20
99
  }
21
100
  interface StorageAdapterFactory<AdapterConfig> {
22
- (config?: AdapterConfig): StorageAdapter;
101
+ (config: AdapterConfig): StorageAdapter;
23
102
  factory: true;
24
103
  }
25
- type Contract<Data> = ((raw: unknown) => raw is Data) | {
26
- isData: (raw: unknown) => raw is Data;
27
- getErrorMessages: (raw: unknown) => string[];
28
- };
104
+ type Contract<Data> = ((raw: unknown) => raw is Data) | StandardSchemaV1<unknown, Data> | Contract$1<unknown, Data>;
29
105
  type Done<State> = {
30
106
  key: string;
31
107
  keyPrefix: string;
@@ -39,13 +115,15 @@ type Fail<Err> = {
39
115
  error: Err;
40
116
  value?: any;
41
117
  };
42
- type Finally<State, Err> = (Done<State> & {
118
+ type FinallyDone<State> = Done<State> & {
43
119
  status: 'done';
44
- }) | (Fail<Err> & {
120
+ };
121
+ type FinallyFail<Err> = Fail<Err> & {
45
122
  status: 'fail';
46
- });
123
+ };
124
+ type Finally<State, Err> = FinallyDone<State> | FinallyFail<Err>;
47
125
  interface ConfigPersist {
48
- pickup?: Unit<any>;
126
+ pickup?: Unit<any> | Unit<any>[];
49
127
  context?: Unit<any>;
50
128
  keyPrefix?: string;
51
129
  contract?: Contract<any>;
@@ -58,21 +136,21 @@ interface ConfigAdapterFactory<AdapterConfig> {
58
136
  }
59
137
  interface ConfigCommon<State, Err = Error> {
60
138
  clock?: Unit<any>;
61
- done?: Unit<Done<State>>;
62
- fail?: Unit<Fail<Err>>;
63
- finally?: Unit<Finally<State, Err>>;
64
- pickup?: Unit<any>;
139
+ done?: UnitTargetable<Done<State>>;
140
+ fail?: UnitTargetable<Fail<Err>>;
141
+ finally?: UnitTargetable<Finally<State, Err>>;
142
+ pickup?: Unit<any> | Unit<any>[];
65
143
  context?: Unit<any>;
66
144
  key?: string;
67
145
  keyPrefix?: string;
68
146
  contract?: Contract<State | undefined>;
69
147
  }
70
148
  interface ConfigJustStore<State> {
71
- store: Store<State>;
149
+ store: StoreWritable<State>;
72
150
  }
73
151
  interface ConfigJustSourceTarget<State> {
74
152
  source: Store<State> | Event<State> | Effect<State, any, any>;
75
- target: Store<State> | Event<State> | Effect<State, any, any>;
153
+ target: StoreWritable<State> | EventCallable<State> | Effect<State, any, any>;
76
154
  }
77
155
  interface ConfigStore<State, Err = Error> extends ConfigCommon<State, Err>, ConfigJustStore<State> {
78
156
  }
@@ -88,10 +166,11 @@ interface Persist {
88
166
  /**
89
167
  * Creates custom `persist`
90
168
  */
91
- declare function createPersist(defaults?: ConfigPersist): Persist;
169
+ declare const createPersist: (defaults?: ConfigPersist) => Persist;
92
170
  /**
93
171
  * Default `persist`
94
172
  */
95
173
  declare const persist: Persist;
96
174
 
97
- export { type ConfigPersist, type ConfigSourceTarget, type ConfigStore, type Contract, type Done, type Fail, type Finally, type Persist, type StorageAdapter, type StorageAdapterFactory, createPersist, persist };
175
+ export { createPersist, persist };
176
+ export type { Adapter, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, Persist, StorageAdapter, StorageAdapterFactory };
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Unit, Subscription, Store, Event, Effect } from 'effector';
1
+ import { Unit, UnitTargetable, Store, Event, Effect, StoreWritable, EventCallable, Subscription } from 'effector';
2
2
  export { AsyncStorageConfig, asyncStorage } from './async-storage';
3
3
  export { BroadcastConfig, broadcast } from './broadcast';
4
4
  export { LocalStorageConfig, local } from './local';
@@ -10,22 +10,98 @@ export { SessionStorageConfig, session } from './session';
10
10
  export { StorageConfig, storage } from './storage';
11
11
  export { async, either, farcached } from './tools';
12
12
 
13
+ /** The Contract interface. */
14
+ interface Contract$1<Raw, Data extends Raw> {
15
+ /**
16
+ * Checks if Raw is Data
17
+ */
18
+ isData: (prepared: Raw) => prepared is Data;
19
+ /**
20
+ * - empty array is dedicated for valid response
21
+ * - array of string with validation erorrs for invalidDataError
22
+ */
23
+ getErrorMessages: (prepared: Raw) => string[];
24
+ }
25
+
26
+ /** The Standard Schema interface. */
27
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
28
+ /** The Standard Schema properties. */
29
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
30
+ }
31
+ declare namespace StandardSchemaV1 {
32
+ /** The Standard Schema properties interface. */
33
+ interface Props<Input = unknown, Output = Input> {
34
+ /** The version number of the standard. */
35
+ readonly version: 1;
36
+ /** The vendor name of the schema library. */
37
+ readonly vendor: string;
38
+ /** Validates unknown input values. */
39
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
40
+ /** Inferred types associated with the schema. */
41
+ readonly types?: Types<Input, Output> | undefined;
42
+ }
43
+ /** The result interface of the validate function. */
44
+ type Result<Output> = SuccessResult<Output> | FailureResult;
45
+ /** The result interface if validation succeeds. */
46
+ interface SuccessResult<Output> {
47
+ /** The typed output value. */
48
+ readonly value: Output;
49
+ /** A falsy value for `issues` indicates success. */
50
+ readonly issues?: undefined;
51
+ }
52
+ interface Options {
53
+ /** Explicit support for additional vendor-specific parameters, if needed. */
54
+ readonly libraryOptions?: Record<string, unknown> | undefined;
55
+ }
56
+ /** The result interface if validation fails. */
57
+ interface FailureResult {
58
+ /** The issues of failed validation. */
59
+ readonly issues: ReadonlyArray<Issue>;
60
+ }
61
+ /** The issue interface of the failure output. */
62
+ interface Issue {
63
+ /** The error message of the issue. */
64
+ readonly message: string;
65
+ /** The path of the issue, if any. */
66
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
67
+ }
68
+ /** The path segment interface of the issue. */
69
+ interface PathSegment {
70
+ /** The key representing a path segment. */
71
+ readonly key: PropertyKey;
72
+ }
73
+ /** The Standard Schema types interface. */
74
+ interface Types<Input = unknown, Output = Input> {
75
+ /** The input type of the schema. */
76
+ readonly input: Input;
77
+ /** The output type of the schema. */
78
+ readonly output: Output;
79
+ }
80
+ /** Infers the input type of a Standard Schema. */
81
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
82
+ /** Infers the output type of a Standard Schema. */
83
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
84
+ }
85
+
86
+ interface Adapter<State> {
87
+ get(this: void, //
88
+ raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
89
+ set(this: void, //
90
+ value: State, ctx?: any): void | Promise<void>;
91
+ }
92
+ interface DisposableAdapter<State> extends Adapter<State> {
93
+ (): void;
94
+ }
13
95
  interface StorageAdapter {
14
- <State>(key: string, update: (raw?: any) => void): {
15
- get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
16
- set(value: State, ctx?: any): void;
17
- };
96
+ <State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
18
97
  keyArea?: any;
19
98
  noop?: boolean;
20
99
  }
21
100
  interface StorageAdapterFactory<AdapterConfig> {
22
- (config?: AdapterConfig): StorageAdapter;
101
+ (config: AdapterConfig): StorageAdapter;
23
102
  factory: true;
24
103
  }
25
- type Contract<Data> = ((raw: unknown) => raw is Data) | {
26
- isData: (raw: unknown) => raw is Data;
27
- getErrorMessages: (raw: unknown) => string[];
28
- };
104
+ type Contract<Data> = ((raw: unknown) => raw is Data) | StandardSchemaV1<unknown, Data> | Contract$1<unknown, Data>;
29
105
  type Done<State> = {
30
106
  key: string;
31
107
  keyPrefix: string;
@@ -39,13 +115,15 @@ type Fail<Err> = {
39
115
  error: Err;
40
116
  value?: any;
41
117
  };
42
- type Finally<State, Err> = (Done<State> & {
118
+ type FinallyDone<State> = Done<State> & {
43
119
  status: 'done';
44
- }) | (Fail<Err> & {
120
+ };
121
+ type FinallyFail<Err> = Fail<Err> & {
45
122
  status: 'fail';
46
- });
123
+ };
124
+ type Finally<State, Err> = FinallyDone<State> | FinallyFail<Err>;
47
125
  interface ConfigPersist {
48
- pickup?: Unit<any>;
126
+ pickup?: Unit<any> | Unit<any>[];
49
127
  context?: Unit<any>;
50
128
  keyPrefix?: string;
51
129
  contract?: Contract<any>;
@@ -58,21 +136,21 @@ interface ConfigAdapterFactory<AdapterConfig> {
58
136
  }
59
137
  interface ConfigCommon<State, Err = Error> {
60
138
  clock?: Unit<any>;
61
- done?: Unit<Done<State>>;
62
- fail?: Unit<Fail<Err>>;
63
- finally?: Unit<Finally<State, Err>>;
64
- pickup?: Unit<any>;
139
+ done?: UnitTargetable<Done<State>>;
140
+ fail?: UnitTargetable<Fail<Err>>;
141
+ finally?: UnitTargetable<Finally<State, Err>>;
142
+ pickup?: Unit<any> | Unit<any>[];
65
143
  context?: Unit<any>;
66
144
  key?: string;
67
145
  keyPrefix?: string;
68
146
  contract?: Contract<State | undefined>;
69
147
  }
70
148
  interface ConfigJustStore<State> {
71
- store: Store<State>;
149
+ store: StoreWritable<State>;
72
150
  }
73
151
  interface ConfigJustSourceTarget<State> {
74
152
  source: Store<State> | Event<State> | Effect<State, any, any>;
75
- target: Store<State> | Event<State> | Effect<State, any, any>;
153
+ target: StoreWritable<State> | EventCallable<State> | Effect<State, any, any>;
76
154
  }
77
155
  interface ConfigStore<State, Err = Error> extends ConfigCommon<State, Err>, ConfigJustStore<State> {
78
156
  }
@@ -88,10 +166,11 @@ interface Persist {
88
166
  /**
89
167
  * Creates custom `persist`
90
168
  */
91
- declare function createPersist(defaults?: ConfigPersist): Persist;
169
+ declare const createPersist: (defaults?: ConfigPersist) => Persist;
92
170
  /**
93
171
  * Default `persist`
94
172
  */
95
173
  declare const persist: Persist;
96
174
 
97
- export { type ConfigPersist, type ConfigSourceTarget, type ConfigStore, type Contract, type Done, type Fail, type Finally, type Persist, type StorageAdapter, type StorageAdapterFactory, createPersist, persist };
175
+ export { createPersist, persist };
176
+ export type { Adapter, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, Persist, StorageAdapter, StorageAdapterFactory };
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{persist as o}from"./core/index.js";export{asyncStorage}from"./async-storage/index.js";export{broadcast}from"./broadcast/index.js";export{local}from"./local/index.js";export{log}from"./log/index.js";export{memory}from"./memory/index.js";export{nil}from"./nil/index.js";export{query}from"./query/index.js";export{session}from"./session/index.js";export{storage}from"./storage/index.js";export{async,either,farcached}from"./tools/index.js";function r(r){return e=>o({...r,...e})}var e=o;export{r as createPersist,e as persist};
1
+ import{persist as o}from"./core/index.js";export{asyncStorage}from"./async-storage/index.js";export{broadcast}from"./broadcast/index.js";export{local}from"./local/index.js";export{log}from"./log/index.js";export{memory}from"./memory/index.js";export{nil}from"./nil/index.js";export{query}from"./query/index.js";export{session}from"./session/index.js";export{storage}from"./storage/index.js";export{async,either,farcached}from"./tools/index.js";var r=r=>e=>o({...r,...e}),e=o;export{r as createPersist,e as persist};
2
2
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { ConfigPersist, Persist } from './types'\nimport { persist as base } from './core'\n\nexport type {\n ConfigPersist,\n ConfigSourceTarget,\n ConfigStore,\n Contract,\n Done,\n Fail,\n Finally,\n Persist,\n StorageAdapter,\n StorageAdapterFactory,\n} from './types'\n\n//\n// reexport adapters\n//\n\nexport type { AsyncStorageConfig } from './async-storage'\nexport type { BroadcastConfig } from './broadcast'\nexport type { LocalStorageConfig } from './local'\nexport type { LogConfig } from './log'\nexport type { MemoryConfig } from './memory'\nexport type { NilConfig } from './nil'\nexport type { QueryConfig } from './query'\nexport type { SessionStorageConfig } from './session'\nexport type { StorageConfig } from './storage'\n\nexport { asyncStorage } from './async-storage'\nexport { broadcast } from './broadcast'\nexport { local } from './local'\nexport { log } from './log'\nexport { memory } from './memory'\nexport { nil } from './nil'\nexport { query } from './query'\nexport { session } from './session'\nexport { storage } from './storage'\n\n//\n// reexport tools\n//\n\nexport { async, either, farcached } from './tools'\n\n/**\n * Creates custom `persist`\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config: any) =>\n base({\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default `persist`\n */\nexport const persist: Persist = base\n"],"names":["createPersist","defaults","config","base","persist"],"mappings":"4bAiDO,SAASA,EAAcC,GAC5B,OAAQC,GACNC,EAAK,IACAF,KACAC,GAET,CAKO,IAAME,EAAmBD"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { ConfigPersist, Persist } from './types'\nimport { persist as basePersist } from './core'\n\nexport type {\n Adapter,\n ConfigPersist,\n ConfigSourceTarget,\n ConfigStore,\n Contract,\n DisposableAdapter,\n Done,\n Fail,\n Finally,\n Persist,\n StorageAdapter,\n StorageAdapterFactory,\n} from './types'\n\n//\n// reexport adapters\n//\n\nexport type { AsyncStorageConfig } from './async-storage'\nexport type { BroadcastConfig } from './broadcast'\nexport type { LocalStorageConfig } from './local'\nexport type { LogConfig } from './log'\nexport type { MemoryConfig } from './memory'\nexport type { NilConfig } from './nil'\nexport type { QueryConfig } from './query'\nexport type { SessionStorageConfig } from './session'\nexport type { StorageConfig } from './storage'\nexport { asyncStorage } from './async-storage'\nexport { broadcast } from './broadcast'\nexport { local } from './local'\nexport { log } from './log'\nexport { memory } from './memory'\nexport { nil } from './nil'\nexport { query } from './query'\nexport { session } from './session'\nexport { storage } from './storage'\n\n//\n// reexport tools\n//\n\nexport { async, either, farcached } from './tools'\n\n/**\n * Creates custom `persist`\n */\nexport const createPersist =\n (defaults?: ConfigPersist): Persist =>\n (config: any) =>\n basePersist({\n ...defaults,\n ...config,\n })\n\n/**\n * Default `persist`\n */\nexport const persist: Persist = basePersist\n"],"names":["createPersist","defaults","config","basePersist","persist"],"mappings":"4bAkDO,IAAMA,EACVC,GACAC,GACCC,EAAY,IACPF,KACAC,IAMIE,EAAmBD"}
package/local/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("../core/index.cjs"),r=require("../nil/index.cjs"),t=require("../storage/index.cjs");function n(e){return function(){try{return"undefined"!=typeof localStorage}catch(e){return!0}}()?t.storage({storage:()=>localStorage,sync:!0,...e}):r.nil({keyArea:"local"})}function o(r){return t=>e.persist({adapter:n,...r,...t})}n.factory=!0;var s=o();exports.createPersist=o,exports.local=n,exports.persist=s;
1
+ "use strict";var e=require("../core/index.cjs"),r=require("../nil/index.cjs"),t=require("../storage/index.cjs"),s=e=>(()=>{try{return"undefined"!=typeof localStorage}catch(e){return!0}})()?t.storage({storage:()=>localStorage,sync:!0,...e}):r.nil({keyArea:"local"});s.factory=!0;var a=r=>t=>e.persist({adapter:s,...r,...t}),o=/*#__PURE__*/a();exports.createPersist=a,exports.local=s,exports.persist=o;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/local/index.ts"],"sourcesContent":["import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigStore as BaseConfigStore,\n ConfigSourceTarget as BaseConfigSourceTarget,\n StorageAdapter,\n} from '../types'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { storage } from '../storage'\n\nexport type {\n Contract,\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 */\nfunction 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 */\nlocal.factory = true as const\nexport function local(config?: LocalStorageConfig): StorageAdapter {\n return supports()\n ? storage({\n storage: () => localStorage,\n sync: true,\n ...config,\n })\n : nil({ keyArea: 'local' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `localStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: local,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["local","config","localStorage","error","supports","storage","sync","nil","keyArea","createPersist","defaults","base","adapter","factory","persist"],"mappings":"gHA+DO,SAASA,EAAMC,GACpB,OAfF,WACE,IACE,MAA+B,oBAAjBC,YACf,CAAC,MAAOC,GAGP,OAAO,CACT,CACF,CAOSC,GACHC,UAAQ,CACNA,QAASA,IAAMH,aACfI,MAAM,KACHL,IAELM,EAAAA,IAAI,CAAEC,QAAS,SACrB,CAMO,SAASC,EAAcC,GAC5B,OAAQT,GACNU,EAAAA,QAAK,CACHC,QAASZ,KACNU,KACAT,GAET,CAtBAD,EAAMa,SAAU,EA2BHC,IAAAA,EAAUL"}
1
+ {"version":3,"file":"index.cjs","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":"gHAgEaA,EAERC,GAfYC,MACf,IACE,MAA+B,oBAAjBC,YAChB,CAAE,MAAOC,GAGP,OAAO,CACT,GASOF,GACHG,UAAQ,CACNA,QAASA,IAAMF,aACfG,MAAM,KACHL,IAELM,EAAAA,IAAI,CAAEC,QAAS,UAIrBR,EAAMS,SAAU,EAMT,IAAMC,EACVC,GACAV,GACCW,UAAK,CACHC,QAASb,KACNW,KACAV,IAMIa,eAAiCJ"}
package/local/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?: AdapterConfig): StorageAdapter;
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,34 +105,36 @@ type Fail<Err> = {
29
105
  error: Err;
30
106
  value?: any;
31
107
  };
32
- type Finally<State, Err> = (Done<State> & {
108
+ type FinallyDone<State> = Done<State> & {
33
109
  status: 'done';
34
- }) | (Fail<Err> & {
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
- pickup?: Unit<any>;
116
+ pickup?: Unit<any> | Unit<any>[];
39
117
  context?: Unit<any>;
40
118
  keyPrefix?: string;
41
119
  contract?: Contract<any>;
42
120
  }
43
121
  interface ConfigCommon<State, Err = Error> {
44
122
  clock?: Unit<any>;
45
- done?: Unit<Done<State>>;
46
- fail?: Unit<Fail<Err>>;
47
- finally?: Unit<Finally<State, Err>>;
48
- pickup?: Unit<any>;
123
+ done?: UnitTargetable<Done<State>>;
124
+ fail?: UnitTargetable<Fail<Err>>;
125
+ finally?: UnitTargetable<Finally<State, Err>>;
126
+ pickup?: Unit<any> | Unit<any>[];
49
127
  context?: Unit<any>;
50
128
  key?: string;
51
129
  keyPrefix?: string;
52
130
  contract?: Contract<State | undefined>;
53
131
  }
54
132
  interface ConfigJustStore<State> {
55
- store: Store<State>;
133
+ store: StoreWritable<State>;
56
134
  }
57
135
  interface ConfigJustSourceTarget<State> {
58
136
  source: Store<State> | Event<State> | Effect<State, any, any>;
59
- target: Store<State> | Event<State> | Effect<State, any, any>;
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
- declare function local(config?: LocalStorageConfig): StorageAdapter;
86
- declare namespace local {
87
- var factory: true;
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 function createPersist(defaults?: ConfigPersist): Persist;
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 { type ConfigPersist, type ConfigSourceTarget, type ConfigStore, type Contract, type Done, type Fail, type Finally, type LocalStorageConfig, type Persist, type StorageAdapter, type StorageAdapterFactory, createPersist, local, persist };
177
+ export { createPersist, local, persist };
178
+ export type { Adapter, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, LocalStorageConfig, Persist, StorageAdapter, StorageAdapterFactory };