@snowtop/ent 0.1.0-alpha1 → 0.1.0-alpha100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action/action.d.ts +38 -30
- package/action/action.js +22 -7
- package/action/executor.d.ts +4 -4
- package/action/executor.js +8 -3
- package/action/experimental_action.d.ts +32 -22
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +48 -16
- package/action/orchestrator.js +343 -81
- package/action/privacy.d.ts +2 -2
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +54 -27
- package/core/base.js +23 -1
- package/core/clause.d.ts +105 -3
- package/core/clause.js +563 -30
- package/core/config.d.ts +30 -1
- package/core/config.js +24 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +14 -11
- package/core/db.js +22 -8
- package/core/ent.d.ts +82 -28
- package/core/ent.js +692 -202
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +13 -15
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +2 -2
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +13 -7
- package/core/loaders/object_loader.js +95 -32
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +52 -11
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +23 -24
- package/core/query/assoc_query.d.ts +7 -6
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +26 -0
- package/core/query/custom_clause_query.js +78 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +87 -12
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +8 -4
- package/core/query/query.js +101 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +35 -45
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +469 -236
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +5 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +17 -9
- package/graphql/graphql.js +47 -30
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +3 -4
- package/graphql/mutations/union.d.ts +2 -0
- package/graphql/mutations/union.js +35 -0
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +3 -3
- package/graphql/query/shared_edge_connection.js +1 -19
- package/graphql/scalars/time.d.ts +1 -1
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +23 -1
- package/index.js +32 -6
- package/package.json +18 -17
- package/parse_schema/parse.d.ts +45 -8
- package/parse_schema/parse.js +193 -15
- package/schema/base_schema.d.ts +38 -1
- package/schema/base_schema.js +53 -2
- package/schema/field.d.ts +75 -21
- package/schema/field.js +185 -72
- package/schema/index.d.ts +4 -2
- package/schema/index.js +15 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +125 -10
- package/schema/schema.js +133 -5
- package/schema/struct_field.d.ts +27 -0
- package/schema/struct_field.js +138 -0
- package/schema/union_field.d.ts +23 -0
- package/schema/union_field.js +79 -0
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +224 -36
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.d.ts +1 -0
- package/scripts/move_types.js +117 -0
- package/scripts/read_schema.js +35 -6
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +52 -49
- package/testutils/builder.js +143 -44
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +26 -9
- package/testutils/db/{test_db.js → temp_db.js} +190 -46
- package/testutils/db/value.d.ts +7 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +51 -6
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.d.ts +9 -1
- package/testutils/ent-graphql-tests/index.js +53 -25
- 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 +10 -10
- package/testutils/fake_data/fake_contact.js +23 -21
- package/testutils/fake_data/fake_event.d.ts +8 -9
- package/testutils/fake_data/fake_event.js +25 -28
- package/testutils/fake_data/fake_tag.d.ts +36 -0
- package/testutils/fake_data/fake_tag.js +89 -0
- package/testutils/fake_data/fake_user.d.ts +10 -11
- package/testutils/fake_data/fake_user.js +20 -23
- 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 +11 -4
- package/testutils/fake_data/test_helpers.js +29 -13
- package/testutils/fake_data/user_query.d.ts +13 -6
- package/testutils/fake_data/user_query.js +54 -22
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +277 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +45 -2
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +22 -0
- package/tsc/transform.js +181 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +183 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +383 -0
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/transform_schema.js +0 -288
package/core/config.d.ts
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Database, DBDict } from "./db";
|
|
3
|
-
|
|
3
|
+
type logType = "query" | "warn" | "info" | "error" | "debug";
|
|
4
|
+
declare enum graphqlMutationName {
|
|
5
|
+
NOUN_VERB = "NounVerb",
|
|
6
|
+
VERB_NOUN = "VerbNoun"
|
|
7
|
+
}
|
|
8
|
+
declare enum graphQLFieldFormat {
|
|
9
|
+
LOWER_CAMEL = "lowerCamel",
|
|
10
|
+
SNAKE_CASE = "snake_case"
|
|
11
|
+
}
|
|
12
|
+
declare enum fieldPrivacyEvaluated {
|
|
13
|
+
AT_ENT_LOAD = "at_ent_load",
|
|
14
|
+
ON_DEMAND = "on_demand"
|
|
15
|
+
}
|
|
4
16
|
export interface Config {
|
|
5
17
|
dbConnectionString?: string;
|
|
6
18
|
dbFile?: string;
|
|
7
19
|
db?: Database | DBDict;
|
|
8
20
|
log?: logType | logType[];
|
|
9
21
|
codegen?: CodegenConfig;
|
|
22
|
+
logQueryWithError?: boolean;
|
|
23
|
+
customGraphQLJSONPath?: string;
|
|
24
|
+
dynamicScriptCustomGraphQLJSONPath?: string;
|
|
25
|
+
globalSchemaPath?: string;
|
|
10
26
|
}
|
|
11
27
|
interface CodegenConfig {
|
|
12
28
|
defaultEntPolicy?: PrivacyConfig;
|
|
@@ -17,6 +33,14 @@ interface CodegenConfig {
|
|
|
17
33
|
generatedHeader?: string;
|
|
18
34
|
disableBase64Encoding?: boolean;
|
|
19
35
|
generateRootResolvers?: boolean;
|
|
36
|
+
defaultGraphQLMutationName?: graphqlMutationName;
|
|
37
|
+
defaultGraphQLFieldFormat?: graphQLFieldFormat;
|
|
38
|
+
schemaSQLFilePath?: boolean;
|
|
39
|
+
databaseToCompareTo?: string;
|
|
40
|
+
fieldPrivacyEvaluated?: fieldPrivacyEvaluated;
|
|
41
|
+
templatizedViewer?: importedObject;
|
|
42
|
+
customAssocEdgePath?: importedObject;
|
|
43
|
+
globalImportPath?: string;
|
|
20
44
|
}
|
|
21
45
|
interface PrettierConfig {
|
|
22
46
|
custom?: boolean;
|
|
@@ -27,5 +51,10 @@ interface PrivacyConfig {
|
|
|
27
51
|
policyName: string;
|
|
28
52
|
class?: boolean;
|
|
29
53
|
}
|
|
54
|
+
interface importedObject {
|
|
55
|
+
path: string;
|
|
56
|
+
name: string;
|
|
57
|
+
alias?: string;
|
|
58
|
+
}
|
|
30
59
|
export declare function loadConfig(file?: string | Buffer | Config): void;
|
|
31
60
|
export {};
|
package/core/config.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];
|
|
@@ -28,6 +32,24 @@ const js_yaml_1 = require("js-yaml");
|
|
|
28
32
|
const db_1 = __importDefault(require("./db"));
|
|
29
33
|
const path = __importStar(require("path"));
|
|
30
34
|
const logger_1 = require("./logger");
|
|
35
|
+
const ent_1 = require("./ent");
|
|
36
|
+
// ent.config.ts eventually. for now ent.yml
|
|
37
|
+
// or ent.yml?
|
|
38
|
+
var graphqlMutationName;
|
|
39
|
+
(function (graphqlMutationName) {
|
|
40
|
+
graphqlMutationName["NOUN_VERB"] = "NounVerb";
|
|
41
|
+
graphqlMutationName["VERB_NOUN"] = "VerbNoun";
|
|
42
|
+
})(graphqlMutationName || (graphqlMutationName = {}));
|
|
43
|
+
var graphQLFieldFormat;
|
|
44
|
+
(function (graphQLFieldFormat) {
|
|
45
|
+
graphQLFieldFormat["LOWER_CAMEL"] = "lowerCamel";
|
|
46
|
+
graphQLFieldFormat["SNAKE_CASE"] = "snake_case";
|
|
47
|
+
})(graphQLFieldFormat || (graphQLFieldFormat = {}));
|
|
48
|
+
var fieldPrivacyEvaluated;
|
|
49
|
+
(function (fieldPrivacyEvaluated) {
|
|
50
|
+
fieldPrivacyEvaluated["AT_ENT_LOAD"] = "at_ent_load";
|
|
51
|
+
fieldPrivacyEvaluated["ON_DEMAND"] = "on_demand";
|
|
52
|
+
})(fieldPrivacyEvaluated || (fieldPrivacyEvaluated = {}));
|
|
31
53
|
function setConfig(cfg) {
|
|
32
54
|
if (cfg.log) {
|
|
33
55
|
(0, logger_1.setLogLevels)(cfg.log);
|
|
@@ -39,6 +61,7 @@ function setConfig(cfg) {
|
|
|
39
61
|
db: cfg.db,
|
|
40
62
|
});
|
|
41
63
|
}
|
|
64
|
+
(0, ent_1.___setLogQueryErrorWithError)(cfg.logQueryWithError);
|
|
42
65
|
}
|
|
43
66
|
function isBuffer(b) {
|
|
44
67
|
return b.write !== undefined;
|
package/core/context.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Viewer, Data, Loader } from "./base";
|
|
2
|
+
import { Viewer, Data, Loader, LoaderWithLoadMany } from "./base";
|
|
3
3
|
import { IncomingMessage, ServerResponse } from "http";
|
|
4
4
|
import * as clause from "./clause";
|
|
5
5
|
import { Context } from "./base";
|
|
6
|
-
export interface RequestContext extends Context {
|
|
7
|
-
authViewer(viewer:
|
|
6
|
+
export interface RequestContext<TViewer extends Viewer = Viewer> extends Context<TViewer> {
|
|
7
|
+
authViewer(viewer: TViewer): Promise<void>;
|
|
8
8
|
logout(): Promise<void>;
|
|
9
9
|
request: IncomingMessage;
|
|
10
10
|
response: ServerResponse;
|
|
11
11
|
}
|
|
12
12
|
export declare class ContextCache {
|
|
13
13
|
loaders: Map<string, Loader<any, any>>;
|
|
14
|
+
loaderWithLoadMany: Map<string, LoaderWithLoadMany<any, any>>;
|
|
14
15
|
getLoader<T, V>(name: string, create: () => Loader<T, V>): Loader<T, V>;
|
|
16
|
+
getLoaderWithLoadMany<T, V>(name: string, create: () => LoaderWithLoadMany<T, V>): LoaderWithLoadMany<T, V>;
|
|
15
17
|
private itemMap;
|
|
16
18
|
private listMap;
|
|
17
19
|
private getkey;
|
package/core/context.js
CHANGED
|
@@ -5,6 +5,8 @@ const logger_1 = require("./logger");
|
|
|
5
5
|
class ContextCache {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.loaders = new Map();
|
|
8
|
+
// we should eventually combine the two but better for typing to be separate for now
|
|
9
|
+
this.loaderWithLoadMany = new Map();
|
|
8
10
|
// we have a per-table map to make it easier to purge and have less things to compare with
|
|
9
11
|
this.itemMap = new Map();
|
|
10
12
|
this.listMap = new Map();
|
|
@@ -19,6 +21,16 @@ class ContextCache {
|
|
|
19
21
|
this.loaders.set(name, l);
|
|
20
22
|
return l;
|
|
21
23
|
}
|
|
24
|
+
getLoaderWithLoadMany(name, create) {
|
|
25
|
+
let l = this.loaderWithLoadMany.get(name);
|
|
26
|
+
if (l) {
|
|
27
|
+
return l;
|
|
28
|
+
}
|
|
29
|
+
(0, logger_1.log)("debug", `new context-aware loader created for ${name}`);
|
|
30
|
+
l = create();
|
|
31
|
+
this.loaderWithLoadMany.set(name, l);
|
|
32
|
+
return l;
|
|
33
|
+
}
|
|
22
34
|
// tableName is ignored bcos already indexed on that
|
|
23
35
|
// maybe we just want to store sql queries???
|
|
24
36
|
getkey(options) {
|
|
@@ -39,7 +51,7 @@ class ContextCache {
|
|
|
39
51
|
const key = this.getkey(options);
|
|
40
52
|
let rows = m.get(key);
|
|
41
53
|
if (rows) {
|
|
42
|
-
(0, logger_1.log)("
|
|
54
|
+
(0, logger_1.log)("cache", {
|
|
43
55
|
"cache-hit": key,
|
|
44
56
|
"tableName": options.tableName,
|
|
45
57
|
});
|
|
@@ -54,7 +66,7 @@ class ContextCache {
|
|
|
54
66
|
const key = this.getkey(options);
|
|
55
67
|
let row = m.get(key);
|
|
56
68
|
if (row) {
|
|
57
|
-
(0, logger_1.log)("
|
|
69
|
+
(0, logger_1.log)("cache", {
|
|
58
70
|
"cache-hit": key,
|
|
59
71
|
"tableName": options.tableName,
|
|
60
72
|
});
|
|
@@ -79,7 +91,13 @@ class ContextCache {
|
|
|
79
91
|
// but may have some benefits by explicitily doing so?
|
|
80
92
|
loader.clearAll();
|
|
81
93
|
}
|
|
94
|
+
for (const [_key, loader] of this.loaderWithLoadMany) {
|
|
95
|
+
// may not need this since we're clearing the loaders themselves...
|
|
96
|
+
// but may have some benefits by explicitily doing so?
|
|
97
|
+
loader.clearAll();
|
|
98
|
+
}
|
|
82
99
|
this.loaders.clear();
|
|
100
|
+
this.loaderWithLoadMany.clear();
|
|
83
101
|
this.itemMap.clear();
|
|
84
102
|
this.listMap.clear();
|
|
85
103
|
}
|
package/core/convert.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ export declare function convertBoolList(val: any): boolean[];
|
|
|
10
10
|
export declare function convertNullableBoolList(val: any): boolean[] | null;
|
|
11
11
|
export declare function convertJSON(val: any): any;
|
|
12
12
|
export declare function convertNullableJSON(val: any): any | null;
|
|
13
|
-
export declare function convertJSONList(val: any):
|
|
13
|
+
export declare function convertJSONList(val: any): any[];
|
|
14
14
|
export declare function convertNullableJSONList(val: any): any[] | null;
|
package/core/date.js
CHANGED
|
@@ -10,11 +10,7 @@ function parseDate(val, throwErr) {
|
|
|
10
10
|
else if (typeof val === "string") {
|
|
11
11
|
dt = luxon_1.DateTime.fromISO(val);
|
|
12
12
|
if (!dt.isValid) {
|
|
13
|
-
|
|
14
|
-
if (ms === NaN) {
|
|
15
|
-
throw throwErr(`invalid input for type Time ${val}`);
|
|
16
|
-
}
|
|
17
|
-
dt = luxon_1.DateTime.fromMillis(ms);
|
|
13
|
+
dt = luxon_1.DateTime.fromMillis(Date.parse(val));
|
|
18
14
|
}
|
|
19
15
|
}
|
|
20
16
|
else if (val instanceof Date) {
|
package/core/db.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { Pool,
|
|
2
|
-
export interface Database {
|
|
1
|
+
import { Pool, PoolClient, PoolConfig } from "pg";
|
|
2
|
+
export interface Database extends PoolConfig {
|
|
3
3
|
database?: string;
|
|
4
4
|
user?: string;
|
|
5
5
|
password?: string;
|
|
6
6
|
host?: string;
|
|
7
7
|
port?: number;
|
|
8
|
-
ssl?: boolean;
|
|
9
8
|
sslmode?: string;
|
|
10
9
|
}
|
|
11
|
-
export
|
|
10
|
+
export type env = "production" | "test" | "development";
|
|
12
11
|
export declare type DBDict = Partial<Record<env, Database>>;
|
|
13
12
|
export declare enum Dialect {
|
|
14
13
|
Postgres = "postgres",
|
|
@@ -16,9 +15,14 @@ export declare enum Dialect {
|
|
|
16
15
|
}
|
|
17
16
|
interface DatabaseInfo {
|
|
18
17
|
dialect: Dialect;
|
|
19
|
-
config:
|
|
18
|
+
config: PoolConfig;
|
|
20
19
|
filePath?: string;
|
|
21
20
|
}
|
|
21
|
+
interface clientConfigArgs {
|
|
22
|
+
connectionString?: string;
|
|
23
|
+
dbFile?: string;
|
|
24
|
+
db?: Database | DBDict;
|
|
25
|
+
}
|
|
22
26
|
export default class DB {
|
|
23
27
|
db: DatabaseInfo;
|
|
24
28
|
static instance: DB;
|
|
@@ -29,15 +33,12 @@ export default class DB {
|
|
|
29
33
|
getConnection(): Connection;
|
|
30
34
|
getPool(): Queryer;
|
|
31
35
|
getNewClient(): Promise<Client>;
|
|
32
|
-
getSQLiteClient():
|
|
36
|
+
getSQLiteClient(): Sqlite;
|
|
33
37
|
endPool(): Promise<void>;
|
|
38
|
+
emitsExplicitTransactionStatements(): boolean;
|
|
34
39
|
static getInstance(): DB;
|
|
35
40
|
static getDialect(): Dialect;
|
|
36
|
-
static initDB(args?:
|
|
37
|
-
connectionString?: string;
|
|
38
|
-
dbFile?: string;
|
|
39
|
-
db?: Database | DBDict;
|
|
40
|
-
}): void;
|
|
41
|
+
static initDB(args?: clientConfigArgs): void;
|
|
41
42
|
}
|
|
42
43
|
export declare const defaultTimestampParser: any;
|
|
43
44
|
export interface Queryer {
|
|
@@ -54,6 +55,7 @@ export interface Connection extends Queryer {
|
|
|
54
55
|
self(): Queryer;
|
|
55
56
|
newClient(): Promise<Client>;
|
|
56
57
|
close(): Promise<void>;
|
|
58
|
+
runInTransaction?(cb: () => void | Promise<void>): any;
|
|
57
59
|
}
|
|
58
60
|
export interface QueryResultRow {
|
|
59
61
|
[column: string]: any;
|
|
@@ -78,6 +80,7 @@ interface SqliteRunResult {
|
|
|
78
80
|
}
|
|
79
81
|
interface SqliteDatabase {
|
|
80
82
|
memory: boolean;
|
|
83
|
+
exec(query: string): SqliteStatement;
|
|
81
84
|
prepare(query: string): SqliteStatement;
|
|
82
85
|
close(): void;
|
|
83
86
|
transaction(fn: (...params: any[]) => any): SqliteTransaction;
|
package/core/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];
|
|
@@ -35,13 +39,16 @@ var Dialect;
|
|
|
35
39
|
Dialect["Postgres"] = "postgres";
|
|
36
40
|
Dialect["SQLite"] = "sqlite";
|
|
37
41
|
})(Dialect = exports.Dialect || (exports.Dialect = {}));
|
|
38
|
-
function parseConnectionString(str) {
|
|
42
|
+
function parseConnectionString(str, args) {
|
|
39
43
|
if (str.startsWith("sqlite:///")) {
|
|
40
44
|
let filePath = str.substr(10);
|
|
41
45
|
return {
|
|
42
46
|
dialect: Dialect.SQLite,
|
|
43
47
|
config: {
|
|
44
48
|
connectionString: str,
|
|
49
|
+
// TODO would like to do this for other args e.g. max being set but would have to update tests
|
|
50
|
+
// e.g. src/core/config.test.ts which tests this
|
|
51
|
+
// ...args?.db,
|
|
45
52
|
},
|
|
46
53
|
filePath,
|
|
47
54
|
};
|
|
@@ -50,6 +57,9 @@ function parseConnectionString(str) {
|
|
|
50
57
|
dialect: Dialect.Postgres,
|
|
51
58
|
config: {
|
|
52
59
|
connectionString: str,
|
|
60
|
+
// TODO would like to do this for other args e.g. max being set but would have to update tests
|
|
61
|
+
// e.g. src/core/config.test.ts which tests this
|
|
62
|
+
// ...args?.db,
|
|
53
63
|
},
|
|
54
64
|
};
|
|
55
65
|
}
|
|
@@ -63,12 +73,12 @@ function getClientConfig(args) {
|
|
|
63
73
|
// if there's a db connection string, use that first
|
|
64
74
|
const str = process.env.DB_CONNECTION_STRING;
|
|
65
75
|
if (str) {
|
|
66
|
-
return parseConnectionString(str);
|
|
76
|
+
return parseConnectionString(str, args);
|
|
67
77
|
}
|
|
68
78
|
let file = "config/database.yml";
|
|
69
79
|
if (args) {
|
|
70
80
|
if (args.connectionString) {
|
|
71
|
-
return parseConnectionString(args.connectionString);
|
|
81
|
+
return parseConnectionString(args.connectionString, args);
|
|
72
82
|
}
|
|
73
83
|
if (args.db) {
|
|
74
84
|
let db;
|
|
@@ -109,6 +119,8 @@ function getClientConfig(args) {
|
|
|
109
119
|
host: cfg.host,
|
|
110
120
|
port: cfg.port,
|
|
111
121
|
ssl: cfg.sslmode == "enable",
|
|
122
|
+
// max, min, etc
|
|
123
|
+
...cfg,
|
|
112
124
|
},
|
|
113
125
|
};
|
|
114
126
|
}
|
|
@@ -146,7 +158,7 @@ class DB {
|
|
|
146
158
|
async getNewClient() {
|
|
147
159
|
return this.q.newClient();
|
|
148
160
|
}
|
|
149
|
-
|
|
161
|
+
getSQLiteClient() {
|
|
150
162
|
if (this.db.dialect == Dialect.Postgres) {
|
|
151
163
|
throw new Error(`can't call getSQLiteClient when dialect is postgres`);
|
|
152
164
|
}
|
|
@@ -156,6 +168,10 @@ class DB {
|
|
|
156
168
|
async endPool() {
|
|
157
169
|
return this.q.close();
|
|
158
170
|
}
|
|
171
|
+
emitsExplicitTransactionStatements() {
|
|
172
|
+
const instance = DB.getInstance();
|
|
173
|
+
return instance.q.runInTransaction === undefined;
|
|
174
|
+
}
|
|
159
175
|
// throws if invalid
|
|
160
176
|
static getInstance() {
|
|
161
177
|
if (DB.instance) {
|
|
@@ -190,8 +206,6 @@ exports.defaultTimestampParser = pg_1.default.types.getTypeParser(pg_1.default.t
|
|
|
190
206
|
// it's parsed as UTC time as opposed to the local time
|
|
191
207
|
pg_1.default.types.setTypeParser(pg_1.default.types.builtins.TIMESTAMP, function (val) {
|
|
192
208
|
return luxon_1.DateTime.fromSQL(val + "Z").toJSDate();
|
|
193
|
-
// let d = new Date(val + "Z");
|
|
194
|
-
// return d;
|
|
195
209
|
});
|
|
196
210
|
class Sqlite {
|
|
197
211
|
constructor(db) {
|
|
@@ -310,7 +324,7 @@ class Postgres {
|
|
|
310
324
|
};
|
|
311
325
|
}
|
|
312
326
|
async close() {
|
|
313
|
-
return this.pool.end();
|
|
327
|
+
return await this.pool.end();
|
|
314
328
|
}
|
|
315
329
|
}
|
|
316
330
|
exports.Postgres = Postgres;
|
package/core/ent.d.ts
CHANGED
|
@@ -1,32 +1,70 @@
|
|
|
1
1
|
import { Queryer, SyncQueryer } from "./db";
|
|
2
|
-
import { Viewer, Ent, ID, LoadRowsOptions, LoadRowOptions, Data, DataOptions, QueryableDataOptions, EditRowOptions, LoadEntOptions, LoadCustomEntOptions, EdgeQueryableDataOptions, Context,
|
|
2
|
+
import { Viewer, Ent, ID, LoadRowsOptions, LoadRowOptions, Data, DataOptions, QueryableDataOptions, EditRowOptions, LoadEntOptions, LoadCustomEntOptions, EdgeQueryableDataOptions, Context, CreateRowOptions, QueryDataOptions, SelectCustomDataOptions } from "./base";
|
|
3
3
|
import { Executor } from "../action/action";
|
|
4
4
|
import * as clause from "./clause";
|
|
5
5
|
import { Builder } from "../action";
|
|
6
6
|
import DataLoader from "dataloader";
|
|
7
|
-
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare function
|
|
17
|
-
|
|
7
|
+
import { GlobalSchema } from "../schema/";
|
|
8
|
+
export declare function getEntKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): string;
|
|
9
|
+
export declare function loadEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
|
|
10
|
+
export declare function loadEntViaKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, key: any, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
|
|
11
|
+
export declare function loadEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt>;
|
|
12
|
+
export declare function loadEntXViaKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, key: any, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt>;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated use loadCustomEnts
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadEntFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, clause: clause.Clause): Promise<TEnt | null>;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use loadCustomEnts
|
|
19
|
+
*/
|
|
20
|
+
export declare function loadEntXFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, clause: clause.Clause): Promise<TEnt>;
|
|
21
|
+
export declare function loadEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, ...ids: ID[]): Promise<Map<ID, TEnt>>;
|
|
22
|
+
export declare function loadEntsList<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, ...ids: ID[]): Promise<TEnt[]>;
|
|
23
|
+
/**
|
|
24
|
+
* @deperecated use loadCustomEnts
|
|
25
|
+
*/
|
|
26
|
+
export declare function loadEntsFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, clause: clause.Clause, options: LoadEntOptions<TEnt, TViewer>): Promise<Map<ID, TEnt>>;
|
|
27
|
+
export declare function loadCustomEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadCustomEntOptions<TEnt, TViewer>, query: CustomQuery): Promise<TEnt[]>;
|
|
28
|
+
interface parameterizedQueryOptions {
|
|
18
29
|
query: string;
|
|
19
30
|
values?: any[];
|
|
20
31
|
logValues?: any[];
|
|
21
32
|
}
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
export type CustomQuery = string | parameterizedQueryOptions | clause.Clause | QueryDataOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
|
|
36
|
+
* either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
|
|
37
|
+
* (e.g. soft delete) is applied.
|
|
38
|
+
*
|
|
39
|
+
* Passing a full SQL string or Paramterized SQL string doesn't apply it and the given string is sent to the
|
|
40
|
+
* database as written.
|
|
41
|
+
*
|
|
42
|
+
* e.g.
|
|
43
|
+
* Foo.loadCustom(opts, 'SELECT * FROM foo') // doesn't change the query
|
|
44
|
+
* Foo.loadCustom(opts, { query: 'SELECT * FROM foo WHERE id = ?', values: [1]}) // doesn't change the query
|
|
45
|
+
* Foo.loadCustom(opts, query.Eq('time', Date.now())) // changes the query
|
|
46
|
+
* Foo.loadCustom(opts, {
|
|
47
|
+
* clause: query.LessEq('time', Date.now()),
|
|
48
|
+
* limit: 100,
|
|
49
|
+
* orderby: 'time',
|
|
50
|
+
* }) // changes the query
|
|
51
|
+
* Foo.loadCustom(opts, {
|
|
52
|
+
* clause: query.LessEq('time', Date.now()),
|
|
53
|
+
* limit: 100,
|
|
54
|
+
* orderby: 'time',
|
|
55
|
+
* disableTransformations: false
|
|
56
|
+
* }) // doesn't change the query
|
|
57
|
+
*/
|
|
58
|
+
export declare function loadCustomData(options: SelectCustomDataOptions, query: CustomQuery, context: Context | undefined): Promise<Data[]>;
|
|
59
|
+
interface CustomCountOptions extends DataOptions {
|
|
60
|
+
}
|
|
61
|
+
export declare function loadCustomCount(options: CustomCountOptions, query: CustomQuery, context: Context | undefined): Promise<number>;
|
|
62
|
+
export declare function loadDerivedEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt | null>;
|
|
63
|
+
export declare function loadDerivedEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt>;
|
|
64
|
+
export declare function logQuery(query: string, logValues: any[]): void;
|
|
28
65
|
export declare function loadRowX(options: LoadRowOptions): Promise<Data>;
|
|
29
66
|
export declare function loadRow(options: LoadRowOptions): Promise<Data | null>;
|
|
67
|
+
export declare function ___setLogQueryErrorWithError(val: boolean | undefined): void;
|
|
30
68
|
export declare function performRawQuery(query: string, values: any[], logValues?: any[]): Promise<Data[]>;
|
|
31
69
|
export declare function loadRows(options: LoadRowsOptions): Promise<Data[]>;
|
|
32
70
|
export declare function buildQuery(options: QueryableDataOptions): string;
|
|
@@ -52,8 +90,15 @@ export interface DataOperation<T extends Ent = Ent> {
|
|
|
52
90
|
}
|
|
53
91
|
export interface EditNodeOptions<T extends Ent> extends EditRowOptions {
|
|
54
92
|
fieldsToResolve: string[];
|
|
55
|
-
|
|
93
|
+
loadEntOptions: LoadEntOptions<T>;
|
|
56
94
|
placeholderID?: ID;
|
|
95
|
+
key: string;
|
|
96
|
+
}
|
|
97
|
+
export declare class RawQueryOperation implements DataOperation {
|
|
98
|
+
private queries;
|
|
99
|
+
constructor(queries: (string | parameterizedQueryOptions)[]);
|
|
100
|
+
performWrite(queryer: Queryer, context?: Context): Promise<void>;
|
|
101
|
+
performWriteSync(queryer: SyncQueryer, context?: Context): void;
|
|
57
102
|
}
|
|
58
103
|
export declare class EditNodeOperation<T extends Ent> implements DataOperation {
|
|
59
104
|
options: EditNodeOptions<T>;
|
|
@@ -69,7 +114,11 @@ export declare class EditNodeOperation<T extends Ent> implements DataOperation {
|
|
|
69
114
|
returnedRow(): Data | null;
|
|
70
115
|
createdEnt(viewer: Viewer): T | null;
|
|
71
116
|
}
|
|
117
|
+
export declare function setGlobalSchema(val: GlobalSchema): void;
|
|
118
|
+
export declare function clearGlobalSchema(): void;
|
|
119
|
+
export declare function __hasGlobalSchema(): boolean;
|
|
72
120
|
export declare class EdgeOperation implements DataOperation {
|
|
121
|
+
private builder;
|
|
73
122
|
edgeInput: AssocEdgeInput;
|
|
74
123
|
private options;
|
|
75
124
|
private edgeData;
|
|
@@ -98,9 +147,9 @@ export declare class EdgeOperation implements DataOperation {
|
|
|
98
147
|
export declare function buildInsertQuery(options: CreateRowOptions, suffix?: string): [string, string[], string[]];
|
|
99
148
|
export declare function createRow(queryer: Queryer, options: CreateRowOptions, suffix: string): Promise<Data | null>;
|
|
100
149
|
export declare function createRowSync(queryer: SyncQueryer, options: CreateRowOptions, suffix: string): Data | null;
|
|
101
|
-
export declare function buildUpdateQuery(options: EditRowOptions,
|
|
102
|
-
export declare function editRow(queryer: Queryer, options: EditRowOptions,
|
|
103
|
-
export declare function editRowSync(queryer: SyncQueryer, options: EditRowOptions,
|
|
150
|
+
export declare function buildUpdateQuery(options: EditRowOptions, suffix?: string): [string, any[], any[]];
|
|
151
|
+
export declare function editRow(queryer: Queryer, options: EditRowOptions, suffix?: string): Promise<Data | null>;
|
|
152
|
+
export declare function editRowSync(queryer: SyncQueryer, options: EditRowOptions, suffix?: string): Data | null;
|
|
104
153
|
export declare function deleteRows(queryer: Queryer, options: DataOptions, cls: clause.Clause): Promise<void>;
|
|
105
154
|
export declare function deleteRowsSync(queryer: SyncQueryer, options: DataOptions, cls: clause.Clause): void;
|
|
106
155
|
export declare class DeleteNodeOperation implements DataOperation {
|
|
@@ -118,7 +167,9 @@ export declare class AssocEdge {
|
|
|
118
167
|
id2Type: string;
|
|
119
168
|
time: Date;
|
|
120
169
|
data?: string | null;
|
|
170
|
+
private rawData;
|
|
121
171
|
constructor(data: Data);
|
|
172
|
+
__getRawData(): Data;
|
|
122
173
|
getCursor(): string;
|
|
123
174
|
}
|
|
124
175
|
interface cursorOptions {
|
|
@@ -147,7 +198,7 @@ export declare class AssocEdgeData {
|
|
|
147
198
|
edgeTable: string;
|
|
148
199
|
constructor(data: Data);
|
|
149
200
|
}
|
|
150
|
-
export declare const assocEdgeLoader: DataLoader<
|
|
201
|
+
export declare const assocEdgeLoader: DataLoader<ID, Data | null, ID>;
|
|
151
202
|
export declare function loadEdgeData(edgeType: string): Promise<AssocEdgeData | null>;
|
|
152
203
|
export declare function loadEdgeDatas(...edgeTypes: string[]): Promise<Map<string, AssocEdgeData>>;
|
|
153
204
|
export interface AssocEdgeConstructor<T extends AssocEdge> {
|
|
@@ -158,24 +209,27 @@ interface loadEdgesOptions {
|
|
|
158
209
|
edgeType: string;
|
|
159
210
|
context?: Context;
|
|
160
211
|
queryOptions?: EdgeQueryableDataOptions;
|
|
212
|
+
disableTransformations?: boolean;
|
|
161
213
|
}
|
|
162
214
|
interface loadCustomEdgesOptions<T extends AssocEdge> extends loadEdgesOptions {
|
|
163
215
|
ctr: AssocEdgeConstructor<T>;
|
|
164
216
|
}
|
|
165
217
|
export declare const DefaultLimit = 1000;
|
|
166
|
-
export declare function defaultEdgeQueryOptions(id1: ID, edgeType: string): EdgeQueryableDataOptions;
|
|
167
218
|
export declare function loadEdges(options: loadEdgesOptions): Promise<AssocEdge[]>;
|
|
219
|
+
export declare function getEdgeClauseAndFields(cls: clause.Clause, options: Pick<loadEdgesOptions, "disableTransformations">): {
|
|
220
|
+
cls: clause.Clause;
|
|
221
|
+
fields: string[];
|
|
222
|
+
};
|
|
168
223
|
export declare function loadCustomEdges<T extends AssocEdge>(options: loadCustomEdgesOptions<T>): Promise<T[]>;
|
|
169
224
|
export declare function loadUniqueEdge(options: loadEdgesOptions): Promise<AssocEdge | null>;
|
|
170
|
-
export declare function loadUniqueNode<
|
|
225
|
+
export declare function loadUniqueNode<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id1: ID, edgeType: string, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
|
|
171
226
|
export declare function loadRawEdgeCountX(options: loadEdgesOptions): Promise<number>;
|
|
172
227
|
interface loadEdgeForIDOptions<T extends AssocEdge> extends loadCustomEdgesOptions<T> {
|
|
173
228
|
id2: ID;
|
|
174
229
|
}
|
|
175
230
|
export declare function loadEdgeForID2<T extends AssocEdge>(options: loadEdgeForIDOptions<T>): Promise<T | undefined>;
|
|
176
231
|
export declare function loadNodesByEdge<T extends Ent>(viewer: Viewer, id1: ID, edgeType: string, options: LoadEntOptions<T>): Promise<T[]>;
|
|
177
|
-
export declare function applyPrivacyPolicyForRow<
|
|
178
|
-
export declare function
|
|
179
|
-
export declare function applyPrivacyPolicyForRows<T extends Ent>(viewer: Viewer, rows: Data[], options: LoadEntOptions<T>): Promise<Map<ID, T>>;
|
|
232
|
+
export declare function applyPrivacyPolicyForRow<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, row: Data): Promise<TEnt | null>;
|
|
233
|
+
export declare function applyPrivacyPolicyForRows<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, rows: Data[], options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt[]>;
|
|
180
234
|
export declare function getEdgeTypeInGroup<T extends string>(viewer: Viewer, id1: ID, id2: ID, m: Map<T, string>): Promise<[T, AssocEdge] | undefined>;
|
|
181
235
|
export {};
|