@dbos-inc/koa-serve 2.11.6-preview.gcb74958171 → 2.11.13-preview
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +280 -1
- package/dist/src/dboshttp.d.ts +15 -2
- package/dist/src/dboshttp.d.ts.map +1 -1
- package/dist/src/dboshttp.js +22 -1
- package/dist/src/dboshttp.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/dboshttp.ts +34 -2
- package/tests/argsource.test.ts +10 -10
- package/tests/endpoints.test.ts +2 -2
- package/tests/validation.test.ts +16 -24
package/package.json
CHANGED
package/src/dboshttp.ts
CHANGED
|
@@ -8,6 +8,13 @@ import {
|
|
|
8
8
|
Error as DBOSErrors,
|
|
9
9
|
MethodParameter,
|
|
10
10
|
requestArgValidation,
|
|
11
|
+
ArgRequired,
|
|
12
|
+
ArgOptional,
|
|
13
|
+
DefaultArgRequired,
|
|
14
|
+
DefaultArgValidate,
|
|
15
|
+
DefaultArgOptional,
|
|
16
|
+
ArgDate,
|
|
17
|
+
ArgVarchar,
|
|
11
18
|
} from '@dbos-inc/dbos-sdk';
|
|
12
19
|
|
|
13
20
|
export enum APITypes {
|
|
@@ -142,7 +149,7 @@ export class DBOSHTTPBase extends DBOSLifecycleCallback {
|
|
|
142
149
|
}
|
|
143
150
|
|
|
144
151
|
/** Parameter decorator indicating which source to use (URL, BODY, etc) for arg data */
|
|
145
|
-
argSource(source: ArgSources) {
|
|
152
|
+
static argSource(source: ArgSources) {
|
|
146
153
|
return function (target: object, propertyKey: string | symbol, parameterIndex: number) {
|
|
147
154
|
const curParam = DBOS.associateParamWithInfo(
|
|
148
155
|
DBOSHTTP,
|
|
@@ -159,7 +166,7 @@ export class DBOSHTTPBase extends DBOSLifecycleCallback {
|
|
|
159
166
|
};
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
getArgSource(arg: MethodParameter) {
|
|
169
|
+
protected getArgSource(arg: MethodParameter) {
|
|
163
170
|
const arginfo = arg.getRegisteredInfo(DBOSHTTP) as DBOSHTTPArgInfo;
|
|
164
171
|
return arginfo?.argSource ?? ArgSources.AUTO;
|
|
165
172
|
}
|
|
@@ -182,4 +189,29 @@ export class DBOSHTTPBase extends DBOSLifecycleCallback {
|
|
|
182
189
|
}
|
|
183
190
|
}
|
|
184
191
|
}
|
|
192
|
+
|
|
193
|
+
static argRequired(target: object, propertyKey: string | symbol, parameterIndex: number) {
|
|
194
|
+
ArgRequired(target, propertyKey, parameterIndex);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static argOptional(target: object, propertyKey: string | symbol, parameterIndex: number) {
|
|
198
|
+
ArgOptional(target, propertyKey, parameterIndex);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static argDate() {
|
|
202
|
+
return ArgDate();
|
|
203
|
+
}
|
|
204
|
+
static argVarchar(n: number) {
|
|
205
|
+
return ArgVarchar(n);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
static defaultArgRequired<T extends { new (...args: unknown[]): object }>(ctor: T) {
|
|
209
|
+
return DefaultArgRequired(ctor);
|
|
210
|
+
}
|
|
211
|
+
static defaultArgOptional<T extends { new (...args: unknown[]): object }>(ctor: T) {
|
|
212
|
+
return DefaultArgOptional(ctor);
|
|
213
|
+
}
|
|
214
|
+
static defaultArgValidate<T extends { new (...args: unknown[]): object }>(ctor: T) {
|
|
215
|
+
return DefaultArgValidate(ctor);
|
|
216
|
+
}
|
|
185
217
|
}
|
package/tests/argsource.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Koa from 'koa';
|
|
2
2
|
import Router from '@koa/router';
|
|
3
3
|
|
|
4
|
-
import { DBOS
|
|
4
|
+
import { DBOS } from '@dbos-inc/dbos-sdk';
|
|
5
5
|
|
|
6
6
|
import { ArgSources, DBOSKoa } from '../src';
|
|
7
7
|
|
|
@@ -108,45 +108,45 @@ describe('httpserver-argsource-tests', () => {
|
|
|
108
108
|
parsedMethods: ['GET', 'POST'],
|
|
109
109
|
}),
|
|
110
110
|
)
|
|
111
|
-
@
|
|
111
|
+
@DBOSKoa.defaultArgRequired
|
|
112
112
|
class ArgTestEndpoints {
|
|
113
113
|
@dhttp.getApi('/getquery')
|
|
114
|
-
static async getQuery(@
|
|
114
|
+
static async getQuery(@DBOSKoa.argSource(ArgSources.QUERY) name: string) {
|
|
115
115
|
return Promise.resolve(`hello ${name}`);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
@dhttp.getApi('/getbody')
|
|
119
|
-
static async getBody(@
|
|
119
|
+
static async getBody(@DBOSKoa.argSource(ArgSources.BODY) name: string) {
|
|
120
120
|
return Promise.resolve(`hello ${name}`);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
@dhttp.getApi('/getdefault')
|
|
124
|
-
static async getDefault(@
|
|
124
|
+
static async getDefault(@DBOSKoa.argSource(ArgSources.DEFAULT) name: string) {
|
|
125
125
|
return Promise.resolve(`hello ${name}`);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
@dhttp.getApi('/getauto')
|
|
129
|
-
static async getAuto(@
|
|
129
|
+
static async getAuto(@DBOSKoa.argSource(ArgSources.AUTO) name: string) {
|
|
130
130
|
return Promise.resolve(`hello ${name}`);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
@dhttp.postApi('/postquery')
|
|
134
|
-
static async postQuery(@
|
|
134
|
+
static async postQuery(@DBOSKoa.argSource(ArgSources.QUERY) name: string) {
|
|
135
135
|
return Promise.resolve(`hello ${name}`);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
@dhttp.postApi('/postbody')
|
|
139
|
-
static async postBody(@
|
|
139
|
+
static async postBody(@DBOSKoa.argSource(ArgSources.BODY) name: string) {
|
|
140
140
|
return Promise.resolve(`hello ${name}`);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
@dhttp.postApi('/postdefault')
|
|
144
|
-
static async postDefault(@
|
|
144
|
+
static async postDefault(@DBOSKoa.argSource(ArgSources.DEFAULT) name: string) {
|
|
145
145
|
return Promise.resolve(`hello ${name}`);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
@dhttp.postApi('/postauto')
|
|
149
|
-
static async postAuto(@
|
|
149
|
+
static async postAuto(@DBOSKoa.argSource(ArgSources.AUTO) name: string) {
|
|
150
150
|
return Promise.resolve(`hello ${name}`);
|
|
151
151
|
}
|
|
152
152
|
}
|
package/tests/endpoints.test.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import Koa from 'koa';
|
|
3
3
|
import Router from '@koa/router';
|
|
4
4
|
|
|
5
|
-
import { DBOS, DBOSResponseError, Error as DBOSErrors,
|
|
5
|
+
import { DBOS, DBOSResponseError, Error as DBOSErrors, StatusString } from '@dbos-inc/dbos-sdk';
|
|
6
6
|
|
|
7
7
|
import { DBOSKoa, DBOSKoaAuthContext, RequestIDHeader, WorkflowIDHeader } from '../src';
|
|
8
8
|
|
|
@@ -351,7 +351,7 @@ describe('httpserver-tests', () => {
|
|
|
351
351
|
parsedMethods: ['POST', 'PUT', 'PATCH', 'GET', 'DELETE'],
|
|
352
352
|
}),
|
|
353
353
|
)
|
|
354
|
-
@
|
|
354
|
+
@DBOSKoa.defaultArgRequired
|
|
355
355
|
class TestEndpoints {
|
|
356
356
|
@dhttp.getApi('/hello')
|
|
357
357
|
static async hello() {
|
package/tests/validation.test.ts
CHANGED
|
@@ -2,15 +2,7 @@
|
|
|
2
2
|
import Koa from 'koa';
|
|
3
3
|
import Router from '@koa/router';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
ArgDate,
|
|
7
|
-
ArgOptional,
|
|
8
|
-
ArgRequired,
|
|
9
|
-
ArgVarchar,
|
|
10
|
-
DBOS,
|
|
11
|
-
DefaultArgOptional,
|
|
12
|
-
DefaultArgRequired,
|
|
13
|
-
} from '@dbos-inc/dbos-sdk';
|
|
5
|
+
import { DBOS } from '@dbos-inc/dbos-sdk';
|
|
14
6
|
|
|
15
7
|
import { DBOSKoa } from '../src';
|
|
16
8
|
|
|
@@ -346,7 +338,7 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
346
338
|
}
|
|
347
339
|
});
|
|
348
340
|
|
|
349
|
-
@
|
|
341
|
+
@DBOSKoa.defaultArgRequired
|
|
350
342
|
class TestEndpointDataVal {
|
|
351
343
|
@dhttp.getApi('/hello')
|
|
352
344
|
static async hello() {
|
|
@@ -370,7 +362,7 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
370
362
|
}
|
|
371
363
|
|
|
372
364
|
@dhttp.getApi('/varchar')
|
|
373
|
-
static async checkVarcharG(@
|
|
365
|
+
static async checkVarcharG(@DBOSKoa.argVarchar(10) v: string) {
|
|
374
366
|
if (typeof v !== 'string') {
|
|
375
367
|
return Promise.reject(new Error('THIS SHOULD NEVER HAPPEN'));
|
|
376
368
|
}
|
|
@@ -378,7 +370,7 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
378
370
|
}
|
|
379
371
|
|
|
380
372
|
@dhttp.postApi('/varchar')
|
|
381
|
-
static async checkVarcharP(@
|
|
373
|
+
static async checkVarcharP(@DBOSKoa.argVarchar(10) v: string) {
|
|
382
374
|
if (typeof v !== 'string') {
|
|
383
375
|
return Promise.reject(new Error('THIS SHOULD NEVER HAPPEN'));
|
|
384
376
|
}
|
|
@@ -418,7 +410,7 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
418
410
|
}
|
|
419
411
|
|
|
420
412
|
@dhttp.getApi('/date')
|
|
421
|
-
static async checkDateG(@
|
|
413
|
+
static async checkDateG(@DBOSKoa.argDate() v: Date) {
|
|
422
414
|
if (!(v instanceof Date)) {
|
|
423
415
|
return Promise.reject(new Error('THIS SHOULD NEVER HAPPEN'));
|
|
424
416
|
}
|
|
@@ -426,7 +418,7 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
426
418
|
}
|
|
427
419
|
|
|
428
420
|
@dhttp.postApi('/date')
|
|
429
|
-
static async checkDateP(@
|
|
421
|
+
static async checkDateP(@DBOSKoa.argDate() v: Date) {
|
|
430
422
|
if (!(v instanceof Date)) {
|
|
431
423
|
return Promise.reject(new Error('THIS SHOULD NEVER HAPPEN'));
|
|
432
424
|
}
|
|
@@ -457,15 +449,15 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
457
449
|
// JSON
|
|
458
450
|
}
|
|
459
451
|
|
|
460
|
-
@
|
|
452
|
+
@DBOSKoa.defaultArgRequired
|
|
461
453
|
class DefaultArgToRequired {
|
|
462
454
|
@dhttp.postApi('/rrequired')
|
|
463
|
-
static async checkReqValueR(@
|
|
455
|
+
static async checkReqValueR(@DBOSKoa.argRequired v: string) {
|
|
464
456
|
return Promise.resolve({ message: `Got string ${v}` });
|
|
465
457
|
}
|
|
466
458
|
|
|
467
459
|
@dhttp.postApi('/roptional')
|
|
468
|
-
static async checkOptValueR(@
|
|
460
|
+
static async checkOptValueR(@DBOSKoa.argOptional v?: string) {
|
|
469
461
|
return Promise.resolve({ message: `Got string ${v}` });
|
|
470
462
|
}
|
|
471
463
|
|
|
@@ -475,15 +467,15 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
475
467
|
}
|
|
476
468
|
}
|
|
477
469
|
|
|
478
|
-
@
|
|
470
|
+
@DBOSKoa.defaultArgOptional
|
|
479
471
|
class DefaultArgToOptional {
|
|
480
472
|
@dhttp.postApi('/orequired')
|
|
481
|
-
static async checkReqValueO(@
|
|
473
|
+
static async checkReqValueO(@DBOSKoa.argRequired v: string) {
|
|
482
474
|
return Promise.resolve({ message: `Got string ${v}` });
|
|
483
475
|
}
|
|
484
476
|
|
|
485
477
|
@dhttp.postApi('/ooptional')
|
|
486
|
-
static async checkOptValueO(@
|
|
478
|
+
static async checkOptValueO(@DBOSKoa.argOptional v?: string) {
|
|
487
479
|
return Promise.resolve({ message: `Got string ${v}` });
|
|
488
480
|
}
|
|
489
481
|
|
|
@@ -495,12 +487,12 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
495
487
|
|
|
496
488
|
class DefaultArgToDefault {
|
|
497
489
|
@dhttp.postApi('/drequired')
|
|
498
|
-
static async checkReqValueD(@
|
|
490
|
+
static async checkReqValueD(@DBOSKoa.argRequired v: string) {
|
|
499
491
|
return Promise.resolve({ message: `Got string ${v}` });
|
|
500
492
|
}
|
|
501
493
|
|
|
502
494
|
@dhttp.postApi('/doptional')
|
|
503
|
-
static async checkOptValueD(@
|
|
495
|
+
static async checkOptValueD(@DBOSKoa.argOptional v?: string) {
|
|
504
496
|
return Promise.resolve({ message: `Got string ${v}` });
|
|
505
497
|
}
|
|
506
498
|
|
|
@@ -510,12 +502,12 @@ describe('httpserver-datavalidation-tests', () => {
|
|
|
510
502
|
}
|
|
511
503
|
|
|
512
504
|
@DBOS.workflow()
|
|
513
|
-
static async opworkflow(@
|
|
505
|
+
static async opworkflow(@DBOSKoa.argOptional v?: string) {
|
|
514
506
|
return Promise.resolve({ message: v });
|
|
515
507
|
}
|
|
516
508
|
|
|
517
509
|
@dhttp.postApi('/doworkflow')
|
|
518
|
-
static async doWorkflow(@
|
|
510
|
+
static async doWorkflow(@DBOSKoa.argOptional v?: string) {
|
|
519
511
|
return await DefaultArgToDefault.opworkflow(v);
|
|
520
512
|
}
|
|
521
513
|
}
|