fib-orm 2.0.0 → 3.0.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 (427) hide show
  1. package/README.md +42 -6
  2. package/index.d.ts +11 -0
  3. package/index.js +15 -0
  4. package/package.json +36 -34
  5. package/{lib/cli/commands/ddlFrom.js → src/cli/commands/ddlFrom.ts} +40 -26
  6. package/{lib/cli/commands/dumpModel.js → src/cli/commands/dumpModel.ts} +78 -31
  7. package/{lib/cli/commands/escape.js → src/cli/commands/escape.ts} +51 -28
  8. package/{lib/cli/commands/spinner.js → src/cli/commands/spinner.ts} +20 -10
  9. package/{lib/cli/commands/upgrade.js → src/cli/commands/upgrade.ts} +53 -33
  10. package/src/cli/helpers/ddl.ts +84 -0
  11. package/src/cli/helpers/package.ts +81 -0
  12. package/src/cli/index.ts +24 -0
  13. package/src/cli/wrapSubcommand.ts +66 -0
  14. package/src/db-driver/Typo.d.ts +141 -0
  15. package/src/db-driver/built-ins/base.class.ts +260 -0
  16. package/src/db-driver/built-ins/driver-dm.ts +62 -0
  17. package/src/db-driver/built-ins/driver-mssql.ts +67 -0
  18. package/src/db-driver/built-ins/driver-mysql.ts +44 -0
  19. package/src/db-driver/built-ins/driver-postgresql.ts +94 -0
  20. package/src/db-driver/built-ins/driver-redis.ts +45 -0
  21. package/src/db-driver/built-ins/driver-sqlite.ts +41 -0
  22. package/src/db-driver/index.ts +6 -0
  23. package/src/db-driver/parseQueryString.ts +76 -0
  24. package/src/db-driver/utils.ts +204 -0
  25. package/src/knex/deps/tarn/PendingOperation.ts +56 -0
  26. package/src/knex/deps/tarn/Pool.ts +610 -0
  27. package/src/knex/deps/tarn/PromiseInspection.ts +29 -0
  28. package/src/knex/deps/tarn/Resource.ts +22 -0
  29. package/src/knex/deps/tarn/TimeoutError.ts +1 -0
  30. package/src/knex/deps/tarn/tarn.ts +7 -0
  31. package/src/knex/deps/tarn/utils.ts +62 -0
  32. package/src/knex/knex.ts +11 -0
  33. package/src/knex/result.d.ts +27 -0
  34. package/src/knex/sandbox.ts +45 -0
  35. package/src/knex/tables.d.ts +4 -0
  36. package/src/knex/types.d.ts +3228 -0
  37. package/src/orm/Adapters.ts +53 -0
  38. package/src/orm/AggregateFunctions.ts +254 -0
  39. package/src/orm/Associations/Extend.ts +405 -0
  40. package/src/orm/Associations/Many.ts +784 -0
  41. package/src/orm/Associations/One.ts +494 -0
  42. package/src/orm/Associations/_utils.ts +72 -0
  43. package/src/orm/ChainFind.ts +427 -0
  44. package/src/orm/ChainInstance.ts +97 -0
  45. package/src/orm/Debug.ts +21 -0
  46. package/src/orm/Drivers/DB/base.ts +7 -0
  47. package/src/orm/Drivers/DB/dm.ts +35 -0
  48. package/src/orm/Drivers/DB/mssql.ts +35 -0
  49. package/src/orm/Drivers/DB/mysql.ts +35 -0
  50. package/src/orm/Drivers/DB/postgres.ts +35 -0
  51. package/src/orm/Drivers/DB/sqlite3.ts +60 -0
  52. package/src/orm/Drivers/DML/_ddl-sql.ts +85 -0
  53. package/src/orm/Drivers/DML/_dml-helpers.ts +66 -0
  54. package/src/orm/Drivers/DML/_shared.ts +61 -0
  55. package/src/orm/Drivers/DML/_utils.ts +112 -0
  56. package/{lib/orm/Drivers/DML/dm.js → src/orm/Drivers/DML/dm.ts} +178 -85
  57. package/src/orm/Drivers/DML/index.ts +10 -0
  58. package/src/orm/Drivers/DML/mssql.ts +366 -0
  59. package/src/orm/Drivers/DML/mysql.ts +347 -0
  60. package/src/orm/Drivers/DML/postgres.ts +382 -0
  61. package/src/orm/Drivers/DML/sqlite.ts +361 -0
  62. package/src/orm/Error.ts +49 -0
  63. package/src/orm/Helpers.ts +297 -0
  64. package/src/orm/Hook.ts +125 -0
  65. package/src/orm/Instance.ts +944 -0
  66. package/src/orm/LazyLoad.ts +117 -0
  67. package/src/orm/Model.ts +1235 -0
  68. package/src/orm/ORM.ts +301 -0
  69. package/src/orm/Patch/fib-cache.ts +7 -0
  70. package/src/orm/Patch/plugin.ts +25 -0
  71. package/src/orm/Property.ts +86 -0
  72. package/src/orm/Settings.ts +134 -0
  73. package/src/orm/Singleton.ts +97 -0
  74. package/src/orm/Typo/Adapter.d.ts +5 -0
  75. package/src/orm/Typo/DMLDriver.d.ts +260 -0
  76. package/src/orm/Typo/Db.d.ts +100 -0
  77. package/src/orm/Typo/Error.d.ts +36 -0
  78. package/src/orm/Typo/ORM.d.ts +315 -0
  79. package/src/orm/Typo/Validators.d.ts +39 -0
  80. package/src/orm/Typo/_common.d.ts +44 -0
  81. package/src/orm/Typo/assoc.d.ts +280 -0
  82. package/src/orm/Typo/hook.d.ts +68 -0
  83. package/src/orm/Typo/instance.d.ts +214 -0
  84. package/{lib → src}/orm/Typo/model.d.ts +297 -176
  85. package/src/orm/Typo/patch.d.ts +39 -0
  86. package/src/orm/Typo/property.d.ts +79 -0
  87. package/src/orm/Typo/query.d.ts +266 -0
  88. package/{lib → src}/orm/Typo/settings.d.ts +14 -7
  89. package/{lib → src}/orm/Typo/synchronous.d.ts +51 -26
  90. package/src/orm/Utilities.ts +1313 -0
  91. package/src/orm/Validators.ts +127 -0
  92. package/src/orm/Where/common.ts +8 -0
  93. package/src/orm/Where/filterDate.ts +74 -0
  94. package/src/orm/cloneDeep.ts +45 -0
  95. package/src/orm/index.ts +231 -0
  96. package/src/orm-core/callback.d.ts +15 -0
  97. package/{lib → src}/orm-core/dialect.d.ts +75 -52
  98. package/src/orm-core/error.ts +71 -0
  99. package/{lib/orm-core/index.d.ts → src/orm-core/index.ts} +8 -2
  100. package/src/orm-core/sync.d.ts +14 -0
  101. package/src/orm-core/utils.ts +4 -0
  102. package/src/orm-property/Property.ts +110 -0
  103. package/src/orm-property/Utils.ts +26 -0
  104. package/src/orm-property/customTypes.ts +13 -0
  105. package/src/orm-property/index.ts +34 -0
  106. package/src/orm-property/transformer.ts +16 -0
  107. package/{lib/orm-property/transformers/dm.js → src/orm-property/transformers/dm.ts} +128 -68
  108. package/src/orm-property/transformers/index.ts +10 -0
  109. package/src/orm-property/transformers/mssql.ts +285 -0
  110. package/src/orm-property/transformers/mysql.ts +395 -0
  111. package/src/orm-property/transformers/postgresql.ts +267 -0
  112. package/src/orm-property/transformers/sqlite.ts +217 -0
  113. package/src/plugins/orm-plugin-uacl/Typo.d.ts +173 -0
  114. package/src/plugins/orm-plugin-uacl/_utils.ts +237 -0
  115. package/src/plugins/orm-plugin-uacl/acl-tree.ts +440 -0
  116. package/src/plugins/orm-plugin-uacl/config-acl-tree.ts +592 -0
  117. package/src/plugins/orm-plugin-uacl/index.ts +180 -0
  118. package/src/plugins/orm-plugin-uacl/tree.ts +331 -0
  119. package/src/sql-ddl-sync/Dialects/dm.ts +493 -0
  120. package/{lib/sql-query/Dialects/index.d.ts → src/sql-ddl-sync/Dialects/index.ts} +3 -3
  121. package/src/sql-ddl-sync/Dialects/mssql.ts +441 -0
  122. package/src/sql-ddl-sync/Dialects/mysql.ts +414 -0
  123. package/src/sql-ddl-sync/Dialects/postgresql.ts +474 -0
  124. package/src/sql-ddl-sync/Dialects/sqlite.ts +439 -0
  125. package/src/sql-ddl-sync/SQL.ts +157 -0
  126. package/src/sql-ddl-sync/Typo/Collection.d.ts +19 -0
  127. package/src/sql-ddl-sync/Typo/DbIndex.d.ts +11 -0
  128. package/{lib → src}/sql-ddl-sync/Typo/Dialect.d.ts +67 -52
  129. package/src/sql-ddl-sync/Typo/Driver.d.ts +67 -0
  130. package/src/sql-ddl-sync/Typo/Query.d.ts +8 -0
  131. package/src/sql-ddl-sync/Typo/SQL.d.ts +45 -0
  132. package/src/sql-ddl-sync/Typo/_common.d.ts +59 -0
  133. package/src/sql-ddl-sync/Utils.ts +291 -0
  134. package/src/sql-ddl-sync/index.ts +599 -0
  135. package/src/sql-query/Comparators.ts +115 -0
  136. package/src/sql-query/Create.ts +87 -0
  137. package/{lib/sql-query/Dialects/dm.js → src/sql-query/Dialects/dm.ts} +42 -21
  138. package/src/sql-query/Dialects/index.ts +14 -0
  139. package/src/sql-query/Dialects/mssql.ts +91 -0
  140. package/src/sql-query/Dialects/mysql.ts +120 -0
  141. package/src/sql-query/Dialects/postgresql.ts +99 -0
  142. package/src/sql-query/Dialects/sqlite.ts +80 -0
  143. package/src/sql-query/Helpers.ts +303 -0
  144. package/src/sql-query/Insert.ts +41 -0
  145. package/src/sql-query/Query.ts +140 -0
  146. package/src/sql-query/Remove.ts +111 -0
  147. package/src/sql-query/Select.ts +719 -0
  148. package/src/sql-query/Set.ts +25 -0
  149. package/src/sql-query/Typo/Aggregation.d.ts +34 -0
  150. package/src/sql-query/Typo/Comparators.d.ts +156 -0
  151. package/src/sql-query/Typo/Dialect.d.ts +51 -0
  152. package/src/sql-query/Typo/Field.d.ts +10 -0
  153. package/src/sql-query/Typo/Helper.d.ts +4 -0
  154. package/src/sql-query/Typo/Query-ChainBuilder.d.ts +110 -0
  155. package/src/sql-query/Typo/Query.d.ts +65 -0
  156. package/src/sql-query/Typo/Sql.d.ts +192 -0
  157. package/src/sql-query/Typo/SubQuery.d.ts +52 -0
  158. package/{lib/sql-query/Typo/index.d.ts → src/sql-query/Typo/index.ts} +5 -2
  159. package/src/sql-query/Update.ts +50 -0
  160. package/src/sql-query/Where.ts +435 -0
  161. package/{lib/orm/Patch → src/typings}/fib-cache.d.ts +4 -3
  162. package/lib/cli/commands/ddlFrom.d.ts +0 -2
  163. package/lib/cli/commands/dumpModel.d.ts +0 -2
  164. package/lib/cli/commands/escape.d.ts +0 -2
  165. package/lib/cli/commands/spinner.d.ts +0 -2
  166. package/lib/cli/commands/upgrade.d.ts +0 -2
  167. package/lib/cli/helpers/ddl.d.ts +0 -17
  168. package/lib/cli/helpers/ddl.js +0 -55
  169. package/lib/cli/helpers/package.d.ts +0 -26
  170. package/lib/cli/helpers/package.js +0 -56
  171. package/lib/cli/index.d.ts +0 -2
  172. package/lib/cli/index.js +0 -18
  173. package/lib/db-driver/Typo.d.ts +0 -112
  174. package/lib/db-driver/Typo.js +0 -1
  175. package/lib/db-driver/built-ins/base.class.d.ts +0 -96
  176. package/lib/db-driver/built-ins/base.class.js +0 -186
  177. package/lib/db-driver/built-ins/driver-dm.d.ts +0 -18
  178. package/lib/db-driver/built-ins/driver-dm.js +0 -53
  179. package/lib/db-driver/built-ins/driver-mongodb.d.ts +0 -24
  180. package/lib/db-driver/built-ins/driver-mongodb.js +0 -46
  181. package/lib/db-driver/built-ins/driver-mysql.d.ts +0 -18
  182. package/lib/db-driver/built-ins/driver-mysql.js +0 -37
  183. package/lib/db-driver/built-ins/driver-postgresql.d.ts +0 -22
  184. package/lib/db-driver/built-ins/driver-postgresql.js +0 -76
  185. package/lib/db-driver/built-ins/driver-redis.d.ts +0 -12
  186. package/lib/db-driver/built-ins/driver-redis.js +0 -35
  187. package/lib/db-driver/built-ins/driver-sqlite.d.ts +0 -17
  188. package/lib/db-driver/built-ins/driver-sqlite.js +0 -34
  189. package/lib/db-driver/index.d.ts +0 -3
  190. package/lib/db-driver/index.js +0 -4
  191. package/lib/db-driver/utils.d.ts +0 -14
  192. package/lib/db-driver/utils.js +0 -187
  193. package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +0 -12
  194. package/lib/knex/deps/tarn/dist/PendingOperation.js +0 -48
  195. package/lib/knex/deps/tarn/dist/Pool.d.ts +0 -97
  196. package/lib/knex/deps/tarn/dist/Pool.js +0 -516
  197. package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +0 -16
  198. package/lib/knex/deps/tarn/dist/PromiseInspection.js +0 -21
  199. package/lib/knex/deps/tarn/dist/Resource.d.ts +0 -9
  200. package/lib/knex/deps/tarn/dist/Resource.js +0 -19
  201. package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +0 -2
  202. package/lib/knex/deps/tarn/dist/TimeoutError.js +0 -5
  203. package/lib/knex/deps/tarn/dist/tarn.d.ts +0 -3
  204. package/lib/knex/deps/tarn/dist/tarn.js +0 -10
  205. package/lib/knex/deps/tarn/dist/utils.d.ts +0 -14
  206. package/lib/knex/deps/tarn/dist/utils.js +0 -60
  207. package/lib/knex/knex.d.ts +0 -2
  208. package/lib/knex/knex.js +0 -3
  209. package/lib/knex/sandbox.d.ts +0 -4
  210. package/lib/knex/sandbox.js +0 -22
  211. package/lib/orm/Adapters.d.ts +0 -3
  212. package/lib/orm/Adapters.js +0 -44
  213. package/lib/orm/AggregateFunctions.d.ts +0 -3
  214. package/lib/orm/AggregateFunctions.js +0 -176
  215. package/lib/orm/Associations/Extend.d.ts +0 -22
  216. package/lib/orm/Associations/Extend.js +0 -274
  217. package/lib/orm/Associations/Many.d.ts +0 -17
  218. package/lib/orm/Associations/Many.js +0 -569
  219. package/lib/orm/Associations/One.d.ts +0 -16
  220. package/lib/orm/Associations/One.js +0 -310
  221. package/lib/orm/Associations/_utils.d.ts +0 -15
  222. package/lib/orm/Associations/_utils.js +0 -52
  223. package/lib/orm/ChainFind.d.ts +0 -3
  224. package/lib/orm/ChainFind.js +0 -327
  225. package/lib/orm/ChainInstance.d.ts +0 -6
  226. package/lib/orm/ChainInstance.js +0 -73
  227. package/lib/orm/Debug.d.ts +0 -2
  228. package/lib/orm/Debug.js +0 -17
  229. package/lib/orm/Drivers/DB/base.d.ts +0 -3
  230. package/lib/orm/Drivers/DB/base.js +0 -3
  231. package/lib/orm/Drivers/DB/dm.d.ts +0 -11
  232. package/lib/orm/Drivers/DB/dm.js +0 -23
  233. package/lib/orm/Drivers/DB/mysql.d.ts +0 -11
  234. package/lib/orm/Drivers/DB/mysql.js +0 -23
  235. package/lib/orm/Drivers/DB/postgres.d.ts +0 -11
  236. package/lib/orm/Drivers/DB/postgres.js +0 -22
  237. package/lib/orm/Drivers/DB/sqlite3.d.ts +0 -16
  238. package/lib/orm/Drivers/DB/sqlite3.js +0 -39
  239. package/lib/orm/Drivers/DML/_ddl-sql.d.ts +0 -3
  240. package/lib/orm/Drivers/DML/_ddl-sql.js +0 -51
  241. package/lib/orm/Drivers/DML/_dml-helpers.d.ts +0 -19
  242. package/lib/orm/Drivers/DML/_dml-helpers.js +0 -51
  243. package/lib/orm/Drivers/DML/_shared.d.ts +0 -9
  244. package/lib/orm/Drivers/DML/_shared.js +0 -38
  245. package/lib/orm/Drivers/DML/_utils.d.ts +0 -8
  246. package/lib/orm/Drivers/DML/_utils.js +0 -67
  247. package/lib/orm/Drivers/DML/constants.d.ts +0 -3
  248. package/lib/orm/Drivers/DML/constants.js +0 -2
  249. package/lib/orm/Drivers/DML/dm.d.ts +0 -2
  250. package/lib/orm/Drivers/DML/index.d.ts +0 -4
  251. package/lib/orm/Drivers/DML/index.js +0 -6
  252. package/lib/orm/Drivers/DML/mysql.d.ts +0 -2
  253. package/lib/orm/Drivers/DML/mysql.js +0 -251
  254. package/lib/orm/Drivers/DML/postgres.d.ts +0 -3
  255. package/lib/orm/Drivers/DML/postgres.js +0 -276
  256. package/lib/orm/Drivers/DML/sqlite.d.ts +0 -2
  257. package/lib/orm/Drivers/DML/sqlite.js +0 -266
  258. package/lib/orm/Error.d.ts +0 -11
  259. package/lib/orm/Error.js +0 -40
  260. package/lib/orm/Helpers.d.ts +0 -35
  261. package/lib/orm/Helpers.js +0 -233
  262. package/lib/orm/Hook.d.ts +0 -13
  263. package/lib/orm/Hook.js +0 -99
  264. package/lib/orm/Instance.d.ts +0 -2
  265. package/lib/orm/Instance.js +0 -697
  266. package/lib/orm/LazyLoad.d.ts +0 -4
  267. package/lib/orm/LazyLoad.js +0 -76
  268. package/lib/orm/Model.d.ts +0 -7
  269. package/lib/orm/Model.js +0 -971
  270. package/lib/orm/ORM.d.ts +0 -37
  271. package/lib/orm/ORM.js +0 -241
  272. package/lib/orm/Patch/fib-cache.js +0 -2
  273. package/lib/orm/Patch/plugin.d.ts +0 -4
  274. package/lib/orm/Patch/plugin.js +0 -13
  275. package/lib/orm/Property.d.ts +0 -9
  276. package/lib/orm/Property.js +0 -71
  277. package/lib/orm/Settings.d.ts +0 -42
  278. package/lib/orm/Settings.js +0 -119
  279. package/lib/orm/Singleton.d.ts +0 -5
  280. package/lib/orm/Singleton.js +0 -72
  281. package/lib/orm/Typo/Adapter.d.ts +0 -5
  282. package/lib/orm/Typo/Adapter.js +0 -1
  283. package/lib/orm/Typo/DMLDriver.d.ts +0 -210
  284. package/lib/orm/Typo/DMLDriver.js +0 -1
  285. package/lib/orm/Typo/Db.d.ts +0 -38
  286. package/lib/orm/Typo/Db.js +0 -1
  287. package/lib/orm/Typo/Error.d.ts +0 -31
  288. package/lib/orm/Typo/Error.js +0 -1
  289. package/lib/orm/Typo/ORM.d.ts +0 -233
  290. package/lib/orm/Typo/ORM.js +0 -3
  291. package/lib/orm/Typo/Validators.d.ts +0 -32
  292. package/lib/orm/Typo/Validators.js +0 -2
  293. package/lib/orm/Typo/_common.d.ts +0 -38
  294. package/lib/orm/Typo/_common.js +0 -1
  295. package/lib/orm/Typo/assoc.d.ts +0 -221
  296. package/lib/orm/Typo/assoc.js +0 -1
  297. package/lib/orm/Typo/hook.d.ts +0 -42
  298. package/lib/orm/Typo/hook.js +0 -1
  299. package/lib/orm/Typo/instance.d.ts +0 -157
  300. package/lib/orm/Typo/instance.js +0 -1
  301. package/lib/orm/Typo/model.js +0 -6
  302. package/lib/orm/Typo/patch.d.ts +0 -31
  303. package/lib/orm/Typo/patch.js +0 -1
  304. package/lib/orm/Typo/property.d.ts +0 -57
  305. package/lib/orm/Typo/property.js +0 -1
  306. package/lib/orm/Typo/query.d.ts +0 -216
  307. package/lib/orm/Typo/query.js +0 -1
  308. package/lib/orm/Typo/settings.js +0 -5
  309. package/lib/orm/Typo/synchronous.js +0 -1
  310. package/lib/orm/Utilities.d.ts +0 -179
  311. package/lib/orm/Utilities.js +0 -975
  312. package/lib/orm/Validators.d.ts +0 -34
  313. package/lib/orm/Validators.js +0 -100
  314. package/lib/orm/Where/common.d.ts +0 -1
  315. package/lib/orm/Where/common.js +0 -7
  316. package/lib/orm/Where/filterDate.d.ts +0 -11
  317. package/lib/orm/Where/filterDate.js +0 -58
  318. package/lib/orm/index.d.ts +0 -68
  319. package/lib/orm/index.js +0 -157
  320. package/lib/orm-core/callback.d.ts +0 -12
  321. package/lib/orm-core/callback.js +0 -1
  322. package/lib/orm-core/dialect.js +0 -1
  323. package/lib/orm-core/error.d.ts +0 -16
  324. package/lib/orm-core/error.js +0 -29
  325. package/lib/orm-core/index.js +0 -6
  326. package/lib/orm-core/sync.d.ts +0 -12
  327. package/lib/orm-core/sync.js +0 -1
  328. package/lib/orm-core/utils.d.ts +0 -1
  329. package/lib/orm-core/utils.js +0 -5
  330. package/lib/orm-property/Property.d.ts +0 -78
  331. package/lib/orm-property/Property.js +0 -1
  332. package/lib/orm-property/Utils.d.ts +0 -9
  333. package/lib/orm-property/Utils.js +0 -13
  334. package/lib/orm-property/customTypes.d.ts +0 -2
  335. package/lib/orm-property/customTypes.js +0 -13
  336. package/lib/orm-property/index.d.ts +0 -10
  337. package/lib/orm-property/index.js +0 -22
  338. package/lib/orm-property/transformer.d.ts +0 -5
  339. package/lib/orm-property/transformer.js +0 -10
  340. package/lib/orm-property/transformers/dm.d.ts +0 -29
  341. package/lib/orm-property/transformers/index.d.ts +0 -4
  342. package/lib/orm-property/transformers/index.js +0 -5
  343. package/lib/orm-property/transformers/mysql.d.ts +0 -102
  344. package/lib/orm-property/transformers/mysql.js +0 -261
  345. package/lib/orm-property/transformers/postgresql.d.ts +0 -54
  346. package/lib/orm-property/transformers/postgresql.js +0 -189
  347. package/lib/orm-property/transformers/sqlite.d.ts +0 -19
  348. package/lib/orm-property/transformers/sqlite.js +0 -171
  349. package/lib/sql-ddl-sync/Dialects/dm.d.ts +0 -40
  350. package/lib/sql-ddl-sync/Dialects/dm.js +0 -296
  351. package/lib/sql-ddl-sync/Dialects/index.d.ts +0 -7
  352. package/lib/sql-ddl-sync/Dialects/index.js +0 -7
  353. package/lib/sql-ddl-sync/Dialects/mysql.d.ts +0 -39
  354. package/lib/sql-ddl-sync/Dialects/mysql.js +0 -240
  355. package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +0 -40
  356. package/lib/sql-ddl-sync/Dialects/postgresql.js +0 -286
  357. package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +0 -44
  358. package/lib/sql-ddl-sync/Dialects/sqlite.js +0 -256
  359. package/lib/sql-ddl-sync/SQL.d.ts +0 -12
  360. package/lib/sql-ddl-sync/SQL.js +0 -108
  361. package/lib/sql-ddl-sync/Typo/Collection.d.ts +0 -13
  362. package/lib/sql-ddl-sync/Typo/Collection.js +0 -1
  363. package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +0 -13
  364. package/lib/sql-ddl-sync/Typo/DbIndex.js +0 -1
  365. package/lib/sql-ddl-sync/Typo/Dialect.js +0 -1
  366. package/lib/sql-ddl-sync/Typo/Driver.d.ts +0 -53
  367. package/lib/sql-ddl-sync/Typo/Driver.js +0 -1
  368. package/lib/sql-ddl-sync/Typo/Query.d.ts +0 -7
  369. package/lib/sql-ddl-sync/Typo/Query.js +0 -1
  370. package/lib/sql-ddl-sync/Typo/SQL.d.ts +0 -31
  371. package/lib/sql-ddl-sync/Typo/SQL.js +0 -1
  372. package/lib/sql-ddl-sync/Typo/_common.d.ts +0 -29
  373. package/lib/sql-ddl-sync/Typo/_common.js +0 -1
  374. package/lib/sql-ddl-sync/Utils.d.ts +0 -40
  375. package/lib/sql-ddl-sync/Utils.js +0 -217
  376. package/lib/sql-ddl-sync/index.d.ts +0 -87
  377. package/lib/sql-ddl-sync/index.js +0 -371
  378. package/lib/sql-query/Comparators.d.ts +0 -3
  379. package/lib/sql-query/Comparators.js +0 -94
  380. package/lib/sql-query/Create.d.ts +0 -35
  381. package/lib/sql-query/Create.js +0 -77
  382. package/lib/sql-query/Dialects/dm.d.ts +0 -3
  383. package/lib/sql-query/Dialects/index.js +0 -12
  384. package/lib/sql-query/Dialects/mssql.d.ts +0 -3
  385. package/lib/sql-query/Dialects/mssql.js +0 -73
  386. package/lib/sql-query/Dialects/mysql.d.ts +0 -3
  387. package/lib/sql-query/Dialects/mysql.js +0 -100
  388. package/lib/sql-query/Dialects/postgresql.d.ts +0 -3
  389. package/lib/sql-query/Dialects/postgresql.js +0 -76
  390. package/lib/sql-query/Dialects/sqlite.d.ts +0 -3
  391. package/lib/sql-query/Dialects/sqlite.js +0 -61
  392. package/lib/sql-query/Helpers.d.ts +0 -38
  393. package/lib/sql-query/Helpers.js +0 -259
  394. package/lib/sql-query/Insert.d.ts +0 -12
  395. package/lib/sql-query/Insert.js +0 -33
  396. package/lib/sql-query/Query.d.ts +0 -29
  397. package/lib/sql-query/Query.js +0 -119
  398. package/lib/sql-query/Remove.d.ts +0 -16
  399. package/lib/sql-query/Remove.js +0 -93
  400. package/lib/sql-query/Select.d.ts +0 -62
  401. package/lib/sql-query/Select.js +0 -533
  402. package/lib/sql-query/Set.d.ts +0 -4
  403. package/lib/sql-query/Set.js +0 -16
  404. package/lib/sql-query/Typo/Aggregation.d.ts +0 -32
  405. package/lib/sql-query/Typo/Aggregation.js +0 -1
  406. package/lib/sql-query/Typo/Comparators.d.ts +0 -140
  407. package/lib/sql-query/Typo/Comparators.js +0 -1
  408. package/lib/sql-query/Typo/Dialect.d.ts +0 -39
  409. package/lib/sql-query/Typo/Dialect.js +0 -1
  410. package/lib/sql-query/Typo/Field.d.ts +0 -8
  411. package/lib/sql-query/Typo/Field.js +0 -1
  412. package/lib/sql-query/Typo/Helper.d.ts +0 -4
  413. package/lib/sql-query/Typo/Helper.js +0 -1
  414. package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +0 -80
  415. package/lib/sql-query/Typo/Query-ChainBuilder.js +0 -1
  416. package/lib/sql-query/Typo/Query.d.ts +0 -34
  417. package/lib/sql-query/Typo/Query.js +0 -16
  418. package/lib/sql-query/Typo/Sql.d.ts +0 -143
  419. package/lib/sql-query/Typo/Sql.js +0 -1
  420. package/lib/sql-query/Typo/SubQuery.d.ts +0 -39
  421. package/lib/sql-query/Typo/SubQuery.js +0 -1
  422. package/lib/sql-query/Typo/index.js +0 -1
  423. package/lib/sql-query/Update.d.ts +0 -15
  424. package/lib/sql-query/Update.js +0 -38
  425. package/lib/sql-query/Where.d.ts +0 -4
  426. package/lib/sql-query/Where.js +0 -280
  427. /package/{lib → src}/codepoints-map.json +0 -0
@@ -0,0 +1,237 @@
1
+ import { createRequire } from 'node:module';
2
+ import type { FxOrmNS } from '../../orm/Typo/ORM';
3
+ const require = createRequire(import.meta.url);
4
+ const mq = require('mq');
5
+ const coroutine = require('coroutine');
6
+ export function arraify<T = any> (item: T | T[]): T[] {
7
+ return Array.isArray(item) ? item : [item]
8
+ }
9
+
10
+ export function normalizeUaci (uaci: string = '') {
11
+ if (!uaci || typeof uaci !== 'string')
12
+ throw new Error(`[normalizeUaci] uaci must be non-empty string`)
13
+
14
+ if (uaci[0] !== '/')
15
+ uaci = '/' + uaci
16
+
17
+ return uaci
18
+ }
19
+
20
+ export function findACLNode (
21
+ aclTree: FxORMPluginUACLNS.ACLTree,
22
+ uaci: string,
23
+ ): FxORMPluginUACLNS.ACLNode | null {
24
+ let node: FxORMPluginUACLNS.ACLNode | null = null
25
+
26
+ if (!uaci || typeof uaci !== 'string')
27
+ throw Error('[findACLNode]invalid uaci')
28
+
29
+ const depth = compuateUaciDepth(uaci)
30
+
31
+ for (let x of aclTree.nodeSet) {
32
+ if (x.isRoot)
33
+ continue ;
34
+
35
+ if (x.layer - 1 !== depth)
36
+ continue ;
37
+
38
+ if (x.id === uaci) {
39
+ node = x as FxORMPluginUACLNS.ACLNode;
40
+ break ;
41
+ }
42
+ }
43
+
44
+ return node;
45
+ }
46
+
47
+ /* for acl-tree: start */
48
+ /**
49
+ * generate message for retrievable-end
50
+ *
51
+ * ---- head begin ----
52
+ * verb: GRANT
53
+ * date: GMT FORMAT STRING
54
+ * uaci: /project/1; /project/1/stages/2
55
+ * level: 1, 2
56
+ * ---- head end ------
57
+ *
58
+ * ---- body begin ----
59
+ * x-key1: ...
60
+ * x-key2: ...
61
+ * ---- body end ------
62
+ */
63
+ export function generateGrantMessage (
64
+ node: FxORMPluginUACLNS.ACLNode,
65
+ {
66
+ uid = null as any,
67
+ role = []
68
+ }: {
69
+ uid: FxOrmNS.Arraible<string>,
70
+ role: FxOrmNS.Arraible<string>,
71
+ }
72
+ ) {
73
+ const msg = new mq.Message()
74
+ msg.type = 1
75
+
76
+ msg.value = node.id
77
+
78
+ const uids = arraify(uid)
79
+ const roles = arraify(role)
80
+
81
+ msg.json({
82
+ verb: 'GRANT',
83
+ date: (new Date()).toUTCString(),
84
+ uids: uids,
85
+ roles: roles,
86
+ oacl: node.oacl,
87
+
88
+ // via: type,
89
+ } as FxORMPluginUACLInternal.ACLMessagePayloadGrant)
90
+
91
+ return msg
92
+ }
93
+
94
+ export function generateRevokeByUACIMessage (
95
+ node: FxORMPluginUACLNS.ACLNode,
96
+ {
97
+ uid = null as any,
98
+ role = []
99
+ }: {
100
+ uid: FxOrmNS.Arraible<string>,
101
+ role: FxOrmNS.Arraible<string>,
102
+ }
103
+ ) {
104
+ const msg = new mq.Message()
105
+ msg.type = 1
106
+
107
+ msg.value = node.id
108
+
109
+ const uids = arraify(uid)
110
+ const roles = arraify(role)
111
+
112
+ msg.json({
113
+ verb: 'REVOKE_BY_UACI',
114
+ date: (new Date()).toUTCString(),
115
+ uids: uids,
116
+ roles: roles,
117
+ oacl: null,
118
+ } as FxORMPluginUACLInternal.ACLMessagePayloadGrant)
119
+
120
+ return msg
121
+ }
122
+
123
+ export function getIdsFromTree (tree: FxORMPluginUACLNS.ACLTree) {
124
+ let uids = [] as string[]
125
+ let roles = [] as string[]
126
+ switch (tree.type) {
127
+ case 'user':
128
+ uids = arraify(tree.name)
129
+ break
130
+ case 'role':
131
+ roles = arraify(tree.name)
132
+ break
133
+ }
134
+
135
+ return {
136
+ uids,
137
+ roles
138
+ }
139
+ }
140
+
141
+ /**
142
+ *
143
+ * @param uaci batch query when uaci is empty
144
+ */
145
+ export function generateLoadMessage (
146
+ uaci: string,
147
+ {
148
+ uid = null as any,
149
+ role = [] as any,
150
+ uacis = [],
151
+ }: {
152
+ uid: FxOrmNS.Arraible<string>,
153
+ role: FxOrmNS.Arraible<string>,
154
+ uacis: FxOrmNS.Arraible<string>,
155
+ }
156
+ ) {
157
+ const msg = new mq.Message()
158
+ msg.type = 1
159
+
160
+ msg.value = uaci
161
+
162
+ const uids = arraify(uid)
163
+ const roles = arraify(role)
164
+
165
+ if (uaci)
166
+ uacis = []
167
+ else
168
+ uacis = arraify(uaci)
169
+
170
+ msg.json({
171
+ verb: 'QUERY',
172
+ date: (new Date()).toUTCString(),
173
+ uids: uids,
174
+ roles: roles,
175
+ uacis: uacis
176
+ })
177
+
178
+ return msg
179
+ }
180
+ /* for acl-tree: end */
181
+
182
+ /* for acl-item: start */
183
+ export function encodeGrantTareget (type: FxORMPluginUACLInternal.GRANT_TYPE, id = '0') {
184
+ return `${type}:${id}`
185
+ }
186
+ export function decodeGrantTareget (value: string): FxORMPluginUACLInternal.ACLStorageItem['target'] {
187
+ const tuple = (value || '').split(':')
188
+ return {
189
+ type: tuple[0] as any,
190
+ id: tuple[1]
191
+ }
192
+ }
193
+
194
+ export function compuateUaciDepth (uaci: string = '') {
195
+ if (!uaci)
196
+ return 0
197
+
198
+ const list = uaci.split('/').filter(x => x !== undefined)
199
+ return Math.floor(list.length / 2)
200
+ }
201
+
202
+ export function isUaciWild (uaci: string = '') {
203
+ if (!uaci)
204
+ return false
205
+
206
+ const list = uaci.split('/').filter(x => !!x)
207
+ const result = list.every((item, idx) => {
208
+ // even position
209
+ if (idx % 2 === 0) return true
210
+
211
+ return item + '' === '0'
212
+ })
213
+
214
+ return result
215
+ }
216
+ /* for acl-item: end */
217
+
218
+ /* for acl-message: start */
219
+ export function waitUntil (timeout: number, ifTrue: () => boolean) {
220
+ if (ifTrue())
221
+ return
222
+
223
+ const tstart = process.hrtime()
224
+ const evt = new coroutine.Event()
225
+
226
+ coroutine.start(() => {
227
+ const [t_offset_s] = process.hrtime(tstart)
228
+ while (t_offset_s && t_offset_s * 1000 <= timeout) {
229
+ if (ifTrue())
230
+ break
231
+ }
232
+ evt.set()
233
+ })
234
+
235
+ evt.wait()
236
+ }
237
+ /* for acl-message: end */
@@ -0,0 +1,440 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+ const coroutine = require('coroutine');
4
+ const util = require('util');
5
+ const mq = require('mq');
6
+ import { Tree, Node } from './tree'
7
+ import { findACLNode, generateGrantMessage, generateLoadMessage, normalizeUaci, generateRevokeByUACIMessage, getIdsFromTree } from './_utils';
8
+ import type { FxOrmNS } from '../../orm/Typo/ORM';
9
+
10
+ function nOop () { return null as any }
11
+
12
+ /**
13
+ * @description retrievable-end/grant-end of uacl
14
+ */
15
+ export class ACLTree extends Tree<ACLNode> implements FxORMPluginUACLNS.ACLTree {
16
+ name!: string
17
+ type!: FxORMPluginUACLInternal.GRANT_TYPE
18
+
19
+ readonly _tree_stores: FxORMPluginUACLNS.ACLTree['_tree_stores'];
20
+ readonly routing: FxORMPluginUACLNS.ACLTree['routing'];
21
+
22
+ constructor ({ name, type = 'user', configStorageServiceRouting = nOop }: {
23
+ name: FxORMPluginUACLNS.ACLTree['name'],
24
+ type: FxORMPluginUACLNS.ACLTree['type'],
25
+ configStorageServiceRouting?: FxORMPluginUACLNS.ACLTreeStorageRoutingConfigurationGenerator
26
+ } = {
27
+ name: null as any, type: null as any, configStorageServiceRouting: null as any
28
+ }) {
29
+ super();
30
+
31
+ if (!type || !['user', 'role'].includes(type))
32
+ throw `[ACLTree] valid type is required, but '${type}' provided`
33
+
34
+ const _treeStores = {}
35
+ Object.defineProperty(this, '_tree_stores', { get () { return _treeStores }, enumerable: false });
36
+
37
+ if (typeof name === 'number') {
38
+ if (isNaN(name)) name = '0'
39
+ else name = name + ''
40
+ }
41
+ Object.defineProperty(this, 'name', { get () { return name }, configurable: false });
42
+ Object.defineProperty(this, 'type', { get () { return type }, configurable: false });
43
+
44
+ /* after basic info :start */
45
+ let routing = configStorageServiceRouting({ tree: this })
46
+ if (!(routing instanceof mq.Routing)) {
47
+ routing = routing || {}
48
+ routing = new mq.Routing(routing)
49
+ }
50
+ Object.defineProperty(this, 'routing', { get () { return routing }, configurable: false });
51
+ /* after basic info :end */
52
+ }
53
+
54
+ /**
55
+ * @default_sync
56
+ * @description
57
+ * load resource's information of specific uaci if provided,
58
+ * if no uaci specified, load all uacis from ALL childNodes in this tree
59
+ */
60
+ load (opts?: FxORMPluginUACLNS.ACLTreePersistOptions) {
61
+ let { uaci = null, sync: is_sync = true } = opts || {}
62
+
63
+ if (!uaci) {
64
+ this.nonRootNodes.forEach(node => node.pull({ sync: is_sync }))
65
+ return this;
66
+ }
67
+
68
+ uaci = normalizeUaci(uaci)
69
+
70
+ let node: any = findACLNode(this, uaci)
71
+ if (!node)
72
+ node = ACLNode.looseNodeOf(this, {id: uaci, data: {}})
73
+
74
+ // use synchronous mode
75
+ node.pull({ sync: is_sync })
76
+
77
+ return this
78
+ }
79
+
80
+ /**
81
+ * @default_async
82
+ * @description
83
+ * save resource's information of specific uaci if provided,
84
+ * if no uaci specified, save all uacis from ALL childNodes in this tree
85
+ */
86
+ persist(opts?: FxORMPluginUACLNS.ACLTreePersistOptions) {
87
+ let { uaci = null, sync: is_sync = false } = opts || {}
88
+
89
+ if (!uaci) {
90
+ this.nonRootNodes.forEach(
91
+ node => node.push({
92
+ type: this.type,
93
+ id: this.name
94
+ }, {
95
+ sync: is_sync
96
+ })
97
+ )
98
+ return this;
99
+ }
100
+
101
+ uaci = normalizeUaci(uaci)
102
+
103
+ const node = findACLNode(this, uaci)
104
+ if (!node)
105
+ return this;
106
+
107
+ node.push(
108
+ {
109
+ type: this.type,
110
+ id: this.name
111
+ },
112
+ { sync: is_sync }
113
+ )
114
+
115
+ return this
116
+ }
117
+
118
+ revoke (
119
+ opts?: FxORMPluginUACLNS.ACLTreeRevokeOptions
120
+ ) {
121
+ let { uaci = null, sync: is_sync = false } = opts || {}
122
+
123
+ if (!uaci) {
124
+ this.nonRootNodes.forEach(
125
+ node => node.revoke({
126
+ sync: is_sync
127
+ })
128
+ )
129
+ return this;
130
+ }
131
+
132
+ uaci = normalizeUaci(uaci)
133
+
134
+ const node = findACLNode(this, uaci)
135
+ if (!node)
136
+ return this;
137
+
138
+ node.revoke({ sync: is_sync })
139
+
140
+ return this
141
+ }
142
+
143
+ /**
144
+ * check if `user` with (this.id) can DO `action` TO uaci('s askedFields if provided)
145
+ *
146
+ * verb: CAN
147
+ */
148
+ can (action: FxORMPluginUACLNS.ACLKeyType, uaci: string, askedFields: any[]) {
149
+ const node = findACLNode(this, uaci)
150
+
151
+ if (!node)
152
+ return false;
153
+
154
+ return node.could(action, uaci, askedFields)
155
+ }
156
+
157
+ grant (
158
+ uaci: string,
159
+ oacl: FxORMPluginUACLNS.ACLNode['oacl'],
160
+ opts?: {
161
+ puaci?: string
162
+ }
163
+ ) {
164
+ const { puaci = null } = opts || {}
165
+
166
+ let pnode: any
167
+ if (puaci && (pnode = findACLNode(this, puaci))) {}
168
+ else
169
+ pnode = this.root
170
+
171
+ uaci = normalizeUaci(uaci)
172
+
173
+ ;[null].forEach(() => {
174
+ let node: any = findACLNode(this, uaci)
175
+ if (!node)
176
+ node = pnode.addChildNode(
177
+ new ACLNode({
178
+ id: uaci,
179
+ data: {
180
+ id: this.type === 'user' ? this.name : null,
181
+ role: this.type === 'role' ? this.name : null
182
+ },
183
+ oacl
184
+ })
185
+ ) as unknown as ACLNode;
186
+
187
+ _setOACL(node, oacl)
188
+ });
189
+
190
+ return this;
191
+ }
192
+
193
+ reset () {
194
+ super.clear()
195
+
196
+ return this;
197
+ }
198
+
199
+ find ({ uaci = '' } : { uaci: string }): FxORMPluginUACLNS.ACLNode | null {
200
+ return findACLNode(this, uaci)
201
+ }
202
+ }
203
+
204
+ function _setOACL (node: FxORMPluginUACLNS.ACLNode, newOACL: ACLNode['oacl']) {
205
+ const {
206
+ write = undefined,
207
+ read = undefined,
208
+ delete: _del = undefined,
209
+ } = {
210
+ ...node.oacl,
211
+ ...newOACL
212
+ }
213
+
214
+ const oacl: ACLNode['oacl'] = {
215
+ write: write,
216
+ read: read,
217
+ delete: _del,
218
+ }
219
+
220
+ node.oacl = oacl
221
+ }
222
+
223
+ export class ACLNode extends Node<FxORMPluginUACLNS.ACLNode['data']> implements FxORMPluginUACLNS.ACLNode {
224
+ declare data: FxORMPluginUACLNS.ACLNode['data']
225
+ oacl!: FxORMPluginUACLNS.ACLNode['oacl']
226
+
227
+ declare root: FxORMPluginUACLNS.Node<any, FxORMPluginUACLNS.ACLTree>['root']
228
+
229
+ static looseNodeOf (tree: FxORMPluginUACLNS.ACLTree, cfg: FxORMPluginUACLNS.ACLNodeConstructorOptions) {
230
+ const node = new ACLNode(cfg)
231
+ node.root = tree.root as ACLNode['root']
232
+
233
+ return node;
234
+ }
235
+
236
+ constructor (cfg: FxORMPluginUACLNS.ACLNodeConstructorOptions) {
237
+ cfg.data = {...cfg.data}
238
+
239
+ super({
240
+ id: cfg.id,
241
+ parent: cfg.parent,
242
+ children: cfg.children,
243
+ data: cfg.data
244
+ })
245
+
246
+ _setOACL(this, cfg.oacl)
247
+ }
248
+
249
+ /**
250
+ * @default_async
251
+ * @description data to storage
252
+ */
253
+ push (
254
+ {
255
+ type = null as any,
256
+ id = null
257
+ }: {
258
+ type: FxORMPluginUACLInternal.ACLStorageItem['target']['type'],
259
+ id: FxOrmNS.Arraible<FxORMPluginUACLInternal.ACLStorageItem['target']['id']>
260
+ },
261
+ opts?: FxORMPluginUACLNS.ACLNodePushOpts
262
+ ) {
263
+ const { sync = false } = opts || {};
264
+
265
+ const data = {
266
+ id: type === 'user' ? id : null,
267
+ role: type === 'role' ? id : []
268
+ }
269
+
270
+ const msg = generateGrantMessage(this, {
271
+ uid: data.id,
272
+ role: data.role,
273
+ })
274
+
275
+ const evt = new coroutine.Event()
276
+
277
+ const handler = () => {
278
+ const { success, error } = msg.json() as FxORMPluginUACLInternal.ACLMessageResult<FxORMPluginUACLInternal.ACLStorageItem[]>
279
+
280
+ if (success && success.code === 'pending') {
281
+ return
282
+ } else if (error) {
283
+ console.error('error', error);
284
+ }
285
+
286
+ evt.set()
287
+ }
288
+
289
+ coroutine.start(() => {
290
+ mq.invoke(this.root.tree.routing, msg);
291
+
292
+ handler()
293
+ })
294
+
295
+ if (sync) evt.wait()
296
+ }
297
+
298
+ /**
299
+ * @default_sync
300
+ * @description pull data about uaci(this.id)
301
+ *
302
+ * if no data corresponding in persist-end, remove this node in tree
303
+ */
304
+ pull (
305
+ opts?: FxORMPluginUACLNS.ACLNodePullOpts
306
+ ) {
307
+ const { sync = true } = opts || {};
308
+
309
+ const msg = generateLoadMessage(this.id, {
310
+ uid: this.root.tree.name,
311
+ role: [],
312
+ uacis: []
313
+ })
314
+
315
+ const evt = new coroutine.Event()
316
+
317
+ const handler = () => {
318
+ const { success, error } = msg.json() as FxORMPluginUACLInternal.ACLMessageResult<FxORMPluginUACLInternal.ACLStorageItem[]>
319
+
320
+ if (success && success.code === 'pending') {
321
+ return
322
+ } else if (error) {
323
+ console.error('error', error);
324
+ evt.set()
325
+ return
326
+ }
327
+
328
+ const { data: aclInfos = [] } = success || {}
329
+ /**
330
+ * @TODO: update the whole tree for `root.tree.type+root.tree.name` once
331
+ */
332
+ const sync_lock = new coroutine.Lock()
333
+ sync_lock.acquire()
334
+ aclInfos.forEach((item: FxORMPluginUACLInternal.ACLStorageItem) => {
335
+ if (item.target.type !== this.root.tree.type)
336
+ return ;
337
+
338
+ if (item.target.id !== this.root.tree.name)
339
+ return ;
340
+
341
+ this.root.tree.grant(item.uaci, {
342
+ write: item.write,
343
+ read: item.read,
344
+ delete: item.delete
345
+ })
346
+ })
347
+ sync_lock.release()
348
+
349
+ evt.set()
350
+ }
351
+
352
+ coroutine.start(() => {
353
+ mq.invoke(this.root.tree.routing, msg);
354
+
355
+ handler()
356
+ })
357
+
358
+ if (sync) evt.wait()
359
+ }
360
+
361
+ /**
362
+ * @default_sync
363
+ * @description pull data about uaci(this.id)
364
+ *
365
+ * if no data corresponding in persist-end, remove this node in tree
366
+ */
367
+ revoke (
368
+ opts?: FxORMPluginUACLNS.ACLNodeRevokeOpts
369
+ ) {
370
+ const tree = this.root.tree;
371
+
372
+ // remove local data firstly
373
+ this.remove();
374
+
375
+ const { sync = true } = opts || {};
376
+
377
+ const { uids: uid, roles: role } = getIdsFromTree(tree)
378
+ const msg = generateRevokeByUACIMessage(this, {uid, role})
379
+
380
+ const evt = new coroutine.Event()
381
+
382
+ const handler = () => {
383
+ const { success, error } = msg.json() as FxORMPluginUACLInternal.ACLMessageResult<FxORMPluginUACLInternal.ACLStorageItem[]>
384
+
385
+ if (success && success.code === 'pending') {
386
+ return
387
+ } else if (error) {
388
+ console.error('error', error);
389
+ evt.set()
390
+ return
391
+ }
392
+
393
+ /**
394
+ * @TODO: update the whole tree for `root.tree.type+root.tree.name` once
395
+ */
396
+ evt.set()
397
+ }
398
+
399
+ coroutine.start(() => {
400
+ mq.invoke(tree.routing, msg);
401
+
402
+ handler()
403
+ })
404
+
405
+ if (sync) evt.wait()
406
+ }
407
+
408
+ /**
409
+ * @local_computation
410
+ */
411
+ could (action: FxORMPluginUACLNS.ACLKeyType, uaci: string, askedFields: any[]) {
412
+ const node = this;
413
+
414
+ const oacl = node.oacl[action as keyof ACLNode['oacl']]
415
+
416
+ if (!oacl)
417
+ return false;
418
+
419
+ if (oacl === true)
420
+ return true;
421
+
422
+ if (!askedFields || !askedFields.length)
423
+ return false;
424
+
425
+ let permissonedFields: any[] = ([] as any[])
426
+ .concat(
427
+ Array.isArray(oacl) ? oacl : []
428
+ )
429
+
430
+ if (!permissonedFields.length)
431
+ return false;
432
+
433
+ if (askedFields.length > permissonedFields.length)
434
+ return false
435
+
436
+ const diff = util.difference(askedFields, permissonedFields)
437
+
438
+ return !diff.length;
439
+ }
440
+ }