@snowtop/ent 0.0.3-5.alpha.2 → 0.0.3-6.alpha
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
CHANGED
|
@@ -108,6 +108,7 @@ declare enum privacyResult {
|
|
|
108
108
|
export interface PrivacyResult {
|
|
109
109
|
result: privacyResult;
|
|
110
110
|
error?: PrivacyError;
|
|
111
|
+
getError?(policy: PrivacyPolicy, rule: PrivacyPolicyRule, ent?: Ent): PrivacyError;
|
|
111
112
|
}
|
|
112
113
|
export interface PrivacyError extends Error {
|
|
113
114
|
privacyPolicy: PrivacyPolicy;
|
|
@@ -116,7 +117,7 @@ export interface PrivacyError extends Error {
|
|
|
116
117
|
export declare function Allow(): PrivacyResult;
|
|
117
118
|
export declare function Skip(): PrivacyResult;
|
|
118
119
|
export declare function Deny(): PrivacyResult;
|
|
119
|
-
export declare function DenyWithReason(e: PrivacyError): PrivacyResult;
|
|
120
|
+
export declare function DenyWithReason(e: PrivacyError | string): PrivacyResult;
|
|
120
121
|
export interface PrivacyPolicyRule {
|
|
121
122
|
apply(v: Viewer, ent?: Ent): Promise<PrivacyResult>;
|
|
122
123
|
}
|
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,
|
|
@@ -32,7 +32,7 @@ export declare class AssocEdgeLoaderFactory<T extends AssocEdge> implements Load
|
|
|
32
32
|
name: string;
|
|
33
33
|
constructor(edgeType: string, edgeCtr: AssocEdgeConstructor<T> | (() => AssocEdgeConstructor<T>));
|
|
34
34
|
createLoader(context?: Context): AssocLoader<T>;
|
|
35
|
-
private
|
|
35
|
+
private isConstructor;
|
|
36
36
|
createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): AssocLoader<T>;
|
|
37
37
|
}
|
|
38
38
|
export {};
|
|
@@ -161,16 +161,18 @@ class AssocEdgeLoaderFactory {
|
|
|
161
161
|
createLoader(context) {
|
|
162
162
|
return this.createConfigurableLoader({}, context);
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
isConstructor(edgeCtr) {
|
|
165
165
|
// not constructor
|
|
166
|
-
return
|
|
166
|
+
return (edgeCtr.prototype &&
|
|
167
|
+
edgeCtr.prototype.constructor &&
|
|
168
|
+
edgeCtr.prototype.constructor.name.length > 0);
|
|
167
169
|
}
|
|
168
170
|
createConfigurableLoader(options, context) {
|
|
169
171
|
let edgeCtr = this.edgeCtr;
|
|
170
172
|
// in generated code, the edge is not necessarily defined at the time of loading
|
|
171
173
|
// so we call this as follows:
|
|
172
174
|
// const loader = new AssocEdgeLoaderFactory(EdgeType.Foo, ()=>DerivedEdgeClass);
|
|
173
|
-
if (this.
|
|
175
|
+
if (!this.isConstructor(edgeCtr)) {
|
|
174
176
|
edgeCtr = edgeCtr();
|
|
175
177
|
}
|
|
176
178
|
// rename to make TS happy
|
package/core/privacy.js
CHANGED