@snowtop/ent 0.1.0-alpha160-test7 → 0.1.0-alpha160

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 (317) hide show
  1. package/core/query/shared_assoc_test.d.ts +2 -0
  2. package/core/query/shared_assoc_test.js +804 -0
  3. package/core/query/shared_test.d.ts +21 -0
  4. package/core/query/shared_test.js +736 -0
  5. package/graphql/query/shared_assoc_test.d.ts +1 -0
  6. package/graphql/query/shared_assoc_test.js +203 -0
  7. package/package.json +8 -53
  8. package/dist/package.json +0 -64
  9. package/src/action/action.ts +0 -330
  10. package/src/action/executor.ts +0 -453
  11. package/src/action/experimental_action.ts +0 -277
  12. package/src/action/index.ts +0 -31
  13. package/src/action/operations.ts +0 -967
  14. package/src/action/orchestrator.ts +0 -1527
  15. package/src/action/privacy.ts +0 -37
  16. package/src/action/relative_value.ts +0 -242
  17. package/src/action/transaction.ts +0 -38
  18. package/src/auth/auth.ts +0 -77
  19. package/src/auth/index.ts +0 -8
  20. package/src/core/base.ts +0 -367
  21. package/src/core/clause.ts +0 -1065
  22. package/src/core/config.ts +0 -219
  23. package/src/core/const.ts +0 -5
  24. package/src/core/context.ts +0 -135
  25. package/src/core/convert.ts +0 -106
  26. package/src/core/date.ts +0 -23
  27. package/src/core/db.ts +0 -498
  28. package/src/core/ent.ts +0 -1740
  29. package/src/core/global_schema.ts +0 -49
  30. package/src/core/loaders/assoc_count_loader.ts +0 -99
  31. package/src/core/loaders/assoc_edge_loader.ts +0 -250
  32. package/src/core/loaders/index.ts +0 -12
  33. package/src/core/loaders/loader.ts +0 -66
  34. package/src/core/loaders/object_loader.ts +0 -489
  35. package/src/core/loaders/query_loader.ts +0 -314
  36. package/src/core/loaders/raw_count_loader.ts +0 -175
  37. package/src/core/logger.ts +0 -49
  38. package/src/core/privacy.ts +0 -660
  39. package/src/core/query/assoc_query.ts +0 -240
  40. package/src/core/query/custom_clause_query.ts +0 -174
  41. package/src/core/query/custom_query.ts +0 -302
  42. package/src/core/query/index.ts +0 -9
  43. package/src/core/query/query.ts +0 -674
  44. package/src/core/query_impl.ts +0 -32
  45. package/src/core/viewer.ts +0 -52
  46. package/src/ent.code-workspace +0 -73
  47. package/src/graphql/builtins/connection.ts +0 -25
  48. package/src/graphql/builtins/edge.ts +0 -16
  49. package/src/graphql/builtins/node.ts +0 -12
  50. package/src/graphql/graphql.ts +0 -891
  51. package/src/graphql/graphql_field_helpers.ts +0 -221
  52. package/src/graphql/index.ts +0 -42
  53. package/src/graphql/mutations/union.ts +0 -39
  54. package/src/graphql/node_resolver.ts +0 -122
  55. package/src/graphql/query/connection_type.ts +0 -113
  56. package/src/graphql/query/edge_connection.ts +0 -171
  57. package/src/graphql/query/page_info.ts +0 -34
  58. package/src/graphql/query/shared_edge_connection.ts +0 -287
  59. package/src/graphql/scalars/orderby_direction.ts +0 -13
  60. package/src/graphql/scalars/time.ts +0 -38
  61. package/src/imports/dataz/example1/_auth.ts +0 -51
  62. package/src/imports/dataz/example1/_viewer.ts +0 -35
  63. package/src/imports/index.ts +0 -213
  64. package/src/index.ts +0 -145
  65. package/src/parse_schema/parse.ts +0 -585
  66. package/src/schema/base_schema.ts +0 -224
  67. package/src/schema/field.ts +0 -1087
  68. package/src/schema/index.ts +0 -53
  69. package/src/schema/json_field.ts +0 -94
  70. package/src/schema/schema.ts +0 -1028
  71. package/src/schema/struct_field.ts +0 -234
  72. package/src/schema/union_field.ts +0 -105
  73. package/src/scripts/custom_compiler.ts +0 -331
  74. package/src/scripts/custom_graphql.ts +0 -550
  75. package/src/scripts/migrate_v0.1.ts +0 -41
  76. package/src/scripts/move_types.ts +0 -131
  77. package/src/scripts/read_schema.ts +0 -67
  78. package/src/setupPackage.js +0 -42
  79. package/src/testutils/action/complex_schemas.ts +0 -517
  80. package/src/testutils/builder.ts +0 -422
  81. package/src/testutils/context/test_context.ts +0 -25
  82. package/src/testutils/db/fixture.ts +0 -32
  83. package/src/testutils/db/temp_db.ts +0 -941
  84. package/src/testutils/db/value.ts +0 -294
  85. package/src/testutils/db_mock.ts +0 -351
  86. package/src/testutils/db_time_zone.ts +0 -40
  87. package/src/testutils/ent-graphql-tests/index.ts +0 -653
  88. package/src/testutils/fake_comms.ts +0 -50
  89. package/src/testutils/fake_data/const.ts +0 -64
  90. package/src/testutils/fake_data/events_query.ts +0 -145
  91. package/src/testutils/fake_data/fake_contact.ts +0 -150
  92. package/src/testutils/fake_data/fake_event.ts +0 -150
  93. package/src/testutils/fake_data/fake_tag.ts +0 -139
  94. package/src/testutils/fake_data/fake_user.ts +0 -232
  95. package/src/testutils/fake_data/index.ts +0 -1
  96. package/src/testutils/fake_data/internal.ts +0 -8
  97. package/src/testutils/fake_data/tag_query.ts +0 -56
  98. package/src/testutils/fake_data/test_helpers.ts +0 -388
  99. package/src/testutils/fake_data/user_query.ts +0 -524
  100. package/src/testutils/fake_log.ts +0 -52
  101. package/src/testutils/mock_date.ts +0 -10
  102. package/src/testutils/mock_log.ts +0 -39
  103. package/src/testutils/parse_sql.ts +0 -685
  104. package/src/testutils/test_edge_global_schema.ts +0 -49
  105. package/src/testutils/write.ts +0 -70
  106. package/src/tsc/ast.ts +0 -351
  107. package/src/tsc/compilerOptions.ts +0 -85
  108. package/src/tsc/move_generated.ts +0 -191
  109. package/src/tsc/transform.ts +0 -226
  110. package/src/tsc/transform_action.ts +0 -224
  111. package/src/tsc/transform_ent.ts +0 -66
  112. package/src/tsc/transform_schema.ts +0 -546
  113. package/tsconfig.json +0 -20
  114. /package/{dist/action → action}/action.d.ts +0 -0
  115. /package/{dist/action → action}/action.js +0 -0
  116. /package/{dist/action → action}/executor.d.ts +0 -0
  117. /package/{dist/action → action}/executor.js +0 -0
  118. /package/{dist/action → action}/experimental_action.d.ts +0 -0
  119. /package/{dist/action → action}/experimental_action.js +0 -0
  120. /package/{dist/action → action}/index.d.ts +0 -0
  121. /package/{dist/action → action}/index.js +0 -0
  122. /package/{dist/action → action}/operations.d.ts +0 -0
  123. /package/{dist/action → action}/operations.js +0 -0
  124. /package/{dist/action → action}/orchestrator.d.ts +0 -0
  125. /package/{dist/action → action}/orchestrator.js +0 -0
  126. /package/{dist/action → action}/privacy.d.ts +0 -0
  127. /package/{dist/action → action}/privacy.js +0 -0
  128. /package/{dist/action → action}/relative_value.d.ts +0 -0
  129. /package/{dist/action → action}/relative_value.js +0 -0
  130. /package/{dist/action → action}/transaction.d.ts +0 -0
  131. /package/{dist/action → action}/transaction.js +0 -0
  132. /package/{dist/auth → auth}/auth.d.ts +0 -0
  133. /package/{dist/auth → auth}/auth.js +0 -0
  134. /package/{dist/auth → auth}/index.d.ts +0 -0
  135. /package/{dist/auth → auth}/index.js +0 -0
  136. /package/{dist/core → core}/base.d.ts +0 -0
  137. /package/{dist/core → core}/base.js +0 -0
  138. /package/{dist/core → core}/clause.d.ts +0 -0
  139. /package/{dist/core → core}/clause.js +0 -0
  140. /package/{dist/core → core}/config.d.ts +0 -0
  141. /package/{dist/core → core}/config.js +0 -0
  142. /package/{dist/core → core}/const.d.ts +0 -0
  143. /package/{dist/core → core}/const.js +0 -0
  144. /package/{dist/core → core}/context.d.ts +0 -0
  145. /package/{dist/core → core}/context.js +0 -0
  146. /package/{dist/core → core}/convert.d.ts +0 -0
  147. /package/{dist/core → core}/convert.js +0 -0
  148. /package/{dist/core → core}/date.d.ts +0 -0
  149. /package/{dist/core → core}/date.js +0 -0
  150. /package/{dist/core → core}/db.d.ts +0 -0
  151. /package/{dist/core → core}/db.js +0 -0
  152. /package/{dist/core → core}/ent.d.ts +0 -0
  153. /package/{dist/core → core}/ent.js +0 -0
  154. /package/{dist/core → core}/global_schema.d.ts +0 -0
  155. /package/{dist/core → core}/global_schema.js +0 -0
  156. /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
  157. /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
  158. /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
  159. /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
  160. /package/{dist/core → core}/loaders/index.d.ts +0 -0
  161. /package/{dist/core → core}/loaders/index.js +0 -0
  162. /package/{dist/core → core}/loaders/loader.d.ts +0 -0
  163. /package/{dist/core → core}/loaders/loader.js +0 -0
  164. /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
  165. /package/{dist/core → core}/loaders/object_loader.js +0 -0
  166. /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
  167. /package/{dist/core → core}/loaders/query_loader.js +0 -0
  168. /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
  169. /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
  170. /package/{dist/core → core}/logger.d.ts +0 -0
  171. /package/{dist/core → core}/logger.js +0 -0
  172. /package/{dist/core → core}/privacy.d.ts +0 -0
  173. /package/{dist/core → core}/privacy.js +0 -0
  174. /package/{dist/core → core}/query/assoc_query.d.ts +0 -0
  175. /package/{dist/core → core}/query/assoc_query.js +0 -0
  176. /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
  177. /package/{dist/core → core}/query/custom_clause_query.js +0 -0
  178. /package/{dist/core → core}/query/custom_query.d.ts +0 -0
  179. /package/{dist/core → core}/query/custom_query.js +0 -0
  180. /package/{dist/core → core}/query/index.d.ts +0 -0
  181. /package/{dist/core → core}/query/index.js +0 -0
  182. /package/{dist/core → core}/query/query.d.ts +0 -0
  183. /package/{dist/core → core}/query/query.js +0 -0
  184. /package/{dist/core → core}/query_impl.d.ts +0 -0
  185. /package/{dist/core → core}/query_impl.js +0 -0
  186. /package/{dist/core → core}/viewer.d.ts +0 -0
  187. /package/{dist/core → core}/viewer.js +0 -0
  188. /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
  189. /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
  190. /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
  191. /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
  192. /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
  193. /package/{dist/graphql → graphql}/builtins/node.js +0 -0
  194. /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
  195. /package/{dist/graphql → graphql}/graphql.js +0 -0
  196. /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
  197. /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
  198. /package/{dist/graphql → graphql}/index.d.ts +0 -0
  199. /package/{dist/graphql → graphql}/index.js +0 -0
  200. /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
  201. /package/{dist/graphql → graphql}/mutations/union.js +0 -0
  202. /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
  203. /package/{dist/graphql → graphql}/node_resolver.js +0 -0
  204. /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
  205. /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
  206. /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
  207. /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
  208. /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
  209. /package/{dist/graphql → graphql}/query/page_info.js +0 -0
  210. /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
  211. /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
  212. /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
  213. /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
  214. /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
  215. /package/{dist/graphql → graphql}/scalars/time.js +0 -0
  216. /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
  217. /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
  218. /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
  219. /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
  220. /package/{dist/imports → imports}/index.d.ts +0 -0
  221. /package/{dist/imports → imports}/index.js +0 -0
  222. /package/{dist/index.d.ts → index.d.ts} +0 -0
  223. /package/{dist/index.js → index.js} +0 -0
  224. /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
  225. /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
  226. /package/{dist/schema → schema}/base_schema.d.ts +0 -0
  227. /package/{dist/schema → schema}/base_schema.js +0 -0
  228. /package/{dist/schema → schema}/field.d.ts +0 -0
  229. /package/{dist/schema → schema}/field.js +0 -0
  230. /package/{dist/schema → schema}/index.d.ts +0 -0
  231. /package/{dist/schema → schema}/index.js +0 -0
  232. /package/{dist/schema → schema}/json_field.d.ts +0 -0
  233. /package/{dist/schema → schema}/json_field.js +0 -0
  234. /package/{dist/schema → schema}/schema.d.ts +0 -0
  235. /package/{dist/schema → schema}/schema.js +0 -0
  236. /package/{dist/schema → schema}/struct_field.d.ts +0 -0
  237. /package/{dist/schema → schema}/struct_field.js +0 -0
  238. /package/{dist/schema → schema}/union_field.d.ts +0 -0
  239. /package/{dist/schema → schema}/union_field.js +0 -0
  240. /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
  241. /package/{dist/scripts → scripts}/custom_compiler.js +0 -0
  242. /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
  243. /package/{dist/scripts → scripts}/custom_graphql.js +0 -0
  244. /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
  245. /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
  246. /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
  247. /package/{dist/scripts → scripts}/move_types.js +0 -0
  248. /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
  249. /package/{dist/scripts → scripts}/read_schema.js +0 -0
  250. /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
  251. /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
  252. /package/{dist/testutils → testutils}/builder.d.ts +0 -0
  253. /package/{dist/testutils → testutils}/builder.js +0 -0
  254. /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
  255. /package/{dist/testutils → testutils}/context/test_context.js +0 -0
  256. /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
  257. /package/{dist/testutils → testutils}/db/fixture.js +0 -0
  258. /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
  259. /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
  260. /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
  261. /package/{dist/testutils → testutils}/db/value.js +0 -0
  262. /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
  263. /package/{dist/testutils → testutils}/db_mock.js +0 -0
  264. /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
  265. /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
  266. /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
  267. /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
  268. /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
  269. /package/{dist/testutils → testutils}/fake_comms.js +0 -0
  270. /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
  271. /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
  272. /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
  273. /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
  274. /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
  275. /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
  276. /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
  277. /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
  278. /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
  279. /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
  280. /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
  281. /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
  282. /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
  283. /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
  284. /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
  285. /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
  286. /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
  287. /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
  288. /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +0 -0
  289. /package/{dist/testutils → testutils}/fake_data/test_helpers.js +0 -0
  290. /package/{dist/testutils → testutils}/fake_data/user_query.d.ts +0 -0
  291. /package/{dist/testutils → testutils}/fake_data/user_query.js +0 -0
  292. /package/{dist/testutils → testutils}/fake_log.d.ts +0 -0
  293. /package/{dist/testutils → testutils}/fake_log.js +0 -0
  294. /package/{dist/testutils → testutils}/mock_date.d.ts +0 -0
  295. /package/{dist/testutils → testutils}/mock_date.js +0 -0
  296. /package/{dist/testutils → testutils}/mock_log.d.ts +0 -0
  297. /package/{dist/testutils → testutils}/mock_log.js +0 -0
  298. /package/{dist/testutils → testutils}/parse_sql.d.ts +0 -0
  299. /package/{dist/testutils → testutils}/parse_sql.js +0 -0
  300. /package/{dist/testutils → testutils}/test_edge_global_schema.d.ts +0 -0
  301. /package/{dist/testutils → testutils}/test_edge_global_schema.js +0 -0
  302. /package/{dist/testutils → testutils}/write.d.ts +0 -0
  303. /package/{dist/testutils → testutils}/write.js +0 -0
  304. /package/{dist/tsc → tsc}/ast.d.ts +0 -0
  305. /package/{dist/tsc → tsc}/ast.js +0 -0
  306. /package/{dist/tsc → tsc}/compilerOptions.d.ts +0 -0
  307. /package/{dist/tsc → tsc}/compilerOptions.js +0 -0
  308. /package/{dist/tsc → tsc}/move_generated.d.ts +0 -0
  309. /package/{dist/tsc → tsc}/move_generated.js +0 -0
  310. /package/{dist/tsc → tsc}/transform.d.ts +0 -0
  311. /package/{dist/tsc → tsc}/transform.js +0 -0
  312. /package/{dist/tsc → tsc}/transform_action.d.ts +0 -0
  313. /package/{dist/tsc → tsc}/transform_action.js +0 -0
  314. /package/{dist/tsc → tsc}/transform_ent.d.ts +0 -0
  315. /package/{dist/tsc → tsc}/transform_ent.js +0 -0
  316. /package/{dist/tsc → tsc}/transform_schema.d.ts +0 -0
  317. /package/{dist/tsc → tsc}/transform_schema.js +0 -0
@@ -1,453 +0,0 @@
1
- import { Graph } from "graph-data-structure";
2
- import { ID, Ent, Viewer, Context, Data } from "../core/base";
3
- import { logQuery } from "../core/ent";
4
- import { Changeset, Executor } from "../action/action";
5
- import { Builder, WriteOperation } from "../action";
6
- import { OrchestratorOptions } from "./orchestrator";
7
- import DB, { Client, Queryer, SyncClient } from "../core/db";
8
- import { log } from "../core/logger";
9
- import {
10
- ConditionalNodeOperation,
11
- ConditionalOperation,
12
- DataOperation,
13
- } from "./operations";
14
-
15
- // private to ent
16
- export class ListBasedExecutor<T extends Ent> implements Executor {
17
- private idx: number = 0;
18
- public builder?: Builder<Ent> | undefined;
19
- constructor(
20
- private viewer: Viewer,
21
- public placeholderID: ID,
22
- private operations: DataOperation<T>[],
23
- private options?: OrchestratorOptions<T, Data, Viewer>,
24
- private complexOptions?: ComplexExecutorOptions,
25
- ) {
26
- this.builder = options?.builder;
27
- }
28
- private lastOp: DataOperation<T> | undefined;
29
- private createdEnt: T | null = null;
30
- private changedOps: Map<ID, WriteOperation> = new Map();
31
-
32
- resolveValue(val: ID): Ent | null {
33
- if (val === this.placeholderID && val !== undefined) {
34
- return this.createdEnt;
35
- }
36
-
37
- return null;
38
- }
39
-
40
- builderOpChanged(builder: Builder<any>): boolean {
41
- const v = this.changedOps.get(builder.placeholderID);
42
- return v !== undefined && v !== builder.operation;
43
- }
44
-
45
- [Symbol.iterator]() {
46
- return this;
47
- }
48
-
49
- // returns true and null|undefined when done
50
- next(): IteratorResult<DataOperation<T>> {
51
- let createdEnt = getCreatedEnt(this.viewer, this.lastOp);
52
- if (createdEnt) {
53
- this.createdEnt = createdEnt;
54
- }
55
- maybeFlagOpOperationAsChanged(this.lastOp, this.changedOps);
56
-
57
- const done = this.idx >= this.operations.length;
58
- const op = maybeChangeOp(this.operations[this.idx], this.complexOptions);
59
-
60
- this.idx++;
61
- this.lastOp = op;
62
-
63
- if (done || op === undefined) {
64
- return {
65
- value: op,
66
- done: true,
67
- };
68
- }
69
- return {
70
- value: op,
71
- };
72
- }
73
-
74
- async executeObservers() {
75
- const action = this.options?.action;
76
- if (!this.options || !action || !action.getObservers) {
77
- return;
78
- }
79
-
80
- const builder = this.options.builder;
81
- await Promise.all(
82
- action.getObservers().map(async (observer) => {
83
- try {
84
- await observer.observe(builder, action.getInput());
85
- } catch (err) {
86
- // TODO we eventually want a global observer error handler so that this can be logged or whatever...
87
- // TODO https://github.com/lolopinto/ent/issues/1429
88
- }
89
- }),
90
- );
91
- }
92
-
93
- async execute(): Promise<void> {
94
- await executeOperations(this, this.viewer.context);
95
- }
96
-
97
- async preFetch?(queryer: Queryer, context: Context): Promise<void> {
98
- const prefetches: Promise<void>[] = [];
99
-
100
- for (const op of this.operations) {
101
- if (op.preFetch) {
102
- prefetches.push(op.preFetch(queryer, context));
103
- }
104
- }
105
- await Promise.all(prefetches);
106
- }
107
-
108
- async postFetch?(queryer: Queryer, context: Context): Promise<void> {
109
- const postfetches: Promise<void>[] = [];
110
-
111
- for (const op of this.operations) {
112
- if (op.postFetch) {
113
- postfetches.push(op.postFetch(queryer, context));
114
- }
115
- }
116
- await Promise.all(postfetches);
117
- }
118
- }
119
-
120
- function getCreatedEnt<T extends Ent>(
121
- viewer: Viewer,
122
- op: DataOperation<T> | undefined,
123
- ): T | null {
124
- if (op && op.createdEnt) {
125
- return op.createdEnt(viewer);
126
- }
127
- return null;
128
- }
129
-
130
- function maybeFlagOpOperationAsChanged<T extends Ent>(
131
- op: DataOperation<T> | undefined,
132
- changedOps: Map<ID, WriteOperation>,
133
- ) {
134
- if (!op || !op.updatedOperation) {
135
- return;
136
- }
137
- const r = op.updatedOperation();
138
- if (!r || r.builder.operation === r.operation) {
139
- return;
140
- }
141
-
142
- changedOps.set(r.builder.placeholderID, r.operation);
143
- }
144
-
145
- interface ComplexExecutorOptions {
146
- conditionalOverride: boolean;
147
- builder: Builder<any, any>;
148
- }
149
-
150
- export class ComplexExecutor<T extends Ent> implements Executor {
151
- private idx: number = 0;
152
- private mapper: Map<ID, Ent> = new Map();
153
- private lastOp: DataOperation<Ent> | undefined;
154
- private allOperations: DataOperation<Ent>[] = [];
155
- private executors: Executor[] = [];
156
- private changedOps: Map<ID, WriteOperation> = new Map();
157
- public builder?: Builder<Ent> | undefined;
158
-
159
- constructor(
160
- private viewer: Viewer,
161
- public placeholderID: ID,
162
- operations: DataOperation[],
163
- dependencies: Map<ID, Builder<T>>,
164
- changesets: Changeset[],
165
- options?: OrchestratorOptions<T, Data, Viewer>,
166
- private complexOptions?: ComplexExecutorOptions,
167
- ) {
168
- this.builder = options?.builder;
169
-
170
- let graph = Graph();
171
-
172
- const changesetMap: Map<string, Changeset> = new Map();
173
-
174
- const impl = (c: Changeset) => {
175
- changesetMap.set(c.placeholderID.toString(), c);
176
-
177
- graph.addNode(c.placeholderID.toString());
178
- if (c.dependencies) {
179
- for (let [_, builder] of c.dependencies) {
180
- // dependency should go first...
181
- graph.addEdge(
182
- builder.placeholderID.toString(),
183
- c.placeholderID.toString(),
184
- 1,
185
- );
186
- }
187
- }
188
-
189
- if (c.changesets) {
190
- c.changesets.forEach((c2) => {
191
- impl(c2);
192
- });
193
- }
194
- };
195
- let localChangesets = new Map<ID, Changeset>();
196
- changesets.forEach((c) => localChangesets.set(c.placeholderID, c));
197
-
198
- // create a new changeset representing the source changeset with the simple executor
199
- impl({
200
- viewer: this.viewer,
201
- placeholderID: this.placeholderID,
202
- changesets: changesets,
203
- dependencies: dependencies,
204
- executor: () => {
205
- return new ListBasedExecutor(
206
- this.viewer,
207
- this.placeholderID,
208
- operations,
209
- options,
210
- );
211
- },
212
- });
213
-
214
- // use a set to handle repeated ops because of how the executor logic currently works
215
- // TODO: can this logic be rewritten to not have a set yet avoid duplicates?
216
- let nodeOps: Set<DataOperation<Ent>> = new Set();
217
- let remainOps: Set<DataOperation<Ent>> = new Set();
218
-
219
- let sorted = graph.topologicalSort(graph.nodes());
220
- sorted.forEach((node) => {
221
- let c = changesetMap.get(node);
222
-
223
- if (!c) {
224
- // phew. expect it to be handled somewhere else
225
- // we can just skip it and expect the resolver to handle this correctly
226
- // this means it's not a changeset that was created by this ent and can/will be handled elsewhere
227
- if (dependencies.has(node)) {
228
- return;
229
- }
230
- throw new Error(
231
- `trying to do a write with incomplete mutation data ${node}. current node: ${placeholderID}`,
232
- );
233
- }
234
-
235
- // get ordered list of ops
236
- let executor = c.executor();
237
- for (let op of executor) {
238
- if (op.createdEnt) {
239
- nodeOps.add(op);
240
- } else {
241
- remainOps.add(op);
242
- }
243
- }
244
-
245
- // only add executors that are part of the changeset to what should be tracked here
246
- // or self.
247
- if (
248
- localChangesets.has(c.placeholderID) ||
249
- c.placeholderID === placeholderID
250
- ) {
251
- this.executors.push(executor);
252
- }
253
- });
254
- // get all the operations and put node operations first
255
- this.allOperations = [...nodeOps, ...remainOps];
256
- }
257
-
258
- [Symbol.iterator]() {
259
- return this;
260
- }
261
-
262
- private handleCreatedEnt() {
263
- if (!this.lastOp) {
264
- return;
265
- }
266
- let createdEnt = getCreatedEnt(this.viewer, this.lastOp);
267
- if (!createdEnt) {
268
- return;
269
- }
270
- const placeholderID = this.lastOp.placeholderID;
271
- if (!placeholderID) {
272
- throw new Error(
273
- `op ${this.lastOp} which implements getCreatedEnt doesn't have a placeholderID`,
274
- );
275
- }
276
-
277
- this.mapper.set(placeholderID, createdEnt);
278
- }
279
-
280
- next(): IteratorResult<DataOperation<Ent>> {
281
- this.handleCreatedEnt();
282
- maybeFlagOpOperationAsChanged(this.lastOp, this.changedOps);
283
-
284
- const done = this.idx >= this.allOperations.length;
285
- const op = maybeChangeOp(this.allOperations[this.idx], this.complexOptions);
286
- this.idx++;
287
-
288
- this.lastOp = op;
289
-
290
- if (done || op === undefined) {
291
- return {
292
- value: op,
293
- done: true,
294
- };
295
- }
296
-
297
- return { value: op };
298
- }
299
-
300
- resolveValue(val: ID): Ent | null {
301
- let ent = this.mapper.get(val);
302
- if (ent) {
303
- return ent;
304
- }
305
- for (const c of this.executors) {
306
- const ent = c.resolveValue(val);
307
- if (ent) {
308
- return ent;
309
- }
310
- }
311
- return null;
312
- }
313
-
314
- builderOpChanged(builder: Builder<any>): boolean {
315
- const v = this.changedOps.get(builder.placeholderID);
316
- return v !== undefined && v !== builder.operation;
317
- }
318
-
319
- async executeObservers() {
320
- await Promise.all(
321
- this.executors.map((executor) => {
322
- if (executor.builder && this.builderOpChanged(executor.builder)) {
323
- return null;
324
- }
325
- if (!executor.executeObservers) {
326
- return null;
327
- }
328
- return executor.executeObservers();
329
- }),
330
- );
331
- }
332
-
333
- async execute(): Promise<void> {
334
- await executeOperations(this, this.viewer.context);
335
- }
336
-
337
- async preFetch?(queryer: Queryer, context: Context): Promise<void> {
338
- const prefetches: Promise<void>[] = [];
339
-
340
- for (const exec of this.executors) {
341
- if (exec.preFetch) {
342
- prefetches.push(exec.preFetch(queryer, context));
343
- }
344
- }
345
- await Promise.all(prefetches);
346
- }
347
-
348
- async postFetch?(queryer: Queryer, context: Context): Promise<void> {
349
- const postfetches: Promise<void>[] = [];
350
-
351
- for (const exec of this.executors) {
352
- if (exec.postFetch) {
353
- postfetches.push(exec.postFetch(queryer, context));
354
- }
355
- }
356
- await Promise.all(postfetches);
357
- }
358
- }
359
-
360
- function isSyncClient(client: Client): client is SyncClient {
361
- return (client as SyncClient).execSync !== undefined;
362
- }
363
-
364
- export async function executeOperations(
365
- executor: Executor,
366
- context?: Context,
367
- trackOps?: true,
368
- ) {
369
- const client = await DB.getInstance().getNewClient();
370
-
371
- const operations: DataOperation[] = [];
372
- try {
373
- if (executor.preFetch) {
374
- await executor.preFetch(client, context);
375
- }
376
-
377
- if (isSyncClient(client)) {
378
- client.runInTransaction(() => {
379
- for (const operation of executor) {
380
- if (operation.shortCircuit && operation.shortCircuit(executor)) {
381
- continue;
382
- }
383
- if (trackOps) {
384
- operations.push(operation);
385
- }
386
- if (operation.resolve) {
387
- operation.resolve(executor);
388
- }
389
- operation.performWriteSync(client, context);
390
- }
391
- });
392
- } else {
393
- logQuery("BEGIN", []);
394
- await client.query("BEGIN");
395
- for (const operation of executor) {
396
- if (operation.shortCircuit && operation.shortCircuit(executor)) {
397
- continue;
398
- }
399
-
400
- if (trackOps) {
401
- operations.push(operation);
402
- }
403
- // resolve any placeholders before writes
404
- if (operation.resolve) {
405
- operation.resolve(executor);
406
- }
407
-
408
- await operation.performWrite(client, context);
409
- }
410
- logQuery("COMMIT", []);
411
- await client.query("COMMIT");
412
- }
413
-
414
- if (executor.postFetch) {
415
- await executor.postFetch(client, context);
416
- }
417
- client.release();
418
- } catch (e) {
419
- if (!isSyncClient(client)) {
420
- // TODO these changes break tests
421
- logQuery("ROLLBACK", []);
422
- await client.query("ROLLBACK");
423
- }
424
- client.release(e);
425
- log("error", e);
426
- throw e;
427
- }
428
-
429
- if (executor.executeObservers) {
430
- try {
431
- await executor.executeObservers();
432
- } catch (e) {}
433
- }
434
- return operations;
435
- }
436
-
437
- function maybeChangeOp<T extends Ent = Ent>(
438
- op: DataOperation<T> | undefined,
439
- complexOptions?: ComplexExecutorOptions,
440
- ): DataOperation<T> | undefined {
441
- if (
442
- !op ||
443
- !complexOptions?.conditionalOverride ||
444
- op instanceof ConditionalNodeOperation
445
- ) {
446
- return op;
447
- }
448
- if (op.createdEnt) {
449
- return new ConditionalNodeOperation(op, complexOptions.builder);
450
- } else {
451
- return new ConditionalOperation(op, complexOptions.builder);
452
- }
453
- }
@@ -1,277 +0,0 @@
1
- import { Orchestrator } from "./orchestrator";
2
- import { Viewer, Ent, Data } from "../core/base";
3
- import { AlwaysAllowPrivacyPolicy } from "../core/privacy";
4
- import {
5
- Action,
6
- WriteOperation,
7
- Builder,
8
- Trigger,
9
- Observer,
10
- Changeset,
11
- Validator,
12
- } from "./action";
13
-
14
- export interface ActionOptions<
15
- TEnt extends Ent<TViewer>,
16
- TViewer extends Viewer,
17
- TData extends Data,
18
- TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
19
- > {
20
- existingEnt: TExistingEnt;
21
- input?: TData;
22
- operation?: WriteOperation;
23
- }
24
-
25
- type MaybeNull<T extends Ent> = T | null;
26
- type TMaybleNullableEnt<T extends Ent> = T | MaybeNull<T>;
27
-
28
- export interface EntBuilder<
29
- TEnt extends Ent<TViewer>,
30
- TViewer extends Viewer,
31
- TInput extends Data,
32
- TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
33
- > extends Builder<TEnt, TViewer, TExistingEnt> {
34
- valid(): Promise<boolean>;
35
- validX(): Promise<void>;
36
- save(): Promise<void>;
37
- saveX(): Promise<void>;
38
- editedEnt(): Promise<TEnt | null>;
39
- editedEntX(): Promise<TEnt>;
40
- getInput(): TInput;
41
- orchestrator: Orchestrator<TEnt, TInput, TViewer, TExistingEnt>;
42
- }
43
-
44
- export class BaseAction<
45
- TEnt extends Ent<TViewer>,
46
- TViewer extends Viewer,
47
- TInput extends Data,
48
- TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
49
- > implements
50
- Action<
51
- TEnt,
52
- EntBuilder<TEnt, TViewer, TInput, TExistingEnt>,
53
- TViewer,
54
- TInput,
55
- TExistingEnt
56
- >
57
- {
58
- builder: EntBuilder<TEnt, TViewer, TInput, TExistingEnt>;
59
- private input: TInput;
60
-
61
- getPrivacyPolicy() {
62
- return AlwaysAllowPrivacyPolicy;
63
- }
64
-
65
- getTriggers(): Trigger<
66
- TEnt,
67
- EntBuilder<TEnt, TViewer, TInput, TExistingEnt>,
68
- TViewer,
69
- TInput,
70
- TExistingEnt
71
- >[] {
72
- return [];
73
- }
74
-
75
- getObservers(): Observer<
76
- TEnt,
77
- EntBuilder<TEnt, TViewer, TInput, TExistingEnt>,
78
- TViewer,
79
- TInput,
80
- TExistingEnt
81
- >[] {
82
- return [];
83
- }
84
-
85
- getValidators(): Validator<
86
- TEnt,
87
- EntBuilder<TEnt, TViewer, TInput, TExistingEnt>,
88
- TViewer,
89
- TInput,
90
- TExistingEnt
91
- >[] {
92
- return [];
93
- }
94
-
95
- constructor(
96
- public viewer: TViewer,
97
- public builderCtr: BuilderConstructor<TEnt, TViewer, TInput, TExistingEnt>,
98
- options: ActionOptions<TEnt, TViewer, TInput, TExistingEnt>,
99
- ) {
100
- let operation = options?.operation;
101
- if (!operation) {
102
- if (options?.existingEnt) {
103
- operation = WriteOperation.Edit;
104
- } else {
105
- operation = WriteOperation.Insert;
106
- }
107
- }
108
- this.input = options?.input || ({} as TInput);
109
- this.builder = new builderCtr(viewer, operation, this, options.existingEnt);
110
- }
111
-
112
- static createBuilder<
113
- TEnt extends Ent<TViewer>,
114
- TViewer extends Viewer,
115
- TInput extends Data,
116
- TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
117
- >(
118
- viewer: Viewer,
119
- builderCtr: BuilderConstructor<TEnt, TViewer, TInput, TExistingEnt>,
120
- options: ActionOptions<TEnt, TViewer, TInput, TExistingEnt>,
121
- ): Builder<TEnt> {
122
- let action = new BaseAction(viewer, builderCtr, options);
123
- return action.builder;
124
- }
125
-
126
- // perform a bulk action in a transaction rooted on ent T
127
- // it ends up creating triggers and having all the given actions performed in a transaction
128
- /**
129
- * @deprecated use Transaction
130
- */
131
- static bulkAction<
132
- TEnt extends Ent<TViewer>,
133
- TViewer extends Viewer,
134
- TInput extends Data,
135
- >(
136
- ent: TEnt,
137
- builderCtr: BuilderConstructor<TEnt, TViewer, TInput, TEnt>,
138
- ...actions: Action<Ent, Builder<Ent, any>>[]
139
- ): BaseAction<TEnt, TViewer, TInput, TEnt> {
140
- let action = new BaseAction(ent.viewer, builderCtr, {
141
- existingEnt: ent,
142
- });
143
- action.getTriggers = () => [
144
- {
145
- changeset: (): Promise<Changeset>[] => {
146
- return actions.map((action) => action.changeset());
147
- },
148
- },
149
- ];
150
- return action;
151
- }
152
-
153
- changeset() {
154
- return this.builder.build();
155
- }
156
-
157
- async valid() {
158
- return this.builder.valid();
159
- }
160
-
161
- async validX() {
162
- return this.builder.validX();
163
- }
164
-
165
- async save(): Promise<TEnt | null> {
166
- await this.builder.save();
167
- return await this.builder.editedEnt();
168
- }
169
-
170
- async saveX(): Promise<TEnt> {
171
- await this.builder.saveX();
172
- return await this.builder.editedEntX();
173
- }
174
-
175
- getInput() {
176
- return this.input;
177
- }
178
- }
179
-
180
- export interface BuilderConstructor<
181
- TEnt extends Ent<TViewer>,
182
- TViewer extends Viewer,
183
- TInput extends Data,
184
- TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
185
- > {
186
- new (
187
- viewer: TViewer,
188
- operation: WriteOperation,
189
- action: Action<
190
- TEnt,
191
- any,
192
- // EntBuilder<TEnt, TViewer, TInput, TExistingEnt>,
193
- TViewer,
194
- TInput,
195
- TExistingEnt
196
- >,
197
- existingEnt: TExistingEnt,
198
- ): EntBuilder<TEnt, TViewer, TInput, TExistingEnt>;
199
- }
200
-
201
- // this provides a way to just update a row in the database.
202
- // skips privacy, triggers, observers, etc
203
- // does do field validation
204
- // note that only editable fields in the builder can be passed here
205
- export async function updateRawObject<
206
- TEnt extends Ent<TViewer>,
207
- TViewer extends Viewer,
208
- TInput extends Data,
209
- >(
210
- viewer: TViewer,
211
- builderCtr: BuilderConstructor<TEnt, TViewer, TInput, TEnt>,
212
- existingEnt: TEnt,
213
- input: TInput,
214
- ) {
215
- const action = new BaseAction(viewer, builderCtr, {
216
- existingEnt: existingEnt,
217
- operation: WriteOperation.Edit,
218
- input,
219
- });
220
- return action.saveX();
221
- }
222
-
223
- // TODO need to fix types for all these
224
-
225
- // creates an action which has no privacy, triggers, observers etc
226
- // does do field validation
227
- // useful to batch a bunch of writes together with BaseAction.bulkAction
228
- // note that only editable fields in the builder can be passed here
229
- export function getSimpleEditAction<
230
- TEnt extends Ent<TViewer>,
231
- TViewer extends Viewer,
232
- TInput extends Data,
233
- >(
234
- viewer: TViewer,
235
- builderCtr: BuilderConstructor<TEnt, TViewer, TInput, TEnt>,
236
- existingEnt: TEnt,
237
- input: TInput,
238
- ): BaseAction<TEnt, TViewer, TInput, TEnt> {
239
- return new BaseAction(viewer, builderCtr, {
240
- existingEnt: existingEnt,
241
- operation: WriteOperation.Edit,
242
- input,
243
- });
244
- }
245
-
246
- export function getSimpleDeleteAction<
247
- TEnt extends Ent<TViewer>,
248
- TViewer extends Viewer,
249
- TInput extends Data,
250
- >(
251
- viewer: TViewer,
252
- builderCtr: BuilderConstructor<TEnt, TViewer, TInput, TEnt>,
253
- existingEnt: TEnt,
254
- input: TInput,
255
- ): BaseAction<TEnt, TViewer, TInput, TEnt> {
256
- return new BaseAction(viewer, builderCtr, {
257
- existingEnt: existingEnt,
258
- operation: WriteOperation.Delete,
259
- input,
260
- });
261
- }
262
-
263
- export function getSimpleInsertAction<
264
- TEnt extends Ent<TViewer>,
265
- TViewer extends Viewer,
266
- TInput extends Data,
267
- >(
268
- viewer: TViewer,
269
- builderCtr: BuilderConstructor<TEnt, TViewer, TInput, null>,
270
- input: TInput,
271
- ): BaseAction<TEnt, TViewer, TInput, null> {
272
- return new BaseAction(viewer, builderCtr, {
273
- operation: WriteOperation.Insert,
274
- input,
275
- existingEnt: null,
276
- });
277
- }