@snowtop/ent 0.1.0-alpha90 → 0.1.0-alpha91
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/orchestrator.js +5 -1
- package/core/clause.d.ts +15 -0
- package/core/clause.js +44 -2
- package/core/config.js +5 -1
- package/core/db.js +5 -1
- package/core/ent.js +7 -8
- package/core/loaders/assoc_count_loader.d.ts +1 -0
- package/core/loaders/assoc_count_loader.js +8 -1
- package/core/loaders/assoc_edge_loader.js +5 -1
- package/core/loaders/object_loader.js +5 -1
- package/core/loaders/query_loader.js +5 -1
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/privacy.d.ts +6 -6
- package/core/query/assoc_query.d.ts +1 -0
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +2 -0
- package/core/query/custom_clause_query.js +9 -3
- package/core/query/custom_query.d.ts +2 -2
- package/core/query/custom_query.js +29 -21
- package/core/query/query.d.ts +7 -3
- package/core/query/query.js +101 -60
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +24 -45
- package/core/query/shared_test.d.ts +5 -1
- package/core/query/shared_test.js +354 -301
- package/graphql/graphql.js +10 -6
- package/graphql/query/shared_edge_connection.js +1 -15
- package/imports/index.js +5 -1
- package/index.js +5 -1
- package/package.json +1 -1
- package/schema/field.js +11 -1
- package/schema/index.js +5 -1
- package/schema/schema.d.ts +1 -0
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +5 -1
- package/scripts/read_schema.js +5 -1
- package/testutils/db/temp_db.d.ts +6 -5
- package/testutils/db/temp_db.js +40 -28
- package/testutils/db_mock.js +3 -1
- package/testutils/ent-graphql-tests/index.js +8 -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 +2 -0
- package/testutils/fake_data/fake_tag.d.ts +35 -0
- package/testutils/fake_data/fake_tag.js +88 -0
- package/testutils/fake_data/fake_user.d.ts +2 -0
- 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 +8 -2
- package/testutils/fake_data/test_helpers.js +21 -7
- package/testutils/fake_data/user_query.d.ts +5 -0
- package/testutils/fake_data/user_query.js +28 -3
- package/testutils/test_edge_global_schema.js +5 -1
- package/testutils/write.js +5 -1
- package/tsc/ast.js +5 -1
- package/tsc/compilerOptions.js +5 -1
- package/tsc/move_generated.js +5 -1
- package/tsc/transform.js +5 -1
- package/tsc/transform_action.js +5 -1
- package/tsc/transform_schema.js +5 -1
package/action/orchestrator.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];
|
package/core/clause.d.ts
CHANGED
|
@@ -119,4 +119,19 @@ export declare function JSONObjectFieldKeyASJSON(col: string, field: string): st
|
|
|
119
119
|
export declare function JSONObjectFieldKeyAsText(col: string, field: string): string;
|
|
120
120
|
declare type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
|
|
121
121
|
export declare function JSONPathValuePredicate(dbCol: string, path: string, val: any, pred: predicate): Clause;
|
|
122
|
+
declare class paginationMultipleColumnsSubQueryClause implements Clause {
|
|
123
|
+
private col;
|
|
124
|
+
private op;
|
|
125
|
+
private tableName;
|
|
126
|
+
private uniqueCol;
|
|
127
|
+
private val;
|
|
128
|
+
constructor(col: string, op: string, tableName: string, uniqueCol: string, val: any);
|
|
129
|
+
private buildSimpleQuery;
|
|
130
|
+
clause(idx: number): string;
|
|
131
|
+
columns(): string[];
|
|
132
|
+
values(): any[];
|
|
133
|
+
logValues(): any[];
|
|
134
|
+
instanceKey(): string;
|
|
135
|
+
}
|
|
136
|
+
export declare function PaginationMultipleColsSubQuery(col: string, op: string, tableName: string, uniqueCol: string, val: any): paginationMultipleColumnsSubQueryClause;
|
|
122
137
|
export {};
|
package/core/clause.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];
|
|
@@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.inClause = void 0;
|
|
26
|
+
exports.PaginationMultipleColsSubQuery = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.inClause = void 0;
|
|
23
27
|
const db_1 = __importStar(require("./db"));
|
|
24
28
|
function isSensitive(val) {
|
|
25
29
|
return (val !== null &&
|
|
@@ -666,3 +670,41 @@ function JSONPathValuePredicate(dbCol, path, val, pred) {
|
|
|
666
670
|
return new jSONPathValuePredicateClause(dbCol, path, val, pred);
|
|
667
671
|
}
|
|
668
672
|
exports.JSONPathValuePredicate = JSONPathValuePredicate;
|
|
673
|
+
// TODO need a better name for this lol
|
|
674
|
+
// this assumes we're doing the same direction twice which isn't necessarily accurate in the future...
|
|
675
|
+
class paginationMultipleColumnsSubQueryClause {
|
|
676
|
+
constructor(col, op, tableName, uniqueCol, val) {
|
|
677
|
+
this.col = col;
|
|
678
|
+
this.op = op;
|
|
679
|
+
this.tableName = tableName;
|
|
680
|
+
this.uniqueCol = uniqueCol;
|
|
681
|
+
this.val = val;
|
|
682
|
+
}
|
|
683
|
+
buildSimpleQuery(clause, idx) {
|
|
684
|
+
return `SELECT ${this.col} FROM ${this.tableName} WHERE ${clause.clause(idx)}`;
|
|
685
|
+
}
|
|
686
|
+
clause(idx) {
|
|
687
|
+
const eq1 = this.buildSimpleQuery(Eq(this.uniqueCol, this.val), idx);
|
|
688
|
+
const eq2 = this.buildSimpleQuery(Eq(this.uniqueCol, this.val), idx + 1);
|
|
689
|
+
const op = new simpleClause(this.uniqueCol, this.val, this.op).clause(idx + 2);
|
|
690
|
+
// nest in () to make sure it's scoped correctly
|
|
691
|
+
return `(${this.col} ${this.op} (${eq1}) OR (${this.col} = (${eq2}) AND ${op}))`;
|
|
692
|
+
}
|
|
693
|
+
columns() {
|
|
694
|
+
return [this.col];
|
|
695
|
+
}
|
|
696
|
+
values() {
|
|
697
|
+
return [this.val, this.val, this.val];
|
|
698
|
+
}
|
|
699
|
+
logValues() {
|
|
700
|
+
const log = isSensitive(this.val) ? this.val.logValue() : this.val;
|
|
701
|
+
return [log, log, log];
|
|
702
|
+
}
|
|
703
|
+
instanceKey() {
|
|
704
|
+
return `${this.col}-${this.op}-${this.tableName}-${this.uniqueCol}-${this.val}`;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
function PaginationMultipleColsSubQuery(col, op, tableName, uniqueCol, val) {
|
|
708
|
+
return new paginationMultipleColumnsSubQueryClause(col, op, tableName, uniqueCol, val);
|
|
709
|
+
}
|
|
710
|
+
exports.PaginationMultipleColsSubQuery = PaginationMultipleColsSubQuery;
|
package/core/config.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
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];
|
package/core/ent.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];
|
|
@@ -1315,17 +1319,12 @@ class AssocEdge {
|
|
|
1315
1319
|
getCursor() {
|
|
1316
1320
|
return getCursor({
|
|
1317
1321
|
row: this,
|
|
1318
|
-
col: "
|
|
1319
|
-
conv: (t) => {
|
|
1320
|
-
if (typeof t === "string") {
|
|
1321
|
-
return Date.parse(t);
|
|
1322
|
-
}
|
|
1323
|
-
return t.getTime();
|
|
1324
|
-
},
|
|
1322
|
+
col: "id2",
|
|
1325
1323
|
});
|
|
1326
1324
|
}
|
|
1327
1325
|
}
|
|
1328
1326
|
exports.AssocEdge = AssocEdge;
|
|
1327
|
+
// TODO eventually update this for sortCol time unique keys
|
|
1329
1328
|
function getCursor(opts) {
|
|
1330
1329
|
const { row, col, conv } = opts;
|
|
1331
1330
|
// row: Data, col: string, conv?: (any) => any) {
|
|
@@ -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];
|
|
@@ -73,6 +77,9 @@ class AssocEdgeCountLoaderFactory {
|
|
|
73
77
|
this.edgeType = edgeType;
|
|
74
78
|
this.name = `assocEdgeLoader:count:${edgeType}`;
|
|
75
79
|
}
|
|
80
|
+
getEdgeType() {
|
|
81
|
+
return this.edgeType;
|
|
82
|
+
}
|
|
76
83
|
createLoader(context) {
|
|
77
84
|
return (0, loader_1.getLoader)(this, () => new AssocEdgeCountLoader(this.edgeType, context), context);
|
|
78
85
|
}
|
|
@@ -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];
|
|
@@ -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];
|
|
@@ -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];
|
|
@@ -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];
|
package/core/privacy.d.ts
CHANGED
|
@@ -6,22 +6,22 @@ export declare class EntPrivacyError extends Error implements PrivacyError {
|
|
|
6
6
|
constructor(privacyPolicy: PrivacyPolicy, rule: PrivacyPolicyRule, ent?: Ent);
|
|
7
7
|
}
|
|
8
8
|
export declare const AlwaysAllowRule: {
|
|
9
|
-
apply(_v: Viewer, _ent?: Ent
|
|
9
|
+
apply(_v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
10
10
|
};
|
|
11
11
|
export declare const AlwaysDenyRule: {
|
|
12
|
-
apply(_v: Viewer, _ent?: Ent
|
|
12
|
+
apply(_v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
13
13
|
};
|
|
14
14
|
export declare const DenyIfLoggedOutRule: {
|
|
15
|
-
apply(v: Viewer, _ent?: Ent
|
|
15
|
+
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
16
16
|
};
|
|
17
17
|
export declare const DenyIfLoggedInRule: {
|
|
18
|
-
apply(v: Viewer, _ent?: Ent
|
|
18
|
+
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
19
19
|
};
|
|
20
20
|
export declare const AllowIfHasIdentity: {
|
|
21
|
-
apply(v: Viewer, _ent?: Ent
|
|
21
|
+
apply(v: Viewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
22
22
|
};
|
|
23
23
|
export declare const AllowIfViewerRule: {
|
|
24
|
-
apply(v: Viewer, ent?: Ent
|
|
24
|
+
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
25
25
|
};
|
|
26
26
|
export declare class AllowIfViewerEqualsRule {
|
|
27
27
|
private id;
|
|
@@ -14,6 +14,7 @@ export declare abstract class AssocEdgeQueryBase<TSource extends Ent<TViewer>, T
|
|
|
14
14
|
constructor(viewer: TViewer, src: EdgeQuerySource<TSource, TDest, TViewer>, countLoaderFactory: AssocEdgeCountLoaderFactory, dataLoaderFactory: AssocEdgeLoaderFactory<TEdge>, options: LoadEntOptions<TDest, TViewer> | loaderOptionsFunc<TViewer>);
|
|
15
15
|
private isEdgeQuery;
|
|
16
16
|
abstract sourceEnt(id: ID): Promise<Ent | null>;
|
|
17
|
+
getTableName(): Promise<string>;
|
|
17
18
|
private getSingleID;
|
|
18
19
|
queryRawCount(): Promise<number>;
|
|
19
20
|
queryAllRawCount(): Promise<Map<ID, number>>;
|
|
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AssocEdgeQueryBase = void 0;
|
|
4
4
|
const ent_1 = require("../ent");
|
|
5
5
|
const query_1 = require("./query");
|
|
6
|
+
// would be nice to someday have an API for assoc asc
|
|
6
7
|
class AssocEdgeQueryBase extends query_1.BaseEdgeQuery {
|
|
7
8
|
constructor(viewer, src, countLoaderFactory, dataLoaderFactory,
|
|
8
9
|
// if function, it's a polymorphic edge and need to provide
|
|
9
10
|
// a function that goes from edgeType to LoadEntOptions
|
|
10
11
|
options) {
|
|
11
|
-
super(viewer, "time");
|
|
12
|
+
super(viewer, "time", "id2");
|
|
12
13
|
this.viewer = viewer;
|
|
13
14
|
this.src = src;
|
|
14
15
|
this.countLoaderFactory = countLoaderFactory;
|
|
@@ -21,6 +22,13 @@ class AssocEdgeQueryBase extends query_1.BaseEdgeQuery {
|
|
|
21
22
|
}
|
|
22
23
|
return false;
|
|
23
24
|
}
|
|
25
|
+
async getTableName() {
|
|
26
|
+
const edgeData = await (0, ent_1.loadEdgeData)(this.countLoaderFactory.getEdgeType());
|
|
27
|
+
if (!edgeData) {
|
|
28
|
+
throw new Error(`couldn't load edgeData`);
|
|
29
|
+
}
|
|
30
|
+
return edgeData.edgeTable;
|
|
31
|
+
}
|
|
24
32
|
async getSingleID() {
|
|
25
33
|
const infos = await this.genIDInfosToFetch();
|
|
26
34
|
if (infos.length !== 1) {
|
|
@@ -6,6 +6,7 @@ interface CustomClauseQueryOptions<TDest extends Ent<TViewer>, TViewer extends V
|
|
|
6
6
|
clause: Clause;
|
|
7
7
|
name: string;
|
|
8
8
|
sortColumn?: string;
|
|
9
|
+
sortColumnUnique?: boolean;
|
|
9
10
|
disableTransformations?: boolean;
|
|
10
11
|
}
|
|
11
12
|
export declare class CustomClauseQuery<TDest extends Ent<TViewer>, TViewer extends Viewer = Viewer> extends BaseEdgeQuery<any, TDest, Data> {
|
|
@@ -14,6 +15,7 @@ export declare class CustomClauseQuery<TDest extends Ent<TViewer>, TViewer exten
|
|
|
14
15
|
private clause;
|
|
15
16
|
constructor(viewer: TViewer, options: CustomClauseQueryOptions<TDest, TViewer>);
|
|
16
17
|
sourceEnt(_id: ID): Promise<null>;
|
|
18
|
+
getTableName(): string;
|
|
17
19
|
queryRawCount(): Promise<number>;
|
|
18
20
|
queryAllRawCount(): Promise<Map<ID, number>>;
|
|
19
21
|
protected loadRawIDs(_addID: (src: ID) => void): Promise<void>;
|
|
@@ -21,7 +21,11 @@ function getClause(opts) {
|
|
|
21
21
|
}
|
|
22
22
|
class CustomClauseQuery extends query_1.BaseEdgeQuery {
|
|
23
23
|
constructor(viewer, options) {
|
|
24
|
-
|
|
24
|
+
const sortCol = options.sortColumn || "id";
|
|
25
|
+
let unique = options.sortColumnUnique
|
|
26
|
+
? sortCol
|
|
27
|
+
: options.loadEntOptions.loaderFactory.options?.key || "id";
|
|
28
|
+
super(viewer, options.sortColumn || sortCol, unique);
|
|
25
29
|
this.viewer = viewer;
|
|
26
30
|
this.options = options;
|
|
27
31
|
this.clause = getClause(options);
|
|
@@ -29,6 +33,9 @@ class CustomClauseQuery extends query_1.BaseEdgeQuery {
|
|
|
29
33
|
async sourceEnt(_id) {
|
|
30
34
|
return null;
|
|
31
35
|
}
|
|
36
|
+
getTableName() {
|
|
37
|
+
return this.options.loadEntOptions.tableName;
|
|
38
|
+
}
|
|
32
39
|
async queryRawCount() {
|
|
33
40
|
const row = await (0, ent_1.loadRow)({
|
|
34
41
|
tableName: this.options.loadEntOptions.tableName,
|
|
@@ -51,12 +58,11 @@ class CustomClauseQuery extends query_1.BaseEdgeQuery {
|
|
|
51
58
|
if (!options.limit) {
|
|
52
59
|
options.limit = ent_1.DefaultLimit;
|
|
53
60
|
}
|
|
54
|
-
let sortCol = this.options.sortColumn || "created_at";
|
|
55
61
|
const rows = await (0, ent_1.loadRows)({
|
|
56
62
|
tableName: this.options.loadEntOptions.tableName,
|
|
57
63
|
fields: this.options.loadEntOptions.fields,
|
|
58
64
|
clause: (0, clause_1.AndOptional)(this.clause, options.clause),
|
|
59
|
-
orderby: (0, query_loader_1.getOrderBy)(
|
|
65
|
+
orderby: (0, query_loader_1.getOrderBy)(this.getSortCol(), options?.orderby),
|
|
60
66
|
limit: options?.limit || ent_1.DefaultLimit,
|
|
61
67
|
context: this.viewer.context,
|
|
62
68
|
});
|
|
@@ -15,6 +15,7 @@ export interface CustomEdgeQueryOptions<TSource extends Ent<TViewer>, TDest exte
|
|
|
15
15
|
clause?: Clause;
|
|
16
16
|
name: string;
|
|
17
17
|
sortColumn?: string;
|
|
18
|
+
sortColumnUnique?: boolean;
|
|
18
19
|
disableTransformations?: boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare abstract class CustomEdgeQueryBase<TSource extends Ent<TViewer>, TDest extends Ent<TViewer>, TViewer extends Viewer = Viewer> extends BaseEdgeQuery<TSource, TDest, Data> implements EdgeQuery<TSource, TDest, Data> {
|
|
@@ -23,15 +24,14 @@ export declare abstract class CustomEdgeQueryBase<TSource extends Ent<TViewer>,
|
|
|
23
24
|
private id;
|
|
24
25
|
private opts;
|
|
25
26
|
constructor(viewer: TViewer, options: CustomEdgeQueryOptionsDeprecated<TSource, TDest, TViewer> | CustomEdgeQueryOptions<TSource, TDest, TViewer>);
|
|
27
|
+
getTableName(): string;
|
|
26
28
|
abstract sourceEnt(id: ID): Promise<Ent | null>;
|
|
27
29
|
private idVisible;
|
|
28
|
-
private isDeprecatedOptions;
|
|
29
30
|
private getCountLoader;
|
|
30
31
|
private getQueryLoader;
|
|
31
32
|
queryRawCount(): Promise<number>;
|
|
32
33
|
queryAllRawCount(): Promise<Map<ID, number>>;
|
|
33
34
|
protected loadRawIDs(addID: (src: ID | TSource) => void): Promise<void>;
|
|
34
|
-
private getLoadEntOptions;
|
|
35
35
|
protected loadRawData(infos: IDInfo[], options: EdgeQueryableDataOptions): Promise<void>;
|
|
36
36
|
dataToID(edge: Data): ID;
|
|
37
37
|
protected loadEntsFromEdges(id: ID, rows: Data[]): Promise<TDest[]>;
|
|
@@ -45,20 +45,42 @@ function getQueryLoader(viewer, opts, options) {
|
|
|
45
45
|
toPrime: [loader],
|
|
46
46
|
}, options, viewer.context);
|
|
47
47
|
}
|
|
48
|
+
function isDeprecatedOptions(options) {
|
|
49
|
+
return (options
|
|
50
|
+
.countLoaderFactory !== undefined);
|
|
51
|
+
}
|
|
48
52
|
class CustomEdgeQueryBase extends query_1.BaseEdgeQuery {
|
|
49
53
|
constructor(viewer, options) {
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
let opts;
|
|
55
|
+
let defaultSort = "id";
|
|
56
|
+
let uniqueColIsSort = false;
|
|
57
|
+
if (isDeprecatedOptions(options)) {
|
|
58
|
+
opts = options.options;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
opts = options.loadEntOptions;
|
|
62
|
+
if (options.sortColumnUnique) {
|
|
63
|
+
uniqueColIsSort = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let uniqueCol = opts.loaderFactory.options?.key || "id";
|
|
67
|
+
if (uniqueColIsSort) {
|
|
68
|
+
uniqueCol = options.sortColumn || defaultSort;
|
|
69
|
+
}
|
|
70
|
+
options.sortColumn = options.sortColumn || defaultSort;
|
|
71
|
+
super(viewer, options.sortColumn, uniqueCol);
|
|
52
72
|
this.viewer = viewer;
|
|
53
73
|
this.options = options;
|
|
54
|
-
options.sortColumn = options.sortColumn || "created_at";
|
|
55
74
|
if (typeof options.src === "object") {
|
|
56
75
|
this.id = options.src.id;
|
|
57
76
|
}
|
|
58
77
|
else {
|
|
59
78
|
this.id = options.src;
|
|
60
79
|
}
|
|
61
|
-
this.opts =
|
|
80
|
+
this.opts = opts;
|
|
81
|
+
}
|
|
82
|
+
getTableName() {
|
|
83
|
+
return this.opts.tableName;
|
|
62
84
|
}
|
|
63
85
|
async idVisible() {
|
|
64
86
|
const ids = await this.genIDInfosToFetch();
|
|
@@ -67,18 +89,14 @@ class CustomEdgeQueryBase extends query_1.BaseEdgeQuery {
|
|
|
67
89
|
}
|
|
68
90
|
return !ids[0].invalidated;
|
|
69
91
|
}
|
|
70
|
-
isDeprecatedOptions(options) {
|
|
71
|
-
return (options
|
|
72
|
-
.countLoaderFactory !== undefined);
|
|
73
|
-
}
|
|
74
92
|
getCountLoader() {
|
|
75
|
-
if (
|
|
93
|
+
if (isDeprecatedOptions(this.options)) {
|
|
76
94
|
return this.options.countLoaderFactory.createLoader(this.viewer.context);
|
|
77
95
|
}
|
|
78
96
|
return getRawCountLoader(this.viewer, this.options);
|
|
79
97
|
}
|
|
80
98
|
getQueryLoader(options) {
|
|
81
|
-
if (
|
|
99
|
+
if (isDeprecatedOptions(this.options)) {
|
|
82
100
|
return this.options.dataLoaderFactory.createConfigurableLoader(options, this.viewer.context);
|
|
83
101
|
}
|
|
84
102
|
return getQueryLoader(this.viewer, this.options, options);
|
|
@@ -101,22 +119,12 @@ class CustomEdgeQueryBase extends query_1.BaseEdgeQuery {
|
|
|
101
119
|
async loadRawIDs(addID) {
|
|
102
120
|
addID(this.options.src);
|
|
103
121
|
}
|
|
104
|
-
getLoadEntOptions() {
|
|
105
|
-
let opts;
|
|
106
|
-
if (this.isDeprecatedOptions(this.options)) {
|
|
107
|
-
opts = this.options.options;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
opts = this.options.loadEntOptions;
|
|
111
|
-
}
|
|
112
|
-
return opts;
|
|
113
|
-
}
|
|
114
122
|
async loadRawData(infos, options) {
|
|
115
123
|
if (infos.length !== 1) {
|
|
116
124
|
throw new Error(`expected 1 info passed to loadRawData. ${infos.length} passed`);
|
|
117
125
|
}
|
|
118
126
|
if (!options.orderby) {
|
|
119
|
-
options.orderby = `${this.
|
|
127
|
+
options.orderby = `${this.getSortCol()} DESC`;
|
|
120
128
|
}
|
|
121
129
|
if (!options.limit) {
|
|
122
130
|
options.limit = ent_1.DefaultLimit;
|
package/core/query/query.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface EdgeQuery<TSource extends Ent, TDest extends Ent, TEdge extends
|
|
|
20
20
|
}
|
|
21
21
|
export interface EdgeQueryFilter<T extends Data> {
|
|
22
22
|
filter?(id: ID, edges: T[]): T[];
|
|
23
|
-
query?(options: EdgeQueryableDataOptions): EdgeQueryableDataOptions
|
|
23
|
+
query?(options: EdgeQueryableDataOptions): EdgeQueryableDataOptions | Promise<EdgeQueryableDataOptions>;
|
|
24
24
|
paginationInfo?(id: ID): PaginationInfo | undefined;
|
|
25
25
|
}
|
|
26
26
|
export interface PaginationInfo {
|
|
@@ -31,7 +31,6 @@ export interface PaginationInfo {
|
|
|
31
31
|
}
|
|
32
32
|
export declare abstract class BaseEdgeQuery<TSource extends Ent, TDest extends Ent, TEdge extends Data> implements EdgeQuery<TSource, TDest, TEdge> {
|
|
33
33
|
viewer: Viewer;
|
|
34
|
-
private sortCol;
|
|
35
34
|
private filters;
|
|
36
35
|
private queryDispatched;
|
|
37
36
|
protected edges: Map<ID, TEdge[]>;
|
|
@@ -40,7 +39,11 @@ export declare abstract class BaseEdgeQuery<TSource extends Ent, TDest extends E
|
|
|
40
39
|
protected genIDInfosToFetch: () => Promise<IDInfo[]>;
|
|
41
40
|
private idMap;
|
|
42
41
|
private idsToFetch;
|
|
43
|
-
|
|
42
|
+
private sortCol;
|
|
43
|
+
private cursorCol;
|
|
44
|
+
private defaultDirection?;
|
|
45
|
+
constructor(viewer: Viewer, sortCol: string, cursorCol: string);
|
|
46
|
+
protected getSortCol(): string;
|
|
44
47
|
getPrivacyPolicy(): PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
45
48
|
abstract sourceEnt(id: ID): Promise<Ent | null>;
|
|
46
49
|
first(n: number, after?: string): this;
|
|
@@ -64,6 +67,7 @@ export declare abstract class BaseEdgeQuery<TSource extends Ent, TDest extends E
|
|
|
64
67
|
protected abstract loadRawIDs(addID: (src: ID | TSource) => void): Promise<void>;
|
|
65
68
|
protected abstract loadRawData(infos: IDInfo[], options: EdgeQueryableDataOptions): Promise<void>;
|
|
66
69
|
private addID;
|
|
70
|
+
abstract getTableName(): string | Promise<string>;
|
|
67
71
|
protected genIDInfosToFetchImpl(): Promise<IDInfo[]>;
|
|
68
72
|
private loadEdges;
|
|
69
73
|
getCursor(row: TEdge): string;
|