lazypock 0.3.0 → 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/README.md +75 -98
- package/dist/{chunk-Y6PMBL2S.js → chunk-HOBNUW5Z.js} +27 -2
- package/dist/{chunk-Y6PMBL2S.js.map → chunk-HOBNUW5Z.js.map} +1 -1
- package/dist/cli.cjs +26 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.global.js +26 -1
- package/dist/cli.global.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +248 -397
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +182 -296
- package/dist/index.d.ts +182 -296
- package/dist/index.global.js +248 -395
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +223 -395
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen.ts +34 -1
- package/src/collection.ts +203 -15
- package/src/collections.ts +35 -5
- package/src/http.ts +60 -126
- package/src/index.ts +8 -5
- package/src/lazypock.ts +19 -146
- package/src/types.ts +115 -12
- package/src/cache.ts +0 -314
package/dist/index.d.cts
CHANGED
|
@@ -50,21 +50,6 @@ interface RequestOptions {
|
|
|
50
50
|
signal?: AbortSignal;
|
|
51
51
|
/** Custom fetch implementation (for RN or test mocking) */
|
|
52
52
|
fetch?: typeof globalThis.fetch;
|
|
53
|
-
/**
|
|
54
|
-
* Cache control for this request (see {@link CacheRequestOptions}).
|
|
55
|
-
* Resolved against the client's global cache config when unset.
|
|
56
|
-
*/
|
|
57
|
-
cache?: boolean | number | {
|
|
58
|
-
ttl?: number;
|
|
59
|
-
key?: string;
|
|
60
|
-
};
|
|
61
|
-
/** Alias of `cache: <ms>` — cache this GET for `ttl` milliseconds. */
|
|
62
|
-
ttl?: number;
|
|
63
|
-
/**
|
|
64
|
-
* Extra cache namespaces to invalidate when this mutation succeeds.
|
|
65
|
-
* The current collection is always invalidated automatically.
|
|
66
|
-
*/
|
|
67
|
-
invalidate?: string[];
|
|
68
53
|
/**
|
|
69
54
|
* Request identifier used by the auto-cancellation mechanism.
|
|
70
55
|
*
|
|
@@ -87,6 +72,17 @@ interface RequestOptions {
|
|
|
87
72
|
* Alias of `requestKey` (PocketBase `$cancelKey` compat).
|
|
88
73
|
*/
|
|
89
74
|
cancelKey?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Coalesce concurrent identical requests (same `requestKey`) onto a single
|
|
77
|
+
* in-flight promise instead of aborting the earlier one.
|
|
78
|
+
*
|
|
79
|
+
* When enabled, a request arriving while another with the same key is still
|
|
80
|
+
* pending awaits the same result — no duplicate network request, and the
|
|
81
|
+
* caller of the first request never sees an abort rejection.
|
|
82
|
+
*
|
|
83
|
+
* @default false (auto-cancellation aborts the earlier duplicate)
|
|
84
|
+
*/
|
|
85
|
+
singleFlight?: boolean;
|
|
90
86
|
}
|
|
91
87
|
declare class ApiError extends Error {
|
|
92
88
|
readonly data: unknown;
|
|
@@ -99,6 +95,79 @@ declare class ApiError extends Error {
|
|
|
99
95
|
readonly isAbort: boolean;
|
|
100
96
|
constructor(message: string, data: unknown, status: number, isAbort?: boolean);
|
|
101
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* String keys of a record shape (excludes methods/symbols).
|
|
100
|
+
* Falls back to `string` when `T` has no known keys (e.g. `unknown`), so
|
|
101
|
+
* untyped services accept any field name.
|
|
102
|
+
*/
|
|
103
|
+
type FieldKey<T> = Extract<keyof T, string> extends never ? string : Extract<keyof T, string>;
|
|
104
|
+
/** Valid filter operators, matching the backend FilterCompiler. */
|
|
105
|
+
type FilterOp = "=" | "!=" | "~" | "!~" | ">" | ">=" | "<" | "<=";
|
|
106
|
+
/** One `field op value` clause. */
|
|
107
|
+
type FilterClause<T> = `${FieldKey<T>} ${FilterOp} ${string}`;
|
|
108
|
+
/**
|
|
109
|
+
* Type-checked filter expression (PocketBase syntax).
|
|
110
|
+
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* getList(1, 20, { filter: "title ~ 'x' && published = true" })
|
|
113
|
+
* getList(1, 20, { filter: "(title = 'a' || title = 'b')" })
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* The first clause's field name + operator are validated; the rest of the
|
|
117
|
+
* expression (values, `&&`/`||`, parens, `!`) is free-form.
|
|
118
|
+
*/
|
|
119
|
+
type FilterString<T> = FilterClause<T> | `${FilterClause<T>}${string}`;
|
|
120
|
+
/** A single `[+|-]field` sort token. */
|
|
121
|
+
type SortField<T> = `${"" | "-" | "+"}${FieldKey<T>}`;
|
|
122
|
+
/**
|
|
123
|
+
* Type-checked sort string: `field`, `-field` (desc), `+field`, or
|
|
124
|
+
* comma-separated combinations (e.g. `"-created,title"`).
|
|
125
|
+
*/
|
|
126
|
+
type SortString<T> = SortField<T> | `${SortField<T>},${string}`;
|
|
127
|
+
/**
|
|
128
|
+
* Type-checked expand string: comma-separated relation field names
|
|
129
|
+
* (e.g. `"author"` or `"author,category"`). Non-relation fields are
|
|
130
|
+
* warned about at runtime when a schema is available.
|
|
131
|
+
*/
|
|
132
|
+
type ExpandString<T> = FieldKey<T> | `${FieldKey<T>},${string}`;
|
|
133
|
+
/**
|
|
134
|
+
* Query options for list/read operations, typed against a record shape `T`.
|
|
135
|
+
*
|
|
136
|
+
* `filter`, `sort`, `expand` and `fields` are recognized; any other key is
|
|
137
|
+
* passed through as a raw query parameter (PocketBase-compatible).
|
|
138
|
+
*/
|
|
139
|
+
interface ListOptions<T = ApiRecord> {
|
|
140
|
+
/**
|
|
141
|
+
* PocketBase filter expression. Field names + operators are type-checked
|
|
142
|
+
* when `T` is a concrete shape.
|
|
143
|
+
*/
|
|
144
|
+
filter?: FilterString<T>;
|
|
145
|
+
/**
|
|
146
|
+
* Sort field(s): `field`, `-field` (descending), comma-separated.
|
|
147
|
+
*/
|
|
148
|
+
sort?: SortString<T>;
|
|
149
|
+
/**
|
|
150
|
+
* Comma-separated relation field names to expand.
|
|
151
|
+
*/
|
|
152
|
+
expand?: ExpandString<T>;
|
|
153
|
+
/**
|
|
154
|
+
* Explicit field projection (overrides {@link CollectionService.select}).
|
|
155
|
+
*/
|
|
156
|
+
fields?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Raw query parameters — any other key is passed through verbatim.
|
|
159
|
+
*/
|
|
160
|
+
[key: string]: unknown;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Options for single-record reads (`getOne`): expand + explicit fields.
|
|
164
|
+
*/
|
|
165
|
+
interface ReadOptions<T = ApiRecord> {
|
|
166
|
+
/** Comma-separated relation field names to expand. */
|
|
167
|
+
expand?: ExpandString<T>;
|
|
168
|
+
/** Explicit field projection (overrides {@link CollectionService.select}). */
|
|
169
|
+
fields?: string;
|
|
170
|
+
}
|
|
102
171
|
|
|
103
172
|
/**
|
|
104
173
|
* Interface for pluggable persistence backends.
|
|
@@ -173,153 +242,23 @@ declare class AuthStore {
|
|
|
173
242
|
private notify;
|
|
174
243
|
}
|
|
175
244
|
|
|
176
|
-
/** Options for enabling/customising the client's query cache. */
|
|
177
|
-
interface CacheConfig {
|
|
178
|
-
/**
|
|
179
|
-
* Master switch. When `true`, readable GET requests are cached with the
|
|
180
|
-
* default TTL unless a request opts out via `{ cache: false }`.
|
|
181
|
-
*
|
|
182
|
-
* When `false` (default), caching is disabled unless a request opts in
|
|
183
|
-
* via `{ cache: true }` or `{ ttl: <ms> }`. Opt-in works regardless.
|
|
184
|
-
*/
|
|
185
|
-
enabled?: boolean;
|
|
186
|
-
/**
|
|
187
|
-
* Default time-to-live for cached entries, in milliseconds.
|
|
188
|
-
* @default 60_000 (1 minute)
|
|
189
|
-
*/
|
|
190
|
-
defaultTTL?: number;
|
|
191
|
-
/**
|
|
192
|
-
* Optional persistence backend (same interface as AuthStore's storage).
|
|
193
|
-
* Defaults to an in-memory Map — swap for `localStorage` / `AsyncStorage`
|
|
194
|
-
* to keep the cache across page reloads / app restarts.
|
|
195
|
-
*/
|
|
196
|
-
store?: StorageAdapter;
|
|
197
|
-
/**
|
|
198
|
-
* Max number of entries to keep in memory (LRU eviction).
|
|
199
|
-
* @default 500
|
|
200
|
-
*/
|
|
201
|
-
maxEntries?: number;
|
|
202
|
-
/**
|
|
203
|
-
* When true and the client has an active realtime subscription for a
|
|
204
|
-
* collection, inbound create/update/delete events invalidate that
|
|
205
|
-
* collection's cached entries automatically.
|
|
206
|
-
* @default false — only local mutations invalidate (explicit + predictable)
|
|
207
|
-
*/
|
|
208
|
-
invalidateOnRealtime?: boolean;
|
|
209
|
-
}
|
|
210
|
-
/** Per-request cache controls (mixed into {@link RequestOptions}). */
|
|
211
|
-
interface CacheRequestOptions {
|
|
212
|
-
/**
|
|
213
|
-
* Cache control for this request:
|
|
214
|
-
* - `true` — cache with the default (or global) TTL
|
|
215
|
-
* - `false` — always fetch fresh, bypass cache (and don't store the result)
|
|
216
|
-
* - a number — cache with this TTL in milliseconds
|
|
217
|
-
* - an object — `{ ttl, key }` for finer control
|
|
218
|
-
*
|
|
219
|
-
* When unset, the global `cache.enabled` flag decides.
|
|
220
|
-
*/
|
|
221
|
-
cache?: boolean | number | {
|
|
222
|
-
ttl?: number;
|
|
223
|
-
key?: string;
|
|
224
|
-
};
|
|
225
|
-
/** Alias of `cache: <ms>` (convenience, reads naturally). */
|
|
226
|
-
ttl?: number;
|
|
227
|
-
/**
|
|
228
|
-
* Extra cache namespaces to invalidate when this mutation succeeds.
|
|
229
|
-
* The current collection is always invalidated automatically.
|
|
230
|
-
* @example create({ ... }, { invalidate: ['users'] })
|
|
231
|
-
*/
|
|
232
|
-
invalidate?: string[];
|
|
233
|
-
}
|
|
234
|
-
/** LRU-ish memory store + optional persistent adapter hybrid. */
|
|
235
|
-
declare class CacheStore {
|
|
236
|
-
private memory;
|
|
237
|
-
private readonly ttl;
|
|
238
|
-
private readonly persistence?;
|
|
239
|
-
private readonly maxEntries;
|
|
240
|
-
private hits;
|
|
241
|
-
private misses;
|
|
242
|
-
private namespaceEntries;
|
|
243
|
-
/** Key → set of prefix tags registered for that key (e.g. `getList:posts`). */
|
|
244
|
-
private prefixEntries;
|
|
245
|
-
constructor(config?: {
|
|
246
|
-
defaultTTL?: number;
|
|
247
|
-
store?: StorageAdapter;
|
|
248
|
-
maxEntries?: number;
|
|
249
|
-
});
|
|
250
|
-
/** Resolve the effective TTL: request override → global default. */
|
|
251
|
-
private resolveTTL;
|
|
252
|
-
/**
|
|
253
|
-
* Read a cached value. Fast sync path (memory) with async persistence
|
|
254
|
-
* fallback for adapters whose `get` returns a Promise.
|
|
255
|
-
* @param key Cache key (e.g. `"GET /posts?page=1"`).
|
|
256
|
-
* @returns The cached value, or undefined when absent/expired (the hit is
|
|
257
|
-
* cleared on expiry so a stale value is never served).
|
|
258
|
-
*/
|
|
259
|
-
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
260
|
-
/**
|
|
261
|
-
* Store a value.
|
|
262
|
-
* @param key Cache key.
|
|
263
|
-
* @param value The response payload.
|
|
264
|
-
* @param ttlOverride Optional TTL override (ms).
|
|
265
|
-
* @param namespace Optional namespace for group invalidation.
|
|
266
|
-
*/
|
|
267
|
-
set(key: string, value: unknown, ttlOverride?: number, namespace?: string, tags?: string[]): void;
|
|
268
|
-
/**
|
|
269
|
-
* Invalidate entries belonging to a namespace (e.g. a collection name).
|
|
270
|
-
* Also clears the namespace index entry.
|
|
271
|
-
*/
|
|
272
|
-
invalidate(namespace: string): void;
|
|
273
|
-
/** Remove a single key. */
|
|
274
|
-
delete(key: string): void;
|
|
275
|
-
/**
|
|
276
|
-
* Delete every entry whose key starts with `prefix`.
|
|
277
|
-
*
|
|
278
|
-
* Useful for fine-grained invalidation, e.g.:
|
|
279
|
-
* ```ts
|
|
280
|
-
* client.cache.deleteByPrefix('getList:posts'); // delete all getList cache
|
|
281
|
-
* client.cache.deleteByPrefix('getOne:posts'); // delete all getOne cache
|
|
282
|
-
* ```
|
|
283
|
-
*/
|
|
284
|
-
deleteByPrefix(prefix: string): void;
|
|
285
|
-
/** Drop every cached entry (memory + persistence). */
|
|
286
|
-
clear(): void;
|
|
287
|
-
/** Cache hit/miss/entry statistics. */
|
|
288
|
-
stats(): {
|
|
289
|
-
hits: number;
|
|
290
|
-
misses: number;
|
|
291
|
-
entries: number;
|
|
292
|
-
};
|
|
293
|
-
private persistKey;
|
|
294
|
-
private readPersisted;
|
|
295
|
-
}
|
|
296
|
-
/** Resolve per-request cache options into a usable directive. */
|
|
297
|
-
declare function resolveCacheDirective(opts?: {
|
|
298
|
-
cache?: boolean | number | {
|
|
299
|
-
ttl?: number;
|
|
300
|
-
key?: string;
|
|
301
|
-
};
|
|
302
|
-
ttl?: number;
|
|
303
|
-
}): {
|
|
304
|
-
enabled: boolean;
|
|
305
|
-
ttl?: number;
|
|
306
|
-
key?: string;
|
|
307
|
-
} | null;
|
|
308
|
-
|
|
309
245
|
declare class HttpClient {
|
|
310
246
|
private baseUrl;
|
|
311
247
|
private authStore;
|
|
312
248
|
private defaultFetch;
|
|
313
|
-
/** Optional query cache store (wired when the client enables caching). */
|
|
314
|
-
private cache?;
|
|
315
|
-
/** Master switch resolved from CacheConfig.enabled. */
|
|
316
|
-
private cacheEnabled;
|
|
317
249
|
/**
|
|
318
250
|
* Abort controllers for in-flight requests, keyed by their cancellation key
|
|
319
251
|
* (default `METHOD path`). A new request with the same key aborts the
|
|
320
252
|
* previous one — PocketBase-style auto-cancellation of duplicated requests.
|
|
321
253
|
*/
|
|
322
254
|
private cancelControllers;
|
|
255
|
+
/**
|
|
256
|
+
* In-flight request promises, keyed by cancellation key. When auto-cancellation
|
|
257
|
+
* would abort a pending duplicate, the newer request instead awaits the same
|
|
258
|
+
* promise — single-flight coalescing (no duplicate network request, no
|
|
259
|
+
* spurious abort rejection for the caller).
|
|
260
|
+
*/
|
|
261
|
+
private inflight;
|
|
323
262
|
/** Global toggle for the auto-cancellation behaviour (default: on). */
|
|
324
263
|
private enableAutoCancellation;
|
|
325
264
|
/**
|
|
@@ -327,13 +266,6 @@ declare class HttpClient {
|
|
|
327
266
|
* @param authStore The auth store providing the token for Authorization headers.
|
|
328
267
|
*/
|
|
329
268
|
constructor(baseUrl: string, authStore: AuthStore);
|
|
330
|
-
/**
|
|
331
|
-
* Attach a cache store + master switch.
|
|
332
|
-
* Called by the client constructor when cache config is present.
|
|
333
|
-
*/
|
|
334
|
-
setCache(cache: CacheStore, enabled: boolean): void;
|
|
335
|
-
/** Whether the global cache flag is on (requests opt in/out individually too). */
|
|
336
|
-
get cacheIsEnabled(): boolean;
|
|
337
269
|
private refreshAuth;
|
|
338
270
|
/**
|
|
339
271
|
* Globally enable or disable auto-cancellation of duplicated pending requests.
|
|
@@ -363,26 +295,12 @@ declare class HttpClient {
|
|
|
363
295
|
* @throws {ApiError} On non-2xx responses or when the request is aborted
|
|
364
296
|
* (aborted requests throw an `ApiError` with `isAbort === true`).
|
|
365
297
|
*/
|
|
366
|
-
/** Invalidate a namespace (collection name). No-op when cache is off. */
|
|
367
|
-
invalidateCache(namespace: string): void;
|
|
368
|
-
/** Current cache statistics (hits/misses/entries), or null when disabled. */
|
|
369
|
-
cacheStats(): {
|
|
370
|
-
hits: number;
|
|
371
|
-
misses: number;
|
|
372
|
-
entries: number;
|
|
373
|
-
} | null;
|
|
374
298
|
request<T = unknown>(method: Method, path: string, body?: unknown, options?: RequestOptions): Promise<T | null>;
|
|
375
|
-
/** Build a token-scoped cache key: `METHOD path|token-hash|params`. */
|
|
376
|
-
private cacheKeyFor;
|
|
377
|
-
/** Best-effort namespace (collection name) from a REST path. */
|
|
378
|
-
private namespaceFromPath;
|
|
379
299
|
/**
|
|
380
|
-
*
|
|
381
|
-
* -
|
|
382
|
-
* - `/{collection}/{id}` → `getOne:{collection}`
|
|
383
|
-
* - `/collections?...` / `/collections/{id}` → `collections:getList` / `collections:getOne`
|
|
300
|
+
* Execute the actual HTTP request (fetch + parse). Called by {@link request}
|
|
301
|
+
* as the inner in-flight unit so single-flight callers can reuse the promise.
|
|
384
302
|
*/
|
|
385
|
-
private
|
|
303
|
+
private doRequest;
|
|
386
304
|
/**
|
|
387
305
|
* HTTP GET.
|
|
388
306
|
* @param path URL path.
|
|
@@ -490,6 +408,37 @@ declare class RealtimeService {
|
|
|
490
408
|
private clearReconnectTimer;
|
|
491
409
|
}
|
|
492
410
|
|
|
411
|
+
/** A single field definition as returned by `GET /collections`. */
|
|
412
|
+
interface SchemaField {
|
|
413
|
+
id?: string;
|
|
414
|
+
name: string;
|
|
415
|
+
type: string;
|
|
416
|
+
required?: boolean;
|
|
417
|
+
unique?: boolean;
|
|
418
|
+
options?: {
|
|
419
|
+
/** For relation fields: the target collection name. */
|
|
420
|
+
collection?: string;
|
|
421
|
+
/** Max selectable/related items (multi when > 1). */
|
|
422
|
+
maxSelect?: number;
|
|
423
|
+
/** Allowed values for select / multi_select fields. */
|
|
424
|
+
values?: string[];
|
|
425
|
+
} & Record<string, unknown>;
|
|
426
|
+
indexed?: boolean;
|
|
427
|
+
hidden?: boolean;
|
|
428
|
+
system?: boolean;
|
|
429
|
+
sort_order?: number;
|
|
430
|
+
}
|
|
431
|
+
/** A collection definition as returned by `GET /collections`. */
|
|
432
|
+
interface CollectionSchema {
|
|
433
|
+
id?: string;
|
|
434
|
+
name: string;
|
|
435
|
+
type: "base" | "auth";
|
|
436
|
+
system?: boolean;
|
|
437
|
+
fields?: SchemaField[];
|
|
438
|
+
rules?: Record<string, unknown>;
|
|
439
|
+
options?: Record<string, unknown>;
|
|
440
|
+
}
|
|
441
|
+
|
|
493
442
|
/**
|
|
494
443
|
* A realtime record-change event delivered to subscription callbacks.
|
|
495
444
|
* Mirrors PocketBase's RealtimeService result shape (`action` + `record`).
|
|
@@ -512,9 +461,53 @@ declare class CollectionService<T = ApiRecord> {
|
|
|
512
461
|
private collectionName;
|
|
513
462
|
private authStore?;
|
|
514
463
|
private realtime?;
|
|
464
|
+
/** Optional schema for this collection (from client `types.schemas`). */
|
|
465
|
+
private schema?;
|
|
466
|
+
/**
|
|
467
|
+
* Active field projection from {@link select}. `"*"` (or unset) means
|
|
468
|
+
* "all visible (non-hidden) fields" — resolved against the schema when
|
|
469
|
+
* one is available, otherwise left to the server.
|
|
470
|
+
*/
|
|
471
|
+
private fieldsPreset?;
|
|
515
472
|
/** @internal */
|
|
516
|
-
constructor(http: HttpClient, collectionName: string, authStore?: AuthStore, realtime?: RealtimeService);
|
|
473
|
+
constructor(http: HttpClient, collectionName: string, authStore?: AuthStore, realtime?: RealtimeService, schema?: CollectionSchema);
|
|
517
474
|
private encodeId;
|
|
475
|
+
/**
|
|
476
|
+
* Project list/read responses to the given fields (PocketBase `fields`
|
|
477
|
+
* param). Field names are type-checked when this service is typed
|
|
478
|
+
* (codegen / `typed<T>()`).
|
|
479
|
+
*
|
|
480
|
+
* Returns a derived service — the original is untouched.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```ts
|
|
484
|
+
* const t = await client.collection("posts").select("id", "title").getList();
|
|
485
|
+
* // GET /api/posts?fields=id,title
|
|
486
|
+
*
|
|
487
|
+
* // All visible fields (hidden fields are excluded server-side)
|
|
488
|
+
* const all = await client.collection("posts").select("*").getList();
|
|
489
|
+
* // GET /api/posts?fields=id,title,published,… (schema known)
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* When no schema is known, the default (no `select()` call) sends no
|
|
493
|
+
* `fields` param — the server returns every non-password field.
|
|
494
|
+
* Pass `select("*")` to restore the default after a projection.
|
|
495
|
+
*/
|
|
496
|
+
select<K extends FieldKey<T> | "*">(...fields: K[]): CollectionService<T>;
|
|
497
|
+
/**
|
|
498
|
+
* Fields to send with reads:
|
|
499
|
+
* 1. explicit `options.fields` (caller wins)
|
|
500
|
+
* 2. `select()` preset
|
|
501
|
+
* 3. schema default — all visible (non-hidden, non-system) fields
|
|
502
|
+
*/
|
|
503
|
+
private effectiveFields;
|
|
504
|
+
/**
|
|
505
|
+
* All non-hidden, non-system, non-password field names from the schema.
|
|
506
|
+
* `undefined` when no schema is available (server decides).
|
|
507
|
+
*/
|
|
508
|
+
visibleFields(): string | undefined;
|
|
509
|
+
/** Warn once when an expand field is not a relation (schema known). */
|
|
510
|
+
private validateExpand;
|
|
518
511
|
/**
|
|
519
512
|
* Fetch a paginated list of records (PocketBase `getList`).
|
|
520
513
|
*
|
|
@@ -522,27 +515,27 @@ declare class CollectionService<T = ApiRecord> {
|
|
|
522
515
|
* @param perPage Records per page (default 30).
|
|
523
516
|
* @param options Query params (`filter`, `sort`, `expand`, `fields`) + request options.
|
|
524
517
|
*/
|
|
525
|
-
getList<T2 = T>(page?: number, perPage?: number, options?:
|
|
518
|
+
getList<T2 = T>(page?: number, perPage?: number, options?: ListOptions<T> & RequestOptions): Promise<ListResult<T2> | null>;
|
|
526
519
|
/**
|
|
527
520
|
* Fetch all records at once (auto-paginates). Mirrors PocketBase's
|
|
528
521
|
* `pb.collection(name).getFullList()`.
|
|
529
522
|
*
|
|
530
523
|
* @param options Query params (`sort`, `filter`, `batch`, etc.) + request options.
|
|
531
524
|
*/
|
|
532
|
-
getFullList<T2 = T>(options?:
|
|
525
|
+
getFullList<T2 = T>(options?: ListOptions<T> & RequestOptions): Promise<Array<T2>>;
|
|
533
526
|
/**
|
|
534
527
|
* Fetch the first record matching a filter (PocketBase `getFirstListItem`).
|
|
535
528
|
*
|
|
536
529
|
* @param filter Filter expression (e.g. `title = 'x'`).
|
|
537
530
|
* @param options Optional request options.
|
|
538
531
|
*/
|
|
539
|
-
getFirstListItem<T2 = T>(filter:
|
|
532
|
+
getFirstListItem<T2 = T>(filter: FilterString<T>, options?: ListOptions<T> & RequestOptions): Promise<T2 | null>;
|
|
540
533
|
/**
|
|
541
534
|
* Get a single record by ID.
|
|
542
535
|
* @param id Record ID.
|
|
543
536
|
* @param options Optional request options.
|
|
544
537
|
*/
|
|
545
|
-
getOne(id: string, options?: RequestOptions): Promise<T | null>;
|
|
538
|
+
getOne(id: string, options?: ReadOptions<T> & RequestOptions): Promise<T | null>;
|
|
546
539
|
/**
|
|
547
540
|
* Create a new record.
|
|
548
541
|
* @param data Record fields. When `T` is a concrete shape (e.g. a generated
|
|
@@ -590,6 +583,12 @@ declare class CollectionService<T = ApiRecord> {
|
|
|
590
583
|
* ```
|
|
591
584
|
*/
|
|
592
585
|
typed<TRecord = ApiRecord>(): CollectionService<TRecord>;
|
|
586
|
+
/**
|
|
587
|
+
* Explicitly bind a schema for this service (overrides the client-level
|
|
588
|
+
* `types.schemas`). Enables schema-aware defaults: hidden fields are
|
|
589
|
+
* excluded from responses, select/expand are validated.
|
|
590
|
+
*/
|
|
591
|
+
withSchema(schema: CollectionSchema): CollectionService<T>;
|
|
593
592
|
/**
|
|
594
593
|
* Subscribe to realtime changes for this collection.
|
|
595
594
|
* The event's `action` is one of `"create" | "update" | "delete"`.
|
|
@@ -789,37 +788,6 @@ declare class CollectionsService {
|
|
|
789
788
|
unsubscribe(): void;
|
|
790
789
|
}
|
|
791
790
|
|
|
792
|
-
/** A single field definition as returned by `GET /collections`. */
|
|
793
|
-
interface SchemaField {
|
|
794
|
-
id?: string;
|
|
795
|
-
name: string;
|
|
796
|
-
type: string;
|
|
797
|
-
required?: boolean;
|
|
798
|
-
unique?: boolean;
|
|
799
|
-
options?: {
|
|
800
|
-
/** For relation fields: the target collection name. */
|
|
801
|
-
collection?: string;
|
|
802
|
-
/** Max selectable/related items (multi when > 1). */
|
|
803
|
-
maxSelect?: number;
|
|
804
|
-
/** Allowed values for select / multi_select fields. */
|
|
805
|
-
values?: string[];
|
|
806
|
-
} & Record<string, unknown>;
|
|
807
|
-
indexed?: boolean;
|
|
808
|
-
hidden?: boolean;
|
|
809
|
-
system?: boolean;
|
|
810
|
-
sort_order?: number;
|
|
811
|
-
}
|
|
812
|
-
/** A collection definition as returned by `GET /collections`. */
|
|
813
|
-
interface CollectionSchema {
|
|
814
|
-
id?: string;
|
|
815
|
-
name: string;
|
|
816
|
-
type: "base" | "auth";
|
|
817
|
-
system?: boolean;
|
|
818
|
-
fields?: SchemaField[];
|
|
819
|
-
rules?: Record<string, unknown>;
|
|
820
|
-
options?: Record<string, unknown>;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
791
|
/** Format a raw collection name into a valid TS identifier (PascalCase). */
|
|
824
792
|
declare function collectionTypeName(name: string): string;
|
|
825
793
|
/**
|
|
@@ -859,26 +827,6 @@ declare function fieldTypeKind(field: SchemaField): FieldTypeKind;
|
|
|
859
827
|
*/
|
|
860
828
|
declare function schemaFieldType(field: SchemaField): unknown;
|
|
861
829
|
|
|
862
|
-
/**
|
|
863
|
-
* Callable cache namespace: `client.cache(config)` configures, and
|
|
864
|
-
* `client.cache.deleteByPrefix(...)` etc. manage cached entries.
|
|
865
|
-
*/
|
|
866
|
-
interface CacheController {
|
|
867
|
-
/** Configure the query cache at runtime. */
|
|
868
|
-
(config?: CacheConfig): LazypockClient;
|
|
869
|
-
/** Delete every entry whose key starts with `prefix` (e.g. `getList:posts`). */
|
|
870
|
-
deleteByPrefix(prefix: string): void;
|
|
871
|
-
/** Invalidate a collection's cached entries (alias of invalidateCache). */
|
|
872
|
-
invalidate(namespace: string): void;
|
|
873
|
-
/** Drop every cached entry. */
|
|
874
|
-
clear(): void;
|
|
875
|
-
/** Cache hit/miss/entry stats, or null when never configured. */
|
|
876
|
-
stats(): {
|
|
877
|
-
hits: number;
|
|
878
|
-
misses: number;
|
|
879
|
-
entries: number;
|
|
880
|
-
} | null;
|
|
881
|
-
}
|
|
882
830
|
/** Options for constructing a {@link LazypockClient}. */
|
|
883
831
|
interface LazypockClientOptions {
|
|
884
832
|
/** API base URL (e.g. 'http://localhost:4000/api') */
|
|
@@ -889,24 +837,6 @@ interface LazypockClientOptions {
|
|
|
889
837
|
authStore?: AuthStore;
|
|
890
838
|
/** Real-time service for Phoenix Channel WebSocket subscriptions */
|
|
891
839
|
realtime?: RealtimeService;
|
|
892
|
-
/**
|
|
893
|
-
* Query cache configuration. Disabled by default.
|
|
894
|
-
*
|
|
895
|
-
* ```ts
|
|
896
|
-
* const client = createClient({
|
|
897
|
-
* baseUrl: '...',
|
|
898
|
-
* cache: {
|
|
899
|
-
* enabled: true,
|
|
900
|
-
* defaultTTL: 30_000,
|
|
901
|
-
* store: myStorage, // optional persistence (same interface as auth)
|
|
902
|
-
* },
|
|
903
|
-
* });
|
|
904
|
-
* ```
|
|
905
|
-
*
|
|
906
|
-
* When enabled, readable GETs are cached. Requests can opt out via
|
|
907
|
-
* `{ cache: false }`, or opt in with a custom TTL via `{ ttl: ms }`.
|
|
908
|
-
*/
|
|
909
|
-
cache?: CacheConfig;
|
|
910
840
|
/**
|
|
911
841
|
* Optional schema types for generating typed services at runtime.
|
|
912
842
|
* When provided, `collection()` returns a service whose create/update
|
|
@@ -940,9 +870,6 @@ declare class LazypockClient {
|
|
|
940
870
|
readonly files: FilesService;
|
|
941
871
|
private collectionCache;
|
|
942
872
|
private schemaByName?;
|
|
943
|
-
private cacheStore?;
|
|
944
|
-
/** Namespace → realtime unsubscribe; used for realtime-driven invalidation. */
|
|
945
|
-
private realtimeInvalidators;
|
|
946
873
|
/**
|
|
947
874
|
* Create a new Lazypock client.
|
|
948
875
|
* @param options Configuration options.
|
|
@@ -959,7 +886,7 @@ declare class LazypockClient {
|
|
|
959
886
|
* @param name The collection name.
|
|
960
887
|
* @returns A {@link CollectionService} instance.
|
|
961
888
|
*/
|
|
962
|
-
collection(name: string): CollectionService<unknown>;
|
|
889
|
+
collection(name: string, schema?: CollectionSchema): CollectionService<unknown>;
|
|
963
890
|
/**
|
|
964
891
|
* Get a typed service whose record shape is derived from the schema
|
|
965
892
|
* passed via `options.types.schemas` (if available), or fall back to
|
|
@@ -997,47 +924,6 @@ declare class LazypockClient {
|
|
|
997
924
|
cancelRequest(requestKey: string): this;
|
|
998
925
|
/** Abort all pending requests. */
|
|
999
926
|
cancelAllRequests(): this;
|
|
1000
|
-
/**
|
|
1001
|
-
* Configure the query cache at runtime (also a namespace for cache
|
|
1002
|
-
* management methods).
|
|
1003
|
-
*
|
|
1004
|
-
* ```ts
|
|
1005
|
-
* client.cache({ enabled: true, defaultTTL: 30_000 });
|
|
1006
|
-
* client.cache.deleteByPrefix('getList:posts'); // all list caches for posts
|
|
1007
|
-
* client.cache.deleteByPrefix('getOne:posts'); // all one-record caches
|
|
1008
|
-
* ```
|
|
1009
|
-
*
|
|
1010
|
-
* When enabled, GET requests cache their payload; mutations invalidate the
|
|
1011
|
-
* affected collection automatically. Individual requests can opt out with
|
|
1012
|
-
* `{ cache: false }` or override the TTL with `{ ttl: ms }`.
|
|
1013
|
-
*/
|
|
1014
|
-
readonly cache: CacheController;
|
|
1015
|
-
/**
|
|
1016
|
-
* Drop every cached entry (all collections / namespaces).
|
|
1017
|
-
* Also disables realtime-driven invalidation subscriptions.
|
|
1018
|
-
*/
|
|
1019
|
-
clearCache(): this;
|
|
1020
|
-
/**
|
|
1021
|
-
* Invalidate cached entries for a collection (or custom namespace).
|
|
1022
|
-
* Runs automatically on mutations — call explicitly when data changed
|
|
1023
|
-
* out-of-band (e.g. another client wrote to the same collection).
|
|
1024
|
-
*/
|
|
1025
|
-
invalidateCache(namespace: string): this;
|
|
1026
|
-
/**
|
|
1027
|
-
* Cache hit/miss/entry statistics.
|
|
1028
|
-
* Returns null when caching was never configured.
|
|
1029
|
-
*/
|
|
1030
|
-
cacheStats(): {
|
|
1031
|
-
hits: number;
|
|
1032
|
-
misses: number;
|
|
1033
|
-
entries: number;
|
|
1034
|
-
} | null;
|
|
1035
|
-
/**
|
|
1036
|
-
* Subscribe a collection's cache to realtime invalidation: any inbound
|
|
1037
|
-
* create/update/delete event for the collection clears its cached entries.
|
|
1038
|
-
* Returns an unsubscribe function.
|
|
1039
|
-
*/
|
|
1040
|
-
invalidateCacheOnRealtime(collectionName: string): () => void;
|
|
1041
927
|
/** Check whether any superuser exists (for login vs setup screen routing). */
|
|
1042
928
|
checkSuperuser(): Promise<{
|
|
1043
929
|
has_superuser: boolean;
|
|
@@ -1130,4 +1016,4 @@ declare class TypedClient<TCollections extends LazypockCollections = LazypockCol
|
|
|
1130
1016
|
*/
|
|
1131
1017
|
declare function createClient<TCollections extends LazypockCollections = LazypockCollections>(options: LazypockClientOptions): TypedClient<TCollections>;
|
|
1132
1018
|
|
|
1133
|
-
export { ApiError, type ApiRecord, type AuthModel, AuthStore, type
|
|
1019
|
+
export { ApiError, type ApiRecord, type AuthModel, AuthStore, type CollectionSchema, CollectionService, type CollectionsMessage, CollectionsService, type CreateData, type ExpandString, type FieldKey, type FileRecord, FilesService, type FilterOp, type FilterString, HttpClient, LazypockClient, type LazypockClientOptions, type LazypockCollections, type ListOptions, type ListResult, type ReadOptions, type RealtimeCallback, type RealtimeMessage, RealtimeService, type RecordShape, type RequestOptions, type SchemaField, type SortString, type StorageAdapter, type SystemFields, TypedClient, type UpdateData, collectionTypeName, createClient, fieldTypeKind, fieldTypeScriptType, generateTypes, getFileUrl, getScaleUrl, getThumbUrl, schemaFieldType, wsUrlFromBaseUrl };
|