@visiolab/effect-firebase 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +66 -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,567 @@
|
|
|
1
|
+
import { DocumentPath as DocumentPath$1 } from "./DocumentPath.mjs";
|
|
2
|
+
import { ArrayRemove as ArrayRemove$1, ArrayUnion as ArrayUnion$1, DeleteField as DeleteField$1, Increment as Increment$1, ServerTimestamp as ServerTimestamp$1 } from "./FieldValue.mjs";
|
|
3
|
+
import { GeoPoint as GeoPoint$1 } from "./GeoPoint.mjs";
|
|
4
|
+
import { Timestamp as Timestamp$1 } from "./Timestamp.mjs";
|
|
5
|
+
import { Any, DocumentReference as DocumentReference$1 } from "./Collection.mjs";
|
|
6
|
+
import { DateTime, Schema } from "effect";
|
|
7
|
+
declare namespace FirestoreSchema_d_exports {
|
|
8
|
+
export { ArrayOr, ArrayRemove, ArrayUnion, DeleteField, DeleteFieldOr, DocumentPath, DocumentReference, GeoPoint, Increment, IncrementOr, ServerTimestamp, ServerTimestampOr, TimeSchema, Timestamp };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Type-level representation of {@link Timestamp}.
|
|
12
|
+
*
|
|
13
|
+
* @stability unstable
|
|
14
|
+
* @category models
|
|
15
|
+
* @since 0.2.0
|
|
16
|
+
*/
|
|
17
|
+
export interface Timestamp extends Schema.declare<Timestamp$1> {
|
|
18
|
+
readonly Rebuild: Timestamp;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Schema for a Firestore timestamp, held as the portable
|
|
22
|
+
* {@link Timestamp.Timestamp}.
|
|
23
|
+
*
|
|
24
|
+
* **When to use**
|
|
25
|
+
*
|
|
26
|
+
* Use when a document is read, written back, and has to come out unchanged.
|
|
27
|
+
* Use `Schema.DateTimeUtc` or `Schema.Date` when a millisecond is precise
|
|
28
|
+
* enough and that value is easier to work with: Firestore stores both as a
|
|
29
|
+
* timestamp too, but they drop the digits finer than a millisecond.
|
|
30
|
+
*
|
|
31
|
+
* **Details**
|
|
32
|
+
*
|
|
33
|
+
* It serializes with `Schema.toCodecJson` as `{ seconds, nanoseconds }`, so the
|
|
34
|
+
* same model can be sent over HTTP.
|
|
35
|
+
*
|
|
36
|
+
* @example Storing a timestamp at full precision
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { Schema } from "effect";
|
|
39
|
+
* import { FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
40
|
+
*
|
|
41
|
+
* const Event = Schema.Struct({ at: FirestoreSchema.Timestamp });
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @see {@link FirestoreModel.Timestamp} for a timestamp field the server may also fill in
|
|
45
|
+
* @see {@link ServerTimestampOr} for the write side of such a field
|
|
46
|
+
* @see {@link TimeSchema} for every schema Firestore stores as a timestamp
|
|
47
|
+
*
|
|
48
|
+
* @stability unstable
|
|
49
|
+
* @category schemas
|
|
50
|
+
* @since 0.2.0
|
|
51
|
+
*/
|
|
52
|
+
export declare const Timestamp: Timestamp;
|
|
53
|
+
/**
|
|
54
|
+
* A schema Firestore stores as a timestamp: {@link Timestamp},
|
|
55
|
+
* `Schema.DateTimeUtc`, `Schema.Date`, or any schema transformed into one of
|
|
56
|
+
* them.
|
|
57
|
+
*
|
|
58
|
+
* **Details**
|
|
59
|
+
*
|
|
60
|
+
* The check is on the encoded type alone, so it accepts any schema whose
|
|
61
|
+
* encoded side is a {@link Timestamp.Timestamp}, a `DateTime.Utc` or a `Date`.
|
|
62
|
+
* A declaration of your own, such as `Schema.declare<Date>(...)`, type-checks
|
|
63
|
+
* but is not stored as a timestamp: {@link FirestoreValue.toCodecFirestore}
|
|
64
|
+
* only stores `Schema.Date` and `Schema.DateTimeUtc` as one, so it fails to
|
|
65
|
+
* encode, or is written through its own `toCodecJson`. The types cannot tell
|
|
66
|
+
* the two apart, since `Schema.Date` has the same type as any
|
|
67
|
+
* `Schema.declare<Date>`.
|
|
68
|
+
*
|
|
69
|
+
* @see {@link ServerTimestampOr} for a timestamp the server may fill in
|
|
70
|
+
* @see {@link FirestoreModel.Timestamp} for the matching model field
|
|
71
|
+
*
|
|
72
|
+
* @stability unstable
|
|
73
|
+
* @category models
|
|
74
|
+
* @since 0.2.0
|
|
75
|
+
*/
|
|
76
|
+
export type TimeSchema = Schema.Codec<unknown, Timestamp$1 | DateTime.Utc | globalThis.Date, unknown, unknown>;
|
|
77
|
+
/**
|
|
78
|
+
* Type-level representation of {@link GeoPoint}.
|
|
79
|
+
*
|
|
80
|
+
* @stability unstable
|
|
81
|
+
* @category models
|
|
82
|
+
* @since 0.2.0
|
|
83
|
+
*/
|
|
84
|
+
export interface GeoPoint extends Schema.declare<GeoPoint$1> {
|
|
85
|
+
readonly Rebuild: GeoPoint;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Schema for a Firestore geopoint, held as the portable
|
|
89
|
+
* {@link GeoPoint.GeoPoint}.
|
|
90
|
+
*
|
|
91
|
+
* **When to use**
|
|
92
|
+
*
|
|
93
|
+
* Use for a location field. A hand-written struct of `latitude` and
|
|
94
|
+
* `longitude` would be stored as a map; this schema is stored as Firestore's
|
|
95
|
+
* own geopoint.
|
|
96
|
+
*
|
|
97
|
+
* @example Storing a location
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { Schema } from "effect";
|
|
100
|
+
* import { FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
101
|
+
*
|
|
102
|
+
* const Place = Schema.Struct({ name: Schema.String, location: FirestoreSchema.GeoPoint });
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @see {@link GeoPoint.make} for building a geopoint
|
|
106
|
+
*
|
|
107
|
+
* @stability unstable
|
|
108
|
+
* @category schemas
|
|
109
|
+
* @since 0.2.0
|
|
110
|
+
*/
|
|
111
|
+
export declare const GeoPoint: GeoPoint;
|
|
112
|
+
/**
|
|
113
|
+
* Type-level representation of {@link DocumentPath}.
|
|
114
|
+
*
|
|
115
|
+
* @stability unstable
|
|
116
|
+
* @category models
|
|
117
|
+
* @since 0.2.0
|
|
118
|
+
*/
|
|
119
|
+
export interface DocumentPath extends Schema.declare<DocumentPath$1> {
|
|
120
|
+
readonly Rebuild: DocumentPath;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Schema for an untyped reference to a document, held as the portable
|
|
124
|
+
* {@link DocumentPath.DocumentPath}.
|
|
125
|
+
*
|
|
126
|
+
* **When to use**
|
|
127
|
+
*
|
|
128
|
+
* Use for a reference whose target collection the model does not know. Use
|
|
129
|
+
* {@link DocumentReference} when the field always points into a known
|
|
130
|
+
* collection.
|
|
131
|
+
*
|
|
132
|
+
* **Details**
|
|
133
|
+
*
|
|
134
|
+
* It is stored as the SDK's own reference, built against the database the
|
|
135
|
+
* document is written to.
|
|
136
|
+
*
|
|
137
|
+
* @see {@link DocumentReference} for a reference typed by its collection
|
|
138
|
+
*
|
|
139
|
+
* @stability unstable
|
|
140
|
+
* @category schemas
|
|
141
|
+
* @since 0.2.0
|
|
142
|
+
*/
|
|
143
|
+
export declare const DocumentPath: DocumentPath;
|
|
144
|
+
/**
|
|
145
|
+
* Type-level representation of {@link DocumentReference}.
|
|
146
|
+
*
|
|
147
|
+
* @stability unstable
|
|
148
|
+
* @category models
|
|
149
|
+
* @since 0.2.0
|
|
150
|
+
*/
|
|
151
|
+
export interface DocumentReference<C extends Any> extends Schema.declare<DocumentReference$1<C>> {
|
|
152
|
+
readonly Rebuild: DocumentReference<C>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Schema for a reference to a document in `collection`, held as a typed
|
|
156
|
+
* {@link Collection.DocumentReference}.
|
|
157
|
+
*
|
|
158
|
+
* **When to use**
|
|
159
|
+
*
|
|
160
|
+
* Use for a field that points to a document in a known collection, so the
|
|
161
|
+
* reference keeps its ids and model typed. For a field that may point into
|
|
162
|
+
* several collections, use a `Schema.Union` of one of these per collection.
|
|
163
|
+
* Use {@link DocumentPath} when the target collection is unknown.
|
|
164
|
+
*
|
|
165
|
+
* **Details**
|
|
166
|
+
*
|
|
167
|
+
* Firestore stores a reference as the document's path alone, so it is written
|
|
168
|
+
* as a {@link DocumentPath.DocumentPath}. Reading it back checks the path
|
|
169
|
+
* against the collection's segments and rebuilds the collection's own
|
|
170
|
+
* reference, equal to one built from `collection`. A path into any other
|
|
171
|
+
* collection, even one with the same last segment, fails to decode.
|
|
172
|
+
* `Schema.is` only accepts references built from `collection`.
|
|
173
|
+
*
|
|
174
|
+
* @example Referencing the author of a post
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { Schema } from "effect";
|
|
177
|
+
* import { Collection, FirestoreModel, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
178
|
+
*
|
|
179
|
+
* class User extends FirestoreModel.Class<User>("User")({ name: Schema.String }) {}
|
|
180
|
+
* const Users = Collection.make("users", User);
|
|
181
|
+
*
|
|
182
|
+
* class Post extends FirestoreModel.Class<Post>("Post")({
|
|
183
|
+
* author: FirestoreSchema.DocumentReference(Users),
|
|
184
|
+
* }) {}
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @see {@link DocumentPath} for an untyped reference
|
|
188
|
+
*
|
|
189
|
+
* @stability unstable
|
|
190
|
+
* @category schemas
|
|
191
|
+
* @since 0.2.0
|
|
192
|
+
*/
|
|
193
|
+
export declare const DocumentReference: <C extends Any>(collection: C) => DocumentReference<C>;
|
|
194
|
+
interface ServerTimestampSentinel extends Schema.declare<ServerTimestamp$1> {
|
|
195
|
+
readonly Rebuild: ServerTimestampSentinel;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Type-level representation of {@link ServerTimestamp}.
|
|
199
|
+
*
|
|
200
|
+
* @stability unstable
|
|
201
|
+
* @category models
|
|
202
|
+
* @since 0.2.0
|
|
203
|
+
*/
|
|
204
|
+
export interface ServerTimestamp extends Schema.withConstructorDefault<ServerTimestampSentinel> {
|
|
205
|
+
readonly Rebuild: ServerTimestamp;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Schema that always writes the {@link FieldValue.serverTimestamp} sentinel,
|
|
209
|
+
* and fills it in when the value is constructed.
|
|
210
|
+
*
|
|
211
|
+
* **When to use**
|
|
212
|
+
*
|
|
213
|
+
* Use in a write-only schema for a field that is always the server's time,
|
|
214
|
+
* such as `updatedAt` on every update. Use {@link ServerTimestampOr} when the
|
|
215
|
+
* field may also be written with a time of your own.
|
|
216
|
+
*
|
|
217
|
+
* **Details**
|
|
218
|
+
*
|
|
219
|
+
* It accepts only the sentinel, and its constructor default fills it in, the
|
|
220
|
+
* way `Schema.tag` fills in a tag, so a call site never names the field. A
|
|
221
|
+
* document never holds the sentinel: the field reads back as the timestamp the
|
|
222
|
+
* server wrote, so the read side is a timestamp schema.
|
|
223
|
+
*
|
|
224
|
+
* @example Stamping every update with the server's time
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { Schema } from "effect";
|
|
227
|
+
* import { FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
228
|
+
*
|
|
229
|
+
* const Touch = Schema.Struct({ updatedAt: FirestoreSchema.ServerTimestamp });
|
|
230
|
+
*
|
|
231
|
+
* const update = Touch.make({}); // { updatedAt: FieldValue.serverTimestamp }
|
|
232
|
+
* ```
|
|
233
|
+
*
|
|
234
|
+
* @see {@link ServerTimestampOr} for a field that may also take a time of your own
|
|
235
|
+
* @see {@link FirestoreModel.Timestamp} for the matching model field
|
|
236
|
+
*
|
|
237
|
+
* @stability unstable
|
|
238
|
+
* @category schemas
|
|
239
|
+
* @since 0.2.0
|
|
240
|
+
*/
|
|
241
|
+
export declare const ServerTimestamp: ServerTimestamp;
|
|
242
|
+
/**
|
|
243
|
+
* Type-level representation of {@link ServerTimestampOr}.
|
|
244
|
+
*
|
|
245
|
+
* @stability unstable
|
|
246
|
+
* @category models
|
|
247
|
+
* @since 0.2.0
|
|
248
|
+
*/
|
|
249
|
+
export interface ServerTimestampOr<S extends TimeSchema> extends Schema.Union<readonly [S, ServerTimestamp]> {
|
|
250
|
+
readonly Rebuild: ServerTimestampOr<S>;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Schema for a timestamp field written either as a time of your own or as
|
|
254
|
+
* {@link FieldValue.serverTimestamp}.
|
|
255
|
+
*
|
|
256
|
+
* **When to use**
|
|
257
|
+
*
|
|
258
|
+
* Use as the write side of a timestamp field when building model variants by
|
|
259
|
+
* hand. Most models use {@link FirestoreModel.Timestamp}, which pairs this with
|
|
260
|
+
* the read side for you.
|
|
261
|
+
*
|
|
262
|
+
* **Details**
|
|
263
|
+
*
|
|
264
|
+
* `schema` is the read side: {@link Timestamp} to keep digits finer than a
|
|
265
|
+
* millisecond, or `Schema.DateTimeUtc` or `Schema.Date` (see
|
|
266
|
+
* {@link TimeSchema}). A read never sees the sentinel, so the read variant
|
|
267
|
+
* uses `schema` alone.
|
|
268
|
+
*
|
|
269
|
+
* @example A timestamp the server may fill in
|
|
270
|
+
* ```ts
|
|
271
|
+
* import { Schema } from "effect";
|
|
272
|
+
* import { FieldValue, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
273
|
+
*
|
|
274
|
+
* const UpdatedAt = FirestoreSchema.ServerTimestampOr(Schema.DateTimeUtc);
|
|
275
|
+
*
|
|
276
|
+
* Schema.is(UpdatedAt)(FieldValue.serverTimestamp); // true
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @see {@link FirestoreModel.Timestamp} for the model field built on it
|
|
280
|
+
* @see {@link ServerTimestamp} for a field that always writes the sentinel
|
|
281
|
+
* @see {@link FieldValue.serverTimestamp} for the sentinel itself
|
|
282
|
+
*
|
|
283
|
+
* @stability unstable
|
|
284
|
+
* @category schemas
|
|
285
|
+
* @since 0.2.0
|
|
286
|
+
*/
|
|
287
|
+
export declare const ServerTimestampOr: <S extends TimeSchema>(schema: S) => ServerTimestampOr<S>;
|
|
288
|
+
/**
|
|
289
|
+
* Type-level representation of {@link Increment}.
|
|
290
|
+
*
|
|
291
|
+
* @stability unstable
|
|
292
|
+
* @category models
|
|
293
|
+
* @since 0.2.0
|
|
294
|
+
*/
|
|
295
|
+
export interface Increment extends Schema.declare<Increment$1> {
|
|
296
|
+
readonly Rebuild: Increment;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Schema for the {@link FieldValue.Increment} sentinel, as built by
|
|
300
|
+
* {@link FieldValue.increment} and {@link FieldValue.decrement}.
|
|
301
|
+
*
|
|
302
|
+
* **When to use**
|
|
303
|
+
*
|
|
304
|
+
* Use in a write-only schema for a field that is only ever moved, never set.
|
|
305
|
+
* Use {@link IncrementOr} for a field that may be set outright too.
|
|
306
|
+
*
|
|
307
|
+
* **Details**
|
|
308
|
+
*
|
|
309
|
+
* A document holds the sum the server wrote, so the read side of the same
|
|
310
|
+
* field is a plain number.
|
|
311
|
+
*
|
|
312
|
+
* @see {@link IncrementOr} for a number that may also be set outright
|
|
313
|
+
* @see {@link FirestoreModel.Number} for the matching model field
|
|
314
|
+
*
|
|
315
|
+
* @stability unstable
|
|
316
|
+
* @category schemas
|
|
317
|
+
* @since 0.2.0
|
|
318
|
+
*/
|
|
319
|
+
export declare const Increment: Increment;
|
|
320
|
+
/**
|
|
321
|
+
* Type-level representation of {@link IncrementOr}.
|
|
322
|
+
*
|
|
323
|
+
* @stability unstable
|
|
324
|
+
* @category models
|
|
325
|
+
* @since 0.2.0
|
|
326
|
+
*/
|
|
327
|
+
export interface IncrementOr<S extends Schema.Codec<unknown, number, unknown, unknown>> extends Schema.Union<readonly [S, Increment]> {
|
|
328
|
+
readonly Rebuild: IncrementOr<S>;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Schema for a number field written either as a number or as an
|
|
332
|
+
* {@link FieldValue.increment} or {@link FieldValue.decrement}.
|
|
333
|
+
*
|
|
334
|
+
* **When to use**
|
|
335
|
+
*
|
|
336
|
+
* Use as the write side of a counter when building model variants by hand.
|
|
337
|
+
* Most models use {@link FirestoreModel.Number}, which pairs this with the
|
|
338
|
+
* read side for you.
|
|
339
|
+
*
|
|
340
|
+
* **Details**
|
|
341
|
+
*
|
|
342
|
+
* `schema` is the read side and says what the number may be: `Schema.Finite`,
|
|
343
|
+
* `Schema.Int` for whole steps, or either with further checks. It must be
|
|
344
|
+
* stored as a number, since that is what the server adds to. A read never sees
|
|
345
|
+
* the sentinel, so the read variant uses `schema` alone.
|
|
346
|
+
*
|
|
347
|
+
* @example A counter the server may move
|
|
348
|
+
* ```ts
|
|
349
|
+
* import { Schema } from "effect";
|
|
350
|
+
* import { FieldValue, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
351
|
+
*
|
|
352
|
+
* const Visits = FirestoreSchema.IncrementOr(Schema.Int);
|
|
353
|
+
*
|
|
354
|
+
* Schema.is(Visits)(FieldValue.increment(1)); // true
|
|
355
|
+
* ```
|
|
356
|
+
*
|
|
357
|
+
* @see {@link FirestoreModel.Number} for the model field built on it
|
|
358
|
+
* @see {@link Increment} for a field that is only ever moved
|
|
359
|
+
* @see {@link FieldValue.increment} for the sentinel itself
|
|
360
|
+
*
|
|
361
|
+
* @stability unstable
|
|
362
|
+
* @category schemas
|
|
363
|
+
* @since 0.2.0
|
|
364
|
+
*/
|
|
365
|
+
export declare const IncrementOr: <S extends Schema.Codec<unknown, number, unknown, unknown>>(schema: S) => IncrementOr<S>;
|
|
366
|
+
/**
|
|
367
|
+
* Type-level representation of {@link DeleteField}.
|
|
368
|
+
*
|
|
369
|
+
* @stability unstable
|
|
370
|
+
* @category models
|
|
371
|
+
* @since 0.2.0
|
|
372
|
+
*/
|
|
373
|
+
export interface DeleteField extends Schema.declare<DeleteField$1> {
|
|
374
|
+
readonly Rebuild: DeleteField;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Schema for the {@link FieldValue.deleteField} sentinel.
|
|
378
|
+
*
|
|
379
|
+
* **When to use**
|
|
380
|
+
*
|
|
381
|
+
* Use when building an update schema by hand. Most models get it through
|
|
382
|
+
* {@link DeleteFieldOr}, or through {@link FirestoreModel.Optional}.
|
|
383
|
+
*
|
|
384
|
+
* **Details**
|
|
385
|
+
*
|
|
386
|
+
* Unlike {@link ServerTimestamp}, it has no constructor default: a field is
|
|
387
|
+
* only removed when you ask for it. A removed field is not there to read, so
|
|
388
|
+
* the read side of the same field is an optional key.
|
|
389
|
+
*
|
|
390
|
+
* @see {@link DeleteFieldOr} for a field an update may write or remove
|
|
391
|
+
* @see {@link FirestoreModel.Optional} for the matching model field
|
|
392
|
+
*
|
|
393
|
+
* @stability unstable
|
|
394
|
+
* @category schemas
|
|
395
|
+
* @since 0.2.0
|
|
396
|
+
*/
|
|
397
|
+
export declare const DeleteField: DeleteField;
|
|
398
|
+
/**
|
|
399
|
+
* Type-level representation of {@link DeleteFieldOr}.
|
|
400
|
+
*
|
|
401
|
+
* @stability unstable
|
|
402
|
+
* @category models
|
|
403
|
+
* @since 0.2.0
|
|
404
|
+
*/
|
|
405
|
+
export interface DeleteFieldOr<S extends Schema.Top> extends Schema.Union<readonly [DeleteField, S]> {
|
|
406
|
+
readonly Rebuild: DeleteFieldOr<S>;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Schema for a field an update either writes or removes with
|
|
410
|
+
* {@link FieldValue.deleteField}.
|
|
411
|
+
*
|
|
412
|
+
* **When to use**
|
|
413
|
+
*
|
|
414
|
+
* Use as the update side of an optional field when building model variants by
|
|
415
|
+
* hand. Most models use {@link FirestoreModel.Optional}, which does this for
|
|
416
|
+
* you.
|
|
417
|
+
*
|
|
418
|
+
* **Details**
|
|
419
|
+
*
|
|
420
|
+
* `schema` is what the field holds while it is there. Only an update accepts
|
|
421
|
+
* it: a read never holds the sentinel, and Firestore refuses it in a document
|
|
422
|
+
* written whole.
|
|
423
|
+
*
|
|
424
|
+
* The sentinel is tried first, since a schema that accepts any object, such
|
|
425
|
+
* as a struct whose keys are all optional, would accept it too and strip it to
|
|
426
|
+
* `{}`.
|
|
427
|
+
*
|
|
428
|
+
* @example An optional field an update may remove
|
|
429
|
+
* ```ts
|
|
430
|
+
* import { Schema } from "effect";
|
|
431
|
+
* import { FieldValue, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
432
|
+
*
|
|
433
|
+
* const Nickname = FirestoreSchema.DeleteFieldOr(Schema.String);
|
|
434
|
+
*
|
|
435
|
+
* Schema.is(Nickname)(FieldValue.deleteField); // true
|
|
436
|
+
* ```
|
|
437
|
+
*
|
|
438
|
+
* @see {@link FirestoreModel.Optional} for the model field built on it
|
|
439
|
+
* @see {@link FieldValue.deleteField} for the sentinel itself
|
|
440
|
+
*
|
|
441
|
+
* @stability unstable
|
|
442
|
+
* @category schemas
|
|
443
|
+
* @since 0.2.0
|
|
444
|
+
*/
|
|
445
|
+
export declare const DeleteFieldOr: <S extends Schema.Top>(schema: S) => DeleteFieldOr<S>;
|
|
446
|
+
/**
|
|
447
|
+
* Type-level representation of {@link ArrayUnion}.
|
|
448
|
+
*
|
|
449
|
+
* @stability unstable
|
|
450
|
+
* @category models
|
|
451
|
+
* @since 0.2.0
|
|
452
|
+
*/
|
|
453
|
+
export interface ArrayUnion<S extends Schema.Top> extends Schema.declareConstructor<ArrayUnion$1<S["Type"]>, ArrayUnion$1<S["Encoded"]>, readonly [S]> {
|
|
454
|
+
readonly Rebuild: ArrayUnion<S>;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Schema for the {@link FieldValue.arrayUnion} sentinel, with each element
|
|
458
|
+
* encoded through `item`.
|
|
459
|
+
*
|
|
460
|
+
* **When to use**
|
|
461
|
+
*
|
|
462
|
+
* Use when building an update schema by hand. Most models get it through
|
|
463
|
+
* {@link ArrayOr}, or through {@link FirestoreModel.Array}.
|
|
464
|
+
*
|
|
465
|
+
* **Details**
|
|
466
|
+
*
|
|
467
|
+
* Each element is encoded through `item`, then stored the way
|
|
468
|
+
* {@link FirestoreValue.toCodecFirestore} stores `item`, so a `DateTimeUtc`
|
|
469
|
+
* among them is stored as a timestamp, and an element `item` rejects is
|
|
470
|
+
* rejected here too.
|
|
471
|
+
*
|
|
472
|
+
* Firestore requires two things of `item`: it is not an array itself, since
|
|
473
|
+
* arrays may not nest, and it does not write a sentinel, since one may not sit
|
|
474
|
+
* inside an array.
|
|
475
|
+
*
|
|
476
|
+
* A document holds the array the server wrote, so the read side of the same
|
|
477
|
+
* field is the array.
|
|
478
|
+
*
|
|
479
|
+
* @see {@link ArrayRemove} for removing elements
|
|
480
|
+
* @see {@link ArrayOr} for an array field written whole, grown or shrunk
|
|
481
|
+
*
|
|
482
|
+
* @stability unstable
|
|
483
|
+
* @category schemas
|
|
484
|
+
* @since 0.2.0
|
|
485
|
+
*/
|
|
486
|
+
export declare const ArrayUnion: <S extends Schema.Top>(item: S) => ArrayUnion<S>;
|
|
487
|
+
/**
|
|
488
|
+
* Type-level representation of {@link ArrayRemove}.
|
|
489
|
+
*
|
|
490
|
+
* @stability unstable
|
|
491
|
+
* @category models
|
|
492
|
+
* @since 0.2.0
|
|
493
|
+
*/
|
|
494
|
+
export interface ArrayRemove<S extends Schema.Top> extends Schema.declareConstructor<ArrayRemove$1<S["Type"]>, ArrayRemove$1<S["Encoded"]>, readonly [S]> {
|
|
495
|
+
readonly Rebuild: ArrayRemove<S>;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Schema for the {@link FieldValue.arrayRemove} sentinel, with each element
|
|
499
|
+
* encoded through `item`.
|
|
500
|
+
*
|
|
501
|
+
* **When to use**
|
|
502
|
+
*
|
|
503
|
+
* Use when building an update schema by hand. Most models get it through
|
|
504
|
+
* {@link ArrayOr}, or through {@link FirestoreModel.Array}.
|
|
505
|
+
*
|
|
506
|
+
* **Details**
|
|
507
|
+
*
|
|
508
|
+
* Each element is encoded through `item`, as for {@link ArrayUnion}. Encode
|
|
509
|
+
* through the same schema the array was written with: the server only removes
|
|
510
|
+
* elements that match exactly.
|
|
511
|
+
*
|
|
512
|
+
* @see {@link ArrayUnion} for adding elements
|
|
513
|
+
* @see {@link ArrayOr} for an array field written whole, grown or shrunk
|
|
514
|
+
*
|
|
515
|
+
* @stability unstable
|
|
516
|
+
* @category schemas
|
|
517
|
+
* @since 0.2.0
|
|
518
|
+
*/
|
|
519
|
+
export declare const ArrayRemove: <S extends Schema.Top>(item: S) => ArrayRemove<S>;
|
|
520
|
+
/**
|
|
521
|
+
* Type-level representation of {@link ArrayOr}.
|
|
522
|
+
*
|
|
523
|
+
* @stability unstable
|
|
524
|
+
* @category models
|
|
525
|
+
* @since 0.2.0
|
|
526
|
+
*/
|
|
527
|
+
export interface ArrayOr<S extends Schema.Top> extends Schema.Union<readonly [Schema.$Array<S>, ArrayUnion<S>, ArrayRemove<S>]> {
|
|
528
|
+
readonly Rebuild: ArrayOr<S>;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Schema for an array field written whole, or grown or shrunk by the server
|
|
532
|
+
* with {@link FieldValue.arrayUnion} and {@link FieldValue.arrayRemove}.
|
|
533
|
+
*
|
|
534
|
+
* **When to use**
|
|
535
|
+
*
|
|
536
|
+
* Use as the update side of an array of `item` when building model variants by
|
|
537
|
+
* hand, against a read of `Schema.Array(item)`. Most models use
|
|
538
|
+
* {@link FirestoreModel.Array}, which pairs the two for you.
|
|
539
|
+
*
|
|
540
|
+
* **Details**
|
|
541
|
+
*
|
|
542
|
+
* Writing the array whole replaces what the server holds, so a client that
|
|
543
|
+
* read it, added an element and wrote it back loses whatever another client
|
|
544
|
+
* added in between. Growing or shrinking it does not. A read never sees the
|
|
545
|
+
* sentinels, so the read variant is the array alone.
|
|
546
|
+
*
|
|
547
|
+
* @example An array the server may grow or shrink
|
|
548
|
+
* ```ts
|
|
549
|
+
* import { Schema } from "effect";
|
|
550
|
+
* import { FieldValue, FirestoreSchema } from "@visiolab/effect-firebase/firestore";
|
|
551
|
+
*
|
|
552
|
+
* const Tags = FirestoreSchema.ArrayOr(Schema.String);
|
|
553
|
+
*
|
|
554
|
+
* Schema.is(Tags)(["news"]); // true
|
|
555
|
+
* Schema.is(Tags)(FieldValue.arrayUnion("news")); // true
|
|
556
|
+
* ```
|
|
557
|
+
*
|
|
558
|
+
* @see {@link FirestoreModel.Array} for the model field built on it
|
|
559
|
+
* @see {@link ArrayUnion} for the growing sentinel's schema
|
|
560
|
+
* @see {@link ArrayRemove} for the shrinking sentinel's schema
|
|
561
|
+
*
|
|
562
|
+
* @stability unstable
|
|
563
|
+
* @category schemas
|
|
564
|
+
* @since 0.2.0
|
|
565
|
+
*/
|
|
566
|
+
export declare const ArrayOr: <S extends Schema.Top>(item: S) => ArrayOr<S>;
|
|
567
|
+
export { FirestoreSchema_d_exports };
|