@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha101
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 +40 -16
- package/action/orchestrator.js +230 -62
- 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 +49 -26
- package/core/base.js +7 -1
- package/core/clause.d.ts +88 -7
- package/core/clause.js +355 -63
- package/core/config.d.ts +12 -1
- package/core/config.js +7 -1
- package/core/context.d.ts +5 -3
- 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 +81 -25
- package/core/ent.js +636 -193
- 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 +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +6 -5
- package/core/loaders/object_loader.js +67 -59
- package/core/loaders/query_loader.d.ts +6 -12
- 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 +26 -0
- package/core/query/custom_clause_query.js +78 -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 +469 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.d.ts +14 -7
- package/graphql/graphql.js +23 -7
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +1 -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/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +12 -5
- package/index.js +20 -7
- package/package.json +17 -16
- package/parse_schema/parse.d.ts +29 -9
- package/parse_schema/parse.js +118 -11
- package/schema/base_schema.d.ts +5 -3
- package/schema/base_schema.js +5 -0
- package/schema/field.d.ts +74 -20
- package/schema/field.js +174 -69
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +81 -18
- package/schema/schema.js +24 -17
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +57 -21
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +117 -30
- package/scripts/{transform_code.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/{transform_schema.d.ts → move_types.d.ts} +0 -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 +46 -47
- package/testutils/builder.js +108 -65
- 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} +179 -44
- 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 +27 -8
- 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 +7 -3
- 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 +7 -4
- 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 +26 -2
- package/tsc/ast.js +163 -17
- package/tsc/compilerOptions.d.ts +2 -1
- package/tsc/compilerOptions.js +11 -2
- 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 +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/{scripts → tsc}/transform_schema.js +145 -119
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/transform_code.js +0 -114
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,14 @@ 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 util_1 = require("util");
|
|
28
34
|
class BaseField {
|
|
29
35
|
logValue(val) {
|
|
30
36
|
if (this.sensitive) {
|
|
@@ -60,31 +66,26 @@ class UUIDField extends BaseField {
|
|
|
60
66
|
else {
|
|
61
67
|
throw new Error(`unsupported id polymorhpic type ${fieldName}`);
|
|
62
68
|
}
|
|
69
|
+
let types;
|
|
70
|
+
let serverDefault = undefined;
|
|
71
|
+
if (typeof polymorphic === "object") {
|
|
72
|
+
serverDefault = polymorphic.serverDefault;
|
|
73
|
+
types = polymorphic.types;
|
|
74
|
+
}
|
|
63
75
|
// polymorphic field automatically hidden from GraphQL
|
|
64
76
|
// can be made visible with custom fields if user wants to change this behavior
|
|
65
77
|
// can't be foreignKey so need to make other changes to the field
|
|
66
78
|
// 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
|
-
}
|
|
79
|
+
return {
|
|
80
|
+
[name]: PolymorphicStringType({
|
|
81
|
+
types: types,
|
|
82
|
+
hideFromGraphQL: true,
|
|
83
|
+
derivedWhenEmbedded: true,
|
|
84
|
+
nullable: this.options?.nullable,
|
|
85
|
+
parentFieldToValidate: fieldName,
|
|
86
|
+
serverDefault: serverDefault,
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
88
89
|
}
|
|
89
90
|
return {};
|
|
90
91
|
}
|
|
@@ -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
|
}
|
|
@@ -115,9 +119,10 @@ function UUIDType(options) {
|
|
|
115
119
|
return Object.assign(result, options);
|
|
116
120
|
}
|
|
117
121
|
exports.UUIDType = UUIDType;
|
|
118
|
-
class
|
|
122
|
+
class NumberField extends BaseField {
|
|
119
123
|
constructor(options) {
|
|
120
124
|
super();
|
|
125
|
+
// to be overriden as needed
|
|
121
126
|
this.type = { dbType: schema_1.DBType.Int };
|
|
122
127
|
this.validators = [];
|
|
123
128
|
this.options = {};
|
|
@@ -141,9 +146,11 @@ class IntegerField extends BaseField {
|
|
|
141
146
|
this.options = options;
|
|
142
147
|
}
|
|
143
148
|
min(l) {
|
|
149
|
+
// @ts-ignore Operator '>=' cannot be applied to types 'number' and 'T'.
|
|
144
150
|
return this.validate((val) => val >= l);
|
|
145
151
|
}
|
|
146
152
|
max(l) {
|
|
153
|
+
// @ts-ignore Operator '<=' cannot be applied to types 'number' and 'T'.
|
|
147
154
|
return this.validate((val) => val <= l);
|
|
148
155
|
}
|
|
149
156
|
valid(val) {
|
|
@@ -159,13 +166,20 @@ class IntegerField extends BaseField {
|
|
|
159
166
|
return this;
|
|
160
167
|
}
|
|
161
168
|
}
|
|
169
|
+
exports.NumberField = NumberField;
|
|
170
|
+
class IntegerField extends NumberField {
|
|
171
|
+
constructor() {
|
|
172
|
+
super(...arguments);
|
|
173
|
+
this.type = { dbType: schema_1.DBType.Int };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
162
176
|
exports.IntegerField = IntegerField;
|
|
163
177
|
function IntegerType(options) {
|
|
164
178
|
let result = new IntegerField(options);
|
|
165
179
|
return Object.assign(result, options);
|
|
166
180
|
}
|
|
167
181
|
exports.IntegerType = IntegerType;
|
|
168
|
-
class BigIntegerField extends
|
|
182
|
+
class BigIntegerField extends NumberField {
|
|
169
183
|
constructor() {
|
|
170
184
|
super(...arguments);
|
|
171
185
|
this.type = { dbType: schema_1.DBType.BigInt };
|
|
@@ -173,11 +187,11 @@ class BigIntegerField extends BaseField {
|
|
|
173
187
|
}
|
|
174
188
|
exports.BigIntegerField = BigIntegerField;
|
|
175
189
|
function BigIntegerType(options) {
|
|
176
|
-
let result = new BigIntegerField();
|
|
190
|
+
let result = new BigIntegerField(options);
|
|
177
191
|
return Object.assign(result, options);
|
|
178
192
|
}
|
|
179
193
|
exports.BigIntegerType = BigIntegerType;
|
|
180
|
-
class FloatField extends
|
|
194
|
+
class FloatField extends NumberField {
|
|
181
195
|
constructor() {
|
|
182
196
|
super(...arguments);
|
|
183
197
|
this.type = { dbType: schema_1.DBType.Float };
|
|
@@ -185,7 +199,7 @@ class FloatField extends BaseField {
|
|
|
185
199
|
}
|
|
186
200
|
exports.FloatField = FloatField;
|
|
187
201
|
function FloatType(options) {
|
|
188
|
-
let result = new FloatField();
|
|
202
|
+
let result = new FloatField(options);
|
|
189
203
|
return Object.assign(result, options);
|
|
190
204
|
}
|
|
191
205
|
exports.FloatType = FloatType;
|
|
@@ -307,6 +321,58 @@ class StringField extends BaseField {
|
|
|
307
321
|
}
|
|
308
322
|
}
|
|
309
323
|
exports.StringField = StringField;
|
|
324
|
+
class PolymorphicStringField extends StringField {
|
|
325
|
+
constructor(opts) {
|
|
326
|
+
super(opts);
|
|
327
|
+
this.opts = opts;
|
|
328
|
+
if (opts.types) {
|
|
329
|
+
this.camelCaseVals = opts.types.map((v) => (0, camel_case_1.camelCase)(v));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
validateWithFullData(val, b) {
|
|
333
|
+
const input = b.getInput();
|
|
334
|
+
const inputKey = b.orchestrator.__getOptions().fieldInfo[this.opts.parentFieldToValidate]
|
|
335
|
+
.inputKey;
|
|
336
|
+
const v = input[inputKey];
|
|
337
|
+
if (val === null) {
|
|
338
|
+
// if this is being set to null, ok if v is also null
|
|
339
|
+
return v === null;
|
|
340
|
+
}
|
|
341
|
+
// if this is not being set, ok if v is not being set
|
|
342
|
+
if (val === undefined && b.operation === base_1.WriteOperation.Insert) {
|
|
343
|
+
return v === undefined;
|
|
344
|
+
}
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
valid(val) {
|
|
348
|
+
if (!this.camelCaseVals) {
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
let str = (0, camel_case_1.camelCase)(String(val));
|
|
352
|
+
// allow different cases because it could be coming from different clients who don't have strong typing
|
|
353
|
+
return this.camelCaseVals.some((value) => value === str);
|
|
354
|
+
}
|
|
355
|
+
format(val) {
|
|
356
|
+
if (!this.camelCaseVals) {
|
|
357
|
+
return val;
|
|
358
|
+
}
|
|
359
|
+
const converted = (0, camel_case_1.camelCase)(String(val));
|
|
360
|
+
for (const v of this.camelCaseVals) {
|
|
361
|
+
if (v === val) {
|
|
362
|
+
return val;
|
|
363
|
+
}
|
|
364
|
+
if (converted === v) {
|
|
365
|
+
return converted;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return val;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
exports.PolymorphicStringField = PolymorphicStringField;
|
|
372
|
+
function PolymorphicStringType(opts) {
|
|
373
|
+
let result = new PolymorphicStringField(opts);
|
|
374
|
+
return Object.assign(result, opts);
|
|
375
|
+
}
|
|
310
376
|
function StringType(options) {
|
|
311
377
|
let result = new StringField(options);
|
|
312
378
|
const options2 = { ...options };
|
|
@@ -426,9 +492,10 @@ class DateField extends BaseField {
|
|
|
426
492
|
this.type = { dbType: schema_1.DBType.Date };
|
|
427
493
|
}
|
|
428
494
|
format(val) {
|
|
429
|
-
if (
|
|
495
|
+
if (typeof val === "string") {
|
|
430
496
|
return val;
|
|
431
497
|
}
|
|
498
|
+
val = new Date(val);
|
|
432
499
|
let yy = (0, exports.leftPad)(val.getFullYear());
|
|
433
500
|
// lol this API
|
|
434
501
|
// for some reason this is 0-index
|
|
@@ -444,6 +511,9 @@ function DateType(options) {
|
|
|
444
511
|
return Object.assign(result, options);
|
|
445
512
|
}
|
|
446
513
|
exports.DateType = DateType;
|
|
514
|
+
/**
|
|
515
|
+
* @deprecated Use StringEnumField
|
|
516
|
+
*/
|
|
447
517
|
class EnumField extends BaseField {
|
|
448
518
|
constructor(options) {
|
|
449
519
|
super();
|
|
@@ -454,6 +524,7 @@ class EnumField extends BaseField {
|
|
|
454
524
|
enumMap: options.map,
|
|
455
525
|
type: options.tsType,
|
|
456
526
|
graphQLType: options.graphQLType,
|
|
527
|
+
disableUnknownType: options.disableUnknownType,
|
|
457
528
|
};
|
|
458
529
|
if (!options.foreignKey) {
|
|
459
530
|
if (!options.values && !options.map) {
|
|
@@ -466,7 +537,7 @@ class EnumField extends BaseField {
|
|
|
466
537
|
}
|
|
467
538
|
if (options.map) {
|
|
468
539
|
let count = 0;
|
|
469
|
-
for (const
|
|
540
|
+
for (const _ in options.map) {
|
|
470
541
|
count++;
|
|
471
542
|
break;
|
|
472
543
|
}
|
|
@@ -492,10 +563,6 @@ class EnumField extends BaseField {
|
|
|
492
563
|
this.values = options.values;
|
|
493
564
|
this.map = options.map;
|
|
494
565
|
}
|
|
495
|
-
// TODO need to update this for map
|
|
496
|
-
convertForGQL(value) {
|
|
497
|
-
return (0, snake_case_1.snakeCase)(value).toUpperCase();
|
|
498
|
-
}
|
|
499
566
|
valid(val) {
|
|
500
567
|
// lookup table enum and indicated via presence of foreignKey
|
|
501
568
|
if (!this.values && !this.map) {
|
|
@@ -503,58 +570,77 @@ class EnumField extends BaseField {
|
|
|
503
570
|
}
|
|
504
571
|
if (this.values) {
|
|
505
572
|
let str = String(val);
|
|
506
|
-
return this.values.some((value) => value === str
|
|
573
|
+
return this.values.some((value) => value === str);
|
|
507
574
|
}
|
|
508
575
|
for (const k in this.map) {
|
|
509
576
|
const v = this.map[k];
|
|
510
|
-
if (v === val
|
|
511
|
-
// TODO decide on behavior for GQL since GQL only supports one type
|
|
577
|
+
if (v === val) {
|
|
512
578
|
return true;
|
|
513
579
|
}
|
|
514
580
|
}
|
|
515
581
|
return false;
|
|
516
582
|
}
|
|
517
583
|
format(val) {
|
|
518
|
-
// TODO need to format correctly for graphql purposes...
|
|
519
|
-
// how to best get the values in the db...
|
|
520
|
-
if (!this.values && !this.map) {
|
|
521
|
-
return val;
|
|
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
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
// whelp, just return what's passed
|
|
545
584
|
return val;
|
|
546
585
|
}
|
|
547
586
|
}
|
|
548
587
|
exports.EnumField = EnumField;
|
|
588
|
+
class StringEnumField extends EnumField {
|
|
589
|
+
}
|
|
590
|
+
exports.StringEnumField = StringEnumField;
|
|
549
591
|
function EnumType(options) {
|
|
550
|
-
let result = new
|
|
592
|
+
let result = new StringEnumField(options);
|
|
551
593
|
return Object.assign(result, options);
|
|
552
594
|
}
|
|
553
595
|
exports.EnumType = EnumType;
|
|
596
|
+
class IntegerEnumField extends BaseField {
|
|
597
|
+
constructor(options) {
|
|
598
|
+
super();
|
|
599
|
+
this.type = {
|
|
600
|
+
dbType: schema_1.DBType.IntEnum,
|
|
601
|
+
intEnumMap: options.map,
|
|
602
|
+
type: options.tsType,
|
|
603
|
+
graphQLType: options.graphQLType,
|
|
604
|
+
deprecatedIntEnumMap: options.deprecated,
|
|
605
|
+
};
|
|
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
|
+
if (options.foreignKey) {
|
|
615
|
+
throw new Error(`foreignKey on intEnum not supported`);
|
|
616
|
+
}
|
|
617
|
+
this.map = options.map;
|
|
618
|
+
}
|
|
619
|
+
valid(val) {
|
|
620
|
+
// lookup table enum and indicated via presence of foreignKey
|
|
621
|
+
for (const k in this.map) {
|
|
622
|
+
const v = this.map[k];
|
|
623
|
+
if (v === val || v === parseInt(val)) {
|
|
624
|
+
return true;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return false;
|
|
628
|
+
}
|
|
629
|
+
format(val) {
|
|
630
|
+
return parseInt(val);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
exports.IntegerEnumField = IntegerEnumField;
|
|
634
|
+
function IntegerEnumType(options) {
|
|
635
|
+
let result = new IntegerEnumField(options);
|
|
636
|
+
return Object.assign(result, options);
|
|
637
|
+
}
|
|
638
|
+
exports.IntegerEnumType = IntegerEnumType;
|
|
554
639
|
class ListField extends BaseField {
|
|
555
640
|
constructor(field, options) {
|
|
556
641
|
super();
|
|
557
642
|
this.field = field;
|
|
643
|
+
this.options = options;
|
|
558
644
|
this.validators = [];
|
|
559
645
|
if (field.type.dbType === schema_1.DBType.List) {
|
|
560
646
|
throw new Error(`nested lists not currently supported`);
|
|
@@ -565,6 +651,9 @@ class ListField extends BaseField {
|
|
|
565
651
|
};
|
|
566
652
|
Object.assign(this, options);
|
|
567
653
|
}
|
|
654
|
+
__getElemField() {
|
|
655
|
+
return this.field;
|
|
656
|
+
}
|
|
568
657
|
validate(validator) {
|
|
569
658
|
this.validators.push(validator);
|
|
570
659
|
return this;
|
|
@@ -592,7 +681,12 @@ class ListField extends BaseField {
|
|
|
592
681
|
return result;
|
|
593
682
|
}
|
|
594
683
|
postgresVal(val, jsonType) {
|
|
595
|
-
if (!jsonType) {
|
|
684
|
+
if (!jsonType && val === "") {
|
|
685
|
+
// support empty strings in list
|
|
686
|
+
val = '"' + val + '"';
|
|
687
|
+
return val;
|
|
688
|
+
}
|
|
689
|
+
if (this.options?.disableJSONStringify) {
|
|
596
690
|
return val;
|
|
597
691
|
}
|
|
598
692
|
return JSON.stringify(val);
|
|
@@ -720,7 +814,18 @@ function EnumListType(options) {
|
|
|
720
814
|
return new ListField(EnumType(options), options);
|
|
721
815
|
}
|
|
722
816
|
exports.EnumListType = EnumListType;
|
|
817
|
+
function IntegerEnumListType(options) {
|
|
818
|
+
// not all of these will make sense in a list...
|
|
819
|
+
// can make it work eventually but involves work we're not currently trying to do
|
|
820
|
+
// developer can try to work around it by calling below on their own.
|
|
821
|
+
// unclear what the behavior is
|
|
822
|
+
return new ListField(IntegerEnumType(options), options);
|
|
823
|
+
}
|
|
824
|
+
exports.IntegerEnumListType = IntegerEnumListType;
|
|
723
825
|
function UUIDListType(options) {
|
|
724
|
-
return new ListField(UUIDType(options),
|
|
826
|
+
return new ListField(UUIDType(options), {
|
|
827
|
+
...options,
|
|
828
|
+
disableJSONStringify: true,
|
|
829
|
+
});
|
|
725
830
|
}
|
|
726
831
|
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, } 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
|
@@ -4,14 +4,26 @@ export interface JSONOptions extends FieldOptions {
|
|
|
4
4
|
validator?: (val: any) => boolean;
|
|
5
5
|
importType?: ImportType;
|
|
6
6
|
}
|
|
7
|
+
interface allJSONOptions extends JSONOptions {
|
|
8
|
+
jsonAsList?: boolean;
|
|
9
|
+
}
|
|
7
10
|
export declare class JSONField extends BaseField implements Field {
|
|
8
11
|
private options?;
|
|
9
12
|
type: Type;
|
|
10
|
-
constructor(jsonb: boolean, options?:
|
|
13
|
+
constructor(jsonb: boolean, options?: allJSONOptions | undefined);
|
|
11
14
|
format(val: any): string;
|
|
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,6 +16,11 @@ 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
25
|
format(val) {
|
|
21
26
|
return JSON.stringify(val);
|
|
@@ -38,11 +43,33 @@ function JSONBType(options) {
|
|
|
38
43
|
return Object.assign(result, options);
|
|
39
44
|
}
|
|
40
45
|
exports.JSONBType = JSONBType;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated use JSONBTypeAsList
|
|
48
|
+
*/
|
|
41
49
|
function JSONBListType(options) {
|
|
42
50
|
return new field_1.ListField(JSONBType(options), options);
|
|
43
51
|
}
|
|
44
52
|
exports.JSONBListType = JSONBListType;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated use JSONTypeAsList
|
|
55
|
+
*/
|
|
45
56
|
function JSONListType(options) {
|
|
46
57
|
return new field_1.ListField(JSONType(options), options);
|
|
47
58
|
}
|
|
48
59
|
exports.JSONListType = JSONListType;
|
|
60
|
+
function JSONBTypeAsList(options) {
|
|
61
|
+
let result = new JSONField(true, {
|
|
62
|
+
...options,
|
|
63
|
+
jsonAsList: true,
|
|
64
|
+
});
|
|
65
|
+
return Object.assign(result, options);
|
|
66
|
+
}
|
|
67
|
+
exports.JSONBTypeAsList = JSONBTypeAsList;
|
|
68
|
+
function JSONTypeAsList(options) {
|
|
69
|
+
let result = new JSONField(false, {
|
|
70
|
+
...options,
|
|
71
|
+
jsonAsList: true,
|
|
72
|
+
});
|
|
73
|
+
return Object.assign(result, options);
|
|
74
|
+
}
|
|
75
|
+
exports.JSONTypeAsList = JSONTypeAsList;
|