lazypock 0.19.2 → 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 +36 -0
- package/dist/index.cjs +905 -674
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +232 -82
- package/dist/index.d.ts +232 -82
- package/dist/index.global.js +904 -674
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +904 -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 +37 -6
- package/src/index.ts +12 -0
- package/src/lazypock.ts +65 -71
- package/src/mail.ts +290 -0
- 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/types.ts +1 -1
- package/src/collection.ts +0 -1412
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ── Collection paths ────────────────────────────────────
|
|
2
|
+
// The server's collection routes live in exactly one place: a path repeated
|
|
3
|
+
// eighteen times is a path that drifts.
|
|
4
|
+
|
|
5
|
+
/** URL-encode a collection name or record id. */
|
|
6
|
+
export function encodeId(id: string): string {
|
|
7
|
+
return encodeURIComponent(id);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The records endpoint for a collection
|
|
12
|
+
* (`/api/collections/<name>/records`).
|
|
13
|
+
*/
|
|
14
|
+
export function recordsPath(collectionName: string): string {
|
|
15
|
+
return "/collections/" + encodeId(collectionName) + "/records";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The collection's own endpoint, which is where its auth routes live. */
|
|
19
|
+
export function collectionPath(collectionName: string): string {
|
|
20
|
+
return "/collections/" + encodeId(collectionName);
|
|
21
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// ── Query building ──────────────────────────────────────
|
|
2
|
+
// Turns a caller's option bag into the query string both servers understand:
|
|
3
|
+
// array shorthands joined, filter callbacks resolved, `expand` normalised, and
|
|
4
|
+
// the field projection merged so expanded data survives strict projection.
|
|
5
|
+
|
|
6
|
+
import type { ExpandContext } from "../expand";
|
|
7
|
+
import { normalizeExpand } from "../expand";
|
|
8
|
+
import { mergeExpandFields } from "../projection";
|
|
9
|
+
|
|
10
|
+
/** The service state query building needs. */
|
|
11
|
+
export interface QueryContext {
|
|
12
|
+
/** Schema-aware expand normalisation. */
|
|
13
|
+
expand: ExpandContext;
|
|
14
|
+
/** Resolves `options.fields` / `select()` / schema default. */
|
|
15
|
+
effectiveFields(optionsFields?: string): string | undefined;
|
|
16
|
+
/** Resolves a `filter` callback into a string / FilterExpr. */
|
|
17
|
+
resolveFilter(filter: unknown): unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A built request query. */
|
|
21
|
+
export interface BuiltQuery {
|
|
22
|
+
/** The serialised query string (no leading `?`). */
|
|
23
|
+
qs: string;
|
|
24
|
+
/**
|
|
25
|
+
* Top-level relation → leaf fields to apply client-side, for servers that
|
|
26
|
+
* return the full expanded record regardless of `fields`.
|
|
27
|
+
*/
|
|
28
|
+
narrow: Map<string, string[]>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Build the query string for a list request.
|
|
33
|
+
*
|
|
34
|
+
* Mutates `queryParams` in place (it is always a fresh rest object) and drops
|
|
35
|
+
* keys whose value is `undefined` only implicitly, via `String()` — matching
|
|
36
|
+
* the historical serialisation exactly.
|
|
37
|
+
*/
|
|
38
|
+
export function buildListQuery(
|
|
39
|
+
ctx: QueryContext,
|
|
40
|
+
page: number,
|
|
41
|
+
perPage: number,
|
|
42
|
+
queryParams: Record<string, unknown>,
|
|
43
|
+
): BuiltQuery {
|
|
44
|
+
// Array shorthands (`sort: ["-title"]`, `expand: ["author"]`) join to
|
|
45
|
+
// the comma-separated form the server expects.
|
|
46
|
+
if (Array.isArray(queryParams.sort)) {
|
|
47
|
+
queryParams.sort = queryParams.sort.join(",");
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(queryParams.expand)) {
|
|
50
|
+
queryParams.expand = queryParams.expand.join(",");
|
|
51
|
+
}
|
|
52
|
+
// Resolve a `filter` callback (receives the typed `where` helper) into
|
|
53
|
+
// a concrete string / FilterExpr before serialization.
|
|
54
|
+
if (typeof queryParams.filter === "function") {
|
|
55
|
+
queryParams.filter = ctx.resolveFilter(queryParams.filter);
|
|
56
|
+
}
|
|
57
|
+
// Normalise `expand`: dotted tokens that select fields of a relation are
|
|
58
|
+
// rewritten to PocketBase's `expand` + `fields=expand.<rel>.<field>`
|
|
59
|
+
// form (raw `expand=owner.name` is silently ignored by the server).
|
|
60
|
+
const expandInfo = normalizeExpand(
|
|
61
|
+
typeof queryParams.expand === "string" ? queryParams.expand : undefined,
|
|
62
|
+
ctx.expand,
|
|
63
|
+
);
|
|
64
|
+
if (expandInfo.expand !== undefined) {
|
|
65
|
+
queryParams.expand = expandInfo.expand;
|
|
66
|
+
}
|
|
67
|
+
// Resolve the effective `fields` projection (select() preset or schema
|
|
68
|
+
// default) and keep the expanded data alive under strict projection.
|
|
69
|
+
const fields = mergeExpandFields(
|
|
70
|
+
ctx.effectiveFields(queryParams.fields as string | undefined),
|
|
71
|
+
expandInfo,
|
|
72
|
+
);
|
|
73
|
+
if (fields !== undefined) {
|
|
74
|
+
queryParams.fields = fields;
|
|
75
|
+
}
|
|
76
|
+
const qs = new URLSearchParams(
|
|
77
|
+
Object.fromEntries(
|
|
78
|
+
Object.entries({
|
|
79
|
+
// `page`/`perPage` are spread LAST so the call's positional arguments
|
|
80
|
+
// win: with the caller's keys last, `getList(2, 30, { page: 5 })`
|
|
81
|
+
// silently requested page 5, and `getFullList({ perPage: 1000 })`
|
|
82
|
+
// slipped a >500 `perPage` past `clampBatch`.
|
|
83
|
+
...queryParams,
|
|
84
|
+
page: String(page),
|
|
85
|
+
perPage: String(perPage),
|
|
86
|
+
}).map(([k, v]) => [k, String(v)]),
|
|
87
|
+
),
|
|
88
|
+
).toString();
|
|
89
|
+
return { qs, narrow: expandInfo.narrow };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Build the query string for a single-record read. */
|
|
93
|
+
export function buildReadQuery(
|
|
94
|
+
ctx: QueryContext,
|
|
95
|
+
options?: { expand?: string | readonly string[]; fields?: string },
|
|
96
|
+
): BuiltQuery {
|
|
97
|
+
const rawExpand = Array.isArray(options?.expand)
|
|
98
|
+
? options.expand.join(",")
|
|
99
|
+
: typeof options?.expand === "string"
|
|
100
|
+
? options.expand
|
|
101
|
+
: undefined;
|
|
102
|
+
const expandInfo = normalizeExpand(rawExpand, ctx.expand);
|
|
103
|
+
const fields = mergeExpandFields(
|
|
104
|
+
ctx.effectiveFields(options?.fields),
|
|
105
|
+
expandInfo,
|
|
106
|
+
);
|
|
107
|
+
const qs = new URLSearchParams();
|
|
108
|
+
if (fields !== undefined) qs.set("fields", fields);
|
|
109
|
+
if (rawExpand !== undefined) qs.set("expand", expandInfo.expand ?? rawExpand);
|
|
110
|
+
return { qs: qs.toString(), narrow: expandInfo.narrow };
|
|
111
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// ── Collection realtime subscriptions ───────────────────
|
|
2
|
+
// Topic naming, event normalisation and the PocketBase-compatible argument
|
|
3
|
+
// forms for a single collection's record channel.
|
|
4
|
+
|
|
5
|
+
import type { RealtimeService } from "../realtime";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A realtime record-change event delivered to subscription callbacks.
|
|
9
|
+
* Mirrors PocketBase's RealtimeService result shape (`action` + `record`).
|
|
10
|
+
*/
|
|
11
|
+
export interface RealtimeMessage {
|
|
12
|
+
action: "create" | "update" | "delete";
|
|
13
|
+
record: Record<string, unknown>;
|
|
14
|
+
topic?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Subscription callback for a collection's realtime events. */
|
|
18
|
+
export type RealtimeCallback = (e: RealtimeMessage) => void;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Options for {@link CollectionService.subscribe} (PocketBase-compatible).
|
|
22
|
+
*
|
|
23
|
+
* `expand` and any extra keys are forwarded to the server channel join
|
|
24
|
+
* payload (available to `onRealtimeSubscribeRequest` hooks). `headers` is
|
|
25
|
+
* accepted for PocketBase signature compatibility but has no effect over
|
|
26
|
+
* the SSE connection — it is not forwarded.
|
|
27
|
+
*/
|
|
28
|
+
export interface RealtimeSubscribeOptions {
|
|
29
|
+
/** Fields to expand on the subscribed records (server join payload). */
|
|
30
|
+
expand?: string;
|
|
31
|
+
/** Accepted for PocketBase parity; not sent over the SSE connection. */
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
/** Any extra keys are forwarded verbatim to the server join payload. */
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Raw event passed by the low-level realtime service. */
|
|
38
|
+
interface RealtimeEventLike {
|
|
39
|
+
event: string;
|
|
40
|
+
topic: string;
|
|
41
|
+
payload?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** What a collection's realtime helpers need. */
|
|
45
|
+
export interface CollectionRealtimeContext {
|
|
46
|
+
realtime?: RealtimeService;
|
|
47
|
+
collectionName: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The topic prefix shared by every subscription of one collection. */
|
|
51
|
+
export function collectionTopic(collectionName: string): string {
|
|
52
|
+
return "collection:" + collectionName;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Map a raw event/action to a normalised create/update/delete action. */
|
|
56
|
+
export function normalizeAction(
|
|
57
|
+
event: string,
|
|
58
|
+
rawAction?: unknown,
|
|
59
|
+
): RealtimeMessage["action"] {
|
|
60
|
+
if (typeof rawAction === "string") {
|
|
61
|
+
const a = rawAction.toLowerCase();
|
|
62
|
+
if (a === "create" || a === "update" || a === "delete") {
|
|
63
|
+
return a;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (event === "record_change") return "update";
|
|
67
|
+
if (event === "create" || event === "record_create") return "create";
|
|
68
|
+
if (event === "delete" || event === "record_delete") return "delete";
|
|
69
|
+
return "update";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Subscribe to this collection's realtime changes.
|
|
74
|
+
*
|
|
75
|
+
* Accepts the PocketBase argument order (`recordId`, `callback`, `options`)
|
|
76
|
+
* and the legacy callback-first form (`callback`, `recordId`).
|
|
77
|
+
*
|
|
78
|
+
* @returns A function that unsubscribes this callback.
|
|
79
|
+
*/
|
|
80
|
+
export function subscribeToCollection(
|
|
81
|
+
ctx: CollectionRealtimeContext,
|
|
82
|
+
topicOrCallback: string | RealtimeCallback,
|
|
83
|
+
maybeCallback?: RealtimeCallback | string,
|
|
84
|
+
options?: RealtimeSubscribeOptions,
|
|
85
|
+
): () => void {
|
|
86
|
+
const { realtime, collectionName } = ctx;
|
|
87
|
+
if (!realtime) {
|
|
88
|
+
console.warn("[lazypock] No realtime service configured.");
|
|
89
|
+
return () => {};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let recordId: string | undefined;
|
|
93
|
+
let callback: RealtimeCallback;
|
|
94
|
+
let joinPayload: Record<string, unknown> | undefined;
|
|
95
|
+
|
|
96
|
+
if (typeof topicOrCallback === "function") {
|
|
97
|
+
callback = topicOrCallback;
|
|
98
|
+
if (typeof maybeCallback === "string") recordId = maybeCallback;
|
|
99
|
+
} else {
|
|
100
|
+
callback = maybeCallback as RealtimeCallback;
|
|
101
|
+
recordId = topicOrCallback === "*" ? undefined : topicOrCallback;
|
|
102
|
+
// Forward subscribe options (minus HTTP-only headers) to the server
|
|
103
|
+
// channel join payload.
|
|
104
|
+
const { headers: _ignored, ...rest } = options ?? {};
|
|
105
|
+
if (Object.keys(rest).length > 0) joinPayload = rest;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const topic =
|
|
109
|
+
collectionTopic(collectionName) + (recordId ? ":" + recordId : "");
|
|
110
|
+
const handler = (raw: RealtimeEventLike) => {
|
|
111
|
+
const record = (raw.payload?.["record"] ?? {}) as Record<string, unknown>;
|
|
112
|
+
callback({
|
|
113
|
+
action: normalizeAction(raw.event, raw.payload?.["action"]),
|
|
114
|
+
record,
|
|
115
|
+
topic: raw.topic,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
realtime.ensureConnected();
|
|
119
|
+
realtime.subscribe(topic, handler as never, joinPayload);
|
|
120
|
+
return () => realtime.unsubscribe(topic, handler as never);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Unsubscribe from realtime changes (PocketBase-compatible):
|
|
125
|
+
* - `unsubscribe()` — remove **all** subscriptions of this collection
|
|
126
|
+
* - `unsubscribe('*')` — remove wildcard subscriptions
|
|
127
|
+
* - `unsubscribe('RECORD_ID')` — remove that record's subscriptions
|
|
128
|
+
*/
|
|
129
|
+
export function unsubscribeFromCollection(
|
|
130
|
+
ctx: CollectionRealtimeContext,
|
|
131
|
+
recordId?: string,
|
|
132
|
+
): void {
|
|
133
|
+
const { realtime, collectionName } = ctx;
|
|
134
|
+
if (recordId === undefined) {
|
|
135
|
+
realtime?.unsubscribeByPrefix(collectionTopic(collectionName));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const topic =
|
|
139
|
+
collectionTopic(collectionName) + (recordId === "*" ? "" : ":" + recordId);
|
|
140
|
+
realtime?.unsubscribe(topic);
|
|
141
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// ── Auth responses & session recording ──────────────────
|
|
2
|
+
// One place that turns a server auth response into a stored session. Every
|
|
3
|
+
// auth route (password, refresh, OAuth2, superuser login) goes through it, so
|
|
4
|
+
// the refresh token and the real `expiresIn` can never be dropped again.
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
rememberAuthResponse,
|
|
8
|
+
type AuthModel,
|
|
9
|
+
type AuthStore,
|
|
10
|
+
} from "../auth";
|
|
11
|
+
import type { HttpClient } from "../http";
|
|
12
|
+
import type { ApiRecord, RequestOptions } from "../types";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The shape of a successful auth response: Pancake/PocketBase auth routes
|
|
16
|
+
* return a token plus the authenticated record.
|
|
17
|
+
*/
|
|
18
|
+
export type AuthResponse = { token: string; record: ApiRecord } & Record<
|
|
19
|
+
string,
|
|
20
|
+
unknown
|
|
21
|
+
>;
|
|
22
|
+
|
|
23
|
+
/** What the auth routes need: a transport, the collection, and the store. */
|
|
24
|
+
export interface SessionContext {
|
|
25
|
+
http: HttpClient;
|
|
26
|
+
/** The auth collection this session belongs to. */
|
|
27
|
+
collectionName: string;
|
|
28
|
+
/** Where the session is recorded. When absent, the response is returned only. */
|
|
29
|
+
authStore?: AuthStore;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Record an auth response in the store: the collection name, the access token,
|
|
34
|
+
* the refresh token and the access token's real lifetime.
|
|
35
|
+
*
|
|
36
|
+
* `model` is explicit because a superuser session has no record — it is stored
|
|
37
|
+
* with a `null` model and no collection name.
|
|
38
|
+
*/
|
|
39
|
+
export function rememberSession(
|
|
40
|
+
ctx: SessionContext,
|
|
41
|
+
data: Record<string, unknown> | null | undefined,
|
|
42
|
+
model: AuthModel | null,
|
|
43
|
+
): void {
|
|
44
|
+
if (!data || !ctx.authStore) return;
|
|
45
|
+
ctx.authStore.setCollectionName(ctx.collectionName);
|
|
46
|
+
rememberAuthResponse(ctx.authStore, data, model);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Record the auth response's own `record` field as the session model. */
|
|
50
|
+
export function rememberSessionRecord(
|
|
51
|
+
ctx: SessionContext,
|
|
52
|
+
data: Record<string, unknown> | null | undefined,
|
|
53
|
+
): void {
|
|
54
|
+
const record = data?.["record"];
|
|
55
|
+
// SAFETY: the server's auth response record is a superset of AuthModel;
|
|
56
|
+
// the auth store consumes it generically.
|
|
57
|
+
const model =
|
|
58
|
+
record && typeof record === "object" ? (record as AuthModel) : null;
|
|
59
|
+
rememberSession(ctx, data, model);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* POST an auth route and record the resulting session.
|
|
64
|
+
*
|
|
65
|
+
* @param path Route suffix appended to the collection path (e.g. `auth-refresh`).
|
|
66
|
+
*/
|
|
67
|
+
export async function postWithSession<T extends Record<string, unknown>>(
|
|
68
|
+
ctx: SessionContext,
|
|
69
|
+
path: string,
|
|
70
|
+
body: unknown,
|
|
71
|
+
options?: RequestOptions,
|
|
72
|
+
): Promise<T | null> {
|
|
73
|
+
const data = await ctx.http.post<T>(path, body, options);
|
|
74
|
+
rememberSessionRecord(ctx, data);
|
|
75
|
+
return data;
|
|
76
|
+
}
|
package/src/collections.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import type { HttpClient } from "./http";
|
|
14
14
|
import type { RealtimeService } from "./realtime";
|
|
15
|
-
import {
|
|
15
|
+
import { fullListKey, paginateAll, splitListOptions } from "./paginate";
|
|
16
16
|
import type { ListResult, RequestOptions, ApiRecord } from "./types";
|
|
17
17
|
|
|
18
18
|
const REGISTRY_TOPIC = "collections";
|
|
@@ -74,52 +74,15 @@ export class CollectionsService {
|
|
|
74
74
|
options?: Record<string, unknown> & RequestOptions,
|
|
75
75
|
): Promise<Array<T>> {
|
|
76
76
|
if (!this.http) return [];
|
|
77
|
-
|
|
78
|
-
const batch =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
signal: sig,
|
|
87
|
-
params: passthroughParams,
|
|
88
|
-
...queryParams
|
|
89
|
-
} = rest as Record<string, unknown> & RequestOptions;
|
|
90
|
-
|
|
91
|
-
// Stable key for the whole full-list fetch — see CollectionService.getFullList
|
|
92
|
-
// for the rationale (single-flight dedup, per-page paths stay unique).
|
|
93
|
-
const effectiveKey =
|
|
94
|
-
typeof reqKey === "string"
|
|
95
|
-
? reqKey
|
|
96
|
-
: `getFullList:collections:${stableStringify(rest)}`;
|
|
97
|
-
|
|
98
|
-
const items: T[] = [];
|
|
99
|
-
let page = 1;
|
|
100
|
-
// Auto-paginate until empty (bounded by perPage and totalPages).
|
|
101
|
-
for (;;) {
|
|
102
|
-
const res = await this.getList<T>(
|
|
103
|
-
{
|
|
104
|
-
...queryParams,
|
|
105
|
-
...(passthroughParams ?? {}),
|
|
106
|
-
page,
|
|
107
|
-
perPage: batch,
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
requestKey: effectiveKey,
|
|
111
|
-
singleFlight: true,
|
|
112
|
-
...(fetchFn ? { fetch: fetchFn } : {}),
|
|
113
|
-
...(hdrs ? { headers: hdrs } : {}),
|
|
114
|
-
...(sig ? { signal: sig } : {}),
|
|
115
|
-
} as RequestOptions,
|
|
116
|
-
);
|
|
117
|
-
if (!res || !res.items || res.items.length === 0) break;
|
|
118
|
-
items.push(...(res.items as T[]));
|
|
119
|
-
if (page >= (res.totalPages ?? page)) break;
|
|
120
|
-
page += 1;
|
|
121
|
-
}
|
|
122
|
-
return items;
|
|
77
|
+
// Same split/clamp/key logic as the records service — see paginate.ts.
|
|
78
|
+
const { query, transport, batch } = splitListOptions(options);
|
|
79
|
+
const requestKey = fullListKey("collections", query, transport.requestKey);
|
|
80
|
+
return paginateAll<T>(batch, (page, perPage) =>
|
|
81
|
+
this.getList<T>(
|
|
82
|
+
{ ...query, page, perPage },
|
|
83
|
+
{ ...transport, requestKey, singleFlight: true },
|
|
84
|
+
),
|
|
85
|
+
);
|
|
123
86
|
}
|
|
124
87
|
|
|
125
88
|
/**
|
|
@@ -179,11 +142,14 @@ export class CollectionsService {
|
|
|
179
142
|
* @param options Optional request options.
|
|
180
143
|
*/
|
|
181
144
|
async delete(id: string, options?: RequestOptions): Promise<boolean> {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
145
|
+
if (!this.http) return false;
|
|
146
|
+
// Must be awaited: `delete` returns a promise, and comparing that promise
|
|
147
|
+
// to null (as this used to) is always false — the method reported success
|
|
148
|
+
// synchronously while a 403/404/network failure escaped as an unhandled
|
|
149
|
+
// rejection. Both `delete` and the API keep the same signature; failures
|
|
150
|
+
// now reject with ApiError, like create()/update().
|
|
151
|
+
await this.http.delete("/collections/" + encodeURIComponent(id), options);
|
|
152
|
+
return true;
|
|
187
153
|
}
|
|
188
154
|
|
|
189
155
|
/**
|