oak-domain 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/es/actions/action.d.ts +1 -1
- package/es/base-app-domain/EntityDict.d.ts +27 -0
- package/es/base-app-domain/LocalizedContent/Schema.d.ts +19 -0
- package/es/base-app-domain/LocalizedContent/Schema.js +1 -0
- package/es/base-app-domain/LocalizedContent/Storage.d.ts +3 -0
- package/es/base-app-domain/LocalizedContent/Storage.js +75 -0
- package/es/base-app-domain/LocalizedContent/Style.d.ts +3 -0
- package/es/base-app-domain/LocalizedContent/Style.js +12 -0
- package/es/base-app-domain/LocalizedContent/_baseSchema.d.ts +58 -0
- package/es/base-app-domain/Storage.js +2 -0
- package/es/base-app-domain/StyleDict.js +2 -0
- package/es/compiler/customChecks/i18n.js +4 -1
- package/es/compiler/customChecks/runner.d.ts +1 -1
- package/es/compiler/customChecks/runner.js +1 -1
- package/es/compiler/customChecks/types.d.ts +2 -1
- package/es/compiler/dependencyBuilder.d.ts +11 -2
- package/es/compiler/dependencyBuilder.js +188 -199
- package/es/compiler/entityDescEnum.d.ts +5 -0
- package/es/compiler/entityDescEnum.js +443 -0
- package/es/compiler/entitySource.d.ts +28 -0
- package/es/compiler/entitySource.js +521 -0
- package/es/compiler/localeBuilder.d.ts +7 -2
- package/es/compiler/localeBuilder.js +52 -56
- package/es/compiler/routerBuilder.d.ts +32 -3
- package/es/compiler/routerBuilder.js +157 -45
- package/es/compiler/schemaBuilder.d.ts +12 -2
- package/es/compiler/schemaBuilder.js +653 -148
- package/es/compiler/tscBuilder.d.ts +20 -2
- package/es/compiler/tscBuilder.js +231 -45
- package/es/context/BackendRuntimeContext.d.ts +6 -4
- package/es/context/BackendRuntimeContext.js +9 -1
- package/es/context/ContextComposer.d.ts +93 -0
- package/es/context/ContextComposer.js +353 -0
- package/es/context/SerializedData.d.ts +2 -1
- package/es/data/i18n.d.ts +1 -1
- package/es/data/i18n.js +1 -86
- package/es/data/i18n.json +86 -0
- package/es/entities/ActionAuth.d.ts +3 -3
- package/es/entities/I18n.d.ts +2 -2
- package/es/entities/LocalizedContent.d.ts +22 -0
- package/es/entities/LocalizedContent.js +101 -0
- package/es/entities/Log.d.ts +3 -3
- package/es/entities/Modi.d.ts +2 -2
- package/es/entities/ModiEntity.d.ts +3 -3
- package/es/entities/Oper.d.ts +5 -5
- package/es/entities/OperEntity.d.ts +3 -3
- package/es/entities/Path.d.ts +2 -2
- package/es/entities/Relation.d.ts +2 -2
- package/es/entities/RelationAuth.d.ts +3 -3
- package/es/entities/User.d.ts +4 -4
- package/es/entities/UserEntityClaim.d.ts +6 -6
- package/es/entities/UserEntityGrant.d.ts +2 -2
- package/es/entities/UserRelation.d.ts +4 -4
- package/es/store/AsyncRowStore.d.ts +2 -2
- package/es/store/AsyncRowStore.js +2 -2
- package/es/store/CascadeStore.d.ts +5 -3
- package/es/store/CascadeStore.js +56 -24
- package/es/store/IntrinsicCheckers.d.ts +1 -1
- package/es/store/IntrinsicCheckers.js +2 -2
- package/es/store/IntrinsicLogics.d.ts +1 -1
- package/es/store/RelationAuth.js +3 -3
- package/es/store/SyncRowStore.d.ts +1 -1
- package/es/store/SyncRowStore.js +1 -1
- package/es/store/TriggerExecutor.d.ts +6 -4
- package/es/store/TriggerExecutor.js +16 -4
- package/es/store/checker.d.ts +2 -2
- package/es/store/checker.js +45 -9
- package/es/store/filter.d.ts +3 -3
- package/es/store/filter.js +4 -4
- package/es/store/modi.d.ts +5 -5
- package/es/store/modi.js +4 -4
- package/es/store/projection.d.ts +1 -1
- package/es/store/relation.js +1 -1
- package/es/store/triggers.d.ts +4 -4
- package/es/store/triggers.js +2 -2
- package/es/timers/oper.d.ts +3 -3
- package/es/timers/oper.js +1 -1
- package/es/timers/vaccum.d.ts +3 -3
- package/es/types/Action.d.ts +1 -1
- package/es/types/AppLoader.d.ts +1 -1
- package/es/types/Aspect.d.ts +1 -1
- package/es/types/Auth.d.ts +2 -2
- package/es/types/Configuration.d.ts +7 -6
- package/es/types/Connector.d.ts +47 -1
- package/es/types/DataType.d.ts +2 -2
- package/es/types/Demand.d.ts +40 -6
- package/es/types/Endpoint.d.ts +17 -1
- package/es/types/Entity.d.ts +21 -4
- package/es/types/Entity.js +23 -0
- package/es/types/EntityDesc.d.ts +9 -8
- package/es/types/Environment.d.ts +17 -0
- package/es/types/Exception.d.ts +1 -1
- package/es/types/Exception.js +1 -1
- package/es/types/Expression.d.ts +13 -2
- package/es/types/Expression.js +36 -1
- package/es/types/Locale.d.ts +14 -1
- package/es/types/Locale.js +13 -1
- package/es/types/OakPackage.d.ts +29 -0
- package/es/types/OakPackage.js +30 -0
- package/es/types/Port.d.ts +1 -1
- package/es/types/RowStore.d.ts +9 -7
- package/es/types/Storage.d.ts +11 -3
- package/es/types/Storage.js +12 -1
- package/es/types/Style.d.ts +2 -2
- package/es/types/Sync.d.ts +3 -3
- package/es/types/Timer.d.ts +14 -2
- package/es/types/Trigger.d.ts +1 -1
- package/es/types/Watcher.d.ts +1 -1
- package/es/types/index.d.ts +1 -0
- package/es/types/index.js +1 -0
- package/es/utils/SimpleConnector.d.ts +30 -4
- package/es/utils/SimpleConnector.js +294 -21
- package/es/utils/concurrent.js +1 -1
- package/es/utils/decimal.d.ts +26 -0
- package/es/utils/decimal.js +87 -0
- package/es/utils/fetch/index.d.ts +1 -0
- package/es/utils/fetch/index.js +3 -0
- package/es/utils/fetch/index.mp.d.ts +3 -0
- package/es/utils/fetch/index.mp.js +280 -0
- package/es/utils/fetch/index.native.d.ts +1 -0
- package/es/utils/fetch/index.native.js +3 -0
- package/es/utils/fetch/index.web.d.ts +1 -0
- package/es/utils/fetch/index.web.js +3 -0
- package/es/utils/fetch/shared.d.ts +6 -0
- package/es/utils/fetch/shared.js +23 -0
- package/es/utils/localizedContent.d.ts +11 -0
- package/es/utils/localizedContent.js +346 -0
- package/es/utils/lodash.d.ts +1 -35
- package/es/utils/lodash.js +1 -52
- package/es/utils/module/combine.common.d.ts +3 -3
- package/es/utils/module/combine.common.js +2 -2
- package/es/utils/module/combine.dev.d.ts +2 -2
- package/es/utils/module/combine.dev.js +2 -2
- package/es/utils/module/combine.prod.d.ts +1 -1
- package/es/utils/module/combine.server.d.ts +2 -2
- package/es/utils/module/combine.server.js +2 -2
- package/es/utils/money.d.ts +2 -2
- package/es/utils/money.js +2 -2
- package/es/utils/operationResult.js +1 -1
- package/es/utils/projection.d.ts +3 -3
- package/es/utils/projection.js +1 -1
- package/es/utils/relationPath.d.ts +1 -1
- package/es/utils/relationPath.js +1 -1
- package/es/utils/row.d.ts +3 -3
- package/es/utils/row.js +2 -2
- package/es/utils/sseEndpoint.d.ts +41 -0
- package/es/utils/sseEndpoint.js +151 -0
- package/es/utils/toolkit.d.ts +28 -0
- package/es/utils/toolkit.js +220 -0
- package/es/utils/url/index.d.ts +1 -3
- package/es/utils/url/index.js +1 -1
- package/es/utils/url/index.mp.d.ts +16 -3
- package/es/utils/url/index.mp.js +2 -2
- package/es/utils/url/index.native.d.ts +13 -1
- package/es/utils/url/index.native.js +3 -1
- package/es/utils/url/index.web.d.ts +13 -1
- package/es/utils/url/index.web.js +3 -1
- package/es/utils/url/lightweight.d.ts +65 -0
- package/es/utils/url/lightweight.js +530 -0
- package/es/utils/url/urlObject.d.ts +16 -0
- package/es/utils/validate/id.d.ts +5 -0
- package/es/utils/validate/id.js +28 -0
- package/es/utils/validate/index.d.ts +4 -0
- package/es/utils/validate/index.js +4 -0
- package/es/utils/validate/mobile.d.ts +6 -0
- package/es/utils/validate/mobile.js +49 -0
- package/es/utils/validate/nationality.d.ts +14 -0
- package/es/utils/validate/nationality.data.d.ts +9 -0
- package/es/utils/validate/nationality.data.js +257 -0
- package/es/utils/validate/nationality.js +64 -0
- package/es/utils/validate/passport.d.ts +3 -0
- package/es/utils/validate/passport.js +19 -0
- package/es/utils/validator.d.ts +10 -8
- package/es/utils/validator.js +24 -40
- package/lib/actions/action.d.ts +1 -1
- package/lib/base-app-domain/EntityDict.d.ts +27 -0
- package/lib/base-app-domain/LocalizedContent/Schema.d.ts +19 -0
- package/lib/base-app-domain/LocalizedContent/Schema.js +4 -0
- package/lib/base-app-domain/LocalizedContent/Storage.d.ts +3 -0
- package/lib/base-app-domain/LocalizedContent/Storage.js +78 -0
- package/lib/base-app-domain/LocalizedContent/Style.d.ts +3 -0
- package/lib/base-app-domain/LocalizedContent/Style.js +15 -0
- package/lib/base-app-domain/LocalizedContent/_baseSchema.d.ts +58 -0
- package/lib/base-app-domain/Storage.js +26 -24
- package/lib/base-app-domain/StyleDict.js +10 -8
- package/lib/compiler/customChecks/i18n.js +5 -2
- package/lib/compiler/customChecks/runner.d.ts +1 -1
- package/lib/compiler/customChecks/types.d.ts +2 -1
- package/lib/compiler/dependencyBuilder.d.ts +11 -2
- package/lib/compiler/dependencyBuilder.js +237 -243
- package/lib/compiler/entityDescEnum.d.ts +5 -0
- package/lib/compiler/entityDescEnum.js +450 -0
- package/lib/compiler/entitySource.d.ts +28 -0
- package/lib/compiler/entitySource.js +529 -0
- package/lib/compiler/localeBuilder.d.ts +7 -2
- package/lib/compiler/localeBuilder.js +52 -56
- package/lib/compiler/routerBuilder.d.ts +32 -3
- package/lib/compiler/routerBuilder.js +160 -48
- package/lib/compiler/schemaBuilder.d.ts +12 -2
- package/lib/compiler/schemaBuilder.js +855 -350
- package/lib/compiler/tscBuilder.d.ts +20 -2
- package/lib/compiler/tscBuilder.js +217 -37
- package/lib/context/BackendRuntimeContext.d.ts +6 -4
- package/lib/context/BackendRuntimeContext.js +10 -3
- package/lib/context/ContextComposer.d.ts +93 -0
- package/lib/context/ContextComposer.js +361 -0
- package/lib/context/SerializedData.d.ts +2 -1
- package/lib/data/i18n.d.ts +1 -1
- package/lib/data/i18n.js +1 -86
- package/lib/data/i18n.json +86 -0
- package/lib/entities/ActionAuth.d.ts +3 -3
- package/lib/entities/I18n.d.ts +2 -2
- package/lib/entities/LocalizedContent.d.ts +22 -0
- package/lib/entities/LocalizedContent.js +104 -0
- package/lib/entities/Log.d.ts +3 -3
- package/lib/entities/Modi.d.ts +2 -2
- package/lib/entities/ModiEntity.d.ts +3 -3
- package/lib/entities/Oper.d.ts +5 -5
- package/lib/entities/OperEntity.d.ts +3 -3
- package/lib/entities/Path.d.ts +2 -2
- package/lib/entities/Relation.d.ts +2 -2
- package/lib/entities/RelationAuth.d.ts +3 -3
- package/lib/entities/User.d.ts +4 -4
- package/lib/entities/UserEntityClaim.d.ts +6 -6
- package/lib/entities/UserEntityGrant.d.ts +2 -2
- package/lib/entities/UserRelation.d.ts +4 -4
- package/lib/store/AsyncRowStore.d.ts +2 -2
- package/lib/store/AsyncRowStore.js +6 -7
- package/lib/store/CascadeStore.d.ts +5 -3
- package/lib/store/CascadeStore.js +101 -70
- package/lib/store/IntrinsicCheckers.d.ts +1 -1
- package/lib/store/IntrinsicCheckers.js +12 -13
- package/lib/store/IntrinsicLogics.d.ts +1 -1
- package/lib/store/RelationAuth.js +42 -43
- package/lib/store/SyncRowStore.d.ts +1 -1
- package/lib/store/SyncRowStore.js +4 -5
- package/lib/store/TriggerExecutor.d.ts +6 -4
- package/lib/store/TriggerExecutor.js +39 -28
- package/lib/store/checker.d.ts +2 -2
- package/lib/store/checker.js +55 -20
- package/lib/store/filter.d.ts +3 -3
- package/lib/store/filter.js +47 -48
- package/lib/store/modi.d.ts +5 -5
- package/lib/store/modi.js +5 -6
- package/lib/store/projection.d.ts +1 -1
- package/lib/store/relation.js +4 -5
- package/lib/store/triggers.d.ts +4 -4
- package/lib/store/triggers.js +13 -14
- package/lib/timers/oper.d.ts +3 -3
- package/lib/timers/vaccum.d.ts +3 -3
- package/lib/types/Action.d.ts +1 -1
- package/lib/types/AppLoader.d.ts +1 -1
- package/lib/types/Aspect.d.ts +1 -1
- package/lib/types/Auth.d.ts +2 -2
- package/lib/types/Configuration.d.ts +7 -6
- package/lib/types/Connector.d.ts +47 -1
- package/lib/types/DataType.d.ts +2 -2
- package/lib/types/Demand.d.ts +40 -6
- package/lib/types/Endpoint.d.ts +17 -1
- package/lib/types/Entity.d.ts +21 -4
- package/lib/types/Entity.js +27 -0
- package/lib/types/EntityDesc.d.ts +9 -8
- package/lib/types/Environment.d.ts +17 -0
- package/lib/types/Exception.d.ts +1 -1
- package/lib/types/Exception.js +2 -2
- package/lib/types/Expression.d.ts +13 -2
- package/lib/types/Expression.js +40 -5
- package/lib/types/Locale.d.ts +14 -1
- package/lib/types/Locale.js +14 -0
- package/lib/types/OakPackage.d.ts +29 -0
- package/lib/types/OakPackage.js +36 -0
- package/lib/types/Port.d.ts +1 -1
- package/lib/types/RowStore.d.ts +9 -7
- package/lib/types/Storage.d.ts +11 -3
- package/lib/types/Storage.js +13 -0
- package/lib/types/Style.d.ts +2 -2
- package/lib/types/Sync.d.ts +3 -3
- package/lib/types/Timer.d.ts +14 -2
- package/lib/types/Trigger.d.ts +1 -1
- package/lib/types/Watcher.d.ts +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/utils/SimpleConnector.d.ts +30 -4
- package/lib/utils/SimpleConnector.js +297 -24
- package/lib/utils/concurrent.js +4 -5
- package/lib/utils/decimal.d.ts +26 -0
- package/lib/utils/decimal.js +112 -0
- package/lib/utils/fetch/index.d.ts +1 -0
- package/lib/utils/fetch/index.js +6 -0
- package/lib/utils/fetch/index.mp.d.ts +3 -0
- package/lib/utils/fetch/index.mp.js +285 -0
- package/lib/utils/fetch/index.native.d.ts +1 -0
- package/lib/utils/fetch/index.native.js +6 -0
- package/lib/utils/fetch/index.web.d.ts +1 -0
- package/lib/utils/fetch/index.web.js +6 -0
- package/lib/utils/fetch/shared.d.ts +6 -0
- package/lib/utils/fetch/shared.js +28 -0
- package/lib/utils/localizedContent.d.ts +11 -0
- package/lib/utils/localizedContent.js +352 -0
- package/lib/utils/lodash.d.ts +1 -35
- package/lib/utils/lodash.js +1 -76
- package/lib/utils/module/combine.common.d.ts +3 -3
- package/lib/utils/module/combine.common.js +6 -7
- package/lib/utils/module/combine.dev.d.ts +2 -2
- package/lib/utils/module/combine.dev.js +19 -19
- package/lib/utils/module/combine.prod.d.ts +1 -1
- package/lib/utils/module/combine.server.d.ts +2 -2
- package/lib/utils/module/combine.server.js +19 -19
- package/lib/utils/money.d.ts +2 -2
- package/lib/utils/money.js +2 -2
- package/lib/utils/operationResult.js +4 -4
- package/lib/utils/projection.d.ts +3 -3
- package/lib/utils/relationPath.d.ts +1 -1
- package/lib/utils/relationPath.js +10 -11
- package/lib/utils/row.d.ts +3 -3
- package/lib/utils/row.js +4 -5
- package/lib/utils/sseEndpoint.d.ts +41 -0
- package/lib/utils/sseEndpoint.js +156 -0
- package/lib/utils/toolkit.d.ts +28 -0
- package/lib/utils/toolkit.js +253 -0
- package/lib/utils/url/index.d.ts +1 -3
- package/lib/utils/url/index.js +3 -1
- package/lib/utils/url/index.mp.d.ts +16 -3
- package/lib/utils/url/index.mp.js +6 -4
- package/lib/utils/url/index.native.d.ts +13 -1
- package/lib/utils/url/index.native.js +5 -1
- package/lib/utils/url/index.web.d.ts +13 -1
- package/lib/utils/url/index.web.js +5 -1
- package/lib/utils/url/lightweight.d.ts +65 -0
- package/lib/utils/url/lightweight.js +535 -0
- package/lib/utils/url/urlObject.d.ts +16 -0
- package/lib/utils/url/urlObject.js +2 -0
- package/lib/utils/url/whatwg-url/lib/URL-impl.d.ts +8 -15
- package/lib/utils/url/whatwg-url/lib/infra.js +5 -4
- package/lib/utils/url/whatwg-url/lib/urlencoded.d.ts +3 -1
- package/lib/utils/url/whatwg-url/lib/utils.d.ts +1 -1
- package/lib/utils/validate/id.d.ts +5 -0
- package/lib/utils/validate/id.js +35 -0
- package/lib/utils/validate/index.d.ts +4 -0
- package/lib/utils/validate/index.js +7 -0
- package/lib/utils/validate/mobile.d.ts +6 -0
- package/lib/utils/validate/mobile.js +57 -0
- package/lib/utils/validate/nationality.d.ts +14 -0
- package/lib/utils/validate/nationality.data.d.ts +9 -0
- package/lib/utils/validate/nationality.data.js +260 -0
- package/lib/utils/validate/nationality.js +76 -0
- package/lib/utils/validate/passport.d.ts +3 -0
- package/lib/utils/validate/passport.js +24 -0
- package/lib/utils/validator.d.ts +10 -8
- package/lib/utils/validator.js +38 -42
- package/package.json +19 -9
- package/es/utils/url/whatwg-url/index.d.ts +0 -3
- package/es/utils/url/whatwg-url/index.js +0 -12
- package/es/utils/url/whatwg-url/lib/URL-impl.d.ts +0 -27
- package/es/utils/url/whatwg-url/lib/URL-impl.js +0 -172
- package/es/utils/url/whatwg-url/lib/URL.js +0 -295
- package/es/utils/url/whatwg-url/lib/URLSearchParams-impl.d.ts +0 -19
- package/es/utils/url/whatwg-url/lib/URLSearchParams-impl.js +0 -123
- package/es/utils/url/whatwg-url/lib/URLSearchParams.js +0 -423
- package/es/utils/url/whatwg-url/lib/infra.d.ts +0 -12
- package/es/utils/url/whatwg-url/lib/infra.js +0 -19
- package/es/utils/url/whatwg-url/lib/url-state-machine.d.ts +0 -24
- package/es/utils/url/whatwg-url/lib/url-state-machine.js +0 -1228
- package/es/utils/url/whatwg-url/lib/urlencoded.d.ts +0 -14
- package/es/utils/url/whatwg-url/lib/urlencoded.js +0 -160
- package/es/utils/url/whatwg-url/lib/utils.d.ts +0 -37
- package/es/utils/url/whatwg-url/lib/utils.js +0 -99
- package/lib/store/diffSchema.d.ts +0 -1
- package/lib/utils/url/whatwg-url/index.d.ts +0 -3
- package/lib/utils/url/whatwg-url/index.js +0 -16
- package/lib/utils/url/whatwg-url/lib/URL-impl.js +0 -175
- package/lib/utils/url/whatwg-url/lib/URL.d.ts +0 -1
- package/lib/utils/url/whatwg-url/lib/URL.js +0 -298
- package/lib/utils/url/whatwg-url/lib/URLSearchParams-impl.d.ts +0 -19
- package/lib/utils/url/whatwg-url/lib/URLSearchParams-impl.js +0 -126
- package/lib/utils/url/whatwg-url/lib/URLSearchParams.d.ts +0 -1
- package/lib/utils/url/whatwg-url/lib/URLSearchParams.js +0 -426
- package/lib/utils/url/whatwg-url/lib/infra.d.ts +0 -12
- package/lib/utils/url/whatwg-url/lib/url-state-machine.d.ts +0 -24
- package/lib/utils/url/whatwg-url/lib/url-state-machine.js +0 -1238
- package/lib/utils/url/whatwg-url/lib/urlencoded.js +0 -162
- package/lib/utils/url/whatwg-url/lib/utils.js +0 -101
- package/src/entities/ActionAuth.ts +0 -50
- package/src/entities/I18n.ts +0 -53
- package/src/entities/Log.ts +0 -62
- package/src/entities/Modi.ts +0 -107
- package/src/entities/ModiEntity.ts +0 -35
- package/src/entities/Oper.ts +0 -115
- package/src/entities/OperEntity.ts +0 -36
- package/src/entities/Path.ts +0 -56
- package/src/entities/Relation.ts +0 -53
- package/src/entities/RelationAuth.ts +0 -53
- package/src/entities/User.ts +0 -85
- package/src/entities/UserEntityClaim.ts +0 -41
- package/src/entities/UserEntityGrant.ts +0 -33
- package/src/entities/UserRelation.ts +0 -60
- /package/es/{utils/url/whatwg-url/lib/URL.d.ts → base-app-domain/LocalizedContent/_baseSchema.js} +0 -0
- /package/es/utils/url/{whatwg-url/lib/URLSearchParams.d.ts → urlObject.js} +0 -0
- /package/lib/{store/diffSchema.js → base-app-domain/LocalizedContent/_baseSchema.js} +0 -0
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const assert_1 =
|
|
3
|
+
exports.makeServerUrl = makeServerUrl;
|
|
4
|
+
const assert_1 = require("./assert");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const version_1 = require("./version");
|
|
7
|
+
const domain_1 = require("./domain");
|
|
8
|
+
const shared_1 = require("./fetch/shared");
|
|
7
9
|
function isBufferResult(value) {
|
|
8
10
|
return typeof Buffer !== 'undefined' && value instanceof Buffer;
|
|
9
11
|
}
|
|
10
12
|
function isStreamResult(value) {
|
|
11
13
|
return !!value && typeof value === 'object' && typeof value.pipe === 'function';
|
|
12
14
|
}
|
|
15
|
+
function makeServerUrl(configuration) {
|
|
16
|
+
const { ssl, hostname, port, path } = configuration.http;
|
|
17
|
+
const protocol = ssl ? 'https:' : 'http:';
|
|
18
|
+
let serverUrl = `${protocol}//${hostname}`;
|
|
19
|
+
if (typeof port === 'number') {
|
|
20
|
+
serverUrl += `:${port}`;
|
|
21
|
+
}
|
|
22
|
+
if (path) {
|
|
23
|
+
serverUrl += path.startsWith('/') ? path : `/${path}`;
|
|
24
|
+
}
|
|
25
|
+
return serverUrl;
|
|
26
|
+
}
|
|
13
27
|
class SimpleConnector {
|
|
14
28
|
static ASPECT_ROUTER = '/aspect';
|
|
15
29
|
static BRIDGE_ROUTER = '/bridge';
|
|
@@ -28,24 +42,11 @@ class SimpleConnector {
|
|
|
28
42
|
getVersion;
|
|
29
43
|
constructor(configuration, makeException, getVersion) {
|
|
30
44
|
this.configuration = configuration;
|
|
31
|
-
const { routerPrefixes,
|
|
45
|
+
const { routerPrefixes, timeout, clockDriftDuration } = configuration;
|
|
32
46
|
this.timeout = timeout || 5000;
|
|
33
47
|
this.clockDriftDuration = clockDriftDuration || 10000;
|
|
34
|
-
const
|
|
35
|
-
const protocol = ssl ? 'https:' : 'http:';
|
|
36
|
-
let serverUrl = `${protocol}//${hostname}`;
|
|
48
|
+
const serverUrl = makeServerUrl(configuration);
|
|
37
49
|
this.serverUrl = serverUrl;
|
|
38
|
-
if (typeof port === 'number') {
|
|
39
|
-
serverUrl += `:${port}`;
|
|
40
|
-
}
|
|
41
|
-
if (path) {
|
|
42
|
-
if (path.startsWith('/')) {
|
|
43
|
-
serverUrl += path;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
serverUrl += `/${path}`;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
50
|
this.serverAspectUrl = `${serverUrl}${routerPrefixes?.aspect || SimpleConnector.ASPECT_ROUTER}`;
|
|
50
51
|
this.serverBridgeUrl = `${serverUrl}${routerPrefixes?.bridge || SimpleConnector.BRIDGE_ROUTER}`;
|
|
51
52
|
this.serverSubscribePointUrl = `${serverUrl}${routerPrefixes?.getSubscribePoint ||
|
|
@@ -89,7 +90,9 @@ class SimpleConnector {
|
|
|
89
90
|
;
|
|
90
91
|
async parseAspectResult(response) {
|
|
91
92
|
if (response.status > 299) {
|
|
92
|
-
throw new types_1.OakServerProxyException(
|
|
93
|
+
throw new types_1.OakServerProxyException('error::serverProxyException', 'oak-domain', {
|
|
94
|
+
status: response.status,
|
|
95
|
+
});
|
|
93
96
|
}
|
|
94
97
|
const rawMessage = response.headers.get('oak-message');
|
|
95
98
|
const message = rawMessage ? decodeURIComponent(rawMessage) : undefined;
|
|
@@ -174,11 +177,12 @@ class SimpleConnector {
|
|
|
174
177
|
const message = response.headers.get('oak-message');
|
|
175
178
|
const contentType = response.headers.get('Content-Type') || response.headers.get('content-type');
|
|
176
179
|
if (contentType?.toLocaleLowerCase().match(/application\/json/i)) {
|
|
177
|
-
const { socketUrl, subscribeUrl, path } = await response.json();
|
|
180
|
+
const { socketUrl, subscribeUrl, path, scope } = await response.json();
|
|
178
181
|
return {
|
|
179
182
|
path,
|
|
180
183
|
subscribeUrl,
|
|
181
184
|
socketUrl,
|
|
185
|
+
scope,
|
|
182
186
|
};
|
|
183
187
|
}
|
|
184
188
|
else {
|
|
@@ -190,10 +194,279 @@ class SimpleConnector {
|
|
|
190
194
|
getEndpointRouter() {
|
|
191
195
|
return this.configuration.routerPrefixes?.endpoint || SimpleConnector.ENDPOINT_ROUTER;
|
|
192
196
|
}
|
|
197
|
+
makeEndpointUrl(path) {
|
|
198
|
+
return (0, domain_1.urlJoin)(this.serverUrl, this.getEndpointRouter(), path);
|
|
199
|
+
}
|
|
200
|
+
async makeEndpointHeadersAndBody(options, aspectName) {
|
|
201
|
+
const { method = 'get', body, context, headers: extraHeaders } = options || {};
|
|
202
|
+
const cxtStr = context ? await context.toString() : '{}';
|
|
203
|
+
const headers = {
|
|
204
|
+
'oak-cxt': cxtStr,
|
|
205
|
+
'oak-version': this.getVersion?.(),
|
|
206
|
+
'oak-platform': process.env.OAK_PLATFORM || 'unknown',
|
|
207
|
+
...extraHeaders,
|
|
208
|
+
};
|
|
209
|
+
if (aspectName) {
|
|
210
|
+
headers['oak-aspect'] = aspectName;
|
|
211
|
+
}
|
|
212
|
+
if (method === 'get' || method === 'delete') {
|
|
213
|
+
return {
|
|
214
|
+
headers,
|
|
215
|
+
body: undefined,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (process.env.OAK_PLATFORM !== 'wechatMp' && body instanceof FormData) {
|
|
219
|
+
return {
|
|
220
|
+
headers,
|
|
221
|
+
body,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
headers['Content-Type'] = headers['Content-Type'] || 'application/json';
|
|
225
|
+
return {
|
|
226
|
+
headers,
|
|
227
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
buildEndpointUrl(path, options) {
|
|
231
|
+
const url = this.makeEndpointUrl(path);
|
|
232
|
+
if (options?.params) {
|
|
233
|
+
return (0, domain_1.composeUrl)(url, options.params);
|
|
234
|
+
}
|
|
235
|
+
return url;
|
|
236
|
+
}
|
|
237
|
+
async makeSSEEndpointHeadersAndBody(path, options) {
|
|
238
|
+
const result = await this.makeEndpointHeadersAndBody({
|
|
239
|
+
method: 'post',
|
|
240
|
+
body: options?.body,
|
|
241
|
+
context: options?.context,
|
|
242
|
+
headers: options?.headers,
|
|
243
|
+
}, path);
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
createSSEClient(stream) {
|
|
247
|
+
const reader = stream.getReader();
|
|
248
|
+
const decoder = new TextDecoder();
|
|
249
|
+
const callbacks = new Map();
|
|
250
|
+
const errorCallbacks = new Set();
|
|
251
|
+
const doneCallbacks = new Set();
|
|
252
|
+
let buffer = '';
|
|
253
|
+
let closed = false;
|
|
254
|
+
const addCallback = (eventName, callback) => {
|
|
255
|
+
const set = callbacks.get(eventName) || new Set();
|
|
256
|
+
set.add(callback);
|
|
257
|
+
callbacks.set(eventName, set);
|
|
258
|
+
return () => set.delete(callback);
|
|
259
|
+
};
|
|
260
|
+
const dispatch = (event) => {
|
|
261
|
+
if (event.event === 'error') {
|
|
262
|
+
const exception = event.data?.exception;
|
|
263
|
+
const error = exception ? this.makeException(exception) : event.data;
|
|
264
|
+
errorCallbacks.forEach((callback) => callback(error));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
callbacks.get(event.event)?.forEach((callback) => callback(event.data, event));
|
|
268
|
+
if (event.event !== 'message') {
|
|
269
|
+
callbacks.get('message')?.forEach((callback) => callback(event.data, event));
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const parsePacket = (packet) => {
|
|
273
|
+
const lines = packet.split(/\r?\n/);
|
|
274
|
+
let eventName = 'message';
|
|
275
|
+
let id;
|
|
276
|
+
const dataLines = [];
|
|
277
|
+
for (const line of lines) {
|
|
278
|
+
if (!line || line.startsWith(':')) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const index = line.indexOf(':');
|
|
282
|
+
const field = index >= 0 ? line.slice(0, index) : line;
|
|
283
|
+
const value = index >= 0 ? line.slice(index + 1).replace(/^ /, '') : '';
|
|
284
|
+
if (field === 'event') {
|
|
285
|
+
eventName = value || 'message';
|
|
286
|
+
}
|
|
287
|
+
else if (field === 'data') {
|
|
288
|
+
dataLines.push(value);
|
|
289
|
+
}
|
|
290
|
+
else if (field === 'id') {
|
|
291
|
+
id = value;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (dataLines.length === 0) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const rawData = dataLines.join('\n');
|
|
298
|
+
const data = JSON.parse(rawData);
|
|
299
|
+
dispatch({ event: eventName, data, id });
|
|
300
|
+
};
|
|
301
|
+
const pump = async () => {
|
|
302
|
+
try {
|
|
303
|
+
while (!closed) {
|
|
304
|
+
const { value, done } = await reader.read();
|
|
305
|
+
if (done) {
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
buffer += decoder.decode(value, { stream: true });
|
|
309
|
+
const packets = buffer.split(/\r?\n\r?\n/);
|
|
310
|
+
buffer = packets.pop() || '';
|
|
311
|
+
packets.forEach(parsePacket);
|
|
312
|
+
}
|
|
313
|
+
if (buffer.trim()) {
|
|
314
|
+
parsePacket(buffer);
|
|
315
|
+
}
|
|
316
|
+
doneCallbacks.forEach((callback) => callback());
|
|
317
|
+
}
|
|
318
|
+
catch (err) {
|
|
319
|
+
errorCallbacks.forEach((callback) => callback(err));
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
pump();
|
|
323
|
+
return {
|
|
324
|
+
onMessage: (callback) => addCallback('message', callback),
|
|
325
|
+
on: addCallback,
|
|
326
|
+
onError: (callback) => {
|
|
327
|
+
errorCallbacks.add(callback);
|
|
328
|
+
return () => errorCallbacks.delete(callback);
|
|
329
|
+
},
|
|
330
|
+
onDone: (callback) => {
|
|
331
|
+
doneCallbacks.add(callback);
|
|
332
|
+
return () => doneCallbacks.delete(callback);
|
|
333
|
+
},
|
|
334
|
+
close: () => {
|
|
335
|
+
closed = true;
|
|
336
|
+
reader.cancel();
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
async parseEndpointResponse(response) {
|
|
341
|
+
if (response.status > 299) {
|
|
342
|
+
throw new types_1.OakServerProxyException('error::serverProxyException', 'oak-domain', {
|
|
343
|
+
status: response.status,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
const rawMessage = response.headers.get('oak-message');
|
|
347
|
+
const message = rawMessage ? decodeURIComponent(rawMessage) : undefined;
|
|
348
|
+
const responseType = response.headers.get('Content-Type') || response.headers.get('content-type');
|
|
349
|
+
if (responseType?.toLocaleLowerCase().match(/application\/json/i)) {
|
|
350
|
+
const { exception, result, opRecords } = await response.json();
|
|
351
|
+
if (exception) {
|
|
352
|
+
throw this.makeException(exception);
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
result,
|
|
356
|
+
opRecords,
|
|
357
|
+
message,
|
|
358
|
+
status: response.status,
|
|
359
|
+
headers: response.headers,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
result: response.body,
|
|
364
|
+
message,
|
|
365
|
+
status: response.status,
|
|
366
|
+
headers: response.headers,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
async callEndpoint(path, options) {
|
|
370
|
+
const method = (options?.method || 'get').toUpperCase();
|
|
371
|
+
const url = this.buildEndpointUrl(path, options);
|
|
372
|
+
const { headers, body } = await this.makeEndpointHeadersAndBody(options, path);
|
|
373
|
+
let response;
|
|
374
|
+
try {
|
|
375
|
+
response = await this.fetchWithTimeout(url, {
|
|
376
|
+
method,
|
|
377
|
+
headers,
|
|
378
|
+
body,
|
|
379
|
+
}, this.timeout);
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
if (err instanceof types_1.OakRequestTimeoutException) {
|
|
383
|
+
throw new types_1.OakNetworkException(`error::requestTimeout`, 'oak-domain');
|
|
384
|
+
}
|
|
385
|
+
throw new types_1.OakNetworkException(`error::networkException`, 'oak-domain');
|
|
386
|
+
}
|
|
387
|
+
const parsed = await this.parseEndpointResponse(response);
|
|
388
|
+
if (!(parsed.headers && parsed.result instanceof ReadableStream)) {
|
|
389
|
+
return parsed;
|
|
390
|
+
}
|
|
391
|
+
return parsed;
|
|
392
|
+
}
|
|
393
|
+
async openEndpointStream(path, options) {
|
|
394
|
+
const method = (options?.method || 'get').toUpperCase();
|
|
395
|
+
const url = this.buildEndpointUrl(path, options);
|
|
396
|
+
const { headers, body } = await this.makeEndpointHeadersAndBody(options, path);
|
|
397
|
+
let response;
|
|
398
|
+
try {
|
|
399
|
+
response = await this.fetchWithTimeout(url, {
|
|
400
|
+
method,
|
|
401
|
+
headers,
|
|
402
|
+
body,
|
|
403
|
+
}, this.timeout);
|
|
404
|
+
}
|
|
405
|
+
catch (err) {
|
|
406
|
+
if (err instanceof types_1.OakRequestTimeoutException) {
|
|
407
|
+
throw new types_1.OakNetworkException(`error::requestTimeout`, 'oak-domain');
|
|
408
|
+
}
|
|
409
|
+
throw new types_1.OakNetworkException(`error::networkException`, 'oak-domain');
|
|
410
|
+
}
|
|
411
|
+
const parsed = await this.parseEndpointResponse(response);
|
|
412
|
+
if (!(parsed.result instanceof ReadableStream) && !response.body) {
|
|
413
|
+
throw new types_1.OakException('error::content types not yet supported', 'oak-domain', {
|
|
414
|
+
contentType: response.headers.get('Content-Type') || response.headers.get('content-type'),
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
result: parsed.result || response.body,
|
|
419
|
+
message: parsed.message,
|
|
420
|
+
status: response.status,
|
|
421
|
+
headers: response.headers,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
async callSSEEndpoint(path, options) {
|
|
425
|
+
const url = this.makeEndpointUrl(path);
|
|
426
|
+
const { headers, body } = await this.makeSSEEndpointHeadersAndBody(path, options);
|
|
427
|
+
let response;
|
|
428
|
+
try {
|
|
429
|
+
response = await this.fetchWithTimeout(url, {
|
|
430
|
+
method: 'POST',
|
|
431
|
+
headers,
|
|
432
|
+
body,
|
|
433
|
+
oakSSE: true,
|
|
434
|
+
}, this.timeout);
|
|
435
|
+
}
|
|
436
|
+
catch (err) {
|
|
437
|
+
if (err instanceof types_1.OakRequestTimeoutException) {
|
|
438
|
+
throw new types_1.OakNetworkException(`error::requestTimeout`, 'oak-domain');
|
|
439
|
+
}
|
|
440
|
+
throw new types_1.OakNetworkException(`error::networkException`, 'oak-domain');
|
|
441
|
+
}
|
|
442
|
+
if (response.status > 299) {
|
|
443
|
+
throw new types_1.OakServerProxyException('error::serverProxyException', 'oak-domain', {
|
|
444
|
+
status: response.status,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
if (!response.body) {
|
|
448
|
+
throw new types_1.OakException('error::content types not yet supported', 'oak-domain', {
|
|
449
|
+
contentType: response.headers.get('Content-Type') || response.headers.get('content-type'),
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return this.createSSEClient(response.body);
|
|
453
|
+
}
|
|
454
|
+
async serializeSSEEndpointResult(result, headers, body, rawMessage) {
|
|
455
|
+
const message = rawMessage ? encodeURIComponent(rawMessage) : undefined;
|
|
456
|
+
return {
|
|
457
|
+
body: result,
|
|
458
|
+
headers: {
|
|
459
|
+
'Content-Type': 'text/event-stream; charset=utf-8',
|
|
460
|
+
'Cache-Control': 'no-cache, no-transform',
|
|
461
|
+
Connection: 'keep-alive',
|
|
462
|
+
'oak-message': message,
|
|
463
|
+
},
|
|
464
|
+
};
|
|
465
|
+
}
|
|
193
466
|
parseRequest(headers, body, files) {
|
|
194
467
|
const { 'oak-cxt': oakCxtStr, 'oak-aspect': aspectName } = headers;
|
|
195
|
-
(0, assert_1.
|
|
196
|
-
(0, assert_1.
|
|
468
|
+
(0, assert_1.assert)(typeof oakCxtStr === 'string' || oakCxtStr === undefined);
|
|
469
|
+
(0, assert_1.assert)(typeof aspectName === 'string');
|
|
197
470
|
return {
|
|
198
471
|
contextString: oakCxtStr,
|
|
199
472
|
aspectName,
|
|
@@ -257,9 +530,9 @@ class SimpleConnector {
|
|
|
257
530
|
return {};
|
|
258
531
|
}
|
|
259
532
|
async fetchWithTimeout(url, options, timeout = 5000) {
|
|
260
|
-
return
|
|
533
|
+
return (0, shared_1.getGlobalFetch)()(url, options);
|
|
261
534
|
// if (typeof AbortController === 'undefined' || timeout === 0) {
|
|
262
|
-
// return
|
|
535
|
+
// return getGlobalFetch()(url, options);
|
|
263
536
|
// }
|
|
264
537
|
// const controller = new AbortController();
|
|
265
538
|
// const signal = controller.signal;
|
|
@@ -268,7 +541,7 @@ class SimpleConnector {
|
|
|
268
541
|
// controller.abort();
|
|
269
542
|
// }, timeout);
|
|
270
543
|
// // 发起 fetch 请求并传递 signal
|
|
271
|
-
// return
|
|
544
|
+
// return getGlobalFetch()(url, Object.assign({}, options, { signal }))
|
|
272
545
|
// .then(response => {
|
|
273
546
|
// clearTimeout(timeoutId); // 如果请求成功,清除超时
|
|
274
547
|
// return response;
|
package/lib/utils/concurrent.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RWLock = void 0;
|
|
4
|
-
const
|
|
5
|
-
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
4
|
+
const assert_1 = require("./assert");
|
|
6
5
|
/**
|
|
7
6
|
* 模拟一个读写锁,用于同步。
|
|
8
7
|
* 注意,千万不要发生自己等自己
|
|
@@ -36,7 +35,7 @@ class RWLock {
|
|
|
36
35
|
}
|
|
37
36
|
release() {
|
|
38
37
|
if (this.writeNumber) {
|
|
39
|
-
(0, assert_1.
|
|
38
|
+
(0, assert_1.assert)(this.writeNumber === 1);
|
|
40
39
|
this.writeNumber = 0;
|
|
41
40
|
if (this.readWaiter.length > 0) {
|
|
42
41
|
for (const f of this.readWaiter) {
|
|
@@ -50,8 +49,8 @@ class RWLock {
|
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
else {
|
|
53
|
-
(0, assert_1.
|
|
54
|
-
(0, assert_1.
|
|
52
|
+
(0, assert_1.assert)(this.readNumber > 0);
|
|
53
|
+
(0, assert_1.assert)(this.readWaiter.length === 0);
|
|
55
54
|
this.readNumber--;
|
|
56
55
|
if (this.readNumber === 0) {
|
|
57
56
|
const f = this.writeWaiter.pop();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
export type DecimalValue = string | null | undefined;
|
|
3
|
+
export type DecimalInput = string | null | undefined;
|
|
4
|
+
export type DecimalCalculationInput = DecimalInput | BigNumber;
|
|
5
|
+
export declare function toBigNumber(value: DecimalCalculationInput): BigNumber;
|
|
6
|
+
export declare function toDecimalString(value: DecimalInput): string;
|
|
7
|
+
export declare function numberToDecimalString(value: number | string): string;
|
|
8
|
+
export declare function requireDecimalString(value: unknown, label: string): string;
|
|
9
|
+
export declare function decimalToDisplayNumber(value: DecimalCalculationInput): number;
|
|
10
|
+
export declare function decimalToApiNumber(value: DecimalCalculationInput): number;
|
|
11
|
+
export declare function decimalRound(value: DecimalCalculationInput, roundingMode?: 4): string;
|
|
12
|
+
export declare function decimalIsZero(value: DecimalCalculationInput): boolean;
|
|
13
|
+
export declare function decimalEq(left: DecimalCalculationInput, right: DecimalCalculationInput): boolean;
|
|
14
|
+
export declare function decimalGt(left: DecimalCalculationInput, right: DecimalCalculationInput): boolean;
|
|
15
|
+
export declare function decimalGte(left: DecimalCalculationInput, right: DecimalCalculationInput): boolean;
|
|
16
|
+
export declare function decimalLt(left: DecimalCalculationInput, right: DecimalCalculationInput): boolean;
|
|
17
|
+
export declare function decimalLte(left: DecimalCalculationInput, right: DecimalCalculationInput): boolean;
|
|
18
|
+
export declare function decimalAdd(left: DecimalCalculationInput, right: DecimalCalculationInput): string;
|
|
19
|
+
export declare function decimalSub(left: DecimalCalculationInput, right: DecimalCalculationInput): string;
|
|
20
|
+
export declare function decimalNeg(value: DecimalCalculationInput): string;
|
|
21
|
+
export declare function decimalAbs(value: DecimalCalculationInput): string;
|
|
22
|
+
export declare function decimalMul(left: DecimalCalculationInput, right: DecimalCalculationInput): string;
|
|
23
|
+
export declare function decimalDiv(left: DecimalCalculationInput, right: DecimalCalculationInput): string;
|
|
24
|
+
export declare function decimalMin(left: DecimalCalculationInput, right: DecimalCalculationInput): string;
|
|
25
|
+
export declare function setDecimal(value: DecimalCalculationInput): any;
|
|
26
|
+
export declare function addDecimal<A extends string>(attr: A, delta: DecimalCalculationInput): any;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toBigNumber = toBigNumber;
|
|
4
|
+
exports.toDecimalString = toDecimalString;
|
|
5
|
+
exports.numberToDecimalString = numberToDecimalString;
|
|
6
|
+
exports.requireDecimalString = requireDecimalString;
|
|
7
|
+
exports.decimalToDisplayNumber = decimalToDisplayNumber;
|
|
8
|
+
exports.decimalToApiNumber = decimalToApiNumber;
|
|
9
|
+
exports.decimalRound = decimalRound;
|
|
10
|
+
exports.decimalIsZero = decimalIsZero;
|
|
11
|
+
exports.decimalEq = decimalEq;
|
|
12
|
+
exports.decimalGt = decimalGt;
|
|
13
|
+
exports.decimalGte = decimalGte;
|
|
14
|
+
exports.decimalLt = decimalLt;
|
|
15
|
+
exports.decimalLte = decimalLte;
|
|
16
|
+
exports.decimalAdd = decimalAdd;
|
|
17
|
+
exports.decimalSub = decimalSub;
|
|
18
|
+
exports.decimalNeg = decimalNeg;
|
|
19
|
+
exports.decimalAbs = decimalAbs;
|
|
20
|
+
exports.decimalMul = decimalMul;
|
|
21
|
+
exports.decimalDiv = decimalDiv;
|
|
22
|
+
exports.decimalMin = decimalMin;
|
|
23
|
+
exports.setDecimal = setDecimal;
|
|
24
|
+
exports.addDecimal = addDecimal;
|
|
25
|
+
const tslib_1 = require("tslib");
|
|
26
|
+
const bignumber_js_1 = tslib_1.__importDefault(require("bignumber.js"));
|
|
27
|
+
const assert_1 = require("./assert");
|
|
28
|
+
function toBigNumber(value) {
|
|
29
|
+
(0, assert_1.assert)(value !== null && value !== undefined, 'decimal value is required');
|
|
30
|
+
const decimal = bignumber_js_1.default.isBigNumber(value) ? value : new bignumber_js_1.default(value);
|
|
31
|
+
(0, assert_1.assert)(decimal.isFinite(), `invalid decimal value: ${value}`);
|
|
32
|
+
return decimal;
|
|
33
|
+
}
|
|
34
|
+
function toDecimalString(value) {
|
|
35
|
+
return toBigNumber(value).toFixed();
|
|
36
|
+
}
|
|
37
|
+
function numberToDecimalString(value) {
|
|
38
|
+
(0, assert_1.assert)(typeof value === 'number' || typeof value === 'string', `invalid decimal input: ${value}`);
|
|
39
|
+
const decimal = new bignumber_js_1.default(value);
|
|
40
|
+
(0, assert_1.assert)(decimal.isFinite(), `invalid decimal input: ${value}`);
|
|
41
|
+
return decimal.toFixed();
|
|
42
|
+
}
|
|
43
|
+
function requireDecimalString(value, label) {
|
|
44
|
+
(0, assert_1.assert)(typeof value === 'string', `${label} must be a decimal string`);
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
function decimalToDisplayNumber(value) {
|
|
48
|
+
return toBigNumber(value).toNumber();
|
|
49
|
+
}
|
|
50
|
+
function decimalToApiNumber(value) {
|
|
51
|
+
return toBigNumber(value).toNumber();
|
|
52
|
+
}
|
|
53
|
+
function decimalRound(value, roundingMode = bignumber_js_1.default.ROUND_HALF_UP) {
|
|
54
|
+
return toBigNumber(value).integerValue(roundingMode).toFixed();
|
|
55
|
+
}
|
|
56
|
+
function decimalIsZero(value) {
|
|
57
|
+
return toBigNumber(value).isZero();
|
|
58
|
+
}
|
|
59
|
+
function decimalEq(left, right) {
|
|
60
|
+
return toBigNumber(left).isEqualTo(toBigNumber(right));
|
|
61
|
+
}
|
|
62
|
+
function decimalGt(left, right) {
|
|
63
|
+
return toBigNumber(left).isGreaterThan(toBigNumber(right));
|
|
64
|
+
}
|
|
65
|
+
function decimalGte(left, right) {
|
|
66
|
+
return toBigNumber(left).isGreaterThanOrEqualTo(toBigNumber(right));
|
|
67
|
+
}
|
|
68
|
+
function decimalLt(left, right) {
|
|
69
|
+
return toBigNumber(left).isLessThan(toBigNumber(right));
|
|
70
|
+
}
|
|
71
|
+
function decimalLte(left, right) {
|
|
72
|
+
return toBigNumber(left).isLessThanOrEqualTo(toBigNumber(right));
|
|
73
|
+
}
|
|
74
|
+
function decimalAdd(left, right) {
|
|
75
|
+
return toBigNumber(left).plus(toBigNumber(right)).toFixed();
|
|
76
|
+
}
|
|
77
|
+
function decimalSub(left, right) {
|
|
78
|
+
return toBigNumber(left).minus(toBigNumber(right)).toFixed();
|
|
79
|
+
}
|
|
80
|
+
function decimalNeg(value) {
|
|
81
|
+
return toBigNumber(value).negated().toFixed();
|
|
82
|
+
}
|
|
83
|
+
function decimalAbs(value) {
|
|
84
|
+
return toBigNumber(value).absoluteValue().toFixed();
|
|
85
|
+
}
|
|
86
|
+
function decimalMul(left, right) {
|
|
87
|
+
return toBigNumber(left).multipliedBy(toBigNumber(right)).toFixed();
|
|
88
|
+
}
|
|
89
|
+
function decimalDiv(left, right) {
|
|
90
|
+
return toBigNumber(left).dividedBy(toBigNumber(right)).toFixed();
|
|
91
|
+
}
|
|
92
|
+
function decimalMin(left, right) {
|
|
93
|
+
const leftDecimal = toBigNumber(left);
|
|
94
|
+
const rightDecimal = toBigNumber(right);
|
|
95
|
+
return bignumber_js_1.default.minimum(leftDecimal, rightDecimal).toFixed();
|
|
96
|
+
}
|
|
97
|
+
function decimalAddExpr(left, right) {
|
|
98
|
+
return {
|
|
99
|
+
$expr: {
|
|
100
|
+
$add: [
|
|
101
|
+
left,
|
|
102
|
+
toBigNumber(right).toFixed(),
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function setDecimal(value) {
|
|
108
|
+
return decimalAddExpr(0, value);
|
|
109
|
+
}
|
|
110
|
+
function addDecimal(attr, delta) {
|
|
111
|
+
return decimalAddExpr({ '#attr': attr }, delta);
|
|
112
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './shared';
|