lazypock 0.4.0 → 0.6.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 +57 -108
- 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 +155 -402
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +162 -299
- package/dist/index.d.ts +162 -299
- package/dist/index.global.js +155 -400
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +130 -400
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen.ts +34 -1
- package/src/collection.ts +158 -13
- package/src/collections.ts +0 -6
- package/src/http.ts +1 -131
- package/src/index.ts +8 -5
- package/src/lazypock.ts +19 -146
- package/src/types.ts +104 -12
- package/src/cache.ts +0 -314
package/dist/index.d.ts
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
|
*
|
|
@@ -110,6 +95,79 @@ declare class ApiError extends Error {
|
|
|
110
95
|
readonly isAbort: boolean;
|
|
111
96
|
constructor(message: string, data: unknown, status: number, isAbort?: boolean);
|
|
112
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
|
+
}
|
|
113
171
|
|
|
114
172
|
/**
|
|
115
173
|
* Interface for pluggable persistence backends.
|
|
@@ -184,147 +242,10 @@ declare class AuthStore {
|
|
|
184
242
|
private notify;
|
|
185
243
|
}
|
|
186
244
|
|
|
187
|
-
/** Options for enabling/customising the client's query cache. */
|
|
188
|
-
interface CacheConfig {
|
|
189
|
-
/**
|
|
190
|
-
* Master switch. When `true`, readable GET requests are cached with the
|
|
191
|
-
* default TTL unless a request opts out via `{ cache: false }`.
|
|
192
|
-
*
|
|
193
|
-
* When `false` (default), caching is disabled unless a request opts in
|
|
194
|
-
* via `{ cache: true }` or `{ ttl: <ms> }`. Opt-in works regardless.
|
|
195
|
-
*/
|
|
196
|
-
enabled?: boolean;
|
|
197
|
-
/**
|
|
198
|
-
* Default time-to-live for cached entries, in milliseconds.
|
|
199
|
-
* @default 60_000 (1 minute)
|
|
200
|
-
*/
|
|
201
|
-
defaultTTL?: number;
|
|
202
|
-
/**
|
|
203
|
-
* Optional persistence backend (same interface as AuthStore's storage).
|
|
204
|
-
* Defaults to an in-memory Map — swap for `localStorage` / `AsyncStorage`
|
|
205
|
-
* to keep the cache across page reloads / app restarts.
|
|
206
|
-
*/
|
|
207
|
-
store?: StorageAdapter;
|
|
208
|
-
/**
|
|
209
|
-
* Max number of entries to keep in memory (LRU eviction).
|
|
210
|
-
* @default 500
|
|
211
|
-
*/
|
|
212
|
-
maxEntries?: number;
|
|
213
|
-
/**
|
|
214
|
-
* When true and the client has an active realtime subscription for a
|
|
215
|
-
* collection, inbound create/update/delete events invalidate that
|
|
216
|
-
* collection's cached entries automatically.
|
|
217
|
-
* @default false — only local mutations invalidate (explicit + predictable)
|
|
218
|
-
*/
|
|
219
|
-
invalidateOnRealtime?: boolean;
|
|
220
|
-
}
|
|
221
|
-
/** Per-request cache controls (mixed into {@link RequestOptions}). */
|
|
222
|
-
interface CacheRequestOptions {
|
|
223
|
-
/**
|
|
224
|
-
* Cache control for this request:
|
|
225
|
-
* - `true` — cache with the default (or global) TTL
|
|
226
|
-
* - `false` — always fetch fresh, bypass cache (and don't store the result)
|
|
227
|
-
* - a number — cache with this TTL in milliseconds
|
|
228
|
-
* - an object — `{ ttl, key }` for finer control
|
|
229
|
-
*
|
|
230
|
-
* When unset, the global `cache.enabled` flag decides.
|
|
231
|
-
*/
|
|
232
|
-
cache?: boolean | number | {
|
|
233
|
-
ttl?: number;
|
|
234
|
-
key?: string;
|
|
235
|
-
};
|
|
236
|
-
/** Alias of `cache: <ms>` (convenience, reads naturally). */
|
|
237
|
-
ttl?: number;
|
|
238
|
-
/**
|
|
239
|
-
* Extra cache namespaces to invalidate when this mutation succeeds.
|
|
240
|
-
* The current collection is always invalidated automatically.
|
|
241
|
-
* @example create({ ... }, { invalidate: ['users'] })
|
|
242
|
-
*/
|
|
243
|
-
invalidate?: string[];
|
|
244
|
-
}
|
|
245
|
-
/** LRU-ish memory store + optional persistent adapter hybrid. */
|
|
246
|
-
declare class CacheStore {
|
|
247
|
-
private memory;
|
|
248
|
-
private readonly ttl;
|
|
249
|
-
private readonly persistence?;
|
|
250
|
-
private readonly maxEntries;
|
|
251
|
-
private hits;
|
|
252
|
-
private misses;
|
|
253
|
-
private namespaceEntries;
|
|
254
|
-
/** Key → set of prefix tags registered for that key (e.g. `getList:posts`). */
|
|
255
|
-
private prefixEntries;
|
|
256
|
-
constructor(config?: {
|
|
257
|
-
defaultTTL?: number;
|
|
258
|
-
store?: StorageAdapter;
|
|
259
|
-
maxEntries?: number;
|
|
260
|
-
});
|
|
261
|
-
/** Resolve the effective TTL: request override → global default. */
|
|
262
|
-
private resolveTTL;
|
|
263
|
-
/**
|
|
264
|
-
* Read a cached value. Fast sync path (memory) with async persistence
|
|
265
|
-
* fallback for adapters whose `get` returns a Promise.
|
|
266
|
-
* @param key Cache key (e.g. `"GET /posts?page=1"`).
|
|
267
|
-
* @returns The cached value, or undefined when absent/expired (the hit is
|
|
268
|
-
* cleared on expiry so a stale value is never served).
|
|
269
|
-
*/
|
|
270
|
-
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
271
|
-
/**
|
|
272
|
-
* Store a value.
|
|
273
|
-
* @param key Cache key.
|
|
274
|
-
* @param value The response payload.
|
|
275
|
-
* @param ttlOverride Optional TTL override (ms).
|
|
276
|
-
* @param namespace Optional namespace for group invalidation.
|
|
277
|
-
*/
|
|
278
|
-
set(key: string, value: unknown, ttlOverride?: number, namespace?: string, tags?: string[]): void;
|
|
279
|
-
/**
|
|
280
|
-
* Invalidate entries belonging to a namespace (e.g. a collection name).
|
|
281
|
-
* Also clears the namespace index entry.
|
|
282
|
-
*/
|
|
283
|
-
invalidate(namespace: string): void;
|
|
284
|
-
/** Remove a single key. */
|
|
285
|
-
delete(key: string): void;
|
|
286
|
-
/**
|
|
287
|
-
* Delete every entry whose key starts with `prefix`.
|
|
288
|
-
*
|
|
289
|
-
* Useful for fine-grained invalidation, e.g.:
|
|
290
|
-
* ```ts
|
|
291
|
-
* client.cache.deleteByPrefix('getList:posts'); // delete all getList cache
|
|
292
|
-
* client.cache.deleteByPrefix('getOne:posts'); // delete all getOne cache
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
deleteByPrefix(prefix: string): void;
|
|
296
|
-
/** Drop every cached entry (memory + persistence). */
|
|
297
|
-
clear(): void;
|
|
298
|
-
/** Cache hit/miss/entry statistics. */
|
|
299
|
-
stats(): {
|
|
300
|
-
hits: number;
|
|
301
|
-
misses: number;
|
|
302
|
-
entries: number;
|
|
303
|
-
};
|
|
304
|
-
private persistKey;
|
|
305
|
-
private readPersisted;
|
|
306
|
-
}
|
|
307
|
-
/** Resolve per-request cache options into a usable directive. */
|
|
308
|
-
declare function resolveCacheDirective(opts?: {
|
|
309
|
-
cache?: boolean | number | {
|
|
310
|
-
ttl?: number;
|
|
311
|
-
key?: string;
|
|
312
|
-
};
|
|
313
|
-
ttl?: number;
|
|
314
|
-
}): {
|
|
315
|
-
enabled: boolean;
|
|
316
|
-
ttl?: number;
|
|
317
|
-
key?: string;
|
|
318
|
-
} | null;
|
|
319
|
-
|
|
320
245
|
declare class HttpClient {
|
|
321
246
|
private baseUrl;
|
|
322
247
|
private authStore;
|
|
323
248
|
private defaultFetch;
|
|
324
|
-
/** Optional query cache store (wired when the client enables caching). */
|
|
325
|
-
private cache?;
|
|
326
|
-
/** Master switch resolved from CacheConfig.enabled. */
|
|
327
|
-
private cacheEnabled;
|
|
328
249
|
/**
|
|
329
250
|
* Abort controllers for in-flight requests, keyed by their cancellation key
|
|
330
251
|
* (default `METHOD path`). A new request with the same key aborts the
|
|
@@ -345,13 +266,6 @@ declare class HttpClient {
|
|
|
345
266
|
* @param authStore The auth store providing the token for Authorization headers.
|
|
346
267
|
*/
|
|
347
268
|
constructor(baseUrl: string, authStore: AuthStore);
|
|
348
|
-
/**
|
|
349
|
-
* Attach a cache store + master switch.
|
|
350
|
-
* Called by the client constructor when cache config is present.
|
|
351
|
-
*/
|
|
352
|
-
setCache(cache: CacheStore, enabled: boolean): void;
|
|
353
|
-
/** Whether the global cache flag is on (requests opt in/out individually too). */
|
|
354
|
-
get cacheIsEnabled(): boolean;
|
|
355
269
|
private refreshAuth;
|
|
356
270
|
/**
|
|
357
271
|
* Globally enable or disable auto-cancellation of duplicated pending requests.
|
|
@@ -381,31 +295,12 @@ declare class HttpClient {
|
|
|
381
295
|
* @throws {ApiError} On non-2xx responses or when the request is aborted
|
|
382
296
|
* (aborted requests throw an `ApiError` with `isAbort === true`).
|
|
383
297
|
*/
|
|
384
|
-
/** Invalidate a namespace (collection name). No-op when cache is off. */
|
|
385
|
-
invalidateCache(namespace: string): void;
|
|
386
|
-
/** Current cache statistics (hits/misses/entries), or null when disabled. */
|
|
387
|
-
cacheStats(): {
|
|
388
|
-
hits: number;
|
|
389
|
-
misses: number;
|
|
390
|
-
entries: number;
|
|
391
|
-
} | null;
|
|
392
298
|
request<T = unknown>(method: Method, path: string, body?: unknown, options?: RequestOptions): Promise<T | null>;
|
|
393
299
|
/**
|
|
394
|
-
* Execute the actual HTTP request (fetch + parse
|
|
300
|
+
* Execute the actual HTTP request (fetch + parse). Called by {@link request}
|
|
395
301
|
* as the inner in-flight unit so single-flight callers can reuse the promise.
|
|
396
302
|
*/
|
|
397
303
|
private doRequest;
|
|
398
|
-
/** Build a token-scoped cache key: `METHOD path|token-hash|params`. */
|
|
399
|
-
private cacheKeyFor;
|
|
400
|
-
/** Best-effort namespace (collection name) from a REST path. */
|
|
401
|
-
private namespaceFromPath;
|
|
402
|
-
/**
|
|
403
|
-
* Semantic prefix tags for `deleteByPrefix`, derived from the REST shape:
|
|
404
|
-
* - `/{collection}?...` → `getList:{collection}`
|
|
405
|
-
* - `/{collection}/{id}` → `getOne:{collection}`
|
|
406
|
-
* - `/collections?...` / `/collections/{id}` → `collections:getList` / `collections:getOne`
|
|
407
|
-
*/
|
|
408
|
-
private cacheTagsFor;
|
|
409
304
|
/**
|
|
410
305
|
* HTTP GET.
|
|
411
306
|
* @param path URL path.
|
|
@@ -513,6 +408,37 @@ declare class RealtimeService {
|
|
|
513
408
|
private clearReconnectTimer;
|
|
514
409
|
}
|
|
515
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
|
+
|
|
516
442
|
/**
|
|
517
443
|
* A realtime record-change event delivered to subscription callbacks.
|
|
518
444
|
* Mirrors PocketBase's RealtimeService result shape (`action` + `record`).
|
|
@@ -535,9 +461,53 @@ declare class CollectionService<T = ApiRecord> {
|
|
|
535
461
|
private collectionName;
|
|
536
462
|
private authStore?;
|
|
537
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?;
|
|
538
472
|
/** @internal */
|
|
539
|
-
constructor(http: HttpClient, collectionName: string, authStore?: AuthStore, realtime?: RealtimeService);
|
|
473
|
+
constructor(http: HttpClient, collectionName: string, authStore?: AuthStore, realtime?: RealtimeService, schema?: CollectionSchema);
|
|
540
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;
|
|
541
511
|
/**
|
|
542
512
|
* Fetch a paginated list of records (PocketBase `getList`).
|
|
543
513
|
*
|
|
@@ -545,27 +515,27 @@ declare class CollectionService<T = ApiRecord> {
|
|
|
545
515
|
* @param perPage Records per page (default 30).
|
|
546
516
|
* @param options Query params (`filter`, `sort`, `expand`, `fields`) + request options.
|
|
547
517
|
*/
|
|
548
|
-
getList<T2 = T>(page?: number, perPage?: number, options?:
|
|
518
|
+
getList<T2 = T>(page?: number, perPage?: number, options?: ListOptions<T> & RequestOptions): Promise<ListResult<T2> | null>;
|
|
549
519
|
/**
|
|
550
520
|
* Fetch all records at once (auto-paginates). Mirrors PocketBase's
|
|
551
521
|
* `pb.collection(name).getFullList()`.
|
|
552
522
|
*
|
|
553
523
|
* @param options Query params (`sort`, `filter`, `batch`, etc.) + request options.
|
|
554
524
|
*/
|
|
555
|
-
getFullList<T2 = T>(options?:
|
|
525
|
+
getFullList<T2 = T>(options?: ListOptions<T> & RequestOptions): Promise<Array<T2>>;
|
|
556
526
|
/**
|
|
557
527
|
* Fetch the first record matching a filter (PocketBase `getFirstListItem`).
|
|
558
528
|
*
|
|
559
529
|
* @param filter Filter expression (e.g. `title = 'x'`).
|
|
560
530
|
* @param options Optional request options.
|
|
561
531
|
*/
|
|
562
|
-
getFirstListItem<T2 = T>(filter:
|
|
532
|
+
getFirstListItem<T2 = T>(filter: FilterString<T>, options?: ListOptions<T> & RequestOptions): Promise<T2 | null>;
|
|
563
533
|
/**
|
|
564
534
|
* Get a single record by ID.
|
|
565
535
|
* @param id Record ID.
|
|
566
536
|
* @param options Optional request options.
|
|
567
537
|
*/
|
|
568
|
-
getOne(id: string, options?: RequestOptions): Promise<T | null>;
|
|
538
|
+
getOne(id: string, options?: ReadOptions<T> & RequestOptions): Promise<T | null>;
|
|
569
539
|
/**
|
|
570
540
|
* Create a new record.
|
|
571
541
|
* @param data Record fields. When `T` is a concrete shape (e.g. a generated
|
|
@@ -613,6 +583,12 @@ declare class CollectionService<T = ApiRecord> {
|
|
|
613
583
|
* ```
|
|
614
584
|
*/
|
|
615
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>;
|
|
616
592
|
/**
|
|
617
593
|
* Subscribe to realtime changes for this collection.
|
|
618
594
|
* The event's `action` is one of `"create" | "update" | "delete"`.
|
|
@@ -812,37 +788,6 @@ declare class CollectionsService {
|
|
|
812
788
|
unsubscribe(): void;
|
|
813
789
|
}
|
|
814
790
|
|
|
815
|
-
/** A single field definition as returned by `GET /collections`. */
|
|
816
|
-
interface SchemaField {
|
|
817
|
-
id?: string;
|
|
818
|
-
name: string;
|
|
819
|
-
type: string;
|
|
820
|
-
required?: boolean;
|
|
821
|
-
unique?: boolean;
|
|
822
|
-
options?: {
|
|
823
|
-
/** For relation fields: the target collection name. */
|
|
824
|
-
collection?: string;
|
|
825
|
-
/** Max selectable/related items (multi when > 1). */
|
|
826
|
-
maxSelect?: number;
|
|
827
|
-
/** Allowed values for select / multi_select fields. */
|
|
828
|
-
values?: string[];
|
|
829
|
-
} & Record<string, unknown>;
|
|
830
|
-
indexed?: boolean;
|
|
831
|
-
hidden?: boolean;
|
|
832
|
-
system?: boolean;
|
|
833
|
-
sort_order?: number;
|
|
834
|
-
}
|
|
835
|
-
/** A collection definition as returned by `GET /collections`. */
|
|
836
|
-
interface CollectionSchema {
|
|
837
|
-
id?: string;
|
|
838
|
-
name: string;
|
|
839
|
-
type: "base" | "auth";
|
|
840
|
-
system?: boolean;
|
|
841
|
-
fields?: SchemaField[];
|
|
842
|
-
rules?: Record<string, unknown>;
|
|
843
|
-
options?: Record<string, unknown>;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
791
|
/** Format a raw collection name into a valid TS identifier (PascalCase). */
|
|
847
792
|
declare function collectionTypeName(name: string): string;
|
|
848
793
|
/**
|
|
@@ -882,26 +827,6 @@ declare function fieldTypeKind(field: SchemaField): FieldTypeKind;
|
|
|
882
827
|
*/
|
|
883
828
|
declare function schemaFieldType(field: SchemaField): unknown;
|
|
884
829
|
|
|
885
|
-
/**
|
|
886
|
-
* Callable cache namespace: `client.cache(config)` configures, and
|
|
887
|
-
* `client.cache.deleteByPrefix(...)` etc. manage cached entries.
|
|
888
|
-
*/
|
|
889
|
-
interface CacheController {
|
|
890
|
-
/** Configure the query cache at runtime. */
|
|
891
|
-
(config?: CacheConfig): LazypockClient;
|
|
892
|
-
/** Delete every entry whose key starts with `prefix` (e.g. `getList:posts`). */
|
|
893
|
-
deleteByPrefix(prefix: string): void;
|
|
894
|
-
/** Invalidate a collection's cached entries (alias of invalidateCache). */
|
|
895
|
-
invalidate(namespace: string): void;
|
|
896
|
-
/** Drop every cached entry. */
|
|
897
|
-
clear(): void;
|
|
898
|
-
/** Cache hit/miss/entry stats, or null when never configured. */
|
|
899
|
-
stats(): {
|
|
900
|
-
hits: number;
|
|
901
|
-
misses: number;
|
|
902
|
-
entries: number;
|
|
903
|
-
} | null;
|
|
904
|
-
}
|
|
905
830
|
/** Options for constructing a {@link LazypockClient}. */
|
|
906
831
|
interface LazypockClientOptions {
|
|
907
832
|
/** API base URL (e.g. 'http://localhost:4000/api') */
|
|
@@ -912,24 +837,6 @@ interface LazypockClientOptions {
|
|
|
912
837
|
authStore?: AuthStore;
|
|
913
838
|
/** Real-time service for Phoenix Channel WebSocket subscriptions */
|
|
914
839
|
realtime?: RealtimeService;
|
|
915
|
-
/**
|
|
916
|
-
* Query cache configuration. Disabled by default.
|
|
917
|
-
*
|
|
918
|
-
* ```ts
|
|
919
|
-
* const client = createClient({
|
|
920
|
-
* baseUrl: '...',
|
|
921
|
-
* cache: {
|
|
922
|
-
* enabled: true,
|
|
923
|
-
* defaultTTL: 30_000,
|
|
924
|
-
* store: myStorage, // optional persistence (same interface as auth)
|
|
925
|
-
* },
|
|
926
|
-
* });
|
|
927
|
-
* ```
|
|
928
|
-
*
|
|
929
|
-
* When enabled, readable GETs are cached. Requests can opt out via
|
|
930
|
-
* `{ cache: false }`, or opt in with a custom TTL via `{ ttl: ms }`.
|
|
931
|
-
*/
|
|
932
|
-
cache?: CacheConfig;
|
|
933
840
|
/**
|
|
934
841
|
* Optional schema types for generating typed services at runtime.
|
|
935
842
|
* When provided, `collection()` returns a service whose create/update
|
|
@@ -963,9 +870,6 @@ declare class LazypockClient {
|
|
|
963
870
|
readonly files: FilesService;
|
|
964
871
|
private collectionCache;
|
|
965
872
|
private schemaByName?;
|
|
966
|
-
private cacheStore?;
|
|
967
|
-
/** Namespace → realtime unsubscribe; used for realtime-driven invalidation. */
|
|
968
|
-
private realtimeInvalidators;
|
|
969
873
|
/**
|
|
970
874
|
* Create a new Lazypock client.
|
|
971
875
|
* @param options Configuration options.
|
|
@@ -982,7 +886,7 @@ declare class LazypockClient {
|
|
|
982
886
|
* @param name The collection name.
|
|
983
887
|
* @returns A {@link CollectionService} instance.
|
|
984
888
|
*/
|
|
985
|
-
collection(name: string): CollectionService<unknown>;
|
|
889
|
+
collection(name: string, schema?: CollectionSchema): CollectionService<unknown>;
|
|
986
890
|
/**
|
|
987
891
|
* Get a typed service whose record shape is derived from the schema
|
|
988
892
|
* passed via `options.types.schemas` (if available), or fall back to
|
|
@@ -1020,47 +924,6 @@ declare class LazypockClient {
|
|
|
1020
924
|
cancelRequest(requestKey: string): this;
|
|
1021
925
|
/** Abort all pending requests. */
|
|
1022
926
|
cancelAllRequests(): this;
|
|
1023
|
-
/**
|
|
1024
|
-
* Configure the query cache at runtime (also a namespace for cache
|
|
1025
|
-
* management methods).
|
|
1026
|
-
*
|
|
1027
|
-
* ```ts
|
|
1028
|
-
* client.cache({ enabled: true, defaultTTL: 30_000 });
|
|
1029
|
-
* client.cache.deleteByPrefix('getList:posts'); // all list caches for posts
|
|
1030
|
-
* client.cache.deleteByPrefix('getOne:posts'); // all one-record caches
|
|
1031
|
-
* ```
|
|
1032
|
-
*
|
|
1033
|
-
* When enabled, GET requests cache their payload; mutations invalidate the
|
|
1034
|
-
* affected collection automatically. Individual requests can opt out with
|
|
1035
|
-
* `{ cache: false }` or override the TTL with `{ ttl: ms }`.
|
|
1036
|
-
*/
|
|
1037
|
-
readonly cache: CacheController;
|
|
1038
|
-
/**
|
|
1039
|
-
* Drop every cached entry (all collections / namespaces).
|
|
1040
|
-
* Also disables realtime-driven invalidation subscriptions.
|
|
1041
|
-
*/
|
|
1042
|
-
clearCache(): this;
|
|
1043
|
-
/**
|
|
1044
|
-
* Invalidate cached entries for a collection (or custom namespace).
|
|
1045
|
-
* Runs automatically on mutations — call explicitly when data changed
|
|
1046
|
-
* out-of-band (e.g. another client wrote to the same collection).
|
|
1047
|
-
*/
|
|
1048
|
-
invalidateCache(namespace: string): this;
|
|
1049
|
-
/**
|
|
1050
|
-
* Cache hit/miss/entry statistics.
|
|
1051
|
-
* Returns null when caching was never configured.
|
|
1052
|
-
*/
|
|
1053
|
-
cacheStats(): {
|
|
1054
|
-
hits: number;
|
|
1055
|
-
misses: number;
|
|
1056
|
-
entries: number;
|
|
1057
|
-
} | null;
|
|
1058
|
-
/**
|
|
1059
|
-
* Subscribe a collection's cache to realtime invalidation: any inbound
|
|
1060
|
-
* create/update/delete event for the collection clears its cached entries.
|
|
1061
|
-
* Returns an unsubscribe function.
|
|
1062
|
-
*/
|
|
1063
|
-
invalidateCacheOnRealtime(collectionName: string): () => void;
|
|
1064
927
|
/** Check whether any superuser exists (for login vs setup screen routing). */
|
|
1065
928
|
checkSuperuser(): Promise<{
|
|
1066
929
|
has_superuser: boolean;
|
|
@@ -1153,4 +1016,4 @@ declare class TypedClient<TCollections extends LazypockCollections = LazypockCol
|
|
|
1153
1016
|
*/
|
|
1154
1017
|
declare function createClient<TCollections extends LazypockCollections = LazypockCollections>(options: LazypockClientOptions): TypedClient<TCollections>;
|
|
1155
1018
|
|
|
1156
|
-
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 };
|