@nmnmcc/ability 1.0.1 → 2.0.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/README.md +112 -69
- package/dist/Authorizer.d.ts +43 -47
- package/dist/Authorizer.d.ts.map +1 -1
- package/dist/Authorizer.js +5 -290
- package/dist/Authorizer.js.map +1 -1
- package/dist/Condition.d.ts +164 -332
- package/dist/Condition.d.ts.map +1 -1
- package/dist/Condition.js +75 -890
- package/dist/Condition.js.map +1 -1
- package/dist/Decision.d.ts +13 -13
- package/dist/Decision.d.ts.map +1 -1
- package/dist/Decision.js.map +1 -1
- package/dist/Domain.d.ts +10 -21
- package/dist/Domain.d.ts.map +1 -1
- package/dist/Domain.js +4 -62
- package/dist/Domain.js.map +1 -1
- package/dist/HttpApi.d.ts +31 -7
- package/dist/HttpApi.d.ts.map +1 -1
- package/dist/HttpApi.js +25 -8
- package/dist/HttpApi.js.map +1 -1
- package/dist/Limits.d.ts +114 -0
- package/dist/Limits.d.ts.map +1 -0
- package/dist/Limits.js +132 -0
- package/dist/Limits.js.map +1 -0
- package/dist/Policy.d.ts +271 -269
- package/dist/Policy.d.ts.map +1 -1
- package/dist/Policy.js +68 -1177
- package/dist/Policy.js.map +1 -1
- package/dist/Resource.d.ts +4 -177
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +4 -803
- package/dist/Resource.js.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +4 -5
- package/dist/internal/algebra.js +267 -0
- package/dist/internal/algebra.js.map +1 -0
- package/dist/internal/analysis.js +245 -0
- package/dist/internal/analysis.js.map +1 -0
- package/dist/internal/authorizer.d.ts +30 -0
- package/dist/internal/authorizer.d.ts.map +1 -0
- package/dist/internal/authorizer.js +221 -0
- package/dist/internal/authorizer.js.map +1 -0
- package/dist/internal/bind.js +286 -0
- package/dist/internal/bind.js.map +1 -0
- package/dist/internal/catalog.d.ts +56 -0
- package/dist/internal/catalog.d.ts.map +1 -0
- package/dist/internal/catalog.js +292 -0
- package/dist/internal/catalog.js.map +1 -0
- package/dist/internal/decide.js +166 -0
- package/dist/internal/decide.js.map +1 -0
- package/dist/internal/domain.js +32 -0
- package/dist/internal/domain.js.map +1 -0
- package/dist/internal/json.js +134 -0
- package/dist/internal/json.js.map +1 -0
- package/dist/internal/limits.d.ts +14 -0
- package/dist/internal/limits.d.ts.map +1 -0
- package/dist/internal/limits.js +43 -0
- package/dist/internal/limits.js.map +1 -0
- package/dist/internal/nodes.d.ts +121 -0
- package/dist/internal/nodes.d.ts.map +1 -0
- package/dist/internal/nodes.js +277 -0
- package/dist/internal/nodes.js.map +1 -0
- package/dist/internal/patterns.js +110 -0
- package/dist/internal/patterns.js.map +1 -0
- package/dist/internal/policy-json.js +255 -0
- package/dist/internal/policy-json.js.map +1 -0
- package/dist/internal/policy-nodes.d.ts +61 -0
- package/dist/internal/policy-nodes.d.ts.map +1 -0
- package/dist/internal/policy-nodes.js +146 -0
- package/dist/internal/policy-nodes.js.map +1 -0
- package/dist/internal/policy.d.ts +42 -0
- package/dist/internal/policy.d.ts.map +1 -0
- package/dist/internal/policy.js +124 -0
- package/dist/internal/policy.js.map +1 -0
- package/dist/internal/read.js +39 -0
- package/dist/internal/read.js.map +1 -0
- package/dist/internal/resource.js +115 -0
- package/dist/internal/resource.js.map +1 -0
- package/dist/internal/rule.d.ts +26 -0
- package/dist/internal/rule.d.ts.map +1 -0
- package/dist/internal/rule.js +93 -0
- package/dist/internal/rule.js.map +1 -0
- package/dist/internal/search.d.ts +22 -0
- package/dist/internal/search.d.ts.map +1 -0
- package/dist/internal/search.js +274 -0
- package/dist/internal/search.js.map +1 -0
- package/dist/internal/suggest.js +46 -0
- package/dist/internal/suggest.js.map +1 -0
- package/package.json +3 -4
- package/src/Authorizer.ts +67 -583
- package/src/Condition.ts +339 -2095
- package/src/Decision.ts +6 -5
- package/src/Domain.ts +12 -69
- package/src/HttpApi.ts +72 -10
- package/src/Limits.ts +132 -0
- package/src/Policy.ts +386 -2772
- package/src/Resource.ts +7 -1548
- package/src/index.ts +3 -9
- package/src/internal/algebra.ts +482 -0
- package/src/internal/analysis.ts +478 -0
- package/src/internal/authorizer.ts +418 -0
- package/src/internal/bind.ts +596 -0
- package/src/internal/catalog.ts +534 -0
- package/src/internal/decide.ts +402 -0
- package/src/internal/domain.ts +66 -0
- package/src/internal/json.ts +260 -0
- package/src/internal/limits.ts +78 -0
- package/src/internal/nodes.ts +404 -0
- package/src/internal/patterns.ts +211 -0
- package/src/internal/policy-json.ts +484 -0
- package/src/internal/policy-nodes.ts +207 -0
- package/src/internal/policy.ts +264 -0
- package/src/internal/read.ts +55 -0
- package/src/internal/resource.ts +180 -0
- package/src/internal/rule.ts +181 -0
- package/src/internal/search.ts +541 -0
- package/src/internal/suggest.ts +104 -0
- package/dist/Principal.d.ts +0 -35
- package/dist/Principal.d.ts.map +0 -1
- package/dist/Principal.js +0 -37
- package/dist/Principal.js.map +0 -1
- package/dist/Rule.d.ts +0 -275
- package/dist/Rule.d.ts.map +0 -1
- package/dist/Rule.js +0 -257
- package/dist/Rule.js.map +0 -1
- package/src/Principal.ts +0 -41
- package/src/Rule.ts +0 -683
package/dist/Condition.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import { And as And$1, Compare as Compare$1, CompareOperator as CompareOperator$1, Exists as Exists$1, False as False$1, In as In$1, Literal as Literal$1, Node, Not as Not$1, Or as Or$1, Predicate as Predicate$1, PrincipalRef as PrincipalRef$1, Scalar as Scalar$1, True as True$1, Under as Under$1 } from "./internal/nodes.js";
|
|
2
|
+
import { Example as Example$1, Satisfiability as Satisfiability$1 } from "./internal/search.js";
|
|
1
3
|
import { PathSegment } from "./Resource.js";
|
|
2
4
|
import * as Context from "effect/Context";
|
|
3
5
|
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as
|
|
6
|
+
import * as Result from "effect/Result";
|
|
5
7
|
import * as Schema from "effect/Schema";
|
|
6
|
-
import * as Data from "effect/Data";
|
|
7
|
-
import * as HashMap from "effect/HashMap";
|
|
8
8
|
import * as HashSet from "effect/HashSet";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
|
+
import * as HashMap from "effect/HashMap";
|
|
9
11
|
import * as Chunk from "effect/Chunk";
|
|
10
12
|
import * as Duration from "effect/Duration";
|
|
11
13
|
import * as BigDecimal from "effect/BigDecimal";
|
|
12
14
|
import * as Cause from "effect/Cause";
|
|
13
15
|
import * as DateTime from "effect/DateTime";
|
|
16
|
+
import * as Exit from "effect/Exit";
|
|
14
17
|
import * as Redacted from "effect/Redacted";
|
|
15
|
-
import * as Result from "effect/Result";
|
|
16
18
|
declare namespace Condition_d_exports {
|
|
17
|
-
export { And,
|
|
19
|
+
export { And, Any, Ast, Builder, Compare, CompareOperator, Condition, Encoded, EncodedOperand, ErrorOf, Example, Exists, False, FieldName, FieldPath, FieldSelector, FieldValue, In, Input, Interpreter, Literal, Not, Opaque, OpaqueOf, Operand, OperandOf, Or, PathValue, PlainCondition, Predicate, PrincipalRef, Provided, Reads, ReadsOf, Ref, Satisfiability, SatisfiableOptions, Scalar, ServicesOf, Test, True, Under, Untranslatable, always, and, andAll, builder, evaluate, evaluateSync, fields, fold, never, not, or, orAll, partial, provideContext, satisfiable, schema, simplify };
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* A value that a condition can compare.
|
|
@@ -23,7 +25,7 @@ declare namespace Condition_d_exports {
|
|
|
23
25
|
* @category models
|
|
24
26
|
* @since 0.3.0
|
|
25
27
|
*/
|
|
26
|
-
export type Scalar =
|
|
28
|
+
export type Scalar = Scalar$1;
|
|
27
29
|
/**
|
|
28
30
|
* A fixed value in a condition.
|
|
29
31
|
*
|
|
@@ -31,10 +33,7 @@ export type Scalar = string | number | boolean | null;
|
|
|
31
33
|
* @category models
|
|
32
34
|
* @since 0.3.0
|
|
33
35
|
*/
|
|
34
|
-
export
|
|
35
|
-
readonly _tag: "Literal";
|
|
36
|
-
readonly value: Scalar;
|
|
37
|
-
}
|
|
36
|
+
export type Literal = Literal$1;
|
|
38
37
|
/**
|
|
39
38
|
* A field of the principal. {@link partial} puts the value of the field in its
|
|
40
39
|
* place.
|
|
@@ -48,17 +47,12 @@ export interface Literal {
|
|
|
48
47
|
* @category models
|
|
49
48
|
* @since 0.3.0
|
|
50
49
|
*/
|
|
51
|
-
export
|
|
52
|
-
readonly _tag: "Principal";
|
|
53
|
-
readonly path: string;
|
|
54
|
-
}
|
|
50
|
+
export type PrincipalRef = PrincipalRef$1;
|
|
55
51
|
/**
|
|
56
52
|
* A field of the principal with a known value type `A`, from a principal of
|
|
57
|
-
* the type `P`. The type fields are only in the types. A
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* into a rule of a domain with another principal. With no `P`, it is `never`,
|
|
61
|
-
* and a test with the reference fits no rule.
|
|
53
|
+
* the type `P`. The type fields are only in the types. A test with the
|
|
54
|
+
* reference reads a principal of the type `P`, so it can not go into a rule
|
|
55
|
+
* of a domain with another principal.
|
|
62
56
|
*
|
|
63
57
|
* @stability stable
|
|
64
58
|
* @category models
|
|
@@ -79,7 +73,7 @@ export type Operand = Literal | PrincipalRef;
|
|
|
79
73
|
* @category models
|
|
80
74
|
* @since 0.3.0
|
|
81
75
|
*/
|
|
82
|
-
export type CompareOperator =
|
|
76
|
+
export type CompareOperator = CompareOperator$1;
|
|
83
77
|
/**
|
|
84
78
|
* Always true.
|
|
85
79
|
*
|
|
@@ -87,9 +81,7 @@ export type CompareOperator = "eq" | "ne" | "lt" | "lte" | "gt" | "gte";
|
|
|
87
81
|
* @category models
|
|
88
82
|
* @since 0.3.0
|
|
89
83
|
*/
|
|
90
|
-
export
|
|
91
|
-
readonly _tag: "True";
|
|
92
|
-
}
|
|
84
|
+
export type True = True$1;
|
|
93
85
|
/**
|
|
94
86
|
* Always false.
|
|
95
87
|
*
|
|
@@ -97,9 +89,7 @@ export interface True {
|
|
|
97
89
|
* @category models
|
|
98
90
|
* @since 0.3.0
|
|
99
91
|
*/
|
|
100
|
-
export
|
|
101
|
-
readonly _tag: "False";
|
|
102
|
-
}
|
|
92
|
+
export type False = False$1;
|
|
103
93
|
/**
|
|
104
94
|
* Compares a field with a value. A missing field has the value `null`. `lt`,
|
|
105
95
|
* `lte`, `gt` and `gte` are false when the two sides are not both numbers or
|
|
@@ -109,12 +99,7 @@ export interface False {
|
|
|
109
99
|
* @category models
|
|
110
100
|
* @since 0.3.0
|
|
111
101
|
*/
|
|
112
|
-
export
|
|
113
|
-
readonly _tag: "Compare";
|
|
114
|
-
readonly op: CompareOperator;
|
|
115
|
-
readonly field: string;
|
|
116
|
-
readonly value: Operand;
|
|
117
|
-
}
|
|
102
|
+
export type Compare = Compare$1;
|
|
118
103
|
/**
|
|
119
104
|
* True when a field is equal to one of the values.
|
|
120
105
|
*
|
|
@@ -122,11 +107,7 @@ export interface Compare {
|
|
|
122
107
|
* @category models
|
|
123
108
|
* @since 0.3.0
|
|
124
109
|
*/
|
|
125
|
-
export
|
|
126
|
-
readonly _tag: "In";
|
|
127
|
-
readonly field: string;
|
|
128
|
-
readonly values: ReadonlyArray<Operand>;
|
|
129
|
-
}
|
|
110
|
+
export type In = In$1;
|
|
130
111
|
/**
|
|
131
112
|
* True when a field is not `null` and not missing.
|
|
132
113
|
*
|
|
@@ -134,10 +115,7 @@ export interface In {
|
|
|
134
115
|
* @category models
|
|
135
116
|
* @since 0.3.0
|
|
136
117
|
*/
|
|
137
|
-
export
|
|
138
|
-
readonly _tag: "Exists";
|
|
139
|
-
readonly field: string;
|
|
140
|
-
}
|
|
118
|
+
export type Exists = Exists$1;
|
|
141
119
|
/**
|
|
142
120
|
* True when the path of the resource starts with the prefix. A resource with
|
|
143
121
|
* no path is never under a prefix.
|
|
@@ -146,37 +124,25 @@ export interface Exists {
|
|
|
146
124
|
* @category models
|
|
147
125
|
* @since 0.3.0
|
|
148
126
|
*/
|
|
149
|
-
export
|
|
150
|
-
readonly _tag: "Under";
|
|
151
|
-
readonly prefix: ReadonlyArray<Operand>;
|
|
152
|
-
}
|
|
127
|
+
export type Under = Under$1;
|
|
153
128
|
/**
|
|
154
129
|
* @stability stable
|
|
155
130
|
* @category models
|
|
156
131
|
* @since 0.3.0
|
|
157
132
|
*/
|
|
158
|
-
export
|
|
159
|
-
readonly _tag: "And";
|
|
160
|
-
readonly conditions: ReadonlyArray<Ast>;
|
|
161
|
-
}
|
|
133
|
+
export type And = And$1;
|
|
162
134
|
/**
|
|
163
135
|
* @stability stable
|
|
164
136
|
* @category models
|
|
165
137
|
* @since 0.3.0
|
|
166
138
|
*/
|
|
167
|
-
export
|
|
168
|
-
readonly _tag: "Or";
|
|
169
|
-
readonly conditions: ReadonlyArray<Ast>;
|
|
170
|
-
}
|
|
139
|
+
export type Or = Or$1;
|
|
171
140
|
/**
|
|
172
141
|
* @stability stable
|
|
173
142
|
* @category models
|
|
174
143
|
* @since 0.3.0
|
|
175
144
|
*/
|
|
176
|
-
export
|
|
177
|
-
readonly _tag: "Not";
|
|
178
|
-
readonly condition: Ast;
|
|
179
|
-
}
|
|
145
|
+
export type Not = Not$1;
|
|
180
146
|
/**
|
|
181
147
|
* A test that runs an `Effect`. It can not become JSON or a query.
|
|
182
148
|
*
|
|
@@ -184,143 +150,87 @@ export interface Not {
|
|
|
184
150
|
* @category models
|
|
185
151
|
* @since 0.3.0
|
|
186
152
|
*/
|
|
187
|
-
export
|
|
188
|
-
readonly _tag: "Predicate";
|
|
189
|
-
readonly name: string;
|
|
190
|
-
run(value: any, principal: any): Effect.Effect<boolean, unknown, unknown>;
|
|
191
|
-
}
|
|
153
|
+
export type Predicate = Predicate$1;
|
|
192
154
|
/**
|
|
193
|
-
* The nodes of a condition, without types.
|
|
155
|
+
* The nodes of a condition, without types. Each node is a class, and only the
|
|
156
|
+
* builder, the functions of this module and the Schema make one. So a plain
|
|
157
|
+
* object, or a spread of a node, is not a node.
|
|
194
158
|
*
|
|
195
159
|
* @stability stable
|
|
196
160
|
* @category models
|
|
197
161
|
* @since 0.3.0
|
|
198
162
|
*/
|
|
199
|
-
export type Ast =
|
|
163
|
+
export type Ast = Node;
|
|
200
164
|
/**
|
|
201
|
-
* The
|
|
165
|
+
* The mark of a condition with a predicate. `E` and `R` are the error type
|
|
166
|
+
* and the service type of its predicates.
|
|
202
167
|
*
|
|
203
168
|
* @stability stable
|
|
204
169
|
* @category models
|
|
205
|
-
* @since 0.
|
|
206
|
-
*/
|
|
207
|
-
export type Opaque = "Opaque";
|
|
208
|
-
/**
|
|
209
|
-
* @stability stable
|
|
210
|
-
* @category models
|
|
211
|
-
* @since 0.3.0
|
|
170
|
+
* @since 2.0.0
|
|
212
171
|
*/
|
|
213
|
-
export interface
|
|
214
|
-
readonly
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* What the predicates of a condition read: a resource value of the type `V`
|
|
220
|
-
* and a principal of the type `P`. It is only in the types.
|
|
221
|
-
*
|
|
222
|
-
* @stability stable
|
|
223
|
-
* @category models
|
|
224
|
-
* @since 1.0.0
|
|
225
|
-
*/
|
|
226
|
-
export interface Reads<V, P> {
|
|
227
|
-
readonly value: V;
|
|
228
|
-
readonly principal: P;
|
|
172
|
+
export interface Opaque<out E = never, out R = never> {
|
|
173
|
+
readonly "~Opaque": {
|
|
174
|
+
readonly E: E;
|
|
175
|
+
readonly R: R;
|
|
176
|
+
};
|
|
229
177
|
}
|
|
230
178
|
/**
|
|
231
|
-
* The type
|
|
179
|
+
* The error type of the predicates of a mark `X`. A mark that may be
|
|
180
|
+
* anything, as `unknown`, may have any error.
|
|
232
181
|
*
|
|
233
182
|
* @stability stable
|
|
234
|
-
* @category
|
|
235
|
-
* @since
|
|
183
|
+
* @category utility types
|
|
184
|
+
* @since 2.0.0
|
|
236
185
|
*/
|
|
237
|
-
export
|
|
238
|
-
readonly "~Condition": Variance<E, R, O>;
|
|
239
|
-
/** `I` is what the predicates read. See {@link Reads}. */
|
|
240
|
-
readonly "~Reads": (reads: I) => void;
|
|
241
|
-
}
|
|
186
|
+
export type ErrorOf<X> = unknown extends X ? unknown : X extends Opaque<infer E, infer _R> ? E : never;
|
|
242
187
|
/**
|
|
243
|
-
*
|
|
188
|
+
* The service type of the predicates of a mark `X`. A mark that may be
|
|
189
|
+
* anything, as `unknown`, may need any service.
|
|
244
190
|
*
|
|
245
191
|
* @stability stable
|
|
246
|
-
* @category
|
|
247
|
-
* @since
|
|
192
|
+
* @category utility types
|
|
193
|
+
* @since 2.0.0
|
|
248
194
|
*/
|
|
249
|
-
export
|
|
250
|
-
readonly _tag: "And";
|
|
251
|
-
readonly conditions: ReadonlyArray<Condition<E, R, O, I>>;
|
|
252
|
-
}
|
|
195
|
+
export type ServicesOf<X> = unknown extends X ? unknown : X extends Opaque<infer _E, infer R> ? R : never;
|
|
253
196
|
/**
|
|
254
|
-
*
|
|
197
|
+
* The mark `X` with no services.
|
|
255
198
|
*
|
|
256
199
|
* @stability stable
|
|
257
|
-
* @category
|
|
258
|
-
* @since
|
|
200
|
+
* @category utility types
|
|
201
|
+
* @since 2.0.0
|
|
259
202
|
*/
|
|
260
|
-
export
|
|
261
|
-
readonly _tag: "Or";
|
|
262
|
-
readonly conditions: ReadonlyArray<Condition<E, R, O, I>>;
|
|
263
|
-
}
|
|
203
|
+
export type Provided<X> = unknown extends X ? Opaque<unknown> : X extends Opaque<infer E, infer _R> ? Opaque<E> : never;
|
|
264
204
|
/**
|
|
265
|
-
*
|
|
205
|
+
* What the predicates of a condition read: a resource value of the type `V`
|
|
206
|
+
* and a principal of the type `P`. It is only in the types.
|
|
266
207
|
*
|
|
267
208
|
* @stability stable
|
|
268
209
|
* @category models
|
|
269
210
|
* @since 1.0.0
|
|
270
211
|
*/
|
|
271
|
-
export interface
|
|
272
|
-
readonly
|
|
273
|
-
readonly
|
|
212
|
+
export interface Reads<V, P> {
|
|
213
|
+
readonly value: V;
|
|
214
|
+
readonly principal: P;
|
|
274
215
|
}
|
|
275
216
|
/**
|
|
276
|
-
* A
|
|
277
|
-
* the
|
|
278
|
-
*
|
|
217
|
+
* A condition. `I` is what its tests read: see {@link Reads}. `X` is
|
|
218
|
+
* {@link Opaque} when the condition has a predicate, and `never` when it is
|
|
219
|
+
* plain data. A plain condition can become JSON or a query.
|
|
279
220
|
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
|
|
284
|
-
export interface PredicateCondition<E, R, O, I> extends Marks<E, R, O, I> {
|
|
285
|
-
readonly _tag: "Predicate";
|
|
286
|
-
readonly name: string;
|
|
287
|
-
/**
|
|
288
|
-
* The test. Its inputs have the type `never`, so it can not be called with
|
|
289
|
-
* a value that it does not read. Use {@link evaluate}, which checks the
|
|
290
|
-
* input against `I`.
|
|
291
|
-
*/
|
|
292
|
-
readonly run: PredicateRun<E, R, I>;
|
|
293
|
-
readonly "~Predicate": O;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* The test of a predicate node. The type field `"~Reads"` is only in the
|
|
297
|
-
* types. It ties the test to what it reads, so the test of one predicate can
|
|
298
|
-
* not go into a node that says it reads other values.
|
|
221
|
+
* The two type fields are only in the types. `I` goes into a function as an
|
|
222
|
+
* input, so a condition that reads a `Post` does not fit a rule for a
|
|
223
|
+
* `Comment`. `X` comes out of a function, so a plain condition fits where a
|
|
224
|
+
* condition with predicates may go.
|
|
299
225
|
*
|
|
300
226
|
* @stability stable
|
|
301
227
|
* @category models
|
|
302
|
-
* @since
|
|
228
|
+
* @since 0.3.0
|
|
303
229
|
*/
|
|
304
|
-
export type
|
|
230
|
+
export type Condition<I = unknown, X = never> = Ast & {
|
|
305
231
|
readonly "~Reads": (reads: I) => void;
|
|
232
|
+
readonly "~Opaque": () => X;
|
|
306
233
|
};
|
|
307
|
-
/**
|
|
308
|
-
* A condition. `E` and `R` are the error type and the service type of its
|
|
309
|
-
* predicates. `O` is {@link Opaque} when the condition has a predicate, and
|
|
310
|
-
* `never` when it is plain data. `I` is what its predicates read. See
|
|
311
|
-
* {@link Reads}.
|
|
312
|
-
*
|
|
313
|
-
* The type fields are only in the types. A plain node made by hand does not
|
|
314
|
-
* have them, so it is not a condition. Use the builder. Each child of a node
|
|
315
|
-
* is a condition with the same types, so a node can not hide the types of a
|
|
316
|
-
* predicate inside it. A predicate is a condition only when `O` is
|
|
317
|
-
* {@link Opaque}.
|
|
318
|
-
*
|
|
319
|
-
* @stability stable
|
|
320
|
-
* @category models
|
|
321
|
-
* @since 0.3.0
|
|
322
|
-
*/
|
|
323
|
-
export type Condition<E = never, R = never, O = never, I = unknown> = ((True | False | Compare | In | Exists | Under) & Marks<E, R, O, I>) | AndCondition<E, R, O, I> | OrCondition<E, R, O, I> | NotCondition<E, R, O, I> | PredicateCondition<E, R, O, I>;
|
|
324
234
|
/**
|
|
325
235
|
* Any condition.
|
|
326
236
|
*
|
|
@@ -328,30 +238,10 @@ export type Condition<E = never, R = never, O = never, I = unknown> = ((True | F
|
|
|
328
238
|
* @category models
|
|
329
239
|
* @since 0.3.0
|
|
330
240
|
*/
|
|
331
|
-
export type Any = Condition<any, any
|
|
332
|
-
/**
|
|
333
|
-
* The error type of a condition.
|
|
334
|
-
*
|
|
335
|
-
* @stability stable
|
|
336
|
-
* @category utility types
|
|
337
|
-
* @since 0.3.0
|
|
338
|
-
*/
|
|
339
|
-
export type Error<C> = C extends {
|
|
340
|
-
readonly "~Condition"?: Variance<infer E, infer _R, infer _O>;
|
|
341
|
-
} ? E : never;
|
|
342
|
-
/**
|
|
343
|
-
* The service type of a condition.
|
|
344
|
-
*
|
|
345
|
-
* @stability stable
|
|
346
|
-
* @category utility types
|
|
347
|
-
* @since 0.3.0
|
|
348
|
-
*/
|
|
349
|
-
export type Services<C> = C extends {
|
|
350
|
-
readonly "~Condition"?: Variance<infer _E, infer R, infer _O>;
|
|
351
|
-
} ? R : never;
|
|
241
|
+
export type Any = Condition<any, any>;
|
|
352
242
|
/**
|
|
353
|
-
* What the
|
|
354
|
-
*
|
|
243
|
+
* What the tests of a condition read. For a union of conditions, it is what
|
|
244
|
+
* all of them read.
|
|
355
245
|
*
|
|
356
246
|
* @stability stable
|
|
357
247
|
* @category utility types
|
|
@@ -361,41 +251,32 @@ export type ReadsOf<C> = [C] extends [{
|
|
|
361
251
|
readonly "~Reads": (reads: infer I) => void;
|
|
362
252
|
}] ? I : unknown;
|
|
363
253
|
/**
|
|
364
|
-
*
|
|
365
|
-
* its children has them too. A node made with a spread may keep the type
|
|
366
|
-
* fields of another node, and then it is `never`, so the call stops.
|
|
367
|
-
*
|
|
368
|
-
* @stability stable
|
|
369
|
-
* @category utility types
|
|
370
|
-
* @since 1.0.0
|
|
371
|
-
*/
|
|
372
|
-
export type Checked<C> = [NotChecked<C>] extends [never] ? unknown : never;
|
|
373
|
-
/**
|
|
374
|
-
* The members of a union of conditions that do not fit their own type fields.
|
|
375
|
-
* Each member is checked alone, so a good member does not hide a bad one.
|
|
376
|
-
*/
|
|
377
|
-
type NotChecked<C> = C extends Condition<Error<C>, Services<C>, OpaqueOf<C>, ReadsOf<C>> ? never : C;
|
|
378
|
-
/** Each condition, checked with {@link Checked}. */
|
|
379
|
-
type Consistent<Cs extends ReadonlyArray<Any>> = { readonly [K in keyof Cs]: Cs[K] & Checked<Cs[K]>; };
|
|
380
|
-
/**
|
|
381
|
-
* {@link Opaque} when a condition has a predicate.
|
|
254
|
+
* The mark of a condition: {@link Opaque} when it has a predicate.
|
|
382
255
|
*
|
|
383
256
|
* @stability stable
|
|
384
257
|
* @category utility types
|
|
385
258
|
* @since 0.3.0
|
|
386
259
|
*/
|
|
387
260
|
export type OpaqueOf<C> = C extends {
|
|
388
|
-
readonly "~
|
|
389
|
-
} ?
|
|
261
|
+
readonly "~Opaque": () => infer X;
|
|
262
|
+
} ? X : never;
|
|
390
263
|
type Leaf = string | number | boolean | bigint | symbol | null | undefined;
|
|
391
264
|
/**
|
|
392
265
|
* Values of a class that keeps its data inside. A path does not go into them,
|
|
393
266
|
* as in the field paths of a resource, so a field with such a value is one
|
|
394
267
|
* field. A condition can test only if it exists.
|
|
395
268
|
*/
|
|
396
|
-
type Whole = ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | HashMap.HashMap<unknown, unknown> | HashSet.HashSet<unknown> | Date | URL | Uint8Array | Option.Option<unknown> | BigDecimal.BigDecimal | Duration.Duration | DateTime.DateTime | Redacted.Redacted<unknown> | Chunk.Chunk<unknown> | Cause.Cause<unknown> | Result.Result<unknown, unknown> | File | FormData | RegExp;
|
|
269
|
+
type Whole = ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | HashMap.HashMap<unknown, unknown> | HashSet.HashSet<unknown> | Date | URL | Uint8Array | Option.Option<unknown> | BigDecimal.BigDecimal | Duration.Duration | DateTime.DateTime | Redacted.Redacted<unknown> | Chunk.Chunk<unknown> | Cause.Cause<unknown> | Result.Result<unknown, unknown> | Exit.Exit<unknown, unknown> | File | FormData | RegExp | URLSearchParams;
|
|
397
270
|
type PreviousDepth = [never, 0, 1, 2, 3];
|
|
398
|
-
type FieldPathInternal<T, Depth extends number, Arrays extends boolean> = [Depth] extends [never] ? never : { [K in keyof T & string]-?:
|
|
271
|
+
type FieldPathInternal<T, Depth extends number, Arrays extends boolean, Parents extends boolean = false> = [Depth] extends [never] ? never : { [K in keyof T & string]-?: PathsOf<K, NonNullable<T[K]>, Depth, Arrays, Parents>; }[keyof T & string];
|
|
272
|
+
/**
|
|
273
|
+
* The paths of one field `K` with the values `V`. Each kind of value in `V`
|
|
274
|
+
* gives its own paths, so a field that holds a string or a struct is a field,
|
|
275
|
+
* and the fields of the struct are fields too. A function is no field.
|
|
276
|
+
*/
|
|
277
|
+
type PathsOf<K extends string, V, Depth extends number, Arrays extends boolean, Parents extends boolean> = ([V] extends [never] ? K : never) | ([Extract<V, Leaf | Whole>] extends [never] ? never : K) | ([Extract<V, ReadonlyArray<unknown>>] extends [never] ? never : Arrays extends true ? K : never) | ObjectPaths<K, Exclude<V, Leaf | Whole | Function | ReadonlyArray<unknown>>, Depth, Arrays, Parents>;
|
|
278
|
+
/** The paths of a field `K` that holds the objects `O`, and of the fields below. */
|
|
279
|
+
type ObjectPaths<K extends string, O, Depth extends number, Arrays extends boolean, Parents extends boolean> = [O] extends [never] ? never : (Parents extends true ? K : Arrays extends true ? string extends keyof O ? K : never : never) | `${K}.${FieldPathInternal<O, PreviousDepth[Depth], Arrays, Parents>}`;
|
|
399
280
|
/**
|
|
400
281
|
* The paths of the fields of `T` that hold one value, with dots for nested
|
|
401
282
|
* fields. Arrays are left out. A map, a set, a date, a URL, a byte array, an
|
|
@@ -420,6 +301,16 @@ export type FieldPath<T> = [T] extends [object] ? FieldPathInternal<T, 4, false>
|
|
|
420
301
|
* @since 1.0.0
|
|
421
302
|
*/
|
|
422
303
|
export type FieldSelector<T> = [T] extends [object] ? FieldPathInternal<T, 4, true> : never;
|
|
304
|
+
/**
|
|
305
|
+
* The names that the `fields` of a rule may have: the paths of
|
|
306
|
+
* {@link FieldSelector}, and the paths of the structs above them. A name of a
|
|
307
|
+
* struct covers the fields below it.
|
|
308
|
+
*
|
|
309
|
+
* @stability stable
|
|
310
|
+
* @category utility types
|
|
311
|
+
* @since 2.0.0
|
|
312
|
+
*/
|
|
313
|
+
export type FieldName<T> = [T] extends [object] ? FieldPathInternal<T, 4, true, true> : never;
|
|
423
314
|
/**
|
|
424
315
|
* The value type that fits every field in `F`. For one field, it is the type
|
|
425
316
|
* of the field. For a union of fields, it is the values that each of them can
|
|
@@ -463,7 +354,7 @@ type OrderedPath<T> = { [F in FieldPath<T>]: Exclude<PathValue<T, F>, null> exte
|
|
|
463
354
|
* @category models
|
|
464
355
|
* @since 1.0.0
|
|
465
356
|
*/
|
|
466
|
-
export type Test<Value, P = unknown> = Condition<
|
|
357
|
+
export type Test<Value, P = unknown> = Condition<Reads<Value, P>>;
|
|
467
358
|
/**
|
|
468
359
|
* The principal type that a test reads: the principal of each field of the
|
|
469
360
|
* principal in the values `V`, and `unknown` when there is none. A reference
|
|
@@ -500,14 +391,14 @@ export interface Builder<Data, Value, P> {
|
|
|
500
391
|
* {@link Scalar} type.
|
|
501
392
|
*/
|
|
502
393
|
readonly principal: <const F extends ScalarPath<P>>(field: F) => Ref<PathValue<P, F>, P>;
|
|
503
|
-
readonly and: <const Cs extends ReadonlyArray<Any>>(...conditions:
|
|
504
|
-
readonly or: <const Cs extends ReadonlyArray<Any>>(...conditions:
|
|
505
|
-
readonly not: <C extends Any>(condition: C
|
|
394
|
+
readonly and: <const Cs extends ReadonlyArray<Any>>(...conditions: Cs) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>>;
|
|
395
|
+
readonly or: <const Cs extends ReadonlyArray<Any>>(...conditions: Cs) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>>;
|
|
396
|
+
readonly not: <C extends Any>(condition: C) => Condition<ReadsOf<C>, OpaqueOf<C>>;
|
|
506
397
|
/**
|
|
507
398
|
* A test that runs any code. It may give a boolean or an `Effect`. A
|
|
508
399
|
* condition with a predicate can not become JSON or a query.
|
|
509
400
|
*/
|
|
510
|
-
readonly predicate: <E = never, R = never>(name: string, test: (value: Value, principal: P) => boolean | Effect.Effect<boolean, E, R>) => Condition<
|
|
401
|
+
readonly predicate: <E = never, R = never>(name: string, test: (value: Value, principal: P) => boolean | Effect.Effect<boolean, E, R>) => Condition<Reads<Value, P>, Opaque<E, R>>;
|
|
511
402
|
}
|
|
512
403
|
/**
|
|
513
404
|
* Makes a builder. Rules give you a builder with the right types, so you do not
|
|
@@ -541,7 +432,7 @@ export declare const never: Condition;
|
|
|
541
432
|
* @category combinators
|
|
542
433
|
* @since 0.3.0
|
|
543
434
|
*/
|
|
544
|
-
export declare const and: <const Cs extends ReadonlyArray<Any>>(...conditions:
|
|
435
|
+
export declare const and: <const Cs extends ReadonlyArray<Any>>(...conditions: Cs) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>>;
|
|
545
436
|
/**
|
|
546
437
|
* The same as {@link and}, for a list of conditions of one type. Use it for a
|
|
547
438
|
* long list: a function call may take only so many arguments.
|
|
@@ -550,7 +441,7 @@ export declare const and: <const Cs extends ReadonlyArray<Any>>(...conditions: C
|
|
|
550
441
|
* @category combinators
|
|
551
442
|
* @since 1.0.0
|
|
552
443
|
*/
|
|
553
|
-
export declare const andAll: <C extends Any>(conditions: ReadonlyArray<C
|
|
444
|
+
export declare const andAll: <C extends Any>(conditions: ReadonlyArray<C>) => Condition<ReadsOf<C>, OpaqueOf<C>>;
|
|
554
445
|
/**
|
|
555
446
|
* The same as {@link or}, for a list of conditions of one type. Use it for a
|
|
556
447
|
* long list: a function call may take only so many arguments.
|
|
@@ -559,7 +450,7 @@ export declare const andAll: <C extends Any>(conditions: ReadonlyArray<C & Check
|
|
|
559
450
|
* @category combinators
|
|
560
451
|
* @since 1.0.0
|
|
561
452
|
*/
|
|
562
|
-
export declare const orAll: <C extends Any>(conditions: ReadonlyArray<C
|
|
453
|
+
export declare const orAll: <C extends Any>(conditions: ReadonlyArray<C>) => Condition<ReadsOf<C>, OpaqueOf<C>>;
|
|
563
454
|
/**
|
|
564
455
|
* True when one of the conditions is true. With no conditions, it is false.
|
|
565
456
|
*
|
|
@@ -567,13 +458,13 @@ export declare const orAll: <C extends Any>(conditions: ReadonlyArray<C & Checke
|
|
|
567
458
|
* @category combinators
|
|
568
459
|
* @since 0.3.0
|
|
569
460
|
*/
|
|
570
|
-
export declare const or: <const Cs extends ReadonlyArray<Any>>(...conditions:
|
|
461
|
+
export declare const or: <const Cs extends ReadonlyArray<Any>>(...conditions: Cs) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>>;
|
|
571
462
|
/**
|
|
572
463
|
* @stability stable
|
|
573
464
|
* @category combinators
|
|
574
465
|
* @since 0.3.0
|
|
575
466
|
*/
|
|
576
|
-
export declare const not: <C extends Any>(condition: C
|
|
467
|
+
export declare const not: <C extends Any>(condition: C) => Condition<ReadsOf<C>, OpaqueOf<C>>;
|
|
577
468
|
/**
|
|
578
469
|
* The data that a condition needs for a test.
|
|
579
470
|
*
|
|
@@ -592,14 +483,6 @@ export interface Input {
|
|
|
592
483
|
/** The path of the resource. Without it, `Under` is false. */
|
|
593
484
|
readonly path?: ReadonlyArray<PathSegment> | undefined;
|
|
594
485
|
}
|
|
595
|
-
/**
|
|
596
|
-
* True when a condition has a {@link Predicate}.
|
|
597
|
-
*
|
|
598
|
-
* @stability stable
|
|
599
|
-
* @category predicates
|
|
600
|
-
* @since 1.0.0
|
|
601
|
-
*/
|
|
602
|
-
export declare const hasPredicate: (condition: Ast) => boolean;
|
|
603
486
|
/**
|
|
604
487
|
* Gives the services in `context` to every predicate of a condition, so the
|
|
605
488
|
* condition needs no services when it runs.
|
|
@@ -609,8 +492,8 @@ export declare const hasPredicate: (condition: Ast) => boolean;
|
|
|
609
492
|
* @since 1.0.0
|
|
610
493
|
*/
|
|
611
494
|
export declare const provideContext: {
|
|
612
|
-
<R>(context: Context.Context<R>): <
|
|
613
|
-
<
|
|
495
|
+
<R>(context: Context.Context<R>): <I, X>(condition: Condition<I, X> & ([ServicesOf<X>] extends [R] ? unknown : never)) => Condition<I, Provided<X>>;
|
|
496
|
+
<I, X>(condition: Condition<I, X>, context: Context.Context<ServicesOf<X>>): Condition<I, Provided<X>>;
|
|
614
497
|
};
|
|
615
498
|
/**
|
|
616
499
|
* The input of {@link evaluate} that the predicates of a condition need: a
|
|
@@ -621,11 +504,6 @@ type ReadsInput<I> = I extends Reads<infer V, infer P> ? {
|
|
|
621
504
|
} & (unknown extends P ? unknown : {
|
|
622
505
|
readonly principal: P;
|
|
623
506
|
}) : unknown;
|
|
624
|
-
/**
|
|
625
|
-
* `unknown` when `In` gives what `I` reads, and `never` when it does not. For
|
|
626
|
-
* a union, each member must give it, so the test is not split over the union.
|
|
627
|
-
*/
|
|
628
|
-
type ReadsFrom<I, In> = [In] extends [ReadsInput<I>] ? unknown : never;
|
|
629
507
|
/**
|
|
630
508
|
* Tests a condition on a value. A predicate may fail with its error. When the
|
|
631
509
|
* condition has a predicate, the input must have the value and the principal
|
|
@@ -635,10 +513,7 @@ type ReadsFrom<I, In> = [In] extends [ReadsInput<I>] ? unknown : never;
|
|
|
635
513
|
* @category evaluation
|
|
636
514
|
* @since 0.3.0
|
|
637
515
|
*/
|
|
638
|
-
export declare const evaluate:
|
|
639
|
-
<In extends Input>(input: In): <E, R, O, I>(condition: Condition<E, R, O, I> & ReadsFrom<I, In>) => Effect.Effect<boolean, E, R>;
|
|
640
|
-
<E, R, O, I, In extends Input>(condition: Condition<E, R, O, I>, input: In & ReadsInput<I>): Effect.Effect<boolean, E, R>;
|
|
641
|
-
};
|
|
516
|
+
export declare const evaluate: <I, X, In extends Input>(condition: Condition<I, X>, input: In & ReadsInput<I>) => Effect.Effect<boolean, ErrorOf<X>, ServicesOf<X>>;
|
|
642
517
|
/**
|
|
643
518
|
* Tests a condition with no predicate on a value, at once.
|
|
644
519
|
*
|
|
@@ -646,31 +521,17 @@ export declare const evaluate: {
|
|
|
646
521
|
* @category evaluation
|
|
647
522
|
* @since 0.3.0
|
|
648
523
|
*/
|
|
649
|
-
export declare const evaluateSync:
|
|
650
|
-
<In extends Input>(input: In): <I>(condition: Condition<never, never, never, I> & ReadsFrom<I, In>) => boolean;
|
|
651
|
-
<I, In extends Input>(condition: Condition<never, never, never, I>, input: In & ReadsInput<I>): boolean;
|
|
652
|
-
};
|
|
524
|
+
export declare const evaluateSync: <I, In extends Input>(condition: Condition<I>, input: In & ReadsInput<I>) => boolean;
|
|
653
525
|
/**
|
|
654
526
|
* Makes a condition smaller without a change to its meaning. It removes `True`
|
|
655
527
|
* and `False` from `And` and `Or`, joins nested `And` and `Or` nodes, and
|
|
656
|
-
* removes double `Not` nodes.
|
|
528
|
+
* removes double `Not` nodes and copies of a child.
|
|
657
529
|
*
|
|
658
530
|
* @stability stable
|
|
659
531
|
* @category evaluation
|
|
660
532
|
* @since 0.3.0
|
|
661
533
|
*/
|
|
662
|
-
export declare const simplify: <
|
|
663
|
-
/**
|
|
664
|
-
* Makes a {@link simplify} function that keeps its work for the parts it has
|
|
665
|
-
* seen. Use one for many calls on conditions that share parts, such as the
|
|
666
|
-
* steps of one residual condition. Do not keep it for long: it keeps every
|
|
667
|
-
* part that it has seen.
|
|
668
|
-
*
|
|
669
|
-
* @stability stable
|
|
670
|
-
* @category evaluation
|
|
671
|
-
* @since 1.0.0
|
|
672
|
-
*/
|
|
673
|
-
export declare const simplifier: () => (<E, R, O, I>(condition: Condition<E, R, O, I>) => Condition<E, R, O, I>);
|
|
534
|
+
export declare const simplify: <I, X>(condition: Condition<I, X>) => Condition<I, X>;
|
|
674
535
|
interface PartialInput {
|
|
675
536
|
readonly principal?: object | undefined;
|
|
676
537
|
readonly path?: ReadonlyArray<PathSegment> | undefined;
|
|
@@ -683,8 +544,6 @@ interface PartialInput {
|
|
|
683
544
|
type PrincipalInput<I> = I extends Reads<infer _V, infer P> ? unknown extends P ? unknown : {
|
|
684
545
|
readonly principal: P;
|
|
685
546
|
} : unknown;
|
|
686
|
-
/** `unknown` when `In` gives what `I` reads, and `never` when it does not. */
|
|
687
|
-
type PrincipalFrom<I, In> = [In] extends [PrincipalInput<I>] ? unknown : never;
|
|
688
547
|
/** What a condition reads after {@link partial}: the value, and no principal. */
|
|
689
548
|
type Bound<I> = I extends Reads<infer V, infer _P> ? Reads<V, unknown> : I;
|
|
690
549
|
/**
|
|
@@ -697,10 +556,7 @@ type Bound<I> = I extends Reads<infer V, infer _P> ? Reads<V, unknown> : I;
|
|
|
697
556
|
* @category evaluation
|
|
698
557
|
* @since 0.3.0
|
|
699
558
|
*/
|
|
700
|
-
export declare const partial:
|
|
701
|
-
<In extends PartialInput>(input: In): <E, R, O, I>(condition: Condition<E, R, O, I> & PrincipalFrom<I, In>) => Condition<E, R, O, Bound<I>>;
|
|
702
|
-
<E, R, O, I>(condition: Condition<E, R, O, I>, input: PartialInput & PrincipalInput<I>): Condition<E, R, O, Bound<I>>;
|
|
703
|
-
};
|
|
559
|
+
export declare const partial: <I, X>(condition: Condition<I, X>, input: PartialInput & PrincipalInput<I>) => Condition<Bound<I>, X>;
|
|
704
560
|
/**
|
|
705
561
|
* The functions that change each node of a condition into another form, such
|
|
706
562
|
* as a database query.
|
|
@@ -746,7 +602,7 @@ export declare const fold: {
|
|
|
746
602
|
<A>(condition: Any, interpreter: Interpreter<A>): Effect.Effect<A, Untranslatable>;
|
|
747
603
|
};
|
|
748
604
|
/**
|
|
749
|
-
* The fields that a condition uses.
|
|
605
|
+
* The fields that a condition uses, in the order that they first come.
|
|
750
606
|
*
|
|
751
607
|
* @stability stable
|
|
752
608
|
* @category getters
|
|
@@ -762,30 +618,19 @@ export declare const fields: (condition: Ast) => ReadonlyArray<string>;
|
|
|
762
618
|
* @category models
|
|
763
619
|
* @since 1.0.0
|
|
764
620
|
*/
|
|
765
|
-
export
|
|
766
|
-
readonly [field: string]: unknown;
|
|
767
|
-
}
|
|
621
|
+
export type Example = Example$1;
|
|
768
622
|
/**
|
|
769
623
|
* The answer of {@link satisfiable}:
|
|
770
624
|
* - `Satisfiable`: some value makes the condition true. `example` is one.
|
|
771
625
|
* - `Unsatisfiable`: no value makes the condition true.
|
|
772
|
-
* - `Unknown`: the search can not say. The condition has a predicate,
|
|
773
|
-
* search went past its budget
|
|
774
|
-
* together, as below a union or a field that may be missing.
|
|
626
|
+
* - `Unknown`: the search can not say. The condition has a predicate, or
|
|
627
|
+
* the search went past its budget.
|
|
775
628
|
*
|
|
776
629
|
* @stability stable
|
|
777
630
|
* @category models
|
|
778
631
|
* @since 1.0.0
|
|
779
632
|
*/
|
|
780
|
-
export type Satisfiability =
|
|
781
|
-
Satisfiable: {
|
|
782
|
-
readonly example: Example;
|
|
783
|
-
};
|
|
784
|
-
Unsatisfiable: {};
|
|
785
|
-
Unknown: {
|
|
786
|
-
readonly reason: "predicate" | "budget" | "schema";
|
|
787
|
-
};
|
|
788
|
-
}>;
|
|
633
|
+
export type Satisfiability = Satisfiability$1;
|
|
789
634
|
/**
|
|
790
635
|
* The options of {@link satisfiable}.
|
|
791
636
|
*
|
|
@@ -795,11 +640,11 @@ export type Satisfiability = Data.TaggedEnum<{
|
|
|
795
640
|
*/
|
|
796
641
|
export interface SatisfiableOptions {
|
|
797
642
|
/**
|
|
798
|
-
* The Schema of the values.
|
|
799
|
-
* it, a field may have any value.
|
|
643
|
+
* The Schema of the values. Its shape gives the kinds of values of each
|
|
644
|
+
* field. Without it, a field may have any value.
|
|
800
645
|
*/
|
|
801
646
|
readonly schema?: Schema.Top | undefined;
|
|
802
|
-
/** The most
|
|
647
|
+
/** The most steps that the search may take. The default is 1000000. */
|
|
803
648
|
readonly budget?: number | undefined;
|
|
804
649
|
}
|
|
805
650
|
/**
|
|
@@ -808,44 +653,39 @@ export interface SatisfiableOptions {
|
|
|
808
653
|
* Call {@link partial} first: the condition must have no principal fields and
|
|
809
654
|
* no `Under` nodes. A condition with a predicate gives `Unknown`.
|
|
810
655
|
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
656
|
+
* Each test of a condition compares one field with constants, so the
|
|
657
|
+
* constants cut the values of each field into a few cells. The search tries
|
|
658
|
+
* one value from each cell, one field at a time. The values of a field come
|
|
659
|
+
* from the shape of the Schema in `options.schema`: its literals, `null` for
|
|
660
|
+
* a nullable or optional field, and finite or integer numbers.
|
|
816
661
|
*
|
|
817
|
-
* The
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
* of a field come from the Schema in `options.schema`: its literals, `null`
|
|
821
|
-
* for a nullable or optional field, and finite or integer numbers. A field
|
|
822
|
-
* with another Schema check is not a plain field, so the search never tries a
|
|
823
|
-
* value that such a check stops.
|
|
662
|
+
* The search reads the shape of the Schema, not its other checks, such as a
|
|
663
|
+
* minimum length. So `Unsatisfiable` holds for every value of the Schema. A
|
|
664
|
+
* `Satisfiable` example fits the shape, but a check may still stop it.
|
|
824
665
|
*
|
|
825
666
|
* The problem is as hard as boolean satisfiability, so the search has a
|
|
826
667
|
* budget. Past it, the answer is `Unknown`. A condition with more than 256
|
|
827
|
-
* fields
|
|
668
|
+
* fields gives `Unknown` too.
|
|
828
669
|
*
|
|
829
670
|
* @stability stable
|
|
830
671
|
* @category evaluation
|
|
831
672
|
* @since 1.0.0
|
|
832
673
|
*/
|
|
833
|
-
export declare const satisfiable:
|
|
834
|
-
(options?: SatisfiableOptions): (condition: Any) => Satisfiability;
|
|
835
|
-
(condition: Any, options?: SatisfiableOptions): Satisfiability;
|
|
836
|
-
};
|
|
674
|
+
export declare const satisfiable: (condition: Any, options?: SatisfiableOptions) => Satisfiability;
|
|
837
675
|
/**
|
|
838
|
-
*
|
|
839
|
-
* has no `Infinity`, `-Infinity` or `NaN`: it writes `null` in their place,
|
|
840
|
-
* and a test with `null` has another meaning. Such a number becomes an object
|
|
841
|
-
* that {@link schema} does not decode, so a policy with it fails to load and
|
|
842
|
-
* never gives a wrong answer.
|
|
676
|
+
* The JSON form of an operand.
|
|
843
677
|
*
|
|
844
678
|
* @stability stable
|
|
845
|
-
* @category
|
|
846
|
-
* @since
|
|
679
|
+
* @category models
|
|
680
|
+
* @since 2.0.0
|
|
847
681
|
*/
|
|
848
|
-
export
|
|
682
|
+
export type EncodedOperand = {
|
|
683
|
+
readonly _tag: "Literal";
|
|
684
|
+
readonly value: Scalar;
|
|
685
|
+
} | {
|
|
686
|
+
readonly _tag: "Principal";
|
|
687
|
+
readonly path: string;
|
|
688
|
+
};
|
|
849
689
|
/**
|
|
850
690
|
* The JSON form of a condition with no predicate.
|
|
851
691
|
*
|
|
@@ -853,34 +693,32 @@ export declare const toJsonValue: (condition: Ast) => unknown;
|
|
|
853
693
|
* @category models
|
|
854
694
|
* @since 0.3.0
|
|
855
695
|
*/
|
|
856
|
-
export type Encoded =
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
readonly
|
|
864
|
-
readonly
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
696
|
+
export type Encoded = {
|
|
697
|
+
readonly _tag: "True";
|
|
698
|
+
} | {
|
|
699
|
+
readonly _tag: "False";
|
|
700
|
+
} | {
|
|
701
|
+
readonly _tag: "Compare";
|
|
702
|
+
readonly op: CompareOperator;
|
|
703
|
+
readonly field: string;
|
|
704
|
+
readonly value: EncodedOperand;
|
|
705
|
+
} | {
|
|
706
|
+
readonly _tag: "In";
|
|
707
|
+
readonly field: string;
|
|
708
|
+
readonly values: ReadonlyArray<EncodedOperand>;
|
|
709
|
+
} | {
|
|
710
|
+
readonly _tag: "Exists";
|
|
711
|
+
readonly field: string;
|
|
712
|
+
} | {
|
|
713
|
+
readonly _tag: "Under";
|
|
714
|
+
readonly prefix: ReadonlyArray<EncodedOperand>;
|
|
715
|
+
} | {
|
|
716
|
+
readonly _tag: "And" | "Or";
|
|
873
717
|
readonly conditions: ReadonlyArray<Encoded>;
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* @stability stable
|
|
877
|
-
* @category models
|
|
878
|
-
* @since 0.3.0
|
|
879
|
-
*/
|
|
880
|
-
export interface EncodedNot {
|
|
718
|
+
} | {
|
|
881
719
|
readonly _tag: "Not";
|
|
882
720
|
readonly condition: Encoded;
|
|
883
|
-
}
|
|
721
|
+
};
|
|
884
722
|
/**
|
|
885
723
|
* A condition with no predicate, that may read any values. It is the type of
|
|
886
724
|
* {@link schema}: a decoded condition reads nothing, so it fits any rule, and
|
|
@@ -891,25 +729,19 @@ export interface EncodedNot {
|
|
|
891
729
|
* @category models
|
|
892
730
|
* @since 1.0.0
|
|
893
731
|
*/
|
|
894
|
-
export type PlainCondition = Condition<
|
|
732
|
+
export type PlainCondition = Condition<any>;
|
|
895
733
|
/**
|
|
896
734
|
* The Schema of a condition with no predicate. It checks the shape only. Use
|
|
897
735
|
* `Policy.schema` to check the field names against a domain too.
|
|
898
736
|
*
|
|
737
|
+
* The decoder takes at most 500 levels of conditions, and at most 1000000
|
|
738
|
+
* objects and array items, with a shared object counted for each place. It
|
|
739
|
+
* reads only the own data fields of the input.
|
|
740
|
+
*
|
|
899
741
|
* @stability stable
|
|
900
742
|
* @category schemas
|
|
901
743
|
* @since 0.3.0
|
|
902
744
|
*/
|
|
903
745
|
export declare const schema: Schema.Codec<PlainCondition, Encoded>;
|
|
904
|
-
/**
|
|
905
|
-
* Tests if a value is a whole condition tree: each node has a known tag and
|
|
906
|
-
* the fields of that tag. A predicate node needs a name and a test. A tree
|
|
907
|
-
* deeper than 1000 levels is not taken.
|
|
908
|
-
*
|
|
909
|
-
* @stability stable
|
|
910
|
-
* @category guards
|
|
911
|
-
* @since 1.0.0
|
|
912
|
-
*/
|
|
913
|
-
export declare const isAst: (u: unknown) => u is Ast;
|
|
914
746
|
export { Condition_d_exports };
|
|
915
747
|
//# sourceMappingURL=Condition.d.ts.map
|