temba 0.31.0 → 0.32.0
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 +14 -16
- package/config/index.d.ts +1 -3
- package/config/index.d.ts.map +1 -1
- package/config/index.js +0 -4
- package/config/index.js.map +1 -1
- package/package.json +1 -1
- package/requestHandlers/get.d.ts +1 -13
- package/requestHandlers/get.d.ts.map +1 -1
- package/requestHandlers/get.js +3 -4
- package/requestHandlers/get.js.map +1 -1
- package/requestHandlers/index.d.ts +0 -12
- package/requestHandlers/index.d.ts.map +1 -1
- package/requestHandlers/index.js +2 -2
- package/requestHandlers/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -74,8 +74,8 @@ Alternatively, add Temba to your app manually:
|
|
|
74
74
|
2. Example code to create a Temba server:
|
|
75
75
|
|
|
76
76
|
```js
|
|
77
|
-
import
|
|
78
|
-
const server =
|
|
77
|
+
import { create } from "temba"
|
|
78
|
+
const server = create()
|
|
79
79
|
server.start()
|
|
80
80
|
```
|
|
81
81
|
|
|
@@ -139,7 +139,7 @@ By default data is stored in memory. This means the data is flushed when the ser
|
|
|
139
139
|
const config = {
|
|
140
140
|
connectionString: 'data.json',
|
|
141
141
|
}
|
|
142
|
-
const server =
|
|
142
|
+
const server = create(config)
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
All resources are saved in a single JSON file. The file is not created or updated unless you create, update, or delete resources.
|
|
@@ -150,7 +150,7 @@ All resources are saved in a single JSON file. The file is not created or update
|
|
|
150
150
|
const config = {
|
|
151
151
|
connectionString: 'mongodb://localhost:27017/myDatabase',
|
|
152
152
|
}
|
|
153
|
-
const server =
|
|
153
|
+
const server = create(config)
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
For every resource you use in your requests, a collection is created in the database. However, not until you actually create a resource with a `POST`.
|
|
@@ -163,7 +163,7 @@ If you only want to allow specific resource names, configure them by providing a
|
|
|
163
163
|
const config = {
|
|
164
164
|
resources: ['movies', 'actors'],
|
|
165
165
|
}
|
|
166
|
-
const server =
|
|
166
|
+
const server = create(config)
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
Requests on these resources only give a `404 Not Found` if the ID does not exist. Requests on any other resource will always return a `404 Not Found`.
|
|
@@ -176,7 +176,7 @@ If you want to host static assets, for example next to the API, a web app consum
|
|
|
176
176
|
const config = {
|
|
177
177
|
staticFolder: 'build',
|
|
178
178
|
}
|
|
179
|
-
const server =
|
|
179
|
+
const server = create(config)
|
|
180
180
|
```
|
|
181
181
|
|
|
182
182
|
With this setting, sending a `GET` request to the root URL, returns the content that is in the `'./build'` folder in your project.
|
|
@@ -195,7 +195,7 @@ With the `apiPrefix` config setting, all resources get an extra path segment in
|
|
|
195
195
|
const config = {
|
|
196
196
|
apiPrefix: 'api',
|
|
197
197
|
}
|
|
198
|
-
const server =
|
|
198
|
+
const server = create(config)
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
A request to the `apiPrefix` (e.g. http://localhost:1234/api) will now return the `"It works! ツ"` response message.
|
|
@@ -251,7 +251,7 @@ const config = {
|
|
|
251
251
|
},
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
const server =
|
|
254
|
+
const server = create(config)
|
|
255
255
|
```
|
|
256
256
|
|
|
257
257
|
If a request is not valid according to the schema, a `400 Bad Request` response is returned, and a message in the response body indicating the validation error.
|
|
@@ -283,7 +283,7 @@ const config = {
|
|
|
283
283
|
},
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
const server =
|
|
286
|
+
const server = create(config)
|
|
287
287
|
```
|
|
288
288
|
|
|
289
289
|
The `requestInterceptor` is an object with fields for each of the HTTP methods you might want to intercept, and the callback function you want Temba to call, before processing the request, i.e. going to the database.
|
|
@@ -321,7 +321,7 @@ const config = {
|
|
|
321
321
|
},
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
const server =
|
|
324
|
+
const server = create(config)
|
|
325
325
|
```
|
|
326
326
|
|
|
327
327
|
### Response body interception
|
|
@@ -351,7 +351,7 @@ const config = {
|
|
|
351
351
|
},
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
const server =
|
|
354
|
+
const server = create(config)
|
|
355
355
|
```
|
|
356
356
|
|
|
357
357
|
`responseBodyInterceptor` is a callback function that provides an object containing the `resource`, `body`, and the `id`. Depending on whether it's a collection or item request, the `body` is either an array or object, and the `id` can be `undefined`.
|
|
@@ -392,7 +392,7 @@ const config = {
|
|
|
392
392
|
customRouter: router,
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
const server =
|
|
395
|
+
const server = create(config)
|
|
396
396
|
```
|
|
397
397
|
|
|
398
398
|
> 💁 Don't overuse `customRouter`, as it defeats the purpose of Temba being a simple out-of-the-box solution.
|
|
@@ -418,7 +418,7 @@ const config = {
|
|
|
418
418
|
resources: ['stuff'],
|
|
419
419
|
staticFolder: 'build',
|
|
420
420
|
}
|
|
421
|
-
const server =
|
|
421
|
+
const server = create(config)
|
|
422
422
|
```
|
|
423
423
|
|
|
424
424
|
- `/` will be handled by Temba, and will return the `staticFolder` (`build`) folder contents
|
|
@@ -436,7 +436,6 @@ Here is an example of the config settings for Temba, and how you define them:
|
|
|
436
436
|
const config = {
|
|
437
437
|
allowDeleteCollection: true,
|
|
438
438
|
apiPrefix: 'api',
|
|
439
|
-
cacheControl: 'public, max-age=300',
|
|
440
439
|
connectionString: 'mongodb://localhost:27017/myDatabase',
|
|
441
440
|
customRouter: router,
|
|
442
441
|
delay: 500,
|
|
@@ -476,7 +475,7 @@ const config = {
|
|
|
476
475
|
},
|
|
477
476
|
staticFolder: 'build',
|
|
478
477
|
}
|
|
479
|
-
const server =
|
|
478
|
+
const server = create(config)
|
|
480
479
|
```
|
|
481
480
|
|
|
482
481
|
These are all the possible settings:
|
|
@@ -485,7 +484,6 @@ These are all the possible settings:
|
|
|
485
484
|
| :------------------------ | :----------------------------------------------------------------------------------------- | :------------ |
|
|
486
485
|
| `allowDeleteCollection` | Whether a `DELETE` request on a collection is allowed to delete all items. | `false` |
|
|
487
486
|
| `apiPrefix` | See [API prefix](#api-prefix) | `null` |
|
|
488
|
-
| `cacheControl` | The `Cache-control` response header value for each GET request. | `'no-store'` |
|
|
489
487
|
| `connectionString` | See [Data persistency](#data-persistency) | `null` |
|
|
490
488
|
| `customRouter` | See [Custom router](#custom-router) | `null` |
|
|
491
489
|
| `delay` | The delay, in milliseconds, after processing the request before sending the response. | `0` |
|
package/config/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export type Config = {
|
|
|
6
6
|
validateResources: boolean;
|
|
7
7
|
resources: string[];
|
|
8
8
|
apiPrefix: string | null;
|
|
9
|
-
cacheControl: string;
|
|
10
9
|
requestInterceptor: RequestInterceptor | null;
|
|
11
10
|
responseBodyInterceptor: ResponseBodyInterceptor | null;
|
|
12
11
|
staticFolder: string | null;
|
|
@@ -20,13 +19,12 @@ export type Config = {
|
|
|
20
19
|
allowDeleteCollection: boolean;
|
|
21
20
|
};
|
|
22
21
|
export type ConfigKey = keyof Config;
|
|
23
|
-
export type RouterConfig = Pick<Config, 'validateResources' | 'resources' | 'apiPrefix' | '
|
|
22
|
+
export type RouterConfig = Pick<Config, 'validateResources' | 'resources' | 'apiPrefix' | 'requestInterceptor' | 'responseBodyInterceptor' | 'returnNullFields' | 'allowDeleteCollection'>;
|
|
24
23
|
export type UserConfig = {
|
|
25
24
|
resources?: string[];
|
|
26
25
|
staticFolder?: string;
|
|
27
26
|
apiPrefix?: string;
|
|
28
27
|
connectionString?: string;
|
|
29
|
-
cacheControl?: string;
|
|
30
28
|
delay?: number;
|
|
31
29
|
requestInterceptor?: RequestInterceptor;
|
|
32
30
|
responseBodyInterceptor?: ResponseBodyInterceptor;
|
package/config/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO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AM,MAAM,CAAA;AAEpC,MAAM,MAAM,YAAY,GAAG,IAAI,CAC7B,MAAM,EACJ,mBAAmB,GACnB,WAAW,GACX,WAAW,GACX,oBAAoB,GACpB,yBAAyB,GACzB,kBAAkB,GAClB,uBAAuB,CAC1B,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;IACvC,uBAAuB,CAAC,EAAE,uBAAuB,CAAA;IACjD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAmBD,eAAO,MAAM,UAAU,gBAAiB,UAAU,KAAG,MAgGpD,CAAA;AAED,eAAO,MAAM,WAAW,UAAW,OAAO,uBAAqD,CAAA"}
|
package/config/index.js
CHANGED
|
@@ -5,7 +5,6 @@ const defaultConfig = {
|
|
|
5
5
|
staticFolder: null,
|
|
6
6
|
apiPrefix: null,
|
|
7
7
|
connectionString: null,
|
|
8
|
-
cacheControl: 'no-store',
|
|
9
8
|
delay: 0,
|
|
10
9
|
requestInterceptor: null,
|
|
11
10
|
responseBodyInterceptor: null,
|
|
@@ -33,9 +32,6 @@ export const initConfig = (userConfig) => {
|
|
|
33
32
|
if (userConfig.connectionString && userConfig.connectionString.length > 0) {
|
|
34
33
|
config.connectionString = userConfig.connectionString;
|
|
35
34
|
}
|
|
36
|
-
if (userConfig.cacheControl && userConfig.cacheControl.length > 0) {
|
|
37
|
-
config.cacheControl = userConfig.cacheControl;
|
|
38
|
-
}
|
|
39
35
|
if (userConfig.delay &&
|
|
40
36
|
userConfig.delay !== 0 &&
|
|
41
37
|
typeof Number(userConfig.delay) === 'number' &&
|
package/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAmDhC,MAAM,aAAa,GAAW;IAC5B,SAAS,EAAE,EAAE;IACb,iBAAiB,EAAE,KAAK;IACxB,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,IAAI;IACf,gBAAgB,EAAE,IAAI;IACtB,KAAK,EAAE,CAAC;IACR,kBAAkB,EAAE,IAAI;IACxB,uBAAuB,EAAE,IAAI;IAC7B,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,IAAI;IACtB,SAAS,EAAE,KAAK;IAChB,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,qBAAqB,EAAE,KAAK;CAC7B,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,UAAuB,EAAU,EAAE;IAC5D,IAAI,CAAC,UAAU;QAAE,OAAO,aAAa,CAAA;IAErC,MAAM,MAAM,GAAG,EAAE,GAAG,aAAa,EAAY,CAAA;IAE7C,IAAI,UAAU,CAAC,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5D,MAAM,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAA;QACvC,MAAM,CAAC,iBAAiB,GAAG,IAAI,CAAA;IACjC,CAAC;IAED,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC;Q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E,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;IAC/B,CAAC;IAED,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;IACrC,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,qBAAqB,GAAG,UAAU,CAAC,qBAAqB,CAAA;IACjE,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAsB,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAA"}
|
package/package.json
CHANGED
package/requestHandlers/get.d.ts
CHANGED
|
@@ -2,22 +2,10 @@ import type { Queries } from '../data/types.js';
|
|
|
2
2
|
import type { RequestInterceptor } from '../requestInterceptor/types.js';
|
|
3
3
|
import type { ResponseBodyInterceptor } from '../responseBodyInterceptor/types.js';
|
|
4
4
|
import type { GetRequest } from './types.js';
|
|
5
|
-
export declare const createGetRoutes: (queries: Queries,
|
|
5
|
+
export declare const createGetRoutes: (queries: Queries, requestInterceptor: RequestInterceptor | null, responseBodyInterceptor: ResponseBodyInterceptor | null, returnNullFields: boolean) => (req: GetRequest) => Promise<{
|
|
6
6
|
status: number;
|
|
7
7
|
body: unknown;
|
|
8
|
-
headers: {
|
|
9
|
-
'Cache-control': string;
|
|
10
|
-
};
|
|
11
8
|
} | {
|
|
12
9
|
status: number;
|
|
13
|
-
body: {
|
|
14
|
-
message: string;
|
|
15
|
-
};
|
|
16
|
-
} | {
|
|
17
|
-
status: number;
|
|
18
|
-
headers: {
|
|
19
|
-
'Cache-control': string;
|
|
20
|
-
};
|
|
21
|
-
body?: undefined;
|
|
22
10
|
}>;
|
|
23
11
|
//# sourceMappingURL=get.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/requestHandlers/get.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAG5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAErE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGzC,eAAO,MAAM,eAAe,YACjB,OAAO,
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/requestHandlers/get.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAG5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAErE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGzC,eAAO,MAAM,eAAe,YACjB,OAAO,sBACI,kBAAkB,GAAG,IAAI,2BACpB,uBAAuB,GAAG,IAAI,oBACrC,OAAO,WAIK,UAAU;;;;;EA8DzC,CAAA"}
|
package/requestHandlers/get.js
CHANGED
|
@@ -2,9 +2,8 @@ import { TembaError } from '../requestInterceptor/TembaError.js';
|
|
|
2
2
|
import { interceptGetRequest } from '../requestInterceptor/interceptRequest.js';
|
|
3
3
|
import { interceptResponseBody } from '../responseBodyInterceptor/interceptResponseBody.js';
|
|
4
4
|
import { removeNullFields } from './utils.js';
|
|
5
|
-
export const createGetRoutes = (queries,
|
|
6
|
-
const
|
|
7
|
-
const responseOk = (body) => ({ ...defaultResponse, status: 200, body });
|
|
5
|
+
export const createGetRoutes = (queries, requestInterceptor, responseBodyInterceptor, returnNullFields) => {
|
|
6
|
+
const responseOk = (body) => ({ status: 200, body });
|
|
8
7
|
const handleGet = async (req) => {
|
|
9
8
|
try {
|
|
10
9
|
const { resource, id } = req;
|
|
@@ -22,7 +21,7 @@ export const createGetRoutes = (queries, cacheControl, requestInterceptor, respo
|
|
|
22
21
|
if (id) {
|
|
23
22
|
const item = await queries.getById(resource, id);
|
|
24
23
|
if (!item) {
|
|
25
|
-
return {
|
|
24
|
+
return { status: 404 };
|
|
26
25
|
}
|
|
27
26
|
const theItem = responseBodyInterceptor
|
|
28
27
|
? interceptResponseBody(responseBodyInterceptor, { resource, body: item, id })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/requestHandlers/get.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAE5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kDAAkD,CAAA;AAGxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAAgB,EAChB,
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/requestHandlers/get.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAE5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kDAAkD,CAAA;AAGxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAAgB,EAChB,kBAA6C,EAC7C,uBAAuD,EACvD,gBAAyB,EACzB,EAAE;IACF,MAAM,UAAU,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;IAE7D,MAAM,SAAS,GAAG,KAAK,EAAE,GAAe,EAAE,EAAE;QA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,CAAC,CAAA;oBAC9C,CAAC;gBACH,CAAC;gBAED,OAAO,UAAU,CAAC,OAAO,CAAC,CAAA;YAC5B,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAE5C,MAAM,QAAQ,GAAG,uBAAuB;gBACtC,CAAC,CAAC,qBAAqB,CAAC,uBAAuB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;gBAC3E,CAAC,CAAC,KAAK,CAAA;YAET,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACtB,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC5B,OAAO,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;gBACnE,CAAC;gBAED,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;oBACjC,OAAO,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAA;gBAC/C,CAAC;YACH,CAAC;YAED,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAA;QAC7B,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAG,KAAe,CAAC,OAAO,EAAE,EAAE,CAAA;QACrE,CAAC;IACH,CAAC,CAAA;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA"}
|
|
@@ -5,20 +5,8 @@ export declare const getRequestHandler: (queries: Queries, schemas: CompiledSche
|
|
|
5
5
|
handleGet: (req: import("./types.js").GetRequest) => Promise<{
|
|
6
6
|
status: number;
|
|
7
7
|
body: unknown;
|
|
8
|
-
headers: {
|
|
9
|
-
'Cache-control': string;
|
|
10
|
-
};
|
|
11
|
-
} | {
|
|
12
|
-
status: number;
|
|
13
|
-
body: {
|
|
14
|
-
message: string;
|
|
15
|
-
};
|
|
16
8
|
} | {
|
|
17
9
|
status: number;
|
|
18
|
-
headers: {
|
|
19
|
-
'Cache-control': string;
|
|
20
|
-
};
|
|
21
|
-
body?: undefined;
|
|
22
10
|
}>;
|
|
23
11
|
handlePost: (req: import("./types.js").PostRequest) => Promise<{
|
|
24
12
|
status: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/requestHandlers/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,eAAO,MAAM,iBAAiB,YACnB,OAAO,WACP,eAAe,gBACV,YAAY
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/requestHandlers/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,eAAO,MAAM,iBAAiB,YACnB,OAAO,WACP,eAAe,gBACV,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgC3B,CAAA"}
|
package/requestHandlers/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import { createPutRoutes } from './put.js';
|
|
|
4
4
|
import { createPatchRoutes } from './patch.js';
|
|
5
5
|
import { createDeleteRoutes } from './delete.js';
|
|
6
6
|
export const getRequestHandler = (queries, schemas, routerConfig) => {
|
|
7
|
-
const {
|
|
8
|
-
const handleGet = createGetRoutes(queries,
|
|
7
|
+
const { requestInterceptor, responseBodyInterceptor, returnNullFields, allowDeleteCollection } = routerConfig;
|
|
8
|
+
const handleGet = createGetRoutes(queries, requestInterceptor, responseBodyInterceptor, returnNullFields);
|
|
9
9
|
const handlePost = createPostRoutes(queries, requestInterceptor, returnNullFields, schemas.post);
|
|
10
10
|
const handlePut = createPutRoutes(queries, requestInterceptor, returnNullFields, schemas.put);
|
|
11
11
|
const handlePatch = createPatchRoutes(queries, requestInterceptor, returnNullFields, schemas.patch);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/requestHandlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAM7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAgB,EAChB,OAAwB,EACxB,YAA0B,EAC1B,EAAE;IACF,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/requestHandlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAM7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAgB,EAChB,OAAwB,EACxB,YAA0B,EAC1B,EAAE;IACF,MAAM,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,GAC5F,YAAY,CAAA;IAEd,MA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