azure-mock 4.5.0 → 4.6.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 +2 -0
- package/dist/index.js +33 -13
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1106,8 +1106,10 @@ export declare const getMockQueueMessageItem: (messageText: string) => {
|
|
|
1106
1106
|
messageText: string;
|
|
1107
1107
|
};
|
|
1108
1108
|
export declare const compareValues: (firstValue: unknown, secondValue: unknown) => number;
|
|
1109
|
+
export declare const deserializeDocumentKeys: (document: Record<string, unknown>) => Record<string, unknown>;
|
|
1109
1110
|
export declare const getSearchFieldValues: (value: unknown, pathSegments: string[]) => unknown[];
|
|
1110
1111
|
export declare const searchDocuments: (documents: Record<string, unknown>[], searchText: string | undefined, searchFields: readonly string[] | undefined) => Record<string, unknown>[];
|
|
1112
|
+
export declare const selectSearchDocumentFields: (document: Record<string, unknown>, select: readonly string[]) => Record<string, unknown>;
|
|
1111
1113
|
export declare const sortDocuments: (documents: Record<string, unknown>[], orderBy: string[]) => Record<string, unknown>[];
|
|
1112
1114
|
export declare const toComparable: (value: unknown) => number | string;
|
|
1113
1115
|
export declare const createMockResponse: (status: number, url?: string) => MockResponse;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ID_SEPARATOR, InvalidOperationError, Operation, checkIsDeepEqual, chunk, exhaustiveGuard, getDecodedUriComponent, getOrCreate, getResult, html, noop, streamToText, takeOne } from "@esposter/shared";
|
|
2
2
|
import { toHttpHeadersLike } from "@azure/core-http-compat";
|
|
3
3
|
import { RestError, createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
|
|
4
|
-
import { AZURE_MAX_BATCH_SIZE, AZURE_MAX_PAGE_SIZE, AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS, BinaryOperator, MAX_BLOB_BATCH_DELETIONS, MAX_EVENT_GRID_PUBLISH_EVENT_COUNT, MAX_EVENT_GRID_PUBLISH_REQUEST_BYTES, deserializeClause, deserializeKey, getTableNullClause, serializeClauses } from "@esposter/azure";
|
|
4
|
+
import { AZURE_MAX_BATCH_SIZE, AZURE_MAX_PAGE_SIZE, AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS, BinaryOperator, CompositeKeyPropertyNames, MAX_BLOB_BATCH_DELETIONS, MAX_EVENT_GRID_PUBLISH_EVENT_COUNT, MAX_EVENT_GRID_PUBLISH_REQUEST_BYTES, deserializeClause, deserializeKey, getTableNullClause, serializeClauses, serializeKey } from "@esposter/azure";
|
|
5
5
|
import { AnonymousCredential } from "@azure/storage-blob";
|
|
6
6
|
import { Readable } from "node:stream";
|
|
7
7
|
// src/models/shared/NotImplementedError.ts
|
|
@@ -925,6 +925,8 @@ const createFilterPredicate = (filter) => {
|
|
|
925
925
|
return true;
|
|
926
926
|
};
|
|
927
927
|
};
|
|
928
|
+
// src/services/search/deserializeDocumentKeys.ts
|
|
929
|
+
const deserializeDocumentKeys = (document) => Object.fromEntries(Object.entries(document).map(([key, value]) => [deserializeKey(key), value]));
|
|
928
930
|
// src/services/search/getSearchFieldValues.ts
|
|
929
931
|
const getSearchFieldValues = (value, pathSegments) => {
|
|
930
932
|
if (pathSegments.length === 0) return [value];
|
|
@@ -941,6 +943,11 @@ const searchDocuments = (documents, searchText, searchFields) => {
|
|
|
941
943
|
const searchFieldPaths = searchFields?.map((searchField) => searchField.split("/"));
|
|
942
944
|
return documents.filter((document) => (searchFieldPaths ?? Object.keys(document).map((field) => field.split("/"))).some((pathSegments) => getSearchFieldValues(document, pathSegments).some((value) => typeof value === "string" && value.toLocaleLowerCase().includes(normalizedSearchText))));
|
|
943
945
|
};
|
|
946
|
+
// src/services/search/selectSearchDocumentFields.ts
|
|
947
|
+
const selectSearchDocumentFields = (document, select) => {
|
|
948
|
+
if (select.some((field) => field.includes("/"))) throw new NotImplementedError(selectSearchDocumentFields.name);
|
|
949
|
+
return Object.fromEntries(select.filter((field) => field in document).map((field) => [field, document[field]]));
|
|
950
|
+
};
|
|
944
951
|
// src/services/search/toComparable.ts
|
|
945
952
|
const toComparable = (value) => {
|
|
946
953
|
if (value instanceof Date) return value.getTime();
|
|
@@ -997,8 +1004,15 @@ var MockSearchClient = class {
|
|
|
997
1004
|
autocomplete() {
|
|
998
1005
|
throw new NotImplementedError(this.autocomplete.name);
|
|
999
1006
|
}
|
|
1000
|
-
deleteDocuments() {
|
|
1001
|
-
throw new NotImplementedError(this.deleteDocuments.name);
|
|
1007
|
+
deleteDocuments(keyName, keyValues) {
|
|
1008
|
+
if (Array.isArray(keyName) || !Array.isArray(keyValues)) throw new NotImplementedError(this.deleteDocuments.name);
|
|
1009
|
+
const deletedKeys = new Set(keyValues);
|
|
1010
|
+
MockSearchDatabase.set(this.indexName, this.documents.filter((document) => !deletedKeys.has(String(document[keyName]))));
|
|
1011
|
+
return Promise.resolve({ results: keyValues.map((key) => ({
|
|
1012
|
+
key,
|
|
1013
|
+
statusCode: 200,
|
|
1014
|
+
succeeded: true
|
|
1015
|
+
})) });
|
|
1002
1016
|
}
|
|
1003
1017
|
getDocument(_key, _options) {
|
|
1004
1018
|
throw new NotImplementedError(this.getDocument.name);
|
|
@@ -1016,17 +1030,18 @@ var MockSearchClient = class {
|
|
|
1016
1030
|
throw new NotImplementedError(this.mergeOrUploadDocuments.name);
|
|
1017
1031
|
}
|
|
1018
1032
|
search(searchText, options) {
|
|
1019
|
-
const { filter, includeTotalCount, orderBy, searchFields, skip = 0, top } = options ?? {};
|
|
1033
|
+
const { filter, includeTotalCount, orderBy, searchFields, select, skip = 0, top } = options ?? {};
|
|
1020
1034
|
let documents = searchDocuments(this.documents, searchText, searchFields);
|
|
1021
1035
|
if (filter) {
|
|
1022
1036
|
const predicate = createFilterPredicate(filter);
|
|
1023
|
-
documents = documents.filter((document) => predicate(document));
|
|
1037
|
+
documents = documents.filter((document) => predicate(deserializeDocumentKeys(document)));
|
|
1024
1038
|
}
|
|
1025
1039
|
if (orderBy) documents = sortDocuments(documents, orderBy);
|
|
1026
1040
|
const count = documents.length;
|
|
1027
1041
|
const paginatedDocuments = documents.slice(skip, top === void 0 ? void 0 : skip + top);
|
|
1042
|
+
const returnedDocuments = select ? paginatedDocuments.map((document) => selectSearchDocumentFields(document, select)) : paginatedDocuments;
|
|
1028
1043
|
const results = { async *[Symbol.asyncIterator]() {
|
|
1029
|
-
for (const document of
|
|
1044
|
+
for (const document of returnedDocuments) yield { document };
|
|
1030
1045
|
} };
|
|
1031
1046
|
return Promise.resolve({
|
|
1032
1047
|
...includeTotalCount ? { count } : {},
|
|
@@ -1037,9 +1052,10 @@ var MockSearchClient = class {
|
|
|
1037
1052
|
throw new NotImplementedError(this.suggest.name);
|
|
1038
1053
|
}
|
|
1039
1054
|
uploadDocuments(documents, _options) {
|
|
1055
|
+
const rowKeyName = serializeKey(CompositeKeyPropertyNames.rowKey);
|
|
1040
1056
|
for (const document of documents) {
|
|
1041
|
-
const key = document
|
|
1042
|
-
const index = this.documents.findIndex((existingDocument) => existingDocument
|
|
1057
|
+
const key = document[rowKeyName];
|
|
1058
|
+
const index = this.documents.findIndex((existingDocument) => existingDocument[rowKeyName] === key);
|
|
1043
1059
|
if (index === -1) this.documents.push(document);
|
|
1044
1060
|
else this.documents[index] = document;
|
|
1045
1061
|
}
|
|
@@ -1181,7 +1197,7 @@ var MockTableClient = class {
|
|
|
1181
1197
|
else if (entity.partitionKey !== partitionKey) throw new MockRestError("All transaction actions must target the same partitionKey.", 400);
|
|
1182
1198
|
const snapshot = new Map(this.table);
|
|
1183
1199
|
getResult(() => {
|
|
1184
|
-
for (const [type, entity, updateMode] of actions) switch (type) {
|
|
1200
|
+
for (const [type, entity, updateMode, updateOptions] of actions) switch (type) {
|
|
1185
1201
|
case "create":
|
|
1186
1202
|
this.#applyCreate(entity);
|
|
1187
1203
|
break;
|
|
@@ -1189,7 +1205,7 @@ var MockTableClient = class {
|
|
|
1189
1205
|
this.#applyDelete(entity.partitionKey, entity.rowKey);
|
|
1190
1206
|
break;
|
|
1191
1207
|
case "update":
|
|
1192
|
-
this.#applyUpdate(entity, updateMode);
|
|
1208
|
+
this.#applyUpdate(entity, updateMode, updateOptions?.etag);
|
|
1193
1209
|
break;
|
|
1194
1210
|
case "upsert":
|
|
1195
1211
|
this.#applyUpsert(entity, updateMode);
|
|
@@ -1267,14 +1283,18 @@ var MockTableClient = class {
|
|
|
1267
1283
|
etag: entity.etag ?? this.#getEtag()
|
|
1268
1284
|
};
|
|
1269
1285
|
}
|
|
1286
|
+
#withPresentProperties(entity) {
|
|
1287
|
+
return Object.fromEntries(Object.entries(entity).filter(([, value]) => value !== null && value !== void 0));
|
|
1288
|
+
}
|
|
1270
1289
|
#writeEntity(key, entity, mode, existingEntity) {
|
|
1290
|
+
const presentEntity = this.#withPresentProperties(entity);
|
|
1271
1291
|
if (existingEntity && mode === "Merge") this.table.set(key, {
|
|
1272
1292
|
...existingEntity,
|
|
1273
|
-
...
|
|
1293
|
+
...presentEntity,
|
|
1274
1294
|
etag: this.#getEtag()
|
|
1275
1295
|
});
|
|
1276
1296
|
else this.table.set(key, {
|
|
1277
|
-
...
|
|
1297
|
+
...presentEntity,
|
|
1278
1298
|
etag: this.#getEtag()
|
|
1279
1299
|
});
|
|
1280
1300
|
}
|
|
@@ -1307,4 +1327,4 @@ const applyFilter = (documents, clauses) => {
|
|
|
1307
1327
|
const predicate = createFilterPredicate(serializeClauses(clauses));
|
|
1308
1328
|
return documents.filter((document) => predicate(document));
|
|
1309
1329
|
};
|
|
1310
|
-
export { BLOB_NOT_FOUND_ERROR_CODE, BLOB_NOT_FOUND_MESSAGE, CONDITION_NOT_MET_ERROR_CODE, CONDITION_NOT_MET_MESSAGE, INVALID_INPUT_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, MockWebPubSubDatabase, MockWebPubSubServiceClient, NotImplementedError, applyFilter, assertMockBlobIfMatch, bodyToBuffer, checkIsNullClause, checkIsReadableStream, compare, compareByCompositeKey, compareValues, createFilterPredicate, createMockResponse, decodeSegment, deleteMockBlob, getAzureErrorXml, getBlobItemXml, getBlobPrefixXml, getBlobUrl, getBlobUrlParts, getListBlobsSegmentResponse, getListBlobsXml, getMockBlobKey, getMockContainer, getMockQueueMessageItem, getMockSasUrl, getSearchFieldValues, readMockBlobDates, readMockBlobMetadata, searchDocuments, sortDocuments, storeMockBlobMetadata, storeMockBlobWrite, toComparable, toWebResourceLike };
|
|
1330
|
+
export { BLOB_NOT_FOUND_ERROR_CODE, BLOB_NOT_FOUND_MESSAGE, CONDITION_NOT_MET_ERROR_CODE, CONDITION_NOT_MET_MESSAGE, INVALID_INPUT_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, MockWebPubSubDatabase, MockWebPubSubServiceClient, NotImplementedError, applyFilter, assertMockBlobIfMatch, bodyToBuffer, checkIsNullClause, checkIsReadableStream, compare, compareByCompositeKey, compareValues, createFilterPredicate, createMockResponse, decodeSegment, deleteMockBlob, deserializeDocumentKeys, getAzureErrorXml, getBlobItemXml, getBlobPrefixXml, getBlobUrl, getBlobUrlParts, getListBlobsSegmentResponse, getListBlobsXml, getMockBlobKey, getMockContainer, getMockQueueMessageItem, getMockSasUrl, getSearchFieldValues, readMockBlobDates, readMockBlobMetadata, searchDocuments, selectSearchDocumentFields, sortDocuments, storeMockBlobMetadata, storeMockBlobWrite, toComparable, toWebResourceLike };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "azure-mock",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "A library that contains azure mock classes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"azure",
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"typecheck": "tsrs --fast"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@esposter/azure": "4.
|
|
55
|
-
"@esposter/shared": "4.
|
|
54
|
+
"@esposter/azure": "4.6.0",
|
|
55
|
+
"@esposter/shared": "4.6.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@esposter/configuration": "4.
|
|
59
|
-
"tsdown": "^0.23.
|
|
58
|
+
"@esposter/configuration": "4.6.0",
|
|
59
|
+
"tsdown": "^0.23.7",
|
|
60
60
|
"type-fest": "^5.10.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"inlinedDependencies": {
|
|
73
73
|
"type-fest": "5.10.0"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "0ceea3ffbe12ca69413ea5db2d3cfad197a63cba"
|
|
76
76
|
}
|