@snowtop/ent 0.1.0-alpha160-test7 → 0.1.0-alpha161-test1
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/{dist/core → core}/query/assoc_query.d.ts +3 -0
- package/{dist/core → core}/query/assoc_query.js +71 -0
- package/{dist/core → core}/query/query.d.ts +3 -0
- package/{dist/core → core}/query/query.js +20 -6
- package/core/query/shared_assoc_test.d.ts +2 -0
- package/core/query/shared_assoc_test.js +1089 -0
- package/core/query/shared_test.d.ts +21 -0
- package/core/query/shared_test.js +736 -0
- package/graphql/query/shared_assoc_test.d.ts +1 -0
- package/graphql/query/shared_assoc_test.js +203 -0
- package/package.json +8 -53
- package/{dist/testutils → testutils}/fake_data/test_helpers.js +2 -1
- package/dist/package.json +0 -64
- package/src/action/action.ts +0 -330
- package/src/action/executor.ts +0 -453
- package/src/action/experimental_action.ts +0 -277
- package/src/action/index.ts +0 -31
- package/src/action/operations.ts +0 -967
- package/src/action/orchestrator.ts +0 -1527
- package/src/action/privacy.ts +0 -37
- package/src/action/relative_value.ts +0 -242
- package/src/action/transaction.ts +0 -38
- package/src/auth/auth.ts +0 -77
- package/src/auth/index.ts +0 -8
- package/src/core/base.ts +0 -367
- package/src/core/clause.ts +0 -1065
- package/src/core/config.ts +0 -219
- package/src/core/const.ts +0 -5
- package/src/core/context.ts +0 -135
- package/src/core/convert.ts +0 -106
- package/src/core/date.ts +0 -23
- package/src/core/db.ts +0 -498
- package/src/core/ent.ts +0 -1740
- package/src/core/global_schema.ts +0 -49
- package/src/core/loaders/assoc_count_loader.ts +0 -99
- package/src/core/loaders/assoc_edge_loader.ts +0 -250
- package/src/core/loaders/index.ts +0 -12
- package/src/core/loaders/loader.ts +0 -66
- package/src/core/loaders/object_loader.ts +0 -489
- package/src/core/loaders/query_loader.ts +0 -314
- package/src/core/loaders/raw_count_loader.ts +0 -175
- package/src/core/logger.ts +0 -49
- package/src/core/privacy.ts +0 -660
- package/src/core/query/assoc_query.ts +0 -240
- package/src/core/query/custom_clause_query.ts +0 -174
- package/src/core/query/custom_query.ts +0 -302
- package/src/core/query/index.ts +0 -9
- package/src/core/query/query.ts +0 -674
- package/src/core/query_impl.ts +0 -32
- package/src/core/viewer.ts +0 -52
- package/src/ent.code-workspace +0 -73
- package/src/graphql/builtins/connection.ts +0 -25
- package/src/graphql/builtins/edge.ts +0 -16
- package/src/graphql/builtins/node.ts +0 -12
- package/src/graphql/graphql.ts +0 -891
- package/src/graphql/graphql_field_helpers.ts +0 -221
- package/src/graphql/index.ts +0 -42
- package/src/graphql/mutations/union.ts +0 -39
- package/src/graphql/node_resolver.ts +0 -122
- package/src/graphql/query/connection_type.ts +0 -113
- package/src/graphql/query/edge_connection.ts +0 -171
- package/src/graphql/query/page_info.ts +0 -34
- package/src/graphql/query/shared_edge_connection.ts +0 -287
- package/src/graphql/scalars/orderby_direction.ts +0 -13
- package/src/graphql/scalars/time.ts +0 -38
- package/src/imports/dataz/example1/_auth.ts +0 -51
- package/src/imports/dataz/example1/_viewer.ts +0 -35
- package/src/imports/index.ts +0 -213
- package/src/index.ts +0 -145
- package/src/parse_schema/parse.ts +0 -585
- package/src/schema/base_schema.ts +0 -224
- package/src/schema/field.ts +0 -1087
- package/src/schema/index.ts +0 -53
- package/src/schema/json_field.ts +0 -94
- package/src/schema/schema.ts +0 -1028
- package/src/schema/struct_field.ts +0 -234
- package/src/schema/union_field.ts +0 -105
- package/src/scripts/custom_compiler.ts +0 -331
- package/src/scripts/custom_graphql.ts +0 -550
- package/src/scripts/migrate_v0.1.ts +0 -41
- package/src/scripts/move_types.ts +0 -131
- package/src/scripts/read_schema.ts +0 -67
- package/src/setupPackage.js +0 -42
- package/src/testutils/action/complex_schemas.ts +0 -517
- package/src/testutils/builder.ts +0 -422
- package/src/testutils/context/test_context.ts +0 -25
- package/src/testutils/db/fixture.ts +0 -32
- package/src/testutils/db/temp_db.ts +0 -941
- package/src/testutils/db/value.ts +0 -294
- package/src/testutils/db_mock.ts +0 -351
- package/src/testutils/db_time_zone.ts +0 -40
- package/src/testutils/ent-graphql-tests/index.ts +0 -653
- package/src/testutils/fake_comms.ts +0 -50
- package/src/testutils/fake_data/const.ts +0 -64
- package/src/testutils/fake_data/events_query.ts +0 -145
- package/src/testutils/fake_data/fake_contact.ts +0 -150
- package/src/testutils/fake_data/fake_event.ts +0 -150
- package/src/testutils/fake_data/fake_tag.ts +0 -139
- package/src/testutils/fake_data/fake_user.ts +0 -232
- package/src/testutils/fake_data/index.ts +0 -1
- package/src/testutils/fake_data/internal.ts +0 -8
- package/src/testutils/fake_data/tag_query.ts +0 -56
- package/src/testutils/fake_data/test_helpers.ts +0 -388
- package/src/testutils/fake_data/user_query.ts +0 -524
- package/src/testutils/fake_log.ts +0 -52
- package/src/testutils/mock_date.ts +0 -10
- package/src/testutils/mock_log.ts +0 -39
- package/src/testutils/parse_sql.ts +0 -685
- package/src/testutils/test_edge_global_schema.ts +0 -49
- package/src/testutils/write.ts +0 -70
- package/src/tsc/ast.ts +0 -351
- package/src/tsc/compilerOptions.ts +0 -85
- package/src/tsc/move_generated.ts +0 -191
- package/src/tsc/transform.ts +0 -226
- package/src/tsc/transform_action.ts +0 -224
- package/src/tsc/transform_ent.ts +0 -66
- package/src/tsc/transform_schema.ts +0 -546
- package/tsconfig.json +0 -20
- /package/{dist/action → action}/action.d.ts +0 -0
- /package/{dist/action → action}/action.js +0 -0
- /package/{dist/action → action}/executor.d.ts +0 -0
- /package/{dist/action → action}/executor.js +0 -0
- /package/{dist/action → action}/experimental_action.d.ts +0 -0
- /package/{dist/action → action}/experimental_action.js +0 -0
- /package/{dist/action → action}/index.d.ts +0 -0
- /package/{dist/action → action}/index.js +0 -0
- /package/{dist/action → action}/operations.d.ts +0 -0
- /package/{dist/action → action}/operations.js +0 -0
- /package/{dist/action → action}/orchestrator.d.ts +0 -0
- /package/{dist/action → action}/orchestrator.js +0 -0
- /package/{dist/action → action}/privacy.d.ts +0 -0
- /package/{dist/action → action}/privacy.js +0 -0
- /package/{dist/action → action}/relative_value.d.ts +0 -0
- /package/{dist/action → action}/relative_value.js +0 -0
- /package/{dist/action → action}/transaction.d.ts +0 -0
- /package/{dist/action → action}/transaction.js +0 -0
- /package/{dist/auth → auth}/auth.d.ts +0 -0
- /package/{dist/auth → auth}/auth.js +0 -0
- /package/{dist/auth → auth}/index.d.ts +0 -0
- /package/{dist/auth → auth}/index.js +0 -0
- /package/{dist/core → core}/base.d.ts +0 -0
- /package/{dist/core → core}/base.js +0 -0
- /package/{dist/core → core}/clause.d.ts +0 -0
- /package/{dist/core → core}/clause.js +0 -0
- /package/{dist/core → core}/config.d.ts +0 -0
- /package/{dist/core → core}/config.js +0 -0
- /package/{dist/core → core}/const.d.ts +0 -0
- /package/{dist/core → core}/const.js +0 -0
- /package/{dist/core → core}/context.d.ts +0 -0
- /package/{dist/core → core}/context.js +0 -0
- /package/{dist/core → core}/convert.d.ts +0 -0
- /package/{dist/core → core}/convert.js +0 -0
- /package/{dist/core → core}/date.d.ts +0 -0
- /package/{dist/core → core}/date.js +0 -0
- /package/{dist/core → core}/db.d.ts +0 -0
- /package/{dist/core → core}/db.js +0 -0
- /package/{dist/core → core}/ent.d.ts +0 -0
- /package/{dist/core → core}/ent.js +0 -0
- /package/{dist/core → core}/global_schema.d.ts +0 -0
- /package/{dist/core → core}/global_schema.js +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
- /package/{dist/core → core}/loaders/index.d.ts +0 -0
- /package/{dist/core → core}/loaders/index.js +0 -0
- /package/{dist/core → core}/loaders/loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/loader.js +0 -0
- /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/object_loader.js +0 -0
- /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/query_loader.js +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
- /package/{dist/core → core}/logger.d.ts +0 -0
- /package/{dist/core → core}/logger.js +0 -0
- /package/{dist/core → core}/privacy.d.ts +0 -0
- /package/{dist/core → core}/privacy.js +0 -0
- /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_clause_query.js +0 -0
- /package/{dist/core → core}/query/custom_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_query.js +0 -0
- /package/{dist/core → core}/query/index.d.ts +0 -0
- /package/{dist/core → core}/query/index.js +0 -0
- /package/{dist/core → core}/query_impl.d.ts +0 -0
- /package/{dist/core → core}/query_impl.js +0 -0
- /package/{dist/core → core}/viewer.d.ts +0 -0
- /package/{dist/core → core}/viewer.js +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
- /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/node.js +0 -0
- /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql.js +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
- /package/{dist/graphql → graphql}/index.d.ts +0 -0
- /package/{dist/graphql → graphql}/index.js +0 -0
- /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
- /package/{dist/graphql → graphql}/mutations/union.js +0 -0
- /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
- /package/{dist/graphql → graphql}/node_resolver.js +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/page_info.js +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
- /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/time.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
- /package/{dist/imports → imports}/index.d.ts +0 -0
- /package/{dist/imports → imports}/index.js +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
- /package/{dist/schema → schema}/base_schema.d.ts +0 -0
- /package/{dist/schema → schema}/base_schema.js +0 -0
- /package/{dist/schema → schema}/field.d.ts +0 -0
- /package/{dist/schema → schema}/field.js +0 -0
- /package/{dist/schema → schema}/index.d.ts +0 -0
- /package/{dist/schema → schema}/index.js +0 -0
- /package/{dist/schema → schema}/json_field.d.ts +0 -0
- /package/{dist/schema → schema}/json_field.js +0 -0
- /package/{dist/schema → schema}/schema.d.ts +0 -0
- /package/{dist/schema → schema}/schema.js +0 -0
- /package/{dist/schema → schema}/struct_field.d.ts +0 -0
- /package/{dist/schema → schema}/struct_field.js +0 -0
- /package/{dist/schema → schema}/union_field.d.ts +0 -0
- /package/{dist/schema → schema}/union_field.js +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.js +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.js +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
- /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
- /package/{dist/scripts → scripts}/move_types.js +0 -0
- /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
- /package/{dist/scripts → scripts}/read_schema.js +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
- /package/{dist/testutils → testutils}/builder.d.ts +0 -0
- /package/{dist/testutils → testutils}/builder.js +0 -0
- /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
- /package/{dist/testutils → testutils}/context/test_context.js +0 -0
- /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/fixture.js +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
- /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/value.js +0 -0
- /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_mock.js +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_comms.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_log.js +0 -0
- /package/{dist/testutils → testutils}/mock_date.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_date.js +0 -0
- /package/{dist/testutils → testutils}/mock_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_log.js +0 -0
- /package/{dist/testutils → testutils}/parse_sql.d.ts +0 -0
- /package/{dist/testutils → testutils}/parse_sql.js +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.d.ts +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.js +0 -0
- /package/{dist/testutils → testutils}/write.d.ts +0 -0
- /package/{dist/testutils → testutils}/write.js +0 -0
- /package/{dist/tsc → tsc}/ast.d.ts +0 -0
- /package/{dist/tsc → tsc}/ast.js +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.d.ts +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.js +0 -0
- /package/{dist/tsc → tsc}/move_generated.d.ts +0 -0
- /package/{dist/tsc → tsc}/move_generated.js +0 -0
- /package/{dist/tsc → tsc}/transform.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform.js +0 -0
- /package/{dist/tsc → tsc}/transform_action.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_action.js +0 -0
- /package/{dist/tsc → tsc}/transform_ent.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_ent.js +0 -0
- /package/{dist/tsc → tsc}/transform_schema.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_schema.js +0 -0
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { v4 } from "uuid";
|
|
2
|
-
import { DBType, Field, Schema, Type } from "../../schema";
|
|
3
|
-
import {
|
|
4
|
-
DateType,
|
|
5
|
-
TimeType,
|
|
6
|
-
TimetzType,
|
|
7
|
-
TimestampType,
|
|
8
|
-
TimestamptzType,
|
|
9
|
-
JSONBType,
|
|
10
|
-
JSONType,
|
|
11
|
-
StringType,
|
|
12
|
-
} from "../../schema";
|
|
13
|
-
|
|
14
|
-
function random(): string {
|
|
15
|
-
return Math.random().toString(16).substring(2);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function randomEmail(domain?: string): string {
|
|
19
|
-
domain = domain || "email.com";
|
|
20
|
-
|
|
21
|
-
return `test+${random()}@${domain}`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function randomPhoneNumber(): string {
|
|
25
|
-
return `+1${Math.random().toString(10).substring(2, 11)}`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function coinFlip() {
|
|
29
|
-
return Math.floor(Math.random() * 10) >= 5;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function specialType(typ: Type, col: string) {
|
|
33
|
-
let list = m.get(typ.dbType);
|
|
34
|
-
if (list?.length) {
|
|
35
|
-
for (const l of list) {
|
|
36
|
-
let regex: RegExp[] = [];
|
|
37
|
-
if (Array.isArray(l.regex)) {
|
|
38
|
-
regex = l.regex;
|
|
39
|
-
} else {
|
|
40
|
-
regex = [l.regex];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for (const r of regex) {
|
|
44
|
-
if (r.test(col)) {
|
|
45
|
-
return l.newValue();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
interface Info {
|
|
54
|
-
schema: Schema;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function getDefaultValue(
|
|
58
|
-
f: Field,
|
|
59
|
-
col: string,
|
|
60
|
-
infos?: Map<string, Info>,
|
|
61
|
-
): any {
|
|
62
|
-
if (f.defaultValueOnCreate) {
|
|
63
|
-
// @ts-ignore
|
|
64
|
-
return f.defaultValueOnCreate();
|
|
65
|
-
}
|
|
66
|
-
// half the time, return null for nullable
|
|
67
|
-
if (f.nullable && coinFlip()) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const specialVal = specialType(f.type, col);
|
|
72
|
-
if (specialVal !== undefined) {
|
|
73
|
-
return specialVal;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return getValueForType(f.type, f, infos);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function getValueForType(typ: Type, f: Field, infos?: Map<string, Info>) {
|
|
80
|
-
switch (typ.dbType) {
|
|
81
|
-
case DBType.UUID:
|
|
82
|
-
return v4();
|
|
83
|
-
case DBType.Boolean:
|
|
84
|
-
return coinFlip();
|
|
85
|
-
case DBType.Date:
|
|
86
|
-
return DateType().format(new Date());
|
|
87
|
-
case DBType.Time:
|
|
88
|
-
return TimeType().format(new Date());
|
|
89
|
-
case DBType.Timetz:
|
|
90
|
-
return TimetzType().format(new Date());
|
|
91
|
-
case DBType.Timestamp:
|
|
92
|
-
return TimestampType().format(new Date());
|
|
93
|
-
case DBType.Timestamptz:
|
|
94
|
-
return TimestamptzType().format(new Date());
|
|
95
|
-
case DBType.String:
|
|
96
|
-
return random();
|
|
97
|
-
case DBType.Int:
|
|
98
|
-
return Math.floor(Math.random() * 100000000);
|
|
99
|
-
case DBType.Float:
|
|
100
|
-
return Math.random() * 100000000;
|
|
101
|
-
case DBType.Enum:
|
|
102
|
-
case DBType.StringEnum:
|
|
103
|
-
if (typ.values) {
|
|
104
|
-
const idx = Math.floor(Math.random() * typ.values.length);
|
|
105
|
-
return typ.values[idx];
|
|
106
|
-
}
|
|
107
|
-
if (typ.enumMap) {
|
|
108
|
-
const vals = Object.values(typ.enumMap);
|
|
109
|
-
const idx = Math.floor(Math.random() * vals.length);
|
|
110
|
-
return vals[idx];
|
|
111
|
-
}
|
|
112
|
-
if (f.foreignKey) {
|
|
113
|
-
const schema = f.foreignKey.schema;
|
|
114
|
-
const col = f.foreignKey.column;
|
|
115
|
-
if (!infos) {
|
|
116
|
-
throw new Error(`infos required for enum with foreignKey`);
|
|
117
|
-
}
|
|
118
|
-
const info = infos.get(schema);
|
|
119
|
-
if (!info) {
|
|
120
|
-
throw new Error(`couldn't load data for schema ${schema}`);
|
|
121
|
-
}
|
|
122
|
-
if (!info.schema.dbRows) {
|
|
123
|
-
throw new Error(`no dbRows for schema ${schema}`);
|
|
124
|
-
}
|
|
125
|
-
const idx = Math.floor(Math.random() * info.schema.dbRows.length);
|
|
126
|
-
return info.schema.dbRows[idx][col];
|
|
127
|
-
}
|
|
128
|
-
throw new Error("TODO: enum without values not currently supported");
|
|
129
|
-
|
|
130
|
-
case DBType.IntEnum:
|
|
131
|
-
const vals = Object.values(typ.intEnumMap!);
|
|
132
|
-
const idx = Math.floor(Math.random() * vals.length);
|
|
133
|
-
return vals[idx];
|
|
134
|
-
|
|
135
|
-
case DBType.BigInt:
|
|
136
|
-
return BigInt(Math.floor(Math.random() * 100000000));
|
|
137
|
-
case DBType.JSONB:
|
|
138
|
-
// type as list
|
|
139
|
-
if (typ.listElemType?.dbType === DBType.JSONB) {
|
|
140
|
-
const values: any[] = [];
|
|
141
|
-
|
|
142
|
-
for (let i = 0; i < 10; i++) {
|
|
143
|
-
values.push(getValueForType(typ.listElemType, f, infos));
|
|
144
|
-
}
|
|
145
|
-
if (!f.format) {
|
|
146
|
-
throw new Error("invalid format");
|
|
147
|
-
}
|
|
148
|
-
return f.format(values);
|
|
149
|
-
}
|
|
150
|
-
return JSONBType().format({});
|
|
151
|
-
case DBType.JSON:
|
|
152
|
-
return JSONType().format({});
|
|
153
|
-
case DBType.List:
|
|
154
|
-
// just do 10
|
|
155
|
-
const values: any[] = [];
|
|
156
|
-
|
|
157
|
-
for (let i = 0; i < 10; i++) {
|
|
158
|
-
values.push(
|
|
159
|
-
getValueForType(f.type.listElemType!, f.__getElemField(), infos),
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
if (!f.format) {
|
|
163
|
-
throw new Error("invalid format");
|
|
164
|
-
}
|
|
165
|
-
return f.format(values);
|
|
166
|
-
default:
|
|
167
|
-
throw new Error(`unsupported type ${typ.dbType}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
interface commonType {
|
|
172
|
-
dbType: DBType;
|
|
173
|
-
newValue: () => any;
|
|
174
|
-
regex: [RegExp] | RegExp;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const emailType = {
|
|
178
|
-
dbType: DBType.String,
|
|
179
|
-
newValue: () => {
|
|
180
|
-
return StringType().format(randomEmail().toLowerCase());
|
|
181
|
-
},
|
|
182
|
-
regex: /^email(_address)|_email$/,
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const phoneType = {
|
|
186
|
-
dbType: DBType.String,
|
|
187
|
-
newValue: () => {
|
|
188
|
-
return randomPhoneNumber();
|
|
189
|
-
},
|
|
190
|
-
regex: /^phone(_number)?|_phone$|_phone_number$/,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const passwordType = {
|
|
194
|
-
dbType: DBType.String,
|
|
195
|
-
newValue: () => {
|
|
196
|
-
// we don't use password type because when we're generating so many rows, it's too slow...
|
|
197
|
-
return random();
|
|
198
|
-
},
|
|
199
|
-
regex: /^password/,
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
const firstNames = [
|
|
203
|
-
"Daenerys",
|
|
204
|
-
"Jon",
|
|
205
|
-
"Arya",
|
|
206
|
-
"Sansa",
|
|
207
|
-
"Eddard",
|
|
208
|
-
"Khal",
|
|
209
|
-
"Robb",
|
|
210
|
-
"Joffrey",
|
|
211
|
-
"Ramsay",
|
|
212
|
-
"Cersei",
|
|
213
|
-
"Bolton",
|
|
214
|
-
"Oberyn",
|
|
215
|
-
"Jojen",
|
|
216
|
-
"Petyr",
|
|
217
|
-
"Brienne",
|
|
218
|
-
"Ygritte",
|
|
219
|
-
"Missandei",
|
|
220
|
-
"Shae",
|
|
221
|
-
"Sandor",
|
|
222
|
-
"Theon",
|
|
223
|
-
"Catelyn",
|
|
224
|
-
"Gilly",
|
|
225
|
-
"Samwell",
|
|
226
|
-
"Jaime",
|
|
227
|
-
"Stannis",
|
|
228
|
-
"Tyene",
|
|
229
|
-
"Obara",
|
|
230
|
-
"Nymeria",
|
|
231
|
-
"Elia",
|
|
232
|
-
"Ellaria",
|
|
233
|
-
"Myrcella",
|
|
234
|
-
"Hodor",
|
|
235
|
-
"Osha",
|
|
236
|
-
"Meera",
|
|
237
|
-
"Davos",
|
|
238
|
-
"Gendry",
|
|
239
|
-
];
|
|
240
|
-
|
|
241
|
-
const lastNames = [
|
|
242
|
-
"Stark",
|
|
243
|
-
"Targaryen",
|
|
244
|
-
"Lannister",
|
|
245
|
-
"Drogo",
|
|
246
|
-
"Baratheon",
|
|
247
|
-
"Reed",
|
|
248
|
-
"Martell",
|
|
249
|
-
"Tyrell",
|
|
250
|
-
"Clegane",
|
|
251
|
-
"Baelish",
|
|
252
|
-
"Greyjoy",
|
|
253
|
-
"Tarly",
|
|
254
|
-
"Sand",
|
|
255
|
-
"Snow",
|
|
256
|
-
"Bolton",
|
|
257
|
-
"Frey",
|
|
258
|
-
"Tarth",
|
|
259
|
-
"Payne",
|
|
260
|
-
"Seaworth",
|
|
261
|
-
];
|
|
262
|
-
|
|
263
|
-
const firstNameType = {
|
|
264
|
-
dbType: DBType.String,
|
|
265
|
-
newValue: () => {
|
|
266
|
-
let idx = Math.floor(firstNames.length * Math.random());
|
|
267
|
-
return firstNames[idx];
|
|
268
|
-
},
|
|
269
|
-
regex: /^first_?(name)?/,
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
const lastNameType = {
|
|
273
|
-
dbType: DBType.String,
|
|
274
|
-
newValue: () => {
|
|
275
|
-
let idx = Math.floor(lastNames.length * Math.random());
|
|
276
|
-
return lastNames[idx];
|
|
277
|
-
},
|
|
278
|
-
regex: /^last_?(name)?/,
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
let types: commonType[] = [
|
|
282
|
-
phoneType,
|
|
283
|
-
emailType,
|
|
284
|
-
passwordType,
|
|
285
|
-
firstNameType,
|
|
286
|
-
lastNameType,
|
|
287
|
-
];
|
|
288
|
-
|
|
289
|
-
let m: Map<DBType, commonType[]> = new Map();
|
|
290
|
-
for (const type of types) {
|
|
291
|
-
let list = m.get(type.dbType) || [];
|
|
292
|
-
list.push(type);
|
|
293
|
-
m.set(type.dbType, list);
|
|
294
|
-
}
|
package/src/testutils/db_mock.ts
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2
|
-
import { Pool, PoolClient } from "pg";
|
|
3
|
-
import { mocked } from "jest-mock";
|
|
4
|
-
import { ID, Data } from "../core/base";
|
|
5
|
-
import { Clause } from "../core/clause";
|
|
6
|
-
|
|
7
|
-
import { performQuery, queryResult, getDataToReturn } from "./parse_sql";
|
|
8
|
-
import { MockLogs } from "./mock_log";
|
|
9
|
-
|
|
10
|
-
const eventEmitter = {
|
|
11
|
-
on: jest.fn(),
|
|
12
|
-
addListener: jest.fn(),
|
|
13
|
-
removeListener: jest.fn(),
|
|
14
|
-
once: jest.fn(),
|
|
15
|
-
off: jest.fn(),
|
|
16
|
-
removeAllListeners: jest.fn(),
|
|
17
|
-
setMaxListeners: jest.fn(),
|
|
18
|
-
getMaxListeners: jest.fn(),
|
|
19
|
-
listeners: jest.fn(),
|
|
20
|
-
rawListeners: jest.fn(),
|
|
21
|
-
emit: jest.fn(),
|
|
22
|
-
listenerCount: jest.fn(),
|
|
23
|
-
prependListener: jest.fn(),
|
|
24
|
-
prependOnceListener: jest.fn(),
|
|
25
|
-
eventNames: jest.fn(),
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export interface queryOptions {
|
|
29
|
-
query: string;
|
|
30
|
-
values?: any[];
|
|
31
|
-
qs?: internalQueryStructure | null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface mockOptions {
|
|
35
|
-
tableName: string;
|
|
36
|
-
// columns?: string[];
|
|
37
|
-
clause: Clause;
|
|
38
|
-
result: (values: any[]) => {};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export enum queryType {
|
|
42
|
-
SELECT,
|
|
43
|
-
INSERT,
|
|
44
|
-
UPDATE,
|
|
45
|
-
BEGIN,
|
|
46
|
-
COMMIT,
|
|
47
|
-
ROLLBACK,
|
|
48
|
-
DELETE,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface queryStructure {
|
|
52
|
-
tableName?: string;
|
|
53
|
-
type: queryType;
|
|
54
|
-
// columns?: string[];
|
|
55
|
-
values?: any[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface internalQueryStructure extends queryStructure {
|
|
59
|
-
query: string;
|
|
60
|
-
columns?: string[];
|
|
61
|
-
whereClause?: string;
|
|
62
|
-
suffix?: string;
|
|
63
|
-
setClause?: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @deprecated
|
|
68
|
-
*/
|
|
69
|
-
export class QueryRecorder {
|
|
70
|
-
private static queries: queryOptions[] = [];
|
|
71
|
-
private static ids: ID[] = [];
|
|
72
|
-
|
|
73
|
-
// we need pkeys when storing...
|
|
74
|
-
private static data: Map<string, Data[]> = new Map();
|
|
75
|
-
|
|
76
|
-
// TODO kill use AST or just throw away
|
|
77
|
-
static getQueryStructure(query): internalQueryStructure | null {
|
|
78
|
-
// we parsing sql now??
|
|
79
|
-
// slowing building sqlshim?
|
|
80
|
-
// make it so that we return the values entered back when mocking the db
|
|
81
|
-
|
|
82
|
-
if (/^INSERT/.test(query)) {
|
|
83
|
-
let execArray = /INSERT INTO (.+) \((.+)\) VALUES \((.+)\) (.+)?/.exec(
|
|
84
|
-
query,
|
|
85
|
-
);
|
|
86
|
-
if (execArray) {
|
|
87
|
-
return {
|
|
88
|
-
tableName: execArray[1],
|
|
89
|
-
columns: execArray[2].split(", "),
|
|
90
|
-
type: queryType.INSERT,
|
|
91
|
-
query: execArray[0],
|
|
92
|
-
suffix: execArray[4],
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (/^SELECT/.test(query)) {
|
|
99
|
-
let execArray = /^SELECT (.+) FROM (.+) WHERE (.+)?/.exec(query);
|
|
100
|
-
if (execArray) {
|
|
101
|
-
return {
|
|
102
|
-
tableName: execArray[2],
|
|
103
|
-
whereClause: execArray[3],
|
|
104
|
-
type: queryType.SELECT,
|
|
105
|
-
query: execArray[0],
|
|
106
|
-
columns: execArray[1].split(", "),
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (/^UPDATE/.test(query)) {
|
|
112
|
-
// regex can't do returning
|
|
113
|
-
let execArray = /^UPDATE (.+) SET (.+) WHERE (.+) /.exec(query);
|
|
114
|
-
if (execArray) {
|
|
115
|
-
return {
|
|
116
|
-
tableName: execArray[1],
|
|
117
|
-
// not completely accurate
|
|
118
|
-
whereClause: execArray[3],
|
|
119
|
-
type: queryType.UPDATE,
|
|
120
|
-
query: execArray[0],
|
|
121
|
-
setClause: execArray[2],
|
|
122
|
-
// colummns: execArray[1].split(", "),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (/^DELETE/.test(query)) {
|
|
128
|
-
// regex can't do returning
|
|
129
|
-
let execArray = /^DELETE FROM (.+) WHERE (.+) /.exec(query);
|
|
130
|
-
if (execArray) {
|
|
131
|
-
return {
|
|
132
|
-
tableName: execArray[1],
|
|
133
|
-
whereClause: execArray[2],
|
|
134
|
-
type: queryType.DELETE,
|
|
135
|
-
query: execArray[0],
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (/^BEGIN/.test(query)) {
|
|
141
|
-
return {
|
|
142
|
-
type: queryType.BEGIN,
|
|
143
|
-
query: query,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (/^COMMIT/.test(query)) {
|
|
148
|
-
return {
|
|
149
|
-
type: queryType.COMMIT,
|
|
150
|
-
query: query,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (/^ROLLBACK/.test(query)) {
|
|
155
|
-
return {
|
|
156
|
-
type: queryType.ROLLBACK,
|
|
157
|
-
query: query,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
private static recordQuery(
|
|
164
|
-
query: string,
|
|
165
|
-
values: any[],
|
|
166
|
-
): queryResult | undefined {
|
|
167
|
-
let qs = QueryRecorder.getQueryStructure(query);
|
|
168
|
-
QueryRecorder.queries.push({
|
|
169
|
-
query: query,
|
|
170
|
-
values: values,
|
|
171
|
-
qs: qs,
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
return performQuery(query, values, QueryRecorder.data);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
static newID(): ID {
|
|
178
|
-
let id = uuidv4();
|
|
179
|
-
QueryRecorder.ids.push(id);
|
|
180
|
-
return id;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
static getCurrentIDs(): ID[] {
|
|
184
|
-
return QueryRecorder.ids;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
static getLastID(): ID {
|
|
188
|
-
const l = QueryRecorder.ids.length;
|
|
189
|
-
if (!l) {
|
|
190
|
-
throw new Error(`no ID`);
|
|
191
|
-
}
|
|
192
|
-
return QueryRecorder.ids[l - 1];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
static getData() {
|
|
196
|
-
return QueryRecorder.data;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
static filterData(tableName: string, filterfn: (row: Data) => boolean) {
|
|
200
|
-
const rows = QueryRecorder.data.get(tableName) || [];
|
|
201
|
-
let result: Data[] = [];
|
|
202
|
-
for (const row of rows) {
|
|
203
|
-
// transform the data into whatever the return value should be before filtering
|
|
204
|
-
const row2 = getDataToReturn(row, undefined, true);
|
|
205
|
-
if (filterfn(row2)) {
|
|
206
|
-
result.push(row2);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return result;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
static clear() {
|
|
213
|
-
QueryRecorder.queries = [];
|
|
214
|
-
QueryRecorder.ids = [];
|
|
215
|
-
QueryRecorder.data = new Map();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
static clearQueries() {
|
|
219
|
-
// clears queries but keeps data
|
|
220
|
-
// this is useful for situations like write this data before each test
|
|
221
|
-
// but each test shouldn't have to account for this
|
|
222
|
-
QueryRecorder.queries = [];
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
static getCurrentQueries(): queryOptions[] {
|
|
226
|
-
return QueryRecorder.queries;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* @deprecated will keep this since it's just using ml.logs
|
|
231
|
-
* which we still want around (I think) but we should eventually
|
|
232
|
-
* probably stop using this
|
|
233
|
-
*/
|
|
234
|
-
static validateQueryStructuresFromLogs(
|
|
235
|
-
ml: MockLogs,
|
|
236
|
-
expected: queryStructure[],
|
|
237
|
-
opts?: {
|
|
238
|
-
skipSelect?: boolean;
|
|
239
|
-
flagBeginCommit?: boolean;
|
|
240
|
-
},
|
|
241
|
-
) {
|
|
242
|
-
const queries = ml.logs.map((log) => {
|
|
243
|
-
const qs = QueryRecorder.getQueryStructure(log.query);
|
|
244
|
-
if (!qs) {
|
|
245
|
-
throw new Error(`invalid query ${log.querya}`);
|
|
246
|
-
}
|
|
247
|
-
return {
|
|
248
|
-
query: log.query,
|
|
249
|
-
qs,
|
|
250
|
-
};
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
QueryRecorder.validateQueryStructuresImpl(expected, queries, opts);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
private static validateQueryStructuresImpl(
|
|
257
|
-
expected: queryStructure[],
|
|
258
|
-
queries: queryOptions[],
|
|
259
|
-
opts?: {
|
|
260
|
-
skipSelect?: boolean;
|
|
261
|
-
flagBeginCommit?: boolean;
|
|
262
|
-
},
|
|
263
|
-
) {
|
|
264
|
-
if (opts?.skipSelect) {
|
|
265
|
-
queries = queries.filter((query) => query.qs?.type !== queryType.SELECT);
|
|
266
|
-
}
|
|
267
|
-
if (!opts?.flagBeginCommit) {
|
|
268
|
-
queries = queries.filter(
|
|
269
|
-
(query) =>
|
|
270
|
-
query.qs?.type !== queryType.BEGIN &&
|
|
271
|
-
query.qs?.type !== queryType.COMMIT,
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
// console.log(queries, expected);
|
|
275
|
-
expect(queries.length).toBe(expected.length);
|
|
276
|
-
|
|
277
|
-
for (let i = 0; i < expected.length; i++) {
|
|
278
|
-
let expectedStructure = expected[i];
|
|
279
|
-
let query = queries[i];
|
|
280
|
-
switch (expectedStructure.type) {
|
|
281
|
-
case queryType.BEGIN:
|
|
282
|
-
expect(query.query).toBe("BEGIN");
|
|
283
|
-
expect(query.values).toBe(undefined);
|
|
284
|
-
break;
|
|
285
|
-
case queryType.ROLLBACK:
|
|
286
|
-
expect(query.query).toBe("ROLLBACK");
|
|
287
|
-
expect(query.values).toBe(undefined);
|
|
288
|
-
break;
|
|
289
|
-
case queryType.COMMIT:
|
|
290
|
-
expect(query.query).toBe("COMMIT");
|
|
291
|
-
expect(query.values).toBe(undefined);
|
|
292
|
-
break;
|
|
293
|
-
case queryType.SELECT:
|
|
294
|
-
if (!opts?.skipSelect) {
|
|
295
|
-
console.error(
|
|
296
|
-
"validating select query structure not supported yet",
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
// TODO INSERT and UPDATE tests here...
|
|
300
|
-
// should be easy...
|
|
301
|
-
break;
|
|
302
|
-
case queryType.INSERT:
|
|
303
|
-
expect(query.query.startsWith("INSERT")).toBe(true);
|
|
304
|
-
expect(query.qs?.tableName).toBe(expectedStructure.tableName);
|
|
305
|
-
break;
|
|
306
|
-
case queryType.UPDATE:
|
|
307
|
-
expect(query.query.startsWith("UPDATE")).toBe(true);
|
|
308
|
-
expect(query.qs?.tableName).toBe(expectedStructure.tableName);
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
static mockPool(pool: typeof Pool) {
|
|
315
|
-
const mockedPool = mocked(pool);
|
|
316
|
-
// @ts-ignore
|
|
317
|
-
// TODO what changed in mockImplementation?
|
|
318
|
-
mockedPool.mockImplementation((): Pool => {
|
|
319
|
-
return {
|
|
320
|
-
totalCount: 1,
|
|
321
|
-
idleCount: 1,
|
|
322
|
-
waitingCount: 1,
|
|
323
|
-
connect: async (): Promise<PoolClient> => {
|
|
324
|
-
return {
|
|
325
|
-
connect: jest.fn(),
|
|
326
|
-
release: jest.fn(),
|
|
327
|
-
query: jest
|
|
328
|
-
.fn()
|
|
329
|
-
.mockImplementation((query: string, values: any[]) => {
|
|
330
|
-
return QueryRecorder.recordQuery(query, values);
|
|
331
|
-
}),
|
|
332
|
-
copyFrom: jest.fn(),
|
|
333
|
-
copyTo: jest.fn(),
|
|
334
|
-
pauseDrain: jest.fn(),
|
|
335
|
-
resumeDrain: jest.fn(),
|
|
336
|
-
escapeIdentifier: jest.fn(),
|
|
337
|
-
escapeLiteral: jest.fn(),
|
|
338
|
-
|
|
339
|
-
// EventEmitter
|
|
340
|
-
...eventEmitter,
|
|
341
|
-
};
|
|
342
|
-
},
|
|
343
|
-
end: jest.fn(),
|
|
344
|
-
query: jest.fn().mockImplementation(QueryRecorder.recordQuery),
|
|
345
|
-
|
|
346
|
-
// EventEmitter
|
|
347
|
-
...eventEmitter,
|
|
348
|
-
};
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { DateTime } from "luxon";
|
|
2
|
-
import { leftPad } from "../schema";
|
|
3
|
-
import DB from "../core/db";
|
|
4
|
-
|
|
5
|
-
let dbCurrentZone: string | null | undefined = undefined;
|
|
6
|
-
export class DBTimeZone {
|
|
7
|
-
private static async getVal(): Promise<string | null> {
|
|
8
|
-
if (dbCurrentZone !== undefined) {
|
|
9
|
-
return dbCurrentZone;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const r = await DB.getInstance()
|
|
13
|
-
.getPool()
|
|
14
|
-
.query("SELECT current_setting('TIMEZONE');");
|
|
15
|
-
|
|
16
|
-
if (r.rows.length) {
|
|
17
|
-
dbCurrentZone = r.rows[0].current_setting as string;
|
|
18
|
-
} else {
|
|
19
|
-
dbCurrentZone = null;
|
|
20
|
-
}
|
|
21
|
-
return dbCurrentZone;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static async getDateOffset(d: Date) {
|
|
25
|
-
let zone = await DBTimeZone.getVal();
|
|
26
|
-
|
|
27
|
-
let dt = DateTime.fromJSDate(d);
|
|
28
|
-
if (zone) {
|
|
29
|
-
dt = dt.setZone(zone);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// use
|
|
33
|
-
const val = leftPad(dt.get("offset") / 60);
|
|
34
|
-
|
|
35
|
-
if (val == "00") {
|
|
36
|
-
return "+00";
|
|
37
|
-
}
|
|
38
|
-
return val;
|
|
39
|
-
}
|
|
40
|
-
}
|