@snowtop/ent 0.1.0-alpha90 → 0.1.0-alpha92-56721980-4046-11ed-ba1f-832778cd7daa
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.d.ts +13 -0
- package/schema/field.js +63 -52
- 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.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Builder } from "../action/action";
|
|
1
2
|
import { Field, FieldMap, FieldOptions, ForeignKey, PolymorphicOptions, Type } from "./schema";
|
|
2
3
|
export declare abstract class BaseField {
|
|
3
4
|
name: string;
|
|
@@ -88,6 +89,18 @@ export declare class StringField extends BaseField implements Field {
|
|
|
88
89
|
trimLeft(): this;
|
|
89
90
|
trimRight(): this;
|
|
90
91
|
}
|
|
92
|
+
interface PolymorphicStringOptions extends StringOptions {
|
|
93
|
+
parentFieldToValidate: string;
|
|
94
|
+
types?: string[];
|
|
95
|
+
}
|
|
96
|
+
export declare class PolymorphicStringField extends StringField {
|
|
97
|
+
private opts;
|
|
98
|
+
private camelCaseVals;
|
|
99
|
+
constructor(opts: PolymorphicStringOptions);
|
|
100
|
+
validateWithFullData(val: any, b: Builder<any>): boolean;
|
|
101
|
+
valid(val: any): boolean;
|
|
102
|
+
format(val: any): any;
|
|
103
|
+
}
|
|
91
104
|
export declare function StringType(options?: StringOptions): StringField;
|
|
92
105
|
export interface TimestampOptions extends FieldOptions {
|
|
93
106
|
withTimezone?: boolean;
|
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];
|
|
@@ -19,9 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
26
|
+
exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.PolymorphicStringField = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
23
27
|
const luxon_1 = require("luxon");
|
|
24
28
|
const snake_case_1 = require("snake-case");
|
|
29
|
+
const camel_case_1 = require("camel-case");
|
|
25
30
|
const util_1 = require("util");
|
|
26
31
|
const uuid_1 = require("uuid");
|
|
27
32
|
const base_1 = require("../core/base");
|
|
@@ -62,32 +67,26 @@ class UUIDField extends BaseField {
|
|
|
62
67
|
else {
|
|
63
68
|
throw new Error(`unsupported id polymorhpic type ${fieldName}`);
|
|
64
69
|
}
|
|
70
|
+
let types;
|
|
71
|
+
let serverDefault = undefined;
|
|
72
|
+
if (typeof polymorphic === "object") {
|
|
73
|
+
serverDefault = polymorphic.serverDefault;
|
|
74
|
+
types = polymorphic.types;
|
|
75
|
+
}
|
|
65
76
|
// polymorphic field automatically hidden from GraphQL
|
|
66
77
|
// can be made visible with custom fields if user wants to change this behavior
|
|
67
78
|
// can't be foreignKey so need to make other changes to the field
|
|
68
79
|
// intentionally not made private as it doesn't seem like it needs to be hidden
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return {
|
|
83
|
-
[name]: PolymorphicStringType({
|
|
84
|
-
hideFromGraphQL: true,
|
|
85
|
-
derivedWhenEmbedded: true,
|
|
86
|
-
nullable: this.options?.nullable,
|
|
87
|
-
parentFieldToValidate: fieldName,
|
|
88
|
-
}),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
80
|
+
return {
|
|
81
|
+
[name]: PolymorphicStringType({
|
|
82
|
+
types: types,
|
|
83
|
+
hideFromGraphQL: true,
|
|
84
|
+
derivedWhenEmbedded: true,
|
|
85
|
+
nullable: this.options?.nullable,
|
|
86
|
+
parentFieldToValidate: fieldName,
|
|
87
|
+
serverDefault: serverDefault,
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
91
90
|
}
|
|
92
91
|
return {};
|
|
93
92
|
}
|
|
@@ -313,29 +312,54 @@ class StringField extends BaseField {
|
|
|
313
312
|
}
|
|
314
313
|
}
|
|
315
314
|
exports.StringField = StringField;
|
|
316
|
-
function validatePolymorphicTypeWithFullData(val, b, field) {
|
|
317
|
-
const input = b.getInput();
|
|
318
|
-
const inputKey = b.orchestrator.__getOptions().fieldInfo[field].inputKey;
|
|
319
|
-
const v = input[inputKey];
|
|
320
|
-
if (val === null) {
|
|
321
|
-
// if this is being set to null, ok if v is also null
|
|
322
|
-
return v === null;
|
|
323
|
-
}
|
|
324
|
-
// if this is not being set, ok if v is not being set
|
|
325
|
-
if (val === undefined && b.operation === base_1.WriteOperation.Insert) {
|
|
326
|
-
return v === undefined;
|
|
327
|
-
}
|
|
328
|
-
return true;
|
|
329
|
-
}
|
|
330
315
|
class PolymorphicStringField extends StringField {
|
|
331
316
|
constructor(opts) {
|
|
332
317
|
super(opts);
|
|
333
318
|
this.opts = opts;
|
|
319
|
+
if (opts.types) {
|
|
320
|
+
this.camelCaseVals = opts.types.map((v) => (0, camel_case_1.camelCase)(v));
|
|
321
|
+
}
|
|
334
322
|
}
|
|
335
323
|
validateWithFullData(val, b) {
|
|
336
|
-
|
|
324
|
+
const input = b.getInput();
|
|
325
|
+
const inputKey = b.orchestrator.__getOptions().fieldInfo[this.opts.parentFieldToValidate]
|
|
326
|
+
.inputKey;
|
|
327
|
+
const v = input[inputKey];
|
|
328
|
+
if (val === null) {
|
|
329
|
+
// if this is being set to null, ok if v is also null
|
|
330
|
+
return v === null;
|
|
331
|
+
}
|
|
332
|
+
// if this is not being set, ok if v is not being set
|
|
333
|
+
if (val === undefined && b.operation === base_1.WriteOperation.Insert) {
|
|
334
|
+
return v === undefined;
|
|
335
|
+
}
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
valid(val) {
|
|
339
|
+
if (!this.camelCaseVals) {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
let str = (0, camel_case_1.camelCase)(String(val));
|
|
343
|
+
// allow different cases because it could be coming from different clients who don't have strong typing
|
|
344
|
+
return this.camelCaseVals.some((value) => value === str);
|
|
345
|
+
}
|
|
346
|
+
format(val) {
|
|
347
|
+
if (!this.camelCaseVals) {
|
|
348
|
+
return val;
|
|
349
|
+
}
|
|
350
|
+
const converted = (0, camel_case_1.camelCase)(String(val));
|
|
351
|
+
for (const v of this.camelCaseVals) {
|
|
352
|
+
if (v === val) {
|
|
353
|
+
return val;
|
|
354
|
+
}
|
|
355
|
+
if (converted === v) {
|
|
356
|
+
return converted;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return val;
|
|
337
360
|
}
|
|
338
361
|
}
|
|
362
|
+
exports.PolymorphicStringField = PolymorphicStringField;
|
|
339
363
|
function PolymorphicStringType(opts) {
|
|
340
364
|
let result = new PolymorphicStringField(opts);
|
|
341
365
|
return Object.assign(result, opts);
|
|
@@ -586,19 +610,6 @@ exports.EnumField = EnumField;
|
|
|
586
610
|
class StringEnumField extends EnumField {
|
|
587
611
|
}
|
|
588
612
|
exports.StringEnumField = StringEnumField;
|
|
589
|
-
class PolymorphicStringEnumField extends StringEnumField {
|
|
590
|
-
constructor(opts) {
|
|
591
|
-
super(opts);
|
|
592
|
-
this.opts = opts;
|
|
593
|
-
}
|
|
594
|
-
validateWithFullData(val, b) {
|
|
595
|
-
return validatePolymorphicTypeWithFullData(val, b, this.opts.parentFieldToValidate);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
function PolymorphicStringEnumType(options) {
|
|
599
|
-
let result = new PolymorphicStringEnumField(options);
|
|
600
|
-
return Object.assign(result, options);
|
|
601
|
-
}
|
|
602
613
|
function EnumType(options) {
|
|
603
614
|
let result = new StringEnumField(options);
|
|
604
615
|
return Object.assign(result, options);
|
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>;
|