@snowtop/ent 0.0.2 → 0.0.3-5.alpha.2
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 +6 -6
- package/action/action.js +2 -2
- package/action/executor.d.ts +7 -12
- package/action/executor.js +39 -33
- package/action/experimental_action.d.ts +4 -2
- package/action/experimental_action.js +27 -2
- package/action/index.d.ts +1 -1
- package/action/orchestrator.d.ts +14 -6
- package/action/orchestrator.js +188 -99
- package/action/privacy.js +4 -4
- package/auth/auth.js +2 -2
- package/core/base.d.ts +6 -0
- package/core/base.js +12 -9
- package/core/clause.d.ts +1 -0
- package/core/clause.js +6 -2
- package/core/config.d.ts +20 -0
- package/core/config.js +2 -2
- package/core/context.js +3 -3
- package/core/convert.d.ts +4 -0
- package/core/convert.js +25 -2
- package/core/db.d.ts +18 -1
- package/core/db.js +4 -7
- package/core/ent.d.ts +17 -10
- package/core/ent.js +38 -15
- package/core/loaders/assoc_count_loader.js +5 -5
- package/core/loaders/assoc_edge_loader.js +10 -10
- package/core/loaders/loader.js +3 -3
- package/core/loaders/object_loader.js +6 -6
- package/core/loaders/query_loader.js +7 -7
- package/core/loaders/raw_count_loader.js +4 -4
- package/core/logger.js +2 -2
- package/core/privacy.d.ts +21 -1
- package/core/privacy.js +91 -47
- package/core/query/assoc_query.d.ts +12 -12
- package/core/query/assoc_query.js +86 -51
- package/core/query/custom_query.d.ts +10 -7
- package/core/query/custom_query.js +29 -3
- package/core/query/query.d.ts +24 -8
- package/core/query/query.js +41 -4
- package/core/query/shared_assoc_test.js +257 -13
- package/core/query/shared_test.d.ts +1 -1
- package/core/query/shared_test.js +11 -11
- package/core/viewer.js +1 -0
- package/graphql/builtins/connection.js +4 -3
- package/graphql/builtins/edge.js +3 -2
- package/graphql/builtins/node.js +2 -1
- package/graphql/graphql.d.ts +2 -0
- package/graphql/graphql.js +83 -61
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +2 -1
- package/graphql/node_resolver.d.ts +1 -0
- package/graphql/node_resolver.js +14 -1
- package/graphql/query/connection_type.d.ts +5 -4
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +7 -7
- package/graphql/query/page_info.js +5 -4
- package/graphql/query/shared_assoc_test.js +9 -9
- package/graphql/query/shared_edge_connection.d.ts +1 -1
- package/graphql/query/shared_edge_connection.js +4 -4
- package/graphql/scalars/time.js +1 -1
- package/imports/dataz/example1/_auth.js +8 -8
- package/imports/dataz/example1/_viewer.js +4 -4
- package/imports/index.d.ts +1 -1
- package/imports/index.js +3 -5
- package/index.d.ts +2 -1
- package/index.js +6 -2
- package/package.json +17 -10
- package/parse_schema/parse.d.ts +48 -0
- package/parse_schema/parse.js +160 -0
- package/schema/base_schema.d.ts +2 -0
- package/schema/base_schema.js +17 -7
- package/schema/field.d.ts +52 -15
- package/schema/field.js +234 -47
- package/schema/index.d.ts +1 -0
- package/schema/index.js +1 -0
- package/schema/json_field.d.ts +17 -0
- package/schema/json_field.js +48 -0
- package/schema/schema.d.ts +39 -4
- package/schema/schema.js +2 -0
- package/scripts/custom_compiler.js +8 -10
- package/scripts/custom_graphql.js +45 -10
- package/scripts/read_schema.js +6 -108
- package/testutils/builder.d.ts +6 -3
- package/testutils/builder.js +31 -15
- package/testutils/db/test_db.d.ts +16 -8
- package/testutils/db/test_db.js +65 -9
- package/testutils/db_mock.js +5 -5
- package/testutils/ent-graphql-tests/index.d.ts +1 -0
- package/testutils/ent-graphql-tests/index.js +13 -13
- package/testutils/fake_comms.d.ts +1 -0
- package/testutils/fake_comms.js +4 -0
- package/testutils/fake_data/const.d.ts +5 -1
- package/testutils/fake_data/const.js +19 -1
- package/testutils/fake_data/events_query.d.ts +16 -11
- package/testutils/fake_data/events_query.js +15 -0
- package/testutils/fake_data/fake_contact.js +9 -9
- package/testutils/fake_data/fake_event.js +14 -14
- package/testutils/fake_data/fake_user.js +12 -10
- package/testutils/fake_data/test_helpers.d.ts +5 -1
- package/testutils/fake_data/test_helpers.js +49 -16
- package/testutils/fake_data/user_query.d.ts +25 -9
- package/testutils/fake_data/user_query.js +52 -5
- package/testutils/parse_sql.js +19 -3
- package/testutils/write.js +6 -6
|
@@ -67,7 +67,7 @@ class Compiler {
|
|
|
67
67
|
resolvePaths(moduleName, _containingFile) {
|
|
68
68
|
// console.log("resolvePaths", moduleName);
|
|
69
69
|
if (!this.options.paths) {
|
|
70
|
-
return
|
|
70
|
+
return undefined;
|
|
71
71
|
}
|
|
72
72
|
let paths = this.options.paths;
|
|
73
73
|
for (let key in paths) {
|
|
@@ -94,16 +94,16 @@ class Compiler {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
return
|
|
97
|
+
return undefined;
|
|
98
98
|
}
|
|
99
|
-
otherLocations(moduleName,
|
|
99
|
+
otherLocations(moduleName, _containingFile) {
|
|
100
100
|
for (const location of this.moduleSearchLocations) {
|
|
101
101
|
const modulePath = path.join(location, moduleName + ".d.ts");
|
|
102
102
|
if (typescript_1.default.sys.fileExists(modulePath)) {
|
|
103
103
|
return { resolvedFileName: modulePath };
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
return
|
|
106
|
+
return undefined;
|
|
107
107
|
}
|
|
108
108
|
readCompilerOptions() {
|
|
109
109
|
let json = {};
|
|
@@ -149,19 +149,17 @@ class Compiler {
|
|
|
149
149
|
// go through each moduleName and resolvers in order to see if we find what we're looking for
|
|
150
150
|
let resolvedModules = [];
|
|
151
151
|
for (const moduleName of moduleNames) {
|
|
152
|
+
// undefined is valid
|
|
153
|
+
let resolved;
|
|
152
154
|
for (const resolver of this.resolvers) {
|
|
153
155
|
let result = resolver(moduleName, containingFile);
|
|
154
156
|
// yay!
|
|
155
157
|
if (result) {
|
|
156
|
-
|
|
158
|
+
resolved = result;
|
|
157
159
|
break;
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
|
-
|
|
161
|
-
if (moduleNames.length !== resolvedModules.length) {
|
|
162
|
-
// TODO if not equal, we need to do more
|
|
163
|
-
// it doesn't seem to be coming here for node_modules here which is good
|
|
164
|
-
console.error("couldn't resolve everything", containingFile, moduleNames, resolvedModules);
|
|
162
|
+
resolvedModules.push(resolved);
|
|
165
163
|
}
|
|
166
164
|
return resolvedModules;
|
|
167
165
|
}
|
|
@@ -25,6 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const glob_1 = __importDefault(require("glob"));
|
|
27
27
|
const minimist_1 = __importDefault(require("minimist"));
|
|
28
|
+
const graphql_1 = require("../graphql/graphql");
|
|
28
29
|
const readline = __importStar(require("readline"));
|
|
29
30
|
const path = __importStar(require("path"));
|
|
30
31
|
const fs = __importStar(require("fs"));
|
|
@@ -52,7 +53,17 @@ async function readInputs() {
|
|
|
52
53
|
});
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
|
-
async function captureCustom(filePath) {
|
|
56
|
+
async function captureCustom(filePath, filesCsv) {
|
|
57
|
+
if (filesCsv !== undefined) {
|
|
58
|
+
let files = filesCsv.split(",");
|
|
59
|
+
for (let i = 0; i < files.length; i++) {
|
|
60
|
+
// TODO fix. we have "src" in the path we get here
|
|
61
|
+
files[i] = path.join(filePath, "..", files[i]);
|
|
62
|
+
}
|
|
63
|
+
await requireFiles(files);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// TODO delete all of this eventually
|
|
56
67
|
// TODO configurable paths eventually
|
|
57
68
|
// for now only files that are in the include path of the roots are allowed
|
|
58
69
|
const rootFiles = [
|
|
@@ -81,18 +92,28 @@ async function captureCustom(filePath) {
|
|
|
81
92
|
ignore: ignore,
|
|
82
93
|
});
|
|
83
94
|
const files = rootFiles.concat(customGQLResolvers, customGQLMutations);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
await requireFiles(files);
|
|
96
|
+
}
|
|
97
|
+
async function requireFiles(files) {
|
|
98
|
+
await Promise.all(files.map(async (file) => {
|
|
87
99
|
if (fs.existsSync(file)) {
|
|
88
|
-
|
|
100
|
+
try {
|
|
101
|
+
await require(file);
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
throw new Error(`${e.message} loading ${file}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new Error(`file ${file} doesn't exist`);
|
|
89
109
|
}
|
|
110
|
+
})).catch((err) => {
|
|
111
|
+
throw new Error(err);
|
|
90
112
|
});
|
|
91
|
-
await Promise.all(promises);
|
|
92
113
|
}
|
|
93
114
|
async function parseImports(filePath) {
|
|
94
115
|
// only do graphql files...
|
|
95
|
-
return imports_1.
|
|
116
|
+
return (0, imports_1.parseCustomImports)(path.join(filePath, "graphql"), {
|
|
96
117
|
ignore: ["**/generated/**", "**/tests/**"],
|
|
97
118
|
});
|
|
98
119
|
}
|
|
@@ -110,7 +131,21 @@ function findGraphQLPath(filePath) {
|
|
|
110
131
|
return undefined;
|
|
111
132
|
}
|
|
112
133
|
async function main() {
|
|
113
|
-
|
|
134
|
+
// known custom types that are not required
|
|
135
|
+
// if not in the schema, will be ignored
|
|
136
|
+
// something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
|
|
137
|
+
// these 2 need this because they're added by the schema
|
|
138
|
+
// if this list grows too long, need to build this into golang types and passed here
|
|
139
|
+
// TODO foreign non-scalars eventually
|
|
140
|
+
(0, graphql_1.addCustomType)({
|
|
141
|
+
importPath: "../graphql/scalars/time",
|
|
142
|
+
type: "GraphQLTime",
|
|
143
|
+
});
|
|
144
|
+
(0, graphql_1.addCustomType)({
|
|
145
|
+
importPath: "graphql-type-json",
|
|
146
|
+
type: "GraphQLJSON",
|
|
147
|
+
});
|
|
148
|
+
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
114
149
|
if (!options.path) {
|
|
115
150
|
throw new Error("path required");
|
|
116
151
|
}
|
|
@@ -126,7 +161,7 @@ async function main() {
|
|
|
126
161
|
GQLCapture.enable(true);
|
|
127
162
|
const [inputsRead, _, imports] = await Promise.all([
|
|
128
163
|
readInputs(),
|
|
129
|
-
captureCustom(options.path),
|
|
164
|
+
captureCustom(options.path, options.files),
|
|
130
165
|
parseImports(options.path),
|
|
131
166
|
]);
|
|
132
167
|
const { nodes, nodesMap } = inputsRead;
|
|
@@ -210,5 +245,5 @@ main()
|
|
|
210
245
|
.then()
|
|
211
246
|
.catch((err) => {
|
|
212
247
|
console.error(err);
|
|
213
|
-
process_1.exit(1);
|
|
248
|
+
(0, process_1.exit)(1);
|
|
214
249
|
});
|
package/scripts/read_schema.js
CHANGED
|
@@ -27,58 +27,9 @@ const path = __importStar(require("path"));
|
|
|
27
27
|
const pascal_case_1 = require("pascal-case");
|
|
28
28
|
const minimist_1 = __importDefault(require("minimist"));
|
|
29
29
|
const process_1 = require("process");
|
|
30
|
-
|
|
31
|
-
for (const field of src) {
|
|
32
|
-
let f = {};
|
|
33
|
-
f = field;
|
|
34
|
-
f["hasDefaultValueOnCreate"] = field.defaultValueOnCreate != undefined;
|
|
35
|
-
f["hasDefaultValueOnEdit"] = field.defaultValueOnEdit != undefined;
|
|
36
|
-
if (field.polymorphic) {
|
|
37
|
-
// convert boolean into object
|
|
38
|
-
// we keep boolean as an option to keep API simple
|
|
39
|
-
if (typeof field.polymorphic === "boolean") {
|
|
40
|
-
f["polymorphic"] = {};
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
f["polymorphic"] = field.polymorphic;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
dst.push(f);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
var NullableResult;
|
|
50
|
-
(function (NullableResult) {
|
|
51
|
-
NullableResult["CONTENTS"] = "contents";
|
|
52
|
-
NullableResult["CONTENTS_AND_LIST"] = "contentsAndList";
|
|
53
|
-
NullableResult["ITEM"] = "true";
|
|
54
|
-
})(NullableResult || (NullableResult = {}));
|
|
55
|
-
function processAction(action) {
|
|
56
|
-
if (!action.actionOnlyFields) {
|
|
57
|
-
return action;
|
|
58
|
-
}
|
|
59
|
-
let ret = action;
|
|
60
|
-
ret.actionOnlyFields = action.actionOnlyFields.map((f) => {
|
|
61
|
-
let f2 = f;
|
|
62
|
-
if (!f.nullable) {
|
|
63
|
-
return f2;
|
|
64
|
-
}
|
|
65
|
-
if (typeof f.nullable === "boolean") {
|
|
66
|
-
f2.nullable = NullableResult.ITEM;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
if (f.nullable === "contentsAndList") {
|
|
70
|
-
f2.nullable = NullableResult.CONTENTS_AND_LIST;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
f2.nullable = NullableResult.CONTENTS;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return f2;
|
|
77
|
-
});
|
|
78
|
-
return ret;
|
|
79
|
-
}
|
|
30
|
+
const parse_1 = require("../parse_schema/parse");
|
|
80
31
|
function main() {
|
|
81
|
-
const options = minimist_1.default(process.argv.slice(2));
|
|
32
|
+
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
82
33
|
if (!options.path) {
|
|
83
34
|
throw new Error("path required");
|
|
84
35
|
}
|
|
@@ -93,69 +44,16 @@ function main() {
|
|
|
93
44
|
if (!match) {
|
|
94
45
|
throw new Error(`non-typescript file ${p} returned by glob`);
|
|
95
46
|
}
|
|
96
|
-
potentialSchemas[pascal_case_1.pascalCase(match[1])] = require(p).default;
|
|
47
|
+
potentialSchemas[(0, pascal_case_1.pascalCase)(match[1])] = require(p).default;
|
|
97
48
|
}
|
|
98
49
|
// console.log(potentialSchemas);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const value = potentialSchemas[key];
|
|
102
|
-
let schema;
|
|
103
|
-
if (value.constructor == Object) {
|
|
104
|
-
schema = value;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
schema = new value();
|
|
108
|
-
}
|
|
109
|
-
// let's put patterns first just so we have id, created_at, updated_at first
|
|
110
|
-
// ¯\_(ツ)_/¯
|
|
111
|
-
let fields = [];
|
|
112
|
-
if (schema.patterns) {
|
|
113
|
-
for (const pattern of schema.patterns) {
|
|
114
|
-
processFields(fields, pattern.fields);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
processFields(fields, schema.fields);
|
|
118
|
-
let assocEdges = [];
|
|
119
|
-
let assocEdgeGroups = [];
|
|
120
|
-
if (schema.edges) {
|
|
121
|
-
for (const edge of schema.edges) {
|
|
122
|
-
let edge2 = edge;
|
|
123
|
-
edge2.edgeActions = edge.edgeActions?.map((action) => processAction(action));
|
|
124
|
-
assocEdges.push(edge2);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (schema.edgeGroups) {
|
|
128
|
-
// array-ify this
|
|
129
|
-
for (const group of schema.edgeGroups) {
|
|
130
|
-
if (group.nullStates && !Array.isArray(group.nullStates)) {
|
|
131
|
-
group.nullStates = [group.nullStates];
|
|
132
|
-
}
|
|
133
|
-
let group2 = group;
|
|
134
|
-
if (group.edgeAction) {
|
|
135
|
-
group2.edgeAction = processAction(group.edgeAction);
|
|
136
|
-
}
|
|
137
|
-
assocEdgeGroups.push(group2);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
schemas[key] = {
|
|
141
|
-
tableName: schema.tableName,
|
|
142
|
-
fields: fields,
|
|
143
|
-
assocEdges: assocEdges,
|
|
144
|
-
assocEdgeGroups: assocEdgeGroups,
|
|
145
|
-
actions: schema.actions?.map((action) => processAction(action)),
|
|
146
|
-
enumTable: schema.enumTable,
|
|
147
|
-
dbRows: schema.dbRows,
|
|
148
|
-
constraints: schema.constraints,
|
|
149
|
-
indices: schema.indices,
|
|
150
|
-
hideFromGraphQL: schema.hideFromGraphQL,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
console.log(JSON.stringify(schemas));
|
|
50
|
+
const result = (0, parse_1.parseSchema)(potentialSchemas);
|
|
51
|
+
console.log(JSON.stringify(result));
|
|
154
52
|
}
|
|
155
53
|
try {
|
|
156
54
|
main();
|
|
157
55
|
}
|
|
158
56
|
catch (err) {
|
|
159
57
|
console.error(err);
|
|
160
|
-
process_1.exit(1);
|
|
58
|
+
(0, process_1.exit)(1);
|
|
161
59
|
}
|
package/testutils/builder.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class User implements Ent {
|
|
|
9
9
|
accountID: string;
|
|
10
10
|
nodeType: string;
|
|
11
11
|
privacyPolicy: import("../core/base").PrivacyPolicy;
|
|
12
|
+
firstName: string;
|
|
12
13
|
constructor(viewer: Viewer, data: Data);
|
|
13
14
|
}
|
|
14
15
|
export declare class Event implements Ent {
|
|
@@ -65,12 +66,13 @@ export declare class SimpleBuilder<T extends Ent> implements Builder<T> {
|
|
|
65
66
|
viewer: Viewer;
|
|
66
67
|
private schema;
|
|
67
68
|
operation: WriteOperation;
|
|
68
|
-
existingEnt:
|
|
69
|
+
existingEnt: T | undefined;
|
|
69
70
|
ent: EntConstructor<T>;
|
|
70
71
|
placeholderID: ID;
|
|
71
72
|
orchestrator: Orchestrator<T>;
|
|
72
73
|
fields: Map<string, any>;
|
|
73
|
-
|
|
74
|
+
nodeType: string;
|
|
75
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation?: WriteOperation, existingEnt?: T | undefined, action?: Action<T> | undefined);
|
|
74
76
|
build(): Promise<Changeset<T>>;
|
|
75
77
|
editedEnt(): Promise<T | null>;
|
|
76
78
|
editedEntX(): Promise<T>;
|
|
@@ -92,12 +94,13 @@ export declare class SimpleAction<T extends Ent> implements Action<T> {
|
|
|
92
94
|
viewerForEntLoad: viewerEntLoadFunc | undefined;
|
|
93
95
|
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation?: WriteOperation, existingEnt?: T | undefined);
|
|
94
96
|
getPrivacyPolicy(): import("../core/base").PrivacyPolicy;
|
|
95
|
-
getInput():
|
|
97
|
+
getInput(): Data;
|
|
96
98
|
changeset(): Promise<Changeset<T>>;
|
|
97
99
|
valid(): Promise<boolean>;
|
|
98
100
|
validX(): Promise<void>;
|
|
99
101
|
save(): Promise<T | null>;
|
|
100
102
|
saveX(): Promise<T>;
|
|
101
103
|
editedEnt(): Promise<T | null>;
|
|
104
|
+
editedEntX(): Promise<T>;
|
|
102
105
|
}
|
|
103
106
|
export {};
|
package/testutils/builder.js
CHANGED
|
@@ -13,15 +13,18 @@ const pluralize_1 = __importDefault(require("pluralize"));
|
|
|
13
13
|
const snake_case_1 = require("snake-case");
|
|
14
14
|
const loaders_1 = require("../core/loaders");
|
|
15
15
|
const convert_1 = require("../core/convert");
|
|
16
|
+
const camel_case_1 = require("camel-case");
|
|
16
17
|
class User {
|
|
17
18
|
constructor(viewer, data) {
|
|
18
19
|
this.viewer = viewer;
|
|
19
20
|
this.data = data;
|
|
21
|
+
this.accountID = "";
|
|
20
22
|
this.nodeType = "User";
|
|
21
23
|
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
22
|
-
this.data.created_at = convert_1.convertDate(data.created_at);
|
|
23
|
-
this.data.updated_at = convert_1.convertDate(data.updated_at);
|
|
24
|
+
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
25
|
+
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
24
26
|
this.id = data.id;
|
|
27
|
+
this.firstName = data.first_name;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
exports.User = User;
|
|
@@ -29,6 +32,7 @@ class Event {
|
|
|
29
32
|
constructor(viewer, data) {
|
|
30
33
|
this.viewer = viewer;
|
|
31
34
|
this.data = data;
|
|
35
|
+
this.accountID = "";
|
|
32
36
|
this.nodeType = "Event";
|
|
33
37
|
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
34
38
|
this.id = data.id;
|
|
@@ -39,10 +43,11 @@ class Contact {
|
|
|
39
43
|
constructor(viewer, data) {
|
|
40
44
|
this.viewer = viewer;
|
|
41
45
|
this.data = data;
|
|
46
|
+
this.accountID = "";
|
|
42
47
|
this.nodeType = "Contact";
|
|
43
48
|
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
44
|
-
this.data.created_at = convert_1.convertDate(data.created_at);
|
|
45
|
-
this.data.updated_at = convert_1.convertDate(data.updated_at);
|
|
49
|
+
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
50
|
+
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
46
51
|
this.id = data.id;
|
|
47
52
|
}
|
|
48
53
|
}
|
|
@@ -51,6 +56,7 @@ class Group {
|
|
|
51
56
|
constructor(viewer, data) {
|
|
52
57
|
this.viewer = viewer;
|
|
53
58
|
this.data = data;
|
|
59
|
+
this.accountID = "";
|
|
54
60
|
this.nodeType = "Group";
|
|
55
61
|
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
56
62
|
this.id = data.id;
|
|
@@ -61,6 +67,7 @@ class Message {
|
|
|
61
67
|
constructor(viewer, data) {
|
|
62
68
|
this.viewer = viewer;
|
|
63
69
|
this.data = data;
|
|
70
|
+
this.accountID = "";
|
|
64
71
|
this.nodeType = "Message";
|
|
65
72
|
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
66
73
|
this.id = data.id;
|
|
@@ -71,6 +78,7 @@ class Address {
|
|
|
71
78
|
constructor(viewer, data) {
|
|
72
79
|
this.viewer = viewer;
|
|
73
80
|
this.data = data;
|
|
81
|
+
this.accountID = "";
|
|
74
82
|
this.nodeType = "Address";
|
|
75
83
|
this.privacyPolicy = privacy_1.AlwaysAllowPrivacyPolicy;
|
|
76
84
|
this.id = data.id;
|
|
@@ -82,7 +90,7 @@ function getSchemaName(value) {
|
|
|
82
90
|
}
|
|
83
91
|
exports.getSchemaName = getSchemaName;
|
|
84
92
|
function getTableName(value) {
|
|
85
|
-
return pluralize_1.default(snake_case_1.snakeCase(value.ent.name)).toLowerCase();
|
|
93
|
+
return (0, pluralize_1.default)((0, snake_case_1.snakeCase)(value.ent.name)).toLowerCase();
|
|
86
94
|
}
|
|
87
95
|
exports.getTableName = getTableName;
|
|
88
96
|
function randomNum() {
|
|
@@ -107,18 +115,19 @@ class SimpleBuilder {
|
|
|
107
115
|
}
|
|
108
116
|
}
|
|
109
117
|
this.fields = fields;
|
|
110
|
-
const schemaFields = schema_1.getFields(schema);
|
|
118
|
+
const schemaFields = (0, schema_1.getFields)(schema);
|
|
111
119
|
let key = "id";
|
|
112
120
|
if (!schemaFields.has("id") && !schemaFields.has("ID")) {
|
|
113
121
|
if (schemaFields.size !== 1) {
|
|
114
122
|
throw new Error(`no id field and multiple fields so can't deduce key. add an id field to schema`);
|
|
115
123
|
}
|
|
116
124
|
for (const [name, _] of fields) {
|
|
117
|
-
key = snake_case_1.snakeCase(name);
|
|
125
|
+
key = (0, snake_case_1.snakeCase)(name);
|
|
118
126
|
}
|
|
119
127
|
}
|
|
120
128
|
this.ent = schema.ent;
|
|
121
129
|
const tableName = getTableName(schema);
|
|
130
|
+
this.nodeType = (0, camel_case_1.camelCase)(schema.ent.name);
|
|
122
131
|
this.orchestrator = new orchestrator_1.Orchestrator({
|
|
123
132
|
viewer: this.viewer,
|
|
124
133
|
operation: operation,
|
|
@@ -152,10 +161,10 @@ class SimpleBuilder {
|
|
|
152
161
|
return await this.orchestrator.editedEntX();
|
|
153
162
|
}
|
|
154
163
|
async save() {
|
|
155
|
-
await action_1.saveBuilder(this);
|
|
164
|
+
await (0, action_1.saveBuilder)(this);
|
|
156
165
|
}
|
|
157
166
|
async saveX() {
|
|
158
|
-
await action_1.saveBuilderX(this);
|
|
167
|
+
await (0, action_1.saveBuilderX)(this);
|
|
159
168
|
}
|
|
160
169
|
async valid() {
|
|
161
170
|
return await this.orchestrator.valid();
|
|
@@ -178,7 +187,11 @@ class SimpleAction {
|
|
|
178
187
|
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
179
188
|
}
|
|
180
189
|
getInput() {
|
|
181
|
-
|
|
190
|
+
const ret = {};
|
|
191
|
+
for (const [k, v] of this.fields) {
|
|
192
|
+
ret[k] = v;
|
|
193
|
+
}
|
|
194
|
+
return ret;
|
|
182
195
|
}
|
|
183
196
|
changeset() {
|
|
184
197
|
return this.builder.build();
|
|
@@ -190,18 +203,21 @@ class SimpleAction {
|
|
|
190
203
|
return this.builder.orchestrator.validX();
|
|
191
204
|
}
|
|
192
205
|
async save() {
|
|
193
|
-
await action_1.saveBuilder(this.builder);
|
|
206
|
+
await (0, action_1.saveBuilder)(this.builder);
|
|
194
207
|
if (this.builder.operation !== action_1.WriteOperation.Delete) {
|
|
195
|
-
return
|
|
208
|
+
return this.builder.orchestrator.editedEnt();
|
|
196
209
|
}
|
|
197
210
|
return null;
|
|
198
211
|
}
|
|
199
212
|
async saveX() {
|
|
200
|
-
await action_1.saveBuilderX(this.builder);
|
|
201
|
-
return
|
|
213
|
+
await (0, action_1.saveBuilderX)(this.builder);
|
|
214
|
+
return this.builder.orchestrator.editedEntX();
|
|
202
215
|
}
|
|
203
216
|
async editedEnt() {
|
|
204
|
-
return
|
|
217
|
+
return this.builder.orchestrator.editedEnt();
|
|
218
|
+
}
|
|
219
|
+
async editedEntX() {
|
|
220
|
+
return this.builder.orchestrator.editedEntX();
|
|
205
221
|
}
|
|
206
222
|
}
|
|
207
223
|
exports.SimpleAction = SimpleAction;
|
|
@@ -10,6 +10,7 @@ interface Column extends SchemaItem {
|
|
|
10
10
|
datatype(): string;
|
|
11
11
|
nullable?: boolean;
|
|
12
12
|
primaryKey?: boolean;
|
|
13
|
+
unique?: boolean;
|
|
13
14
|
default?: string;
|
|
14
15
|
foreignKey?: {
|
|
15
16
|
table: string;
|
|
@@ -19,21 +20,25 @@ interface Column extends SchemaItem {
|
|
|
19
20
|
interface Constraint extends SchemaItem {
|
|
20
21
|
generate(): string;
|
|
21
22
|
}
|
|
22
|
-
export interface
|
|
23
|
+
export interface CoreConcept {
|
|
23
24
|
name: string;
|
|
24
|
-
columns: Column[];
|
|
25
|
-
constraints?: Constraint[];
|
|
26
25
|
create(): string;
|
|
27
26
|
drop(): string;
|
|
28
27
|
}
|
|
29
|
-
|
|
28
|
+
export interface Table extends CoreConcept {
|
|
29
|
+
columns: Column[];
|
|
30
|
+
constraints?: Constraint[];
|
|
31
|
+
}
|
|
32
|
+
declare type options = Pick<Column, "nullable" | "primaryKey" | "default" | "foreignKey" | "unique">;
|
|
30
33
|
export declare function primaryKey(name: string, cols: string[]): Constraint;
|
|
31
34
|
export declare function foreignKey(name: string, cols: string[], fkey: {
|
|
32
35
|
table: string;
|
|
33
36
|
cols: string[];
|
|
34
37
|
}): Constraint;
|
|
38
|
+
export declare function uniqueIndex(name: string): Constraint;
|
|
35
39
|
export declare function uuid(name: string, opts?: options): Column;
|
|
36
40
|
export declare function text(name: string, opts?: options): Column;
|
|
41
|
+
export declare function enumCol(name: string, type: string): Column;
|
|
37
42
|
export declare function timestamp(name: string, opts?: options): Column;
|
|
38
43
|
export declare function timestamptz(name: string, opts?: options): Column;
|
|
39
44
|
export declare function time(name: string, opts?: options): Column;
|
|
@@ -42,6 +47,8 @@ export declare function date(name: string, opts?: options): Column;
|
|
|
42
47
|
export declare function bool(name: string, opts?: options): Column;
|
|
43
48
|
export declare function integer(name: string, opts?: options): Column;
|
|
44
49
|
export declare function float(name: string, opts?: options): Column;
|
|
50
|
+
export declare function json(name: string, opts?: options): Column;
|
|
51
|
+
export declare function jsonb(name: string, opts?: options): Column;
|
|
45
52
|
export declare function textList(name: string, opts?: options): Column;
|
|
46
53
|
export declare function integerList(name: string, opts?: options): Column;
|
|
47
54
|
export declare function uuidList(name: string, opts?: options): Column;
|
|
@@ -52,6 +59,7 @@ export declare function timetzList(name: string, opts?: options): Column;
|
|
|
52
59
|
export declare function dateList(name: string, opts?: options): Column;
|
|
53
60
|
export declare function boolList(name: string, opts?: options): Column;
|
|
54
61
|
export declare function table(name: string, ...items: SchemaItem[]): Table;
|
|
62
|
+
export declare function enumType(name: string, values: string[]): CoreConcept;
|
|
55
63
|
export declare class TempDB {
|
|
56
64
|
private db;
|
|
57
65
|
private client;
|
|
@@ -59,17 +67,17 @@ export declare class TempDB {
|
|
|
59
67
|
private tables;
|
|
60
68
|
private dialect;
|
|
61
69
|
private sqlite;
|
|
62
|
-
constructor(dialect: Dialect, tables?:
|
|
63
|
-
constructor(tables:
|
|
70
|
+
constructor(dialect: Dialect, tables?: CoreConcept[]);
|
|
71
|
+
constructor(tables: CoreConcept[]);
|
|
64
72
|
getDialect(): Dialect;
|
|
65
|
-
getTables(): Map<string,
|
|
73
|
+
getTables(): Map<string, CoreConcept>;
|
|
66
74
|
beforeAll(): Promise<void>;
|
|
67
75
|
getSqliteClient(): SqliteDatabase;
|
|
68
76
|
getPostgresClient(): PGClient;
|
|
69
77
|
afterAll(): Promise<void>;
|
|
70
78
|
dropAll(): Promise<void>;
|
|
71
79
|
drop(...tables: string[]): Promise<void>;
|
|
72
|
-
create(...tables:
|
|
80
|
+
create(...tables: CoreConcept[]): Promise<void>;
|
|
73
81
|
}
|
|
74
82
|
export declare function assoc_edge_config_table(): Table;
|
|
75
83
|
export declare function assoc_edge_table(name: string): Table;
|