@snowtop/ent 0.1.0-alpha116 → 0.1.0-alpha118
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/core/base.d.ts +3 -3
- package/core/clause.d.ts +43 -80
- package/core/clause.js +3 -1
- package/core/ent.d.ts +10 -10
- package/core/ent.js +5 -0
- package/core/loaders/object_loader.js +1 -0
- package/package.json +1 -1
package/core/base.d.ts
CHANGED
|
@@ -75,11 +75,11 @@ export interface SelectDataOptions extends SelectBaseDataOptions {
|
|
|
75
75
|
}
|
|
76
76
|
export interface QueryableDataOptions extends SelectBaseDataOptions, QueryDataOptions {
|
|
77
77
|
}
|
|
78
|
-
export interface QueryDataOptions {
|
|
78
|
+
export interface QueryDataOptions<T extends Data = Data, K = keyof T> {
|
|
79
79
|
distinct?: boolean;
|
|
80
|
-
clause: clause.Clause
|
|
80
|
+
clause: clause.Clause<T, K>;
|
|
81
81
|
orderby?: string;
|
|
82
|
-
groupby?:
|
|
82
|
+
groupby?: K;
|
|
83
83
|
limit?: number;
|
|
84
84
|
disableTransformations?: boolean;
|
|
85
85
|
}
|
package/core/clause.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { Data } from "./base";
|
|
2
|
+
export interface Clause<T extends Data = Data, K = keyof T> {
|
|
2
3
|
clause(idx: number): string;
|
|
3
|
-
columns():
|
|
4
|
+
columns(): K[];
|
|
4
5
|
values(): any[];
|
|
5
6
|
instanceKey(): string;
|
|
6
7
|
logValues(): any[];
|
|
@@ -10,38 +11,14 @@ export interface SensitiveValue {
|
|
|
10
11
|
value(): any;
|
|
11
12
|
logValue(): any;
|
|
12
13
|
}
|
|
13
|
-
declare class
|
|
14
|
-
protected col: string;
|
|
15
|
-
private value;
|
|
16
|
-
private op;
|
|
17
|
-
private handleNull?;
|
|
18
|
-
constructor(col: string, value: any, op: string, handleNull?: Clause | undefined);
|
|
19
|
-
clause(idx: number): string;
|
|
20
|
-
private nullClause;
|
|
21
|
-
columns(): string[];
|
|
22
|
-
values(): any[];
|
|
23
|
-
logValues(): any[];
|
|
24
|
-
instanceKey(): string;
|
|
25
|
-
}
|
|
26
|
-
export declare class inClause implements Clause {
|
|
14
|
+
export declare class inClause<T extends Data, K = keyof T> implements Clause<T, K> {
|
|
27
15
|
private col;
|
|
28
16
|
private value;
|
|
29
17
|
private type;
|
|
30
18
|
static getPostgresInClauseValuesThreshold(): number;
|
|
31
|
-
constructor(col:
|
|
19
|
+
constructor(col: K, value: any[], type?: string);
|
|
32
20
|
clause(idx: number): string;
|
|
33
|
-
columns():
|
|
34
|
-
values(): any[];
|
|
35
|
-
logValues(): any[];
|
|
36
|
-
instanceKey(): string;
|
|
37
|
-
}
|
|
38
|
-
declare class compositeClause implements Clause {
|
|
39
|
-
private clauses;
|
|
40
|
-
private sep;
|
|
41
|
-
compositeOp: string;
|
|
42
|
-
constructor(clauses: Clause[], sep: string);
|
|
43
|
-
clause(idx: number): string;
|
|
44
|
-
columns(): string[];
|
|
21
|
+
columns(): K[];
|
|
45
22
|
values(): any[];
|
|
46
23
|
logValues(): any[];
|
|
47
24
|
instanceKey(): string;
|
|
@@ -51,92 +28,78 @@ declare class compositeClause implements Clause {
|
|
|
51
28
|
* only works with postgres gin indexes
|
|
52
29
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
53
30
|
*/
|
|
54
|
-
export declare function PostgresArrayContainsValue(col:
|
|
31
|
+
export declare function PostgresArrayContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
55
32
|
/**
|
|
56
33
|
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
57
34
|
* only works with postgres gin indexes
|
|
58
35
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
59
36
|
*/
|
|
60
|
-
export declare function PostgresArrayContains(col:
|
|
37
|
+
export declare function PostgresArrayContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
61
38
|
/**
|
|
62
39
|
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
63
40
|
* only works with postgres gin indexes
|
|
64
41
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
65
42
|
*/
|
|
66
|
-
export declare function PostgresArrayNotContainsValue(col:
|
|
43
|
+
export declare function PostgresArrayNotContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
67
44
|
/**
|
|
68
45
|
* creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
|
|
69
46
|
* only works with postgres gin indexes
|
|
70
47
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
71
48
|
*/
|
|
72
|
-
export declare function PostgresArrayNotContains(col:
|
|
49
|
+
export declare function PostgresArrayNotContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
73
50
|
/**
|
|
74
51
|
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
75
52
|
* only works with postgres gin indexes
|
|
76
53
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
77
54
|
*/
|
|
78
|
-
export declare function PostgresArrayOverlaps(col:
|
|
55
|
+
export declare function PostgresArrayOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
79
56
|
/**
|
|
80
57
|
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
81
58
|
* only works with postgres gin indexes
|
|
82
59
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
83
60
|
*/
|
|
84
|
-
export declare function PostgresArrayNotOverlaps(col:
|
|
61
|
+
export declare function PostgresArrayNotOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
85
62
|
/**
|
|
86
63
|
* @deprecated use PostgresArrayContainsValue
|
|
87
64
|
*/
|
|
88
|
-
export declare function ArrayEq(col:
|
|
65
|
+
export declare function ArrayEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
89
66
|
/**
|
|
90
67
|
* @deprecated use PostgresNotArrayContains
|
|
91
68
|
*/
|
|
92
|
-
export declare function ArrayNotEq(col:
|
|
93
|
-
export declare function Eq(col:
|
|
94
|
-
export declare function NotEq(col:
|
|
95
|
-
export declare function Greater(col:
|
|
96
|
-
export declare function Less(col:
|
|
97
|
-
export declare function GreaterEq(col:
|
|
98
|
-
export declare function LessEq(col:
|
|
99
|
-
export declare function And(...args: Clause[]):
|
|
100
|
-
export declare function AndOptional(...args: (Clause | undefined)[]): Clause
|
|
101
|
-
export declare function Or(...args: Clause[]):
|
|
102
|
-
export declare function OrOptional(...args: (Clause | undefined)[]): Clause
|
|
103
|
-
export declare function In(col:
|
|
104
|
-
export declare function In(col:
|
|
69
|
+
export declare function ArrayNotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
70
|
+
export declare function Eq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
71
|
+
export declare function NotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
72
|
+
export declare function Greater<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
73
|
+
export declare function Less<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
74
|
+
export declare function GreaterEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
75
|
+
export declare function LessEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
76
|
+
export declare function And<T extends Data, K = keyof T>(...args: Clause<T, K>[]): Clause<T, K>;
|
|
77
|
+
export declare function AndOptional<T extends Data, K = keyof T>(...args: (Clause<T, K> | undefined)[]): Clause<T, K>;
|
|
78
|
+
export declare function Or<T extends Data, K = keyof T>(...args: Clause<T, K>[]): Clause<T, K>;
|
|
79
|
+
export declare function OrOptional<T extends Data, K = keyof T>(...args: (Clause<T, K> | undefined)[]): Clause<T, K>;
|
|
80
|
+
export declare function In<T extends Data, K = keyof T>(col: K, ...values: any): Clause<T, K>;
|
|
81
|
+
export declare function In<T extends Data, K = keyof T>(col: K, values: any[], type?: string): Clause<T, K>;
|
|
105
82
|
interface TsQuery {
|
|
106
83
|
language: "english" | "french" | "german" | "simple";
|
|
107
84
|
value: string;
|
|
108
85
|
}
|
|
109
|
-
export declare function TsQuery(col:
|
|
110
|
-
export declare function PlainToTsQuery(col:
|
|
111
|
-
export declare function PhraseToTsQuery(col:
|
|
112
|
-
export declare function WebsearchToTsQuery(col:
|
|
113
|
-
export declare function TsVectorColTsQuery(col:
|
|
114
|
-
export declare function TsVectorPlainToTsQuery(col:
|
|
115
|
-
export declare function TsVectorPhraseToTsQuery(col:
|
|
116
|
-
export declare function TsVectorWebsearchToTsQuery(col:
|
|
86
|
+
export declare function TsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
87
|
+
export declare function PlainToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
88
|
+
export declare function PhraseToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
89
|
+
export declare function WebsearchToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
90
|
+
export declare function TsVectorColTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
91
|
+
export declare function TsVectorPlainToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
92
|
+
export declare function TsVectorPhraseToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
93
|
+
export declare function TsVectorWebsearchToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
|
|
117
94
|
export declare function sensitiveValue(val: any): SensitiveValue;
|
|
118
|
-
export declare function JSONObjectFieldKeyASJSON(col:
|
|
119
|
-
export declare function JSONObjectFieldKeyAsText(col:
|
|
95
|
+
export declare function JSONObjectFieldKeyASJSON<T extends Data, K = keyof T>(col: K, field: string): keyof T;
|
|
96
|
+
export declare function JSONObjectFieldKeyAsText<T extends Data, K = keyof T>(col: K, field: string): keyof T;
|
|
120
97
|
type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
|
|
121
|
-
export declare function JSONPathValuePredicate(dbCol:
|
|
122
|
-
declare
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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;
|
|
137
|
-
export declare function Add(col: string, value: any): Clause;
|
|
138
|
-
export declare function Subtract(col: string, value: any): Clause;
|
|
139
|
-
export declare function Multiply(col: string, value: any): Clause;
|
|
140
|
-
export declare function Divide(col: string, value: any): Clause;
|
|
141
|
-
export declare function Modulo(col: string, value: any): Clause;
|
|
98
|
+
export declare function JSONPathValuePredicate<T extends Data, K = keyof T>(dbCol: K, path: string, val: any, pred: predicate): Clause<T, K>;
|
|
99
|
+
export declare function PaginationMultipleColsSubQuery<T extends Data, K = keyof T>(col: K, op: string, tableName: string, uniqueCol: K, val: any): Clause<T, K>;
|
|
100
|
+
export declare function Add<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
101
|
+
export declare function Subtract<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
102
|
+
export declare function Multiply<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
103
|
+
export declare function Divide<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
104
|
+
export declare function Modulo<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
142
105
|
export {};
|
package/core/clause.js
CHANGED
|
@@ -94,7 +94,7 @@ class isNullClause {
|
|
|
94
94
|
constructor(col) {
|
|
95
95
|
this.col = col;
|
|
96
96
|
}
|
|
97
|
-
clause(
|
|
97
|
+
clause(_idx) {
|
|
98
98
|
return `${this.col} IS NULL`;
|
|
99
99
|
}
|
|
100
100
|
columns() {
|
|
@@ -623,10 +623,12 @@ exports.sensitiveValue = sensitiveValue;
|
|
|
623
623
|
// see test in db_clause.test.ts
|
|
624
624
|
// unclear best time to use this...
|
|
625
625
|
function JSONObjectFieldKeyASJSON(col, field) {
|
|
626
|
+
// type as keyof T to make it easier to use in other queries
|
|
626
627
|
return `${col}->'${field}'`;
|
|
627
628
|
}
|
|
628
629
|
exports.JSONObjectFieldKeyASJSON = JSONObjectFieldKeyASJSON;
|
|
629
630
|
function JSONObjectFieldKeyAsText(col, field) {
|
|
631
|
+
// type as keyof T to make it easier to use in other queries
|
|
630
632
|
return `${col}->>'${field}'`;
|
|
631
633
|
}
|
|
632
634
|
exports.JSONObjectFieldKeyAsText = JSONObjectFieldKeyAsText;
|
package/core/ent.d.ts
CHANGED
|
@@ -24,13 +24,13 @@ export declare function loadEntsList<TEnt extends Ent<TViewer>, TViewer extends
|
|
|
24
24
|
* @deperecated use loadCustomEnts
|
|
25
25
|
*/
|
|
26
26
|
export declare function loadEntsFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, clause: clause.Clause, options: LoadEntOptions<TEnt, TViewer>): Promise<Map<ID, TEnt>>;
|
|
27
|
-
export declare function loadCustomEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadCustomEntOptions<TEnt, TViewer>, query: CustomQuery): Promise<TEnt[]>;
|
|
27
|
+
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[]>;
|
|
28
28
|
interface parameterizedQueryOptions {
|
|
29
29
|
query: string;
|
|
30
30
|
values?: any[];
|
|
31
31
|
logValues?: any[];
|
|
32
32
|
}
|
|
33
|
-
export type CustomQuery = string | parameterizedQueryOptions | clause.Clause | QueryDataOptions;
|
|
33
|
+
export type CustomQuery<T extends Data = Data, K = keyof T> = string | parameterizedQueryOptions | clause.Clause<T, K> | QueryDataOptions;
|
|
34
34
|
/**
|
|
35
35
|
* Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
|
|
36
36
|
* either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
|
|
@@ -55,10 +55,10 @@ export type CustomQuery = string | parameterizedQueryOptions | clause.Clause | Q
|
|
|
55
55
|
* disableTransformations: false
|
|
56
56
|
* }) // doesn't change the query
|
|
57
57
|
*/
|
|
58
|
-
export declare function loadCustomData(options: SelectCustomDataOptions, query: CustomQuery, context: Context | undefined): Promise<
|
|
58
|
+
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[]>;
|
|
59
59
|
interface CustomCountOptions extends DataOptions {
|
|
60
60
|
}
|
|
61
|
-
export declare function loadCustomCount(options: CustomCountOptions, query: CustomQuery, context: Context | undefined): Promise<number>;
|
|
61
|
+
export declare function loadCustomCount<T extends Data = Data, K = keyof T>(options: CustomCountOptions, query: CustomQuery<T, K>, context: Context | undefined): Promise<number>;
|
|
62
62
|
export declare function loadDerivedEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt | null>;
|
|
63
63
|
export declare function loadDerivedEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt>;
|
|
64
64
|
export declare function logQuery(query: string, logValues: any[]): void;
|
|
@@ -68,16 +68,16 @@ export declare function ___setLogQueryErrorWithError(val: boolean | undefined):
|
|
|
68
68
|
export declare function performRawQuery(query: string, values: any[], logValues?: any[]): Promise<Data[]>;
|
|
69
69
|
export declare function loadRows(options: LoadRowsOptions): Promise<Data[]>;
|
|
70
70
|
export declare function buildQuery(options: QueryableDataOptions): string;
|
|
71
|
-
interface GroupQueryOptions {
|
|
71
|
+
interface GroupQueryOptions<T extends Data, K = keyof T> {
|
|
72
72
|
tableName: string;
|
|
73
|
-
clause?: clause.Clause
|
|
74
|
-
groupColumn:
|
|
75
|
-
fields:
|
|
73
|
+
clause?: clause.Clause<T, K>;
|
|
74
|
+
groupColumn: K;
|
|
75
|
+
fields: K[];
|
|
76
76
|
values: any[];
|
|
77
77
|
orderby?: string;
|
|
78
78
|
limit: number;
|
|
79
79
|
}
|
|
80
|
-
export declare function buildGroupQuery(options: GroupQueryOptions): [string, clause.Clause];
|
|
80
|
+
export declare function buildGroupQuery<T extends Data = Data, K = keyof T>(options: GroupQueryOptions<T, K>): [string, clause.Clause<T, K>];
|
|
81
81
|
export interface DataOperation<T extends Ent = Ent> {
|
|
82
82
|
preFetch?(queryer: Queryer, context?: Context): Promise<void>;
|
|
83
83
|
performWriteSync(queryer: SyncQueryer, context?: Context): void;
|
|
@@ -217,7 +217,7 @@ interface loadCustomEdgesOptions<T extends AssocEdge> extends loadEdgesOptions {
|
|
|
217
217
|
export declare const DefaultLimit = 1000;
|
|
218
218
|
export declare function loadEdges(options: loadEdgesOptions): Promise<AssocEdge[]>;
|
|
219
219
|
export declare function getEdgeClauseAndFields(cls: clause.Clause, options: Pick<loadEdgesOptions, "disableTransformations">): {
|
|
220
|
-
cls: clause.Clause
|
|
220
|
+
cls: clause.Clause<Data, string | number>;
|
|
221
221
|
fields: string[];
|
|
222
222
|
};
|
|
223
223
|
export declare function loadCustomEdges<T extends AssocEdge>(options: loadCustomEdgesOptions<T>): Promise<T[]>;
|
package/core/ent.js
CHANGED
|
@@ -437,11 +437,13 @@ async function loadCustomDataImpl(options, query, context) {
|
|
|
437
437
|
if (!optClause) {
|
|
438
438
|
return cls;
|
|
439
439
|
}
|
|
440
|
+
// @ts-expect-error string|ID mismatch
|
|
440
441
|
return clause.And(cls, optClause);
|
|
441
442
|
}
|
|
442
443
|
if (typeof query === "string") {
|
|
443
444
|
// no caching, perform raw query
|
|
444
445
|
return performRawQuery(query, [], []);
|
|
446
|
+
// @ts-ignore
|
|
445
447
|
}
|
|
446
448
|
else if (isClause(query)) {
|
|
447
449
|
// if a Clause is passed in and we have a default clause
|
|
@@ -451,6 +453,7 @@ async function loadCustomDataImpl(options, query, context) {
|
|
|
451
453
|
// this will have rudimentary caching but nothing crazy
|
|
452
454
|
return loadRows({
|
|
453
455
|
...options,
|
|
456
|
+
// @ts-ignore
|
|
454
457
|
clause: getClause(query),
|
|
455
458
|
context: context,
|
|
456
459
|
});
|
|
@@ -462,6 +465,7 @@ async function loadCustomDataImpl(options, query, context) {
|
|
|
462
465
|
else {
|
|
463
466
|
let cls = query.clause;
|
|
464
467
|
if (!query.disableTransformations) {
|
|
468
|
+
// @ts-ignore
|
|
465
469
|
cls = getClause(cls);
|
|
466
470
|
}
|
|
467
471
|
// this will have rudimentary caching but nothing crazy
|
|
@@ -762,6 +766,7 @@ class EditNodeOperation {
|
|
|
762
766
|
optionClause = opts.clause;
|
|
763
767
|
}
|
|
764
768
|
if (optionClause) {
|
|
769
|
+
// @ts-expect-error ID|string mismatch
|
|
765
770
|
cls = clause.And(cls, optionClause);
|
|
766
771
|
}
|
|
767
772
|
}
|