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,521 @@
|
|
|
1
|
+
import PathLib from 'path';
|
|
2
|
+
import { existsSync, realpathSync, readdirSync, readFileSync } from 'fs';
|
|
3
|
+
import * as ts from 'typescript';
|
|
4
|
+
const { factory } = ts;
|
|
5
|
+
const RuntimeSourceFileCache = {};
|
|
6
|
+
function normalizeCachePath(pathName) {
|
|
7
|
+
const resolvedPath = existsSync(pathName) ? realpathSync(pathName) : pathName;
|
|
8
|
+
return process.platform === 'win32' ? resolvedPath.toLowerCase() : resolvedPath;
|
|
9
|
+
}
|
|
10
|
+
function entityNameFromFilename(filename) {
|
|
11
|
+
return filename.replace(/\.d\.ts$/i, '').replace(/\.[^.]+$/i, '');
|
|
12
|
+
}
|
|
13
|
+
function isDeclarationEntityFile(filename) {
|
|
14
|
+
return filename.endsWith('.d.ts');
|
|
15
|
+
}
|
|
16
|
+
function isSourceEntityFile(filename) {
|
|
17
|
+
return /\.(ts|tsx)$/i.test(filename) && !filename.endsWith('.d.ts');
|
|
18
|
+
}
|
|
19
|
+
function getRuntimeFilePath(typeFilePath) {
|
|
20
|
+
if (!typeFilePath.endsWith('.d.ts')) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const runtimeFilePath = typeFilePath.replace(/\.d\.ts$/i, '.js');
|
|
24
|
+
return existsSync(runtimeFilePath) ? realpathSync(runtimeFilePath) : undefined;
|
|
25
|
+
}
|
|
26
|
+
export function listEntitySourceFiles(absoluteInputDir) {
|
|
27
|
+
const files = readdirSync(absoluteInputDir).sort();
|
|
28
|
+
const declarationFiles = files.filter(isDeclarationEntityFile);
|
|
29
|
+
if (declarationFiles.length > 0) {
|
|
30
|
+
return declarationFiles.map((filename) => {
|
|
31
|
+
const typeFilePath = realpathSync(PathLib.join(absoluteInputDir, filename));
|
|
32
|
+
return {
|
|
33
|
+
filename,
|
|
34
|
+
typeFilePath,
|
|
35
|
+
runtimeFilePath: getRuntimeFilePath(typeFilePath),
|
|
36
|
+
isDeclaration: true,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return files.filter(isSourceEntityFile).map((filename) => {
|
|
41
|
+
const typeFilePath = realpathSync(PathLib.join(absoluteInputDir, filename));
|
|
42
|
+
return {
|
|
43
|
+
filename,
|
|
44
|
+
typeFilePath,
|
|
45
|
+
isDeclaration: false,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function readRuntimeSourceFile(runtimeFilePath) {
|
|
50
|
+
const cacheKey = normalizeCachePath(runtimeFilePath);
|
|
51
|
+
if (!RuntimeSourceFileCache[cacheKey]) {
|
|
52
|
+
RuntimeSourceFileCache[cacheKey] = ts.createSourceFile(runtimeFilePath, readFileSync(runtimeFilePath, 'utf8'), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
53
|
+
}
|
|
54
|
+
return RuntimeSourceFileCache[cacheKey];
|
|
55
|
+
}
|
|
56
|
+
function getRuntimeSourceFileForTypeFile(typeFilePath) {
|
|
57
|
+
const runtimeFilePath = getRuntimeFilePath(typeFilePath);
|
|
58
|
+
return runtimeFilePath ? readRuntimeSourceFile(runtimeFilePath) : undefined;
|
|
59
|
+
}
|
|
60
|
+
function isExportsObject(expression) {
|
|
61
|
+
return ts.isIdentifier(expression) && expression.text === 'exports';
|
|
62
|
+
}
|
|
63
|
+
function isModuleExportsObject(expression) {
|
|
64
|
+
return ts.isPropertyAccessExpression(expression)
|
|
65
|
+
&& ts.isIdentifier(expression.expression)
|
|
66
|
+
&& expression.expression.text === 'module'
|
|
67
|
+
&& expression.name.text === 'exports';
|
|
68
|
+
}
|
|
69
|
+
function getCommonJsExportName(expression) {
|
|
70
|
+
if (ts.isPropertyAccessExpression(expression)
|
|
71
|
+
&& (isExportsObject(expression.expression) || isModuleExportsObject(expression.expression))) {
|
|
72
|
+
return expression.name.text;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function isVoidExpression(expression) {
|
|
76
|
+
return ts.isVoidExpression(expression);
|
|
77
|
+
}
|
|
78
|
+
function findVariableInitializer(sourceFile, name) {
|
|
79
|
+
for (const statement of sourceFile.statements) {
|
|
80
|
+
if (!ts.isVariableStatement(statement)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const declaration = statement.declarationList.declarations.find((item) => ts.isIdentifier(item.name) && item.name.text === name);
|
|
84
|
+
if (declaration?.initializer) {
|
|
85
|
+
return declaration.initializer;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function findExportedInitializer(sourceFile, name) {
|
|
90
|
+
let initializer;
|
|
91
|
+
for (const statement of sourceFile.statements) {
|
|
92
|
+
if (ts.isVariableStatement(statement)) {
|
|
93
|
+
const hasExport = statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
94
|
+
if (hasExport) {
|
|
95
|
+
const declaration = statement.declarationList.declarations.find((item) => ts.isIdentifier(item.name) && item.name.text === name);
|
|
96
|
+
if (declaration?.initializer) {
|
|
97
|
+
initializer = declaration.initializer;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!ts.isExpressionStatement(statement)) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const expression = statement.expression;
|
|
105
|
+
if (!ts.isBinaryExpression(expression) || expression.operatorToken.kind !== ts.SyntaxKind.EqualsToken) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const exportName = getCommonJsExportName(expression.left);
|
|
109
|
+
if (exportName !== name || isVoidExpression(expression.right)) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
initializer = ts.isIdentifier(expression.right)
|
|
113
|
+
? findVariableInitializer(sourceFile, expression.right.text) || expression.right
|
|
114
|
+
: expression.right;
|
|
115
|
+
}
|
|
116
|
+
return initializer || findVariableInitializer(sourceFile, name);
|
|
117
|
+
}
|
|
118
|
+
function getRequireModuleSpecifier(sourceFile, localName) {
|
|
119
|
+
for (const statement of sourceFile.statements) {
|
|
120
|
+
if (!ts.isVariableStatement(statement)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
124
|
+
if (!ts.isIdentifier(declaration.name) || declaration.name.text !== localName) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const initializer = declaration.initializer;
|
|
128
|
+
if (initializer
|
|
129
|
+
&& ts.isCallExpression(initializer)
|
|
130
|
+
&& ts.isIdentifier(initializer.expression)
|
|
131
|
+
&& initializer.expression.text === 'require'
|
|
132
|
+
&& initializer.arguments.length === 1
|
|
133
|
+
&& ts.isStringLiteral(initializer.arguments[0])) {
|
|
134
|
+
return initializer.arguments[0].text;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function getEsImportReference(sourceFile, localName) {
|
|
140
|
+
for (const statement of sourceFile.statements) {
|
|
141
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const namedBindings = statement.importClause?.namedBindings;
|
|
145
|
+
if (!namedBindings || !ts.isNamedImports(namedBindings)) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const specifier = namedBindings.elements.find((element) => element.name.text === localName);
|
|
149
|
+
if (specifier) {
|
|
150
|
+
return {
|
|
151
|
+
name: localName,
|
|
152
|
+
propertyName: specifier.propertyName?.text,
|
|
153
|
+
moduleSpecifier: statement.moduleSpecifier.text,
|
|
154
|
+
sourceFilePath: sourceFile.fileName,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function unwrapCommaExpression(expression) {
|
|
160
|
+
if (ts.isParenthesizedExpression(expression)
|
|
161
|
+
&& ts.isBinaryExpression(expression.expression)
|
|
162
|
+
&& expression.expression.operatorToken.kind === ts.SyntaxKind.CommaToken) {
|
|
163
|
+
return expression.expression.right;
|
|
164
|
+
}
|
|
165
|
+
return expression;
|
|
166
|
+
}
|
|
167
|
+
function getRuntimeCallImportReference(sourceFile, expression) {
|
|
168
|
+
if (!ts.isCallExpression(expression)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const callTarget = unwrapCommaExpression(expression.expression);
|
|
172
|
+
if (ts.isIdentifier(callTarget)) {
|
|
173
|
+
return {
|
|
174
|
+
expression,
|
|
175
|
+
importReference: getEsImportReference(sourceFile, callTarget.text),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (ts.isPropertyAccessExpression(callTarget) && ts.isIdentifier(callTarget.expression)) {
|
|
179
|
+
const moduleSpecifier = getRequireModuleSpecifier(sourceFile, callTarget.expression.text);
|
|
180
|
+
if (!moduleSpecifier) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const name = callTarget.name.text;
|
|
184
|
+
return {
|
|
185
|
+
expression: factory.createCallExpression(factory.createIdentifier(name), expression.typeArguments, expression.arguments),
|
|
186
|
+
importReference: {
|
|
187
|
+
name,
|
|
188
|
+
moduleSpecifier,
|
|
189
|
+
sourceFilePath: sourceFile.fileName,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function cloneRuntimePropertyName(name) {
|
|
195
|
+
if (ts.isIdentifier(name)) {
|
|
196
|
+
return factory.createIdentifier(name.text);
|
|
197
|
+
}
|
|
198
|
+
if (ts.isStringLiteral(name)) {
|
|
199
|
+
return factory.createStringLiteral(name.text);
|
|
200
|
+
}
|
|
201
|
+
if (ts.isNumericLiteral(name)) {
|
|
202
|
+
return factory.createNumericLiteral(name.text);
|
|
203
|
+
}
|
|
204
|
+
if (ts.isComputedPropertyName(name)) {
|
|
205
|
+
return factory.createComputedPropertyName(cloneRuntimeExpression(name.expression));
|
|
206
|
+
}
|
|
207
|
+
return name;
|
|
208
|
+
}
|
|
209
|
+
function cloneRuntimeObjectElement(property) {
|
|
210
|
+
if (ts.isPropertyAssignment(property)) {
|
|
211
|
+
return factory.createPropertyAssignment(cloneRuntimePropertyName(property.name), cloneRuntimeExpression(property.initializer));
|
|
212
|
+
}
|
|
213
|
+
if (ts.isShorthandPropertyAssignment(property)) {
|
|
214
|
+
return factory.createShorthandPropertyAssignment(property.name.text, property.objectAssignmentInitializer
|
|
215
|
+
? cloneRuntimeExpression(property.objectAssignmentInitializer)
|
|
216
|
+
: undefined);
|
|
217
|
+
}
|
|
218
|
+
if (ts.isSpreadAssignment(property)) {
|
|
219
|
+
return factory.createSpreadAssignment(cloneRuntimeExpression(property.expression));
|
|
220
|
+
}
|
|
221
|
+
return property;
|
|
222
|
+
}
|
|
223
|
+
function cloneRuntimeExpression(expression) {
|
|
224
|
+
if (ts.isObjectLiteralExpression(expression)) {
|
|
225
|
+
return factory.createObjectLiteralExpression(expression.properties.map(cloneRuntimeObjectElement), true);
|
|
226
|
+
}
|
|
227
|
+
if (ts.isArrayLiteralExpression(expression)) {
|
|
228
|
+
return factory.createArrayLiteralExpression(expression.elements.map((element) => ts.isSpreadElement(element)
|
|
229
|
+
? factory.createSpreadElement(cloneRuntimeExpression(element.expression))
|
|
230
|
+
: cloneRuntimeExpression(element)), false);
|
|
231
|
+
}
|
|
232
|
+
if (ts.isStringLiteral(expression)) {
|
|
233
|
+
return factory.createStringLiteral(expression.text);
|
|
234
|
+
}
|
|
235
|
+
if (ts.isNoSubstitutionTemplateLiteral(expression)) {
|
|
236
|
+
return factory.createNoSubstitutionTemplateLiteral(expression.text, expression.rawText);
|
|
237
|
+
}
|
|
238
|
+
if (ts.isNumericLiteral(expression)) {
|
|
239
|
+
return factory.createNumericLiteral(expression.text);
|
|
240
|
+
}
|
|
241
|
+
if (ts.isBigIntLiteral(expression)) {
|
|
242
|
+
return factory.createBigIntLiteral(expression.text);
|
|
243
|
+
}
|
|
244
|
+
if (ts.isRegularExpressionLiteral(expression)) {
|
|
245
|
+
return factory.createRegularExpressionLiteral(expression.text);
|
|
246
|
+
}
|
|
247
|
+
if (expression.kind === ts.SyntaxKind.TrueKeyword) {
|
|
248
|
+
return factory.createTrue();
|
|
249
|
+
}
|
|
250
|
+
if (expression.kind === ts.SyntaxKind.FalseKeyword) {
|
|
251
|
+
return factory.createFalse();
|
|
252
|
+
}
|
|
253
|
+
if (expression.kind === ts.SyntaxKind.NullKeyword) {
|
|
254
|
+
return factory.createNull();
|
|
255
|
+
}
|
|
256
|
+
if (ts.isIdentifier(expression)) {
|
|
257
|
+
return factory.createIdentifier(expression.text);
|
|
258
|
+
}
|
|
259
|
+
if (ts.isPropertyAccessExpression(expression)) {
|
|
260
|
+
return factory.createPropertyAccessExpression(cloneRuntimeExpression(expression.expression), expression.name.text);
|
|
261
|
+
}
|
|
262
|
+
if (ts.isElementAccessExpression(expression)) {
|
|
263
|
+
return factory.createElementAccessExpression(cloneRuntimeExpression(expression.expression), cloneRuntimeExpression(expression.argumentExpression));
|
|
264
|
+
}
|
|
265
|
+
if (ts.isCallExpression(expression)) {
|
|
266
|
+
return factory.createCallExpression(cloneRuntimeExpression(expression.expression), expression.typeArguments, expression.arguments.map(cloneRuntimeExpression));
|
|
267
|
+
}
|
|
268
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
269
|
+
return factory.createParenthesizedExpression(cloneRuntimeExpression(expression.expression));
|
|
270
|
+
}
|
|
271
|
+
if (ts.isPrefixUnaryExpression(expression)) {
|
|
272
|
+
return factory.createPrefixUnaryExpression(expression.operator, cloneRuntimeExpression(expression.operand));
|
|
273
|
+
}
|
|
274
|
+
if (ts.isPostfixUnaryExpression(expression)) {
|
|
275
|
+
return factory.createPostfixUnaryExpression(cloneRuntimeExpression(expression.operand), expression.operator);
|
|
276
|
+
}
|
|
277
|
+
if (ts.isBinaryExpression(expression)) {
|
|
278
|
+
return factory.createBinaryExpression(cloneRuntimeExpression(expression.left), expression.operatorToken.kind, cloneRuntimeExpression(expression.right));
|
|
279
|
+
}
|
|
280
|
+
if (ts.isConditionalExpression(expression)) {
|
|
281
|
+
return factory.createConditionalExpression(cloneRuntimeExpression(expression.condition), expression.questionToken, cloneRuntimeExpression(expression.whenTrue), expression.colonToken, cloneRuntimeExpression(expression.whenFalse));
|
|
282
|
+
}
|
|
283
|
+
if (ts.isAsExpression(expression)) {
|
|
284
|
+
return factory.createAsExpression(cloneRuntimeExpression(expression.expression), expression.type);
|
|
285
|
+
}
|
|
286
|
+
if (ts.isTypeAssertionExpression(expression)) {
|
|
287
|
+
return factory.createTypeAssertion(expression.type, cloneRuntimeExpression(expression.expression));
|
|
288
|
+
}
|
|
289
|
+
return expression;
|
|
290
|
+
}
|
|
291
|
+
function resolveRuntimeFileCandidate(modulePath) {
|
|
292
|
+
const candidates = [
|
|
293
|
+
modulePath,
|
|
294
|
+
`${modulePath}.js`,
|
|
295
|
+
PathLib.join(modulePath, 'index.js'),
|
|
296
|
+
];
|
|
297
|
+
for (const candidate of candidates) {
|
|
298
|
+
if (existsSync(candidate)) {
|
|
299
|
+
return realpathSync(candidate);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function getPackageNameFromModuleSpecifier(moduleSpecifier) {
|
|
304
|
+
if (moduleSpecifier.startsWith('@')) {
|
|
305
|
+
const [scope, name] = moduleSpecifier.split('/');
|
|
306
|
+
return scope && name ? `${scope}/${name}` : undefined;
|
|
307
|
+
}
|
|
308
|
+
return moduleSpecifier.split('/')[0];
|
|
309
|
+
}
|
|
310
|
+
function getPackageRelativePathFromModuleSpecifier(moduleSpecifier) {
|
|
311
|
+
const packageName = getPackageNameFromModuleSpecifier(moduleSpecifier);
|
|
312
|
+
return packageName ? moduleSpecifier.slice(packageName.length).replace(/^[\\/]/, '') : '';
|
|
313
|
+
}
|
|
314
|
+
function getNodeModuleSearchRoots(sourceFilePath) {
|
|
315
|
+
const roots = [process.cwd()];
|
|
316
|
+
let current = PathLib.dirname(sourceFilePath);
|
|
317
|
+
while (current && current !== PathLib.dirname(current)) {
|
|
318
|
+
roots.push(current);
|
|
319
|
+
current = PathLib.dirname(current);
|
|
320
|
+
}
|
|
321
|
+
return roots;
|
|
322
|
+
}
|
|
323
|
+
function resolveRuntimeModuleFile(importReference) {
|
|
324
|
+
if (importReference.moduleSpecifier.startsWith('.')) {
|
|
325
|
+
return resolveRuntimeFileCandidate(PathLib.resolve(PathLib.dirname(importReference.sourceFilePath), importReference.moduleSpecifier));
|
|
326
|
+
}
|
|
327
|
+
for (const root of getNodeModuleSearchRoots(importReference.sourceFilePath)) {
|
|
328
|
+
const resolved = resolveRuntimeFileCandidate(PathLib.join(root, 'node_modules', importReference.moduleSpecifier));
|
|
329
|
+
if (resolved) {
|
|
330
|
+
return resolved;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const packageName = getPackageNameFromModuleSpecifier(importReference.moduleSpecifier);
|
|
334
|
+
const packageRelativePath = getPackageRelativePathFromModuleSpecifier(importReference.moduleSpecifier);
|
|
335
|
+
if (!packageName) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
for (const root of getNodeModuleSearchRoots(importReference.sourceFilePath)) {
|
|
339
|
+
const siblingPackagePath = PathLib.join(root, packageName, packageRelativePath);
|
|
340
|
+
const resolved = resolveRuntimeFileCandidate(siblingPackagePath);
|
|
341
|
+
if (resolved) {
|
|
342
|
+
return resolved;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function createRuntimeImportReferenceForIdentifier(sourceFile, expression) {
|
|
347
|
+
if (!ts.isIdentifier(expression)) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const importReference = getEsImportReference(sourceFile, expression.text);
|
|
351
|
+
return importReference ? { expression: factory.createIdentifier(expression.text), importReference } : undefined;
|
|
352
|
+
}
|
|
353
|
+
function createRuntimeImportReferenceForPropertyAccess(sourceFile, expression, exportedName) {
|
|
354
|
+
if (!ts.isPropertyAccessExpression(expression) || !ts.isIdentifier(expression.expression)) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
const moduleSpecifier = getRequireModuleSpecifier(sourceFile, expression.expression.text);
|
|
358
|
+
if (!moduleSpecifier) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const importedName = expression.name.text;
|
|
362
|
+
const localName = importedName === exportedName ? `Imported${importedName}` : importedName;
|
|
363
|
+
return {
|
|
364
|
+
expression: factory.createIdentifier(localName),
|
|
365
|
+
importReference: {
|
|
366
|
+
name: localName,
|
|
367
|
+
propertyName: localName === importedName ? undefined : importedName,
|
|
368
|
+
moduleSpecifier,
|
|
369
|
+
sourceFilePath: sourceFile.fileName,
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function createRuntimeImportReference(sourceFile, expression, exportedName) {
|
|
374
|
+
return createRuntimeImportReferenceForIdentifier(sourceFile, expression)
|
|
375
|
+
|| createRuntimeImportReferenceForPropertyAccess(sourceFile, expression, exportedName);
|
|
376
|
+
}
|
|
377
|
+
function getRuntimeActionDefMetadataFromImportReference(importReference, visited = new Set()) {
|
|
378
|
+
const runtimeFilePath = resolveRuntimeModuleFile(importReference);
|
|
379
|
+
if (!runtimeFilePath) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const exportName = importReference.propertyName || importReference.name;
|
|
383
|
+
const visitKey = `${normalizeCachePath(runtimeFilePath)}#${exportName}`;
|
|
384
|
+
if (visited.has(visitKey)) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
visited.add(visitKey);
|
|
388
|
+
const sourceFile = readRuntimeSourceFile(runtimeFilePath);
|
|
389
|
+
const initializer = findExportedInitializer(sourceFile, exportName);
|
|
390
|
+
if (!initializer) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
return getRuntimeActionDefMetadata(normalizeRuntimeInitializer(sourceFile, initializer, exportName, visited), visited);
|
|
394
|
+
}
|
|
395
|
+
function normalizeRuntimeInitializer(sourceFile, expression, exportedName, visited = new Set()) {
|
|
396
|
+
const callImportReference = getRuntimeCallImportReference(sourceFile, expression);
|
|
397
|
+
if (callImportReference) {
|
|
398
|
+
return {
|
|
399
|
+
expression: cloneRuntimeExpression(callImportReference.expression),
|
|
400
|
+
importReference: callImportReference.importReference,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
const runtimeImportReference = createRuntimeImportReference(sourceFile, expression, exportedName);
|
|
404
|
+
if (runtimeImportReference) {
|
|
405
|
+
return {
|
|
406
|
+
expression: cloneRuntimeExpression(runtimeImportReference.expression),
|
|
407
|
+
importReference: runtimeImportReference.importReference,
|
|
408
|
+
metadata: getRuntimeActionDefMetadataFromImportReference(runtimeImportReference.importReference, visited),
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
return { expression: cloneRuntimeExpression(expression) };
|
|
412
|
+
}
|
|
413
|
+
export function getRuntimeInitializer(typeFilePath, name) {
|
|
414
|
+
const sourceFile = getRuntimeSourceFileForTypeFile(typeFilePath);
|
|
415
|
+
if (!sourceFile) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const initializer = findExportedInitializer(sourceFile, name);
|
|
419
|
+
return initializer ? normalizeRuntimeInitializer(sourceFile, initializer, name) : undefined;
|
|
420
|
+
}
|
|
421
|
+
export function getRuntimeActionDefInitializers(typeFilePath) {
|
|
422
|
+
const sourceFile = getRuntimeSourceFileForTypeFile(typeFilePath);
|
|
423
|
+
if (!sourceFile) {
|
|
424
|
+
return {};
|
|
425
|
+
}
|
|
426
|
+
const names = new Set();
|
|
427
|
+
for (const statement of sourceFile.statements) {
|
|
428
|
+
if (ts.isVariableStatement(statement)) {
|
|
429
|
+
statement.declarationList.declarations.forEach((declaration) => {
|
|
430
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text.endsWith('ActionDef')) {
|
|
431
|
+
names.add(declaration.name.text);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
if (ts.isExpressionStatement(statement)
|
|
436
|
+
&& ts.isBinaryExpression(statement.expression)
|
|
437
|
+
&& statement.expression.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
438
|
+
const exportName = getCommonJsExportName(statement.expression.left);
|
|
439
|
+
if (exportName?.endsWith('ActionDef') && !isVoidExpression(statement.expression.right)) {
|
|
440
|
+
names.add(exportName);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
const result = {};
|
|
445
|
+
names.forEach((name) => {
|
|
446
|
+
const initializer = getRuntimeInitializer(typeFilePath, name);
|
|
447
|
+
if (initializer) {
|
|
448
|
+
result[name] = initializer;
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
export function getEntityNameFromSourceFile(source) {
|
|
454
|
+
return entityNameFromFilename(source.filename);
|
|
455
|
+
}
|
|
456
|
+
function getPropertyNameText(name) {
|
|
457
|
+
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {
|
|
458
|
+
return name.text;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function collectStringLiterals(expression, result) {
|
|
462
|
+
if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {
|
|
463
|
+
if (!result.includes(expression.text)) {
|
|
464
|
+
result.push(expression.text);
|
|
465
|
+
}
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (ts.isArrayLiteralExpression(expression)) {
|
|
469
|
+
expression.elements.forEach((element) => collectStringLiterals(element, result));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function readActionDefObjectMetadata(expression) {
|
|
473
|
+
const actions = [];
|
|
474
|
+
const states = [];
|
|
475
|
+
let hasIs = false;
|
|
476
|
+
expression.properties.forEach((property) => {
|
|
477
|
+
if (!ts.isPropertyAssignment(property)) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const propertyName = getPropertyNameText(property.name);
|
|
481
|
+
if (propertyName === 'is' && (ts.isStringLiteral(property.initializer) || ts.isNoSubstitutionTemplateLiteral(property.initializer))) {
|
|
482
|
+
hasIs = true;
|
|
483
|
+
if (!states.includes(property.initializer.text)) {
|
|
484
|
+
states.push(property.initializer.text);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (propertyName === 'stm' && ts.isObjectLiteralExpression(property.initializer)) {
|
|
488
|
+
property.initializer.properties.forEach((stmProperty) => {
|
|
489
|
+
if (!ts.isPropertyAssignment(stmProperty)) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
const actionName = getPropertyNameText(stmProperty.name);
|
|
493
|
+
if (actionName && !actions.includes(actionName)) {
|
|
494
|
+
actions.push(actionName);
|
|
495
|
+
}
|
|
496
|
+
collectStringLiterals(stmProperty.initializer, states);
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
return { actions, states, hasIs };
|
|
501
|
+
}
|
|
502
|
+
export function getRuntimeActionDefMetadata(initializer, visited = new Set()) {
|
|
503
|
+
if (initializer.metadata) {
|
|
504
|
+
return initializer.metadata;
|
|
505
|
+
}
|
|
506
|
+
if (ts.isObjectLiteralExpression(initializer.expression)) {
|
|
507
|
+
return readActionDefObjectMetadata(initializer.expression);
|
|
508
|
+
}
|
|
509
|
+
if (initializer.importReference) {
|
|
510
|
+
return getRuntimeActionDefMetadataFromImportReference(initializer.importReference, visited);
|
|
511
|
+
}
|
|
512
|
+
if (ts.isCallExpression(initializer.expression)
|
|
513
|
+
&& ts.isIdentifier(initializer.expression.expression)
|
|
514
|
+
&& initializer.expression.expression.text === 'makeAbleActionDef') {
|
|
515
|
+
return {
|
|
516
|
+
actions: ['enable', 'disable'],
|
|
517
|
+
states: ['enabled', 'disabled'],
|
|
518
|
+
hasIs: initializer.expression.arguments.length > 0,
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { Hash } from
|
|
1
|
+
import { Hash } from "crypto";
|
|
2
2
|
type OakPackageMeta = {
|
|
3
3
|
i18n: boolean;
|
|
4
4
|
name: string;
|
|
5
5
|
root: string;
|
|
6
6
|
};
|
|
7
|
+
export type LocaleWorkspace = {
|
|
8
|
+
namespacePrefix: string;
|
|
9
|
+
relativePath: string;
|
|
10
|
+
};
|
|
7
11
|
/**
|
|
8
12
|
* 这个类的作用是把项目和所有相关的模块下的locales编译成为src/data/i18n中的数据
|
|
9
13
|
*/
|
|
@@ -15,7 +19,8 @@ export default class LocaleBuilder {
|
|
|
15
19
|
locales: Record<string, [string, string, string, string, object]>;
|
|
16
20
|
hash: Hash;
|
|
17
21
|
projectName?: string;
|
|
18
|
-
|
|
22
|
+
localeWorkspaces?: LocaleWorkspace[];
|
|
23
|
+
constructor(asLib?: boolean, localeWorkspaces?: LocaleWorkspace[]);
|
|
19
24
|
/**
|
|
20
25
|
* 将locales输出成为data/i18n.ts中的数据
|
|
21
26
|
* 如果有Dependency需要引出来
|