@snowtop/ent 0.1.0-alpha45 → 0.1.0-alpha47
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/graphql/graphql.js +6 -0
- package/package.json +1 -1
- package/schema/field.d.ts +33 -5
- package/schema/field.js +59 -2
- package/schema/schema.d.ts +6 -0
- package/schema/schema.js +1 -0
- package/scripts/custom_graphql.js +3 -1
package/graphql/graphql.js
CHANGED
|
@@ -85,6 +85,12 @@ const addCustomType = (type) => {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
catch (e) {
|
|
88
|
+
if (type.secondaryImportPath) {
|
|
89
|
+
(0, exports.addCustomType)({
|
|
90
|
+
...type,
|
|
91
|
+
importPath: type.secondaryImportPath,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
88
94
|
return;
|
|
89
95
|
}
|
|
90
96
|
GQLCapture.getCustomTypes().set(type.type, type);
|
package/package.json
CHANGED
package/schema/field.d.ts
CHANGED
|
@@ -118,26 +118,53 @@ 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;
|
|
@@ -163,6 +190,7 @@ export declare function TimestamptzListType(options?: TimestampOptions): ListFie
|
|
|
163
190
|
export declare function TimeListType(options?: TimeOptions): ListField;
|
|
164
191
|
export declare function TimetzListType(options: TimeOptions): ListField;
|
|
165
192
|
export declare function DateListType(options?: FieldOptions): ListField;
|
|
166
|
-
export declare function EnumListType(options:
|
|
193
|
+
export declare function EnumListType(options: StringEnumOptions): ListField;
|
|
194
|
+
export declare function IntegerEnumListType(options: IntegerEnumOptions): ListField;
|
|
167
195
|
export declare function UUIDListType(options?: FieldOptions): ListField;
|
|
168
196
|
export {};
|
package/schema/field.js
CHANGED
|
@@ -19,7 +19,7 @@ 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"));
|
|
@@ -444,6 +444,9 @@ function DateType(options) {
|
|
|
444
444
|
return Object.assign(result, options);
|
|
445
445
|
}
|
|
446
446
|
exports.DateType = DateType;
|
|
447
|
+
/**
|
|
448
|
+
* @deprecated Use StringEnumField
|
|
449
|
+
*/
|
|
447
450
|
class EnumField extends BaseField {
|
|
448
451
|
constructor(options) {
|
|
449
452
|
super();
|
|
@@ -546,11 +549,57 @@ class EnumField extends BaseField {
|
|
|
546
549
|
}
|
|
547
550
|
}
|
|
548
551
|
exports.EnumField = EnumField;
|
|
552
|
+
class StringEnumField extends EnumField {
|
|
553
|
+
}
|
|
554
|
+
exports.StringEnumField = StringEnumField;
|
|
549
555
|
function EnumType(options) {
|
|
550
|
-
let result = new
|
|
556
|
+
let result = new StringEnumField(options);
|
|
551
557
|
return Object.assign(result, options);
|
|
552
558
|
}
|
|
553
559
|
exports.EnumType = EnumType;
|
|
560
|
+
class IntegerEnumField extends BaseField {
|
|
561
|
+
constructor(options) {
|
|
562
|
+
super();
|
|
563
|
+
this.type = {
|
|
564
|
+
dbType: schema_1.DBType.IntEnum,
|
|
565
|
+
intEnumMap: options.map,
|
|
566
|
+
type: options.tsType,
|
|
567
|
+
graphQLType: options.graphQLType,
|
|
568
|
+
deprecatedIntEnumMap: options.deprecated,
|
|
569
|
+
};
|
|
570
|
+
let count = 0;
|
|
571
|
+
for (const k in options.map) {
|
|
572
|
+
count++;
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
if (!count) {
|
|
576
|
+
throw new Error("need at least one entry in enum map");
|
|
577
|
+
}
|
|
578
|
+
if (options.foreignKey) {
|
|
579
|
+
throw new Error(`foreignKey on intEnum not supported`);
|
|
580
|
+
}
|
|
581
|
+
this.map = options.map;
|
|
582
|
+
}
|
|
583
|
+
valid(val) {
|
|
584
|
+
// lookup table enum and indicated via presence of foreignKey
|
|
585
|
+
for (const k in this.map) {
|
|
586
|
+
const v = this.map[k];
|
|
587
|
+
if (v === val || v === parseInt(val)) {
|
|
588
|
+
return true;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
format(val) {
|
|
594
|
+
return parseInt(val);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
exports.IntegerEnumField = IntegerEnumField;
|
|
598
|
+
function IntegerEnumType(options) {
|
|
599
|
+
let result = new IntegerEnumField(options);
|
|
600
|
+
return Object.assign(result, options);
|
|
601
|
+
}
|
|
602
|
+
exports.IntegerEnumType = IntegerEnumType;
|
|
554
603
|
class ListField extends BaseField {
|
|
555
604
|
constructor(field, options) {
|
|
556
605
|
super();
|
|
@@ -720,6 +769,14 @@ function EnumListType(options) {
|
|
|
720
769
|
return new ListField(EnumType(options), options);
|
|
721
770
|
}
|
|
722
771
|
exports.EnumListType = EnumListType;
|
|
772
|
+
function IntegerEnumListType(options) {
|
|
773
|
+
// not all of these will make sense in a list...
|
|
774
|
+
// can make it work eventually but involves work we're not currently trying to do
|
|
775
|
+
// developer can try to work around it by calling below on their own.
|
|
776
|
+
// unclear what the behavior is
|
|
777
|
+
return new ListField(IntegerEnumType(options), options);
|
|
778
|
+
}
|
|
779
|
+
exports.IntegerEnumListType = IntegerEnumListType;
|
|
723
780
|
function UUIDListType(options) {
|
|
724
781
|
return new ListField(UUIDType(options), options);
|
|
725
782
|
}
|
package/schema/schema.d.ts
CHANGED
|
@@ -107,6 +107,7 @@ export declare enum DBType {
|
|
|
107
107
|
JSONB = "JSONB",
|
|
108
108
|
Enum = "Enum",
|
|
109
109
|
StringEnum = "StringEnum",
|
|
110
|
+
IntEnum = "IntEnum",
|
|
110
111
|
Date = "Date",
|
|
111
112
|
Time = "Time",
|
|
112
113
|
Timetz = "Timetz",
|
|
@@ -120,6 +121,9 @@ export interface ImportType {
|
|
|
120
121
|
declare type EnumMap = {
|
|
121
122
|
[key: string]: string;
|
|
122
123
|
};
|
|
124
|
+
declare type IntEnumMap = {
|
|
125
|
+
[key: string]: number;
|
|
126
|
+
};
|
|
123
127
|
export interface Type {
|
|
124
128
|
dbType: DBType;
|
|
125
129
|
listElemType?: Type;
|
|
@@ -127,6 +131,8 @@ export interface Type {
|
|
|
127
131
|
graphQLType?: string;
|
|
128
132
|
values?: string[];
|
|
129
133
|
enumMap?: EnumMap;
|
|
134
|
+
intEnumMap?: IntEnumMap;
|
|
135
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
130
136
|
importType?: ImportType;
|
|
131
137
|
subFields?: FieldMap;
|
|
132
138
|
unionFields?: FieldMap;
|
package/schema/schema.js
CHANGED
|
@@ -235,7 +235,9 @@ async function main() {
|
|
|
235
235
|
// if this list grows too long, need to build this into golang types and passed here
|
|
236
236
|
// TODO foreign non-scalars eventually
|
|
237
237
|
(0, graphql_1.addCustomType)({
|
|
238
|
-
importPath:
|
|
238
|
+
importPath: MODULE_PATH,
|
|
239
|
+
// for go tests...
|
|
240
|
+
secondaryImportPath: "../graphql/scalars/time",
|
|
239
241
|
type: "GraphQLTime",
|
|
240
242
|
});
|
|
241
243
|
(0, graphql_1.addCustomType)({
|