@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha14
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 +27 -25
- package/action/executor.d.ts +3 -3
- package/action/experimental_action.d.ts +21 -20
- package/action/experimental_action.js +1 -1
- package/action/orchestrator.d.ts +23 -16
- package/action/orchestrator.js +31 -14
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +20 -20
- package/core/context.d.ts +2 -2
- package/core/ent.d.ts +13 -13
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/object_loader.d.ts +3 -3
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/privacy.d.ts +24 -24
- 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/viewer.d.ts +3 -3
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/package.json +1 -1
- package/schema/schema.d.ts +15 -5
- package/schema/schema.js +16 -4
- package/scripts/move_generated.d.ts +1 -0
- package/scripts/move_generated.js +142 -0
- package/scripts/transform_code.js +1 -2
- package/scripts/transform_schema.js +1 -3
- package/testutils/builder.d.ts +19 -13
- package/testutils/builder.js +43 -20
- package/testutils/fake_data/fake_contact.d.ts +1 -1
- package/testutils/fake_data/fake_contact.js +2 -1
- package/testutils/fake_data/fake_event.d.ts +1 -1
- package/testutils/fake_data/fake_event.js +2 -1
- package/testutils/fake_data/fake_user.d.ts +2 -2
- package/testutils/fake_data/fake_user.js +2 -1
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/tsc/ast.d.ts +1 -0
- package/tsc/ast.js +24 -1
- package/tsc/compilerOptions.d.ts +2 -1
- package/tsc/compilerOptions.js +6 -1
|
@@ -9,9 +9,9 @@ interface QueryCountOptions {
|
|
|
9
9
|
export declare function createCountDataLoader<K extends any>(options: QueryCountOptions): DataLoader<K, number, K>;
|
|
10
10
|
export declare class RawCountLoader<K extends any> implements Loader<K, number> {
|
|
11
11
|
private options;
|
|
12
|
-
context?: Context | undefined;
|
|
12
|
+
context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined;
|
|
13
13
|
private loader;
|
|
14
|
-
constructor(options: QueryCountOptions, context?: Context | undefined);
|
|
14
|
+
constructor(options: QueryCountOptions, context?: Context<import("../base").Viewer<import("../base").Ent<any> | null, ID | null>> | undefined);
|
|
15
15
|
load(id: K): Promise<number>;
|
|
16
16
|
clearAll(): void;
|
|
17
17
|
}
|
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 | undefined): Promise<PrivacyResult>;
|
|
9
|
+
apply(_v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
10
10
|
};
|
|
11
11
|
export declare const AlwaysDenyRule: {
|
|
12
|
-
apply(_v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
12
|
+
apply(_v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
13
13
|
};
|
|
14
14
|
export declare const DenyIfLoggedOutRule: {
|
|
15
|
-
apply(v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
15
|
+
apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
16
16
|
};
|
|
17
17
|
export declare const DenyIfLoggedInRule: {
|
|
18
|
-
apply(v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
18
|
+
apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
19
19
|
};
|
|
20
20
|
export declare const AllowIfHasIdentity: {
|
|
21
|
-
apply(v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
21
|
+
apply(v: Viewer, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
22
22
|
};
|
|
23
23
|
export declare const AllowIfViewerRule: {
|
|
24
|
-
apply(v: Viewer, ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
24
|
+
apply(v: Viewer, ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
25
25
|
};
|
|
26
26
|
export declare class AllowIfViewerEqualsRule {
|
|
27
27
|
private id;
|
|
@@ -71,45 +71,45 @@ export declare class DenyIfEntPropertyIsRule<T extends Ent> implements PrivacyPo
|
|
|
71
71
|
constructor(property: keyof T, val: any);
|
|
72
72
|
apply(v: Viewer, ent?: T): Promise<PrivacyResult>;
|
|
73
73
|
}
|
|
74
|
-
export declare class AllowIfEntIsVisibleRule<
|
|
74
|
+
export declare class AllowIfEntIsVisibleRule<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicyRule {
|
|
75
75
|
private id;
|
|
76
76
|
private options;
|
|
77
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
78
|
-
apply(v:
|
|
77
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
78
|
+
apply(v: TViewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
79
79
|
}
|
|
80
|
-
export declare class AllowIfEntIsNotVisibleRule<
|
|
80
|
+
export declare class AllowIfEntIsNotVisibleRule<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicyRule {
|
|
81
81
|
private id;
|
|
82
82
|
private options;
|
|
83
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
84
|
-
apply(v:
|
|
83
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
84
|
+
apply(v: TViewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
85
85
|
}
|
|
86
|
-
export declare class AllowIfEntIsVisiblePolicy<
|
|
86
|
+
export declare class AllowIfEntIsVisiblePolicy<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicy<TEnt, TViewer> {
|
|
87
87
|
private id;
|
|
88
88
|
private options;
|
|
89
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
89
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
90
90
|
rules: {
|
|
91
|
-
apply(_v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
91
|
+
apply(_v: Viewer<Ent<any> | null, ID | null>, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
92
92
|
}[];
|
|
93
93
|
}
|
|
94
|
-
export declare class DenyIfEntIsVisiblePolicy<
|
|
94
|
+
export declare class DenyIfEntIsVisiblePolicy<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicy<TEnt, TViewer> {
|
|
95
95
|
private id;
|
|
96
96
|
private options;
|
|
97
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
97
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
98
98
|
rules: {
|
|
99
|
-
apply(_v: Viewer, _ent?: Ent | undefined): Promise<PrivacyResult>;
|
|
99
|
+
apply(_v: Viewer<Ent<any> | null, ID | null>, _ent?: Ent<Viewer<Ent<any> | null, ID | null>> | undefined): Promise<PrivacyResult>;
|
|
100
100
|
}[];
|
|
101
101
|
}
|
|
102
|
-
export declare class DenyIfEntIsVisibleRule<
|
|
102
|
+
export declare class DenyIfEntIsVisibleRule<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicyRule<TEnt, TViewer> {
|
|
103
103
|
private id;
|
|
104
104
|
private options;
|
|
105
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
106
|
-
apply(v:
|
|
105
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
106
|
+
apply(v: TViewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
107
107
|
}
|
|
108
|
-
export declare class DenyIfEntIsNotVisibleRule<
|
|
108
|
+
export declare class DenyIfEntIsNotVisibleRule<TEnt extends Ent<TViewer>, TViewer extends Viewer> implements PrivacyPolicyRule {
|
|
109
109
|
private id;
|
|
110
110
|
private options;
|
|
111
|
-
constructor(id: ID, options: LoadEntOptions<
|
|
112
|
-
apply(v:
|
|
111
|
+
constructor(id: ID, options: LoadEntOptions<TEnt, TViewer>);
|
|
112
|
+
apply(v: TViewer, _ent?: Ent): Promise<PrivacyResult>;
|
|
113
113
|
}
|
|
114
114
|
export declare class AllowIfEdgeExistsRule implements PrivacyPolicyRule {
|
|
115
115
|
private id1;
|
|
@@ -3,15 +3,15 @@ import { AssocEdge } from "../ent";
|
|
|
3
3
|
import { AssocEdgeCountLoaderFactory } from "../loaders/assoc_count_loader";
|
|
4
4
|
import { AssocEdgeLoaderFactory } from "../loaders/assoc_edge_loader";
|
|
5
5
|
import { EdgeQuery, BaseEdgeQuery, IDInfo } from "./query";
|
|
6
|
-
export declare type EdgeQuerySource<TSource extends Ent
|
|
7
|
-
declare type loaderOptionsFunc = (type: string) => LoadEntOptions<Ent>;
|
|
8
|
-
export declare abstract class AssocEdgeQueryBase<TSource extends Ent
|
|
9
|
-
viewer:
|
|
10
|
-
src: EdgeQuerySource<TSource, TDest>;
|
|
6
|
+
export declare type EdgeQuerySource<TSource extends Ent<TViewer>, TDest extends Ent<TViewer> = Ent<any>, TViewer extends Viewer = Viewer> = TSource | TSource[] | ID | ID[] | EdgeQuery<TDest, Ent, AssocEdge>;
|
|
7
|
+
declare type loaderOptionsFunc<TViewer extends Viewer> = (type: string) => LoadEntOptions<Ent, TViewer>;
|
|
8
|
+
export declare abstract class AssocEdgeQueryBase<TSource extends Ent<TViewer>, TDest extends Ent<TViewer>, TEdge extends AssocEdge, TViewer extends Viewer = Viewer> extends BaseEdgeQuery<TSource, TDest, TEdge> implements EdgeQuery<TSource, TDest, TEdge> {
|
|
9
|
+
viewer: TViewer;
|
|
10
|
+
src: EdgeQuerySource<TSource, TDest, TViewer>;
|
|
11
11
|
private countLoaderFactory;
|
|
12
12
|
private dataLoaderFactory;
|
|
13
13
|
private options;
|
|
14
|
-
constructor(viewer:
|
|
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
17
|
private getSingleID;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Data, Ent, ID, EdgeQueryableDataOptions, LoadEntOptions, Viewer, LoaderFactory, ConfigurableLoaderFactory } from "../base";
|
|
2
2
|
import { BaseEdgeQuery, IDInfo, EdgeQuery } from "./query";
|
|
3
|
-
export interface CustomEdgeQueryOptions<TSource extends Ent
|
|
3
|
+
export interface CustomEdgeQueryOptions<TSource extends Ent<TViewer>, TDest extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
4
4
|
src: TSource | ID;
|
|
5
5
|
countLoaderFactory: LoaderFactory<ID, number>;
|
|
6
6
|
dataLoaderFactory: ConfigurableLoaderFactory<ID, Data[]>;
|
|
7
|
-
options: LoadEntOptions<TDest>;
|
|
7
|
+
options: LoadEntOptions<TDest, TViewer>;
|
|
8
8
|
sortColumn?: string;
|
|
9
9
|
}
|
|
10
|
-
export declare abstract class CustomEdgeQueryBase<TSource extends Ent
|
|
11
|
-
viewer:
|
|
10
|
+
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> {
|
|
11
|
+
viewer: TViewer;
|
|
12
12
|
private options;
|
|
13
13
|
private id;
|
|
14
|
-
constructor(viewer:
|
|
14
|
+
constructor(viewer: TViewer, options: CustomEdgeQueryOptions<TSource, TDest, TViewer>);
|
|
15
15
|
abstract sourceEnt(id: ID): Promise<Ent | null>;
|
|
16
16
|
private idVisible;
|
|
17
17
|
queryRawCount(): Promise<number>;
|
package/core/query/query.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare abstract class BaseEdgeQuery<TSource extends Ent, TDest extends E
|
|
|
41
41
|
private idMap;
|
|
42
42
|
private idsToFetch;
|
|
43
43
|
constructor(viewer: Viewer, sortCol: string);
|
|
44
|
-
getPrivacyPolicy(): PrivacyPolicy<Ent
|
|
44
|
+
getPrivacyPolicy(): PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
45
45
|
abstract sourceEnt(id: ID): Promise<Ent | null>;
|
|
46
46
|
first(n: number, after?: string): this;
|
|
47
47
|
last(n: number, before?: string): this;
|
package/core/viewer.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ID, Ent, Viewer, Context } from "./base";
|
|
2
2
|
export declare class LoggedOutViewer implements Viewer {
|
|
3
|
-
context?: Context | undefined;
|
|
4
|
-
constructor(context?: Context | undefined);
|
|
3
|
+
context?: Context<Viewer<Ent<any> | null, ID | null>> | undefined;
|
|
4
|
+
constructor(context?: Context<Viewer<Ent<any> | null, ID | null>> | undefined);
|
|
5
5
|
viewerID: null;
|
|
6
6
|
viewer(): Promise<null>;
|
|
7
7
|
instanceKey(): string;
|
|
@@ -18,6 +18,6 @@ export declare class IDViewer implements Viewer {
|
|
|
18
18
|
constructor(viewerID: ID, opts?: Partial<IDViewerOptions>);
|
|
19
19
|
constructor(opts: IDViewerOptions);
|
|
20
20
|
setContext(ctx: Context): this;
|
|
21
|
-
viewer(): Promise<Ent | null>;
|
|
21
|
+
viewer(): Promise<Ent<Viewer<Ent<any> | null, ID | null>> | null>;
|
|
22
22
|
instanceKey(): string;
|
|
23
23
|
}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { EdgeQuery, PaginationInfo } from "../../core/query/query";
|
|
2
|
-
import { Data, Ent, Viewer } from "../../core/base";
|
|
2
|
+
import { Data, Ent, ID, Viewer } from "../../core/base";
|
|
3
3
|
export interface GraphQLEdge<T extends Data> {
|
|
4
4
|
edge: T;
|
|
5
5
|
node: Ent;
|
|
6
6
|
cursor: string;
|
|
7
7
|
}
|
|
8
|
-
interface edgeQueryCtr<T extends Ent, TEdge extends Data> {
|
|
9
|
-
(v:
|
|
8
|
+
interface edgeQueryCtr<T extends Ent, TEdge extends Data, TViewer extends Viewer> {
|
|
9
|
+
(v: TViewer, src: T): EdgeQuery<T, Ent, TEdge>;
|
|
10
10
|
}
|
|
11
|
-
interface edgeQueryCtr2<T extends Ent, TEdge extends Data> {
|
|
12
|
-
(v:
|
|
11
|
+
interface edgeQueryCtr2<T extends Ent, TEdge extends Data, TViewer extends Viewer> {
|
|
12
|
+
(v: TViewer): EdgeQuery<T, Ent, TEdge>;
|
|
13
13
|
}
|
|
14
|
-
export declare class GraphQLEdgeConnection<TSource extends Ent, TEdge extends Data> {
|
|
14
|
+
export declare class GraphQLEdgeConnection<TSource extends Ent, TEdge extends Data, TViewer extends Viewer = Viewer> {
|
|
15
15
|
query: EdgeQuery<TSource, Ent, TEdge>;
|
|
16
16
|
private results;
|
|
17
17
|
private viewer;
|
|
18
18
|
private source?;
|
|
19
19
|
private args?;
|
|
20
|
-
constructor(viewer:
|
|
21
|
-
constructor(viewer:
|
|
20
|
+
constructor(viewer: TViewer, source: TSource, getQuery: edgeQueryCtr<TSource, TEdge, TViewer>, args?: Data);
|
|
21
|
+
constructor(viewer: TViewer, getQuery: edgeQueryCtr2<TSource, TEdge, TViewer>, args?: Data);
|
|
22
22
|
first(limit: number, cursor?: string): void;
|
|
23
23
|
last(limit: number, cursor?: string): void;
|
|
24
24
|
modifyQuery(fn: (query: EdgeQuery<TSource, Ent, TEdge>) => EdgeQuery<TSource, Ent, TEdge>): void;
|
|
25
25
|
queryTotalCount(): Promise<number>;
|
|
26
26
|
queryEdges(): Promise<GraphQLEdge<TEdge>[]>;
|
|
27
|
-
queryNodes(): Promise<Ent[]>;
|
|
27
|
+
queryNodes(): Promise<Ent<Viewer<Ent<any> | null, ID | null>>[]>;
|
|
28
28
|
private defaultPageInfo;
|
|
29
29
|
queryPageInfo(): Promise<PaginationInfo>;
|
|
30
30
|
private queryData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GraphQLObjectType } from "graphql";
|
|
2
2
|
import { RequestContext } from "../../core/context";
|
|
3
3
|
import { PaginationInfo } from "../../core/query/query";
|
|
4
|
-
export declare const GraphQLPageInfo: GraphQLObjectType<PaginationInfo, RequestContext
|
|
4
|
+
export declare const GraphQLPageInfo: GraphQLObjectType<PaginationInfo, RequestContext<import("../..").Viewer<import("../..").Ent<any> | null, import("../..").ID | null>>>;
|
package/package.json
CHANGED
package/schema/schema.d.ts
CHANGED
|
@@ -4,6 +4,13 @@ import { Clause } from "../core/clause";
|
|
|
4
4
|
export declare type FieldMap = {
|
|
5
5
|
[key: string]: Field;
|
|
6
6
|
};
|
|
7
|
+
interface FieldInfo {
|
|
8
|
+
dbCol: string;
|
|
9
|
+
inputKey: string;
|
|
10
|
+
}
|
|
11
|
+
export declare type FieldInfoMap = {
|
|
12
|
+
[key: string]: FieldInfo;
|
|
13
|
+
};
|
|
7
14
|
export default interface Schema {
|
|
8
15
|
fields: FieldMap | Field[];
|
|
9
16
|
tableName?: string;
|
|
@@ -64,7 +71,7 @@ export interface Pattern {
|
|
|
64
71
|
fields: FieldMap | Field[];
|
|
65
72
|
edges?: Edge[];
|
|
66
73
|
transformRead?: () => Clause;
|
|
67
|
-
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> |
|
|
74
|
+
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
|
|
68
75
|
transformsDelete?: boolean;
|
|
69
76
|
transformsInsert?: boolean;
|
|
70
77
|
transformsUpdate?: boolean;
|
|
@@ -76,14 +83,14 @@ export declare enum SQLStatementOperation {
|
|
|
76
83
|
}
|
|
77
84
|
export interface UpdateOperation<T extends Ent> {
|
|
78
85
|
op: SQLStatementOperation;
|
|
79
|
-
existingEnt
|
|
86
|
+
existingEnt: T | null;
|
|
80
87
|
viewer: Viewer;
|
|
81
88
|
data?: Map<string, any>;
|
|
82
89
|
}
|
|
83
90
|
export interface TransformedUpdateOperation<T extends Ent> {
|
|
84
91
|
op: SQLStatementOperation;
|
|
85
92
|
data?: Data;
|
|
86
|
-
existingEnt?: T;
|
|
93
|
+
existingEnt?: T | null;
|
|
87
94
|
}
|
|
88
95
|
export declare enum DBType {
|
|
89
96
|
UUID = "UUID",
|
|
@@ -185,15 +192,18 @@ export interface SchemaConstructor {
|
|
|
185
192
|
export declare type SchemaInputType = Schema | SchemaConstructor;
|
|
186
193
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
187
194
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
195
|
+
/**
|
|
196
|
+
* @deprecated should only be used by tests
|
|
197
|
+
*/
|
|
188
198
|
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
189
|
-
export declare function getFieldsWithPrivacy(value: SchemaInputType): Map<string, PrivacyPolicy>;
|
|
199
|
+
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
190
200
|
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
191
201
|
interface objectLoaderOptions {
|
|
192
202
|
clause?: () => Clause | undefined;
|
|
193
203
|
instanceKey?: string;
|
|
194
204
|
}
|
|
195
205
|
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
196
|
-
export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> |
|
|
206
|
+
export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | null;
|
|
197
207
|
export declare enum ActionOperation {
|
|
198
208
|
Create = 1,
|
|
199
209
|
Edit = 2,
|
package/schema/schema.js
CHANGED
|
@@ -86,12 +86,15 @@ function getFields(value) {
|
|
|
86
86
|
return m;
|
|
87
87
|
}
|
|
88
88
|
exports.getFields = getFields;
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated should only be used by tests
|
|
91
|
+
*/
|
|
89
92
|
function getStorageKey(field, fieldName) {
|
|
90
93
|
return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
|
|
91
94
|
}
|
|
92
95
|
exports.getStorageKey = getStorageKey;
|
|
93
96
|
// returns a mapping of storage key to field privacy
|
|
94
|
-
function getFieldsWithPrivacy(value) {
|
|
97
|
+
function getFieldsWithPrivacy(value, fieldMap) {
|
|
95
98
|
const schema = getSchema(value);
|
|
96
99
|
function addFields(fields) {
|
|
97
100
|
if (Array.isArray(fields)) {
|
|
@@ -111,7 +114,11 @@ function getFieldsWithPrivacy(value) {
|
|
|
111
114
|
else {
|
|
112
115
|
privacyPolicy = field.privacyPolicy;
|
|
113
116
|
}
|
|
114
|
-
|
|
117
|
+
const info = fieldMap[name];
|
|
118
|
+
if (!info) {
|
|
119
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
120
|
+
}
|
|
121
|
+
m.set(info.dbCol, privacyPolicy);
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
}
|
|
@@ -128,7 +135,11 @@ function getFieldsWithPrivacy(value) {
|
|
|
128
135
|
else {
|
|
129
136
|
privacyPolicy = field.privacyPolicy;
|
|
130
137
|
}
|
|
131
|
-
|
|
138
|
+
const info = fieldMap[name];
|
|
139
|
+
if (!info) {
|
|
140
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
141
|
+
}
|
|
142
|
+
m.set(info.dbCol, privacyPolicy);
|
|
132
143
|
}
|
|
133
144
|
}
|
|
134
145
|
}
|
|
@@ -167,13 +178,14 @@ exports.getObjectLoaderProperties = getObjectLoaderProperties;
|
|
|
167
178
|
function getTransformedUpdateOp(value, stmt) {
|
|
168
179
|
const schema = getSchema(value);
|
|
169
180
|
if (!schema.patterns) {
|
|
170
|
-
return;
|
|
181
|
+
return null;
|
|
171
182
|
}
|
|
172
183
|
for (const p of schema.patterns) {
|
|
173
184
|
if (p.transformWrite) {
|
|
174
185
|
return p.transformWrite(stmt);
|
|
175
186
|
}
|
|
176
187
|
}
|
|
188
|
+
return null;
|
|
177
189
|
}
|
|
178
190
|
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
179
191
|
// this maps to ActionOperation in ent/action.go
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const glob_1 = require("glob");
|
|
26
|
+
const path = __importStar(require("path"));
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
29
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
30
|
+
const ast_1 = require("../tsc/ast");
|
|
31
|
+
const child_process_1 = require("child_process");
|
|
32
|
+
// src/ent/generated and src/graphql/generated
|
|
33
|
+
function transformPath(old) {
|
|
34
|
+
const parts = old.split(path.sep);
|
|
35
|
+
if (parts.length < 3) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const changedParts = parts
|
|
39
|
+
.slice(0, 2)
|
|
40
|
+
.concat("generated")
|
|
41
|
+
.concat(parts.slice(2).filter((v) => v !== "generated"));
|
|
42
|
+
const newFile = changedParts.join(path.sep);
|
|
43
|
+
return { changedParts, newFile };
|
|
44
|
+
}
|
|
45
|
+
function moveFiles(files) {
|
|
46
|
+
files.forEach((file) => {
|
|
47
|
+
const conv = transformPath(file);
|
|
48
|
+
if (!conv) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const { changedParts, newFile } = conv;
|
|
52
|
+
if (file === newFile) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// check if directory exists, if not, create recursive dir
|
|
56
|
+
const p = changedParts.slice(0, changedParts.length - 1).join(path.sep);
|
|
57
|
+
const statInfo = fs.statSync(p, { throwIfNoEntry: false });
|
|
58
|
+
if (!statInfo) {
|
|
59
|
+
fs.mkdirSync(p, {
|
|
60
|
+
recursive: true,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// move file to new location
|
|
64
|
+
fs.renameSync(file, newFile);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function updateImports(files, target, cwd) {
|
|
68
|
+
files.forEach((file) => {
|
|
69
|
+
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
70
|
+
let nodes = [];
|
|
71
|
+
let updated = false;
|
|
72
|
+
typescript_1.default.forEachChild(sourceFile, function (node) {
|
|
73
|
+
let dirPath = path.join(cwd, file, "..");
|
|
74
|
+
if (typescript_1.default.isImportDeclaration(node)) {
|
|
75
|
+
const conv = isGeneratedPath(node, sourceFile, dirPath);
|
|
76
|
+
if (!conv) {
|
|
77
|
+
nodes.push({ node });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
updated = true;
|
|
81
|
+
const newImportPath = path.relative(dirPath, conv.newFile);
|
|
82
|
+
const v = (0, ast_1.updateImportPath)(contents, node, sourceFile, newImportPath);
|
|
83
|
+
nodes.push({ rawString: v });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
nodes.push({ node });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
let newContents = "";
|
|
90
|
+
for (const node of nodes) {
|
|
91
|
+
if (node.node) {
|
|
92
|
+
newContents += node.node.getFullText(sourceFile);
|
|
93
|
+
}
|
|
94
|
+
else if (node.rawString) {
|
|
95
|
+
newContents += node.rawString;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error(`malformed node with no node or rawString`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (updated) {
|
|
102
|
+
fs.writeFileSync(file, newContents);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function main() {
|
|
107
|
+
const entFiles = glob_1.glob.sync("src/ent/**/generated/**/**.ts");
|
|
108
|
+
const graphqlFiles = glob_1.glob.sync("src/graphql/**/generated/**/**.ts");
|
|
109
|
+
moveFiles(entFiles);
|
|
110
|
+
moveFiles(graphqlFiles);
|
|
111
|
+
const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
|
|
112
|
+
const entImportFiles = glob_1.glob.sync("src/ent/**/*.ts", {
|
|
113
|
+
ignore: ["**/generated/**", "node_modules/**"],
|
|
114
|
+
});
|
|
115
|
+
const graphqlImportFiles = glob_1.glob.sync("src/graphql/**/*.ts", {
|
|
116
|
+
ignore: ["**/generated/**", "node_modules/**"],
|
|
117
|
+
});
|
|
118
|
+
const cwd = process.cwd();
|
|
119
|
+
updateImports(entImportFiles, target, cwd);
|
|
120
|
+
updateImports(graphqlImportFiles, target, cwd);
|
|
121
|
+
(0, child_process_1.execSync)("prettier src/ent/*.ts --write");
|
|
122
|
+
(0, child_process_1.execSync)("prettier src/graphql/*.ts --write");
|
|
123
|
+
}
|
|
124
|
+
function isGeneratedPath(node, sourceFile, dirPath) {
|
|
125
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
126
|
+
// it's relative and has generated in there, continue
|
|
127
|
+
if (!((text.startsWith("..") || text.startsWith("./")) &&
|
|
128
|
+
text.indexOf("/generated") !== -1)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const oldPath = path.join(dirPath, text);
|
|
132
|
+
const relFromRoot = path.relative(".", oldPath);
|
|
133
|
+
const conv = transformPath(relFromRoot);
|
|
134
|
+
if (!conv) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (relFromRoot === conv.newFile) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return conv;
|
|
141
|
+
}
|
|
142
|
+
main();
|
|
@@ -29,9 +29,8 @@ const ast_1 = require("../tsc/ast");
|
|
|
29
29
|
const child_process_1 = require("child_process");
|
|
30
30
|
const fs = __importStar(require("fs"));
|
|
31
31
|
async function main() {
|
|
32
|
-
const options = (0, compilerOptions_1.readCompilerOptions)(".");
|
|
33
32
|
let files = glob_1.glob.sync("src/ent/*.ts");
|
|
34
|
-
const target = (0, compilerOptions_1.
|
|
33
|
+
const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
|
|
35
34
|
files.forEach((file) => {
|
|
36
35
|
let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
|
|
37
36
|
let traversed = false;
|
|
@@ -30,10 +30,8 @@ const child_process_1 = require("child_process");
|
|
|
30
30
|
const path_1 = __importDefault(require("path"));
|
|
31
31
|
const ast_1 = require("../tsc/ast");
|
|
32
32
|
async function main() {
|
|
33
|
-
// this assumes this is being run from root of directory
|
|
34
|
-
const options = (0, compilerOptions_1.readCompilerOptions)(".");
|
|
35
33
|
let files = glob_1.glob.sync("src/schema/*.ts");
|
|
36
|
-
const target = (0, compilerOptions_1.
|
|
34
|
+
const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
|
|
37
35
|
// filter to only event.ts e.g. for comments and whitespace...
|
|
38
36
|
// files = files.filter((f) => f.endsWith("event.ts"));
|
|
39
37
|
files.forEach((file) => {
|
package/testutils/builder.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Orchestrator } from "../action/orchestrator";
|
|
|
3
3
|
import { Action, Builder, Changeset, WriteOperation, Validator, Trigger, Observer } from "../action";
|
|
4
4
|
import { FieldMap, Schema } from "../schema";
|
|
5
5
|
import { SchemaConfig } from "../schema/base_schema";
|
|
6
|
+
import { FieldInfoMap } from "../schema/schema";
|
|
6
7
|
export declare class User implements Ent {
|
|
7
8
|
viewer: Viewer;
|
|
8
9
|
data: Data;
|
|
@@ -66,18 +67,23 @@ export declare function getBuilderSchemaFromFields<T extends Ent>(fields: FieldM
|
|
|
66
67
|
export declare function getBuilderSchemaTZFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
|
|
67
68
|
export declare function getSchemaName(value: BuilderSchema<Ent>): string;
|
|
68
69
|
export declare function getTableName(value: BuilderSchema<Ent>): string;
|
|
69
|
-
export declare
|
|
70
|
+
export declare function getFieldInfo(value: BuilderSchema<Ent>): FieldInfoMap;
|
|
71
|
+
declare type MaybeNull<T extends Ent> = T | null;
|
|
72
|
+
declare type TMaybleNullableEnt<T extends Ent> = T | MaybeNull<T>;
|
|
73
|
+
export declare class SimpleBuilder<T extends Ent, TExistingEnt extends TMaybleNullableEnt<T> = MaybeNull<T>> implements Builder<T> {
|
|
70
74
|
viewer: Viewer;
|
|
71
75
|
private schema;
|
|
72
76
|
operation: WriteOperation;
|
|
73
|
-
existingEnt:
|
|
77
|
+
existingEnt: TExistingEnt;
|
|
74
78
|
ent: EntConstructor<T>;
|
|
75
79
|
placeholderID: ID;
|
|
76
|
-
orchestrator: Orchestrator<T, Data>;
|
|
80
|
+
orchestrator: Orchestrator<T, Data, Viewer>;
|
|
77
81
|
fields: Map<string, any>;
|
|
78
82
|
nodeType: string;
|
|
79
|
-
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation
|
|
80
|
-
|
|
83
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation: WriteOperation, existingEnt: TExistingEnt, action?: Action<T, SimpleBuilder<T>, Viewer, Data> | undefined);
|
|
84
|
+
getInput(): Data;
|
|
85
|
+
updateInput(input: Data): void;
|
|
86
|
+
build(): Promise<Changeset>;
|
|
81
87
|
editedEnt(): Promise<T | null>;
|
|
82
88
|
editedEntX(): Promise<T>;
|
|
83
89
|
save(): Promise<void>;
|
|
@@ -88,18 +94,18 @@ export declare class SimpleBuilder<T extends Ent> implements Builder<T> {
|
|
|
88
94
|
interface viewerEntLoadFunc {
|
|
89
95
|
(data: Data): Viewer | Promise<Viewer>;
|
|
90
96
|
}
|
|
91
|
-
export declare class SimpleAction<T extends Ent> implements Action<T, SimpleBuilder<T>, Data> {
|
|
97
|
+
export declare class SimpleAction<T extends Ent, TExistingEnt extends TMaybleNullableEnt<T> = MaybeNull<T>> implements Action<T, SimpleBuilder<T, TExistingEnt>, Viewer, Data, TExistingEnt> {
|
|
92
98
|
viewer: Viewer;
|
|
93
99
|
private fields;
|
|
94
|
-
builder: SimpleBuilder<T>;
|
|
95
|
-
validators: Validator<SimpleBuilder<T
|
|
96
|
-
triggers: Trigger<SimpleBuilder<T
|
|
97
|
-
observers: Observer<SimpleBuilder<T
|
|
100
|
+
builder: SimpleBuilder<T, TExistingEnt>;
|
|
101
|
+
validators: Validator<T, SimpleBuilder<T>>[];
|
|
102
|
+
triggers: Trigger<T, SimpleBuilder<T>>[];
|
|
103
|
+
observers: Observer<T, SimpleBuilder<T>>[];
|
|
98
104
|
viewerForEntLoad: viewerEntLoadFunc | undefined;
|
|
99
|
-
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation
|
|
100
|
-
getPrivacyPolicy(): PrivacyPolicy<Ent
|
|
105
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation: WriteOperation | undefined, existingEnt: TExistingEnt);
|
|
106
|
+
getPrivacyPolicy(): PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
101
107
|
getInput(): Data;
|
|
102
|
-
changeset(): Promise<Changeset
|
|
108
|
+
changeset(): Promise<Changeset>;
|
|
103
109
|
valid(): Promise<boolean>;
|
|
104
110
|
validX(): Promise<void>;
|
|
105
111
|
save(): Promise<T | null>;
|