Skip to content

Commit 59a0294

Browse files
committed
feat(Transfer): Adds 'next' export to transfer.fileOperations
1 parent ab6b2ab commit 59a0294

3 files changed

Lines changed: 301 additions & 0 deletions

File tree

src/services/transfer/__tests__/__snapshots__/file-operations.spec.ts.snap

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,96 @@ exports[`transfer.file-operations mkdir 1`] = `
3434
}
3535
`;
3636

37+
exports[`transfer.file-operations next ls 1`] = `
38+
{
39+
"headers": {
40+
"accept": "*/*",
41+
"accept-encoding": "gzip,deflate",
42+
"connection": "close",
43+
"host": "transfer.api.globus.org",
44+
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
45+
},
46+
"method": "GET",
47+
"url": "https://transfer.api.globus.org/v0.10/operation/endpoint/c591c905-2674-4227-9d31-1ff9485945a7/ls?path=%2F%7E%2F",
48+
}
49+
`;
50+
51+
exports[`transfer.file-operations next mkdir 1`] = `
52+
{
53+
"headers": {
54+
"accept": "*/*",
55+
"accept-encoding": "gzip,deflate",
56+
"connection": "close",
57+
"content-length": "47",
58+
"content-type": "application/json",
59+
"host": "transfer.api.globus.org",
60+
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
61+
},
62+
"json": {
63+
"DATA_TYPE": "mkdir",
64+
"path": "/~/new-directory",
65+
},
66+
"method": "POST",
67+
"url": "https://transfer.api.globus.org/v0.10/operation/endpoint/c591c905-2674-4227-9d31-1ff9485945a7/mkdir",
68+
}
69+
`;
70+
71+
exports[`transfer.file-operations next rename 1`] = `
72+
{
73+
"headers": {
74+
"accept": "*/*",
75+
"accept-encoding": "gzip,deflate",
76+
"connection": "close",
77+
"content-length": "75",
78+
"content-type": "application/json",
79+
"host": "transfer.api.globus.org",
80+
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
81+
},
82+
"json": {
83+
"DATA_TYPE": "rename",
84+
"new_path": "/new-path",
85+
"old_path": "/~/old-directory",
86+
},
87+
"method": "POST",
88+
"url": "https://transfer.api.globus.org/v0.10/operation/endpoint/c591c905-2674-4227-9d31-1ff9485945a7/rename",
89+
}
90+
`;
91+
92+
exports[`transfer.file-operations next stat 1`] = `
93+
{
94+
"headers": {
95+
"accept": "*/*",
96+
"accept-encoding": "gzip,deflate",
97+
"connection": "close",
98+
"host": "transfer.api.globus.org",
99+
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
100+
},
101+
"method": "GET",
102+
"url": "https://transfer.api.globus.org/v0.10/operation/endpoint/c591c905-2674-4227-9d31-1ff9485945a7/stat?path=%2F%7E%2Fmy-file",
103+
}
104+
`;
105+
106+
exports[`transfer.file-operations next symlink 1`] = `
107+
{
108+
"headers": {
109+
"accept": "*/*",
110+
"accept-encoding": "gzip,deflate",
111+
"connection": "close",
112+
"content-length": "96",
113+
"content-type": "application/json",
114+
"host": "transfer.api.globus.org",
115+
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
116+
},
117+
"json": {
118+
"DATA_TYPE": "symlink",
119+
"path": "/~/quick_link.txt",
120+
"symlink_target": "/~/some/project/myfile.txt",
121+
},
122+
"method": "POST",
123+
"url": "https://transfer.api.globus.org/v0.10/operation/endpoint/c591c905-2674-4227-9d31-1ff9485945a7/symlink",
124+
}
125+
`;
126+
37127
exports[`transfer.file-operations rename 1`] = `
38128
{
39129
"headers": {

src/services/transfer/__tests__/file-operations.spec.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,111 @@ describe('transfer.file-operations', () => {
109109
headers,
110110
}).toMatchSnapshot();
111111
});
112+
113+
describe('next', () => {
114+
test('ls', async () => {
115+
const {
116+
req: { url, method, headers },
117+
} = await mirror(
118+
await fileOperations.next.ls({
119+
endpoint_xid: ENDPOINT,
120+
request: {
121+
query: {
122+
path: '/~/',
123+
},
124+
},
125+
}),
126+
);
127+
expect({
128+
url,
129+
method,
130+
headers,
131+
}).toMatchSnapshot();
132+
});
133+
134+
test('mkdir', async () => {
135+
const {
136+
req: { url, method, headers, json },
137+
} = await mirror(
138+
await fileOperations.next.mkdir({
139+
endpoint_xid: ENDPOINT,
140+
request: {
141+
data: {
142+
path: '/~/new-directory',
143+
},
144+
},
145+
}),
146+
);
147+
expect({
148+
url,
149+
method,
150+
headers,
151+
json,
152+
}).toMatchSnapshot();
153+
});
154+
155+
test('rename', async () => {
156+
const {
157+
req: { url, method, headers, json },
158+
} = await mirror(
159+
await fileOperations.next.rename({
160+
endpoint_xid: ENDPOINT,
161+
request: {
162+
data: {
163+
old_path: '/~/old-directory',
164+
new_path: '/new-path',
165+
},
166+
},
167+
}),
168+
);
169+
expect({
170+
url,
171+
method,
172+
headers,
173+
json,
174+
}).toMatchSnapshot();
175+
});
176+
177+
test('symlink', async () => {
178+
const {
179+
req: { url, method, headers, json },
180+
} = await mirror(
181+
await fileOperations.next.symlink({
182+
endpoint_xid: ENDPOINT,
183+
request: {
184+
data: {
185+
symlink_target: '/~/some/project/myfile.txt',
186+
path: '/~/quick_link.txt',
187+
},
188+
},
189+
}),
190+
);
191+
expect({
192+
url,
193+
method,
194+
headers,
195+
json,
196+
}).toMatchSnapshot();
197+
});
198+
199+
test('stat', async () => {
200+
const {
201+
req: { url, method, headers },
202+
} = await mirror(
203+
await fileOperations.next.stat({
204+
endpoint_xid: ENDPOINT,
205+
request: {
206+
query: {
207+
path: '/~/my-file',
208+
},
209+
},
210+
}),
211+
);
212+
expect({
213+
url,
214+
method,
215+
headers,
216+
}).toMatchSnapshot();
217+
});
218+
});
112219
});

src/services/transfer/service/file-operations.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { HTTP_METHODS, serviceRequest } from '../../shared.js';
22
import { getHeadersForService } from '../shared.js';
33
import { ID, SCOPES } from '../config.js';
4+
import { RESOURCE_SERVERS } from '../../auth/config.js';
5+
import { createServiceMethodFactory } from '../../factory.js';
46

57
import type { ErrorDocument, QueryParameters } from '../types.js';
68
import type { JSONFetchResponse, ServiceMethodDynamicSegments } from '../../types.js';
79
import { ConsentRequiredError } from '../../../core/errors.js';
810

11+
// eslint-disable-next-line @typescript-eslint/naming-convention
12+
const resource_server = RESOURCE_SERVERS[ID];
13+
914
/**
1015
* @see https://docs.globus.org/api/transfer/file_operations/#file_document
1116
*/
@@ -242,3 +247,102 @@ export const stat = function (
242247
};
243248
}
244249
>;
250+
251+
/**
252+
* @private
253+
*/
254+
export const next = {
255+
ls: createServiceMethodFactory({
256+
service: ID,
257+
resource_server,
258+
path: `/v0.10/operation/endpoint/{endpoint_xid}/ls`,
259+
}).generate<
260+
{
261+
request?: {
262+
query?: DirectoryListingQuery;
263+
};
264+
},
265+
JSONFetchResponse<FileListDocument | DirectoryListingError>
266+
>(),
267+
mkdir: createServiceMethodFactory({
268+
service: ID,
269+
resource_server,
270+
path: `/v0.10/operation/endpoint/{endpoint_xid}/mkdir`,
271+
method: HTTP_METHODS.POST,
272+
transform: (payload) => ({
273+
...payload,
274+
request: {
275+
...payload?.request,
276+
data: { DATA_TYPE: 'mkdir', ...payload?.request?.data },
277+
},
278+
}),
279+
}).generate<
280+
{
281+
request: {
282+
data: { path: string };
283+
};
284+
},
285+
Response
286+
>(),
287+
rename: createServiceMethodFactory({
288+
service: ID,
289+
resource_server,
290+
path: `/v0.10/operation/endpoint/{endpoint_xid}/rename`,
291+
method: HTTP_METHODS.POST,
292+
transform: (payload) => ({
293+
...payload,
294+
request: {
295+
...payload?.request,
296+
data: { DATA_TYPE: 'rename', ...payload?.request?.data },
297+
},
298+
}),
299+
}).generate<
300+
{
301+
request: {
302+
data: {
303+
old_path: string;
304+
new_path: string;
305+
};
306+
};
307+
},
308+
Response
309+
>(),
310+
symlink: createServiceMethodFactory({
311+
service: ID,
312+
resource_server,
313+
path: `/v0.10/operation/endpoint/{endpoint_xid}/symlink`,
314+
method: HTTP_METHODS.POST,
315+
transform: (payload) => ({
316+
...payload,
317+
request: {
318+
...payload?.request,
319+
data: { DATA_TYPE: 'symlink', ...payload?.request?.data },
320+
},
321+
}),
322+
}).generate<
323+
{
324+
request: {
325+
data: {
326+
path: string;
327+
symlink_target: string;
328+
};
329+
};
330+
},
331+
Response
332+
>(),
333+
stat: createServiceMethodFactory({
334+
service: ID,
335+
resource_server,
336+
path: `/v0.10/operation/endpoint/{endpoint_xid}/stat`,
337+
}).generate<
338+
{
339+
request: {
340+
query: {
341+
path: string;
342+
local_user?: string;
343+
};
344+
};
345+
},
346+
JSONFetchResponse<FileDocument>
347+
>(),
348+
};

0 commit comments

Comments
 (0)