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

box / box-typescript-sdk-gen / 8349154666

19 Mar 2024 07:42PM UTC coverage: 43.733% (+1.7%) from 42.003%
8349154666

Pull #103

github

web-flow
Merge 7b82a5617 into 14e115481
Pull Request #103: chore: Update .codegen.json with commit hash of codegen and openapi spec

2293 of 9105 branches covered (25.18%)

Branch coverage included in aggregate %.

388 of 545 new or added lines in 17 files covered. (71.19%)

184 existing lines in 6 files now uncovered.

7256 of 12730 relevant lines covered (57.0%)

68.54 hits per line

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

46.84
/src/managers/fileMetadata.generated.ts
1
import { serializeMetadatas } from '../schemas.generated.js';
2
import { deserializeMetadatas } from '../schemas.generated.js';
136✔
3
import { serializeClientError } from '../schemas.generated.js';
4
import { deserializeClientError } from '../schemas.generated.js';
5
import { serializeMetadataFull } from '../schemas.generated.js';
6
import { deserializeMetadataFull } from '../schemas.generated.js';
136✔
7
import { Metadatas } from '../schemas.generated.js';
8
import { ClientError } from '../schemas.generated.js';
9
import { MetadataFull } from '../schemas.generated.js';
10
import { Authentication } from '../networking/auth.generated.js';
11
import { NetworkSession } from '../networking/network.generated.js';
136✔
12
import { prepareParams } from '../internal/utils.js';
136✔
13
import { toString } from '../internal/utils.js';
136✔
14
import { ByteStream } from '../internal/utils.js';
15
import { CancellationToken } from '../internal/utils.js';
16
import { FetchOptions } from '../networking/fetch.js';
17
import { FetchResponse } from '../networking/fetch.js';
18
import { fetch } from '../networking/fetch.js';
136✔
19
import { sdToJson } from '../serialization/json.js';
20
import { SerializedData } from '../serialization/json.js';
21
import { BoxSdkError } from '../box/errors.js';
136✔
22
import { sdIsEmpty } from '../serialization/json.js';
23
import { sdIsBoolean } from '../serialization/json.js';
24
import { sdIsNumber } from '../serialization/json.js';
25
import { sdIsString } from '../serialization/json.js';
136✔
26
import { sdIsList } from '../serialization/json.js';
27
import { sdIsMap } from '../serialization/json.js';
28
export class GetFileMetadataHeaders {
136✔
29
  readonly extraHeaders?: {
2✔
30
    readonly [key: string]: undefined | string;
31
  } = {};
32
  constructor(
33
    fields:
34
      | Omit<GetFileMetadataHeaders, 'extraHeaders'>
35
      | Partial<Pick<GetFileMetadataHeaders, 'extraHeaders'>>
36
  ) {
37
    Object.assign(this, fields);
2✔
38
  }
39
}
40
export type GetFileMetadataByIdScope = 'global' | 'enterprise';
41
export class GetFileMetadataByIdHeaders {
136✔
42
  readonly extraHeaders?: {
6✔
43
    readonly [key: string]: undefined | string;
44
  } = {};
45
  constructor(
46
    fields:
47
      | Omit<GetFileMetadataByIdHeaders, 'extraHeaders'>
48
      | Partial<Pick<GetFileMetadataByIdHeaders, 'extraHeaders'>>
49
  ) {
50
    Object.assign(this, fields);
6✔
51
  }
52
}
53
export type CreateFileMetadataByIdScope = 'global' | 'enterprise';
54
export type CreateFileMetadataByIdRequestBody = {
55
  readonly [key: string]: any;
56
};
57
export class CreateFileMetadataByIdHeaders {
136✔
58
  readonly extraHeaders?: {
10✔
59
    readonly [key: string]: undefined | string;
60
  } = {};
61
  constructor(
62
    fields:
63
      | Omit<CreateFileMetadataByIdHeaders, 'extraHeaders'>
64
      | Partial<Pick<CreateFileMetadataByIdHeaders, 'extraHeaders'>>
65
  ) {
66
    Object.assign(this, fields);
10✔
67
  }
68
}
69
export type UpdateFileMetadataByIdScope = 'global' | 'enterprise';
70
export type UpdateFileMetadataByIdRequestBodyOpField =
71
  | 'add'
72
  | 'replace'
73
  | 'remove'
74
  | 'test'
75
  | 'move'
76
  | 'copy';
77
export interface UpdateFileMetadataByIdRequestBody {
78
  readonly op?: UpdateFileMetadataByIdRequestBodyOpField;
79
  readonly path?: string;
80
  readonly value?: string;
81
  readonly from?: string;
82
}
83
export class UpdateFileMetadataByIdHeaders {
136✔
84
  readonly extraHeaders?: {
2✔
85
    readonly [key: string]: undefined | string;
86
  } = {};
87
  constructor(
88
    fields:
89
      | Omit<UpdateFileMetadataByIdHeaders, 'extraHeaders'>
90
      | Partial<Pick<UpdateFileMetadataByIdHeaders, 'extraHeaders'>>
91
  ) {
92
    Object.assign(this, fields);
2✔
93
  }
94
}
95
export type DeleteFileMetadataByIdScope = 'global' | 'enterprise';
96
export class DeleteFileMetadataByIdHeaders {
136✔
97
  readonly extraHeaders?: {
6✔
98
    readonly [key: string]: undefined | string;
99
  } = {};
100
  constructor(
101
    fields:
102
      | Omit<DeleteFileMetadataByIdHeaders, 'extraHeaders'>
103
      | Partial<Pick<DeleteFileMetadataByIdHeaders, 'extraHeaders'>>
104
  ) {
105
    Object.assign(this, fields);
6✔
106
  }
107
}
108
export class FileMetadataManager {
136✔
109
  readonly auth?: Authentication;
110
  readonly networkSession: NetworkSession = new NetworkSession({});
262✔
111
  constructor(
112
    fields:
113
      | Omit<
114
          FileMetadataManager,
115
          | 'networkSession'
116
          | 'getFileMetadata'
117
          | 'getFileMetadataById'
118
          | 'createFileMetadataById'
119
          | 'updateFileMetadataById'
120
          | 'deleteFileMetadataById'
121
        >
122
      | Partial<Pick<FileMetadataManager, 'networkSession'>>
123
  ) {
124
    Object.assign(this, fields);
262✔
125
  }
126
  async getFileMetadata(
127
    fileId: string,
2✔
128
    headers: GetFileMetadataHeaders = new GetFileMetadataHeaders({}),
2✔
129
    cancellationToken?: CancellationToken
130
  ): Promise<Metadatas> {
131
    const headersMap: {
132
      readonly [key: string]: string;
133
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
134
    const response: FetchResponse = (await fetch(
2✔
135
      ''.concat(
136
        this.networkSession.baseUrls.baseUrl,
137
        '/files/',
138
        toString(fileId) as string,
139
        '/metadata'
140
      ) as string,
141
      {
142
        method: 'GET',
143
        headers: headersMap,
144
        responseFormat: 'json',
145
        auth: this.auth,
146
        networkSession: this.networkSession,
147
        cancellationToken: cancellationToken,
148
      } satisfies FetchOptions
149
    )) as FetchResponse;
150
    return deserializeMetadatas(response.data);
2✔
151
  }
152
  async getFileMetadataById(
153
    fileId: string,
6✔
154
    scope: GetFileMetadataByIdScope,
155
    templateKey: string,
156
    headers: GetFileMetadataByIdHeaders = new GetFileMetadataByIdHeaders({}),
6✔
157
    cancellationToken?: CancellationToken
158
  ): Promise<MetadataFull> {
159
    const headersMap: {
160
      readonly [key: string]: string;
161
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
162
    const response: FetchResponse = (await fetch(
6✔
163
      ''.concat(
164
        this.networkSession.baseUrls.baseUrl,
165
        '/files/',
166
        toString(fileId) as string,
167
        '/metadata/',
168
        toString(scope) as string,
169
        '/',
170
        toString(templateKey) as string
171
      ) as string,
172
      {
173
        method: 'GET',
174
        headers: headersMap,
175
        responseFormat: 'json',
176
        auth: this.auth,
177
        networkSession: this.networkSession,
178
        cancellationToken: cancellationToken,
179
      } satisfies FetchOptions
180
    )) as FetchResponse;
181
    return deserializeMetadataFull(response.data);
4✔
182
  }
183
  async createFileMetadataById(
184
    fileId: string,
10✔
185
    scope: CreateFileMetadataByIdScope,
186
    templateKey: string,
187
    requestBody: CreateFileMetadataByIdRequestBody,
188
    headers: CreateFileMetadataByIdHeaders = new CreateFileMetadataByIdHeaders(
10✔
189
      {}
190
    ),
191
    cancellationToken?: CancellationToken
192
  ): Promise<MetadataFull> {
193
    const headersMap: {
194
      readonly [key: string]: string;
195
    } = prepareParams({ ...{}, ...headers.extraHeaders });
10✔
196
    const response: FetchResponse = (await fetch(
10✔
197
      ''.concat(
198
        this.networkSession.baseUrls.baseUrl,
199
        '/files/',
200
        toString(fileId) as string,
201
        '/metadata/',
202
        toString(scope) as string,
203
        '/',
204
        toString(templateKey) as string
205
      ) as string,
206
      {
207
        method: 'POST',
208
        headers: headersMap,
209
        data: serializeCreateFileMetadataByIdRequestBody(requestBody),
210
        contentType: 'application/json',
211
        responseFormat: 'json',
212
        auth: this.auth,
213
        networkSession: this.networkSession,
214
        cancellationToken: cancellationToken,
215
      } satisfies FetchOptions
216
    )) as FetchResponse;
217
    return deserializeMetadataFull(response.data);
10✔
218
  }
219
  async updateFileMetadataById(
220
    fileId: string,
2✔
221
    scope: UpdateFileMetadataByIdScope,
222
    templateKey: string,
223
    requestBody: readonly UpdateFileMetadataByIdRequestBody[],
224
    headers: UpdateFileMetadataByIdHeaders = new UpdateFileMetadataByIdHeaders(
2✔
225
      {}
226
    ),
227
    cancellationToken?: CancellationToken
228
  ): Promise<MetadataFull> {
229
    const headersMap: {
230
      readonly [key: string]: string;
231
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
232
    const response: FetchResponse = (await fetch(
2✔
233
      ''.concat(
234
        this.networkSession.baseUrls.baseUrl,
235
        '/files/',
236
        toString(fileId) as string,
237
        '/metadata/',
238
        toString(scope) as string,
239
        '/',
240
        toString(templateKey) as string
241
      ) as string,
242
      {
243
        method: 'PUT',
244
        headers: headersMap,
245
        data: requestBody.map(
246
          serializeUpdateFileMetadataByIdRequestBody
247
        ) as readonly any[],
248
        contentType: 'application/json-patch+json',
249
        responseFormat: 'json',
250
        auth: this.auth,
251
        networkSession: this.networkSession,
252
        cancellationToken: cancellationToken,
253
      } satisfies FetchOptions
254
    )) as FetchResponse;
255
    return deserializeMetadataFull(response.data);
2✔
256
  }
257
  async deleteFileMetadataById(
258
    fileId: string,
6✔
259
    scope: DeleteFileMetadataByIdScope,
260
    templateKey: string,
261
    headers: DeleteFileMetadataByIdHeaders = new DeleteFileMetadataByIdHeaders(
6✔
262
      {}
263
    ),
264
    cancellationToken?: CancellationToken
265
  ): Promise<undefined> {
266
    const headersMap: {
267
      readonly [key: string]: string;
268
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
269
    const response: FetchResponse = (await fetch(
6✔
270
      ''.concat(
271
        this.networkSession.baseUrls.baseUrl,
272
        '/files/',
273
        toString(fileId) as string,
274
        '/metadata/',
275
        toString(scope) as string,
276
        '/',
277
        toString(templateKey) as string
278
      ) as string,
279
      {
280
        method: 'DELETE',
281
        headers: headersMap,
282
        responseFormat: void 0,
283
        auth: this.auth,
284
        networkSession: this.networkSession,
285
        cancellationToken: cancellationToken,
286
      } satisfies FetchOptions
287
    )) as FetchResponse;
288
    return void 0;
6✔
289
  }
290
}
291
export function serializeGetFileMetadataByIdScope(val: any): SerializedData {
136✔
UNCOV
292
  return val;
×
293
}
294
export function deserializeGetFileMetadataByIdScope(
136✔
295
  val: any
296
): GetFileMetadataByIdScope {
297
  if (!sdIsString(val)) {
×
298
    throw new BoxSdkError({
×
299
      message: 'Expecting a string for "GetFileMetadataByIdScope"',
300
    });
301
  }
302
  if (val == 'global') {
×
303
    return 'global';
×
304
  }
305
  if (val == 'enterprise') {
×
306
    return 'enterprise';
×
307
  }
308
  throw new BoxSdkError({
×
309
    message: ''.concat('Invalid value: ', val) as string,
310
  });
311
}
312
export function serializeCreateFileMetadataByIdScope(val: any): SerializedData {
136✔
UNCOV
313
  return val;
×
314
}
315
export function deserializeCreateFileMetadataByIdScope(
136✔
316
  val: any
317
): CreateFileMetadataByIdScope {
318
  if (!sdIsString(val)) {
×
319
    throw new BoxSdkError({
×
320
      message: 'Expecting a string for "CreateFileMetadataByIdScope"',
321
    });
322
  }
323
  if (val == 'global') {
×
324
    return 'global';
×
325
  }
326
  if (val == 'enterprise') {
×
327
    return 'enterprise';
×
328
  }
329
  throw new BoxSdkError({
×
330
    message: ''.concat('Invalid value: ', val) as string,
331
  });
332
}
333
export function serializeCreateFileMetadataByIdRequestBody(
136✔
334
  val: any
335
): SerializedData {
336
  return Object.fromEntries(
10✔
337
    Object.entries(val).map(([k, v]: [string, any]) => [
26✔
338
      k,
339
      (function (v: any): any {
340
        return v;
26✔
341
      })(v),
342
    ])
343
  ) as {
344
    readonly [key: string]: any;
345
  };
346
}
347
export function deserializeCreateFileMetadataByIdRequestBody(
136✔
348
  val: any
349
): CreateFileMetadataByIdRequestBody {
350
  return val;
×
351
}
352
export function serializeUpdateFileMetadataByIdScope(val: any): SerializedData {
136✔
UNCOV
353
  return val;
×
354
}
355
export function deserializeUpdateFileMetadataByIdScope(
136✔
356
  val: any
357
): UpdateFileMetadataByIdScope {
358
  if (!sdIsString(val)) {
×
359
    throw new BoxSdkError({
×
360
      message: 'Expecting a string for "UpdateFileMetadataByIdScope"',
361
    });
362
  }
363
  if (val == 'global') {
×
364
    return 'global';
×
365
  }
366
  if (val == 'enterprise') {
×
367
    return 'enterprise';
×
368
  }
369
  throw new BoxSdkError({
×
370
    message: ''.concat('Invalid value: ', val) as string,
371
  });
372
}
373
export function serializeUpdateFileMetadataByIdRequestBodyOpField(
136✔
374
  val: any
375
): SerializedData {
376
  return val;
2✔
377
}
378
export function deserializeUpdateFileMetadataByIdRequestBodyOpField(
136✔
379
  val: any
380
): UpdateFileMetadataByIdRequestBodyOpField {
381
  if (!sdIsString(val)) {
×
382
    throw new BoxSdkError({
×
383
      message:
384
        'Expecting a string for "UpdateFileMetadataByIdRequestBodyOpField"',
385
    });
386
  }
387
  if (val == 'add') {
×
388
    return 'add';
×
389
  }
390
  if (val == 'replace') {
×
391
    return 'replace';
×
392
  }
393
  if (val == 'remove') {
×
394
    return 'remove';
×
395
  }
396
  if (val == 'test') {
×
397
    return 'test';
×
398
  }
399
  if (val == 'move') {
×
400
    return 'move';
×
401
  }
402
  if (val == 'copy') {
×
403
    return 'copy';
×
404
  }
405
  throw new BoxSdkError({
×
406
    message: ''.concat('Invalid value: ', val) as string,
407
  });
408
}
409
export function serializeUpdateFileMetadataByIdRequestBody(
136✔
410
  val: any
411
): SerializedData {
412
  return {
2✔
413
    ['op']:
414
      val.op == void 0
2!
415
        ? void 0
416
        : serializeUpdateFileMetadataByIdRequestBodyOpField(val.op),
417
    ['path']: val.path == void 0 ? void 0 : val.path,
2!
418
    ['value']: val.value == void 0 ? void 0 : val.value,
2!
419
    ['from']: val.from == void 0 ? void 0 : val.from,
2!
420
  };
421
}
422
export function deserializeUpdateFileMetadataByIdRequestBody(
136✔
423
  val: any
424
): UpdateFileMetadataByIdRequestBody {
425
  const op: undefined | UpdateFileMetadataByIdRequestBodyOpField =
426
    val.op == void 0
×
427
      ? void 0
428
      : deserializeUpdateFileMetadataByIdRequestBodyOpField(val.op);
429
  const path: undefined | string = val.path == void 0 ? void 0 : val.path;
×
430
  const value: undefined | string = val.value == void 0 ? void 0 : val.value;
×
431
  const from: undefined | string = val.from == void 0 ? void 0 : val.from;
×
432
  return {
×
433
    op: op,
434
    path: path,
435
    value: value,
436
    from: from,
437
  } satisfies UpdateFileMetadataByIdRequestBody;
438
}
439
export function serializeDeleteFileMetadataByIdScope(val: any): SerializedData {
136✔
UNCOV
440
  return val;
×
441
}
442
export function deserializeDeleteFileMetadataByIdScope(
136✔
443
  val: any
444
): DeleteFileMetadataByIdScope {
445
  if (!sdIsString(val)) {
×
446
    throw new BoxSdkError({
×
447
      message: 'Expecting a string for "DeleteFileMetadataByIdScope"',
448
    });
449
  }
450
  if (val == 'global') {
×
451
    return 'global';
×
452
  }
453
  if (val == 'enterprise') {
×
454
    return 'enterprise';
×
455
  }
456
  throw new BoxSdkError({
×
457
    message: ''.concat('Invalid value: ', val) as string,
458
  });
459
}
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