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
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import PathLib from 'path';
|
|
2
|
+
import { existsSync, realpathSync, readFileSync } from 'fs';
|
|
3
|
+
import * as ts from 'typescript';
|
|
4
|
+
import { assert } from '../utils/assert';
|
|
5
|
+
const ParsedDeclarationSourceFileCache = {};
|
|
6
|
+
const PUBLISHED_DECLARATION_DIRS = [
|
|
7
|
+
'es',
|
|
8
|
+
// TODO: lib output is a legacy compatibility fallback. Remove it after Oak packages stop publishing lib.
|
|
9
|
+
'lib',
|
|
10
|
+
'src',
|
|
11
|
+
];
|
|
12
|
+
function normalizePathKey(pathName) {
|
|
13
|
+
const resolvedPath = existsSync(pathName) ? realpathSync(pathName) : pathName;
|
|
14
|
+
const normalizedPath = PathLib.normalize(resolvedPath);
|
|
15
|
+
return process.platform === 'win32' ? normalizedPath.toLowerCase() : normalizedPath;
|
|
16
|
+
}
|
|
17
|
+
function findNearestPackageJson(startPath) {
|
|
18
|
+
let current = existsSync(startPath) ? realpathSync(startPath) : PathLib.resolve(process.cwd(), startPath);
|
|
19
|
+
if (!ts.sys.directoryExists(current)) {
|
|
20
|
+
current = PathLib.dirname(current);
|
|
21
|
+
}
|
|
22
|
+
while (true) {
|
|
23
|
+
const candidate = PathLib.join(current, 'package.json');
|
|
24
|
+
if (existsSync(candidate)) {
|
|
25
|
+
return candidate;
|
|
26
|
+
}
|
|
27
|
+
const parent = PathLib.dirname(current);
|
|
28
|
+
if (parent === current) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
current = parent;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function readDeclarationSourceFile(pathName) {
|
|
35
|
+
const resolvedPath = existsSync(pathName) ? realpathSync(pathName) : pathName;
|
|
36
|
+
const cacheKey = normalizePathKey(resolvedPath);
|
|
37
|
+
if (!ParsedDeclarationSourceFileCache[cacheKey]) {
|
|
38
|
+
ParsedDeclarationSourceFileCache[cacheKey] = ts.createSourceFile(resolvedPath, readFileSync(resolvedPath, 'utf8'), ts.ScriptTarget.Latest, true, resolvedPath.endsWith('.tsx') ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
39
|
+
}
|
|
40
|
+
return ParsedDeclarationSourceFileCache[cacheKey];
|
|
41
|
+
}
|
|
42
|
+
function isPathInside(parent, child) {
|
|
43
|
+
const relativePath = PathLib.relative(parent, child);
|
|
44
|
+
return !!relativePath && !relativePath.startsWith('..') && !PathLib.isAbsolute(relativePath);
|
|
45
|
+
}
|
|
46
|
+
function getDeclarationFileCandidates(basePath) {
|
|
47
|
+
return [
|
|
48
|
+
`${basePath}.d.ts`,
|
|
49
|
+
PathLib.join(basePath, 'index.d.ts'),
|
|
50
|
+
`${basePath}.ts`,
|
|
51
|
+
PathLib.join(basePath, 'index.ts'),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
function resolvePublishedDeclarationImport(sourceFilePath, importPath) {
|
|
55
|
+
if (!importPath.startsWith('.')) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const directTarget = PathLib.resolve(PathLib.dirname(sourceFilePath), importPath);
|
|
59
|
+
const packageJsonPath = findNearestPackageJson(sourceFilePath);
|
|
60
|
+
if (packageJsonPath) {
|
|
61
|
+
const packageRoot = PathLib.dirname(packageJsonPath);
|
|
62
|
+
const sourceRoot = PathLib.join(packageRoot, 'src');
|
|
63
|
+
const sourceFile = existsSync(sourceFilePath) ? realpathSync(sourceFilePath) : PathLib.resolve(sourceFilePath);
|
|
64
|
+
if (!isPathInside(sourceRoot, sourceFile) && isPathInside(sourceRoot, directTarget)) {
|
|
65
|
+
const relativeToSourceRoot = PathLib.relative(sourceRoot, directTarget);
|
|
66
|
+
const candidates = PUBLISHED_DECLARATION_DIRS.flatMap((dir) => (getDeclarationFileCandidates(PathLib.join(packageRoot, dir, relativeToSourceRoot))));
|
|
67
|
+
const matched = candidates.find((candidate) => existsSync(candidate));
|
|
68
|
+
if (matched) {
|
|
69
|
+
return realpathSync(matched);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const directMatched = getDeclarationFileCandidates(directTarget).find((candidate) => existsSync(candidate));
|
|
74
|
+
return directMatched ? realpathSync(directMatched) : undefined;
|
|
75
|
+
}
|
|
76
|
+
function getPropertyNameText(name) {
|
|
77
|
+
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {
|
|
78
|
+
return name.text;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getTypeLiteralPropertyKeys(node) {
|
|
82
|
+
return node.members.map((member) => ts.isPropertySignature(member) ? getPropertyNameText(member.name) : undefined).filter((value) => !!value);
|
|
83
|
+
}
|
|
84
|
+
function unwrapObjectLiteralExpression(expression) {
|
|
85
|
+
if (ts.isObjectLiteralExpression(expression)) {
|
|
86
|
+
return expression;
|
|
87
|
+
}
|
|
88
|
+
if (ts.isAsExpression(expression) || ts.isParenthesizedExpression(expression)) {
|
|
89
|
+
return unwrapObjectLiteralExpression(expression.expression);
|
|
90
|
+
}
|
|
91
|
+
if (ts.isSatisfiesExpression(expression)) {
|
|
92
|
+
return unwrapObjectLiteralExpression(expression.expression);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function unwrapArrayLiteralExpression(expression) {
|
|
96
|
+
if (ts.isArrayLiteralExpression(expression)) {
|
|
97
|
+
return expression;
|
|
98
|
+
}
|
|
99
|
+
if (ts.isAsExpression(expression) || ts.isParenthesizedExpression(expression)) {
|
|
100
|
+
return unwrapArrayLiteralExpression(expression.expression);
|
|
101
|
+
}
|
|
102
|
+
if (ts.isSatisfiesExpression(expression)) {
|
|
103
|
+
return unwrapArrayLiteralExpression(expression.expression);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function getObjectLiteralPropertyKeys(node) {
|
|
107
|
+
return node.properties.map((property) => ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)
|
|
108
|
+
? getPropertyNameText(property.name)
|
|
109
|
+
: undefined).filter((value) => !!value);
|
|
110
|
+
}
|
|
111
|
+
function getStringLiteralValuesFromArrayLiteralExpression(node) {
|
|
112
|
+
return node.elements.map((element) => ts.isStringLiteral(element) ? element.text : undefined).filter((value) => !!value);
|
|
113
|
+
}
|
|
114
|
+
function getStringLiteralValuesFromObjectLiteralPropertyValues(node) {
|
|
115
|
+
return node.properties.map((property) => ts.isPropertyAssignment(property) && ts.isStringLiteral(property.initializer)
|
|
116
|
+
? property.initializer.text
|
|
117
|
+
: undefined).filter((value) => !!value);
|
|
118
|
+
}
|
|
119
|
+
function findTypeAliasDeclaration(sourceFile, name) {
|
|
120
|
+
return sourceFile.statements.find((statement) => ts.isTypeAliasDeclaration(statement) && statement.name.text === name);
|
|
121
|
+
}
|
|
122
|
+
function findEnumDeclaration(sourceFile, name) {
|
|
123
|
+
return sourceFile.statements.find((statement) => ts.isEnumDeclaration(statement) && statement.name.text === name);
|
|
124
|
+
}
|
|
125
|
+
function findInterfaceDeclaration(sourceFile, name) {
|
|
126
|
+
return sourceFile.statements.find((statement) => ts.isInterfaceDeclaration(statement) && statement.name.text === name);
|
|
127
|
+
}
|
|
128
|
+
function findVariableDeclaration(sourceFile, name) {
|
|
129
|
+
for (const statement of sourceFile.statements) {
|
|
130
|
+
if (!ts.isVariableStatement(statement)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const declaration = statement.declarationList.declarations.find((item) => ts.isIdentifier(item.name) && item.name.text === name);
|
|
134
|
+
if (declaration) {
|
|
135
|
+
return declaration;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function hasTypeAliasDeclaration(sourceFile, name) {
|
|
140
|
+
return !!findTypeAliasDeclaration(sourceFile, name);
|
|
141
|
+
}
|
|
142
|
+
export function hasTypeAliasOrEnumDeclaration(sourceFile, name) {
|
|
143
|
+
return !!findTypeAliasDeclaration(sourceFile, name) || !!findEnumDeclaration(sourceFile, name);
|
|
144
|
+
}
|
|
145
|
+
function getStringLiteralValueFromTypeNode(typeNode) {
|
|
146
|
+
if (ts.isLiteralTypeNode(typeNode) && ts.isStringLiteral(typeNode.literal)) {
|
|
147
|
+
return typeNode.literal.text;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function isNumberIndexTypeNode(typeNode) {
|
|
151
|
+
return typeNode.kind === ts.SyntaxKind.NumberKeyword;
|
|
152
|
+
}
|
|
153
|
+
function getDeclarationCacheKey(sourceFile, name) {
|
|
154
|
+
return `${normalizePathKey(sourceFile.fileName)}#${name}`;
|
|
155
|
+
}
|
|
156
|
+
function tryGetStringLiteralValuesFromType(type) {
|
|
157
|
+
if (type.isStringLiteral()) {
|
|
158
|
+
return [type.value];
|
|
159
|
+
}
|
|
160
|
+
if (type.isUnion()) {
|
|
161
|
+
return type.types.map((item) => item.isStringLiteral() ? item.value : undefined).filter((item) => !!item);
|
|
162
|
+
}
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
function tryGetStringLiteralValuesFromEnumDeclaration(declaration) {
|
|
166
|
+
const values = declaration.members.map((member) => member.initializer && ts.isStringLiteral(member.initializer) ? member.initializer.text : undefined).filter((value) => !!value);
|
|
167
|
+
return values.length === declaration.members.length ? values : [];
|
|
168
|
+
}
|
|
169
|
+
function unwrapReadonlyTypeNode(typeNode) {
|
|
170
|
+
if (ts.isTypeOperatorNode(typeNode) && typeNode.operator === ts.SyntaxKind.ReadonlyKeyword) {
|
|
171
|
+
return typeNode.type;
|
|
172
|
+
}
|
|
173
|
+
return typeNode;
|
|
174
|
+
}
|
|
175
|
+
function tryGetStringLiteralValuesFromTupleElementTypeNode(typeNode, checker, visitedSymbols, visitedTypeAliases) {
|
|
176
|
+
if (ts.isNamedTupleMember(typeNode)) {
|
|
177
|
+
return tryGetStringLiteralValuesFromTypeNode(typeNode.type, checker, visitedSymbols, visitedTypeAliases);
|
|
178
|
+
}
|
|
179
|
+
if (ts.isOptionalTypeNode(typeNode) || ts.isRestTypeNode(typeNode)) {
|
|
180
|
+
return tryGetStringLiteralValuesFromTypeNode(typeNode.type, checker, visitedSymbols, visitedTypeAliases);
|
|
181
|
+
}
|
|
182
|
+
return tryGetStringLiteralValuesFromTypeNode(typeNode, checker, visitedSymbols, visitedTypeAliases);
|
|
183
|
+
}
|
|
184
|
+
function tryGetStringLiteralValuesFromArrayLikeTypeNode(typeNode, checker, visitedSymbols, visitedTypeAliases) {
|
|
185
|
+
const unwrappedTypeNode = unwrapReadonlyTypeNode(typeNode);
|
|
186
|
+
if (ts.isTupleTypeNode(unwrappedTypeNode)) {
|
|
187
|
+
const values = unwrappedTypeNode.elements.flatMap((element) => tryGetStringLiteralValuesFromTupleElementTypeNode(element, checker, visitedSymbols, visitedTypeAliases));
|
|
188
|
+
return values.length === unwrappedTypeNode.elements.length ? values : [];
|
|
189
|
+
}
|
|
190
|
+
if (ts.isArrayTypeNode(unwrappedTypeNode)) {
|
|
191
|
+
return tryGetStringLiteralValuesFromTypeNode(unwrappedTypeNode.elementType, checker, visitedSymbols, visitedTypeAliases);
|
|
192
|
+
}
|
|
193
|
+
if (ts.isTypeReferenceNode(unwrappedTypeNode)
|
|
194
|
+
&& ts.isIdentifier(unwrappedTypeNode.typeName)
|
|
195
|
+
&& ['Array', 'ReadonlyArray'].includes(unwrappedTypeNode.typeName.text)
|
|
196
|
+
&& unwrappedTypeNode.typeArguments?.length === 1) {
|
|
197
|
+
return tryGetStringLiteralValuesFromTypeNode(unwrappedTypeNode.typeArguments[0], checker, visitedSymbols, visitedTypeAliases);
|
|
198
|
+
}
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
function tryGetStringLiteralValuesFromKeyofTypeNode(typeNode) {
|
|
202
|
+
if (typeNode.operator !== ts.SyntaxKind.KeyOfKeyword || !ts.isTypeQueryNode(typeNode.type)) {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
const exprName = typeNode.type.exprName;
|
|
206
|
+
if (!ts.isIdentifier(exprName)) {
|
|
207
|
+
return [];
|
|
208
|
+
}
|
|
209
|
+
const declaration = findVariableDeclaration(typeNode.getSourceFile(), exprName.text);
|
|
210
|
+
if (!declaration) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
if (declaration.type && ts.isTypeLiteralNode(declaration.type)) {
|
|
214
|
+
return getTypeLiteralPropertyKeys(declaration.type);
|
|
215
|
+
}
|
|
216
|
+
if (declaration.initializer) {
|
|
217
|
+
const objectLiteral = unwrapObjectLiteralExpression(declaration.initializer);
|
|
218
|
+
if (objectLiteral) {
|
|
219
|
+
return getObjectLiteralPropertyKeys(objectLiteral);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
function tryGetStringLiteralValuesFromTypeQueryIndexedAccessNode(typeNode, checker, visitedSymbols, visitedTypeAliases) {
|
|
225
|
+
if (!ts.isTypeQueryNode(typeNode.objectType) || !ts.isIdentifier(typeNode.objectType.exprName)) {
|
|
226
|
+
return [];
|
|
227
|
+
}
|
|
228
|
+
const declaration = findVariableDeclaration(typeNode.getSourceFile(), typeNode.objectType.exprName.text);
|
|
229
|
+
if (!declaration) {
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
if (isNumberIndexTypeNode(typeNode.indexType)) {
|
|
233
|
+
if (declaration.type) {
|
|
234
|
+
const values = tryGetStringLiteralValuesFromArrayLikeTypeNode(declaration.type, checker, visitedSymbols, visitedTypeAliases);
|
|
235
|
+
if (values.length > 0) {
|
|
236
|
+
return values;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (declaration.initializer) {
|
|
240
|
+
const arrayLiteral = unwrapArrayLiteralExpression(declaration.initializer);
|
|
241
|
+
if (arrayLiteral) {
|
|
242
|
+
return getStringLiteralValuesFromArrayLiteralExpression(arrayLiteral);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (ts.isTypeOperatorNode(typeNode.indexType)) {
|
|
247
|
+
const indexValues = tryGetStringLiteralValuesFromKeyofTypeNode(typeNode.indexType);
|
|
248
|
+
if (indexValues.length > 0) {
|
|
249
|
+
if (declaration.type && ts.isTypeLiteralNode(declaration.type)) {
|
|
250
|
+
return declaration.type.members.flatMap((member) => ts.isPropertySignature(member) && member.type
|
|
251
|
+
? tryGetStringLiteralValuesFromTypeNode(member.type, checker, visitedSymbols, visitedTypeAliases)
|
|
252
|
+
: []);
|
|
253
|
+
}
|
|
254
|
+
if (declaration.initializer) {
|
|
255
|
+
const objectLiteral = unwrapObjectLiteralExpression(declaration.initializer);
|
|
256
|
+
if (objectLiteral) {
|
|
257
|
+
return getStringLiteralValuesFromObjectLiteralPropertyValues(objectLiteral);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return [];
|
|
263
|
+
}
|
|
264
|
+
function tryGetStringLiteralValuesFromIndexedAccessTypeNode(typeNode, checker, visitedSymbols, visitedTypeAliases) {
|
|
265
|
+
const checkerValues = tryGetStringLiteralValuesFromType(checker.getTypeFromTypeNode(typeNode));
|
|
266
|
+
if (checkerValues.length > 0) {
|
|
267
|
+
return checkerValues;
|
|
268
|
+
}
|
|
269
|
+
const typeQueryValues = tryGetStringLiteralValuesFromTypeQueryIndexedAccessNode(typeNode, checker, visitedSymbols, visitedTypeAliases);
|
|
270
|
+
if (typeQueryValues.length > 0) {
|
|
271
|
+
return typeQueryValues;
|
|
272
|
+
}
|
|
273
|
+
const propertyName = getStringLiteralValueFromTypeNode(typeNode.indexType);
|
|
274
|
+
if (!propertyName) {
|
|
275
|
+
return [];
|
|
276
|
+
}
|
|
277
|
+
if (ts.isTypeReferenceNode(typeNode.objectType) && ts.isIdentifier(typeNode.objectType.typeName)) {
|
|
278
|
+
const sourceFile = typeNode.getSourceFile();
|
|
279
|
+
const objectTypeName = typeNode.objectType.typeName.text;
|
|
280
|
+
const interfaceDeclaration = findInterfaceDeclaration(sourceFile, objectTypeName);
|
|
281
|
+
const member = interfaceDeclaration?.members.find((item) => ts.isPropertySignature(item) && getPropertyNameText(item.name) === propertyName);
|
|
282
|
+
if (member?.type) {
|
|
283
|
+
return tryGetStringLiteralValuesFromTypeNode(member.type, checker, visitedSymbols, visitedTypeAliases);
|
|
284
|
+
}
|
|
285
|
+
const typeAliasDeclaration = findTypeAliasDeclaration(sourceFile, objectTypeName);
|
|
286
|
+
if (typeAliasDeclaration && ts.isTypeLiteralNode(typeAliasDeclaration.type)) {
|
|
287
|
+
const typeMember = typeAliasDeclaration.type.members.find((item) => ts.isPropertySignature(item) && getPropertyNameText(item.name) === propertyName);
|
|
288
|
+
if (typeMember?.type) {
|
|
289
|
+
return tryGetStringLiteralValuesFromTypeNode(typeMember.type, checker, visitedSymbols, visitedTypeAliases);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
function findImportedStringEnumDeclaration(typeNode, visitedTypeAliases) {
|
|
296
|
+
if (!ts.isIdentifier(typeNode.typeName)) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const localName = typeNode.typeName.text;
|
|
300
|
+
const sourceFile = typeNode.getSourceFile();
|
|
301
|
+
for (const statement of sourceFile.statements) {
|
|
302
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const namedBindings = statement.importClause?.namedBindings;
|
|
306
|
+
if (!namedBindings || !ts.isNamedImports(namedBindings)) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
const importSpecifier = namedBindings.elements.find((element) => element.name.text === localName);
|
|
310
|
+
if (!importSpecifier) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const declarationPath = resolvePublishedDeclarationImport(sourceFile.fileName, statement.moduleSpecifier.text);
|
|
314
|
+
if (!declarationPath) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const importedName = importSpecifier.propertyName?.text || importSpecifier.name.text;
|
|
318
|
+
const cacheKey = `${normalizePathKey(declarationPath)}#${importedName}`;
|
|
319
|
+
if (visitedTypeAliases.has(cacheKey)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
visitedTypeAliases.add(cacheKey);
|
|
323
|
+
const declarationSourceFile = readDeclarationSourceFile(declarationPath);
|
|
324
|
+
return findTypeAliasDeclaration(declarationSourceFile, importedName)
|
|
325
|
+
|| findEnumDeclaration(declarationSourceFile, importedName);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function tryGetStringLiteralValuesFromLocalDeclaration(typeNode, checker, visitedSymbols, visitedTypeAliases) {
|
|
329
|
+
if (!ts.isIdentifier(typeNode.typeName)) {
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
const typeName = typeNode.typeName.text;
|
|
333
|
+
const sourceFile = typeNode.getSourceFile();
|
|
334
|
+
const enumDeclaration = findEnumDeclaration(sourceFile, typeName);
|
|
335
|
+
if (enumDeclaration) {
|
|
336
|
+
return tryGetStringLiteralValuesFromEnumDeclaration(enumDeclaration);
|
|
337
|
+
}
|
|
338
|
+
const typeAliasDeclaration = findTypeAliasDeclaration(sourceFile, typeName);
|
|
339
|
+
if (!typeAliasDeclaration) {
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
const cacheKey = getDeclarationCacheKey(sourceFile, typeName);
|
|
343
|
+
if (visitedTypeAliases.has(cacheKey)) {
|
|
344
|
+
return [];
|
|
345
|
+
}
|
|
346
|
+
visitedTypeAliases.add(cacheKey);
|
|
347
|
+
return tryGetStringLiteralValuesFromTypeNode(typeAliasDeclaration.type, checker, visitedSymbols, visitedTypeAliases);
|
|
348
|
+
}
|
|
349
|
+
function tryGetStringLiteralValuesFromSymbol(symbol, checker, visitedSymbols = new Set(), visitedTypeAliases = new Set()) {
|
|
350
|
+
if (!symbol || visitedSymbols.has(symbol)) {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
visitedSymbols.add(symbol);
|
|
354
|
+
const declaredTypeValues = tryGetStringLiteralValuesFromType(checker.getDeclaredTypeOfSymbol(symbol));
|
|
355
|
+
if (declaredTypeValues.length > 0) {
|
|
356
|
+
return declaredTypeValues;
|
|
357
|
+
}
|
|
358
|
+
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
359
|
+
const aliasedSymbol = checker.getAliasedSymbol(symbol);
|
|
360
|
+
const aliasedValues = tryGetStringLiteralValuesFromSymbol(aliasedSymbol, checker, visitedSymbols, visitedTypeAliases);
|
|
361
|
+
if (aliasedValues.length > 0) {
|
|
362
|
+
return aliasedValues;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
for (const declaration of symbol.getDeclarations() ?? []) {
|
|
366
|
+
if (ts.isTypeAliasDeclaration(declaration)) {
|
|
367
|
+
const values = tryGetStringLiteralValuesFromTypeNode(declaration.type, checker, visitedSymbols, visitedTypeAliases);
|
|
368
|
+
if (values.length > 0) {
|
|
369
|
+
return values;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
export function tryGetStringLiteralValuesFromTypeNode(typeNode, checker, visitedSymbols = new Set(), visitedTypeAliases = new Set()) {
|
|
376
|
+
const literalValue = getStringLiteralValueFromTypeNode(typeNode);
|
|
377
|
+
if (literalValue) {
|
|
378
|
+
return [literalValue];
|
|
379
|
+
}
|
|
380
|
+
if (ts.isUnionTypeNode(typeNode)) {
|
|
381
|
+
const values = typeNode.types.map((item) => getStringLiteralValueFromTypeNode(item)).filter((item) => !!item);
|
|
382
|
+
if (values.length > 0) {
|
|
383
|
+
return values;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (ts.isTypeOperatorNode(typeNode)) {
|
|
387
|
+
const values = tryGetStringLiteralValuesFromKeyofTypeNode(typeNode);
|
|
388
|
+
if (values.length > 0) {
|
|
389
|
+
return values;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (ts.isIndexedAccessTypeNode(typeNode)) {
|
|
393
|
+
const values = tryGetStringLiteralValuesFromIndexedAccessTypeNode(typeNode, checker, visitedSymbols, visitedTypeAliases);
|
|
394
|
+
if (values.length > 0) {
|
|
395
|
+
return values;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (ts.isTypeReferenceNode(typeNode)) {
|
|
399
|
+
const localValues = tryGetStringLiteralValuesFromLocalDeclaration(typeNode, checker, visitedSymbols, visitedTypeAliases);
|
|
400
|
+
if (localValues.length > 0) {
|
|
401
|
+
return localValues;
|
|
402
|
+
}
|
|
403
|
+
const importedDeclaration = findImportedStringEnumDeclaration(typeNode, visitedTypeAliases);
|
|
404
|
+
if (importedDeclaration && ts.isTypeAliasDeclaration(importedDeclaration)) {
|
|
405
|
+
return tryGetStringLiteralValuesFromTypeNode(importedDeclaration.type, checker, visitedSymbols, visitedTypeAliases);
|
|
406
|
+
}
|
|
407
|
+
if (importedDeclaration && ts.isEnumDeclaration(importedDeclaration)) {
|
|
408
|
+
return tryGetStringLiteralValuesFromEnumDeclaration(importedDeclaration);
|
|
409
|
+
}
|
|
410
|
+
const symbolValues = tryGetStringLiteralValuesFromSymbol(checker.getSymbolAtLocation(typeNode.typeName), checker, visitedSymbols, visitedTypeAliases);
|
|
411
|
+
if (symbolValues.length > 0) {
|
|
412
|
+
return symbolValues;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const values = tryGetStringLiteralValuesFromType(checker.getTypeFromTypeNode(typeNode));
|
|
416
|
+
if (values.length > 0) {
|
|
417
|
+
return values;
|
|
418
|
+
}
|
|
419
|
+
return [];
|
|
420
|
+
}
|
|
421
|
+
export function collectEntityDescEnumAttrs(declaration, filename, checker) {
|
|
422
|
+
const enumAttrs = {};
|
|
423
|
+
if (!declaration.type || !ts.isTypeReferenceNode(declaration.type) || !ts.isIdentifier(declaration.type.typeName)) {
|
|
424
|
+
return enumAttrs;
|
|
425
|
+
}
|
|
426
|
+
if (declaration.type.typeName.text !== 'EntityDesc') {
|
|
427
|
+
return enumAttrs;
|
|
428
|
+
}
|
|
429
|
+
const { typeArguments } = declaration.type;
|
|
430
|
+
if (!typeArguments || typeArguments.length < 4 || !ts.isTypeLiteralNode(typeArguments[3])) {
|
|
431
|
+
return enumAttrs;
|
|
432
|
+
}
|
|
433
|
+
typeArguments[3].members.forEach((member) => {
|
|
434
|
+
if (!ts.isPropertySignature(member) || !member.type) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
assert(ts.isIdentifier(member.name), `${filename}中的EntityDesc第四个泛型参数成员必须是identifier`);
|
|
438
|
+
const values = tryGetStringLiteralValuesFromTypeNode(member.type, checker);
|
|
439
|
+
assert(values.length > 0, `${filename}中的EntityDesc第四个泛型参数「${member.name.text}」必须对应字符串枚举类型`);
|
|
440
|
+
enumAttrs[member.name.text] = values;
|
|
441
|
+
});
|
|
442
|
+
return enumAttrs;
|
|
443
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
export type EntitySourceFile = {
|
|
3
|
+
filename: string;
|
|
4
|
+
typeFilePath: string;
|
|
5
|
+
runtimeFilePath?: string;
|
|
6
|
+
isDeclaration: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type RuntimeImportReference = {
|
|
9
|
+
name: string;
|
|
10
|
+
propertyName?: string;
|
|
11
|
+
moduleSpecifier: string;
|
|
12
|
+
sourceFilePath: string;
|
|
13
|
+
};
|
|
14
|
+
export type RuntimeInitializer = {
|
|
15
|
+
expression: ts.Expression;
|
|
16
|
+
importReference?: RuntimeImportReference;
|
|
17
|
+
metadata?: RuntimeActionDefMetadata;
|
|
18
|
+
};
|
|
19
|
+
export type RuntimeActionDefMetadata = {
|
|
20
|
+
actions: string[];
|
|
21
|
+
states: string[];
|
|
22
|
+
hasIs: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function listEntitySourceFiles(absoluteInputDir: string): EntitySourceFile[];
|
|
25
|
+
export declare function getRuntimeInitializer(typeFilePath: string, name: string): RuntimeInitializer | undefined;
|
|
26
|
+
export declare function getRuntimeActionDefInitializers(typeFilePath: string): Record<string, RuntimeInitializer>;
|
|
27
|
+
export declare function getEntityNameFromSourceFile(source: EntitySourceFile): string;
|
|
28
|
+
export declare function getRuntimeActionDefMetadata(initializer: RuntimeInitializer, visited?: Set<string>): RuntimeActionDefMetadata | undefined;
|