@snowtop/ent 0.0.33 → 0.1.0-alpha2
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 +15 -14
- package/action/experimental_action.d.ts +20 -20
- package/action/experimental_action.js +1 -1
- package/action/orchestrator.d.ts +9 -9
- package/action/orchestrator.js +11 -11
- package/core/base.d.ts +12 -6
- package/core/ent.d.ts +2 -1
- package/core/ent.js +13 -8
- package/core/query/assoc_query.js +2 -2
- package/core/query/query.d.ts +1 -1
- package/imports/index.d.ts +0 -1
- package/imports/index.js +3 -36
- package/package.json +1 -1
- package/parse_schema/parse.d.ts +11 -2
- package/parse_schema/parse.js +52 -22
- package/schema/base_schema.js +15 -15
- package/schema/field.d.ts +24 -24
- package/schema/field.js +38 -40
- package/schema/index.d.ts +1 -1
- package/schema/json_field.d.ts +6 -6
- package/schema/json_field.js +2 -2
- package/schema/schema.d.ts +11 -7
- package/schema/schema.js +18 -5
- package/scripts/custom_compiler.js +2 -19
- package/scripts/transform_schema.d.ts +1 -0
- package/scripts/transform_schema.js +288 -0
- package/testutils/builder.d.ts +14 -13
- package/testutils/builder.js +2 -0
- package/testutils/db/test_db.js +9 -9
- package/testutils/fake_data/fake_contact.d.ts +2 -2
- package/testutils/fake_data/fake_contact.js +6 -13
- package/testutils/fake_data/fake_event.d.ts +2 -2
- package/testutils/fake_data/fake_event.js +8 -16
- package/testutils/fake_data/fake_user.d.ts +2 -2
- package/testutils/fake_data/fake_user.js +7 -16
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/tsc/compilerOptions.d.ts +2 -0
- package/tsc/compilerOptions.js +61 -0
package/schema/base_schema.js
CHANGED
|
@@ -3,17 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const field_1 = require("./field");
|
|
6
|
-
let tsFields =
|
|
7
|
-
(0, field_1.TimestampType)({
|
|
8
|
-
name: "createdAt",
|
|
6
|
+
let tsFields = {
|
|
7
|
+
createdAt: (0, field_1.TimestampType)({
|
|
9
8
|
hideFromGraphQL: true,
|
|
10
9
|
disableUserEditable: true,
|
|
11
10
|
defaultValueOnCreate: () => {
|
|
12
11
|
return new Date();
|
|
13
12
|
},
|
|
14
13
|
}),
|
|
15
|
-
(0, field_1.TimestampType)({
|
|
16
|
-
name: "updatedAt",
|
|
14
|
+
updatedAt: (0, field_1.TimestampType)({
|
|
17
15
|
hideFromGraphQL: true,
|
|
18
16
|
disableUserEditable: true,
|
|
19
17
|
defaultValueOnCreate: () => {
|
|
@@ -23,25 +21,28 @@ let tsFields = [
|
|
|
23
21
|
return new Date();
|
|
24
22
|
},
|
|
25
23
|
}),
|
|
26
|
-
|
|
24
|
+
};
|
|
27
25
|
// Timestamps is a Pattern that adds a createdAt and updatedAt timestamp fields to the ent
|
|
28
26
|
exports.Timestamps = {
|
|
29
27
|
name: "timestamps",
|
|
30
28
|
fields: tsFields,
|
|
31
29
|
};
|
|
32
30
|
let nodeField = (0, field_1.UUIDType)({
|
|
33
|
-
name: "ID",
|
|
34
31
|
primaryKey: true,
|
|
35
32
|
disableUserEditable: true,
|
|
36
33
|
defaultValueOnCreate: () => {
|
|
37
34
|
return (0, uuid_1.v4)();
|
|
38
35
|
},
|
|
39
36
|
});
|
|
40
|
-
let nodeFields =
|
|
41
|
-
|
|
42
|
-
nodeField,
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
let nodeFields = {
|
|
38
|
+
// inconsistent naming :(
|
|
39
|
+
ID: nodeField,
|
|
40
|
+
...tsFields,
|
|
41
|
+
};
|
|
42
|
+
let nodeFieldsWithTZ = {
|
|
43
|
+
// inconsistent naming :(
|
|
44
|
+
ID: nodeField,
|
|
45
|
+
createdAt: (0, field_1.TimestampType)({
|
|
45
46
|
hideFromGraphQL: true,
|
|
46
47
|
disableUserEditable: true,
|
|
47
48
|
defaultValueOnCreate: () => {
|
|
@@ -49,8 +50,7 @@ let nodeFieldsWithTZ = [
|
|
|
49
50
|
},
|
|
50
51
|
withTimezone: true,
|
|
51
52
|
}),
|
|
52
|
-
(0, field_1.TimestampType)({
|
|
53
|
-
name: "updatedAt",
|
|
53
|
+
updatedAt: (0, field_1.TimestampType)({
|
|
54
54
|
hideFromGraphQL: true,
|
|
55
55
|
disableUserEditable: true,
|
|
56
56
|
defaultValueOnCreate: () => {
|
|
@@ -61,7 +61,7 @@ let nodeFieldsWithTZ = [
|
|
|
61
61
|
},
|
|
62
62
|
withTimezone: true,
|
|
63
63
|
}),
|
|
64
|
-
|
|
64
|
+
};
|
|
65
65
|
// Node is a Pattern that adds 3 fields to the ent: (id, createdAt, and updatedAt timestamps)
|
|
66
66
|
exports.Node = {
|
|
67
67
|
name: "node",
|
package/schema/field.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Field, FieldOptions, ForeignKey, PolymorphicOptions, Type } from "./schema";
|
|
1
|
+
import { Field, FieldMap, FieldOptions, ForeignKey, PolymorphicOptions, Type } from "./schema";
|
|
2
2
|
export declare abstract class BaseField {
|
|
3
3
|
name: string;
|
|
4
4
|
nullable?: boolean;
|
|
@@ -12,18 +12,18 @@ export declare abstract class BaseField {
|
|
|
12
12
|
index?: boolean;
|
|
13
13
|
foreignKey?: ForeignKey;
|
|
14
14
|
polymorphic?: boolean | PolymorphicOptions;
|
|
15
|
-
derivedFields?: Field[];
|
|
16
15
|
derivedWhenEmbedded?: boolean;
|
|
17
16
|
logValue(val: any): any;
|
|
18
17
|
}
|
|
19
18
|
export declare class UUIDField extends BaseField implements Field {
|
|
20
|
-
private options
|
|
19
|
+
private options?;
|
|
21
20
|
type: Type;
|
|
22
|
-
constructor(options
|
|
21
|
+
constructor(options?: FieldOptions | undefined);
|
|
22
|
+
getDerivedFields(fieldName: string): FieldMap;
|
|
23
23
|
private isBuilder;
|
|
24
24
|
valid(val: any): Promise<boolean>;
|
|
25
25
|
}
|
|
26
|
-
export declare function UUIDType(options
|
|
26
|
+
export declare function UUIDType(options?: FieldOptions): UUIDField;
|
|
27
27
|
export interface IntegerOptions extends FieldOptions {
|
|
28
28
|
min?: number;
|
|
29
29
|
max?: number;
|
|
@@ -40,7 +40,7 @@ export declare class IntegerField extends BaseField implements Field {
|
|
|
40
40
|
valid(val: any): boolean;
|
|
41
41
|
validate(validator: (str: number) => boolean): this;
|
|
42
42
|
}
|
|
43
|
-
export declare function IntegerType(options
|
|
43
|
+
export declare function IntegerType(options?: IntegerOptions): IntegerField;
|
|
44
44
|
export declare class BigIntegerField extends BaseField implements Field {
|
|
45
45
|
type: Type;
|
|
46
46
|
}
|
|
@@ -48,11 +48,11 @@ export declare function BigIntegerType(options: FieldOptions): BigIntegerField;
|
|
|
48
48
|
export declare class FloatField extends BaseField implements Field {
|
|
49
49
|
type: Type;
|
|
50
50
|
}
|
|
51
|
-
export declare function FloatType(options
|
|
51
|
+
export declare function FloatType(options?: FieldOptions): FloatField;
|
|
52
52
|
export declare class BooleanField extends BaseField implements Field {
|
|
53
53
|
type: Type;
|
|
54
54
|
}
|
|
55
|
-
export declare function BooleanType(options
|
|
55
|
+
export declare function BooleanType(options?: FieldOptions): BooleanField;
|
|
56
56
|
export interface StringOptions extends FieldOptions {
|
|
57
57
|
minLen?: number;
|
|
58
58
|
maxLen?: number;
|
|
@@ -88,7 +88,7 @@ export declare class StringField extends BaseField implements Field {
|
|
|
88
88
|
trimLeft(): this;
|
|
89
89
|
trimRight(): this;
|
|
90
90
|
}
|
|
91
|
-
export declare function StringType(options
|
|
91
|
+
export declare function StringType(options?: StringOptions): StringField;
|
|
92
92
|
export interface TimestampOptions extends FieldOptions {
|
|
93
93
|
withTimezone?: boolean;
|
|
94
94
|
}
|
|
@@ -98,8 +98,8 @@ export declare class TimestampField extends BaseField implements Field {
|
|
|
98
98
|
constructor(options: TimestampOptions);
|
|
99
99
|
format(val: Date): any;
|
|
100
100
|
}
|
|
101
|
-
export declare function TimestampType(options
|
|
102
|
-
export declare function TimestamptzType(options
|
|
101
|
+
export declare function TimestampType(options?: TimestampOptions): TimestampField;
|
|
102
|
+
export declare function TimestamptzType(options?: FieldOptions): TimestampField;
|
|
103
103
|
export interface TimeOptions extends FieldOptions {
|
|
104
104
|
withTimezone?: boolean;
|
|
105
105
|
precision?: number;
|
|
@@ -108,16 +108,16 @@ export declare const leftPad: (val: number) => string;
|
|
|
108
108
|
export declare class TimeField extends BaseField implements Field {
|
|
109
109
|
type: Type;
|
|
110
110
|
withTimezone?: boolean;
|
|
111
|
-
constructor(options
|
|
111
|
+
constructor(options?: TimeOptions);
|
|
112
112
|
format(val: any): any;
|
|
113
113
|
}
|
|
114
|
-
export declare function TimeType(options
|
|
115
|
-
export declare function TimetzType(options
|
|
114
|
+
export declare function TimeType(options?: TimeOptions): TimeField;
|
|
115
|
+
export declare function TimetzType(options?: FieldOptions): TimeField;
|
|
116
116
|
export declare class DateField extends BaseField implements Field {
|
|
117
117
|
type: Type;
|
|
118
118
|
format(val: any): any;
|
|
119
119
|
}
|
|
120
|
-
export declare function DateType(options
|
|
120
|
+
export declare function DateType(options?: FieldOptions): DateField;
|
|
121
121
|
declare type EnumMap = {
|
|
122
122
|
[key: string]: string;
|
|
123
123
|
};
|
|
@@ -142,7 +142,7 @@ export declare class ListField extends BaseField {
|
|
|
142
142
|
private field;
|
|
143
143
|
type: Type;
|
|
144
144
|
private validators;
|
|
145
|
-
constructor(field: Field, options
|
|
145
|
+
constructor(field: Field, options?: FieldOptions);
|
|
146
146
|
validate(validator: (val: any[]) => boolean): this;
|
|
147
147
|
valid(val: any): Promise<boolean>;
|
|
148
148
|
private postgresVal;
|
|
@@ -152,17 +152,17 @@ export declare class ListField extends BaseField {
|
|
|
152
152
|
length(l: number): this;
|
|
153
153
|
range(start: any, stop: any): this;
|
|
154
154
|
}
|
|
155
|
-
export declare function StringListType(options
|
|
155
|
+
export declare function StringListType(options?: StringOptions): ListField;
|
|
156
156
|
export declare function IntListType(options: FieldOptions): ListField;
|
|
157
|
-
export declare function IntegerListType(options
|
|
158
|
-
export declare function FloatListType(options
|
|
157
|
+
export declare function IntegerListType(options?: FieldOptions): ListField;
|
|
158
|
+
export declare function FloatListType(options?: FieldOptions): ListField;
|
|
159
159
|
export declare function BigIntegerListType(options: FieldOptions): ListField;
|
|
160
|
-
export declare function BooleanListType(options
|
|
160
|
+
export declare function BooleanListType(options?: FieldOptions): ListField;
|
|
161
161
|
export declare function TimestampListType(options: TimestampOptions): ListField;
|
|
162
|
-
export declare function TimestamptzListType(options
|
|
163
|
-
export declare function TimeListType(options
|
|
162
|
+
export declare function TimestamptzListType(options?: TimestampOptions): ListField;
|
|
163
|
+
export declare function TimeListType(options?: TimeOptions): ListField;
|
|
164
164
|
export declare function TimetzListType(options: TimeOptions): ListField;
|
|
165
|
-
export declare function DateListType(options
|
|
165
|
+
export declare function DateListType(options?: FieldOptions): ListField;
|
|
166
166
|
export declare function EnumListType(options: EnumOptions): ListField;
|
|
167
|
-
export declare function UUIDListType(options
|
|
167
|
+
export declare function UUIDListType(options?: FieldOptions): ListField;
|
|
168
168
|
export {};
|
package/schema/field.js
CHANGED
|
@@ -22,7 +22,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
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;
|
|
23
23
|
const luxon_1 = require("luxon");
|
|
24
24
|
const snake_case_1 = require("snake-case");
|
|
25
|
-
const camel_case_1 = require("camel-case");
|
|
26
25
|
const db_1 = __importStar(require("../core/db"));
|
|
27
26
|
const schema_1 = require("./schema");
|
|
28
27
|
const util_1 = require("util");
|
|
@@ -41,19 +40,25 @@ class UUIDField extends BaseField {
|
|
|
41
40
|
super();
|
|
42
41
|
this.options = options;
|
|
43
42
|
this.type = { dbType: schema_1.DBType.UUID };
|
|
44
|
-
|
|
43
|
+
if (options?.fieldEdge?.enforceSchema &&
|
|
44
|
+
!options.fieldEdge.getLoaderInfoFromSchema) {
|
|
45
|
+
throw new Error(`cannot enforceSchema if getLoaderInfoFromSchema wasn't passed in`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
getDerivedFields(fieldName) {
|
|
49
|
+
const polymorphic = this.options?.polymorphic;
|
|
45
50
|
if (polymorphic) {
|
|
46
51
|
let name = "";
|
|
47
|
-
if (
|
|
48
|
-
let idx =
|
|
49
|
-
name =
|
|
52
|
+
if (fieldName.endsWith("_id")) {
|
|
53
|
+
let idx = fieldName.indexOf("_id");
|
|
54
|
+
name = fieldName.substring(0, idx) + "_type";
|
|
50
55
|
}
|
|
51
|
-
else if (
|
|
52
|
-
let idx =
|
|
53
|
-
name =
|
|
56
|
+
else if (fieldName.endsWith("ID")) {
|
|
57
|
+
let idx = fieldName.indexOf("ID");
|
|
58
|
+
name = fieldName.substring(0, idx) + "Type";
|
|
54
59
|
}
|
|
55
60
|
else {
|
|
56
|
-
throw new Error(`unsupported id polymorhpic type ${
|
|
61
|
+
throw new Error(`unsupported id polymorhpic type ${fieldName}`);
|
|
57
62
|
}
|
|
58
63
|
// polymorphic field automatically hidden from GraphQL
|
|
59
64
|
// can be made visible with custom fields if user wants to change this behavior
|
|
@@ -61,53 +66,46 @@ class UUIDField extends BaseField {
|
|
|
61
66
|
// intentionally not made private as it doesn't seem like it needs to be hidden
|
|
62
67
|
if (typeof polymorphic === "object" && polymorphic.types) {
|
|
63
68
|
// an enum with types validated here
|
|
64
|
-
|
|
65
|
-
EnumType({
|
|
66
|
-
name,
|
|
69
|
+
return {
|
|
70
|
+
[name]: EnumType({
|
|
67
71
|
values: polymorphic.types,
|
|
68
72
|
hideFromGraphQL: true,
|
|
69
73
|
derivedWhenEmbedded: true,
|
|
70
|
-
nullable: options
|
|
74
|
+
nullable: this.options?.nullable,
|
|
71
75
|
}),
|
|
72
|
-
|
|
76
|
+
};
|
|
73
77
|
}
|
|
74
78
|
else {
|
|
75
79
|
// just a string field...
|
|
76
|
-
|
|
77
|
-
StringType({
|
|
78
|
-
name,
|
|
80
|
+
return {
|
|
81
|
+
[name]: StringType({
|
|
79
82
|
hideFromGraphQL: true,
|
|
80
83
|
derivedWhenEmbedded: true,
|
|
81
|
-
nullable: options
|
|
84
|
+
nullable: this.options?.nullable,
|
|
82
85
|
}),
|
|
83
|
-
|
|
86
|
+
};
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
|
-
|
|
87
|
-
!options.fieldEdge.getLoaderOptions) {
|
|
88
|
-
throw new Error(`cannot enforceSchema if getLoaderOptions wasn't passed in`);
|
|
89
|
-
}
|
|
89
|
+
return {};
|
|
90
90
|
}
|
|
91
91
|
isBuilder(val) {
|
|
92
92
|
return val.placeholderID !== undefined;
|
|
93
93
|
}
|
|
94
94
|
async valid(val) {
|
|
95
|
-
if (!this.options
|
|
95
|
+
if (!this.options?.fieldEdge?.enforceSchema) {
|
|
96
96
|
return true;
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (!loadRowOptions) {
|
|
103
|
-
throw new Error(`couldn't get loaderOptions for ${f}`);
|
|
98
|
+
const getLoaderInfo = this.options.fieldEdge.getLoaderInfoFromSchema;
|
|
99
|
+
const loaderInfo = getLoaderInfo(this.options.fieldEdge.schema);
|
|
100
|
+
if (!loaderInfo) {
|
|
101
|
+
throw new Error(`couldn't get loaderInfo for ${this.options.fieldEdge.schema}`);
|
|
104
102
|
}
|
|
105
103
|
if (this.isBuilder(val)) {
|
|
106
|
-
// if builder, the
|
|
107
|
-
return val.
|
|
104
|
+
// if builder, the nodeType of the builder and the nodeType of the loaderInfo should match
|
|
105
|
+
return val.nodeType === loaderInfo.nodeType;
|
|
108
106
|
}
|
|
109
107
|
// TODO we need context here to make sure that we hit local cache
|
|
110
|
-
const row = await
|
|
108
|
+
const row = await loaderInfo.loaderFactory.createLoader().load(val);
|
|
111
109
|
return row !== null;
|
|
112
110
|
}
|
|
113
111
|
}
|
|
@@ -122,7 +120,7 @@ class IntegerField extends BaseField {
|
|
|
122
120
|
super();
|
|
123
121
|
this.type = { dbType: schema_1.DBType.Int };
|
|
124
122
|
this.validators = [];
|
|
125
|
-
this.options = {
|
|
123
|
+
this.options = {};
|
|
126
124
|
// for legacy callers
|
|
127
125
|
this.handleOptions(options || this.options);
|
|
128
126
|
}
|
|
@@ -209,9 +207,9 @@ class StringField extends BaseField {
|
|
|
209
207
|
this.type = { dbType: schema_1.DBType.String };
|
|
210
208
|
this.validators = [];
|
|
211
209
|
this.formatters = [];
|
|
212
|
-
this.options = {
|
|
210
|
+
this.options = {};
|
|
213
211
|
// for legacy callers
|
|
214
|
-
this.handleOptions(options || {
|
|
212
|
+
this.handleOptions(options || {});
|
|
215
213
|
}
|
|
216
214
|
getOptions() {
|
|
217
215
|
return this.options;
|
|
@@ -350,7 +348,7 @@ class TimestampField extends BaseField {
|
|
|
350
348
|
}
|
|
351
349
|
exports.TimestampField = TimestampField;
|
|
352
350
|
function TimestampType(options) {
|
|
353
|
-
let result = new TimestampField(options);
|
|
351
|
+
let result = new TimestampField({ ...options });
|
|
354
352
|
return Object.assign(result, options);
|
|
355
353
|
}
|
|
356
354
|
exports.TimestampType = TimestampType;
|
|
@@ -377,7 +375,7 @@ class TimeField extends BaseField {
|
|
|
377
375
|
constructor(options) {
|
|
378
376
|
super();
|
|
379
377
|
this.type = { dbType: schema_1.DBType.Time };
|
|
380
|
-
if (options
|
|
378
|
+
if (options?.withTimezone) {
|
|
381
379
|
this.type = {
|
|
382
380
|
dbType: schema_1.DBType.Timetz,
|
|
383
381
|
};
|
|
@@ -454,8 +452,8 @@ class EnumField extends BaseField {
|
|
|
454
452
|
dbType: options.createEnumType ? schema_1.DBType.Enum : schema_1.DBType.StringEnum,
|
|
455
453
|
values: options.values,
|
|
456
454
|
enumMap: options.map,
|
|
457
|
-
type: options.tsType
|
|
458
|
-
graphQLType: options.graphQLType
|
|
455
|
+
type: options.tsType,
|
|
456
|
+
graphQLType: options.graphQLType,
|
|
459
457
|
};
|
|
460
458
|
if (!options.foreignKey) {
|
|
461
459
|
if (!options.values && !options.map) {
|
package/schema/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Schema from "./schema";
|
|
2
2
|
export { Schema };
|
|
3
|
-
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, } from "./schema";
|
|
3
|
+
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, } from "./schema";
|
|
4
4
|
export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, } from "./base_schema";
|
|
5
5
|
export * from "./field";
|
|
6
6
|
export * from "./json_field";
|
package/schema/json_field.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ export interface JSONOptions extends FieldOptions {
|
|
|
5
5
|
importType?: ImportType;
|
|
6
6
|
}
|
|
7
7
|
export declare class JSONField extends BaseField implements Field {
|
|
8
|
-
private options
|
|
8
|
+
private options?;
|
|
9
9
|
type: Type;
|
|
10
|
-
constructor(jsonb: boolean, options
|
|
10
|
+
constructor(jsonb: boolean, options?: JSONOptions | undefined);
|
|
11
11
|
format(val: any): string;
|
|
12
12
|
valid(val: any): boolean;
|
|
13
13
|
}
|
|
14
|
-
export declare function JSONType(options
|
|
15
|
-
export declare function JSONBType(options
|
|
16
|
-
export declare function JSONBListType(options
|
|
17
|
-
export declare function JSONListType(options
|
|
14
|
+
export declare function JSONType(options?: JSONOptions): JSONField;
|
|
15
|
+
export declare function JSONBType(options?: JSONOptions): JSONField;
|
|
16
|
+
export declare function JSONBListType(options?: JSONOptions): ListField;
|
|
17
|
+
export declare function JSONListType(options?: JSONOptions): ListField;
|
package/schema/json_field.js
CHANGED
|
@@ -13,7 +13,7 @@ class JSONField extends field_1.BaseField {
|
|
|
13
13
|
if (jsonb) {
|
|
14
14
|
this.type.dbType = schema_1.DBType.JSONB;
|
|
15
15
|
}
|
|
16
|
-
if (options
|
|
16
|
+
if (options?.importType) {
|
|
17
17
|
this.type.importType = options.importType;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -21,7 +21,7 @@ class JSONField extends field_1.BaseField {
|
|
|
21
21
|
return JSON.stringify(val);
|
|
22
22
|
}
|
|
23
23
|
valid(val) {
|
|
24
|
-
if (this.options
|
|
24
|
+
if (this.options?.validator) {
|
|
25
25
|
return this.options.validator(val);
|
|
26
26
|
}
|
|
27
27
|
return true;
|
package/schema/schema.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { Data, Ent,
|
|
1
|
+
import { Data, Ent, LoaderInfo } from "../core/base";
|
|
2
2
|
import { Builder } from "../action/action";
|
|
3
|
+
export declare type FieldMap = {
|
|
4
|
+
[key: string]: Field;
|
|
5
|
+
};
|
|
3
6
|
export default interface Schema {
|
|
4
|
-
fields: Field[];
|
|
7
|
+
fields: FieldMap | Field[];
|
|
5
8
|
tableName?: string;
|
|
6
9
|
patterns?: Pattern[];
|
|
7
10
|
edges?: Edge[];
|
|
@@ -57,7 +60,7 @@ export interface AssocEdgeGroup {
|
|
|
57
60
|
export declare type Edge = AssocEdge;
|
|
58
61
|
export interface Pattern {
|
|
59
62
|
name: string;
|
|
60
|
-
fields: Field[];
|
|
63
|
+
fields: FieldMap | Field[];
|
|
61
64
|
edges?: Edge[];
|
|
62
65
|
}
|
|
63
66
|
export declare enum DBType {
|
|
@@ -102,7 +105,7 @@ export interface ForeignKey {
|
|
|
102
105
|
disableIndex?: boolean;
|
|
103
106
|
disableBuilderType?: boolean;
|
|
104
107
|
}
|
|
105
|
-
declare type
|
|
108
|
+
declare type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
106
109
|
export interface InverseFieldEdge {
|
|
107
110
|
name: string;
|
|
108
111
|
edgeConstName?: string;
|
|
@@ -113,11 +116,10 @@ export interface FieldEdge {
|
|
|
113
116
|
schema: string;
|
|
114
117
|
inverseEdge?: string | InverseFieldEdge;
|
|
115
118
|
enforceSchema?: boolean;
|
|
116
|
-
|
|
119
|
+
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
117
120
|
disableBuilderType?: boolean;
|
|
118
121
|
}
|
|
119
122
|
export interface FieldOptions {
|
|
120
|
-
name: string;
|
|
121
123
|
nullable?: boolean;
|
|
122
124
|
storageKey?: string;
|
|
123
125
|
serverDefault?: any;
|
|
@@ -136,7 +138,8 @@ export interface FieldOptions {
|
|
|
136
138
|
defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
|
|
137
139
|
derivedWhenEmbedded?: boolean;
|
|
138
140
|
polymorphic?: boolean | PolymorphicOptions;
|
|
139
|
-
|
|
141
|
+
getDerivedFields?(name: string): FieldMap;
|
|
142
|
+
[x: string]: any;
|
|
140
143
|
}
|
|
141
144
|
export interface PolymorphicOptions {
|
|
142
145
|
types?: string[];
|
|
@@ -171,6 +174,7 @@ export interface ActionField {
|
|
|
171
174
|
nullable?: boolean | NullableListOptions;
|
|
172
175
|
list?: boolean;
|
|
173
176
|
actionName?: string;
|
|
177
|
+
excludedFields?: string[];
|
|
174
178
|
}
|
|
175
179
|
export interface Action {
|
|
176
180
|
operation: ActionOperation;
|
package/schema/schema.js
CHANGED
|
@@ -37,12 +37,25 @@ function getFields(value) {
|
|
|
37
37
|
schema = new value();
|
|
38
38
|
}
|
|
39
39
|
function addFields(fields) {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
if (Array.isArray(fields)) {
|
|
41
|
+
for (const field of fields) {
|
|
42
|
+
const name = field.name;
|
|
43
|
+
if (!name) {
|
|
44
|
+
throw new Error(`name required`);
|
|
45
|
+
}
|
|
46
|
+
if (field.getDerivedFields !== undefined) {
|
|
47
|
+
addFields(field.getDerivedFields(name));
|
|
48
|
+
}
|
|
49
|
+
m.set(name, field);
|
|
44
50
|
}
|
|
45
|
-
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
for (const name in fields) {
|
|
54
|
+
const field = fields[name];
|
|
55
|
+
if (field.getDerivedFields !== undefined) {
|
|
56
|
+
addFields(field.getDerivedFields(name));
|
|
57
|
+
}
|
|
58
|
+
m.set(name, field);
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
let m = new Map();
|
|
@@ -25,9 +25,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const typescript_1 = __importDefault(require("typescript"));
|
|
27
27
|
const path = __importStar(require("path"));
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
|
-
const json5_1 = __importDefault(require("json5"));
|
|
30
28
|
const glob_1 = __importDefault(require("glob"));
|
|
29
|
+
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
31
30
|
// TODO this should probably be its own package but for now it's here
|
|
32
31
|
class Compiler {
|
|
33
32
|
constructor(sourceFiles, moduleSearchLocations) {
|
|
@@ -35,7 +34,7 @@ class Compiler {
|
|
|
35
34
|
this.moduleSearchLocations = moduleSearchLocations;
|
|
36
35
|
this.regexMap = new Map();
|
|
37
36
|
this.resolvers = [];
|
|
38
|
-
this.options =
|
|
37
|
+
this.options = (0, compilerOptions_1.readCompilerOptions)(".");
|
|
39
38
|
if (this.options.paths) {
|
|
40
39
|
for (let key in this.options.paths) {
|
|
41
40
|
if (key === "*") {
|
|
@@ -105,22 +104,6 @@ class Compiler {
|
|
|
105
104
|
}
|
|
106
105
|
return undefined;
|
|
107
106
|
}
|
|
108
|
-
readCompilerOptions() {
|
|
109
|
-
let json = {};
|
|
110
|
-
try {
|
|
111
|
-
json = json5_1.default.parse(fs.readFileSync("./tsconfig.json", {
|
|
112
|
-
encoding: "utf8",
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
console.error("couldn't read tsconfig.json file");
|
|
117
|
-
}
|
|
118
|
-
let options = json["compilerOptions"] || {};
|
|
119
|
-
if (options.moduleResolution === "node") {
|
|
120
|
-
options.moduleResolution = typescript_1.default.ModuleResolutionKind.NodeJs;
|
|
121
|
-
}
|
|
122
|
-
return options;
|
|
123
|
-
}
|
|
124
107
|
createCompilerHost() {
|
|
125
108
|
return {
|
|
126
109
|
getSourceFile: this.getSourceFile,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|