@finueva/drive 0.3.0 → 0.5.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/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const DRIVE_API_ERROR_CODES = Object.freeze([
8
8
  "invalid_pagination_cursor",
9
9
  "invalid_idempotency_key",
10
10
  "precondition_failed",
11
+ "range_not_satisfiable",
11
12
  "idempotency_conflict",
12
13
  "quota_exceeded",
13
14
  "upload_recovery_required",
@@ -23,6 +24,7 @@ const DRIVE_API_ERROR_MESSAGES = Object.freeze({
23
24
  invalid_pagination_cursor: "The pagination cursor is invalid.",
24
25
  invalid_idempotency_key: "The idempotency key is invalid.",
25
26
  precondition_failed: "The request precondition failed.",
27
+ range_not_satisfiable: "The requested byte range is not satisfiable.",
26
28
  idempotency_conflict: "The idempotency key conflicts with an earlier request.",
27
29
  quota_exceeded: "The workspace storage quota would be exceeded.",
28
30
  upload_recovery_required: "The upload requires recovery before it can continue.",
@@ -61,6 +63,7 @@ const REQUEST_ID = /^[A-Za-z0-9_-]{16,128}$/;
61
63
  const COLLECTION_ETAG = /^"drive\.permission-collection\.v1\.(0|[1-9][0-9]*)"$/;
62
64
  const GRANT_ETAG$1 = /^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/;
63
65
  const LIST_ETAG$1 = /^"drive\.permission-list\.v1\.[0-9a-f]{64}"$/;
66
+ const ITEM_ETAG = /^"drive\.item\.v1\.(0|[1-9][0-9]*)"$/;
64
67
  async function parseResponse(response, operationSignal, preconditionStatus, successStatuses, guard, allowsQuotaExceeded, allowedErrorCodes) {
65
68
  const requestId = safeRequestId(response.headers.get("x-request-id"));
66
69
  if (requestId === null) {
@@ -68,6 +71,24 @@ async function parseResponse(response, operationSignal, preconditionStatus, succ
68
71
  throw new DriveError("invalid_response", { status: response.status });
69
72
  }
70
73
  if (!successStatuses.includes(response.status)) throw await normalizeError(response, requestId, operationSignal, preconditionStatus, allowsQuotaExceeded, allowedErrorCodes);
74
+ if (response.status === 304) {
75
+ const contentLength = response.headers.get("content-length");
76
+ const etag = response.headers.get("etag");
77
+ const status = response.status;
78
+ if (response.body !== null || contentLength !== null && contentLength !== "0" || response.headers.has("content-type") || etag === null || !/^"[\x21\x23-\x7e]{1,1022}"$/.test(etag) || !guard(void 0, status, response.headers)) {
79
+ cancelResponse(response);
80
+ throw new DriveError("invalid_response", {
81
+ status,
82
+ requestId
83
+ });
84
+ }
85
+ return Object.freeze({
86
+ data: void 0,
87
+ status,
88
+ requestId,
89
+ validators: Object.freeze({ etag })
90
+ });
91
+ }
71
92
  const { value } = await parseBoundedJson(response, SUCCESS_BODY_LIMIT, response.status, requestId, operationSignal);
72
93
  const status = response.status;
73
94
  if (!guard(value, status, response.headers)) throw new DriveError("invalid_response", {
@@ -116,6 +137,12 @@ function parseGrantEtag(value) {
116
137
  const grantRevision = Number(match[2]);
117
138
  return Number.isSafeInteger(collectionRevision) && Number.isSafeInteger(grantRevision) ? [collectionRevision, grantRevision] : void 0;
118
139
  }
140
+ function parseItemEtag(value) {
141
+ const match = ITEM_ETAG.exec(value);
142
+ if (!match) return void 0;
143
+ const revision = Number(match[1]);
144
+ return Number.isSafeInteger(revision) ? revision : void 0;
145
+ }
119
146
  async function normalizeError(response, headerRequestId, signal, preconditionStatus, allowsQuotaExceeded, allowedErrorCodes) {
120
147
  let parsed;
121
148
  try {
@@ -159,6 +186,7 @@ function errorStatusMatches(code, status, preconditionStatus, allowsQuotaExceede
159
186
  invalid_pagination_cursor: [422],
160
187
  invalid_idempotency_key: [422],
161
188
  precondition_failed: preconditionStatus === null ? [] : [preconditionStatus],
189
+ range_not_satisfiable: [416],
162
190
  idempotency_conflict: [409],
163
191
  quota_exceeded: [409],
164
192
  upload_recovery_required: [409],
@@ -256,7 +284,7 @@ function readValidators(headers) {
256
284
  const permissionCollectionEtag = headers.get("drive-permission-collection-etag");
257
285
  const permissionGrantEtag = headers.get("drive-permission-grant-etag");
258
286
  return Object.freeze({
259
- ...etag !== null && LIST_ETAG$1.test(etag) ? { etag } : {},
287
+ ...etag !== null && (LIST_ETAG$1.test(etag) || parseItemEtag(etag) !== void 0) ? { etag } : {},
260
288
  ...permissionCollectionEtag !== null && parseCollectionEtag(permissionCollectionEtag) !== void 0 ? { permissionCollectionEtag } : {},
261
289
  ...permissionGrantEtag !== null && parseGrantEtag(permissionGrantEtag) !== void 0 ? { permissionGrantEtag } : {}
262
290
  });
@@ -272,7 +300,8 @@ const WORKSPACE_ID$1 = /^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-
272
300
  const VOLUME_ID = /^drive\.volume\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
273
301
  const GRANT_ID$1 = /^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
274
302
  const UPLOAD_ID$1 = /^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
275
- const VERSION_ID = /^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
303
+ const VERSION_ID$1 = /^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
304
+ const RETRIEVAL_ID = /^drive\.retrieval\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
276
305
  const CURSOR$1 = /^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/;
277
306
  const AUTH_ID$1 = /^[A-Za-z0-9_-]{1,128}$/;
278
307
  const GRANT_ETAG = /^"drive\.permission-grant\.v1\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"$/;
@@ -297,6 +326,7 @@ const EFFECTIVE_ACTIONS = Object.freeze([
297
326
  const MAX_UPLOAD_BYTE_LENGTH$1 = 33554432e4;
298
327
  const UPLOAD_PART_BYTE_LENGTH$2 = 32 * 1024 * 1024;
299
328
  const CONTENT_DIGEST$1 = /^sha256:[0-9a-f]{64}$/;
329
+ const UTF8 = new TextEncoder();
300
330
  function isCurrentWorkspace(value) {
301
331
  if (!isExactRecord(value, [
302
332
  "workspaceId",
@@ -307,6 +337,61 @@ function isCurrentWorkspace(value) {
307
337
  const reference = value.workspaceReference;
308
338
  return isExactRecord(reference, ["type", "userId"]) && reference.type === "personal" && typeof reference.userId === "string" && AUTH_ID$1.test(reference.userId) || isExactRecord(reference, ["type", "organizationId"]) && reference.type === "organization" && typeof reference.organizationId === "string" && AUTH_ID$1.test(reference.organizationId);
309
339
  }
340
+ function isManagedDownloadDescriptor(value) {
341
+ if (!isExactRecord(value, [
342
+ "mode",
343
+ "method",
344
+ "url",
345
+ "headers",
346
+ "expiresAtEpochMilliseconds",
347
+ "response"
348
+ ]) || value.mode !== "presigned-single" || value.method !== "GET" && value.method !== "HEAD" || typeof value.url !== "string" || !isSafeCapabilityUrl(value.url) || !isSafeInteger$1(value.expiresAtEpochMilliseconds) || !isExactRecord(value.headers, ["if-match"]) && !isExactRecord(value.headers, ["if-match", "range"]) || typeof value.headers["if-match"] !== "string" || !isStrongEtag(value.headers["if-match"]) || value.headers.range !== void 0 && (typeof value.headers.range !== "string" || !/^bytes=(?:0|[1-9][0-9]*)-(?:0|[1-9][0-9]*)$/.test(value.headers.range)) || !isExactRecord(value.response, [
349
+ "status",
350
+ "versionId",
351
+ "byteLength",
352
+ "contentLength",
353
+ "contentType",
354
+ "contentDisposition",
355
+ "etag",
356
+ "acceptRanges",
357
+ "contentRange"
358
+ ]) || value.response.status !== 200 && value.response.status !== 206 || typeof value.response.versionId !== "string" || !VERSION_ID$1.test(value.response.versionId) || !isSafeInteger$1(value.response.byteLength) || !isSafeInteger$1(value.response.contentLength) || typeof value.response.contentType !== "string" || !/^[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?\/[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?$/.test(value.response.contentType) || typeof value.response.contentDisposition !== "string" || value.response.contentDisposition.length > 2048 || !/^[\x20-\x7e]+$/.test(value.response.contentDisposition) || value.response.etag !== value.headers["if-match"] || value.response.acceptRanges !== "bytes" || value.response.contentRange !== null && typeof value.response.contentRange !== "string") return false;
359
+ if (!downloadDescriptorIsCoherent(value)) return false;
360
+ Object.freeze(value.headers);
361
+ Object.freeze(value.response);
362
+ Object.freeze(value);
363
+ return true;
364
+ }
365
+ function downloadDescriptorIsCoherent(value) {
366
+ const response = value.response;
367
+ if (response.contentLength > response.byteLength || value.method === "HEAD" && response.status !== 200 || !response.contentDisposition.startsWith("attachment; filename=\"")) return false;
368
+ if (response.status === 200) return value.headers.range === void 0 && response.contentRange === null && response.contentLength === response.byteLength;
369
+ if (value.method !== "GET" || value.headers.range === void 0 || response.contentRange === null) return false;
370
+ const range = /^bytes=(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$/.exec(value.headers.range);
371
+ const contentRange = /^bytes (0|[1-9][0-9]*)-(0|[1-9][0-9]*)\/(0|[1-9][0-9]*)$/.exec(response.contentRange);
372
+ if (!range || !contentRange) return false;
373
+ const start = Number(range[1]);
374
+ const end = Number(range[2]);
375
+ const contentStart = Number(contentRange[1]);
376
+ const contentEnd = Number(contentRange[2]);
377
+ const byteLength = Number(contentRange[3]);
378
+ return [
379
+ start,
380
+ end,
381
+ contentStart,
382
+ contentEnd,
383
+ byteLength
384
+ ].every(isSafeInteger$1) && start === contentStart && end === contentEnd && byteLength === response.byteLength && start <= end && end < byteLength && response.contentLength === end - start + 1;
385
+ }
386
+ function isManagedDownloadRestorePending(value) {
387
+ return isExactRecord(value, [
388
+ "mode",
389
+ "operationId",
390
+ "versionId",
391
+ "state",
392
+ "pollAfterSeconds"
393
+ ]) && value.mode === "restore-pending" && typeof value.operationId === "string" && RETRIEVAL_ID.test(value.operationId) && typeof value.versionId === "string" && VERSION_ID$1.test(value.versionId) && (value.state === "pending" || value.state === "restoring") && isSafeInteger$1(value.pollAfterSeconds) && value.pollAfterSeconds >= 1 && value.pollAfterSeconds <= 60;
394
+ }
310
395
  function isFolderPage(value, workspaceId, parentItemId) {
311
396
  if (!(isExactRecord(value, ["items", "nextCursor"]) && Array.isArray(value.items) && value.items.length <= 50 && value.items.every(isFolderItem) && (value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length <= 699 && CURSOR$1.test(value.nextCursor)))) return false;
312
397
  return value.items.every((item) => item.workspaceId === workspaceId && item.parentItemId === parentItemId) && isStrictlyOrdered(value.items, (item) => item.itemId);
@@ -323,6 +408,101 @@ function isFolderItem(value) {
323
408
  "revision"
324
409
  ]) && typeof value.workspaceId === "string" && WORKSPACE_ID$1.test(value.workspaceId) && typeof value.volumeId === "string" && VOLUME_ID.test(value.volumeId) && typeof value.itemId === "string" && ITEM_ID$1.test(value.itemId) && typeof value.parentItemId === "string" && ITEM_ID$1.test(value.parentItemId) && (value.kind === "file" || value.kind === "folder") && isSafeFilename$1(value.name) && (value.visibility === "workspace" || value.visibility === "restricted") && isSafeInteger$1(value.revision);
325
410
  }
411
+ function isManagedLifecycleItem(value, workspaceId, itemId, expectedState) {
412
+ if (!isExactRecord(value, [
413
+ "workspaceId",
414
+ "volumeId",
415
+ "itemId",
416
+ "parentItemId",
417
+ "kind",
418
+ "name",
419
+ "state",
420
+ "revision",
421
+ "purgeAfterEpochMilliseconds"
422
+ ]) || value.workspaceId !== workspaceId || value.itemId !== itemId || typeof value.volumeId !== "string" || !VOLUME_ID.test(value.volumeId) || typeof value.parentItemId !== "string" || !ITEM_ID$1.test(value.parentItemId) || value.kind !== "file" && value.kind !== "folder" || !isSafeFilename$1(value.name) || value.state !== expectedState || !isSafeInteger$1(value.revision) || (value.state === "active" ? value.purgeAfterEpochMilliseconds !== null : !isSafeInteger$1(value.purgeAfterEpochMilliseconds))) return false;
423
+ Object.freeze(value);
424
+ return true;
425
+ }
426
+ function isManagedItemMetadata(value, workspaceId, itemId) {
427
+ if (!isExactRecord(value, [
428
+ "workspaceId",
429
+ "itemId",
430
+ "parentId",
431
+ "type",
432
+ "name",
433
+ "lifecycleState",
434
+ "revision",
435
+ "currentVersion"
436
+ ]) || value.workspaceId !== workspaceId || value.itemId !== itemId || !(value.parentId === null || typeof value.parentId === "string" && ITEM_ID$1.test(value.parentId)) || value.type !== "file" && value.type !== "folder" || !isSafeFilename$1(value.name) || value.lifecycleState !== "active" || !isSafeInteger$1(value.revision) || (value.type === "folder" ? value.currentVersion !== null : !isCurrentVersionMetadata(value.currentVersion))) return false;
437
+ if (value.currentVersion !== null) Object.freeze(value.currentVersion);
438
+ Object.freeze(value);
439
+ return true;
440
+ }
441
+ function isWorkspaceItemSearchPage(value, workspaceId, query, limit) {
442
+ if (!isExactRecord(value, ["items", "nextCursor"]) || !Array.isArray(value.items) || value.items.length > limit || !value.items.every((item) => isWorkspaceItemSearchItem(item, workspaceId, query)) || !(value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length <= 699 && CURSOR$1.test(value.nextCursor)) || value.items.length === 0 && value.nextCursor !== null || new Set(value.items.map((item) => item.itemId)).size !== value.items.length || !isWorkspaceItemSearchOrder(value.items)) return false;
443
+ for (const item of value.items) {
444
+ if (item.currentVersion !== null) Object.freeze(item.currentVersion);
445
+ Object.freeze(item);
446
+ }
447
+ Object.freeze(value.items);
448
+ Object.freeze(value);
449
+ return true;
450
+ }
451
+ function itemEtagMatchesRevision(headers, revision) {
452
+ const etag = headers.get("etag");
453
+ return etag !== null && parseItemEtag(etag) === revision;
454
+ }
455
+ function isCurrentVersionMetadata(value) {
456
+ return isExactRecord(value, [
457
+ "versionId",
458
+ "state",
459
+ "byteLength",
460
+ "mediaType",
461
+ "protectionClassification"
462
+ ]) && typeof value.versionId === "string" && VERSION_ID$1.test(value.versionId) && value.state === "current" && isSafeInteger$1(value.byteLength) && isMediaType$1(value.mediaType) && (value.protectionClassification === "ordinary" || value.protectionClassification === "opaque-encrypted");
463
+ }
464
+ function isWorkspaceItemSearchItem(value, workspaceId, query) {
465
+ return isExactRecord(value, [
466
+ "workspaceId",
467
+ "volumeId",
468
+ "provider",
469
+ "itemId",
470
+ "parentId",
471
+ "type",
472
+ "name",
473
+ "lifecycleState",
474
+ "revision",
475
+ "currentVersion"
476
+ ]) && value.workspaceId === workspaceId && typeof value.volumeId === "string" && VOLUME_ID.test(value.volumeId) && value.provider === "managed" && typeof value.itemId === "string" && ITEM_ID$1.test(value.itemId) && (value.parentId === null || typeof value.parentId === "string" && ITEM_ID$1.test(value.parentId)) && (value.type === "file" || value.type === "folder") && isSafeFilename$1(value.name) && value.name.startsWith(query) && value.lifecycleState === "active" && isSafeInteger$1(value.revision) && (value.type === "folder" ? value.currentVersion === null : isCurrentVersionMetadata(value.currentVersion));
477
+ }
478
+ function isWorkspaceItemSearchOrder(items) {
479
+ for (let index = 1; index < items.length; index += 1) {
480
+ const previous = items[index - 1];
481
+ const current = items[index];
482
+ const nameOrder = compareBinary(previous.name, current.name);
483
+ if (nameOrder > 0 || nameOrder === 0 && previous.itemId >= current.itemId) return false;
484
+ }
485
+ return true;
486
+ }
487
+ function compareBinary(left, right) {
488
+ const leftBytes = UTF8.encode(left);
489
+ const rightBytes = UTF8.encode(right);
490
+ const length = Math.min(leftBytes.length, rightBytes.length);
491
+ for (let index = 0; index < length; index += 1) if (leftBytes[index] !== rightBytes[index]) return leftBytes[index] - rightBytes[index];
492
+ return leftBytes.length - rightBytes.length;
493
+ }
494
+ function isManagedItemVersionPage(value, limit) {
495
+ if (!isExactRecord(value, ["items", "nextCursor"]) || !Array.isArray(value.items) || value.items.length > limit || !value.items.every(isManagedItemVersion) || !(value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length <= 699 && CURSOR$1.test(value.nextCursor)) || value.nextCursor !== null && value.items.length === 0 || !isStrictlyOrdered(value.items, (version) => version.versionId)) return false;
496
+ for (const version of value.items) Object.freeze(version);
497
+ Object.freeze(value.items);
498
+ Object.freeze(value);
499
+ return true;
500
+ }
501
+ function isManagedItemVersionRestoreResult(value, versionId) {
502
+ if (!isExactRecord(value, ["itemRevision", "currentVersionId"]) || !isSafeInteger$1(value.itemRevision) || value.currentVersionId !== versionId) return false;
503
+ Object.freeze(value);
504
+ return true;
505
+ }
326
506
  function isPermissionPage(value, headers, targetItemId) {
327
507
  if (!(isExactRecord(value, [
328
508
  "items",
@@ -387,7 +567,7 @@ function isUploadSession(value, expectedByteLength) {
387
567
  "partCount",
388
568
  "revision",
389
569
  "expiresAtEpochMilliseconds"
390
- ]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID.test(value.versionId) || typeof value.uploadId !== "string" || !UPLOAD_ID$1.test(value.uploadId) || value.mode !== "presigned-multipart" && value.mode !== "server-mediated-zero-byte" || value.partByteLength !== UPLOAD_PART_BYTE_LENGTH$2 || !isSafeInteger$1(value.partCount) || value.partCount > 1e4 || value.partCount !== Math.ceil(expectedByteLength / UPLOAD_PART_BYTE_LENGTH$2) || (expectedByteLength === 0 ? value.mode !== "server-mediated-zero-byte" : value.mode !== "presigned-multipart") || !isSafeInteger$1(value.revision) || !isSafeInteger$1(value.expiresAtEpochMilliseconds) || value.expiresAtEpochMilliseconds <= Date.now()) return false;
570
+ ]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID$1.test(value.versionId) || typeof value.uploadId !== "string" || !UPLOAD_ID$1.test(value.uploadId) || value.mode !== "presigned-multipart" && value.mode !== "server-mediated-zero-byte" || value.partByteLength !== UPLOAD_PART_BYTE_LENGTH$2 || !isSafeInteger$1(value.partCount) || value.partCount > 1e4 || value.partCount !== Math.ceil(expectedByteLength / UPLOAD_PART_BYTE_LENGTH$2) || (expectedByteLength === 0 ? value.mode !== "server-mediated-zero-byte" : value.mode !== "presigned-multipart") || !isSafeInteger$1(value.revision) || !isSafeInteger$1(value.expiresAtEpochMilliseconds) || value.expiresAtEpochMilliseconds <= Date.now()) return false;
391
571
  Object.freeze(value);
392
572
  return true;
393
573
  }
@@ -404,7 +584,7 @@ function isUploadStatus(value, afterPartNumber, limit) {
404
584
  "nextAfterPartNumber",
405
585
  "expiresAtEpochMilliseconds",
406
586
  "ready"
407
- ]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID.test(value.versionId) || typeof value.uploadId !== "string" || !UPLOAD_ID$1.test(value.uploadId) || value.mode !== "presigned-multipart" && value.mode !== "server-mediated-zero-byte" || ![
587
+ ]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID$1.test(value.versionId) || typeof value.uploadId !== "string" || !UPLOAD_ID$1.test(value.uploadId) || value.mode !== "presigned-multipart" && value.mode !== "server-mediated-zero-byte" || ![
408
588
  "initiating",
409
589
  "recovery-required",
410
590
  "uploading",
@@ -458,13 +638,47 @@ function isReadyUpload(value, expected) {
458
638
  "displayFilename",
459
639
  "mediaType",
460
640
  "state"
461
- ]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID.test(value.versionId) || value.uploadId !== expected.uploadId || !isSafeInteger$1(value.byteLength) || value.byteLength < 0 || value.byteLength > MAX_UPLOAD_BYTE_LENGTH$1 || typeof value.callerDeclaredContentDigest !== "string" || !CONTENT_DIGEST$1.test(value.callerDeclaredContentDigest) || !isSafeFilename$1(value.displayFilename) || !isMediaType$1(value.mediaType) || value.state !== "ready" || expected.byteLength !== void 0 && value.byteLength !== expected.byteLength || expected.callerDeclaredContentDigest !== void 0 && value.callerDeclaredContentDigest !== expected.callerDeclaredContentDigest || expected.displayFilename !== void 0 && value.displayFilename !== expected.displayFilename || expected.mediaType !== void 0 && value.mediaType !== expected.mediaType) return false;
641
+ ]) || typeof value.itemId !== "string" || !ITEM_ID$1.test(value.itemId) || typeof value.versionId !== "string" || !VERSION_ID$1.test(value.versionId) || value.uploadId !== expected.uploadId || !isSafeInteger$1(value.byteLength) || value.byteLength < 0 || value.byteLength > MAX_UPLOAD_BYTE_LENGTH$1 || typeof value.callerDeclaredContentDigest !== "string" || !CONTENT_DIGEST$1.test(value.callerDeclaredContentDigest) || !isSafeFilename$1(value.displayFilename) || !isMediaType$1(value.mediaType) || value.state !== "ready" || expected.byteLength !== void 0 && value.byteLength !== expected.byteLength || expected.callerDeclaredContentDigest !== void 0 && value.callerDeclaredContentDigest !== expected.callerDeclaredContentDigest || expected.displayFilename !== void 0 && value.displayFilename !== expected.displayFilename || expected.mediaType !== void 0 && value.mediaType !== expected.mediaType) return false;
462
642
  Object.freeze(value);
463
643
  return true;
464
644
  }
465
645
  function isPartChecksum$1(value) {
466
646
  return typeof value === "string" && /^[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/.test(value);
467
647
  }
648
+ function isManagedItemVersion(value) {
649
+ const valid = isExactRecord(value, managedItemVersionKeys) && managedItemVersionFieldsAreValid(value);
650
+ if (valid) Object.freeze(value);
651
+ return valid;
652
+ }
653
+ function isManagedItemVersionResource(value, workspaceId, itemId, versionId) {
654
+ const valid = isExactRecord(value, [
655
+ ...managedItemVersionKeys,
656
+ "workspaceId",
657
+ "itemId"
658
+ ]) && value.workspaceId === workspaceId && value.itemId === itemId && value.versionId === versionId && managedItemVersionFieldsAreValid(value);
659
+ if (valid) Object.freeze(value);
660
+ return valid;
661
+ }
662
+ const managedItemVersionKeys = Object.freeze([
663
+ "versionId",
664
+ "state",
665
+ "revision",
666
+ "byteLength",
667
+ "contentDigest",
668
+ "mediaType",
669
+ "displayFilename",
670
+ "protectionClassification",
671
+ "archiveState"
672
+ ]);
673
+ function managedItemVersionFieldsAreValid(value) {
674
+ return typeof value.versionId === "string" && VERSION_ID$1.test(value.versionId) && (value.state === "current" || value.state === "superseded") && isSafeInteger$1(value.revision) && isSafeInteger$1(value.byteLength) && typeof value.contentDigest === "string" && CONTENT_DIGEST$1.test(value.contentDigest) && isMediaType$1(value.mediaType) && isSafeFilename$1(value.displayFilename) && (value.protectionClassification === "ordinary" || value.protectionClassification === "opaque-encrypted") && [
675
+ "available",
676
+ "cold",
677
+ "restoring",
678
+ "unavailable",
679
+ "corrupt"
680
+ ].includes(String(value.archiveState));
681
+ }
468
682
  function mutationValidatorsAreCoherent(headers) {
469
683
  const collection = headers.get("drive-permission-collection-etag");
470
684
  const grant = headers.get("drive-permission-grant-etag");
@@ -551,6 +765,22 @@ function isStrictlyOrdered(values, key) {
551
765
  function isSafeInteger$1(value) {
552
766
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
553
767
  }
768
+ function isStrongEtag(value) {
769
+ return /^"[\x21\x23-\x7e]{1,1022}"$/.test(value);
770
+ }
771
+ function isSafeCapabilityUrl(value) {
772
+ try {
773
+ const url = new URL(value);
774
+ const localHttp = url.protocol === "http:" && [
775
+ "localhost",
776
+ "127.0.0.1",
777
+ "[::1]"
778
+ ].includes(url.hostname);
779
+ return (url.protocol === "https:" || localHttp) && !url.username && !url.password && !url.hash;
780
+ } catch {
781
+ return false;
782
+ }
783
+ }
554
784
  function isExactRecord(value, keys) {
555
785
  if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
556
786
  return Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
@@ -561,6 +791,7 @@ const ITEM_ID = /^drive\.item\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-
561
791
  const WORKSPACE_ID = /^drive\.workspace\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
562
792
  const GRANT_ID = /^drive\.grant\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
563
793
  const UPLOAD_ID = /^drive\.upload\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
794
+ const VERSION_ID = /^drive\.version\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
564
795
  const CURSOR = /^drive\.cursor\.v1\.[A-Za-z0-9_-]+$/;
565
796
  const AUTH_ID = /^[A-Za-z0-9_-]{1,128}$/;
566
797
  const PERMISSION_ACTIONS = Object.freeze([
@@ -592,6 +823,71 @@ function validateResourceInput(value) {
592
823
  ...signal === void 0 ? {} : { signal }
593
824
  };
594
825
  }
826
+ function validateItemVersionInput(value) {
827
+ const input = captureRecord(value, [
828
+ "workspaceId",
829
+ "itemId",
830
+ "versionId"
831
+ ], ["signal"]);
832
+ const resource = validateResourceInput({
833
+ workspaceId: input.workspaceId,
834
+ itemId: input.itemId,
835
+ ...input.signal === void 0 ? {} : { signal: input.signal }
836
+ });
837
+ if (typeof input.versionId !== "string" || !VERSION_ID.test(input.versionId)) throw new DriveError("invalid_input");
838
+ return {
839
+ ...resource,
840
+ versionId: input.versionId
841
+ };
842
+ }
843
+ function validateCreateDownloadInput(value) {
844
+ const input = captureRecord(value, [
845
+ "workspaceId",
846
+ "itemId",
847
+ "idempotencyKey"
848
+ ], [
849
+ "versionId",
850
+ "method",
851
+ "range",
852
+ "ifMatch",
853
+ "ifNoneMatch",
854
+ "ifRange",
855
+ "signal"
856
+ ]);
857
+ const resource = validateResourceInput({
858
+ workspaceId: input.workspaceId,
859
+ itemId: input.itemId,
860
+ ...input.signal === void 0 ? {} : { signal: input.signal }
861
+ });
862
+ const method = input.method ?? "GET";
863
+ if (!isIdempotencyKey(input.idempotencyKey) || input.versionId !== void 0 && (typeof input.versionId !== "string" || !VERSION_ID.test(input.versionId)) || method !== "GET" && method !== "HEAD" || input.range !== void 0 && (typeof input.range !== "string" || input.range.length > 128 || !/^bytes=(?:[0-9]+-[0-9]*|-[0-9]+)$/.test(input.range)) || !isOptionalHeaderValue(input.ifMatch) || !isOptionalHeaderValue(input.ifNoneMatch) || !isOptionalHeaderValue(input.ifRange)) throw new DriveError("invalid_input");
864
+ return {
865
+ ...resource,
866
+ idempotencyKey: input.idempotencyKey,
867
+ method,
868
+ ...input.versionId === void 0 ? {} : { versionId: input.versionId },
869
+ ...input.range === void 0 ? {} : { range: input.range },
870
+ ...input.ifMatch === void 0 ? {} : { ifMatch: input.ifMatch },
871
+ ...input.ifNoneMatch === void 0 ? {} : { ifNoneMatch: input.ifNoneMatch },
872
+ ...input.ifRange === void 0 ? {} : { ifRange: input.ifRange }
873
+ };
874
+ }
875
+ function validateSearchWorkspaceItemsInput(value) {
876
+ const input = captureRecord(value, ["workspaceId", "query"], [
877
+ "limit",
878
+ "cursor",
879
+ "signal"
880
+ ]);
881
+ const signal = validateSignal(input.signal);
882
+ if (typeof input.workspaceId !== "string" || !WORKSPACE_ID.test(input.workspaceId) || !isSearchQuery(input.query) || input.limit !== void 0 && (!isSafeInteger(input.limit) || input.limit < 1 || input.limit > 50) || input.cursor !== void 0 && (typeof input.cursor !== "string" || input.cursor.length > 699 || !CURSOR.test(input.cursor))) throw new DriveError("invalid_input");
883
+ return {
884
+ workspaceId: input.workspaceId,
885
+ query: input.query,
886
+ ...input.limit === void 0 ? {} : { limit: input.limit },
887
+ ...input.cursor === void 0 ? {} : { cursor: input.cursor },
888
+ ...signal === void 0 ? {} : { signal }
889
+ };
890
+ }
595
891
  function validatePageInput(value) {
596
892
  const input = captureRecord(value, ["workspaceId", "itemId"], [
597
893
  "signal",
@@ -631,6 +927,69 @@ function validateCreateFolderInput(value) {
631
927
  idempotencyKey: input.idempotencyKey
632
928
  };
633
929
  }
930
+ function validateUpdateItemInput(value) {
931
+ const input = captureRecord(value, [
932
+ "workspaceId",
933
+ "itemId",
934
+ "name",
935
+ "parentItemId",
936
+ "idempotencyKey",
937
+ "ifMatch"
938
+ ], ["signal"]);
939
+ const mutation = validateLifecycleMutationInput({
940
+ workspaceId: input.workspaceId,
941
+ itemId: input.itemId,
942
+ idempotencyKey: input.idempotencyKey,
943
+ ifMatch: input.ifMatch,
944
+ ...input.signal === void 0 ? {} : { signal: input.signal }
945
+ });
946
+ if (!isSafeFilename(input.name) || typeof input.parentItemId !== "string" || !ITEM_ID.test(input.parentItemId)) throw new DriveError("invalid_input");
947
+ return {
948
+ ...mutation,
949
+ name: input.name,
950
+ parentItemId: input.parentItemId
951
+ };
952
+ }
953
+ function validateLifecycleMutationInput(value) {
954
+ const input = captureRecord(value, [
955
+ "workspaceId",
956
+ "itemId",
957
+ "idempotencyKey",
958
+ "ifMatch"
959
+ ], ["signal"]);
960
+ const resource = validateResourceInput({
961
+ workspaceId: input.workspaceId,
962
+ itemId: input.itemId,
963
+ ...input.signal === void 0 ? {} : { signal: input.signal }
964
+ });
965
+ if (!isIdempotencyKey(input.idempotencyKey) || typeof input.ifMatch !== "string" || parseItemEtag(input.ifMatch) === void 0) throw new DriveError("invalid_input");
966
+ return {
967
+ ...resource,
968
+ idempotencyKey: input.idempotencyKey,
969
+ ifMatch: input.ifMatch
970
+ };
971
+ }
972
+ function validateRestoreItemVersionInput(value) {
973
+ const input = captureRecord(value, [
974
+ "workspaceId",
975
+ "itemId",
976
+ "versionId",
977
+ "idempotencyKey",
978
+ "ifMatch"
979
+ ], ["signal"]);
980
+ const mutation = validateLifecycleMutationInput({
981
+ workspaceId: input.workspaceId,
982
+ itemId: input.itemId,
983
+ idempotencyKey: input.idempotencyKey,
984
+ ifMatch: input.ifMatch,
985
+ ...input.signal === void 0 ? {} : { signal: input.signal }
986
+ });
987
+ if (typeof input.versionId !== "string" || !VERSION_ID.test(input.versionId)) throw new DriveError("invalid_input");
988
+ return {
989
+ ...mutation,
990
+ versionId: input.versionId
991
+ };
992
+ }
634
993
  function validateCreatePermissionInput(value) {
635
994
  const input = captureRecord(value, [
636
995
  "workspaceId",
@@ -948,6 +1307,24 @@ function isEtag$1(value) {
948
1307
  function isMediaType(value) {
949
1308
  return typeof value === "string" && value.length <= 255 && /^[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?\/[a-z0-9](?:[a-z0-9!#$&^_.+-]{0,125}[a-z0-9])?$/.test(value);
950
1309
  }
1310
+ function isSearchQuery(value) {
1311
+ if (typeof value !== "string" || value.length === 0) return false;
1312
+ try {
1313
+ if (value.normalize("NFC") !== value) return false;
1314
+ let codePoints = 0;
1315
+ let bytes = 0;
1316
+ for (const character of value) {
1317
+ const point = character.codePointAt(0);
1318
+ if (point === void 0 || point <= 31 || point >= 127 && point <= 159 || point === 8232 || point === 8233 || point >= 55296 && point <= 57343) return false;
1319
+ codePoints += 1;
1320
+ bytes += point <= 127 ? 1 : point <= 2047 ? 2 : point <= 65535 ? 3 : 4;
1321
+ if (codePoints > 64 || bytes > 255) return false;
1322
+ }
1323
+ return true;
1324
+ } catch {
1325
+ return false;
1326
+ }
1327
+ }
951
1328
  function isExpiry(value) {
952
1329
  return value === null || isSafeInteger(value);
953
1330
  }
@@ -979,6 +1356,12 @@ function filenameIsReserved(value) {
979
1356
  function isSafeInteger(value) {
980
1357
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
981
1358
  }
1359
+ function isOptionalHeaderValue(value) {
1360
+ return value === void 0 || typeof value === "string" && value.length <= 8192 && !value.split("").some((character) => {
1361
+ const code = character.charCodeAt(0);
1362
+ return code <= 31 || code === 127;
1363
+ });
1364
+ }
982
1365
  //#endregion
983
1366
  //#region ../../node_modules/.pnpm/openapi-fetch@0.17.0/node_modules/openapi-fetch/dist/index.mjs
984
1367
  const PATH_PARAM_RE = /\{[^{}]+\}/g;
@@ -1397,7 +1780,7 @@ function createClientRuntime(config) {
1397
1780
  try {
1398
1781
  runtime = Object.freeze({
1399
1782
  baseUrl: parseBaseUrl(config.baseUrl),
1400
- fetchImplementation: config.fetch ?? globalThis.fetch,
1783
+ fetchImplementation: config.fetch ?? globalThis.fetch.bind(globalThis),
1401
1784
  getCredential: config.getCredential,
1402
1785
  timeoutMilliseconds: parseTimeoutMilliseconds(config.timeoutMilliseconds)
1403
1786
  });
@@ -1522,6 +1905,25 @@ const CURRENT_WORKSPACE_ERROR_CODES = Object.freeze([
1522
1905
  "invalid_request",
1523
1906
  "service_unavailable"
1524
1907
  ]);
1908
+ const GET_ITEM_ERROR_CODES = Object.freeze([
1909
+ "authentication_required",
1910
+ "identity_authority_unavailable",
1911
+ "permission_denied",
1912
+ "resource_not_found",
1913
+ "invalid_request",
1914
+ "precondition_failed",
1915
+ "service_unavailable"
1916
+ ]);
1917
+ const SEARCH_WORKSPACE_ITEMS_ERROR_CODES = Object.freeze([
1918
+ "authentication_required",
1919
+ "identity_authority_unavailable",
1920
+ "permission_denied",
1921
+ "resource_not_found",
1922
+ "invalid_request",
1923
+ "invalid_pagination_cursor",
1924
+ "precondition_failed",
1925
+ "service_unavailable"
1926
+ ]);
1525
1927
  const TRANSFER_ERROR_CODES = Object.freeze([
1526
1928
  "authentication_required",
1527
1929
  "identity_authority_unavailable",
@@ -1547,11 +1949,54 @@ const CREATE_UPLOAD_ERROR_CODES = Object.freeze([
1547
1949
  "quota_exceeded"
1548
1950
  ]);
1549
1951
  const COMPLETE_UPLOAD_ERROR_CODES = Object.freeze([...TRANSFER_ERROR_CODES, "invalid_idempotency_key"]);
1952
+ const LIFECYCLE_MUTATION_ERROR_CODES = Object.freeze([
1953
+ "authentication_required",
1954
+ "identity_authority_unavailable",
1955
+ "permission_denied",
1956
+ "resource_not_found",
1957
+ "invalid_request",
1958
+ "invalid_idempotency_key",
1959
+ "idempotency_conflict",
1960
+ "precondition_failed",
1961
+ "service_unavailable"
1962
+ ]);
1963
+ const LIST_ITEM_VERSIONS_ERROR_CODES = Object.freeze([
1964
+ "authentication_required",
1965
+ "identity_authority_unavailable",
1966
+ "permission_denied",
1967
+ "resource_not_found",
1968
+ "invalid_request",
1969
+ "precondition_failed",
1970
+ "service_unavailable"
1971
+ ]);
1972
+ const DOWNLOAD_ERROR_CODES = Object.freeze([
1973
+ "authentication_required",
1974
+ "identity_authority_unavailable",
1975
+ "permission_denied",
1976
+ "resource_not_found",
1977
+ "invalid_request",
1978
+ "invalid_idempotency_key",
1979
+ "idempotency_conflict",
1980
+ "precondition_failed",
1981
+ "range_not_satisfiable",
1982
+ "service_unavailable"
1983
+ ]);
1550
1984
  function createDriveOperations(runtime) {
1551
1985
  return Object.freeze({
1552
1986
  getCurrentWorkspace: (input) => getCurrentWorkspace(runtime, input),
1987
+ getItem: (input) => getItem(runtime, input),
1988
+ searchWorkspaceItems: (input) => searchWorkspaceItems(runtime, input),
1553
1989
  listFolderChildren: (input) => listFolderChildren(runtime, input),
1554
1990
  createFolder: (input) => createFolder(runtime, input),
1991
+ updateItem: (input) => updateItem(runtime, input),
1992
+ trashItem: (input) => trashItem(runtime, input),
1993
+ restoreItem: (input) => restoreItem(runtime, input),
1994
+ deleteItem: (input) => deleteItem(runtime, input),
1995
+ listItemVersions: (input) => listItemVersions(runtime, input),
1996
+ getItemVersion: (input) => getItemVersion(runtime, input),
1997
+ restoreItemVersion: (input) => restoreItemVersion(runtime, input),
1998
+ createDownload: (input) => createDownload(runtime, input),
1999
+ downloadItem: (input) => downloadItem(runtime, input),
1555
2000
  listItemPermissions: (input) => listItemPermissions(runtime, input),
1556
2001
  readEffectiveItemPermissions: (input) => readEffectiveItemPermissions(runtime, input),
1557
2002
  createItemPermission: (input) => createItemPermission(runtime, input),
@@ -1565,12 +2010,205 @@ function createDriveOperations(runtime) {
1565
2010
  abortUpload: (input) => abortUpload(runtime, input)
1566
2011
  });
1567
2012
  }
2013
+ async function createDownload(runtime, input) {
2014
+ const validated = validateCreateDownloadInput(input);
2015
+ return execute(runtime, validated.signal, 412, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/downloads", {
2016
+ ...operationOptions("createDownload", { params: {
2017
+ path: {
2018
+ workspaceId: validated.workspaceId,
2019
+ itemId: validated.itemId
2020
+ },
2021
+ query: validated.versionId === void 0 ? {} : { versionId: validated.versionId },
2022
+ header: {
2023
+ "Idempotency-Key": validated.idempotencyKey,
2024
+ "Download-Method": validated.method,
2025
+ ...validated.range === void 0 ? {} : { Range: validated.range },
2026
+ ...validated.ifMatch === void 0 ? {} : { "If-Match": validated.ifMatch },
2027
+ ...validated.ifNoneMatch === void 0 ? {} : { "If-None-Match": validated.ifNoneMatch },
2028
+ ...validated.ifRange === void 0 ? {} : { "If-Range": validated.ifRange }
2029
+ }
2030
+ } }),
2031
+ ...requestOptions
2032
+ }), [
2033
+ 200,
2034
+ 202,
2035
+ 304
2036
+ ], (value, status) => status === 200 ? isManagedDownloadDescriptor(value) : status === 202 ? isManagedDownloadRestorePending(value) : value === void 0, false, DOWNLOAD_ERROR_CODES);
2037
+ }
2038
+ async function downloadItem(runtime, input) {
2039
+ const validated = validateCreateDownloadInput(input);
2040
+ const created = await createDownload(runtime, input);
2041
+ if (created.status === 202 || created.status === 304) return created;
2042
+ const descriptor = created.data;
2043
+ if (descriptor.expiresAtEpochMilliseconds <= Date.now()) throw new DriveError("invalid_response");
2044
+ const operation = createOperationSignal(validated.signal, runtime.timeoutMilliseconds);
2045
+ try {
2046
+ const response = await raceWithAbort(runtime.fetchImplementation(directDownloadRequest(descriptor, operation.signal)), operation.signal);
2047
+ if (!responseMatchesDownloadDescriptor(response, descriptor)) {
2048
+ await response.body?.cancel().catch(() => void 0);
2049
+ throw new DriveError("invalid_response");
2050
+ }
2051
+ const responseHeaders = downloadResponseHeaders(descriptor);
2052
+ if (descriptor.method === "HEAD") {
2053
+ await response.body?.cancel().catch(() => void 0);
2054
+ operation.dispose();
2055
+ return new Response(null, {
2056
+ status: response.status,
2057
+ headers: responseHeaders
2058
+ });
2059
+ }
2060
+ if (!response.body) {
2061
+ operation.dispose();
2062
+ if (descriptor.response.contentLength !== 0) throw new DriveError("invalid_response");
2063
+ return new Response(null, {
2064
+ status: response.status,
2065
+ headers: responseHeaders
2066
+ });
2067
+ }
2068
+ operation.dispose();
2069
+ return new Response(streamWithOperationLifetime(response.body, descriptor.response.contentLength, validated.signal), {
2070
+ status: response.status,
2071
+ headers: responseHeaders
2072
+ });
2073
+ } catch (error) {
2074
+ operation.dispose();
2075
+ if (operation.didTimeout()) throw new DriveError("timeout");
2076
+ if (error instanceof DriveError) throw error;
2077
+ throw operation.signal.aborted ? new DriveError(operation.didTimeout() ? "timeout" : "aborted") : new DriveError("network_error");
2078
+ }
2079
+ }
2080
+ function downloadResponseHeaders(descriptor) {
2081
+ const expected = descriptor.response;
2082
+ const headers = new Headers();
2083
+ headers.set("accept-ranges", expected.acceptRanges);
2084
+ headers.set("content-disposition", expected.contentDisposition);
2085
+ headers.set("content-length", String(expected.contentLength));
2086
+ headers.set("content-type", expected.contentType);
2087
+ headers.set("etag", expected.etag);
2088
+ if (expected.contentRange === null) headers.delete("content-range");
2089
+ else headers.set("content-range", expected.contentRange);
2090
+ return headers;
2091
+ }
2092
+ function directDownloadRequest(descriptor, signal) {
2093
+ const base = {
2094
+ method: descriptor.method,
2095
+ headers: descriptor.headers,
2096
+ redirect: "manual",
2097
+ signal
2098
+ };
2099
+ try {
2100
+ return new Request(descriptor.url, {
2101
+ ...base,
2102
+ cache: "no-store",
2103
+ credentials: "omit",
2104
+ referrerPolicy: "no-referrer"
2105
+ });
2106
+ } catch {
2107
+ try {
2108
+ return new Request(descriptor.url, {
2109
+ ...base,
2110
+ credentials: "omit",
2111
+ referrerPolicy: "no-referrer"
2112
+ });
2113
+ } catch {
2114
+ return new Request(descriptor.url, {
2115
+ ...base,
2116
+ credentials: "omit"
2117
+ });
2118
+ }
2119
+ }
2120
+ }
2121
+ function responseMatchesDownloadDescriptor(response, descriptor) {
2122
+ const expected = descriptor.response;
2123
+ const encoding = response.headers.get("content-encoding");
2124
+ return response.status === expected.status && response.headers.get("etag") === expected.etag && response.headers.get("content-length") === String(expected.contentLength) && (encoding === null || encoding === "identity") && (expected.contentRange === null ? response.headers.get("content-range") === null : response.headers.get("content-range") === expected.contentRange);
2125
+ }
2126
+ function streamWithOperationLifetime(source, expectedLength, signal) {
2127
+ const reader = source.getReader();
2128
+ let receivedLength = 0;
2129
+ let finished = false;
2130
+ let removeAbort = () => {};
2131
+ return new ReadableStream({
2132
+ start(controller) {
2133
+ if (!signal) return;
2134
+ const onAbort = () => {
2135
+ if (finished) return;
2136
+ finished = true;
2137
+ removeAbort();
2138
+ reader.cancel().catch(() => void 0);
2139
+ controller.error(new DriveError("aborted"));
2140
+ };
2141
+ if (signal.aborted) onAbort();
2142
+ else {
2143
+ signal.addEventListener("abort", onAbort, { once: true });
2144
+ removeAbort = () => signal.removeEventListener("abort", onAbort);
2145
+ }
2146
+ },
2147
+ async pull(controller) {
2148
+ if (finished) return;
2149
+ try {
2150
+ const chunk = await reader.read();
2151
+ if (finished) return;
2152
+ if (chunk.done) {
2153
+ finished = true;
2154
+ removeAbort();
2155
+ reader.releaseLock();
2156
+ if (receivedLength === expectedLength) controller.close();
2157
+ else controller.error(new DriveError("invalid_response"));
2158
+ } else {
2159
+ receivedLength += chunk.value.byteLength;
2160
+ if (!Number.isSafeInteger(receivedLength) || receivedLength > expectedLength) {
2161
+ finished = true;
2162
+ removeAbort();
2163
+ await reader.cancel().catch(() => void 0);
2164
+ controller.error(new DriveError("invalid_response"));
2165
+ return;
2166
+ }
2167
+ controller.enqueue(chunk.value);
2168
+ }
2169
+ } catch (error) {
2170
+ if (finished) return;
2171
+ finished = true;
2172
+ removeAbort();
2173
+ await reader.cancel().catch(() => void 0);
2174
+ controller.error(error instanceof DriveError ? error : signal?.aborted ? new DriveError("aborted") : new DriveError("network_error"));
2175
+ }
2176
+ },
2177
+ async cancel(reason) {
2178
+ if (finished) return;
2179
+ finished = true;
2180
+ removeAbort();
2181
+ await reader.cancel(reason).catch(() => void 0);
2182
+ }
2183
+ });
2184
+ }
1568
2185
  async function getCurrentWorkspace(runtime, input) {
1569
2186
  return execute(runtime, validateCurrentWorkspaceInput(input).signal, null, (api, requestOptions) => api.GET("/api/v1/workspaces/current", {
1570
2187
  ...operationOptions("getCurrentWorkspace", { params: {} }),
1571
2188
  ...requestOptions
1572
2189
  }), [200], isCurrentWorkspace, false, CURRENT_WORKSPACE_ERROR_CODES);
1573
2190
  }
2191
+ async function getItem(runtime, input) {
2192
+ const validated = validateResourceInput(input);
2193
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}", {
2194
+ ...operationOptions("getItem", { params: { path: resourcePath(validated) } }),
2195
+ ...requestOptions
2196
+ }), [200], (value, _status, headers) => isManagedItemMetadata(value, validated.workspaceId, validated.itemId) && itemEtagMatchesRevision(headers, value.revision), false, GET_ITEM_ERROR_CODES);
2197
+ }
2198
+ async function searchWorkspaceItems(runtime, input) {
2199
+ const validated = validateSearchWorkspaceItemsInput(input);
2200
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/search", {
2201
+ ...operationOptions("searchWorkspaceItems", { params: {
2202
+ path: { workspaceId: validated.workspaceId },
2203
+ query: {
2204
+ query: validated.query,
2205
+ ...validated.limit === void 0 ? {} : { limit: validated.limit },
2206
+ ...validated.cursor === void 0 ? {} : { cursor: validated.cursor }
2207
+ }
2208
+ } }),
2209
+ ...requestOptions
2210
+ }), [200], (value) => isWorkspaceItemSearchPage(value, validated.workspaceId, validated.query, validated.limit ?? 50), false, SEARCH_WORKSPACE_ITEMS_ERROR_CODES);
2211
+ }
1574
2212
  async function listFolderChildren(runtime, input) {
1575
2213
  const validated = validatePageInput(input);
1576
2214
  return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/children", {
@@ -1594,6 +2232,100 @@ async function createFolder(runtime, input) {
1594
2232
  ...requestOptions
1595
2233
  }), [200, 201], (value) => isFolderItem(value) && value.workspaceId === validated.workspaceId && value.parentItemId === validated.itemId && value.kind === "folder" && value.name === validated.name);
1596
2234
  }
2235
+ async function updateItem(runtime, input) {
2236
+ const validated = validateUpdateItemInput(input);
2237
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.PATCH("/api/v1/workspaces/{workspaceId}/items/{itemId}", {
2238
+ ...operationOptions("updateItem", {
2239
+ params: {
2240
+ path: resourcePath(validated),
2241
+ header: {
2242
+ "Idempotency-Key": validated.idempotencyKey,
2243
+ "If-Match": validated.ifMatch
2244
+ }
2245
+ },
2246
+ body: {
2247
+ name: validated.name,
2248
+ parentItemId: validated.parentItemId
2249
+ }
2250
+ }),
2251
+ ...requestOptions
2252
+ }), [200], (value, _status, headers) => isManagedLifecycleItem(value, validated.workspaceId, validated.itemId, "active") && value.name === validated.name && value.parentItemId === validated.parentItemId && itemEtagMatchesRevision(headers, value.revision), false, LIFECYCLE_MUTATION_ERROR_CODES);
2253
+ }
2254
+ async function trashItem(runtime, input) {
2255
+ const validated = validateLifecycleMutationInput(input);
2256
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/trash", {
2257
+ ...operationOptions("trashItem", { params: {
2258
+ path: resourcePath(validated),
2259
+ header: {
2260
+ "Idempotency-Key": validated.idempotencyKey,
2261
+ "If-Match": validated.ifMatch
2262
+ }
2263
+ } }),
2264
+ ...requestOptions
2265
+ }), [200], (value, _status, headers) => isManagedLifecycleItem(value, validated.workspaceId, validated.itemId, "trashed") && itemEtagMatchesRevision(headers, value.revision), false, LIFECYCLE_MUTATION_ERROR_CODES);
2266
+ }
2267
+ async function restoreItem(runtime, input) {
2268
+ const validated = validateLifecycleMutationInput(input);
2269
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/restore", {
2270
+ ...operationOptions("restoreItem", { params: {
2271
+ path: resourcePath(validated),
2272
+ header: {
2273
+ "Idempotency-Key": validated.idempotencyKey,
2274
+ "If-Match": validated.ifMatch
2275
+ }
2276
+ } }),
2277
+ ...requestOptions
2278
+ }), [200], (value, _status, headers) => isManagedLifecycleItem(value, validated.workspaceId, validated.itemId, "active") && itemEtagMatchesRevision(headers, value.revision), false, LIFECYCLE_MUTATION_ERROR_CODES);
2279
+ }
2280
+ async function deleteItem(runtime, input) {
2281
+ const validated = validateLifecycleMutationInput(input);
2282
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.DELETE("/api/v1/workspaces/{workspaceId}/items/{itemId}", {
2283
+ ...operationOptions("deleteItem", { params: {
2284
+ path: resourcePath(validated),
2285
+ header: {
2286
+ "Idempotency-Key": validated.idempotencyKey,
2287
+ "If-Match": validated.ifMatch
2288
+ }
2289
+ } }),
2290
+ ...requestOptions
2291
+ }), [200, 202], (value, _status, headers) => isManagedLifecycleItem(value, validated.workspaceId, validated.itemId, "deleting") && itemEtagMatchesRevision(headers, value.revision), false, LIFECYCLE_MUTATION_ERROR_CODES);
2292
+ }
2293
+ async function listItemVersions(runtime, input) {
2294
+ const validated = validatePageInput(input);
2295
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/versions", {
2296
+ ...operationOptions("listItemVersions", { params: {
2297
+ path: resourcePath(validated),
2298
+ query: pageQuery(validated)
2299
+ } }),
2300
+ ...requestOptions
2301
+ }), [200], (value) => isManagedItemVersionPage(value, validated.limit ?? 50), false, LIST_ITEM_VERSIONS_ERROR_CODES);
2302
+ }
2303
+ async function getItemVersion(runtime, input) {
2304
+ const validated = validateItemVersionInput(input);
2305
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}", {
2306
+ ...operationOptions("getItemVersion", { params: { path: {
2307
+ ...resourcePath(validated),
2308
+ versionId: validated.versionId
2309
+ } } }),
2310
+ ...requestOptions
2311
+ }), [200], (value) => isManagedItemVersionResource(value, validated.workspaceId, validated.itemId, validated.versionId), false, LIST_ITEM_VERSIONS_ERROR_CODES);
2312
+ }
2313
+ async function restoreItemVersion(runtime, input) {
2314
+ const validated = validateRestoreItemVersionInput(input);
2315
+ return execute(runtime, validated.signal, 409, (api, requestOptions) => api.POST("/api/v1/workspaces/{workspaceId}/items/{itemId}/versions/{versionId}/restore", {
2316
+ ...operationOptions("restoreItemVersion", { params: {
2317
+ path: {
2318
+ ...resourcePath(validated),
2319
+ versionId: validated.versionId
2320
+ },
2321
+ header: {
2322
+ "Idempotency-Key": validated.idempotencyKey,
2323
+ "If-Match": validated.ifMatch
2324
+ }
2325
+ } }),
2326
+ ...requestOptions
2327
+ }), [200], (value, _status, headers) => isManagedItemVersionRestoreResult(value, validated.versionId) && itemEtagMatchesRevision(headers, value.itemRevision), false, LIFECYCLE_MUTATION_ERROR_CODES);
2328
+ }
1597
2329
  async function listItemPermissions(runtime, input) {
1598
2330
  const validated = validatePageInput(input);
1599
2331
  return execute(runtime, validated.signal, 412, (api, requestOptions) => api.GET("/api/v1/workspaces/{workspaceId}/items/{itemId}/permissions", {