Skip to content

Commit d0ae28d

Browse files
committed
chore: fix lot of type issues
- Reordered dependencies in package.json for consistency - Added devDependencies and peerDependencies in package.json - Improved type annotations in FlowRun and FlowStep classes for better type safety - Corrected remaining_steps type conversion to Number in FlowRun - Updated event handling in SupabaseBroadcastAdapter to use system event namespace - Enhanced type definitions for FlowRunEvents, StepEvents, and related state types for stricter type checking - Overall, these changes improve maintainability, type safety, and consistency across the codebase
1 parent b34343d commit d0ae28d

File tree

6 files changed

+105
-22
lines changed

6 files changed

+105
-22
lines changed

pkgs/client/package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "@pgflow/client",
33
"version": "0.0.1",
44
"dependencies": {
5-
"nanoevents": "^7.0.1",
6-
"uuid": "^9.0.0",
75
"@pgflow/core": "workspace:*",
8-
"@pgflow/dsl": "workspace:*"
6+
"@pgflow/dsl": "workspace:*",
7+
"nanoevents": "^7.0.1",
8+
"uuid": "^9.0.0"
99
},
1010
"main": "./dist/index.cjs",
1111
"module": "./dist/index.js",
@@ -18,5 +18,12 @@
1818
"default": "./dist/index.cjs.js"
1919
}
2020
},
21-
"types": "./dist/index.d.ts"
21+
"types": "./dist/index.d.ts",
22+
"devDependencies": {
23+
"@supabase/supabase-js": "^2.49.4",
24+
"@types/uuid": "^10.0.0"
25+
},
26+
"peerDependencies": {
27+
"@supabase/supabase-js": "^2.49.4"
28+
}
2229
}

pkgs/client/src/lib/FlowRun.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createNanoEvents } from 'nanoevents';
2-
import type { ExtractFlowInput, ExtractFlowOutput, ExtractFlowSteps } from '@pgflow/dsl';
3-
import type { FlowRunState, FlowRunEvents, Unsubscribe } from './types';
2+
import type { AnyFlow, ExtractFlowInput, ExtractFlowOutput, ExtractFlowSteps } from '@pgflow/dsl';
3+
import type { FlowRunState, FlowRunEvents, Unsubscribe, StepEvents } from './types';
44
import { FlowStep } from './FlowStep';
55

66
/**
77
* Represents a single execution of a flow
88
*/
9-
export class FlowRun<TFlow> {
9+
export class FlowRun<TFlow extends AnyFlow> {
1010
#state: FlowRunState<TFlow>;
1111
#events = createNanoEvents<FlowRunEvents<TFlow>>();
1212
#steps = new Map<string, FlowStep<TFlow, keyof ExtractFlowSteps<TFlow> & string>>();
@@ -234,7 +234,7 @@ export class FlowRun<TFlow> {
234234
...this.#state,
235235
status: 'started',
236236
started_at: event.started_at ? new Date(event.started_at) : new Date(),
237-
remaining_steps: 'remaining_steps' in event ? event.remaining_steps : this.#state.remaining_steps,
237+
remaining_steps: 'remaining_steps' in event ? Number(event.remaining_steps) : this.#state.remaining_steps,
238238
};
239239
this.#events.emit('started', event as FlowRunEvents<TFlow>['started']);
240240
break;

pkgs/client/src/lib/FlowStep.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createNanoEvents } from 'nanoevents';
2-
import type { ExtractFlowSteps, StepOutput } from '@pgflow/dsl';
2+
import type { AnyFlow, ExtractFlowSteps, StepOutput } from '@pgflow/dsl';
33
import type { FlowStepState, StepEvents, Unsubscribe } from './types';
44

55
/**
66
* Represents a single step in a flow run
77
*/
88
export class FlowStep<
9-
TFlow,
9+
TFlow extends AnyFlow,
1010
TStepSlug extends keyof ExtractFlowSteps<TFlow> & string
1111
> {
1212
#state: FlowStepState<TFlow, TStepSlug>;

pkgs/client/src/lib/SupabaseBroadcastAdapter.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
IFlowRealtime,
66
BroadcastRunEvent,
77
BroadcastStepEvent,
8+
Unsubscribe,
89
} from './types';
910

1011
// Define the events interface for the adapter
@@ -62,7 +63,7 @@ export class SupabaseBroadcastAdapter implements IFlowRealtime {
6263
run_id: string,
6364
channelName: string,
6465
channel: RealtimeChannel,
65-
error: Error | unknown
66+
error: unknown
6667
): Promise<void> {
6768
console.error(`Channel ${channelName} error:`, error);
6869

@@ -88,16 +89,16 @@ export class SupabaseBroadcastAdapter implements IFlowRealtime {
8889
channel.on('broadcast', { event: '*' }, this.#handleBroadcastMessage.bind(this));
8990

9091
// Handle channel lifecycle events
91-
channel.on('subscribed', () => {
92+
channel.on('system', { event: 'subscribed' }, () => {
9293
console.log(`Subscribed to channel ${channelName}`);
9394
});
9495

95-
channel.on('closed', () => {
96+
channel.on('system', { event: 'closed' }, () => {
9697
console.log(`Channel ${channelName} closed`);
9798
});
9899

99-
channel.on('error', (error) =>
100-
this.#handleChannelError(run_id, channelName, channel, error)
100+
channel.on('system', { event: 'error' }, (payload) =>
101+
this.#handleChannelError(run_id, channelName, channel, payload.error)
101102
);
102103

103104
return channel;

pkgs/client/src/lib/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { FlowRun } from './FlowRun';
55
/**
66
* Flow run event types
77
*/
8-
export type FlowRunEvents<TFlow> = {
8+
export type FlowRunEvents<TFlow extends AnyFlow> = {
99
started: {
1010
run_id: string;
1111
flow_slug: string;
@@ -34,7 +34,7 @@ export type FlowRunEvents<TFlow> = {
3434
* Step event types
3535
*/
3636
export type StepEvents<
37-
TFlow,
37+
TFlow extends AnyFlow,
3838
TStepSlug extends keyof ExtractFlowSteps<TFlow> & string
3939
> = {
4040
started: {
@@ -146,7 +146,7 @@ export type BroadcastStepEvent =
146146
/**
147147
* Flow run state
148148
*/
149-
export type FlowRunState<TFlow> = {
149+
export type FlowRunState<TFlow extends AnyFlow> = {
150150
run_id: string;
151151
flow_slug: string;
152152
status: 'queued' | 'started' | 'completed' | 'failed';
@@ -163,7 +163,7 @@ export type FlowRunState<TFlow> = {
163163
/**
164164
* Flow step state
165165
*/
166-
export type FlowStepState<TFlow, TStepSlug extends keyof ExtractFlowSteps<TFlow> & string> = {
166+
export type FlowStepState<TFlow extends AnyFlow, TStepSlug extends keyof ExtractFlowSteps<TFlow> & string> = {
167167
run_id: string;
168168
step_slug: TStepSlug;
169169
status: 'created' | 'started' | 'completed' | 'failed';

pnpm-lock.yaml

Lines changed: 78 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)