@nmnmcc/ability 2.1.1 → 2.1.3

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 (41) hide show
  1. package/README.md +2 -2
  2. package/dist/Authorizer.d.ts +11 -11
  3. package/dist/Authorizer.d.ts.map +1 -1
  4. package/dist/Authorizer.js.map +1 -1
  5. package/dist/Condition.d.ts +6 -4
  6. package/dist/Condition.d.ts.map +1 -1
  7. package/dist/Condition.js +5 -3
  8. package/dist/Condition.js.map +1 -1
  9. package/dist/Policy.d.ts +26 -15
  10. package/dist/Policy.d.ts.map +1 -1
  11. package/dist/Policy.js +7 -6
  12. package/dist/Policy.js.map +1 -1
  13. package/dist/internal/algebra.js +8 -5
  14. package/dist/internal/algebra.js.map +1 -1
  15. package/dist/internal/authorizer.js +23 -9
  16. package/dist/internal/authorizer.js.map +1 -1
  17. package/dist/internal/bind.js +16 -10
  18. package/dist/internal/bind.js.map +1 -1
  19. package/dist/internal/catalog.d.ts.map +1 -1
  20. package/dist/internal/catalog.js +37 -7
  21. package/dist/internal/catalog.js.map +1 -1
  22. package/dist/internal/decide.js +2 -2
  23. package/dist/internal/decide.js.map +1 -1
  24. package/dist/internal/patterns.js +26 -26
  25. package/dist/internal/patterns.js.map +1 -1
  26. package/dist/internal/policy-nodes.js +21 -12
  27. package/dist/internal/policy-nodes.js.map +1 -1
  28. package/dist/internal/search.js +38 -26
  29. package/dist/internal/search.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/Authorizer.ts +10 -10
  32. package/src/Condition.ts +14 -8
  33. package/src/Policy.ts +34 -17
  34. package/src/internal/algebra.ts +12 -8
  35. package/src/internal/authorizer.ts +49 -34
  36. package/src/internal/bind.ts +28 -30
  37. package/src/internal/catalog.ts +50 -14
  38. package/src/internal/decide.ts +3 -1
  39. package/src/internal/patterns.ts +37 -29
  40. package/src/internal/policy-nodes.ts +19 -13
  41. package/src/internal/search.ts +31 -21
package/README.md CHANGED
@@ -337,8 +337,8 @@ predicate with the name `"policy"`. It runs the whole policy for each value, so
337
337
  it gives the same answers and the same failures as `Policy.decide`.
338
338
 
339
339
  A deep policy tree may give a very large residual. When it would have more than
340
- 10000 nodes, `Policy.residual` throws an error, and a check in an `Authorizer`
341
- fails.
340
+ `residualNodes` nodes of its domain, 100000 by default, `Policy.residual` throws
341
+ an error, and a check in an `Authorizer` fails.
342
342
 
343
343
  ### Scopes
344
344
 
@@ -1,6 +1,6 @@
1
1
  import { Condition, Opaque } from "./Condition.js";
2
2
  import { Any, CommonAction, Kind, Principal } from "./Domain.js";
3
- import { CheckField, Coverage, DeepKindTarget, DeepTarget as DeepTarget$1, FieldlessTarget, KindRequest, KindTarget, Policy, Request, ResidualReads, Target as Target$1 } from "./Policy.js";
3
+ import { Checked, Coverage, DeepKindTarget, DeepTarget as DeepTarget$1, FieldlessTarget, KindRequest, KindTarget, Policy, Request, ResidualReads, Target as Target$1 } from "./Policy.js";
4
4
  import { Decision } from "./Decision.js";
5
5
  import { Forbidden as Forbidden$1, Pending as Pending$1, PolicyUnavailable as PolicyUnavailable$1 } from "./internal/authorizer.js";
6
6
  import * as Context from "effect/Context";
@@ -123,29 +123,29 @@ export interface Authorizer<D extends Any, E, R> {
123
123
  */
124
124
  readonly policy: Effect.Effect<Policy<D, Opaque<E>>, PolicyUnavailable | E, R>;
125
125
  /** Gives the decision of the policy. It does not ask the decider. */
126
- readonly decide: <const T extends DeepTarget$1<D>>(target: T & CheckField<D, T>) => Effect.Effect<Decision, PolicyUnavailable | E, R>;
126
+ readonly decide: <const T extends DeepTarget$1<D>>(target: Checked<D, T>) => Effect.Effect<Decision, PolicyUnavailable | E, R>;
127
127
  /** Succeeds when the principal may do the act, and fails when it may not. */
128
- readonly check: <const T extends DeepTarget<D>>(target: T & CheckField<D, T>) => Effect.Effect<void, Forbidden | Pending | PolicyUnavailable | E, R>;
128
+ readonly check: <const T extends DeepTarget<D>>(target: Checked<D, T>) => Effect.Effect<void, Forbidden | Pending | PolicyUnavailable | E, R>;
129
129
  /**
130
130
  * Checks the read action first, and fails with the error of `hide` when the
131
131
  * principal may not see the resource. Then it checks the act. Use it to
132
132
  * answer "not found" to a principal that may not know that a resource
133
133
  * exists.
134
134
  */
135
- readonly guard: <const T extends DeepTarget$1<D>, E2>(target: T & CheckField<D, T>, options: GuardOptions<D, E2, T["resource"]["_tag"]>) => Effect.Effect<void, E2 | Forbidden | Pending | PolicyUnavailable | E, R>;
135
+ readonly guard: <const T extends DeepTarget$1<D>, E2>(target: Checked<D, T>, options: GuardOptions<D, E2, T["resource"]["_tag"]>) => Effect.Effect<void, E2 | Forbidden | Pending | PolicyUnavailable | E, R>;
136
136
  /**
137
137
  * Gives the condition on resource values that the principal may act on,
138
138
  * inside the scope of the target when it has one. Change it into a query
139
139
  * with `Condition.fold`. It is `False` when the principal may act on no
140
140
  * value, so the list is empty: it is not an error.
141
141
  */
142
- readonly filter: <const T extends DeepKindTarget<D>>(target: T & CheckField<D, T>) => Effect.Effect<Condition<ResidualReads<D, T["kind"]>, Opaque<E>>, PolicyUnavailable | E, R>;
142
+ readonly filter: <const T extends DeepKindTarget<D>>(target: Checked<D, T>) => Effect.Effect<Condition<ResidualReads<D, T["kind"]>, Opaque<E>>, PolicyUnavailable | E, R>;
143
143
  /**
144
144
  * Tells if the principal may act on all, none or some of the values in
145
145
  * the scope of the target. See `Policy.coverage`. Use it to show a button
146
146
  * only when the answer is not `None`.
147
147
  */
148
- readonly coverage: <const T extends DeepKindTarget<D>>(target: T & CheckField<D, T>) => Effect.Effect<Coverage<ResidualReads<D, T["kind"]>, Opaque<E>>, PolicyUnavailable | E, R>;
148
+ readonly coverage: <const T extends DeepKindTarget<D>>(target: Checked<D, T>) => Effect.Effect<Coverage<ResidualReads<D, T["kind"]>, Opaque<E>>, PolicyUnavailable | E, R>;
149
149
  /** Gives the fields of a value that the principal may use. */
150
150
  readonly permittedFields: (target: FieldlessTarget<D>) => Effect.Effect<ReadonlyArray<string>, PolicyUnavailable | E, R>;
151
151
  /**
@@ -166,11 +166,11 @@ export interface ServiceClass<Self, Id extends string, D extends Any, E, R> exte
166
166
  readonly domain: D;
167
167
  /** The Effect that gives the principal of the current request. */
168
168
  readonly principal: Effect.Effect<Principal<D>, E, R>;
169
- readonly decide: <const T extends DeepTarget$1<D>>(target: T & CheckField<D, T>) => Effect.Effect<Decision, PolicyUnavailable | E, R | Self>;
170
- readonly check: <const T extends DeepTarget<D>>(target: T & CheckField<D, T>) => Effect.Effect<void, Forbidden | Pending | PolicyUnavailable | E, R | Self>;
171
- readonly guard: <const T extends DeepTarget$1<D>, E2>(target: T & CheckField<D, T>, options: GuardOptions<D, E2, T["resource"]["_tag"]>) => Effect.Effect<void, E2 | Forbidden | Pending | PolicyUnavailable | E, R | Self>;
172
- readonly filter: <const T extends DeepKindTarget<D>>(target: T & CheckField<D, T>) => Effect.Effect<Condition<ResidualReads<D, T["kind"]>, Opaque<E>>, PolicyUnavailable | E, R | Self>;
173
- readonly coverage: <const T extends DeepKindTarget<D>>(target: T & CheckField<D, T>) => Effect.Effect<Coverage<ResidualReads<D, T["kind"]>, Opaque<E>>, PolicyUnavailable | E, R | Self>;
169
+ readonly decide: <const T extends DeepTarget$1<D>>(target: Checked<D, T>) => Effect.Effect<Decision, PolicyUnavailable | E, R | Self>;
170
+ readonly check: <const T extends DeepTarget<D>>(target: Checked<D, T>) => Effect.Effect<void, Forbidden | Pending | PolicyUnavailable | E, R | Self>;
171
+ readonly guard: <const T extends DeepTarget$1<D>, E2>(target: Checked<D, T>, options: GuardOptions<D, E2, T["resource"]["_tag"]>) => Effect.Effect<void, E2 | Forbidden | Pending | PolicyUnavailable | E, R | Self>;
172
+ readonly filter: <const T extends DeepKindTarget<D>>(target: Checked<D, T>) => Effect.Effect<Condition<ResidualReads<D, T["kind"]>, Opaque<E>>, PolicyUnavailable | E, R | Self>;
173
+ readonly coverage: <const T extends DeepKindTarget<D>>(target: Checked<D, T>) => Effect.Effect<Coverage<ResidualReads<D, T["kind"]>, Opaque<E>>, PolicyUnavailable | E, R | Self>;
174
174
  readonly permittedFields: (target: FieldlessTarget<D>) => Effect.Effect<ReadonlyArray<string>, PolicyUnavailable | E, R | Self>;
175
175
  }
176
176
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Authorizer.d.ts","names":["Internal.Forbidden","Internal.PolicyUnavailable","Internal.Pending","Policy.Target","Policy.KindTarget","Policy.DeepTarget","Policy.DeepKindTarget","Policy.Request","Policy.KindRequest","Domain.Kind","Domain.CommonAction","Domain.Any","Domain.Principal","Condition.Opaque","Policy.Policy","Policy.CheckField","Decision.Decision","Policy.ResidualReads","Condition.Condition","Policy.Coverage","Policy.FieldlessTarget"],"sources":["../src/Authorizer.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBAqDa,kBAAkBA;;;;;;YAOnB,YAAYA;;;;;;;;;qBAUX,0BAA0BC;;;;;;YAQ3B,oBAAoBA;;;;;;;;;qBAUnB,gBAAgBC;;;;;;YAOjB,UAAUA;;;;;;;;;;;YAYV,OAAO,KAAKC,SAAc,KAAKC,WAAkB;;;;;;;;;YAUjD,WAAW,KAAKC,aAAkB,KAAKC,eAAsB;;;;;;;;YAS7D,eAAe,KAAKC,QAAe,KAAKC,YAAmB;;;;;;;;YAS3D,aAAa,GAAG,IAAI,mBAAmBC,KAAY;;WAErD,YAAY;oBACFC,aAAoB,GAAG;;;;;WAM/B,OAAOA,aAAoB,GAAG;;;;;;;WAQ9B,MAAMA,aAAoB,GAAG;;;;;;;;;iBAUxB,WAAW,UAAUC,KAAY,GAAG;WAC3C,QAAQ;;WAER,WAAW,OAAO,OAAOC,UAAiB,IAAI,GAAG;;;;;WAKjD,QAAQ,OAAO,OACvBE,OAAc,GAAGD,OAAiB,KAClC,oBAAoB,GACpB;;WAGQ,eAAe,UAAUR,aAAkB,IACnD,QAAQ,IAAIU,WAAkB,GAAG,OAC7B,OAAO,OAAOC,UAAmB,oBAAoB,GAAG;;WAEpD,cAAc,UAAU,WAAW,IAC3C,Q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B,OAAO,OACXG,UACCD,cAAqB,GAAG,YACxBJ,OAAiB,KAElB,oBAAoB,GACpB,IAAI;WAEI,iBAAiB,UAAUP,eAAsB,IACzD,QAAQ,IAAIS,WAAkB,GAAG,OAC7B,OAAO,OACXI,SAAgBF,cAAqB,GAAG,YAAYJ,OAAiB,KACrE,oBAAoB,GACpB,IAAI;WAEI,kBACR,QAAQO,gBAAuB,OAC3B,OAAO,OAAO,uBAAuB,oBAAoB,GAAG,IAAI;;;;;;;;;YAU1D,kBAAkB,QAAQ;WAC5B,QAAQT;WACR,WAAW,OAAO;;;;;;;;;qBAUf,UAAU,kBAChB,mBACN,UAAUA,KACV,WACA,WAEA,IAAI,IACJ;WACU,QAAQ;;WAER,WAAW,OAAO,OAAOC,UAAiB,QAAQ,KAAK,GAAG;MAEhE,aAAa,MAAM,IAAI,GAAG,GAAG;;;;;;;;iBASjB,QAAQ,UAAUD,KAAY,GAAG,GAAG,IAAI,IAAI;;;;;;WAMnD,SACR,WAAWC,UAAiB,OACxB,OAAO,OAAOE,OAAc,GAAGD,OAAiB,GAAG,MAAM,IAAI;;;;;WAKzD,WACR,SAAS,eAAe,OACpB,OAAO,OAAOG,UAAmB,UAAU,GAAG;;;;;;;;;;;;;;WAc1C;aAEG;aACA,aAAa,SAAS;aACtB,OAAO,WAAWJ,UAAiB;;;;;;;;;;qBAYnC,QACZ,MACA,mBACA,UAAUD,KACV,GACA,GACA,YACA,YACA,YAEA,SAAS,aAAa,MAAM,IAAI,GAAG,GAAG,IACtC,SAAS,QAAQ,GAAG,QAAQ,IAAI,QAAQ,IAAI,IAAI,IAAI,QAChD,MAAM,MAAM,aAAa,KAAK"}
1
+ {"version":3,"file":"Authorizer.d.ts","names":["Internal.Forbidden","Internal.PolicyUnavailable","Internal.Pending","Policy.Target","Policy.KindTarget","Policy.DeepTarget","Policy.DeepKindTarget","Policy.Request","Policy.KindRequest","Domain.Kind","Domain.CommonAction","Domain.Any","Domain.Principal","Condition.Opaque","Policy.Policy","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;WAER,WAAW,OAAO,OAAOC,UAAiB,QAAQ,KAAK,GAAG;MAEhE,aAAa,MAAM,IAAI,GAAG,GAAG;;;;;;;;iBASjB,QAAQ,UAAUD,KAAY,GAAG,GAAG,IAAI,IAAI;;;;;;WAMnD,SACR,WAAWC,UAAiB,OACxB,OAAO,OAAOE,OAAc,GAAGD,OAAiB,GAAG,MAAM,IAAI;;;;;WAKzD,WACR,SAAS,eAAe,OACpB,OAAO,OAAOG,UAAmB,UAAU,GAAG;;;;;;;;;;;;;;WAc1C;aAEG;aACA,aAAa,SAAS;aACtB,OAAO,WAAWJ,UAAiB;;;;;;;;;;qBAYnC,QACZ,MACA,mBACA,UAAUD,KACV,GACA,GACA,YACA,YACA,YAEA,SAAS,aAAa,MAAM,IAAI,GAAG,GAAG,IACtC,SAAS,QAAQ,GAAG,QAAQ,IAAI,QAAQ,IAAI,IAAI,IAAI,QAChD,MAAM,MAAM,aAAa,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"Authorizer.js","names":["Internal.Forbidden","Internal.PolicyUnavailable","Internal.Pending","Internal.Service","Internal.makeLayer"],"sources":["../src/Authorizer.ts"],"sourcesContent":["/**\n * An authorizer is an Effect service that makes decisions for the principal\n * of the current request.\n *\n * You make the service class, in the same way as `Context.Service`. Give the\n * domain, and the Effect that gives the principal of the current request. The\n * error type and the service type of the checks come from that Effect:\n *\n * ```ts\n * class Auth extends Authorizer.Service<Auth>()(\"app/Auth\", {\n * domain: App,\n * principal: Identity,\n * }) {}\n * ```\n *\n * Then give a layer with {@link layer}. It says how to load the policy of a\n * principal. The policy of each principal is loaded once and kept in a cache\n * for a short time.\n *\n * Then use the service in a handler:\n *\n * ```ts\n * yield* Auth.check({ action: \"update\", resource: document })\n * ```\n *\n * A \"no\" answer goes into the error channel as {@link Forbidden}. When the\n * policy can not be loaded, the check fails with {@link PolicyUnavailable}.\n * So the check fails closed: an error is never a \"yes\".\n *\n * When no rule gives an answer, the authorizer asks the decider, if there is\n * one. A decider may answer at once, or fail with {@link Pending} when a person\n * or another service must answer later.\n *\n * @stability stable\n * @since 0.3.0\n */\nimport type * as Context from \"effect/Context\"\nimport type * as Duration from \"effect/Duration\"\nimport type * as Effect from \"effect/Effect\"\nimport type * as Layer from \"effect/Layer\"\nimport type * as Condition from \"./Condition.ts\"\nimport type * as Decision from \"./Decision.ts\"\nimport type * as Domain from \"./Domain.ts\"\nimport * as Internal from \"./internal/authorizer.ts\"\nimport type * as Policy from \"./Policy.ts\"\n\n/**\n * The error when a policy says no.\n *\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport const Forbidden: typeof Internal.Forbidden = Internal.Forbidden\n\n/**\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport type Forbidden = Internal.Forbidden\n\n/**\n * The error when the policy of the principal can not be loaded. The cause is\n * kept, but it is not shown to the client.\n *\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport const PolicyUnavailable: typeof Internal.PolicyUnavailable =\n\tInternal.PolicyUnavailable\n\n/**\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport type PolicyUnavailable = Internal.PolicyUnavailable\n\n/**\n * The error when a decider must wait for an answer. `ticket` names the\n * request that waits, so the client can come back for the answer.\n *\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport const Pending: typeof Internal.Pending = Internal.Pending\n\n/**\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport type Pending = Internal.Pending\n\n/**\n * What a check is about: an act on a resource value, or an act on a kind of\n * resource. A check on a kind passes only when the policy allows the act on\n * every value of the kind. With a scope (`within`), it passes when the policy\n * allows the act on every value in the scope, and the scope is not empty.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Target<D> = Policy.Target<D> | Policy.KindTarget<D>\n\n/**\n * A {@link Target} with a field of any length, which a check checks with\n * `Policy.CheckField`.\n *\n * @stability stable\n * @category models\n * @since 2.1.0\n */\nexport type DeepTarget<D> = Policy.DeepTarget<D> | Policy.DeepKindTarget<D>\n\n/**\n * A request to the decider.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type DeciderRequest<D> = Policy.Request<D> | Policy.KindRequest<D>\n\n/**\n * The options of a guard.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type GuardOptions<D, E2, K extends string = Domain.Kind<D>> = {\n\t/** The error when the principal may not see the resource. */\n\treadonly hide: () => E2\n} & (\"read\" extends Domain.CommonAction<D, K>\n\t? {\n\t\t\t/**\n\t\t\t * The action that lets the principal see the resource. It must be an\n\t\t\t * action of every kind in `K`. The default is `\"read\"`.\n\t\t\t */\n\t\t\treadonly read?: Domain.CommonAction<D, K>\n\t\t}\n\t: {\n\t\t\t/**\n\t\t\t * The action that lets the principal see the resource. It must be an\n\t\t\t * action of every kind in `K`. Some kind in `K` has no `\"read\"`\n\t\t\t * action, so you must give it.\n\t\t\t */\n\t\t\treadonly read: Domain.CommonAction<D, K>\n\t\t})\n\n/**\n * The service.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Authorizer<D extends Domain.Any, E, R> {\n\treadonly domain: D\n\t/** The principal of the current request. */\n\treadonly principal: Effect.Effect<Domain.Principal<D>, E, R>\n\t/**\n\t * The policy of the principal of the current request. Its predicates have\n\t * the services of the layer. It may have predicates, so it is opaque.\n\t */\n\treadonly policy: Effect.Effect<\n\t\tPolicy.Policy<D, Condition.Opaque<E>>,\n\t\tPolicyUnavailable | E,\n\t\tR\n\t>\n\t/** Gives the decision of the policy. It does not ask the decider. */\n\treadonly decide: <const T extends Policy.DeepTarget<D>>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t) => Effect.Effect<Decision.Decision, PolicyUnavailable | E, R>\n\t/** Succeeds when the principal may do the act, and fails when it may not. */\n\treadonly check: <const T extends DeepTarget<D>>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t) => Effect.Effect<void, Forbidden | Pending | PolicyUnavailable | E, R>\n\t/**\n\t * Checks the read action first, and fails with the error of `hide` when the\n\t * principal may not see the resource. Then it checks the act. Use it to\n\t * answer \"not found\" to a principal that may not know that a resource\n\t * exists.\n\t */\n\treadonly guard: <const T extends Policy.DeepTarget<D>, E2>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t\toptions: GuardOptions<D, E2, T[\"resource\"][\"_tag\"]>,\n\t) => Effect.Effect<void, E2 | Forbidden | Pending | PolicyUnavailable | E, R>\n\t/**\n\t * Gives the condition on resource values that the principal may act on,\n\t * inside the scope of the target when it has one. Change it into a query\n\t * with `Condition.fold`. It is `False` when the principal may act on no\n\t * value, so the list is empty: it is not an error.\n\t */\n\treadonly filter: <const T extends Policy.DeepKindTarget<D>>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t) => Effect.Effect<\n\t\tCondition.Condition<\n\t\t\tPolicy.ResidualReads<D, T[\"kind\"]>,\n\t\t\tCondition.Opaque<E>\n\t\t>,\n\t\tPolicyUnavailable | E,\n\t\tR\n\t>\n\t/**\n\t * Tells if the principal may act on all, none or some of the values in\n\t * the scope of the target. See `Policy.coverage`. Use it to show a button\n\t * only when the answer is not `None`.\n\t */\n\treadonly coverage: <const T extends Policy.DeepKindTarget<D>>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t) => Effect.Effect<\n\t\tPolicy.Coverage<Policy.ResidualReads<D, T[\"kind\"]>, Condition.Opaque<E>>,\n\t\tPolicyUnavailable | E,\n\t\tR\n\t>\n\t/** Gives the fields of a value that the principal may use. */\n\treadonly permittedFields: (\n\t\ttarget: Policy.FieldlessTarget<D>,\n\t) => Effect.Effect<ReadonlyArray<string>, PolicyUnavailable | E, R>\n\t/**\n\t * Removes the cached policy of a principal, or of every principal. Call it\n\t * after a change to the rules or roles of a principal.\n\t */\n\treadonly invalidate: (principal?: Domain.Principal<D>) => Effect.Effect<void>\n}\n\n/**\n * The class made by {@link Service}. The static functions use the service\n * from the context.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface ServiceClass<\n\tSelf,\n\tId extends string,\n\tD extends Domain.Any,\n\tE,\n\tR,\n> extends Context.ServiceClass<Self, Id, Authorizer<D, E, R>> {\n\treadonly domain: D\n\t/** The Effect that gives the principal of the current request. */\n\treadonly principal: Effect.Effect<Domain.Principal<D>, E, R>\n\treadonly decide: <const T extends Policy.DeepTarget<D>>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t) => Effect.Effect<Decision.Decision, PolicyUnavailable | E, R | Self>\n\treadonly check: <const T extends DeepTarget<D>>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t) => Effect.Effect<\n\t\tvoid,\n\t\tForbidden | Pending | PolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly guard: <const T extends Policy.DeepTarget<D>, E2>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t\toptions: GuardOptions<D, E2, T[\"resource\"][\"_tag\"]>,\n\t) => Effect.Effect<\n\t\tvoid,\n\t\tE2 | Forbidden | Pending | PolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly filter: <const T extends Policy.DeepKindTarget<D>>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t) => Effect.Effect<\n\t\tCondition.Condition<\n\t\t\tPolicy.ResidualReads<D, T[\"kind\"]>,\n\t\t\tCondition.Opaque<E>\n\t\t>,\n\t\tPolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly coverage: <const T extends Policy.DeepKindTarget<D>>(\n\t\ttarget: T & Policy.CheckField<D, T>,\n\t) => Effect.Effect<\n\t\tPolicy.Coverage<Policy.ResidualReads<D, T[\"kind\"]>, Condition.Opaque<E>>,\n\t\tPolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly permittedFields: (\n\t\ttarget: Policy.FieldlessTarget<D>,\n\t) => Effect.Effect<ReadonlyArray<string>, PolicyUnavailable | E, R | Self>\n}\n\n/**\n * Any service class made by {@link Service}.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type AnyServiceClass = Context.Key<any, any> & {\n\treadonly domain: Domain.Any\n\treadonly principal: Effect.Effect<any, any, any>\n}\n\n/**\n * Makes an authorizer service class for a domain.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport const Service: <Self>() => <\n\tconst Id extends string,\n\tD extends Domain.Any,\n\tE = never,\n\tR = never,\n>(\n\tid: Id,\n\toptions: {\n\t\treadonly domain: D\n\t\t/** Gives the principal of the current request. */\n\t\treadonly principal: Effect.Effect<Domain.Principal<NoInfer<D>>, E, R>\n\t},\n) => ServiceClass<Self, Id, D, E, R> = Internal.Service as never\n\n/**\n * The options of {@link layer}.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Options<D extends Domain.Any, E, R, EL, RL, RP> {\n\t/**\n\t * Loads the policy of a principal. A failure becomes\n\t * {@link PolicyUnavailable}. The services of the predicates of the policy\n\t * are taken when the layer is built.\n\t */\n\treadonly policy: (\n\t\tprincipal: Domain.Principal<D>,\n\t) => Effect.Effect<Policy.Policy<D, Condition.Opaque<E, RP>>, EL, RL>\n\t/**\n\t * Answers when no rule gives an answer. Without a decider, such a request\n\t * fails with {@link Forbidden}.\n\t */\n\treadonly decider?: (\n\t\trequest: DeciderRequest<D>,\n\t) => Effect.Effect<Decision.Decision, Pending | E, R>\n\t/**\n\t * How the policies are kept. The default keeps 1000 policies for 30 seconds.\n\t * Give `false` to load the policy for each check.\n\t *\n\t * The key of a principal is the text of its JSON form, from the Schema of\n\t * the principal of the domain. A principal is kept only when the value that\n\t * the Schema decodes from that form is `Equal` to it. The loader always\n\t * gets that decoded copy, also with no cache, so two principals with one\n\t * key get one policy, and the cache can not change an answer. So the loader\n\t * must decide by the data of the principal, not by the identity of its\n\t * objects. A principal with no JSON form is not kept, and the loader gets\n\t * it as it is. Give `key` to make the key in another way.\n\t */\n\treadonly cache?:\n\t\t| {\n\t\t\t\treadonly capacity?: number\n\t\t\t\treadonly timeToLive?: Duration.Input\n\t\t\t\treadonly key?: (principal: Domain.Principal<D>) => string | undefined\n\t\t }\n\t\t| false\n}\n\n/**\n * Makes the layer of an authorizer.\n *\n * @stability stable\n * @category layers\n * @since 0.3.0\n */\nexport const layer: <\n\tSelf,\n\tId extends string,\n\tD extends Domain.Any,\n\tE,\n\tR,\n\tEL = never,\n\tRL = never,\n\tRP = never,\n>(\n\tservice: ServiceClass<Self, Id, D, E, R>,\n\toptions: Options<D, NoInfer<E>, NoInfer<R>, EL, RL, RP>,\n) => Layer.Layer<Self, never, RL | RP> = Internal.makeLayer as never\n"],"mappings":";;;;;;;;;;;;;;;;;AAqDA,MAAa,YAAuCA;;;;;;;;;AAiBpD,MAAa,oBACZC;;;;;;;;;AAiBD,MAAa,UAAmCC;;;;;;;;AA6NhD,MAAa,UAY0BC;;;;;;;;AAsDvC,MAAa,QAY4BC"}
1
+ {"version":3,"file":"Authorizer.js","names":["Internal.Forbidden","Internal.PolicyUnavailable","Internal.Pending","Internal.Service","Internal.makeLayer"],"sources":["../src/Authorizer.ts"],"sourcesContent":["/**\n * An authorizer is an Effect service that makes decisions for the principal\n * of the current request.\n *\n * You make the service class, in the same way as `Context.Service`. Give the\n * domain, and the Effect that gives the principal of the current request. The\n * error type and the service type of the checks come from that Effect:\n *\n * ```ts\n * class Auth extends Authorizer.Service<Auth>()(\"app/Auth\", {\n * domain: App,\n * principal: Identity,\n * }) {}\n * ```\n *\n * Then give a layer with {@link layer}. It says how to load the policy of a\n * principal. The policy of each principal is loaded once and kept in a cache\n * for a short time.\n *\n * Then use the service in a handler:\n *\n * ```ts\n * yield* Auth.check({ action: \"update\", resource: document })\n * ```\n *\n * A \"no\" answer goes into the error channel as {@link Forbidden}. When the\n * policy can not be loaded, the check fails with {@link PolicyUnavailable}.\n * So the check fails closed: an error is never a \"yes\".\n *\n * When no rule gives an answer, the authorizer asks the decider, if there is\n * one. A decider may answer at once, or fail with {@link Pending} when a person\n * or another service must answer later.\n *\n * @stability stable\n * @since 0.3.0\n */\nimport type * as Context from \"effect/Context\"\nimport type * as Duration from \"effect/Duration\"\nimport type * as Effect from \"effect/Effect\"\nimport type * as Layer from \"effect/Layer\"\nimport type * as Condition from \"./Condition.ts\"\nimport type * as Decision from \"./Decision.ts\"\nimport type * as Domain from \"./Domain.ts\"\nimport * as Internal from \"./internal/authorizer.ts\"\nimport type * as Policy from \"./Policy.ts\"\n\n/**\n * The error when a policy says no.\n *\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport const Forbidden: typeof Internal.Forbidden = Internal.Forbidden\n\n/**\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport type Forbidden = Internal.Forbidden\n\n/**\n * The error when the policy of the principal can not be loaded. The cause is\n * kept, but it is not shown to the client.\n *\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport const PolicyUnavailable: typeof Internal.PolicyUnavailable =\n\tInternal.PolicyUnavailable\n\n/**\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport type PolicyUnavailable = Internal.PolicyUnavailable\n\n/**\n * The error when a decider must wait for an answer. `ticket` names the\n * request that waits, so the client can come back for the answer.\n *\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport const Pending: typeof Internal.Pending = Internal.Pending\n\n/**\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport type Pending = Internal.Pending\n\n/**\n * What a check is about: an act on a resource value, or an act on a kind of\n * resource. A check on a kind passes only when the policy allows the act on\n * every value of the kind. With a scope (`within`), it passes when the policy\n * allows the act on every value in the scope, and the scope is not empty.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Target<D> = Policy.Target<D> | Policy.KindTarget<D>\n\n/**\n * A {@link Target} with a field of any length, which a check checks with\n * `Policy.CheckField`.\n *\n * @stability stable\n * @category models\n * @since 2.1.0\n */\nexport type DeepTarget<D> = Policy.DeepTarget<D> | Policy.DeepKindTarget<D>\n\n/**\n * A request to the decider.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type DeciderRequest<D> = Policy.Request<D> | Policy.KindRequest<D>\n\n/**\n * The options of a guard.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type GuardOptions<D, E2, K extends string = Domain.Kind<D>> = {\n\t/** The error when the principal may not see the resource. */\n\treadonly hide: () => E2\n} & (\"read\" extends Domain.CommonAction<D, K>\n\t? {\n\t\t\t/**\n\t\t\t * The action that lets the principal see the resource. It must be an\n\t\t\t * action of every kind in `K`. The default is `\"read\"`.\n\t\t\t */\n\t\t\treadonly read?: Domain.CommonAction<D, K>\n\t\t}\n\t: {\n\t\t\t/**\n\t\t\t * The action that lets the principal see the resource. It must be an\n\t\t\t * action of every kind in `K`. Some kind in `K` has no `\"read\"`\n\t\t\t * action, so you must give it.\n\t\t\t */\n\t\t\treadonly read: Domain.CommonAction<D, K>\n\t\t})\n\n/**\n * The service.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Authorizer<D extends Domain.Any, E, R> {\n\treadonly domain: D\n\t/** The principal of the current request. */\n\treadonly principal: Effect.Effect<Domain.Principal<D>, E, R>\n\t/**\n\t * The policy of the principal of the current request. Its predicates have\n\t * the services of the layer. It may have predicates, so it is opaque.\n\t */\n\treadonly policy: Effect.Effect<\n\t\tPolicy.Policy<D, Condition.Opaque<E>>,\n\t\tPolicyUnavailable | E,\n\t\tR\n\t>\n\t/** Gives the decision of the policy. It does not ask the decider. */\n\treadonly decide: <const T extends Policy.DeepTarget<D>>(\n\t\ttarget: Policy.Checked<D, T>,\n\t) => Effect.Effect<Decision.Decision, PolicyUnavailable | E, R>\n\t/** Succeeds when the principal may do the act, and fails when it may not. */\n\treadonly check: <const T extends DeepTarget<D>>(\n\t\ttarget: Policy.Checked<D, T>,\n\t) => Effect.Effect<void, Forbidden | Pending | PolicyUnavailable | E, R>\n\t/**\n\t * Checks the read action first, and fails with the error of `hide` when the\n\t * principal may not see the resource. Then it checks the act. Use it to\n\t * answer \"not found\" to a principal that may not know that a resource\n\t * exists.\n\t */\n\treadonly guard: <const T extends Policy.DeepTarget<D>, E2>(\n\t\ttarget: Policy.Checked<D, T>,\n\t\toptions: GuardOptions<D, E2, T[\"resource\"][\"_tag\"]>,\n\t) => Effect.Effect<void, E2 | Forbidden | Pending | PolicyUnavailable | E, R>\n\t/**\n\t * Gives the condition on resource values that the principal may act on,\n\t * inside the scope of the target when it has one. Change it into a query\n\t * with `Condition.fold`. It is `False` when the principal may act on no\n\t * value, so the list is empty: it is not an error.\n\t */\n\treadonly filter: <const T extends Policy.DeepKindTarget<D>>(\n\t\ttarget: Policy.Checked<D, T>,\n\t) => Effect.Effect<\n\t\tCondition.Condition<\n\t\t\tPolicy.ResidualReads<D, T[\"kind\"]>,\n\t\t\tCondition.Opaque<E>\n\t\t>,\n\t\tPolicyUnavailable | E,\n\t\tR\n\t>\n\t/**\n\t * Tells if the principal may act on all, none or some of the values in\n\t * the scope of the target. See `Policy.coverage`. Use it to show a button\n\t * only when the answer is not `None`.\n\t */\n\treadonly coverage: <const T extends Policy.DeepKindTarget<D>>(\n\t\ttarget: Policy.Checked<D, T>,\n\t) => Effect.Effect<\n\t\tPolicy.Coverage<Policy.ResidualReads<D, T[\"kind\"]>, Condition.Opaque<E>>,\n\t\tPolicyUnavailable | E,\n\t\tR\n\t>\n\t/** Gives the fields of a value that the principal may use. */\n\treadonly permittedFields: (\n\t\ttarget: Policy.FieldlessTarget<D>,\n\t) => Effect.Effect<ReadonlyArray<string>, PolicyUnavailable | E, R>\n\t/**\n\t * Removes the cached policy of a principal, or of every principal. Call it\n\t * after a change to the rules or roles of a principal.\n\t */\n\treadonly invalidate: (principal?: Domain.Principal<D>) => Effect.Effect<void>\n}\n\n/**\n * The class made by {@link Service}. The static functions use the service\n * from the context.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface ServiceClass<\n\tSelf,\n\tId extends string,\n\tD extends Domain.Any,\n\tE,\n\tR,\n> extends Context.ServiceClass<Self, Id, Authorizer<D, E, R>> {\n\treadonly domain: D\n\t/** The Effect that gives the principal of the current request. */\n\treadonly principal: Effect.Effect<Domain.Principal<D>, E, R>\n\treadonly decide: <const T extends Policy.DeepTarget<D>>(\n\t\ttarget: Policy.Checked<D, T>,\n\t) => Effect.Effect<Decision.Decision, PolicyUnavailable | E, R | Self>\n\treadonly check: <const T extends DeepTarget<D>>(\n\t\ttarget: Policy.Checked<D, T>,\n\t) => Effect.Effect<\n\t\tvoid,\n\t\tForbidden | Pending | PolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly guard: <const T extends Policy.DeepTarget<D>, E2>(\n\t\ttarget: Policy.Checked<D, T>,\n\t\toptions: GuardOptions<D, E2, T[\"resource\"][\"_tag\"]>,\n\t) => Effect.Effect<\n\t\tvoid,\n\t\tE2 | Forbidden | Pending | PolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly filter: <const T extends Policy.DeepKindTarget<D>>(\n\t\ttarget: Policy.Checked<D, T>,\n\t) => Effect.Effect<\n\t\tCondition.Condition<\n\t\t\tPolicy.ResidualReads<D, T[\"kind\"]>,\n\t\t\tCondition.Opaque<E>\n\t\t>,\n\t\tPolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly coverage: <const T extends Policy.DeepKindTarget<D>>(\n\t\ttarget: Policy.Checked<D, T>,\n\t) => Effect.Effect<\n\t\tPolicy.Coverage<Policy.ResidualReads<D, T[\"kind\"]>, Condition.Opaque<E>>,\n\t\tPolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly permittedFields: (\n\t\ttarget: Policy.FieldlessTarget<D>,\n\t) => Effect.Effect<ReadonlyArray<string>, PolicyUnavailable | E, R | Self>\n}\n\n/**\n * Any service class made by {@link Service}.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type AnyServiceClass = Context.Key<any, any> & {\n\treadonly domain: Domain.Any\n\treadonly principal: Effect.Effect<any, any, any>\n}\n\n/**\n * Makes an authorizer service class for a domain.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport const Service: <Self>() => <\n\tconst Id extends string,\n\tD extends Domain.Any,\n\tE = never,\n\tR = never,\n>(\n\tid: Id,\n\toptions: {\n\t\treadonly domain: D\n\t\t/** Gives the principal of the current request. */\n\t\treadonly principal: Effect.Effect<Domain.Principal<NoInfer<D>>, E, R>\n\t},\n) => ServiceClass<Self, Id, D, E, R> = Internal.Service as never\n\n/**\n * The options of {@link layer}.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Options<D extends Domain.Any, E, R, EL, RL, RP> {\n\t/**\n\t * Loads the policy of a principal. A failure becomes\n\t * {@link PolicyUnavailable}. The services of the predicates of the policy\n\t * are taken when the layer is built.\n\t */\n\treadonly policy: (\n\t\tprincipal: Domain.Principal<D>,\n\t) => Effect.Effect<Policy.Policy<D, Condition.Opaque<E, RP>>, EL, RL>\n\t/**\n\t * Answers when no rule gives an answer. Without a decider, such a request\n\t * fails with {@link Forbidden}.\n\t */\n\treadonly decider?: (\n\t\trequest: DeciderRequest<D>,\n\t) => Effect.Effect<Decision.Decision, Pending | E, R>\n\t/**\n\t * How the policies are kept. The default keeps 1000 policies for 30 seconds.\n\t * Give `false` to load the policy for each check.\n\t *\n\t * The key of a principal is the text of its JSON form, from the Schema of\n\t * the principal of the domain. A principal is kept only when the value that\n\t * the Schema decodes from that form is `Equal` to it. The loader always\n\t * gets that decoded copy, also with no cache, so two principals with one\n\t * key get one policy, and the cache can not change an answer. So the loader\n\t * must decide by the data of the principal, not by the identity of its\n\t * objects. A principal with no JSON form is not kept, and the loader gets\n\t * it as it is. Give `key` to make the key in another way.\n\t */\n\treadonly cache?:\n\t\t| {\n\t\t\t\treadonly capacity?: number\n\t\t\t\treadonly timeToLive?: Duration.Input\n\t\t\t\treadonly key?: (principal: Domain.Principal<D>) => string | undefined\n\t\t }\n\t\t| false\n}\n\n/**\n * Makes the layer of an authorizer.\n *\n * @stability stable\n * @category layers\n * @since 0.3.0\n */\nexport const layer: <\n\tSelf,\n\tId extends string,\n\tD extends Domain.Any,\n\tE,\n\tR,\n\tEL = never,\n\tRL = never,\n\tRP = never,\n>(\n\tservice: ServiceClass<Self, Id, D, E, R>,\n\toptions: Options<D, NoInfer<E>, NoInfer<R>, EL, RL, RP>,\n) => Layer.Layer<Self, never, RL | RP> = Internal.makeLayer as never\n"],"mappings":";;;;;;;;;;;;;;;;;AAqDA,MAAa,YAAuCA;;;;;;;;;AAiBpD,MAAa,oBACZC;;;;;;;;;AAiBD,MAAa,UAAmCC;;;;;;;;AA6NhD,MAAa,UAY0BC;;;;;;;;AAsDvC,MAAa,QAY4BC"}
@@ -410,7 +410,7 @@ type PathEnd<O, Name extends string, Done extends string, R extends PathRules, C
410
410
  * the paths that may come next after its last good part, so a type error
411
411
  * names them. For a union of types, a part must be in each of them.
412
412
  */
413
- type PathCheck<T, F extends string, R extends PathRules> = [T] extends [object] ? PathWalk<T, F, "", R, []> extends true ? F : NoInfer<PathWalk<T, F, "", R, []>> : never;
413
+ type PathCheck<T, F extends string, R extends PathRules> = [T] extends [object] ? F extends unknown ? PathWalk<T, F, "", R, []> extends true ? F : NoInfer<PathWalk<T, F, "", R, []>> : never : never;
414
414
  /**
415
415
  * A path of `T` that a condition may read, as one of {@link FieldPath}, of
416
416
  * any length up to about 1000 parts. It is `F` when `F` is such a path, and
@@ -844,9 +844,11 @@ export type PlainCondition = Condition<any>;
844
844
  * The Schema of a condition with no predicate. It checks the shape only. Use
845
845
  * `Policy.schema` to check the field names against a domain too.
846
846
  *
847
- * The decoder takes at most 500 levels of conditions, and at most 1000000
848
- * objects and array items, with a shared object counted for each place. It
849
- * reads only the own data fields of the input.
847
+ * The decoder takes the default limits: at most `conditionNodes` nodes,
848
+ * 1000000, and `jsonNodes` objects and array items, 10000000, with a shared
849
+ * object counted for each place. It stops at the first one past a limit. It
850
+ * takes any number of levels, and it reads only the own data fields of the
851
+ * input. Use `Policy.schema` for the limits of a domain.
850
852
  *
851
853
  * @stability stable
852
854
  * @category schemas
@@ -1 +1 @@
1
- {"version":3,"file":"Condition.d.ts","names":["Nodes.Scalar","Nodes.Literal","Nodes.PrincipalRef","Nodes.CompareOperator","Nodes.True","Nodes.False","Nodes.Compare","Nodes.In","Nodes.Exists","Nodes.Under","Nodes.And","Nodes.Or","Nodes.Not","Nodes.Predicate","Nodes.Node","Resource.PathSegment","Search.Example","Search.Satisfiability"],"sources":["../src/Condition.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;YA6DY,SAASA;;;;;;;;YAST,UAAUC;;;;;;;;;;;;;;YAeV,eAAeC;;;;;;;;;;;YAYf,IAAI,GAAG,aAAa;WACtB,cAAc;WACd,eAAe,WAAW;;;;;;;YAQxB,UAAU,UAAU;;;;;;YAOpB,kBAAkBC;;;;;;;;YASlB,OAAOC;;;;;;;;YASP,QAAQC;;;;;;;;;;YAWR,UAAUC;;;;;;;;YASV,KAAKC;;;;;;;;YASL,SAASC;;;;;;;;;YAUT,QAAQC;;;;;;YAOR,MAAMC;;;;;;YAON,KAAKC;;;;;;YAOL,MAAMC;;;;;;;;YASN,YAAYC;;;;;;;;;;YAWZ,MAAMC;;;;;;;;;iBAUD,WAAW,eAAe;WACjC;aAAsB,GAAG;aAAY,GAAG;;;;;;;;;;;YAWtC,QAAQ,KAAK,UAAU,aAAa,SAAS,MAAM;;;;;;;;;YAUnD,WAAW,KAAK,UAAU,aAAa,UAAU,KAAK;;;;;;;;YAStD,SAAS,KACpB,UAAU,aAAa,SAAS,MAAM,OAAO,KAAK;;;;;;;;;iBAUlC,MAAM,GAAG;WAChB,OAAO;WACP,WAAW;;;;;;;;;;;;;;;;YAiBT,UAAU,aAAa,aAAa;WACtC,WAAW,OAAO;WAClB,iBAAiB;;;;;;;;;YAUf,MAAM;;;;;;;;;YAUN,QAAQ,MAAM;WACd,WAAW,aAAa;KAEjC;;;;;;;;YAUS,SAAS,KAAK;WAAqB,uBAAuB;IACnE;KAGE;;;;;;KAMA,QACF,gCACA,uBACA,QAAQ,4BACR,QAAQ,mBACR,OACA,MACA,aACA,OAAO,kBACP,WAAW,aACX,SAAS,WACT,SAAS,WACT,SAAS,oBACT,MA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BAAuB;;;;;;;;;;qBAkFvB;GACX,GACA,aAAa,YAAY,MACtB,WAAW,QAAQ,OAAO,OAAO,GAAG;GACvC,GACA,WAAW,KACX,aAAa,YAAY,KACvB,OAAO,OAAO,GAAG;;;;;;;;;qBAyBR,SAAM,WAAe,QAAM;;;;;;;;;;YAc5B,UAAUC;;;;;;;;;;;;YAaV,iBAAiBC;;;;;;;;iBASZ;;;;;WAKP,SAAS,OAAO;;WAEhB;;;;;;;;;;;;;;;;;;;;;;;;;;qBA2BG,cAAW,WACZ,KAAG,UACL,uBACP;;;;;;;;YAkBS;WACE;WAA0B,OAAO;;WACjC;WAA4B;;;;;;;;;YAS9B;WACE;;WACA;;WAEF;WACA,IAAI;WACJ;WACA,OAAO;;WAGP;WACA;WACA,QAAQ,cAAc;;WAEpB;WAAyB;;WACzB;WAAwB,QAAQ,cAAc;;WAEhD;WACA,YAAY,cAAc;;WAExB;WAAsB,WAAW;;;;;;;;;;;;YAcnC,iBAAiB;;;;;;;;;;;;;qBAchB,QAAQ,OAAO,MAAM,gBAAgB"}
1
+ {"version":3,"file":"Condition.d.ts","names":["Nodes.Scalar","Nodes.Literal","Nodes.PrincipalRef","Nodes.CompareOperator","Nodes.True","Nodes.False","Nodes.Compare","Nodes.In","Nodes.Exists","Nodes.Under","Nodes.And","Nodes.Or","Nodes.Not","Nodes.Predicate","Nodes.Node","Resource.PathSegment","Search.Example","Search.Satisfiability"],"sources":["../src/Condition.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;YA6DY,SAASA;;;;;;;;YAST,UAAUC;;;;;;;;;;;;;;YAeV,eAAeC;;;;;;;;;;;YAYf,IAAI,GAAG,aAAa;WACtB,cAAc;WACd,eAAe,WAAW;;;;;;;YAQxB,UAAU,UAAU;;;;;;YAOpB,kBAAkBC;;;;;;;;YASlB,OAAOC;;;;;;;;YASP,QAAQC;;;;;;;;;;YAWR,UAAUC;;;;;;;;YASV,KAAKC;;;;;;;;YASL,SAASC;;;;;;;;;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AEpB;WAAyB;;WACzB;WAAwB,QAAQ,cAAc;;WAEhD;WACA,YAAY,cAAc;;WAExB;WAAsB,WAAW;;;;;;;;;;;;YAcnC,iBAAiB;;;;;;;;;;;;;;;qBAgBhB,QAAQ,OAAO,MAAM,gBAAgB"}
package/dist/Condition.js CHANGED
@@ -298,9 +298,11 @@ const satisfiable = (condition, options = {}) => satisfiable$1(nodeOf(condition)
298
298
  * The Schema of a condition with no predicate. It checks the shape only. Use
299
299
  * `Policy.schema` to check the field names against a domain too.
300
300
  *
301
- * The decoder takes at most 500 levels of conditions, and at most 1000000
302
- * objects and array items, with a shared object counted for each place. It
303
- * reads only the own data fields of the input.
301
+ * The decoder takes the default limits: at most `conditionNodes` nodes,
302
+ * 1000000, and `jsonNodes` objects and array items, 10000000, with a shared
303
+ * object counted for each place. It stops at the first one past a limit. It
304
+ * takes any number of levels, and it reads only the own data fields of the
305
+ * input. Use `Policy.schema` for the limits of a domain.
304
306
  *
305
307
  * @stability stable
306
308
  * @category schemas
@@ -1 +1 @@
1
- {"version":3,"file":"Condition.js","names":["Nodes.literal","Nodes.Compare","Nodes.And","Nodes.Or","Nodes.Not","Nodes.In","Nodes.Exists","Nodes.Under","Nodes.principalRef","Nodes.Predicate","Nodes.always","Nodes.never","Nodes.toNode","Algebra.provide","Algebra.evaluate","Algebra.evaluateSync","Algebra.simplify","Algebra.partial","Trampoline.run","Algebra.fields","Search.satisfiable","Search.kindsIn","Catalog.catalogOf","Nodes.isNode","Json.decode","Json.toJson"],"sources":["../src/Condition.ts"],"sourcesContent":["/**\n * A condition is a test on a resource value. A rule applies only when its\n * condition is true.\n *\n * A condition is plain data: a tree of nodes. So you can:\n * - test it on a value with {@link evaluate};\n * - put the principal into it and make it smaller with {@link partial}, which\n * gives a \"residual\" condition: the part that still depends on the\n * resource;\n * - change it into a database query with {@link fold};\n * - keep it as JSON with {@link schema}.\n *\n * Make conditions with a {@link Builder}. A rule gives you a builder for its\n * resource, so the field names and the value types are checked.\n *\n * {@link Builder.predicate} is the one way out of plain data. A predicate runs\n * any `Effect`. Its error type and its service type go into the type of the\n * check. A rule with a predicate can not become JSON, and the type system\n * stops you when you try.\n *\n * @stability stable\n * @since 0.3.0\n */\n// A predicate keeps its error type and service type in the public types. The\n// code below works on the nodes with no types, where they are `unknown`, so\n// the language service check for `unknown` in an Effect is off here.\n// @effect-diagnostics anyUnknownInErrorContext:off\nimport * as Arr from \"effect/Array\"\nimport type * as BigDecimal from \"effect/BigDecimal\"\nimport type * as Cause from \"effect/Cause\"\nimport type * as Chunk from \"effect/Chunk\"\nimport type * as DateTime from \"effect/DateTime\"\nimport type * as Duration from \"effect/Duration\"\nimport type * as Exit from \"effect/Exit\"\nimport type * as HashMap from \"effect/HashMap\"\nimport type * as HashSet from \"effect/HashSet\"\nimport type * as Option from \"effect/Option\"\nimport type * as Redacted from \"effect/Redacted\"\nimport type * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport { dual } from \"effect/Function\"\nimport { hasProperty } from \"effect/Predicate\"\nimport * as Schema from \"effect/Schema\"\nimport * as SchemaIssue from \"effect/SchemaIssue\"\nimport * as SchemaTransformation from \"effect/SchemaTransformation\"\nimport * as Result from \"effect/Result\"\nimport * as Algebra from \"./internal/algebra.ts\"\nimport * as Catalog from \"./internal/catalog.ts\"\nimport * as Json from \"./internal/json.ts\"\nimport * as Nodes from \"./internal/nodes.ts\"\nimport * as Search from \"./internal/search.ts\"\nimport * as Trampoline from \"./internal/trampoline.ts\"\nimport * as Resource from \"./Resource.ts\"\n\n/**\n * A value that a condition can compare.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Scalar = Nodes.Scalar\n\n/**\n * A fixed value in a condition.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Literal = Nodes.Literal\n\n/**\n * A field of the principal. {@link partial} puts the value of the field in its\n * place.\n *\n * A principal field that is `null` or missing has no value. A `Compare`, `In`\n * or `Under` test with it is always false, also with `ne`. So a principal with\n * no id never matches a resource with no owner. `not` still turns false into\n * true.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type PrincipalRef = Nodes.PrincipalRef\n\n/**\n * A field of the principal with a known value type `A`, from a principal of\n * the type `P`. The type fields are only in the types. A test with the\n * reference reads a principal of the type `P`, so it can not go into a rule\n * of a domain with another principal.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Ref<A, P = never> = PrincipalRef & {\n\treadonly \"~Ref\": () => A\n\treadonly \"~Principal\": (principal: P) => void\n}\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Operand = Literal | PrincipalRef\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type CompareOperator = Nodes.CompareOperator\n\n/**\n * Always true.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type True = Nodes.True\n\n/**\n * Always false.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type False = Nodes.False\n\n/**\n * Compares a field with a value. A missing field has the value `null`. `lt`,\n * `lte`, `gt` and `gte` are false when the two sides are not both numbers or\n * both strings.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Compare = Nodes.Compare\n\n/**\n * True when a field is equal to one of the values.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type In = Nodes.In\n\n/**\n * True when a field is not `null` and not missing.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Exists = Nodes.Exists\n\n/**\n * True when the path of the resource starts with the prefix. A resource with\n * no path is never under a prefix.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Under = Nodes.Under\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type And = Nodes.And\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Or = Nodes.Or\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Not = Nodes.Not\n\n/**\n * A test that runs an `Effect`. It can not become JSON or a query.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Predicate = Nodes.Predicate\n\n/**\n * The nodes of a condition, without types. Each node is a class, and only the\n * builder, the functions of this module and the Schema make one. So a plain\n * object, or a spread of a node, is not a node.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Ast = Nodes.Node\n\n/**\n * The mark of a condition with a predicate. `E` and `R` are the error type\n * and the service type of its predicates.\n *\n * @stability stable\n * @category models\n * @since 2.0.0\n */\nexport interface Opaque<out E = never, out R = never> {\n\treadonly \"~Opaque\": { readonly E: E; readonly R: R }\n}\n\n/**\n * The error type of the predicates of a mark `X`. A mark that is not an\n * {@link Opaque}, as `unknown` or `object`, may have any error.\n *\n * @stability stable\n * @category utility types\n * @since 2.0.0\n */\nexport type ErrorOf<X> = X extends Opaque<infer E, infer _R> ? E : unknown\n\n/**\n * The service type of the predicates of a mark `X`. A mark that is not an\n * {@link Opaque}, as `unknown` or `object`, may need any service.\n *\n * @stability stable\n * @category utility types\n * @since 2.0.0\n */\nexport type ServicesOf<X> = X extends Opaque<infer _E, infer R> ? R : unknown\n\n/**\n * The mark `X` with no services.\n *\n * @stability stable\n * @category utility types\n * @since 2.0.0\n */\nexport type Provided<X> =\n\tX extends Opaque<infer E, infer _R> ? Opaque<E> : Opaque<unknown>\n\n/**\n * What the predicates of a condition read: a resource value of the type `V`\n * and a principal of the type `P`. It is only in the types.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport interface Reads<V, P> {\n\treadonly value: V\n\treadonly principal: P\n}\n\n/**\n * A condition. `I` is what its tests read: see {@link Reads}. `X` is\n * {@link Opaque} when the condition has a predicate, and `never` when it is\n * plain data. A plain condition can become JSON or a query.\n *\n * The two type fields are only in the types. `I` goes into a function as an\n * input, so a condition that reads a `Post` does not fit a rule for a\n * `Comment`. `X` comes out of a function, so a plain condition fits where a\n * condition with predicates may go.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Condition<I = unknown, X = never> = Ast & {\n\treadonly \"~Reads\": (reads: I) => void\n\treadonly \"~Opaque\": () => X\n}\n\n/**\n * Any condition.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Any = Condition<any, any>\n\n/**\n * What the tests of a condition read. For a union of conditions, it is what\n * all of them read.\n *\n * @stability stable\n * @category utility types\n * @since 1.0.0\n */\nexport type ReadsOf<C> = [C] extends [\n\t{ readonly \"~Reads\": (reads: infer I) => void },\n]\n\t? I\n\t: unknown\n\n/**\n * The mark of a condition: {@link Opaque} when it has a predicate.\n *\n * @stability stable\n * @category utility types\n * @since 0.3.0\n */\nexport type OpaqueOf<C> = C extends { readonly \"~Opaque\": () => infer X }\n\t? X\n\t: never\n\ntype Leaf = string | number | boolean | bigint | symbol | null | undefined\n/**\n * Values of a class that keeps its data inside. A path does not go into them,\n * as in the field paths of a resource, so a field with such a value is one\n * field. A condition can test only if it exists.\n */\ntype Whole =\n\t| ReadonlyMap<unknown, unknown>\n\t| ReadonlySet<unknown>\n\t| HashMap.HashMap<unknown, unknown>\n\t| HashSet.HashSet<unknown>\n\t| Date\n\t| URL\n\t| Uint8Array\n\t| Option.Option<unknown>\n\t| BigDecimal.BigDecimal\n\t| Duration.Duration\n\t| DateTime.DateTime\n\t| Redacted.Redacted<unknown>\n\t| Chunk.Chunk<unknown>\n\t| Cause.Cause<unknown>\n\t| Result.Result<unknown, unknown>\n\t| Exit.Exit<unknown, unknown>\n\t| File\n\t| FormData\n\t| RegExp\n\t| URLSearchParams\ntype PreviousDepth = [never, 0, 1, 2, 3]\ntype FieldPathInternal<\n\tT,\n\tDepth extends number,\n\tArrays extends boolean,\n\tParents extends boolean = false,\n> = [Depth] extends [never]\n\t? never\n\t: {\n\t\t\t// A record with number keys has number keys, as `counts.1`.\n\t\t\t[K in keyof T & (string | number)]-?: PathsOf<\n\t\t\t\t`${K}`,\n\t\t\t\tNonNullable<T[K]>,\n\t\t\t\tDepth,\n\t\t\t\tArrays,\n\t\t\t\tParents\n\t\t\t>\n\t\t}[keyof T & (string | number)]\n\n/**\n * The paths of one field `K` with the values `V`. Each kind of value in `V`\n * gives its own paths, so a field that holds a string or a struct is a field,\n * and the fields of the struct are fields too. A function is no field.\n */\ntype PathsOf<\n\tK extends string,\n\tV,\n\tDepth extends number,\n\tArrays extends boolean,\n\tParents extends boolean,\n> =\n\t// A field that is only ever `null` or missing is a field too, and so is a\n\t// field that may hold any value, as one of `Schema.Unknown` may.\n\t| ([V] extends [never] ? K : {} extends V ? K : never)\n\t| ([Extract<V, Leaf | Whole>] extends [never] ? never : K)\n\t| ([Extract<V, ReadonlyArray<unknown>>] extends [never]\n\t\t\t? never\n\t\t\t: Arrays extends true\n\t\t\t\t? K\n\t\t\t\t: never)\n\t// A condition reads a field below `K` only when `K` holds plain data: a\n\t// list, a whole value such as a date, or a function may have a getter or a\n\t// method with the name, so the binding does not take such a read. A rule\n\t// or a request names a field and does not read it, so it may.\n\t| (Arrays extends true\n\t\t\t? ObjectPaths<\n\t\t\t\t\tK,\n\t\t\t\t\tExclude<V, Leaf | Whole | Function | ReadonlyArray<unknown>>,\n\t\t\t\t\tDepth,\n\t\t\t\t\tArrays,\n\t\t\t\t\tParents\n\t\t\t\t>\n\t\t\t: [Extract<V, Whole | Function | ReadonlyArray<unknown>>] extends [never]\n\t\t\t\t? ObjectPaths<K, Exclude<V, Leaf>, Depth, Arrays, Parents>\n\t\t\t\t: never)\n\n/** The paths of a field `K` that holds the objects `O`, and of the fields below. */\ntype ObjectPaths<\n\tK extends string,\n\tO,\n\tDepth extends number,\n\tArrays extends boolean,\n\tParents extends boolean,\n> = [O] extends [never]\n\t? never\n\t: // A record is one field to a rule or a request, as `permittedFields`\n\t\t// lists it.\n\t\t| (Parents extends true\n\t\t\t\t? K\n\t\t\t\t: Arrays extends true\n\t\t\t\t\t? string extends keyof O\n\t\t\t\t\t\t? K\n\t\t\t\t\t\t: number extends keyof O\n\t\t\t\t\t\t\t? K\n\t\t\t\t\t\t\t: never\n\t\t\t\t\t: never)\n\t\t| `${K}.${FieldPathInternal<O, PreviousDepth[Depth], Arrays, Parents>}`\n\n/**\n * The paths of the fields of `T` that hold one value, with dots for nested\n * fields. Arrays are left out. A map, a set, a date, a URL, a byte array, an\n * `Option` and the other value types of Effect, such as `BigDecimal` and\n * `Duration`, are one field, and a path does not go into them. A path does\n * not go into a field that may hold one of them or a list either. The type\n * goes down four levels, so type checking stays fast. For a union of types,\n * only the common fields are paths.\n *\n * @stability stable\n * @category utility types\n * @since 0.3.0\n */\nexport type FieldPath<T> = [T] extends [object]\n\t? FieldPathInternal<T, 4, false>\n\t: never\n\n/**\n * The paths of the fields of `T` that a rule or a request may name, as in\n * `Rule.Options.fields`. They are the paths of {@link FieldPath}, and the\n * paths of arrays too: a rule may allow or deny a whole array field, and\n * `permittedFields` lists it.\n *\n * @stability stable\n * @category utility types\n * @since 1.0.0\n */\nexport type FieldSelector<T> = [T] extends [object]\n\t? FieldPathInternal<T, 4, true>\n\t: never\n\n/**\n * The names that the `fields` of a rule may have: the paths of\n * {@link FieldSelector}, and the paths of the structs above them. A name of a\n * struct covers the fields below it.\n *\n * @stability stable\n * @category utility types\n * @since 2.0.0\n */\nexport type FieldName<T> = [T] extends [object]\n\t? FieldPathInternal<T, 4, true, true>\n\t: never\n\n/**\n * The value type that fits every field in `F`. For one field, it is the type\n * of the field. For a union of fields, it is the values that each of them can\n * hold, so a value of a union type can not test a field of another type. For\n * a union of data types, as for a rule on two kinds, it is the values that\n * the field can hold in each of them.\n *\n * @stability stable\n * @category utility types\n * @since 1.0.0\n */\nexport type FieldValue<Data, F extends string> = (\n\tData extends unknown\n\t\t? F extends unknown\n\t\t\t? (value: PathValue<Data, F>) => void\n\t\t\t: never\n\t\t: never\n) extends (value: infer V) => void\n\t? V\n\t: never\n\ntype Normalize<A> = Exclude<A, undefined> | (undefined extends A ? null : never)\n\n/**\n * The type of the field of `T` at `Path`. A field that may be missing may also\n * be `null`. Each type of a union gives its own value: a field below a value\n * that is not an object, as below a string, is `null`, as a read of it is.\n *\n * @stability stable\n * @category utility types\n * @since 0.3.0\n */\nexport type PathValue<T, Path extends string> = ValueWalk<T, Path>\n\n/**\n * The values of the part `Name` of each type of `U`. A part below a value\n * that is not an object, as below a string or `null`, is `null`.\n */\ntype StepValue<U, Name extends string> = U extends unknown\n\t? U extends object\n\t\t? ChildOf<U, Name>\n\t\t: null\n\t: never\n\n/**\n * Walks a path two parts at a time, with the values of each step. The type\n * checker takes at most about 1000 steps of a type that calls itself, so a\n * walk of one part at a time would stop before a path of 1000 parts.\n */\ntype ValueWalk<\n\tU,\n\tPath extends string,\n> = Path extends `${infer A}.${infer B}.${infer Rest}`\n\t? ValueWalk<StepValue<StepValue<U, A>, B>, Rest>\n\t: Path extends `${infer A}.${infer B}`\n\t\t? Normalize<StepValue<StepValue<U, A>, B>>\n\t\t: Normalize<StepValue<U, Path>>\n\n/**\n * The type of the part `Name` of `T`. A part of a path is text, so the part\n * `\"1\"` names the number key `1` too, as of a record with number keys.\n */\ntype ChildOf<T, Name extends string> = Name extends keyof T\n\t? T[Name]\n\t: Name extends `${infer N extends number}`\n\t\t? N extends keyof T\n\t\t\t? T[N]\n\t\t\t: number extends keyof T\n\t\t\t\t? T[number]\n\t\t\t\t: never\n\t\t: never\n\n/**\n * What a path may do, for one use of it: go below a list or a whole value,\n * as a rule or a request may, and end at a struct, as the fields of a rule\n * may. See {@link FieldPath}, {@link FieldSelector} and {@link FieldName},\n * which list the short paths with the same rules.\n */\ninterface PathRules {\n\treadonly arrays: boolean\n\treadonly parents: boolean\n}\n\n/** The rules of a path that a condition reads. */\ninterface ReadRules {\n\treadonly arrays: false\n\treadonly parents: false\n}\n\n/** The rules of the field of a request. */\ninterface SelectRules {\n\treadonly arrays: true\n\treadonly parents: false\n}\n\n/** The rules of a field of a rule, which may name a struct. */\ninterface NameRules {\n\treadonly arrays: true\n\treadonly parents: true\n}\n\n/** The objects below a field with the values `V`: see `PathsOf`. */\ntype ObjectsBelow<V, Arrays extends boolean> = Arrays extends true\n\t? Exclude<V, Leaf | Whole | Function | ReadonlyArray<unknown>>\n\t: [Extract<V, Whole | Function | ReadonlyArray<unknown>>] extends [never]\n\t\t? Exclude<V, Leaf>\n\t\t: never\n\n/** Tests if `Name` names a field of every object of `O`, as `keyof` does. */\ntype HasPart<O, Name extends string> = Name extends keyof O\n\t? true\n\t: Name extends `${infer N extends number}`\n\t\t? N extends keyof O\n\t\t\t? true\n\t\t\t: number extends keyof O\n\t\t\t\t? true\n\t\t\t\t: false\n\t\t: false\n\n/**\n * The objects below the part `Name` of the objects `O`, for a path that goes\n * on, or `never` when it can not go on.\n */\ntype PathStep<O, Name extends string, R extends PathRules> =\n\tHasPart<O, Name> extends true\n\t\t? ObjectsBelow<NonNullable<ChildOf<O, Name>>, R[\"arrays\"]>\n\t\t: never\n\n/** Tests if a path may end at a field with the values `V`: see `PathsOf`. */\ntype EndsAt<V, R extends PathRules, Last extends boolean> = [V] extends [never]\n\t? true\n\t: {} extends V\n\t\t? true\n\t\t: [Extract<V, Leaf | Whole>] extends [never]\n\t\t\t? R[\"arrays\"] extends true\n\t\t\t\t? [Extract<V, ReadonlyArray<unknown>>] extends [never]\n\t\t\t\t\t? EndsAtObjects<ObjectsBelow<V, true>, R, Last>\n\t\t\t\t\t: true\n\t\t\t\t: false\n\t\t\t: true\n\n/**\n * Tests if a path may end at a field that holds the objects `O`: a field of a\n * rule may name a struct, and a request may name a record, or a struct at\n * the last part that a path may have.\n */\ntype EndsAtObjects<O, R extends PathRules, Last extends boolean> = [O] extends [\n\tnever,\n]\n\t? false\n\t: R[\"parents\"] extends true\n\t\t? true\n\t\t: string extends keyof O\n\t\t\t? true\n\t\t\t: number extends keyof O\n\t\t\t\t? true\n\t\t\t\t: Last\n\n/** The paths one part below `Done`, as the names that may come next. */\ntype NextNames<O, Done extends string> = `${Done}${keyof O & (string | number)}`\n\n/**\n * Walks a path two parts at a time, from the objects `O`. It gives `true`\n * for a path that the rules `R` take, or the names that may come next after\n * the last good part. `Count` counts the parts before `F`, so the walk knows\n * the last part that a path may have: part 1000, the default of\n * `Limits.fieldPathParts`.\n */\ntype PathWalk<\n\tO,\n\tF extends string,\n\tDone extends string,\n\tR extends PathRules,\n\tCount extends ReadonlyArray<0>,\n> = F extends `${infer A}.${infer B}.${infer Rest}`\n\t? PathStep<O, A, R> extends infer O1\n\t\t? [O1] extends [never]\n\t\t\t? NextNames<O, Done>\n\t\t\t: PathStep<O1, B, R> extends infer O2\n\t\t\t\t? [O2] extends [never]\n\t\t\t\t\t? NextNames<O1, `${Done}${A}.`>\n\t\t\t\t\t: PathWalk<O2, Rest, `${Done}${A}.${B}.`, R, [...Count, 0, 0]>\n\t\t\t\t: never\n\t\t: never\n\t: F extends `${infer A}.${infer B}`\n\t\t? PathStep<O, A, R> extends infer O1\n\t\t\t? [O1] extends [never]\n\t\t\t\t? NextNames<O, Done>\n\t\t\t\t: PathEnd<O1, B, `${Done}${A}.`, R, [...Count, 0]>\n\t\t\t: never\n\t\t: PathEnd<O, F, Done, R, Count>\n\ntype PathEnd<\n\tO,\n\tName extends string,\n\tDone extends string,\n\tR extends PathRules,\n\tCount extends ReadonlyArray<0>,\n> =\n\tHasPart<O, Name> extends true\n\t\t? EndsAt<\n\t\t\t\tNonNullable<ChildOf<O, Name>>,\n\t\t\t\tR,\n\t\t\t\tCount[\"length\"] extends 999 ? true : false\n\t\t\t> extends true\n\t\t\t? true\n\t\t\t: // The name is a field, but a path may not end at it, as at a struct\n\t\t\t\t// for a condition: the paths below it may come next. The names of\n\t\t\t\t// this place would hold the name itself.\n\t\t\t\tNextNames<\n\t\t\t\t\tObjectsBelow<NonNullable<ChildOf<O, Name>>, R[\"arrays\"]>,\n\t\t\t\t\t`${Done}${Name}.`\n\t\t\t\t>\n\t\t: NextNames<O, Done>\n\n/**\n * Checks one field path `F` of `T`, of any length up to about 1000 parts.\n * It gives `F` for a path that the rules `R` take. For another path, it gives\n * the paths that may come next after its last good part, so a type error\n * names them. For a union of types, a part must be in each of them.\n */\ntype PathCheck<T, F extends string, R extends PathRules> = [T] extends [object]\n\t? PathWalk<T, F, \"\", R, []> extends true\n\t\t? F\n\t\t: // The names come from parts of `F`. Inference must not find `F` in\n\t\t\t// them, so a call gets its `F` from the path that it gives.\n\t\t\tNoInfer<PathWalk<T, F, \"\", R, []>>\n\t: never\n\n/**\n * A path of `T` that a condition may read, as one of {@link FieldPath}, of\n * any length up to about 1000 parts. It is `F` when `F` is such a path, and\n * the names that may come next when it is not.\n *\n * @stability stable\n * @category utility types\n * @since 2.1.0\n */\nexport type ReadPath<T, F extends string> = PathCheck<T, F, ReadRules>\n\n/**\n * A path of `T` that a request may name, as one of {@link FieldSelector}, of\n * any length up to about 1000 parts. See {@link ReadPath}.\n *\n * @stability stable\n * @category utility types\n * @since 2.1.0\n */\nexport type SelectPath<T, F extends string> = PathCheck<T, F, SelectRules>\n\n/**\n * A path of `T` that a field of a rule may name, as one of\n * {@link FieldName}, of any length up to about 1000 parts. See\n * {@link ReadPath}.\n *\n * @stability stable\n * @category utility types\n * @since 2.1.0\n */\nexport type NamePath<T, F extends string> = PathCheck<T, F, NameRules>\n\n/** A path that a condition may read, with an ordered value. */\ntype OrderedReadPath<T, F extends string> =\n\tReadPath<T, F> extends F\n\t\t? Exclude<PathValue<T, F>, null> extends number | string\n\t\t\t? F\n\t\t\t: never\n\t\t: ReadPath<T, F>\n\n/** A path that a condition may read, with a scalar value. */\ntype ScalarReadPath<T, F extends string> =\n\tReadPath<T, F> extends F\n\t\t? PathValue<T, F> extends Scalar\n\t\t\t? F\n\t\t\t: never\n\t\t: ReadPath<T, F>\n\n/**\n * A value for a field of type `A`: a fixed value, or a field of the principal\n * with the same type.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type OperandOf<A, P = never> = Extract<A, Scalar> | Ref<A, P>\n\n/**\n * A test made by a {@link Builder}. It runs no code, but it keeps the value\n * type of its resource, so a test on the fields of one resource can not go\n * into a rule for another resource. A test with a field of the principal\n * keeps the principal type `P` too.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport type Test<Value, P = unknown> = Condition<Reads<Value, P>>\n\n/**\n * The principal type that a test reads: the principal of each field of the\n * principal in the values `V`, and `unknown` when there is none. A reference\n * from another builder keeps the principal of that builder.\n */\ntype PrincipalOf<V, _P> = [Extract<V, PrincipalRef>] extends [never]\n\t? unknown\n\t: [Extract<V, PrincipalRef>] extends [\n\t\t\t\t{ readonly \"~Principal\": (principal: infer Q) => void },\n\t\t ]\n\t\t? Q\n\t\t: unknown\n\n/**\n * Makes conditions for a resource with the data type `Data` and the value type\n * `Value`, and a principal with the type `P`.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Builder<Data, Value, P> {\n\t/** The field is equal to the value. */\n\treadonly eq: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<FieldValue<Data, F>, any>,\n\t>(\n\t\tfield: ReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\t/** The field is not equal to the value. */\n\treadonly ne: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<FieldValue<Data, F>, any>,\n\t>(\n\t\tfield: ReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\treadonly lt: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<Exclude<FieldValue<Data, F>, null>, any>,\n\t>(\n\t\tfield: OrderedReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\treadonly lte: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<Exclude<FieldValue<Data, F>, null>, any>,\n\t>(\n\t\tfield: OrderedReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\treadonly gt: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<Exclude<FieldValue<Data, F>, null>, any>,\n\t>(\n\t\tfield: OrderedReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\treadonly gte: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<Exclude<FieldValue<Data, F>, null>, any>,\n\t>(\n\t\tfield: OrderedReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\t/** The field is equal to one of the values. */\n\treadonly in: <\n\t\tconst F extends string,\n\t\tconst Vs extends ReadonlyArray<OperandOf<FieldValue<Data, F>, any>>,\n\t>(\n\t\tfield: ReadPath<Data, F>,\n\t\tvalues: Vs,\n\t) => Test<Value, PrincipalOf<Vs[number], P>>\n\t/** The field has a value that is not `null`. */\n\treadonly exists: <const F extends string>(\n\t\tfield: ReadPath<Data, F>,\n\t) => Test<Value>\n\t/** The path of the resource starts with these parts. */\n\treadonly under: <\n\t\tconst Ps extends ReadonlyArray<string | null | Ref<string | null, any>>,\n\t>(\n\t\t...prefix: Ps\n\t) => Test<Value, PrincipalOf<Ps[number], P>>\n\t/**\n\t * A field of the principal, to use as a value. The field must have a\n\t * {@link Scalar} type.\n\t */\n\treadonly principal: <const F extends string>(\n\t\tfield: ScalarReadPath<P, F>,\n\t) => Ref<PathValue<P, F>, P>\n\treadonly and: <const Cs extends ReadonlyArray<Any>>(\n\t\t...conditions: Cs\n\t) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>>\n\treadonly or: <const Cs extends ReadonlyArray<Any>>(\n\t\t...conditions: Cs\n\t) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>>\n\treadonly not: <C extends Any>(\n\t\tcondition: C,\n\t) => Condition<ReadsOf<C>, OpaqueOf<C>>\n\t/**\n\t * A test that runs any code. It may give a boolean or an `Effect`. A\n\t * condition with a predicate can not become JSON or a query.\n\t */\n\treadonly predicate: <E = never, R = never>(\n\t\tname: string,\n\t\ttest: (\n\t\t\tvalue: Value,\n\t\t\tprincipal: P,\n\t\t) => boolean | Effect.Effect<boolean, E, R>,\n\t) => Condition<Reads<Value, P>, Opaque<E, R>>\n}\n\nconst isOperand = (u: unknown): u is Operand =>\n\thasProperty(u, \"_tag\") && (u._tag === \"Literal\" || u._tag === \"Principal\")\n\nconst toOperand = (value: unknown): Operand =>\n\tisOperand(value) ? value : Nodes.literal(value as Scalar)\n\nconst compare =\n\t(op: CompareOperator) =>\n\t(field: string, value: unknown): Ast =>\n\t\tnew Nodes.Compare({ op, field, value: toOperand(value) })\n\n// A list of conditions goes in as an array, not as arguments: a call may take\n// only so many arguments, and a decoded condition may have more children.\n// The constructor copies the list, so a later change to the array of a caller\n// does not change the condition.\nconst andOf = (conditions: ReadonlyArray<Ast>): Ast =>\n\tnew Nodes.And(conditions as ReadonlyArray<Nodes.Node>)\n\nconst orOf = (conditions: ReadonlyArray<Ast>): Ast =>\n\tnew Nodes.Or(conditions as ReadonlyArray<Nodes.Node>)\n\nconst makeNot = (condition: Ast): Ast => new Nodes.Not(condition as Nodes.Node)\n\nconst sharedBuilder: Builder<any, any, any> = {\n\teq: compare(\"eq\"),\n\tne: compare(\"ne\"),\n\tlt: compare(\"lt\"),\n\tlte: compare(\"lte\"),\n\tgt: compare(\"gt\"),\n\tgte: compare(\"gte\"),\n\tin: (field: string, values: ReadonlyArray<unknown>) =>\n\t\tnew Nodes.In({ field, values: Arr.map(Array.from(values), toOperand) }),\n\texists: (field: string) => new Nodes.Exists({ field }),\n\tunder: (...prefix: ReadonlyArray<unknown>) =>\n\t\tnew Nodes.Under({ prefix: Arr.map(prefix, toOperand) }),\n\tprincipal: (path: string) => Nodes.principalRef(path),\n\tand: (...conditions: ReadonlyArray<Ast>) => andOf(conditions),\n\tor: (...conditions: ReadonlyArray<Ast>) => orOf(conditions),\n\tnot: makeNot,\n\tpredicate: (\n\t\tname: string,\n\t\ttest: (\n\t\t\tvalue: unknown,\n\t\t\tprincipal: unknown,\n\t\t) => boolean | Effect.Effect<boolean, unknown, unknown>,\n\t) =>\n\t\tnew Nodes.Predicate({\n\t\t\tname,\n\t\t\trun: (value, principal) =>\n\t\t\t\tEffect.suspend(() => {\n\t\t\t\t\tconst result = test(value, principal)\n\t\t\t\t\treturn Effect.isEffect(result) ? result : Effect.succeed(result)\n\t\t\t\t}),\n\t\t}),\n} as never\n\n/**\n * Makes a builder. Rules give you a builder with the right types, so you do not\n * often need this.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport const builder = <Data, Value, P>(): Builder<Data, Value, P> =>\n\tsharedBuilder\n\n/**\n * Always true.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport const always: Condition = Nodes.always as never\n\n/**\n * Always false.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport const never: Condition = Nodes.never as never\n\n/**\n * True when all the conditions are true. With no conditions, it is true.\n *\n * @stability stable\n * @category combinators\n * @since 0.3.0\n */\nexport const and: <const Cs extends ReadonlyArray<Any>>(\n\t...conditions: Cs\n) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>> = ((\n\t...conditions: ReadonlyArray<Ast>\n) => andOf(conditions)) as never\n\n/**\n * The same as {@link and}, for a list of conditions of one type. Use it for a\n * long list: a function call may take only so many arguments.\n *\n * @stability stable\n * @category combinators\n * @since 1.0.0\n */\nexport const andAll: <C extends Any>(\n\tconditions: ReadonlyArray<C>,\n) => Condition<ReadsOf<C>, OpaqueOf<C>> = andOf as never\n\n/**\n * The same as {@link or}, for a list of conditions of one type. Use it for a\n * long list: a function call may take only so many arguments.\n *\n * @stability stable\n * @category combinators\n * @since 1.0.0\n */\nexport const orAll: <C extends Any>(\n\tconditions: ReadonlyArray<C>,\n) => Condition<ReadsOf<C>, OpaqueOf<C>> = orOf as never\n\n/**\n * True when one of the conditions is true. With no conditions, it is false.\n *\n * @stability stable\n * @category combinators\n * @since 0.3.0\n */\nexport const or: <const Cs extends ReadonlyArray<Any>>(\n\t...conditions: Cs\n) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>> = ((\n\t...conditions: ReadonlyArray<Ast>\n) => orOf(conditions)) as never\n\n/**\n * @stability stable\n * @category combinators\n * @since 0.3.0\n */\nexport const not: <C extends Any>(\n\tcondition: C,\n) => Condition<ReadsOf<C>, OpaqueOf<C>> = makeNot as never\n\n/**\n * The data that a condition needs for a test.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Input {\n\t/** The resource value. */\n\treadonly value: object\n\t/**\n\t * The principal. Without it, a principal field has no value. See\n\t * {@link PrincipalRef}.\n\t */\n\treadonly principal?: object | undefined\n\t/** The path of the resource. Without it, `Under` is false. */\n\treadonly path?: ReadonlyArray<Resource.PathSegment> | undefined\n}\n\n/** Gives a condition as a node. A value that no constructor made is a defect. */\nconst nodeOf = (condition: Ast): Nodes.Node => Nodes.toNode(condition)\n\n/**\n * Gives the services in `context` to every predicate of a condition, so the\n * condition needs no services when it runs.\n *\n * @stability stable\n * @category services\n * @since 1.0.0\n */\nexport const provideContext: {\n\t<R>(\n\t\tcontext: Context.Context<R>,\n\t): <I, X>(\n\t\tcondition: Condition<I, X> &\n\t\t\t([ServicesOf<X>] extends [R] ? unknown : never),\n\t) => Condition<I, Provided<X>>\n\t<I, X>(\n\t\tcondition: Condition<I, X>,\n\t\tcontext: Context.Context<ServicesOf<X>>,\n\t): Condition<I, Provided<X>>\n} = dual(2, (condition: Ast, context: Context.Context<never>): Ast =>\n\tAlgebra.provide(nodeOf(condition), context),\n) as never\n\n/**\n * The input of {@link evaluate} that the predicates of a condition need: a\n * value and a principal of the types in `I`. See {@link Reads}.\n */\ntype ReadsInput<I> =\n\tI extends Reads<infer V, infer P>\n\t\t? { readonly value: V } & (unknown extends P\n\t\t\t\t? unknown\n\t\t\t\t: { readonly principal: P })\n\t\t: unknown\n\n/**\n * Tests a condition on a value. A predicate may fail with its error. When the\n * condition has a predicate, the input must have the value and the principal\n * that the predicate reads. The test runs on the simple form of the condition\n * with the principal in it, so it reads only the fields that a residual reads.\n *\n * @stability stable\n * @category evaluation\n * @since 0.3.0\n */\nexport const evaluate: <I, X, In extends Input>(\n\tcondition: Condition<I, X>,\n\tinput: In & ReadsInput<I>,\n) => Effect.Effect<boolean, ErrorOf<X>, ServicesOf<X>> = ((\n\tcondition: Ast,\n\tinput: Input,\n): Effect.Effect<boolean, unknown, unknown> =>\n\tEffect.suspend(() => Algebra.evaluate(nodeOf(condition), input))) as never\n\n/**\n * Tests a condition with no predicate on a value, at once.\n *\n * @stability stable\n * @category evaluation\n * @since 0.3.0\n */\nexport const evaluateSync: <I, In extends Input>(\n\tcondition: Condition<I>,\n\tinput: In & ReadsInput<I>,\n) => boolean = (condition: Ast, input: Input): boolean =>\n\tAlgebra.evaluateSync(nodeOf(condition), input)\n\n/**\n * Makes a condition smaller without a change to its meaning. It removes `True`\n * and `False` from `And` and `Or`, joins nested `And` and `Or` nodes, and\n * removes double `Not` nodes and copies of a child.\n *\n * @stability stable\n * @category evaluation\n * @since 0.3.0\n */\nexport const simplify: <I, X>(condition: Condition<I, X>) => Condition<I, X> =\n\t((condition: Ast) => condition.pipe(nodeOf, Algebra.simplify)) as never\n\ninterface PartialInput {\n\treadonly principal?: object | undefined\n\treadonly path?: ReadonlyArray<Resource.PathSegment> | undefined\n}\n\n/**\n * The principal that {@link partial} must get for the predicates of a\n * condition. A predicate keeps the principal that it gets, so the principal\n * must have the type that the predicate reads.\n */\ntype PrincipalInput<I> =\n\tI extends Reads<infer _V, infer P>\n\t\t? unknown extends P\n\t\t\t? unknown\n\t\t\t: { readonly principal: P }\n\t\t: unknown\n\n/** What a condition reads after {@link partial}: the value, and no principal. */\ntype Bound<I> = I extends Reads<infer V, infer _P> ? Reads<V, unknown> : I\n\n/**\n * Puts the principal into a condition and expands `Under` with the path of the\n * resource. The result is simplified. It has no principal fields and no\n * `Under` nodes. It is `True` or `False` when the answer does not depend on the\n * resource value.\n *\n * @stability stable\n * @category evaluation\n * @since 0.3.0\n */\nexport const partial: <I, X>(\n\tcondition: Condition<I, X>,\n\tinput: PartialInput & PrincipalInput<I>,\n) => Condition<Bound<I>, X> = ((condition: Ast, input: PartialInput): Ast =>\n\tAlgebra.partial(nodeOf(condition), input)) as never\n\n/**\n * The functions that change each node of a condition into another form, such\n * as a database query.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Interpreter<A> {\n\treadonly true: () => A\n\treadonly false: () => A\n\treadonly compare: (op: CompareOperator, field: string, value: Scalar) => A\n\treadonly in: (field: string, values: ReadonlyArray<Scalar>) => A\n\treadonly exists: (field: string) => A\n\treadonly and: (conditions: ReadonlyArray<A>) => A\n\treadonly or: (conditions: ReadonlyArray<A>) => A\n\treadonly not: (condition: A) => A\n\t/** Optional. Without it, a predicate makes `fold` fail. */\n\treadonly predicate?: (name: string) => A\n}\n\n/**\n * The error when `fold` can not change a node.\n *\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport class Untranslatable extends Schema.TaggedError<Untranslatable>(\n\t\"@nmnmcc/ability/Condition/Untranslatable\",\n)(\"Untranslatable\", { reason: Schema.String }) {}\n\nconst literalValue = (operand: Operand, field: string): Scalar => {\n\tif (operand._tag !== \"Literal\") {\n\t\tthrow Untranslatable.make({\n\t\t\treason: `The field \"${field}\" uses a principal field. Call Condition.partial first.`,\n\t\t})\n\t}\n\treturn operand.value\n}\n\n/**\n * Folds a condition. A shared child is folded again for each place. The walk\n * takes the steps of a trampoline, so a deep condition does not fill the\n * stack.\n */\nconst foldNode = <A>(root: Nodes.Node, interpreter: Interpreter<A>): A =>\n\tTrampoline.run(root.depth, (R) => {\n\t\tconst go = (node: Nodes.Node): Trampoline.Step<A> => {\n\t\t\tconst children = (nodes: ReadonlyArray<Nodes.Node>) =>\n\t\t\t\tR.forEach(nodes, (child) => R.suspend(() => go(child)))\n\t\t\tswitch (node._tag) {\n\t\t\t\tcase \"True\":\n\t\t\t\t\treturn R.succeed(interpreter.true())\n\t\t\t\tcase \"False\":\n\t\t\t\t\treturn R.succeed(interpreter.false())\n\t\t\t\tcase \"Compare\":\n\t\t\t\t\treturn R.succeed(\n\t\t\t\t\t\tinterpreter.compare(\n\t\t\t\t\t\t\tnode.op,\n\t\t\t\t\t\t\tnode.field,\n\t\t\t\t\t\t\tliteralValue(node.value, node.field),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\tcase \"In\":\n\t\t\t\t\treturn R.succeed(\n\t\t\t\t\t\tinterpreter.in(\n\t\t\t\t\t\t\tnode.field,\n\t\t\t\t\t\t\tArr.map(node.values, (operand) =>\n\t\t\t\t\t\t\t\tliteralValue(operand, node.field),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\tcase \"Exists\":\n\t\t\t\t\treturn R.succeed(interpreter.exists(node.field))\n\t\t\t\tcase \"Under\":\n\t\t\t\t\tthrow Untranslatable.make({\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\"An Under node needs the resource path. Call Condition.partial first.\",\n\t\t\t\t\t})\n\t\t\t\tcase \"And\":\n\t\t\t\t\treturn R.map(children(node.conditions), interpreter.and)\n\t\t\t\tcase \"Or\":\n\t\t\t\t\treturn R.map(children(node.conditions), interpreter.or)\n\t\t\t\tcase \"Not\":\n\t\t\t\t\treturn R.map(\n\t\t\t\t\t\tR.suspend(() => go(node.condition)),\n\t\t\t\t\t\tinterpreter.not,\n\t\t\t\t\t)\n\t\t\t\tcase \"Predicate\":\n\t\t\t\t\tif (interpreter.predicate === undefined) {\n\t\t\t\t\t\tthrow Untranslatable.make({\n\t\t\t\t\t\t\treason: `The predicate \"${node.name}\" can not become a query`,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\treturn R.succeed(interpreter.predicate(node.name))\n\t\t\t}\n\t\t}\n\t\treturn go(root)\n\t})\n\n/**\n * Changes a condition into another form with an interpreter. Call\n * {@link partial} first: `fold` fails on principal fields and on `Under`\n * nodes, and on predicates when the interpreter has no `predicate` function.\n *\n * @stability stable\n * @category converting\n * @since 0.3.0\n */\nexport const fold: {\n\t<A>(\n\t\tinterpreter: Interpreter<A>,\n\t): (condition: Any) => Effect.Effect<A, Untranslatable>\n\t<A>(\n\t\tcondition: Any,\n\t\tinterpreter: Interpreter<A>,\n\t): Effect.Effect<A, Untranslatable>\n} = dual(\n\t2,\n\t<A>(\n\t\tcondition: Ast,\n\t\tinterpreter: Interpreter<A>,\n\t): Effect.Effect<A, Untranslatable> =>\n\t\tEffect.try({\n\t\t\ttry: () => foldNode(nodeOf(condition), interpreter),\n\t\t\tcatch: (cause) => {\n\t\t\t\tif (cause instanceof Untranslatable) {\n\t\t\t\t\treturn cause\n\t\t\t\t}\n\t\t\t\tthrow cause\n\t\t\t},\n\t\t}),\n)\n\n/**\n * The fields that a condition uses, in the order that they first come.\n *\n * @stability stable\n * @category getters\n * @since 0.3.0\n */\nexport const fields = (condition: Ast): ReadonlyArray<string> =>\n\tcondition.pipe(nodeOf, Algebra.fields)\n\n// Satisfiability\n\n/**\n * Values of fields, as a nested object. A field that is not in it may have any\n * value. A value with parts that the search does not look into, such as a\n * date, is an empty object.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport type Example = Search.Example\n\n/**\n * The answer of {@link satisfiable}:\n * - `Satisfiable`: some value makes the condition true. `example` is one.\n * - `Unsatisfiable`: no value makes the condition true.\n * - `Unknown`: the search can not say. The condition has a predicate, or\n * the search went past its budget.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport type Satisfiability = Search.Satisfiability\n\n/**\n * The options of {@link satisfiable}.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport interface SatisfiableOptions {\n\t/**\n\t * The Schema of the values. Its shape gives the kinds of values of each\n\t * field. Without it, a field may have any value.\n\t */\n\treadonly schema?: Schema.Top | undefined\n\t/** The most steps that the search may take. The default is 1000000. */\n\treadonly budget?: number | undefined\n}\n\n/**\n * Tests if some value makes a condition true, and gives such a value.\n *\n * Call {@link partial} first: the condition must have no principal fields and\n * no `Under` nodes. A condition with a predicate gives `Unknown`.\n *\n * Each test of a condition compares one field with constants, so the\n * constants cut the values of each field into a few cells. The search tries\n * one value from each cell, one field at a time. The values of a field come\n * from the shape of the Schema in `options.schema`: its literals, `null` for\n * a nullable or optional field, and finite or integer numbers.\n *\n * The search reads the shape of the Schema, not its other checks, such as a\n * minimum length. So `Unsatisfiable` holds for every value of the Schema. A\n * `Satisfiable` example fits the shape, but a check may still stop it.\n *\n * The problem is as hard as boolean satisfiability, so the search has a\n * budget. Past it, the answer is `Unknown`. A condition with more than 256\n * fields gives `Unknown` too.\n *\n * @stability stable\n * @category evaluation\n * @since 1.0.0\n */\nexport const satisfiable = (\n\tcondition: Any,\n\toptions: SatisfiableOptions = {},\n): Satisfiability =>\n\tSearch.satisfiable(\n\t\tnodeOf(condition),\n\t\tSearch.kindsIn(\n\t\t\toptions.schema === undefined\n\t\t\t\t? undefined\n\t\t\t\t: Catalog.catalogOf(options.schema.ast),\n\t\t),\n\t\toptions.budget,\n\t)\n\n/**\n * The JSON form of an operand.\n *\n * @stability stable\n * @category models\n * @since 2.0.0\n */\nexport type EncodedOperand =\n\t| { readonly _tag: \"Literal\"; readonly value: Scalar }\n\t| { readonly _tag: \"Principal\"; readonly path: string }\n\n/**\n * The JSON form of a condition with no predicate.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Encoded =\n\t| { readonly _tag: \"True\" }\n\t| { readonly _tag: \"False\" }\n\t| {\n\t\t\treadonly _tag: \"Compare\"\n\t\t\treadonly op: CompareOperator\n\t\t\treadonly field: string\n\t\t\treadonly value: EncodedOperand\n\t }\n\t| {\n\t\t\treadonly _tag: \"In\"\n\t\t\treadonly field: string\n\t\t\treadonly values: ReadonlyArray<EncodedOperand>\n\t }\n\t| { readonly _tag: \"Exists\"; readonly field: string }\n\t| { readonly _tag: \"Under\"; readonly prefix: ReadonlyArray<EncodedOperand> }\n\t| {\n\t\t\treadonly _tag: \"And\" | \"Or\"\n\t\t\treadonly conditions: ReadonlyArray<Encoded>\n\t }\n\t| { readonly _tag: \"Not\"; readonly condition: Encoded }\n\n/**\n * A condition with no predicate, that may read any values. It is the type of\n * {@link schema}: a decoded condition reads nothing, so it fits any rule, and\n * any plain condition, such as one from a builder or a residual, may be\n * encoded.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\n// `any` for what it reads: the field is contravariant, so no other type both\n// takes every condition and fits every rule.\nexport type PlainCondition = Condition<any>\n\n/**\n * The Schema of a condition with no predicate. It checks the shape only. Use\n * `Policy.schema` to check the field names against a domain too.\n *\n * The decoder takes at most 500 levels of conditions, and at most 1000000\n * objects and array items, with a shared object counted for each place. It\n * reads only the own data fields of the input.\n *\n * @stability stable\n * @category schemas\n * @since 0.3.0\n */\nexport const schema: Schema.Codec<PlainCondition, Encoded> =\n\tSchema.Unknown.pipe(\n\t\tSchema.decodeTo(\n\t\t\tSchema.declare(\n\t\t\t\t(input): input is PlainCondition =>\n\t\t\t\t\tNodes.isNode(input) && !input.opaque,\n\t\t\t),\n\t\t\tSchemaTransformation.transformEffect({\n\t\t\t\tdecode: (input: unknown, options) =>\n\t\t\t\t\tResult.match(Json.decode(input), {\n\t\t\t\t\t\tonSuccess: (node) => Effect.succeed(node as never),\n\t\t\t\t\t\tonFailure: (problem) =>\n\t\t\t\t\t\t\tEffect.fail(\n\t\t\t\t\t\t\t\tnew SchemaIssue.Pointer(\n\t\t\t\t\t\t\t\t\tproblem.path,\n\t\t\t\t\t\t\t\t\tnew SchemaIssue.InvalidValue(\n\t\t\t\t\t\t\t\t\t\t{ message: problem.message },\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t\t\tencode: (condition: PlainCondition) =>\n\t\t\t\t\tEffect.sync(() => Json.toJson(condition as never)),\n\t\t\t}),\n\t\t),\n\t) as never\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAm3BA,MAAM,aAAa,MACl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KACd,OAAO,SACN,OAAO,SACL,UACAC,OAAa,KAAK,KAAK,CAAC,MAAM,MAChC,GACA,qBAAqB,gBAAgB;CACpC,SAAS,OAAgB,YACxB,OAAO,MAAMC,OAAY,KAAK,GAAG;EAChC,YAAY,SAAS,OAAO,QAAQ,IAAa;EACjD,YAAY,YACX,OAAO,KACN,IAAI,YAAY,QACf,QAAQ,MACR,IAAI,YAAY,aACf,EAAE,SAAS,QAAQ,QAAQ,GAC3B,OACA,OACD,CACD,CACD;CACF,CAAC;CACF,SAAS,cACR,OAAO,WAAWC,OAAY,SAAkB,CAAC;AACnD,CAAC,CACF,CACD"}
1
+ {"version":3,"file":"Condition.js","names":["Nodes.literal","Nodes.Compare","Nodes.And","Nodes.Or","Nodes.Not","Nodes.In","Nodes.Exists","Nodes.Under","Nodes.principalRef","Nodes.Predicate","Nodes.always","Nodes.never","Nodes.toNode","Algebra.provide","Algebra.evaluate","Algebra.evaluateSync","Algebra.simplify","Algebra.partial","Trampoline.run","Algebra.fields","Search.satisfiable","Search.kindsIn","Catalog.catalogOf","Nodes.isNode","Json.decode","Json.toJson"],"sources":["../src/Condition.ts"],"sourcesContent":["/**\n * A condition is a test on a resource value. A rule applies only when its\n * condition is true.\n *\n * A condition is plain data: a tree of nodes. So you can:\n * - test it on a value with {@link evaluate};\n * - put the principal into it and make it smaller with {@link partial}, which\n * gives a \"residual\" condition: the part that still depends on the\n * resource;\n * - change it into a database query with {@link fold};\n * - keep it as JSON with {@link schema}.\n *\n * Make conditions with a {@link Builder}. A rule gives you a builder for its\n * resource, so the field names and the value types are checked.\n *\n * {@link Builder.predicate} is the one way out of plain data. A predicate runs\n * any `Effect`. Its error type and its service type go into the type of the\n * check. A rule with a predicate can not become JSON, and the type system\n * stops you when you try.\n *\n * @stability stable\n * @since 0.3.0\n */\n// A predicate keeps its error type and service type in the public types. The\n// code below works on the nodes with no types, where they are `unknown`, so\n// the language service check for `unknown` in an Effect is off here.\n// @effect-diagnostics anyUnknownInErrorContext:off\nimport * as Arr from \"effect/Array\"\nimport type * as BigDecimal from \"effect/BigDecimal\"\nimport type * as Cause from \"effect/Cause\"\nimport type * as Chunk from \"effect/Chunk\"\nimport type * as DateTime from \"effect/DateTime\"\nimport type * as Duration from \"effect/Duration\"\nimport type * as Exit from \"effect/Exit\"\nimport type * as HashMap from \"effect/HashMap\"\nimport type * as HashSet from \"effect/HashSet\"\nimport type * as Option from \"effect/Option\"\nimport type * as Redacted from \"effect/Redacted\"\nimport type * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport { dual } from \"effect/Function\"\nimport { hasProperty } from \"effect/Predicate\"\nimport * as Schema from \"effect/Schema\"\nimport * as SchemaIssue from \"effect/SchemaIssue\"\nimport * as SchemaTransformation from \"effect/SchemaTransformation\"\nimport * as Result from \"effect/Result\"\nimport * as Algebra from \"./internal/algebra.ts\"\nimport * as Catalog from \"./internal/catalog.ts\"\nimport * as Json from \"./internal/json.ts\"\nimport * as Nodes from \"./internal/nodes.ts\"\nimport * as Search from \"./internal/search.ts\"\nimport * as Trampoline from \"./internal/trampoline.ts\"\nimport * as Resource from \"./Resource.ts\"\n\n/**\n * A value that a condition can compare.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Scalar = Nodes.Scalar\n\n/**\n * A fixed value in a condition.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Literal = Nodes.Literal\n\n/**\n * A field of the principal. {@link partial} puts the value of the field in its\n * place.\n *\n * A principal field that is `null` or missing has no value. A `Compare`, `In`\n * or `Under` test with it is always false, also with `ne`. So a principal with\n * no id never matches a resource with no owner. `not` still turns false into\n * true.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type PrincipalRef = Nodes.PrincipalRef\n\n/**\n * A field of the principal with a known value type `A`, from a principal of\n * the type `P`. The type fields are only in the types. A test with the\n * reference reads a principal of the type `P`, so it can not go into a rule\n * of a domain with another principal.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Ref<A, P = never> = PrincipalRef & {\n\treadonly \"~Ref\": () => A\n\treadonly \"~Principal\": (principal: P) => void\n}\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Operand = Literal | PrincipalRef\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type CompareOperator = Nodes.CompareOperator\n\n/**\n * Always true.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type True = Nodes.True\n\n/**\n * Always false.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type False = Nodes.False\n\n/**\n * Compares a field with a value. A missing field has the value `null`. `lt`,\n * `lte`, `gt` and `gte` are false when the two sides are not both numbers or\n * both strings.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Compare = Nodes.Compare\n\n/**\n * True when a field is equal to one of the values.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type In = Nodes.In\n\n/**\n * True when a field is not `null` and not missing.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Exists = Nodes.Exists\n\n/**\n * True when the path of the resource starts with the prefix. A resource with\n * no path is never under a prefix.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Under = Nodes.Under\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type And = Nodes.And\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Or = Nodes.Or\n\n/**\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Not = Nodes.Not\n\n/**\n * A test that runs an `Effect`. It can not become JSON or a query.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Predicate = Nodes.Predicate\n\n/**\n * The nodes of a condition, without types. Each node is a class, and only the\n * builder, the functions of this module and the Schema make one. So a plain\n * object, or a spread of a node, is not a node.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Ast = Nodes.Node\n\n/**\n * The mark of a condition with a predicate. `E` and `R` are the error type\n * and the service type of its predicates.\n *\n * @stability stable\n * @category models\n * @since 2.0.0\n */\nexport interface Opaque<out E = never, out R = never> {\n\treadonly \"~Opaque\": { readonly E: E; readonly R: R }\n}\n\n/**\n * The error type of the predicates of a mark `X`. A mark that is not an\n * {@link Opaque}, as `unknown` or `object`, may have any error.\n *\n * @stability stable\n * @category utility types\n * @since 2.0.0\n */\nexport type ErrorOf<X> = X extends Opaque<infer E, infer _R> ? E : unknown\n\n/**\n * The service type of the predicates of a mark `X`. A mark that is not an\n * {@link Opaque}, as `unknown` or `object`, may need any service.\n *\n * @stability stable\n * @category utility types\n * @since 2.0.0\n */\nexport type ServicesOf<X> = X extends Opaque<infer _E, infer R> ? R : unknown\n\n/**\n * The mark `X` with no services.\n *\n * @stability stable\n * @category utility types\n * @since 2.0.0\n */\nexport type Provided<X> =\n\tX extends Opaque<infer E, infer _R> ? Opaque<E> : Opaque<unknown>\n\n/**\n * What the predicates of a condition read: a resource value of the type `V`\n * and a principal of the type `P`. It is only in the types.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport interface Reads<V, P> {\n\treadonly value: V\n\treadonly principal: P\n}\n\n/**\n * A condition. `I` is what its tests read: see {@link Reads}. `X` is\n * {@link Opaque} when the condition has a predicate, and `never` when it is\n * plain data. A plain condition can become JSON or a query.\n *\n * The two type fields are only in the types. `I` goes into a function as an\n * input, so a condition that reads a `Post` does not fit a rule for a\n * `Comment`. `X` comes out of a function, so a plain condition fits where a\n * condition with predicates may go.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Condition<I = unknown, X = never> = Ast & {\n\treadonly \"~Reads\": (reads: I) => void\n\treadonly \"~Opaque\": () => X\n}\n\n/**\n * Any condition.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Any = Condition<any, any>\n\n/**\n * What the tests of a condition read. For a union of conditions, it is what\n * all of them read.\n *\n * @stability stable\n * @category utility types\n * @since 1.0.0\n */\nexport type ReadsOf<C> = [C] extends [\n\t{ readonly \"~Reads\": (reads: infer I) => void },\n]\n\t? I\n\t: unknown\n\n/**\n * The mark of a condition: {@link Opaque} when it has a predicate.\n *\n * @stability stable\n * @category utility types\n * @since 0.3.0\n */\nexport type OpaqueOf<C> = C extends { readonly \"~Opaque\": () => infer X }\n\t? X\n\t: never\n\ntype Leaf = string | number | boolean | bigint | symbol | null | undefined\n/**\n * Values of a class that keeps its data inside. A path does not go into them,\n * as in the field paths of a resource, so a field with such a value is one\n * field. A condition can test only if it exists.\n */\ntype Whole =\n\t| ReadonlyMap<unknown, unknown>\n\t| ReadonlySet<unknown>\n\t| HashMap.HashMap<unknown, unknown>\n\t| HashSet.HashSet<unknown>\n\t| Date\n\t| URL\n\t| Uint8Array\n\t| Option.Option<unknown>\n\t| BigDecimal.BigDecimal\n\t| Duration.Duration\n\t| DateTime.DateTime\n\t| Redacted.Redacted<unknown>\n\t| Chunk.Chunk<unknown>\n\t| Cause.Cause<unknown>\n\t| Result.Result<unknown, unknown>\n\t| Exit.Exit<unknown, unknown>\n\t| File\n\t| FormData\n\t| RegExp\n\t| URLSearchParams\ntype PreviousDepth = [never, 0, 1, 2, 3]\ntype FieldPathInternal<\n\tT,\n\tDepth extends number,\n\tArrays extends boolean,\n\tParents extends boolean = false,\n> = [Depth] extends [never]\n\t? never\n\t: {\n\t\t\t// A record with number keys has number keys, as `counts.1`.\n\t\t\t[K in keyof T & (string | number)]-?: PathsOf<\n\t\t\t\t`${K}`,\n\t\t\t\tNonNullable<T[K]>,\n\t\t\t\tDepth,\n\t\t\t\tArrays,\n\t\t\t\tParents\n\t\t\t>\n\t\t}[keyof T & (string | number)]\n\n/**\n * The paths of one field `K` with the values `V`. Each kind of value in `V`\n * gives its own paths, so a field that holds a string or a struct is a field,\n * and the fields of the struct are fields too. A function is no field.\n */\ntype PathsOf<\n\tK extends string,\n\tV,\n\tDepth extends number,\n\tArrays extends boolean,\n\tParents extends boolean,\n> =\n\t// A field that is only ever `null` or missing is a field too, and so is a\n\t// field that may hold any value, as one of `Schema.Unknown` may.\n\t| ([V] extends [never] ? K : {} extends V ? K : never)\n\t| ([Extract<V, Leaf | Whole>] extends [never] ? never : K)\n\t| ([Extract<V, ReadonlyArray<unknown>>] extends [never]\n\t\t\t? never\n\t\t\t: Arrays extends true\n\t\t\t\t? K\n\t\t\t\t: never)\n\t// A condition reads a field below `K` only when `K` holds plain data: a\n\t// list, a whole value such as a date, or a function may have a getter or a\n\t// method with the name, so the binding does not take such a read. A rule\n\t// or a request names a field and does not read it, so it may.\n\t| (Arrays extends true\n\t\t\t? ObjectPaths<\n\t\t\t\t\tK,\n\t\t\t\t\tExclude<V, Leaf | Whole | Function | ReadonlyArray<unknown>>,\n\t\t\t\t\tDepth,\n\t\t\t\t\tArrays,\n\t\t\t\t\tParents\n\t\t\t\t>\n\t\t\t: [Extract<V, Whole | Function | ReadonlyArray<unknown>>] extends [never]\n\t\t\t\t? ObjectPaths<K, Exclude<V, Leaf>, Depth, Arrays, Parents>\n\t\t\t\t: never)\n\n/** The paths of a field `K` that holds the objects `O`, and of the fields below. */\ntype ObjectPaths<\n\tK extends string,\n\tO,\n\tDepth extends number,\n\tArrays extends boolean,\n\tParents extends boolean,\n> = [O] extends [never]\n\t? never\n\t: // A record is one field to a rule or a request, as `permittedFields`\n\t\t// lists it.\n\t\t| (Parents extends true\n\t\t\t\t? K\n\t\t\t\t: Arrays extends true\n\t\t\t\t\t? string extends keyof O\n\t\t\t\t\t\t? K\n\t\t\t\t\t\t: number extends keyof O\n\t\t\t\t\t\t\t? K\n\t\t\t\t\t\t\t: never\n\t\t\t\t\t: never)\n\t\t| `${K}.${FieldPathInternal<O, PreviousDepth[Depth], Arrays, Parents>}`\n\n/**\n * The paths of the fields of `T` that hold one value, with dots for nested\n * fields. Arrays are left out. A map, a set, a date, a URL, a byte array, an\n * `Option` and the other value types of Effect, such as `BigDecimal` and\n * `Duration`, are one field, and a path does not go into them. A path does\n * not go into a field that may hold one of them or a list either. The type\n * goes down four levels, so type checking stays fast. For a union of types,\n * only the common fields are paths.\n *\n * @stability stable\n * @category utility types\n * @since 0.3.0\n */\nexport type FieldPath<T> = [T] extends [object]\n\t? FieldPathInternal<T, 4, false>\n\t: never\n\n/**\n * The paths of the fields of `T` that a rule or a request may name, as in\n * `Rule.Options.fields`. They are the paths of {@link FieldPath}, and the\n * paths of arrays too: a rule may allow or deny a whole array field, and\n * `permittedFields` lists it.\n *\n * @stability stable\n * @category utility types\n * @since 1.0.0\n */\nexport type FieldSelector<T> = [T] extends [object]\n\t? FieldPathInternal<T, 4, true>\n\t: never\n\n/**\n * The names that the `fields` of a rule may have: the paths of\n * {@link FieldSelector}, and the paths of the structs above them. A name of a\n * struct covers the fields below it.\n *\n * @stability stable\n * @category utility types\n * @since 2.0.0\n */\nexport type FieldName<T> = [T] extends [object]\n\t? FieldPathInternal<T, 4, true, true>\n\t: never\n\n/**\n * The value type that fits every field in `F`. For one field, it is the type\n * of the field. For a union of fields, it is the values that each of them can\n * hold, so a value of a union type can not test a field of another type. For\n * a union of data types, as for a rule on two kinds, it is the values that\n * the field can hold in each of them.\n *\n * @stability stable\n * @category utility types\n * @since 1.0.0\n */\nexport type FieldValue<Data, F extends string> = (\n\tData extends unknown\n\t\t? F extends unknown\n\t\t\t? (value: PathValue<Data, F>) => void\n\t\t\t: never\n\t\t: never\n) extends (value: infer V) => void\n\t? V\n\t: never\n\ntype Normalize<A> = Exclude<A, undefined> | (undefined extends A ? null : never)\n\n/**\n * The type of the field of `T` at `Path`. A field that may be missing may also\n * be `null`. Each type of a union gives its own value: a field below a value\n * that is not an object, as below a string, is `null`, as a read of it is.\n *\n * @stability stable\n * @category utility types\n * @since 0.3.0\n */\nexport type PathValue<T, Path extends string> = ValueWalk<T, Path>\n\n/**\n * The values of the part `Name` of each type of `U`. A part below a value\n * that is not an object, as below a string or `null`, is `null`.\n */\ntype StepValue<U, Name extends string> = U extends unknown\n\t? U extends object\n\t\t? ChildOf<U, Name>\n\t\t: null\n\t: never\n\n/**\n * Walks a path two parts at a time, with the values of each step. The type\n * checker takes at most about 1000 steps of a type that calls itself, so a\n * walk of one part at a time would stop before a path of 1000 parts.\n */\ntype ValueWalk<\n\tU,\n\tPath extends string,\n> = Path extends `${infer A}.${infer B}.${infer Rest}`\n\t? ValueWalk<StepValue<StepValue<U, A>, B>, Rest>\n\t: Path extends `${infer A}.${infer B}`\n\t\t? Normalize<StepValue<StepValue<U, A>, B>>\n\t\t: Normalize<StepValue<U, Path>>\n\n/**\n * The type of the part `Name` of `T`. A part of a path is text, so the part\n * `\"1\"` names the number key `1` too, as of a record with number keys.\n */\ntype ChildOf<T, Name extends string> = Name extends keyof T\n\t? T[Name]\n\t: Name extends `${infer N extends number}`\n\t\t? N extends keyof T\n\t\t\t? T[N]\n\t\t\t: number extends keyof T\n\t\t\t\t? T[number]\n\t\t\t\t: never\n\t\t: never\n\n/**\n * What a path may do, for one use of it: go below a list or a whole value,\n * as a rule or a request may, and end at a struct, as the fields of a rule\n * may. See {@link FieldPath}, {@link FieldSelector} and {@link FieldName},\n * which list the short paths with the same rules.\n */\ninterface PathRules {\n\treadonly arrays: boolean\n\treadonly parents: boolean\n}\n\n/** The rules of a path that a condition reads. */\ninterface ReadRules {\n\treadonly arrays: false\n\treadonly parents: false\n}\n\n/** The rules of the field of a request. */\ninterface SelectRules {\n\treadonly arrays: true\n\treadonly parents: false\n}\n\n/** The rules of a field of a rule, which may name a struct. */\ninterface NameRules {\n\treadonly arrays: true\n\treadonly parents: true\n}\n\n/** The objects below a field with the values `V`: see `PathsOf`. */\ntype ObjectsBelow<V, Arrays extends boolean> = Arrays extends true\n\t? Exclude<V, Leaf | Whole | Function | ReadonlyArray<unknown>>\n\t: [Extract<V, Whole | Function | ReadonlyArray<unknown>>] extends [never]\n\t\t? Exclude<V, Leaf>\n\t\t: never\n\n/** Tests if `Name` names a field of every object of `O`, as `keyof` does. */\ntype HasPart<O, Name extends string> = Name extends keyof O\n\t? true\n\t: Name extends `${infer N extends number}`\n\t\t? N extends keyof O\n\t\t\t? true\n\t\t\t: number extends keyof O\n\t\t\t\t? true\n\t\t\t\t: false\n\t\t: false\n\n/**\n * The objects below the part `Name` of the objects `O`, for a path that goes\n * on, or `never` when it can not go on.\n */\ntype PathStep<O, Name extends string, R extends PathRules> =\n\tHasPart<O, Name> extends true\n\t\t? ObjectsBelow<NonNullable<ChildOf<O, Name>>, R[\"arrays\"]>\n\t\t: never\n\n/** Tests if a path may end at a field with the values `V`: see `PathsOf`. */\ntype EndsAt<V, R extends PathRules, Last extends boolean> = [V] extends [never]\n\t? true\n\t: {} extends V\n\t\t? true\n\t\t: [Extract<V, Leaf | Whole>] extends [never]\n\t\t\t? R[\"arrays\"] extends true\n\t\t\t\t? [Extract<V, ReadonlyArray<unknown>>] extends [never]\n\t\t\t\t\t? EndsAtObjects<ObjectsBelow<V, true>, R, Last>\n\t\t\t\t\t: true\n\t\t\t\t: false\n\t\t\t: true\n\n/**\n * Tests if a path may end at a field that holds the objects `O`: a field of a\n * rule may name a struct, and a request may name a record, or a struct at\n * the last part that a path may have.\n */\ntype EndsAtObjects<O, R extends PathRules, Last extends boolean> = [O] extends [\n\tnever,\n]\n\t? false\n\t: R[\"parents\"] extends true\n\t\t? true\n\t\t: string extends keyof O\n\t\t\t? true\n\t\t\t: number extends keyof O\n\t\t\t\t? true\n\t\t\t\t: Last\n\n/** The paths one part below `Done`, as the names that may come next. */\ntype NextNames<O, Done extends string> = `${Done}${keyof O & (string | number)}`\n\n/**\n * Walks a path two parts at a time, from the objects `O`. It gives `true`\n * for a path that the rules `R` take, or the names that may come next after\n * the last good part. `Count` counts the parts before `F`, so the walk knows\n * the last part that a path may have: part 1000, the default of\n * `Limits.fieldPathParts`.\n */\ntype PathWalk<\n\tO,\n\tF extends string,\n\tDone extends string,\n\tR extends PathRules,\n\tCount extends ReadonlyArray<0>,\n> = F extends `${infer A}.${infer B}.${infer Rest}`\n\t? PathStep<O, A, R> extends infer O1\n\t\t? [O1] extends [never]\n\t\t\t? NextNames<O, Done>\n\t\t\t: PathStep<O1, B, R> extends infer O2\n\t\t\t\t? [O2] extends [never]\n\t\t\t\t\t? NextNames<O1, `${Done}${A}.`>\n\t\t\t\t\t: PathWalk<O2, Rest, `${Done}${A}.${B}.`, R, [...Count, 0, 0]>\n\t\t\t\t: never\n\t\t: never\n\t: F extends `${infer A}.${infer B}`\n\t\t? PathStep<O, A, R> extends infer O1\n\t\t\t? [O1] extends [never]\n\t\t\t\t? NextNames<O, Done>\n\t\t\t\t: PathEnd<O1, B, `${Done}${A}.`, R, [...Count, 0]>\n\t\t\t: never\n\t\t: PathEnd<O, F, Done, R, Count>\n\ntype PathEnd<\n\tO,\n\tName extends string,\n\tDone extends string,\n\tR extends PathRules,\n\tCount extends ReadonlyArray<0>,\n> =\n\tHasPart<O, Name> extends true\n\t\t? EndsAt<\n\t\t\t\tNonNullable<ChildOf<O, Name>>,\n\t\t\t\tR,\n\t\t\t\tCount[\"length\"] extends 999 ? true : false\n\t\t\t> extends true\n\t\t\t? true\n\t\t\t: // The name is a field, but a path may not end at it, as at a struct\n\t\t\t\t// for a condition: the paths below it may come next. The names of\n\t\t\t\t// this place would hold the name itself.\n\t\t\t\tNextNames<\n\t\t\t\t\tObjectsBelow<NonNullable<ChildOf<O, Name>>, R[\"arrays\"]>,\n\t\t\t\t\t`${Done}${Name}.`\n\t\t\t\t>\n\t\t: NextNames<O, Done>\n\n/**\n * Checks one field path `F` of `T`, of any length up to about 1000 parts.\n * It gives `F` for a path that the rules `R` take. For another path, it gives\n * the paths that may come next after its last good part, so a type error\n * names them. For a union of types, a part must be in each of them.\n */\ntype PathCheck<T, F extends string, R extends PathRules> = [T] extends [object]\n\t? // Each path of a union of paths, as of a field typed `FieldSelector`,\n\t\t// is checked by itself.\n\t\tF extends unknown\n\t\t? PathWalk<T, F, \"\", R, []> extends true\n\t\t\t? F\n\t\t\t: // The names come from parts of `F`. Inference must not find `F`\n\t\t\t\t// in them, so a call gets its `F` from the path that it gives.\n\t\t\t\tNoInfer<PathWalk<T, F, \"\", R, []>>\n\t\t: never\n\t: never\n\n/**\n * A path of `T` that a condition may read, as one of {@link FieldPath}, of\n * any length up to about 1000 parts. It is `F` when `F` is such a path, and\n * the names that may come next when it is not.\n *\n * @stability stable\n * @category utility types\n * @since 2.1.0\n */\nexport type ReadPath<T, F extends string> = PathCheck<T, F, ReadRules>\n\n/**\n * A path of `T` that a request may name, as one of {@link FieldSelector}, of\n * any length up to about 1000 parts. See {@link ReadPath}.\n *\n * @stability stable\n * @category utility types\n * @since 2.1.0\n */\nexport type SelectPath<T, F extends string> = PathCheck<T, F, SelectRules>\n\n/**\n * A path of `T` that a field of a rule may name, as one of\n * {@link FieldName}, of any length up to about 1000 parts. See\n * {@link ReadPath}.\n *\n * @stability stable\n * @category utility types\n * @since 2.1.0\n */\nexport type NamePath<T, F extends string> = PathCheck<T, F, NameRules>\n\n/** A path that a condition may read, with an ordered value. */\ntype OrderedReadPath<T, F extends string> =\n\tReadPath<T, F> extends F\n\t\t? Exclude<PathValue<T, F>, null> extends number | string\n\t\t\t? F\n\t\t\t: never\n\t\t: ReadPath<T, F>\n\n/** A path that a condition may read, with a scalar value. */\ntype ScalarReadPath<T, F extends string> =\n\tReadPath<T, F> extends F\n\t\t? PathValue<T, F> extends Scalar\n\t\t\t? F\n\t\t\t: never\n\t\t: ReadPath<T, F>\n\n/**\n * A value for a field of type `A`: a fixed value, or a field of the principal\n * with the same type.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type OperandOf<A, P = never> = Extract<A, Scalar> | Ref<A, P>\n\n/**\n * A test made by a {@link Builder}. It runs no code, but it keeps the value\n * type of its resource, so a test on the fields of one resource can not go\n * into a rule for another resource. A test with a field of the principal\n * keeps the principal type `P` too.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport type Test<Value, P = unknown> = Condition<Reads<Value, P>>\n\n/**\n * The principal type that a test reads: the principal of each field of the\n * principal in the values `V`, and `unknown` when there is none. A reference\n * from another builder keeps the principal of that builder.\n */\ntype PrincipalOf<V, _P> = [Extract<V, PrincipalRef>] extends [never]\n\t? unknown\n\t: [Extract<V, PrincipalRef>] extends [\n\t\t\t\t{ readonly \"~Principal\": (principal: infer Q) => void },\n\t\t ]\n\t\t? Q\n\t\t: unknown\n\n/**\n * Makes conditions for a resource with the data type `Data` and the value type\n * `Value`, and a principal with the type `P`.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Builder<Data, Value, P> {\n\t/** The field is equal to the value. */\n\treadonly eq: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<FieldValue<Data, F>, any>,\n\t>(\n\t\tfield: ReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\t/** The field is not equal to the value. */\n\treadonly ne: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<FieldValue<Data, F>, any>,\n\t>(\n\t\tfield: ReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\treadonly lt: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<Exclude<FieldValue<Data, F>, null>, any>,\n\t>(\n\t\tfield: OrderedReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\treadonly lte: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<Exclude<FieldValue<Data, F>, null>, any>,\n\t>(\n\t\tfield: OrderedReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\treadonly gt: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<Exclude<FieldValue<Data, F>, null>, any>,\n\t>(\n\t\tfield: OrderedReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\treadonly gte: <\n\t\tconst F extends string,\n\t\tconst V extends OperandOf<Exclude<FieldValue<Data, F>, null>, any>,\n\t>(\n\t\tfield: OrderedReadPath<Data, F>,\n\t\tvalue: V,\n\t) => Test<Value, PrincipalOf<V, P>>\n\t/** The field is equal to one of the values. */\n\treadonly in: <\n\t\tconst F extends string,\n\t\tconst Vs extends ReadonlyArray<OperandOf<FieldValue<Data, F>, any>>,\n\t>(\n\t\tfield: ReadPath<Data, F>,\n\t\tvalues: Vs,\n\t) => Test<Value, PrincipalOf<Vs[number], P>>\n\t/** The field has a value that is not `null`. */\n\treadonly exists: <const F extends string>(\n\t\tfield: ReadPath<Data, F>,\n\t) => Test<Value>\n\t/** The path of the resource starts with these parts. */\n\treadonly under: <\n\t\tconst Ps extends ReadonlyArray<string | null | Ref<string | null, any>>,\n\t>(\n\t\t...prefix: Ps\n\t) => Test<Value, PrincipalOf<Ps[number], P>>\n\t/**\n\t * A field of the principal, to use as a value. The field must have a\n\t * {@link Scalar} type.\n\t */\n\treadonly principal: <const F extends string>(\n\t\tfield: ScalarReadPath<P, F>,\n\t) => Ref<PathValue<P, F>, P>\n\treadonly and: <const Cs extends ReadonlyArray<Any>>(\n\t\t...conditions: Cs\n\t) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>>\n\treadonly or: <const Cs extends ReadonlyArray<Any>>(\n\t\t...conditions: Cs\n\t) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>>\n\treadonly not: <C extends Any>(\n\t\tcondition: C,\n\t) => Condition<ReadsOf<C>, OpaqueOf<C>>\n\t/**\n\t * A test that runs any code. It may give a boolean or an `Effect`. A\n\t * condition with a predicate can not become JSON or a query.\n\t */\n\treadonly predicate: <E = never, R = never>(\n\t\tname: string,\n\t\ttest: (\n\t\t\tvalue: Value,\n\t\t\tprincipal: P,\n\t\t) => boolean | Effect.Effect<boolean, E, R>,\n\t) => Condition<Reads<Value, P>, Opaque<E, R>>\n}\n\nconst isOperand = (u: unknown): u is Operand =>\n\thasProperty(u, \"_tag\") && (u._tag === \"Literal\" || u._tag === \"Principal\")\n\nconst toOperand = (value: unknown): Operand =>\n\tisOperand(value) ? value : Nodes.literal(value as Scalar)\n\nconst compare =\n\t(op: CompareOperator) =>\n\t(field: string, value: unknown): Ast =>\n\t\tnew Nodes.Compare({ op, field, value: toOperand(value) })\n\n// A list of conditions goes in as an array, not as arguments: a call may take\n// only so many arguments, and a decoded condition may have more children.\n// The constructor copies the list, so a later change to the array of a caller\n// does not change the condition.\nconst andOf = (conditions: ReadonlyArray<Ast>): Ast =>\n\tnew Nodes.And(conditions as ReadonlyArray<Nodes.Node>)\n\nconst orOf = (conditions: ReadonlyArray<Ast>): Ast =>\n\tnew Nodes.Or(conditions as ReadonlyArray<Nodes.Node>)\n\nconst makeNot = (condition: Ast): Ast => new Nodes.Not(condition as Nodes.Node)\n\nconst sharedBuilder: Builder<any, any, any> = {\n\teq: compare(\"eq\"),\n\tne: compare(\"ne\"),\n\tlt: compare(\"lt\"),\n\tlte: compare(\"lte\"),\n\tgt: compare(\"gt\"),\n\tgte: compare(\"gte\"),\n\tin: (field: string, values: ReadonlyArray<unknown>) =>\n\t\tnew Nodes.In({ field, values: Arr.map(Array.from(values), toOperand) }),\n\texists: (field: string) => new Nodes.Exists({ field }),\n\tunder: (...prefix: ReadonlyArray<unknown>) =>\n\t\tnew Nodes.Under({ prefix: Arr.map(prefix, toOperand) }),\n\tprincipal: (path: string) => Nodes.principalRef(path),\n\tand: (...conditions: ReadonlyArray<Ast>) => andOf(conditions),\n\tor: (...conditions: ReadonlyArray<Ast>) => orOf(conditions),\n\tnot: makeNot,\n\tpredicate: (\n\t\tname: string,\n\t\ttest: (\n\t\t\tvalue: unknown,\n\t\t\tprincipal: unknown,\n\t\t) => boolean | Effect.Effect<boolean, unknown, unknown>,\n\t) =>\n\t\tnew Nodes.Predicate({\n\t\t\tname,\n\t\t\trun: (value, principal) =>\n\t\t\t\tEffect.suspend(() => {\n\t\t\t\t\tconst result = test(value, principal)\n\t\t\t\t\treturn Effect.isEffect(result) ? result : Effect.succeed(result)\n\t\t\t\t}),\n\t\t}),\n} as never\n\n/**\n * Makes a builder. Rules give you a builder with the right types, so you do not\n * often need this.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport const builder = <Data, Value, P>(): Builder<Data, Value, P> =>\n\tsharedBuilder\n\n/**\n * Always true.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport const always: Condition = Nodes.always as never\n\n/**\n * Always false.\n *\n * @stability stable\n * @category constructors\n * @since 0.3.0\n */\nexport const never: Condition = Nodes.never as never\n\n/**\n * True when all the conditions are true. With no conditions, it is true.\n *\n * @stability stable\n * @category combinators\n * @since 0.3.0\n */\nexport const and: <const Cs extends ReadonlyArray<Any>>(\n\t...conditions: Cs\n) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>> = ((\n\t...conditions: ReadonlyArray<Ast>\n) => andOf(conditions)) as never\n\n/**\n * The same as {@link and}, for a list of conditions of one type. Use it for a\n * long list: a function call may take only so many arguments.\n *\n * @stability stable\n * @category combinators\n * @since 1.0.0\n */\nexport const andAll: <C extends Any>(\n\tconditions: ReadonlyArray<C>,\n) => Condition<ReadsOf<C>, OpaqueOf<C>> = andOf as never\n\n/**\n * The same as {@link or}, for a list of conditions of one type. Use it for a\n * long list: a function call may take only so many arguments.\n *\n * @stability stable\n * @category combinators\n * @since 1.0.0\n */\nexport const orAll: <C extends Any>(\n\tconditions: ReadonlyArray<C>,\n) => Condition<ReadsOf<C>, OpaqueOf<C>> = orOf as never\n\n/**\n * True when one of the conditions is true. With no conditions, it is false.\n *\n * @stability stable\n * @category combinators\n * @since 0.3.0\n */\nexport const or: <const Cs extends ReadonlyArray<Any>>(\n\t...conditions: Cs\n) => Condition<ReadsOf<Cs[number]>, OpaqueOf<Cs[number]>> = ((\n\t...conditions: ReadonlyArray<Ast>\n) => orOf(conditions)) as never\n\n/**\n * @stability stable\n * @category combinators\n * @since 0.3.0\n */\nexport const not: <C extends Any>(\n\tcondition: C,\n) => Condition<ReadsOf<C>, OpaqueOf<C>> = makeNot as never\n\n/**\n * The data that a condition needs for a test.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Input {\n\t/** The resource value. */\n\treadonly value: object\n\t/**\n\t * The principal. Without it, a principal field has no value. See\n\t * {@link PrincipalRef}.\n\t */\n\treadonly principal?: object | undefined\n\t/** The path of the resource. Without it, `Under` is false. */\n\treadonly path?: ReadonlyArray<Resource.PathSegment> | undefined\n}\n\n/** Gives a condition as a node. A value that no constructor made is a defect. */\nconst nodeOf = (condition: Ast): Nodes.Node => Nodes.toNode(condition)\n\n/**\n * Gives the services in `context` to every predicate of a condition, so the\n * condition needs no services when it runs.\n *\n * @stability stable\n * @category services\n * @since 1.0.0\n */\nexport const provideContext: {\n\t<R>(\n\t\tcontext: Context.Context<R>,\n\t): <I, X>(\n\t\tcondition: Condition<I, X> &\n\t\t\t([ServicesOf<X>] extends [R] ? unknown : never),\n\t) => Condition<I, Provided<X>>\n\t<I, X>(\n\t\tcondition: Condition<I, X>,\n\t\tcontext: Context.Context<ServicesOf<X>>,\n\t): Condition<I, Provided<X>>\n} = dual(2, (condition: Ast, context: Context.Context<never>): Ast =>\n\tAlgebra.provide(nodeOf(condition), context),\n) as never\n\n/**\n * The input of {@link evaluate} that the predicates of a condition need: a\n * value and a principal of the types in `I`. See {@link Reads}.\n */\ntype ReadsInput<I> =\n\tI extends Reads<infer V, infer P>\n\t\t? { readonly value: V } & (unknown extends P\n\t\t\t\t? unknown\n\t\t\t\t: { readonly principal: P })\n\t\t: unknown\n\n/**\n * Tests a condition on a value. A predicate may fail with its error. When the\n * condition has a predicate, the input must have the value and the principal\n * that the predicate reads. The test runs on the simple form of the condition\n * with the principal in it, so it reads only the fields that a residual reads.\n *\n * @stability stable\n * @category evaluation\n * @since 0.3.0\n */\nexport const evaluate: <I, X, In extends Input>(\n\tcondition: Condition<I, X>,\n\tinput: In & ReadsInput<I>,\n) => Effect.Effect<boolean, ErrorOf<X>, ServicesOf<X>> = ((\n\tcondition: Ast,\n\tinput: Input,\n): Effect.Effect<boolean, unknown, unknown> =>\n\tEffect.suspend(() => Algebra.evaluate(nodeOf(condition), input))) as never\n\n/**\n * Tests a condition with no predicate on a value, at once.\n *\n * @stability stable\n * @category evaluation\n * @since 0.3.0\n */\nexport const evaluateSync: <I, In extends Input>(\n\tcondition: Condition<I>,\n\tinput: In & ReadsInput<I>,\n) => boolean = (condition: Ast, input: Input): boolean =>\n\tAlgebra.evaluateSync(nodeOf(condition), input)\n\n/**\n * Makes a condition smaller without a change to its meaning. It removes `True`\n * and `False` from `And` and `Or`, joins nested `And` and `Or` nodes, and\n * removes double `Not` nodes and copies of a child.\n *\n * @stability stable\n * @category evaluation\n * @since 0.3.0\n */\nexport const simplify: <I, X>(condition: Condition<I, X>) => Condition<I, X> =\n\t((condition: Ast) => condition.pipe(nodeOf, Algebra.simplify)) as never\n\ninterface PartialInput {\n\treadonly principal?: object | undefined\n\treadonly path?: ReadonlyArray<Resource.PathSegment> | undefined\n}\n\n/**\n * The principal that {@link partial} must get for the predicates of a\n * condition. A predicate keeps the principal that it gets, so the principal\n * must have the type that the predicate reads.\n */\ntype PrincipalInput<I> =\n\tI extends Reads<infer _V, infer P>\n\t\t? unknown extends P\n\t\t\t? unknown\n\t\t\t: { readonly principal: P }\n\t\t: unknown\n\n/** What a condition reads after {@link partial}: the value, and no principal. */\ntype Bound<I> = I extends Reads<infer V, infer _P> ? Reads<V, unknown> : I\n\n/**\n * Puts the principal into a condition and expands `Under` with the path of the\n * resource. The result is simplified. It has no principal fields and no\n * `Under` nodes. It is `True` or `False` when the answer does not depend on the\n * resource value.\n *\n * @stability stable\n * @category evaluation\n * @since 0.3.0\n */\nexport const partial: <I, X>(\n\tcondition: Condition<I, X>,\n\tinput: PartialInput & PrincipalInput<I>,\n) => Condition<Bound<I>, X> = ((condition: Ast, input: PartialInput): Ast =>\n\tAlgebra.partial(nodeOf(condition), input)) as never\n\n/**\n * The functions that change each node of a condition into another form, such\n * as a database query.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Interpreter<A> {\n\treadonly true: () => A\n\treadonly false: () => A\n\treadonly compare: (op: CompareOperator, field: string, value: Scalar) => A\n\treadonly in: (field: string, values: ReadonlyArray<Scalar>) => A\n\treadonly exists: (field: string) => A\n\treadonly and: (conditions: ReadonlyArray<A>) => A\n\treadonly or: (conditions: ReadonlyArray<A>) => A\n\treadonly not: (condition: A) => A\n\t/** Optional. Without it, a predicate makes `fold` fail. */\n\treadonly predicate?: (name: string) => A\n}\n\n/**\n * The error when `fold` can not change a node.\n *\n * @stability stable\n * @category errors\n * @since 0.3.0\n */\nexport class Untranslatable extends Schema.TaggedError<Untranslatable>(\n\t\"@nmnmcc/ability/Condition/Untranslatable\",\n)(\"Untranslatable\", { reason: Schema.String }) {}\n\nconst literalValue = (operand: Operand, field: string): Scalar => {\n\tif (operand._tag !== \"Literal\") {\n\t\tthrow Untranslatable.make({\n\t\t\treason: `The field \"${field}\" uses a principal field. Call Condition.partial first.`,\n\t\t})\n\t}\n\treturn operand.value\n}\n\n/**\n * Folds a condition. A shared child is folded again for each place. The walk\n * takes the steps of a trampoline, so a deep condition does not fill the\n * stack.\n */\nconst foldNode = <A>(root: Nodes.Node, interpreter: Interpreter<A>): A =>\n\tTrampoline.run(root.depth, (R) => {\n\t\tconst go = (node: Nodes.Node): Trampoline.Step<A> => {\n\t\t\tconst children = (nodes: ReadonlyArray<Nodes.Node>) =>\n\t\t\t\tR.forEach(nodes, (child) => R.suspend(() => go(child)))\n\t\t\tswitch (node._tag) {\n\t\t\t\tcase \"True\":\n\t\t\t\t\treturn R.succeed(interpreter.true())\n\t\t\t\tcase \"False\":\n\t\t\t\t\treturn R.succeed(interpreter.false())\n\t\t\t\tcase \"Compare\":\n\t\t\t\t\treturn R.succeed(\n\t\t\t\t\t\tinterpreter.compare(\n\t\t\t\t\t\t\tnode.op,\n\t\t\t\t\t\t\tnode.field,\n\t\t\t\t\t\t\tliteralValue(node.value, node.field),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\tcase \"In\":\n\t\t\t\t\treturn R.succeed(\n\t\t\t\t\t\tinterpreter.in(\n\t\t\t\t\t\t\tnode.field,\n\t\t\t\t\t\t\tArr.map(node.values, (operand) =>\n\t\t\t\t\t\t\t\tliteralValue(operand, node.field),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\tcase \"Exists\":\n\t\t\t\t\treturn R.succeed(interpreter.exists(node.field))\n\t\t\t\tcase \"Under\":\n\t\t\t\t\tthrow Untranslatable.make({\n\t\t\t\t\t\treason:\n\t\t\t\t\t\t\t\"An Under node needs the resource path. Call Condition.partial first.\",\n\t\t\t\t\t})\n\t\t\t\tcase \"And\":\n\t\t\t\t\treturn R.map(children(node.conditions), interpreter.and)\n\t\t\t\tcase \"Or\":\n\t\t\t\t\treturn R.map(children(node.conditions), interpreter.or)\n\t\t\t\tcase \"Not\":\n\t\t\t\t\treturn R.map(\n\t\t\t\t\t\tR.suspend(() => go(node.condition)),\n\t\t\t\t\t\tinterpreter.not,\n\t\t\t\t\t)\n\t\t\t\tcase \"Predicate\":\n\t\t\t\t\tif (interpreter.predicate === undefined) {\n\t\t\t\t\t\tthrow Untranslatable.make({\n\t\t\t\t\t\t\treason: `The predicate \"${node.name}\" can not become a query`,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t\treturn R.succeed(interpreter.predicate(node.name))\n\t\t\t}\n\t\t}\n\t\treturn go(root)\n\t})\n\n/**\n * Changes a condition into another form with an interpreter. Call\n * {@link partial} first: `fold` fails on principal fields and on `Under`\n * nodes, and on predicates when the interpreter has no `predicate` function.\n *\n * @stability stable\n * @category converting\n * @since 0.3.0\n */\nexport const fold: {\n\t<A>(\n\t\tinterpreter: Interpreter<A>,\n\t): (condition: Any) => Effect.Effect<A, Untranslatable>\n\t<A>(\n\t\tcondition: Any,\n\t\tinterpreter: Interpreter<A>,\n\t): Effect.Effect<A, Untranslatable>\n} = dual(\n\t2,\n\t<A>(\n\t\tcondition: Ast,\n\t\tinterpreter: Interpreter<A>,\n\t): Effect.Effect<A, Untranslatable> =>\n\t\tEffect.try({\n\t\t\ttry: () => foldNode(nodeOf(condition), interpreter),\n\t\t\tcatch: (cause) => {\n\t\t\t\tif (cause instanceof Untranslatable) {\n\t\t\t\t\treturn cause\n\t\t\t\t}\n\t\t\t\tthrow cause\n\t\t\t},\n\t\t}),\n)\n\n/**\n * The fields that a condition uses, in the order that they first come.\n *\n * @stability stable\n * @category getters\n * @since 0.3.0\n */\nexport const fields = (condition: Ast): ReadonlyArray<string> =>\n\tcondition.pipe(nodeOf, Algebra.fields)\n\n// Satisfiability\n\n/**\n * Values of fields, as a nested object. A field that is not in it may have any\n * value. A value with parts that the search does not look into, such as a\n * date, is an empty object.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport type Example = Search.Example\n\n/**\n * The answer of {@link satisfiable}:\n * - `Satisfiable`: some value makes the condition true. `example` is one.\n * - `Unsatisfiable`: no value makes the condition true.\n * - `Unknown`: the search can not say. The condition has a predicate, or\n * the search went past its budget.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport type Satisfiability = Search.Satisfiability\n\n/**\n * The options of {@link satisfiable}.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\nexport interface SatisfiableOptions {\n\t/**\n\t * The Schema of the values. Its shape gives the kinds of values of each\n\t * field. Without it, a field may have any value.\n\t */\n\treadonly schema?: Schema.Top | undefined\n\t/** The most steps that the search may take. The default is 1000000. */\n\treadonly budget?: number | undefined\n}\n\n/**\n * Tests if some value makes a condition true, and gives such a value.\n *\n * Call {@link partial} first: the condition must have no principal fields and\n * no `Under` nodes. A condition with a predicate gives `Unknown`.\n *\n * Each test of a condition compares one field with constants, so the\n * constants cut the values of each field into a few cells. The search tries\n * one value from each cell, one field at a time. The values of a field come\n * from the shape of the Schema in `options.schema`: its literals, `null` for\n * a nullable or optional field, and finite or integer numbers.\n *\n * The search reads the shape of the Schema, not its other checks, such as a\n * minimum length. So `Unsatisfiable` holds for every value of the Schema. A\n * `Satisfiable` example fits the shape, but a check may still stop it.\n *\n * The problem is as hard as boolean satisfiability, so the search has a\n * budget. Past it, the answer is `Unknown`. A condition with more than 256\n * fields gives `Unknown` too.\n *\n * @stability stable\n * @category evaluation\n * @since 1.0.0\n */\nexport const satisfiable = (\n\tcondition: Any,\n\toptions: SatisfiableOptions = {},\n): Satisfiability =>\n\tSearch.satisfiable(\n\t\tnodeOf(condition),\n\t\tSearch.kindsIn(\n\t\t\toptions.schema === undefined\n\t\t\t\t? undefined\n\t\t\t\t: Catalog.catalogOf(options.schema.ast),\n\t\t),\n\t\toptions.budget,\n\t)\n\n/**\n * The JSON form of an operand.\n *\n * @stability stable\n * @category models\n * @since 2.0.0\n */\nexport type EncodedOperand =\n\t| { readonly _tag: \"Literal\"; readonly value: Scalar }\n\t| { readonly _tag: \"Principal\"; readonly path: string }\n\n/**\n * The JSON form of a condition with no predicate.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport type Encoded =\n\t| { readonly _tag: \"True\" }\n\t| { readonly _tag: \"False\" }\n\t| {\n\t\t\treadonly _tag: \"Compare\"\n\t\t\treadonly op: CompareOperator\n\t\t\treadonly field: string\n\t\t\treadonly value: EncodedOperand\n\t }\n\t| {\n\t\t\treadonly _tag: \"In\"\n\t\t\treadonly field: string\n\t\t\treadonly values: ReadonlyArray<EncodedOperand>\n\t }\n\t| { readonly _tag: \"Exists\"; readonly field: string }\n\t| { readonly _tag: \"Under\"; readonly prefix: ReadonlyArray<EncodedOperand> }\n\t| {\n\t\t\treadonly _tag: \"And\" | \"Or\"\n\t\t\treadonly conditions: ReadonlyArray<Encoded>\n\t }\n\t| { readonly _tag: \"Not\"; readonly condition: Encoded }\n\n/**\n * A condition with no predicate, that may read any values. It is the type of\n * {@link schema}: a decoded condition reads nothing, so it fits any rule, and\n * any plain condition, such as one from a builder or a residual, may be\n * encoded.\n *\n * @stability stable\n * @category models\n * @since 1.0.0\n */\n// `any` for what it reads: the field is contravariant, so no other type both\n// takes every condition and fits every rule.\nexport type PlainCondition = Condition<any>\n\n/**\n * The Schema of a condition with no predicate. It checks the shape only. Use\n * `Policy.schema` to check the field names against a domain too.\n *\n * The decoder takes the default limits: at most `conditionNodes` nodes,\n * 1000000, and `jsonNodes` objects and array items, 10000000, with a shared\n * object counted for each place. It stops at the first one past a limit. It\n * takes any number of levels, and it reads only the own data fields of the\n * input. Use `Policy.schema` for the limits of a domain.\n *\n * @stability stable\n * @category schemas\n * @since 0.3.0\n */\nexport const schema: Schema.Codec<PlainCondition, Encoded> =\n\tSchema.Unknown.pipe(\n\t\tSchema.decodeTo(\n\t\t\tSchema.declare(\n\t\t\t\t(input): input is PlainCondition =>\n\t\t\t\t\tNodes.isNode(input) && !input.opaque,\n\t\t\t),\n\t\t\tSchemaTransformation.transformEffect({\n\t\t\t\tdecode: (input: unknown, options) =>\n\t\t\t\t\tResult.match(Json.decode(input), {\n\t\t\t\t\t\tonSuccess: (node) => Effect.succeed(node as never),\n\t\t\t\t\t\tonFailure: (problem) =>\n\t\t\t\t\t\t\tEffect.fail(\n\t\t\t\t\t\t\t\tnew SchemaIssue.Pointer(\n\t\t\t\t\t\t\t\t\tproblem.path,\n\t\t\t\t\t\t\t\t\tnew SchemaIssue.InvalidValue(\n\t\t\t\t\t\t\t\t\t\t{ message: problem.message },\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t}),\n\t\t\t\tencode: (condition: PlainCondition) =>\n\t\t\t\t\tEffect.sync(() => Json.toJson(condition as never)),\n\t\t\t}),\n\t\t),\n\t) as never\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAu3BA,MAAM,aAAa,MAClB,YAAY,GAAG,MAAM,MAAM,EAAE,SAAS,aAAa,EAAE,SAAS;AAE/D,MAAM,aAAa,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