@protobase/client 0.12.22 → 0.13.3
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/client.d.ts +3 -2
- package/dist/client.js +24 -0
- package/dist/file-urls.d.ts +8 -0
- package/dist/file-urls.js +23 -8
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/query-string.d.ts +9 -0
- package/dist/routed-client.js +1 -0
- package/dist/types.d.ts +31 -1
- package/package.json +3 -3
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FilterInput, ListParams } from "./query-string.js";
|
|
1
|
+
import { FilterInput, ListParams, MapParams } from "./query-string.js";
|
|
2
2
|
import { ClientOptions } from "./transport.js";
|
|
3
3
|
import { UploadProgress } from "./upload-request.js";
|
|
4
|
-
import { BatchOp, BatchResult, Facet, Histogram, ListPage, MetaResult, RecordOf, ResourceRef, Series, SeriesParams, Stored } from "./types.js";
|
|
4
|
+
import { BatchOp, BatchResult, Facet, Histogram, ListPage, MapResult, MetaResult, RecordOf, ResourceRef, Series, SeriesParams, Stored } from "./types.js";
|
|
5
5
|
import { KeyValue } from "@protobase/schema";
|
|
6
6
|
//#region src/client.d.ts
|
|
7
7
|
/** How `invoke` calls a function: GET without a body, POST with one, unless `method` says otherwise. */
|
|
@@ -65,6 +65,7 @@ export declare const createClient: (options?: ClientOptions) => {
|
|
|
65
65
|
filter?: FilterInput;
|
|
66
66
|
buckets?: number;
|
|
67
67
|
}) => Promise<Histogram>;
|
|
68
|
+
map: <R extends ResourceRef>(resource: R, params: MapParams) => Promise<MapResult<RecordOf<R>>>;
|
|
68
69
|
seek: <R extends ResourceRef>(resource: R, params: ListParams & {
|
|
69
70
|
position: number;
|
|
70
71
|
}) => Promise<ListPage<RecordOf<R>>>;
|
package/dist/client.js
CHANGED
|
@@ -179,6 +179,29 @@ const createClient = (options = {}) => {
|
|
|
179
179
|
})
|
|
180
180
|
})).json();
|
|
181
181
|
};
|
|
182
|
+
/**
|
|
183
|
+
* The records in a map's view, its bounding box being part of `filter`: the records themselves when few match or the
|
|
184
|
+
* map is close, else buckets of them on a grid sized for `zoom`.
|
|
185
|
+
*/
|
|
186
|
+
const map = async (resource, params) => {
|
|
187
|
+
const body = await (await send({
|
|
188
|
+
method: "GET",
|
|
189
|
+
path: `/${nameOf(resource)}:map`,
|
|
190
|
+
query: queryString({
|
|
191
|
+
latitude: params.latitude,
|
|
192
|
+
longitude: params.longitude,
|
|
193
|
+
zoom: params.zoom,
|
|
194
|
+
filter: filterText(params.filter) || void 0,
|
|
195
|
+
order_by: params.orderBy,
|
|
196
|
+
fields: params.fields?.join(",")
|
|
197
|
+
})
|
|
198
|
+
})).json();
|
|
199
|
+
return {
|
|
200
|
+
items: body.items.map((item) => withFileOrigin(item, origin)),
|
|
201
|
+
buckets: body.buckets,
|
|
202
|
+
totalSize: body.total_size
|
|
203
|
+
};
|
|
204
|
+
};
|
|
182
205
|
/** The page that starts at row `position` of a sort (scrollbar jumps), with the tokens of its own neighbours. Past the end it is empty. */
|
|
183
206
|
const seek = async (resource, params) => {
|
|
184
207
|
const response = await send({
|
|
@@ -259,6 +282,7 @@ const createClient = (options = {}) => {
|
|
|
259
282
|
facets,
|
|
260
283
|
series,
|
|
261
284
|
histogram,
|
|
285
|
+
map,
|
|
262
286
|
seek,
|
|
263
287
|
meta,
|
|
264
288
|
invoke,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StoredFile } from "./types.js";
|
|
2
|
+
//#region src/file-urls.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The link of a stored file, or of its variant by that name when it has one (`fileUrl(listing.photo, 'card')`); the
|
|
5
|
+
* file's own link otherwise, and `undefined` for a missing file or one without a link.
|
|
6
|
+
*/
|
|
7
|
+
export declare const fileUrl: (file: StoredFile, variant?: string) => string | undefined;
|
|
8
|
+
//#endregion
|
package/dist/file-urls.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
//#region src/file-urls.ts
|
|
2
|
+
const isPath = (url) => url.startsWith("/") && !url.startsWith("//");
|
|
2
3
|
const isFileAtPath = (value) => {
|
|
3
4
|
if (typeof value !== "object" || value === null) return false;
|
|
4
5
|
const { uri, url } = value;
|
|
5
|
-
return typeof uri === "string" && typeof url === "string" &&
|
|
6
|
+
return typeof uri === "string" && typeof url === "string" && isPath(url);
|
|
6
7
|
};
|
|
7
8
|
/** The origin of an absolute `baseUrl`; `undefined` for a path on the page's own origin. */
|
|
8
9
|
const originOf = (baseUrl) => baseUrl !== void 0 && URL.canParse(baseUrl) ? new URL(baseUrl).origin : void 0;
|
|
10
|
+
const fromOrigin = (file, origin) => ({
|
|
11
|
+
...file,
|
|
12
|
+
url: `${origin}${file.url}`,
|
|
13
|
+
...file.variants && { variants: Object.fromEntries(Object.entries(file.variants).map(([name, variant]) => [name, isPath(variant.url) ? {
|
|
14
|
+
...variant,
|
|
15
|
+
url: `${origin}${variant.url}`
|
|
16
|
+
} : variant])) }
|
|
17
|
+
});
|
|
9
18
|
/**
|
|
10
|
-
* Makes each file of a record download from `origin
|
|
11
|
-
* page on another origin, or code outside a page, cannot follow. Without an origin the record is
|
|
19
|
+
* Makes each file of a record download from `origin`, its variants too: the API answers a file's URL as a path on its
|
|
20
|
+
* own origin, which a page on another origin, or code outside a page, cannot follow. Without an origin the record is
|
|
21
|
+
* returned as it is.
|
|
12
22
|
*/
|
|
13
23
|
const withFileOrigin = (record, origin) => {
|
|
14
24
|
if (origin === void 0 || typeof record !== "object" || record === null) return record;
|
|
15
|
-
return Object.fromEntries(Object.entries(record).map(([name, value]) => [name, isFileAtPath(value) ?
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
return Object.fromEntries(Object.entries(record).map(([name, value]) => [name, isFileAtPath(value) ? fromOrigin(value, origin) : value]));
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The link of a stored file, or of its variant by that name when it has one (`fileUrl(listing.photo, 'card')`); the
|
|
29
|
+
* file's own link otherwise, and `undefined` for a missing file or one without a link.
|
|
30
|
+
*/
|
|
31
|
+
const fileUrl = (file, variant) => {
|
|
32
|
+
if ("missing" in file) return void 0;
|
|
33
|
+
return (variant === void 0 ? void 0 : file.variants?.[variant]?.url) ?? file.url;
|
|
19
34
|
};
|
|
20
35
|
//#endregion
|
|
21
|
-
export { originOf, withFileOrigin };
|
|
36
|
+
export { fileUrl, originOf, withFileOrigin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { FilterInput, ListParams, filterText, listWire } from "./query-string.js";
|
|
1
|
+
import { FilterInput, ListParams, MapParams, filterText, listWire } from "./query-string.js";
|
|
2
2
|
import { ClientOptions } from "./transport.js";
|
|
3
3
|
import { UploadProgress } from "./upload-request.js";
|
|
4
|
-
import { BatchOp, BatchRef, BatchResult, Facet, Histogram, HistogramBucket, ListPage, Meta, MetaResult, PluginRef, RecordOf, RecordPermissions, ResourcePermissions, ResourceRef, Series, SeriesParams, SeriesPoint, SourceRef, Stored, StoredFile } from "./types.js";
|
|
4
|
+
import { BatchOp, BatchRef, BatchResult, Facet, Histogram, HistogramBucket, ListPage, MapBounds, MapBucket, MapResult, Meta, MetaResult, PluginRef, RecordOf, RecordPermissions, ResourcePermissions, ResourceRef, Series, SeriesParams, SeriesPoint, SourceRef, Stored, StoredFile, StoredFileVariant } from "./types.js";
|
|
5
5
|
import { Client, InvokeOptions, UploadOptions, UploadResult, createClient } from "./client.js";
|
|
6
6
|
import { ApiError, PreconditionFailedError, ProblemDetails, ProblemError, isApiError } from "./problem.js";
|
|
7
|
+
import { fileUrl } from "./file-urls.js";
|
|
7
8
|
import { routedClient } from "./routed-client.js";
|
|
8
9
|
import { SourceMeta, sourceMeta } from "./source-meta.js";
|
|
9
10
|
import { SignInPolicy, SignInPolicyClient, SignInPolicyState, SignInRule, StaffAccessRule } from "./sign-in-policy.js";
|
|
@@ -17,4 +18,4 @@ import { AuthSession, AuthSessionOptions, createAuthSession, tokenExpiry } from
|
|
|
17
18
|
import { createStaticSession } from "./static-session.js";
|
|
18
19
|
import { AssistantClient, AssistantClientOptions, AssistantConnection, createAssistantClient } from "./assistant.js";
|
|
19
20
|
import { RuntimeClient, RuntimeClientOptions, RuntimePolicy, RuntimeStatus, createRuntimeClient } from "./runtime.js";
|
|
20
|
-
export { type AccountSecurity, type AccountSignIn, type ActiveRole, ApiError, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type AuthenticatorSetup, type BatchOp, type BatchRef, type BatchResult, type Client, type ClientOptions, type CurrentOrganization, type Facet, type FilterInput, type Histogram, type HistogramBucket, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type Meta, type MetaResult, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationRole, type OrganizationsClient, type Passkey, type PlatformSignIn, type PluginRef, PreconditionFailedError, type ProblemDetails, type ProblemError, type RecordOf, type RecordPermissions, type RequiredSetup, type ResourcePermissions, type ResourceRef, type RoleLabel, type RoleOption, type RolesClient, type RuntimeClient, type RuntimeClientOptions, type RuntimePolicy, type RuntimeStatus, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type SignInMethod, type SignInPolicy, type SignInPolicyClient, type SignInPolicyState, type SignInResult, type SignInRule, type SourceMeta, type SourceRef, type StaffAccessRule, type StaffSignIn, type StaffSignInClient, type Stored, type StoredFile, type TwoFactorMethod, type UploadOptions, type UploadProgress, type UploadResult, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, filterText, isApiError, listWire, routedClient, sourceMeta, tokenExpiry };
|
|
21
|
+
export { type AccountSecurity, type AccountSignIn, type ActiveRole, ApiError, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type AuthenticatorSetup, type BatchOp, type BatchRef, type BatchResult, type Client, type ClientOptions, type CurrentOrganization, type Facet, type FilterInput, type Histogram, type HistogramBucket, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type MapBounds, type MapBucket, type MapParams, type MapResult, type Meta, type MetaResult, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationRole, type OrganizationsClient, type Passkey, type PlatformSignIn, type PluginRef, PreconditionFailedError, type ProblemDetails, type ProblemError, type RecordOf, type RecordPermissions, type RequiredSetup, type ResourcePermissions, type ResourceRef, type RoleLabel, type RoleOption, type RolesClient, type RuntimeClient, type RuntimeClientOptions, type RuntimePolicy, type RuntimeStatus, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type SignInMethod, type SignInPolicy, type SignInPolicyClient, type SignInPolicyState, type SignInResult, type SignInRule, type SourceMeta, type SourceRef, type StaffAccessRule, type StaffSignIn, type StaffSignInClient, type Stored, type StoredFile, type StoredFileVariant, type TwoFactorMethod, type UploadOptions, type UploadProgress, type UploadResult, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, isApiError, listWire, routedClient, sourceMeta, tokenExpiry };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { filterText, listWire } from "./query-string.js";
|
|
2
|
+
import { fileUrl } from "./file-urls.js";
|
|
2
3
|
import { ApiError, PreconditionFailedError, isApiError } from "./problem.js";
|
|
3
4
|
import { createClient } from "./client.js";
|
|
4
5
|
import { routedClient } from "./routed-client.js";
|
|
@@ -8,4 +9,4 @@ import { createAuthSession, tokenExpiry } from "./auth.js";
|
|
|
8
9
|
import { createStaticSession } from "./static-session.js";
|
|
9
10
|
import { createAssistantClient } from "./assistant.js";
|
|
10
11
|
import { createRuntimeClient } from "./runtime.js";
|
|
11
|
-
export { ApiError, AuthError, PreconditionFailedError, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, filterText, isApiError, listWire, routedClient, sourceMeta, tokenExpiry };
|
|
12
|
+
export { ApiError, AuthError, PreconditionFailedError, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, isApiError, listWire, routedClient, sourceMeta, tokenExpiry };
|
package/dist/query-string.d.ts
CHANGED
|
@@ -10,6 +10,15 @@ export type ListParams = {
|
|
|
10
10
|
fields?: string[];
|
|
11
11
|
count?: 'exact';
|
|
12
12
|
};
|
|
13
|
+
/** What `map` asks for: the fields of the position, the map's zoom, and the bounding box in `filter`. */
|
|
14
|
+
export type MapParams = {
|
|
15
|
+
latitude: string;
|
|
16
|
+
longitude: string;
|
|
17
|
+
zoom: number;
|
|
18
|
+
filter?: FilterInput;
|
|
19
|
+
orderBy?: string;
|
|
20
|
+
fields?: string[];
|
|
21
|
+
};
|
|
13
22
|
export declare const filterText: (filter: FilterInput | undefined) => string | undefined;
|
|
14
23
|
/** The snake_case parameters of `GET /{resource}` and the body of `POST /{resource}:search`. */
|
|
15
24
|
export declare const listWire: (params?: ListParams) => {
|
package/dist/routed-client.js
CHANGED
|
@@ -25,6 +25,7 @@ const routedClient = (own, sourceOf) => {
|
|
|
25
25
|
facets: (resource, field, options) => to(resource).facets(resource, field, options),
|
|
26
26
|
series: (resource, params) => to(resource).series(resource, params),
|
|
27
27
|
histogram: (resource, field, options) => to(resource).histogram(resource, field, options),
|
|
28
|
+
map: (resource, params) => to(resource).map(resource, params),
|
|
28
29
|
seek: (resource, params) => to(resource).seek(resource, params),
|
|
29
30
|
meta: (etag, options) => own.meta(etag, options),
|
|
30
31
|
invoke: (name, options) => own.invoke(name, options),
|
package/dist/types.d.ts
CHANGED
|
@@ -54,6 +54,26 @@ export type Histogram = {
|
|
|
54
54
|
max: number | null;
|
|
55
55
|
buckets: HistogramBucket[];
|
|
56
56
|
};
|
|
57
|
+
/** The corners around some records, in decimal degrees. */
|
|
58
|
+
export type MapBounds = {
|
|
59
|
+
south: number;
|
|
60
|
+
west: number;
|
|
61
|
+
north: number;
|
|
62
|
+
east: number;
|
|
63
|
+
};
|
|
64
|
+
/** The records in one cell of a map's grid: how many, their mean position, and the bounds around them. */
|
|
65
|
+
export type MapBucket = {
|
|
66
|
+
count: number;
|
|
67
|
+
latitude: number;
|
|
68
|
+
longitude: number;
|
|
69
|
+
bounds: MapBounds;
|
|
70
|
+
};
|
|
71
|
+
/** The records `map` answers, or buckets of them when many match, never both; `totalSize` counts the matches. */
|
|
72
|
+
export type MapResult<T> = {
|
|
73
|
+
items: T[];
|
|
74
|
+
buckets: MapBucket[];
|
|
75
|
+
totalSize: number;
|
|
76
|
+
};
|
|
57
77
|
/** What the signed-in user may do with a resource; `conditional` operations are decided per record by the server. */
|
|
58
78
|
export type ResourcePermissions = {
|
|
59
79
|
read?: boolean;
|
|
@@ -124,9 +144,17 @@ export type Stored<T> = {
|
|
|
124
144
|
etag: string;
|
|
125
145
|
permissions?: RecordPermissions;
|
|
126
146
|
};
|
|
147
|
+
/** A resized copy of an image, by the field's `.variants()`: its link and type, and the box it is resized into. */
|
|
148
|
+
export type StoredFileVariant = {
|
|
149
|
+
url: string;
|
|
150
|
+
type: string;
|
|
151
|
+
width?: number;
|
|
152
|
+
height?: number;
|
|
153
|
+
};
|
|
127
154
|
/**
|
|
128
155
|
* A file field as records carry it. `url` downloads it: signed and valid one to two hours for a private file, permanent
|
|
129
|
-
* for a public one.
|
|
156
|
+
* for a public one. An image may have `variants` by name and a `placeholder`, its ThumbHash in base64. Send `uri` back
|
|
157
|
+
* unchanged to keep the file, or `null` to clear it.
|
|
130
158
|
*/
|
|
131
159
|
export type StoredFile = {
|
|
132
160
|
uri: string;
|
|
@@ -134,6 +162,8 @@ export type StoredFile = {
|
|
|
134
162
|
type: string;
|
|
135
163
|
size?: number;
|
|
136
164
|
url?: string;
|
|
165
|
+
placeholder?: string;
|
|
166
|
+
variants?: Record<string, StoredFileVariant>;
|
|
137
167
|
} | {
|
|
138
168
|
uri: string;
|
|
139
169
|
missing: true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"description": "Typed fetch client for the Protobase REST API.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@better-auth/passkey": "^1.7.7",
|
|
33
|
-
"@protobase/layout": "0.
|
|
34
|
-
"@protobase/schema": "0.
|
|
33
|
+
"@protobase/layout": "0.13.3",
|
|
34
|
+
"@protobase/schema": "0.13.3",
|
|
35
35
|
"@simplewebauthn/browser": "^13.3.0",
|
|
36
36
|
"better-auth": "^1.7.7"
|
|
37
37
|
}
|