@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha73
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 +28 -24
- package/action/executor.d.ts +4 -4
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +44 -16
- package/action/orchestrator.js +287 -73
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +35 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +69 -3
- package/core/clause.js +420 -5
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +2 -2
- package/core/context.js +2 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -4
- package/core/db.js +2 -0
- package/core/ent.d.ts +62 -27
- package/core/ent.js +272 -63
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +10 -5
- package/core/loaders/object_loader.js +58 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +25 -25
- package/core/privacy.js +5 -5
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +4 -0
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +30 -23
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +21 -1
- package/index.js +24 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +24 -5
- package/parse_schema/parse.js +90 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +34 -6
- package/schema/field.js +67 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/schema.d.ts +100 -2
- package/schema/schema.js +127 -5
- package/scripts/custom_graphql.js +127 -16
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +36 -22
- package/testutils/builder.js +110 -13
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
- package/testutils/db/{test_db.js → temp_db.js} +76 -19
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +26 -17
- package/testutils/fake_data/fake_contact.d.ts +5 -9
- package/testutils/fake_data/fake_contact.js +17 -21
- package/testutils/fake_data/fake_event.d.ts +5 -9
- package/testutils/fake_data/fake_event.js +24 -28
- package/testutils/fake_data/fake_user.d.ts +6 -10
- package/testutils/fake_data/fake_user.js +25 -29
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +6 -6
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +3 -3
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +379 -0
- package/scripts/transform_schema.js +0 -288
package/core/base.d.ts
CHANGED
|
@@ -30,27 +30,27 @@ interface queryOptions {
|
|
|
30
30
|
clause: clause.Clause;
|
|
31
31
|
orderby?: string;
|
|
32
32
|
}
|
|
33
|
-
export interface Context {
|
|
34
|
-
getViewer():
|
|
33
|
+
export interface Context<TViewer extends Viewer = Viewer> {
|
|
34
|
+
getViewer(): TViewer;
|
|
35
35
|
cache?: cache;
|
|
36
36
|
}
|
|
37
|
-
export interface Viewer {
|
|
38
|
-
viewerID:
|
|
39
|
-
viewer: () => Promise<
|
|
37
|
+
export interface Viewer<TEnt extends any = Ent<any> | null, TID extends any = ID | null> {
|
|
38
|
+
viewerID: TID;
|
|
39
|
+
viewer: () => Promise<TEnt>;
|
|
40
40
|
instanceKey: () => string;
|
|
41
|
-
context?: Context
|
|
41
|
+
context?: Context<any>;
|
|
42
42
|
}
|
|
43
|
-
export interface Ent {
|
|
43
|
+
export interface Ent<TViewer extends Viewer = Viewer> {
|
|
44
44
|
id: ID;
|
|
45
|
-
viewer:
|
|
46
|
-
|
|
45
|
+
viewer: TViewer;
|
|
46
|
+
getPrivacyPolicy(): PrivacyPolicy<this, TViewer>;
|
|
47
47
|
nodeType: string;
|
|
48
48
|
}
|
|
49
49
|
export declare type Data = {
|
|
50
50
|
[key: string]: any;
|
|
51
51
|
};
|
|
52
|
-
export interface EntConstructor<
|
|
53
|
-
new (viewer:
|
|
52
|
+
export interface EntConstructor<TEnt extends Ent, TViewer extends Viewer = Viewer> {
|
|
53
|
+
new (viewer: TViewer, data: Data): TEnt;
|
|
54
54
|
}
|
|
55
55
|
export declare type ID = string | number;
|
|
56
56
|
export interface DataOptions {
|
|
@@ -62,6 +62,7 @@ export interface SelectBaseDataOptions extends DataOptions {
|
|
|
62
62
|
}
|
|
63
63
|
export interface SelectDataOptions extends SelectBaseDataOptions {
|
|
64
64
|
key: string;
|
|
65
|
+
clause?: clause.Clause | (() => clause.Clause | undefined);
|
|
65
66
|
}
|
|
66
67
|
export interface QueryableDataOptions extends SelectBaseDataOptions, QueryDataOptions {
|
|
67
68
|
}
|
|
@@ -71,6 +72,7 @@ export interface QueryDataOptions {
|
|
|
71
72
|
orderby?: string;
|
|
72
73
|
groupby?: string;
|
|
73
74
|
limit?: number;
|
|
75
|
+
disableTransformations?: boolean;
|
|
74
76
|
}
|
|
75
77
|
export interface LoadRowOptions extends QueryableDataOptions {
|
|
76
78
|
}
|
|
@@ -81,16 +83,25 @@ export interface CreateRowOptions extends DataOptions {
|
|
|
81
83
|
fieldsToLog?: Data;
|
|
82
84
|
}
|
|
83
85
|
export interface EditRowOptions extends CreateRowOptions {
|
|
84
|
-
|
|
86
|
+
whereClause: clause.Clause;
|
|
85
87
|
}
|
|
86
|
-
interface LoadableEntOptions<
|
|
87
|
-
loaderFactory:
|
|
88
|
-
ent: EntConstructor<
|
|
88
|
+
interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> {
|
|
89
|
+
loaderFactory: LoaderFactoryWithOptions;
|
|
90
|
+
ent: EntConstructor<TEnt, TViewer>;
|
|
91
|
+
}
|
|
92
|
+
interface LoaderFactoryWithOptions extends LoaderFactory<any, Data | null> {
|
|
93
|
+
options?: SelectDataOptions;
|
|
94
|
+
}
|
|
95
|
+
export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends LoadableEntOptions<TEnt, TViewer>, SelectBaseDataOptions {
|
|
96
|
+
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
89
97
|
}
|
|
90
|
-
export interface
|
|
98
|
+
export interface SelectCustomDataOptions extends SelectBaseDataOptions {
|
|
99
|
+
clause?: clause.Clause;
|
|
100
|
+
loaderFactory?: LoaderFactoryWithOptions;
|
|
91
101
|
}
|
|
92
|
-
export interface LoadCustomEntOptions<
|
|
93
|
-
ent: EntConstructor<
|
|
102
|
+
export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends SelectCustomDataOptions {
|
|
103
|
+
ent: EntConstructor<TEnt, TViewer>;
|
|
104
|
+
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
94
105
|
}
|
|
95
106
|
export interface LoaderInfo {
|
|
96
107
|
tableName: string;
|
|
@@ -108,6 +119,7 @@ declare enum privacyResult {
|
|
|
108
119
|
export interface PrivacyResult {
|
|
109
120
|
result: privacyResult;
|
|
110
121
|
error?: PrivacyError;
|
|
122
|
+
getError?(policy: PrivacyPolicy, rule: PrivacyPolicyRule, ent?: Ent): PrivacyError;
|
|
111
123
|
}
|
|
112
124
|
export interface PrivacyError extends Error {
|
|
113
125
|
privacyPolicy: PrivacyPolicy<Ent>;
|
|
@@ -116,11 +128,11 @@ export interface PrivacyError extends Error {
|
|
|
116
128
|
export declare function Allow(): PrivacyResult;
|
|
117
129
|
export declare function Skip(): PrivacyResult;
|
|
118
130
|
export declare function Deny(): PrivacyResult;
|
|
119
|
-
export declare function DenyWithReason(e: PrivacyError): PrivacyResult;
|
|
120
|
-
export interface PrivacyPolicyRule<TEnt extends Ent = Ent> {
|
|
121
|
-
apply(v:
|
|
131
|
+
export declare function DenyWithReason(e: PrivacyError | string): PrivacyResult;
|
|
132
|
+
export interface PrivacyPolicyRule<TEnt extends Ent = Ent, TViewer = Viewer> {
|
|
133
|
+
apply(v: TViewer, ent?: TEnt): Promise<PrivacyResult>;
|
|
122
134
|
}
|
|
123
|
-
export interface PrivacyPolicy<TEnt extends Ent = Ent> {
|
|
124
|
-
rules: PrivacyPolicyRule<TEnt>[];
|
|
135
|
+
export interface PrivacyPolicy<TEnt extends Ent = Ent, TViewer = Viewer> {
|
|
136
|
+
rules: PrivacyPolicyRule<TEnt, TViewer>[];
|
|
125
137
|
}
|
|
126
138
|
export {};
|
package/core/base.js
CHANGED
|
@@ -30,7 +30,23 @@ function Deny() {
|
|
|
30
30
|
return deny;
|
|
31
31
|
}
|
|
32
32
|
exports.Deny = Deny;
|
|
33
|
+
class DenyWithReasonError extends Error {
|
|
34
|
+
constructor(privacyPolicy, rule, msg, ent) {
|
|
35
|
+
super(msg);
|
|
36
|
+
this.privacyPolicy = privacyPolicy;
|
|
37
|
+
this.privacyRule = rule;
|
|
38
|
+
this.ent = ent;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
33
41
|
function DenyWithReason(e) {
|
|
42
|
+
if (typeof e === "string") {
|
|
43
|
+
return {
|
|
44
|
+
result: privacyResult.Deny,
|
|
45
|
+
getError(policy, rule, ent) {
|
|
46
|
+
return new DenyWithReasonError(policy, rule, e, ent);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
34
50
|
return {
|
|
35
51
|
result: privacyResult.Deny,
|
|
36
52
|
error: e,
|
package/core/clause.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface Clause {
|
|
2
2
|
clause(idx: number): string;
|
|
3
|
+
columns(): string[];
|
|
3
4
|
values(): any[];
|
|
4
5
|
instanceKey(): string;
|
|
5
6
|
logValues(): any[];
|
|
@@ -12,8 +13,11 @@ declare class simpleClause implements Clause {
|
|
|
12
13
|
protected col: string;
|
|
13
14
|
private value;
|
|
14
15
|
private op;
|
|
15
|
-
|
|
16
|
+
private handleNull?;
|
|
17
|
+
constructor(col: string, value: any, op: string, handleNull?: Clause | undefined);
|
|
16
18
|
clause(idx: number): string;
|
|
19
|
+
private nullClause;
|
|
20
|
+
columns(): string[];
|
|
17
21
|
values(): any[];
|
|
18
22
|
logValues(): any[];
|
|
19
23
|
instanceKey(): string;
|
|
@@ -23,18 +27,80 @@ declare class compositeClause implements Clause {
|
|
|
23
27
|
private sep;
|
|
24
28
|
constructor(clauses: Clause[], sep: string);
|
|
25
29
|
clause(idx: number): string;
|
|
30
|
+
columns(): string[];
|
|
26
31
|
values(): any[];
|
|
27
32
|
logValues(): any[];
|
|
28
33
|
instanceKey(): string;
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
/**
|
|
36
|
+
* creates a clause to determine if the given value is contained in the array stored in the column in the db
|
|
37
|
+
* only works with postgres gin indexes
|
|
38
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
39
|
+
*/
|
|
40
|
+
export declare function PostgresArrayContainsValue(col: string, value: any): Clause;
|
|
41
|
+
/**
|
|
42
|
+
* creates a clause to determine if every item in the list is stored in the array stored in the column in the db
|
|
43
|
+
* only works with postgres gin indexes
|
|
44
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
45
|
+
*/
|
|
46
|
+
export declare function PostgresArrayContains(col: string, value: any[]): Clause;
|
|
47
|
+
/**
|
|
48
|
+
* creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
|
|
49
|
+
* only works with postgres gin indexes
|
|
50
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
51
|
+
*/
|
|
52
|
+
export declare function PostgresArrayNotContainsValue(col: string, value: any): Clause;
|
|
53
|
+
/**
|
|
54
|
+
* creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
|
|
55
|
+
* only works with postgres gin indexes
|
|
56
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
57
|
+
*/
|
|
58
|
+
export declare function PostgresArrayNotContains(col: string, value: any[]): Clause;
|
|
59
|
+
/**
|
|
60
|
+
* creates a clause to determine if the arrays overlap, that is, do they have any elements in common
|
|
61
|
+
* only works with postgres gin indexes
|
|
62
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
63
|
+
*/
|
|
64
|
+
export declare function PostgresArrayOverlaps(col: string, value: any[]): Clause;
|
|
65
|
+
/**
|
|
66
|
+
* creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
|
|
67
|
+
* only works with postgres gin indexes
|
|
68
|
+
* https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
|
|
69
|
+
*/
|
|
70
|
+
export declare function PostgresArrayNotOverlaps(col: string, value: any[]): Clause;
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated use PostgresArrayContainsValue
|
|
73
|
+
*/
|
|
74
|
+
export declare function ArrayEq(col: string, value: any): Clause;
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated use PostgresNotArrayContains
|
|
77
|
+
*/
|
|
78
|
+
export declare function ArrayNotEq(col: string, value: any): Clause;
|
|
79
|
+
export declare function Eq(col: string, value: any): Clause;
|
|
80
|
+
export declare function NotEq(col: string, value: any): Clause;
|
|
32
81
|
export declare function Greater(col: string, value: any): simpleClause;
|
|
33
82
|
export declare function Less(col: string, value: any): simpleClause;
|
|
34
83
|
export declare function GreaterEq(col: string, value: any): simpleClause;
|
|
35
84
|
export declare function LessEq(col: string, value: any): simpleClause;
|
|
36
85
|
export declare function And(...args: Clause[]): compositeClause;
|
|
86
|
+
export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
|
|
37
87
|
export declare function Or(...args: Clause[]): compositeClause;
|
|
38
88
|
export declare function In(col: string, ...values: any): Clause;
|
|
89
|
+
interface TsQuery {
|
|
90
|
+
language: "english" | "french" | "german" | "simple";
|
|
91
|
+
value: string;
|
|
92
|
+
}
|
|
93
|
+
export declare function TsQuery(col: string, val: string | TsQuery): Clause;
|
|
94
|
+
export declare function PlainToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
95
|
+
export declare function PhraseToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
96
|
+
export declare function WebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
97
|
+
export declare function TsVectorColTsQuery(col: string, val: string | TsQuery): Clause;
|
|
98
|
+
export declare function TsVectorPlainToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
99
|
+
export declare function TsVectorPhraseToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
100
|
+
export declare function TsVectorWebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
|
|
39
101
|
export declare function sensitiveValue(val: any): SensitiveValue;
|
|
102
|
+
export declare function JSONObjectFieldKeyASJSON(col: string, field: string): string;
|
|
103
|
+
export declare function JSONObjectFieldKeyAsText(col: string, field: string): string;
|
|
104
|
+
declare type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
|
|
105
|
+
export declare function JSONPathValuePredicate(dbCol: string, path: string, val: any, pred: predicate): Clause;
|
|
40
106
|
export {};
|