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

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/core → core}/query/assoc_query.d.ts +3 -0
  2. package/{dist/core → core}/query/assoc_query.js +71 -0
  3. package/{dist/core → core}/query/query.d.ts +3 -0
  4. package/{dist/core → core}/query/query.js +20 -6
  5. package/core/query/shared_assoc_test.d.ts +2 -0
  6. package/core/query/shared_assoc_test.js +1089 -0
  7. package/core/query/shared_test.d.ts +21 -0
  8. package/core/query/shared_test.js +736 -0
  9. package/graphql/query/shared_assoc_test.d.ts +1 -0
  10. package/graphql/query/shared_assoc_test.js +203 -0
  11. package/package.json +8 -53
  12. package/{dist/testutils → testutils}/fake_data/test_helpers.js +2 -1
  13. package/dist/package.json +0 -64
  14. package/src/action/action.ts +0 -330
  15. package/src/action/executor.ts +0 -453
  16. package/src/action/experimental_action.ts +0 -277
  17. package/src/action/index.ts +0 -31
  18. package/src/action/operations.ts +0 -967
  19. package/src/action/orchestrator.ts +0 -1527
  20. package/src/action/privacy.ts +0 -37
  21. package/src/action/relative_value.ts +0 -242
  22. package/src/action/transaction.ts +0 -38
  23. package/src/auth/auth.ts +0 -77
  24. package/src/auth/index.ts +0 -8
  25. package/src/core/base.ts +0 -367
  26. package/src/core/clause.ts +0 -1065
  27. package/src/core/config.ts +0 -219
  28. package/src/core/const.ts +0 -5
  29. package/src/core/context.ts +0 -135
  30. package/src/core/convert.ts +0 -106
  31. package/src/core/date.ts +0 -23
  32. package/src/core/db.ts +0 -498
  33. package/src/core/ent.ts +0 -1740
  34. package/src/core/global_schema.ts +0 -49
  35. package/src/core/loaders/assoc_count_loader.ts +0 -99
  36. package/src/core/loaders/assoc_edge_loader.ts +0 -250
  37. package/src/core/loaders/index.ts +0 -12
  38. package/src/core/loaders/loader.ts +0 -66
  39. package/src/core/loaders/object_loader.ts +0 -489
  40. package/src/core/loaders/query_loader.ts +0 -314
  41. package/src/core/loaders/raw_count_loader.ts +0 -175
  42. package/src/core/logger.ts +0 -49
  43. package/src/core/privacy.ts +0 -660
  44. package/src/core/query/assoc_query.ts +0 -240
  45. package/src/core/query/custom_clause_query.ts +0 -174
  46. package/src/core/query/custom_query.ts +0 -302
  47. package/src/core/query/index.ts +0 -9
  48. package/src/core/query/query.ts +0 -674
  49. package/src/core/query_impl.ts +0 -32
  50. package/src/core/viewer.ts +0 -52
  51. package/src/ent.code-workspace +0 -73
  52. package/src/graphql/builtins/connection.ts +0 -25
  53. package/src/graphql/builtins/edge.ts +0 -16
  54. package/src/graphql/builtins/node.ts +0 -12
  55. package/src/graphql/graphql.ts +0 -891
  56. package/src/graphql/graphql_field_helpers.ts +0 -221
  57. package/src/graphql/index.ts +0 -42
  58. package/src/graphql/mutations/union.ts +0 -39
  59. package/src/graphql/node_resolver.ts +0 -122
  60. package/src/graphql/query/connection_type.ts +0 -113
  61. package/src/graphql/query/edge_connection.ts +0 -171
  62. package/src/graphql/query/page_info.ts +0 -34
  63. package/src/graphql/query/shared_edge_connection.ts +0 -287
  64. package/src/graphql/scalars/orderby_direction.ts +0 -13
  65. package/src/graphql/scalars/time.ts +0 -38
  66. package/src/imports/dataz/example1/_auth.ts +0 -51
  67. package/src/imports/dataz/example1/_viewer.ts +0 -35
  68. package/src/imports/index.ts +0 -213
  69. package/src/index.ts +0 -145
  70. package/src/parse_schema/parse.ts +0 -585
  71. package/src/schema/base_schema.ts +0 -224
  72. package/src/schema/field.ts +0 -1087
  73. package/src/schema/index.ts +0 -53
  74. package/src/schema/json_field.ts +0 -94
  75. package/src/schema/schema.ts +0 -1028
  76. package/src/schema/struct_field.ts +0 -234
  77. package/src/schema/union_field.ts +0 -105
  78. package/src/scripts/custom_compiler.ts +0 -331
  79. package/src/scripts/custom_graphql.ts +0 -550
  80. package/src/scripts/migrate_v0.1.ts +0 -41
  81. package/src/scripts/move_types.ts +0 -131
  82. package/src/scripts/read_schema.ts +0 -67
  83. package/src/setupPackage.js +0 -42
  84. package/src/testutils/action/complex_schemas.ts +0 -517
  85. package/src/testutils/builder.ts +0 -422
  86. package/src/testutils/context/test_context.ts +0 -25
  87. package/src/testutils/db/fixture.ts +0 -32
  88. package/src/testutils/db/temp_db.ts +0 -941
  89. package/src/testutils/db/value.ts +0 -294
  90. package/src/testutils/db_mock.ts +0 -351
  91. package/src/testutils/db_time_zone.ts +0 -40
  92. package/src/testutils/ent-graphql-tests/index.ts +0 -653
  93. package/src/testutils/fake_comms.ts +0 -50
  94. package/src/testutils/fake_data/const.ts +0 -64
  95. package/src/testutils/fake_data/events_query.ts +0 -145
  96. package/src/testutils/fake_data/fake_contact.ts +0 -150
  97. package/src/testutils/fake_data/fake_event.ts +0 -150
  98. package/src/testutils/fake_data/fake_tag.ts +0 -139
  99. package/src/testutils/fake_data/fake_user.ts +0 -232
  100. package/src/testutils/fake_data/index.ts +0 -1
  101. package/src/testutils/fake_data/internal.ts +0 -8
  102. package/src/testutils/fake_data/tag_query.ts +0 -56
  103. package/src/testutils/fake_data/test_helpers.ts +0 -388
  104. package/src/testutils/fake_data/user_query.ts +0 -524
  105. package/src/testutils/fake_log.ts +0 -52
  106. package/src/testutils/mock_date.ts +0 -10
  107. package/src/testutils/mock_log.ts +0 -39
  108. package/src/testutils/parse_sql.ts +0 -685
  109. package/src/testutils/test_edge_global_schema.ts +0 -49
  110. package/src/testutils/write.ts +0 -70
  111. package/src/tsc/ast.ts +0 -351
  112. package/src/tsc/compilerOptions.ts +0 -85
  113. package/src/tsc/move_generated.ts +0 -191
  114. package/src/tsc/transform.ts +0 -226
  115. package/src/tsc/transform_action.ts +0 -224
  116. package/src/tsc/transform_ent.ts +0 -66
  117. package/src/tsc/transform_schema.ts +0 -546
  118. package/tsconfig.json +0 -20
  119. /package/{dist/action → action}/action.d.ts +0 -0
  120. /package/{dist/action → action}/action.js +0 -0
  121. /package/{dist/action → action}/executor.d.ts +0 -0
  122. /package/{dist/action → action}/executor.js +0 -0
  123. /package/{dist/action → action}/experimental_action.d.ts +0 -0
  124. /package/{dist/action → action}/experimental_action.js +0 -0
  125. /package/{dist/action → action}/index.d.ts +0 -0
  126. /package/{dist/action → action}/index.js +0 -0
  127. /package/{dist/action → action}/operations.d.ts +0 -0
  128. /package/{dist/action → action}/operations.js +0 -0
  129. /package/{dist/action → action}/orchestrator.d.ts +0 -0
  130. /package/{dist/action → action}/orchestrator.js +0 -0
  131. /package/{dist/action → action}/privacy.d.ts +0 -0
  132. /package/{dist/action → action}/privacy.js +0 -0
  133. /package/{dist/action → action}/relative_value.d.ts +0 -0
  134. /package/{dist/action → action}/relative_value.js +0 -0
  135. /package/{dist/action → action}/transaction.d.ts +0 -0
  136. /package/{dist/action → action}/transaction.js +0 -0
  137. /package/{dist/auth → auth}/auth.d.ts +0 -0
  138. /package/{dist/auth → auth}/auth.js +0 -0
  139. /package/{dist/auth → auth}/index.d.ts +0 -0
  140. /package/{dist/auth → auth}/index.js +0 -0
  141. /package/{dist/core → core}/base.d.ts +0 -0
  142. /package/{dist/core → core}/base.js +0 -0
  143. /package/{dist/core → core}/clause.d.ts +0 -0
  144. /package/{dist/core → core}/clause.js +0 -0
  145. /package/{dist/core → core}/config.d.ts +0 -0
  146. /package/{dist/core → core}/config.js +0 -0
  147. /package/{dist/core → core}/const.d.ts +0 -0
  148. /package/{dist/core → core}/const.js +0 -0
  149. /package/{dist/core → core}/context.d.ts +0 -0
  150. /package/{dist/core → core}/context.js +0 -0
  151. /package/{dist/core → core}/convert.d.ts +0 -0
  152. /package/{dist/core → core}/convert.js +0 -0
  153. /package/{dist/core → core}/date.d.ts +0 -0
  154. /package/{dist/core → core}/date.js +0 -0
  155. /package/{dist/core → core}/db.d.ts +0 -0
  156. /package/{dist/core → core}/db.js +0 -0
  157. /package/{dist/core → core}/ent.d.ts +0 -0
  158. /package/{dist/core → core}/ent.js +0 -0
  159. /package/{dist/core → core}/global_schema.d.ts +0 -0
  160. /package/{dist/core → core}/global_schema.js +0 -0
  161. /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
  162. /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
  163. /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
  164. /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
  165. /package/{dist/core → core}/loaders/index.d.ts +0 -0
  166. /package/{dist/core → core}/loaders/index.js +0 -0
  167. /package/{dist/core → core}/loaders/loader.d.ts +0 -0
  168. /package/{dist/core → core}/loaders/loader.js +0 -0
  169. /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
  170. /package/{dist/core → core}/loaders/object_loader.js +0 -0
  171. /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
  172. /package/{dist/core → core}/loaders/query_loader.js +0 -0
  173. /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
  174. /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
  175. /package/{dist/core → core}/logger.d.ts +0 -0
  176. /package/{dist/core → core}/logger.js +0 -0
  177. /package/{dist/core → core}/privacy.d.ts +0 -0
  178. /package/{dist/core → core}/privacy.js +0 -0
  179. /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
  180. /package/{dist/core → core}/query/custom_clause_query.js +0 -0
  181. /package/{dist/core → core}/query/custom_query.d.ts +0 -0
  182. /package/{dist/core → core}/query/custom_query.js +0 -0
  183. /package/{dist/core → core}/query/index.d.ts +0 -0
  184. /package/{dist/core → core}/query/index.js +0 -0
  185. /package/{dist/core → core}/query_impl.d.ts +0 -0
  186. /package/{dist/core → core}/query_impl.js +0 -0
  187. /package/{dist/core → core}/viewer.d.ts +0 -0
  188. /package/{dist/core → core}/viewer.js +0 -0
  189. /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
  190. /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
  191. /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
  192. /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
  193. /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
  194. /package/{dist/graphql → graphql}/builtins/node.js +0 -0
  195. /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
  196. /package/{dist/graphql → graphql}/graphql.js +0 -0
  197. /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
  198. /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
  199. /package/{dist/graphql → graphql}/index.d.ts +0 -0
  200. /package/{dist/graphql → graphql}/index.js +0 -0
  201. /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
  202. /package/{dist/graphql → graphql}/mutations/union.js +0 -0
  203. /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
  204. /package/{dist/graphql → graphql}/node_resolver.js +0 -0
  205. /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
  206. /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
  207. /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
  208. /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
  209. /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
  210. /package/{dist/graphql → graphql}/query/page_info.js +0 -0
  211. /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
  212. /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
  213. /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
  214. /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
  215. /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
  216. /package/{dist/graphql → graphql}/scalars/time.js +0 -0
  217. /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
  218. /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
  219. /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
  220. /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
  221. /package/{dist/imports → imports}/index.d.ts +0 -0
  222. /package/{dist/imports → imports}/index.js +0 -0
  223. /package/{dist/index.d.ts → index.d.ts} +0 -0
  224. /package/{dist/index.js → index.js} +0 -0
  225. /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
  226. /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
  227. /package/{dist/schema → schema}/base_schema.d.ts +0 -0
  228. /package/{dist/schema → schema}/base_schema.js +0 -0
  229. /package/{dist/schema → schema}/field.d.ts +0 -0
  230. /package/{dist/schema → schema}/field.js +0 -0
  231. /package/{dist/schema → schema}/index.d.ts +0 -0
  232. /package/{dist/schema → schema}/index.js +0 -0
  233. /package/{dist/schema → schema}/json_field.d.ts +0 -0
  234. /package/{dist/schema → schema}/json_field.js +0 -0
  235. /package/{dist/schema → schema}/schema.d.ts +0 -0
  236. /package/{dist/schema → schema}/schema.js +0 -0
  237. /package/{dist/schema → schema}/struct_field.d.ts +0 -0
  238. /package/{dist/schema → schema}/struct_field.js +0 -0
  239. /package/{dist/schema → schema}/union_field.d.ts +0 -0
  240. /package/{dist/schema → schema}/union_field.js +0 -0
  241. /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
  242. /package/{dist/scripts → scripts}/custom_compiler.js +0 -0
  243. /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
  244. /package/{dist/scripts → scripts}/custom_graphql.js +0 -0
  245. /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
  246. /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
  247. /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
  248. /package/{dist/scripts → scripts}/move_types.js +0 -0
  249. /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
  250. /package/{dist/scripts → scripts}/read_schema.js +0 -0
  251. /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
  252. /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
  253. /package/{dist/testutils → testutils}/builder.d.ts +0 -0
  254. /package/{dist/testutils → testutils}/builder.js +0 -0
  255. /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
  256. /package/{dist/testutils → testutils}/context/test_context.js +0 -0
  257. /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
  258. /package/{dist/testutils → testutils}/db/fixture.js +0 -0
  259. /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
  260. /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
  261. /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
  262. /package/{dist/testutils → testutils}/db/value.js +0 -0
  263. /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
  264. /package/{dist/testutils → testutils}/db_mock.js +0 -0
  265. /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
  266. /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
  267. /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
  268. /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
  269. /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
  270. /package/{dist/testutils → testutils}/fake_comms.js +0 -0
  271. /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
  272. /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
  273. /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
  274. /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
  275. /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
  276. /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
  277. /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
  278. /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
  279. /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
  280. /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
  281. /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
  282. /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
  283. /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
  284. /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
  285. /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
  286. /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
  287. /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
  288. /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
  289. /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +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,232 +0,0 @@
1
- import {
2
- ID,
3
- Ent,
4
- Viewer,
5
- Data,
6
- LoadEntOptions,
7
- PrivacyPolicy,
8
- Skip,
9
- Allow,
10
- Context,
11
- } from "../../core/base";
12
- import { loadEnt, loadEntX } from "../../core/ent";
13
- import {
14
- AllowIfViewerRule,
15
- AlwaysDenyRule,
16
- AllowIfViewerInboundEdgeExistsRule,
17
- AllowIfConditionAppliesRule,
18
- } from "../../core/privacy";
19
- import { getBuilderSchemaFromFields, SimpleAction } from "../builder";
20
- import { StringType } from "../../schema";
21
- import { EdgeType } from "./internal";
22
- import { NodeType } from "./const";
23
- import { IDViewer, IDViewerOptions } from "../../core/viewer";
24
- import { table, uuid, text, timestamptz } from "../db/temp_db";
25
- import { ObjectLoaderFactory } from "../../core/loaders";
26
- import { convertDate } from "../../core/convert";
27
- import { WriteOperation } from "../../action";
28
-
29
- interface TokenOptions extends IDViewerOptions {
30
- tokens?: {};
31
- }
32
-
33
- export class ViewerWithAccessToken extends IDViewer {
34
- constructor(viewerID: ID, private opts?: Partial<TokenOptions>) {
35
- super(viewerID, opts);
36
- }
37
-
38
- hasToken(key: string): boolean {
39
- const tokens = this.opts?.tokens || {};
40
- return tokens[key] !== undefined;
41
- }
42
- }
43
-
44
- export class FakeUser implements Ent {
45
- readonly id: ID;
46
- readonly data: Data;
47
- readonly nodeType = NodeType.FakeUser;
48
- readonly createdAt: Date;
49
- readonly updatedAt: Date;
50
- readonly firstName: string;
51
- readonly lastName: string;
52
- readonly emailAddress: string;
53
- readonly phoneNumber: string | null;
54
- protected readonly password: string | null;
55
-
56
- getPrivacyPolicy(): PrivacyPolicy<this> {
57
- return {
58
- rules: [
59
- AllowIfViewerRule,
60
- {
61
- async apply(v, ent) {
62
- if (!(v instanceof ViewerWithAccessToken)) {
63
- return Skip();
64
- }
65
-
66
- return v.hasToken("always_allow_user") ? Allow() : Skip();
67
- },
68
- },
69
-
70
- // can view user if friends
71
- new AllowIfViewerInboundEdgeExistsRule(EdgeType.UserToFriends),
72
- // can view user if following
73
- new AllowIfViewerInboundEdgeExistsRule(EdgeType.UserToFollowing),
74
- new AllowIfConditionAppliesRule((viewer: Viewer, ent: Ent) => {
75
- if (!(viewer instanceof ViewerWithAccessToken)) {
76
- return false;
77
- }
78
-
79
- return viewer.hasToken("allow_outbound_friend_request");
80
- }, new AllowIfViewerInboundEdgeExistsRule(EdgeType.UserToFriendRequests)),
81
- new AllowIfConditionAppliesRule((viewer: Viewer, ent: Ent) => {
82
- if (!(viewer instanceof ViewerWithAccessToken)) {
83
- return false;
84
- }
85
-
86
- return viewer.hasToken("allow_incoming_friend_request");
87
- }, new AllowIfViewerInboundEdgeExistsRule(EdgeType.UserToIncomingFriendRequests)),
88
- AlwaysDenyRule,
89
- ],
90
- };
91
- }
92
-
93
- constructor(public viewer: Viewer, data: Data) {
94
- this.data = data;
95
- this.id = data.id;
96
- this.createdAt = convertDate(data.created_at);
97
- this.updatedAt = convertDate(data.updated_at);
98
- this.firstName = data.first_name;
99
- this.lastName = data.last_name;
100
- this.emailAddress = data.email_address;
101
- this.phoneNumber = data.phone_number;
102
- this.password = data.password;
103
- }
104
-
105
- __setRawDBData(data: Data) {}
106
-
107
- static getFields(): string[] {
108
- return [
109
- "id",
110
- "created_at",
111
- "updated_at",
112
- "first_name",
113
- "last_name",
114
- "email_address",
115
- "phone_number",
116
- "password",
117
- ];
118
- }
119
-
120
- static getTestTable() {
121
- return table(
122
- "fake_users",
123
- uuid("id", { primaryKey: true }),
124
- timestamptz("created_at"),
125
- timestamptz("updated_at"),
126
- text("first_name"),
127
- text("last_name"),
128
- text("email_address"),
129
- text("phone_number"),
130
- text("password"),
131
- );
132
- }
133
-
134
- static loaderOptions(): LoadEntOptions<FakeUser> {
135
- return {
136
- tableName: "fake_users",
137
- fields: FakeUser.getFields(),
138
- ent: this,
139
- loaderFactory: userLoader,
140
- };
141
- }
142
- static async load(v: Viewer, id: ID): Promise<FakeUser | null> {
143
- return loadEnt(v, id, FakeUser.loaderOptions());
144
- }
145
-
146
- static async loadX(v: Viewer, id: ID): Promise<FakeUser> {
147
- return loadEntX(v, id, FakeUser.loaderOptions());
148
- }
149
- }
150
-
151
- export const FakeUserSchema = getBuilderSchemaFromFields(
152
- {
153
- firstName: StringType(),
154
- lastName: StringType(),
155
- emailAddress: StringType(),
156
- phoneNumber: StringType(),
157
- password: StringType({
158
- nullable: true,
159
- }),
160
- },
161
- FakeUser,
162
- );
163
-
164
- export interface UserCreateInput {
165
- firstName: string;
166
- lastName: string;
167
- emailAddress: string;
168
- phoneNumber: string | null;
169
- password: string | null;
170
- createdAt?: Date;
171
- updatedAt?: Date;
172
- }
173
-
174
- export type UserEditInput = Partial<UserCreateInput>;
175
-
176
- export function getUserBuilder(viewer: Viewer, input: UserCreateInput) {
177
- const action = getUserAction(viewer, input);
178
- return action.builder;
179
- }
180
-
181
- export function getUserAction(viewer: Viewer, input: UserCreateInput) {
182
- const m = new Map();
183
- for (const key in input) {
184
- m.set(key, input[key]);
185
- }
186
- const action = new SimpleAction(
187
- viewer,
188
- FakeUserSchema,
189
- m,
190
- WriteOperation.Insert,
191
- null,
192
- );
193
- action.viewerForEntLoad = (data: Data, context?: Context) => {
194
- // load the created ent using a VC of the newly created user.
195
- return new IDViewer(data.id, {
196
- context,
197
- });
198
- };
199
- return action;
200
- }
201
-
202
- export async function createUser(viewer: Viewer, input: UserCreateInput) {
203
- const action = getUserAction(viewer, input);
204
- return action.saveX();
205
- }
206
-
207
- export const userLoader = new ObjectLoaderFactory({
208
- tableName: "fake_users",
209
- fields: FakeUser.getFields(),
210
- key: "id",
211
- });
212
-
213
- export const userEmailLoader = new ObjectLoaderFactory({
214
- tableName: "fake_users",
215
- fields: FakeUser.getFields(),
216
- key: "email_address",
217
- });
218
-
219
- export const userPhoneNumberLoader = new ObjectLoaderFactory({
220
- tableName: "fake_users",
221
- fields: FakeUser.getFields(),
222
- key: "phone_number",
223
- });
224
-
225
- userLoader.addToPrime(userEmailLoader);
226
- userLoader.addToPrime(userPhoneNumberLoader);
227
-
228
- userEmailLoader.addToPrime(userLoader);
229
- userEmailLoader.addToPrime(userPhoneNumberLoader);
230
-
231
- userPhoneNumberLoader.addToPrime(userLoader);
232
- userPhoneNumberLoader.addToPrime(userEmailLoader);
@@ -1 +0,0 @@
1
- export * from "./internal";
@@ -1,8 +0,0 @@
1
- export * from "./const";
2
- export * from "./fake_contact";
3
- export * from "./fake_user";
4
- export * from "./fake_event";
5
- export * from "./fake_tag";
6
- export * from "./events_query";
7
- export * from "./user_query";
8
- export * from "./tag_query";
@@ -1,56 +0,0 @@
1
- import { ID, Viewer } from "../../core/base";
2
- import { CustomEdgeQueryBase } from "../../core/query/custom_query";
3
- import { FakeUser, FakeTag } from "./internal";
4
-
5
- export class UserToTagsFkeyQuery extends CustomEdgeQueryBase<
6
- FakeUser,
7
- FakeTag
8
- > {
9
- constructor(viewer: Viewer, src: ID | FakeUser) {
10
- super(viewer, {
11
- src,
12
- loadEntOptions: FakeTag.loaderOptions(),
13
- groupCol: "owner_id",
14
- name: "user_to_tags",
15
- sortColumn: "canonical_name",
16
- primarySortColIsUnique: true,
17
- });
18
- }
19
-
20
- static query(viewer: Viewer, src: FakeUser | ID): UserToTagsFkeyQuery {
21
- return new UserToTagsFkeyQuery(viewer, src);
22
- }
23
-
24
- sourceEnt(id: ID) {
25
- return FakeUser.load(this.viewer, id);
26
- }
27
- }
28
-
29
- export class UserToTagsFkeyQueryAsc extends CustomEdgeQueryBase<
30
- FakeUser,
31
- FakeTag
32
- > {
33
- constructor(viewer: Viewer, src: ID | FakeUser) {
34
- super(viewer, {
35
- src,
36
- loadEntOptions: FakeTag.loaderOptions(),
37
- groupCol: "owner_id",
38
- name: "user_to_tags_asc",
39
- orderby: [
40
- {
41
- column: "canonical_name",
42
- direction: "ASC",
43
- },
44
- ],
45
- primarySortColIsUnique: true,
46
- });
47
- }
48
-
49
- static query(viewer: Viewer, src: FakeUser | ID): UserToTagsFkeyQueryAsc {
50
- return new UserToTagsFkeyQueryAsc(viewer, src);
51
- }
52
-
53
- sourceEnt(id: ID) {
54
- return FakeUser.load(this.viewer, id);
55
- }
56
- }
@@ -1,388 +0,0 @@
1
- import { advanceBy, advanceTo } from "jest-date-mock";
2
- import { IDViewer, LoggedOutViewer } from "../../core/viewer";
3
- import { Context, Data, Ent } from "../../core/base";
4
- import { AssocEdge, loadEdgeData } from "../../core/ent";
5
- import { snakeCase } from "snake-case";
6
- import { createRowForTest } from "../write";
7
- import {
8
- TempDB,
9
- assoc_edge_config_table,
10
- assoc_edge_table,
11
- } from "../db/temp_db";
12
-
13
- import {
14
- createUser,
15
- FakeUser,
16
- UserCreateInput,
17
- ContactCreateInput,
18
- FakeContact,
19
- getContactBuilder,
20
- EdgeType,
21
- SymmetricEdges,
22
- InverseEdges,
23
- FakeUserSchema,
24
- } from ".";
25
- import { EventCreateInput, FakeEvent, getEventBuilder } from "./fake_event";
26
- import { NodeType } from "./const";
27
- import { MockDate } from "./../mock_date";
28
- import { BuilderSchema, SimpleAction } from "../builder";
29
- import { WriteOperation } from "../../action";
30
- import { FakeTag } from "./fake_tag";
31
- import { Dialect } from "../../core/db";
32
-
33
- export function getContactInput(
34
- user: FakeUser,
35
- input?: Partial<ContactCreateInput>,
36
- ): ContactCreateInput {
37
- return {
38
- firstName: "Jon",
39
- lastName: "Snow",
40
- emailAddress: "foo@bar.com",
41
- userID: user.id,
42
- createdAt: new Date(),
43
- updatedAt: new Date(),
44
- ...input,
45
- };
46
- }
47
-
48
- export function getUserInput(
49
- input?: Partial<UserCreateInput>,
50
- ): UserCreateInput {
51
- return {
52
- firstName: "Jon",
53
- lastName: "Snow",
54
- emailAddress: "foo@bar.com",
55
- phoneNumber: "415-212-1212",
56
- password: "pa$$w0rd",
57
- createdAt: new Date(),
58
- updatedAt: new Date(),
59
- ...input,
60
- };
61
- }
62
-
63
- export function getEventInput(
64
- user: FakeUser,
65
- input?: Partial<EventCreateInput>,
66
- ): EventCreateInput {
67
- return {
68
- startTime: new Date(),
69
- location: "fun location",
70
- title: "title",
71
- description: "fun event",
72
- userID: user.id,
73
- createdAt: new Date(),
74
- updatedAt: new Date(),
75
- ...input,
76
- };
77
- }
78
-
79
- export async function createTestUser(
80
- input?: Partial<UserCreateInput>,
81
- ctx?: Context,
82
- ): Promise<FakeUser> {
83
- const user = await createUser(new LoggedOutViewer(ctx), {
84
- firstName: "Jon",
85
- lastName: "Snow",
86
- password: "12345678",
87
- phoneNumber: "4152221231",
88
- emailAddress: "foo@bar.com",
89
- ...input,
90
- });
91
- if (!user) {
92
- throw new Error("error creating user");
93
- }
94
- return user;
95
- }
96
-
97
- export const inputs: Partial<ContactCreateInput>[] = [
98
- {
99
- firstName: "Arya",
100
- lastName: "Stark",
101
- },
102
- {
103
- firstName: "Robb",
104
- lastName: "Stark",
105
- },
106
- {
107
- firstName: "Sansa",
108
- lastName: "Stark",
109
- },
110
- {
111
- firstName: "Rickon",
112
- lastName: "Stark",
113
- },
114
- {
115
- firstName: "Bran",
116
- lastName: "Stark",
117
- },
118
- ];
119
-
120
- interface createContactOptions {
121
- input?: Partial<UserCreateInput>;
122
- slice?: number;
123
- user?: FakeUser;
124
- start?: number;
125
- ctx?: Context;
126
- }
127
- export async function createAllContacts(
128
- opts?: createContactOptions,
129
- ): Promise<[FakeUser, FakeContact[]]> {
130
- let { input, slice, user } = opts || {};
131
- if (!user) {
132
- user = await createTestUser(input, opts?.ctx);
133
- }
134
- const userr = user!;
135
-
136
- if (opts?.start) {
137
- advanceTo(opts.start);
138
- }
139
- let userInputs = inputs.slice(0, slice || inputs.length);
140
- const contacts = await Promise.all(
141
- userInputs.map(async (input) => {
142
- // just to make times deterministic so that tests can consistently work
143
- advanceBy(100);
144
- const builder = getContactBuilder(
145
- userr.viewer,
146
- getContactInput(userr, input),
147
- );
148
- // add edge from user to contact
149
- builder.orchestrator.addInboundEdge(
150
- userr.id,
151
- EdgeType.UserToContacts,
152
- NodeType.FakeUser,
153
- {
154
- time: new Date(), // set time to advanceBy time
155
- },
156
- );
157
- await builder.saveX();
158
- return await builder.editedEntX();
159
- }),
160
- );
161
- expect(contacts.length).toBe(userInputs.length);
162
- return [userr, contacts];
163
- }
164
-
165
- export async function createUserPlusFriendRequests(
166
- input?: Partial<UserCreateInput>,
167
- slice?: number,
168
- ): Promise<[FakeUser, FakeUser[]]> {
169
- const user = await createTestUser(input);
170
-
171
- let userInputs = inputs.slice(0, slice || inputs.length);
172
-
173
- const friendRequests = await Promise.all(
174
- userInputs.map(async (input) => {
175
- return createTestUser(input);
176
- }),
177
- );
178
- expect(friendRequests.length).toBe(userInputs.length);
179
-
180
- await addEdge(
181
- user,
182
- FakeUserSchema,
183
- EdgeType.UserToFriendRequests,
184
- true,
185
- ...friendRequests,
186
- );
187
-
188
- return [user, friendRequests];
189
- }
190
-
191
- export async function addEdge<T extends Ent>(
192
- source: T,
193
- schema: BuilderSchema<T>,
194
- edgeType: string,
195
- inbound: boolean, // inbound or outbound
196
- ...dest: Ent[]
197
- ) {
198
- const action = new SimpleAction(
199
- source.viewer,
200
- schema,
201
- new Map(),
202
- WriteOperation.Edit,
203
- source,
204
- );
205
-
206
- dest.forEach(async (friendRequest) => {
207
- // just to make times deterministic so that tests can consistently work
208
- advanceBy(100);
209
- // add edge
210
- if (inbound) {
211
- action.builder.orchestrator.addInboundEdge(
212
- friendRequest.id,
213
- edgeType,
214
- dest[0].nodeType,
215
- {
216
- time: new Date(), // set time to advanceBy time
217
- },
218
- );
219
- } else {
220
- action.builder.orchestrator.addOutboundEdge(
221
- friendRequest.id,
222
- edgeType,
223
- dest[0].nodeType,
224
- {
225
- time: new Date(), // set time to advanceBy time
226
- },
227
- );
228
- }
229
- });
230
- await action.saveX();
231
- }
232
-
233
- export function verifyUserToContactEdges(
234
- user: FakeUser,
235
- edges: AssocEdge[],
236
- contacts: FakeContact[],
237
- ) {
238
- expect(edges.length).toBe(contacts.length);
239
-
240
- for (let i = 0; i < contacts.length; i++) {
241
- const edge = edges[i];
242
- const expectedEdge = {
243
- id1: user.id,
244
- id1Type: NodeType.FakeUser,
245
- id2: contacts[i].id,
246
- id2Type: NodeType.FakeContact,
247
- data: null,
248
- edgeType: EdgeType.UserToContacts,
249
- };
250
- expect(edge, `${i}th index`).toMatchObject(expectedEdge);
251
- expect(edge.getCursor()).not.toBe("");
252
- }
253
- }
254
-
255
- export function verifyUserToContactRawData(
256
- user: FakeUser,
257
- edges: Data[],
258
- contacts: FakeContact[],
259
- ) {
260
- expect(edges.length).toBe(contacts.length);
261
-
262
- for (let i = 0; i < contacts.length; i++) {
263
- const edge = edges[i];
264
- const expectedEdge = contacts[i].data;
265
- // getting data from db so just checking that data's as expected
266
-
267
- expect(edge, `${i}th index`).toMatchObject(expectedEdge);
268
- }
269
- }
270
-
271
- export function verifyUserToContacts(
272
- user: FakeUser,
273
- ents: FakeContact[],
274
- contacts: FakeContact[],
275
- ) {
276
- expect(ents.length).toBe(contacts.length);
277
- const expectedContacts = contacts.map((contact) => contact.id);
278
-
279
- expect(ents.map((contact) => contact.id)).toStrictEqual(expectedContacts);
280
- }
281
-
282
- export async function createEdges() {
283
- // create all edges// for now all one-way
284
- const edgeNames = Object.keys(EdgeType);
285
- const edges = Object.values(EdgeType);
286
-
287
- for (let i = 0; i < edges.length; i++) {
288
- const edge = edges[i];
289
- await createRowForTest({
290
- tableName: "assoc_edge_config",
291
- fields: {
292
- edge_table: snakeCase(`${edge}_table`),
293
- symmetric_edge: SymmetricEdges.has(edge),
294
- inverse_edge_type: InverseEdges.get(edge) || null,
295
- edge_type: edge,
296
- edge_name: edgeNames[i],
297
- created_at: new Date(),
298
- updated_at: new Date(),
299
- },
300
- });
301
- const edgeData = await loadEdgeData(edge);
302
- expect(edgeData).toBeDefined();
303
- }
304
- }
305
-
306
- export function edgeTableNames() {
307
- const edges = Object.values(EdgeType);
308
- return edges.map((edge) => snakeCase(`${edge}_table`));
309
- }
310
-
311
- export async function createTestEvent(
312
- user: FakeUser,
313
- input?: Partial<EventCreateInput>,
314
- ) {
315
- const vc = new IDViewer(user.id);
316
- const builder = getEventBuilder(vc, {
317
- startTime: new Date(),
318
- location: "fun house",
319
- description: "fun fun fun",
320
- title: "fun time",
321
- userID: user.id,
322
- ...input,
323
- });
324
- builder.orchestrator.addOutboundEdge(user.id, EdgeType.EventToHosts, "User");
325
-
326
- await builder.saveX();
327
- return await builder.editedEntX();
328
- }
329
-
330
- export async function setupTempDB(global: boolean = false) {
331
- const tdb = new TempDB(Dialect.Postgres, tempDBTables(global));
332
-
333
- await tdb.beforeAll();
334
-
335
- // create once
336
- await createEdges();
337
-
338
- return tdb;
339
- }
340
-
341
- export function tempDBTables(global: boolean = false) {
342
- const tables = [
343
- FakeUser.getTestTable(),
344
- FakeContact.getTestTable(),
345
- FakeEvent.getTestTable(),
346
- FakeTag.getTestTable(),
347
- assoc_edge_config_table(),
348
- ];
349
- edgeTableNames().forEach((tableName) =>
350
- tables.push(assoc_edge_table(tableName, global)),
351
- );
352
-
353
- return tables;
354
- }
355
-
356
- interface options {
357
- howMany: number;
358
- interval: number;
359
- userInput?: Partial<UserCreateInput>;
360
- eventInputs?: Partial<EventCreateInput>[];
361
- startTime?: number | Date;
362
- }
363
- export async function createAllEvents(
364
- opts: options,
365
- ): Promise<[FakeUser, FakeEvent[]]> {
366
- const user = await createTestUser(opts.userInput);
367
-
368
- let arr = new Array(opts.howMany);
369
- arr.fill(1);
370
-
371
- // start at date in case something else has used a date already
372
- advanceTo(opts.startTime || MockDate.getDate());
373
-
374
- const events = await Promise.all(
375
- arr.map(async (v, idx: number) => {
376
- // just to make times deterministic so that tests can consistently work
377
- if (opts.interval > 0) {
378
- advanceBy(opts.interval);
379
- }
380
- const input = opts.eventInputs?.[idx];
381
- const builder = getEventBuilder(user.viewer, getEventInput(user, input));
382
- await builder.saveX();
383
- return builder.editedEntX();
384
- }),
385
- );
386
- expect(events.length).toBe(opts.howMany);
387
- return [user, events];
388
- }