@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,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentinels: values Firestore resolves when a write lands.
|
|
3
|
+
*
|
|
4
|
+
* In place of a value, a write can ask the server for its current time, to
|
|
5
|
+
* move a number, to delete a field, or to add or remove array elements. The
|
|
6
|
+
* server resolves each sentinel when it applies the write, so a document read
|
|
7
|
+
* back never holds one.
|
|
8
|
+
*
|
|
9
|
+
* Each sentinel here is portable: a Firestore Value that each SDK package
|
|
10
|
+
* turns into its own SDK's sentinel. Hand one to a field whose model accepts
|
|
11
|
+
* it, which the {@link FirestoreModel} field helpers and the
|
|
12
|
+
* {@link FirestoreSchema} `*Or` schemas do.
|
|
13
|
+
*
|
|
14
|
+
* | Sentinel | Schema | Model field |
|
|
15
|
+
* | --- | --- | --- |
|
|
16
|
+
* | {@link serverTimestamp} | {@link FirestoreSchema.ServerTimestampOr} | {@link FirestoreModel.Timestamp} |
|
|
17
|
+
* | {@link increment}, {@link decrement} | {@link FirestoreSchema.IncrementOr} | {@link FirestoreModel.Number} |
|
|
18
|
+
* | {@link deleteField} | {@link FirestoreSchema.DeleteFieldOr} | {@link FirestoreModel.Optional} |
|
|
19
|
+
* | {@link arrayUnion}, {@link arrayRemove} | {@link FirestoreSchema.ArrayOr} | {@link FirestoreModel.Array} |
|
|
20
|
+
*
|
|
21
|
+
* @stability unstable
|
|
22
|
+
* @since 0.2.0
|
|
23
|
+
*/
|
|
24
|
+
import type { Equal, Inspectable } from "effect";
|
|
25
|
+
import * as fieldValue from "./internal/fieldValue.ts";
|
|
26
|
+
|
|
27
|
+
const ServerTimestampTypeId = fieldValue.ServerTimestampTypeId;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The sentinel for the time the server applies the write. Its only value is
|
|
31
|
+
* {@link serverTimestamp}.
|
|
32
|
+
*
|
|
33
|
+
* @stability unstable
|
|
34
|
+
* @category models
|
|
35
|
+
* @since 0.2.0
|
|
36
|
+
*/
|
|
37
|
+
export interface ServerTimestamp extends Inspectable.Inspectable {
|
|
38
|
+
readonly [ServerTimestampTypeId]: typeof ServerTimestampTypeId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Asks the server to write the time it applies the write.
|
|
43
|
+
*
|
|
44
|
+
* **When to use**
|
|
45
|
+
*
|
|
46
|
+
* Use for fields such as `createdAt` and `updatedAt` that every client should
|
|
47
|
+
* agree on. The local clock differs between clients, the server's does not.
|
|
48
|
+
*
|
|
49
|
+
* **Details**
|
|
50
|
+
*
|
|
51
|
+
* It carries nothing, so there is only this one value. The field reads back as
|
|
52
|
+
* the timestamp the server wrote.
|
|
53
|
+
*
|
|
54
|
+
* @example Stamping a document with the server's time
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { Schema } from "effect";
|
|
57
|
+
* import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
58
|
+
*
|
|
59
|
+
* class Post extends FirestoreModel.Class<Post>("Post")({
|
|
60
|
+
* updatedAt: FirestoreModel.Timestamp(Schema.DateTimeUtc),
|
|
61
|
+
* }) {}
|
|
62
|
+
*
|
|
63
|
+
* Post.update.make({ updatedAt: FieldValue.serverTimestamp });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see {@link Timestamp.now} for the local time instead
|
|
67
|
+
* @see {@link FirestoreModel.Timestamp} for a model field that accepts it
|
|
68
|
+
* @see {@link FirestoreSchema.ServerTimestampOr} for a schema that accepts it
|
|
69
|
+
* @see {@link FirestoreSchema.ServerTimestamp} for a schema that always writes it
|
|
70
|
+
*
|
|
71
|
+
* @stability unstable
|
|
72
|
+
* @category constructors
|
|
73
|
+
* @since 0.2.0
|
|
74
|
+
*/
|
|
75
|
+
export const serverTimestamp: ServerTimestamp = fieldValue.serverTimestamp;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Checks whether `u` is the {@link ServerTimestamp} sentinel.
|
|
79
|
+
*
|
|
80
|
+
* @stability unstable
|
|
81
|
+
* @category guards
|
|
82
|
+
* @since 0.2.0
|
|
83
|
+
*/
|
|
84
|
+
export const isServerTimestamp: (u: unknown) => u is ServerTimestamp = fieldValue.isServerTimestamp;
|
|
85
|
+
|
|
86
|
+
const IncrementTypeId = fieldValue.IncrementTypeId;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The sentinel for a number the server moves by `by`. Built by
|
|
90
|
+
* {@link increment} and {@link decrement}.
|
|
91
|
+
*
|
|
92
|
+
* **Details**
|
|
93
|
+
*
|
|
94
|
+
* The server adds `by` to what the field holds. A field that holds no number,
|
|
95
|
+
* or is missing, counts as zero. Two sentinels are equal when their `by` is.
|
|
96
|
+
*
|
|
97
|
+
* @stability unstable
|
|
98
|
+
* @category models
|
|
99
|
+
* @since 0.2.0
|
|
100
|
+
*/
|
|
101
|
+
export interface Increment extends Equal.Equal, Inspectable.Inspectable {
|
|
102
|
+
readonly [IncrementTypeId]: typeof IncrementTypeId;
|
|
103
|
+
/** How far the field moves; negative to lower it. */
|
|
104
|
+
readonly by: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Checks whether `u` is an {@link Increment} sentinel.
|
|
109
|
+
*
|
|
110
|
+
* @stability unstable
|
|
111
|
+
* @category guards
|
|
112
|
+
* @since 0.2.0
|
|
113
|
+
*/
|
|
114
|
+
export const isIncrement: (u: unknown) => u is Increment = fieldValue.isIncrement;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Asks the server to raise a number field by `by`.
|
|
118
|
+
*
|
|
119
|
+
* **When to use**
|
|
120
|
+
*
|
|
121
|
+
* Use for counters and totals that several clients may change at once. Two
|
|
122
|
+
* clients that each read a number and write back the sum lose one of the
|
|
123
|
+
* changes; two increments do not.
|
|
124
|
+
*
|
|
125
|
+
* **Details**
|
|
126
|
+
*
|
|
127
|
+
* Throws unless `by` is a finite number. Integers and doubles both work; an
|
|
128
|
+
* integer added to a double gives a double. A field that holds no number, or
|
|
129
|
+
* is missing, counts as zero.
|
|
130
|
+
*
|
|
131
|
+
* @example Counting a visit
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { Schema } from "effect";
|
|
134
|
+
* import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
135
|
+
*
|
|
136
|
+
* class Page extends FirestoreModel.Class<Page>("Page")({
|
|
137
|
+
* visits: FirestoreModel.Number(Schema.Int),
|
|
138
|
+
* }) {}
|
|
139
|
+
*
|
|
140
|
+
* Page.update.make({ visits: FieldValue.increment(1) });
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @see {@link decrement} for lowering a field
|
|
144
|
+
* @see {@link FirestoreModel.Number} for a model field that accepts it
|
|
145
|
+
* @see {@link FirestoreSchema.IncrementOr} for a schema that accepts it
|
|
146
|
+
*
|
|
147
|
+
* @stability unstable
|
|
148
|
+
* @category constructors
|
|
149
|
+
* @since 0.2.0
|
|
150
|
+
*/
|
|
151
|
+
export const increment: (by: number) => Increment = fieldValue.increment;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Asks the server to lower a number field by `by`.
|
|
155
|
+
*
|
|
156
|
+
* **When to use**
|
|
157
|
+
*
|
|
158
|
+
* Use where the code counts down, so it reads that way rather than as an
|
|
159
|
+
* increment by a negative number.
|
|
160
|
+
*
|
|
161
|
+
* **Details**
|
|
162
|
+
*
|
|
163
|
+
* It is {@link increment} of `-by`: `decrement(2).by` is `-2`.
|
|
164
|
+
*
|
|
165
|
+
* @see {@link increment} for raising a field
|
|
166
|
+
*
|
|
167
|
+
* @stability unstable
|
|
168
|
+
* @category constructors
|
|
169
|
+
* @since 0.2.0
|
|
170
|
+
*/
|
|
171
|
+
export const decrement: (by: number) => Increment = fieldValue.decrement;
|
|
172
|
+
|
|
173
|
+
const DeleteFieldTypeId = fieldValue.DeleteFieldTypeId;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The sentinel for a field an update removes. Its only value is
|
|
177
|
+
* {@link deleteField}.
|
|
178
|
+
*
|
|
179
|
+
* @stability unstable
|
|
180
|
+
* @category models
|
|
181
|
+
* @since 0.2.0
|
|
182
|
+
*/
|
|
183
|
+
export interface DeleteField extends Inspectable.Inspectable {
|
|
184
|
+
readonly [DeleteFieldTypeId]: typeof DeleteFieldTypeId;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Asks the server to remove a field.
|
|
189
|
+
*
|
|
190
|
+
* **When to use**
|
|
191
|
+
*
|
|
192
|
+
* Use in an update to remove an optional field. Leaving a field out of an
|
|
193
|
+
* update keeps it as it is, so removing one has to be asked for.
|
|
194
|
+
*
|
|
195
|
+
* **Details**
|
|
196
|
+
*
|
|
197
|
+
* After the write, the document has no key at all for the field, not one
|
|
198
|
+
* holding `null`. Only an update accepts it: a document written whole with
|
|
199
|
+
* `setDoc` drops a field by leaving it out, and Firestore refuses the sentinel
|
|
200
|
+
* there.
|
|
201
|
+
*
|
|
202
|
+
* It carries nothing, so there is only this one value. It is not called
|
|
203
|
+
* `delete` because that is a reserved word in JavaScript, which is also why the
|
|
204
|
+
* client SDK calls its own `deleteField`.
|
|
205
|
+
*
|
|
206
|
+
* @example Removing an optional field
|
|
207
|
+
* ```ts
|
|
208
|
+
* import { Schema } from "effect";
|
|
209
|
+
* import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
210
|
+
*
|
|
211
|
+
* class User extends FirestoreModel.Class<User>("User")({
|
|
212
|
+
* nickname: FirestoreModel.Optional(Schema.String),
|
|
213
|
+
* }) {}
|
|
214
|
+
*
|
|
215
|
+
* User.update.make({ nickname: FieldValue.deleteField });
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @see {@link FirestoreModel.Optional} for a model field that accepts it
|
|
219
|
+
* @see {@link FirestoreSchema.DeleteFieldOr} for a schema that accepts it
|
|
220
|
+
*
|
|
221
|
+
* @stability unstable
|
|
222
|
+
* @category constructors
|
|
223
|
+
* @since 0.2.0
|
|
224
|
+
*/
|
|
225
|
+
export const deleteField: DeleteField = fieldValue.deleteField;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Checks whether `u` is the {@link DeleteField} sentinel.
|
|
229
|
+
*
|
|
230
|
+
* @stability unstable
|
|
231
|
+
* @category guards
|
|
232
|
+
* @since 0.2.0
|
|
233
|
+
*/
|
|
234
|
+
export const isDeleteField: (u: unknown) => u is DeleteField = fieldValue.isDeleteField;
|
|
235
|
+
|
|
236
|
+
const ArrayUnionTypeId = fieldValue.ArrayUnionTypeId;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* The sentinel for an array the server adds `elements` to. Built by
|
|
240
|
+
* {@link arrayUnion}.
|
|
241
|
+
*
|
|
242
|
+
* **Details**
|
|
243
|
+
*
|
|
244
|
+
* The server appends each element the array does not already hold. It compares
|
|
245
|
+
* by value, all the way down: a map matches one with the same keys holding the
|
|
246
|
+
* same values, whatever their order. A field that holds no array, or is
|
|
247
|
+
* missing, ends up holding just `elements`.
|
|
248
|
+
*
|
|
249
|
+
* @stability unstable
|
|
250
|
+
* @category models
|
|
251
|
+
* @since 0.2.0
|
|
252
|
+
*/
|
|
253
|
+
export interface ArrayUnion<A> extends Inspectable.Inspectable {
|
|
254
|
+
readonly [ArrayUnionTypeId]: typeof ArrayUnionTypeId;
|
|
255
|
+
/** The elements to add, in the order they are appended. */
|
|
256
|
+
readonly elements: ReadonlyArray<A>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Checks whether `u` is an {@link ArrayUnion} sentinel.
|
|
261
|
+
*
|
|
262
|
+
* @stability unstable
|
|
263
|
+
* @category guards
|
|
264
|
+
* @since 0.2.0
|
|
265
|
+
*/
|
|
266
|
+
export const isArrayUnion: (u: unknown) => u is ArrayUnion<unknown> = fieldValue.isArrayUnion;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Asks the server to add `elements` to an array, skipping any it holds already.
|
|
270
|
+
*
|
|
271
|
+
* **When to use**
|
|
272
|
+
*
|
|
273
|
+
* Use to add to an array that several clients may change at once. A client
|
|
274
|
+
* that reads the array, adds an element and writes it back loses whatever
|
|
275
|
+
* another client added in between; `arrayUnion` does not.
|
|
276
|
+
*
|
|
277
|
+
* **Details**
|
|
278
|
+
*
|
|
279
|
+
* Elements are compared by value, as {@link ArrayUnion} describes. With no
|
|
280
|
+
* elements it changes nothing, except that a field that held no array ends up
|
|
281
|
+
* holding an empty one.
|
|
282
|
+
*
|
|
283
|
+
* @example Adding a tag
|
|
284
|
+
* ```ts
|
|
285
|
+
* import { Schema } from "effect";
|
|
286
|
+
* import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
287
|
+
*
|
|
288
|
+
* class Article extends FirestoreModel.Class<Article>("Article")({
|
|
289
|
+
* tags: FirestoreModel.Array(Schema.String),
|
|
290
|
+
* }) {}
|
|
291
|
+
*
|
|
292
|
+
* Article.update.make({ tags: FieldValue.arrayUnion("news") });
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @see {@link arrayRemove} for removing elements
|
|
296
|
+
* @see {@link FirestoreModel.Array} for a model field that accepts it
|
|
297
|
+
* @see {@link FirestoreSchema.ArrayOr} for a schema that accepts it
|
|
298
|
+
*
|
|
299
|
+
* @stability unstable
|
|
300
|
+
* @category constructors
|
|
301
|
+
* @since 0.2.0
|
|
302
|
+
*/
|
|
303
|
+
export const arrayUnion: <A>(...elements: ReadonlyArray<A>) => ArrayUnion<A> =
|
|
304
|
+
fieldValue.arrayUnion;
|
|
305
|
+
|
|
306
|
+
const ArrayRemoveTypeId = fieldValue.ArrayRemoveTypeId;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* The sentinel for an array the server removes `elements` from. Built by
|
|
310
|
+
* {@link arrayRemove}.
|
|
311
|
+
*
|
|
312
|
+
* **Details**
|
|
313
|
+
*
|
|
314
|
+
* The server drops every element equal to one of `elements`. The match is by
|
|
315
|
+
* value, as for {@link ArrayUnion}, and exact: an element with an extra key, or
|
|
316
|
+
* a different number, is a different element and stays. To remove a map from
|
|
317
|
+
* an array you must pass every key it holds, with the same values. Where
|
|
318
|
+
* elements have an id of their own, a map keyed by that id is easier to remove
|
|
319
|
+
* from. A field that holds no array, or is missing, ends up holding an empty
|
|
320
|
+
* one.
|
|
321
|
+
*
|
|
322
|
+
* @stability unstable
|
|
323
|
+
* @category models
|
|
324
|
+
* @since 0.2.0
|
|
325
|
+
*/
|
|
326
|
+
export interface ArrayRemove<A> extends Inspectable.Inspectable {
|
|
327
|
+
readonly [ArrayRemoveTypeId]: typeof ArrayRemoveTypeId;
|
|
328
|
+
/** The elements to remove, wherever they are in the array. */
|
|
329
|
+
readonly elements: ReadonlyArray<A>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Checks whether `u` is an {@link ArrayRemove} sentinel.
|
|
334
|
+
*
|
|
335
|
+
* @stability unstable
|
|
336
|
+
* @category guards
|
|
337
|
+
* @since 0.2.0
|
|
338
|
+
*/
|
|
339
|
+
export const isArrayRemove: (u: unknown) => u is ArrayRemove<unknown> = fieldValue.isArrayRemove;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Asks the server to remove every element equal to one of `elements` from an
|
|
343
|
+
* array.
|
|
344
|
+
*
|
|
345
|
+
* **When to use**
|
|
346
|
+
*
|
|
347
|
+
* Use to remove from an array that several clients may change at once, keeping
|
|
348
|
+
* whatever they add in the meantime.
|
|
349
|
+
*
|
|
350
|
+
* **Details**
|
|
351
|
+
*
|
|
352
|
+
* The match is exact, as {@link ArrayRemove} describes.
|
|
353
|
+
*
|
|
354
|
+
* @example Removing a tag
|
|
355
|
+
* ```ts
|
|
356
|
+
* import { Schema } from "effect";
|
|
357
|
+
* import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
|
|
358
|
+
*
|
|
359
|
+
* class Article extends FirestoreModel.Class<Article>("Article")({
|
|
360
|
+
* tags: FirestoreModel.Array(Schema.String),
|
|
361
|
+
* }) {}
|
|
362
|
+
*
|
|
363
|
+
* Article.update.make({ tags: FieldValue.arrayRemove("draft") });
|
|
364
|
+
* ```
|
|
365
|
+
*
|
|
366
|
+
* @see {@link arrayUnion} for adding elements
|
|
367
|
+
* @see {@link FirestoreModel.Array} for a model field that accepts it
|
|
368
|
+
* @see {@link FirestoreSchema.ArrayOr} for a schema that accepts it
|
|
369
|
+
*
|
|
370
|
+
* @stability unstable
|
|
371
|
+
* @category constructors
|
|
372
|
+
* @since 0.2.0
|
|
373
|
+
*/
|
|
374
|
+
export const arrayRemove: <A>(...elements: ReadonlyArray<A>) => ArrayRemove<A> =
|
|
375
|
+
fieldValue.arrayRemove;
|