@visiolab/effect-firebase 0.0.0-stage → 0.3.1

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 +72 -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,450 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { deployedName, errorSchemas as errorSchemas$1, getErrorCode as getErrorCode$1, handler as handler$1, kind, make as make$1, serve as serve$1, spanAttributes, toLayer as toLayer$1 } from "./internal/callable.mjs";
3
+ import { isFunctionGroup } from "./internal/functionGroup.mjs";
4
+ import { Schema } from "effect";
5
+ // src/functions/Callable.ts
6
+ /**
7
+ * Callables: server functions the client calls by name, declared once and
8
+ * shared by the server and the client.
9
+ *
10
+ * A {@link Callable} is a contract: its name, its Payload and what it succeeds
11
+ * with. The server implements it with {@link toLayer} and serves it with
12
+ * `Functions.make` from `@visiolab/effect-firebase-functions`. The client
13
+ * calls it with `CallableClient` from `@visiolab/effect-firebase-client`. This
14
+ * module imports neither SDK, so the contract can live in code shared with the
15
+ * browser.
16
+ *
17
+ * Values cross the wire as `Schema.toCodecJson` output, on both sides, so a
18
+ * `Date` or a `bigint` arrives as itself.
19
+ *
20
+ * @example Declaring a Callable and implementing it
21
+ * ```ts
22
+ * import { Effect, Schema } from "effect";
23
+ * import { Callable } from "@visiolab/effect-firebase/functions";
24
+ *
25
+ * const Greet = Callable.make("greet", {
26
+ * payload: { name: Schema.String },
27
+ * success: Schema.String,
28
+ * });
29
+ *
30
+ * const GreetLive = Callable.toLayer(Greet, ({ name }) => Effect.succeed(`Hello, ${name}!`));
31
+ * ```
32
+ *
33
+ * @stability unstable
34
+ * @since 0.3.0
35
+ */
36
+ var Callable_exports = /* @__PURE__ */ __exportAll({
37
+ deployment: () => deployment,
38
+ errorCode: () => errorCode,
39
+ errorSchemas: () => errorSchemas,
40
+ getErrorCode: () => getErrorCode,
41
+ handler: () => handler,
42
+ make: () => make,
43
+ serve: () => serve,
44
+ toLayer: () => toLayer
45
+ });
46
+ /**
47
+ * The group and the Callable that the arguments of an overload taking
48
+ * `(callable, ...)` or `(group, name, ...)` name.
49
+ */
50
+ const target = (args) => isFunctionGroup(args[0]) ? [args[0], args[0].functions[args[1]]] : [void 0, args[0]];
51
+ /**
52
+ * Declares a Callable.
53
+ *
54
+ * **When to use**
55
+ *
56
+ * Use to declare a server function once, in code that the server and the
57
+ * client share.
58
+ *
59
+ * **Details**
60
+ *
61
+ * `payload` takes a schema or the fields of a struct, and defaults to
62
+ * `Schema.Void`. `success` defaults to `Schema.Void`. `error` takes one
63
+ * schema or an array; without it the Callable never fails with an error of
64
+ * its own, and its client fails only with `CallableError`.
65
+ *
66
+ * All of them are sent through `Schema.toCodecJson`, so they must round-trip
67
+ * through JSON. `Schema.Unknown` is the safe choice for "any JSON".
68
+ * `Schema.Any` skips every check and is an escape hatch. A schema that can't
69
+ * round-trip fails at runtime, not at compile time.
70
+ *
71
+ * An error is sent with the Firebase error code of its schema, `internal`
72
+ * unless {@link errorCode} or its `callableErrorCode` annotation sets one.
73
+ *
74
+ * @example Declaring a Callable with a Payload and a success value
75
+ * ```ts
76
+ * import { Schema } from "effect";
77
+ * import { Callable } from "@visiolab/effect-firebase/functions";
78
+ *
79
+ * const Greet = Callable.make("greet", {
80
+ * payload: { name: Schema.String, at: Schema.Date },
81
+ * success: Schema.Struct({ message: Schema.String }),
82
+ * });
83
+ * ```
84
+ *
85
+ * @example Declaring the errors a Callable can fail with
86
+ * ```ts
87
+ * import { Schema } from "effect";
88
+ * import { Callable, CallableError } from "@visiolab/effect-firebase/functions";
89
+ *
90
+ * class NameTaken extends Schema.TaggedError<NameTaken>()(
91
+ * "NameTaken",
92
+ * { name: Schema.String },
93
+ * { callableErrorCode: "already-exists" },
94
+ * ) {}
95
+ *
96
+ * const Register = Callable.make("register", {
97
+ * payload: { name: Schema.String },
98
+ * error: [NameTaken, CallableError.PermissionDenied],
99
+ * });
100
+ * ```
101
+ *
102
+ * @see {@link toLayer} for implementing the Callable on the server
103
+ * @see {@link errorCode} for giving an error schema its code
104
+ * @see {@link FunctionGroup.make} for collecting Functions under one prefix
105
+ * @see {@link DocumentTrigger.created} for declaring a Function a change to a document runs
106
+ *
107
+ * @stability unstable
108
+ * @category constructors
109
+ * @since 0.3.0
110
+ */
111
+ const make = (name, options) => {
112
+ const payload = options?.payload;
113
+ const error = options?.error;
114
+ return make$1({
115
+ kind,
116
+ error: new Set(error === void 0 ? [] : Schema.isSchema(error) ? [error] : error),
117
+ middlewares: /* @__PURE__ */ new Set(),
118
+ name,
119
+ payload: payload === void 0 ? Schema.Void : Schema.isSchema(payload) ? payload : Schema.Struct(payload),
120
+ success: options?.success ?? Schema.Void
121
+ });
122
+ };
123
+ /**
124
+ * Implements a Callable as a Layer.
125
+ *
126
+ * **When to use**
127
+ *
128
+ * Use to write the server side of a Callable. The Layer is what
129
+ * `Functions.make` or `Functions.group` from
130
+ * `@visiolab/effect-firebase-functions` serves.
131
+ *
132
+ * **Details**
133
+ *
134
+ * Pass the Callable for a Callable in no group. Pass its group and its name
135
+ * for a Callable member of a {@link FunctionGroup.FunctionGroup}: the Layer then
136
+ * provides `Handler<"users", "create">`, which serves the member in that group
137
+ * only. A Layer from the Callable on its own doesn't serve it in a group, and
138
+ * a Callable in two groups needs a Layer for each.
139
+ *
140
+ * Takes the handler itself, or an Effect that builds it. The Effect runs once,
141
+ * when the Layer is built, so do per-instance setup there.
142
+ *
143
+ * The Layer requires what the handler needs on each call and what building it
144
+ * needs. Both are provided where the Layer is built: services built with the
145
+ * Layer are shared by every call. What the Callable's middleware provides,
146
+ * such as the `Caller`, and the {@link CallableRequest.CallableRequest} are
147
+ * provided per call instead, so the Layer doesn't require them. Nor does it
148
+ * require the middleware's implementations: those are required where the
149
+ * chain runs.
150
+ *
151
+ * @example Implementing a Callable
152
+ * ```ts
153
+ * import { Effect, Schema } from "effect";
154
+ * import { Callable } from "@visiolab/effect-firebase/functions";
155
+ *
156
+ * const Greet = Callable.make("greet", {
157
+ * payload: { name: Schema.String },
158
+ * success: Schema.String,
159
+ * });
160
+ *
161
+ * const GreetLive = Callable.toLayer(Greet, ({ name }) => Effect.succeed(`Hello, ${name}!`));
162
+ * ```
163
+ *
164
+ * @example Building the handler once per instance
165
+ * ```ts
166
+ * import { Effect, Schema } from "effect";
167
+ * import { Callable } from "@visiolab/effect-firebase/functions";
168
+ *
169
+ * const Greet = Callable.make("greet", {
170
+ * payload: { name: Schema.String },
171
+ * success: Schema.String,
172
+ * });
173
+ *
174
+ * const GreetLive = Callable.toLayer(
175
+ * Greet,
176
+ * Effect.gen(function* () {
177
+ * const greeting = yield* Effect.succeed("Hello");
178
+ * return ({ name }) => Effect.succeed(`${greeting}, ${name}!`);
179
+ * }),
180
+ * );
181
+ * ```
182
+ *
183
+ * @example Implementing a member of a group
184
+ * ```ts
185
+ * import { Effect, Schema } from "effect";
186
+ * import { Callable, FunctionGroup } from "@visiolab/effect-firebase/functions";
187
+ *
188
+ * const CreateUser = Callable.make("create", {
189
+ * payload: { name: Schema.String },
190
+ * success: Schema.String,
191
+ * });
192
+ *
193
+ * class Users extends FunctionGroup.make("users").add(CreateUser) {}
194
+ *
195
+ * const CreateUserLive = Callable.toLayer(Users, "create", ({ name }) => Effect.succeed(name));
196
+ * ```
197
+ *
198
+ * @see {@link make} for declaring the Callable
199
+ * @see {@link serve} for running a call against the handler
200
+ * @see {@link DocumentTrigger.toLayer} for implementing a Document Trigger
201
+ * @see {@link FunctionGroup.make} for collecting Functions under one prefix
202
+ *
203
+ * @stability unstable
204
+ * @category constructors
205
+ * @since 0.3.0
206
+ */
207
+ const toLayer = ((...args) => {
208
+ const [group, callable] = target(args);
209
+ return toLayer$1(group?.identifier, callable.name, args[group === void 0 ? 1 : 2]);
210
+ });
211
+ /**
212
+ * Runs one call to a Callable, as it arrives on the wire. A building block for
213
+ * the functions package. Most apps don't need it.
214
+ *
215
+ * **When to use**
216
+ *
217
+ * Use to serve Callables from a transport of your own. `Functions`
218
+ * from `@visiolab/effect-firebase-functions` serves them through
219
+ * `firebase-functions`.
220
+ *
221
+ * **Details**
222
+ *
223
+ * Pass the Callable for a Callable in no group, or its group and its name for
224
+ * a Callable member of a {@link FunctionGroup.FunctionGroup}.
225
+ *
226
+ * Returns a function of the call's {@link CallableRequest.CallableRequest}. It
227
+ * runs the middleware chain, the same one {@link handler} runs. Inside it, it
228
+ * decodes the raw `data` with the Payload's `Schema.toCodecJson` and runs the
229
+ * handler. It then encodes the success value with the success schema's
230
+ * `Schema.toCodecJson`, so its result is plain JSON. The request is provided
231
+ * to the chain. Give it a `rawRequest` built from your transport's HTTP
232
+ * request, with `HttpServerRequest.fromWeb` from `effect/http/HttpServerRequest`.
233
+ *
234
+ * Requires the handler, every middleware implementation, and what the chain
235
+ * still requires. They are read once, so a call needs nothing else.
236
+ *
237
+ * Every failure is a `CallableError` whose `ResponseError` reason is what to
238
+ * answer with:
239
+ *
240
+ * - A declared error, or an error of a middleware, is sent with its schema's
241
+ * code, the error's `message` if it is a non-empty string, else its `_tag`,
242
+ * and the error encoded with its schema's `Schema.toCodecJson` as
243
+ * `details`.
244
+ * - A raw Payload that doesn't decode is sent as `invalid-argument` with a
245
+ * generic message and no details. The `Schema.SchemaError` is logged at
246
+ * Debug.
247
+ *
248
+ * A defect, or a success or error value that doesn't encode, is a defect.
249
+ * Answer it with a bare `internal`, so nothing of it reaches the caller.
250
+ *
251
+ * The `CallableError`'s `callable` is the deployed name: the Callable's name,
252
+ * or `<group>-<name>` for a member of a group.
253
+ *
254
+ * @see {@link toLayer} for providing the handler
255
+ * @see {@link handler} for running the handler in process, with typed values
256
+ * @see {@link Functions.make} for serving through `firebase-functions`
257
+ * @see {@link deployment} for the name and span attributes a transport uses
258
+ * @see {@link DocumentTrigger.serve} for running an event of a Document Trigger
259
+ *
260
+ * @stability unstable
261
+ * @category serving
262
+ * @since 0.3.0
263
+ */
264
+ const serve = ((...args) => serve$1(...target(args)));
265
+ /**
266
+ * Runs a Callable's handler in process, behind its middleware chain.
267
+ *
268
+ * **When to use**
269
+ *
270
+ * Use to test a handler and its middleware without the emulator and without
271
+ * `firebase-functions`. Provide the same Layers you serve it with, or stub a
272
+ * middleware with a Layer of your own.
273
+ *
274
+ * **Details**
275
+ *
276
+ * Pass the Callable for a Callable in no group, or its group and its name for
277
+ * a Callable member of a {@link FunctionGroup.FunctionGroup}.
278
+ *
279
+ * Requires the handler, every middleware implementation, and what the chain
280
+ * still requires. A middleware whose
281
+ * `requires` no middleware outside it provides leaves that requirement here,
282
+ * so a chain in the wrong order is a type error where the Layers are
283
+ * provided.
284
+ *
285
+ * Yields a function of the Payload and a {@link CallableRequest.Input}: `{}`
286
+ * for a signed-out call, `{ auth: { uid, token } }` for a signed-in one. It
287
+ * encodes the Payload with `Schema.toCodecJson` as the request's raw `data`,
288
+ * so middleware sees what it would see on the wire. The request's
289
+ * `rawRequest` is the input's, or else a JSON `POST` of the encoded Payload to
290
+ * `http://localhost/<deployed name>` (see
291
+ * {@link CallableRequest.Input.rawRequest}). It runs the chain that
292
+ * `Functions` runs, and fails with the Callable's declared errors and
293
+ * those of its middleware. The success value is the handler's, not encoded.
294
+ *
295
+ * @example Running a handler behind Authenticated
296
+ * ```ts
297
+ * import { Effect, Layer, Schema } from "effect";
298
+ * import { Callable, Caller } from "@visiolab/effect-firebase/functions";
299
+ *
300
+ * const WhoAmI = Callable.make("whoAmI", { success: Schema.String }).middleware(
301
+ * Caller.Authenticated,
302
+ * );
303
+ *
304
+ * const WhoAmILive = Callable.toLayer(WhoAmI, () =>
305
+ * Effect.map(Effect.service(Caller.Caller), ({ uid }) => uid),
306
+ * );
307
+ *
308
+ * const program = Effect.gen(function* () {
309
+ * const whoAmI = yield* Callable.handler(WhoAmI);
310
+ * // "ada"
311
+ * return yield* whoAmI(undefined, { auth: { uid: "ada", token: {} } });
312
+ * }).pipe(Effect.provide(Layer.merge(WhoAmILive, Caller.Authenticated.layer)));
313
+ * ```
314
+ *
315
+ * @see {@link serve} for running a call as it arrives on the wire
316
+ * @see {@link toLayer} for providing the handler
317
+ * @see {@link Functions.make} for serving the same chain through `firebase-functions`
318
+ *
319
+ * @stability unstable
320
+ * @category serving
321
+ * @since 0.3.0
322
+ */
323
+ const handler = ((...args) => handler$1(...target(args)));
324
+ /**
325
+ * Sets the Firebase error code a Callable answers with when it fails with
326
+ * errors of this schema.
327
+ *
328
+ * **When to use**
329
+ *
330
+ * Use to give a code to an error schema you don't own. For an error class of
331
+ * your own, set `callableErrorCode` in its annotations instead, so every
332
+ * Callable that lists it uses the same code.
333
+ *
334
+ * **Details**
335
+ *
336
+ * An error schema without a code is sent as `internal`. The client reads the
337
+ * code to find the declared errors to decode the answer against, so the code
338
+ * is part of the contract.
339
+ *
340
+ * @example Giving codes to error schemas
341
+ * ```ts
342
+ * import { Schema } from "effect";
343
+ * import { Callable } from "@visiolab/effect-firebase/functions";
344
+ *
345
+ * class NameTaken extends Schema.TaggedError<NameTaken>()(
346
+ * "NameTaken",
347
+ * { name: Schema.String },
348
+ * { callableErrorCode: "already-exists" },
349
+ * ) {}
350
+ *
351
+ * class Banned extends Schema.TaggedError<Banned>()("Banned", {}) {}
352
+ *
353
+ * const Register = Callable.make("register", {
354
+ * payload: { name: Schema.String },
355
+ * error: [NameTaken, Banned.pipe(Callable.errorCode("permission-denied"))],
356
+ * });
357
+ * ```
358
+ *
359
+ * @see {@link getErrorCode} for reading the code back
360
+ * @see {@link make} for declaring the errors a Callable fails with
361
+ *
362
+ * @stability unstable
363
+ * @category errors
364
+ * @since 0.3.0
365
+ */
366
+ const errorCode = (code) => (self) => self.annotate({ callableErrorCode: code });
367
+ /**
368
+ * Reads the Firebase error code of an error schema: what {@link errorCode} or
369
+ * its `callableErrorCode` annotation set, else `internal`. A building block
370
+ * for the functions and client packages. Most apps don't need it.
371
+ *
372
+ * **When to use**
373
+ *
374
+ * Use when serving or calling Callables from a transport of your own.
375
+ *
376
+ * @see {@link errorCode} for setting the code
377
+ * @see {@link errorSchemas} for the schemas a call can be answered with
378
+ *
379
+ * @stability unstable
380
+ * @category errors
381
+ * @since 0.3.0
382
+ */
383
+ const getErrorCode = getErrorCode$1;
384
+ /**
385
+ * The schemas of every error a call can be answered with: the Callable's
386
+ * declared errors, then those of its middleware. A building block for the
387
+ * client package. Most apps don't need it.
388
+ *
389
+ * **When to use**
390
+ *
391
+ * Use when calling Callables from a transport of your own, to decode an
392
+ * error's `details` against the schemas that carry its code.
393
+ *
394
+ * **Details**
395
+ *
396
+ * Pass the Callable for a Callable in no group, or its group and its name for
397
+ * a Callable member of a {@link FunctionGroup.FunctionGroup}.
398
+ *
399
+ * @see {@link getErrorCode} for the code of each schema
400
+ * @see {@link deployment} for the name a transport calls
401
+ *
402
+ * @stability unstable
403
+ * @category errors
404
+ * @since 0.3.0
405
+ */
406
+ const errorSchemas = ((...args) => errorSchemas$1(target(args)[1]));
407
+ /**
408
+ * Returns the {@link Deployment} of a Callable: its deployed name and its span
409
+ * attributes. A building block of the functions and client packages, which
410
+ * agree on both through it. Most apps don't need it.
411
+ *
412
+ * **When to use**
413
+ *
414
+ * Use when serving or calling Callables from a transport of your own.
415
+ * `Functions` and `CallableClient` already use it.
416
+ *
417
+ * **Details**
418
+ *
419
+ * Pass the Callable for a Callable in no group, or its group and its name for
420
+ * a Callable member of a {@link FunctionGroup.FunctionGroup}.
421
+ *
422
+ * @example Reading the deployed name of a member
423
+ * ```ts
424
+ * import { Schema } from "effect";
425
+ * import { Callable, FunctionGroup } from "@visiolab/effect-firebase/functions";
426
+ *
427
+ * const CreateUser = Callable.make("create", { payload: { name: Schema.String } });
428
+ *
429
+ * class Users extends FunctionGroup.make("users").add(CreateUser) {}
430
+ *
431
+ * // "users-create"
432
+ * const { name } = Callable.deployment(Users, "create");
433
+ * ```
434
+ *
435
+ * @see {@link serve} for running a call on the server
436
+ * @see {@link errorSchemas} for the errors a call can be answered with
437
+ * @see {@link DocumentTrigger.deployment} for where a Document Trigger is deployed
438
+ *
439
+ * @stability unstable
440
+ * @category serving
441
+ * @since 0.3.0
442
+ */
443
+ const deployment = ((...args) => {
444
+ const [group, callable] = target(args);
445
+ return {
446
+ name: deployedName(group, callable),
447
+ attributes: spanAttributes(group, callable)
448
+ };
449
+ });
450
+ export { Callable_exports, deployment, errorCode, errorSchemas, getErrorCode, handler, make, serve, toLayer };