@snowtop/ent 0.1.0-alpha12 → 0.1.0-alpha121
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 +37 -31
- 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 +33 -14
- package/action/orchestrator.js +251 -54
- 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 +60 -37
- package/core/base.js +7 -1
- package/core/clause.d.ts +84 -40
- package/core/clause.js +358 -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 +82 -30
- package/core/ent.js +632 -193
- 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 +11 -10
- package/core/loaders/object_loader.js +70 -60
- 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 +15 -7
- package/graphql/graphql.js +23 -7
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +3 -4
- 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/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 -16
- package/parse_schema/parse.d.ts +31 -9
- package/parse_schema/parse.js +152 -12
- package/schema/base_schema.d.ts +5 -3
- package/schema/base_schema.js +6 -0
- package/schema/field.d.ts +78 -21
- package/schema/field.js +219 -72
- 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 -20
- package/schema/schema.js +13 -14
- package/schema/struct_field.d.ts +15 -3
- package/schema/struct_field.js +71 -22
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +124 -31
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +117 -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 +43 -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 +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 +7 -1
- package/testutils/ent-graphql-tests/index.js +52 -23
- 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 +8 -4
- package/testutils/fake_data/fake_contact.js +15 -8
- package/testutils/fake_data/fake_event.d.ts +5 -2
- package/testutils/fake_data/fake_event.js +9 -7
- 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 -7
- package/testutils/fake_data/fake_user.js +18 -16
- 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/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.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,82 @@
|
|
|
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>, 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;
|
|
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
|
+
export declare function loadCustomData<TQueryData extends Data = Data, TResultData extends Data = TQueryData, K = keyof TQueryData>(options: SelectCustomDataOptions, query: CustomQuery<TQueryData, K>, context: Context | undefined): Promise<TResultData[]>;
|
|
58
|
+
interface CustomCountOptions extends DataOptions {
|
|
59
|
+
}
|
|
60
|
+
export declare function loadCustomCount<T extends Data = Data, K = keyof T>(options: CustomCountOptions, query: CustomQuery<T, K>, context: Context | undefined): Promise<number>;
|
|
61
|
+
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>;
|
|
62
|
+
export declare function loadDerivedEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt>;
|
|
63
|
+
export declare function logQuery(query: string, logValues: any[]): void;
|
|
26
64
|
export declare function loadRowX(options: LoadRowOptions): Promise<Data>;
|
|
27
65
|
export declare function loadRow(options: LoadRowOptions): Promise<Data | null>;
|
|
66
|
+
export declare function ___setLogQueryErrorWithError(val: boolean | undefined): void;
|
|
28
67
|
export declare function performRawQuery(query: string, values: any[], logValues?: any[]): Promise<Data[]>;
|
|
29
68
|
export declare function loadRows(options: LoadRowsOptions): Promise<Data[]>;
|
|
30
69
|
export declare function buildQuery(options: QueryableDataOptions): string;
|
|
31
|
-
interface GroupQueryOptions {
|
|
70
|
+
interface GroupQueryOptions<T extends Data, K = keyof T> {
|
|
32
71
|
tableName: string;
|
|
33
|
-
clause?: clause.Clause
|
|
34
|
-
groupColumn:
|
|
35
|
-
fields:
|
|
72
|
+
clause?: clause.Clause<T, K>;
|
|
73
|
+
groupColumn: K;
|
|
74
|
+
fields: K[];
|
|
36
75
|
values: any[];
|
|
37
76
|
orderby?: string;
|
|
38
77
|
limit: number;
|
|
39
78
|
}
|
|
40
|
-
export declare function buildGroupQuery(options: GroupQueryOptions): [string, clause.Clause];
|
|
79
|
+
export declare function buildGroupQuery<T extends Data = Data, K = keyof T>(options: GroupQueryOptions<T, K>): [string, clause.Clause<T, K>];
|
|
41
80
|
export interface DataOperation<T extends Ent = Ent> {
|
|
42
81
|
preFetch?(queryer: Queryer, context?: Context): Promise<void>;
|
|
43
82
|
performWriteSync(queryer: SyncQueryer, context?: Context): void;
|
|
@@ -52,6 +91,13 @@ export interface EditNodeOptions<T extends Ent> extends EditRowOptions {
|
|
|
52
91
|
fieldsToResolve: string[];
|
|
53
92
|
loadEntOptions: LoadEntOptions<T>;
|
|
54
93
|
placeholderID?: ID;
|
|
94
|
+
key: string;
|
|
95
|
+
}
|
|
96
|
+
export declare class RawQueryOperation implements DataOperation {
|
|
97
|
+
private queries;
|
|
98
|
+
constructor(queries: (string | parameterizedQueryOptions)[]);
|
|
99
|
+
performWrite(queryer: Queryer, context?: Context): Promise<void>;
|
|
100
|
+
performWriteSync(queryer: SyncQueryer, context?: Context): void;
|
|
55
101
|
}
|
|
56
102
|
export declare class EditNodeOperation<T extends Ent> implements DataOperation {
|
|
57
103
|
options: EditNodeOptions<T>;
|
|
@@ -68,6 +114,7 @@ export declare class EditNodeOperation<T extends Ent> implements DataOperation {
|
|
|
68
114
|
createdEnt(viewer: Viewer): T | null;
|
|
69
115
|
}
|
|
70
116
|
export declare class EdgeOperation implements DataOperation {
|
|
117
|
+
private builder;
|
|
71
118
|
edgeInput: AssocEdgeInput;
|
|
72
119
|
private options;
|
|
73
120
|
private edgeData;
|
|
@@ -96,9 +143,9 @@ export declare class EdgeOperation implements DataOperation {
|
|
|
96
143
|
export declare function buildInsertQuery(options: CreateRowOptions, suffix?: string): [string, string[], string[]];
|
|
97
144
|
export declare function createRow(queryer: Queryer, options: CreateRowOptions, suffix: string): Promise<Data | null>;
|
|
98
145
|
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,
|
|
146
|
+
export declare function buildUpdateQuery(options: EditRowOptions, suffix?: string): [string, any[], any[]];
|
|
147
|
+
export declare function editRow(queryer: Queryer, options: EditRowOptions, suffix?: string): Promise<Data | null>;
|
|
148
|
+
export declare function editRowSync(queryer: SyncQueryer, options: EditRowOptions, suffix?: string): Data | null;
|
|
102
149
|
export declare function deleteRows(queryer: Queryer, options: DataOptions, cls: clause.Clause): Promise<void>;
|
|
103
150
|
export declare function deleteRowsSync(queryer: SyncQueryer, options: DataOptions, cls: clause.Clause): void;
|
|
104
151
|
export declare class DeleteNodeOperation implements DataOperation {
|
|
@@ -116,7 +163,9 @@ export declare class AssocEdge {
|
|
|
116
163
|
id2Type: string;
|
|
117
164
|
time: Date;
|
|
118
165
|
data?: string | null;
|
|
166
|
+
private rawData;
|
|
119
167
|
constructor(data: Data);
|
|
168
|
+
__getRawData(): Data;
|
|
120
169
|
getCursor(): string;
|
|
121
170
|
}
|
|
122
171
|
interface cursorOptions {
|
|
@@ -145,7 +194,7 @@ export declare class AssocEdgeData {
|
|
|
145
194
|
edgeTable: string;
|
|
146
195
|
constructor(data: Data);
|
|
147
196
|
}
|
|
148
|
-
export declare const assocEdgeLoader: DataLoader<
|
|
197
|
+
export declare const assocEdgeLoader: DataLoader<ID, Data | null, ID>;
|
|
149
198
|
export declare function loadEdgeData(edgeType: string): Promise<AssocEdgeData | null>;
|
|
150
199
|
export declare function loadEdgeDatas(...edgeTypes: string[]): Promise<Map<string, AssocEdgeData>>;
|
|
151
200
|
export interface AssocEdgeConstructor<T extends AssocEdge> {
|
|
@@ -156,24 +205,27 @@ interface loadEdgesOptions {
|
|
|
156
205
|
edgeType: string;
|
|
157
206
|
context?: Context;
|
|
158
207
|
queryOptions?: EdgeQueryableDataOptions;
|
|
208
|
+
disableTransformations?: boolean;
|
|
159
209
|
}
|
|
160
210
|
interface loadCustomEdgesOptions<T extends AssocEdge> extends loadEdgesOptions {
|
|
161
211
|
ctr: AssocEdgeConstructor<T>;
|
|
162
212
|
}
|
|
163
213
|
export declare const DefaultLimit = 1000;
|
|
164
|
-
export declare function defaultEdgeQueryOptions(id1: ID, edgeType: string): EdgeQueryableDataOptions;
|
|
165
214
|
export declare function loadEdges(options: loadEdgesOptions): Promise<AssocEdge[]>;
|
|
215
|
+
export declare function getEdgeClauseAndFields(cls: clause.Clause, options: Pick<loadEdgesOptions, "disableTransformations">): {
|
|
216
|
+
cls: clause.Clause<Data, string | number>;
|
|
217
|
+
fields: string[];
|
|
218
|
+
};
|
|
166
219
|
export declare function loadCustomEdges<T extends AssocEdge>(options: loadCustomEdgesOptions<T>): Promise<T[]>;
|
|
167
220
|
export declare function loadUniqueEdge(options: loadEdgesOptions): Promise<AssocEdge | null>;
|
|
168
|
-
export declare function loadUniqueNode<
|
|
221
|
+
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
222
|
export declare function loadRawEdgeCountX(options: loadEdgesOptions): Promise<number>;
|
|
170
223
|
interface loadEdgeForIDOptions<T extends AssocEdge> extends loadCustomEdgesOptions<T> {
|
|
171
224
|
id2: ID;
|
|
172
225
|
}
|
|
173
226
|
export declare function loadEdgeForID2<T extends AssocEdge>(options: loadEdgeForIDOptions<T>): Promise<T | undefined>;
|
|
174
227
|
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>>;
|
|
228
|
+
export declare function applyPrivacyPolicyForRow<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, row: Data): Promise<TEnt | null>;
|
|
229
|
+
export declare function applyPrivacyPolicyForRows<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, rows: Data[], options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt[]>;
|
|
178
230
|
export declare function getEdgeTypeInGroup<T extends string>(viewer: Viewer, id1: ID, id2: ID, m: Map<T, string>): Promise<[T, AssocEdge] | undefined>;
|
|
179
231
|
export {};
|