@entity-access/entity-access 1.0.377 → 1.0.379

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 (264) hide show
  1. package/dist/compiler/postgres/PostgreSqlMethodTransformer.d.ts.map +1 -1
  2. package/dist/compiler/postgres/PostgreSqlMethodTransformer.js +27 -1
  3. package/dist/compiler/postgres/PostgreSqlMethodTransformer.js.map +1 -1
  4. package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.d.ts.map +1 -1
  5. package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.js +26 -0
  6. package/dist/compiler/sql-server/SqlServerSqlMethodTransformer.js.map +1 -1
  7. package/dist/drivers/postgres/PostgreSqlDriver.d.ts.map +1 -1
  8. package/dist/drivers/postgres/PostgreSqlDriver.js +1 -0
  9. package/dist/drivers/postgres/PostgreSqlDriver.js.map +1 -1
  10. package/dist/model/EntityQuery.d.ts.map +1 -1
  11. package/dist/model/EntityQuery.js +10 -0
  12. package/dist/model/EntityQuery.js.map +1 -1
  13. package/dist/model/IFilterWithParameter.d.ts +5 -5
  14. package/dist/model/IFilterWithParameter.d.ts.map +1 -1
  15. package/dist/sql/ISql.d.ts +10 -0
  16. package/dist/sql/ISql.d.ts.map +1 -1
  17. package/dist/tsconfig.tsbuildinfo +1 -1
  18. package/package.json +2 -2
  19. package/src/compiler/postgres/PostgreSqlMethodTransformer.ts +27 -1
  20. package/src/compiler/sql-server/SqlServerSqlMethodTransformer.ts +26 -0
  21. package/src/drivers/postgres/PostgreSqlDriver.ts +1 -0
  22. package/src/model/EntityQuery.ts +11 -1
  23. package/src/model/IFilterWithParameter.ts +5 -5
  24. package/src/sql/ISql.ts +11 -0
  25. package/dist/tests/TestConfig.d.ts +0 -6
  26. package/dist/tests/TestConfig.d.ts.map +0 -1
  27. package/dist/tests/TestConfig.js +0 -3
  28. package/dist/tests/TestConfig.js.map +0 -1
  29. package/dist/tests/db-tests/tests/check-constraint-test.d.ts +0 -3
  30. package/dist/tests/db-tests/tests/check-constraint-test.d.ts.map +0 -1
  31. package/dist/tests/db-tests/tests/check-constraint-test.js +0 -25
  32. package/dist/tests/db-tests/tests/check-constraint-test.js.map +0 -1
  33. package/dist/tests/db-tests/tests/delete-items.d.ts +0 -3
  34. package/dist/tests/db-tests/tests/delete-items.d.ts.map +0 -1
  35. package/dist/tests/db-tests/tests/delete-items.js +0 -25
  36. package/dist/tests/db-tests/tests/delete-items.js.map +0 -1
  37. package/dist/tests/db-tests/tests/filtered-include-items.d.ts +0 -3
  38. package/dist/tests/db-tests/tests/filtered-include-items.d.ts.map +0 -1
  39. package/dist/tests/db-tests/tests/filtered-include-items.js +0 -19
  40. package/dist/tests/db-tests/tests/filtered-include-items.js.map +0 -1
  41. package/dist/tests/db-tests/tests/insert-into.d.ts +0 -3
  42. package/dist/tests/db-tests/tests/insert-into.d.ts.map +0 -1
  43. package/dist/tests/db-tests/tests/insert-into.js +0 -17
  44. package/dist/tests/db-tests/tests/insert-into.js.map +0 -1
  45. package/dist/tests/db-tests/tests/multi-fk-tests.d.ts +0 -3
  46. package/dist/tests/db-tests/tests/multi-fk-tests.d.ts.map +0 -1
  47. package/dist/tests/db-tests/tests/multi-fk-tests.js +0 -29
  48. package/dist/tests/db-tests/tests/multi-fk-tests.js.map +0 -1
  49. package/dist/tests/db-tests/tests/select-identity.d.ts +0 -3
  50. package/dist/tests/db-tests/tests/select-identity.d.ts.map +0 -1
  51. package/dist/tests/db-tests/tests/select-identity.js +0 -16
  52. package/dist/tests/db-tests/tests/select-identity.js.map +0 -1
  53. package/dist/tests/db-tests/tests/select-inverse-one-to-one.d.ts +0 -3
  54. package/dist/tests/db-tests/tests/select-inverse-one-to-one.d.ts.map +0 -1
  55. package/dist/tests/db-tests/tests/select-inverse-one-to-one.js +0 -27
  56. package/dist/tests/db-tests/tests/select-inverse-one-to-one.js.map +0 -1
  57. package/dist/tests/db-tests/tests/select-items-map.d.ts +0 -3
  58. package/dist/tests/db-tests/tests/select-items-map.d.ts.map +0 -1
  59. package/dist/tests/db-tests/tests/select-items-map.js +0 -28
  60. package/dist/tests/db-tests/tests/select-items-map.js.map +0 -1
  61. package/dist/tests/db-tests/tests/select-items-sum.d.ts +0 -3
  62. package/dist/tests/db-tests/tests/select-items-sum.d.ts.map +0 -1
  63. package/dist/tests/db-tests/tests/select-items-sum.js +0 -46
  64. package/dist/tests/db-tests/tests/select-items-sum.js.map +0 -1
  65. package/dist/tests/db-tests/tests/select-items.d.ts +0 -3
  66. package/dist/tests/db-tests/tests/select-items.d.ts.map +0 -1
  67. package/dist/tests/db-tests/tests/select-items.js +0 -30
  68. package/dist/tests/db-tests/tests/select-items.js.map +0 -1
  69. package/dist/tests/db-tests/tests/select-map.d.ts +0 -3
  70. package/dist/tests/db-tests/tests/select-map.d.ts.map +0 -1
  71. package/dist/tests/db-tests/tests/select-map.js +0 -12
  72. package/dist/tests/db-tests/tests/select-map.js.map +0 -1
  73. package/dist/tests/db-tests/tests/select-nested.d.ts +0 -3
  74. package/dist/tests/db-tests/tests/select-nested.d.ts.map +0 -1
  75. package/dist/tests/db-tests/tests/select-nested.js +0 -25
  76. package/dist/tests/db-tests/tests/select-nested.js.map +0 -1
  77. package/dist/tests/db-tests/tests/select-parent.d.ts +0 -3
  78. package/dist/tests/db-tests/tests/select-parent.d.ts.map +0 -1
  79. package/dist/tests/db-tests/tests/select-parent.js +0 -17
  80. package/dist/tests/db-tests/tests/select-parent.js.map +0 -1
  81. package/dist/tests/db-tests/tests/select-related.d.ts +0 -3
  82. package/dist/tests/db-tests/tests/select-related.d.ts.map +0 -1
  83. package/dist/tests/db-tests/tests/select-related.js +0 -20
  84. package/dist/tests/db-tests/tests/select-related.js.map +0 -1
  85. package/dist/tests/db-tests/tests/update-items.d.ts +0 -3
  86. package/dist/tests/db-tests/tests/update-items.d.ts.map +0 -1
  87. package/dist/tests/db-tests/tests/update-items.js +0 -31
  88. package/dist/tests/db-tests/tests/update-items.js.map +0 -1
  89. package/dist/tests/db-tests/tests/update-select.d.ts +0 -3
  90. package/dist/tests/db-tests/tests/update-select.d.ts.map +0 -1
  91. package/dist/tests/db-tests/tests/update-select.js +0 -19
  92. package/dist/tests/db-tests/tests/update-select.js.map +0 -1
  93. package/dist/tests/db-tests/tests/upsert-test.d.ts +0 -3
  94. package/dist/tests/db-tests/tests/upsert-test.d.ts.map +0 -1
  95. package/dist/tests/db-tests/tests/upsert-test.js +0 -31
  96. package/dist/tests/db-tests/tests/upsert-test.js.map +0 -1
  97. package/dist/tests/db-tests/tests/version-history.d.ts +0 -3
  98. package/dist/tests/db-tests/tests/version-history.d.ts.map +0 -1
  99. package/dist/tests/db-tests/tests/version-history.js +0 -16
  100. package/dist/tests/db-tests/tests/version-history.js.map +0 -1
  101. package/dist/tests/db-tests/transaction-save-point/transaction-save-point.d.ts +0 -3
  102. package/dist/tests/db-tests/transaction-save-point/transaction-save-point.d.ts.map +0 -1
  103. package/dist/tests/db-tests/transaction-save-point/transaction-save-point.js +0 -58
  104. package/dist/tests/db-tests/transaction-save-point/transaction-save-point.js.map +0 -1
  105. package/dist/tests/drivers/postgres/connection-test.d.ts +0 -3
  106. package/dist/tests/drivers/postgres/connection-test.d.ts.map +0 -1
  107. package/dist/tests/drivers/postgres/connection-test.js +0 -40
  108. package/dist/tests/drivers/postgres/connection-test.js.map +0 -1
  109. package/dist/tests/drivers/sql-server/sql-server-test.d.ts +0 -2
  110. package/dist/tests/drivers/sql-server/sql-server-test.d.ts.map +0 -1
  111. package/dist/tests/drivers/sql-server/sql-server-test.js +0 -6
  112. package/dist/tests/drivers/sql-server/sql-server-test.js.map +0 -1
  113. package/dist/tests/eternity/child-tests.d.ts +0 -3
  114. package/dist/tests/eternity/child-tests.d.ts.map +0 -1
  115. package/dist/tests/eternity/child-tests.js +0 -97
  116. package/dist/tests/eternity/child-tests.js.map +0 -1
  117. package/dist/tests/eternity/eternity-tests.d.ts +0 -3
  118. package/dist/tests/eternity/eternity-tests.d.ts.map +0 -1
  119. package/dist/tests/eternity/eternity-tests.js +0 -85
  120. package/dist/tests/eternity/eternity-tests.js.map +0 -1
  121. package/dist/tests/eternity/external-event-tests.d.ts +0 -3
  122. package/dist/tests/eternity/external-event-tests.d.ts.map +0 -1
  123. package/dist/tests/eternity/external-event-tests.js +0 -108
  124. package/dist/tests/eternity/external-event-tests.js.map +0 -1
  125. package/dist/tests/eternity/throttle-tests.d.ts +0 -3
  126. package/dist/tests/eternity/throttle-tests.d.ts.map +0 -1
  127. package/dist/tests/eternity/throttle-tests.js +0 -86
  128. package/dist/tests/eternity/throttle-tests.js.map +0 -1
  129. package/dist/tests/expressions/left-joins/child-joins.d.ts +0 -2
  130. package/dist/tests/expressions/left-joins/child-joins.d.ts.map +0 -1
  131. package/dist/tests/expressions/left-joins/child-joins.js +0 -114
  132. package/dist/tests/expressions/left-joins/child-joins.js.map +0 -1
  133. package/dist/tests/expressions/sanitize/sanitize-test.d.ts +0 -2
  134. package/dist/tests/expressions/sanitize/sanitize-test.d.ts.map +0 -1
  135. package/dist/tests/expressions/sanitize/sanitize-test.js +0 -8
  136. package/dist/tests/expressions/sanitize/sanitize-test.js.map +0 -1
  137. package/dist/tests/expressions/select/select.d.ts +0 -2
  138. package/dist/tests/expressions/select/select.d.ts.map +0 -1
  139. package/dist/tests/expressions/select/select.js +0 -11
  140. package/dist/tests/expressions/select/select.js.map +0 -1
  141. package/dist/tests/expressions/self-joins/self-joins.d.ts +0 -2
  142. package/dist/tests/expressions/self-joins/self-joins.d.ts.map +0 -1
  143. package/dist/tests/expressions/self-joins/self-joins.js +0 -14
  144. package/dist/tests/expressions/self-joins/self-joins.js.map +0 -1
  145. package/dist/tests/expressions/simple/parse-array.d.ts +0 -2
  146. package/dist/tests/expressions/simple/parse-array.d.ts.map +0 -1
  147. package/dist/tests/expressions/simple/parse-array.js +0 -21
  148. package/dist/tests/expressions/simple/parse-array.js.map +0 -1
  149. package/dist/tests/expressions/simple/parse-arrow.d.ts +0 -2
  150. package/dist/tests/expressions/simple/parse-arrow.d.ts.map +0 -1
  151. package/dist/tests/expressions/simple/parse-arrow.js +0 -36
  152. package/dist/tests/expressions/simple/parse-arrow.js.map +0 -1
  153. package/dist/tests/expressions/simple/parse-complex.d.ts +0 -2
  154. package/dist/tests/expressions/simple/parse-complex.d.ts.map +0 -1
  155. package/dist/tests/expressions/simple/parse-complex.js +0 -11
  156. package/dist/tests/expressions/simple/parse-complex.js.map +0 -1
  157. package/dist/tests/expressions/trimInternal.d.ts +0 -3
  158. package/dist/tests/expressions/trimInternal.d.ts.map +0 -1
  159. package/dist/tests/expressions/trimInternal.js +0 -24
  160. package/dist/tests/expressions/trimInternal.js.map +0 -1
  161. package/dist/tests/model/ShoppingContext.d.ts +0 -140
  162. package/dist/tests/model/ShoppingContext.d.ts.map +0 -1
  163. package/dist/tests/model/ShoppingContext.js +0 -440
  164. package/dist/tests/model/ShoppingContext.js.map +0 -1
  165. package/dist/tests/model/UseFile.d.ts +0 -8
  166. package/dist/tests/model/UseFile.d.ts.map +0 -1
  167. package/dist/tests/model/UseFile.js +0 -25
  168. package/dist/tests/model/UseFile.js.map +0 -1
  169. package/dist/tests/model/createContext.d.ts +0 -6
  170. package/dist/tests/model/createContext.d.ts.map +0 -1
  171. package/dist/tests/model/createContext.js +0 -327
  172. package/dist/tests/model/createContext.js.map +0 -1
  173. package/dist/tests/pool/pool-test.d.ts +0 -2
  174. package/dist/tests/pool/pool-test.d.ts.map +0 -1
  175. package/dist/tests/pool/pool-test.js +0 -66
  176. package/dist/tests/pool/pool-test.js.map +0 -1
  177. package/dist/tests/query/combine.d.ts +0 -2
  178. package/dist/tests/query/combine.d.ts.map +0 -1
  179. package/dist/tests/query/combine.js +0 -20
  180. package/dist/tests/query/combine.js.map +0 -1
  181. package/dist/tests/security/ShoppingContextEvents.d.ts +0 -5
  182. package/dist/tests/security/ShoppingContextEvents.d.ts.map +0 -1
  183. package/dist/tests/security/ShoppingContextEvents.js +0 -20
  184. package/dist/tests/security/ShoppingContextEvents.js.map +0 -1
  185. package/dist/tests/security/events/OrderEvents.d.ts +0 -17
  186. package/dist/tests/security/events/OrderEvents.d.ts.map +0 -1
  187. package/dist/tests/security/events/OrderEvents.js +0 -62
  188. package/dist/tests/security/events/OrderEvents.js.map +0 -1
  189. package/dist/tests/security/events/ProductEvents.d.ts +0 -23
  190. package/dist/tests/security/events/ProductEvents.d.ts.map +0 -1
  191. package/dist/tests/security/events/ProductEvents.js +0 -79
  192. package/dist/tests/security/events/ProductEvents.js.map +0 -1
  193. package/dist/tests/security/events/UserEvents.d.ts +0 -10
  194. package/dist/tests/security/events/UserEvents.d.ts.map +0 -1
  195. package/dist/tests/security/events/UserEvents.js +0 -26
  196. package/dist/tests/security/events/UserEvents.js.map +0 -1
  197. package/dist/tests/security/events/UserFileEvents.d.ts +0 -7
  198. package/dist/tests/security/events/UserFileEvents.d.ts.map +0 -1
  199. package/dist/tests/security/events/UserFileEvents.js +0 -7
  200. package/dist/tests/security/events/UserFileEvents.js.map +0 -1
  201. package/dist/tests/security/events/UserInfo.d.ts +0 -5
  202. package/dist/tests/security/events/UserInfo.d.ts.map +0 -1
  203. package/dist/tests/security/events/UserInfo.js +0 -9
  204. package/dist/tests/security/events/UserInfo.js.map +0 -1
  205. package/dist/tests/security/tests/include-items.d.ts +0 -3
  206. package/dist/tests/security/tests/include-items.d.ts.map +0 -1
  207. package/dist/tests/security/tests/include-items.js +0 -15
  208. package/dist/tests/security/tests/include-items.js.map +0 -1
  209. package/dist/tests/security/tests/place-order.d.ts +0 -3
  210. package/dist/tests/security/tests/place-order.d.ts.map +0 -1
  211. package/dist/tests/security/tests/place-order.js +0 -139
  212. package/dist/tests/security/tests/place-order.js.map +0 -1
  213. package/dist/tests/security/tests/test-events.d.ts +0 -3
  214. package/dist/tests/security/tests/test-events.d.ts.map +0 -1
  215. package/dist/tests/security/tests/test-events.js +0 -54
  216. package/dist/tests/security/tests/test-events.js.map +0 -1
  217. package/src/tests/TestConfig.ts +0 -6
  218. package/src/tests/db-tests/tests/check-constraint-test.ts +0 -32
  219. package/src/tests/db-tests/tests/delete-items.ts +0 -42
  220. package/src/tests/db-tests/tests/filtered-include-items.ts +0 -28
  221. package/src/tests/db-tests/tests/insert-into.ts +0 -24
  222. package/src/tests/db-tests/tests/multi-fk-tests.ts +0 -37
  223. package/src/tests/db-tests/tests/select-identity.ts +0 -23
  224. package/src/tests/db-tests/tests/select-inverse-one-to-one.ts +0 -39
  225. package/src/tests/db-tests/tests/select-items-map.ts +0 -38
  226. package/src/tests/db-tests/tests/select-items-sum.ts +0 -60
  227. package/src/tests/db-tests/tests/select-items.ts +0 -49
  228. package/src/tests/db-tests/tests/select-map.ts +0 -19
  229. package/src/tests/db-tests/tests/select-nested.ts +0 -36
  230. package/src/tests/db-tests/tests/select-parent.ts +0 -25
  231. package/src/tests/db-tests/tests/select-related.ts +0 -35
  232. package/src/tests/db-tests/tests/update-items.ts +0 -44
  233. package/src/tests/db-tests/tests/update-select.ts +0 -28
  234. package/src/tests/db-tests/tests/upsert-test.ts +0 -48
  235. package/src/tests/db-tests/tests/version-history.ts +0 -24
  236. package/src/tests/db-tests/transaction-save-point/transaction-save-point.ts +0 -48
  237. package/src/tests/drivers/postgres/connection-test.ts +0 -39
  238. package/src/tests/drivers/sql-server/sql-server-test.ts +0 -9
  239. package/src/tests/eternity/child-tests.ts +0 -119
  240. package/src/tests/eternity/eternity-tests.ts +0 -108
  241. package/src/tests/eternity/external-event-tests.ts +0 -133
  242. package/src/tests/eternity/throttle-tests.ts +0 -100
  243. package/src/tests/expressions/left-joins/child-joins.ts +0 -131
  244. package/src/tests/expressions/sanitize/sanitize-test.ts +0 -17
  245. package/src/tests/expressions/select/select.ts +0 -21
  246. package/src/tests/expressions/self-joins/self-joins.ts +0 -23
  247. package/src/tests/expressions/simple/parse-array.ts +0 -31
  248. package/src/tests/expressions/simple/parse-arrow.ts +0 -65
  249. package/src/tests/expressions/simple/parse-complex.ts +0 -20
  250. package/src/tests/expressions/trimInternal.ts +0 -25
  251. package/src/tests/model/ShoppingContext.ts +0 -435
  252. package/src/tests/model/UseFile.ts +0 -24
  253. package/src/tests/model/createContext.ts +0 -367
  254. package/src/tests/pool/pool-test.ts +0 -79
  255. package/src/tests/query/combine.ts +0 -28
  256. package/src/tests/security/ShoppingContextEvents.ts +0 -23
  257. package/src/tests/security/events/OrderEvents.ts +0 -72
  258. package/src/tests/security/events/ProductEvents.ts +0 -102
  259. package/src/tests/security/events/UserEvents.ts +0 -28
  260. package/src/tests/security/events/UserFileEvents.ts +0 -11
  261. package/src/tests/security/events/UserInfo.ts +0 -7
  262. package/src/tests/security/tests/include-items.ts +0 -20
  263. package/src/tests/security/tests/place-order.ts +0 -138
  264. package/src/tests/security/tests/test-events.ts +0 -55
@@ -1,108 +0,0 @@
1
- import assert from "assert";
2
- import Inject, { Register, RegisterSingleton, ServiceProvider } from "../../di/di.js";
3
- import WorkflowContext from "../../workflows/WorkflowContext.js";
4
- import Workflow, { Activity } from "../../workflows/Workflow.js";
5
- import WorkflowClock from "../../workflows/WorkflowClock.js";
6
- import DateTime from "../../types/DateTime.js";
7
- import { TestConfig } from "../TestConfig.js";
8
- import { BaseDriver } from "../../drivers/base/BaseDriver.js";
9
- import WorkflowStorage from "../../workflows/WorkflowStorage.js";
10
- import TimeSpan from "../../types/TimeSpan.js";
11
- import sleep from "../../common/sleep.js";
12
-
13
- class MockClock extends WorkflowClock {
14
-
15
- public get utcNow(): DateTime {
16
- return this.time;
17
- }
18
-
19
- public set utcNow(v: DateTime) {
20
- this.time = v;
21
- }
22
-
23
- private time: DateTime = DateTime.now;
24
-
25
- public add(ts: TimeSpan) {
26
- this.time = this.time.add(ts);
27
- return this;
28
- }
29
- }
30
-
31
- @RegisterSingleton
32
- class Mailer {
33
-
34
- public items: any[] = [];
35
- }
36
-
37
- class SendWorkflow extends Workflow<string, string> {
38
-
39
- public async run(): Promise<any> {
40
-
41
- await this.delay(TimeSpan.fromHours(1));
42
-
43
- await this.sendMail("a", "b", "c");
44
- return "1";
45
- }
46
-
47
- @Activity
48
- public async sendMail(
49
- from: string,
50
- to: string,
51
- message: string,
52
- @Inject logger?: Mailer) {
53
- await sleep(10);
54
- logger.items.push({ from, to, message });
55
- }
56
-
57
- }
58
-
59
- export default async function (this: TestConfig) {
60
-
61
- const mockClock = new MockClock();
62
- const mailer = new Mailer();
63
-
64
- const scope = new ServiceProvider();
65
- scope.add(WorkflowClock, mockClock);
66
- scope.add(BaseDriver, this.driver);
67
- const storage = new WorkflowStorage(this.driver, mockClock);
68
- scope.add(Mailer, mailer);
69
- scope.add(WorkflowStorage, storage);
70
-
71
- const c = new WorkflowContext(storage);
72
- scope.add(WorkflowContext, c);
73
-
74
- // this is an important step
75
- c.register(SendWorkflow);
76
-
77
- await storage.seed();
78
-
79
- const id = await c.queue(SendWorkflow, "a");
80
-
81
- mockClock.add(TimeSpan.fromSeconds(15));
82
-
83
- await c.processQueueOnce();
84
-
85
- mockClock.add(TimeSpan.fromSeconds(15));
86
-
87
- await c.processQueueOnce();
88
-
89
- assert.equal(0, mailer.items.length);
90
-
91
- mockClock.add(TimeSpan.fromHours(1));
92
-
93
- await c.processQueueOnce();
94
-
95
- assert.equal(1, mailer.items.length);
96
-
97
- let r = await c.get(SendWorkflow, id);
98
- assert.equal("1", r.output);
99
-
100
- mockClock.add(TimeSpan.fromDays(2));
101
-
102
- await c.processQueueOnce();
103
-
104
- r = await c.get(SendWorkflow, id);
105
- assert.strictEqual(null, r);
106
-
107
- // throw new Error("Preserve");
108
- }
@@ -1,133 +0,0 @@
1
- /* eslint-disable no-console */
2
- import assert from "assert";
3
- import Inject, { Register, RegisterScoped, RegisterSingleton, ServiceProvider } from "../../di/di.js";
4
- import WorkflowContext from "../../workflows/WorkflowContext.js";
5
- import Workflow, { Activity } from "../../workflows/Workflow.js";
6
- import WorkflowClock from "../../workflows/WorkflowClock.js";
7
- import DateTime from "../../types/DateTime.js";
8
- import { TestConfig } from "../TestConfig.js";
9
- import { BaseDriver } from "../../drivers/base/BaseDriver.js";
10
- import WorkflowStorage from "../../workflows/WorkflowStorage.js";
11
- import TimeSpan from "../../types/TimeSpan.js";
12
- import sleep from "../../common/sleep.js";
13
-
14
- class MockClock extends WorkflowClock {
15
-
16
- public get utcNow(): DateTime {
17
- return this.time;
18
- }
19
-
20
- public set utcNow(v: DateTime) {
21
- this.time = v;
22
- }
23
-
24
- private time: DateTime = DateTime.now;
25
-
26
- public add(ts: TimeSpan) {
27
- this.time = this.time.add(ts);
28
- return this;
29
- }
30
- }
31
-
32
- @RegisterSingleton
33
- class StateLogger {
34
- state: string;
35
- }
36
-
37
- class VerifyWorkflow extends Workflow<string, string> {
38
-
39
- public async run() {
40
-
41
- const ts = TimeSpan.fromSeconds(15);
42
-
43
- for (let index = 0; index < 5; index++) {
44
- const { name, result } = await this.waitForExternalEvent(ts, "verify", "resend");
45
- switch(name) {
46
- case "verify":
47
- await this.log("verify");
48
- if (result === this.input) {
49
- return "ok";
50
- }
51
- break;
52
- case "resend":
53
- // do something...
54
- await this.delay(TimeSpan.fromSeconds(1));
55
- await this.log("resend");
56
- break;
57
- }
58
- }
59
-
60
- return "failed";
61
- }
62
-
63
- @Activity
64
- async log(
65
- state: string,
66
- @Inject stateLogger?: StateLogger
67
- ) {
68
- console.log(`${state} logged`);
69
- stateLogger.state = state;
70
- }
71
-
72
- }
73
-
74
- export default async function (this: TestConfig) {
75
-
76
- const mockClock = new MockClock();
77
- const stateLogger = new StateLogger();
78
- const scope = new ServiceProvider();
79
- scope.add(WorkflowClock, mockClock);
80
- scope.add(BaseDriver, this.driver);
81
- scope.add(StateLogger, stateLogger);
82
- const storage = new WorkflowStorage(this.driver, mockClock);
83
- scope.add(WorkflowStorage, storage);
84
-
85
- const c = new WorkflowContext(storage);
86
- scope.add(WorkflowContext, c);
87
-
88
- // this is an important step
89
- c.register(VerifyWorkflow);
90
-
91
- await storage.seed();
92
-
93
- const id = await c.queue(VerifyWorkflow, "a");
94
-
95
- mockClock.add(TimeSpan.fromSeconds(5));
96
-
97
- await c.processQueueOnce();
98
-
99
- let w = await c.get(VerifyWorkflow, id);
100
- assert.equal("queued", w.state);
101
-
102
- mockClock.add(TimeSpan.fromSeconds(5));
103
- await c.processQueueOnce();
104
-
105
- w = await c.get(VerifyWorkflow, id);
106
- assert.equal("queued", w.state);
107
-
108
- await c.raiseEvent(id, { name: "resend"});
109
- mockClock.add(TimeSpan.fromSeconds(5));
110
- await c.processQueueOnce();
111
-
112
- assert.equal("resend", stateLogger.state);
113
-
114
- w = await c.get(VerifyWorkflow, id);
115
- assert.equal("queued", w.state);
116
-
117
- mockClock.add(TimeSpan.fromSeconds(5));
118
- await c.raiseEvent(id, { name: "verify", result: "a"});
119
- mockClock.add(TimeSpan.fromSeconds(5));
120
- await c.processQueueOnce();
121
- assert.equal("verify", stateLogger.state);
122
-
123
- w = await c.get(VerifyWorkflow, id);
124
- assert.equal("done", w.state);
125
-
126
- mockClock.add(TimeSpan.fromDays(1));
127
- await c.processQueueOnce();
128
-
129
- // make sure workflow is deleted...
130
-
131
- w = await c.get(VerifyWorkflow, id);
132
- assert.equal(null, w);
133
- }
@@ -1,100 +0,0 @@
1
- import assert from "assert";
2
- import Inject, { Register, RegisterSingleton, ServiceProvider } from "../../di/di.js";
3
- import WorkflowContext from "../../workflows/WorkflowContext.js";
4
- import Workflow, { Activity } from "../../workflows/Workflow.js";
5
- import WorkflowClock from "../../workflows/WorkflowClock.js";
6
- import DateTime from "../../types/DateTime.js";
7
- import { TestConfig } from "../TestConfig.js";
8
- import { BaseDriver } from "../../drivers/base/BaseDriver.js";
9
- import WorkflowStorage from "../../workflows/WorkflowStorage.js";
10
- import TimeSpan from "../../types/TimeSpan.js";
11
- import sleep from "../../common/sleep.js";
12
-
13
- class MockClock extends WorkflowClock {
14
-
15
- public get utcNow(): DateTime {
16
- return this.time;
17
- }
18
-
19
- public set utcNow(v: DateTime) {
20
- this.time = v;
21
- }
22
-
23
- private time: DateTime = DateTime.now;
24
-
25
- public add(ts: TimeSpan) {
26
- this.time = this.time.add(ts);
27
- return this;
28
- }
29
- }
30
-
31
- @RegisterSingleton
32
- class Mailer {
33
-
34
- public items: any[] = [];
35
- }
36
-
37
- class SendWorkflow extends Workflow<string, string> {
38
-
39
- public async run(): Promise<any> {
40
-
41
- await this.delay(TimeSpan.fromHours(1));
42
-
43
- await this.sendMail("a", "b", "c");
44
- return "1";
45
- }
46
-
47
- @Activity
48
- public async sendMail(
49
- from: string,
50
- to: string,
51
- message: string,
52
- @Inject logger?: Mailer) {
53
- await sleep(10);
54
- logger.items.push({ from, to, message });
55
- }
56
-
57
- }
58
-
59
- export default async function (this: TestConfig) {
60
-
61
- const mockClock = new MockClock();
62
- const mailer = new Mailer();
63
-
64
- const scope = new ServiceProvider();
65
- scope.add(WorkflowClock, mockClock);
66
- scope.add(BaseDriver, this.driver);
67
- const storage = new WorkflowStorage(this.driver, mockClock);
68
- scope.add(Mailer, mailer);
69
- scope.add(WorkflowStorage, storage);
70
-
71
- const c = new WorkflowContext(storage);
72
- scope.add(WorkflowContext, c);
73
-
74
- // this is an important step
75
- c.register(SendWorkflow);
76
-
77
- await storage.seed();
78
-
79
- const id = await c.queue(SendWorkflow, "a", {
80
- throttle: {
81
- group: "a",
82
- maxPerSecond: 1/15
83
- }
84
- });
85
-
86
- const result = await storage.getWorkflow(id);
87
-
88
- const next = await c.queue(SendWorkflow, "b", {
89
- throttle: {
90
- group: "a",
91
- maxPerSecond: 1/15
92
- }
93
- });
94
-
95
- const resultNext = await storage.getWorkflow(next);
96
- const span = DateTime.from(resultNext.eta).diff(DateTime.from(result.eta));
97
- assert(span.totalSeconds > 14);
98
-
99
- // throw new Error("Preserve");
100
- }
@@ -1,131 +0,0 @@
1
- import assert from "assert";
2
- import QueryCompiler from "../../../compiler/QueryCompiler.js";
3
- import { ShoppingContext } from "../../model/ShoppingContext.js";
4
- import { assertSqlMatch, trimInternal } from "../trimInternal.js";
5
- import PostgreSqlDriver from "../../../drivers/postgres/PostgreSqlDriver.js";
6
-
7
- const sql1 = `SELECT
8
- p1.product_id,
9
- p1.name,
10
- p1.owner_id,
11
- p1.status,
12
- p1.product_description
13
- FROM products AS p1
14
- WHERE EXISTS (SELECT
15
- 1
16
- FROM order_items AS o
17
- WHERE (o.product_id = $1) AND (p1.product_id = o.product_id))`;
18
-
19
- const sql2 = `SELECT
20
- p1.product_id,
21
- p1.name,
22
- p1.owner_id,
23
- p1.status,
24
- p1.product_description
25
- FROM products AS p1
26
- WHERE EXISTS (SELECT
27
- 1
28
- FROM order_items AS o
29
- WHERE (o.product_id = $1) AND (p1.product_id = o.product_id)) AND EXISTS (SELECT
30
- 1
31
- FROM order_items AS o1
32
- WHERE (o1.amount > $2) AND (p1.product_id = o1.product_id))`;
33
-
34
- const sql3 = `SELECT
35
- p1.product_id,
36
- p1.name,
37
- p1.owner_id,
38
- p1.status,
39
- p1.product_description
40
- FROM products AS p1
41
- WHERE EXISTS (SELECT
42
- 1
43
- FROM order_items AS o
44
- WHERE (o.product_id = $1) AND (p1.product_id = o.product_id)) AND EXISTS (SELECT
45
- 1
46
- FROM order_items AS o1
47
- INNER JOIN orders AS o2 ON o1.order_id = o2.order_id
48
- WHERE (o2.order_date > $2) AND (p1.product_id = o1.product_id))`;
49
-
50
- const productJoin = `SELECT
51
- p1.product_id,
52
- p1.name,
53
- p1.owner_id,
54
- p1.status,
55
- p1.product_description
56
- FROM products AS p1
57
- LEFT JOIN users AS u ON p1.owner_id = u.user_id
58
- WHERE u.date_created > $1`;
59
-
60
-
61
- const join2 = `SELECT
62
- o1.order_item_id,
63
- o1.order_id,
64
- o1.product_id,
65
- o1.price_id,
66
- o1.amount
67
- FROM order_items AS o1
68
- LEFT JOIN products AS p ON o1.product_id = p.product_id
69
- WHERE (o1.product_id = $1) OR (p.owner_id = $2)`;
70
-
71
- const notExp = `SELECT
72
- p1.product_id,
73
- p1.name,
74
- p1.owner_id,
75
- p1.status,
76
- p1.product_description
77
- FROM products AS p1
78
- WHERE EXISTS
79
- (SELECT 1 FROM order_items AS o
80
- WHERE (o.product_id = $1) AND (p1.product_id = o.product_id)) AND
81
- NOT (EXISTS (SELECT 1 FROM order_items AS o1
82
- INNER JOIN orders AS o2 ON o1.order_id = o2.order_id
83
- WHERE (o2.order_date > $2) AND (p1.product_id = o1.product_id)))
84
- `;
85
-
86
- export default function() {
87
-
88
- const context = new ShoppingContext(new PostgreSqlDriver({}));
89
- let query = context.products.where({ productID: 1 }, (p) => (x) => x.orderItems.some((o) => o.productID === p.productID));
90
-
91
- let r = query.toQuery();
92
- assertSqlMatch(sql1, r.text);
93
-
94
- const old = query;
95
- query = query.where({ amount: 200}, (p) => (x) => x.orderItems.some((o) => o.amount > p.amount));
96
- r = query.toQuery();
97
- assertSqlMatch(sql2, r.text);
98
-
99
- query = old.where({ date: new Date()}, (p) => (x) => x.orderItems.some((o) => o.order.orderDate > p.date));
100
- r = query.toQuery();
101
- assertSqlMatch(sql3, r.text);
102
-
103
- query = context.products.where({ date: new Date()}, (p) => (x) => x.owner.dateCreated > p.date);
104
- r = query.toQuery();
105
- assertSqlMatch(productJoin, r.text);
106
-
107
- const q = context.orderItems.where({ o: 1, owner: 1}, (p) => (x) => x.productID === p.o || x.product.ownerID === p.owner);
108
- r = q.toQuery();
109
- assertSqlMatch(join2, r.text);
110
-
111
- query = old.where({ date: new Date()}, (p) => (x) => !x.orderItems.some((o) => o.order.orderDate > p.date));
112
- r = query.toQuery();
113
- assertSqlMatch(notExp, r.text);
114
-
115
- query = old.selectView(void 0, (p) => (x) => ({
116
- productDescription: x.productDescription,
117
- ownerID: 0,
118
- }));
119
- r = query.toQuery();
120
- assertSqlMatch(`SELECT
121
- s."product_description",
122
- s."owner_id"
123
- FROM (SELECT
124
- p1."product_description",
125
- p1."owner_id"
126
- FROM products AS p1
127
- WHERE EXISTS (SELECT
128
- 1
129
- FROM order_items AS o
130
- WHERE (o.product_id = $1) AND (p1.product_id = o.product_id))) AS s`, r.text);
131
- }
@@ -1,17 +0,0 @@
1
- import assert from "assert";
2
- import QueryCompiler from "../../../compiler/QueryCompiler.js";
3
-
4
- declare let pg_kill: any;
5
-
6
- export default function () {
7
-
8
- const compiler = QueryCompiler.instance;
9
-
10
- const name = "Akash";
11
-
12
- assert.throws(()=>
13
- compiler.execute({ name }, (p) => (x) => pg_kill(9))
14
- );
15
-
16
-
17
- }
@@ -1,21 +0,0 @@
1
- import assert from "assert";
2
- import QueryCompiler from "../../../compiler/QueryCompiler.js";
3
-
4
- type ICustomer = { firstName: string; lastName: string; emailAddress: string; birthDate: Date };
5
-
6
- export default function() {
7
-
8
-
9
- const compiler = QueryCompiler.instance;
10
-
11
- const name = "Akash";
12
-
13
- let r = compiler.execute({ name }, (p) => ({ firstName, lastName, emailAddress }: ICustomer) => ({ emailAddress, name: `${firstName} ${lastName}` }));
14
-
15
- assert.strictEqual(`FROM (x1.emailAddress AS emailAddress,CONCAT(x1.firstName,' ',x1.lastName) AS name)`, r.text);
16
-
17
- r = compiler.execute({ name }, (p) => ({ id }) => ({ error: `${id > 0 ? "Error" : ""}` }));
18
-
19
- assert.strictEqual(`FROM (CONCAT((CASE WHEN x1.id > 0 THEN 'Error' ELSE '' END)) AS error)`, r.text);
20
-
21
- }
@@ -1,23 +0,0 @@
1
- import assert from "assert";
2
- import QueryCompiler from "../../../compiler/QueryCompiler.js";
3
- import { ShoppingContext } from "../../model/ShoppingContext.js";
4
- import { assertSqlMatch, trimInternal } from "../trimInternal.js";
5
- import PostgreSqlDriver from "../../../drivers/postgres/PostgreSqlDriver.js";
6
-
7
-
8
- export default function() {
9
-
10
- // const { driver } = this;
11
-
12
- // const context = new ShoppingContext(driver);
13
- // const c1 = "a";
14
- // const log = [];
15
- // let query = context.categories.where({ c1 }, (p) => (x) => x.categoryID === p.c1)
16
- // .include((x) => x.children)
17
- // .trace((x) => log.push(x))
18
- // .first();
19
-
20
- // for (const iterator of log) {
21
- // console.log(iterator);
22
- // }
23
- }
@@ -1,31 +0,0 @@
1
- import assert from "assert";
2
- import Sql from "../../../sql/Sql.js";
3
- import QueryCompiler from "../../../compiler/QueryCompiler.js";
4
-
5
- export default function () {
6
-
7
- const compiler = QueryCompiler.instance;
8
-
9
- const names = ["Akash", "Simmi"];
10
-
11
- let r = compiler.execute({ names }, (p) => (x) => Sql.in(x.firstName, p.names));
12
- assert.equal("x.firstName IN ($1,$2)", r.text);
13
-
14
- r = compiler.execute({ names }, (p) => (x) => x.firstName in p.names);
15
- assert.equal("x.firstName IN ($1,$2)", r.text);
16
-
17
- r = compiler.execute({ names }, (p) => (x) => x.firstName in ["a", "b"]);
18
- assert.equal("x.firstName IN ('a','b')", r.text);
19
-
20
- // r = compiler.execute({ names }, (p) => (x) => Sql.text.likeAny(x.firstName, p.names));
21
-
22
- // r = compiler.execute({ names }, (p) => (x) => Sql.text.likeAny(x.firstName, p.names));
23
- // assert.equal("((x.firstName like $1) OR (x.firstName like $2))", r.text);
24
-
25
- r = compiler.execute({ names }, (p) => (x) => Sql.text.likeAny(x.firstName, p.names));
26
- assert.equal("(x.firstName LIKE ANY (ARRAY[$1,$2]))", r.text);
27
-
28
- r = compiler.execute({ names }, (p) => (x) => Sql.text.iLikeAny(x.firstName, p.names));
29
- assert.equal("(x.firstName iLIKE ANY (ARRAY[$1,$2]))", r.text);
30
- }
31
-
@@ -1,65 +0,0 @@
1
- import assert from "assert";
2
- import Sql from "../../../sql/Sql.js";
3
- import QueryCompiler from "../../../compiler/QueryCompiler.js";
4
-
5
- export default function () {
6
-
7
- const compiler = QueryCompiler.instance;
8
-
9
- const name = "Akash";
10
-
11
- let r = compiler.execute({ name }, (p) => (x) => x.firstName === p.name);
12
-
13
- assert.equal(`x.firstName = $1`, r.text);
14
-
15
- r = compiler.execute({ name }, (p) => (x) => x.firstName === p.name && x.lastName !== p.name);
16
-
17
- assert.equal(`(x.firstName = $1) AND (x.lastName <> $2)`, r.text);
18
-
19
- r = compiler.execute({ name }, (p) => (x) => (x.firstName === p.name || x.middleName === p.name) && x.lastName !== p.name);
20
-
21
- assert.equal(`((x.firstName = $1) OR (x.middleName = $2)) AND (x.lastName <> $3)`, r.text);
22
-
23
- r = compiler.execute({ name }, (p) => (x) => x.lastName !== p.name || (x.firstName === p.name || x.middleName === p.name));
24
-
25
- assert.equal(`(x.lastName <> $1) OR ((x.firstName = $2) OR (x.middleName = $3))`, r.text);
26
-
27
- const sqlServerCompiler = new QueryCompiler({});
28
- r = sqlServerCompiler.execute({ name }, (p) => (x) => x.firstName === p.name && x.lastName !== p.name);
29
-
30
- assert.equal(`(x.firstName = $1) AND (x.lastName <> $2)`, r.text);
31
-
32
- r = compiler.execute({ name }, (p) => (x) => ( x.firstName ?? x.lastName ) === p.name);
33
-
34
- assert.equal(`COALESCE(x.firstName, x.lastName) = $1`, r.text);
35
-
36
- r = compiler.execute({ name }, (p) => (x) => Sql.text.like(x.firstName, p.name));
37
-
38
- assert.equal(`(x.firstName LIKE $1)`, r.text);
39
-
40
- r = compiler.execute({ days: 1 }, (p) => (x) => Sql.date.addDays(x.birthDate, p.days));
41
-
42
- assert.equal(`(x.birthDate + ($1 * interval '1 day'))`, r.text);
43
-
44
- r = compiler.execute({name}, (p) => (x) => Sql.text.startsWith(x.firstName, p.name));
45
-
46
- assert.equal(`starts_with(x.firstName, $1)`, r.text);
47
- assert.equal("Akash", r.values[0]);
48
-
49
- const code = "1235";
50
- const key = 13434;
51
- r = compiler.execute({name, code, key},
52
- (p) => (x: KeyCode) =>
53
- x.code === Sql.cast.asNumber(p.code) && x.key === Sql.cast.asText(p.key) );
54
-
55
- assert.equal(`(x.code = ($1 ::numeric)) AND (x.key = ($2 ::text))`, r.text);
56
-
57
-
58
- r = compiler.execute({}, (p) => (x) => `a`);
59
- assert.equal(`'a'`, r.text);
60
-
61
- r = compiler.execute({}, (p) => (x) => `${x.firstName} ${x.lastName}`);
62
- assert.equal(`CONCAT(x.firstName,' ',x.lastName)`, r.text);
63
- }
64
-
65
- type KeyCode = { name: string, code: number, key: string };
@@ -1,20 +0,0 @@
1
- import assert from "assert";
2
- import Sql from "../../../sql/Sql.js";
3
- import QueryCompiler from "../../../compiler/QueryCompiler.js";
4
-
5
- export default function () {
6
-
7
- const compiler = QueryCompiler.instance;
8
-
9
- const name = "Akash";
10
-
11
- let r = compiler.execute({ name }, (p) => (x) => x.id ? 1 : -1);
12
- assert.equal("(CASE WHEN x.id THEN 1 ELSE -1 END)", r.text);
13
-
14
- r = compiler.execute({ name }, (p) => (x) => x.id ? 1 : -(5*1));
15
- assert.equal("(CASE WHEN x.id THEN 1 ELSE (-5 * 1) END)", r.text);
16
-
17
-
18
- }
19
-
20
- type KeyCode = { name: string, code: number, key: string };
@@ -1,25 +0,0 @@
1
- import assert, { AssertionError } from "assert";
2
-
3
- export const trimInternal = (text: string) => {
4
- let r = "";
5
- for (const iterator of text) {
6
- switch(iterator) {
7
- case "\n":
8
- case "\t":
9
- case "\r":
10
- case " ":
11
- if (!r.endsWith(" ")) {
12
- r += " ";
13
- }
14
- continue;
15
- }
16
- r += iterator;
17
- }
18
- return r.trim();
19
- };
20
-
21
- export const assertSqlMatch = (expected: string, actual: string) => {
22
- const expectedTrimmed = trimInternal(expected);
23
- const actualTrimmed = trimInternal(actual);
24
- assert.strictEqual(actualTrimmed, expectedTrimmed);
25
- };