azure-mock 2.27.0 → 2.28.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 +61 -12
- package/dist/index.js +149 -24
- package/package.json +10 -9
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ import { BinaryOperator, Clause } from "@esposter/db-schema";
|
|
|
6
6
|
import { EventGridEvent, EventGridPublisherClient } from "@azure/eventgrid";
|
|
7
7
|
import { CreateTableEntityResponse, GetAccessPolicyResponse, GetTableEntityResponse, ListTableEntitiesOptions, TableClient, TableDeleteEntityHeaders, TableEntity, TableEntityResult, TableEntityResultPage, TableMergeEntityHeaders, TableSetAccessPolicyHeaders, TableTransactionResponse, UpdateMode } from "@azure/data-tables";
|
|
8
8
|
import { QueueClearMessagesResponse, QueueClient, QueueCreateIfNotExistsResponse, QueueCreateOptions, QueueCreateResponse, QueueDeleteIfExistsResponse, QueueDeleteMessageResponse, QueueDeleteResponse, QueueGenerateSasUrlOptions, QueueGetAccessPolicyResponse, QueueGetPropertiesResponse, QueueItem, QueuePeekMessagesOptions, QueuePeekMessagesResponse, QueueReceiveMessageOptions, QueueReceiveMessageResponse, QueueSendMessageOptions, QueueSendMessageResponse, QueueServiceProperties, QueueSetAccessPolicyResponse, QueueSetMetadataResponse, QueueUpdateMessageResponse, SignedIdentifier } from "@azure/storage-queue";
|
|
9
|
+
import { AutocompleteResult, CountDocumentsOptions, DeleteDocumentsOptions, GetDocumentOptions, IndexDocumentsBatch, IndexDocumentsOptions, IndexDocumentsResult, MergeDocumentsOptions, MergeOrUploadDocumentsOptions, NarrowedModel, SearchClient, SearchDocumentsResult, SearchOptions, SelectFields, SuggestDocumentsResult, SuggestOptions, UploadDocumentsOptions } from "@azure/search-documents";
|
|
9
10
|
|
|
10
11
|
//#region src/constants.d.ts
|
|
11
12
|
declare const MOCK_BLOB_BASE_URL = "https://mockaccount.blob.core.windows.net";
|
|
12
13
|
declare const MOCK_QUEUE_BASE_URL = "https://mockaccount.queue.core.windows.net";
|
|
14
|
+
declare const MOCK_SEARCH_BASE_URL = "https://mockaccount.search.windows.net";
|
|
13
15
|
declare const MOCK_TABLE_BASE_URL = "https://mockaccount.table.core.windows.net";
|
|
14
16
|
//#endregion
|
|
15
17
|
//#region src/models/MockRestError.d.ts
|
|
@@ -61,6 +63,9 @@ declare const MockEventGridDatabase: Map<string, EventGridEvent<unknown>[]>;
|
|
|
61
63
|
//#region src/store/MockQueueDatabase.d.ts
|
|
62
64
|
declare const MockQueueDatabase: Map<string, string[]>;
|
|
63
65
|
//#endregion
|
|
66
|
+
//#region src/store/MockSearchDatabase.d.ts
|
|
67
|
+
declare const MockSearchDatabase: Map<string, object[]>;
|
|
68
|
+
//#endregion
|
|
64
69
|
//#region src/store/MockTableDatabase.d.ts
|
|
65
70
|
declare const MockTableDatabase: Map<string, Map<string, TableEntity>>;
|
|
66
71
|
//#endregion
|
|
@@ -981,10 +986,12 @@ declare class MockContainerClient implements Except<ContainerClient, "accountNam
|
|
|
981
986
|
/**
|
|
982
987
|
* An in-memory mock of the Azure EventGridPublisherClient.
|
|
983
988
|
* It uses a Map to simulate event grid storage and correctly implements the EventGridPublisherClient interface.
|
|
989
|
+
* `client` is excluded because it is a private member of the real class and cannot be satisfied structurally.
|
|
984
990
|
*/
|
|
985
|
-
declare class MockEventGridPublisherClient implements Except<EventGridPublisherClient<"EventGrid">, "apiVersion"
|
|
986
|
-
|
|
987
|
-
|
|
991
|
+
declare class MockEventGridPublisherClient implements Except<EventGridPublisherClient<"EventGrid">, "apiVersion"> {
|
|
992
|
+
readonly endpointUrl: string;
|
|
993
|
+
readonly inputSchema: "EventGrid";
|
|
994
|
+
readonly topicType: "EventGrid";
|
|
988
995
|
constructor(endpoint: string, topicType: "EventGrid");
|
|
989
996
|
send(newEvents: EventGridEvent<unknown>[]): Promise<void>;
|
|
990
997
|
}
|
|
@@ -1029,6 +1036,36 @@ declare class MockQueueClient implements Except<QueueClient, "accountName"> {
|
|
|
1029
1036
|
updateMessage(): Promise<QueueUpdateMessageResponse>;
|
|
1030
1037
|
}
|
|
1031
1038
|
//#endregion
|
|
1039
|
+
//#region src/models/search/MockSearchClient.d.ts
|
|
1040
|
+
/**
|
|
1041
|
+
* An in-memory mock of the Azure SearchClient.
|
|
1042
|
+
* It uses a Map to simulate the search index and applies the same OData filtering as the other mock clients.
|
|
1043
|
+
*
|
|
1044
|
+
* @example
|
|
1045
|
+
* const mockSearchClient = new MockSearchClient(SearchIndex.Messages);
|
|
1046
|
+
* await mockSearchClient.uploadDocuments([{ ... }]);
|
|
1047
|
+
* const { count, results } = await mockSearchClient.search("*", { filter, includeTotalCount: true });
|
|
1048
|
+
*/
|
|
1049
|
+
declare class MockSearchClient<TModel extends object = Record<string, unknown>> implements Except<SearchClient<TModel>, "pipeline"> {
|
|
1050
|
+
readonly apiVersion: string;
|
|
1051
|
+
readonly endpoint: string;
|
|
1052
|
+
readonly indexName: string;
|
|
1053
|
+
readonly serviceVersion: string;
|
|
1054
|
+
get documents(): MapValue<typeof MockSearchDatabase>;
|
|
1055
|
+
constructor(indexName: string);
|
|
1056
|
+
autocomplete(): Promise<AutocompleteResult>;
|
|
1057
|
+
deleteDocuments(documents: TModel[], options?: DeleteDocumentsOptions): Promise<IndexDocumentsResult>;
|
|
1058
|
+
deleteDocuments(keyName: keyof TModel, keyValues: string[], options?: DeleteDocumentsOptions): Promise<IndexDocumentsResult>;
|
|
1059
|
+
getDocument<TFields extends SelectFields<TModel>>(_key: string, _options?: GetDocumentOptions<TModel, TFields>): Promise<NarrowedModel<TModel, TFields>>;
|
|
1060
|
+
getDocumentsCount(_options?: CountDocumentsOptions): Promise<number>;
|
|
1061
|
+
indexDocuments(_batch: IndexDocumentsBatch<TModel>, _options?: IndexDocumentsOptions): Promise<IndexDocumentsResult>;
|
|
1062
|
+
mergeDocuments(_documents: TModel[], _options?: MergeDocumentsOptions): Promise<IndexDocumentsResult>;
|
|
1063
|
+
mergeOrUploadDocuments(_documents: TModel[], _options?: MergeOrUploadDocumentsOptions): Promise<IndexDocumentsResult>;
|
|
1064
|
+
search<TFields extends SelectFields<TModel>>(searchText?: string, options?: SearchOptions<TModel, TFields>): Promise<SearchDocumentsResult<TModel, TFields>>;
|
|
1065
|
+
suggest<TFields extends SelectFields<TModel> = never>(_searchText: string, _suggesterName: string, _options?: SuggestOptions<TModel, TFields>): Promise<SuggestDocumentsResult<TModel, TFields>>;
|
|
1066
|
+
uploadDocuments(documents: TModel[], _options?: UploadDocumentsOptions): Promise<IndexDocumentsResult>;
|
|
1067
|
+
}
|
|
1068
|
+
//#endregion
|
|
1032
1069
|
//#region src/models/table/MockTableClient.d.ts
|
|
1033
1070
|
/**
|
|
1034
1071
|
* An in-memory mock of the Azure TableClient.
|
|
@@ -1039,7 +1076,8 @@ declare class MockQueueClient implements Except<QueueClient, "accountName"> {
|
|
|
1039
1076
|
* await mockTableClient.createEntity({ partitionKey: "partitionKey", rowKey: "rowKey" });
|
|
1040
1077
|
* const entity = await mockTableClient.getEntity("partitionKey", "rowKey");
|
|
1041
1078
|
*/
|
|
1042
|
-
declare class MockTableClient implements Except<TableClient, "pipeline"> {
|
|
1079
|
+
declare class MockTableClient<TEntity extends TableEntity = TableEntity> implements Except<TableClient, "pipeline"> {
|
|
1080
|
+
entityType: TEntity;
|
|
1043
1081
|
tableName: string;
|
|
1044
1082
|
url: string;
|
|
1045
1083
|
get table(): MapValue<typeof MockTableDatabase>;
|
|
@@ -1061,6 +1099,17 @@ declare class MockTableClient implements Except<TableClient, "pipeline"> {
|
|
|
1061
1099
|
private withMetadata;
|
|
1062
1100
|
}
|
|
1063
1101
|
//#endregion
|
|
1102
|
+
//#region src/models/webPubSub/MockWebPubSubServiceClient.d.ts
|
|
1103
|
+
/**
|
|
1104
|
+
* A minimal mock of the Azure WebPubSubServiceClient for testing purposes.
|
|
1105
|
+
* Only implements `group().sendToAll` — the only method used in azure-functions tests.
|
|
1106
|
+
*/
|
|
1107
|
+
declare class MockWebPubSubServiceClient {
|
|
1108
|
+
group(_groupName: string): {
|
|
1109
|
+
sendToAll: () => Promise<void>;
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
//#endregion
|
|
1064
1113
|
//#region src/services/container/bodyToBuffer.d.ts
|
|
1065
1114
|
declare const bodyToBuffer: (body: HttpRequestBody) => Promise<Buffer>;
|
|
1066
1115
|
//#endregion
|
|
@@ -1097,16 +1146,16 @@ declare const isReadableStream: (value: unknown) => value is NodeJS.ReadableStre
|
|
|
1097
1146
|
//#region src/services/container/toWebResourceLike.d.ts
|
|
1098
1147
|
declare const toWebResourceLike: (request: PipelineRequest) => WebResourceLike;
|
|
1099
1148
|
//#endregion
|
|
1100
|
-
//#region src/services/
|
|
1101
|
-
declare const
|
|
1149
|
+
//#region src/services/filter/applyFilter.d.ts
|
|
1150
|
+
declare const applyFilter: <T extends Record<string, unknown>>(documents: T[], clauses: Clause<T>[]) => T[];
|
|
1102
1151
|
//#endregion
|
|
1103
|
-
//#region src/services/
|
|
1152
|
+
//#region src/services/filter/compare.d.ts
|
|
1104
1153
|
declare const compare: <T>(operator: BinaryOperator, leftHandSide: T, rightHandSide: null | T) => boolean;
|
|
1105
1154
|
//#endregion
|
|
1106
|
-
//#region src/services/
|
|
1107
|
-
declare const
|
|
1155
|
+
//#region src/services/filter/createFilterPredicate.d.ts
|
|
1156
|
+
declare const createFilterPredicate: (filter: string) => ((document: Record<string, unknown>) => boolean);
|
|
1108
1157
|
//#endregion
|
|
1109
|
-
//#region src/services/
|
|
1110
|
-
declare const
|
|
1158
|
+
//#region src/services/filter/isNullClause.d.ts
|
|
1159
|
+
declare const isNullClause: (clause: Clause<Record<string, unknown>>) => boolean;
|
|
1111
1160
|
//#endregion
|
|
1112
|
-
export { BlobHierarchyItem, MOCK_BLOB_BASE_URL, MOCK_QUEUE_BASE_URL, MOCK_TABLE_BASE_URL, MockBlobBatchClient, MockBlobClient, MockBlockBlobClient, MockContainerClient, MockContainerDatabase, MockEventGridDatabase, MockEventGridPublisherClient, MockQueueClient, MockQueueDatabase, MockRestError, MockTableClient, MockTableDatabase, PageSettings, PagedAsyncIterableIterator,
|
|
1161
|
+
export { BlobHierarchyItem, MOCK_BLOB_BASE_URL, MOCK_QUEUE_BASE_URL, MOCK_SEARCH_BASE_URL, MOCK_TABLE_BASE_URL, MockBlobBatchClient, MockBlobClient, MockBlockBlobClient, MockContainerClient, MockContainerDatabase, MockEventGridDatabase, MockEventGridPublisherClient, MockQueueClient, MockQueueDatabase, MockRestError, MockSearchClient, MockSearchDatabase, MockTableClient, MockTableDatabase, MockWebPubSubServiceClient, PageSettings, PagedAsyncIterableIterator, applyFilter, bodyToBuffer, compare, createFilterPredicate, getAzureErrorXml, getBlobItemXml, getBlobPrefixXml, getListBlobsXml, isNullClause, isReadableStream, toWebResourceLike };
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { toHttpHeadersLike } from "@azure/core-http-compat";
|
|
|
3
3
|
import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
|
|
4
4
|
import { AnonymousCredential } from "@azure/storage-blob";
|
|
5
5
|
import { Readable } from "node:stream";
|
|
6
|
+
import { MAX_QUEUE_VISIBILITY_TIMEOUT_MS, deserializeClause, deserializeKey, getTableNullClause, serializeClauses } from "@esposter/db";
|
|
6
7
|
import { BinaryOperator } from "@esposter/db-schema";
|
|
7
|
-
import { deserializeClause, getTableNullClause, serializeClauses } from "@esposter/db";
|
|
8
8
|
//#region \0rolldown/runtime.js
|
|
9
9
|
var __create = Object.create;
|
|
10
10
|
var __defProp = Object.defineProperty;
|
|
@@ -31,6 +31,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
31
31
|
//#region src/constants.ts
|
|
32
32
|
const MOCK_BLOB_BASE_URL = "https://mockaccount.blob.core.windows.net";
|
|
33
33
|
const MOCK_QUEUE_BASE_URL = "https://mockaccount.queue.core.windows.net";
|
|
34
|
+
const MOCK_SEARCH_BASE_URL = "https://mockaccount.search.windows.net";
|
|
34
35
|
const MOCK_TABLE_BASE_URL = "https://mockaccount.table.core.windows.net";
|
|
35
36
|
//#endregion
|
|
36
37
|
//#region src/models/MockRestError.ts
|
|
@@ -52,6 +53,9 @@ const MockEventGridDatabase = /* @__PURE__ */ new Map();
|
|
|
52
53
|
//#region src/store/MockQueueDatabase.ts
|
|
53
54
|
const MockQueueDatabase = /* @__PURE__ */ new Map();
|
|
54
55
|
//#endregion
|
|
56
|
+
//#region src/store/MockSearchDatabase.ts
|
|
57
|
+
const MockSearchDatabase = /* @__PURE__ */ new Map();
|
|
58
|
+
//#endregion
|
|
55
59
|
//#region src/store/MockTableDatabase.ts
|
|
56
60
|
const MockTableDatabase = /* @__PURE__ */ new Map();
|
|
57
61
|
//#endregion
|
|
@@ -711,18 +715,21 @@ var MockContainerClient = class {
|
|
|
711
715
|
/**
|
|
712
716
|
* An in-memory mock of the Azure EventGridPublisherClient.
|
|
713
717
|
* It uses a Map to simulate event grid storage and correctly implements the EventGridPublisherClient interface.
|
|
718
|
+
* `client` is excluded because it is a private member of the real class and cannot be satisfied structurally.
|
|
714
719
|
*/
|
|
715
720
|
var MockEventGridPublisherClient = class {
|
|
716
|
-
|
|
721
|
+
endpointUrl;
|
|
722
|
+
inputSchema;
|
|
717
723
|
topicType;
|
|
718
724
|
constructor(endpoint, topicType) {
|
|
719
|
-
this.
|
|
725
|
+
this.endpointUrl = endpoint;
|
|
720
726
|
this.topicType = topicType;
|
|
727
|
+
this.inputSchema = topicType;
|
|
721
728
|
}
|
|
722
729
|
send(newEvents) {
|
|
723
|
-
const events = MockEventGridDatabase.get(this.
|
|
730
|
+
const events = MockEventGridDatabase.get(this.endpointUrl) ?? [];
|
|
724
731
|
events.push(...newEvents);
|
|
725
|
-
MockEventGridDatabase.set(this.
|
|
732
|
+
MockEventGridDatabase.set(this.endpointUrl, events);
|
|
726
733
|
return Promise.resolve();
|
|
727
734
|
}
|
|
728
735
|
};
|
|
@@ -804,7 +811,7 @@ var MockQueueClient = class {
|
|
|
804
811
|
peekMessages(_options) {
|
|
805
812
|
const peekedMessageItems = this.queue.map((text) => ({
|
|
806
813
|
dequeueCount: 0,
|
|
807
|
-
expiresOn: new Date(Date.now() +
|
|
814
|
+
expiresOn: new Date(Date.now() + MAX_QUEUE_VISIBILITY_TIMEOUT_MS),
|
|
808
815
|
insertedOn: /* @__PURE__ */ new Date(),
|
|
809
816
|
messageId: crypto.randomUUID(),
|
|
810
817
|
messageText: text
|
|
@@ -824,7 +831,7 @@ var MockQueueClient = class {
|
|
|
824
831
|
receiveMessages(_options) {
|
|
825
832
|
const receivedMessageItems = this.queue.splice(0).map((text) => ({
|
|
826
833
|
dequeueCount: 1,
|
|
827
|
-
expiresOn: new Date(Date.now() +
|
|
834
|
+
expiresOn: new Date(Date.now() + MAX_QUEUE_VISIBILITY_TIMEOUT_MS),
|
|
828
835
|
insertedOn: /* @__PURE__ */ new Date(),
|
|
829
836
|
messageId: crypto.randomUUID(),
|
|
830
837
|
messageText: text,
|
|
@@ -846,7 +853,7 @@ var MockQueueClient = class {
|
|
|
846
853
|
sendMessage(messageText, _options) {
|
|
847
854
|
this.queue.push(messageText);
|
|
848
855
|
const now = /* @__PURE__ */ new Date();
|
|
849
|
-
const expiresOn = new Date(now.getTime() +
|
|
856
|
+
const expiresOn = new Date(now.getTime() + MAX_QUEUE_VISIBILITY_TIMEOUT_MS);
|
|
850
857
|
const insertedOn = now;
|
|
851
858
|
const messageId = crypto.randomUUID();
|
|
852
859
|
const nextVisibleOn = now;
|
|
@@ -885,7 +892,7 @@ var MockQueueClient = class {
|
|
|
885
892
|
}
|
|
886
893
|
};
|
|
887
894
|
//#endregion
|
|
888
|
-
//#region src/services/
|
|
895
|
+
//#region src/services/filter/compare.ts
|
|
889
896
|
const compare = (operator, leftHandSide, rightHandSide) => {
|
|
890
897
|
if (rightHandSide === null || rightHandSide === void 0) {
|
|
891
898
|
if (operator !== BinaryOperator.eq) throw new InvalidOperationError(Operation.Read, compare.name, JSON.stringify({
|
|
@@ -893,7 +900,7 @@ const compare = (operator, leftHandSide, rightHandSide) => {
|
|
|
893
900
|
operator,
|
|
894
901
|
rightHandSide
|
|
895
902
|
}));
|
|
896
|
-
return leftHandSide ===
|
|
903
|
+
return leftHandSide === null || leftHandSide === void 0;
|
|
897
904
|
}
|
|
898
905
|
switch (operator) {
|
|
899
906
|
case BinaryOperator.eq: return leftHandSide === rightHandSide;
|
|
@@ -906,7 +913,7 @@ const compare = (operator, leftHandSide, rightHandSide) => {
|
|
|
906
913
|
}
|
|
907
914
|
};
|
|
908
915
|
//#endregion
|
|
909
|
-
//#region src/services/
|
|
916
|
+
//#region src/services/filter/isNullClause.ts
|
|
910
917
|
var import_fast_deep_equal = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
911
918
|
module.exports = function equal(a, b) {
|
|
912
919
|
if (a === b) return true;
|
|
@@ -935,21 +942,21 @@ var import_fast_deep_equal = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJS
|
|
|
935
942
|
return a !== a && b !== b;
|
|
936
943
|
};
|
|
937
944
|
})))(), 1);
|
|
938
|
-
const
|
|
945
|
+
const isNullClause = (clause) => {
|
|
939
946
|
return (0, import_fast_deep_equal.default)(clause, getTableNullClause(clause.key));
|
|
940
947
|
};
|
|
941
948
|
//#endregion
|
|
942
|
-
//#region src/services/
|
|
943
|
-
const
|
|
949
|
+
//#region src/services/filter/createFilterPredicate.ts
|
|
950
|
+
const createFilterPredicate = (filter) => {
|
|
944
951
|
const orGroups = filter.replaceAll(String.raw`(`, " ").replaceAll(String.raw`)`, "").split(/\s+and\s+/iu).filter(Boolean).map((group) => group.split(/\s+or\s+/iu).filter(Boolean));
|
|
945
|
-
return (
|
|
952
|
+
return (document) => {
|
|
946
953
|
for (const orGroup of orGroups) {
|
|
947
954
|
let isGroupMatched = false;
|
|
948
955
|
for (const group of orGroup) {
|
|
949
956
|
const clause = deserializeClause(group);
|
|
950
|
-
const value = takeOne(
|
|
951
|
-
let isMatched
|
|
952
|
-
if (
|
|
957
|
+
const value = takeOne(document, clause.key);
|
|
958
|
+
let isMatched;
|
|
959
|
+
if (isNullClause(clause)) isMatched = compare(BinaryOperator.eq, value, null);
|
|
953
960
|
else {
|
|
954
961
|
const comparisonResult = compare(clause.operator, value, clause.value);
|
|
955
962
|
isMatched = clause.not ? !comparisonResult : comparisonResult;
|
|
@@ -965,6 +972,112 @@ const createTableFilterPredicate = (filter) => {
|
|
|
965
972
|
};
|
|
966
973
|
};
|
|
967
974
|
//#endregion
|
|
975
|
+
//#region src/models/search/MockSearchClient.ts
|
|
976
|
+
const toComparable = (value) => {
|
|
977
|
+
if (value instanceof Date) return value.getTime();
|
|
978
|
+
else if (typeof value === "number" || typeof value === "string") return value;
|
|
979
|
+
else return String(value);
|
|
980
|
+
};
|
|
981
|
+
const compareValues = (leftHandSide, rightHandSide) => {
|
|
982
|
+
const left = toComparable(leftHandSide);
|
|
983
|
+
const right = toComparable(rightHandSide);
|
|
984
|
+
if (typeof left === "number" && typeof right === "number") return left - right;
|
|
985
|
+
return String(left).localeCompare(String(right));
|
|
986
|
+
};
|
|
987
|
+
const sortDocuments = (documents, orderBy) => [...documents].toSorted((leftHandSide, rightHandSide) => {
|
|
988
|
+
for (const clause of orderBy) {
|
|
989
|
+
const [field = "", direction = "asc"] = clause.split(/\s+/u);
|
|
990
|
+
const key = deserializeKey(field);
|
|
991
|
+
const comparison = compareValues(leftHandSide[key], rightHandSide[key]);
|
|
992
|
+
if (comparison !== 0) return direction === "desc" ? -comparison : comparison;
|
|
993
|
+
}
|
|
994
|
+
return 0;
|
|
995
|
+
});
|
|
996
|
+
const getSearchFieldValues = (value, pathSegments) => {
|
|
997
|
+
if (pathSegments.length === 0) return [value];
|
|
998
|
+
if (Array.isArray(value)) return value.flatMap((item) => getSearchFieldValues(item, pathSegments));
|
|
999
|
+
if (typeof value !== "object" || value === null) return [];
|
|
1000
|
+
const [field = "", ...remainingPathSegments] = pathSegments;
|
|
1001
|
+
return getSearchFieldValues(value[deserializeKey(field)], remainingPathSegments);
|
|
1002
|
+
};
|
|
1003
|
+
const searchDocuments = (documents, searchText, searchFields) => {
|
|
1004
|
+
if (!searchText || searchText === "*") return documents;
|
|
1005
|
+
const normalizedSearchText = searchText.toLocaleLowerCase();
|
|
1006
|
+
return documents.filter((document) => (searchFields ?? Object.keys(document)).some((searchField) => getSearchFieldValues(document, searchField.split("/")).some((value) => value !== null && value !== void 0 && String(value).toLocaleLowerCase().includes(normalizedSearchText))));
|
|
1007
|
+
};
|
|
1008
|
+
/**
|
|
1009
|
+
* An in-memory mock of the Azure SearchClient.
|
|
1010
|
+
* It uses a Map to simulate the search index and applies the same OData filtering as the other mock clients.
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* const mockSearchClient = new MockSearchClient(SearchIndex.Messages);
|
|
1014
|
+
* await mockSearchClient.uploadDocuments([{ ... }]);
|
|
1015
|
+
* const { count, results } = await mockSearchClient.search("*", { filter, includeTotalCount: true });
|
|
1016
|
+
*/
|
|
1017
|
+
var MockSearchClient = class {
|
|
1018
|
+
apiVersion = "";
|
|
1019
|
+
endpoint = MOCK_SEARCH_BASE_URL;
|
|
1020
|
+
indexName;
|
|
1021
|
+
serviceVersion = "";
|
|
1022
|
+
get documents() {
|
|
1023
|
+
let documents = MockSearchDatabase.get(this.indexName);
|
|
1024
|
+
if (!documents) {
|
|
1025
|
+
documents = [];
|
|
1026
|
+
MockSearchDatabase.set(this.indexName, documents);
|
|
1027
|
+
}
|
|
1028
|
+
return documents;
|
|
1029
|
+
}
|
|
1030
|
+
constructor(indexName) {
|
|
1031
|
+
this.indexName = indexName;
|
|
1032
|
+
}
|
|
1033
|
+
autocomplete() {
|
|
1034
|
+
throw new Error("Method not implemented.");
|
|
1035
|
+
}
|
|
1036
|
+
deleteDocuments() {
|
|
1037
|
+
throw new Error("Method not implemented.");
|
|
1038
|
+
}
|
|
1039
|
+
getDocument(_key, _options) {
|
|
1040
|
+
throw new Error("Method not implemented.");
|
|
1041
|
+
}
|
|
1042
|
+
getDocumentsCount(_options) {
|
|
1043
|
+
return Promise.resolve(this.documents.length);
|
|
1044
|
+
}
|
|
1045
|
+
indexDocuments(_batch, _options) {
|
|
1046
|
+
throw new Error("Method not implemented.");
|
|
1047
|
+
}
|
|
1048
|
+
mergeDocuments(_documents, _options) {
|
|
1049
|
+
throw new Error("Method not implemented.");
|
|
1050
|
+
}
|
|
1051
|
+
mergeOrUploadDocuments(_documents, _options) {
|
|
1052
|
+
throw new Error("Method not implemented.");
|
|
1053
|
+
}
|
|
1054
|
+
search(searchText, options) {
|
|
1055
|
+
const { filter, includeTotalCount, orderBy, searchFields, skip = 0, top } = options ?? {};
|
|
1056
|
+
let documents = searchDocuments(this.documents, searchText, searchFields);
|
|
1057
|
+
if (filter) {
|
|
1058
|
+
const predicate = createFilterPredicate(filter);
|
|
1059
|
+
documents = documents.filter((document) => predicate(document));
|
|
1060
|
+
}
|
|
1061
|
+
if (orderBy) documents = sortDocuments(documents, orderBy);
|
|
1062
|
+
const count = documents.length;
|
|
1063
|
+
const paginatedDocuments = documents.slice(skip, top === void 0 ? void 0 : skip + top);
|
|
1064
|
+
const results = { async *[Symbol.asyncIterator]() {
|
|
1065
|
+
for (const document of paginatedDocuments) yield { document };
|
|
1066
|
+
} };
|
|
1067
|
+
return Promise.resolve({
|
|
1068
|
+
...includeTotalCount ? { count } : {},
|
|
1069
|
+
results
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
suggest(_searchText, _suggesterName, _options) {
|
|
1073
|
+
throw new Error("Method not implemented.");
|
|
1074
|
+
}
|
|
1075
|
+
uploadDocuments(documents, _options) {
|
|
1076
|
+
this.documents.push(...documents);
|
|
1077
|
+
return Promise.resolve({ results: [] });
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
//#endregion
|
|
968
1081
|
//#region src/models/table/MockTableClient.ts
|
|
969
1082
|
/**
|
|
970
1083
|
* An in-memory mock of the Azure TableClient.
|
|
@@ -1027,7 +1140,8 @@ var MockTableClient = class {
|
|
|
1027
1140
|
const withMetadata = this.withMetadata.bind(this);
|
|
1028
1141
|
const filter = options?.queryOptions?.filter;
|
|
1029
1142
|
const tableEntities = [...this.table.values()];
|
|
1030
|
-
const
|
|
1143
|
+
const predicate = filter ? createFilterPredicate(filter) : void 0;
|
|
1144
|
+
const resultTableEntities = predicate ? tableEntities.filter((e) => predicate(e)) : tableEntities;
|
|
1031
1145
|
return {
|
|
1032
1146
|
byPage: ({ maxPageSize } = {}) => (async function* (entities) {
|
|
1033
1147
|
if (maxPageSize !== void 0 && maxPageSize <= 0) throw new RangeError("maxPageSize must be greater than 0.");
|
|
@@ -1132,10 +1246,21 @@ var MockTableClient = class {
|
|
|
1132
1246
|
}
|
|
1133
1247
|
};
|
|
1134
1248
|
//#endregion
|
|
1135
|
-
//#region src/
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1249
|
+
//#region src/models/webPubSub/MockWebPubSubServiceClient.ts
|
|
1250
|
+
/**
|
|
1251
|
+
* A minimal mock of the Azure WebPubSubServiceClient for testing purposes.
|
|
1252
|
+
* Only implements `group().sendToAll` — the only method used in azure-functions tests.
|
|
1253
|
+
*/
|
|
1254
|
+
var MockWebPubSubServiceClient = class {
|
|
1255
|
+
group(_groupName) {
|
|
1256
|
+
return { sendToAll: () => Promise.resolve() };
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
//#endregion
|
|
1260
|
+
//#region src/services/filter/applyFilter.ts
|
|
1261
|
+
const applyFilter = (documents, clauses) => {
|
|
1262
|
+
const predicate = createFilterPredicate(serializeClauses(clauses));
|
|
1263
|
+
return documents.filter((document) => predicate(document));
|
|
1139
1264
|
};
|
|
1140
1265
|
//#endregion
|
|
1141
|
-
export { MOCK_BLOB_BASE_URL, MOCK_QUEUE_BASE_URL, MOCK_TABLE_BASE_URL, MockBlobBatchClient, MockBlobClient, MockBlockBlobClient, MockContainerClient, MockContainerDatabase, MockEventGridDatabase, MockEventGridPublisherClient, MockQueueClient, MockQueueDatabase, MockRestError, MockTableClient, MockTableDatabase,
|
|
1266
|
+
export { MOCK_BLOB_BASE_URL, MOCK_QUEUE_BASE_URL, MOCK_SEARCH_BASE_URL, MOCK_TABLE_BASE_URL, MockBlobBatchClient, MockBlobClient, MockBlockBlobClient, MockContainerClient, MockContainerDatabase, MockEventGridDatabase, MockEventGridPublisherClient, MockQueueClient, MockQueueDatabase, MockRestError, MockSearchClient, MockSearchDatabase, MockTableClient, MockTableDatabase, MockWebPubSubServiceClient, applyFilter, bodyToBuffer, compare, createFilterPredicate, getAzureErrorXml, getBlobItemXml, getBlobPrefixXml, getListBlobsXml, isNullClause, isReadableStream, toWebResourceLike };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "azure-mock",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.28.0",
|
|
4
4
|
"description": "A library that contains azure mock classes.",
|
|
5
5
|
"homepage": "https://github.com/Esposter/Esposter#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -33,26 +33,27 @@
|
|
|
33
33
|
"typecheck": "tsgo"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@esposter/db": "2.
|
|
37
|
-
"@esposter/db-schema": "2.
|
|
38
|
-
"@esposter/shared": "2.
|
|
36
|
+
"@esposter/db": "2.28.0",
|
|
37
|
+
"@esposter/db-schema": "2.28.0",
|
|
38
|
+
"@esposter/shared": "2.28.0",
|
|
39
39
|
"fast-deep-equal": "^3.1.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@esposter/configuration": "2.
|
|
42
|
+
"@esposter/configuration": "2.28.0",
|
|
43
43
|
"@vitest/coverage-v8": "^4.1.8",
|
|
44
44
|
"ctix": "^2.8.1",
|
|
45
|
-
"rolldown": "^1.1.
|
|
45
|
+
"rolldown": "^1.1.1",
|
|
46
46
|
"type-fest": "^5.7.0",
|
|
47
47
|
"vitest": "^4.1.8"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@azure/core-http-compat": "^2.4.0",
|
|
51
|
-
"@azure/core-rest-pipeline": "^1.
|
|
51
|
+
"@azure/core-rest-pipeline": "^1.24.0",
|
|
52
52
|
"@azure/data-tables": "^13.3.2",
|
|
53
53
|
"@azure/eventgrid": "^5.12.0",
|
|
54
|
+
"@azure/search-documents": "^13.0.0",
|
|
54
55
|
"@azure/storage-blob": "^12.32.0",
|
|
55
|
-
"@azure/storage-queue": "^12.
|
|
56
|
+
"@azure/storage-queue": "^12.30.0"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "c633ee2d9e27aa520d3487a179982249463032a0"
|
|
58
59
|
}
|