@edgestore/sdk 1.0.0-next.1 → 1.0.0-next.2
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/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -1
- package/dist/generated/api-v2.d.ts +71 -26
- package/dist/generated/api-v2.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/managementUploadOperations.d.ts +64 -0
- package/dist/internal/managementUploadOperations.d.ts.map +1 -0
- package/dist/internal/managementUploadOperations.js +72 -0
- package/dist/internal/multipartUpload.d.ts +6 -6
- package/dist/internal/multipartUpload.d.ts.map +1 -1
- package/dist/internal/runtimeOperations.d.ts.map +1 -1
- package/dist/internal/transport.d.ts.map +1 -1
- package/dist/internal/transport.js +20 -7
- package/dist/internal/uploadLifecycle.d.ts +57 -0
- package/dist/internal/uploadLifecycle.d.ts.map +1 -0
- package/dist/internal/uploadLifecycle.js +91 -0
- package/dist/internal/uploadProcessing.d.ts +20 -0
- package/dist/internal/uploadProcessing.d.ts.map +1 -0
- package/dist/internal/uploadProcessing.js +25 -0
- package/dist/internal/uploadSource.d.ts +18 -0
- package/dist/internal/uploadSource.d.ts.map +1 -0
- package/dist/internal/uploadSource.js +75 -0
- package/dist/internal/uploadTransfer.js +15 -1
- package/dist/managementClient.d.ts +2 -1
- package/dist/managementClient.d.ts.map +1 -1
- package/dist/managementClient.js +2 -2
- package/dist/managementResources.d.ts +5 -1
- package/dist/managementResources.d.ts.map +1 -1
- package/dist/managementResources.js +14 -49
- package/dist/managementUpload.d.ts +36 -0
- package/dist/managementUpload.d.ts.map +1 -0
- package/dist/managementUpload.js +74 -0
- package/dist/sdk.js +1 -1
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +42 -189
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/src/errors.ts +28 -0
- package/src/generated/api-v2.ts +71 -26
- package/src/generated/openapi-v2.json +237 -16
- package/src/generated/source.ts +2 -2
- package/src/index.ts +6 -0
- package/src/internal/managementUploadOperations.ts +99 -0
- package/src/internal/multipartUpload.ts +8 -8
- package/src/internal/transport.ts +21 -12
- package/src/internal/uploadLifecycle.ts +154 -0
- package/src/internal/uploadProcessing.ts +48 -0
- package/src/internal/uploadSource.ts +104 -0
- package/src/internal/uploadTransfer.ts +20 -1
- package/src/managementClient.ts +6 -2
- package/src/managementResources.ts +21 -51
- package/src/managementUpload.ts +139 -0
- package/src/sdk.ts +1 -1
- package/src/upload.ts +49 -274
- package/src/version.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type { BearerCredentials, EdgeStoreCredentials, ProjectCredentials, } from './credentials.js';
|
|
2
|
-
export { EdgeStoreAbortError, EdgeStoreApiError, EdgeStoreError, EdgeStoreFileMutationError, EdgeStoreNetworkError, EdgeStoreUploadCanceledError, EdgeStoreUploadError, EdgeStoreUploadProcessingTimeoutError, } from './errors.js';
|
|
2
|
+
export { EdgeStoreAbortError, EdgeStoreApiError, EdgeStoreError, EdgeStoreFileMutationError, EdgeStoreNetworkError, EdgeStoreTimeoutError, EdgeStoreUploadCanceledError, EdgeStoreUploadCleanupError, EdgeStoreUploadError, EdgeStoreUploadProcessingTimeoutError, } from './errors.js';
|
|
3
3
|
export type { ManagementClient } from './managementClient.js';
|
|
4
|
+
export type { ManagementUploadInput, ManagementUploadResult, } from './managementUpload.js';
|
|
4
5
|
export { planMultipartUpload, type MultipartUploadPlan, type MultipartUploadPlanOptions, } from './multipartPlan.js';
|
|
5
6
|
export { createEdgeStoreSdk, type EdgeStoreSdkOptions, type ManagementEdgeStoreSdk, type ProjectEdgeStoreSdk, } from './sdk.js';
|
|
6
7
|
export type { SystemClient } from './system.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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AAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,uBAAuB,EACvB,kCAAkC,EAClC,mCAAmC,EACnC,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,qBAAqB,EACrB,sBAAsB,EACtB,6BAA6B,EAC7B,8BAA8B,EAC9B,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,6BAA6B,EAC7B,iCAAiC,EACjC,iCAAiC,EACjC,6BAA6B,EAC7B,mBAAmB,EACnB,6BAA6B,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { EdgeStoreAbortError, EdgeStoreApiError, EdgeStoreError, EdgeStoreFileMutationError, EdgeStoreNetworkError, EdgeStoreUploadCanceledError, EdgeStoreUploadError, EdgeStoreUploadProcessingTimeoutError } from './errors.js';
|
|
1
|
+
export { EdgeStoreAbortError, EdgeStoreApiError, EdgeStoreError, EdgeStoreFileMutationError, EdgeStoreNetworkError, EdgeStoreTimeoutError, EdgeStoreUploadCanceledError, EdgeStoreUploadCleanupError, EdgeStoreUploadError, EdgeStoreUploadProcessingTimeoutError } from './errors.js';
|
|
2
2
|
export { planMultipartUpload } from './multipartPlan.js';
|
|
3
3
|
export { createEdgeStoreSdk } from './sdk.js';
|
|
4
4
|
export { DEFAULT_MULTIPART_CONCURRENCY, DEFAULT_MULTIPART_PART_SIZE_BYTES, DEFAULT_MULTIPART_THRESHOLD_BYTES, DEFAULT_PROCESSING_TIMEOUT_MS, MAX_MULTIPART_PARTS, MIN_MULTIPART_PART_SIZE_BYTES } from './uploadTypes.js';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { OperationBody, OperationResult } from './operationTypes.js';
|
|
2
|
+
import type { Transport } from './transport.js';
|
|
3
|
+
type ProjectUploadInput = {
|
|
4
|
+
project: string;
|
|
5
|
+
uploadId: string;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
};
|
|
8
|
+
export type ManagementUploadOperations = ReturnType<typeof createManagementUploadOperations>;
|
|
9
|
+
export declare function createManagementUploadOperations(transport: Transport): {
|
|
10
|
+
request: (input: OperationBody<"v2.management.uploads.request"> & {
|
|
11
|
+
project: string;
|
|
12
|
+
bucket: string;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}) => Promise<OperationResult<"v2.management.uploads.request">>;
|
|
15
|
+
get: (input: ProjectUploadInput) => Promise<OperationResult<"v2.management.uploads.get">>;
|
|
16
|
+
getWithResponse: (input: ProjectUploadInput) => Promise<{
|
|
17
|
+
data: {
|
|
18
|
+
upload: {
|
|
19
|
+
id: string;
|
|
20
|
+
status: "completed";
|
|
21
|
+
};
|
|
22
|
+
file: {
|
|
23
|
+
id: string;
|
|
24
|
+
url: string;
|
|
25
|
+
key: string;
|
|
26
|
+
thumbnailUrl: string | null;
|
|
27
|
+
thumbnailKey: string | null;
|
|
28
|
+
bucketId: string;
|
|
29
|
+
bucketName: string;
|
|
30
|
+
projectId: string;
|
|
31
|
+
accountId: string;
|
|
32
|
+
name: string;
|
|
33
|
+
path: {
|
|
34
|
+
[x: string]: string;
|
|
35
|
+
};
|
|
36
|
+
metadata: {
|
|
37
|
+
[x: string]: string;
|
|
38
|
+
};
|
|
39
|
+
sizeBytes: number;
|
|
40
|
+
mimeType: string | null;
|
|
41
|
+
state: "requested" | "uploaded" | "deleted" | "replace_requested";
|
|
42
|
+
temporary: boolean;
|
|
43
|
+
uploadedAt: string;
|
|
44
|
+
updatedAt: string;
|
|
45
|
+
};
|
|
46
|
+
} | {
|
|
47
|
+
upload: {
|
|
48
|
+
id: string;
|
|
49
|
+
status: "canceled";
|
|
50
|
+
};
|
|
51
|
+
} | {
|
|
52
|
+
upload: {
|
|
53
|
+
id: string;
|
|
54
|
+
status: "processing";
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
response: Response;
|
|
58
|
+
}>;
|
|
59
|
+
cancel: (input: ProjectUploadInput) => Promise<OperationResult<"v2.management.uploads.cancel">>;
|
|
60
|
+
createParts: (input: ProjectUploadInput & OperationBody<"v2.management.uploads.parts.create">) => Promise<OperationResult<"v2.management.uploads.parts.create">>;
|
|
61
|
+
completeMultipart: (input: ProjectUploadInput & OperationBody<"v2.management.uploads.multipart.complete">) => Promise<OperationResult<"v2.management.uploads.multipart.complete">>;
|
|
62
|
+
};
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=managementUploadOperations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managementUploadOperations.d.ts","sourceRoot":"","sources":["../../src/internal/managementUploadOperations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,UAAU,CACjD,OAAO,gCAAgC,CACxC,CAAC;AAEF,wBAAgB,gCAAgC,CAAC,SAAS,EAAE,SAAS;qBAGxD,aAAa,CAAC,+BAA+B,CAAC,GAAG;QACtD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,KACA,OAAO,CAAC,eAAe,CAAC,+BAA+B,CAAC,CAAC;iBAcnD,kBAAkB,KACxB,OAAO,CAAC,eAAe,CAAC,2BAA2B,CAAC,CAAC;6BAS/B,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAUlC,kBAAkB,KACxB,OAAO,CAAC,eAAe,CAAC,8BAA8B,CAAC,CAAC;yBAUlD,kBAAkB,GACvB,aAAa,CAAC,oCAAoC,CAAC,KACpD,OAAO,CAAC,eAAe,CAAC,oCAAoC,CAAC,CAAC;+BAcxD,kBAAkB,GACvB,aAAa,CAAC,0CAA0C,CAAC,KAC1D,OAAO,CAAC,eAAe,CAAC,0CAA0C,CAAC,CAAC;EAc1E"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
function createManagementUploadOperations(transport) {
|
|
2
|
+
return {
|
|
3
|
+
request: (input)=>{
|
|
4
|
+
const { project, bucket, signal, ...body } = input;
|
|
5
|
+
return transport.execute((client)=>client.POST('/management/projects/{projectRef}/buckets/{bucketName}/uploads', {
|
|
6
|
+
params: {
|
|
7
|
+
path: {
|
|
8
|
+
projectRef: project,
|
|
9
|
+
bucketName: bucket
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
body,
|
|
13
|
+
signal
|
|
14
|
+
}));
|
|
15
|
+
},
|
|
16
|
+
get: (input)=>transport.execute((client)=>client.GET('/management/projects/{projectRef}/uploads/{uploadId}', {
|
|
17
|
+
params: {
|
|
18
|
+
path: {
|
|
19
|
+
projectRef: input.project,
|
|
20
|
+
uploadId: input.uploadId
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
signal: input.signal
|
|
24
|
+
})),
|
|
25
|
+
getWithResponse: (input)=>transport.executeWithResponse((client)=>client.GET('/management/projects/{projectRef}/uploads/{uploadId}', {
|
|
26
|
+
params: {
|
|
27
|
+
path: {
|
|
28
|
+
projectRef: input.project,
|
|
29
|
+
uploadId: input.uploadId
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
signal: input.signal
|
|
33
|
+
})),
|
|
34
|
+
cancel: (input)=>transport.execute((client)=>client.DELETE('/management/projects/{projectRef}/uploads/{uploadId}', {
|
|
35
|
+
params: {
|
|
36
|
+
path: {
|
|
37
|
+
projectRef: input.project,
|
|
38
|
+
uploadId: input.uploadId
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
signal: input.signal
|
|
42
|
+
})),
|
|
43
|
+
createParts: (input)=>{
|
|
44
|
+
const { project, uploadId, signal, ...body } = input;
|
|
45
|
+
return transport.execute((client)=>client.POST('/management/projects/{projectRef}/uploads/{uploadId}/parts', {
|
|
46
|
+
params: {
|
|
47
|
+
path: {
|
|
48
|
+
projectRef: project,
|
|
49
|
+
uploadId
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
body,
|
|
53
|
+
signal
|
|
54
|
+
}));
|
|
55
|
+
},
|
|
56
|
+
completeMultipart: (input)=>{
|
|
57
|
+
const { project, uploadId, signal, ...body } = input;
|
|
58
|
+
return transport.execute((client)=>client.POST('/management/projects/{projectRef}/uploads/{uploadId}/complete', {
|
|
59
|
+
params: {
|
|
60
|
+
path: {
|
|
61
|
+
projectRef: project,
|
|
62
|
+
uploadId
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
body,
|
|
66
|
+
signal
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { createManagementUploadOperations };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { RuntimeUploadInput } from '../uploadTypes.js';
|
|
2
2
|
import type { Transport } from './transport.js';
|
|
3
|
-
type
|
|
3
|
+
export type CompletedUploadPart = {
|
|
4
4
|
partNumber: number;
|
|
5
5
|
eTag: string;
|
|
6
6
|
};
|
|
7
|
-
type
|
|
7
|
+
export type SignedUploadPart = {
|
|
8
8
|
partNumber: number;
|
|
9
9
|
signedUrl: string;
|
|
10
10
|
};
|
|
@@ -12,20 +12,20 @@ type ProgressHandler = RuntimeUploadInput['onProgress'];
|
|
|
12
12
|
export declare function uploadParts(transport: Transport, options: {
|
|
13
13
|
body: Blob;
|
|
14
14
|
uploadId: string;
|
|
15
|
-
parts:
|
|
15
|
+
parts: SignedUploadPart[];
|
|
16
16
|
partSizeBytes: number;
|
|
17
17
|
concurrency: number;
|
|
18
18
|
signal?: AbortSignal;
|
|
19
19
|
onProgress?: ProgressHandler;
|
|
20
|
-
}): Promise<
|
|
20
|
+
}): Promise<CompletedUploadPart[]>;
|
|
21
21
|
export declare function uploadStreamParts(transport: Transport, options: {
|
|
22
22
|
stream: ReadableStream<Uint8Array>;
|
|
23
23
|
totalBytes: number;
|
|
24
24
|
uploadId: string;
|
|
25
|
-
parts:
|
|
25
|
+
parts: SignedUploadPart[];
|
|
26
26
|
partSizeBytes: number;
|
|
27
27
|
signal?: AbortSignal;
|
|
28
28
|
onProgress?: ProgressHandler;
|
|
29
|
-
}): Promise<
|
|
29
|
+
}): Promise<CompletedUploadPart[]>;
|
|
30
30
|
export {};
|
|
31
31
|
//# sourceMappingURL=multipartUpload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipartUpload.d.ts","sourceRoot":"","sources":["../../src/internal/multipartUpload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,
|
|
1
|
+
{"version":3,"file":"multipartUpload.d.ts","sourceRoot":"","sources":["../../src/internal/multipartUpload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,MAAM,MAAM,mBAAmB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACvE,MAAM,MAAM,gBAAgB,GAAG;IAAE,U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AAC,UAAU,CAAC,CAAC;AACvD,KAAK,sBAAsB,GAAG,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,GAAG;IACrE,OAAO,EAAE,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,EAAE,QAAQ,GAAG,eAAe,CAAC,CAAC;CAC7E,CAAC;AACF,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,sBAAsB,CAAC,CAAC;AAE7E,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,SAAS,GACnB,iBAAiB,CAuJnB;AAED,wBAAgB,sBAAsB,CAAC,EACrC,OAAO,EACP,QAAQ,EACR,MAAM,GACP,EAAE,sBAAsB,IACf,QAAQ,MAAM,CAAC,KAAK,CAAC;;aA8Dyi2V,CAAC;cAA2B,CAAC;;;;;cAAoI,CAAC;;;;;;gCAA0L,mDAAsB;;;;;;;;;;8BAA0uB,mDAAsB;;;;;;;;;;;;+BAAirB,mDAAsB;gCAAmD,mDAAsB;;;;;;;;;;;;;;;;gCAA04B,mDAAsB;;;;oCAAiJ,mDAAsB;;;;;gCAAgL,mDAAsB;;;;oCAAiJ,mDAAsB,kCAAiC,mDAAsB;;;;;gCAAmL,mDAAsB;;;;oCAAiJ,mDAAsB,gCAA+B,mDAAsB;;;;;gCAA8K,mDAAsB;;;;oCAAiJ,mDAAsB,2BAA0B,mDAAsB;;;;;gCAAgL,mDAAsB;;;;oCAAiJ,mDAAsB;;;;;gCAAiL,mDAAsB;;;;oCAAiJ,mDAAsB;;;;;;;;;;;;2BAzD/8/V"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/internal/transport.ts"],"names":[],"mappings":"AAAA,OAAqB,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/internal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K,CAAC,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC;CAC1D,CAAC;AAEF,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAoEpE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import createClient from 'openapi-fetch';
|
|
2
2
|
import { getAuthorizationHeader } from '../credentials.js';
|
|
3
|
-
import { EdgeStoreError, EdgeStoreAbortError, EdgeStoreNetworkError, EdgeStoreApiError } from '../errors.js';
|
|
3
|
+
import { EdgeStoreTimeoutError, EdgeStoreError, EdgeStoreAbortError, EdgeStoreNetworkError, EdgeStoreApiError } from '../errors.js';
|
|
4
4
|
import { EDGE_STORE_PACKAGE_NAME, EDGE_STORE_PACKAGE_VERSION } from '../version.js';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_API_URL = 'https://api.edgestore.dev/v2';
|
|
@@ -14,12 +14,25 @@ function createTransport(options) {
|
|
|
14
14
|
}
|
|
15
15
|
const client = createClient({
|
|
16
16
|
baseUrl: normalizeApiUrl(options.apiUrl ?? DEFAULT_API_URL),
|
|
17
|
-
fetch: (request)=>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
fetch: async (request)=>{
|
|
18
|
+
if (controlTimeoutMs === 0) return await fetch(request);
|
|
19
|
+
const timeoutSignal = AbortSignal.timeout(controlTimeoutMs);
|
|
20
|
+
try {
|
|
21
|
+
return await fetch(new Request(request, {
|
|
22
|
+
signal: AbortSignal.any([
|
|
23
|
+
request.signal,
|
|
24
|
+
timeoutSignal
|
|
25
|
+
])
|
|
26
|
+
}));
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (timeoutSignal.aborted && !request.signal.aborted) {
|
|
29
|
+
throw new EdgeStoreTimeoutError(`The EdgeStore API request timed out after ${controlTimeoutMs}ms.`, {
|
|
30
|
+
cause: error
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
23
36
|
headers: {
|
|
24
37
|
authorization,
|
|
25
38
|
'user-agent': `${EDGE_STORE_PACKAGE_NAME}/${EDGE_STORE_PACKAGE_VERSION}`
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { MultipartUploadPlan } from '../multipartPlan.js';
|
|
2
|
+
import { type UploadProgress } from '../uploadTypes.js';
|
|
3
|
+
import { type CompletedUploadPart, type SignedUploadPart } from './multipartUpload.js';
|
|
4
|
+
import type { Transport } from './transport.js';
|
|
5
|
+
import { type PreparedUploadSource } from './uploadSource.js';
|
|
6
|
+
type RequestedUpload = {
|
|
7
|
+
upload: {
|
|
8
|
+
id: string;
|
|
9
|
+
kind: 'single';
|
|
10
|
+
signedUrl: string;
|
|
11
|
+
} | {
|
|
12
|
+
id: string;
|
|
13
|
+
kind: 'multipart';
|
|
14
|
+
parts: SignedUploadPart[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
type UploadState = {
|
|
18
|
+
upload: {
|
|
19
|
+
status: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
type UploadLifecycleOperations<TResult extends UploadState> = {
|
|
23
|
+
completeMultipart(input: {
|
|
24
|
+
uploadId: string;
|
|
25
|
+
parts: CompletedUploadPart[];
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}): Promise<unknown>;
|
|
28
|
+
get(input: {
|
|
29
|
+
uploadId: string;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
data: TResult;
|
|
33
|
+
response: Response;
|
|
34
|
+
}>;
|
|
35
|
+
cancel(input: {
|
|
36
|
+
uploadId: string;
|
|
37
|
+
}): Promise<unknown>;
|
|
38
|
+
};
|
|
39
|
+
export declare function executeUploadLifecycle<TResult extends UploadState>(options: {
|
|
40
|
+
transport: Transport;
|
|
41
|
+
requested: RequestedUpload;
|
|
42
|
+
prepared: PreparedUploadSource;
|
|
43
|
+
multipartPlan: MultipartUploadPlan | null;
|
|
44
|
+
multipartConcurrency?: number;
|
|
45
|
+
defaultMultipartConcurrency?: number;
|
|
46
|
+
processingTimeoutMs: number;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
49
|
+
operations: UploadLifecycleOperations<TResult>;
|
|
50
|
+
cleanupPolicy: 'preserve-original' | 'report-failure';
|
|
51
|
+
}): Promise<Extract<TResult, {
|
|
52
|
+
upload: {
|
|
53
|
+
status: 'completed';
|
|
54
|
+
};
|
|
55
|
+
}>>;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=uploadLifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadLifecycle.d.ts","sourceRoot":"","sources":["../../src/internal/uploadLifecycle.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AAIxB,KAAK,eAAe,GAAG;IACrB,MAAM,EACF;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GACjD;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,WAAW,CAAC;QAAC,KAAK,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAAC;CAClE,CAAC;AAEF,KAAK,WAAW,GAAG;IAAE,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAElD,KAAK,yBA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import { EdgeStoreUploadProcessingTimeoutError, EdgeStoreUploadCleanupError } from '../errors.js';
|
|
2
|
+
import { DEFAULT_MULTIPART_CONCURRENCY } from '../uploadTypes.js';
|
|
3
|
+
import { uploadStreamParts, uploadParts } from './multipartUpload.js';
|
|
4
|
+
import { waitForUploadProcessing } from './uploadProcessing.js';
|
|
5
|
+
import { reportUploadProgress } from './uploadSource.js';
|
|
6
|
+
import { putWithRetry } from './uploadTransfer.js';
|
|
7
|
+
import { getPositiveInteger } from './uploadValidation.js';
|
|
8
|
+
|
|
9
|
+
async function executeUploadLifecycle(options) {
|
|
10
|
+
const { transport, requested, prepared, multipartPlan, processingTimeoutMs, signal, onProgress, operations } = options;
|
|
11
|
+
const uploadId = requested.upload.id;
|
|
12
|
+
const totalBytes = prepared.sizeBytes;
|
|
13
|
+
try {
|
|
14
|
+
reportUploadProgress(onProgress, {
|
|
15
|
+
transferredBytes: 0,
|
|
16
|
+
totalBytes,
|
|
17
|
+
phase: 'uploading'
|
|
18
|
+
});
|
|
19
|
+
if (prepared.kind === 'body' && requested.upload.kind === 'single') {
|
|
20
|
+
await putWithRetry(transport, {
|
|
21
|
+
uploadId,
|
|
22
|
+
url: requested.upload.signedUrl,
|
|
23
|
+
body: prepared.body,
|
|
24
|
+
signal
|
|
25
|
+
});
|
|
26
|
+
reportUploadProgress(onProgress, {
|
|
27
|
+
transferredBytes: totalBytes,
|
|
28
|
+
totalBytes,
|
|
29
|
+
phase: 'uploading'
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
if (requested.upload.kind !== 'multipart' || !multipartPlan) {
|
|
33
|
+
throw new TypeError('The API returned an upload plan that does not match the request.');
|
|
34
|
+
}
|
|
35
|
+
const transfer = {
|
|
36
|
+
uploadId,
|
|
37
|
+
parts: requested.upload.parts,
|
|
38
|
+
partSizeBytes: multipartPlan.partSizeBytes,
|
|
39
|
+
signal,
|
|
40
|
+
onProgress
|
|
41
|
+
};
|
|
42
|
+
const parts = prepared.kind === 'stream' ? await uploadStreamParts(transport, {
|
|
43
|
+
...transfer,
|
|
44
|
+
stream: prepared.stream,
|
|
45
|
+
totalBytes
|
|
46
|
+
}) : await uploadParts(transport, {
|
|
47
|
+
...transfer,
|
|
48
|
+
body: prepared.body,
|
|
49
|
+
concurrency: getPositiveInteger(options.multipartConcurrency, options.defaultMultipartConcurrency ?? DEFAULT_MULTIPART_CONCURRENCY, 'multipart.concurrency')
|
|
50
|
+
});
|
|
51
|
+
await operations.completeMultipart({
|
|
52
|
+
uploadId,
|
|
53
|
+
parts,
|
|
54
|
+
signal
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
reportUploadProgress(onProgress, {
|
|
58
|
+
transferredBytes: totalBytes,
|
|
59
|
+
totalBytes,
|
|
60
|
+
phase: 'processing'
|
|
61
|
+
});
|
|
62
|
+
return await waitForUploadProcessing({
|
|
63
|
+
uploadId,
|
|
64
|
+
signal,
|
|
65
|
+
timeoutMs: processingTimeoutMs,
|
|
66
|
+
get: (requestSignal)=>operations.get({
|
|
67
|
+
uploadId,
|
|
68
|
+
signal: requestSignal
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (error instanceof EdgeStoreUploadProcessingTimeoutError) throw error;
|
|
73
|
+
try {
|
|
74
|
+
await operations.cancel({
|
|
75
|
+
uploadId
|
|
76
|
+
});
|
|
77
|
+
} catch (cleanupError) {
|
|
78
|
+
if (options.cleanupPolicy === 'report-failure') {
|
|
79
|
+
throw new EdgeStoreUploadCleanupError({
|
|
80
|
+
message: `Automatic cancellation of upload ${uploadId} failed.`,
|
|
81
|
+
uploadId,
|
|
82
|
+
uploadCause: error,
|
|
83
|
+
cleanupCause: cleanupError
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { executeUploadLifecycle };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type UploadState = {
|
|
2
|
+
upload: {
|
|
3
|
+
status: string;
|
|
4
|
+
};
|
|
5
|
+
};
|
|
6
|
+
export declare function waitForUploadProcessing<TResult extends UploadState>(options: {
|
|
7
|
+
uploadId: string;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
timeoutMs: number;
|
|
10
|
+
get(signal?: AbortSignal): Promise<{
|
|
11
|
+
data: TResult;
|
|
12
|
+
response: Response;
|
|
13
|
+
}>;
|
|
14
|
+
}): Promise<Extract<TResult, {
|
|
15
|
+
upload: {
|
|
16
|
+
status: 'completed';
|
|
17
|
+
};
|
|
18
|
+
}>>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=uploadProcessing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadProcessing.d.ts","sourceRoot":"","sources":["../../src/internal/uploadProcessing.ts"],"names":[],"mappings":"AAMA,KAAK,WAAW,GAAG;IAAE,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAElD,wBAAsB,uBAAuB,CAC3C,OAAO,SAAS,WAAW,EAC3B,OAAO,EAAE;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC;CAC3E,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,CAAA;CAAE,CAAC,CAAC,CAgCjE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EdgeStoreUploadCanceledError, EdgeStoreUploadProcessingTimeoutError } from '../errors.js';
|
|
2
|
+
import { retryOperation, getRetryAfterMs, sleep } from './uploadRetry.js';
|
|
3
|
+
|
|
4
|
+
async function waitForUploadProcessing(options) {
|
|
5
|
+
const deadline = Date.now() + options.timeoutMs;
|
|
6
|
+
const timeoutError = ()=>new EdgeStoreUploadProcessingTimeoutError('Timed out while EdgeStore was processing the upload.', options.uploadId);
|
|
7
|
+
while(true){
|
|
8
|
+
const { data, response } = await retryOperation((signal)=>options.get(signal), {
|
|
9
|
+
signal: options.signal,
|
|
10
|
+
deadline,
|
|
11
|
+
timeoutError
|
|
12
|
+
});
|
|
13
|
+
if (data.upload.status === 'completed') {
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
if (data.upload.status === 'canceled') {
|
|
17
|
+
throw new EdgeStoreUploadCanceledError('The EdgeStore upload was canceled.', options.uploadId);
|
|
18
|
+
}
|
|
19
|
+
const delayMs = getRetryAfterMs(response) ?? 1000;
|
|
20
|
+
if (Date.now() + delayMs > deadline) throw timeoutError();
|
|
21
|
+
await sleep(delayMs, options.signal);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { waitForUploadProcessing };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UploadMetadataValue, UploadProgress, UploadSource } from '../uploadTypes.js';
|
|
2
|
+
type PreparedUploadDetails = {
|
|
3
|
+
sizeBytes: number;
|
|
4
|
+
fileName?: string;
|
|
5
|
+
mimeType?: string;
|
|
6
|
+
};
|
|
7
|
+
export type PreparedUploadSource = (PreparedUploadDetails & {
|
|
8
|
+
kind: 'body';
|
|
9
|
+
body: Blob;
|
|
10
|
+
}) | (PreparedUploadDetails & {
|
|
11
|
+
kind: 'stream';
|
|
12
|
+
stream: ReadableStream<Uint8Array>;
|
|
13
|
+
});
|
|
14
|
+
export declare function prepareUploadSource(source: UploadSource): PreparedUploadSource;
|
|
15
|
+
export declare function normalizeUploadMetadata(metadata?: Record<string, UploadMetadataValue>): Record<string, string> | undefined;
|
|
16
|
+
export declare function reportUploadProgress(onProgress: ((progress: UploadProgress) => void) | undefined, progress: Omit<UploadProgress, 'percentage'>): void;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=uploadSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploadSource.d.ts","sourceRoot":"","sources":["../../src/internal/uploadSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,YAAY,EAEb,MAAM,gBAAgB,CAAC;AAExB,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B,CAAC,qBAAqB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,GACtD,CAAC,qBAAqB,GAAG;IACvB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CACpC,CAAC,CAAC;AAEP,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,GACnB,oBAAoB,CA0CtB;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAC7C,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAMpC;AAED,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,CAAC,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC,GAAG,SAAS,EAC5D,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,GAC3C,IAAI,CAWN"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
function prepareUploadSource(source) {
|
|
2
|
+
if (typeof source === 'string') {
|
|
3
|
+
const body = new Blob([
|
|
4
|
+
source
|
|
5
|
+
], {
|
|
6
|
+
type: 'text/plain'
|
|
7
|
+
});
|
|
8
|
+
return {
|
|
9
|
+
kind: 'body',
|
|
10
|
+
body,
|
|
11
|
+
sizeBytes: body.size,
|
|
12
|
+
mimeType: body.type
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (isStreamSource(source)) {
|
|
16
|
+
if (!Number.isSafeInteger(source.sizeBytes) || source.sizeBytes < 0) {
|
|
17
|
+
throw new RangeError('source.sizeBytes must be a non-negative integer.');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
kind: 'stream',
|
|
21
|
+
stream: source.stream,
|
|
22
|
+
sizeBytes: source.sizeBytes
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (source instanceof Blob) {
|
|
26
|
+
return {
|
|
27
|
+
kind: 'body',
|
|
28
|
+
body: source,
|
|
29
|
+
sizeBytes: source.size,
|
|
30
|
+
fileName: 'name' in source && typeof source.name === 'string' ? source.name : undefined,
|
|
31
|
+
mimeType: source.type || undefined
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (source instanceof ArrayBuffer) {
|
|
35
|
+
const body = new Blob([
|
|
36
|
+
source
|
|
37
|
+
]);
|
|
38
|
+
return {
|
|
39
|
+
kind: 'body',
|
|
40
|
+
body,
|
|
41
|
+
sizeBytes: body.size
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const body = new Blob([
|
|
45
|
+
Uint8Array.from(new Uint8Array(source.buffer, source.byteOffset, source.byteLength))
|
|
46
|
+
]);
|
|
47
|
+
return {
|
|
48
|
+
kind: 'body',
|
|
49
|
+
body,
|
|
50
|
+
sizeBytes: body.size
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function normalizeUploadMetadata(metadata) {
|
|
54
|
+
if (!metadata) return undefined;
|
|
55
|
+
const entries = Object.entries(metadata).flatMap(([key, value])=>value === null || value === undefined ? [] : [
|
|
56
|
+
[
|
|
57
|
+
key,
|
|
58
|
+
String(value)
|
|
59
|
+
]
|
|
60
|
+
]);
|
|
61
|
+
return entries.length ? Object.fromEntries(entries) : undefined;
|
|
62
|
+
}
|
|
63
|
+
function reportUploadProgress(onProgress, progress) {
|
|
64
|
+
const { transferredBytes, totalBytes, phase } = progress;
|
|
65
|
+
onProgress?.({
|
|
66
|
+
...progress,
|
|
67
|
+
percentage: totalBytes === 0 ? phase === 'preparing' ? 0 : 100 : Math.round(transferredBytes / totalBytes * 10000) / 100
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function isStreamSource(source) {
|
|
71
|
+
const stream = typeof source === 'object' && source !== null && 'stream' in source ? Reflect.get(source, 'stream') : undefined;
|
|
72
|
+
return typeof stream === 'object' && stream !== null && 'getReader' in stream && typeof Reflect.get(stream, 'getReader') === 'function';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { normalizeUploadMetadata, prepareUploadSource, reportUploadProgress };
|
|
@@ -39,12 +39,14 @@ async function putWithRetry(transport, options) {
|
|
|
39
39
|
}
|
|
40
40
|
}, {
|
|
41
41
|
signal: options.signal,
|
|
42
|
-
isRetryable: (error)=>error instanceof SignedUploadResponseError ? isRetryableStatus(error.status) : !(error instanceof EdgeStoreUploadError),
|
|
42
|
+
isRetryable: (error)=>error instanceof SignedUploadResponseError ? isRetryableStatus(error.status) : !findBlobReadError(error) && !(error instanceof EdgeStoreUploadError),
|
|
43
43
|
getRetryDelayMs: (error)=>error instanceof SignedUploadResponseError ? error.retryAfterMs : undefined
|
|
44
44
|
});
|
|
45
45
|
} catch (error) {
|
|
46
46
|
if (error instanceof EdgeStoreAbortError) throw error;
|
|
47
47
|
if (error instanceof EdgeStoreUploadError) throw error;
|
|
48
|
+
const blobReadError = findBlobReadError(error);
|
|
49
|
+
if (blobReadError) throw blobReadError;
|
|
48
50
|
if (error instanceof SignedUploadResponseError) {
|
|
49
51
|
throw new EdgeStoreUploadError(error.message, options.uploadId);
|
|
50
52
|
}
|
|
@@ -53,6 +55,18 @@ async function putWithRetry(transport, options) {
|
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
}
|
|
58
|
+
function findBlobReadError(error) {
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
let current = error;
|
|
61
|
+
while(current instanceof Error && !seen.has(current)){
|
|
62
|
+
if (current instanceof DOMException && current.name === 'NotReadableError') {
|
|
63
|
+
return current;
|
|
64
|
+
}
|
|
65
|
+
seen.add(current);
|
|
66
|
+
current = current.cause;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
56
70
|
async function cancelResponseBody(body) {
|
|
57
71
|
if (!body) return;
|
|
58
72
|
await body.cancel().catch(()=>undefined);
|
|
@@ -2,6 +2,7 @@ import type { OperationResult } from './internal/operationTypes.js';
|
|
|
2
2
|
import type { Transport } from './internal/transport.js';
|
|
3
3
|
import { type ManagementAccessClient } from './managementAccess.js';
|
|
4
4
|
import { type ManagementResourceClient } from './managementResources.js';
|
|
5
|
+
import type { UploadDefaults } from './uploadTypes.js';
|
|
5
6
|
/** Complete administrative client available to Bearer credentials. */
|
|
6
7
|
export type ManagementClient = ManagementResourceClient & ManagementAccessClient & {
|
|
7
8
|
/** Describes the identity represented by the management credential. */
|
|
@@ -10,5 +11,5 @@ export type ManagementClient = ManagementResourceClient & ManagementAccessClient
|
|
|
10
11
|
signal?: AbortSignal;
|
|
11
12
|
}): Promise<OperationResult<'v2.whoami'>>;
|
|
12
13
|
};
|
|
13
|
-
export declare function createManagementClient(transport: Transport): ManagementClient;
|
|
14
|
+
export declare function createManagementClient(transport: Transport, uploadDefaults?: UploadDefaults): ManagementClient;
|
|
14
15
|
//# sourceMappingURL=managementClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"managementClient.d.ts","sourceRoot":"","sources":["../src/managementClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"managementClient.d.ts","sourceRoot":"","sources":["../src/managementClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GAAG,wBAAwB,GACrD,sBAAsB,GAAG;IACvB,uEAAuE;IACvE,MAAM,CAAC,OAAO,CAAC,EAAE;QACf,2BAA2B;QAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GAAG,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC;CAC3C,CAAC;AAEJ,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,EACpB,cAAc,CAAC,EAAE,cAAc,GAC9B,gBAAgB,CASlB"}
|