@snowtop/ent 0.1.0-alpha16 → 0.1.0-alpha160-test2
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 +25 -14
- package/action/action.js +22 -7
- package/action/executor.d.ts +16 -3
- package/action/executor.js +89 -28
- package/action/experimental_action.d.ts +25 -16
- package/action/experimental_action.js +34 -14
- package/action/index.d.ts +4 -1
- package/action/index.js +7 -1
- package/action/operations.d.ts +126 -0
- package/action/operations.js +686 -0
- package/action/orchestrator.d.ts +43 -12
- package/action/orchestrator.js +461 -101
- 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 +56 -23
- package/core/base.js +7 -1
- package/core/clause.d.ts +103 -39
- package/core/clause.js +430 -66
- package/core/config.d.ts +13 -3
- package/core/config.js +10 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +6 -3
- package/core/context.js +22 -3
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +12 -8
- package/core/db.js +21 -9
- package/core/ent.d.ts +99 -95
- package/core/ent.js +550 -602
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +5 -2
- package/core/loaders/assoc_count_loader.js +19 -3
- package/core/loaders/assoc_edge_loader.d.ts +2 -3
- package/core/loaders/assoc_edge_loader.js +23 -17
- package/core/loaders/index.d.ts +1 -2
- package/core/loaders/index.js +1 -5
- package/core/loaders/loader.d.ts +3 -3
- package/core/loaders/loader.js +4 -21
- package/core/loaders/object_loader.d.ts +30 -9
- package/core/loaders/object_loader.js +226 -79
- package/core/loaders/query_loader.d.ts +7 -13
- package/core/loaders/query_loader.js +60 -24
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +8 -3
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -16
- package/core/privacy.js +68 -51
- package/core/query/assoc_query.d.ts +3 -2
- package/core/query/assoc_query.js +10 -2
- package/core/query/custom_clause_query.d.ts +29 -0
- package/core/query/custom_clause_query.js +105 -0
- package/core/query/custom_query.d.ts +19 -2
- package/core/query/custom_query.js +111 -13
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +18 -4
- package/core/query/query.js +135 -58
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +186 -55
- package/core/query/shared_test.d.ts +9 -2
- package/core/query/shared_test.js +529 -236
- package/core/query_impl.d.ts +8 -0
- package/core/query_impl.js +28 -0
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +3 -1
- package/graphql/graphql.d.ts +108 -22
- package/graphql/graphql.js +183 -137
- package/graphql/graphql_field_helpers.d.ts +9 -3
- package/graphql/graphql_field_helpers.js +22 -2
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +5 -5
- package/graphql/query/connection_type.d.ts +9 -9
- 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/dataz/example1/_auth.js +128 -47
- package/imports/dataz/example1/_viewer.js +87 -39
- package/imports/index.d.ts +7 -2
- package/imports/index.js +20 -5
- package/index.d.ts +23 -5
- package/index.js +35 -10
- package/package.json +20 -19
- package/parse_schema/parse.d.ts +33 -9
- package/parse_schema/parse.js +182 -33
- package/schema/base_schema.d.ts +13 -3
- package/schema/base_schema.js +13 -0
- package/schema/field.d.ts +78 -21
- package/schema/field.js +232 -72
- package/schema/index.d.ts +2 -2
- package/schema/index.js +7 -2
- package/schema/json_field.d.ts +16 -4
- package/schema/json_field.js +32 -2
- package/schema/schema.d.ts +109 -20
- package/schema/schema.js +42 -53
- package/schema/struct_field.d.ts +15 -3
- package/schema/struct_field.js +117 -22
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +12 -8
- package/scripts/custom_graphql.js +167 -64
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +120 -0
- package/scripts/read_schema.js +22 -7
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +405 -0
- package/testutils/builder.d.ts +37 -41
- package/testutils/builder.js +66 -46
- 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} +32 -8
- package/testutils/db/{test_db.js → temp_db.js} +251 -48
- 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 +52 -9
- 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 +56 -26
- package/testutils/fake_comms.js +1 -1
- 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 +13 -7
- package/testutils/fake_data/fake_event.d.ts +4 -1
- package/testutils/fake_data/fake_event.js +7 -6
- 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 +8 -5
- package/testutils/fake_data/fake_user.js +31 -19
- 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 +48 -0
- package/testutils/fake_data/test_helpers.d.ts +14 -6
- package/testutils/fake_data/test_helpers.js +31 -15
- package/testutils/fake_data/user_query.d.ts +16 -6
- package/testutils/fake_data/user_query.js +72 -23
- package/testutils/fake_log.js +1 -1
- 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 +15 -3
- package/tsc/ast.js +114 -23
- 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 +182 -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/core/loaders/index_loader.d.ts +0 -14
- package/core/loaders/index_loader.js +0 -27
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -141
- package/scripts/transform_actions.js +0 -266
- package/scripts/transform_code.d.ts +0 -1
- package/scripts/transform_code.js +0 -111
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_actions.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,16 @@ 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 types_1 = require("util/types");
|
|
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");
|
|
35
|
+
const logger_1 = require("../core/logger");
|
|
28
36
|
class BaseField {
|
|
29
37
|
logValue(val) {
|
|
30
38
|
if (this.sensitive) {
|
|
@@ -60,31 +68,26 @@ class UUIDField extends BaseField {
|
|
|
60
68
|
else {
|
|
61
69
|
throw new Error(`unsupported id polymorhpic type ${fieldName}`);
|
|
62
70
|
}
|
|
71
|
+
let types;
|
|
72
|
+
let serverDefault = undefined;
|
|
73
|
+
if (typeof polymorphic === "object") {
|
|
74
|
+
serverDefault = polymorphic.serverDefault;
|
|
75
|
+
types = polymorphic.types;
|
|
76
|
+
}
|
|
63
77
|
// polymorphic field automatically hidden from GraphQL
|
|
64
78
|
// can be made visible with custom fields if user wants to change this behavior
|
|
65
79
|
// can't be foreignKey so need to make other changes to the field
|
|
66
80
|
// 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
|
-
}
|
|
81
|
+
return {
|
|
82
|
+
[name]: PolymorphicStringType({
|
|
83
|
+
types: types,
|
|
84
|
+
hideFromGraphQL: true,
|
|
85
|
+
derivedWhenEmbedded: true,
|
|
86
|
+
nullable: this.options?.nullable,
|
|
87
|
+
parentFieldToValidate: fieldName,
|
|
88
|
+
serverDefault: serverDefault,
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
88
91
|
}
|
|
89
92
|
return {};
|
|
90
93
|
}
|
|
@@ -92,6 +95,9 @@ class UUIDField extends BaseField {
|
|
|
92
95
|
return val.placeholderID !== undefined;
|
|
93
96
|
}
|
|
94
97
|
async valid(val) {
|
|
98
|
+
if (typeof val === "string" && !(0, uuid_1.validate)(val)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
95
101
|
if (!this.options?.fieldEdge?.enforceSchema) {
|
|
96
102
|
return true;
|
|
97
103
|
}
|
|
@@ -115,9 +121,10 @@ function UUIDType(options) {
|
|
|
115
121
|
return Object.assign(result, options);
|
|
116
122
|
}
|
|
117
123
|
exports.UUIDType = UUIDType;
|
|
118
|
-
class
|
|
124
|
+
class NumberField extends BaseField {
|
|
119
125
|
constructor(options) {
|
|
120
126
|
super();
|
|
127
|
+
// to be overriden as needed
|
|
121
128
|
this.type = { dbType: schema_1.DBType.Int };
|
|
122
129
|
this.validators = [];
|
|
123
130
|
this.options = {};
|
|
@@ -141,9 +148,11 @@ class IntegerField extends BaseField {
|
|
|
141
148
|
this.options = options;
|
|
142
149
|
}
|
|
143
150
|
min(l) {
|
|
151
|
+
// @ts-ignore Operator '>=' cannot be applied to types 'number' and 'T'.
|
|
144
152
|
return this.validate((val) => val >= l);
|
|
145
153
|
}
|
|
146
154
|
max(l) {
|
|
155
|
+
// @ts-ignore Operator '<=' cannot be applied to types 'number' and 'T'.
|
|
147
156
|
return this.validate((val) => val <= l);
|
|
148
157
|
}
|
|
149
158
|
valid(val) {
|
|
@@ -159,13 +168,20 @@ class IntegerField extends BaseField {
|
|
|
159
168
|
return this;
|
|
160
169
|
}
|
|
161
170
|
}
|
|
171
|
+
exports.NumberField = NumberField;
|
|
172
|
+
class IntegerField extends NumberField {
|
|
173
|
+
constructor() {
|
|
174
|
+
super(...arguments);
|
|
175
|
+
this.type = { dbType: schema_1.DBType.Int };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
162
178
|
exports.IntegerField = IntegerField;
|
|
163
179
|
function IntegerType(options) {
|
|
164
180
|
let result = new IntegerField(options);
|
|
165
181
|
return Object.assign(result, options);
|
|
166
182
|
}
|
|
167
183
|
exports.IntegerType = IntegerType;
|
|
168
|
-
class BigIntegerField extends
|
|
184
|
+
class BigIntegerField extends NumberField {
|
|
169
185
|
constructor() {
|
|
170
186
|
super(...arguments);
|
|
171
187
|
this.type = { dbType: schema_1.DBType.BigInt };
|
|
@@ -173,11 +189,11 @@ class BigIntegerField extends BaseField {
|
|
|
173
189
|
}
|
|
174
190
|
exports.BigIntegerField = BigIntegerField;
|
|
175
191
|
function BigIntegerType(options) {
|
|
176
|
-
let result = new BigIntegerField();
|
|
192
|
+
let result = new BigIntegerField(options);
|
|
177
193
|
return Object.assign(result, options);
|
|
178
194
|
}
|
|
179
195
|
exports.BigIntegerType = BigIntegerType;
|
|
180
|
-
class FloatField extends
|
|
196
|
+
class FloatField extends NumberField {
|
|
181
197
|
constructor() {
|
|
182
198
|
super(...arguments);
|
|
183
199
|
this.type = { dbType: schema_1.DBType.Float };
|
|
@@ -185,7 +201,7 @@ class FloatField extends BaseField {
|
|
|
185
201
|
}
|
|
186
202
|
exports.FloatField = FloatField;
|
|
187
203
|
function FloatType(options) {
|
|
188
|
-
let result = new FloatField();
|
|
204
|
+
let result = new FloatField(options);
|
|
189
205
|
return Object.assign(result, options);
|
|
190
206
|
}
|
|
191
207
|
exports.FloatType = FloatType;
|
|
@@ -307,6 +323,58 @@ class StringField extends BaseField {
|
|
|
307
323
|
}
|
|
308
324
|
}
|
|
309
325
|
exports.StringField = StringField;
|
|
326
|
+
class PolymorphicStringField extends StringField {
|
|
327
|
+
constructor(opts) {
|
|
328
|
+
super(opts);
|
|
329
|
+
this.opts = opts;
|
|
330
|
+
if (opts.types) {
|
|
331
|
+
this.camelCaseVals = opts.types.map((v) => (0, camel_case_1.camelCase)(v));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
validateWithFullData(val, b) {
|
|
335
|
+
const input = b.getInput();
|
|
336
|
+
const inputKey = b.orchestrator.__getOptions().fieldInfo[this.opts.parentFieldToValidate]
|
|
337
|
+
.inputKey;
|
|
338
|
+
const v = input[inputKey];
|
|
339
|
+
if (val === null) {
|
|
340
|
+
// if this is being set to null, ok if v is also null
|
|
341
|
+
return v === null;
|
|
342
|
+
}
|
|
343
|
+
// if this is not being set, ok if v is not being set
|
|
344
|
+
if (val === undefined && b.operation === base_1.WriteOperation.Insert) {
|
|
345
|
+
return v === undefined;
|
|
346
|
+
}
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
valid(val) {
|
|
350
|
+
if (!this.camelCaseVals) {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
let str = (0, camel_case_1.camelCase)(String(val));
|
|
354
|
+
// allow different cases because it could be coming from different clients who don't have strong typing
|
|
355
|
+
return this.camelCaseVals.some((value) => value === str);
|
|
356
|
+
}
|
|
357
|
+
format(val) {
|
|
358
|
+
if (!this.camelCaseVals) {
|
|
359
|
+
return val;
|
|
360
|
+
}
|
|
361
|
+
const converted = (0, camel_case_1.camelCase)(String(val));
|
|
362
|
+
for (const v of this.camelCaseVals) {
|
|
363
|
+
if (v === val) {
|
|
364
|
+
return val;
|
|
365
|
+
}
|
|
366
|
+
if (converted === v) {
|
|
367
|
+
return converted;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return val;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
exports.PolymorphicStringField = PolymorphicStringField;
|
|
374
|
+
function PolymorphicStringType(opts) {
|
|
375
|
+
let result = new PolymorphicStringField(opts);
|
|
376
|
+
return Object.assign(result, opts);
|
|
377
|
+
}
|
|
310
378
|
function StringType(options) {
|
|
311
379
|
let result = new StringField(options);
|
|
312
380
|
const options2 = { ...options };
|
|
@@ -426,9 +494,10 @@ class DateField extends BaseField {
|
|
|
426
494
|
this.type = { dbType: schema_1.DBType.Date };
|
|
427
495
|
}
|
|
428
496
|
format(val) {
|
|
429
|
-
if (
|
|
497
|
+
if (typeof val === "string") {
|
|
430
498
|
return val;
|
|
431
499
|
}
|
|
500
|
+
val = new Date(val);
|
|
432
501
|
let yy = (0, exports.leftPad)(val.getFullYear());
|
|
433
502
|
// lol this API
|
|
434
503
|
// for some reason this is 0-index
|
|
@@ -444,6 +513,9 @@ function DateType(options) {
|
|
|
444
513
|
return Object.assign(result, options);
|
|
445
514
|
}
|
|
446
515
|
exports.DateType = DateType;
|
|
516
|
+
/**
|
|
517
|
+
* @deprecated Use StringEnumField
|
|
518
|
+
*/
|
|
447
519
|
class EnumField extends BaseField {
|
|
448
520
|
constructor(options) {
|
|
449
521
|
super();
|
|
@@ -454,10 +526,12 @@ class EnumField extends BaseField {
|
|
|
454
526
|
enumMap: options.map,
|
|
455
527
|
type: options.tsType,
|
|
456
528
|
graphQLType: options.graphQLType,
|
|
529
|
+
disableUnknownType: options.disableUnknownType,
|
|
530
|
+
globalType: options.globalType,
|
|
457
531
|
};
|
|
458
532
|
if (!options.foreignKey) {
|
|
459
|
-
if (!options.values && !options.map) {
|
|
460
|
-
throw new Error("values or
|
|
533
|
+
if (!options.values && !options.map && !options.globalType) {
|
|
534
|
+
throw new Error("values, map or globalType required if not look up table enum. Look-up table enum indicated by foreignKey field");
|
|
461
535
|
}
|
|
462
536
|
if (options.values) {
|
|
463
537
|
if (!options.values.length) {
|
|
@@ -466,7 +540,7 @@ class EnumField extends BaseField {
|
|
|
466
540
|
}
|
|
467
541
|
if (options.map) {
|
|
468
542
|
let count = 0;
|
|
469
|
-
for (const
|
|
543
|
+
for (const _ in options.map) {
|
|
470
544
|
count++;
|
|
471
545
|
break;
|
|
472
546
|
}
|
|
@@ -476,8 +550,8 @@ class EnumField extends BaseField {
|
|
|
476
550
|
}
|
|
477
551
|
}
|
|
478
552
|
else {
|
|
479
|
-
if (options.values || options.map) {
|
|
480
|
-
throw new Error("cannot specify values or
|
|
553
|
+
if (options.values || options.map || options.globalType) {
|
|
554
|
+
throw new Error("cannot specify values, map or globalType and foreign key for lookup table enum type");
|
|
481
555
|
}
|
|
482
556
|
if (options.createEnumType) {
|
|
483
557
|
throw new Error("cannot specify createEnumType without specifying values");
|
|
@@ -492,69 +566,136 @@ class EnumField extends BaseField {
|
|
|
492
566
|
this.values = options.values;
|
|
493
567
|
this.map = options.map;
|
|
494
568
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
569
|
+
async valid(val) {
|
|
570
|
+
if (this.type.globalType) {
|
|
571
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
572
|
+
if (f) {
|
|
573
|
+
if (f.valid) {
|
|
574
|
+
return f.valid(val);
|
|
575
|
+
}
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
500
583
|
// lookup table enum and indicated via presence of foreignKey
|
|
501
584
|
if (!this.values && !this.map) {
|
|
502
585
|
return true;
|
|
503
586
|
}
|
|
504
587
|
if (this.values) {
|
|
505
588
|
let str = String(val);
|
|
506
|
-
return this.values.some((value) => value === str
|
|
589
|
+
return this.values.some((value) => value === str);
|
|
507
590
|
}
|
|
508
591
|
for (const k in this.map) {
|
|
509
592
|
const v = this.map[k];
|
|
510
|
-
if (v === val
|
|
511
|
-
// TODO decide on behavior for GQL since GQL only supports one type
|
|
593
|
+
if (v === val) {
|
|
512
594
|
return true;
|
|
513
595
|
}
|
|
514
596
|
}
|
|
515
597
|
return false;
|
|
516
598
|
}
|
|
517
599
|
format(val) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
600
|
+
if (this.type.globalType) {
|
|
601
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
602
|
+
if (f && f.format) {
|
|
603
|
+
return f.format(val);
|
|
604
|
+
}
|
|
521
605
|
return val;
|
|
522
606
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
607
|
+
return val;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
exports.EnumField = EnumField;
|
|
611
|
+
class StringEnumField extends EnumField {
|
|
612
|
+
}
|
|
613
|
+
exports.StringEnumField = StringEnumField;
|
|
614
|
+
function EnumType(options) {
|
|
615
|
+
let result = new StringEnumField(options);
|
|
616
|
+
return Object.assign(result, options);
|
|
617
|
+
}
|
|
618
|
+
exports.EnumType = EnumType;
|
|
619
|
+
class IntegerEnumField extends BaseField {
|
|
620
|
+
constructor(options) {
|
|
621
|
+
super();
|
|
622
|
+
this.type = {
|
|
623
|
+
dbType: schema_1.DBType.IntEnum,
|
|
624
|
+
intEnumMap: options.map,
|
|
625
|
+
type: options.tsType,
|
|
626
|
+
graphQLType: options.graphQLType,
|
|
627
|
+
deprecatedIntEnumMap: options.deprecated,
|
|
628
|
+
disableUnknownType: options.disableUnknownType,
|
|
629
|
+
globalType: options.globalType,
|
|
630
|
+
};
|
|
631
|
+
if (options.foreignKey) {
|
|
632
|
+
throw new Error(`foreignKey on intEnum not supported`);
|
|
633
|
+
}
|
|
634
|
+
if (options.globalType) {
|
|
635
|
+
if (options.map) {
|
|
636
|
+
throw new Error(`cannot specify map and globalType`);
|
|
531
637
|
}
|
|
638
|
+
this.map = {};
|
|
532
639
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
640
|
+
else {
|
|
641
|
+
let count = 0;
|
|
642
|
+
for (const _ in options.map) {
|
|
643
|
+
count++;
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
if (!count) {
|
|
647
|
+
throw new Error("need at least one entry in enum map");
|
|
648
|
+
}
|
|
649
|
+
if (!options.map) {
|
|
650
|
+
throw new Error("map required if not globalType");
|
|
651
|
+
}
|
|
652
|
+
this.map = options.map;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
async valid(val) {
|
|
656
|
+
if (this.type?.globalType) {
|
|
657
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
658
|
+
if (f) {
|
|
659
|
+
if (f.valid) {
|
|
660
|
+
return f.valid(val);
|
|
541
661
|
}
|
|
662
|
+
return true;
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
666
|
+
return false;
|
|
542
667
|
}
|
|
543
668
|
}
|
|
544
|
-
//
|
|
545
|
-
|
|
669
|
+
// lookup table enum and indicated via presence of foreignKey
|
|
670
|
+
for (const k in this.map) {
|
|
671
|
+
const v = this.map[k];
|
|
672
|
+
if (v === val || v === parseInt(val)) {
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
format(val) {
|
|
679
|
+
if (this.type.globalType) {
|
|
680
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
681
|
+
if (f && f.format) {
|
|
682
|
+
return f.format(val);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return parseInt(val);
|
|
546
686
|
}
|
|
547
687
|
}
|
|
548
|
-
exports.
|
|
549
|
-
function
|
|
550
|
-
let result = new
|
|
688
|
+
exports.IntegerEnumField = IntegerEnumField;
|
|
689
|
+
function IntegerEnumType(options) {
|
|
690
|
+
let result = new IntegerEnumField(options);
|
|
551
691
|
return Object.assign(result, options);
|
|
552
692
|
}
|
|
553
|
-
exports.
|
|
693
|
+
exports.IntegerEnumType = IntegerEnumType;
|
|
554
694
|
class ListField extends BaseField {
|
|
555
695
|
constructor(field, options) {
|
|
556
696
|
super();
|
|
557
697
|
this.field = field;
|
|
698
|
+
this.options = options;
|
|
558
699
|
this.validators = [];
|
|
559
700
|
if (field.type.dbType === schema_1.DBType.List) {
|
|
560
701
|
throw new Error(`nested lists not currently supported`);
|
|
@@ -565,6 +706,9 @@ class ListField extends BaseField {
|
|
|
565
706
|
};
|
|
566
707
|
Object.assign(this, options);
|
|
567
708
|
}
|
|
709
|
+
__getElemField() {
|
|
710
|
+
return this.field;
|
|
711
|
+
}
|
|
568
712
|
validate(validator) {
|
|
569
713
|
this.validators.push(validator);
|
|
570
714
|
return this;
|
|
@@ -583,7 +727,7 @@ class ListField extends BaseField {
|
|
|
583
727
|
return true;
|
|
584
728
|
}
|
|
585
729
|
const res = valid.apply(this.field, [val[0]]);
|
|
586
|
-
if (
|
|
730
|
+
if ((0, types_1.isPromise)(res)) {
|
|
587
731
|
const ret = await Promise.all(val.map(async (v) => await valid.apply(this.field, [v])));
|
|
588
732
|
return ret.every((v) => v);
|
|
589
733
|
}
|
|
@@ -592,7 +736,12 @@ class ListField extends BaseField {
|
|
|
592
736
|
return result;
|
|
593
737
|
}
|
|
594
738
|
postgresVal(val, jsonType) {
|
|
595
|
-
if (!jsonType) {
|
|
739
|
+
if (!jsonType && val === "") {
|
|
740
|
+
// support empty strings in list
|
|
741
|
+
val = '"' + val + '"';
|
|
742
|
+
return val;
|
|
743
|
+
}
|
|
744
|
+
if (this.options?.disableJSONStringify) {
|
|
596
745
|
return val;
|
|
597
746
|
}
|
|
598
747
|
return JSON.stringify(val);
|
|
@@ -720,7 +869,18 @@ function EnumListType(options) {
|
|
|
720
869
|
return new ListField(EnumType(options), options);
|
|
721
870
|
}
|
|
722
871
|
exports.EnumListType = EnumListType;
|
|
872
|
+
function IntegerEnumListType(options) {
|
|
873
|
+
// not all of these will make sense in a list...
|
|
874
|
+
// can make it work eventually but involves work we're not currently trying to do
|
|
875
|
+
// developer can try to work around it by calling below on their own.
|
|
876
|
+
// unclear what the behavior is
|
|
877
|
+
return new ListField(IntegerEnumType(options), options);
|
|
878
|
+
}
|
|
879
|
+
exports.IntegerEnumListType = IntegerEnumListType;
|
|
723
880
|
function UUIDListType(options) {
|
|
724
|
-
return new ListField(UUIDType(options),
|
|
881
|
+
return new ListField(UUIDType(options), {
|
|
882
|
+
...options,
|
|
883
|
+
disableJSONStringify: true,
|
|
884
|
+
});
|
|
725
885
|
}
|
|
726
886
|
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, getFieldsWithEditPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, EdgeUpdateOperation, TransformedEdgeUpdateOperation, getTransformedReadClause, getObjectLoaderProperties, GlobalSchema, ActionField, } from "./schema";
|
|
4
|
+
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];
|
|
@@ -10,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
17
|
+
exports.EntSchemaWithTZ = exports.EntSchema = exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.SQLStatementOperation = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getStorageKey = exports.getFieldsWithEditPrivacy = exports.getFieldsWithPrivacy = exports.getFields = exports.DBType = void 0;
|
|
14
18
|
var schema_1 = require("./schema");
|
|
15
19
|
Object.defineProperty(exports, "DBType", { enumerable: true, get: function () { return schema_1.DBType; } });
|
|
16
20
|
Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return schema_1.getFields; } });
|
|
17
21
|
Object.defineProperty(exports, "getFieldsWithPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithPrivacy; } });
|
|
22
|
+
Object.defineProperty(exports, "getFieldsWithEditPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithEditPrivacy; } });
|
|
18
23
|
Object.defineProperty(exports, "getStorageKey", { enumerable: true, get: function () { return schema_1.getStorageKey; } });
|
|
19
24
|
Object.defineProperty(exports, "ActionOperation", { enumerable: true, get: function () { return schema_1.ActionOperation; } });
|
|
20
25
|
Object.defineProperty(exports, "NoFields", { enumerable: true, get: function () { return schema_1.NoFields; } });
|
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;
|