@virentia/effector 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,188 +1,36 @@
1
- import * as core from "@virentia/core";
2
- import { EventPayload, Scope as Scope$1 } from "@virentia/core";
1
+ import * as virentia from "@virentia/core";
2
+ import { Effect, EventCallable, Scope, Unit, UnitTargetable } from "effector";
3
3
 
4
- //#region lib/types.d.ts
5
- declare const unitKind: unique symbol;
6
- type Unsubscribe = () => void;
7
- interface Scope {
8
- readonly __core: Scope$1;
9
- getState<T>(store: Store<T>): T;
10
- }
11
- interface Unit<T = unknown> {
12
- readonly [unitKind]: UnitKind;
13
- readonly node: core.Node;
14
- readonly shortName: string;
15
- getType(): string;
16
- watch(fn: (payload: T) => void): Unsubscribe;
17
- }
18
- interface Event<T = void> extends Unit<T> {
19
- map<Next>(fn: (payload: T) => Next): Event<Next>;
20
- filter(config: {
21
- fn(payload: T): boolean;
22
- } | ((payload: T) => boolean)): Event<T>;
23
- filterMap<Next>(fn: (payload: T) => Next | undefined): Event<Next>;
24
- prepend<Before>(fn: (payload: Before) => T): EventCallable<Before>;
4
+ //#region lib/index.d.ts
5
+ interface EffectorCompatibilityOptions {
6
+ name?: string;
25
7
  }
26
- interface EventCallable<T = void> extends Event<T> {
27
- (...payload: EventPayload<T>): Promise<void>;
8
+ interface EffectorAssociationConfig {
9
+ virentia: virentia.Scope;
10
+ effector: Scope;
28
11
  }
29
- interface Store<T> extends Unit<T> {
30
- readonly updates: Event<T>;
31
- readonly sid?: string;
32
- defaultState: T;
33
- getState(scope?: Scope): T;
34
- map<Next>(fn: (state: T) => Next): Store<Next>;
35
- on<Payload>(trigger: Unit<Payload>, reducer: (state: T, payload: Payload) => T): Store<T>;
36
- reset(trigger: Unit<any> | readonly Unit<any>[]): Store<T>;
12
+ interface EffectorAssociationLookup {
13
+ virentia?: virentia.Scope;
14
+ effector?: Scope;
37
15
  }
38
- interface StoreWritable<T> extends Store<T> {
39
- setState(value: T, scope?: Scope): void;
40
- on<Payload>(trigger: Unit<Payload>, reducer: (state: T, payload: Payload) => T): StoreWritable<T>;
41
- reset(trigger: Unit<any> | readonly Unit<any>[]): StoreWritable<T>;
16
+ type EffectorPayloadMap<From, To> = (payload: From) => To;
17
+ type EffectorCompatibilityUnsubscribe = () => void;
18
+ interface EffectorAssociation {
19
+ dispose(): void;
42
20
  }
43
- interface Effect<Params, Done, Fail = Error> extends Unit<Params> {
44
- (...params: EventPayload<Params>): Promise<Done>;
45
- readonly done: Event<{
46
- params: Params;
47
- result: Done;
48
- }>;
49
- readonly fail: Event<{
50
- params: Params;
51
- error: Fail;
52
- }>;
53
- readonly finally: Event<{
54
- status: "done";
55
- params: Params;
56
- result: Done;
57
- } | {
58
- status: "fail";
59
- params: Params;
60
- error: Fail;
61
- }>;
62
- readonly doneData: Event<Done>;
63
- readonly failData: Event<Fail>;
64
- readonly pending: Store<boolean>;
65
- readonly inFlight: Store<number>;
66
- prepend<Before>(fn: (payload: Before) => Params): EventCallable<Before>;
67
- use: {
68
- (handler: (params: Params) => Done | PromiseLike<Done>): Effect<Params, Done, Fail>;
69
- getCurrent(): (params: Params) => Done | PromiseLike<Done>;
70
- };
21
+ interface EffectorCompatibility {
22
+ associate(config: EffectorAssociationConfig): EffectorAssociation;
23
+ ensureAssociation(config?: EffectorAssociationLookup): EffectorAssociation;
24
+ link<From, To = From>(from: Unit<From> | VirentiaUnit<From>, to: UnitTargetable<To> | VirentiaTarget<To>, map?: EffectorPayloadMap<From, To>): EffectorCompatibilityUnsubscribe;
25
+ asEffector<T>(unit: virentia.Effect<T, any, any>): Effect<T, any, unknown>;
26
+ asEffector<T>(unit: VirentiaUnit<T>): EventCallable<T>;
27
+ asEffector<T>(unit: Unit<T>): Unit<T>;
28
+ asVirentia<T>(unit: VirentiaUnit<T>): VirentiaUnit<T>;
29
+ asVirentia<T>(unit: Effect<T, any, any>): virentia.Effect<T, any, unknown>;
30
+ asVirentia<T>(unit: Unit<T>): virentia.EventCallable<T>;
71
31
  }
72
- type UnitKind = "event" | "store" | "effect";
73
- type AnyUnit = Event<any> | Store<any> | Effect<any, any, any>;
74
- type UnitTargetable<T = any> = EventCallable<T> | StoreWritable<T> | Effect<T, any, any>;
75
- type UnitTarget<T> = Unit<T> | readonly Unit<T>[];
76
- type SourceShape = Store<any> | readonly Store<any>[] | Record<string, Store<any>>;
77
- type SourceValue<Source> = Source extends Store<infer Value> ? Value : Source extends readonly unknown[] ? { [Key in keyof Source]: Source[Key] extends Store<infer Value> ? Value : never } : Source extends Record<string, Store<any>> ? { [Key in keyof Source]: Source[Key] extends Store<infer Value> ? Value : never } : never;
78
- type StoreValues = Record<string, unknown> | ReadonlyMap<StoreWritable<any> | string, unknown> | readonly (readonly [StoreWritable<any>, unknown])[];
79
- //#endregion
80
- //#region lib/attach.d.ts
81
- declare function attach<Params, Done, Fail>(config: {
82
- effect: Effect<Params, Done, Fail>;
83
- name?: string;
84
- }): Effect<Params, Done, Fail>;
85
- declare function attach<Params, Done, Fail = Error>(config: {
86
- effect(params: Params): Done | PromiseLike<Done>;
87
- name?: string;
88
- }): Effect<Params, Done, Fail>;
89
- declare function attach<Params, Done, Fail, AttachedParams>(config: {
90
- effect: Effect<Params, Done, Fail>;
91
- mapParams(params: AttachedParams): Params;
92
- name?: string;
93
- }): Effect<AttachedParams, Done, Fail>;
94
- declare function attach<Source extends SourceShape, Params, Done, Fail>(config: {
95
- source: Source;
96
- effect: Effect<Params, Done, Fail>;
97
- name?: string;
98
- }): Effect<Params, Done, Fail>;
99
- declare function attach<Source extends SourceShape, Params, Done, Fail, AttachedParams>(config: {
100
- source: Source;
101
- effect: Effect<Params, Done, Fail>;
102
- mapParams(params: AttachedParams, source: SourceValue<Source>): Params;
103
- name?: string;
104
- }): Effect<AttachedParams, Done, Fail>;
105
- declare function attach<Source extends SourceShape, Params, Done, Fail = Error>(config: {
106
- source: Source;
107
- effect(source: SourceValue<Source>, params: Params): Done | PromiseLike<Done>;
108
- name?: string;
109
- }): Effect<Params, Done, Fail>;
110
- //#endregion
111
- //#region lib/effect.d.ts
112
- declare function createEffect<Params = void, Done = void, Fail = Error>(handlerOrConfig?: ((params: Params) => Done | PromiseLike<Done>) | {
113
- name?: string;
114
- handler?: (params: Params) => Done | PromiseLike<Done>;
115
- }): Effect<Params, Done, Fail>;
116
- //#endregion
117
- //#region lib/event.d.ts
118
- declare function createEvent<T = void>(nameOrConfig?: string | {
119
- name?: string;
120
- }): EventCallable<T>;
121
- //#endregion
122
- //#region lib/guards.d.ts
123
- declare const is: {
124
- unit(value: unknown): value is AnyUnit;
125
- event(value: unknown): value is Event<any>;
126
- store(value: unknown): value is Store<any>;
127
- effect(value: unknown): value is Effect<any, any, any>;
128
- targetable(value: unknown): value is UnitTargetable;
129
- };
130
- //#endregion
131
- //#region lib/operators.d.ts
132
- declare function sample(config: {
133
- clock?: AnyUnit | readonly AnyUnit[];
134
- source?: SourceShape;
135
- filter?: Store<boolean> | ((source: any, clock: any) => boolean);
136
- fn?: (source: any, clock: any) => any;
137
- target?: UnitTarget<any>;
138
- }): AnyUnit;
139
- declare function combine(shape: SourceShape, fn?: (value: any) => any): Store<any>;
140
- declare function combine(...args: any[]): Store<any>;
141
- declare function split<T>(source: Unit<T>, cases: Record<string, (payload: T) => boolean>): Record<string, Event<T>>;
142
- declare function split<T>(config: {
143
- source: Unit<T>;
144
- match: ((payload: T) => string) | Record<string, (payload: T) => boolean>;
145
- cases?: Record<string, Event<T>>;
146
- }): Record<string, Event<T>>;
147
- declare function createApi<T, Shape extends Record<string, (state: T, payload: any) => T>>(store: StoreWritable<T>, reducers: Shape): { [Key in keyof Shape]: EventCallable<Parameters<Shape[Key]>[1]> };
148
- declare function restore<T>(unit: Event<T> | Effect<any, T, any>, defaultState: T): StoreWritable<T>;
149
- //#endregion
150
- //#region lib/persistence.d.ts
151
- declare function serialize(scope: Scope, config?: {
152
- onlyChanges?: boolean;
153
- ignore?: readonly (Store<any> | string)[];
154
- }): Record<string, unknown>;
155
- declare function hydrate(scope: Scope, config: {
156
- values: StoreValues;
157
- }): void;
158
- //#endregion
159
- //#region lib/scope.d.ts
160
- declare function fork(config?: {
161
- values?: StoreValues;
162
- }): Scope;
163
- declare function allSettled<T>(unit: Event<T> | StoreWritable<T>, options?: {
164
- scope?: Scope;
165
- params?: T;
166
- }): Promise<void>;
167
- declare function allSettled<Params, Done, Fail>(unit: Effect<Params, Done, Fail>, options?: {
168
- scope?: Scope;
169
- params?: Params;
170
- }): Promise<{
171
- status: "done";
172
- value: Done;
173
- } | {
174
- status: "fail";
175
- value: Fail;
176
- }>;
177
- declare function scopeBind<T>(unit: EventCallable<T> | Effect<T, any, any>, config?: {
178
- scope?: Scope;
179
- }): (...payload: EventPayload<T>) => unknown;
180
- //#endregion
181
- //#region lib/store.d.ts
182
- declare function createStore<T>(defaultState: T, config?: {
183
- name?: string;
184
- sid?: string;
185
- skipVoid?: boolean;
186
- }): StoreWritable<T>;
32
+ type VirentiaUnit<T = unknown> = virentia.Event<T> | virentia.EventCallable<T> | virentia.Effect<T, any, any> | virentia.Store<T> | virentia.StoreWritable<T>;
33
+ type VirentiaTarget<T = unknown> = virentia.EventCallable<T> | virentia.Effect<T, any, any> | virentia.StoreWritable<T>;
34
+ declare function createEffectorCompatibility(_options?: EffectorCompatibilityOptions): EffectorCompatibility;
187
35
  //#endregion
188
- export { type Effect, type Event, type EventCallable, type Scope, type Store, type StoreWritable, type Unit, type Unsubscribe, allSettled, attach, combine, createApi, createEffect, createEvent, createStore, fork, hydrate, is, restore, sample, scopeBind, serialize, split };
36
+ export { EffectorAssociation, EffectorAssociationConfig, EffectorAssociationLookup, EffectorCompatibility, EffectorCompatibilityOptions, EffectorCompatibilityUnsubscribe, EffectorPayloadMap, VirentiaTarget, VirentiaUnit, createEffectorCompatibility };
package/dist/index.d.mts CHANGED
@@ -1,188 +1,36 @@
1
- import * as core from "@virentia/core";
2
- import { EventPayload, Scope as Scope$1 } from "@virentia/core";
1
+ import * as virentia from "@virentia/core";
2
+ import { Effect, EventCallable, Scope, Unit, UnitTargetable } from "effector";
3
3
 
4
- //#region lib/types.d.ts
5
- declare const unitKind: unique symbol;
6
- type Unsubscribe = () => void;
7
- interface Scope {
8
- readonly __core: Scope$1;
9
- getState<T>(store: Store<T>): T;
10
- }
11
- interface Unit<T = unknown> {
12
- readonly [unitKind]: UnitKind;
13
- readonly node: core.Node;
14
- readonly shortName: string;
15
- getType(): string;
16
- watch(fn: (payload: T) => void): Unsubscribe;
17
- }
18
- interface Event<T = void> extends Unit<T> {
19
- map<Next>(fn: (payload: T) => Next): Event<Next>;
20
- filter(config: {
21
- fn(payload: T): boolean;
22
- } | ((payload: T) => boolean)): Event<T>;
23
- filterMap<Next>(fn: (payload: T) => Next | undefined): Event<Next>;
24
- prepend<Before>(fn: (payload: Before) => T): EventCallable<Before>;
4
+ //#region lib/index.d.ts
5
+ interface EffectorCompatibilityOptions {
6
+ name?: string;
25
7
  }
26
- interface EventCallable<T = void> extends Event<T> {
27
- (...payload: EventPayload<T>): Promise<void>;
8
+ interface EffectorAssociationConfig {
9
+ virentia: virentia.Scope;
10
+ effector: Scope;
28
11
  }
29
- interface Store<T> extends Unit<T> {
30
- readonly updates: Event<T>;
31
- readonly sid?: string;
32
- defaultState: T;
33
- getState(scope?: Scope): T;
34
- map<Next>(fn: (state: T) => Next): Store<Next>;
35
- on<Payload>(trigger: Unit<Payload>, reducer: (state: T, payload: Payload) => T): Store<T>;
36
- reset(trigger: Unit<any> | readonly Unit<any>[]): Store<T>;
12
+ interface EffectorAssociationLookup {
13
+ virentia?: virentia.Scope;
14
+ effector?: Scope;
37
15
  }
38
- interface StoreWritable<T> extends Store<T> {
39
- setState(value: T, scope?: Scope): void;
40
- on<Payload>(trigger: Unit<Payload>, reducer: (state: T, payload: Payload) => T): StoreWritable<T>;
41
- reset(trigger: Unit<any> | readonly Unit<any>[]): StoreWritable<T>;
16
+ type EffectorPayloadMap<From, To> = (payload: From) => To;
17
+ type EffectorCompatibilityUnsubscribe = () => void;
18
+ interface EffectorAssociation {
19
+ dispose(): void;
42
20
  }
43
- interface Effect<Params, Done, Fail = Error> extends Unit<Params> {
44
- (...params: EventPayload<Params>): Promise<Done>;
45
- readonly done: Event<{
46
- params: Params;
47
- result: Done;
48
- }>;
49
- readonly fail: Event<{
50
- params: Params;
51
- error: Fail;
52
- }>;
53
- readonly finally: Event<{
54
- status: "done";
55
- params: Params;
56
- result: Done;
57
- } | {
58
- status: "fail";
59
- params: Params;
60
- error: Fail;
61
- }>;
62
- readonly doneData: Event<Done>;
63
- readonly failData: Event<Fail>;
64
- readonly pending: Store<boolean>;
65
- readonly inFlight: Store<number>;
66
- prepend<Before>(fn: (payload: Before) => Params): EventCallable<Before>;
67
- use: {
68
- (handler: (params: Params) => Done | PromiseLike<Done>): Effect<Params, Done, Fail>;
69
- getCurrent(): (params: Params) => Done | PromiseLike<Done>;
70
- };
21
+ interface EffectorCompatibility {
22
+ associate(config: EffectorAssociationConfig): EffectorAssociation;
23
+ ensureAssociation(config?: EffectorAssociationLookup): EffectorAssociation;
24
+ link<From, To = From>(from: Unit<From> | VirentiaUnit<From>, to: UnitTargetable<To> | VirentiaTarget<To>, map?: EffectorPayloadMap<From, To>): EffectorCompatibilityUnsubscribe;
25
+ asEffector<T>(unit: virentia.Effect<T, any, any>): Effect<T, any, unknown>;
26
+ asEffector<T>(unit: VirentiaUnit<T>): EventCallable<T>;
27
+ asEffector<T>(unit: Unit<T>): Unit<T>;
28
+ asVirentia<T>(unit: VirentiaUnit<T>): VirentiaUnit<T>;
29
+ asVirentia<T>(unit: Effect<T, any, any>): virentia.Effect<T, any, unknown>;
30
+ asVirentia<T>(unit: Unit<T>): virentia.EventCallable<T>;
71
31
  }
72
- type UnitKind = "event" | "store" | "effect";
73
- type AnyUnit = Event<any> | Store<any> | Effect<any, any, any>;
74
- type UnitTargetable<T = any> = EventCallable<T> | StoreWritable<T> | Effect<T, any, any>;
75
- type UnitTarget<T> = Unit<T> | readonly Unit<T>[];
76
- type SourceShape = Store<any> | readonly Store<any>[] | Record<string, Store<any>>;
77
- type SourceValue<Source> = Source extends Store<infer Value> ? Value : Source extends readonly unknown[] ? { [Key in keyof Source]: Source[Key] extends Store<infer Value> ? Value : never } : Source extends Record<string, Store<any>> ? { [Key in keyof Source]: Source[Key] extends Store<infer Value> ? Value : never } : never;
78
- type StoreValues = Record<string, unknown> | ReadonlyMap<StoreWritable<any> | string, unknown> | readonly (readonly [StoreWritable<any>, unknown])[];
79
- //#endregion
80
- //#region lib/attach.d.ts
81
- declare function attach<Params, Done, Fail>(config: {
82
- effect: Effect<Params, Done, Fail>;
83
- name?: string;
84
- }): Effect<Params, Done, Fail>;
85
- declare function attach<Params, Done, Fail = Error>(config: {
86
- effect(params: Params): Done | PromiseLike<Done>;
87
- name?: string;
88
- }): Effect<Params, Done, Fail>;
89
- declare function attach<Params, Done, Fail, AttachedParams>(config: {
90
- effect: Effect<Params, Done, Fail>;
91
- mapParams(params: AttachedParams): Params;
92
- name?: string;
93
- }): Effect<AttachedParams, Done, Fail>;
94
- declare function attach<Source extends SourceShape, Params, Done, Fail>(config: {
95
- source: Source;
96
- effect: Effect<Params, Done, Fail>;
97
- name?: string;
98
- }): Effect<Params, Done, Fail>;
99
- declare function attach<Source extends SourceShape, Params, Done, Fail, AttachedParams>(config: {
100
- source: Source;
101
- effect: Effect<Params, Done, Fail>;
102
- mapParams(params: AttachedParams, source: SourceValue<Source>): Params;
103
- name?: string;
104
- }): Effect<AttachedParams, Done, Fail>;
105
- declare function attach<Source extends SourceShape, Params, Done, Fail = Error>(config: {
106
- source: Source;
107
- effect(source: SourceValue<Source>, params: Params): Done | PromiseLike<Done>;
108
- name?: string;
109
- }): Effect<Params, Done, Fail>;
110
- //#endregion
111
- //#region lib/effect.d.ts
112
- declare function createEffect<Params = void, Done = void, Fail = Error>(handlerOrConfig?: ((params: Params) => Done | PromiseLike<Done>) | {
113
- name?: string;
114
- handler?: (params: Params) => Done | PromiseLike<Done>;
115
- }): Effect<Params, Done, Fail>;
116
- //#endregion
117
- //#region lib/event.d.ts
118
- declare function createEvent<T = void>(nameOrConfig?: string | {
119
- name?: string;
120
- }): EventCallable<T>;
121
- //#endregion
122
- //#region lib/guards.d.ts
123
- declare const is: {
124
- unit(value: unknown): value is AnyUnit;
125
- event(value: unknown): value is Event<any>;
126
- store(value: unknown): value is Store<any>;
127
- effect(value: unknown): value is Effect<any, any, any>;
128
- targetable(value: unknown): value is UnitTargetable;
129
- };
130
- //#endregion
131
- //#region lib/operators.d.ts
132
- declare function sample(config: {
133
- clock?: AnyUnit | readonly AnyUnit[];
134
- source?: SourceShape;
135
- filter?: Store<boolean> | ((source: any, clock: any) => boolean);
136
- fn?: (source: any, clock: any) => any;
137
- target?: UnitTarget<any>;
138
- }): AnyUnit;
139
- declare function combine(shape: SourceShape, fn?: (value: any) => any): Store<any>;
140
- declare function combine(...args: any[]): Store<any>;
141
- declare function split<T>(source: Unit<T>, cases: Record<string, (payload: T) => boolean>): Record<string, Event<T>>;
142
- declare function split<T>(config: {
143
- source: Unit<T>;
144
- match: ((payload: T) => string) | Record<string, (payload: T) => boolean>;
145
- cases?: Record<string, Event<T>>;
146
- }): Record<string, Event<T>>;
147
- declare function createApi<T, Shape extends Record<string, (state: T, payload: any) => T>>(store: StoreWritable<T>, reducers: Shape): { [Key in keyof Shape]: EventCallable<Parameters<Shape[Key]>[1]> };
148
- declare function restore<T>(unit: Event<T> | Effect<any, T, any>, defaultState: T): StoreWritable<T>;
149
- //#endregion
150
- //#region lib/persistence.d.ts
151
- declare function serialize(scope: Scope, config?: {
152
- onlyChanges?: boolean;
153
- ignore?: readonly (Store<any> | string)[];
154
- }): Record<string, unknown>;
155
- declare function hydrate(scope: Scope, config: {
156
- values: StoreValues;
157
- }): void;
158
- //#endregion
159
- //#region lib/scope.d.ts
160
- declare function fork(config?: {
161
- values?: StoreValues;
162
- }): Scope;
163
- declare function allSettled<T>(unit: Event<T> | StoreWritable<T>, options?: {
164
- scope?: Scope;
165
- params?: T;
166
- }): Promise<void>;
167
- declare function allSettled<Params, Done, Fail>(unit: Effect<Params, Done, Fail>, options?: {
168
- scope?: Scope;
169
- params?: Params;
170
- }): Promise<{
171
- status: "done";
172
- value: Done;
173
- } | {
174
- status: "fail";
175
- value: Fail;
176
- }>;
177
- declare function scopeBind<T>(unit: EventCallable<T> | Effect<T, any, any>, config?: {
178
- scope?: Scope;
179
- }): (...payload: EventPayload<T>) => unknown;
180
- //#endregion
181
- //#region lib/store.d.ts
182
- declare function createStore<T>(defaultState: T, config?: {
183
- name?: string;
184
- sid?: string;
185
- skipVoid?: boolean;
186
- }): StoreWritable<T>;
32
+ type VirentiaUnit<T = unknown> = virentia.Event<T> | virentia.EventCallable<T> | virentia.Effect<T, any, any> | virentia.Store<T> | virentia.StoreWritable<T>;
33
+ type VirentiaTarget<T = unknown> = virentia.EventCallable<T> | virentia.Effect<T, any, any> | virentia.StoreWritable<T>;
34
+ declare function createEffectorCompatibility(_options?: EffectorCompatibilityOptions): EffectorCompatibility;
187
35
  //#endregion
188
- export { type Effect, type Event, type EventCallable, type Scope, type Store, type StoreWritable, type Unit, type Unsubscribe, allSettled, attach, combine, createApi, createEffect, createEvent, createStore, fork, hydrate, is, restore, sample, scopeBind, serialize, split };
36
+ export { EffectorAssociation, EffectorAssociationConfig, EffectorAssociationLookup, EffectorCompatibility, EffectorCompatibilityOptions, EffectorCompatibilityUnsubscribe, EffectorPayloadMap, VirentiaTarget, VirentiaUnit, createEffectorCompatibility };