1- import * as adapterVfsClient from '@relayfile/adapter-core/vfs-client' ;
21import {
32 writeJsonFile as coreWriteJsonFile ,
4- RelayfileWritebackError ,
3+ normalizeWritebackStatus ,
4+ WritebackError ,
55 type IntegrationClientOptions ,
6- type WritebackReceipt ,
76 type WritebackResult
87} from '@relayfile/adapter-core/vfs-client' ;
98
@@ -25,8 +24,12 @@ export {
2524 readTextFile ,
2625 resolveMountRoot ,
2726 RelayfileWritebackError ,
27+ WritebackError ,
28+ normalizeWritebackStatus ,
2829 type RelayfileWritebackErrorOptions ,
2930 type IntegrationClientOptions ,
31+ type NormalizedWritebackState ,
32+ type NormalizedWritebackStatus ,
3033 type WritebackReceipt ,
3134 type WritebackResult
3235} from '@relayfile/adapter-core/vfs-client' ;
@@ -37,101 +40,6 @@ export {
3740 SandboxNotAvailableError
3841} from '../errors.js' ;
3942
40- export type NormalizedWritebackState =
41- | 'succeeded'
42- | 'no_receipt'
43- | 'validation_failed'
44- | 'readonly_rejected'
45- | 'adapter_error'
46- | 'ok' ;
47-
48- export interface NormalizedWritebackStatus {
49- state : NormalizedWritebackState ;
50- path : string ;
51- op ?: 'create' | 'patch' | 'delete' ;
52- id ?: string ;
53- error ?: string ;
54- field ?: string ;
55- receipt ?: WritebackReceipt ;
56- timestamp ?: string ;
57- entry ?: unknown ;
58- }
59-
60- type AdapterVfsClientExtensions = {
61- normalizeWritebackStatus ?: (
62- result ?: WritebackResult ,
63- entry ?: unknown
64- ) => NormalizedWritebackStatus ;
65- WritebackError ?: new ( normalized : NormalizedWritebackStatus ) => RelayfileWritebackError &
66- NormalizedWritebackStatus ;
67- } ;
68-
69- class FallbackWritebackError extends RelayfileWritebackError {
70- readonly state : NormalizedWritebackState ;
71- readonly path : string ;
72- readonly op ?: 'create' | 'patch' | 'delete' ;
73- readonly id ?: string ;
74- readonly receipt ?: WritebackReceipt ;
75- readonly error ?: string ;
76- readonly field ?: string ;
77- readonly timestamp ?: string ;
78-
79- constructor ( normalized : NormalizedWritebackStatus ) {
80- super ( {
81- provider : 'writeback' ,
82- operation : normalized . state ,
83- cause : normalized . error ? new Error ( normalized . error ) : undefined ,
84- retryable : false
85- } ) ;
86- this . name = 'WritebackError' ;
87- this . message = `writeback ${ normalized . state } ${ normalized . path } ${
88- normalized . error ? `: ${ normalized . error } ` : ''
89- } `;
90- this . state = normalized . state ;
91- this . path = normalized . path ;
92- this . op = normalized . op ;
93- this . id = normalized . id ;
94- this . receipt = normalized . receipt ;
95- this . error = normalized . error ;
96- this . field = normalized . field ;
97- this . timestamp = normalized . timestamp ;
98- }
99- }
100-
101- const adapterExtensions = adapterVfsClient as AdapterVfsClientExtensions ;
102-
103- export const WritebackError = adapterExtensions . WritebackError ?? FallbackWritebackError ;
104-
105- export function normalizeWritebackStatus (
106- result ?: WritebackResult ,
107- entry ?: unknown
108- ) : NormalizedWritebackStatus {
109- const normalize = adapterExtensions . normalizeWritebackStatus ;
110- if ( normalize ) return normalize ( result , entry ) ;
111-
112- if ( ! result ?. receipt ) {
113- return {
114- state : 'no_receipt' ,
115- path : result ?. path ?? '' ,
116- error : 'writeback produced no receipt'
117- } ;
118- }
119-
120- const receipt = result . receipt ;
121- const id =
122- receipt . id !== undefined
123- ? String ( receipt . id )
124- : receipt . created !== undefined
125- ? String ( receipt . created )
126- : undefined ;
127- return {
128- state : 'succeeded' ,
129- path : result . path ,
130- ...( id ? { id } : { } ) ,
131- receipt
132- } ;
133- }
134-
13543export async function writeJsonFile (
13644 client : IntegrationClientOptions ,
13745 provider : string ,
0 commit comments