@visiolab/effect-firebase 0.0.0-stage → 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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +81 -2
  3. package/dist/_virtual/_rolldown/runtime.mjs +12 -0
  4. package/dist/app/App.d.mts +27 -0
  5. package/dist/app/App.mjs +27 -0
  6. package/dist/app/index.d.mts +2 -0
  7. package/dist/app/index.mjs +1 -0
  8. package/dist/firestore/Collection.d.mts +423 -0
  9. package/dist/firestore/Collection.mjs +133 -0
  10. package/dist/firestore/CollectionGroup.d.mts +164 -0
  11. package/dist/firestore/CollectionGroup.mjs +84 -0
  12. package/dist/firestore/DocumentPath.d.mts +95 -0
  13. package/dist/firestore/DocumentPath.mjs +71 -0
  14. package/dist/firestore/DocumentSnapshot.d.mts +239 -0
  15. package/dist/firestore/DocumentSnapshot.mjs +134 -0
  16. package/dist/firestore/FieldValue.d.mts +332 -0
  17. package/dist/firestore/FieldValue.mjs +256 -0
  18. package/dist/firestore/Firestore.d.mts +1165 -0
  19. package/dist/firestore/Firestore.mjs +274 -0
  20. package/dist/firestore/FirestoreModel.d.mts +1232 -0
  21. package/dist/firestore/FirestoreModel.mjs +586 -0
  22. package/dist/firestore/FirestoreSchema.d.mts +567 -0
  23. package/dist/firestore/FirestoreSchema.mjs +419 -0
  24. package/dist/firestore/FirestoreValue.d.mts +145 -0
  25. package/dist/firestore/FirestoreValue.mjs +87 -0
  26. package/dist/firestore/GeoPoint.d.mts +90 -0
  27. package/dist/firestore/GeoPoint.mjs +75 -0
  28. package/dist/firestore/Patch.d.mts +73 -0
  29. package/dist/firestore/Patch.mjs +57 -0
  30. package/dist/firestore/QuerySnapshot.d.mts +107 -0
  31. package/dist/firestore/QuerySnapshot.mjs +43 -0
  32. package/dist/firestore/Timestamp.d.mts +273 -0
  33. package/dist/firestore/Timestamp.mjs +255 -0
  34. package/dist/firestore/index.d.mts +14 -0
  35. package/dist/firestore/index.mjs +14 -0
  36. package/dist/firestore/internal/collection.mjs +156 -0
  37. package/dist/firestore/internal/collectionGroup.mjs +64 -0
  38. package/dist/firestore/internal/documentPath.d.mts +4 -0
  39. package/dist/firestore/internal/documentPath.mjs +42 -0
  40. package/dist/firestore/internal/documentSnapshot.mjs +63 -0
  41. package/dist/firestore/internal/fieldValue.d.mts +11 -0
  42. package/dist/firestore/internal/fieldValue.mjs +88 -0
  43. package/dist/firestore/internal/firestore.mjs +145 -0
  44. package/dist/firestore/internal/firestoreError.d.mts +29 -0
  45. package/dist/firestore/internal/firestoreError.mjs +30 -0
  46. package/dist/firestore/internal/firestoreModel.mjs +719 -0
  47. package/dist/firestore/internal/firestoreSchema.mjs +123 -0
  48. package/dist/firestore/internal/firestoreValue.mjs +108 -0
  49. package/dist/firestore/internal/firestoreValueWalk.d.mts +58 -0
  50. package/dist/firestore/internal/firestoreValueWalk.mjs +223 -0
  51. package/dist/firestore/internal/geoPoint.d.mts +4 -0
  52. package/dist/firestore/internal/geoPoint.mjs +39 -0
  53. package/dist/firestore/internal/patch.mjs +19 -0
  54. package/dist/firestore/internal/querySnapshot.mjs +24 -0
  55. package/dist/firestore/internal/schemaAST.mjs +35 -0
  56. package/dist/firestore/internal/snapshotExtra.mjs +35 -0
  57. package/dist/firestore/internal/streamFromListener.mjs +12 -0
  58. package/dist/firestore/internal/timestamp.d.mts +4 -0
  59. package/dist/firestore/internal/timestamp.mjs +66 -0
  60. package/dist/firestore/internal/timestampSchema.mjs +31 -0
  61. package/dist/firestore/internal/transactionFromCallback.mjs +66 -0
  62. package/dist/functions/Callable.d.mts +654 -0
  63. package/dist/functions/Callable.mjs +450 -0
  64. package/dist/functions/CallableError.d.mts +297 -0
  65. package/dist/functions/CallableError.mjs +256 -0
  66. package/dist/functions/CallableMiddleware.d.mts +213 -0
  67. package/dist/functions/CallableMiddleware.mjs +52 -0
  68. package/dist/functions/CallableRequest.d.mts +166 -0
  69. package/dist/functions/CallableRequest.mjs +18 -0
  70. package/dist/functions/Caller.d.mts +103 -0
  71. package/dist/functions/Caller.mjs +115 -0
  72. package/dist/functions/DocumentTrigger.d.mts +795 -0
  73. package/dist/functions/DocumentTrigger.mjs +566 -0
  74. package/dist/functions/FirebaseFunction.d.mts +79 -0
  75. package/dist/functions/FirebaseFunction.mjs +4 -0
  76. package/dist/functions/FunctionGroup.d.mts +175 -0
  77. package/dist/functions/FunctionGroup.mjs +64 -0
  78. package/dist/functions/index.d.mts +9 -0
  79. package/dist/functions/index.mjs +9 -0
  80. package/dist/functions/internal/callable.mjs +167 -0
  81. package/dist/functions/internal/callableMiddleware.d.mts +19 -0
  82. package/dist/functions/internal/callableMiddleware.mjs +15 -0
  83. package/dist/functions/internal/callableRequest.mjs +6 -0
  84. package/dist/functions/internal/documentTrigger.d.mts +10 -0
  85. package/dist/functions/internal/documentTrigger.mjs +73 -0
  86. package/dist/functions/internal/firebaseFunction.d.mts +5 -0
  87. package/dist/functions/internal/firebaseFunction.mjs +24 -0
  88. package/dist/functions/internal/functionGroup.mjs +36 -0
  89. package/package.json +66 -3
  90. package/src/app/App.ts +24 -0
  91. package/src/app/index.ts +7 -0
  92. package/src/firestore/Collection.ts +520 -0
  93. package/src/firestore/CollectionGroup.ts +245 -0
  94. package/src/firestore/DocumentPath.ts +114 -0
  95. package/src/firestore/DocumentSnapshot.ts +308 -0
  96. package/src/firestore/FieldValue.ts +375 -0
  97. package/src/firestore/Firestore.ts +1432 -0
  98. package/src/firestore/FirestoreModel.ts +1884 -0
  99. package/src/firestore/FirestoreSchema.ts +643 -0
  100. package/src/firestore/FirestoreValue.ts +207 -0
  101. package/src/firestore/GeoPoint.ts +105 -0
  102. package/src/firestore/Patch.ts +117 -0
  103. package/src/firestore/QuerySnapshot.ts +150 -0
  104. package/src/firestore/Timestamp.ts +302 -0
  105. package/src/firestore/index.ts +67 -0
  106. package/src/firestore/internal/collection.ts +246 -0
  107. package/src/firestore/internal/collectionGroup.ts +81 -0
  108. package/src/firestore/internal/documentPath.ts +53 -0
  109. package/src/firestore/internal/documentSnapshot.ts +117 -0
  110. package/src/firestore/internal/fieldValue.ts +119 -0
  111. package/src/firestore/internal/firestore.ts +322 -0
  112. package/src/firestore/internal/firestoreError.ts +36 -0
  113. package/src/firestore/internal/firestoreModel.ts +1242 -0
  114. package/src/firestore/internal/firestoreSchema.ts +218 -0
  115. package/src/firestore/internal/firestoreValue.ts +202 -0
  116. package/src/firestore/internal/firestoreValueWalk.ts +349 -0
  117. package/src/firestore/internal/geoPoint.ts +59 -0
  118. package/src/firestore/internal/patch.ts +21 -0
  119. package/src/firestore/internal/querySnapshot.ts +39 -0
  120. package/src/firestore/internal/schemaAST.ts +83 -0
  121. package/src/firestore/internal/snapshotExtra.ts +47 -0
  122. package/src/firestore/internal/streamFromListener.ts +27 -0
  123. package/src/firestore/internal/timestamp.ts +119 -0
  124. package/src/firestore/internal/timestampSchema.ts +42 -0
  125. package/src/firestore/internal/transactionFromCallback.ts +106 -0
  126. package/src/functions/Callable.ts +855 -0
  127. package/src/functions/CallableError.ts +348 -0
  128. package/src/functions/CallableMiddleware.ts +279 -0
  129. package/src/functions/CallableRequest.ts +207 -0
  130. package/src/functions/Caller.ts +141 -0
  131. package/src/functions/DocumentTrigger.ts +927 -0
  132. package/src/functions/FirebaseFunction.ts +96 -0
  133. package/src/functions/FunctionGroup.ts +225 -0
  134. package/src/functions/index.ts +62 -0
  135. package/src/functions/internal/callable.ts +272 -0
  136. package/src/functions/internal/callableMiddleware.ts +54 -0
  137. package/src/functions/internal/callableRequest.ts +8 -0
  138. package/src/functions/internal/documentTrigger.ts +143 -0
  139. package/src/functions/internal/firebaseFunction.ts +58 -0
  140. package/src/functions/internal/functionGroup.ts +47 -0
@@ -0,0 +1,654 @@
1
+ import { CallableError, ErrorCode } from "./CallableError.mjs";
2
+ import { CallableRequest, Input } from "./CallableRequest.mjs";
3
+ import { AnyId, AnyKey, ApplyServices, ErrorSchema as ErrorSchema$1, Provides } from "./CallableMiddleware.mjs";
4
+ import { FirebaseFunction, Handler as Handler$1, HandlerFor as HandlerFor$1, NoGroup as NoGroup$1 } from "./FirebaseFunction.mjs";
5
+ import { Any as Any$1, Member, Names } from "./FunctionGroup.mjs";
6
+ import { Attached, AttachedServices } from "./internal/callableMiddleware.mjs";
7
+ import { Context, Effect, Layer, Pipeable, Schema } from "effect";
8
+ declare namespace Callable_d_exports {
9
+ export { Any, Callable, ChainServices, Deployment, Error, ErrorSchema, Handler, HandlerCall, HandlerFor, HandlerFunction, HandlerServices, MakeOptions, Middleware, MiddlewareProvides, MiddlewareServices, NoGroup, Payload, Success, deployment, errorCode, errorSchemas, getErrorCode, handler, make, serve, toLayer };
10
+ }
11
+ declare const TypeId = "~@visiolab/effect-firebase/functions/Callable";
12
+ /**
13
+ * A Callable: a server function's name, its Payload and what it succeeds with.
14
+ *
15
+ * **Details**
16
+ *
17
+ * A Callable is the kind of {@link FirebaseFunction.FirebaseFunction} the
18
+ * client calls by name, and its `kind` is `"Callable"`.
19
+ *
20
+ * The name is the Callable's identity. A Callable in no group is deployed
21
+ * under its name, so it is a literal type that the server's exports and the
22
+ * client's functions are keyed on.
23
+ *
24
+ * @see {@link DocumentTrigger.DocumentTrigger} for a Function a change to a document runs
25
+ *
26
+ * @stability unstable
27
+ * @category models
28
+ * @since 0.3.0
29
+ */
30
+ export interface Callable<out Name extends string, out Payload extends Schema.Top = Schema.Void, out Success extends Schema.Top = Schema.Void, out Error extends Schema.Top = never, out Middleware = never, out MiddlewareServices = never> extends FirebaseFunction<"Callable", Name>, Pipeable.Pipeable {
31
+ readonly [TypeId]: typeof TypeId;
32
+ /** The Callable's name, which a Callable in no group is deployed under. */
33
+ readonly name: Name;
34
+ /** The schema of what the client sends. */
35
+ readonly payload: Payload;
36
+ /** The schema of what the handler succeeds with. */
37
+ readonly success: Success;
38
+ /** The schemas of the errors the handler can fail with. */
39
+ readonly error: ReadonlySet<Error>;
40
+ /** The Callable's own middleware, in the order it was attached. */
41
+ readonly middlewares: ReadonlySet<AnyKey>;
42
+ /** The middleware attached to the Callable, as a union. Types only. */
43
+ readonly "~Middleware": Middleware;
44
+ /** What the middleware chain still requires. Types only. */
45
+ readonly "~MiddlewareServices": MiddlewareServices;
46
+ /**
47
+ * Attaches a Callable Middleware to the Callable.
48
+ *
49
+ * **Details**
50
+ *
51
+ * Returns a new Callable. The middleware runs around every call, before
52
+ * the Payload is decoded. A middleware attached later wraps the ones
53
+ * attached before it, so it can provide what they require. A Function
54
+ * Group carries no middleware, so a member of a group runs only its own.
55
+ *
56
+ * Its `provides` are removed from what the handler's Layer requires, and
57
+ * its errors join the Callable's error union. Its implementation is
58
+ * required where the chain runs: by `Functions` and by
59
+ * {@link handler}.
60
+ *
61
+ * The Payload is decoded inside the chain, so a middleware that catches
62
+ * every failure also catches a Payload that doesn't decode, and the caller
63
+ * then no longer gets `invalid-argument`.
64
+ *
65
+ * @see {@link CallableMiddleware.Service} for declaring a middleware
66
+ */
67
+ middleware<I extends AnyId, S>(middleware: Context.Key<I, S>): Callable<Name, Payload, Success, Error, Middleware | I, ApplyServices<I, MiddlewareServices>>;
68
+ }
69
+ /**
70
+ * Any {@link Callable}, whatever its name, schemas and middleware.
71
+ *
72
+ * @stability unstable
73
+ * @category models
74
+ * @since 0.3.0
75
+ */
76
+ export interface Any extends FirebaseFunction<"Callable", string> {
77
+ readonly [TypeId]: typeof TypeId;
78
+ readonly payload: Schema.Top;
79
+ readonly success: Schema.Top;
80
+ readonly error: ReadonlySet<Schema.Top>;
81
+ readonly middlewares: ReadonlySet<AnyKey>;
82
+ }
83
+ /**
84
+ * The middleware attached to a {@link Callable}, as a union of the middleware
85
+ * service types.
86
+ *
87
+ * @stability unstable
88
+ * @category type-level
89
+ * @since 0.3.0
90
+ */
91
+ export type Middleware<C> = Attached<C>;
92
+ /**
93
+ * What the middleware chain of a {@link Callable} still requires: the
94
+ * `requires` of each middleware that no middleware outside it provides.
95
+ *
96
+ * @stability unstable
97
+ * @category type-level
98
+ * @since 0.3.0
99
+ */
100
+ export type MiddlewareServices<C> = Exclude<AttachedServices<C>, CallableRequest>;
101
+ /**
102
+ * What the middleware of a {@link Callable} provides to its handler.
103
+ *
104
+ * @stability unstable
105
+ * @category type-level
106
+ * @since 0.3.0
107
+ */
108
+ export type MiddlewareProvides<C> = Provides<Middleware<C>>;
109
+ /**
110
+ * The Payload type of a {@link Callable}: what its handler receives.
111
+ *
112
+ * @stability unstable
113
+ * @category type-level
114
+ * @since 0.3.0
115
+ */
116
+ export type Payload<C extends Any> = C["payload"]["Type"];
117
+ /**
118
+ * The success type of a {@link Callable}: what its handler succeeds with.
119
+ *
120
+ * @stability unstable
121
+ * @category type-level
122
+ * @since 0.3.0
123
+ */
124
+ export type Success<C extends Any> = C["success"]["Type"];
125
+ /**
126
+ * The union of the error schemas of a {@link Callable}.
127
+ *
128
+ * @stability unstable
129
+ * @category type-level
130
+ * @since 0.3.0
131
+ */
132
+ export type ErrorSchema<C extends Any> = (C["error"] extends ReadonlySet<infer S extends Schema.Top> ? S : never) | ErrorSchema$1<Middleware<C>>;
133
+ /**
134
+ * The error type of a {@link Callable}: what its handler can fail with, and
135
+ * what its client decodes back. It includes the errors of its middleware.
136
+ *
137
+ * @stability unstable
138
+ * @category type-level
139
+ * @since 0.3.0
140
+ */
141
+ export type Error<C extends Any> = ErrorSchema<C>["Type"];
142
+ /**
143
+ * Options for {@link make}.
144
+ *
145
+ * @stability unstable
146
+ * @category models
147
+ * @since 0.3.0
148
+ */
149
+ export interface MakeOptions<Payload extends Schema.Top | Schema.Struct.Fields, Success extends Schema.Top, Error extends Schema.Top | ReadonlyArray<Schema.Top> = never> {
150
+ /**
151
+ * What the client sends: a schema, or the fields of a struct. Leave it out
152
+ * for a Callable that takes nothing.
153
+ */
154
+ readonly payload?: Payload | undefined;
155
+ /**
156
+ * What the handler succeeds with. Leave it out for a Callable that answers
157
+ * with nothing.
158
+ */
159
+ readonly success?: Success | undefined;
160
+ /**
161
+ * The errors the handler can fail with: one schema or an array. Leave it
162
+ * out for a Callable that never fails with an error of its own.
163
+ */
164
+ readonly error?: Error | undefined;
165
+ }
166
+ /**
167
+ * Declares a Callable.
168
+ *
169
+ * **When to use**
170
+ *
171
+ * Use to declare a server function once, in code that the server and the
172
+ * client share.
173
+ *
174
+ * **Details**
175
+ *
176
+ * `payload` takes a schema or the fields of a struct, and defaults to
177
+ * `Schema.Void`. `success` defaults to `Schema.Void`. `error` takes one
178
+ * schema or an array; without it the Callable never fails with an error of
179
+ * its own, and its client fails only with `CallableError`.
180
+ *
181
+ * All of them are sent through `Schema.toCodecJson`, so they must round-trip
182
+ * through JSON. `Schema.Unknown` is the safe choice for "any JSON".
183
+ * `Schema.Any` skips every check and is an escape hatch. A schema that can't
184
+ * round-trip fails at runtime, not at compile time.
185
+ *
186
+ * An error is sent with the Firebase error code of its schema, `internal`
187
+ * unless {@link errorCode} or its `callableErrorCode` annotation sets one.
188
+ *
189
+ * @example Declaring a Callable with a Payload and a success value
190
+ * ```ts
191
+ * import { Schema } from "effect";
192
+ * import { Callable } from "@visiolab/effect-firebase/functions";
193
+ *
194
+ * const Greet = Callable.make("greet", {
195
+ * payload: { name: Schema.String, at: Schema.Date },
196
+ * success: Schema.Struct({ message: Schema.String }),
197
+ * });
198
+ * ```
199
+ *
200
+ * @example Declaring the errors a Callable can fail with
201
+ * ```ts
202
+ * import { Schema } from "effect";
203
+ * import { Callable, CallableError } from "@visiolab/effect-firebase/functions";
204
+ *
205
+ * class NameTaken extends Schema.TaggedError<NameTaken>()(
206
+ * "NameTaken",
207
+ * { name: Schema.String },
208
+ * { callableErrorCode: "already-exists" },
209
+ * ) {}
210
+ *
211
+ * const Register = Callable.make("register", {
212
+ * payload: { name: Schema.String },
213
+ * error: [NameTaken, CallableError.PermissionDenied],
214
+ * });
215
+ * ```
216
+ *
217
+ * @see {@link toLayer} for implementing the Callable on the server
218
+ * @see {@link errorCode} for giving an error schema its code
219
+ * @see {@link FunctionGroup.make} for collecting Functions under one prefix
220
+ * @see {@link DocumentTrigger.created} for declaring a Function a change to a document runs
221
+ *
222
+ * @stability unstable
223
+ * @category constructors
224
+ * @since 0.3.0
225
+ */
226
+ export declare const make: <const Name extends string, Payload extends Schema.Top | Schema.Struct.Fields = Schema.Void, Success extends Schema.Top = Schema.Void, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never>(name: Name, options?: MakeOptions<Payload, Success, Error>) => Callable<Name, Payload extends Schema.Top ? Payload : Payload extends Schema.Struct.Fields ? Schema.Struct<Payload> : never, Success, Error extends ReadonlyArray<Schema.Top> ? Error[number] : Error>;
227
+ /**
228
+ * Marks the {@link Handler} of a Callable in no group. The same marker as
229
+ * {@link FirebaseFunction.NoGroup}, which every kind of Function shares.
230
+ *
231
+ * @stability unstable
232
+ * @category models
233
+ * @since 0.3.0
234
+ */
235
+ export type NoGroup = NoGroup$1;
236
+ /**
237
+ * The service a {@link toLayer} Layer provides: the Callable Handler of the
238
+ * Callable `Name`, as served in `Group`.
239
+ *
240
+ * **Details**
241
+ *
242
+ * A handler is keyed by its group and its name, so the handler of `greet` in
243
+ * no group is `Handler<NoGroup, "greet">`. A Layer that serves a Callable must
244
+ * provide the handler under exactly that key. It is the
245
+ * {@link FirebaseFunction.Handler} every kind of Function is served by.
246
+ *
247
+ * @stability unstable
248
+ * @category models
249
+ * @since 0.3.0
250
+ */
251
+ export type Handler<Group, Name extends string> = Handler$1<Group, Name>;
252
+ /**
253
+ * The {@link Handler} of a Callable in no group.
254
+ *
255
+ * @stability unstable
256
+ * @category type-level
257
+ * @since 0.3.0
258
+ */
259
+ export type HandlerFor<C extends Any> = HandlerFor$1<C>;
260
+ /**
261
+ * What implements a Callable: a function from the decoded Payload to an
262
+ * Effect of the success value, failing only with the Callable's declared
263
+ * errors.
264
+ *
265
+ * @stability unstable
266
+ * @category models
267
+ * @since 0.3.0
268
+ */
269
+ export type HandlerFunction<C extends Any, R> = (payload: Payload<C>) => Effect.Effect<Success<C>, Error<C>, R>;
270
+ /**
271
+ * What a handler that requires `R` leaves for its {@link toLayer} Layer to
272
+ * require: `R` without what the Callable's middleware provides and without
273
+ * the {@link CallableRequest.CallableRequest}, which every call provides.
274
+ *
275
+ * @stability unstable
276
+ * @category type-level
277
+ * @since 0.3.0
278
+ */
279
+ export type HandlerServices<C, R> = Exclude<R, MiddlewareProvides<C> | CallableRequest>;
280
+ /**
281
+ * What {@link handler} yields: the Callable's handler behind its middleware
282
+ * chain, run in process.
283
+ *
284
+ * @stability unstable
285
+ * @category models
286
+ * @since 0.3.0
287
+ */
288
+ export type HandlerCall<C extends Any> = (payload: Payload<C>, request: Input) => Effect.Effect<Success<C>, Error<C>>;
289
+ /**
290
+ * What running the middleware chain of a {@link Callable} requires: its
291
+ * handler, each middleware implementation, and what the chain still
292
+ * requires.
293
+ *
294
+ * @stability unstable
295
+ * @category type-level
296
+ * @since 0.3.0
297
+ */
298
+ export type ChainServices<C extends Any, H> = H | Middleware<C> | MiddlewareServices<C>;
299
+ /**
300
+ * Implements a Callable as a Layer.
301
+ *
302
+ * **When to use**
303
+ *
304
+ * Use to write the server side of a Callable. The Layer is what
305
+ * `Functions.make` or `Functions.group` from
306
+ * `@visiolab/effect-firebase-functions` serves.
307
+ *
308
+ * **Details**
309
+ *
310
+ * Pass the Callable for a Callable in no group. Pass its group and its name
311
+ * for a Callable member of a {@link FunctionGroup.FunctionGroup}: the Layer then
312
+ * provides `Handler<"users", "create">`, which serves the member in that group
313
+ * only. A Layer from the Callable on its own doesn't serve it in a group, and
314
+ * a Callable in two groups needs a Layer for each.
315
+ *
316
+ * Takes the handler itself, or an Effect that builds it. The Effect runs once,
317
+ * when the Layer is built, so do per-instance setup there.
318
+ *
319
+ * The Layer requires what the handler needs on each call and what building it
320
+ * needs. Both are provided where the Layer is built: services built with the
321
+ * Layer are shared by every call. What the Callable's middleware provides,
322
+ * such as the `Caller`, and the {@link CallableRequest.CallableRequest} are
323
+ * provided per call instead, so the Layer doesn't require them. Nor does it
324
+ * require the middleware's implementations: those are required where the
325
+ * chain runs.
326
+ *
327
+ * @example Implementing a Callable
328
+ * ```ts
329
+ * import { Effect, Schema } from "effect";
330
+ * import { Callable } from "@visiolab/effect-firebase/functions";
331
+ *
332
+ * const Greet = Callable.make("greet", {
333
+ * payload: { name: Schema.String },
334
+ * success: Schema.String,
335
+ * });
336
+ *
337
+ * const GreetLive = Callable.toLayer(Greet, ({ name }) => Effect.succeed(`Hello, ${name}!`));
338
+ * ```
339
+ *
340
+ * @example Building the handler once per instance
341
+ * ```ts
342
+ * import { Effect, Schema } from "effect";
343
+ * import { Callable } from "@visiolab/effect-firebase/functions";
344
+ *
345
+ * const Greet = Callable.make("greet", {
346
+ * payload: { name: Schema.String },
347
+ * success: Schema.String,
348
+ * });
349
+ *
350
+ * const GreetLive = Callable.toLayer(
351
+ * Greet,
352
+ * Effect.gen(function* () {
353
+ * const greeting = yield* Effect.succeed("Hello");
354
+ * return ({ name }) => Effect.succeed(`${greeting}, ${name}!`);
355
+ * }),
356
+ * );
357
+ * ```
358
+ *
359
+ * @example Implementing a member of a group
360
+ * ```ts
361
+ * import { Effect, Schema } from "effect";
362
+ * import { Callable, FunctionGroup } from "@visiolab/effect-firebase/functions";
363
+ *
364
+ * const CreateUser = Callable.make("create", {
365
+ * payload: { name: Schema.String },
366
+ * success: Schema.String,
367
+ * });
368
+ *
369
+ * class Users extends FunctionGroup.make("users").add(CreateUser) {}
370
+ *
371
+ * const CreateUserLive = Callable.toLayer(Users, "create", ({ name }) => Effect.succeed(name));
372
+ * ```
373
+ *
374
+ * @see {@link make} for declaring the Callable
375
+ * @see {@link serve} for running a call against the handler
376
+ * @see {@link DocumentTrigger.toLayer} for implementing a Document Trigger
377
+ * @see {@link FunctionGroup.make} for collecting Functions under one prefix
378
+ *
379
+ * @stability unstable
380
+ * @category constructors
381
+ * @since 0.3.0
382
+ */
383
+ export declare const toLayer: {
384
+ <C extends Any, R = never, EB = never, RB = never>(callable: C, handler: HandlerFunction<C, R> | Effect.Effect<HandlerFunction<C, R>, EB, RB>): Layer.Layer<HandlerFor<C>, EB, HandlerServices<C, R> | RB>;
385
+ <G extends Any$1, const Name extends Names<G, Any>, R = never, EB = never, RB = never>(group: G, name: Name, handler: HandlerFunction<Member<G, Name, Any>, R> | Effect.Effect<HandlerFunction<Member<G, Name, Any>, R>, EB, RB>): Layer.Layer<Handler<G["identifier"], Name>, EB, HandlerServices<Member<G, Name, Any>, R> | RB>;
386
+ };
387
+ /**
388
+ * Runs one call to a Callable, as it arrives on the wire. A building block for
389
+ * the functions package. Most apps don't need it.
390
+ *
391
+ * **When to use**
392
+ *
393
+ * Use to serve Callables from a transport of your own. `Functions`
394
+ * from `@visiolab/effect-firebase-functions` serves them through
395
+ * `firebase-functions`.
396
+ *
397
+ * **Details**
398
+ *
399
+ * Pass the Callable for a Callable in no group, or its group and its name for
400
+ * a Callable member of a {@link FunctionGroup.FunctionGroup}.
401
+ *
402
+ * Returns a function of the call's {@link CallableRequest.CallableRequest}. It
403
+ * runs the middleware chain, the same one {@link handler} runs. Inside it, it
404
+ * decodes the raw `data` with the Payload's `Schema.toCodecJson` and runs the
405
+ * handler. It then encodes the success value with the success schema's
406
+ * `Schema.toCodecJson`, so its result is plain JSON. The request is provided
407
+ * to the chain. Give it a `rawRequest` built from your transport's HTTP
408
+ * request, with `HttpServerRequest.fromWeb` from `effect/http/HttpServerRequest`.
409
+ *
410
+ * Requires the handler, every middleware implementation, and what the chain
411
+ * still requires. They are read once, so a call needs nothing else.
412
+ *
413
+ * Every failure is a `CallableError` whose `ResponseError` reason is what to
414
+ * answer with:
415
+ *
416
+ * - A declared error, or an error of a middleware, is sent with its schema's
417
+ * code, the error's `message` if it is a non-empty string, else its `_tag`,
418
+ * and the error encoded with its schema's `Schema.toCodecJson` as
419
+ * `details`.
420
+ * - A raw Payload that doesn't decode is sent as `invalid-argument` with a
421
+ * generic message and no details. The `Schema.SchemaError` is logged at
422
+ * Debug.
423
+ *
424
+ * A defect, or a success or error value that doesn't encode, is a defect.
425
+ * Answer it with a bare `internal`, so nothing of it reaches the caller.
426
+ *
427
+ * The `CallableError`'s `callable` is the deployed name: the Callable's name,
428
+ * or `<group>-<name>` for a member of a group.
429
+ *
430
+ * @see {@link toLayer} for providing the handler
431
+ * @see {@link handler} for running the handler in process, with typed values
432
+ * @see {@link Functions.make} for serving through `firebase-functions`
433
+ * @see {@link deployment} for the name and span attributes a transport uses
434
+ * @see {@link DocumentTrigger.serve} for running an event of a Document Trigger
435
+ *
436
+ * @stability unstable
437
+ * @category serving
438
+ * @since 0.3.0
439
+ */
440
+ export declare const serve: {
441
+ <C extends Any>(callable: C): Effect.Effect<(request: CallableRequest) => Effect.Effect<unknown, CallableError>, never, ChainServices<C, HandlerFor<C>>>;
442
+ <G extends Any$1, const Name extends Names<G, Any>>(group: G, name: Name): Effect.Effect<(request: CallableRequest) => Effect.Effect<unknown, CallableError>, never, ChainServices<Member<G, Name, Any>, Handler<G["identifier"], Name>>>;
443
+ };
444
+ /**
445
+ * Runs a Callable's handler in process, behind its middleware chain.
446
+ *
447
+ * **When to use**
448
+ *
449
+ * Use to test a handler and its middleware without the emulator and without
450
+ * `firebase-functions`. Provide the same Layers you serve it with, or stub a
451
+ * middleware with a Layer of your own.
452
+ *
453
+ * **Details**
454
+ *
455
+ * Pass the Callable for a Callable in no group, or its group and its name for
456
+ * a Callable member of a {@link FunctionGroup.FunctionGroup}.
457
+ *
458
+ * Requires the handler, every middleware implementation, and what the chain
459
+ * still requires. A middleware whose
460
+ * `requires` no middleware outside it provides leaves that requirement here,
461
+ * so a chain in the wrong order is a type error where the Layers are
462
+ * provided.
463
+ *
464
+ * Yields a function of the Payload and a {@link CallableRequest.Input}: `{}`
465
+ * for a signed-out call, `{ auth: { uid, token } }` for a signed-in one. It
466
+ * encodes the Payload with `Schema.toCodecJson` as the request's raw `data`,
467
+ * so middleware sees what it would see on the wire. The request's
468
+ * `rawRequest` is the input's, or else a JSON `POST` of the encoded Payload to
469
+ * `http://localhost/<deployed name>` (see
470
+ * {@link CallableRequest.Input.rawRequest}). It runs the chain that
471
+ * `Functions` runs, and fails with the Callable's declared errors and
472
+ * those of its middleware. The success value is the handler's, not encoded.
473
+ *
474
+ * @example Running a handler behind Authenticated
475
+ * ```ts
476
+ * import { Effect, Layer, Schema } from "effect";
477
+ * import { Callable, Caller } from "@visiolab/effect-firebase/functions";
478
+ *
479
+ * const WhoAmI = Callable.make("whoAmI", { success: Schema.String }).middleware(
480
+ * Caller.Authenticated,
481
+ * );
482
+ *
483
+ * const WhoAmILive = Callable.toLayer(WhoAmI, () =>
484
+ * Effect.map(Effect.service(Caller.Caller), ({ uid }) => uid),
485
+ * );
486
+ *
487
+ * const program = Effect.gen(function* () {
488
+ * const whoAmI = yield* Callable.handler(WhoAmI);
489
+ * // "ada"
490
+ * return yield* whoAmI(undefined, { auth: { uid: "ada", token: {} } });
491
+ * }).pipe(Effect.provide(Layer.merge(WhoAmILive, Caller.Authenticated.layer)));
492
+ * ```
493
+ *
494
+ * @see {@link serve} for running a call as it arrives on the wire
495
+ * @see {@link toLayer} for providing the handler
496
+ * @see {@link Functions.make} for serving the same chain through `firebase-functions`
497
+ *
498
+ * @stability unstable
499
+ * @category serving
500
+ * @since 0.3.0
501
+ */
502
+ export declare const handler: {
503
+ <C extends Any>(callable: C): Effect.Effect<HandlerCall<C>, never, ChainServices<C, HandlerFor<C>>>;
504
+ <G extends Any$1, const Name extends Names<G, Any>>(group: G, name: Name): Effect.Effect<HandlerCall<Member<G, Name, Any>>, never, ChainServices<Member<G, Name, Any>, Handler<G["identifier"], Name>>>;
505
+ };
506
+ /**
507
+ * Sets the Firebase error code a Callable answers with when it fails with
508
+ * errors of this schema.
509
+ *
510
+ * **When to use**
511
+ *
512
+ * Use to give a code to an error schema you don't own. For an error class of
513
+ * your own, set `callableErrorCode` in its annotations instead, so every
514
+ * Callable that lists it uses the same code.
515
+ *
516
+ * **Details**
517
+ *
518
+ * An error schema without a code is sent as `internal`. The client reads the
519
+ * code to find the declared errors to decode the answer against, so the code
520
+ * is part of the contract.
521
+ *
522
+ * @example Giving codes to error schemas
523
+ * ```ts
524
+ * import { Schema } from "effect";
525
+ * import { Callable } from "@visiolab/effect-firebase/functions";
526
+ *
527
+ * class NameTaken extends Schema.TaggedError<NameTaken>()(
528
+ * "NameTaken",
529
+ * { name: Schema.String },
530
+ * { callableErrorCode: "already-exists" },
531
+ * ) {}
532
+ *
533
+ * class Banned extends Schema.TaggedError<Banned>()("Banned", {}) {}
534
+ *
535
+ * const Register = Callable.make("register", {
536
+ * payload: { name: Schema.String },
537
+ * error: [NameTaken, Banned.pipe(Callable.errorCode("permission-denied"))],
538
+ * });
539
+ * ```
540
+ *
541
+ * @see {@link getErrorCode} for reading the code back
542
+ * @see {@link make} for declaring the errors a Callable fails with
543
+ *
544
+ * @stability unstable
545
+ * @category errors
546
+ * @since 0.3.0
547
+ */
548
+ export declare const errorCode: (code: ErrorCode) => <S extends Schema.Top>(self: S) => S["Rebuild"];
549
+ /**
550
+ * Reads the Firebase error code of an error schema: what {@link errorCode} or
551
+ * its `callableErrorCode` annotation set, else `internal`. A building block
552
+ * for the functions and client packages. Most apps don't need it.
553
+ *
554
+ * **When to use**
555
+ *
556
+ * Use when serving or calling Callables from a transport of your own.
557
+ *
558
+ * @see {@link errorCode} for setting the code
559
+ * @see {@link errorSchemas} for the schemas a call can be answered with
560
+ *
561
+ * @stability unstable
562
+ * @category errors
563
+ * @since 0.3.0
564
+ */
565
+ export declare const getErrorCode: (schema: Schema.Top) => ErrorCode;
566
+ /**
567
+ * The schemas of every error a call can be answered with: the Callable's
568
+ * declared errors, then those of its middleware. A building block for the
569
+ * client package. Most apps don't need it.
570
+ *
571
+ * **When to use**
572
+ *
573
+ * Use when calling Callables from a transport of your own, to decode an
574
+ * error's `details` against the schemas that carry its code.
575
+ *
576
+ * **Details**
577
+ *
578
+ * Pass the Callable for a Callable in no group, or its group and its name for
579
+ * a Callable member of a {@link FunctionGroup.FunctionGroup}.
580
+ *
581
+ * @see {@link getErrorCode} for the code of each schema
582
+ * @see {@link deployment} for the name a transport calls
583
+ *
584
+ * @stability unstable
585
+ * @category errors
586
+ * @since 0.3.0
587
+ */
588
+ export declare const errorSchemas: {
589
+ (callable: Any): ReadonlyArray<Schema.Top>;
590
+ <G extends Any$1>(group: G, name: Names<G, Any>): ReadonlyArray<Schema.Top>;
591
+ };
592
+ /**
593
+ * Where a Callable is served: the name it is deployed under and the
594
+ * attributes of each call's spans.
595
+ *
596
+ * @stability unstable
597
+ * @category models
598
+ * @since 0.3.0
599
+ */
600
+ export interface Deployment {
601
+ /**
602
+ * The name the Callable Function is exported under and the client calls:
603
+ * the Callable's name, or `<group>-<name>` for a member of a group.
604
+ */
605
+ readonly name: string;
606
+ /**
607
+ * The attributes of the server's and the client's span of a call:
608
+ * `rpc.system: "firebase_callable"`, `rpc.method` (the Callable's name),
609
+ * `rpc.service` (the group, for a member) and `faas.name` (the deployed
610
+ * name).
611
+ */
612
+ readonly attributes: Readonly<Record<string, string>>;
613
+ }
614
+ /**
615
+ * Returns the {@link Deployment} of a Callable: its deployed name and its span
616
+ * attributes. A building block of the functions and client packages, which
617
+ * agree on both through it. Most apps don't need it.
618
+ *
619
+ * **When to use**
620
+ *
621
+ * Use when serving or calling Callables from a transport of your own.
622
+ * `Functions` and `CallableClient` already use it.
623
+ *
624
+ * **Details**
625
+ *
626
+ * Pass the Callable for a Callable in no group, or its group and its name for
627
+ * a Callable member of a {@link FunctionGroup.FunctionGroup}.
628
+ *
629
+ * @example Reading the deployed name of a member
630
+ * ```ts
631
+ * import { Schema } from "effect";
632
+ * import { Callable, FunctionGroup } from "@visiolab/effect-firebase/functions";
633
+ *
634
+ * const CreateUser = Callable.make("create", { payload: { name: Schema.String } });
635
+ *
636
+ * class Users extends FunctionGroup.make("users").add(CreateUser) {}
637
+ *
638
+ * // "users-create"
639
+ * const { name } = Callable.deployment(Users, "create");
640
+ * ```
641
+ *
642
+ * @see {@link serve} for running a call on the server
643
+ * @see {@link errorSchemas} for the errors a call can be answered with
644
+ * @see {@link DocumentTrigger.deployment} for where a Document Trigger is deployed
645
+ *
646
+ * @stability unstable
647
+ * @category serving
648
+ * @since 0.3.0
649
+ */
650
+ export declare const deployment: {
651
+ (callable: Any): Deployment;
652
+ <G extends Any$1>(group: G, name: Names<G, Any>): Deployment;
653
+ };
654
+ export { Callable_d_exports };