@snowtop/ent 0.1.0-alpha12 → 0.1.0-alpha121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action/action.d.ts +37 -31
- package/action/action.js +22 -7
- package/action/executor.d.ts +3 -3
- package/action/executor.js +8 -3
- package/action/experimental_action.d.ts +32 -22
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +33 -14
- package/action/orchestrator.js +251 -54
- package/action/privacy.d.ts +2 -2
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +60 -37
- package/core/base.js +7 -1
- package/core/clause.d.ts +84 -40
- package/core/clause.js +358 -64
- package/core/config.d.ts +12 -1
- package/core/config.js +7 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +6 -4
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +11 -8
- package/core/db.js +20 -8
- package/core/ent.d.ts +82 -30
- package/core/ent.js +632 -193
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.js +8 -11
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +3 -3
- package/core/loaders/loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +11 -10
- package/core/loaders/object_loader.js +70 -60
- package/core/loaders/query_loader.d.ts +7 -13
- package/core/loaders/query_loader.js +52 -11
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +25 -24
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +7 -6
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +27 -0
- package/core/query/custom_clause_query.js +84 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +87 -12
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +8 -4
- package/core/query/query.js +101 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +35 -45
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +470 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.d.ts +15 -7
- package/graphql/graphql.js +23 -7
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +3 -4
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +1 -19
- package/graphql/scalars/orderby_direction.d.ts +2 -0
- package/graphql/scalars/orderby_direction.js +15 -0
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +13 -5
- package/index.js +21 -7
- package/package.json +17 -16
- package/parse_schema/parse.d.ts +31 -9
- package/parse_schema/parse.js +152 -12
- package/schema/base_schema.d.ts +5 -3
- package/schema/base_schema.js +6 -0
- package/schema/field.d.ts +78 -21
- package/schema/field.js +219 -72
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +16 -4
- package/schema/json_field.js +32 -2
- package/schema/schema.d.ts +89 -20
- package/schema/schema.js +13 -14
- package/schema/struct_field.d.ts +15 -3
- package/schema/struct_field.js +71 -22
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +124 -31
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +117 -0
- package/scripts/read_schema.js +20 -5
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +43 -47
- package/testutils/builder.js +76 -49
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
- package/testutils/db/{test_db.js → temp_db.js} +182 -45
- package/testutils/db/value.d.ts +7 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +51 -6
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.d.ts +7 -1
- package/testutils/ent-graphql-tests/index.js +52 -23
- package/testutils/fake_data/const.d.ts +2 -1
- package/testutils/fake_data/const.js +3 -0
- package/testutils/fake_data/fake_contact.d.ts +8 -4
- package/testutils/fake_data/fake_contact.js +15 -8
- package/testutils/fake_data/fake_event.d.ts +5 -2
- package/testutils/fake_data/fake_event.js +9 -7
- package/testutils/fake_data/fake_tag.d.ts +36 -0
- package/testutils/fake_data/fake_tag.js +89 -0
- package/testutils/fake_data/fake_user.d.ts +10 -7
- package/testutils/fake_data/fake_user.js +18 -16
- package/testutils/fake_data/index.js +5 -1
- package/testutils/fake_data/internal.d.ts +2 -0
- package/testutils/fake_data/internal.js +7 -1
- package/testutils/fake_data/tag_query.d.ts +13 -0
- package/testutils/fake_data/tag_query.js +43 -0
- package/testutils/fake_data/test_helpers.d.ts +11 -4
- package/testutils/fake_data/test_helpers.js +28 -12
- package/testutils/fake_data/user_query.d.ts +13 -6
- package/testutils/fake_data/user_query.js +54 -22
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +25 -2
- package/tsc/ast.js +141 -17
- package/tsc/compilerOptions.js +5 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +22 -0
- package/tsc/transform.js +181 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +183 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +60 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/{scripts → tsc}/transform_schema.js +146 -117
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -142
- package/scripts/transform_code.js +0 -113
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
package/schema/field.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -19,12 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
21
25
|
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;
|
|
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;
|
|
23
27
|
const luxon_1 = require("luxon");
|
|
24
|
-
const
|
|
28
|
+
const camel_case_1 = require("camel-case");
|
|
29
|
+
const util_1 = require("util");
|
|
30
|
+
const uuid_1 = require("uuid");
|
|
31
|
+
const base_1 = require("../core/base");
|
|
25
32
|
const db_1 = __importStar(require("../core/db"));
|
|
26
33
|
const schema_1 = require("./schema");
|
|
27
|
-
const
|
|
34
|
+
const global_schema_1 = require("../core/global_schema");
|
|
28
35
|
class BaseField {
|
|
29
36
|
logValue(val) {
|
|
30
37
|
if (this.sensitive) {
|
|
@@ -60,31 +67,26 @@ class UUIDField extends BaseField {
|
|
|
60
67
|
else {
|
|
61
68
|
throw new Error(`unsupported id polymorhpic type ${fieldName}`);
|
|
62
69
|
}
|
|
70
|
+
let types;
|
|
71
|
+
let serverDefault = undefined;
|
|
72
|
+
if (typeof polymorphic === "object") {
|
|
73
|
+
serverDefault = polymorphic.serverDefault;
|
|
74
|
+
types = polymorphic.types;
|
|
75
|
+
}
|
|
63
76
|
// polymorphic field automatically hidden from GraphQL
|
|
64
77
|
// can be made visible with custom fields if user wants to change this behavior
|
|
65
78
|
// can't be foreignKey so need to make other changes to the field
|
|
66
79
|
// intentionally not made private as it doesn't seem like it needs to be hidden
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// just a string field...
|
|
80
|
-
return {
|
|
81
|
-
[name]: StringType({
|
|
82
|
-
hideFromGraphQL: true,
|
|
83
|
-
derivedWhenEmbedded: true,
|
|
84
|
-
nullable: this.options?.nullable,
|
|
85
|
-
}),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
80
|
+
return {
|
|
81
|
+
[name]: PolymorphicStringType({
|
|
82
|
+
types: types,
|
|
83
|
+
hideFromGraphQL: true,
|
|
84
|
+
derivedWhenEmbedded: true,
|
|
85
|
+
nullable: this.options?.nullable,
|
|
86
|
+
parentFieldToValidate: fieldName,
|
|
87
|
+
serverDefault: serverDefault,
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
88
90
|
}
|
|
89
91
|
return {};
|
|
90
92
|
}
|
|
@@ -92,6 +94,9 @@ class UUIDField extends BaseField {
|
|
|
92
94
|
return val.placeholderID !== undefined;
|
|
93
95
|
}
|
|
94
96
|
async valid(val) {
|
|
97
|
+
if (typeof val === "string" && !(0, uuid_1.validate)(val)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
95
100
|
if (!this.options?.fieldEdge?.enforceSchema) {
|
|
96
101
|
return true;
|
|
97
102
|
}
|
|
@@ -115,9 +120,10 @@ function UUIDType(options) {
|
|
|
115
120
|
return Object.assign(result, options);
|
|
116
121
|
}
|
|
117
122
|
exports.UUIDType = UUIDType;
|
|
118
|
-
class
|
|
123
|
+
class NumberField extends BaseField {
|
|
119
124
|
constructor(options) {
|
|
120
125
|
super();
|
|
126
|
+
// to be overriden as needed
|
|
121
127
|
this.type = { dbType: schema_1.DBType.Int };
|
|
122
128
|
this.validators = [];
|
|
123
129
|
this.options = {};
|
|
@@ -141,9 +147,11 @@ class IntegerField extends BaseField {
|
|
|
141
147
|
this.options = options;
|
|
142
148
|
}
|
|
143
149
|
min(l) {
|
|
150
|
+
// @ts-ignore Operator '>=' cannot be applied to types 'number' and 'T'.
|
|
144
151
|
return this.validate((val) => val >= l);
|
|
145
152
|
}
|
|
146
153
|
max(l) {
|
|
154
|
+
// @ts-ignore Operator '<=' cannot be applied to types 'number' and 'T'.
|
|
147
155
|
return this.validate((val) => val <= l);
|
|
148
156
|
}
|
|
149
157
|
valid(val) {
|
|
@@ -159,13 +167,20 @@ class IntegerField extends BaseField {
|
|
|
159
167
|
return this;
|
|
160
168
|
}
|
|
161
169
|
}
|
|
170
|
+
exports.NumberField = NumberField;
|
|
171
|
+
class IntegerField extends NumberField {
|
|
172
|
+
constructor() {
|
|
173
|
+
super(...arguments);
|
|
174
|
+
this.type = { dbType: schema_1.DBType.Int };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
162
177
|
exports.IntegerField = IntegerField;
|
|
163
178
|
function IntegerType(options) {
|
|
164
179
|
let result = new IntegerField(options);
|
|
165
180
|
return Object.assign(result, options);
|
|
166
181
|
}
|
|
167
182
|
exports.IntegerType = IntegerType;
|
|
168
|
-
class BigIntegerField extends
|
|
183
|
+
class BigIntegerField extends NumberField {
|
|
169
184
|
constructor() {
|
|
170
185
|
super(...arguments);
|
|
171
186
|
this.type = { dbType: schema_1.DBType.BigInt };
|
|
@@ -173,11 +188,11 @@ class BigIntegerField extends BaseField {
|
|
|
173
188
|
}
|
|
174
189
|
exports.BigIntegerField = BigIntegerField;
|
|
175
190
|
function BigIntegerType(options) {
|
|
176
|
-
let result = new BigIntegerField();
|
|
191
|
+
let result = new BigIntegerField(options);
|
|
177
192
|
return Object.assign(result, options);
|
|
178
193
|
}
|
|
179
194
|
exports.BigIntegerType = BigIntegerType;
|
|
180
|
-
class FloatField extends
|
|
195
|
+
class FloatField extends NumberField {
|
|
181
196
|
constructor() {
|
|
182
197
|
super(...arguments);
|
|
183
198
|
this.type = { dbType: schema_1.DBType.Float };
|
|
@@ -185,7 +200,7 @@ class FloatField extends BaseField {
|
|
|
185
200
|
}
|
|
186
201
|
exports.FloatField = FloatField;
|
|
187
202
|
function FloatType(options) {
|
|
188
|
-
let result = new FloatField();
|
|
203
|
+
let result = new FloatField(options);
|
|
189
204
|
return Object.assign(result, options);
|
|
190
205
|
}
|
|
191
206
|
exports.FloatType = FloatType;
|
|
@@ -307,6 +322,58 @@ class StringField extends BaseField {
|
|
|
307
322
|
}
|
|
308
323
|
}
|
|
309
324
|
exports.StringField = StringField;
|
|
325
|
+
class PolymorphicStringField extends StringField {
|
|
326
|
+
constructor(opts) {
|
|
327
|
+
super(opts);
|
|
328
|
+
this.opts = opts;
|
|
329
|
+
if (opts.types) {
|
|
330
|
+
this.camelCaseVals = opts.types.map((v) => (0, camel_case_1.camelCase)(v));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
validateWithFullData(val, b) {
|
|
334
|
+
const input = b.getInput();
|
|
335
|
+
const inputKey = b.orchestrator.__getOptions().fieldInfo[this.opts.parentFieldToValidate]
|
|
336
|
+
.inputKey;
|
|
337
|
+
const v = input[inputKey];
|
|
338
|
+
if (val === null) {
|
|
339
|
+
// if this is being set to null, ok if v is also null
|
|
340
|
+
return v === null;
|
|
341
|
+
}
|
|
342
|
+
// if this is not being set, ok if v is not being set
|
|
343
|
+
if (val === undefined && b.operation === base_1.WriteOperation.Insert) {
|
|
344
|
+
return v === undefined;
|
|
345
|
+
}
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
valid(val) {
|
|
349
|
+
if (!this.camelCaseVals) {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
let str = (0, camel_case_1.camelCase)(String(val));
|
|
353
|
+
// allow different cases because it could be coming from different clients who don't have strong typing
|
|
354
|
+
return this.camelCaseVals.some((value) => value === str);
|
|
355
|
+
}
|
|
356
|
+
format(val) {
|
|
357
|
+
if (!this.camelCaseVals) {
|
|
358
|
+
return val;
|
|
359
|
+
}
|
|
360
|
+
const converted = (0, camel_case_1.camelCase)(String(val));
|
|
361
|
+
for (const v of this.camelCaseVals) {
|
|
362
|
+
if (v === val) {
|
|
363
|
+
return val;
|
|
364
|
+
}
|
|
365
|
+
if (converted === v) {
|
|
366
|
+
return converted;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return val;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
exports.PolymorphicStringField = PolymorphicStringField;
|
|
373
|
+
function PolymorphicStringType(opts) {
|
|
374
|
+
let result = new PolymorphicStringField(opts);
|
|
375
|
+
return Object.assign(result, opts);
|
|
376
|
+
}
|
|
310
377
|
function StringType(options) {
|
|
311
378
|
let result = new StringField(options);
|
|
312
379
|
const options2 = { ...options };
|
|
@@ -426,9 +493,10 @@ class DateField extends BaseField {
|
|
|
426
493
|
this.type = { dbType: schema_1.DBType.Date };
|
|
427
494
|
}
|
|
428
495
|
format(val) {
|
|
429
|
-
if (
|
|
496
|
+
if (typeof val === "string") {
|
|
430
497
|
return val;
|
|
431
498
|
}
|
|
499
|
+
val = new Date(val);
|
|
432
500
|
let yy = (0, exports.leftPad)(val.getFullYear());
|
|
433
501
|
// lol this API
|
|
434
502
|
// for some reason this is 0-index
|
|
@@ -444,6 +512,9 @@ function DateType(options) {
|
|
|
444
512
|
return Object.assign(result, options);
|
|
445
513
|
}
|
|
446
514
|
exports.DateType = DateType;
|
|
515
|
+
/**
|
|
516
|
+
* @deprecated Use StringEnumField
|
|
517
|
+
*/
|
|
447
518
|
class EnumField extends BaseField {
|
|
448
519
|
constructor(options) {
|
|
449
520
|
super();
|
|
@@ -454,10 +525,12 @@ class EnumField extends BaseField {
|
|
|
454
525
|
enumMap: options.map,
|
|
455
526
|
type: options.tsType,
|
|
456
527
|
graphQLType: options.graphQLType,
|
|
528
|
+
disableUnknownType: options.disableUnknownType,
|
|
529
|
+
globalType: options.globalType,
|
|
457
530
|
};
|
|
458
531
|
if (!options.foreignKey) {
|
|
459
|
-
if (!options.values && !options.map) {
|
|
460
|
-
throw new Error("values or
|
|
532
|
+
if (!options.values && !options.map && !options.globalType) {
|
|
533
|
+
throw new Error("values, map or globalType required if not look up table enum. Look-up table enum indicated by foreignKey field");
|
|
461
534
|
}
|
|
462
535
|
if (options.values) {
|
|
463
536
|
if (!options.values.length) {
|
|
@@ -466,7 +539,7 @@ class EnumField extends BaseField {
|
|
|
466
539
|
}
|
|
467
540
|
if (options.map) {
|
|
468
541
|
let count = 0;
|
|
469
|
-
for (const
|
|
542
|
+
for (const _ in options.map) {
|
|
470
543
|
count++;
|
|
471
544
|
break;
|
|
472
545
|
}
|
|
@@ -476,8 +549,8 @@ class EnumField extends BaseField {
|
|
|
476
549
|
}
|
|
477
550
|
}
|
|
478
551
|
else {
|
|
479
|
-
if (options.values || options.map) {
|
|
480
|
-
throw new Error("cannot specify values or
|
|
552
|
+
if (options.values || options.map || options.globalType) {
|
|
553
|
+
throw new Error("cannot specify values, map or globalType and foreign key for lookup table enum type");
|
|
481
554
|
}
|
|
482
555
|
if (options.createEnumType) {
|
|
483
556
|
throw new Error("cannot specify createEnumType without specifying values");
|
|
@@ -492,69 +565,124 @@ class EnumField extends BaseField {
|
|
|
492
565
|
this.values = options.values;
|
|
493
566
|
this.map = options.map;
|
|
494
567
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
568
|
+
async valid(val) {
|
|
569
|
+
if (this.type.globalType) {
|
|
570
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
571
|
+
if (f && f.valid) {
|
|
572
|
+
return f.valid(val);
|
|
573
|
+
}
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
500
576
|
// lookup table enum and indicated via presence of foreignKey
|
|
501
577
|
if (!this.values && !this.map) {
|
|
502
578
|
return true;
|
|
503
579
|
}
|
|
504
580
|
if (this.values) {
|
|
505
581
|
let str = String(val);
|
|
506
|
-
return this.values.some((value) => value === str
|
|
582
|
+
return this.values.some((value) => value === str);
|
|
507
583
|
}
|
|
508
584
|
for (const k in this.map) {
|
|
509
585
|
const v = this.map[k];
|
|
510
|
-
if (v === val
|
|
511
|
-
// TODO decide on behavior for GQL since GQL only supports one type
|
|
586
|
+
if (v === val) {
|
|
512
587
|
return true;
|
|
513
588
|
}
|
|
514
589
|
}
|
|
515
590
|
return false;
|
|
516
591
|
}
|
|
517
592
|
format(val) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
let str = String(val);
|
|
524
|
-
if (this.values) {
|
|
525
|
-
for (let i = 0; i < this.values.length; i++) {
|
|
526
|
-
let value = this.values[i];
|
|
527
|
-
// store the format that maps to the given value in the db instead of saving the upper case value
|
|
528
|
-
if (str === value || str === this.convertForGQL(value)) {
|
|
529
|
-
return value;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
if (this.map) {
|
|
534
|
-
for (const k in this.map) {
|
|
535
|
-
const v = this.map[k];
|
|
536
|
-
if (str === v) {
|
|
537
|
-
return v;
|
|
538
|
-
}
|
|
539
|
-
if (str === this.convertForGQL(k)) {
|
|
540
|
-
return v;
|
|
541
|
-
}
|
|
593
|
+
if (this.type.globalType) {
|
|
594
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
595
|
+
if (f && f.format) {
|
|
596
|
+
return f.format(val);
|
|
542
597
|
}
|
|
598
|
+
return val;
|
|
543
599
|
}
|
|
544
|
-
// whelp, just return what's passed
|
|
545
600
|
return val;
|
|
546
601
|
}
|
|
547
602
|
}
|
|
548
603
|
exports.EnumField = EnumField;
|
|
604
|
+
class StringEnumField extends EnumField {
|
|
605
|
+
}
|
|
606
|
+
exports.StringEnumField = StringEnumField;
|
|
549
607
|
function EnumType(options) {
|
|
550
|
-
let result = new
|
|
608
|
+
let result = new StringEnumField(options);
|
|
551
609
|
return Object.assign(result, options);
|
|
552
610
|
}
|
|
553
611
|
exports.EnumType = EnumType;
|
|
612
|
+
class IntegerEnumField extends BaseField {
|
|
613
|
+
constructor(options) {
|
|
614
|
+
super();
|
|
615
|
+
this.type = {
|
|
616
|
+
dbType: schema_1.DBType.IntEnum,
|
|
617
|
+
intEnumMap: options.map,
|
|
618
|
+
type: options.tsType,
|
|
619
|
+
graphQLType: options.graphQLType,
|
|
620
|
+
deprecatedIntEnumMap: options.deprecated,
|
|
621
|
+
disableUnknownType: options.disableUnknownType,
|
|
622
|
+
globalType: options.globalType,
|
|
623
|
+
};
|
|
624
|
+
if (options.foreignKey) {
|
|
625
|
+
throw new Error(`foreignKey on intEnum not supported`);
|
|
626
|
+
}
|
|
627
|
+
if (options.globalType) {
|
|
628
|
+
if (options.map) {
|
|
629
|
+
throw new Error(`cannot specify map and globalType`);
|
|
630
|
+
}
|
|
631
|
+
this.map = {};
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
let count = 0;
|
|
635
|
+
for (const _ in options.map) {
|
|
636
|
+
count++;
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
if (!count) {
|
|
640
|
+
throw new Error("need at least one entry in enum map");
|
|
641
|
+
}
|
|
642
|
+
if (!options.map) {
|
|
643
|
+
throw new Error("map required if not globalType");
|
|
644
|
+
}
|
|
645
|
+
this.map = options.map;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
async valid(val) {
|
|
649
|
+
if (this.type?.globalType) {
|
|
650
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
651
|
+
if (f && f.valid) {
|
|
652
|
+
return f.valid(val);
|
|
653
|
+
}
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
// lookup table enum and indicated via presence of foreignKey
|
|
657
|
+
for (const k in this.map) {
|
|
658
|
+
const v = this.map[k];
|
|
659
|
+
if (v === val || v === parseInt(val)) {
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
format(val) {
|
|
666
|
+
if (this.type.globalType) {
|
|
667
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
668
|
+
if (f && f.format) {
|
|
669
|
+
return f.format(val);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return parseInt(val);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
exports.IntegerEnumField = IntegerEnumField;
|
|
676
|
+
function IntegerEnumType(options) {
|
|
677
|
+
let result = new IntegerEnumField(options);
|
|
678
|
+
return Object.assign(result, options);
|
|
679
|
+
}
|
|
680
|
+
exports.IntegerEnumType = IntegerEnumType;
|
|
554
681
|
class ListField extends BaseField {
|
|
555
682
|
constructor(field, options) {
|
|
556
683
|
super();
|
|
557
684
|
this.field = field;
|
|
685
|
+
this.options = options;
|
|
558
686
|
this.validators = [];
|
|
559
687
|
if (field.type.dbType === schema_1.DBType.List) {
|
|
560
688
|
throw new Error(`nested lists not currently supported`);
|
|
@@ -565,6 +693,9 @@ class ListField extends BaseField {
|
|
|
565
693
|
};
|
|
566
694
|
Object.assign(this, options);
|
|
567
695
|
}
|
|
696
|
+
__getElemField() {
|
|
697
|
+
return this.field;
|
|
698
|
+
}
|
|
568
699
|
validate(validator) {
|
|
569
700
|
this.validators.push(validator);
|
|
570
701
|
return this;
|
|
@@ -592,7 +723,12 @@ class ListField extends BaseField {
|
|
|
592
723
|
return result;
|
|
593
724
|
}
|
|
594
725
|
postgresVal(val, jsonType) {
|
|
595
|
-
if (!jsonType) {
|
|
726
|
+
if (!jsonType && val === "") {
|
|
727
|
+
// support empty strings in list
|
|
728
|
+
val = '"' + val + '"';
|
|
729
|
+
return val;
|
|
730
|
+
}
|
|
731
|
+
if (this.options?.disableJSONStringify) {
|
|
596
732
|
return val;
|
|
597
733
|
}
|
|
598
734
|
return JSON.stringify(val);
|
|
@@ -720,7 +856,18 @@ function EnumListType(options) {
|
|
|
720
856
|
return new ListField(EnumType(options), options);
|
|
721
857
|
}
|
|
722
858
|
exports.EnumListType = EnumListType;
|
|
859
|
+
function IntegerEnumListType(options) {
|
|
860
|
+
// not all of these will make sense in a list...
|
|
861
|
+
// can make it work eventually but involves work we're not currently trying to do
|
|
862
|
+
// developer can try to work around it by calling below on their own.
|
|
863
|
+
// unclear what the behavior is
|
|
864
|
+
return new ListField(IntegerEnumType(options), options);
|
|
865
|
+
}
|
|
866
|
+
exports.IntegerEnumListType = IntegerEnumListType;
|
|
723
867
|
function UUIDListType(options) {
|
|
724
|
-
return new ListField(UUIDType(options),
|
|
868
|
+
return new ListField(UUIDType(options), {
|
|
869
|
+
...options,
|
|
870
|
+
disableJSONStringify: true,
|
|
871
|
+
});
|
|
725
872
|
}
|
|
726
873
|
exports.UUIDListType = UUIDListType;
|
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, getFieldsWithPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, getTransformedReadClause, getObjectLoaderProperties, } from "./schema";
|
|
4
|
-
export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, EntSchema, EntSchemaWithTZ, } 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, ActionField, } 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
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/schema/json_field.d.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
import { FieldOptions, Type, Field,
|
|
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?:
|
|
5
|
+
importType?: DeprecatedImportType;
|
|
6
|
+
}
|
|
7
|
+
interface allJSONOptions extends JSONOptions {
|
|
8
|
+
jsonAsList?: boolean;
|
|
6
9
|
}
|
|
7
10
|
export declare class JSONField extends BaseField implements Field {
|
|
8
11
|
private options?;
|
|
9
12
|
type: Type;
|
|
10
|
-
constructor(jsonb: boolean, options?:
|
|
11
|
-
format(val: any):
|
|
13
|
+
constructor(jsonb: boolean, options?: allJSONOptions | undefined);
|
|
14
|
+
format(val: any, nested?: boolean): any;
|
|
12
15
|
valid(val: any): boolean;
|
|
13
16
|
}
|
|
14
17
|
export declare function JSONType(options?: JSONOptions): JSONField;
|
|
15
18
|
export declare function JSONBType(options?: JSONOptions): JSONField;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use JSONBTypeAsList
|
|
21
|
+
*/
|
|
16
22
|
export declare function JSONBListType(options?: JSONOptions): ListField;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated use JSONTypeAsList
|
|
25
|
+
*/
|
|
17
26
|
export declare function JSONListType(options?: JSONOptions): ListField;
|
|
27
|
+
export declare function JSONBTypeAsList(options?: JSONOptions): JSONField & JSONOptions;
|
|
28
|
+
export declare function JSONTypeAsList(options?: JSONOptions): JSONField & JSONOptions;
|
|
29
|
+
export {};
|
package/schema/json_field.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSONListType = exports.JSONBListType = exports.JSONBType = exports.JSONType = exports.JSONField = void 0;
|
|
3
|
+
exports.JSONTypeAsList = exports.JSONBTypeAsList = exports.JSONListType = exports.JSONBListType = exports.JSONBType = exports.JSONType = exports.JSONField = void 0;
|
|
4
4
|
const schema_1 = require("./schema");
|
|
5
5
|
const field_1 = require("./field");
|
|
6
6
|
class JSONField extends field_1.BaseField {
|
|
@@ -16,8 +16,16 @@ class JSONField extends field_1.BaseField {
|
|
|
16
16
|
if (options?.importType) {
|
|
17
17
|
this.type.importType = options.importType;
|
|
18
18
|
}
|
|
19
|
+
if (options?.jsonAsList) {
|
|
20
|
+
this.type.listElemType = {
|
|
21
|
+
dbType: schema_1.DBType.JSONB,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
19
24
|
}
|
|
20
|
-
format(val) {
|
|
25
|
+
format(val, nested) {
|
|
26
|
+
if (nested) {
|
|
27
|
+
return val;
|
|
28
|
+
}
|
|
21
29
|
return JSON.stringify(val);
|
|
22
30
|
}
|
|
23
31
|
valid(val) {
|
|
@@ -38,11 +46,33 @@ function JSONBType(options) {
|
|
|
38
46
|
return Object.assign(result, options);
|
|
39
47
|
}
|
|
40
48
|
exports.JSONBType = JSONBType;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated use JSONBTypeAsList
|
|
51
|
+
*/
|
|
41
52
|
function JSONBListType(options) {
|
|
42
53
|
return new field_1.ListField(JSONBType(options), options);
|
|
43
54
|
}
|
|
44
55
|
exports.JSONBListType = JSONBListType;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated use JSONTypeAsList
|
|
58
|
+
*/
|
|
45
59
|
function JSONListType(options) {
|
|
46
60
|
return new field_1.ListField(JSONType(options), options);
|
|
47
61
|
}
|
|
48
62
|
exports.JSONListType = JSONListType;
|
|
63
|
+
function JSONBTypeAsList(options) {
|
|
64
|
+
let result = new JSONField(true, {
|
|
65
|
+
...options,
|
|
66
|
+
jsonAsList: true,
|
|
67
|
+
});
|
|
68
|
+
return Object.assign(result, options);
|
|
69
|
+
}
|
|
70
|
+
exports.JSONBTypeAsList = JSONBTypeAsList;
|
|
71
|
+
function JSONTypeAsList(options) {
|
|
72
|
+
let result = new JSONField(false, {
|
|
73
|
+
...options,
|
|
74
|
+
jsonAsList: true,
|
|
75
|
+
});
|
|
76
|
+
return Object.assign(result, options);
|
|
77
|
+
}
|
|
78
|
+
exports.JSONTypeAsList = JSONTypeAsList;
|