@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,1028 +0,0 @@
1
- import { snakeCase } from "snake-case";
2
- import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
3
- import { Builder, Changeset } from "../action/action";
4
- import { Clause } from "../core/clause";
5
- import { AssocEdgeInput } from "../action/operations";
6
-
7
- export declare type FieldMap = {
8
- [key: string]: Field;
9
- };
10
-
11
- interface FieldInfo {
12
- dbCol: string;
13
- inputKey: string;
14
- }
15
-
16
- export type FieldInfoMap = {
17
- [key: string]: FieldInfo;
18
- };
19
-
20
- export interface GlobalSchema {
21
- // source is ¯\_(ツ)_/¯
22
- // this api works fine for external to int
23
- // internal to external, we need to solve ala polymorphic
24
- // internal to internal, why is this here
25
- edges?: Edge[];
26
-
27
- // e.g. deleted_at for edges
28
- extraEdgeFields?: FieldMap;
29
-
30
- transformEdgeRead?: () => Clause;
31
- transformEdgeWrite?: (
32
- stmt: EdgeUpdateOperation,
33
- ) => TransformedEdgeUpdateOperation | null;
34
-
35
- // for enum and other fields
36
- fields?: FieldMap;
37
- }
38
-
39
- // we may eventually support more properties but for now, minimal field properties
40
- // which affect specific codegen/db/graphql but nothing at runtime
41
- type FieldOverride = Pick<
42
- FieldOptions,
43
- | "nullable"
44
- | "storageKey"
45
- | "serverDefault"
46
- | "unique"
47
- | "hideFromGraphQL"
48
- | "graphqlName"
49
- | "index"
50
- >;
51
-
52
- export type FieldOverrideMap = {
53
- [key: string]: FieldOverride;
54
- };
55
-
56
- // Schema is the base for every schema in typescript
57
- export default interface Schema {
58
- // schema has fields that are unique to each node
59
- fields: FieldMap;
60
-
61
- fieldOverrides?: FieldOverrideMap;
62
-
63
- // optional, can be overriden as needed
64
- tableName?: string;
65
-
66
- // reusable functionality in each schema
67
- patterns?: Pattern[];
68
-
69
- // edges in the schema
70
- edges?: Edge[];
71
- edgeGroups?: AssocEdgeGroup[];
72
-
73
- actions?: Action[];
74
-
75
- // treat the single primary key as enums
76
- // (it's possible to have other values too..)
77
- enumTable?: boolean;
78
-
79
- // data that should be saved in the db corresponding for this table
80
- // keys should map to either field names or storage_key
81
- dbRows?: { [key: string]: any }[];
82
-
83
- // constraints applied to the schema e.g. multi-fkey, multi-column unique keys, join table primary keys etc
84
- constraints?: Constraint[];
85
-
86
- // should this be indexes?
87
- indices?: Index[];
88
-
89
- // hide a node from graphql
90
- // this automatically hides all related actions to it from graphql
91
- // AND hides all edges pointing to it since we can't return this object
92
- hideFromGraphQL?: boolean;
93
-
94
- // indicates that this ent should implement these custom interfaces
95
- customGraphQLInterfaces?: string[];
96
-
97
- // beta feature!
98
- supportUpsert?: boolean;
99
-
100
- // if ent has fields which have privacy policies and this is true, we generate a
101
- // canViewerSeeInfo() function + a graphql field for each field to indicate if it's
102
- // visible to the viewer
103
- showCanViewerSee?: boolean;
104
- // above but for editPrivacyPolicy
105
- showCanViewerEdit?: boolean;
106
- }
107
-
108
- // An AssocEdge is an edge between 2 ids that has a common table/edge format
109
- // columns are
110
- // id1 uuid (or int64),
111
- // id1Type type (enum), TODO
112
- // edgeType (enum?), TODO
113
- // id2 uuid (or int64)
114
- // id2Type (enum), TODO
115
- // time (time without time zone)
116
- // data (string)
117
- // common edge type means we can support all types of common functionality
118
- // across different edges
119
- // we also get 3 types of assocs from the framework: 1-way (favorite), inverse (followers + followees), symmetric (friends)
120
- // default is 1-way
121
- export interface AssocEdge {
122
- // name of the edge e.g. creator, hosts, etc. edge name should be plural except for unique edges
123
- name: string;
124
- // name of schema which edge is pointing to e.g. User, Address
125
- schemaName: string;
126
- // symmetric edge? should we write an edge from id2 -> id1 of the same edgeType?
127
- symmetric?: boolean;
128
- // unique edge. add constraint and enforce that not more than one can be written
129
- unique?: boolean;
130
- // inverse edge. should we write an inverse edge from id2 -> id1 of the inverse edge type
131
- inverseEdge?: InverseAssocEdge;
132
- // optional, can be overriden as needed. if not provided, schema generates one
133
- tableName?: string;
134
- edgeActions?: EdgeAction[];
135
- hideFromGraphQL?: boolean;
136
- // use this instead of the default generated const names
137
- edgeConstName?: string;
138
- }
139
-
140
- // type PickKey<T, K extends keyof T> = Extract<keyof T, K>;
141
- // type EdgeActionOperation = PickKey<
142
- // typeof ActionOperation,
143
- // "AddEdge",
144
- // "RemoveEdge"
145
- // >;
146
-
147
- export interface EdgeAction {
148
- // TODO ideally this only requires AddEdge|RemoveEdge but can't get it to work (yet)
149
- // operation: EdgeActionOperation;
150
- operation: ActionOperation;
151
- // ActionOperation,
152
- // ActionOperation.AddEdge | ActionOperation.RemoveEdge
153
- // >;
154
- actionName?: string;
155
- hideFromGraphQL?: boolean;
156
- graphQLName?: string;
157
- actionOnlyFields?: ActionField[];
158
- // if true, adds under a canViewerDo field on the source Object mapping to graphql name
159
- // of this...
160
- canViewerDo?: boolean | CanViewerDo;
161
- }
162
-
163
- // Information about the inverse edge of an assoc edge
164
- export interface InverseAssocEdge {
165
- // name of the inverse edge
166
- name: string;
167
- // same as in AssocEdge
168
- edgeConstName?: string;
169
- }
170
-
171
- export interface EdgeGroupAction {
172
- // TODO ideally this only requires AddEdge|RemoveEdge but can't get it to work (yet)
173
- // operation: EdgeActionOperation;
174
- operation: ActionOperation.EdgeGroup; // implied and don't put it?
175
- // ActionOperation,
176
- // ActionOperation.AddEdge | ActionOperation.RemoveEdge
177
- // >;
178
- actionName?: string;
179
- hideFromGraphQL?: boolean;
180
- graphQLName?: string;
181
- actionOnlyFields?: ActionField[];
182
- // if true, adds under a canViewerDo field on the source Object mapping to graphql name
183
- // of this...
184
- canViewerDo?: boolean | CanViewerDo;
185
- }
186
-
187
- // interface AssocEdgeNullState {
188
- // name: string;
189
- // fnName: string;
190
- // }
191
-
192
- // AssocEdgeGroup provides a way to group related edges together
193
- // e.g. rsvps and you have an invited, attending, declined edge all together in the same
194
- // table and a way to configure it so that changing one edge also affects the others
195
- export interface AssocEdgeGroup {
196
- name: string;
197
- groupStatusName: string; // e.g. EventRsvpStatus
198
- tableName?: string;
199
- assocEdges: AssocEdge[];
200
- statusEnums?: string[]; // if present, restrict to these instead of all given enums...
201
-
202
- // breaking change!
203
- // if true, assumes the edge group is viewer based e.g. viewer rsvping to an event
204
- // viewer sending a friend request etc.
205
- // if viewer based, a viewer{Foo}() function is added to the source ent to get the viewer status
206
- // to this and cannot check it for another User|Account|et
207
-
208
- // if not viewer based, will generate an API to pass an instance of the other ent to get the status for
209
- viewerBased?: boolean;
210
-
211
- // extraEnums:
212
- // either single item or should be list with way to differentiate btw them...
213
- // nullStates are not part of input, just output...
214
- // make nullStates optional for non-viewer-based edges...
215
- // required for now for viewer based status enums, optional otherwise
216
- nullStates?: string | string[];
217
-
218
- // if more than one nullState. must pass this in
219
- nullStateFn?: string;
220
- // nullStates?: string | AssocEdgeNullState[]; // if the edge doesn't exist, return this instead
221
- /// rest
222
- // edgeAction -> where a setRsvp yes/no is best
223
- edgeAction?: EdgeGroupAction;
224
- }
225
-
226
- // edges we support from the schema
227
- // there are some implied edges that are derived from fields: foreignKeys/fieldEdges
228
- // writing to those fields automatically writes to the defined edges
229
- // TODO other edges such as join tables 3-way id1->id2 (data)
230
- // TODO clean this up with 1-1, 1-many, many-many etc
231
- export type Edge = AssocEdge;
232
-
233
- // replaces DeprecatedImportType
234
- export interface ImportPath {
235
- importPath: string;
236
- import: string;
237
- defaultImport?: boolean;
238
- originalImport?: string;
239
- }
240
-
241
- export interface TransformReadBetaResult {
242
- code: string;
243
- imports: ImportPath[];
244
- }
245
-
246
- // Pattern is reusable functionality that leads to code sharing
247
- // The most commonly used pattern in the ent framework is going to be the Node pattern
248
- // which automatically provides 3 fields to every ent: id, created_at, updated_at
249
- export interface Pattern {
250
- name: string;
251
- fields: FieldMap;
252
- disableMixin?: boolean;
253
- edges?: Edge[];
254
-
255
- // can only have one thing transforming a select
256
- // transform to loader instead?
257
- // we can change generated loader to do this instead of what we're doing here
258
- transformRead?: () => Clause;
259
-
260
- // to avoid circular dependencies in codegen, instead of generated loader code depending on the
261
- // schema, we determine this at codegen time and generate the clause here in the code
262
- // API is subject to change...
263
- // called only if transformRead exists
264
- transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
265
-
266
- transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(
267
- stmt: UpdateOperation<T, TViewer>,
268
- ) => TransformedUpdateOperation<T, TViewer> | null;
269
-
270
- // can only have one pattern in an object which transforms each
271
- // if we do, it throws an Error
272
- // it also simplifies what we call?
273
- // transformsSelect?: boolean;
274
- transformsDelete?: boolean;
275
- transformsInsert?: boolean;
276
- transformsUpdate?: boolean;
277
- }
278
-
279
- // we also want this transformation to exist on a per-action basis
280
- // if it exists on an action, we don't do the global schema transformation
281
-
282
- export enum SQLStatementOperation {
283
- // transform insert e.g. to an update based on whatever logic
284
- Insert = "insert",
285
-
286
- // // transform select e.g. deleted_at. can't change from select to different query type
287
- // // but can change the query
288
- // Select = "select",
289
-
290
- // e.g. change updated value
291
- Update = "update",
292
-
293
- // delete -> update theoretically e.g. deleted_at
294
- Delete = "delete",
295
- }
296
-
297
- export interface EdgeUpdateOperation {
298
- op: SQLStatementOperation;
299
- edge: AssocEdgeInput;
300
- }
301
-
302
- export interface TransformedEdgeUpdateOperation {
303
- op: SQLStatementOperation;
304
-
305
- // data to write to db for this edge
306
- data?: Data;
307
- }
308
-
309
- export interface UpdateOperation<
310
- TEnt extends Ent<TViewer>,
311
- TViewer extends Viewer = Viewer,
312
- > {
313
- // TODO how should this affect builder.operation?
314
- op: SQLStatementOperation;
315
- builder: Builder<TEnt, TViewer, any>;
316
- // input. same input that's passed to Triggers, Observers, Validators. includes action-only fields
317
- input: Data;
318
- // data that'll be saved in the db
319
- data?: Map<string, any>;
320
- }
321
-
322
- export interface TransformedUpdateOperation<
323
- T extends Ent<TViewer>,
324
- TViewer extends Viewer = Viewer,
325
- > {
326
- op: SQLStatementOperation;
327
-
328
- data?: Data;
329
-
330
- // if changing to an update, we want to return the ent
331
- // TODO don't have a way to delete the ent e.g. update -> insert
332
- existingEnt?: T | null;
333
- changeset?(): Promise<Changeset> | Changeset;
334
- }
335
-
336
- // we want --strictNullChecks flag so nullable is used to type graphql, ts, db
337
- // should eventually generate (boolean | null) etc
338
-
339
- // supported db types
340
- export enum DBType {
341
- UUID = "UUID",
342
- Int64ID = "Int64ID", // unsupported right now
343
- Boolean = "Boolean",
344
- Int = "Int",
345
- BigInt = "BigInt",
346
- Float = "Float",
347
- String = "String",
348
- //
349
- Timestamp = "Timestamp",
350
- Timestamptz = "Timestamptz",
351
- JSON = "JSON", //JSON type in the database
352
- JSONB = "JSONB", // JSONB type in the database Postgres
353
- Enum = "Enum", // enum type in the database
354
- StringEnum = "StringEnum", // string type in the database
355
- IntEnum = "IntEnum", // int type in the database
356
-
357
- Date = "Date",
358
- Time = "Time",
359
- Timetz = "Timetz",
360
-
361
- List = "List",
362
- }
363
-
364
- export interface DeprecatedImportType {
365
- path: string; // path to import from. either absolute path e.g. from an npm package or relative path starting at root of code e.g. "src/foo/jsonType"
366
- type: string; // type being imported
367
- // for importPath, import conversion to go
368
- [x: string]: any;
369
- }
370
-
371
- // TODO make this have an async flag and an accessor will be generated
372
- // for it that does this instead of doing in constructor
373
- export interface ConvertType {
374
- path: string;
375
- function: string;
376
- }
377
-
378
- declare type EnumMap = {
379
- [key: string]: string;
380
- };
381
-
382
- declare type IntEnumMap = {
383
- [key: string]: number;
384
- };
385
-
386
- // represents the type of each field
387
- export interface Type {
388
- dbType: DBType; // type in the db
389
- // if DBType is a list, we need this for what list type
390
- // e.g. text[], integer[] in postgres
391
- // For SQLite, we'll just store as text and json encode/decode
392
- listElemType?: Type;
393
- // TODO make these required eventually once we get there
394
- type?: string; // typescript type
395
- graphQLType?: string; // graphql type
396
- values?: string[]; // values e.g. enum values
397
- // TODO need to refactor this into type specific objects instead of killing the top level field like this.
398
- enumMap?: EnumMap; // enumMap e.g. k->v pair for enums
399
- intEnumMap?: IntEnumMap;
400
- deprecatedIntEnumMap?: IntEnumMap;
401
- disableUnknownType?: boolean;
402
- globalType?: string;
403
-
404
- // @deprecated eventually kill this
405
- importType?: DeprecatedImportType;
406
-
407
- // StructType fields
408
- subFields?: FieldMap;
409
-
410
- // UnionType fields. really StructMap but don't want circular dependency...
411
- unionFields?: FieldMap;
412
-
413
- // allow other keys
414
- [x: string]: any;
415
- }
416
-
417
- export interface ForeignKey {
418
- schema: string;
419
- column: string;
420
- name?: string; // optional but if we have multiple foreign keys to the same schema, it becomes required for all but one
421
- // defaults to pluralize(schema) if not provided
422
- disableIndex?: boolean;
423
- // disable generating Builder<Ent> in Builder and Action. helpful
424
- // to simplify the code when it's known that the object here
425
- // would always have been previously created. simplifies validation
426
- disableBuilderType?: boolean;
427
-
428
- // allow other keys
429
- [x: string]: any;
430
- }
431
-
432
- type getLoaderInfoFn = (type: string) => LoaderInfo;
433
-
434
- export interface InverseFieldEdge {
435
- // 1-N if field exists so no need for inverse or symmetric edge. also can't be unique
436
-
437
- // name of the inverse edge
438
- name: string;
439
- // following 3: same as in AssocEdge
440
- edgeConstName?: string;
441
- tableName?: string;
442
- hideFromGraphQL?: boolean;
443
- }
444
-
445
- export interface IndexEdgeOptions {
446
- name: string;
447
- }
448
-
449
- export interface FieldEdge {
450
- schema: string;
451
- // inverseEdge is optional. if present, indicates it maps to an edge in the other schema
452
- // it creates the edge in the other schema if not provided.
453
- // this makes it so that we can define and write the edge from this schema
454
- inverseEdge?: string | InverseFieldEdge;
455
-
456
- // this *intentionally* breaks the mold from what we do for polymorphic edges
457
- // TODO: *also* make that opt-in.
458
- // if provided, we generate a query|connection for this edge.
459
- // name given is used for the name of the query|connection e.g. 'todos_assigned' gives
460
- // queryTodosAssigned() and a 'todos_assigned' field which points to a generated connection.
461
- indexEdge?: IndexEdgeOptions;
462
-
463
- // if enforceSchema. implement the valid type.
464
- // we use getLoaderOptions to do it
465
- enforceSchema?: boolean;
466
- // pass the generated getLoaderInfoFromSchema method in src/ent/generated/loaders.ts
467
- getLoaderInfoFromSchema?: getLoaderInfoFn;
468
- // disable generating Builder<Ent> in Builder and Action. helpful
469
- // to simplify the code when it's known that the object here
470
- // would always have been previously created. simplifies validation
471
- disableBuilderType?: boolean;
472
-
473
- // similar to polymorphic options && assoc edge, if provided and an index query, used to generate the query
474
- // e.g.
475
- //
476
- // author_id: UUIDType({
477
- // index: true,
478
- // fieldEdge: {
479
- // schema: "User",
480
- // edgeConstName: 'AuthorToCommentsMade';
481
- // },
482
- // })
483
- // will generate the following query:
484
- // AuthorToCommentsMadeQuery
485
- //
486
- // instead of the default:
487
- // AuthorToCommentsQuery
488
- //
489
- // The graphql connection and edge will be AuthorToCommentsMadeConnection and AuthorToCommentsMadeEdge
490
- //
491
- edgeConstName?: string;
492
- }
493
-
494
- interface PrivateOptions {
495
- exposeToActions?: boolean;
496
- }
497
-
498
- // FieldOptions are configurable options for fields.
499
- // Can be combined with options for specific field types as neededs
500
- export interface FieldOptions {
501
- // optional modification of fields: nullable/storagekey etc.
502
- nullable?: boolean;
503
- storageKey?: string; // db?
504
- serverDefault?: any;
505
- unique?: boolean;
506
- // hide field from graphql
507
- // does not hide field from actions by default
508
- // if you want to hide it from action, use disableUserGraphQLEditable
509
- // for fields which generate new types e.g. enums, you have to also set
510
- // disableUserGraphQLEditable since it won't compile since it'll try and reference a type
511
- // that doesn't exist
512
- hideFromGraphQL?: boolean;
513
- // private automatically hides from graphql and actions
514
- // but you may want something which is private and visible in actions
515
- // e.g. because you have custom code you want to run in the accessors
516
- private?: boolean | PrivateOptions;
517
- sensitive?: boolean;
518
- graphqlName?: string;
519
- index?: boolean;
520
- foreignKey?: ForeignKey;
521
- fieldEdge?: FieldEdge;
522
- primaryKey?: boolean; // can only have one in a schema. Node provides id as default primary key in a schema
523
-
524
- immutable?: boolean;
525
-
526
- // indicates that this can't be edited by the user
527
- // must have a defaultValueOnCreate() field if set
528
- disableUserEditable?: boolean;
529
- // indicates that this can't be edited by the user in graphql
530
- // must have a defaultValueOnCreate() field if set
531
- // helpful for migrations or fields that we wanna edit in code but not expose to the world
532
- disableUserGraphQLEditable?: boolean;
533
- defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
534
- // shorthand for defaultValueOnCreate: (builder)=>builder.viewer.viewerID;
535
- // exists for common scenario to set a field to the logged in viewerID.
536
- defaultToViewerOnCreate?: boolean;
537
-
538
- // goes along with defaultValueOnEdit
539
- // flag that indicates that if this is the only field being updated,
540
- // don't update the ent, only if other fields are being updated, should this be updated
541
- onlyUpdateIfOtherFieldsBeingSet_BETA?: boolean;
542
- defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
543
- // this is very specific.
544
- // maybe there's a better way to indicate this
545
- // we sometimes have actionOnlyFields when an action creates a child object and we want to skip
546
- // including derived fields in the actionOnlyField created in the parent
547
- derivedWhenEmbedded?: boolean;
548
-
549
- polymorphic?: boolean | PolymorphicOptions;
550
-
551
- // FYI. copied in config.ts
552
- // field can have privacy policy
553
- // there's 2 modes of how this is treated that can be configured in ent.yml because it affects codegen
554
- // 1: evaluate at the time of ent load, we apply the privacy of each object and then apply the privacy of every
555
- // field which has field privacy and set the property to null if the field is not visible to the viewer
556
- // The underlying column is no longer in the `data` field of the object
557
- // 2: generate accessors for the field and all callsites which reference that field will use that.
558
- // the privacy will be evaluated on demand when needed
559
- privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
560
-
561
- // like privacyPolicy, applies to permissions of fields when writing
562
- // if this is set, the check is done in addition to the action's privacy policy
563
- // the action's privacy policy is still used to determine if the action can be run and then this will be an additional
564
- // check on each field in the action that has this property set
565
- editPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
566
-
567
- // by default editPrivacyPolicy is used for create as well but if this exists, this will be used for create and edit will use editPrivacyPolicy
568
- // intentionally ugly so it's clear...
569
- createOnlyOverrideEditPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
570
-
571
- // takes the name of the field and returns any fields which are derived from current field
572
- getDerivedFields?(name: string): FieldMap;
573
-
574
- // to convert the field in some way
575
- // should be the same type e.g. Date to Date
576
- convert?: ConvertType;
577
-
578
- fetchOnDemand?: boolean;
579
-
580
- // if dbOnly, field isn't exposed in ent and graphql
581
- // will still exit in the db and not be removed
582
- // allows keeping the field in the db and avoid data loss if we still want the field for some reason
583
- // won't be queryable automatically though
584
- // can't use deprecated because intEnum uses it
585
- dbOnly?: boolean;
586
-
587
- // allow name for now
588
- [x: string]: any;
589
- }
590
-
591
- export interface PolymorphicOptions {
592
- // optional but if we have multiple Polymorphic fields in the source schema, it becomes required for all but one
593
- // defaults to pluralize(schema) if not provided
594
- // same philosophy as type ForeignKey
595
- name?: string;
596
- // restrict to just these types
597
- types?: string[];
598
- // hide inverse type from graphql
599
- hideFromInverseGraphQL?: boolean;
600
- // disable generating Builder<Ent> in Builder and Action. helpful
601
- // to simplify the code when it's known that the object here
602
- // would always have been previously created. simplifies validation
603
- disableBuilderType?: boolean;
604
- // serverDefault for derived polymorphic field
605
- // TODO rename this. it's not clear...
606
- serverDefault?: any;
607
-
608
- // similar to assoc edge, if provided and an index query, used to generate the query
609
- // e.g.
610
- //
611
- // author_id: UUIDType({
612
- // index: true,
613
- // polymorphic: {
614
- // types: ['User', 'Account'],
615
- // edgeConstName: 'AuthorToCommentsMade';
616
- // },
617
- // })
618
- // will generate the following 3 queries:
619
- // AuthorToCommentsMadeQuery
620
- // UserAuthorToCommentsMadeQuery
621
- // AccountAuthorToCommentsMadeQuery
622
- //
623
- // instead of the default:
624
- // AuthorToCommentsQuery
625
- // UserAuthorToCommentsQuery
626
- // AccountAuthorToCommentsQuery
627
- //
628
- // The graphql connection and edge will be AuthorToCommentsMadeConnection and AuthorToCommentsMadeEdge
629
- edgeConstName?: string;
630
- }
631
-
632
- // Field interface that each Field needs to support
633
- export interface Field extends FieldOptions {
634
- // type of field. db, typescript, graphql types encoded in here
635
- type: Type;
636
-
637
- // optional valid and format to validate and format before storing
638
- // editedFields, data added to valid is useful for start_time, end_time comparisons too
639
- valid?(val: any): Promise<boolean> | boolean;
640
-
641
- // validate if a field can be nullable based on other fields
642
- // validate field based on other fields
643
- // have to be careful that there's no circular dependencies btw fields
644
- // which needs this
645
- // can be used to validate if a field can be nullable based on other fields
646
- // used for polymorphic and maybe eventually other fields
647
- validateWithFullData?(
648
- val: any,
649
- builder: Builder<any>,
650
- ): boolean | Promise<boolean>;
651
-
652
- // optional second param which if passed and true indicates that this is a nested object
653
- // and should only format children and not format lists or objects
654
- format?(val: any, nested?: boolean): any;
655
-
656
- logValue(val: any): any;
657
- }
658
-
659
- export interface SchemaConstructor {
660
- new (): Schema;
661
- }
662
-
663
- export type SchemaInputType = Schema | SchemaConstructor;
664
-
665
- function isSchema(value: SchemaInputType): value is Schema {
666
- return (value as Schema).fields !== undefined;
667
- }
668
-
669
- export function getSchema(value: SchemaInputType): Schema {
670
- if (isSchema(value)) {
671
- return value;
672
- } else {
673
- return new value();
674
- }
675
- }
676
-
677
- export function getFields(value: SchemaInputType): Map<string, Field> {
678
- const schema = getSchema(value);
679
- function addFields(fields: FieldMap) {
680
- for (const name in fields) {
681
- const field = fields[name];
682
- if (field.dbOnly) {
683
- continue;
684
- }
685
- if (field.getDerivedFields !== undefined) {
686
- addFields(field.getDerivedFields(name));
687
- }
688
- m.set(name, field);
689
- }
690
- }
691
-
692
- let m = new Map();
693
- if (schema.patterns) {
694
- for (const pattern of schema.patterns) {
695
- addFields(pattern.fields);
696
- }
697
- }
698
-
699
- addFields(schema.fields);
700
-
701
- return m;
702
- }
703
-
704
- /**
705
- * @deprecated should only be used by tests
706
- */
707
- export function getStorageKey(field: Field, fieldName: string): string {
708
- return field.storageKey || snakeCase(fieldName);
709
- }
710
-
711
- // returns a mapping of storage key to field privacy
712
- export function getFieldsWithPrivacy(
713
- value: SchemaInputType,
714
- fieldInfoMap: FieldInfoMap,
715
- ): Map<string, PrivacyPolicy> {
716
- return getFieldsWithPrivacyImpl(value, fieldInfoMap, ["privacyPolicy"]);
717
- }
718
-
719
- export function getFieldsWithEditPrivacy(
720
- value: SchemaInputType,
721
- fieldInfoMap: FieldInfoMap,
722
- ): Map<string, PrivacyPolicy> {
723
- return getFieldsWithPrivacyImpl(value, fieldInfoMap, ["editPrivacyPolicy"]);
724
- }
725
-
726
- export function getFieldsForCreateAction(
727
- value: SchemaInputType,
728
- fieldInfoMap: FieldInfoMap,
729
- ): Map<string, PrivacyPolicy> {
730
- return getFieldsWithPrivacyImpl(value, fieldInfoMap, [
731
- "createOnlyOverrideEditPrivacyPolicy",
732
- "editPrivacyPolicy",
733
- ]);
734
- }
735
-
736
- type policy =
737
- | "privacyPolicy"
738
- | "editPrivacyPolicy"
739
- | "createOnlyOverrideEditPrivacyPolicy";
740
-
741
- function getFieldsWithPrivacyImpl(
742
- value: SchemaInputType,
743
- fieldInfoMap: FieldInfoMap,
744
- keys: policy[],
745
- ): Map<string, PrivacyPolicy> {
746
- const schema = getSchema(value);
747
- function addFields(fields: FieldMap) {
748
- for (const name in fields) {
749
- const field = fields[name];
750
- if (field.dbOnly) {
751
- continue;
752
- }
753
- if (field.getDerivedFields !== undefined) {
754
- addFields(field.getDerivedFields(name));
755
- }
756
- for (const key of keys) {
757
- let privacyPolicy = field[key];
758
- if (privacyPolicy) {
759
- if (typeof privacyPolicy === "function") {
760
- privacyPolicy = privacyPolicy();
761
- }
762
- const info = fieldInfoMap[name];
763
- if (!info) {
764
- throw new Error(`field with name ${name} not passed in fieldMap`);
765
- }
766
- m.set(info.dbCol, privacyPolicy);
767
- break;
768
- }
769
- }
770
- }
771
- }
772
-
773
- let m = new Map<string, PrivacyPolicy>();
774
- if (schema.patterns) {
775
- for (const pattern of schema.patterns) {
776
- addFields(pattern.fields);
777
- }
778
- }
779
- addFields(schema.fields);
780
-
781
- return m;
782
- }
783
-
784
- export function getTransformedReadClause(
785
- value: SchemaInputType,
786
- ): Clause | undefined {
787
- const schema = getSchema(value);
788
- if (!schema.patterns) {
789
- return;
790
- }
791
- for (const p of schema.patterns) {
792
- // e.g. discarded_at, deleted_at, etc
793
- if (p.transformRead) {
794
- // return clause.Eq('deleted_at', null);
795
- return p.transformRead();
796
- }
797
- }
798
-
799
- return;
800
- }
801
-
802
- interface objectLoaderOptions {
803
- clause?: () => Clause | undefined;
804
- instanceKey?: string;
805
- }
806
-
807
- // would like to avoid calling this so that itwe don't run into circular dependencies
808
- // but the fact that it returns a clause makes it hard since we don't control the patterns...
809
- // we can make each clause return a format that can be extrapolated and used in codegen...
810
-
811
- export function getObjectLoaderProperties(
812
- value: SchemaInputType,
813
- tableName: string,
814
- ): objectLoaderOptions | undefined {
815
- return {
816
- clause: () => getTransformedReadClause(value),
817
- instanceKey: `${tableName}:transformedReadClause`,
818
- };
819
- }
820
-
821
- export function getTransformedUpdateOp<
822
- TEnt extends Ent<TViewer>,
823
- TViewer extends Viewer,
824
- >(
825
- value: SchemaInputType,
826
- stmt: UpdateOperation<TEnt, TViewer>,
827
- ): TransformedUpdateOperation<TEnt> | null {
828
- const schema = getSchema(value);
829
- if (!schema.patterns) {
830
- return null;
831
- }
832
- for (const p of schema.patterns) {
833
- if (p.transformWrite) {
834
- return p.transformWrite(stmt);
835
- }
836
- }
837
- return null;
838
- }
839
-
840
- // this maps to ActionOperation in ent/action.go
841
- export enum ActionOperation {
842
- // Create generates a create action for the ent. If no fields are provided, uses all fields
843
- // on the ent. Doesn't include private fields if no fields are provided.
844
- Create = 1,
845
- // Edit generates an edit action for the ent. If no fields are provided, uses all fields
846
- // on the ent. Can have multiple EditActions with different fields provided. Doesn't include
847
- // private fields if no fields are provided.
848
- Edit = 2,
849
- // Delete generates a delete action for the ent.
850
- Delete = 4,
851
- // Mutations is a shortcut to generate create, edit, and delete actions for an ent
852
- // Can be used to boostrap ents or for simple ents where the granularity of actions is overkill
853
- // Provides CUD of CRUD. Can be the default for most ents. Should rarely be used for the `User` or `Account` ent
854
- Mutations = 8,
855
- // AddEdge is used to provide the ability to add an edge in an AssociationEdge.
856
- AddEdge = 16,
857
- // RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
858
- RemoveEdge = 32,
859
- // EdgeGroup is used to provide the ability to edit an edge group in an AssociationEdgeGroup.
860
- // if you want to clear this edge group e.g. any set edge with id1 and id2,
861
- // you should create a custom action that takes the id as an action only field,
862
- // and then calls `clearEdgeTypeInGroup` in a trigger to clear
863
- EdgeGroup = 64,
864
- }
865
-
866
- type actionFieldType =
867
- | "ID"
868
- | "Boolean"
869
- | "Int"
870
- | "Float"
871
- | "String"
872
- | "Time"
873
- | "JSON"
874
- | "Object";
875
- // TODO...
876
- // | Array<actionFieldType>;
877
-
878
- type NullableListOptions = "contents" | "contentsAndList";
879
-
880
- export interface ActionField {
881
- name: string;
882
- // Type with no db component
883
- // currently a subset of DBType. could be expanded in the future
884
- type: actionFieldType;
885
- // TODO can support overriding later but for now, this is fine
886
- nullable?: boolean | NullableListOptions;
887
- // optional field that can't be set to null
888
- optional?: boolean;
889
- // list of something
890
- list?: boolean;
891
- actionName?: string; // take the fields of this action and add them as this. only works with type "Object"
892
-
893
- // if actionName is provided, exclude the following fields from being embedded
894
- // either because they can be derived or optional and don't need it
895
- // no validation on what can be excluded is done. things will eventually fail if done incorrectly
896
- excludedFields?: string[];
897
-
898
- // hide this param from graphql. should clearly be nullable for this to make sense
899
- hideFromGraphQL?: boolean;
900
-
901
- // allow other keys
902
- [x: string]: any;
903
- }
904
-
905
- // provides a way to configure the actions generated for the ent
906
- export interface Action {
907
- operation: ActionOperation;
908
- fields?: string[];
909
- actionName?: string;
910
- inputName?: string;
911
- graphQLName?: string;
912
- hideFromGraphQL?: boolean;
913
-
914
- // only allowed for actionOnlyField
915
- actionOnlyFields?: ActionField[];
916
-
917
- // beta. may be removed in the future
918
- // https://github.com/lolopinto/ent/issues/570
919
- // allows changing default behavior e.g. making an optional field required
920
- // or excluding a field so as to not put in fields
921
- excludedFields?: string[];
922
- // NB: optionalFields still requires field in list of fields
923
- optionalFields?: string[];
924
- // NB: requiredFields still requires field in list of fields
925
- requiredFields?: string[];
926
- noFields?: boolean;
927
-
928
- // if true, adds under a canViewerDo field on the source Object mapping to graphql name
929
- // of this...
930
- canViewerDo?: boolean | CanViewerDo;
931
-
932
- // allow other keys
933
- [x: string]: any;
934
- }
935
-
936
- export interface CanViewerDo {
937
- addAllFields?: boolean;
938
- inputFields?: string[]; // need x fields for can ViewerDo
939
- }
940
-
941
- // sentinel that indicates an action has no fields
942
- // should be the only field in an action
943
- // required to differentiate against default value of no fields being set to indicate
944
- // all fields in a create/edit mutation
945
- export const NoFields = "__NO_FIELDS__";
946
-
947
- export function requiredField(field: string) {
948
- return `__required__.${field}.__required__`;
949
- }
950
-
951
- export function optionalField(field: string) {
952
- return `__optional__.${field}.__optional__`;
953
- }
954
-
955
- // no nullable constraint here since simple enough it's just part of the field
956
- export interface Constraint {
957
- name: string;
958
- type: ConstraintType;
959
- columns: string[];
960
- fkey?: ForeignKeyInfo;
961
- condition?: string; // only applies in check constraint
962
-
963
- // allow other keys
964
- [x: string]: any;
965
- }
966
-
967
- export interface FullTextWeight {
968
- // can have multiple columns with the same weight so we allow configuring this way
969
- A?: string[];
970
- B?: string[];
971
- C?: string[];
972
- D?: string[];
973
- }
974
-
975
- // use coalesce for all generated
976
- export interface FullText {
977
- // create a generated computed stored text column for this named XXX
978
- // https://www.postgresql.org/docs/current/ddl-generated-columns.html
979
- // postgres 12+
980
- generatedColumnName?: string;
981
- // TODO full list
982
- // simple is practical for names
983
- // rename to search config
984
- // may eventually need different languages depending on the column
985
- language?: "english" | "french" | "german" | "simple";
986
- // search config lang column
987
- languageColumn?: string;
988
- // gin is default
989
- indexType?: "gin" | "gist";
990
-
991
- // to simplify: we only allow weights when there's a generated column so that rank is easiest ts_rank(col, ...)
992
- weights?: FullTextWeight;
993
-
994
- // allow other keys
995
- [x: string]: any;
996
- }
997
-
998
- export interface Index {
999
- name: string;
1000
- columns: string[];
1001
- unique?: boolean; // can also create a unique constraint this way because why not...
1002
- fulltext?: FullText;
1003
- // TODO support gist soon...
1004
- // need operator class too
1005
- // TODO https://github.com/lolopinto/ent/issues/1029
1006
- indexType?: "gin" | "btree";
1007
-
1008
- // allow other keys
1009
- [x: string]: any;
1010
- }
1011
-
1012
- export interface ForeignKeyInfo {
1013
- tableName: string;
1014
- ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
1015
- columns: string[];
1016
- // no on update, match full etc
1017
-
1018
- // allow other keys
1019
- [x: string]: any;
1020
- }
1021
-
1022
- export enum ConstraintType {
1023
- PrimaryKey = "primary",
1024
- ForeignKey = "foreign",
1025
- Unique = "unique",
1026
- Check = "check",
1027
- // index not a constraint and will be its own indices field
1028
- }