@magda/typescript-common 2.3.3 → 3.0.0-alpha.1

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.
Files changed (249) hide show
  1. package/dist/AspectBuilder.d.ts +1 -1
  2. package/dist/AspectBuilder.js +1 -2
  3. package/dist/AspectCreationFailure.js +3 -4
  4. package/dist/AspectCreationFailure.js.map +1 -1
  5. package/dist/AsyncPage.js +59 -79
  6. package/dist/AsyncPage.js.map +1 -1
  7. package/dist/BaseApiClient.d.ts +3 -3
  8. package/dist/BaseApiClient.js +20 -13
  9. package/dist/BaseApiClient.js.map +1 -1
  10. package/dist/ConnectionResult.d.ts +2 -2
  11. package/dist/ConnectionResult.js +17 -22
  12. package/dist/ConnectionResult.js.map +1 -1
  13. package/dist/ConnectorRecordId.d.ts +1 -1
  14. package/dist/ConnectorRecordId.js +9 -13
  15. package/dist/ConnectorRecordId.js.map +1 -1
  16. package/dist/IndexerApiClient.d.ts +1 -1
  17. package/dist/IndexerApiClient.js +13 -32
  18. package/dist/IndexerApiClient.js.map +1 -1
  19. package/dist/JsonConnector.d.ts +9 -9
  20. package/dist/JsonConnector.js +163 -206
  21. package/dist/JsonConnector.js.map +1 -1
  22. package/dist/JsonTransformer.d.ts +3 -3
  23. package/dist/JsonTransformer.js +71 -75
  24. package/dist/JsonTransformer.js.map +1 -1
  25. package/dist/OpaCompileResponseParser.d.ts +4 -4
  26. package/dist/OpaCompileResponseParser.js +279 -212
  27. package/dist/OpaCompileResponseParser.js.map +1 -1
  28. package/dist/RecordCreationFailure.d.ts +1 -1
  29. package/dist/RecordCreationFailure.js +4 -4
  30. package/dist/RecordCreationFailure.js.map +1 -1
  31. package/dist/SQLUtils.d.ts +3 -3
  32. package/dist/SQLUtils.js +139 -195
  33. package/dist/SQLUtils.js.map +1 -1
  34. package/dist/ServerError.js +2 -4
  35. package/dist/ServerError.js.map +1 -1
  36. package/dist/Try.js +20 -35
  37. package/dist/Try.js.map +1 -1
  38. package/dist/addTrailingSlash.js +1 -4
  39. package/dist/addTrailingSlash.js.map +1 -1
  40. package/dist/appendUrlSegments.js +3 -8
  41. package/dist/appendUrlSegments.js.map +1 -1
  42. package/dist/authorization-api/AccessControlError.d.ts +1 -1
  43. package/dist/authorization-api/AccessControlError.js +2 -8
  44. package/dist/authorization-api/AccessControlError.js.map +1 -1
  45. package/dist/authorization-api/ApiClient.d.ts +3 -3
  46. package/dist/authorization-api/ApiClient.js +211 -272
  47. package/dist/authorization-api/ApiClient.js.map +1 -1
  48. package/dist/authorization-api/AuthError.d.ts +1 -1
  49. package/dist/authorization-api/AuthError.js +2 -8
  50. package/dist/authorization-api/AuthError.js.map +1 -1
  51. package/dist/authorization-api/GenericError.js +2 -4
  52. package/dist/authorization-api/GenericError.js.map +1 -1
  53. package/dist/authorization-api/authMiddleware.d.ts +3 -3
  54. package/dist/authorization-api/authMiddleware.js +19 -40
  55. package/dist/authorization-api/authMiddleware.js.map +1 -1
  56. package/dist/authorization-api/constants.js +9 -12
  57. package/dist/authorization-api/constants.js.map +1 -1
  58. package/dist/authorization-api/model.d.ts +8 -8
  59. package/dist/authorization-api/model.js +1 -2
  60. package/dist/coerceJson.js +1 -3
  61. package/dist/coerceJson.js.map +1 -1
  62. package/dist/createNoCacheFetchOptions.d.ts +1 -1
  63. package/dist/createNoCacheFetchOptions.js +4 -7
  64. package/dist/createNoCacheFetchOptions.js.map +1 -1
  65. package/dist/createServiceError.d.ts +1 -1
  66. package/dist/createServiceError.js +7 -11
  67. package/dist/createServiceError.js.map +1 -1
  68. package/dist/delay.js +1 -3
  69. package/dist/delay.js.map +1 -1
  70. package/dist/express/getNoCacheHeaders.js +1 -3
  71. package/dist/express/getNoCacheHeaders.js.map +1 -1
  72. package/dist/express/setResponseNoCache.d.ts +1 -1
  73. package/dist/express/setResponseNoCache.js +3 -8
  74. package/dist/express/setResponseNoCache.js.map +1 -1
  75. package/dist/express/status.d.ts +14 -15
  76. package/dist/express/status.js +145 -148
  77. package/dist/express/status.js.map +1 -1
  78. package/dist/fetchRequest.d.ts +6 -6
  79. package/dist/fetchRequest.js +36 -51
  80. package/dist/fetchRequest.js.map +1 -1
  81. package/dist/formatServiceError.js +4 -6
  82. package/dist/formatServiceError.js.map +1 -1
  83. package/dist/generated/registry/api.d.ts +67 -55
  84. package/dist/generated/registry/api.js +557 -765
  85. package/dist/generated/registry/api.js.map +1 -1
  86. package/dist/getAbsoluteUrl.js +8 -11
  87. package/dist/getAbsoluteUrl.js.map +1 -1
  88. package/dist/getBasePathFromUrl.js +3 -9
  89. package/dist/getBasePathFromUrl.js.map +1 -1
  90. package/dist/getBoolValWithDefault.js +1 -3
  91. package/dist/getBoolValWithDefault.js.map +1 -1
  92. package/dist/getRequest.js +9 -26
  93. package/dist/getRequest.js.map +1 -1
  94. package/dist/getRequestNoCache.js +4 -21
  95. package/dist/getRequestNoCache.js.map +1 -1
  96. package/dist/getStorageUrl.js +13 -23
  97. package/dist/getStorageUrl.js.map +1 -1
  98. package/dist/getUserAgent.d.ts +2 -0
  99. package/dist/getUserAgent.js +10 -0
  100. package/dist/getUserAgent.js.map +1 -0
  101. package/dist/handleServerError.js +3 -9
  102. package/dist/handleServerError.js.map +1 -1
  103. package/dist/markdownToHtml.js +5 -11
  104. package/dist/markdownToHtml.js.map +1 -1
  105. package/dist/opa/AspectQuery.js +55 -79
  106. package/dist/opa/AspectQuery.js.map +1 -1
  107. package/dist/opa/AuthDecision.d.ts +2 -2
  108. package/dist/opa/AuthDecision.js +52 -69
  109. package/dist/opa/AuthDecision.js.map +1 -1
  110. package/dist/opa/AuthDecisionQueryClient.d.ts +2 -2
  111. package/dist/opa/AuthDecisionQueryClient.js +72 -102
  112. package/dist/opa/AuthDecisionQueryClient.js.map +1 -1
  113. package/dist/pgTypes.js +4 -9
  114. package/dist/pgTypes.js.map +1 -1
  115. package/dist/registry/AuthorizedRegistryClient.d.ts +4 -4
  116. package/dist/registry/AuthorizedRegistryClient.js +55 -95
  117. package/dist/registry/AuthorizedRegistryClient.js.map +1 -1
  118. package/dist/registry/RegistryClient.d.ts +2 -3
  119. package/dist/registry/RegistryClient.js +61 -78
  120. package/dist/registry/RegistryClient.js.map +1 -1
  121. package/dist/registry/TenantConsts.js +3 -6
  122. package/dist/registry/TenantConsts.js.map +1 -1
  123. package/dist/registry/model.js +1 -2
  124. package/dist/registry-manual/api.d.ts +1 -1
  125. package/dist/registry-manual/api.js +18 -7
  126. package/dist/registry-manual/api.js.map +1 -1
  127. package/dist/retry.d.ts +1 -1
  128. package/dist/retry.js +3 -9
  129. package/dist/retry.js.map +1 -1
  130. package/dist/retryBackoff.js +3 -9
  131. package/dist/retryBackoff.js.map +1 -1
  132. package/dist/runLater.js +1 -4
  133. package/dist/runLater.js.map +1 -1
  134. package/dist/session/GetUserId.d.ts +2 -2
  135. package/dist/session/GetUserId.js +10 -16
  136. package/dist/session/GetUserId.js.map +1 -1
  137. package/dist/session/GetUserSession.d.ts +1 -1
  138. package/dist/session/GetUserSession.js +6 -10
  139. package/dist/session/GetUserSession.js.map +1 -1
  140. package/dist/session/addJwtSecretFromEnvVar.js +1 -4
  141. package/dist/session/addJwtSecretFromEnvVar.js.map +1 -1
  142. package/dist/session/buildJwt.d.ts +1 -1
  143. package/dist/session/buildJwt.js +2 -5
  144. package/dist/session/buildJwt.js.map +1 -1
  145. package/dist/session/buildJwtFromReq.d.ts +1 -1
  146. package/dist/session/buildJwtFromReq.js +3 -8
  147. package/dist/session/buildJwtFromReq.js.map +1 -1
  148. package/dist/session/cookieUtils.d.ts +2 -13
  149. package/dist/session/cookieUtils.js +8 -9
  150. package/dist/session/cookieUtils.js.map +1 -1
  151. package/dist/session/destroySession.js +18 -33
  152. package/dist/session/destroySession.js.map +1 -1
  153. package/dist/session/getSessionId.js +5 -11
  154. package/dist/session/getSessionId.js.map +1 -1
  155. package/dist/tenant-api/AuthorizedTenantClient.d.ts +1 -1
  156. package/dist/tenant-api/AuthorizedTenantClient.js +22 -36
  157. package/dist/tenant-api/AuthorizedTenantClient.js.map +1 -1
  158. package/dist/tenant-api/Tenant.js +13 -5
  159. package/dist/tenant-api/Tenant.js.map +1 -1
  160. package/dist/test/JsonConnector.spec.js +56 -61
  161. package/dist/test/JsonConnector.spec.js.map +1 -1
  162. package/dist/test/JsonTransformer.spec.js +15 -19
  163. package/dist/test/JsonTransformer.spec.js.map +1 -1
  164. package/dist/test/arbitraries.d.ts +21 -21
  165. package/dist/test/arbitraries.js +85 -99
  166. package/dist/test/arbitraries.js.map +1 -1
  167. package/dist/test/aspect-templates/organization-details.d.ts +1 -4
  168. package/dist/test/aspect-templates/organization-details.js +1 -1
  169. package/dist/test/aspect-templates/organization-details.js.map +1 -1
  170. package/dist/test/buildApiClient.spec.js +81 -107
  171. package/dist/test/buildApiClient.spec.js.map +1 -1
  172. package/dist/test/buildAuthorizedTenantClient.spec.js +25 -40
  173. package/dist/test/buildAuthorizedTenantClient.spec.js.map +1 -1
  174. package/dist/test/connectors/MockExpressServer.js +9 -23
  175. package/dist/test/connectors/MockExpressServer.js.map +1 -1
  176. package/dist/test/connectors/MockRegistry.d.ts +1 -1
  177. package/dist/test/connectors/MockRegistry.js +11 -18
  178. package/dist/test/connectors/MockRegistry.js.map +1 -1
  179. package/dist/test/connectors/runConnectorTest.js +33 -55
  180. package/dist/test/connectors/runConnectorTest.js.map +1 -1
  181. package/dist/test/createMockAuthDecisionQueryClient.d.ts +4 -4
  182. package/dist/test/createMockAuthDecisionQueryClient.js +4 -9
  183. package/dist/test/createMockAuthDecisionQueryClient.js.map +1 -1
  184. package/dist/test/db/getTestDBConfig.js +1 -3
  185. package/dist/test/db/getTestDBConfig.js.map +1 -1
  186. package/dist/test/db/runMigrationSql.js +37 -58
  187. package/dist/test/db/runMigrationSql.js.map +1 -1
  188. package/dist/test/express/status.spec.js +81 -72
  189. package/dist/test/express/status.spec.js.map +1 -1
  190. package/dist/test/fakeArgv.js +6 -5
  191. package/dist/test/fakeArgv.js.map +1 -1
  192. package/dist/test/getBasePathFromUrl.spec.js +5 -10
  193. package/dist/test/getBasePathFromUrl.spec.js.map +1 -1
  194. package/dist/test/getStorageUrl.spec.js +22 -46
  195. package/dist/test/getStorageUrl.spec.js.map +1 -1
  196. package/dist/test/mockAuthApiHost.js +26 -28
  197. package/dist/test/mockAuthApiHost.js.map +1 -1
  198. package/dist/test/mockAuthorization.js +4 -10
  199. package/dist/test/mockAuthorization.js.map +1 -1
  200. package/dist/test/mockTenantDataStore.d.ts +1 -1
  201. package/dist/test/mockTenantDataStore.js +3 -5
  202. package/dist/test/mockTenantDataStore.js.map +1 -1
  203. package/dist/test/mockUserDataStore.d.ts +1 -1
  204. package/dist/test/mockUserDataStore.js +4 -6
  205. package/dist/test/mockUserDataStore.js.map +1 -1
  206. package/dist/test/registry/buildAuthorizedClient.spec.js +65 -87
  207. package/dist/test/registry/buildAuthorizedClient.spec.js.map +1 -1
  208. package/dist/test/session/buildJwt.spec.js +15 -19
  209. package/dist/test/session/buildJwt.spec.js.map +1 -1
  210. package/dist/test/session/buildJwtForRegistryEsriOpaGroupsAndOwnerTest.spec.js +6 -11
  211. package/dist/test/session/buildJwtForRegistryEsriOpaGroupsAndOwnerTest.spec.js.map +1 -1
  212. package/dist/test/session/buildJwtForRegistryEsriOpaGroupsTest.spec.js +6 -11
  213. package/dist/test/session/buildJwtForRegistryEsriOpaGroupsTest.spec.js.map +1 -1
  214. package/dist/test/session/buildJwtForRegistryEsriOpaOwnerTest.spec.js +6 -11
  215. package/dist/test/session/buildJwtForRegistryEsriOpaOwnerTest.spec.js.map +1 -1
  216. package/dist/test/testAsyncPage.spec.js +84 -105
  217. package/dist/test/testAsyncPage.spec.js.map +1 -1
  218. package/dist/test/testOpaCompileResponseParser.spec.js +192 -196
  219. package/dist/test/testOpaCompileResponseParser.spec.js.map +1 -1
  220. package/dist/test/util.js +1 -5
  221. package/dist/test/util.js.map +1 -1
  222. package/dist/unknown2Error.d.ts +2 -0
  223. package/dist/unknown2Error.js +3 -0
  224. package/dist/unknown2Error.js.map +1 -0
  225. package/dist/util/arrayToMaybe.d.ts +1 -1
  226. package/dist/util/arrayToMaybe.js +3 -6
  227. package/dist/util/arrayToMaybe.js.map +1 -1
  228. package/dist/util/cleanOrgTitle.js +1 -4
  229. package/dist/util/cleanOrgTitle.js.map +1 -1
  230. package/dist/util/escapeRegExp.js +1 -3
  231. package/dist/util/escapeRegExp.js.map +1 -1
  232. package/dist/util/getMinikubeIP.js +3 -9
  233. package/dist/util/getMinikubeIP.js.map +1 -1
  234. package/dist/util/isArray.js +1 -3
  235. package/dist/util/isArray.js.map +1 -1
  236. package/dist/util/isUuid.js +1 -3
  237. package/dist/util/isUuid.js.map +1 -1
  238. package/dist/util/unionToThrowable.d.ts +1 -1
  239. package/dist/util/unionToThrowable.js +3 -9
  240. package/dist/util/unionToThrowable.js.map +1 -1
  241. package/dist/utilityTypes.d.ts +1 -1
  242. package/dist/utilityTypes.js +1 -2
  243. package/package.json +45 -29
  244. package/dist/request.d.ts +0 -3
  245. package/dist/request.js +0 -19
  246. package/dist/request.js.map +0 -1
  247. package/dist/test/jsverify.d.ts +0 -2
  248. package/dist/test/jsverify.js +0 -8
  249. package/dist/test/jsverify.js.map +0 -1
@@ -1,21 +1,4 @@
1
- "use strict";
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 = lodash_1.default.isString(options.name) ? options.name : "";
47
- this.fullName = lodash_1.default.isString(options.fullName) ? options.fullName : "";
48
- this.isDefault = lodash_1.default.isBoolean(options.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 = lodash_1.default.isUndefined(options.value) ? true : options.value;
52
- this.expressions = lodash_1.default.isArray(options.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 = lodash_1.default.isBoolean(options.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 (((_a = this.expressions) === null || _a === void 0 ? void 0 : _a.length) &&
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
- var _a;
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
- var _a;
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(Object.assign({ name: this.name, fullName: this.fullName, isDefault: this.isDefault, value: this.value, isCompleteEvaluated: this.isCompleteEvaluated, expressions: this.expressions.map((e) => e.clone()), parser: this.parser }, options));
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 (!((_a = this === null || this === void 0 ? void 0 : this.expressions) === null || _a === void 0 ? void 0 : _a.length)) {
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 && !lodash_1.default.isUndefined(r.head.value.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 (!lodash_1.default.isArray(data) || !data.length) {
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,9 +340,8 @@ class RegoRule {
288
340
  });
289
341
  }
290
342
  }
291
- exports.RegoRule = RegoRule;
292
- exports.RegoOperators = {
293
- eq: "=",
343
+ export const RegoOperators = {
344
+ eq: "=", // --- eq & equal are different in rego but no difference for value evluation.
294
345
  equal: "=",
295
346
  neq: "!=",
296
347
  lt: "<",
@@ -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 (((_a = this === null || this === void 0 ? void 0 : this.terms) === null || _a === void 0 ? void 0 : _a.length) &&
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 (!lodash_1.default.isUndefined(value)) {
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 (lodash_1.default.isUndefined(this.value))
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 || lodash_1.default.isUndefined(this.value) ? false : true;
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 (lodash_1.default.isEmpty(expData.terms)) {
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 (lodash_1.default.isArray(expData.terms)) {
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 && ((_a = this.parts[0]) === null || _a === void 0 ? void 0 : _a.value) === "input") ||
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) => (Object.assign({}, 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(exports.RegoOperators).indexOf(this.fullRefString()) !== -1;
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 exports.RegoOperators[this.fullRefString()];
1123
+ return RegoOperators[this.fullRefString()];
1050
1124
  else
1051
1125
  return null;
1052
1126
  }
1053
1127
  }
1054
- exports.RegoRef = RegoRef;
1055
- function value2String(value) {
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
- exports.value2String = value2String;
1062
- class RegoRuleSet {
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 === null || rules === void 0 ? void 0 : rules.length) {
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 ((_a = rules === null || rules === void 0 ? void 0 : rules[0]) === null || _a === void 0 ? void 0 : _a.fullName) {
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 ((_b = rules === null || rules === void 0 ? void 0 : rules[0]) === null || _b === void 0 ? void 0 : _b.name) {
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 (!((_a = this.rules) === null || _a === void 0 ? void 0 : _a.length)) {
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 = lodash_1.default.flatMap(rules, (rule) => {
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
- constructor() {
1253
- /**
1254
- * If a warning is produced during the parsing
1255
- *
1256
- * @type {boolean}
1257
- * @memberof OpaCompileResponseParser
1258
- */
1259
- this.hasWarns = false;
1260
- /**
1261
- * Any warnings produced during the parsing
1262
- *
1263
- * @type {string[]}
1264
- * @memberof OpaCompileResponseParser
1265
- */
1266
- this.warns = [];
1267
- this.data = null;
1268
- /**
1269
- * Inital Rules parsed from result
1270
- * Only for debug purpose
1271
- *
1272
- * @type {RegoRule[]}
1273
- * @memberof OpaCompileResponseParser
1274
- */
1275
- this.originalRules = [];
1276
- /**
1277
- * Parsed, compressed & evaluated rules
1278
- *
1279
- * @type {RegoRule[]}
1280
- * @memberof OpaCompileResponseParser
1281
- */
1282
- this.rules = [];
1283
- /**
1284
- * Parsed, compressed & evaluated rule sets
1285
- *
1286
- * @type {RegoRuleSet[]}
1287
- * @memberof OpaCompileResponseParser
1288
- */
1289
- this.ruleSets = {};
1290
- this.queries = [];
1291
- /**
1292
- * A cache of all resolved rule result
1293
- *
1294
- * @type {{
1295
- * [fullName: string]: CompleteRuleResult;
1296
- * }}
1297
- * @memberof OpaCompileResponseParser
1298
- */
1299
- this.completeRuleResults = {};
1300
- /**
1301
- * The pseudo query rule name
1302
- * The parser will assign a random pseudo rule name to the query expressions you submit.
1303
- *
1304
- * @type {string}
1305
- * @memberof OpaCompileResponseParser
1306
- */
1307
- this.pseudoQueryRuleName = RegoRule.randomRuleName("default_rule_");
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 (lodash_1.default.isString(json)) {
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
- !lodash_1.default.isArray(this.data.queries) ||
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) => !(q === null || q === void 0 ? void 0 : q.length)) !== -1) {
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 (!lodash_1.default.isArray(p.rules) || !p.rules.length)
1446
+ if (!_.isArray(p.rules) || !p.rules.length)
1378
1447
  return;
1379
- const packageName = p.package && lodash_1.default.isArray(p.package.path)
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
- lodash_1.default.uniq(this.rules.map((r) => r.fullName)).forEach((fullName) => (this.ruleSets[fullName] = new RegoRuleSet(this, this.rules.filter((r) => r.fullName === fullName), fullName)));
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 _a = rule.toData(), { name, fullName } = _a, ruleData = __rest(_a, ["name", "fullName"]);
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
- exports.default = OpaCompileResponseParser;
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