@simpleplatform/sdk 2.4.2 → 3.0.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/README.md +459 -44
- package/dist/ai.d.ts +10 -0
- package/dist/ai.js +5 -1
- package/dist/space/actions.d.ts +59 -0
- package/dist/space/actions.js +69 -0
- package/dist/space/browser-transport.d.ts +18 -0
- package/dist/space/browser-transport.js +229 -0
- package/dist/space/core.d.ts +43 -201
- package/dist/space/core.js +70 -408
- package/dist/space/documents.d.ts +25 -0
- package/dist/space/documents.js +72 -0
- package/dist/space/index.d.ts +6 -31
- package/dist/space/index.js +61 -90
- package/dist/space/navigation.d.ts +25 -0
- package/dist/space/navigation.js +32 -0
- package/dist/space/protocol.d.ts +66 -0
- package/dist/space/protocol.js +77 -0
- package/dist/space/record-form.d.ts +94 -0
- package/dist/space/record-form.js +217 -0
- package/dist/space/record.d.ts +137 -0
- package/dist/space/record.js +231 -0
- package/dist/space/status.d.ts +2 -0
- package/dist/space/status.js +7 -0
- package/dist/space/tabs.d.ts +64 -0
- package/dist/space/tabs.js +236 -0
- package/dist/space/tasks.d.ts +84 -0
- package/dist/space/tasks.js +129 -0
- package/dist/space/ui.d.ts +67 -0
- package/dist/space/ui.js +123 -0
- package/dist/tasks.d.ts +18 -0
- package/dist/tasks.js +34 -0
- package/package.json +5 -1
package/dist/space/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { createMessagePortTransport } from './browser-transport.js';
|
|
2
|
+
import { createSimpleClient, HEADER_ACTIONS_PROTOCOL_VERSION, HEADER_STATUS_PROTOCOL_VERSION, isSpaceContext, MANAGED_RECORD_FORM_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION, } from './core.js';
|
|
3
|
+
import { isObjectRecord } from './protocol.js';
|
|
4
|
+
export { HEADER_ACTIONS_PROTOCOL_VERSION, HEADER_STATUS_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION };
|
|
5
|
+
/** Connects this Space to its host using the explicitly supplied host origin. */
|
|
6
|
+
export function connect({ targetOrigin }) {
|
|
7
|
+
if (!isOrigin(targetOrigin)) {
|
|
8
|
+
return Promise.reject(new SpaceProtocolError({
|
|
9
|
+
code: 'invalid_request',
|
|
10
|
+
message: 'connect() requires targetOrigin to be an HTTP or HTTPS origin.',
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
const window = globalThis.window;
|
|
10
14
|
if (!window) {
|
|
11
15
|
return Promise.reject(new SpaceProtocolError({
|
|
12
16
|
code: 'unavailable',
|
|
13
17
|
message: 'The Space SDK requires a browser window.',
|
|
14
18
|
}));
|
|
15
19
|
}
|
|
20
|
+
// The host cannot style a cross-origin frame's viewport, where edge bounce occurs.
|
|
21
|
+
window.document.documentElement.style.overscrollBehaviorY = 'none';
|
|
16
22
|
return new Promise((resolve, reject) => {
|
|
17
23
|
const onMessage = (event) => {
|
|
18
24
|
if (event.origin !== targetOrigin || !isInitializationMessage(event.data))
|
|
@@ -33,108 +39,73 @@ export function connectSpace({ targetOrigin, window = globalThis.window }) {
|
|
|
33
39
|
}));
|
|
34
40
|
return;
|
|
35
41
|
}
|
|
36
|
-
const transport = createMessagePortTransport(port);
|
|
42
|
+
const transport = createMessagePortTransport(port, targetOrigin);
|
|
37
43
|
const protocols = event.data.protocols;
|
|
44
|
+
const hasRecord = protocols?.record === PROTOCOL_VERSION;
|
|
45
|
+
const hasRecords = protocols?.records === RECORDS_PROTOCOL_VERSION;
|
|
38
46
|
resolve(createSimpleClient({
|
|
47
|
+
actionTransport: protocols?.action === PROTOCOL_VERSION ? transport : undefined,
|
|
48
|
+
capabilities: transport.capabilities,
|
|
39
49
|
context: event.data.context,
|
|
40
50
|
dataTransport: transport,
|
|
41
51
|
documentTransport: protocols?.document === PROTOCOL_VERSION ? transport : undefined,
|
|
52
|
+
formModelTransport: protocols?.form === MANAGED_RECORD_FORM_PROTOCOL_VERSION ? transport : undefined,
|
|
53
|
+
headerStatusTransport: hasRecord && protocols?.headerStatus === HEADER_STATUS_PROTOCOL_VERSION ? transport : undefined,
|
|
54
|
+
headerTransport: hasRecord && protocols?.header === HEADER_ACTIONS_PROTOCOL_VERSION ? transport : undefined,
|
|
55
|
+
hostOrigin: targetOrigin,
|
|
56
|
+
navigationTransport: transport,
|
|
57
|
+
recordsTransport: hasRecords ? transport : undefined,
|
|
58
|
+
runtime: event.data.runtime,
|
|
59
|
+
tabsTransport: hasRecord && protocols?.tabs === TABS_PROTOCOL_VERSION ? transport : undefined,
|
|
42
60
|
taskTransport: protocols?.task === PROTOCOL_VERSION ? transport : undefined,
|
|
43
|
-
|
|
61
|
+
toastTransport: protocols?.toast === TOAST_PROTOCOL_VERSION ? transport : undefined,
|
|
62
|
+
transport: hasRecord ? transport : undefined,
|
|
44
63
|
}));
|
|
45
64
|
};
|
|
46
65
|
window.addEventListener('message', onMessage);
|
|
47
66
|
window.parent.postMessage({
|
|
48
67
|
protocols: {
|
|
68
|
+
action: [PROTOCOL_VERSION],
|
|
49
69
|
document: [PROTOCOL_VERSION],
|
|
70
|
+
form: [MANAGED_RECORD_FORM_PROTOCOL_VERSION],
|
|
71
|
+
header: [HEADER_ACTIONS_PROTOCOL_VERSION],
|
|
72
|
+
headerStatus: [HEADER_STATUS_PROTOCOL_VERSION],
|
|
50
73
|
record: [PROTOCOL_VERSION],
|
|
74
|
+
records: [RECORDS_PROTOCOL_VERSION],
|
|
75
|
+
tabs: [TABS_PROTOCOL_VERSION],
|
|
51
76
|
task: [PROTOCOL_VERSION],
|
|
77
|
+
toast: [TOAST_PROTOCOL_VERSION],
|
|
52
78
|
},
|
|
53
79
|
type: 'SPACE_READY',
|
|
54
80
|
}, targetOrigin);
|
|
55
81
|
});
|
|
56
82
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (envelope.type === 'SPACE_PROTOCOL_RESPONSE' && envelope.response) {
|
|
66
|
-
const requestId = envelope.response.requestId;
|
|
67
|
-
const request = pending.get(requestId);
|
|
68
|
-
if (!request)
|
|
69
|
-
return;
|
|
70
|
-
pending.delete(requestId);
|
|
71
|
-
request.resolve(envelope.response);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (envelope.type !== 'GRAPHQL_RESPONSE' || typeof envelope.id !== 'string')
|
|
75
|
-
return;
|
|
76
|
-
const request = pendingData.get(envelope.id);
|
|
77
|
-
if (!request)
|
|
78
|
-
return;
|
|
79
|
-
pendingData.delete(envelope.id);
|
|
80
|
-
if (envelope.error || envelope.errors) {
|
|
81
|
-
request.reject(new SpaceDataError({
|
|
82
|
-
code: 'request_failed',
|
|
83
|
-
details: envelope.errors,
|
|
84
|
-
message: readGraphQLErrorMessage(envelope.error, envelope.errors),
|
|
85
|
-
}));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
request.resolve(envelope.data);
|
|
89
|
-
};
|
|
90
|
-
port.start?.();
|
|
91
|
-
return {
|
|
92
|
-
execute: (document, variables) => {
|
|
93
|
-
return new Promise((resolve, reject) => {
|
|
94
|
-
const id = createDataRequestId();
|
|
95
|
-
pendingData.set(id, { reject, resolve: result => resolve(result) });
|
|
96
|
-
port.postMessage({
|
|
97
|
-
payload: { id, query: document, variables },
|
|
98
|
-
type: 'GRAPHQL_REQUEST',
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
request: (request, transfer = []) => {
|
|
103
|
-
return new Promise((resolve) => {
|
|
104
|
-
pending.set(request.requestId, {
|
|
105
|
-
resolve: response => resolve(response),
|
|
106
|
-
});
|
|
107
|
-
port.postMessage({ request, type: 'SPACE_PROTOCOL_REQUEST' }, transfer);
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function createDataRequestId() {
|
|
113
|
-
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function')
|
|
114
|
-
return crypto.randomUUID();
|
|
115
|
-
return `space-data-${Math.random().toString(36).slice(2)}`;
|
|
116
|
-
}
|
|
117
|
-
function readGraphQLErrorMessage(error, errors) {
|
|
118
|
-
if (typeof error === 'string' && error)
|
|
119
|
-
return error;
|
|
120
|
-
if (Array.isArray(errors)) {
|
|
121
|
-
const firstError = errors[0];
|
|
122
|
-
if (firstError && typeof firstError === 'object') {
|
|
123
|
-
const details = firstError;
|
|
124
|
-
const issue = details.extensions?.issues?.[0]?.message;
|
|
125
|
-
if (typeof issue === 'string' && issue)
|
|
126
|
-
return issue;
|
|
127
|
-
const message = details.extensions?.details?.message;
|
|
128
|
-
if (typeof message === 'string' && message)
|
|
129
|
-
return message;
|
|
130
|
-
if (typeof details.message === 'string' && details.message)
|
|
131
|
-
return details.message;
|
|
132
|
-
}
|
|
83
|
+
function isOrigin(targetOrigin) {
|
|
84
|
+
try {
|
|
85
|
+
const url = new URL(targetOrigin);
|
|
86
|
+
return (url.protocol === 'http:' || url.protocol === 'https:')
|
|
87
|
+
&& url.origin === targetOrigin;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
133
91
|
}
|
|
134
|
-
return 'GraphQL request failed.';
|
|
135
92
|
}
|
|
136
93
|
function isInitializationMessage(value) {
|
|
137
|
-
if (!value ||
|
|
94
|
+
if (!isObjectRecord(value) || value.type !== 'INIT_RPC')
|
|
95
|
+
return false;
|
|
96
|
+
return value.runtime === undefined || isUiRuntimeDescriptor(value.runtime);
|
|
97
|
+
}
|
|
98
|
+
function isUiRuntimeDescriptor(value) {
|
|
99
|
+
if (!isObjectRecord(value))
|
|
100
|
+
return false;
|
|
101
|
+
const { url, version } = value;
|
|
102
|
+
if (typeof url !== 'string' || !url || typeof version !== 'string' || !version)
|
|
138
103
|
return false;
|
|
139
|
-
|
|
104
|
+
try {
|
|
105
|
+
const protocol = new URL(url).protocol;
|
|
106
|
+
return protocol === 'http:' || protocol === 'https:';
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
140
111
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the platform opens the path. `same-tab` opens it in the platform tab
|
|
3
|
+
* the Space is shown in (a Space cannot navigate its own frame); `new-tab`
|
|
4
|
+
* opens it in a new browser tab.
|
|
5
|
+
*
|
|
6
|
+
* These are the platform's own names, not the browser's `_self` and `_blank`.
|
|
7
|
+
* The platform's navigation message has carried `same-tab` and `new-tab`
|
|
8
|
+
* since before this call existed, so keeping them leaves that contract
|
|
9
|
+
* untouched and gives one set of names from a Space to the platform page,
|
|
10
|
+
* with no mapping in between. They also say where a platform page opens
|
|
11
|
+
* rather than which browsing context a link uses, which leaves room for
|
|
12
|
+
* targets a browser has no name for, such as a popup or the developer studio.
|
|
13
|
+
*/
|
|
14
|
+
export type NavigationTarget = 'same-tab' | 'new-tab';
|
|
15
|
+
export interface NavigationOpenOptions {
|
|
16
|
+
path: string;
|
|
17
|
+
target?: NavigationTarget;
|
|
18
|
+
}
|
|
19
|
+
export interface SimpleNavigationClient {
|
|
20
|
+
open: (options: NavigationOpenOptions) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface SpaceNavigationTransport {
|
|
23
|
+
navigate: (url: string, target: NavigationTarget) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function createNavigationClient(hostOrigin: string | undefined, transport: SpaceNavigationTransport | undefined): SimpleNavigationClient;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { invalidRequest, isObjectRecord, SpaceProtocolError } from './protocol.js';
|
|
2
|
+
export function createNavigationClient(hostOrigin, transport) {
|
|
3
|
+
return {
|
|
4
|
+
open(options) {
|
|
5
|
+
if (!isObjectRecord(options))
|
|
6
|
+
throw invalidRequest('Navigation options must be an object.');
|
|
7
|
+
const { path, target } = options;
|
|
8
|
+
if (typeof path !== 'string' || path.length === 0 || !path.startsWith('/') || path.startsWith('//') || path.includes('\\'))
|
|
9
|
+
throw invalidRequest('Navigation path must be a host-relative path starting with one slash, with no backslash.');
|
|
10
|
+
const resolvedTarget = target === undefined ? 'same-tab' : target;
|
|
11
|
+
if (resolvedTarget !== 'same-tab' && resolvedTarget !== 'new-tab')
|
|
12
|
+
throw invalidRequest('Navigation target must be "same-tab" or "new-tab".');
|
|
13
|
+
if (!hostOrigin || new URL(hostOrigin).protocol !== 'https:') {
|
|
14
|
+
throw new SpaceProtocolError({
|
|
15
|
+
code: 'unavailable',
|
|
16
|
+
message: 'Platform navigation is available only when connected to an HTTPS host.',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (!transport) {
|
|
20
|
+
throw new SpaceProtocolError({
|
|
21
|
+
code: 'unavailable',
|
|
22
|
+
message: 'The platform-navigation bridge is unavailable for this Space.',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
// URL parsing drops a tab or a newline, which can turn a path into another host's address.
|
|
26
|
+
const url = new URL(path, hostOrigin);
|
|
27
|
+
if (url.origin !== new URL(hostOrigin).origin)
|
|
28
|
+
throw invalidRequest('Navigation path must stay on the host this Space is connected to.');
|
|
29
|
+
transport.navigate(url.href, resolvedTarget);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export declare const PROTOCOL_VERSION: 1;
|
|
2
|
+
export interface SpaceProtocolErrorPayload {
|
|
3
|
+
code: string;
|
|
4
|
+
details?: unknown;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class SpaceProtocolError extends Error {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly details?: unknown;
|
|
10
|
+
constructor({ code, details, message }: SpaceProtocolErrorPayload);
|
|
11
|
+
}
|
|
12
|
+
export interface SpaceDataErrorPayload {
|
|
13
|
+
code: string;
|
|
14
|
+
details?: unknown;
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class SpaceDataError extends Error {
|
|
18
|
+
readonly code: string;
|
|
19
|
+
readonly details?: unknown;
|
|
20
|
+
constructor({ code, details, message }: SpaceDataErrorPayload);
|
|
21
|
+
}
|
|
22
|
+
export interface ProtocolRequest<TPayload = unknown> {
|
|
23
|
+
operation: string;
|
|
24
|
+
payload: TPayload;
|
|
25
|
+
protocol: typeof PROTOCOL_VERSION;
|
|
26
|
+
requestId: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ProtocolSuccessResponse<TResult> {
|
|
29
|
+
ok: true;
|
|
30
|
+
protocol: typeof PROTOCOL_VERSION;
|
|
31
|
+
requestId: string;
|
|
32
|
+
result: TResult;
|
|
33
|
+
}
|
|
34
|
+
export interface ProtocolErrorResponse {
|
|
35
|
+
error: SpaceProtocolErrorPayload;
|
|
36
|
+
ok: false;
|
|
37
|
+
protocol: typeof PROTOCOL_VERSION;
|
|
38
|
+
requestId: string;
|
|
39
|
+
}
|
|
40
|
+
export type ProtocolResponse<TResult> = ProtocolErrorResponse | ProtocolSuccessResponse<TResult>;
|
|
41
|
+
export interface SpaceTransport {
|
|
42
|
+
/**
|
|
43
|
+
* `transfer` names buffers inside the request whose ownership moves to the
|
|
44
|
+
* host with it instead of being copied. A transport that cannot transfer
|
|
45
|
+
* sends them by value. When `signal` aborts, the transport forgets the
|
|
46
|
+
* request, so a late answer is dropped, and rejects with the signal's reason.
|
|
47
|
+
*/
|
|
48
|
+
request: <TResult>(request: ProtocolRequest, transfer?: ArrayBuffer[], signal?: AbortSignal) => Promise<ProtocolResponse<TResult>>;
|
|
49
|
+
}
|
|
50
|
+
export declare function createRequestId(): string;
|
|
51
|
+
export declare function readResponse<TResult>(response: ProtocolResponse<TResult>, request: {
|
|
52
|
+
protocol: typeof PROTOCOL_VERSION;
|
|
53
|
+
requestId: string;
|
|
54
|
+
}): TResult;
|
|
55
|
+
/**
|
|
56
|
+
* Sends a request and waits at most `waitMs` for its answer. After that it
|
|
57
|
+
* rejects with `timeout` and aborts the transport's wait, so the request is
|
|
58
|
+
* not kept pending on a port the host may no longer read.
|
|
59
|
+
*/
|
|
60
|
+
export declare function requestWithin<TResult>(transport: SpaceTransport, request: ProtocolRequest, waitMs: number): Promise<ProtocolResponse<TResult>>;
|
|
61
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
62
|
+
export declare function invalidResponse(message: string): SpaceProtocolError;
|
|
63
|
+
export declare function invalidRequest(message: string): SpaceProtocolError;
|
|
64
|
+
export declare function isObjectRecord(value: unknown): value is Record<string, unknown>;
|
|
65
|
+
export declare function isNonBlankString(value: unknown): value is string;
|
|
66
|
+
export declare function isNonNegativeInteger(value: unknown): value is number;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export const PROTOCOL_VERSION = 1;
|
|
2
|
+
export class SpaceProtocolError extends Error {
|
|
3
|
+
constructor({ code, details, message }) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'SpaceProtocolError';
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.details = details;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class SpaceDataError extends Error {
|
|
11
|
+
constructor({ code, details, message }) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'SpaceDataError';
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.details = details;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function createRequestId() {
|
|
19
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function')
|
|
20
|
+
return crypto.randomUUID();
|
|
21
|
+
return `space-request-${Math.random().toString(36).slice(2)}`;
|
|
22
|
+
}
|
|
23
|
+
export function readResponse(response, request) {
|
|
24
|
+
if (response.protocol !== PROTOCOL_VERSION || response.requestId !== request.requestId) {
|
|
25
|
+
throw invalidResponse('The response does not match the request envelope.');
|
|
26
|
+
}
|
|
27
|
+
if (!response.ok)
|
|
28
|
+
throw new SpaceProtocolError(response.error);
|
|
29
|
+
return response.result;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sends a request and waits at most `waitMs` for its answer. After that it
|
|
33
|
+
* rejects with `timeout` and aborts the transport's wait, so the request is
|
|
34
|
+
* not kept pending on a port the host may no longer read.
|
|
35
|
+
*/
|
|
36
|
+
export async function requestWithin(transport, request, waitMs) {
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
let timer;
|
|
39
|
+
const expired = new Promise((_resolve, reject) => {
|
|
40
|
+
timer = setTimeout(() => {
|
|
41
|
+
const error = new SpaceProtocolError({
|
|
42
|
+
code: 'timeout',
|
|
43
|
+
message: `The Space host did not answer ${request.operation} within ${waitMs} milliseconds, so its outcome is unknown.`,
|
|
44
|
+
});
|
|
45
|
+
controller.abort(error);
|
|
46
|
+
reject(error);
|
|
47
|
+
}, waitMs);
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
return await Promise.race([transport.request(request, undefined, controller.signal), expired]);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function deepFreeze(value) {
|
|
57
|
+
if (!value || typeof value !== 'object' || Object.isFrozen(value))
|
|
58
|
+
return value;
|
|
59
|
+
for (const child of Object.values(value))
|
|
60
|
+
deepFreeze(child);
|
|
61
|
+
return Object.freeze(value);
|
|
62
|
+
}
|
|
63
|
+
export function invalidResponse(message) {
|
|
64
|
+
return new SpaceProtocolError({ code: 'invalid_response', message });
|
|
65
|
+
}
|
|
66
|
+
export function invalidRequest(message) {
|
|
67
|
+
return new SpaceProtocolError({ code: 'invalid_request', message });
|
|
68
|
+
}
|
|
69
|
+
export function isObjectRecord(value) {
|
|
70
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
71
|
+
}
|
|
72
|
+
export function isNonBlankString(value) {
|
|
73
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
74
|
+
}
|
|
75
|
+
export function isNonNegativeInteger(value) {
|
|
76
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
77
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { RecordHandle, RecordSnapshot, RecordUiBridge } from './record.js';
|
|
2
|
+
import type { SpaceToastOptions } from './ui.js';
|
|
3
|
+
export declare const MANAGED_RECORD_FORM_PROTOCOL_VERSION: 2;
|
|
4
|
+
export interface UiRuntimeDescriptor {
|
|
5
|
+
readonly url: string;
|
|
6
|
+
readonly version: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ManagedRecordFormField {
|
|
9
|
+
constraints?: unknown;
|
|
10
|
+
description?: string;
|
|
11
|
+
displayName?: string;
|
|
12
|
+
id: string;
|
|
13
|
+
isRequired: boolean;
|
|
14
|
+
name: string;
|
|
15
|
+
position?: number;
|
|
16
|
+
readOnly: boolean;
|
|
17
|
+
relationship?: unknown;
|
|
18
|
+
tableId?: string;
|
|
19
|
+
type: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ManagedRecordFormModel {
|
|
22
|
+
fields: readonly ManagedRecordFormField[];
|
|
23
|
+
recordId?: string;
|
|
24
|
+
tableId?: string;
|
|
25
|
+
tableName?: string;
|
|
26
|
+
}
|
|
27
|
+
export type ManagedRecordFormSnapshotListener = (snapshot: RecordSnapshot) => void;
|
|
28
|
+
export type RecordFormSubmitPreparation = () => Promise<Readonly<Record<string, unknown>> | undefined>;
|
|
29
|
+
export interface RecordFormCapabilities {
|
|
30
|
+
createDocumentHandle: (request: {
|
|
31
|
+
bytes: ArrayBuffer;
|
|
32
|
+
lifecycle?: 'pending' | 'record' | 'staged';
|
|
33
|
+
mime: string;
|
|
34
|
+
name: string;
|
|
35
|
+
target?: Record<string, unknown>;
|
|
36
|
+
}) => Promise<unknown>;
|
|
37
|
+
decrypt: (request: {
|
|
38
|
+
appId: string;
|
|
39
|
+
fieldName: string;
|
|
40
|
+
recordId: string;
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
tableName: string;
|
|
43
|
+
}) => Promise<string>;
|
|
44
|
+
deleteFile: (request: {
|
|
45
|
+
context: Record<string, string>;
|
|
46
|
+
fileHash: string;
|
|
47
|
+
}) => Promise<void>;
|
|
48
|
+
getDocumentPreview: (request: {
|
|
49
|
+
fieldName: string;
|
|
50
|
+
fileHash: string;
|
|
51
|
+
sessionId?: string;
|
|
52
|
+
}) => Promise<{
|
|
53
|
+
bytes: ArrayBuffer;
|
|
54
|
+
mimeType: string;
|
|
55
|
+
} | {
|
|
56
|
+
url: string;
|
|
57
|
+
}>;
|
|
58
|
+
navigate: (path: string) => Promise<void>;
|
|
59
|
+
showToast?: (options: SpaceToastOptions) => void;
|
|
60
|
+
}
|
|
61
|
+
export interface RecordFormBridge extends RecordUiBridge {
|
|
62
|
+
blurField: (fieldName: string) => Promise<void>;
|
|
63
|
+
focusField: (fieldName: string) => Promise<void>;
|
|
64
|
+
form: unknown;
|
|
65
|
+
registerSubmitPreparation: (preparation: RecordFormSubmitPreparation) => () => void;
|
|
66
|
+
subscribeFormModel: (listener: (form: unknown) => void) => () => void;
|
|
67
|
+
subscribe: (listener: ManagedRecordFormSnapshotListener) => () => void;
|
|
68
|
+
}
|
|
69
|
+
export interface RecordFormModelTransport {
|
|
70
|
+
subscribeFormModel: (listener: (form: unknown) => void) => () => void;
|
|
71
|
+
}
|
|
72
|
+
export interface RecordFormLifecycle {
|
|
73
|
+
notifySnapshot: (snapshot: RecordSnapshot) => void;
|
|
74
|
+
prepareSubmit: () => Promise<Record<string, unknown>>;
|
|
75
|
+
}
|
|
76
|
+
export interface RecordFormLifecycleOptions {
|
|
77
|
+
applicationId?: string;
|
|
78
|
+
capabilities?: RecordFormCapabilities;
|
|
79
|
+
form?: ManagedRecordFormModel;
|
|
80
|
+
formModelTransport?: RecordFormModelTransport;
|
|
81
|
+
graphql: (document: string, variables?: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
82
|
+
runtime?: UiRuntimeDescriptor;
|
|
83
|
+
setActiveField: (operation: 'record.blur' | 'record.focus', fieldName: string) => Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
export declare function isManagedRecordFormModel(value: unknown): value is ManagedRecordFormModel;
|
|
86
|
+
export declare function immutableManagedRecordForm(form: ManagedRecordFormModel): ManagedRecordFormModel;
|
|
87
|
+
export declare function immutableRuntimeDescriptor(runtime: UiRuntimeDescriptor): UiRuntimeDescriptor;
|
|
88
|
+
export declare function initRecordFormLifecycle(record: RecordHandle, options: RecordFormLifecycleOptions): RecordFormLifecycle | undefined;
|
|
89
|
+
export interface FormModelSubscriptionManager {
|
|
90
|
+
handleUpdate: (form: unknown) => void;
|
|
91
|
+
subscribeFormModel: (listener: (form: unknown) => void) => () => void;
|
|
92
|
+
}
|
|
93
|
+
export declare function createFormModelSubscriptionManager(): FormModelSubscriptionManager;
|
|
94
|
+
export declare function createRecordFormCapabilities(requestCapability: <TResult>(type: string, payload: unknown, responseType: string) => Promise<TResult>, postMessage: (message: unknown) => void, targetOrigin: string): RecordFormCapabilities;
|