@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,49 +0,0 @@
1
- import { DBType, Field, GlobalSchema } from "../schema/schema";
2
-
3
- let globalSchema: GlobalSchema | undefined;
4
- let globalSchemaFields: Map<string, Field> = new Map();
5
-
6
- function isGlobalSchemaField(f: Field) {
7
- switch (f.type.dbType) {
8
- case DBType.Enum:
9
- case DBType.StringEnum:
10
- case DBType.IntEnum:
11
- case DBType.JSON:
12
- case DBType.JSONB:
13
- return true;
14
- }
15
- return false;
16
- }
17
- export function setGlobalSchema(val: GlobalSchema) {
18
- globalSchema = val;
19
- if (val.fields) {
20
- for (const [k, v] of Object.entries(val.fields)) {
21
- if (isGlobalSchemaField(v) && v.type.type) {
22
- globalSchemaFields.set(v.type.type, v);
23
- }
24
- }
25
- }
26
- }
27
-
28
- export function clearGlobalSchema() {
29
- globalSchema = undefined;
30
- globalSchemaFields.clear();
31
- }
32
-
33
- // used by tests. no guarantee will always exist
34
- export function __hasGlobalSchema() {
35
- return globalSchema !== undefined;
36
- }
37
-
38
- // used by tests. no guarantee will always exist
39
- export function __getGlobalSchema(): GlobalSchema | undefined {
40
- return globalSchema;
41
- }
42
-
43
- export function __getGlobalSchemaFields() {
44
- return globalSchemaFields;
45
- }
46
-
47
- export function __getGlobalSchemaField(type: string) {
48
- return globalSchemaFields.get(type);
49
- }
@@ -1,99 +0,0 @@
1
- import DataLoader from "dataloader";
2
- import {
3
- ID,
4
- Context,
5
- Loader,
6
- LoaderFactory,
7
- EdgeQueryableDataOptionsConfigureLoader,
8
- } from "../base";
9
- import {
10
- getEdgeClauseAndFields,
11
- loadEdgeData,
12
- loadRawEdgeCountX,
13
- } from "../ent";
14
- import * as clause from "../clause";
15
- import { getCustomLoader, getLoader } from "./loader";
16
- import { createCountDataLoader } from "./raw_count_loader";
17
- import memoize from "memoizee";
18
-
19
- export class AssocEdgeCountLoader implements Loader<ID, number> {
20
- private loaderFn: () => Promise<DataLoader<ID, number>>;
21
- private loader: DataLoader<ID, number> | undefined;
22
-
23
- constructor(
24
- private edgeType: string,
25
- public context?: Context,
26
- private options?: EdgeQueryableDataOptionsConfigureLoader,
27
- ) {
28
- if (context) {
29
- this.loaderFn = memoize(this.getLoader);
30
- }
31
- }
32
-
33
- private async getLoader() {
34
- const edgeData = await loadEdgeData(this.edgeType);
35
- if (!edgeData) {
36
- throw new Error(`error loading edge data for ${this.edgeType}`);
37
- }
38
- const { cls } = getEdgeClauseAndFields(
39
- clause.Eq("edge_type", this.edgeType),
40
- {
41
- queryOptions: this.options,
42
- },
43
- );
44
-
45
- this.loader = createCountDataLoader({
46
- tableName: edgeData.edgeTable,
47
- groupCol: "id1",
48
- clause: cls,
49
- });
50
- return this.loader;
51
- }
52
-
53
- async load(id: ID): Promise<number> {
54
- if (!this.loaderFn) {
55
- return loadRawEdgeCountX({
56
- id1: id,
57
- edgeType: this.edgeType,
58
- queryOptions: this.options,
59
- });
60
- }
61
- const loader = await this.loaderFn();
62
- return await loader.load(id);
63
- }
64
-
65
- clearAll() {
66
- this.loader && this.loader.clearAll();
67
- }
68
- }
69
-
70
- export class AssocEdgeCountLoaderFactory implements LoaderFactory<ID, number> {
71
- name: string;
72
- constructor(private edgeType: string) {
73
- this.name = `assocEdgeLoader:count:${edgeType}`;
74
- }
75
-
76
- getEdgeType() {
77
- return this.edgeType;
78
- }
79
-
80
- createLoader(context?: Context): AssocEdgeCountLoader {
81
- return getLoader(
82
- this,
83
- () => new AssocEdgeCountLoader(this.edgeType, context),
84
- context,
85
- ) as AssocEdgeCountLoader;
86
- }
87
-
88
- createConfigurableLoader(
89
- options: EdgeQueryableDataOptionsConfigureLoader,
90
- context?: Context,
91
- ): AssocEdgeCountLoader {
92
- const key = `${this.name}:disableTransformations:${options.disableTransformations}`;
93
- return getCustomLoader(
94
- key,
95
- () => new AssocEdgeCountLoader(this.edgeType, context, options),
96
- context,
97
- ) as AssocEdgeCountLoader;
98
- }
99
- }
@@ -1,250 +0,0 @@
1
- import DataLoader from "dataloader";
2
- import {
3
- Context,
4
- ID,
5
- EdgeQueryableDataOptions,
6
- Loader,
7
- LoaderFactory,
8
- } from "../base";
9
- import {
10
- AssocEdge,
11
- loadCustomEdges,
12
- AssocEdgeConstructor,
13
- loadEdgeData,
14
- getDefaultLimit,
15
- performRawQuery,
16
- loadEdgeForID2,
17
- buildGroupQuery,
18
- AssocEdgeData,
19
- getEdgeClauseAndFields,
20
- } from "../ent";
21
- import * as clause from "../clause";
22
- import { logEnabled } from "../logger";
23
- import { CacheMap, getCustomLoader } from "./loader";
24
- import memoizee from "memoizee";
25
-
26
- function createLoader<T extends AssocEdge>(
27
- options: EdgeQueryableDataOptions,
28
- edgeType: string,
29
- edgeCtr: AssocEdgeConstructor<T>,
30
- edgeData: AssocEdgeData,
31
- ) {
32
- const loaderOptions: DataLoader.Options<ID, T[]> = {};
33
-
34
- if (logEnabled("query")) {
35
- loaderOptions.cacheMap = new CacheMap({
36
- tableName: edgeData.edgeTable,
37
- });
38
- }
39
-
40
- return new DataLoader(async (keys: ID[]) => {
41
- if (keys.length === 1) {
42
- // 1 key, just be simple and move on
43
- // same as AssocDirectEdgeLoader
44
- const r = await loadCustomEdges({
45
- id1: keys[0],
46
- edgeType: edgeType,
47
- queryOptions: options,
48
- ctr: edgeCtr,
49
- });
50
- return [r];
51
- }
52
-
53
- let m = new Map<ID, number>();
54
- let result: T[][] = [];
55
- for (let i = 0; i < keys.length; i++) {
56
- result.push([]);
57
- // store the index....
58
- m.set(keys[i], i);
59
- }
60
-
61
- options.orderby = options.orderby || [
62
- {
63
- column: "time",
64
- direction: "DESC",
65
- },
66
- ];
67
- // TODO defaultEdgeQueryOptions
68
- options.limit = options.limit || getDefaultLimit();
69
-
70
- const tableName = edgeData.edgeTable;
71
- const { cls: cls1, fields } = getEdgeClauseAndFields(
72
- clause.Eq("edge_type", edgeType),
73
- {
74
- queryOptions: options,
75
- },
76
- );
77
- const [query, cls] = buildGroupQuery({
78
- tableName: tableName,
79
- fields,
80
- values: keys,
81
- orderby: options.orderby,
82
- limit: options.limit || getDefaultLimit(),
83
- groupColumn: "id1",
84
- clause: cls1,
85
- });
86
-
87
- const rows = await performRawQuery(query, cls.values(), cls.logValues());
88
- for (const row of rows) {
89
- const srcID = row.id1;
90
- const idx = m.get(srcID);
91
- delete row.row_num;
92
- if (idx === undefined) {
93
- throw new Error(
94
- `malformed query. got ${srcID} back but didn't query for it`,
95
- );
96
- }
97
- result[idx].push(new edgeCtr(row));
98
- }
99
- return result;
100
- }, loaderOptions);
101
- }
102
-
103
- export interface AssocLoader<T extends AssocEdge> extends Loader<ID, T[]> {
104
- loadEdgeForID2(id: ID, id2: ID): Promise<T | undefined>;
105
- }
106
-
107
- export class AssocEdgeLoader<T extends AssocEdge> implements Loader<ID, T[]> {
108
- private loaderFn: () => Promise<DataLoader<ID, T[]>>;
109
- private loader: DataLoader<ID, T[]> | undefined;
110
- constructor(
111
- private edgeType: string,
112
- private edgeCtr: AssocEdgeConstructor<T>,
113
- private options: EdgeQueryableDataOptions,
114
- public context: Context,
115
- ) {
116
- this.loaderFn = memoizee(this.getLoader);
117
- }
118
-
119
- private async getLoader() {
120
- const edgeData = await loadEdgeData(this.edgeType);
121
- if (!edgeData) {
122
- throw new Error(`error loading edge data for ${this.edgeType}`);
123
- }
124
- this.loader = createLoader(
125
- this.options,
126
- this.edgeType,
127
- this.edgeCtr,
128
- edgeData,
129
- );
130
- return this.loader;
131
- }
132
-
133
- async load(id: ID): Promise<T[]> {
134
- const loader = await this.loaderFn();
135
- return loader.load(id);
136
- }
137
-
138
- // maybe eventually optimize this
139
- async loadEdgeForID2(id: ID, id2: ID) {
140
- return loadEdgeForID2({
141
- id1: id,
142
- edgeType: this.edgeType,
143
- id2,
144
- context: this.context,
145
- ctr: this.edgeCtr,
146
- queryOptions: this.options,
147
- });
148
- }
149
-
150
- clearAll() {
151
- this.loader && this.loader.clearAll();
152
- }
153
- }
154
-
155
- export class AssocDirectEdgeLoader<T extends AssocEdge>
156
- implements Loader<ID, T[]>
157
- {
158
- constructor(
159
- private edgeType: string,
160
- private edgeCtr: AssocEdgeConstructor<T>,
161
- private options?: EdgeQueryableDataOptions,
162
- public context?: Context,
163
- ) {}
164
-
165
- async load(id: ID) {
166
- return loadCustomEdges({
167
- id1: id,
168
- edgeType: this.edgeType,
169
- context: this.context,
170
- queryOptions: this.options,
171
- ctr: this.edgeCtr,
172
- });
173
- }
174
-
175
- async loadEdgeForID2(id: ID, id2: ID) {
176
- return loadEdgeForID2({
177
- id1: id,
178
- edgeType: this.edgeType,
179
- id2,
180
- context: this.context,
181
- queryOptions: this.options,
182
- ctr: this.edgeCtr,
183
- });
184
- }
185
-
186
- clearAll() {}
187
- }
188
-
189
- export class AssocEdgeLoaderFactory<T extends AssocEdge>
190
- implements LoaderFactory<ID, T[]>
191
- {
192
- name: string;
193
-
194
- constructor(
195
- private edgeType: string,
196
- private edgeCtr: AssocEdgeConstructor<T> | (() => AssocEdgeConstructor<T>),
197
- ) {
198
- this.name = `assocEdgeLoader:${edgeType}`;
199
- }
200
-
201
- createLoader(context?: Context) {
202
- return this.createConfigurableLoader({}, context);
203
- }
204
-
205
- private isConstructor(
206
- edgeCtr: AssocEdgeConstructor<T> | (() => AssocEdgeConstructor<T>),
207
- ): edgeCtr is AssocEdgeConstructor<T> {
208
- return (
209
- edgeCtr.prototype &&
210
- edgeCtr.prototype.constructor &&
211
- edgeCtr.prototype.constructor.name.length > 0
212
- );
213
- }
214
-
215
- createConfigurableLoader(
216
- options: EdgeQueryableDataOptions,
217
- context?: Context,
218
- ): AssocLoader<T> {
219
- let edgeCtr = this.edgeCtr;
220
- // in generated code, the edge is not necessarily defined at the time of loading
221
- // so we call this as follows:
222
- // const loader = new AssocEdgeLoaderFactory(EdgeType.Foo, ()=>DerivedEdgeClass);
223
- if (!this.isConstructor(edgeCtr)) {
224
- edgeCtr = edgeCtr();
225
- }
226
- // rename to make TS happy
227
- let ctr: AssocEdgeConstructor<T> = edgeCtr;
228
-
229
- // there's a clause which implies there's an offset or something else complicated
230
- // let's be simple for now and just return a regular Loader that does nothing fancy and hits
231
- // the db for each query
232
- // or no context. just do the simple query
233
- if (options?.clause || !context) {
234
- return new AssocDirectEdgeLoader(
235
- this.edgeType,
236
- edgeCtr,
237
- options,
238
- context,
239
- );
240
- }
241
-
242
- // we create a loader which can combine first X queries in the same fetch
243
- const key = `${this.name}:limit:${options.limit}:orderby:${options.orderby}:disableTransformations:${options.disableTransformations}`;
244
- return getCustomLoader(
245
- key,
246
- () => new AssocEdgeLoader(this.edgeType, ctr, options, context),
247
- context,
248
- ) as AssocEdgeLoader<T>;
249
- }
250
- }
@@ -1,12 +0,0 @@
1
- export { ObjectLoader, ObjectLoaderFactory } from "./object_loader";
2
- export { RawCountLoader, RawCountLoaderFactory } from "./raw_count_loader";
3
- export {
4
- AssocEdgeCountLoader,
5
- AssocEdgeCountLoaderFactory,
6
- } from "./assoc_count_loader";
7
- export {
8
- AssocDirectEdgeLoader,
9
- AssocEdgeLoader,
10
- AssocEdgeLoaderFactory,
11
- } from "./assoc_edge_loader";
12
- export { QueryLoaderFactory } from "./query_loader";
@@ -1,66 +0,0 @@
1
- import { Loader, LoaderFactory, Context, DataOptions } from "../base";
2
- import { log } from "../logger";
3
-
4
- // this is like factory factory FML
5
- // helper function to handle context vs not
6
- // and to keep the API clean for clients who shouldn't have to worry about this
7
- export function getLoader<K, V>(
8
- factory: LoaderFactory<K, V>,
9
- create: () => Loader<K, V>,
10
- context?: Context,
11
- ): Loader<K, V> {
12
- // just create a new one every time if no context cache
13
- if (!context?.cache) {
14
- log("debug", `new loader created for ${factory.name}`);
15
- return create();
16
- }
17
-
18
- // g|set from context cache
19
- return context.cache.getLoader(factory.name, create);
20
- }
21
-
22
- export function getCustomLoader<K, V>(
23
- key: string,
24
- create: () => Loader<K, V>,
25
- context?: Context,
26
- ): Loader<K, V> {
27
- // just create a new one every time if no context cache
28
- if (!context?.cache) {
29
- log("debug", `new loader created for ${key}`);
30
- return create();
31
- }
32
-
33
- // g|set from context cache
34
- return context.cache.getLoader(key, create);
35
- }
36
-
37
- export class CacheMap {
38
- private m = new Map();
39
- constructor(private options: DataOptions) {}
40
- get(key) {
41
- const ret = this.m.get(key);
42
- if (ret) {
43
- // should this be debug?
44
- // might be a lot?
45
- // TODO this is not the best log format
46
- // was designed for ObjectLoader time. Now we have different needs e.g. count, assoc etc
47
- log("cache", {
48
- "dataloader-cache-hit": key,
49
- "tableName": this.options.tableName,
50
- });
51
- }
52
- return ret;
53
- }
54
-
55
- set(key, value) {
56
- return this.m.set(key, value);
57
- }
58
-
59
- delete(key) {
60
- return this.m.delete(key);
61
- }
62
-
63
- clear() {
64
- return this.m.clear();
65
- }
66
- }