@event-driven-io/emmett-expressjs 0.4.0 → 0.5.1
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/dist/application.d.mts +23 -0
- package/dist/application.d.ts +23 -0
- package/dist/application.js +45 -0
- package/dist/application.js.map +1 -0
- package/dist/application.mjs +45 -0
- package/dist/application.mjs.map +1 -0
- package/dist/e2e/decider/api.d.mts +3 -2
- package/dist/e2e/decider/api.d.ts +3 -2
- package/dist/etag.js.map +1 -1
- package/dist/etag.mjs.map +1 -1
- package/dist/handler.d.mts +21 -8
- package/dist/handler.d.ts +21 -8
- package/dist/handler.js.map +1 -1
- package/dist/handler.mjs.map +1 -1
- package/dist/index.d.mts +12 -68
- package/dist/index.d.ts +12 -68
- package/dist/index.js +3 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -93
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/problemDetailsMiddleware.d.mts +1 -7
- package/dist/middlewares/problemDetailsMiddleware.d.ts +1 -7
- package/dist/responses.d.mts +35 -0
- package/dist/responses.d.ts +35 -0
- package/dist/responses.js +50 -0
- package/dist/responses.js.map +1 -0
- package/dist/responses.mjs +50 -0
- package/dist/responses.mjs.map +1 -0
- package/dist/testing/apiE2ESpecification.d.mts +17 -0
- package/dist/testing/apiE2ESpecification.d.ts +17 -0
- package/dist/testing/apiE2ESpecification.js +37 -0
- package/dist/testing/apiE2ESpecification.js.map +1 -0
- package/dist/testing/apiE2ESpecification.mjs +37 -0
- package/dist/testing/apiE2ESpecification.mjs.map +1 -0
- package/dist/testing/apiSpecification.d.mts +4 -7
- package/dist/testing/apiSpecification.d.ts +4 -7
- package/dist/testing/apiSpecification.js +6 -33
- package/dist/testing/apiSpecification.js.map +1 -1
- package/dist/testing/apiSpecification.mjs +5 -32
- package/dist/testing/apiSpecification.mjs.map +1 -1
- package/dist/testing/index.d.mts +5 -3
- package/dist/testing/index.d.ts +5 -3
- package/dist/testing/index.js +2 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/index.mjs +1 -0
- package/dist/testing/index.mjs.map +1 -1
- package/dist/testing/utils.d.mts +12 -0
- package/dist/testing/utils.d.ts +12 -0
- package/dist/testing/utils.js +32 -0
- package/dist/testing/utils.js.map +1 -0
- package/dist/testing/utils.mjs +32 -0
- package/dist/testing/utils.mjs.map +1 -0
- package/package.json +2 -8
- package/dist/e2e/decider/applicationLogicWithOC.int.spec.d.mts +0 -2
- package/dist/e2e/decider/applicationLogicWithOC.int.spec.d.ts +0 -2
- package/dist/e2e/decider/applicationLogicWithOC.int.spec.js +0 -128
- package/dist/e2e/decider/applicationLogicWithOC.int.spec.js.map +0 -1
- package/dist/e2e/decider/applicationLogicWithOC.int.spec.mjs +0 -128
- package/dist/e2e/decider/applicationLogicWithOC.int.spec.mjs.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import express, { Router, Application } from 'express';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { ErrorToProblemDetailsMapping } from './responses.mjs';
|
|
4
|
+
import 'http-problem-details';
|
|
5
|
+
import './etag.mjs';
|
|
6
|
+
import '@event-driven-io/emmett';
|
|
7
|
+
|
|
8
|
+
type WebApiSetup = (router: Router) => void;
|
|
9
|
+
type ApplicationOptions = {
|
|
10
|
+
apis: WebApiSetup[];
|
|
11
|
+
mapError?: ErrorToProblemDetailsMapping;
|
|
12
|
+
enableDefaultExpressEtag?: boolean;
|
|
13
|
+
disableJsonMiddleware?: boolean;
|
|
14
|
+
disableUrlEncodingMiddleware?: boolean;
|
|
15
|
+
disableProblemDetailsMiddleware?: boolean;
|
|
16
|
+
};
|
|
17
|
+
declare const getApplication: (options: ApplicationOptions) => express.Application;
|
|
18
|
+
type StartApiOptions = {
|
|
19
|
+
port?: number;
|
|
20
|
+
};
|
|
21
|
+
declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
22
|
+
|
|
23
|
+
export { type ApplicationOptions, type StartApiOptions, type WebApiSetup, getApplication, startAPI };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import express, { Router, Application } from 'express';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { ErrorToProblemDetailsMapping } from './responses.js';
|
|
4
|
+
import 'http-problem-details';
|
|
5
|
+
import './etag.js';
|
|
6
|
+
import '@event-driven-io/emmett';
|
|
7
|
+
|
|
8
|
+
type WebApiSetup = (router: Router) => void;
|
|
9
|
+
type ApplicationOptions = {
|
|
10
|
+
apis: WebApiSetup[];
|
|
11
|
+
mapError?: ErrorToProblemDetailsMapping;
|
|
12
|
+
enableDefaultExpressEtag?: boolean;
|
|
13
|
+
disableJsonMiddleware?: boolean;
|
|
14
|
+
disableUrlEncodingMiddleware?: boolean;
|
|
15
|
+
disableProblemDetailsMiddleware?: boolean;
|
|
16
|
+
};
|
|
17
|
+
declare const getApplication: (options: ApplicationOptions) => express.Application;
|
|
18
|
+
type StartApiOptions = {
|
|
19
|
+
port?: number;
|
|
20
|
+
};
|
|
21
|
+
declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
22
|
+
|
|
23
|
+
export { type ApplicationOptions, type StartApiOptions, type WebApiSetup, getApplication, startAPI };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _express = require('express'); var _express2 = _interopRequireDefault(_express);
|
|
2
|
+
require('express-async-errors');
|
|
3
|
+
var _http = require('http'); var _http2 = _interopRequireDefault(_http);
|
|
4
|
+
var _problemDetailsMiddleware = require('./middlewares/problemDetailsMiddleware');
|
|
5
|
+
const getApplication = (options) => {
|
|
6
|
+
const app = _express2.default.call(void 0, );
|
|
7
|
+
const {
|
|
8
|
+
apis,
|
|
9
|
+
mapError,
|
|
10
|
+
enableDefaultExpressEtag,
|
|
11
|
+
disableJsonMiddleware,
|
|
12
|
+
disableUrlEncodingMiddleware,
|
|
13
|
+
disableProblemDetailsMiddleware
|
|
14
|
+
} = options;
|
|
15
|
+
const router = _express.Router.call(void 0, );
|
|
16
|
+
app.set("etag", _nullishCoalesce(enableDefaultExpressEtag, () => ( false)));
|
|
17
|
+
if (!disableJsonMiddleware)
|
|
18
|
+
app.use(_express2.default.json());
|
|
19
|
+
if (!disableUrlEncodingMiddleware)
|
|
20
|
+
app.use(
|
|
21
|
+
_express2.default.urlencoded({
|
|
22
|
+
extended: true
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
for (const api of apis) {
|
|
26
|
+
api(router);
|
|
27
|
+
}
|
|
28
|
+
app.use(router);
|
|
29
|
+
if (!disableProblemDetailsMiddleware)
|
|
30
|
+
app.use(_problemDetailsMiddleware.problemDetailsMiddleware.call(void 0, mapError));
|
|
31
|
+
return app;
|
|
32
|
+
};
|
|
33
|
+
const startAPI = (app, options = { port: 3e3 }) => {
|
|
34
|
+
const { port } = options;
|
|
35
|
+
const server = _http2.default.createServer(app);
|
|
36
|
+
server.on("listening", () => {
|
|
37
|
+
console.info("server up listening");
|
|
38
|
+
});
|
|
39
|
+
return server.listen(port);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.getApplication = getApplication; exports.startAPI = startAPI;
|
|
45
|
+
//# sourceMappingURL=application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/application.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,cAAgC;AAClD,OAAO;AACP,OAAO,UAAU;AACjB,SAAS,gCAAgC;AAgBlC,MAAM,iBAAiB,CAAC,YAAgC;AAC7D,QAAM,MAAmB,QAAQ;AAEjC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,SAAS,OAAO;AAItB,MAAI,IAAI,QAAQ,4BAA4B,KAAK;AAGjD,MAAI,CAAC;AAAuB,QAAI,IAAI,QAAQ,KAAK,CAAC;AAGlD,MAAI,CAAC;AACH,QAAI;AAAA,MACF,QAAQ,WAAW;AAAA,QACjB,UAAU;AAAA,MACZ,CAAC;AAAA,IACH;AAEF,aAAW,OAAO,MAAM;AACtB,QAAI,MAAM;AAAA,EACZ;AACA,MAAI,IAAI,MAAM;AAGd,MAAI,CAAC;AACH,QAAI,IAAI,yBAAyB,QAAQ,CAAC;AAE5C,SAAO;AACT;AAMO,MAAM,WAAW,CACtB,KACA,UAA2B,EAAE,MAAM,IAAK,MACrC;AACH,QAAM,EAAE,KAAK,IAAI;AACjB,QAAM,SAAS,KAAK,aAAa,GAAG;AAEpC,SAAO,GAAG,aAAa,MAAM;AAC3B,YAAQ,KAAK,qBAAqB;AAAA,EACpC,CAAC;AAED,SAAO,OAAO,OAAO,IAAI;AAC3B","sourcesContent":["import express, { Router, type Application } from 'express';\nimport 'express-async-errors';\nimport http from 'http';\nimport { problemDetailsMiddleware } from './middlewares/problemDetailsMiddleware';\nimport type { ErrorToProblemDetailsMapping } from './responses';\n\n// #region web-api-setup\nexport type WebApiSetup = (router: Router) => void;\n// #endregion web-api-setup\n\nexport type ApplicationOptions = {\n apis: WebApiSetup[];\n mapError?: ErrorToProblemDetailsMapping;\n enableDefaultExpressEtag?: boolean;\n disableJsonMiddleware?: boolean;\n disableUrlEncodingMiddleware?: boolean;\n disableProblemDetailsMiddleware?: boolean;\n};\n\nexport const getApplication = (options: ApplicationOptions) => {\n const app: Application = express();\n\n const {\n apis,\n mapError,\n enableDefaultExpressEtag,\n disableJsonMiddleware,\n disableUrlEncodingMiddleware,\n disableProblemDetailsMiddleware,\n } = options;\n\n const router = Router();\n\n // disabling default etag behaviour\n // to use etags in if-match and if-not-match headers\n app.set('etag', enableDefaultExpressEtag ?? false);\n\n // add json middleware\n if (!disableJsonMiddleware) app.use(express.json());\n\n // enable url encoded urls and bodies\n if (!disableUrlEncodingMiddleware)\n app.use(\n express.urlencoded({\n extended: true,\n }),\n );\n\n for (const api of apis) {\n api(router);\n }\n app.use(router);\n\n // add problem details middleware\n if (!disableProblemDetailsMiddleware)\n app.use(problemDetailsMiddleware(mapError));\n\n return app;\n};\n\nexport type StartApiOptions = {\n port?: number;\n};\n\nexport const startAPI = (\n app: Application,\n options: StartApiOptions = { port: 3000 },\n) => {\n const { port } = options;\n const server = http.createServer(app);\n\n server.on('listening', () => {\n console.info('server up listening');\n });\n\n return server.listen(port);\n};\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import express, { Router } from "express";
|
|
2
|
+
import "express-async-errors";
|
|
3
|
+
import http from "http";
|
|
4
|
+
import { problemDetailsMiddleware } from "./middlewares/problemDetailsMiddleware";
|
|
5
|
+
const getApplication = (options) => {
|
|
6
|
+
const app = express();
|
|
7
|
+
const {
|
|
8
|
+
apis,
|
|
9
|
+
mapError,
|
|
10
|
+
enableDefaultExpressEtag,
|
|
11
|
+
disableJsonMiddleware,
|
|
12
|
+
disableUrlEncodingMiddleware,
|
|
13
|
+
disableProblemDetailsMiddleware
|
|
14
|
+
} = options;
|
|
15
|
+
const router = Router();
|
|
16
|
+
app.set("etag", enableDefaultExpressEtag ?? false);
|
|
17
|
+
if (!disableJsonMiddleware)
|
|
18
|
+
app.use(express.json());
|
|
19
|
+
if (!disableUrlEncodingMiddleware)
|
|
20
|
+
app.use(
|
|
21
|
+
express.urlencoded({
|
|
22
|
+
extended: true
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
for (const api of apis) {
|
|
26
|
+
api(router);
|
|
27
|
+
}
|
|
28
|
+
app.use(router);
|
|
29
|
+
if (!disableProblemDetailsMiddleware)
|
|
30
|
+
app.use(problemDetailsMiddleware(mapError));
|
|
31
|
+
return app;
|
|
32
|
+
};
|
|
33
|
+
const startAPI = (app, options = { port: 3e3 }) => {
|
|
34
|
+
const { port } = options;
|
|
35
|
+
const server = http.createServer(app);
|
|
36
|
+
server.on("listening", () => {
|
|
37
|
+
console.info("server up listening");
|
|
38
|
+
});
|
|
39
|
+
return server.listen(port);
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
getApplication,
|
|
43
|
+
startAPI
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=application.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/application.ts"],"sourcesContent":["import express, { Router, type Application } from 'express';\nimport 'express-async-errors';\nimport http from 'http';\nimport { problemDetailsMiddleware } from './middlewares/problemDetailsMiddleware';\nimport type { ErrorToProblemDetailsMapping } from './responses';\n\n// #region web-api-setup\nexport type WebApiSetup = (router: Router) => void;\n// #endregion web-api-setup\n\nexport type ApplicationOptions = {\n apis: WebApiSetup[];\n mapError?: ErrorToProblemDetailsMapping;\n enableDefaultExpressEtag?: boolean;\n disableJsonMiddleware?: boolean;\n disableUrlEncodingMiddleware?: boolean;\n disableProblemDetailsMiddleware?: boolean;\n};\n\nexport const getApplication = (options: ApplicationOptions) => {\n const app: Application = express();\n\n const {\n apis,\n mapError,\n enableDefaultExpressEtag,\n disableJsonMiddleware,\n disableUrlEncodingMiddleware,\n disableProblemDetailsMiddleware,\n } = options;\n\n const router = Router();\n\n // disabling default etag behaviour\n // to use etags in if-match and if-not-match headers\n app.set('etag', enableDefaultExpressEtag ?? false);\n\n // add json middleware\n if (!disableJsonMiddleware) app.use(express.json());\n\n // enable url encoded urls and bodies\n if (!disableUrlEncodingMiddleware)\n app.use(\n express.urlencoded({\n extended: true,\n }),\n );\n\n for (const api of apis) {\n api(router);\n }\n app.use(router);\n\n // add problem details middleware\n if (!disableProblemDetailsMiddleware)\n app.use(problemDetailsMiddleware(mapError));\n\n return app;\n};\n\nexport type StartApiOptions = {\n port?: number;\n};\n\nexport const startAPI = (\n app: Application,\n options: StartApiOptions = { port: 3000 },\n) => {\n const { port } = options;\n const server = http.createServer(app);\n\n server.on('listening', () => {\n console.info('server up listening');\n });\n\n return server.listen(port);\n};\n"],"mappings":"AAAA,OAAO,WAAW,cAAgC;AAClD,OAAO;AACP,OAAO,UAAU;AACjB,SAAS,gCAAgC;AAgBlC,MAAM,iBAAiB,CAAC,YAAgC;AAC7D,QAAM,MAAmB,QAAQ;AAEjC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,SAAS,OAAO;AAItB,MAAI,IAAI,QAAQ,4BAA4B,KAAK;AAGjD,MAAI,CAAC;AAAuB,QAAI,IAAI,QAAQ,KAAK,CAAC;AAGlD,MAAI,CAAC;AACH,QAAI;AAAA,MACF,QAAQ,WAAW;AAAA,QACjB,UAAU;AAAA,MACZ,CAAC;AAAA,IACH;AAEF,aAAW,OAAO,MAAM;AACtB,QAAI,MAAM;AAAA,EACZ;AACA,MAAI,IAAI,MAAM;AAGd,MAAI,CAAC;AACH,QAAI,IAAI,yBAAyB,QAAQ,CAAC;AAE5C,SAAO;AACT;AAMO,MAAM,WAAW,CACtB,KACA,UAA2B,EAAE,MAAM,IAAK,MACrC;AACH,QAAM,EAAE,KAAK,IAAI;AACjB,QAAM,SAAS,KAAK,aAAa,GAAG;AAEpC,SAAO,GAAG,aAAa,MAAM;AAC3B,YAAQ,KAAK,qBAAqB;AAAA,EACpC,CAAC;AAED,SAAO,OAAO,OAAO,IAAI;AAC3B;","names":[]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import * as _event_driven_io_emmett_dist_commandHandling_handleCommand from '@event-driven-io/emmett/dist/commandHandling/handleCommand';
|
|
2
|
+
import { ShoppingCart } from './shoppingCart.mjs';
|
|
1
3
|
import * as _event_driven_io_emmett_dist_eventStore_N_YMFCDT from '@event-driven-io/emmett/dist/eventStore-N_YMFCDT';
|
|
2
4
|
import { ShoppingCartCommand } from './businessLogic.mjs';
|
|
3
5
|
import { EventStore } from '@event-driven-io/emmett';
|
|
4
6
|
import { Router } from 'express';
|
|
5
|
-
import './shoppingCart.mjs';
|
|
6
7
|
|
|
7
8
|
declare const handle: (eventStore: EventStore<bigint>, id: string, command: ShoppingCartCommand, options?: {
|
|
8
9
|
expectedStreamVersion?: _event_driven_io_emmett_dist_eventStore_N_YMFCDT.e<bigint> | undefined;
|
|
9
|
-
} | undefined) => Promise<
|
|
10
|
+
} | undefined) => Promise<_event_driven_io_emmett_dist_commandHandling_handleCommand.CommandHandlerResult<ShoppingCart, bigint>>;
|
|
10
11
|
declare const shoppingCartApi: (eventStore: EventStore) => (router: Router) => void;
|
|
11
12
|
|
|
12
13
|
export { handle, shoppingCartApi };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import * as _event_driven_io_emmett_dist_commandHandling_handleCommand from '@event-driven-io/emmett/dist/commandHandling/handleCommand';
|
|
2
|
+
import { ShoppingCart } from './shoppingCart.js';
|
|
1
3
|
import * as _event_driven_io_emmett_dist_eventStore_N_YMFCDT from '@event-driven-io/emmett/dist/eventStore-N_YMFCDT';
|
|
2
4
|
import { ShoppingCartCommand } from './businessLogic.js';
|
|
3
5
|
import { EventStore } from '@event-driven-io/emmett';
|
|
4
6
|
import { Router } from 'express';
|
|
5
|
-
import './shoppingCart.js';
|
|
6
7
|
|
|
7
8
|
declare const handle: (eventStore: EventStore<bigint>, id: string, command: ShoppingCartCommand, options?: {
|
|
8
9
|
expectedStreamVersion?: _event_driven_io_emmett_dist_eventStore_N_YMFCDT.e<bigint> | undefined;
|
|
9
|
-
} | undefined) => Promise<
|
|
10
|
+
} | undefined) => Promise<_event_driven_io_emmett_dist_commandHandling_handleCommand.CommandHandlerResult<ShoppingCart, bigint>>;
|
|
10
11
|
declare const shoppingCartApi: (eventStore: EventStore) => (router: Router) => void;
|
|
11
12
|
|
|
12
13
|
export { handle, shoppingCartApi };
|
package/dist/etag.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/etag.ts"],"names":["ETagErrors"],"mappings":"AAAA,eAA2B;AAOpB,MAAM,cAAc;AAAA,EACzB,UAAU;AAAA,EACV,cAAc;AAAA,EACd,MAAM;AACR;AAKO,MAAM,gBAAgB;AAEtB,IAAW,aAAX,kBAAWA,gBAAX;AACL,EAAAA,YAAA,4BAAyB;AACzB,EAAAA,YAAA,6BAA0B;AAC1B,EAAAA,YAAA,iCAA8B;AAHd,SAAAA;AAAA,GAAA;AAMX,MAAM,aAAa,CAAC,SAAiC;AAC1D,SAAO,cAAc,KAAK,IAAc;AAC1C;AAEO,MAAM,mBAAmB,CAAC,SAAuB;AACtD,QAAM,SAAS,cAAc,KAAK,IAAc;AAChD,MAAI,WAAW,QAAQ,OAAO,WAAW,GAAG;AAC1C,UAAM,IAAI,MAAM,qDAAiC;AAAA,EACnD;AACA,SAAO,OAAO,CAAC;AACjB;AAEO,MAAM,aAAa,CAAC,UAA8C;AACvE,SAAO,MAAM,KAAK;AACpB;AAEO,MAAM,qBAAqB,CAAC,YAA2B;AAC5D,QAAM,OAAO,QAAQ,QAAQ,YAAY,QAAQ;AAEjD,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,uDAAkC;AAAA,EACpD;AAEA,SAAO;AACT;AAEO,MAAM,wBAAwB,CAAC,YAA2B;AAC/D,QAAM,OAAO,QAAQ,QAAQ,YAAY,YAAY;AAErD,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,uDAAkC;AAAA,EACpD;AAEA,SAAQ,MAAM,QAAQ,IAAI,IAAI,KAAK,CAAC,IAAI;AAC1C;AAEO,MAAM,UAAU,CAAC,UAAoB,SAAqB;AAC/D,WAAS,UAAU,YAAY,MAAM,IAAc;AACrD;AAEO,MAAM,0BAA0B,CAAC,YAA6B;
|
|
1
|
+
{"version":3,"sources":["../src/etag.ts"],"names":["ETagErrors"],"mappings":"AAAA,eAA2B;AAOpB,MAAM,cAAc;AAAA,EACzB,UAAU;AAAA,EACV,cAAc;AAAA,EACd,MAAM;AACR;AAKO,MAAM,gBAAgB;AAEtB,IAAW,aAAX,kBAAWA,gBAAX;AACL,EAAAA,YAAA,4BAAyB;AACzB,EAAAA,YAAA,6BAA0B;AAC1B,EAAAA,YAAA,iCAA8B;AAHd,SAAAA;AAAA,GAAA;AAMX,MAAM,aAAa,CAAC,SAAiC;AAC1D,SAAO,cAAc,KAAK,IAAc;AAC1C;AAEO,MAAM,mBAAmB,CAAC,SAAuB;AACtD,QAAM,SAAS,cAAc,KAAK,IAAc;AAChD,MAAI,WAAW,QAAQ,OAAO,WAAW,GAAG;AAC1C,UAAM,IAAI,MAAM,qDAAiC;AAAA,EACnD;AACA,SAAO,OAAO,CAAC;AACjB;AAEO,MAAM,aAAa,CAAC,UAA8C;AACvE,SAAO,MAAM,KAAK;AACpB;AAEO,MAAM,qBAAqB,CAAC,YAA2B;AAC5D,QAAM,OAAO,QAAQ,QAAQ,YAAY,QAAQ;AAEjD,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,uDAAkC;AAAA,EACpD;AAEA,SAAO;AACT;AAEO,MAAM,wBAAwB,CAAC,YAA2B;AAC/D,QAAM,OAAO,QAAQ,QAAQ,YAAY,YAAY;AAErD,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,uDAAkC;AAAA,EACpD;AAEA,SAAQ,MAAM,QAAQ,IAAI,IAAI,KAAK,CAAC,IAAI;AAC1C;AAEO,MAAM,UAAU,CAAC,UAAoB,SAAqB;AAC/D,WAAS,UAAU,YAAY,MAAM,IAAc;AACrD;AAEO,MAAM,0BAA0B,CAAC,YAA6B;AACnE,QAAM,YAAkB,mBAAmB,OAAO;AAElD,SAAO,WAAW,SAAS,IACvB,iBAAiB,SAAS,IACzB;AACP","sourcesContent":["import { type Brand } from '@event-driven-io/emmett';\nimport type { Request, Response } from 'express';\n\n//////////////////////////////////////\n/// ETAG\n//////////////////////////////////////\n\nexport const HeaderNames = {\n IF_MATCH: 'if-match',\n IF_NOT_MATCH: 'if-not-match',\n ETag: 'etag',\n};\n\nexport type WeakETag = Brand<`W/${string}`, 'ETag'>;\nexport type ETag = Brand<string, 'ETag'>;\n\nexport const WeakETagRegex = /W\\/\"(-?\\d+.*)\"/;\n\nexport const enum ETagErrors {\n WRONG_WEAK_ETAG_FORMAT = 'WRONG_WEAK_ETAG_FORMAT',\n MISSING_IF_MATCH_HEADER = 'MISSING_IF_MATCH_HEADER',\n MISSING_IF_NOT_MATCH_HEADER = 'MISSING_IF_NOT_MATCH_HEADER',\n}\n\nexport const isWeakETag = (etag: ETag): etag is WeakETag => {\n return WeakETagRegex.test(etag as string);\n};\n\nexport const getWeakETagValue = (etag: ETag): string => {\n const result = WeakETagRegex.exec(etag as string);\n if (result === null || result.length === 0) {\n throw new Error(ETagErrors.WRONG_WEAK_ETAG_FORMAT);\n }\n return result[1]!;\n};\n\nexport const toWeakETag = (value: number | bigint | string): WeakETag => {\n return `W/\"${value}\"` as WeakETag;\n};\n\nexport const getETagFromIfMatch = (request: Request): ETag => {\n const etag = request.headers[HeaderNames.IF_MATCH];\n\n if (etag === undefined) {\n throw new Error(ETagErrors.MISSING_IF_MATCH_HEADER);\n }\n\n return etag as ETag;\n};\n\nexport const getETagFromIfNotMatch = (request: Request): ETag => {\n const etag = request.headers[HeaderNames.IF_NOT_MATCH];\n\n if (etag === undefined) {\n throw new Error(ETagErrors.MISSING_IF_MATCH_HEADER);\n }\n\n return (Array.isArray(etag) ? etag[0] : etag) as ETag;\n};\n\nexport const setETag = (response: Response, etag: ETag): void => {\n response.setHeader(HeaderNames.ETag, etag as string);\n};\n\nexport const getETagValueFromIfMatch = (request: Request): string => {\n const eTagValue: ETag = getETagFromIfMatch(request);\n\n return isWeakETag(eTagValue)\n ? getWeakETagValue(eTagValue)\n : (eTagValue as string);\n};\n"]}
|
package/dist/etag.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/etag.ts"],"sourcesContent":["import { type Brand } from '@event-driven-io/emmett';\nimport type { Request, Response } from 'express';\n\n//////////////////////////////////////\n/// ETAG\n//////////////////////////////////////\n\nexport const HeaderNames = {\n IF_MATCH: 'if-match',\n IF_NOT_MATCH: 'if-not-match',\n ETag: 'etag',\n};\n\nexport type WeakETag = Brand<`W/${string}`, 'ETag'>;\nexport type ETag = Brand<string, 'ETag'>;\n\nexport const WeakETagRegex = /W\\/\"(-?\\d+.*)\"/;\n\nexport const enum ETagErrors {\n WRONG_WEAK_ETAG_FORMAT = 'WRONG_WEAK_ETAG_FORMAT',\n MISSING_IF_MATCH_HEADER = 'MISSING_IF_MATCH_HEADER',\n MISSING_IF_NOT_MATCH_HEADER = 'MISSING_IF_NOT_MATCH_HEADER',\n}\n\nexport const isWeakETag = (etag: ETag): etag is WeakETag => {\n return WeakETagRegex.test(etag as string);\n};\n\nexport const getWeakETagValue = (etag: ETag): string => {\n const result = WeakETagRegex.exec(etag as string);\n if (result === null || result.length === 0) {\n throw new Error(ETagErrors.WRONG_WEAK_ETAG_FORMAT);\n }\n return result[1]!;\n};\n\nexport const toWeakETag = (value: number | bigint | string): WeakETag => {\n return `W/\"${value}\"` as WeakETag;\n};\n\nexport const getETagFromIfMatch = (request: Request): ETag => {\n const etag = request.headers[HeaderNames.IF_MATCH];\n\n if (etag === undefined) {\n throw new Error(ETagErrors.MISSING_IF_MATCH_HEADER);\n }\n\n return etag as ETag;\n};\n\nexport const getETagFromIfNotMatch = (request: Request): ETag => {\n const etag = request.headers[HeaderNames.IF_NOT_MATCH];\n\n if (etag === undefined) {\n throw new Error(ETagErrors.MISSING_IF_MATCH_HEADER);\n }\n\n return (Array.isArray(etag) ? etag[0] : etag) as ETag;\n};\n\nexport const setETag = (response: Response, etag: ETag): void => {\n response.setHeader(HeaderNames.ETag, etag as string);\n};\n\nexport const getETagValueFromIfMatch = (request: Request): string => {\n
|
|
1
|
+
{"version":3,"sources":["../src/etag.ts"],"sourcesContent":["import { type Brand } from '@event-driven-io/emmett';\nimport type { Request, Response } from 'express';\n\n//////////////////////////////////////\n/// ETAG\n//////////////////////////////////////\n\nexport const HeaderNames = {\n IF_MATCH: 'if-match',\n IF_NOT_MATCH: 'if-not-match',\n ETag: 'etag',\n};\n\nexport type WeakETag = Brand<`W/${string}`, 'ETag'>;\nexport type ETag = Brand<string, 'ETag'>;\n\nexport const WeakETagRegex = /W\\/\"(-?\\d+.*)\"/;\n\nexport const enum ETagErrors {\n WRONG_WEAK_ETAG_FORMAT = 'WRONG_WEAK_ETAG_FORMAT',\n MISSING_IF_MATCH_HEADER = 'MISSING_IF_MATCH_HEADER',\n MISSING_IF_NOT_MATCH_HEADER = 'MISSING_IF_NOT_MATCH_HEADER',\n}\n\nexport const isWeakETag = (etag: ETag): etag is WeakETag => {\n return WeakETagRegex.test(etag as string);\n};\n\nexport const getWeakETagValue = (etag: ETag): string => {\n const result = WeakETagRegex.exec(etag as string);\n if (result === null || result.length === 0) {\n throw new Error(ETagErrors.WRONG_WEAK_ETAG_FORMAT);\n }\n return result[1]!;\n};\n\nexport const toWeakETag = (value: number | bigint | string): WeakETag => {\n return `W/\"${value}\"` as WeakETag;\n};\n\nexport const getETagFromIfMatch = (request: Request): ETag => {\n const etag = request.headers[HeaderNames.IF_MATCH];\n\n if (etag === undefined) {\n throw new Error(ETagErrors.MISSING_IF_MATCH_HEADER);\n }\n\n return etag as ETag;\n};\n\nexport const getETagFromIfNotMatch = (request: Request): ETag => {\n const etag = request.headers[HeaderNames.IF_NOT_MATCH];\n\n if (etag === undefined) {\n throw new Error(ETagErrors.MISSING_IF_MATCH_HEADER);\n }\n\n return (Array.isArray(etag) ? etag[0] : etag) as ETag;\n};\n\nexport const setETag = (response: Response, etag: ETag): void => {\n response.setHeader(HeaderNames.ETag, etag as string);\n};\n\nexport const getETagValueFromIfMatch = (request: Request): string => {\n const eTagValue: ETag = getETagFromIfMatch(request);\n\n return isWeakETag(eTagValue)\n ? getWeakETagValue(eTagValue)\n : (eTagValue as string);\n};\n"],"mappings":"AAAA,eAA2B;AAOpB,MAAM,cAAc;AAAA,EACzB,UAAU;AAAA,EACV,cAAc;AAAA,EACd,MAAM;AACR;AAKO,MAAM,gBAAgB;AAEtB,IAAW,aAAX,kBAAWA,gBAAX;AACL,EAAAA,YAAA,4BAAyB;AACzB,EAAAA,YAAA,6BAA0B;AAC1B,EAAAA,YAAA,iCAA8B;AAHd,SAAAA;AAAA,GAAA;AAMX,MAAM,aAAa,CAAC,SAAiC;AAC1D,SAAO,cAAc,KAAK,IAAc;AAC1C;AAEO,MAAM,mBAAmB,CAAC,SAAuB;AACtD,QAAM,SAAS,cAAc,KAAK,IAAc;AAChD,MAAI,WAAW,QAAQ,OAAO,WAAW,GAAG;AAC1C,UAAM,IAAI,MAAM,qDAAiC;AAAA,EACnD;AACA,SAAO,OAAO,CAAC;AACjB;AAEO,MAAM,aAAa,CAAC,UAA8C;AACvE,SAAO,MAAM,KAAK;AACpB;AAEO,MAAM,qBAAqB,CAAC,YAA2B;AAC5D,QAAM,OAAO,QAAQ,QAAQ,YAAY,QAAQ;AAEjD,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,uDAAkC;AAAA,EACpD;AAEA,SAAO;AACT;AAEO,MAAM,wBAAwB,CAAC,YAA2B;AAC/D,QAAM,OAAO,QAAQ,QAAQ,YAAY,YAAY;AAErD,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,uDAAkC;AAAA,EACpD;AAEA,SAAQ,MAAM,QAAQ,IAAI,IAAI,KAAK,CAAC,IAAI;AAC1C;AAEO,MAAM,UAAU,CAAC,UAAoB,SAAqB;AAC/D,WAAS,UAAU,YAAY,MAAM,IAAc;AACrD;AAEO,MAAM,0BAA0B,CAAC,YAA6B;AACnE,QAAM,YAAkB,mBAAmB,OAAO;AAElD,SAAO,WAAW,SAAS,IACvB,iBAAiB,SAAS,IACzB;AACP;","names":["ETagErrors"]}
|
package/dist/handler.d.mts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import 'qs';
|
|
2
|
-
import 'express-serve-static-core';
|
|
3
|
-
import 'express';
|
|
4
|
-
|
|
5
|
-
import 'http';
|
|
1
|
+
import * as qs from 'qs';
|
|
2
|
+
import * as express_serve_static_core from 'express-serve-static-core';
|
|
3
|
+
import { Request, Response, NextFunction } from 'express';
|
|
4
|
+
import { HttpResponseOptions, CreatedHttpResponseOptions, AcceptedHttpResponseOptions, NoContentHttpResponseOptions, HttpProblemResponseOptions } from './responses.mjs';
|
|
6
5
|
import 'http-problem-details';
|
|
7
6
|
import './etag.mjs';
|
|
8
7
|
import '@event-driven-io/emmett';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
|
|
9
|
+
type HttpHandler<RequestType extends Request> = (request: RequestType) => Promise<HttpResponse> | HttpResponse;
|
|
10
|
+
declare const on: <RequestType extends Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>>(handle: HttpHandler<RequestType>) => (request: RequestType, response: Response, _next: NextFunction) => Promise<void>;
|
|
11
|
+
declare const OK: (options?: HttpResponseOptions) => HttpResponse;
|
|
12
|
+
declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse;
|
|
13
|
+
declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse;
|
|
14
|
+
declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse;
|
|
15
|
+
type HttpResponse = (response: Response) => void;
|
|
16
|
+
declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse;
|
|
17
|
+
declare const BadRequest: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
18
|
+
declare const Forbidden: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
19
|
+
declare const NotFound: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
20
|
+
declare const Conflict: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
21
|
+
declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
22
|
+
declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse;
|
|
23
|
+
|
|
24
|
+
export { Accepted, BadRequest, Conflict, Created, Forbidden, type HttpHandler, HttpProblem, HttpResponse, NoContent, NotFound, OK, PreconditionFailed, on };
|
package/dist/handler.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import 'qs';
|
|
2
|
-
import 'express-serve-static-core';
|
|
3
|
-
import 'express';
|
|
4
|
-
|
|
5
|
-
import 'http';
|
|
1
|
+
import * as qs from 'qs';
|
|
2
|
+
import * as express_serve_static_core from 'express-serve-static-core';
|
|
3
|
+
import { Request, Response, NextFunction } from 'express';
|
|
4
|
+
import { HttpResponseOptions, CreatedHttpResponseOptions, AcceptedHttpResponseOptions, NoContentHttpResponseOptions, HttpProblemResponseOptions } from './responses.js';
|
|
6
5
|
import 'http-problem-details';
|
|
7
6
|
import './etag.js';
|
|
8
7
|
import '@event-driven-io/emmett';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
|
|
9
|
+
type HttpHandler<RequestType extends Request> = (request: RequestType) => Promise<HttpResponse> | HttpResponse;
|
|
10
|
+
declare const on: <RequestType extends Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>>(handle: HttpHandler<RequestType>) => (request: RequestType, response: Response, _next: NextFunction) => Promise<void>;
|
|
11
|
+
declare const OK: (options?: HttpResponseOptions) => HttpResponse;
|
|
12
|
+
declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse;
|
|
13
|
+
declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse;
|
|
14
|
+
declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse;
|
|
15
|
+
type HttpResponse = (response: Response) => void;
|
|
16
|
+
declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse;
|
|
17
|
+
declare const BadRequest: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
18
|
+
declare const Forbidden: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
19
|
+
declare const NotFound: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
20
|
+
declare const Conflict: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
21
|
+
declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
22
|
+
declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse;
|
|
23
|
+
|
|
24
|
+
export { Accepted, BadRequest, Conflict, Created, Forbidden, type HttpHandler, HttpProblem, HttpResponse, NoContent, NotFound, OK, PreconditionFailed, on };
|
package/dist/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,eAA+D;AAC/D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AASA,MAAM,KACX,CAA8B,WAC9B,OACE,SACA,UACA,UACkB;AAClB,QAAM,cAAc,MAAM,QAAQ,QAAQ,OAAO,OAAO,CAAC;AAEzD,SAAO,YAAY,QAAQ;AAC7B;AAGK,MAAM,KACX,CAAC,YACD,CAAC,aAAuB;AACtB,OAAK,UAAU,KAAK,OAAO;AAC7B;AAEK,MAAM,UACX,CAAC,YACD,CAAC,aAAuB;AACtB,cAAY,UAAU,OAAO;AAC/B;AAEK,MAAM,WACX,CAAC,YACD,CAAC,aAAuB;AACtB,eAAa,UAAU,OAAO;AAChC;AAEK,MAAM,YAAY,CACvB,YACiB,aAAa,KAAK,OAAO;AAErC,MAAM,eACX,CAAC,YAAoB,YACrB,CAAC,aAAuB;AACtB,OAAK,UAAU,YAAY,OAAO;AACpC;AAMK,MAAM,aAAa,
|
|
1
|
+
{"version":3,"sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,eAA+D;AAC/D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AASA,MAAM,KACX,CAA8B,WAC9B,OACE,SACA,UACA,UACkB;AAClB,QAAM,cAAc,MAAM,QAAQ,QAAQ,OAAO,OAAO,CAAC;AAEzD,SAAO,YAAY,QAAQ;AAC7B;AAGK,MAAM,KACX,CAAC,YACD,CAAC,aAAuB;AACtB,OAAK,UAAU,KAAK,OAAO;AAC7B;AAEK,MAAM,UACX,CAAC,YACD,CAAC,aAAuB;AACtB,cAAY,UAAU,OAAO;AAC/B;AAEK,MAAM,WACX,CAAC,YACD,CAAC,aAAuB;AACtB,eAAa,UAAU,OAAO;AAChC;AAEK,MAAM,YAAY,CACvB,YACiB,aAAa,KAAK,OAAO;AAErC,MAAM,eACX,CAAC,YAAoB,YACrB,CAAC,aAAuB;AACtB,OAAK,UAAU,YAAY,OAAO;AACpC;AAMK,MAAM,aAAa,CACxB,YACiB,YAAY,KAAK,OAAO;AAEpC,MAAM,YAAY,CAAC,YACxB,YAAY,KAAK,OAAO;AAEnB,MAAM,WAAW,CAAC,YACvB,YAAY,KAAK,OAAO;AAEnB,MAAM,WAAW,CAAC,YACvB,YAAY,KAAK,OAAO;AAEnB,MAAM,qBAAqB,CAChC,YACiB,YAAY,KAAK,OAAO;AAEpC,MAAM,cACX,CAAC,YAAoB,YACrB,CAAC,aAAuB;AACtB,cAAY,UAAU,YAAY,OAAO;AAC3C","sourcesContent":["import { type NextFunction, type Request, type Response } from 'express';\nimport {\n send,\n sendAccepted,\n sendCreated,\n sendProblem,\n type AcceptedHttpResponseOptions,\n type CreatedHttpResponseOptions,\n type HttpProblemResponseOptions,\n type HttpResponseOptions,\n type NoContentHttpResponseOptions,\n} from '.';\n\n// #region httpresponse-on\nexport type HttpResponse = (response: Response) => void;\n\nexport type HttpHandler<RequestType extends Request> = (\n request: RequestType,\n) => Promise<HttpResponse> | HttpResponse;\n\nexport const on =\n <RequestType extends Request>(handle: HttpHandler<RequestType>) =>\n async (\n request: RequestType,\n response: Response,\n _next: NextFunction,\n ): Promise<void> => {\n const setResponse = await Promise.resolve(handle(request));\n\n return setResponse(response);\n };\n// #endregion httpresponse-on\n\nexport const OK =\n (options?: HttpResponseOptions): HttpResponse =>\n (response: Response) => {\n send(response, 200, options);\n };\n\nexport const Created =\n (options: CreatedHttpResponseOptions): HttpResponse =>\n (response: Response) => {\n sendCreated(response, options);\n };\n\nexport const Accepted =\n (options: AcceptedHttpResponseOptions): HttpResponse =>\n (response: Response) => {\n sendAccepted(response, options);\n };\n\nexport const NoContent = (\n options?: NoContentHttpResponseOptions,\n): HttpResponse => HttpResponse(204, options);\n\nexport const HttpResponse =\n (statusCode: number, options?: HttpResponseOptions): HttpResponse =>\n (response: Response) => {\n send(response, statusCode, options);\n };\n\n/////////////////////\n// ERRORS\n/////////////////////\n\nexport const BadRequest = (\n options?: HttpProblemResponseOptions,\n): HttpResponse => HttpProblem(400, options);\n\nexport const Forbidden = (options?: HttpProblemResponseOptions): HttpResponse =>\n HttpProblem(403, options);\n\nexport const NotFound = (options?: HttpProblemResponseOptions): HttpResponse =>\n HttpProblem(404, options);\n\nexport const Conflict = (options?: HttpProblemResponseOptions): HttpResponse =>\n HttpProblem(409, options);\n\nexport const PreconditionFailed = (\n options: HttpProblemResponseOptions,\n): HttpResponse => HttpProblem(412, options);\n\nexport const HttpProblem =\n (statusCode: number, options?: HttpProblemResponseOptions): HttpResponse =>\n (response: Response) => {\n sendProblem(response, statusCode, options);\n };\n"]}
|
package/dist/handler.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handler.ts"],"sourcesContent":["import { type NextFunction, type Request, type Response } from 'express';\nimport {\n send,\n sendAccepted,\n sendCreated,\n sendProblem,\n type AcceptedHttpResponseOptions,\n type CreatedHttpResponseOptions,\n type HttpProblemResponseOptions,\n type HttpResponseOptions,\n type NoContentHttpResponseOptions,\n} from '.';\n\n// #region httpresponse-on\nexport type HttpResponse = (response: Response) => void;\n\nexport type HttpHandler<RequestType extends Request> = (\n request: RequestType,\n) => Promise<HttpResponse> | HttpResponse;\n\nexport const on =\n <RequestType extends Request>(handle: HttpHandler<RequestType>) =>\n async (\n request: RequestType,\n response: Response,\n _next: NextFunction,\n ): Promise<void> => {\n const setResponse = await Promise.resolve(handle(request));\n\n return setResponse(response);\n };\n// #endregion httpresponse-on\n\nexport const OK =\n (options?: HttpResponseOptions): HttpResponse =>\n (response: Response) => {\n send(response, 200, options);\n };\n\nexport const Created =\n (options: CreatedHttpResponseOptions): HttpResponse =>\n (response: Response) => {\n sendCreated(response, options);\n };\n\nexport const Accepted =\n (options: AcceptedHttpResponseOptions): HttpResponse =>\n (response: Response) => {\n sendAccepted(response, options);\n };\n\nexport const NoContent = (\n options?: NoContentHttpResponseOptions,\n): HttpResponse => HttpResponse(204, options);\n\nexport const HttpResponse =\n (statusCode: number, options?: HttpResponseOptions): HttpResponse =>\n (response: Response) => {\n send(response, statusCode, options);\n };\n\n/////////////////////\n// ERRORS\n/////////////////////\n\nexport const BadRequest = (options
|
|
1
|
+
{"version":3,"sources":["../src/handler.ts"],"sourcesContent":["import { type NextFunction, type Request, type Response } from 'express';\nimport {\n send,\n sendAccepted,\n sendCreated,\n sendProblem,\n type AcceptedHttpResponseOptions,\n type CreatedHttpResponseOptions,\n type HttpProblemResponseOptions,\n type HttpResponseOptions,\n type NoContentHttpResponseOptions,\n} from '.';\n\n// #region httpresponse-on\nexport type HttpResponse = (response: Response) => void;\n\nexport type HttpHandler<RequestType extends Request> = (\n request: RequestType,\n) => Promise<HttpResponse> | HttpResponse;\n\nexport const on =\n <RequestType extends Request>(handle: HttpHandler<RequestType>) =>\n async (\n request: RequestType,\n response: Response,\n _next: NextFunction,\n ): Promise<void> => {\n const setResponse = await Promise.resolve(handle(request));\n\n return setResponse(response);\n };\n// #endregion httpresponse-on\n\nexport const OK =\n (options?: HttpResponseOptions): HttpResponse =>\n (response: Response) => {\n send(response, 200, options);\n };\n\nexport const Created =\n (options: CreatedHttpResponseOptions): HttpResponse =>\n (response: Response) => {\n sendCreated(response, options);\n };\n\nexport const Accepted =\n (options: AcceptedHttpResponseOptions): HttpResponse =>\n (response: Response) => {\n sendAccepted(response, options);\n };\n\nexport const NoContent = (\n options?: NoContentHttpResponseOptions,\n): HttpResponse => HttpResponse(204, options);\n\nexport const HttpResponse =\n (statusCode: number, options?: HttpResponseOptions): HttpResponse =>\n (response: Response) => {\n send(response, statusCode, options);\n };\n\n/////////////////////\n// ERRORS\n/////////////////////\n\nexport const BadRequest = (\n options?: HttpProblemResponseOptions,\n): HttpResponse => HttpProblem(400, options);\n\nexport const Forbidden = (options?: HttpProblemResponseOptions): HttpResponse =>\n HttpProblem(403, options);\n\nexport const NotFound = (options?: HttpProblemResponseOptions): HttpResponse =>\n HttpProblem(404, options);\n\nexport const Conflict = (options?: HttpProblemResponseOptions): HttpResponse =>\n HttpProblem(409, options);\n\nexport const PreconditionFailed = (\n options: HttpProblemResponseOptions,\n): HttpResponse => HttpProblem(412, options);\n\nexport const HttpProblem =\n (statusCode: number, options?: HttpProblemResponseOptions): HttpResponse =>\n (response: Response) => {\n sendProblem(response, statusCode, options);\n };\n"],"mappings":"AAAA,eAA+D;AAC/D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AASA,MAAM,KACX,CAA8B,WAC9B,OACE,SACA,UACA,UACkB;AAClB,QAAM,cAAc,MAAM,QAAQ,QAAQ,OAAO,OAAO,CAAC;AAEzD,SAAO,YAAY,QAAQ;AAC7B;AAGK,MAAM,KACX,CAAC,YACD,CAAC,aAAuB;AACtB,OAAK,UAAU,KAAK,OAAO;AAC7B;AAEK,MAAM,UACX,CAAC,YACD,CAAC,aAAuB;AACtB,cAAY,UAAU,OAAO;AAC/B;AAEK,MAAM,WACX,CAAC,YACD,CAAC,aAAuB;AACtB,eAAa,UAAU,OAAO;AAChC;AAEK,MAAM,YAAY,CACvB,YACiB,aAAa,KAAK,OAAO;AAErC,MAAM,eACX,CAAC,YAAoB,YACrB,CAAC,aAAuB;AACtB,OAAK,UAAU,YAAY,OAAO;AACpC;AAMK,MAAM,aAAa,CACxB,YACiB,YAAY,KAAK,OAAO;AAEpC,MAAM,YAAY,CAAC,YACxB,YAAY,KAAK,OAAO;AAEnB,MAAM,WAAW,CAAC,YACvB,YAAY,KAAK,OAAO;AAEnB,MAAM,WAAW,CAAC,YACvB,YAAY,KAAK,OAAO;AAEnB,MAAM,qBAAqB,CAChC,YACiB,YAAY,KAAK,OAAO;AAEpC,MAAM,cACX,CAAC,YAAoB,YACrB,CAAC,aAAuB;AACtB,cAAY,UAAU,YAAY,OAAO;AAC3C;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,71 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export { ApplicationOptions, StartApiOptions, WebApiSetup, getApplication, startAPI } from './application.mjs';
|
|
2
|
+
export { ETag, ETagErrors, HeaderNames, WeakETag, WeakETagRegex, getETagFromIfMatch, getETagFromIfNotMatch, getETagValueFromIfMatch, getWeakETagValue, isWeakETag, setETag, toWeakETag } from './etag.mjs';
|
|
3
|
+
export { Accepted, BadRequest, Conflict, Created, Forbidden, HttpHandler, HttpProblem, HttpResponse, NoContent, NotFound, OK, PreconditionFailed, on } from './handler.mjs';
|
|
4
|
+
export { AcceptedHttpResponseOptions, CreatedHttpResponseOptions, DefaultHttpProblemResponseOptions, DefaultHttpResponseOptions, ErrorToProblemDetailsMapping, HttpProblemResponseOptions, HttpResponseOptions, NoContentHttpResponseOptions, send, sendAccepted, sendCreated, sendProblem } from './responses.mjs';
|
|
5
|
+
export { ApiE2ESpecification, ApiE2ESpecificationAssert, E2EResponseAssert } from './testing/apiE2ESpecification.mjs';
|
|
6
|
+
export { ApiSpecification, ApiSpecificationAssert, ResponseAssert, existingStream, expect, expectError, expectNewEvents, expectResponse } from './testing/apiSpecification.mjs';
|
|
7
|
+
import 'express';
|
|
8
|
+
import 'http';
|
|
9
9
|
import '@event-driven-io/emmett';
|
|
10
|
+
import 'qs';
|
|
11
|
+
import 'express-serve-static-core';
|
|
12
|
+
import 'http-problem-details';
|
|
10
13
|
import 'supertest';
|
|
11
14
|
import 'supertest/lib/agent';
|
|
12
|
-
|
|
13
|
-
type ErrorToProblemDetailsMapping = (error: Error, request: Request) => ProblemDocument | undefined;
|
|
14
|
-
type WebApiSetup = (router: Router) => void;
|
|
15
|
-
type ApplicationOptions = {
|
|
16
|
-
apis: WebApiSetup[];
|
|
17
|
-
mapError?: ErrorToProblemDetailsMapping;
|
|
18
|
-
enableDefaultExpressEtag?: boolean;
|
|
19
|
-
disableJsonMiddleware?: boolean;
|
|
20
|
-
disableUrlEncodingMiddleware?: boolean;
|
|
21
|
-
disableProblemDetailsMiddleware?: boolean;
|
|
22
|
-
};
|
|
23
|
-
declare const getApplication: (options: ApplicationOptions) => express.Application;
|
|
24
|
-
type StartApiOptions = {
|
|
25
|
-
port?: number;
|
|
26
|
-
};
|
|
27
|
-
declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
28
|
-
type HttpResponseOptions = {
|
|
29
|
-
body?: unknown;
|
|
30
|
-
location?: string;
|
|
31
|
-
eTag?: ETag;
|
|
32
|
-
};
|
|
33
|
-
declare const DefaultHttpResponseOptions: HttpResponseOptions;
|
|
34
|
-
type HttpProblemResponseOptions = {
|
|
35
|
-
location?: string;
|
|
36
|
-
eTag?: ETag;
|
|
37
|
-
} & Omit<HttpResponseOptions, 'body'> & ({
|
|
38
|
-
problem: ProblemDocument;
|
|
39
|
-
} | {
|
|
40
|
-
problemDetails: string;
|
|
41
|
-
});
|
|
42
|
-
declare const DefaultHttpProblemResponseOptions: HttpProblemResponseOptions;
|
|
43
|
-
type CreatedHttpResponseOptions = {
|
|
44
|
-
createdId: string;
|
|
45
|
-
urlPrefix?: string;
|
|
46
|
-
} & HttpResponseOptions;
|
|
47
|
-
declare const sendCreated: (response: Response, { createdId, urlPrefix, eTag }: CreatedHttpResponseOptions) => void;
|
|
48
|
-
type AcceptedHttpResponseOptions = {
|
|
49
|
-
location: string;
|
|
50
|
-
} & HttpResponseOptions;
|
|
51
|
-
declare const sendAccepted: (response: Response, options: AcceptedHttpResponseOptions) => void;
|
|
52
|
-
type NoContentHttpResponseOptions = Omit<HttpResponseOptions, 'body'>;
|
|
53
|
-
declare const send: (response: Response, statusCode: number, options?: HttpResponseOptions) => void;
|
|
54
|
-
declare const sendProblem: (response: Response, statusCode: number, options?: HttpProblemResponseOptions) => void;
|
|
55
|
-
|
|
56
|
-
type HttpHandler<RequestType extends Request> = (request: RequestType) => Promise<HttpResponse> | HttpResponse;
|
|
57
|
-
declare const on: <RequestType extends Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>>(handle: HttpHandler<RequestType>) => (request: RequestType, response: Response, _next: NextFunction) => Promise<void>;
|
|
58
|
-
declare const OK: (options?: HttpResponseOptions) => HttpResponse;
|
|
59
|
-
declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse;
|
|
60
|
-
declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse;
|
|
61
|
-
declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse;
|
|
62
|
-
type HttpResponse = (response: Response) => void;
|
|
63
|
-
declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse;
|
|
64
|
-
declare const BadRequest: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
65
|
-
declare const Forbidden: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
66
|
-
declare const NotFound: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
67
|
-
declare const Conflict: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
68
|
-
declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
69
|
-
declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse;
|
|
70
|
-
|
|
71
|
-
export { Accepted, type AcceptedHttpResponseOptions, type ApplicationOptions, BadRequest, Conflict, Created, type CreatedHttpResponseOptions, DefaultHttpProblemResponseOptions, DefaultHttpResponseOptions, ETag, type ErrorToProblemDetailsMapping, Forbidden, type HttpHandler, HttpProblem, type HttpProblemResponseOptions, HttpResponse, type HttpResponseOptions, NoContent, type NoContentHttpResponseOptions, NotFound, OK, PreconditionFailed, type StartApiOptions, type WebApiSetup, getApplication, on, send, sendAccepted, sendCreated, sendProblem, startAPI };
|
|
15
|
+
import './testing/utils.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,71 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export { ApplicationOptions, StartApiOptions, WebApiSetup, getApplication, startAPI } from './application.js';
|
|
2
|
+
export { ETag, ETagErrors, HeaderNames, WeakETag, WeakETagRegex, getETagFromIfMatch, getETagFromIfNotMatch, getETagValueFromIfMatch, getWeakETagValue, isWeakETag, setETag, toWeakETag } from './etag.js';
|
|
3
|
+
export { Accepted, BadRequest, Conflict, Created, Forbidden, HttpHandler, HttpProblem, HttpResponse, NoContent, NotFound, OK, PreconditionFailed, on } from './handler.js';
|
|
4
|
+
export { AcceptedHttpResponseOptions, CreatedHttpResponseOptions, DefaultHttpProblemResponseOptions, DefaultHttpResponseOptions, ErrorToProblemDetailsMapping, HttpProblemResponseOptions, HttpResponseOptions, NoContentHttpResponseOptions, send, sendAccepted, sendCreated, sendProblem } from './responses.js';
|
|
5
|
+
export { ApiE2ESpecification, ApiE2ESpecificationAssert, E2EResponseAssert } from './testing/apiE2ESpecification.js';
|
|
6
|
+
export { ApiSpecification, ApiSpecificationAssert, ResponseAssert, existingStream, expect, expectError, expectNewEvents, expectResponse } from './testing/apiSpecification.js';
|
|
7
|
+
import 'express';
|
|
8
|
+
import 'http';
|
|
9
9
|
import '@event-driven-io/emmett';
|
|
10
|
+
import 'qs';
|
|
11
|
+
import 'express-serve-static-core';
|
|
12
|
+
import 'http-problem-details';
|
|
10
13
|
import 'supertest';
|
|
11
14
|
import 'supertest/lib/agent';
|
|
12
|
-
|
|
13
|
-
type ErrorToProblemDetailsMapping = (error: Error, request: Request) => ProblemDocument | undefined;
|
|
14
|
-
type WebApiSetup = (router: Router) => void;
|
|
15
|
-
type ApplicationOptions = {
|
|
16
|
-
apis: WebApiSetup[];
|
|
17
|
-
mapError?: ErrorToProblemDetailsMapping;
|
|
18
|
-
enableDefaultExpressEtag?: boolean;
|
|
19
|
-
disableJsonMiddleware?: boolean;
|
|
20
|
-
disableUrlEncodingMiddleware?: boolean;
|
|
21
|
-
disableProblemDetailsMiddleware?: boolean;
|
|
22
|
-
};
|
|
23
|
-
declare const getApplication: (options: ApplicationOptions) => express.Application;
|
|
24
|
-
type StartApiOptions = {
|
|
25
|
-
port?: number;
|
|
26
|
-
};
|
|
27
|
-
declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
28
|
-
type HttpResponseOptions = {
|
|
29
|
-
body?: unknown;
|
|
30
|
-
location?: string;
|
|
31
|
-
eTag?: ETag;
|
|
32
|
-
};
|
|
33
|
-
declare const DefaultHttpResponseOptions: HttpResponseOptions;
|
|
34
|
-
type HttpProblemResponseOptions = {
|
|
35
|
-
location?: string;
|
|
36
|
-
eTag?: ETag;
|
|
37
|
-
} & Omit<HttpResponseOptions, 'body'> & ({
|
|
38
|
-
problem: ProblemDocument;
|
|
39
|
-
} | {
|
|
40
|
-
problemDetails: string;
|
|
41
|
-
});
|
|
42
|
-
declare const DefaultHttpProblemResponseOptions: HttpProblemResponseOptions;
|
|
43
|
-
type CreatedHttpResponseOptions = {
|
|
44
|
-
createdId: string;
|
|
45
|
-
urlPrefix?: string;
|
|
46
|
-
} & HttpResponseOptions;
|
|
47
|
-
declare const sendCreated: (response: Response, { createdId, urlPrefix, eTag }: CreatedHttpResponseOptions) => void;
|
|
48
|
-
type AcceptedHttpResponseOptions = {
|
|
49
|
-
location: string;
|
|
50
|
-
} & HttpResponseOptions;
|
|
51
|
-
declare const sendAccepted: (response: Response, options: AcceptedHttpResponseOptions) => void;
|
|
52
|
-
type NoContentHttpResponseOptions = Omit<HttpResponseOptions, 'body'>;
|
|
53
|
-
declare const send: (response: Response, statusCode: number, options?: HttpResponseOptions) => void;
|
|
54
|
-
declare const sendProblem: (response: Response, statusCode: number, options?: HttpProblemResponseOptions) => void;
|
|
55
|
-
|
|
56
|
-
type HttpHandler<RequestType extends Request> = (request: RequestType) => Promise<HttpResponse> | HttpResponse;
|
|
57
|
-
declare const on: <RequestType extends Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>>(handle: HttpHandler<RequestType>) => (request: RequestType, response: Response, _next: NextFunction) => Promise<void>;
|
|
58
|
-
declare const OK: (options?: HttpResponseOptions) => HttpResponse;
|
|
59
|
-
declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse;
|
|
60
|
-
declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse;
|
|
61
|
-
declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse;
|
|
62
|
-
type HttpResponse = (response: Response) => void;
|
|
63
|
-
declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse;
|
|
64
|
-
declare const BadRequest: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
65
|
-
declare const Forbidden: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
66
|
-
declare const NotFound: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
67
|
-
declare const Conflict: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
68
|
-
declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
69
|
-
declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse;
|
|
70
|
-
|
|
71
|
-
export { Accepted, type AcceptedHttpResponseOptions, type ApplicationOptions, BadRequest, Conflict, Created, type CreatedHttpResponseOptions, DefaultHttpProblemResponseOptions, DefaultHttpResponseOptions, ETag, type ErrorToProblemDetailsMapping, Forbidden, type HttpHandler, HttpProblem, type HttpProblemResponseOptions, HttpResponse, type HttpResponseOptions, NoContent, type NoContentHttpResponseOptions, NotFound, OK, PreconditionFailed, type StartApiOptions, type WebApiSetup, getApplication, on, send, sendAccepted, sendCreated, sendProblem, startAPI };
|
|
15
|
+
import './testing/utils.js';
|
package/dist/index.js
CHANGED
|
@@ -1,98 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
2
|
-
|
|
3
|
-
var _express = require('express'); var _express2 = _interopRequireDefault(_express);
|
|
4
|
-
require('express-async-errors');
|
|
5
|
-
var _http = require('http'); var _http2 = _interopRequireDefault(_http);
|
|
6
|
-
var _httpproblemdetails = require('http-problem-details');
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }require('express-async-errors');
|
|
2
|
+
var _application = require('./application'); _createStarExport(_application);
|
|
7
3
|
var _etag = require('./etag'); _createStarExport(_etag);
|
|
8
|
-
var _problemDetailsMiddleware = require('./middlewares/problemDetailsMiddleware');
|
|
9
|
-
|
|
10
4
|
var _handler = require('./handler'); _createStarExport(_handler);
|
|
5
|
+
var _responses = require('./responses'); _createStarExport(_responses);
|
|
11
6
|
var _testing = require('./testing'); _createStarExport(_testing);
|
|
12
|
-
const getApplication = (options) => {
|
|
13
|
-
const app = _express2.default.call(void 0, );
|
|
14
|
-
const {
|
|
15
|
-
apis,
|
|
16
|
-
mapError,
|
|
17
|
-
enableDefaultExpressEtag,
|
|
18
|
-
disableJsonMiddleware,
|
|
19
|
-
disableUrlEncodingMiddleware,
|
|
20
|
-
disableProblemDetailsMiddleware
|
|
21
|
-
} = options;
|
|
22
|
-
const router = _express.Router.call(void 0, );
|
|
23
|
-
app.set("etag", _nullishCoalesce(enableDefaultExpressEtag, () => ( false)));
|
|
24
|
-
if (!disableJsonMiddleware)
|
|
25
|
-
app.use(_express2.default.json());
|
|
26
|
-
if (!disableUrlEncodingMiddleware)
|
|
27
|
-
app.use(
|
|
28
|
-
_express2.default.urlencoded({
|
|
29
|
-
extended: true
|
|
30
|
-
})
|
|
31
|
-
);
|
|
32
|
-
for (const api of apis) {
|
|
33
|
-
api(router);
|
|
34
|
-
}
|
|
35
|
-
app.use(router);
|
|
36
|
-
if (!disableProblemDetailsMiddleware)
|
|
37
|
-
app.use(_problemDetailsMiddleware.problemDetailsMiddleware.call(void 0, mapError));
|
|
38
|
-
return app;
|
|
39
|
-
};
|
|
40
|
-
const startAPI = (app, options = { port: 3e3 }) => {
|
|
41
|
-
const { port } = options;
|
|
42
|
-
const server = _http2.default.createServer(app);
|
|
43
|
-
server.on("listening", () => {
|
|
44
|
-
console.info("server up listening");
|
|
45
|
-
});
|
|
46
|
-
return server.listen(port);
|
|
47
|
-
};
|
|
48
|
-
const DefaultHttpResponseOptions = {};
|
|
49
|
-
const DefaultHttpProblemResponseOptions = {
|
|
50
|
-
problemDetails: "Error occured!"
|
|
51
|
-
};
|
|
52
|
-
const sendCreated = (response, { createdId, urlPrefix, eTag }) => send(response, 201, {
|
|
53
|
-
location: `${_nullishCoalesce(urlPrefix, () => ( response.req.url))}/${createdId}`,
|
|
54
|
-
body: { id: createdId },
|
|
55
|
-
// TODO: https://github.com/event-driven-io/emmett/issues/18
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
57
|
-
eTag
|
|
58
|
-
});
|
|
59
|
-
const sendAccepted = (response, options) => send(response, 202, options);
|
|
60
|
-
const send = (response, statusCode, options) => {
|
|
61
|
-
const { location, body, eTag } = _nullishCoalesce(options, () => ( DefaultHttpResponseOptions));
|
|
62
|
-
if (eTag)
|
|
63
|
-
_etag.setETag.call(void 0, response, eTag);
|
|
64
|
-
if (location)
|
|
65
|
-
response.setHeader("Location", location);
|
|
66
|
-
if (body) {
|
|
67
|
-
response.statusCode = statusCode;
|
|
68
|
-
response.send(body);
|
|
69
|
-
} else {
|
|
70
|
-
response.sendStatus(statusCode);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const sendProblem = (response, statusCode, options) => {
|
|
74
|
-
options = _nullishCoalesce(options, () => ( DefaultHttpProblemResponseOptions));
|
|
75
|
-
const { location, eTag } = options;
|
|
76
|
-
const problemDetails = "problem" in options ? options.problem : new (0, _httpproblemdetails.ProblemDocument)({
|
|
77
|
-
detail: options.problemDetails,
|
|
78
|
-
status: statusCode
|
|
79
|
-
});
|
|
80
|
-
if (eTag)
|
|
81
|
-
_etag.setETag.call(void 0, response, eTag);
|
|
82
|
-
if (location)
|
|
83
|
-
response.setHeader("Location", location);
|
|
84
|
-
response.setHeader("Content-Type", "application/problem+json");
|
|
85
|
-
response.statusCode = statusCode;
|
|
86
|
-
response.json(problemDetails);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
exports.DefaultHttpProblemResponseOptions = DefaultHttpProblemResponseOptions; exports.DefaultHttpResponseOptions = DefaultHttpResponseOptions; exports.getApplication = getApplication; exports.send = send; exports.sendAccepted = sendAccepted; exports.sendCreated = sendCreated; exports.sendProblem = sendProblem; exports.startAPI = startAPI;
|
|
98
7
|
//# sourceMappingURL=index.js.map
|