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/query/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
  }
@@ -91,18 +169,19 @@ interface Persist {
91
169
  <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription;
92
170
  <State, Err = Error>(config: ConfigStore<State, Err>): Subscription;
93
171
  }
94
- declare function query(config?: QueryConfig): StorageAdapter;
95
- declare namespace query {
96
- var factory: true;
97
- }
172
+ /**
173
+ * Creates query string adapter
174
+ */
175
+ declare const query: StorageAdapterFactory<QueryConfig | undefined | void>;
98
176
  /**
99
177
  * Creates custom partially applied `persist`
100
178
  * with predefined `query` adapter
101
179
  */
102
- declare function createPersist(defaults?: ConfigPersist): Persist;
180
+ declare const createPersist: (defaults?: ConfigPersist) => Persist;
103
181
  /**
104
182
  * Default partially applied `persist`
105
183
  */
106
184
  declare const persist: Persist;
107
185
 
108
- export { type ChangeMethod, type ConfigPersist, type ConfigSourceTarget, type ConfigStore, type Contract, type Done, type Fail, type Finally, type Persist, type QueryConfig, type StateBehavior, type StorageAdapter, type StorageAdapterFactory, createPersist, locationAssign, locationReplace, persist, pushState, query, replaceState };
186
+ export { createPersist, locationAssign, locationReplace, persist, pushState, query, replaceState };
187
+ export type { Adapter, ChangeMethod, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, Persist, QueryConfig, StateBehavior, StorageAdapter, StorageAdapterFactory };
package/query/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{persist as e}from"../core/index.js";import{nil as t}from"../nil/index.js";var a,r,o=Symbol(),i=new Map,n=e=>location.pathname+(e+""?"?"+e:"")+(location.hash&&"#"!==location.hash?location.hash:""),s=(e,t)=>history.pushState(t?null:history.state,"",n(e)),l=(e,t)=>history.replaceState(t?null:history.state,"",n(e)),c=e=>location.assign(n(e)),u=e=>location.replace(n(e));function d(e,t){if(r=void 0,i.size){var a=new URLSearchParams(location.search);for(var[o,n]of i.entries())null!=n?a.set(o,`${n}`):a.delete(o);i.clear(),e(a,"erase"===t)}}function f(e){return"undefined"!=typeof history&&"undefined"!=typeof location?function({method:e=s,state:t,serialize:n,deserialize:l,def:c=null,timeout:u}){var f=(o,s)=>("undefined"!=typeof addEventListener&&addEventListener("popstate",(()=>setTimeout(s,0))),{get(){var e=new URLSearchParams(location.search).get(o);return e?l?l(e):e:c},set(s){if(i.set(o,n?n(s):s),void 0===u)return clearTimeout(a),d(e,t);var l=Date.now()+u;(void 0===r||r>l)&&(clearTimeout(a),r=l,a=setTimeout(d,u,e,t))}});return f.keyArea=o,f}({...e}):t({keyArea:"query"})}function h(t){return a=>e({adapter:f,...t,...a})}f.factory=!0;var p=h();export{h as createPersist,c as locationAssign,u as locationReplace,p as persist,s as pushState,f as query,l as replaceState};
1
+ import{persist as e}from"../core/index.js";import{nil as t}from"../nil/index.js";var a,r,o=Symbol(),i=new Map,n=e=>location.pathname+(e+""?"?"+e:"")+(location.hash&&"#"!==location.hash?location.hash:""),s=(e,t)=>history.pushState(t?null:history.state,"",n(e)),l=(e,t)=>history.replaceState(t?null:history.state,"",n(e)),d=e=>location.assign(n(e)),c=e=>location.replace(n(e)),u=(e,t)=>{if(r=void 0,i.size){var a=new URLSearchParams(location.search);for(var[o,n]of i.entries())null!=n?a.set(o,`${n}`):a.delete(o);i.clear(),e(a,"erase"===t)}},h=e=>"undefined"!=typeof history&&"undefined"!=typeof location?(({method:e=s,state:t,serialize:n,deserialize:l,def:d=null,timeout:c})=>{var h=(o,s)=>{var h=()=>setTimeout(s,0);return"undefined"!=typeof addEventListener&&addEventListener("popstate",h),Object.assign(()=>{"undefined"!=typeof removeEventListener&&removeEventListener("popstate",h)},{get(){var e=new URLSearchParams(location.search).get(o);return e?l?l(e):e:d},set(s){if(i.set(o,n?n(s):s),void 0===c)return clearTimeout(a),u(e,t);var l=Date.now()+c;(void 0===r||r>l)&&(clearTimeout(a),r=l,a=setTimeout(u,c,e,t))}})};return h.keyArea=o,h})({...e}):t({keyArea:"query"});h.factory=!0;var p=t=>a=>e({adapter:h,...t,...a}),v=/*#__PURE__*/p();export{p as createPersist,d as locationAssign,c as locationReplace,v as persist,s as pushState,h as query,l as replaceState};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/query/adapter.ts","../../src/query/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport type ChangeMethod = (\n params: URLSearchParams | string,\n erase?: boolean\n) => void\n\nexport type StateBehavior = 'keep' | 'erase'\n\nexport interface QueryConfig {\n method?: ChangeMethod\n state?: StateBehavior\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nconst keyArea = Symbol() // eslint-disable-line symbol-description\n\nconst buffer = new Map<string, any>()\nlet timeoutId: ReturnType<typeof setTimeout> | undefined\nlet scheduled: number | undefined\n\n/*\n * Location change methods list\n */\n\nconst url = (params: URLSearchParams | string) =>\n location.pathname +\n (params + '' ? '?' + params : '') +\n (location.hash && location.hash !== '#' ? location.hash : '')\n\nexport const pushState: ChangeMethod = (params, erase): void =>\n history.pushState(erase ? null : history.state, '', url(params))\n\nexport const replaceState: ChangeMethod = (params, erase): void =>\n history.replaceState(erase ? null : history.state, '', url(params))\n\nexport const locationAssign: ChangeMethod = (params): void =>\n location.assign(url(params))\n\nexport const locationReplace: ChangeMethod = (params): void =>\n location.replace(url(params))\n\n/**\n * Flush buffer to actual location search params\n */\nfunction flush(method: ChangeMethod, state?: StateBehavior) {\n scheduled = undefined\n if (buffer.size) {\n const params = new URLSearchParams(location.search)\n for (const [name, value] of buffer.entries()) {\n if (value != null) {\n params.set(name, `${value}`)\n } else {\n params.delete(name)\n }\n }\n buffer.clear()\n method(params, state === 'erase')\n }\n}\n\n/**\n * Query string adapter factory\n */\nexport function adapter({\n method = pushState,\n state,\n serialize,\n deserialize,\n def = null,\n timeout,\n}: QueryConfig): StorageAdapter {\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => void\n ) => {\n if (typeof addEventListener !== 'undefined') {\n addEventListener('popstate', () => setTimeout(update, 0))\n }\n\n return {\n get() {\n const params = new URLSearchParams(location.search)\n const value = params.get(key)\n return value ? (deserialize ? deserialize(value) : value) : def\n },\n\n set(value: State) {\n buffer.set(key, serialize ? serialize(value) : value)\n\n if (timeout === undefined) {\n clearTimeout(timeoutId)\n return flush(method, state)\n }\n\n const deadline = Date.now() + timeout\n if (scheduled === undefined || scheduled > deadline) {\n clearTimeout(timeoutId)\n scheduled = deadline\n timeoutId = setTimeout(flush, timeout, method, state)\n }\n },\n }\n }\n\n adapter.keyArea = keyArea\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 StorageAdapter,\n} from '../types'\nimport type { ChangeMethod, StateBehavior, QueryConfig } from './adapter'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { adapter } from './adapter'\n\nexport type {\n Contract,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\nexport type { ChangeMethod, StateBehavior, QueryConfig } from './adapter'\nexport {\n locationAssign,\n locationReplace,\n pushState,\n replaceState,\n} from './adapter'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n method?: ChangeMethod\n state?: StateBehavior\n timeout?: number\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends QueryConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends QueryConfig,\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 `history` and `location` exists and accessible\n */\nfunction supports() {\n return typeof history !== 'undefined' && typeof location !== 'undefined'\n}\n\n/**\n * Creates query string adapter\n */\nquery.factory = true as const\nexport function query(config?: QueryConfig): StorageAdapter {\n return supports()\n ? adapter({\n ...config,\n })\n : nil({ keyArea: 'query' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `query` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: query,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["timeoutId","scheduled","keyArea","Symbol","buffer","Map","url","params","location","pathname","hash","pushState","erase","history","state","replaceState","locationAssign","assign","locationReplace","replace","flush","method","undefined","size","URLSearchParams","search","name","value","entries","set","delete","clear","query","config","serialize","deserialize","def","timeout","adapter","key","update","addEventListener","setTimeout","get","clearTimeout","deadline","Date","now","nil","createPersist","defaults","base","factory","persist"],"mappings":"iFAkBA,IAGIA,EACAC,EAJEC,EAAUC,SAEVC,EAAS,IAAIC,IAQbC,EAAOC,GACXC,SAASC,UACRF,EAAS,GAAK,IAAMA,EAAS,KAC7BC,SAASE,MAA0B,MAAlBF,SAASE,KAAeF,SAASE,KAAO,IAE/CC,EAA0BA,CAACJ,EAAQK,IAC9CC,QAAQF,UAAUC,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC,IAE7CQ,EAA6BA,CAACR,EAAQK,IACjDC,QAAQE,aAAaH,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC,IAEhDS,EAAgCT,GAC3CC,SAASS,OAAOX,EAAIC,IAETW,EAAiCX,GAC5CC,SAASW,QAAQb,EAAIC,IAKvB,SAASa,EAAMC,EAAsBP,GAEnC,GADAb,OAAYqB,EACRlB,EAAOmB,KAAM,CACf,IAAMhB,EAAS,IAAIiB,gBAAgBhB,SAASiB,QAC5C,IAAK,IAAOC,EAAMC,KAAUvB,EAAOwB,UACpB,MAATD,EACFpB,EAAOsB,IAAIH,EAAO,GAAEC,KAEpBpB,EAAOuB,OAAOJ,GAGlBtB,EAAO2B,QACPV,EAAOd,EAAkB,UAAVO,EACjB,CACF,CCJO,SAASkB,EAAMC,GACpB,MAR0B,oBAAZpB,SAA+C,oBAAbL,SDgB3C,UAAiBa,OACtBA,EAASV,EAASG,MAClBA,EAAKoB,UACLA,EAASC,YACTA,EAAWC,IACXA,EAAM,KAAIC,QACVA,IAEA,IAAMC,EAA0BA,CAC9BC,EACAC,KAEgC,oBAArBC,kBACTA,iBAAiB,YAAY,IAAMC,WAAWF,EAAQ,KAGjD,CACLG,GAAAA,GACE,IACMhB,EADS,IAAIH,gBAAgBhB,SAASiB,QACvBkB,IAAIJ,GACzB,OAAOZ,EAASQ,EAAcA,EAAYR,GAASA,EAASS,CAC7D,EAEDP,GAAAA,CAAIF,GAGF,GAFAvB,EAAOyB,IAAIU,EAAKL,EAAYA,EAAUP,GAASA,QAE/BL,IAAZe,EAEF,OADAO,aAAa5C,GACNoB,EAAMC,EAAQP,GAGvB,IAAM+B,EAAWC,KAAKC,MAAQV,QACZf,IAAdrB,GAA2BA,EAAY4C,KACzCD,aAAa5C,GACbC,EAAY4C,EACZ7C,EAAY0C,WAAWtB,EAAOiB,EAAShB,EAAQP,GAEnD,IAKJ,OADAwB,EAAQpC,QAAUA,EACXoC,CACT,CClDMA,CAAQ,IACHL,IAELe,EAAI,CAAE9C,QAAS,SACrB,CAMO,SAAS+C,EAAcC,GAC5B,OAAQjB,GACNkB,EAAK,CACHb,QAASN,KACNkB,KACAjB,GAET,CApBAD,EAAMoB,SAAU,EAyBHC,IAAAA,EAAUJ"}
1
+ {"version":3,"file":"index.js","sources":["../../src/query/adapter.ts","../../src/query/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport type ChangeMethod = (\n params: URLSearchParams | string,\n erase?: boolean\n) => void\n\nexport type StateBehavior = 'keep' | 'erase'\n\nexport interface QueryConfig {\n method?: ChangeMethod\n state?: StateBehavior\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nconst keyArea = Symbol()\n\nconst buffer = new Map<string, any>()\nlet timeoutId: ReturnType<typeof setTimeout> | undefined\nlet scheduled: number | undefined\n\n/*\n * Location change methods list\n */\n\nconst url = (params: URLSearchParams | string) =>\n location.pathname +\n (params + '' ? '?' + params : '') +\n (location.hash && location.hash !== '#' ? location.hash : '')\n\nexport const pushState: ChangeMethod = (params, erase): void =>\n history.pushState(erase ? null : history.state, '', url(params))\n\nexport const replaceState: ChangeMethod = (params, erase): void =>\n history.replaceState(erase ? null : history.state, '', url(params))\n\nexport const locationAssign: ChangeMethod = (params): void =>\n location.assign(url(params))\n\nexport const locationReplace: ChangeMethod = (params): void =>\n location.replace(url(params))\n\n/**\n * Flush buffer to actual location search params\n */\nconst flush = (method: ChangeMethod, state?: StateBehavior) => {\n scheduled = undefined\n if (buffer.size) {\n const params = new URLSearchParams(location.search)\n for (const [name, value] of buffer.entries()) {\n if (value != null) {\n params.set(name, `${value}`)\n } else {\n params.delete(name)\n }\n }\n buffer.clear()\n method(params, state === 'erase')\n }\n}\n\n/**\n * Query string adapter factory\n */\nexport const adapter = ({\n method = pushState,\n state,\n serialize,\n deserialize,\n def = null,\n timeout,\n}: QueryConfig): StorageAdapter => {\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => void\n ) => {\n const updated = () => setTimeout(update, 0)\n\n if (typeof addEventListener !== 'undefined') {\n addEventListener('popstate', updated)\n }\n\n const dispose = () => {\n if (typeof removeEventListener !== 'undefined') {\n removeEventListener('popstate', updated)\n }\n }\n\n return Object.assign(dispose, {\n get() {\n const params = new URLSearchParams(location.search)\n const value = params.get(key)\n return value ? (deserialize ? deserialize(value) : value) : def\n },\n\n set(value: State) {\n buffer.set(key, serialize ? serialize(value) : value)\n\n if (timeout === undefined) {\n clearTimeout(timeoutId)\n return flush(method, state)\n }\n\n const deadline = Date.now() + timeout\n if (scheduled === undefined || scheduled > deadline) {\n clearTimeout(timeoutId)\n scheduled = deadline\n timeoutId = setTimeout(flush, timeout, method, state)\n }\n },\n })\n }\n\n adapter.keyArea = keyArea\n return adapter\n}\n","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 type { ChangeMethod, QueryConfig, StateBehavior } from './adapter'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\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 { ChangeMethod, QueryConfig, StateBehavior } from './adapter'\nexport {\n locationAssign,\n locationReplace,\n pushState,\n replaceState,\n} from './adapter'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n method?: ChangeMethod\n state?: StateBehavior\n timeout?: number\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends QueryConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends QueryConfig,\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 `history` and `location` exists and accessible\n */\nconst supports = () =>\n typeof history !== 'undefined' && typeof location !== 'undefined'\n\n/**\n * Creates query string adapter\n */\nexport const query: StorageAdapterFactory<QueryConfig | undefined | void> = (\n config\n) => {\n return supports()\n ? adapter({\n ...config,\n })\n : nil({ keyArea: 'query' })\n}\n\n// mark as factory\nquery.factory = true\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `query` adapter\n */\nexport const createPersist =\n (defaults?: ConfigPersist): Persist =>\n (config) =>\n base({\n adapter: query,\n ...defaults,\n ...config,\n })\n\n/**\n * Default partially applied `persist`\n */\nexport const persist: Persist = /*#__PURE__*/ createPersist()\n"],"names":["timeoutId","scheduled","keyArea","Symbol","buffer","Map","url","params","location","pathname","hash","pushState","erase","history","state","replaceState","locationAssign","assign","locationReplace","replace","flush","method","undefined","size","URLSearchParams","search","name","value","entries","set","delete","clear","query","config","adapter","serialize","deserialize","def","timeout","key","update","updated","setTimeout","addEventListener","Object","dispose","removeEventListener","get","clearTimeout","deadline","Date","now","nil","factory","createPersist","defaults","base","persist"],"mappings":"iFAkBA,IAGIA,EACAC,EAJEC,EAAUC,SAEVC,EAAS,IAAIC,IAQbC,EAAOC,GACXC,SAASC,UACRF,EAAS,GAAK,IAAMA,EAAS,KAC7BC,SAASE,MAA0B,MAAlBF,SAASE,KAAeF,SAASE,KAAO,IAE/CC,EAA0BA,CAACJ,EAAQK,IAC9CC,QAAQF,UAAUC,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC,IAE7CQ,EAA6BA,CAACR,EAAQK,IACjDC,QAAQE,aAAaH,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC,IAEhDS,EAAgCT,GAC3CC,SAASS,OAAOX,EAAIC,IAETW,EAAiCX,GAC5CC,SAASW,QAAQb,EAAIC,IAKjBa,EAAQA,CAACC,EAAsBP,KAEnC,GADAb,OAAYqB,EACRlB,EAAOmB,KAAM,CACf,IAAMhB,EAAS,IAAIiB,gBAAgBhB,SAASiB,QAC5C,IAAK,IAAOC,EAAMC,KAAUvB,EAAOwB,UACpB,MAATD,EACFpB,EAAOsB,IAAIH,EAAM,GAAGC,KAEpBpB,EAAOuB,OAAOJ,GAGlBtB,EAAO2B,QACPV,EAAOd,EAAkB,UAAVO,EACjB,GCHWkB,EACXC,GANmB,oBAAZpB,SAA+C,oBAAbL,SDcpB0B,GACrBb,SAASV,EACTG,QACAqB,YACAC,cACAC,MAAM,KACNC,cAEA,IAAMJ,EAA0BA,CAC9BK,EACAC,KAEA,IAAMC,EAAUA,IAAMC,WAAWF,EAAQ,GAYzC,MAVgC,oBAArBG,kBACTA,iBAAiB,WAAYF,GASxBG,OAAO3B,OANE4B,KACqB,oBAAxBC,qBACTA,oBAAoB,WAAYL,IAIN,CAC5BM,GAAAA,GACE,IACMpB,EADS,IAAIH,gBAAgBhB,SAASiB,QACvBsB,IAAIR,GACzB,OAAOZ,EAASS,EAAcA,EAAYT,GAASA,EAASU,CAC9D,EAEAR,GAAAA,CAAIF,GAGF,GAFAvB,EAAOyB,IAAIU,EAAKJ,EAAYA,EAAUR,GAASA,QAE/BL,IAAZgB,EAEF,OADAU,aAAahD,GACNoB,EAAMC,EAAQP,GAGvB,IAAMmC,EAAWC,KAAKC,MAAQb,QACZhB,IAAdrB,GAA2BA,EAAYgD,KACzCD,aAAahD,GACbC,EAAYgD,EACZjD,EAAY0C,WAAWtB,EAAOkB,EAASjB,EAAQP,GAEnD,KAKJ,OADAoB,EAAQhC,QAAUA,EACXgC,GCvDHA,CAAQ,IACHD,IAELmB,EAAI,CAAElD,QAAS,UAIrB8B,EAAMqB,SAAU,EAMT,IAAMC,EACVC,GACAtB,GACCuB,EAAK,CACHtB,QAASF,KACNuB,KACAtB,IAMIwB,eAAiCH"}
package/session/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("../core/index.cjs"),r=require("../nil/index.cjs"),s=require("../storage/index.cjs");function t(e){return function(){try{return"undefined"!=typeof sessionStorage}catch(e){return!0}}()?s.storage({storage:()=>sessionStorage,...e}):r.nil({keyArea:"session"})}function n(r){return s=>e.persist({adapter:t,...r,...s})}t.factory=!0;var i=n();exports.createPersist=n,exports.persist=i,exports.session=t;
1
+ "use strict";var e=require("../core/index.cjs"),r=require("../nil/index.cjs"),s=require("../storage/index.cjs"),t=e=>(()=>{try{return"undefined"!=typeof sessionStorage}catch(e){return!0}})()?s.storage({storage:()=>sessionStorage,...e}):r.nil({keyArea:"session"});t.factory=!0;var i=r=>s=>e.persist({adapter:t,...r,...s}),o=/*#__PURE__*/i();exports.createPersist=i,exports.persist=o,exports.session=t;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/session/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 SessionStorageConfig {\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 SessionStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\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 `sessionStorage` exists\n */\nfunction supports() {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nsession.factory = true as const\nexport function session(config?: SessionStorageConfig): StorageAdapter {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["session","config","sessionStorage","error","supports","storage","nil","keyArea","createPersist","defaults","base","adapter","factory","persist"],"mappings":"gHA+DO,SAASA,EAAQC,GACtB,OAfF,WACE,IACE,MAAiC,oBAAnBC,cACf,CAAC,MAAOC,GAGP,OAAO,CACT,CACF,CAOSC,GACHC,UAAQ,CACNA,QAASA,IAAMH,kBACZD,IAELK,EAAAA,IAAI,CAAEC,QAAS,WACrB,CAMO,SAASC,EAAcC,GAC5B,OAAQR,GACNS,EAAAA,QAAK,CACHC,QAASX,KACNS,KACAR,GAET,CArBAD,EAAQY,SAAU,EA0BLC,IAAAA,EAAUL"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/session/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 SessionStorageConfig {\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 SessionStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\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 `sessionStorage` exists\n */\nconst supports = () => {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (_error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nexport const session: StorageAdapterFactory<\n SessionStorageConfig | undefined | void\n> = (config) => {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n// mark as factory\nsession.factory = true\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport const createPersist =\n (defaults?: ConfigPersist): Persist =>\n (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n\n/**\n * Default partially applied `persist`\n */\nexport const persist: Persist = /*#__PURE__*/ createPersist()\n"],"names":["session","config","supports","sessionStorage","_error","storage","nil","keyArea","factory","createPersist","defaults","base","adapter","persist"],"mappings":"gHAgEaA,EAERC,GAfYC,MACf,IACE,MAAiC,oBAAnBC,cAChB,CAAE,MAAOC,GAGP,OAAO,CACT,GASOF,GACHG,UAAQ,CACNA,QAASA,IAAMF,kBACZF,IAELK,EAAAA,IAAI,CAAEC,QAAS,YAIrBP,EAAQQ,SAAU,EAMX,IAAMC,EACVC,GACAT,GACCU,UAAK,CACHC,QAASZ,KACNU,KACAT,IAMIY,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
  }
@@ -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 session(config?: SessionStorageConfig): StorageAdapter;
86
- declare namespace session {
87
- var factory: true;
88
- }
163
+ /**
164
+ * Creates `sessionStorage` adapter
165
+ */
166
+ declare const session: StorageAdapterFactory<SessionStorageConfig | undefined | void>;
89
167
  /**
90
168
  * Creates custom partially applied `persist`
91
169
  * with predefined `sessionStorage` 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 Persist, type SessionStorageConfig, type StorageAdapter, type StorageAdapterFactory, createPersist, persist, session };
177
+ export { createPersist, persist, session };
178
+ export type { Adapter, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, Persist, SessionStorageConfig, StorageAdapter, StorageAdapterFactory };
@@ -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 session(config?: SessionStorageConfig): StorageAdapter;
86
- declare namespace session {
87
- var factory: true;
88
- }
163
+ /**
164
+ * Creates `sessionStorage` adapter
165
+ */
166
+ declare const session: StorageAdapterFactory<SessionStorageConfig | undefined | void>;
89
167
  /**
90
168
  * Creates custom partially applied `persist`
91
169
  * with predefined `sessionStorage` 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 Persist, type SessionStorageConfig, type StorageAdapter, type StorageAdapterFactory, createPersist, persist, session };
177
+ export { createPersist, persist, session };
178
+ export type { Adapter, ConfigPersist, ConfigSourceTarget, ConfigStore, Contract, DisposableAdapter, Done, Fail, Finally, Persist, SessionStorageConfig, StorageAdapter, StorageAdapterFactory };
package/session/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{persist as r}from"../core/index.js";import{nil as e}from"../nil/index.js";import{storage as t}from"../storage/index.js";function o(r){return function(){try{return"undefined"!=typeof sessionStorage}catch(r){return!0}}()?t({storage:()=>sessionStorage,...r}):e({keyArea:"session"})}function n(e){return t=>r({adapter:o,...e,...t})}o.factory=!0;var s=n();export{n as createPersist,s as persist,o as session};
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 s=r=>(()=>{try{return"undefined"!=typeof sessionStorage}catch(r){return!0}})()?o({storage:()=>sessionStorage,...r}):e({keyArea:"session"});s.factory=!0;var t=e=>o=>r({adapter:s,...e,...o}),a=/*#__PURE__*/t();export{t as createPersist,a as persist,s as session};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/session/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 SessionStorageConfig {\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 SessionStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\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 `sessionStorage` exists\n */\nfunction supports() {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nsession.factory = true as const\nexport function session(config?: SessionStorageConfig): StorageAdapter {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["session","config","sessionStorage","error","supports","storage","nil","keyArea","createPersist","defaults","base","adapter","factory","persist"],"mappings":"+HA+DO,SAASA,EAAQC,GACtB,OAfF,WACE,IACE,MAAiC,oBAAnBC,cACf,CAAC,MAAOC,GAGP,OAAO,CACT,CACF,CAOSC,GACHC,EAAQ,CACNA,QAASA,IAAMH,kBACZD,IAELK,EAAI,CAAEC,QAAS,WACrB,CAMO,SAASC,EAAcC,GAC5B,OAAQR,GACNS,EAAK,CACHC,QAASX,KACNS,KACAR,GAET,CArBAD,EAAQY,SAAU,EA0BLC,IAAAA,EAAUL"}
1
+ {"version":3,"file":"index.js","sources":["../../src/session/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 SessionStorageConfig {\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 SessionStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\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 `sessionStorage` exists\n */\nconst supports = () => {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (_error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nexport const session: StorageAdapterFactory<\n SessionStorageConfig | undefined | void\n> = (config) => {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n// mark as factory\nsession.factory = true\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport const createPersist =\n (defaults?: ConfigPersist): Persist =>\n (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n\n/**\n * Default partially applied `persist`\n */\nexport const persist: Persist = /*#__PURE__*/ createPersist()\n"],"names":["session","config","supports","sessionStorage","_error","storage","nil","keyArea","factory","createPersist","defaults","base","adapter","persist"],"mappings":"+HAmDA,IAaaA,EAERC,GAfYC,MACf,IACE,MAAiC,oBAAnBC,cAChB,CAAE,MAAOC,GAGP,OAAO,CACT,GASOF,GACHG,EAAQ,CACNA,QAASA,IAAMF,kBACZF,IAELK,EAAI,CAAEC,QAAS,YAIrBP,EAAQQ,SAAU,EAMX,IAAMC,EACVC,GACAT,GACCU,EAAK,CACHC,QAASZ,KACNU,KACAT,IAMIY,eAAiCJ"}