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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/core/query/shared_assoc_test.d.ts +2 -0
  2. package/core/query/shared_assoc_test.js +804 -0
  3. package/core/query/shared_test.d.ts +21 -0
  4. package/core/query/shared_test.js +736 -0
  5. package/graphql/query/shared_assoc_test.d.ts +1 -0
  6. package/graphql/query/shared_assoc_test.js +203 -0
  7. package/package.json +8 -53
  8. package/dist/package.json +0 -64
  9. package/src/action/action.ts +0 -330
  10. package/src/action/executor.ts +0 -453
  11. package/src/action/experimental_action.ts +0 -277
  12. package/src/action/index.ts +0 -31
  13. package/src/action/operations.ts +0 -967
  14. package/src/action/orchestrator.ts +0 -1527
  15. package/src/action/privacy.ts +0 -37
  16. package/src/action/relative_value.ts +0 -242
  17. package/src/action/transaction.ts +0 -38
  18. package/src/auth/auth.ts +0 -77
  19. package/src/auth/index.ts +0 -8
  20. package/src/core/base.ts +0 -367
  21. package/src/core/clause.ts +0 -1065
  22. package/src/core/config.ts +0 -219
  23. package/src/core/const.ts +0 -5
  24. package/src/core/context.ts +0 -135
  25. package/src/core/convert.ts +0 -106
  26. package/src/core/date.ts +0 -23
  27. package/src/core/db.ts +0 -498
  28. package/src/core/ent.ts +0 -1740
  29. package/src/core/global_schema.ts +0 -49
  30. package/src/core/loaders/assoc_count_loader.ts +0 -99
  31. package/src/core/loaders/assoc_edge_loader.ts +0 -250
  32. package/src/core/loaders/index.ts +0 -12
  33. package/src/core/loaders/loader.ts +0 -66
  34. package/src/core/loaders/object_loader.ts +0 -489
  35. package/src/core/loaders/query_loader.ts +0 -314
  36. package/src/core/loaders/raw_count_loader.ts +0 -175
  37. package/src/core/logger.ts +0 -49
  38. package/src/core/privacy.ts +0 -660
  39. package/src/core/query/assoc_query.ts +0 -240
  40. package/src/core/query/custom_clause_query.ts +0 -174
  41. package/src/core/query/custom_query.ts +0 -302
  42. package/src/core/query/index.ts +0 -9
  43. package/src/core/query/query.ts +0 -674
  44. package/src/core/query_impl.ts +0 -32
  45. package/src/core/viewer.ts +0 -52
  46. package/src/ent.code-workspace +0 -73
  47. package/src/graphql/builtins/connection.ts +0 -25
  48. package/src/graphql/builtins/edge.ts +0 -16
  49. package/src/graphql/builtins/node.ts +0 -12
  50. package/src/graphql/graphql.ts +0 -891
  51. package/src/graphql/graphql_field_helpers.ts +0 -221
  52. package/src/graphql/index.ts +0 -42
  53. package/src/graphql/mutations/union.ts +0 -39
  54. package/src/graphql/node_resolver.ts +0 -122
  55. package/src/graphql/query/connection_type.ts +0 -113
  56. package/src/graphql/query/edge_connection.ts +0 -171
  57. package/src/graphql/query/page_info.ts +0 -34
  58. package/src/graphql/query/shared_edge_connection.ts +0 -287
  59. package/src/graphql/scalars/orderby_direction.ts +0 -13
  60. package/src/graphql/scalars/time.ts +0 -38
  61. package/src/imports/dataz/example1/_auth.ts +0 -51
  62. package/src/imports/dataz/example1/_viewer.ts +0 -35
  63. package/src/imports/index.ts +0 -213
  64. package/src/index.ts +0 -145
  65. package/src/parse_schema/parse.ts +0 -585
  66. package/src/schema/base_schema.ts +0 -224
  67. package/src/schema/field.ts +0 -1087
  68. package/src/schema/index.ts +0 -53
  69. package/src/schema/json_field.ts +0 -94
  70. package/src/schema/schema.ts +0 -1028
  71. package/src/schema/struct_field.ts +0 -234
  72. package/src/schema/union_field.ts +0 -105
  73. package/src/scripts/custom_compiler.ts +0 -331
  74. package/src/scripts/custom_graphql.ts +0 -550
  75. package/src/scripts/migrate_v0.1.ts +0 -41
  76. package/src/scripts/move_types.ts +0 -131
  77. package/src/scripts/read_schema.ts +0 -67
  78. package/src/setupPackage.js +0 -42
  79. package/src/testutils/action/complex_schemas.ts +0 -517
  80. package/src/testutils/builder.ts +0 -422
  81. package/src/testutils/context/test_context.ts +0 -25
  82. package/src/testutils/db/fixture.ts +0 -32
  83. package/src/testutils/db/temp_db.ts +0 -941
  84. package/src/testutils/db/value.ts +0 -294
  85. package/src/testutils/db_mock.ts +0 -351
  86. package/src/testutils/db_time_zone.ts +0 -40
  87. package/src/testutils/ent-graphql-tests/index.ts +0 -653
  88. package/src/testutils/fake_comms.ts +0 -50
  89. package/src/testutils/fake_data/const.ts +0 -64
  90. package/src/testutils/fake_data/events_query.ts +0 -145
  91. package/src/testutils/fake_data/fake_contact.ts +0 -150
  92. package/src/testutils/fake_data/fake_event.ts +0 -150
  93. package/src/testutils/fake_data/fake_tag.ts +0 -139
  94. package/src/testutils/fake_data/fake_user.ts +0 -232
  95. package/src/testutils/fake_data/index.ts +0 -1
  96. package/src/testutils/fake_data/internal.ts +0 -8
  97. package/src/testutils/fake_data/tag_query.ts +0 -56
  98. package/src/testutils/fake_data/test_helpers.ts +0 -388
  99. package/src/testutils/fake_data/user_query.ts +0 -524
  100. package/src/testutils/fake_log.ts +0 -52
  101. package/src/testutils/mock_date.ts +0 -10
  102. package/src/testutils/mock_log.ts +0 -39
  103. package/src/testutils/parse_sql.ts +0 -685
  104. package/src/testutils/test_edge_global_schema.ts +0 -49
  105. package/src/testutils/write.ts +0 -70
  106. package/src/tsc/ast.ts +0 -351
  107. package/src/tsc/compilerOptions.ts +0 -85
  108. package/src/tsc/move_generated.ts +0 -191
  109. package/src/tsc/transform.ts +0 -226
  110. package/src/tsc/transform_action.ts +0 -224
  111. package/src/tsc/transform_ent.ts +0 -66
  112. package/src/tsc/transform_schema.ts +0 -546
  113. package/tsconfig.json +0 -20
  114. /package/{dist/action → action}/action.d.ts +0 -0
  115. /package/{dist/action → action}/action.js +0 -0
  116. /package/{dist/action → action}/executor.d.ts +0 -0
  117. /package/{dist/action → action}/executor.js +0 -0
  118. /package/{dist/action → action}/experimental_action.d.ts +0 -0
  119. /package/{dist/action → action}/experimental_action.js +0 -0
  120. /package/{dist/action → action}/index.d.ts +0 -0
  121. /package/{dist/action → action}/index.js +0 -0
  122. /package/{dist/action → action}/operations.d.ts +0 -0
  123. /package/{dist/action → action}/operations.js +0 -0
  124. /package/{dist/action → action}/orchestrator.d.ts +0 -0
  125. /package/{dist/action → action}/orchestrator.js +0 -0
  126. /package/{dist/action → action}/privacy.d.ts +0 -0
  127. /package/{dist/action → action}/privacy.js +0 -0
  128. /package/{dist/action → action}/relative_value.d.ts +0 -0
  129. /package/{dist/action → action}/relative_value.js +0 -0
  130. /package/{dist/action → action}/transaction.d.ts +0 -0
  131. /package/{dist/action → action}/transaction.js +0 -0
  132. /package/{dist/auth → auth}/auth.d.ts +0 -0
  133. /package/{dist/auth → auth}/auth.js +0 -0
  134. /package/{dist/auth → auth}/index.d.ts +0 -0
  135. /package/{dist/auth → auth}/index.js +0 -0
  136. /package/{dist/core → core}/base.d.ts +0 -0
  137. /package/{dist/core → core}/base.js +0 -0
  138. /package/{dist/core → core}/clause.d.ts +0 -0
  139. /package/{dist/core → core}/clause.js +0 -0
  140. /package/{dist/core → core}/config.d.ts +0 -0
  141. /package/{dist/core → core}/config.js +0 -0
  142. /package/{dist/core → core}/const.d.ts +0 -0
  143. /package/{dist/core → core}/const.js +0 -0
  144. /package/{dist/core → core}/context.d.ts +0 -0
  145. /package/{dist/core → core}/context.js +0 -0
  146. /package/{dist/core → core}/convert.d.ts +0 -0
  147. /package/{dist/core → core}/convert.js +0 -0
  148. /package/{dist/core → core}/date.d.ts +0 -0
  149. /package/{dist/core → core}/date.js +0 -0
  150. /package/{dist/core → core}/db.d.ts +0 -0
  151. /package/{dist/core → core}/db.js +0 -0
  152. /package/{dist/core → core}/ent.d.ts +0 -0
  153. /package/{dist/core → core}/ent.js +0 -0
  154. /package/{dist/core → core}/global_schema.d.ts +0 -0
  155. /package/{dist/core → core}/global_schema.js +0 -0
  156. /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
  157. /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
  158. /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
  159. /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
  160. /package/{dist/core → core}/loaders/index.d.ts +0 -0
  161. /package/{dist/core → core}/loaders/index.js +0 -0
  162. /package/{dist/core → core}/loaders/loader.d.ts +0 -0
  163. /package/{dist/core → core}/loaders/loader.js +0 -0
  164. /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
  165. /package/{dist/core → core}/loaders/object_loader.js +0 -0
  166. /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
  167. /package/{dist/core → core}/loaders/query_loader.js +0 -0
  168. /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
  169. /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
  170. /package/{dist/core → core}/logger.d.ts +0 -0
  171. /package/{dist/core → core}/logger.js +0 -0
  172. /package/{dist/core → core}/privacy.d.ts +0 -0
  173. /package/{dist/core → core}/privacy.js +0 -0
  174. /package/{dist/core → core}/query/assoc_query.d.ts +0 -0
  175. /package/{dist/core → core}/query/assoc_query.js +0 -0
  176. /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
  177. /package/{dist/core → core}/query/custom_clause_query.js +0 -0
  178. /package/{dist/core → core}/query/custom_query.d.ts +0 -0
  179. /package/{dist/core → core}/query/custom_query.js +0 -0
  180. /package/{dist/core → core}/query/index.d.ts +0 -0
  181. /package/{dist/core → core}/query/index.js +0 -0
  182. /package/{dist/core → core}/query/query.d.ts +0 -0
  183. /package/{dist/core → core}/query/query.js +0 -0
  184. /package/{dist/core → core}/query_impl.d.ts +0 -0
  185. /package/{dist/core → core}/query_impl.js +0 -0
  186. /package/{dist/core → core}/viewer.d.ts +0 -0
  187. /package/{dist/core → core}/viewer.js +0 -0
  188. /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
  189. /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
  190. /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
  191. /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
  192. /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
  193. /package/{dist/graphql → graphql}/builtins/node.js +0 -0
  194. /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
  195. /package/{dist/graphql → graphql}/graphql.js +0 -0
  196. /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
  197. /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
  198. /package/{dist/graphql → graphql}/index.d.ts +0 -0
  199. /package/{dist/graphql → graphql}/index.js +0 -0
  200. /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
  201. /package/{dist/graphql → graphql}/mutations/union.js +0 -0
  202. /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
  203. /package/{dist/graphql → graphql}/node_resolver.js +0 -0
  204. /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
  205. /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
  206. /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
  207. /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
  208. /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
  209. /package/{dist/graphql → graphql}/query/page_info.js +0 -0
  210. /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
  211. /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
  212. /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
  213. /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
  214. /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
  215. /package/{dist/graphql → graphql}/scalars/time.js +0 -0
  216. /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
  217. /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
  218. /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
  219. /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
  220. /package/{dist/imports → imports}/index.d.ts +0 -0
  221. /package/{dist/imports → imports}/index.js +0 -0
  222. /package/{dist/index.d.ts → index.d.ts} +0 -0
  223. /package/{dist/index.js → index.js} +0 -0
  224. /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
  225. /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
  226. /package/{dist/schema → schema}/base_schema.d.ts +0 -0
  227. /package/{dist/schema → schema}/base_schema.js +0 -0
  228. /package/{dist/schema → schema}/field.d.ts +0 -0
  229. /package/{dist/schema → schema}/field.js +0 -0
  230. /package/{dist/schema → schema}/index.d.ts +0 -0
  231. /package/{dist/schema → schema}/index.js +0 -0
  232. /package/{dist/schema → schema}/json_field.d.ts +0 -0
  233. /package/{dist/schema → schema}/json_field.js +0 -0
  234. /package/{dist/schema → schema}/schema.d.ts +0 -0
  235. /package/{dist/schema → schema}/schema.js +0 -0
  236. /package/{dist/schema → schema}/struct_field.d.ts +0 -0
  237. /package/{dist/schema → schema}/struct_field.js +0 -0
  238. /package/{dist/schema → schema}/union_field.d.ts +0 -0
  239. /package/{dist/schema → schema}/union_field.js +0 -0
  240. /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
  241. /package/{dist/scripts → scripts}/custom_compiler.js +0 -0
  242. /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
  243. /package/{dist/scripts → scripts}/custom_graphql.js +0 -0
  244. /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
  245. /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
  246. /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
  247. /package/{dist/scripts → scripts}/move_types.js +0 -0
  248. /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
  249. /package/{dist/scripts → scripts}/read_schema.js +0 -0
  250. /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
  251. /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
  252. /package/{dist/testutils → testutils}/builder.d.ts +0 -0
  253. /package/{dist/testutils → testutils}/builder.js +0 -0
  254. /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
  255. /package/{dist/testutils → testutils}/context/test_context.js +0 -0
  256. /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
  257. /package/{dist/testutils → testutils}/db/fixture.js +0 -0
  258. /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
  259. /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
  260. /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
  261. /package/{dist/testutils → testutils}/db/value.js +0 -0
  262. /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
  263. /package/{dist/testutils → testutils}/db_mock.js +0 -0
  264. /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
  265. /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
  266. /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
  267. /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
  268. /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
  269. /package/{dist/testutils → testutils}/fake_comms.js +0 -0
  270. /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
  271. /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
  272. /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
  273. /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
  274. /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
  275. /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
  276. /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
  277. /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
  278. /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
  279. /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
  280. /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
  281. /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
  282. /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
  283. /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
  284. /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
  285. /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
  286. /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
  287. /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
  288. /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +0 -0
  289. /package/{dist/testutils → testutils}/fake_data/test_helpers.js +0 -0
  290. /package/{dist/testutils → testutils}/fake_data/user_query.d.ts +0 -0
  291. /package/{dist/testutils → testutils}/fake_data/user_query.js +0 -0
  292. /package/{dist/testutils → testutils}/fake_log.d.ts +0 -0
  293. /package/{dist/testutils → testutils}/fake_log.js +0 -0
  294. /package/{dist/testutils → testutils}/mock_date.d.ts +0 -0
  295. /package/{dist/testutils → testutils}/mock_date.js +0 -0
  296. /package/{dist/testutils → testutils}/mock_log.d.ts +0 -0
  297. /package/{dist/testutils → testutils}/mock_log.js +0 -0
  298. /package/{dist/testutils → testutils}/parse_sql.d.ts +0 -0
  299. /package/{dist/testutils → testutils}/parse_sql.js +0 -0
  300. /package/{dist/testutils → testutils}/test_edge_global_schema.d.ts +0 -0
  301. /package/{dist/testutils → testutils}/test_edge_global_schema.js +0 -0
  302. /package/{dist/testutils → testutils}/write.d.ts +0 -0
  303. /package/{dist/testutils → testutils}/write.js +0 -0
  304. /package/{dist/tsc → tsc}/ast.d.ts +0 -0
  305. /package/{dist/tsc → tsc}/ast.js +0 -0
  306. /package/{dist/tsc → tsc}/compilerOptions.d.ts +0 -0
  307. /package/{dist/tsc → tsc}/compilerOptions.js +0 -0
  308. /package/{dist/tsc → tsc}/move_generated.d.ts +0 -0
  309. /package/{dist/tsc → tsc}/move_generated.js +0 -0
  310. /package/{dist/tsc → tsc}/transform.d.ts +0 -0
  311. /package/{dist/tsc → tsc}/transform.js +0 -0
  312. /package/{dist/tsc → tsc}/transform_action.d.ts +0 -0
  313. /package/{dist/tsc → tsc}/transform_action.js +0 -0
  314. /package/{dist/tsc → tsc}/transform_ent.d.ts +0 -0
  315. /package/{dist/tsc → tsc}/transform_ent.js +0 -0
  316. /package/{dist/tsc → tsc}/transform_schema.d.ts +0 -0
  317. /package/{dist/tsc → tsc}/transform_schema.js +0 -0
@@ -1,550 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import * as glob from "glob";
4
- import JSON5 from "json5";
5
- import minimist from "minimist";
6
- import * as path from "path";
7
- import * as fs from "fs";
8
- import {
9
- // can use the local interfaces since it's just the API we're getting from here
10
- ProcessedField,
11
- ProcessedCustomField,
12
- addCustomType,
13
- CustomObject,
14
- CustomQuery,
15
- CustomField,
16
- knownAllowedNames,
17
- isCustomType,
18
- CustomFieldType,
19
- } from "../graphql/graphql";
20
- import type {
21
- CustomFieldTypeInput,
22
- CustomGraphQLInput,
23
- GQLCapture,
24
- } from "../graphql/graphql";
25
- import * as readline from "readline";
26
- import { parseCustomImports, file } from "../imports";
27
- import { exit } from "process";
28
- import { Data } from "../core/base";
29
- import { spawn } from "child_process";
30
- import { GRAPHQL_PATH } from "../core/const";
31
-
32
- // need to use the GQLCapture from the package so that when we call GQLCapture.enable()
33
- // we're affecting the local paths as opposed to a different instance
34
- // life is hard
35
- const MODULE_PATH = GRAPHQL_PATH;
36
-
37
- async function readInputs(): Promise<{
38
- nodes: string[];
39
- nodesMap: Map<string, boolean>;
40
- }> {
41
- return await new Promise((resolve) => {
42
- const rl = readline.createInterface({
43
- input: process.stdin,
44
- // output: process.stdout,
45
- terminal: false,
46
- });
47
- let nodes: string[] = [];
48
- let nodesMap: Map<string, boolean> = new Map();
49
- rl.on("line", function (line: string) {
50
- nodes.push(line);
51
- nodesMap.set(line, true);
52
- });
53
-
54
- rl.on("close", function () {
55
- return resolve({ nodes, nodesMap });
56
- });
57
- });
58
- }
59
-
60
- function processCustomObjects(
61
- l: NonNullable<CustomGraphQLInput["inputs"]>,
62
- gqlCapture: typeof GQLCapture,
63
- m: Map<string, CustomObject>,
64
- ) {
65
- for (const input of l) {
66
- m.set(input.name, {
67
- nodeName: input.graphQLName || input.name,
68
- className: input.name,
69
- });
70
- if (input.fields) {
71
- processCustomFields(input.fields, gqlCapture, input.name);
72
- }
73
- }
74
- }
75
-
76
- function transformArgs(f: any, gqlCapture: typeof GQLCapture) {
77
- return (f.args || []).map((v: any) => {
78
- const ret = {
79
- ...v,
80
- };
81
- // duplicated from getType in graphql.ts
82
- if (isCustomType(ret.type)) {
83
- ret.type = v.type.type;
84
- addCustomType(v.type, gqlCapture);
85
- }
86
- // scalar types not supported for now
87
- ret.tsType = knownAllowedNames.get(v.type);
88
- return ret;
89
- });
90
- }
91
-
92
- function transformFieldTypeInput(input: CustomFieldTypeInput): CustomFieldType {
93
- switch (input) {
94
- case "ACCESSOR":
95
- return CustomFieldType.Accessor;
96
- case "ASYNC_FUNCTION":
97
- return CustomFieldType.AsyncFunction;
98
- case "FUNCTION":
99
- return CustomFieldType.Function;
100
- case "FIELD":
101
- return CustomFieldType.Field;
102
- }
103
- }
104
-
105
- function transformResultType(f: any) {
106
- return f.resultType
107
- ? [
108
- {
109
- name: "",
110
- type: f.resultType,
111
- tsType: knownAllowedNames.get(f.resultType),
112
- list: f.list,
113
- connection: f.connection,
114
- nullable: f.nullable,
115
- },
116
- ]
117
- : [];
118
- }
119
-
120
- function processTopLevel(
121
- l: NonNullable<CustomGraphQLInput["queries"]>,
122
- l2: CustomQuery[],
123
- gqlCapture: typeof GQLCapture,
124
- ) {
125
- for (const custom of l) {
126
- l2.push({
127
- nodeName: custom.class ?? "",
128
- functionName: custom.functionName || custom.name || "",
129
- gqlName: custom.graphQLName || custom.name || "",
130
- edgeName: custom.edgeName,
131
- fieldType: transformFieldTypeInput(custom.fieldType),
132
- args: transformArgs(custom, gqlCapture),
133
- results: transformResultType(custom),
134
- description: custom.description,
135
- extraImports: custom.extraImports,
136
- functionContents: custom.functionContents,
137
- });
138
- }
139
- }
140
-
141
- function processCustomTypes(
142
- m: NonNullable<CustomGraphQLInput["customTypes"]>,
143
- gqlCapture: typeof GQLCapture,
144
- ) {
145
- for (const k in m) {
146
- addCustomType(m[k], gqlCapture);
147
- }
148
- }
149
-
150
- function processCustomFields(
151
- fields: NonNullable<CustomGraphQLInput["fields"]>[string],
152
- gqlCapture: typeof GQLCapture,
153
- nodeName: string,
154
- ) {
155
- const m = gqlCapture.getCustomFields();
156
- let results: CustomField[] = [];
157
- for (const f of fields) {
158
- results.push({
159
- nodeName: nodeName,
160
- gqlName: f.graphQLName || f.name || "",
161
- functionName: f.functionName || f.name || "",
162
- fieldType: transformFieldTypeInput(f.fieldType),
163
- args: transformArgs(f, gqlCapture),
164
- results: transformResultType(f),
165
- description: f.description,
166
- });
167
- }
168
- m.set(nodeName, results);
169
- }
170
-
171
- async function captureDynamic(filePath: string, gqlCapture: typeof GQLCapture) {
172
- if (!filePath) {
173
- return;
174
- }
175
- return new Promise((resolve, reject) => {
176
- let cmd = "";
177
- const args: string[] = [];
178
- const env = {
179
- ...process.env,
180
- };
181
- if (process.env.ENABLE_SWC) {
182
- cmd = "node";
183
- // we seem to get tsconfig-paths by default because child process but not 100% sure...
184
- args.push("-r", "@swc-node/register");
185
- env.SWCRC = "true";
186
- } else {
187
- cmd = "ts-node";
188
- args.push("--transpileOnly");
189
- }
190
- args.push(filePath);
191
- const r = spawn(cmd, args, {
192
- env,
193
- });
194
-
195
- const datas: string[] = [];
196
- r.stdout.on("data", (data) => {
197
- datas.push(data.toString());
198
- });
199
-
200
- r.stderr.on("data", (data) => {
201
- reject(new Error(data.toString()));
202
- });
203
-
204
- r.on("close", (code) => {
205
- if (code !== 0) {
206
- reject(new Error(`error code ${code} on dynamic path`));
207
- return;
208
- }
209
-
210
- let json = JSON5.parse(datas.join(""));
211
-
212
- processJSON(gqlCapture, json);
213
-
214
- resolve(undefined);
215
- });
216
- });
217
- }
218
-
219
- async function processJSON(
220
- gqlCapture: typeof GQLCapture,
221
- json: CustomGraphQLInput,
222
- ) {
223
- if (json.fields) {
224
- for (const k in json.fields) {
225
- processCustomFields(json.fields[k], gqlCapture, k);
226
- }
227
- }
228
- if (json.inputs) {
229
- processCustomObjects(
230
- json.inputs,
231
- gqlCapture,
232
- gqlCapture.getCustomInputObjects(),
233
- );
234
- }
235
- if (json.objects) {
236
- processCustomObjects(
237
- json.objects,
238
- gqlCapture,
239
- gqlCapture.getCustomObjects(),
240
- );
241
- }
242
- if (json.args) {
243
- processCustomObjects(json.args, gqlCapture, gqlCapture.getCustomArgs());
244
- }
245
- if (json.queries) {
246
- processTopLevel(json.queries, gqlCapture.getCustomQueries(), gqlCapture);
247
- }
248
- if (json.mutations) {
249
- processTopLevel(
250
- json.mutations,
251
- gqlCapture.getCustomMutations(),
252
- gqlCapture,
253
- );
254
- }
255
- if (json.customTypes) {
256
- processCustomTypes(json.customTypes, gqlCapture);
257
- }
258
- }
259
-
260
- async function captureCustom(
261
- filePath: string,
262
- filesCsv: string | undefined,
263
- jsonPath: string | undefined,
264
- gqlCapture: typeof GQLCapture,
265
- ) {
266
- if (jsonPath !== undefined) {
267
- let json = JSON5.parse(
268
- fs.readFileSync(jsonPath, {
269
- encoding: "utf8",
270
- }),
271
- );
272
-
273
- processJSON(gqlCapture, json);
274
-
275
- return;
276
- }
277
- if (filesCsv !== undefined) {
278
- let files = filesCsv.split(",");
279
- for (let i = 0; i < files.length; i++) {
280
- // TODO fix. we have "src" in the path we get here
281
- files[i] = path.join(filePath, "..", files[i]);
282
- }
283
-
284
- await requireFiles(files);
285
- return;
286
- }
287
- // TODO delete all of this eventually
288
-
289
- // TODO configurable paths eventually
290
- // for now only files that are in the include path of the roots are allowed
291
-
292
- const rootFiles = [
293
- // right now, currently expecting all custom ent stuff to be in the ent object
294
- // eventually, create a path we check e.g. ent/custom_gql/ ent/graphql?
295
- // for now can just go in graphql/resolvers/ (not generated)
296
- path.join(filePath, "ent/index.ts"),
297
- path.join(filePath, "/graphql/resolvers/index.ts"),
298
- ];
299
-
300
- const ignore = [
301
- "**/generated/**",
302
- "**/tests/**",
303
- "**/index.ts",
304
- "**/internal.ts",
305
- // ignore test files.
306
- "**/*.test.ts",
307
- ];
308
- const customGQLResolvers = glob.sync(
309
- path.join(filePath, "/graphql/resolvers/**/*.ts"),
310
- {
311
- // no actions for now to speed things up
312
- // no index.ts or internal file.
313
- ignore: ignore,
314
- },
315
- );
316
- const customGQLMutations = glob.sync(
317
- path.join(filePath, "/graphql/mutations/**/*.ts"),
318
- {
319
- // no actions for now to speed things up
320
- // no index.ts or internal file.
321
- ignore: ignore,
322
- },
323
- );
324
- const files = rootFiles.concat(customGQLResolvers, customGQLMutations);
325
-
326
- await requireFiles(files);
327
- }
328
-
329
- async function requireFiles(files: string[]) {
330
- await Promise.all(
331
- files.map(async (file) => {
332
- if (fs.existsSync(file)) {
333
- try {
334
- await require(file);
335
- } catch (e) {
336
- throw new Error(`${(e as Error).message} loading ${file}`);
337
- }
338
- } else {
339
- throw new Error(`file ${file} doesn't exist`);
340
- }
341
- }),
342
- ).catch((err) => {
343
- throw new Error(err);
344
- });
345
- }
346
-
347
- // filePath is path-to-src
348
- async function parseImports(filePath: string) {
349
- return parseCustomImports(filePath, [
350
- {
351
- // graphql files
352
- root: path.join(filePath, "graphql"),
353
- opts: {
354
- ignore: ["**/generated/**", "**/tests/**"],
355
- },
356
- },
357
- {
358
- // can't just use top level ent files but have to check for all (non-generated) files
359
- // in src/ent/* because custom edges (or other things) could have @gqlField etc
360
- // and then have to look for these imports etc
361
- root: path.join(filePath, "ent"),
362
- opts: {
363
- // not in action files since we can't customize payloads (yet?)
364
- ignore: ["**/generated/**", "**/tests/**", "**/actions/**"],
365
- },
366
- },
367
- ]);
368
- }
369
-
370
- function findGraphQLPath(filePath: string): string | undefined {
371
- while (filePath !== "/") {
372
- const potentialPath = path.join(filePath, "node_modules");
373
- if (fs.existsSync(potentialPath)) {
374
- const graphqlPath = path.join(potentialPath, MODULE_PATH);
375
- if (fs.existsSync(graphqlPath)) {
376
- return graphqlPath;
377
- }
378
- }
379
- filePath = path.join(filePath, "..");
380
- }
381
- return undefined;
382
- }
383
-
384
- // test as follows:
385
- // there should be an easier way to do this...
386
- // also, there should be a way to get the list of objects here that's not manual
387
- //echo "User\nContact\nContactEmail\nComment" | ts-node-script --log-error --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/custom_graphql.ts --path ~/code/ent/examples/simple/src/
388
- async function main() {
389
- const options = minimist(process.argv.slice(2));
390
-
391
- if (!options.path) {
392
- throw new Error("path required");
393
- }
394
-
395
- const gqlPath = process.env.GRAPHQL_PATH || findGraphQLPath(options.path);
396
- if (!gqlPath) {
397
- throw new Error("could not find graphql path");
398
- }
399
-
400
- // use different variable so that we use the correct GQLCapture as needed
401
- // for local dev, get the one from the file system. otherwise, get the one
402
- // from node_modules
403
- let gqlCapture: typeof GQLCapture;
404
- if (process.env.LOCAL_SCRIPT_PATH) {
405
- const r = require("../graphql/graphql");
406
- gqlCapture = r.GQLCapture;
407
- } else {
408
- const r = require(gqlPath);
409
- if (!r.GQLCapture) {
410
- throw new Error("could not find GQLCapture in module");
411
- }
412
- gqlCapture = r.GQLCapture;
413
- gqlCapture.enable(true);
414
- }
415
-
416
- // known custom types that are not required
417
- // if not in the schema, will be ignored
418
- // something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
419
- // these 2 need this because they're added by the schema
420
- // if this list grows too long, need to build this into golang types and passed here
421
-
422
- // TODO foreign non-scalars eventually
423
- addCustomType(
424
- {
425
- importPath: MODULE_PATH,
426
- // for go tests...
427
- // TODO need a flag that only does this for go tests
428
- // breaks when running locally sometimes...
429
- secondaryImportPath: "../graphql/scalars/time",
430
- type: "GraphQLTime",
431
- },
432
- gqlCapture,
433
- );
434
- addCustomType(
435
- {
436
- importPath: "graphql-type-json",
437
- type: "GraphQLJSON",
438
- },
439
- gqlCapture,
440
- );
441
-
442
- const [inputsRead, _, __, imports] = await Promise.all([
443
- readInputs(),
444
- captureCustom(options.path, options.files, options.json_path, gqlCapture),
445
- captureDynamic(options.dynamic_path, gqlCapture),
446
- parseImports(options.path),
447
- ]);
448
- const { nodes, nodesMap } = inputsRead;
449
-
450
- function fromMap<T extends any>(m: Map<string, T>) {
451
- let result: Data = {};
452
- for (const [key, value] of m) {
453
- result[key] = value;
454
- }
455
- return result;
456
- }
457
- gqlCapture.resolve(nodes);
458
-
459
- let args = fromMap(gqlCapture.getCustomArgs());
460
- let inputs = fromMap(gqlCapture.getCustomInputObjects());
461
- let fields = gqlCapture.getProcessedCustomFields();
462
- let queries = gqlCapture.getProcessedCustomQueries();
463
- let mutations = gqlCapture.getProcessedCustomMutations();
464
- let objects = fromMap(gqlCapture.getCustomObjects());
465
- let interfaces = fromMap(gqlCapture.getCustomInterfaces());
466
- let unions = fromMap(gqlCapture.getCustomUnions());
467
- let customTypes = fromMap(gqlCapture.getCustomTypes());
468
-
469
- let classes: Data = {};
470
- let allFiles: Data = {};
471
-
472
- const buildClasses2 = (args: ProcessedField[]) => {
473
- args.forEach((arg) => {
474
- if (arg.isContextArg) {
475
- return;
476
- }
477
- let files = imports.m.get(arg.type);
478
- if (files?.length !== 1) {
479
- return;
480
- }
481
- let file = files[0];
482
- let classInfo = file.classes.get(arg.type);
483
- classes[arg.type] = { ...classInfo, path: file.path };
484
-
485
- buildFiles(file);
486
- });
487
- };
488
-
489
- // gather imports from files...
490
- // format is more compact as needed
491
- const buildFiles = (f: file) => {
492
- if (allFiles[f.path]) {
493
- return;
494
- }
495
- let imps: Data = {};
496
- for (const [key, value] of f.imports) {
497
- imps[key] = {
498
- path: value.importPath,
499
- };
500
- if (value.defaultImport) {
501
- imps[key].defaultImport = true;
502
- }
503
- }
504
- allFiles[f.path] = {
505
- imports: imps,
506
- };
507
- };
508
-
509
- const buildClasses = (fields: ProcessedCustomField[]) => {
510
- fields.forEach((field) => {
511
- if (field.nodeName && !nodesMap.has(field.nodeName)) {
512
- let info = imports.getInfoForClass(field.nodeName);
513
- classes[field.nodeName] = { ...info.class, path: info.file.path };
514
- buildFiles(info.file);
515
- }
516
-
517
- buildClasses2(field.args);
518
- buildClasses2(field.results);
519
- });
520
- };
521
- buildClasses(mutations);
522
- buildClasses(queries);
523
- // call for every field in a node
524
- for (const k in fields) {
525
- buildClasses(fields[k]);
526
- }
527
-
528
- console.log(
529
- JSON.stringify({
530
- args,
531
- inputs,
532
- fields,
533
- queries,
534
- mutations,
535
- classes,
536
- objects,
537
- interfaces,
538
- unions,
539
- files: allFiles,
540
- customTypes,
541
- }),
542
- );
543
- }
544
-
545
- main()
546
- .then()
547
- .catch((err) => {
548
- console.error(err);
549
- exit(1);
550
- });
@@ -1,41 +0,0 @@
1
- import minimist from "minimist";
2
- import { transform } from "../tsc/transform";
3
- import { TransformSchema } from "../tsc/transform_schema";
4
- import { TransformEnt } from "../tsc/transform_ent";
5
- import { moveGenerated } from "../tsc/move_generated";
6
- import { TransformAction } from "../tsc/transform_action";
7
- import { getCustomInfo } from "../tsc/ast";
8
-
9
- // todo-sqlite
10
- // ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/migrate_v0.1.ts --transform_schema --old_base_class BaseEntTodoSchema --new_schema_class TodoEntSchema --transform_path src/schema/patterns/base
11
- function main() {
12
- const customInfo = getCustomInfo();
13
- const options = minimist(process.argv.slice(2));
14
-
15
- // install 0.1.x dependencies
16
- // maybe provide options to make this easier if someone wants to do this in steps to see what's happening
17
- if (options.move_generated) {
18
- moveGenerated(customInfo.relativeImports!!);
19
- }
20
- // codegen write-all --disable-custom-graphql
21
- if (options.transform_schema) {
22
- transform(
23
- new TransformSchema(
24
- customInfo.relativeImports!!,
25
- options.old_base_class,
26
- options.new_schema_class,
27
- options.transform_path,
28
- ),
29
- );
30
- }
31
- // codegen write-all --disable-custom-graphql
32
- if (options.transform_ent) {
33
- transform(new TransformEnt());
34
- }
35
- if (options.transform_action) {
36
- transform(new TransformAction(customInfo));
37
- }
38
- // codegen write-all
39
- }
40
-
41
- main();
@@ -1,131 +0,0 @@
1
- import { TransformFile, transform } from "../tsc/transform";
2
- import {
3
- getImportInfo,
4
- getCustomInfo,
5
- transformRelative,
6
- transformImport,
7
- } from "../tsc/ast";
8
- import ts, { isImportDeclaration } from "typescript";
9
- import path from "path";
10
-
11
- class GatherExportsInGeneratedTypes implements TransformFile {
12
- glob = "src/ent/generated/types.ts";
13
- names: string[] = [];
14
- traverseChild(
15
- sourceFile: ts.SourceFile,
16
- contents: string,
17
- file: string,
18
- node: ts.Node,
19
- ) {
20
- const modifiers = ts.canHaveModifiers(node)
21
- ? ts.getModifiers(node)
22
- : undefined;
23
-
24
- const exported = modifiers?.filter(
25
- (mod) => mod.getText(sourceFile) === "export",
26
- );
27
-
28
- if (exported?.length) {
29
- if (
30
- ts.isEnumDeclaration(node) ||
31
- ts.isInterfaceDeclaration(node) ||
32
- ts.isTypeAliasDeclaration(node)
33
- ) {
34
- this.names.push(node.name.text);
35
- }
36
-
37
- if (ts.isFunctionDeclaration(node) && node.name?.text) {
38
- this.names.push(node.name.text);
39
- }
40
- }
41
- return { node };
42
- }
43
- }
44
-
45
- class TransformImports implements TransformFile {
46
- glob = "src/**/*.ts";
47
-
48
- prettierGlob = "src/**/*.ts";
49
-
50
- impsToMove = new Map();
51
- cwd = "";
52
- relative = false;
53
-
54
- constructor() {
55
- this.cwd = process.cwd();
56
- const gt = new GatherExportsInGeneratedTypes();
57
- transform(gt);
58
- gt.names.forEach((v) => this.impsToMove.set(v, true));
59
-
60
- this.relative = getCustomInfo().relativeImports ?? this.relative;
61
- }
62
-
63
- private getSrcPath(file: string, text: string) {
64
- if (text.startsWith("src")) {
65
- return text;
66
- }
67
- const dir = path.dirname(path.join(this.cwd, file));
68
- const fullPath = path.join(dir, text);
69
- return path.relative(this.cwd, fullPath);
70
- }
71
-
72
- traverseChild(
73
- sourceFile: ts.SourceFile,
74
- contents: string,
75
- file: string,
76
- node: ts.Node,
77
- ) {
78
- if (!isImportDeclaration(node)) {
79
- return { node };
80
- }
81
-
82
- const impInfo = getImportInfo(node, sourceFile);
83
- if (!impInfo) {
84
- return { node };
85
- }
86
- const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
87
- const pathToWrite = transformRelative(
88
- file,
89
- "src/ent/generated/types",
90
- this.relative,
91
- );
92
- const current = transformRelative(file, text, this.relative);
93
- const srcPath = this.getSrcPath(file, text);
94
- // nothing to do here
95
- if (!srcPath.startsWith("src/ent") || pathToWrite === current) {
96
- return { node };
97
- }
98
-
99
- // let's see if we can simplify
100
- let seenImports: string[] = [];
101
- for (let imp of impInfo.imports) {
102
- imp = imp.trim();
103
- if (this.impsToMove.has(imp)) {
104
- seenImports.push(imp);
105
- }
106
- }
107
-
108
- if (!seenImports.length) {
109
- return { node };
110
- }
111
-
112
- let imports: Map<string, string[]> = new Map([[pathToWrite, seenImports]]);
113
-
114
- return {
115
- rawString: transformImport(contents, node, sourceFile, {
116
- removeImports: seenImports,
117
- transformPath: text,
118
- }),
119
- traversed: true,
120
- imports, // new imports to add
121
- allowSeenImportsAdded: true,
122
- };
123
- }
124
- }
125
-
126
- // ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/move_types.ts
127
- function main() {
128
- transform(new TransformImports());
129
- }
130
-
131
- main();