@dbos-inc/koa-serve 2.11.7-preview.gc208400219 → 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 +2 -2
- package/dist/src/dboshttp.d.ts.map +1 -1
- package/dist/src/dboshttp.js +1 -8
- package/dist/src/dboshttp.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/dboshttp.ts +2 -23
- package/tests/argsource.test.ts +8 -8
package/package.json
CHANGED
package/src/dboshttp.ts
CHANGED
|
@@ -50,25 +50,6 @@ export interface DBOSHTTPArgInfo {
|
|
|
50
50
|
argSource?: ArgSources;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
enum ArgRequiredOptions {
|
|
54
|
-
REQUIRED = 'REQUIRED',
|
|
55
|
-
OPTIONAL = 'OPTIONAL',
|
|
56
|
-
DEFAULT = 'DEFAULT',
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
interface ValidatorClassInfo {
|
|
60
|
-
defaultArgRequired?: ArgRequiredOptions;
|
|
61
|
-
defaultArgValidate?: boolean;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
interface ValidatorFuncInfo {
|
|
65
|
-
performArgValidation?: boolean;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
interface ValidatorArgInfo {
|
|
69
|
-
required?: ArgRequiredOptions;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
53
|
/**
|
|
73
54
|
* HTTPRequest includes useful information from http.IncomingMessage and parsed body,
|
|
74
55
|
* URL parameters, and parsed query string.
|
|
@@ -107,8 +88,6 @@ export function isClientRequestError(e: Error) {
|
|
|
107
88
|
return DBOSErrors.isDataValidationError(e);
|
|
108
89
|
}
|
|
109
90
|
|
|
110
|
-
const VALIDATOR = 'validator';
|
|
111
|
-
|
|
112
91
|
export class DBOSHTTPBase extends DBOSLifecycleCallback {
|
|
113
92
|
static HTTP_OPERATION_TYPE: string = 'http';
|
|
114
93
|
|
|
@@ -170,7 +149,7 @@ export class DBOSHTTPBase extends DBOSLifecycleCallback {
|
|
|
170
149
|
}
|
|
171
150
|
|
|
172
151
|
/** Parameter decorator indicating which source to use (URL, BODY, etc) for arg data */
|
|
173
|
-
argSource(source: ArgSources) {
|
|
152
|
+
static argSource(source: ArgSources) {
|
|
174
153
|
return function (target: object, propertyKey: string | symbol, parameterIndex: number) {
|
|
175
154
|
const curParam = DBOS.associateParamWithInfo(
|
|
176
155
|
DBOSHTTP,
|
|
@@ -187,7 +166,7 @@ export class DBOSHTTPBase extends DBOSLifecycleCallback {
|
|
|
187
166
|
};
|
|
188
167
|
}
|
|
189
168
|
|
|
190
|
-
getArgSource(arg: MethodParameter) {
|
|
169
|
+
protected getArgSource(arg: MethodParameter) {
|
|
191
170
|
const arginfo = arg.getRegisteredInfo(DBOSHTTP) as DBOSHTTPArgInfo;
|
|
192
171
|
return arginfo?.argSource ?? ArgSources.AUTO;
|
|
193
172
|
}
|
package/tests/argsource.test.ts
CHANGED
|
@@ -111,42 +111,42 @@ describe('httpserver-argsource-tests', () => {
|
|
|
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
|
}
|