firesmelt 0.1.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 +437 -0
- package/dist/admin.d.ts +11 -0
- package/dist/admin.js +236 -0
- package/dist/admin.js.map +1 -0
- package/dist/chunk-WEVOVXQQ.js +565 -0
- package/dist/chunk-WEVOVXQQ.js.map +1 -0
- package/dist/index.d.ts +355 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/web.d.ts +11 -0
- package/dist/web.js +252 -0
- package/dist/web.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
|
|
3
|
+
interface Timestamp {
|
|
4
|
+
readonly seconds: number;
|
|
5
|
+
readonly nanoseconds: number;
|
|
6
|
+
toDate(): Date;
|
|
7
|
+
toMillis(): number;
|
|
8
|
+
isEqual(other: Timestamp): boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function isTimestampLike(value: unknown): value is Timestamp;
|
|
11
|
+
interface GeoPoint {
|
|
12
|
+
readonly latitude: number;
|
|
13
|
+
readonly longitude: number;
|
|
14
|
+
isEqual(other: GeoPoint): boolean;
|
|
15
|
+
}
|
|
16
|
+
interface DocumentReference {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly path: string;
|
|
19
|
+
}
|
|
20
|
+
interface VectorValue {
|
|
21
|
+
toArray(): number[];
|
|
22
|
+
isEqual(other: VectorValue): boolean;
|
|
23
|
+
}
|
|
24
|
+
declare abstract class Sentinel {
|
|
25
|
+
abstract readonly kind: string;
|
|
26
|
+
}
|
|
27
|
+
declare class ServerTimestampSentinel extends Sentinel {
|
|
28
|
+
readonly kind = "serverTimestamp";
|
|
29
|
+
}
|
|
30
|
+
declare class IncrementSentinel extends Sentinel {
|
|
31
|
+
readonly by: number;
|
|
32
|
+
readonly kind = "increment";
|
|
33
|
+
constructor(by: number);
|
|
34
|
+
}
|
|
35
|
+
declare class ArrayUnionSentinel<E = unknown> extends Sentinel {
|
|
36
|
+
readonly values: ReadonlyArray<E>;
|
|
37
|
+
readonly kind = "arrayUnion";
|
|
38
|
+
constructor(values: ReadonlyArray<E>);
|
|
39
|
+
}
|
|
40
|
+
declare class ArrayRemoveSentinel<E = unknown> extends Sentinel {
|
|
41
|
+
readonly values: ReadonlyArray<E>;
|
|
42
|
+
readonly kind = "arrayRemove";
|
|
43
|
+
constructor(values: ReadonlyArray<E>);
|
|
44
|
+
}
|
|
45
|
+
declare class DeleteFieldSentinel extends Sentinel {
|
|
46
|
+
readonly kind = "deleteField";
|
|
47
|
+
}
|
|
48
|
+
declare function serverTimestamp(): ServerTimestampSentinel;
|
|
49
|
+
declare function increment(by: number): IncrementSentinel;
|
|
50
|
+
declare function arrayUnion<E>(...values: Array<E>): ArrayUnionSentinel<E>;
|
|
51
|
+
declare function arrayRemove<E>(...values: Array<E>): ArrayRemoveSentinel<E>;
|
|
52
|
+
declare function deleteField(): DeleteFieldSentinel;
|
|
53
|
+
declare class DocumentIdRef {
|
|
54
|
+
readonly kind = "documentId";
|
|
55
|
+
}
|
|
56
|
+
declare function documentId(): DocumentIdRef;
|
|
57
|
+
|
|
58
|
+
interface CollectionDef<S extends StandardSchemaV1 = StandardSchemaV1> {
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly schema: S;
|
|
61
|
+
readonly raw?: readonly string[];
|
|
62
|
+
}
|
|
63
|
+
type InferOutput<S extends StandardSchemaV1> = StandardSchemaV1.InferOutput<S>;
|
|
64
|
+
type Doc<S extends StandardSchemaV1> = InferOutput<S> & {
|
|
65
|
+
id: string;
|
|
66
|
+
};
|
|
67
|
+
type Primitive = string | number | boolean | bigint | symbol | null | undefined | Date;
|
|
68
|
+
type NeutralValue = Timestamp | GeoPoint | DocumentReference | VectorValue | Uint8Array;
|
|
69
|
+
type WithFieldValue<T> = T extends Primitive | NeutralValue ? T : T extends Array<infer E> ? Array<E> : T extends object ? {
|
|
70
|
+
[K in keyof T]: WithFieldValue<T[K]> | SentinelFor<NonNullable<T[K]>>;
|
|
71
|
+
} : T;
|
|
72
|
+
type SentinelFor<V> = (V extends number ? IncrementSentinel : never) | (V extends Array<infer E> ? ArrayUnionSentinel<E> | ArrayRemoveSentinel<E> : never) | (V extends Date | Timestamp ? ServerTimestampSentinel : never);
|
|
73
|
+
type UpdateValue<V> = Exclude<WithFieldValue<V>, undefined> | SentinelFor<NonNullable<V>> | (undefined extends V ? DeleteFieldSentinel : never);
|
|
74
|
+
type UpdateData<T> = {
|
|
75
|
+
[K in keyof T]?: UpdateValue<T[K]>;
|
|
76
|
+
};
|
|
77
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
78
|
+
type PrefixPaths<P extends string, T> = {
|
|
79
|
+
[K in keyof T & string as `${P}.${K}`]?: T[K];
|
|
80
|
+
};
|
|
81
|
+
type NestedUpdatePaths<T> = UnionToIntersection<{
|
|
82
|
+
[K in keyof T & string]: NonNullable<T[K]> extends FieldPathLeaf ? {} : NonNullable<T[K]> extends object ? PrefixPaths<K, UpdatePaths<NonNullable<T[K]>>> : {};
|
|
83
|
+
}[keyof T & string]>;
|
|
84
|
+
type UpdatePaths<T> = UpdateData<T> & NestedUpdatePaths<T>;
|
|
85
|
+
type MergeOptions<T> = {
|
|
86
|
+
merge: true;
|
|
87
|
+
} | {
|
|
88
|
+
mergeFields: Array<FieldPath<T>>;
|
|
89
|
+
};
|
|
90
|
+
type WhereFilterOp = "==" | "!=" | "<" | "<=" | ">" | ">=" | "array-contains" | "in" | "not-in" | "array-contains-any";
|
|
91
|
+
type OrderByDirection = "asc" | "desc";
|
|
92
|
+
type ArrayElement<T> = T extends ReadonlyArray<infer E> ? E : never;
|
|
93
|
+
type FieldPathLeaf = Primitive | NeutralValue | ReadonlyArray<unknown>;
|
|
94
|
+
type FieldPath<T> = T extends object ? {
|
|
95
|
+
[K in keyof T & string]: K | (NonNullable<T[K]> extends FieldPathLeaf ? never : `${K}.${FieldPath<NonNullable<T[K]>>}`);
|
|
96
|
+
}[keyof T & string] : never;
|
|
97
|
+
type NumericFieldPath<T> = {
|
|
98
|
+
[P in FieldPath<T>]: NonNullable<ValueAtPath<T, P>> extends number ? P : never;
|
|
99
|
+
}[FieldPath<T>];
|
|
100
|
+
type ValueAtPath<T, P extends string> = P extends `${infer Head}.${infer Rest}` ? Head extends keyof T ? ValueAtPath<NonNullable<T[Head]>, Rest> : never : P extends keyof T ? T[P] : never;
|
|
101
|
+
|
|
102
|
+
type DocumentData = Record<string, unknown>;
|
|
103
|
+
type FieldRef = string | DocumentIdRef;
|
|
104
|
+
interface DocLocation {
|
|
105
|
+
readonly kind: "doc";
|
|
106
|
+
readonly segments: readonly string[];
|
|
107
|
+
}
|
|
108
|
+
interface CollectionLocation {
|
|
109
|
+
readonly kind: "collection";
|
|
110
|
+
readonly segments: readonly string[];
|
|
111
|
+
}
|
|
112
|
+
interface CollectionGroupLocation {
|
|
113
|
+
readonly kind: "collectionGroup";
|
|
114
|
+
readonly collectionId: string;
|
|
115
|
+
}
|
|
116
|
+
type QuerySource = CollectionLocation | CollectionGroupLocation;
|
|
117
|
+
type Constraint = {
|
|
118
|
+
type: "where";
|
|
119
|
+
field: FieldRef;
|
|
120
|
+
op: WhereFilterOp;
|
|
121
|
+
value: unknown;
|
|
122
|
+
} | {
|
|
123
|
+
type: "orderBy";
|
|
124
|
+
field: FieldRef;
|
|
125
|
+
direction: "asc" | "desc";
|
|
126
|
+
} | {
|
|
127
|
+
type: "limit";
|
|
128
|
+
limit: number;
|
|
129
|
+
} | {
|
|
130
|
+
type: "startAt";
|
|
131
|
+
values: readonly unknown[];
|
|
132
|
+
} | {
|
|
133
|
+
type: "startAfter";
|
|
134
|
+
values: readonly unknown[];
|
|
135
|
+
} | {
|
|
136
|
+
type: "endAt";
|
|
137
|
+
values: readonly unknown[];
|
|
138
|
+
} | {
|
|
139
|
+
type: "endBefore";
|
|
140
|
+
values: readonly unknown[];
|
|
141
|
+
};
|
|
142
|
+
interface RawSnapshot {
|
|
143
|
+
readonly id: string;
|
|
144
|
+
readonly exists: boolean;
|
|
145
|
+
readonly data: DocumentData | undefined;
|
|
146
|
+
}
|
|
147
|
+
interface WriteOptions {
|
|
148
|
+
readonly merge?: boolean;
|
|
149
|
+
readonly mergeFields?: readonly string[];
|
|
150
|
+
}
|
|
151
|
+
interface TransactionOptions {
|
|
152
|
+
readonly maxAttempts?: number;
|
|
153
|
+
}
|
|
154
|
+
type Unsubscribe = () => void;
|
|
155
|
+
interface DocObserver {
|
|
156
|
+
next(snapshot: RawSnapshot): void;
|
|
157
|
+
error?(error: unknown): void;
|
|
158
|
+
}
|
|
159
|
+
interface QueryObserver {
|
|
160
|
+
next(snapshots: readonly RawSnapshot[]): void;
|
|
161
|
+
error?(error: unknown): void;
|
|
162
|
+
}
|
|
163
|
+
interface NativeAdapter {
|
|
164
|
+
timestampFromDate(date: Date): unknown;
|
|
165
|
+
fieldValue(sentinel: Sentinel): unknown;
|
|
166
|
+
bytesFromUint8Array(bytes: Uint8Array): unknown;
|
|
167
|
+
}
|
|
168
|
+
interface RawConverter {
|
|
169
|
+
toNative(data: DocumentData): DocumentData;
|
|
170
|
+
fromNative(id: string, data: DocumentData): unknown;
|
|
171
|
+
}
|
|
172
|
+
interface TxDriver {
|
|
173
|
+
get(path: DocLocation): Promise<RawSnapshot>;
|
|
174
|
+
set(path: DocLocation, data: DocumentData, options?: WriteOptions): void;
|
|
175
|
+
update(path: DocLocation, data: DocumentData): void;
|
|
176
|
+
delete(path: DocLocation): void;
|
|
177
|
+
}
|
|
178
|
+
interface BatchDriver {
|
|
179
|
+
set(path: DocLocation, data: DocumentData, options?: WriteOptions): void;
|
|
180
|
+
update(path: DocLocation, data: DocumentData): void;
|
|
181
|
+
delete(path: DocLocation): void;
|
|
182
|
+
commit(): Promise<void>;
|
|
183
|
+
}
|
|
184
|
+
interface Driver {
|
|
185
|
+
readonly native: NativeAdapter;
|
|
186
|
+
getDoc(path: DocLocation): Promise<RawSnapshot>;
|
|
187
|
+
setDoc(path: DocLocation, data: DocumentData, options?: WriteOptions): Promise<void>;
|
|
188
|
+
updateDoc(path: DocLocation, data: DocumentData): Promise<void>;
|
|
189
|
+
addDoc(path: CollectionLocation, data: DocumentData): Promise<string>;
|
|
190
|
+
deleteDoc(path: DocLocation): Promise<void>;
|
|
191
|
+
runQuery(source: QuerySource, constraints: readonly Constraint[]): Promise<RawSnapshot[]>;
|
|
192
|
+
count(source: QuerySource, constraints: readonly Constraint[]): Promise<number>;
|
|
193
|
+
sum(source: QuerySource, constraints: readonly Constraint[], field: string): Promise<number>;
|
|
194
|
+
average(source: QuerySource, constraints: readonly Constraint[], field: string): Promise<number | null>;
|
|
195
|
+
onSnapshotDoc(path: DocLocation, observer: DocObserver): Unsubscribe;
|
|
196
|
+
onSnapshotQuery(source: QuerySource, constraints: readonly Constraint[], observer: QueryObserver): Unsubscribe;
|
|
197
|
+
runTransaction<T>(fn: (tx: TxDriver) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
198
|
+
batch(): BatchDriver;
|
|
199
|
+
docRef(path: DocLocation, converter: RawConverter): unknown;
|
|
200
|
+
collectionRef(path: CollectionLocation, converter: RawConverter): unknown;
|
|
201
|
+
queryRef(source: QuerySource, constraints: readonly Constraint[], converter: RawConverter): unknown;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
interface QueryContext<S extends StandardSchemaV1> {
|
|
205
|
+
driver: Driver;
|
|
206
|
+
def: CollectionDef<S>;
|
|
207
|
+
source: QuerySource;
|
|
208
|
+
}
|
|
209
|
+
type WhereField<S extends StandardSchemaV1> = FieldPath<InferOutput<S>>;
|
|
210
|
+
type WhereValue<S extends StandardSchemaV1, K extends WhereField<S>> = Exclude<ValueAtPath<InferOutput<S>, K>, undefined>;
|
|
211
|
+
type NumericField<S extends StandardSchemaV1> = NumericFieldPath<InferOutput<S>>;
|
|
212
|
+
type QuerySnapshotObserver<S extends StandardSchemaV1> = ((docs: Array<Doc<S>>) => void) | {
|
|
213
|
+
next: (docs: Array<Doc<S>>) => void;
|
|
214
|
+
error?: (error: unknown) => void;
|
|
215
|
+
};
|
|
216
|
+
declare class QueryBuilder<S extends StandardSchemaV1> {
|
|
217
|
+
#private;
|
|
218
|
+
constructor(ctx: QueryContext<S>, constraints?: readonly Constraint[]);
|
|
219
|
+
where<K extends WhereField<S>>(field: K, op: "in" | "not-in", value: Array<WhereValue<S, K>>): QueryBuilder<S>;
|
|
220
|
+
where<K extends WhereField<S>>(field: K, op: "array-contains", value: ArrayElement<WhereValue<S, K>>): QueryBuilder<S>;
|
|
221
|
+
where<K extends WhereField<S>>(field: K, op: "array-contains-any", value: Array<ArrayElement<WhereValue<S, K>>>): QueryBuilder<S>;
|
|
222
|
+
where<K extends WhereField<S>>(field: K, op: "==" | "!=" | "<" | "<=" | ">" | ">=", value: WhereValue<S, K>): QueryBuilder<S>;
|
|
223
|
+
where(field: DocumentIdRef, op: "in" | "not-in", value: string[]): QueryBuilder<S>;
|
|
224
|
+
where(field: DocumentIdRef, op: "==" | "!=" | "<" | "<=" | ">" | ">=", value: string): QueryBuilder<S>;
|
|
225
|
+
orderBy(field: WhereField<S>, direction?: OrderByDirection): QueryBuilder<S>;
|
|
226
|
+
orderBy(field: DocumentIdRef, direction?: OrderByDirection): QueryBuilder<S>;
|
|
227
|
+
limit(limit: number): QueryBuilder<S>;
|
|
228
|
+
startAt(...values: unknown[]): QueryBuilder<S>;
|
|
229
|
+
startAfter(...values: unknown[]): QueryBuilder<S>;
|
|
230
|
+
endAt(...values: unknown[]): QueryBuilder<S>;
|
|
231
|
+
endBefore(...values: unknown[]): QueryBuilder<S>;
|
|
232
|
+
get(): Promise<Array<Doc<S>>>;
|
|
233
|
+
list(): Promise<Array<Doc<S>>>;
|
|
234
|
+
count(): Promise<number>;
|
|
235
|
+
sum(field: NumericField<S>): Promise<number>;
|
|
236
|
+
average(field: NumericField<S>): Promise<number | null>;
|
|
237
|
+
onSnapshot(observer: QuerySnapshotObserver<S>): Unsubscribe;
|
|
238
|
+
get ref(): unknown;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare class CollectionHandle<S extends StandardSchemaV1> {
|
|
242
|
+
#private;
|
|
243
|
+
constructor(driver: Driver, def: CollectionDef<S>, segments: readonly string[]);
|
|
244
|
+
doc(id: string): DocumentHandle<S>;
|
|
245
|
+
get(id: string): Promise<Doc<S> | null>;
|
|
246
|
+
set(id: string, data: WithFieldValue<InferOutput<S>>): Promise<void>;
|
|
247
|
+
set(id: string, data: UpdateData<InferOutput<S>>, options: MergeOptions<InferOutput<S>>): Promise<void>;
|
|
248
|
+
update(id: string, data: UpdatePaths<InferOutput<S>>): Promise<void>;
|
|
249
|
+
add(data: WithFieldValue<InferOutput<S>>): Promise<string>;
|
|
250
|
+
delete(id: string): Promise<void>;
|
|
251
|
+
query(): QueryBuilder<S>;
|
|
252
|
+
where<K extends WhereField<S>>(field: K, op: "in" | "not-in", value: Array<WhereValue<S, K>>): QueryBuilder<S>;
|
|
253
|
+
where<K extends WhereField<S>>(field: K, op: "array-contains", value: ArrayElement<WhereValue<S, K>>): QueryBuilder<S>;
|
|
254
|
+
where<K extends WhereField<S>>(field: K, op: "array-contains-any", value: Array<ArrayElement<WhereValue<S, K>>>): QueryBuilder<S>;
|
|
255
|
+
where<K extends WhereField<S>>(field: K, op: "==" | "!=" | "<" | "<=" | ">" | ">=", value: WhereValue<S, K>): QueryBuilder<S>;
|
|
256
|
+
where(field: DocumentIdRef, op: "in" | "not-in", value: string[]): QueryBuilder<S>;
|
|
257
|
+
where(field: DocumentIdRef, op: "==" | "!=" | "<" | "<=" | ">" | ">=", value: string): QueryBuilder<S>;
|
|
258
|
+
orderBy(field: WhereField<S>, direction?: OrderByDirection): QueryBuilder<S>;
|
|
259
|
+
orderBy(field: DocumentIdRef, direction?: OrderByDirection): QueryBuilder<S>;
|
|
260
|
+
limit(limit: number): QueryBuilder<S>;
|
|
261
|
+
count(): Promise<number>;
|
|
262
|
+
sum(field: NumericField<S>): Promise<number>;
|
|
263
|
+
average(field: NumericField<S>): Promise<number | null>;
|
|
264
|
+
onSnapshot(observer: QuerySnapshotObserver<S>): Unsubscribe;
|
|
265
|
+
get ref(): unknown;
|
|
266
|
+
}
|
|
267
|
+
declare class TxCollectionHandle<S extends StandardSchemaV1> {
|
|
268
|
+
#private;
|
|
269
|
+
constructor(tx: TxDriver, driver: Driver, def: CollectionDef<S>, segments: readonly string[]);
|
|
270
|
+
doc(id: string): TxDocumentHandle<S>;
|
|
271
|
+
get(id: string): Promise<Doc<S> | null>;
|
|
272
|
+
set(id: string, data: WithFieldValue<InferOutput<S>>): void;
|
|
273
|
+
set(id: string, data: UpdateData<InferOutput<S>>, options: MergeOptions<InferOutput<S>>): void;
|
|
274
|
+
update(id: string, data: UpdatePaths<InferOutput<S>>): void;
|
|
275
|
+
delete(id: string): void;
|
|
276
|
+
}
|
|
277
|
+
declare class BatchCollectionHandle<S extends StandardSchemaV1> {
|
|
278
|
+
#private;
|
|
279
|
+
constructor(batch: BatchDriver, driver: Driver, segments: readonly string[]);
|
|
280
|
+
doc(id: string): BatchDocumentHandle<S>;
|
|
281
|
+
set(id: string, data: WithFieldValue<InferOutput<S>>): void;
|
|
282
|
+
set(id: string, data: UpdateData<InferOutput<S>>, options: MergeOptions<InferOutput<S>>): void;
|
|
283
|
+
update(id: string, data: UpdatePaths<InferOutput<S>>): void;
|
|
284
|
+
delete(id: string): void;
|
|
285
|
+
}
|
|
286
|
+
type DocSnapshotObserver<S extends StandardSchemaV1> = ((doc: Doc<S> | null) => void) | {
|
|
287
|
+
next: (doc: Doc<S> | null) => void;
|
|
288
|
+
error?: (error: unknown) => void;
|
|
289
|
+
};
|
|
290
|
+
declare class DocumentHandle<S extends StandardSchemaV1> {
|
|
291
|
+
#private;
|
|
292
|
+
constructor(driver: Driver, def: CollectionDef<S>, segments: readonly string[]);
|
|
293
|
+
get id(): string;
|
|
294
|
+
collection<C extends StandardSchemaV1>(def: CollectionDef<C>): CollectionHandle<C>;
|
|
295
|
+
get(): Promise<Doc<S> | null>;
|
|
296
|
+
exists(): Promise<boolean>;
|
|
297
|
+
set(data: WithFieldValue<InferOutput<S>>): Promise<void>;
|
|
298
|
+
set(data: UpdateData<InferOutput<S>>, options: MergeOptions<InferOutput<S>>): Promise<void>;
|
|
299
|
+
update(data: UpdatePaths<InferOutput<S>>): Promise<void>;
|
|
300
|
+
delete(): Promise<void>;
|
|
301
|
+
onSnapshot(observer: DocSnapshotObserver<S>): Unsubscribe;
|
|
302
|
+
get ref(): unknown;
|
|
303
|
+
}
|
|
304
|
+
declare class TxDocumentHandle<S extends StandardSchemaV1> {
|
|
305
|
+
#private;
|
|
306
|
+
constructor(tx: TxDriver, driver: Driver, def: CollectionDef<S>, segments: readonly string[]);
|
|
307
|
+
get id(): string;
|
|
308
|
+
collection<C extends StandardSchemaV1>(def: CollectionDef<C>): TxCollectionHandle<C>;
|
|
309
|
+
get(): Promise<Doc<S> | null>;
|
|
310
|
+
set(data: WithFieldValue<InferOutput<S>>): void;
|
|
311
|
+
set(data: UpdateData<InferOutput<S>>, options: MergeOptions<InferOutput<S>>): void;
|
|
312
|
+
update(data: UpdatePaths<InferOutput<S>>): void;
|
|
313
|
+
delete(): void;
|
|
314
|
+
}
|
|
315
|
+
declare class BatchDocumentHandle<S extends StandardSchemaV1> {
|
|
316
|
+
#private;
|
|
317
|
+
constructor(batch: BatchDriver, driver: Driver, segments: readonly string[]);
|
|
318
|
+
get id(): string;
|
|
319
|
+
collection<C extends StandardSchemaV1>(def: CollectionDef<C>): BatchCollectionHandle<C>;
|
|
320
|
+
set(data: WithFieldValue<InferOutput<S>>): void;
|
|
321
|
+
set(data: UpdateData<InferOutput<S>>, options: MergeOptions<InferOutput<S>>): void;
|
|
322
|
+
update(data: UpdatePaths<InferOutput<S>>): void;
|
|
323
|
+
delete(): void;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
declare class Transaction {
|
|
327
|
+
#private;
|
|
328
|
+
constructor(tx: TxDriver, driver: Driver);
|
|
329
|
+
collection<S extends StandardSchemaV1>(def: CollectionDef<S>): TxCollectionHandle<S>;
|
|
330
|
+
}
|
|
331
|
+
declare class Batch {
|
|
332
|
+
#private;
|
|
333
|
+
constructor(batch: BatchDriver, driver: Driver);
|
|
334
|
+
collection<S extends StandardSchemaV1>(def: CollectionDef<S>): BatchCollectionHandle<S>;
|
|
335
|
+
commit(): Promise<void>;
|
|
336
|
+
}
|
|
337
|
+
declare class Database {
|
|
338
|
+
#private;
|
|
339
|
+
constructor(driver: Driver);
|
|
340
|
+
collection<S extends StandardSchemaV1>(def: CollectionDef<S>): CollectionHandle<S>;
|
|
341
|
+
collectionGroup<S extends StandardSchemaV1>(def: CollectionDef<S>): QueryBuilder<S>;
|
|
342
|
+
runTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
343
|
+
batch(): Batch;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
interface CollectionOptions {
|
|
347
|
+
raw?: readonly string[];
|
|
348
|
+
}
|
|
349
|
+
declare function collection<S extends StandardSchemaV1>(name: string, schema: S & ("id" extends keyof InferOutput<S> ? never : unknown), options?: CollectionOptions): CollectionDef<S>;
|
|
350
|
+
|
|
351
|
+
declare class FiresmeltError extends Error {
|
|
352
|
+
readonly name: string;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export { type ArrayElement, ArrayRemoveSentinel, ArrayUnionSentinel, Batch, BatchCollectionHandle, BatchDocumentHandle, type CollectionDef, CollectionHandle, type CollectionOptions, Database, DeleteFieldSentinel, type Doc, type DocSnapshotObserver, DocumentHandle, DocumentIdRef, type DocumentReference, type FieldPath, FiresmeltError, type GeoPoint, IncrementSentinel, type InferOutput, type MergeOptions, type NumericField, type NumericFieldPath, type OrderByDirection, QueryBuilder, type QuerySnapshotObserver, type SentinelFor, ServerTimestampSentinel, type Timestamp, Transaction, type TransactionOptions, TxCollectionHandle, TxDocumentHandle, type Unsubscribe, type UpdateData, type UpdatePaths, type UpdateValue, type ValueAtPath, type VectorValue, type WhereField, type WhereFilterOp, type WhereValue, type WithFieldValue, arrayRemove, arrayUnion, collection, deleteField, documentId, increment, isTimestampLike, serverTimestamp };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Batch, BatchCollectionHandle, BatchDocumentHandle, CollectionHandle, Database, DocumentHandle, FiresmeltError, QueryBuilder, Transaction, TxCollectionHandle, TxDocumentHandle, arrayRemove, arrayUnion, collection, deleteField, documentId, increment, isTimestampLike, serverTimestamp } from './chunk-WEVOVXQQ.js';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { CollectionReference, Firestore, DocumentReference, Query } from 'firebase/firestore';
|
|
3
|
+
import { CollectionHandle, Doc, Database, DocumentHandle, QueryBuilder } from './index.js';
|
|
4
|
+
export { ArrayElement, ArrayRemoveSentinel, ArrayUnionSentinel, Batch, BatchCollectionHandle, BatchDocumentHandle, CollectionDef, CollectionOptions, DeleteFieldSentinel, DocSnapshotObserver, DocumentIdRef, DocumentReference, FieldPath, FiresmeltError, GeoPoint, IncrementSentinel, InferOutput, MergeOptions, NumericField, NumericFieldPath, OrderByDirection, QuerySnapshotObserver, SentinelFor, ServerTimestampSentinel, Timestamp, Transaction, TransactionOptions, TxCollectionHandle, TxDocumentHandle, Unsubscribe, UpdateData, UpdatePaths, UpdateValue, ValueAtPath, VectorValue, WhereField, WhereFilterOp, WhereValue, WithFieldValue, arrayRemove, arrayUnion, collection, deleteField, documentId, increment, isTimestampLike, serverTimestamp } from './index.js';
|
|
5
|
+
|
|
6
|
+
declare function createDatabase(firestore: Firestore): Database;
|
|
7
|
+
declare function docRef<S extends StandardSchemaV1>(handle: DocumentHandle<S>): DocumentReference<Doc<S>>;
|
|
8
|
+
declare function collectionRef<S extends StandardSchemaV1>(handle: CollectionHandle<S>): CollectionReference<Doc<S>>;
|
|
9
|
+
declare function queryRef<S extends StandardSchemaV1>(builder: QueryBuilder<S>): Query<Doc<S>>;
|
|
10
|
+
|
|
11
|
+
export { CollectionHandle, Database, Doc, DocumentHandle, QueryBuilder, collectionRef, createDatabase, docRef, queryRef };
|
package/dist/web.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Database, ServerTimestampSentinel, IncrementSentinel, ArrayUnionSentinel, ArrayRemoveSentinel, DeleteFieldSentinel, FiresmeltError, toNative } from './chunk-WEVOVXQQ.js';
|
|
2
|
+
export { Batch, BatchCollectionHandle, BatchDocumentHandle, CollectionHandle, Database, DocumentHandle, FiresmeltError, QueryBuilder, Transaction, TxCollectionHandle, TxDocumentHandle, arrayRemove, arrayUnion, collection, deleteField, documentId, increment, isTimestampLike, serverTimestamp } from './chunk-WEVOVXQQ.js';
|
|
3
|
+
import { Bytes, Timestamp, serverTimestamp, increment, arrayUnion, arrayRemove, deleteField, doc, collection, collectionGroup, query, endBefore, endAt, startAfter, startAt, limit, orderBy, where, getDoc, setDoc, updateDoc, addDoc, deleteDoc, getDocs, getCountFromServer, getAggregateFromServer, sum, average, onSnapshot, runTransaction, writeBatch, documentId } from 'firebase/firestore';
|
|
4
|
+
|
|
5
|
+
var SNAPSHOT_OPTIONS = { serverTimestamps: "estimate" };
|
|
6
|
+
var WebDriver = class {
|
|
7
|
+
native;
|
|
8
|
+
#fs;
|
|
9
|
+
constructor(firestore) {
|
|
10
|
+
this.#fs = firestore;
|
|
11
|
+
this.native = {
|
|
12
|
+
timestampFromDate: (date) => Timestamp.fromDate(date),
|
|
13
|
+
fieldValue: (sentinel) => this.#fieldValue(sentinel),
|
|
14
|
+
bytesFromUint8Array: (bytes) => Bytes.fromUint8Array(bytes)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
#fieldValue(sentinel) {
|
|
18
|
+
if (sentinel instanceof ServerTimestampSentinel) {
|
|
19
|
+
return serverTimestamp();
|
|
20
|
+
}
|
|
21
|
+
if (sentinel instanceof IncrementSentinel) {
|
|
22
|
+
return increment(sentinel.by);
|
|
23
|
+
}
|
|
24
|
+
if (sentinel instanceof ArrayUnionSentinel) {
|
|
25
|
+
return arrayUnion(...this.#values(sentinel.values));
|
|
26
|
+
}
|
|
27
|
+
if (sentinel instanceof ArrayRemoveSentinel) {
|
|
28
|
+
return arrayRemove(...this.#values(sentinel.values));
|
|
29
|
+
}
|
|
30
|
+
if (sentinel instanceof DeleteFieldSentinel) {
|
|
31
|
+
return deleteField();
|
|
32
|
+
}
|
|
33
|
+
throw new FiresmeltError("Unknown sentinel");
|
|
34
|
+
}
|
|
35
|
+
#values(values) {
|
|
36
|
+
return values.map((value) => toNative(value, this.native));
|
|
37
|
+
}
|
|
38
|
+
#setOptions(options) {
|
|
39
|
+
if (options?.mergeFields) {
|
|
40
|
+
return { mergeFields: [...options.mergeFields] };
|
|
41
|
+
}
|
|
42
|
+
if (options?.merge) {
|
|
43
|
+
return { merge: true };
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
#doc(segments) {
|
|
48
|
+
return doc(this.#fs, segments.join("/"));
|
|
49
|
+
}
|
|
50
|
+
#collection(segments) {
|
|
51
|
+
return collection(this.#fs, segments.join("/"));
|
|
52
|
+
}
|
|
53
|
+
#query(source, constraints) {
|
|
54
|
+
const base = source.kind === "collection" ? this.#collection(source.segments) : collectionGroup(this.#fs, source.collectionId);
|
|
55
|
+
return query(base, ...constraints.map((c) => this.#constraint(c)));
|
|
56
|
+
}
|
|
57
|
+
#constraint(constraint) {
|
|
58
|
+
switch (constraint.type) {
|
|
59
|
+
case "where":
|
|
60
|
+
return where(
|
|
61
|
+
fieldRef(constraint.field),
|
|
62
|
+
constraint.op,
|
|
63
|
+
toNative(constraint.value, this.native)
|
|
64
|
+
);
|
|
65
|
+
case "orderBy":
|
|
66
|
+
return orderBy(fieldRef(constraint.field), constraint.direction);
|
|
67
|
+
case "limit":
|
|
68
|
+
return limit(constraint.limit);
|
|
69
|
+
case "startAt":
|
|
70
|
+
return startAt(...this.#values(constraint.values));
|
|
71
|
+
case "startAfter":
|
|
72
|
+
return startAfter(...this.#values(constraint.values));
|
|
73
|
+
case "endAt":
|
|
74
|
+
return endAt(...this.#values(constraint.values));
|
|
75
|
+
case "endBefore":
|
|
76
|
+
return endBefore(...this.#values(constraint.values));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async getDoc(path) {
|
|
80
|
+
const snapshot = await getDoc(this.#doc(path.segments));
|
|
81
|
+
return {
|
|
82
|
+
id: snapshot.id,
|
|
83
|
+
exists: snapshot.exists(),
|
|
84
|
+
data: snapshot.data(SNAPSHOT_OPTIONS)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async setDoc(path, data, options) {
|
|
88
|
+
const ref = this.#doc(path.segments);
|
|
89
|
+
const setOptions = this.#setOptions(options);
|
|
90
|
+
await (setOptions ? setDoc(ref, data, setOptions) : setDoc(ref, data));
|
|
91
|
+
}
|
|
92
|
+
async updateDoc(path, data) {
|
|
93
|
+
await updateDoc(this.#doc(path.segments), data);
|
|
94
|
+
}
|
|
95
|
+
async addDoc(path, data) {
|
|
96
|
+
const ref = await addDoc(this.#collection(path.segments), data);
|
|
97
|
+
return ref.id;
|
|
98
|
+
}
|
|
99
|
+
async deleteDoc(path) {
|
|
100
|
+
await deleteDoc(this.#doc(path.segments));
|
|
101
|
+
}
|
|
102
|
+
async runQuery(source, constraints) {
|
|
103
|
+
const snapshot = await getDocs(this.#query(source, constraints));
|
|
104
|
+
return snapshot.docs.map((doc) => ({
|
|
105
|
+
id: doc.id,
|
|
106
|
+
exists: true,
|
|
107
|
+
data: doc.data(SNAPSHOT_OPTIONS)
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
async count(source, constraints) {
|
|
111
|
+
const snapshot = await getCountFromServer(this.#query(source, constraints));
|
|
112
|
+
return snapshot.data().count;
|
|
113
|
+
}
|
|
114
|
+
async sum(source, constraints, field) {
|
|
115
|
+
const snapshot = await getAggregateFromServer(
|
|
116
|
+
this.#query(source, constraints),
|
|
117
|
+
{ value: sum(field) }
|
|
118
|
+
);
|
|
119
|
+
return snapshot.data().value;
|
|
120
|
+
}
|
|
121
|
+
async average(source, constraints, field) {
|
|
122
|
+
const snapshot = await getAggregateFromServer(
|
|
123
|
+
this.#query(source, constraints),
|
|
124
|
+
{ value: average(field) }
|
|
125
|
+
);
|
|
126
|
+
return snapshot.data().value;
|
|
127
|
+
}
|
|
128
|
+
onSnapshotDoc(path, observer) {
|
|
129
|
+
return onSnapshot(
|
|
130
|
+
this.#doc(path.segments),
|
|
131
|
+
(snapshot) => observer.next({
|
|
132
|
+
id: snapshot.id,
|
|
133
|
+
exists: snapshot.exists(),
|
|
134
|
+
data: snapshot.data(SNAPSHOT_OPTIONS)
|
|
135
|
+
}),
|
|
136
|
+
observer.error?.bind(observer)
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
onSnapshotQuery(source, constraints, observer) {
|
|
140
|
+
return onSnapshot(
|
|
141
|
+
this.#query(source, constraints),
|
|
142
|
+
(snapshot) => observer.next(
|
|
143
|
+
snapshot.docs.map((doc) => ({
|
|
144
|
+
id: doc.id,
|
|
145
|
+
exists: true,
|
|
146
|
+
data: doc.data(SNAPSHOT_OPTIONS)
|
|
147
|
+
}))
|
|
148
|
+
),
|
|
149
|
+
observer.error?.bind(observer)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
runTransaction(fn, options) {
|
|
153
|
+
return runTransaction(
|
|
154
|
+
this.#fs,
|
|
155
|
+
(transaction) => {
|
|
156
|
+
const tx = {
|
|
157
|
+
get: async (path) => {
|
|
158
|
+
const snapshot = await transaction.get(this.#doc(path.segments));
|
|
159
|
+
return {
|
|
160
|
+
id: snapshot.id,
|
|
161
|
+
exists: snapshot.exists(),
|
|
162
|
+
data: snapshot.data(SNAPSHOT_OPTIONS)
|
|
163
|
+
};
|
|
164
|
+
},
|
|
165
|
+
set: (path, data, options2) => {
|
|
166
|
+
const ref = this.#doc(path.segments);
|
|
167
|
+
const setOptions = this.#setOptions(options2);
|
|
168
|
+
if (setOptions) {
|
|
169
|
+
transaction.set(ref, data, setOptions);
|
|
170
|
+
} else {
|
|
171
|
+
transaction.set(ref, data);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
update: (path, data) => {
|
|
175
|
+
transaction.update(this.#doc(path.segments), data);
|
|
176
|
+
},
|
|
177
|
+
delete: (path) => {
|
|
178
|
+
transaction.delete(this.#doc(path.segments));
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return fn(tx);
|
|
182
|
+
},
|
|
183
|
+
options
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
batch() {
|
|
187
|
+
const batch = writeBatch(this.#fs);
|
|
188
|
+
return {
|
|
189
|
+
set: (path, data, options) => {
|
|
190
|
+
const ref = this.#doc(path.segments);
|
|
191
|
+
const setOptions = this.#setOptions(options);
|
|
192
|
+
if (setOptions) {
|
|
193
|
+
batch.set(ref, data, setOptions);
|
|
194
|
+
} else {
|
|
195
|
+
batch.set(ref, data);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
update: (path, data) => {
|
|
199
|
+
batch.update(this.#doc(path.segments), data);
|
|
200
|
+
},
|
|
201
|
+
delete: (path) => {
|
|
202
|
+
batch.delete(this.#doc(path.segments));
|
|
203
|
+
},
|
|
204
|
+
commit: async () => {
|
|
205
|
+
await batch.commit();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
docRef(path, converter) {
|
|
210
|
+
return this.#doc(path.segments).withConverter(adaptConverter(converter));
|
|
211
|
+
}
|
|
212
|
+
collectionRef(path, converter) {
|
|
213
|
+
return this.#collection(path.segments).withConverter(
|
|
214
|
+
adaptConverter(converter)
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
queryRef(source, constraints, converter) {
|
|
218
|
+
return this.#query(source, constraints).withConverter(
|
|
219
|
+
adaptConverter(converter)
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
function fieldRef(field) {
|
|
224
|
+
return typeof field === "string" ? field : documentId();
|
|
225
|
+
}
|
|
226
|
+
function adaptConverter(converter) {
|
|
227
|
+
return {
|
|
228
|
+
toFirestore: (model) => converter.toNative(model),
|
|
229
|
+
fromFirestore: (snapshot, options) => converter.fromNative(
|
|
230
|
+
snapshot.id,
|
|
231
|
+
snapshot.data(options.serverTimestamps ? options : SNAPSHOT_OPTIONS)
|
|
232
|
+
)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/web.ts
|
|
237
|
+
function createDatabase(firestore) {
|
|
238
|
+
return new Database(new WebDriver(firestore));
|
|
239
|
+
}
|
|
240
|
+
function docRef(handle) {
|
|
241
|
+
return handle.ref;
|
|
242
|
+
}
|
|
243
|
+
function collectionRef(handle) {
|
|
244
|
+
return handle.ref;
|
|
245
|
+
}
|
|
246
|
+
function queryRef(builder) {
|
|
247
|
+
return builder.ref;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export { collectionRef, createDatabase, docRef, queryRef };
|
|
251
|
+
//# sourceMappingURL=web.js.map
|
|
252
|
+
//# sourceMappingURL=web.js.map
|