@snowtop/ent 0.1.0-alpha8 → 0.1.0-alpha80
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 +27 -25
- package/action/executor.d.ts +3 -3
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +37 -16
- package/action/orchestrator.js +184 -54
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +38 -22
- package/core/clause.d.ts +65 -7
- package/core/clause.js +261 -54
- package/core/config.d.ts +8 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +1 -2
- package/core/db.js +1 -1
- package/core/ent.d.ts +76 -24
- package/core/ent.js +459 -143
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +4 -3
- package/core/loaders/object_loader.js +22 -5
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.js +8 -2
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +10 -5
- package/index.js +13 -6
- package/package.json +2 -2
- package/parse_schema/parse.d.ts +14 -2
- package/parse_schema/parse.js +40 -2
- package/schema/base_schema.d.ts +1 -1
- package/schema/base_schema.js +3 -0
- package/schema/field.d.ts +36 -7
- package/schema/field.js +70 -2
- package/schema/index.d.ts +2 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +61 -10
- package/schema/schema.js +18 -4
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +5 -1
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +82 -29
- 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} +15 -3
- package/testutils/db/{test_db.js → temp_db.js} +63 -15
- package/testutils/db/value.d.ts +6 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.js +19 -12
- package/testutils/fake_data/fake_contact.d.ts +3 -3
- package/testutils/fake_data/fake_contact.js +9 -6
- package/testutils/fake_data/fake_event.d.ts +3 -3
- package/testutils/fake_data/fake_event.js +8 -5
- package/testutils/fake_data/fake_user.d.ts +4 -4
- package/testutils/fake_data/fake_user.js +16 -13
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +5 -5
- package/testutils/fake_data/user_query.d.ts +2 -2
- 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 +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +29 -7
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -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/tsc/transform_schema.js +379 -0
- package/scripts/transform_schema.js +0 -437
package/schema/base_schema.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class EntSchema implements Schema {
|
|
|
20
20
|
hideFromGraphQL?: boolean;
|
|
21
21
|
constructor(cfg: SchemaConfig);
|
|
22
22
|
}
|
|
23
|
-
export declare class EntSchemaWithTZ {
|
|
23
|
+
export declare class EntSchemaWithTZ implements Schema {
|
|
24
24
|
fields: FieldMap | Field[];
|
|
25
25
|
tableName: string | undefined;
|
|
26
26
|
patterns: Pattern[];
|
package/schema/base_schema.js
CHANGED
|
@@ -66,6 +66,7 @@ let nodeFieldsWithTZ = {
|
|
|
66
66
|
exports.Node = {
|
|
67
67
|
name: "node",
|
|
68
68
|
fields: nodeFields,
|
|
69
|
+
disableMixin: true,
|
|
69
70
|
};
|
|
70
71
|
// Ent schema. has Node Pattern by default.
|
|
71
72
|
// exists just to have less typing and easier for clients to implement
|
|
@@ -95,6 +96,7 @@ class EntSchemaWithTZ {
|
|
|
95
96
|
// default schema added
|
|
96
97
|
name: "nodeWithTZ",
|
|
97
98
|
fields: nodeFieldsWithTZ,
|
|
99
|
+
disableMixin: true,
|
|
98
100
|
},
|
|
99
101
|
];
|
|
100
102
|
this.fields = cfg.fields;
|
|
@@ -131,6 +133,7 @@ class BaseEntSchemaWithTZ {
|
|
|
131
133
|
// default schema added
|
|
132
134
|
name: "nodeWithTZ",
|
|
133
135
|
fields: nodeFieldsWithTZ,
|
|
136
|
+
disableMixin: true,
|
|
134
137
|
},
|
|
135
138
|
];
|
|
136
139
|
}
|
package/schema/field.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare function IntegerType(options?: IntegerOptions): IntegerField;
|
|
|
44
44
|
export declare class BigIntegerField extends BaseField implements Field {
|
|
45
45
|
type: Type;
|
|
46
46
|
}
|
|
47
|
-
export declare function BigIntegerType(options
|
|
47
|
+
export declare function BigIntegerType(options?: FieldOptions): BigIntegerField;
|
|
48
48
|
export declare class FloatField extends BaseField implements Field {
|
|
49
49
|
type: Type;
|
|
50
50
|
}
|
|
@@ -118,31 +118,59 @@ export declare class DateField extends BaseField implements Field {
|
|
|
118
118
|
format(val: any): any;
|
|
119
119
|
}
|
|
120
120
|
export declare function DateType(options?: FieldOptions): DateField;
|
|
121
|
-
declare type
|
|
121
|
+
declare type StringEnumMap = {
|
|
122
122
|
[key: string]: string;
|
|
123
123
|
};
|
|
124
|
+
/**
|
|
125
|
+
* @deprecated use StringEnumOptions
|
|
126
|
+
*/
|
|
124
127
|
export interface EnumOptions extends FieldOptions {
|
|
125
128
|
values?: string[];
|
|
126
|
-
map?:
|
|
129
|
+
map?: StringEnumMap;
|
|
127
130
|
tsType?: string;
|
|
128
131
|
graphQLType?: string;
|
|
129
132
|
createEnumType?: boolean;
|
|
130
133
|
}
|
|
134
|
+
export interface StringEnumOptions extends EnumOptions {
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated Use StringEnumField
|
|
138
|
+
*/
|
|
131
139
|
export declare class EnumField extends BaseField implements Field {
|
|
132
140
|
type: Type;
|
|
133
141
|
private values?;
|
|
134
142
|
private map?;
|
|
135
|
-
constructor(options:
|
|
143
|
+
constructor(options: StringEnumOptions);
|
|
136
144
|
convertForGQL(value: string): string;
|
|
137
145
|
valid(val: any): boolean;
|
|
138
146
|
format(val: any): any;
|
|
139
147
|
}
|
|
140
|
-
export declare
|
|
148
|
+
export declare class StringEnumField extends EnumField {
|
|
149
|
+
}
|
|
150
|
+
export declare function EnumType(options: StringEnumOptions): EnumField;
|
|
151
|
+
declare type IntEnumMap = {
|
|
152
|
+
[key: string]: number;
|
|
153
|
+
};
|
|
154
|
+
export interface IntegerEnumOptions extends FieldOptions {
|
|
155
|
+
map: IntEnumMap;
|
|
156
|
+
deprecated?: IntEnumMap;
|
|
157
|
+
tsType?: string;
|
|
158
|
+
graphQLType?: string;
|
|
159
|
+
}
|
|
160
|
+
export declare class IntegerEnumField extends BaseField implements Field {
|
|
161
|
+
type: Type;
|
|
162
|
+
private map;
|
|
163
|
+
constructor(options: IntegerEnumOptions);
|
|
164
|
+
valid(val: any): boolean;
|
|
165
|
+
format(val: any): any;
|
|
166
|
+
}
|
|
167
|
+
export declare function IntegerEnumType(options: IntegerEnumOptions): IntegerEnumField;
|
|
141
168
|
export declare class ListField extends BaseField {
|
|
142
169
|
private field;
|
|
143
170
|
type: Type;
|
|
144
171
|
private validators;
|
|
145
172
|
constructor(field: Field, options?: FieldOptions);
|
|
173
|
+
__getElemField(): Field;
|
|
146
174
|
validate(validator: (val: any[]) => boolean): this;
|
|
147
175
|
valid(val: any): Promise<boolean>;
|
|
148
176
|
private postgresVal;
|
|
@@ -153,7 +181,7 @@ export declare class ListField extends BaseField {
|
|
|
153
181
|
range(start: any, stop: any): this;
|
|
154
182
|
}
|
|
155
183
|
export declare function StringListType(options?: StringOptions): ListField;
|
|
156
|
-
export declare function IntListType(options
|
|
184
|
+
export declare function IntListType(options?: FieldOptions): ListField;
|
|
157
185
|
export declare function IntegerListType(options?: FieldOptions): ListField;
|
|
158
186
|
export declare function FloatListType(options?: FieldOptions): ListField;
|
|
159
187
|
export declare function BigIntegerListType(options: FieldOptions): ListField;
|
|
@@ -163,6 +191,7 @@ export declare function TimestamptzListType(options?: TimestampOptions): ListFie
|
|
|
163
191
|
export declare function TimeListType(options?: TimeOptions): ListField;
|
|
164
192
|
export declare function TimetzListType(options: TimeOptions): ListField;
|
|
165
193
|
export declare function DateListType(options?: FieldOptions): ListField;
|
|
166
|
-
export declare function EnumListType(options:
|
|
194
|
+
export declare function EnumListType(options: StringEnumOptions): ListField;
|
|
195
|
+
export declare function IntegerEnumListType(options: IntegerEnumOptions): ListField;
|
|
167
196
|
export declare function UUIDListType(options?: FieldOptions): ListField;
|
|
168
197
|
export {};
|
package/schema/field.js
CHANGED
|
@@ -19,12 +19,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.UUIDListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.EnumType = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
22
|
+
exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
23
23
|
const luxon_1 = require("luxon");
|
|
24
24
|
const snake_case_1 = require("snake-case");
|
|
25
25
|
const db_1 = __importStar(require("../core/db"));
|
|
26
26
|
const schema_1 = require("./schema");
|
|
27
27
|
const util_1 = require("util");
|
|
28
|
+
const uuid_1 = require("uuid");
|
|
28
29
|
class BaseField {
|
|
29
30
|
logValue(val) {
|
|
30
31
|
if (this.sensitive) {
|
|
@@ -92,6 +93,9 @@ class UUIDField extends BaseField {
|
|
|
92
93
|
return val.placeholderID !== undefined;
|
|
93
94
|
}
|
|
94
95
|
async valid(val) {
|
|
96
|
+
if (typeof val === "string" && !(0, uuid_1.validate)(val)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
95
99
|
if (!this.options?.fieldEdge?.enforceSchema) {
|
|
96
100
|
return true;
|
|
97
101
|
}
|
|
@@ -444,6 +448,9 @@ function DateType(options) {
|
|
|
444
448
|
return Object.assign(result, options);
|
|
445
449
|
}
|
|
446
450
|
exports.DateType = DateType;
|
|
451
|
+
/**
|
|
452
|
+
* @deprecated Use StringEnumField
|
|
453
|
+
*/
|
|
447
454
|
class EnumField extends BaseField {
|
|
448
455
|
constructor(options) {
|
|
449
456
|
super();
|
|
@@ -546,11 +553,57 @@ class EnumField extends BaseField {
|
|
|
546
553
|
}
|
|
547
554
|
}
|
|
548
555
|
exports.EnumField = EnumField;
|
|
556
|
+
class StringEnumField extends EnumField {
|
|
557
|
+
}
|
|
558
|
+
exports.StringEnumField = StringEnumField;
|
|
549
559
|
function EnumType(options) {
|
|
550
|
-
let result = new
|
|
560
|
+
let result = new StringEnumField(options);
|
|
551
561
|
return Object.assign(result, options);
|
|
552
562
|
}
|
|
553
563
|
exports.EnumType = EnumType;
|
|
564
|
+
class IntegerEnumField extends BaseField {
|
|
565
|
+
constructor(options) {
|
|
566
|
+
super();
|
|
567
|
+
this.type = {
|
|
568
|
+
dbType: schema_1.DBType.IntEnum,
|
|
569
|
+
intEnumMap: options.map,
|
|
570
|
+
type: options.tsType,
|
|
571
|
+
graphQLType: options.graphQLType,
|
|
572
|
+
deprecatedIntEnumMap: options.deprecated,
|
|
573
|
+
};
|
|
574
|
+
let count = 0;
|
|
575
|
+
for (const k in options.map) {
|
|
576
|
+
count++;
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
if (!count) {
|
|
580
|
+
throw new Error("need at least one entry in enum map");
|
|
581
|
+
}
|
|
582
|
+
if (options.foreignKey) {
|
|
583
|
+
throw new Error(`foreignKey on intEnum not supported`);
|
|
584
|
+
}
|
|
585
|
+
this.map = options.map;
|
|
586
|
+
}
|
|
587
|
+
valid(val) {
|
|
588
|
+
// lookup table enum and indicated via presence of foreignKey
|
|
589
|
+
for (const k in this.map) {
|
|
590
|
+
const v = this.map[k];
|
|
591
|
+
if (v === val || v === parseInt(val)) {
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
format(val) {
|
|
598
|
+
return parseInt(val);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
exports.IntegerEnumField = IntegerEnumField;
|
|
602
|
+
function IntegerEnumType(options) {
|
|
603
|
+
let result = new IntegerEnumField(options);
|
|
604
|
+
return Object.assign(result, options);
|
|
605
|
+
}
|
|
606
|
+
exports.IntegerEnumType = IntegerEnumType;
|
|
554
607
|
class ListField extends BaseField {
|
|
555
608
|
constructor(field, options) {
|
|
556
609
|
super();
|
|
@@ -565,6 +618,9 @@ class ListField extends BaseField {
|
|
|
565
618
|
};
|
|
566
619
|
Object.assign(this, options);
|
|
567
620
|
}
|
|
621
|
+
__getElemField() {
|
|
622
|
+
return this.field;
|
|
623
|
+
}
|
|
568
624
|
validate(validator) {
|
|
569
625
|
this.validators.push(validator);
|
|
570
626
|
return this;
|
|
@@ -593,6 +649,10 @@ class ListField extends BaseField {
|
|
|
593
649
|
}
|
|
594
650
|
postgresVal(val, jsonType) {
|
|
595
651
|
if (!jsonType) {
|
|
652
|
+
// support empty strings in list
|
|
653
|
+
if (val === "") {
|
|
654
|
+
val = '"' + val + '"';
|
|
655
|
+
}
|
|
596
656
|
return val;
|
|
597
657
|
}
|
|
598
658
|
return JSON.stringify(val);
|
|
@@ -720,6 +780,14 @@ function EnumListType(options) {
|
|
|
720
780
|
return new ListField(EnumType(options), options);
|
|
721
781
|
}
|
|
722
782
|
exports.EnumListType = EnumListType;
|
|
783
|
+
function IntegerEnumListType(options) {
|
|
784
|
+
// not all of these will make sense in a list...
|
|
785
|
+
// can make it work eventually but involves work we're not currently trying to do
|
|
786
|
+
// developer can try to work around it by calling below on their own.
|
|
787
|
+
// unclear what the behavior is
|
|
788
|
+
return new ListField(IntegerEnumType(options), options);
|
|
789
|
+
}
|
|
790
|
+
exports.IntegerEnumListType = IntegerEnumListType;
|
|
723
791
|
function UUIDListType(options) {
|
|
724
792
|
return new ListField(UUIDType(options), options);
|
|
725
793
|
}
|
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/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;
|
package/schema/schema.d.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
|
|
2
|
-
import { Builder } from "../action/action";
|
|
2
|
+
import { Builder, Changeset } from "../action/action";
|
|
3
3
|
import { Clause } from "../core/clause";
|
|
4
|
+
import { AssocEdgeInput } from "../core/ent";
|
|
4
5
|
export declare type FieldMap = {
|
|
5
6
|
[key: string]: Field;
|
|
6
7
|
};
|
|
8
|
+
interface FieldInfo {
|
|
9
|
+
dbCol: string;
|
|
10
|
+
inputKey: string;
|
|
11
|
+
}
|
|
12
|
+
export declare type FieldInfoMap = {
|
|
13
|
+
[key: string]: FieldInfo;
|
|
14
|
+
};
|
|
15
|
+
export interface GlobalSchema {
|
|
16
|
+
edges?: Edge[];
|
|
17
|
+
extraEdgeFields?: FieldMap;
|
|
18
|
+
transformEdgeRead?: () => Clause;
|
|
19
|
+
transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
|
|
20
|
+
}
|
|
7
21
|
export default interface Schema {
|
|
8
22
|
fields: FieldMap | Field[];
|
|
9
23
|
tableName?: string;
|
|
@@ -62,9 +76,10 @@ export declare type Edge = AssocEdge;
|
|
|
62
76
|
export interface Pattern {
|
|
63
77
|
name: string;
|
|
64
78
|
fields: FieldMap | Field[];
|
|
79
|
+
disableMixin?: boolean;
|
|
65
80
|
edges?: Edge[];
|
|
66
81
|
transformRead?: () => Clause;
|
|
67
|
-
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> |
|
|
82
|
+
transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
|
|
68
83
|
transformsDelete?: boolean;
|
|
69
84
|
transformsInsert?: boolean;
|
|
70
85
|
transformsUpdate?: boolean;
|
|
@@ -74,16 +89,25 @@ export declare enum SQLStatementOperation {
|
|
|
74
89
|
Update = "update",
|
|
75
90
|
Delete = "delete"
|
|
76
91
|
}
|
|
77
|
-
export interface
|
|
92
|
+
export interface EdgeUpdateOperation {
|
|
93
|
+
op: SQLStatementOperation;
|
|
94
|
+
edge: AssocEdgeInput;
|
|
95
|
+
}
|
|
96
|
+
export interface TransformedEdgeUpdateOperation {
|
|
78
97
|
op: SQLStatementOperation;
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
data?: Data;
|
|
99
|
+
}
|
|
100
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
101
|
+
op: SQLStatementOperation;
|
|
102
|
+
builder: Builder<TEnt, TViewer, any>;
|
|
103
|
+
input: Data;
|
|
81
104
|
data?: Map<string, any>;
|
|
82
105
|
}
|
|
83
|
-
export interface TransformedUpdateOperation<T extends Ent> {
|
|
106
|
+
export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
84
107
|
op: SQLStatementOperation;
|
|
85
108
|
data?: Data;
|
|
86
|
-
existingEnt?: T;
|
|
109
|
+
existingEnt?: T | null;
|
|
110
|
+
changeset?(): Promise<Changeset> | Changeset;
|
|
87
111
|
}
|
|
88
112
|
export declare enum DBType {
|
|
89
113
|
UUID = "UUID",
|
|
@@ -99,6 +123,7 @@ export declare enum DBType {
|
|
|
99
123
|
JSONB = "JSONB",
|
|
100
124
|
Enum = "Enum",
|
|
101
125
|
StringEnum = "StringEnum",
|
|
126
|
+
IntEnum = "IntEnum",
|
|
102
127
|
Date = "Date",
|
|
103
128
|
Time = "Time",
|
|
104
129
|
Timetz = "Timetz",
|
|
@@ -109,9 +134,16 @@ export interface ImportType {
|
|
|
109
134
|
type: string;
|
|
110
135
|
[x: string]: any;
|
|
111
136
|
}
|
|
137
|
+
export interface ConvertType {
|
|
138
|
+
path: string;
|
|
139
|
+
function: string;
|
|
140
|
+
}
|
|
112
141
|
declare type EnumMap = {
|
|
113
142
|
[key: string]: string;
|
|
114
143
|
};
|
|
144
|
+
declare type IntEnumMap = {
|
|
145
|
+
[key: string]: number;
|
|
146
|
+
};
|
|
115
147
|
export interface Type {
|
|
116
148
|
dbType: DBType;
|
|
117
149
|
listElemType?: Type;
|
|
@@ -119,9 +151,12 @@ export interface Type {
|
|
|
119
151
|
graphQLType?: string;
|
|
120
152
|
values?: string[];
|
|
121
153
|
enumMap?: EnumMap;
|
|
154
|
+
intEnumMap?: IntEnumMap;
|
|
155
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
122
156
|
importType?: ImportType;
|
|
123
157
|
subFields?: FieldMap;
|
|
124
158
|
unionFields?: FieldMap;
|
|
159
|
+
[x: string]: any;
|
|
125
160
|
}
|
|
126
161
|
export interface ForeignKey {
|
|
127
162
|
schema: string;
|
|
@@ -129,6 +164,7 @@ export interface ForeignKey {
|
|
|
129
164
|
name?: string;
|
|
130
165
|
disableIndex?: boolean;
|
|
131
166
|
disableBuilderType?: boolean;
|
|
167
|
+
[x: string]: any;
|
|
132
168
|
}
|
|
133
169
|
declare type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
134
170
|
export interface InverseFieldEdge {
|
|
@@ -144,13 +180,16 @@ export interface FieldEdge {
|
|
|
144
180
|
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
145
181
|
disableBuilderType?: boolean;
|
|
146
182
|
}
|
|
183
|
+
interface PrivateOptions {
|
|
184
|
+
exposeToActions?: boolean;
|
|
185
|
+
}
|
|
147
186
|
export interface FieldOptions {
|
|
148
187
|
nullable?: boolean;
|
|
149
188
|
storageKey?: string;
|
|
150
189
|
serverDefault?: any;
|
|
151
190
|
unique?: boolean;
|
|
152
191
|
hideFromGraphQL?: boolean;
|
|
153
|
-
private?: boolean;
|
|
192
|
+
private?: boolean | PrivateOptions;
|
|
154
193
|
sensitive?: boolean;
|
|
155
194
|
graphqlName?: string;
|
|
156
195
|
index?: boolean;
|
|
@@ -166,6 +205,8 @@ export interface FieldOptions {
|
|
|
166
205
|
polymorphic?: boolean | PolymorphicOptions;
|
|
167
206
|
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
168
207
|
getDerivedFields?(name: string): FieldMap;
|
|
208
|
+
convert?: ConvertType;
|
|
209
|
+
fetchOnDemand?: boolean;
|
|
169
210
|
[x: string]: any;
|
|
170
211
|
}
|
|
171
212
|
export interface PolymorphicOptions {
|
|
@@ -185,15 +226,18 @@ export interface SchemaConstructor {
|
|
|
185
226
|
export declare type SchemaInputType = Schema | SchemaConstructor;
|
|
186
227
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
187
228
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
229
|
+
/**
|
|
230
|
+
* @deprecated should only be used by tests
|
|
231
|
+
*/
|
|
188
232
|
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
189
|
-
export declare function getFieldsWithPrivacy(value: SchemaInputType): Map<string, PrivacyPolicy>;
|
|
233
|
+
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
190
234
|
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
191
235
|
interface objectLoaderOptions {
|
|
192
236
|
clause?: () => Clause | undefined;
|
|
193
237
|
instanceKey?: string;
|
|
194
238
|
}
|
|
195
239
|
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
196
|
-
export declare function getTransformedUpdateOp<
|
|
240
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
197
241
|
export declare enum ActionOperation {
|
|
198
242
|
Create = 1,
|
|
199
243
|
Edit = 2,
|
|
@@ -212,6 +256,7 @@ export interface ActionField {
|
|
|
212
256
|
list?: boolean;
|
|
213
257
|
actionName?: string;
|
|
214
258
|
excludedFields?: string[];
|
|
259
|
+
[x: string]: any;
|
|
215
260
|
}
|
|
216
261
|
export interface Action {
|
|
217
262
|
operation: ActionOperation;
|
|
@@ -225,6 +270,7 @@ export interface Action {
|
|
|
225
270
|
optionalFields?: string[];
|
|
226
271
|
requiredFields?: string[];
|
|
227
272
|
noFields?: boolean;
|
|
273
|
+
[x: string]: any;
|
|
228
274
|
}
|
|
229
275
|
export declare const NoFields = "__NO_FIELDS__";
|
|
230
276
|
export declare function requiredField(field: string): string;
|
|
@@ -235,6 +281,7 @@ export interface Constraint {
|
|
|
235
281
|
columns: string[];
|
|
236
282
|
fkey?: ForeignKeyInfo;
|
|
237
283
|
condition?: string;
|
|
284
|
+
[x: string]: any;
|
|
238
285
|
}
|
|
239
286
|
export interface FullTextWeight {
|
|
240
287
|
A?: string[];
|
|
@@ -248,17 +295,21 @@ export interface FullText {
|
|
|
248
295
|
languageColumn?: string;
|
|
249
296
|
indexType?: "gin" | "gist";
|
|
250
297
|
weights?: FullTextWeight;
|
|
298
|
+
[x: string]: any;
|
|
251
299
|
}
|
|
252
300
|
export interface Index {
|
|
253
301
|
name: string;
|
|
254
302
|
columns: string[];
|
|
255
303
|
unique?: boolean;
|
|
256
304
|
fulltext?: FullText;
|
|
305
|
+
indexType?: "gin" | "btree";
|
|
306
|
+
[x: string]: any;
|
|
257
307
|
}
|
|
258
308
|
export interface ForeignKeyInfo {
|
|
259
309
|
tableName: string;
|
|
260
310
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
261
311
|
columns: string[];
|
|
312
|
+
[x: string]: any;
|
|
262
313
|
}
|
|
263
314
|
export declare enum ConstraintType {
|
|
264
315
|
PrimaryKey = "primary",
|
package/schema/schema.js
CHANGED
|
@@ -35,6 +35,7 @@ var DBType;
|
|
|
35
35
|
DBType["JSONB"] = "JSONB";
|
|
36
36
|
DBType["Enum"] = "Enum";
|
|
37
37
|
DBType["StringEnum"] = "StringEnum";
|
|
38
|
+
DBType["IntEnum"] = "IntEnum";
|
|
38
39
|
DBType["Date"] = "Date";
|
|
39
40
|
DBType["Time"] = "Time";
|
|
40
41
|
DBType["Timetz"] = "Timetz";
|
|
@@ -86,12 +87,15 @@ function getFields(value) {
|
|
|
86
87
|
return m;
|
|
87
88
|
}
|
|
88
89
|
exports.getFields = getFields;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated should only be used by tests
|
|
92
|
+
*/
|
|
89
93
|
function getStorageKey(field, fieldName) {
|
|
90
94
|
return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
|
|
91
95
|
}
|
|
92
96
|
exports.getStorageKey = getStorageKey;
|
|
93
97
|
// returns a mapping of storage key to field privacy
|
|
94
|
-
function getFieldsWithPrivacy(value) {
|
|
98
|
+
function getFieldsWithPrivacy(value, fieldMap) {
|
|
95
99
|
const schema = getSchema(value);
|
|
96
100
|
function addFields(fields) {
|
|
97
101
|
if (Array.isArray(fields)) {
|
|
@@ -111,9 +115,14 @@ function getFieldsWithPrivacy(value) {
|
|
|
111
115
|
else {
|
|
112
116
|
privacyPolicy = field.privacyPolicy;
|
|
113
117
|
}
|
|
114
|
-
|
|
118
|
+
const info = fieldMap[name];
|
|
119
|
+
if (!info) {
|
|
120
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
121
|
+
}
|
|
122
|
+
m.set(info.dbCol, privacyPolicy);
|
|
115
123
|
}
|
|
116
124
|
}
|
|
125
|
+
return;
|
|
117
126
|
}
|
|
118
127
|
for (const name in fields) {
|
|
119
128
|
const field = fields[name];
|
|
@@ -128,7 +137,11 @@ function getFieldsWithPrivacy(value) {
|
|
|
128
137
|
else {
|
|
129
138
|
privacyPolicy = field.privacyPolicy;
|
|
130
139
|
}
|
|
131
|
-
|
|
140
|
+
const info = fieldMap[name];
|
|
141
|
+
if (!info) {
|
|
142
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
143
|
+
}
|
|
144
|
+
m.set(info.dbCol, privacyPolicy);
|
|
132
145
|
}
|
|
133
146
|
}
|
|
134
147
|
}
|
|
@@ -167,13 +180,14 @@ exports.getObjectLoaderProperties = getObjectLoaderProperties;
|
|
|
167
180
|
function getTransformedUpdateOp(value, stmt) {
|
|
168
181
|
const schema = getSchema(value);
|
|
169
182
|
if (!schema.patterns) {
|
|
170
|
-
return;
|
|
183
|
+
return null;
|
|
171
184
|
}
|
|
172
185
|
for (const p of schema.patterns) {
|
|
173
186
|
if (p.transformWrite) {
|
|
174
187
|
return p.transformWrite(stmt);
|
|
175
188
|
}
|
|
176
189
|
}
|
|
190
|
+
return null;
|
|
177
191
|
}
|
|
178
192
|
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
179
193
|
// this maps to ActionOperation in ent/action.go
|
package/schema/struct_field.d.ts
CHANGED
|
@@ -6,12 +6,22 @@ export interface StructOptions extends FieldOptions {
|
|
|
6
6
|
graphQLType?: string;
|
|
7
7
|
jsonNotJSONB?: boolean;
|
|
8
8
|
}
|
|
9
|
+
interface allStructOptions extends StructOptions {
|
|
10
|
+
jsonAsList?: boolean;
|
|
11
|
+
}
|
|
9
12
|
export declare class StructField extends BaseField implements Field {
|
|
10
13
|
private options;
|
|
11
14
|
type: Type;
|
|
12
|
-
constructor(options:
|
|
15
|
+
constructor(options: allStructOptions);
|
|
16
|
+
formatImpl(obj: any, nested?: boolean): string | Object;
|
|
13
17
|
format(obj: any, nested?: boolean): string | Object;
|
|
18
|
+
private validImpl;
|
|
14
19
|
valid(obj: any): Promise<boolean>;
|
|
15
20
|
}
|
|
16
21
|
export declare function StructType(options: StructOptions): StructField & StructOptions;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use StructTypeAsList
|
|
24
|
+
*/
|
|
17
25
|
export declare function StructListType(options: StructOptions): ListField;
|
|
26
|
+
export declare function StructTypeAsList(options: allStructOptions): StructField & allStructOptions;
|
|
27
|
+
export {};
|