@loopback/rest 4.0.0-alpha.8 → 5.0.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/CHANGELOG.md +1822 -0
- package/LICENSE +1 -1
- package/README.md +30 -58
- package/dist/body-parsers/body-parser.d.ts +25 -0
- package/dist/body-parsers/body-parser.helpers.d.ts +44 -0
- package/dist/body-parsers/body-parser.helpers.js +102 -0
- package/dist/body-parsers/body-parser.helpers.js.map +1 -0
- package/dist/body-parsers/body-parser.js +159 -0
- package/dist/body-parsers/body-parser.js.map +1 -0
- package/dist/body-parsers/body-parser.json.d.ts +9 -0
- package/dist/body-parsers/body-parser.json.js +43 -0
- package/dist/body-parsers/body-parser.json.js.map +1 -0
- package/dist/body-parsers/body-parser.raw.d.ts +12 -0
- package/dist/body-parsers/body-parser.raw.js +39 -0
- package/dist/body-parsers/body-parser.raw.js.map +1 -0
- package/dist/body-parsers/body-parser.stream.d.ts +12 -0
- package/dist/body-parsers/body-parser.stream.js +28 -0
- package/dist/body-parsers/body-parser.stream.js.map +1 -0
- package/dist/body-parsers/body-parser.text.d.ts +9 -0
- package/dist/body-parsers/body-parser.text.js +38 -0
- package/dist/body-parsers/body-parser.text.js.map +1 -0
- package/dist/body-parsers/body-parser.urlencoded.d.ts +9 -0
- package/dist/body-parsers/body-parser.urlencoded.js +36 -0
- package/dist/body-parsers/body-parser.urlencoded.js.map +1 -0
- package/dist/body-parsers/index.d.ts +8 -0
- package/dist/body-parsers/index.js +16 -0
- package/dist/body-parsers/index.js.map +1 -0
- package/dist/body-parsers/types.d.ts +51 -0
- package/dist/body-parsers/types.js +12 -0
- package/dist/body-parsers/types.js.map +1 -0
- package/dist/coercion/coerce-parameter.d.ts +9 -0
- package/dist/coercion/coerce-parameter.js +166 -0
- package/dist/coercion/coerce-parameter.js.map +1 -0
- package/dist/coercion/utils.d.ts +43 -0
- package/dist/coercion/utils.js +96 -0
- package/dist/coercion/utils.js.map +1 -0
- package/dist/coercion/validator.d.ts +49 -0
- package/dist/coercion/validator.js +85 -0
- package/dist/coercion/validator.js.map +1 -0
- package/dist/http-handler.d.ts +38 -0
- package/dist/http-handler.js +68 -0
- package/dist/http-handler.js.map +1 -0
- package/dist/index.d.ts +36 -1
- package/dist/index.js +40 -6
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +198 -0
- package/dist/keys.js +202 -0
- package/dist/keys.js.map +1 -0
- package/dist/parse-json.d.ts +11 -0
- package/dist/parse-json.js +42 -0
- package/dist/parse-json.js.map +1 -0
- package/dist/parser.d.ts +11 -0
- package/dist/parser.js +76 -0
- package/dist/parser.js.map +1 -0
- package/{dist6/src/providers/find-route.d.ts → dist/providers/find-route.provider.d.ts} +3 -1
- package/dist/providers/find-route.provider.js +36 -0
- package/dist/providers/find-route.provider.js.map +1 -0
- package/dist/providers/index.d.ts +6 -0
- package/dist/providers/index.js +14 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/{src/providers/invoke-method.d.ts → providers/invoke-method.provider.d.ts} +3 -1
- package/dist/providers/invoke-method.provider.js +30 -0
- package/dist/providers/invoke-method.provider.js.map +1 -0
- package/dist/providers/log-error.provider.d.ts +6 -0
- package/dist/providers/log-error.provider.js +21 -0
- package/dist/providers/log-error.provider.js.map +1 -0
- package/dist/providers/parse-params.provider.d.ts +15 -0
- package/dist/providers/parse-params.provider.js +41 -0
- package/dist/providers/parse-params.provider.js.map +1 -0
- package/dist/providers/reject.provider.d.ts +10 -0
- package/dist/providers/reject.provider.js +47 -0
- package/dist/providers/reject.provider.js.map +1 -0
- package/dist/{src/providers/send.d.ts → providers/send.provider.d.ts} +1 -4
- package/dist/{src/providers/send.js → providers/send.provider.js} +4 -6
- package/dist/providers/send.provider.js.map +1 -0
- package/dist/request-context.d.ts +36 -0
- package/dist/request-context.js +104 -0
- package/dist/request-context.js.map +1 -0
- package/dist/rest-http-error.d.ts +37 -0
- package/dist/rest-http-error.js +51 -0
- package/dist/rest-http-error.js.map +1 -0
- package/dist/rest.application.d.ts +232 -0
- package/dist/rest.application.js +174 -0
- package/dist/rest.application.js.map +1 -0
- package/dist/rest.component.d.ts +15 -0
- package/dist/rest.component.js +72 -0
- package/dist/rest.component.js.map +1 -0
- package/dist/rest.server.d.ts +443 -0
- package/dist/rest.server.js +748 -0
- package/dist/rest.server.js.map +1 -0
- package/dist/router/base-route.d.ts +29 -0
- package/dist/router/base-route.js +41 -0
- package/dist/router/base-route.js.map +1 -0
- package/dist/router/controller-route.d.ts +61 -0
- package/dist/router/controller-route.js +160 -0
- package/dist/router/controller-route.js.map +1 -0
- package/dist/router/external-express-routes.d.ts +24 -0
- package/dist/router/external-express-routes.js +90 -0
- package/dist/router/external-express-routes.js.map +1 -0
- package/dist/router/handler-route.d.ts +12 -0
- package/dist/router/handler-route.js +30 -0
- package/dist/router/handler-route.js.map +1 -0
- package/dist/router/index.d.ts +14 -0
- package/dist/router/index.js +25 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/openapi-path.d.ts +14 -0
- package/dist/router/openapi-path.js +64 -0
- package/dist/router/openapi-path.js.map +1 -0
- package/dist/router/redirect-route.d.ts +23 -0
- package/dist/router/redirect-route.js +50 -0
- package/dist/router/redirect-route.js.map +1 -0
- package/dist/router/regexp-router.d.ts +25 -0
- package/dist/router/regexp-router.js +84 -0
- package/dist/router/regexp-router.js.map +1 -0
- package/dist/router/rest-router.d.ts +35 -0
- package/dist/{src/internal-types.js → router/rest-router.js} +2 -2
- package/dist/router/rest-router.js.map +1 -0
- package/dist/router/route-entry.d.ts +46 -0
- package/dist/router/route-entry.js +20 -0
- package/dist/router/route-entry.js.map +1 -0
- package/dist/router/route-sort.d.ts +7 -0
- package/dist/router/route-sort.js +75 -0
- package/dist/router/route-sort.js.map +1 -0
- package/dist/router/router-base.d.ts +42 -0
- package/dist/router/router-base.js +101 -0
- package/dist/router/router-base.js.map +1 -0
- package/dist/router/router-spec.d.ts +3 -0
- package/dist/router/router-spec.js +40 -0
- package/dist/router/router-spec.js.map +1 -0
- package/dist/router/routing-table.d.ts +32 -0
- package/dist/router/routing-table.js +86 -0
- package/dist/router/routing-table.js.map +1 -0
- package/dist/router/trie-router.d.ts +13 -0
- package/dist/router/trie-router.js +55 -0
- package/dist/router/trie-router.js.map +1 -0
- package/dist/router/trie.d.ts +59 -0
- package/dist/router/trie.js +180 -0
- package/dist/router/trie.js.map +1 -0
- package/{dist6/src → dist}/sequence.d.ts +28 -23
- package/dist/sequence.js +112 -0
- package/dist/sequence.js.map +1 -0
- package/dist/spec-enhancers/consolidate.spec-enhancer.d.ts +68 -0
- package/dist/spec-enhancers/consolidate.spec-enhancer.js +145 -0
- package/dist/spec-enhancers/consolidate.spec-enhancer.js.map +1 -0
- package/dist/spec-enhancers/info.spec-enhancer.d.ts +19 -0
- package/dist/spec-enhancers/info.spec-enhancer.js +89 -0
- package/dist/spec-enhancers/info.spec-enhancer.js.map +1 -0
- package/dist/types.d.ts +178 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/validation/ajv-factory.provider.d.ts +12 -0
- package/dist/validation/ajv-factory.provider.js +87 -0
- package/dist/validation/ajv-factory.provider.js.map +1 -0
- package/dist/validation/request-body.validator.d.ts +14 -0
- package/dist/validation/request-body.validator.js +161 -0
- package/dist/validation/request-body.validator.js.map +1 -0
- package/dist/writer.d.ts +9 -0
- package/dist/writer.js +62 -0
- package/dist/writer.js.map +1 -0
- package/package.json +66 -38
- package/src/body-parsers/body-parser.helpers.ts +148 -0
- package/src/body-parsers/body-parser.json.ts +46 -0
- package/src/body-parsers/body-parser.raw.ts +42 -0
- package/src/body-parsers/body-parser.stream.ts +27 -0
- package/src/body-parsers/body-parser.text.ts +44 -0
- package/src/body-parsers/body-parser.ts +208 -0
- package/src/body-parsers/body-parser.urlencoded.ts +42 -0
- package/src/body-parsers/index.ts +13 -0
- package/src/body-parsers/types.ts +60 -0
- package/src/coercion/coerce-parameter.ts +207 -0
- package/src/coercion/utils.ts +103 -0
- package/src/coercion/validator.ts +98 -0
- package/src/http-handler.ts +84 -41
- package/src/index.ts +37 -30
- package/src/keys.ts +273 -20
- package/src/parse-json.ts +42 -0
- package/src/parser.ts +89 -104
- package/src/providers/{find-route.ts → find-route.provider.ts} +10 -7
- package/src/providers/index.ts +7 -9
- package/src/providers/{invoke-method.ts → invoke-method.provider.ts} +8 -5
- package/src/providers/log-error.provider.ts +27 -0
- package/src/providers/parse-params.provider.ts +42 -0
- package/src/providers/reject.provider.ts +44 -0
- package/src/providers/{send.ts → send.provider.ts} +2 -5
- package/src/request-context.ts +123 -0
- package/src/rest-http-error.ts +87 -0
- package/src/rest.application.ts +390 -0
- package/src/rest.component.ts +111 -0
- package/src/rest.server.ts +1192 -0
- package/src/router/base-route.ts +53 -0
- package/src/router/controller-route.ts +241 -0
- package/src/router/external-express-routes.ts +139 -0
- package/src/router/handler-route.ts +44 -0
- package/src/router/index.ts +24 -0
- package/src/router/openapi-path.ts +67 -0
- package/src/router/redirect-route.ts +64 -0
- package/src/router/regexp-router.ts +104 -0
- package/src/router/rest-router.ts +48 -0
- package/src/router/route-entry.ts +74 -0
- package/src/router/route-sort.ts +74 -0
- package/src/router/router-base.ts +124 -0
- package/src/router/router-spec.ts +36 -0
- package/src/router/routing-table.ts +83 -279
- package/src/router/trie-router.ts +57 -0
- package/src/router/trie.ts +233 -0
- package/src/sequence.ts +44 -37
- package/src/spec-enhancers/consolidate.spec-enhancer.ts +182 -0
- package/src/spec-enhancers/info.spec-enhancer.ts +92 -0
- package/src/types.ts +216 -0
- package/src/validation/ajv-factory.provider.ts +94 -0
- package/src/validation/request-body.validator.ts +208 -0
- package/src/writer.ts +41 -68
- package/api-docs/.DS_Store +0 -0
- package/api-docs/apple-touch-icon-114x114-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-144x144-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-57x57-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-72x72-precomposed.png +0 -0
- package/api-docs/apple-touch-icon-precomposed.png +0 -0
- package/api-docs/apple-touch-icon.png +0 -0
- package/api-docs/css/bootstrap.min.css +0 -9
- package/api-docs/css/code-themes/arta.css +0 -158
- package/api-docs/css/code-themes/ascetic.css +0 -50
- package/api-docs/css/code-themes/brown_paper.css +0 -104
- package/api-docs/css/code-themes/brown_papersq.png +0 -0
- package/api-docs/css/code-themes/dark.css +0 -103
- package/api-docs/css/code-themes/default.css +0 -135
- package/api-docs/css/code-themes/far.css +0 -111
- package/api-docs/css/code-themes/github.css +0 -127
- package/api-docs/css/code-themes/googlecode.css +0 -144
- package/api-docs/css/code-themes/idea.css +0 -121
- package/api-docs/css/code-themes/ir_black.css +0 -104
- package/api-docs/css/code-themes/magula.css +0 -121
- package/api-docs/css/code-themes/monokai.css +0 -114
- package/api-docs/css/code-themes/pojoaque.css +0 -104
- package/api-docs/css/code-themes/pojoaque.jpg +0 -0
- package/api-docs/css/code-themes/rainbow.css +0 -114
- package/api-docs/css/code-themes/school_book.css +0 -111
- package/api-docs/css/code-themes/school_book.png +0 -0
- package/api-docs/css/code-themes/sl-theme.css +0 -45
- package/api-docs/css/code-themes/solarized_dark.css +0 -88
- package/api-docs/css/code-themes/solarized_light.css +0 -88
- package/api-docs/css/code-themes/sunburst.css +0 -158
- package/api-docs/css/code-themes/tomorrow-night-blue.css +0 -52
- package/api-docs/css/code-themes/tomorrow-night-bright.css +0 -51
- package/api-docs/css/code-themes/tomorrow-night-eighties.css +0 -51
- package/api-docs/css/code-themes/tomorrow-night.css +0 -52
- package/api-docs/css/code-themes/tomorrow.css +0 -49
- package/api-docs/css/code-themes/vs.css +0 -86
- package/api-docs/css/code-themes/xcode.css +0 -154
- package/api-docs/css/code-themes/zenburn.css +0 -115
- package/api-docs/css/main.css +0 -139
- package/api-docs/favicon.ico +0 -0
- package/api-docs/fonts/0ihfXUL2emPh0ROJezvraLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/fonts/OsJ2DjdpjqFRVUSto6IffLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/fonts/_aijTyevf54tkVDLy-dlnLO3LdcAZYWl9Si6vvxL-qU.woff +0 -0
- package/api-docs/index.html +0 -7082
- package/api-docs/js/main.js +0 -19
- package/api-docs/js/vendor/bootstrap.min.js +0 -6
- package/api-docs/js/vendor/jquery-1.10.1.min.js +0 -6
- package/api-docs/js/vendor/jquery.scrollTo-1.4.3.1.js +0 -218
- package/api-docs/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js +0 -11
- package/dist/src/http-handler.d.ts +0 -19
- package/dist/src/http-handler.js +0 -43
- package/dist/src/http-handler.js.map +0 -1
- package/dist/src/index.d.ts +0 -14
- package/dist/src/index.js +0 -33
- package/dist/src/index.js.map +0 -1
- package/dist/src/internal-types.d.ts +0 -67
- package/dist/src/internal-types.js.map +0 -1
- package/dist/src/keys.d.ts +0 -22
- package/dist/src/keys.js +0 -35
- package/dist/src/keys.js.map +0 -1
- package/dist/src/parser.d.ts +0 -11
- package/dist/src/parser.js +0 -98
- package/dist/src/parser.js.map +0 -1
- package/dist/src/providers/bind-element.d.ts +0 -7
- package/dist/src/providers/bind-element.js +0 -34
- package/dist/src/providers/bind-element.js.map +0 -1
- package/dist/src/providers/find-route.d.ts +0 -9
- package/dist/src/providers/find-route.js +0 -42
- package/dist/src/providers/find-route.js.map +0 -1
- package/dist/src/providers/get-from-context.d.ts +0 -7
- package/dist/src/providers/get-from-context.js +0 -34
- package/dist/src/providers/get-from-context.js.map +0 -1
- package/dist/src/providers/index.d.ts +0 -8
- package/dist/src/providers/index.js +0 -18
- package/dist/src/providers/index.js.map +0 -1
- package/dist/src/providers/invoke-method.js +0 -36
- package/dist/src/providers/invoke-method.js.map +0 -1
- package/dist/src/providers/log-error-provider.d.ts +0 -6
- package/dist/src/providers/log-error-provider.js +0 -17
- package/dist/src/providers/log-error-provider.js.map +0 -1
- package/dist/src/providers/parse-params.d.ts +0 -13
- package/dist/src/providers/parse-params.js +0 -22
- package/dist/src/providers/parse-params.js.map +0 -1
- package/dist/src/providers/reject.d.ts +0 -6
- package/dist/src/providers/reject.js +0 -40
- package/dist/src/providers/reject.js.map +0 -1
- package/dist/src/providers/send.js.map +0 -1
- package/dist/src/rest-component.d.ts +0 -12
- package/dist/src/rest-component.js +0 -50
- package/dist/src/rest-component.js.map +0 -1
- package/dist/src/rest-server.d.ts +0 -211
- package/dist/src/rest-server.js +0 -426
- package/dist/src/rest-server.js.map +0 -1
- package/dist/src/router/metadata.d.ts +0 -150
- package/dist/src/router/metadata.js +0 -410
- package/dist/src/router/metadata.js.map +0 -1
- package/dist/src/router/routing-table.d.ts +0 -68
- package/dist/src/router/routing-table.js +0 -204
- package/dist/src/router/routing-table.js.map +0 -1
- package/dist/src/sequence.d.ts +0 -81
- package/dist/src/sequence.js +0 -104
- package/dist/src/sequence.js.map +0 -1
- package/dist/src/writer.d.ts +0 -17
- package/dist/src/writer.js +0 -87
- package/dist/src/writer.js.map +0 -1
- package/dist6/index.d.ts +0 -1
- package/dist6/index.js +0 -12
- package/dist6/src/http-handler.d.ts +0 -19
- package/dist6/src/http-handler.js +0 -53
- package/dist6/src/http-handler.js.map +0 -1
- package/dist6/src/index.d.ts +0 -14
- package/dist6/src/index.js +0 -33
- package/dist6/src/index.js.map +0 -1
- package/dist6/src/internal-types.d.ts +0 -67
- package/dist6/src/internal-types.js +0 -7
- package/dist6/src/internal-types.js.map +0 -1
- package/dist6/src/keys.d.ts +0 -22
- package/dist6/src/keys.js +0 -35
- package/dist6/src/keys.js.map +0 -1
- package/dist6/src/parser.d.ts +0 -11
- package/dist6/src/parser.js +0 -108
- package/dist6/src/parser.js.map +0 -1
- package/dist6/src/providers/bind-element.d.ts +0 -7
- package/dist6/src/providers/bind-element.js +0 -34
- package/dist6/src/providers/bind-element.js.map +0 -1
- package/dist6/src/providers/find-route.js +0 -42
- package/dist6/src/providers/find-route.js.map +0 -1
- package/dist6/src/providers/get-from-context.d.ts +0 -7
- package/dist6/src/providers/get-from-context.js +0 -34
- package/dist6/src/providers/get-from-context.js.map +0 -1
- package/dist6/src/providers/index.d.ts +0 -8
- package/dist6/src/providers/index.js +0 -18
- package/dist6/src/providers/index.js.map +0 -1
- package/dist6/src/providers/invoke-method.d.ts +0 -7
- package/dist6/src/providers/invoke-method.js +0 -44
- package/dist6/src/providers/invoke-method.js.map +0 -1
- package/dist6/src/providers/log-error-provider.d.ts +0 -6
- package/dist6/src/providers/log-error-provider.js +0 -17
- package/dist6/src/providers/log-error-provider.js.map +0 -1
- package/dist6/src/providers/parse-params.d.ts +0 -13
- package/dist6/src/providers/parse-params.js +0 -22
- package/dist6/src/providers/parse-params.js.map +0 -1
- package/dist6/src/providers/reject.d.ts +0 -6
- package/dist6/src/providers/reject.js +0 -40
- package/dist6/src/providers/reject.js.map +0 -1
- package/dist6/src/providers/send.d.ts +0 -15
- package/dist6/src/providers/send.js +0 -24
- package/dist6/src/providers/send.js.map +0 -1
- package/dist6/src/rest-component.d.ts +0 -12
- package/dist6/src/rest-component.js +0 -50
- package/dist6/src/rest-component.js.map +0 -1
- package/dist6/src/rest-server.d.ts +0 -211
- package/dist6/src/rest-server.js +0 -444
- package/dist6/src/rest-server.js.map +0 -1
- package/dist6/src/router/metadata.d.ts +0 -150
- package/dist6/src/router/metadata.js +0 -410
- package/dist6/src/router/metadata.js.map +0 -1
- package/dist6/src/router/routing-table.d.ts +0 -68
- package/dist6/src/router/routing-table.js +0 -218
- package/dist6/src/router/routing-table.js.map +0 -1
- package/dist6/src/sequence.js +0 -114
- package/dist6/src/sequence.js.map +0 -1
- package/dist6/src/writer.d.ts +0 -17
- package/dist6/src/writer.js +0 -87
- package/dist6/src/writer.js.map +0 -1
- package/index.d.ts +0 -6
- package/index.js +0 -9
- package/src/internal-types.ts +0 -96
- package/src/providers/bind-element.ts +0 -15
- package/src/providers/get-from-context.ts +0 -16
- package/src/providers/log-error-provider.ts +0 -23
- package/src/providers/parse-params.ts +0 -20
- package/src/providers/reject.ts +0 -27
- package/src/rest-component.ts +0 -54
- package/src/rest-server.ts +0 -584
- package/src/router/metadata.ts +0 -517
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/coercion/validator.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAGhE,2BAAmC;AAgBnC;;;GAGG;AACH,MAAa,SAAS;IACpB,YAAmB,GAAsB;QAAtB,QAAG,GAAH,GAAG,CAAmB;IAAG,CAAC;IAE7C;;;;;;;OAOG;IACH,2BAA2B,CACzB,KAAkC,EAClC,IAAwB;QAExB,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACjD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC;YACzC,MAAM,kBAAc,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAC5C;IACH,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,IAAwB;QACjC,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QACjD,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ;YAAE,OAAO,IAAI,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACH,8DAA8D;IAC9D,QAAQ,CAAC,KAAU;;QACjB,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QAErD,MAAM,IAAI,GAAoB,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC;QACrD,MAAM,MAAM,SAAiB,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,mCAAI,EAAE,CAAC;QACjE,MAAM,WAAW,GAAG,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,IAAI,CAAC;QAEvD,IAAI,IAAI,CAAC,qBAAqB,EAAE,EAAE;YAChC,sDAAsD;YACtD,wBAAwB;YACxB,IAAI,WAAW;gBAAE,OAAO,IAAI,CAAC;SAC9B;aAAM,IAAI,IAAI,CAAC,MAAM,EAAE;YACtB,4EAA4E;YAC5E,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,WAAW;gBAAE,OAAO,IAAI,CAAC;SAC1D;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACH,qBAAqB;;QACnB,MAAM,IAAI,GAAoB,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC;QAErD,IAAI,IAAI,CAAC,EAAE,KAAK,OAAO,iBAAI,IAAI,CAAC,OAAO,0CAAG,kBAAkB,2CAAG,MAAM,CAAA,EAAE;YACrE,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAvED,8BAuEC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Context } from '@loopback/context';
|
|
2
|
+
import { ComponentsObject, ControllerSpec, PathObject, ReferenceObject, SchemaObject, SchemasObject } from '@loopback/openapi-v3';
|
|
3
|
+
import { RestServerResolvedConfig } from './rest.server';
|
|
4
|
+
import { ControllerClass, ControllerFactory, ResolvedRoute, RouteEntry, RoutingTable } from './router';
|
|
5
|
+
import { Request, Response } from './types';
|
|
6
|
+
export declare class HttpHandler {
|
|
7
|
+
protected readonly _rootContext: Context;
|
|
8
|
+
protected readonly _serverConfig: RestServerResolvedConfig;
|
|
9
|
+
protected readonly _routes: RoutingTable;
|
|
10
|
+
/**
|
|
11
|
+
* Shared OpenAPI spec objects as `components`
|
|
12
|
+
*/
|
|
13
|
+
protected _openApiComponents: ComponentsObject;
|
|
14
|
+
handleRequest: (request: Request, response: Response) => Promise<void>;
|
|
15
|
+
constructor(_rootContext: Context, _serverConfig: RestServerResolvedConfig, _routes?: RoutingTable);
|
|
16
|
+
registerController<T>(spec: ControllerSpec, controllerCtor: ControllerClass<T>, controllerFactory?: ControllerFactory<T>): void;
|
|
17
|
+
registerRoute(route: RouteEntry): void;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `registerApiComponents`
|
|
20
|
+
* @param defs Schemas
|
|
21
|
+
*/
|
|
22
|
+
registerApiDefinitions(defs: SchemasObject): void;
|
|
23
|
+
/**
|
|
24
|
+
* Merge components into the OpenApi spec
|
|
25
|
+
* @param defs - Components
|
|
26
|
+
*/
|
|
27
|
+
registerApiComponents(defs: ComponentsObject): void;
|
|
28
|
+
getApiComponents(): ComponentsObject;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use `getApiComponents`
|
|
31
|
+
*/
|
|
32
|
+
getApiDefinitions(): {
|
|
33
|
+
[schema: string]: SchemaObject | ReferenceObject;
|
|
34
|
+
} | undefined;
|
|
35
|
+
describeApiPaths(): PathObject;
|
|
36
|
+
findRoute(request: Request): ResolvedRoute;
|
|
37
|
+
protected _handleRequest(request: Request, response: Response): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2017,2019. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/rest
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.HttpHandler = void 0;
|
|
8
|
+
const keys_1 = require("./keys");
|
|
9
|
+
const request_context_1 = require("./request-context");
|
|
10
|
+
const router_1 = require("./router");
|
|
11
|
+
class HttpHandler {
|
|
12
|
+
constructor(_rootContext, _serverConfig, _routes = new router_1.RoutingTable()) {
|
|
13
|
+
this._rootContext = _rootContext;
|
|
14
|
+
this._serverConfig = _serverConfig;
|
|
15
|
+
this._routes = _routes;
|
|
16
|
+
this.handleRequest = (req, res) => this._handleRequest(req, res);
|
|
17
|
+
}
|
|
18
|
+
registerController(spec, controllerCtor, controllerFactory) {
|
|
19
|
+
this._routes.registerController(spec, controllerCtor, controllerFactory);
|
|
20
|
+
}
|
|
21
|
+
registerRoute(route) {
|
|
22
|
+
this._routes.registerRoute(route);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use `registerApiComponents`
|
|
26
|
+
* @param defs Schemas
|
|
27
|
+
*/
|
|
28
|
+
registerApiDefinitions(defs) {
|
|
29
|
+
this.registerApiComponents({ schemas: defs });
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Merge components into the OpenApi spec
|
|
33
|
+
* @param defs - Components
|
|
34
|
+
*/
|
|
35
|
+
registerApiComponents(defs) {
|
|
36
|
+
var _a;
|
|
37
|
+
this._openApiComponents = (_a = this._openApiComponents) !== null && _a !== void 0 ? _a : {};
|
|
38
|
+
for (const p in defs) {
|
|
39
|
+
// Merge each child, such as `schemas`, `parameters`, and `headers`
|
|
40
|
+
this._openApiComponents[p] = { ...this._openApiComponents[p], ...defs[p] };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
getApiComponents() {
|
|
44
|
+
return this._openApiComponents;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use `getApiComponents`
|
|
48
|
+
*/
|
|
49
|
+
getApiDefinitions() {
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = this._openApiComponents) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
52
|
+
}
|
|
53
|
+
describeApiPaths() {
|
|
54
|
+
return this._routes.describeApiPaths();
|
|
55
|
+
}
|
|
56
|
+
findRoute(request) {
|
|
57
|
+
const route = this._routes.find(request);
|
|
58
|
+
Object.assign(route.schemas, this.getApiDefinitions());
|
|
59
|
+
return route;
|
|
60
|
+
}
|
|
61
|
+
async _handleRequest(request, response) {
|
|
62
|
+
const requestContext = new request_context_1.RequestContext(request, response, this._rootContext, this._serverConfig);
|
|
63
|
+
const sequence = await requestContext.get(keys_1.RestBindings.SEQUENCE);
|
|
64
|
+
await sequence.handle(requestContext);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.HttpHandler = HttpHandler;
|
|
68
|
+
//# sourceMappingURL=http-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-handler.js","sourceRoot":"","sources":["../src/http-handler.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAWhE,iCAAoC;AACpC,uDAAiD;AAEjD,qCAMkB;AAIlB,MAAa,WAAW;IAQtB,YACqB,YAAqB,EACrB,aAAuC,EACvC,UAAU,IAAI,qBAAY,EAAE;QAF5B,iBAAY,GAAZ,YAAY,CAAS;QACrB,kBAAa,GAAb,aAAa,CAA0B;QACvC,YAAO,GAAP,OAAO,CAAqB;QAE/C,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnE,CAAC;IAED,kBAAkB,CAChB,IAAoB,EACpB,cAAkC,EAClC,iBAAwC;QAExC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAC;IAC3E,CAAC;IAED,aAAa,CAAC,KAAiB;QAC7B,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,sBAAsB,CAAC,IAAmB;QACxC,IAAI,CAAC,qBAAqB,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,qBAAqB,CAAC,IAAsB;;QAC1C,IAAI,CAAC,kBAAkB,SAAG,IAAI,CAAC,kBAAkB,mCAAI,EAAE,CAAC;QACxD,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE;YACpB,mEAAmE;YACnE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,EAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,EAAC,CAAC;SAC1E;IACH,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,iBAAiB;;QAKf,aAAO,IAAI,CAAC,kBAAkB,0CAAE,OAAO,CAAC;IAC1C,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC;IAED,SAAS,CAAC,OAAgB;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;IAES,KAAK,CAAC,cAAc,CAC5B,OAAgB,EAChB,QAAkB;QAElB,MAAM,cAAc,GAAG,IAAI,gCAAc,CACvC,OAAO,EACP,QAAQ,EACR,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,aAAa,CACnB,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,GAAG,CACvC,mBAAY,CAAC,QAAQ,CACtB,CAAC;QACF,MAAM,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACxC,CAAC;CACF;AAzFD,kCAyFC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The REST API package for loopback-next.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* A REST server for LoopBack 4 application instances, complete with:
|
|
6
|
+
*
|
|
7
|
+
* - new custom routing engine (special thanks to @bajtos)!
|
|
8
|
+
* - tools for defining your application routes
|
|
9
|
+
* - OpenAPI 3.0 spec (openapi.json/openapi.yaml) generation using
|
|
10
|
+
* @loopback/openapi-v3
|
|
11
|
+
* - a default sequence implementation to manage the request and response
|
|
12
|
+
* lifecycle
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
export * from '@loopback/openapi-v3';
|
|
18
|
+
export * from './body-parsers';
|
|
19
|
+
export * from './http-handler';
|
|
20
|
+
export * from './keys';
|
|
21
|
+
export * from './parse-json';
|
|
22
|
+
export * from './parser';
|
|
23
|
+
export * from './providers';
|
|
24
|
+
export * from './request-context';
|
|
25
|
+
export * from './rest-http-error';
|
|
26
|
+
export * from './rest.application';
|
|
27
|
+
export * from './rest.component';
|
|
28
|
+
export * from './rest.server';
|
|
29
|
+
export * from './router';
|
|
30
|
+
export * from './sequence';
|
|
31
|
+
export * from './spec-enhancers/info.spec-enhancer';
|
|
32
|
+
export * from './types';
|
|
33
|
+
export * from './validation/request-body.validator';
|
|
34
|
+
export * from './writer';
|
|
35
|
+
export { HttpErrors };
|
|
36
|
+
import HttpErrors from 'http-errors';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright IBM Corp.
|
|
2
|
+
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
|
|
3
3
|
// Node module: @loopback/rest
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
function __export(m) {
|
|
7
|
-
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
8
|
-
}
|
|
9
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
exports.HttpErrors = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
/**
|
|
10
|
+
* The REST API package for loopback-next.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* A REST server for LoopBack 4 application instances, complete with:
|
|
14
|
+
*
|
|
15
|
+
* - new custom routing engine (special thanks to @bajtos)!
|
|
16
|
+
* - tools for defining your application routes
|
|
17
|
+
* - OpenAPI 3.0 spec (openapi.json/openapi.yaml) generation using
|
|
18
|
+
* @loopback/openapi-v3
|
|
19
|
+
* - a default sequence implementation to manage the request and response
|
|
20
|
+
* lifecycle
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
tslib_1.__exportStar(require("@loopback/openapi-v3"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./body-parsers"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./http-handler"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./keys"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./parse-json"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./parser"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./providers"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./request-context"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./rest-http-error"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./rest.application"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./rest.component"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./rest.server"), exports);
|
|
37
|
+
tslib_1.__exportStar(require("./router"), exports);
|
|
38
|
+
tslib_1.__exportStar(require("./sequence"), exports);
|
|
39
|
+
tslib_1.__exportStar(require("./spec-enhancers/info.spec-enhancer"), exports);
|
|
40
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
41
|
+
tslib_1.__exportStar(require("./validation/request-body.validator"), exports);
|
|
42
|
+
tslib_1.__exportStar(require("./writer"), exports);
|
|
43
|
+
// export all errors from external http-errors package
|
|
44
|
+
const http_errors_1 = tslib_1.__importDefault(require("http-errors"));
|
|
45
|
+
exports.HttpErrors = http_errors_1.default;
|
|
12
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE;;;;;;;;;;;;;;;GAeG;AAEH,+DAAqC;AACrC,yDAA+B;AAC/B,yDAA+B;AAC/B,iDAAuB;AACvB,uDAA6B;AAC7B,mDAAyB;AACzB,sDAA4B;AAC5B,4DAAkC;AAClC,4DAAkC;AAClC,6DAAmC;AACnC,2DAAiC;AACjC,wDAA8B;AAC9B,mDAAyB;AACzB,qDAA2B;AAC3B,8EAAoD;AACpD,kDAAwB;AACxB,8EAAoD;AACpD,mDAAyB;AAGzB,sDAAsD;AACtD,sEAAqC;AAH7B,qBAGD,qBAAU,CAHC"}
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BindingKey, Context } from '@loopback/context';
|
|
3
|
+
import { InvokeMiddleware } from '@loopback/express';
|
|
4
|
+
import { HttpProtocol } from '@loopback/http-server';
|
|
5
|
+
import { OpenApiSpec, OperationObject } from '@loopback/openapi-v3';
|
|
6
|
+
import https from 'https';
|
|
7
|
+
import { ErrorWriterOptions } from 'strong-error-handler';
|
|
8
|
+
import { BodyParser, RequestBodyParser } from './body-parsers';
|
|
9
|
+
import { HttpHandler } from './http-handler';
|
|
10
|
+
import { RestServer, RestServerConfig } from './rest.server';
|
|
11
|
+
import { RestRouter, RestRouterOptions } from './router';
|
|
12
|
+
import { SequenceHandler } from './sequence';
|
|
13
|
+
import { AjvFactory, FindRoute, InvokeMethod, LogError, ParseParams, Reject, Request, RequestBodyParserOptions, Response, Send } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* RestServer-specific bindings
|
|
16
|
+
*/
|
|
17
|
+
export declare namespace RestBindings {
|
|
18
|
+
/**
|
|
19
|
+
* Binding key for setting and injecting RestComponentConfig
|
|
20
|
+
*/
|
|
21
|
+
const CONFIG: BindingKey<RestServerConfig>;
|
|
22
|
+
/**
|
|
23
|
+
* Binding key for setting and injecting the host name of RestServer
|
|
24
|
+
*/
|
|
25
|
+
const HOST: BindingKey<string | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Binding key for setting and injecting the port number of RestServer
|
|
28
|
+
*/
|
|
29
|
+
const PORT: BindingKey<number>;
|
|
30
|
+
/**
|
|
31
|
+
* Binding key for setting and injecting the socket path of the RestServer
|
|
32
|
+
*/
|
|
33
|
+
const PATH: BindingKey<string | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Binding key for setting and injecting the URL of RestServer
|
|
36
|
+
*/
|
|
37
|
+
const URL: BindingKey<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Binding key for setting and injecting the protocol of RestServer
|
|
40
|
+
*/
|
|
41
|
+
const PROTOCOL: BindingKey<HttpProtocol>;
|
|
42
|
+
/**
|
|
43
|
+
* Binding key for HTTPS options
|
|
44
|
+
*/
|
|
45
|
+
const HTTPS_OPTIONS: BindingKey<https.ServerOptions>;
|
|
46
|
+
/**
|
|
47
|
+
* Binding key for the server itself
|
|
48
|
+
*/
|
|
49
|
+
const SERVER: BindingKey<RestServer>;
|
|
50
|
+
/**
|
|
51
|
+
* Internal binding key for basePath
|
|
52
|
+
*/
|
|
53
|
+
const BASE_PATH: BindingKey<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Internal binding key for http-handler
|
|
56
|
+
*/
|
|
57
|
+
const HANDLER: BindingKey<HttpHandler>;
|
|
58
|
+
/**
|
|
59
|
+
* Internal binding key for rest router
|
|
60
|
+
*/
|
|
61
|
+
const ROUTER: BindingKey<RestRouter>;
|
|
62
|
+
const ROUTER_OPTIONS: BindingKey<RestRouterOptions>;
|
|
63
|
+
/**
|
|
64
|
+
* Binding key for setting and injecting Reject action's error handling
|
|
65
|
+
* options.
|
|
66
|
+
*
|
|
67
|
+
* See https://github.com/strongloop/strong-error-handler#options for
|
|
68
|
+
* the list of available options. Please note that the flag `log` is not used
|
|
69
|
+
* by `@loopback/rest`.
|
|
70
|
+
*/
|
|
71
|
+
const ERROR_WRITER_OPTIONS: BindingKey<ErrorWriterOptions>;
|
|
72
|
+
/**
|
|
73
|
+
* Binding key for request body parser options
|
|
74
|
+
*/
|
|
75
|
+
const REQUEST_BODY_PARSER_OPTIONS: BindingKey<RequestBodyParserOptions>;
|
|
76
|
+
/**
|
|
77
|
+
* Binding key for request body parser
|
|
78
|
+
*/
|
|
79
|
+
const REQUEST_BODY_PARSER: BindingKey<RequestBodyParser>;
|
|
80
|
+
/**
|
|
81
|
+
* Binding key for request json body parser
|
|
82
|
+
*/
|
|
83
|
+
const REQUEST_BODY_PARSER_JSON: BindingKey<BodyParser>;
|
|
84
|
+
/**
|
|
85
|
+
* Binding key for request urlencoded body parser
|
|
86
|
+
*/
|
|
87
|
+
const REQUEST_BODY_PARSER_URLENCODED: BindingKey<BodyParser>;
|
|
88
|
+
/**
|
|
89
|
+
* Binding key for request text body parser
|
|
90
|
+
*/
|
|
91
|
+
const REQUEST_BODY_PARSER_TEXT: BindingKey<BodyParser>;
|
|
92
|
+
/**
|
|
93
|
+
* Binding key for request raw body parser
|
|
94
|
+
*/
|
|
95
|
+
const REQUEST_BODY_PARSER_RAW: BindingKey<BodyParser>;
|
|
96
|
+
/**
|
|
97
|
+
* Binding key for request raw body parser
|
|
98
|
+
*/
|
|
99
|
+
const REQUEST_BODY_PARSER_STREAM: BindingKey<BodyParser>;
|
|
100
|
+
/**
|
|
101
|
+
* Binding key for AJV
|
|
102
|
+
*/
|
|
103
|
+
const AJV_FACTORY: BindingKey<AjvFactory>;
|
|
104
|
+
/**
|
|
105
|
+
* Binding key for setting and injecting an OpenAPI spec
|
|
106
|
+
*/
|
|
107
|
+
const API_SPEC: BindingKey<OpenApiSpec>;
|
|
108
|
+
/**
|
|
109
|
+
* Binding key for setting and injecting an OpenAPI operation spec
|
|
110
|
+
*/
|
|
111
|
+
const OPERATION_SPEC_CURRENT: BindingKey<OperationObject>;
|
|
112
|
+
/**
|
|
113
|
+
* Binding key for setting and injecting a Sequence
|
|
114
|
+
*/
|
|
115
|
+
const SEQUENCE: BindingKey<SequenceHandler>;
|
|
116
|
+
/**
|
|
117
|
+
* Bindings for potential actions that could be used in a sequence
|
|
118
|
+
*/
|
|
119
|
+
namespace SequenceActions {
|
|
120
|
+
/**
|
|
121
|
+
* Binding key for setting and injecting a route finding function
|
|
122
|
+
*/
|
|
123
|
+
const INVOKE_MIDDLEWARE: BindingKey<InvokeMiddleware>;
|
|
124
|
+
/**
|
|
125
|
+
* Binding key for setting and injecting a route finding function
|
|
126
|
+
*/
|
|
127
|
+
const FIND_ROUTE: BindingKey<FindRoute>;
|
|
128
|
+
/**
|
|
129
|
+
* Binding key for setting and injecting a parameter parsing function
|
|
130
|
+
*/
|
|
131
|
+
const PARSE_PARAMS: BindingKey<ParseParams>;
|
|
132
|
+
/**
|
|
133
|
+
* Binding key for setting and injecting a controller route invoking function
|
|
134
|
+
*/
|
|
135
|
+
const INVOKE_METHOD: BindingKey<InvokeMethod>;
|
|
136
|
+
/**
|
|
137
|
+
* Binding key for setting and injecting an error logging function
|
|
138
|
+
*/
|
|
139
|
+
const LOG_ERROR: BindingKey<LogError>;
|
|
140
|
+
/**
|
|
141
|
+
* Binding key for setting and injecting a response writing function
|
|
142
|
+
*/
|
|
143
|
+
const SEND: BindingKey<Send>;
|
|
144
|
+
/**
|
|
145
|
+
* Binding key for setting and injecting a bad response writing function
|
|
146
|
+
*/
|
|
147
|
+
const REJECT: BindingKey<Reject>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Request-specific bindings
|
|
151
|
+
*/
|
|
152
|
+
namespace Http {
|
|
153
|
+
/**
|
|
154
|
+
* Binding key for setting and injecting the http request
|
|
155
|
+
*/
|
|
156
|
+
const REQUEST: BindingKey<Request>;
|
|
157
|
+
/**
|
|
158
|
+
* Binding key for setting and injecting the http response
|
|
159
|
+
*/
|
|
160
|
+
const RESPONSE: BindingKey<Response<any>>;
|
|
161
|
+
/**
|
|
162
|
+
* Binding key for setting and injecting the http request context
|
|
163
|
+
*/
|
|
164
|
+
const CONTEXT: BindingKey<Context>;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Namespace for REST routes
|
|
168
|
+
*/
|
|
169
|
+
const ROUTES = "routes";
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Binding tags for RestServer
|
|
173
|
+
*/
|
|
174
|
+
export declare namespace RestTags {
|
|
175
|
+
/**
|
|
176
|
+
* Binding tag to identify REST routes
|
|
177
|
+
*/
|
|
178
|
+
const REST_ROUTE = "restRoute";
|
|
179
|
+
/**
|
|
180
|
+
* Binding tag for the REST route verb
|
|
181
|
+
*/
|
|
182
|
+
const ROUTE_VERB = "restRouteVerb";
|
|
183
|
+
/**
|
|
184
|
+
* Binding tag for the REST route path
|
|
185
|
+
*/
|
|
186
|
+
const ROUTE_PATH = "restRoutePath";
|
|
187
|
+
/**
|
|
188
|
+
* Binding tag to identify controller based REST routes
|
|
189
|
+
*/
|
|
190
|
+
const CONTROLLER_ROUTE = "controllerRoute";
|
|
191
|
+
/**
|
|
192
|
+
* Binding tag for controller route bindings to represent the controller
|
|
193
|
+
* binding key
|
|
194
|
+
*/
|
|
195
|
+
const CONTROLLER_BINDING = "controllerBinding";
|
|
196
|
+
const AJV_KEYWORD = "ajvKeyword";
|
|
197
|
+
const AJV_FORMAT = "ajvFormat";
|
|
198
|
+
}
|
package/dist/keys.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/rest
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RestTags = exports.RestBindings = void 0;
|
|
8
|
+
const context_1 = require("@loopback/context");
|
|
9
|
+
const core_1 = require("@loopback/core");
|
|
10
|
+
/**
|
|
11
|
+
* RestServer-specific bindings
|
|
12
|
+
*/
|
|
13
|
+
var RestBindings;
|
|
14
|
+
(function (RestBindings) {
|
|
15
|
+
/**
|
|
16
|
+
* Binding key for setting and injecting RestComponentConfig
|
|
17
|
+
*/
|
|
18
|
+
RestBindings.CONFIG = core_1.CoreBindings.APPLICATION_CONFIG.deepProperty('rest');
|
|
19
|
+
/**
|
|
20
|
+
* Binding key for setting and injecting the host name of RestServer
|
|
21
|
+
*/
|
|
22
|
+
RestBindings.HOST = context_1.BindingKey.create('rest.host');
|
|
23
|
+
/**
|
|
24
|
+
* Binding key for setting and injecting the port number of RestServer
|
|
25
|
+
*/
|
|
26
|
+
RestBindings.PORT = context_1.BindingKey.create('rest.port');
|
|
27
|
+
/**
|
|
28
|
+
* Binding key for setting and injecting the socket path of the RestServer
|
|
29
|
+
*/
|
|
30
|
+
RestBindings.PATH = context_1.BindingKey.create('rest.path');
|
|
31
|
+
/**
|
|
32
|
+
* Binding key for setting and injecting the URL of RestServer
|
|
33
|
+
*/
|
|
34
|
+
RestBindings.URL = context_1.BindingKey.create('rest.url');
|
|
35
|
+
/**
|
|
36
|
+
* Binding key for setting and injecting the protocol of RestServer
|
|
37
|
+
*/
|
|
38
|
+
RestBindings.PROTOCOL = context_1.BindingKey.create('rest.protocol');
|
|
39
|
+
/**
|
|
40
|
+
* Binding key for HTTPS options
|
|
41
|
+
*/
|
|
42
|
+
RestBindings.HTTPS_OPTIONS = context_1.BindingKey.create('rest.httpsOptions');
|
|
43
|
+
/**
|
|
44
|
+
* Binding key for the server itself
|
|
45
|
+
*/
|
|
46
|
+
RestBindings.SERVER = context_1.BindingKey.create('servers.RestServer');
|
|
47
|
+
/**
|
|
48
|
+
* Internal binding key for basePath
|
|
49
|
+
*/
|
|
50
|
+
RestBindings.BASE_PATH = context_1.BindingKey.create('rest.basePath');
|
|
51
|
+
/**
|
|
52
|
+
* Internal binding key for http-handler
|
|
53
|
+
*/
|
|
54
|
+
RestBindings.HANDLER = context_1.BindingKey.create('rest.handler');
|
|
55
|
+
/**
|
|
56
|
+
* Internal binding key for rest router
|
|
57
|
+
*/
|
|
58
|
+
RestBindings.ROUTER = context_1.BindingKey.create('rest.router');
|
|
59
|
+
RestBindings.ROUTER_OPTIONS = context_1.BindingKey.create('rest.router.options');
|
|
60
|
+
/**
|
|
61
|
+
* Binding key for setting and injecting Reject action's error handling
|
|
62
|
+
* options.
|
|
63
|
+
*
|
|
64
|
+
* See https://github.com/strongloop/strong-error-handler#options for
|
|
65
|
+
* the list of available options. Please note that the flag `log` is not used
|
|
66
|
+
* by `@loopback/rest`.
|
|
67
|
+
*/
|
|
68
|
+
RestBindings.ERROR_WRITER_OPTIONS = context_1.BindingKey.create('rest.errorWriterOptions');
|
|
69
|
+
/**
|
|
70
|
+
* Binding key for request body parser options
|
|
71
|
+
*/
|
|
72
|
+
RestBindings.REQUEST_BODY_PARSER_OPTIONS = context_1.BindingKey.create('rest.requestBodyParserOptions');
|
|
73
|
+
/**
|
|
74
|
+
* Binding key for request body parser
|
|
75
|
+
*/
|
|
76
|
+
RestBindings.REQUEST_BODY_PARSER = context_1.BindingKey.create('rest.requestBodyParser');
|
|
77
|
+
function bodyParserBindingKey(parser) {
|
|
78
|
+
return `${RestBindings.REQUEST_BODY_PARSER}.${parser}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Binding key for request json body parser
|
|
82
|
+
*/
|
|
83
|
+
RestBindings.REQUEST_BODY_PARSER_JSON = context_1.BindingKey.create(bodyParserBindingKey('JsonBodyParser'));
|
|
84
|
+
/**
|
|
85
|
+
* Binding key for request urlencoded body parser
|
|
86
|
+
*/
|
|
87
|
+
RestBindings.REQUEST_BODY_PARSER_URLENCODED = context_1.BindingKey.create(bodyParserBindingKey('UrlEncodedBodyParser'));
|
|
88
|
+
/**
|
|
89
|
+
* Binding key for request text body parser
|
|
90
|
+
*/
|
|
91
|
+
RestBindings.REQUEST_BODY_PARSER_TEXT = context_1.BindingKey.create(bodyParserBindingKey('TextBodyParser'));
|
|
92
|
+
/**
|
|
93
|
+
* Binding key for request raw body parser
|
|
94
|
+
*/
|
|
95
|
+
RestBindings.REQUEST_BODY_PARSER_RAW = context_1.BindingKey.create(bodyParserBindingKey('RawBodyParser'));
|
|
96
|
+
/**
|
|
97
|
+
* Binding key for request raw body parser
|
|
98
|
+
*/
|
|
99
|
+
RestBindings.REQUEST_BODY_PARSER_STREAM = context_1.BindingKey.create(bodyParserBindingKey('StreamBodyParser'));
|
|
100
|
+
/**
|
|
101
|
+
* Binding key for AJV
|
|
102
|
+
*/
|
|
103
|
+
RestBindings.AJV_FACTORY = context_1.BindingKey.create(bodyParserBindingKey('rest.ajvFactory'));
|
|
104
|
+
/**
|
|
105
|
+
* Binding key for setting and injecting an OpenAPI spec
|
|
106
|
+
*/
|
|
107
|
+
RestBindings.API_SPEC = context_1.BindingKey.create('rest.apiSpec');
|
|
108
|
+
/**
|
|
109
|
+
* Binding key for setting and injecting an OpenAPI operation spec
|
|
110
|
+
*/
|
|
111
|
+
RestBindings.OPERATION_SPEC_CURRENT = context_1.BindingKey.create('rest.operationSpec.current');
|
|
112
|
+
/**
|
|
113
|
+
* Binding key for setting and injecting a Sequence
|
|
114
|
+
*/
|
|
115
|
+
RestBindings.SEQUENCE = context_1.BindingKey.create('rest.sequence');
|
|
116
|
+
/**
|
|
117
|
+
* Bindings for potential actions that could be used in a sequence
|
|
118
|
+
*/
|
|
119
|
+
let SequenceActions;
|
|
120
|
+
(function (SequenceActions) {
|
|
121
|
+
/**
|
|
122
|
+
* Binding key for setting and injecting a route finding function
|
|
123
|
+
*/
|
|
124
|
+
SequenceActions.INVOKE_MIDDLEWARE = context_1.BindingKey.create('rest.sequence.actions.invokeMiddleware');
|
|
125
|
+
/**
|
|
126
|
+
* Binding key for setting and injecting a route finding function
|
|
127
|
+
*/
|
|
128
|
+
SequenceActions.FIND_ROUTE = context_1.BindingKey.create('rest.sequence.actions.findRoute');
|
|
129
|
+
/**
|
|
130
|
+
* Binding key for setting and injecting a parameter parsing function
|
|
131
|
+
*/
|
|
132
|
+
SequenceActions.PARSE_PARAMS = context_1.BindingKey.create('rest.sequence.actions.parseParams');
|
|
133
|
+
/**
|
|
134
|
+
* Binding key for setting and injecting a controller route invoking function
|
|
135
|
+
*/
|
|
136
|
+
SequenceActions.INVOKE_METHOD = context_1.BindingKey.create('rest.sequence.actions.invokeMethod');
|
|
137
|
+
/**
|
|
138
|
+
* Binding key for setting and injecting an error logging function
|
|
139
|
+
*/
|
|
140
|
+
SequenceActions.LOG_ERROR = context_1.BindingKey.create('rest.sequence.actions.logError');
|
|
141
|
+
/**
|
|
142
|
+
* Binding key for setting and injecting a response writing function
|
|
143
|
+
*/
|
|
144
|
+
SequenceActions.SEND = context_1.BindingKey.create('rest.sequence.actions.send');
|
|
145
|
+
/**
|
|
146
|
+
* Binding key for setting and injecting a bad response writing function
|
|
147
|
+
*/
|
|
148
|
+
SequenceActions.REJECT = context_1.BindingKey.create('rest.sequence.actions.reject');
|
|
149
|
+
})(SequenceActions = RestBindings.SequenceActions || (RestBindings.SequenceActions = {}));
|
|
150
|
+
/**
|
|
151
|
+
* Request-specific bindings
|
|
152
|
+
*/
|
|
153
|
+
let Http;
|
|
154
|
+
(function (Http) {
|
|
155
|
+
/**
|
|
156
|
+
* Binding key for setting and injecting the http request
|
|
157
|
+
*/
|
|
158
|
+
Http.REQUEST = context_1.BindingKey.create('rest.http.request');
|
|
159
|
+
/**
|
|
160
|
+
* Binding key for setting and injecting the http response
|
|
161
|
+
*/
|
|
162
|
+
Http.RESPONSE = context_1.BindingKey.create('rest.http.response');
|
|
163
|
+
/**
|
|
164
|
+
* Binding key for setting and injecting the http request context
|
|
165
|
+
*/
|
|
166
|
+
Http.CONTEXT = context_1.BindingKey.create('rest.http.request.context');
|
|
167
|
+
})(Http = RestBindings.Http || (RestBindings.Http = {}));
|
|
168
|
+
/**
|
|
169
|
+
* Namespace for REST routes
|
|
170
|
+
*/
|
|
171
|
+
RestBindings.ROUTES = 'routes';
|
|
172
|
+
})(RestBindings = exports.RestBindings || (exports.RestBindings = {}));
|
|
173
|
+
/**
|
|
174
|
+
* Binding tags for RestServer
|
|
175
|
+
*/
|
|
176
|
+
var RestTags;
|
|
177
|
+
(function (RestTags) {
|
|
178
|
+
/**
|
|
179
|
+
* Binding tag to identify REST routes
|
|
180
|
+
*/
|
|
181
|
+
RestTags.REST_ROUTE = 'restRoute';
|
|
182
|
+
/**
|
|
183
|
+
* Binding tag for the REST route verb
|
|
184
|
+
*/
|
|
185
|
+
RestTags.ROUTE_VERB = 'restRouteVerb';
|
|
186
|
+
/**
|
|
187
|
+
* Binding tag for the REST route path
|
|
188
|
+
*/
|
|
189
|
+
RestTags.ROUTE_PATH = 'restRoutePath';
|
|
190
|
+
/**
|
|
191
|
+
* Binding tag to identify controller based REST routes
|
|
192
|
+
*/
|
|
193
|
+
RestTags.CONTROLLER_ROUTE = 'controllerRoute';
|
|
194
|
+
/**
|
|
195
|
+
* Binding tag for controller route bindings to represent the controller
|
|
196
|
+
* binding key
|
|
197
|
+
*/
|
|
198
|
+
RestTags.CONTROLLER_BINDING = 'controllerBinding';
|
|
199
|
+
RestTags.AJV_KEYWORD = 'ajvKeyword';
|
|
200
|
+
RestTags.AJV_FORMAT = 'ajvFormat';
|
|
201
|
+
})(RestTags = exports.RestTags || (exports.RestTags = {}));
|
|
202
|
+
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAAsD;AACtD,yCAA4C;AAwB5C;;GAEG;AACH,IAAiB,YAAY,CA6N5B;AA7ND,WAAiB,YAAY;IAC3B;;OAEG;IACU,mBAAM,GAAiC,mBAAY,CAAC,kBAAkB,CAAC,YAAY,CAC9F,MAAM,CACP,CAAC;IACF;;OAEG;IACU,iBAAI,GAAG,oBAAU,CAAC,MAAM,CAAqB,WAAW,CAAC,CAAC;IACvE;;OAEG;IACU,iBAAI,GAAG,oBAAU,CAAC,MAAM,CAAS,WAAW,CAAC,CAAC;IAC3D;;OAEG;IACU,iBAAI,GAAG,oBAAU,CAAC,MAAM,CAAqB,WAAW,CAAC,CAAC;IACvE;;OAEG;IACU,gBAAG,GAAG,oBAAU,CAAC,MAAM,CAAS,UAAU,CAAC,CAAC;IACzD;;OAEG;IACU,qBAAQ,GAAG,oBAAU,CAAC,MAAM,CAAe,eAAe,CAAC,CAAC;IACzE;;OAEG;IACU,0BAAa,GAAG,oBAAU,CAAC,MAAM,CAC5C,mBAAmB,CACpB,CAAC;IAEF;;OAEG;IACU,mBAAM,GAAG,oBAAU,CAAC,MAAM,CAAa,oBAAoB,CAAC,CAAC;IAE1E;;OAEG;IACU,sBAAS,GAAG,oBAAU,CAAC,MAAM,CAAS,eAAe,CAAC,CAAC;IAEpE;;OAEG;IACU,oBAAO,GAAG,oBAAU,CAAC,MAAM,CAAc,cAAc,CAAC,CAAC;IAEtE;;OAEG;IACU,mBAAM,GAAG,oBAAU,CAAC,MAAM,CAAa,aAAa,CAAC,CAAC;IAEtD,2BAAc,GAAG,oBAAU,CAAC,MAAM,CAC7C,qBAAqB,CACtB,CAAC;IAEF;;;;;;;OAOG;IACU,iCAAoB,GAAG,oBAAU,CAAC,MAAM,CACnD,yBAAyB,CAC1B,CAAC;IAEF;;OAEG;IACU,wCAA2B,GAAG,oBAAU,CAAC,MAAM,CAE1D,+BAA+B,CAAC,CAAC;IAEnC;;OAEG;IACU,gCAAmB,GAAG,oBAAU,CAAC,MAAM,CAClD,wBAAwB,CACzB,CAAC;IAEF,SAAS,oBAAoB,CAAC,MAAc;QAC1C,OAAO,GAAG,aAAA,mBAAmB,IAAI,MAAM,EAAE,CAAC;IAC5C,CAAC;IAED;;OAEG;IACU,qCAAwB,GAAG,oBAAU,CAAC,MAAM,CACvD,oBAAoB,CAAC,gBAAgB,CAAC,CACvC,CAAC;IAEF;;OAEG;IACU,2CAA8B,GAAG,oBAAU,CAAC,MAAM,CAC7D,oBAAoB,CAAC,sBAAsB,CAAC,CAC7C,CAAC;IAEF;;OAEG;IACU,qCAAwB,GAAG,oBAAU,CAAC,MAAM,CACvD,oBAAoB,CAAC,gBAAgB,CAAC,CACvC,CAAC;IAEF;;OAEG;IACU,oCAAuB,GAAG,oBAAU,CAAC,MAAM,CACtD,oBAAoB,CAAC,eAAe,CAAC,CACtC,CAAC;IAEF;;OAEG;IACU,uCAA0B,GAAG,oBAAU,CAAC,MAAM,CACzD,oBAAoB,CAAC,kBAAkB,CAAC,CACzC,CAAC;IAEF;;OAEG;IACU,wBAAW,GAAG,oBAAU,CAAC,MAAM,CAC1C,oBAAoB,CAAC,iBAAiB,CAAC,CACxC,CAAC;IAEF;;OAEG;IACU,qBAAQ,GAA4B,oBAAU,CAAC,MAAM,CAEhE,cAAc,CAAC,CAAC;IAElB;;OAEG;IACU,mCAAsB,GAAG,oBAAU,CAAC,MAAM,CACrD,4BAA4B,CAC7B,CAAC;IAEF;;OAEG;IACU,qBAAQ,GAAG,oBAAU,CAAC,MAAM,CAAkB,eAAe,CAAC,CAAC;IAE5E;;OAEG;IACH,IAAiB,eAAe,CAyC/B;IAzCD,WAAiB,eAAe;QAC9B;;WAEG;QACU,iCAAiB,GAAG,oBAAU,CAAC,MAAM,CAChD,wCAAwC,CACzC,CAAC;QACF;;WAEG;QACU,0BAAU,GAAG,oBAAU,CAAC,MAAM,CACzC,iCAAiC,CAClC,CAAC;QACF;;WAEG;QACU,4BAAY,GAAG,oBAAU,CAAC,MAAM,CAC3C,mCAAmC,CACpC,CAAC;QACF;;WAEG;QACU,6BAAa,GAAG,oBAAU,CAAC,MAAM,CAC5C,oCAAoC,CACrC,CAAC;QACF;;WAEG;QACU,yBAAS,GAAG,oBAAU,CAAC,MAAM,CACxC,gCAAgC,CACjC,CAAC;QACF;;WAEG;QACU,oBAAI,GAAG,oBAAU,CAAC,MAAM,CAAO,4BAA4B,CAAC,CAAC;QAC1E;;WAEG;QACU,sBAAM,GAAG,oBAAU,CAAC,MAAM,CACrC,8BAA8B,CAC/B,CAAC;IACJ,CAAC,EAzCgB,eAAe,GAAf,4BAAe,KAAf,4BAAe,QAyC/B;IAED;;OAEG;IACH,IAAiB,IAAI,CAiBpB;IAjBD,WAAiB,IAAI;QACnB;;WAEG;QACU,YAAO,GAAwB,oBAAU,CAAC,MAAM,CAC3D,mBAAmB,CACpB,CAAC;QACF;;WAEG;QACU,aAAQ,GAAG,oBAAU,CAAC,MAAM,CAAW,oBAAoB,CAAC,CAAC;QAC1E;;WAEG;QACU,YAAO,GAAG,oBAAU,CAAC,MAAM,CACtC,2BAA2B,CAC5B,CAAC;IACJ,CAAC,EAjBgB,IAAI,GAAJ,iBAAI,KAAJ,iBAAI,QAiBpB;IAED;;OAEG;IACU,mBAAM,GAAG,QAAQ,CAAC;AACjC,CAAC,EA7NgB,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QA6N5B;AAED;;GAEG;AACH,IAAiB,QAAQ,CA6BxB;AA7BD,WAAiB,QAAQ;IACvB;;OAEG;IACU,mBAAU,GAAG,WAAW,CAAC;IAEtC;;OAEG;IACU,mBAAU,GAAG,eAAe,CAAC;IAE1C;;OAEG;IACU,mBAAU,GAAG,eAAe,CAAC;IAE1C;;OAEG;IACU,yBAAgB,GAAG,iBAAiB,CAAC;IAElD;;;OAGG;IACU,2BAAkB,GAAG,mBAAmB,CAAC;IAEzC,oBAAW,GAAG,YAAY,CAAC;IAC3B,mBAAU,GAAG,WAAW,CAAC;AACxC,CAAC,EA7BgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QA6BxB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory to create a reviver function for `JSON.parse` to sanitize keys
|
|
3
|
+
* @param reviver - Reviver function
|
|
4
|
+
*/
|
|
5
|
+
export declare function sanitizeJsonParse(reviver?: (key: any, value: any) => any): (key: string, value: any) => any;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param text - JSON string
|
|
9
|
+
* @param reviver - Optional reviver function for `JSON.parse`
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseJson(text: string, reviver?: (key: any, value: any) => any): any;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/rest
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.parseJson = exports.sanitizeJsonParse = void 0;
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
|
+
// These utilities are introduced to mitigate the prototype pollution issue
|
|
10
|
+
// with `JSON.parse`.
|
|
11
|
+
// See https://hueniverse.com/a-tale-of-prototype-poisoning-2610fa170061
|
|
12
|
+
//
|
|
13
|
+
// The [bourne](https://github.com/hapijs/bourne) module provides a drop-in
|
|
14
|
+
// replacement for `JSON.parse` but we need to instruct `body-parser` to honor
|
|
15
|
+
// a `reviver` function.
|
|
16
|
+
/**
|
|
17
|
+
* Factory to create a reviver function for `JSON.parse` to sanitize keys
|
|
18
|
+
* @param reviver - Reviver function
|
|
19
|
+
*/
|
|
20
|
+
function sanitizeJsonParse(reviver) {
|
|
21
|
+
return (key, value) => {
|
|
22
|
+
if (key === '__proto__')
|
|
23
|
+
throw new Error('JSON string cannot contain "__proto__" key.');
|
|
24
|
+
if (reviver) {
|
|
25
|
+
return reviver(key, value);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.sanitizeJsonParse = sanitizeJsonParse;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param text - JSON string
|
|
36
|
+
* @param reviver - Optional reviver function for `JSON.parse`
|
|
37
|
+
*/
|
|
38
|
+
function parseJson(text, reviver) {
|
|
39
|
+
return JSON.parse(text, sanitizeJsonParse(reviver));
|
|
40
|
+
}
|
|
41
|
+
exports.parseJson = parseJson;
|
|
42
|
+
//# sourceMappingURL=parse-json.js.map
|