lazypock 0.18.0 → 0.19.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/dist/index.d.cts CHANGED
@@ -259,7 +259,7 @@ type ValidExpand<T, E extends string, O extends string = E> = string extends Fie
259
259
  * Non-relation fields are warned about at runtime when a schema is
260
260
  * available.
261
261
  */
262
- type ExpandString<T, E extends string = never> = E & (E extends ValidExpand<T, E, E> ? E : never);
262
+ type ExpandString<T, E extends string = never> = [E] extends [never] ? string : E & (E extends ValidExpand<T, E, E> ? E : never);
263
263
  /** A single `[+|-]field` sort token. */
264
264
  type SortField<T> = `${"" | "-" | "+"}${FieldKey<T>}`;
265
265
  /**
@@ -272,7 +272,7 @@ type ValidSort<T, E extends string, O extends string = E> = string extends Field
272
272
  * comma-separated combinations (e.g. `"-created,title"`). **Every** token is
273
273
  * validated — `sort: "title, nope"` is a compile error.
274
274
  */
275
- type SortString<T, E extends string = never> = E & (E extends ValidSort<T, E, E> ? E : never);
275
+ type SortString<T, E extends string = never> = [E] extends [never] ? string : E & (E extends ValidSort<T, E, E> ? E : never);
276
276
  /**
277
277
  * A string value with no quotes, `&&`/`||`, or parens — the "bare" fallback
278
278
  * for filter values (numbers, `true`/`false`/`null`, unquoted text).
@@ -339,7 +339,7 @@ type ValidFilter<T, F extends string, O extends string = F> = string extends Fie
339
339
  * `filter: \`title=${search}\``), the guard falls back to accepting it
340
340
  * verbatim — the server decides at runtime.
341
341
  */
342
- type FilterString<T, F extends string = never> = F & (F extends ValidFilter<T, F, F> ? F : string extends F ? F : never);
342
+ type FilterString<T, F extends string = never> = [F] extends [never] ? string : F & (F extends ValidFilter<T, F, F> ? F : string extends F ? F : never);
343
343
  /**
344
344
  * First segment of a single expand token (`"author.user"` → `"author"`) —
345
345
  * the key PocketBase uses on the expanded record.
@@ -391,9 +391,11 @@ type ExpandObj<E extends string, TExpand = Record<string, unknown>> = [
391
391
  type FilterInput<TFields, F extends string = never> = FilterString<TFields, F> | FilterExpr | ((where: FilterWhere<TFields>) => FilterExpr);
392
392
  /**
393
393
  * `_T` is kept for backward compatibility (`ListOptions<Post>`) but the
394
- * per-field validation now runs through the `E`/`S`/`F` generics.
394
+ * per-field validation now runs through the `E`/`S`/`F` generics. The default
395
+ * is `unknown` — the same shape an untyped `CollectionService<unknown>`
396
+ * carries — so the options bag lines up with what `getList` accepts.
395
397
  */
396
- interface ListOptions<_T = ApiRecord, E extends string = never, S extends string = never, F extends string = never> {
398
+ interface ListOptions<_T = unknown, E extends string = never, S extends string = never, F extends string = never> {
397
399
  /**
398
400
  * PocketBase filter expression. Accepts a raw filter string (field names
399
401
  * + operators type-checked when `T` is concrete), a pre-built
@@ -426,7 +428,7 @@ interface ListOptions<_T = ApiRecord, E extends string = never, S extends string
426
428
  /**
427
429
  * Options for single-record reads (`getOne`): expand + explicit fields.
428
430
  */
429
- interface ReadOptions<_T = ApiRecord, E extends string = never> {
431
+ interface ReadOptions<_T = unknown, E extends string = never> {
430
432
  /** Relation field(s) to expand — a comma-separated string or a
431
433
  * field-checked array. */
432
434
  expand?: ExpandString<_T, E> | ExpandField<_T>[];
@@ -616,112 +618,89 @@ interface RealtimeEvent {
616
618
  payload: Record<string, unknown>;
617
619
  }
618
620
  type RealtimeConnectOpts = {
619
- /** WebSocket URL (e.g. ws://localhost:4000/socket/websocket) */
621
+ /** SSE endpoint URL, e.g. `http://localhost:4000/api/realtime`. */
620
622
  url: string;
621
- /** Auth token to pass as query param */
623
+ /** Auth token to send as a bearer. */
622
624
  token?: string;
623
625
  };
624
626
  /**
625
627
  * Provides the current auth token at connect/reconnect time.
626
- * Wired by {@link LazypockClient} from its `authStore` so the socket is
628
+ * Wired by {@link LazypockClient} from its `authStore` so the stream is
627
629
  * always authenticated with the latest token (PocketBase parity).
628
630
  */
629
631
  type RealtimeTokenProvider = () => string | undefined;
630
632
  /**
631
- * Derive a WebSocket URL from an HTTP base URL.
632
- * http://localhost:4000/api → ws://localhost:4000/socket/websocket
633
+ * Derive the SSE endpoint from an HTTP base URL.
634
+ * `http://localhost:4000/api` → `http://localhost:4000/api/realtime`
633
635
  */
634
- declare function wsUrlFromBaseUrl(baseUrl: string): string;
636
+ declare function sseUrlFromBaseUrl(baseUrl: string): string;
635
637
  /**
636
- * Phoenix Channel client for real-time collection subscriptions.
638
+ * SSE client for real-time collection subscriptions.
637
639
  *
638
- * Connects via WebSocket and subscribes to collection topics.
639
- * Includes automatic reconnection with exponential backoff.
640
- *
641
- * @example
642
- * ```ts
643
- * const rt = new RealtimeService();
644
- * rt.connect({ url: wsUrlFromBaseUrl('http://localhost:4000/api') });
645
- * rt.subscribe('collection:posts', (e) => console.log(e));
646
- * ```
640
+ * Connects to `/api/realtime`, subscribes to the collection topics the SDK uses,
641
+ * and reconnects with exponential backoff. Live row-level security is applied by the
642
+ * server: an event is only sent for a record the subscriber may read.
647
643
  */
648
644
  declare class RealtimeService {
649
- private ws;
650
- private refCounter;
645
+ private controller;
646
+ private open;
647
+ private closed;
651
648
  private subscriptions;
652
649
  private reconnectTimer;
650
+ private resubscribeTimer;
653
651
  private reconnectAttempt;
654
652
  private maxReconnectDelay;
655
653
  onReconnect?: () => void;
656
654
  onDisconnect?: () => void;
657
- onError?: (err: Event) => void;
655
+ onError?: (err: unknown) => void;
658
656
  private url;
659
657
  private token;
660
658
  private tokenProvider;
661
659
  private connectionId;
662
- /** Whether the WebSocket is currently open. */
660
+ /** Whether the stream is currently open. */
663
661
  get isOpen(): boolean;
664
- /**
665
- * The most recently used WebSocket URL (set on {@link connect}).
666
- * Useful for SDK convenience methods that auto-connect before subscribing.
667
- */
662
+ /** The most recently used SSE URL (set on {@link connect}/{@link setUrl}). */
668
663
  get lastUrl(): string;
669
- /** The auth token configured for this connection (set on connect). */
664
+ /** The auth token configured for this connection. */
670
665
  get lastToken(): string | undefined;
671
- /**
672
- * Set the per-client connection id (browser tab / device). The SDK
673
- * appends it as the `connectionId` socket query param at connect time
674
- * (unless the URL already carries one), matching the `X-Connection-Id`
675
- * header the HTTP client sends — together they let the server exclude
676
- * the originating connection from its own realtime broadcasts.
677
- */
666
+ /** Set the per-client connection id (browser tab / device). */
678
667
  setConnectionId(id: string): void;
679
- /**
680
- * Set the socket URL. Useful before subscribing so the SDK can
681
- * auto-connect on the first {@link subscribe}.
682
- */
668
+ /** Set the stream URL. Useful before subscribing so the SDK auto-connects. */
683
669
  setUrl(url: string): void;
684
- /**
685
- * Register a token provider consulted at every (re)connect.
686
- * When set, it takes precedence over the token passed to {@link connect}.
687
- */
670
+ /** Register a token provider consulted at every (re)connect. */
688
671
  setTokenProvider(provider: RealtimeTokenProvider): void;
689
672
  /**
690
- * Reconnect the socket immediately with the current token.
691
- * Called by the SDK when auth changes (login/logout/token refresh) so
692
- * private-channel joins are authorized with the new credentials. No-op
693
- * when the socket has never been opened and nothing is subscribed.
673
+ * Reconnect immediately with the current token, so auth changes
674
+ * (login/logout/refresh) re-authorize private subscriptions.
694
675
  */
695
676
  refresh(): void;
677
+ /** Ensure a connection is open, then subscribe. */
696
678
  ensureConnected(): void;
697
679
  connect(opts: RealtimeConnectOpts): void;
698
680
  disconnect(): void;
699
681
  /**
700
- * Subscribe to a topic (e.g. "collection:posts" or "custom:chat-room").
701
- * The backend Channel authorizes via listRule on join.
702
- *
703
- * @param joinPayload Optional payload forwarded with the channel join
704
- * (available to the server's join callback / hooks, e.g. `expand`).
682
+ * Subscribe to a topic (`collection:posts`, `collection:posts:ID`, or the
683
+ * registry topic `collections`).
705
684
  */
706
685
  subscribe(topic: string, callback: (e: RealtimeEvent) => void, joinPayload?: Record<string, unknown>): void;
707
- /**
708
- * Remove all subscriptions for topics under `prefix` (the topic itself or
709
- * any topic starting with `prefix + ":"`). Used by collection-level
710
- * `unsubscribe()` to drop every subscription of a collection.
711
- */
686
+ /** Remove every subscription under `prefix` (the topic or `prefix:...`). */
712
687
  unsubscribeByPrefix(prefix: string): void;
688
+ /** Remove a specific callback from a topic, or the whole topic. */
689
+ unsubscribe(topic: string, callback?: (e: RealtimeEvent) => void): void;
690
+ /** The distinct server topics the current subscriptions need. */
691
+ private serverTopics;
713
692
  /**
714
- * Unsubscribe a specific callback from a topic.
693
+ * The subscription set is part of the connection URL, so a change needs a new
694
+ * connection. Coalesced, because mounting a page subscribes to several
695
+ * collections in one tick.
715
696
  */
716
- unsubscribe(topic: string, callback?: (e: RealtimeEvent) => void): void;
717
- private resubscribeAll;
697
+ private resubscribe;
718
698
  private doConnect;
719
- private handleMessage;
720
- private joinTopic;
721
- private nextRef;
722
- private heartbeatInterval;
723
- private startHeartbeat;
724
- private stopHeartbeat;
699
+ private read;
700
+ private handleFrame;
701
+ private dispatch;
702
+ private emit;
703
+ private closeStream;
725
704
  private scheduleReconnect;
726
705
  private clearReconnectTimer;
727
706
  }
@@ -928,6 +907,15 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
928
907
  /** @internal */
929
908
  constructor(http: HttpClient, collectionName: string, authStore?: AuthStore, realtime?: RealtimeService, schema?: CollectionSchema, schemaResolver?: SchemaResolver);
930
909
  private encodeId;
910
+ /**
911
+ * The records endpoint for this collection.
912
+ *
913
+ * Centralised because the server's shape is `/api/collections/<name>/records`,
914
+ * and a path repeated eighteen times is a path that drifts.
915
+ */
916
+ private recordsPath;
917
+ /** The collection's own endpoint, which is where its auth routes live. */
918
+ private collectionPath;
931
919
  /**
932
920
  * Project list/read responses to the given fields (PocketBase `fields`
933
921
  * param). Field names are type-checked when this service is typed
@@ -1301,23 +1289,29 @@ interface DirectUpload {
1301
1289
  headers: Record<string, string>;
1302
1290
  }
1303
1291
  /**
1304
- * Construct a file URL from the API base URL and file ID.
1292
+ * Construct a file URL from the API base URL and a storage **key**.
1293
+ *
1294
+ * The key is `collection/record/filename` — for example
1295
+ * `posts/p1/abc123_photo.png` — which is what `GET /api/files` returns as `key`.
1296
+ * The server addresses an object by its key rather than by an opaque id, since
1297
+ * in this design an object *is* its key.
1298
+ *
1299
+ * Prefer the `url` the listing already provides; build one only when all you hold
1300
+ * is a key.
1305
1301
  */
1306
- declare function getFileUrl(baseUrl: string, fileId: string): string;
1302
+ declare function getFileUrl(baseUrl: string, key: string): string;
1307
1303
  /**
1308
- * Construct a thumbnail URL from the API base URL, file ID, and thumb size.
1309
- * @param size e.g. "50x50"
1304
+ * Construct a thumbnail URL for a storage key.
1305
+ *
1306
+ * @param size A box like `200x200`, or a preset name from the server's list.
1310
1307
  */
1311
- declare function getThumbUrl(baseUrl: string, fileId: string, size: string): string;
1308
+ declare function getThumbUrl(baseUrl: string, key: string, size: string): string;
1312
1309
  /**
1313
- * Construct an on-demand scaled image URL from the API base URL, file ID, and size.
1310
+ * Construct a scaled image URL for a storage key.
1314
1311
  *
1315
- * The size is an ImageMagick geometry: "100" (width, keep aspect), "100x100"
1316
- * (fit within box), "100x100!" (exact crop), "x200" (height). The server
1317
- * generates and caches the scaled image on first request.
1318
- * @param size e.g. "100x100"
1312
+ * @param size A preset name (`md`), or a box (`400x300`) for an ad-hoc size.
1319
1313
  */
1320
- declare function getScaleUrl(baseUrl: string, fileId: string, size: string): string;
1314
+ declare function getScaleUrl(baseUrl: string, key: string, size: string): string;
1321
1315
  /**
1322
1316
  * Construct a URL for a named preset variant, e.g. "thumb" or "content".
1323
1317
  * These are generated eagerly on upload or lazily on first request.
@@ -1726,4 +1720,4 @@ declare class TypedClient<TCollections extends LazypockCollections = LazypockCol
1726
1720
  */
1727
1721
  declare function createClient<TCollections extends LazypockCollections = LazypockCollections>(options: LazypockClientOptions): TypedClient<TCollections>;
1728
1722
 
1729
- export { ApiError, type ApiRecord, type AuthMethodsList, type AuthModel, type AuthProviderInfo, AuthStore, type CollectionSchema, CollectionService, type CollectionsMessage, CollectionsService, type CreateData, type ExpandString, type FieldKey, type FileRecord, FilesService, FilterBuilder, FilterExpr, type FilterInput, type FilterOp, type FilterScalar, type FilterString, type FilterWhere, type FilterableKey, HttpClient, LazypockClient, type LazypockClientOptions, type LazypockCollections, type ListOptions, type ListResult, type OAuth2AuthCodeOptions, type OAuth2Meta, type OAuth2Options, type OAuth2PopupOptions, type ReadOptions, type RealtimeCallback, type RealtimeMessage, RealtimeService, type RealtimeSubscribeOptions, type RecordAuth, type RecordShape, type RequestOptions, type SchemaField, type SortString, type StorageAdapter, type SystemFields, TypedClient, type UpdateData, collectionTypeName, createClient, fieldTypeKind, fieldTypeScriptType, generateTypes, getFileUrl, getScaleUrl, getThumbUrl, getVariantUrl, schemaFieldType, wsUrlFromBaseUrl };
1723
+ export { ApiError, type ApiRecord, type AuthMethodsList, type AuthModel, type AuthProviderInfo, AuthStore, type CollectionSchema, CollectionService, type CollectionsMessage, CollectionsService, type CreateData, type ExpandString, type FieldKey, type FileRecord, FilesService, FilterBuilder, FilterExpr, type FilterInput, type FilterOp, type FilterScalar, type FilterString, type FilterWhere, type FilterableKey, HttpClient, LazypockClient, type LazypockClientOptions, type LazypockCollections, type ListOptions, type ListResult, type OAuth2AuthCodeOptions, type OAuth2Meta, type OAuth2Options, type OAuth2PopupOptions, type ReadOptions, type RealtimeCallback, type RealtimeMessage, RealtimeService, type RealtimeSubscribeOptions, type RecordAuth, type RecordShape, type RequestOptions, type SchemaField, type SortString, type StorageAdapter, type SystemFields, TypedClient, type UpdateData, collectionTypeName, createClient, fieldTypeKind, fieldTypeScriptType, generateTypes, getFileUrl, getScaleUrl, getThumbUrl, getVariantUrl, schemaFieldType, sseUrlFromBaseUrl };
package/dist/index.d.ts CHANGED
@@ -259,7 +259,7 @@ type ValidExpand<T, E extends string, O extends string = E> = string extends Fie
259
259
  * Non-relation fields are warned about at runtime when a schema is
260
260
  * available.
261
261
  */
262
- type ExpandString<T, E extends string = never> = E & (E extends ValidExpand<T, E, E> ? E : never);
262
+ type ExpandString<T, E extends string = never> = [E] extends [never] ? string : E & (E extends ValidExpand<T, E, E> ? E : never);
263
263
  /** A single `[+|-]field` sort token. */
264
264
  type SortField<T> = `${"" | "-" | "+"}${FieldKey<T>}`;
265
265
  /**
@@ -272,7 +272,7 @@ type ValidSort<T, E extends string, O extends string = E> = string extends Field
272
272
  * comma-separated combinations (e.g. `"-created,title"`). **Every** token is
273
273
  * validated — `sort: "title, nope"` is a compile error.
274
274
  */
275
- type SortString<T, E extends string = never> = E & (E extends ValidSort<T, E, E> ? E : never);
275
+ type SortString<T, E extends string = never> = [E] extends [never] ? string : E & (E extends ValidSort<T, E, E> ? E : never);
276
276
  /**
277
277
  * A string value with no quotes, `&&`/`||`, or parens — the "bare" fallback
278
278
  * for filter values (numbers, `true`/`false`/`null`, unquoted text).
@@ -339,7 +339,7 @@ type ValidFilter<T, F extends string, O extends string = F> = string extends Fie
339
339
  * `filter: \`title=${search}\``), the guard falls back to accepting it
340
340
  * verbatim — the server decides at runtime.
341
341
  */
342
- type FilterString<T, F extends string = never> = F & (F extends ValidFilter<T, F, F> ? F : string extends F ? F : never);
342
+ type FilterString<T, F extends string = never> = [F] extends [never] ? string : F & (F extends ValidFilter<T, F, F> ? F : string extends F ? F : never);
343
343
  /**
344
344
  * First segment of a single expand token (`"author.user"` → `"author"`) —
345
345
  * the key PocketBase uses on the expanded record.
@@ -391,9 +391,11 @@ type ExpandObj<E extends string, TExpand = Record<string, unknown>> = [
391
391
  type FilterInput<TFields, F extends string = never> = FilterString<TFields, F> | FilterExpr | ((where: FilterWhere<TFields>) => FilterExpr);
392
392
  /**
393
393
  * `_T` is kept for backward compatibility (`ListOptions<Post>`) but the
394
- * per-field validation now runs through the `E`/`S`/`F` generics.
394
+ * per-field validation now runs through the `E`/`S`/`F` generics. The default
395
+ * is `unknown` — the same shape an untyped `CollectionService<unknown>`
396
+ * carries — so the options bag lines up with what `getList` accepts.
395
397
  */
396
- interface ListOptions<_T = ApiRecord, E extends string = never, S extends string = never, F extends string = never> {
398
+ interface ListOptions<_T = unknown, E extends string = never, S extends string = never, F extends string = never> {
397
399
  /**
398
400
  * PocketBase filter expression. Accepts a raw filter string (field names
399
401
  * + operators type-checked when `T` is concrete), a pre-built
@@ -426,7 +428,7 @@ interface ListOptions<_T = ApiRecord, E extends string = never, S extends string
426
428
  /**
427
429
  * Options for single-record reads (`getOne`): expand + explicit fields.
428
430
  */
429
- interface ReadOptions<_T = ApiRecord, E extends string = never> {
431
+ interface ReadOptions<_T = unknown, E extends string = never> {
430
432
  /** Relation field(s) to expand — a comma-separated string or a
431
433
  * field-checked array. */
432
434
  expand?: ExpandString<_T, E> | ExpandField<_T>[];
@@ -616,112 +618,89 @@ interface RealtimeEvent {
616
618
  payload: Record<string, unknown>;
617
619
  }
618
620
  type RealtimeConnectOpts = {
619
- /** WebSocket URL (e.g. ws://localhost:4000/socket/websocket) */
621
+ /** SSE endpoint URL, e.g. `http://localhost:4000/api/realtime`. */
620
622
  url: string;
621
- /** Auth token to pass as query param */
623
+ /** Auth token to send as a bearer. */
622
624
  token?: string;
623
625
  };
624
626
  /**
625
627
  * Provides the current auth token at connect/reconnect time.
626
- * Wired by {@link LazypockClient} from its `authStore` so the socket is
628
+ * Wired by {@link LazypockClient} from its `authStore` so the stream is
627
629
  * always authenticated with the latest token (PocketBase parity).
628
630
  */
629
631
  type RealtimeTokenProvider = () => string | undefined;
630
632
  /**
631
- * Derive a WebSocket URL from an HTTP base URL.
632
- * http://localhost:4000/api → ws://localhost:4000/socket/websocket
633
+ * Derive the SSE endpoint from an HTTP base URL.
634
+ * `http://localhost:4000/api` → `http://localhost:4000/api/realtime`
633
635
  */
634
- declare function wsUrlFromBaseUrl(baseUrl: string): string;
636
+ declare function sseUrlFromBaseUrl(baseUrl: string): string;
635
637
  /**
636
- * Phoenix Channel client for real-time collection subscriptions.
638
+ * SSE client for real-time collection subscriptions.
637
639
  *
638
- * Connects via WebSocket and subscribes to collection topics.
639
- * Includes automatic reconnection with exponential backoff.
640
- *
641
- * @example
642
- * ```ts
643
- * const rt = new RealtimeService();
644
- * rt.connect({ url: wsUrlFromBaseUrl('http://localhost:4000/api') });
645
- * rt.subscribe('collection:posts', (e) => console.log(e));
646
- * ```
640
+ * Connects to `/api/realtime`, subscribes to the collection topics the SDK uses,
641
+ * and reconnects with exponential backoff. Live row-level security is applied by the
642
+ * server: an event is only sent for a record the subscriber may read.
647
643
  */
648
644
  declare class RealtimeService {
649
- private ws;
650
- private refCounter;
645
+ private controller;
646
+ private open;
647
+ private closed;
651
648
  private subscriptions;
652
649
  private reconnectTimer;
650
+ private resubscribeTimer;
653
651
  private reconnectAttempt;
654
652
  private maxReconnectDelay;
655
653
  onReconnect?: () => void;
656
654
  onDisconnect?: () => void;
657
- onError?: (err: Event) => void;
655
+ onError?: (err: unknown) => void;
658
656
  private url;
659
657
  private token;
660
658
  private tokenProvider;
661
659
  private connectionId;
662
- /** Whether the WebSocket is currently open. */
660
+ /** Whether the stream is currently open. */
663
661
  get isOpen(): boolean;
664
- /**
665
- * The most recently used WebSocket URL (set on {@link connect}).
666
- * Useful for SDK convenience methods that auto-connect before subscribing.
667
- */
662
+ /** The most recently used SSE URL (set on {@link connect}/{@link setUrl}). */
668
663
  get lastUrl(): string;
669
- /** The auth token configured for this connection (set on connect). */
664
+ /** The auth token configured for this connection. */
670
665
  get lastToken(): string | undefined;
671
- /**
672
- * Set the per-client connection id (browser tab / device). The SDK
673
- * appends it as the `connectionId` socket query param at connect time
674
- * (unless the URL already carries one), matching the `X-Connection-Id`
675
- * header the HTTP client sends — together they let the server exclude
676
- * the originating connection from its own realtime broadcasts.
677
- */
666
+ /** Set the per-client connection id (browser tab / device). */
678
667
  setConnectionId(id: string): void;
679
- /**
680
- * Set the socket URL. Useful before subscribing so the SDK can
681
- * auto-connect on the first {@link subscribe}.
682
- */
668
+ /** Set the stream URL. Useful before subscribing so the SDK auto-connects. */
683
669
  setUrl(url: string): void;
684
- /**
685
- * Register a token provider consulted at every (re)connect.
686
- * When set, it takes precedence over the token passed to {@link connect}.
687
- */
670
+ /** Register a token provider consulted at every (re)connect. */
688
671
  setTokenProvider(provider: RealtimeTokenProvider): void;
689
672
  /**
690
- * Reconnect the socket immediately with the current token.
691
- * Called by the SDK when auth changes (login/logout/token refresh) so
692
- * private-channel joins are authorized with the new credentials. No-op
693
- * when the socket has never been opened and nothing is subscribed.
673
+ * Reconnect immediately with the current token, so auth changes
674
+ * (login/logout/refresh) re-authorize private subscriptions.
694
675
  */
695
676
  refresh(): void;
677
+ /** Ensure a connection is open, then subscribe. */
696
678
  ensureConnected(): void;
697
679
  connect(opts: RealtimeConnectOpts): void;
698
680
  disconnect(): void;
699
681
  /**
700
- * Subscribe to a topic (e.g. "collection:posts" or "custom:chat-room").
701
- * The backend Channel authorizes via listRule on join.
702
- *
703
- * @param joinPayload Optional payload forwarded with the channel join
704
- * (available to the server's join callback / hooks, e.g. `expand`).
682
+ * Subscribe to a topic (`collection:posts`, `collection:posts:ID`, or the
683
+ * registry topic `collections`).
705
684
  */
706
685
  subscribe(topic: string, callback: (e: RealtimeEvent) => void, joinPayload?: Record<string, unknown>): void;
707
- /**
708
- * Remove all subscriptions for topics under `prefix` (the topic itself or
709
- * any topic starting with `prefix + ":"`). Used by collection-level
710
- * `unsubscribe()` to drop every subscription of a collection.
711
- */
686
+ /** Remove every subscription under `prefix` (the topic or `prefix:...`). */
712
687
  unsubscribeByPrefix(prefix: string): void;
688
+ /** Remove a specific callback from a topic, or the whole topic. */
689
+ unsubscribe(topic: string, callback?: (e: RealtimeEvent) => void): void;
690
+ /** The distinct server topics the current subscriptions need. */
691
+ private serverTopics;
713
692
  /**
714
- * Unsubscribe a specific callback from a topic.
693
+ * The subscription set is part of the connection URL, so a change needs a new
694
+ * connection. Coalesced, because mounting a page subscribes to several
695
+ * collections in one tick.
715
696
  */
716
- unsubscribe(topic: string, callback?: (e: RealtimeEvent) => void): void;
717
- private resubscribeAll;
697
+ private resubscribe;
718
698
  private doConnect;
719
- private handleMessage;
720
- private joinTopic;
721
- private nextRef;
722
- private heartbeatInterval;
723
- private startHeartbeat;
724
- private stopHeartbeat;
699
+ private read;
700
+ private handleFrame;
701
+ private dispatch;
702
+ private emit;
703
+ private closeStream;
725
704
  private scheduleReconnect;
726
705
  private clearReconnectTimer;
727
706
  }
@@ -928,6 +907,15 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
928
907
  /** @internal */
929
908
  constructor(http: HttpClient, collectionName: string, authStore?: AuthStore, realtime?: RealtimeService, schema?: CollectionSchema, schemaResolver?: SchemaResolver);
930
909
  private encodeId;
910
+ /**
911
+ * The records endpoint for this collection.
912
+ *
913
+ * Centralised because the server's shape is `/api/collections/<name>/records`,
914
+ * and a path repeated eighteen times is a path that drifts.
915
+ */
916
+ private recordsPath;
917
+ /** The collection's own endpoint, which is where its auth routes live. */
918
+ private collectionPath;
931
919
  /**
932
920
  * Project list/read responses to the given fields (PocketBase `fields`
933
921
  * param). Field names are type-checked when this service is typed
@@ -1301,23 +1289,29 @@ interface DirectUpload {
1301
1289
  headers: Record<string, string>;
1302
1290
  }
1303
1291
  /**
1304
- * Construct a file URL from the API base URL and file ID.
1292
+ * Construct a file URL from the API base URL and a storage **key**.
1293
+ *
1294
+ * The key is `collection/record/filename` — for example
1295
+ * `posts/p1/abc123_photo.png` — which is what `GET /api/files` returns as `key`.
1296
+ * The server addresses an object by its key rather than by an opaque id, since
1297
+ * in this design an object *is* its key.
1298
+ *
1299
+ * Prefer the `url` the listing already provides; build one only when all you hold
1300
+ * is a key.
1305
1301
  */
1306
- declare function getFileUrl(baseUrl: string, fileId: string): string;
1302
+ declare function getFileUrl(baseUrl: string, key: string): string;
1307
1303
  /**
1308
- * Construct a thumbnail URL from the API base URL, file ID, and thumb size.
1309
- * @param size e.g. "50x50"
1304
+ * Construct a thumbnail URL for a storage key.
1305
+ *
1306
+ * @param size A box like `200x200`, or a preset name from the server's list.
1310
1307
  */
1311
- declare function getThumbUrl(baseUrl: string, fileId: string, size: string): string;
1308
+ declare function getThumbUrl(baseUrl: string, key: string, size: string): string;
1312
1309
  /**
1313
- * Construct an on-demand scaled image URL from the API base URL, file ID, and size.
1310
+ * Construct a scaled image URL for a storage key.
1314
1311
  *
1315
- * The size is an ImageMagick geometry: "100" (width, keep aspect), "100x100"
1316
- * (fit within box), "100x100!" (exact crop), "x200" (height). The server
1317
- * generates and caches the scaled image on first request.
1318
- * @param size e.g. "100x100"
1312
+ * @param size A preset name (`md`), or a box (`400x300`) for an ad-hoc size.
1319
1313
  */
1320
- declare function getScaleUrl(baseUrl: string, fileId: string, size: string): string;
1314
+ declare function getScaleUrl(baseUrl: string, key: string, size: string): string;
1321
1315
  /**
1322
1316
  * Construct a URL for a named preset variant, e.g. "thumb" or "content".
1323
1317
  * These are generated eagerly on upload or lazily on first request.
@@ -1726,4 +1720,4 @@ declare class TypedClient<TCollections extends LazypockCollections = LazypockCol
1726
1720
  */
1727
1721
  declare function createClient<TCollections extends LazypockCollections = LazypockCollections>(options: LazypockClientOptions): TypedClient<TCollections>;
1728
1722
 
1729
- export { ApiError, type ApiRecord, type AuthMethodsList, type AuthModel, type AuthProviderInfo, AuthStore, type CollectionSchema, CollectionService, type CollectionsMessage, CollectionsService, type CreateData, type ExpandString, type FieldKey, type FileRecord, FilesService, FilterBuilder, FilterExpr, type FilterInput, type FilterOp, type FilterScalar, type FilterString, type FilterWhere, type FilterableKey, HttpClient, LazypockClient, type LazypockClientOptions, type LazypockCollections, type ListOptions, type ListResult, type OAuth2AuthCodeOptions, type OAuth2Meta, type OAuth2Options, type OAuth2PopupOptions, type ReadOptions, type RealtimeCallback, type RealtimeMessage, RealtimeService, type RealtimeSubscribeOptions, type RecordAuth, type RecordShape, type RequestOptions, type SchemaField, type SortString, type StorageAdapter, type SystemFields, TypedClient, type UpdateData, collectionTypeName, createClient, fieldTypeKind, fieldTypeScriptType, generateTypes, getFileUrl, getScaleUrl, getThumbUrl, getVariantUrl, schemaFieldType, wsUrlFromBaseUrl };
1723
+ export { ApiError, type ApiRecord, type AuthMethodsList, type AuthModel, type AuthProviderInfo, AuthStore, type CollectionSchema, CollectionService, type CollectionsMessage, CollectionsService, type CreateData, type ExpandString, type FieldKey, type FileRecord, FilesService, FilterBuilder, FilterExpr, type FilterInput, type FilterOp, type FilterScalar, type FilterString, type FilterWhere, type FilterableKey, HttpClient, LazypockClient, type LazypockClientOptions, type LazypockCollections, type ListOptions, type ListResult, type OAuth2AuthCodeOptions, type OAuth2Meta, type OAuth2Options, type OAuth2PopupOptions, type ReadOptions, type RealtimeCallback, type RealtimeMessage, RealtimeService, type RealtimeSubscribeOptions, type RecordAuth, type RecordShape, type RequestOptions, type SchemaField, type SortString, type StorageAdapter, type SystemFields, TypedClient, type UpdateData, collectionTypeName, createClient, fieldTypeKind, fieldTypeScriptType, generateTypes, getFileUrl, getScaleUrl, getThumbUrl, getVariantUrl, schemaFieldType, sseUrlFromBaseUrl };