@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha100
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 +37 -31
- package/action/action.js +22 -7
- package/action/executor.d.ts +3 -3
- package/action/executor.js +8 -3
- package/action/experimental_action.d.ts +32 -22
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +40 -16
- package/action/orchestrator.js +230 -62
- package/action/privacy.d.ts +2 -2
- 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 +49 -26
- package/core/base.js +7 -1
- package/core/clause.d.ts +88 -7
- package/core/clause.js +355 -63
- package/core/config.d.ts +12 -1
- package/core/config.js +7 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +11 -8
- package/core/db.js +20 -8
- package/core/ent.d.ts +81 -25
- package/core/ent.js +636 -193
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.js +8 -11
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +6 -5
- package/core/loaders/object_loader.js +67 -59
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +52 -11
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +25 -24
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +7 -6
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +26 -0
- package/core/query/custom_clause_query.js +78 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +87 -12
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +8 -4
- package/core/query/query.js +101 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +35 -45
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +469 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.d.ts +14 -7
- package/graphql/graphql.js +23 -7
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +1 -4
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +1 -19
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +12 -5
- package/index.js +20 -7
- package/package.json +17 -16
- package/parse_schema/parse.d.ts +29 -9
- package/parse_schema/parse.js +118 -11
- package/schema/base_schema.d.ts +5 -3
- package/schema/base_schema.js +5 -0
- package/schema/field.d.ts +74 -20
- package/schema/field.js +174 -69
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +81 -18
- package/schema/schema.js +24 -17
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +57 -21
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +111 -30
- package/scripts/{transform_code.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/{transform_schema.d.ts → move_types.d.ts} +0 -0
- package/scripts/move_types.js +117 -0
- package/scripts/read_schema.js +20 -5
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +46 -47
- package/testutils/builder.js +108 -65
- 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} +24 -8
- package/testutils/db/{test_db.js → temp_db.js} +179 -44
- 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 +51 -6
- 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 +27 -8
- 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 +15 -8
- package/testutils/fake_data/fake_event.d.ts +5 -2
- package/testutils/fake_data/fake_event.js +9 -7
- 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 +7 -4
- package/testutils/fake_data/fake_user.js +18 -16
- 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 +43 -0
- package/testutils/fake_data/test_helpers.d.ts +11 -4
- package/testutils/fake_data/test_helpers.js +28 -12
- package/testutils/fake_data/user_query.d.ts +13 -6
- package/testutils/fake_data/user_query.js +54 -22
- 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 +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +26 -2
- package/tsc/ast.js +163 -17
- package/tsc/compilerOptions.d.ts +2 -1
- package/tsc/compilerOptions.js +11 -2
- 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 +181 -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 +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/{scripts → tsc}/transform_schema.js +145 -119
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/transform_code.js +0 -114
|
@@ -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];
|
|
@@ -26,12 +30,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
30
|
const glob_1 = __importDefault(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");
|
|
35
40
|
// need to use the GQLCapture from the package so that when we call GQLCapture.enable()
|
|
36
41
|
// we're affecting the local paths as opposed to a different instance
|
|
37
42
|
// life is hard
|
|
@@ -72,7 +77,7 @@ function processCustomObjects(l, gqlCapture, input) {
|
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
|
-
function transformArgs(f) {
|
|
80
|
+
function transformArgs(f, gqlCapture) {
|
|
76
81
|
return (f.args || []).map((v) => {
|
|
77
82
|
const ret = {
|
|
78
83
|
...v,
|
|
@@ -80,7 +85,7 @@ function transformArgs(f) {
|
|
|
80
85
|
// duplicated from getType in graphql.ts
|
|
81
86
|
if ((0, graphql_1.isCustomType)(ret.type)) {
|
|
82
87
|
ret.type = v.type.type;
|
|
83
|
-
(0, graphql_1.addCustomType)(v.type);
|
|
88
|
+
(0, graphql_1.addCustomType)(v.type, gqlCapture);
|
|
84
89
|
}
|
|
85
90
|
// scalar types not supported for now
|
|
86
91
|
ret.tsType = graphql_1.knownAllowedNames.get(v.type);
|
|
@@ -95,20 +100,24 @@ function transformResultType(f) {
|
|
|
95
100
|
type: f.resultType,
|
|
96
101
|
tsType: graphql_1.knownAllowedNames.get(f.resultType),
|
|
97
102
|
list: f.list,
|
|
103
|
+
connection: f.connection,
|
|
98
104
|
nullable: f.nullable,
|
|
99
105
|
},
|
|
100
106
|
]
|
|
101
107
|
: [];
|
|
102
108
|
}
|
|
103
|
-
function processTopLevel(l, l2) {
|
|
109
|
+
function processTopLevel(l, l2, gqlCapture) {
|
|
104
110
|
for (const custom of l) {
|
|
105
111
|
l2.push({
|
|
106
112
|
nodeName: custom.class,
|
|
107
113
|
functionName: custom.functionName || custom.name,
|
|
108
114
|
gqlName: custom.graphQLName || custom.name,
|
|
109
115
|
fieldType: custom.fieldType,
|
|
110
|
-
args: transformArgs(custom),
|
|
116
|
+
args: transformArgs(custom, gqlCapture),
|
|
111
117
|
results: transformResultType(custom),
|
|
118
|
+
description: custom.description,
|
|
119
|
+
extraImports: custom.extraImports,
|
|
120
|
+
functionContents: custom.functionContents,
|
|
112
121
|
});
|
|
113
122
|
}
|
|
114
123
|
}
|
|
@@ -121,12 +130,50 @@ function processCustomFields(fields, gqlCapture, nodeName) {
|
|
|
121
130
|
gqlName: f.graphQLName || f.name,
|
|
122
131
|
functionName: f.functionName || f.name,
|
|
123
132
|
fieldType: f.fieldType,
|
|
124
|
-
args: transformArgs(f),
|
|
133
|
+
args: transformArgs(f, gqlCapture),
|
|
125
134
|
results: transformResultType(f),
|
|
135
|
+
description: f.description,
|
|
126
136
|
});
|
|
127
137
|
}
|
|
128
138
|
m.set(nodeName, results);
|
|
129
139
|
}
|
|
140
|
+
async function captureDynamic(filePath, gqlCapture) {
|
|
141
|
+
if (!filePath) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
return await new Promise((resolve, reject) => {
|
|
145
|
+
// do we eventually need tsconfig-paths here or do we get it by default because child process?
|
|
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(), gqlCapture);
|
|
165
|
+
break;
|
|
166
|
+
case "mutations":
|
|
167
|
+
processTopLevel(v, gqlCapture.getCustomMutations(), gqlCapture);
|
|
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
|
+
}
|
|
130
177
|
async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
131
178
|
if (jsonPath !== undefined) {
|
|
132
179
|
let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
|
|
@@ -144,10 +191,15 @@ async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
|
144
191
|
processCustomObjects(json.objects, gqlCapture);
|
|
145
192
|
}
|
|
146
193
|
if (json.queries) {
|
|
147
|
-
processTopLevel(json.queries, gqlCapture.getCustomQueries());
|
|
194
|
+
processTopLevel(json.queries, gqlCapture.getCustomQueries(), gqlCapture);
|
|
148
195
|
}
|
|
149
196
|
if (json.mutations) {
|
|
150
|
-
processTopLevel(json.mutations, gqlCapture.getCustomMutations());
|
|
197
|
+
processTopLevel(json.mutations, gqlCapture.getCustomMutations(), gqlCapture);
|
|
198
|
+
}
|
|
199
|
+
if (json.customTypes) {
|
|
200
|
+
for (const k in json.customTypes) {
|
|
201
|
+
(0, graphql_1.addCustomType)(json.customTypes[k], gqlCapture);
|
|
202
|
+
}
|
|
151
203
|
}
|
|
152
204
|
return;
|
|
153
205
|
}
|
|
@@ -208,11 +260,27 @@ async function requireFiles(files) {
|
|
|
208
260
|
throw new Error(err);
|
|
209
261
|
});
|
|
210
262
|
}
|
|
263
|
+
// filePath is path-to-src
|
|
211
264
|
async function parseImports(filePath) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
265
|
+
return (0, imports_1.parseCustomImports)(filePath, [
|
|
266
|
+
{
|
|
267
|
+
// graphql files
|
|
268
|
+
root: path.join(filePath, "graphql"),
|
|
269
|
+
opts: {
|
|
270
|
+
ignore: ["**/generated/**", "**/tests/**"],
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
// can't just use top level ent files but have to check for all (non-generated) files
|
|
275
|
+
// in src/ent/* because custom edges (or other things) could have @gqlField etc
|
|
276
|
+
// and then have to look for these imports etc
|
|
277
|
+
root: path.join(filePath, "ent"),
|
|
278
|
+
opts: {
|
|
279
|
+
// not in action files since we can't customize payloads (yet?)
|
|
280
|
+
ignore: ["**/generated/**", "**/tests/**", "**/actions/**"],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
]);
|
|
216
284
|
}
|
|
217
285
|
function findGraphQLPath(filePath) {
|
|
218
286
|
while (filePath !== "/") {
|
|
@@ -227,21 +295,11 @@ function findGraphQLPath(filePath) {
|
|
|
227
295
|
}
|
|
228
296
|
return undefined;
|
|
229
297
|
}
|
|
298
|
+
// test as follows:
|
|
299
|
+
// there should be an easier way to do this...
|
|
300
|
+
// also, there should be a way to get the list of objects here that's not manual
|
|
301
|
+
//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
302
|
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
303
|
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
246
304
|
if (!options.path) {
|
|
247
305
|
throw new Error("path required");
|
|
@@ -266,9 +324,28 @@ async function main() {
|
|
|
266
324
|
gqlCapture = r.GQLCapture;
|
|
267
325
|
gqlCapture.enable(true);
|
|
268
326
|
}
|
|
269
|
-
|
|
327
|
+
// known custom types that are not required
|
|
328
|
+
// if not in the schema, will be ignored
|
|
329
|
+
// something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
|
|
330
|
+
// these 2 need this because they're added by the schema
|
|
331
|
+
// if this list grows too long, need to build this into golang types and passed here
|
|
332
|
+
// TODO foreign non-scalars eventually
|
|
333
|
+
(0, graphql_1.addCustomType)({
|
|
334
|
+
importPath: MODULE_PATH,
|
|
335
|
+
// for go tests...
|
|
336
|
+
// TODO need a flag that only does this for go tests
|
|
337
|
+
// breaks when running locally sometimes...
|
|
338
|
+
secondaryImportPath: "../graphql/scalars/time",
|
|
339
|
+
type: "GraphQLTime",
|
|
340
|
+
}, gqlCapture);
|
|
341
|
+
(0, graphql_1.addCustomType)({
|
|
342
|
+
importPath: "graphql-type-json",
|
|
343
|
+
type: "GraphQLJSON",
|
|
344
|
+
}, gqlCapture);
|
|
345
|
+
const [inputsRead, _, __, imports] = await Promise.all([
|
|
270
346
|
readInputs(),
|
|
271
347
|
captureCustom(options.path, options.files, options.json_path, gqlCapture),
|
|
348
|
+
captureDynamic(options.dynamic_path, gqlCapture),
|
|
272
349
|
parseImports(options.path),
|
|
273
350
|
]);
|
|
274
351
|
const { nodes, nodesMap } = inputsRead;
|
|
@@ -325,7 +402,7 @@ async function main() {
|
|
|
325
402
|
};
|
|
326
403
|
const buildClasses = (fields) => {
|
|
327
404
|
fields.forEach((field) => {
|
|
328
|
-
if (!nodesMap.has(field.nodeName)) {
|
|
405
|
+
if (field.nodeName && !nodesMap.has(field.nodeName)) {
|
|
329
406
|
let info = imports.getInfoForClass(field.nodeName);
|
|
330
407
|
classes[field.nodeName] = { ...info.class, path: info.file.path };
|
|
331
408
|
buildFiles(info.file);
|
|
@@ -336,6 +413,10 @@ async function main() {
|
|
|
336
413
|
};
|
|
337
414
|
buildClasses(mutations);
|
|
338
415
|
buildClasses(queries);
|
|
416
|
+
// call for every field in a node
|
|
417
|
+
for (const k in fields) {
|
|
418
|
+
buildClasses(fields[k]);
|
|
419
|
+
}
|
|
339
420
|
console.log(JSON.stringify({
|
|
340
421
|
args,
|
|
341
422
|
inputs,
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
7
|
+
const transform_1 = require("../tsc/transform");
|
|
8
|
+
const transform_schema_1 = require("../tsc/transform_schema");
|
|
9
|
+
const transform_ent_1 = require("../tsc/transform_ent");
|
|
10
|
+
const move_generated_1 = require("../tsc/move_generated");
|
|
11
|
+
const transform_action_1 = require("../tsc/transform_action");
|
|
12
|
+
const ast_1 = require("../tsc/ast");
|
|
13
|
+
// todo-sqlite
|
|
14
|
+
// ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/migrate_v0.1.ts --transform_schema --old_base_class BaseEntTodoSchema --new_schema_class TodoEntSchema --transform_path src/schema/patterns/base
|
|
15
|
+
function main() {
|
|
16
|
+
const customInfo = (0, ast_1.getCustomInfo)();
|
|
17
|
+
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
18
|
+
// install 0.1.x dependencies
|
|
19
|
+
// maybe provide options to make this easier if someone wants to do this in steps to see what's happening
|
|
20
|
+
if (options.move_generated) {
|
|
21
|
+
(0, move_generated_1.moveGenerated)(customInfo.relativeImports);
|
|
22
|
+
}
|
|
23
|
+
// codegen write-all --disable-custom-graphql
|
|
24
|
+
if (options.transform_schema) {
|
|
25
|
+
(0, transform_1.transform)(new transform_schema_1.TransformSchema(customInfo.relativeImports, options.old_base_class, options.new_schema_class, options.transform_path));
|
|
26
|
+
}
|
|
27
|
+
// codegen write-all --disable-custom-graphql
|
|
28
|
+
if (options.transform_ent) {
|
|
29
|
+
(0, transform_1.transform)(new transform_ent_1.TransformEnt());
|
|
30
|
+
}
|
|
31
|
+
if (options.transform_action) {
|
|
32
|
+
(0, transform_1.transform)(new transform_action_1.TransformAction(customInfo));
|
|
33
|
+
}
|
|
34
|
+
// codegen write-all
|
|
35
|
+
}
|
|
36
|
+
main();
|
|
File without changes
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const transform_1 = require("../tsc/transform");
|
|
30
|
+
const ast_1 = require("../tsc/ast");
|
|
31
|
+
const typescript_1 = __importStar(require("typescript"));
|
|
32
|
+
const path_1 = __importDefault(require("path"));
|
|
33
|
+
class GatherExportsInGeneratedTypes {
|
|
34
|
+
constructor() {
|
|
35
|
+
this.glob = "src/ent/generated/types.ts";
|
|
36
|
+
this.names = [];
|
|
37
|
+
}
|
|
38
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
39
|
+
const exported = node.modifiers?.filter((mod) => mod.getText(sourceFile) === "export");
|
|
40
|
+
if (exported?.length) {
|
|
41
|
+
if (typescript_1.default.isEnumDeclaration(node) ||
|
|
42
|
+
typescript_1.default.isInterfaceDeclaration(node) ||
|
|
43
|
+
typescript_1.default.isTypeAliasDeclaration(node)) {
|
|
44
|
+
this.names.push(node.name.text);
|
|
45
|
+
}
|
|
46
|
+
if (typescript_1.default.isFunctionDeclaration(node) && node.name?.text) {
|
|
47
|
+
this.names.push(node.name.text);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { node };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class TransformImports {
|
|
54
|
+
constructor() {
|
|
55
|
+
this.glob = "src/**/*.ts";
|
|
56
|
+
this.prettierGlob = "src/**/*.ts";
|
|
57
|
+
this.impsToMove = new Map();
|
|
58
|
+
this.cwd = "";
|
|
59
|
+
this.relative = false;
|
|
60
|
+
this.cwd = process.cwd();
|
|
61
|
+
const gt = new GatherExportsInGeneratedTypes();
|
|
62
|
+
(0, transform_1.transform)(gt);
|
|
63
|
+
gt.names.forEach((v) => this.impsToMove.set(v, true));
|
|
64
|
+
this.relative = (0, ast_1.getCustomInfo)().relativeImports ?? this.relative;
|
|
65
|
+
}
|
|
66
|
+
getSrcPath(file, text) {
|
|
67
|
+
if (text.startsWith("src")) {
|
|
68
|
+
return text;
|
|
69
|
+
}
|
|
70
|
+
const dir = path_1.default.dirname(path_1.default.join(this.cwd, file));
|
|
71
|
+
const fullPath = path_1.default.join(dir, text);
|
|
72
|
+
return path_1.default.relative(this.cwd, fullPath);
|
|
73
|
+
}
|
|
74
|
+
traverseChild(sourceFile, contents, file, node) {
|
|
75
|
+
if (!(0, typescript_1.isImportDeclaration)(node)) {
|
|
76
|
+
return { node };
|
|
77
|
+
}
|
|
78
|
+
const impInfo = (0, ast_1.getImportInfo)(node, sourceFile);
|
|
79
|
+
if (!impInfo) {
|
|
80
|
+
return { node };
|
|
81
|
+
}
|
|
82
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
83
|
+
const pathToWrite = (0, ast_1.transformRelative)(file, "src/ent/generated/types", this.relative);
|
|
84
|
+
const current = (0, ast_1.transformRelative)(file, text, this.relative);
|
|
85
|
+
const srcPath = this.getSrcPath(file, text);
|
|
86
|
+
// nothing to do here
|
|
87
|
+
if (!srcPath.startsWith("src/ent") || pathToWrite === current) {
|
|
88
|
+
return { node };
|
|
89
|
+
}
|
|
90
|
+
// let's see if we can simplify
|
|
91
|
+
let seenImports = [];
|
|
92
|
+
for (let imp of impInfo.imports) {
|
|
93
|
+
imp = imp.trim();
|
|
94
|
+
if (this.impsToMove.has(imp)) {
|
|
95
|
+
seenImports.push(imp);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!seenImports.length) {
|
|
99
|
+
return { node };
|
|
100
|
+
}
|
|
101
|
+
let imports = new Map([[pathToWrite, seenImports]]);
|
|
102
|
+
return {
|
|
103
|
+
rawString: (0, ast_1.transformImport)(contents, node, sourceFile, {
|
|
104
|
+
removeImports: seenImports,
|
|
105
|
+
transformPath: text,
|
|
106
|
+
}),
|
|
107
|
+
traversed: true,
|
|
108
|
+
imports,
|
|
109
|
+
allowSeenImportsAdded: true,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/move_types.ts
|
|
114
|
+
function main() {
|
|
115
|
+
(0, transform_1.transform)(new TransformImports());
|
|
116
|
+
}
|
|
117
|
+
main();
|
package/scripts/read_schema.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -26,20 +30,28 @@ const glob_1 = __importDefault(require("glob"));
|
|
|
26
30
|
const path = __importStar(require("path"));
|
|
27
31
|
const pascal_case_1 = require("pascal-case");
|
|
28
32
|
const minimist_1 = __importDefault(require("minimist"));
|
|
29
|
-
const process_1 = require("process");
|
|
30
33
|
const parse_1 = require("../parse_schema/parse");
|
|
34
|
+
const ast_1 = require("../tsc/ast");
|
|
31
35
|
function main() {
|
|
32
36
|
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
33
37
|
if (!options.path) {
|
|
34
38
|
throw new Error("path required");
|
|
35
39
|
}
|
|
40
|
+
const customInfo = (0, ast_1.getCustomInfo)();
|
|
41
|
+
const globalSchemaPath = customInfo.globalSchemaPath || "__global__schema.ts";
|
|
42
|
+
let globalSchema;
|
|
36
43
|
const r = /(\w+).ts/;
|
|
44
|
+
// do we still even need this...
|
|
37
45
|
const paths = glob_1.default.sync(path.join(options.path, "*.ts"), {
|
|
38
46
|
ignore: [`\d+_read_schema.ts`],
|
|
39
47
|
});
|
|
40
48
|
let potentialSchemas = {};
|
|
41
49
|
for (const p of paths) {
|
|
42
50
|
const basename = path.basename(p);
|
|
51
|
+
if (basename === globalSchemaPath) {
|
|
52
|
+
globalSchema = require(p).default;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
43
55
|
const match = r.exec(basename);
|
|
44
56
|
if (!match) {
|
|
45
57
|
throw new Error(`non-typescript file ${p} returned by glob`);
|
|
@@ -61,13 +73,16 @@ function main() {
|
|
|
61
73
|
potentialSchemas[(0, pascal_case_1.pascalCase)(schema)] = s;
|
|
62
74
|
}
|
|
63
75
|
// console.log(potentialSchemas);
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
// NB: do not change this to async/await
|
|
77
|
+
// doing so runs it buffer limit on linux (65536 bytes) and we lose data reading in go
|
|
78
|
+
(0, parse_1.parseSchema)(potentialSchemas, globalSchema).then((result) => {
|
|
79
|
+
console.log(JSON.stringify(result));
|
|
80
|
+
});
|
|
66
81
|
}
|
|
67
82
|
try {
|
|
68
83
|
main();
|
|
69
84
|
}
|
|
70
85
|
catch (err) {
|
|
71
86
|
console.error(err);
|
|
72
|
-
|
|
87
|
+
process.exit(1);
|
|
73
88
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Ent, ID, Viewer, Data } from "../../core/base";
|
|
2
|
+
import { DataOperation } from "../../core/ent";
|
|
3
|
+
import { Action, Builder, Executor, WriteOperation, Trigger, Observer, TriggerReturn } from "../../action/action";
|
|
4
|
+
import { EdgeInputData } from "../../action/orchestrator";
|
|
5
|
+
import { User, Group, Message, Contact, SimpleBuilder, BuilderSchema, SimpleAction, BaseEnt } from "../../testutils/builder";
|
|
6
|
+
import { MockLogs } from "../../testutils/mock_log";
|
|
7
|
+
import { Table } from "../db/temp_db";
|
|
8
|
+
export declare function setupTest(): void;
|
|
9
|
+
export declare function getML(): MockLogs;
|
|
10
|
+
export declare function getOperations(): DataOperation<Ent<Viewer<Ent<any> | null, ID | null>>>[];
|
|
11
|
+
export declare const UserSchema: BuilderSchema<User>;
|
|
12
|
+
export declare class UserWithBalance extends User {
|
|
13
|
+
}
|
|
14
|
+
export declare const UserBalanceSchema: BuilderSchema<UserWithBalance>;
|
|
15
|
+
export declare class UserWithBalanceWithCheck extends UserWithBalance {
|
|
16
|
+
}
|
|
17
|
+
export declare const UserBalanceWithCheckSchema: BuilderSchema<UserWithBalanceWithCheck>;
|
|
18
|
+
export declare class Account extends BaseEnt {
|
|
19
|
+
accountID: string;
|
|
20
|
+
nodeType: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const AccountSchema: BuilderSchema<Account>;
|
|
23
|
+
export declare const ContactSchema: BuilderSchema<Contact>;
|
|
24
|
+
export declare const GroupSchema: BuilderSchema<Group>;
|
|
25
|
+
export declare class GroupMembership extends BaseEnt {
|
|
26
|
+
nodeType: string;
|
|
27
|
+
}
|
|
28
|
+
export declare const GroupMembershipSchema: BuilderSchema<GroupMembership>;
|
|
29
|
+
export declare class Changelog extends BaseEnt {
|
|
30
|
+
nodeType: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const ChangelogSchema: BuilderSchema<Changelog>;
|
|
33
|
+
export declare const MessageSchema: BuilderSchema<Message>;
|
|
34
|
+
export declare function executeAction<T extends Ent, E = any>(action: Action<T, Builder<T>>, name?: E): Promise<Executor>;
|
|
35
|
+
export declare function createGroup(): Promise<Group>;
|
|
36
|
+
export declare function createUser(): Promise<User>;
|
|
37
|
+
export declare class MessageAction extends SimpleAction<Message> {
|
|
38
|
+
constructor(viewer: Viewer, fields: Map<string, any>, operation: WriteOperation, existingEnt: Message | null);
|
|
39
|
+
getTriggers(): Trigger<Message, SimpleBuilder<Message, Message | null>>[];
|
|
40
|
+
getObservers(): Observer<Message, SimpleBuilder<Message>>[];
|
|
41
|
+
}
|
|
42
|
+
export declare class UserAction extends SimpleAction<User> {
|
|
43
|
+
contactAction: SimpleAction<Contact> | undefined;
|
|
44
|
+
constructor(viewer: Viewer, fields: Map<string, any>, operation: WriteOperation, existingEnt: User | null);
|
|
45
|
+
getTriggers(): Trigger<User, SimpleBuilder<User>>[];
|
|
46
|
+
getObservers(): Observer<User, SimpleBuilder<User>>[];
|
|
47
|
+
}
|
|
48
|
+
type getMembershipFunction = (viewer: Viewer, edge: EdgeInputData) => SimpleAction<Ent>;
|
|
49
|
+
export declare class GroupMembershipTrigger implements Trigger<Group, SimpleBuilder<Group>> {
|
|
50
|
+
private getter;
|
|
51
|
+
constructor(getter: getMembershipFunction);
|
|
52
|
+
changeset(builder: SimpleBuilder<Group>, input: Data): TriggerReturn;
|
|
53
|
+
}
|
|
54
|
+
export declare class EditGroupAction extends SimpleAction<Group> {
|
|
55
|
+
viewer: Viewer;
|
|
56
|
+
private getter;
|
|
57
|
+
constructor(viewer: Viewer, schema: BuilderSchema<Group>, fields: Map<string, any>, existingEnt: Group, getter: getMembershipFunction);
|
|
58
|
+
getTriggers: () => GroupMembershipTrigger[];
|
|
59
|
+
}
|
|
60
|
+
export declare function verifyGroupMembers(group: Group, members: User[]): Promise<ID[]>;
|
|
61
|
+
export declare function loadMemberships(viewer: Viewer, membershipids: ID[]): Promise<GroupMembership[]>;
|
|
62
|
+
export declare function loadChangelogs(viewer: Viewer, clids: ID[]): Promise<Changelog[]>;
|
|
63
|
+
export declare function verifyChangelogFromMeberships(user: User, memberships: GroupMembership[]): Promise<void>;
|
|
64
|
+
export declare class GroupMemberOf extends BaseEnt {
|
|
65
|
+
nodeType: string;
|
|
66
|
+
}
|
|
67
|
+
export declare const GroupMemberOfSchema: BuilderSchema<GroupMemberOf>;
|
|
68
|
+
export declare const getTables: () => Table[];
|
|
69
|
+
export {};
|