@snowtop/ent 0.1.0-alpha99 → 0.1.0

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 (115) hide show
  1. package/action/action.d.ts +8 -1
  2. package/action/executor.d.ts +16 -3
  3. package/action/executor.js +83 -27
  4. package/action/index.d.ts +2 -1
  5. package/action/operations.d.ts +126 -0
  6. package/action/operations.js +686 -0
  7. package/action/orchestrator.d.ts +22 -8
  8. package/action/orchestrator.js +278 -67
  9. package/core/base.d.ts +34 -24
  10. package/core/clause.d.ts +62 -79
  11. package/core/clause.js +77 -5
  12. package/core/config.d.ts +5 -1
  13. package/core/config.js +3 -0
  14. package/core/const.d.ts +3 -0
  15. package/core/const.js +6 -0
  16. package/core/context.d.ts +4 -3
  17. package/core/context.js +2 -1
  18. package/core/db.d.ts +1 -0
  19. package/core/db.js +7 -7
  20. package/core/ent.d.ts +53 -105
  21. package/core/ent.js +104 -599
  22. package/core/global_schema.d.ts +7 -0
  23. package/core/global_schema.js +51 -0
  24. package/core/loaders/assoc_count_loader.d.ts +4 -2
  25. package/core/loaders/assoc_count_loader.js +10 -2
  26. package/core/loaders/assoc_edge_loader.d.ts +2 -3
  27. package/core/loaders/assoc_edge_loader.js +16 -7
  28. package/core/loaders/index.d.ts +0 -1
  29. package/core/loaders/index.js +1 -3
  30. package/core/loaders/loader.d.ts +3 -3
  31. package/core/loaders/loader.js +3 -20
  32. package/core/loaders/object_loader.d.ts +30 -10
  33. package/core/loaders/object_loader.js +179 -40
  34. package/core/loaders/query_loader.d.ts +4 -4
  35. package/core/loaders/query_loader.js +14 -19
  36. package/core/loaders/raw_count_loader.d.ts +1 -0
  37. package/core/loaders/raw_count_loader.js +3 -2
  38. package/core/privacy.d.ts +19 -10
  39. package/core/privacy.js +47 -26
  40. package/core/query/assoc_query.js +1 -1
  41. package/core/query/custom_clause_query.d.ts +6 -3
  42. package/core/query/custom_clause_query.js +36 -9
  43. package/core/query/custom_query.d.ts +3 -1
  44. package/core/query/custom_query.js +29 -6
  45. package/core/query/query.d.ts +12 -2
  46. package/core/query/query.js +67 -38
  47. package/core/query/shared_assoc_test.js +151 -10
  48. package/core/query/shared_test.d.ts +2 -2
  49. package/core/query/shared_test.js +90 -30
  50. package/core/query_impl.d.ts +8 -0
  51. package/core/query_impl.js +28 -0
  52. package/core/viewer.d.ts +2 -0
  53. package/core/viewer.js +2 -0
  54. package/graphql/graphql.d.ts +103 -19
  55. package/graphql/graphql.js +169 -134
  56. package/graphql/graphql_field_helpers.d.ts +9 -3
  57. package/graphql/graphql_field_helpers.js +22 -2
  58. package/graphql/index.d.ts +2 -1
  59. package/graphql/index.js +5 -2
  60. package/graphql/scalars/orderby_direction.d.ts +2 -0
  61. package/graphql/scalars/orderby_direction.js +15 -0
  62. package/imports/dataz/example1/_auth.js +128 -47
  63. package/imports/dataz/example1/_viewer.js +87 -39
  64. package/imports/index.d.ts +1 -1
  65. package/imports/index.js +2 -2
  66. package/index.d.ts +12 -1
  67. package/index.js +18 -6
  68. package/package.json +20 -17
  69. package/parse_schema/parse.d.ts +10 -4
  70. package/parse_schema/parse.js +70 -24
  71. package/schema/base_schema.d.ts +8 -0
  72. package/schema/base_schema.js +11 -0
  73. package/schema/field.d.ts +6 -3
  74. package/schema/field.js +72 -17
  75. package/schema/index.d.ts +1 -1
  76. package/schema/index.js +2 -1
  77. package/schema/json_field.d.ts +3 -3
  78. package/schema/json_field.js +4 -1
  79. package/schema/schema.d.ts +42 -5
  80. package/schema/schema.js +35 -41
  81. package/schema/struct_field.d.ts +8 -6
  82. package/schema/struct_field.js +67 -8
  83. package/schema/union_field.d.ts +1 -1
  84. package/scripts/custom_compiler.js +4 -4
  85. package/scripts/custom_graphql.js +105 -75
  86. package/scripts/move_types.js +4 -1
  87. package/scripts/read_schema.js +2 -2
  88. package/testutils/action/complex_schemas.d.ts +1 -1
  89. package/testutils/action/complex_schemas.js +10 -3
  90. package/testutils/builder.d.ts +3 -0
  91. package/testutils/builder.js +6 -0
  92. package/testutils/db/temp_db.d.ts +9 -1
  93. package/testutils/db/temp_db.js +82 -14
  94. package/testutils/db_mock.js +1 -3
  95. package/testutils/ent-graphql-tests/index.d.ts +1 -1
  96. package/testutils/ent-graphql-tests/index.js +30 -19
  97. package/testutils/fake_comms.js +1 -1
  98. package/testutils/fake_data/fake_contact.d.ts +1 -1
  99. package/testutils/fake_data/fake_tag.d.ts +1 -1
  100. package/testutils/fake_data/fake_user.d.ts +3 -3
  101. package/testutils/fake_data/fake_user.js +15 -4
  102. package/testutils/fake_data/tag_query.js +8 -3
  103. package/testutils/fake_data/test_helpers.d.ts +3 -2
  104. package/testutils/fake_data/test_helpers.js +4 -4
  105. package/testutils/fake_data/user_query.d.ts +5 -2
  106. package/testutils/fake_data/user_query.js +19 -2
  107. package/testutils/fake_log.js +1 -1
  108. package/tsc/ast.js +2 -1
  109. package/tsc/move_generated.js +2 -2
  110. package/tsc/transform.d.ts +2 -2
  111. package/tsc/transform.js +4 -3
  112. package/tsc/transform_ent.js +2 -1
  113. package/tsc/transform_schema.js +4 -3
  114. package/core/loaders/index_loader.d.ts +0 -14
  115. package/core/loaders/index_loader.js +0 -27
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSchema = void 0;
3
+ exports.parseSchema = exports.processFields = void 0;
4
4
  const cosmiconfig_1 = require("cosmiconfig");
5
+ const const_1 = require("../core/const");
6
+ const global_schema_1 = require("../core/global_schema");
5
7
  async function processFields(src, patternName) {
6
8
  const ret = [];
7
9
  let m = {};
@@ -20,10 +22,11 @@ async function processFields(src, patternName) {
20
22
  for (const name in m) {
21
23
  const field = m[name];
22
24
  //@ts-ignore type and other changed fields with different type in ProcessedField vs Field
23
- let f = { name, ...field };
25
+ let f = { ...field, name };
24
26
  f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
25
27
  f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
26
28
  f.hasFieldPrivacy = field.privacyPolicy !== undefined;
29
+ f.hasEditFieldPrivacy = field.editPrivacyPolicy !== undefined;
27
30
  if (field.polymorphic) {
28
31
  // convert boolean into object
29
32
  // we keep boolean as an option to keep API simple
@@ -84,6 +87,7 @@ async function processFields(src, patternName) {
84
87
  }
85
88
  return ret;
86
89
  }
90
+ exports.processFields = processFields;
87
91
  async function transformServerDefault(name, f, value) {
88
92
  if (f.valid) {
89
93
  if (!(await f.valid(value))) {
@@ -158,6 +162,23 @@ async function processPattern(patterns, pattern, processedSchema) {
158
162
  // flag transformsSelect
159
163
  if (pattern.transformRead) {
160
164
  ret.transformsSelect = true;
165
+ if (pattern.transformReadCodegen_BETA) {
166
+ const r = pattern.transformReadCodegen_BETA();
167
+ if (typeof r === "string") {
168
+ ret.transformsLoaderCodegen = {
169
+ code: r,
170
+ imports: [
171
+ {
172
+ importPath: const_1.PACKAGE,
173
+ import: "query",
174
+ },
175
+ ],
176
+ };
177
+ }
178
+ else {
179
+ ret.transformsLoaderCodegen = r;
180
+ }
181
+ }
161
182
  }
162
183
  if (patterns[name] === undefined) {
163
184
  // intentionally processing separately and not passing pattern.name
@@ -182,30 +203,39 @@ var NullableResult;
182
203
  NullableResult["ITEM"] = "true";
183
204
  })(NullableResult || (NullableResult = {}));
184
205
  function processAction(action) {
185
- if (!action.actionOnlyFields) {
186
- return { ...action };
187
- }
188
- let ret = { ...action };
189
- let actionOnlyFields = action.actionOnlyFields.map((f) => {
190
- let f2 = f;
191
- if (!f.nullable) {
192
- delete f2.nullable;
193
- return f2;
194
- }
195
- if (typeof f.nullable === "boolean") {
196
- f2.nullable = NullableResult.ITEM;
197
- }
198
- else {
199
- if (f.nullable === "contentsAndList") {
200
- f2.nullable = NullableResult.CONTENTS_AND_LIST;
206
+ const ret = { ...action };
207
+ if (action.actionOnlyFields !== undefined) {
208
+ let actionOnlyFields = action.actionOnlyFields.map((f) => {
209
+ let f2 = f;
210
+ if (!f.nullable) {
211
+ delete f2.nullable;
212
+ return f2;
213
+ }
214
+ if (typeof f.nullable === "boolean") {
215
+ f2.nullable = NullableResult.ITEM;
201
216
  }
202
217
  else {
203
- f2.nullable = NullableResult.CONTENTS;
218
+ if (f.nullable === "contentsAndList") {
219
+ f2.nullable = NullableResult.CONTENTS_AND_LIST;
220
+ }
221
+ else if (f.nullable === "contents") {
222
+ f2.nullable = NullableResult.CONTENTS;
223
+ }
224
+ else if (f.nullable === "true") {
225
+ // shouldn't happen but ran into weirdness where it did...
226
+ f2.nullable = NullableResult.ITEM;
227
+ }
204
228
  }
229
+ return f2;
230
+ });
231
+ ret.actionOnlyFields = actionOnlyFields;
232
+ }
233
+ if (action.canViewerDo !== undefined) {
234
+ if (typeof action.canViewerDo !== "object") {
235
+ delete ret.canViewerDo;
236
+ ret.canViewerDo = {};
205
237
  }
206
- return f2;
207
- });
208
- ret.actionOnlyFields = actionOnlyFields;
238
+ }
209
239
  return ret;
210
240
  }
211
241
  async function parseSchema(potentialSchemas, globalSchema) {
@@ -214,6 +244,9 @@ async function parseSchema(potentialSchemas, globalSchema) {
214
244
  let parsedGlobalSchema;
215
245
  if (globalSchema) {
216
246
  parsedGlobalSchema = await parseGlobalSchema(globalSchema);
247
+ // set this so that we can use it, if we're trying to process server default or anything
248
+ // that ends up parsing,validating and formatting fields
249
+ (0, global_schema_1.setGlobalSchema)(globalSchema);
217
250
  }
218
251
  for (const key in potentialSchemas) {
219
252
  const value = potentialSchemas[key];
@@ -241,6 +274,10 @@ async function parseSchema(potentialSchemas, globalSchema) {
241
274
  actions: schema.actions?.map((action) => processAction(action)) || [],
242
275
  assocEdges: [],
243
276
  assocEdgeGroups: [],
277
+ customGraphQLInterfaces: schema.customGraphQLInterfaces,
278
+ supportUpsert: schema.supportUpsert,
279
+ showCanViewerSee: schema.showCanViewerSee,
280
+ showCanViewerEdit: schema.showCanViewerEdit,
244
281
  };
245
282
  // let's put patterns first just so we have id, created_at, updated_at first
246
283
  // ¯\_(ツ)_/¯
@@ -254,6 +291,10 @@ async function parseSchema(potentialSchemas, globalSchema) {
254
291
  throw new Error(`can only have one pattern which transforms default querying behavior`);
255
292
  }
256
293
  processedSchema.transformsSelect = true;
294
+ if (ret.transformsLoaderCodegen) {
295
+ processedSchema.transformsLoaderCodegen =
296
+ ret.transformsLoaderCodegen;
297
+ }
257
298
  }
258
299
  if (ret.transformsDelete) {
259
300
  if (processedSchema.transformsDelete) {
@@ -328,9 +369,11 @@ async function parseGlobalSchema(s) {
328
369
  const ret = {
329
370
  globalEdges: [],
330
371
  extraEdgeFields: [],
331
- initForEdges: !!s.extraEdgeFields ||
372
+ init: !!s.extraEdgeFields ||
332
373
  s.transformEdgeRead !== undefined ||
333
- s.transformEdgeWrite !== undefined,
374
+ s.transformEdgeWrite !== undefined ||
375
+ s.fields !== undefined,
376
+ transformsEdges: !!s.transformEdgeRead || !!s.transformEdgeWrite,
334
377
  };
335
378
  if (s.extraEdgeFields) {
336
379
  ret.extraEdgeFields = await processFields(s.extraEdgeFields);
@@ -338,5 +381,8 @@ async function parseGlobalSchema(s) {
338
381
  if (s.edges) {
339
382
  ret.globalEdges = processEdges(s.edges);
340
383
  }
384
+ if (s.fields) {
385
+ ret.globalFields = await processFields(s.fields);
386
+ }
341
387
  return ret;
342
388
  }
@@ -19,6 +19,10 @@ export declare class EntSchema implements Schema {
19
19
  constraints: Constraint[] | undefined;
20
20
  indices: Index[] | undefined;
21
21
  hideFromGraphQL?: boolean;
22
+ customGraphQLInterfaces?: string[] | undefined;
23
+ supportUpsert?: boolean | undefined;
24
+ showCanViewerSee?: boolean | undefined;
25
+ showCanViewerEdit?: boolean | undefined;
22
26
  constructor(cfg: SchemaConfig);
23
27
  }
24
28
  export declare class EntSchemaWithTZ implements Schema {
@@ -36,6 +40,10 @@ export declare class EntSchemaWithTZ implements Schema {
36
40
  constraints: Constraint[] | undefined;
37
41
  indices: Index[] | undefined;
38
42
  hideFromGraphQL?: boolean;
43
+ customGraphQLInterfaces?: string[] | undefined;
44
+ supportUpsert?: boolean | undefined;
45
+ showCanViewerSee?: boolean | undefined;
46
+ showCanViewerEdit?: boolean | undefined;
39
47
  constructor(cfg: SchemaConfig);
40
48
  }
41
49
  export declare abstract class BaseEntSchema {
@@ -17,6 +17,7 @@ let tsFields = {
17
17
  defaultValueOnCreate: () => {
18
18
  return new Date();
19
19
  },
20
+ onlyUpdateIfOtherFieldsBeingSet_BETA: true,
20
21
  defaultValueOnEdit: () => {
21
22
  return new Date();
22
23
  },
@@ -87,6 +88,11 @@ class EntSchema {
87
88
  this.constraints = cfg.constraints;
88
89
  this.indices = cfg.indices;
89
90
  this.hideFromGraphQL = cfg.hideFromGraphQL;
91
+ // TODO annoying that have to list these...
92
+ this.customGraphQLInterfaces = cfg.customGraphQLInterfaces;
93
+ this.supportUpsert = cfg.supportUpsert;
94
+ this.showCanViewerSee = cfg.showCanViewerSee;
95
+ this.showCanViewerEdit = cfg.showCanViewerEdit;
90
96
  }
91
97
  }
92
98
  exports.EntSchema = EntSchema;
@@ -114,6 +120,11 @@ class EntSchemaWithTZ {
114
120
  this.constraints = cfg.constraints;
115
121
  this.indices = cfg.indices;
116
122
  this.hideFromGraphQL = cfg.hideFromGraphQL;
123
+ // TODO annoying that have to list these...
124
+ this.customGraphQLInterfaces = cfg.customGraphQLInterfaces;
125
+ this.supportUpsert = cfg.supportUpsert;
126
+ this.showCanViewerSee = cfg.showCanViewerSee;
127
+ this.showCanViewerEdit = cfg.showCanViewerEdit;
117
128
  }
118
129
  }
119
130
  exports.EntSchemaWithTZ = EntSchemaWithTZ;
package/schema/field.d.ts CHANGED
@@ -149,6 +149,7 @@ export interface EnumOptions extends FieldOptions {
149
149
  graphQLType?: string;
150
150
  createEnumType?: boolean;
151
151
  disableUnknownType?: boolean;
152
+ globalType?: string;
152
153
  }
153
154
  /**
154
155
  * @deprecated Use StringEnumField
@@ -158,7 +159,7 @@ export declare class EnumField extends BaseField implements Field {
158
159
  private values?;
159
160
  private map?;
160
161
  constructor(options: StringEnumOptions);
161
- valid(val: any): boolean;
162
+ valid(val: any): Promise<boolean>;
162
163
  format(val: any): any;
163
164
  }
164
165
  export declare class StringEnumField extends EnumField {
@@ -173,16 +174,18 @@ declare type IntEnumMap = {
173
174
  [key: string]: number;
174
175
  };
175
176
  export interface IntegerEnumOptions extends FieldOptions {
176
- map: IntEnumMap;
177
+ map?: IntEnumMap;
177
178
  deprecated?: IntEnumMap;
178
179
  tsType?: string;
179
180
  graphQLType?: string;
181
+ disableUnknownType?: boolean;
182
+ globalType?: string;
180
183
  }
181
184
  export declare class IntegerEnumField extends BaseField implements Field {
182
185
  type: Type;
183
186
  private map;
184
187
  constructor(options: IntegerEnumOptions);
185
- valid(val: any): boolean;
188
+ valid(val: any): Promise<boolean>;
186
189
  format(val: any): any;
187
190
  }
188
191
  export declare function IntegerEnumType(options: IntegerEnumOptions): IntegerEnumField;
package/schema/field.js CHANGED
@@ -26,11 +26,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.PolymorphicStringField = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.NumberField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
27
27
  const luxon_1 = require("luxon");
28
28
  const camel_case_1 = require("camel-case");
29
- const util_1 = require("util");
29
+ const types_1 = require("util/types");
30
30
  const uuid_1 = require("uuid");
31
31
  const base_1 = require("../core/base");
32
32
  const db_1 = __importStar(require("../core/db"));
33
33
  const schema_1 = require("./schema");
34
+ const global_schema_1 = require("../core/global_schema");
35
+ const logger_1 = require("../core/logger");
34
36
  class BaseField {
35
37
  logValue(val) {
36
38
  if (this.sensitive) {
@@ -525,10 +527,11 @@ class EnumField extends BaseField {
525
527
  type: options.tsType,
526
528
  graphQLType: options.graphQLType,
527
529
  disableUnknownType: options.disableUnknownType,
530
+ globalType: options.globalType,
528
531
  };
529
532
  if (!options.foreignKey) {
530
- if (!options.values && !options.map) {
531
- throw new Error("values or map required if not look up table enum. Look-up table enum indicated by foreignKey field");
533
+ if (!options.values && !options.map && !options.globalType) {
534
+ throw new Error("values, map or globalType required if not look up table enum. Look-up table enum indicated by foreignKey field");
532
535
  }
533
536
  if (options.values) {
534
537
  if (!options.values.length) {
@@ -547,8 +550,8 @@ class EnumField extends BaseField {
547
550
  }
548
551
  }
549
552
  else {
550
- if (options.values || options.map) {
551
- throw new Error("cannot specify values or map and foreign key for lookup table enum type");
553
+ if (options.values || options.map || options.globalType) {
554
+ throw new Error("cannot specify values, map or globalType and foreign key for lookup table enum type");
552
555
  }
553
556
  if (options.createEnumType) {
554
557
  throw new Error("cannot specify createEnumType without specifying values");
@@ -563,7 +566,20 @@ class EnumField extends BaseField {
563
566
  this.values = options.values;
564
567
  this.map = options.map;
565
568
  }
566
- valid(val) {
569
+ async valid(val) {
570
+ if (this.type.globalType) {
571
+ const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
572
+ if (f) {
573
+ if (f.valid) {
574
+ return f.valid(val);
575
+ }
576
+ return true;
577
+ }
578
+ else {
579
+ (0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
580
+ return false;
581
+ }
582
+ }
567
583
  // lookup table enum and indicated via presence of foreignKey
568
584
  if (!this.values && !this.map) {
569
585
  return true;
@@ -581,6 +597,13 @@ class EnumField extends BaseField {
581
597
  return false;
582
598
  }
583
599
  format(val) {
600
+ if (this.type.globalType) {
601
+ const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
602
+ if (f && f.format) {
603
+ return f.format(val);
604
+ }
605
+ return val;
606
+ }
584
607
  return val;
585
608
  }
586
609
  }
@@ -602,21 +625,47 @@ class IntegerEnumField extends BaseField {
602
625
  type: options.tsType,
603
626
  graphQLType: options.graphQLType,
604
627
  deprecatedIntEnumMap: options.deprecated,
628
+ disableUnknownType: options.disableUnknownType,
629
+ globalType: options.globalType,
605
630
  };
606
- let count = 0;
607
- for (const _ in options.map) {
608
- count++;
609
- break;
610
- }
611
- if (!count) {
612
- throw new Error("need at least one entry in enum map");
613
- }
614
631
  if (options.foreignKey) {
615
632
  throw new Error(`foreignKey on intEnum not supported`);
616
633
  }
617
- this.map = options.map;
634
+ if (options.globalType) {
635
+ if (options.map) {
636
+ throw new Error(`cannot specify map and globalType`);
637
+ }
638
+ this.map = {};
639
+ }
640
+ else {
641
+ let count = 0;
642
+ for (const _ in options.map) {
643
+ count++;
644
+ break;
645
+ }
646
+ if (!count) {
647
+ throw new Error("need at least one entry in enum map");
648
+ }
649
+ if (!options.map) {
650
+ throw new Error("map required if not globalType");
651
+ }
652
+ this.map = options.map;
653
+ }
618
654
  }
619
- valid(val) {
655
+ async valid(val) {
656
+ if (this.type?.globalType) {
657
+ const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
658
+ if (f) {
659
+ if (f.valid) {
660
+ return f.valid(val);
661
+ }
662
+ return true;
663
+ }
664
+ else {
665
+ (0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
666
+ return false;
667
+ }
668
+ }
620
669
  // lookup table enum and indicated via presence of foreignKey
621
670
  for (const k in this.map) {
622
671
  const v = this.map[k];
@@ -627,6 +676,12 @@ class IntegerEnumField extends BaseField {
627
676
  return false;
628
677
  }
629
678
  format(val) {
679
+ if (this.type.globalType) {
680
+ const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
681
+ if (f && f.format) {
682
+ return f.format(val);
683
+ }
684
+ }
630
685
  return parseInt(val);
631
686
  }
632
687
  }
@@ -672,7 +727,7 @@ class ListField extends BaseField {
672
727
  return true;
673
728
  }
674
729
  const res = valid.apply(this.field, [val[0]]);
675
- if (util_1.types.isPromise(res)) {
730
+ if ((0, types_1.isPromise)(res)) {
676
731
  const ret = await Promise.all(val.map(async (v) => await valid.apply(this.field, [v])));
677
732
  return ret.every((v) => v);
678
733
  }
package/schema/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Schema from "./schema";
2
2
  export { Schema };
3
- export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, getFieldsWithPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, EdgeUpdateOperation, TransformedEdgeUpdateOperation, getTransformedReadClause, getObjectLoaderProperties, GlobalSchema, } from "./schema";
3
+ export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, getFieldsWithPrivacy, getFieldsWithEditPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, EdgeUpdateOperation, TransformedEdgeUpdateOperation, getTransformedReadClause, getObjectLoaderProperties, GlobalSchema, ActionField, } from "./schema";
4
4
  export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, EntSchema, EntSchemaWithTZ, SchemaConfig, } from "./base_schema";
5
5
  export * from "./field";
6
6
  export * from "./json_field";
package/schema/index.js CHANGED
@@ -14,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.EntSchemaWithTZ = exports.EntSchema = exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.SQLStatementOperation = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getStorageKey = exports.getFieldsWithPrivacy = exports.getFields = exports.DBType = void 0;
17
+ exports.EntSchemaWithTZ = exports.EntSchema = exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.SQLStatementOperation = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getStorageKey = exports.getFieldsWithEditPrivacy = exports.getFieldsWithPrivacy = exports.getFields = exports.DBType = void 0;
18
18
  var schema_1 = require("./schema");
19
19
  Object.defineProperty(exports, "DBType", { enumerable: true, get: function () { return schema_1.DBType; } });
20
20
  Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return schema_1.getFields; } });
21
21
  Object.defineProperty(exports, "getFieldsWithPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithPrivacy; } });
22
+ Object.defineProperty(exports, "getFieldsWithEditPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithEditPrivacy; } });
22
23
  Object.defineProperty(exports, "getStorageKey", { enumerable: true, get: function () { return schema_1.getStorageKey; } });
23
24
  Object.defineProperty(exports, "ActionOperation", { enumerable: true, get: function () { return schema_1.ActionOperation; } });
24
25
  Object.defineProperty(exports, "NoFields", { enumerable: true, get: function () { return schema_1.NoFields; } });
@@ -1,8 +1,8 @@
1
- import { FieldOptions, Type, Field, ImportType } from "./schema";
1
+ import { FieldOptions, Type, Field, DeprecatedImportType } from "./schema";
2
2
  import { BaseField, ListField } from "./field";
3
3
  export interface JSONOptions extends FieldOptions {
4
4
  validator?: (val: any) => boolean;
5
- importType?: ImportType;
5
+ importType?: DeprecatedImportType;
6
6
  }
7
7
  interface allJSONOptions extends JSONOptions {
8
8
  jsonAsList?: boolean;
@@ -11,7 +11,7 @@ export declare class JSONField extends BaseField implements Field {
11
11
  private options?;
12
12
  type: Type;
13
13
  constructor(jsonb: boolean, options?: allJSONOptions | undefined);
14
- format(val: any): string;
14
+ format(val: any, nested?: boolean): any;
15
15
  valid(val: any): boolean;
16
16
  }
17
17
  export declare function JSONType(options?: JSONOptions): JSONField;
@@ -22,7 +22,10 @@ class JSONField extends field_1.BaseField {
22
22
  };
23
23
  }
24
24
  }
25
- format(val) {
25
+ format(val, nested) {
26
+ if (nested) {
27
+ return val;
28
+ }
26
29
  return JSON.stringify(val);
27
30
  }
28
31
  valid(val) {
@@ -1,7 +1,7 @@
1
1
  import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
2
2
  import { Builder, Changeset } from "../action/action";
3
3
  import { Clause } from "../core/clause";
4
- import { AssocEdgeInput } from "../core/ent";
4
+ import { AssocEdgeInput } from "../action/operations";
5
5
  export declare type FieldMap = {
6
6
  [key: string]: Field;
7
7
  };
@@ -17,6 +17,7 @@ export interface GlobalSchema {
17
17
  extraEdgeFields?: FieldMap;
18
18
  transformEdgeRead?: () => Clause;
19
19
  transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
20
+ fields?: FieldMap;
20
21
  }
21
22
  type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index">;
22
23
  export type FieldOverrideMap = {
@@ -37,6 +38,10 @@ export default interface Schema {
37
38
  constraints?: Constraint[];
38
39
  indices?: Index[];
39
40
  hideFromGraphQL?: boolean;
41
+ customGraphQLInterfaces?: string[];
42
+ supportUpsert?: boolean;
43
+ showCanViewerSee?: boolean;
44
+ showCanViewerEdit?: boolean;
40
45
  }
41
46
  export interface AssocEdge {
42
47
  name: string;
@@ -55,6 +60,7 @@ export interface EdgeAction {
55
60
  hideFromGraphQL?: boolean;
56
61
  graphQLName?: string;
57
62
  actionOnlyFields?: ActionField[];
63
+ canViewerDo?: boolean | CanViewerDo;
58
64
  }
59
65
  export interface InverseAssocEdge {
60
66
  name: string;
@@ -66,6 +72,7 @@ export interface EdgeGroupAction {
66
72
  hideFromGraphQL?: boolean;
67
73
  graphQLName?: string;
68
74
  actionOnlyFields?: ActionField[];
75
+ canViewerDo?: boolean | CanViewerDo;
69
76
  }
70
77
  export interface AssocEdgeGroup {
71
78
  name: string;
@@ -79,12 +86,23 @@ export interface AssocEdgeGroup {
79
86
  edgeAction?: EdgeGroupAction;
80
87
  }
81
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
+ }
82
99
  export interface Pattern {
83
100
  name: string;
84
101
  fields: FieldMap;
85
102
  disableMixin?: boolean;
86
103
  edges?: Edge[];
87
104
  transformRead?: () => Clause;
105
+ transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
88
106
  transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
89
107
  transformsDelete?: boolean;
90
108
  transformsInsert?: boolean;
@@ -135,7 +153,7 @@ export declare enum DBType {
135
153
  Timetz = "Timetz",
136
154
  List = "List"
137
155
  }
138
- export interface ImportType {
156
+ export interface DeprecatedImportType {
139
157
  path: string;
140
158
  type: string;
141
159
  [x: string]: any;
@@ -160,7 +178,8 @@ export interface Type {
160
178
  intEnumMap?: IntEnumMap;
161
179
  deprecatedIntEnumMap?: IntEnumMap;
162
180
  disableUnknownType?: boolean;
163
- importType?: ImportType;
181
+ globalType?: string;
182
+ importType?: DeprecatedImportType;
164
183
  subFields?: FieldMap;
165
184
  unionFields?: FieldMap;
166
185
  [x: string]: any;
@@ -180,12 +199,17 @@ export interface InverseFieldEdge {
180
199
  tableName?: string;
181
200
  hideFromGraphQL?: boolean;
182
201
  }
202
+ export interface IndexEdgeOptions {
203
+ name: string;
204
+ }
183
205
  export interface FieldEdge {
184
206
  schema: string;
185
207
  inverseEdge?: string | InverseFieldEdge;
208
+ indexEdge?: IndexEdgeOptions;
186
209
  enforceSchema?: boolean;
187
210
  getLoaderInfoFromSchema?: getLoaderInfoFn;
188
211
  disableBuilderType?: boolean;
212
+ edgeConstName?: string;
189
213
  }
190
214
  interface PrivateOptions {
191
215
  exposeToActions?: boolean;
@@ -203,14 +227,18 @@ export interface FieldOptions {
203
227
  foreignKey?: ForeignKey;
204
228
  fieldEdge?: FieldEdge;
205
229
  primaryKey?: boolean;
230
+ immutable?: boolean;
206
231
  disableUserEditable?: boolean;
207
232
  disableUserGraphQLEditable?: boolean;
208
233
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
209
234
  defaultToViewerOnCreate?: boolean;
235
+ onlyUpdateIfOtherFieldsBeingSet_BETA?: boolean;
210
236
  defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
211
237
  derivedWhenEmbedded?: boolean;
212
238
  polymorphic?: boolean | PolymorphicOptions;
213
239
  privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
240
+ editPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
241
+ createOnlyOverrideEditPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
214
242
  getDerivedFields?(name: string): FieldMap;
215
243
  convert?: ConvertType;
216
244
  fetchOnDemand?: boolean;
@@ -223,6 +251,7 @@ export interface PolymorphicOptions {
223
251
  hideFromInverseGraphQL?: boolean;
224
252
  disableBuilderType?: boolean;
225
253
  serverDefault?: any;
254
+ edgeConstName?: string;
226
255
  }
227
256
  export interface Field extends FieldOptions {
228
257
  type: Type;
@@ -241,7 +270,9 @@ export declare function getFields(value: SchemaInputType): Map<string, Field>;
241
270
  * @deprecated should only be used by tests
242
271
  */
243
272
  export declare function getStorageKey(field: Field, fieldName: string): string;
244
- 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>;
245
276
  export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
246
277
  interface objectLoaderOptions {
247
278
  clause?: () => Clause | undefined;
@@ -258,12 +289,13 @@ export declare enum ActionOperation {
258
289
  RemoveEdge = 32,
259
290
  EdgeGroup = 64
260
291
  }
261
- type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "Object";
292
+ type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "JSON" | "Object";
262
293
  type NullableListOptions = "contents" | "contentsAndList";
263
294
  export interface ActionField {
264
295
  name: string;
265
296
  type: actionFieldType;
266
297
  nullable?: boolean | NullableListOptions;
298
+ optional?: boolean;
267
299
  list?: boolean;
268
300
  actionName?: string;
269
301
  excludedFields?: string[];
@@ -282,8 +314,13 @@ export interface Action {
282
314
  optionalFields?: string[];
283
315
  requiredFields?: string[];
284
316
  noFields?: boolean;
317
+ canViewerDo?: boolean | CanViewerDo;
285
318
  [x: string]: any;
286
319
  }
320
+ export interface CanViewerDo {
321
+ addAllFields?: boolean;
322
+ inputFields?: string[];
323
+ }
287
324
  export declare const NoFields = "__NO_FIELDS__";
288
325
  export declare function requiredField(field: string): string;
289
326
  export declare function optionalField(field: string): string;