Skip to content

Commit

Permalink
fix(types): dedupe unique and greatest strategy needs id (#11945)
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha authored May 16, 2024
1 parent f1bb8ac commit fabecdd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/pull-request-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- uses: Ana06/[email protected]
id: changed_files
name: Get changed files
continue-on-error: true
- id: md_changed_files
name: Spellcheck Markdown files
run: |-
Expand Down Expand Up @@ -93,13 +94,15 @@ jobs:
uses: Ana06/[email protected]
with:
format: 'space-delimited'
continue-on-error: true
- name: Lint changed files
run: npx eslint --quiet ${{ steps.changed_files_space.outputs.added_modified }} ${{ steps.changed_files_space.outputs.renamed }}
- name: Get Changed Files (comma-separated)
id: changed_files
uses: Ana06/[email protected]
with:
format: 'csv'
continue-on-error: true
# NOTE: These steps are kept in this workflow to avoid re-rerunning the rest of the lint job
# in the Components Checks workflow
- name: Check component keys
Expand Down
44 changes: 43 additions & 1 deletion types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,25 @@ export interface EmitMetadata {
ts?: number;
}

export interface IdEmitMetadata extends EmitMetadata {
id: string | number;
}

type EmitFunction = {
$emit: (event: JSONValue, metadata?: EmitMetadata) => Promise<void>;
};

type IdEmitFunction = {
$emit: (event: JSONValue, metadata: IdEmitMetadata) => Promise<void>;
};

type PropThis<Props> = {
[Prop in keyof Props]: Props[Prop] extends App<Methods, AppPropDefinitions> ? any : any
};

export interface Source<
type Modify<T, R> = Omit<T, keyof R> & R;

interface BaseSource<
Methods,
SourcePropDefinitions
> {
Expand All @@ -337,6 +347,38 @@ export interface Source<
run: (this: PropThis<SourcePropDefinitions> & Methods & EmitFunction, options?: SourceRunOptions) => void | Promise<void>;
}

export interface LastSource<
Methods,
SourcePropDefinitions
> extends BaseSource<
Methods,
SourcePropDefinitions
> {
dedupe?: "last";
}

export type DedupedSource<
Methods,
SourcePropDefinitions
> = Modify<BaseSource<
Methods,
SourcePropDefinitions
>, {
dedupe: "greatest" | "unique";
run: (this: PropThis<SourcePropDefinitions> & Methods & IdEmitFunction, options?: SourceRunOptions) => void | Promise<void>;
}>;

export type Source<
Methods,
SourcePropDefinitions
> = LastSource<
Methods,
SourcePropDefinitions
> | DedupedSource<
Methods,
SourcePropDefinitions
>;

export function defineSource<
Methods,
SourcePropDefinitions,
Expand Down
14 changes: 14 additions & 0 deletions types/src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,17 @@ const actionWrongType: Pipedream.Action<Pipedream.Methods, Pipedream.ActionPropD
type: "source",
run() { console.log("foo"); },
};

Pipedream.defineSource({
key: "source",
version: "0.0.1",
type: "source",
dedupe: "unique",
run() {
this.$emit(
{},
// @ts-expect-error $ExpectError - Missing id property in metadata object
{},
);
},
});

0 comments on commit fabecdd

Please sign in to comment.