• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-typescript-sdk-gen / 6814673855

09 Nov 2023 04:31PM UTC coverage: 31.432% (+1.3%) from 30.127%
6814673855

Pull #41

github

web-flow
Merge 3aec2106f into 1aa8f5afc
Pull Request #41: codegen output 13ed41f186c7473db272e90659610b17

1501 of 9137 branches covered (0.0%)

Branch coverage included in aggregate %.

492 of 992 new or added lines in 75 files covered. (49.6%)

160 existing lines in 14 files now uncovered.

5124 of 11940 relevant lines covered (42.91%)

27.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.22
/src/managers/fileVersions.generated.ts
1
import { serializeFileVersions } from '../schemas.generated.js';
2
import { deserializeFileVersions } from '../schemas.generated.js';
70✔
3
import { serializeClientError } from '../schemas.generated.js';
4
import { deserializeClientError } from '../schemas.generated.js';
5
import { serializeFileVersionFull } from '../schemas.generated.js';
6
import { deserializeFileVersionFull } from '../schemas.generated.js';
70✔
7
import { FileVersions } from '../schemas.generated.js';
8
import { ClientError } from '../schemas.generated.js';
9
import { FileVersionFull } from '../schemas.generated.js';
10
import { Authentication } from '../auth.js';
11
import { NetworkSession } from '../network.js';
12
import { prepareParams } from '../utils.js';
70✔
13
import { toString } from '../utils.js';
70✔
14
import { ByteStream } from '../utils.js';
15
import { CancellationToken } from '../utils.js';
16
import { sdToJson } from '../json.js';
17
import { fetch } from '../fetch.js';
70✔
18
import { FetchOptions } from '../fetch.js';
19
import { FetchResponse } from '../fetch.js';
20
import { SerializedData } from '../json.js';
21
import { sdIsEmpty } from '../json.js';
22
import { sdIsBoolean } from '../json.js';
23
import { sdIsNumber } from '../json.js';
24
import { sdIsString } from '../json.js';
70✔
25
import { sdIsList } from '../json.js';
26
import { sdIsMap } from '../json.js';
27
export interface GetFileVersionsQueryParamsArg {
28
  readonly fields?: readonly string[];
29
  readonly limit?: number;
30
  readonly offset?: number;
31
}
32
export class GetFileVersionsHeadersArg {
70✔
33
  readonly extraHeaders?: {
6✔
34
    readonly [key: string]: undefined | string;
35
  } = {};
36
  constructor(
37
    fields:
38
      | Omit<GetFileVersionsHeadersArg, 'extraHeaders'>
39
      | Partial<Pick<GetFileVersionsHeadersArg, 'extraHeaders'>>
40
  ) {
41
    Object.assign(this, fields);
6✔
42
  }
43
}
44
export interface GetFileVersionByIdQueryParamsArg {
45
  readonly fields?: readonly string[];
46
}
47
export class GetFileVersionByIdHeadersArg {
70✔
48
  readonly extraHeaders?: {
2✔
49
    readonly [key: string]: undefined | string;
50
  } = {};
51
  constructor(
52
    fields:
53
      | Omit<GetFileVersionByIdHeadersArg, 'extraHeaders'>
54
      | Partial<Pick<GetFileVersionByIdHeadersArg, 'extraHeaders'>>
55
  ) {
56
    Object.assign(this, fields);
2✔
57
  }
58
}
59
export interface UpdateFileVersionByIdRequestBodyArg {
60
  readonly trashedAt?: string;
61
}
62
export class UpdateFileVersionByIdHeadersArg {
70✔
63
  readonly extraHeaders?: {
×
64
    readonly [key: string]: undefined | string;
65
  } = {};
66
  constructor(
67
    fields:
68
      | Omit<UpdateFileVersionByIdHeadersArg, 'extraHeaders'>
69
      | Partial<Pick<UpdateFileVersionByIdHeadersArg, 'extraHeaders'>>
70
  ) {
71
    Object.assign(this, fields);
×
72
  }
73
}
74
export class DeleteFileVersionByIdHeadersArg {
70✔
75
  readonly ifMatch?: string;
76
  readonly extraHeaders?: {
2✔
77
    readonly [key: string]: undefined | string;
78
  } = {};
79
  constructor(
80
    fields:
81
      | Omit<DeleteFileVersionByIdHeadersArg, 'extraHeaders'>
82
      | Partial<Pick<DeleteFileVersionByIdHeadersArg, 'extraHeaders'>>
83
  ) {
84
    Object.assign(this, fields);
2✔
85
  }
86
}
87
export type PromoteFileVersionRequestBodyArgTypeField = 'file_version';
88
export interface PromoteFileVersionRequestBodyArg {
89
  readonly id?: string;
90
  readonly type?: PromoteFileVersionRequestBodyArgTypeField;
91
}
92
export interface PromoteFileVersionQueryParamsArg {
93
  readonly fields?: readonly string[];
94
}
95
export class PromoteFileVersionHeadersArg {
70✔
96
  readonly extraHeaders?: {
2✔
97
    readonly [key: string]: undefined | string;
98
  } = {};
99
  constructor(
100
    fields:
101
      | Omit<PromoteFileVersionHeadersArg, 'extraHeaders'>
102
      | Partial<Pick<PromoteFileVersionHeadersArg, 'extraHeaders'>>
103
  ) {
104
    Object.assign(this, fields);
2✔
105
  }
106
}
107
export class FileVersionsManager {
70✔
108
  readonly auth?: Authentication;
109
  readonly networkSession?: NetworkSession;
110
  constructor(
111
    fields: Omit<
112
      FileVersionsManager,
113
      | 'getFileVersions'
114
      | 'getFileVersionById'
115
      | 'updateFileVersionById'
116
      | 'deleteFileVersionById'
117
      | 'promoteFileVersion'
118
    >
119
  ) {
120
    Object.assign(this, fields);
104✔
121
  }
122
  async getFileVersions(
123
    fileId: string,
124
    queryParams: GetFileVersionsQueryParamsArg = {} satisfies GetFileVersionsQueryParamsArg,
6✔
125
    headers: GetFileVersionsHeadersArg = new GetFileVersionsHeadersArg({}),
6✔
126
    cancellationToken?: CancellationToken
127
  ): Promise<FileVersions> {
128
    const queryParamsMap: {
129
      readonly [key: string]: string;
130
    } = prepareParams({
6✔
131
      ['fields']: queryParams.fields
6!
132
        ? queryParams.fields.map(toString).join(',')
133
        : undefined,
134
      ['limit']: toString(queryParams.limit) as string,
135
      ['offset']: toString(queryParams.offset) as string,
136
    });
137
    const headersMap: {
138
      readonly [key: string]: string;
139
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
140
    const response: FetchResponse = (await fetch(
6✔
141
      ''.concat(
142
        'https://api.box.com/2.0/files/',
143
        toString(fileId) as string,
144
        '/versions'
145
      ) as string,
146
      {
147
        method: 'GET',
148
        params: queryParamsMap,
149
        headers: headersMap,
150
        responseFormat: 'json',
151
        auth: this.auth,
152
        networkSession: this.networkSession,
153
        cancellationToken: cancellationToken,
154
      } satisfies FetchOptions
155
    )) as FetchResponse;
156
    return deserializeFileVersions(response.data);
6✔
157
  }
158
  async getFileVersionById(
159
    fileId: string,
160
    fileVersionId: string,
161
    queryParams: GetFileVersionByIdQueryParamsArg = {} satisfies GetFileVersionByIdQueryParamsArg,
2✔
162
    headers: GetFileVersionByIdHeadersArg = new GetFileVersionByIdHeadersArg(
2✔
163
      {}
164
    ),
165
    cancellationToken?: CancellationToken
166
  ): Promise<FileVersionFull> {
167
    const queryParamsMap: {
168
      readonly [key: string]: string;
169
    } = prepareParams({
2✔
170
      ['fields']: queryParams.fields
2!
171
        ? queryParams.fields.map(toString).join(',')
172
        : undefined,
173
    });
174
    const headersMap: {
175
      readonly [key: string]: string;
176
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
177
    const response: FetchResponse = (await fetch(
2✔
178
      ''.concat(
179
        'https://api.box.com/2.0/files/',
180
        toString(fileId) as string,
181
        '/versions/',
182
        toString(fileVersionId) as string
183
      ) as string,
184
      {
185
        method: 'GET',
186
        params: queryParamsMap,
187
        headers: headersMap,
188
        responseFormat: 'json',
189
        auth: this.auth,
190
        networkSession: this.networkSession,
191
        cancellationToken: cancellationToken,
192
      } satisfies FetchOptions
193
    )) as FetchResponse;
194
    return deserializeFileVersionFull(response.data);
2✔
195
  }
196
  async updateFileVersionById(
197
    fileId: string,
198
    fileVersionId: string,
199
    requestBody: UpdateFileVersionByIdRequestBodyArg = {} satisfies UpdateFileVersionByIdRequestBodyArg,
×
200
    headers: UpdateFileVersionByIdHeadersArg = new UpdateFileVersionByIdHeadersArg(
×
201
      {}
202
    ),
203
    cancellationToken?: CancellationToken
204
  ): Promise<FileVersionFull> {
205
    const headersMap: {
206
      readonly [key: string]: string;
207
    } = prepareParams({ ...{}, ...headers.extraHeaders });
×
208
    const response: FetchResponse = (await fetch(
×
209
      ''.concat(
210
        'https://api.box.com/2.0/files/',
211
        toString(fileId) as string,
212
        '/versions/',
213
        toString(fileVersionId) as string
214
      ) as string,
215
      {
216
        method: 'PUT',
217
        headers: headersMap,
218
        data: serializeUpdateFileVersionByIdRequestBodyArg(requestBody),
219
        contentType: 'application/json',
220
        responseFormat: 'json',
221
        auth: this.auth,
222
        networkSession: this.networkSession,
223
        cancellationToken: cancellationToken,
224
      } satisfies FetchOptions
225
    )) as FetchResponse;
NEW
226
    return deserializeFileVersionFull(response.data);
×
227
  }
228
  async deleteFileVersionById(
229
    fileId: string,
230
    fileVersionId: string,
231
    headers: DeleteFileVersionByIdHeadersArg = new DeleteFileVersionByIdHeadersArg(
2✔
232
      {}
233
    ),
234
    cancellationToken?: CancellationToken
235
  ): Promise<undefined> {
236
    const headersMap: {
237
      readonly [key: string]: string;
238
    } = prepareParams({
2✔
239
      ...{ ['if-match']: toString(headers.ifMatch) as string },
240
      ...headers.extraHeaders,
241
    });
242
    const response: FetchResponse = (await fetch(
2✔
243
      ''.concat(
244
        'https://api.box.com/2.0/files/',
245
        toString(fileId) as string,
246
        '/versions/',
247
        toString(fileVersionId) as string
248
      ) as string,
249
      {
250
        method: 'DELETE',
251
        headers: headersMap,
252
        responseFormat: void 0,
253
        auth: this.auth,
254
        networkSession: this.networkSession,
255
        cancellationToken: cancellationToken,
256
      } satisfies FetchOptions
257
    )) as FetchResponse;
258
    return void 0;
2✔
259
  }
260
  async promoteFileVersion(
261
    fileId: string,
262
    requestBody: PromoteFileVersionRequestBodyArg = {} satisfies PromoteFileVersionRequestBodyArg,
×
263
    queryParams: PromoteFileVersionQueryParamsArg = {} satisfies PromoteFileVersionQueryParamsArg,
2✔
264
    headers: PromoteFileVersionHeadersArg = new PromoteFileVersionHeadersArg(
2✔
265
      {}
266
    ),
267
    cancellationToken?: CancellationToken
268
  ): Promise<FileVersionFull> {
269
    const queryParamsMap: {
270
      readonly [key: string]: string;
271
    } = prepareParams({
2✔
272
      ['fields']: queryParams.fields
2!
273
        ? queryParams.fields.map(toString).join(',')
274
        : undefined,
275
    });
276
    const headersMap: {
277
      readonly [key: string]: string;
278
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
279
    const response: FetchResponse = (await fetch(
2✔
280
      ''.concat(
281
        'https://api.box.com/2.0/files/',
282
        toString(fileId) as string,
283
        '/versions/current'
284
      ) as string,
285
      {
286
        method: 'POST',
287
        params: queryParamsMap,
288
        headers: headersMap,
289
        data: serializePromoteFileVersionRequestBodyArg(requestBody),
290
        contentType: 'application/json',
291
        responseFormat: 'json',
292
        auth: this.auth,
293
        networkSession: this.networkSession,
294
        cancellationToken: cancellationToken,
295
      } satisfies FetchOptions
296
    )) as FetchResponse;
297
    return deserializeFileVersionFull(response.data);
2✔
298
  }
299
}
300
export function serializeUpdateFileVersionByIdRequestBodyArg(
70✔
301
  val: UpdateFileVersionByIdRequestBodyArg
302
): SerializedData {
303
  return { ['trashed_at']: val.trashedAt == void 0 ? void 0 : val.trashedAt };
×
304
}
305
export function deserializeUpdateFileVersionByIdRequestBodyArg(
70✔
306
  val: any
307
): UpdateFileVersionByIdRequestBodyArg {
308
  const trashedAt: undefined | string =
309
    val.trashed_at == void 0 ? void 0 : val.trashed_at;
×
310
  return { trashedAt: trashedAt } satisfies UpdateFileVersionByIdRequestBodyArg;
×
311
}
312
export function serializePromoteFileVersionRequestBodyArgTypeField(
70✔
313
  val: PromoteFileVersionRequestBodyArgTypeField
314
): SerializedData {
315
  return val;
2✔
316
}
317
export function deserializePromoteFileVersionRequestBodyArgTypeField(
70✔
318
  val: any
319
): PromoteFileVersionRequestBodyArgTypeField {
NEW
320
  if (!sdIsString(val)) {
×
321
    throw 'Expecting a string for "PromoteFileVersionRequestBodyArgTypeField"';
×
322
  }
323
  if (val == 'file_version') {
×
324
    return 'file_version';
×
325
  }
326
  throw ''.concat('Invalid value: ', val) as string;
×
327
}
328
export function serializePromoteFileVersionRequestBodyArg(
70✔
329
  val: PromoteFileVersionRequestBodyArg
330
): SerializedData {
331
  return {
2✔
332
    ['id']: val.id == void 0 ? void 0 : val.id,
2!
333
    ['type']:
334
      val.type == void 0
2!
335
        ? void 0
336
        : serializePromoteFileVersionRequestBodyArgTypeField(val.type),
337
  };
338
}
339
export function deserializePromoteFileVersionRequestBodyArg(
70✔
340
  val: any
341
): PromoteFileVersionRequestBodyArg {
342
  const id: undefined | string = val.id == void 0 ? void 0 : val.id;
×
343
  const type: undefined | PromoteFileVersionRequestBodyArgTypeField =
344
    val.type == void 0
×
345
      ? void 0
346
      : deserializePromoteFileVersionRequestBodyArgTypeField(val.type);
347
  return { id: id, type: type } satisfies PromoteFileVersionRequestBodyArg;
×
348
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc