Skip to content

Commit 1d823d8

Browse files
Elb
1 parent dcb7387 commit 1d823d8

File tree

4 files changed

+77
-55
lines changed

4 files changed

+77
-55
lines changed

packages/sources/walkerjs/src/types/elb.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
1-
import type { WalkerOS } from '@elbwalker/types';
1+
import type { Elb, WalkerOS } from '@elbwalker/types';
22
import { State } from './source';
33
import type { On, DestinationWeb, Walker } from '.';
44

5-
export interface Fn
6-
extends CommandInit,
7-
CommandDestination,
8-
CommandRun,
9-
CommandOn,
10-
Parameters,
11-
WalkerOS.DeepPartialEvent {}
5+
export interface Fn<R = void>
6+
extends CommandInit<R>,
7+
CommandDestination<R>,
8+
CommandRun<R>,
9+
CommandOn<R>,
10+
Parameters<R>,
11+
Event<R> {}
1212

13-
export type CommandInit = (
13+
export type CommandInit<R = void> = (
1414
event: 'walker init',
1515
scope: Scope | Scope[],
16-
) => void;
16+
) => R;
1717

18-
export type CommandDestination = (
18+
export type CommandDestination<R = void> = (
1919
event: 'walker destination',
2020
destination: DestinationWeb.Destination | DestinationWeb.DestinationInit,
2121
config?: DestinationWeb.Config,
22-
) => void;
22+
) => R;
2323

24-
export type CommandRun = (event: 'walker run', state?: Partial<State>) => void;
24+
export type CommandRun<R = void> = (
25+
event: 'walker run',
26+
state?: Partial<State>,
27+
) => R;
2528

26-
export type CommandOn = (
29+
export type CommandOn<R = void> = (
2730
event: 'walker on',
2831
type: 'consent',
2932
rules: WalkerOS.SingleOrArray<On.ConsentConfig>,
30-
) => void;
33+
) => R;
3134

32-
export type Parameters = (
35+
export type Parameters<R = void> = (
3336
event: string | unknown,
3437
data?: PushData,
3538
options?: PushOptions,
3639
context?: PushContext,
3740
nested?: WalkerOS.Entities,
3841
custom?: WalkerOS.Properties,
39-
) => void;
42+
) => R;
43+
44+
export type Event<R = void> = (partialEvent: WalkerOS.DeepPartialEvent) => R;
4045

4146
export type Layer = [
4247
string?,
@@ -48,14 +53,14 @@ export type Layer = [
4853
];
4954

5055
export type PushData =
51-
| WalkerOS.PushData
56+
| Elb.PushData
5257
| DestinationWeb.Destination
5358
| DestinationWeb.DestinationInit
5459
| Partial<State>
5560
| ScopeType;
5661

5762
export type PushOptions =
58-
| WalkerOS.PushOptions
63+
| Elb.PushOptions
5964
| Walker.Trigger
6065
| WalkerOS.SingleOrArray<On.Options>
6166
| DestinationWeb.Config;

packages/types/src/elb.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { Hooks, WalkerOS } from '.';
2+
3+
export interface Fn<R = void>
4+
extends CommandConfig<R>,
5+
CommandConsent<R>,
6+
CommandHook<R>,
7+
CommandRun<R>,
8+
CommandUser<R>,
9+
CommandPush<R>,
10+
Event<R> {}
11+
12+
export type CommandConfig<R = void> = (
13+
event: 'walker config',
14+
config: Partial<WalkerOS.Config>,
15+
) => R;
16+
export type CommandConsent<R = void> = (
17+
event: 'walker consent',
18+
consent: WalkerOS.Consent,
19+
) => R;
20+
export type CommandHook<R = void> = <K extends keyof Hooks.Functions>(
21+
event: 'walker hook',
22+
name: K,
23+
hookFn: Hooks.Functions[K],
24+
) => R;
25+
export type CommandRun<R = void> = (event: 'walker run') => R;
26+
export type CommandUser<R = void> = (
27+
event: 'walker user',
28+
user: WalkerOS.User,
29+
) => R;
30+
export type CommandPush<R = void> = (
31+
event: string,
32+
data?: PushData,
33+
options?: PushOptions,
34+
context?: PushContext,
35+
nested?: WalkerOS.Entities,
36+
custom?: WalkerOS.Properties,
37+
) => R;
38+
export type Event<R = void> = (partialEvent: WalkerOS.DeepPartialEvent) => R;
39+
40+
export type PushData =
41+
| string
42+
| object
43+
| WalkerOS.DeepPartial<WalkerOS.Config>
44+
| WalkerOS.Consent
45+
| WalkerOS.User
46+
| WalkerOS.Properties;
47+
48+
export type PushOptions = Hooks.AnyFunction | object;
49+
50+
export type PushContext = WalkerOS.OrderedProperties;

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * as Data from './data';
22
export * as Destination from './destination';
3+
export * as Elb from './elb';
34
export * as Handler from './handler';
45
export * as Hooks from './hooks';
56
export * as Mapping from './mapping';

packages/types/src/walkeros.ts

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { Destination, Hooks } from '.';
1+
import type { Destination, Elb, Hooks } from '.';
22

33
export type AnyObject = Record<string, unknown>;
44
export type AnyFunction = (...args: unknown[]) => unknown;
55
export type SingleOrArray<T> = T | Array<T>;
66

77
export interface Instance extends State {
8-
push: Elb;
8+
push: Elb.Fn;
99
}
1010

1111
export interface State {
@@ -30,40 +30,6 @@ export interface Config {
3030
verbose?: boolean; // Enable verbose logging
3131
}
3232

33-
export interface Elb<R = void> {
34-
(event: 'walker config', config: Partial<Config>): R;
35-
(event: 'walker consent', consent: Consent): R;
36-
37-
<K extends keyof Hooks.Functions>(
38-
event: 'walker hook',
39-
name: K,
40-
hookFn: Hooks.Functions[K],
41-
): R;
42-
(event: 'walker run'): R;
43-
(event: 'walker user', user: User): R;
44-
(
45-
event: string,
46-
data?: PushData,
47-
options?: PushOptions,
48-
context?: PushContext,
49-
nested?: Entities,
50-
custom?: Properties,
51-
): R;
52-
(partialEvent: DeepPartialEvent): R;
53-
}
54-
55-
export type PushData =
56-
| string
57-
| object
58-
| Partial<Config>
59-
| Consent
60-
| User
61-
| Properties;
62-
63-
export type PushOptions = Hooks.AnyFunction | object;
64-
65-
export type PushContext = OrderedProperties;
66-
6733
export interface Destinations {
6834
[name: string]: Destination.Destination;
6935
}

0 commit comments

Comments
 (0)