@atlaskit/editor-synced-block-provider 3.30.6 → 3.31.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/CHANGELOG.md +21 -0
- package/dist/cjs/clients/block-service/blockService.js +98 -1
- package/dist/cjs/clients/block-service/blockSubscription.js +48 -3
- package/dist/cjs/index.js +12 -33
- package/dist/cjs/providers/block-service/blockServiceAPI.js +509 -185
- package/dist/cjs/providers/syncBlockProvider.js +36 -4
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +117 -9
- package/dist/cjs/store-manager/syncBlockBatchFetcher.js +76 -0
- package/dist/cjs/store-manager/syncBlockInMemorySessionCache.js +26 -0
- package/dist/cjs/store-manager/syncBlockProviderFactoryManager.js +175 -0
- package/dist/cjs/store-manager/syncBlockSubscriptionManager.js +198 -0
- package/dist/es2019/clients/block-service/blockService.js +88 -0
- package/dist/es2019/clients/block-service/blockSubscription.js +62 -2
- package/dist/es2019/index.js +2 -6
- package/dist/es2019/providers/block-service/blockServiceAPI.js +172 -23
- package/dist/es2019/providers/syncBlockProvider.js +26 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +93 -9
- package/dist/es2019/store-manager/syncBlockBatchFetcher.js +56 -0
- package/dist/es2019/store-manager/syncBlockInMemorySessionCache.js +24 -0
- package/dist/es2019/store-manager/syncBlockProviderFactoryManager.js +158 -0
- package/dist/es2019/store-manager/syncBlockSubscriptionManager.js +136 -0
- package/dist/esm/clients/block-service/blockService.js +97 -0
- package/dist/esm/clients/block-service/blockSubscription.js +47 -2
- package/dist/esm/index.js +2 -6
- package/dist/esm/providers/block-service/blockServiceAPI.js +513 -189
- package/dist/esm/providers/syncBlockProvider.js +36 -4
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +117 -9
- package/dist/esm/store-manager/syncBlockBatchFetcher.js +69 -0
- package/dist/esm/store-manager/syncBlockInMemorySessionCache.js +26 -0
- package/dist/esm/store-manager/syncBlockProviderFactoryManager.js +168 -0
- package/dist/esm/store-manager/syncBlockSubscriptionManager.js +191 -0
- package/dist/types/clients/block-service/blockService.d.ts +36 -0
- package/dist/types/clients/block-service/blockSubscription.d.ts +26 -1
- package/dist/types/index.d.ts +2 -6
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +15 -7
- package/dist/types/providers/types.d.ts +6 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
- package/dist/types/store-manager/syncBlockBatchFetcher.d.ts +25 -0
- package/dist/types/store-manager/syncBlockInMemorySessionCache.d.ts +18 -0
- package/dist/types/store-manager/syncBlockProviderFactoryManager.d.ts +25 -0
- package/dist/types/store-manager/syncBlockSubscriptionManager.d.ts +38 -0
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +36 -0
- package/dist/types-ts4.5/clients/block-service/blockSubscription.d.ts +26 -1
- package/dist/types-ts4.5/index.d.ts +2 -6
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +15 -7
- package/dist/types-ts4.5/providers/types.d.ts +6 -0
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +3 -0
- package/dist/types-ts4.5/store-manager/syncBlockBatchFetcher.d.ts +25 -0
- package/dist/types-ts4.5/store-manager/syncBlockInMemorySessionCache.d.ts +18 -0
- package/dist/types-ts4.5/store-manager/syncBlockProviderFactoryManager.d.ts +25 -0
- package/dist/types-ts4.5/store-manager/syncBlockSubscriptionManager.d.ts +38 -0
- package/package.json +5 -3
- package/dist/cjs/clients/block-service/sharedSubscriptionUtils.js +0 -82
- package/dist/cjs/utils/__generated__/relaySubscriptionUtilsSubscription.graphql.js +0 -94
- package/dist/cjs/utils/relayResponseConverter.js +0 -76
- package/dist/cjs/utils/relaySubscriptionUtils.js +0 -130
- package/dist/es2019/clients/block-service/sharedSubscriptionUtils.js +0 -91
- package/dist/es2019/utils/__generated__/relaySubscriptionUtilsSubscription.graphql.js +0 -88
- package/dist/es2019/utils/relayResponseConverter.js +0 -69
- package/dist/es2019/utils/relaySubscriptionUtils.js +0 -125
- package/dist/esm/clients/block-service/sharedSubscriptionUtils.js +0 -76
- package/dist/esm/utils/__generated__/relaySubscriptionUtilsSubscription.graphql.js +0 -88
- package/dist/esm/utils/relayResponseConverter.js +0 -69
- package/dist/esm/utils/relaySubscriptionUtils.js +0 -123
- package/dist/types/clients/block-service/sharedSubscriptionUtils.d.ts +0 -61
- package/dist/types/utils/__generated__/relaySubscriptionUtilsSubscription.graphql.d.ts +0 -31
- package/dist/types/utils/relayResponseConverter.d.ts +0 -47
- package/dist/types/utils/relaySubscriptionUtils.d.ts +0 -61
- package/dist/types-ts4.5/clients/block-service/sharedSubscriptionUtils.d.ts +0 -61
- package/dist/types-ts4.5/utils/__generated__/relaySubscriptionUtilsSubscription.graphql.d.ts +0 -31
- package/dist/types-ts4.5/utils/relayResponseConverter.d.ts +0 -47
- package/dist/types-ts4.5/utils/relaySubscriptionUtils.d.ts +0 -61
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { convertContentUpdatedAt } from '../../utils/utils';
|
|
2
|
-
/**
|
|
3
|
-
* Shared GraphQL subscription query for block updates.
|
|
4
|
-
* This is the canonical subscription query used across all implementations.
|
|
5
|
-
*/
|
|
6
|
-
export const BLOCK_SERVICE_SUBSCRIPTION_QUERY = `
|
|
7
|
-
subscription EDITOR_SYNCED_BLOCK_ON_BLOCK_UPDATED($resourceId: ID!) {
|
|
8
|
-
blockService_onBlockUpdated(resourceId: $resourceId) {
|
|
9
|
-
blockAri
|
|
10
|
-
blockInstanceId
|
|
11
|
-
content
|
|
12
|
-
contentUpdatedAt
|
|
13
|
-
createdAt
|
|
14
|
-
createdBy
|
|
15
|
-
deletionReason
|
|
16
|
-
product
|
|
17
|
-
sourceAri
|
|
18
|
-
status
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Raw subscription payload from the GraphQL subscription.
|
|
25
|
-
* This represents the exact shape returned by the blockService_onBlockUpdated subscription.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Parsed and normalized block subscription data.
|
|
30
|
-
* This is the standardized format used across different subscription implementations.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Extracts the resourceId from a block ARI.
|
|
35
|
-
* Block ARI format: ari:cloud:blocks:<cloudId>:synced-block/<resourceId>
|
|
36
|
-
* @param blockAri - The block ARI string
|
|
37
|
-
* @returns The resourceId portion of the ARI
|
|
38
|
-
*/
|
|
39
|
-
export const extractResourceIdFromBlockAri = blockAri => {
|
|
40
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
41
|
-
const match = blockAri.match(/ari:cloud:blocks:[^:]+:synced-block\/(.+)$/);
|
|
42
|
-
return (match === null || match === void 0 ? void 0 : match[1]) || null;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Converts a timestamp to ISO string.
|
|
47
|
-
* @param timestamp - Timestamp in milliseconds
|
|
48
|
-
* @returns ISO string or undefined if conversion fails
|
|
49
|
-
*/
|
|
50
|
-
export const convertTimestampToISOString = timestamp => {
|
|
51
|
-
if (timestamp === undefined || timestamp === null) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
return new Date(timestamp).toISOString();
|
|
56
|
-
} catch {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Parses the raw subscription payload into a standardized format.
|
|
63
|
-
* This function handles all the data transformation and error handling consistently
|
|
64
|
-
* across different subscription implementations.
|
|
65
|
-
*
|
|
66
|
-
* @param payload - The raw subscription payload
|
|
67
|
-
* @returns Parsed block data or null if parsing fails
|
|
68
|
-
*/
|
|
69
|
-
export const parseSubscriptionPayload = payload => {
|
|
70
|
-
try {
|
|
71
|
-
const resourceId = extractResourceIdFromBlockAri(payload.blockAri);
|
|
72
|
-
if (!resourceId) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
const createdAt = convertTimestampToISOString(payload.createdAt);
|
|
76
|
-
return {
|
|
77
|
-
blockAri: payload.blockAri,
|
|
78
|
-
blockInstanceId: payload.blockInstanceId,
|
|
79
|
-
content: JSON.parse(payload.content),
|
|
80
|
-
contentUpdatedAt: convertContentUpdatedAt(payload.contentUpdatedAt),
|
|
81
|
-
createdAt,
|
|
82
|
-
createdBy: payload.createdBy,
|
|
83
|
-
product: payload.product,
|
|
84
|
-
resourceId,
|
|
85
|
-
sourceAri: payload.sourceAri,
|
|
86
|
-
status: payload.status
|
|
87
|
-
};
|
|
88
|
-
} catch {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @generated SignedSource<<559b4fb25d0e5bc72be383427a939e2d>>
|
|
3
|
-
* @relayHash 38684212c43376e58fea2d6095011652
|
|
4
|
-
* @lightSyntaxTransform
|
|
5
|
-
* @nogrep
|
|
6
|
-
* @codegen-command: yarn relay
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/* tslint:disable */
|
|
10
|
-
/* eslint-disable */
|
|
11
|
-
// @ts-nocheck
|
|
12
|
-
|
|
13
|
-
// @relayRequestID c84045a1f05bd1e73ade0a9d8b18462cc3dad5dcae1ebabab76b13135411c530
|
|
14
|
-
|
|
15
|
-
const node = function () {
|
|
16
|
-
var v0 = [{
|
|
17
|
-
"defaultValue": null,
|
|
18
|
-
"kind": "LocalArgument",
|
|
19
|
-
"name": "resourceId"
|
|
20
|
-
}],
|
|
21
|
-
v1 = [{
|
|
22
|
-
"args": [{
|
|
23
|
-
"kind": "Variable",
|
|
24
|
-
"name": "resourceId",
|
|
25
|
-
"variableName": "resourceId"
|
|
26
|
-
}],
|
|
27
|
-
"concreteType": "BlockServiceBlockPayload",
|
|
28
|
-
"kind": "LinkedField",
|
|
29
|
-
"name": "blockService_onBlockUpdated",
|
|
30
|
-
"plural": false,
|
|
31
|
-
"selections": [{
|
|
32
|
-
"kind": "ScalarField",
|
|
33
|
-
"name": "blockAri"
|
|
34
|
-
}, {
|
|
35
|
-
"kind": "ScalarField",
|
|
36
|
-
"name": "blockInstanceId"
|
|
37
|
-
}, {
|
|
38
|
-
"kind": "ScalarField",
|
|
39
|
-
"name": "content"
|
|
40
|
-
}, {
|
|
41
|
-
"kind": "ScalarField",
|
|
42
|
-
"name": "contentUpdatedAt"
|
|
43
|
-
}, {
|
|
44
|
-
"kind": "ScalarField",
|
|
45
|
-
"name": "createdAt"
|
|
46
|
-
}, {
|
|
47
|
-
"kind": "ScalarField",
|
|
48
|
-
"name": "createdBy"
|
|
49
|
-
}, {
|
|
50
|
-
"kind": "ScalarField",
|
|
51
|
-
"name": "deletionReason"
|
|
52
|
-
}, {
|
|
53
|
-
"kind": "ScalarField",
|
|
54
|
-
"name": "product"
|
|
55
|
-
}, {
|
|
56
|
-
"kind": "ScalarField",
|
|
57
|
-
"name": "sourceAri"
|
|
58
|
-
}, {
|
|
59
|
-
"kind": "ScalarField",
|
|
60
|
-
"name": "status"
|
|
61
|
-
}]
|
|
62
|
-
}];
|
|
63
|
-
return {
|
|
64
|
-
"fragment": {
|
|
65
|
-
"argumentDefinitions": v0 /*: any*/,
|
|
66
|
-
"kind": "Fragment",
|
|
67
|
-
"name": "relaySubscriptionUtilsSubscription",
|
|
68
|
-
"selections": v1 /*: any*/,
|
|
69
|
-
"type": "Subscription"
|
|
70
|
-
},
|
|
71
|
-
"kind": "Request",
|
|
72
|
-
"operation": {
|
|
73
|
-
"argumentDefinitions": v0 /*: any*/,
|
|
74
|
-
"kind": "Operation",
|
|
75
|
-
"name": "relaySubscriptionUtilsSubscription",
|
|
76
|
-
"selections": v1 /*: any*/
|
|
77
|
-
},
|
|
78
|
-
"params": {
|
|
79
|
-
"id": "c84045a1f05bd1e73ade0a9d8b18462cc3dad5dcae1ebabab76b13135411c530",
|
|
80
|
-
"metadata": {},
|
|
81
|
-
"name": "relaySubscriptionUtilsSubscription",
|
|
82
|
-
"operationKind": "subscription",
|
|
83
|
-
"text": null
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}();
|
|
87
|
-
node.hash = "6f3ebc87921555436cad753ec1aead2e";
|
|
88
|
-
export default node;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { parseSubscriptionPayload } from '../clients/block-service/sharedSubscriptionUtils';
|
|
2
|
-
import { normaliseSyncBlockStatus } from './validValue';
|
|
3
|
-
/**
|
|
4
|
-
* Converts parsed subscription data to SyncBlockInstance format.
|
|
5
|
-
*
|
|
6
|
-
* @param parsed - The parsed subscription data
|
|
7
|
-
* @param resourceId - The resource ID for the block
|
|
8
|
-
* @returns A SyncBlockInstance
|
|
9
|
-
*/
|
|
10
|
-
export function convertParsedDataToSyncBlockInstance(parsed, resourceId) {
|
|
11
|
-
return {
|
|
12
|
-
data: {
|
|
13
|
-
content: parsed.content,
|
|
14
|
-
contentUpdatedAt: parsed.contentUpdatedAt,
|
|
15
|
-
resourceId: parsed.blockAri,
|
|
16
|
-
blockInstanceId: parsed.blockInstanceId,
|
|
17
|
-
sourceAri: parsed.sourceAri,
|
|
18
|
-
product: parsed.product,
|
|
19
|
-
createdAt: parsed.createdAt,
|
|
20
|
-
createdBy: parsed.createdBy,
|
|
21
|
-
status: normaliseSyncBlockStatus(parsed.status)
|
|
22
|
-
},
|
|
23
|
-
resourceId
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Converts a Relay subscription response to SyncBlockInstance format using shared parsing logic.
|
|
29
|
-
|
|
30
|
-
* @param response - The Relay subscription response containing block update data
|
|
31
|
-
* @param resourceId - The resource ID for the block
|
|
32
|
-
* @returns A SyncBlockInstance or null if parsing fails
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* // In a Relay subscription handler
|
|
37
|
-
* onNext: (response) => {
|
|
38
|
-
* if (response?.blockService_onBlockUpdated) {
|
|
39
|
-
* const syncBlockInstance = convertRelayResponseToSyncBlockInstance(
|
|
40
|
-
* response.blockService_onBlockUpdated,
|
|
41
|
-
* resourceId,
|
|
42
|
-
* );
|
|
43
|
-
* if (syncBlockInstance) {
|
|
44
|
-
* onUpdate(syncBlockInstance);
|
|
45
|
-
* }
|
|
46
|
-
* }
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export function convertRelayResponseToSyncBlockInstance(response, resourceId) {
|
|
51
|
-
var _response$contentUpda, _response$deletionRea;
|
|
52
|
-
const payload = {
|
|
53
|
-
blockAri: response.blockAri,
|
|
54
|
-
blockInstanceId: response.blockInstanceId,
|
|
55
|
-
content: response.content,
|
|
56
|
-
contentUpdatedAt: (_response$contentUpda = response.contentUpdatedAt) !== null && _response$contentUpda !== void 0 ? _response$contentUpda : undefined,
|
|
57
|
-
createdAt: response.createdAt,
|
|
58
|
-
createdBy: response.createdBy,
|
|
59
|
-
deletionReason: (_response$deletionRea = response.deletionReason) !== null && _response$deletionRea !== void 0 ? _response$deletionRea : undefined,
|
|
60
|
-
product: response.product,
|
|
61
|
-
sourceAri: response.sourceAri,
|
|
62
|
-
status: response.status
|
|
63
|
-
};
|
|
64
|
-
const parsed = parseSubscriptionPayload(payload);
|
|
65
|
-
if (!parsed) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return convertParsedDataToSyncBlockInstance(parsed, resourceId);
|
|
69
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { requestSubscription } from 'relay-runtime';
|
|
2
|
-
import { generateBlockAriFromReference } from '../clients/block-service/ari';
|
|
3
|
-
import { subscribeToBlockUpdates as subscribeToBlockUpdatesWS } from '../clients/block-service/blockSubscription';
|
|
4
|
-
import relaySubscriptionUtilsSubscriptionDocument from './__generated__/relaySubscriptionUtilsSubscription.graphql';
|
|
5
|
-
import { convertRelayResponseToSyncBlockInstance, convertParsedDataToSyncBlockInstance } from './relayResponseConverter';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Configuration for creating a Relay block subscription.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates a Relay-based block subscription without needing to wrap providers.
|
|
13
|
-
* This is a clean utility function that can be used directly in components or hooks.
|
|
14
|
-
*
|
|
15
|
-
* @param config - Configuration for the subscription
|
|
16
|
-
* @returns An unsubscribe function to dispose the subscription
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const unsubscribe = createRelayBlockSubscription({
|
|
21
|
-
* relayEnvironment: environment,
|
|
22
|
-
* cloudId: 'my-cloud-id',
|
|
23
|
-
* resourceId: 'my-resource-id',
|
|
24
|
-
* onUpdate: (blockInstance) => {
|
|
25
|
-
* console.log('Block updated:', blockInstance);
|
|
26
|
-
* },
|
|
27
|
-
* onError: (error) => {
|
|
28
|
-
* console.error('Subscription error:', error);
|
|
29
|
-
* }
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* // Later, when component unmounts or subscription is no longer needed
|
|
33
|
-
* unsubscribe();
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export function createRelayBlockSubscription(config) {
|
|
37
|
-
const {
|
|
38
|
-
relayEnvironment,
|
|
39
|
-
cloudId,
|
|
40
|
-
resourceId,
|
|
41
|
-
onUpdate,
|
|
42
|
-
onError
|
|
43
|
-
} = config;
|
|
44
|
-
|
|
45
|
-
// Convert resourceId to blockAri for the subscription
|
|
46
|
-
const blockAri = generateBlockAriFromReference({
|
|
47
|
-
cloudId,
|
|
48
|
-
resourceId
|
|
49
|
-
});
|
|
50
|
-
const subscriptionQuery = relaySubscriptionUtilsSubscriptionDocument;
|
|
51
|
-
|
|
52
|
-
// Try to use Relay subscription first
|
|
53
|
-
try {
|
|
54
|
-
const disposable = requestSubscription(relayEnvironment, {
|
|
55
|
-
subscription: subscriptionQuery,
|
|
56
|
-
variables: {
|
|
57
|
-
resourceId: blockAri
|
|
58
|
-
},
|
|
59
|
-
onNext: response => {
|
|
60
|
-
if (response !== null && response !== void 0 && response.blockService_onBlockUpdated) {
|
|
61
|
-
const syncBlockInstance = convertRelayResponseToSyncBlockInstance(response.blockService_onBlockUpdated, resourceId);
|
|
62
|
-
if (syncBlockInstance) {
|
|
63
|
-
onUpdate(syncBlockInstance);
|
|
64
|
-
} else {
|
|
65
|
-
onError === null || onError === void 0 ? void 0 : onError(new Error('Failed to parse Relay block subscription payload'));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
onError: error => {
|
|
70
|
-
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// If subscription was successfully created, return the unsubscribe function
|
|
75
|
-
if (disposable) {
|
|
76
|
-
return () => {
|
|
77
|
-
disposable.dispose();
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
} catch (error) {
|
|
81
|
-
// If requestSubscription throws, fall back to WebSocket
|
|
82
|
-
onError === null || onError === void 0 ? void 0 : onError(error instanceof Error ? error : new Error('Relay subscription failed'));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Fallback to WebSocket subscription when Relay subscriptions aren't available
|
|
86
|
-
return subscribeToBlockUpdatesWS(blockAri, parsedData => {
|
|
87
|
-
const syncBlockInstance = convertParsedDataToSyncBlockInstance(parsedData, parsedData.resourceId);
|
|
88
|
-
onUpdate(syncBlockInstance);
|
|
89
|
-
}, error => {
|
|
90
|
-
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Hook-like function to create a subscription function that can be passed to providers.
|
|
96
|
-
* This creates a function with the same signature as subscribeToBlockUpdates that uses Relay.
|
|
97
|
-
*
|
|
98
|
-
* @param cloudId - Cloud ID for generating block ARIs
|
|
99
|
-
* @param relayEnvironment - Optional Relay environment. If not provided, will attempt to use global environment
|
|
100
|
-
* @returns A function that can be used as subscribeToBlockUpdates in provider configurations
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* const relaySubscribeToBlockUpdates = createRelaySubscriptionFunction(cloudId, environment);
|
|
105
|
-
*
|
|
106
|
-
* // Can be used directly as a subscribeToBlockUpdates replacement
|
|
107
|
-
* const unsubscribe = relaySubscribeToBlockUpdates(resourceId, onUpdate, onError);
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export function createRelaySubscriptionFunction(cloudId, relayEnvironment) {
|
|
111
|
-
return (resourceId, onUpdate, onError) => {
|
|
112
|
-
const environment = relayEnvironment;
|
|
113
|
-
if (!environment) {
|
|
114
|
-
onError === null || onError === void 0 ? void 0 : onError(new Error('Relay environment not available'));
|
|
115
|
-
return () => {};
|
|
116
|
-
}
|
|
117
|
-
return createRelayBlockSubscription({
|
|
118
|
-
relayEnvironment: environment,
|
|
119
|
-
cloudId,
|
|
120
|
-
resourceId,
|
|
121
|
-
onUpdate,
|
|
122
|
-
onError
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { convertContentUpdatedAt } from '../../utils/utils';
|
|
2
|
-
/**
|
|
3
|
-
* Shared GraphQL subscription query for block updates.
|
|
4
|
-
* This is the canonical subscription query used across all implementations.
|
|
5
|
-
*/
|
|
6
|
-
export var BLOCK_SERVICE_SUBSCRIPTION_QUERY = "\nsubscription EDITOR_SYNCED_BLOCK_ON_BLOCK_UPDATED($resourceId: ID!) {\n\tblockService_onBlockUpdated(resourceId: $resourceId) {\n\t\tblockAri\n\t\tblockInstanceId\n\t\tcontent\n\t\tcontentUpdatedAt\n\t\tcreatedAt\n\t\tcreatedBy\n\t\tdeletionReason\n\t\tproduct\n\t\tsourceAri\n\t\tstatus\n\t}\n}\n";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Raw subscription payload from the GraphQL subscription.
|
|
10
|
-
* This represents the exact shape returned by the blockService_onBlockUpdated subscription.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Parsed and normalized block subscription data.
|
|
15
|
-
* This is the standardized format used across different subscription implementations.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Extracts the resourceId from a block ARI.
|
|
20
|
-
* Block ARI format: ari:cloud:blocks:<cloudId>:synced-block/<resourceId>
|
|
21
|
-
* @param blockAri - The block ARI string
|
|
22
|
-
* @returns The resourceId portion of the ARI
|
|
23
|
-
*/
|
|
24
|
-
export var extractResourceIdFromBlockAri = function extractResourceIdFromBlockAri(blockAri) {
|
|
25
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
26
|
-
var match = blockAri.match(/ari:cloud:blocks:[^:]+:synced-block\/(.+)$/);
|
|
27
|
-
return (match === null || match === void 0 ? void 0 : match[1]) || null;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Converts a timestamp to ISO string.
|
|
32
|
-
* @param timestamp - Timestamp in milliseconds
|
|
33
|
-
* @returns ISO string or undefined if conversion fails
|
|
34
|
-
*/
|
|
35
|
-
export var convertTimestampToISOString = function convertTimestampToISOString(timestamp) {
|
|
36
|
-
if (timestamp === undefined || timestamp === null) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
return new Date(timestamp).toISOString();
|
|
41
|
-
} catch (_unused) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Parses the raw subscription payload into a standardized format.
|
|
48
|
-
* This function handles all the data transformation and error handling consistently
|
|
49
|
-
* across different subscription implementations.
|
|
50
|
-
*
|
|
51
|
-
* @param payload - The raw subscription payload
|
|
52
|
-
* @returns Parsed block data or null if parsing fails
|
|
53
|
-
*/
|
|
54
|
-
export var parseSubscriptionPayload = function parseSubscriptionPayload(payload) {
|
|
55
|
-
try {
|
|
56
|
-
var resourceId = extractResourceIdFromBlockAri(payload.blockAri);
|
|
57
|
-
if (!resourceId) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
var createdAt = convertTimestampToISOString(payload.createdAt);
|
|
61
|
-
return {
|
|
62
|
-
blockAri: payload.blockAri,
|
|
63
|
-
blockInstanceId: payload.blockInstanceId,
|
|
64
|
-
content: JSON.parse(payload.content),
|
|
65
|
-
contentUpdatedAt: convertContentUpdatedAt(payload.contentUpdatedAt),
|
|
66
|
-
createdAt: createdAt,
|
|
67
|
-
createdBy: payload.createdBy,
|
|
68
|
-
product: payload.product,
|
|
69
|
-
resourceId: resourceId,
|
|
70
|
-
sourceAri: payload.sourceAri,
|
|
71
|
-
status: payload.status
|
|
72
|
-
};
|
|
73
|
-
} catch (_unused2) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @generated SignedSource<<559b4fb25d0e5bc72be383427a939e2d>>
|
|
3
|
-
* @relayHash 38684212c43376e58fea2d6095011652
|
|
4
|
-
* @lightSyntaxTransform
|
|
5
|
-
* @nogrep
|
|
6
|
-
* @codegen-command: yarn relay
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/* tslint:disable */
|
|
10
|
-
/* eslint-disable */
|
|
11
|
-
// @ts-nocheck
|
|
12
|
-
|
|
13
|
-
// @relayRequestID c84045a1f05bd1e73ade0a9d8b18462cc3dad5dcae1ebabab76b13135411c530
|
|
14
|
-
|
|
15
|
-
var node = function () {
|
|
16
|
-
var v0 = [{
|
|
17
|
-
"defaultValue": null,
|
|
18
|
-
"kind": "LocalArgument",
|
|
19
|
-
"name": "resourceId"
|
|
20
|
-
}],
|
|
21
|
-
v1 = [{
|
|
22
|
-
"args": [{
|
|
23
|
-
"kind": "Variable",
|
|
24
|
-
"name": "resourceId",
|
|
25
|
-
"variableName": "resourceId"
|
|
26
|
-
}],
|
|
27
|
-
"concreteType": "BlockServiceBlockPayload",
|
|
28
|
-
"kind": "LinkedField",
|
|
29
|
-
"name": "blockService_onBlockUpdated",
|
|
30
|
-
"plural": false,
|
|
31
|
-
"selections": [{
|
|
32
|
-
"kind": "ScalarField",
|
|
33
|
-
"name": "blockAri"
|
|
34
|
-
}, {
|
|
35
|
-
"kind": "ScalarField",
|
|
36
|
-
"name": "blockInstanceId"
|
|
37
|
-
}, {
|
|
38
|
-
"kind": "ScalarField",
|
|
39
|
-
"name": "content"
|
|
40
|
-
}, {
|
|
41
|
-
"kind": "ScalarField",
|
|
42
|
-
"name": "contentUpdatedAt"
|
|
43
|
-
}, {
|
|
44
|
-
"kind": "ScalarField",
|
|
45
|
-
"name": "createdAt"
|
|
46
|
-
}, {
|
|
47
|
-
"kind": "ScalarField",
|
|
48
|
-
"name": "createdBy"
|
|
49
|
-
}, {
|
|
50
|
-
"kind": "ScalarField",
|
|
51
|
-
"name": "deletionReason"
|
|
52
|
-
}, {
|
|
53
|
-
"kind": "ScalarField",
|
|
54
|
-
"name": "product"
|
|
55
|
-
}, {
|
|
56
|
-
"kind": "ScalarField",
|
|
57
|
-
"name": "sourceAri"
|
|
58
|
-
}, {
|
|
59
|
-
"kind": "ScalarField",
|
|
60
|
-
"name": "status"
|
|
61
|
-
}]
|
|
62
|
-
}];
|
|
63
|
-
return {
|
|
64
|
-
"fragment": {
|
|
65
|
-
"argumentDefinitions": v0 /*: any*/,
|
|
66
|
-
"kind": "Fragment",
|
|
67
|
-
"name": "relaySubscriptionUtilsSubscription",
|
|
68
|
-
"selections": v1 /*: any*/,
|
|
69
|
-
"type": "Subscription"
|
|
70
|
-
},
|
|
71
|
-
"kind": "Request",
|
|
72
|
-
"operation": {
|
|
73
|
-
"argumentDefinitions": v0 /*: any*/,
|
|
74
|
-
"kind": "Operation",
|
|
75
|
-
"name": "relaySubscriptionUtilsSubscription",
|
|
76
|
-
"selections": v1 /*: any*/
|
|
77
|
-
},
|
|
78
|
-
"params": {
|
|
79
|
-
"id": "c84045a1f05bd1e73ade0a9d8b18462cc3dad5dcae1ebabab76b13135411c530",
|
|
80
|
-
"metadata": {},
|
|
81
|
-
"name": "relaySubscriptionUtilsSubscription",
|
|
82
|
-
"operationKind": "subscription",
|
|
83
|
-
"text": null
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}();
|
|
87
|
-
node.hash = "6f3ebc87921555436cad753ec1aead2e";
|
|
88
|
-
export default node;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { parseSubscriptionPayload } from '../clients/block-service/sharedSubscriptionUtils';
|
|
2
|
-
import { normaliseSyncBlockStatus } from './validValue';
|
|
3
|
-
/**
|
|
4
|
-
* Converts parsed subscription data to SyncBlockInstance format.
|
|
5
|
-
*
|
|
6
|
-
* @param parsed - The parsed subscription data
|
|
7
|
-
* @param resourceId - The resource ID for the block
|
|
8
|
-
* @returns A SyncBlockInstance
|
|
9
|
-
*/
|
|
10
|
-
export function convertParsedDataToSyncBlockInstance(parsed, resourceId) {
|
|
11
|
-
return {
|
|
12
|
-
data: {
|
|
13
|
-
content: parsed.content,
|
|
14
|
-
contentUpdatedAt: parsed.contentUpdatedAt,
|
|
15
|
-
resourceId: parsed.blockAri,
|
|
16
|
-
blockInstanceId: parsed.blockInstanceId,
|
|
17
|
-
sourceAri: parsed.sourceAri,
|
|
18
|
-
product: parsed.product,
|
|
19
|
-
createdAt: parsed.createdAt,
|
|
20
|
-
createdBy: parsed.createdBy,
|
|
21
|
-
status: normaliseSyncBlockStatus(parsed.status)
|
|
22
|
-
},
|
|
23
|
-
resourceId: resourceId
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Converts a Relay subscription response to SyncBlockInstance format using shared parsing logic.
|
|
29
|
-
|
|
30
|
-
* @param response - The Relay subscription response containing block update data
|
|
31
|
-
* @param resourceId - The resource ID for the block
|
|
32
|
-
* @returns A SyncBlockInstance or null if parsing fails
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* // In a Relay subscription handler
|
|
37
|
-
* onNext: (response) => {
|
|
38
|
-
* if (response?.blockService_onBlockUpdated) {
|
|
39
|
-
* const syncBlockInstance = convertRelayResponseToSyncBlockInstance(
|
|
40
|
-
* response.blockService_onBlockUpdated,
|
|
41
|
-
* resourceId,
|
|
42
|
-
* );
|
|
43
|
-
* if (syncBlockInstance) {
|
|
44
|
-
* onUpdate(syncBlockInstance);
|
|
45
|
-
* }
|
|
46
|
-
* }
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export function convertRelayResponseToSyncBlockInstance(response, resourceId) {
|
|
51
|
-
var _response$contentUpda, _response$deletionRea;
|
|
52
|
-
var payload = {
|
|
53
|
-
blockAri: response.blockAri,
|
|
54
|
-
blockInstanceId: response.blockInstanceId,
|
|
55
|
-
content: response.content,
|
|
56
|
-
contentUpdatedAt: (_response$contentUpda = response.contentUpdatedAt) !== null && _response$contentUpda !== void 0 ? _response$contentUpda : undefined,
|
|
57
|
-
createdAt: response.createdAt,
|
|
58
|
-
createdBy: response.createdBy,
|
|
59
|
-
deletionReason: (_response$deletionRea = response.deletionReason) !== null && _response$deletionRea !== void 0 ? _response$deletionRea : undefined,
|
|
60
|
-
product: response.product,
|
|
61
|
-
sourceAri: response.sourceAri,
|
|
62
|
-
status: response.status
|
|
63
|
-
};
|
|
64
|
-
var parsed = parseSubscriptionPayload(payload);
|
|
65
|
-
if (!parsed) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return convertParsedDataToSyncBlockInstance(parsed, resourceId);
|
|
69
|
-
}
|