@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha91
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 +36 -31
- package/action/action.js +2 -6
- 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 +38 -16
- package/action/orchestrator.js +223 -61
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +45 -24
- package/core/base.js +7 -1
- package/core/clause.d.ts +83 -7
- package/core/clause.js +334 -63
- package/core/config.d.ts +8 -0
- package/core/config.js +5 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +2 -2
- package/core/db.js +6 -2
- package/core/ent.d.ts +79 -24
- package/core/ent.js +527 -176
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +14 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.js +5 -1
- 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 +26 -25
- 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 +34 -43
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +470 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.js +16 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/shared_edge_connection.js +1 -15
- package/imports/index.js +5 -1
- package/index.d.ts +11 -5
- package/index.js +20 -7
- package/package.json +1 -1
- package/parse_schema/parse.d.ts +12 -3
- package/parse_schema/parse.js +70 -11
- package/schema/base_schema.js +3 -0
- package/schema/field.d.ts +44 -8
- package/schema/field.js +136 -10
- 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 +66 -11
- package/schema/schema.js +18 -4
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +44 -5
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +13 -4
- 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 +20 -5
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +83 -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} +20 -7
- package/testutils/db/{test_db.js → temp_db.js} +102 -36
- package/testutils/db/value.d.ts +6 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.js +3 -1
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.js +8 -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 -4
- package/testutils/fake_data/fake_contact.js +14 -6
- package/testutils/fake_data/fake_event.d.ts +5 -3
- package/testutils/fake_data/fake_event.js +8 -5
- package/testutils/fake_data/fake_tag.d.ts +35 -0
- package/testutils/fake_data/fake_tag.js +88 -0
- package/testutils/fake_data/fake_user.d.ts +6 -4
- package/testutils/fake_data/fake_user.js +16 -13
- 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 +44 -0
- package/tsc/ast.js +271 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +45 -2
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +171 -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/tsc/transform_schema.js +383 -0
- package/scripts/transform_schema.js +0 -445
package/schema/struct_field.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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 camel_case_1 = require("camel-case");
|
|
7
7
|
class StructField extends field_1.BaseField {
|
|
8
8
|
constructor(options) {
|
|
9
9
|
super();
|
|
@@ -17,11 +17,16 @@ class StructField extends field_1.BaseField {
|
|
|
17
17
|
if (options.jsonNotJSONB) {
|
|
18
18
|
this.type.dbType = schema_1.DBType.JSON;
|
|
19
19
|
}
|
|
20
|
+
if (options?.jsonAsList) {
|
|
21
|
+
this.type.listElemType = {
|
|
22
|
+
dbType: schema_1.DBType.JSONB,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
// right now, we store things in the db in lowerCase format
|
|
22
27
|
// this will lead to issues if field changes.
|
|
23
28
|
// TODO: use storageKey and convert back...
|
|
24
|
-
|
|
29
|
+
formatImpl(obj, nested) {
|
|
25
30
|
if (!(obj instanceof Object)) {
|
|
26
31
|
throw new Error("valid was not called");
|
|
27
32
|
}
|
|
@@ -47,13 +52,23 @@ class StructField extends field_1.BaseField {
|
|
|
47
52
|
ret[dbKey] = val;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
|
-
// don't json.stringify if nested
|
|
55
|
+
// don't json.stringify if nested or list
|
|
51
56
|
if (nested) {
|
|
52
57
|
return ret;
|
|
53
58
|
}
|
|
54
59
|
return JSON.stringify(ret);
|
|
55
60
|
}
|
|
56
|
-
|
|
61
|
+
format(obj, nested) {
|
|
62
|
+
if (Array.isArray(obj) && this.options.jsonAsList) {
|
|
63
|
+
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
64
|
+
if (nested) {
|
|
65
|
+
return ret;
|
|
66
|
+
}
|
|
67
|
+
return JSON.stringify(ret);
|
|
68
|
+
}
|
|
69
|
+
return this.formatImpl(obj, nested);
|
|
70
|
+
}
|
|
71
|
+
async validImpl(obj) {
|
|
57
72
|
if (!(obj instanceof Object)) {
|
|
58
73
|
return false;
|
|
59
74
|
}
|
|
@@ -89,6 +104,19 @@ class StructField extends field_1.BaseField {
|
|
|
89
104
|
const ret = await Promise.all(promises);
|
|
90
105
|
return ret.every((v) => v);
|
|
91
106
|
}
|
|
107
|
+
async valid(obj) {
|
|
108
|
+
if (this.options.jsonAsList) {
|
|
109
|
+
if (!Array.isArray(obj)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
|
|
113
|
+
return valid.every((b) => b);
|
|
114
|
+
}
|
|
115
|
+
if (!(obj instanceof Object)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return this.validImpl(obj);
|
|
119
|
+
}
|
|
92
120
|
}
|
|
93
121
|
exports.StructField = StructField;
|
|
94
122
|
function StructType(options) {
|
|
@@ -96,7 +124,18 @@ function StructType(options) {
|
|
|
96
124
|
return Object.assign(result, options);
|
|
97
125
|
}
|
|
98
126
|
exports.StructType = StructType;
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated use StructTypeAsList
|
|
129
|
+
*/
|
|
99
130
|
function StructListType(options) {
|
|
100
131
|
return new field_1.ListField(StructType(options), options);
|
|
101
132
|
}
|
|
102
133
|
exports.StructListType = StructListType;
|
|
134
|
+
function StructTypeAsList(options) {
|
|
135
|
+
let result = new StructField({
|
|
136
|
+
...options,
|
|
137
|
+
jsonAsList: true,
|
|
138
|
+
});
|
|
139
|
+
return Object.assign(result, options);
|
|
140
|
+
}
|
|
141
|
+
exports.StructTypeAsList = StructTypeAsList;
|
|
@@ -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];
|
|
@@ -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.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.
|
|
232
|
+
return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.decorators, 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.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.
|
|
242
|
+
return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.isTypeOnly);
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
}
|
|
@@ -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,10 +30,10 @@ 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");
|
|
35
39
|
// need to use the GQLCapture from the package so that when we call GQLCapture.enable()
|
|
@@ -95,6 +99,7 @@ function transformResultType(f) {
|
|
|
95
99
|
type: f.resultType,
|
|
96
100
|
tsType: graphql_1.knownAllowedNames.get(f.resultType),
|
|
97
101
|
list: f.list,
|
|
102
|
+
connection: f.connection,
|
|
98
103
|
nullable: f.nullable,
|
|
99
104
|
},
|
|
100
105
|
]
|
|
@@ -235,7 +240,11 @@ async function main() {
|
|
|
235
240
|
// if this list grows too long, need to build this into golang types and passed here
|
|
236
241
|
// TODO foreign non-scalars eventually
|
|
237
242
|
(0, graphql_1.addCustomType)({
|
|
238
|
-
importPath:
|
|
243
|
+
importPath: MODULE_PATH,
|
|
244
|
+
// for go tests...
|
|
245
|
+
// TODO need a flag that only does this for go tests
|
|
246
|
+
// breaks when running locally sometimes...
|
|
247
|
+
secondaryImportPath: "../graphql/scalars/time",
|
|
239
248
|
type: "GraphQLTime",
|
|
240
249
|
});
|
|
241
250
|
(0, graphql_1.addCustomType)({
|
|
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();
|
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
|
}
|
package/testutils/builder.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { Ent, ID, Viewer, Data, EntConstructor } from "../core/base";
|
|
1
|
+
import { Ent, ID, Viewer, Data, EntConstructor, PrivacyPolicy } from "../core/base";
|
|
2
2
|
import { Orchestrator } from "../action/orchestrator";
|
|
3
3
|
import { Action, Builder, Changeset, WriteOperation, Validator, Trigger, Observer } from "../action";
|
|
4
4
|
import { FieldMap, Schema } from "../schema";
|
|
5
5
|
import { SchemaConfig } from "../schema/base_schema";
|
|
6
|
+
import { FieldInfoMap } from "../schema/schema";
|
|
6
7
|
export declare class User implements Ent {
|
|
7
8
|
viewer: Viewer;
|
|
8
9
|
data: Data;
|
|
9
10
|
id: ID;
|
|
10
11
|
accountID: string;
|
|
11
12
|
nodeType: string;
|
|
12
|
-
|
|
13
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
13
14
|
firstName: string;
|
|
14
15
|
constructor(viewer: Viewer, data: Data);
|
|
15
16
|
}
|
|
@@ -19,7 +20,7 @@ export declare class Event implements Ent {
|
|
|
19
20
|
id: ID;
|
|
20
21
|
accountID: string;
|
|
21
22
|
nodeType: string;
|
|
22
|
-
|
|
23
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
23
24
|
constructor(viewer: Viewer, data: Data);
|
|
24
25
|
}
|
|
25
26
|
export declare class Contact implements Ent {
|
|
@@ -28,7 +29,7 @@ export declare class Contact implements Ent {
|
|
|
28
29
|
id: ID;
|
|
29
30
|
accountID: string;
|
|
30
31
|
nodeType: string;
|
|
31
|
-
|
|
32
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
32
33
|
constructor(viewer: Viewer, data: Data);
|
|
33
34
|
}
|
|
34
35
|
export declare class Group implements Ent {
|
|
@@ -37,7 +38,7 @@ export declare class Group implements Ent {
|
|
|
37
38
|
id: ID;
|
|
38
39
|
accountID: string;
|
|
39
40
|
nodeType: string;
|
|
40
|
-
|
|
41
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
41
42
|
constructor(viewer: Viewer, data: Data);
|
|
42
43
|
}
|
|
43
44
|
export declare class Message implements Ent {
|
|
@@ -46,7 +47,7 @@ export declare class Message implements Ent {
|
|
|
46
47
|
id: ID;
|
|
47
48
|
accountID: string;
|
|
48
49
|
nodeType: string;
|
|
49
|
-
|
|
50
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
50
51
|
constructor(viewer: Viewer, data: Data);
|
|
51
52
|
}
|
|
52
53
|
export declare class Address implements Ent {
|
|
@@ -55,7 +56,7 @@ export declare class Address implements Ent {
|
|
|
55
56
|
id: ID;
|
|
56
57
|
accountID: string;
|
|
57
58
|
nodeType: string;
|
|
58
|
-
|
|
59
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
59
60
|
constructor(viewer: Viewer, data: Data);
|
|
60
61
|
}
|
|
61
62
|
export interface BuilderSchema<T extends Ent> extends Schema {
|
|
@@ -66,18 +67,26 @@ export declare function getBuilderSchemaFromFields<T extends Ent>(fields: FieldM
|
|
|
66
67
|
export declare function getBuilderSchemaTZFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
|
|
67
68
|
export declare function getSchemaName(value: BuilderSchema<Ent>): string;
|
|
68
69
|
export declare function getTableName(value: BuilderSchema<Ent>): string;
|
|
69
|
-
export declare
|
|
70
|
+
export declare function getFieldInfo(value: BuilderSchema<Ent>): FieldInfoMap;
|
|
71
|
+
declare type MaybeNull<T extends Ent> = T | null;
|
|
72
|
+
declare type TMaybleNullableEnt<T extends Ent> = T | MaybeNull<T>;
|
|
73
|
+
export declare class SimpleBuilder<T extends Ent, TExistingEnt extends TMaybleNullableEnt<T> = MaybeNull<T>> implements Builder<T, Viewer, TExistingEnt> {
|
|
70
74
|
viewer: Viewer;
|
|
71
75
|
private schema;
|
|
72
76
|
operation: WriteOperation;
|
|
73
|
-
existingEnt:
|
|
74
|
-
ent: EntConstructor<T>;
|
|
77
|
+
existingEnt: TExistingEnt;
|
|
78
|
+
ent: EntConstructor<T, Viewer>;
|
|
75
79
|
placeholderID: ID;
|
|
76
|
-
orchestrator: Orchestrator<T, Data>;
|
|
80
|
+
orchestrator: Orchestrator<T, Data, Viewer, TExistingEnt>;
|
|
77
81
|
fields: Map<string, any>;
|
|
78
82
|
nodeType: string;
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
m: Map<string, any>;
|
|
84
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation: WriteOperation, existingEnt: TExistingEnt, action?: Action<T, SimpleBuilder<T, TExistingEnt>, Viewer, Data, TExistingEnt> | undefined);
|
|
85
|
+
getInput(): Data;
|
|
86
|
+
updateInput(input: Data): void;
|
|
87
|
+
storeData(k: string, v: any): void;
|
|
88
|
+
getStoredData(k: string): any;
|
|
89
|
+
build(): Promise<Changeset>;
|
|
81
90
|
editedEnt(): Promise<T | null>;
|
|
82
91
|
editedEntX(): Promise<T>;
|
|
83
92
|
save(): Promise<void>;
|
|
@@ -88,20 +97,21 @@ export declare class SimpleBuilder<T extends Ent> implements Builder<T> {
|
|
|
88
97
|
interface viewerEntLoadFunc {
|
|
89
98
|
(data: Data): Viewer | Promise<Viewer>;
|
|
90
99
|
}
|
|
91
|
-
export declare class SimpleAction<T extends Ent> implements Action<T, SimpleBuilder<T>, Data> {
|
|
100
|
+
export declare class SimpleAction<T extends Ent, TExistingEnt extends TMaybleNullableEnt<T> = MaybeNull<T>> implements Action<T, SimpleBuilder<T, TExistingEnt>, Viewer, Data, TExistingEnt> {
|
|
92
101
|
viewer: Viewer;
|
|
93
102
|
private fields;
|
|
94
|
-
builder: SimpleBuilder<T>;
|
|
95
|
-
validators: Validator<SimpleBuilder<T>, Data>[];
|
|
96
|
-
triggers: Trigger<SimpleBuilder<T>, Data>[];
|
|
97
|
-
observers: Observer<SimpleBuilder<T>, Data>[];
|
|
103
|
+
builder: SimpleBuilder<T, TExistingEnt>;
|
|
98
104
|
viewerForEntLoad: viewerEntLoadFunc | undefined;
|
|
99
|
-
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation
|
|
100
|
-
|
|
105
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation: WriteOperation | undefined, existingEnt: TExistingEnt);
|
|
106
|
+
getTriggers(): (Trigger<T, SimpleBuilder<T>> | Array<Trigger<T, SimpleBuilder<T>>>)[];
|
|
107
|
+
getValidators(): Validator<T, SimpleBuilder<T>>[];
|
|
108
|
+
getObservers(): Observer<T, SimpleBuilder<T>>[];
|
|
109
|
+
getPrivacyPolicy(): PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
101
110
|
getInput(): Data;
|
|
102
|
-
changeset(): Promise<Changeset
|
|
111
|
+
changeset(): Promise<Changeset>;
|
|
103
112
|
valid(): Promise<boolean>;
|
|
104
113
|
validX(): Promise<void>;
|
|
114
|
+
validWithErrors(): Promise<Error[]>;
|
|
105
115
|
save(): Promise<T | null>;
|
|
106
116
|
saveX(): Promise<T>;
|
|
107
117
|
editedEnt(): Promise<T | null>;
|
package/testutils/builder.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SimpleAction = exports.SimpleBuilder = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
|
|
6
|
+
exports.SimpleAction = exports.SimpleBuilder = exports.getFieldInfo = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
|
|
7
7
|
const privacy_1 = require("../core/privacy");
|
|
8
8
|
const orchestrator_1 = require("../action/orchestrator");
|
|
9
9
|
const action_1 = require("../action");
|
|
@@ -15,18 +15,21 @@ const loaders_1 = require("../core/loaders");
|
|
|
15
15
|
const convert_1 = require("../core/convert");
|
|
16
16
|
const camel_case_1 = require("camel-case");
|
|
17
17
|
const base_schema_1 = require("../schema/base_schema");
|
|
18
|
+
const schema_2 = require("../schema/schema");
|
|
18
19
|
class User {
|
|
19
20
|
constructor(viewer, data) {
|
|
20
21
|
this.viewer = viewer;
|
|
21
22
|
this.data = data;
|
|
22
23
|
this.accountID = "";
|
|
23
24
|
this.nodeType = "User";
|
|
24
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
25
25
|
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
26
26
|
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
27
27
|
this.id = data.id;
|
|
28
28
|
this.firstName = data.first_name;
|
|
29
29
|
}
|
|
30
|
+
getPrivacyPolicy() {
|
|
31
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
34
|
exports.User = User;
|
|
32
35
|
class Event {
|
|
@@ -35,9 +38,11 @@ class Event {
|
|
|
35
38
|
this.data = data;
|
|
36
39
|
this.accountID = "";
|
|
37
40
|
this.nodeType = "Event";
|
|
38
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
39
41
|
this.id = data.id;
|
|
40
42
|
}
|
|
43
|
+
getPrivacyPolicy() {
|
|
44
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
45
|
+
}
|
|
41
46
|
}
|
|
42
47
|
exports.Event = Event;
|
|
43
48
|
class Contact {
|
|
@@ -46,11 +51,13 @@ class Contact {
|
|
|
46
51
|
this.data = data;
|
|
47
52
|
this.accountID = "";
|
|
48
53
|
this.nodeType = "Contact";
|
|
49
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
50
54
|
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
51
55
|
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
52
56
|
this.id = data.id;
|
|
53
57
|
}
|
|
58
|
+
getPrivacyPolicy() {
|
|
59
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
60
|
+
}
|
|
54
61
|
}
|
|
55
62
|
exports.Contact = Contact;
|
|
56
63
|
class Group {
|
|
@@ -59,9 +66,11 @@ class Group {
|
|
|
59
66
|
this.data = data;
|
|
60
67
|
this.accountID = "";
|
|
61
68
|
this.nodeType = "Group";
|
|
62
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
63
69
|
this.id = data.id;
|
|
64
70
|
}
|
|
71
|
+
getPrivacyPolicy() {
|
|
72
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
75
|
exports.Group = Group;
|
|
67
76
|
class Message {
|
|
@@ -70,9 +79,11 @@ class Message {
|
|
|
70
79
|
this.data = data;
|
|
71
80
|
this.accountID = "";
|
|
72
81
|
this.nodeType = "Message";
|
|
73
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
74
82
|
this.id = data.id;
|
|
75
83
|
}
|
|
84
|
+
getPrivacyPolicy() {
|
|
85
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
86
|
+
}
|
|
76
87
|
}
|
|
77
88
|
exports.Message = Message;
|
|
78
89
|
class Address {
|
|
@@ -81,9 +92,11 @@ class Address {
|
|
|
81
92
|
this.data = data;
|
|
82
93
|
this.accountID = "";
|
|
83
94
|
this.nodeType = "Address";
|
|
84
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
85
95
|
this.id = data.id;
|
|
86
96
|
}
|
|
97
|
+
getPrivacyPolicy() {
|
|
98
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
99
|
+
}
|
|
87
100
|
}
|
|
88
101
|
exports.Address = Address;
|
|
89
102
|
function getBuilderSchema(cfg, ent) {
|
|
@@ -118,13 +131,27 @@ exports.getTableName = getTableName;
|
|
|
118
131
|
function randomNum() {
|
|
119
132
|
return Math.random().toString(10).substring(2);
|
|
120
133
|
}
|
|
134
|
+
function getFieldInfo(value) {
|
|
135
|
+
const fields = (0, schema_1.getFields)(value);
|
|
136
|
+
let ret = {};
|
|
137
|
+
for (const [k, f] of fields) {
|
|
138
|
+
ret[k] = {
|
|
139
|
+
dbCol: (0, schema_2.getStorageKey)(f, k),
|
|
140
|
+
// in tests (anything using SimpleBuilder), make it be the same as the fieldName
|
|
141
|
+
inputKey: k,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return ret;
|
|
145
|
+
}
|
|
146
|
+
exports.getFieldInfo = getFieldInfo;
|
|
121
147
|
// reuses orchestrator and standard things
|
|
122
148
|
class SimpleBuilder {
|
|
123
|
-
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt
|
|
149
|
+
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt, action) {
|
|
124
150
|
this.viewer = viewer;
|
|
125
151
|
this.schema = schema;
|
|
126
152
|
this.operation = operation;
|
|
127
153
|
this.existingEnt = existingEnt;
|
|
154
|
+
this.m = new Map();
|
|
128
155
|
// create dynamic placeholder
|
|
129
156
|
// TODO: do we need to use this as the node when there's an existingEnt
|
|
130
157
|
// same for generated builders.
|
|
@@ -150,11 +177,13 @@ class SimpleBuilder {
|
|
|
150
177
|
this.ent = schema.ent;
|
|
151
178
|
const tableName = getTableName(schema);
|
|
152
179
|
this.nodeType = (0, camel_case_1.camelCase)(schema.ent.name);
|
|
180
|
+
const fieldInfo = getFieldInfo(schema);
|
|
153
181
|
this.orchestrator = new orchestrator_1.Orchestrator({
|
|
154
182
|
viewer: this.viewer,
|
|
155
183
|
operation: operation,
|
|
156
184
|
tableName: tableName,
|
|
157
185
|
key,
|
|
186
|
+
fieldInfo,
|
|
158
187
|
loaderOptions: {
|
|
159
188
|
loaderFactory: new loaders_1.ObjectLoaderFactory({
|
|
160
189
|
tableName: tableName,
|
|
@@ -164,7 +193,7 @@ class SimpleBuilder {
|
|
|
164
193
|
ent: schema.ent,
|
|
165
194
|
tableName: tableName,
|
|
166
195
|
fields: [],
|
|
167
|
-
fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema),
|
|
196
|
+
fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema, fieldInfo),
|
|
168
197
|
},
|
|
169
198
|
builder: this,
|
|
170
199
|
action: action,
|
|
@@ -177,24 +206,40 @@ class SimpleBuilder {
|
|
|
177
206
|
}
|
|
178
207
|
return m;
|
|
179
208
|
},
|
|
180
|
-
updateInput: (
|
|
181
|
-
const knownFields = (0, schema_1.getFields)(this.schema);
|
|
182
|
-
for (const k in input) {
|
|
183
|
-
if (knownFields.has(k)) {
|
|
184
|
-
this.fields.set(k, input[k]);
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
// related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
|
|
188
|
-
// we do camelCase in
|
|
189
|
-
const sc = (0, snake_case_1.snakeCase)(k);
|
|
190
|
-
if (knownFields.has(sc)) {
|
|
191
|
-
this.fields.set(sc, input[k]);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
},
|
|
209
|
+
updateInput: this.updateInput.bind(this),
|
|
196
210
|
});
|
|
197
211
|
}
|
|
212
|
+
getInput() {
|
|
213
|
+
let ret = {};
|
|
214
|
+
for (const [k, v] of this.fields) {
|
|
215
|
+
ret[k] = v;
|
|
216
|
+
}
|
|
217
|
+
return ret;
|
|
218
|
+
}
|
|
219
|
+
updateInput(input) {
|
|
220
|
+
const knownFields = (0, schema_1.getFields)(this.schema);
|
|
221
|
+
for (const k in input) {
|
|
222
|
+
if (knownFields.has(k)) {
|
|
223
|
+
this.fields.set(k, input[k]);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
// related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
|
|
227
|
+
// we do camelCase in
|
|
228
|
+
const sc = (0, snake_case_1.snakeCase)(k);
|
|
229
|
+
if (knownFields.has(sc)) {
|
|
230
|
+
this.fields.set(sc, input[k]);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// store data in Builder that can be retrieved by another validator, trigger, observer later in the action
|
|
236
|
+
storeData(k, v) {
|
|
237
|
+
this.m.set(k, v);
|
|
238
|
+
}
|
|
239
|
+
// retrieve data stored in this Builder with key
|
|
240
|
+
getStoredData(k) {
|
|
241
|
+
return this.m.get(k);
|
|
242
|
+
}
|
|
198
243
|
build() {
|
|
199
244
|
return this.orchestrator.build();
|
|
200
245
|
}
|
|
@@ -219,14 +264,20 @@ class SimpleBuilder {
|
|
|
219
264
|
}
|
|
220
265
|
exports.SimpleBuilder = SimpleBuilder;
|
|
221
266
|
class SimpleAction {
|
|
222
|
-
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt
|
|
267
|
+
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt) {
|
|
223
268
|
this.viewer = viewer;
|
|
224
269
|
this.fields = fields;
|
|
225
|
-
this.validators = [];
|
|
226
|
-
this.triggers = [];
|
|
227
|
-
this.observers = [];
|
|
228
270
|
this.builder = new SimpleBuilder(this.viewer, schema, fields, operation, existingEnt, this);
|
|
229
271
|
}
|
|
272
|
+
getTriggers() {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
getValidators() {
|
|
276
|
+
return [];
|
|
277
|
+
}
|
|
278
|
+
getObservers() {
|
|
279
|
+
return [];
|
|
280
|
+
}
|
|
230
281
|
getPrivacyPolicy() {
|
|
231
282
|
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
232
283
|
}
|
|
@@ -246,6 +297,9 @@ class SimpleAction {
|
|
|
246
297
|
validX() {
|
|
247
298
|
return this.builder.orchestrator.validX();
|
|
248
299
|
}
|
|
300
|
+
validWithErrors() {
|
|
301
|
+
return this.builder.orchestrator.validWithErrors();
|
|
302
|
+
}
|
|
249
303
|
async save() {
|
|
250
304
|
await (0, action_1.saveBuilder)(this.builder);
|
|
251
305
|
if (this.builder.operation !== action_1.WriteOperation.Delete) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Client } from "pg";
|
|
2
|
+
import { Data } from "../../core/base";
|
|
3
|
+
import { Schema } from "../../schema";
|
|
4
|
+
interface Options {
|
|
5
|
+
overrides?: Data;
|
|
6
|
+
client: Client;
|
|
7
|
+
tableName: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function writeFixture(schema: Schema, opts: Options): Promise<void>;
|
|
10
|
+
export {};
|