@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,239 @@
1
+ import { Any, DocumentReference, DocumentSchema, Id } from "./Collection.mjs";
2
+ import { Effect, Inspectable, Schema } from "effect";
3
+ declare namespace DocumentSnapshot_d_exports {
4
+ export { Data, DecodingServices, DocumentSnapshot, Existing, Missing, existing, isDocumentSnapshot, isExisting, isMissing, make, missing };
5
+ }
6
+ declare const TypeId = "~@visiolab/effect-firebase/firestore/DocumentSnapshot";
7
+ /**
8
+ * What a document in `C` decodes into: the `read` variant of its model.
9
+ *
10
+ * @stability unstable
11
+ * @category models
12
+ * @since 0.2.0
13
+ */
14
+ export type Data<C extends Any> = DocumentSchema<C>["Type"];
15
+ /**
16
+ * The services decoding a document in `C` requires, which
17
+ * {@link Existing.data} asks for.
18
+ *
19
+ * @stability unstable
20
+ * @category models
21
+ * @since 0.2.0
22
+ */
23
+ export type DecodingServices<C extends Any> = DocumentSchema<C>["DecodingServices"];
24
+ /**
25
+ * A snapshot of a document that was there when it was read.
26
+ *
27
+ * **Details**
28
+ *
29
+ * Its tag is `"Existing"`. {@link Existing.data} decodes what it held through
30
+ * the collection's model. Every document of a {@link QuerySnapshot.QuerySnapshot}
31
+ * is one of these.
32
+ *
33
+ * @see {@link Missing} for a document that was not there
34
+ * @see {@link isExisting} for narrowing a {@link DocumentSnapshot} to this
35
+ *
36
+ * @stability unstable
37
+ * @category models
38
+ * @since 0.2.0
39
+ */
40
+ export interface Existing<C extends Any> extends Inspectable.Inspectable {
41
+ readonly [TypeId]: typeof TypeId;
42
+ readonly _tag: "Existing";
43
+ /** The reference the document was read at. */
44
+ readonly ref: DocumentReference<C>;
45
+ /** The document's own id, the same as `ref.id`. */
46
+ readonly id: Id<C>;
47
+ /**
48
+ * The document's data as the SDK read it, before the collection's model has
49
+ * decoded it.
50
+ *
51
+ * **Details**
52
+ *
53
+ * It is what the document held at the time of the read. Do not change it: a
54
+ * snapshot is a record of that read, not a handle on the document.
55
+ *
56
+ * @see {@link Existing.data} for the decoded data
57
+ */
58
+ readonly raw: unknown;
59
+ /**
60
+ * Decodes {@link Existing.raw} through the collection's model.
61
+ *
62
+ * **Details**
63
+ *
64
+ * Nothing is decoded until this runs, and it decodes again on each run.
65
+ * Fails with a `Schema.SchemaError` when the data does not match the model.
66
+ */
67
+ readonly data: Effect.Effect<Data<C>, Schema.SchemaError, DecodingServices<C>>;
68
+ }
69
+ /**
70
+ * A snapshot of a document that was not there when it was read.
71
+ *
72
+ * **Details**
73
+ *
74
+ * Its tag is `"Missing"`. It holds no data, so a missing document is never
75
+ * confused with one that failed to decode.
76
+ *
77
+ * @see {@link Existing} for a document that was there
78
+ * @see {@link isMissing} for narrowing a {@link DocumentSnapshot} to this
79
+ *
80
+ * @stability unstable
81
+ * @category models
82
+ * @since 0.2.0
83
+ */
84
+ export interface Missing<C extends Any> extends Inspectable.Inspectable {
85
+ readonly [TypeId]: typeof TypeId;
86
+ readonly _tag: "Missing";
87
+ /** The reference the document was read at. */
88
+ readonly ref: DocumentReference<C>;
89
+ /** The document's own id, the same as `ref.id`. */
90
+ readonly id: Id<C>;
91
+ }
92
+ /**
93
+ * A document in `C` as a read found it: {@link Existing} or {@link Missing}.
94
+ *
95
+ * **Details**
96
+ *
97
+ * {@link Firestore.With.getDoc} and {@link Firestore.With.streamDoc} return
98
+ * one. A missing document is a result, not a failure. Tell the two apart with
99
+ * {@link isExisting} or {@link isMissing}, or by `_tag`.
100
+ *
101
+ * @see {@link QuerySnapshot.QuerySnapshot} for the result of a read of many documents
102
+ *
103
+ * @stability unstable
104
+ * @category models
105
+ * @since 0.2.0
106
+ */
107
+ export type DocumentSnapshot<C extends Any> = Existing<C> | Missing<C>;
108
+ /**
109
+ * Checks whether a value is a {@link DocumentSnapshot}, existing or missing.
110
+ *
111
+ * @see {@link isExisting} and {@link isMissing} for telling the two kinds apart
112
+ * @see {@link QuerySnapshot.isQuerySnapshot} for a snapshot of many documents
113
+ *
114
+ * @stability unstable
115
+ * @category guards
116
+ * @since 0.2.0
117
+ */
118
+ export declare const isDocumentSnapshot: (u: unknown) => u is DocumentSnapshot<Any>;
119
+ /**
120
+ * Narrows a {@link DocumentSnapshot} to an {@link Existing} one.
121
+ *
122
+ * **When to use**
123
+ *
124
+ * Use after {@link Firestore.With.getDoc} to get at the data of a document
125
+ * that was there.
126
+ *
127
+ * @see {@link isMissing} for the opposite check
128
+ *
129
+ * @stability unstable
130
+ * @category guards
131
+ * @since 0.2.0
132
+ */
133
+ export declare const isExisting: <C extends Any>(self: DocumentSnapshot<C>) => self is Existing<C>;
134
+ /**
135
+ * Narrows a {@link DocumentSnapshot} to a {@link Missing} one.
136
+ *
137
+ * **When to use**
138
+ *
139
+ * Use after {@link Firestore.With.getDoc} to handle a document that was not
140
+ * there, such as returning early.
141
+ *
142
+ * @see {@link isExisting} for the opposite check
143
+ *
144
+ * @stability unstable
145
+ * @category guards
146
+ * @since 0.2.0
147
+ */
148
+ export declare const isMissing: <C extends Any>(self: DocumentSnapshot<C>) => self is Missing<C>;
149
+ /**
150
+ * Builds a snapshot of the document at `ref` from what an SDK's
151
+ * `snapshot.data()` returned: {@link Missing} for `undefined`, and
152
+ * {@link Existing} otherwise.
153
+ *
154
+ * **When to use**
155
+ *
156
+ * Use when implementing a backend or a test double, to turn an SDK snapshot
157
+ * into a portable one. Application code gets snapshots from
158
+ * {@link Firestore.With.getDoc} instead.
159
+ *
160
+ * **Details**
161
+ *
162
+ * Both SDKs return `undefined` from `data()` for a document that is not there.
163
+ * An SDK that knows more about the read, such as the client's `metadata`,
164
+ * passes it as `extra`: each of its fields is put on the snapshot and shown
165
+ * when it prints. Its fields must not have the same names as the snapshot's
166
+ * own.
167
+ *
168
+ * @example Building a snapshot with extra fields
169
+ * ```ts
170
+ * import {
171
+ * Collection,
172
+ * DocumentSnapshot,
173
+ * FirestoreModel,
174
+ * } from "@visiolab/effect-firebase/firestore";
175
+ * import { Schema } from "effect";
176
+ *
177
+ * class User extends FirestoreModel.Class<User>("User")({ name: Schema.String }) {}
178
+ *
179
+ * const Users = Collection.make("users", User);
180
+ * const ref = Users.doc(Users.id.make("alice"));
181
+ *
182
+ * const snapshot = DocumentSnapshot.make(ref, { name: "Alice" }, {
183
+ * metadata: { fromCache: false, hasPendingWrites: false },
184
+ * });
185
+ *
186
+ * snapshot.metadata.fromCache; // false
187
+ * ```
188
+ *
189
+ * @see {@link existing} for a document known to be there
190
+ * @see {@link missing} for a document known not to be there
191
+ *
192
+ * @stability unstable
193
+ * @category constructors
194
+ * @since 0.2.0
195
+ */
196
+ export declare const make: {
197
+ <C extends Any>(ref: DocumentReference<C>, data: unknown): DocumentSnapshot<C>;
198
+ <C extends Any, E extends object>(ref: DocumentReference<C>, data: unknown, extra: E): DocumentSnapshot<C> & E;
199
+ };
200
+ /**
201
+ * Builds an {@link Existing} snapshot of the document at `ref`, with the
202
+ * fields of `extra` when given, as {@link make} adds them.
203
+ *
204
+ * **When to use**
205
+ *
206
+ * Use in a backend for a document known to be there, such as each document a
207
+ * query returned.
208
+ *
209
+ * @see {@link make} for a document that may or may not be there
210
+ * @see {@link missing} for a document known not to be there
211
+ *
212
+ * @stability unstable
213
+ * @category constructors
214
+ * @since 0.2.0
215
+ */
216
+ export declare const existing: {
217
+ <C extends Any>(ref: DocumentReference<C>, data: unknown): Existing<C>;
218
+ <C extends Any, E extends object>(ref: DocumentReference<C>, data: unknown, extra: E): Existing<C> & E;
219
+ };
220
+ /**
221
+ * Builds a {@link Missing} snapshot of the document at `ref`, with the fields
222
+ * of `extra` when given, as {@link make} adds them.
223
+ *
224
+ * **When to use**
225
+ *
226
+ * Use in a backend or a test double for a document known not to be there.
227
+ *
228
+ * @see {@link make} for a document that may or may not be there
229
+ * @see {@link existing} for a document known to be there
230
+ *
231
+ * @stability unstable
232
+ * @category constructors
233
+ * @since 0.2.0
234
+ */
235
+ export declare const missing: {
236
+ <C extends Any>(ref: DocumentReference<C>): Missing<C>;
237
+ <C extends Any, E extends object>(ref: DocumentReference<C>, extra: E): Missing<C> & E;
238
+ };
239
+ export { DocumentSnapshot_d_exports };
@@ -0,0 +1,134 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { existing as existing$1, isDocumentSnapshot as isDocumentSnapshot$1, isExisting as isExisting$1, isMissing as isMissing$1, make as make$1, missing as missing$1 } from "./internal/documentSnapshot.mjs";
3
+ // src/firestore/DocumentSnapshot.ts
4
+ var DocumentSnapshot_exports = /* @__PURE__ */ __exportAll({
5
+ existing: () => existing,
6
+ isDocumentSnapshot: () => isDocumentSnapshot,
7
+ isExisting: () => isExisting,
8
+ isMissing: () => isMissing,
9
+ make: () => make,
10
+ missing: () => missing
11
+ });
12
+ /**
13
+ * Checks whether a value is a {@link DocumentSnapshot}, existing or missing.
14
+ *
15
+ * @see {@link isExisting} and {@link isMissing} for telling the two kinds apart
16
+ * @see {@link QuerySnapshot.isQuerySnapshot} for a snapshot of many documents
17
+ *
18
+ * @stability unstable
19
+ * @category guards
20
+ * @since 0.2.0
21
+ */
22
+ const isDocumentSnapshot = isDocumentSnapshot$1;
23
+ /**
24
+ * Narrows a {@link DocumentSnapshot} to an {@link Existing} one.
25
+ *
26
+ * **When to use**
27
+ *
28
+ * Use after {@link Firestore.With.getDoc} to get at the data of a document
29
+ * that was there.
30
+ *
31
+ * @see {@link isMissing} for the opposite check
32
+ *
33
+ * @stability unstable
34
+ * @category guards
35
+ * @since 0.2.0
36
+ */
37
+ const isExisting = isExisting$1;
38
+ /**
39
+ * Narrows a {@link DocumentSnapshot} to a {@link Missing} one.
40
+ *
41
+ * **When to use**
42
+ *
43
+ * Use after {@link Firestore.With.getDoc} to handle a document that was not
44
+ * there, such as returning early.
45
+ *
46
+ * @see {@link isExisting} for the opposite check
47
+ *
48
+ * @stability unstable
49
+ * @category guards
50
+ * @since 0.2.0
51
+ */
52
+ const isMissing = isMissing$1;
53
+ /**
54
+ * Builds a snapshot of the document at `ref` from what an SDK's
55
+ * `snapshot.data()` returned: {@link Missing} for `undefined`, and
56
+ * {@link Existing} otherwise.
57
+ *
58
+ * **When to use**
59
+ *
60
+ * Use when implementing a backend or a test double, to turn an SDK snapshot
61
+ * into a portable one. Application code gets snapshots from
62
+ * {@link Firestore.With.getDoc} instead.
63
+ *
64
+ * **Details**
65
+ *
66
+ * Both SDKs return `undefined` from `data()` for a document that is not there.
67
+ * An SDK that knows more about the read, such as the client's `metadata`,
68
+ * passes it as `extra`: each of its fields is put on the snapshot and shown
69
+ * when it prints. Its fields must not have the same names as the snapshot's
70
+ * own.
71
+ *
72
+ * @example Building a snapshot with extra fields
73
+ * ```ts
74
+ * import {
75
+ * Collection,
76
+ * DocumentSnapshot,
77
+ * FirestoreModel,
78
+ * } from "@visiolab/effect-firebase/firestore";
79
+ * import { Schema } from "effect";
80
+ *
81
+ * class User extends FirestoreModel.Class<User>("User")({ name: Schema.String }) {}
82
+ *
83
+ * const Users = Collection.make("users", User);
84
+ * const ref = Users.doc(Users.id.make("alice"));
85
+ *
86
+ * const snapshot = DocumentSnapshot.make(ref, { name: "Alice" }, {
87
+ * metadata: { fromCache: false, hasPendingWrites: false },
88
+ * });
89
+ *
90
+ * snapshot.metadata.fromCache; // false
91
+ * ```
92
+ *
93
+ * @see {@link existing} for a document known to be there
94
+ * @see {@link missing} for a document known not to be there
95
+ *
96
+ * @stability unstable
97
+ * @category constructors
98
+ * @since 0.2.0
99
+ */
100
+ const make = make$1;
101
+ /**
102
+ * Builds an {@link Existing} snapshot of the document at `ref`, with the
103
+ * fields of `extra` when given, as {@link make} adds them.
104
+ *
105
+ * **When to use**
106
+ *
107
+ * Use in a backend for a document known to be there, such as each document a
108
+ * query returned.
109
+ *
110
+ * @see {@link make} for a document that may or may not be there
111
+ * @see {@link missing} for a document known not to be there
112
+ *
113
+ * @stability unstable
114
+ * @category constructors
115
+ * @since 0.2.0
116
+ */
117
+ const existing = existing$1;
118
+ /**
119
+ * Builds a {@link Missing} snapshot of the document at `ref`, with the fields
120
+ * of `extra` when given, as {@link make} adds them.
121
+ *
122
+ * **When to use**
123
+ *
124
+ * Use in a backend or a test double for a document known not to be there.
125
+ *
126
+ * @see {@link make} for a document that may or may not be there
127
+ * @see {@link existing} for a document known to be there
128
+ *
129
+ * @stability unstable
130
+ * @category constructors
131
+ * @since 0.2.0
132
+ */
133
+ const missing = missing$1;
134
+ export { DocumentSnapshot_exports, existing, isDocumentSnapshot, isExisting, isMissing, make, missing };
@@ -0,0 +1,332 @@
1
+ import { Equal, Inspectable } from "effect";
2
+ declare namespace FieldValue_d_exports {
3
+ export { ArrayRemove, ArrayUnion, DeleteField, Increment, ServerTimestamp, arrayRemove, arrayUnion, decrement, deleteField, increment, isArrayRemove, isArrayUnion, isDeleteField, isIncrement, isServerTimestamp, serverTimestamp };
4
+ }
5
+ declare const ServerTimestampTypeId = "~@visiolab/effect-firebase/firestore/FieldValue/ServerTimestamp";
6
+ /**
7
+ * The sentinel for the time the server applies the write. Its only value is
8
+ * {@link serverTimestamp}.
9
+ *
10
+ * @stability unstable
11
+ * @category models
12
+ * @since 0.2.0
13
+ */
14
+ export interface ServerTimestamp extends Inspectable.Inspectable {
15
+ readonly [ServerTimestampTypeId]: typeof ServerTimestampTypeId;
16
+ }
17
+ /**
18
+ * Asks the server to write the time it applies the write.
19
+ *
20
+ * **When to use**
21
+ *
22
+ * Use for fields such as `createdAt` and `updatedAt` that every client should
23
+ * agree on. The local clock differs between clients, the server's does not.
24
+ *
25
+ * **Details**
26
+ *
27
+ * It carries nothing, so there is only this one value. The field reads back as
28
+ * the timestamp the server wrote.
29
+ *
30
+ * @example Stamping a document with the server's time
31
+ * ```ts
32
+ * import { Schema } from "effect";
33
+ * import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
34
+ *
35
+ * class Post extends FirestoreModel.Class<Post>("Post")({
36
+ * updatedAt: FirestoreModel.Timestamp(Schema.DateTimeUtc),
37
+ * }) {}
38
+ *
39
+ * Post.update.make({ updatedAt: FieldValue.serverTimestamp });
40
+ * ```
41
+ *
42
+ * @see {@link Timestamp.now} for the local time instead
43
+ * @see {@link FirestoreModel.Timestamp} for a model field that accepts it
44
+ * @see {@link FirestoreSchema.ServerTimestampOr} for a schema that accepts it
45
+ * @see {@link FirestoreSchema.ServerTimestamp} for a schema that always writes it
46
+ *
47
+ * @stability unstable
48
+ * @category constructors
49
+ * @since 0.2.0
50
+ */
51
+ export declare const serverTimestamp: ServerTimestamp;
52
+ /**
53
+ * Checks whether `u` is the {@link ServerTimestamp} sentinel.
54
+ *
55
+ * @stability unstable
56
+ * @category guards
57
+ * @since 0.2.0
58
+ */
59
+ export declare const isServerTimestamp: (u: unknown) => u is ServerTimestamp;
60
+ declare const IncrementTypeId = "~@visiolab/effect-firebase/firestore/FieldValue/Increment";
61
+ /**
62
+ * The sentinel for a number the server moves by `by`. Built by
63
+ * {@link increment} and {@link decrement}.
64
+ *
65
+ * **Details**
66
+ *
67
+ * The server adds `by` to what the field holds. A field that holds no number,
68
+ * or is missing, counts as zero. Two sentinels are equal when their `by` is.
69
+ *
70
+ * @stability unstable
71
+ * @category models
72
+ * @since 0.2.0
73
+ */
74
+ export interface Increment extends Equal.Equal, Inspectable.Inspectable {
75
+ readonly [IncrementTypeId]: typeof IncrementTypeId;
76
+ /** How far the field moves; negative to lower it. */
77
+ readonly by: number;
78
+ }
79
+ /**
80
+ * Checks whether `u` is an {@link Increment} sentinel.
81
+ *
82
+ * @stability unstable
83
+ * @category guards
84
+ * @since 0.2.0
85
+ */
86
+ export declare const isIncrement: (u: unknown) => u is Increment;
87
+ /**
88
+ * Asks the server to raise a number field by `by`.
89
+ *
90
+ * **When to use**
91
+ *
92
+ * Use for counters and totals that several clients may change at once. Two
93
+ * clients that each read a number and write back the sum lose one of the
94
+ * changes; two increments do not.
95
+ *
96
+ * **Details**
97
+ *
98
+ * Throws unless `by` is a finite number. Integers and doubles both work; an
99
+ * integer added to a double gives a double. A field that holds no number, or
100
+ * is missing, counts as zero.
101
+ *
102
+ * @example Counting a visit
103
+ * ```ts
104
+ * import { Schema } from "effect";
105
+ * import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
106
+ *
107
+ * class Page extends FirestoreModel.Class<Page>("Page")({
108
+ * visits: FirestoreModel.Number(Schema.Int),
109
+ * }) {}
110
+ *
111
+ * Page.update.make({ visits: FieldValue.increment(1) });
112
+ * ```
113
+ *
114
+ * @see {@link decrement} for lowering a field
115
+ * @see {@link FirestoreModel.Number} for a model field that accepts it
116
+ * @see {@link FirestoreSchema.IncrementOr} for a schema that accepts it
117
+ *
118
+ * @stability unstable
119
+ * @category constructors
120
+ * @since 0.2.0
121
+ */
122
+ export declare const increment: (by: number) => Increment;
123
+ /**
124
+ * Asks the server to lower a number field by `by`.
125
+ *
126
+ * **When to use**
127
+ *
128
+ * Use where the code counts down, so it reads that way rather than as an
129
+ * increment by a negative number.
130
+ *
131
+ * **Details**
132
+ *
133
+ * It is {@link increment} of `-by`: `decrement(2).by` is `-2`.
134
+ *
135
+ * @see {@link increment} for raising a field
136
+ *
137
+ * @stability unstable
138
+ * @category constructors
139
+ * @since 0.2.0
140
+ */
141
+ export declare const decrement: (by: number) => Increment;
142
+ declare const DeleteFieldTypeId = "~@visiolab/effect-firebase/firestore/FieldValue/DeleteField";
143
+ /**
144
+ * The sentinel for a field an update removes. Its only value is
145
+ * {@link deleteField}.
146
+ *
147
+ * @stability unstable
148
+ * @category models
149
+ * @since 0.2.0
150
+ */
151
+ export interface DeleteField extends Inspectable.Inspectable {
152
+ readonly [DeleteFieldTypeId]: typeof DeleteFieldTypeId;
153
+ }
154
+ /**
155
+ * Asks the server to remove a field.
156
+ *
157
+ * **When to use**
158
+ *
159
+ * Use in an update to remove an optional field. Leaving a field out of an
160
+ * update keeps it as it is, so removing one has to be asked for.
161
+ *
162
+ * **Details**
163
+ *
164
+ * After the write, the document has no key at all for the field, not one
165
+ * holding `null`. Only an update accepts it: a document written whole with
166
+ * `setDoc` drops a field by leaving it out, and Firestore refuses the sentinel
167
+ * there.
168
+ *
169
+ * It carries nothing, so there is only this one value. It is not called
170
+ * `delete` because that is a reserved word in JavaScript, which is also why the
171
+ * client SDK calls its own `deleteField`.
172
+ *
173
+ * @example Removing an optional field
174
+ * ```ts
175
+ * import { Schema } from "effect";
176
+ * import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
177
+ *
178
+ * class User extends FirestoreModel.Class<User>("User")({
179
+ * nickname: FirestoreModel.Optional(Schema.String),
180
+ * }) {}
181
+ *
182
+ * User.update.make({ nickname: FieldValue.deleteField });
183
+ * ```
184
+ *
185
+ * @see {@link FirestoreModel.Optional} for a model field that accepts it
186
+ * @see {@link FirestoreSchema.DeleteFieldOr} for a schema that accepts it
187
+ *
188
+ * @stability unstable
189
+ * @category constructors
190
+ * @since 0.2.0
191
+ */
192
+ export declare const deleteField: DeleteField;
193
+ /**
194
+ * Checks whether `u` is the {@link DeleteField} sentinel.
195
+ *
196
+ * @stability unstable
197
+ * @category guards
198
+ * @since 0.2.0
199
+ */
200
+ export declare const isDeleteField: (u: unknown) => u is DeleteField;
201
+ declare const ArrayUnionTypeId = "~@visiolab/effect-firebase/firestore/FieldValue/ArrayUnion";
202
+ /**
203
+ * The sentinel for an array the server adds `elements` to. Built by
204
+ * {@link arrayUnion}.
205
+ *
206
+ * **Details**
207
+ *
208
+ * The server appends each element the array does not already hold. It compares
209
+ * by value, all the way down: a map matches one with the same keys holding the
210
+ * same values, whatever their order. A field that holds no array, or is
211
+ * missing, ends up holding just `elements`.
212
+ *
213
+ * @stability unstable
214
+ * @category models
215
+ * @since 0.2.0
216
+ */
217
+ export interface ArrayUnion<A> extends Inspectable.Inspectable {
218
+ readonly [ArrayUnionTypeId]: typeof ArrayUnionTypeId;
219
+ /** The elements to add, in the order they are appended. */
220
+ readonly elements: ReadonlyArray<A>;
221
+ }
222
+ /**
223
+ * Checks whether `u` is an {@link ArrayUnion} sentinel.
224
+ *
225
+ * @stability unstable
226
+ * @category guards
227
+ * @since 0.2.0
228
+ */
229
+ export declare const isArrayUnion: (u: unknown) => u is ArrayUnion<unknown>;
230
+ /**
231
+ * Asks the server to add `elements` to an array, skipping any it holds already.
232
+ *
233
+ * **When to use**
234
+ *
235
+ * Use to add to an array that several clients may change at once. A client
236
+ * that reads the array, adds an element and writes it back loses whatever
237
+ * another client added in between; `arrayUnion` does not.
238
+ *
239
+ * **Details**
240
+ *
241
+ * Elements are compared by value, as {@link ArrayUnion} describes. With no
242
+ * elements it changes nothing, except that a field that held no array ends up
243
+ * holding an empty one.
244
+ *
245
+ * @example Adding a tag
246
+ * ```ts
247
+ * import { Schema } from "effect";
248
+ * import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
249
+ *
250
+ * class Article extends FirestoreModel.Class<Article>("Article")({
251
+ * tags: FirestoreModel.Array(Schema.String),
252
+ * }) {}
253
+ *
254
+ * Article.update.make({ tags: FieldValue.arrayUnion("news") });
255
+ * ```
256
+ *
257
+ * @see {@link arrayRemove} for removing elements
258
+ * @see {@link FirestoreModel.Array} for a model field that accepts it
259
+ * @see {@link FirestoreSchema.ArrayOr} for a schema that accepts it
260
+ *
261
+ * @stability unstable
262
+ * @category constructors
263
+ * @since 0.2.0
264
+ */
265
+ export declare const arrayUnion: <A>(...elements: ReadonlyArray<A>) => ArrayUnion<A>;
266
+ declare const ArrayRemoveTypeId = "~@visiolab/effect-firebase/firestore/FieldValue/ArrayRemove";
267
+ /**
268
+ * The sentinel for an array the server removes `elements` from. Built by
269
+ * {@link arrayRemove}.
270
+ *
271
+ * **Details**
272
+ *
273
+ * The server drops every element equal to one of `elements`. The match is by
274
+ * value, as for {@link ArrayUnion}, and exact: an element with an extra key, or
275
+ * a different number, is a different element and stays. To remove a map from
276
+ * an array you must pass every key it holds, with the same values. Where
277
+ * elements have an id of their own, a map keyed by that id is easier to remove
278
+ * from. A field that holds no array, or is missing, ends up holding an empty
279
+ * one.
280
+ *
281
+ * @stability unstable
282
+ * @category models
283
+ * @since 0.2.0
284
+ */
285
+ export interface ArrayRemove<A> extends Inspectable.Inspectable {
286
+ readonly [ArrayRemoveTypeId]: typeof ArrayRemoveTypeId;
287
+ /** The elements to remove, wherever they are in the array. */
288
+ readonly elements: ReadonlyArray<A>;
289
+ }
290
+ /**
291
+ * Checks whether `u` is an {@link ArrayRemove} sentinel.
292
+ *
293
+ * @stability unstable
294
+ * @category guards
295
+ * @since 0.2.0
296
+ */
297
+ export declare const isArrayRemove: (u: unknown) => u is ArrayRemove<unknown>;
298
+ /**
299
+ * Asks the server to remove every element equal to one of `elements` from an
300
+ * array.
301
+ *
302
+ * **When to use**
303
+ *
304
+ * Use to remove from an array that several clients may change at once, keeping
305
+ * whatever they add in the meantime.
306
+ *
307
+ * **Details**
308
+ *
309
+ * The match is exact, as {@link ArrayRemove} describes.
310
+ *
311
+ * @example Removing a tag
312
+ * ```ts
313
+ * import { Schema } from "effect";
314
+ * import { FieldValue, FirestoreModel } from "@visiolab/effect-firebase/firestore";
315
+ *
316
+ * class Article extends FirestoreModel.Class<Article>("Article")({
317
+ * tags: FirestoreModel.Array(Schema.String),
318
+ * }) {}
319
+ *
320
+ * Article.update.make({ tags: FieldValue.arrayRemove("draft") });
321
+ * ```
322
+ *
323
+ * @see {@link arrayUnion} for adding elements
324
+ * @see {@link FirestoreModel.Array} for a model field that accepts it
325
+ * @see {@link FirestoreSchema.ArrayOr} for a schema that accepts it
326
+ *
327
+ * @stability unstable
328
+ * @category constructors
329
+ * @since 0.2.0
330
+ */
331
+ export declare const arrayRemove: <A>(...elements: ReadonlyArray<A>) => ArrayRemove<A>;
332
+ export { FieldValue_d_exports };