lazypock 0.20.0 → 0.20.1
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 +19 -0
- package/dist/index.cjs +750 -674
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -80
- package/dist/index.d.ts +46 -80
- package/dist/index.global.js +750 -674
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +750 -674
- package/dist/index.js.map +1 -1
- package/package.json +19 -2
- package/src/auth.ts +29 -0
- package/src/collection/auth.ts +289 -0
- package/src/collection/index.ts +754 -0
- package/src/collection/paths.ts +21 -0
- package/src/collection/query.ts +111 -0
- package/src/collection/realtime.ts +141 -0
- package/src/collection/session.ts +76 -0
- package/src/collections.ts +18 -52
- package/src/expand.ts +286 -0
- package/src/files.ts +15 -2
- package/src/filter.ts +2 -2
- package/src/http.ts +21 -6
- package/src/lazypock.ts +38 -71
- package/src/paginate.ts +111 -0
- package/src/projection.ts +139 -0
- package/src/query-params.ts +74 -0
- package/src/realtime.ts +6 -0
- package/src/collection.ts +0 -1412
package/dist/index.d.cts
CHANGED
|
@@ -518,6 +518,19 @@ declare class AuthStore {
|
|
|
518
518
|
* @param model The authenticated user record, or null for superusers.
|
|
519
519
|
*/
|
|
520
520
|
set(token: string, model: AuthModel | null): void;
|
|
521
|
+
/**
|
|
522
|
+
* Replace the cached auth model **without** touching the token, its recorded
|
|
523
|
+
* expiry, or the refresh token.
|
|
524
|
+
*
|
|
525
|
+
* Use this when a read refreshes the identity record (e.g. `me()`, or the
|
|
526
|
+
* server echoing the record back). Routing that through {@link set} would
|
|
527
|
+
* overwrite the access token's real `expiresIn` with the 7-day fallback TTL,
|
|
528
|
+
* so `isExpired` stays false long past the real 15-minute lifetime and the
|
|
529
|
+
* proactive refresh never fires — every request then pays a 401 + retry.
|
|
530
|
+
*
|
|
531
|
+
* @param model The authenticated user record, or null for superusers.
|
|
532
|
+
*/
|
|
533
|
+
setModel(model: AuthModel | null): void;
|
|
521
534
|
/**
|
|
522
535
|
* Record a complete auth response: token, model, refresh token and the access
|
|
523
536
|
* token's real lifetime.
|
|
@@ -589,6 +602,11 @@ declare class HttpClient {
|
|
|
589
602
|
*
|
|
590
603
|
* A network failure keeps the session (the next request can retry); only a refusal
|
|
591
604
|
* by the server ends it.
|
|
605
|
+
*
|
|
606
|
+
* `fetcher` is the per-request `options.fetch` override, so a caller (or a test)
|
|
607
|
+
* that injected its own transport also intercepts the refresh. Falling back to
|
|
608
|
+
* the global fetch here meant those callers — React Native and the test suite —
|
|
609
|
+
* silently did not cover this path at all.
|
|
592
610
|
*/
|
|
593
611
|
private refreshAuth;
|
|
594
612
|
/** The store's current session, in the shape the old refresh returned. */
|
|
@@ -793,6 +811,14 @@ interface CollectionSchema {
|
|
|
793
811
|
options?: Record<string, unknown>;
|
|
794
812
|
}
|
|
795
813
|
|
|
814
|
+
/**
|
|
815
|
+
* Resolves a collection schema by name or id. Supplied by
|
|
816
|
+
* {@link LazypockClient} so a service can follow relation fields into their
|
|
817
|
+
* target collection — needed to tell a nested relation (`owner.manager`)
|
|
818
|
+
* apart from a field selection (`owner.name`).
|
|
819
|
+
*/
|
|
820
|
+
type SchemaResolver = (nameOrId: string) => CollectionSchema | undefined;
|
|
821
|
+
|
|
796
822
|
/** A single configured OAuth2 provider, as returned by `auth-methods`. */
|
|
797
823
|
interface AuthProviderInfo {
|
|
798
824
|
/** Provider identifier (e.g. `"google"`, `"github"`). */
|
|
@@ -910,23 +936,17 @@ type RealtimeCallback = (e: RealtimeMessage) => void;
|
|
|
910
936
|
* `expand` and any extra keys are forwarded to the server channel join
|
|
911
937
|
* payload (available to `onRealtimeSubscribeRequest` hooks). `headers` is
|
|
912
938
|
* accepted for PocketBase signature compatibility but has no effect over
|
|
913
|
-
*
|
|
939
|
+
* the SSE connection — it is not forwarded.
|
|
914
940
|
*/
|
|
915
941
|
interface RealtimeSubscribeOptions {
|
|
916
942
|
/** Fields to expand on the subscribed records (server join payload). */
|
|
917
943
|
expand?: string;
|
|
918
|
-
/** Accepted for PocketBase parity; not sent over the
|
|
944
|
+
/** Accepted for PocketBase parity; not sent over the SSE connection. */
|
|
919
945
|
headers?: Record<string, string>;
|
|
920
946
|
/** Any extra keys are forwarded verbatim to the server join payload. */
|
|
921
947
|
[key: string]: unknown;
|
|
922
948
|
}
|
|
923
|
-
|
|
924
|
-
* Resolves a collection schema by name or id. Supplied by
|
|
925
|
-
* {@link LazypockClient} so a service can follow relation fields into their
|
|
926
|
-
* target collection — needed to tell a nested relation (`owner.manager`)
|
|
927
|
-
* apart from a field selection (`owner.name`).
|
|
928
|
-
*/
|
|
929
|
-
type SchemaResolver = (nameOrId: string) => CollectionSchema | undefined;
|
|
949
|
+
|
|
930
950
|
/**
|
|
931
951
|
* Typed CRUD service for a single dynamic collection.
|
|
932
952
|
* Get an instance via {@link LazypockClient.collection}.
|
|
@@ -961,16 +981,20 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
961
981
|
private fieldsPreset?;
|
|
962
982
|
/** @internal */
|
|
963
983
|
constructor(http: HttpClient, collectionName: string, authStore?: AuthStore, realtime?: RealtimeService, schema?: CollectionSchema, schemaResolver?: SchemaResolver);
|
|
964
|
-
private encodeId;
|
|
965
984
|
/**
|
|
966
|
-
*
|
|
985
|
+
* A copy of this service with the given overrides applied.
|
|
967
986
|
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
987
|
+
* Every field is listed exactly once, so a new service-level field can't be
|
|
988
|
+
* silently dropped by `select()` or `withSchema()`.
|
|
970
989
|
*/
|
|
990
|
+
private derive;
|
|
991
|
+
/** The records endpoint for this collection. */
|
|
971
992
|
private recordsPath;
|
|
972
993
|
/** The collection's own endpoint, which is where its auth routes live. */
|
|
973
994
|
private collectionPath;
|
|
995
|
+
private encodeId;
|
|
996
|
+
/** What the auth routes need: transport, collection name, session store. */
|
|
997
|
+
private sessionContext;
|
|
974
998
|
/**
|
|
975
999
|
* Project list/read responses to the given fields (PocketBase `fields`
|
|
976
1000
|
* param). Field names are type-checked when this service is typed
|
|
@@ -983,10 +1007,10 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
983
1007
|
* const t = await client.collection("posts").select("id", "title").getList();
|
|
984
1008
|
* // GET /api/posts?fields=id,title
|
|
985
1009
|
*
|
|
986
|
-
* // All visible fields (implicit system keys id/created/updated
|
|
1010
|
+
* // All visible fields (implicit system keys id/created/updated/... are
|
|
987
1011
|
* // kept; hidden fields are excluded via the projection)
|
|
988
1012
|
* const all = await client.collection("posts").select("*").getList();
|
|
989
|
-
* // GET /api/posts?fields=id,created,updated,collectionId,collectionName,title,published
|
|
1013
|
+
* // GET /api/posts?fields=id,created,updated,collectionId,collectionName,title,published,... (schema known)
|
|
990
1014
|
* ```
|
|
991
1015
|
*
|
|
992
1016
|
* When no schema is known, the default (no `select()` call) sends no
|
|
@@ -1017,6 +1041,10 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
1017
1041
|
* default returns every non-password field, including the system keys).
|
|
1018
1042
|
*/
|
|
1019
1043
|
visibleFields(): string | undefined;
|
|
1044
|
+
/** Service state that query building needs. */
|
|
1045
|
+
private queryContext;
|
|
1046
|
+
/** Context for the schema-aware expand helpers. */
|
|
1047
|
+
private expandContext;
|
|
1020
1048
|
/**
|
|
1021
1049
|
* Start a type-checked filter expression. The field name is suggested
|
|
1022
1050
|
* from the collection's key set and the value is checked against the
|
|
@@ -1027,7 +1055,7 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
1027
1055
|
* await posts.getList(1, 20, {
|
|
1028
1056
|
* filter: q("title").contains("x").and(q("published").eq(true)),
|
|
1029
1057
|
* });
|
|
1030
|
-
* // → filter=(title ~ '
|
|
1058
|
+
* // → filter=(title ~ 'x' && published = true)
|
|
1031
1059
|
*
|
|
1032
1060
|
* // PocketBase `?` array operators (multi-select / multi-relation):
|
|
1033
1061
|
* posts.getList(1, 20, { filter: q("tags").anyEq("news") });
|
|
@@ -1046,69 +1074,6 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
1046
1074
|
* `filter: (w) => w("title").contains("x")` type-checks field names inline.
|
|
1047
1075
|
*/
|
|
1048
1076
|
private resolveFilter;
|
|
1049
|
-
/**
|
|
1050
|
-
* Resolve the leading relation chain of an expand token against the
|
|
1051
|
-
* (optionally schema-aware) collection graph.
|
|
1052
|
-
*
|
|
1053
|
-
* Walks `segments` from this collection: each segment that is a relation
|
|
1054
|
-
* advances to its target collection. Stops at the first non-relation
|
|
1055
|
-
* segment or when the target schema is unknown.
|
|
1056
|
-
*
|
|
1057
|
-
* @returns `depth` — how many leading segments are relations; and
|
|
1058
|
-
* `canInspect` — whether the schema at `depth` is known (so the next
|
|
1059
|
-
* segment can be classified as a field selection vs a nested relation).
|
|
1060
|
-
*/
|
|
1061
|
-
private resolveRelationChain;
|
|
1062
|
-
/** Follow a relation field to its target collection, if resolvable. */
|
|
1063
|
-
private resolveTargetCollection;
|
|
1064
|
-
/** Warn once when an expand field is not a relation (schema known). */
|
|
1065
|
-
private warnNonRelation;
|
|
1066
|
-
/**
|
|
1067
|
-
* Validate and normalise a caller's `expand` string.
|
|
1068
|
-
*
|
|
1069
|
-
* PocketBase only expands *relations*: a dotted token like `author.user`
|
|
1070
|
-
* walks into the related record. Callers often use a dotted token to mean
|
|
1071
|
-
* "only these fields of the expanded record" (`owner.name,owner.email`),
|
|
1072
|
-
* which PocketBase silently drops. When the trailing segment is not a
|
|
1073
|
-
* relation — resolved from the schema graph — the token is rewritten as a
|
|
1074
|
-
* field selection:
|
|
1075
|
-
*
|
|
1076
|
-
* ```
|
|
1077
|
-
* expand: 'owner.name,owner.email'
|
|
1078
|
-
* → expand=owner&fields=<base>,expand.owner.name,expand.owner.email
|
|
1079
|
-
* ```
|
|
1080
|
-
*
|
|
1081
|
-
* Tokens whose whole path is relations keep their existing nested-expand
|
|
1082
|
-
* behaviour. Without a schema the two are indistinguishable, so a lone
|
|
1083
|
-
* dotted token stays a nested expand (with a warning) while two or more
|
|
1084
|
-
* dotted tokens sharing the same relation are treated as field selection.
|
|
1085
|
-
*/
|
|
1086
|
-
private normalizeExpand;
|
|
1087
|
-
/**
|
|
1088
|
-
* Keep only the requested leaf fields on `record.expand.<relation>`.
|
|
1089
|
-
*
|
|
1090
|
-
* Mirrors PocketBase's server-side `fields=expand.<rel>.<field>` projection
|
|
1091
|
-
* for servers that don't support it (the LazyPock server), so field
|
|
1092
|
-
* selection behaves the same against both. A no-op when the server already
|
|
1093
|
-
* narrowed the record. Multi-relations are narrowed element-wise.
|
|
1094
|
-
*/
|
|
1095
|
-
private applyExpandNarrowing;
|
|
1096
|
-
/**
|
|
1097
|
-
* Merge the expand-preserving selectors into the base field projection.
|
|
1098
|
-
*
|
|
1099
|
-
* Both servers are kept happy at once:
|
|
1100
|
-
* - PocketBase drops the whole `expand` payload unless an `expand.<key>`
|
|
1101
|
-
* entry is present in `fields`;
|
|
1102
|
-
* - the LazyPock server projects first (strict, top-level only) and then
|
|
1103
|
-
* expands, so the relation *field* itself must be present in `fields`.
|
|
1104
|
-
*
|
|
1105
|
-
* We therefore add both the relation field (`cate`) and the
|
|
1106
|
-
* `expand.<key>` entry. When no projection is active, no `fields` param is
|
|
1107
|
-
* sent at all — a value like `*` plus other tokens is not a wildcard on
|
|
1108
|
-
* the LazyPock server (it is a strict take, yielding empty records) and
|
|
1109
|
-
* the server keeps `expand` by default when `fields` is absent.
|
|
1110
|
-
*/
|
|
1111
|
-
private mergeExpandFields;
|
|
1112
1077
|
/**
|
|
1113
1078
|
* Fetch a paginated list of records (PocketBase `getList`).
|
|
1114
1079
|
*
|
|
@@ -1120,7 +1085,8 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
1120
1085
|
expand?: ExpandObj<E, TExpand>;
|
|
1121
1086
|
}> | null>;
|
|
1122
1087
|
/**
|
|
1123
|
-
* Fetch all records at once (auto-paginates; `batch` defaults to and is
|
|
1088
|
+
* Fetch all records at once (auto-paginates; `batch` defaults to and is
|
|
1089
|
+
* capped at 500, the server max `perPage`). Mirrors PocketBase's
|
|
1124
1090
|
* `pb.collection(name).getFullList()`.
|
|
1125
1091
|
*
|
|
1126
1092
|
* @param options Query params (`sort`, `filter`, `batch`, etc.) + request options.
|
package/dist/index.d.ts
CHANGED
|
@@ -518,6 +518,19 @@ declare class AuthStore {
|
|
|
518
518
|
* @param model The authenticated user record, or null for superusers.
|
|
519
519
|
*/
|
|
520
520
|
set(token: string, model: AuthModel | null): void;
|
|
521
|
+
/**
|
|
522
|
+
* Replace the cached auth model **without** touching the token, its recorded
|
|
523
|
+
* expiry, or the refresh token.
|
|
524
|
+
*
|
|
525
|
+
* Use this when a read refreshes the identity record (e.g. `me()`, or the
|
|
526
|
+
* server echoing the record back). Routing that through {@link set} would
|
|
527
|
+
* overwrite the access token's real `expiresIn` with the 7-day fallback TTL,
|
|
528
|
+
* so `isExpired` stays false long past the real 15-minute lifetime and the
|
|
529
|
+
* proactive refresh never fires — every request then pays a 401 + retry.
|
|
530
|
+
*
|
|
531
|
+
* @param model The authenticated user record, or null for superusers.
|
|
532
|
+
*/
|
|
533
|
+
setModel(model: AuthModel | null): void;
|
|
521
534
|
/**
|
|
522
535
|
* Record a complete auth response: token, model, refresh token and the access
|
|
523
536
|
* token's real lifetime.
|
|
@@ -589,6 +602,11 @@ declare class HttpClient {
|
|
|
589
602
|
*
|
|
590
603
|
* A network failure keeps the session (the next request can retry); only a refusal
|
|
591
604
|
* by the server ends it.
|
|
605
|
+
*
|
|
606
|
+
* `fetcher` is the per-request `options.fetch` override, so a caller (or a test)
|
|
607
|
+
* that injected its own transport also intercepts the refresh. Falling back to
|
|
608
|
+
* the global fetch here meant those callers — React Native and the test suite —
|
|
609
|
+
* silently did not cover this path at all.
|
|
592
610
|
*/
|
|
593
611
|
private refreshAuth;
|
|
594
612
|
/** The store's current session, in the shape the old refresh returned. */
|
|
@@ -793,6 +811,14 @@ interface CollectionSchema {
|
|
|
793
811
|
options?: Record<string, unknown>;
|
|
794
812
|
}
|
|
795
813
|
|
|
814
|
+
/**
|
|
815
|
+
* Resolves a collection schema by name or id. Supplied by
|
|
816
|
+
* {@link LazypockClient} so a service can follow relation fields into their
|
|
817
|
+
* target collection — needed to tell a nested relation (`owner.manager`)
|
|
818
|
+
* apart from a field selection (`owner.name`).
|
|
819
|
+
*/
|
|
820
|
+
type SchemaResolver = (nameOrId: string) => CollectionSchema | undefined;
|
|
821
|
+
|
|
796
822
|
/** A single configured OAuth2 provider, as returned by `auth-methods`. */
|
|
797
823
|
interface AuthProviderInfo {
|
|
798
824
|
/** Provider identifier (e.g. `"google"`, `"github"`). */
|
|
@@ -910,23 +936,17 @@ type RealtimeCallback = (e: RealtimeMessage) => void;
|
|
|
910
936
|
* `expand` and any extra keys are forwarded to the server channel join
|
|
911
937
|
* payload (available to `onRealtimeSubscribeRequest` hooks). `headers` is
|
|
912
938
|
* accepted for PocketBase signature compatibility but has no effect over
|
|
913
|
-
*
|
|
939
|
+
* the SSE connection — it is not forwarded.
|
|
914
940
|
*/
|
|
915
941
|
interface RealtimeSubscribeOptions {
|
|
916
942
|
/** Fields to expand on the subscribed records (server join payload). */
|
|
917
943
|
expand?: string;
|
|
918
|
-
/** Accepted for PocketBase parity; not sent over the
|
|
944
|
+
/** Accepted for PocketBase parity; not sent over the SSE connection. */
|
|
919
945
|
headers?: Record<string, string>;
|
|
920
946
|
/** Any extra keys are forwarded verbatim to the server join payload. */
|
|
921
947
|
[key: string]: unknown;
|
|
922
948
|
}
|
|
923
|
-
|
|
924
|
-
* Resolves a collection schema by name or id. Supplied by
|
|
925
|
-
* {@link LazypockClient} so a service can follow relation fields into their
|
|
926
|
-
* target collection — needed to tell a nested relation (`owner.manager`)
|
|
927
|
-
* apart from a field selection (`owner.name`).
|
|
928
|
-
*/
|
|
929
|
-
type SchemaResolver = (nameOrId: string) => CollectionSchema | undefined;
|
|
949
|
+
|
|
930
950
|
/**
|
|
931
951
|
* Typed CRUD service for a single dynamic collection.
|
|
932
952
|
* Get an instance via {@link LazypockClient.collection}.
|
|
@@ -961,16 +981,20 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
961
981
|
private fieldsPreset?;
|
|
962
982
|
/** @internal */
|
|
963
983
|
constructor(http: HttpClient, collectionName: string, authStore?: AuthStore, realtime?: RealtimeService, schema?: CollectionSchema, schemaResolver?: SchemaResolver);
|
|
964
|
-
private encodeId;
|
|
965
984
|
/**
|
|
966
|
-
*
|
|
985
|
+
* A copy of this service with the given overrides applied.
|
|
967
986
|
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
987
|
+
* Every field is listed exactly once, so a new service-level field can't be
|
|
988
|
+
* silently dropped by `select()` or `withSchema()`.
|
|
970
989
|
*/
|
|
990
|
+
private derive;
|
|
991
|
+
/** The records endpoint for this collection. */
|
|
971
992
|
private recordsPath;
|
|
972
993
|
/** The collection's own endpoint, which is where its auth routes live. */
|
|
973
994
|
private collectionPath;
|
|
995
|
+
private encodeId;
|
|
996
|
+
/** What the auth routes need: transport, collection name, session store. */
|
|
997
|
+
private sessionContext;
|
|
974
998
|
/**
|
|
975
999
|
* Project list/read responses to the given fields (PocketBase `fields`
|
|
976
1000
|
* param). Field names are type-checked when this service is typed
|
|
@@ -983,10 +1007,10 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
983
1007
|
* const t = await client.collection("posts").select("id", "title").getList();
|
|
984
1008
|
* // GET /api/posts?fields=id,title
|
|
985
1009
|
*
|
|
986
|
-
* // All visible fields (implicit system keys id/created/updated
|
|
1010
|
+
* // All visible fields (implicit system keys id/created/updated/... are
|
|
987
1011
|
* // kept; hidden fields are excluded via the projection)
|
|
988
1012
|
* const all = await client.collection("posts").select("*").getList();
|
|
989
|
-
* // GET /api/posts?fields=id,created,updated,collectionId,collectionName,title,published
|
|
1013
|
+
* // GET /api/posts?fields=id,created,updated,collectionId,collectionName,title,published,... (schema known)
|
|
990
1014
|
* ```
|
|
991
1015
|
*
|
|
992
1016
|
* When no schema is known, the default (no `select()` call) sends no
|
|
@@ -1017,6 +1041,10 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
1017
1041
|
* default returns every non-password field, including the system keys).
|
|
1018
1042
|
*/
|
|
1019
1043
|
visibleFields(): string | undefined;
|
|
1044
|
+
/** Service state that query building needs. */
|
|
1045
|
+
private queryContext;
|
|
1046
|
+
/** Context for the schema-aware expand helpers. */
|
|
1047
|
+
private expandContext;
|
|
1020
1048
|
/**
|
|
1021
1049
|
* Start a type-checked filter expression. The field name is suggested
|
|
1022
1050
|
* from the collection's key set and the value is checked against the
|
|
@@ -1027,7 +1055,7 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
1027
1055
|
* await posts.getList(1, 20, {
|
|
1028
1056
|
* filter: q("title").contains("x").and(q("published").eq(true)),
|
|
1029
1057
|
* });
|
|
1030
|
-
* // → filter=(title ~ '
|
|
1058
|
+
* // → filter=(title ~ 'x' && published = true)
|
|
1031
1059
|
*
|
|
1032
1060
|
* // PocketBase `?` array operators (multi-select / multi-relation):
|
|
1033
1061
|
* posts.getList(1, 20, { filter: q("tags").anyEq("news") });
|
|
@@ -1046,69 +1074,6 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
1046
1074
|
* `filter: (w) => w("title").contains("x")` type-checks field names inline.
|
|
1047
1075
|
*/
|
|
1048
1076
|
private resolveFilter;
|
|
1049
|
-
/**
|
|
1050
|
-
* Resolve the leading relation chain of an expand token against the
|
|
1051
|
-
* (optionally schema-aware) collection graph.
|
|
1052
|
-
*
|
|
1053
|
-
* Walks `segments` from this collection: each segment that is a relation
|
|
1054
|
-
* advances to its target collection. Stops at the first non-relation
|
|
1055
|
-
* segment or when the target schema is unknown.
|
|
1056
|
-
*
|
|
1057
|
-
* @returns `depth` — how many leading segments are relations; and
|
|
1058
|
-
* `canInspect` — whether the schema at `depth` is known (so the next
|
|
1059
|
-
* segment can be classified as a field selection vs a nested relation).
|
|
1060
|
-
*/
|
|
1061
|
-
private resolveRelationChain;
|
|
1062
|
-
/** Follow a relation field to its target collection, if resolvable. */
|
|
1063
|
-
private resolveTargetCollection;
|
|
1064
|
-
/** Warn once when an expand field is not a relation (schema known). */
|
|
1065
|
-
private warnNonRelation;
|
|
1066
|
-
/**
|
|
1067
|
-
* Validate and normalise a caller's `expand` string.
|
|
1068
|
-
*
|
|
1069
|
-
* PocketBase only expands *relations*: a dotted token like `author.user`
|
|
1070
|
-
* walks into the related record. Callers often use a dotted token to mean
|
|
1071
|
-
* "only these fields of the expanded record" (`owner.name,owner.email`),
|
|
1072
|
-
* which PocketBase silently drops. When the trailing segment is not a
|
|
1073
|
-
* relation — resolved from the schema graph — the token is rewritten as a
|
|
1074
|
-
* field selection:
|
|
1075
|
-
*
|
|
1076
|
-
* ```
|
|
1077
|
-
* expand: 'owner.name,owner.email'
|
|
1078
|
-
* → expand=owner&fields=<base>,expand.owner.name,expand.owner.email
|
|
1079
|
-
* ```
|
|
1080
|
-
*
|
|
1081
|
-
* Tokens whose whole path is relations keep their existing nested-expand
|
|
1082
|
-
* behaviour. Without a schema the two are indistinguishable, so a lone
|
|
1083
|
-
* dotted token stays a nested expand (with a warning) while two or more
|
|
1084
|
-
* dotted tokens sharing the same relation are treated as field selection.
|
|
1085
|
-
*/
|
|
1086
|
-
private normalizeExpand;
|
|
1087
|
-
/**
|
|
1088
|
-
* Keep only the requested leaf fields on `record.expand.<relation>`.
|
|
1089
|
-
*
|
|
1090
|
-
* Mirrors PocketBase's server-side `fields=expand.<rel>.<field>` projection
|
|
1091
|
-
* for servers that don't support it (the LazyPock server), so field
|
|
1092
|
-
* selection behaves the same against both. A no-op when the server already
|
|
1093
|
-
* narrowed the record. Multi-relations are narrowed element-wise.
|
|
1094
|
-
*/
|
|
1095
|
-
private applyExpandNarrowing;
|
|
1096
|
-
/**
|
|
1097
|
-
* Merge the expand-preserving selectors into the base field projection.
|
|
1098
|
-
*
|
|
1099
|
-
* Both servers are kept happy at once:
|
|
1100
|
-
* - PocketBase drops the whole `expand` payload unless an `expand.<key>`
|
|
1101
|
-
* entry is present in `fields`;
|
|
1102
|
-
* - the LazyPock server projects first (strict, top-level only) and then
|
|
1103
|
-
* expands, so the relation *field* itself must be present in `fields`.
|
|
1104
|
-
*
|
|
1105
|
-
* We therefore add both the relation field (`cate`) and the
|
|
1106
|
-
* `expand.<key>` entry. When no projection is active, no `fields` param is
|
|
1107
|
-
* sent at all — a value like `*` plus other tokens is not a wildcard on
|
|
1108
|
-
* the LazyPock server (it is a strict take, yielding empty records) and
|
|
1109
|
-
* the server keeps `expand` by default when `fields` is absent.
|
|
1110
|
-
*/
|
|
1111
|
-
private mergeExpandFields;
|
|
1112
1077
|
/**
|
|
1113
1078
|
* Fetch a paginated list of records (PocketBase `getList`).
|
|
1114
1079
|
*
|
|
@@ -1120,7 +1085,8 @@ declare class CollectionService<T = ApiRecord, TData = never, TFields = T, TExpa
|
|
|
1120
1085
|
expand?: ExpandObj<E, TExpand>;
|
|
1121
1086
|
}> | null>;
|
|
1122
1087
|
/**
|
|
1123
|
-
* Fetch all records at once (auto-paginates; `batch` defaults to and is
|
|
1088
|
+
* Fetch all records at once (auto-paginates; `batch` defaults to and is
|
|
1089
|
+
* capped at 500, the server max `perPage`). Mirrors PocketBase's
|
|
1124
1090
|
* `pb.collection(name).getFullList()`.
|
|
1125
1091
|
*
|
|
1126
1092
|
* @param options Query params (`sort`, `filter`, `batch`, etc.) + request options.
|