@magda/typescript-common 2.3.2 → 3.0.0-alpha.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/dist/AspectBuilder.d.ts +1 -1
- package/dist/AspectBuilder.js +1 -2
- package/dist/AspectCreationFailure.js +3 -4
- package/dist/AspectCreationFailure.js.map +1 -1
- package/dist/AsyncPage.js +59 -79
- package/dist/AsyncPage.js.map +1 -1
- package/dist/BaseApiClient.d.ts +3 -3
- package/dist/BaseApiClient.js +20 -13
- package/dist/BaseApiClient.js.map +1 -1
- package/dist/ConnectionResult.d.ts +2 -2
- package/dist/ConnectionResult.js +17 -22
- package/dist/ConnectionResult.js.map +1 -1
- package/dist/ConnectorRecordId.d.ts +1 -1
- package/dist/ConnectorRecordId.js +9 -13
- package/dist/ConnectorRecordId.js.map +1 -1
- package/dist/IndexerApiClient.d.ts +1 -1
- package/dist/IndexerApiClient.js +13 -32
- package/dist/IndexerApiClient.js.map +1 -1
- package/dist/JsonConnector.d.ts +9 -9
- package/dist/JsonConnector.js +163 -206
- package/dist/JsonConnector.js.map +1 -1
- package/dist/JsonTransformer.d.ts +3 -3
- package/dist/JsonTransformer.js +71 -75
- package/dist/JsonTransformer.js.map +1 -1
- package/dist/OpaCompileResponseParser.d.ts +4 -4
- package/dist/OpaCompileResponseParser.js +278 -211
- package/dist/OpaCompileResponseParser.js.map +1 -1
- package/dist/RecordCreationFailure.d.ts +1 -1
- package/dist/RecordCreationFailure.js +4 -4
- package/dist/RecordCreationFailure.js.map +1 -1
- package/dist/SQLUtils.d.ts +3 -3
- package/dist/SQLUtils.js +139 -195
- package/dist/SQLUtils.js.map +1 -1
- package/dist/ServerError.js +2 -4
- package/dist/ServerError.js.map +1 -1
- package/dist/Try.js +20 -35
- package/dist/Try.js.map +1 -1
- package/dist/addTrailingSlash.js +1 -4
- package/dist/addTrailingSlash.js.map +1 -1
- package/dist/appendUrlSegments.js +3 -8
- package/dist/appendUrlSegments.js.map +1 -1
- package/dist/authorization-api/AccessControlError.d.ts +1 -1
- package/dist/authorization-api/AccessControlError.js +2 -8
- package/dist/authorization-api/AccessControlError.js.map +1 -1
- package/dist/authorization-api/ApiClient.d.ts +3 -3
- package/dist/authorization-api/ApiClient.js +211 -272
- package/dist/authorization-api/ApiClient.js.map +1 -1
- package/dist/authorization-api/AuthError.d.ts +1 -1
- package/dist/authorization-api/AuthError.js +2 -8
- package/dist/authorization-api/AuthError.js.map +1 -1
- package/dist/authorization-api/GenericError.js +2 -4
- package/dist/authorization-api/GenericError.js.map +1 -1
- package/dist/authorization-api/authMiddleware.d.ts +3 -3
- package/dist/authorization-api/authMiddleware.js +19 -40
- package/dist/authorization-api/authMiddleware.js.map +1 -1
- package/dist/authorization-api/constants.js +9 -12
- package/dist/authorization-api/constants.js.map +1 -1
- package/dist/authorization-api/model.d.ts +8 -8
- package/dist/authorization-api/model.js +1 -2
- package/dist/coerceJson.js +1 -3
- package/dist/coerceJson.js.map +1 -1
- package/dist/createNoCacheFetchOptions.d.ts +1 -1
- package/dist/createNoCacheFetchOptions.js +4 -7
- package/dist/createNoCacheFetchOptions.js.map +1 -1
- package/dist/createServiceError.d.ts +1 -1
- package/dist/createServiceError.js +4 -9
- package/dist/createServiceError.js.map +1 -1
- package/dist/delay.js +1 -3
- package/dist/delay.js.map +1 -1
- package/dist/express/getNoCacheHeaders.js +1 -3
- package/dist/express/getNoCacheHeaders.js.map +1 -1
- package/dist/express/setResponseNoCache.d.ts +1 -1
- package/dist/express/setResponseNoCache.js +3 -8
- package/dist/express/setResponseNoCache.js.map +1 -1
- package/dist/express/status.d.ts +14 -15
- package/dist/express/status.js +135 -126
- package/dist/express/status.js.map +1 -1
- package/dist/fetchRequest.d.ts +6 -6
- package/dist/fetchRequest.js +36 -51
- package/dist/fetchRequest.js.map +1 -1
- package/dist/formatServiceError.js +1 -4
- package/dist/formatServiceError.js.map +1 -1
- package/dist/generated/registry/api.d.ts +4 -4
- package/dist/generated/registry/api.js +197 -102
- package/dist/generated/registry/api.js.map +1 -1
- package/dist/getAbsoluteUrl.js +8 -11
- package/dist/getAbsoluteUrl.js.map +1 -1
- package/dist/getBasePathFromUrl.js +3 -9
- package/dist/getBasePathFromUrl.js.map +1 -1
- package/dist/getBoolValWithDefault.js +1 -3
- package/dist/getBoolValWithDefault.js.map +1 -1
- package/dist/getRequest.js +9 -26
- package/dist/getRequest.js.map +1 -1
- package/dist/getRequestNoCache.js +4 -21
- package/dist/getRequestNoCache.js.map +1 -1
- package/dist/getStorageUrl.js +13 -23
- package/dist/getStorageUrl.js.map +1 -1
- package/dist/handleServerError.js +3 -9
- package/dist/handleServerError.js.map +1 -1
- package/dist/markdownToHtml.js +5 -11
- package/dist/markdownToHtml.js.map +1 -1
- package/dist/opa/AspectQuery.js +55 -79
- package/dist/opa/AspectQuery.js.map +1 -1
- package/dist/opa/AuthDecision.d.ts +2 -2
- package/dist/opa/AuthDecision.js +52 -69
- package/dist/opa/AuthDecision.js.map +1 -1
- package/dist/opa/AuthDecisionQueryClient.d.ts +2 -2
- package/dist/opa/AuthDecisionQueryClient.js +75 -102
- package/dist/opa/AuthDecisionQueryClient.js.map +1 -1
- package/dist/pgTypes.js +4 -9
- package/dist/pgTypes.js.map +1 -1
- package/dist/registry/AuthorizedRegistryClient.d.ts +4 -4
- package/dist/registry/AuthorizedRegistryClient.js +52 -92
- package/dist/registry/AuthorizedRegistryClient.js.map +1 -1
- package/dist/registry/RegistryClient.d.ts +2 -2
- package/dist/registry/RegistryClient.js +60 -76
- package/dist/registry/RegistryClient.js.map +1 -1
- package/dist/registry/TenantConsts.js +3 -6
- package/dist/registry/TenantConsts.js.map +1 -1
- package/dist/registry/model.js +1 -2
- package/dist/registry-manual/api.d.ts +1 -1
- package/dist/registry-manual/api.js +18 -7
- package/dist/registry-manual/api.js.map +1 -1
- package/dist/request.d.ts +2 -2
- package/dist/request.js +4 -9
- package/dist/request.js.map +1 -1
- package/dist/retry.d.ts +1 -1
- package/dist/retry.js +3 -9
- package/dist/retry.js.map +1 -1
- package/dist/retryBackoff.js +3 -9
- package/dist/retryBackoff.js.map +1 -1
- package/dist/runLater.js +1 -4
- package/dist/runLater.js.map +1 -1
- package/dist/session/GetUserId.d.ts +2 -2
- package/dist/session/GetUserId.js +10 -16
- package/dist/session/GetUserId.js.map +1 -1
- package/dist/session/GetUserSession.d.ts +1 -1
- package/dist/session/GetUserSession.js +6 -10
- package/dist/session/GetUserSession.js.map +1 -1
- package/dist/session/addJwtSecretFromEnvVar.js +1 -4
- package/dist/session/addJwtSecretFromEnvVar.js.map +1 -1
- package/dist/session/buildJwt.d.ts +1 -1
- package/dist/session/buildJwt.js +2 -5
- package/dist/session/buildJwt.js.map +1 -1
- package/dist/session/buildJwtFromReq.d.ts +2 -0
- package/dist/session/buildJwtFromReq.js +4 -0
- package/dist/session/buildJwtFromReq.js.map +1 -0
- package/dist/session/cookieUtils.d.ts +2 -13
- package/dist/session/cookieUtils.js +8 -9
- package/dist/session/cookieUtils.js.map +1 -1
- package/dist/session/destroySession.js +18 -33
- package/dist/session/destroySession.js.map +1 -1
- package/dist/session/getSessionId.js +5 -11
- package/dist/session/getSessionId.js.map +1 -1
- package/dist/tenant-api/AuthorizedTenantClient.d.ts +1 -1
- package/dist/tenant-api/AuthorizedTenantClient.js +22 -36
- package/dist/tenant-api/AuthorizedTenantClient.js.map +1 -1
- package/dist/tenant-api/Tenant.js +13 -5
- package/dist/tenant-api/Tenant.js.map +1 -1
- package/dist/test/JsonConnector.spec.js +56 -61
- package/dist/test/JsonConnector.spec.js.map +1 -1
- package/dist/test/JsonTransformer.spec.js +15 -19
- package/dist/test/JsonTransformer.spec.js.map +1 -1
- package/dist/test/arbitraries.d.ts +21 -21
- package/dist/test/arbitraries.js +85 -99
- package/dist/test/arbitraries.js.map +1 -1
- package/dist/test/aspect-templates/organization-details.d.ts +1 -4
- package/dist/test/aspect-templates/organization-details.js +1 -1
- package/dist/test/aspect-templates/organization-details.js.map +1 -1
- package/dist/test/buildApiClient.spec.js +81 -107
- package/dist/test/buildApiClient.spec.js.map +1 -1
- package/dist/test/buildAuthorizedTenantClient.spec.js +25 -40
- package/dist/test/buildAuthorizedTenantClient.spec.js.map +1 -1
- package/dist/test/connectors/MockExpressServer.js +9 -23
- package/dist/test/connectors/MockExpressServer.js.map +1 -1
- package/dist/test/connectors/MockRegistry.d.ts +1 -1
- package/dist/test/connectors/MockRegistry.js +11 -18
- package/dist/test/connectors/MockRegistry.js.map +1 -1
- package/dist/test/connectors/runConnectorTest.js +33 -55
- package/dist/test/connectors/runConnectorTest.js.map +1 -1
- package/dist/test/createMockAuthDecisionQueryClient.d.ts +4 -4
- package/dist/test/createMockAuthDecisionQueryClient.js +4 -9
- package/dist/test/createMockAuthDecisionQueryClient.js.map +1 -1
- package/dist/test/db/getTestDBConfig.js +1 -3
- package/dist/test/db/getTestDBConfig.js.map +1 -1
- package/dist/test/db/runMigrationSql.js +37 -58
- package/dist/test/db/runMigrationSql.js.map +1 -1
- package/dist/test/express/status.spec.js +81 -72
- package/dist/test/express/status.spec.js.map +1 -1
- package/dist/test/fakeArgv.js +6 -5
- package/dist/test/fakeArgv.js.map +1 -1
- package/dist/test/getBasePathFromUrl.spec.js +5 -10
- package/dist/test/getBasePathFromUrl.spec.js.map +1 -1
- package/dist/test/getStorageUrl.spec.js +22 -46
- package/dist/test/getStorageUrl.spec.js.map +1 -1
- package/dist/test/mockAuthApiHost.js +26 -28
- package/dist/test/mockAuthApiHost.js.map +1 -1
- package/dist/test/mockAuthorization.js +4 -10
- package/dist/test/mockAuthorization.js.map +1 -1
- package/dist/test/mockTenantDataStore.d.ts +1 -1
- package/dist/test/mockTenantDataStore.js +3 -5
- package/dist/test/mockTenantDataStore.js.map +1 -1
- package/dist/test/mockUserDataStore.d.ts +1 -1
- package/dist/test/mockUserDataStore.js +4 -6
- package/dist/test/mockUserDataStore.js.map +1 -1
- package/dist/test/registry/buildAuthorizedClient.spec.js +65 -87
- package/dist/test/registry/buildAuthorizedClient.spec.js.map +1 -1
- package/dist/test/session/buildJwt.spec.js +15 -19
- package/dist/test/session/buildJwt.spec.js.map +1 -1
- package/dist/test/session/buildJwtForRegistryEsriOpaGroupsAndOwnerTest.spec.js +6 -11
- package/dist/test/session/buildJwtForRegistryEsriOpaGroupsAndOwnerTest.spec.js.map +1 -1
- package/dist/test/session/buildJwtForRegistryEsriOpaGroupsTest.spec.js +6 -11
- package/dist/test/session/buildJwtForRegistryEsriOpaGroupsTest.spec.js.map +1 -1
- package/dist/test/session/buildJwtForRegistryEsriOpaOwnerTest.spec.js +6 -11
- package/dist/test/session/buildJwtForRegistryEsriOpaOwnerTest.spec.js.map +1 -1
- package/dist/test/testAsyncPage.spec.js +84 -105
- package/dist/test/testAsyncPage.spec.js.map +1 -1
- package/dist/test/testOpaCompileResponseParser.spec.js +192 -196
- package/dist/test/testOpaCompileResponseParser.spec.js.map +1 -1
- package/dist/test/util.js +1 -5
- package/dist/test/util.js.map +1 -1
- package/dist/unknown2Error.d.ts +2 -0
- package/dist/unknown2Error.js +3 -0
- package/dist/unknown2Error.js.map +1 -0
- package/dist/util/arrayToMaybe.d.ts +1 -1
- package/dist/util/arrayToMaybe.js +3 -6
- package/dist/util/arrayToMaybe.js.map +1 -1
- package/dist/util/cleanOrgTitle.js +1 -4
- package/dist/util/cleanOrgTitle.js.map +1 -1
- package/dist/util/escapeRegExp.js +1 -3
- package/dist/util/escapeRegExp.js.map +1 -1
- package/dist/util/getMinikubeIP.js +3 -9
- package/dist/util/getMinikubeIP.js.map +1 -1
- package/dist/util/isArray.js +1 -3
- package/dist/util/isArray.js.map +1 -1
- package/dist/util/isUuid.js +1 -3
- package/dist/util/isUuid.js.map +1 -1
- package/dist/util/unionToThrowable.d.ts +1 -1
- package/dist/util/unionToThrowable.js +3 -9
- package/dist/util/unionToThrowable.js.map +1 -1
- package/dist/utilityTypes.d.ts +1 -1
- package/dist/utilityTypes.js +1 -2
- package/package.json +44 -26
- package/dist/test/jsverify.d.ts +0 -2
- package/dist/test/jsverify.js +0 -8
- package/dist/test/jsverify.js.map +0 -1
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.unknown2Ref = exports.RegoRuleSet = exports.value2String = exports.RegoRef = exports.RegoExp = exports.RegoTerm = exports.RegoOperators = exports.RegoRule = void 0;
|
|
18
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
1
|
+
import _ from "lodash";
|
|
19
2
|
/**
|
|
20
3
|
* @class RegoRule
|
|
21
4
|
* @export
|
|
@@ -28,31 +11,94 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
28
11
|
* - The rule is considered as matched if all expressions in rule body are `true`
|
|
29
12
|
* You can opt to define a `default` rule. A default rule has no rule body and will only considered as matched if all other rules are not matched.
|
|
30
13
|
*/
|
|
31
|
-
class RegoRule {
|
|
14
|
+
export class RegoRule {
|
|
15
|
+
/**
|
|
16
|
+
* the local name of the rule. i.e. doesn't include full package path
|
|
17
|
+
* e.g. `allow`
|
|
18
|
+
*
|
|
19
|
+
* @type {string}
|
|
20
|
+
* @memberof RegoRule
|
|
21
|
+
*/
|
|
22
|
+
name;
|
|
23
|
+
/**
|
|
24
|
+
* Full name of the rule. Includes fulle package path
|
|
25
|
+
* e.g. `data.object.content.allowRead`
|
|
26
|
+
*
|
|
27
|
+
* @type {string}
|
|
28
|
+
* @memberof RegoRule
|
|
29
|
+
*/
|
|
30
|
+
fullName;
|
|
31
|
+
/**
|
|
32
|
+
* Whether a rule is a default Rule
|
|
33
|
+
* Its value only be used if any other residual rules are not matched (or no other residual rules)
|
|
34
|
+
*
|
|
35
|
+
* @type {boolean}
|
|
36
|
+
* @memberof RegoRule
|
|
37
|
+
*/
|
|
38
|
+
isDefault;
|
|
39
|
+
/**
|
|
40
|
+
* Rule value. Rule value is this value if all expression in rule body are true
|
|
41
|
+
* It can be any type. e.g. can be object or array etc. But a simple policy normally outputs a boolean true or false
|
|
42
|
+
*
|
|
43
|
+
* @type {RegoValue}
|
|
44
|
+
* @memberof RegoRule
|
|
45
|
+
*/
|
|
46
|
+
value;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the rule contains any expressions that has any resolvable references.
|
|
49
|
+
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
50
|
+
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
51
|
+
* i.e. evaluate() method should return immediately.
|
|
52
|
+
* This will speed up evaluation process.
|
|
53
|
+
*
|
|
54
|
+
* @type {boolean}
|
|
55
|
+
* @memberof RegoRule
|
|
56
|
+
*/
|
|
57
|
+
hasNoResolvableRef = false;
|
|
58
|
+
/**
|
|
59
|
+
* All Rego expressions in this rule's rule body. @see RegoExp
|
|
60
|
+
*
|
|
61
|
+
* @type {RegoExp[]}
|
|
62
|
+
* @memberof RegoRule
|
|
63
|
+
*/
|
|
64
|
+
expressions;
|
|
65
|
+
/**
|
|
66
|
+
* If the rule is matched or not
|
|
67
|
+
* Default to undefined
|
|
68
|
+
* Its value is only set when `isCompleteEvaluated` is true
|
|
69
|
+
*
|
|
70
|
+
* @type {boolean}
|
|
71
|
+
* @memberof RegoRule
|
|
72
|
+
*/
|
|
73
|
+
isMatched;
|
|
74
|
+
/**
|
|
75
|
+
* If the rule is fully evaluate
|
|
76
|
+
* Default to false
|
|
77
|
+
*
|
|
78
|
+
* @type {boolean}
|
|
79
|
+
* @memberof RegoRule
|
|
80
|
+
*/
|
|
81
|
+
isCompleteEvaluated;
|
|
82
|
+
/**
|
|
83
|
+
* Reference to OpaParser
|
|
84
|
+
*
|
|
85
|
+
* @private
|
|
86
|
+
* @type {OpaCompileResponseParser}
|
|
87
|
+
* @memberof RegoRule
|
|
88
|
+
*/
|
|
89
|
+
parser;
|
|
32
90
|
constructor(options) {
|
|
33
|
-
var _a;
|
|
34
|
-
/**
|
|
35
|
-
* Whether the rule contains any expressions that has any resolvable references.
|
|
36
|
-
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
37
|
-
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
38
|
-
* i.e. evaluate() method should return immediately.
|
|
39
|
-
* This will speed up evaluation process.
|
|
40
|
-
*
|
|
41
|
-
* @type {boolean}
|
|
42
|
-
* @memberof RegoRule
|
|
43
|
-
*/
|
|
44
|
-
this.hasNoResolvableRef = false;
|
|
45
91
|
this.isCompleteEvaluated = false;
|
|
46
|
-
this.name =
|
|
47
|
-
this.fullName =
|
|
48
|
-
this.isDefault =
|
|
92
|
+
this.name = _.isString(options.name) ? options.name : "";
|
|
93
|
+
this.fullName = _.isString(options.fullName) ? options.fullName : "";
|
|
94
|
+
this.isDefault = _.isBoolean(options.isDefault)
|
|
49
95
|
? options.isDefault
|
|
50
96
|
: false;
|
|
51
|
-
this.value =
|
|
52
|
-
this.expressions =
|
|
97
|
+
this.value = _.isUndefined(options.value) ? true : options.value;
|
|
98
|
+
this.expressions = _.isArray(options.expressions)
|
|
53
99
|
? options.expressions
|
|
54
100
|
: [];
|
|
55
|
-
this.isCompleteEvaluated =
|
|
101
|
+
this.isCompleteEvaluated = _.isBoolean(options.isCompleteEvaluated)
|
|
56
102
|
? options.isCompleteEvaluated
|
|
57
103
|
: false;
|
|
58
104
|
this.parser = options.parser;
|
|
@@ -66,7 +112,7 @@ class RegoRule {
|
|
|
66
112
|
throw new Error("Require parser parameter to create a RegoRule");
|
|
67
113
|
}
|
|
68
114
|
this.removeDuplicateExpressions();
|
|
69
|
-
if (
|
|
115
|
+
if (this.expressions?.length &&
|
|
70
116
|
this.expressions.findIndex((exp) => !exp.hasNoResolvableRef) === -1) {
|
|
71
117
|
this.hasNoResolvableRef = true;
|
|
72
118
|
}
|
|
@@ -81,8 +127,7 @@ class RegoRule {
|
|
|
81
127
|
* @memberof RegoRule
|
|
82
128
|
*/
|
|
83
129
|
removeDuplicateExpressions() {
|
|
84
|
-
|
|
85
|
-
if (!((_a = this === null || this === void 0 ? void 0 : this.expressions) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
130
|
+
if (!this?.expressions?.length) {
|
|
86
131
|
return;
|
|
87
132
|
}
|
|
88
133
|
const expSet = new Set();
|
|
@@ -102,8 +147,7 @@ class RegoRule {
|
|
|
102
147
|
* @memberof RegoRule
|
|
103
148
|
*/
|
|
104
149
|
isImpossible() {
|
|
105
|
-
|
|
106
|
-
if (!((_a = this === null || this === void 0 ? void 0 : this.expressions) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
150
|
+
if (!this?.expressions?.length) {
|
|
107
151
|
return false;
|
|
108
152
|
}
|
|
109
153
|
const nonNegatedExpSet = new Set();
|
|
@@ -129,7 +173,16 @@ class RegoRule {
|
|
|
129
173
|
return false;
|
|
130
174
|
}
|
|
131
175
|
clone(options = {}) {
|
|
132
|
-
const regoRule = new RegoRule(
|
|
176
|
+
const regoRule = new RegoRule({
|
|
177
|
+
name: this.name,
|
|
178
|
+
fullName: this.fullName,
|
|
179
|
+
isDefault: this.isDefault,
|
|
180
|
+
value: this.value,
|
|
181
|
+
isCompleteEvaluated: this.isCompleteEvaluated,
|
|
182
|
+
expressions: this.expressions.map((e) => e.clone()),
|
|
183
|
+
parser: this.parser,
|
|
184
|
+
...options
|
|
185
|
+
});
|
|
133
186
|
regoRule.isMatched = this.isMatched;
|
|
134
187
|
return regoRule;
|
|
135
188
|
}
|
|
@@ -141,14 +194,13 @@ class RegoRule {
|
|
|
141
194
|
* @memberof RegoRule
|
|
142
195
|
*/
|
|
143
196
|
evaluate() {
|
|
144
|
-
var _a;
|
|
145
197
|
if (this.hasNoResolvableRef) {
|
|
146
198
|
return this;
|
|
147
199
|
}
|
|
148
200
|
if (this.isCompleteEvaluated) {
|
|
149
201
|
return this;
|
|
150
202
|
}
|
|
151
|
-
if (!
|
|
203
|
+
if (!this?.expressions?.length) {
|
|
152
204
|
// a rule with empty body / no expression is matched
|
|
153
205
|
this.isCompleteEvaluated = true;
|
|
154
206
|
this.isMatched = true;
|
|
@@ -252,7 +304,7 @@ class RegoRule {
|
|
|
252
304
|
const ruleName = r.head && r.head.name ? r.head.name : "";
|
|
253
305
|
const ruleFullName = [packageName, ruleName].join(".");
|
|
254
306
|
const ruleIsDefault = r.default === true;
|
|
255
|
-
const ruleValue = r.head && r.head.value && !
|
|
307
|
+
const ruleValue = r.head && r.head.value && !_.isUndefined(r.head.value.value)
|
|
256
308
|
? r.head.value.value
|
|
257
309
|
: true;
|
|
258
310
|
const ruleOptions = {
|
|
@@ -267,7 +319,7 @@ class RegoRule {
|
|
|
267
319
|
return regoRule;
|
|
268
320
|
}
|
|
269
321
|
static createExpressionsFromRuleBodyData(data, parser) {
|
|
270
|
-
if (!
|
|
322
|
+
if (!_.isArray(data) || !data.length) {
|
|
271
323
|
throw new Error(`Encountered empty rule body.`);
|
|
272
324
|
}
|
|
273
325
|
return data.map((expData) => RegoExp.parseFromData(expData, parser));
|
|
@@ -288,8 +340,7 @@ class RegoRule {
|
|
|
288
340
|
});
|
|
289
341
|
}
|
|
290
342
|
}
|
|
291
|
-
|
|
292
|
-
exports.RegoOperators = {
|
|
343
|
+
export const RegoOperators = {
|
|
293
344
|
eq: "=",
|
|
294
345
|
equal: "=",
|
|
295
346
|
neq: "!=",
|
|
@@ -308,19 +359,22 @@ exports.RegoOperators = {
|
|
|
308
359
|
* @export
|
|
309
360
|
* @class RegoTerm
|
|
310
361
|
*/
|
|
311
|
-
class RegoTerm {
|
|
362
|
+
export class RegoTerm {
|
|
363
|
+
type;
|
|
364
|
+
value;
|
|
365
|
+
parser;
|
|
366
|
+
/**
|
|
367
|
+
* Whether the expression contains any resolvable references.
|
|
368
|
+
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
369
|
+
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
370
|
+
* i.e. evaluate() method should return immediately.
|
|
371
|
+
* This will speed up evaluation process.
|
|
372
|
+
*
|
|
373
|
+
* @type {boolean}
|
|
374
|
+
* @memberof RegoTerm
|
|
375
|
+
*/
|
|
376
|
+
hasNoResolvableRef = false;
|
|
312
377
|
constructor(type, value, parser) {
|
|
313
|
-
/**
|
|
314
|
-
* Whether the expression contains any resolvable references.
|
|
315
|
-
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
316
|
-
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
317
|
-
* i.e. evaluate() method should return immediately.
|
|
318
|
-
* This will speed up evaluation process.
|
|
319
|
-
*
|
|
320
|
-
* @type {boolean}
|
|
321
|
-
* @memberof RegoTerm
|
|
322
|
-
*/
|
|
323
|
-
this.hasNoResolvableRef = false;
|
|
324
378
|
this.type = type;
|
|
325
379
|
this.value = value;
|
|
326
380
|
this.parser = parser;
|
|
@@ -559,47 +613,68 @@ class RegoTerm {
|
|
|
559
613
|
}
|
|
560
614
|
}
|
|
561
615
|
}
|
|
562
|
-
exports.RegoTerm = RegoTerm;
|
|
563
616
|
/**
|
|
564
617
|
* Represents Rego expression
|
|
565
618
|
*
|
|
566
619
|
* @export
|
|
567
620
|
* @class RegoExp
|
|
568
621
|
*/
|
|
569
|
-
class RegoExp {
|
|
622
|
+
export class RegoExp {
|
|
623
|
+
/**
|
|
624
|
+
* All RegoTerms belongs to this expression
|
|
625
|
+
*
|
|
626
|
+
* @type {RegoTerm[]}
|
|
627
|
+
* @memberof RegoExp
|
|
628
|
+
*/
|
|
629
|
+
terms;
|
|
630
|
+
/**
|
|
631
|
+
* Whether the expression contains any resolvable references.
|
|
632
|
+
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
633
|
+
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
634
|
+
* i.e. evaluate() method should return immediately.
|
|
635
|
+
* This will speed up evaluation process.
|
|
636
|
+
*
|
|
637
|
+
* @type {boolean}
|
|
638
|
+
* @memberof RegoExp
|
|
639
|
+
*/
|
|
640
|
+
hasNoResolvableRef = false;
|
|
641
|
+
/**
|
|
642
|
+
* Whether this expression is a negative expression
|
|
643
|
+
* i.e. it's final evaluation result should be `false` if result is `true`
|
|
644
|
+
*
|
|
645
|
+
* @type {boolean}
|
|
646
|
+
* @memberof RegoExp
|
|
647
|
+
*/
|
|
648
|
+
isNegated;
|
|
649
|
+
/**
|
|
650
|
+
* If it's complete evaluated
|
|
651
|
+
*
|
|
652
|
+
* @type {boolean}
|
|
653
|
+
* @memberof RegoExp
|
|
654
|
+
*/
|
|
655
|
+
isCompleteEvaluated = false;
|
|
656
|
+
/**
|
|
657
|
+
* The value of the expression
|
|
658
|
+
*
|
|
659
|
+
* @type {RegoValue}
|
|
660
|
+
* @memberof RegoExp
|
|
661
|
+
*/
|
|
662
|
+
value = null;
|
|
663
|
+
/**
|
|
664
|
+
* Ref to Opa Parser
|
|
665
|
+
*
|
|
666
|
+
* @private
|
|
667
|
+
* @type {OpaCompileResponseParser}
|
|
668
|
+
* @memberof RegoExp
|
|
669
|
+
*/
|
|
670
|
+
parser;
|
|
570
671
|
constructor(terms, isNegated = false, isCompleteEvaluated = false, value = null, parser) {
|
|
571
|
-
var _a;
|
|
572
|
-
/**
|
|
573
|
-
* Whether the expression contains any resolvable references.
|
|
574
|
-
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
575
|
-
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
576
|
-
* i.e. evaluate() method should return immediately.
|
|
577
|
-
* This will speed up evaluation process.
|
|
578
|
-
*
|
|
579
|
-
* @type {boolean}
|
|
580
|
-
* @memberof RegoExp
|
|
581
|
-
*/
|
|
582
|
-
this.hasNoResolvableRef = false;
|
|
583
|
-
/**
|
|
584
|
-
* If it's complete evaluated
|
|
585
|
-
*
|
|
586
|
-
* @type {boolean}
|
|
587
|
-
* @memberof RegoExp
|
|
588
|
-
*/
|
|
589
|
-
this.isCompleteEvaluated = false;
|
|
590
|
-
/**
|
|
591
|
-
* The value of the expression
|
|
592
|
-
*
|
|
593
|
-
* @type {RegoValue}
|
|
594
|
-
* @memberof RegoExp
|
|
595
|
-
*/
|
|
596
|
-
this.value = null;
|
|
597
672
|
this.terms = terms;
|
|
598
673
|
this.isNegated = isNegated;
|
|
599
674
|
this.isCompleteEvaluated = isCompleteEvaluated;
|
|
600
675
|
this.value = value;
|
|
601
676
|
this.parser = parser;
|
|
602
|
-
if (
|
|
677
|
+
if (this?.terms?.length &&
|
|
603
678
|
this.terms.findIndex((item) => !item.hasNoResolvableRef) === -1) {
|
|
604
679
|
this.hasNoResolvableRef = true;
|
|
605
680
|
}
|
|
@@ -644,7 +719,7 @@ class RegoExp {
|
|
|
644
719
|
const parts = [];
|
|
645
720
|
if (this.isNegated)
|
|
646
721
|
parts.push("NOT");
|
|
647
|
-
if (!
|
|
722
|
+
if (!_.isUndefined(value)) {
|
|
648
723
|
parts.push(value2String(value));
|
|
649
724
|
}
|
|
650
725
|
else {
|
|
@@ -692,7 +767,7 @@ class RegoExp {
|
|
|
692
767
|
// --- undefined is a common value in Rego similar to false
|
|
693
768
|
// --- we set to false here to tell the difference between
|
|
694
769
|
// --- real undefined (not full resolved) and undefined value
|
|
695
|
-
if (
|
|
770
|
+
if (_.isUndefined(this.value))
|
|
696
771
|
return false;
|
|
697
772
|
else
|
|
698
773
|
return this.value;
|
|
@@ -713,7 +788,7 @@ class RegoExp {
|
|
|
713
788
|
if (!this.isResolvable()) {
|
|
714
789
|
return undefined;
|
|
715
790
|
}
|
|
716
|
-
const isMatched = this.value === false ||
|
|
791
|
+
const isMatched = this.value === false || _.isUndefined(this.value) ? false : true;
|
|
717
792
|
if (this.isNegated) {
|
|
718
793
|
return !isMatched;
|
|
719
794
|
}
|
|
@@ -896,13 +971,13 @@ class RegoExp {
|
|
|
896
971
|
}
|
|
897
972
|
static parseFromData(expData, parser) {
|
|
898
973
|
const isNegated = expData.negated === true;
|
|
899
|
-
if (
|
|
974
|
+
if (_.isEmpty(expData.terms)) {
|
|
900
975
|
if (isNegated)
|
|
901
976
|
throw new Error("Invalid negated empty term!");
|
|
902
977
|
return new RegoExp([], isNegated, false, null, parser);
|
|
903
978
|
}
|
|
904
979
|
let termsData = [];
|
|
905
|
-
if (
|
|
980
|
+
if (_.isArray(expData.terms)) {
|
|
906
981
|
termsData = expData.terms;
|
|
907
982
|
}
|
|
908
983
|
else {
|
|
@@ -914,7 +989,6 @@ class RegoExp {
|
|
|
914
989
|
return exp;
|
|
915
990
|
}
|
|
916
991
|
}
|
|
917
|
-
exports.RegoExp = RegoExp;
|
|
918
992
|
/**
|
|
919
993
|
* Represents a special Rego Term type: reference term
|
|
920
994
|
* You shouldn't use this class directly
|
|
@@ -922,30 +996,30 @@ exports.RegoExp = RegoExp;
|
|
|
922
996
|
* @export
|
|
923
997
|
* @class RegoRef
|
|
924
998
|
*/
|
|
925
|
-
class RegoRef {
|
|
999
|
+
export class RegoRef {
|
|
1000
|
+
parts;
|
|
1001
|
+
/**
|
|
1002
|
+
* Whether the expression contains any resolvable references.
|
|
1003
|
+
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
1004
|
+
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
1005
|
+
* i.e. evaluate() method should return immediately.
|
|
1006
|
+
* This will speed up evaluation process.
|
|
1007
|
+
*
|
|
1008
|
+
* @type {boolean}
|
|
1009
|
+
* @memberof RegoRef
|
|
1010
|
+
*/
|
|
1011
|
+
hasNoResolvableRef = false;
|
|
926
1012
|
constructor(parts) {
|
|
927
|
-
var _a;
|
|
928
|
-
/**
|
|
929
|
-
* Whether the expression contains any resolvable references.
|
|
930
|
-
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
931
|
-
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
932
|
-
* i.e. evaluate() method should return immediately.
|
|
933
|
-
* This will speed up evaluation process.
|
|
934
|
-
*
|
|
935
|
-
* @type {boolean}
|
|
936
|
-
* @memberof RegoRef
|
|
937
|
-
*/
|
|
938
|
-
this.hasNoResolvableRef = false;
|
|
939
1013
|
this.parts = parts;
|
|
940
1014
|
if (
|
|
941
1015
|
// `input.` ref should be considered not resolvable in partial evaluate context.
|
|
942
|
-
(this.parts.length &&
|
|
1016
|
+
(this.parts.length && this.parts[0]?.value === "input") ||
|
|
943
1017
|
this.isOperator()) {
|
|
944
1018
|
this.hasNoResolvableRef = true;
|
|
945
1019
|
}
|
|
946
1020
|
}
|
|
947
1021
|
clone() {
|
|
948
|
-
return new RegoRef(this.parts.map((p) => (
|
|
1022
|
+
return new RegoRef(this.parts.map((p) => ({ ...p })));
|
|
949
1023
|
}
|
|
950
1024
|
toData() {
|
|
951
1025
|
return {
|
|
@@ -1018,7 +1092,7 @@ class RegoRef {
|
|
|
1018
1092
|
.map((refStr) => refStr.replace(/^\./, ""));
|
|
1019
1093
|
}
|
|
1020
1094
|
isOperator() {
|
|
1021
|
-
return Object.keys(
|
|
1095
|
+
return Object.keys(RegoOperators).indexOf(this.fullRefString()) !== -1;
|
|
1022
1096
|
}
|
|
1023
1097
|
// --- the first var type won't count as collection lookup
|
|
1024
1098
|
hasCollectionLookup() {
|
|
@@ -1046,40 +1120,39 @@ class RegoRef {
|
|
|
1046
1120
|
}
|
|
1047
1121
|
asOperator() {
|
|
1048
1122
|
if (this.isOperator())
|
|
1049
|
-
return
|
|
1123
|
+
return RegoOperators[this.fullRefString()];
|
|
1050
1124
|
else
|
|
1051
1125
|
return null;
|
|
1052
1126
|
}
|
|
1053
1127
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
if (lodash_1.default.isBoolean(value) || lodash_1.default.isNumber(value))
|
|
1128
|
+
export function value2String(value) {
|
|
1129
|
+
if (_.isBoolean(value) || _.isNumber(value))
|
|
1057
1130
|
return value.toString();
|
|
1058
1131
|
else
|
|
1059
1132
|
return JSON.stringify(value);
|
|
1060
1133
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1134
|
+
export class RegoRuleSet {
|
|
1135
|
+
fullName = "";
|
|
1136
|
+
name = "";
|
|
1137
|
+
rules = [];
|
|
1138
|
+
defaultRule = null;
|
|
1139
|
+
value;
|
|
1140
|
+
isCompleteEvaluated = false;
|
|
1141
|
+
parser;
|
|
1142
|
+
/**
|
|
1143
|
+
* Whether the ruleSet contains any rules that has any resolvable references.
|
|
1144
|
+
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
1145
|
+
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
1146
|
+
* i.e. evaluate() method should return immediately.
|
|
1147
|
+
* This will speed up evaluation process.
|
|
1148
|
+
*
|
|
1149
|
+
* @type {boolean}
|
|
1150
|
+
* @memberof RegoRuleSet
|
|
1151
|
+
*/
|
|
1152
|
+
hasNoResolvableRef = false;
|
|
1063
1153
|
constructor(parser, rules, fullName = "", name = "") {
|
|
1064
|
-
var _a, _b;
|
|
1065
|
-
this.fullName = "";
|
|
1066
|
-
this.name = "";
|
|
1067
|
-
this.rules = [];
|
|
1068
|
-
this.defaultRule = null;
|
|
1069
|
-
this.isCompleteEvaluated = false;
|
|
1070
|
-
/**
|
|
1071
|
-
* Whether the ruleSet contains any rules that has any resolvable references.
|
|
1072
|
-
* reference start with `input.` should be considered as non-resolvable in context of partial evaluation.
|
|
1073
|
-
* When this field is set to `true`, we should not attempt to evaluate this expression.
|
|
1074
|
-
* i.e. evaluate() method should return immediately.
|
|
1075
|
-
* This will speed up evaluation process.
|
|
1076
|
-
*
|
|
1077
|
-
* @type {boolean}
|
|
1078
|
-
* @memberof RegoRuleSet
|
|
1079
|
-
*/
|
|
1080
|
-
this.hasNoResolvableRef = false;
|
|
1081
1154
|
this.parser = parser;
|
|
1082
|
-
if (rules
|
|
1155
|
+
if (rules?.length) {
|
|
1083
1156
|
const defaultRuleIdx = rules.findIndex((r) => r.isDefault);
|
|
1084
1157
|
if (defaultRuleIdx !== -1) {
|
|
1085
1158
|
this.defaultRule = rules[defaultRuleIdx];
|
|
@@ -1089,13 +1162,13 @@ class RegoRuleSet {
|
|
|
1089
1162
|
if (fullName) {
|
|
1090
1163
|
this.fullName = fullName;
|
|
1091
1164
|
}
|
|
1092
|
-
else if (
|
|
1165
|
+
else if (rules?.[0]?.fullName) {
|
|
1093
1166
|
this.fullName = rules[0].fullName;
|
|
1094
1167
|
}
|
|
1095
1168
|
if (name) {
|
|
1096
1169
|
this.name = name;
|
|
1097
1170
|
}
|
|
1098
|
-
else if (
|
|
1171
|
+
else if (rules?.[0]?.name) {
|
|
1099
1172
|
this.name = rules[0].name;
|
|
1100
1173
|
}
|
|
1101
1174
|
if (this.rules.length &&
|
|
@@ -1105,14 +1178,13 @@ class RegoRuleSet {
|
|
|
1105
1178
|
this.evaluate();
|
|
1106
1179
|
}
|
|
1107
1180
|
evaluate() {
|
|
1108
|
-
var _a;
|
|
1109
1181
|
if (this.hasNoResolvableRef) {
|
|
1110
1182
|
return this;
|
|
1111
1183
|
}
|
|
1112
1184
|
if (this.isCompleteEvaluated) {
|
|
1113
1185
|
return this;
|
|
1114
1186
|
}
|
|
1115
|
-
if (!
|
|
1187
|
+
if (!this.rules?.length) {
|
|
1116
1188
|
if (!this.defaultRule) {
|
|
1117
1189
|
this.isCompleteEvaluated = true;
|
|
1118
1190
|
this.value = undefined;
|
|
@@ -1174,7 +1246,7 @@ class RegoRuleSet {
|
|
|
1174
1246
|
if (!rules.length) {
|
|
1175
1247
|
return [];
|
|
1176
1248
|
}
|
|
1177
|
-
rules =
|
|
1249
|
+
rules = _.flatMap(rules, (rule) => {
|
|
1178
1250
|
// all resolvable expressions can all be ignored as:
|
|
1179
1251
|
// - if the expression is resolved to "matched", it won't impact the result of the rule
|
|
1180
1252
|
// - if the expression is resolved to "unmatched", the rule should be resolved to "unmatched" earlier.
|
|
@@ -1241,72 +1313,69 @@ class RegoRuleSet {
|
|
|
1241
1313
|
return rules;
|
|
1242
1314
|
}
|
|
1243
1315
|
}
|
|
1244
|
-
exports.RegoRuleSet = RegoRuleSet;
|
|
1245
1316
|
/**
|
|
1246
1317
|
* OPA result Parser
|
|
1247
1318
|
*
|
|
1248
1319
|
* @export
|
|
1249
1320
|
* @class OpaCompileResponseParser
|
|
1250
1321
|
*/
|
|
1251
|
-
class OpaCompileResponseParser {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
this.ruleDuplicationCheckCache = {};
|
|
1309
|
-
}
|
|
1322
|
+
export default class OpaCompileResponseParser {
|
|
1323
|
+
/**
|
|
1324
|
+
* If a warning is produced during the parsing
|
|
1325
|
+
*
|
|
1326
|
+
* @type {boolean}
|
|
1327
|
+
* @memberof OpaCompileResponseParser
|
|
1328
|
+
*/
|
|
1329
|
+
hasWarns = false;
|
|
1330
|
+
/**
|
|
1331
|
+
* Any warnings produced during the parsing
|
|
1332
|
+
*
|
|
1333
|
+
* @type {string[]}
|
|
1334
|
+
* @memberof OpaCompileResponseParser
|
|
1335
|
+
*/
|
|
1336
|
+
warns = [];
|
|
1337
|
+
data = null;
|
|
1338
|
+
/**
|
|
1339
|
+
* Inital Rules parsed from result
|
|
1340
|
+
* Only for debug purpose
|
|
1341
|
+
*
|
|
1342
|
+
* @type {RegoRule[]}
|
|
1343
|
+
* @memberof OpaCompileResponseParser
|
|
1344
|
+
*/
|
|
1345
|
+
originalRules = [];
|
|
1346
|
+
/**
|
|
1347
|
+
* Parsed, compressed & evaluated rules
|
|
1348
|
+
*
|
|
1349
|
+
* @type {RegoRule[]}
|
|
1350
|
+
* @memberof OpaCompileResponseParser
|
|
1351
|
+
*/
|
|
1352
|
+
rules = [];
|
|
1353
|
+
/**
|
|
1354
|
+
* Parsed, compressed & evaluated rule sets
|
|
1355
|
+
*
|
|
1356
|
+
* @type {RegoRuleSet[]}
|
|
1357
|
+
* @memberof OpaCompileResponseParser
|
|
1358
|
+
*/
|
|
1359
|
+
ruleSets = {};
|
|
1360
|
+
queries = [];
|
|
1361
|
+
/**
|
|
1362
|
+
* A cache of all resolved rule result
|
|
1363
|
+
*
|
|
1364
|
+
* @type {{
|
|
1365
|
+
* [fullName: string]: CompleteRuleResult;
|
|
1366
|
+
* }}
|
|
1367
|
+
* @memberof OpaCompileResponseParser
|
|
1368
|
+
*/
|
|
1369
|
+
completeRuleResults = {};
|
|
1370
|
+
/**
|
|
1371
|
+
* The pseudo query rule name
|
|
1372
|
+
* The parser will assign a random pseudo rule name to the query expressions you submit.
|
|
1373
|
+
*
|
|
1374
|
+
* @type {string}
|
|
1375
|
+
* @memberof OpaCompileResponseParser
|
|
1376
|
+
*/
|
|
1377
|
+
pseudoQueryRuleName = RegoRule.randomRuleName("default_rule_");
|
|
1378
|
+
ruleDuplicationCheckCache = {};
|
|
1310
1379
|
setQueryRuleResult(val) {
|
|
1311
1380
|
this.completeRuleResults[this.pseudoQueryRuleName] = {
|
|
1312
1381
|
fullName: this.pseudoQueryRuleName,
|
|
@@ -1323,7 +1392,7 @@ class OpaCompileResponseParser {
|
|
|
1323
1392
|
* @memberof OpaCompileResponseParser
|
|
1324
1393
|
*/
|
|
1325
1394
|
parse(json) {
|
|
1326
|
-
if (
|
|
1395
|
+
if (_.isString(json)) {
|
|
1327
1396
|
this.data = JSON.parse(json);
|
|
1328
1397
|
}
|
|
1329
1398
|
else {
|
|
@@ -1339,12 +1408,12 @@ class OpaCompileResponseParser {
|
|
|
1339
1408
|
}
|
|
1340
1409
|
this.data = this.data.result;
|
|
1341
1410
|
if (!this.data.queries ||
|
|
1342
|
-
!
|
|
1411
|
+
!_.isArray(this.data.queries) ||
|
|
1343
1412
|
!this.data.queries.length) {
|
|
1344
1413
|
this.setQueryRuleResult(false);
|
|
1345
1414
|
return [];
|
|
1346
1415
|
}
|
|
1347
|
-
if (this.data.queries.findIndex((q) => !
|
|
1416
|
+
if (this.data.queries.findIndex((q) => !q?.length) !== -1) {
|
|
1348
1417
|
// when query is always true, the "queries" value in the result will contain an empty array
|
|
1349
1418
|
this.setQueryRuleResult(true);
|
|
1350
1419
|
return [];
|
|
@@ -1374,9 +1443,9 @@ class OpaCompileResponseParser {
|
|
|
1374
1443
|
const packages = this.data.support;
|
|
1375
1444
|
if (packages) {
|
|
1376
1445
|
packages.forEach((p) => {
|
|
1377
|
-
if (!
|
|
1446
|
+
if (!_.isArray(p.rules) || !p.rules.length)
|
|
1378
1447
|
return;
|
|
1379
|
-
const packageName = p.package &&
|
|
1448
|
+
const packageName = p.package && _.isArray(p.package.path)
|
|
1380
1449
|
? RegoRef.convertToFullRefString(p.package.path)
|
|
1381
1450
|
: "";
|
|
1382
1451
|
const rules = p.rules;
|
|
@@ -1389,7 +1458,7 @@ class OpaCompileResponseParser {
|
|
|
1389
1458
|
});
|
|
1390
1459
|
}
|
|
1391
1460
|
this.ruleDuplicationCheckCache = {};
|
|
1392
|
-
|
|
1461
|
+
_.uniq(this.rules.map((r) => r.fullName)).forEach((fullName) => (this.ruleSets[fullName] = new RegoRuleSet(this, this.rules.filter((r) => r.fullName === fullName), fullName)));
|
|
1393
1462
|
this.resolveAllRuleSets();
|
|
1394
1463
|
return this.rules;
|
|
1395
1464
|
}
|
|
@@ -1402,7 +1471,7 @@ class OpaCompileResponseParser {
|
|
|
1402
1471
|
this.ruleDuplicationCheckCache[rule.fullName] = new Set();
|
|
1403
1472
|
}
|
|
1404
1473
|
const setData = this.ruleDuplicationCheckCache[rule.fullName];
|
|
1405
|
-
const
|
|
1474
|
+
const { name, fullName, ...ruleData } = rule.toData();
|
|
1406
1475
|
const jsonData = JSON.stringify(ruleData);
|
|
1407
1476
|
const size = setData.size;
|
|
1408
1477
|
setData.add(jsonData);
|
|
@@ -1525,10 +1594,8 @@ class OpaCompileResponseParser {
|
|
|
1525
1594
|
this.hasWarns = true;
|
|
1526
1595
|
}
|
|
1527
1596
|
}
|
|
1528
|
-
|
|
1529
|
-
function unknown2Ref(unknown) {
|
|
1597
|
+
export function unknown2Ref(unknown) {
|
|
1530
1598
|
const prefix = unknown.replace(/^input\./, "");
|
|
1531
1599
|
return `data.partial.${prefix}`;
|
|
1532
1600
|
}
|
|
1533
|
-
exports.unknown2Ref = unknown2Ref;
|
|
1534
1601
|
//# sourceMappingURL=OpaCompileResponseParser.js.map
|