@snowtop/ent 0.1.0-alpha160-test6 → 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 +6 -48
  8. package/{dist/scripts → scripts}/custom_compiler.js +0 -0
  9. package/{dist/scripts → scripts}/custom_graphql.js +0 -0
  10. package/dist/package.json +0 -64
  11. package/src/action/action.ts +0 -330
  12. package/src/action/executor.ts +0 -453
  13. package/src/action/experimental_action.ts +0 -277
  14. package/src/action/index.ts +0 -31
  15. package/src/action/operations.ts +0 -967
  16. package/src/action/orchestrator.ts +0 -1527
  17. package/src/action/privacy.ts +0 -37
  18. package/src/action/relative_value.ts +0 -242
  19. package/src/action/transaction.ts +0 -38
  20. package/src/auth/auth.ts +0 -77
  21. package/src/auth/index.ts +0 -8
  22. package/src/core/base.ts +0 -367
  23. package/src/core/clause.ts +0 -1065
  24. package/src/core/config.ts +0 -219
  25. package/src/core/const.ts +0 -5
  26. package/src/core/context.ts +0 -135
  27. package/src/core/convert.ts +0 -106
  28. package/src/core/date.ts +0 -23
  29. package/src/core/db.ts +0 -498
  30. package/src/core/ent.ts +0 -1740
  31. package/src/core/global_schema.ts +0 -49
  32. package/src/core/loaders/assoc_count_loader.ts +0 -99
  33. package/src/core/loaders/assoc_edge_loader.ts +0 -250
  34. package/src/core/loaders/index.ts +0 -12
  35. package/src/core/loaders/loader.ts +0 -66
  36. package/src/core/loaders/object_loader.ts +0 -489
  37. package/src/core/loaders/query_loader.ts +0 -314
  38. package/src/core/loaders/raw_count_loader.ts +0 -175
  39. package/src/core/logger.ts +0 -49
  40. package/src/core/privacy.ts +0 -660
  41. package/src/core/query/assoc_query.ts +0 -240
  42. package/src/core/query/custom_clause_query.ts +0 -174
  43. package/src/core/query/custom_query.ts +0 -302
  44. package/src/core/query/index.ts +0 -9
  45. package/src/core/query/query.ts +0 -674
  46. package/src/core/query_impl.ts +0 -32
  47. package/src/core/viewer.ts +0 -52
  48. package/src/ent.code-workspace +0 -73
  49. package/src/graphql/builtins/connection.ts +0 -25
  50. package/src/graphql/builtins/edge.ts +0 -16
  51. package/src/graphql/builtins/node.ts +0 -12
  52. package/src/graphql/graphql.ts +0 -891
  53. package/src/graphql/graphql_field_helpers.ts +0 -221
  54. package/src/graphql/index.ts +0 -42
  55. package/src/graphql/mutations/union.ts +0 -39
  56. package/src/graphql/node_resolver.ts +0 -122
  57. package/src/graphql/query/connection_type.ts +0 -113
  58. package/src/graphql/query/edge_connection.ts +0 -171
  59. package/src/graphql/query/page_info.ts +0 -34
  60. package/src/graphql/query/shared_edge_connection.ts +0 -287
  61. package/src/graphql/scalars/orderby_direction.ts +0 -13
  62. package/src/graphql/scalars/time.ts +0 -38
  63. package/src/imports/dataz/example1/_auth.ts +0 -51
  64. package/src/imports/dataz/example1/_viewer.ts +0 -35
  65. package/src/imports/index.ts +0 -213
  66. package/src/index.ts +0 -145
  67. package/src/parse_schema/parse.ts +0 -585
  68. package/src/schema/base_schema.ts +0 -224
  69. package/src/schema/field.ts +0 -1087
  70. package/src/schema/index.ts +0 -53
  71. package/src/schema/json_field.ts +0 -94
  72. package/src/schema/schema.ts +0 -1028
  73. package/src/schema/struct_field.ts +0 -234
  74. package/src/schema/union_field.ts +0 -105
  75. package/src/scripts/custom_compiler.ts +0 -331
  76. package/src/scripts/custom_graphql.ts +0 -550
  77. package/src/scripts/migrate_v0.1.ts +0 -41
  78. package/src/scripts/move_types.ts +0 -131
  79. package/src/scripts/read_schema.ts +0 -67
  80. package/src/setupPackage.js +0 -42
  81. package/src/testutils/action/complex_schemas.ts +0 -517
  82. package/src/testutils/builder.ts +0 -422
  83. package/src/testutils/context/test_context.ts +0 -25
  84. package/src/testutils/db/fixture.ts +0 -32
  85. package/src/testutils/db/temp_db.ts +0 -941
  86. package/src/testutils/db/value.ts +0 -294
  87. package/src/testutils/db_mock.ts +0 -351
  88. package/src/testutils/db_time_zone.ts +0 -40
  89. package/src/testutils/ent-graphql-tests/index.ts +0 -653
  90. package/src/testutils/fake_comms.ts +0 -50
  91. package/src/testutils/fake_data/const.ts +0 -64
  92. package/src/testutils/fake_data/events_query.ts +0 -145
  93. package/src/testutils/fake_data/fake_contact.ts +0 -150
  94. package/src/testutils/fake_data/fake_event.ts +0 -150
  95. package/src/testutils/fake_data/fake_tag.ts +0 -139
  96. package/src/testutils/fake_data/fake_user.ts +0 -232
  97. package/src/testutils/fake_data/index.ts +0 -1
  98. package/src/testutils/fake_data/internal.ts +0 -8
  99. package/src/testutils/fake_data/tag_query.ts +0 -56
  100. package/src/testutils/fake_data/test_helpers.ts +0 -388
  101. package/src/testutils/fake_data/user_query.ts +0 -524
  102. package/src/testutils/fake_log.ts +0 -52
  103. package/src/testutils/mock_date.ts +0 -10
  104. package/src/testutils/mock_log.ts +0 -39
  105. package/src/testutils/parse_sql.ts +0 -685
  106. package/src/testutils/test_edge_global_schema.ts +0 -49
  107. package/src/testutils/write.ts +0 -70
  108. package/src/tsc/ast.ts +0 -351
  109. package/src/tsc/compilerOptions.ts +0 -85
  110. package/src/tsc/move_generated.ts +0 -191
  111. package/src/tsc/transform.ts +0 -226
  112. package/src/tsc/transform_action.ts +0 -224
  113. package/src/tsc/transform_ent.ts +0 -66
  114. package/src/tsc/transform_schema.ts +0 -546
  115. package/tsconfig.json +0 -20
  116. /package/{dist/action → action}/action.d.ts +0 -0
  117. /package/{dist/action → action}/action.js +0 -0
  118. /package/{dist/action → action}/executor.d.ts +0 -0
  119. /package/{dist/action → action}/executor.js +0 -0
  120. /package/{dist/action → action}/experimental_action.d.ts +0 -0
  121. /package/{dist/action → action}/experimental_action.js +0 -0
  122. /package/{dist/action → action}/index.d.ts +0 -0
  123. /package/{dist/action → action}/index.js +0 -0
  124. /package/{dist/action → action}/operations.d.ts +0 -0
  125. /package/{dist/action → action}/operations.js +0 -0
  126. /package/{dist/action → action}/orchestrator.d.ts +0 -0
  127. /package/{dist/action → action}/orchestrator.js +0 -0
  128. /package/{dist/action → action}/privacy.d.ts +0 -0
  129. /package/{dist/action → action}/privacy.js +0 -0
  130. /package/{dist/action → action}/relative_value.d.ts +0 -0
  131. /package/{dist/action → action}/relative_value.js +0 -0
  132. /package/{dist/action → action}/transaction.d.ts +0 -0
  133. /package/{dist/action → action}/transaction.js +0 -0
  134. /package/{dist/auth → auth}/auth.d.ts +0 -0
  135. /package/{dist/auth → auth}/auth.js +0 -0
  136. /package/{dist/auth → auth}/index.d.ts +0 -0
  137. /package/{dist/auth → auth}/index.js +0 -0
  138. /package/{dist/core → core}/base.d.ts +0 -0
  139. /package/{dist/core → core}/base.js +0 -0
  140. /package/{dist/core → core}/clause.d.ts +0 -0
  141. /package/{dist/core → core}/clause.js +0 -0
  142. /package/{dist/core → core}/config.d.ts +0 -0
  143. /package/{dist/core → core}/config.js +0 -0
  144. /package/{dist/core → core}/const.d.ts +0 -0
  145. /package/{dist/core → core}/const.js +0 -0
  146. /package/{dist/core → core}/context.d.ts +0 -0
  147. /package/{dist/core → core}/context.js +0 -0
  148. /package/{dist/core → core}/convert.d.ts +0 -0
  149. /package/{dist/core → core}/convert.js +0 -0
  150. /package/{dist/core → core}/date.d.ts +0 -0
  151. /package/{dist/core → core}/date.js +0 -0
  152. /package/{dist/core → core}/db.d.ts +0 -0
  153. /package/{dist/core → core}/db.js +0 -0
  154. /package/{dist/core → core}/ent.d.ts +0 -0
  155. /package/{dist/core → core}/ent.js +0 -0
  156. /package/{dist/core → core}/global_schema.d.ts +0 -0
  157. /package/{dist/core → core}/global_schema.js +0 -0
  158. /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
  159. /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
  160. /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
  161. /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
  162. /package/{dist/core → core}/loaders/index.d.ts +0 -0
  163. /package/{dist/core → core}/loaders/index.js +0 -0
  164. /package/{dist/core → core}/loaders/loader.d.ts +0 -0
  165. /package/{dist/core → core}/loaders/loader.js +0 -0
  166. /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
  167. /package/{dist/core → core}/loaders/object_loader.js +0 -0
  168. /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
  169. /package/{dist/core → core}/loaders/query_loader.js +0 -0
  170. /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
  171. /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
  172. /package/{dist/core → core}/logger.d.ts +0 -0
  173. /package/{dist/core → core}/logger.js +0 -0
  174. /package/{dist/core → core}/privacy.d.ts +0 -0
  175. /package/{dist/core → core}/privacy.js +0 -0
  176. /package/{dist/core → core}/query/assoc_query.d.ts +0 -0
  177. /package/{dist/core → core}/query/assoc_query.js +0 -0
  178. /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
  179. /package/{dist/core → core}/query/custom_clause_query.js +0 -0
  180. /package/{dist/core → core}/query/custom_query.d.ts +0 -0
  181. /package/{dist/core → core}/query/custom_query.js +0 -0
  182. /package/{dist/core → core}/query/index.d.ts +0 -0
  183. /package/{dist/core → core}/query/index.js +0 -0
  184. /package/{dist/core → core}/query/query.d.ts +0 -0
  185. /package/{dist/core → core}/query/query.js +0 -0
  186. /package/{dist/core → core}/query_impl.d.ts +0 -0
  187. /package/{dist/core → core}/query_impl.js +0 -0
  188. /package/{dist/core → core}/viewer.d.ts +0 -0
  189. /package/{dist/core → core}/viewer.js +0 -0
  190. /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
  191. /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
  192. /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
  193. /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
  194. /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
  195. /package/{dist/graphql → graphql}/builtins/node.js +0 -0
  196. /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
  197. /package/{dist/graphql → graphql}/graphql.js +0 -0
  198. /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
  199. /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
  200. /package/{dist/graphql → graphql}/index.d.ts +0 -0
  201. /package/{dist/graphql → graphql}/index.js +0 -0
  202. /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
  203. /package/{dist/graphql → graphql}/mutations/union.js +0 -0
  204. /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
  205. /package/{dist/graphql → graphql}/node_resolver.js +0 -0
  206. /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
  207. /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
  208. /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
  209. /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
  210. /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
  211. /package/{dist/graphql → graphql}/query/page_info.js +0 -0
  212. /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
  213. /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
  214. /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
  215. /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
  216. /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
  217. /package/{dist/graphql → graphql}/scalars/time.js +0 -0
  218. /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
  219. /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
  220. /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
  221. /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
  222. /package/{dist/imports → imports}/index.d.ts +0 -0
  223. /package/{dist/imports → imports}/index.js +0 -0
  224. /package/{dist/index.d.ts → index.d.ts} +0 -0
  225. /package/{dist/index.js → index.js} +0 -0
  226. /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
  227. /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
  228. /package/{dist/schema → schema}/base_schema.d.ts +0 -0
  229. /package/{dist/schema → schema}/base_schema.js +0 -0
  230. /package/{dist/schema → schema}/field.d.ts +0 -0
  231. /package/{dist/schema → schema}/field.js +0 -0
  232. /package/{dist/schema → schema}/index.d.ts +0 -0
  233. /package/{dist/schema → schema}/index.js +0 -0
  234. /package/{dist/schema → schema}/json_field.d.ts +0 -0
  235. /package/{dist/schema → schema}/json_field.js +0 -0
  236. /package/{dist/schema → schema}/schema.d.ts +0 -0
  237. /package/{dist/schema → schema}/schema.js +0 -0
  238. /package/{dist/schema → schema}/struct_field.d.ts +0 -0
  239. /package/{dist/schema → schema}/struct_field.js +0 -0
  240. /package/{dist/schema → schema}/union_field.d.ts +0 -0
  241. /package/{dist/schema → schema}/union_field.js +0 -0
  242. /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
  243. /package/{dist/scripts → scripts}/custom_graphql.d.ts +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,67 +0,0 @@
1
- import * as glob from "glob";
2
- import * as path from "path";
3
- import { pascalCase } from "pascal-case";
4
- import minimist from "minimist";
5
- import { parseSchema } from "../parse_schema/parse";
6
- import { getCustomInfo } from "../tsc/ast";
7
- import { GlobalSchema } from "../schema/schema";
8
-
9
- function main() {
10
- const options = minimist(process.argv.slice(2));
11
-
12
- if (!options.path) {
13
- throw new Error("path required");
14
- }
15
-
16
- const customInfo = getCustomInfo();
17
- const globalSchemaPath = customInfo.globalSchemaPath || "__global__schema.ts";
18
-
19
- let globalSchema: GlobalSchema | undefined;
20
- const r = /(\w+).ts/;
21
- // do we still even need this...
22
- const paths = glob.sync(path.join(options.path, "*.ts"), {
23
- ignore: [`\d+_read_schema.ts`],
24
- });
25
- let potentialSchemas = {};
26
- for (const p of paths) {
27
- const basename = path.basename(p);
28
- if (basename === globalSchemaPath) {
29
- globalSchema = require(p).default;
30
- continue;
31
- }
32
-
33
- const match = r.exec(basename);
34
- if (!match) {
35
- throw new Error(`non-typescript file ${p} returned by glob`);
36
- }
37
- let schema = match[1];
38
- // convert foo_schema.ts -> foo
39
- if (schema.endsWith("_schema")) {
40
- schema = schema.slice(0, -7);
41
- }
42
- let relativePath: string | undefined;
43
- const index = p.indexOf("src/schema");
44
- if (index !== -1) {
45
- relativePath = p.substring(index);
46
- }
47
- const s = require(p).default;
48
- if (relativePath !== undefined) {
49
- s.schemaPath = relativePath;
50
- }
51
- potentialSchemas[pascalCase(schema)] = s;
52
- }
53
- // console.log(potentialSchemas);
54
-
55
- // NB: do not change this to async/await
56
- // doing so runs it buffer limit on linux (65536 bytes) and we lose data reading in go
57
- parseSchema(potentialSchemas, globalSchema).then((result) => {
58
- console.log(JSON.stringify(result));
59
- });
60
- }
61
-
62
- try {
63
- main();
64
- } catch (err) {
65
- console.error(err);
66
- process.exit(1);
67
- }
@@ -1,42 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const minimist = require("minimist");
4
-
5
- // root is "ts/"
6
- const root = path.resolve();
7
-
8
- // DO NOT DELETE THIS FILE
9
- // This file is used by build system to build a clean npm package with the compiled js files in the root of the package.
10
- // It will not be included in the npm package.
11
- // gotten from https://stackoverflow.com/questions/38935176/how-to-npm-publish-specific-folder-but-as-package-root
12
- function main() {
13
- const options = minimist(process.argv.slice(2));
14
-
15
- const source = fs
16
- .readFileSync(path.join(root, "package.json"))
17
- .toString("utf-8");
18
- const sourceObj = JSON.parse(source);
19
-
20
- if (options.legacy) {
21
- sourceObj.name = "@lolopinto/ent";
22
- // TODO this needs to be updated here everytime we wanna update legacy version...
23
- // the legacy path is difficult because of tsent though...
24
- sourceObj.version = "0.0.100";
25
- }
26
- sourceObj.scripts = {};
27
- sourceObj.devDependencies = {};
28
- if (sourceObj.main.startsWith("dist/")) {
29
- sourceObj.main = sourceObj.main.slice(5);
30
- }
31
- fs.writeFileSync(
32
- path.join(root, "dist", "/package.json"),
33
- Buffer.from(JSON.stringify(sourceObj, null, 2), "utf-8"),
34
- );
35
-
36
- fs.copyFileSync(
37
- path.join(root, ".npmignore"),
38
- path.join(root, "dist", ".npmignore"),
39
- );
40
- }
41
-
42
- main();
@@ -1,517 +0,0 @@
1
- import { Ent, ID, Viewer, Data } from "../../core/base";
2
- import { loadEdges, loadEnts } from "../../core/ent";
3
- import { DataOperation } from "../../action/operations";
4
- import { ObjectLoaderFactory } from "../../core/loaders/object_loader";
5
- import {
6
- Action,
7
- Builder,
8
- Changeset,
9
- Executor,
10
- WriteOperation,
11
- Trigger,
12
- Observer,
13
- TriggerReturn,
14
- } from "../../action/action";
15
- import { executeOperations } from "../../action/executor";
16
- import { EdgeInputData } from "../../action/orchestrator";
17
- import {
18
- User,
19
- Group,
20
- Message,
21
- Contact,
22
- SimpleBuilder,
23
- BuilderSchema,
24
- SimpleAction,
25
- getTableName,
26
- getBuilderSchemaFromFields,
27
- BaseEnt,
28
- } from "../../testutils/builder";
29
- import { LoggedOutViewer, IDViewer } from "../../core/viewer";
30
- import {
31
- StringType,
32
- TimestampType,
33
- BooleanType,
34
- UUIDType,
35
- FloatType,
36
- } from "../../schema/field";
37
- import { JSONBType } from "../../schema/json_field";
38
- import { FakeLogger, EntCreationObserver } from "../../testutils/fake_log";
39
- import { createRowForTest } from "../../testutils/write";
40
- import { AlwaysAllowPrivacyPolicy } from "../../core/privacy";
41
- import { MockLogs } from "../../testutils/mock_log";
42
- import { setLogLevels } from "../../core/logger";
43
- import * as action from "../../action";
44
- import { convertJSON } from "../../core/convert";
45
- import { v4 } from "uuid";
46
- import {
47
- assoc_edge_config_table,
48
- assoc_edge_table,
49
- getSchemaTable,
50
- Table,
51
- } from "../db/temp_db";
52
- import { Dialect } from "../../core/db";
53
- import { ConstraintType } from "../../schema";
54
-
55
- const ml = new MockLogs();
56
- let operations: DataOperation[] = [];
57
-
58
- const edges = [
59
- "fake_edge",
60
- "selfContact",
61
- "channelMember",
62
- "senderToMessage",
63
- "workspaceMember",
64
- "recipientToMessage",
65
- "objectToChangelog",
66
- "changelogToParent",
67
- ];
68
-
69
- export function setupTest() {
70
- beforeEach(async () => {
71
- // does assoc_edge_config loader need to be cleared?
72
- for (const edge of edges) {
73
- await createRowForTest({
74
- tableName: "assoc_edge_config",
75
- fields: {
76
- edge_table: `${edge}_table`,
77
- symmetric_edge: false,
78
- inverse_edge_type: null,
79
- edge_type: edge,
80
- edge_name: "name",
81
- created_at: new Date(),
82
- updated_at: new Date(),
83
- },
84
- });
85
- }
86
- ml.clear();
87
- });
88
-
89
- beforeAll(() => {
90
- setLogLevels(["query", "error", "cache"]);
91
- ml.mock();
92
- });
93
-
94
- afterEach(() => {
95
- ml.clear();
96
- });
97
-
98
- afterAll(() => {
99
- ml.restore();
100
- });
101
-
102
- afterEach(() => {
103
- FakeLogger.clear();
104
- operations = [];
105
- });
106
- }
107
-
108
- export function getML() {
109
- return ml;
110
- }
111
-
112
- export function getOperations() {
113
- return operations;
114
- }
115
-
116
- export const UserSchema = getBuilderSchemaFromFields(
117
- {
118
- FirstName: StringType(),
119
- LastName: StringType(),
120
- EmailAddress: StringType({ nullable: true }),
121
- AccountID: UUIDType({ nullable: true }),
122
- },
123
- User,
124
- );
125
-
126
- export class UserWithBalance extends User {}
127
-
128
- export const UserBalanceSchema = getBuilderSchemaFromFields(
129
- {
130
- first_name: StringType(),
131
- last_name: StringType(),
132
- email_address: StringType({ nullable: true }),
133
- balance: FloatType(),
134
- },
135
- UserWithBalance,
136
- );
137
-
138
- export class UserWithBalanceWithCheck extends UserWithBalance {}
139
-
140
- export const UserBalanceWithCheckSchema = getBuilderSchemaFromFields(
141
- {
142
- first_name: StringType(),
143
- last_name: StringType(),
144
- email_address: StringType({ nullable: true }),
145
- balance: FloatType(),
146
- },
147
- UserWithBalanceWithCheck,
148
- {
149
- constraints: [
150
- {
151
- type: ConstraintType.Check,
152
- name: "positive_balance",
153
- columns: ["balance"],
154
- condition: "balance >= 0",
155
- },
156
- ],
157
- },
158
- );
159
-
160
- export class Account extends BaseEnt {
161
- accountID: string = "";
162
- nodeType = "Account";
163
- }
164
-
165
- export const AccountSchema = getBuilderSchemaFromFields({}, Account);
166
-
167
- export const ContactSchema = getBuilderSchemaFromFields(
168
- {
169
- FirstName: StringType(),
170
- LastName: StringType(),
171
- UserID: StringType(),
172
- },
173
- Contact,
174
- );
175
-
176
- export const GroupSchema = getBuilderSchemaFromFields(
177
- {
178
- name: StringType(),
179
- funField: StringType({ nullable: true }),
180
- },
181
- Group,
182
- );
183
-
184
- export class GroupMembership extends BaseEnt {
185
- nodeType = "GroupMembership";
186
- }
187
-
188
- export const GroupMembershipSchema = getBuilderSchemaFromFields(
189
- {
190
- ownerID: UUIDType(),
191
- addedBy: UUIDType(),
192
- notificationsEnabled: BooleanType(),
193
- },
194
- GroupMembership,
195
- );
196
-
197
- export class Changelog extends BaseEnt {
198
- nodeType = "Changelog";
199
- }
200
-
201
- export const ChangelogSchema = getBuilderSchemaFromFields(
202
- {
203
- parentID: UUIDType({ polymorphic: true }),
204
- log: JSONBType(),
205
- },
206
- Changelog,
207
- );
208
-
209
- export const MessageSchema = getBuilderSchemaFromFields(
210
- {
211
- // TODO both id fields
212
- sender: StringType({
213
- index: true,
214
- }), // can't use from
215
- recipient: StringType(), // can't use to in sqlite
216
- message: StringType(),
217
- transient: BooleanType({ nullable: true }),
218
- expiresAt: TimestampType({ nullable: true }),
219
- delivered: BooleanType({ defaultValueOnCreate: () => false }),
220
- },
221
- Message,
222
- );
223
-
224
- jest.spyOn(action, "saveBuilder").mockImplementation(saveBuilder);
225
- jest.spyOn(action, "saveBuilderX").mockImplementation(saveBuilderX);
226
-
227
- async function saveBuilder<T extends Ent>(builder: Builder<T>): Promise<void> {
228
- const changeset = await builder.build();
229
- const executor = changeset.executor();
230
- operations = await executeOperations(executor, builder.viewer.context, true);
231
- }
232
-
233
- async function saveBuilderX<T extends Ent>(builder: Builder<T>): Promise<void> {
234
- return saveBuilder(builder);
235
- }
236
-
237
- export async function executeAction<T extends Ent, E = any>(
238
- action: Action<T, Builder<T>>,
239
- name?: E,
240
- ): Promise<Executor> {
241
- const exec = await executor(action.builder);
242
- if (name !== undefined) {
243
- expect(exec).toBeInstanceOf(name);
244
- }
245
- operations = await executeOperations(
246
- exec,
247
- action.builder.viewer.context,
248
- true,
249
- );
250
- return exec;
251
- }
252
-
253
- async function executor<T extends Ent>(builder: Builder<T>): Promise<Executor> {
254
- const changeset = await builder.build();
255
- return changeset.executor();
256
- }
257
-
258
- export async function createGroup() {
259
- let groupID = v4();
260
- let groupFields = {
261
- id: groupID,
262
- name: "group",
263
- created_at: new Date(),
264
- updated_at: new Date(),
265
- };
266
- // need to create the group first
267
- await createRowForTest({
268
- tableName: "groups",
269
- fields: groupFields,
270
- });
271
- return new Group(new LoggedOutViewer(), groupFields);
272
- }
273
-
274
- export async function createUser(): Promise<User> {
275
- const id = v4();
276
- return new User(new IDViewer(id), { id });
277
- }
278
-
279
- export class MessageAction extends SimpleAction<Message> {
280
- constructor(
281
- viewer: Viewer,
282
- fields: Map<string, any>,
283
- operation: WriteOperation,
284
- existingEnt: Message | null,
285
- ) {
286
- super(viewer, MessageSchema, fields, operation, existingEnt);
287
- }
288
-
289
- getTriggers(): Trigger<Message, SimpleBuilder<Message, Message | null>>[] {
290
- return [
291
- {
292
- changeset: (builder, _input): void => {
293
- let sender = builder.fields.get("sender");
294
- let recipient = builder.fields.get("recipient");
295
- if (sender) {
296
- builder.orchestrator.addInboundEdge(
297
- sender,
298
- "senderToMessage",
299
- "user",
300
- );
301
- }
302
- if (recipient) {
303
- builder.orchestrator.addInboundEdge(
304
- recipient,
305
- "recipientToMessage",
306
- "user",
307
- );
308
- }
309
- },
310
- },
311
- ];
312
- }
313
-
314
- getObservers(): Observer<Message, SimpleBuilder<Message>>[] {
315
- return [new EntCreationObserver<Message>()];
316
- }
317
- }
318
-
319
- export class UserAction extends SimpleAction<User> {
320
- contactAction: SimpleAction<Contact> | undefined;
321
-
322
- constructor(
323
- viewer: Viewer,
324
- fields: Map<string, any>,
325
- operation: WriteOperation,
326
- existingEnt: User | null,
327
- ) {
328
- super(viewer, UserSchema, fields, operation, existingEnt);
329
- }
330
-
331
- getTriggers(): Trigger<User, SimpleBuilder<User>>[] {
332
- return [
333
- {
334
- changeset: (builder): Promise<Changeset> => {
335
- let firstName = builder.fields.get("FirstName");
336
- let lastName = builder.fields.get("LastName");
337
- this.contactAction = new SimpleAction(
338
- builder.viewer,
339
- ContactSchema,
340
- new Map([
341
- ["FirstName", firstName],
342
- ["LastName", lastName],
343
- ["UserID", builder],
344
- ]),
345
- WriteOperation.Insert,
346
- null,
347
- );
348
-
349
- this.contactAction.getObservers = () => [
350
- new EntCreationObserver<Contact>(),
351
- ];
352
-
353
- builder.orchestrator.addOutboundEdge(
354
- this.contactAction.builder,
355
- "selfContact",
356
- "contact",
357
- );
358
- return this.contactAction.changeset();
359
- },
360
- },
361
- ];
362
- }
363
-
364
- getObservers(): Observer<User, SimpleBuilder<User>>[] {
365
- return [new EntCreationObserver<User>()];
366
- }
367
- }
368
-
369
- type getMembershipFunction = (
370
- viewer: Viewer,
371
- edge: EdgeInputData,
372
- ) => SimpleAction<Ent>;
373
-
374
- export class GroupMembershipTrigger
375
- implements Trigger<Group, SimpleBuilder<Group>>
376
- {
377
- constructor(private getter: getMembershipFunction) {}
378
- changeset(builder: SimpleBuilder<Group>, input: Data): TriggerReturn {
379
- const inputEdges = builder.orchestrator.getInputEdges(
380
- "workspaceMember",
381
- WriteOperation.Insert,
382
- );
383
- const changesets: TriggerReturn = [];
384
- for (const edge of inputEdges) {
385
- // we're going to simplify and assume it doesn't currently exist
386
- const memberAction = this.getter(builder.viewer, edge);
387
- // store the membership edge in data field of member edge
388
- builder.orchestrator.addOutboundEdge(edge.id, "workspaceMember", "User", {
389
- data: memberAction.builder,
390
- });
391
- changesets.push(memberAction.changeset());
392
- }
393
- return Promise.all(changesets);
394
- }
395
- }
396
-
397
- export class EditGroupAction extends SimpleAction<Group> {
398
- constructor(
399
- public viewer: Viewer,
400
- schema: BuilderSchema<Group>,
401
- fields: Map<string, any>,
402
- existingEnt: Group,
403
- private getter: getMembershipFunction,
404
- ) {
405
- super(viewer, schema, fields, WriteOperation.Edit, existingEnt);
406
- }
407
- getTriggers = () => [new GroupMembershipTrigger(this.getter)];
408
- }
409
-
410
- export async function verifyGroupMembers(group: Group, members: User[]) {
411
- const memberEdges = await loadEdges({
412
- edgeType: "workspaceMember",
413
- id1: group.id,
414
- });
415
- const memberIDs = members.map((ent) => ent.id);
416
- expect(memberIDs.sort()).toEqual(memberEdges.map((edge) => edge.id2).sort());
417
- // @ts-ignore
418
- const membershipids: ID[] = memberEdges
419
- .map((edge) => edge.data)
420
- .filter((str) => str !== null && str !== undefined);
421
- return membershipids;
422
- }
423
-
424
- export async function loadMemberships(viewer: Viewer, membershipids: ID[]) {
425
- const tableName = getTableName(GroupMembershipSchema);
426
- const ents = await loadEnts(
427
- viewer,
428
- {
429
- tableName,
430
- ent: GroupMembership,
431
- fields: ["id", "owner_id", "added_by", "notifications_enabled"],
432
- loaderFactory: new ObjectLoaderFactory({
433
- tableName,
434
- fields: ["id", "owner_id", "added_by", "notifications_enabled"],
435
- key: "id",
436
- }),
437
- },
438
- ...membershipids,
439
- );
440
- return Array.from(ents.values());
441
- }
442
-
443
- export async function loadChangelogs(viewer: Viewer, clids: ID[]) {
444
- const ents = await loadEnts(
445
- viewer,
446
- {
447
- tableName: "changelogs",
448
- ent: Changelog,
449
- fields: ["id", "parent_id", "log"],
450
- loaderFactory: new ObjectLoaderFactory({
451
- tableName: "changelogs",
452
- fields: ["id", "parent_id", "log"],
453
- key: "id",
454
- }),
455
- },
456
- ...clids,
457
- );
458
- return Array.from(ents.values());
459
- }
460
-
461
- export async function verifyChangelogFromMeberships(
462
- user: User,
463
- memberships: GroupMembership[],
464
- ) {
465
- await Promise.all(
466
- memberships.map(async (membership) => {
467
- const edges = await loadEdges({
468
- edgeType: "objectToChangelog",
469
- id1: membership.id,
470
- });
471
- expect(edges.length).toBe(1);
472
- const clIDs = edges.map((edge) => edge.id2);
473
- const cls = await loadChangelogs(user.viewer, clIDs);
474
- expect(cls.length).toBe(1);
475
- const cl: Changelog = cls[0];
476
- expect(edges[0].id2).toBe(cl.id);
477
- expect(convertJSON(cl.data.log)).toMatchObject({
478
- // also has ownerID...
479
- addedBy: user.id,
480
- notificationsEnabled: true,
481
- });
482
- }),
483
- );
484
- }
485
-
486
- export class GroupMemberOf extends BaseEnt {
487
- nodeType = "GroupMemberOf";
488
- }
489
-
490
- export const GroupMemberOfSchema = getBuilderSchemaFromFields(
491
- {
492
- userID: UUIDType({ index: true }),
493
- addedBy: UUIDType(),
494
- groupID: UUIDType(),
495
- notificationsEnabled: BooleanType(),
496
- },
497
- GroupMemberOf,
498
- );
499
-
500
- export const getTables = () => {
501
- const tables: Table[] = [assoc_edge_config_table()];
502
- edges.map((edge) => tables.push(assoc_edge_table(`${edge}_table`)));
503
-
504
- [
505
- AccountSchema,
506
- ContactSchema,
507
- GroupSchema,
508
- UserSchema,
509
- MessageSchema,
510
- GroupMembershipSchema,
511
- ChangelogSchema,
512
- GroupMemberOfSchema,
513
- UserBalanceSchema,
514
- UserBalanceWithCheckSchema,
515
- ].map((s) => tables.push(getSchemaTable(s, Dialect.SQLite)));
516
- return tables;
517
- };