Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): dedupe unique and greatest strategy needs id #11945

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: jitterbit/get-changed-files@v1
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: jitterbit/get-changed-files@v1
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: jitterbit/get-changed-files@v1
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly the timestamp is a prerequisite for the greatest strategy. Let me know if that is the case and I can make the change.

}

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
{},
);
},
});
Loading