@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,419 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { ArrayOr as ArrayOr$1, ArrayRemove as ArrayRemove$1, ArrayUnion as ArrayUnion$1, DeleteField as DeleteField$1, DeleteFieldOr as DeleteFieldOr$1, DocumentPath as DocumentPath$1, DocumentReference as DocumentReference$1, GeoPoint as GeoPoint$1, Increment as Increment$1, IncrementOr as IncrementOr$1, ServerTimestamp as ServerTimestamp$1, ServerTimestampOr as ServerTimestampOr$1, Timestamp as Timestamp$1 } from "./internal/firestoreSchema.mjs";
3
+ // src/firestore/FirestoreSchema.ts
4
+ var FirestoreSchema_exports = /* @__PURE__ */ __exportAll({
5
+ ArrayOr: () => ArrayOr,
6
+ ArrayRemove: () => ArrayRemove,
7
+ ArrayUnion: () => ArrayUnion,
8
+ DeleteField: () => DeleteField,
9
+ DeleteFieldOr: () => DeleteFieldOr,
10
+ DocumentPath: () => DocumentPath,
11
+ DocumentReference: () => DocumentReference,
12
+ GeoPoint: () => GeoPoint,
13
+ Increment: () => Increment,
14
+ IncrementOr: () => IncrementOr,
15
+ ServerTimestamp: () => ServerTimestamp,
16
+ ServerTimestampOr: () => ServerTimestampOr,
17
+ Timestamp: () => Timestamp
18
+ });
19
+ /**
20
+ * Schema for a Firestore timestamp, held as the portable
21
+ * {@link Timestamp.Timestamp}.
22
+ *
23
+ * **When to use**
24
+ *
25
+ * Use when a document is read, written back, and has to come out unchanged.
26
+ * Use `Schema.DateTimeUtc` or `Schema.Date` when a millisecond is precise
27
+ * enough and that value is easier to work with: Firestore stores both as a
28
+ * timestamp too, but they drop the digits finer than a millisecond.
29
+ *
30
+ * **Details**
31
+ *
32
+ * It serializes with `Schema.toCodecJson` as `{ seconds, nanoseconds }`, so the
33
+ * same model can be sent over HTTP.
34
+ *
35
+ * @example Storing a timestamp at full precision
36
+ * ```ts
37
+ * import { Schema } from "effect";
38
+ * import { FirestoreSchema } from "@visiolab/effect-firebase/firestore";
39
+ *
40
+ * const Event = Schema.Struct({ at: FirestoreSchema.Timestamp });
41
+ * ```
42
+ *
43
+ * @see {@link FirestoreModel.Timestamp} for a timestamp field the server may also fill in
44
+ * @see {@link ServerTimestampOr} for the write side of such a field
45
+ * @see {@link TimeSchema} for every schema Firestore stores as a timestamp
46
+ *
47
+ * @stability unstable
48
+ * @category schemas
49
+ * @since 0.2.0
50
+ */
51
+ const Timestamp = Timestamp$1;
52
+ /**
53
+ * Schema for a Firestore geopoint, held as the portable
54
+ * {@link GeoPoint.GeoPoint}.
55
+ *
56
+ * **When to use**
57
+ *
58
+ * Use for a location field. A hand-written struct of `latitude` and
59
+ * `longitude` would be stored as a map; this schema is stored as Firestore's
60
+ * own geopoint.
61
+ *
62
+ * @example Storing a location
63
+ * ```ts
64
+ * import { Schema } from "effect";
65
+ * import { FirestoreSchema } from "@visiolab/effect-firebase/firestore";
66
+ *
67
+ * const Place = Schema.Struct({ name: Schema.String, location: FirestoreSchema.GeoPoint });
68
+ * ```
69
+ *
70
+ * @see {@link GeoPoint.make} for building a geopoint
71
+ *
72
+ * @stability unstable
73
+ * @category schemas
74
+ * @since 0.2.0
75
+ */
76
+ const GeoPoint = GeoPoint$1;
77
+ /**
78
+ * Schema for an untyped reference to a document, held as the portable
79
+ * {@link DocumentPath.DocumentPath}.
80
+ *
81
+ * **When to use**
82
+ *
83
+ * Use for a reference whose target collection the model does not know. Use
84
+ * {@link DocumentReference} when the field always points into a known
85
+ * collection.
86
+ *
87
+ * **Details**
88
+ *
89
+ * It is stored as the SDK's own reference, built against the database the
90
+ * document is written to.
91
+ *
92
+ * @see {@link DocumentReference} for a reference typed by its collection
93
+ *
94
+ * @stability unstable
95
+ * @category schemas
96
+ * @since 0.2.0
97
+ */
98
+ const DocumentPath = DocumentPath$1;
99
+ /**
100
+ * Schema for a reference to a document in `collection`, held as a typed
101
+ * {@link Collection.DocumentReference}.
102
+ *
103
+ * **When to use**
104
+ *
105
+ * Use for a field that points to a document in a known collection, so the
106
+ * reference keeps its ids and model typed. For a field that may point into
107
+ * several collections, use a `Schema.Union` of one of these per collection.
108
+ * Use {@link DocumentPath} when the target collection is unknown.
109
+ *
110
+ * **Details**
111
+ *
112
+ * Firestore stores a reference as the document's path alone, so it is written
113
+ * as a {@link DocumentPath.DocumentPath}. Reading it back checks the path
114
+ * against the collection's segments and rebuilds the collection's own
115
+ * reference, equal to one built from `collection`. A path into any other
116
+ * collection, even one with the same last segment, fails to decode.
117
+ * `Schema.is` only accepts references built from `collection`.
118
+ *
119
+ * @example Referencing the author of a post
120
+ * ```ts
121
+ * import { Schema } from "effect";
122
+ * import { Collection, FirestoreModel, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
123
+ *
124
+ * class User extends FirestoreModel.Class<User>("User")({ name: Schema.String }) {}
125
+ * const Users = Collection.make("users", User);
126
+ *
127
+ * class Post extends FirestoreModel.Class<Post>("Post")({
128
+ * author: FirestoreSchema.DocumentReference(Users),
129
+ * }) {}
130
+ * ```
131
+ *
132
+ * @see {@link DocumentPath} for an untyped reference
133
+ *
134
+ * @stability unstable
135
+ * @category schemas
136
+ * @since 0.2.0
137
+ */
138
+ const DocumentReference = DocumentReference$1;
139
+ /**
140
+ * Schema that always writes the {@link FieldValue.serverTimestamp} sentinel,
141
+ * and fills it in when the value is constructed.
142
+ *
143
+ * **When to use**
144
+ *
145
+ * Use in a write-only schema for a field that is always the server's time,
146
+ * such as `updatedAt` on every update. Use {@link ServerTimestampOr} when the
147
+ * field may also be written with a time of your own.
148
+ *
149
+ * **Details**
150
+ *
151
+ * It accepts only the sentinel, and its constructor default fills it in, the
152
+ * way `Schema.tag` fills in a tag, so a call site never names the field. A
153
+ * document never holds the sentinel: the field reads back as the timestamp the
154
+ * server wrote, so the read side is a timestamp schema.
155
+ *
156
+ * @example Stamping every update with the server's time
157
+ * ```ts
158
+ * import { Schema } from "effect";
159
+ * import { FirestoreSchema } from "@visiolab/effect-firebase/firestore";
160
+ *
161
+ * const Touch = Schema.Struct({ updatedAt: FirestoreSchema.ServerTimestamp });
162
+ *
163
+ * const update = Touch.make({}); // { updatedAt: FieldValue.serverTimestamp }
164
+ * ```
165
+ *
166
+ * @see {@link ServerTimestampOr} for a field that may also take a time of your own
167
+ * @see {@link FirestoreModel.Timestamp} for the matching model field
168
+ *
169
+ * @stability unstable
170
+ * @category schemas
171
+ * @since 0.2.0
172
+ */
173
+ const ServerTimestamp = ServerTimestamp$1;
174
+ /**
175
+ * Schema for a timestamp field written either as a time of your own or as
176
+ * {@link FieldValue.serverTimestamp}.
177
+ *
178
+ * **When to use**
179
+ *
180
+ * Use as the write side of a timestamp field when building model variants by
181
+ * hand. Most models use {@link FirestoreModel.Timestamp}, which pairs this with
182
+ * the read side for you.
183
+ *
184
+ * **Details**
185
+ *
186
+ * `schema` is the read side: {@link Timestamp} to keep digits finer than a
187
+ * millisecond, or `Schema.DateTimeUtc` or `Schema.Date` (see
188
+ * {@link TimeSchema}). A read never sees the sentinel, so the read variant
189
+ * uses `schema` alone.
190
+ *
191
+ * @example A timestamp the server may fill in
192
+ * ```ts
193
+ * import { Schema } from "effect";
194
+ * import { FieldValue, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
195
+ *
196
+ * const UpdatedAt = FirestoreSchema.ServerTimestampOr(Schema.DateTimeUtc);
197
+ *
198
+ * Schema.is(UpdatedAt)(FieldValue.serverTimestamp); // true
199
+ * ```
200
+ *
201
+ * @see {@link FirestoreModel.Timestamp} for the model field built on it
202
+ * @see {@link ServerTimestamp} for a field that always writes the sentinel
203
+ * @see {@link FieldValue.serverTimestamp} for the sentinel itself
204
+ *
205
+ * @stability unstable
206
+ * @category schemas
207
+ * @since 0.2.0
208
+ */
209
+ const ServerTimestampOr = ServerTimestampOr$1;
210
+ /**
211
+ * Schema for the {@link FieldValue.Increment} sentinel, as built by
212
+ * {@link FieldValue.increment} and {@link FieldValue.decrement}.
213
+ *
214
+ * **When to use**
215
+ *
216
+ * Use in a write-only schema for a field that is only ever moved, never set.
217
+ * Use {@link IncrementOr} for a field that may be set outright too.
218
+ *
219
+ * **Details**
220
+ *
221
+ * A document holds the sum the server wrote, so the read side of the same
222
+ * field is a plain number.
223
+ *
224
+ * @see {@link IncrementOr} for a number that may also be set outright
225
+ * @see {@link FirestoreModel.Number} for the matching model field
226
+ *
227
+ * @stability unstable
228
+ * @category schemas
229
+ * @since 0.2.0
230
+ */
231
+ const Increment = Increment$1;
232
+ /**
233
+ * Schema for a number field written either as a number or as an
234
+ * {@link FieldValue.increment} or {@link FieldValue.decrement}.
235
+ *
236
+ * **When to use**
237
+ *
238
+ * Use as the write side of a counter when building model variants by hand.
239
+ * Most models use {@link FirestoreModel.Number}, which pairs this with the
240
+ * read side for you.
241
+ *
242
+ * **Details**
243
+ *
244
+ * `schema` is the read side and says what the number may be: `Schema.Finite`,
245
+ * `Schema.Int` for whole steps, or either with further checks. It must be
246
+ * stored as a number, since that is what the server adds to. A read never sees
247
+ * the sentinel, so the read variant uses `schema` alone.
248
+ *
249
+ * @example A counter the server may move
250
+ * ```ts
251
+ * import { Schema } from "effect";
252
+ * import { FieldValue, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
253
+ *
254
+ * const Visits = FirestoreSchema.IncrementOr(Schema.Int);
255
+ *
256
+ * Schema.is(Visits)(FieldValue.increment(1)); // true
257
+ * ```
258
+ *
259
+ * @see {@link FirestoreModel.Number} for the model field built on it
260
+ * @see {@link Increment} for a field that is only ever moved
261
+ * @see {@link FieldValue.increment} for the sentinel itself
262
+ *
263
+ * @stability unstable
264
+ * @category schemas
265
+ * @since 0.2.0
266
+ */
267
+ const IncrementOr = IncrementOr$1;
268
+ /**
269
+ * Schema for the {@link FieldValue.deleteField} sentinel.
270
+ *
271
+ * **When to use**
272
+ *
273
+ * Use when building an update schema by hand. Most models get it through
274
+ * {@link DeleteFieldOr}, or through {@link FirestoreModel.Optional}.
275
+ *
276
+ * **Details**
277
+ *
278
+ * Unlike {@link ServerTimestamp}, it has no constructor default: a field is
279
+ * only removed when you ask for it. A removed field is not there to read, so
280
+ * the read side of the same field is an optional key.
281
+ *
282
+ * @see {@link DeleteFieldOr} for a field an update may write or remove
283
+ * @see {@link FirestoreModel.Optional} for the matching model field
284
+ *
285
+ * @stability unstable
286
+ * @category schemas
287
+ * @since 0.2.0
288
+ */
289
+ const DeleteField = DeleteField$1;
290
+ /**
291
+ * Schema for a field an update either writes or removes with
292
+ * {@link FieldValue.deleteField}.
293
+ *
294
+ * **When to use**
295
+ *
296
+ * Use as the update side of an optional field when building model variants by
297
+ * hand. Most models use {@link FirestoreModel.Optional}, which does this for
298
+ * you.
299
+ *
300
+ * **Details**
301
+ *
302
+ * `schema` is what the field holds while it is there. Only an update accepts
303
+ * it: a read never holds the sentinel, and Firestore refuses it in a document
304
+ * written whole.
305
+ *
306
+ * The sentinel is tried first, since a schema that accepts any object, such
307
+ * as a struct whose keys are all optional, would accept it too and strip it to
308
+ * `{}`.
309
+ *
310
+ * @example An optional field an update may remove
311
+ * ```ts
312
+ * import { Schema } from "effect";
313
+ * import { FieldValue, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
314
+ *
315
+ * const Nickname = FirestoreSchema.DeleteFieldOr(Schema.String);
316
+ *
317
+ * Schema.is(Nickname)(FieldValue.deleteField); // true
318
+ * ```
319
+ *
320
+ * @see {@link FirestoreModel.Optional} for the model field built on it
321
+ * @see {@link FieldValue.deleteField} for the sentinel itself
322
+ *
323
+ * @stability unstable
324
+ * @category schemas
325
+ * @since 0.2.0
326
+ */
327
+ const DeleteFieldOr = DeleteFieldOr$1;
328
+ /**
329
+ * Schema for the {@link FieldValue.arrayUnion} sentinel, with each element
330
+ * encoded through `item`.
331
+ *
332
+ * **When to use**
333
+ *
334
+ * Use when building an update schema by hand. Most models get it through
335
+ * {@link ArrayOr}, or through {@link FirestoreModel.Array}.
336
+ *
337
+ * **Details**
338
+ *
339
+ * Each element is encoded through `item`, then stored the way
340
+ * {@link FirestoreValue.toCodecFirestore} stores `item`, so a `DateTimeUtc`
341
+ * among them is stored as a timestamp, and an element `item` rejects is
342
+ * rejected here too.
343
+ *
344
+ * Firestore requires two things of `item`: it is not an array itself, since
345
+ * arrays may not nest, and it does not write a sentinel, since one may not sit
346
+ * inside an array.
347
+ *
348
+ * A document holds the array the server wrote, so the read side of the same
349
+ * field is the array.
350
+ *
351
+ * @see {@link ArrayRemove} for removing elements
352
+ * @see {@link ArrayOr} for an array field written whole, grown or shrunk
353
+ *
354
+ * @stability unstable
355
+ * @category schemas
356
+ * @since 0.2.0
357
+ */
358
+ const ArrayUnion = ArrayUnion$1;
359
+ /**
360
+ * Schema for the {@link FieldValue.arrayRemove} sentinel, with each element
361
+ * encoded through `item`.
362
+ *
363
+ * **When to use**
364
+ *
365
+ * Use when building an update schema by hand. Most models get it through
366
+ * {@link ArrayOr}, or through {@link FirestoreModel.Array}.
367
+ *
368
+ * **Details**
369
+ *
370
+ * Each element is encoded through `item`, as for {@link ArrayUnion}. Encode
371
+ * through the same schema the array was written with: the server only removes
372
+ * elements that match exactly.
373
+ *
374
+ * @see {@link ArrayUnion} for adding elements
375
+ * @see {@link ArrayOr} for an array field written whole, grown or shrunk
376
+ *
377
+ * @stability unstable
378
+ * @category schemas
379
+ * @since 0.2.0
380
+ */
381
+ const ArrayRemove = ArrayRemove$1;
382
+ /**
383
+ * Schema for an array field written whole, or grown or shrunk by the server
384
+ * with {@link FieldValue.arrayUnion} and {@link FieldValue.arrayRemove}.
385
+ *
386
+ * **When to use**
387
+ *
388
+ * Use as the update side of an array of `item` when building model variants by
389
+ * hand, against a read of `Schema.Array(item)`. Most models use
390
+ * {@link FirestoreModel.Array}, which pairs the two for you.
391
+ *
392
+ * **Details**
393
+ *
394
+ * Writing the array whole replaces what the server holds, so a client that
395
+ * read it, added an element and wrote it back loses whatever another client
396
+ * added in between. Growing or shrinking it does not. A read never sees the
397
+ * sentinels, so the read variant is the array alone.
398
+ *
399
+ * @example An array the server may grow or shrink
400
+ * ```ts
401
+ * import { Schema } from "effect";
402
+ * import { FieldValue, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
403
+ *
404
+ * const Tags = FirestoreSchema.ArrayOr(Schema.String);
405
+ *
406
+ * Schema.is(Tags)(["news"]); // true
407
+ * Schema.is(Tags)(FieldValue.arrayUnion("news")); // true
408
+ * ```
409
+ *
410
+ * @see {@link FirestoreModel.Array} for the model field built on it
411
+ * @see {@link ArrayUnion} for the growing sentinel's schema
412
+ * @see {@link ArrayRemove} for the shrinking sentinel's schema
413
+ *
414
+ * @stability unstable
415
+ * @category schemas
416
+ * @since 0.2.0
417
+ */
418
+ const ArrayOr = ArrayOr$1;
419
+ export { ArrayOr, ArrayRemove, ArrayUnion, DeleteField, DeleteFieldOr, DocumentPath, DocumentReference, FirestoreSchema_exports, GeoPoint, Increment, IncrementOr, ServerTimestamp, ServerTimestampOr, Timestamp };
@@ -0,0 +1,145 @@
1
+ import { DocumentPath } from "./DocumentPath.mjs";
2
+ import { ArrayRemove, ArrayUnion, DeleteField, Increment, ServerTimestamp } from "./FieldValue.mjs";
3
+ import { GeoPoint } from "./GeoPoint.mjs";
4
+ import { Timestamp } from "./Timestamp.mjs";
5
+ import { FirestoreError } from "./internal/firestoreError.mjs";
6
+ import { FieldPath as FieldPath$1, Kinds as Kinds$1, Reader as Reader$1, Writer as Writer$1 } from "./internal/firestoreValueWalk.mjs";
7
+ import "./Firestore.mjs";
8
+ import { Result, Schema, SchemaAST } from "effect";
9
+ declare namespace FirestoreValue_d_exports {
10
+ export { FieldPath, FirestoreValue, Kinds, Reader, Writer, formatFieldPath, fromSdk, isFirestoreValue, readDocument, toCodecFirestore, toSdk };
11
+ }
12
+ declare module "effect/Schema" {
13
+ namespace Annotations {
14
+ interface Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []> {
15
+ /**
16
+ * Returns the link used to derive the declaration's Firestore
17
+ * representation, or `undefined` when it already holds a Firestore Value.
18
+ *
19
+ * {@link toCodecFirestore} prefers it to `toCodecJson` and `toCodec`.
20
+ */
21
+ readonly toCodecFirestore?: ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link | undefined) | undefined;
22
+ }
23
+ }
24
+ }
25
+ /**
26
+ * A value as Firestore stores it, independent of either SDK.
27
+ *
28
+ * **Details**
29
+ *
30
+ * One of: `null`, a boolean, a number, a string, a {@link Timestamp.Timestamp},
31
+ * a {@link GeoPoint.GeoPoint}, a {@link DocumentPath.DocumentPath}, bytes as a
32
+ * `Uint8Array`, a {@link FieldValue} sentinel, or an array or plain-object map
33
+ * of Firestore Values.
34
+ *
35
+ * A typed {@link Collection.DocumentReference} is not one: Firestore stores
36
+ * only its path, as a {@link DocumentPath.DocumentPath}.
37
+ *
38
+ * @stability unstable
39
+ * @category models
40
+ * @since 0.2.0
41
+ */
42
+ export type FirestoreValue = null | boolean | number | string | Timestamp | GeoPoint | DocumentPath | Uint8Array | ServerTimestamp | Increment | DeleteField | ArrayUnion<FirestoreValue> | ArrayRemove<FirestoreValue> | ReadonlyArray<FirestoreValue> | {
43
+ readonly [key: string]: FirestoreValue;
44
+ };
45
+ /**
46
+ * Checks whether `u` is a {@link FirestoreValue}, all the way down.
47
+ *
48
+ * **Details**
49
+ *
50
+ * Maps must be plain objects. An instance of any other class is not a
51
+ * Firestore Value, since Firestore would store it as a map and read it back as
52
+ * a plain object.
53
+ *
54
+ * @stability unstable
55
+ * @category guards
56
+ * @since 0.2.0
57
+ */
58
+ export declare const isFirestoreValue: (u: unknown) => u is FirestoreValue;
59
+ /** @internal */
60
+ export type FieldPath = FieldPath$1;
61
+ /** @internal */
62
+ export type Kinds = Kinds$1;
63
+ /** @internal */
64
+ export type Writer = Writer$1;
65
+ /** @internal */
66
+ export type Reader = Reader$1;
67
+ /** @internal */
68
+ export declare const formatFieldPath: (path: FieldPath) => string;
69
+ /** @internal */
70
+ export declare const toSdk: (value: FirestoreValue, writer: Writer) => unknown;
71
+ /** @internal */
72
+ export declare const fromSdk: (value: unknown, reader: Reader) => Result.Result<FirestoreValue, FirestoreError>;
73
+ /** @internal */
74
+ export declare const readDocument: (path: string, data: unknown, reader: Reader) => Result.Result<FirestoreValue | undefined, FirestoreError>;
75
+ /**
76
+ * Type-level representation of the codec {@link toCodecFirestore} returns: the
77
+ * schema's `Type`, encoded as a {@link FirestoreValue}.
78
+ *
79
+ * @stability unstable
80
+ * @category models
81
+ * @since 0.2.0
82
+ */
83
+ export interface toCodecFirestore<S extends Schema.Constraint> extends Schema.BottomLazy<S["ast"], toCodecFirestore<S>, S["~type.parameters"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
84
+ readonly Type: S["Type"];
85
+ readonly Encoded: FirestoreValue;
86
+ readonly DecodingServices: S["DecodingServices"];
87
+ readonly EncodingServices: S["EncodingServices"];
88
+ readonly "~type.make.in": S["~type.make.in"];
89
+ readonly "~type.make": S["~type.make"];
90
+ readonly Iso: S["Iso"];
91
+ readonly schema: S;
92
+ }
93
+ /**
94
+ * Derives a codec from a schema to Firestore Values.
95
+ *
96
+ * **When to use**
97
+ *
98
+ * Use to encode or decode a value the way {@link Firestore} stores it outside
99
+ * a read or write, such as in a test or a custom backend. Reads and writes
100
+ * through {@link Firestore} already use it.
101
+ *
102
+ * **Details**
103
+ *
104
+ * It works like `Schema.toCodecJson`: the schema's own transformations run
105
+ * first, then structs, tuples, arrays, unions and `Schema.suspend` are walked.
106
+ * A declaration is resolved in this order:
107
+ *
108
+ * 1. `Schema.Date` and `Schema.DateTimeUtc` become a portable `Timestamp`, and
109
+ * `Schema.Uint8Array` is stored as bytes. Reading a `Date` or `DateTime.Utc`
110
+ * back keeps milliseconds only.
111
+ * 2. A `toCodecFirestore` annotation.
112
+ * 3. A `toCodecJson` annotation, since every JSON value is a Firestore Value.
113
+ * 4. A `toCodec` annotation.
114
+ * 5. Otherwise the value must already be a Firestore Value, and encoding
115
+ * anything else fails with a schema issue at its path.
116
+ *
117
+ * Keywords follow `Schema.toCodecJson`: a `bigint` or `symbol` is written as a
118
+ * string, and `undefined` as `null`. Unlike there, `Schema.Any` is no escape
119
+ * hatch: like `Schema.Unknown` it takes Firestore Values only, since the SDK
120
+ * mappings take nothing else. Derivation never fails and is memoized per
121
+ * schema.
122
+ *
123
+ * @example Encoding a value to Firestore Values
124
+ * ```ts
125
+ * import { DateTime, Effect, Schema } from "effect";
126
+ * import { FirestoreValue } from "@visiolab/effect-firebase/firestore";
127
+ *
128
+ * const Event = Schema.Struct({ name: Schema.String, at: Schema.DateTimeUtc });
129
+ * const codec = FirestoreValue.toCodecFirestore(Event);
130
+ *
131
+ * // `at` is encoded as a portable `Timestamp`.
132
+ * const encoded = Schema.encodeEffect(codec)({
133
+ * name: "launch",
134
+ * at: DateTime.makeUnsafe("2024-01-01T00:00:00Z"),
135
+ * });
136
+ * ```
137
+ *
138
+ * @see {@link FirestoreSchema} for schemas of the values Effect has none for
139
+ *
140
+ * @stability unstable
141
+ * @category converting
142
+ * @since 0.2.0
143
+ */
144
+ export declare const toCodecFirestore: <S extends Schema.Constraint>(schema: S) => toCodecFirestore<S>;
145
+ export { FirestoreValue_d_exports };
@@ -0,0 +1,87 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { formatFieldPath as formatFieldPath$1, fromSdk as fromSdk$1, readDocument as readDocument$1, toSdk as toSdk$1 } from "./internal/firestoreValueWalk.mjs";
3
+ import { isFirestoreValue as isFirestoreValue$1, toCodecFirestore as toCodecFirestore$1 } from "./internal/firestoreValue.mjs";
4
+ // src/firestore/FirestoreValue.ts
5
+ var FirestoreValue_exports = /* @__PURE__ */ __exportAll({
6
+ formatFieldPath: () => formatFieldPath,
7
+ fromSdk: () => fromSdk,
8
+ isFirestoreValue: () => isFirestoreValue,
9
+ readDocument: () => readDocument,
10
+ toCodecFirestore: () => toCodecFirestore,
11
+ toSdk: () => toSdk
12
+ });
13
+ /**
14
+ * Checks whether `u` is a {@link FirestoreValue}, all the way down.
15
+ *
16
+ * **Details**
17
+ *
18
+ * Maps must be plain objects. An instance of any other class is not a
19
+ * Firestore Value, since Firestore would store it as a map and read it back as
20
+ * a plain object.
21
+ *
22
+ * @stability unstable
23
+ * @category guards
24
+ * @since 0.2.0
25
+ */
26
+ const isFirestoreValue = isFirestoreValue$1;
27
+ /** @internal */
28
+ const formatFieldPath = formatFieldPath$1;
29
+ /** @internal */
30
+ const toSdk = toSdk$1;
31
+ /** @internal */
32
+ const fromSdk = fromSdk$1;
33
+ /** @internal */
34
+ const readDocument = readDocument$1;
35
+ /**
36
+ * Derives a codec from a schema to Firestore Values.
37
+ *
38
+ * **When to use**
39
+ *
40
+ * Use to encode or decode a value the way {@link Firestore} stores it outside
41
+ * a read or write, such as in a test or a custom backend. Reads and writes
42
+ * through {@link Firestore} already use it.
43
+ *
44
+ * **Details**
45
+ *
46
+ * It works like `Schema.toCodecJson`: the schema's own transformations run
47
+ * first, then structs, tuples, arrays, unions and `Schema.suspend` are walked.
48
+ * A declaration is resolved in this order:
49
+ *
50
+ * 1. `Schema.Date` and `Schema.DateTimeUtc` become a portable `Timestamp`, and
51
+ * `Schema.Uint8Array` is stored as bytes. Reading a `Date` or `DateTime.Utc`
52
+ * back keeps milliseconds only.
53
+ * 2. A `toCodecFirestore` annotation.
54
+ * 3. A `toCodecJson` annotation, since every JSON value is a Firestore Value.
55
+ * 4. A `toCodec` annotation.
56
+ * 5. Otherwise the value must already be a Firestore Value, and encoding
57
+ * anything else fails with a schema issue at its path.
58
+ *
59
+ * Keywords follow `Schema.toCodecJson`: a `bigint` or `symbol` is written as a
60
+ * string, and `undefined` as `null`. Unlike there, `Schema.Any` is no escape
61
+ * hatch: like `Schema.Unknown` it takes Firestore Values only, since the SDK
62
+ * mappings take nothing else. Derivation never fails and is memoized per
63
+ * schema.
64
+ *
65
+ * @example Encoding a value to Firestore Values
66
+ * ```ts
67
+ * import { DateTime, Effect, Schema } from "effect";
68
+ * import { FirestoreValue } from "@visiolab/effect-firebase/firestore";
69
+ *
70
+ * const Event = Schema.Struct({ name: Schema.String, at: Schema.DateTimeUtc });
71
+ * const codec = FirestoreValue.toCodecFirestore(Event);
72
+ *
73
+ * // `at` is encoded as a portable `Timestamp`.
74
+ * const encoded = Schema.encodeEffect(codec)({
75
+ * name: "launch",
76
+ * at: DateTime.makeUnsafe("2024-01-01T00:00:00Z"),
77
+ * });
78
+ * ```
79
+ *
80
+ * @see {@link FirestoreSchema} for schemas of the values Effect has none for
81
+ *
82
+ * @stability unstable
83
+ * @category converting
84
+ * @since 0.2.0
85
+ */
86
+ const toCodecFirestore = toCodecFirestore$1;
87
+ export { FirestoreValue_exports, formatFieldPath, fromSdk, isFirestoreValue, readDocument, toCodecFirestore, toSdk };