@esposter/azure 2.38.1

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2020-present Jimmy Chen
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @esposter/azure
2
+
3
+ [![Apache-2.0 licensed][badge-license]][url-license]
4
+ [![NPM version][badge-npm-version]][url-npm]
5
+ [![NPM downloads][badge-npm-downloads]][url-npm]
6
+ [![NPM Unpacked Size (with version)][badge-npm-unpacked-size]][url-npm]
7
+
8
+ The parts of Azure's wire contract that both a real client and a fake one have to agree on: the OData filter
9
+ clause vocabulary shared by Table Storage and Search, the entity key casing convention, and the service limits.
10
+ No SDK client is constructed here and no credential is read — this package is pure data and pure functions, so
11
+ it runs anywhere.
12
+
13
+ ## Table of Contents
14
+
15
+ - 🚀 [Getting Started](#getting-started)
16
+ - 📖 [Documentation](#documentation)
17
+ - ⚖️ [License](#license)
18
+
19
+ ---
20
+
21
+ ## <a name="getting-started">🚀 Getting Started</a>
22
+
23
+ ```bash
24
+ pnpm add @esposter/azure
25
+ ```
26
+
27
+ ## <a name="documentation">📖 Documentation</a>
28
+
29
+ ### Clauses
30
+
31
+ A `Clause<T>` is a filter condition expressed against a property of `T`, and it is what the OData string is
32
+ built from rather than the string being assembled by hand. `BinaryOperator` covers the comparisons Table
33
+ Storage understands; `SearchOperator` covers the collection predicates only Azure Search does; `UnaryOperator`
34
+ is how clauses are combined.
35
+
36
+ ```ts
37
+ import type { Clause } from "@esposter/azure";
38
+
39
+ import { BinaryOperator } from "@esposter/azure";
40
+
41
+ const clause: Clause<{ createdAt: Date }> = { key: "createdAt", operator: BinaryOperator.ge, value: new Date(0) };
42
+ ```
43
+
44
+ ### Values
45
+
46
+ `serializeValue` renders a `SerializableValue` the way the target service expects — Table Storage wants a
47
+ `datetime'<iso>'` literal for a `Date`, Search wants the bare ISO string, and `isTableFilter` selects between
48
+ them. Strings go through `escapeValue`, which doubles embedded single quotes so a value can never close its own
49
+ literal and append filter syntax of its own.
50
+
51
+ ```ts
52
+ import { escapeValue, serializeValue } from "@esposter/azure";
53
+ ```
54
+
55
+ ### Filters
56
+
57
+ `serializeClauses` turns a clause array into a Table Storage filter string and `serializeSearchClauses` into a
58
+ Search one; the two differ only in how a `Date` renders, which is why they share a single core. Clauses on the
59
+ same key are grouped — a range pair is joined with `and`, anything else with `or` — so a caller never assembles
60
+ the boolean structure by hand. `deserializeClause` is the inverse, and is what lets a fake client evaluate a
61
+ filter it was handed rather than pattern-matching the string.
62
+
63
+ ```ts
64
+ import { BinaryOperator, CompositeKeyPropertyNames, getTableNullClause, serializeClauses } from "@esposter/azure";
65
+
66
+ const roomId = "00000000-0000-0000-0000-000000000000";
67
+ const filter = serializeClauses([
68
+ { key: CompositeKeyPropertyNames.partitionKey, operator: BinaryOperator.eq, value: roomId },
69
+ getTableNullClause("deletedAt"),
70
+ ]);
71
+ ```
72
+
73
+ Null is where the two services diverge and the helpers carry the difference: Table Storage cannot compare
74
+ against null at all, so `getTableNullClause` expresses "is null" as a negated `NaN` comparison, while Search
75
+ supports it directly through `getSearchNullClause` / `getSearchNonNullClause`. `getPartitionKeyFilter` is the
76
+ one-clause case worth naming, since a read, a count and a purge of the same entity must all start from it.
77
+
78
+ ### Keys
79
+
80
+ `CompositeKey` is the `partitionKey`/`rowKey` pair every Table entity carries, and `CompositeKeyPropertyNames`
81
+ is how those names are referred to without restating the strings. The wire spells those two capitalized and
82
+ JavaScript does not, so `serializeKey` and `deserializeKey` convert at the boundary and nothing in between has
83
+ to know.
84
+
85
+ ```ts
86
+ import { CompositeKey, CompositeKeyPropertyNames, serializeKey } from "@esposter/azure";
87
+ ```
88
+
89
+ ### Limits
90
+
91
+ `AZURE_MAX_BATCH_SIZE`, `AZURE_MAX_PAGE_SIZE` and `AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS` are the service's own
92
+ ceilings, named so a caller paginating, batching or enqueueing does not hard-code them.
93
+
94
+ ### Commands
95
+
96
+ Run from `packages/azure/`:
97
+
98
+ ```bash
99
+ pnpm build # compile to dist/
100
+ pnpm test # vitest watch mode (coverage is run from the repo root)
101
+ pnpm lint:fix # auto-fix lint
102
+ pnpm typecheck # type check
103
+ ```
104
+
105
+ ## <a name="license">⚖️ License</a>
106
+
107
+ This project is licensed under the [Apache-2.0 license](https://github.com/Esposter/Esposter/blob/main/LICENSE).
108
+
109
+ [badge-license]: https://img.shields.io/github/license/Esposter/Esposter.svg?color=blue
110
+ [url-license]: https://github.com/Esposter/Esposter/blob/main/LICENSE
111
+ [badge-npm-version]: https://img.shields.io/npm/v/@esposter/azure/latest?color=brightgreen
112
+ [url-npm]: https://www.npmjs.com/package/@esposter/azure/v/latest
113
+ [badge-npm-unpacked-size]: https://img.shields.io/npm/unpacked-size/@esposter/azure/latest?label=npm
114
+ [badge-npm-downloads]: https://img.shields.io/npm/dm/@esposter/azure.svg
@@ -0,0 +1,211 @@
1
+ import { z } from "zod";
2
+ import baseDayjs from "dayjs";
3
+ import { PropertyNames } from "@esposter/shared";
4
+ import { TableEntity } from "@azure/data-tables";
5
+ //#region src/models/BinaryOperator.d.ts
6
+ declare enum BinaryOperator {
7
+ eq = "eq",
8
+ ge = "ge",
9
+ gt = "gt",
10
+ le = "le",
11
+ lt = "lt",
12
+ ne = "ne"
13
+ }
14
+ declare const BinaryOperators: readonly BinaryOperator[];
15
+ //#endregion
16
+ //#region src/models/search/SearchOperator.d.ts
17
+ declare enum SearchOperator {
18
+ arrayAny = "arrayAny",
19
+ arrayContains = "arrayContains"
20
+ }
21
+ //#endregion
22
+ //#region src/models/SerializableValue.d.ts
23
+ declare const SERIALIZABLE_VALUE_MAX_LENGTH = 100;
24
+ type SerializableValue = boolean | Date | null | number | string;
25
+ declare const serializableValueSchema: z.ZodType<SerializableValue, SerializableValue>;
26
+ //#endregion
27
+ //#region src/models/Clause.d.ts
28
+ type Clause<T extends object> = {
29
+ key: keyof T & string;
30
+ not?: boolean;
31
+ } & ({
32
+ operator: BinaryOperator;
33
+ value: SerializableValue;
34
+ } | {
35
+ operator: SearchOperator.arrayAny;
36
+ } | {
37
+ operator: SearchOperator.arrayContains;
38
+ value: SerializableValue[];
39
+ });
40
+ //#endregion
41
+ //#region src/models/UnaryOperator.d.ts
42
+ declare enum UnaryOperator {
43
+ and = "and",
44
+ not = "not",
45
+ or = "or"
46
+ }
47
+ //#endregion
48
+ //#region src/services/constants.d.ts
49
+ declare const AZURE_MAX_BATCH_SIZE = 100;
50
+ declare const AZURE_MAX_PAGE_SIZE = 1e3;
51
+ declare const AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS: number;
52
+ //#endregion
53
+ //#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/omit-index-signature.d.ts
54
+ /**
55
+ Omit any index signatures from the given object type, leaving only explicitly defined properties.
56
+
57
+ This is the counterpart of `PickIndexSignature`.
58
+
59
+ Use-cases:
60
+ - Remove overly permissive signatures from third-party types.
61
+
62
+ This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
63
+
64
+ It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
65
+
66
+ (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
67
+
68
+ ```
69
+ const indexed: Record<string, unknown> = {}; // Allowed
70
+
71
+ // @ts-expect-error
72
+ const keyed: Record<'foo', unknown> = {}; // Error
73
+ // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
74
+ ```
75
+
76
+ Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
77
+
78
+ ```
79
+ type Indexed = {} extends Record<string, unknown>
80
+ ? '✅ `{}` is assignable to `Record<string, unknown>`'
81
+ : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
82
+
83
+ type IndexedResult = Indexed;
84
+ //=> '✅ `{}` is assignable to `Record<string, unknown>`'
85
+
86
+ type Keyed = {} extends Record<'foo' | 'bar', unknown>
87
+ ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
88
+ : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
89
+
90
+ type KeyedResult = Keyed;
91
+ //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
92
+ ```
93
+
94
+ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
95
+
96
+ ```
97
+ type OmitIndexSignature<ObjectType> = {
98
+ [KeyType in keyof ObjectType // Map each key of `ObjectType`...
99
+ ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
100
+ };
101
+ ```
102
+
103
+ ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
104
+
105
+ ```
106
+ type OmitIndexSignature<ObjectType> = {
107
+ [KeyType in keyof ObjectType
108
+ // Is `{}` assignable to `Record<KeyType, unknown>`?
109
+ as {} extends Record<KeyType, unknown>
110
+ ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
111
+ : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
112
+ ]: ObjectType[KeyType];
113
+ };
114
+ ```
115
+
116
+ If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
117
+
118
+ @example
119
+ ```
120
+ import type {OmitIndexSignature} from 'type-fest';
121
+
122
+ type Example = {
123
+ // These index signatures will be removed.
124
+ [x: string]: any;
125
+ [x: number]: any;
126
+ [x: symbol]: any;
127
+ [x: `head-${string}`]: string;
128
+ [x: `${string}-tail`]: string;
129
+ [x: `head-${string}-tail`]: string;
130
+ [x: `${bigint}`]: string;
131
+ [x: `embedded-${number}`]: string;
132
+
133
+ // These explicitly defined keys will remain.
134
+ foo: 'bar';
135
+ qux?: 'baz';
136
+ };
137
+
138
+ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
139
+ //=> {foo: 'bar'; qux?: 'baz'}
140
+ ```
141
+
142
+ @see {@link PickIndexSignature}
143
+ @category Object
144
+ */
145
+ type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType]; };
146
+ //#endregion
147
+ //#region src/models/table/CompositeKey.d.ts
148
+ declare class CompositeKey implements OmitIndexSignature<TableEntity> {
149
+ partitionKey: string;
150
+ rowKey: string;
151
+ }
152
+ declare const CompositeKeyPropertyNames: PropertyNames<CompositeKey>;
153
+ //#endregion
154
+ //#region src/services/dayjs/index.d.ts
155
+ declare const dayjs: typeof baseDayjs;
156
+ //#endregion
157
+ //#region src/services/search/getSearchNonNullClause.d.ts
158
+ declare const getSearchNonNullClause: <T extends object>(key: keyof T & string) => Clause<T>;
159
+ //#endregion
160
+ //#region src/services/search/getSearchNullClause.d.ts
161
+ declare const getSearchNullClause: <T extends object>(key: keyof T & string) => Clause<T>;
162
+ //#endregion
163
+ //#region src/services/table/constants.d.ts
164
+ declare const KeysToCapitalize: Set<string>;
165
+ declare const KeysToUncapitalize: Set<string>;
166
+ //#endregion
167
+ //#region src/services/table/deserializeKey.d.ts
168
+ declare const deserializeKey: (key: string) => string;
169
+ //#endregion
170
+ //#region src/services/table/getTableNullClause.d.ts
171
+ declare const getTableNullClause: <T extends object>(key: keyof T & string) => Clause<T>;
172
+ //#endregion
173
+ //#region src/services/table/serializeKey.d.ts
174
+ declare const serializeKey: (key: string) => string;
175
+ //#endregion
176
+ //#region src/services/transformer/constants.d.ts
177
+ declare const CLAUSE_REGEX: RegExp;
178
+ //#endregion
179
+ //#region src/services/transformer/deserializeClause.d.ts
180
+ declare const deserializeClause: (string: string) => Extract<Clause<Record<string, unknown>>, {
181
+ operator: BinaryOperator;
182
+ }>;
183
+ //#endregion
184
+ //#region src/services/transformer/deserializeValue.d.ts
185
+ declare const deserializeValue: (string: string) => SerializableValue;
186
+ //#endregion
187
+ //#region src/services/transformer/escapeValue.d.ts
188
+ declare const escapeValue: (value: string) => string;
189
+ //#endregion
190
+ //#region src/services/transformer/getPartitionKeyFilter.d.ts
191
+ declare const getPartitionKeyFilter: (partitionKey: CompositeKey["partitionKey"]) => string;
192
+ //#endregion
193
+ //#region src/services/transformer/RangeOperators.d.ts
194
+ declare const RangeOperators: (BinaryOperator | SearchOperator)[];
195
+ //#endregion
196
+ //#region src/services/transformer/serializeClause.d.ts
197
+ declare const serializeClause: (clause: Clause<Record<string, unknown>>, isTableFilter?: boolean) => string;
198
+ //#endregion
199
+ //#region src/services/transformer/serializeClauses.d.ts
200
+ declare const serializeClauses: (clauses: Clause<Record<string, unknown>>[]) => string;
201
+ //#endregion
202
+ //#region src/services/transformer/serializeClausesCore.d.ts
203
+ declare const serializeClausesCore: (clauses: Clause<Record<string, unknown>>[], isTableFilter: boolean) => string;
204
+ //#endregion
205
+ //#region src/services/transformer/serializeSearchClauses.d.ts
206
+ declare const serializeSearchClauses: (clauses: Clause<Record<string, unknown>>[]) => string;
207
+ //#endregion
208
+ //#region src/services/transformer/serializeValue.d.ts
209
+ declare const serializeValue: (value: SerializableValue, isTableFilter?: boolean) => string;
210
+ //#endregion
211
+ export { AZURE_MAX_BATCH_SIZE, AZURE_MAX_PAGE_SIZE, AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS, BinaryOperator, BinaryOperators, CLAUSE_REGEX, Clause, CompositeKey, CompositeKeyPropertyNames, KeysToCapitalize, KeysToUncapitalize, RangeOperators, SERIALIZABLE_VALUE_MAX_LENGTH, SearchOperator, SerializableValue, UnaryOperator, dayjs, deserializeClause, deserializeKey, deserializeValue, escapeValue, getPartitionKeyFilter, getSearchNonNullClause, getSearchNullClause, getTableNullClause, serializableValueSchema, serializeClause, serializeClauses, serializeClausesCore, serializeKey, serializeSearchClauses, serializeValue };
package/dist/index.js ADDED
@@ -0,0 +1,195 @@
1
+ import { z } from "zod";
2
+ import baseDayjs from "dayjs";
3
+ import duration from "dayjs/plugin/duration.js";
4
+ import { ID_SEPARATOR, InvalidOperationError, NotFoundError, Operation, capitalize, getPropertyNames, normalizeString, takeOne, uncapitalize } from "@esposter/shared";
5
+ //#region src/models/BinaryOperator.ts
6
+ let BinaryOperator = /* @__PURE__ */ function(BinaryOperator) {
7
+ BinaryOperator["eq"] = "eq";
8
+ BinaryOperator["ge"] = "ge";
9
+ BinaryOperator["gt"] = "gt";
10
+ BinaryOperator["le"] = "le";
11
+ BinaryOperator["lt"] = "lt";
12
+ BinaryOperator["ne"] = "ne";
13
+ return BinaryOperator;
14
+ }({});
15
+ const BinaryOperators = Object.values(BinaryOperator);
16
+ //#endregion
17
+ //#region src/models/SerializableValue.ts
18
+ const SERIALIZABLE_VALUE_MAX_LENGTH = 100;
19
+ const serializableValueSchema = z.union([
20
+ z.boolean(),
21
+ z.date(),
22
+ z.null(),
23
+ z.number(),
24
+ z.string().min(1).max(100)
25
+ ]);
26
+ //#endregion
27
+ //#region src/models/UnaryOperator.ts
28
+ let UnaryOperator = /* @__PURE__ */ function(UnaryOperator) {
29
+ UnaryOperator["and"] = "and";
30
+ UnaryOperator["not"] = "not";
31
+ UnaryOperator["or"] = "or";
32
+ return UnaryOperator;
33
+ }({});
34
+ //#endregion
35
+ //#region src/services/dayjs/index.ts
36
+ baseDayjs.extend(duration);
37
+ const dayjs = baseDayjs;
38
+ //#endregion
39
+ //#region src/services/constants.ts
40
+ const AZURE_MAX_BATCH_SIZE = 100;
41
+ const AZURE_MAX_PAGE_SIZE = 1e3;
42
+ const AZURE_MAX_QUEUE_VISIBILITY_TIMEOUT_MS = dayjs.duration(7, "days").asMilliseconds();
43
+ //#endregion
44
+ //#region src/models/search/SearchOperator.ts
45
+ let SearchOperator = /* @__PURE__ */ function(SearchOperator) {
46
+ SearchOperator["arrayAny"] = "arrayAny";
47
+ SearchOperator["arrayContains"] = "arrayContains";
48
+ return SearchOperator;
49
+ }({});
50
+ //#endregion
51
+ //#region src/models/table/CompositeKey.ts
52
+ var CompositeKey = class {};
53
+ const CompositeKeyPropertyNames = getPropertyNames();
54
+ //#endregion
55
+ //#region src/services/search/getSearchNonNullClause.ts
56
+ const getSearchNonNullClause = (key) => ({
57
+ key,
58
+ operator: "ne",
59
+ value: null
60
+ });
61
+ //#endregion
62
+ //#region src/services/search/getSearchNullClause.ts
63
+ const getSearchNullClause = (key) => ({
64
+ key,
65
+ operator: "eq",
66
+ value: null
67
+ });
68
+ //#endregion
69
+ //#region src/services/table/constants.ts
70
+ const KeysToCapitalize = /* @__PURE__ */ new Set([CompositeKeyPropertyNames.partitionKey, CompositeKeyPropertyNames.rowKey]);
71
+ const KeysToUncapitalize = /* @__PURE__ */ new Set([capitalize(CompositeKeyPropertyNames.partitionKey), capitalize(CompositeKeyPropertyNames.rowKey)]);
72
+ //#endregion
73
+ //#region src/services/table/deserializeKey.ts
74
+ const deserializeKey = (key) => KeysToUncapitalize.has(key) ? uncapitalize(key) : key;
75
+ //#endregion
76
+ //#region src/services/table/getTableNullClause.ts
77
+ const getTableNullClause = (key) => ({
78
+ key,
79
+ not: true,
80
+ operator: "ne",
81
+ value: NaN
82
+ });
83
+ //#endregion
84
+ //#region src/services/table/serializeKey.ts
85
+ const serializeKey = (key) => KeysToCapitalize.has(key) ? capitalize(key) : key;
86
+ //#endregion
87
+ //#region src/services/transformer/constants.ts
88
+ const VALUE_REGEX = [
89
+ true,
90
+ false,
91
+ String.raw`datetime'[^']*'`,
92
+ String.raw`\d{4}-\d{2}-\d{2}T[^\s]+`,
93
+ String(null),
94
+ String.raw`-?\d+(?:\.\d+)?`,
95
+ String(NaN),
96
+ "'(?:[^']|'')*'"
97
+ ].join(ID_SEPARATOR);
98
+ 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");
99
+ //#endregion
100
+ //#region src/services/transformer/deserializeValue.ts
101
+ const deserializeValue = (string) => {
102
+ if (string === String(true)) return true;
103
+ else if (string === String(false)) return false;
104
+ else if (string === String(null)) return null;
105
+ else if (Number.isFinite(Number(string))) return Number(string);
106
+ else if (string === String(NaN)) return NaN;
107
+ else if (string.startsWith("datetime'") && string.endsWith("'")) return new Date(string.slice(9, -1));
108
+ else if (string.startsWith("'") && string.endsWith("'")) return string.slice(1, -1).replaceAll("''", "'");
109
+ else {
110
+ const date = new Date(string);
111
+ if (Number.isNaN(date)) return string;
112
+ else return date;
113
+ }
114
+ };
115
+ //#endregion
116
+ //#region src/services/transformer/deserializeClause.ts
117
+ const deserializeClause = (string) => {
118
+ const normalizedString = normalizeString(string);
119
+ const match = CLAUSE_REGEX.exec(normalizedString);
120
+ if (!match) throw new NotFoundError(deserializeClause.name, normalizedString);
121
+ const groups = match.groups;
122
+ if (!groups) throw new NotFoundError(deserializeClause.name, normalizedString);
123
+ return {
124
+ key: deserializeKey(groups.key),
125
+ not: Boolean(groups.not),
126
+ operator: groups.operator,
127
+ value: deserializeValue(groups.value)
128
+ };
129
+ };
130
+ //#endregion
131
+ //#region src/services/transformer/escapeValue.ts
132
+ const escapeValue = (value) => `'${value.replaceAll("'", "''")}'`;
133
+ //#endregion
134
+ //#region src/services/transformer/RangeOperators.ts
135
+ const RangeOperators = [
136
+ "ge",
137
+ "gt",
138
+ "le",
139
+ "lt"
140
+ ];
141
+ //#endregion
142
+ //#region src/services/transformer/serializeValue.ts
143
+ const serializeValue = (value, isTableFilter = false) => {
144
+ if (value instanceof Date) return isTableFilter ? `datetime'${value.toISOString()}'` : value.toISOString();
145
+ else if (typeof value === "string") return escapeValue(value);
146
+ else return String(value);
147
+ };
148
+ //#endregion
149
+ //#region src/services/transformer/serializeClause.ts
150
+ const serializeClause = (clause, isTableFilter = false) => {
151
+ const keys = clause.key.split("/").map((key) => serializeKey(key));
152
+ const clauseKey = keys.join("/");
153
+ if (clause.operator === "arrayAny") return `${clauseKey}/any()`;
154
+ else if (clause.operator === "arrayContains") {
155
+ const serializedValue = serializeValue(clause.value.join(","));
156
+ if (keys.length === 1) return `${clauseKey}/any(x: search.in(x, ${serializedValue}))`;
157
+ else if (keys.length === 2) {
158
+ const [collectionName, propertyName] = keys;
159
+ return `${collectionName}/any(x: search.in(x/${propertyName}, ${serializedValue}))`;
160
+ } else throw new InvalidOperationError(Operation.Read, serializeClause.name, clause.key);
161
+ }
162
+ const { not, operator, value } = clause;
163
+ const baseClause = `${clauseKey} ${operator} ${serializeValue(value, isTableFilter)}`;
164
+ return not ? `not(${baseClause})` : baseClause;
165
+ };
166
+ //#endregion
167
+ //#region src/services/transformer/serializeClausesCore.ts
168
+ const serializeClausesCore = (clauses, isTableFilter) => {
169
+ if (clauses.length === 0) return "";
170
+ else if (clauses.length === 1) return serializeClause(takeOne(clauses), isTableFilter);
171
+ const groupedClauses = Object.groupBy(clauses, ({ key }) => key);
172
+ const groupedStrings = [];
173
+ for (const clauseGroup of Object.values(groupedClauses)) if (clauseGroup.length === 1) groupedStrings.push(serializeClause(takeOne(clauseGroup), isTableFilter));
174
+ else {
175
+ const serializedClauses = clauseGroup.map((c) => serializeClause(c, isTableFilter));
176
+ const groupedString = clauseGroup.some(({ operator }) => RangeOperators.includes(operator)) ? serializedClauses.join(` and `) : `(${serializedClauses.join(` or `)})`;
177
+ groupedStrings.push(groupedString);
178
+ }
179
+ return groupedStrings.join(` and `);
180
+ };
181
+ //#endregion
182
+ //#region src/services/transformer/serializeClauses.ts
183
+ const serializeClauses = (clauses) => serializeClausesCore(clauses, true);
184
+ //#endregion
185
+ //#region src/services/transformer/getPartitionKeyFilter.ts
186
+ const getPartitionKeyFilter = (partitionKey) => serializeClauses([{
187
+ key: CompositeKeyPropertyNames.partitionKey,
188
+ operator: "eq",
189
+ value: partitionKey
190
+ }]);
191
+ //#endregion
192
+ //#region src/services/transformer/serializeSearchClauses.ts
193
+ const serializeSearchClauses = (clauses) => serializeClausesCore(clauses, false);
194
+ //#endregion
195
+ 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, dayjs, deserializeClause, deserializeKey, deserializeValue, escapeValue, getPartitionKeyFilter, getSearchNonNullClause, getSearchNullClause, getTableNullClause, serializableValueSchema, serializeClause, serializeClauses, serializeClausesCore, serializeKey, serializeSearchClauses, serializeValue };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@esposter/azure",
3
+ "version": "2.38.1",
4
+ "description": "The Azure wire conventions Esposter's clients and its mocks both speak — OData filter clauses, entity key casing, and service limits.",
5
+ "keywords": [
6
+ "azure",
7
+ "azure-search",
8
+ "azure-table-storage",
9
+ "filter",
10
+ "odata",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/Esposter/Esposter/blob/main/packages/azure#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/Esposter/Esposter/issues"
16
+ },
17
+ "license": "Apache-2.0",
18
+ "author": "Jimmy Chen",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/Esposter/Esposter.git"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "type": "module",
27
+ "types": "dist/index.d.ts",
28
+ "imports": {
29
+ "#src/*": "./src/*.ts"
30
+ },
31
+ "exports": {
32
+ ".": "./dist/index.js",
33
+ "./package.json": "./package.json"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "pnpm export:gen && tsdown",
40
+ "export:gen": "ctix build --config ../configuration/.ctirc-ts",
41
+ "format": "oxfmt",
42
+ "format:check": "oxfmt --check",
43
+ "lint": "eslint .",
44
+ "lint:fix": "eslint --fix .",
45
+ "test": "vitest",
46
+ "typecheck": "tsgo"
47
+ },
48
+ "dependencies": {
49
+ "@esposter/shared": "2.38.1",
50
+ "dayjs": "^1.11.23"
51
+ },
52
+ "devDependencies": {
53
+ "@arethetypeswrong/core": "^0.18.5",
54
+ "@esposter/configuration": "2.38.1",
55
+ "ctix": "^2.8.2",
56
+ "publint": "^0.3.24",
57
+ "tsdown": "^0.22.14",
58
+ "type-fest": "^5.8.0",
59
+ "vitest": "^4.1.11"
60
+ },
61
+ "peerDependencies": {
62
+ "@azure/data-tables": "^13.3.2",
63
+ "zod": "^4.4.3"
64
+ },
65
+ "inlinedDependencies": {
66
+ "type-fest": "5.8.0"
67
+ },
68
+ "gitHead": "b4c56347a01ac26a5e447c934a0c3c3308161bb5"
69
+ }