@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/struct_field.js
CHANGED
|
@@ -1,44 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StructListType = exports.StructType = exports.StructField = void 0;
|
|
3
|
+
exports.StructTypeAsList = exports.StructListType = exports.StructType = exports.StructField = void 0;
|
|
4
|
+
const camel_case_1 = require("camel-case");
|
|
4
5
|
const field_1 = require("./field");
|
|
5
6
|
const schema_1 = require("./schema");
|
|
6
|
-
const
|
|
7
|
+
const global_schema_1 = require("../core/global_schema");
|
|
8
|
+
const logger_1 = require("../core/logger");
|
|
7
9
|
class StructField extends field_1.BaseField {
|
|
8
|
-
constructor(options) {
|
|
10
|
+
constructor(options, jsonAsList) {
|
|
9
11
|
super();
|
|
10
12
|
this.options = options;
|
|
13
|
+
this.jsonAsList = jsonAsList;
|
|
11
14
|
this.type = {
|
|
12
15
|
dbType: schema_1.DBType.JSONB,
|
|
13
16
|
};
|
|
14
17
|
this.type.subFields = options.fields;
|
|
15
18
|
this.type.type = options.tsType;
|
|
16
19
|
this.type.graphQLType = options.graphQLType || options.tsType;
|
|
20
|
+
this.type.globalType = this.options.globalType;
|
|
17
21
|
if (options.jsonNotJSONB) {
|
|
18
22
|
this.type.dbType = schema_1.DBType.JSON;
|
|
19
23
|
}
|
|
24
|
+
if (jsonAsList) {
|
|
25
|
+
this.type.listElemType = {
|
|
26
|
+
dbType: schema_1.DBType.JSONB,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
// this will lead to issues if field changes.
|
|
23
|
-
// TODO: use storageKey and convert back...
|
|
24
|
-
format(obj, nested) {
|
|
30
|
+
formatImpl(obj, nested) {
|
|
25
31
|
if (!(obj instanceof Object)) {
|
|
26
32
|
throw new Error("valid was not called");
|
|
27
33
|
}
|
|
28
34
|
let ret = {};
|
|
29
35
|
for (const k in this.options.fields) {
|
|
36
|
+
const field = this.options.fields[k];
|
|
37
|
+
// check two values
|
|
38
|
+
// store in dbKey format
|
|
30
39
|
// TODO more #510
|
|
31
|
-
let dbKey = (0,
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
if (val === undefined && obj[
|
|
35
|
-
val = obj[
|
|
36
|
-
dbKey = k;
|
|
40
|
+
let dbKey = (0, schema_1.getStorageKey)(field, k);
|
|
41
|
+
let camelKey = (0, camel_case_1.camelCase)(k);
|
|
42
|
+
let val = obj[camelKey];
|
|
43
|
+
if (val === undefined && obj[dbKey] !== undefined) {
|
|
44
|
+
val = obj[dbKey];
|
|
37
45
|
}
|
|
38
46
|
if (val === undefined) {
|
|
39
47
|
continue;
|
|
40
48
|
}
|
|
41
|
-
const field = this.options.fields[k];
|
|
42
49
|
if (field.format) {
|
|
43
50
|
// indicate nested so this isn't JSON stringified
|
|
44
51
|
ret[dbKey] = field.format(val, true);
|
|
@@ -47,13 +54,53 @@ class StructField extends field_1.BaseField {
|
|
|
47
54
|
ret[dbKey] = val;
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
|
-
// don't json.stringify if nested
|
|
57
|
+
// don't json.stringify if nested or list
|
|
51
58
|
if (nested) {
|
|
52
59
|
return ret;
|
|
53
60
|
}
|
|
54
61
|
return JSON.stringify(ret);
|
|
55
62
|
}
|
|
56
|
-
|
|
63
|
+
format(obj, nested) {
|
|
64
|
+
if (this.type.globalType) {
|
|
65
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
66
|
+
if (f && f.format) {
|
|
67
|
+
if (JSON.stringify(this.type.listElemType) !==
|
|
68
|
+
JSON.stringify(f?.type.listElemType)) {
|
|
69
|
+
if (this.jsonAsList) {
|
|
70
|
+
// handle as nested
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
const formatted = obj.map((v) => f.format(v, true));
|
|
73
|
+
if (nested) {
|
|
74
|
+
return formatted;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return JSON.stringify(formatted);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const formatted = f.format([obj], true);
|
|
82
|
+
if (nested) {
|
|
83
|
+
return formatted[0];
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return JSON.stringify(formatted[0]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// TODO handle format code
|
|
91
|
+
return f.format(obj);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(obj) && this.jsonAsList) {
|
|
95
|
+
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
96
|
+
if (nested) {
|
|
97
|
+
return ret;
|
|
98
|
+
}
|
|
99
|
+
return JSON.stringify(ret);
|
|
100
|
+
}
|
|
101
|
+
return this.formatImpl(obj, nested);
|
|
102
|
+
}
|
|
103
|
+
async validImpl(obj) {
|
|
57
104
|
if (!(obj instanceof Object)) {
|
|
58
105
|
return false;
|
|
59
106
|
}
|
|
@@ -63,12 +110,11 @@ class StructField extends field_1.BaseField {
|
|
|
63
110
|
for (const k in this.options.fields) {
|
|
64
111
|
const field = this.options.fields[k];
|
|
65
112
|
// TODO more #510
|
|
66
|
-
let dbKey = (0,
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
if (val === undefined && obj[
|
|
70
|
-
val = obj[
|
|
71
|
-
dbKey = k;
|
|
113
|
+
let dbKey = (0, schema_1.getStorageKey)(field, k);
|
|
114
|
+
let camelKey = (0, camel_case_1.camelCase)(k);
|
|
115
|
+
let val = obj[camelKey];
|
|
116
|
+
if (val === undefined && obj[dbKey] !== undefined) {
|
|
117
|
+
val = obj[dbKey];
|
|
72
118
|
}
|
|
73
119
|
if (val === undefined || val === null) {
|
|
74
120
|
// nullable, nothing to do here
|
|
@@ -89,6 +135,47 @@ class StructField extends field_1.BaseField {
|
|
|
89
135
|
const ret = await Promise.all(promises);
|
|
90
136
|
return ret.every((v) => v);
|
|
91
137
|
}
|
|
138
|
+
async valid(obj) {
|
|
139
|
+
if (this.type.globalType) {
|
|
140
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
141
|
+
// list and global type is not valid.
|
|
142
|
+
if (f) {
|
|
143
|
+
if (f.valid) {
|
|
144
|
+
if (JSON.stringify(this.type.listElemType) !==
|
|
145
|
+
JSON.stringify(f?.type.listElemType)) {
|
|
146
|
+
if (this.jsonAsList) {
|
|
147
|
+
if (!Array.isArray(obj)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
const valid = await Promise.all(obj.map((v) => f.valid(v)));
|
|
152
|
+
return valid.every((b) => b);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return f.valid([obj]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return f.valid(obj);
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (this.jsonAsList) {
|
|
168
|
+
if (!Array.isArray(obj)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
|
|
172
|
+
return valid.every((b) => b);
|
|
173
|
+
}
|
|
174
|
+
if (!(obj instanceof Object)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return this.validImpl(obj);
|
|
178
|
+
}
|
|
92
179
|
}
|
|
93
180
|
exports.StructField = StructField;
|
|
94
181
|
function StructType(options) {
|
|
@@ -96,7 +183,15 @@ function StructType(options) {
|
|
|
96
183
|
return Object.assign(result, options);
|
|
97
184
|
}
|
|
98
185
|
exports.StructType = StructType;
|
|
186
|
+
/**
|
|
187
|
+
* @deprecated use StructTypeAsList
|
|
188
|
+
*/
|
|
99
189
|
function StructListType(options) {
|
|
100
190
|
return new field_1.ListField(StructType(options), options);
|
|
101
191
|
}
|
|
102
192
|
exports.StructListType = StructListType;
|
|
193
|
+
function StructTypeAsList(options) {
|
|
194
|
+
let result = new StructField(options, true);
|
|
195
|
+
return Object.assign(result, options);
|
|
196
|
+
}
|
|
197
|
+
exports.StructTypeAsList = StructTypeAsList;
|
package/schema/union_field.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class UnionField extends BaseField implements FieldOptions {
|
|
|
15
15
|
type: Type;
|
|
16
16
|
m: Map<Object, string>;
|
|
17
17
|
constructor(options: UnionOptions);
|
|
18
|
-
format(obj: any):
|
|
18
|
+
format(obj: any): any;
|
|
19
19
|
private validField;
|
|
20
20
|
valid(obj: any): Promise<boolean>;
|
|
21
21
|
}
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
|
@@ -25,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
30
|
const typescript_1 = __importDefault(require("typescript"));
|
|
27
31
|
const path = __importStar(require("path"));
|
|
28
|
-
const
|
|
32
|
+
const glob = __importStar(require("glob"));
|
|
29
33
|
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
30
34
|
// TODO this should probably be its own package but for now it's here
|
|
31
35
|
class Compiler {
|
|
@@ -193,7 +197,7 @@ class Compiler {
|
|
|
193
197
|
}
|
|
194
198
|
relPath = path.relative(
|
|
195
199
|
// just because of how imports work. it's relative from directory not current path
|
|
196
|
-
path.dirname(fullPath), path.join(text.
|
|
200
|
+
path.dirname(fullPath), path.join(text.substring(0, idx).replace(r, str.substring(0, strIdx)), text.substring(idx)));
|
|
197
201
|
// if file ends with "..", we've reached a case where we're trying to
|
|
198
202
|
// import something like foo/contact(.ts) from within foo/contact/bar/baz/page.ts
|
|
199
203
|
// and we're confused about it so we need to detect that case and handle it
|
|
@@ -204,7 +208,7 @@ class Compiler {
|
|
|
204
208
|
let text2 = text + ".ts";
|
|
205
209
|
relPath = path.relative(
|
|
206
210
|
// just because of how imports work. it's relative from directory not current path
|
|
207
|
-
path.dirname(fullPath), path.join(text2.
|
|
211
|
+
path.dirname(fullPath), path.join(text2.substring(0, idx).replace(r, str.substring(0, strIdx)), text2.substring(idx)));
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
214
|
if (!relPath.startsWith("..")) {
|
|
@@ -213,7 +217,7 @@ class Compiler {
|
|
|
213
217
|
// tsc removes this by default so we need to also do it
|
|
214
218
|
let tsIdx = relPath.indexOf(".ts");
|
|
215
219
|
if (tsIdx !== -1) {
|
|
216
|
-
relPath = relPath.
|
|
220
|
+
relPath = relPath.substring(0, tsIdx);
|
|
217
221
|
}
|
|
218
222
|
return relPath;
|
|
219
223
|
}
|
|
@@ -225,7 +229,7 @@ class Compiler {
|
|
|
225
229
|
let relPath = checkPath(paths, text);
|
|
226
230
|
if (relPath) {
|
|
227
231
|
// update the node...
|
|
228
|
-
return typescript_1.default.updateImportDeclaration(importNode, importNode.
|
|
232
|
+
return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.modifiers, importNode.importClause, typescript_1.default.factory.createStringLiteral(relPath), importNode.assertClause);
|
|
229
233
|
}
|
|
230
234
|
}
|
|
231
235
|
if (node.kind === typescript_1.default.SyntaxKind.ExportDeclaration) {
|
|
@@ -235,7 +239,7 @@ class Compiler {
|
|
|
235
239
|
let relPath = checkPath(paths, text);
|
|
236
240
|
if (relPath) {
|
|
237
241
|
// update the node...
|
|
238
|
-
return typescript_1.default.updateExportDeclaration(exportNode, exportNode.
|
|
242
|
+
return typescript_1.default.factory.updateExportDeclaration(exportNode, exportNode.modifiers, exportNode.isTypeOnly, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.assertClause);
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
}
|
|
@@ -261,6 +265,6 @@ class Compiler {
|
|
|
261
265
|
// todo this should be configurable
|
|
262
266
|
// TODO this should be broken into its own repo and npm module
|
|
263
267
|
// TODO use includes and exclude in tsconfig.json if it exists
|
|
264
|
-
new Compiler(
|
|
268
|
+
new Compiler(glob.sync("**/*.ts", {
|
|
265
269
|
ignore: ["node_modules/**", "tests/**", "**/*.test.ts"],
|
|
266
270
|
}), ["node_modules/@types/node"]).compile();
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
|
@@ -23,19 +27,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
28
|
};
|
|
25
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const
|
|
30
|
+
const glob = __importStar(require("glob"));
|
|
27
31
|
const json5_1 = __importDefault(require("json5"));
|
|
28
32
|
const minimist_1 = __importDefault(require("minimist"));
|
|
29
|
-
const graphql_1 = require("../graphql/graphql");
|
|
30
|
-
const readline = __importStar(require("readline"));
|
|
31
33
|
const path = __importStar(require("path"));
|
|
32
34
|
const fs = __importStar(require("fs"));
|
|
35
|
+
const graphql_1 = require("../graphql/graphql");
|
|
36
|
+
const readline = __importStar(require("readline"));
|
|
33
37
|
const imports_1 = require("../imports");
|
|
34
38
|
const process_1 = require("process");
|
|
39
|
+
const child_process_1 = require("child_process");
|
|
40
|
+
const const_1 = require("../core/const");
|
|
35
41
|
// need to use the GQLCapture from the package so that when we call GQLCapture.enable()
|
|
36
42
|
// we're affecting the local paths as opposed to a different instance
|
|
37
43
|
// life is hard
|
|
38
|
-
const MODULE_PATH =
|
|
44
|
+
const MODULE_PATH = const_1.GRAPHQL_PATH;
|
|
39
45
|
async function readInputs() {
|
|
40
46
|
return await new Promise((resolve) => {
|
|
41
47
|
const rl = readline.createInterface({
|
|
@@ -54,14 +60,7 @@ async function readInputs() {
|
|
|
54
60
|
});
|
|
55
61
|
});
|
|
56
62
|
}
|
|
57
|
-
function processCustomObjects(l, gqlCapture,
|
|
58
|
-
let m;
|
|
59
|
-
if (input) {
|
|
60
|
-
m = gqlCapture.getCustomInputObjects();
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
m = gqlCapture.getCustomObjects();
|
|
64
|
-
}
|
|
63
|
+
function processCustomObjects(l, gqlCapture, m) {
|
|
65
64
|
for (const input of l) {
|
|
66
65
|
m.set(input.name, {
|
|
67
66
|
nodeName: input.graphQLName || input.name,
|
|
@@ -72,7 +71,7 @@ function processCustomObjects(l, gqlCapture, input) {
|
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
|
-
function transformArgs(f) {
|
|
74
|
+
function transformArgs(f, gqlCapture) {
|
|
76
75
|
return (f.args || []).map((v) => {
|
|
77
76
|
const ret = {
|
|
78
77
|
...v,
|
|
@@ -80,13 +79,25 @@ function transformArgs(f) {
|
|
|
80
79
|
// duplicated from getType in graphql.ts
|
|
81
80
|
if ((0, graphql_1.isCustomType)(ret.type)) {
|
|
82
81
|
ret.type = v.type.type;
|
|
83
|
-
(0, graphql_1.addCustomType)(v.type);
|
|
82
|
+
(0, graphql_1.addCustomType)(v.type, gqlCapture);
|
|
84
83
|
}
|
|
85
84
|
// scalar types not supported for now
|
|
86
85
|
ret.tsType = graphql_1.knownAllowedNames.get(v.type);
|
|
87
86
|
return ret;
|
|
88
87
|
});
|
|
89
88
|
}
|
|
89
|
+
function transformFieldTypeInput(input) {
|
|
90
|
+
switch (input) {
|
|
91
|
+
case "ACCESSOR":
|
|
92
|
+
return graphql_1.CustomFieldType.Accessor;
|
|
93
|
+
case "ASYNC_FUNCTION":
|
|
94
|
+
return graphql_1.CustomFieldType.AsyncFunction;
|
|
95
|
+
case "FUNCTION":
|
|
96
|
+
return graphql_1.CustomFieldType.Function;
|
|
97
|
+
case "FIELD":
|
|
98
|
+
return graphql_1.CustomFieldType.Field;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
90
101
|
function transformResultType(f) {
|
|
91
102
|
return f.resultType
|
|
92
103
|
? [
|
|
@@ -95,60 +106,119 @@ function transformResultType(f) {
|
|
|
95
106
|
type: f.resultType,
|
|
96
107
|
tsType: graphql_1.knownAllowedNames.get(f.resultType),
|
|
97
108
|
list: f.list,
|
|
109
|
+
connection: f.connection,
|
|
98
110
|
nullable: f.nullable,
|
|
99
111
|
},
|
|
100
112
|
]
|
|
101
113
|
: [];
|
|
102
114
|
}
|
|
103
|
-
function processTopLevel(l, l2) {
|
|
115
|
+
function processTopLevel(l, l2, gqlCapture) {
|
|
104
116
|
for (const custom of l) {
|
|
105
117
|
l2.push({
|
|
106
|
-
nodeName: custom.class,
|
|
107
|
-
functionName: custom.functionName || custom.name,
|
|
108
|
-
gqlName: custom.graphQLName || custom.name,
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
nodeName: custom.class ?? "",
|
|
119
|
+
functionName: custom.functionName || custom.name || "",
|
|
120
|
+
gqlName: custom.graphQLName || custom.name || "",
|
|
121
|
+
edgeName: custom.edgeName,
|
|
122
|
+
fieldType: transformFieldTypeInput(custom.fieldType),
|
|
123
|
+
args: transformArgs(custom, gqlCapture),
|
|
111
124
|
results: transformResultType(custom),
|
|
125
|
+
description: custom.description,
|
|
126
|
+
extraImports: custom.extraImports,
|
|
127
|
+
functionContents: custom.functionContents,
|
|
112
128
|
});
|
|
113
129
|
}
|
|
114
130
|
}
|
|
131
|
+
function processCustomTypes(m, gqlCapture) {
|
|
132
|
+
for (const k in m) {
|
|
133
|
+
(0, graphql_1.addCustomType)(m[k], gqlCapture);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
115
136
|
function processCustomFields(fields, gqlCapture, nodeName) {
|
|
116
137
|
const m = gqlCapture.getCustomFields();
|
|
117
138
|
let results = [];
|
|
118
139
|
for (const f of fields) {
|
|
119
140
|
results.push({
|
|
120
141
|
nodeName: nodeName,
|
|
121
|
-
gqlName: f.graphQLName || f.name,
|
|
122
|
-
functionName: f.functionName || f.name,
|
|
123
|
-
fieldType: f.fieldType,
|
|
124
|
-
args: transformArgs(f),
|
|
142
|
+
gqlName: f.graphQLName || f.name || "",
|
|
143
|
+
functionName: f.functionName || f.name || "",
|
|
144
|
+
fieldType: transformFieldTypeInput(f.fieldType),
|
|
145
|
+
args: transformArgs(f, gqlCapture),
|
|
125
146
|
results: transformResultType(f),
|
|
147
|
+
description: f.description,
|
|
126
148
|
});
|
|
127
149
|
}
|
|
128
150
|
m.set(nodeName, results);
|
|
129
151
|
}
|
|
152
|
+
async function captureDynamic(filePath, gqlCapture) {
|
|
153
|
+
if (!filePath) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
let args = [];
|
|
158
|
+
const env = {
|
|
159
|
+
...process.env,
|
|
160
|
+
};
|
|
161
|
+
// really only exists if there's a bug with swc or something. we should almost always be using swc
|
|
162
|
+
if (process.env.DISABLE_SWC) {
|
|
163
|
+
args = ["--transpileOnly", filePath];
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
args = ["--swc", filePath];
|
|
167
|
+
// we seem to get tsconfig-paths by default because child process but not 100% sure...
|
|
168
|
+
env.SWCRC = "true";
|
|
169
|
+
}
|
|
170
|
+
const r = (0, child_process_1.spawn)("ts-node", args, {
|
|
171
|
+
env,
|
|
172
|
+
});
|
|
173
|
+
const datas = [];
|
|
174
|
+
r.stdout.on("data", (data) => {
|
|
175
|
+
datas.push(data.toString());
|
|
176
|
+
});
|
|
177
|
+
r.stderr.on("data", (data) => {
|
|
178
|
+
reject(new Error(data.toString()));
|
|
179
|
+
});
|
|
180
|
+
r.on("close", (code) => {
|
|
181
|
+
if (code !== 0) {
|
|
182
|
+
reject(new Error(`error code ${code} on dynamic path`));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
let json = json5_1.default.parse(datas.join(""));
|
|
186
|
+
processJSON(gqlCapture, json);
|
|
187
|
+
resolve(undefined);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async function processJSON(gqlCapture, json) {
|
|
192
|
+
if (json.fields) {
|
|
193
|
+
for (const k in json.fields) {
|
|
194
|
+
processCustomFields(json.fields[k], gqlCapture, k);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (json.inputs) {
|
|
198
|
+
processCustomObjects(json.inputs, gqlCapture, gqlCapture.getCustomInputObjects());
|
|
199
|
+
}
|
|
200
|
+
if (json.objects) {
|
|
201
|
+
processCustomObjects(json.objects, gqlCapture, gqlCapture.getCustomObjects());
|
|
202
|
+
}
|
|
203
|
+
if (json.args) {
|
|
204
|
+
processCustomObjects(json.args, gqlCapture, gqlCapture.getCustomArgs());
|
|
205
|
+
}
|
|
206
|
+
if (json.queries) {
|
|
207
|
+
processTopLevel(json.queries, gqlCapture.getCustomQueries(), gqlCapture);
|
|
208
|
+
}
|
|
209
|
+
if (json.mutations) {
|
|
210
|
+
processTopLevel(json.mutations, gqlCapture.getCustomMutations(), gqlCapture);
|
|
211
|
+
}
|
|
212
|
+
if (json.customTypes) {
|
|
213
|
+
processCustomTypes(json.customTypes, gqlCapture);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
130
216
|
async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
131
217
|
if (jsonPath !== undefined) {
|
|
132
218
|
let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
|
|
133
219
|
encoding: "utf8",
|
|
134
220
|
}));
|
|
135
|
-
|
|
136
|
-
for (const k in json.fields) {
|
|
137
|
-
processCustomFields(json.fields[k], gqlCapture, k);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (json.inputs) {
|
|
141
|
-
processCustomObjects(json.inputs, gqlCapture, true);
|
|
142
|
-
}
|
|
143
|
-
if (json.objects) {
|
|
144
|
-
processCustomObjects(json.objects, gqlCapture);
|
|
145
|
-
}
|
|
146
|
-
if (json.queries) {
|
|
147
|
-
processTopLevel(json.queries, gqlCapture.getCustomQueries());
|
|
148
|
-
}
|
|
149
|
-
if (json.mutations) {
|
|
150
|
-
processTopLevel(json.mutations, gqlCapture.getCustomMutations());
|
|
151
|
-
}
|
|
221
|
+
processJSON(gqlCapture, json);
|
|
152
222
|
return;
|
|
153
223
|
}
|
|
154
224
|
if (filesCsv !== undefined) {
|
|
@@ -178,12 +248,12 @@ async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
|
178
248
|
// ignore test files.
|
|
179
249
|
"**/*.test.ts",
|
|
180
250
|
];
|
|
181
|
-
const customGQLResolvers =
|
|
251
|
+
const customGQLResolvers = glob.sync(path.join(filePath, "/graphql/resolvers/**/*.ts"), {
|
|
182
252
|
// no actions for now to speed things up
|
|
183
253
|
// no index.ts or internal file.
|
|
184
254
|
ignore: ignore,
|
|
185
255
|
});
|
|
186
|
-
const customGQLMutations =
|
|
256
|
+
const customGQLMutations = glob.sync(path.join(filePath, "/graphql/mutations/**/*.ts"), {
|
|
187
257
|
// no actions for now to speed things up
|
|
188
258
|
// no index.ts or internal file.
|
|
189
259
|
ignore: ignore,
|
|
@@ -208,11 +278,27 @@ async function requireFiles(files) {
|
|
|
208
278
|
throw new Error(err);
|
|
209
279
|
});
|
|
210
280
|
}
|
|
281
|
+
// filePath is path-to-src
|
|
211
282
|
async function parseImports(filePath) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
283
|
+
return (0, imports_1.parseCustomImports)(filePath, [
|
|
284
|
+
{
|
|
285
|
+
// graphql files
|
|
286
|
+
root: path.join(filePath, "graphql"),
|
|
287
|
+
opts: {
|
|
288
|
+
ignore: ["**/generated/**", "**/tests/**"],
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
// can't just use top level ent files but have to check for all (non-generated) files
|
|
293
|
+
// in src/ent/* because custom edges (or other things) could have @gqlField etc
|
|
294
|
+
// and then have to look for these imports etc
|
|
295
|
+
root: path.join(filePath, "ent"),
|
|
296
|
+
opts: {
|
|
297
|
+
// not in action files since we can't customize payloads (yet?)
|
|
298
|
+
ignore: ["**/generated/**", "**/tests/**", "**/actions/**"],
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
]);
|
|
216
302
|
}
|
|
217
303
|
function findGraphQLPath(filePath) {
|
|
218
304
|
while (filePath !== "/") {
|
|
@@ -227,21 +313,11 @@ function findGraphQLPath(filePath) {
|
|
|
227
313
|
}
|
|
228
314
|
return undefined;
|
|
229
315
|
}
|
|
316
|
+
// test as follows:
|
|
317
|
+
// there should be an easier way to do this...
|
|
318
|
+
// also, there should be a way to get the list of objects here that's not manual
|
|
319
|
+
//echo "User\nContact\nContactEmail\nComment" | ts-node-script --log-error --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/custom_graphql.ts --path ~/code/ent/examples/simple/src/
|
|
230
320
|
async function main() {
|
|
231
|
-
// known custom types that are not required
|
|
232
|
-
// if not in the schema, will be ignored
|
|
233
|
-
// something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
|
|
234
|
-
// these 2 need this because they're added by the schema
|
|
235
|
-
// if this list grows too long, need to build this into golang types and passed here
|
|
236
|
-
// TODO foreign non-scalars eventually
|
|
237
|
-
(0, graphql_1.addCustomType)({
|
|
238
|
-
importPath: "../graphql/scalars/time",
|
|
239
|
-
type: "GraphQLTime",
|
|
240
|
-
});
|
|
241
|
-
(0, graphql_1.addCustomType)({
|
|
242
|
-
importPath: "graphql-type-json",
|
|
243
|
-
type: "GraphQLJSON",
|
|
244
|
-
});
|
|
245
321
|
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
246
322
|
if (!options.path) {
|
|
247
323
|
throw new Error("path required");
|
|
@@ -266,9 +342,28 @@ async function main() {
|
|
|
266
342
|
gqlCapture = r.GQLCapture;
|
|
267
343
|
gqlCapture.enable(true);
|
|
268
344
|
}
|
|
269
|
-
|
|
345
|
+
// known custom types that are not required
|
|
346
|
+
// if not in the schema, will be ignored
|
|
347
|
+
// something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
|
|
348
|
+
// these 2 need this because they're added by the schema
|
|
349
|
+
// if this list grows too long, need to build this into golang types and passed here
|
|
350
|
+
// TODO foreign non-scalars eventually
|
|
351
|
+
(0, graphql_1.addCustomType)({
|
|
352
|
+
importPath: MODULE_PATH,
|
|
353
|
+
// for go tests...
|
|
354
|
+
// TODO need a flag that only does this for go tests
|
|
355
|
+
// breaks when running locally sometimes...
|
|
356
|
+
secondaryImportPath: "../graphql/scalars/time",
|
|
357
|
+
type: "GraphQLTime",
|
|
358
|
+
}, gqlCapture);
|
|
359
|
+
(0, graphql_1.addCustomType)({
|
|
360
|
+
importPath: "graphql-type-json",
|
|
361
|
+
type: "GraphQLJSON",
|
|
362
|
+
}, gqlCapture);
|
|
363
|
+
const [inputsRead, _, __, imports] = await Promise.all([
|
|
270
364
|
readInputs(),
|
|
271
365
|
captureCustom(options.path, options.files, options.json_path, gqlCapture),
|
|
366
|
+
captureDynamic(options.dynamic_path, gqlCapture),
|
|
272
367
|
parseImports(options.path),
|
|
273
368
|
]);
|
|
274
369
|
const { nodes, nodesMap } = inputsRead;
|
|
@@ -286,6 +381,8 @@ async function main() {
|
|
|
286
381
|
let queries = gqlCapture.getProcessedCustomQueries();
|
|
287
382
|
let mutations = gqlCapture.getProcessedCustomMutations();
|
|
288
383
|
let objects = fromMap(gqlCapture.getCustomObjects());
|
|
384
|
+
let interfaces = fromMap(gqlCapture.getCustomInterfaces());
|
|
385
|
+
let unions = fromMap(gqlCapture.getCustomUnions());
|
|
289
386
|
let customTypes = fromMap(gqlCapture.getCustomTypes());
|
|
290
387
|
let classes = {};
|
|
291
388
|
let allFiles = {};
|
|
@@ -325,7 +422,7 @@ async function main() {
|
|
|
325
422
|
};
|
|
326
423
|
const buildClasses = (fields) => {
|
|
327
424
|
fields.forEach((field) => {
|
|
328
|
-
if (!nodesMap.has(field.nodeName)) {
|
|
425
|
+
if (field.nodeName && !nodesMap.has(field.nodeName)) {
|
|
329
426
|
let info = imports.getInfoForClass(field.nodeName);
|
|
330
427
|
classes[field.nodeName] = { ...info.class, path: info.file.path };
|
|
331
428
|
buildFiles(info.file);
|
|
@@ -336,6 +433,10 @@ async function main() {
|
|
|
336
433
|
};
|
|
337
434
|
buildClasses(mutations);
|
|
338
435
|
buildClasses(queries);
|
|
436
|
+
// call for every field in a node
|
|
437
|
+
for (const k in fields) {
|
|
438
|
+
buildClasses(fields[k]);
|
|
439
|
+
}
|
|
339
440
|
console.log(JSON.stringify({
|
|
340
441
|
args,
|
|
341
442
|
inputs,
|
|
@@ -344,6 +445,8 @@ async function main() {
|
|
|
344
445
|
mutations,
|
|
345
446
|
classes,
|
|
346
447
|
objects,
|
|
448
|
+
interfaces,
|
|
449
|
+
unions,
|
|
347
450
|
files: allFiles,
|
|
348
451
|
customTypes,
|
|
349
452
|
}));
|