@nmnmcc/ability 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +322 -469
  2. package/dist/Authorizer.d.ts +216 -0
  3. package/dist/Authorizer.d.ts.map +1 -0
  4. package/dist/Authorizer.js +55 -0
  5. package/dist/Authorizer.js.map +1 -0
  6. package/dist/Condition.d.ts +536 -0
  7. package/dist/Condition.d.ts.map +1 -0
  8. package/dist/Condition.js +141 -0
  9. package/dist/Condition.js.map +1 -0
  10. package/dist/Decision.d.ts +131 -0
  11. package/dist/Decision.d.ts.map +1 -0
  12. package/dist/Decision.js +83 -0
  13. package/dist/Decision.js.map +1 -0
  14. package/dist/Domain.d.ts +148 -0
  15. package/dist/Domain.d.ts.map +1 -0
  16. package/dist/Domain.js +34 -0
  17. package/dist/Domain.js.map +1 -0
  18. package/dist/HttpApi.d.ts +129 -0
  19. package/dist/HttpApi.d.ts.map +1 -0
  20. package/dist/HttpApi.js +95 -0
  21. package/dist/HttpApi.js.map +1 -0
  22. package/dist/Policy.d.ts +429 -0
  23. package/dist/Policy.d.ts.map +1 -0
  24. package/dist/Policy.js +162 -0
  25. package/dist/Policy.js.map +1 -0
  26. package/dist/Principal.d.ts +35 -0
  27. package/dist/Principal.d.ts.map +1 -0
  28. package/dist/Principal.js +37 -0
  29. package/dist/Principal.js.map +1 -0
  30. package/dist/Resource.d.ts +213 -0
  31. package/dist/Resource.d.ts.map +1 -0
  32. package/dist/Resource.js +71 -0
  33. package/dist/Resource.js.map +1 -0
  34. package/dist/Rule.d.ts +189 -0
  35. package/dist/Rule.d.ts.map +1 -0
  36. package/dist/Rule.js +50 -0
  37. package/dist/Rule.js.map +1 -0
  38. package/dist/_virtual/_rolldown/runtime.js +1 -2
  39. package/dist/index.d.ts +9 -3
  40. package/dist/index.js +9 -3
  41. package/dist/internal/authorizer.d.ts +28 -0
  42. package/dist/internal/authorizer.d.ts.map +1 -0
  43. package/dist/internal/authorizer.js +153 -0
  44. package/dist/internal/authorizer.js.map +1 -0
  45. package/dist/internal/condition.d.ts +11 -0
  46. package/dist/internal/condition.d.ts.map +1 -0
  47. package/dist/internal/condition.js +393 -0
  48. package/dist/internal/condition.js.map +1 -0
  49. package/dist/internal/domain.js +34 -0
  50. package/dist/internal/domain.js.map +1 -0
  51. package/dist/internal/httpApi.js +41 -0
  52. package/dist/internal/httpApi.js.map +1 -0
  53. package/dist/internal/policy.js +524 -0
  54. package/dist/internal/policy.js.map +1 -0
  55. package/dist/internal/resource.js +66 -0
  56. package/dist/internal/resource.js.map +1 -0
  57. package/dist/internal/rule.js +131 -0
  58. package/dist/internal/rule.js.map +1 -0
  59. package/package.json +61 -72
  60. package/src/Authorizer.ts +330 -0
  61. package/src/Condition.ts +706 -0
  62. package/src/Decision.ts +117 -0
  63. package/src/Domain.ts +189 -0
  64. package/src/HttpApi.ts +148 -0
  65. package/src/Policy.ts +575 -0
  66. package/src/Principal.ts +41 -0
  67. package/src/Resource.ts +290 -0
  68. package/src/Rule.ts +265 -0
  69. package/src/index.ts +57 -0
  70. package/src/internal/authorizer.ts +271 -0
  71. package/src/internal/condition.ts +607 -0
  72. package/src/internal/domain.ts +56 -0
  73. package/src/internal/httpApi.ts +84 -0
  74. package/src/internal/policy.ts +815 -0
  75. package/src/internal/resource.ts +98 -0
  76. package/src/internal/rule.ts +203 -0
  77. package/dist/Ability.d.ts +0 -491
  78. package/dist/Ability.js +0 -207
  79. package/dist/AbilityExtra.d.ts +0 -79
  80. package/dist/AbilityExtra.js +0 -187
  81. package/dist/internal/ability.d.ts +0 -90
  82. package/dist/internal/ability.js +0 -550
  83. package/dist/internal/serializable.js +0 -22
@@ -0,0 +1,216 @@
1
+ import { Condition, Opaque } from "./Condition.js";
2
+ import { Any, AnyAction, Principal } from "./Domain.js";
3
+ import { Decision } from "./Decision.js";
4
+ import { KindRequest, KindTarget, Policy, Request, Target as Target$1 } from "./Policy.js";
5
+ import { Forbidden as Forbidden$1, Pending as Pending$1, PolicyUnavailable as PolicyUnavailable$1 } from "./internal/authorizer.js";
6
+ import * as Context from "effect/Context";
7
+ import * as Effect from "effect/Effect";
8
+ import * as Layer from "effect/Layer";
9
+ import * as Duration from "effect/Duration";
10
+ declare namespace Authorizer_d_exports {
11
+ export { AnyServiceClass, Authorizer, Config, DeciderRequest, Forbidden, GuardOptions, Options, Pending, PolicyUnavailable, Service, ServiceClass, Target, layer };
12
+ }
13
+ /**
14
+ * The error when a policy says no.
15
+ *
16
+ * @stability stable
17
+ * @category errors
18
+ * @since 0.3.0
19
+ */
20
+ export declare const Forbidden: typeof Forbidden$1;
21
+ /**
22
+ * @stability stable
23
+ * @category errors
24
+ * @since 0.3.0
25
+ */
26
+ export type Forbidden = Forbidden$1;
27
+ /**
28
+ * The error when the policy of the principal can not be loaded. The cause is
29
+ * kept, but it is not shown to the client.
30
+ *
31
+ * @stability stable
32
+ * @category errors
33
+ * @since 0.3.0
34
+ */
35
+ export declare const PolicyUnavailable: typeof PolicyUnavailable$1;
36
+ /**
37
+ * @stability stable
38
+ * @category errors
39
+ * @since 0.3.0
40
+ */
41
+ export type PolicyUnavailable = PolicyUnavailable$1;
42
+ /**
43
+ * The error when a decider must wait for an answer. `ticket` names the
44
+ * request that waits, so the client can come back for the answer.
45
+ *
46
+ * @stability stable
47
+ * @category errors
48
+ * @since 0.3.0
49
+ */
50
+ export declare const Pending: typeof Pending$1;
51
+ /**
52
+ * @stability stable
53
+ * @category errors
54
+ * @since 0.3.0
55
+ */
56
+ export type Pending = Pending$1;
57
+ /**
58
+ * The services and the errors of the principal and the decider of an
59
+ * authorizer.
60
+ *
61
+ * @stability stable
62
+ * @category models
63
+ * @since 0.3.0
64
+ */
65
+ export interface Config {
66
+ readonly requires?: unknown;
67
+ readonly error?: unknown;
68
+ }
69
+ type RequiresOf<C> = C extends {
70
+ readonly requires: infer R;
71
+ } ? R : never;
72
+ type ErrorOf<C> = C extends {
73
+ readonly error: infer E;
74
+ } ? E : never;
75
+ /**
76
+ * What a check is about: an act on a resource value, or an act on a kind of
77
+ * resource. A check on a kind passes only when the policy allows the act on
78
+ * every value of the kind.
79
+ *
80
+ * @stability stable
81
+ * @category models
82
+ * @since 0.3.0
83
+ */
84
+ export type Target<D> = Target$1<D> | KindTarget<D>;
85
+ /**
86
+ * A request to the decider.
87
+ *
88
+ * @stability stable
89
+ * @category models
90
+ * @since 0.3.0
91
+ */
92
+ export type DeciderRequest<D> = Request<D> | KindRequest<D>;
93
+ /**
94
+ * The options of a guard.
95
+ *
96
+ * @stability stable
97
+ * @category models
98
+ * @since 0.3.0
99
+ */
100
+ export interface GuardOptions<D, E2> {
101
+ /** The action that lets the principal see the resource. The default is `"read"`. */
102
+ readonly read?: AnyAction<D>;
103
+ /** The error when the principal may not see the resource. */
104
+ readonly hide: () => E2;
105
+ }
106
+ /**
107
+ * The service.
108
+ *
109
+ * @stability stable
110
+ * @category models
111
+ * @since 0.3.0
112
+ */
113
+ export interface Authorizer<D extends Any, E, R> {
114
+ readonly domain: D;
115
+ /** The principal of the current request. */
116
+ readonly principal: Effect.Effect<Principal<D>, E, R>;
117
+ /** The policy of the principal of the current request. */
118
+ readonly policy: Effect.Effect<Policy<D, E>, PolicyUnavailable | E, R>;
119
+ /** Gives the decision of the policy. It does not ask the decider. */
120
+ readonly decide: (target: Target$1<D>) => Effect.Effect<Decision, PolicyUnavailable | E, R>;
121
+ /** Succeeds when the principal may do the act, and fails when it may not. */
122
+ readonly check: (target: Target<D>) => Effect.Effect<void, Forbidden | Pending | PolicyUnavailable | E, R>;
123
+ /**
124
+ * Checks the read action first, and fails with the error of `hide` when the
125
+ * principal may not see the resource. Then it checks the act. Use it to
126
+ * answer "not found" to a principal that may not know that a resource
127
+ * exists.
128
+ */
129
+ readonly guard: <E2>(target: Target$1<D>, options: GuardOptions<D, E2>) => Effect.Effect<void, E2 | Forbidden | Pending | PolicyUnavailable | E, R>;
130
+ /**
131
+ * Gives the condition on resource values that the principal may act on.
132
+ * Change it into a query with `Condition.fold`.
133
+ */
134
+ readonly filter: (target: KindTarget<D>) => Effect.Effect<Condition<E, never, Opaque>, PolicyUnavailable | E, R>;
135
+ /** Gives the fields of a value that the principal may use. */
136
+ readonly permittedFields: (target: Omit<Target$1<D>, "field">) => Effect.Effect<ReadonlyArray<string>, PolicyUnavailable | E, R>;
137
+ /**
138
+ * Removes the cached policy of a principal, or of every principal. Call it
139
+ * after a change to the rules or roles of a principal.
140
+ */
141
+ readonly invalidate: (principal?: Principal<D>) => Effect.Effect<void>;
142
+ }
143
+ /**
144
+ * The class made by {@link Service}. The static functions use the service
145
+ * from the context.
146
+ *
147
+ * @stability stable
148
+ * @category models
149
+ * @since 0.3.0
150
+ */
151
+ export interface ServiceClass<Self, Id extends string, D extends Any, E, R> extends Context.ServiceClass<Self, Id, Authorizer<D, E, R>> {
152
+ readonly domain: D;
153
+ readonly decide: (target: Target$1<D>) => Effect.Effect<Decision, PolicyUnavailable | E, R | Self>;
154
+ readonly check: (target: Target<D>) => Effect.Effect<void, Forbidden | Pending | PolicyUnavailable | E, R | Self>;
155
+ readonly guard: <E2>(target: Target$1<D>, options: GuardOptions<D, E2>) => Effect.Effect<void, E2 | Forbidden | Pending | PolicyUnavailable | E, R | Self>;
156
+ readonly filter: (target: KindTarget<D>) => Effect.Effect<Condition<E, never, Opaque>, PolicyUnavailable | E, R | Self>;
157
+ readonly permittedFields: (target: Omit<Target$1<D>, "field">) => Effect.Effect<ReadonlyArray<string>, PolicyUnavailable | E, R | Self>;
158
+ }
159
+ /**
160
+ * Any service class made by {@link Service}.
161
+ *
162
+ * @stability stable
163
+ * @category models
164
+ * @since 0.3.0
165
+ */
166
+ export type AnyServiceClass = Context.Key<any, any> & {
167
+ readonly domain: Any;
168
+ };
169
+ /**
170
+ * Makes an authorizer service class for a domain.
171
+ *
172
+ * @stability stable
173
+ * @category constructors
174
+ * @since 0.3.0
175
+ */
176
+ export declare const Service: <Self, C extends Config = {}>() => <const Id extends string, D extends Any>(id: Id, domain: D) => ServiceClass<Self, Id, D, ErrorOf<C>, RequiresOf<C>>;
177
+ /**
178
+ * The options of {@link layer}.
179
+ *
180
+ * @stability stable
181
+ * @category models
182
+ * @since 0.3.0
183
+ */
184
+ export interface Options<D extends Any, E, R, EL, RL, RP> {
185
+ /** Gives the principal of the current request. */
186
+ readonly principal: Effect.Effect<Principal<D>, E, R>;
187
+ /**
188
+ * Loads the policy of a principal. A failure becomes
189
+ * {@link PolicyUnavailable}. The services of the predicates of the policy
190
+ * are taken when the layer is built.
191
+ */
192
+ readonly policy: (principal: Principal<D>) => Effect.Effect<Policy<D, E, RP, any>, EL, RL>;
193
+ /**
194
+ * Answers when no rule gives an answer. Without a decider, such a request
195
+ * fails with {@link Forbidden}.
196
+ */
197
+ readonly decider?: (request: DeciderRequest<D>) => Effect.Effect<Decision, Pending | E, R>;
198
+ /**
199
+ * How the policies are kept. The default keeps 1000 policies for 30 seconds.
200
+ * Give `false` to load the policy for each check.
201
+ */
202
+ readonly cache?: {
203
+ readonly capacity?: number;
204
+ readonly timeToLive?: Duration.Input;
205
+ } | false;
206
+ }
207
+ /**
208
+ * Makes the layer of an authorizer.
209
+ *
210
+ * @stability stable
211
+ * @category layers
212
+ * @since 0.3.0
213
+ */
214
+ export declare const layer: <Self, Id extends string, D extends Any, E, R, EL = never, RL = never, RP = never>(service: ServiceClass<Self, Id, D, E, R>, options: Options<D, NoInfer<E>, NoInfer<R>, EL, RL, RP>) => Layer.Layer<Self, never, RL | RP>;
215
+ export { Authorizer_d_exports };
216
+ //# sourceMappingURL=Authorizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Authorizer.d.ts","names":["internal.Forbidden","internal.PolicyUnavailable","internal.Pending","Policy.Target","Policy.KindTarget","Policy.Request","Policy.KindRequest","Domain.AnyAction","Domain.Any","Domain.Principal","Policy.Policy","Decision.Decision","Condition.Opaque","Condition.Condition"],"sources":["../src/Authorizer.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBAqDa,kBAAkBA;;;;;;YAOnB,YAAYA;;;;;;;;;qBAUX,0BAA0BC;;;;;;YAQ3B,oBAAoBA;;;;;;;;;qBAUnB,gBAAgBC;;;;;;YAOjB,UAAUA;;;;;;;;;iBAUL;WACP;WACA;;KAGL,WAAW,KAAK;WAAqB,gBAAgB;IAAM;KAC3D,QAAQ,KAAK;WAAqB,aAAa;IAAM;;;;;;;;;;YAW9C,OAAO,KAAKC,SAAc,KAAKC,WAAkB;;;;;;;;YASjD,eAAe,KAAKC,QAAe,KAAKC,YAAmB;;;;;;;;iBAStD,aAAa,GAAG;;WAEvB,OAAOC,UAAiB;;WAExB,YAAY;;;;;;;;;iBAUL,WAAW,UAAUC,KAAY,GAAG;WAC3C,QAAQ;;WAER,WAAW,OAAO,OAAOC,UAAiB,IAAI,GAAG;;WAEjD,QAAQ,OAAO,OAAOC,OAAc,GAAG,IAAI,oBAAoB,GAAG;;WAElE,SACR,QAAQP,SAAc,OAClB,OAAO,OAAOQ,UAAmB,oBAAoB,GAAG;;WAEpD,QACR,QAAQ,OAAO,OACX,OAAO,aAAa,YAAY,UAAU,oBAAoB,GAAG;;;;;;;WAO7D,QAAQ,IAChB,QAAQR,SAAc,IACtB,SAAS,aAAa,GAAG,QACrB,OAAO,aAAa,KAAK,YAAY,UAAU,oBAAoB,GAAG;;;;;WAKlE,SACR,QAAQC,WAAkB,OACtB,OAAO,OACXS,UAAoB,UAAUD,SAC9B,oBAAoB,GACpB;;WAGQ,kBACR,QAAQ,KAAKT,SAAc,iBACvB,OAAO,OAAO,uBAAuB,oBAAoB,GAAG;;;;;WAKxD,aAAa,YAAYM,UAAiB,OAAO,OAAO;;;;;;;;;;iBAWjD,aAChB,MACA,mBACA,UAAUD,KACV,GACA,WACS,QAAQ,aAAa,MAAM,IAAI,WAAW,GAAG,GAAG;WAChD,QAAQ;WACR,SACR,QAAQL,SAAc,OAClB,OAAO,OAAOQ,UAAmB,oBAAoB,GAAG,IAAI;WACxD,QACR,QAAQ,OAAO,OACX,OAAO,aAEX,YAAY,UAAU,oBAAoB,GAC1C,IAAI;WAEI,QAAQ,IAChB,QAAQR,SAAc,IACtB,SAAS,aAAa,GAAG,QACrB,OAAO,aAEX,KAAK,YAAY,UAAU,oBAAoB,GAC/C,IAAI;WAEI,SACR,QAAQC,WAAkB,OACtB,OAAO,OACXS,UAAoB,UAAUD,SAC9B,oBAAoB,GACpB,IAAI;WAEI,kBACR,QAAQ,KAAKT,SAAc,iBACvB,OAAO,OAAO,uBAAuB,oBAAoB,GAAG,IAAI;;;;;;;;;YAU1D,kBAAkB,QAAQ;WAC5B,QAAQK;;;;;;;;;qBAUL,UAAU,MAAM,UAAU,yBAChC,mBACN,UAAUA,KAEV,IAAI,IACJ,QAAQ,MACJ,aAAa,MAAM,IAAI,GAAG,QAAQ,IAAI,WAAW;;;;;;;;iBAUrC,QAAQ,UAAUA,KAAY,GAAG,GAAG,IAAI,IAAI;;WAEnD,WAAW,OAAO,OAAOC,UAAiB,IAAI,GAAG;;;;;;WAMjD,SACR,WAAWA,UAAiB,OACxB,OAAO,OAAOC,OAAc,GAAG,GAAG,UAAU,IAAI;;;;;WAK5C,WACR,SAAS,eAAe,OACpB,OAAO,OAAOC,UAAmB,UAAU,GAAG;;;;;WAK1C;aAEG;aACA,aAAa,SAAS;;;;;;;;;;qBAYtB,QACZ,MACA,mBACA,UAAUH,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"}
@@ -0,0 +1,55 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { Forbidden as Forbidden$1, Pending as Pending$1, PolicyUnavailable as PolicyUnavailable$1, Service as Service$1, layer as layer$1 } from "./internal/authorizer.js";
3
+ // src/Authorizer.ts
4
+ var Authorizer_exports = /* @__PURE__ */ __exportAll({
5
+ Forbidden: () => Forbidden,
6
+ Pending: () => Pending,
7
+ PolicyUnavailable: () => PolicyUnavailable,
8
+ Service: () => Service,
9
+ layer: () => layer
10
+ });
11
+ /**
12
+ * The error when a policy says no.
13
+ *
14
+ * @stability stable
15
+ * @category errors
16
+ * @since 0.3.0
17
+ */
18
+ const Forbidden = Forbidden$1;
19
+ /**
20
+ * The error when the policy of the principal can not be loaded. The cause is
21
+ * kept, but it is not shown to the client.
22
+ *
23
+ * @stability stable
24
+ * @category errors
25
+ * @since 0.3.0
26
+ */
27
+ const PolicyUnavailable = PolicyUnavailable$1;
28
+ /**
29
+ * The error when a decider must wait for an answer. `ticket` names the
30
+ * request that waits, so the client can come back for the answer.
31
+ *
32
+ * @stability stable
33
+ * @category errors
34
+ * @since 0.3.0
35
+ */
36
+ const Pending = Pending$1;
37
+ /**
38
+ * Makes an authorizer service class for a domain.
39
+ *
40
+ * @stability stable
41
+ * @category constructors
42
+ * @since 0.3.0
43
+ */
44
+ const Service = Service$1;
45
+ /**
46
+ * Makes the layer of an authorizer.
47
+ *
48
+ * @stability stable
49
+ * @category layers
50
+ * @since 0.3.0
51
+ */
52
+ const layer = layer$1;
53
+ export { Authorizer_exports, Forbidden, Pending, PolicyUnavailable, Service, layer };
54
+
55
+ //# sourceMappingURL=Authorizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Authorizer.js","names":["internal.Forbidden","internal.PolicyUnavailable","internal.Pending","internal.Service","internal.layer"],"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 * services that the principal and the decider need as `requires`, and their\n * errors as `error`:\n *\n * ```ts\n * class Auth extends Authorizer.Service<Auth, { requires: Identity }>()(\n * \"app/Auth\",\n * App,\n * ) {}\n * ```\n *\n * Then give a layer with {@link layer}. It says where the principal comes\n * from and how to load its policy. The policy of each principal is loaded\n * once and kept in a cache for a short time.\n *\n * Then use the service in a handler:\n *\n * ```ts\n * yield* Auth.check({ action: \"update\", resource: bot })\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 a Bot 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 * The services and the errors of the principal and the decider of an\n * authorizer.\n *\n * @stability stable\n * @category models\n * @since 0.3.0\n */\nexport interface Config {\n\treadonly requires?: unknown\n\treadonly error?: unknown\n}\n\ntype RequiresOf<C> = C extends { readonly requires: infer R } ? R : never\ntype ErrorOf<C> = C extends { readonly error: infer E } ? E : never\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.\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 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 interface GuardOptions<D, E2> {\n\t/** The action that lets the principal see the resource. The default is `\"read\"`. */\n\treadonly read?: Domain.AnyAction<D>\n\t/** The error when the principal may not see the resource. */\n\treadonly hide: () => E2\n}\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/** The policy of the principal of the current request. */\n\treadonly policy: Effect.Effect<Policy.Policy<D, E>, PolicyUnavailable | E, R>\n\t/** Gives the decision of the policy. It does not ask the decider. */\n\treadonly decide: (\n\t\ttarget: Policy.Target<D>,\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: (\n\t\ttarget: Target<D>,\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: <E2>(\n\t\ttarget: Policy.Target<D>,\n\t\toptions: GuardOptions<D, E2>,\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 * Change it into a query with `Condition.fold`.\n\t */\n\treadonly filter: (\n\t\ttarget: Policy.KindTarget<D>,\n\t) => Effect.Effect<\n\t\tCondition.Condition<E, never, Condition.Opaque>,\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: Omit<Policy.Target<D>, \"field\">,\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\treadonly decide: (\n\t\ttarget: Policy.Target<D>,\n\t) => Effect.Effect<Decision.Decision, PolicyUnavailable | E, R | Self>\n\treadonly check: (\n\t\ttarget: Target<D>,\n\t) => Effect.Effect<\n\t\tvoid,\n\t\tForbidden | Pending | PolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly guard: <E2>(\n\t\ttarget: Policy.Target<D>,\n\t\toptions: GuardOptions<D, E2>,\n\t) => Effect.Effect<\n\t\tvoid,\n\t\tE2 | Forbidden | Pending | PolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly filter: (\n\t\ttarget: Policy.KindTarget<D>,\n\t) => Effect.Effect<\n\t\tCondition.Condition<E, never, Condition.Opaque>,\n\t\tPolicyUnavailable | E,\n\t\tR | Self\n\t>\n\treadonly permittedFields: (\n\t\ttarget: Omit<Policy.Target<D>, \"field\">,\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}\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, C extends Config = {}>() => <\n\tconst Id extends string,\n\tD extends Domain.Any,\n>(\n\tid: Id,\n\tdomain: D,\n) => ServiceClass<Self, Id, D, ErrorOf<C>, RequiresOf<C>> =\n\tinternal.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/** Gives the principal of the current request. */\n\treadonly principal: Effect.Effect<Domain.Principal<D>, E, R>\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, E, RP, any>, 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\treadonly cache?:\n\t\t| {\n\t\t\t\treadonly capacity?: number\n\t\t\t\treadonly timeToLive?: Duration.Input\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.layer as never\n"],"mappings":";;;;;;;;;;;;;;;;;AAqDA,MAAa,YAAuCA;;;;;;;;;AAiBpD,MAAa,oBACZC;;;;;;;;;AAiBD,MAAa,UAAmCC;;;;;;;;AAgLhD,MAAa,UAOZC;;;;;;;;AA8CD,MAAa,QAY4BC"}