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.
Files changed (400) hide show
  1. package/README.md +5 -1
  2. package/es/actions/action.d.ts +1 -1
  3. package/es/base-app-domain/EntityDict.d.ts +27 -0
  4. package/es/base-app-domain/LocalizedContent/Schema.d.ts +19 -0
  5. package/es/base-app-domain/LocalizedContent/Schema.js +1 -0
  6. package/es/base-app-domain/LocalizedContent/Storage.d.ts +3 -0
  7. package/es/base-app-domain/LocalizedContent/Storage.js +75 -0
  8. package/es/base-app-domain/LocalizedContent/Style.d.ts +3 -0
  9. package/es/base-app-domain/LocalizedContent/Style.js +12 -0
  10. package/es/base-app-domain/LocalizedContent/_baseSchema.d.ts +58 -0
  11. package/es/base-app-domain/Storage.js +2 -0
  12. package/es/base-app-domain/StyleDict.js +2 -0
  13. package/es/compiler/customChecks/i18n.js +4 -1
  14. package/es/compiler/customChecks/runner.d.ts +1 -1
  15. package/es/compiler/customChecks/runner.js +1 -1
  16. package/es/compiler/customChecks/types.d.ts +2 -1
  17. package/es/compiler/dependencyBuilder.d.ts +11 -2
  18. package/es/compiler/dependencyBuilder.js +188 -199
  19. package/es/compiler/entityDescEnum.d.ts +5 -0
  20. package/es/compiler/entityDescEnum.js +443 -0
  21. package/es/compiler/entitySource.d.ts +28 -0
  22. package/es/compiler/entitySource.js +521 -0
  23. package/es/compiler/localeBuilder.d.ts +7 -2
  24. package/es/compiler/localeBuilder.js +52 -56
  25. package/es/compiler/routerBuilder.d.ts +32 -3
  26. package/es/compiler/routerBuilder.js +157 -45
  27. package/es/compiler/schemaBuilder.d.ts +12 -2
  28. package/es/compiler/schemaBuilder.js +653 -148
  29. package/es/compiler/tscBuilder.d.ts +20 -2
  30. package/es/compiler/tscBuilder.js +231 -45
  31. package/es/context/BackendRuntimeContext.d.ts +6 -4
  32. package/es/context/BackendRuntimeContext.js +9 -1
  33. package/es/context/ContextComposer.d.ts +93 -0
  34. package/es/context/ContextComposer.js +353 -0
  35. package/es/context/SerializedData.d.ts +2 -1
  36. package/es/data/i18n.d.ts +1 -1
  37. package/es/data/i18n.js +1 -86
  38. package/es/data/i18n.json +86 -0
  39. package/es/entities/ActionAuth.d.ts +3 -3
  40. package/es/entities/I18n.d.ts +2 -2
  41. package/es/entities/LocalizedContent.d.ts +22 -0
  42. package/es/entities/LocalizedContent.js +101 -0
  43. package/es/entities/Log.d.ts +3 -3
  44. package/es/entities/Modi.d.ts +2 -2
  45. package/es/entities/ModiEntity.d.ts +3 -3
  46. package/es/entities/Oper.d.ts +5 -5
  47. package/es/entities/OperEntity.d.ts +3 -3
  48. package/es/entities/Path.d.ts +2 -2
  49. package/es/entities/Relation.d.ts +2 -2
  50. package/es/entities/RelationAuth.d.ts +3 -3
  51. package/es/entities/User.d.ts +4 -4
  52. package/es/entities/UserEntityClaim.d.ts +6 -6
  53. package/es/entities/UserEntityGrant.d.ts +2 -2
  54. package/es/entities/UserRelation.d.ts +4 -4
  55. package/es/store/AsyncRowStore.d.ts +2 -2
  56. package/es/store/AsyncRowStore.js +2 -2
  57. package/es/store/CascadeStore.d.ts +5 -3
  58. package/es/store/CascadeStore.js +56 -24
  59. package/es/store/IntrinsicCheckers.d.ts +1 -1
  60. package/es/store/IntrinsicCheckers.js +2 -2
  61. package/es/store/IntrinsicLogics.d.ts +1 -1
  62. package/es/store/RelationAuth.js +3 -3
  63. package/es/store/SyncRowStore.d.ts +1 -1
  64. package/es/store/SyncRowStore.js +1 -1
  65. package/es/store/TriggerExecutor.d.ts +6 -4
  66. package/es/store/TriggerExecutor.js +16 -4
  67. package/es/store/checker.d.ts +2 -2
  68. package/es/store/checker.js +45 -9
  69. package/es/store/filter.d.ts +3 -3
  70. package/es/store/filter.js +4 -4
  71. package/es/store/modi.d.ts +5 -5
  72. package/es/store/modi.js +4 -4
  73. package/es/store/projection.d.ts +1 -1
  74. package/es/store/relation.js +1 -1
  75. package/es/store/triggers.d.ts +4 -4
  76. package/es/store/triggers.js +2 -2
  77. package/es/timers/oper.d.ts +3 -3
  78. package/es/timers/oper.js +1 -1
  79. package/es/timers/vaccum.d.ts +3 -3
  80. package/es/types/Action.d.ts +1 -1
  81. package/es/types/AppLoader.d.ts +1 -1
  82. package/es/types/Aspect.d.ts +1 -1
  83. package/es/types/Auth.d.ts +2 -2
  84. package/es/types/Configuration.d.ts +7 -6
  85. package/es/types/Connector.d.ts +47 -1
  86. package/es/types/DataType.d.ts +2 -2
  87. package/es/types/Demand.d.ts +40 -6
  88. package/es/types/Endpoint.d.ts +17 -1
  89. package/es/types/Entity.d.ts +21 -4
  90. package/es/types/Entity.js +23 -0
  91. package/es/types/EntityDesc.d.ts +9 -8
  92. package/es/types/Environment.d.ts +17 -0
  93. package/es/types/Exception.d.ts +1 -1
  94. package/es/types/Exception.js +1 -1
  95. package/es/types/Expression.d.ts +13 -2
  96. package/es/types/Expression.js +36 -1
  97. package/es/types/Locale.d.ts +14 -1
  98. package/es/types/Locale.js +13 -1
  99. package/es/types/OakPackage.d.ts +29 -0
  100. package/es/types/OakPackage.js +30 -0
  101. package/es/types/Port.d.ts +1 -1
  102. package/es/types/RowStore.d.ts +9 -7
  103. package/es/types/Storage.d.ts +11 -3
  104. package/es/types/Storage.js +12 -1
  105. package/es/types/Style.d.ts +2 -2
  106. package/es/types/Sync.d.ts +3 -3
  107. package/es/types/Timer.d.ts +14 -2
  108. package/es/types/Trigger.d.ts +1 -1
  109. package/es/types/Watcher.d.ts +1 -1
  110. package/es/types/index.d.ts +1 -0
  111. package/es/types/index.js +1 -0
  112. package/es/utils/SimpleConnector.d.ts +30 -4
  113. package/es/utils/SimpleConnector.js +294 -21
  114. package/es/utils/concurrent.js +1 -1
  115. package/es/utils/decimal.d.ts +26 -0
  116. package/es/utils/decimal.js +87 -0
  117. package/es/utils/fetch/index.d.ts +1 -0
  118. package/es/utils/fetch/index.js +3 -0
  119. package/es/utils/fetch/index.mp.d.ts +3 -0
  120. package/es/utils/fetch/index.mp.js +280 -0
  121. package/es/utils/fetch/index.native.d.ts +1 -0
  122. package/es/utils/fetch/index.native.js +3 -0
  123. package/es/utils/fetch/index.web.d.ts +1 -0
  124. package/es/utils/fetch/index.web.js +3 -0
  125. package/es/utils/fetch/shared.d.ts +6 -0
  126. package/es/utils/fetch/shared.js +23 -0
  127. package/es/utils/localizedContent.d.ts +11 -0
  128. package/es/utils/localizedContent.js +346 -0
  129. package/es/utils/lodash.d.ts +1 -35
  130. package/es/utils/lodash.js +1 -52
  131. package/es/utils/module/combine.common.d.ts +3 -3
  132. package/es/utils/module/combine.common.js +2 -2
  133. package/es/utils/module/combine.dev.d.ts +2 -2
  134. package/es/utils/module/combine.dev.js +2 -2
  135. package/es/utils/module/combine.prod.d.ts +1 -1
  136. package/es/utils/module/combine.server.d.ts +2 -2
  137. package/es/utils/module/combine.server.js +2 -2
  138. package/es/utils/money.d.ts +2 -2
  139. package/es/utils/money.js +2 -2
  140. package/es/utils/operationResult.js +1 -1
  141. package/es/utils/projection.d.ts +3 -3
  142. package/es/utils/projection.js +1 -1
  143. package/es/utils/relationPath.d.ts +1 -1
  144. package/es/utils/relationPath.js +1 -1
  145. package/es/utils/row.d.ts +3 -3
  146. package/es/utils/row.js +2 -2
  147. package/es/utils/sseEndpoint.d.ts +41 -0
  148. package/es/utils/sseEndpoint.js +151 -0
  149. package/es/utils/toolkit.d.ts +28 -0
  150. package/es/utils/toolkit.js +220 -0
  151. package/es/utils/url/index.d.ts +1 -3
  152. package/es/utils/url/index.js +1 -1
  153. package/es/utils/url/index.mp.d.ts +16 -3
  154. package/es/utils/url/index.mp.js +2 -2
  155. package/es/utils/url/index.native.d.ts +13 -1
  156. package/es/utils/url/index.native.js +3 -1
  157. package/es/utils/url/index.web.d.ts +13 -1
  158. package/es/utils/url/index.web.js +3 -1
  159. package/es/utils/url/lightweight.d.ts +65 -0
  160. package/es/utils/url/lightweight.js +530 -0
  161. package/es/utils/url/urlObject.d.ts +16 -0
  162. package/es/utils/validate/id.d.ts +5 -0
  163. package/es/utils/validate/id.js +28 -0
  164. package/es/utils/validate/index.d.ts +4 -0
  165. package/es/utils/validate/index.js +4 -0
  166. package/es/utils/validate/mobile.d.ts +6 -0
  167. package/es/utils/validate/mobile.js +49 -0
  168. package/es/utils/validate/nationality.d.ts +14 -0
  169. package/es/utils/validate/nationality.data.d.ts +9 -0
  170. package/es/utils/validate/nationality.data.js +257 -0
  171. package/es/utils/validate/nationality.js +64 -0
  172. package/es/utils/validate/passport.d.ts +3 -0
  173. package/es/utils/validate/passport.js +19 -0
  174. package/es/utils/validator.d.ts +10 -8
  175. package/es/utils/validator.js +24 -40
  176. package/lib/actions/action.d.ts +1 -1
  177. package/lib/base-app-domain/EntityDict.d.ts +27 -0
  178. package/lib/base-app-domain/LocalizedContent/Schema.d.ts +19 -0
  179. package/lib/base-app-domain/LocalizedContent/Schema.js +4 -0
  180. package/lib/base-app-domain/LocalizedContent/Storage.d.ts +3 -0
  181. package/lib/base-app-domain/LocalizedContent/Storage.js +78 -0
  182. package/lib/base-app-domain/LocalizedContent/Style.d.ts +3 -0
  183. package/lib/base-app-domain/LocalizedContent/Style.js +15 -0
  184. package/lib/base-app-domain/LocalizedContent/_baseSchema.d.ts +58 -0
  185. package/lib/base-app-domain/Storage.js +26 -24
  186. package/lib/base-app-domain/StyleDict.js +10 -8
  187. package/lib/compiler/customChecks/i18n.js +5 -2
  188. package/lib/compiler/customChecks/runner.d.ts +1 -1
  189. package/lib/compiler/customChecks/types.d.ts +2 -1
  190. package/lib/compiler/dependencyBuilder.d.ts +11 -2
  191. package/lib/compiler/dependencyBuilder.js +237 -243
  192. package/lib/compiler/entityDescEnum.d.ts +5 -0
  193. package/lib/compiler/entityDescEnum.js +450 -0
  194. package/lib/compiler/entitySource.d.ts +28 -0
  195. package/lib/compiler/entitySource.js +529 -0
  196. package/lib/compiler/localeBuilder.d.ts +7 -2
  197. package/lib/compiler/localeBuilder.js +52 -56
  198. package/lib/compiler/routerBuilder.d.ts +32 -3
  199. package/lib/compiler/routerBuilder.js +160 -48
  200. package/lib/compiler/schemaBuilder.d.ts +12 -2
  201. package/lib/compiler/schemaBuilder.js +855 -350
  202. package/lib/compiler/tscBuilder.d.ts +20 -2
  203. package/lib/compiler/tscBuilder.js +217 -37
  204. package/lib/context/BackendRuntimeContext.d.ts +6 -4
  205. package/lib/context/BackendRuntimeContext.js +10 -3
  206. package/lib/context/ContextComposer.d.ts +93 -0
  207. package/lib/context/ContextComposer.js +361 -0
  208. package/lib/context/SerializedData.d.ts +2 -1
  209. package/lib/data/i18n.d.ts +1 -1
  210. package/lib/data/i18n.js +1 -86
  211. package/lib/data/i18n.json +86 -0
  212. package/lib/entities/ActionAuth.d.ts +3 -3
  213. package/lib/entities/I18n.d.ts +2 -2
  214. package/lib/entities/LocalizedContent.d.ts +22 -0
  215. package/lib/entities/LocalizedContent.js +104 -0
  216. package/lib/entities/Log.d.ts +3 -3
  217. package/lib/entities/Modi.d.ts +2 -2
  218. package/lib/entities/ModiEntity.d.ts +3 -3
  219. package/lib/entities/Oper.d.ts +5 -5
  220. package/lib/entities/OperEntity.d.ts +3 -3
  221. package/lib/entities/Path.d.ts +2 -2
  222. package/lib/entities/Relation.d.ts +2 -2
  223. package/lib/entities/RelationAuth.d.ts +3 -3
  224. package/lib/entities/User.d.ts +4 -4
  225. package/lib/entities/UserEntityClaim.d.ts +6 -6
  226. package/lib/entities/UserEntityGrant.d.ts +2 -2
  227. package/lib/entities/UserRelation.d.ts +4 -4
  228. package/lib/store/AsyncRowStore.d.ts +2 -2
  229. package/lib/store/AsyncRowStore.js +6 -7
  230. package/lib/store/CascadeStore.d.ts +5 -3
  231. package/lib/store/CascadeStore.js +101 -70
  232. package/lib/store/IntrinsicCheckers.d.ts +1 -1
  233. package/lib/store/IntrinsicCheckers.js +12 -13
  234. package/lib/store/IntrinsicLogics.d.ts +1 -1
  235. package/lib/store/RelationAuth.js +42 -43
  236. package/lib/store/SyncRowStore.d.ts +1 -1
  237. package/lib/store/SyncRowStore.js +4 -5
  238. package/lib/store/TriggerExecutor.d.ts +6 -4
  239. package/lib/store/TriggerExecutor.js +39 -28
  240. package/lib/store/checker.d.ts +2 -2
  241. package/lib/store/checker.js +55 -20
  242. package/lib/store/filter.d.ts +3 -3
  243. package/lib/store/filter.js +47 -48
  244. package/lib/store/modi.d.ts +5 -5
  245. package/lib/store/modi.js +5 -6
  246. package/lib/store/projection.d.ts +1 -1
  247. package/lib/store/relation.js +4 -5
  248. package/lib/store/triggers.d.ts +4 -4
  249. package/lib/store/triggers.js +13 -14
  250. package/lib/timers/oper.d.ts +3 -3
  251. package/lib/timers/vaccum.d.ts +3 -3
  252. package/lib/types/Action.d.ts +1 -1
  253. package/lib/types/AppLoader.d.ts +1 -1
  254. package/lib/types/Aspect.d.ts +1 -1
  255. package/lib/types/Auth.d.ts +2 -2
  256. package/lib/types/Configuration.d.ts +7 -6
  257. package/lib/types/Connector.d.ts +47 -1
  258. package/lib/types/DataType.d.ts +2 -2
  259. package/lib/types/Demand.d.ts +40 -6
  260. package/lib/types/Endpoint.d.ts +17 -1
  261. package/lib/types/Entity.d.ts +21 -4
  262. package/lib/types/Entity.js +27 -0
  263. package/lib/types/EntityDesc.d.ts +9 -8
  264. package/lib/types/Environment.d.ts +17 -0
  265. package/lib/types/Exception.d.ts +1 -1
  266. package/lib/types/Exception.js +2 -2
  267. package/lib/types/Expression.d.ts +13 -2
  268. package/lib/types/Expression.js +40 -5
  269. package/lib/types/Locale.d.ts +14 -1
  270. package/lib/types/Locale.js +14 -0
  271. package/lib/types/OakPackage.d.ts +29 -0
  272. package/lib/types/OakPackage.js +36 -0
  273. package/lib/types/Port.d.ts +1 -1
  274. package/lib/types/RowStore.d.ts +9 -7
  275. package/lib/types/Storage.d.ts +11 -3
  276. package/lib/types/Storage.js +13 -0
  277. package/lib/types/Style.d.ts +2 -2
  278. package/lib/types/Sync.d.ts +3 -3
  279. package/lib/types/Timer.d.ts +14 -2
  280. package/lib/types/Trigger.d.ts +1 -1
  281. package/lib/types/Watcher.d.ts +1 -1
  282. package/lib/types/index.d.ts +1 -0
  283. package/lib/types/index.js +1 -0
  284. package/lib/utils/SimpleConnector.d.ts +30 -4
  285. package/lib/utils/SimpleConnector.js +297 -24
  286. package/lib/utils/concurrent.js +4 -5
  287. package/lib/utils/decimal.d.ts +26 -0
  288. package/lib/utils/decimal.js +112 -0
  289. package/lib/utils/fetch/index.d.ts +1 -0
  290. package/lib/utils/fetch/index.js +6 -0
  291. package/lib/utils/fetch/index.mp.d.ts +3 -0
  292. package/lib/utils/fetch/index.mp.js +285 -0
  293. package/lib/utils/fetch/index.native.d.ts +1 -0
  294. package/lib/utils/fetch/index.native.js +6 -0
  295. package/lib/utils/fetch/index.web.d.ts +1 -0
  296. package/lib/utils/fetch/index.web.js +6 -0
  297. package/lib/utils/fetch/shared.d.ts +6 -0
  298. package/lib/utils/fetch/shared.js +28 -0
  299. package/lib/utils/localizedContent.d.ts +11 -0
  300. package/lib/utils/localizedContent.js +352 -0
  301. package/lib/utils/lodash.d.ts +1 -35
  302. package/lib/utils/lodash.js +1 -76
  303. package/lib/utils/module/combine.common.d.ts +3 -3
  304. package/lib/utils/module/combine.common.js +6 -7
  305. package/lib/utils/module/combine.dev.d.ts +2 -2
  306. package/lib/utils/module/combine.dev.js +19 -19
  307. package/lib/utils/module/combine.prod.d.ts +1 -1
  308. package/lib/utils/module/combine.server.d.ts +2 -2
  309. package/lib/utils/module/combine.server.js +19 -19
  310. package/lib/utils/money.d.ts +2 -2
  311. package/lib/utils/money.js +2 -2
  312. package/lib/utils/operationResult.js +4 -4
  313. package/lib/utils/projection.d.ts +3 -3
  314. package/lib/utils/relationPath.d.ts +1 -1
  315. package/lib/utils/relationPath.js +10 -11
  316. package/lib/utils/row.d.ts +3 -3
  317. package/lib/utils/row.js +4 -5
  318. package/lib/utils/sseEndpoint.d.ts +41 -0
  319. package/lib/utils/sseEndpoint.js +156 -0
  320. package/lib/utils/toolkit.d.ts +28 -0
  321. package/lib/utils/toolkit.js +253 -0
  322. package/lib/utils/url/index.d.ts +1 -3
  323. package/lib/utils/url/index.js +3 -1
  324. package/lib/utils/url/index.mp.d.ts +16 -3
  325. package/lib/utils/url/index.mp.js +6 -4
  326. package/lib/utils/url/index.native.d.ts +13 -1
  327. package/lib/utils/url/index.native.js +5 -1
  328. package/lib/utils/url/index.web.d.ts +13 -1
  329. package/lib/utils/url/index.web.js +5 -1
  330. package/lib/utils/url/lightweight.d.ts +65 -0
  331. package/lib/utils/url/lightweight.js +535 -0
  332. package/lib/utils/url/urlObject.d.ts +16 -0
  333. package/lib/utils/url/urlObject.js +2 -0
  334. package/lib/utils/url/whatwg-url/lib/URL-impl.d.ts +8 -15
  335. package/lib/utils/url/whatwg-url/lib/infra.js +5 -4
  336. package/lib/utils/url/whatwg-url/lib/urlencoded.d.ts +3 -1
  337. package/lib/utils/url/whatwg-url/lib/utils.d.ts +1 -1
  338. package/lib/utils/validate/id.d.ts +5 -0
  339. package/lib/utils/validate/id.js +35 -0
  340. package/lib/utils/validate/index.d.ts +4 -0
  341. package/lib/utils/validate/index.js +7 -0
  342. package/lib/utils/validate/mobile.d.ts +6 -0
  343. package/lib/utils/validate/mobile.js +57 -0
  344. package/lib/utils/validate/nationality.d.ts +14 -0
  345. package/lib/utils/validate/nationality.data.d.ts +9 -0
  346. package/lib/utils/validate/nationality.data.js +260 -0
  347. package/lib/utils/validate/nationality.js +76 -0
  348. package/lib/utils/validate/passport.d.ts +3 -0
  349. package/lib/utils/validate/passport.js +24 -0
  350. package/lib/utils/validator.d.ts +10 -8
  351. package/lib/utils/validator.js +38 -42
  352. package/package.json +19 -9
  353. package/es/utils/url/whatwg-url/index.d.ts +0 -3
  354. package/es/utils/url/whatwg-url/index.js +0 -12
  355. package/es/utils/url/whatwg-url/lib/URL-impl.d.ts +0 -27
  356. package/es/utils/url/whatwg-url/lib/URL-impl.js +0 -172
  357. package/es/utils/url/whatwg-url/lib/URL.js +0 -295
  358. package/es/utils/url/whatwg-url/lib/URLSearchParams-impl.d.ts +0 -19
  359. package/es/utils/url/whatwg-url/lib/URLSearchParams-impl.js +0 -123
  360. package/es/utils/url/whatwg-url/lib/URLSearchParams.js +0 -423
  361. package/es/utils/url/whatwg-url/lib/infra.d.ts +0 -12
  362. package/es/utils/url/whatwg-url/lib/infra.js +0 -19
  363. package/es/utils/url/whatwg-url/lib/url-state-machine.d.ts +0 -24
  364. package/es/utils/url/whatwg-url/lib/url-state-machine.js +0 -1228
  365. package/es/utils/url/whatwg-url/lib/urlencoded.d.ts +0 -14
  366. package/es/utils/url/whatwg-url/lib/urlencoded.js +0 -160
  367. package/es/utils/url/whatwg-url/lib/utils.d.ts +0 -37
  368. package/es/utils/url/whatwg-url/lib/utils.js +0 -99
  369. package/lib/store/diffSchema.d.ts +0 -1
  370. package/lib/utils/url/whatwg-url/index.d.ts +0 -3
  371. package/lib/utils/url/whatwg-url/index.js +0 -16
  372. package/lib/utils/url/whatwg-url/lib/URL-impl.js +0 -175
  373. package/lib/utils/url/whatwg-url/lib/URL.d.ts +0 -1
  374. package/lib/utils/url/whatwg-url/lib/URL.js +0 -298
  375. package/lib/utils/url/whatwg-url/lib/URLSearchParams-impl.d.ts +0 -19
  376. package/lib/utils/url/whatwg-url/lib/URLSearchParams-impl.js +0 -126
  377. package/lib/utils/url/whatwg-url/lib/URLSearchParams.d.ts +0 -1
  378. package/lib/utils/url/whatwg-url/lib/URLSearchParams.js +0 -426
  379. package/lib/utils/url/whatwg-url/lib/infra.d.ts +0 -12
  380. package/lib/utils/url/whatwg-url/lib/url-state-machine.d.ts +0 -24
  381. package/lib/utils/url/whatwg-url/lib/url-state-machine.js +0 -1238
  382. package/lib/utils/url/whatwg-url/lib/urlencoded.js +0 -162
  383. package/lib/utils/url/whatwg-url/lib/utils.js +0 -101
  384. package/src/entities/ActionAuth.ts +0 -50
  385. package/src/entities/I18n.ts +0 -53
  386. package/src/entities/Log.ts +0 -62
  387. package/src/entities/Modi.ts +0 -107
  388. package/src/entities/ModiEntity.ts +0 -35
  389. package/src/entities/Oper.ts +0 -115
  390. package/src/entities/OperEntity.ts +0 -36
  391. package/src/entities/Path.ts +0 -56
  392. package/src/entities/Relation.ts +0 -53
  393. package/src/entities/RelationAuth.ts +0 -53
  394. package/src/entities/User.ts +0 -85
  395. package/src/entities/UserEntityClaim.ts +0 -41
  396. package/src/entities/UserEntityGrant.ts +0 -33
  397. package/src/entities/UserRelation.ts +0 -60
  398. /package/es/{utils/url/whatwg-url/lib/URL.d.ts → base-app-domain/LocalizedContent/_baseSchema.js} +0 -0
  399. /package/es/utils/url/{whatwg-url/lib/URLSearchParams.d.ts → urlObject.js} +0 -0
  400. /package/lib/{store/diffSchema.js → base-app-domain/LocalizedContent/_baseSchema.js} +0 -0
@@ -1,12 +1,30 @@
1
1
  import PathLib from 'path';
2
- import assert from 'assert';
2
+ import { assert } from '../utils/assert';
3
3
  import { writeFileSync, readdirSync, mkdirSync, existsSync, realpathSync, readFileSync } from 'fs';
4
4
  import { emptydirSync } from 'fs-extra';
5
- import { assign, cloneDeep, difference, intersection, keys, uniq, uniqBy, flatten } from 'lodash';
5
+ import { assign, cloneDeep, difference, intersection, keys, uniq, uniqBy, flatten } from '../utils/toolkit';
6
6
  import * as ts from 'typescript';
7
7
  const { factory } = ts;
8
- import { ACTION_CONSTANT_IN_OAK_DOMAIN, TYPE_PATH_IN_OAK_DOMAIN, RESERVED_ENTITY_NAMES, STRING_LITERAL_MAX_LENGTH, NUMERICAL_LITERL_DEFAULT_PRECISION, NUMERICAL_LITERL_DEFAULT_SCALE, INT_LITERL_DEFAULT_WIDTH, LIB_OAK_DOMAIN, isAtDomainOutput, setCompilerOutputOptions, ENTITY_NAME_MAX_LENGTH, } from './env';
8
+ import { ACTION_CONSTANT_IN_OAK_DOMAIN, TYPE_PATH_IN_OAK_DOMAIN, RESERVED_ENTITY_NAMES, STRING_LITERAL_MAX_LENGTH, NUMERICAL_LITERL_DEFAULT_PRECISION, NUMERICAL_LITERL_DEFAULT_SCALE, INT_LITERL_DEFAULT_WIDTH, LIB_OAK_DOMAIN, isAtDomainOutput, setCompilerOutputOptions, ENTITY_NAME_MAX_LENGTH } from "./env";
9
9
  import { firstLetterLowerCase, firstLetterUpperCase } from '../utils/string';
10
+ import { getEntityNameFromSourceFile, getRuntimeActionDefMetadata, getRuntimeActionDefInitializers, getRuntimeInitializer, listEntitySourceFiles, } from './entitySource';
11
+ import { collectEntityDescEnumAttrs, hasTypeAliasDeclaration, hasTypeAliasOrEnumDeclaration, tryGetStringLiteralValuesFromTypeNode, } from './entityDescEnum';
12
+ let currentSchemaBuilderProjectOptions;
13
+ function resolveSchemaBuilderProjectOptions(options) {
14
+ const pwd = PathLib.resolve(options?.pwd || process.cwd());
15
+ return {
16
+ pwd,
17
+ configFile: options?.configFile
18
+ ? PathLib.resolve(pwd, options.configFile)
19
+ : undefined,
20
+ };
21
+ }
22
+ function getCurrentSchemaBuilderProjectOptions() {
23
+ return currentSchemaBuilderProjectOptions || resolveSchemaBuilderProjectOptions();
24
+ }
25
+ function getCurrentProjectPwd() {
26
+ return getCurrentSchemaBuilderProjectOptions().pwd;
27
+ }
10
28
  const Schema = {};
11
29
  const OneToMany = {};
12
30
  const ManyToOne = {};
@@ -15,6 +33,11 @@ const ReversePointerRelations = {};
15
33
  const ReferenceSchemaDescriptorCache = {};
16
34
  const PrinterSourceFile = ts.createSourceFile('__oak_printer__.ts', '', ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
17
35
  const StatementSourceFileMap = new WeakMap();
36
+ function clearReferenceSchemaDescriptorCache() {
37
+ Object.keys(ReferenceSchemaDescriptorCache).forEach((key) => {
38
+ delete ReferenceSchemaDescriptorCache[key];
39
+ });
40
+ }
18
41
  const ActionImportStatements = () => [
19
42
  factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("ActionDef"))])), factory.createStringLiteral(`${TYPE_PATH_IN_OAK_DOMAIN()}Action`), undefined),
20
43
  factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
@@ -85,15 +108,21 @@ function createForeignRef(entity, foreignKey, ref) {
85
108
  function createIndexedForeignRef(foreignEntity, ref) {
86
109
  return factory.createIndexedAccessTypeNode(factory.createTypeReferenceNode(factory.createIdentifier(foreignEntity), undefined), factory.createLiteralTypeNode(factory.createStringLiteral(ref)));
87
110
  }
111
+ function createStringLiteralUnionType(values) {
112
+ const literalTypes = values.map((value) => factory.createLiteralTypeNode(factory.createStringLiteral(value)));
113
+ return literalTypes.length === 1
114
+ ? literalTypes[0]
115
+ : factory.createUnionTypeNode(literalTypes);
116
+ }
88
117
  function formatTsDiagnostic(diagnostic) {
89
118
  return ts.formatDiagnostic(diagnostic, {
90
119
  getCanonicalFileName: (fileName) => fileName,
91
- getCurrentDirectory: process.cwd,
120
+ getCurrentDirectory: getCurrentProjectPwd,
92
121
  getNewLine: () => '\n',
93
122
  });
94
123
  }
95
- function findNearestTsConfig(startPath) {
96
- let current = existsSync(startPath) ? realpathSync(startPath) : PathLib.resolve(process.cwd(), startPath);
124
+ function findNearestTsConfig(startPath, pwd = getCurrentProjectPwd()) {
125
+ let current = existsSync(startPath) ? realpathSync(startPath) : PathLib.resolve(pwd, startPath);
97
126
  if (!ts.sys.directoryExists(current)) {
98
127
  current = PathLib.dirname(current);
99
128
  }
@@ -109,8 +138,11 @@ function findNearestTsConfig(startPath) {
109
138
  current = parent;
110
139
  }
111
140
  }
112
- function findNearestPackageJson(startPath) {
113
- let current = existsSync(startPath) ? realpathSync(startPath) : PathLib.resolve(process.cwd(), startPath);
141
+ function resolveTsConfigPath(startPath, projectOptions = getCurrentSchemaBuilderProjectOptions()) {
142
+ return projectOptions.configFile || findNearestTsConfig(startPath, projectOptions.pwd);
143
+ }
144
+ function findNearestPackageJson(startPath, pwd = getCurrentProjectPwd()) {
145
+ let current = existsSync(startPath) ? realpathSync(startPath) : PathLib.resolve(pwd, startPath);
114
146
  if (!ts.sys.directoryExists(current)) {
115
147
  current = PathLib.dirname(current);
116
148
  }
@@ -127,8 +159,7 @@ function findNearestPackageJson(startPath) {
127
159
  }
128
160
  }
129
161
  let currentProjectPathAliasesCache;
130
- function getPathAliasesFromTsConfig(startPath) {
131
- const tsconfigPath = findNearestTsConfig(startPath);
162
+ function getPathAliasesFromTsConfig(tsconfigPath) {
132
163
  if (!tsconfigPath) {
133
164
  return new Set();
134
165
  }
@@ -144,13 +175,16 @@ function getPathAliasesFromTsConfig(startPath) {
144
175
  return new Set(Object.keys(parsedConfig.options.paths || {}));
145
176
  }
146
177
  function getCurrentProjectPathAliases() {
147
- const cwd = process.cwd();
148
- if (currentProjectPathAliasesCache?.cwd === cwd) {
178
+ const projectOptions = getCurrentSchemaBuilderProjectOptions();
179
+ const tsconfigPath = resolveTsConfigPath(projectOptions.pwd, projectOptions);
180
+ if (currentProjectPathAliasesCache?.pwd === projectOptions.pwd &&
181
+ currentProjectPathAliasesCache.tsconfigPath === tsconfigPath) {
149
182
  return currentProjectPathAliasesCache.aliases;
150
183
  }
151
- const aliases = getPathAliasesFromTsConfig(cwd);
184
+ const aliases = getPathAliasesFromTsConfig(tsconfigPath);
152
185
  currentProjectPathAliasesCache = {
153
- cwd,
186
+ pwd: projectOptions.pwd,
187
+ tsconfigPath,
154
188
  aliases,
155
189
  };
156
190
  return aliases;
@@ -211,13 +245,14 @@ function resolveExistingImportTargetPath(sourceFilePath, importPath) {
211
245
  return existedPath ? realpathSync(existedPath) : basePath;
212
246
  }
213
247
  function isSourceFileFromAnotherPackage(sourceFilePath) {
214
- const currentPackageJson = findNearestPackageJson(process.cwd());
248
+ const pwd = getCurrentProjectPwd();
249
+ const currentPackageJson = findNearestPackageJson(pwd);
215
250
  if (!currentPackageJson) {
216
251
  return false;
217
252
  }
218
253
  const normalizedSourceFilePath = existsSync(sourceFilePath)
219
254
  ? realpathSync(sourceFilePath)
220
- : PathLib.resolve(process.cwd(), sourceFilePath);
255
+ : PathLib.resolve(pwd, sourceFilePath);
221
256
  const sourcePackageJson = findNearestPackageJson(normalizedSourceFilePath);
222
257
  return !!sourcePackageJson && currentPackageJson !== sourcePackageJson;
223
258
  }
@@ -229,7 +264,7 @@ function tryResolveExternalPackageAliasImport(sourceFilePath, importPath) {
229
264
  return;
230
265
  }
231
266
  const normalizedSourceFilePath = existsSync(sourceFilePath) ? realpathSync(sourceFilePath) : sourceFilePath;
232
- const currentPackageJson = findNearestPackageJson(process.cwd());
267
+ const currentPackageJson = findNearestPackageJson(getCurrentProjectPwd());
233
268
  const sourcePackageJson = findNearestPackageJson(normalizedSourceFilePath);
234
269
  if (!currentPackageJson || !sourcePackageJson || currentPackageJson === sourcePackageJson) {
235
270
  return;
@@ -283,8 +318,8 @@ function tryResolveLegacyOakDomainImport(importPath) {
283
318
  return `${LIB_OAK_DOMAIN}/lib/${importPath.slice('@oak-domain/'.length)}`;
284
319
  }
285
320
  }
286
- function getCompilerOptions(inputDir) {
287
- const tsconfigPath = findNearestTsConfig(inputDir);
321
+ function getCompilerOptions(inputDir, projectOptions) {
322
+ const tsconfigPath = resolveTsConfigPath(inputDir, projectOptions);
288
323
  if (!tsconfigPath) {
289
324
  return {
290
325
  allowJs: true,
@@ -465,6 +500,34 @@ function addImportedFrom(moduleName, name, node, relativePath) {
465
500
  });
466
501
  }
467
502
  }
503
+ function getTypeReferenceName(typeNode) {
504
+ if (ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName)) {
505
+ return typeNode.typeName.text;
506
+ }
507
+ return undefined;
508
+ }
509
+ function collectImportedActionOrStateAliasReferences(moduleName, filename, typeNode, program, relativePath) {
510
+ const checker = program.getTypeChecker();
511
+ const collect = (node) => {
512
+ const typeName = getTypeReferenceName(node);
513
+ if (!typeName || (!typeName.endsWith('Action') && !typeName.endsWith('State'))) {
514
+ return;
515
+ }
516
+ const symbol = checker.getSymbolAtLocation(node.typeName);
517
+ const declaration = symbol?.getDeclarations()?.[0];
518
+ if (!declaration || !ts.isImportSpecifier(declaration)) {
519
+ return;
520
+ }
521
+ const importDeclaration = declaration.parent.parent.parent;
522
+ assert(ts.isImportDeclaration(importDeclaration), `未找到${filename}中${typeName}的importDeclaration`);
523
+ addImportedFrom(moduleName, declaration.name.text, importDeclaration, relativePath);
524
+ };
525
+ if (ts.isUnionTypeNode(typeNode)) {
526
+ typeNode.types.forEach(collect);
527
+ return;
528
+ }
529
+ collect(typeNode);
530
+ }
468
531
  /**
469
532
  * 计算编译后文件的正确导入路径
470
533
  * @param sourceFilePath 源文件路径(相对于项目根目录),例如: 'src/entities/User.ts'
@@ -516,7 +579,7 @@ function resolveCollectedImportPath(sourceFilePath, outputFilePath, importPath,
516
579
  if (!sourceFilePath) {
517
580
  return importPath;
518
581
  }
519
- return resolveCompiledImportPath(PathLib.relative(process.cwd(), sourceFilePath), PathLib.relative(process.cwd(), outputFilePath), importPath, '.', relativePath);
582
+ return resolveCompiledImportPath(PathLib.relative(getCurrentProjectPwd(), sourceFilePath), PathLib.relative(getCurrentProjectPwd(), outputFilePath), importPath, '.', relativePath);
520
583
  }
521
584
  function analyzeExternalAttrImport(node, program, importAttrFrom, relativePath) {
522
585
  const checker = program.getTypeChecker();
@@ -572,23 +635,9 @@ function analyzeExternalAttrImport(node, program, importAttrFrom, relativePath)
572
635
  function tryGetStringLiteralValues(moduleName, filename, obj, node, program, relativePath) {
573
636
  const checker = program.getTypeChecker();
574
637
  const symbol = checker.getSymbolAtLocation(node.typeName);
575
- let declaration = symbol?.getDeclarations()[0];
576
- /* const typee = checker.getDeclaredTypeOfSymbol(symbol!);
577
-
578
- const declaration = typee.aliasSymbol!.getDeclarations()![0]; */
579
- const values = [];
580
- if (ts.isImportSpecifier(declaration)) {
581
- const typee = checker.getDeclaredTypeOfSymbol(symbol);
582
- if (typee.isStringLiteral()) {
583
- values.push(typee.value);
584
- }
585
- else if (typee.isUnion()) {
586
- values.push(...typee.types.map(ele => {
587
- if (ele.isStringLiteral()) {
588
- return ele.value;
589
- }
590
- }).filter(ele => !!ele));
591
- }
638
+ const declaration = symbol?.getDeclarations()?.[0];
639
+ const values = tryGetStringLiteralValuesFromTypeNode(node, checker);
640
+ if (declaration && ts.isImportSpecifier(declaration)) {
592
641
  if (['state', 'action'].includes(obj)) {
593
642
  assert(values.length > 0, `${filename}中的${obj} ${node.typeName.getText()}未定义`);
594
643
  const importDeclartion = declaration.parent.parent.parent;
@@ -596,33 +645,24 @@ function tryGetStringLiteralValues(moduleName, filename, obj, node, program, rel
596
645
  addImportedFrom(moduleName, declaration.name.text, importDeclartion, relativePath);
597
646
  }
598
647
  }
599
- else if (ts.isTypeAliasDeclaration(declaration)) {
600
- // 本地定义的type
601
- const { name, type } = declaration;
602
- if (ts.isUnionTypeNode(type)) {
603
- values.push(...(type.types.map(ele => {
604
- if (ts.isLiteralTypeNode(ele)) {
605
- return checkStringLiteralLegal(filename, obj, name.text, ele);
606
- }
607
- else if (ts.isTypeReferenceNode(ele)) {
608
- return tryGetStringLiteralValues(moduleName, filename, obj, ele, program, relativePath);
609
- }
610
- else {
611
- throw new Error(`暂时不能处理的type${ele.getText()}`);
612
- }
613
- })).flat());
614
- }
615
- else if (ts.isLiteralTypeNode(type)) {
616
- const action = checkStringLiteralLegal(filename, obj, name.text, type);
617
- values.push(action);
618
- }
648
+ else if (declaration && ts.isTypeAliasDeclaration(declaration)) {
619
649
  if (['state', 'action'].includes(obj)) {
620
650
  assert(values.length > 0, `${filename}中的${obj} ${node.typeName.getText()}未定义`);
621
- const ast = ActionAsts[moduleName];
622
651
  addImportedFrom(moduleName, declaration.name.text, './', relativePath);
623
652
  }
624
653
  }
625
- return values;
654
+ else if (['state', 'action'].includes(obj) && ts.isIdentifier(node.typeName)) {
655
+ const localName = node.typeName.text;
656
+ const declarationSourceFile = node.getSourceFile();
657
+ if (hasTypeAliasOrEnumDeclaration(declarationSourceFile, localName)) {
658
+ assert(values.length > 0, `${filename}中的${obj} ${node.typeName.getText()}未定义`);
659
+ addImportedFrom(moduleName, localName, './', relativePath);
660
+ }
661
+ }
662
+ return uniq(values);
663
+ }
664
+ function createStringUnionTypeNode(values) {
665
+ return factory.createUnionTypeNode(values.map((value) => factory.createLiteralTypeNode(factory.createStringLiteral(value))));
626
666
  }
627
667
  const RESERVED_ACTION_NAMES = ['GenericAction', 'ParticularAction', 'ExcludeRemoveAction', 'ExcludeUpdateAction', 'ReadOnlyAction', 'AppendOnlyAction', 'RelationAction'];
628
668
  import { appendOnlyActions, excludeRemoveActions, excludeUpdateActions, genericActions, readOnlyActions, relationActions, } from '../actions/action';
@@ -695,20 +735,45 @@ function dealWithActionTypeNode(moduleName, filename, actionTypeNode, program, s
695
735
  });
696
736
  pushStatementIntoActionAst(moduleName, factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("actions"), undefined, undefined, factory.createArrayLiteralExpression(actionTexts.map(ele => factory.createStringLiteral(ele)), false))], ts.NodeFlags.Const)), sourceFile);
697
737
  }
698
- function dealWithActionDefInitializer(moduleName, initializer, program, relativePath) {
738
+ function registerRuntimeImport(moduleName, importReference, relativePath) {
739
+ const ast = ActionAsts[moduleName];
740
+ assert(ast, `${moduleName}中的${importReference.name}未找到ActionAst`);
741
+ assign(ast.importActionDefFrom, {
742
+ [importReference.name]: [
743
+ importReference.moduleSpecifier,
744
+ importReference.propertyName,
745
+ importReference.sourceFilePath,
746
+ relativePath,
747
+ ],
748
+ });
749
+ }
750
+ function dealWithActionDefInitializer(moduleName, initializer, program, relativePath, runtimeImportReference, runtimeHasIs) {
699
751
  if (ts.isIdentifier(initializer) || ts.isCallExpression(initializer)) {
700
752
  // 是从别处的引用,注入到importActionDefFrom
701
753
  const checker = program.getTypeChecker();
702
754
  const identifier = ts.isIdentifier(initializer) ? initializer : initializer.expression;
703
755
  assert(ts.isIdentifier(identifier), "ActionDef的initializer不是一个Identifier");
704
756
  const symbol = checker.getSymbolAtLocation(identifier);
705
- const declaration = symbol?.getDeclarations()[0];
706
- assert(ts.isImportSpecifier(declaration), "ActionDef的initializer不是一个ImportSpecifier");
707
- const importDeclartion = declaration.parent.parent.parent;
708
- addImportedFrom(moduleName, identifier.text, importDeclartion, relativePath);
757
+ const declaration = symbol?.getDeclarations()?.[0];
758
+ let importSpecifierDeclaration;
759
+ if (declaration) {
760
+ assert(ts.isImportSpecifier(declaration), "ActionDef的initializer不是一个ImportSpecifier");
761
+ importSpecifierDeclaration = declaration;
762
+ const importDeclartion = declaration.parent.parent.parent;
763
+ addImportedFrom(moduleName, identifier.text, importDeclartion, relativePath);
764
+ }
765
+ else if (runtimeImportReference) {
766
+ registerRuntimeImport(moduleName, runtimeImportReference, relativePath);
767
+ }
768
+ else {
769
+ assert(false, "ActionDef的initializer不是一个ImportSpecifier");
770
+ }
771
+ if (!symbol) {
772
+ return !!runtimeHasIs;
773
+ }
709
774
  // 如果是函数调用(CallExpression),无法在编译时确定is,直接返回false
710
775
  if (ts.isCallExpression(initializer)) {
711
- return false;
776
+ return !!runtimeHasIs;
712
777
  }
713
778
  // 如果是直接引用(Identifier),尝试分析外部引用的actionDef中的is
714
779
  const aliasedSymbol = checker.getAliasedSymbol(symbol);
@@ -732,7 +797,7 @@ function dealWithActionDefInitializer(moduleName, initializer, program, relative
732
797
  // 获取原始的导出名称(处理 as 别名的情况)
733
798
  // 如果有 propertyName,说明使用了 as,应该使用 propertyName
734
799
  // 否则使用 name
735
- const exportName = declaration.propertyName?.text || declaration.name.text;
800
+ const exportName = importSpecifierDeclaration?.propertyName?.text || importSpecifierDeclaration?.name.text || identifier.text;
736
801
  // 尝试从JS文件中解析is属性
737
802
  const hasIs = tryParseIsFromJsFile(jsContent, exportName);
738
803
  return hasIs;
@@ -865,7 +930,7 @@ function checkLocaleEnumAttrs(node, attrs, filename) {
865
930
  throw new Error(`${filename}中缺少了对${lack.join(',')}属性的locale定义`);
866
931
  }
867
932
  }
868
- function checkLocaleExpressionPropertyExists(root, attr, exists, filename) {
933
+ function checkLocaleExpressionPropertyExists(root, attr, required, allowed, filename) {
869
934
  const { properties } = root;
870
935
  properties.forEach((ele) => {
871
936
  assert(ts.isPropertyAssignment(ele) && (ts.isIdentifier(ele.name) || ts.isStringLiteral(ele.name)) && ts.isObjectLiteralExpression(ele.initializer));
@@ -874,14 +939,35 @@ function checkLocaleExpressionPropertyExists(root, attr, exists, filename) {
874
939
  assert(ts.isPropertyAssignment(ele2) && ts.isIdentifier(ele2.name), 'locale定义中的属性必须是identifier');
875
940
  return ele2.name.text === attr;
876
941
  });
877
- if (exists && !pp) {
942
+ if (required && !pp) {
878
943
  throw new Error(`${filename}中的locale定义中的${ele.name.text}中缺少了${attr}的定义`);
879
944
  }
880
- else if (!exists && pp) {
945
+ else if (!allowed && pp) {
881
946
  throw new Error(`${filename}中的locale定义中的${ele.name.text}中有多余的${attr}定义`);
882
947
  }
883
948
  });
884
949
  }
950
+ function hasLocaleSection(localeDef, attr) {
951
+ if (!localeDef) {
952
+ return false;
953
+ }
954
+ return Object.values(localeDef).some((value) => isLocaleObject(value) && isLocaleObject(value[attr]));
955
+ }
956
+ function getLocalEnumAttributeNames(localEnumAttrNames) {
957
+ return uniq(localEnumAttrNames);
958
+ }
959
+ function checkMergedLocaleEnumAttrs(localeDef, attrs, filename) {
960
+ if (attrs.length === 0) {
961
+ return;
962
+ }
963
+ Object.entries(localeDef).forEach(([locale, value]) => {
964
+ assert(isLocaleObject(value), `${filename}中的locale定义中的${locale}定义非法`);
965
+ const v = value.v;
966
+ if (!isLocaleObject(v)) {
967
+ throw new Error(`${filename}中的locale定义中的${locale}中缺少了v的定义`);
968
+ }
969
+ });
970
+ }
885
971
  function checkOwnLocaleAttrs(root, attrs, filename) {
886
972
  if (attrs.length === 0) {
887
973
  return;
@@ -911,6 +997,26 @@ function extractEntityDescLocale(expression, filename) {
911
997
  assert(ts.isPropertyAssignment(localesProperty) && ts.isObjectLiteralExpression(localesProperty.initializer), `「${filename}」中entityDesc的locales应该是属性声明`);
912
998
  return translateLocaleObject(localesProperty.initializer);
913
999
  }
1000
+ function readLocaleFromOakAppDomain(resolvedFileName) {
1001
+ const normalizedPath = PathLib.normalize(resolvedFileName);
1002
+ if (!normalizedPath.includes(`${PathLib.sep}entities${PathLib.sep}`)) {
1003
+ return;
1004
+ }
1005
+ const entityName = PathLib.basename(normalizedPath).replace(/\.d\.ts$/i, '').replace(/\.[^.]+$/i, '');
1006
+ const localeDir = PathLib.join(PathLib.dirname(PathLib.dirname(normalizedPath)), 'oak-app-domain', entityName, 'locales');
1007
+ if (!existsSync(localeDir)) {
1008
+ return;
1009
+ }
1010
+ const locale = {};
1011
+ readdirSync(localeDir).forEach((file) => {
1012
+ if (!file.endsWith('.json')) {
1013
+ return;
1014
+ }
1015
+ const language = file.replace(/\.json$/i, '');
1016
+ locale[language] = JSON.parse(readFileSync(PathLib.join(localeDir, file), 'utf8'));
1017
+ });
1018
+ return Object.keys(locale).length > 0 ? locale : undefined;
1019
+ }
914
1020
  /* function getStringEnumValues(filename: string, program: ts.Program, obj: string, node: ts.TypeReferenceNode) {
915
1021
  const checker = program.getTypeChecker();
916
1022
  const symbol = checker.getSymbolAtLocation(node.typeName);
@@ -1053,7 +1159,7 @@ function getSchemaAnalysisKey(pathName) {
1053
1159
  return process.platform === 'win32' ? normalizedPath.toLowerCase() : normalizedPath;
1054
1160
  }
1055
1161
  function normalizeDisplayPath(pathName) {
1056
- const relativePath = PathLib.relative(process.cwd(), pathName).replace(/\\/g, '/');
1162
+ const relativePath = PathLib.relative(getCurrentProjectPwd(), pathName).replace(/\\/g, '/');
1057
1163
  return relativePath || PathLib.basename(pathName);
1058
1164
  }
1059
1165
  function createRootOrigin(pathName) {
@@ -1248,7 +1354,7 @@ function createEmitSafePropertyName(name) {
1248
1354
  function createEmitSafePropertySignature(node) {
1249
1355
  return factory.createPropertySignature(undefined, createEmitSafePropertyName(node.name), node.questionToken ? factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, createEmitSafeTypeNode(node.type));
1250
1356
  }
1251
- function addSchemaAttrEntry(schemaAttrDict, attrName, node, origin, filename) {
1357
+ function addSchemaAttrEntry(schemaAttrDict, attrName, node, origin, filename, kind) {
1252
1358
  const existed = schemaAttrDict[attrName];
1253
1359
  if (existed) {
1254
1360
  throw new Error(buildAttrConflictMessage(filename, attrName, origin, existed.origin));
@@ -1256,8 +1362,66 @@ function addSchemaAttrEntry(schemaAttrDict, attrName, node, origin, filename) {
1256
1362
  schemaAttrDict[attrName] = {
1257
1363
  node: createEmitSafePropertySignature(node),
1258
1364
  origin,
1365
+ kind,
1366
+ };
1367
+ }
1368
+ function includesAllStringLiteralValues(values, previousValues) {
1369
+ return previousValues.every((value) => values.includes(value));
1370
+ }
1371
+ function hasSameStringLiteralValues(values, previousValues) {
1372
+ return values.length === previousValues.length && includesAllStringLiteralValues(values, previousValues);
1373
+ }
1374
+ function addActionDefStateSchemaAttr(schemaAttrDict, enumAttributes, attrName, node, values, origin, filename) {
1375
+ const existed = schemaAttrDict[attrName];
1376
+ if (existed?.kind === 'entityDescVirtualEnumAttr') {
1377
+ const previousValues = enumAttributes[attrName] || [];
1378
+ if (!includesAllStringLiteralValues(values, previousValues)) {
1379
+ throw new Error(buildAttrConflictMessage(filename, attrName, origin, existed.origin));
1380
+ }
1381
+ schemaAttrDict[attrName] = {
1382
+ node: createEmitSafePropertySignature(node),
1383
+ origin,
1384
+ };
1385
+ enumAttributes[attrName] = values;
1386
+ return;
1387
+ }
1388
+ addSchemaAttrEntry(schemaAttrDict, attrName, node, origin, filename);
1389
+ enumAttributes[attrName] = values;
1390
+ }
1391
+ function createEntityDescVirtualEnumPropertySignature(attrName, values) {
1392
+ return factory.createPropertySignature(undefined, factory.createIdentifier(attrName), undefined, createStringUnionTypeNode(values));
1393
+ }
1394
+ function replaceEntityDescVirtualEnumAttr(schemaAttrDict, attrName, values, origin) {
1395
+ schemaAttrDict[attrName] = {
1396
+ node: createEmitSafePropertySignature(createEntityDescVirtualEnumPropertySignature(attrName, values)),
1397
+ origin,
1398
+ kind: 'entityDescVirtualEnumAttr',
1259
1399
  };
1260
1400
  }
1401
+ function mergeEntityDescEnumAttr(schemaAttrDict, enumAttributes, attrName, values, origin, filename) {
1402
+ const existed = schemaAttrDict[attrName];
1403
+ if (existed) {
1404
+ const previousValues = enumAttributes[attrName] || [];
1405
+ if (existed.kind !== 'entityDescVirtualEnumAttr') {
1406
+ if (previousValues.length > 0 && !includesAllStringLiteralValues(values, previousValues)) {
1407
+ throw new Error(buildAttrConflictMessage(filename, attrName, origin, existed.origin));
1408
+ }
1409
+ enumAttributes[attrName] = values;
1410
+ return;
1411
+ }
1412
+ if (hasSameStringLiteralValues(values, previousValues)) {
1413
+ return;
1414
+ }
1415
+ if (includesAllStringLiteralValues(values, previousValues)) {
1416
+ replaceEntityDescVirtualEnumAttr(schemaAttrDict, attrName, values, origin);
1417
+ enumAttributes[attrName] = values;
1418
+ return;
1419
+ }
1420
+ throw new Error(buildAttrConflictMessage(filename, attrName, origin, existed.origin));
1421
+ }
1422
+ addSchemaAttrEntry(schemaAttrDict, attrName, createEntityDescVirtualEnumPropertySignature(attrName, values), origin, filename, 'entityDescVirtualEnumAttr');
1423
+ enumAttributes[attrName] = values;
1424
+ }
1261
1425
  function getEntityDescProperty(declaration, propertyName) {
1262
1426
  return declaration.properties.find((property) => ts.isPropertyAssignment(property) && ts.isIdentifier(property.name) && property.name.text === propertyName);
1263
1427
  }
@@ -1274,6 +1438,18 @@ function parseRecursiveDepthMetadata(declaration, filename) {
1274
1438
  assert(typeof recursiveDepth === 'number', `「${filename}」中的recursiveDepth必须是数字字面量`);
1275
1439
  return recursiveDepth;
1276
1440
  }
1441
+ function parseLocalizedContentMetadata(declaration, filename) {
1442
+ const localizedContent = readStaticValue(declaration, filename, 'entityDesc.localizedContent');
1443
+ assert(isStaticLiteralObject(localizedContent), `「${filename}」中的localizedContent必须是对象字面量`);
1444
+ const attributes = localizedContent.attributes;
1445
+ assert(Array.isArray(attributes) && attributes.every(ele => typeof ele === 'string'), `「${filename}」中的localizedContent.attributes必须是字符串数组`);
1446
+ const sourceLanguage = localizedContent.sourceLanguage;
1447
+ assert(sourceLanguage === undefined || typeof sourceLanguage === 'string', `「${filename}」中的localizedContent.sourceLanguage必须是字符串字面量`);
1448
+ return {
1449
+ attributes: attributes,
1450
+ sourceLanguage: sourceLanguage,
1451
+ };
1452
+ }
1277
1453
  function parseStyleMetadata(declaration, filename) {
1278
1454
  const style = readStaticValue(declaration, filename, 'entityDesc.style');
1279
1455
  assert(isStaticLiteralObject(style), `「${filename}」中的style必须是对象字面量`);
@@ -1383,9 +1559,10 @@ function mergeParsedIndexes(filename, indexes, preferCurrent = false) {
1383
1559
  }
1384
1560
  return;
1385
1561
  }
1386
- const sameAttributes = merged.find((item) => item.attributeKey === index.attributeKey);
1387
- if (sameAttributes) {
1388
- throw new Error(buildMetadataConflictMessage(filename, '索引', index.name, index.origin, sameAttributes.origin, index.attributes.map((attr) => attr.name).join(',')));
1562
+ const sameAttributes = merged.filter((item) => item.attributeKey === index.attributeKey);
1563
+ const sameTypeAttributes = sameAttributes.find((item) => item.isFulltext === index.isFulltext);
1564
+ if (sameTypeAttributes) {
1565
+ throw new Error(buildMetadataConflictMessage(filename, '索引', index.name, index.origin, sameTypeAttributes.origin, index.attributes.map((attr) => attr.name).join(',')));
1389
1566
  }
1390
1567
  const fulltextIndex = merged.find((item) => item.isFulltext);
1391
1568
  if (index.isFulltext && fulltextIndex && fulltextIndex.semanticKey !== index.semanticKey) {
@@ -1414,6 +1591,25 @@ function resolveInheritedScalarMetadata(filename, metadataType, entries) {
1414
1591
  });
1415
1592
  return resolved?.value;
1416
1593
  }
1594
+ function resolveInheritedLocalizedContentMetadata(filename, entries) {
1595
+ let resolved;
1596
+ entries.forEach((entry) => {
1597
+ if (!entry.value) {
1598
+ return;
1599
+ }
1600
+ if (!resolved) {
1601
+ resolved = {
1602
+ value: entry.value,
1603
+ origin: entry.origin,
1604
+ };
1605
+ return;
1606
+ }
1607
+ if (JSON.stringify(resolved.value) !== JSON.stringify(entry.value)) {
1608
+ throw new Error(buildMetadataConflictMessage(filename, 'localizedContent', '', entry.origin, resolved.origin));
1609
+ }
1610
+ });
1611
+ return resolved?.value;
1612
+ }
1417
1613
  function mergeInheritedStyle(filename, inheritedStyles, localStyle) {
1418
1614
  const result = {};
1419
1615
  const leafOrigins = {};
@@ -1495,7 +1691,7 @@ function normalizeStyleForEntity(moduleName, actionType, relations, hasActionDef
1495
1691
  }
1496
1692
  return Object.keys(nextStyle).length > 0 ? nextStyle : undefined;
1497
1693
  }
1498
- function getReferenceSchemaDescriptor(filename, schemaKey, sourceFile, relativePath) {
1694
+ function getReferenceSchemaDescriptor(filename, schemaKey, sourceFile, program, relativePath) {
1499
1695
  const cachedDescriptor = ReferenceSchemaDescriptorCache[schemaKey];
1500
1696
  if (cachedDescriptor) {
1501
1697
  return cachedDescriptor;
@@ -1508,7 +1704,9 @@ function getReferenceSchemaDescriptor(filename, schemaKey, sourceFile, relativeP
1508
1704
  let configuredActionType;
1509
1705
  let _static;
1510
1706
  let recursiveDepth;
1707
+ let localizedContent;
1511
1708
  let style;
1709
+ const entityDescEnumAttrs = {};
1512
1710
  ts.forEachChild(sourceFile, (node) => {
1513
1711
  if (ts.isImportDeclaration(node)) {
1514
1712
  analyzeImportDeclaration(node, referencedSchemas, [], filename, relativePath);
@@ -1526,27 +1724,39 @@ function getReferenceSchemaDescriptor(filename, schemaKey, sourceFile, relativeP
1526
1724
  }
1527
1725
  if (ts.isVariableStatement(node)) {
1528
1726
  node.declarationList.declarations.forEach((declaration) => {
1727
+ const declarationName = ts.isIdentifier(declaration.name) ? declaration.name.text : undefined;
1728
+ const runtimeInitializer = declarationName
1729
+ ? getRuntimeInitializer(sourceFile.fileName, declarationName)
1730
+ : undefined;
1731
+ const initializer = declaration.initializer || runtimeInitializer?.expression;
1529
1732
  const isEntityDesc = declaration.type
1530
1733
  && ts.isTypeReferenceNode(declaration.type)
1531
1734
  && ts.isIdentifier(declaration.type.typeName)
1532
1735
  && declaration.type.typeName.text === 'EntityDesc';
1533
- if (declaration.initializer && (isEntityDesc || (ts.isIdentifier(declaration.name) && declaration.name.text === 'entityDesc')) && ts.isObjectLiteralExpression(declaration.initializer)) {
1534
- locale = extractEntityDescLocale(declaration.initializer, filename);
1535
- const indexesProperty = getEntityDescProperty(declaration.initializer, 'indexes');
1736
+ if (initializer && (isEntityDesc || declarationName === 'entityDesc') && ts.isObjectLiteralExpression(initializer)) {
1737
+ if (isEntityDesc) {
1738
+ assign(entityDescEnumAttrs, collectEntityDescEnumAttrs(declaration, filename, program.getTypeChecker()));
1739
+ }
1740
+ locale = extractEntityDescLocale(initializer, filename);
1741
+ const indexesProperty = getEntityDescProperty(initializer, 'indexes');
1536
1742
  if (indexesProperty && ts.isArrayLiteralExpression(indexesProperty.initializer)) {
1537
1743
  indexesExpression = indexesProperty.initializer;
1538
1744
  }
1539
- const configurationProperty = getEntityDescProperty(declaration.initializer, 'configuration');
1745
+ const configurationProperty = getEntityDescProperty(initializer, 'configuration');
1540
1746
  if (configurationProperty && ts.isObjectLiteralExpression(configurationProperty.initializer)) {
1541
1747
  const metadata = parseConfigurationMetadata(configurationProperty.initializer, filename);
1542
1748
  configuredActionType = metadata.configuredActionType;
1543
1749
  _static = metadata.static;
1544
1750
  }
1545
- const recursiveDepthProperty = getEntityDescProperty(declaration.initializer, 'recursiveDepth');
1751
+ const recursiveDepthProperty = getEntityDescProperty(initializer, 'recursiveDepth');
1546
1752
  if (recursiveDepthProperty) {
1547
1753
  recursiveDepth = parseRecursiveDepthMetadata(recursiveDepthProperty.initializer, filename);
1548
1754
  }
1549
- const styleProperty = getEntityDescProperty(declaration.initializer, 'style');
1755
+ const localizedContentProperty = getEntityDescProperty(initializer, 'localizedContent');
1756
+ if (localizedContentProperty) {
1757
+ localizedContent = parseLocalizedContentMetadata(localizedContentProperty.initializer, filename);
1758
+ }
1759
+ const styleProperty = getEntityDescProperty(initializer, 'style');
1550
1760
  if (styleProperty && ts.isObjectLiteralExpression(styleProperty.initializer)) {
1551
1761
  style = parseStyleMetadata(styleProperty.initializer, filename);
1552
1762
  }
@@ -1554,16 +1764,50 @@ function getReferenceSchemaDescriptor(filename, schemaKey, sourceFile, relativeP
1554
1764
  });
1555
1765
  }
1556
1766
  });
1767
+ if (!locale) {
1768
+ const runtimeEntityDesc = getRuntimeInitializer(sourceFile.fileName, 'entityDesc');
1769
+ if (runtimeEntityDesc?.expression) {
1770
+ assert(ts.isObjectLiteralExpression(runtimeEntityDesc.expression), `「${filename}」中entityDesc的运行时定义应该是对象字面量`);
1771
+ locale = extractEntityDescLocale(runtimeEntityDesc.expression, filename);
1772
+ const indexesProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'indexes');
1773
+ if (indexesProperty && ts.isArrayLiteralExpression(indexesProperty.initializer)) {
1774
+ indexesExpression = indexesProperty.initializer;
1775
+ }
1776
+ const configurationProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'configuration');
1777
+ if (configurationProperty && ts.isObjectLiteralExpression(configurationProperty.initializer)) {
1778
+ const metadata = parseConfigurationMetadata(configurationProperty.initializer, filename);
1779
+ configuredActionType = metadata.configuredActionType;
1780
+ _static = metadata.static;
1781
+ }
1782
+ const recursiveDepthProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'recursiveDepth');
1783
+ if (recursiveDepthProperty) {
1784
+ recursiveDepth = parseRecursiveDepthMetadata(recursiveDepthProperty.initializer, filename);
1785
+ }
1786
+ const localizedContentProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'localizedContent');
1787
+ if (localizedContentProperty) {
1788
+ localizedContent = parseLocalizedContentMetadata(localizedContentProperty.initializer, filename);
1789
+ }
1790
+ const styleProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'style');
1791
+ if (styleProperty && ts.isObjectLiteralExpression(styleProperty.initializer)) {
1792
+ style = parseStyleMetadata(styleProperty.initializer, filename);
1793
+ }
1794
+ }
1795
+ }
1796
+ if (!locale) {
1797
+ locale = readLocaleFromOakAppDomain(sourceFile.fileName);
1798
+ }
1557
1799
  assert(schemaNode, `「${filename}」中缺少 Schema 定义。\n提示:每个实体文件必须包含 'export interface Schema extends EntityShape { ... }'`);
1558
1800
  const descriptor = {
1559
1801
  supportStatements,
1560
1802
  referencedSchemas,
1561
1803
  schemaNode,
1804
+ entityDescEnumAttrs,
1562
1805
  locale,
1563
1806
  indexesExpression,
1564
1807
  configuredActionType,
1565
1808
  static: _static,
1566
1809
  recursiveDepth,
1810
+ localizedContent,
1567
1811
  style,
1568
1812
  };
1569
1813
  ReferenceSchemaDescriptorCache[schemaKey] = descriptor;
@@ -1576,6 +1820,7 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe
1576
1820
  let toLog = false;
1577
1821
  const extendsFrom = [];
1578
1822
  const ownAttrNames = [];
1823
+ const localEnumAttrNames = [];
1579
1824
  const { members, heritageClauses } = node;
1580
1825
  assert(heritageClauses, `「${filename}」中的 Schema 定义错误:必须继承 EntityShape 或其他实体。\n` +
1581
1826
  `示例:export interface Schema extends EntityShape { ... }`);
@@ -1621,12 +1866,11 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe
1621
1866
  }
1622
1867
  }).filter((ele) => !!ele);
1623
1868
  const inheritedLocale = mergeLocaleData(...heritagedResult.map((ele) => ele.locale));
1624
- const inheritedIndexes = mergeParsedIndexes(filename, [
1625
- ...flatten(heritagedResult.map((ele) => ele.indexes)),
1626
- ...resolvePendingIndexes(schemaAttrDict, flatten(heritagedResult.map((ele) => ele.pendingLocalIndexes))),
1627
- ]);
1869
+ const inheritedPendingIndexes = flatten(heritagedResult.map((ele) => ele.pendingLocalIndexes));
1870
+ const inheritedIndexes = mergeParsedIndexes(filename, flatten(heritagedResult.map((ele) => ele.indexes)));
1628
1871
  const inheritedActionType = resolveInheritedScalarMetadata(filename, 'configuration.actionType', heritagedResult.map((ele) => ({ value: ele.configuredActionType, origin: ele.origin })));
1629
1872
  const inheritedRecursiveDepth = resolveInheritedScalarMetadata(filename, 'recursiveDepth', heritagedResult.map((ele) => ({ value: ele.recursiveDepth, origin: ele.origin })));
1873
+ const inheritedLocalizedContent = resolveInheritedLocalizedContentMetadata(filename, heritagedResult.map((ele) => ({ value: ele.localizedContent, origin: ele.origin })));
1630
1874
  const inheritedStyle = mergeInheritedStyle(filename, heritagedResult.map((ele) => ({ style: ele.style, origin: ele.origin })));
1631
1875
  const inheritedStatic = heritagedResult.some((ele) => ele.static);
1632
1876
  members.forEach((attrNode) => {
@@ -1670,6 +1914,7 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe
1670
1914
  const enumStringValues = tryGetStringLiteralValues(moduleName, filename, `attr-${attrName}`, type, program);
1671
1915
  if (enumStringValues.length > 0) {
1672
1916
  enumAttributes[attrName] = enumStringValues;
1917
+ localEnumAttrNames.push(attrName);
1673
1918
  }
1674
1919
  analyzeExternalAttrImport(type, program, importAttrFrom, relativePath);
1675
1920
  }
@@ -1703,9 +1948,11 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe
1703
1948
  if (ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0]) && ts.isStringLiteral(type.types[0].literal)) {
1704
1949
  const enumValues = type.types.map((ele) => checkStringLiteralLegal(filename, '属性', name.text, ele));
1705
1950
  enumAttributes[name.text] = enumValues;
1951
+ localEnumAttrNames.push(name.text);
1706
1952
  }
1707
1953
  else if (ts.isLiteralTypeNode(type) && ts.isStringLiteral(type.literal)) {
1708
1954
  enumAttributes[name.text] = [checkStringLiteralLegal(filename, '属性', name.text, type)];
1955
+ localEnumAttrNames.push(name.text);
1709
1956
  }
1710
1957
  }
1711
1958
  if (attrName === 'entity') {
@@ -1762,18 +2009,20 @@ function analyzeSchemaDefinition(node, moduleName, filename, path, program, refe
1762
2009
  toLog,
1763
2010
  extendsFrom,
1764
2011
  ownAttrNames,
2012
+ localEnumAttrNames,
1765
2013
  locale: inheritedLocale,
1766
2014
  indexes: inheritedIndexes,
1767
- pendingLocalIndexes: [],
2015
+ pendingLocalIndexes: inheritedPendingIndexes,
1768
2016
  configuredActionType: inheritedActionType,
1769
2017
  static: inheritedStatic,
1770
2018
  recursiveDepth: inheritedRecursiveDepth,
2019
+ localizedContent: inheritedLocalizedContent,
1771
2020
  style: inheritedStyle,
1772
2021
  origin: currentOrigin,
1773
2022
  };
1774
2023
  }
1775
2024
  function analyzeReferenceSchemaFile(moduleName, filename, path, sourceFile, program, referencedSchemas, schemaAttrDict, enumAttributes, importAttrFrom, visitedSchemaPaths, visitingSchemaPaths, currentOrigin, relativePath) {
1776
- const descriptor = getReferenceSchemaDescriptor(filename, currentOrigin.schemaKey, sourceFile, relativePath);
2025
+ const descriptor = getReferenceSchemaDescriptor(filename, currentOrigin.schemaKey, sourceFile, program, relativePath);
1777
2026
  descriptor.referencedSchemas.forEach((schema) => {
1778
2027
  if (!referencedSchemas.includes(schema)) {
1779
2028
  referencedSchemas.push(schema);
@@ -1783,6 +2032,9 @@ function analyzeReferenceSchemaFile(moduleName, filename, path, sourceFile, prog
1783
2032
  pushStatementIntoSchemaAst(moduleName, statement, sourceFile);
1784
2033
  });
1785
2034
  const result = analyzeSchemaDefinition(descriptor.schemaNode, moduleName, filename, path, program, referencedSchemas, schemaAttrDict, enumAttributes, importAttrFrom, visitedSchemaPaths, visitingSchemaPaths, currentOrigin, relativePath);
2035
+ Object.entries(descriptor.entityDescEnumAttrs).forEach(([attrName, values]) => {
2036
+ mergeEntityDescEnumAttr(schemaAttrDict, enumAttributes, attrName, values, currentOrigin, filename);
2037
+ });
1786
2038
  return {
1787
2039
  ...result,
1788
2040
  pendingLocalIndexes: descriptor.indexesExpression ? [
@@ -1798,15 +2050,34 @@ function analyzeReferenceSchemaFile(moduleName, filename, path, sourceFile, prog
1798
2050
  configuredActionType: descriptor.configuredActionType ?? result.configuredActionType,
1799
2051
  static: descriptor.static || result.static,
1800
2052
  recursiveDepth: descriptor.recursiveDepth !== undefined ? descriptor.recursiveDepth : result.recursiveDepth,
2053
+ localizedContent: descriptor.localizedContent || result.localizedContent,
1801
2054
  style: mergeInheritedStyle(filename, result.style ? [{ style: result.style, origin: currentOrigin }] : [], descriptor.style),
1802
2055
  origin: currentOrigin,
1803
2056
  };
1804
2057
  }
1805
- function analyzeEntity(filename, path, program, relativePath) {
1806
- const fullPath = PathLib.join(path, filename);
2058
+ function stripDeclareModifier(modifiers) {
2059
+ const nextModifiers = modifiers?.filter((modifier) => ts.isModifier(modifier) && modifier.kind !== ts.SyntaxKind.DeclareKeyword);
2060
+ return nextModifiers && nextModifiers.length > 0 ? nextModifiers : undefined;
2061
+ }
2062
+ function createVariableStatementWithInitializer(node, declaration, initializer) {
2063
+ return factory.createVariableStatement(stripDeclareModifier(node.modifiers), factory.createVariableDeclarationList([factory.createVariableDeclaration(declaration.name, declaration.exclamationToken, declaration.type, initializer)], node.declarationList.flags));
2064
+ }
2065
+ function createRuntimeActionDefVariableStatement(name, initializer, sourceFile) {
2066
+ const actionDefName = name.slice(0, name.length - 'ActionDef'.length);
2067
+ const sourceText = `${sourceFile.getFullText()}\nconst ${name}: ActionDef<${actionDefName}Action, ${actionDefName}State> = undefined as any;\n`;
2068
+ const syntheticSourceFile = ts.createSourceFile(sourceFile.fileName, sourceText, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
2069
+ const statement = syntheticSourceFile.statements[syntheticSourceFile.statements.length - 1];
2070
+ assert(ts.isVariableStatement(statement), `「${sourceFile.fileName}」中无法创建${name}声明`);
2071
+ const declaration = statement.declarationList.declarations[0];
2072
+ return createVariableStatementWithInitializer(statement, declaration, initializer);
2073
+ }
2074
+ function analyzeEntity(source, program, relativePath) {
2075
+ const filename = source.filename;
2076
+ const fullPath = source.typeFilePath;
2077
+ const path = PathLib.dirname(fullPath);
1807
2078
  const sourceFile = program.getSourceFile(fullPath);
1808
2079
  assert(sourceFile, `「${filename}」文件不存在`);
1809
- const moduleName = filename.split('.')[0];
2080
+ const moduleName = getEntityNameFromSourceFile(source);
1810
2081
  if (Schema.hasOwnProperty(moduleName)) {
1811
2082
  delete ActionAsts[moduleName];
1812
2083
  delete SchemaAsts[moduleName];
@@ -1826,6 +2097,7 @@ function analyzeEntity(filename, path, program, relativePath) {
1826
2097
  let configuredActionType;
1827
2098
  let _static = false;
1828
2099
  let recursiveDepth;
2100
+ let localizedContent;
1829
2101
  let localStyle;
1830
2102
  const enumAttributes = {};
1831
2103
  const importAttrFrom = {};
@@ -1833,9 +2105,12 @@ function analyzeEntity(filename, path, program, relativePath) {
1833
2105
  let localLocaleDef = undefined;
1834
2106
  let inheritedLocale = {};
1835
2107
  let inheritedIndexes = [];
2108
+ let inheritedPendingIndexes = [];
1836
2109
  let inheritedStyle;
1837
2110
  let inheritedRecursiveDepth;
2111
+ let inheritedLocalizedContent;
1838
2112
  let ownAttrNames = [];
2113
+ let localEnumAttrNames = [];
1839
2114
  let extendsFrom;
1840
2115
  const rootOrigin = createRootOrigin(fullPath);
1841
2116
  const visitedSchemaPaths = new Set();
@@ -1844,6 +2119,9 @@ function analyzeEntity(filename, path, program, relativePath) {
1844
2119
  // let reverseCascadeRelationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
1845
2120
  let toModi = false;
1846
2121
  let toLog = false;
2122
+ const runtimeActionDefInitializers = getRuntimeActionDefInitializers(fullPath);
2123
+ const processedActionDefNames = new Set();
2124
+ let runtimeOnlyActionDefsProcessed = false;
1847
2125
  ts.forEachChild(sourceFile, (node) => {
1848
2126
  if (ts.isImportDeclaration(node)) {
1849
2127
  analyzeImportDeclaration(node, referencedSchemas, [], filename, relativePath);
@@ -1865,10 +2143,14 @@ function analyzeEntity(filename, path, program, relativePath) {
1865
2143
  toModi = result.toModi;
1866
2144
  toLog = result.toLog;
1867
2145
  ownAttrNames = result.ownAttrNames;
2146
+ localEnumAttrNames = [...result.localEnumAttrNames];
1868
2147
  inheritedLocale = result.locale;
1869
- inheritedIndexes = mergeParsedIndexes(filename, [...result.indexes, ...resolvePendingIndexes(schemaAttrDict, result.pendingLocalIndexes)]);
2148
+ inheritedIndexes = result.indexes;
2149
+ inheritedPendingIndexes = result.pendingLocalIndexes;
1870
2150
  inheritedStyle = result.style;
1871
2151
  inheritedRecursiveDepth = result.recursiveDepth;
2152
+ inheritedLocalizedContent = result.localizedContent;
2153
+ localizedContent = inheritedLocalizedContent;
1872
2154
  if (result.configuredActionType) {
1873
2155
  actionType = result.configuredActionType;
1874
2156
  }
@@ -1991,12 +2273,13 @@ function analyzeEntity(filename, path, program, relativePath) {
1991
2273
  ]) : type), sourceFile);
1992
2274
  }
1993
2275
  else {
1994
- assert(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type), `文件${filename}中的${type.getText()}应该是字面量或引用类型`);
2276
+ assert(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type), `文件${filename}中的Action/State定义应该是字面量或引用类型`);
1995
2277
  pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode([
1996
2278
  type,
1997
2279
  factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
1998
2280
  ]) : type), sourceFile);
1999
2281
  }
2282
+ collectImportedActionOrStateAliasReferences(moduleName, filename, type, program, relativePath);
2000
2283
  }
2001
2284
  else if (beforeSchema) {
2002
2285
  // 本地规定的一些形状定义,直接使用
@@ -2005,7 +2288,7 @@ function analyzeEntity(filename, path, program, relativePath) {
2005
2288
  }
2006
2289
  if (ts.isVariableStatement(node)) {
2007
2290
  const { declarationList: { declarations } } = node;
2008
- const dealWithActionDef = (declaration) => {
2291
+ const dealWithActionDef = (declaration, statement, runtimeInitializer) => {
2009
2292
  checkActionDefNameConsistent(filename, declaration);
2010
2293
  const { typeArguments } = declaration.type;
2011
2294
  assert(typeArguments.length === 2, `文件${filename}中的action定义不是两个泛型参数`);
@@ -2016,13 +2299,96 @@ function analyzeEntity(filename, path, program, relativePath) {
2016
2299
  assert(ts.isTypeReferenceNode(stateNode), `文件${filename}中的action定义不是TypeReferenceNode`);
2017
2300
  const enumStateValues = tryGetStringLiteralValues(moduleName, filename, 'state', stateNode, program, relativePath);
2018
2301
  assert(enumStateValues.length > 0, `文件${filename}中的state${stateNode.typeName.text}定义不是字符串类型`);
2019
- pushStatementIntoActionAst(moduleName, node, sourceFile);
2020
- const isDefined = dealWithActionDefInitializer(moduleName, declaration.initializer, program, relativePath);
2021
2302
  assert(ts.isIdentifier(declaration.name));
2303
+ processedActionDefNames.add(declaration.name.text);
2304
+ const initializer = declaration.initializer || runtimeInitializer?.expression;
2305
+ assert(initializer, `「${filename}」中的${declaration.name.text}缺少运行时定义`);
2306
+ pushStatementIntoActionAst(moduleName, declaration.initializer ? statement : createVariableStatementWithInitializer(statement, declaration, initializer), sourceFile);
2307
+ const isDefined = dealWithActionDefInitializer(moduleName, initializer, program, relativePath, runtimeInitializer?.importReference, runtimeInitializer ? getRuntimeActionDefMetadata(runtimeInitializer)?.hasIs : undefined);
2022
2308
  const adName = declaration.name.text.slice(0, declaration.name.text.length - 9);
2023
2309
  const attr = adName.concat('State');
2024
- addSchemaAttrEntry(schemaAttrDict, firstLetterLowerCase(attr), factory.createPropertySignature(undefined, firstLetterLowerCase(attr), isDefined ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(attr)), rootOrigin, filename);
2025
- enumAttributes[firstLetterLowerCase(attr)] = enumStateValues;
2310
+ addActionDefStateSchemaAttr(schemaAttrDict, enumAttributes, firstLetterLowerCase(attr), factory.createPropertySignature(undefined, firstLetterLowerCase(attr), isDefined ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(attr)), enumStateValues, rootOrigin, filename);
2311
+ localEnumAttrNames.push(firstLetterLowerCase(attr));
2312
+ };
2313
+ const processRuntimeOnlyActionDefs = () => {
2314
+ if (runtimeOnlyActionDefsProcessed) {
2315
+ return;
2316
+ }
2317
+ runtimeOnlyActionDefsProcessed = true;
2318
+ const runtimeOnlyActionDefs = Object.entries(runtimeActionDefInitializers).filter(([name]) => !processedActionDefNames.has(name));
2319
+ const inferredActionDefs = runtimeOnlyActionDefs.map(([name, runtimeInitializer]) => {
2320
+ const actionDefName = name.slice(0, name.length - 'ActionDef'.length);
2321
+ return {
2322
+ name,
2323
+ runtimeInitializer,
2324
+ actionName: `${actionDefName}Action`,
2325
+ stateName: `${actionDefName}State`,
2326
+ stateAttr: firstLetterLowerCase(`${actionDefName}State`),
2327
+ metadata: getRuntimeActionDefMetadata(runtimeInitializer),
2328
+ };
2329
+ });
2330
+ const pushInferredActionAliasIfMissing = (typeName, values) => {
2331
+ if (hasTypeAliasDeclaration(sourceFile, typeName)) {
2332
+ return;
2333
+ }
2334
+ pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), undefined, createStringUnionTypeNode(values)), sourceFile);
2335
+ hasActionOrStateDef = true;
2336
+ };
2337
+ const registerInferredStateImport = (stateName) => {
2338
+ if (!ActionAsts[moduleName]?.importStateFrom[stateName]) {
2339
+ addImportedFrom(moduleName, stateName, './', relativePath);
2340
+ }
2341
+ };
2342
+ const pushRuntimeActionList = (actionValues) => {
2343
+ const actionTexts = [...genericActions];
2344
+ if (moduleName === 'User') {
2345
+ actionTexts.push(...relationActions);
2346
+ }
2347
+ actionTexts.push(...actionValues);
2348
+ const actionDict = {};
2349
+ actionTexts.forEach((action) => {
2350
+ assert(action.length < STRING_LITERAL_MAX_LENGTH, `「${filename}」中的 Action「${action}」命名长度超限。\n` +
2351
+ `当前长度:${action.length},最大允许:${STRING_LITERAL_MAX_LENGTH}`);
2352
+ assert(/^[a-z][A-Za-z]*$/.test(action), `「${filename}」中的 Action「${action}」命名格式错误:必须以小写字母开头且只能包含字母`);
2353
+ if (actionDict[action]) {
2354
+ throw new Error(`文件${filename}中,Action定义上的【${action}】动作存在同名`);
2355
+ }
2356
+ actionDict[action] = 1;
2357
+ });
2358
+ setActionNamesOnActionAst(moduleName, actionTexts, sourceFile);
2359
+ pushStatementIntoActionAst(moduleName, factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("actions"), undefined, undefined, factory.createArrayLiteralExpression(actionTexts.map((action) => factory.createStringLiteral(action)), false))], ts.NodeFlags.Const)), sourceFile);
2360
+ };
2361
+ const actionAliasNames = inferredActionDefs.map(({ actionName }) => actionName);
2362
+ const shouldInferActionAlias = !hasActionDef
2363
+ && inferredActionDefs.length > 0
2364
+ && inferredActionDefs.every(({ metadata }) => metadata && metadata.actions.length > 0 && metadata.states.length > 0);
2365
+ if (shouldInferActionAlias) {
2366
+ inferredActionDefs.forEach(({ actionName, stateName, metadata }) => {
2367
+ pushInferredActionAliasIfMissing(actionName, metadata.actions);
2368
+ pushInferredActionAliasIfMissing(stateName, metadata.states);
2369
+ registerInferredStateImport(stateName);
2370
+ });
2371
+ pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier('ParticularAction'), undefined, factory.createUnionTypeNode(actionAliasNames.map((name) => factory.createTypeReferenceNode(factory.createIdentifier(name))))), sourceFile);
2372
+ pushRuntimeActionList(flatten(inferredActionDefs.map(({ metadata }) => metadata.actions)));
2373
+ hasActionDef = true;
2374
+ }
2375
+ runtimeOnlyActionDefs.forEach(([name, runtimeInitializer]) => {
2376
+ if (processedActionDefNames.has(name)) {
2377
+ return;
2378
+ }
2379
+ const inferred = inferredActionDefs.find((item) => item.name === name);
2380
+ if (inferred?.metadata && !hasTypeAliasDeclaration(sourceFile, inferred.actionName) && !hasTypeAliasDeclaration(sourceFile, inferred.stateName)) {
2381
+ processedActionDefNames.add(name);
2382
+ const statement = createRuntimeActionDefVariableStatement(name, runtimeInitializer.expression, sourceFile);
2383
+ pushStatementIntoActionAst(moduleName, statement, sourceFile);
2384
+ addActionDefStateSchemaAttr(schemaAttrDict, enumAttributes, inferred.stateAttr, factory.createPropertySignature(undefined, inferred.stateAttr, inferred.metadata.hasIs ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(inferred.stateName)), inferred.metadata.states, rootOrigin, filename);
2385
+ localEnumAttrNames.push(inferred.stateAttr);
2386
+ return;
2387
+ }
2388
+ const statement = createRuntimeActionDefVariableStatement(name, runtimeInitializer.expression, sourceFile);
2389
+ const declaration = statement.declarationList.declarations[0];
2390
+ dealWithActionDef(declaration, statement, runtimeInitializer);
2391
+ });
2026
2392
  };
2027
2393
  const dealWithIndexes = (declaration) => {
2028
2394
  localPendingIndexes.push({
@@ -2035,26 +2401,17 @@ function analyzeEntity(filename, path, program, relativePath) {
2035
2401
  const dealWithLocales = (declaration) => {
2036
2402
  if (hasActionDef) {
2037
2403
  // 检查每种locale定义中都应该有'action'域
2038
- checkLocaleExpressionPropertyExists(declaration, 'action', true, filename);
2404
+ checkLocaleExpressionPropertyExists(declaration, 'action', true, true, filename);
2039
2405
  }
2040
2406
  else {
2041
- checkLocaleExpressionPropertyExists(declaration, 'action', false, filename);
2407
+ checkLocaleExpressionPropertyExists(declaration, 'action', false, hasLocaleSection(inheritedLocale, 'action'), filename);
2042
2408
  }
2043
2409
  if (relations) {
2044
2410
  // 检查每种locale定义中都应该有'r'域
2045
- checkLocaleExpressionPropertyExists(declaration, 'r', true, filename);
2411
+ checkLocaleExpressionPropertyExists(declaration, 'r', true, true, filename);
2046
2412
  }
2047
2413
  else {
2048
- checkLocaleExpressionPropertyExists(declaration, 'r', false, filename);
2049
- }
2050
- const allEnumStringAttrs = Object.keys(enumAttributes);
2051
- if (allEnumStringAttrs.length > 0) {
2052
- // 检查每种locale定义中都应该有'v'域
2053
- checkLocaleExpressionPropertyExists(declaration, 'v', true, filename);
2054
- }
2055
- else {
2056
- // 检查每种locale定义中都应该有'v'域
2057
- checkLocaleExpressionPropertyExists(declaration, 'v', false, filename);
2414
+ checkLocaleExpressionPropertyExists(declaration, 'r', false, hasLocaleSection(inheritedLocale, 'r'), filename);
2058
2415
  }
2059
2416
  localeExpression = declaration;
2060
2417
  localLocaleDef = translateLocaleObject(declaration);
@@ -2093,6 +2450,10 @@ function analyzeEntity(filename, path, program, relativePath) {
2093
2450
  assert(ts.isPropertyAssignment(recursiveDepthProperty), `「${filename}」中entityDesc的recursiveDepth应该是属性声明`);
2094
2451
  recursiveDepth = parseRecursiveDepthMetadata(recursiveDepthProperty.initializer, filename);
2095
2452
  }
2453
+ const localizedContentProperty = getEntityDescProperty(declaration, 'localizedContent');
2454
+ if (localizedContentProperty) {
2455
+ localizedContent = parseLocalizedContentMetadata(localizedContentProperty.initializer, filename);
2456
+ }
2096
2457
  const styleDescProperty = properties.find(ele => ts.isPropertyAssignment(ele) && ts.isIdentifier(ele.name) && ele.name.text === 'style');
2097
2458
  if (styleDescProperty) {
2098
2459
  assert(ts.isPropertyAssignment(styleDescProperty), `「${filename}」中entityDesc的style应该是属性声明`);
@@ -2112,7 +2473,11 @@ function analyzeEntity(filename, path, program, relativePath) {
2112
2473
  };
2113
2474
  declarations.forEach((declaration) => {
2114
2475
  if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'ActionDef') {
2115
- dealWithActionDef(declaration);
2476
+ assert(ts.isIdentifier(declaration.name), `「${filename}」中的ActionDef变量名必须是identifier`);
2477
+ if (processedActionDefNames.has(declaration.name.text)) {
2478
+ return;
2479
+ }
2480
+ dealWithActionDef(declaration, node, declaration.initializer ? undefined : getRuntimeInitializer(fullPath, declaration.name.text));
2116
2481
  }
2117
2482
  else if (declaration.type && (ts.isArrayTypeNode(declaration.type)
2118
2483
  && ts.isTypeReferenceNode(declaration.type.elementType)
@@ -2136,7 +2501,7 @@ function analyzeEntity(filename, path, program, relativePath) {
2136
2501
  assert(ts.isObjectLiteralExpression(initializer), `「${filename}」中locale定义应该是对象字面量`);
2137
2502
  const { properties } = initializer;
2138
2503
  assert(properties.length > 0, `${filename}至少需要有一种locale定义`);
2139
- const allEnumStringAttrs = Object.keys(enumAttributes);
2504
+ const localEnumStringAttrs = getLocalEnumAttributeNames(localEnumAttrNames);
2140
2505
  const { typeArguments } = type;
2141
2506
  assert(typeArguments &&
2142
2507
  ts.isTypeReferenceNode(typeArguments[0])
@@ -2158,13 +2523,15 @@ function analyzeEntity(filename, path, program, relativePath) {
2158
2523
  assert(ts.isLiteralTypeNode(typeArguments[2])
2159
2524
  && ts.isStringLiteral(typeArguments[2].literal), `${filename}中locale类型定义的第三个参数不是空字符串`);
2160
2525
  }
2161
- if (allEnumStringAttrs.length > 0) {
2526
+ if (localEnumStringAttrs.length > 0) {
2162
2527
  assert(ts.isTypeLiteralNode(typeArguments[3]), `${filename}中的locale类型定义的第四个参数不是{}`);
2163
- checkLocaleEnumAttrs(typeArguments[3], allEnumStringAttrs, filename);
2528
+ checkLocaleEnumAttrs(typeArguments[3], localEnumStringAttrs, filename);
2164
2529
  }
2165
2530
  else {
2166
2531
  assert(ts.isTypeLiteralNode(typeArguments[3]), `${filename}中的locale类型定义的第四个参数不是{}`);
2167
- assert(typeArguments[3].members.length == 0, `${filename}中locale类型定义的第四个参数不应存在相应的v定义`);
2532
+ if (!hasLocaleSection(inheritedLocale, 'v')) {
2533
+ assert(typeArguments[3].members.length == 0, `${filename}中locale类型定义的第四个参数不应存在相应的v定义`);
2534
+ }
2168
2535
  }
2169
2536
  dealWithLocales(initializer);
2170
2537
  }
@@ -2174,8 +2541,16 @@ function analyzeEntity(filename, path, program, relativePath) {
2174
2541
  dealWithConfiguration(declaration.initializer);
2175
2542
  }
2176
2543
  else if (declaration.type && ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'EntityDesc') {
2177
- const { initializer } = declaration;
2544
+ assert(ts.isIdentifier(declaration.name), `「${filename}」中的entityDesc变量名必须是identifier`);
2545
+ const runtimeInitializer = declaration.initializer ? undefined : getRuntimeInitializer(fullPath, declaration.name.text);
2546
+ const initializer = declaration.initializer || runtimeInitializer?.expression;
2178
2547
  assert(initializer, `「${filename}」中entityDesc的定义不应该为空`);
2548
+ processRuntimeOnlyActionDefs();
2549
+ const entityDescEnumAttrs = collectEntityDescEnumAttrs(declaration, filename, program.getTypeChecker());
2550
+ Object.entries(entityDescEnumAttrs).forEach(([attrName, values]) => {
2551
+ mergeEntityDescEnumAttr(schemaAttrDict, enumAttributes, attrName, values, rootOrigin, filename);
2552
+ });
2553
+ localEnumAttrNames.push(...Object.keys(entityDescEnumAttrs));
2179
2554
  dealWithEntityDesc(initializer);
2180
2555
  }
2181
2556
  else {
@@ -2184,6 +2559,101 @@ function analyzeEntity(filename, path, program, relativePath) {
2184
2559
  });
2185
2560
  }
2186
2561
  });
2562
+ if (!hasActionDef && !runtimeOnlyActionDefsProcessed && Object.keys(runtimeActionDefInitializers).length > 0) {
2563
+ const inferredActionDefs = Object.entries(runtimeActionDefInitializers).map(([name, runtimeInitializer]) => {
2564
+ const actionDefName = name.slice(0, name.length - 'ActionDef'.length);
2565
+ return {
2566
+ name,
2567
+ runtimeInitializer,
2568
+ actionName: `${actionDefName}Action`,
2569
+ stateName: `${actionDefName}State`,
2570
+ stateAttr: firstLetterLowerCase(`${actionDefName}State`),
2571
+ metadata: getRuntimeActionDefMetadata(runtimeInitializer),
2572
+ };
2573
+ }).filter((item) => item.metadata && item.metadata.actions.length > 0 && item.metadata.states.length > 0);
2574
+ if (inferredActionDefs.length > 0) {
2575
+ runtimeOnlyActionDefsProcessed = true;
2576
+ inferredActionDefs.forEach(({ actionName, stateName, metadata }) => {
2577
+ pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(actionName), undefined, createStringUnionTypeNode(metadata.actions)), sourceFile);
2578
+ pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(stateName), undefined, createStringUnionTypeNode(metadata.states)), sourceFile);
2579
+ if (!ActionAsts[moduleName]?.importStateFrom[stateName]) {
2580
+ addImportedFrom(moduleName, stateName, './', relativePath);
2581
+ }
2582
+ });
2583
+ pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier('ParticularAction'), undefined, factory.createUnionTypeNode(inferredActionDefs.map(({ actionName }) => factory.createTypeReferenceNode(factory.createIdentifier(actionName))))), sourceFile);
2584
+ const actionTexts = [
2585
+ ...genericActions,
2586
+ ...(moduleName === 'User' ? relationActions : []),
2587
+ ...flatten(inferredActionDefs.map(({ metadata }) => metadata.actions)),
2588
+ ];
2589
+ setActionNamesOnActionAst(moduleName, actionTexts, sourceFile);
2590
+ pushStatementIntoActionAst(moduleName, factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("actions"), undefined, undefined, factory.createArrayLiteralExpression(actionTexts.map((action) => factory.createStringLiteral(action)), false))], ts.NodeFlags.Const)), sourceFile);
2591
+ inferredActionDefs.forEach(({ name, runtimeInitializer, stateName, stateAttr, metadata }) => {
2592
+ processedActionDefNames.add(name);
2593
+ const statement = createRuntimeActionDefVariableStatement(name, runtimeInitializer.expression, sourceFile);
2594
+ pushStatementIntoActionAst(moduleName, statement, sourceFile);
2595
+ addActionDefStateSchemaAttr(schemaAttrDict, enumAttributes, stateAttr, factory.createPropertySignature(undefined, stateAttr, metadata.hasIs ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), factory.createTypeReferenceNode(stateName)), metadata.states, rootOrigin, filename);
2596
+ localEnumAttrNames.push(stateAttr);
2597
+ });
2598
+ hasActionDef = true;
2599
+ hasActionOrStateDef = true;
2600
+ }
2601
+ }
2602
+ if (!localLocaleDef || !localeExpression) {
2603
+ const runtimeEntityDesc = getRuntimeInitializer(fullPath, 'entityDesc');
2604
+ if (runtimeEntityDesc?.expression) {
2605
+ assert(ts.isObjectLiteralExpression(runtimeEntityDesc.expression), `「${filename}」中entityDesc的运行时定义应该是对象字面量`);
2606
+ const localesProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'locales');
2607
+ if (localesProperty) {
2608
+ assert(ts.isObjectLiteralExpression(localesProperty.initializer), `「${filename}」中entityDesc的locales应该是属性声明`);
2609
+ if (hasActionDef) {
2610
+ checkLocaleExpressionPropertyExists(localesProperty.initializer, 'action', true, true, filename);
2611
+ }
2612
+ else {
2613
+ checkLocaleExpressionPropertyExists(localesProperty.initializer, 'action', false, hasLocaleSection(inheritedLocale, 'action'), filename);
2614
+ }
2615
+ if (relations) {
2616
+ checkLocaleExpressionPropertyExists(localesProperty.initializer, 'r', true, true, filename);
2617
+ }
2618
+ else {
2619
+ checkLocaleExpressionPropertyExists(localesProperty.initializer, 'r', false, hasLocaleSection(inheritedLocale, 'r'), filename);
2620
+ }
2621
+ localeExpression = localesProperty.initializer;
2622
+ localLocaleDef = translateLocaleObject(localesProperty.initializer);
2623
+ }
2624
+ const indexesProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'indexes');
2625
+ if (indexesProperty) {
2626
+ assert(ts.isArrayLiteralExpression(indexesProperty.initializer), `「${filename}」中entityDesc的indexes应该是属性声明`);
2627
+ localPendingIndexes.push({
2628
+ filename,
2629
+ moduleName,
2630
+ declaration: indexesProperty.initializer,
2631
+ origin: rootOrigin,
2632
+ });
2633
+ }
2634
+ const configurationProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'configuration');
2635
+ if (configurationProperty) {
2636
+ assert(ts.isObjectLiteralExpression(configurationProperty.initializer), `「${filename}」中entityDesc的configuration应该是属性声明`);
2637
+ const metadata = parseConfigurationMetadata(configurationProperty.initializer, filename);
2638
+ configuredActionType = metadata.configuredActionType;
2639
+ if (configuredActionType) {
2640
+ actionType = configuredActionType;
2641
+ }
2642
+ if (metadata.static) {
2643
+ _static = true;
2644
+ }
2645
+ }
2646
+ const recursiveDepthProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'recursiveDepth');
2647
+ if (recursiveDepthProperty) {
2648
+ recursiveDepth = parseRecursiveDepthMetadata(recursiveDepthProperty.initializer, filename);
2649
+ }
2650
+ const styleDescProperty = getEntityDescProperty(runtimeEntityDesc.expression, 'style');
2651
+ if (styleDescProperty) {
2652
+ assert(ts.isObjectLiteralExpression(styleDescProperty.initializer), `「${filename}」中entityDesc的style应该是属性声明`);
2653
+ localStyle = parseStyleMetadata(styleDescProperty.initializer, filename);
2654
+ }
2655
+ }
2656
+ }
2187
2657
  // 要等configuration确定了actionType后再处理
2188
2658
  if (hasActionDef) {
2189
2659
  const actionDefNodes = [
@@ -2206,8 +2676,12 @@ function analyzeEntity(filename, path, program, relativePath) {
2206
2676
  }
2207
2677
  const schemaAttrs = Object.values(schemaAttrDict).map((entry) => entry.node);
2208
2678
  assert(schemaAttrs.length > 0, `对象${moduleName}没有任何属性定义`);
2679
+ const resolvedInheritedIndexes = mergeParsedIndexes(filename, [
2680
+ ...inheritedIndexes,
2681
+ ...resolvePendingIndexes(schemaAttrDict, inheritedPendingIndexes),
2682
+ ]);
2209
2683
  const localIndexes = resolvePendingIndexes(schemaAttrDict, localPendingIndexes);
2210
- const mergedIndexes = mergeParsedIndexes(filename, [...inheritedIndexes, ...localIndexes], true);
2684
+ const mergedIndexes = mergeParsedIndexes(filename, [...resolvedInheritedIndexes, ...localIndexes], true);
2211
2685
  const mergedStyle = mergeInheritedStyle(filename, inheritedStyle ? [{ style: inheritedStyle, origin: rootOrigin }] : [], localStyle);
2212
2686
  if (configuredActionType) {
2213
2687
  actionType = configuredActionType;
@@ -2220,6 +2694,8 @@ function analyzeEntity(filename, path, program, relativePath) {
2220
2694
  recursiveDepth = inheritedRecursiveDepth;
2221
2695
  }
2222
2696
  checkOwnLocaleAttrs(localeExpression, ownAttrNames, filename);
2697
+ const mergedLocale = mergeLocaleData(inheritedLocale, localLocaleDef);
2698
+ checkMergedLocaleEnumAttrs(mergedLocale, Object.keys(enumAttributes), filename);
2223
2699
  const schema = {
2224
2700
  schemaAttrs,
2225
2701
  sourceFile,
@@ -2230,7 +2706,7 @@ function analyzeEntity(filename, path, program, relativePath) {
2230
2706
  enumAttributes,
2231
2707
  importAttrFrom,
2232
2708
  extendsFrom,
2233
- locale: mergeLocaleData(inheritedLocale, localLocaleDef),
2709
+ locale: mergedLocale,
2234
2710
  };
2235
2711
  if (mergedIndexes.length > 0) {
2236
2712
  assign(schema, {
@@ -2243,6 +2719,11 @@ function analyzeEntity(filename, path, program, relativePath) {
2243
2719
  recursiveDepth,
2244
2720
  });
2245
2721
  }
2722
+ if (localizedContent) {
2723
+ assign(schema, {
2724
+ localizedContent,
2725
+ });
2726
+ }
2246
2727
  if (normalizedStyle) {
2247
2728
  assign(schema, {
2248
2729
  style: normalizedStyle,
@@ -2560,10 +3041,13 @@ function constructFilter(statements, entity) {
2560
3041
  case 'Int':
2561
3042
  case 'Uint':
2562
3043
  case 'Float':
2563
- case 'Double':
3044
+ case 'Double': {
3045
+ type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_NumberValue'));
3046
+ break;
3047
+ }
2564
3048
  case 'Price':
2565
3049
  case 'Decimal': {
2566
- type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_NumberValue'));
3050
+ type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_DecimalValue'));
2567
3051
  break;
2568
3052
  }
2569
3053
  case 'Boolean': {
@@ -2576,7 +3060,7 @@ function constructFilter(statements, entity) {
2576
3060
  }
2577
3061
  case 'SingleGeo':
2578
3062
  case 'Geo': {
2579
- // geo类型暂时只支持通过expr查询
3063
+ type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_GeoValue'));
2580
3064
  break;
2581
3065
  }
2582
3066
  case 'Object': {
@@ -2732,10 +3216,13 @@ function _constructOpFilter(statements, entity) {
2732
3216
  case 'Int':
2733
3217
  case 'Uint':
2734
3218
  case 'Float':
2735
- case 'Double':
3219
+ case 'Double': {
3220
+ type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_NumberValue'));
3221
+ break;
3222
+ }
2736
3223
  case 'Price':
2737
3224
  case 'Decimal': {
2738
- type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_NumberValue'));
3225
+ type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_DecimalValue'));
2739
3226
  break;
2740
3227
  }
2741
3228
  case 'Boolean': {
@@ -2748,7 +3235,7 @@ function _constructOpFilter(statements, entity) {
2748
3235
  }
2749
3236
  case 'SingleGeo':
2750
3237
  case 'Geo': {
2751
- // geo类型暂时只支持通过expr查询
3238
+ type2 = factory.createTypeReferenceNode(factory.createIdentifier('Q_GeoValue'));
2752
3239
  break;
2753
3240
  }
2754
3241
  case 'Object': {
@@ -4318,8 +4805,10 @@ const initialStatements = (level) => [
4318
4805
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_DateValue')),
4319
4806
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_BooleanValue')),
4320
4807
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_NumberValue')),
4808
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_DecimalValue')),
4321
4809
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_StringValue')),
4322
4810
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_EnumValue')),
4811
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_GeoValue')),
4323
4812
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('NodeId')),
4324
4813
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('MakeFilter')),
4325
4814
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('FulltextFilter')),
@@ -4371,8 +4860,10 @@ const initialStatements2 = () => [
4371
4860
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_DateValue')),
4372
4861
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_BooleanValue')),
4373
4862
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_NumberValue')),
4863
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_DecimalValue')),
4374
4864
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_StringValue')),
4375
4865
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_EnumValue')),
4866
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_GeoValue')),
4376
4867
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('NodeId')),
4377
4868
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('MakeFilter')),
4378
4869
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('FulltextFilter')),
@@ -4403,6 +4894,7 @@ const initialStatements3 = (level) => [
4403
4894
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExprOp')),
4404
4895
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('ExpressionKey')),
4405
4896
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('JsonFilter')),
4897
+ factory.createImportSpecifier(false, undefined, factory.createIdentifier('Q_GeoValue')),
4406
4898
  factory.createImportSpecifier(false, undefined, factory.createIdentifier('SubQueryPredicateMetadata')),
4407
4899
  ])), factory.createStringLiteral(`${TYPE_PATH_IN_OAK_DOMAIN(level)}Demand`)),
4408
4900
  factory.createImportDeclaration(undefined, factory.createImportClause(false, undefined, factory.createNamedImports([
@@ -4665,7 +5157,7 @@ function _outputBaseSchema(outputDir, printer) {
4665
5157
  // ===== 在这里进行路径转换 =====
4666
5158
  const outputFilePath = PathLib.join(outputDir, entity, '_baseSchema.ts'); // 输出文件路径
4667
5159
  // 使用路径解析算法计算新的导入路径
4668
- const newImportPath = resolveCompiledImportPath(PathLib.relative(process.cwd(), sourceFilePath), PathLib.relative(process.cwd(), outputFilePath), from, // 原始导入路径
5160
+ const newImportPath = resolveCompiledImportPath(PathLib.relative(getCurrentProjectPwd(), sourceFilePath), PathLib.relative(getCurrentProjectPwd(), outputFilePath), from, // 原始导入路径
4669
5161
  ".", relative);
4670
5162
  // console.log('resolve import path:', {
4671
5163
  // sourceFilePath: PathLib.relative(process.cwd(), sourceFilePath),
@@ -4825,24 +5317,30 @@ export function constructAttributes(entity) {
4825
5317
  ], true)));
4826
5318
  break;
4827
5319
  }
4828
- case 'Double':
4829
- case 'Float':
4830
5320
  case 'Decimal': {
4831
- if (['Double', 'Float'].includes(text)) {
4832
- console.warn(`${entity}对象中还有${text}类型定义,现在统一用Decimal进行存储`);
4833
- }
4834
5321
  attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("decimal")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
4835
5322
  factory.createPropertyAssignment(factory.createIdentifier("precision"), factory.createNumericLiteral(typeArguments[0].literal.text)),
4836
5323
  factory.createPropertyAssignment(factory.createIdentifier("scale"), factory.createNumericLiteral(typeArguments[1].literal.text))
4837
5324
  ], true)));
4838
5325
  break;
4839
5326
  }
5327
+ case 'Double':
5328
+ case 'Float': {
5329
+ attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral(text.toLowerCase())), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
5330
+ factory.createPropertyAssignment(factory.createIdentifier("precision"), factory.createNumericLiteral(typeArguments[0].literal.text)),
5331
+ factory.createPropertyAssignment(factory.createIdentifier("scale"), factory.createNumericLiteral(typeArguments[1].literal.text))
5332
+ ], true)));
5333
+ break;
5334
+ }
4840
5335
  case 'Boolean': {
4841
5336
  attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("boolean")));
4842
5337
  break;
4843
5338
  }
4844
5339
  case 'Price': {
4845
- attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("money")));
5340
+ attrAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("type"), factory.createStringLiteral("decimal")), factory.createPropertyAssignment(factory.createIdentifier("params"), factory.createObjectLiteralExpression([
5341
+ factory.createPropertyAssignment(factory.createIdentifier("precision"), factory.createNumericLiteral("32")),
5342
+ factory.createPropertyAssignment(factory.createIdentifier("scale"), factory.createNumericLiteral("10"))
5343
+ ], true)));
4846
5344
  break;
4847
5345
  }
4848
5346
  case 'Datetime': {
@@ -5002,7 +5500,7 @@ function outputStorage(outputDir, printer) {
5002
5500
  const entityAssignments = [];
5003
5501
  for (const entity in Schema) {
5004
5502
  const indexExpressions = [];
5005
- const { sourceFile, inModi, indexes, toModi, toLog, actionType, static: _static, recursiveDepth, relations } = Schema[entity];
5503
+ const { sourceFile, inModi, indexes, toModi, toLog, actionType, static: _static, recursiveDepth, localizedContent, relations } = Schema[entity];
5006
5504
  const fromSchemaSpecifiers = [
5007
5505
  factory.createImportSpecifier(false, undefined, factory.createIdentifier("OpSchema"))
5008
5506
  ];
@@ -5078,6 +5576,9 @@ function outputStorage(outputDir, printer) {
5078
5576
  if (recursiveDepth !== undefined) {
5079
5577
  propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("recursiveDepth"), factory.createNumericLiteral(recursiveDepth)));
5080
5578
  }
5579
+ if (localizedContent) {
5580
+ propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("localizedContent"), createLiteralExpression(localizedContent)));
5581
+ }
5081
5582
  /* if (relationHierarchy) {
5082
5583
  propertyAssignments.push(
5083
5584
  factory.createPropertyAssignment(
@@ -5745,22 +6246,24 @@ function outputStyleDict(outputDir, printer) {
5745
6246
  export const getAnalizedSchema = () => {
5746
6247
  return Schema;
5747
6248
  };
5748
- export function analyzeEntities(inputDir, relativePath, options) {
6249
+ export function analyzeEntities(inputDir, relativePath, options, projectOptions) {
5749
6250
  setCompilerOutputOptions(options);
5750
- const resolvedInputDir = PathLib.resolve(process.cwd(), inputDir);
6251
+ currentSchemaBuilderProjectOptions = resolveSchemaBuilderProjectOptions(projectOptions);
6252
+ clearReferenceSchemaDescriptorCache();
6253
+ const resolvedInputDir = PathLib.resolve(currentSchemaBuilderProjectOptions.pwd, inputDir);
5751
6254
  const absoluteInputDir = existsSync(resolvedInputDir) ? realpathSync(resolvedInputDir) : resolvedInputDir;
5752
- const files = readdirSync(absoluteInputDir);
5753
- const fullFilenames = files.map(ele => {
5754
- const entity = ele.slice(0, ele.indexOf('.'));
6255
+ const entitySources = listEntitySourceFiles(absoluteInputDir);
6256
+ const fullFilenames = entitySources.map((source) => {
6257
+ const entity = getEntityNameFromSourceFile(source);
5755
6258
  if (RESERVED_ENTITY_NAMES.includes(entity) || RESERVED_ENTITY_NAMES.find(ele2 => entity.startsWith(ele2))) {
5756
- throw new Error(`${ele}是系统保留字,请勿使用其当对象名或对象名前缀`);
6259
+ throw new Error(`${source.filename}是系统保留字,请勿使用其当对象名或对象名前缀`);
5757
6260
  }
5758
- return PathLib.join(absoluteInputDir, ele);
6261
+ return source.typeFilePath;
5759
6262
  });
5760
6263
  // Reuse the nearest tsconfig so `baseUrl`/`paths` aliases resolve exactly like TypeScript.
5761
- const program = ts.createProgram(fullFilenames, getCompilerOptions(absoluteInputDir));
5762
- files.forEach((filename) => {
5763
- analyzeEntity(filename, absoluteInputDir, program, relativePath);
6264
+ const program = ts.createProgram(fullFilenames, getCompilerOptions(absoluteInputDir, currentSchemaBuilderProjectOptions));
6265
+ entitySources.forEach((source) => {
6266
+ analyzeEntity(source, program, relativePath);
5764
6267
  });
5765
6268
  analyzeInModi();
5766
6269
  uniqRelationships();
@@ -6348,6 +6851,13 @@ function _outputEntityDict(outputDir, printer) {
6348
6851
  ); */
6349
6852
  }
6350
6853
  }
6854
+ const updateOperationDataSchema = cascadeUpdateElements.length ? factory.createIntersectionTypeNode([
6855
+ factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema"))),
6856
+ factory.createTypeLiteralNode(cascadeUpdateElements),
6857
+ ]) : factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema")));
6858
+ const UpdateDataType = factory.createTypeReferenceNode('FormUpdateData', [
6859
+ updateOperationDataSchema,
6860
+ ]);
6351
6861
  return {
6352
6862
  CreateOperationData: factory.createTypeReferenceNode('FormCreateData', [
6353
6863
  cascadeCreateElements.length ? factory.createIntersectionTypeNode([
@@ -6355,12 +6865,7 @@ function _outputEntityDict(outputDir, printer) {
6355
6865
  factory.createTypeLiteralNode(cascadeCreateElements),
6356
6866
  ]) : factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema")))
6357
6867
  ]),
6358
- UpdateOperationData: factory.createTypeReferenceNode('FormUpdateData', [
6359
- cascadeUpdateElements.length ? factory.createIntersectionTypeNode([
6360
- factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema"))),
6361
- factory.createTypeLiteralNode(cascadeUpdateElements),
6362
- ]) : factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(`Base${entity}`), factory.createIdentifier("OpSchema")))
6363
- ]),
6868
+ UpdateOperationData: UpdateDataType,
6364
6869
  RemoveOperationData: factory.createTypeLiteralNode([]), // RemoveOperate暂时不支持Cascade
6365
6870
  };
6366
6871
  };