@snowtop/ent 0.1.0-alpha99 → 0.1.0
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 +8 -1
- package/action/executor.d.ts +16 -3
- package/action/executor.js +83 -27
- package/action/index.d.ts +2 -1
- package/action/operations.d.ts +126 -0
- package/action/operations.js +686 -0
- package/action/orchestrator.d.ts +22 -8
- package/action/orchestrator.js +278 -67
- package/core/base.d.ts +34 -24
- package/core/clause.d.ts +62 -79
- package/core/clause.js +77 -5
- package/core/config.d.ts +5 -1
- package/core/config.js +3 -0
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +4 -3
- package/core/context.js +2 -1
- package/core/db.d.ts +1 -0
- package/core/db.js +7 -7
- package/core/ent.d.ts +53 -105
- package/core/ent.js +104 -599
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +4 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -3
- package/core/loaders/assoc_edge_loader.js +16 -7
- package/core/loaders/index.d.ts +0 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/loader.d.ts +3 -3
- package/core/loaders/loader.js +3 -20
- package/core/loaders/object_loader.d.ts +30 -10
- package/core/loaders/object_loader.js +179 -40
- package/core/loaders/query_loader.d.ts +4 -4
- package/core/loaders/query_loader.js +14 -19
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +3 -2
- package/core/privacy.d.ts +19 -10
- package/core/privacy.js +47 -26
- package/core/query/assoc_query.js +1 -1
- package/core/query/custom_clause_query.d.ts +6 -3
- package/core/query/custom_clause_query.js +36 -9
- package/core/query/custom_query.d.ts +3 -1
- package/core/query/custom_query.js +29 -6
- package/core/query/query.d.ts +12 -2
- package/core/query/query.js +67 -38
- package/core/query/shared_assoc_test.js +151 -10
- package/core/query/shared_test.d.ts +2 -2
- package/core/query/shared_test.js +90 -30
- 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 +2 -0
- package/graphql/graphql.d.ts +103 -19
- package/graphql/graphql.js +169 -134
- package/graphql/graphql_field_helpers.d.ts +9 -3
- package/graphql/graphql_field_helpers.js +22 -2
- package/graphql/index.d.ts +2 -1
- package/graphql/index.js +5 -2
- 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 +1 -1
- package/imports/index.js +2 -2
- package/index.d.ts +12 -1
- package/index.js +18 -6
- package/package.json +20 -17
- package/parse_schema/parse.d.ts +10 -4
- package/parse_schema/parse.js +70 -24
- package/schema/base_schema.d.ts +8 -0
- package/schema/base_schema.js +11 -0
- package/schema/field.d.ts +6 -3
- package/schema/field.js +72 -17
- package/schema/index.d.ts +1 -1
- package/schema/index.js +2 -1
- package/schema/json_field.d.ts +3 -3
- package/schema/json_field.js +4 -1
- package/schema/schema.d.ts +42 -5
- package/schema/schema.js +35 -41
- package/schema/struct_field.d.ts +8 -6
- package/schema/struct_field.js +67 -8
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +4 -4
- package/scripts/custom_graphql.js +105 -75
- package/scripts/move_types.js +4 -1
- package/scripts/read_schema.js +2 -2
- package/testutils/action/complex_schemas.d.ts +1 -1
- package/testutils/action/complex_schemas.js +10 -3
- package/testutils/builder.d.ts +3 -0
- package/testutils/builder.js +6 -0
- package/testutils/db/temp_db.d.ts +9 -1
- package/testutils/db/temp_db.js +82 -14
- package/testutils/db_mock.js +1 -3
- package/testutils/ent-graphql-tests/index.d.ts +1 -1
- package/testutils/ent-graphql-tests/index.js +30 -19
- package/testutils/fake_comms.js +1 -1
- package/testutils/fake_data/fake_contact.d.ts +1 -1
- package/testutils/fake_data/fake_tag.d.ts +1 -1
- package/testutils/fake_data/fake_user.d.ts +3 -3
- package/testutils/fake_data/fake_user.js +15 -4
- package/testutils/fake_data/tag_query.js +8 -3
- package/testutils/fake_data/test_helpers.d.ts +3 -2
- package/testutils/fake_data/test_helpers.js +4 -4
- package/testutils/fake_data/user_query.d.ts +5 -2
- package/testutils/fake_data/user_query.js +19 -2
- package/testutils/fake_log.js +1 -1
- package/tsc/ast.js +2 -1
- package/tsc/move_generated.js +2 -2
- package/tsc/transform.d.ts +2 -2
- package/tsc/transform.js +4 -3
- package/tsc/transform_ent.js +2 -1
- package/tsc/transform_schema.js +4 -3
- package/core/loaders/index_loader.d.ts +0 -14
- package/core/loaders/index_loader.js +0 -27
package/core/base.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
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
10
|
export interface LoaderWithLoadMany<T, V> extends Loader<T, V> {
|
|
@@ -18,14 +20,15 @@ interface LoaderFactoryWithLoaderMany<T, V> extends LoaderFactory<T, V> {
|
|
|
18
20
|
export interface ConfigurableLoaderFactory<T, V> extends LoaderFactory<T, V> {
|
|
19
21
|
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<T, V>;
|
|
20
22
|
}
|
|
21
|
-
export type EdgeQueryableDataOptions = Partial<Pick<QueryableDataOptions, "limit" | "orderby" | "clause">>;
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
25
28
|
}
|
|
26
29
|
interface cache {
|
|
27
|
-
getLoader<
|
|
28
|
-
getLoaderWithLoadMany<
|
|
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>;
|
|
29
32
|
getCachedRows(options: queryOptions): Data[] | null;
|
|
30
33
|
getCachedRow(options: queryOptions): Data | null;
|
|
31
34
|
primeCache(options: queryOptions, rows: Data[]): void;
|
|
@@ -36,7 +39,7 @@ interface queryOptions {
|
|
|
36
39
|
fields: string[];
|
|
37
40
|
tableName: string;
|
|
38
41
|
clause: clause.Clause;
|
|
39
|
-
orderby?:
|
|
42
|
+
orderby?: OrderBy;
|
|
40
43
|
}
|
|
41
44
|
export interface Context<TViewer extends Viewer = Viewer> {
|
|
42
45
|
getViewer(): TViewer;
|
|
@@ -71,15 +74,16 @@ export interface SelectBaseDataOptions extends DataOptions {
|
|
|
71
74
|
}
|
|
72
75
|
export interface SelectDataOptions extends SelectBaseDataOptions {
|
|
73
76
|
key: string;
|
|
77
|
+
keyType?: string;
|
|
74
78
|
clause?: clause.Clause | (() => clause.Clause | undefined);
|
|
75
79
|
}
|
|
76
80
|
export interface QueryableDataOptions extends SelectBaseDataOptions, QueryDataOptions {
|
|
77
81
|
}
|
|
78
|
-
export interface QueryDataOptions {
|
|
82
|
+
export interface QueryDataOptions<T extends Data = Data, K = keyof T> {
|
|
79
83
|
distinct?: boolean;
|
|
80
|
-
clause: clause.Clause
|
|
81
|
-
orderby?:
|
|
82
|
-
groupby?:
|
|
84
|
+
clause: clause.Clause<T, K>;
|
|
85
|
+
orderby?: OrderBy;
|
|
86
|
+
groupby?: K;
|
|
83
87
|
limit?: number;
|
|
84
88
|
disableTransformations?: boolean;
|
|
85
89
|
}
|
|
@@ -87,37 +91,43 @@ export interface LoadRowOptions extends QueryableDataOptions {
|
|
|
87
91
|
}
|
|
88
92
|
export interface LoadRowsOptions extends QueryableDataOptions {
|
|
89
93
|
}
|
|
94
|
+
interface OnConflictOptions {
|
|
95
|
+
onConflictCols: string[];
|
|
96
|
+
onConflictConstraint?: string;
|
|
97
|
+
updateCols?: string[];
|
|
98
|
+
}
|
|
90
99
|
export interface CreateRowOptions extends DataOptions {
|
|
91
100
|
fields: Data;
|
|
92
101
|
fieldsToLog?: Data;
|
|
102
|
+
onConflict?: OnConflictOptions;
|
|
93
103
|
}
|
|
94
|
-
export interface EditRowOptions extends CreateRowOptions {
|
|
104
|
+
export interface EditRowOptions extends Omit<CreateRowOptions, "onConflict"> {
|
|
95
105
|
whereClause: clause.Clause;
|
|
96
106
|
expressions?: Map<string, clause.Clause>;
|
|
97
107
|
}
|
|
98
|
-
interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> {
|
|
99
|
-
loaderFactory:
|
|
108
|
+
interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> {
|
|
109
|
+
loaderFactory: ObjectLoaderFactory<TData>;
|
|
100
110
|
ent: EntConstructor<TEnt, TViewer>;
|
|
101
111
|
}
|
|
102
|
-
export interface LoaderFactoryWithOptions extends LoaderFactoryWithLoaderMany<any,
|
|
112
|
+
export interface LoaderFactoryWithOptions<T extends Data = Data> extends LoaderFactoryWithLoaderMany<any, T | null> {
|
|
103
113
|
options?: SelectDataOptions;
|
|
104
114
|
}
|
|
105
|
-
export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends LoadableEntOptions<TEnt, TViewer>, SelectBaseDataOptions {
|
|
115
|
+
export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> extends LoadableEntOptions<TEnt, TViewer, TData>, SelectBaseDataOptions {
|
|
106
116
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
107
117
|
}
|
|
108
|
-
export interface SelectCustomDataOptions extends SelectBaseDataOptions {
|
|
109
|
-
loaderFactory:
|
|
118
|
+
export interface SelectCustomDataOptions<T extends Data = Data> extends SelectBaseDataOptions {
|
|
119
|
+
loaderFactory: ObjectLoaderFactory<T>;
|
|
110
120
|
prime?: boolean;
|
|
111
121
|
}
|
|
112
|
-
export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends SelectCustomDataOptions {
|
|
122
|
+
export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> extends SelectCustomDataOptions<TData> {
|
|
113
123
|
ent: EntConstructor<TEnt, TViewer>;
|
|
114
124
|
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
115
125
|
}
|
|
116
|
-
export interface LoaderInfo {
|
|
126
|
+
export interface LoaderInfo<T = Data> {
|
|
117
127
|
tableName: string;
|
|
118
128
|
fields: string[];
|
|
119
129
|
nodeType: string;
|
|
120
|
-
loaderFactory: LoaderFactory<
|
|
130
|
+
loaderFactory: LoaderFactory<ID, T | null>;
|
|
121
131
|
}
|
|
122
132
|
export interface EditEntOptions<T extends Ent> extends LoadableEntOptions<T>, EditRowOptions {
|
|
123
133
|
}
|
package/core/clause.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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;
|
|
3
|
-
columns():
|
|
4
|
+
columns(): K[];
|
|
4
5
|
values(): any[];
|
|
5
6
|
instanceKey(): string;
|
|
6
7
|
logValues(): any[];
|
|
@@ -10,133 +11,115 @@ export interface SensitiveValue {
|
|
|
10
11
|
value(): any;
|
|
11
12
|
logValue(): any;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
type InClauseOperator = "IN" | "NOT IN";
|
|
15
|
+
export declare class inClause<T extends Data, K = keyof T> implements Clause<T, K> {
|
|
27
16
|
private col;
|
|
28
17
|
private value;
|
|
29
18
|
private type;
|
|
19
|
+
protected op: InClauseOperator;
|
|
30
20
|
static getPostgresInClauseValuesThreshold(): number;
|
|
31
|
-
constructor(col:
|
|
21
|
+
constructor(col: K, value: any[], type?: string);
|
|
32
22
|
clause(idx: number): string;
|
|
33
|
-
columns():
|
|
23
|
+
columns(): K[];
|
|
34
24
|
values(): any[];
|
|
35
25
|
logValues(): any[];
|
|
36
26
|
instanceKey(): string;
|
|
37
27
|
}
|
|
38
|
-
declare class
|
|
39
|
-
|
|
40
|
-
private sep;
|
|
41
|
-
compositeOp: string;
|
|
42
|
-
constructor(clauses: Clause[], sep: string);
|
|
43
|
-
clause(idx: number): string;
|
|
44
|
-
columns(): string[];
|
|
45
|
-
values(): any[];
|
|
46
|
-
logValues(): any[];
|
|
47
|
-
instanceKey(): string;
|
|
28
|
+
export declare class notInClause<T extends Data, K = keyof T> extends inClause<T, K> {
|
|
29
|
+
protected op: InClauseOperator;
|
|
48
30
|
}
|
|
49
31
|
/**
|
|
50
32
|
* creates a clause to determine if the given value is contained in the array stored in the column in the db
|
|
51
33
|
* only works with postgres gin indexes
|
|
52
34
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
53
35
|
*/
|
|
54
|
-
export declare function PostgresArrayContainsValue(col:
|
|
36
|
+
export declare function PostgresArrayContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
55
37
|
/**
|
|
56
38
|
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
57
39
|
* only works with postgres gin indexes
|
|
58
40
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
59
41
|
*/
|
|
60
|
-
export declare function PostgresArrayContains(col:
|
|
42
|
+
export declare function PostgresArrayContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
61
43
|
/**
|
|
62
44
|
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
63
45
|
* only works with postgres gin indexes
|
|
64
46
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
65
47
|
*/
|
|
66
|
-
export declare function PostgresArrayNotContainsValue(col:
|
|
48
|
+
export declare function PostgresArrayNotContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
67
49
|
/**
|
|
68
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
|
|
69
51
|
* only works with postgres gin indexes
|
|
70
52
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
71
53
|
*/
|
|
72
|
-
export declare function PostgresArrayNotContains(col:
|
|
54
|
+
export declare function PostgresArrayNotContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
73
55
|
/**
|
|
74
56
|
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
75
57
|
* only works with postgres gin indexes
|
|
76
58
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
77
59
|
*/
|
|
78
|
-
export declare function PostgresArrayOverlaps(col:
|
|
60
|
+
export declare function PostgresArrayOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
79
61
|
/**
|
|
80
62
|
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
81
63
|
* only works with postgres gin indexes
|
|
82
64
|
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
83
65
|
*/
|
|
84
|
-
export declare function PostgresArrayNotOverlaps(col:
|
|
66
|
+
export declare function PostgresArrayNotOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
|
|
85
67
|
/**
|
|
86
68
|
* @deprecated use PostgresArrayContainsValue
|
|
87
69
|
*/
|
|
88
|
-
export declare function ArrayEq(col:
|
|
70
|
+
export declare function ArrayEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
|
|
89
71
|
/**
|
|
90
72
|
* @deprecated use PostgresNotArrayContains
|
|
91
73
|
*/
|
|
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
|
-
|
|
104
|
-
|
|
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>;
|
|
105
101
|
interface TsQuery {
|
|
106
102
|
language: "english" | "french" | "german" | "simple";
|
|
107
103
|
value: string;
|
|
108
104
|
}
|
|
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:
|
|
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>;
|
|
117
113
|
export declare function sensitiveValue(val: any): SensitiveValue;
|
|
118
|
-
export declare function JSONObjectFieldKeyASJSON(col:
|
|
119
|
-
export declare function JSONObjectFieldKeyAsText(col:
|
|
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;
|
|
120
116
|
type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
|
|
121
|
-
export declare function JSONPathValuePredicate(dbCol:
|
|
122
|
-
declare
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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;
|
|
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>;
|
|
142
125
|
export {};
|
package/core/clause.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = 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;
|
|
26
|
+
exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = 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.DBTypeNotIn = exports.TextNotIn = exports.IntegerNotIn = exports.UuidNotIn = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = 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.notInClause = exports.inClause = void 0;
|
|
27
27
|
const db_1 = __importStar(require("./db"));
|
|
28
28
|
function isSensitive(val) {
|
|
29
29
|
return (val !== null &&
|
|
@@ -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() {
|
|
@@ -236,11 +236,17 @@ class inClause {
|
|
|
236
236
|
this.col = col;
|
|
237
237
|
this.value = value;
|
|
238
238
|
this.type = type;
|
|
239
|
+
this.op = "IN";
|
|
239
240
|
}
|
|
240
241
|
clause(idx) {
|
|
241
242
|
// do a simple = when only one item
|
|
242
243
|
if (this.value.length === 1) {
|
|
243
|
-
|
|
244
|
+
if (this.op === "IN") {
|
|
245
|
+
return new simpleClause(this.col, this.value[0], "=").clause(idx);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
return new simpleClause(this.col, this.value[0], "!=").clause(idx);
|
|
249
|
+
}
|
|
244
250
|
}
|
|
245
251
|
const postgres = db_1.default.getDialect() === db_1.Dialect.Postgres;
|
|
246
252
|
const postgresValuesList = postgres &&
|
|
@@ -272,7 +278,7 @@ class inClause {
|
|
|
272
278
|
if (postgresValuesList) {
|
|
273
279
|
inValue = `VALUES${inValue}`;
|
|
274
280
|
}
|
|
275
|
-
return `${this.col}
|
|
281
|
+
return `${this.col} ${this.op} (${inValue})`;
|
|
276
282
|
// TODO we need to return idx at end to query builder...
|
|
277
283
|
// or anything that's doing a composite query so next clause knows where to start
|
|
278
284
|
// or change to a sqlx.Rebind format
|
|
@@ -296,10 +302,17 @@ class inClause {
|
|
|
296
302
|
return result;
|
|
297
303
|
}
|
|
298
304
|
instanceKey() {
|
|
299
|
-
return
|
|
305
|
+
return `${this.op.toLowerCase()}:${this.col}:${this.values().join(",")}`;
|
|
300
306
|
}
|
|
301
307
|
}
|
|
302
308
|
exports.inClause = inClause;
|
|
309
|
+
class notInClause extends inClause {
|
|
310
|
+
constructor() {
|
|
311
|
+
super(...arguments);
|
|
312
|
+
this.op = "NOT IN";
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
exports.notInClause = notInClause;
|
|
303
316
|
class compositeClause {
|
|
304
317
|
constructor(clauses, sep) {
|
|
305
318
|
this.clauses = clauses;
|
|
@@ -550,6 +563,46 @@ function In(...args) {
|
|
|
550
563
|
return new inClause(args[0], args.slice(1));
|
|
551
564
|
}
|
|
552
565
|
exports.In = In;
|
|
566
|
+
function UuidIn(col, values) {
|
|
567
|
+
return new inClause(col, values, "uuid");
|
|
568
|
+
}
|
|
569
|
+
exports.UuidIn = UuidIn;
|
|
570
|
+
function IntegerIn(col, values) {
|
|
571
|
+
return new inClause(col, values, "integer");
|
|
572
|
+
}
|
|
573
|
+
exports.IntegerIn = IntegerIn;
|
|
574
|
+
function TextIn(col, values) {
|
|
575
|
+
return new inClause(col, values, "text");
|
|
576
|
+
}
|
|
577
|
+
exports.TextIn = TextIn;
|
|
578
|
+
/*
|
|
579
|
+
* if not uuid or text, pass the db type that can be used to cast this query
|
|
580
|
+
* if we end up with a large list of ids
|
|
581
|
+
*/
|
|
582
|
+
function DBTypeIn(col, values, typ) {
|
|
583
|
+
return new inClause(col, values, typ);
|
|
584
|
+
}
|
|
585
|
+
exports.DBTypeIn = DBTypeIn;
|
|
586
|
+
function UuidNotIn(col, values) {
|
|
587
|
+
return new notInClause(col, values, "uuid");
|
|
588
|
+
}
|
|
589
|
+
exports.UuidNotIn = UuidNotIn;
|
|
590
|
+
function IntegerNotIn(col, values) {
|
|
591
|
+
return new notInClause(col, values, "integer");
|
|
592
|
+
}
|
|
593
|
+
exports.IntegerNotIn = IntegerNotIn;
|
|
594
|
+
function TextNotIn(col, values) {
|
|
595
|
+
return new notInClause(col, values, "text");
|
|
596
|
+
}
|
|
597
|
+
exports.TextNotIn = TextNotIn;
|
|
598
|
+
/*
|
|
599
|
+
* if not uuid or text, pass the db type that can be used to cast this query
|
|
600
|
+
* if we end up with a large list of ids
|
|
601
|
+
*/
|
|
602
|
+
function DBTypeNotIn(col, values, typ) {
|
|
603
|
+
return new notInClause(col, values, typ);
|
|
604
|
+
}
|
|
605
|
+
exports.DBTypeNotIn = DBTypeNotIn;
|
|
553
606
|
// if string defaults to english
|
|
554
607
|
// https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
|
|
555
608
|
// to_tsquery
|
|
@@ -623,10 +676,12 @@ exports.sensitiveValue = sensitiveValue;
|
|
|
623
676
|
// see test in db_clause.test.ts
|
|
624
677
|
// unclear best time to use this...
|
|
625
678
|
function JSONObjectFieldKeyASJSON(col, field) {
|
|
679
|
+
// type as keyof T to make it easier to use in other queries
|
|
626
680
|
return `${col}->'${field}'`;
|
|
627
681
|
}
|
|
628
682
|
exports.JSONObjectFieldKeyASJSON = JSONObjectFieldKeyASJSON;
|
|
629
683
|
function JSONObjectFieldKeyAsText(col, field) {
|
|
684
|
+
// type as keyof T to make it easier to use in other queries
|
|
630
685
|
return `${col}->>'${field}'`;
|
|
631
686
|
}
|
|
632
687
|
exports.JSONObjectFieldKeyAsText = JSONObjectFieldKeyAsText;
|
|
@@ -729,3 +784,20 @@ function Modulo(col, value) {
|
|
|
729
784
|
return new simpleClause(col, value, "%", new isNullClause(col));
|
|
730
785
|
}
|
|
731
786
|
exports.Modulo = Modulo;
|
|
787
|
+
function getCombinedClause(options, cls) {
|
|
788
|
+
if (options.clause) {
|
|
789
|
+
let optionClause;
|
|
790
|
+
if (typeof options.clause === "function") {
|
|
791
|
+
optionClause = options.clause();
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
optionClause = options.clause;
|
|
795
|
+
}
|
|
796
|
+
if (optionClause) {
|
|
797
|
+
// @ts-expect-error different types
|
|
798
|
+
cls = And(cls, optionClause);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return cls;
|
|
802
|
+
}
|
|
803
|
+
exports.getCombinedClause = getCombinedClause;
|
package/core/config.d.ts
CHANGED
|
@@ -18,8 +18,11 @@ export interface Config {
|
|
|
18
18
|
dbFile?: string;
|
|
19
19
|
db?: Database | DBDict;
|
|
20
20
|
log?: logType | logType[];
|
|
21
|
-
codegen?: CodegenConfig;
|
|
22
21
|
logQueryWithError?: boolean;
|
|
22
|
+
defaultConnectionLimit?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ConfigWithCodegen extends Config {
|
|
25
|
+
codegen?: CodegenConfig;
|
|
23
26
|
customGraphQLJSONPath?: string;
|
|
24
27
|
dynamicScriptCustomGraphQLJSONPath?: string;
|
|
25
28
|
globalSchemaPath?: string;
|
|
@@ -41,6 +44,7 @@ interface CodegenConfig {
|
|
|
41
44
|
templatizedViewer?: importedObject;
|
|
42
45
|
customAssocEdgePath?: importedObject;
|
|
43
46
|
globalImportPath?: string;
|
|
47
|
+
userOveriddenFiles?: string[];
|
|
44
48
|
}
|
|
45
49
|
interface PrettierConfig {
|
|
46
50
|
custom?: boolean;
|
package/core/config.js
CHANGED
|
@@ -62,6 +62,9 @@ function setConfig(cfg) {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
(0, ent_1.___setLogQueryErrorWithError)(cfg.logQueryWithError);
|
|
65
|
+
if (cfg.defaultConnectionLimit) {
|
|
66
|
+
(0, ent_1.setDefaultLimit)(cfg.defaultConnectionLimit);
|
|
67
|
+
}
|
|
65
68
|
}
|
|
66
69
|
function isBuffer(b) {
|
|
67
70
|
return b.write !== undefined;
|
package/core/const.d.ts
ADDED
package/core/const.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SCHEMA_PATH = exports.GRAPHQL_PATH = exports.PACKAGE = void 0;
|
|
4
|
+
exports.PACKAGE = "@snowtop/ent";
|
|
5
|
+
exports.GRAPHQL_PATH = "@snowtop/ent/graphql";
|
|
6
|
+
exports.SCHEMA_PATH = "@snowtop/ent/schema";
|
package/core/context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Viewer, Data, Loader, LoaderWithLoadMany } from "./base";
|
|
|
3
3
|
import { IncomingMessage, ServerResponse } from "http";
|
|
4
4
|
import * as clause from "./clause";
|
|
5
5
|
import { Context } from "./base";
|
|
6
|
+
import { OrderBy } from "./query_impl";
|
|
6
7
|
export interface RequestContext<TViewer extends Viewer = Viewer> extends Context<TViewer> {
|
|
7
8
|
authViewer(viewer: TViewer): Promise<void>;
|
|
8
9
|
logout(): Promise<void>;
|
|
@@ -12,8 +13,8 @@ export interface RequestContext<TViewer extends Viewer = Viewer> extends Context
|
|
|
12
13
|
export declare class ContextCache {
|
|
13
14
|
loaders: Map<string, Loader<any, any>>;
|
|
14
15
|
loaderWithLoadMany: Map<string, LoaderWithLoadMany<any, any>>;
|
|
15
|
-
getLoader<
|
|
16
|
-
getLoaderWithLoadMany<
|
|
16
|
+
getLoader<K, V>(name: string, create: () => Loader<K, V>): Loader<K, V>;
|
|
17
|
+
getLoaderWithLoadMany<K, V>(name: string, create: () => LoaderWithLoadMany<K, V>): LoaderWithLoadMany<K, V>;
|
|
17
18
|
private itemMap;
|
|
18
19
|
private listMap;
|
|
19
20
|
private getkey;
|
|
@@ -27,6 +28,6 @@ interface queryOptions {
|
|
|
27
28
|
fields: string[];
|
|
28
29
|
tableName: string;
|
|
29
30
|
clause: clause.Clause;
|
|
30
|
-
orderby?:
|
|
31
|
+
orderby?: OrderBy;
|
|
31
32
|
}
|
|
32
33
|
export {};
|
package/core/context.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ContextCache = void 0;
|
|
4
4
|
const logger_1 = require("./logger");
|
|
5
|
+
const query_impl_1 = require("./query_impl");
|
|
5
6
|
class ContextCache {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.loaders = new Map();
|
|
@@ -39,7 +40,7 @@ class ContextCache {
|
|
|
39
40
|
options.clause.instanceKey(),
|
|
40
41
|
];
|
|
41
42
|
if (options.orderby) {
|
|
42
|
-
parts.push(options.orderby);
|
|
43
|
+
parts.push((0, query_impl_1.getOrderByPhrase)(options.orderby));
|
|
43
44
|
}
|
|
44
45
|
return parts.join(",");
|
|
45
46
|
}
|
package/core/db.d.ts
CHANGED
package/core/db.js
CHANGED
|
@@ -46,9 +46,7 @@ function parseConnectionString(str, args) {
|
|
|
46
46
|
dialect: Dialect.SQLite,
|
|
47
47
|
config: {
|
|
48
48
|
connectionString: str,
|
|
49
|
-
|
|
50
|
-
// e.g. src/core/config.test.ts which tests this
|
|
51
|
-
// ...args?.db,
|
|
49
|
+
...args?.cfg,
|
|
52
50
|
},
|
|
53
51
|
filePath,
|
|
54
52
|
};
|
|
@@ -56,10 +54,8 @@ function parseConnectionString(str, args) {
|
|
|
56
54
|
return {
|
|
57
55
|
dialect: Dialect.Postgres,
|
|
58
56
|
config: {
|
|
57
|
+
...args?.cfg,
|
|
59
58
|
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,
|
|
63
59
|
},
|
|
64
60
|
};
|
|
65
61
|
}
|
|
@@ -143,7 +139,9 @@ class DB {
|
|
|
143
139
|
}
|
|
144
140
|
else {
|
|
145
141
|
let sqlite = require("better-sqlite3");
|
|
146
|
-
|
|
142
|
+
const dbb = sqlite(db.filePath || "");
|
|
143
|
+
dbb.pragma("journal_mode = WAL");
|
|
144
|
+
this.q = new Sqlite(dbb);
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
147
|
getConnection() {
|
|
@@ -242,6 +240,8 @@ class Sqlite {
|
|
|
242
240
|
r = this.db.prepare(query).get(this.convertValues(values));
|
|
243
241
|
}
|
|
244
242
|
else {
|
|
243
|
+
// TODO querySync() with no values seems to do the wrong thing...
|
|
244
|
+
// e.g. querySync('select count(*) as count from table') returns nonsense
|
|
245
245
|
r = this.db.prepare(query).run();
|
|
246
246
|
}
|
|
247
247
|
return {
|