@snowtop/ent 0.1.0-alpha13 → 0.1.0-alpha131

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 (173) hide show
  1. package/action/action.d.ts +33 -29
  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 +32 -15
  10. package/action/orchestrator.js +249 -53
  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 +61 -37
  18. package/core/base.js +7 -1
  19. package/core/clause.d.ts +85 -40
  20. package/core/clause.js +375 -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 +86 -30
  32. package/core/ent.js +626 -197
  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 +32 -11
  45. package/core/loaders/object_loader.js +225 -78
  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 +51 -19
  71. package/graphql/graphql.js +160 -136
  72. package/graphql/graphql_field_helpers.d.ts +7 -1
  73. package/graphql/graphql_field_helpers.js +21 -1
  74. package/graphql/index.d.ts +2 -2
  75. package/graphql/index.js +3 -5
  76. package/graphql/query/connection_type.d.ts +9 -9
  77. package/graphql/query/edge_connection.d.ts +9 -9
  78. package/graphql/query/page_info.d.ts +1 -1
  79. package/graphql/query/shared_assoc_test.js +1 -1
  80. package/graphql/query/shared_edge_connection.js +1 -19
  81. package/graphql/scalars/orderby_direction.d.ts +2 -0
  82. package/graphql/scalars/orderby_direction.js +15 -0
  83. package/imports/dataz/example1/_auth.js +128 -47
  84. package/imports/dataz/example1/_viewer.js +87 -39
  85. package/imports/index.d.ts +6 -1
  86. package/imports/index.js +19 -4
  87. package/index.d.ts +13 -5
  88. package/index.js +21 -7
  89. package/package.json +17 -17
  90. package/parse_schema/parse.d.ts +31 -9
  91. package/parse_schema/parse.js +155 -13
  92. package/schema/base_schema.d.ts +7 -3
  93. package/schema/base_schema.js +10 -0
  94. package/schema/field.d.ts +78 -21
  95. package/schema/field.js +231 -71
  96. package/schema/index.d.ts +2 -2
  97. package/schema/index.js +5 -1
  98. package/schema/json_field.d.ts +16 -4
  99. package/schema/json_field.js +32 -2
  100. package/schema/schema.d.ts +89 -19
  101. package/schema/schema.js +11 -13
  102. package/schema/struct_field.d.ts +15 -3
  103. package/schema/struct_field.js +117 -22
  104. package/schema/union_field.d.ts +1 -1
  105. package/scripts/custom_compiler.js +10 -6
  106. package/scripts/custom_graphql.js +128 -31
  107. package/scripts/migrate_v0.1.js +36 -0
  108. package/scripts/move_types.js +120 -0
  109. package/scripts/read_schema.js +20 -5
  110. package/testutils/action/complex_schemas.d.ts +69 -0
  111. package/testutils/action/complex_schemas.js +398 -0
  112. package/testutils/builder.d.ts +41 -47
  113. package/testutils/builder.js +76 -49
  114. package/testutils/db/fixture.d.ts +10 -0
  115. package/testutils/db/fixture.js +26 -0
  116. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
  117. package/testutils/db/{test_db.js → temp_db.js} +182 -45
  118. package/testutils/db/value.d.ts +7 -0
  119. package/testutils/db/value.js +251 -0
  120. package/testutils/db_mock.d.ts +16 -4
  121. package/testutils/db_mock.js +52 -7
  122. package/testutils/db_time_zone.d.ts +4 -0
  123. package/testutils/db_time_zone.js +41 -0
  124. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  125. package/testutils/ent-graphql-tests/index.js +52 -23
  126. package/testutils/fake_comms.js +1 -1
  127. package/testutils/fake_data/const.d.ts +2 -1
  128. package/testutils/fake_data/const.js +3 -0
  129. package/testutils/fake_data/fake_contact.d.ts +7 -3
  130. package/testutils/fake_data/fake_contact.js +13 -7
  131. package/testutils/fake_data/fake_event.d.ts +4 -1
  132. package/testutils/fake_data/fake_event.js +7 -6
  133. package/testutils/fake_data/fake_tag.d.ts +36 -0
  134. package/testutils/fake_data/fake_tag.js +89 -0
  135. package/testutils/fake_data/fake_user.d.ts +8 -5
  136. package/testutils/fake_data/fake_user.js +16 -15
  137. package/testutils/fake_data/index.js +5 -1
  138. package/testutils/fake_data/internal.d.ts +2 -0
  139. package/testutils/fake_data/internal.js +7 -1
  140. package/testutils/fake_data/tag_query.d.ts +13 -0
  141. package/testutils/fake_data/tag_query.js +43 -0
  142. package/testutils/fake_data/test_helpers.d.ts +11 -4
  143. package/testutils/fake_data/test_helpers.js +28 -12
  144. package/testutils/fake_data/user_query.d.ts +13 -6
  145. package/testutils/fake_data/user_query.js +54 -22
  146. package/testutils/fake_log.d.ts +3 -3
  147. package/testutils/fake_log.js +1 -1
  148. package/testutils/parse_sql.d.ts +6 -0
  149. package/testutils/parse_sql.js +16 -2
  150. package/testutils/test_edge_global_schema.d.ts +15 -0
  151. package/testutils/test_edge_global_schema.js +62 -0
  152. package/testutils/write.d.ts +2 -2
  153. package/testutils/write.js +33 -7
  154. package/tsc/ast.d.ts +25 -2
  155. package/tsc/ast.js +141 -17
  156. package/tsc/compilerOptions.js +5 -1
  157. package/tsc/move_generated.d.ts +1 -0
  158. package/tsc/move_generated.js +164 -0
  159. package/tsc/transform.d.ts +22 -0
  160. package/tsc/transform.js +181 -0
  161. package/tsc/transform_action.d.ts +22 -0
  162. package/tsc/transform_action.js +183 -0
  163. package/tsc/transform_ent.d.ts +17 -0
  164. package/tsc/transform_ent.js +60 -0
  165. package/tsc/transform_schema.d.ts +27 -0
  166. package/{scripts → tsc}/transform_schema.js +146 -117
  167. package/graphql/enums.d.ts +0 -3
  168. package/graphql/enums.js +0 -25
  169. package/scripts/move_generated.js +0 -142
  170. package/scripts/transform_code.js +0 -113
  171. package/scripts/transform_schema.d.ts +0 -1
  172. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  173. /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[];
@@ -25,6 +38,7 @@ export default interface Schema {
25
38
  constraints?: Constraint[];
26
39
  indices?: Index[];
27
40
  hideFromGraphQL?: boolean;
41
+ customGraphQLInterfaces?: string[];
28
42
  }
29
43
  export interface AssocEdge {
30
44
  name: string;
@@ -61,17 +75,30 @@ export interface AssocEdgeGroup {
61
75
  tableName?: string;
62
76
  assocEdges: AssocEdge[];
63
77
  statusEnums?: string[];
64
- nullStates: string | string[];
78
+ viewerBased?: boolean;
79
+ nullStates?: string | string[];
65
80
  nullStateFn?: string;
66
81
  edgeAction?: EdgeGroupAction;
67
82
  }
68
- export declare type Edge = AssocEdge;
83
+ export type Edge = AssocEdge;
84
+ interface ImportPath {
85
+ importPath: string;
86
+ import: string;
87
+ defaultImport?: boolean;
88
+ originalImport?: string;
89
+ }
90
+ export interface TransformReadBetaResult {
91
+ code: string;
92
+ imports: ImportPath[];
93
+ }
69
94
  export interface Pattern {
70
95
  name: string;
71
- fields: FieldMap | Field[];
96
+ fields: FieldMap;
97
+ disableMixin?: boolean;
72
98
  edges?: Edge[];
73
99
  transformRead?: () => Clause;
74
- transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
100
+ transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
101
+ transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
75
102
  transformsDelete?: boolean;
76
103
  transformsInsert?: boolean;
77
104
  transformsUpdate?: boolean;
@@ -81,16 +108,25 @@ export declare enum SQLStatementOperation {
81
108
  Update = "update",
82
109
  Delete = "delete"
83
110
  }
84
- export interface UpdateOperation<T extends Ent> {
111
+ export interface EdgeUpdateOperation {
112
+ op: SQLStatementOperation;
113
+ edge: AssocEdgeInput;
114
+ }
115
+ export interface TransformedEdgeUpdateOperation {
85
116
  op: SQLStatementOperation;
86
- existingEnt: T | null;
87
- viewer: Viewer;
117
+ data?: Data;
118
+ }
119
+ export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
120
+ op: SQLStatementOperation;
121
+ builder: Builder<TEnt, TViewer, any>;
122
+ input: Data;
88
123
  data?: Map<string, any>;
89
124
  }
90
- export interface TransformedUpdateOperation<T extends Ent> {
125
+ export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
91
126
  op: SQLStatementOperation;
92
127
  data?: Data;
93
128
  existingEnt?: T | null;
129
+ changeset?(): Promise<Changeset> | Changeset;
94
130
  }
95
131
  export declare enum DBType {
96
132
  UUID = "UUID",
@@ -106,19 +142,27 @@ export declare enum DBType {
106
142
  JSONB = "JSONB",
107
143
  Enum = "Enum",
108
144
  StringEnum = "StringEnum",
145
+ IntEnum = "IntEnum",
109
146
  Date = "Date",
110
147
  Time = "Time",
111
148
  Timetz = "Timetz",
112
149
  List = "List"
113
150
  }
114
- export interface ImportType {
151
+ export interface DeprecatedImportType {
115
152
  path: string;
116
153
  type: string;
117
154
  [x: string]: any;
118
155
  }
156
+ export interface ConvertType {
157
+ path: string;
158
+ function: string;
159
+ }
119
160
  declare type EnumMap = {
120
161
  [key: string]: string;
121
162
  };
163
+ declare type IntEnumMap = {
164
+ [key: string]: number;
165
+ };
122
166
  export interface Type {
123
167
  dbType: DBType;
124
168
  listElemType?: Type;
@@ -126,9 +170,14 @@ export interface Type {
126
170
  graphQLType?: string;
127
171
  values?: string[];
128
172
  enumMap?: EnumMap;
129
- importType?: ImportType;
173
+ intEnumMap?: IntEnumMap;
174
+ deprecatedIntEnumMap?: IntEnumMap;
175
+ disableUnknownType?: boolean;
176
+ globalType?: string;
177
+ importType?: DeprecatedImportType;
130
178
  subFields?: FieldMap;
131
179
  unionFields?: FieldMap;
180
+ [x: string]: any;
132
181
  }
133
182
  export interface ForeignKey {
134
183
  schema: string;
@@ -136,8 +185,9 @@ export interface ForeignKey {
136
185
  name?: string;
137
186
  disableIndex?: boolean;
138
187
  disableBuilderType?: boolean;
188
+ [x: string]: any;
139
189
  }
140
- declare type getLoaderInfoFn = (type: string) => LoaderInfo;
190
+ type getLoaderInfoFn = (type: string) => LoaderInfo;
141
191
  export interface InverseFieldEdge {
142
192
  name: string;
143
193
  edgeConstName?: string;
@@ -151,45 +201,56 @@ export interface FieldEdge {
151
201
  getLoaderInfoFromSchema?: getLoaderInfoFn;
152
202
  disableBuilderType?: boolean;
153
203
  }
204
+ interface PrivateOptions {
205
+ exposeToActions?: boolean;
206
+ }
154
207
  export interface FieldOptions {
155
208
  nullable?: boolean;
156
209
  storageKey?: string;
157
210
  serverDefault?: any;
158
211
  unique?: boolean;
159
212
  hideFromGraphQL?: boolean;
160
- private?: boolean;
213
+ private?: boolean | PrivateOptions;
161
214
  sensitive?: boolean;
162
215
  graphqlName?: string;
163
216
  index?: boolean;
164
217
  foreignKey?: ForeignKey;
165
218
  fieldEdge?: FieldEdge;
166
219
  primaryKey?: boolean;
220
+ immutable?: boolean;
167
221
  disableUserEditable?: boolean;
168
222
  disableUserGraphQLEditable?: boolean;
169
223
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
170
224
  defaultToViewerOnCreate?: boolean;
225
+ onlyUpdateIfOtherFieldsBeingSet_BETA?: boolean;
171
226
  defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
172
227
  derivedWhenEmbedded?: boolean;
173
228
  polymorphic?: boolean | PolymorphicOptions;
174
229
  privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
175
230
  getDerivedFields?(name: string): FieldMap;
231
+ convert?: ConvertType;
232
+ fetchOnDemand?: boolean;
233
+ dbOnly?: boolean;
176
234
  [x: string]: any;
177
235
  }
178
236
  export interface PolymorphicOptions {
237
+ name?: string;
179
238
  types?: string[];
180
239
  hideFromInverseGraphQL?: boolean;
181
240
  disableBuilderType?: boolean;
241
+ serverDefault?: any;
182
242
  }
183
243
  export interface Field extends FieldOptions {
184
244
  type: Type;
185
245
  valid?(val: any): Promise<boolean> | boolean;
246
+ validateWithFullData?(val: any, builder: Builder<any>): boolean | Promise<boolean>;
186
247
  format?(val: any, nested?: boolean): any;
187
248
  logValue(val: any): any;
188
249
  }
189
250
  export interface SchemaConstructor {
190
251
  new (): Schema;
191
252
  }
192
- export declare type SchemaInputType = Schema | SchemaConstructor;
253
+ export type SchemaInputType = Schema | SchemaConstructor;
193
254
  export declare function getSchema(value: SchemaInputType): Schema;
194
255
  export declare function getFields(value: SchemaInputType): Map<string, Field>;
195
256
  /**
@@ -203,7 +264,7 @@ interface objectLoaderOptions {
203
264
  instanceKey?: string;
204
265
  }
205
266
  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> | null;
267
+ export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
207
268
  export declare enum ActionOperation {
208
269
  Create = 1,
209
270
  Edit = 2,
@@ -213,15 +274,18 @@ export declare enum ActionOperation {
213
274
  RemoveEdge = 32,
214
275
  EdgeGroup = 64
215
276
  }
216
- declare type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "Object";
217
- declare type NullableListOptions = "contents" | "contentsAndList";
277
+ type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "JSON" | "Object";
278
+ type NullableListOptions = "contents" | "contentsAndList";
218
279
  export interface ActionField {
219
280
  name: string;
220
281
  type: actionFieldType;
221
282
  nullable?: boolean | NullableListOptions;
283
+ optional?: boolean;
222
284
  list?: boolean;
223
285
  actionName?: string;
224
286
  excludedFields?: string[];
287
+ hideFromGraphQL?: boolean;
288
+ [x: string]: any;
225
289
  }
226
290
  export interface Action {
227
291
  operation: ActionOperation;
@@ -235,6 +299,7 @@ export interface Action {
235
299
  optionalFields?: string[];
236
300
  requiredFields?: string[];
237
301
  noFields?: boolean;
302
+ [x: string]: any;
238
303
  }
239
304
  export declare const NoFields = "__NO_FIELDS__";
240
305
  export declare function requiredField(field: string): string;
@@ -245,6 +310,7 @@ export interface Constraint {
245
310
  columns: string[];
246
311
  fkey?: ForeignKeyInfo;
247
312
  condition?: string;
313
+ [x: string]: any;
248
314
  }
249
315
  export interface FullTextWeight {
250
316
  A?: string[];
@@ -258,17 +324,21 @@ export interface FullText {
258
324
  languageColumn?: string;
259
325
  indexType?: "gin" | "gist";
260
326
  weights?: FullTextWeight;
327
+ [x: string]: any;
261
328
  }
262
329
  export interface Index {
263
330
  name: string;
264
331
  columns: string[];
265
332
  unique?: boolean;
266
333
  fulltext?: FullText;
334
+ indexType?: "gin" | "btree";
335
+ [x: string]: any;
267
336
  }
268
337
  export interface ForeignKeyInfo {
269
338
  tableName: string;
270
339
  ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
271
340
  columns: string[];
341
+ [x: string]: any;
272
342
  }
273
343
  export declare enum ConstraintType {
274
344
  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),
@@ -209,6 +204,9 @@ var ActionOperation;
209
204
  // RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
210
205
  ActionOperation[ActionOperation["RemoveEdge"] = 32] = "RemoveEdge";
211
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
212
210
  ActionOperation[ActionOperation["EdgeGroup"] = 64] = "EdgeGroup";
213
211
  })(ActionOperation = exports.ActionOperation || (exports.ActionOperation = {}));
214
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,51 @@
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");
8
+ const logger_1 = require("../core/logger");
7
9
  class StructField extends field_1.BaseField {
8
- constructor(options) {
10
+ constructor(options, jsonAsList) {
9
11
  super();
10
12
  this.options = options;
13
+ this.jsonAsList = jsonAsList;
11
14
  this.type = {
12
15
  dbType: schema_1.DBType.JSONB,
13
16
  };
14
17
  this.type.subFields = options.fields;
15
18
  this.type.type = options.tsType;
16
19
  this.type.graphQLType = options.graphQLType || options.tsType;
20
+ this.type.globalType = this.options.globalType;
17
21
  if (options.jsonNotJSONB) {
18
22
  this.type.dbType = schema_1.DBType.JSON;
19
23
  }
24
+ if (jsonAsList) {
25
+ this.type.listElemType = {
26
+ dbType: schema_1.DBType.JSONB,
27
+ };
28
+ }
20
29
  }
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) {
30
+ formatImpl(obj, nested) {
25
31
  if (!(obj instanceof Object)) {
26
32
  throw new Error("valid was not called");
27
33
  }
28
34
  let ret = {};
29
35
  for (const k in this.options.fields) {
36
+ const field = this.options.fields[k];
37
+ // check two values
38
+ // store in dbKey format
30
39
  // 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;
40
+ let dbKey = (0, schema_1.getStorageKey)(field, k);
41
+ let camelKey = (0, camel_case_1.camelCase)(k);
42
+ let val = obj[camelKey];
43
+ if (val === undefined && obj[dbKey] !== undefined) {
44
+ val = obj[dbKey];
37
45
  }
38
46
  if (val === undefined) {
39
47
  continue;
40
48
  }
41
- const field = this.options.fields[k];
42
49
  if (field.format) {
43
50
  // indicate nested so this isn't JSON stringified
44
51
  ret[dbKey] = field.format(val, true);
@@ -47,13 +54,53 @@ class StructField extends field_1.BaseField {
47
54
  ret[dbKey] = val;
48
55
  }
49
56
  }
50
- // don't json.stringify if nested
57
+ // don't json.stringify if nested or list
51
58
  if (nested) {
52
59
  return ret;
53
60
  }
54
61
  return JSON.stringify(ret);
55
62
  }
56
- async valid(obj) {
63
+ format(obj, nested) {
64
+ if (this.type.globalType) {
65
+ const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
66
+ if (f && f.format) {
67
+ if (JSON.stringify(this.type.listElemType) !==
68
+ JSON.stringify(f?.type.listElemType)) {
69
+ if (this.jsonAsList) {
70
+ // handle as nested
71
+ // @ts-ignore
72
+ const formatted = obj.map((v) => f.format(v, true));
73
+ if (nested) {
74
+ return formatted;
75
+ }
76
+ else {
77
+ return JSON.stringify(formatted);
78
+ }
79
+ }
80
+ else {
81
+ const formatted = f.format([obj], true);
82
+ if (nested) {
83
+ return formatted[0];
84
+ }
85
+ else {
86
+ return JSON.stringify(formatted[0]);
87
+ }
88
+ }
89
+ }
90
+ // TODO handle format code
91
+ return f.format(obj);
92
+ }
93
+ }
94
+ if (Array.isArray(obj) && this.jsonAsList) {
95
+ const ret = obj.map((v) => this.formatImpl(v, true));
96
+ if (nested) {
97
+ return ret;
98
+ }
99
+ return JSON.stringify(ret);
100
+ }
101
+ return this.formatImpl(obj, nested);
102
+ }
103
+ async validImpl(obj) {
57
104
  if (!(obj instanceof Object)) {
58
105
  return false;
59
106
  }
@@ -63,12 +110,11 @@ class StructField extends field_1.BaseField {
63
110
  for (const k in this.options.fields) {
64
111
  const field = this.options.fields[k];
65
112
  // 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;
113
+ let dbKey = (0, schema_1.getStorageKey)(field, k);
114
+ let camelKey = (0, camel_case_1.camelCase)(k);
115
+ let val = obj[camelKey];
116
+ if (val === undefined && obj[dbKey] !== undefined) {
117
+ val = obj[dbKey];
72
118
  }
73
119
  if (val === undefined || val === null) {
74
120
  // nullable, nothing to do here
@@ -89,6 +135,47 @@ class StructField extends field_1.BaseField {
89
135
  const ret = await Promise.all(promises);
90
136
  return ret.every((v) => v);
91
137
  }
138
+ async valid(obj) {
139
+ if (this.type.globalType) {
140
+ const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
141
+ // list and global type is not valid.
142
+ if (f) {
143
+ if (f.valid) {
144
+ if (JSON.stringify(this.type.listElemType) !==
145
+ JSON.stringify(f?.type.listElemType)) {
146
+ if (this.jsonAsList) {
147
+ if (!Array.isArray(obj)) {
148
+ return false;
149
+ }
150
+ // @ts-ignore
151
+ const valid = await Promise.all(obj.map((v) => f.valid(v)));
152
+ return valid.every((b) => b);
153
+ }
154
+ else {
155
+ return f.valid([obj]);
156
+ }
157
+ }
158
+ return f.valid(obj);
159
+ }
160
+ return true;
161
+ }
162
+ else {
163
+ (0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
164
+ return false;
165
+ }
166
+ }
167
+ if (this.jsonAsList) {
168
+ if (!Array.isArray(obj)) {
169
+ return false;
170
+ }
171
+ const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
172
+ return valid.every((b) => b);
173
+ }
174
+ if (!(obj instanceof Object)) {
175
+ return false;
176
+ }
177
+ return this.validImpl(obj);
178
+ }
92
179
  }
93
180
  exports.StructField = StructField;
94
181
  function StructType(options) {
@@ -96,7 +183,15 @@ function StructType(options) {
96
183
  return Object.assign(result, options);
97
184
  }
98
185
  exports.StructType = StructType;
186
+ /**
187
+ * @deprecated use StructTypeAsList
188
+ */
99
189
  function StructListType(options) {
100
190
  return new field_1.ListField(StructType(options), options);
101
191
  }
102
192
  exports.StructListType = StructListType;
193
+ function StructTypeAsList(options) {
194
+ let result = new StructField(options, true);
195
+ return Object.assign(result, options);
196
+ }
197
+ 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.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.factory.updateExportDeclaration(exportNode, exportNode.modifiers, exportNode.isTypeOnly, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.assertClause);
239
243
  }
240
244
  }
241
245
  }