Skip to content

Commit a0bdc30

Browse files
Elb
1 parent 1d823d8 commit a0bdc30

File tree

8 files changed

+61
-48
lines changed

8 files changed

+61
-48
lines changed

packages/sources/node/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SourceNode } from './types';
1+
import type { Elb, SourceNode } from './types';
22
import { handleCommand, handleEvent } from './lib/handle';
33
import { run } from './lib/run';
44
import { getState } from './lib/state';
@@ -22,7 +22,7 @@ export function sourceNode(
2222
const instance: SourceNode.Instance = {
2323
version,
2424
...state,
25-
push: (() => {}) as unknown as SourceNode.Elb, // Placeholder for the actual push function
25+
push: (() => {}) as unknown as Elb.Fn, // Placeholder for the actual push function
2626
};
2727

2828
// Overwrite the push function with the instance-reference

packages/sources/node/src/lib/handle.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { WalkerOS } from '@elbwalker/types';
2-
import type { SourceNode, DestinationNode } from '../types';
2+
import type { Elb, SourceNode } from '../types';
33
import { Const, assign, isObject, isSameType } from '@elbwalker/utils';
44
import { addDestination } from './destination';
55
import { pushToDestinations } from './push';
@@ -14,9 +14,7 @@ export const handleCommand: SourceNode.HandleCommand = async (
1414
data?,
1515
options?,
1616
) => {
17-
let result:
18-
| Partial<SourceNode.PushResult | DestinationNode.PushResult>
19-
| undefined = {};
17+
let result: Partial<Elb.PushResult> | undefined = {};
2018

2119
switch (action) {
2220
case Const.Commands.Config:

packages/sources/node/src/lib/helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { SourceNode } from '../types';
1+
import type { Elb } from '../types';
22
import { Const, assign } from '@elbwalker/utils';
33

44
export function createResult(
5-
partialResult?: Partial<SourceNode.PushResult>,
6-
): SourceNode.PushResult {
7-
const result: SourceNode.PushResult = assign(
5+
partialResult?: Partial<Elb.PushResult>,
6+
): Elb.PushResult {
7+
const result: Elb.PushResult = assign(
88
{
99
successful: [],
1010
queued: [],

packages/sources/node/src/lib/push.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { WalkerOS } from '@elbwalker/types';
2-
import type { SourceNode, DestinationNode } from '../types';
2+
import type { SourceNode, DestinationNode, Elb } from '../types';
33
import {
44
assign,
55
getGrantedConsent,
@@ -15,13 +15,13 @@ export function createPush(
1515
instance: SourceNode.Instance,
1616
handleCommand: SourceNode.HandleCommand,
1717
handleEvent: SourceNode.HandleEvent,
18-
): SourceNode.Elb {
19-
const push: SourceNode.Elb = async (
18+
): Elb.Fn<Promise<Elb.PushResult>> {
19+
const push = async (
2020
nameOrEvent: string | WalkerOS.DeepPartialEvent,
21-
data?: SourceNode.PushData,
22-
options?: SourceNode.PushOptions,
23-
): Promise<SourceNode.PushResult> => {
24-
let result: SourceNode.PushResult = {
21+
data?: Elb.PushData,
22+
options?: Elb.PushOptions,
23+
) => {
24+
let result: Elb.PushResult = {
2525
status: { ok: false },
2626
successful: [],
2727
queued: [],
@@ -31,9 +31,9 @@ export function createPush(
3131
return await tryCatchAsync(
3232
async (
3333
nameOrEvent: string | WalkerOS.DeepPartialEvent,
34-
data?: SourceNode.PushData,
35-
options?: SourceNode.PushOptions,
36-
): Promise<SourceNode.PushResult> => {
34+
data?: Elb.PushData,
35+
options?: Elb.PushOptions,
36+
): Promise<Elb.PushResult> => {
3737
const { event, command } = createEventOrCommand(
3838
instance,
3939
nameOrEvent,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Elb, WalkerOS } from '@elbwalker/types';
2+
import { DestinationNode, SourceNode } from '.';
3+
4+
export interface Fn<R = Promise<PushResult>>
5+
extends Elb.Fn<R>,
6+
Parameters<R>,
7+
Event<R> {}
8+
9+
export type Parameters<R = Promise<PushResult>> = (
10+
name: string,
11+
data?: PushData,
12+
options?: PushOptions,
13+
) => R;
14+
15+
export type Event<R = Promise<PushResult>> = (
16+
event: WalkerOS.DeepPartialEvent,
17+
data?: PushData,
18+
options?: PushOptions,
19+
) => R;
20+
21+
export type PushData =
22+
| Elb.PushData
23+
| DestinationNode.Destination
24+
| Partial<SourceNode.State>;
25+
26+
export type PushOptions = Elb.PushOptions | DestinationNode.Config;
27+
28+
export interface PushResult extends DestinationNode.PushResult {
29+
event?: WalkerOS.Event;
30+
status: SourceNode.Status;
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * as DestinationNode from './destination';
2+
export * as Elb from './elb';
23
export * as On from './on';
34
export * as SourceNode from './source';

packages/sources/node/src/types/source.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { WalkerOS, Schema, Handler, Hooks } from '@elbwalker/types';
2-
import type { DestinationNode, On } from '.';
2+
import type { DestinationNode, Elb, On } from '.';
33

44
export interface Instance extends State, WalkerOS.Instance {
55
config: Config;
66
destinations: Destinations;
77
version: string;
8-
push: Elb<Promise<PushResult>>;
8+
push: Elb.Fn;
99
}
1010

1111
export interface State extends WalkerOS.State {
@@ -39,34 +39,17 @@ export interface AddDestination {
3939
(id: string, destination: DestinationNode.Destination): void;
4040
}
4141

42-
export interface Elb<R = Promise<PushResult>> extends WalkerOS.Elb<R> {
43-
(name: string, data?: PushData, options?: PushOptions): R;
44-
(event: WalkerOS.PartialEvent, data?: PushData, options?: PushOptions): R;
45-
}
46-
4742
export type HandleCommand = (
4843
instance: Instance,
4944
action: string,
50-
data?: PushData,
51-
options?: PushOptions,
52-
) => Promise<PushResult>;
45+
data?: Elb.PushData,
46+
options?: Elb.PushOptions,
47+
) => Promise<Elb.PushResult>;
5348

5449
export type HandleEvent = (
5550
instance: Instance,
5651
event: WalkerOS.Event,
57-
) => Promise<PushResult>;
58-
59-
export type PushData =
60-
| WalkerOS.PushData
61-
| DestinationNode.Destination
62-
| Partial<State>;
63-
64-
export type PushOptions = WalkerOS.PushOptions | DestinationNode.Config;
65-
66-
export interface PushResult extends DestinationNode.PushResult {
67-
event?: WalkerOS.Event;
68-
status: Status;
69-
}
52+
) => Promise<Elb.PushResult>;
7053

7154
export interface Command {
7255
name: string;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Elb, WalkerOS } from '@elbwalker/types';
2-
import { State } from './source';
3-
import type { On, DestinationWeb, Walker } from '.';
2+
import type { On, DestinationWeb, Walker, SourceWalkerjs } from '.';
43

54
export interface Fn<R = void>
6-
extends CommandInit<R>,
5+
extends Elb.Fn<R>,
6+
CommandInit<R>,
77
CommandDestination<R>,
88
CommandRun<R>,
99
CommandOn<R>,
@@ -23,7 +23,7 @@ export type CommandDestination<R = void> = (
2323

2424
export type CommandRun<R = void> = (
2525
event: 'walker run',
26-
state?: Partial<State>,
26+
state?: Partial<SourceWalkerjs.State>,
2727
) => R;
2828

2929
export type CommandOn<R = void> = (
@@ -56,7 +56,7 @@ export type PushData =
5656
| Elb.PushData
5757
| DestinationWeb.Destination
5858
| DestinationWeb.DestinationInit
59-
| Partial<State>
59+
| Partial<SourceWalkerjs.State>
6060
| ScopeType;
6161

6262
export type PushOptions =

0 commit comments

Comments
 (0)