@nmnmcc/ability 0.1.0 → 0.3.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.
Files changed (85) hide show
  1. package/README.md +353 -170
  2. package/dist/Authorizer.d.ts +216 -0
  3. package/dist/Authorizer.d.ts.map +1 -0
  4. package/dist/Authorizer.js +55 -0
  5. package/dist/Authorizer.js.map +1 -0
  6. package/dist/Condition.d.ts +536 -0
  7. package/dist/Condition.d.ts.map +1 -0
  8. package/dist/Condition.js +141 -0
  9. package/dist/Condition.js.map +1 -0
  10. package/dist/Decision.d.ts +131 -0
  11. package/dist/Decision.d.ts.map +1 -0
  12. package/dist/Decision.js +83 -0
  13. package/dist/Decision.js.map +1 -0
  14. package/dist/Domain.d.ts +148 -0
  15. package/dist/Domain.d.ts.map +1 -0
  16. package/dist/Domain.js +34 -0
  17. package/dist/Domain.js.map +1 -0
  18. package/dist/HttpApi.d.ts +129 -0
  19. package/dist/HttpApi.d.ts.map +1 -0
  20. package/dist/HttpApi.js +95 -0
  21. package/dist/HttpApi.js.map +1 -0
  22. package/dist/Policy.d.ts +429 -0
  23. package/dist/Policy.d.ts.map +1 -0
  24. package/dist/Policy.js +162 -0
  25. package/dist/Policy.js.map +1 -0
  26. package/dist/Principal.d.ts +35 -0
  27. package/dist/Principal.d.ts.map +1 -0
  28. package/dist/Principal.js +37 -0
  29. package/dist/Principal.js.map +1 -0
  30. package/dist/Resource.d.ts +213 -0
  31. package/dist/Resource.d.ts.map +1 -0
  32. package/dist/Resource.js +71 -0
  33. package/dist/Resource.js.map +1 -0
  34. package/dist/Rule.d.ts +189 -0
  35. package/dist/Rule.d.ts.map +1 -0
  36. package/dist/Rule.js +50 -0
  37. package/dist/Rule.js.map +1 -0
  38. package/dist/_virtual/_rolldown/runtime.js +1 -2
  39. package/dist/index.d.ts +9 -4
  40. package/dist/index.js +9 -4
  41. package/dist/internal/authorizer.d.ts +28 -0
  42. package/dist/internal/authorizer.d.ts.map +1 -0
  43. package/dist/internal/authorizer.js +153 -0
  44. package/dist/internal/authorizer.js.map +1 -0
  45. package/dist/internal/condition.d.ts +11 -0
  46. package/dist/internal/condition.d.ts.map +1 -0
  47. package/dist/internal/condition.js +393 -0
  48. package/dist/internal/condition.js.map +1 -0
  49. package/dist/internal/domain.js +34 -0
  50. package/dist/internal/domain.js.map +1 -0
  51. package/dist/internal/httpApi.js +41 -0
  52. package/dist/internal/httpApi.js.map +1 -0
  53. package/dist/internal/policy.js +524 -0
  54. package/dist/internal/policy.js.map +1 -0
  55. package/dist/internal/resource.js +66 -0
  56. package/dist/internal/resource.js.map +1 -0
  57. package/dist/internal/rule.js +131 -0
  58. package/dist/internal/rule.js.map +1 -0
  59. package/package.json +61 -74
  60. package/src/Authorizer.ts +330 -0
  61. package/src/Condition.ts +706 -0
  62. package/src/Decision.ts +117 -0
  63. package/src/Domain.ts +189 -0
  64. package/src/HttpApi.ts +148 -0
  65. package/src/Policy.ts +575 -0
  66. package/src/Principal.ts +41 -0
  67. package/src/Resource.ts +290 -0
  68. package/src/Rule.ts +265 -0
  69. package/src/index.ts +57 -0
  70. package/src/internal/authorizer.ts +271 -0
  71. package/src/internal/condition.ts +607 -0
  72. package/src/internal/domain.ts +56 -0
  73. package/src/internal/httpApi.ts +84 -0
  74. package/src/internal/policy.ts +815 -0
  75. package/src/internal/resource.ts +98 -0
  76. package/src/internal/rule.ts +203 -0
  77. package/dist/Ability.d.ts +0 -516
  78. package/dist/Ability.js +0 -211
  79. package/dist/AbilityExtra.d.ts +0 -79
  80. package/dist/AbilityExtra.js +0 -195
  81. package/dist/AbilityRef.d.ts +0 -110
  82. package/dist/AbilityRef.js +0 -160
  83. package/dist/internal/ability.d.ts +0 -114
  84. package/dist/internal/ability.js +0 -624
  85. package/dist/internal/serializable.js +0 -22
@@ -0,0 +1,536 @@
1
+ import { PathSegment } from "./Resource.js";
2
+ import { Untranslatable as Untranslatable$1 } from "./internal/condition.js";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Schema from "effect/Schema";
5
+ declare namespace Condition_d_exports {
6
+ export { And, Any, Ast, Builder, Compare, CompareOperator, Condition, Encoded, EncodedAnd, EncodedNot, EncodedOr, Error, Exists, False, FieldPath, In, Input, Interpreter, Literal, Not, Opaque, OpaqueOf, Operand, OperandOf, Or, PathValue, Predicate, PrincipalRef, Ref, Scalar, Services, True, Under, Untranslatable, Variance, always, and, builder, evaluate, evaluateSync, fields, fold, never, not, or, partial, schema, simplify };
7
+ }
8
+ /**
9
+ * A value that a condition can compare.
10
+ *
11
+ * @stability stable
12
+ * @category models
13
+ * @since 0.3.0
14
+ */
15
+ export type Scalar = string | number | boolean | null;
16
+ /**
17
+ * A fixed value in a condition.
18
+ *
19
+ * @stability stable
20
+ * @category models
21
+ * @since 0.3.0
22
+ */
23
+ export interface Literal {
24
+ readonly _tag: "Literal";
25
+ readonly value: Scalar;
26
+ }
27
+ /**
28
+ * A field of the principal. {@link partial} puts the value of the field in its
29
+ * place.
30
+ *
31
+ * A principal field that is `null` or missing has no value. A `Compare`, `In`
32
+ * or `Under` test with it is always false, also with `ne`. So a principal with
33
+ * no id never matches a resource with no owner. `not` still turns false into
34
+ * true.
35
+ *
36
+ * @stability stable
37
+ * @category models
38
+ * @since 0.3.0
39
+ */
40
+ export interface PrincipalRef {
41
+ readonly _tag: "Principal";
42
+ readonly path: string;
43
+ }
44
+ /**
45
+ * A field of the principal with a known value type.
46
+ *
47
+ * @stability stable
48
+ * @category models
49
+ * @since 0.3.0
50
+ */
51
+ export type Ref<A> = PrincipalRef & {
52
+ readonly "~Ref"?: () => A;
53
+ };
54
+ /**
55
+ * @stability stable
56
+ * @category models
57
+ * @since 0.3.0
58
+ */
59
+ export type Operand = Literal | PrincipalRef;
60
+ /**
61
+ * @stability stable
62
+ * @category models
63
+ * @since 0.3.0
64
+ */
65
+ export type CompareOperator = "eq" | "ne" | "lt" | "lte" | "gt" | "gte";
66
+ /**
67
+ * Always true.
68
+ *
69
+ * @stability stable
70
+ * @category models
71
+ * @since 0.3.0
72
+ */
73
+ export interface True {
74
+ readonly _tag: "True";
75
+ }
76
+ /**
77
+ * Always false.
78
+ *
79
+ * @stability stable
80
+ * @category models
81
+ * @since 0.3.0
82
+ */
83
+ export interface False {
84
+ readonly _tag: "False";
85
+ }
86
+ /**
87
+ * Compares a field with a value. A missing field has the value `null`. `lt`,
88
+ * `lte`, `gt` and `gte` are false when the two sides are not both numbers or
89
+ * both strings.
90
+ *
91
+ * @stability stable
92
+ * @category models
93
+ * @since 0.3.0
94
+ */
95
+ export interface Compare {
96
+ readonly _tag: "Compare";
97
+ readonly op: CompareOperator;
98
+ readonly field: string;
99
+ readonly value: Operand;
100
+ }
101
+ /**
102
+ * True when a field is equal to one of the values.
103
+ *
104
+ * @stability stable
105
+ * @category models
106
+ * @since 0.3.0
107
+ */
108
+ export interface In {
109
+ readonly _tag: "In";
110
+ readonly field: string;
111
+ readonly values: ReadonlyArray<Operand>;
112
+ }
113
+ /**
114
+ * True when a field is not `null` and not missing.
115
+ *
116
+ * @stability stable
117
+ * @category models
118
+ * @since 0.3.0
119
+ */
120
+ export interface Exists {
121
+ readonly _tag: "Exists";
122
+ readonly field: string;
123
+ }
124
+ /**
125
+ * True when the path of the resource starts with the prefix. A resource with
126
+ * no path is never under a prefix.
127
+ *
128
+ * @stability stable
129
+ * @category models
130
+ * @since 0.3.0
131
+ */
132
+ export interface Under {
133
+ readonly _tag: "Under";
134
+ readonly prefix: ReadonlyArray<Operand>;
135
+ }
136
+ /**
137
+ * @stability stable
138
+ * @category models
139
+ * @since 0.3.0
140
+ */
141
+ export interface And {
142
+ readonly _tag: "And";
143
+ readonly conditions: ReadonlyArray<Ast>;
144
+ }
145
+ /**
146
+ * @stability stable
147
+ * @category models
148
+ * @since 0.3.0
149
+ */
150
+ export interface Or {
151
+ readonly _tag: "Or";
152
+ readonly conditions: ReadonlyArray<Ast>;
153
+ }
154
+ /**
155
+ * @stability stable
156
+ * @category models
157
+ * @since 0.3.0
158
+ */
159
+ export interface Not {
160
+ readonly _tag: "Not";
161
+ readonly condition: Ast;
162
+ }
163
+ /**
164
+ * A test that runs an `Effect`. It can not become JSON or a query.
165
+ *
166
+ * @stability stable
167
+ * @category models
168
+ * @since 0.3.0
169
+ */
170
+ export interface Predicate {
171
+ readonly _tag: "Predicate";
172
+ readonly name: string;
173
+ readonly run: (value: any, principal: any) => Effect.Effect<boolean, unknown, unknown>;
174
+ }
175
+ /**
176
+ * The nodes of a condition, without types.
177
+ *
178
+ * @stability stable
179
+ * @category models
180
+ * @since 0.3.0
181
+ */
182
+ export type Ast = True | False | Compare | In | Exists | Under | And | Or | Not | Predicate;
183
+ /**
184
+ * The type marker for a condition with a {@link Predicate}.
185
+ *
186
+ * @stability stable
187
+ * @category models
188
+ * @since 0.3.0
189
+ */
190
+ export type Opaque = "Opaque";
191
+ /**
192
+ * @stability stable
193
+ * @category models
194
+ * @since 0.3.0
195
+ */
196
+ export interface Variance<E, R, O> {
197
+ readonly E: () => E;
198
+ readonly R: () => R;
199
+ readonly O: () => O;
200
+ }
201
+ /**
202
+ * A condition. `E` and `R` are the error type and the service type of its
203
+ * predicates. `O` is {@link Opaque} when the condition has a predicate, and
204
+ * `never` when it is plain data.
205
+ *
206
+ * @stability stable
207
+ * @category models
208
+ * @since 0.3.0
209
+ */
210
+ export type Condition<E = never, R = never, O = never> = Ast & {
211
+ readonly "~Condition"?: Variance<E, R, O>;
212
+ };
213
+ /**
214
+ * Any condition.
215
+ *
216
+ * @stability stable
217
+ * @category models
218
+ * @since 0.3.0
219
+ */
220
+ export type Any = Condition<any, any, any>;
221
+ /**
222
+ * The error type of a condition.
223
+ *
224
+ * @stability stable
225
+ * @category utility types
226
+ * @since 0.3.0
227
+ */
228
+ export type Error<C> = C extends {
229
+ readonly "~Condition"?: Variance<infer E, infer _R, infer _O>;
230
+ } ? E : never;
231
+ /**
232
+ * The service type of a condition.
233
+ *
234
+ * @stability stable
235
+ * @category utility types
236
+ * @since 0.3.0
237
+ */
238
+ export type Services<C> = C extends {
239
+ readonly "~Condition"?: Variance<infer _E, infer R, infer _O>;
240
+ } ? R : never;
241
+ /**
242
+ * {@link Opaque} when a condition has a predicate.
243
+ *
244
+ * @stability stable
245
+ * @category utility types
246
+ * @since 0.3.0
247
+ */
248
+ export type OpaqueOf<C> = C extends {
249
+ readonly "~Condition"?: Variance<infer _E, infer _R, infer O>;
250
+ } ? O : never;
251
+ type Leaf = string | number | boolean | bigint | symbol | null | undefined;
252
+ type PreviousDepth = [never, 0, 1, 2, 3];
253
+ type FieldPathInternal<T, Depth extends number> = [Depth] extends [never] ? never : { [K in keyof T & string]-?: NonNullable<T[K]> extends Leaf ? K : NonNullable<T[K]> extends ReadonlyArray<unknown> | Function ? never : NonNullable<T[K]> extends object ? `${K}.${FieldPathInternal<NonNullable<T[K]>, PreviousDepth[Depth]>}` : never; }[keyof T & string];
254
+ /**
255
+ * The paths of the fields of `T` that hold one value, with dots for nested
256
+ * fields. Arrays are left out. The type goes down four levels, so type
257
+ * checking stays fast. For a union of types, only the common fields are
258
+ * paths.
259
+ *
260
+ * @stability stable
261
+ * @category utility types
262
+ * @since 0.3.0
263
+ */
264
+ export type FieldPath<T> = [T] extends [object] ? FieldPathInternal<T, 4> : never;
265
+ type Normalize<A> = Exclude<A, undefined> | (undefined extends A ? null : never);
266
+ /**
267
+ * The type of the field of `T` at `Path`. A field that may be missing may also
268
+ * be `null`.
269
+ *
270
+ * @stability stable
271
+ * @category utility types
272
+ * @since 0.3.0
273
+ */
274
+ export type PathValue<T, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof T ? undefined extends T[Head] ? PathValue<NonNullable<T[Head]>, Rest> | null : null extends T[Head] ? PathValue<NonNullable<T[Head]>, Rest> | null : PathValue<T[Head], Rest> : never : Path extends keyof T ? Normalize<T[Path]> : never;
275
+ /**
276
+ * A value for a field of type `A`: a fixed value, or a field of the principal
277
+ * with the same type.
278
+ *
279
+ * @stability stable
280
+ * @category models
281
+ * @since 0.3.0
282
+ */
283
+ export type OperandOf<A> = Extract<A, Scalar> | Ref<A>;
284
+ type OrderedPath<T> = { [F in FieldPath<T>]: Exclude<PathValue<T, F>, null> extends number | string ? F : never; }[FieldPath<T>];
285
+ /**
286
+ * Makes conditions for a resource with the data type `Data` and the value type
287
+ * `Value`, and a principal with the type `P`.
288
+ *
289
+ * @stability stable
290
+ * @category models
291
+ * @since 0.3.0
292
+ */
293
+ export interface Builder<Data, Value, P> {
294
+ /** The field is equal to the value. */
295
+ readonly eq: <const F extends FieldPath<Data>>(field: F, value: OperandOf<PathValue<Data, F>>) => Condition;
296
+ /** The field is not equal to the value. */
297
+ readonly ne: <const F extends FieldPath<Data>>(field: F, value: OperandOf<PathValue<Data, F>>) => Condition;
298
+ readonly lt: <const F extends OrderedPath<Data>>(field: F, value: OperandOf<Exclude<PathValue<Data, F>, null>>) => Condition;
299
+ readonly lte: <const F extends OrderedPath<Data>>(field: F, value: OperandOf<Exclude<PathValue<Data, F>, null>>) => Condition;
300
+ readonly gt: <const F extends OrderedPath<Data>>(field: F, value: OperandOf<Exclude<PathValue<Data, F>, null>>) => Condition;
301
+ readonly gte: <const F extends OrderedPath<Data>>(field: F, value: OperandOf<Exclude<PathValue<Data, F>, null>>) => Condition;
302
+ /** The field is equal to one of the values. */
303
+ readonly in: <const F extends FieldPath<Data>>(field: F, values: ReadonlyArray<OperandOf<PathValue<Data, F>>>) => Condition;
304
+ /** The field has a value that is not `null`. */
305
+ readonly exists: <const F extends FieldPath<Data>>(field: F) => Condition;
306
+ /** The path of the resource starts with these parts. */
307
+ readonly under: (...prefix: ReadonlyArray<string | null | Ref<string | null>>) => Condition;
308
+ /** A field of the principal, to use as a value. */
309
+ readonly principal: <const F extends FieldPath<P>>(field: F) => Ref<PathValue<P, F>>;
310
+ readonly and: <const Cs extends ReadonlyArray<Any>>(...conditions: Cs) => Condition<Error<Cs[number]>, Services<Cs[number]>, OpaqueOf<Cs[number]>>;
311
+ readonly or: <const Cs extends ReadonlyArray<Any>>(...conditions: Cs) => Condition<Error<Cs[number]>, Services<Cs[number]>, OpaqueOf<Cs[number]>>;
312
+ readonly not: <C extends Any>(condition: C) => Condition<Error<C>, Services<C>, OpaqueOf<C>>;
313
+ /**
314
+ * A test that runs any code. It may give a boolean or an `Effect`. A
315
+ * condition with a predicate can not become JSON or a query.
316
+ */
317
+ readonly predicate: <E = never, R = never>(name: string, test: (value: Value, principal: P) => boolean | Effect.Effect<boolean, E, R>) => Condition<E, R, Opaque>;
318
+ }
319
+ /**
320
+ * Makes a builder. Rules give you a builder with the right types, so you do not
321
+ * often need this.
322
+ *
323
+ * @stability stable
324
+ * @category constructors
325
+ * @since 0.3.0
326
+ */
327
+ export declare const builder: <Data, Value, P>() => Builder<Data, Value, P>;
328
+ /**
329
+ * Always true.
330
+ *
331
+ * @stability stable
332
+ * @category constructors
333
+ * @since 0.3.0
334
+ */
335
+ export declare const always: Condition;
336
+ /**
337
+ * Always false.
338
+ *
339
+ * @stability stable
340
+ * @category constructors
341
+ * @since 0.3.0
342
+ */
343
+ export declare const never: Condition;
344
+ /**
345
+ * True when all the conditions are true. With no conditions, it is true.
346
+ *
347
+ * @stability stable
348
+ * @category combinators
349
+ * @since 0.3.0
350
+ */
351
+ export declare const and: <const Cs extends ReadonlyArray<Any>>(...conditions: Cs) => Condition<Error<Cs[number]>, Services<Cs[number]>, OpaqueOf<Cs[number]>>;
352
+ /**
353
+ * True when one of the conditions is true. With no conditions, it is false.
354
+ *
355
+ * @stability stable
356
+ * @category combinators
357
+ * @since 0.3.0
358
+ */
359
+ export declare const or: <const Cs extends ReadonlyArray<Any>>(...conditions: Cs) => Condition<Error<Cs[number]>, Services<Cs[number]>, OpaqueOf<Cs[number]>>;
360
+ /**
361
+ * @stability stable
362
+ * @category combinators
363
+ * @since 0.3.0
364
+ */
365
+ export declare const not: <C extends Any>(condition: C) => Condition<Error<C>, Services<C>, OpaqueOf<C>>;
366
+ /**
367
+ * The data that a condition needs for a test.
368
+ *
369
+ * @stability stable
370
+ * @category models
371
+ * @since 0.3.0
372
+ */
373
+ export interface Input {
374
+ /** The resource value. */
375
+ readonly value: object;
376
+ /**
377
+ * The principal. Without it, a principal field has no value. See
378
+ * {@link PrincipalRef}.
379
+ */
380
+ readonly principal?: object | undefined;
381
+ /** The path of the resource. Without it, `Under` is false. */
382
+ readonly path?: ReadonlyArray<PathSegment> | undefined;
383
+ }
384
+ /**
385
+ * Tests a condition on a value. A predicate may fail with its error.
386
+ *
387
+ * @stability stable
388
+ * @category evaluation
389
+ * @since 0.3.0
390
+ */
391
+ export declare const evaluate: {
392
+ (input: Input): <E, R, O>(condition: Condition<E, R, O>) => Effect.Effect<boolean, E, R>;
393
+ <E, R, O>(condition: Condition<E, R, O>, input: Input): Effect.Effect<boolean, E, R>;
394
+ };
395
+ /**
396
+ * Tests a condition with no predicate on a value, at once.
397
+ *
398
+ * @stability stable
399
+ * @category evaluation
400
+ * @since 0.3.0
401
+ */
402
+ export declare const evaluateSync: {
403
+ (input: Input): (condition: Condition) => boolean;
404
+ (condition: Condition, input: Input): boolean;
405
+ };
406
+ /**
407
+ * Puts the principal into a condition and expands `Under` with the path of the
408
+ * resource. The result is simplified. It has no principal fields and no
409
+ * `Under` nodes. It is `True` or `False` when the answer does not depend on the
410
+ * resource value.
411
+ *
412
+ * @stability stable
413
+ * @category evaluation
414
+ * @since 0.3.0
415
+ */
416
+ export declare const partial: {
417
+ (input: {
418
+ readonly principal?: object | undefined;
419
+ readonly path?: ReadonlyArray<PathSegment> | undefined;
420
+ }): <E, R, O>(condition: Condition<E, R, O>) => Condition<E, R, O>;
421
+ <E, R, O>(condition: Condition<E, R, O>, input: {
422
+ readonly principal?: object | undefined;
423
+ readonly path?: ReadonlyArray<PathSegment> | undefined;
424
+ }): Condition<E, R, O>;
425
+ };
426
+ /**
427
+ * Makes a condition smaller without a change to its meaning. It removes `True`
428
+ * and `False` from `And` and `Or`, joins nested `And` and `Or` nodes, and
429
+ * removes double `Not` nodes.
430
+ *
431
+ * @stability stable
432
+ * @category evaluation
433
+ * @since 0.3.0
434
+ */
435
+ export declare const simplify: <E, R, O>(condition: Condition<E, R, O>) => Condition<E, R, O>;
436
+ /**
437
+ * The functions that change each node of a condition into another form, such
438
+ * as a database query.
439
+ *
440
+ * @stability stable
441
+ * @category models
442
+ * @since 0.3.0
443
+ */
444
+ export interface Interpreter<A> {
445
+ readonly true: () => A;
446
+ readonly false: () => A;
447
+ readonly compare: (op: CompareOperator, field: string, value: Scalar) => A;
448
+ readonly in: (field: string, values: ReadonlyArray<Scalar>) => A;
449
+ readonly exists: (field: string) => A;
450
+ readonly and: (conditions: ReadonlyArray<A>) => A;
451
+ readonly or: (conditions: ReadonlyArray<A>) => A;
452
+ readonly not: (condition: A) => A;
453
+ /** Optional. Without it, a predicate makes `fold` fail. */
454
+ readonly predicate?: (name: string) => A;
455
+ }
456
+ /**
457
+ * The error when `fold` can not change a node.
458
+ *
459
+ * @stability stable
460
+ * @category errors
461
+ * @since 0.3.0
462
+ */
463
+ export declare const Untranslatable: typeof Untranslatable$1;
464
+ /**
465
+ * @stability stable
466
+ * @category errors
467
+ * @since 0.3.0
468
+ */
469
+ export type Untranslatable = Untranslatable$1;
470
+ /**
471
+ * Changes a condition into another form with an interpreter. Call
472
+ * {@link partial} first: `fold` fails on principal fields and on `Under`
473
+ * nodes, and on predicates when the interpreter has no `predicate` function.
474
+ *
475
+ * @stability stable
476
+ * @category converting
477
+ * @since 0.3.0
478
+ */
479
+ export declare const fold: {
480
+ <A>(interpreter: Interpreter<A>): (condition: Any) => Effect.Effect<A, Untranslatable>;
481
+ <A>(condition: Any, interpreter: Interpreter<A>): Effect.Effect<A, Untranslatable>;
482
+ };
483
+ /**
484
+ * The fields that a condition uses.
485
+ *
486
+ * @stability stable
487
+ * @category getters
488
+ * @since 0.3.0
489
+ */
490
+ export declare const fields: (condition: Any) => ReadonlyArray<string>;
491
+ /**
492
+ * The JSON form of a condition with no predicate.
493
+ *
494
+ * @stability stable
495
+ * @category models
496
+ * @since 0.3.0
497
+ */
498
+ export type Encoded = Exclude<Ast, Predicate | And | Or | Not> | EncodedAnd | EncodedOr | EncodedNot;
499
+ /**
500
+ * @stability stable
501
+ * @category models
502
+ * @since 0.3.0
503
+ */
504
+ export interface EncodedAnd {
505
+ readonly _tag: "And";
506
+ readonly conditions: ReadonlyArray<Encoded>;
507
+ }
508
+ /**
509
+ * @stability stable
510
+ * @category models
511
+ * @since 0.3.0
512
+ */
513
+ export interface EncodedOr {
514
+ readonly _tag: "Or";
515
+ readonly conditions: ReadonlyArray<Encoded>;
516
+ }
517
+ /**
518
+ * @stability stable
519
+ * @category models
520
+ * @since 0.3.0
521
+ */
522
+ export interface EncodedNot {
523
+ readonly _tag: "Not";
524
+ readonly condition: Encoded;
525
+ }
526
+ /**
527
+ * The Schema of a condition with no predicate. It checks the shape only. Use
528
+ * `Policy.schema` to check the field names against a domain too.
529
+ *
530
+ * @stability stable
531
+ * @category schemas
532
+ * @since 0.3.0
533
+ */
534
+ export declare const schema: Schema.Codec<Condition, Encoded>;
535
+ export { Condition_d_exports };
536
+ //# sourceMappingURL=Condition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Condition.d.ts","names":["Resource.PathSegment","internal.Untranslatable"],"sources":["../src/Condition.ts"],"mappings":";;;;;;;;;;;;;;YAmCY;;;;;;;;iBASK;WACP;WACA,OAAO;;;;;;;;;;;;;;;iBAgBA;WACP;WACA;;;;;;;;;YAUE,IAAI,KAAK;WAA0B,eAAe;;;;;;;YAOlD,UAAU,UAAU;;;;;;YAOpB;;;;;;;;iBASK;WACP;;;;;;;;;iBAUO;WACP;;;;;;;;;;;iBAYO;WACP;WACA,IAAI;WACJ;WACA,OAAO;;;;;;;;;iBAUA;WACP;WACA;WACA,QAAQ,cAAc;;;;;;;;;iBAUf;WACP;WACA;;;;;;;;;;iBAWO;WACP;WACA,QAAQ,cAAc;;;;;;;iBAQf;WACP;WACA,YAAY,cAAc;;;;;;;iBAQnB;WACP;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KAAK,YAAY,MAAM,KAAK,OAAO,aAAa,YAAY;;;;;;iBAOpD;WACP;WACA,YAAY,cAAc;;;;;;;iBAQnB;WACP;WACA,YAAY,cAAc;;;;;;;iBAQnB;WACP;WACA,WAAW;;;;;;;;;;qBAWR,QAAQ,OAAO,MAAM,WAAW"}
@@ -0,0 +1,141 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { Untranslatable as Untranslatable$1, always as always$1, and as and$1, builder as builder$1, evaluate as evaluate$1, evaluateSync as evaluateSync$1, fields as fields$1, fold as fold$1, never as never$1, not as not$1, or as or$1, partial as partial$1, schema as schema$1, simplify as simplify$1 } from "./internal/condition.js";
3
+ // src/Condition.ts
4
+ var Condition_exports = /* @__PURE__ */ __exportAll({
5
+ Untranslatable: () => Untranslatable,
6
+ always: () => always,
7
+ and: () => and,
8
+ builder: () => builder,
9
+ evaluate: () => evaluate,
10
+ evaluateSync: () => evaluateSync,
11
+ fields: () => fields,
12
+ fold: () => fold,
13
+ never: () => never,
14
+ not: () => not,
15
+ or: () => or,
16
+ partial: () => partial,
17
+ schema: () => schema,
18
+ simplify: () => simplify
19
+ });
20
+ /**
21
+ * Makes a builder. Rules give you a builder with the right types, so you do not
22
+ * often need this.
23
+ *
24
+ * @stability stable
25
+ * @category constructors
26
+ * @since 0.3.0
27
+ */
28
+ const builder = builder$1;
29
+ /**
30
+ * Always true.
31
+ *
32
+ * @stability stable
33
+ * @category constructors
34
+ * @since 0.3.0
35
+ */
36
+ const always = always$1;
37
+ /**
38
+ * Always false.
39
+ *
40
+ * @stability stable
41
+ * @category constructors
42
+ * @since 0.3.0
43
+ */
44
+ const never = never$1;
45
+ /**
46
+ * True when all the conditions are true. With no conditions, it is true.
47
+ *
48
+ * @stability stable
49
+ * @category combinators
50
+ * @since 0.3.0
51
+ */
52
+ const and = and$1;
53
+ /**
54
+ * True when one of the conditions is true. With no conditions, it is false.
55
+ *
56
+ * @stability stable
57
+ * @category combinators
58
+ * @since 0.3.0
59
+ */
60
+ const or = or$1;
61
+ /**
62
+ * @stability stable
63
+ * @category combinators
64
+ * @since 0.3.0
65
+ */
66
+ const not = not$1;
67
+ /**
68
+ * Tests a condition on a value. A predicate may fail with its error.
69
+ *
70
+ * @stability stable
71
+ * @category evaluation
72
+ * @since 0.3.0
73
+ */
74
+ const evaluate = evaluate$1;
75
+ /**
76
+ * Tests a condition with no predicate on a value, at once.
77
+ *
78
+ * @stability stable
79
+ * @category evaluation
80
+ * @since 0.3.0
81
+ */
82
+ const evaluateSync = evaluateSync$1;
83
+ /**
84
+ * Puts the principal into a condition and expands `Under` with the path of the
85
+ * resource. The result is simplified. It has no principal fields and no
86
+ * `Under` nodes. It is `True` or `False` when the answer does not depend on the
87
+ * resource value.
88
+ *
89
+ * @stability stable
90
+ * @category evaluation
91
+ * @since 0.3.0
92
+ */
93
+ const partial = partial$1;
94
+ /**
95
+ * Makes a condition smaller without a change to its meaning. It removes `True`
96
+ * and `False` from `And` and `Or`, joins nested `And` and `Or` nodes, and
97
+ * removes double `Not` nodes.
98
+ *
99
+ * @stability stable
100
+ * @category evaluation
101
+ * @since 0.3.0
102
+ */
103
+ const simplify = simplify$1;
104
+ /**
105
+ * The error when `fold` can not change a node.
106
+ *
107
+ * @stability stable
108
+ * @category errors
109
+ * @since 0.3.0
110
+ */
111
+ const Untranslatable = Untranslatable$1;
112
+ /**
113
+ * Changes a condition into another form with an interpreter. Call
114
+ * {@link partial} first: `fold` fails on principal fields and on `Under`
115
+ * nodes, and on predicates when the interpreter has no `predicate` function.
116
+ *
117
+ * @stability stable
118
+ * @category converting
119
+ * @since 0.3.0
120
+ */
121
+ const fold = fold$1;
122
+ /**
123
+ * The fields that a condition uses.
124
+ *
125
+ * @stability stable
126
+ * @category getters
127
+ * @since 0.3.0
128
+ */
129
+ const fields = fields$1;
130
+ /**
131
+ * The Schema of a condition with no predicate. It checks the shape only. Use
132
+ * `Policy.schema` to check the field names against a domain too.
133
+ *
134
+ * @stability stable
135
+ * @category schemas
136
+ * @since 0.3.0
137
+ */
138
+ const schema = schema$1;
139
+ export { Condition_exports, Untranslatable, always, and, builder, evaluate, evaluateSync, fields, fold, never, not, or, partial, schema, simplify };
140
+
141
+ //# sourceMappingURL=Condition.js.map