@snowtop/ent 0.1.0-alpha15 → 0.1.0-alpha151

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 (171) hide show
  1. package/action/action.d.ts +27 -16
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +16 -3
  4. package/action/executor.js +90 -23
  5. package/action/experimental_action.d.ts +25 -16
  6. package/action/experimental_action.js +35 -9
  7. package/action/index.d.ts +3 -1
  8. package/action/index.js +7 -1
  9. package/action/operations.d.ts +125 -0
  10. package/action/operations.js +684 -0
  11. package/action/orchestrator.d.ts +38 -12
  12. package/action/orchestrator.js +427 -102
  13. package/action/relative_value.d.ts +47 -0
  14. package/action/relative_value.js +125 -0
  15. package/action/transaction.d.ts +10 -0
  16. package/action/transaction.js +23 -0
  17. package/auth/auth.d.ts +1 -1
  18. package/core/base.d.ts +52 -21
  19. package/core/base.js +7 -1
  20. package/core/clause.d.ts +95 -40
  21. package/core/clause.js +395 -64
  22. package/core/config.d.ts +15 -1
  23. package/core/config.js +10 -1
  24. package/core/const.d.ts +3 -0
  25. package/core/const.js +6 -0
  26. package/core/context.d.ts +4 -2
  27. package/core/context.js +20 -2
  28. package/core/convert.d.ts +1 -1
  29. package/core/date.js +1 -5
  30. package/core/db.d.ts +12 -8
  31. package/core/db.js +18 -8
  32. package/core/ent.d.ts +68 -94
  33. package/core/ent.js +538 -587
  34. package/core/global_schema.d.ts +7 -0
  35. package/core/global_schema.js +51 -0
  36. package/core/loaders/assoc_count_loader.d.ts +1 -0
  37. package/core/loaders/assoc_count_loader.js +10 -2
  38. package/core/loaders/assoc_edge_loader.d.ts +1 -1
  39. package/core/loaders/assoc_edge_loader.js +10 -13
  40. package/core/loaders/index.d.ts +1 -1
  41. package/core/loaders/index.js +1 -3
  42. package/core/loaders/index_loader.d.ts +3 -3
  43. package/core/loaders/loader.d.ts +2 -2
  44. package/core/loaders/loader.js +5 -5
  45. package/core/loaders/object_loader.d.ts +30 -9
  46. package/core/loaders/object_loader.js +225 -78
  47. package/core/loaders/query_loader.d.ts +6 -12
  48. package/core/loaders/query_loader.js +54 -13
  49. package/core/loaders/raw_count_loader.d.ts +1 -0
  50. package/core/loaders/raw_count_loader.js +7 -2
  51. package/core/logger.d.ts +1 -1
  52. package/core/logger.js +1 -0
  53. package/core/privacy.d.ts +7 -6
  54. package/core/privacy.js +21 -25
  55. package/core/query/assoc_query.d.ts +3 -2
  56. package/core/query/assoc_query.js +9 -1
  57. package/core/query/custom_clause_query.d.ts +27 -0
  58. package/core/query/custom_clause_query.js +88 -0
  59. package/core/query/custom_query.d.ts +17 -2
  60. package/core/query/custom_query.js +88 -13
  61. package/core/query/index.d.ts +1 -0
  62. package/core/query/index.js +3 -1
  63. package/core/query/query.d.ts +15 -3
  64. package/core/query/query.js +128 -53
  65. package/core/query/shared_assoc_test.d.ts +2 -1
  66. package/core/query/shared_assoc_test.js +44 -54
  67. package/core/query/shared_test.d.ts +8 -1
  68. package/core/query/shared_test.js +532 -236
  69. package/core/viewer.d.ts +2 -0
  70. package/core/viewer.js +3 -1
  71. package/graphql/graphql.d.ts +52 -19
  72. package/graphql/graphql.js +174 -136
  73. package/graphql/graphql_field_helpers.d.ts +7 -1
  74. package/graphql/graphql_field_helpers.js +21 -1
  75. package/graphql/index.d.ts +2 -2
  76. package/graphql/index.js +3 -5
  77. package/graphql/query/connection_type.d.ts +9 -9
  78. package/graphql/query/shared_assoc_test.js +1 -1
  79. package/graphql/query/shared_edge_connection.js +1 -19
  80. package/graphql/scalars/orderby_direction.d.ts +2 -0
  81. package/graphql/scalars/orderby_direction.js +15 -0
  82. package/imports/dataz/example1/_auth.js +128 -47
  83. package/imports/dataz/example1/_viewer.js +87 -39
  84. package/imports/index.d.ts +7 -2
  85. package/imports/index.js +20 -5
  86. package/index.d.ts +18 -5
  87. package/index.js +30 -10
  88. package/package.json +18 -17
  89. package/parse_schema/parse.d.ts +31 -9
  90. package/parse_schema/parse.js +179 -32
  91. package/schema/base_schema.d.ts +13 -3
  92. package/schema/base_schema.js +13 -0
  93. package/schema/field.d.ts +78 -21
  94. package/schema/field.js +231 -71
  95. package/schema/index.d.ts +2 -2
  96. package/schema/index.js +7 -2
  97. package/schema/json_field.d.ts +16 -4
  98. package/schema/json_field.js +32 -2
  99. package/schema/schema.d.ts +109 -20
  100. package/schema/schema.js +42 -53
  101. package/schema/struct_field.d.ts +15 -3
  102. package/schema/struct_field.js +117 -22
  103. package/schema/union_field.d.ts +1 -1
  104. package/scripts/custom_compiler.js +12 -8
  105. package/scripts/custom_graphql.js +145 -34
  106. package/scripts/migrate_v0.1.js +36 -0
  107. package/scripts/move_types.js +120 -0
  108. package/scripts/read_schema.js +22 -7
  109. package/testutils/action/complex_schemas.d.ts +69 -0
  110. package/testutils/action/complex_schemas.js +405 -0
  111. package/testutils/builder.d.ts +39 -43
  112. package/testutils/builder.js +75 -49
  113. package/testutils/db/fixture.d.ts +10 -0
  114. package/testutils/db/fixture.js +26 -0
  115. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +32 -8
  116. package/testutils/db/{test_db.js → temp_db.js} +244 -48
  117. package/testutils/db/value.d.ts +7 -0
  118. package/testutils/db/value.js +251 -0
  119. package/testutils/db_mock.d.ts +16 -4
  120. package/testutils/db_mock.js +52 -9
  121. package/testutils/db_time_zone.d.ts +4 -0
  122. package/testutils/db_time_zone.js +41 -0
  123. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  124. package/testutils/ent-graphql-tests/index.js +56 -26
  125. package/testutils/fake_comms.js +1 -1
  126. package/testutils/fake_data/const.d.ts +2 -1
  127. package/testutils/fake_data/const.js +3 -0
  128. package/testutils/fake_data/fake_contact.d.ts +7 -3
  129. package/testutils/fake_data/fake_contact.js +13 -7
  130. package/testutils/fake_data/fake_event.d.ts +4 -1
  131. package/testutils/fake_data/fake_event.js +7 -6
  132. package/testutils/fake_data/fake_tag.d.ts +36 -0
  133. package/testutils/fake_data/fake_tag.js +89 -0
  134. package/testutils/fake_data/fake_user.d.ts +8 -5
  135. package/testutils/fake_data/fake_user.js +16 -15
  136. package/testutils/fake_data/index.js +5 -1
  137. package/testutils/fake_data/internal.d.ts +2 -0
  138. package/testutils/fake_data/internal.js +7 -1
  139. package/testutils/fake_data/tag_query.d.ts +13 -0
  140. package/testutils/fake_data/tag_query.js +43 -0
  141. package/testutils/fake_data/test_helpers.d.ts +11 -4
  142. package/testutils/fake_data/test_helpers.js +29 -13
  143. package/testutils/fake_data/user_query.d.ts +11 -4
  144. package/testutils/fake_data/user_query.js +54 -22
  145. package/testutils/fake_log.js +1 -1
  146. package/testutils/parse_sql.d.ts +6 -0
  147. package/testutils/parse_sql.js +16 -2
  148. package/testutils/test_edge_global_schema.d.ts +15 -0
  149. package/testutils/test_edge_global_schema.js +62 -0
  150. package/testutils/write.d.ts +2 -2
  151. package/testutils/write.js +33 -7
  152. package/tsc/ast.d.ts +25 -2
  153. package/tsc/ast.js +141 -17
  154. package/tsc/compilerOptions.js +5 -1
  155. package/tsc/move_generated.d.ts +1 -0
  156. package/tsc/move_generated.js +164 -0
  157. package/tsc/transform.d.ts +22 -0
  158. package/tsc/transform.js +182 -0
  159. package/tsc/transform_action.d.ts +22 -0
  160. package/tsc/transform_action.js +183 -0
  161. package/tsc/transform_ent.d.ts +17 -0
  162. package/tsc/transform_ent.js +60 -0
  163. package/tsc/transform_schema.d.ts +27 -0
  164. package/{scripts → tsc}/transform_schema.js +146 -117
  165. package/graphql/enums.d.ts +0 -3
  166. package/graphql/enums.js +0 -25
  167. package/scripts/move_generated.js +0 -142
  168. package/scripts/transform_code.js +0 -113
  169. package/scripts/transform_schema.d.ts +0 -1
  170. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  171. /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha15",
3
+ "version": "0.1.0-alpha151",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -8,26 +8,27 @@
8
8
  "example": "examples"
9
9
  },
10
10
  "dependencies": {
11
- "@types/node": "^15.0.2",
11
+ "@swc-node/register": "^1.6.5",
12
+ "@types/node": "^20.2.5",
12
13
  "camel-case": "^4.1.2",
13
- "dataloader": "^2.0.0",
14
- "glob": "^7.1.6",
15
- "graph-data-structure": "^1.12.0",
14
+ "cosmiconfig": "^8.1.3",
15
+ "dataloader": "^2.2.2",
16
+ "glob": "^10.2.6",
17
+ "graph-data-structure": "^3.3.0",
16
18
  "js-yaml": "^4.1.0",
17
- "json5": "^2.1.3",
18
- "luxon": "^1.25.0",
19
+ "json5": "^2.2.3",
20
+ "luxon": "^3.3.0",
19
21
  "memoizee": "^0.4.15",
20
- "minimist": "^1.2.6",
22
+ "minimist": "^1.2.8",
21
23
  "pascal-case": "^3.1.2",
22
- "pg": "^8.0.3",
23
- "prettier": "^2.3.2",
24
- "reflect-metadata": "^0.1.13",
25
- "snake-case": "^3.0.3",
26
- "ts-node": "^10.2.1",
27
- "tsconfig-paths": "^3.11.0",
28
- "tslib": "^2.3.1",
29
- "typescript": "^4.4.2",
30
- "uuid": "^8.3.2"
24
+ "pg": "^8.11.0",
25
+ "prettier": "^2.8.8",
26
+ "snake-case": "^3.0.4",
27
+ "ts-node": "^10.9.1",
28
+ "tsconfig-paths": "^4.2.0",
29
+ "tslib": "^2.5.2",
30
+ "typescript": "^5.0.4",
31
+ "uuid": "^9.0.0"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "better-sqlite3": "^7.4.1",
@@ -1,24 +1,25 @@
1
1
  import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
2
- import { ActionField, Type } from "../schema/schema";
2
+ import { ActionField, Type, GlobalSchema, TransformReadBetaResult, CanViewerDo } from "../schema/schema";
3
3
  declare enum NullableResult {
4
4
  CONTENTS = "contents",
5
5
  CONTENTS_AND_LIST = "contentsAndList",
6
6
  ITEM = "true"
7
7
  }
8
- declare type ProcessedActionField = Omit<ActionField, "nullable"> & {
8
+ type ProcessedActionField = Omit<ActionField, "nullable"> & {
9
9
  nullable?: NullableResult;
10
10
  };
11
- declare type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActions"> & {
11
+ type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActions"> & {
12
12
  patternName?: string;
13
13
  edgeActions?: OutputAction[];
14
14
  };
15
15
  interface TransformFlags {
16
16
  transformsSelect?: boolean;
17
17
  transformsDelete?: boolean;
18
+ transformsLoaderCodegen?: TransformReadBetaResult;
18
19
  transformsInsert?: boolean;
19
20
  transformsUpdate?: boolean;
20
21
  }
21
- declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
22
+ type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
22
23
  actions: OutputAction[];
23
24
  assocEdges: ProcessedAssocEdge[];
24
25
  assocEdgeGroups: ProcessedAssocEdgeGroup[];
@@ -26,11 +27,12 @@ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" |
26
27
  schemaPath?: string;
27
28
  patternNames?: string[];
28
29
  };
29
- declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
30
+ type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
30
31
  edgeAction?: OutputAction;
31
32
  };
32
- declare type OutputAction = Omit<Action, "actionOnlyFields"> & {
33
+ type OutputAction = Omit<Action, "actionOnlyFields" | "canViewerDo"> & {
33
34
  actionOnlyFields?: ProcessedActionField[];
35
+ canViewerDo?: CanViewerDo;
34
36
  };
35
37
  interface schemasDict {
36
38
  [key: string]: ProcessedSchema;
@@ -41,19 +43,21 @@ interface ProcessedPattern {
41
43
  fields: ProcessedField[];
42
44
  disableMixin?: boolean;
43
45
  }
44
- declare type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
46
+ type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
45
47
  subFields?: ProcessedField[];
46
48
  listElemType?: ProcessedType;
47
49
  unionFields?: ProcessedField[];
48
50
  };
49
- declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type"> & {
51
+ type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type" | "serverDefault"> & {
50
52
  name: string;
51
53
  hasDefaultValueOnCreate?: boolean;
52
54
  hasDefaultValueOnEdit?: boolean;
53
55
  patternName?: string;
54
56
  hasFieldPrivacy?: boolean;
57
+ hasEditFieldPrivacy?: boolean;
55
58
  derivedFields?: ProcessedField[];
56
59
  type: ProcessedType;
60
+ serverDefault?: string;
57
61
  };
58
62
  interface patternsDict {
59
63
  [key: string]: ProcessedPattern;
@@ -61,9 +65,27 @@ interface patternsDict {
61
65
  interface Result {
62
66
  schemas: schemasDict;
63
67
  patterns: patternsDict;
68
+ globalSchema?: ProcessedGlobalSchema;
69
+ config?: {
70
+ rome?: RomeConfig;
71
+ };
64
72
  }
65
73
  declare type PotentialSchemas = {
66
74
  [key: string]: any;
67
75
  };
68
- export declare function parseSchema(potentialSchemas: PotentialSchemas): Result;
76
+ export declare function parseSchema(potentialSchemas: PotentialSchemas, globalSchema?: GlobalSchema): Promise<Result>;
77
+ interface RomeConfig {
78
+ indentStyle?: string;
79
+ lineWidth?: number;
80
+ indentSize?: number;
81
+ quoteStyle?: string;
82
+ quoteProperties?: string;
83
+ trailingComma?: string;
84
+ }
85
+ interface ProcessedGlobalSchema {
86
+ globalEdges: ProcessedAssocEdge[];
87
+ extraEdgeFields: ProcessedField[];
88
+ init?: boolean;
89
+ globalFields?: ProcessedField[];
90
+ }
69
91
  export {};
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSchema = void 0;
4
- function processFields(src, patternName) {
4
+ const cosmiconfig_1 = require("cosmiconfig");
5
+ const const_1 = require("../core/const");
6
+ const global_schema_1 = require("../core/global_schema");
7
+ async function processFields(src, patternName) {
5
8
  const ret = [];
6
9
  let m = {};
7
10
  if (Array.isArray(src)) {
@@ -19,10 +22,11 @@ function processFields(src, patternName) {
19
22
  for (const name in m) {
20
23
  const field = m[name];
21
24
  //@ts-ignore type and other changed fields with different type in ProcessedField vs Field
22
- let f = { name, ...field };
25
+ let f = { ...field, name };
23
26
  f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
24
27
  f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
25
28
  f.hasFieldPrivacy = field.privacyPolicy !== undefined;
29
+ f.hasEditFieldPrivacy = field.editPrivacyPolicy !== undefined;
26
30
  if (field.polymorphic) {
27
31
  // convert boolean into object
28
32
  // we keep boolean as an option to keep API simple
@@ -36,6 +40,19 @@ function processFields(src, patternName) {
36
40
  else {
37
41
  delete f.polymorphic;
38
42
  }
43
+ if (field.private) {
44
+ // convert boolean into object
45
+ // we keep boolean as an option to keep API simple
46
+ if (typeof field.private === "boolean") {
47
+ f.private = {};
48
+ }
49
+ else {
50
+ f.private = field.private;
51
+ }
52
+ }
53
+ else {
54
+ delete f.private;
55
+ }
39
56
  // convert string to object to make API consumed by go simple
40
57
  if (f.fieldEdge && f.fieldEdge.inverseEdge) {
41
58
  if (typeof f.fieldEdge.inverseEdge === "string") {
@@ -47,26 +64,48 @@ function processFields(src, patternName) {
47
64
  if (patternName) {
48
65
  f.patternName = patternName;
49
66
  }
67
+ if (field.serverDefault !== undefined) {
68
+ f.serverDefault = await transformServerDefault(name, field, field.serverDefault);
69
+ }
50
70
  transformType(field.type);
51
71
  if (field.getDerivedFields) {
52
- f.derivedFields = processFields(field.getDerivedFields(name));
72
+ f.derivedFields = await processFields(field.getDerivedFields(name));
53
73
  }
54
74
  if (field.type.subFields) {
55
- f.type.subFields = processFields(field.type.subFields);
75
+ f.type.subFields = await processFields(field.type.subFields);
56
76
  }
57
77
  if (field.type.unionFields) {
58
- f.type.unionFields = processFields(field.type.unionFields);
78
+ f.type.unionFields = await processFields(field.type.unionFields);
59
79
  }
60
80
  if (field.type.listElemType &&
61
81
  field.type.listElemType.subFields &&
62
82
  // check to avoid ts-ignore below. exists just for tsc
63
83
  f.type.listElemType) {
64
- f.type.listElemType.subFields = processFields(field.type.listElemType.subFields);
84
+ f.type.listElemType.subFields = await processFields(field.type.listElemType.subFields);
65
85
  }
66
86
  ret.push(f);
67
87
  }
68
88
  return ret;
69
89
  }
90
+ async function transformServerDefault(name, f, value) {
91
+ if (f.valid) {
92
+ if (!(await f.valid(value))) {
93
+ throw new Error(`invalid value ${value} passed to field ${name}`);
94
+ }
95
+ }
96
+ if (f.format) {
97
+ value = await f.format(value);
98
+ }
99
+ switch (typeof value) {
100
+ case "boolean":
101
+ case "number":
102
+ case "bigint":
103
+ case "string":
104
+ return `${value}`;
105
+ default:
106
+ throw new Error(`invalid value ${value} passed to field ${name}`);
107
+ }
108
+ }
70
109
  function transformImportType(typ) {
71
110
  if (!typ.importType) {
72
111
  return;
@@ -108,12 +147,12 @@ function processEdgeGroups(processedSchema, edgeGroups) {
108
147
  processedSchema.assocEdgeGroups.push(group2);
109
148
  }
110
149
  }
111
- function processPattern(patterns, pattern, processedSchema) {
150
+ async function processPattern(patterns, pattern, processedSchema) {
112
151
  let ret = {
113
152
  ...pattern,
114
153
  };
115
154
  const name = pattern.name;
116
- const fields = processFields(pattern.fields, pattern.name);
155
+ const fields = await processFields(pattern.fields, pattern.name);
117
156
  processedSchema.fields.push(...fields);
118
157
  if (pattern.edges) {
119
158
  const edges = processEdges(pattern.edges, pattern.name);
@@ -122,6 +161,23 @@ function processPattern(patterns, pattern, processedSchema) {
122
161
  // flag transformsSelect
123
162
  if (pattern.transformRead) {
124
163
  ret.transformsSelect = true;
164
+ if (pattern.transformReadCodegen_BETA) {
165
+ const r = pattern.transformReadCodegen_BETA();
166
+ if (typeof r === "string") {
167
+ ret.transformsLoaderCodegen = {
168
+ code: r,
169
+ imports: [
170
+ {
171
+ importPath: const_1.PACKAGE,
172
+ import: "query",
173
+ },
174
+ ],
175
+ };
176
+ }
177
+ else {
178
+ ret.transformsLoaderCodegen = r;
179
+ }
180
+ }
125
181
  }
126
182
  if (patterns[name] === undefined) {
127
183
  // intentionally processing separately and not passing pattern.name
@@ -146,35 +202,51 @@ var NullableResult;
146
202
  NullableResult["ITEM"] = "true";
147
203
  })(NullableResult || (NullableResult = {}));
148
204
  function processAction(action) {
149
- if (!action.actionOnlyFields) {
150
- return { ...action };
151
- }
152
- let ret = { ...action };
153
- let actionOnlyFields = action.actionOnlyFields.map((f) => {
154
- let f2 = f;
155
- if (!f.nullable) {
156
- delete f2.nullable;
157
- return f2;
158
- }
159
- if (typeof f.nullable === "boolean") {
160
- f2.nullable = NullableResult.ITEM;
161
- }
162
- else {
163
- if (f.nullable === "contentsAndList") {
164
- f2.nullable = NullableResult.CONTENTS_AND_LIST;
205
+ const ret = { ...action };
206
+ if (action.actionOnlyFields !== undefined) {
207
+ let actionOnlyFields = action.actionOnlyFields.map((f) => {
208
+ let f2 = f;
209
+ if (!f.nullable) {
210
+ delete f2.nullable;
211
+ return f2;
212
+ }
213
+ if (typeof f.nullable === "boolean") {
214
+ f2.nullable = NullableResult.ITEM;
165
215
  }
166
216
  else {
167
- f2.nullable = NullableResult.CONTENTS;
217
+ if (f.nullable === "contentsAndList") {
218
+ f2.nullable = NullableResult.CONTENTS_AND_LIST;
219
+ }
220
+ else if (f.nullable === "contents") {
221
+ f2.nullable = NullableResult.CONTENTS;
222
+ }
223
+ else if (f.nullable === "true") {
224
+ // shouldn't happen but ran into weirdness where it did...
225
+ f2.nullable = NullableResult.ITEM;
226
+ }
168
227
  }
228
+ return f2;
229
+ });
230
+ ret.actionOnlyFields = actionOnlyFields;
231
+ }
232
+ if (action.canViewerDo !== undefined) {
233
+ if (typeof action.canViewerDo !== "object") {
234
+ delete ret.canViewerDo;
235
+ ret.canViewerDo = {};
169
236
  }
170
- return f2;
171
- });
172
- ret.actionOnlyFields = actionOnlyFields;
237
+ }
173
238
  return ret;
174
239
  }
175
- function parseSchema(potentialSchemas) {
240
+ async function parseSchema(potentialSchemas, globalSchema) {
176
241
  let schemas = {};
177
242
  let patterns = {};
243
+ let parsedGlobalSchema;
244
+ if (globalSchema) {
245
+ parsedGlobalSchema = await parseGlobalSchema(globalSchema);
246
+ // set this so that we can use it, if we're trying to process server default or anything
247
+ // that ends up parsing,validating and formatting fields
248
+ (0, global_schema_1.setGlobalSchema)(globalSchema);
249
+ }
178
250
  for (const key in potentialSchemas) {
179
251
  const value = potentialSchemas[key];
180
252
  let schema;
@@ -190,6 +262,7 @@ function parseSchema(potentialSchemas) {
190
262
  }
191
263
  let processedSchema = {
192
264
  fields: [],
265
+ fieldOverrides: schema.fieldOverrides,
193
266
  schemaPath: schema.schemaPath,
194
267
  tableName: schema.tableName,
195
268
  enumTable: schema.enumTable,
@@ -200,19 +273,27 @@ function parseSchema(potentialSchemas) {
200
273
  actions: schema.actions?.map((action) => processAction(action)) || [],
201
274
  assocEdges: [],
202
275
  assocEdgeGroups: [],
276
+ customGraphQLInterfaces: schema.customGraphQLInterfaces,
277
+ supportUpsert: schema.supportUpsert,
278
+ showCanViewerSee: schema.showCanViewerSee,
279
+ showCanViewerEdit: schema.showCanViewerEdit,
203
280
  };
204
281
  // let's put patterns first just so we have id, created_at, updated_at first
205
282
  // ¯\_(ツ)_/¯
206
283
  let patternNames = [];
207
284
  if (schema.patterns) {
208
285
  for (const pattern of schema.patterns) {
209
- const ret = processPattern(patterns, pattern, processedSchema);
286
+ const ret = await processPattern(patterns, pattern, processedSchema);
210
287
  patternNames.push(pattern.name);
211
288
  if (ret.transformsSelect) {
212
289
  if (processedSchema.transformsSelect) {
213
290
  throw new Error(`can only have one pattern which transforms default querying behavior`);
214
291
  }
215
292
  processedSchema.transformsSelect = true;
293
+ if (ret.transformsLoaderCodegen) {
294
+ processedSchema.transformsLoaderCodegen =
295
+ ret.transformsLoaderCodegen;
296
+ }
216
297
  }
217
298
  if (ret.transformsDelete) {
218
299
  if (processedSchema.transformsDelete) {
@@ -222,7 +303,7 @@ function parseSchema(potentialSchemas) {
222
303
  }
223
304
  }
224
305
  }
225
- const fields = processFields(schema.fields);
306
+ const fields = await processFields(schema.fields);
226
307
  processedSchema.fields.push(...fields);
227
308
  processedSchema.patternNames = patternNames;
228
309
  if (schema.edges) {
@@ -234,6 +315,72 @@ function parseSchema(potentialSchemas) {
234
315
  }
235
316
  schemas[key] = processedSchema;
236
317
  }
237
- return { schemas, patterns };
318
+ const rome = translatePrettier();
319
+ return {
320
+ schemas,
321
+ patterns,
322
+ globalSchema: parsedGlobalSchema,
323
+ config: {
324
+ rome,
325
+ },
326
+ };
238
327
  }
239
328
  exports.parseSchema = parseSchema;
329
+ function translatePrettier() {
330
+ const r = (0, cosmiconfig_1.cosmiconfigSync)("prettier").search();
331
+ if (!r) {
332
+ return;
333
+ }
334
+ const ret = {};
335
+ if (r.config.printWidth !== undefined) {
336
+ ret.lineWidth = parseInt(r.config.printWidth);
337
+ }
338
+ if (r.config.useTabs) {
339
+ ret.indentStyle = "tab";
340
+ }
341
+ else {
342
+ ret.indentStyle = "space";
343
+ }
344
+ if (r.config.tabWidth !== undefined) {
345
+ ret.indentSize = parseInt(r.config.tabWidth);
346
+ }
347
+ if (r.config.singleQuote) {
348
+ ret.quoteStyle = "single";
349
+ }
350
+ else {
351
+ ret.quoteStyle = "double";
352
+ }
353
+ if (r.config.quoteProps !== undefined) {
354
+ if (r.config.quoteProps === "consistent") {
355
+ // rome doesn't support this
356
+ ret.quoteProperties = "as-needed";
357
+ }
358
+ else {
359
+ ret.quoteProperties = r.config.quoteProps;
360
+ }
361
+ }
362
+ if (r.config.trailingComma !== undefined) {
363
+ ret.trailingComma = r.config.trailingComma;
364
+ }
365
+ return ret;
366
+ }
367
+ async function parseGlobalSchema(s) {
368
+ const ret = {
369
+ globalEdges: [],
370
+ extraEdgeFields: [],
371
+ init: !!s.extraEdgeFields ||
372
+ s.transformEdgeRead !== undefined ||
373
+ s.transformEdgeWrite !== undefined ||
374
+ s.fields !== undefined,
375
+ };
376
+ if (s.extraEdgeFields) {
377
+ ret.extraEdgeFields = await processFields(s.extraEdgeFields);
378
+ }
379
+ if (s.edges) {
380
+ ret.globalEdges = processEdges(s.edges);
381
+ }
382
+ if (s.fields) {
383
+ ret.globalFields = await processFields(s.fields);
384
+ }
385
+ return ret;
386
+ }
@@ -1,11 +1,12 @@
1
- import { Field, FieldMap, Pattern } from "./schema";
1
+ import { FieldMap, Pattern, FieldOverrideMap } from "./schema";
2
2
  import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
3
3
  export declare const Timestamps: Pattern;
4
4
  export declare const Node: Pattern;
5
5
  export interface SchemaConfig extends Schema {
6
6
  }
7
7
  export declare class EntSchema implements Schema {
8
- fields: FieldMap | Field[];
8
+ fields: FieldMap;
9
+ fieldOverrides: FieldOverrideMap | undefined;
9
10
  tableName: string | undefined;
10
11
  patterns: Pattern[];
11
12
  edges: Edge[] | undefined;
@@ -18,10 +19,15 @@ export declare class EntSchema implements Schema {
18
19
  constraints: Constraint[] | undefined;
19
20
  indices: Index[] | undefined;
20
21
  hideFromGraphQL?: boolean;
22
+ customGraphQLInterfaces?: string[] | undefined;
23
+ supportUpsert?: boolean | undefined;
24
+ showCanViewerSee?: boolean | undefined;
25
+ showCanViewerEdit?: boolean | undefined;
21
26
  constructor(cfg: SchemaConfig);
22
27
  }
23
28
  export declare class EntSchemaWithTZ implements Schema {
24
- fields: FieldMap | Field[];
29
+ fields: FieldMap;
30
+ fieldOverrides: FieldOverrideMap | undefined;
25
31
  tableName: string | undefined;
26
32
  patterns: Pattern[];
27
33
  edges: Edge[] | undefined;
@@ -34,6 +40,10 @@ export declare class EntSchemaWithTZ implements Schema {
34
40
  constraints: Constraint[] | undefined;
35
41
  indices: Index[] | undefined;
36
42
  hideFromGraphQL?: boolean;
43
+ customGraphQLInterfaces?: string[] | undefined;
44
+ supportUpsert?: boolean | undefined;
45
+ showCanViewerSee?: boolean | undefined;
46
+ showCanViewerEdit?: boolean | undefined;
37
47
  constructor(cfg: SchemaConfig);
38
48
  }
39
49
  export declare abstract class BaseEntSchema {
@@ -17,6 +17,7 @@ let tsFields = {
17
17
  defaultValueOnCreate: () => {
18
18
  return new Date();
19
19
  },
20
+ onlyUpdateIfOtherFieldsBeingSet_BETA: true,
20
21
  defaultValueOnEdit: () => {
21
22
  return new Date();
22
23
  },
@@ -74,6 +75,7 @@ class EntSchema {
74
75
  constructor(cfg) {
75
76
  this.patterns = [exports.Node];
76
77
  this.fields = cfg.fields;
78
+ this.fieldOverrides = cfg.fieldOverrides;
77
79
  this.tableName = cfg.tableName;
78
80
  if (cfg.patterns) {
79
81
  this.patterns.push(...cfg.patterns);
@@ -86,6 +88,11 @@ class EntSchema {
86
88
  this.constraints = cfg.constraints;
87
89
  this.indices = cfg.indices;
88
90
  this.hideFromGraphQL = cfg.hideFromGraphQL;
91
+ // TODO annoying that have to list these...
92
+ this.customGraphQLInterfaces = cfg.customGraphQLInterfaces;
93
+ this.supportUpsert = cfg.supportUpsert;
94
+ this.showCanViewerSee = cfg.showCanViewerSee;
95
+ this.showCanViewerEdit = cfg.showCanViewerEdit;
89
96
  }
90
97
  }
91
98
  exports.EntSchema = EntSchema;
@@ -100,6 +107,7 @@ class EntSchemaWithTZ {
100
107
  },
101
108
  ];
102
109
  this.fields = cfg.fields;
110
+ this.fieldOverrides = cfg.fieldOverrides;
103
111
  this.tableName = cfg.tableName;
104
112
  if (cfg.patterns) {
105
113
  this.patterns.push(...cfg.patterns);
@@ -112,6 +120,11 @@ class EntSchemaWithTZ {
112
120
  this.constraints = cfg.constraints;
113
121
  this.indices = cfg.indices;
114
122
  this.hideFromGraphQL = cfg.hideFromGraphQL;
123
+ // TODO annoying that have to list these...
124
+ this.customGraphQLInterfaces = cfg.customGraphQLInterfaces;
125
+ this.supportUpsert = cfg.supportUpsert;
126
+ this.showCanViewerSee = cfg.showCanViewerSee;
127
+ this.showCanViewerEdit = cfg.showCanViewerEdit;
115
128
  }
116
129
  }
117
130
  exports.EntSchemaWithTZ = EntSchemaWithTZ;