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

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/dist/package.json +64 -0
  2. package/package.json +52 -7
  3. package/src/action/action.ts +330 -0
  4. package/src/action/executor.ts +453 -0
  5. package/src/action/experimental_action.ts +277 -0
  6. package/src/action/index.ts +31 -0
  7. package/src/action/operations.ts +967 -0
  8. package/src/action/orchestrator.ts +1527 -0
  9. package/src/action/privacy.ts +37 -0
  10. package/src/action/relative_value.ts +242 -0
  11. package/src/action/transaction.ts +38 -0
  12. package/src/auth/auth.ts +77 -0
  13. package/src/auth/index.ts +8 -0
  14. package/src/core/base.ts +367 -0
  15. package/src/core/clause.ts +1065 -0
  16. package/src/core/config.ts +219 -0
  17. package/src/core/const.ts +5 -0
  18. package/src/core/context.ts +135 -0
  19. package/src/core/convert.ts +106 -0
  20. package/src/core/date.ts +23 -0
  21. package/src/core/db.ts +498 -0
  22. package/src/core/ent.ts +1740 -0
  23. package/src/core/global_schema.ts +49 -0
  24. package/src/core/loaders/assoc_count_loader.ts +99 -0
  25. package/src/core/loaders/assoc_edge_loader.ts +250 -0
  26. package/src/core/loaders/index.ts +12 -0
  27. package/src/core/loaders/loader.ts +66 -0
  28. package/src/core/loaders/object_loader.ts +489 -0
  29. package/src/core/loaders/query_loader.ts +314 -0
  30. package/src/core/loaders/raw_count_loader.ts +175 -0
  31. package/src/core/logger.ts +49 -0
  32. package/src/core/privacy.ts +660 -0
  33. package/src/core/query/assoc_query.ts +240 -0
  34. package/src/core/query/custom_clause_query.ts +174 -0
  35. package/src/core/query/custom_query.ts +302 -0
  36. package/src/core/query/index.ts +9 -0
  37. package/src/core/query/query.ts +674 -0
  38. package/src/core/query_impl.ts +32 -0
  39. package/src/core/viewer.ts +52 -0
  40. package/src/ent.code-workspace +73 -0
  41. package/src/graphql/builtins/connection.ts +25 -0
  42. package/src/graphql/builtins/edge.ts +16 -0
  43. package/src/graphql/builtins/node.ts +12 -0
  44. package/src/graphql/graphql.ts +891 -0
  45. package/src/graphql/graphql_field_helpers.ts +221 -0
  46. package/src/graphql/index.ts +42 -0
  47. package/src/graphql/mutations/union.ts +39 -0
  48. package/src/graphql/node_resolver.ts +122 -0
  49. package/src/graphql/query/connection_type.ts +113 -0
  50. package/src/graphql/query/edge_connection.ts +171 -0
  51. package/src/graphql/query/page_info.ts +34 -0
  52. package/src/graphql/query/shared_edge_connection.ts +287 -0
  53. package/src/graphql/scalars/orderby_direction.ts +13 -0
  54. package/src/graphql/scalars/time.ts +38 -0
  55. package/src/imports/dataz/example1/_auth.ts +51 -0
  56. package/src/imports/dataz/example1/_viewer.ts +35 -0
  57. package/src/imports/index.ts +213 -0
  58. package/src/index.ts +145 -0
  59. package/src/parse_schema/parse.ts +585 -0
  60. package/src/schema/base_schema.ts +224 -0
  61. package/src/schema/field.ts +1087 -0
  62. package/src/schema/index.ts +53 -0
  63. package/src/schema/json_field.ts +94 -0
  64. package/src/schema/schema.ts +1028 -0
  65. package/src/schema/struct_field.ts +234 -0
  66. package/src/schema/union_field.ts +105 -0
  67. package/src/scripts/custom_compiler.ts +331 -0
  68. package/src/scripts/custom_graphql.ts +550 -0
  69. package/src/scripts/migrate_v0.1.ts +41 -0
  70. package/src/scripts/move_types.ts +131 -0
  71. package/src/scripts/read_schema.ts +67 -0
  72. package/src/setupPackage.js +42 -0
  73. package/src/testutils/action/complex_schemas.ts +517 -0
  74. package/src/testutils/builder.ts +422 -0
  75. package/src/testutils/context/test_context.ts +25 -0
  76. package/src/testutils/db/fixture.ts +32 -0
  77. package/src/testutils/db/temp_db.ts +941 -0
  78. package/src/testutils/db/value.ts +294 -0
  79. package/src/testutils/db_mock.ts +351 -0
  80. package/src/testutils/db_time_zone.ts +40 -0
  81. package/src/testutils/ent-graphql-tests/index.ts +653 -0
  82. package/src/testutils/fake_comms.ts +50 -0
  83. package/src/testutils/fake_data/const.ts +64 -0
  84. package/src/testutils/fake_data/events_query.ts +145 -0
  85. package/src/testutils/fake_data/fake_contact.ts +150 -0
  86. package/src/testutils/fake_data/fake_event.ts +150 -0
  87. package/src/testutils/fake_data/fake_tag.ts +139 -0
  88. package/src/testutils/fake_data/fake_user.ts +232 -0
  89. package/src/testutils/fake_data/index.ts +1 -0
  90. package/src/testutils/fake_data/internal.ts +8 -0
  91. package/src/testutils/fake_data/tag_query.ts +56 -0
  92. package/src/testutils/fake_data/test_helpers.ts +388 -0
  93. package/src/testutils/fake_data/user_query.ts +524 -0
  94. package/src/testutils/fake_log.ts +52 -0
  95. package/src/testutils/mock_date.ts +10 -0
  96. package/src/testutils/mock_log.ts +39 -0
  97. package/src/testutils/parse_sql.ts +685 -0
  98. package/src/testutils/test_edge_global_schema.ts +49 -0
  99. package/src/testutils/write.ts +70 -0
  100. package/src/tsc/ast.ts +351 -0
  101. package/src/tsc/compilerOptions.ts +85 -0
  102. package/src/tsc/move_generated.ts +191 -0
  103. package/src/tsc/transform.ts +226 -0
  104. package/src/tsc/transform_action.ts +224 -0
  105. package/src/tsc/transform_ent.ts +66 -0
  106. package/src/tsc/transform_schema.ts +546 -0
  107. package/tsconfig.json +20 -0
  108. package/core/query/shared_assoc_test.d.ts +0 -2
  109. package/core/query/shared_assoc_test.js +0 -804
  110. package/core/query/shared_test.d.ts +0 -21
  111. package/core/query/shared_test.js +0 -736
  112. package/graphql/query/shared_assoc_test.d.ts +0 -1
  113. package/graphql/query/shared_assoc_test.js +0 -203
  114. /package/{action → dist/action}/action.d.ts +0 -0
  115. /package/{action → dist/action}/action.js +0 -0
  116. /package/{action → dist/action}/executor.d.ts +0 -0
  117. /package/{action → dist/action}/executor.js +0 -0
  118. /package/{action → dist/action}/experimental_action.d.ts +0 -0
  119. /package/{action → dist/action}/experimental_action.js +0 -0
  120. /package/{action → dist/action}/index.d.ts +0 -0
  121. /package/{action → dist/action}/index.js +0 -0
  122. /package/{action → dist/action}/operations.d.ts +0 -0
  123. /package/{action → dist/action}/operations.js +0 -0
  124. /package/{action → dist/action}/orchestrator.d.ts +0 -0
  125. /package/{action → dist/action}/orchestrator.js +0 -0
  126. /package/{action → dist/action}/privacy.d.ts +0 -0
  127. /package/{action → dist/action}/privacy.js +0 -0
  128. /package/{action → dist/action}/relative_value.d.ts +0 -0
  129. /package/{action → dist/action}/relative_value.js +0 -0
  130. /package/{action → dist/action}/transaction.d.ts +0 -0
  131. /package/{action → dist/action}/transaction.js +0 -0
  132. /package/{auth → dist/auth}/auth.d.ts +0 -0
  133. /package/{auth → dist/auth}/auth.js +0 -0
  134. /package/{auth → dist/auth}/index.d.ts +0 -0
  135. /package/{auth → dist/auth}/index.js +0 -0
  136. /package/{core → dist/core}/base.d.ts +0 -0
  137. /package/{core → dist/core}/base.js +0 -0
  138. /package/{core → dist/core}/clause.d.ts +0 -0
  139. /package/{core → dist/core}/clause.js +0 -0
  140. /package/{core → dist/core}/config.d.ts +0 -0
  141. /package/{core → dist/core}/config.js +0 -0
  142. /package/{core → dist/core}/const.d.ts +0 -0
  143. /package/{core → dist/core}/const.js +0 -0
  144. /package/{core → dist/core}/context.d.ts +0 -0
  145. /package/{core → dist/core}/context.js +0 -0
  146. /package/{core → dist/core}/convert.d.ts +0 -0
  147. /package/{core → dist/core}/convert.js +0 -0
  148. /package/{core → dist/core}/date.d.ts +0 -0
  149. /package/{core → dist/core}/date.js +0 -0
  150. /package/{core → dist/core}/db.d.ts +0 -0
  151. /package/{core → dist/core}/db.js +0 -0
  152. /package/{core → dist/core}/ent.d.ts +0 -0
  153. /package/{core → dist/core}/ent.js +0 -0
  154. /package/{core → dist/core}/global_schema.d.ts +0 -0
  155. /package/{core → dist/core}/global_schema.js +0 -0
  156. /package/{core → dist/core}/loaders/assoc_count_loader.d.ts +0 -0
  157. /package/{core → dist/core}/loaders/assoc_count_loader.js +0 -0
  158. /package/{core → dist/core}/loaders/assoc_edge_loader.d.ts +0 -0
  159. /package/{core → dist/core}/loaders/assoc_edge_loader.js +0 -0
  160. /package/{core → dist/core}/loaders/index.d.ts +0 -0
  161. /package/{core → dist/core}/loaders/index.js +0 -0
  162. /package/{core → dist/core}/loaders/loader.d.ts +0 -0
  163. /package/{core → dist/core}/loaders/loader.js +0 -0
  164. /package/{core → dist/core}/loaders/object_loader.d.ts +0 -0
  165. /package/{core → dist/core}/loaders/object_loader.js +0 -0
  166. /package/{core → dist/core}/loaders/query_loader.d.ts +0 -0
  167. /package/{core → dist/core}/loaders/query_loader.js +0 -0
  168. /package/{core → dist/core}/loaders/raw_count_loader.d.ts +0 -0
  169. /package/{core → dist/core}/loaders/raw_count_loader.js +0 -0
  170. /package/{core → dist/core}/logger.d.ts +0 -0
  171. /package/{core → dist/core}/logger.js +0 -0
  172. /package/{core → dist/core}/privacy.d.ts +0 -0
  173. /package/{core → dist/core}/privacy.js +0 -0
  174. /package/{core → dist/core}/query/assoc_query.d.ts +0 -0
  175. /package/{core → dist/core}/query/assoc_query.js +0 -0
  176. /package/{core → dist/core}/query/custom_clause_query.d.ts +0 -0
  177. /package/{core → dist/core}/query/custom_clause_query.js +0 -0
  178. /package/{core → dist/core}/query/custom_query.d.ts +0 -0
  179. /package/{core → dist/core}/query/custom_query.js +0 -0
  180. /package/{core → dist/core}/query/index.d.ts +0 -0
  181. /package/{core → dist/core}/query/index.js +0 -0
  182. /package/{core → dist/core}/query/query.d.ts +0 -0
  183. /package/{core → dist/core}/query/query.js +0 -0
  184. /package/{core → dist/core}/query_impl.d.ts +0 -0
  185. /package/{core → dist/core}/query_impl.js +0 -0
  186. /package/{core → dist/core}/viewer.d.ts +0 -0
  187. /package/{core → dist/core}/viewer.js +0 -0
  188. /package/{graphql → dist/graphql}/builtins/connection.d.ts +0 -0
  189. /package/{graphql → dist/graphql}/builtins/connection.js +0 -0
  190. /package/{graphql → dist/graphql}/builtins/edge.d.ts +0 -0
  191. /package/{graphql → dist/graphql}/builtins/edge.js +0 -0
  192. /package/{graphql → dist/graphql}/builtins/node.d.ts +0 -0
  193. /package/{graphql → dist/graphql}/builtins/node.js +0 -0
  194. /package/{graphql → dist/graphql}/graphql.d.ts +0 -0
  195. /package/{graphql → dist/graphql}/graphql.js +0 -0
  196. /package/{graphql → dist/graphql}/graphql_field_helpers.d.ts +0 -0
  197. /package/{graphql → dist/graphql}/graphql_field_helpers.js +0 -0
  198. /package/{graphql → dist/graphql}/index.d.ts +0 -0
  199. /package/{graphql → dist/graphql}/index.js +0 -0
  200. /package/{graphql → dist/graphql}/mutations/union.d.ts +0 -0
  201. /package/{graphql → dist/graphql}/mutations/union.js +0 -0
  202. /package/{graphql → dist/graphql}/node_resolver.d.ts +0 -0
  203. /package/{graphql → dist/graphql}/node_resolver.js +0 -0
  204. /package/{graphql → dist/graphql}/query/connection_type.d.ts +0 -0
  205. /package/{graphql → dist/graphql}/query/connection_type.js +0 -0
  206. /package/{graphql → dist/graphql}/query/edge_connection.d.ts +0 -0
  207. /package/{graphql → dist/graphql}/query/edge_connection.js +0 -0
  208. /package/{graphql → dist/graphql}/query/page_info.d.ts +0 -0
  209. /package/{graphql → dist/graphql}/query/page_info.js +0 -0
  210. /package/{graphql → dist/graphql}/query/shared_edge_connection.d.ts +0 -0
  211. /package/{graphql → dist/graphql}/query/shared_edge_connection.js +0 -0
  212. /package/{graphql → dist/graphql}/scalars/orderby_direction.d.ts +0 -0
  213. /package/{graphql → dist/graphql}/scalars/orderby_direction.js +0 -0
  214. /package/{graphql → dist/graphql}/scalars/time.d.ts +0 -0
  215. /package/{graphql → dist/graphql}/scalars/time.js +0 -0
  216. /package/{imports → dist/imports}/dataz/example1/_auth.d.ts +0 -0
  217. /package/{imports → dist/imports}/dataz/example1/_auth.js +0 -0
  218. /package/{imports → dist/imports}/dataz/example1/_viewer.d.ts +0 -0
  219. /package/{imports → dist/imports}/dataz/example1/_viewer.js +0 -0
  220. /package/{imports → dist/imports}/index.d.ts +0 -0
  221. /package/{imports → dist/imports}/index.js +0 -0
  222. /package/{index.d.ts → dist/index.d.ts} +0 -0
  223. /package/{index.js → dist/index.js} +0 -0
  224. /package/{parse_schema → dist/parse_schema}/parse.d.ts +0 -0
  225. /package/{parse_schema → dist/parse_schema}/parse.js +0 -0
  226. /package/{schema → dist/schema}/base_schema.d.ts +0 -0
  227. /package/{schema → dist/schema}/base_schema.js +0 -0
  228. /package/{schema → dist/schema}/field.d.ts +0 -0
  229. /package/{schema → dist/schema}/field.js +0 -0
  230. /package/{schema → dist/schema}/index.d.ts +0 -0
  231. /package/{schema → dist/schema}/index.js +0 -0
  232. /package/{schema → dist/schema}/json_field.d.ts +0 -0
  233. /package/{schema → dist/schema}/json_field.js +0 -0
  234. /package/{schema → dist/schema}/schema.d.ts +0 -0
  235. /package/{schema → dist/schema}/schema.js +0 -0
  236. /package/{schema → dist/schema}/struct_field.d.ts +0 -0
  237. /package/{schema → dist/schema}/struct_field.js +0 -0
  238. /package/{schema → dist/schema}/union_field.d.ts +0 -0
  239. /package/{schema → dist/schema}/union_field.js +0 -0
  240. /package/{scripts → dist/scripts}/custom_compiler.d.ts +0 -0
  241. /package/{scripts → dist/scripts}/custom_compiler.js +0 -0
  242. /package/{scripts → dist/scripts}/custom_graphql.d.ts +0 -0
  243. /package/{scripts → dist/scripts}/custom_graphql.js +0 -0
  244. /package/{scripts → dist/scripts}/migrate_v0.1.d.ts +0 -0
  245. /package/{scripts → dist/scripts}/migrate_v0.1.js +0 -0
  246. /package/{scripts → dist/scripts}/move_types.d.ts +0 -0
  247. /package/{scripts → dist/scripts}/move_types.js +0 -0
  248. /package/{scripts → dist/scripts}/read_schema.d.ts +0 -0
  249. /package/{scripts → dist/scripts}/read_schema.js +0 -0
  250. /package/{testutils → dist/testutils}/action/complex_schemas.d.ts +0 -0
  251. /package/{testutils → dist/testutils}/action/complex_schemas.js +0 -0
  252. /package/{testutils → dist/testutils}/builder.d.ts +0 -0
  253. /package/{testutils → dist/testutils}/builder.js +0 -0
  254. /package/{testutils → dist/testutils}/context/test_context.d.ts +0 -0
  255. /package/{testutils → dist/testutils}/context/test_context.js +0 -0
  256. /package/{testutils → dist/testutils}/db/fixture.d.ts +0 -0
  257. /package/{testutils → dist/testutils}/db/fixture.js +0 -0
  258. /package/{testutils → dist/testutils}/db/temp_db.d.ts +0 -0
  259. /package/{testutils → dist/testutils}/db/temp_db.js +0 -0
  260. /package/{testutils → dist/testutils}/db/value.d.ts +0 -0
  261. /package/{testutils → dist/testutils}/db/value.js +0 -0
  262. /package/{testutils → dist/testutils}/db_mock.d.ts +0 -0
  263. /package/{testutils → dist/testutils}/db_mock.js +0 -0
  264. /package/{testutils → dist/testutils}/db_time_zone.d.ts +0 -0
  265. /package/{testutils → dist/testutils}/db_time_zone.js +0 -0
  266. /package/{testutils → dist/testutils}/ent-graphql-tests/index.d.ts +0 -0
  267. /package/{testutils → dist/testutils}/ent-graphql-tests/index.js +0 -0
  268. /package/{testutils → dist/testutils}/fake_comms.d.ts +0 -0
  269. /package/{testutils → dist/testutils}/fake_comms.js +0 -0
  270. /package/{testutils → dist/testutils}/fake_data/const.d.ts +0 -0
  271. /package/{testutils → dist/testutils}/fake_data/const.js +0 -0
  272. /package/{testutils → dist/testutils}/fake_data/events_query.d.ts +0 -0
  273. /package/{testutils → dist/testutils}/fake_data/events_query.js +0 -0
  274. /package/{testutils → dist/testutils}/fake_data/fake_contact.d.ts +0 -0
  275. /package/{testutils → dist/testutils}/fake_data/fake_contact.js +0 -0
  276. /package/{testutils → dist/testutils}/fake_data/fake_event.d.ts +0 -0
  277. /package/{testutils → dist/testutils}/fake_data/fake_event.js +0 -0
  278. /package/{testutils → dist/testutils}/fake_data/fake_tag.d.ts +0 -0
  279. /package/{testutils → dist/testutils}/fake_data/fake_tag.js +0 -0
  280. /package/{testutils → dist/testutils}/fake_data/fake_user.d.ts +0 -0
  281. /package/{testutils → dist/testutils}/fake_data/fake_user.js +0 -0
  282. /package/{testutils → dist/testutils}/fake_data/index.d.ts +0 -0
  283. /package/{testutils → dist/testutils}/fake_data/index.js +0 -0
  284. /package/{testutils → dist/testutils}/fake_data/internal.d.ts +0 -0
  285. /package/{testutils → dist/testutils}/fake_data/internal.js +0 -0
  286. /package/{testutils → dist/testutils}/fake_data/tag_query.d.ts +0 -0
  287. /package/{testutils → dist/testutils}/fake_data/tag_query.js +0 -0
  288. /package/{testutils → dist/testutils}/fake_data/test_helpers.d.ts +0 -0
  289. /package/{testutils → dist/testutils}/fake_data/test_helpers.js +0 -0
  290. /package/{testutils → dist/testutils}/fake_data/user_query.d.ts +0 -0
  291. /package/{testutils → dist/testutils}/fake_data/user_query.js +0 -0
  292. /package/{testutils → dist/testutils}/fake_log.d.ts +0 -0
  293. /package/{testutils → dist/testutils}/fake_log.js +0 -0
  294. /package/{testutils → dist/testutils}/mock_date.d.ts +0 -0
  295. /package/{testutils → dist/testutils}/mock_date.js +0 -0
  296. /package/{testutils → dist/testutils}/mock_log.d.ts +0 -0
  297. /package/{testutils → dist/testutils}/mock_log.js +0 -0
  298. /package/{testutils → dist/testutils}/parse_sql.d.ts +0 -0
  299. /package/{testutils → dist/testutils}/parse_sql.js +0 -0
  300. /package/{testutils → dist/testutils}/test_edge_global_schema.d.ts +0 -0
  301. /package/{testutils → dist/testutils}/test_edge_global_schema.js +0 -0
  302. /package/{testutils → dist/testutils}/write.d.ts +0 -0
  303. /package/{testutils → dist/testutils}/write.js +0 -0
  304. /package/{tsc → dist/tsc}/ast.d.ts +0 -0
  305. /package/{tsc → dist/tsc}/ast.js +0 -0
  306. /package/{tsc → dist/tsc}/compilerOptions.d.ts +0 -0
  307. /package/{tsc → dist/tsc}/compilerOptions.js +0 -0
  308. /package/{tsc → dist/tsc}/move_generated.d.ts +0 -0
  309. /package/{tsc → dist/tsc}/move_generated.js +0 -0
  310. /package/{tsc → dist/tsc}/transform.d.ts +0 -0
  311. /package/{tsc → dist/tsc}/transform.js +0 -0
  312. /package/{tsc → dist/tsc}/transform_action.d.ts +0 -0
  313. /package/{tsc → dist/tsc}/transform_action.js +0 -0
  314. /package/{tsc → dist/tsc}/transform_ent.d.ts +0 -0
  315. /package/{tsc → dist/tsc}/transform_ent.js +0 -0
  316. /package/{tsc → dist/tsc}/transform_schema.d.ts +0 -0
  317. /package/{tsc → dist/tsc}/transform_schema.js +0 -0
@@ -1,736 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.commonTests = void 0;
4
- const ent_1 = require("../ent");
5
- const global_schema_1 = require("../global_schema");
6
- const viewer_1 = require("../viewer");
7
- const index_1 = require("../../testutils/fake_data/index");
8
- const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
9
- const temp_db_1 = require("../../testutils/db/temp_db");
10
- const test_context_1 = require("../../testutils/context/test_context");
11
- const logger_1 = require("../logger");
12
- const test_edge_global_schema_1 = require("../../testutils/test_edge_global_schema");
13
- const builder_1 = require("../../testutils/builder");
14
- const action_1 = require("../../action");
15
- const clause_1 = require("../clause");
16
- const query_impl_1 = require("../query_impl");
17
- function getWhereClause(query) {
18
- const idx = query.query.indexOf("WHERE");
19
- if (idx !== -1) {
20
- return query.query.substr(idx + 6);
21
- }
22
- return null;
23
- }
24
- const commonTests = (opts) => {
25
- (0, logger_1.setLogLevels)(["query", "error"]);
26
- const ml = opts.ml;
27
- ml.mock();
28
- function isCustomQuery(q) {
29
- if (q.customQuery !== undefined) {
30
- return q.customQuery;
31
- }
32
- // TODO sad not generic enough
33
- return (q instanceof index_1.UserToContactsFkeyQuery ||
34
- q instanceof index_1.UserToContactsFkeyQueryDeprecated ||
35
- q instanceof index_1.UserToContactsFkeyQueryAsc);
36
- }
37
- class TestQueryFilter {
38
- constructor(filter, newQuery, ents, defaultViewer) {
39
- this.filter = filter;
40
- this.newQuery = newQuery;
41
- this.ents = ents;
42
- this.defaultViewer = defaultViewer;
43
- this.allContacts = [];
44
- this.filteredContacts = [];
45
- // @ts-ignore
46
- const q = this.newQuery(this.defaultViewer);
47
- this.customQuery = isCustomQuery(q);
48
- }
49
- async createData() {
50
- [this.user, this.allContacts] = await (0, test_helpers_1.createAllContacts)();
51
- // this.allContacts = this.allContacts.reverse();
52
- this.filteredContacts = this.ents(this.allContacts);
53
- ml.clear();
54
- }
55
- getQuery(viewer) {
56
- return this.filter(this.newQuery(viewer || this.defaultViewer, this.user), this.user, this.allContacts);
57
- }
58
- async testIDs() {
59
- const ids = await this.getQuery().queryIDs();
60
- this.verifyIDs(ids);
61
- }
62
- verifyIDs(ids) {
63
- expect(ids).toEqual(this.filteredContacts.map((contact) => contact.id));
64
- }
65
- // rawCount isn't affected by filters...
66
- async testRawCount(expectedCount) {
67
- const count = await this.getQuery().queryRawCount();
68
- this.verifyRawCount(count, expectedCount);
69
- }
70
- verifyRawCount(count, expectedCount) {
71
- expect(count).toBe(expectedCount ?? test_helpers_1.inputs.length);
72
- }
73
- async testCount(expectedCount) {
74
- const count = await this.getQuery().queryCount();
75
- this.verifyCount(count, expectedCount);
76
- }
77
- verifyCount(count, expectedCount) {
78
- expect(count).toBe(expectedCount ?? this.filteredContacts.length);
79
- }
80
- async testEdges() {
81
- const edges = await this.getQuery().queryEdges();
82
- this.verifyEdges(edges);
83
- }
84
- verifyEdges(edges) {
85
- // TODO sad not generic enough
86
- if (this.customQuery) {
87
- (0, test_helpers_1.verifyUserToContactRawData)(this.user, edges, this.filteredContacts);
88
- }
89
- else {
90
- (0, test_helpers_1.verifyUserToContactEdges)(this.user, edges, this.filteredContacts);
91
- }
92
- }
93
- async testEnts(v) {
94
- const ents = await this.getQuery(v || new viewer_1.IDViewer(this.user.id)).queryEnts();
95
- this.verifyEnts(ents);
96
- return ents;
97
- }
98
- async testEntsCache() {
99
- if (!this.customQuery) {
100
- return;
101
- }
102
- (0, logger_1.setLogLevels)(["query", "cache"]);
103
- const v = new test_context_1.TestContext(new viewer_1.IDViewer(this.user.id)).getViewer();
104
- const ents = await this.testEnts(v);
105
- expect(ml.logs.length).toBe(1);
106
- expect(ml.logs[0].query).toMatch(/SELECT (.+) FROM /);
107
- await Promise.all(ents.map((ent) => index_1.FakeContact.loadX(v, ent.id)));
108
- expect(ml.logs.length).toBe(this.filteredContacts.length + 1);
109
- for (const log of ml.logs.slice(1)) {
110
- expect(log["ent-cache-hit"]).toBeDefined();
111
- }
112
- // "restore" back to previous
113
- (0, logger_1.setLogLevels)("query");
114
- }
115
- async testDataCache() {
116
- if (!this.customQuery) {
117
- return;
118
- }
119
- (0, logger_1.setLogLevels)(["query", "cache"]);
120
- const v = new test_context_1.TestContext(new viewer_1.IDViewer(this.user.id)).getViewer();
121
- const ents = await this.testEnts(v);
122
- expect(ml.logs.length).toBe(1);
123
- expect(ml.logs[0].query).toMatch(/SELECT (.+) FROM /);
124
- await Promise.all(ents.map((ent) => index_1.FakeContact.loadRawData(ent.id, v.context)));
125
- expect(ml.logs.length).toBe(this.filteredContacts.length + 1);
126
- for (const log of ml.logs.slice(1)) {
127
- expect(log["dataloader-cache-hit"]).toBeDefined();
128
- }
129
- // "restore" back to previous
130
- (0, logger_1.setLogLevels)("query");
131
- }
132
- verifyEnts(ents) {
133
- (0, test_helpers_1.verifyUserToContacts)(this.user, ents, this.filteredContacts);
134
- }
135
- async testAll(expectedCount) {
136
- const query = this.getQuery(new viewer_1.IDViewer(this.user.id));
137
- const [edges, count, ids, rawCount, ents] = await Promise.all([
138
- query.queryEdges(),
139
- query.queryCount(),
140
- query.queryIDs(),
141
- query.queryRawCount(),
142
- query.queryEnts(),
143
- ]);
144
- this.verifyCount(count, expectedCount);
145
- this.verifyEdges(edges);
146
- this.verifyIDs(ids);
147
- this.verifyRawCount(rawCount, expectedCount);
148
- this.verifyEnts(ents);
149
- }
150
- }
151
- function verifyQuery(filter, { length = 1, numQueries = 1, limit = (0, ent_1.getDefaultLimit)(), disablePaginationBump = false, orderby = opts.orderby, }) {
152
- const uniqCol = isCustomQuery(filter) ? "id" : "id2";
153
- expect(ml.logs.length).toBe(length);
154
- for (let i = 0; i < numQueries; i++) {
155
- const whereClause = getWhereClause(ml.logs[i]);
156
- let expLimit = disablePaginationBump ? limit : limit + 1;
157
- expect(whereClause, `${i}`).toBe(
158
- // default limit
159
- `${opts.clause.clause(1)} ORDER BY ${(0, query_impl_1.getOrderByPhrase)(orderby)}, ${uniqCol} ${orderby[0].direction} LIMIT ${expLimit}`);
160
- }
161
- }
162
- function verifyCountQuery({ length = 1, numQueries = 1 }) {
163
- expect(ml.logs.length).toBe(length);
164
- for (let i = 0; i < numQueries; i++) {
165
- const whereClause = getWhereClause(ml.logs[i]);
166
- expect(whereClause).toBe(opts.clause.clause(1));
167
- }
168
- }
169
- function verifyFirstAfterCursorQuery(filter, length = 1, limit = 3) {
170
- // cache showing up in a few because of cross runs...
171
- expect(ml.logs.length).toBeGreaterThanOrEqual(length);
172
- const uniqCol = isCustomQuery(filter) ? "id" : "id2";
173
- let parts = opts.clause.clause(1).split(" AND ");
174
- const cmp = (0, clause_1.PaginationMultipleColsSubQuery)(opts.orderby[0].column, opts.orderby[0].direction === "DESC" ? "<" : ">", opts.tableName, uniqCol, "").clause(opts.clause.values().length + 1);
175
- if (parts[parts.length - 1] === "deleted_at IS NULL") {
176
- parts = parts
177
- .slice(0, parts.length - 1)
178
- .concat([cmp, "deleted_at IS NULL"]);
179
- }
180
- else {
181
- parts.push(cmp);
182
- }
183
- expect(getWhereClause(ml.logs[0])).toBe(`${parts.join(" AND ")} ORDER BY ${(0, query_impl_1.getOrderByPhrase)(opts.orderby)}, ${uniqCol} ${opts.orderby[0].direction} LIMIT ${limit + 1}`);
184
- }
185
- function verifyLastBeforeCursorQuery(filter, { length = 1, limit = 3, orderby = opts.orderby }) {
186
- // cache showing up in a few because of cross runs...
187
- expect(ml.logs.length).toBeGreaterThanOrEqual(length);
188
- const uniqCol = isCustomQuery(filter) ? "id" : "id2";
189
- let parts = opts.clause.clause(1).split(" AND ");
190
- const cmp = (0, clause_1.PaginationMultipleColsSubQuery)(orderby[0].column, orderby[0].direction === "ASC" ? ">" : "<", opts.tableName, uniqCol, "").clause(opts.clause.values().length + 1);
191
- if (parts[parts.length - 1] === "deleted_at IS NULL") {
192
- parts = parts
193
- .slice(0, parts.length - 1)
194
- .concat([cmp, "deleted_at IS NULL"]);
195
- }
196
- else {
197
- parts.push(cmp);
198
- }
199
- expect(getWhereClause(ml.logs[0])).toBe(
200
- // extra fetched for pagination
201
- `${parts.join(" AND ")} ORDER BY ${(0, query_impl_1.getOrderByPhrase)(orderby)}, ${uniqCol} ${orderby[0].direction} LIMIT ${limit + 1}`);
202
- }
203
- function getViewer() {
204
- return new viewer_1.LoggedOutViewer();
205
- }
206
- function getCursorFrom(contacts, idx) {
207
- return (0, ent_1.getCursor)({
208
- row: contacts[idx],
209
- col: "id",
210
- });
211
- }
212
- function getVerifyAfterEachCursor(edges, pageLength, user) {
213
- let query;
214
- async function verify(i, hasEdge, hasNextPage, cursor) {
215
- ml.clear();
216
- query = opts.newQuery(getViewer(), user);
217
- const newEdges = await query.first(pageLength, cursor).queryEdges();
218
- const pagination = query.paginationInfo().get(user.id);
219
- if (hasEdge) {
220
- expect(newEdges[0], `${i}`).toStrictEqual(edges[i]);
221
- expect(newEdges.length, `${i}`).toBe(edges.length - i >= pageLength ? pageLength : edges.length - i);
222
- }
223
- else {
224
- expect(newEdges.length, `${i}`).toBe(0);
225
- }
226
- if (hasNextPage) {
227
- expect(pagination?.hasNextPage, `${i}`).toBe(true);
228
- expect(pagination?.hasPreviousPage, `${i}`).toBe(false);
229
- }
230
- else {
231
- expect(pagination?.hasNextPage, `${i}`).toBe(undefined);
232
- expect(pagination?.hasNextPage, `${i}`).toBe(undefined);
233
- }
234
- if (cursor) {
235
- verifyFirstAfterCursorQuery(query, 1, pageLength);
236
- }
237
- else {
238
- verifyQuery(query, { orderby: opts.orderby, limit: pageLength });
239
- }
240
- }
241
- function getCursor(edge) {
242
- return query.getCursor(edge);
243
- }
244
- return { verify, getCursor };
245
- }
246
- function getVerifyBeforeEachCursor(edges, pageLength, user) {
247
- let query;
248
- async function verify(i, hasEdge, hasPreviousPage, cursor) {
249
- ml.clear();
250
- query = opts.newQuery(getViewer(), user);
251
- const newEdges = await query.last(pageLength, cursor).queryEdges();
252
- const pagination = query.paginationInfo().get(user.id);
253
- if (hasEdge) {
254
- expect(newEdges.length, `${i}`).toBe(i >= pageLength ? pageLength : i + 1);
255
- expect(newEdges[0], `${i}`).toStrictEqual(edges[i]);
256
- }
257
- else {
258
- expect(newEdges.length, `${i}`).toBe(0);
259
- }
260
- if (hasPreviousPage) {
261
- expect(pagination?.hasPreviousPage, `${i}`).toBe(true);
262
- expect(pagination?.hasNextPage, `${i}`).toBe(false);
263
- }
264
- else {
265
- expect(pagination?.hasPreviousPage, `${i}`).toBe(undefined);
266
- expect(pagination?.hasNextPage, `${i}`).toBe(undefined);
267
- }
268
- const orderby = (0, query_impl_1.reverseOrderBy)(opts.orderby);
269
- if (cursor) {
270
- verifyLastBeforeCursorQuery(query, {
271
- length: 1,
272
- limit: pageLength,
273
- orderby,
274
- });
275
- }
276
- else {
277
- verifyQuery(query, {
278
- orderby,
279
- limit: pageLength,
280
- });
281
- }
282
- }
283
- function getCursor(edge) {
284
- return query.getCursor(edge);
285
- }
286
- return { verify, getCursor };
287
- }
288
- if (opts.globalSchema) {
289
- (0, global_schema_1.setGlobalSchema)(test_edge_global_schema_1.testEdgeGlobalSchema);
290
- }
291
- let tdb;
292
- if (opts.sqlite) {
293
- (0, temp_db_1.setupSqlite)(`sqlite:///shared_test+${opts.uniqKey}.db`, () => (0, test_helpers_1.tempDBTables)(opts.globalSchema), {
294
- disableDeleteAfterEachTest: true,
295
- });
296
- }
297
- beforeAll(async () => {
298
- if (opts.livePostgresDB) {
299
- tdb = await (0, test_helpers_1.setupTempDB)(opts.globalSchema);
300
- return;
301
- }
302
- await (0, test_helpers_1.createEdges)();
303
- });
304
- afterAll(async () => {
305
- if (opts.livePostgresDB && tdb) {
306
- await tdb.afterAll();
307
- }
308
- });
309
- describe("simple queries", () => {
310
- const filter = new TestQueryFilter((q) => {
311
- // no filters
312
- return q;
313
- }, opts.newQuery, (contacts) => {
314
- // nothing to do here
315
- // reverse because edges are most recent first
316
- if (opts.orderby[0].direction === "DESC") {
317
- return contacts.reverse();
318
- }
319
- return contacts;
320
- }, getViewer());
321
- beforeEach(async () => {
322
- await filter.createData();
323
- });
324
- test("ids", async () => {
325
- await filter.testIDs();
326
- verifyQuery(filter, {});
327
- });
328
- test("rawCount", async () => {
329
- await filter.testRawCount();
330
- verifyCountQuery({});
331
- });
332
- test("count", async () => {
333
- await filter.testCount();
334
- verifyQuery(filter, {});
335
- });
336
- test("edges", async () => {
337
- await filter.testEdges();
338
- verifyQuery(filter, {});
339
- });
340
- test("ents", async () => {
341
- await filter.testEnts();
342
- verifyQuery(filter, { length: opts.entsLength });
343
- });
344
- test("all", async () => {
345
- await filter.testAll();
346
- });
347
- test("ents cache", async () => {
348
- await filter.testEntsCache();
349
- });
350
- test("data cache", async () => {
351
- await filter.testDataCache();
352
- });
353
- });
354
- describe("override default limit", () => {
355
- const filter = new TestQueryFilter((q) => {
356
- // no filters
357
- return q;
358
- }, opts.newQuery, (contacts) => {
359
- // nothing to do here
360
- // reverse because edges are most recent first
361
- if (opts.orderby[0].direction === "DESC") {
362
- return contacts.reverse();
363
- }
364
- return contacts;
365
- }, getViewer());
366
- const OUR_DEFAULT_LIMIT = 10;
367
- beforeAll(async () => {
368
- (0, ent_1.setDefaultLimit)(OUR_DEFAULT_LIMIT);
369
- });
370
- afterAll(async () => {
371
- //set it back to real default
372
- (0, ent_1.setDefaultLimit)(1000);
373
- });
374
- beforeEach(async () => {
375
- await filter.createData();
376
- });
377
- test("ids", async () => {
378
- await filter.testIDs();
379
- verifyQuery(filter, {
380
- limit: OUR_DEFAULT_LIMIT,
381
- });
382
- });
383
- test("rawCount", async () => {
384
- await filter.testRawCount();
385
- verifyCountQuery({});
386
- });
387
- test("count", async () => {
388
- await filter.testCount();
389
- verifyQuery(filter, {
390
- limit: OUR_DEFAULT_LIMIT,
391
- });
392
- });
393
- test("edges", async () => {
394
- await filter.testEdges();
395
- verifyQuery(filter, {
396
- limit: OUR_DEFAULT_LIMIT,
397
- });
398
- });
399
- test("ents", async () => {
400
- await filter.testEnts();
401
- verifyQuery(filter, {
402
- length: opts.entsLength,
403
- limit: OUR_DEFAULT_LIMIT,
404
- });
405
- });
406
- test("all", async () => {
407
- await filter.testAll();
408
- });
409
- test("ents cache", async () => {
410
- await filter.testEntsCache();
411
- });
412
- test("data cache", async () => {
413
- await filter.testDataCache();
414
- });
415
- });
416
- describe("after delete", () => {
417
- const filter = new TestQueryFilter((q) => {
418
- // no filters
419
- return q;
420
- }, opts.newQuery, (contacts) => {
421
- // nothing expected since deleted
422
- return [];
423
- }, getViewer());
424
- beforeEach(async () => {
425
- await filter.createData();
426
- const action = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeUserSchema, new Map(), action_1.WriteOperation.Edit, filter.user);
427
- await Promise.all(filter.allContacts.map(async (contact) => {
428
- action.builder.orchestrator.removeOutboundEdge(contact.id, index_1.EdgeType.UserToContacts);
429
- const action2 = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeContactSchema, new Map(), action_1.WriteOperation.Delete, contact);
430
- await action2.save();
431
- }));
432
- await action.save();
433
- ml.clear();
434
- });
435
- test("ids", async () => {
436
- await filter.testIDs();
437
- verifyQuery(filter, {});
438
- });
439
- test("rawCount", async () => {
440
- await filter.testRawCount(0);
441
- verifyCountQuery({});
442
- });
443
- test("count", async () => {
444
- await filter.testCount(0);
445
- verifyQuery(filter, {});
446
- });
447
- test("edges", async () => {
448
- await filter.testEdges();
449
- verifyQuery(filter, {});
450
- });
451
- test("ents", async () => {
452
- await filter.testEnts();
453
- // no ents so no subsequent query. just the edge query
454
- verifyQuery(filter, { length: 1 });
455
- });
456
- test("all", async () => {
457
- await filter.testAll(0);
458
- });
459
- test("raw_data", async () => {
460
- if (opts.rawDataVerify) {
461
- await opts.rawDataVerify(filter.user);
462
- }
463
- });
464
- test("ents cache", async () => {
465
- await filter.testEntsCache();
466
- });
467
- test("data cache", async () => {
468
- await filter.testDataCache();
469
- });
470
- });
471
- describe("first. no cursor", () => {
472
- const N = 2;
473
- const filter = new TestQueryFilter((q) => {
474
- // no filters
475
- return q.first(N);
476
- }, opts.newQuery, (contacts) => {
477
- if (opts.orderby[0].direction === "DESC") {
478
- return contacts.reverse().slice(0, N);
479
- }
480
- return contacts.slice(0, N);
481
- }, getViewer());
482
- beforeEach(async () => {
483
- await filter.createData();
484
- });
485
- test("ids", async () => {
486
- await filter.testIDs();
487
- verifyQuery(filter, { limit: 2 });
488
- });
489
- test("rawCount", async () => {
490
- await filter.testRawCount();
491
- verifyCountQuery({});
492
- });
493
- test("count", async () => {
494
- await filter.testCount();
495
- verifyQuery(filter, { limit: 2 });
496
- });
497
- test("edges", async () => {
498
- await filter.testEdges();
499
- verifyQuery(filter, { limit: 2 });
500
- });
501
- test("ents", async () => {
502
- await filter.testEnts();
503
- verifyQuery(filter, { limit: 2, length: opts.entsLength });
504
- });
505
- test("all", async () => {
506
- await filter.testAll();
507
- });
508
- test("ents cache", async () => {
509
- await filter.testEntsCache();
510
- });
511
- test("data cache", async () => {
512
- await filter.testDataCache();
513
- });
514
- });
515
- describe("last", () => {
516
- const N = 2;
517
- const filter = new TestQueryFilter((q) => {
518
- // no filters
519
- return q.last(N);
520
- }, opts.newQuery, (contacts) => {
521
- if (opts.orderby[0].direction === "DESC") {
522
- return contacts.slice(0, N);
523
- }
524
- else {
525
- return contacts.reverse().slice(0, N);
526
- }
527
- }, getViewer());
528
- const orderby = (0, query_impl_1.reverseOrderBy)(opts.orderby);
529
- beforeEach(async () => {
530
- await filter.createData();
531
- });
532
- test("ids", async () => {
533
- await filter.testIDs();
534
- verifyQuery(filter, {
535
- orderby,
536
- limit: N,
537
- });
538
- });
539
- test("rawCount", async () => {
540
- await filter.testRawCount();
541
- verifyCountQuery({});
542
- });
543
- test("count", async () => {
544
- await filter.testCount();
545
- verifyQuery(filter, { orderby, limit: N });
546
- });
547
- test("edges", async () => {
548
- await filter.testEdges();
549
- verifyQuery(filter, { orderby, limit: N });
550
- });
551
- test("ents", async () => {
552
- await filter.testEnts();
553
- verifyQuery(filter, {
554
- orderby,
555
- limit: N,
556
- length: opts.entsLength,
557
- });
558
- });
559
- test("all", async () => {
560
- await filter.testAll();
561
- });
562
- test("ents cache", async () => {
563
- await filter.testEntsCache();
564
- });
565
- test("data cache", async () => {
566
- await filter.testDataCache();
567
- });
568
- });
569
- describe("first after cursor", () => {
570
- const idx = 2;
571
- const N = 3;
572
- const filter = new TestQueryFilter((q, user, contacts) => {
573
- return q.first(N, getCursorFrom(contacts, idx));
574
- }, opts.newQuery, (contacts) => {
575
- if (opts.orderby[0].direction === "DESC") {
576
- // < check so we shouldn't get that index
577
- return contacts.reverse().slice(idx + 1, idx + N);
578
- }
579
- else {
580
- return contacts.slice(idx + 1, idx + N);
581
- }
582
- }, getViewer());
583
- beforeAll(async () => {
584
- await filter.createData();
585
- });
586
- beforeEach(() => {
587
- ml.clear();
588
- });
589
- test("ids", async () => {
590
- await filter.testIDs();
591
- verifyFirstAfterCursorQuery(filter);
592
- });
593
- test("rawCount", async () => {
594
- await filter.testRawCount();
595
- verifyCountQuery({});
596
- });
597
- test("count", async () => {
598
- await filter.testCount();
599
- verifyFirstAfterCursorQuery(filter);
600
- });
601
- test("edges", async () => {
602
- await filter.testEdges();
603
- verifyFirstAfterCursorQuery(filter);
604
- });
605
- test("ents", async () => {
606
- await filter.testEnts();
607
- verifyFirstAfterCursorQuery(filter, opts.entsLength);
608
- });
609
- test("all", async () => {
610
- await filter.testAll();
611
- });
612
- test("ents cache", async () => {
613
- await filter.testEntsCache();
614
- });
615
- test("data cache", async () => {
616
- await filter.testDataCache();
617
- });
618
- });
619
- test("first. after each cursor", async () => {
620
- let [user] = await (0, test_helpers_1.createAllContacts)();
621
- const edges = await opts.newQuery(getViewer(), user).queryEdges();
622
- const { verify, getCursor } = getVerifyAfterEachCursor(edges, 1, user);
623
- await verify(0, true, true, undefined);
624
- await verify(1, true, true, getCursor(edges[0]));
625
- await verify(2, true, true, getCursor(edges[1]));
626
- await verify(3, true, true, getCursor(edges[2]));
627
- await verify(4, true, false, getCursor(edges[3]));
628
- await verify(5, false, false, getCursor(edges[4]));
629
- });
630
- describe("last. before cursor", () => {
631
- const idx = 2;
632
- const N = 3;
633
- const filter = new TestQueryFilter((q, user, contacts) => {
634
- return q.last(N, getCursorFrom(contacts, idx));
635
- }, opts.newQuery, (contacts) => {
636
- // > check so we don't want that index
637
- if (opts.orderby[0].direction === "DESC") {
638
- return contacts.reverse().slice(0, idx).reverse(); // because of order returned
639
- }
640
- return contacts.slice(0, idx).reverse(); // because of order returned
641
- }, getViewer());
642
- const orderby = (0, query_impl_1.reverseOrderBy)(opts.orderby);
643
- beforeAll(async () => {
644
- if (opts.livePostgresDB || opts.sqlite) {
645
- await filter.createData();
646
- }
647
- });
648
- beforeEach(async () => {
649
- ml.clear();
650
- });
651
- test("ids", async () => {
652
- await filter.testIDs();
653
- verifyLastBeforeCursorQuery(filter, { orderby });
654
- });
655
- test("rawCount", async () => {
656
- await filter.testRawCount();
657
- verifyCountQuery({});
658
- });
659
- test("count", async () => {
660
- await filter.testCount();
661
- verifyLastBeforeCursorQuery(filter, { orderby });
662
- });
663
- test("edges", async () => {
664
- await filter.testEdges();
665
- verifyLastBeforeCursorQuery(filter, { orderby });
666
- });
667
- test("ents", async () => {
668
- await filter.testEnts();
669
- verifyLastBeforeCursorQuery(filter, { orderby });
670
- });
671
- test("all", async () => {
672
- await filter.testAll();
673
- });
674
- test("ents cache", async () => {
675
- await filter.testEntsCache();
676
- });
677
- test("data cache", async () => {
678
- await filter.testDataCache();
679
- });
680
- });
681
- test("last. before each cursor", async () => {
682
- let [user] = await (0, test_helpers_1.createAllContacts)();
683
- const edges = await opts.newQuery(getViewer(), user).queryEdges();
684
- const { verify, getCursor } = getVerifyBeforeEachCursor(edges, 1, user);
685
- await verify(4, true, true, undefined);
686
- await verify(3, true, true, getCursor(edges[4]));
687
- await verify(2, true, true, getCursor(edges[3]));
688
- await verify(1, true, true, getCursor(edges[2]));
689
- await verify(0, true, false, getCursor(edges[1]));
690
- await verify(-1, false, false, getCursor(edges[0]));
691
- });
692
- describe("with conflicts", () => {
693
- let user;
694
- let allEdges = [];
695
- beforeEach(async () => {
696
- const [u, contacts] = await (0, test_helpers_1.createAllContacts)();
697
- user = u;
698
- const [_, contacts2] = await (0, test_helpers_1.createAllContacts)({
699
- user,
700
- start: contacts[contacts.length - 1].createdAt.getTime() - 100,
701
- });
702
- await (0, test_helpers_1.createAllContacts)({
703
- user,
704
- start: contacts2[contacts.length - 1].createdAt.getTime() - 100,
705
- });
706
- const edges = await opts.newQuery(getViewer(), user).queryEdges();
707
- // confirm there are duplicates...
708
- expect(edges[4].created_at).toStrictEqual(edges[5].created_at);
709
- expect(edges[9].created_at).toStrictEqual(edges[10].created_at);
710
- allEdges = edges;
711
- });
712
- test("first after each cursor", async () => {
713
- const { verify, getCursor } = getVerifyAfterEachCursor(allEdges, 5, user);
714
- // regular pagination
715
- await verify(0, true, true, undefined);
716
- await verify(5, true, true, getCursor(allEdges[4]));
717
- await verify(10, true, false, getCursor(allEdges[9]));
718
- await verify(15, false, false, getCursor(allEdges[14]));
719
- // one without duplicates work if we were paginating at a different place...
720
- await verify(6, true, true, getCursor(allEdges[5]));
721
- await verify(11, true, false, getCursor(allEdges[10]));
722
- });
723
- test("last before each cursor", async () => {
724
- const { verify, getCursor } = getVerifyBeforeEachCursor(allEdges, 5, user);
725
- await verify(14, true, true, undefined);
726
- await verify(13, true, true, getCursor(allEdges[14]));
727
- await verify(8, true, true, getCursor(allEdges[9]));
728
- await verify(9, true, true, getCursor(allEdges[10]));
729
- await verify(3, true, false, getCursor(allEdges[4]));
730
- await verify(4, true, false, getCursor(allEdges[5]));
731
- });
732
- });
733
- };
734
- exports.commonTests = commonTests;
735
- // TODO parse_sql group by...
736
- // or test it with real db...