@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.
- package/LICENSE +21 -0
- package/README.md +81 -2
- package/dist/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/app/App.d.mts +27 -0
- package/dist/app/App.mjs +27 -0
- package/dist/app/index.d.mts +2 -0
- package/dist/app/index.mjs +1 -0
- package/dist/firestore/Collection.d.mts +423 -0
- package/dist/firestore/Collection.mjs +133 -0
- package/dist/firestore/CollectionGroup.d.mts +164 -0
- package/dist/firestore/CollectionGroup.mjs +84 -0
- package/dist/firestore/DocumentPath.d.mts +95 -0
- package/dist/firestore/DocumentPath.mjs +71 -0
- package/dist/firestore/DocumentSnapshot.d.mts +239 -0
- package/dist/firestore/DocumentSnapshot.mjs +134 -0
- package/dist/firestore/FieldValue.d.mts +332 -0
- package/dist/firestore/FieldValue.mjs +256 -0
- package/dist/firestore/Firestore.d.mts +1165 -0
- package/dist/firestore/Firestore.mjs +274 -0
- package/dist/firestore/FirestoreModel.d.mts +1232 -0
- package/dist/firestore/FirestoreModel.mjs +586 -0
- package/dist/firestore/FirestoreSchema.d.mts +567 -0
- package/dist/firestore/FirestoreSchema.mjs +419 -0
- package/dist/firestore/FirestoreValue.d.mts +145 -0
- package/dist/firestore/FirestoreValue.mjs +87 -0
- package/dist/firestore/GeoPoint.d.mts +90 -0
- package/dist/firestore/GeoPoint.mjs +75 -0
- package/dist/firestore/Patch.d.mts +73 -0
- package/dist/firestore/Patch.mjs +57 -0
- package/dist/firestore/QuerySnapshot.d.mts +107 -0
- package/dist/firestore/QuerySnapshot.mjs +43 -0
- package/dist/firestore/Timestamp.d.mts +273 -0
- package/dist/firestore/Timestamp.mjs +255 -0
- package/dist/firestore/index.d.mts +14 -0
- package/dist/firestore/index.mjs +14 -0
- package/dist/firestore/internal/collection.mjs +156 -0
- package/dist/firestore/internal/collectionGroup.mjs +64 -0
- package/dist/firestore/internal/documentPath.d.mts +4 -0
- package/dist/firestore/internal/documentPath.mjs +42 -0
- package/dist/firestore/internal/documentSnapshot.mjs +63 -0
- package/dist/firestore/internal/fieldValue.d.mts +11 -0
- package/dist/firestore/internal/fieldValue.mjs +88 -0
- package/dist/firestore/internal/firestore.mjs +145 -0
- package/dist/firestore/internal/firestoreError.d.mts +29 -0
- package/dist/firestore/internal/firestoreError.mjs +30 -0
- package/dist/firestore/internal/firestoreModel.mjs +719 -0
- package/dist/firestore/internal/firestoreSchema.mjs +123 -0
- package/dist/firestore/internal/firestoreValue.mjs +108 -0
- package/dist/firestore/internal/firestoreValueWalk.d.mts +58 -0
- package/dist/firestore/internal/firestoreValueWalk.mjs +223 -0
- package/dist/firestore/internal/geoPoint.d.mts +4 -0
- package/dist/firestore/internal/geoPoint.mjs +39 -0
- package/dist/firestore/internal/patch.mjs +19 -0
- package/dist/firestore/internal/querySnapshot.mjs +24 -0
- package/dist/firestore/internal/schemaAST.mjs +35 -0
- package/dist/firestore/internal/snapshotExtra.mjs +35 -0
- package/dist/firestore/internal/streamFromListener.mjs +12 -0
- package/dist/firestore/internal/timestamp.d.mts +4 -0
- package/dist/firestore/internal/timestamp.mjs +66 -0
- package/dist/firestore/internal/timestampSchema.mjs +31 -0
- package/dist/firestore/internal/transactionFromCallback.mjs +66 -0
- package/dist/functions/Callable.d.mts +654 -0
- package/dist/functions/Callable.mjs +450 -0
- package/dist/functions/CallableError.d.mts +297 -0
- package/dist/functions/CallableError.mjs +256 -0
- package/dist/functions/CallableMiddleware.d.mts +213 -0
- package/dist/functions/CallableMiddleware.mjs +52 -0
- package/dist/functions/CallableRequest.d.mts +166 -0
- package/dist/functions/CallableRequest.mjs +18 -0
- package/dist/functions/Caller.d.mts +103 -0
- package/dist/functions/Caller.mjs +115 -0
- package/dist/functions/DocumentTrigger.d.mts +795 -0
- package/dist/functions/DocumentTrigger.mjs +566 -0
- package/dist/functions/FirebaseFunction.d.mts +79 -0
- package/dist/functions/FirebaseFunction.mjs +4 -0
- package/dist/functions/FunctionGroup.d.mts +175 -0
- package/dist/functions/FunctionGroup.mjs +64 -0
- package/dist/functions/index.d.mts +9 -0
- package/dist/functions/index.mjs +9 -0
- package/dist/functions/internal/callable.mjs +167 -0
- package/dist/functions/internal/callableMiddleware.d.mts +19 -0
- package/dist/functions/internal/callableMiddleware.mjs +15 -0
- package/dist/functions/internal/callableRequest.mjs +6 -0
- package/dist/functions/internal/documentTrigger.d.mts +10 -0
- package/dist/functions/internal/documentTrigger.mjs +73 -0
- package/dist/functions/internal/firebaseFunction.d.mts +5 -0
- package/dist/functions/internal/firebaseFunction.mjs +24 -0
- package/dist/functions/internal/functionGroup.mjs +36 -0
- package/package.json +72 -3
- package/src/app/App.ts +24 -0
- package/src/app/index.ts +7 -0
- package/src/firestore/Collection.ts +520 -0
- package/src/firestore/CollectionGroup.ts +245 -0
- package/src/firestore/DocumentPath.ts +114 -0
- package/src/firestore/DocumentSnapshot.ts +308 -0
- package/src/firestore/FieldValue.ts +375 -0
- package/src/firestore/Firestore.ts +1432 -0
- package/src/firestore/FirestoreModel.ts +1884 -0
- package/src/firestore/FirestoreSchema.ts +643 -0
- package/src/firestore/FirestoreValue.ts +207 -0
- package/src/firestore/GeoPoint.ts +105 -0
- package/src/firestore/Patch.ts +117 -0
- package/src/firestore/QuerySnapshot.ts +150 -0
- package/src/firestore/Timestamp.ts +302 -0
- package/src/firestore/index.ts +67 -0
- package/src/firestore/internal/collection.ts +246 -0
- package/src/firestore/internal/collectionGroup.ts +81 -0
- package/src/firestore/internal/documentPath.ts +53 -0
- package/src/firestore/internal/documentSnapshot.ts +117 -0
- package/src/firestore/internal/fieldValue.ts +119 -0
- package/src/firestore/internal/firestore.ts +322 -0
- package/src/firestore/internal/firestoreError.ts +36 -0
- package/src/firestore/internal/firestoreModel.ts +1242 -0
- package/src/firestore/internal/firestoreSchema.ts +218 -0
- package/src/firestore/internal/firestoreValue.ts +202 -0
- package/src/firestore/internal/firestoreValueWalk.ts +349 -0
- package/src/firestore/internal/geoPoint.ts +59 -0
- package/src/firestore/internal/patch.ts +21 -0
- package/src/firestore/internal/querySnapshot.ts +39 -0
- package/src/firestore/internal/schemaAST.ts +83 -0
- package/src/firestore/internal/snapshotExtra.ts +47 -0
- package/src/firestore/internal/streamFromListener.ts +27 -0
- package/src/firestore/internal/timestamp.ts +119 -0
- package/src/firestore/internal/timestampSchema.ts +42 -0
- package/src/firestore/internal/transactionFromCallback.ts +106 -0
- package/src/functions/Callable.ts +855 -0
- package/src/functions/CallableError.ts +348 -0
- package/src/functions/CallableMiddleware.ts +279 -0
- package/src/functions/CallableRequest.ts +207 -0
- package/src/functions/Caller.ts +141 -0
- package/src/functions/DocumentTrigger.ts +927 -0
- package/src/functions/FirebaseFunction.ts +96 -0
- package/src/functions/FunctionGroup.ts +225 -0
- package/src/functions/index.ts +62 -0
- package/src/functions/internal/callable.ts +272 -0
- package/src/functions/internal/callableMiddleware.ts +54 -0
- package/src/functions/internal/callableRequest.ts +8 -0
- package/src/functions/internal/documentTrigger.ts +143 -0
- package/src/functions/internal/firebaseFunction.ts +58 -0
- package/src/functions/internal/functionGroup.ts +47 -0
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { Array as Array$1, Class as Class$1, Field as Field$1, FieldExcept as FieldExcept$1, FieldOnly as FieldOnly$1, Immutable as Immutable$1, Number as Number$1, Optional as Optional$1, Record as Record$1, Struct as Struct$1, Timestamp as Timestamp$1, Union as Union$1, extract as extract$1, fieldEvolve as fieldEvolve$1, fields as fields$1 } from "./internal/firestoreModel.mjs";
|
|
3
|
+
// src/firestore/FirestoreModel.ts
|
|
4
|
+
var FirestoreModel_exports = /* @__PURE__ */ __exportAll({
|
|
5
|
+
Array: () => Array,
|
|
6
|
+
Class: () => Class,
|
|
7
|
+
Field: () => Field,
|
|
8
|
+
FieldExcept: () => FieldExcept,
|
|
9
|
+
FieldOnly: () => FieldOnly,
|
|
10
|
+
Immutable: () => Immutable,
|
|
11
|
+
Number: () => Number,
|
|
12
|
+
Optional: () => Optional,
|
|
13
|
+
Record: () => Record,
|
|
14
|
+
Struct: () => Struct,
|
|
15
|
+
Timestamp: () => Timestamp,
|
|
16
|
+
Union: () => Union,
|
|
17
|
+
extract: () => extract,
|
|
18
|
+
fieldEvolve: () => fieldEvolve,
|
|
19
|
+
fields: () => fields
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Declares a field with a different schema per variant.
|
|
23
|
+
*
|
|
24
|
+
* **When to use**
|
|
25
|
+
*
|
|
26
|
+
* Use when a field is read and written in shapes no ready-made field covers.
|
|
27
|
+
* Leave a variant out to keep the field out of that shape.
|
|
28
|
+
*
|
|
29
|
+
* @example A field written as a sentinel and read as a timestamp
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { FirestoreModel, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
32
|
+
*
|
|
33
|
+
* class Post extends FirestoreModel.Class<Post>("Post")({
|
|
34
|
+
* publishedAt: FirestoreModel.Field({
|
|
35
|
+
* read: FirestoreSchema.Timestamp,
|
|
36
|
+
* create: FirestoreSchema.ServerTimestamp,
|
|
37
|
+
* }),
|
|
38
|
+
* }) {}
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @see {@link FieldOnly} for the same schema in some variants
|
|
42
|
+
* @see {@link FieldExcept} for the same schema in all but some variants
|
|
43
|
+
* @see {@link Timestamp} for a timestamp the client or the server may set
|
|
44
|
+
*
|
|
45
|
+
* @stability unstable
|
|
46
|
+
* @category constructors
|
|
47
|
+
* @since 0.2.0
|
|
48
|
+
*/
|
|
49
|
+
const Field = Field$1;
|
|
50
|
+
/**
|
|
51
|
+
* Declares a field with one schema that appears only in the named variants.
|
|
52
|
+
*
|
|
53
|
+
* **When to use**
|
|
54
|
+
*
|
|
55
|
+
* Use for a field only some shapes carry, such as one only ever read, or one
|
|
56
|
+
* only ever written.
|
|
57
|
+
*
|
|
58
|
+
* @example A field only read
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { Schema } from "effect";
|
|
61
|
+
* import { FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
62
|
+
*
|
|
63
|
+
* class Account extends FirestoreModel.Class<Account>("Account")({
|
|
64
|
+
* plan: FirestoreModel.FieldOnly(["read"])(Schema.Literals(["free", "paid"])),
|
|
65
|
+
* }) {}
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @see {@link FieldExcept} for naming the variants to leave out instead
|
|
69
|
+
* @see {@link Field} for a different schema per variant
|
|
70
|
+
* @see {@link Immutable} for a field read and created, but never updated
|
|
71
|
+
*
|
|
72
|
+
* @stability unstable
|
|
73
|
+
* @category constructors
|
|
74
|
+
* @since 0.2.0
|
|
75
|
+
*/
|
|
76
|
+
const FieldOnly = FieldOnly$1;
|
|
77
|
+
/**
|
|
78
|
+
* Declares a field with one schema that appears in every variant but the named
|
|
79
|
+
* ones.
|
|
80
|
+
*
|
|
81
|
+
* **When to use**
|
|
82
|
+
*
|
|
83
|
+
* Use when a field belongs in most shapes and only a few leave it out.
|
|
84
|
+
*
|
|
85
|
+
* @see {@link FieldOnly} for naming the variants to keep instead
|
|
86
|
+
* @see {@link Field} for a different schema per variant
|
|
87
|
+
*
|
|
88
|
+
* @stability unstable
|
|
89
|
+
* @category constructors
|
|
90
|
+
* @since 0.2.0
|
|
91
|
+
*/
|
|
92
|
+
const FieldExcept = FieldExcept$1;
|
|
93
|
+
/**
|
|
94
|
+
* Declares a set of fields without building a class.
|
|
95
|
+
*
|
|
96
|
+
* **When to use**
|
|
97
|
+
*
|
|
98
|
+
* Use for a nested map inside a document, or for fields shared between several
|
|
99
|
+
* documents. An update reaches into a struct field by field, unlike a plain
|
|
100
|
+
* `Schema.Struct`, which is a value written whole.
|
|
101
|
+
*
|
|
102
|
+
* @example A nested address
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { Schema } from "effect";
|
|
105
|
+
* import { FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
106
|
+
*
|
|
107
|
+
* const Address = FirestoreModel.Struct({ city: Schema.String, zip: Schema.String });
|
|
108
|
+
*
|
|
109
|
+
* class Customer extends FirestoreModel.Class<Customer>("Customer")({
|
|
110
|
+
* address: Address,
|
|
111
|
+
* }) {}
|
|
112
|
+
*
|
|
113
|
+
* Customer.update.make({ address: { city: "Berlin" } }); // written at "address.city"
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @see {@link Class} for a whole document
|
|
117
|
+
* @see {@link Patch.replace} for writing a struct whole in an update
|
|
118
|
+
*
|
|
119
|
+
* @stability unstable
|
|
120
|
+
* @category constructors
|
|
121
|
+
* @since 0.2.0
|
|
122
|
+
*/
|
|
123
|
+
const Struct = Struct$1;
|
|
124
|
+
/**
|
|
125
|
+
* Rewrites the schemas of a field, variant by variant.
|
|
126
|
+
*
|
|
127
|
+
* **When to use**
|
|
128
|
+
*
|
|
129
|
+
* Use to derive a field from another one, such as narrowing what one variant
|
|
130
|
+
* takes while keeping the others.
|
|
131
|
+
*
|
|
132
|
+
* @see {@link Field} for declaring a field per variant directly
|
|
133
|
+
*
|
|
134
|
+
* @stability unstable
|
|
135
|
+
* @category transforming
|
|
136
|
+
* @since 0.2.0
|
|
137
|
+
*/
|
|
138
|
+
const fieldEvolve = fieldEvolve$1;
|
|
139
|
+
/**
|
|
140
|
+
* Pulls one variant out of a struct as a plain schema.
|
|
141
|
+
*
|
|
142
|
+
* **When to use**
|
|
143
|
+
*
|
|
144
|
+
* Use to get a struct's `read` or `create` shape as an ordinary schema, for
|
|
145
|
+
* example to validate data outside Firestore.
|
|
146
|
+
*
|
|
147
|
+
* **Details**
|
|
148
|
+
*
|
|
149
|
+
* The `update` variant it returns is the one the fields declare: it is neither
|
|
150
|
+
* made partial nor flattened into paths. Use {@link Class.update} for the
|
|
151
|
+
* update a document is written through.
|
|
152
|
+
*
|
|
153
|
+
* @see {@link fields} for the field declarations themselves
|
|
154
|
+
*
|
|
155
|
+
* @stability unstable
|
|
156
|
+
* @category converting
|
|
157
|
+
* @since 0.2.0
|
|
158
|
+
*/
|
|
159
|
+
const extract = extract$1;
|
|
160
|
+
/**
|
|
161
|
+
* Returns the field declarations a {@link Class} or {@link Struct} was built
|
|
162
|
+
* from.
|
|
163
|
+
*
|
|
164
|
+
* **When to use**
|
|
165
|
+
*
|
|
166
|
+
* Use to build a new struct or class from the fields of an existing one.
|
|
167
|
+
*
|
|
168
|
+
* @see {@link extract} for one variant of a struct as a plain schema
|
|
169
|
+
*
|
|
170
|
+
* @stability unstable
|
|
171
|
+
* @category getters
|
|
172
|
+
* @since 0.2.0
|
|
173
|
+
*/
|
|
174
|
+
const fields = fields$1;
|
|
175
|
+
/**
|
|
176
|
+
* Defines a document schema: one field declaration, with the shapes a document
|
|
177
|
+
* is read, created and updated in derived from it.
|
|
178
|
+
*
|
|
179
|
+
* **When to use**
|
|
180
|
+
*
|
|
181
|
+
* Use to define what the documents of a collection hold. Hand the class to
|
|
182
|
+
* {@link Collection.make}, and every read and write of that collection goes
|
|
183
|
+
* through it.
|
|
184
|
+
*
|
|
185
|
+
* **Details**
|
|
186
|
+
*
|
|
187
|
+
* The class is the `read` variant: what a snapshot decodes into, and what
|
|
188
|
+
* schema combinators take. The write shapes hang off it:
|
|
189
|
+
*
|
|
190
|
+
* - {@link Class.create} is what `setDoc` and `addDoc` write, a whole document,
|
|
191
|
+
* taking the sentinels and constructor defaults its fields declare.
|
|
192
|
+
* - {@link Class.update} is what `updateDoc` writes, a nested partial encoded at
|
|
193
|
+
* field paths, taking only patches that leave any document readable.
|
|
194
|
+
* - {@link Class.updateUnchecked} also takes patches that are only right where
|
|
195
|
+
* the caller knows what the document holds - see {@link UpdateMode}.
|
|
196
|
+
*
|
|
197
|
+
* The document's id is not a field: it lives in the path.
|
|
198
|
+
*
|
|
199
|
+
* @example Defining a document and its writes
|
|
200
|
+
* ```ts
|
|
201
|
+
* import { Schema } from "effect";
|
|
202
|
+
* import {
|
|
203
|
+
* FieldValue,
|
|
204
|
+
* FirestoreModel,
|
|
205
|
+
* FirestoreSchema,
|
|
206
|
+
* } from "@visiolab/effect-firebase/firestore";
|
|
207
|
+
*
|
|
208
|
+
* class User extends FirestoreModel.Class<User>("User")({
|
|
209
|
+
* displayName: Schema.String,
|
|
210
|
+
* signupSource: FirestoreModel.Immutable(Schema.String),
|
|
211
|
+
* createdAt: FirestoreModel.Timestamp(FirestoreSchema.Timestamp),
|
|
212
|
+
* visits: FirestoreModel.Number(Schema.Int),
|
|
213
|
+
* nickname: FirestoreModel.Optional(Schema.String),
|
|
214
|
+
* }) {}
|
|
215
|
+
*
|
|
216
|
+
* User.create.make({
|
|
217
|
+
* displayName: "Ada",
|
|
218
|
+
* signupSource: "web",
|
|
219
|
+
* createdAt: FieldValue.serverTimestamp,
|
|
220
|
+
* visits: 0,
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* User.update.make({ visits: FieldValue.increment(1), nickname: FieldValue.deleteField });
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @see {@link Union} for a document that holds one of several shapes
|
|
227
|
+
* @see {@link Struct} for a nested map, or fields shared between documents
|
|
228
|
+
* @see {@link Collection.make} for the collection a document lives in
|
|
229
|
+
*
|
|
230
|
+
* @stability unstable
|
|
231
|
+
* @category constructors
|
|
232
|
+
* @since 0.2.0
|
|
233
|
+
*/
|
|
234
|
+
const Class = Class$1;
|
|
235
|
+
/**
|
|
236
|
+
* Declares a document or field that holds one of several structs or classes.
|
|
237
|
+
*
|
|
238
|
+
* **When to use**
|
|
239
|
+
*
|
|
240
|
+
* Use when documents of one collection, or one field, come in several shapes,
|
|
241
|
+
* such as the states of a job or the versions of a document, told apart by a
|
|
242
|
+
* literal field.
|
|
243
|
+
*
|
|
244
|
+
* **Details**
|
|
245
|
+
*
|
|
246
|
+
* It is Effect's own union, with no tag of this library's. A snapshot decodes
|
|
247
|
+
* into the first member that matches, so a literal field narrows it, and data
|
|
248
|
+
* matching no member fails with a schema issue. A `create` takes any member
|
|
249
|
+
* in the shape `setDoc` writes it. A value that fits several members, on
|
|
250
|
+
* `create` or in a replacement, is taken as the first in declaration order, as
|
|
251
|
+
* `Schema.Union` does.
|
|
252
|
+
*
|
|
253
|
+
* As a field, an update may:
|
|
254
|
+
*
|
|
255
|
+
* - Replace it with {@link Patch.replace} and any member, in its `create`
|
|
256
|
+
* shape. A member holding a field that `setDoc` or an update leaves out -
|
|
257
|
+
* {@link Immutable}, or a read-only field - is never replaced, as with a
|
|
258
|
+
* struct.
|
|
259
|
+
* - Remove it with {@link FieldValue.deleteField}, where it is
|
|
260
|
+
* {@link Optional}.
|
|
261
|
+
* - Patch its Shared Fields: keys every member holds, with a value every member
|
|
262
|
+
* takes and stores the same way, so the patch is right whichever member the
|
|
263
|
+
* document holds. A struct every member holds at a key is patched at its own
|
|
264
|
+
* Shared Fields. A union every member holds at a key is written by this same
|
|
265
|
+
* rule, across all of those unions. A Record is never shared.
|
|
266
|
+
* - Under `unchecked`, also patch a key only some members hold, such as
|
|
267
|
+
* `completedAt` on a job the caller knows is done. The value is checked
|
|
268
|
+
* against just those members and written at its path. An {@link Optional}
|
|
269
|
+
* union is only patched under `unchecked`.
|
|
270
|
+
*
|
|
271
|
+
* As a whole document, `setDoc` writes any member and changing member takes a
|
|
272
|
+
* whole `setDoc`. An update patches it by the same rule - see
|
|
273
|
+
* {@link UnionUpdate}.
|
|
274
|
+
*
|
|
275
|
+
* @example A field holding one of several states
|
|
276
|
+
* ```ts
|
|
277
|
+
* import { Schema } from "effect";
|
|
278
|
+
* import {
|
|
279
|
+
* FieldValue,
|
|
280
|
+
* FirestoreModel,
|
|
281
|
+
* FirestoreSchema,
|
|
282
|
+
* Patch,
|
|
283
|
+
* } from "@visiolab/effect-firebase/firestore";
|
|
284
|
+
*
|
|
285
|
+
* const Pending = FirestoreModel.Struct({ status: Schema.Literal("pending") });
|
|
286
|
+
* const Done = FirestoreModel.Struct({
|
|
287
|
+
* status: Schema.Literal("done"),
|
|
288
|
+
* completedAt: FirestoreModel.Timestamp(FirestoreSchema.Timestamp),
|
|
289
|
+
* });
|
|
290
|
+
*
|
|
291
|
+
* class Job extends FirestoreModel.Class<Job>("Job")({
|
|
292
|
+
* state: FirestoreModel.Union([Pending, Done]),
|
|
293
|
+
* }) {}
|
|
294
|
+
*
|
|
295
|
+
* Job.update.make({
|
|
296
|
+
* state: Patch.replace({ status: "done", completedAt: FieldValue.serverTimestamp }),
|
|
297
|
+
* });
|
|
298
|
+
* // Where the job is known to be done: written at "state.completedAt".
|
|
299
|
+
* Job.updateUnchecked.make({ state: { completedAt: FieldValue.serverTimestamp } });
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* @see {@link Class} for a document with a single shape
|
|
303
|
+
* @see {@link UpdateMode} for what `checked` and `unchecked` patch
|
|
304
|
+
*
|
|
305
|
+
* @stability unstable
|
|
306
|
+
* @category constructors
|
|
307
|
+
* @since 0.2.0
|
|
308
|
+
*/
|
|
309
|
+
const Union = Union$1;
|
|
310
|
+
/**
|
|
311
|
+
* Declares a field written once, when the document is created.
|
|
312
|
+
*
|
|
313
|
+
* **When to use**
|
|
314
|
+
*
|
|
315
|
+
* Use for a field that must never change after creation, such as a sign-up
|
|
316
|
+
* source or an owner id.
|
|
317
|
+
*
|
|
318
|
+
* **Details**
|
|
319
|
+
*
|
|
320
|
+
* It is read, and written by `setDoc`, but left out of `update`, so no update
|
|
321
|
+
* can change it. A struct or union member holding it is never replaced by an
|
|
322
|
+
* update, since that would rewrite it.
|
|
323
|
+
*
|
|
324
|
+
* @see {@link FieldOnly} for keeping a field to other variants
|
|
325
|
+
* @see {@link Optional} for a field that may be missing
|
|
326
|
+
*
|
|
327
|
+
* @stability unstable
|
|
328
|
+
* @category schemas
|
|
329
|
+
* @since 0.2.0
|
|
330
|
+
*/
|
|
331
|
+
const Immutable = Immutable$1;
|
|
332
|
+
/**
|
|
333
|
+
* Declares a timestamp field that the client or the server may set.
|
|
334
|
+
*
|
|
335
|
+
* **When to use**
|
|
336
|
+
*
|
|
337
|
+
* Use for a timestamp a write may leave to the server, such as `createdAt` or
|
|
338
|
+
* `updatedAt`. Where the server must never set it, use the schema itself as
|
|
339
|
+
* the field.
|
|
340
|
+
*
|
|
341
|
+
* **Details**
|
|
342
|
+
*
|
|
343
|
+
* `setDoc` and `updateDoc` take either a value of `schema` or
|
|
344
|
+
* {@link FieldValue.serverTimestamp}. A read takes `schema` alone, since the
|
|
345
|
+
* sentinel is resolved by the time a document comes back.
|
|
346
|
+
*
|
|
347
|
+
* `schema` decides what the instant is held as:
|
|
348
|
+
* {@link FirestoreSchema.Timestamp} where precision finer than a millisecond
|
|
349
|
+
* must survive a round trip, or `Schema.DateTimeUtc` or `Schema.Date` where one
|
|
350
|
+
* of those is easier to work with. Firestore stores each as a timestamp.
|
|
351
|
+
*
|
|
352
|
+
* @example Timestamps held two ways
|
|
353
|
+
* ```ts
|
|
354
|
+
* import { Schema } from "effect";
|
|
355
|
+
* import { FieldValue, FirestoreModel, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
356
|
+
*
|
|
357
|
+
* class Session extends FirestoreModel.Class<Session>("Session")({
|
|
358
|
+
* createdAt: FirestoreModel.Timestamp(FirestoreSchema.Timestamp),
|
|
359
|
+
* seenAt: FirestoreModel.Timestamp(Schema.DateTimeUtc),
|
|
360
|
+
* }) {}
|
|
361
|
+
*
|
|
362
|
+
* Session.update.make({ seenAt: FieldValue.serverTimestamp });
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* @see {@link FirestoreSchema.Timestamp} for the schema that keeps full precision
|
|
366
|
+
* @see {@link FirestoreSchema.ServerTimestampOr} for the write schema this
|
|
367
|
+
* declares
|
|
368
|
+
* @see {@link FieldValue.serverTimestamp} for the sentinel a write hands it
|
|
369
|
+
*
|
|
370
|
+
* @stability unstable
|
|
371
|
+
* @category schemas
|
|
372
|
+
* @since 0.2.0
|
|
373
|
+
*/
|
|
374
|
+
const Timestamp = Timestamp$1;
|
|
375
|
+
/**
|
|
376
|
+
* Declares a number field that a write may set or have the server increment.
|
|
377
|
+
*
|
|
378
|
+
* **When to use**
|
|
379
|
+
*
|
|
380
|
+
* Use for counters and totals more than one client may change at once: an
|
|
381
|
+
* increment keeps the total right, where reading the number and writing the
|
|
382
|
+
* sum back loses concurrent writes. Where it must never be incremented, use
|
|
383
|
+
* the schema itself as the field.
|
|
384
|
+
*
|
|
385
|
+
* **Details**
|
|
386
|
+
*
|
|
387
|
+
* `setDoc` and `updateDoc` take either a value of `schema` or
|
|
388
|
+
* {@link FieldValue.increment} / {@link FieldValue.decrement}. A read takes
|
|
389
|
+
* `schema` alone, since the document holds the sum the server computed.
|
|
390
|
+
*
|
|
391
|
+
* `schema` decides what the number may be, on both reads and writes: hand it
|
|
392
|
+
* `Schema.Int` for whole steps, or `Schema.Finite` for fractions. An increment
|
|
393
|
+
* is not checked against it, since the server computes the sum and only the
|
|
394
|
+
* next read sees it.
|
|
395
|
+
*
|
|
396
|
+
* @example A counter and a balance
|
|
397
|
+
* ```ts
|
|
398
|
+
* import { Schema } from "effect";
|
|
399
|
+
* import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
400
|
+
*
|
|
401
|
+
* class Account extends FirestoreModel.Class<Account>("Account")({
|
|
402
|
+
* visits: FirestoreModel.Number(Schema.Int),
|
|
403
|
+
* balance: FirestoreModel.Number(Schema.Finite),
|
|
404
|
+
* }) {}
|
|
405
|
+
*
|
|
406
|
+
* Account.update.make({ visits: FieldValue.increment(1) });
|
|
407
|
+
* ```
|
|
408
|
+
*
|
|
409
|
+
* @see {@link FieldValue.increment} for the sentinel a write hands it
|
|
410
|
+
* @see {@link FirestoreSchema.IncrementOr} for the write schema this declares
|
|
411
|
+
*
|
|
412
|
+
* @stability unstable
|
|
413
|
+
* @category schemas
|
|
414
|
+
* @since 0.2.0
|
|
415
|
+
*/
|
|
416
|
+
const Number = Number$1;
|
|
417
|
+
/**
|
|
418
|
+
* Declares an array field that an update may write whole, or have the server
|
|
419
|
+
* add elements to or remove elements from.
|
|
420
|
+
*
|
|
421
|
+
* **When to use**
|
|
422
|
+
*
|
|
423
|
+
* Use for an array more than one client may change at once, such as a list of
|
|
424
|
+
* tags: {@link FieldValue.arrayUnion} and {@link FieldValue.arrayRemove} keep
|
|
425
|
+
* an element another client added at the same time, where reading the array
|
|
426
|
+
* and writing it back does not.
|
|
427
|
+
*
|
|
428
|
+
* **Details**
|
|
429
|
+
*
|
|
430
|
+
* An update takes the array, `arrayUnion` or `arrayRemove`. A read takes the
|
|
431
|
+
* array alone. `setDoc` takes the array alone too: adding to a missing array
|
|
432
|
+
* writes the elements as they are, and removing from one writes it empty,
|
|
433
|
+
* which is not what was meant.
|
|
434
|
+
*
|
|
435
|
+
* Elements are matched by value, all the way down, so removing a map from the
|
|
436
|
+
* array means handing over every key it holds - see
|
|
437
|
+
* {@link FieldValue.ArrayRemove}. `item` is what each element is held as. It
|
|
438
|
+
* cannot be an array, which Firestore does not nest, or a field, since an
|
|
439
|
+
* element is always written whole.
|
|
440
|
+
*
|
|
441
|
+
* @example Adding a tag
|
|
442
|
+
* ```ts
|
|
443
|
+
* import { Schema } from "effect";
|
|
444
|
+
* import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
445
|
+
*
|
|
446
|
+
* class Article extends FirestoreModel.Class<Article>("Article")({
|
|
447
|
+
* tags: FirestoreModel.Array(Schema.String),
|
|
448
|
+
* }) {}
|
|
449
|
+
*
|
|
450
|
+
* Article.update.make({ tags: FieldValue.arrayUnion("news") });
|
|
451
|
+
* ```
|
|
452
|
+
*
|
|
453
|
+
* @see {@link FieldValue.arrayUnion} and {@link FieldValue.arrayRemove} for the
|
|
454
|
+
* sentinels an update hands it
|
|
455
|
+
* @see {@link FirestoreSchema.ArrayOr} for the update schema this declares
|
|
456
|
+
*
|
|
457
|
+
* @stability unstable
|
|
458
|
+
* @category schemas
|
|
459
|
+
* @since 0.2.0
|
|
460
|
+
*/
|
|
461
|
+
const Array = Array$1;
|
|
462
|
+
/**
|
|
463
|
+
* Declares a map field whose keys come from the data, which an update writes
|
|
464
|
+
* key by key.
|
|
465
|
+
*
|
|
466
|
+
* **When to use**
|
|
467
|
+
*
|
|
468
|
+
* Use for a map keyed by data rather than by a fixed set of fields: a counter
|
|
469
|
+
* per option, an entry per member, a lookup table. Writing key by key lets two
|
|
470
|
+
* clients each change a key of the same map without reading it first.
|
|
471
|
+
*
|
|
472
|
+
* **Details**
|
|
473
|
+
*
|
|
474
|
+
* A read and `setDoc` hold it as `Schema.Record(key, value)`, with each value
|
|
475
|
+
* in its read or create shape, so `setDoc` takes the sentinels `value` takes.
|
|
476
|
+
* An update takes a patch, writing each key it carries at its own path, in the
|
|
477
|
+
* update shape of `value`: a {@link Number} takes
|
|
478
|
+
* {@link FieldValue.increment}, an {@link Array} {@link FieldValue.arrayUnion},
|
|
479
|
+
* a {@link Timestamp} {@link FieldValue.serverTimestamp}.
|
|
480
|
+
*
|
|
481
|
+
* - Where `key` is a string, refined or not, any key may be missing, so each
|
|
482
|
+
* takes {@link FieldValue.deleteField}. A value that is itself a struct or
|
|
483
|
+
* Record is treated like an {@link Optional} struct: written whole with
|
|
484
|
+
* {@link Patch.replace} or removed, and only patched by
|
|
485
|
+
* {@link Class.updateUnchecked}.
|
|
486
|
+
* - Where `key` is a union of literals, the Record holds every key, and an
|
|
487
|
+
* update treats it as a struct with a field per key: no key is removed
|
|
488
|
+
* unless `value` is {@link Optional}.
|
|
489
|
+
*
|
|
490
|
+
* Either way, it takes {@link Patch.replace} to be written whole, unless
|
|
491
|
+
* `value` holds a field `setDoc` or an update leaves out.
|
|
492
|
+
*
|
|
493
|
+
* A key's path is the key as `key` encodes it, so the update requires any
|
|
494
|
+
* service `key` needs to encode. A key no path can name - empty, or containing
|
|
495
|
+
* a `.` - fails the update when it is encoded, or throws when the Record is
|
|
496
|
+
* declared if it is a literal. A value no update writes, such as
|
|
497
|
+
* {@link Immutable}, leaves the whole Record out of the update.
|
|
498
|
+
*
|
|
499
|
+
* @example Patching keys of a map
|
|
500
|
+
* ```ts
|
|
501
|
+
* import { Schema } from "effect";
|
|
502
|
+
* import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
503
|
+
*
|
|
504
|
+
* class Poll extends FirestoreModel.Class<Poll>("Poll")({
|
|
505
|
+
* votes: FirestoreModel.Record(Schema.String, FirestoreModel.Number(Schema.Int)),
|
|
506
|
+
* aliases: FirestoreModel.Record(Schema.String, Schema.String),
|
|
507
|
+
* }) {}
|
|
508
|
+
*
|
|
509
|
+
* Poll.update.make({
|
|
510
|
+
* votes: { pizza: FieldValue.increment(1) }, // "votes.pizza"
|
|
511
|
+
* aliases: { old: FieldValue.deleteField }, // "aliases.old"
|
|
512
|
+
* });
|
|
513
|
+
* ```
|
|
514
|
+
*
|
|
515
|
+
* @see {@link Struct} for a map with a fixed set of fields
|
|
516
|
+
*
|
|
517
|
+
* @stability unstable
|
|
518
|
+
* @category schemas
|
|
519
|
+
* @since 0.2.0
|
|
520
|
+
*/
|
|
521
|
+
const Record = Record$1;
|
|
522
|
+
/**
|
|
523
|
+
* Declares a field a document may go without, and an update may remove.
|
|
524
|
+
*
|
|
525
|
+
* **When to use**
|
|
526
|
+
*
|
|
527
|
+
* Use for a field that may be missing from a document. Wrap any schema, field,
|
|
528
|
+
* struct, union or {@link Record} in it.
|
|
529
|
+
*
|
|
530
|
+
* **Details**
|
|
531
|
+
*
|
|
532
|
+
* A read and `setDoc` hold it as an optional key: a missing field is left out
|
|
533
|
+
* rather than stored as `null`. An update also takes
|
|
534
|
+
* {@link FieldValue.deleteField}, since leaving a field out of an update leaves
|
|
535
|
+
* it as it is. Inside a struct, an optional field is removed the same way, at
|
|
536
|
+
* its path.
|
|
537
|
+
*
|
|
538
|
+
* A field with no `update` variant, such as {@link Immutable}, becomes optional
|
|
539
|
+
* where it is read and created, and stays out of the update. Making a field
|
|
540
|
+
* optional twice is the same as once.
|
|
541
|
+
*
|
|
542
|
+
* An optional struct is where the stored document decides what a patch does: a
|
|
543
|
+
* patch written into a missing struct creates it holding only the patch, and
|
|
544
|
+
* the document no longer reads. So {@link Class.update} writes it whole with
|
|
545
|
+
* {@link Patch.replace} or removes it, and only {@link Class.updateUnchecked}
|
|
546
|
+
* patches it, for a caller who knows it is there.
|
|
547
|
+
*
|
|
548
|
+
* @example Optional fields
|
|
549
|
+
* ```ts
|
|
550
|
+
* import { Schema } from "effect";
|
|
551
|
+
* import { FirestoreModel, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
552
|
+
*
|
|
553
|
+
* const Address = FirestoreModel.Struct({ city: Schema.String });
|
|
554
|
+
*
|
|
555
|
+
* class User extends FirestoreModel.Class<User>("User")({
|
|
556
|
+
* nickname: FirestoreModel.Optional(Schema.String),
|
|
557
|
+
* lastSeenAt: FirestoreModel.Optional(FirestoreModel.Timestamp(FirestoreSchema.Timestamp)),
|
|
558
|
+
* address: FirestoreModel.Optional(Address),
|
|
559
|
+
* }) {}
|
|
560
|
+
* ```
|
|
561
|
+
*
|
|
562
|
+
* @example Updating an optional struct
|
|
563
|
+
* ```ts
|
|
564
|
+
* import { Schema } from "effect";
|
|
565
|
+
* import { FieldValue, FirestoreModel, Patch } from "@visiolab/effect-firebase/firestore";
|
|
566
|
+
*
|
|
567
|
+
* const Address = FirestoreModel.Struct({ city: Schema.String, zip: Schema.String });
|
|
568
|
+
*
|
|
569
|
+
* class Customer extends FirestoreModel.Class<Customer>("Customer")({
|
|
570
|
+
* address: FirestoreModel.Optional(Address),
|
|
571
|
+
* }) {}
|
|
572
|
+
*
|
|
573
|
+
* Customer.update.make({ address: Patch.replace({ city: "Berlin", zip: "10115" }) }); // written whole
|
|
574
|
+
* Customer.update.make({ address: FieldValue.deleteField }); // removed
|
|
575
|
+
* Customer.updateUnchecked.make({ address: { city: "Berlin" } }); // the caller knows it is there
|
|
576
|
+
* ```
|
|
577
|
+
*
|
|
578
|
+
* @see {@link FieldValue.deleteField} for removing it in an update
|
|
579
|
+
* @see {@link UpdateMode} for when an optional struct may be patched
|
|
580
|
+
*
|
|
581
|
+
* @stability unstable
|
|
582
|
+
* @category schemas
|
|
583
|
+
* @since 0.2.0
|
|
584
|
+
*/
|
|
585
|
+
const Optional = Optional$1;
|
|
586
|
+
export { Array, Class, Field, FieldExcept, FieldOnly, FirestoreModel_exports, Immutable, Number, Optional, Record, Struct, Timestamp, Union, extract, fieldEvolve, fields };
|