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 2 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
Copy link
Contributor Author

@joscha joscha May 14, 2024

Choose a reason for hiding this comment

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

for #11945 (comment) a possibly better way would be to use a fork of the original unmaintained action in https://github.com/Ana06/get-changed-files - it's a drop in replacement with a fix for the issue and a few other improvements. Let me know if you prefer the fork.

Copy link
Contributor Author

@joscha joscha May 14, 2024

Choose a reason for hiding this comment

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

opened an adjacent pull request in #11949
will rebase this PR on top of it, if it gets merged before and remove the continue-on-error flags.

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 @@
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 @@
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>;
}>

Check failure on line 369 in types/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint Code Base

Missing semicolon

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

export function defineSource<
Methods,
SourcePropDefinitions,
Expand Down
12 changes: 12 additions & 0 deletions types/src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,15 @@
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
{});

Check failure on line 364 in types/src/types.test.ts

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected indentation of 6 spaces but found 4
}

Check failure on line 365 in types/src/types.test.ts

View workflow job for this annotation

GitHub Actions / Lint Code Base

Missing trailing comma
});
Loading