@snowtop/ent 0.1.0-alpha96 → 0.1.0-alpha98-dd4b3a20-9958-11ed-b8bd-fb8b6537b3bc
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/core/config.d.ts +1 -0
- package/graphql/graphql.d.ts +2 -0
- package/package.json +1 -1
- package/schema/field.d.ts +17 -12
- package/schema/field.js +16 -6
- package/scripts/custom_graphql.js +42 -1
package/core/config.d.ts
CHANGED
package/graphql/graphql.d.ts
CHANGED
package/package.json
CHANGED
package/schema/field.d.ts
CHANGED
|
@@ -25,31 +25,36 @@ export declare class UUIDField extends BaseField implements Field {
|
|
|
25
25
|
valid(val: any): Promise<boolean>;
|
|
26
26
|
}
|
|
27
27
|
export declare function UUIDType(options?: FieldOptions): UUIDField;
|
|
28
|
-
export interface IntegerOptions extends
|
|
29
|
-
min?: number;
|
|
30
|
-
max?: number;
|
|
28
|
+
export interface IntegerOptions extends NumberOptions<number> {
|
|
31
29
|
}
|
|
32
|
-
export
|
|
30
|
+
export interface NumberOptions<T> extends FieldOptions {
|
|
31
|
+
min?: T;
|
|
32
|
+
max?: T;
|
|
33
|
+
}
|
|
34
|
+
export declare class NumberField<T> extends BaseField {
|
|
33
35
|
type: Type;
|
|
34
36
|
private validators;
|
|
35
37
|
private options;
|
|
36
|
-
constructor(options?:
|
|
37
|
-
getOptions():
|
|
38
|
+
constructor(options?: NumberOptions<T>);
|
|
39
|
+
getOptions(): NumberOptions<T>;
|
|
38
40
|
private handleOptions;
|
|
39
|
-
min(l:
|
|
40
|
-
max(l:
|
|
41
|
+
min(l: T): this;
|
|
42
|
+
max(l: T): this;
|
|
41
43
|
valid(val: any): boolean;
|
|
42
44
|
validate(validator: (str: number) => boolean): this;
|
|
43
45
|
}
|
|
46
|
+
export declare class IntegerField extends NumberField<number> implements Field {
|
|
47
|
+
type: Type;
|
|
48
|
+
}
|
|
44
49
|
export declare function IntegerType(options?: IntegerOptions): IntegerField;
|
|
45
|
-
export declare class BigIntegerField extends
|
|
50
|
+
export declare class BigIntegerField extends NumberField<BigInt> implements Field {
|
|
46
51
|
type: Type;
|
|
47
52
|
}
|
|
48
|
-
export declare function BigIntegerType(options?:
|
|
49
|
-
export declare class FloatField extends
|
|
53
|
+
export declare function BigIntegerType(options?: NumberOptions<BigInt>): BigIntegerField;
|
|
54
|
+
export declare class FloatField extends NumberField<number> implements Field {
|
|
50
55
|
type: Type;
|
|
51
56
|
}
|
|
52
|
-
export declare function FloatType(options?:
|
|
57
|
+
export declare function FloatType(options?: NumberOptions<number>): FloatField;
|
|
53
58
|
export declare class BooleanField extends BaseField implements Field {
|
|
54
59
|
type: Type;
|
|
55
60
|
}
|
package/schema/field.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.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;
|
|
27
27
|
const luxon_1 = require("luxon");
|
|
28
28
|
const camel_case_1 = require("camel-case");
|
|
29
29
|
const util_1 = require("util");
|
|
@@ -119,9 +119,10 @@ function UUIDType(options) {
|
|
|
119
119
|
return Object.assign(result, options);
|
|
120
120
|
}
|
|
121
121
|
exports.UUIDType = UUIDType;
|
|
122
|
-
class
|
|
122
|
+
class NumberField extends BaseField {
|
|
123
123
|
constructor(options) {
|
|
124
124
|
super();
|
|
125
|
+
// to be overriden as needed
|
|
125
126
|
this.type = { dbType: schema_1.DBType.Int };
|
|
126
127
|
this.validators = [];
|
|
127
128
|
this.options = {};
|
|
@@ -145,9 +146,11 @@ class IntegerField extends BaseField {
|
|
|
145
146
|
this.options = options;
|
|
146
147
|
}
|
|
147
148
|
min(l) {
|
|
149
|
+
// @ts-ignore Operator '>=' cannot be applied to types 'number' and 'T'.
|
|
148
150
|
return this.validate((val) => val >= l);
|
|
149
151
|
}
|
|
150
152
|
max(l) {
|
|
153
|
+
// @ts-ignore Operator '<=' cannot be applied to types 'number' and 'T'.
|
|
151
154
|
return this.validate((val) => val <= l);
|
|
152
155
|
}
|
|
153
156
|
valid(val) {
|
|
@@ -163,13 +166,20 @@ class IntegerField extends BaseField {
|
|
|
163
166
|
return this;
|
|
164
167
|
}
|
|
165
168
|
}
|
|
169
|
+
exports.NumberField = NumberField;
|
|
170
|
+
class IntegerField extends NumberField {
|
|
171
|
+
constructor() {
|
|
172
|
+
super(...arguments);
|
|
173
|
+
this.type = { dbType: schema_1.DBType.Int };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
166
176
|
exports.IntegerField = IntegerField;
|
|
167
177
|
function IntegerType(options) {
|
|
168
178
|
let result = new IntegerField(options);
|
|
169
179
|
return Object.assign(result, options);
|
|
170
180
|
}
|
|
171
181
|
exports.IntegerType = IntegerType;
|
|
172
|
-
class BigIntegerField extends
|
|
182
|
+
class BigIntegerField extends NumberField {
|
|
173
183
|
constructor() {
|
|
174
184
|
super(...arguments);
|
|
175
185
|
this.type = { dbType: schema_1.DBType.BigInt };
|
|
@@ -177,11 +187,11 @@ class BigIntegerField extends BaseField {
|
|
|
177
187
|
}
|
|
178
188
|
exports.BigIntegerField = BigIntegerField;
|
|
179
189
|
function BigIntegerType(options) {
|
|
180
|
-
let result = new BigIntegerField();
|
|
190
|
+
let result = new BigIntegerField(options);
|
|
181
191
|
return Object.assign(result, options);
|
|
182
192
|
}
|
|
183
193
|
exports.BigIntegerType = BigIntegerType;
|
|
184
|
-
class FloatField extends
|
|
194
|
+
class FloatField extends NumberField {
|
|
185
195
|
constructor() {
|
|
186
196
|
super(...arguments);
|
|
187
197
|
this.type = { dbType: schema_1.DBType.Float };
|
|
@@ -189,7 +199,7 @@ class FloatField extends BaseField {
|
|
|
189
199
|
}
|
|
190
200
|
exports.FloatField = FloatField;
|
|
191
201
|
function FloatType(options) {
|
|
192
|
-
let result = new FloatField();
|
|
202
|
+
let result = new FloatField(options);
|
|
193
203
|
return Object.assign(result, options);
|
|
194
204
|
}
|
|
195
205
|
exports.FloatType = FloatType;
|
|
@@ -36,6 +36,7 @@ const graphql_1 = require("../graphql/graphql");
|
|
|
36
36
|
const readline = __importStar(require("readline"));
|
|
37
37
|
const imports_1 = require("../imports");
|
|
38
38
|
const process_1 = require("process");
|
|
39
|
+
const child_process_1 = require("child_process");
|
|
39
40
|
// need to use the GQLCapture from the package so that when we call GQLCapture.enable()
|
|
40
41
|
// we're affecting the local paths as opposed to a different instance
|
|
41
42
|
// life is hard
|
|
@@ -115,6 +116,8 @@ function processTopLevel(l, l2) {
|
|
|
115
116
|
args: transformArgs(custom),
|
|
116
117
|
results: transformResultType(custom),
|
|
117
118
|
description: custom.description,
|
|
119
|
+
extraImports: custom.extraImports,
|
|
120
|
+
functionContents: custom.functionContents,
|
|
118
121
|
});
|
|
119
122
|
}
|
|
120
123
|
}
|
|
@@ -134,6 +137,43 @@ function processCustomFields(fields, gqlCapture, nodeName) {
|
|
|
134
137
|
}
|
|
135
138
|
m.set(nodeName, results);
|
|
136
139
|
}
|
|
140
|
+
async function captureDynamic(filePath, gqlCapture) {
|
|
141
|
+
if (!filePath) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
return await new Promise((resolve, reject) => {
|
|
145
|
+
// TODO tsconfig-paths?
|
|
146
|
+
const r = (0, child_process_1.spawn)("ts-node", [filePath]);
|
|
147
|
+
const datas = [];
|
|
148
|
+
r.stdout.on("data", (data) => {
|
|
149
|
+
datas.push(data.toString());
|
|
150
|
+
});
|
|
151
|
+
r.stderr.on("data", (data) => {
|
|
152
|
+
reject(new Error(data.toString()));
|
|
153
|
+
});
|
|
154
|
+
r.on("close", (code) => {
|
|
155
|
+
if (code !== 0) {
|
|
156
|
+
reject(new Error(`error code ${code} on dynamic path`));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
let json = json5_1.default.parse(datas.join(""));
|
|
160
|
+
for (const k in json) {
|
|
161
|
+
const v = json[k];
|
|
162
|
+
switch (k) {
|
|
163
|
+
case "queries":
|
|
164
|
+
processTopLevel(v, gqlCapture.getCustomQueries());
|
|
165
|
+
break;
|
|
166
|
+
case "mutations":
|
|
167
|
+
processTopLevel(v, gqlCapture.getCustomMutations());
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
reject(new Error(`key ${k} is unsupported in dynamic custom graphql. only queries and mutations are supported`));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
resolve(undefined);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
137
177
|
async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
138
178
|
if (jsonPath !== undefined) {
|
|
139
179
|
let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
|
|
@@ -297,9 +337,10 @@ async function main() {
|
|
|
297
337
|
gqlCapture = r.GQLCapture;
|
|
298
338
|
gqlCapture.enable(true);
|
|
299
339
|
}
|
|
300
|
-
const [inputsRead, _, imports] = await Promise.all([
|
|
340
|
+
const [inputsRead, _, __, imports] = await Promise.all([
|
|
301
341
|
readInputs(),
|
|
302
342
|
captureCustom(options.path, options.files, options.json_path, gqlCapture),
|
|
343
|
+
captureDynamic(options.dynamic_path, gqlCapture),
|
|
303
344
|
parseImports(options.path),
|
|
304
345
|
]);
|
|
305
346
|
const { nodes, nodesMap } = inputsRead;
|