@snowtop/ent 0.1.0-alpha16 → 0.1.0-alpha160-test2
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 +25 -14
- package/action/action.js +22 -7
- package/action/executor.d.ts +16 -3
- package/action/executor.js +89 -28
- package/action/experimental_action.d.ts +25 -16
- package/action/experimental_action.js +34 -14
- package/action/index.d.ts +4 -1
- package/action/index.js +7 -1
- package/action/operations.d.ts +126 -0
- package/action/operations.js +686 -0
- package/action/orchestrator.d.ts +43 -12
- package/action/orchestrator.js +461 -101
- 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 +56 -23
- package/core/base.js +7 -1
- package/core/clause.d.ts +103 -39
- package/core/clause.js +430 -66
- package/core/config.d.ts +13 -3
- package/core/config.js +10 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +6 -3
- package/core/context.js +22 -3
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +12 -8
- package/core/db.js +21 -9
- package/core/ent.d.ts +99 -95
- package/core/ent.js +550 -602
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +5 -2
- package/core/loaders/assoc_count_loader.js +19 -3
- package/core/loaders/assoc_edge_loader.d.ts +2 -3
- package/core/loaders/assoc_edge_loader.js +23 -17
- package/core/loaders/index.d.ts +1 -2
- package/core/loaders/index.js +1 -5
- package/core/loaders/loader.d.ts +3 -3
- package/core/loaders/loader.js +4 -21
- package/core/loaders/object_loader.d.ts +30 -9
- package/core/loaders/object_loader.js +226 -79
- package/core/loaders/query_loader.d.ts +7 -13
- package/core/loaders/query_loader.js +60 -24
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +8 -3
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -16
- package/core/privacy.js +68 -51
- package/core/query/assoc_query.d.ts +3 -2
- package/core/query/assoc_query.js +10 -2
- package/core/query/custom_clause_query.d.ts +29 -0
- package/core/query/custom_clause_query.js +105 -0
- package/core/query/custom_query.d.ts +19 -2
- package/core/query/custom_query.js +111 -13
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +18 -4
- package/core/query/query.js +135 -58
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +186 -55
- package/core/query/shared_test.d.ts +9 -2
- package/core/query/shared_test.js +529 -236
- package/core/query_impl.d.ts +8 -0
- package/core/query_impl.js +28 -0
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +3 -1
- package/graphql/graphql.d.ts +108 -22
- package/graphql/graphql.js +183 -137
- package/graphql/graphql_field_helpers.d.ts +9 -3
- package/graphql/graphql_field_helpers.js +22 -2
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +5 -5
- package/graphql/query/connection_type.d.ts +9 -9
- 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 +7 -2
- package/imports/index.js +20 -5
- package/index.d.ts +23 -5
- package/index.js +35 -10
- package/package.json +20 -19
- package/parse_schema/parse.d.ts +33 -9
- package/parse_schema/parse.js +182 -33
- package/schema/base_schema.d.ts +13 -3
- package/schema/base_schema.js +13 -0
- package/schema/field.d.ts +78 -21
- package/schema/field.js +232 -72
- package/schema/index.d.ts +2 -2
- package/schema/index.js +7 -2
- package/schema/json_field.d.ts +16 -4
- package/schema/json_field.js +32 -2
- package/schema/schema.d.ts +109 -20
- package/schema/schema.js +42 -53
- 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 +12 -8
- package/scripts/custom_graphql.js +167 -64
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +120 -0
- package/scripts/read_schema.js +22 -7
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +405 -0
- package/testutils/builder.d.ts +37 -41
- package/testutils/builder.js +66 -46
- 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} +32 -8
- package/testutils/db/{test_db.js → temp_db.js} +251 -48
- 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 -9
- 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 +56 -26
- 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 +31 -19
- 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 +48 -0
- package/testutils/fake_data/test_helpers.d.ts +14 -6
- package/testutils/fake_data/test_helpers.js +31 -15
- package/testutils/fake_data/user_query.d.ts +16 -6
- package/testutils/fake_data/user_query.js +72 -23
- 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 +15 -3
- package/tsc/ast.js +114 -23
- 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 +182 -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/core/loaders/index_loader.d.ts +0 -14
- package/core/loaders/index_loader.js +0 -27
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -141
- package/scripts/transform_actions.js +0 -266
- package/scripts/transform_code.d.ts +0 -1
- package/scripts/transform_code.js +0 -111
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_actions.d.ts → move_types.d.ts} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Clause } from "../core/clause";
|
|
2
|
+
export interface RelativeFieldValue<T = BigInt | number> {
|
|
3
|
+
delta: T;
|
|
4
|
+
sqlExpression: (col: string) => Clause;
|
|
5
|
+
eval: (curr: T) => T;
|
|
6
|
+
}
|
|
7
|
+
export interface RelativeNumberValue<T> {
|
|
8
|
+
add?: T;
|
|
9
|
+
subtract?: T;
|
|
10
|
+
divide?: T;
|
|
11
|
+
multiply?: T;
|
|
12
|
+
modulo?: T;
|
|
13
|
+
}
|
|
14
|
+
declare function addNumber(delta: number): RelativeFieldValue<number>;
|
|
15
|
+
declare function addNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
16
|
+
declare function subtractNumber(delta: number): RelativeFieldValue<number>;
|
|
17
|
+
declare function subtractNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
18
|
+
declare function multiplyNumber(delta: number): RelativeFieldValue<number>;
|
|
19
|
+
declare function multiplyNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
20
|
+
declare function divideNumber(delta: number): RelativeFieldValue<number>;
|
|
21
|
+
declare function divideNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
22
|
+
declare function moduloNumber(delta: number): RelativeFieldValue<number>;
|
|
23
|
+
declare function moduloNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
24
|
+
export declare const NumberOps: {
|
|
25
|
+
addNumber: typeof addNumber;
|
|
26
|
+
moduloNumber: typeof moduloNumber;
|
|
27
|
+
divideNumber: typeof divideNumber;
|
|
28
|
+
subtractNumber: typeof subtractNumber;
|
|
29
|
+
multiplyNumber: typeof multiplyNumber;
|
|
30
|
+
};
|
|
31
|
+
export declare function convertRelativeInput(rel: RelativeNumberValue<BigInt>, col: string, existing: BigInt): {
|
|
32
|
+
value: BigInt;
|
|
33
|
+
clause: Clause;
|
|
34
|
+
};
|
|
35
|
+
export declare function convertRelativeInput(rel: RelativeNumberValue<number>, col: string, existing: number): {
|
|
36
|
+
value: number;
|
|
37
|
+
clause: Clause;
|
|
38
|
+
};
|
|
39
|
+
export declare function maybeConvertRelativeInputPlusExpressions(rel: number | RelativeNumberValue<number>, col: string, existing: number, expressions: Map<string, Clause>): number;
|
|
40
|
+
export declare function maybeConvertRelativeInputPlusExpressions(rel: number | RelativeNumberValue<number> | undefined, col: string, existing: number, expressions: Map<string, Clause>): number | undefined;
|
|
41
|
+
export declare function maybeConvertRelativeInputPlusExpressions(rel: number | RelativeNumberValue<number> | null, col: string, existing: number | null, expressions: Map<string, Clause>): number | null;
|
|
42
|
+
export declare function maybeConvertRelativeInputPlusExpressions(rel: number | RelativeNumberValue<number> | null | undefined, col: string, existing: number | null, expressions: Map<string, Clause>): number | undefined | null;
|
|
43
|
+
export declare function maybeConvertRelativeInputPlusExpressions(rel: BigInt | RelativeNumberValue<BigInt>, col: string, existing: BigInt, expressions: Map<string, Clause>): BigInt;
|
|
44
|
+
export declare function maybeConvertRelativeInputPlusExpressions(rel: BigInt | RelativeNumberValue<BigInt> | undefined, col: string, existing: BigInt, expressions: Map<string, Clause>): BigInt | undefined;
|
|
45
|
+
export declare function maybeConvertRelativeInputPlusExpressions(rel: BigInt | RelativeNumberValue<BigInt> | null, col: string, existing: BigInt | null, expressions: Map<string, Clause>): BigInt | null;
|
|
46
|
+
export declare function maybeConvertRelativeInputPlusExpressions(rel: BigInt | RelativeNumberValue<BigInt> | null | undefined, col: string, existing: BigInt | null, expressions: Map<string, Clause>): BigInt | null | undefined;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maybeConvertRelativeInputPlusExpressions = exports.convertRelativeInput = exports.NumberOps = void 0;
|
|
4
|
+
const clause_1 = require("../core/clause");
|
|
5
|
+
function addNumber(delta) {
|
|
6
|
+
return {
|
|
7
|
+
delta,
|
|
8
|
+
sqlExpression(col) {
|
|
9
|
+
return (0, clause_1.Add)(col, delta);
|
|
10
|
+
},
|
|
11
|
+
eval(curr) {
|
|
12
|
+
// @ts-expect-error
|
|
13
|
+
return curr + delta;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function subtractNumber(delta) {
|
|
18
|
+
return {
|
|
19
|
+
delta,
|
|
20
|
+
sqlExpression(col) {
|
|
21
|
+
return (0, clause_1.Subtract)(col, delta);
|
|
22
|
+
},
|
|
23
|
+
eval(curr) {
|
|
24
|
+
// @ts-expect-error
|
|
25
|
+
return curr - delta;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function multiplyNumber(delta) {
|
|
30
|
+
return {
|
|
31
|
+
delta,
|
|
32
|
+
sqlExpression(col) {
|
|
33
|
+
return (0, clause_1.Multiply)(col, delta);
|
|
34
|
+
},
|
|
35
|
+
eval(curr) {
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
return curr * delta;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function divideNumber(delta) {
|
|
42
|
+
return {
|
|
43
|
+
delta,
|
|
44
|
+
sqlExpression(col) {
|
|
45
|
+
return (0, clause_1.Divide)(col, delta);
|
|
46
|
+
},
|
|
47
|
+
eval(curr) {
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
return curr / delta;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function moduloNumber(delta) {
|
|
54
|
+
return {
|
|
55
|
+
delta,
|
|
56
|
+
sqlExpression(col) {
|
|
57
|
+
return (0, clause_1.Modulo)(col, delta);
|
|
58
|
+
},
|
|
59
|
+
eval(curr) {
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
return curr % delta;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
exports.NumberOps = {
|
|
66
|
+
addNumber,
|
|
67
|
+
moduloNumber,
|
|
68
|
+
divideNumber,
|
|
69
|
+
subtractNumber,
|
|
70
|
+
multiplyNumber,
|
|
71
|
+
};
|
|
72
|
+
function convertRelativeInput(rel, col, existing) {
|
|
73
|
+
if (Object.keys(rel).length !== 1) {
|
|
74
|
+
throw new Error(`only 1 key is expected. ${Object.keys(rel).length} given`);
|
|
75
|
+
}
|
|
76
|
+
const ret = (relField) => {
|
|
77
|
+
return {
|
|
78
|
+
value: relField.eval(existing),
|
|
79
|
+
clause: relField.sqlExpression(col),
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
if (rel.add !== undefined) {
|
|
83
|
+
// @ts-expect-error
|
|
84
|
+
return ret(addNumber(rel.add));
|
|
85
|
+
}
|
|
86
|
+
if (rel.subtract !== undefined) {
|
|
87
|
+
// @ts-expect-error
|
|
88
|
+
return ret(subtractNumber(rel.subtract));
|
|
89
|
+
}
|
|
90
|
+
if (rel.multiply !== undefined) {
|
|
91
|
+
// @ts-expect-error
|
|
92
|
+
return ret(multiplyNumber(rel.multiply));
|
|
93
|
+
}
|
|
94
|
+
if (rel.divide !== undefined) {
|
|
95
|
+
// @ts-expect-error
|
|
96
|
+
return ret(divideNumber(rel.divide));
|
|
97
|
+
}
|
|
98
|
+
if (rel.modulo !== undefined) {
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
return ret(moduloNumber(rel.modulo));
|
|
101
|
+
}
|
|
102
|
+
throw new Error(`error in convertRelativeInput. shouldn't have gotten here`);
|
|
103
|
+
}
|
|
104
|
+
exports.convertRelativeInput = convertRelativeInput;
|
|
105
|
+
function maybeConvertRelativeInputPlusExpressions(rel, col, existing, expressions) {
|
|
106
|
+
if (rel === null) {
|
|
107
|
+
return rel;
|
|
108
|
+
}
|
|
109
|
+
if (rel === undefined) {
|
|
110
|
+
return rel;
|
|
111
|
+
}
|
|
112
|
+
if (typeof rel === "bigint" || typeof rel === "number") {
|
|
113
|
+
return rel;
|
|
114
|
+
}
|
|
115
|
+
// // TODO is this the behavior we want? should we coalesce as 0?
|
|
116
|
+
// if (existing === null) {
|
|
117
|
+
// throw new Error(`cannot perform a relative operation on null`);
|
|
118
|
+
// }
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
// shouldn't be failing like it currently is. it thinks rel can be bigint and it shouldn't be???
|
|
121
|
+
const { clause, value } = convertRelativeInput(rel, col, existing);
|
|
122
|
+
expressions.set(col, clause);
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
exports.maybeConvertRelativeInputPlusExpressions = maybeConvertRelativeInputPlusExpressions;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Ent, Viewer } from "../core/base";
|
|
2
|
+
import { Action, Builder } from "./action";
|
|
3
|
+
type ActionAny = Action<Ent<Viewer<any, any>>, Builder<Ent<Viewer<any, any>>, Viewer<any, any>, any>, Viewer<any, any>, any, any>;
|
|
4
|
+
export declare class Transaction {
|
|
5
|
+
private viewer;
|
|
6
|
+
private actions;
|
|
7
|
+
constructor(viewer: Viewer, actions: ActionAny[]);
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transaction = void 0;
|
|
4
|
+
const executor_1 = require("./executor");
|
|
5
|
+
class Transaction {
|
|
6
|
+
constructor(viewer,
|
|
7
|
+
// independent operations
|
|
8
|
+
actions) {
|
|
9
|
+
this.viewer = viewer;
|
|
10
|
+
this.actions = actions;
|
|
11
|
+
}
|
|
12
|
+
async run() {
|
|
13
|
+
const changesets = [];
|
|
14
|
+
await Promise.all(this.actions.map(async (action) => {
|
|
15
|
+
const c = await action.changeset();
|
|
16
|
+
changesets.push(c);
|
|
17
|
+
}));
|
|
18
|
+
const executor = new executor_1.ComplexExecutor(this.viewer, "", // no placeholder, no opers
|
|
19
|
+
[], new Map(), changesets);
|
|
20
|
+
await executor.execute();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.Transaction = Transaction;
|
package/auth/auth.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Viewer } from "../core/base";
|
|
3
3
|
import { RequestContext } from "../core/context";
|
|
4
4
|
import { IncomingMessage, ServerResponse } from "http";
|
|
5
|
-
export
|
|
5
|
+
export type AuthViewer = Viewer | null;
|
|
6
6
|
export interface AuthHandler {
|
|
7
7
|
authViewer(ctx: RequestContext): AuthViewer | Promise<AuthViewer>;
|
|
8
8
|
}
|
package/core/base.d.ts
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import * as clause from "./clause";
|
|
2
|
-
|
|
2
|
+
import { ObjectLoaderFactory } from "./loaders";
|
|
3
|
+
import { OrderBy } from "./query_impl";
|
|
4
|
+
export interface Loader<K, V> {
|
|
3
5
|
context?: Context;
|
|
4
|
-
load(key:
|
|
5
|
-
loadMany?(keys:
|
|
6
|
+
load(key: K): Promise<V>;
|
|
7
|
+
loadMany?(keys: K[]): Promise<(V | null)[]>;
|
|
6
8
|
clearAll(): any;
|
|
7
9
|
}
|
|
8
|
-
export interface
|
|
10
|
+
export interface LoaderWithLoadMany<T, V> extends Loader<T, V> {
|
|
11
|
+
loadMany(keys: T[]): Promise<V[]>;
|
|
12
|
+
}
|
|
13
|
+
export interface LoaderFactory<K, V> {
|
|
9
14
|
name: string;
|
|
10
|
-
createLoader(context?: Context): Loader<
|
|
15
|
+
createLoader(context?: Context): Loader<K, V>;
|
|
16
|
+
}
|
|
17
|
+
interface LoaderFactoryWithLoaderMany<T, V> extends LoaderFactory<T, V> {
|
|
18
|
+
createLoader(context?: Context): LoaderWithLoadMany<T, V>;
|
|
11
19
|
}
|
|
12
20
|
export interface ConfigurableLoaderFactory<T, V> extends LoaderFactory<T, V> {
|
|
13
21
|
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<T, V>;
|
|
14
22
|
}
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
|
|
23
|
+
export type EdgeQueryableDataOptions = Partial<Pick<QueryableDataOptions, "limit" | "orderby" | "clause" | "disableTransformations">>;
|
|
24
|
+
export type EdgeQueryableDataOptionsConfigureLoader = Pick<EdgeQueryableDataOptions, "disableTransformations">;
|
|
25
|
+
export interface PrimableLoader<K, V> extends Loader<K, V> {
|
|
26
|
+
prime(d: V): void;
|
|
27
|
+
primeAll?(d: V): void;
|
|
18
28
|
}
|
|
19
29
|
interface cache {
|
|
20
|
-
getLoader<
|
|
30
|
+
getLoader<K, V>(name: string, create: () => Loader<K, V>): Loader<K, V>;
|
|
31
|
+
getLoaderWithLoadMany<K, V>(name: string, create: () => LoaderWithLoadMany<K, V>): LoaderWithLoadMany<K, V>;
|
|
21
32
|
getCachedRows(options: queryOptions): Data[] | null;
|
|
22
33
|
getCachedRow(options: queryOptions): Data | null;
|
|
23
34
|
primeCache(options: queryOptions, rows: Data[]): void;
|
|
@@ -28,7 +39,7 @@ interface queryOptions {
|
|
|
28
39
|
fields: string[];
|
|
29
40
|
tableName: string;
|
|
30
41
|
clause: clause.Clause;
|
|
31
|
-
orderby?:
|
|
42
|
+
orderby?: OrderBy;
|
|
32
43
|
}
|
|
33
44
|
export interface Context<TViewer extends Viewer = Viewer> {
|
|
34
45
|
getViewer(): TViewer;
|
|
@@ -45,6 +56,7 @@ export interface Ent<TViewer extends Viewer = Viewer> {
|
|
|
45
56
|
viewer: TViewer;
|
|
46
57
|
getPrivacyPolicy(): PrivacyPolicy<this, TViewer>;
|
|
47
58
|
nodeType: string;
|
|
59
|
+
__setRawDBData<T extends Data = Data>(data: T): any;
|
|
48
60
|
}
|
|
49
61
|
export declare type Data = {
|
|
50
62
|
[key: string]: any;
|
|
@@ -52,7 +64,7 @@ export declare type Data = {
|
|
|
52
64
|
export interface EntConstructor<TEnt extends Ent, TViewer extends Viewer = Viewer> {
|
|
53
65
|
new (viewer: TViewer, data: Data): TEnt;
|
|
54
66
|
}
|
|
55
|
-
export
|
|
67
|
+
export type ID = string | number;
|
|
56
68
|
export interface DataOptions {
|
|
57
69
|
tableName: string;
|
|
58
70
|
context?: Context;
|
|
@@ -62,44 +74,60 @@ export interface SelectBaseDataOptions extends DataOptions {
|
|
|
62
74
|
}
|
|
63
75
|
export interface SelectDataOptions extends SelectBaseDataOptions {
|
|
64
76
|
key: string;
|
|
77
|
+
keyType?: string;
|
|
65
78
|
clause?: clause.Clause | (() => clause.Clause | undefined);
|
|
66
79
|
}
|
|
67
80
|
export interface QueryableDataOptions extends SelectBaseDataOptions, QueryDataOptions {
|
|
68
81
|
}
|
|
69
|
-
export interface QueryDataOptions {
|
|
82
|
+
export interface QueryDataOptions<T extends Data = Data, K = keyof T> {
|
|
70
83
|
distinct?: boolean;
|
|
71
|
-
clause: clause.Clause
|
|
72
|
-
orderby?:
|
|
73
|
-
groupby?:
|
|
84
|
+
clause: clause.Clause<T, K>;
|
|
85
|
+
orderby?: OrderBy;
|
|
86
|
+
groupby?: K;
|
|
74
87
|
limit?: number;
|
|
88
|
+
disableTransformations?: boolean;
|
|
75
89
|
}
|
|
76
90
|
export interface LoadRowOptions extends QueryableDataOptions {
|
|
77
91
|
}
|
|
78
92
|
export interface LoadRowsOptions extends QueryableDataOptions {
|
|
79
93
|
}
|
|
94
|
+
interface OnConflictOptions {
|
|
95
|
+
onConflictCols: string[];
|
|
96
|
+
onConflictConstraint?: string;
|
|
97
|
+
updateCols?: string[];
|
|
98
|
+
}
|
|
80
99
|
export interface CreateRowOptions extends DataOptions {
|
|
81
100
|
fields: Data;
|
|
82
101
|
fieldsToLog?: Data;
|
|
102
|
+
onConflict?: OnConflictOptions;
|
|
83
103
|
}
|
|
84
|
-
export interface EditRowOptions extends CreateRowOptions {
|
|
85
|
-
|
|
104
|
+
export interface EditRowOptions extends Omit<CreateRowOptions, "onConflict"> {
|
|
105
|
+
whereClause: clause.Clause;
|
|
106
|
+
expressions?: Map<string, clause.Clause>;
|
|
86
107
|
}
|
|
87
|
-
interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> {
|
|
88
|
-
loaderFactory:
|
|
108
|
+
interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> {
|
|
109
|
+
loaderFactory: ObjectLoaderFactory<TData>;
|
|
89
110
|
ent: EntConstructor<TEnt, TViewer>;
|
|
90
111
|
}
|
|
91
|
-
export interface
|
|
112
|
+
export interface LoaderFactoryWithOptions<T extends Data = Data> extends LoaderFactoryWithLoaderMany<any, T | null> {
|
|
113
|
+
options?: SelectDataOptions;
|
|
114
|
+
}
|
|
115
|
+
export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> extends LoadableEntOptions<TEnt, TViewer, TData>, SelectBaseDataOptions {
|
|
92
116
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
93
117
|
}
|
|
94
|
-
export interface
|
|
118
|
+
export interface SelectCustomDataOptions<T extends Data = Data> extends SelectBaseDataOptions {
|
|
119
|
+
loaderFactory: ObjectLoaderFactory<T>;
|
|
120
|
+
prime?: boolean;
|
|
121
|
+
}
|
|
122
|
+
export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> extends SelectCustomDataOptions<TData> {
|
|
95
123
|
ent: EntConstructor<TEnt, TViewer>;
|
|
96
124
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
97
125
|
}
|
|
98
|
-
export interface LoaderInfo {
|
|
126
|
+
export interface LoaderInfo<T = Data> {
|
|
99
127
|
tableName: string;
|
|
100
128
|
fields: string[];
|
|
101
129
|
nodeType: string;
|
|
102
|
-
loaderFactory: LoaderFactory<
|
|
130
|
+
loaderFactory: LoaderFactory<ID, T | null>;
|
|
103
131
|
}
|
|
104
132
|
export interface EditEntOptions<T extends Ent> extends LoadableEntOptions<T>, EditRowOptions {
|
|
105
133
|
}
|
|
@@ -127,4 +155,9 @@ export interface PrivacyPolicyRule<TEnt extends Ent = Ent, TViewer = Viewer> {
|
|
|
127
155
|
export interface PrivacyPolicy<TEnt extends Ent = Ent, TViewer = Viewer> {
|
|
128
156
|
rules: PrivacyPolicyRule<TEnt, TViewer>[];
|
|
129
157
|
}
|
|
158
|
+
export declare enum WriteOperation {
|
|
159
|
+
Insert = "insert",
|
|
160
|
+
Edit = "edit",
|
|
161
|
+
Delete = "delete"
|
|
162
|
+
}
|
|
130
163
|
export {};
|
package/core/base.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DenyWithReason = exports.Deny = exports.Skip = exports.Allow = void 0;
|
|
3
|
+
exports.WriteOperation = exports.DenyWithReason = exports.Deny = exports.Skip = exports.Allow = void 0;
|
|
4
4
|
// Privacy
|
|
5
5
|
var privacyResult;
|
|
6
6
|
(function (privacyResult) {
|
|
@@ -53,3 +53,9 @@ function DenyWithReason(e) {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
exports.DenyWithReason = DenyWithReason;
|
|
56
|
+
var WriteOperation;
|
|
57
|
+
(function (WriteOperation) {
|
|
58
|
+
WriteOperation["Insert"] = "insert";
|
|
59
|
+
WriteOperation["Edit"] = "edit";
|
|
60
|
+
WriteOperation["Delete"] = "delete";
|
|
61
|
+
})(WriteOperation = exports.WriteOperation || (exports.WriteOperation = {}));
|
package/core/clause.d.ts
CHANGED
|
@@ -1,61 +1,125 @@
|
|
|
1
|
-
|
|
1
|
+
import { Data, ID, SelectDataOptions } from "./base";
|
|
2
|
+
export interface Clause<T extends Data = Data, K = keyof T> {
|
|
2
3
|
clause(idx: number): string;
|
|
4
|
+
columns(): K[];
|
|
3
5
|
values(): any[];
|
|
4
6
|
instanceKey(): string;
|
|
5
7
|
logValues(): any[];
|
|
8
|
+
compositeOp?: string;
|
|
6
9
|
}
|
|
7
10
|
export interface SensitiveValue {
|
|
8
11
|
value(): any;
|
|
9
12
|
logValue(): any;
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
type InClauseOperator = "IN" | "NOT IN";
|
|
15
|
+
export declare class inClause<T extends Data, K = keyof T> implements Clause<T, K> {
|
|
16
|
+
private col;
|
|
13
17
|
private value;
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
private type;
|
|
19
|
+
protected op: InClauseOperator;
|
|
20
|
+
static getPostgresInClauseValuesThreshold(): number;
|
|
21
|
+
constructor(col: K, value: any[], type?: string);
|
|
17
22
|
clause(idx: number): string;
|
|
18
|
-
|
|
23
|
+
columns(): K[];
|
|
19
24
|
values(): any[];
|
|
20
25
|
logValues(): any[];
|
|
21
26
|
instanceKey(): string;
|
|
22
27
|
}
|
|
23
|
-
declare class
|
|
24
|
-
|
|
25
|
-
private sep;
|
|
26
|
-
constructor(clauses: Clause[], sep: string);
|
|
27
|
-
clause(idx: number): string;
|
|
28
|
-
values(): any[];
|
|
29
|
-
logValues(): any[];
|
|
30
|
-
instanceKey(): string;
|
|
28
|
+
export declare class notInClause<T extends Data, K = keyof T> extends inClause<T, K> {
|
|
29
|
+
protected op: InClauseOperator;
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export declare function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export declare function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
/**
|
|
32
|
+
* creates a clause to determine if the given value is contained in the array stored in the column in the db
|
|
33
|
+
* only works with postgres gin indexes
|
|
34
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
35
|
+
*/
|
|
36
|
+
export declare function PostgresArrayContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
37
|
+
/**
|
|
38
|
+
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
39
|
+
* only works with postgres gin indexes
|
|
40
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
41
|
+
*/
|
|
42
|
+
export declare function PostgresArrayContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
43
|
+
/**
|
|
44
|
+
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
45
|
+
* only works with postgres gin indexes
|
|
46
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
47
|
+
*/
|
|
48
|
+
export declare function PostgresArrayNotContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
49
|
+
/**
|
|
50
|
+
* creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
|
|
51
|
+
* only works with postgres gin indexes
|
|
52
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
53
|
+
*/
|
|
54
|
+
export declare function PostgresArrayNotContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
55
|
+
/**
|
|
56
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
57
|
+
* only works with postgres gin indexes
|
|
58
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
59
|
+
*/
|
|
60
|
+
export declare function PostgresArrayOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
61
|
+
/**
|
|
62
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
63
|
+
* only works with postgres gin indexes
|
|
64
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
65
|
+
*/
|
|
66
|
+
export declare function PostgresArrayNotOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated use PostgresArrayContainsValue
|
|
69
|
+
*/
|
|
70
|
+
export declare function ArrayEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated use PostgresNotArrayContains
|
|
73
|
+
*/
|
|
74
|
+
export declare function ArrayNotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
75
|
+
export declare function Eq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
76
|
+
export declare function NotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
77
|
+
export declare function Greater<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
78
|
+
export declare function Less<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
79
|
+
export declare function GreaterEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
80
|
+
export declare function LessEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
81
|
+
export declare function And<T extends Data, K = keyof T>(...args: Clause<T, K>[]): Clause<T, K>;
|
|
82
|
+
export declare function AndOptional<T extends Data, K = keyof T>(...args: (Clause<T, K> | undefined)[]): Clause<T, K>;
|
|
83
|
+
export declare function Or<T extends Data, K = keyof T>(...args: Clause<T, K>[]): Clause<T, K>;
|
|
84
|
+
export declare function OrOptional<T extends Data, K = keyof T>(...args: (Clause<T, K> | undefined)[]): Clause<T, K>;
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated use UUidIn, TextIn, IntegerIn, or TypeIn
|
|
87
|
+
*/
|
|
88
|
+
export declare function In<T extends Data, K = keyof T>(col: K, ...values: any): Clause<T, K>;
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated use UUidIn, TextIn, IntegerIn, or TypeIn
|
|
91
|
+
*/
|
|
92
|
+
export declare function In<T extends Data, K = keyof T>(col: K, values: any[], type?: string): Clause<T, K>;
|
|
93
|
+
export declare function UuidIn<T extends Data, K = keyof T>(col: K, values: ID[]): Clause<T, K>;
|
|
94
|
+
export declare function IntegerIn<T extends Data, K = keyof T>(col: K, values: number[]): Clause<T, K>;
|
|
95
|
+
export declare function TextIn<T extends Data, K = keyof T>(col: K, values: any[]): Clause<T, K>;
|
|
96
|
+
export declare function DBTypeIn<T extends Data, K = keyof T>(col: K, values: any[], typ: string): Clause<T, K>;
|
|
97
|
+
export declare function UuidNotIn<T extends Data, K = keyof T>(col: K, values: ID[]): Clause<T, K>;
|
|
98
|
+
export declare function IntegerNotIn<T extends Data, K = keyof T>(col: K, values: number[]): Clause<T, K>;
|
|
99
|
+
export declare function TextNotIn<T extends Data, K = keyof T>(col: K, values: any[]): Clause<T, K>;
|
|
100
|
+
export declare function DBTypeNotIn<T extends Data, K = keyof T>(col: K, values: any[], typ: string): Clause<T, K>;
|
|
48
101
|
interface TsQuery {
|
|
49
102
|
language: "english" | "french" | "german" | "simple";
|
|
50
103
|
value: string;
|
|
51
104
|
}
|
|
52
|
-
export declare function TsQuery(col:
|
|
53
|
-
export declare function PlainToTsQuery(col:
|
|
54
|
-
export declare function PhraseToTsQuery(col:
|
|
55
|
-
export declare function WebsearchToTsQuery(col:
|
|
56
|
-
export declare function TsVectorColTsQuery(col:
|
|
57
|
-
export declare function TsVectorPlainToTsQuery(col:
|
|
58
|
-
export declare function TsVectorPhraseToTsQuery(col:
|
|
59
|
-
export declare function TsVectorWebsearchToTsQuery(col:
|
|
105
|
+
export declare function TsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
106
|
+
export declare function PlainToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
107
|
+
export declare function PhraseToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
108
|
+
export declare function WebsearchToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
109
|
+
export declare function TsVectorColTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
110
|
+
export declare function TsVectorPlainToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
111
|
+
export declare function TsVectorPhraseToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
112
|
+
export declare function TsVectorWebsearchToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
60
113
|
export declare function sensitiveValue(val: any): SensitiveValue;
|
|
114
|
+
export declare function JSONObjectFieldKeyASJSON<T extends Data, K = keyof T>(col: K, field: string): keyof T;
|
|
115
|
+
export declare function JSONObjectFieldKeyAsText<T extends Data, K = keyof T>(col: K, field: string): keyof T;
|
|
116
|
+
type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
|
|
117
|
+
export declare function JSONPathValuePredicate<T extends Data, K = keyof T>(dbCol: K, path: string, val: any, pred: predicate): Clause<T, K>;
|
|
118
|
+
export declare function PaginationMultipleColsSubQuery<T extends Data, K = keyof T>(col: K, op: string, tableName: string, uniqueCol: K, val: any): Clause<T, K>;
|
|
119
|
+
export declare function Add<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
120
|
+
export declare function Subtract<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
121
|
+
export declare function Multiply<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
122
|
+
export declare function Divide<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
123
|
+
export declare function Modulo<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
124
|
+
export declare function getCombinedClause<V extends Data = Data, K = keyof V>(options: Omit<SelectDataOptions, "key">, cls: Clause<V, K>): Clause<V, K>;
|
|
61
125
|
export {};
|