@pol-studios/db 1.0.17 → 1.0.19
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/dist/{chunk-FHVF26YA.js → chunk-2T6WTCP4.js} +56 -27
- package/dist/chunk-2T6WTCP4.js.map +1 -0
- package/dist/{chunk-PMRV6WND.js → chunk-R5B2XMN5.js} +57 -13
- package/dist/chunk-R5B2XMN5.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.native.js +2 -2
- package/dist/index.web.js +1 -1
- package/package.json +1 -1
- package/dist/DataLayerContext-Cm1nAvT7.d.ts +0 -807
- package/dist/EntityPermissions-DwFt4tUd.d.ts +0 -35
- package/dist/FilterConfig-Bt2Ek74z.d.ts +0 -99
- package/dist/UserMetadataContext-B8gVWGMl.d.ts +0 -35
- package/dist/UserMetadataContext-DntmpK41.d.ts +0 -33
- package/dist/auth/context.d.ts +0 -48
- package/dist/auth/guards.d.ts +0 -180
- package/dist/auth/hooks.d.ts +0 -312
- package/dist/auth/index.d.ts +0 -11
- package/dist/chunk-FHVF26YA.js.map +0 -1
- package/dist/chunk-PMRV6WND.js.map +0 -1
- package/dist/client/index.d.ts +0 -16
- package/dist/core/index.d.ts +0 -527
- package/dist/database.types-ChFCG-4M.d.ts +0 -8604
- package/dist/executor-CB4KHyYG.d.ts +0 -507
- package/dist/gen/index.d.ts +0 -1099
- package/dist/hooks/index.d.ts +0 -100
- package/dist/index-BHFInYVr.d.ts +0 -433
- package/dist/index.d.ts +0 -33
- package/dist/index.native.d.ts +0 -773
- package/dist/index.web.d.ts +0 -321
- package/dist/mutation/index.d.ts +0 -58
- package/dist/parser/index.d.ts +0 -366
- package/dist/powersync-bridge/index.d.ts +0 -284
- package/dist/query/index.d.ts +0 -723
- package/dist/realtime/index.d.ts +0 -44
- package/dist/select-query-parser-BwyHum1L.d.ts +0 -352
- package/dist/setupAuthContext-Kv-THH-h.d.ts +0 -61
- package/dist/types/index.d.ts +0 -10
- package/dist/types-CYr9JiUE.d.ts +0 -62
- package/dist/useBatchUpsert-9OYjibLh.d.ts +0 -24
- package/dist/useDbCount-Cu2Q5ZdH.d.ts +0 -1082
- package/dist/useDbQuery-C-TL8jY1.d.ts +0 -19
- package/dist/useReceiptAI-6HkRpRml.d.ts +0 -58
- package/dist/useResolveFeedback-Bg3JDRs8.d.ts +0 -997
- package/dist/useSupabase-DvWVuHHE.d.ts +0 -28
- package/dist/with-auth/index.d.ts +0 -704
package/dist/parser/index.d.ts
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import { PostgrestBuilder, PostgrestSingleResponse, PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestQueryBuilder } from '@supabase/postgrest-js';
|
|
2
|
-
export { G as GetResult, S as SelectQueryError } from '../select-query-parser-BwyHum1L.js';
|
|
3
|
-
export { F as Fetch, i as GenericFunction, g as GenericNonUpdatableView, j as GenericSchema, G as GenericTable, f as GenericUpdatableView, h as GenericView, P as PostgrestError, d as PostgrestMaybeSingleResponse, e as PostgrestResponse, b as PostgrestResponseFailure, a as PostgrestResponseSuccess, c as PostgrestSingleResponse, k as Prettify } from '../types-CYr9JiUE.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A function that validates whether the given input is an object of type Type
|
|
7
|
-
* @returns true if obj is of type Type, false if not
|
|
8
|
-
*/
|
|
9
|
-
type FilterFn<Type extends Record<string, unknown>> = (obj: unknown) => obj is Type;
|
|
10
|
-
/**
|
|
11
|
-
* The supported value types
|
|
12
|
-
*/
|
|
13
|
-
type ValueType = number | string | boolean | null | Date | object;
|
|
14
|
-
/**
|
|
15
|
-
* A function implementing a FilterOperators
|
|
16
|
-
* @param columnValue the value of the input object to test the filter against
|
|
17
|
-
* @param filterValue the value of the filter, e.g. in .eq('colname', 'filterValue'), 'filterValue' would be the filterValue
|
|
18
|
-
* @returns true if the filter applies, false if not
|
|
19
|
-
*/
|
|
20
|
-
type OperatorFn = (columnValue: any, filterValue: any) => boolean;
|
|
21
|
-
/**
|
|
22
|
-
* All supported operators of PostgREST
|
|
23
|
-
*/
|
|
24
|
-
type PostgrestFilterOperator = 'or' | 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'like' | 'ilike' | 'is' | 'in' | 'cs' | 'cd' | 'fts' | 'plfts';
|
|
25
|
-
/**
|
|
26
|
-
* An object describing a selected path of a query
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
type Path = {
|
|
30
|
-
/**
|
|
31
|
-
* The aliased path if a column or relation name mapping is used within the path
|
|
32
|
-
*/
|
|
33
|
-
alias?: string;
|
|
34
|
-
/**
|
|
35
|
-
* The "real" path of a column
|
|
36
|
-
*/
|
|
37
|
-
path: string;
|
|
38
|
-
/**
|
|
39
|
-
* The full declaration of a column that includes alias, hints and inner joins
|
|
40
|
-
*/
|
|
41
|
-
declaration: string;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* A decomposed filter applied to a query
|
|
45
|
-
*/
|
|
46
|
-
type FilterDefinition = {
|
|
47
|
-
/**
|
|
48
|
-
* The path to which the filter is applied
|
|
49
|
-
*/
|
|
50
|
-
path: string;
|
|
51
|
-
/**
|
|
52
|
-
* The aliased path if a column or relation name mapping is used
|
|
53
|
-
*/
|
|
54
|
-
alias?: string;
|
|
55
|
-
/**
|
|
56
|
-
* The operator that is applied
|
|
57
|
-
*/
|
|
58
|
-
operator: PostgrestFilterOperator;
|
|
59
|
-
/**
|
|
60
|
-
* Whether or not to negate the results of the filter, e.g. when .not('name', 'eq', 'Paris') is applied
|
|
61
|
-
*/
|
|
62
|
-
negate: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* The value of the filter
|
|
65
|
-
*/
|
|
66
|
-
value: ValueType;
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* A json representation of PostgREST filters that are applied to a query
|
|
70
|
-
*/
|
|
71
|
-
type FilterDefinitions = ({
|
|
72
|
-
or: FilterDefinitions;
|
|
73
|
-
} | {
|
|
74
|
-
and: FilterDefinitions;
|
|
75
|
-
} | FilterDefinition)[];
|
|
76
|
-
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
|
77
|
-
declare const isAndFilter: (f: ArrayElement<FilterDefinitions>) => f is {
|
|
78
|
-
and: FilterDefinitions;
|
|
79
|
-
};
|
|
80
|
-
declare const isOrFilter: (f: ArrayElement<FilterDefinitions>) => f is {
|
|
81
|
-
or: FilterDefinitions;
|
|
82
|
-
};
|
|
83
|
-
declare const isFilterDefinition: (f: ArrayElement<FilterDefinitions>) => f is FilterDefinition;
|
|
84
|
-
type OrderDefinition = {
|
|
85
|
-
column: string;
|
|
86
|
-
ascending: boolean;
|
|
87
|
-
nullsFirst: boolean;
|
|
88
|
-
foreignTable?: string;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
declare const SUPPORTED_OPERATORS: string[];
|
|
92
|
-
type PostgrestQueryParserOptions = {
|
|
93
|
-
/**
|
|
94
|
-
* If defined, will use only filters that apply to the given paths
|
|
95
|
-
*/
|
|
96
|
-
exclusivePaths?: string[];
|
|
97
|
-
};
|
|
98
|
-
declare class PostgrestQueryParser {
|
|
99
|
-
readonly opts?: PostgrestQueryParserOptions;
|
|
100
|
-
private readonly _params;
|
|
101
|
-
private _filters;
|
|
102
|
-
private _paths;
|
|
103
|
-
constructor(query: string, opts?: PostgrestQueryParserOptions);
|
|
104
|
-
/**
|
|
105
|
-
* Getter that returns the paths and their aliases that the query selects. Will do the computation only once.
|
|
106
|
-
*
|
|
107
|
-
* ```js
|
|
108
|
-
* const p = new PostgrestParser(
|
|
109
|
-
* supabaseClient.from("test")
|
|
110
|
-
* .select(
|
|
111
|
-
* `name,
|
|
112
|
-
* city:cities (
|
|
113
|
-
* test:name
|
|
114
|
-
* ),
|
|
115
|
-
* countries (
|
|
116
|
-
* capital,
|
|
117
|
-
* population,
|
|
118
|
-
* some_ref (
|
|
119
|
-
* test:first,
|
|
120
|
-
* second
|
|
121
|
-
* )
|
|
122
|
-
* )`
|
|
123
|
-
* );
|
|
124
|
-
* console.log(p.paths);
|
|
125
|
-
* // [
|
|
126
|
-
* // { alias: undefined, path: "name" },
|
|
127
|
-
* // { alias: "city.test", path: "cities.name" },
|
|
128
|
-
* // { alias: undefined, path: "countries.capital" },
|
|
129
|
-
* // { alias: undefined, path: "countries.population" },
|
|
130
|
-
* // {
|
|
131
|
-
* // alias: "countries.some_ref.test",
|
|
132
|
-
* // path: "countries.some_ref.first",
|
|
133
|
-
* // },
|
|
134
|
-
* // { alias: undefined, path: "countries.some_ref.second" },
|
|
135
|
-
* // ];
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
* @returns an array of paths that the query selects, containing the columns and aliases
|
|
139
|
-
*/
|
|
140
|
-
get paths(): Path[];
|
|
141
|
-
/**
|
|
142
|
-
* Getter that returns the filters that this query applies in a json object.
|
|
143
|
-
*
|
|
144
|
-
* ```js
|
|
145
|
-
* const p = new PostgrestParser(
|
|
146
|
-
* supabaseClient.from("test").select('*')
|
|
147
|
-
* .or("full_name.eq.20,test.neq.true,and(full_name.eq.Test Name,email.eq.test@mail.com)")
|
|
148
|
-
* .eq("id", "123")
|
|
149
|
-
* .contains("id", "456")
|
|
150
|
-
* );
|
|
151
|
-
*
|
|
152
|
-
* console.log(p.filters);
|
|
153
|
-
*
|
|
154
|
-
* // [
|
|
155
|
-
* // {
|
|
156
|
-
* // or: [
|
|
157
|
-
* // {
|
|
158
|
-
* // path: "full_name",
|
|
159
|
-
* // negate: false,
|
|
160
|
-
* // operator: "eq",
|
|
161
|
-
* // value: 20,
|
|
162
|
-
* // },
|
|
163
|
-
* // {
|
|
164
|
-
* // path: "test",
|
|
165
|
-
* // negate: false,
|
|
166
|
-
* // operator: "neq",
|
|
167
|
-
* // value: true,
|
|
168
|
-
* // },
|
|
169
|
-
* // {
|
|
170
|
-
* // and: [
|
|
171
|
-
* // {
|
|
172
|
-
* // path: "full_name",
|
|
173
|
-
* // negate: false,
|
|
174
|
-
* // operator: "eq",
|
|
175
|
-
* // value: "Test Name",
|
|
176
|
-
* // },
|
|
177
|
-
* // {
|
|
178
|
-
* // path: "email",
|
|
179
|
-
* // negate: false,
|
|
180
|
-
* // operator: "eq",
|
|
181
|
-
* // value: "test@mail.com",
|
|
182
|
-
* // },
|
|
183
|
-
* // ],
|
|
184
|
-
* // },
|
|
185
|
-
* // ],
|
|
186
|
-
* // },
|
|
187
|
-
* // {
|
|
188
|
-
* // path: "id",
|
|
189
|
-
* // negate: false,
|
|
190
|
-
* // operator: "eq",
|
|
191
|
-
* // value: 123,
|
|
192
|
-
* // },
|
|
193
|
-
* // {
|
|
194
|
-
* // path: "id",
|
|
195
|
-
* // negate: false,
|
|
196
|
-
* // operator: "cs",
|
|
197
|
-
* // value: 456,
|
|
198
|
-
* // },
|
|
199
|
-
* // ];
|
|
200
|
-
* ```
|
|
201
|
-
*
|
|
202
|
-
* @returns a FilterDefinitions object
|
|
203
|
-
*/
|
|
204
|
-
get filters(): FilterDefinitions;
|
|
205
|
-
private parseFilterString;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
declare class PostgrestParser<Result> extends PostgrestQueryParser {
|
|
209
|
-
readonly opts?: PostgrestQueryParserOptions;
|
|
210
|
-
private readonly _url;
|
|
211
|
-
private readonly _headers;
|
|
212
|
-
private readonly _body;
|
|
213
|
-
readonly method: "GET" | "HEAD" | "POST" | "PATCH" | "DELETE";
|
|
214
|
-
readonly select: string;
|
|
215
|
-
readonly queryKey: string;
|
|
216
|
-
readonly bodyKey: string | undefined;
|
|
217
|
-
readonly count: string | null;
|
|
218
|
-
readonly schema: string;
|
|
219
|
-
readonly table: string;
|
|
220
|
-
readonly isHead: boolean | undefined;
|
|
221
|
-
readonly limit: number | undefined;
|
|
222
|
-
readonly offset: number | undefined;
|
|
223
|
-
readonly orderBy: OrderDefinition[];
|
|
224
|
-
readonly orderByKey: string;
|
|
225
|
-
readonly searchParams: URLSearchParams;
|
|
226
|
-
constructor(fb: PostgrestBuilder<any, Result>, opts?: PostgrestQueryParserOptions);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
declare class PostgrestFilter<Result extends Record<string, unknown>> {
|
|
230
|
-
readonly params: {
|
|
231
|
-
filters: FilterDefinitions;
|
|
232
|
-
paths: Path[];
|
|
233
|
-
};
|
|
234
|
-
private _fn;
|
|
235
|
-
private _selectFn;
|
|
236
|
-
private _filtersFn;
|
|
237
|
-
private _filterPaths;
|
|
238
|
-
constructor(params: {
|
|
239
|
-
filters: FilterDefinitions;
|
|
240
|
-
paths: Path[];
|
|
241
|
-
});
|
|
242
|
-
static fromQuery(query: string, opts?: PostgrestQueryParserOptions): PostgrestFilter<Record<string, unknown>>;
|
|
243
|
-
static fromBuilder<Result extends Record<string, unknown> = Record<string, unknown>>(fb: PostgrestBuilder<any, Result>, opts?: PostgrestQueryParserOptions): PostgrestFilter<Result>;
|
|
244
|
-
denormalize<Type extends Record<string, unknown>>(obj: Type): Type;
|
|
245
|
-
apply(obj: unknown): obj is Result;
|
|
246
|
-
applyFilters(obj: unknown): obj is Result;
|
|
247
|
-
hasFiltersOnPaths(paths: string[]): boolean;
|
|
248
|
-
applyFiltersOnPaths(obj: unknown, paths: string[]): obj is Result;
|
|
249
|
-
hasPaths(obj: unknown): obj is Result;
|
|
250
|
-
private hasPathRecursive;
|
|
251
|
-
private applyFilterFn;
|
|
252
|
-
private buildFilterFn;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Denormalize a normalized response object using the paths of the target query
|
|
257
|
-
* **/
|
|
258
|
-
declare const denormalize: <R extends Record<string, unknown>>(paths: Path[], obj: R) => R;
|
|
259
|
-
|
|
260
|
-
declare function binarySearch<Type>(arr: Type[], el: Type, compare: (a: Type, b: Type) => number): number;
|
|
261
|
-
|
|
262
|
-
type AnyPostgrestResponse<Result> = PostgrestSingleResponse<Result> | PostgrestMaybeSingleResponse<Result> | PostgrestResponse<Result>;
|
|
263
|
-
declare const isAnyPostgrestResponse: <Result>(q: unknown) => q is AnyPostgrestResponse<Result>;
|
|
264
|
-
type PostgrestPaginationResponse<Result> = Result[];
|
|
265
|
-
declare const isPostgrestPaginationResponse: <Result>(q: unknown) => q is PostgrestPaginationResponse<Result>;
|
|
266
|
-
type PostgrestHasMorePaginationResponse<Result> = {
|
|
267
|
-
data: Result[];
|
|
268
|
-
hasMore: boolean;
|
|
269
|
-
};
|
|
270
|
-
declare const isPostgrestHasMorePaginationResponse: <Result>(q: unknown) => q is PostgrestHasMorePaginationResponse<Result>;
|
|
271
|
-
|
|
272
|
-
type PostgrestPaginationCacheData<Result> = Result[][];
|
|
273
|
-
declare const isPostgrestPaginationCacheData: <Result>(q: unknown) => q is PostgrestPaginationCacheData<Result>;
|
|
274
|
-
type PostgrestHasMorePaginationCacheData<Result> = PostgrestHasMorePaginationResponse<Result>[];
|
|
275
|
-
declare const isPostgrestHasMorePaginationCacheData: <Result>(q: unknown) => q is PostgrestHasMorePaginationCacheData<Result>;
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Encodes an object by url-encoding an ordered lists of all paths and their values.
|
|
279
|
-
*/
|
|
280
|
-
declare const encodeObject: (obj: Record<string, unknown>) => string;
|
|
281
|
-
|
|
282
|
-
declare const extractPathsFromFilters: (f: FilterDefinitions, p: Path[]) => Path[];
|
|
283
|
-
|
|
284
|
-
declare const filterFilterDefinitionsByPaths: (f: FilterDefinitions, paths: string[]) => FilterDefinitions;
|
|
285
|
-
|
|
286
|
-
declare const findFilters: (f: FilterDefinitions, by: Partial<FilterDefinition>) => FilterDefinition[];
|
|
287
|
-
|
|
288
|
-
declare const findIndexOrdered: <Type extends Record<string, unknown>>(input: Type, currentData: Type[], orderBy: OrderDefinition[]) => number;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Returns the index of the last element in the array where predicate is true, and -1
|
|
292
|
-
* otherwise.
|
|
293
|
-
* @param array The source array to search in
|
|
294
|
-
* @param predicate find calls predicate once for each element of the array, in descending
|
|
295
|
-
* order, until it finds one where predicate returns true. If such an element is found,
|
|
296
|
-
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
|
|
297
|
-
*/
|
|
298
|
-
declare function findLastIndex<T>(array: T[], predicate: (value: T, index: number, obj: T[]) => boolean): number;
|
|
299
|
-
|
|
300
|
-
declare const get: (obj: any, path: string, defaultValue?: any) => any;
|
|
301
|
-
|
|
302
|
-
declare const getTable: (query: PostgrestBuilder<any, any> | PostgrestQueryBuilder<any, any, any>) => string;
|
|
303
|
-
|
|
304
|
-
type NestedPath = {
|
|
305
|
-
alias?: string;
|
|
306
|
-
path: string;
|
|
307
|
-
declaration: string;
|
|
308
|
-
paths: (Path | NestedPath)[];
|
|
309
|
-
};
|
|
310
|
-
declare const isNestedPath: (p: Path | NestedPath) => p is NestedPath;
|
|
311
|
-
declare const groupPathsRecursive: (paths: Path[]) => (Path | NestedPath)[];
|
|
312
|
-
|
|
313
|
-
declare const ifDateGetTime: (v: unknown) => unknown;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Check if a value is a valid ISO DateTime string
|
|
317
|
-
* @param v
|
|
318
|
-
* @returns
|
|
319
|
-
*/
|
|
320
|
-
declare const isISODateString: (v: unknown) => boolean;
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
*
|
|
324
|
-
* @param i Ahhh gotta love typescript
|
|
325
|
-
* @returns
|
|
326
|
-
*/
|
|
327
|
-
declare const isNotNull: <I>(i: I | null) => i is I;
|
|
328
|
-
|
|
329
|
-
declare const isObject: (v: unknown) => v is Record<string, unknown>;
|
|
330
|
-
|
|
331
|
-
declare const isPostgrestBuilder: <Result>(q: unknown) => q is PostgrestBuilder<any, Result>;
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* An object containing all PostgrestFilterOperator implementations
|
|
335
|
-
*/
|
|
336
|
-
declare const OPERATOR_MAP: {
|
|
337
|
-
[Key in PostgrestFilterOperator]?: OperatorFn;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Parses orderByKey back to OrderDefinition
|
|
342
|
-
* @param key generated by PostgrestParser
|
|
343
|
-
* @returns The parsed OrderDefinition
|
|
344
|
-
*/
|
|
345
|
-
declare const parseOrderByKey: (v: string) => OrderDefinition[];
|
|
346
|
-
|
|
347
|
-
declare const parseSelectParam: (s: string, currentPath?: Path) => Path[];
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Safely parse any value to a ValueType
|
|
351
|
-
* @param v Any value
|
|
352
|
-
* @returns a ValueType
|
|
353
|
-
*/
|
|
354
|
-
declare const parseValue: (v: any) => ValueType;
|
|
355
|
-
|
|
356
|
-
declare const removeAliasFromDeclaration: (d: string) => string;
|
|
357
|
-
|
|
358
|
-
declare const removeFirstPathElement: (p: Path) => Path;
|
|
359
|
-
|
|
360
|
-
declare const setFilterValue: (searchParams: URLSearchParams, path: string, op: string, value: string) => void;
|
|
361
|
-
|
|
362
|
-
declare const sortSearchParams: (params: URLSearchParams) => URLSearchParams;
|
|
363
|
-
|
|
364
|
-
declare const buildSortedComparator: <Type extends Record<string, unknown>>(orderBy: OrderDefinition[]) => (a: Type, b: Type) => 0 | 1 | -1;
|
|
365
|
-
|
|
366
|
-
export { type AnyPostgrestResponse, type FilterDefinition, type FilterDefinitions, type FilterFn, type NestedPath, OPERATOR_MAP, type OperatorFn, type OrderDefinition, type Path, PostgrestFilter, type PostgrestFilterOperator, type PostgrestHasMorePaginationCacheData, type PostgrestHasMorePaginationResponse, type PostgrestPaginationCacheData, type PostgrestPaginationResponse, PostgrestParser, PostgrestQueryParser, type PostgrestQueryParserOptions, SUPPORTED_OPERATORS, type ValueType, binarySearch, buildSortedComparator, denormalize, encodeObject, extractPathsFromFilters, filterFilterDefinitionsByPaths, findFilters, findIndexOrdered, findLastIndex, get, getTable, groupPathsRecursive, ifDateGetTime, isAndFilter, isAnyPostgrestResponse, isFilterDefinition, isISODateString, isNestedPath, isNotNull, isObject, isOrFilter, isPostgrestBuilder, isPostgrestHasMorePaginationCacheData, isPostgrestHasMorePaginationResponse, isPostgrestPaginationCacheData, isPostgrestPaginationResponse, parseOrderByKey, parseSelectParam, parseValue, removeAliasFromDeclaration, removeFirstPathElement, setFilterValue, sortSearchParams };
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import { SyncStatus, SyncControl } from '../core/index.js';
|
|
2
|
-
export { P as PowerSyncDatabase } from '../executor-CB4KHyYG.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* PowerSync Bridge for @pol-studios/db
|
|
6
|
-
*
|
|
7
|
-
* This module provides integration utilities between @pol-studios/db and
|
|
8
|
-
* @pol-studios/powersync packages. It re-exports key types and provides
|
|
9
|
-
* helper functions for type-safe integration.
|
|
10
|
-
*
|
|
11
|
-
* The @pol-studios/powersync package is an optional peer dependency.
|
|
12
|
-
* This bridge allows the db package to work seamlessly with or without
|
|
13
|
-
* the powersync package installed.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* import { isPowerSyncAvailable, usePowerSyncDatabase } from '@pol-studios/db/powersync-bridge';
|
|
18
|
-
*
|
|
19
|
-
* if (isPowerSyncAvailable()) {
|
|
20
|
-
* // Use PowerSync features
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
/**
|
|
25
|
-
* Re-export core types from @pol-studios/powersync for convenience.
|
|
26
|
-
* These types are defined here to avoid runtime dependency on the package.
|
|
27
|
-
*/
|
|
28
|
-
/**
|
|
29
|
-
* Abstract interface for PowerSync database operations.
|
|
30
|
-
* This matches the interface from @pol-studios/powersync/core.
|
|
31
|
-
*/
|
|
32
|
-
interface AbstractPowerSyncDatabase {
|
|
33
|
-
/** Execute a query and return all results */
|
|
34
|
-
getAll<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
35
|
-
/** Execute a query and return first result or null */
|
|
36
|
-
get<T>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
37
|
-
/** Execute a SQL statement (INSERT, UPDATE, DELETE) */
|
|
38
|
-
execute(sql: string, params?: unknown[]): Promise<{
|
|
39
|
-
rowsAffected: number;
|
|
40
|
-
}>;
|
|
41
|
-
/** Whether the database is currently connected */
|
|
42
|
-
connected: boolean;
|
|
43
|
-
/** Current sync status */
|
|
44
|
-
currentStatus: {
|
|
45
|
-
connected: boolean;
|
|
46
|
-
connecting: boolean;
|
|
47
|
-
hasSynced: boolean;
|
|
48
|
-
lastSyncedAt: Date | null;
|
|
49
|
-
dataFlowStatus?: {
|
|
50
|
-
uploading: boolean;
|
|
51
|
-
downloading: boolean;
|
|
52
|
-
};
|
|
53
|
-
downloadProgress?: {
|
|
54
|
-
downloadedFraction: number;
|
|
55
|
-
downloadedOperations: number;
|
|
56
|
-
totalOperations: number;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
/** Initialize the database */
|
|
60
|
-
init(): Promise<void>;
|
|
61
|
-
/** Close the database connection */
|
|
62
|
-
close(): Promise<void>;
|
|
63
|
-
/** Connect to the PowerSync service */
|
|
64
|
-
connect(connector: unknown): Promise<void>;
|
|
65
|
-
/** Disconnect from the PowerSync service */
|
|
66
|
-
disconnect(): Promise<void>;
|
|
67
|
-
/** Register a listener for status changes */
|
|
68
|
-
registerListener(listener: {
|
|
69
|
-
statusChanged?: (status: unknown) => void;
|
|
70
|
-
}): () => void;
|
|
71
|
-
/** Get the next pending CRUD transaction */
|
|
72
|
-
getNextCrudTransaction(): Promise<unknown>;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Sync status from @pol-studios/powersync.
|
|
76
|
-
*/
|
|
77
|
-
interface PowerSyncSyncStatus {
|
|
78
|
-
/** Whether connected to the PowerSync service */
|
|
79
|
-
connected: boolean;
|
|
80
|
-
/** Whether currently attempting to connect */
|
|
81
|
-
connecting: boolean;
|
|
82
|
-
/** Whether initial sync has completed */
|
|
83
|
-
hasSynced: boolean;
|
|
84
|
-
/** Timestamp of last successful sync */
|
|
85
|
-
lastSyncedAt: Date | null;
|
|
86
|
-
/** Whether currently uploading local changes */
|
|
87
|
-
uploading: boolean;
|
|
88
|
-
/** Whether currently downloading remote changes */
|
|
89
|
-
downloading: boolean;
|
|
90
|
-
/** Download progress details */
|
|
91
|
-
downloadProgress: {
|
|
92
|
-
current: number;
|
|
93
|
-
target: number;
|
|
94
|
-
percentage: number;
|
|
95
|
-
} | null;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Connection health status from @pol-studios/powersync.
|
|
99
|
-
*/
|
|
100
|
-
interface PowerSyncConnectionHealth {
|
|
101
|
-
/** Current connection status */
|
|
102
|
-
status: "healthy" | "degraded" | "disconnected";
|
|
103
|
-
/** Last measured query latency in milliseconds */
|
|
104
|
-
latency: number | null;
|
|
105
|
-
/** Timestamp of the last health check */
|
|
106
|
-
lastHealthCheck: Date | null;
|
|
107
|
-
/** Number of consecutive health check failures */
|
|
108
|
-
consecutiveFailures: number;
|
|
109
|
-
/** Total reconnection attempts since last successful connection */
|
|
110
|
-
reconnectAttempts: number;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Sync metrics from @pol-studios/powersync.
|
|
114
|
-
*/
|
|
115
|
-
interface PowerSyncMetrics {
|
|
116
|
-
/** Total number of sync operations attempted */
|
|
117
|
-
totalSyncs: number;
|
|
118
|
-
/** Number of successful sync operations */
|
|
119
|
-
successfulSyncs: number;
|
|
120
|
-
/** Number of failed sync operations */
|
|
121
|
-
failedSyncs: number;
|
|
122
|
-
/** Duration of the last sync in milliseconds */
|
|
123
|
-
lastSyncDuration: number | null;
|
|
124
|
-
/** Average sync duration in milliseconds */
|
|
125
|
-
averageSyncDuration: number | null;
|
|
126
|
-
/** Total bytes downloaded across all syncs */
|
|
127
|
-
totalDataDownloaded: number;
|
|
128
|
-
/** Total bytes uploaded across all syncs */
|
|
129
|
-
totalDataUploaded: number;
|
|
130
|
-
/** Last sync error details */
|
|
131
|
-
lastError: {
|
|
132
|
-
type: string;
|
|
133
|
-
message: string;
|
|
134
|
-
timestamp: Date;
|
|
135
|
-
} | null;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Sync control actions from @pol-studios/powersync.
|
|
139
|
-
*/
|
|
140
|
-
interface PowerSyncControlActions {
|
|
141
|
-
/** Trigger a sync operation */
|
|
142
|
-
triggerSync: () => Promise<void>;
|
|
143
|
-
/** Pause sync operations */
|
|
144
|
-
pause: () => Promise<void>;
|
|
145
|
-
/** Resume sync operations */
|
|
146
|
-
resume: () => Promise<void>;
|
|
147
|
-
/** Disconnect from the PowerSync service */
|
|
148
|
-
disconnect: () => Promise<void>;
|
|
149
|
-
/** Set the sync scope for selective sync */
|
|
150
|
-
setScope: (scope: {
|
|
151
|
-
type: string;
|
|
152
|
-
ids: string[];
|
|
153
|
-
} | null) => void;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Check if @pol-studios/powersync is available.
|
|
157
|
-
*
|
|
158
|
-
* This function performs a lazy check to see if the powersync package
|
|
159
|
-
* is installed and can be imported. The result is cached for subsequent calls.
|
|
160
|
-
*
|
|
161
|
-
* @returns true if @pol-studios/powersync is available, false otherwise
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```typescript
|
|
165
|
-
* import { isPowerSyncAvailable } from '@pol-studios/db/powersync-bridge';
|
|
166
|
-
*
|
|
167
|
-
* if (isPowerSyncAvailable()) {
|
|
168
|
-
* // Safe to use PowerSync features
|
|
169
|
-
* const { usePowerSync } = await import('@pol-studios/powersync');
|
|
170
|
-
* }
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
declare function isPowerSyncAvailable(): boolean;
|
|
174
|
-
/**
|
|
175
|
-
* Reset the availability check cache.
|
|
176
|
-
* Useful for testing or when package installation state might change.
|
|
177
|
-
*/
|
|
178
|
-
declare function resetPowerSyncAvailabilityCache(): void;
|
|
179
|
-
/**
|
|
180
|
-
* Type guard to check if a value is an AbstractPowerSyncDatabase.
|
|
181
|
-
*
|
|
182
|
-
* @param value - The value to check
|
|
183
|
-
* @returns true if value implements AbstractPowerSyncDatabase interface
|
|
184
|
-
*/
|
|
185
|
-
declare function isAbstractPowerSyncDatabase(value: unknown): value is AbstractPowerSyncDatabase;
|
|
186
|
-
/**
|
|
187
|
-
* Type guard to check if a value is a PowerSyncSyncStatus.
|
|
188
|
-
*
|
|
189
|
-
* @param value - The value to check
|
|
190
|
-
* @returns true if value matches PowerSyncSyncStatus interface
|
|
191
|
-
*/
|
|
192
|
-
declare function isPowerSyncSyncStatus(value: unknown): value is PowerSyncSyncStatus;
|
|
193
|
-
/**
|
|
194
|
-
* Convert PowerSync sync status to the V3 DataLayer SyncStatus format.
|
|
195
|
-
*
|
|
196
|
-
* This utility helps bridge the sync status from @pol-studios/powersync
|
|
197
|
-
* to the format expected by @pol-studios/db's DataLayerProvider.
|
|
198
|
-
*
|
|
199
|
-
* @param powerSyncStatus - The sync status from @pol-studios/powersync
|
|
200
|
-
* @param pendingCount - Number of pending uploads (from pendingMutations)
|
|
201
|
-
* @returns SyncStatus in @pol-studios/db format
|
|
202
|
-
*/
|
|
203
|
-
declare function convertToDataLayerSyncStatus(powerSyncStatus: PowerSyncSyncStatus, pendingCount?: number): SyncStatus;
|
|
204
|
-
/**
|
|
205
|
-
* Convert PowerSync sync control to the V3 DataLayer SyncControl format.
|
|
206
|
-
*
|
|
207
|
-
* @param powerSyncControl - The sync control actions from @pol-studios/powersync
|
|
208
|
-
* @returns SyncControl in @pol-studios/db format
|
|
209
|
-
*/
|
|
210
|
-
declare function convertToDataLayerSyncControl(powerSyncControl: PowerSyncControlActions): SyncControl;
|
|
211
|
-
/**
|
|
212
|
-
* Create a database instance getter that works with PowerSync context.
|
|
213
|
-
*
|
|
214
|
-
* This is useful for integrating PowerSyncProvider with DataLayerProvider
|
|
215
|
-
* by providing a way to get the database instance from the PowerSync context.
|
|
216
|
-
*
|
|
217
|
-
* @param getPowerSyncDb - Function to get the PowerSync database from context
|
|
218
|
-
* @returns A function that returns the database or null
|
|
219
|
-
*/
|
|
220
|
-
declare function createDatabaseGetter(getPowerSyncDb: () => AbstractPowerSyncDatabase | null): () => AbstractPowerSyncDatabase | null;
|
|
221
|
-
/**
|
|
222
|
-
* Options for setting up DataLayerProvider with PowerSync integration.
|
|
223
|
-
*/
|
|
224
|
-
interface PowerSyncIntegrationOptions {
|
|
225
|
-
/**
|
|
226
|
-
* The PowerSync database instance from PowerSyncProvider.
|
|
227
|
-
*/
|
|
228
|
-
database: AbstractPowerSyncDatabase | null;
|
|
229
|
-
/**
|
|
230
|
-
* Whether the PowerSync database is ready.
|
|
231
|
-
*/
|
|
232
|
-
isReady: boolean;
|
|
233
|
-
/**
|
|
234
|
-
* Current sync status from PowerSyncProvider.
|
|
235
|
-
*/
|
|
236
|
-
syncStatus?: PowerSyncSyncStatus;
|
|
237
|
-
/**
|
|
238
|
-
* Sync control actions from PowerSyncProvider.
|
|
239
|
-
*/
|
|
240
|
-
syncControl?: PowerSyncControlActions;
|
|
241
|
-
/**
|
|
242
|
-
* Number of pending mutations.
|
|
243
|
-
*/
|
|
244
|
-
pendingCount?: number;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Get the powerSyncInstance prop for DataLayerProvider from PowerSync context values.
|
|
248
|
-
*
|
|
249
|
-
* This helper extracts the necessary values from @pol-studios/powersync hooks
|
|
250
|
-
* and returns them in a format suitable for DataLayerProvider.
|
|
251
|
-
*
|
|
252
|
-
* @param options - The PowerSync integration options
|
|
253
|
-
* @returns The powerSyncInstance to pass to DataLayerProvider, or null if not ready
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```typescript
|
|
257
|
-
* // Inside a component wrapped with PowerSyncProvider
|
|
258
|
-
* const { db, isReady } = usePowerSync();
|
|
259
|
-
* const { status, pendingCount } = useSyncStatus();
|
|
260
|
-
* const syncControl = useSyncControl();
|
|
261
|
-
*
|
|
262
|
-
* const powerSyncInstance = getPowerSyncInstance({
|
|
263
|
-
* database: db,
|
|
264
|
-
* isReady,
|
|
265
|
-
* syncStatus: status,
|
|
266
|
-
* syncControl,
|
|
267
|
-
* pendingCount,
|
|
268
|
-
* });
|
|
269
|
-
*
|
|
270
|
-
* return (
|
|
271
|
-
* <DataLayerProvider
|
|
272
|
-
* config={config}
|
|
273
|
-
* powerSyncInstance={powerSyncInstance}
|
|
274
|
-
* supabaseClient={supabase}
|
|
275
|
-
* queryClient={queryClient}
|
|
276
|
-
* >
|
|
277
|
-
* {children}
|
|
278
|
-
* </DataLayerProvider>
|
|
279
|
-
* );
|
|
280
|
-
* ```
|
|
281
|
-
*/
|
|
282
|
-
declare function getPowerSyncInstance(options: PowerSyncIntegrationOptions): AbstractPowerSyncDatabase | null;
|
|
283
|
-
|
|
284
|
-
export { type AbstractPowerSyncDatabase, type PowerSyncConnectionHealth, type PowerSyncControlActions, type PowerSyncIntegrationOptions, type PowerSyncMetrics, type PowerSyncSyncStatus, convertToDataLayerSyncControl, convertToDataLayerSyncStatus, createDatabaseGetter, getPowerSyncInstance, isAbstractPowerSyncDatabase, isPowerSyncAvailable, isPowerSyncSyncStatus, resetPowerSyncAvailabilityCache };
|