@snowtop/ent 0.1.0-alpha6 → 0.1.0-alpha63

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 (111) hide show
  1. package/action/action.d.ts +28 -24
  2. package/action/executor.d.ts +4 -4
  3. package/action/executor.js +2 -2
  4. package/action/experimental_action.d.ts +29 -22
  5. package/action/experimental_action.js +29 -6
  6. package/action/orchestrator.d.ts +44 -16
  7. package/action/orchestrator.js +287 -73
  8. package/action/privacy.d.ts +2 -2
  9. package/core/base.d.ts +26 -22
  10. package/core/base.js +16 -0
  11. package/core/clause.d.ts +65 -3
  12. package/core/clause.js +368 -5
  13. package/core/config.d.ts +26 -0
  14. package/core/config.js +17 -0
  15. package/core/context.d.ts +2 -2
  16. package/core/context.js +2 -2
  17. package/core/convert.d.ts +1 -1
  18. package/core/db.d.ts +3 -4
  19. package/core/db.js +2 -0
  20. package/core/ent.d.ts +35 -24
  21. package/core/ent.js +223 -60
  22. package/core/loaders/assoc_count_loader.d.ts +2 -2
  23. package/core/loaders/assoc_count_loader.js +6 -1
  24. package/core/loaders/assoc_edge_loader.d.ts +3 -3
  25. package/core/loaders/assoc_edge_loader.js +5 -4
  26. package/core/loaders/index_loader.js +1 -0
  27. package/core/loaders/loader.js +5 -5
  28. package/core/loaders/object_loader.d.ts +10 -5
  29. package/core/loaders/object_loader.js +58 -4
  30. package/core/loaders/query_loader.d.ts +2 -2
  31. package/core/loaders/raw_count_loader.d.ts +2 -2
  32. package/core/logger.d.ts +1 -1
  33. package/core/logger.js +1 -0
  34. package/core/privacy.d.ts +25 -25
  35. package/core/privacy.js +3 -0
  36. package/core/query/assoc_query.d.ts +6 -6
  37. package/core/query/custom_query.d.ts +5 -5
  38. package/core/query/query.d.ts +1 -1
  39. package/core/query/shared_assoc_test.d.ts +1 -1
  40. package/core/query/shared_assoc_test.js +17 -5
  41. package/core/query/shared_test.d.ts +3 -0
  42. package/core/query/shared_test.js +95 -17
  43. package/core/viewer.d.ts +4 -3
  44. package/core/viewer.js +4 -0
  45. package/graphql/builtins/connection.js +3 -3
  46. package/graphql/builtins/edge.js +2 -2
  47. package/graphql/builtins/node.js +1 -1
  48. package/graphql/graphql.d.ts +3 -2
  49. package/graphql/graphql.js +30 -23
  50. package/graphql/node_resolver.d.ts +0 -1
  51. package/graphql/query/connection_type.js +6 -6
  52. package/graphql/query/edge_connection.d.ts +9 -9
  53. package/graphql/query/page_info.d.ts +1 -1
  54. package/graphql/query/page_info.js +4 -4
  55. package/graphql/query/shared_assoc_test.js +2 -2
  56. package/graphql/scalars/time.d.ts +1 -1
  57. package/index.d.ts +18 -1
  58. package/index.js +21 -5
  59. package/package.json +3 -3
  60. package/parse_schema/parse.d.ts +24 -5
  61. package/parse_schema/parse.js +90 -8
  62. package/schema/base_schema.d.ts +36 -1
  63. package/schema/base_schema.js +51 -2
  64. package/schema/field.d.ts +34 -6
  65. package/schema/field.js +68 -3
  66. package/schema/index.d.ts +2 -2
  67. package/schema/index.js +8 -1
  68. package/schema/schema.d.ts +95 -2
  69. package/schema/schema.js +127 -5
  70. package/scripts/custom_graphql.js +127 -16
  71. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  72. package/scripts/migrate_v0.1.js +36 -0
  73. package/scripts/read_schema.js +25 -2
  74. package/testutils/builder.d.ts +36 -22
  75. package/testutils/builder.js +110 -13
  76. package/testutils/context/test_context.d.ts +2 -2
  77. package/testutils/context/test_context.js +7 -1
  78. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
  79. package/testutils/db/{test_db.js → temp_db.js} +75 -19
  80. package/testutils/ent-graphql-tests/index.d.ts +2 -0
  81. package/testutils/ent-graphql-tests/index.js +26 -17
  82. package/testutils/fake_data/fake_contact.d.ts +5 -9
  83. package/testutils/fake_data/fake_contact.js +17 -21
  84. package/testutils/fake_data/fake_event.d.ts +5 -9
  85. package/testutils/fake_data/fake_event.js +24 -28
  86. package/testutils/fake_data/fake_user.d.ts +6 -10
  87. package/testutils/fake_data/fake_user.js +25 -29
  88. package/testutils/fake_data/test_helpers.d.ts +2 -2
  89. package/testutils/fake_data/test_helpers.js +6 -6
  90. package/testutils/fake_data/user_query.d.ts +2 -2
  91. package/testutils/fake_log.d.ts +3 -3
  92. package/testutils/parse_sql.js +4 -0
  93. package/testutils/test_edge_global_schema.d.ts +15 -0
  94. package/testutils/test_edge_global_schema.js +58 -0
  95. package/testutils/write.d.ts +2 -2
  96. package/testutils/write.js +3 -3
  97. package/tsc/ast.d.ts +44 -0
  98. package/tsc/ast.js +267 -0
  99. package/tsc/compilerOptions.d.ts +6 -0
  100. package/tsc/compilerOptions.js +40 -1
  101. package/tsc/move_generated.d.ts +1 -0
  102. package/tsc/move_generated.js +160 -0
  103. package/tsc/transform.d.ts +21 -0
  104. package/tsc/transform.js +167 -0
  105. package/tsc/transform_action.d.ts +22 -0
  106. package/tsc/transform_action.js +179 -0
  107. package/tsc/transform_ent.d.ts +17 -0
  108. package/tsc/transform_ent.js +59 -0
  109. package/tsc/transform_schema.d.ts +27 -0
  110. package/tsc/transform_schema.js +379 -0
  111. package/scripts/transform_schema.js +0 -288
@@ -22,6 +22,7 @@ function processFields(src, patternName) {
22
22
  let f = { name, ...field };
23
23
  f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
24
24
  f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
25
+ f.hasFieldPrivacy = field.privacyPolicy !== undefined;
25
26
  if (field.polymorphic) {
26
27
  // convert boolean into object
27
28
  // we keep boolean as an option to keep API simple
@@ -35,6 +36,19 @@ function processFields(src, patternName) {
35
36
  else {
36
37
  delete f.polymorphic;
37
38
  }
39
+ if (field.private) {
40
+ // convert boolean into object
41
+ // we keep boolean as an option to keep API simple
42
+ if (typeof field.private === "boolean") {
43
+ f.private = {};
44
+ }
45
+ else {
46
+ f.private = field.private;
47
+ }
48
+ }
49
+ else {
50
+ delete f.private;
51
+ }
38
52
  // convert string to object to make API consumed by go simple
39
53
  if (f.fieldEdge && f.fieldEdge.inverseEdge) {
40
54
  if (typeof f.fieldEdge.inverseEdge === "string") {
@@ -46,6 +60,7 @@ function processFields(src, patternName) {
46
60
  if (patternName) {
47
61
  f.patternName = patternName;
48
62
  }
63
+ transformType(field.type);
49
64
  if (field.getDerivedFields) {
50
65
  f.derivedFields = processFields(field.getDerivedFields(name));
51
66
  }
@@ -65,6 +80,24 @@ function processFields(src, patternName) {
65
80
  }
66
81
  return ret;
67
82
  }
83
+ function transformImportType(typ) {
84
+ if (!typ.importType) {
85
+ return;
86
+ }
87
+ typ.importType = {
88
+ ...typ.importType,
89
+ // these 2 needed for forwards compatibility with new go schema
90
+ importPath: typ.importType.path,
91
+ import: typ.importType.type,
92
+ };
93
+ }
94
+ function transformType(typ) {
95
+ if (!typ) {
96
+ return;
97
+ }
98
+ transformImportType(typ);
99
+ transformType(typ.listElemType);
100
+ }
68
101
  function processEdges(src, patternName) {
69
102
  const ret = [];
70
103
  for (const edge of src) {
@@ -89,6 +122,9 @@ function processEdgeGroups(processedSchema, edgeGroups) {
89
122
  }
90
123
  }
91
124
  function processPattern(patterns, pattern, processedSchema) {
125
+ let ret = {
126
+ ...pattern,
127
+ };
92
128
  const name = pattern.name;
93
129
  const fields = processFields(pattern.fields, pattern.name);
94
130
  processedSchema.fields.push(...fields);
@@ -96,6 +132,10 @@ function processPattern(patterns, pattern, processedSchema) {
96
132
  const edges = processEdges(pattern.edges, pattern.name);
97
133
  processedSchema.assocEdges.push(...edges);
98
134
  }
135
+ // flag transformsSelect
136
+ if (pattern.transformRead) {
137
+ ret.transformsSelect = true;
138
+ }
99
139
  if (patterns[name] === undefined) {
100
140
  // intentionally processing separately and not passing pattern.name
101
141
  const edges = processEdges(pattern.edges || []);
@@ -103,12 +143,14 @@ function processPattern(patterns, pattern, processedSchema) {
103
143
  name: pattern.name,
104
144
  assocEdges: edges,
105
145
  fields: fields,
146
+ disableMixin: pattern.disableMixin,
106
147
  };
107
148
  }
108
149
  else {
109
150
  // TODO ideally we want to make sure that different patterns don't have the same name
110
151
  // can't do a deepEqual check because function calls and therefore different instances in fields
111
152
  }
153
+ return ret;
112
154
  }
113
155
  var NullableResult;
114
156
  (function (NullableResult) {
@@ -143,20 +185,29 @@ function processAction(action) {
143
185
  ret.actionOnlyFields = actionOnlyFields;
144
186
  return ret;
145
187
  }
146
- function parseSchema(potentialSchemas) {
188
+ function parseSchema(potentialSchemas, globalSchema) {
147
189
  let schemas = {};
148
190
  let patterns = {};
191
+ let parsedGlobalSchema;
192
+ if (globalSchema) {
193
+ parsedGlobalSchema = parseGlobalSchema(globalSchema);
194
+ }
149
195
  for (const key in potentialSchemas) {
150
196
  const value = potentialSchemas[key];
151
197
  let schema;
152
- if (value.constructor == Object) {
153
- schema = value;
154
- }
155
- else {
156
- schema = new value();
198
+ const name = value.constructor.name;
199
+ // named class e.g. new BaseEntSchema
200
+ switch (name) {
201
+ case "Function":
202
+ schema = new value();
203
+ break;
204
+ default:
205
+ // implicit schema or named class
206
+ schema = value;
157
207
  }
158
208
  let processedSchema = {
159
209
  fields: [],
210
+ schemaPath: schema.schemaPath,
160
211
  tableName: schema.tableName,
161
212
  enumTable: schema.enumTable,
162
213
  dbRows: schema.dbRows,
@@ -169,13 +220,28 @@ function parseSchema(potentialSchemas) {
169
220
  };
170
221
  // let's put patterns first just so we have id, created_at, updated_at first
171
222
  // ¯\_(ツ)_/¯
223
+ let patternNames = [];
172
224
  if (schema.patterns) {
173
225
  for (const pattern of schema.patterns) {
174
- processPattern(patterns, pattern, processedSchema);
226
+ const ret = processPattern(patterns, pattern, processedSchema);
227
+ patternNames.push(pattern.name);
228
+ if (ret.transformsSelect) {
229
+ if (processedSchema.transformsSelect) {
230
+ throw new Error(`can only have one pattern which transforms default querying behavior`);
231
+ }
232
+ processedSchema.transformsSelect = true;
233
+ }
234
+ if (ret.transformsDelete) {
235
+ if (processedSchema.transformsDelete) {
236
+ throw new Error(`can only have one pattern which transforms default deletion behavior`);
237
+ }
238
+ processedSchema.transformsDelete = true;
239
+ }
175
240
  }
176
241
  }
177
242
  const fields = processFields(schema.fields);
178
243
  processedSchema.fields.push(...fields);
244
+ processedSchema.patternNames = patternNames;
179
245
  if (schema.edges) {
180
246
  const edges = processEdges(schema.edges);
181
247
  processedSchema.assocEdges.push(...edges);
@@ -185,6 +251,22 @@ function parseSchema(potentialSchemas) {
185
251
  }
186
252
  schemas[key] = processedSchema;
187
253
  }
188
- return { schemas, patterns };
254
+ return { schemas, patterns, globalSchema: parsedGlobalSchema };
189
255
  }
190
256
  exports.parseSchema = parseSchema;
257
+ function parseGlobalSchema(s) {
258
+ const ret = {
259
+ globalEdges: [],
260
+ extraEdgeFields: [],
261
+ initForEdges: !!s.extraEdgeFields ||
262
+ s.transformEdgeRead !== undefined ||
263
+ s.transformEdgeWrite !== undefined,
264
+ };
265
+ if (s.extraEdgeFields) {
266
+ ret.extraEdgeFields = processFields(s.extraEdgeFields);
267
+ }
268
+ if (s.edges) {
269
+ ret.globalEdges = processEdges(s.edges);
270
+ }
271
+ return ret;
272
+ }
@@ -1,6 +1,41 @@
1
- import { Pattern } from "./schema";
1
+ import { Field, FieldMap, Pattern } from "./schema";
2
+ import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
2
3
  export declare const Timestamps: Pattern;
3
4
  export declare const Node: Pattern;
5
+ export interface SchemaConfig extends Schema {
6
+ }
7
+ export declare class EntSchema implements Schema {
8
+ fields: FieldMap | Field[];
9
+ tableName: string | undefined;
10
+ patterns: Pattern[];
11
+ edges: Edge[] | undefined;
12
+ edgeGroups: AssocEdgeGroup[] | undefined;
13
+ actions: Action[] | undefined;
14
+ enumTable: boolean | undefined;
15
+ dbRows: {
16
+ [key: string]: any;
17
+ }[] | undefined;
18
+ constraints: Constraint[] | undefined;
19
+ indices: Index[] | undefined;
20
+ hideFromGraphQL?: boolean;
21
+ constructor(cfg: SchemaConfig);
22
+ }
23
+ export declare class EntSchemaWithTZ implements Schema {
24
+ fields: FieldMap | Field[];
25
+ tableName: string | undefined;
26
+ patterns: Pattern[];
27
+ edges: Edge[] | undefined;
28
+ edgeGroups: AssocEdgeGroup[] | undefined;
29
+ actions: Action[] | undefined;
30
+ enumTable: boolean | undefined;
31
+ dbRows: {
32
+ [key: string]: any;
33
+ }[] | undefined;
34
+ constraints: Constraint[] | undefined;
35
+ indices: Index[] | undefined;
36
+ hideFromGraphQL?: boolean;
37
+ constructor(cfg: SchemaConfig);
38
+ }
4
39
  export declare abstract class BaseEntSchema {
5
40
  addPatterns(...patterns: Pattern[]): void;
6
41
  patterns: Pattern[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = void 0;
3
+ exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.EntSchemaWithTZ = exports.EntSchema = exports.Node = exports.Timestamps = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const field_1 = require("./field");
6
6
  let tsFields = {
@@ -66,9 +66,56 @@ let nodeFieldsWithTZ = {
66
66
  exports.Node = {
67
67
  name: "node",
68
68
  fields: nodeFields,
69
+ disableMixin: true,
69
70
  };
70
- // Base ent schema. has Node Pattern by default.
71
+ // Ent schema. has Node Pattern by default.
71
72
  // exists just to have less typing and easier for clients to implement
73
+ class EntSchema {
74
+ constructor(cfg) {
75
+ this.patterns = [exports.Node];
76
+ this.fields = cfg.fields;
77
+ this.tableName = cfg.tableName;
78
+ if (cfg.patterns) {
79
+ this.patterns.push(...cfg.patterns);
80
+ }
81
+ this.edges = cfg.edges;
82
+ this.edgeGroups = cfg.edgeGroups;
83
+ this.actions = cfg.actions;
84
+ this.enumTable = cfg.enumTable;
85
+ this.dbRows = cfg.dbRows;
86
+ this.constraints = cfg.constraints;
87
+ this.indices = cfg.indices;
88
+ this.hideFromGraphQL = cfg.hideFromGraphQL;
89
+ }
90
+ }
91
+ exports.EntSchema = EntSchema;
92
+ class EntSchemaWithTZ {
93
+ constructor(cfg) {
94
+ this.patterns = [
95
+ {
96
+ // default schema added
97
+ name: "nodeWithTZ",
98
+ fields: nodeFieldsWithTZ,
99
+ disableMixin: true,
100
+ },
101
+ ];
102
+ this.fields = cfg.fields;
103
+ this.tableName = cfg.tableName;
104
+ if (cfg.patterns) {
105
+ this.patterns.push(...cfg.patterns);
106
+ }
107
+ this.edges = cfg.edges;
108
+ this.edgeGroups = cfg.edgeGroups;
109
+ this.actions = cfg.actions;
110
+ this.enumTable = cfg.enumTable;
111
+ this.dbRows = cfg.dbRows;
112
+ this.constraints = cfg.constraints;
113
+ this.indices = cfg.indices;
114
+ this.hideFromGraphQL = cfg.hideFromGraphQL;
115
+ }
116
+ }
117
+ exports.EntSchemaWithTZ = EntSchemaWithTZ;
118
+ // @deprecated use EntSchema
72
119
  class BaseEntSchema {
73
120
  constructor() {
74
121
  this.patterns = [exports.Node];
@@ -78,6 +125,7 @@ class BaseEntSchema {
78
125
  }
79
126
  }
80
127
  exports.BaseEntSchema = BaseEntSchema;
128
+ // @deprecated use EntSchemaWithTZ
81
129
  class BaseEntSchemaWithTZ {
82
130
  constructor() {
83
131
  this.patterns = [
@@ -85,6 +133,7 @@ class BaseEntSchemaWithTZ {
85
133
  // default schema added
86
134
  name: "nodeWithTZ",
87
135
  fields: nodeFieldsWithTZ,
136
+ disableMixin: true,
88
137
  },
89
138
  ];
90
139
  }
package/schema/field.d.ts CHANGED
@@ -44,7 +44,7 @@ export declare function IntegerType(options?: IntegerOptions): IntegerField;
44
44
  export declare class BigIntegerField extends BaseField implements Field {
45
45
  type: Type;
46
46
  }
47
- export declare function BigIntegerType(options: FieldOptions): BigIntegerField;
47
+ export declare function BigIntegerType(options?: FieldOptions): BigIntegerField;
48
48
  export declare class FloatField extends BaseField implements Field {
49
49
  type: Type;
50
50
  }
@@ -118,26 +118,53 @@ export declare class DateField extends BaseField implements Field {
118
118
  format(val: any): any;
119
119
  }
120
120
  export declare function DateType(options?: FieldOptions): DateField;
121
- declare type EnumMap = {
121
+ declare type StringEnumMap = {
122
122
  [key: string]: string;
123
123
  };
124
+ /**
125
+ * @deprecated use StringEnumOptions
126
+ */
124
127
  export interface EnumOptions extends FieldOptions {
125
128
  values?: string[];
126
- map?: EnumMap;
129
+ map?: StringEnumMap;
127
130
  tsType?: string;
128
131
  graphQLType?: string;
129
132
  createEnumType?: boolean;
130
133
  }
134
+ export interface StringEnumOptions extends EnumOptions {
135
+ }
136
+ /**
137
+ * @deprecated Use StringEnumField
138
+ */
131
139
  export declare class EnumField extends BaseField implements Field {
132
140
  type: Type;
133
141
  private values?;
134
142
  private map?;
135
- constructor(options: EnumOptions);
143
+ constructor(options: StringEnumOptions);
136
144
  convertForGQL(value: string): string;
137
145
  valid(val: any): boolean;
138
146
  format(val: any): any;
139
147
  }
140
- export declare function EnumType(options: EnumOptions): EnumField;
148
+ export declare class StringEnumField extends EnumField {
149
+ }
150
+ export declare function EnumType(options: StringEnumOptions): EnumField;
151
+ declare type IntEnumMap = {
152
+ [key: string]: number;
153
+ };
154
+ export interface IntegerEnumOptions extends FieldOptions {
155
+ map: IntEnumMap;
156
+ deprecated?: IntEnumMap;
157
+ tsType?: string;
158
+ graphQLType?: string;
159
+ }
160
+ export declare class IntegerEnumField extends BaseField implements Field {
161
+ type: Type;
162
+ private map;
163
+ constructor(options: IntegerEnumOptions);
164
+ valid(val: any): boolean;
165
+ format(val: any): any;
166
+ }
167
+ export declare function IntegerEnumType(options: IntegerEnumOptions): IntegerEnumField;
141
168
  export declare class ListField extends BaseField {
142
169
  private field;
143
170
  type: Type;
@@ -163,6 +190,7 @@ export declare function TimestamptzListType(options?: TimestampOptions): ListFie
163
190
  export declare function TimeListType(options?: TimeOptions): ListField;
164
191
  export declare function TimetzListType(options: TimeOptions): ListField;
165
192
  export declare function DateListType(options?: FieldOptions): ListField;
166
- export declare function EnumListType(options: EnumOptions): ListField;
193
+ export declare function EnumListType(options: StringEnumOptions): ListField;
194
+ export declare function IntegerEnumListType(options: IntegerEnumOptions): ListField;
167
195
  export declare function UUIDListType(options?: FieldOptions): ListField;
168
196
  export {};
package/schema/field.js CHANGED
@@ -19,12 +19,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.UUIDListType = 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.EnumType = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
22
+ 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.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
23
23
  const luxon_1 = require("luxon");
24
24
  const snake_case_1 = require("snake-case");
25
25
  const db_1 = __importStar(require("../core/db"));
26
26
  const schema_1 = require("./schema");
27
27
  const util_1 = require("util");
28
+ const uuid_1 = require("uuid");
28
29
  class BaseField {
29
30
  logValue(val) {
30
31
  if (this.sensitive) {
@@ -92,6 +93,9 @@ class UUIDField extends BaseField {
92
93
  return val.placeholderID !== undefined;
93
94
  }
94
95
  async valid(val) {
96
+ if (typeof val === "string" && !(0, uuid_1.validate)(val)) {
97
+ return false;
98
+ }
95
99
  if (!this.options?.fieldEdge?.enforceSchema) {
96
100
  return true;
97
101
  }
@@ -444,6 +448,9 @@ function DateType(options) {
444
448
  return Object.assign(result, options);
445
449
  }
446
450
  exports.DateType = DateType;
451
+ /**
452
+ * @deprecated Use StringEnumField
453
+ */
447
454
  class EnumField extends BaseField {
448
455
  constructor(options) {
449
456
  super();
@@ -546,11 +553,57 @@ class EnumField extends BaseField {
546
553
  }
547
554
  }
548
555
  exports.EnumField = EnumField;
556
+ class StringEnumField extends EnumField {
557
+ }
558
+ exports.StringEnumField = StringEnumField;
549
559
  function EnumType(options) {
550
- let result = new EnumField(options);
560
+ let result = new StringEnumField(options);
551
561
  return Object.assign(result, options);
552
562
  }
553
563
  exports.EnumType = EnumType;
564
+ class IntegerEnumField extends BaseField {
565
+ constructor(options) {
566
+ super();
567
+ this.type = {
568
+ dbType: schema_1.DBType.IntEnum,
569
+ intEnumMap: options.map,
570
+ type: options.tsType,
571
+ graphQLType: options.graphQLType,
572
+ deprecatedIntEnumMap: options.deprecated,
573
+ };
574
+ let count = 0;
575
+ for (const k in options.map) {
576
+ count++;
577
+ break;
578
+ }
579
+ if (!count) {
580
+ throw new Error("need at least one entry in enum map");
581
+ }
582
+ if (options.foreignKey) {
583
+ throw new Error(`foreignKey on intEnum not supported`);
584
+ }
585
+ this.map = options.map;
586
+ }
587
+ valid(val) {
588
+ // lookup table enum and indicated via presence of foreignKey
589
+ for (const k in this.map) {
590
+ const v = this.map[k];
591
+ if (v === val || v === parseInt(val)) {
592
+ return true;
593
+ }
594
+ }
595
+ return false;
596
+ }
597
+ format(val) {
598
+ return parseInt(val);
599
+ }
600
+ }
601
+ exports.IntegerEnumField = IntegerEnumField;
602
+ function IntegerEnumType(options) {
603
+ let result = new IntegerEnumField(options);
604
+ return Object.assign(result, options);
605
+ }
606
+ exports.IntegerEnumType = IntegerEnumType;
554
607
  class ListField extends BaseField {
555
608
  constructor(field, options) {
556
609
  super();
@@ -593,6 +646,10 @@ class ListField extends BaseField {
593
646
  }
594
647
  postgresVal(val, jsonType) {
595
648
  if (!jsonType) {
649
+ // support empty strings in list
650
+ if (val === "") {
651
+ val = '"' + val + '"';
652
+ }
596
653
  return val;
597
654
  }
598
655
  return JSON.stringify(val);
@@ -616,7 +673,7 @@ class ListField extends BaseField {
616
673
  for (let i = 0; i < val.length; i++) {
617
674
  let formatted = val[i];
618
675
  if (this.field.format) {
619
- formatted = this.field.format(val[i]);
676
+ formatted = this.field.format(val[i], nested);
620
677
  }
621
678
  // postgres supports arrays natively so we
622
679
  // structure it in the expected format
@@ -720,6 +777,14 @@ function EnumListType(options) {
720
777
  return new ListField(EnumType(options), options);
721
778
  }
722
779
  exports.EnumListType = EnumListType;
780
+ function IntegerEnumListType(options) {
781
+ // not all of these will make sense in a list...
782
+ // can make it work eventually but involves work we're not currently trying to do
783
+ // developer can try to work around it by calling below on their own.
784
+ // unclear what the behavior is
785
+ return new ListField(IntegerEnumType(options), options);
786
+ }
787
+ exports.IntegerEnumListType = IntegerEnumListType;
723
788
  function UUIDListType(options) {
724
789
  return new ListField(UUIDType(options), options);
725
790
  }
package/schema/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import Schema from "./schema";
2
2
  export { Schema };
3
- export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, } from "./schema";
4
- export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, } from "./base_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";
4
+ export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, EntSchema, EntSchemaWithTZ, SchemaConfig, } from "./base_schema";
5
5
  export * from "./field";
6
6
  export * from "./json_field";
7
7
  export * from "./struct_field";
package/schema/index.js CHANGED
@@ -10,20 +10,27 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
13
+ 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;
14
14
  var schema_1 = require("./schema");
15
15
  Object.defineProperty(exports, "DBType", { enumerable: true, get: function () { return schema_1.DBType; } });
16
16
  Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return schema_1.getFields; } });
17
+ Object.defineProperty(exports, "getFieldsWithPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithPrivacy; } });
18
+ Object.defineProperty(exports, "getStorageKey", { enumerable: true, get: function () { return schema_1.getStorageKey; } });
17
19
  Object.defineProperty(exports, "ActionOperation", { enumerable: true, get: function () { return schema_1.ActionOperation; } });
18
20
  Object.defineProperty(exports, "NoFields", { enumerable: true, get: function () { return schema_1.NoFields; } });
19
21
  Object.defineProperty(exports, "ConstraintType", { enumerable: true, get: function () { return schema_1.ConstraintType; } });
20
22
  Object.defineProperty(exports, "requiredField", { enumerable: true, get: function () { return schema_1.requiredField; } });
21
23
  Object.defineProperty(exports, "optionalField", { enumerable: true, get: function () { return schema_1.optionalField; } });
24
+ Object.defineProperty(exports, "SQLStatementOperation", { enumerable: true, get: function () { return schema_1.SQLStatementOperation; } });
25
+ Object.defineProperty(exports, "getTransformedReadClause", { enumerable: true, get: function () { return schema_1.getTransformedReadClause; } });
26
+ Object.defineProperty(exports, "getObjectLoaderProperties", { enumerable: true, get: function () { return schema_1.getObjectLoaderProperties; } });
22
27
  var base_schema_1 = require("./base_schema");
23
28
  Object.defineProperty(exports, "Timestamps", { enumerable: true, get: function () { return base_schema_1.Timestamps; } });
24
29
  Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return base_schema_1.Node; } });
25
30
  Object.defineProperty(exports, "BaseEntSchema", { enumerable: true, get: function () { return base_schema_1.BaseEntSchema; } });
26
31
  Object.defineProperty(exports, "BaseEntSchemaWithTZ", { enumerable: true, get: function () { return base_schema_1.BaseEntSchemaWithTZ; } });
32
+ Object.defineProperty(exports, "EntSchema", { enumerable: true, get: function () { return base_schema_1.EntSchema; } });
33
+ Object.defineProperty(exports, "EntSchemaWithTZ", { enumerable: true, get: function () { return base_schema_1.EntSchemaWithTZ; } });
27
34
  __exportStar(require("./field"), exports);
28
35
  __exportStar(require("./json_field"), exports);
29
36
  __exportStar(require("./struct_field"), exports);