@snowtop/ent 0.1.0-alpha13 → 0.1.0-alpha131
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 +33 -29
- package/action/action.js +22 -7
- package/action/executor.d.ts +3 -3
- 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 +32 -15
- package/action/orchestrator.js +249 -53
- 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 +61 -37
- package/core/base.js +7 -1
- package/core/clause.d.ts +85 -40
- package/core/clause.js +375 -64
- package/core/config.d.ts +12 -1
- package/core/config.js +7 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +6 -4
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +11 -8
- package/core/db.js +20 -8
- package/core/ent.d.ts +86 -30
- package/core/ent.js +626 -197
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- 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 +2 -2
- package/core/loaders/assoc_edge_loader.js +8 -11
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +3 -3
- package/core/loaders/loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +32 -11
- package/core/loaders/object_loader.js +225 -78
- package/core/loaders/query_loader.d.ts +7 -13
- 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 +25 -24
- package/core/privacy.js +21 -25
- 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 +27 -0
- package/core/query/custom_clause_query.js +84 -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 +470 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.d.ts +51 -19
- package/graphql/graphql.js +160 -136
- package/graphql/graphql_field_helpers.d.ts +7 -1
- package/graphql/graphql_field_helpers.js +21 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +3 -5
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +1 -19
- package/graphql/scalars/orderby_direction.d.ts +2 -0
- package/graphql/scalars/orderby_direction.js +15 -0
- package/imports/dataz/example1/_auth.js +128 -47
- package/imports/dataz/example1/_viewer.js +87 -39
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +13 -5
- package/index.js +21 -7
- package/package.json +17 -17
- package/parse_schema/parse.d.ts +31 -9
- package/parse_schema/parse.js +155 -13
- package/schema/base_schema.d.ts +7 -3
- package/schema/base_schema.js +10 -0
- package/schema/field.d.ts +78 -21
- package/schema/field.js +231 -71
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +16 -4
- package/schema/json_field.js +32 -2
- package/schema/schema.d.ts +89 -19
- package/schema/schema.js +11 -13
- package/schema/struct_field.d.ts +15 -3
- package/schema/struct_field.js +117 -22
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +128 -31
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +120 -0
- package/scripts/read_schema.js +20 -5
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +41 -47
- package/testutils/builder.js +76 -49
- 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} +24 -8
- package/testutils/db/{test_db.js → temp_db.js} +182 -45
- 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 +52 -7
- 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 +7 -1
- package/testutils/ent-graphql-tests/index.js +52 -23
- package/testutils/fake_comms.js +1 -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 +7 -3
- package/testutils/fake_data/fake_contact.js +13 -7
- package/testutils/fake_data/fake_event.d.ts +4 -1
- package/testutils/fake_data/fake_event.js +7 -6
- 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 +8 -5
- package/testutils/fake_data/fake_user.js +16 -15
- 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 +28 -12
- 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/fake_log.js +1 -1
- 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 +25 -2
- package/tsc/ast.js +141 -17
- package/tsc/compilerOptions.js +5 -1
- 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 +60 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/{scripts → tsc}/transform_schema.js +146 -117
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -142
- package/scripts/transform_code.js +0 -113
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
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
|
-
|
|
14
|
+
loaderWithLoadMany: Map<string, LoaderWithLoadMany<any, any>>;
|
|
15
|
+
getLoader<K, V>(name: string, create: () => Loader<K, V>): Loader<K, V>;
|
|
16
|
+
getLoaderWithLoadMany<K, V>(name: string, create: () => LoaderWithLoadMany<K, V>): LoaderWithLoadMany<K, 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
|
@@ -5,10 +5,9 @@ export interface Database extends PoolConfig {
|
|
|
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",
|
|
@@ -19,6 +18,11 @@ interface DatabaseInfo {
|
|
|
19
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;
|
|
@@ -148,7 +158,7 @@ class DB {
|
|
|
148
158
|
async getNewClient() {
|
|
149
159
|
return this.q.newClient();
|
|
150
160
|
}
|
|
151
|
-
|
|
161
|
+
getSQLiteClient() {
|
|
152
162
|
if (this.db.dialect == Dialect.Postgres) {
|
|
153
163
|
throw new Error(`can't call getSQLiteClient when dialect is postgres`);
|
|
154
164
|
}
|
|
@@ -158,6 +168,10 @@ class DB {
|
|
|
158
168
|
async endPool() {
|
|
159
169
|
return this.q.close();
|
|
160
170
|
}
|
|
171
|
+
emitsExplicitTransactionStatements() {
|
|
172
|
+
const instance = DB.getInstance();
|
|
173
|
+
return instance.q.runInTransaction === undefined;
|
|
174
|
+
}
|
|
161
175
|
// throws if invalid
|
|
162
176
|
static getInstance() {
|
|
163
177
|
if (DB.instance) {
|
|
@@ -192,8 +206,6 @@ exports.defaultTimestampParser = pg_1.default.types.getTypeParser(pg_1.default.t
|
|
|
192
206
|
// it's parsed as UTC time as opposed to the local time
|
|
193
207
|
pg_1.default.types.setTypeParser(pg_1.default.types.builtins.TIMESTAMP, function (val) {
|
|
194
208
|
return luxon_1.DateTime.fromSQL(val + "Z").toJSDate();
|
|
195
|
-
// let d = new Date(val + "Z");
|
|
196
|
-
// return d;
|
|
197
209
|
});
|
|
198
210
|
class Sqlite {
|
|
199
211
|
constructor(db) {
|
|
@@ -312,7 +324,7 @@ class Postgres {
|
|
|
312
324
|
};
|
|
313
325
|
}
|
|
314
326
|
async close() {
|
|
315
|
-
return this.pool.end();
|
|
327
|
+
return await this.pool.end();
|
|
316
328
|
}
|
|
317
329
|
}
|
|
318
330
|
exports.Postgres = Postgres;
|
package/core/ent.d.ts
CHANGED
|
@@ -1,43 +1,86 @@
|
|
|
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
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export declare function
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
export declare function getEntKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): string;
|
|
8
|
+
export declare function loadEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
|
|
9
|
+
export declare function loadEntViaKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, key: any, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
|
|
10
|
+
export declare function loadEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt>;
|
|
11
|
+
export declare function loadEntXViaKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, key: any, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt>;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated use loadCustomEnts
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadEntFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, clause: clause.Clause): Promise<TEnt | null>;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated use loadCustomEnts
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadEntXFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, clause: clause.Clause): Promise<TEnt>;
|
|
20
|
+
export declare function loadEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, ...ids: ID[]): Promise<Map<ID, TEnt>>;
|
|
21
|
+
export declare function loadEntsList<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, ...ids: ID[]): Promise<TEnt[]>;
|
|
22
|
+
/**
|
|
23
|
+
* @deperecated use loadCustomEnts
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadEntsFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, clause: clause.Clause, options: LoadEntOptions<TEnt, TViewer>): Promise<Map<ID, TEnt>>;
|
|
26
|
+
export declare function loadCustomEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer, TQueryData extends Data = Data, TResultData extends Data = TQueryData, TKey = keyof TQueryData>(viewer: TViewer, options: LoadCustomEntOptions<TEnt, TViewer, TResultData>, query: CustomQuery<TQueryData, TKey>): Promise<TEnt[]>;
|
|
27
|
+
interface parameterizedQueryOptions {
|
|
18
28
|
query: string;
|
|
19
29
|
values?: any[];
|
|
20
30
|
logValues?: any[];
|
|
21
31
|
}
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
export type CustomQuery<T extends Data = Data, K = keyof T> = string | parameterizedQueryOptions | clause.Clause<T, K> | QueryDataOptions<T, K>;
|
|
33
|
+
/**
|
|
34
|
+
* Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
|
|
35
|
+
* either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
|
|
36
|
+
* (e.g. soft delete) is applied.
|
|
37
|
+
*
|
|
38
|
+
* Passing a full SQL string or Paramterized SQL string doesn't apply it and the given string is sent to the
|
|
39
|
+
* database as written.
|
|
40
|
+
*
|
|
41
|
+
* e.g.
|
|
42
|
+
* Foo.loadCustom(opts, 'SELECT * FROM foo') // doesn't change the query
|
|
43
|
+
* Foo.loadCustom(opts, { query: 'SELECT * FROM foo WHERE id = ?', values: [1]}) // doesn't change the query
|
|
44
|
+
* Foo.loadCustom(opts, query.Eq('time', Date.now())) // changes the query
|
|
45
|
+
* Foo.loadCustom(opts, {
|
|
46
|
+
* clause: query.LessEq('time', Date.now()),
|
|
47
|
+
* limit: 100,
|
|
48
|
+
* orderby: 'time',
|
|
49
|
+
* }) // changes the query
|
|
50
|
+
* Foo.loadCustom(opts, {
|
|
51
|
+
* clause: query.LessEq('time', Date.now()),
|
|
52
|
+
* limit: 100,
|
|
53
|
+
* orderby: 'time',
|
|
54
|
+
* disableTransformations: false
|
|
55
|
+
* }) // doesn't change the query
|
|
56
|
+
*
|
|
57
|
+
* For queries that pass in a clause, we batch them with an underlying dataloader so that multiple queries with the same clause
|
|
58
|
+
* or parallel queries with the same clause are batched together.
|
|
59
|
+
*
|
|
60
|
+
* If a raw or parameterized query is passed in, we don't attempt to batch them together and they're executed as is.
|
|
61
|
+
* If you end up with a scenario where you may need to coalesce or batch (non-clause) queries here, you should use some kind of memoization here.
|
|
62
|
+
*/
|
|
63
|
+
export declare function loadCustomData<TQueryData extends Data = Data, TResultData extends Data = TQueryData, K = keyof TQueryData>(options: SelectCustomDataOptions<TResultData>, query: CustomQuery<TQueryData, K>, context: Context | undefined): Promise<TResultData[]>;
|
|
64
|
+
export declare function loadCustomCount<T extends Data = Data, K = keyof T>(options: SelectCustomDataOptions<T>, query: CustomQuery<T, K>, context: Context | undefined): Promise<number>;
|
|
65
|
+
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>;
|
|
66
|
+
export declare function loadDerivedEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt>;
|
|
67
|
+
export declare function logQuery(query: string, logValues: any[]): void;
|
|
26
68
|
export declare function loadRowX(options: LoadRowOptions): Promise<Data>;
|
|
27
69
|
export declare function loadRow(options: LoadRowOptions): Promise<Data | null>;
|
|
70
|
+
export declare function ___setLogQueryErrorWithError(val: boolean | undefined): void;
|
|
28
71
|
export declare function performRawQuery(query: string, values: any[], logValues?: any[]): Promise<Data[]>;
|
|
29
72
|
export declare function loadRows(options: LoadRowsOptions): Promise<Data[]>;
|
|
30
73
|
export declare function buildQuery(options: QueryableDataOptions): string;
|
|
31
|
-
interface GroupQueryOptions {
|
|
74
|
+
interface GroupQueryOptions<T extends Data, K = keyof T> {
|
|
32
75
|
tableName: string;
|
|
33
|
-
clause?: clause.Clause
|
|
34
|
-
groupColumn:
|
|
35
|
-
fields:
|
|
76
|
+
clause?: clause.Clause<T, K>;
|
|
77
|
+
groupColumn: K;
|
|
78
|
+
fields: K[];
|
|
36
79
|
values: any[];
|
|
37
80
|
orderby?: string;
|
|
38
81
|
limit: number;
|
|
39
82
|
}
|
|
40
|
-
export declare function buildGroupQuery(options: GroupQueryOptions): [string, clause.Clause];
|
|
83
|
+
export declare function buildGroupQuery<T extends Data = Data, K = keyof T>(options: GroupQueryOptions<T, K>): [string, clause.Clause<T, K>];
|
|
41
84
|
export interface DataOperation<T extends Ent = Ent> {
|
|
42
85
|
preFetch?(queryer: Queryer, context?: Context): Promise<void>;
|
|
43
86
|
performWriteSync(queryer: SyncQueryer, context?: Context): void;
|
|
@@ -52,6 +95,13 @@ export interface EditNodeOptions<T extends Ent> extends EditRowOptions {
|
|
|
52
95
|
fieldsToResolve: string[];
|
|
53
96
|
loadEntOptions: LoadEntOptions<T>;
|
|
54
97
|
placeholderID?: ID;
|
|
98
|
+
key: string;
|
|
99
|
+
}
|
|
100
|
+
export declare class RawQueryOperation implements DataOperation {
|
|
101
|
+
private queries;
|
|
102
|
+
constructor(queries: (string | parameterizedQueryOptions)[]);
|
|
103
|
+
performWrite(queryer: Queryer, context?: Context): Promise<void>;
|
|
104
|
+
performWriteSync(queryer: SyncQueryer, context?: Context): void;
|
|
55
105
|
}
|
|
56
106
|
export declare class EditNodeOperation<T extends Ent> implements DataOperation {
|
|
57
107
|
options: EditNodeOptions<T>;
|
|
@@ -68,6 +118,7 @@ export declare class EditNodeOperation<T extends Ent> implements DataOperation {
|
|
|
68
118
|
createdEnt(viewer: Viewer): T | null;
|
|
69
119
|
}
|
|
70
120
|
export declare class EdgeOperation implements DataOperation {
|
|
121
|
+
private builder;
|
|
71
122
|
edgeInput: AssocEdgeInput;
|
|
72
123
|
private options;
|
|
73
124
|
private edgeData;
|
|
@@ -96,9 +147,9 @@ export declare class EdgeOperation implements DataOperation {
|
|
|
96
147
|
export declare function buildInsertQuery(options: CreateRowOptions, suffix?: string): [string, string[], string[]];
|
|
97
148
|
export declare function createRow(queryer: Queryer, options: CreateRowOptions, suffix: string): Promise<Data | null>;
|
|
98
149
|
export declare function createRowSync(queryer: SyncQueryer, options: CreateRowOptions, suffix: string): Data | null;
|
|
99
|
-
export declare function buildUpdateQuery(options: EditRowOptions,
|
|
100
|
-
export declare function editRow(queryer: Queryer, options: EditRowOptions,
|
|
101
|
-
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;
|
|
102
153
|
export declare function deleteRows(queryer: Queryer, options: DataOptions, cls: clause.Clause): Promise<void>;
|
|
103
154
|
export declare function deleteRowsSync(queryer: SyncQueryer, options: DataOptions, cls: clause.Clause): void;
|
|
104
155
|
export declare class DeleteNodeOperation implements DataOperation {
|
|
@@ -116,7 +167,9 @@ export declare class AssocEdge {
|
|
|
116
167
|
id2Type: string;
|
|
117
168
|
time: Date;
|
|
118
169
|
data?: string | null;
|
|
170
|
+
private rawData;
|
|
119
171
|
constructor(data: Data);
|
|
172
|
+
__getRawData(): Data;
|
|
120
173
|
getCursor(): string;
|
|
121
174
|
}
|
|
122
175
|
interface cursorOptions {
|
|
@@ -145,7 +198,7 @@ export declare class AssocEdgeData {
|
|
|
145
198
|
edgeTable: string;
|
|
146
199
|
constructor(data: Data);
|
|
147
200
|
}
|
|
148
|
-
export declare const assocEdgeLoader: DataLoader<
|
|
201
|
+
export declare const assocEdgeLoader: DataLoader<ID, Data | null, ID>;
|
|
149
202
|
export declare function loadEdgeData(edgeType: string): Promise<AssocEdgeData | null>;
|
|
150
203
|
export declare function loadEdgeDatas(...edgeTypes: string[]): Promise<Map<string, AssocEdgeData>>;
|
|
151
204
|
export interface AssocEdgeConstructor<T extends AssocEdge> {
|
|
@@ -156,24 +209,27 @@ interface loadEdgesOptions {
|
|
|
156
209
|
edgeType: string;
|
|
157
210
|
context?: Context;
|
|
158
211
|
queryOptions?: EdgeQueryableDataOptions;
|
|
212
|
+
disableTransformations?: boolean;
|
|
159
213
|
}
|
|
160
214
|
interface loadCustomEdgesOptions<T extends AssocEdge> extends loadEdgesOptions {
|
|
161
215
|
ctr: AssocEdgeConstructor<T>;
|
|
162
216
|
}
|
|
163
217
|
export declare const DefaultLimit = 1000;
|
|
164
|
-
export declare function defaultEdgeQueryOptions(id1: ID, edgeType: string): EdgeQueryableDataOptions;
|
|
165
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<Data, string | number>;
|
|
221
|
+
fields: string[];
|
|
222
|
+
};
|
|
166
223
|
export declare function loadCustomEdges<T extends AssocEdge>(options: loadCustomEdgesOptions<T>): Promise<T[]>;
|
|
167
224
|
export declare function loadUniqueEdge(options: loadEdgesOptions): Promise<AssocEdge | null>;
|
|
168
|
-
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>;
|
|
169
226
|
export declare function loadRawEdgeCountX(options: loadEdgesOptions): Promise<number>;
|
|
170
227
|
interface loadEdgeForIDOptions<T extends AssocEdge> extends loadCustomEdgesOptions<T> {
|
|
171
228
|
id2: ID;
|
|
172
229
|
}
|
|
173
230
|
export declare function loadEdgeForID2<T extends AssocEdge>(options: loadEdgeForIDOptions<T>): Promise<T | undefined>;
|
|
174
231
|
export declare function loadNodesByEdge<T extends Ent>(viewer: Viewer, id1: ID, edgeType: string, options: LoadEntOptions<T>): Promise<T[]>;
|
|
175
|
-
export declare function applyPrivacyPolicyForRow<
|
|
176
|
-
export declare function
|
|
177
|
-
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[]>;
|
|
178
234
|
export declare function getEdgeTypeInGroup<T extends string>(viewer: Viewer, id1: ID, id2: ID, m: Map<T, string>): Promise<[T, AssocEdge] | undefined>;
|
|
179
235
|
export {};
|