@snowtop/ent 0.1.0-alpha160-test4 → 0.1.0-alpha160-test6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/dist/package.json +64 -0
  2. package/{scripts → dist/scripts}/custom_compiler.js +0 -0
  3. package/{scripts → dist/scripts}/custom_graphql.js +0 -0
  4. package/package.json +48 -6
  5. package/src/action/action.ts +330 -0
  6. package/src/action/executor.ts +453 -0
  7. package/src/action/experimental_action.ts +277 -0
  8. package/src/action/index.ts +31 -0
  9. package/src/action/operations.ts +967 -0
  10. package/src/action/orchestrator.ts +1527 -0
  11. package/src/action/privacy.ts +37 -0
  12. package/src/action/relative_value.ts +242 -0
  13. package/src/action/transaction.ts +38 -0
  14. package/src/auth/auth.ts +77 -0
  15. package/src/auth/index.ts +8 -0
  16. package/src/core/base.ts +367 -0
  17. package/src/core/clause.ts +1065 -0
  18. package/src/core/config.ts +219 -0
  19. package/src/core/const.ts +5 -0
  20. package/src/core/context.ts +135 -0
  21. package/src/core/convert.ts +106 -0
  22. package/src/core/date.ts +23 -0
  23. package/src/core/db.ts +498 -0
  24. package/src/core/ent.ts +1740 -0
  25. package/src/core/global_schema.ts +49 -0
  26. package/src/core/loaders/assoc_count_loader.ts +99 -0
  27. package/src/core/loaders/assoc_edge_loader.ts +250 -0
  28. package/src/core/loaders/index.ts +12 -0
  29. package/src/core/loaders/loader.ts +66 -0
  30. package/src/core/loaders/object_loader.ts +489 -0
  31. package/src/core/loaders/query_loader.ts +314 -0
  32. package/src/core/loaders/raw_count_loader.ts +175 -0
  33. package/src/core/logger.ts +49 -0
  34. package/src/core/privacy.ts +660 -0
  35. package/src/core/query/assoc_query.ts +240 -0
  36. package/src/core/query/custom_clause_query.ts +174 -0
  37. package/src/core/query/custom_query.ts +302 -0
  38. package/src/core/query/index.ts +9 -0
  39. package/src/core/query/query.ts +674 -0
  40. package/src/core/query_impl.ts +32 -0
  41. package/src/core/viewer.ts +52 -0
  42. package/src/ent.code-workspace +73 -0
  43. package/src/graphql/builtins/connection.ts +25 -0
  44. package/src/graphql/builtins/edge.ts +16 -0
  45. package/src/graphql/builtins/node.ts +12 -0
  46. package/src/graphql/graphql.ts +891 -0
  47. package/src/graphql/graphql_field_helpers.ts +221 -0
  48. package/src/graphql/index.ts +42 -0
  49. package/src/graphql/mutations/union.ts +39 -0
  50. package/src/graphql/node_resolver.ts +122 -0
  51. package/src/graphql/query/connection_type.ts +113 -0
  52. package/src/graphql/query/edge_connection.ts +171 -0
  53. package/src/graphql/query/page_info.ts +34 -0
  54. package/src/graphql/query/shared_edge_connection.ts +287 -0
  55. package/src/graphql/scalars/orderby_direction.ts +13 -0
  56. package/src/graphql/scalars/time.ts +38 -0
  57. package/src/imports/dataz/example1/_auth.ts +51 -0
  58. package/src/imports/dataz/example1/_viewer.ts +35 -0
  59. package/src/imports/index.ts +213 -0
  60. package/src/index.ts +145 -0
  61. package/src/parse_schema/parse.ts +585 -0
  62. package/src/schema/base_schema.ts +224 -0
  63. package/src/schema/field.ts +1087 -0
  64. package/src/schema/index.ts +53 -0
  65. package/src/schema/json_field.ts +94 -0
  66. package/src/schema/schema.ts +1028 -0
  67. package/src/schema/struct_field.ts +234 -0
  68. package/src/schema/union_field.ts +105 -0
  69. package/src/scripts/custom_compiler.ts +331 -0
  70. package/src/scripts/custom_graphql.ts +550 -0
  71. package/src/scripts/migrate_v0.1.ts +41 -0
  72. package/src/scripts/move_types.ts +131 -0
  73. package/src/scripts/read_schema.ts +67 -0
  74. package/src/setupPackage.js +42 -0
  75. package/src/testutils/action/complex_schemas.ts +517 -0
  76. package/src/testutils/builder.ts +422 -0
  77. package/src/testutils/context/test_context.ts +25 -0
  78. package/src/testutils/db/fixture.ts +32 -0
  79. package/src/testutils/db/temp_db.ts +941 -0
  80. package/src/testutils/db/value.ts +294 -0
  81. package/src/testutils/db_mock.ts +351 -0
  82. package/src/testutils/db_time_zone.ts +40 -0
  83. package/src/testutils/ent-graphql-tests/index.ts +653 -0
  84. package/src/testutils/fake_comms.ts +50 -0
  85. package/src/testutils/fake_data/const.ts +64 -0
  86. package/src/testutils/fake_data/events_query.ts +145 -0
  87. package/src/testutils/fake_data/fake_contact.ts +150 -0
  88. package/src/testutils/fake_data/fake_event.ts +150 -0
  89. package/src/testutils/fake_data/fake_tag.ts +139 -0
  90. package/src/testutils/fake_data/fake_user.ts +232 -0
  91. package/src/testutils/fake_data/index.ts +1 -0
  92. package/src/testutils/fake_data/internal.ts +8 -0
  93. package/src/testutils/fake_data/tag_query.ts +56 -0
  94. package/src/testutils/fake_data/test_helpers.ts +388 -0
  95. package/src/testutils/fake_data/user_query.ts +524 -0
  96. package/src/testutils/fake_log.ts +52 -0
  97. package/src/testutils/mock_date.ts +10 -0
  98. package/src/testutils/mock_log.ts +39 -0
  99. package/src/testutils/parse_sql.ts +685 -0
  100. package/src/testutils/test_edge_global_schema.ts +49 -0
  101. package/src/testutils/write.ts +70 -0
  102. package/src/tsc/ast.ts +351 -0
  103. package/src/tsc/compilerOptions.ts +85 -0
  104. package/src/tsc/move_generated.ts +191 -0
  105. package/src/tsc/transform.ts +226 -0
  106. package/src/tsc/transform_action.ts +224 -0
  107. package/src/tsc/transform_ent.ts +66 -0
  108. package/src/tsc/transform_schema.ts +546 -0
  109. package/tsconfig.json +20 -0
  110. package/core/query/shared_assoc_test.d.ts +0 -2
  111. package/core/query/shared_assoc_test.js +0 -804
  112. package/core/query/shared_test.d.ts +0 -21
  113. package/core/query/shared_test.js +0 -736
  114. package/graphql/query/shared_assoc_test.d.ts +0 -1
  115. package/graphql/query/shared_assoc_test.js +0 -203
  116. /package/{action → dist/action}/action.d.ts +0 -0
  117. /package/{action → dist/action}/action.js +0 -0
  118. /package/{action → dist/action}/executor.d.ts +0 -0
  119. /package/{action → dist/action}/executor.js +0 -0
  120. /package/{action → dist/action}/experimental_action.d.ts +0 -0
  121. /package/{action → dist/action}/experimental_action.js +0 -0
  122. /package/{action → dist/action}/index.d.ts +0 -0
  123. /package/{action → dist/action}/index.js +0 -0
  124. /package/{action → dist/action}/operations.d.ts +0 -0
  125. /package/{action → dist/action}/operations.js +0 -0
  126. /package/{action → dist/action}/orchestrator.d.ts +0 -0
  127. /package/{action → dist/action}/orchestrator.js +0 -0
  128. /package/{action → dist/action}/privacy.d.ts +0 -0
  129. /package/{action → dist/action}/privacy.js +0 -0
  130. /package/{action → dist/action}/relative_value.d.ts +0 -0
  131. /package/{action → dist/action}/relative_value.js +0 -0
  132. /package/{action → dist/action}/transaction.d.ts +0 -0
  133. /package/{action → dist/action}/transaction.js +0 -0
  134. /package/{auth → dist/auth}/auth.d.ts +0 -0
  135. /package/{auth → dist/auth}/auth.js +0 -0
  136. /package/{auth → dist/auth}/index.d.ts +0 -0
  137. /package/{auth → dist/auth}/index.js +0 -0
  138. /package/{core → dist/core}/base.d.ts +0 -0
  139. /package/{core → dist/core}/base.js +0 -0
  140. /package/{core → dist/core}/clause.d.ts +0 -0
  141. /package/{core → dist/core}/clause.js +0 -0
  142. /package/{core → dist/core}/config.d.ts +0 -0
  143. /package/{core → dist/core}/config.js +0 -0
  144. /package/{core → dist/core}/const.d.ts +0 -0
  145. /package/{core → dist/core}/const.js +0 -0
  146. /package/{core → dist/core}/context.d.ts +0 -0
  147. /package/{core → dist/core}/context.js +0 -0
  148. /package/{core → dist/core}/convert.d.ts +0 -0
  149. /package/{core → dist/core}/convert.js +0 -0
  150. /package/{core → dist/core}/date.d.ts +0 -0
  151. /package/{core → dist/core}/date.js +0 -0
  152. /package/{core → dist/core}/db.d.ts +0 -0
  153. /package/{core → dist/core}/db.js +0 -0
  154. /package/{core → dist/core}/ent.d.ts +0 -0
  155. /package/{core → dist/core}/ent.js +0 -0
  156. /package/{core → dist/core}/global_schema.d.ts +0 -0
  157. /package/{core → dist/core}/global_schema.js +0 -0
  158. /package/{core → dist/core}/loaders/assoc_count_loader.d.ts +0 -0
  159. /package/{core → dist/core}/loaders/assoc_count_loader.js +0 -0
  160. /package/{core → dist/core}/loaders/assoc_edge_loader.d.ts +0 -0
  161. /package/{core → dist/core}/loaders/assoc_edge_loader.js +0 -0
  162. /package/{core → dist/core}/loaders/index.d.ts +0 -0
  163. /package/{core → dist/core}/loaders/index.js +0 -0
  164. /package/{core → dist/core}/loaders/loader.d.ts +0 -0
  165. /package/{core → dist/core}/loaders/loader.js +0 -0
  166. /package/{core → dist/core}/loaders/object_loader.d.ts +0 -0
  167. /package/{core → dist/core}/loaders/object_loader.js +0 -0
  168. /package/{core → dist/core}/loaders/query_loader.d.ts +0 -0
  169. /package/{core → dist/core}/loaders/query_loader.js +0 -0
  170. /package/{core → dist/core}/loaders/raw_count_loader.d.ts +0 -0
  171. /package/{core → dist/core}/loaders/raw_count_loader.js +0 -0
  172. /package/{core → dist/core}/logger.d.ts +0 -0
  173. /package/{core → dist/core}/logger.js +0 -0
  174. /package/{core → dist/core}/privacy.d.ts +0 -0
  175. /package/{core → dist/core}/privacy.js +0 -0
  176. /package/{core → dist/core}/query/assoc_query.d.ts +0 -0
  177. /package/{core → dist/core}/query/assoc_query.js +0 -0
  178. /package/{core → dist/core}/query/custom_clause_query.d.ts +0 -0
  179. /package/{core → dist/core}/query/custom_clause_query.js +0 -0
  180. /package/{core → dist/core}/query/custom_query.d.ts +0 -0
  181. /package/{core → dist/core}/query/custom_query.js +0 -0
  182. /package/{core → dist/core}/query/index.d.ts +0 -0
  183. /package/{core → dist/core}/query/index.js +0 -0
  184. /package/{core → dist/core}/query/query.d.ts +0 -0
  185. /package/{core → dist/core}/query/query.js +0 -0
  186. /package/{core → dist/core}/query_impl.d.ts +0 -0
  187. /package/{core → dist/core}/query_impl.js +0 -0
  188. /package/{core → dist/core}/viewer.d.ts +0 -0
  189. /package/{core → dist/core}/viewer.js +0 -0
  190. /package/{graphql → dist/graphql}/builtins/connection.d.ts +0 -0
  191. /package/{graphql → dist/graphql}/builtins/connection.js +0 -0
  192. /package/{graphql → dist/graphql}/builtins/edge.d.ts +0 -0
  193. /package/{graphql → dist/graphql}/builtins/edge.js +0 -0
  194. /package/{graphql → dist/graphql}/builtins/node.d.ts +0 -0
  195. /package/{graphql → dist/graphql}/builtins/node.js +0 -0
  196. /package/{graphql → dist/graphql}/graphql.d.ts +0 -0
  197. /package/{graphql → dist/graphql}/graphql.js +0 -0
  198. /package/{graphql → dist/graphql}/graphql_field_helpers.d.ts +0 -0
  199. /package/{graphql → dist/graphql}/graphql_field_helpers.js +0 -0
  200. /package/{graphql → dist/graphql}/index.d.ts +0 -0
  201. /package/{graphql → dist/graphql}/index.js +0 -0
  202. /package/{graphql → dist/graphql}/mutations/union.d.ts +0 -0
  203. /package/{graphql → dist/graphql}/mutations/union.js +0 -0
  204. /package/{graphql → dist/graphql}/node_resolver.d.ts +0 -0
  205. /package/{graphql → dist/graphql}/node_resolver.js +0 -0
  206. /package/{graphql → dist/graphql}/query/connection_type.d.ts +0 -0
  207. /package/{graphql → dist/graphql}/query/connection_type.js +0 -0
  208. /package/{graphql → dist/graphql}/query/edge_connection.d.ts +0 -0
  209. /package/{graphql → dist/graphql}/query/edge_connection.js +0 -0
  210. /package/{graphql → dist/graphql}/query/page_info.d.ts +0 -0
  211. /package/{graphql → dist/graphql}/query/page_info.js +0 -0
  212. /package/{graphql → dist/graphql}/query/shared_edge_connection.d.ts +0 -0
  213. /package/{graphql → dist/graphql}/query/shared_edge_connection.js +0 -0
  214. /package/{graphql → dist/graphql}/scalars/orderby_direction.d.ts +0 -0
  215. /package/{graphql → dist/graphql}/scalars/orderby_direction.js +0 -0
  216. /package/{graphql → dist/graphql}/scalars/time.d.ts +0 -0
  217. /package/{graphql → dist/graphql}/scalars/time.js +0 -0
  218. /package/{imports → dist/imports}/dataz/example1/_auth.d.ts +0 -0
  219. /package/{imports → dist/imports}/dataz/example1/_auth.js +0 -0
  220. /package/{imports → dist/imports}/dataz/example1/_viewer.d.ts +0 -0
  221. /package/{imports → dist/imports}/dataz/example1/_viewer.js +0 -0
  222. /package/{imports → dist/imports}/index.d.ts +0 -0
  223. /package/{imports → dist/imports}/index.js +0 -0
  224. /package/{index.d.ts → dist/index.d.ts} +0 -0
  225. /package/{index.js → dist/index.js} +0 -0
  226. /package/{parse_schema → dist/parse_schema}/parse.d.ts +0 -0
  227. /package/{parse_schema → dist/parse_schema}/parse.js +0 -0
  228. /package/{schema → dist/schema}/base_schema.d.ts +0 -0
  229. /package/{schema → dist/schema}/base_schema.js +0 -0
  230. /package/{schema → dist/schema}/field.d.ts +0 -0
  231. /package/{schema → dist/schema}/field.js +0 -0
  232. /package/{schema → dist/schema}/index.d.ts +0 -0
  233. /package/{schema → dist/schema}/index.js +0 -0
  234. /package/{schema → dist/schema}/json_field.d.ts +0 -0
  235. /package/{schema → dist/schema}/json_field.js +0 -0
  236. /package/{schema → dist/schema}/schema.d.ts +0 -0
  237. /package/{schema → dist/schema}/schema.js +0 -0
  238. /package/{schema → dist/schema}/struct_field.d.ts +0 -0
  239. /package/{schema → dist/schema}/struct_field.js +0 -0
  240. /package/{schema → dist/schema}/union_field.d.ts +0 -0
  241. /package/{schema → dist/schema}/union_field.js +0 -0
  242. /package/{scripts → dist/scripts}/custom_compiler.d.ts +0 -0
  243. /package/{scripts → dist/scripts}/custom_graphql.d.ts +0 -0
  244. /package/{scripts → dist/scripts}/migrate_v0.1.d.ts +0 -0
  245. /package/{scripts → dist/scripts}/migrate_v0.1.js +0 -0
  246. /package/{scripts → dist/scripts}/move_types.d.ts +0 -0
  247. /package/{scripts → dist/scripts}/move_types.js +0 -0
  248. /package/{scripts → dist/scripts}/read_schema.d.ts +0 -0
  249. /package/{scripts → dist/scripts}/read_schema.js +0 -0
  250. /package/{testutils → dist/testutils}/action/complex_schemas.d.ts +0 -0
  251. /package/{testutils → dist/testutils}/action/complex_schemas.js +0 -0
  252. /package/{testutils → dist/testutils}/builder.d.ts +0 -0
  253. /package/{testutils → dist/testutils}/builder.js +0 -0
  254. /package/{testutils → dist/testutils}/context/test_context.d.ts +0 -0
  255. /package/{testutils → dist/testutils}/context/test_context.js +0 -0
  256. /package/{testutils → dist/testutils}/db/fixture.d.ts +0 -0
  257. /package/{testutils → dist/testutils}/db/fixture.js +0 -0
  258. /package/{testutils → dist/testutils}/db/temp_db.d.ts +0 -0
  259. /package/{testutils → dist/testutils}/db/temp_db.js +0 -0
  260. /package/{testutils → dist/testutils}/db/value.d.ts +0 -0
  261. /package/{testutils → dist/testutils}/db/value.js +0 -0
  262. /package/{testutils → dist/testutils}/db_mock.d.ts +0 -0
  263. /package/{testutils → dist/testutils}/db_mock.js +0 -0
  264. /package/{testutils → dist/testutils}/db_time_zone.d.ts +0 -0
  265. /package/{testutils → dist/testutils}/db_time_zone.js +0 -0
  266. /package/{testutils → dist/testutils}/ent-graphql-tests/index.d.ts +0 -0
  267. /package/{testutils → dist/testutils}/ent-graphql-tests/index.js +0 -0
  268. /package/{testutils → dist/testutils}/fake_comms.d.ts +0 -0
  269. /package/{testutils → dist/testutils}/fake_comms.js +0 -0
  270. /package/{testutils → dist/testutils}/fake_data/const.d.ts +0 -0
  271. /package/{testutils → dist/testutils}/fake_data/const.js +0 -0
  272. /package/{testutils → dist/testutils}/fake_data/events_query.d.ts +0 -0
  273. /package/{testutils → dist/testutils}/fake_data/events_query.js +0 -0
  274. /package/{testutils → dist/testutils}/fake_data/fake_contact.d.ts +0 -0
  275. /package/{testutils → dist/testutils}/fake_data/fake_contact.js +0 -0
  276. /package/{testutils → dist/testutils}/fake_data/fake_event.d.ts +0 -0
  277. /package/{testutils → dist/testutils}/fake_data/fake_event.js +0 -0
  278. /package/{testutils → dist/testutils}/fake_data/fake_tag.d.ts +0 -0
  279. /package/{testutils → dist/testutils}/fake_data/fake_tag.js +0 -0
  280. /package/{testutils → dist/testutils}/fake_data/fake_user.d.ts +0 -0
  281. /package/{testutils → dist/testutils}/fake_data/fake_user.js +0 -0
  282. /package/{testutils → dist/testutils}/fake_data/index.d.ts +0 -0
  283. /package/{testutils → dist/testutils}/fake_data/index.js +0 -0
  284. /package/{testutils → dist/testutils}/fake_data/internal.d.ts +0 -0
  285. /package/{testutils → dist/testutils}/fake_data/internal.js +0 -0
  286. /package/{testutils → dist/testutils}/fake_data/tag_query.d.ts +0 -0
  287. /package/{testutils → dist/testutils}/fake_data/tag_query.js +0 -0
  288. /package/{testutils → dist/testutils}/fake_data/test_helpers.d.ts +0 -0
  289. /package/{testutils → dist/testutils}/fake_data/test_helpers.js +0 -0
  290. /package/{testutils → dist/testutils}/fake_data/user_query.d.ts +0 -0
  291. /package/{testutils → dist/testutils}/fake_data/user_query.js +0 -0
  292. /package/{testutils → dist/testutils}/fake_log.d.ts +0 -0
  293. /package/{testutils → dist/testutils}/fake_log.js +0 -0
  294. /package/{testutils → dist/testutils}/mock_date.d.ts +0 -0
  295. /package/{testutils → dist/testutils}/mock_date.js +0 -0
  296. /package/{testutils → dist/testutils}/mock_log.d.ts +0 -0
  297. /package/{testutils → dist/testutils}/mock_log.js +0 -0
  298. /package/{testutils → dist/testutils}/parse_sql.d.ts +0 -0
  299. /package/{testutils → dist/testutils}/parse_sql.js +0 -0
  300. /package/{testutils → dist/testutils}/test_edge_global_schema.d.ts +0 -0
  301. /package/{testutils → dist/testutils}/test_edge_global_schema.js +0 -0
  302. /package/{testutils → dist/testutils}/write.d.ts +0 -0
  303. /package/{testutils → dist/testutils}/write.js +0 -0
  304. /package/{tsc → dist/tsc}/ast.d.ts +0 -0
  305. /package/{tsc → dist/tsc}/ast.js +0 -0
  306. /package/{tsc → dist/tsc}/compilerOptions.d.ts +0 -0
  307. /package/{tsc → dist/tsc}/compilerOptions.js +0 -0
  308. /package/{tsc → dist/tsc}/move_generated.d.ts +0 -0
  309. /package/{tsc → dist/tsc}/move_generated.js +0 -0
  310. /package/{tsc → dist/tsc}/transform.d.ts +0 -0
  311. /package/{tsc → dist/tsc}/transform.js +0 -0
  312. /package/{tsc → dist/tsc}/transform_action.d.ts +0 -0
  313. /package/{tsc → dist/tsc}/transform_action.js +0 -0
  314. /package/{tsc → dist/tsc}/transform_ent.d.ts +0 -0
  315. /package/{tsc → dist/tsc}/transform_ent.js +0 -0
  316. /package/{tsc → dist/tsc}/transform_schema.d.ts +0 -0
  317. /package/{tsc → dist/tsc}/transform_schema.js +0 -0
@@ -0,0 +1,191 @@
1
+ import * as glob from "glob";
2
+ import * as path from "path";
3
+ import * as fs from "fs";
4
+ import ts from "typescript";
5
+ import {
6
+ isRelativeGeneratedImport,
7
+ isRelativeImport,
8
+ isSrcGeneratedImport,
9
+ updateImportPath,
10
+ } from "./ast";
11
+ import { transform, TransformFile } from "./transform";
12
+
13
+ class MoveFiles {
14
+ constructor(private globPath: string) {}
15
+
16
+ move() {
17
+ const files = glob.sync(this.globPath);
18
+ moveFiles(files);
19
+ }
20
+ }
21
+
22
+ class TransformImports implements TransformFile {
23
+ cwd: string;
24
+ constructor(
25
+ public glob: string,
26
+ public prettierGlob: string,
27
+ private relativeImports: boolean,
28
+ private checkRelativeImportsValid?: boolean,
29
+ ) {
30
+ this.cwd = process.cwd();
31
+ }
32
+
33
+ globOptions = {
34
+ ignore: ["node_modules/**"],
35
+ };
36
+
37
+ traverseChild(
38
+ sourceFile: ts.SourceFile,
39
+ contents: string,
40
+ file: string,
41
+ node: ts.Node,
42
+ ) {
43
+ if (!ts.isImportDeclaration(node)) {
44
+ return { node };
45
+ }
46
+ let dirPath = path.join(this.cwd, file, "..");
47
+
48
+ const newImportPath = this.getNewImportPath(
49
+ node,
50
+ file,
51
+ sourceFile,
52
+ dirPath,
53
+ );
54
+ if (!newImportPath) {
55
+ return { node };
56
+ }
57
+
58
+ const v = updateImportPath(contents, node, sourceFile, newImportPath);
59
+
60
+ return {
61
+ traversed: true,
62
+ rawString: v,
63
+ };
64
+ }
65
+
66
+ getNewImportPath(
67
+ node: ts.ImportDeclaration,
68
+ file: string,
69
+ sourceFile: ts.SourceFile,
70
+ dirPath: string,
71
+ ) {
72
+ const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
73
+
74
+ // it's relative and has generated in there, continue
75
+ // do relative imports path regardless of if relative imports is on or not
76
+ if (isRelativeGeneratedImport(node, sourceFile)) {
77
+ const oldPath = path.join(dirPath, text);
78
+ const relFromRoot = path.relative(".", oldPath);
79
+ const conv = transformPath(relFromRoot);
80
+ if (!conv || conv.newFile === relFromRoot) {
81
+ return;
82
+ }
83
+ return path.relative(dirPath, conv.newFile);
84
+ }
85
+
86
+ if (this.checkRelativeImportsValid && isRelativeImport(node, sourceFile)) {
87
+ const parts = file.split(path.sep);
88
+ if (
89
+ parts.length === 5 &&
90
+ parts.slice(0, 3).join(path.sep) ===
91
+ ["src", "graphql", "generated"].join(path.sep)
92
+ ) {
93
+ // we have custom graphql import paths
94
+ // src/graphql/generated/mutations|resolvers/foo_type.ts
95
+ // which used to be
96
+ // src/graphql/mutations|resolvers/generated/foo_type.ts
97
+
98
+ // we probably have a broken import.
99
+ // try and fix it...
100
+ let temp = parts[2];
101
+ parts[2] = parts[3];
102
+ parts[3] = temp;
103
+ const oldPath = parts.join(path.sep);
104
+
105
+ let oldDir = path.join(this.cwd, oldPath, "..");
106
+ let importPath = path.join(oldDir, text);
107
+ let exists = fs.statSync(importPath + ".ts", { throwIfNoEntry: false });
108
+ if (!exists) {
109
+ // doesn't exist. sadly has to be fixed manually. could theoretically also be a directory but we shouldn't have that
110
+ return;
111
+ }
112
+
113
+ return path.relative(dirPath, importPath);
114
+ }
115
+ }
116
+ // if relative imports, we done.
117
+ if (this.relativeImports) {
118
+ return;
119
+ }
120
+
121
+ // non relative, only transform src paths with generated
122
+ if (isSrcGeneratedImport(node, sourceFile)) {
123
+ const conv = transformPath(text);
124
+ if (!conv || conv.newFile === text) {
125
+ return;
126
+ }
127
+ return conv.newFile;
128
+ }
129
+
130
+ return;
131
+ }
132
+ }
133
+
134
+ function transformPath(old: string) {
135
+ const parts = old.split(path.sep);
136
+ if (parts.length < 3) {
137
+ return;
138
+ }
139
+
140
+ const changedParts = parts
141
+ .slice(0, 2)
142
+ .concat("generated")
143
+ .concat(parts.slice(2).filter((v) => v !== "generated"));
144
+
145
+ const newFile = changedParts.join(path.sep);
146
+
147
+ return { changedParts, newFile };
148
+ }
149
+
150
+ function moveFiles(files: string[]) {
151
+ files.forEach((file) => {
152
+ const conv = transformPath(file);
153
+ if (!conv) {
154
+ return;
155
+ }
156
+ const { changedParts, newFile } = conv;
157
+
158
+ if (file === newFile) {
159
+ return;
160
+ }
161
+
162
+ // check if directory exists, if not, create recursive dir
163
+ const p = changedParts.slice(0, changedParts.length - 1).join(path.sep);
164
+ const statInfo = fs.statSync(p, { throwIfNoEntry: false });
165
+ if (!statInfo) {
166
+ fs.mkdirSync(p, {
167
+ recursive: true,
168
+ });
169
+ }
170
+
171
+ // move file to new location
172
+ fs.renameSync(file, newFile);
173
+ });
174
+ }
175
+
176
+ export function moveGenerated(relativeImports: boolean) {
177
+ new MoveFiles("src/ent/**/generated/**/**.ts").move();
178
+ new MoveFiles("src/graphql/**/generated/**/**.ts").move();
179
+
180
+ transform(
181
+ new TransformImports("src/ent/**/*.ts", "src/ent/**/*.ts", relativeImports),
182
+ );
183
+ transform(
184
+ new TransformImports(
185
+ "src/graphql/**/*.ts",
186
+ "src/graphql/**/*.ts",
187
+ relativeImports,
188
+ true,
189
+ ),
190
+ );
191
+ }
@@ -0,0 +1,226 @@
1
+ import * as glob from "glob";
2
+ import ts from "typescript";
3
+ import { execSync } from "child_process";
4
+ import * as fs from "fs";
5
+ import { getImportInfo, transformImport } from "./ast";
6
+ import { createSourceFile, getTargetFromCurrentDir } from "./compilerOptions";
7
+
8
+ interface TraverseChildResponse {
9
+ // keep this node, nothing to do here
10
+ node?: ts.Node;
11
+
12
+ // main change we're doing here, transforming file
13
+ rawString?: string;
14
+
15
+ // if this is true, overwrite the file
16
+ traversed?: boolean;
17
+
18
+ // if set, these imports will be added for sure regardless of if path is there
19
+ imports?: Map<string, string[]>;
20
+
21
+ removeImports?: string[];
22
+
23
+ allowSeenImportsAdded?: boolean;
24
+ }
25
+
26
+ interface NodeInfo {
27
+ node?: ts.Node;
28
+ rawString?: string;
29
+ }
30
+
31
+ export interface TransformFile {
32
+ glob: string;
33
+
34
+ globOptions?: glob.GlobOptions;
35
+
36
+ preprocessFile?: (
37
+ contents: string,
38
+ file: string,
39
+ sourceFile: ts.SourceFile,
40
+ ) => boolean;
41
+
42
+ traverseChild(
43
+ sourceFile: ts.SourceFile,
44
+ contents: string,
45
+ file: string,
46
+ node: ts.Node,
47
+ ): TraverseChildResponse | undefined;
48
+
49
+ filter?(files: string[]): string[];
50
+
51
+ fileToWrite?(file: string): string;
52
+
53
+ postProcess?(file: string): void;
54
+
55
+ prettierGlob?: string;
56
+ }
57
+
58
+ function normalizePath(p: string) {
59
+ if (p.endsWith("..")) {
60
+ return p + "/";
61
+ }
62
+ return p;
63
+ }
64
+
65
+ export function transform(transform: TransformFile) {
66
+ let files = glob.sync(transform.glob, transform.globOptions ?? {});
67
+ const target = getTargetFromCurrentDir();
68
+ if (transform.filter) {
69
+ const f2 = files.map((f) => (typeof f === "string" ? f : f.path));
70
+ files = transform.filter(f2);
71
+ }
72
+
73
+ files.forEach((file) => {
74
+ let { contents, sourceFile } = createSourceFile(target, file);
75
+
76
+ let nodes: NodeInfo[] = [];
77
+
78
+ let imports: Map<string, string[]> = new Map();
79
+ let removeImports: string[] = [];
80
+ let traversed = false;
81
+ let allowSeenImportsAdded = false;
82
+
83
+ let seenImports: Map<string, boolean> = new Map();
84
+ ts.forEachChild(sourceFile, function (node: ts.Node) {
85
+ if (ts.isImportDeclaration(node)) {
86
+ const imp = getImportInfo(node, sourceFile);
87
+ if (imp) {
88
+ imp.imports.forEach((v) => {
89
+ v = v.trim();
90
+ v && seenImports.set(v, true);
91
+ });
92
+ }
93
+ }
94
+ const ret = transform.traverseChild(sourceFile, contents, file, node);
95
+ if (!ret) {
96
+ return;
97
+ }
98
+ if (ret.node || ret.rawString) {
99
+ nodes.push(ret);
100
+ }
101
+
102
+ if (ret.imports) {
103
+ for (const [k, v] of ret.imports) {
104
+ imports.set(k, v);
105
+ }
106
+ }
107
+ if (ret.traversed) {
108
+ traversed = ret.traversed;
109
+ }
110
+
111
+ if (ret.removeImports?.length) {
112
+ removeImports.push(...ret.removeImports);
113
+ }
114
+
115
+ if (ret.allowSeenImportsAdded) {
116
+ allowSeenImportsAdded = ret.allowSeenImportsAdded;
117
+ }
118
+ });
119
+
120
+ if (!traversed) {
121
+ return;
122
+ }
123
+
124
+ let newContents = "";
125
+ let afterProcessed = false;
126
+
127
+ let seen = new Map<string, boolean>();
128
+
129
+ const processAfterImport = () => {
130
+ // do this for the first non-import node we see
131
+ // we want to add new imports to end of imports and there's an assumption that imports are ordered
132
+ // at top of file
133
+
134
+ // TODO account for placement after first comment
135
+ if (!afterProcessed) {
136
+ for (const [imp, list] of imports) {
137
+ if (seen.has(imp)) {
138
+ continue;
139
+ }
140
+ // this says only add things you haven't seen
141
+ // we want to add something we've seen in this case
142
+ let final = list;
143
+ if (!allowSeenImportsAdded) {
144
+ final = list.filter((v) => !seenImports.has(v));
145
+ }
146
+ if (final.length) {
147
+ newContents += `\nimport { ${final.join(", ")} } from "${imp}";\n`;
148
+ }
149
+ }
150
+ afterProcessed = true;
151
+ }
152
+ };
153
+
154
+ for (const node of nodes) {
155
+ if (node.node) {
156
+ if (ts.isImportDeclaration(node.node)) {
157
+ const impInfo = getImportInfo(node.node, sourceFile);
158
+ // console.debug(impInfo);
159
+ if (impInfo) {
160
+ const impPath = normalizePath(impInfo.importPath);
161
+
162
+ const list = imports.get(impPath);
163
+ // path exists, we care about it
164
+ if (list !== undefined) {
165
+ let transformed = transformImport(
166
+ contents,
167
+ node.node,
168
+ sourceFile,
169
+ {
170
+ // if we've done this path before, don't try and add
171
+ // but still try and do any removals since we don't know which of the imports
172
+ // has it
173
+ newImports: seen.has(impPath) ? undefined : list,
174
+ removeImports,
175
+ // don't use normalized path here, we wanna use the path that's in code...
176
+ transformPath: impInfo.importPath,
177
+ },
178
+ );
179
+ if (transformed) {
180
+ newContents += transformed;
181
+ seen.set(impPath, true);
182
+ continue;
183
+ }
184
+ }
185
+ }
186
+ } else {
187
+ if (
188
+ !ts.isExportDeclaration(node.node) &&
189
+ !isRequireStatement(node.node, sourceFile)
190
+ ) {
191
+ processAfterImport();
192
+ }
193
+ }
194
+ newContents += node.node.getFullText(sourceFile);
195
+ } else if (node.rawString) {
196
+ processAfterImport();
197
+ newContents += node.rawString;
198
+ } else {
199
+ throw new Error(`malformed node with no node or rawString`);
200
+ }
201
+ }
202
+
203
+ let writeFile = file;
204
+ if (transform.fileToWrite) {
205
+ writeFile = transform.fileToWrite(file);
206
+ }
207
+ fs.writeFileSync(writeFile, newContents);
208
+
209
+ if (transform.postProcess) {
210
+ transform.postProcess(file);
211
+ }
212
+ });
213
+
214
+ if (transform.prettierGlob) {
215
+ execSync(`prettier ${transform.prettierGlob} --write`);
216
+ }
217
+ }
218
+
219
+ function isRequireStatement(node: ts.Node, sourceFile: ts.SourceFile) {
220
+ if (node.kind !== ts.SyntaxKind.VariableStatement) {
221
+ return false;
222
+ }
223
+ const v = node as ts.VariableStatement;
224
+ const text = v.declarationList.declarations[0].getFullText(sourceFile);
225
+ return text.includes("require(");
226
+ }
@@ -0,0 +1,224 @@
1
+ import ts from "typescript";
2
+ import {
3
+ ClassInfo,
4
+ getClassInfo,
5
+ getImportInfo,
6
+ getPreText,
7
+ isRelativeGeneratedImport,
8
+ isSrcGeneratedImport,
9
+ transformRelative,
10
+ customInfo,
11
+ } from "../tsc/ast";
12
+ import { Action } from "../action";
13
+ import { LoggedOutViewer } from "../core/viewer";
14
+ import * as path from "path";
15
+ import { Data } from "../core/base";
16
+ import { TransformFile } from "./transform";
17
+ import { snakeCase } from "snake-case";
18
+
19
+ interface baseFileInfo {
20
+ input: string;
21
+ importPath: string;
22
+ }
23
+
24
+ // returns input and importPath
25
+ function getBaseFileInfo(
26
+ file: string,
27
+ classInfo: ClassInfo,
28
+ sourceFile: ts.SourceFile,
29
+ ): baseFileInfo | null {
30
+ // @ts-ignore
31
+ const importStatements: ts.ImportDeclaration[] = sourceFile.statements.filter(
32
+ (stmt) => ts.isImportDeclaration(stmt),
33
+ );
34
+
35
+ for (const imp of importStatements) {
36
+ const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
37
+
38
+ if (
39
+ isSrcGeneratedImport(imp, sourceFile) ||
40
+ isRelativeGeneratedImport(imp, sourceFile)
41
+ ) {
42
+ // base file and we're importing from it
43
+ // e.g. in create_user_action, we're importing from create_user_action_base
44
+ if (path.basename(file).slice(0, -3) + "_base" !== path.basename(text)) {
45
+ continue;
46
+ }
47
+
48
+ const impInfo = getImportInfo(imp, sourceFile);
49
+ if (!impInfo) {
50
+ continue;
51
+ }
52
+
53
+ let inputs = impInfo.imports
54
+ .filter((imp) => imp.trim() && imp.endsWith("Input"))
55
+ .map((v) => v.trim());
56
+ if (inputs.length === 1) {
57
+ return {
58
+ input: inputs[0],
59
+ importPath: impInfo.importPath,
60
+ };
61
+ }
62
+ if (inputs.length && classInfo.name.endsWith("Action")) {
63
+ const prefix = classInfo.name.slice(0, classInfo.name.length - 6);
64
+ inputs = inputs.filter(
65
+ (imp) => imp.slice(0, imp.length - 5) === prefix,
66
+ );
67
+ if (inputs.length === 1) {
68
+ return {
69
+ input: inputs[0],
70
+ importPath: impInfo.importPath,
71
+ };
72
+ }
73
+ }
74
+ }
75
+ }
76
+ return null;
77
+ }
78
+
79
+ interface convertReturnInfo {
80
+ text: string;
81
+ method: string;
82
+ interface: string;
83
+ methodType: string;
84
+ }
85
+
86
+ let m: Data = {
87
+ triggers: {
88
+ m: "getTriggers",
89
+ i: "Trigger",
90
+ suffix: "Triggers",
91
+ },
92
+ observers: {
93
+ m: "getObservers",
94
+ i: "Observer",
95
+ suffix: "Observers",
96
+ },
97
+ validators: {
98
+ m: "getValidators",
99
+ i: "Validator",
100
+ suffix: "Validators",
101
+ },
102
+ };
103
+
104
+ function getConversionInfo(
105
+ mm: ts.ClassElement,
106
+ actionName: string,
107
+ ): convertReturnInfo | null {
108
+ if (mm.kind !== ts.SyntaxKind.PropertyDeclaration) {
109
+ return null;
110
+ }
111
+ const text = (mm.name as ts.Identifier).escapedText as string;
112
+ const v = m[text];
113
+ if (v === undefined) {
114
+ return null;
115
+ }
116
+ return {
117
+ text,
118
+ method: v.m,
119
+ interface: v.i,
120
+ // CreateFooActionTriggers etc
121
+ methodType: actionName + v.suffix,
122
+ };
123
+ }
124
+
125
+ export class TransformAction implements TransformFile {
126
+ glob = "src/ent/**/actions/**/*_action.ts";
127
+
128
+ prettierGlob = "src/ent/**/actions/**.ts";
129
+
130
+ constructor(private customInfo: customInfo) {}
131
+
132
+ traverseChild(
133
+ sourceFile: ts.SourceFile,
134
+ contents: string,
135
+ file: string,
136
+ node: ts.Node,
137
+ ) {
138
+ if (!ts.isClassDeclaration(node) || !node.heritageClauses) {
139
+ return { node };
140
+ }
141
+
142
+ let classInfo = getClassInfo(contents, sourceFile, node);
143
+ // only do classes
144
+ if (!classInfo || !classInfo.default) {
145
+ return;
146
+ }
147
+
148
+ // require action
149
+ const p = require(path.join(process.cwd(), "./" + file.slice(0, -3)));
150
+ const action: Action<any, any> = new p.default(new LoggedOutViewer(), {});
151
+ const actionName = action.constructor.name;
152
+
153
+ const builder = action.builder.constructor.name;
154
+ const nodeName = action.builder.ent.name;
155
+ const viewer = this.customInfo.viewerInfo.name;
156
+
157
+ const baseInfo = getBaseFileInfo(file, classInfo, sourceFile);
158
+ if (!baseInfo) {
159
+ return;
160
+ }
161
+
162
+ let klassContents = "";
163
+
164
+ let traversed = false;
165
+ let newImports: string[] = [];
166
+ for (const mm of node.members) {
167
+ const conv = getConversionInfo(mm, actionName);
168
+ if (conv !== null) {
169
+ const property = mm as ts.PropertyDeclaration;
170
+ // if invalid, bounce
171
+ if (!property.initializer) {
172
+ return;
173
+ }
174
+
175
+ traversed = true;
176
+
177
+ const pp = property.initializer.getFullText(sourceFile).trim();
178
+ const code = `${conv.method}(): ${conv.methodType} {
179
+ return ${pp}
180
+ }`;
181
+ newImports.push(conv.methodType);
182
+ klassContents += getPreText(contents, mm, sourceFile) + code;
183
+ } else {
184
+ klassContents += mm.getFullText(sourceFile);
185
+ }
186
+ }
187
+
188
+ const builderPath = `src/ent/generated/${snakeCase(
189
+ nodeName,
190
+ )}/actions/${snakeCase(builder)}`;
191
+
192
+ let imports: Map<string, string[]> = new Map([
193
+ [
194
+ transformRelative(
195
+ file,
196
+ this.customInfo.viewerInfo.path,
197
+ this.customInfo.relativeImports,
198
+ ),
199
+ [viewer],
200
+ ],
201
+ [
202
+ transformRelative(
203
+ file,
204
+ baseInfo.importPath,
205
+ this.customInfo.relativeImports,
206
+ ),
207
+ newImports,
208
+ ],
209
+ [
210
+ transformRelative(file, builderPath, this.customInfo.relativeImports),
211
+ [builder],
212
+ ],
213
+ ]);
214
+
215
+ // wrap comments and transform to export class Foo extends Bar { ${inner} }
216
+ return {
217
+ rawString: classInfo.wrapClassContents(klassContents),
218
+ traversed,
219
+ imports,
220
+ removeImports: ["Trigger", "Observer", "Validator"],
221
+ // not removing FooBuilder incase it's still somehow used in type of inline builders
222
+ };
223
+ }
224
+ }
@@ -0,0 +1,66 @@
1
+ import { PACKAGE } from "../core/const";
2
+ import ts from "typescript";
3
+ import { getClassInfo, getPreText } from "./ast";
4
+ import { TransformFile } from "./transform";
5
+
6
+ function isPrivacyPolicy(mm: ts.ClassElement) {
7
+ return (
8
+ mm.kind === ts.SyntaxKind.PropertyDeclaration &&
9
+ (mm.name as ts.Identifier).escapedText === "privacyPolicy"
10
+ );
11
+ }
12
+
13
+ export class TransformEnt implements TransformFile {
14
+ glob = "src/ent/*.ts";
15
+
16
+ traverseChild(
17
+ sourceFile: ts.SourceFile,
18
+ contents: string,
19
+ file: string,
20
+ node: ts.Node,
21
+ ) {
22
+ if (!ts.isClassDeclaration(node) || !node.heritageClauses) {
23
+ return { node };
24
+ }
25
+
26
+ let classInfo = getClassInfo(contents, sourceFile, node);
27
+ if (!classInfo) {
28
+ return;
29
+ }
30
+ // different class. ignore
31
+ // only do classes which extend a base class e.g. User extends UserBase
32
+ // if different class (e.g. privacy rule), just return it
33
+ if (classInfo.extends !== classInfo.name + "Base") {
34
+ return { node };
35
+ }
36
+
37
+ let klassContents = "";
38
+ let traversed = false;
39
+
40
+ for (const mm of node.members) {
41
+ if (isPrivacyPolicy(mm)) {
42
+ const property = mm as ts.PropertyDeclaration;
43
+ // if invalid privacy policy, bounce
44
+ if (!property.initializer) {
45
+ return;
46
+ }
47
+ const pp = property.initializer.getFullText(sourceFile);
48
+ const code = `getPrivacyPolicy(): PrivacyPolicy<this> {
49
+ return ${pp}
50
+ }`;
51
+ klassContents += getPreText(contents, mm, sourceFile) + code;
52
+ traversed = true;
53
+ } else {
54
+ klassContents += mm.getFullText(sourceFile);
55
+ }
56
+ }
57
+
58
+ return {
59
+ rawString: classInfo.wrapClassContents(klassContents),
60
+ traversed,
61
+ imports: new Map<string, string[]>([[PACKAGE, ["PrivacyPolicy"]]]),
62
+ };
63
+ }
64
+
65
+ prettierGlob = "src/ent/*.ts";
66
+ }