azure-mock 2.22.0 → 2.23.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
@@ -5080,7 +5080,7 @@ declare class MockTableClient implements Except<TableClient, "pipeline"> {
5080
5080
  getEntity<T extends object = Record<string, unknown>>(partitionKey: string, rowKey: string): Promise<GetTableEntityResponse<TableEntityResult<T>>>;
5081
5081
  listEntities<T extends object>(options?: ListTableEntitiesOptions): PagedAsyncIterableIterator<TableEntityResult<T>, TableEntityResultPage<T>>;
5082
5082
  setAccessPolicy(): Promise<TableSetAccessPolicyHeaders>;
5083
- submitTransaction(): Promise<TableTransactionResponse>;
5083
+ submitTransaction(actions: Parameters<TableClient["submitTransaction"]>[0]): Promise<TableTransactionResponse>;
5084
5084
  updateEntity<T extends object>(entity: TableEntity<T>, mode?: UpdateMode): Promise<TableMergeEntityHeaders>;
5085
5085
  upsertEntity<T extends object>(entity: TableEntity<T>, mode?: UpdateMode): Promise<TableMergeEntityHeaders>;
5086
5086
  private getCompositeKey;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { ID_SEPARATOR, InvalidOperationError, NotFoundError, Operation, capitalize, exhaustiveGuard, html, streamToText, takeOne, uncapitalize } from "@esposter/shared";
2
+ import { ID_SEPARATOR, InvalidOperationError, NotFoundError, Operation, capitalize, exhaustiveGuard, getResultAsync, html, noop, normalizeString, streamToText, takeOne, uncapitalize } from "@esposter/shared";
3
3
  import { Readable } from "node:stream";
4
4
  import { AnonymousCredential } from "@azure/storage-blob";
5
5
  import { BinaryOperator, BinaryOperators, CompositeKeyPropertyNames, SearchOperator, UnaryOperator, serializeValue } from "@esposter/db-schema";
@@ -373,7 +373,7 @@ const toWebResourceLike = (request) => ({
373
373
  streamResponseStatusCodes: request.streamResponseStatusCodes,
374
374
  timeout: request.timeout,
375
375
  url: request.url,
376
- validateRequestProperties: () => {},
376
+ validateRequestProperties: noop,
377
377
  withCredentials: request.withCredentials
378
378
  });
379
379
  //#endregion
@@ -517,10 +517,10 @@ var MockBlobClient = class {
517
517
  getResult: () => response,
518
518
  isDone: () => true,
519
519
  isStopped: () => false,
520
- onProgress: () => () => {},
520
+ onProgress: () => noop,
521
521
  poll: () => Promise.resolve(),
522
522
  pollUntilDone: () => Promise.resolve(response),
523
- stopPolling: () => {}
523
+ stopPolling: noop
524
524
  });
525
525
  }
526
526
  createSnapshot() {
@@ -10259,7 +10259,6 @@ function getEscaper$1(regex, map) {
10259
10259
  return result + data.substring(lastIdx);
10260
10260
  };
10261
10261
  }
10262
- getEscaper$1(/[&<>'"]/g, xmlCodeMap);
10263
10262
  /**
10264
10263
  * Encodes all characters that have to be escaped in HTML attributes,
10265
10264
  * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}.
@@ -13242,19 +13241,6 @@ function compileGeneralSelector(next, selector, options, context, compileToken)
13242
13241
  return next;
13243
13242
  }
13244
13243
  }
13245
- /**
13246
- * Compiles a selector to an executable function.
13247
- *
13248
- * @param selector Selector to compile.
13249
- * @param options Compilation options.
13250
- * @param context Optional context for the selector.
13251
- */
13252
- function compile$1(selector, options, context) {
13253
- return ensureIsTag(compileUnsafe(selector, options, context), options.adapter);
13254
- }
13255
- function compileUnsafe(selector, options, context) {
13256
- return compileToken(typeof selector === "string" ? (0, import_commonjs.parse)(selector) : selector, options, context);
13257
- }
13258
13244
  function includesScopePseudo(t) {
13259
13245
  return t.type === import_commonjs.SelectorType.Pseudo && (t.name === "scope" || Array.isArray(t.data) && t.data.some((data) => data.some(includesScopePseudo)));
13260
13246
  }
@@ -13324,17 +13310,7 @@ function wrapCompile(func) {
13324
13310
  return func(selector, convertOptionFormats(options), context);
13325
13311
  };
13326
13312
  }
13327
- wrapCompile(compile$1);
13328
- wrapCompile(compileUnsafe);
13329
13313
  const _compileToken = wrapCompile(compileToken);
13330
- function getSelectorFunc(searchFunc) {
13331
- return function select(query, elements, options) {
13332
- const opts = convertOptionFormats(options);
13333
- if (typeof query !== "function") query = compileUnsafe(query, opts, elements);
13334
- const filteredElements = prepareContext(elements, opts.adapter, query.shouldTestNextSiblings);
13335
- return searchFunc(query, filteredElements, opts);
13336
- };
13337
- }
13338
13314
  function prepareContext(elems, adapter, shouldTestNextSiblings = false) {
13339
13315
  if (shouldTestNextSiblings) elems = appendNextSiblings(elems, adapter);
13340
13316
  return Array.isArray(elems) ? adapter.removeSubsets(elems) : adapter.getChildren(elems);
@@ -13348,8 +13324,6 @@ function appendNextSiblings(elem, adapter) {
13348
13324
  }
13349
13325
  return elems;
13350
13326
  }
13351
- getSelectorFunc((query, elems, options) => query === import_boolbase.default.falseFunc || !elems || elems.length === 0 ? [] : options.adapter.findAll(query, elems));
13352
- getSelectorFunc((query, elems, options) => query === import_boolbase.default.falseFunc || !elems || elems.length === 0 ? null : options.adapter.findOne(query, elems));
13353
13327
  const filterNames = new Set([
13354
13328
  "first",
13355
13329
  "last",
@@ -36476,8 +36450,8 @@ const VALUE_REGEX = [
36476
36450
  String.raw`-?\d+(?:\.\d+)?`,
36477
36451
  String(NaN),
36478
36452
  "'[^']*'"
36479
- ].join("|");
36480
- const CLAUSE_REGEX = new RegExp(`^(?<not>not\\s+)?(?<key>[A-Za-z0-9_]*)\\s*(?<operator>${[...BinaryOperators].join("|")})\\s+(?<value>${VALUE_REGEX})$`, "i");
36453
+ ].join(ID_SEPARATOR);
36454
+ const CLAUSE_REGEX = new RegExp(String.raw`^(?<not>not\s+)?(?<key>[A-Za-z0-9_]*)\s*(?<operator>${[...BinaryOperators].join(ID_SEPARATOR)})\s+(?<value>${VALUE_REGEX})$`, "iu");
36481
36455
  const deserializeValue = (string) => {
36482
36456
  if (string === String(true)) return true;
36483
36457
  else if (string === String(false)) return false;
@@ -36492,11 +36466,11 @@ const deserializeValue = (string) => {
36492
36466
  }
36493
36467
  };
36494
36468
  const deserializeClause = (string) => {
36495
- const trimmedString = string.trim();
36496
- const match = CLAUSE_REGEX.exec(trimmedString);
36497
- if (!match) throw new NotFoundError(deserializeClause.name, trimmedString);
36469
+ const normalizedString = normalizeString(string);
36470
+ const match = CLAUSE_REGEX.exec(normalizedString);
36471
+ if (!match) throw new NotFoundError(deserializeClause.name, normalizedString);
36498
36472
  const groups = match.groups;
36499
- if (!groups) throw new NotFoundError(deserializeClause.name, trimmedString);
36473
+ if (!groups) throw new NotFoundError(deserializeClause.name, normalizedString);
36500
36474
  return {
36501
36475
  key: deserializeKey(groups.key),
36502
36476
  not: Boolean(groups.not),
@@ -36573,7 +36547,7 @@ const isTableNullClause = (clause) => {
36573
36547
  //#endregion
36574
36548
  //#region src/services/table/createTableFilterPredicate.ts
36575
36549
  const createTableFilterPredicate = (filter) => {
36576
- const orGroups = filter.replaceAll(String.raw`(`, " ").replaceAll(String.raw`)`, "").split(/\s+and\s+/i).filter(Boolean).map((group) => group.split(/\s+or\s+/i).filter(Boolean));
36550
+ 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));
36577
36551
  return (entity) => {
36578
36552
  for (const orGroup of orGroups) {
36579
36553
  let isGroupMatched = false;
@@ -36661,9 +36635,15 @@ var MockTableClient = class {
36661
36635
  const tableEntities = [...this.table.values()];
36662
36636
  const resultTableEntities = filter ? tableEntities.filter((e) => createTableFilterPredicate(filter)(e)) : tableEntities;
36663
36637
  return {
36664
- byPage: () => (async function* (entities) {
36638
+ byPage: ({ maxPageSize } = {}) => (async function* (entities) {
36639
+ if (maxPageSize !== void 0 && maxPageSize <= 0) throw new RangeError("maxPageSize must be greater than 0.");
36665
36640
  const allEntitiesWithMetadata = entities.map((e) => withMetadata(e));
36666
- if (allEntitiesWithMetadata.length > 0) yield await Promise.resolve(allEntitiesWithMetadata);
36641
+ if (allEntitiesWithMetadata.length === 0) return;
36642
+ else if (!maxPageSize) {
36643
+ yield await Promise.resolve(allEntitiesWithMetadata);
36644
+ return;
36645
+ }
36646
+ for (let i = 0; i < allEntitiesWithMetadata.length; i += maxPageSize) yield await Promise.resolve(allEntitiesWithMetadata.slice(i, i + maxPageSize));
36667
36647
  })(resultTableEntities),
36668
36648
  next: () => (async function* (entities) {
36669
36649
  for (const entity of entities) yield await Promise.resolve(withMetadata(entity));
@@ -36676,8 +36656,38 @@ var MockTableClient = class {
36676
36656
  setAccessPolicy() {
36677
36657
  throw new Error("Method not implemented.");
36678
36658
  }
36679
- submitTransaction() {
36680
- throw new Error("Method not implemented.");
36659
+ async submitTransaction(actions) {
36660
+ let partitionKey;
36661
+ for (const [, entity] of actions) if (partitionKey === void 0) partitionKey = entity.partitionKey;
36662
+ else if (entity.partitionKey !== partitionKey) throw new MockRestError("All transaction actions must target the same partitionKey.", 400);
36663
+ const snapshot = new Map(this.table);
36664
+ await getResultAsync(async () => {
36665
+ for (const [type, entity, updateMode] of actions) switch (type) {
36666
+ case "create":
36667
+ await this.createEntity(entity);
36668
+ break;
36669
+ case "delete":
36670
+ await this.deleteEntity(entity.partitionKey, entity.rowKey);
36671
+ break;
36672
+ case "update":
36673
+ await this.updateEntity(entity, updateMode);
36674
+ break;
36675
+ case "upsert":
36676
+ await this.upsertEntity(entity, updateMode);
36677
+ break;
36678
+ default: exhaustiveGuard(type);
36679
+ }
36680
+ }).orTee(() => {
36681
+ this.table.clear();
36682
+ for (const [key, value] of snapshot) this.table.set(key, value);
36683
+ }).match(noop, (error) => {
36684
+ throw error;
36685
+ });
36686
+ return {
36687
+ getResponseForEntity: noop,
36688
+ status: 202,
36689
+ subResponses: []
36690
+ };
36681
36691
  }
36682
36692
  updateEntity(entity, mode = "Merge") {
36683
36693
  const key = this.getCompositeKey(entity.partitionKey, entity.rowKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azure-mock",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "A library that contains azure mock classes.",
5
5
  "homepage": "https://github.com/Esposter/Esposter#readme",
6
6
  "bugs": {
@@ -33,12 +33,12 @@
33
33
  "typecheck": "tsgo"
34
34
  },
35
35
  "dependencies": {
36
- "@esposter/db": "2.22.0",
37
- "@esposter/db-schema": "2.22.0",
38
- "@esposter/shared": "2.22.0",
39
- "drizzle-orm": "1.0.0-beta.23",
36
+ "@esposter/db": "2.23.0",
37
+ "@esposter/db-schema": "2.23.0",
38
+ "@esposter/shared": "2.23.0",
39
+ "drizzle-orm": "1.0.0-rc.2",
40
40
  "fast-deep-equal": "^3.1.3",
41
- "zod": "^4.3.6"
41
+ "zod": "^4.4.3"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@azure/core-http-compat": "^2.4.0",
@@ -49,5 +49,5 @@
49
49
  "@azure/storage-queue": "^12.29.0",
50
50
  "@azure/web-pubsub": "^1.2.0"
51
51
  },
52
- "gitHead": "405a6743bb0fdae18c07faff17037b9e7a345939"
52
+ "gitHead": "b5172e2824227a4b5e9524a4945f521a70ff5c9d"
53
53
  }