@snowtop/ent 0.1.0-alpha90 → 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/orchestrator.js +5 -1
- package/core/clause.d.ts +15 -0
- package/core/clause.js +44 -2
- package/core/config.js +5 -1
- package/core/db.js +5 -1
- package/core/ent.js +7 -8
- package/core/loaders/assoc_count_loader.d.ts +1 -0
- package/core/loaders/assoc_count_loader.js +8 -1
- package/core/loaders/assoc_edge_loader.js +5 -1
- package/core/loaders/object_loader.js +5 -1
- package/core/loaders/query_loader.js +5 -1
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/privacy.d.ts +6 -6
- package/core/query/assoc_query.d.ts +1 -0
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +2 -0
- package/core/query/custom_clause_query.js +9 -3
- package/core/query/custom_query.d.ts +2 -2
- package/core/query/custom_query.js +29 -21
- package/core/query/query.d.ts +7 -3
- package/core/query/query.js +101 -60
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +24 -45
- package/core/query/shared_test.d.ts +5 -1
- package/core/query/shared_test.js +354 -301
- package/graphql/graphql.js +10 -6
- package/graphql/query/shared_edge_connection.js +1 -15
- package/imports/index.js +5 -1
- package/index.js +5 -1
- package/package.json +1 -1
- package/schema/field.js +11 -1
- package/schema/index.js +5 -1
- package/schema/schema.d.ts +1 -0
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +5 -1
- package/scripts/read_schema.js +5 -1
- package/testutils/db/temp_db.d.ts +6 -5
- package/testutils/db/temp_db.js +40 -28
- package/testutils/db_mock.js +3 -1
- 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 +2 -0
- 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 +2 -0
- 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 +8 -2
- package/testutils/fake_data/test_helpers.js +21 -7
- package/testutils/fake_data/user_query.d.ts +5 -0
- package/testutils/fake_data/user_query.js +28 -3
- package/testutils/test_edge_global_schema.js +5 -1
- package/testutils/write.js +5 -1
- package/tsc/ast.js +5 -1
- package/tsc/compilerOptions.js +5 -1
- package/tsc/move_generated.js +5 -1
- package/tsc/transform.js +5 -1
- package/tsc/transform_action.js +5 -1
- package/tsc/transform_schema.js +5 -1
package/graphql/graphql.js
CHANGED
|
@@ -63,11 +63,9 @@ const isGraphQLScalarType = (type) => {
|
|
|
63
63
|
};
|
|
64
64
|
const addCustomType = (type) => {
|
|
65
65
|
// TODO these should return ReadOnly objects...
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
if (customType) {
|
|
66
|
+
const customTypes = GQLCapture.getCustomTypes();
|
|
67
|
+
const customType = customTypes.get(type.type);
|
|
68
|
+
if (customType && customType === type) {
|
|
71
69
|
return;
|
|
72
70
|
}
|
|
73
71
|
try {
|
|
@@ -93,7 +91,13 @@ const addCustomType = (type) => {
|
|
|
93
91
|
}
|
|
94
92
|
return;
|
|
95
93
|
}
|
|
96
|
-
|
|
94
|
+
if (customType) {
|
|
95
|
+
if (JSON.stringify(customType) !== JSON.stringify(type)) {
|
|
96
|
+
throw new Error(`cannot add multiple custom types of name ${type.type}`);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
customTypes.set(type.type, type);
|
|
97
101
|
};
|
|
98
102
|
exports.addCustomType = addCustomType;
|
|
99
103
|
const getType = (typ, result) => {
|
|
@@ -48,23 +48,9 @@ class TestConnection {
|
|
|
48
48
|
}
|
|
49
49
|
const commonTests = (opts) => {
|
|
50
50
|
function getCursorFrom(contacts, idx) {
|
|
51
|
-
// we depend on the fact that the same time is used for the edge and created_at
|
|
52
|
-
// based on getContactBuilder
|
|
53
|
-
// so regardless of if we're doing assoc or custom queries, we can get the time
|
|
54
|
-
// from the created_at field
|
|
55
51
|
return (0, ent_1.getCursor)({
|
|
56
52
|
row: contacts[idx],
|
|
57
|
-
col: "
|
|
58
|
-
conv: (t) => {
|
|
59
|
-
//sqlite
|
|
60
|
-
if (typeof t === "string") {
|
|
61
|
-
return Date.parse(t);
|
|
62
|
-
}
|
|
63
|
-
return t.getTime();
|
|
64
|
-
},
|
|
65
|
-
// we want the right column to be encoded in the cursor as opposed e.g. time for
|
|
66
|
-
// assoc queries, created_at for index/custom queries
|
|
67
|
-
cursorKey: opts.sortCol,
|
|
53
|
+
col: "id",
|
|
68
54
|
});
|
|
69
55
|
}
|
|
70
56
|
describe("no filters", () => {
|
package/imports/index.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];
|
package/index.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];
|
package/package.json
CHANGED
package/schema/field.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];
|
|
@@ -75,16 +79,22 @@ class UUIDField extends BaseField {
|
|
|
75
79
|
derivedWhenEmbedded: true,
|
|
76
80
|
nullable: this.options?.nullable,
|
|
77
81
|
parentFieldToValidate: fieldName,
|
|
82
|
+
serverDefault: polymorphic.serverDefault,
|
|
78
83
|
}),
|
|
79
84
|
};
|
|
80
85
|
}
|
|
81
86
|
else {
|
|
87
|
+
let serverDefault = undefined;
|
|
88
|
+
if (typeof polymorphic === "object") {
|
|
89
|
+
serverDefault = polymorphic.serverDefault;
|
|
90
|
+
}
|
|
82
91
|
return {
|
|
83
92
|
[name]: PolymorphicStringType({
|
|
84
93
|
hideFromGraphQL: true,
|
|
85
94
|
derivedWhenEmbedded: true,
|
|
86
95
|
nullable: this.options?.nullable,
|
|
87
96
|
parentFieldToValidate: fieldName,
|
|
97
|
+
serverDefault: serverDefault,
|
|
88
98
|
}),
|
|
89
99
|
};
|
|
90
100
|
}
|
package/schema/index.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];
|
package/schema/schema.d.ts
CHANGED
|
@@ -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];
|
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];
|
|
@@ -24,6 +24,7 @@ interface Constraint extends SchemaItem {
|
|
|
24
24
|
}
|
|
25
25
|
interface Index extends SchemaItem {
|
|
26
26
|
generate(): string;
|
|
27
|
+
postCreate?(): boolean;
|
|
27
28
|
}
|
|
28
29
|
export interface CoreConcept {
|
|
29
30
|
name: string;
|
|
@@ -42,10 +43,10 @@ export declare function foreignKey(name: string, cols: string[], fkey: {
|
|
|
42
43
|
cols: string[];
|
|
43
44
|
}): Constraint;
|
|
44
45
|
interface indexOptions {
|
|
45
|
-
type
|
|
46
|
+
type?: string;
|
|
47
|
+
unique?: boolean;
|
|
46
48
|
}
|
|
47
49
|
export declare function index(tableName: string, cols: string[], opts?: indexOptions): Index;
|
|
48
|
-
export declare function uniqueIndex(name: string): Constraint;
|
|
49
50
|
export declare function uuid(name: string, opts?: options): Column;
|
|
50
51
|
export declare function text(name: string, opts?: options): Column;
|
|
51
52
|
export declare function enumCol(name: string, type: string): Column;
|
|
@@ -77,10 +78,10 @@ export declare class TempDB {
|
|
|
77
78
|
private tables;
|
|
78
79
|
private dialect;
|
|
79
80
|
private sqlite;
|
|
80
|
-
|
|
81
|
-
constructor(
|
|
81
|
+
private setTables;
|
|
82
|
+
constructor(dialect: Dialect, tables?: CoreConcept[] | (() => CoreConcept[]));
|
|
82
83
|
getDialect(): Dialect;
|
|
83
|
-
|
|
84
|
+
__getTables(): Map<string, CoreConcept>;
|
|
84
85
|
beforeAll(setupConnString?: boolean): Promise<void>;
|
|
85
86
|
createImpl(table: CoreConcept): Promise<void>;
|
|
86
87
|
getSqliteClient(): SqliteDatabase;
|
package/testutils/db/temp_db.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];
|
|
@@ -22,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.getColumnFromField = exports.getSchemaTable = exports.setupSqlite = exports.assoc_edge_table = exports.assoc_edge_config_table = exports.TempDB = exports.enumType = exports.table = exports.boolList = exports.dateList = exports.timetzList = exports.timeList = exports.timestamptzList = exports.timestampList = exports.uuidList = exports.integerList = exports.textList = exports.jsonb = exports.json = exports.float = exports.integer = exports.bool = exports.date = exports.timetz = exports.time = exports.timestamptz = exports.timestamp = exports.enumCol = exports.text = exports.uuid = exports.
|
|
29
|
+
exports.getColumnFromField = exports.getSchemaTable = exports.setupSqlite = exports.assoc_edge_table = exports.assoc_edge_config_table = exports.TempDB = exports.enumType = exports.table = exports.boolList = exports.dateList = exports.timetzList = exports.timeList = exports.timestamptzList = exports.timestampList = exports.uuidList = exports.integerList = exports.textList = exports.jsonb = exports.json = exports.float = exports.integer = exports.bool = exports.date = exports.timetz = exports.time = exports.timestamptz = exports.timestamp = exports.enumCol = exports.text = exports.uuid = exports.index = exports.foreignKey = exports.primaryKey = void 0;
|
|
26
30
|
const pg_1 = require("pg");
|
|
27
31
|
const db_1 = __importStar(require("../../core/db"));
|
|
28
32
|
// this should only be used in tests so we expect to be able to import without shenanigans
|
|
@@ -51,25 +55,26 @@ function foreignKey(name, cols, fkey) {
|
|
|
51
55
|
};
|
|
52
56
|
}
|
|
53
57
|
exports.foreignKey = foreignKey;
|
|
58
|
+
function isPostCreateIndex(s) {
|
|
59
|
+
return (s.postCreate !== undefined &&
|
|
60
|
+
s.postCreate());
|
|
61
|
+
}
|
|
54
62
|
function index(tableName, cols, opts) {
|
|
55
63
|
const name = `${tableName}_${cols.join("_")}_idx`;
|
|
56
64
|
return {
|
|
57
65
|
name,
|
|
58
66
|
generate() {
|
|
59
|
-
|
|
67
|
+
if (opts?.unique && db_1.Dialect.SQLite === db_1.default.getDialect()) {
|
|
68
|
+
return `UNIQUE (${cols.join(",")})`;
|
|
69
|
+
}
|
|
70
|
+
return `CREATE ${opts?.unique ? "UNIQUE " : ""}INDEX ${name} ON ${tableName} USING ${opts?.type || "btree"} (${cols.join(",")});`;
|
|
60
71
|
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
exports.index = index;
|
|
64
|
-
function uniqueIndex(name) {
|
|
65
|
-
return {
|
|
66
|
-
name: "",
|
|
67
|
-
generate() {
|
|
68
|
-
return `UNIQUE (${name})`;
|
|
72
|
+
postCreate() {
|
|
73
|
+
return db_1.Dialect.Postgres === db_1.default.getDialect() && !!opts?.unique;
|
|
69
74
|
},
|
|
70
75
|
};
|
|
71
76
|
}
|
|
72
|
-
exports.
|
|
77
|
+
exports.index = index;
|
|
73
78
|
function uuid(name, opts) {
|
|
74
79
|
return {
|
|
75
80
|
name,
|
|
@@ -287,7 +292,12 @@ function table(name, ...items) {
|
|
|
287
292
|
cols.push(item);
|
|
288
293
|
}
|
|
289
294
|
else if (item.generate !== undefined) {
|
|
290
|
-
|
|
295
|
+
if (isPostCreateIndex(item) && item.postCreate()) {
|
|
296
|
+
indexes.push(item);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
constraints.push(item);
|
|
300
|
+
}
|
|
291
301
|
}
|
|
292
302
|
}
|
|
293
303
|
return {
|
|
@@ -351,23 +361,15 @@ function isDialect(dialect) {
|
|
|
351
361
|
class TempDB {
|
|
352
362
|
constructor(dialect, tables) {
|
|
353
363
|
this.tables = new Map();
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
this.dialect = dialect;
|
|
357
|
-
if (tables) {
|
|
358
|
-
tbles = tables;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
this.dialect = db_1.Dialect.Postgres;
|
|
363
|
-
tbles = dialect;
|
|
364
|
-
}
|
|
365
|
-
tbles.forEach((table) => this.tables.set(table.name, table));
|
|
364
|
+
this.dialect = dialect;
|
|
365
|
+
this.setTables = tables;
|
|
366
366
|
}
|
|
367
367
|
getDialect() {
|
|
368
368
|
return this.dialect;
|
|
369
369
|
}
|
|
370
|
-
|
|
370
|
+
// NB: this won't be set until after beforeAll() is called since it depends on
|
|
371
|
+
// dialect being correctly set
|
|
372
|
+
__getTables() {
|
|
371
373
|
return this.tables;
|
|
372
374
|
}
|
|
373
375
|
async beforeAll(setupConnString = true) {
|
|
@@ -410,6 +412,16 @@ class TempDB {
|
|
|
410
412
|
const filePath = process.env.DB_CONNECTION_STRING.substr(10);
|
|
411
413
|
this.sqlite = (0, better_sqlite3_1.default)(filePath);
|
|
412
414
|
}
|
|
415
|
+
if (this.setTables) {
|
|
416
|
+
let tables = [];
|
|
417
|
+
if (typeof this.setTables === "function") {
|
|
418
|
+
tables = this.setTables();
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
tables = this.setTables;
|
|
422
|
+
}
|
|
423
|
+
tables.forEach((table) => this.tables.set(table.name, table));
|
|
424
|
+
}
|
|
413
425
|
for (const [_, table] of this.tables) {
|
|
414
426
|
await this.createImpl(table);
|
|
415
427
|
}
|
|
@@ -507,7 +519,7 @@ function assoc_edge_table(name, global) {
|
|
|
507
519
|
}
|
|
508
520
|
exports.assoc_edge_table = assoc_edge_table;
|
|
509
521
|
function setupSqlite(connString, tables, opts) {
|
|
510
|
-
let tdb = new TempDB(db_1.Dialect.SQLite, tables
|
|
522
|
+
let tdb = new TempDB(db_1.Dialect.SQLite, tables);
|
|
511
523
|
beforeAll(async () => {
|
|
512
524
|
process.env.DB_CONNECTION_STRING = connString;
|
|
513
525
|
(0, config_1.loadConfig)();
|
|
@@ -518,7 +530,7 @@ function setupSqlite(connString, tables, opts) {
|
|
|
518
530
|
if (!opts?.disableDeleteAfterEachTest) {
|
|
519
531
|
afterEach(async () => {
|
|
520
532
|
const client = await db_1.default.getInstance().getNewClient();
|
|
521
|
-
for (const [key, _] of tdb.
|
|
533
|
+
for (const [key, _] of tdb.__getTables()) {
|
|
522
534
|
const query = `delete from ${key}`;
|
|
523
535
|
if (isSyncClient(client))
|
|
524
536
|
if (client.execSync) {
|
package/testutils/db_mock.js
CHANGED
|
@@ -185,7 +185,9 @@ class QueryRecorder {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
static mockPool(pool) {
|
|
188
|
-
const mockedPool = (0, jest_mock_1.mocked)(pool
|
|
188
|
+
const mockedPool = (0, jest_mock_1.mocked)(pool);
|
|
189
|
+
// @ts-ignore
|
|
190
|
+
// TODO what changed in mockImplementation?
|
|
189
191
|
mockedPool.mockImplementation(() => {
|
|
190
192
|
return {
|
|
191
193
|
totalCount: 1,
|
|
@@ -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];
|
|
@@ -45,6 +49,7 @@ function server(config) {
|
|
|
45
49
|
if (config.init) {
|
|
46
50
|
config.init(app);
|
|
47
51
|
}
|
|
52
|
+
// @ts-ignore something changed. come back
|
|
48
53
|
app.use(express_1.default.json());
|
|
49
54
|
let handlers = config.customHandlers || [];
|
|
50
55
|
handlers.push(async (req, res) => {
|
|
@@ -56,9 +61,11 @@ function server(config) {
|
|
|
56
61
|
request: req,
|
|
57
62
|
schema: config.schema,
|
|
58
63
|
contextFactory: async (executionContext) => {
|
|
64
|
+
// @ts-ignore something changed. come back
|
|
59
65
|
return (0, auth_1.buildContext)(req, res);
|
|
60
66
|
},
|
|
61
67
|
});
|
|
68
|
+
// @ts-ignore something changed. come back
|
|
62
69
|
await (0, graphql_helix_1.sendResult)(result, res);
|
|
63
70
|
});
|
|
64
71
|
app.use(config.graphQLPath || "/graphql", ...handlers);
|
|
@@ -18,7 +18,8 @@ export declare enum EdgeType {
|
|
|
18
18
|
export declare enum NodeType {
|
|
19
19
|
FakeUser = "user",
|
|
20
20
|
FakeContact = "contact",
|
|
21
|
-
FakeEvent = "event"
|
|
21
|
+
FakeEvent = "event",
|
|
22
|
+
FakeTag = "tag"
|
|
22
23
|
}
|
|
23
24
|
export declare const SymmetricEdges: Set<string>;
|
|
24
25
|
export declare const InverseEdges: Map<EdgeType, EdgeType>;
|
|
@@ -27,6 +27,7 @@ var NodeType;
|
|
|
27
27
|
NodeType["FakeUser"] = "user";
|
|
28
28
|
NodeType["FakeContact"] = "contact";
|
|
29
29
|
NodeType["FakeEvent"] = "event";
|
|
30
|
+
NodeType["FakeTag"] = "tag";
|
|
30
31
|
})(NodeType = exports.NodeType || (exports.NodeType = {}));
|
|
31
32
|
exports.SymmetricEdges = new Set();
|
|
32
33
|
exports.SymmetricEdges.add(EdgeType.UserToFriends);
|
|
@@ -48,6 +49,8 @@ function getLoaderOptions(type) {
|
|
|
48
49
|
return internal_1.FakeUser.loaderOptions();
|
|
49
50
|
case NodeType.FakeEvent:
|
|
50
51
|
return internal_1.FakeEvent.loaderOptions();
|
|
52
|
+
case NodeType.FakeTag:
|
|
53
|
+
return internal_1.FakeTag.loaderOptions();
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
exports.getLoaderOptions = getLoaderOptions;
|
|
@@ -28,6 +28,8 @@ export interface ContactCreateInput {
|
|
|
28
28
|
lastName: string;
|
|
29
29
|
emailAddress: string;
|
|
30
30
|
userID: ID;
|
|
31
|
+
createdAt?: Date;
|
|
32
|
+
updatedAt?: Date;
|
|
31
33
|
}
|
|
32
34
|
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
|
|
33
35
|
export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy } from "../../core/base";
|
|
2
|
+
import { SimpleAction } from "../builder";
|
|
3
|
+
import { NodeType } from "./const";
|
|
4
|
+
import { ObjectLoaderFactory } from "../../core/loaders";
|
|
5
|
+
export declare class FakeTag implements Ent {
|
|
6
|
+
viewer: Viewer;
|
|
7
|
+
readonly id: ID;
|
|
8
|
+
readonly data: Data;
|
|
9
|
+
readonly nodeType = NodeType.FakeUser;
|
|
10
|
+
readonly createdAt: Date;
|
|
11
|
+
readonly updatedAt: Date;
|
|
12
|
+
readonly displayName: string;
|
|
13
|
+
readonly canonicalName: string;
|
|
14
|
+
readonly ownerID: string;
|
|
15
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
16
|
+
constructor(viewer: Viewer, data: Data);
|
|
17
|
+
static getFields(): string[];
|
|
18
|
+
static getTestTable(): import("../db/temp_db").Table;
|
|
19
|
+
static loaderOptions(): LoadEntOptions<FakeTag>;
|
|
20
|
+
static load(v: Viewer, id: ID): Promise<FakeTag | null>;
|
|
21
|
+
static loadX(v: Viewer, id: ID): Promise<FakeTag>;
|
|
22
|
+
}
|
|
23
|
+
export declare const FakeTagSchema: import("../builder").BuilderSchema<FakeTag>;
|
|
24
|
+
export interface TagCreateInput {
|
|
25
|
+
displayName: string;
|
|
26
|
+
canonicalName: string;
|
|
27
|
+
ownerID: ID;
|
|
28
|
+
createdAt?: Date;
|
|
29
|
+
updatedAt?: Date;
|
|
30
|
+
}
|
|
31
|
+
export declare type TagEditInput = Partial<TagCreateInput>;
|
|
32
|
+
export declare function getTagBuilder(viewer: Viewer, input: TagCreateInput): import("../builder").SimpleBuilder<FakeTag, null>;
|
|
33
|
+
export declare function getTagAction(viewer: Viewer, input: TagCreateInput): SimpleAction<FakeTag, null>;
|
|
34
|
+
export declare function createTag(viewer: Viewer, input: TagCreateInput): Promise<FakeTag>;
|
|
35
|
+
export declare const tagLoader: ObjectLoaderFactory<unknown>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tagLoader = exports.createTag = exports.getTagAction = exports.getTagBuilder = exports.FakeTagSchema = exports.FakeTag = void 0;
|
|
4
|
+
const ent_1 = require("../../core/ent");
|
|
5
|
+
const privacy_1 = require("../../core/privacy");
|
|
6
|
+
const builder_1 = require("../builder");
|
|
7
|
+
const schema_1 = require("../../schema");
|
|
8
|
+
const const_1 = require("./const");
|
|
9
|
+
const temp_db_1 = require("../db/temp_db");
|
|
10
|
+
const loaders_1 = require("../../core/loaders");
|
|
11
|
+
const convert_1 = require("../../core/convert");
|
|
12
|
+
const action_1 = require("../../action");
|
|
13
|
+
class FakeTag {
|
|
14
|
+
constructor(viewer, data) {
|
|
15
|
+
this.viewer = viewer;
|
|
16
|
+
this.nodeType = const_1.NodeType.FakeUser;
|
|
17
|
+
this.data = data;
|
|
18
|
+
this.id = data.id;
|
|
19
|
+
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
20
|
+
this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
|
|
21
|
+
this.displayName = data.display_name;
|
|
22
|
+
this.canonicalName = data.canonical_name;
|
|
23
|
+
this.ownerID = data.owner_id;
|
|
24
|
+
}
|
|
25
|
+
getPrivacyPolicy() {
|
|
26
|
+
return {
|
|
27
|
+
rules: [new privacy_1.AllowIfViewerIsEntPropertyRule("ownerID"), privacy_1.AlwaysDenyRule],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
static getFields() {
|
|
31
|
+
return [
|
|
32
|
+
"id",
|
|
33
|
+
"created_at",
|
|
34
|
+
"updated_at",
|
|
35
|
+
"display_name",
|
|
36
|
+
"canonical_name",
|
|
37
|
+
"owner_id",
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
static getTestTable() {
|
|
41
|
+
return (0, temp_db_1.table)("fake_tags", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"), (0, temp_db_1.text)("display_name"), (0, temp_db_1.text)("canonical_name"), (0, temp_db_1.uuid)("owner_id"), // TODO index: true sqlite broken?
|
|
42
|
+
(0, temp_db_1.index)("fake_tags", ["canonical_name", "owner_id"], { unique: true }));
|
|
43
|
+
}
|
|
44
|
+
static loaderOptions() {
|
|
45
|
+
return {
|
|
46
|
+
tableName: "fake_tags",
|
|
47
|
+
fields: FakeTag.getFields(),
|
|
48
|
+
ent: this,
|
|
49
|
+
loaderFactory: exports.tagLoader,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
static async load(v, id) {
|
|
53
|
+
return (0, ent_1.loadEnt)(v, id, FakeTag.loaderOptions());
|
|
54
|
+
}
|
|
55
|
+
static async loadX(v, id) {
|
|
56
|
+
return (0, ent_1.loadEntX)(v, id, FakeTag.loaderOptions());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.FakeTag = FakeTag;
|
|
60
|
+
exports.FakeTagSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
61
|
+
displayName: (0, schema_1.StringType)(),
|
|
62
|
+
canonicalName: (0, schema_1.StringType)().trim().toLowerCase(),
|
|
63
|
+
ownerID: (0, schema_1.UUIDType)({}),
|
|
64
|
+
}, FakeTag);
|
|
65
|
+
function getTagBuilder(viewer, input) {
|
|
66
|
+
const action = getTagAction(viewer, input);
|
|
67
|
+
return action.builder;
|
|
68
|
+
}
|
|
69
|
+
exports.getTagBuilder = getTagBuilder;
|
|
70
|
+
function getTagAction(viewer, input) {
|
|
71
|
+
const m = new Map();
|
|
72
|
+
for (const key in input) {
|
|
73
|
+
m.set(key, input[key]);
|
|
74
|
+
}
|
|
75
|
+
const action = new builder_1.SimpleAction(viewer, exports.FakeTagSchema, m, action_1.WriteOperation.Insert, null);
|
|
76
|
+
return action;
|
|
77
|
+
}
|
|
78
|
+
exports.getTagAction = getTagAction;
|
|
79
|
+
async function createTag(viewer, input) {
|
|
80
|
+
const action = getTagAction(viewer, input);
|
|
81
|
+
return action.saveX();
|
|
82
|
+
}
|
|
83
|
+
exports.createTag = createTag;
|
|
84
|
+
exports.tagLoader = new loaders_1.ObjectLoaderFactory({
|
|
85
|
+
tableName: "fake_tags",
|
|
86
|
+
fields: FakeTag.getFields(),
|
|
87
|
+
key: "id",
|
|
88
|
+
});
|
|
@@ -38,6 +38,8 @@ export interface UserCreateInput {
|
|
|
38
38
|
emailAddress: string;
|
|
39
39
|
phoneNumber: string | null;
|
|
40
40
|
password: string | null;
|
|
41
|
+
createdAt?: Date;
|
|
42
|
+
updatedAt?: Date;
|
|
41
43
|
}
|
|
42
44
|
export declare type UserEditInput = Partial<UserCreateInput>;
|
|
43
45
|
export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser, null>;
|
|
@@ -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];
|