@snowtop/ent 0.1.0-alpha12 → 0.1.0-alpha121

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 (167) hide show
  1. package/action/action.d.ts +37 -31
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +3 -3
  4. package/action/executor.js +8 -3
  5. package/action/experimental_action.d.ts +32 -22
  6. package/action/experimental_action.js +35 -9
  7. package/action/index.d.ts +2 -0
  8. package/action/index.js +7 -1
  9. package/action/orchestrator.d.ts +33 -14
  10. package/action/orchestrator.js +251 -54
  11. package/action/privacy.d.ts +2 -2
  12. package/action/relative_value.d.ts +47 -0
  13. package/action/relative_value.js +125 -0
  14. package/action/transaction.d.ts +10 -0
  15. package/action/transaction.js +23 -0
  16. package/auth/auth.d.ts +1 -1
  17. package/core/base.d.ts +60 -37
  18. package/core/base.js +7 -1
  19. package/core/clause.d.ts +84 -40
  20. package/core/clause.js +358 -64
  21. package/core/config.d.ts +12 -1
  22. package/core/config.js +7 -1
  23. package/core/const.d.ts +3 -0
  24. package/core/const.js +6 -0
  25. package/core/context.d.ts +6 -4
  26. package/core/context.js +20 -2
  27. package/core/convert.d.ts +1 -1
  28. package/core/date.js +1 -5
  29. package/core/db.d.ts +11 -8
  30. package/core/db.js +20 -8
  31. package/core/ent.d.ts +82 -30
  32. package/core/ent.js +632 -193
  33. package/core/global_schema.d.ts +7 -0
  34. package/core/global_schema.js +51 -0
  35. package/core/loaders/assoc_count_loader.d.ts +3 -2
  36. package/core/loaders/assoc_count_loader.js +10 -2
  37. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  38. package/core/loaders/assoc_edge_loader.js +8 -11
  39. package/core/loaders/index.d.ts +1 -1
  40. package/core/loaders/index.js +1 -3
  41. package/core/loaders/index_loader.d.ts +3 -3
  42. package/core/loaders/loader.d.ts +2 -2
  43. package/core/loaders/loader.js +5 -5
  44. package/core/loaders/object_loader.d.ts +11 -10
  45. package/core/loaders/object_loader.js +70 -60
  46. package/core/loaders/query_loader.d.ts +7 -13
  47. package/core/loaders/query_loader.js +52 -11
  48. package/core/loaders/raw_count_loader.d.ts +2 -2
  49. package/core/loaders/raw_count_loader.js +5 -1
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +25 -24
  53. package/core/privacy.js +21 -25
  54. package/core/query/assoc_query.d.ts +7 -6
  55. package/core/query/assoc_query.js +9 -1
  56. package/core/query/custom_clause_query.d.ts +27 -0
  57. package/core/query/custom_clause_query.js +84 -0
  58. package/core/query/custom_query.d.ts +20 -5
  59. package/core/query/custom_query.js +87 -12
  60. package/core/query/index.d.ts +1 -0
  61. package/core/query/index.js +3 -1
  62. package/core/query/query.d.ts +8 -4
  63. package/core/query/query.js +101 -53
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +35 -45
  66. package/core/query/shared_test.d.ts +8 -1
  67. package/core/query/shared_test.js +470 -236
  68. package/core/viewer.d.ts +3 -3
  69. package/core/viewer.js +1 -1
  70. package/graphql/graphql.d.ts +15 -7
  71. package/graphql/graphql.js +23 -7
  72. package/graphql/index.d.ts +1 -1
  73. package/graphql/index.js +3 -4
  74. package/graphql/query/connection_type.d.ts +9 -9
  75. package/graphql/query/edge_connection.d.ts +9 -9
  76. package/graphql/query/page_info.d.ts +1 -1
  77. package/graphql/query/shared_assoc_test.js +1 -1
  78. package/graphql/query/shared_edge_connection.js +1 -19
  79. package/graphql/scalars/orderby_direction.d.ts +2 -0
  80. package/graphql/scalars/orderby_direction.js +15 -0
  81. package/imports/index.d.ts +6 -1
  82. package/imports/index.js +19 -4
  83. package/index.d.ts +13 -5
  84. package/index.js +21 -7
  85. package/package.json +17 -16
  86. package/parse_schema/parse.d.ts +31 -9
  87. package/parse_schema/parse.js +152 -12
  88. package/schema/base_schema.d.ts +5 -3
  89. package/schema/base_schema.js +6 -0
  90. package/schema/field.d.ts +78 -21
  91. package/schema/field.js +219 -72
  92. package/schema/index.d.ts +2 -2
  93. package/schema/index.js +5 -1
  94. package/schema/json_field.d.ts +16 -4
  95. package/schema/json_field.js +32 -2
  96. package/schema/schema.d.ts +89 -20
  97. package/schema/schema.js +13 -14
  98. package/schema/struct_field.d.ts +15 -3
  99. package/schema/struct_field.js +71 -22
  100. package/schema/union_field.d.ts +1 -1
  101. package/scripts/custom_compiler.js +10 -6
  102. package/scripts/custom_graphql.js +124 -31
  103. package/scripts/migrate_v0.1.js +36 -0
  104. package/scripts/move_types.js +117 -0
  105. package/scripts/read_schema.js +20 -5
  106. package/testutils/action/complex_schemas.d.ts +69 -0
  107. package/testutils/action/complex_schemas.js +398 -0
  108. package/testutils/builder.d.ts +43 -47
  109. package/testutils/builder.js +76 -49
  110. package/testutils/db/fixture.d.ts +10 -0
  111. package/testutils/db/fixture.js +26 -0
  112. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
  113. package/testutils/db/{test_db.js → temp_db.js} +182 -45
  114. package/testutils/db/value.d.ts +7 -0
  115. package/testutils/db/value.js +251 -0
  116. package/testutils/db_mock.d.ts +16 -4
  117. package/testutils/db_mock.js +51 -6
  118. package/testutils/db_time_zone.d.ts +4 -0
  119. package/testutils/db_time_zone.js +41 -0
  120. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  121. package/testutils/ent-graphql-tests/index.js +52 -23
  122. package/testutils/fake_data/const.d.ts +2 -1
  123. package/testutils/fake_data/const.js +3 -0
  124. package/testutils/fake_data/fake_contact.d.ts +8 -4
  125. package/testutils/fake_data/fake_contact.js +15 -8
  126. package/testutils/fake_data/fake_event.d.ts +5 -2
  127. package/testutils/fake_data/fake_event.js +9 -7
  128. package/testutils/fake_data/fake_tag.d.ts +36 -0
  129. package/testutils/fake_data/fake_tag.js +89 -0
  130. package/testutils/fake_data/fake_user.d.ts +10 -7
  131. package/testutils/fake_data/fake_user.js +18 -16
  132. package/testutils/fake_data/index.js +5 -1
  133. package/testutils/fake_data/internal.d.ts +2 -0
  134. package/testutils/fake_data/internal.js +7 -1
  135. package/testutils/fake_data/tag_query.d.ts +13 -0
  136. package/testutils/fake_data/tag_query.js +43 -0
  137. package/testutils/fake_data/test_helpers.d.ts +11 -4
  138. package/testutils/fake_data/test_helpers.js +28 -12
  139. package/testutils/fake_data/user_query.d.ts +13 -6
  140. package/testutils/fake_data/user_query.js +54 -22
  141. package/testutils/fake_log.d.ts +3 -3
  142. package/testutils/parse_sql.d.ts +6 -0
  143. package/testutils/parse_sql.js +16 -2
  144. package/testutils/test_edge_global_schema.d.ts +15 -0
  145. package/testutils/test_edge_global_schema.js +62 -0
  146. package/testutils/write.d.ts +2 -2
  147. package/testutils/write.js +33 -7
  148. package/tsc/ast.d.ts +25 -2
  149. package/tsc/ast.js +141 -17
  150. package/tsc/compilerOptions.js +5 -1
  151. package/tsc/move_generated.d.ts +1 -0
  152. package/tsc/move_generated.js +164 -0
  153. package/tsc/transform.d.ts +22 -0
  154. package/tsc/transform.js +181 -0
  155. package/tsc/transform_action.d.ts +22 -0
  156. package/tsc/transform_action.js +183 -0
  157. package/tsc/transform_ent.d.ts +17 -0
  158. package/tsc/transform_ent.js +60 -0
  159. package/tsc/transform_schema.d.ts +27 -0
  160. package/{scripts → tsc}/transform_schema.js +146 -117
  161. package/graphql/enums.d.ts +0 -3
  162. package/graphql/enums.js +0 -25
  163. package/scripts/move_generated.js +0 -142
  164. package/scripts/transform_code.js +0 -113
  165. package/scripts/transform_schema.d.ts +0 -1
  166. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  167. /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
@@ -1,6 +1,7 @@
1
1
  import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
2
- import { Builder } from "../action/action";
2
+ import { Builder, Changeset } from "../action/action";
3
3
  import { Clause } from "../core/clause";
4
+ import { AssocEdgeInput } from "../core/ent";
4
5
  export declare type FieldMap = {
5
6
  [key: string]: Field;
6
7
  };
@@ -8,11 +9,23 @@ interface FieldInfo {
8
9
  dbCol: string;
9
10
  inputKey: string;
10
11
  }
11
- export declare type FieldInfoMap = {
12
+ export type FieldInfoMap = {
12
13
  [key: string]: FieldInfo;
13
14
  };
15
+ export interface GlobalSchema {
16
+ edges?: Edge[];
17
+ extraEdgeFields?: FieldMap;
18
+ transformEdgeRead?: () => Clause;
19
+ transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
20
+ fields?: FieldMap;
21
+ }
22
+ type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index">;
23
+ export type FieldOverrideMap = {
24
+ [key: string]: FieldOverride;
25
+ };
14
26
  export default interface Schema {
15
- fields: FieldMap | Field[];
27
+ fields: FieldMap;
28
+ fieldOverrides?: FieldOverrideMap;
16
29
  tableName?: string;
17
30
  patterns?: Pattern[];
18
31
  edges?: Edge[];
@@ -61,17 +74,30 @@ export interface AssocEdgeGroup {
61
74
  tableName?: string;
62
75
  assocEdges: AssocEdge[];
63
76
  statusEnums?: string[];
64
- nullStates: string | string[];
77
+ viewerBased?: boolean;
78
+ nullStates?: string | string[];
65
79
  nullStateFn?: string;
66
80
  edgeAction?: EdgeGroupAction;
67
81
  }
68
- export declare type Edge = AssocEdge;
82
+ export type Edge = AssocEdge;
83
+ interface ImportPath {
84
+ importPath: string;
85
+ import: string;
86
+ defaultImport?: boolean;
87
+ originalImport?: string;
88
+ }
89
+ export interface TransformReadBetaResult {
90
+ code: string;
91
+ imports: ImportPath[];
92
+ }
69
93
  export interface Pattern {
70
94
  name: string;
71
- fields: FieldMap | Field[];
95
+ fields: FieldMap;
96
+ disableMixin?: boolean;
72
97
  edges?: Edge[];
73
98
  transformRead?: () => Clause;
74
- transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | undefined;
99
+ transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
100
+ transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
75
101
  transformsDelete?: boolean;
76
102
  transformsInsert?: boolean;
77
103
  transformsUpdate?: boolean;
@@ -81,16 +107,25 @@ export declare enum SQLStatementOperation {
81
107
  Update = "update",
82
108
  Delete = "delete"
83
109
  }
84
- export interface UpdateOperation<T extends Ent> {
110
+ export interface EdgeUpdateOperation {
111
+ op: SQLStatementOperation;
112
+ edge: AssocEdgeInput;
113
+ }
114
+ export interface TransformedEdgeUpdateOperation {
85
115
  op: SQLStatementOperation;
86
- existingEnt?: T;
87
- viewer: Viewer;
116
+ data?: Data;
117
+ }
118
+ export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
119
+ op: SQLStatementOperation;
120
+ builder: Builder<TEnt, TViewer, any>;
121
+ input: Data;
88
122
  data?: Map<string, any>;
89
123
  }
90
- export interface TransformedUpdateOperation<T extends Ent> {
124
+ export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
91
125
  op: SQLStatementOperation;
92
126
  data?: Data;
93
- existingEnt?: T;
127
+ existingEnt?: T | null;
128
+ changeset?(): Promise<Changeset> | Changeset;
94
129
  }
95
130
  export declare enum DBType {
96
131
  UUID = "UUID",
@@ -106,19 +141,27 @@ export declare enum DBType {
106
141
  JSONB = "JSONB",
107
142
  Enum = "Enum",
108
143
  StringEnum = "StringEnum",
144
+ IntEnum = "IntEnum",
109
145
  Date = "Date",
110
146
  Time = "Time",
111
147
  Timetz = "Timetz",
112
148
  List = "List"
113
149
  }
114
- export interface ImportType {
150
+ export interface DeprecatedImportType {
115
151
  path: string;
116
152
  type: string;
117
153
  [x: string]: any;
118
154
  }
155
+ export interface ConvertType {
156
+ path: string;
157
+ function: string;
158
+ }
119
159
  declare type EnumMap = {
120
160
  [key: string]: string;
121
161
  };
162
+ declare type IntEnumMap = {
163
+ [key: string]: number;
164
+ };
122
165
  export interface Type {
123
166
  dbType: DBType;
124
167
  listElemType?: Type;
@@ -126,9 +169,14 @@ export interface Type {
126
169
  graphQLType?: string;
127
170
  values?: string[];
128
171
  enumMap?: EnumMap;
129
- importType?: ImportType;
172
+ intEnumMap?: IntEnumMap;
173
+ deprecatedIntEnumMap?: IntEnumMap;
174
+ disableUnknownType?: boolean;
175
+ globalType?: string;
176
+ importType?: DeprecatedImportType;
130
177
  subFields?: FieldMap;
131
178
  unionFields?: FieldMap;
179
+ [x: string]: any;
132
180
  }
133
181
  export interface ForeignKey {
134
182
  schema: string;
@@ -136,8 +184,9 @@ export interface ForeignKey {
136
184
  name?: string;
137
185
  disableIndex?: boolean;
138
186
  disableBuilderType?: boolean;
187
+ [x: string]: any;
139
188
  }
140
- declare type getLoaderInfoFn = (type: string) => LoaderInfo;
189
+ type getLoaderInfoFn = (type: string) => LoaderInfo;
141
190
  export interface InverseFieldEdge {
142
191
  name: string;
143
192
  edgeConstName?: string;
@@ -151,45 +200,56 @@ export interface FieldEdge {
151
200
  getLoaderInfoFromSchema?: getLoaderInfoFn;
152
201
  disableBuilderType?: boolean;
153
202
  }
203
+ interface PrivateOptions {
204
+ exposeToActions?: boolean;
205
+ }
154
206
  export interface FieldOptions {
155
207
  nullable?: boolean;
156
208
  storageKey?: string;
157
209
  serverDefault?: any;
158
210
  unique?: boolean;
159
211
  hideFromGraphQL?: boolean;
160
- private?: boolean;
212
+ private?: boolean | PrivateOptions;
161
213
  sensitive?: boolean;
162
214
  graphqlName?: string;
163
215
  index?: boolean;
164
216
  foreignKey?: ForeignKey;
165
217
  fieldEdge?: FieldEdge;
166
218
  primaryKey?: boolean;
219
+ immutable?: boolean;
167
220
  disableUserEditable?: boolean;
168
221
  disableUserGraphQLEditable?: boolean;
169
222
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
170
223
  defaultToViewerOnCreate?: boolean;
224
+ onlyUpdateIfOtherFieldsBeingSet_BETA?: boolean;
171
225
  defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
172
226
  derivedWhenEmbedded?: boolean;
173
227
  polymorphic?: boolean | PolymorphicOptions;
174
228
  privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
175
229
  getDerivedFields?(name: string): FieldMap;
230
+ convert?: ConvertType;
231
+ fetchOnDemand?: boolean;
232
+ dbOnly?: boolean;
176
233
  [x: string]: any;
177
234
  }
178
235
  export interface PolymorphicOptions {
236
+ name?: string;
179
237
  types?: string[];
180
238
  hideFromInverseGraphQL?: boolean;
181
239
  disableBuilderType?: boolean;
240
+ serverDefault?: any;
182
241
  }
183
242
  export interface Field extends FieldOptions {
184
243
  type: Type;
185
244
  valid?(val: any): Promise<boolean> | boolean;
245
+ validateWithFullData?(val: any, builder: Builder<any>): boolean | Promise<boolean>;
186
246
  format?(val: any, nested?: boolean): any;
187
247
  logValue(val: any): any;
188
248
  }
189
249
  export interface SchemaConstructor {
190
250
  new (): Schema;
191
251
  }
192
- export declare type SchemaInputType = Schema | SchemaConstructor;
252
+ export type SchemaInputType = Schema | SchemaConstructor;
193
253
  export declare function getSchema(value: SchemaInputType): Schema;
194
254
  export declare function getFields(value: SchemaInputType): Map<string, Field>;
195
255
  /**
@@ -203,7 +263,7 @@ interface objectLoaderOptions {
203
263
  instanceKey?: string;
204
264
  }
205
265
  export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
206
- export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | undefined;
266
+ export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
207
267
  export declare enum ActionOperation {
208
268
  Create = 1,
209
269
  Edit = 2,
@@ -213,15 +273,18 @@ export declare enum ActionOperation {
213
273
  RemoveEdge = 32,
214
274
  EdgeGroup = 64
215
275
  }
216
- declare type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "Object";
217
- declare type NullableListOptions = "contents" | "contentsAndList";
276
+ type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "JSON" | "Object";
277
+ type NullableListOptions = "contents" | "contentsAndList";
218
278
  export interface ActionField {
219
279
  name: string;
220
280
  type: actionFieldType;
221
281
  nullable?: boolean | NullableListOptions;
282
+ optional?: boolean;
222
283
  list?: boolean;
223
284
  actionName?: string;
224
285
  excludedFields?: string[];
286
+ hideFromGraphQL?: boolean;
287
+ [x: string]: any;
225
288
  }
226
289
  export interface Action {
227
290
  operation: ActionOperation;
@@ -235,6 +298,7 @@ export interface Action {
235
298
  optionalFields?: string[];
236
299
  requiredFields?: string[];
237
300
  noFields?: boolean;
301
+ [x: string]: any;
238
302
  }
239
303
  export declare const NoFields = "__NO_FIELDS__";
240
304
  export declare function requiredField(field: string): string;
@@ -245,6 +309,7 @@ export interface Constraint {
245
309
  columns: string[];
246
310
  fkey?: ForeignKeyInfo;
247
311
  condition?: string;
312
+ [x: string]: any;
248
313
  }
249
314
  export interface FullTextWeight {
250
315
  A?: string[];
@@ -258,17 +323,21 @@ export interface FullText {
258
323
  languageColumn?: string;
259
324
  indexType?: "gin" | "gist";
260
325
  weights?: FullTextWeight;
326
+ [x: string]: any;
261
327
  }
262
328
  export interface Index {
263
329
  name: string;
264
330
  columns: string[];
265
331
  unique?: boolean;
266
332
  fulltext?: FullText;
333
+ indexType?: "gin" | "btree";
334
+ [x: string]: any;
267
335
  }
268
336
  export interface ForeignKeyInfo {
269
337
  tableName: string;
270
338
  ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
271
339
  columns: string[];
340
+ [x: string]: any;
272
341
  }
273
342
  export declare enum ConstraintType {
274
343
  PrimaryKey = "primary",
package/schema/schema.js CHANGED
@@ -35,6 +35,7 @@ var DBType;
35
35
  DBType["JSONB"] = "JSONB";
36
36
  DBType["Enum"] = "Enum";
37
37
  DBType["StringEnum"] = "StringEnum";
38
+ DBType["IntEnum"] = "IntEnum";
38
39
  DBType["Date"] = "Date";
39
40
  DBType["Time"] = "Time";
40
41
  DBType["Timetz"] = "Timetz";
@@ -55,21 +56,11 @@ exports.getSchema = getSchema;
55
56
  function getFields(value) {
56
57
  const schema = getSchema(value);
57
58
  function addFields(fields) {
58
- if (Array.isArray(fields)) {
59
- for (const field of fields) {
60
- const name = field.name;
61
- if (!name) {
62
- throw new Error(`name required`);
63
- }
64
- if (field.getDerivedFields !== undefined) {
65
- addFields(field.getDerivedFields(name));
66
- }
67
- m.set(name, field);
68
- }
69
- return;
70
- }
71
59
  for (const name in fields) {
72
60
  const field = fields[name];
61
+ if (field.dbOnly) {
62
+ continue;
63
+ }
73
64
  if (field.getDerivedFields !== undefined) {
74
65
  addFields(field.getDerivedFields(name));
75
66
  }
@@ -121,6 +112,7 @@ function getFieldsWithPrivacy(value, fieldMap) {
121
112
  m.set(info.dbCol, privacyPolicy);
122
113
  }
123
114
  }
115
+ return;
124
116
  }
125
117
  for (const name in fields) {
126
118
  const field = fields[name];
@@ -168,6 +160,9 @@ function getTransformedReadClause(value) {
168
160
  return;
169
161
  }
170
162
  exports.getTransformedReadClause = getTransformedReadClause;
163
+ // would like to avoid calling this so that itwe don't run into circular dependencies
164
+ // but the fact that it returns a clause makes it hard since we don't control the patterns...
165
+ // we can make each clause return a format that can be extrapolated and used in codegen...
171
166
  function getObjectLoaderProperties(value, tableName) {
172
167
  return {
173
168
  clause: () => getTransformedReadClause(value),
@@ -178,13 +173,14 @@ exports.getObjectLoaderProperties = getObjectLoaderProperties;
178
173
  function getTransformedUpdateOp(value, stmt) {
179
174
  const schema = getSchema(value);
180
175
  if (!schema.patterns) {
181
- return;
176
+ return null;
182
177
  }
183
178
  for (const p of schema.patterns) {
184
179
  if (p.transformWrite) {
185
180
  return p.transformWrite(stmt);
186
181
  }
187
182
  }
183
+ return null;
188
184
  }
189
185
  exports.getTransformedUpdateOp = getTransformedUpdateOp;
190
186
  // this maps to ActionOperation in ent/action.go
@@ -208,6 +204,9 @@ var ActionOperation;
208
204
  // RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
209
205
  ActionOperation[ActionOperation["RemoveEdge"] = 32] = "RemoveEdge";
210
206
  // EdgeGroup is used to provide the ability to edit an edge group in an AssociationEdgeGroup.
207
+ // if you want to clear this edge group e.g. any set edge with id1 and id2,
208
+ // you should create a custom action that takes the id as an action only field,
209
+ // and then calls `clearEdgeTypeInGroup` in a trigger to clear
211
210
  ActionOperation[ActionOperation["EdgeGroup"] = 64] = "EdgeGroup";
212
211
  })(ActionOperation = exports.ActionOperation || (exports.ActionOperation = {}));
213
212
  // sentinel that indicates an action has no fields
@@ -1,17 +1,29 @@
1
1
  import { BaseField, ListField } from "./field";
2
2
  import { FieldOptions, Field, Type, FieldMap } from "./schema";
3
- export interface StructOptions extends FieldOptions {
3
+ interface structFieldOptions extends FieldOptions {
4
4
  tsType: string;
5
5
  fields: FieldMap;
6
6
  graphQLType?: string;
7
7
  jsonNotJSONB?: boolean;
8
8
  }
9
+ interface GlobalStructOptions extends FieldOptions {
10
+ globalType: string;
11
+ }
12
+ export type StructOptions = structFieldOptions | GlobalStructOptions;
9
13
  export declare class StructField extends BaseField implements Field {
10
14
  private options;
15
+ private jsonAsList?;
11
16
  type: Type;
12
- constructor(options: StructOptions);
13
- format(obj: any, nested?: boolean): string | Object;
17
+ constructor(options: StructOptions, jsonAsList?: boolean | undefined);
18
+ formatImpl(obj: any, nested?: boolean): string | Object;
19
+ format(obj: any, nested?: boolean): any;
20
+ private validImpl;
14
21
  valid(obj: any): Promise<boolean>;
15
22
  }
16
23
  export declare function StructType(options: StructOptions): StructField & StructOptions;
24
+ /**
25
+ * @deprecated use StructTypeAsList
26
+ */
17
27
  export declare function StructListType(options: StructOptions): ListField;
28
+ export declare function StructTypeAsList(options: StructOptions): StructField & StructOptions;
29
+ export {};
@@ -1,44 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StructListType = exports.StructType = exports.StructField = void 0;
3
+ exports.StructTypeAsList = exports.StructListType = exports.StructType = exports.StructField = void 0;
4
+ const camel_case_1 = require("camel-case");
4
5
  const field_1 = require("./field");
5
6
  const schema_1 = require("./schema");
6
- const camel_case_1 = require("camel-case");
7
+ const global_schema_1 = require("../core/global_schema");
7
8
  class StructField extends field_1.BaseField {
8
- constructor(options) {
9
+ constructor(options, jsonAsList) {
9
10
  super();
10
11
  this.options = options;
12
+ this.jsonAsList = jsonAsList;
11
13
  this.type = {
12
14
  dbType: schema_1.DBType.JSONB,
13
15
  };
14
16
  this.type.subFields = options.fields;
15
17
  this.type.type = options.tsType;
16
18
  this.type.graphQLType = options.graphQLType || options.tsType;
19
+ this.type.globalType = this.options.globalType;
17
20
  if (options.jsonNotJSONB) {
18
21
  this.type.dbType = schema_1.DBType.JSON;
19
22
  }
23
+ if (jsonAsList) {
24
+ this.type.listElemType = {
25
+ dbType: schema_1.DBType.JSONB,
26
+ };
27
+ }
20
28
  }
21
- // right now, we store things in the db in lowerCase format
22
- // this will lead to issues if field changes.
23
- // TODO: use storageKey and convert back...
24
- format(obj, nested) {
29
+ formatImpl(obj, nested) {
25
30
  if (!(obj instanceof Object)) {
26
31
  throw new Error("valid was not called");
27
32
  }
28
33
  let ret = {};
29
34
  for (const k in this.options.fields) {
35
+ const field = this.options.fields[k];
36
+ // check two values
37
+ // store in dbKey format
30
38
  // TODO more #510
31
- let dbKey = (0, camel_case_1.camelCase)(k);
32
- let val = obj[dbKey];
33
- // for tests with snake_case
34
- if (val === undefined && obj[k] !== undefined) {
35
- val = obj[k];
36
- dbKey = k;
39
+ let dbKey = (0, schema_1.getStorageKey)(field, k);
40
+ let camelKey = (0, camel_case_1.camelCase)(k);
41
+ let val = obj[camelKey];
42
+ if (val === undefined && obj[dbKey] !== undefined) {
43
+ val = obj[dbKey];
37
44
  }
38
45
  if (val === undefined) {
39
46
  continue;
40
47
  }
41
- const field = this.options.fields[k];
42
48
  if (field.format) {
43
49
  // indicate nested so this isn't JSON stringified
44
50
  ret[dbKey] = field.format(val, true);
@@ -47,13 +53,29 @@ class StructField extends field_1.BaseField {
47
53
  ret[dbKey] = val;
48
54
  }
49
55
  }
50
- // don't json.stringify if nested
56
+ // don't json.stringify if nested or list
51
57
  if (nested) {
52
58
  return ret;
53
59
  }
54
60
  return JSON.stringify(ret);
55
61
  }
56
- async valid(obj) {
62
+ format(obj, nested) {
63
+ if (this.type.globalType) {
64
+ const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
65
+ if (f && f.format) {
66
+ return f.format(obj);
67
+ }
68
+ }
69
+ if (Array.isArray(obj) && this.jsonAsList) {
70
+ const ret = obj.map((v) => this.formatImpl(v, true));
71
+ if (nested) {
72
+ return ret;
73
+ }
74
+ return JSON.stringify(ret);
75
+ }
76
+ return this.formatImpl(obj, nested);
77
+ }
78
+ async validImpl(obj) {
57
79
  if (!(obj instanceof Object)) {
58
80
  return false;
59
81
  }
@@ -63,12 +85,11 @@ class StructField extends field_1.BaseField {
63
85
  for (const k in this.options.fields) {
64
86
  const field = this.options.fields[k];
65
87
  // TODO more #510
66
- let dbKey = (0, camel_case_1.camelCase)(k);
67
- let val = obj[dbKey];
68
- // for tests with snake_case
69
- if (val === undefined && obj[k] !== undefined) {
70
- val = obj[k];
71
- dbKey = k;
88
+ let dbKey = (0, schema_1.getStorageKey)(field, k);
89
+ let camelKey = (0, camel_case_1.camelCase)(k);
90
+ let val = obj[camelKey];
91
+ if (val === undefined && obj[dbKey] !== undefined) {
92
+ val = obj[dbKey];
72
93
  }
73
94
  if (val === undefined || val === null) {
74
95
  // nullable, nothing to do here
@@ -89,6 +110,26 @@ class StructField extends field_1.BaseField {
89
110
  const ret = await Promise.all(promises);
90
111
  return ret.every((v) => v);
91
112
  }
113
+ async valid(obj) {
114
+ if (this.type.globalType) {
115
+ const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
116
+ if (f && f.valid) {
117
+ return f.valid(obj);
118
+ }
119
+ return false;
120
+ }
121
+ if (this.jsonAsList) {
122
+ if (!Array.isArray(obj)) {
123
+ return false;
124
+ }
125
+ const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
126
+ return valid.every((b) => b);
127
+ }
128
+ if (!(obj instanceof Object)) {
129
+ return false;
130
+ }
131
+ return this.validImpl(obj);
132
+ }
92
133
  }
93
134
  exports.StructField = StructField;
94
135
  function StructType(options) {
@@ -96,7 +137,15 @@ function StructType(options) {
96
137
  return Object.assign(result, options);
97
138
  }
98
139
  exports.StructType = StructType;
140
+ /**
141
+ * @deprecated use StructTypeAsList
142
+ */
99
143
  function StructListType(options) {
100
144
  return new field_1.ListField(StructType(options), options);
101
145
  }
102
146
  exports.StructListType = StructListType;
147
+ function StructTypeAsList(options) {
148
+ let result = new StructField(options, true);
149
+ return Object.assign(result, options);
150
+ }
151
+ exports.StructTypeAsList = StructTypeAsList;
@@ -15,7 +15,7 @@ export declare class UnionField extends BaseField implements FieldOptions {
15
15
  type: Type;
16
16
  m: Map<Object, string>;
17
17
  constructor(options: UnionOptions);
18
- format(obj: any): string | Object;
18
+ format(obj: any): any;
19
19
  private validField;
20
20
  valid(obj: any): Promise<boolean>;
21
21
  }
@@ -2,7 +2,11 @@
2
2
  "use strict";
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
@@ -193,7 +197,7 @@ class Compiler {
193
197
  }
194
198
  relPath = path.relative(
195
199
  // just because of how imports work. it's relative from directory not current path
196
- path.dirname(fullPath), path.join(text.substr(0, idx).replace(r, str.substr(0, strIdx)), text.substr(idx)));
200
+ path.dirname(fullPath), path.join(text.substring(0, idx).replace(r, str.substring(0, strIdx)), text.substring(idx)));
197
201
  // if file ends with "..", we've reached a case where we're trying to
198
202
  // import something like foo/contact(.ts) from within foo/contact/bar/baz/page.ts
199
203
  // and we're confused about it so we need to detect that case and handle it
@@ -204,7 +208,7 @@ class Compiler {
204
208
  let text2 = text + ".ts";
205
209
  relPath = path.relative(
206
210
  // just because of how imports work. it's relative from directory not current path
207
- path.dirname(fullPath), path.join(text2.substr(0, idx).replace(r, str.substr(0, strIdx)), text2.substr(idx)));
211
+ path.dirname(fullPath), path.join(text2.substring(0, idx).replace(r, str.substring(0, strIdx)), text2.substring(idx)));
208
212
  }
209
213
  }
210
214
  if (!relPath.startsWith("..")) {
@@ -213,7 +217,7 @@ class Compiler {
213
217
  // tsc removes this by default so we need to also do it
214
218
  let tsIdx = relPath.indexOf(".ts");
215
219
  if (tsIdx !== -1) {
216
- relPath = relPath.substr(0, tsIdx);
220
+ relPath = relPath.substring(0, tsIdx);
217
221
  }
218
222
  return relPath;
219
223
  }
@@ -225,7 +229,7 @@ class Compiler {
225
229
  let relPath = checkPath(paths, text);
226
230
  if (relPath) {
227
231
  // update the node...
228
- return typescript_1.default.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.createLiteral(relPath));
232
+ return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.factory.createStringLiteral(relPath), importNode.assertClause);
229
233
  }
230
234
  }
231
235
  if (node.kind === typescript_1.default.SyntaxKind.ExportDeclaration) {
@@ -235,7 +239,7 @@ class Compiler {
235
239
  let relPath = checkPath(paths, text);
236
240
  if (relPath) {
237
241
  // update the node...
238
- return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.createLiteral(relPath), exportNode.isTypeOnly);
242
+ return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.isTypeOnly);
239
243
  }
240
244
  }
241
245
  }