@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,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018. 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.TextBodyParser = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const context_1 = require("@loopback/context");
|
|
10
|
+
const body_parser_1 = require("body-parser");
|
|
11
|
+
const type_is_1 = require("type-is");
|
|
12
|
+
const keys_1 = require("../keys");
|
|
13
|
+
const body_parser_helpers_1 = require("./body-parser.helpers");
|
|
14
|
+
let TextBodyParser = /** @class */ (() => {
|
|
15
|
+
let TextBodyParser = class TextBodyParser {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.name = body_parser_helpers_1.builtinParsers.text;
|
|
18
|
+
const textOptions = Object.assign({ type: 'text/*' }, body_parser_helpers_1.getParserOptions('text', options));
|
|
19
|
+
this.textParser = body_parser_1.text(textOptions);
|
|
20
|
+
}
|
|
21
|
+
supports(mediaType) {
|
|
22
|
+
// Please note that `text/*` matches `text/plain` and `text/html` but`text`
|
|
23
|
+
// does not.
|
|
24
|
+
return !!type_is_1.is(mediaType, 'text/*');
|
|
25
|
+
}
|
|
26
|
+
async parse(request) {
|
|
27
|
+
const body = await body_parser_helpers_1.invokeBodyParserMiddleware(this.textParser, request);
|
|
28
|
+
return { value: body };
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
TextBodyParser = tslib_1.__decorate([
|
|
32
|
+
tslib_1.__param(0, context_1.inject(keys_1.RestBindings.REQUEST_BODY_PARSER_OPTIONS, { optional: true })),
|
|
33
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
34
|
+
], TextBodyParser);
|
|
35
|
+
return TextBodyParser;
|
|
36
|
+
})();
|
|
37
|
+
exports.TextBodyParser = TextBodyParser;
|
|
38
|
+
//# sourceMappingURL=body-parser.text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-parser.text.js","sourceRoot":"","sources":["../../src/body-parsers/body-parser.text.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAAyC;AACzC,6CAAiC;AACjC,qCAA2B;AAC3B,kCAAqC;AAErC,+DAK+B;AAG/B;IAAA,IAAa,cAAc,GAA3B,MAAa,cAAc;QAIzB,YAEE,UAAoC,EAAE;YALxC,SAAI,GAAG,oCAAc,CAAC,IAAI,CAAC;YAOzB,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAC/B,EAAC,IAAI,EAAE,QAAQ,EAAC,EAChB,sCAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAClC,CAAC;YACF,IAAI,CAAC,UAAU,GAAG,kBAAI,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;QAED,QAAQ,CAAC,SAAiB;YACxB,2EAA2E;YAC3E,YAAY;YACZ,OAAO,CAAC,CAAC,YAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACnC,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,OAAgB;YAC1B,MAAM,IAAI,GAAG,MAAM,gDAA0B,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACxE,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC;QACvB,CAAC;KACF,CAAA;IAzBY,cAAc;QAKtB,mBAAA,gBAAM,CAAC,mBAAY,CAAC,2BAA2B,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;;OAL1D,cAAc,CAyB1B;IAAD,qBAAC;KAAA;AAzBY,wCAAc"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Request, RequestBodyParserOptions } from '../types';
|
|
2
|
+
import { BodyParser, RequestBody } from './types';
|
|
3
|
+
export declare class UrlEncodedBodyParser implements BodyParser {
|
|
4
|
+
name: symbol;
|
|
5
|
+
private urlencodedParser;
|
|
6
|
+
constructor(options?: RequestBodyParserOptions);
|
|
7
|
+
supports(mediaType: string): boolean;
|
|
8
|
+
parse(request: Request): Promise<RequestBody>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018. 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.UrlEncodedBodyParser = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const context_1 = require("@loopback/context");
|
|
10
|
+
const body_parser_1 = require("body-parser");
|
|
11
|
+
const type_is_1 = require("type-is");
|
|
12
|
+
const keys_1 = require("../keys");
|
|
13
|
+
const body_parser_helpers_1 = require("./body-parser.helpers");
|
|
14
|
+
let UrlEncodedBodyParser = /** @class */ (() => {
|
|
15
|
+
let UrlEncodedBodyParser = class UrlEncodedBodyParser {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.name = body_parser_helpers_1.builtinParsers.urlencoded;
|
|
18
|
+
const urlencodedOptions = body_parser_helpers_1.getParserOptions('urlencoded', options);
|
|
19
|
+
this.urlencodedParser = body_parser_1.urlencoded(urlencodedOptions);
|
|
20
|
+
}
|
|
21
|
+
supports(mediaType) {
|
|
22
|
+
return !!type_is_1.is(mediaType, 'urlencoded');
|
|
23
|
+
}
|
|
24
|
+
async parse(request) {
|
|
25
|
+
const body = await body_parser_helpers_1.invokeBodyParserMiddleware(this.urlencodedParser, request);
|
|
26
|
+
return { value: body, coercionRequired: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
UrlEncodedBodyParser = tslib_1.__decorate([
|
|
30
|
+
tslib_1.__param(0, context_1.inject(keys_1.RestBindings.REQUEST_BODY_PARSER_OPTIONS, { optional: true })),
|
|
31
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
32
|
+
], UrlEncodedBodyParser);
|
|
33
|
+
return UrlEncodedBodyParser;
|
|
34
|
+
})();
|
|
35
|
+
exports.UrlEncodedBodyParser = UrlEncodedBodyParser;
|
|
36
|
+
//# sourceMappingURL=body-parser.urlencoded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-parser.urlencoded.js","sourceRoot":"","sources":["../../src/body-parsers/body-parser.urlencoded.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAAyC;AACzC,6CAAuC;AACvC,qCAA2B;AAC3B,kCAAqC;AAErC,+DAK+B;AAG/B;IAAA,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;QAI/B,YAEE,UAAoC,EAAE;YALxC,SAAI,GAAG,oCAAc,CAAC,UAAU,CAAC;YAO/B,MAAM,iBAAiB,GAAG,sCAAgB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YAClE,IAAI,CAAC,gBAAgB,GAAG,wBAAU,CAAC,iBAAiB,CAAC,CAAC;QACxD,CAAC;QAED,QAAQ,CAAC,SAAiB;YACxB,OAAO,CAAC,CAAC,YAAE,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACvC,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,OAAgB;YAC1B,MAAM,IAAI,GAAG,MAAM,gDAA0B,CAC3C,IAAI,CAAC,gBAAgB,EACrB,OAAO,CACR,CAAC;YACF,OAAO,EAAC,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAC,CAAC;QAC/C,CAAC;KACF,CAAA;IAvBY,oBAAoB;QAK5B,mBAAA,gBAAM,CAAC,mBAAY,CAAC,2BAA2B,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;;OAL1D,oBAAoB,CAuBhC;IAAD,2BAAC;KAAA;AAvBY,oDAAoB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './body-parser';
|
|
2
|
+
export * from './body-parser.helpers';
|
|
3
|
+
export * from './body-parser.json';
|
|
4
|
+
export * from './body-parser.raw';
|
|
5
|
+
export * from './body-parser.stream';
|
|
6
|
+
export * from './body-parser.text';
|
|
7
|
+
export * from './body-parser.urlencoded';
|
|
8
|
+
export * from './types';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018. 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
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
tslib_1.__exportStar(require("./body-parser"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./body-parser.helpers"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./body-parser.json"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./body-parser.raw"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./body-parser.stream"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./body-parser.text"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./body-parser.urlencoded"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/body-parsers/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,wDAA8B;AAC9B,gEAAsC;AACtC,6DAAmC;AACnC,4DAAkC;AAClC,+DAAqC;AACrC,6DAAmC;AACnC,mEAAyC;AACzC,kDAAwB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ReferenceObject, SchemaObject } from '@loopback/openapi-v3';
|
|
2
|
+
import { Request } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Request body with metadata
|
|
5
|
+
*/
|
|
6
|
+
export declare type RequestBody = {
|
|
7
|
+
/**
|
|
8
|
+
* Parsed value of the request body
|
|
9
|
+
*/
|
|
10
|
+
value: any | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Is coercion required? Some forms of request such as urlencoded don't
|
|
13
|
+
* have rich types such as number or boolean.
|
|
14
|
+
*/
|
|
15
|
+
coercionRequired?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Resolved media type
|
|
18
|
+
*/
|
|
19
|
+
mediaType?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Corresponding schema for the request body
|
|
22
|
+
*/
|
|
23
|
+
schema?: SchemaObject | ReferenceObject;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Interface to be implemented by body parser extensions
|
|
27
|
+
*/
|
|
28
|
+
export interface BodyParser {
|
|
29
|
+
/**
|
|
30
|
+
* Name of the parser
|
|
31
|
+
*/
|
|
32
|
+
name: string | symbol;
|
|
33
|
+
/**
|
|
34
|
+
* Indicate if the given media type is supported
|
|
35
|
+
* @param mediaType - Media type
|
|
36
|
+
*/
|
|
37
|
+
supports(mediaType: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Parse the request body
|
|
40
|
+
* @param request - http request
|
|
41
|
+
*/
|
|
42
|
+
parse(request: Request): Promise<RequestBody>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Plain function for body parsing
|
|
46
|
+
*/
|
|
47
|
+
export declare type BodyParserFunction = (request: Request) => Promise<RequestBody>;
|
|
48
|
+
/**
|
|
49
|
+
* Binding tag for request body parser extensions
|
|
50
|
+
*/
|
|
51
|
+
export declare const REQUEST_BODY_PARSER_TAG = "rest.requestBodyParser";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,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.REQUEST_BODY_PARSER_TAG = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Binding tag for request body parser extensions
|
|
10
|
+
*/
|
|
11
|
+
exports.REQUEST_BODY_PARSER_TAG = 'rest.requestBodyParser';
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/body-parsers/types.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAqDhE;;GAEG;AACU,QAAA,uBAAuB,GAAG,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParameterObject } from '@loopback/openapi-v3';
|
|
2
|
+
/**
|
|
3
|
+
* Coerce the http raw data to a JavaScript type data of a parameter
|
|
4
|
+
* according to its OpenAPI schema specification.
|
|
5
|
+
*
|
|
6
|
+
* @param data - The raw data get from http request
|
|
7
|
+
* @param schema - The parameter's schema defined in OpenAPI specification
|
|
8
|
+
*/
|
|
9
|
+
export declare function coerceParameter(data: string | undefined | object, spec: ParameterObject): string | number | boolean | object | undefined;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,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.coerceParameter = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const openapi_v3_1 = require("@loopback/openapi-v3");
|
|
10
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
11
|
+
const __1 = require("../");
|
|
12
|
+
const parse_json_1 = require("../parse-json");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
const validator_1 = require("./validator");
|
|
15
|
+
const isRFC3339 = require('validator/lib/isRFC3339');
|
|
16
|
+
const debug = debug_1.default('loopback:rest:coercion');
|
|
17
|
+
/**
|
|
18
|
+
* Coerce the http raw data to a JavaScript type data of a parameter
|
|
19
|
+
* according to its OpenAPI schema specification.
|
|
20
|
+
*
|
|
21
|
+
* @param data - The raw data get from http request
|
|
22
|
+
* @param schema - The parameter's schema defined in OpenAPI specification
|
|
23
|
+
*/
|
|
24
|
+
function coerceParameter(data, spec) {
|
|
25
|
+
let schema = spec.schema;
|
|
26
|
+
// If a query parameter is a url encoded Json object, the schema is defined under content['application/json']
|
|
27
|
+
if (!schema && spec.in === 'query' && spec.content) {
|
|
28
|
+
const jsonSpec = spec.content['application/json'];
|
|
29
|
+
schema = jsonSpec.schema;
|
|
30
|
+
}
|
|
31
|
+
if (!schema || openapi_v3_1.isReferenceObject(schema)) {
|
|
32
|
+
debug('The parameter with schema %s is not coerced since schema' +
|
|
33
|
+
'dereference is not supported yet.', schema);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
const OAIType = utils_1.getOAIPrimitiveType(schema.type, schema.format);
|
|
37
|
+
const validator = new validator_1.Validator({ parameterSpec: spec });
|
|
38
|
+
validator.validateParamBeforeCoercion(data);
|
|
39
|
+
if (data === undefined)
|
|
40
|
+
return data;
|
|
41
|
+
switch (OAIType) {
|
|
42
|
+
case 'byte':
|
|
43
|
+
return coerceBuffer(data, spec);
|
|
44
|
+
case 'date':
|
|
45
|
+
return coerceDatetime(data, spec, { dateOnly: true });
|
|
46
|
+
case 'date-time':
|
|
47
|
+
return coerceDatetime(data, spec);
|
|
48
|
+
case 'float':
|
|
49
|
+
case 'double':
|
|
50
|
+
case 'number':
|
|
51
|
+
return coerceNumber(data, spec);
|
|
52
|
+
case 'long':
|
|
53
|
+
return coerceInteger(data, spec, { isLong: true });
|
|
54
|
+
case 'integer':
|
|
55
|
+
return coerceInteger(data, spec);
|
|
56
|
+
case 'boolean':
|
|
57
|
+
return coerceBoolean(data, spec);
|
|
58
|
+
case 'object':
|
|
59
|
+
return coerceObject(data, spec);
|
|
60
|
+
case 'string':
|
|
61
|
+
case 'password':
|
|
62
|
+
return coerceString(data, spec);
|
|
63
|
+
default:
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.coerceParameter = coerceParameter;
|
|
68
|
+
function coerceString(data, spec) {
|
|
69
|
+
if (typeof data !== 'string')
|
|
70
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
71
|
+
debug('data of type string is coerced to %s', data);
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
function coerceBuffer(data, spec) {
|
|
75
|
+
if (typeof data === 'object')
|
|
76
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
77
|
+
return Buffer.from(data, 'base64');
|
|
78
|
+
}
|
|
79
|
+
function coerceDatetime(data, spec, options) {
|
|
80
|
+
if (typeof data === 'object' || utils_1.isEmpty(data))
|
|
81
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
82
|
+
if (options === null || options === void 0 ? void 0 : options.dateOnly) {
|
|
83
|
+
if (!utils_1.matchDateFormat(data))
|
|
84
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (!isRFC3339(data))
|
|
88
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
89
|
+
}
|
|
90
|
+
const coercedDate = new Date(data);
|
|
91
|
+
if (!utils_1.isValidDateTime(coercedDate))
|
|
92
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
93
|
+
return coercedDate;
|
|
94
|
+
}
|
|
95
|
+
function coerceNumber(data, spec) {
|
|
96
|
+
if (typeof data === 'object' || utils_1.isEmpty(data))
|
|
97
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
98
|
+
const coercedNum = Number(data);
|
|
99
|
+
if (isNaN(coercedNum))
|
|
100
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
101
|
+
debug('data of type number is coerced to %s', coercedNum);
|
|
102
|
+
return coercedNum;
|
|
103
|
+
}
|
|
104
|
+
function coerceInteger(data, spec, options) {
|
|
105
|
+
if (typeof data === 'object' || utils_1.isEmpty(data))
|
|
106
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
107
|
+
const coercedInt = Number(data);
|
|
108
|
+
if (isNaN(coercedInt))
|
|
109
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
110
|
+
if (options === null || options === void 0 ? void 0 : options.isLong) {
|
|
111
|
+
if (!Number.isInteger(coercedInt))
|
|
112
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (!Number.isSafeInteger(coercedInt))
|
|
116
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
117
|
+
}
|
|
118
|
+
debug('data of type integer is coerced to %s', coercedInt);
|
|
119
|
+
return coercedInt;
|
|
120
|
+
}
|
|
121
|
+
function coerceBoolean(data, spec) {
|
|
122
|
+
if (typeof data === 'object' || utils_1.isEmpty(data))
|
|
123
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
124
|
+
if (utils_1.isTrue(data))
|
|
125
|
+
return true;
|
|
126
|
+
if (utils_1.isFalse(data))
|
|
127
|
+
return false;
|
|
128
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name);
|
|
129
|
+
}
|
|
130
|
+
function coerceObject(input, spec) {
|
|
131
|
+
const data = parseJsonIfNeeded(input, spec);
|
|
132
|
+
if (data === undefined) {
|
|
133
|
+
// Skip any further checks and coercions, nothing we can do with `undefined`
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
if (typeof data !== 'object' || Array.isArray(data))
|
|
137
|
+
throw __1.RestHttpErrors.invalidData(input, spec.name);
|
|
138
|
+
// TODO(bajtos) apply coercion based on properties defined by spec.schema
|
|
139
|
+
return data;
|
|
140
|
+
}
|
|
141
|
+
function parseJsonIfNeeded(data, spec) {
|
|
142
|
+
if (typeof data !== 'string')
|
|
143
|
+
return data;
|
|
144
|
+
if (spec.in !== 'query' || (spec.in === 'query' && !spec.content)) {
|
|
145
|
+
debug('Skipping JSON.parse, argument %s is not a url encoded json object query parameter (since content field is missing in parameter schema)', spec.name);
|
|
146
|
+
return data;
|
|
147
|
+
}
|
|
148
|
+
if (data === '') {
|
|
149
|
+
debug('Converted empty string to object value `undefined`');
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const result = parse_json_1.parseJson(data);
|
|
154
|
+
debug('Parsed parameter %s as %j', spec.name, result);
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
debug('Cannot parse %s value %j as JSON: %s', spec.name, data, err.message);
|
|
159
|
+
throw __1.RestHttpErrors.invalidData(data, spec.name, {
|
|
160
|
+
details: {
|
|
161
|
+
syntaxError: err.message,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=coerce-parameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-parameter.js","sourceRoot":"","sources":["../../src/coercion/coerce-parameter.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,qDAAwE;AACxE,0DAAgC;AAChC,2BAAmC;AACnC,8CAAwC;AACxC,mCASiB;AACjB,2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,CAAC,IAAI,CAAC;QACjD,MAAM,kBAAc,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAErD,yEAAyE;IACzE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,iBAAiB,CACxB,IAAqB,EACrB,IAAqB;IAErB,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE1C,IAAI,IAAI,CAAC,EAAE,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QACjE,KAAK,CACH,wIAAwI,EACxI,IAAI,CAAC,IAAI,CACV,CAAC;QACF,OAAO,IAAI,CAAC;KACb;IAED,IAAI,IAAI,KAAK,EAAE,EAAE;QACf,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAC5D,OAAO,SAAS,CAAC;KAClB;IAED,IAAI;QACF,MAAM,MAAM,GAAG,sBAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,KAAK,CAAC,2BAA2B,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACtD,OAAO,MAAM,CAAC;KACf;IAAC,OAAO,GAAG,EAAE;QACZ,KAAK,CAAC,sCAAsC,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC5E,MAAM,kBAAc,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YAChD,OAAO,EAAE;gBACP,WAAW,EAAE,GAAG,CAAC,OAAO;aACzB;SACF,CAAC,CAAC;KACJ;AACH,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for function coerceDatetime
|
|
3
|
+
*/
|
|
4
|
+
export declare type DateCoercionOptions = {
|
|
5
|
+
dateOnly?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Options for function coerceInteger
|
|
9
|
+
*/
|
|
10
|
+
export declare type IntegerCoercionOptions = {
|
|
11
|
+
isLong?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function isEmpty(data: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* A set of truthy values. A data in this set will be coerced to `true`.
|
|
16
|
+
*
|
|
17
|
+
* @param data - The raw data get from http request
|
|
18
|
+
* @returns The corresponding coerced boolean type
|
|
19
|
+
*/
|
|
20
|
+
export declare function isTrue(data: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* A set of falsy values. A data in this set will be coerced to `false`.
|
|
23
|
+
* @param data - The raw data get from http request
|
|
24
|
+
* @returns The corresponding coerced boolean type
|
|
25
|
+
*/
|
|
26
|
+
export declare function isFalse(data: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Return false for invalid date
|
|
29
|
+
*/
|
|
30
|
+
export declare function isValidDateTime(data: Date): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Return true when a date follows the RFC3339 standard
|
|
33
|
+
*
|
|
34
|
+
* @param date - The date to verify
|
|
35
|
+
*/
|
|
36
|
+
export declare function matchDateFormat(date: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Return the corresponding OpenAPI data type given an OpenAPI schema
|
|
39
|
+
*
|
|
40
|
+
* @param type - The type in an OpenAPI schema specification
|
|
41
|
+
* @param format - The format in an OpenAPI schema specification
|
|
42
|
+
*/
|
|
43
|
+
export declare function getOAIPrimitiveType(type?: string, format?: string): "object" | "boolean" | "string" | "number" | "array" | "byte" | "binary" | "date" | "date-time" | "password" | "float" | "double" | "long" | "integer" | undefined;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,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.getOAIPrimitiveType = exports.matchDateFormat = exports.isValidDateTime = exports.isFalse = exports.isTrue = exports.isEmpty = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
10
|
+
const debug = debug_1.default('loopback:rest:coercion');
|
|
11
|
+
function isEmpty(data) {
|
|
12
|
+
const result = data === '';
|
|
13
|
+
debug('isEmpty(%j) -> %s', data, result);
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
exports.isEmpty = isEmpty;
|
|
17
|
+
/**
|
|
18
|
+
* A set of truthy values. A data in this set will be coerced to `true`.
|
|
19
|
+
*
|
|
20
|
+
* @param data - The raw data get from http request
|
|
21
|
+
* @returns The corresponding coerced boolean type
|
|
22
|
+
*/
|
|
23
|
+
function isTrue(data) {
|
|
24
|
+
return ['TRUE', '1'].includes(data.toUpperCase());
|
|
25
|
+
}
|
|
26
|
+
exports.isTrue = isTrue;
|
|
27
|
+
/**
|
|
28
|
+
* A set of falsy values. A data in this set will be coerced to `false`.
|
|
29
|
+
* @param data - The raw data get from http request
|
|
30
|
+
* @returns The corresponding coerced boolean type
|
|
31
|
+
*/
|
|
32
|
+
function isFalse(data) {
|
|
33
|
+
return ['FALSE', '0'].includes(data.toUpperCase());
|
|
34
|
+
}
|
|
35
|
+
exports.isFalse = isFalse;
|
|
36
|
+
/**
|
|
37
|
+
* Return false for invalid date
|
|
38
|
+
*/
|
|
39
|
+
function isValidDateTime(data) {
|
|
40
|
+
return isNaN(data.getTime()) ? false : true;
|
|
41
|
+
}
|
|
42
|
+
exports.isValidDateTime = isValidDateTime;
|
|
43
|
+
const REGEX_RFC3339_DATE = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])$/;
|
|
44
|
+
/**
|
|
45
|
+
* Return true when a date follows the RFC3339 standard
|
|
46
|
+
*
|
|
47
|
+
* @param date - The date to verify
|
|
48
|
+
*/
|
|
49
|
+
function matchDateFormat(date) {
|
|
50
|
+
const pattern = new RegExp(REGEX_RFC3339_DATE);
|
|
51
|
+
const result = pattern.test(date);
|
|
52
|
+
debug('matchDateFormat(%j) -> %s', date, result);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
exports.matchDateFormat = matchDateFormat;
|
|
56
|
+
/**
|
|
57
|
+
* Return the corresponding OpenAPI data type given an OpenAPI schema
|
|
58
|
+
*
|
|
59
|
+
* @param type - The type in an OpenAPI schema specification
|
|
60
|
+
* @param format - The format in an OpenAPI schema specification
|
|
61
|
+
*/
|
|
62
|
+
function getOAIPrimitiveType(type, format) {
|
|
63
|
+
if (type === 'object' || type === 'array')
|
|
64
|
+
return type;
|
|
65
|
+
if (type === 'string') {
|
|
66
|
+
switch (format) {
|
|
67
|
+
case 'byte':
|
|
68
|
+
return 'byte';
|
|
69
|
+
case 'binary':
|
|
70
|
+
return 'binary';
|
|
71
|
+
case 'date':
|
|
72
|
+
return 'date';
|
|
73
|
+
case 'date-time':
|
|
74
|
+
return 'date-time';
|
|
75
|
+
case 'password':
|
|
76
|
+
return 'password';
|
|
77
|
+
default:
|
|
78
|
+
return 'string';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (type === 'boolean')
|
|
82
|
+
return 'boolean';
|
|
83
|
+
if (type === 'number')
|
|
84
|
+
switch (format) {
|
|
85
|
+
case 'float':
|
|
86
|
+
return 'float';
|
|
87
|
+
case 'double':
|
|
88
|
+
return 'double';
|
|
89
|
+
default:
|
|
90
|
+
return 'number';
|
|
91
|
+
}
|
|
92
|
+
if (type === 'integer')
|
|
93
|
+
return format === 'int64' ? 'long' : 'integer';
|
|
94
|
+
}
|
|
95
|
+
exports.getOAIPrimitiveType = getOAIPrimitiveType;
|
|
96
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/coercion/utils.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Aa,EAAE,MAAe;IAChE,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IACvD,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,QAAQ,MAAM,EAAE;YACd,KAAK,MAAM;gBACT,OAAO,MAAM,CAAC;YAChB,KAAK,QAAQ;gBACX,OAAO,QAAQ,CAAC;YAClB,KAAK,MAAM;gBACT,OAAO,MAAM,CAAC;YAChB,KAAK,WAAW;gBACd,OAAO,WAAW,CAAC;YACrB,KAAK,UAAU;gBACb,OAAO,UAAU,CAAC;YACpB;gBACE,OAAO,QAAQ,CAAC;SACnB;KACF;IACD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,IAAI,KAAK,QAAQ;QACnB,QAAQ,MAAM,EAAE;YACd,KAAK,OAAO;gBACV,OAAO,OAAO,CAAC;YACjB,KAAK,QAAQ;gBACX,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,QAAQ,CAAC;SACnB;IACH,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC;AA7BD,kDA6BC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ParameterObject } from '@loopback/openapi-v3';
|
|
2
|
+
/**
|
|
3
|
+
* A set of options to pass into the validator functions
|
|
4
|
+
*/
|
|
5
|
+
export declare type ValidationOptions = {
|
|
6
|
+
required?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The context information that a validator needs
|
|
10
|
+
*/
|
|
11
|
+
export declare type ValidationContext = {
|
|
12
|
+
parameterSpec: ParameterObject;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Validator class provides a bunch of functions that perform
|
|
16
|
+
* validations on the request parameters and request body.
|
|
17
|
+
*/
|
|
18
|
+
export declare class Validator {
|
|
19
|
+
ctx: ValidationContext;
|
|
20
|
+
constructor(ctx: ValidationContext);
|
|
21
|
+
/**
|
|
22
|
+
* The validation executed before type coercion. Like
|
|
23
|
+
* checking absence.
|
|
24
|
+
*
|
|
25
|
+
* @param type - A parameter's type.
|
|
26
|
+
* @param value - A parameter's raw value from http request.
|
|
27
|
+
* @param opts - options
|
|
28
|
+
*/
|
|
29
|
+
validateParamBeforeCoercion(value: string | object | undefined, opts?: ValidationOptions): void;
|
|
30
|
+
/**
|
|
31
|
+
* Check is a parameter required or not.
|
|
32
|
+
*
|
|
33
|
+
* @param opts
|
|
34
|
+
*/
|
|
35
|
+
isRequired(opts?: ValidationOptions): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Return `true` if the value is empty, return `false` otherwise.
|
|
38
|
+
*
|
|
39
|
+
* @param value
|
|
40
|
+
*/
|
|
41
|
+
isAbsent(value: any): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Return `true` if defined specification is for a url encoded Json object query parameter
|
|
44
|
+
*
|
|
45
|
+
* for url encoded Json object query parameters,
|
|
46
|
+
* schema is defined under content['application/json']
|
|
47
|
+
*/
|
|
48
|
+
isUrlEncodedJsonParam(): boolean;
|
|
49
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,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.Validator = void 0;
|
|
8
|
+
const __1 = require("../");
|
|
9
|
+
/**
|
|
10
|
+
* Validator class provides a bunch of functions that perform
|
|
11
|
+
* validations on the request parameters and request body.
|
|
12
|
+
*/
|
|
13
|
+
class Validator {
|
|
14
|
+
constructor(ctx) {
|
|
15
|
+
this.ctx = ctx;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The validation executed before type coercion. Like
|
|
19
|
+
* checking absence.
|
|
20
|
+
*
|
|
21
|
+
* @param type - A parameter's type.
|
|
22
|
+
* @param value - A parameter's raw value from http request.
|
|
23
|
+
* @param opts - options
|
|
24
|
+
*/
|
|
25
|
+
validateParamBeforeCoercion(value, opts) {
|
|
26
|
+
if (this.isAbsent(value) && this.isRequired(opts)) {
|
|
27
|
+
const name = this.ctx.parameterSpec.name;
|
|
28
|
+
throw __1.RestHttpErrors.missingRequired(name);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check is a parameter required or not.
|
|
33
|
+
*
|
|
34
|
+
* @param opts
|
|
35
|
+
*/
|
|
36
|
+
isRequired(opts) {
|
|
37
|
+
if (this.ctx.parameterSpec.required)
|
|
38
|
+
return true;
|
|
39
|
+
if (opts === null || opts === void 0 ? void 0 : opts.required)
|
|
40
|
+
return true;
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Return `true` if the value is empty, return `false` otherwise.
|
|
45
|
+
*
|
|
46
|
+
* @param value
|
|
47
|
+
*/
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
isAbsent(value) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (value === '' || value === undefined)
|
|
52
|
+
return true;
|
|
53
|
+
const spec = this.ctx.parameterSpec;
|
|
54
|
+
const schema = (_a = this.ctx.parameterSpec.schema) !== null && _a !== void 0 ? _a : {};
|
|
55
|
+
const valueIsNull = value === 'null' || value === null;
|
|
56
|
+
if (this.isUrlEncodedJsonParam()) {
|
|
57
|
+
// is this an url encoded Json object query parameter?
|
|
58
|
+
// check for NULL values
|
|
59
|
+
if (valueIsNull)
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
else if (spec.schema) {
|
|
63
|
+
// if parameter spec contains schema object, check if supplied value is NULL
|
|
64
|
+
if (schema.type === 'object' && valueIsNull)
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return `true` if defined specification is for a url encoded Json object query parameter
|
|
71
|
+
*
|
|
72
|
+
* for url encoded Json object query parameters,
|
|
73
|
+
* schema is defined under content['application/json']
|
|
74
|
+
*/
|
|
75
|
+
isUrlEncodedJsonParam() {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
const spec = this.ctx.parameterSpec;
|
|
78
|
+
if (spec.in === 'query' && ((_b = (_a = spec.content) === null || _a === void 0 ? void 0 : _a['application/json']) === null || _b === void 0 ? void 0 : _b.schema)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.Validator = Validator;
|
|
85
|
+
//# sourceMappingURL=validator.js.map
|