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.
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 +103 -24
  11. package/broadcast/index.d.ts +103 -24
  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 +97 -19
  17. package/core/index.d.ts +97 -19
  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 +99 -20
  24. package/index.d.ts +99 -20
  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 +103 -24
  30. package/local/index.d.ts +103 -24
  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 +103 -24
  42. package/memory/index.d.ts +103 -24
  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 +103 -24
  55. package/query/index.d.ts +103 -24
  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 +103 -24
  61. package/session/index.d.ts +103 -24
  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/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?: 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,11 +105,13 @@ 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
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?: Unit<Done<State>>;
46
- fail?: Unit<Fail<Err>>;
47
- finally?: Unit<Finally<State, Err>>;
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: 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 };
package/local/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{persist as r}from"../core/index.js";import{nil as t}from"../nil/index.js";import{storage as e}from"../storage/index.js";function o(r){return function(){try{return"undefined"!=typeof localStorage}catch(r){return!0}}()?e({storage:()=>localStorage,sync:!0,...r}):t({keyArea:"local"})}function n(t){return e=>r({adapter:o,...t,...e})}o.factory=!0;var a=n();export{n as createPersist,o as local,a as persist};
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
@@ -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 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":"+HA+DO,SAASA,EAAMC,GACpB,OAfF,WACE,IACE,MAA+B,oBAAjBC,YACf,CAAC,MAAOC,GAGP,OAAO,CACT,CACF,CAOSC,GACHC,EAAQ,CACNA,QAASA,IAAMH,aACfI,MAAM,KACHL,IAELM,EAAI,CAAEC,QAAS,SACrB,CAMO,SAASC,EAAcC,GAC5B,OAAQT,GACNU,EAAK,CACHC,QAASZ,KACNU,KACAT,GAET,CAtBAD,EAAMa,SAAU,EA2BHC,IAAAA,EAAUL"}
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";function e({keyArea:e="",logger:o=console.log}={}){var t=e=>({set(t){o(`[log adapter] set value "${t}" with key "${e}"`)},get(){o(`[log adapter] get value for key "${e}"`)}});return t.keyArea=e,t.noop=!0,t}e.factory=!0,exports.log=e;
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 */\nlog.factory = true as const\nexport function log({\n keyArea = '',\n logger = console.log,\n}: LogConfig = {}): StorageAdapter {\n const adapter: StorageAdapter = (key: string) =>\n <any>{\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 }\n\n adapter.keyArea = keyArea\n adapter.noop = true\n return adapter\n}\n"],"names":["log","keyArea","logger","console","adapter","key","set","value","get","noop","factory"],"mappings":"aAYO,SAASA,GAAIC,QAClBA,EAAU,GAAEC,OACZA,EAASC,QAAQH,KACJ,IACb,IAAMI,EAA2BC,IAC1B,CACHC,GAAAA,CAAIC,GACFL,EAAQ,4BAA2BK,gBAAoBF,KACxD,EACDG,GAAAA,GACEN,EAAQ,oCAAmCG,KAC7C,IAKJ,OAFAD,EAAQH,QAAUA,EAClBG,EAAQK,MAAO,EACRL,CACT,CAlBAJ,EAAIU,SAAU"}
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
- declare function log({ keyArea, logger, }?: LogConfig): StorageAdapter;
15
- declare namespace log {
16
- var factory: true;
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 { type LogConfig, log };
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
- declare function log({ keyArea, logger, }?: LogConfig): StorageAdapter;
15
- declare namespace log {
16
- var factory: true;
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 { type LogConfig, log };
30
+ export { log };
31
+ export type { LogConfig };
package/log/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function e({keyArea:e="",logger:o=console.log}={}){var r=e=>({set(r){o(`[log adapter] set value "${r}" with key "${e}"`)},get(){o(`[log adapter] get value for key "${e}"`)}});return r.keyArea=e,r.noop=!0,r}e.factory=!0;export{e as log};
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 */\nlog.factory = true as const\nexport function log({\n keyArea = '',\n logger = console.log,\n}: LogConfig = {}): StorageAdapter {\n const adapter: StorageAdapter = (key: string) =>\n <any>{\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 }\n\n adapter.keyArea = keyArea\n adapter.noop = true\n return adapter\n}\n"],"names":["log","keyArea","logger","console","adapter","key","set","value","get","noop","factory"],"mappings":"AAYO,SAASA,GAAIC,QAClBA,EAAU,GAAEC,OACZA,EAASC,QAAQH,KACJ,IACb,IAAMI,EAA2BC,IAC1B,CACHC,GAAAA,CAAIC,GACFL,EAAQ,4BAA2BK,gBAAoBF,KACxD,EACDG,GAAAA,GACEN,EAAQ,oCAAmCG,KAC7C,IAKJ,OAFAD,EAAQH,QAAUA,EAClBG,EAAQK,MAAO,EACRL,CACT,CAlBAJ,EAAIU,SAAU"}
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;function t({area:e=r}={}){var t=r=>({get:()=>e.get(r),set:t=>e.set(r,t)});return t.keyArea=e,t}function s(r){return s=>e.persist({adapter:t(),...r,...s})}t.factory=!0;var a=s();exports.createPersist=s,exports.memory=t,exports.persist=a;
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
@@ -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 */\nadapter.factory = true as const\nexport function adapter({ area = data }: MemoryConfig = {}): StorageAdapter {\n const adapter: StorageAdapter = <State>(key: string) => ({\n get: () => area.get(key),\n set: (value: State) => area.set(key, value),\n })\n\n adapter.keyArea = area\n return adapter\n}\n","import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigStore as BaseConfigStore,\n ConfigSourceTarget as BaseConfigSourceTarget,\n} from '../types'\nimport { persist as base } from '../core'\nimport { adapter } from './adapter'\n\nexport type {\n Contract,\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 function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: adapter(),\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["data","Map","adapter","area","key","get","set","value","keyArea","createPersist","defaults","config","base","factory","persist"],"mappings":"gDAEMA,EAAO,IAAIC,IAUV,SAASC,GAAQC,KAAEA,EAAOH,GAAuB,IACtD,IAAME,EAAkCE,IAAiB,CACvDC,IAAKA,IAAMF,EAAKE,IAAID,GACpBE,IAAMC,GAAiBJ,EAAKG,IAAIF,EAAKG,KAIvC,OADAL,EAAQM,QAAUL,EACXD,CACT,CCqBO,SAASO,EAAcC,GAC5B,OAAQC,GACNC,EAAAA,QAAK,CACHV,QAASA,OACNQ,KACAC,GAET,CDrCAT,EAAQW,SAAU,EC0CLC,IAAAA,EAAUL"}
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"}
@@ -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,11 +105,13 @@ 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
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?: Unit<Done<State>>;
46
- fail?: Unit<Fail<Err>>;
47
- finally?: Unit<Finally<State, Err>>;
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: 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
  }
@@ -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
- declare function adapter({ area }?: MemoryConfig): StorageAdapter;
70
- declare namespace adapter {
71
- var factory: true;
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 function createPersist(defaults?: ConfigPersist): Persist;
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 { type ConfigPersist, type ConfigSourceTarget, type ConfigStore, type Contract, type Done, type Fail, type Finally, type MemoryConfig, type Persist, type StorageAdapter, type StorageAdapterFactory, createPersist, adapter as memory, persist };
173
+ export { createPersist, adapter as memory, persist };
174
+ export type { Adapter, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, MemoryConfig, Persist, StorageAdapter, StorageAdapterFactory };