@sovaria/sdk 0.0.0-stage → 0.5.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 +248 -2
- package/dist/analytics.d.ts +92 -0
- package/dist/analytics.js +236 -0
- package/dist/client.d.ts +146 -0
- package/dist/client.js +583 -0
- package/dist/collections.d.ts +255 -0
- package/dist/collections.js +569 -0
- package/dist/complete-api.d.ts +54 -0
- package/dist/complete-api.js +71 -0
- package/dist/crashes.d.ts +111 -0
- package/dist/crashes.js +244 -0
- package/dist/crypto.d.ts +37 -0
- package/dist/crypto.js +189 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.js +258 -0
- package/dist/firestore.d.ts +239 -0
- package/dist/firestore.js +431 -0
- package/dist/generated.d.ts +2462 -0
- package/dist/generated.js +1962 -0
- package/dist/inapp.d.ts +52 -0
- package/dist/inapp.js +48 -0
- package/dist/index.d.ts +3562 -0
- package/dist/index.js +3018 -0
- package/dist/offline.d.ts +92 -0
- package/dist/offline.js +575 -0
- package/dist/passkeys.d.ts +17 -0
- package/dist/passkeys.js +76 -0
- package/dist/perf.d.ts +76 -0
- package/dist/perf.js +212 -0
- package/dist/remote-config.d.ts +87 -0
- package/dist/remote-config.js +182 -0
- package/dist/types.d.ts +102 -0
- package/dist/types.js +1 -0
- package/dist/webpush.d.ts +46 -0
- package/dist/webpush.js +99 -0
- package/package.json +74 -4
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
type Json = string | number | boolean | null | Json[] | {
|
|
2
|
+
[key: string]: Json;
|
|
3
|
+
};
|
|
4
|
+
type JsonObject = {
|
|
5
|
+
[key: string]: Json;
|
|
6
|
+
};
|
|
7
|
+
/** What the collection API needs from the SDK (keeps this module free of a circular import). */
|
|
8
|
+
export interface DocumentsTransport {
|
|
9
|
+
request<T = unknown>(method: string, path: string, options?: {
|
|
10
|
+
body?: unknown;
|
|
11
|
+
query?: Record<string, string | number | boolean | null | undefined>;
|
|
12
|
+
}): Promise<T>;
|
|
13
|
+
openChannel(name: string, handlers: {
|
|
14
|
+
onMessage?: (payload: JsonObject) => void;
|
|
15
|
+
onStatus?: (status: string) => void;
|
|
16
|
+
onError?: (error: unknown) => void;
|
|
17
|
+
}): {
|
|
18
|
+
close: () => void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export type WhereOp = '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';
|
|
22
|
+
/** One filter or an `or` / `and` group: `posts.where(or(filter('a', '==', 1), filter('b', '<', 2)))`. */
|
|
23
|
+
export type QueryFilter = [string, WhereOp, Json] | {
|
|
24
|
+
or: QueryFilter[];
|
|
25
|
+
} | {
|
|
26
|
+
and: QueryFilter[];
|
|
27
|
+
};
|
|
28
|
+
export declare function filter(field: string, op: WhereOp, value: unknown): QueryFilter;
|
|
29
|
+
/** Matches documents that match any of `filters` (Firestore `or()`; at most 30 OR terms after expansion). */
|
|
30
|
+
export declare function or(...filters: QueryFilter[]): QueryFilter;
|
|
31
|
+
/** Matches documents that match all of `filters` (Firestore `and()`), for nesting inside `or`. */
|
|
32
|
+
export declare function and(...filters: QueryFilter[]): QueryFilter;
|
|
33
|
+
/** An aggregation for `Query.aggregate`: `count()`, `sum('price')`, `average('rating')`. */
|
|
34
|
+
export type AggregateField = {
|
|
35
|
+
op: 'count' | 'sum' | 'avg';
|
|
36
|
+
field?: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const count: () => AggregateField;
|
|
39
|
+
export declare const sum: (field: string) => AggregateField;
|
|
40
|
+
export declare const average: (field: string) => AggregateField;
|
|
41
|
+
export type Direction = 'asc' | 'desc';
|
|
42
|
+
declare const TRANSFORM: unique symbol;
|
|
43
|
+
export interface FieldTransform {
|
|
44
|
+
readonly [TRANSFORM]: true;
|
|
45
|
+
readonly op: string;
|
|
46
|
+
readonly value?: unknown;
|
|
47
|
+
}
|
|
48
|
+
/** Atomic field updates, applied by the server inside the commit. */
|
|
49
|
+
export declare const FieldValue: {
|
|
50
|
+
increment: (n: number) => FieldTransform;
|
|
51
|
+
maximum: (n: number) => FieldTransform;
|
|
52
|
+
minimum: (n: number) => FieldTransform;
|
|
53
|
+
arrayUnion: (...elements: unknown[]) => FieldTransform;
|
|
54
|
+
arrayRemove: (...elements: unknown[]) => FieldTransform;
|
|
55
|
+
serverTimestamp: () => FieldTransform;
|
|
56
|
+
delete: () => FieldTransform;
|
|
57
|
+
};
|
|
58
|
+
/** Pull FieldValue sentinels out of nested data into the API's `transforms` list. */
|
|
59
|
+
export declare function splitTransforms(data: Record<string, unknown>, prefix?: string[]): {
|
|
60
|
+
data: Record<string, unknown>;
|
|
61
|
+
transforms: JsonObject[];
|
|
62
|
+
};
|
|
63
|
+
export interface DocumentSnapshot<T = JsonObject> {
|
|
64
|
+
id: string;
|
|
65
|
+
path: string;
|
|
66
|
+
exists: boolean;
|
|
67
|
+
data: T | null;
|
|
68
|
+
version: number;
|
|
69
|
+
updateTime?: string;
|
|
70
|
+
createTime?: string;
|
|
71
|
+
/** Offline mode: read from the local cache (the server couldn't be reached). */
|
|
72
|
+
fromCache?: boolean;
|
|
73
|
+
/** Offline mode: a local write that hasn't reached the server yet. */
|
|
74
|
+
hasPendingWrites?: boolean;
|
|
75
|
+
/** Vector search (`findNearest`): the distance to the query vector (dot_product: the inner product). */
|
|
76
|
+
distance?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface DocumentChange<T = JsonObject> {
|
|
79
|
+
type: 'added' | 'modified' | 'removed';
|
|
80
|
+
doc: DocumentSnapshot<T>;
|
|
81
|
+
oldIndex: number;
|
|
82
|
+
newIndex: number;
|
|
83
|
+
}
|
|
84
|
+
export interface QuerySnapshot<T = JsonObject> {
|
|
85
|
+
docs: DocumentSnapshot<T>[];
|
|
86
|
+
changes: DocumentChange<T>[];
|
|
87
|
+
hasMore: boolean;
|
|
88
|
+
/** Pass to `startAfter(cursor)` for the next page. */
|
|
89
|
+
nextCursor: {
|
|
90
|
+
values: Json[];
|
|
91
|
+
} | null;
|
|
92
|
+
/** A composite index that would serve this query (create it in Collections › Indexes). */
|
|
93
|
+
indexHint?: {
|
|
94
|
+
collection: string;
|
|
95
|
+
fields: {
|
|
96
|
+
path: string;
|
|
97
|
+
order: string;
|
|
98
|
+
}[];
|
|
99
|
+
};
|
|
100
|
+
empty: boolean;
|
|
101
|
+
size: number;
|
|
102
|
+
}
|
|
103
|
+
export type DistanceMeasure = 'cosine' | 'euclidean' | 'dot_product';
|
|
104
|
+
export interface FindNearestOptions {
|
|
105
|
+
/** The vector field: an array of numbers in each document. */
|
|
106
|
+
vectorField: string;
|
|
107
|
+
queryVector: number[];
|
|
108
|
+
limit: number;
|
|
109
|
+
/** Default cosine. */
|
|
110
|
+
distanceMeasure?: DistanceMeasure | 'COSINE' | 'EUCLIDEAN' | 'DOT_PRODUCT';
|
|
111
|
+
/** Also write the distance into each result's data under this field. */
|
|
112
|
+
distanceResultField?: string;
|
|
113
|
+
/** cosine / euclidean: at most this distance; dot_product: at least this product. */
|
|
114
|
+
distanceThreshold?: number;
|
|
115
|
+
}
|
|
116
|
+
/** A `findNearest` query: `await query.findNearest({...}).get()`. */
|
|
117
|
+
export declare class VectorQuery<T = JsonObject> {
|
|
118
|
+
private readonly sdk;
|
|
119
|
+
readonly path: string;
|
|
120
|
+
private readonly body;
|
|
121
|
+
constructor(sdk: DocumentsTransport, path: string, body: JsonObject);
|
|
122
|
+
toJSON(): JsonObject;
|
|
123
|
+
get(): Promise<QuerySnapshot<T>>;
|
|
124
|
+
}
|
|
125
|
+
export declare class DocumentReference<T = JsonObject> {
|
|
126
|
+
private readonly sdk;
|
|
127
|
+
readonly path: string;
|
|
128
|
+
readonly id: string;
|
|
129
|
+
constructor(sdk: DocumentsTransport, path: string);
|
|
130
|
+
get parent(): Query<T>;
|
|
131
|
+
collection<U = JsonObject>(name: string): Query<U>;
|
|
132
|
+
get(): Promise<DocumentSnapshot<T>>;
|
|
133
|
+
private commitOne;
|
|
134
|
+
/** Replace the document (or merge into it with `{ merge: true }`). */
|
|
135
|
+
set(data: Partial<T> & Record<string, unknown>, opts?: {
|
|
136
|
+
merge?: boolean;
|
|
137
|
+
mergeFields?: string[];
|
|
138
|
+
}): Promise<JsonObject>;
|
|
139
|
+
/** Create it; fails with 409 ALREADY_EXISTS when it exists. */
|
|
140
|
+
create(data: Partial<T> & Record<string, unknown>): Promise<JsonObject>;
|
|
141
|
+
/** Change fields (dotted paths allowed); fails with 404 when the document doesn't exist. */
|
|
142
|
+
update(fields: Record<string, unknown>, opts?: {
|
|
143
|
+
version?: number;
|
|
144
|
+
}): Promise<JsonObject>;
|
|
145
|
+
delete(opts?: {
|
|
146
|
+
version?: number;
|
|
147
|
+
}): Promise<void>;
|
|
148
|
+
/** Live document: `callback` runs now and after every change. Returns a function that stops it. */
|
|
149
|
+
onSnapshot(callback: (doc: DocumentSnapshot<T>) => void, onError?: (error: unknown) => void): Promise<() => void>;
|
|
150
|
+
}
|
|
151
|
+
export declare class Query<T = JsonObject> {
|
|
152
|
+
private readonly sdk;
|
|
153
|
+
private readonly body;
|
|
154
|
+
readonly isGroup: boolean;
|
|
155
|
+
readonly path: string;
|
|
156
|
+
readonly id: string;
|
|
157
|
+
/**
|
|
158
|
+
* A collection, or with `isGroup` (`sov.collectionGroup('comments')`) every collection with that id at any
|
|
159
|
+
* depth; in a group, document cursors and `__key__` are full document paths.
|
|
160
|
+
*/
|
|
161
|
+
constructor(sdk: DocumentsTransport, path: string, body?: JsonObject, isGroup?: boolean);
|
|
162
|
+
private with;
|
|
163
|
+
where(field: string, op: WhereOp, value: unknown): Query<T>;
|
|
164
|
+
where(filter: QueryFilter): Query<T>;
|
|
165
|
+
orderBy(field: string, direction?: Direction): Query<T>;
|
|
166
|
+
limit(n: number): Query<T>;
|
|
167
|
+
limitToLast(n: number): Query<T>;
|
|
168
|
+
private cursor;
|
|
169
|
+
startAt(...values: unknown[]): Query<T>;
|
|
170
|
+
startAfter(...values: unknown[]): Query<T>;
|
|
171
|
+
endAt(...values: unknown[]): Query<T>;
|
|
172
|
+
endBefore(...values: unknown[]): Query<T>;
|
|
173
|
+
doc(id?: string): DocumentReference<T>;
|
|
174
|
+
add(data: Partial<T> & Record<string, unknown>): Promise<DocumentReference<T>>;
|
|
175
|
+
toJSON(): JsonObject;
|
|
176
|
+
/**
|
|
177
|
+
* Vector search like Firestore's `findNearest`: this query's `where` filters run first, then the `limit`
|
|
178
|
+
* documents whose `vectorField` is closest to `queryVector` come back closest first, each with `distance`.
|
|
179
|
+
*/
|
|
180
|
+
findNearest(opts: FindNearestOptions): VectorQuery<T>;
|
|
181
|
+
get(): Promise<QuerySnapshot<T>>;
|
|
182
|
+
count(): Promise<number>;
|
|
183
|
+
/**
|
|
184
|
+
* count / sum / average on the server, like Firestore's `getAggregateFromServer`:
|
|
185
|
+
* `await orders.where('paid', '==', true).aggregate({ n: count(), revenue: sum('total'), avg: average('total') })`.
|
|
186
|
+
* sum and average only use numeric values; average is null when there are none. With `limit`, they cover
|
|
187
|
+
* the first `limit` results; without, every match.
|
|
188
|
+
*/
|
|
189
|
+
aggregate<S extends Record<string, AggregateField>>(spec: S): Promise<{
|
|
190
|
+
[K in keyof S]: number | null;
|
|
191
|
+
}>;
|
|
192
|
+
/** Every matching document, one request per page. */
|
|
193
|
+
pages(pageSize?: number): AsyncGenerator<DocumentSnapshot<T>>;
|
|
194
|
+
/** Live results: `callback` runs with the first snapshot and after every change. Await it for the stop function. */
|
|
195
|
+
onSnapshot(callback: (snap: QuerySnapshot<T>) => void, onError?: (error: unknown) => void): Promise<() => void>;
|
|
196
|
+
}
|
|
197
|
+
export declare function newDocumentId(): string;
|
|
198
|
+
interface ChangeMessage {
|
|
199
|
+
type?: string;
|
|
200
|
+
listener_id?: string;
|
|
201
|
+
seq?: number;
|
|
202
|
+
part?: number;
|
|
203
|
+
parts?: number;
|
|
204
|
+
changes?: JsonObject[];
|
|
205
|
+
ids?: string[];
|
|
206
|
+
resync?: boolean;
|
|
207
|
+
}
|
|
208
|
+
export declare class LiveQuery<T = JsonObject> {
|
|
209
|
+
private readonly sdk;
|
|
210
|
+
private readonly query;
|
|
211
|
+
private readonly callback;
|
|
212
|
+
private readonly onError?;
|
|
213
|
+
id: string;
|
|
214
|
+
channel: string;
|
|
215
|
+
private docs;
|
|
216
|
+
private order;
|
|
217
|
+
private seq;
|
|
218
|
+
private pending;
|
|
219
|
+
private renewTimer?;
|
|
220
|
+
private socket?;
|
|
221
|
+
private pollTimer?;
|
|
222
|
+
private closed;
|
|
223
|
+
/** A server without collection-group listeners (older): the group query is re-run this often (ms). */
|
|
224
|
+
static groupPollMs: number;
|
|
225
|
+
constructor(sdk: DocumentsTransport, query: Query<T>, callback: (snap: QuerySnapshot<T>) => void, onError?: ((error: unknown) => void) | undefined);
|
|
226
|
+
start(): Promise<void>;
|
|
227
|
+
private emit;
|
|
228
|
+
applyFull(docs: DocumentSnapshot<T>[], initial?: boolean): void;
|
|
229
|
+
resync(): Promise<void>;
|
|
230
|
+
applyMessage(msg: ChangeMessage): Promise<void>;
|
|
231
|
+
close(): void;
|
|
232
|
+
}
|
|
233
|
+
export declare function commitWrites(sdk: DocumentsTransport, writes: JsonObject[], reads?: JsonObject[]): Promise<JsonObject>;
|
|
234
|
+
/** Writes committed together: every one or none (up to the plan's docs.max_transaction_writes). */
|
|
235
|
+
export declare class WriteBatch {
|
|
236
|
+
protected readonly sdk: DocumentsTransport;
|
|
237
|
+
protected writes: JsonObject[];
|
|
238
|
+
constructor(sdk: DocumentsTransport);
|
|
239
|
+
set(ref: DocumentReference<any>, data: Record<string, unknown>, opts?: {
|
|
240
|
+
merge?: boolean;
|
|
241
|
+
}): this;
|
|
242
|
+
create(ref: DocumentReference<any>, data: Record<string, unknown>): this;
|
|
243
|
+
update(ref: DocumentReference<any>, fields: Record<string, unknown>): this;
|
|
244
|
+
delete(ref: DocumentReference<any>): this;
|
|
245
|
+
commit(): Promise<JsonObject>;
|
|
246
|
+
}
|
|
247
|
+
export declare class Transaction extends WriteBatch {
|
|
248
|
+
private reads;
|
|
249
|
+
get<T = JsonObject>(ref: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
|
|
250
|
+
get hasWrites(): boolean;
|
|
251
|
+
commit(): Promise<JsonObject>;
|
|
252
|
+
}
|
|
253
|
+
/** Run `fn` and commit its writes atomically; retried when a document it read changed meanwhile. */
|
|
254
|
+
export declare function runTransaction<R>(sdk: DocumentsTransport, fn: (tx: Transaction) => Promise<R>, maxAttempts?: number): Promise<R>;
|
|
255
|
+
export {};
|