File tree 25 files changed +245
-2
lines changed
25 files changed +245
-2
lines changed Original file line number Diff line number Diff line change @@ -20,5 +20,21 @@ export const tests = {
20
20
const instance = await env . workflow . get ( 'bar' ) ;
21
21
assert . deepStrictEqual ( instance . id , 'bar' ) ;
22
22
}
23
+
24
+ {
25
+ // Test createBatch
26
+ const instances = await env . workflow . createBatch ( [
27
+ {
28
+ id : 'foo' ,
29
+ payload : { bar : 'baz' } ,
30
+ } ,
31
+ {
32
+ id : 'bar' ,
33
+ payload : { bar : 'baz' } ,
34
+ } ,
35
+ ] ) ;
36
+ assert . deepStrictEqual ( instances [ 0 ] . id , 'foo' ) ;
37
+ assert . deepStrictEqual ( instances [ 1 ] . id , 'bar' ) ;
38
+ }
23
39
} ,
24
40
} ;
Original file line number Diff line number Diff line change 5
5
export default {
6
6
async fetch ( request , env , ctx ) {
7
7
const data = await request . json ( ) ;
8
+ const reqUrl = new URL ( request . url ) ;
8
9
9
- if ( request . url . includes ( '/get' ) && request . method === 'POST' ) {
10
+ if ( reqUrl . pathname === '/get' && request . method === 'POST' ) {
10
11
return Response . json (
11
12
{
12
13
result : {
@@ -22,7 +23,7 @@ export default {
22
23
) ;
23
24
}
24
25
25
- if ( request . url . includes ( '/create' ) && request . method === 'POST' ) {
26
+ if ( reqUrl . pathname === '/create' && request . method === 'POST' ) {
26
27
return Response . json (
27
28
{
28
29
result : {
@@ -37,5 +38,19 @@ export default {
37
38
}
38
39
) ;
39
40
}
41
+
42
+ if ( reqUrl . pathname === '/createBatch' && request . method === 'POST' ) {
43
+ return Response . json (
44
+ {
45
+ result : data . map ( ( val ) => ( { id : val . id } ) ) ,
46
+ } ,
47
+ {
48
+ status : 201 ,
49
+ headers : {
50
+ 'content-type' : 'application/json' ,
51
+ } ,
52
+ }
53
+ ) ;
54
+ }
40
55
} ,
41
56
} ;
Original file line number Diff line number Diff line change @@ -103,6 +103,18 @@ class WorkflowImpl {
103
103
104
104
return new InstanceImpl ( result . id , this . fetcher ) ;
105
105
}
106
+
107
+ public async createBatch (
108
+ options : WorkflowInstanceCreateOptions [ ]
109
+ ) : Promise < WorkflowInstance [ ] > {
110
+ const results = await callFetcher <
111
+ {
112
+ id : string ;
113
+ } [ ]
114
+ > ( this . fetcher , '/createBatch' , options ) ;
115
+
116
+ return results . map ( ( result ) => new InstanceImpl ( result . id , this . fetcher ) ) ;
117
+ }
106
118
}
107
119
108
120
export function makeBinding ( env : { fetcher : Fetcher } ) : Workflow {
Original file line number Diff line number Diff line change @@ -38,6 +38,16 @@ declare abstract class Workflow<PARAMS = unknown> {
38
38
public create (
39
39
options ?: WorkflowInstanceCreateOptions < PARAMS >
40
40
) : Promise < WorkflowInstance > ;
41
+
42
+ /**
43
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
44
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit (1MiB) is reached.
45
+ * @param batch List of Options when creating an instance including name and params
46
+ * @returns A promise that resolves with a list of handles for the created instances.
47
+ */
48
+ public createBatch (
49
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ]
50
+ ) : Promise < WorkflowInstance [ ] > ;
41
51
}
42
52
43
53
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
Original file line number Diff line number Diff line change @@ -24,6 +24,16 @@ declare abstract class Workflow<PARAMS = unknown> {
24
24
public create (
25
25
options ?: WorkflowInstanceCreateOptions < PARAMS >
26
26
) : Promise < WorkflowInstance > ;
27
+
28
+ /**
29
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
30
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
31
+ * @param batch List of Options when creating an instance including name and params
32
+ * @returns A promise that resolves with a list of handles for the created instances.
33
+ */
34
+ public createBatch (
35
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ]
36
+ ) : Promise < WorkflowInstance [ ] > ;
27
37
}
28
38
29
39
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
Original file line number Diff line number Diff line change @@ -6480,6 +6480,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6480
6480
public create (
6481
6481
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6482
6482
) : Promise < WorkflowInstance > ;
6483
+ /**
6484
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6485
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6486
+ * @param batch List of Options when creating an instance including name and params
6487
+ * @returns A promise that resolves with a list of handles for the created instances.
6488
+ */
6489
+ public createBatch (
6490
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6491
+ ) : Promise < WorkflowInstance [ ] > ;
6483
6492
}
6484
6493
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6485
6494
/**
Original file line number Diff line number Diff line change @@ -6381,6 +6381,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6381
6381
public create (
6382
6382
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6383
6383
) : Promise < WorkflowInstance > ;
6384
+ /**
6385
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6386
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6387
+ * @param batch List of Options when creating an instance including name and params
6388
+ * @returns A promise that resolves with a list of handles for the created instances.
6389
+ */
6390
+ public createBatch (
6391
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6392
+ ) : Promise < WorkflowInstance [ ] > ;
6384
6393
}
6385
6394
export interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6386
6395
/**
Original file line number Diff line number Diff line change @@ -6506,6 +6506,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6506
6506
public create (
6507
6507
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6508
6508
) : Promise < WorkflowInstance > ;
6509
+ /**
6510
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6511
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6512
+ * @param batch List of Options when creating an instance including name and params
6513
+ * @returns A promise that resolves with a list of handles for the created instances.
6514
+ */
6515
+ public createBatch (
6516
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6517
+ ) : Promise < WorkflowInstance [ ] > ;
6509
6518
}
6510
6519
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6511
6520
/**
Original file line number Diff line number Diff line change @@ -6407,6 +6407,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6407
6407
public create (
6408
6408
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6409
6409
) : Promise < WorkflowInstance > ;
6410
+ /**
6411
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6412
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6413
+ * @param batch List of Options when creating an instance including name and params
6414
+ * @returns A promise that resolves with a list of handles for the created instances.
6415
+ */
6416
+ public createBatch (
6417
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6418
+ ) : Promise < WorkflowInstance [ ] > ;
6410
6419
}
6411
6420
export interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6412
6421
/**
Original file line number Diff line number Diff line change @@ -6531,6 +6531,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6531
6531
public create (
6532
6532
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6533
6533
) : Promise < WorkflowInstance > ;
6534
+ /**
6535
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6536
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6537
+ * @param batch List of Options when creating an instance including name and params
6538
+ * @returns A promise that resolves with a list of handles for the created instances.
6539
+ */
6540
+ public createBatch (
6541
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6542
+ ) : Promise < WorkflowInstance [ ] > ;
6534
6543
}
6535
6544
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6536
6545
/**
Original file line number Diff line number Diff line change @@ -6432,6 +6432,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6432
6432
public create (
6433
6433
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6434
6434
) : Promise < WorkflowInstance > ;
6435
+ /**
6436
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6437
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6438
+ * @param batch List of Options when creating an instance including name and params
6439
+ * @returns A promise that resolves with a list of handles for the created instances.
6440
+ */
6441
+ public createBatch (
6442
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6443
+ ) : Promise < WorkflowInstance [ ] > ;
6435
6444
}
6436
6445
export interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6437
6446
/**
Original file line number Diff line number Diff line change @@ -6532,6 +6532,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6532
6532
public create (
6533
6533
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6534
6534
) : Promise < WorkflowInstance > ;
6535
+ /**
6536
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6537
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6538
+ * @param batch List of Options when creating an instance including name and params
6539
+ * @returns A promise that resolves with a list of handles for the created instances.
6540
+ */
6541
+ public createBatch (
6542
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6543
+ ) : Promise < WorkflowInstance [ ] > ;
6535
6544
}
6536
6545
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6537
6546
/**
Original file line number Diff line number Diff line change @@ -6433,6 +6433,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6433
6433
public create (
6434
6434
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6435
6435
) : Promise < WorkflowInstance > ;
6436
+ /**
6437
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6438
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6439
+ * @param batch List of Options when creating an instance including name and params
6440
+ * @returns A promise that resolves with a list of handles for the created instances.
6441
+ */
6442
+ public createBatch (
6443
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6444
+ ) : Promise < WorkflowInstance [ ] > ;
6436
6445
}
6437
6446
export interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6438
6447
/**
Original file line number Diff line number Diff line change @@ -6536,6 +6536,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6536
6536
public create (
6537
6537
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6538
6538
) : Promise < WorkflowInstance > ;
6539
+ /**
6540
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6541
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6542
+ * @param batch List of Options when creating an instance including name and params
6543
+ * @returns A promise that resolves with a list of handles for the created instances.
6544
+ */
6545
+ public createBatch (
6546
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6547
+ ) : Promise < WorkflowInstance [ ] > ;
6539
6548
}
6540
6549
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6541
6550
/**
Original file line number Diff line number Diff line change @@ -6437,6 +6437,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6437
6437
public create (
6438
6438
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6439
6439
) : Promise < WorkflowInstance > ;
6440
+ /**
6441
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6442
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6443
+ * @param batch List of Options when creating an instance including name and params
6444
+ * @returns A promise that resolves with a list of handles for the created instances.
6445
+ */
6446
+ public createBatch (
6447
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6448
+ ) : Promise < WorkflowInstance [ ] > ;
6440
6449
}
6441
6450
export interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6442
6451
/**
Original file line number Diff line number Diff line change @@ -6541,6 +6541,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6541
6541
public create (
6542
6542
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6543
6543
) : Promise < WorkflowInstance > ;
6544
+ /**
6545
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6546
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6547
+ * @param batch List of Options when creating an instance including name and params
6548
+ * @returns A promise that resolves with a list of handles for the created instances.
6549
+ */
6550
+ public createBatch (
6551
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6552
+ ) : Promise < WorkflowInstance [ ] > ;
6544
6553
}
6545
6554
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6546
6555
/**
Original file line number Diff line number Diff line change @@ -6442,6 +6442,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6442
6442
public create (
6443
6443
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6444
6444
) : Promise < WorkflowInstance > ;
6445
+ /**
6446
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6447
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6448
+ * @param batch List of Options when creating an instance including name and params
6449
+ * @returns A promise that resolves with a list of handles for the created instances.
6450
+ */
6451
+ public createBatch (
6452
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6453
+ ) : Promise < WorkflowInstance [ ] > ;
6445
6454
}
6446
6455
export interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6447
6456
/**
Original file line number Diff line number Diff line change @@ -6543,6 +6543,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6543
6543
public create (
6544
6544
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6545
6545
) : Promise < WorkflowInstance > ;
6546
+ /**
6547
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6548
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6549
+ * @param batch List of Options when creating an instance including name and params
6550
+ * @returns A promise that resolves with a list of handles for the created instances.
6551
+ */
6552
+ public createBatch (
6553
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6554
+ ) : Promise < WorkflowInstance [ ] > ;
6546
6555
}
6547
6556
interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6548
6557
/**
Original file line number Diff line number Diff line change @@ -6444,6 +6444,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6444
6444
public create (
6445
6445
options ?: WorkflowInstanceCreateOptions < PARAMS > ,
6446
6446
) : Promise < WorkflowInstance > ;
6447
+ /**
6448
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6449
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6450
+ * @param batch List of Options when creating an instance including name and params
6451
+ * @returns A promise that resolves with a list of handles for the created instances.
6452
+ */
6453
+ public createBatch (
6454
+ batch : WorkflowInstanceCreateOptions < PARAMS > [ ] ,
6455
+ ) : Promise < WorkflowInstance [ ] > ;
6447
6456
}
6448
6457
export interface WorkflowInstanceCreateOptions < PARAMS = unknown > {
6449
6458
/**
Original file line number Diff line number Diff line change @@ -6543,6 +6543,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6543
6543
public create(
6544
6544
options?: WorkflowInstanceCreateOptions<PARAMS>,
6545
6545
): Promise<WorkflowInstance>;
6546
+ /**
6547
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6548
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6549
+ * @param batch List of Options when creating an instance including name and params
6550
+ * @returns A promise that resolves with a list of handles for the created instances.
6551
+ */
6552
+ public createBatch(
6553
+ batch: WorkflowInstanceCreateOptions<PARAMS>[],
6554
+ ): Promise<WorkflowInstance[]>;
6546
6555
}
6547
6556
interface WorkflowInstanceCreateOptions<PARAMS = unknown> {
6548
6557
/**
Original file line number Diff line number Diff line change @@ -6444,6 +6444,15 @@ export declare abstract class Workflow<PARAMS = unknown> {
6444
6444
public create(
6445
6445
options?: WorkflowInstanceCreateOptions<PARAMS>,
6446
6446
): Promise<WorkflowInstance>;
6447
+ /**
6448
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6449
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6450
+ * @param batch List of Options when creating an instance including name and params
6451
+ * @returns A promise that resolves with a list of handles for the created instances.
6452
+ */
6453
+ public createBatch(
6454
+ batch: WorkflowInstanceCreateOptions<PARAMS>[],
6455
+ ): Promise<WorkflowInstance[]>;
6447
6456
}
6448
6457
export interface WorkflowInstanceCreateOptions<PARAMS = unknown> {
6449
6458
/**
Original file line number Diff line number Diff line change @@ -6624,6 +6624,15 @@ declare abstract class Workflow<PARAMS = unknown> {
6624
6624
public create(
6625
6625
options?: WorkflowInstanceCreateOptions<PARAMS>,
6626
6626
): Promise<WorkflowInstance>;
6627
+ /**
6628
+ * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown.
6629
+ * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached.
6630
+ * @param batch List of Options when creating an instance including name and params
6631
+ * @returns A promise that resolves with a list of handles for the created instances.
6632
+ */
6633
+ public createBatch(
6634
+ batch: WorkflowInstanceCreateOptions<PARAMS>[],
6635
+ ): Promise<WorkflowInstance[]>;
6627
6636
}
6628
6637
interface WorkflowInstanceCreateOptions<PARAMS = unknown> {
6629
6638
/**
You can’t perform that action at this time.
0 commit comments