@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,123 +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
|
-
var relayEnvironment = config.relayEnvironment,
|
|
38
|
-
cloudId = config.cloudId,
|
|
39
|
-
resourceId = config.resourceId,
|
|
40
|
-
onUpdate = config.onUpdate,
|
|
41
|
-
_onError = config.onError;
|
|
42
|
-
|
|
43
|
-
// Convert resourceId to blockAri for the subscription
|
|
44
|
-
var blockAri = generateBlockAriFromReference({
|
|
45
|
-
cloudId: cloudId,
|
|
46
|
-
resourceId: resourceId
|
|
47
|
-
});
|
|
48
|
-
var subscriptionQuery = relaySubscriptionUtilsSubscriptionDocument;
|
|
49
|
-
|
|
50
|
-
// Try to use Relay subscription first
|
|
51
|
-
try {
|
|
52
|
-
var disposable = requestSubscription(relayEnvironment, {
|
|
53
|
-
subscription: subscriptionQuery,
|
|
54
|
-
variables: {
|
|
55
|
-
resourceId: blockAri
|
|
56
|
-
},
|
|
57
|
-
onNext: function onNext(response) {
|
|
58
|
-
if (response !== null && response !== void 0 && response.blockService_onBlockUpdated) {
|
|
59
|
-
var syncBlockInstance = convertRelayResponseToSyncBlockInstance(response.blockService_onBlockUpdated, resourceId);
|
|
60
|
-
if (syncBlockInstance) {
|
|
61
|
-
onUpdate(syncBlockInstance);
|
|
62
|
-
} else {
|
|
63
|
-
_onError === null || _onError === void 0 || _onError(new Error('Failed to parse Relay block subscription payload'));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
onError: function onError(error) {
|
|
68
|
-
_onError === null || _onError === void 0 || _onError(error);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// If subscription was successfully created, return the unsubscribe function
|
|
73
|
-
if (disposable) {
|
|
74
|
-
return function () {
|
|
75
|
-
disposable.dispose();
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
// If requestSubscription throws, fall back to WebSocket
|
|
80
|
-
_onError === null || _onError === void 0 || _onError(error instanceof Error ? error : new Error('Relay subscription failed'));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Fallback to WebSocket subscription when Relay subscriptions aren't available
|
|
84
|
-
return subscribeToBlockUpdatesWS(blockAri, function (parsedData) {
|
|
85
|
-
var syncBlockInstance = convertParsedDataToSyncBlockInstance(parsedData, parsedData.resourceId);
|
|
86
|
-
onUpdate(syncBlockInstance);
|
|
87
|
-
}, function (error) {
|
|
88
|
-
_onError === null || _onError === void 0 || _onError(error);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Hook-like function to create a subscription function that can be passed to providers.
|
|
94
|
-
* This creates a function with the same signature as subscribeToBlockUpdates that uses Relay.
|
|
95
|
-
*
|
|
96
|
-
* @param cloudId - Cloud ID for generating block ARIs
|
|
97
|
-
* @param relayEnvironment - Optional Relay environment. If not provided, will attempt to use global environment
|
|
98
|
-
* @returns A function that can be used as subscribeToBlockUpdates in provider configurations
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* const relaySubscribeToBlockUpdates = createRelaySubscriptionFunction(cloudId, environment);
|
|
103
|
-
*
|
|
104
|
-
* // Can be used directly as a subscribeToBlockUpdates replacement
|
|
105
|
-
* const unsubscribe = relaySubscribeToBlockUpdates(resourceId, onUpdate, onError);
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export function createRelaySubscriptionFunction(cloudId, relayEnvironment) {
|
|
109
|
-
return function (resourceId, onUpdate, onError) {
|
|
110
|
-
var environment = relayEnvironment;
|
|
111
|
-
if (!environment) {
|
|
112
|
-
onError === null || onError === void 0 || onError(new Error('Relay environment not available'));
|
|
113
|
-
return function () {};
|
|
114
|
-
}
|
|
115
|
-
return createRelayBlockSubscription({
|
|
116
|
-
relayEnvironment: environment,
|
|
117
|
-
cloudId: cloudId,
|
|
118
|
-
resourceId: resourceId,
|
|
119
|
-
onUpdate: onUpdate,
|
|
120
|
-
onError: onError
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
-
import type { SyncBlockProduct } from '../../common/types';
|
|
3
|
-
/**
|
|
4
|
-
* Shared GraphQL subscription query for block updates.
|
|
5
|
-
* This is the canonical subscription query used across all implementations.
|
|
6
|
-
*/
|
|
7
|
-
export declare const 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";
|
|
8
|
-
/**
|
|
9
|
-
* Raw subscription payload from the GraphQL subscription.
|
|
10
|
-
* This represents the exact shape returned by the blockService_onBlockUpdated subscription.
|
|
11
|
-
*/
|
|
12
|
-
export type BlockSubscriptionPayload = {
|
|
13
|
-
blockAri: string;
|
|
14
|
-
blockInstanceId: string;
|
|
15
|
-
content: string;
|
|
16
|
-
contentUpdatedAt?: number;
|
|
17
|
-
createdAt: number;
|
|
18
|
-
createdBy: string;
|
|
19
|
-
deletionReason?: string;
|
|
20
|
-
product: string;
|
|
21
|
-
sourceAri: string;
|
|
22
|
-
status: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Parsed and normalized block subscription data.
|
|
26
|
-
* This is the standardized format used across different subscription implementations.
|
|
27
|
-
*/
|
|
28
|
-
export type ParsedBlockSubscriptionData = {
|
|
29
|
-
blockAri: string;
|
|
30
|
-
blockInstanceId: string;
|
|
31
|
-
content: ADFEntity[];
|
|
32
|
-
contentUpdatedAt?: string;
|
|
33
|
-
createdAt?: string;
|
|
34
|
-
createdBy: string;
|
|
35
|
-
product: SyncBlockProduct;
|
|
36
|
-
resourceId: string;
|
|
37
|
-
sourceAri: string;
|
|
38
|
-
status: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Extracts the resourceId from a block ARI.
|
|
42
|
-
* Block ARI format: ari:cloud:blocks:<cloudId>:synced-block/<resourceId>
|
|
43
|
-
* @param blockAri - The block ARI string
|
|
44
|
-
* @returns The resourceId portion of the ARI
|
|
45
|
-
*/
|
|
46
|
-
export declare const extractResourceIdFromBlockAri: (blockAri: string) => string | null;
|
|
47
|
-
/**
|
|
48
|
-
* Converts a timestamp to ISO string.
|
|
49
|
-
* @param timestamp - Timestamp in milliseconds
|
|
50
|
-
* @returns ISO string or undefined if conversion fails
|
|
51
|
-
*/
|
|
52
|
-
export declare const convertTimestampToISOString: (timestamp?: number) => string | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* Parses the raw subscription payload into a standardized format.
|
|
55
|
-
* This function handles all the data transformation and error handling consistently
|
|
56
|
-
* across different subscription implementations.
|
|
57
|
-
*
|
|
58
|
-
* @param payload - The raw subscription payload
|
|
59
|
-
* @returns Parsed block data or null if parsing fails
|
|
60
|
-
*/
|
|
61
|
-
export declare const parseSubscriptionPayload: (payload: BlockSubscriptionPayload) => ParsedBlockSubscriptionData | null;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @generated SignedSource<<559b4fb25d0e5bc72be383427a939e2d>>
|
|
3
|
-
* @relayHash 38684212c43376e58fea2d6095011652
|
|
4
|
-
* @lightSyntaxTransform
|
|
5
|
-
* @nogrep
|
|
6
|
-
* @codegen-command: yarn relay
|
|
7
|
-
*/
|
|
8
|
-
import type { ConcreteRequest } from 'relay-runtime';
|
|
9
|
-
export type relaySubscriptionUtilsSubscription$variables = {
|
|
10
|
-
resourceId: string;
|
|
11
|
-
};
|
|
12
|
-
export type relaySubscriptionUtilsSubscription$data = {
|
|
13
|
-
readonly blockService_onBlockUpdated: {
|
|
14
|
-
readonly blockAri: string;
|
|
15
|
-
readonly blockInstanceId: string;
|
|
16
|
-
readonly content: string;
|
|
17
|
-
readonly contentUpdatedAt: number | null | undefined;
|
|
18
|
-
readonly createdAt: number;
|
|
19
|
-
readonly createdBy: string;
|
|
20
|
-
readonly deletionReason: string | null | undefined;
|
|
21
|
-
readonly product: string;
|
|
22
|
-
readonly sourceAri: string;
|
|
23
|
-
readonly status: string;
|
|
24
|
-
} | null | undefined;
|
|
25
|
-
};
|
|
26
|
-
export type relaySubscriptionUtilsSubscription = {
|
|
27
|
-
response: relaySubscriptionUtilsSubscription$data;
|
|
28
|
-
variables: relaySubscriptionUtilsSubscription$variables;
|
|
29
|
-
};
|
|
30
|
-
declare const node: ConcreteRequest;
|
|
31
|
-
export default node;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type ParsedBlockSubscriptionData } from '../clients/block-service/sharedSubscriptionUtils';
|
|
2
|
-
import type { ResourceId } from '../common/types';
|
|
3
|
-
import type { SyncBlockInstance } from '../providers/types';
|
|
4
|
-
export type RelayBlockUpdateResponse = {
|
|
5
|
-
blockAri: string;
|
|
6
|
-
blockInstanceId: string;
|
|
7
|
-
content: string;
|
|
8
|
-
contentUpdatedAt?: number | null;
|
|
9
|
-
createdAt: number;
|
|
10
|
-
createdBy: string;
|
|
11
|
-
deletionReason?: string | null;
|
|
12
|
-
product: string;
|
|
13
|
-
sourceAri: string;
|
|
14
|
-
status: string;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Converts parsed subscription data to SyncBlockInstance format.
|
|
18
|
-
*
|
|
19
|
-
* @param parsed - The parsed subscription data
|
|
20
|
-
* @param resourceId - The resource ID for the block
|
|
21
|
-
* @returns A SyncBlockInstance
|
|
22
|
-
*/
|
|
23
|
-
export declare function convertParsedDataToSyncBlockInstance(parsed: ParsedBlockSubscriptionData, resourceId: ResourceId): SyncBlockInstance;
|
|
24
|
-
/**
|
|
25
|
-
* Converts a Relay subscription response to SyncBlockInstance format using shared parsing logic.
|
|
26
|
-
|
|
27
|
-
* @param response - The Relay subscription response containing block update data
|
|
28
|
-
* @param resourceId - The resource ID for the block
|
|
29
|
-
* @returns A SyncBlockInstance or null if parsing fails
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* // In a Relay subscription handler
|
|
34
|
-
* onNext: (response) => {
|
|
35
|
-
* if (response?.blockService_onBlockUpdated) {
|
|
36
|
-
* const syncBlockInstance = convertRelayResponseToSyncBlockInstance(
|
|
37
|
-
* response.blockService_onBlockUpdated,
|
|
38
|
-
* resourceId,
|
|
39
|
-
* );
|
|
40
|
-
* if (syncBlockInstance) {
|
|
41
|
-
* onUpdate(syncBlockInstance);
|
|
42
|
-
* }
|
|
43
|
-
* }
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare function convertRelayResponseToSyncBlockInstance(response: RelayBlockUpdateResponse, resourceId: ResourceId): SyncBlockInstance | null;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { IEnvironment } from 'relay-runtime';
|
|
2
|
-
import type { ResourceId } from '../common/types';
|
|
3
|
-
import type { BlockSubscriptionErrorCallback, BlockUpdateCallback, Unsubscribe } from '../providers/types';
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for creating a Relay block subscription.
|
|
6
|
-
*/
|
|
7
|
-
export interface RelayBlockSubscriptionConfig {
|
|
8
|
-
/** Cloud ID for generating block ARIs */
|
|
9
|
-
cloudId: string;
|
|
10
|
-
/** Optional callback when subscription errors occur */
|
|
11
|
-
onError?: BlockSubscriptionErrorCallback;
|
|
12
|
-
/** Callback when block updates are received */
|
|
13
|
-
onUpdate: BlockUpdateCallback;
|
|
14
|
-
/** Relay environment to use for the subscription */
|
|
15
|
-
relayEnvironment: IEnvironment;
|
|
16
|
-
/** The resource ID to subscribe to */
|
|
17
|
-
resourceId: ResourceId;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Creates a Relay-based block subscription without needing to wrap providers.
|
|
21
|
-
* This is a clean utility function that can be used directly in components or hooks.
|
|
22
|
-
*
|
|
23
|
-
* @param config - Configuration for the subscription
|
|
24
|
-
* @returns An unsubscribe function to dispose the subscription
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const unsubscribe = createRelayBlockSubscription({
|
|
29
|
-
* relayEnvironment: environment,
|
|
30
|
-
* cloudId: 'my-cloud-id',
|
|
31
|
-
* resourceId: 'my-resource-id',
|
|
32
|
-
* onUpdate: (blockInstance) => {
|
|
33
|
-
* console.log('Block updated:', blockInstance);
|
|
34
|
-
* },
|
|
35
|
-
* onError: (error) => {
|
|
36
|
-
* console.error('Subscription error:', error);
|
|
37
|
-
* }
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* // Later, when component unmounts or subscription is no longer needed
|
|
41
|
-
* unsubscribe();
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function createRelayBlockSubscription(config: RelayBlockSubscriptionConfig): Unsubscribe;
|
|
45
|
-
/**
|
|
46
|
-
* Hook-like function to create a subscription function that can be passed to providers.
|
|
47
|
-
* This creates a function with the same signature as subscribeToBlockUpdates that uses Relay.
|
|
48
|
-
*
|
|
49
|
-
* @param cloudId - Cloud ID for generating block ARIs
|
|
50
|
-
* @param relayEnvironment - Optional Relay environment. If not provided, will attempt to use global environment
|
|
51
|
-
* @returns A function that can be used as subscribeToBlockUpdates in provider configurations
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* const relaySubscribeToBlockUpdates = createRelaySubscriptionFunction(cloudId, environment);
|
|
56
|
-
*
|
|
57
|
-
* // Can be used directly as a subscribeToBlockUpdates replacement
|
|
58
|
-
* const unsubscribe = relaySubscribeToBlockUpdates(resourceId, onUpdate, onError);
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export declare function createRelaySubscriptionFunction(cloudId: string, relayEnvironment?: IEnvironment): (resourceId: ResourceId, onUpdate: BlockUpdateCallback, onError?: BlockSubscriptionErrorCallback) => Unsubscribe;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { ADFEntity } from '@atlaskit/adf-utils/types';
|
|
2
|
-
import type { SyncBlockProduct } from '../../common/types';
|
|
3
|
-
/**
|
|
4
|
-
* Shared GraphQL subscription query for block updates.
|
|
5
|
-
* This is the canonical subscription query used across all implementations.
|
|
6
|
-
*/
|
|
7
|
-
export declare const 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";
|
|
8
|
-
/**
|
|
9
|
-
* Raw subscription payload from the GraphQL subscription.
|
|
10
|
-
* This represents the exact shape returned by the blockService_onBlockUpdated subscription.
|
|
11
|
-
*/
|
|
12
|
-
export type BlockSubscriptionPayload = {
|
|
13
|
-
blockAri: string;
|
|
14
|
-
blockInstanceId: string;
|
|
15
|
-
content: string;
|
|
16
|
-
contentUpdatedAt?: number;
|
|
17
|
-
createdAt: number;
|
|
18
|
-
createdBy: string;
|
|
19
|
-
deletionReason?: string;
|
|
20
|
-
product: string;
|
|
21
|
-
sourceAri: string;
|
|
22
|
-
status: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Parsed and normalized block subscription data.
|
|
26
|
-
* This is the standardized format used across different subscription implementations.
|
|
27
|
-
*/
|
|
28
|
-
export type ParsedBlockSubscriptionData = {
|
|
29
|
-
blockAri: string;
|
|
30
|
-
blockInstanceId: string;
|
|
31
|
-
content: ADFEntity[];
|
|
32
|
-
contentUpdatedAt?: string;
|
|
33
|
-
createdAt?: string;
|
|
34
|
-
createdBy: string;
|
|
35
|
-
product: SyncBlockProduct;
|
|
36
|
-
resourceId: string;
|
|
37
|
-
sourceAri: string;
|
|
38
|
-
status: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Extracts the resourceId from a block ARI.
|
|
42
|
-
* Block ARI format: ari:cloud:blocks:<cloudId>:synced-block/<resourceId>
|
|
43
|
-
* @param blockAri - The block ARI string
|
|
44
|
-
* @returns The resourceId portion of the ARI
|
|
45
|
-
*/
|
|
46
|
-
export declare const extractResourceIdFromBlockAri: (blockAri: string) => string | null;
|
|
47
|
-
/**
|
|
48
|
-
* Converts a timestamp to ISO string.
|
|
49
|
-
* @param timestamp - Timestamp in milliseconds
|
|
50
|
-
* @returns ISO string or undefined if conversion fails
|
|
51
|
-
*/
|
|
52
|
-
export declare const convertTimestampToISOString: (timestamp?: number) => string | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* Parses the raw subscription payload into a standardized format.
|
|
55
|
-
* This function handles all the data transformation and error handling consistently
|
|
56
|
-
* across different subscription implementations.
|
|
57
|
-
*
|
|
58
|
-
* @param payload - The raw subscription payload
|
|
59
|
-
* @returns Parsed block data or null if parsing fails
|
|
60
|
-
*/
|
|
61
|
-
export declare const parseSubscriptionPayload: (payload: BlockSubscriptionPayload) => ParsedBlockSubscriptionData | null;
|
package/dist/types-ts4.5/utils/__generated__/relaySubscriptionUtilsSubscription.graphql.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @generated SignedSource<<559b4fb25d0e5bc72be383427a939e2d>>
|
|
3
|
-
* @relayHash 38684212c43376e58fea2d6095011652
|
|
4
|
-
* @lightSyntaxTransform
|
|
5
|
-
* @nogrep
|
|
6
|
-
* @codegen-command: yarn relay
|
|
7
|
-
*/
|
|
8
|
-
import type { ConcreteRequest } from 'relay-runtime';
|
|
9
|
-
export type relaySubscriptionUtilsSubscription$variables = {
|
|
10
|
-
resourceId: string;
|
|
11
|
-
};
|
|
12
|
-
export type relaySubscriptionUtilsSubscription$data = {
|
|
13
|
-
readonly blockService_onBlockUpdated: {
|
|
14
|
-
readonly blockAri: string;
|
|
15
|
-
readonly blockInstanceId: string;
|
|
16
|
-
readonly content: string;
|
|
17
|
-
readonly contentUpdatedAt: number | null | undefined;
|
|
18
|
-
readonly createdAt: number;
|
|
19
|
-
readonly createdBy: string;
|
|
20
|
-
readonly deletionReason: string | null | undefined;
|
|
21
|
-
readonly product: string;
|
|
22
|
-
readonly sourceAri: string;
|
|
23
|
-
readonly status: string;
|
|
24
|
-
} | null | undefined;
|
|
25
|
-
};
|
|
26
|
-
export type relaySubscriptionUtilsSubscription = {
|
|
27
|
-
response: relaySubscriptionUtilsSubscription$data;
|
|
28
|
-
variables: relaySubscriptionUtilsSubscription$variables;
|
|
29
|
-
};
|
|
30
|
-
declare const node: ConcreteRequest;
|
|
31
|
-
export default node;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type ParsedBlockSubscriptionData } from '../clients/block-service/sharedSubscriptionUtils';
|
|
2
|
-
import type { ResourceId } from '../common/types';
|
|
3
|
-
import type { SyncBlockInstance } from '../providers/types';
|
|
4
|
-
export type RelayBlockUpdateResponse = {
|
|
5
|
-
blockAri: string;
|
|
6
|
-
blockInstanceId: string;
|
|
7
|
-
content: string;
|
|
8
|
-
contentUpdatedAt?: number | null;
|
|
9
|
-
createdAt: number;
|
|
10
|
-
createdBy: string;
|
|
11
|
-
deletionReason?: string | null;
|
|
12
|
-
product: string;
|
|
13
|
-
sourceAri: string;
|
|
14
|
-
status: string;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Converts parsed subscription data to SyncBlockInstance format.
|
|
18
|
-
*
|
|
19
|
-
* @param parsed - The parsed subscription data
|
|
20
|
-
* @param resourceId - The resource ID for the block
|
|
21
|
-
* @returns A SyncBlockInstance
|
|
22
|
-
*/
|
|
23
|
-
export declare function convertParsedDataToSyncBlockInstance(parsed: ParsedBlockSubscriptionData, resourceId: ResourceId): SyncBlockInstance;
|
|
24
|
-
/**
|
|
25
|
-
* Converts a Relay subscription response to SyncBlockInstance format using shared parsing logic.
|
|
26
|
-
|
|
27
|
-
* @param response - The Relay subscription response containing block update data
|
|
28
|
-
* @param resourceId - The resource ID for the block
|
|
29
|
-
* @returns A SyncBlockInstance or null if parsing fails
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* // In a Relay subscription handler
|
|
34
|
-
* onNext: (response) => {
|
|
35
|
-
* if (response?.blockService_onBlockUpdated) {
|
|
36
|
-
* const syncBlockInstance = convertRelayResponseToSyncBlockInstance(
|
|
37
|
-
* response.blockService_onBlockUpdated,
|
|
38
|
-
* resourceId,
|
|
39
|
-
* );
|
|
40
|
-
* if (syncBlockInstance) {
|
|
41
|
-
* onUpdate(syncBlockInstance);
|
|
42
|
-
* }
|
|
43
|
-
* }
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare function convertRelayResponseToSyncBlockInstance(response: RelayBlockUpdateResponse, resourceId: ResourceId): SyncBlockInstance | null;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { IEnvironment } from 'relay-runtime';
|
|
2
|
-
import type { ResourceId } from '../common/types';
|
|
3
|
-
import type { BlockSubscriptionErrorCallback, BlockUpdateCallback, Unsubscribe } from '../providers/types';
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for creating a Relay block subscription.
|
|
6
|
-
*/
|
|
7
|
-
export interface RelayBlockSubscriptionConfig {
|
|
8
|
-
/** Cloud ID for generating block ARIs */
|
|
9
|
-
cloudId: string;
|
|
10
|
-
/** Optional callback when subscription errors occur */
|
|
11
|
-
onError?: BlockSubscriptionErrorCallback;
|
|
12
|
-
/** Callback when block updates are received */
|
|
13
|
-
onUpdate: BlockUpdateCallback;
|
|
14
|
-
/** Relay environment to use for the subscription */
|
|
15
|
-
relayEnvironment: IEnvironment;
|
|
16
|
-
/** The resource ID to subscribe to */
|
|
17
|
-
resourceId: ResourceId;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Creates a Relay-based block subscription without needing to wrap providers.
|
|
21
|
-
* This is a clean utility function that can be used directly in components or hooks.
|
|
22
|
-
*
|
|
23
|
-
* @param config - Configuration for the subscription
|
|
24
|
-
* @returns An unsubscribe function to dispose the subscription
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const unsubscribe = createRelayBlockSubscription({
|
|
29
|
-
* relayEnvironment: environment,
|
|
30
|
-
* cloudId: 'my-cloud-id',
|
|
31
|
-
* resourceId: 'my-resource-id',
|
|
32
|
-
* onUpdate: (blockInstance) => {
|
|
33
|
-
* console.log('Block updated:', blockInstance);
|
|
34
|
-
* },
|
|
35
|
-
* onError: (error) => {
|
|
36
|
-
* console.error('Subscription error:', error);
|
|
37
|
-
* }
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* // Later, when component unmounts or subscription is no longer needed
|
|
41
|
-
* unsubscribe();
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function createRelayBlockSubscription(config: RelayBlockSubscriptionConfig): Unsubscribe;
|
|
45
|
-
/**
|
|
46
|
-
* Hook-like function to create a subscription function that can be passed to providers.
|
|
47
|
-
* This creates a function with the same signature as subscribeToBlockUpdates that uses Relay.
|
|
48
|
-
*
|
|
49
|
-
* @param cloudId - Cloud ID for generating block ARIs
|
|
50
|
-
* @param relayEnvironment - Optional Relay environment. If not provided, will attempt to use global environment
|
|
51
|
-
* @returns A function that can be used as subscribeToBlockUpdates in provider configurations
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* const relaySubscribeToBlockUpdates = createRelaySubscriptionFunction(cloudId, environment);
|
|
56
|
-
*
|
|
57
|
-
* // Can be used directly as a subscribeToBlockUpdates replacement
|
|
58
|
-
* const unsubscribe = relaySubscribeToBlockUpdates(resourceId, onUpdate, onError);
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export declare function createRelaySubscriptionFunction(cloudId: string, relayEnvironment?: IEnvironment): (resourceId: ResourceId, onUpdate: BlockUpdateCallback, onError?: BlockSubscriptionErrorCallback) => Unsubscribe;
|