@snowtop/ent 0.1.0-alpha16 → 0.1.0-alpha160-test1

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 (176) hide show
  1. package/action/action.d.ts +25 -14
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +16 -3
  4. package/action/executor.js +89 -28
  5. package/action/experimental_action.d.ts +25 -16
  6. package/action/experimental_action.js +34 -14
  7. package/action/index.d.ts +4 -1
  8. package/action/index.js +7 -1
  9. package/action/operations.d.ts +126 -0
  10. package/action/operations.js +686 -0
  11. package/action/orchestrator.d.ts +43 -12
  12. package/action/orchestrator.js +461 -101
  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 +56 -23
  19. package/core/base.js +7 -1
  20. package/core/clause.d.ts +103 -39
  21. package/core/clause.js +430 -66
  22. package/core/config.d.ts +13 -3
  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 +6 -3
  27. package/core/context.js +22 -3
  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 +21 -9
  32. package/core/ent.d.ts +99 -95
  33. package/core/ent.js +550 -602
  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 +5 -2
  37. package/core/loaders/assoc_count_loader.js +19 -3
  38. package/core/loaders/assoc_edge_loader.d.ts +2 -3
  39. package/core/loaders/assoc_edge_loader.js +23 -17
  40. package/core/loaders/index.d.ts +1 -2
  41. package/core/loaders/index.js +1 -5
  42. package/core/loaders/loader.d.ts +3 -3
  43. package/core/loaders/loader.js +4 -21
  44. package/core/loaders/object_loader.d.ts +30 -9
  45. package/core/loaders/object_loader.js +226 -79
  46. package/core/loaders/query_loader.d.ts +7 -13
  47. package/core/loaders/query_loader.js +60 -24
  48. package/core/loaders/raw_count_loader.d.ts +1 -0
  49. package/core/loaders/raw_count_loader.js +8 -3
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +26 -16
  53. package/core/privacy.js +68 -51
  54. package/core/query/assoc_query.d.ts +3 -2
  55. package/core/query/assoc_query.js +10 -2
  56. package/core/query/custom_clause_query.d.ts +29 -0
  57. package/core/query/custom_clause_query.js +105 -0
  58. package/core/query/custom_query.d.ts +19 -2
  59. package/core/query/custom_query.js +111 -13
  60. package/core/query/index.d.ts +1 -0
  61. package/core/query/index.js +3 -1
  62. package/core/query/query.d.ts +18 -4
  63. package/core/query/query.js +135 -58
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +186 -55
  66. package/core/query/shared_test.d.ts +9 -2
  67. package/core/query/shared_test.js +529 -236
  68. package/core/query_impl.d.ts +8 -0
  69. package/core/query_impl.js +28 -0
  70. package/core/viewer.d.ts +2 -0
  71. package/core/viewer.js +3 -1
  72. package/graphql/graphql.d.ts +108 -22
  73. package/graphql/graphql.js +183 -137
  74. package/graphql/graphql_field_helpers.d.ts +9 -3
  75. package/graphql/graphql_field_helpers.js +22 -2
  76. package/graphql/index.d.ts +2 -2
  77. package/graphql/index.js +5 -5
  78. package/graphql/query/connection_type.d.ts +9 -9
  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 +7 -2
  86. package/imports/index.js +20 -5
  87. package/index.d.ts +23 -5
  88. package/index.js +35 -10
  89. package/package.json +19 -19
  90. package/parse_schema/parse.d.ts +33 -9
  91. package/parse_schema/parse.js +182 -33
  92. package/schema/base_schema.d.ts +13 -3
  93. package/schema/base_schema.js +13 -0
  94. package/schema/field.d.ts +78 -21
  95. package/schema/field.js +232 -72
  96. package/schema/index.d.ts +2 -2
  97. package/schema/index.js +7 -2
  98. package/schema/json_field.d.ts +16 -4
  99. package/schema/json_field.js +32 -2
  100. package/schema/schema.d.ts +109 -20
  101. package/schema/schema.js +42 -53
  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 +12 -8
  106. package/scripts/custom_graphql.js +171 -64
  107. package/scripts/migrate_v0.1.js +36 -0
  108. package/scripts/move_types.js +120 -0
  109. package/scripts/read_schema.js +22 -7
  110. package/testutils/action/complex_schemas.d.ts +69 -0
  111. package/testutils/action/complex_schemas.js +405 -0
  112. package/testutils/builder.d.ts +37 -41
  113. package/testutils/builder.js +66 -46
  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} +32 -8
  117. package/testutils/db/{test_db.js → temp_db.js} +251 -48
  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 -9
  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 +56 -26
  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 +31 -19
  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 +48 -0
  142. package/testutils/fake_data/test_helpers.d.ts +14 -6
  143. package/testutils/fake_data/test_helpers.js +31 -15
  144. package/testutils/fake_data/user_query.d.ts +16 -6
  145. package/testutils/fake_data/user_query.js +72 -23
  146. package/testutils/fake_log.js +1 -1
  147. package/testutils/parse_sql.d.ts +6 -0
  148. package/testutils/parse_sql.js +16 -2
  149. package/testutils/test_edge_global_schema.d.ts +15 -0
  150. package/testutils/test_edge_global_schema.js +62 -0
  151. package/testutils/write.d.ts +2 -2
  152. package/testutils/write.js +33 -7
  153. package/tsc/ast.d.ts +15 -3
  154. package/tsc/ast.js +114 -23
  155. package/tsc/compilerOptions.js +5 -1
  156. package/tsc/move_generated.d.ts +1 -0
  157. package/tsc/move_generated.js +164 -0
  158. package/tsc/transform.d.ts +22 -0
  159. package/tsc/transform.js +182 -0
  160. package/tsc/transform_action.d.ts +22 -0
  161. package/tsc/transform_action.js +183 -0
  162. package/tsc/transform_ent.d.ts +17 -0
  163. package/tsc/transform_ent.js +60 -0
  164. package/tsc/transform_schema.d.ts +27 -0
  165. package/{scripts → tsc}/transform_schema.js +146 -117
  166. package/core/loaders/index_loader.d.ts +0 -14
  167. package/core/loaders/index_loader.js +0 -27
  168. package/graphql/enums.d.ts +0 -3
  169. package/graphql/enums.js +0 -25
  170. package/scripts/move_generated.js +0 -141
  171. package/scripts/transform_actions.js +0 -266
  172. package/scripts/transform_code.d.ts +0 -1
  173. package/scripts/transform_code.js +0 -111
  174. package/scripts/transform_schema.d.ts +0 -1
  175. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  176. /package/scripts/{transform_actions.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 "../action/operations";
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,10 @@ export default interface Schema {
25
38
  constraints?: Constraint[];
26
39
  indices?: Index[];
27
40
  hideFromGraphQL?: boolean;
41
+ customGraphQLInterfaces?: string[];
42
+ supportUpsert?: boolean;
43
+ showCanViewerSee?: boolean;
44
+ showCanViewerEdit?: boolean;
28
45
  }
29
46
  export interface AssocEdge {
30
47
  name: string;
@@ -43,6 +60,7 @@ export interface EdgeAction {
43
60
  hideFromGraphQL?: boolean;
44
61
  graphQLName?: string;
45
62
  actionOnlyFields?: ActionField[];
63
+ canViewerDo?: boolean | CanViewerDo;
46
64
  }
47
65
  export interface InverseAssocEdge {
48
66
  name: string;
@@ -54,6 +72,7 @@ export interface EdgeGroupAction {
54
72
  hideFromGraphQL?: boolean;
55
73
  graphQLName?: string;
56
74
  actionOnlyFields?: ActionField[];
75
+ canViewerDo?: boolean | CanViewerDo;
57
76
  }
58
77
  export interface AssocEdgeGroup {
59
78
  name: string;
@@ -61,18 +80,30 @@ export interface AssocEdgeGroup {
61
80
  tableName?: string;
62
81
  assocEdges: AssocEdge[];
63
82
  statusEnums?: string[];
64
- nullStates: string | string[];
83
+ viewerBased?: boolean;
84
+ nullStates?: string | string[];
65
85
  nullStateFn?: string;
66
86
  edgeAction?: EdgeGroupAction;
67
87
  }
68
- export declare type Edge = AssocEdge;
88
+ export type Edge = AssocEdge;
89
+ export interface ImportPath {
90
+ importPath: string;
91
+ import: string;
92
+ defaultImport?: boolean;
93
+ originalImport?: string;
94
+ }
95
+ export interface TransformReadBetaResult {
96
+ code: string;
97
+ imports: ImportPath[];
98
+ }
69
99
  export interface Pattern {
70
100
  name: string;
71
- fields: FieldMap | Field[];
101
+ fields: FieldMap;
72
102
  disableMixin?: boolean;
73
103
  edges?: Edge[];
74
104
  transformRead?: () => Clause;
75
- transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
105
+ transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
106
+ transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
76
107
  transformsDelete?: boolean;
77
108
  transformsInsert?: boolean;
78
109
  transformsUpdate?: boolean;
@@ -82,16 +113,25 @@ export declare enum SQLStatementOperation {
82
113
  Update = "update",
83
114
  Delete = "delete"
84
115
  }
85
- export interface UpdateOperation<T extends Ent> {
116
+ export interface EdgeUpdateOperation {
117
+ op: SQLStatementOperation;
118
+ edge: AssocEdgeInput;
119
+ }
120
+ export interface TransformedEdgeUpdateOperation {
86
121
  op: SQLStatementOperation;
87
- existingEnt: T | null;
88
- viewer: Viewer;
122
+ data?: Data;
123
+ }
124
+ export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
125
+ op: SQLStatementOperation;
126
+ builder: Builder<TEnt, TViewer, any>;
127
+ input: Data;
89
128
  data?: Map<string, any>;
90
129
  }
91
- export interface TransformedUpdateOperation<T extends Ent> {
130
+ export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
92
131
  op: SQLStatementOperation;
93
132
  data?: Data;
94
133
  existingEnt?: T | null;
134
+ changeset?(): Promise<Changeset> | Changeset;
95
135
  }
96
136
  export declare enum DBType {
97
137
  UUID = "UUID",
@@ -107,19 +147,27 @@ export declare enum DBType {
107
147
  JSONB = "JSONB",
108
148
  Enum = "Enum",
109
149
  StringEnum = "StringEnum",
150
+ IntEnum = "IntEnum",
110
151
  Date = "Date",
111
152
  Time = "Time",
112
153
  Timetz = "Timetz",
113
154
  List = "List"
114
155
  }
115
- export interface ImportType {
156
+ export interface DeprecatedImportType {
116
157
  path: string;
117
158
  type: string;
118
159
  [x: string]: any;
119
160
  }
161
+ export interface ConvertType {
162
+ path: string;
163
+ function: string;
164
+ }
120
165
  declare type EnumMap = {
121
166
  [key: string]: string;
122
167
  };
168
+ declare type IntEnumMap = {
169
+ [key: string]: number;
170
+ };
123
171
  export interface Type {
124
172
  dbType: DBType;
125
173
  listElemType?: Type;
@@ -127,9 +175,14 @@ export interface Type {
127
175
  graphQLType?: string;
128
176
  values?: string[];
129
177
  enumMap?: EnumMap;
130
- importType?: ImportType;
178
+ intEnumMap?: IntEnumMap;
179
+ deprecatedIntEnumMap?: IntEnumMap;
180
+ disableUnknownType?: boolean;
181
+ globalType?: string;
182
+ importType?: DeprecatedImportType;
131
183
  subFields?: FieldMap;
132
184
  unionFields?: FieldMap;
185
+ [x: string]: any;
133
186
  }
134
187
  export interface ForeignKey {
135
188
  schema: string;
@@ -137,20 +190,29 @@ export interface ForeignKey {
137
190
  name?: string;
138
191
  disableIndex?: boolean;
139
192
  disableBuilderType?: boolean;
193
+ [x: string]: any;
140
194
  }
141
- declare type getLoaderInfoFn = (type: string) => LoaderInfo;
195
+ type getLoaderInfoFn = (type: string) => LoaderInfo;
142
196
  export interface InverseFieldEdge {
143
197
  name: string;
144
198
  edgeConstName?: string;
145
199
  tableName?: string;
146
200
  hideFromGraphQL?: boolean;
147
201
  }
202
+ export interface IndexEdgeOptions {
203
+ name: string;
204
+ }
148
205
  export interface FieldEdge {
149
206
  schema: string;
150
207
  inverseEdge?: string | InverseFieldEdge;
208
+ indexEdge?: IndexEdgeOptions;
151
209
  enforceSchema?: boolean;
152
210
  getLoaderInfoFromSchema?: getLoaderInfoFn;
153
211
  disableBuilderType?: boolean;
212
+ edgeConstName?: string;
213
+ }
214
+ interface PrivateOptions {
215
+ exposeToActions?: boolean;
154
216
  }
155
217
  export interface FieldOptions {
156
218
  nullable?: boolean;
@@ -158,53 +220,66 @@ export interface FieldOptions {
158
220
  serverDefault?: any;
159
221
  unique?: boolean;
160
222
  hideFromGraphQL?: boolean;
161
- private?: boolean;
223
+ private?: boolean | PrivateOptions;
162
224
  sensitive?: boolean;
163
225
  graphqlName?: string;
164
226
  index?: boolean;
165
227
  foreignKey?: ForeignKey;
166
228
  fieldEdge?: FieldEdge;
167
229
  primaryKey?: boolean;
230
+ immutable?: boolean;
168
231
  disableUserEditable?: boolean;
169
232
  disableUserGraphQLEditable?: boolean;
170
233
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
171
234
  defaultToViewerOnCreate?: boolean;
235
+ onlyUpdateIfOtherFieldsBeingSet_BETA?: boolean;
172
236
  defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
173
237
  derivedWhenEmbedded?: boolean;
174
238
  polymorphic?: boolean | PolymorphicOptions;
175
239
  privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
240
+ editPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
241
+ createOnlyOverrideEditPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
176
242
  getDerivedFields?(name: string): FieldMap;
243
+ convert?: ConvertType;
244
+ fetchOnDemand?: boolean;
245
+ dbOnly?: boolean;
177
246
  [x: string]: any;
178
247
  }
179
248
  export interface PolymorphicOptions {
249
+ name?: string;
180
250
  types?: string[];
181
251
  hideFromInverseGraphQL?: boolean;
182
252
  disableBuilderType?: boolean;
253
+ serverDefault?: any;
254
+ edgeConstName?: string;
183
255
  }
184
256
  export interface Field extends FieldOptions {
185
257
  type: Type;
186
258
  valid?(val: any): Promise<boolean> | boolean;
259
+ validateWithFullData?(val: any, builder: Builder<any>): boolean | Promise<boolean>;
187
260
  format?(val: any, nested?: boolean): any;
188
261
  logValue(val: any): any;
189
262
  }
190
263
  export interface SchemaConstructor {
191
264
  new (): Schema;
192
265
  }
193
- export declare type SchemaInputType = Schema | SchemaConstructor;
266
+ export type SchemaInputType = Schema | SchemaConstructor;
194
267
  export declare function getSchema(value: SchemaInputType): Schema;
195
268
  export declare function getFields(value: SchemaInputType): Map<string, Field>;
196
269
  /**
197
270
  * @deprecated should only be used by tests
198
271
  */
199
272
  export declare function getStorageKey(field: Field, fieldName: string): string;
200
- export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
273
+ export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
274
+ export declare function getFieldsWithEditPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
275
+ export declare function getFieldsForCreateAction(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
201
276
  export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
202
277
  interface objectLoaderOptions {
203
278
  clause?: () => Clause | undefined;
204
279
  instanceKey?: string;
205
280
  }
206
281
  export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
207
- export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | null;
282
+ export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
208
283
  export declare enum ActionOperation {
209
284
  Create = 1,
210
285
  Edit = 2,
@@ -214,15 +289,18 @@ export declare enum ActionOperation {
214
289
  RemoveEdge = 32,
215
290
  EdgeGroup = 64
216
291
  }
217
- declare type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "Object";
218
- declare type NullableListOptions = "contents" | "contentsAndList";
292
+ type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "JSON" | "Object";
293
+ type NullableListOptions = "contents" | "contentsAndList";
219
294
  export interface ActionField {
220
295
  name: string;
221
296
  type: actionFieldType;
222
297
  nullable?: boolean | NullableListOptions;
298
+ optional?: boolean;
223
299
  list?: boolean;
224
300
  actionName?: string;
225
301
  excludedFields?: string[];
302
+ hideFromGraphQL?: boolean;
303
+ [x: string]: any;
226
304
  }
227
305
  export interface Action {
228
306
  operation: ActionOperation;
@@ -236,6 +314,12 @@ export interface Action {
236
314
  optionalFields?: string[];
237
315
  requiredFields?: string[];
238
316
  noFields?: boolean;
317
+ canViewerDo?: boolean | CanViewerDo;
318
+ [x: string]: any;
319
+ }
320
+ export interface CanViewerDo {
321
+ addAllFields?: boolean;
322
+ inputFields?: string[];
239
323
  }
240
324
  export declare const NoFields = "__NO_FIELDS__";
241
325
  export declare function requiredField(field: string): string;
@@ -246,6 +330,7 @@ export interface Constraint {
246
330
  columns: string[];
247
331
  fkey?: ForeignKeyInfo;
248
332
  condition?: string;
333
+ [x: string]: any;
249
334
  }
250
335
  export interface FullTextWeight {
251
336
  A?: string[];
@@ -259,17 +344,21 @@ export interface FullText {
259
344
  languageColumn?: string;
260
345
  indexType?: "gin" | "gist";
261
346
  weights?: FullTextWeight;
347
+ [x: string]: any;
262
348
  }
263
349
  export interface Index {
264
350
  name: string;
265
351
  columns: string[];
266
352
  unique?: boolean;
267
353
  fulltext?: FullText;
354
+ indexType?: "gin" | "btree";
355
+ [x: string]: any;
268
356
  }
269
357
  export interface ForeignKeyInfo {
270
358
  tableName: string;
271
359
  ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
272
360
  columns: string[];
361
+ [x: string]: any;
273
362
  }
274
363
  export declare enum ConstraintType {
275
364
  PrimaryKey = "primary",
package/schema/schema.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
3
+ exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsForCreateAction = exports.getFieldsWithEditPrivacy = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
4
4
  const snake_case_1 = require("snake-case");
5
5
  // we also want this transformation to exist on a per-action basis
6
6
  // if it exists on an action, we don't do the global schema transformation
@@ -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
  }
@@ -94,52 +85,45 @@ function getStorageKey(field, fieldName) {
94
85
  }
95
86
  exports.getStorageKey = getStorageKey;
96
87
  // returns a mapping of storage key to field privacy
97
- function getFieldsWithPrivacy(value, fieldMap) {
88
+ function getFieldsWithPrivacy(value, fieldInfoMap) {
89
+ return getFieldsWithPrivacyImpl(value, fieldInfoMap, ["privacyPolicy"]);
90
+ }
91
+ exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
92
+ function getFieldsWithEditPrivacy(value, fieldInfoMap) {
93
+ return getFieldsWithPrivacyImpl(value, fieldInfoMap, ["editPrivacyPolicy"]);
94
+ }
95
+ exports.getFieldsWithEditPrivacy = getFieldsWithEditPrivacy;
96
+ function getFieldsForCreateAction(value, fieldInfoMap) {
97
+ return getFieldsWithPrivacyImpl(value, fieldInfoMap, [
98
+ "createOnlyOverrideEditPrivacyPolicy",
99
+ "editPrivacyPolicy",
100
+ ]);
101
+ }
102
+ exports.getFieldsForCreateAction = getFieldsForCreateAction;
103
+ function getFieldsWithPrivacyImpl(value, fieldInfoMap, keys) {
98
104
  const schema = getSchema(value);
99
105
  function addFields(fields) {
100
- if (Array.isArray(fields)) {
101
- for (const field of fields) {
102
- const name = field.name;
103
- if (!field.name) {
104
- throw new Error(`name required`);
105
- }
106
- if (field.getDerivedFields !== undefined) {
107
- addFields(field.getDerivedFields(name));
108
- }
109
- if (field.privacyPolicy) {
110
- let privacyPolicy;
111
- if (typeof field.privacyPolicy === "function") {
112
- privacyPolicy = field.privacyPolicy();
113
- }
114
- else {
115
- privacyPolicy = field.privacyPolicy;
116
- }
117
- const info = fieldMap[name];
118
- if (!info) {
119
- throw new Error(`field with name ${name} not passed in fieldMap`);
120
- }
121
- m.set(info.dbCol, privacyPolicy);
122
- }
123
- }
124
- }
125
106
  for (const name in fields) {
126
107
  const field = fields[name];
108
+ if (field.dbOnly) {
109
+ continue;
110
+ }
127
111
  if (field.getDerivedFields !== undefined) {
128
112
  addFields(field.getDerivedFields(name));
129
113
  }
130
- if (field.privacyPolicy) {
131
- let privacyPolicy;
132
- if (typeof field.privacyPolicy === "function") {
133
- privacyPolicy = field.privacyPolicy();
134
- }
135
- else {
136
- privacyPolicy = field.privacyPolicy;
137
- }
138
- const info = fieldMap[name];
139
- if (!info) {
140
- throw new Error(`field with name ${name} not passed in fieldMap`);
114
+ for (const key of keys) {
115
+ let privacyPolicy = field[key];
116
+ if (privacyPolicy) {
117
+ if (typeof privacyPolicy === "function") {
118
+ privacyPolicy = privacyPolicy();
119
+ }
120
+ const info = fieldInfoMap[name];
121
+ if (!info) {
122
+ throw new Error(`field with name ${name} not passed in fieldMap`);
123
+ }
124
+ m.set(info.dbCol, privacyPolicy);
125
+ break;
141
126
  }
142
- m.set(info.dbCol, privacyPolicy);
143
127
  }
144
128
  }
145
129
  }
@@ -152,7 +136,6 @@ function getFieldsWithPrivacy(value, fieldMap) {
152
136
  addFields(schema.fields);
153
137
  return m;
154
138
  }
155
- exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
156
139
  function getTransformedReadClause(value) {
157
140
  const schema = getSchema(value);
158
141
  if (!schema.patterns) {
@@ -168,6 +151,9 @@ function getTransformedReadClause(value) {
168
151
  return;
169
152
  }
170
153
  exports.getTransformedReadClause = getTransformedReadClause;
154
+ // would like to avoid calling this so that itwe don't run into circular dependencies
155
+ // but the fact that it returns a clause makes it hard since we don't control the patterns...
156
+ // we can make each clause return a format that can be extrapolated and used in codegen...
171
157
  function getObjectLoaderProperties(value, tableName) {
172
158
  return {
173
159
  clause: () => getTransformedReadClause(value),
@@ -209,6 +195,9 @@ var ActionOperation;
209
195
  // RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
210
196
  ActionOperation[ActionOperation["RemoveEdge"] = 32] = "RemoveEdge";
211
197
  // EdgeGroup is used to provide the ability to edit an edge group in an AssociationEdgeGroup.
198
+ // if you want to clear this edge group e.g. any set edge with id1 and id2,
199
+ // you should create a custom action that takes the id as an action only field,
200
+ // and then calls `clearEdgeTypeInGroup` in a trigger to clear
212
201
  ActionOperation[ActionOperation["EdgeGroup"] = 64] = "EdgeGroup";
213
202
  })(ActionOperation = exports.ActionOperation || (exports.ActionOperation = {}));
214
203
  // 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 {};