@snowtop/ent 0.1.0-alpha3 → 0.1.0-alpha30
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 +28 -24
- package/action/executor.d.ts +4 -4
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +21 -20
- package/action/experimental_action.js +11 -5
- package/action/orchestrator.d.ts +31 -16
- package/action/orchestrator.js +156 -43
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +25 -21
- package/core/base.js +16 -0
- package/core/clause.d.ts +24 -3
- package/core/clause.js +246 -5
- package/core/config.d.ts +23 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +2 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -3
- package/core/db.js +2 -0
- package/core/ent.d.ts +19 -21
- package/core/ent.js +76 -25
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/object_loader.d.ts +10 -5
- package/core/loaders/object_loader.js +59 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/privacy.d.ts +25 -25
- package/core/privacy.js +3 -0
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +4 -0
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +24 -23
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +3 -1
- package/graphql/mutations/union.d.ts +2 -0
- package/graphql/mutations/union.js +35 -0
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +16 -1
- package/index.js +18 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +18 -5
- package/parse_schema/parse.js +55 -6
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +1 -1
- package/schema/field.js +1 -1
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/schema.d.ts +61 -1
- package/schema/schema.js +126 -5
- package/schema/union_field.d.ts +2 -1
- package/schema/union_field.js +32 -14
- package/scripts/custom_graphql.js +122 -15
- 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 +15 -1
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +98 -13
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/test_db.d.ts +2 -1
- package/testutils/db/test_db.js +13 -4
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +26 -17
- package/testutils/fake_data/fake_contact.d.ts +4 -8
- package/testutils/fake_data/fake_contact.js +15 -19
- package/testutils/fake_data/fake_event.d.ts +4 -8
- package/testutils/fake_data/fake_event.js +21 -25
- package/testutils/fake_data/fake_user.d.ts +5 -9
- package/testutils/fake_data/fake_user.js +23 -27
- package/testutils/fake_data/test_helpers.js +1 -1
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/tsc/ast.d.ts +43 -0
- package/tsc/ast.js +264 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +20 -0
- package/tsc/transform_action.js +169 -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 +354 -0
- package/scripts/transform_schema.js +0 -288
|
@@ -24,6 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const glob_1 = __importDefault(require("glob"));
|
|
27
|
+
const json5_1 = __importDefault(require("json5"));
|
|
27
28
|
const minimist_1 = __importDefault(require("minimist"));
|
|
28
29
|
const graphql_1 = require("../graphql/graphql");
|
|
29
30
|
const readline = __importStar(require("readline"));
|
|
@@ -53,7 +54,103 @@ async function readInputs() {
|
|
|
53
54
|
});
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
function processCustomObjects(l, gqlCapture, input) {
|
|
58
|
+
let m;
|
|
59
|
+
if (input) {
|
|
60
|
+
m = gqlCapture.getCustomInputObjects();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
m = gqlCapture.getCustomObjects();
|
|
64
|
+
}
|
|
65
|
+
for (const input of l) {
|
|
66
|
+
m.set(input.name, {
|
|
67
|
+
nodeName: input.graphQLName || input.name,
|
|
68
|
+
className: input.name,
|
|
69
|
+
});
|
|
70
|
+
if (input.fields) {
|
|
71
|
+
processCustomFields(input.fields, gqlCapture, input.name);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function transformArgs(f) {
|
|
76
|
+
return (f.args || []).map((v) => {
|
|
77
|
+
const ret = {
|
|
78
|
+
...v,
|
|
79
|
+
};
|
|
80
|
+
// duplicated from getType in graphql.ts
|
|
81
|
+
if ((0, graphql_1.isCustomType)(ret.type)) {
|
|
82
|
+
ret.type = v.type.type;
|
|
83
|
+
(0, graphql_1.addCustomType)(v.type);
|
|
84
|
+
}
|
|
85
|
+
// scalar types not supported for now
|
|
86
|
+
ret.tsType = graphql_1.knownAllowedNames.get(v.type);
|
|
87
|
+
return ret;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function transformResultType(f) {
|
|
91
|
+
return f.resultType
|
|
92
|
+
? [
|
|
93
|
+
{
|
|
94
|
+
name: "",
|
|
95
|
+
type: f.resultType,
|
|
96
|
+
tsType: graphql_1.knownAllowedNames.get(f.resultType),
|
|
97
|
+
list: f.list,
|
|
98
|
+
nullable: f.nullable,
|
|
99
|
+
},
|
|
100
|
+
]
|
|
101
|
+
: [];
|
|
102
|
+
}
|
|
103
|
+
function processTopLevel(l, l2) {
|
|
104
|
+
for (const custom of l) {
|
|
105
|
+
l2.push({
|
|
106
|
+
nodeName: custom.class,
|
|
107
|
+
functionName: custom.functionName || custom.name,
|
|
108
|
+
gqlName: custom.graphQLName || custom.name,
|
|
109
|
+
fieldType: custom.fieldType,
|
|
110
|
+
args: transformArgs(custom),
|
|
111
|
+
results: transformResultType(custom),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function processCustomFields(fields, gqlCapture, nodeName) {
|
|
116
|
+
const m = gqlCapture.getCustomFields();
|
|
117
|
+
let results = [];
|
|
118
|
+
for (const f of fields) {
|
|
119
|
+
results.push({
|
|
120
|
+
nodeName: nodeName,
|
|
121
|
+
gqlName: f.graphQLName || f.name,
|
|
122
|
+
functionName: f.functionName || f.name,
|
|
123
|
+
fieldType: f.fieldType,
|
|
124
|
+
args: transformArgs(f),
|
|
125
|
+
results: transformResultType(f),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
m.set(nodeName, results);
|
|
129
|
+
}
|
|
130
|
+
async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
131
|
+
if (jsonPath !== undefined) {
|
|
132
|
+
let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
|
|
133
|
+
encoding: "utf8",
|
|
134
|
+
}));
|
|
135
|
+
if (json.fields) {
|
|
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
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
57
154
|
if (filesCsv !== undefined) {
|
|
58
155
|
let files = filesCsv.split(",");
|
|
59
156
|
for (let i = 0; i < files.length; i++) {
|
|
@@ -153,15 +250,25 @@ async function main() {
|
|
|
153
250
|
if (!gqlPath) {
|
|
154
251
|
throw new Error("could not find graphql path");
|
|
155
252
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
253
|
+
// use different variable so that we use the correct GQLCapture as needed
|
|
254
|
+
// for local dev, get the one from the file system. otherwise, get the one
|
|
255
|
+
// from node_modules
|
|
256
|
+
let gqlCapture;
|
|
257
|
+
if (process.env.LOCAL_SCRIPT_PATH) {
|
|
258
|
+
const r = require("../graphql/graphql");
|
|
259
|
+
gqlCapture = r.GQLCapture;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
const r = require(gqlPath);
|
|
263
|
+
if (!r.GQLCapture) {
|
|
264
|
+
throw new Error("could not find GQLCapture in module");
|
|
265
|
+
}
|
|
266
|
+
gqlCapture = r.GQLCapture;
|
|
267
|
+
gqlCapture.enable(true);
|
|
159
268
|
}
|
|
160
|
-
const GQLCapture = r.GQLCapture;
|
|
161
|
-
GQLCapture.enable(true);
|
|
162
269
|
const [inputsRead, _, imports] = await Promise.all([
|
|
163
270
|
readInputs(),
|
|
164
|
-
captureCustom(options.path, options.files),
|
|
271
|
+
captureCustom(options.path, options.files, options.json_path, gqlCapture),
|
|
165
272
|
parseImports(options.path),
|
|
166
273
|
]);
|
|
167
274
|
const { nodes, nodesMap } = inputsRead;
|
|
@@ -172,14 +279,14 @@ async function main() {
|
|
|
172
279
|
}
|
|
173
280
|
return result;
|
|
174
281
|
}
|
|
175
|
-
|
|
176
|
-
let args = fromMap(
|
|
177
|
-
let inputs = fromMap(
|
|
178
|
-
let fields =
|
|
179
|
-
let queries =
|
|
180
|
-
let mutations =
|
|
181
|
-
let objects = fromMap(
|
|
182
|
-
let customTypes = fromMap(
|
|
282
|
+
gqlCapture.resolve(nodes);
|
|
283
|
+
let args = fromMap(gqlCapture.getCustomArgs());
|
|
284
|
+
let inputs = fromMap(gqlCapture.getCustomInputObjects());
|
|
285
|
+
let fields = gqlCapture.getProcessedCustomFields();
|
|
286
|
+
let queries = gqlCapture.getProcessedCustomQueries();
|
|
287
|
+
let mutations = gqlCapture.getProcessedCustomMutations();
|
|
288
|
+
let objects = fromMap(gqlCapture.getCustomObjects());
|
|
289
|
+
let customTypes = fromMap(gqlCapture.getCustomTypes());
|
|
183
290
|
let classes = {};
|
|
184
291
|
let allFiles = {};
|
|
185
292
|
const buildClasses2 = (args) => {
|
|
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 transform_1 = require("../tsc/transform");
|
|
7
|
+
const transform_schema_1 = require("../tsc/transform_schema");
|
|
8
|
+
const transform_ent_1 = require("../tsc/transform_ent");
|
|
9
|
+
const move_generated_1 = require("../tsc/move_generated");
|
|
10
|
+
const transform_action_1 = require("../tsc/transform_action");
|
|
11
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
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
|
@@ -44,7 +44,21 @@ function main() {
|
|
|
44
44
|
if (!match) {
|
|
45
45
|
throw new Error(`non-typescript file ${p} returned by glob`);
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
let schema = match[1];
|
|
48
|
+
// convert foo_schema.ts -> foo
|
|
49
|
+
if (schema.endsWith("_schema")) {
|
|
50
|
+
schema = schema.slice(0, -7);
|
|
51
|
+
}
|
|
52
|
+
let relativePath;
|
|
53
|
+
const index = p.indexOf("src/schema");
|
|
54
|
+
if (index !== -1) {
|
|
55
|
+
relativePath = p.substring(index);
|
|
56
|
+
}
|
|
57
|
+
const s = require(p).default;
|
|
58
|
+
if (relativePath !== undefined) {
|
|
59
|
+
s.schemaPath = relativePath;
|
|
60
|
+
}
|
|
61
|
+
potentialSchemas[(0, pascal_case_1.pascalCase)(schema)] = s;
|
|
48
62
|
}
|
|
49
63
|
// console.log(potentialSchemas);
|
|
50
64
|
const result = (0, parse_1.parseSchema)(potentialSchemas);
|
package/testutils/builder.d.ts
CHANGED
|
@@ -1,14 +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
|
-
import { Schema } from "../schema";
|
|
4
|
+
import { FieldMap, Schema } from "../schema";
|
|
5
|
+
import { SchemaConfig } from "../schema/base_schema";
|
|
6
|
+
import { FieldInfoMap } from "../schema/schema";
|
|
5
7
|
export declare class User implements Ent {
|
|
6
8
|
viewer: Viewer;
|
|
7
9
|
data: Data;
|
|
8
10
|
id: ID;
|
|
9
11
|
accountID: string;
|
|
10
12
|
nodeType: string;
|
|
11
|
-
|
|
13
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
12
14
|
firstName: string;
|
|
13
15
|
constructor(viewer: Viewer, data: Data);
|
|
14
16
|
}
|
|
@@ -18,7 +20,7 @@ export declare class Event implements Ent {
|
|
|
18
20
|
id: ID;
|
|
19
21
|
accountID: string;
|
|
20
22
|
nodeType: string;
|
|
21
|
-
|
|
23
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
22
24
|
constructor(viewer: Viewer, data: Data);
|
|
23
25
|
}
|
|
24
26
|
export declare class Contact implements Ent {
|
|
@@ -27,7 +29,7 @@ export declare class Contact implements Ent {
|
|
|
27
29
|
id: ID;
|
|
28
30
|
accountID: string;
|
|
29
31
|
nodeType: string;
|
|
30
|
-
|
|
32
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
31
33
|
constructor(viewer: Viewer, data: Data);
|
|
32
34
|
}
|
|
33
35
|
export declare class Group implements Ent {
|
|
@@ -36,7 +38,7 @@ export declare class Group implements Ent {
|
|
|
36
38
|
id: ID;
|
|
37
39
|
accountID: string;
|
|
38
40
|
nodeType: string;
|
|
39
|
-
|
|
41
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
40
42
|
constructor(viewer: Viewer, data: Data);
|
|
41
43
|
}
|
|
42
44
|
export declare class Message implements Ent {
|
|
@@ -45,7 +47,7 @@ export declare class Message implements Ent {
|
|
|
45
47
|
id: ID;
|
|
46
48
|
accountID: string;
|
|
47
49
|
nodeType: string;
|
|
48
|
-
|
|
50
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
49
51
|
constructor(viewer: Viewer, data: Data);
|
|
50
52
|
}
|
|
51
53
|
export declare class Address implements Ent {
|
|
@@ -54,26 +56,34 @@ export declare class Address implements Ent {
|
|
|
54
56
|
id: ID;
|
|
55
57
|
accountID: string;
|
|
56
58
|
nodeType: string;
|
|
57
|
-
|
|
59
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
58
60
|
constructor(viewer: Viewer, data: Data);
|
|
59
61
|
}
|
|
60
62
|
export interface BuilderSchema<T extends Ent> extends Schema {
|
|
61
63
|
ent: EntConstructor<T>;
|
|
62
64
|
}
|
|
65
|
+
export declare function getBuilderSchema<T extends Ent>(cfg: SchemaConfig, ent: EntConstructor<T>): BuilderSchema<T>;
|
|
66
|
+
export declare function getBuilderSchemaFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
|
|
67
|
+
export declare function getBuilderSchemaTZFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
|
|
63
68
|
export declare function getSchemaName(value: BuilderSchema<Ent>): string;
|
|
64
69
|
export declare function getTableName(value: BuilderSchema<Ent>): string;
|
|
65
|
-
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> {
|
|
66
74
|
viewer: Viewer;
|
|
67
75
|
private schema;
|
|
68
76
|
operation: WriteOperation;
|
|
69
|
-
existingEnt:
|
|
77
|
+
existingEnt: TExistingEnt;
|
|
70
78
|
ent: EntConstructor<T>;
|
|
71
79
|
placeholderID: ID;
|
|
72
|
-
orchestrator: Orchestrator<T, Data>;
|
|
80
|
+
orchestrator: Orchestrator<T, Data, Viewer>;
|
|
73
81
|
fields: Map<string, any>;
|
|
74
82
|
nodeType: string;
|
|
75
|
-
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation
|
|
76
|
-
|
|
83
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation: WriteOperation, existingEnt: TExistingEnt, action?: Action<T, SimpleBuilder<T>, Viewer, Data> | undefined);
|
|
84
|
+
getInput(): Data;
|
|
85
|
+
updateInput(input: Data): void;
|
|
86
|
+
build(): Promise<Changeset>;
|
|
77
87
|
editedEnt(): Promise<T | null>;
|
|
78
88
|
editedEntX(): Promise<T>;
|
|
79
89
|
save(): Promise<void>;
|
|
@@ -84,18 +94,18 @@ export declare class SimpleBuilder<T extends Ent> implements Builder<T> {
|
|
|
84
94
|
interface viewerEntLoadFunc {
|
|
85
95
|
(data: Data): Viewer | Promise<Viewer>;
|
|
86
96
|
}
|
|
87
|
-
export declare class SimpleAction<T extends Ent> implements Action<T, SimpleBuilder<T>, Data> {
|
|
97
|
+
export declare class SimpleAction<T extends Ent, TExistingEnt extends TMaybleNullableEnt<T> = MaybeNull<T>> implements Action<T, SimpleBuilder<T, TExistingEnt>, Viewer, Data, TExistingEnt> {
|
|
88
98
|
viewer: Viewer;
|
|
89
99
|
private fields;
|
|
90
|
-
builder: SimpleBuilder<T>;
|
|
91
|
-
validators: Validator<SimpleBuilder<T>, Data>[];
|
|
92
|
-
triggers: Trigger<SimpleBuilder<T>, Data>[];
|
|
93
|
-
observers: Observer<SimpleBuilder<T>, Data>[];
|
|
100
|
+
builder: SimpleBuilder<T, TExistingEnt>;
|
|
94
101
|
viewerForEntLoad: viewerEntLoadFunc | undefined;
|
|
95
|
-
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation
|
|
96
|
-
|
|
102
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation: WriteOperation | undefined, existingEnt: TExistingEnt);
|
|
103
|
+
getTriggers(): Trigger<T, SimpleBuilder<T>>[];
|
|
104
|
+
getValidators(): Validator<T, SimpleBuilder<T>>[];
|
|
105
|
+
getObservers(): Observer<T, SimpleBuilder<T>>[];
|
|
106
|
+
getPrivacyPolicy(): PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
97
107
|
getInput(): Data;
|
|
98
|
-
changeset(): Promise<Changeset
|
|
108
|
+
changeset(): Promise<Changeset>;
|
|
99
109
|
valid(): Promise<boolean>;
|
|
100
110
|
validX(): Promise<void>;
|
|
101
111
|
save(): 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.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");
|
|
@@ -14,18 +14,22 @@ const snake_case_1 = require("snake-case");
|
|
|
14
14
|
const loaders_1 = require("../core/loaders");
|
|
15
15
|
const convert_1 = require("../core/convert");
|
|
16
16
|
const camel_case_1 = require("camel-case");
|
|
17
|
+
const base_schema_1 = require("../schema/base_schema");
|
|
18
|
+
const schema_2 = require("../schema/schema");
|
|
17
19
|
class User {
|
|
18
20
|
constructor(viewer, data) {
|
|
19
21
|
this.viewer = viewer;
|
|
20
22
|
this.data = data;
|
|
21
23
|
this.accountID = "";
|
|
22
24
|
this.nodeType = "User";
|
|
23
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
24
25
|
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
25
26
|
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
26
27
|
this.id = data.id;
|
|
27
28
|
this.firstName = data.first_name;
|
|
28
29
|
}
|
|
30
|
+
getPrivacyPolicy() {
|
|
31
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
32
|
+
}
|
|
29
33
|
}
|
|
30
34
|
exports.User = User;
|
|
31
35
|
class Event {
|
|
@@ -34,9 +38,11 @@ class Event {
|
|
|
34
38
|
this.data = data;
|
|
35
39
|
this.accountID = "";
|
|
36
40
|
this.nodeType = "Event";
|
|
37
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
38
41
|
this.id = data.id;
|
|
39
42
|
}
|
|
43
|
+
getPrivacyPolicy() {
|
|
44
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
45
|
+
}
|
|
40
46
|
}
|
|
41
47
|
exports.Event = Event;
|
|
42
48
|
class Contact {
|
|
@@ -45,11 +51,13 @@ class Contact {
|
|
|
45
51
|
this.data = data;
|
|
46
52
|
this.accountID = "";
|
|
47
53
|
this.nodeType = "Contact";
|
|
48
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
49
54
|
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
50
55
|
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
51
56
|
this.id = data.id;
|
|
52
57
|
}
|
|
58
|
+
getPrivacyPolicy() {
|
|
59
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
60
|
+
}
|
|
53
61
|
}
|
|
54
62
|
exports.Contact = Contact;
|
|
55
63
|
class Group {
|
|
@@ -58,9 +66,11 @@ class Group {
|
|
|
58
66
|
this.data = data;
|
|
59
67
|
this.accountID = "";
|
|
60
68
|
this.nodeType = "Group";
|
|
61
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
62
69
|
this.id = data.id;
|
|
63
70
|
}
|
|
71
|
+
getPrivacyPolicy() {
|
|
72
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
75
|
exports.Group = Group;
|
|
66
76
|
class Message {
|
|
@@ -69,9 +79,11 @@ class Message {
|
|
|
69
79
|
this.data = data;
|
|
70
80
|
this.accountID = "";
|
|
71
81
|
this.nodeType = "Message";
|
|
72
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
73
82
|
this.id = data.id;
|
|
74
83
|
}
|
|
84
|
+
getPrivacyPolicy() {
|
|
85
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
86
|
+
}
|
|
75
87
|
}
|
|
76
88
|
exports.Message = Message;
|
|
77
89
|
class Address {
|
|
@@ -80,11 +92,34 @@ class Address {
|
|
|
80
92
|
this.data = data;
|
|
81
93
|
this.accountID = "";
|
|
82
94
|
this.nodeType = "Address";
|
|
83
|
-
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
84
95
|
this.id = data.id;
|
|
85
96
|
}
|
|
97
|
+
getPrivacyPolicy() {
|
|
98
|
+
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
99
|
+
}
|
|
86
100
|
}
|
|
87
101
|
exports.Address = Address;
|
|
102
|
+
function getBuilderSchema(cfg, ent) {
|
|
103
|
+
return {
|
|
104
|
+
...new base_schema_1.EntSchema(cfg),
|
|
105
|
+
ent,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
exports.getBuilderSchema = getBuilderSchema;
|
|
109
|
+
function getBuilderSchemaFromFields(fields, ent) {
|
|
110
|
+
return {
|
|
111
|
+
...new base_schema_1.EntSchema({ fields }),
|
|
112
|
+
ent,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
exports.getBuilderSchemaFromFields = getBuilderSchemaFromFields;
|
|
116
|
+
function getBuilderSchemaTZFromFields(fields, ent) {
|
|
117
|
+
return {
|
|
118
|
+
...new base_schema_1.EntSchemaWithTZ({ fields }),
|
|
119
|
+
ent,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
exports.getBuilderSchemaTZFromFields = getBuilderSchemaTZFromFields;
|
|
88
123
|
function getSchemaName(value) {
|
|
89
124
|
return value.ent.name;
|
|
90
125
|
}
|
|
@@ -96,9 +131,21 @@ exports.getTableName = getTableName;
|
|
|
96
131
|
function randomNum() {
|
|
97
132
|
return Math.random().toString(10).substring(2);
|
|
98
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
|
+
inputKey: (0, camel_case_1.camelCase)(k),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return ret;
|
|
144
|
+
}
|
|
145
|
+
exports.getFieldInfo = getFieldInfo;
|
|
99
146
|
// reuses orchestrator and standard things
|
|
100
147
|
class SimpleBuilder {
|
|
101
|
-
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt
|
|
148
|
+
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt, action) {
|
|
102
149
|
this.viewer = viewer;
|
|
103
150
|
this.schema = schema;
|
|
104
151
|
this.operation = operation;
|
|
@@ -128,11 +175,13 @@ class SimpleBuilder {
|
|
|
128
175
|
this.ent = schema.ent;
|
|
129
176
|
const tableName = getTableName(schema);
|
|
130
177
|
this.nodeType = (0, camel_case_1.camelCase)(schema.ent.name);
|
|
178
|
+
const fieldInfo = getFieldInfo(schema);
|
|
131
179
|
this.orchestrator = new orchestrator_1.Orchestrator({
|
|
132
180
|
viewer: this.viewer,
|
|
133
181
|
operation: operation,
|
|
134
182
|
tableName: tableName,
|
|
135
183
|
key,
|
|
184
|
+
fieldInfo,
|
|
136
185
|
loaderOptions: {
|
|
137
186
|
loaderFactory: new loaders_1.ObjectLoaderFactory({
|
|
138
187
|
tableName: tableName,
|
|
@@ -142,15 +191,45 @@ class SimpleBuilder {
|
|
|
142
191
|
ent: schema.ent,
|
|
143
192
|
tableName: tableName,
|
|
144
193
|
fields: [],
|
|
194
|
+
fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema, fieldInfo),
|
|
145
195
|
},
|
|
146
196
|
builder: this,
|
|
147
197
|
action: action,
|
|
148
198
|
schema: this.schema,
|
|
149
199
|
editedFields: () => {
|
|
150
|
-
return
|
|
200
|
+
// to simulate what we do in generated builders where we return a new Map
|
|
201
|
+
const m = new Map();
|
|
202
|
+
for (const [k, v] of this.fields) {
|
|
203
|
+
m.set(k, v);
|
|
204
|
+
}
|
|
205
|
+
return m;
|
|
151
206
|
},
|
|
207
|
+
updateInput: this.updateInput.bind(this),
|
|
152
208
|
});
|
|
153
209
|
}
|
|
210
|
+
getInput() {
|
|
211
|
+
let ret = {};
|
|
212
|
+
for (const [k, v] of this.fields) {
|
|
213
|
+
ret[k] = v;
|
|
214
|
+
}
|
|
215
|
+
return ret;
|
|
216
|
+
}
|
|
217
|
+
updateInput(input) {
|
|
218
|
+
const knownFields = (0, schema_1.getFields)(this.schema);
|
|
219
|
+
for (const k in input) {
|
|
220
|
+
if (knownFields.has(k)) {
|
|
221
|
+
this.fields.set(k, input[k]);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
|
|
225
|
+
// we do camelCase in
|
|
226
|
+
const sc = (0, snake_case_1.snakeCase)(k);
|
|
227
|
+
if (knownFields.has(sc)) {
|
|
228
|
+
this.fields.set(sc, input[k]);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
154
233
|
build() {
|
|
155
234
|
return this.orchestrator.build();
|
|
156
235
|
}
|
|
@@ -175,14 +254,20 @@ class SimpleBuilder {
|
|
|
175
254
|
}
|
|
176
255
|
exports.SimpleBuilder = SimpleBuilder;
|
|
177
256
|
class SimpleAction {
|
|
178
|
-
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt
|
|
257
|
+
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt) {
|
|
179
258
|
this.viewer = viewer;
|
|
180
259
|
this.fields = fields;
|
|
181
|
-
this.validators = [];
|
|
182
|
-
this.triggers = [];
|
|
183
|
-
this.observers = [];
|
|
184
260
|
this.builder = new SimpleBuilder(this.viewer, schema, fields, operation, existingEnt, this);
|
|
185
261
|
}
|
|
262
|
+
getTriggers() {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
getValidators() {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
getObservers() {
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
186
271
|
getPrivacyPolicy() {
|
|
187
272
|
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
188
273
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Context, Viewer } from "../../core/base";
|
|
2
2
|
import { ContextCache } from "../../core/context";
|
|
3
|
-
import { LoggedOutViewer } from "../../core/viewer";
|
|
4
3
|
export declare class TestContext implements Context {
|
|
4
|
+
constructor(viewer?: Viewer);
|
|
5
5
|
cache: ContextCache;
|
|
6
|
-
viewer:
|
|
6
|
+
viewer: Viewer;
|
|
7
7
|
getViewer(): Viewer;
|
|
8
8
|
}
|
|
@@ -4,9 +4,15 @@ exports.TestContext = void 0;
|
|
|
4
4
|
const context_1 = require("../../core/context");
|
|
5
5
|
const viewer_1 = require("../../core/viewer");
|
|
6
6
|
class TestContext {
|
|
7
|
-
constructor() {
|
|
7
|
+
constructor(viewer) {
|
|
8
8
|
this.cache = new context_1.ContextCache();
|
|
9
9
|
this.viewer = new viewer_1.LoggedOutViewer(this);
|
|
10
|
+
if (viewer) {
|
|
11
|
+
this.viewer = viewer;
|
|
12
|
+
if (viewer.setContext !== undefined) {
|
|
13
|
+
viewer.setContext(this);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
getViewer() {
|
|
12
18
|
return this.viewer;
|
|
@@ -71,10 +71,11 @@ export declare class TempDB {
|
|
|
71
71
|
constructor(tables: CoreConcept[]);
|
|
72
72
|
getDialect(): Dialect;
|
|
73
73
|
getTables(): Map<string, CoreConcept>;
|
|
74
|
-
beforeAll(): Promise<void>;
|
|
74
|
+
beforeAll(setupConnString?: boolean): Promise<void>;
|
|
75
75
|
getSqliteClient(): SqliteDatabase;
|
|
76
76
|
getPostgresClient(): PGClient;
|
|
77
77
|
afterAll(): Promise<void>;
|
|
78
|
+
getDB(): string;
|
|
78
79
|
dropAll(): Promise<void>;
|
|
79
80
|
drop(...tables: string[]): Promise<void>;
|
|
80
81
|
create(...tables: CoreConcept[]): Promise<void>;
|
package/testutils/db/test_db.js
CHANGED
|
@@ -336,7 +336,7 @@ class TempDB {
|
|
|
336
336
|
getTables() {
|
|
337
337
|
return this.tables;
|
|
338
338
|
}
|
|
339
|
-
async beforeAll() {
|
|
339
|
+
async beforeAll(setupConnString = true) {
|
|
340
340
|
if (this.dialect === db_1.Dialect.Postgres) {
|
|
341
341
|
const user = process.env.POSTGRES_USER || "";
|
|
342
342
|
const password = process.env.POSTGRES_PASSWORD || "";
|
|
@@ -348,11 +348,17 @@ class TempDB {
|
|
|
348
348
|
await this.client.connect();
|
|
349
349
|
this.db = randomDB();
|
|
350
350
|
await this.client.query(`CREATE DATABASE ${this.db}`);
|
|
351
|
-
if (
|
|
352
|
-
|
|
351
|
+
if (setupConnString) {
|
|
352
|
+
if (user && password) {
|
|
353
|
+
process.env.DB_CONNECTION_STRING = `postgres://${user}:${password}@localhost:5432/${this.db}`;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
process.env.DB_CONNECTION_STRING = `postgres://localhost/${this.db}?`;
|
|
357
|
+
}
|
|
353
358
|
}
|
|
354
359
|
else {
|
|
355
|
-
|
|
360
|
+
// will probably be setup via loadConfig
|
|
361
|
+
delete process.env.DB_CONNECTION_STRING;
|
|
356
362
|
}
|
|
357
363
|
this.dbClient = new pg_1.Client({
|
|
358
364
|
host: "localhost",
|
|
@@ -397,6 +403,9 @@ class TempDB {
|
|
|
397
403
|
await this.client.query(`DROP DATABASE ${this.db}`);
|
|
398
404
|
await this.client.end();
|
|
399
405
|
}
|
|
406
|
+
getDB() {
|
|
407
|
+
return this.db;
|
|
408
|
+
}
|
|
400
409
|
async dropAll() {
|
|
401
410
|
for (const [t, _] of this.tables) {
|
|
402
411
|
await this.drop(t);
|
|
@@ -16,6 +16,8 @@ interface queryConfig {
|
|
|
16
16
|
callback?: (res: supertest.Response) => void;
|
|
17
17
|
inlineFragmentRoot?: string;
|
|
18
18
|
customHandlers?: RequestHandler[];
|
|
19
|
+
server?: any;
|
|
20
|
+
graphQLPath?: string;
|
|
19
21
|
}
|
|
20
22
|
export interface queryRootConfig extends queryConfig {
|
|
21
23
|
root: string;
|