@esposter/azure 3.2.0 → 3.3.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/README.md CHANGED
@@ -38,7 +38,7 @@ import type { Clause } from "@esposter/azure";
38
38
 
39
39
  import { BinaryOperator } from "@esposter/azure";
40
40
 
41
- const clause: Clause<{ createdAt: Date }> = { key: "createdAt", operator: BinaryOperator.ge, value: new Date(0) };
41
+ const clause: Clause<{ createdAt: Date }> = { key: "createdAt", operator: BinaryOperator.Ge, value: new Date(0) };
42
42
  ```
43
43
 
44
44
  ### Values
@@ -65,7 +65,7 @@ import { BinaryOperator, CompositeKeyPropertyNames, getTableNullClause, serializ
65
65
 
66
66
  const roomId = "00000000-0000-0000-0000-000000000000";
67
67
  const filter = serializeClauses([
68
- { key: CompositeKeyPropertyNames.partitionKey, operator: BinaryOperator.eq, value: roomId },
68
+ { key: CompositeKeyPropertyNames.partitionKey, operator: BinaryOperator.Eq, value: roomId },
69
69
  getTableNullClause("deletedAt"),
70
70
  ]);
71
71
  ```
package/dist/index.d.ts CHANGED
@@ -3,23 +3,22 @@ import { PropertyNames } from "@esposter/shared";
3
3
  import { TableEntity } from "@azure/data-tables";
4
4
  //#region src/models/search/SearchOperator.d.ts
5
5
  export declare enum SearchOperator {
6
- arrayAny = "arrayAny",
7
- arrayContains = "arrayContains"
6
+ ArrayAny = "arrayAny",
7
+ ArrayContains = "arrayContains"
8
8
  }
9
9
  //#endregion
10
10
  //#region src/models/shared/BinaryOperator.d.ts
11
11
  export declare enum BinaryOperator {
12
- eq = "eq",
13
- ge = "ge",
14
- gt = "gt",
15
- le = "le",
16
- lt = "lt",
17
- ne = "ne"
12
+ Eq = "eq",
13
+ Ge = "ge",
14
+ Gt = "gt",
15
+ Le = "le",
16
+ Lt = "lt",
17
+ Ne = "ne"
18
18
  }
19
19
  export declare const BinaryOperators: readonly BinaryOperator[];
20
20
  //#endregion
21
21
  //#region src/models/shared/SerializableValue.d.ts
22
- export declare const SERIALIZABLE_VALUE_MAX_LENGTH = 100;
23
22
  export type SerializableValue = boolean | Date | null | number | string;
24
23
  export declare const serializableValueSchema: z.ZodType<SerializableValue, SerializableValue>;
25
24
  //#endregion
@@ -31,17 +30,17 @@ export type Clause<T extends object> = {
31
30
  operator: BinaryOperator;
32
31
  value: SerializableValue;
33
32
  } | {
34
- operator: SearchOperator.arrayAny;
33
+ operator: SearchOperator.ArrayAny;
35
34
  } | {
36
- operator: SearchOperator.arrayContains;
35
+ operator: SearchOperator.ArrayContains;
37
36
  value: SerializableValue[];
38
37
  });
39
38
  //#endregion
40
39
  //#region src/models/shared/UnaryOperator.d.ts
41
40
  export declare enum UnaryOperator {
42
- and = "and",
43
- not = "not",
44
- or = "or"
41
+ And = "and",
42
+ Not = "not",
43
+ Or = "or"
45
44
  }
46
45
  //#endregion
47
46
  //#region ../../node_modules/.pnpm/type-fest@5.10.0/node_modules/type-fest/source/omit-index-signature.d.ts
@@ -154,11 +153,12 @@ export declare const getSearchNullClause: <T extends object>(key: keyof T & stri
154
153
  //#region src/services/shared/constants.d.ts
155
154
  export declare const AZURE_MAX_BATCH_SIZE = 100;
156
155
  export declare const AZURE_MAX_PAGE_SIZE = 1e3;
156
+ export declare const SERIALIZABLE_VALUE_MAX_LENGTH = 100;
157
157
  export declare const AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS: number;
158
158
  //#endregion
159
159
  //#region src/services/table/constants.d.ts
160
- export declare const KeysToCapitalize: Set<string>;
161
- export declare const KeysToUncapitalize: Set<string>;
160
+ export declare const KEYS_TO_CAPITALIZE: ReadonlySet<string>;
161
+ export declare const KEYS_TO_UNCAPITALIZE: ReadonlySet<string>;
162
162
  //#endregion
163
163
  //#region src/services/table/deserializeKey.d.ts
164
164
  export declare const deserializeKey: (key: string) => string;
@@ -170,6 +170,7 @@ export declare const getTableNullClause: <T extends object>(key: keyof T & strin
170
170
  export declare const serializeKey: (key: string) => string;
171
171
  //#endregion
172
172
  //#region src/services/transformer/constants.d.ts
173
+ export declare const DATETIME_LITERAL_PREFIX = "datetime'";
173
174
  export declare const CLAUSE_REGEX: RegExp;
174
175
  //#endregion
175
176
  //#region src/services/transformer/deserializeClause.d.ts
package/dist/index.js CHANGED
@@ -1,26 +1,31 @@
1
1
  import { z } from "zod";
2
- import { ID_SEPARATOR, InvalidOperationError, NotFoundError, Operation, capitalize, getPropertyNames, normalizeString, takeOne, uncapitalize } from "@esposter/shared";
2
+ import { InvalidOperationError, NotFoundError, Operation, capitalize, getPropertyNames, getResult, normalizeString, takeOne, uncapitalize } from "@esposter/shared";
3
3
  //#region src/models/search/SearchOperator.ts
4
4
  let SearchOperator = /* @__PURE__ */ function(SearchOperator) {
5
- SearchOperator["arrayAny"] = "arrayAny";
6
- SearchOperator["arrayContains"] = "arrayContains";
5
+ SearchOperator["ArrayAny"] = "arrayAny";
6
+ SearchOperator["ArrayContains"] = "arrayContains";
7
7
  return SearchOperator;
8
8
  }({});
9
9
  //#endregion
10
10
  //#region src/models/shared/BinaryOperator.ts
11
11
  let BinaryOperator = /* @__PURE__ */ function(BinaryOperator) {
12
- BinaryOperator["eq"] = "eq";
13
- BinaryOperator["ge"] = "ge";
14
- BinaryOperator["gt"] = "gt";
15
- BinaryOperator["le"] = "le";
16
- BinaryOperator["lt"] = "lt";
17
- BinaryOperator["ne"] = "ne";
12
+ BinaryOperator["Eq"] = "eq";
13
+ BinaryOperator["Ge"] = "ge";
14
+ BinaryOperator["Gt"] = "gt";
15
+ BinaryOperator["Le"] = "le";
16
+ BinaryOperator["Lt"] = "lt";
17
+ BinaryOperator["Ne"] = "ne";
18
18
  return BinaryOperator;
19
19
  }({});
20
20
  const BinaryOperators = Object.values(BinaryOperator);
21
21
  //#endregion
22
- //#region src/models/shared/SerializableValue.ts
22
+ //#region src/services/shared/constants.ts
23
+ const AZURE_MAX_BATCH_SIZE = 100;
24
+ const AZURE_MAX_PAGE_SIZE = 1e3;
23
25
  const SERIALIZABLE_VALUE_MAX_LENGTH = 100;
26
+ const AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS = Temporal.Duration.from({ days: 7 }).total("milliseconds");
27
+ //#endregion
28
+ //#region src/models/shared/SerializableValue.ts
24
29
  const serializableValueSchema = z.union([
25
30
  z.boolean(),
26
31
  z.date(),
@@ -31,9 +36,9 @@ const serializableValueSchema = z.union([
31
36
  //#endregion
32
37
  //#region src/models/shared/UnaryOperator.ts
33
38
  let UnaryOperator = /* @__PURE__ */ function(UnaryOperator) {
34
- UnaryOperator["and"] = "and";
35
- UnaryOperator["not"] = "not";
36
- UnaryOperator["or"] = "or";
39
+ UnaryOperator["And"] = "and";
40
+ UnaryOperator["Not"] = "not";
41
+ UnaryOperator["Or"] = "or";
37
42
  return UnaryOperator;
38
43
  }({});
39
44
  //#endregion
@@ -55,17 +60,12 @@ const getSearchNullClause = (key) => ({
55
60
  value: null
56
61
  });
57
62
  //#endregion
58
- //#region src/services/shared/constants.ts
59
- const AZURE_MAX_BATCH_SIZE = 100;
60
- const AZURE_MAX_PAGE_SIZE = 1e3;
61
- const AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS = Temporal.Duration.from({ days: 7 }).total("milliseconds");
62
- //#endregion
63
63
  //#region src/services/table/constants.ts
64
- const KeysToCapitalize = /* @__PURE__ */ new Set([CompositeKeyPropertyNames.partitionKey, CompositeKeyPropertyNames.rowKey]);
65
- const KeysToUncapitalize = /* @__PURE__ */ new Set([capitalize(CompositeKeyPropertyNames.partitionKey), capitalize(CompositeKeyPropertyNames.rowKey)]);
64
+ const KEYS_TO_CAPITALIZE = /* @__PURE__ */ new Set([CompositeKeyPropertyNames.partitionKey, CompositeKeyPropertyNames.rowKey]);
65
+ const KEYS_TO_UNCAPITALIZE = /* @__PURE__ */ new Set([capitalize(CompositeKeyPropertyNames.partitionKey), capitalize(CompositeKeyPropertyNames.rowKey)]);
66
66
  //#endregion
67
67
  //#region src/services/table/deserializeKey.ts
68
- const deserializeKey = (key) => KeysToUncapitalize.has(key) ? uncapitalize(key) : key;
68
+ const deserializeKey = (key) => KEYS_TO_UNCAPITALIZE.has(key) ? uncapitalize(key) : key;
69
69
  //#endregion
70
70
  //#region src/services/table/getTableNullClause.ts
71
71
  const getTableNullClause = (key) => ({
@@ -76,35 +76,33 @@ const getTableNullClause = (key) => ({
76
76
  });
77
77
  //#endregion
78
78
  //#region src/services/table/serializeKey.ts
79
- const serializeKey = (key) => KeysToCapitalize.has(key) ? capitalize(key) : key;
79
+ const serializeKey = (key) => KEYS_TO_CAPITALIZE.has(key) ? capitalize(key) : key;
80
80
  //#endregion
81
81
  //#region src/services/transformer/constants.ts
82
+ const DATETIME_LITERAL_PREFIX = "datetime'";
82
83
  const VALUE_REGEX = [
83
84
  true,
84
85
  false,
85
- String.raw`datetime'[^']*'`,
86
+ String.raw`${DATETIME_LITERAL_PREFIX}[^']*'`,
86
87
  String.raw`\d{4}-\d{2}-\d{2}T[^\s]+`,
87
88
  String(null),
88
89
  String.raw`-?\d+(?:\.\d+)?`,
89
90
  String(NaN),
90
91
  "'(?:[^']|'')*'"
91
- ].join(ID_SEPARATOR);
92
- 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");
92
+ ].join("|");
93
+ const CLAUSE_REGEX = new RegExp(String.raw`^(?<not>not\s+)?(?<key>[A-Za-z0-9_]*)\s*(?<operator>${BinaryOperators.join("|")})\s+(?<value>${VALUE_REGEX})$`, "iu");
93
94
  //#endregion
94
95
  //#region src/services/transformer/deserializeValue.ts
96
+ const parseIsoDate = (isoValue) => getResult(() => new Date(Temporal.Instant.from(isoValue).epochMilliseconds)).unwrapOr(void 0);
95
97
  const deserializeValue = (serializedValue) => {
96
98
  if (serializedValue === String(true)) return true;
97
99
  else if (serializedValue === String(false)) return false;
98
100
  else if (serializedValue === String(null)) return null;
99
101
  else if (Number.isFinite(Number(serializedValue))) return Number(serializedValue);
100
102
  else if (serializedValue === String(NaN)) return NaN;
101
- else if (serializedValue.startsWith("datetime'") && serializedValue.endsWith("'")) return new Date(serializedValue.slice(9, -1));
103
+ else if (serializedValue.startsWith("datetime'") && serializedValue.endsWith("'")) return parseIsoDate(serializedValue.slice(9, -1)) ?? serializedValue;
102
104
  else if (serializedValue.startsWith("'") && serializedValue.endsWith("'")) return serializedValue.slice(1, -1).replaceAll("''", "'");
103
- else {
104
- const date = new Date(serializedValue);
105
- if (Number.isNaN(date)) return serializedValue;
106
- else return date;
107
- }
105
+ else return parseIsoDate(serializedValue) ?? serializedValue;
108
106
  };
109
107
  //#endregion
110
108
  //#region src/services/transformer/deserializeClause.ts
@@ -135,7 +133,7 @@ const RangeOperators = [
135
133
  //#endregion
136
134
  //#region src/services/transformer/serializeValue.ts
137
135
  const serializeValue = (value, isTableFilter = false) => {
138
- if (value instanceof Date) return isTableFilter ? `datetime'${value.toISOString()}'` : value.toISOString();
136
+ if (value instanceof Date) return isTableFilter ? `${DATETIME_LITERAL_PREFIX}${value.toISOString()}'` : value.toISOString();
139
137
  else if (typeof value === "string") return escapeValue(value);
140
138
  else return String(value);
141
139
  };
@@ -188,4 +186,4 @@ const getPartitionKeyFilter = (partitionKey) => serializeClauses([{
188
186
  //#region src/services/transformer/serializeSearchClauses.ts
189
187
  const serializeSearchClauses = (clauses) => serializeClausesCore(clauses, false);
190
188
  //#endregion
191
- export { AZURE_MAX_BATCH_SIZE, AZURE_MAX_PAGE_SIZE, AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS, BinaryOperator, BinaryOperators, CLAUSE_REGEX, CompositeKey, CompositeKeyPropertyNames, KeysToCapitalize, KeysToUncapitalize, RangeOperators, SERIALIZABLE_VALUE_MAX_LENGTH, SearchOperator, UnaryOperator, deserializeClause, deserializeKey, deserializeValue, escapeValue, getPartitionKeyFilter, getSearchNonNullClause, getSearchNullClause, getTableNullClause, serializableValueSchema, serializeClause, serializeClauses, serializeClausesCore, serializeKey, serializeSearchClauses, serializeValue };
189
+ export { AZURE_MAX_BATCH_SIZE, AZURE_MAX_PAGE_SIZE, AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS, BinaryOperator, BinaryOperators, CLAUSE_REGEX, CompositeKey, CompositeKeyPropertyNames, DATETIME_LITERAL_PREFIX, KEYS_TO_CAPITALIZE, KEYS_TO_UNCAPITALIZE, RangeOperators, SERIALIZABLE_VALUE_MAX_LENGTH, SearchOperator, UnaryOperator, deserializeClause, deserializeKey, deserializeValue, escapeValue, getPartitionKeyFilter, getSearchNonNullClause, getSearchNullClause, getTableNullClause, serializableValueSchema, serializeClause, serializeClauses, serializeClausesCore, serializeKey, serializeSearchClauses, serializeValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esposter/azure",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "The Azure wire conventions Esposter's clients and its mocks both speak — OData filter clauses, entity key casing, and service limits.",
5
5
  "keywords": [
6
6
  "azure",
@@ -47,15 +47,15 @@
47
47
  "typecheck": "tsc"
48
48
  },
49
49
  "dependencies": {
50
- "@esposter/shared": "3.2.0"
50
+ "@esposter/shared": "3.3.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@arethetypeswrong/core": "^0.18.5",
54
- "@esposter/configuration": "3.2.0",
54
+ "@esposter/configuration": "3.3.0",
55
55
  "publint": "^0.3.24",
56
56
  "tsdown": "^0.23.0",
57
57
  "type-fest": "^5.10.0",
58
- "vitest": "^5.0.1"
58
+ "vitest": "^5.0.2"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@azure/data-tables": "^13.3.2",
@@ -64,5 +64,5 @@
64
64
  "inlinedDependencies": {
65
65
  "type-fest": "5.10.0"
66
66
  },
67
- "gitHead": "bc055ed2f154eff219a355016a6b586962dbfa9c"
67
+ "gitHead": "5854a00717502d8de96adc8b44d3621ab85f9b57"
68
68
  }