Skip to content

Commit

Permalink
Allow a single-element concurrency option in function definitions (#…
Browse files Browse the repository at this point in the history
…462)

## Summary
<!-- Succinctly describe your change, providing context, what you've
changed, and why. -->

Fixes `concurrency: [ConcurrencyOption]` not being allowed.

## Checklist
<!-- Tick these items off as you progress. -->
<!-- If an item isn't applicable, ideally please strikeout the item by
wrapping it in "~~"" and suffix it with "N/A My reason for skipping
this." -->
<!-- e.g. "- [ ] ~~Added tests~~ N/A Only touches docs" -->

- [ ] ~~Added a [docs PR](https://github.com/inngest/website) that
references this PR~~ N/A Bug fix
- [ ] ~~Added unit/integration tests~~ N/A
- [x] Added changesets if applicable
  • Loading branch information
jpwilliams committed Jan 16, 2024
1 parent c55e3bc commit c449efe
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-frogs-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": patch
---

Fix not allowing a single-element `concurrency` option in function definitions
7 changes: 4 additions & 3 deletions packages/inngest/etc/inngest.api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions packages/inngest/src/helpers/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { type RecursiveTuple } from "@local/helpers/types";
import { assertType, type IsEqual } from "type-plus";

describe("RecursiveTuple", () => {
test("should create a tuple of length 1", () => {
type Expected = [string];
type Actual = RecursiveTuple<string, 1>;
assertType<IsEqual<Expected, Actual>>(true);
});

test("should create a tuple of length 2", () => {
type Expected = [string] | [string, string];
type Actual = RecursiveTuple<string, 2>;
assertType<IsEqual<Expected, Actual>>(true);
});

test("should create a tuple of length 3", () => {
type Expected = [string] | [string, string] | [string, string, string];
type Actual = RecursiveTuple<string, 3>;
assertType<IsEqual<Expected, Actual>>(true);
});

test("should create a tuple with mixed primitives", () => {
type Expected = [string | number] | [string | number, string | number];
type Actual = RecursiveTuple<string | number, 2>;
assertType<IsEqual<Expected, Actual>>(true);
});

test("should expand type aliases of primitives", () => {
type T0 = string;
type Expected = [string] | [string, string];
type Actual = RecursiveTuple<T0, 2>;
assertType<IsEqual<Expected, Actual>>(true);
});
});
14 changes: 14 additions & 0 deletions packages/inngest/src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,17 @@ export type IsEmptyObject<T> = {} extends T
? true
: false
: false;

/**
* Create a tuple that can be of length 1 to `TLength`, where each element is
* of type `TElement`.
*/
export type RecursiveTuple<
TElement,
TLength extends number,
TAccumulator extends TElement[] = [TElement],
> = TAccumulator["length"] extends TLength
? TAccumulator
:
| RecursiveTuple<TElement, TLength, [TElement, ...TAccumulator]>
| TAccumulator;
6 changes: 4 additions & 2 deletions packages/inngest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { type internalEvents } from "./helpers/consts";
import {
type IsStringLiteral,
type ObjectPaths,
type RecursiveTuple,
type StrictUnion,
} from "./helpers/types";
import { type Logger } from "./middleware/logger";
Expand Down Expand Up @@ -791,12 +792,13 @@ export interface FunctionOptions<
* can occur across all runs of the function. A value of 0 (or undefined) means
* use the maximum available concurrency.
*
* Specifying just a number means specifying only the concurrency limit.
* Specifying just a number means specifying only the concurrency limit. A
* maximum of two concurrency options can be specified.
*/
concurrency?:
| number
| ConcurrencyOption
| [ConcurrencyOption, ConcurrencyOption];
| RecursiveTuple<ConcurrencyOption, 2>;

/**
* batchEvents specifies the batch configuration on when this function
Expand Down

0 comments on commit c449efe

Please sign in to comment.