azure-mock 2.8.1 → 2.9.0

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.d.ts CHANGED
@@ -10,7 +10,6 @@ type BlobHierarchyItem = (BlobItem & {
10
10
  });
11
11
  //#endregion
12
12
  //#region src/store/MockContainerDatabase.d.ts
13
- // Map<container, Map<name, blob>>
14
13
  declare const MockContainerDatabase: Map<string, Map<string, Buffer>>;
15
14
  //#endregion
16
15
  //#region src/models/MockBlobBatchClient.d.ts
@@ -23,7 +22,6 @@ declare class MockBlobBatchClient implements BlobBatchClient {
23
22
  * underlying MockContainerDatabase, and builds a response object that reports
24
23
  * which deletions succeeded and which failed (e.g. for blobs that didn't exist).
25
24
  */
26
- // @ts-expect-error We will only implement urls for deleteBlobs and ignore overloads for now
27
25
  deleteBlobs(urls: string[], credential: AnonymousCredential | StorageSharedKeyCredential, _options?: BlobDeleteOptions): Promise<BlobBatchDeleteBlobsResponse>;
28
26
  getContainer(containerName: string): MapValue<typeof MockContainerDatabase>;
29
27
  }
@@ -671,7 +669,7 @@ declare class MockBlobClient implements Except<BlobClient, "accountName"> {
671
669
  get container(): MapValue<typeof MockContainerDatabase>;
672
670
  constructor(connectionString: string, containerName: string, blobName: string);
673
671
  abortCopyFromURL(): Promise<BlobAbortCopyFromURLResponse>;
674
- beginCopyFromURL(): Promise<PollerLikeWithCancellation<PollOperationState<BlobBeginCopyFromURLResponse>, BlobBeginCopyFromURLResponse>>;
672
+ beginCopyFromURL(copySource: string): Promise<PollerLikeWithCancellation<PollOperationState<BlobBeginCopyFromURLResponse>, BlobBeginCopyFromURLResponse>>;
675
673
  createSnapshot(): Promise<BlobCreateSnapshotResponse>;
676
674
  delete(): Promise<BlobDeleteResponse>;
677
675
  deleteIfExists(): Promise<BlobDeleteIfExistsResponse>;
@@ -773,7 +771,7 @@ declare class MockContainerClient implements Except<ContainerClient, "accountNam
773
771
  create(): Promise<ContainerCreateResponse>;
774
772
  createIfNotExists(): Promise<ContainerCreateIfNotExistsResponse>;
775
773
  delete(): Promise<ContainerDeleteResponse>;
776
- deleteBlob(): Promise<BlobDeleteResponse>;
774
+ deleteBlob(blobName: string): Promise<BlobDeleteResponse>;
777
775
  deleteIfExists(): Promise<ContainerDeleteIfExistsResponse>;
778
776
  exists(): Promise<boolean>;
779
777
  findBlobsByTags(): PagedAsyncIterableIterator<FilterBlobItem, ContainerFindBlobsByTagsSegmentResponse>;
@@ -803,15 +801,12 @@ declare class MockContainerClient implements Except<ContainerClient, "accountNam
803
801
  }
804
802
  //#endregion
805
803
  //#region src/models/MockRestError.d.ts
806
- // A mock error class that mimics the structure of Azure's RestError
807
- // This allows you to test error handling more realistically.
808
804
  declare class MockRestError extends Error {
809
805
  statusCode: number;
810
806
  constructor(message: string, statusCode: number);
811
807
  }
812
808
  //#endregion
813
809
  //#region src/store/MockTableDatabase.d.ts
814
- // Record<table, Map<compositeKey, entity>>
815
810
  declare const MockTableDatabase: Map<string, Map<string, TableEntity>>;
816
811
  //#endregion
817
812
  //#region src/models/MockTableClient.d.ts
@@ -841,8 +836,8 @@ declare class MockTableClient implements Except<TableClient, "pipeline"> {
841
836
  updateEntity<T extends object>(entity: TableEntity<T>, mode?: UpdateMode): Promise<TableMergeEntityHeaders>;
842
837
  upsertEntity<T extends object>(entity: TableEntity<T>, mode?: UpdateMode): Promise<TableMergeEntityHeaders>;
843
838
  private getCompositeKey;
839
+ private getEtag;
844
840
  private mergeEntity;
845
- // Helper to add mock metadata, similar to the real SDK
846
841
  private withMetadata;
847
842
  }
848
843
  //#endregion
@@ -905,7 +900,7 @@ declare global {
905
900
  interface Event {}
906
901
  }
907
902
  //#endregion
908
- //#region ../../node_modules/.pnpm/@azure+core-util@1.12.0/node_modules/@azure/core-util/dist/esm/index.d.ts
903
+ //#region ../../node_modules/.pnpm/@azure+core-util@1.13.0/node_modules/@azure/core-util/dist/esm/index.d.ts
909
904
  /**
910
905
  * Supported HTTP methods to use when making requests.
911
906
  *
@@ -917,7 +912,7 @@ type HttpMethods = "GET" | "PUT" | "POST" | "DELETE" | "PATCH" | "HEAD" | "OPTIO
917
912
  */
918
913
 
919
914
  //#endregion
920
- //#region ../../node_modules/.pnpm/@azure+core-tracing@1.2.0/node_modules/@azure/core-tracing/dist/esm/interfaces.d.ts
915
+ //#region ../../node_modules/.pnpm/@azure+core-tracing@1.3.0/node_modules/@azure/core-tracing/dist/esm/interfaces.d.ts
921
916
  /** An immutable context bag of tracing values for the current operation. */
922
917
  interface TracingContext {
923
918
  /**
@@ -953,7 +948,7 @@ interface OperationTracingOptions {
953
948
  * as part of an operation's options.
954
949
  */
955
950
  //#endregion
956
- //#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.21.0/node_modules/@azure/core-rest-pipeline/dist/esm/interfaces.d.ts
951
+ //#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.0/node_modules/@azure/core-rest-pipeline/dist/esm/interfaces.d.ts
957
952
  /**
958
953
  * A HttpHeaders collection represented as a simple JSON object.
959
954
  */
@@ -1291,7 +1286,7 @@ interface PxfObject {
1291
1286
  }
1292
1287
  //# sourceMappingURL=interfaces.d.ts.map
1293
1288
  //#endregion
1294
- //#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.21.0/node_modules/@azure/core-rest-pipeline/dist/esm/index.d.ts
1289
+ //#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.0/node_modules/@azure/core-rest-pipeline/dist/esm/index.d.ts
1295
1290
  declare global {
1296
1291
  interface FormData {}
1297
1292
  interface Blob {}
package/dist/index.js CHANGED
@@ -47,7 +47,7 @@ const getAzureErrorXml = (errorCode, errorMessage) => html`<?xml version="1.0" e
47
47
  </Error>`;
48
48
 
49
49
  //#endregion
50
- //#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.2.3/node_modules/@typespec/ts-http-runtime/dist/browser/httpHeaders.js
50
+ //#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.0/node_modules/@typespec/ts-http-runtime/dist/browser/httpHeaders.js
51
51
  function normalizeName(name) {
52
52
  return name.toLowerCase();
53
53
  }
@@ -125,7 +125,7 @@ function createHttpHeaders$1(rawHeaders) {
125
125
  }
126
126
 
127
127
  //#endregion
128
- //#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.2.3/node_modules/@typespec/ts-http-runtime/dist/browser/util/uuidUtils.common.js
128
+ //#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.0/node_modules/@typespec/ts-http-runtime/dist/browser/util/uuidUtils.common.js
129
129
  /**
130
130
  * Generated Universally Unique Identifier
131
131
  *
@@ -144,7 +144,7 @@ function generateUUID() {
144
144
  }
145
145
 
146
146
  //#endregion
147
- //#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.2.3/node_modules/@typespec/ts-http-runtime/dist/browser/util/uuidUtils.js
147
+ //#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.0/node_modules/@typespec/ts-http-runtime/dist/browser/util/uuidUtils.js
148
148
  var _a;
149
149
  const uuidFunction = typeof ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) === "function" ? globalThis.crypto.randomUUID.bind(globalThis.crypto) : generateUUID;
150
150
  /**
@@ -157,7 +157,7 @@ function randomUUID() {
157
157
  }
158
158
 
159
159
  //#endregion
160
- //#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.2.3/node_modules/@typespec/ts-http-runtime/dist/browser/pipelineRequest.js
160
+ //#region ../../node_modules/.pnpm/@typespec+ts-http-runtime@0.3.0/node_modules/@typespec/ts-http-runtime/dist/browser/pipelineRequest.js
161
161
  var PipelineRequestImpl = class {
162
162
  constructor(options) {
163
163
  var _a$1, _b, _c, _d, _e, _f, _g;
@@ -192,7 +192,7 @@ function createPipelineRequest$1(options) {
192
192
  }
193
193
 
194
194
  //#endregion
195
- //#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.21.0/node_modules/@azure/core-rest-pipeline/dist/browser/httpHeaders.js
195
+ //#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.0/node_modules/@azure/core-rest-pipeline/dist/browser/httpHeaders.js
196
196
  /**
197
197
  * Creates an object that satisfies the `HttpHeaders` interface.
198
198
  * @param rawHeaders - A simple object representing initial headers
@@ -202,7 +202,7 @@ function createHttpHeaders(rawHeaders) {
202
202
  }
203
203
 
204
204
  //#endregion
205
- //#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.21.0/node_modules/@azure/core-rest-pipeline/dist/browser/pipelineRequest.js
205
+ //#region ../../node_modules/.pnpm/@azure+core-rest-pipeline@1.22.0/node_modules/@azure/core-rest-pipeline/dist/browser/pipelineRequest.js
206
206
  /**
207
207
  * Creates a new pipeline request with the given options.
208
208
  * This method is to allow for the easy setting of default values and not required.
@@ -612,8 +612,37 @@ var MockBlobClient = class {
612
612
  abortCopyFromURL() {
613
613
  throw new Error("Method not implemented.");
614
614
  }
615
- beginCopyFromURL() {
616
- throw new Error("Method not implemented.");
615
+ beginCopyFromURL(copySource) {
616
+ const url = new URL(copySource);
617
+ const pathSegments = url.pathname.split("/").filter(Boolean);
618
+ if (pathSegments.length < 2) throw new MockRestError("Invalid copy source URL format", 400);
619
+ const sourceContainerName = pathSegments[0];
620
+ const sourceBlobName = pathSegments.slice(1).join("/");
621
+ const sourceContainer = MockContainerDatabase.get(sourceContainerName);
622
+ if (!sourceContainer) throw new MockRestError("Source container not found", 404);
623
+ const sourceData = sourceContainer.get(sourceBlobName);
624
+ if (!sourceData) throw new MockRestError("Source blob not found", 404);
625
+ this.container.set(this.name, Buffer.from(sourceData));
626
+ const response = { _response: {
627
+ headers: toHttpHeadersLike(createHttpHeaders()),
628
+ parsedHeaders: {},
629
+ request: toWebResourceLike(createPipelineRequest({ url: `${this.url}?comp=copy` })),
630
+ status: 202
631
+ } };
632
+ return Promise.resolve({
633
+ cancelOperation: () => Promise.resolve(),
634
+ getOperationState: () => ({
635
+ isCompleted: true,
636
+ result: response
637
+ }),
638
+ getResult: () => response,
639
+ isDone: () => true,
640
+ isStopped: () => false,
641
+ onProgress: () => () => {},
642
+ poll: () => Promise.resolve(),
643
+ pollUntilDone: () => Promise.resolve(response),
644
+ stopPolling: () => {}
645
+ });
617
646
  }
618
647
  createSnapshot() {
619
648
  throw new Error("Method not implemented.");
@@ -661,7 +690,7 @@ var MockBlobClient = class {
661
690
  throw new Error("Method not implemented.");
662
691
  }
663
692
  generateSasUrl() {
664
- throw new Error("Method not implemented.");
693
+ return Promise.resolve(`https://mockaccount.blob.core.windows.net/${this.containerName}/${this.name}?sv=2025-11-05&sr=b&sig=mock-signature&st=1970-01-01T00:00:00Z&se=2099-12-31T23:59:59Z&sp=r`);
665
694
  }
666
695
  generateUserDelegationSasStringToSign() {
667
696
  throw new Error("Method not implemented.");
@@ -869,8 +898,15 @@ var MockContainerClient = class {
869
898
  delete() {
870
899
  throw new Error("Method not implemented.");
871
900
  }
872
- deleteBlob() {
873
- throw new Error("Method not implemented.");
901
+ deleteBlob(blobName) {
902
+ if (!this.container.has(blobName)) throw new MockRestError("The specified blob does not exist.", 404);
903
+ this.container.delete(blobName);
904
+ return Promise.resolve({ _response: {
905
+ headers: toHttpHeadersLike(createHttpHeaders()),
906
+ parsedHeaders: {},
907
+ request: toWebResourceLike(createPipelineRequest({ url: `${this.url}/${blobName}` })),
908
+ status: 200
909
+ } });
874
910
  }
875
911
  deleteIfExists() {
876
912
  throw new Error("Method not implemented.");
@@ -885,7 +921,7 @@ var MockContainerClient = class {
885
921
  throw new Error("Method not implemented.");
886
922
  }
887
923
  generateSasUrl() {
888
- throw new Error("Method not implemented.");
924
+ return Promise.resolve(`https://mockaccount.blob.core.windows.net/${this.containerName}?sv=2025-11-05&sr=c&sig=mock-signature&st=1970-01-01T00:00:00Z&se=2099-12-31T23:59:59Z&sp=rw`);
889
925
  }
890
926
  generateUserDelegationSasStringToSign() {
891
927
  throw new Error("Method not implemented.");
@@ -1101,11 +1137,10 @@ var MockTableClient = class {
1101
1137
  createEntity(entity) {
1102
1138
  const key = this.getCompositeKey(entity.partitionKey, entity.rowKey);
1103
1139
  if (this.table.has(key)) throw new MockRestError("The specified entity already exists.", 409);
1104
- const storedEntity = this.withMetadata(entity);
1105
- this.table.set(key, storedEntity);
1140
+ this.table.set(key, entity);
1106
1141
  return Promise.resolve({
1107
1142
  date: /* @__PURE__ */ new Date(),
1108
- etag: storedEntity.etag
1143
+ etag: this.getEtag()
1109
1144
  });
1110
1145
  }
1111
1146
  createTable() {
@@ -1127,8 +1162,10 @@ var MockTableClient = class {
1127
1162
  const key = this.getCompositeKey(partitionKey, rowKey);
1128
1163
  const entity = this.table.get(key);
1129
1164
  if (!entity) throw new MockRestError("The specified resource does not exist.", 404);
1130
- const entityWithMetadata = this.withMetadata(entity);
1131
- return Promise.resolve(entityWithMetadata);
1165
+ return Promise.resolve({
1166
+ ...entity,
1167
+ etag: this.getEtag()
1168
+ });
1132
1169
  }
1133
1170
  listEntities() {
1134
1171
  const withMetadata = this.withMetadata.bind(this);
@@ -1138,10 +1175,7 @@ var MockTableClient = class {
1138
1175
  if (allEntitiesWithMetadata.length > 0) yield await Promise.resolve(allEntitiesWithMetadata);
1139
1176
  }(this.table),
1140
1177
  next: () => async function* (entities) {
1141
- for (const entity of entities.values()) {
1142
- const entityWithMetadata = withMetadata(entity);
1143
- yield await Promise.resolve(entityWithMetadata);
1144
- }
1178
+ for (const entity of entities.values()) yield await Promise.resolve(withMetadata(entity));
1145
1179
  }(this.table).next(),
1146
1180
  [Symbol.asyncIterator]() {
1147
1181
  return this;
@@ -1159,42 +1193,42 @@ var MockTableClient = class {
1159
1193
  const existingEntity = this.table.get(key);
1160
1194
  if (!existingEntity) throw new MockRestError("The specified resource does not exist.", 404);
1161
1195
  else if (mode === "Merge") return this.mergeEntity(key, existingEntity, entity);
1162
- const newEntityWithMetadata = this.withMetadata(entity);
1163
- this.table.set(key, newEntityWithMetadata);
1196
+ this.table.set(key, entity);
1164
1197
  return Promise.resolve({
1165
1198
  date: /* @__PURE__ */ new Date(),
1166
- etag: newEntityWithMetadata.etag
1199
+ etag: this.getEtag()
1167
1200
  });
1168
1201
  }
1169
1202
  upsertEntity(entity, mode = "Merge") {
1170
1203
  const key = this.getCompositeKey(entity.partitionKey, entity.rowKey);
1171
1204
  const existingEntity = this.table.get(key);
1172
1205
  if (existingEntity && mode === "Merge") return this.mergeEntity(key, existingEntity, entity);
1173
- const newEntity = this.withMetadata(entity);
1174
- this.table.set(key, newEntity);
1206
+ this.table.set(key, entity);
1175
1207
  return Promise.resolve({
1176
1208
  date: /* @__PURE__ */ new Date(),
1177
- etag: newEntity.etag
1209
+ etag: this.getEtag()
1178
1210
  });
1179
1211
  }
1180
1212
  getCompositeKey(partitionKey, rowKey) {
1181
1213
  return `${partitionKey}${ID_SEPARATOR}${rowKey}`;
1182
1214
  }
1215
+ getEtag() {
1216
+ return `W/"datetime'${(/* @__PURE__ */ new Date()).toISOString()}'"`;
1217
+ }
1183
1218
  mergeEntity(key, entity, entityToMerge) {
1184
- const mergedEntityWithMetadata = this.withMetadata({
1219
+ this.table.set(key, {
1185
1220
  ...entity,
1186
1221
  ...entityToMerge
1187
1222
  });
1188
- this.table.set(key, mergedEntityWithMetadata);
1189
1223
  return Promise.resolve({
1190
1224
  date: /* @__PURE__ */ new Date(),
1191
- etag: mergedEntityWithMetadata.etag
1225
+ etag: this.getEtag()
1192
1226
  });
1193
1227
  }
1194
1228
  withMetadata(entity) {
1195
1229
  return {
1196
1230
  ...entity,
1197
- etag: `W/"datetime'${(/* @__PURE__ */ new Date()).toISOString()}'"`
1231
+ etag: this.getEtag()
1198
1232
  };
1199
1233
  }
1200
1234
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-mock",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "A library that contains azure mock classes.",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/Esposter/Esposter#readme",
@@ -30,9 +30,9 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@azure/core-http-compat": "^2.3.0",
33
- "@azure/core-rest-pipeline": "^1.21.0",
33
+ "@azure/core-rest-pipeline": "^1.22.0",
34
34
  "@azure/data-tables": "^13.3.1",
35
35
  "@azure/storage-blob": "^12.27.0"
36
36
  },
37
- "gitHead": "a094ff58832d6a54485dadc5d349a72db80b326c"
37
+ "gitHead": "9fc7b20cf4085cca521b09f7f49259b3dc488b68"
38
38
  }