@mdbase-dev/connect 0.1.0-beta.21
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/LICENSE +21 -0
- package/README.md +405 -0
- package/dist/async.d.ts +1 -0
- package/dist/async.js +13 -0
- package/dist/authorization-types.d.ts +7 -0
- package/dist/authorization-types.js +1 -0
- package/dist/authorization-url.d.ts +3 -0
- package/dist/authorization-url.js +27 -0
- package/dist/base64.d.ts +3 -0
- package/dist/base64.js +21 -0
- package/dist/browser/integrity.json +4 -0
- package/dist/browser/mdbase-connect.min.js +3 -0
- package/dist/browser/mdbase-connect.min.js.sha384 +1 -0
- package/dist/collection-client.d.ts +57 -0
- package/dist/collection-client.js +214 -0
- package/dist/connect.d.ts +39 -0
- package/dist/connect.js +620 -0
- package/dist/connection-notifications.d.ts +25 -0
- package/dist/connection-notifications.js +179 -0
- package/dist/connection-transport.d.ts +80 -0
- package/dist/connection-transport.js +670 -0
- package/dist/connection-types.d.ts +29 -0
- package/dist/connection-types.js +1 -0
- package/dist/connection.d.ts +154 -0
- package/dist/connection.js +371 -0
- package/dist/crypto.d.ts +64 -0
- package/dist/crypto.js +391 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +83 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/internal-types.d.ts +70 -0
- package/dist/internal-types.js +1 -0
- package/dist/notifications.d.ts +47 -0
- package/dist/notifications.js +52 -0
- package/dist/operation-helpers.d.ts +24 -0
- package/dist/operation-helpers.js +129 -0
- package/dist/operation-types.d.ts +254 -0
- package/dist/operation-types.js +1 -0
- package/dist/runtime-utils.d.ts +33 -0
- package/dist/runtime-utils.js +224 -0
- package/dist/selection.d.ts +48 -0
- package/dist/selection.js +112 -0
- package/dist/session.d.ts +76 -0
- package/dist/session.js +271 -0
- package/package.json +41 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MdbaseConnectError } from "./errors.js";
|
|
2
|
+
export function parseMdbasePushPayload(value) {
|
|
3
|
+
if (!value || typeof value !== "object") {
|
|
4
|
+
throw new MdbaseConnectError("invalid_push_payload", "The push payload is not an object.");
|
|
5
|
+
}
|
|
6
|
+
const payload = value;
|
|
7
|
+
if (payload.type !== "mdbase.notification"
|
|
8
|
+
|| payload.version !== 1
|
|
9
|
+
|| typeof payload.signal_id !== "string"
|
|
10
|
+
|| typeof payload.criterion_id !== "string"
|
|
11
|
+
|| typeof payload.cursor !== "string"
|
|
12
|
+
|| !payload.presentation
|
|
13
|
+
|| typeof payload.presentation.title !== "string") {
|
|
14
|
+
throw new MdbaseConnectError("invalid_push_payload", "The push payload is not an mdbase notification.");
|
|
15
|
+
}
|
|
16
|
+
return payload;
|
|
17
|
+
}
|
|
18
|
+
/** Parse the string-valued data attached to an APNs/FCM notification. */
|
|
19
|
+
export function parseMdbaseNativeNotificationData(value) {
|
|
20
|
+
if (!value || typeof value !== "object") {
|
|
21
|
+
throw new MdbaseConnectError("invalid_push_payload", "The native notification data is not an object.");
|
|
22
|
+
}
|
|
23
|
+
const data = value;
|
|
24
|
+
if (data.type !== "mdbase.notification"
|
|
25
|
+
|| (data.version !== 1 && data.version !== "1")
|
|
26
|
+
|| typeof data.signal_id !== "string"
|
|
27
|
+
|| typeof data.criterion_id !== "string"
|
|
28
|
+
|| typeof data.cursor !== "string") {
|
|
29
|
+
throw new MdbaseConnectError("invalid_push_payload", "The native notification data is not an mdbase notification.");
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
type: "mdbase.notification",
|
|
33
|
+
version: 1,
|
|
34
|
+
signal_id: data.signal_id,
|
|
35
|
+
criterion_id: data.criterion_id,
|
|
36
|
+
cursor: data.cursor
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Display a validated mdbase push from a service worker `push` handler. */
|
|
40
|
+
export function showMdbasePushNotification(registration, value) {
|
|
41
|
+
const payload = parseMdbasePushPayload(value);
|
|
42
|
+
return registration.showNotification(payload.presentation.title, {
|
|
43
|
+
...(payload.presentation.body ? { body: payload.presentation.body } : {}),
|
|
44
|
+
...(payload.presentation.tag ? { tag: payload.presentation.tag } : {}),
|
|
45
|
+
data: {
|
|
46
|
+
type: payload.type,
|
|
47
|
+
signal_id: payload.signal_id,
|
|
48
|
+
criterion_id: payload.criterion_id,
|
|
49
|
+
cursor: payload.cursor
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CollectionOperation } from "@mdbase-dev/connect-protocol";
|
|
2
|
+
import { MdbaseConnectError } from "./errors.js";
|
|
3
|
+
import type { StoredToken } from "./internal-types.js";
|
|
4
|
+
import type { DeleteInput, DeletePreflightResult, MutationEstimate, RenameInput, RenamePreflightResult } from "./operation-types.js";
|
|
5
|
+
export type LoopbackRequestInit = RequestInit & {
|
|
6
|
+
targetAddressSpace?: "loopback";
|
|
7
|
+
};
|
|
8
|
+
export declare function loopbackRequest(init: RequestInit): LoopbackRequestInit;
|
|
9
|
+
export declare function localNetworkPermission(): Promise<PermissionState | null>;
|
|
10
|
+
export declare function directFallbackStatus(status: number): boolean;
|
|
11
|
+
export declare function isMutation(operation: CollectionOperation, input?: unknown): boolean;
|
|
12
|
+
export declare function uniqueOperations(operations: CollectionOperation[]): CollectionOperation[];
|
|
13
|
+
export declare function sameAuthorization(left: StoredToken, right: StoredToken): boolean;
|
|
14
|
+
export declare function throwIfCancelled(signal?: AbortSignal): void;
|
|
15
|
+
export declare function operationTransportError(error: unknown, signal: AbortSignal | undefined, outcomeUnknown: boolean): Error;
|
|
16
|
+
export declare function isCancellation(error: unknown, signal?: AbortSignal): boolean;
|
|
17
|
+
export declare function assertRenamePreview(input: RenameInput, preview: RenamePreflightResult): void;
|
|
18
|
+
export declare function assertDeletePreview(input: DeleteInput, preview: DeletePreflightResult): void;
|
|
19
|
+
export declare function renameEstimate(input: RenameInput, preview: RenamePreflightResult): MutationEstimate;
|
|
20
|
+
export declare function deleteEstimate(preview: DeletePreflightResult): MutationEstimate;
|
|
21
|
+
export declare function operationFingerprint(operation: CollectionOperation, input: unknown): Promise<string>;
|
|
22
|
+
export declare function canonicalJson(value: unknown): string;
|
|
23
|
+
export declare function sortJson(value: unknown): unknown;
|
|
24
|
+
export declare function uncertainDirectMutation(cause: unknown): MdbaseConnectError;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { MdbaseConnectError } from "./errors.js";
|
|
2
|
+
import { bytesToBase64Url } from "./base64.js";
|
|
3
|
+
export function loopbackRequest(init) {
|
|
4
|
+
return { ...init, credentials: "omit", targetAddressSpace: "loopback" };
|
|
5
|
+
}
|
|
6
|
+
export async function localNetworkPermission() {
|
|
7
|
+
if (typeof navigator === "undefined" || !navigator.permissions?.query)
|
|
8
|
+
return null;
|
|
9
|
+
try {
|
|
10
|
+
const status = await navigator.permissions.query({
|
|
11
|
+
name: "local-network-access"
|
|
12
|
+
});
|
|
13
|
+
return status.state;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function directFallbackStatus(status) {
|
|
20
|
+
return status === 404 || status === 405 || status === 426 || status >= 500;
|
|
21
|
+
}
|
|
22
|
+
export function isMutation(operation, input) {
|
|
23
|
+
if (input && typeof input === "object" && !Array.isArray(input)
|
|
24
|
+
&& input.dry_run === true)
|
|
25
|
+
return false;
|
|
26
|
+
return (operation === "sync"
|
|
27
|
+
&& input !== null
|
|
28
|
+
&& typeof input === "object"
|
|
29
|
+
&& !Array.isArray(input)
|
|
30
|
+
&& input.action === "mutate")
|
|
31
|
+
|| operation === "create"
|
|
32
|
+
|| operation === "update"
|
|
33
|
+
|| operation === "delete"
|
|
34
|
+
|| operation === "rename"
|
|
35
|
+
|| operation === "create_type"
|
|
36
|
+
|| operation === "update_type"
|
|
37
|
+
|| operation === "install_type_pack"
|
|
38
|
+
|| operation === "put_timer"
|
|
39
|
+
|| operation === "cancel_timer"
|
|
40
|
+
|| operation === "reconcile_timers";
|
|
41
|
+
}
|
|
42
|
+
export function uniqueOperations(operations) {
|
|
43
|
+
return [...new Set(operations)];
|
|
44
|
+
}
|
|
45
|
+
export function sameAuthorization(left, right) {
|
|
46
|
+
if (left.grantId || right.grantId) {
|
|
47
|
+
return left.grantId === right.grantId
|
|
48
|
+
&& left.keyHandle === right.keyHandle
|
|
49
|
+
&& left.encryption?.key_id === right.encryption?.key_id;
|
|
50
|
+
}
|
|
51
|
+
return left.accessToken === right.accessToken;
|
|
52
|
+
}
|
|
53
|
+
export function throwIfCancelled(signal) {
|
|
54
|
+
if (!signal?.aborted)
|
|
55
|
+
return;
|
|
56
|
+
throw new MdbaseConnectError("operation_cancelled", "The operation was cancelled before it changed the collection.", { recovery: "none", cause: signal.reason });
|
|
57
|
+
}
|
|
58
|
+
export function operationTransportError(error, signal, outcomeUnknown) {
|
|
59
|
+
if (signal?.aborted) {
|
|
60
|
+
return new MdbaseConnectError("operation_cancelled", outcomeUnknown
|
|
61
|
+
? "Waiting was cancelled after the mutation was sent. Resume the pending mutation to recover its authoritative result."
|
|
62
|
+
: "The operation was cancelled before it changed the collection.", {
|
|
63
|
+
outcomeUnknown,
|
|
64
|
+
recovery: outcomeUnknown ? "resolve_outcome" : "none",
|
|
65
|
+
cause: error
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (outcomeUnknown) {
|
|
69
|
+
if (error instanceof MdbaseConnectError && error.outcomeUnknown)
|
|
70
|
+
return error;
|
|
71
|
+
return uncertainDirectMutation(error);
|
|
72
|
+
}
|
|
73
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
74
|
+
}
|
|
75
|
+
export function isCancellation(error, signal) {
|
|
76
|
+
return signal?.aborted === true
|
|
77
|
+
|| (error instanceof MdbaseConnectError && error.code === "operation_cancelled");
|
|
78
|
+
}
|
|
79
|
+
export function assertRenamePreview(input, preview) {
|
|
80
|
+
if (preview.dry_run !== true || preview.would_rename !== true
|
|
81
|
+
|| preview.from !== input.from || preview.to !== input.to) {
|
|
82
|
+
throw new MdbaseConnectError("invalid_preflight", "The rename preview does not match this mutation. Run the preview again.", { recovery: "fix_request" });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function assertDeletePreview(input, preview) {
|
|
86
|
+
if (preview.dry_run !== true || preview.would_delete !== true || preview.path !== input.path) {
|
|
87
|
+
throw new MdbaseConnectError("invalid_preflight", "The delete preview does not match this mutation. Run the preview again.", { recovery: "fix_request" });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function renameEstimate(input, preview) {
|
|
91
|
+
if (input.update_refs === false) {
|
|
92
|
+
return { affectedRecords: 0, totalUnits: 1, warnings: 0 };
|
|
93
|
+
}
|
|
94
|
+
const references = preview.references_affected ?? [];
|
|
95
|
+
return {
|
|
96
|
+
affectedRecords: new Set(references.map((reference) => reference.path)).size,
|
|
97
|
+
totalUnits: 1 + references.length,
|
|
98
|
+
warnings: preview.warnings?.length ?? 0
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export function deleteEstimate(preview) {
|
|
102
|
+
return {
|
|
103
|
+
affectedRecords: new Set((preview.broken_links ?? []).map((reference) => reference.path)).size,
|
|
104
|
+
totalUnits: 1,
|
|
105
|
+
warnings: 0
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export async function operationFingerprint(operation, input) {
|
|
109
|
+
const encoded = new TextEncoder().encode(`${operation}\0${canonicalJson(input ?? {})}`);
|
|
110
|
+
const digest = await crypto.subtle.digest("SHA-256", encoded);
|
|
111
|
+
return bytesToBase64Url(new Uint8Array(digest));
|
|
112
|
+
}
|
|
113
|
+
export function canonicalJson(value) {
|
|
114
|
+
return JSON.stringify(sortJson(value));
|
|
115
|
+
}
|
|
116
|
+
export function sortJson(value) {
|
|
117
|
+
if (Array.isArray(value))
|
|
118
|
+
return value.map((item) => sortJson(item));
|
|
119
|
+
if (value && typeof value === "object") {
|
|
120
|
+
return Object.fromEntries(Object.entries(value)
|
|
121
|
+
.filter(([, item]) => item !== undefined)
|
|
122
|
+
.sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
|
|
123
|
+
.map(([key, item]) => [key, sortJson(item)]));
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
export function uncertainDirectMutation(cause) {
|
|
128
|
+
return new MdbaseConnectError("direct_outcome_unknown", "The direct write may have completed, and mdbase could not recover its receipt through the relay. Retry the exact same write to recover safely.", { cause });
|
|
129
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import type { CollectionOperation, JsonObject, QueryRecord, RecordDocument } from "@mdbase-dev/connect-protocol";
|
|
2
|
+
import type { MdbaseConnectError } from "./errors.js";
|
|
3
|
+
export interface MdbaseDesiredTimer {
|
|
4
|
+
/** Stable within the timer namespace. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** RFC 3339 instant at which the authority should fire the timer. */
|
|
7
|
+
fire_at: string;
|
|
8
|
+
/** Private application data retained by the collection authority. */
|
|
9
|
+
data?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface MdbaseTimer extends MdbaseDesiredTimer {
|
|
12
|
+
criterion_id: string;
|
|
13
|
+
generation: number;
|
|
14
|
+
status: "scheduled" | "firing" | "fired" | "cancelled";
|
|
15
|
+
created_at: string;
|
|
16
|
+
updated_at: string;
|
|
17
|
+
fired_at: string | null;
|
|
18
|
+
}
|
|
19
|
+
export interface MdbaseTimerList {
|
|
20
|
+
namespace: string;
|
|
21
|
+
timers: MdbaseTimer[];
|
|
22
|
+
}
|
|
23
|
+
export interface MdbaseTimerReconciliation extends MdbaseTimerList {
|
|
24
|
+
cancelled_ids: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface ReadInput {
|
|
27
|
+
path: string;
|
|
28
|
+
/** Select an exact approved contract view when more than one is possible. */
|
|
29
|
+
contract?: DataContractSelector;
|
|
30
|
+
/** Include the exact UTF-8 Markdown source; requires full-collection access. */
|
|
31
|
+
include_document?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface DataContractSelector {
|
|
34
|
+
id: string;
|
|
35
|
+
version: string;
|
|
36
|
+
/** Required when several approved types implement the selected contract. */
|
|
37
|
+
type?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface QueryInput {
|
|
40
|
+
/**
|
|
41
|
+
* Contract-scoped queries accept only `types`, pagination,
|
|
42
|
+
* `frontmatter_mode`, and `contract`; filter normalized fields in the app.
|
|
43
|
+
*/
|
|
44
|
+
types?: string[];
|
|
45
|
+
where?: unknown;
|
|
46
|
+
order_by?: unknown;
|
|
47
|
+
limit?: number;
|
|
48
|
+
offset?: number;
|
|
49
|
+
/** Opaque token returned by the first metadata page for consistent, fast pagination. */
|
|
50
|
+
snapshot?: string;
|
|
51
|
+
include_body?: boolean;
|
|
52
|
+
frontmatter_mode?: "effective" | "persisted" | "both";
|
|
53
|
+
/** Narrow a contract-scoped query to one exact contract/provider view. */
|
|
54
|
+
contract?: DataContractSelector;
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface QueryResult<Record extends JsonObject = JsonObject> {
|
|
58
|
+
results: Array<QueryRecord<Record> & JsonObject>;
|
|
59
|
+
meta?: {
|
|
60
|
+
total_count: number;
|
|
61
|
+
has_more: boolean;
|
|
62
|
+
snapshot?: string;
|
|
63
|
+
[key: string]: unknown;
|
|
64
|
+
};
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
export interface QueryPagesOptions<Record extends JsonObject = JsonObject> {
|
|
68
|
+
firstPageSize?: number;
|
|
69
|
+
pageSize?: number;
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
onProgress?: (page: QueryPage<Record>) => void;
|
|
72
|
+
}
|
|
73
|
+
export interface QueryPage<Record extends JsonObject = JsonObject> {
|
|
74
|
+
results: QueryResult<Record>["results"];
|
|
75
|
+
meta?: QueryResult<Record>["meta"];
|
|
76
|
+
page: number;
|
|
77
|
+
offset: number;
|
|
78
|
+
loaded: number;
|
|
79
|
+
complete: boolean;
|
|
80
|
+
snapshot?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface OperationRequestOptions {
|
|
83
|
+
signal?: AbortSignal;
|
|
84
|
+
}
|
|
85
|
+
export interface MutationEstimate {
|
|
86
|
+
/** Records whose links may be affected, excluding the record being mutated. */
|
|
87
|
+
affectedRecords: number;
|
|
88
|
+
/** Estimated atomic changes: the mutation itself plus known reference updates. */
|
|
89
|
+
totalUnits: number;
|
|
90
|
+
warnings: number;
|
|
91
|
+
}
|
|
92
|
+
export type MutationProgressState = "preflighting" | "ready" | "applying" | "completed" | "cancelled";
|
|
93
|
+
export interface MutationProgress {
|
|
94
|
+
operation: "rename" | "delete";
|
|
95
|
+
state: MutationProgressState;
|
|
96
|
+
elapsedMs: number;
|
|
97
|
+
cancellable: boolean;
|
|
98
|
+
resumed: boolean;
|
|
99
|
+
completedUnits: number;
|
|
100
|
+
estimate?: MutationEstimate;
|
|
101
|
+
}
|
|
102
|
+
export interface MutationProgressOptions {
|
|
103
|
+
signal?: AbortSignal;
|
|
104
|
+
onProgress?: (progress: MutationProgress) => void;
|
|
105
|
+
}
|
|
106
|
+
export interface RenameProgressOptions extends MutationProgressOptions {
|
|
107
|
+
/** Reuse an authoritative preview already shown to the user. */
|
|
108
|
+
preflight?: RenamePreflightResult;
|
|
109
|
+
}
|
|
110
|
+
export interface DeleteProgressOptions extends MutationProgressOptions {
|
|
111
|
+
/** Reuse an authoritative preview already shown to the user. */
|
|
112
|
+
preflight?: DeletePreflightResult;
|
|
113
|
+
}
|
|
114
|
+
export interface PendingMutationSummary {
|
|
115
|
+
operation: CollectionOperation;
|
|
116
|
+
createdAt: number;
|
|
117
|
+
resumable: true;
|
|
118
|
+
}
|
|
119
|
+
export interface CreateInput<Frontmatter extends JsonObject = JsonObject> {
|
|
120
|
+
path?: string;
|
|
121
|
+
type?: string;
|
|
122
|
+
contract?: DataContractSelector;
|
|
123
|
+
frontmatter?: Partial<Frontmatter> & JsonObject;
|
|
124
|
+
/** Requires full-collection access; contract creates are frontmatter-only. */
|
|
125
|
+
body?: string;
|
|
126
|
+
if_revision?: string;
|
|
127
|
+
/** Include the resulting exact Markdown source in `result.document`. */
|
|
128
|
+
include_document?: boolean;
|
|
129
|
+
}
|
|
130
|
+
interface UpdateInputBase {
|
|
131
|
+
path: string;
|
|
132
|
+
contract?: DataContractSelector;
|
|
133
|
+
if_revision?: string;
|
|
134
|
+
/** Include the resulting exact Markdown source; requires full-collection access. */
|
|
135
|
+
include_document?: boolean;
|
|
136
|
+
}
|
|
137
|
+
export type UpdateInput<Frontmatter extends JsonObject = JsonObject> = UpdateInputBase & ({
|
|
138
|
+
patch: Partial<Frontmatter> & JsonObject;
|
|
139
|
+
body?: string;
|
|
140
|
+
document?: never;
|
|
141
|
+
} | {
|
|
142
|
+
/**
|
|
143
|
+
* Replace the complete Markdown source. This is mutually exclusive with
|
|
144
|
+
* `patch` and `body`, and implies `include_document`.
|
|
145
|
+
*/
|
|
146
|
+
document: string;
|
|
147
|
+
patch?: never;
|
|
148
|
+
body?: never;
|
|
149
|
+
});
|
|
150
|
+
export interface DeleteInput {
|
|
151
|
+
path: string;
|
|
152
|
+
contract?: DataContractSelector;
|
|
153
|
+
check_backlinks?: boolean;
|
|
154
|
+
if_revision?: string;
|
|
155
|
+
}
|
|
156
|
+
export interface DeleteResult {
|
|
157
|
+
path: string;
|
|
158
|
+
deleted: boolean;
|
|
159
|
+
broken_links?: Array<{
|
|
160
|
+
path: string;
|
|
161
|
+
}>;
|
|
162
|
+
}
|
|
163
|
+
export interface DeletePreflightResult {
|
|
164
|
+
path: string;
|
|
165
|
+
deleted: false;
|
|
166
|
+
dry_run: true;
|
|
167
|
+
would_delete: true;
|
|
168
|
+
broken_links?: Array<{
|
|
169
|
+
path: string;
|
|
170
|
+
}>;
|
|
171
|
+
}
|
|
172
|
+
export interface RenameInput {
|
|
173
|
+
from: string;
|
|
174
|
+
to: string;
|
|
175
|
+
contract?: DataContractSelector;
|
|
176
|
+
update_refs?: boolean;
|
|
177
|
+
if_revision?: string;
|
|
178
|
+
/** Include the resulting exact Markdown source in `result.document`. */
|
|
179
|
+
include_document?: boolean;
|
|
180
|
+
}
|
|
181
|
+
export interface RenameResult extends RecordDocument {
|
|
182
|
+
from: string;
|
|
183
|
+
to: string;
|
|
184
|
+
references_updated?: JsonObject[];
|
|
185
|
+
}
|
|
186
|
+
export interface RenamePreflightResult {
|
|
187
|
+
from: string;
|
|
188
|
+
to: string;
|
|
189
|
+
dry_run: true;
|
|
190
|
+
would_rename: true;
|
|
191
|
+
references_affected?: Array<{
|
|
192
|
+
path: string;
|
|
193
|
+
field?: string;
|
|
194
|
+
location?: string;
|
|
195
|
+
}>;
|
|
196
|
+
warnings?: Array<{
|
|
197
|
+
path: string;
|
|
198
|
+
message: string;
|
|
199
|
+
}>;
|
|
200
|
+
}
|
|
201
|
+
export interface ReadTypeInput {
|
|
202
|
+
name?: string;
|
|
203
|
+
path?: string;
|
|
204
|
+
}
|
|
205
|
+
export interface CreateTypeInput {
|
|
206
|
+
document: string;
|
|
207
|
+
path?: string;
|
|
208
|
+
}
|
|
209
|
+
export interface UpdateTypeInput extends ReadTypeInput {
|
|
210
|
+
document: string;
|
|
211
|
+
if_revision: string;
|
|
212
|
+
}
|
|
213
|
+
export interface ChangesInput {
|
|
214
|
+
after?: number;
|
|
215
|
+
limit?: number;
|
|
216
|
+
}
|
|
217
|
+
export interface WatchOptions {
|
|
218
|
+
cursor?: number;
|
|
219
|
+
pollIntervalMs?: number;
|
|
220
|
+
signal?: AbortSignal;
|
|
221
|
+
/** Set to false to surface transient transport failures immediately. */
|
|
222
|
+
retry?: false | WatchRetryOptions;
|
|
223
|
+
onStatus?: (status: WatchStatus) => void;
|
|
224
|
+
}
|
|
225
|
+
export interface WatchRetryOptions {
|
|
226
|
+
initialDelayMs?: number;
|
|
227
|
+
maxDelayMs?: number;
|
|
228
|
+
multiplier?: number;
|
|
229
|
+
/** Number of consecutive transient failures. Omit to keep reconnecting. */
|
|
230
|
+
maxAttempts?: number;
|
|
231
|
+
}
|
|
232
|
+
export type WatchStatus = {
|
|
233
|
+
state: "connecting";
|
|
234
|
+
cursor?: number;
|
|
235
|
+
} | {
|
|
236
|
+
state: "connected";
|
|
237
|
+
cursor: number;
|
|
238
|
+
recovered: boolean;
|
|
239
|
+
} | {
|
|
240
|
+
state: "reconnecting";
|
|
241
|
+
cursor?: number;
|
|
242
|
+
attempt: number;
|
|
243
|
+
retryInMs: number;
|
|
244
|
+
error: unknown;
|
|
245
|
+
} | {
|
|
246
|
+
state: "reset_required";
|
|
247
|
+
cursor: number;
|
|
248
|
+
error: MdbaseConnectError;
|
|
249
|
+
};
|
|
250
|
+
/** Provider-neutral operation transport used by the typed collection client. */
|
|
251
|
+
export interface MdbaseCollectionTransport {
|
|
252
|
+
operation<Result>(operation: CollectionOperation, input: unknown, options?: OperationRequestOptions): Promise<Result>;
|
|
253
|
+
}
|
|
254
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { GrantEncryption, GrantScope, MdbaseAppManifest } from "@mdbase-dev/connect-protocol";
|
|
2
|
+
import { MdbaseConnectError } from "./errors.js";
|
|
3
|
+
import type { StoredToken } from "./internal-types.js";
|
|
4
|
+
import type { MdbaseDeviceAuthorization } from "./authorization-types.js";
|
|
5
|
+
export declare function canonicalLoopbackUrl(value: string): string;
|
|
6
|
+
export declare function createPkce(): Promise<{
|
|
7
|
+
verifier: string;
|
|
8
|
+
challenge: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function apiError(body: any, fallbackCode: string, fallbackMessage: string, status?: number): MdbaseConnectError;
|
|
11
|
+
export declare function oauthErrorCode(body: any): string | undefined;
|
|
12
|
+
export declare function validAuthorityTokenResponse(value: unknown, collectionId: unknown): boolean;
|
|
13
|
+
export declare function validStoredAuthority(authority: StoredToken["authority"], collectionId: string): boolean;
|
|
14
|
+
export declare function validStoredEncryption(encryption: StoredToken["encryption"], collectionId: string): encryption is GrantEncryption;
|
|
15
|
+
export declare function parseDeviceAuthorization(body: any): MdbaseDeviceAuthorization;
|
|
16
|
+
export declare function parseStored<T>(value: string | null): T | null;
|
|
17
|
+
export declare function parseGrantScope(value: unknown): GrantScope | null;
|
|
18
|
+
export declare function stripTrailingSlash(value: string): string;
|
|
19
|
+
export declare function defaultManifestSource(): string;
|
|
20
|
+
export declare function defaultRedirectUri(): string;
|
|
21
|
+
export declare function defaultCallbackUrl(): string;
|
|
22
|
+
export declare function defaultStorage(memoryOnly: boolean): Storage;
|
|
23
|
+
export declare class MemoryStorage implements Storage {
|
|
24
|
+
private readonly values;
|
|
25
|
+
get length(): number;
|
|
26
|
+
clear(): void;
|
|
27
|
+
getItem(key: string): string | null;
|
|
28
|
+
key(index: number): string | null;
|
|
29
|
+
removeItem(key: string): void;
|
|
30
|
+
setItem(key: string, value: string): void;
|
|
31
|
+
}
|
|
32
|
+
export declare function isOpaquePortableManifest(manifest: MdbaseAppManifest | string): boolean;
|
|
33
|
+
export declare function manifestStorageFingerprint(manifest: MdbaseAppManifest): string;
|