azure-mock 2.39.0 → 3.0.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 +22 -8
- package/dist/index.js +45 -32
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -71,23 +71,18 @@ export declare const getMockSasUrl: (url: string, permissions: undefined | {
|
|
|
71
71
|
toString: () => string;
|
|
72
72
|
}, resourceType?: string) => string;
|
|
73
73
|
//#endregion
|
|
74
|
-
//#region src/
|
|
74
|
+
//#region src/models/container/MockBlobDates.d.ts
|
|
75
75
|
export interface MockBlobDates {
|
|
76
76
|
createdOn: Date;
|
|
77
77
|
etag: string;
|
|
78
78
|
lastModified: Date;
|
|
79
79
|
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/store/MockContainerBlobDatesDatabase.d.ts
|
|
80
82
|
export declare const MockContainerBlobDatesDatabase: Map<string, MockBlobDates>;
|
|
81
|
-
export declare const MOCK_BLOB_SEEDED_DATE: Date;
|
|
82
|
-
export declare const getMockContainerBlobDatesKey: (containerName: string, blobName: string) => string;
|
|
83
|
-
export declare const storeMockBlobWrite: (containerName: string, blobName: string, isExisting: boolean) => void;
|
|
84
|
-
export declare const MOCK_BLOB_SEEDED_PROPERTIES: MockBlobDates;
|
|
85
|
-
export declare const readMockBlobDates: (containerName: string, blobName: string) => MockBlobDates;
|
|
86
83
|
//#endregion
|
|
87
84
|
//#region src/store/MockContainerBlobMetadataDatabase.d.ts
|
|
88
85
|
export declare const MockContainerBlobMetadataDatabase: Map<string, Record<string, string>>;
|
|
89
|
-
export declare const storeMockBlobMetadata: (containerName: string, blobName: string, metadata: Record<string, string> | undefined) => void;
|
|
90
|
-
export declare const readMockBlobMetadata: (containerName: string, blobName: string) => Record<string, string> | undefined;
|
|
91
86
|
//#endregion
|
|
92
87
|
//#region src/store/MockContainerDatabase.d.ts
|
|
93
88
|
export declare const MockContainerDatabase: Map<string, Map<string, Buffer>>;
|
|
@@ -1144,6 +1139,10 @@ export declare const bodyToBuffer: (body: HttpRequestBody) => Promise<Buffer>;
|
|
|
1144
1139
|
//#region src/services/container/checkIsReadableStream.d.ts
|
|
1145
1140
|
export declare const checkIsReadableStream: (value: unknown) => value is NodeJS.ReadableStream;
|
|
1146
1141
|
//#endregion
|
|
1142
|
+
//#region src/services/container/constants.d.ts
|
|
1143
|
+
export declare const MOCK_BLOB_SEEDED_DATE: Date;
|
|
1144
|
+
export declare const MOCK_BLOB_SEEDED_PROPERTIES: MockBlobDates;
|
|
1145
|
+
//#endregion
|
|
1147
1146
|
//#region src/services/container/deleteMockBlob.d.ts
|
|
1148
1147
|
export declare const deleteMockBlob: (containerName: string, blobName: string) => boolean;
|
|
1149
1148
|
//#endregion
|
|
@@ -1183,9 +1182,24 @@ export declare const getListBlobsSegmentResponse: (containerName: string, prefix
|
|
|
1183
1182
|
*/
|
|
1184
1183
|
export declare const getListBlobsXml: (containerName: string, blobsXml: string) => string;
|
|
1185
1184
|
//#endregion
|
|
1185
|
+
//#region src/services/container/getMockBlobKey.d.ts
|
|
1186
|
+
export declare const getMockBlobKey: (containerName: string, blobName: string) => string;
|
|
1187
|
+
//#endregion
|
|
1186
1188
|
//#region src/services/container/getMockContainer.d.ts
|
|
1187
1189
|
export declare const getMockContainer: (containerName: string) => MapValue<typeof MockContainerDatabase>;
|
|
1188
1190
|
//#endregion
|
|
1191
|
+
//#region src/services/container/readMockBlobDates.d.ts
|
|
1192
|
+
export declare const readMockBlobDates: (containerName: string, blobName: string) => MockBlobDates;
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/services/container/readMockBlobMetadata.d.ts
|
|
1195
|
+
export declare const readMockBlobMetadata: (containerName: string, blobName: string) => Record<string, string> | undefined;
|
|
1196
|
+
//#endregion
|
|
1197
|
+
//#region src/services/container/storeMockBlobMetadata.d.ts
|
|
1198
|
+
export declare const storeMockBlobMetadata: (containerName: string, blobName: string, metadata: Record<string, string> | undefined) => void;
|
|
1199
|
+
//#endregion
|
|
1200
|
+
//#region src/services/container/storeMockBlobWrite.d.ts
|
|
1201
|
+
export declare const storeMockBlobWrite: (containerName: string, blobName: string, isExisting: boolean) => void;
|
|
1202
|
+
//#endregion
|
|
1189
1203
|
//#region src/services/container/toWebResourceLike.d.ts
|
|
1190
1204
|
export declare const toWebResourceLike: (request: PipelineRequest) => WebResourceLike;
|
|
1191
1205
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -61,32 +61,9 @@ const getMockSasUrl = (url, permissions, resourceType) => `${url}?sv=2025-11-05&
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/store/MockContainerBlobDatesDatabase.ts
|
|
63
63
|
const MockContainerBlobDatesDatabase = /* @__PURE__ */ new Map();
|
|
64
|
-
const MOCK_BLOB_SEEDED_DATE = /* @__PURE__ */ new Date(-864e13);
|
|
65
|
-
const getMockContainerBlobDatesKey = (containerName, blobName) => `${containerName}/${blobName}`;
|
|
66
|
-
const storeMockBlobWrite = (containerName, blobName, isExisting) => {
|
|
67
|
-
const key = getMockContainerBlobDatesKey(containerName, blobName);
|
|
68
|
-
const lastModified = /* @__PURE__ */ new Date();
|
|
69
|
-
MockContainerBlobDatesDatabase.set(key, {
|
|
70
|
-
createdOn: MockContainerBlobDatesDatabase.get(key)?.createdOn ?? (isExisting ? MOCK_BLOB_SEEDED_DATE : lastModified),
|
|
71
|
-
etag: `"${crypto.randomUUID()}"`,
|
|
72
|
-
lastModified
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
const MOCK_BLOB_SEEDED_PROPERTIES = {
|
|
76
|
-
createdOn: MOCK_BLOB_SEEDED_DATE,
|
|
77
|
-
etag: "\"seeded\"",
|
|
78
|
-
lastModified: MOCK_BLOB_SEEDED_DATE
|
|
79
|
-
};
|
|
80
|
-
const readMockBlobDates = (containerName, blobName) => MockContainerBlobDatesDatabase.get(getMockContainerBlobDatesKey(containerName, blobName)) ?? MOCK_BLOB_SEEDED_PROPERTIES;
|
|
81
64
|
//#endregion
|
|
82
65
|
//#region src/store/MockContainerBlobMetadataDatabase.ts
|
|
83
66
|
const MockContainerBlobMetadataDatabase = /* @__PURE__ */ new Map();
|
|
84
|
-
const storeMockBlobMetadata = (containerName, blobName, metadata) => {
|
|
85
|
-
const key = getMockContainerBlobDatesKey(containerName, blobName);
|
|
86
|
-
if (metadata) MockContainerBlobMetadataDatabase.set(key, metadata);
|
|
87
|
-
else MockContainerBlobMetadataDatabase.delete(key);
|
|
88
|
-
};
|
|
89
|
-
const readMockBlobMetadata = (containerName, blobName) => MockContainerBlobMetadataDatabase.get(getMockContainerBlobDatesKey(containerName, blobName));
|
|
90
67
|
//#endregion
|
|
91
68
|
//#region src/store/MockContainerDatabase.ts
|
|
92
69
|
var MockContainerDatabaseMap = class extends Map {
|
|
@@ -113,13 +90,23 @@ const MockServiceBusDatabase = /* @__PURE__ */ new Map();
|
|
|
113
90
|
//#region src/store/MockTableDatabase.ts
|
|
114
91
|
const MockTableDatabase = /* @__PURE__ */ new Map();
|
|
115
92
|
//#endregion
|
|
93
|
+
//#region src/services/container/getMockBlobKey.ts
|
|
94
|
+
const getMockBlobKey = (containerName, blobName) => `${encodeURIComponent(containerName)}${ID_SEPARATOR}${encodeURIComponent(blobName)}`;
|
|
95
|
+
//#endregion
|
|
116
96
|
//#region src/services/container/getMockContainer.ts
|
|
117
97
|
const getMockContainer = (containerName) => getOrCreate(MockContainerDatabase, containerName, () => /* @__PURE__ */ new Map());
|
|
118
98
|
//#endregion
|
|
99
|
+
//#region src/services/container/storeMockBlobMetadata.ts
|
|
100
|
+
const storeMockBlobMetadata = (containerName, blobName, metadata) => {
|
|
101
|
+
const key = getMockBlobKey(containerName, blobName);
|
|
102
|
+
if (metadata) MockContainerBlobMetadataDatabase.set(key, metadata);
|
|
103
|
+
else MockContainerBlobMetadataDatabase.delete(key);
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
119
106
|
//#region src/services/container/deleteMockBlob.ts
|
|
120
107
|
const deleteMockBlob = (containerName, blobName) => {
|
|
121
108
|
if (!getMockContainer(containerName).delete(blobName)) return false;
|
|
122
|
-
MockContainerBlobDatesDatabase.delete(
|
|
109
|
+
MockContainerBlobDatesDatabase.delete(getMockBlobKey(containerName, blobName));
|
|
123
110
|
storeMockBlobMetadata(containerName, blobName, void 0);
|
|
124
111
|
return true;
|
|
125
112
|
};
|
|
@@ -224,6 +211,28 @@ var MockBlobBatchClient = class {
|
|
|
224
211
|
//#region src/services/container/getBlobUrl.ts
|
|
225
212
|
const getBlobUrl = (containerName, blobName) => `${MOCK_BLOB_BASE_URL}/${containerName}/${blobName.split("/").map((segment) => encodeURIComponent(segment)).join("/")}`;
|
|
226
213
|
//#endregion
|
|
214
|
+
//#region src/services/container/constants.ts
|
|
215
|
+
const MOCK_BLOB_SEEDED_DATE = /* @__PURE__ */ new Date(-864e13);
|
|
216
|
+
const MOCK_BLOB_SEEDED_PROPERTIES = {
|
|
217
|
+
createdOn: MOCK_BLOB_SEEDED_DATE,
|
|
218
|
+
etag: "\"seeded\"",
|
|
219
|
+
lastModified: MOCK_BLOB_SEEDED_DATE
|
|
220
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/services/container/readMockBlobDates.ts
|
|
223
|
+
const readMockBlobDates = (containerName, blobName) => MockContainerBlobDatesDatabase.get(getMockBlobKey(containerName, blobName)) ?? MOCK_BLOB_SEEDED_PROPERTIES;
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/services/container/storeMockBlobWrite.ts
|
|
226
|
+
const storeMockBlobWrite = (containerName, blobName, isExisting) => {
|
|
227
|
+
const key = getMockBlobKey(containerName, blobName);
|
|
228
|
+
const lastModified = /* @__PURE__ */ new Date();
|
|
229
|
+
MockContainerBlobDatesDatabase.set(key, {
|
|
230
|
+
createdOn: MockContainerBlobDatesDatabase.get(key)?.createdOn ?? (isExisting ? MOCK_BLOB_SEEDED_DATE : lastModified),
|
|
231
|
+
etag: `"${crypto.randomUUID()}"`,
|
|
232
|
+
lastModified
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
227
236
|
//#region src/models/container/MockBlobClient.ts
|
|
228
237
|
var MockBlobClient = class {
|
|
229
238
|
connectionString;
|
|
@@ -275,14 +284,14 @@ var MockBlobClient = class {
|
|
|
275
284
|
delete() {
|
|
276
285
|
if (!this.container.has(this.name)) throw new MockRestError(BLOB_NOT_FOUND_MESSAGE, 404);
|
|
277
286
|
this.container.delete(this.name);
|
|
278
|
-
MockContainerBlobDatesDatabase.delete(
|
|
287
|
+
MockContainerBlobDatesDatabase.delete(getMockBlobKey(this.containerName, this.name));
|
|
279
288
|
return Promise.resolve({ _response: createMockResponse(200) });
|
|
280
289
|
}
|
|
281
290
|
deleteIfExists() {
|
|
282
291
|
const succeeded = this.container.has(this.name);
|
|
283
292
|
if (succeeded) {
|
|
284
293
|
this.container.delete(this.name);
|
|
285
|
-
MockContainerBlobDatesDatabase.delete(
|
|
294
|
+
MockContainerBlobDatesDatabase.delete(getMockBlobKey(this.containerName, this.name));
|
|
286
295
|
}
|
|
287
296
|
return Promise.resolve({
|
|
288
297
|
_response: createMockResponse(succeeded ? 200 : 404),
|
|
@@ -505,6 +514,9 @@ const getListBlobsSegmentResponse = (containerName, prefix, segment, blobsXml) =
|
|
|
505
514
|
};
|
|
506
515
|
};
|
|
507
516
|
//#endregion
|
|
517
|
+
//#region src/services/container/readMockBlobMetadata.ts
|
|
518
|
+
const readMockBlobMetadata = (containerName, blobName) => MockContainerBlobMetadataDatabase.get(getMockBlobKey(containerName, blobName));
|
|
519
|
+
//#endregion
|
|
508
520
|
//#region src/models/container/MockContainerClient.ts
|
|
509
521
|
/**
|
|
510
522
|
* An in-memory mock of the Azure ContainerClient — no emulator and no network.
|
|
@@ -950,10 +962,11 @@ const sortDocuments = (documents, orderBy) => {
|
|
|
950
962
|
};
|
|
951
963
|
const getSearchFieldValues = (value, pathSegments) => {
|
|
952
964
|
if (pathSegments.length === 0) return [value];
|
|
953
|
-
if (Array.isArray(value)) return value.flatMap((item) => getSearchFieldValues(item, pathSegments));
|
|
954
|
-
if (typeof value
|
|
955
|
-
|
|
956
|
-
|
|
965
|
+
else if (Array.isArray(value)) return value.flatMap((item) => getSearchFieldValues(item, pathSegments));
|
|
966
|
+
else if (typeof value === "object" && value !== null) {
|
|
967
|
+
const [field = "", ...remainingPathSegments] = pathSegments;
|
|
968
|
+
return getSearchFieldValues(value[deserializeKey(field)], remainingPathSegments);
|
|
969
|
+
} else return [];
|
|
957
970
|
};
|
|
958
971
|
const searchDocuments = (documents, searchText, searchFields) => {
|
|
959
972
|
if (!searchText || searchText === "*") return documents;
|
|
@@ -1245,7 +1258,7 @@ var MockTableClient = class {
|
|
|
1245
1258
|
});
|
|
1246
1259
|
}
|
|
1247
1260
|
#getCompositeKey(partitionKey, rowKey) {
|
|
1248
|
-
return `${partitionKey}${ID_SEPARATOR}${rowKey}`;
|
|
1261
|
+
return `${encodeURIComponent(partitionKey)}${ID_SEPARATOR}${encodeURIComponent(rowKey)}`;
|
|
1249
1262
|
}
|
|
1250
1263
|
#getEtag() {
|
|
1251
1264
|
return `W/"${crypto.randomUUID()}"`;
|
|
@@ -1275,4 +1288,4 @@ const applyFilter = (documents, clauses) => {
|
|
|
1275
1288
|
return documents.filter((document) => predicate(document));
|
|
1276
1289
|
};
|
|
1277
1290
|
//#endregion
|
|
1278
|
-
export { BLOB_NOT_FOUND_ERROR_CODE, BLOB_NOT_FOUND_MESSAGE, MOCK_BLOB_BASE_URL, MOCK_BLOB_SEEDED_DATE, MOCK_BLOB_SEEDED_PROPERTIES, MOCK_QUEUE_BASE_URL, MOCK_SEARCH_BASE_URL, MOCK_TABLE_BASE_URL, MockBlobBatchClient, MockBlobClient, MockBlockBlobClient, MockContainerBlobDatesDatabase, MockContainerBlobMetadataDatabase, MockContainerClient, MockContainerDatabase, MockEventGridDatabase, MockEventGridPublisherClient, MockQueueClient, MockQueueDatabase, MockRestError, MockSearchClient, MockSearchDatabase, MockServiceBusDatabase, MockServiceBusSender, MockTableClient, MockTableDatabase, MockWebPubSubServiceClient, applyFilter, bodyToBuffer, checkIsNullClause, checkIsReadableStream, compare, compareByCompositeKey, createFilterPredicate, createMockResponse, deleteMockBlob, getAzureErrorXml, getBlobItemXml, getBlobPrefixXml, getBlobUrl, getBlobUrlParts, getListBlobsSegmentResponse, getListBlobsXml,
|
|
1291
|
+
export { BLOB_NOT_FOUND_ERROR_CODE, BLOB_NOT_FOUND_MESSAGE, MOCK_BLOB_BASE_URL, MOCK_BLOB_SEEDED_DATE, MOCK_BLOB_SEEDED_PROPERTIES, MOCK_QUEUE_BASE_URL, MOCK_SEARCH_BASE_URL, MOCK_TABLE_BASE_URL, MockBlobBatchClient, MockBlobClient, MockBlockBlobClient, MockContainerBlobDatesDatabase, MockContainerBlobMetadataDatabase, MockContainerClient, MockContainerDatabase, MockEventGridDatabase, MockEventGridPublisherClient, MockQueueClient, MockQueueDatabase, MockRestError, MockSearchClient, MockSearchDatabase, MockServiceBusDatabase, MockServiceBusSender, MockTableClient, MockTableDatabase, MockWebPubSubServiceClient, applyFilter, bodyToBuffer, checkIsNullClause, checkIsReadableStream, compare, compareByCompositeKey, createFilterPredicate, createMockResponse, deleteMockBlob, getAzureErrorXml, getBlobItemXml, getBlobPrefixXml, getBlobUrl, getBlobUrlParts, getListBlobsSegmentResponse, getListBlobsXml, getMockBlobKey, getMockContainer, getMockQueueMessageItem, getMockSasUrl, readMockBlobDates, readMockBlobMetadata, storeMockBlobMetadata, storeMockBlobWrite, toWebResourceLike };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "azure-mock",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A library that contains azure mock classes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"azure",
|
|
@@ -54,18 +54,18 @@
|
|
|
54
54
|
"typecheck": "tsc"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@esposter/azure": "
|
|
58
|
-
"@esposter/shared": "
|
|
57
|
+
"@esposter/azure": "3.0.0",
|
|
58
|
+
"@esposter/shared": "3.0.0",
|
|
59
59
|
"fast-deep-equal": "^3.1.3"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@arethetypeswrong/core": "^0.18.5",
|
|
63
|
-
"@esposter/configuration": "
|
|
63
|
+
"@esposter/configuration": "3.0.0",
|
|
64
64
|
"publint": "^0.3.24",
|
|
65
65
|
"tsdown": "^0.23.0",
|
|
66
66
|
"type-fest": "^5.9.0",
|
|
67
67
|
"typedoc": "^0.28.20",
|
|
68
|
-
"vitest": "^
|
|
68
|
+
"vitest": "^5.0.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@azure/core-http-compat": "^2.5.0",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"inlinedDependencies": {
|
|
81
81
|
"type-fest": "5.9.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "5ea72289bdd594e598aab8fefd5686df2a642a7e"
|
|
84
84
|
}
|