@ebitex/data-sdk 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +21 -2
- package/dist/client.d.ts +33 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +98 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +30 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/pointers.d.ts +26 -0
- package/dist/pointers.d.ts.map +1 -0
- package/dist/pointers.js +45 -0
- package/dist/pointers.js.map +1 -0
- package/dist/query.d.ts +23 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +136 -0
- package/dist/query.js.map +1 -0
- package/dist/types.d.ts +131 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +37 -4
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 [yyyy] [name of copyright owner]
|
|
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
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ebitex/data-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The client for the ebitex Data Delivery API. Filters, sorts, facets, keyset paging and reference expansion, typed, in a browser or on a server. No runtime dependencies.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createDataClient } from '@ebitex/data-sdk'
|
|
7
|
+
|
|
8
|
+
const data = createDataClient({ apiKey: 'ebx_your_key' })
|
|
9
|
+
|
|
10
|
+
const page = await data.records({ model: 'dog', filters: { colour: 'black' }, sort: '-born', limit: 25 })
|
|
11
|
+
for await (const dog of data.eachRecord({ model: 'dog' })) console.log(dog.name)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- **Keys.** A key with no origin or address restriction is a server key and reads everything in its partition; never ship one to a browser. A key restricted to your site's origins is browser-safe and reads only the models and fields marked public.
|
|
15
|
+
- **Read `models()` first.** It lists what your key may ask for: each field's type and whether it can be filtered, sorted or counted.
|
|
16
|
+
- **A cursor belongs to its query.** `eachRecord` and `eachPage` capture the query once and send it unchanged with every cursor.
|
|
17
|
+
- **Nothing is cached or retried.** Pass your own `fetch` to add either.
|
|
18
|
+
- **Errors.** `DataApiError` carries the status, the server's `code`, and the `X-Request-Id` to quote. `DataNetworkError` is a failure to connect. A request the client refuses to send (a limit of 500, more than 5 facets) is a `DataApiError` with `local: true`.
|
|
19
|
+
|
|
20
|
+
Documentation: https://developers.ebitex.io/reference/data-sdk/
|
|
21
|
+
|
|
22
|
+
Licensed under Apache-2.0.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BatchResult, DataRecord, ExpansionOptions, ModelsResult, RecordOptions, RecordResponse, RecordsPage, RecordsQuery } from './types.js';
|
|
2
|
+
export declare const DEFAULT_BASE_URL = "https://api.ebitex.io";
|
|
3
|
+
export interface DataClientOptions {
|
|
4
|
+
/** A delivery key. A server key reads everything in its partition and must never reach a browser; a browser-safe key is restricted to origins or addresses. */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** Defaults to `https://api.ebitex.io`. */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** Defaults to the global `fetch`. Wrap it to add retries, a cache or tracing: the client adds none of its own. */
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
}
|
|
11
|
+
export interface CallOptions {
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
export interface DataClient {
|
|
15
|
+
/** The models this key may read, each with the fields it may see and what it may query. Read this before querying. */
|
|
16
|
+
models(options?: CallOptions): Promise<ModelsResult>;
|
|
17
|
+
/** One page of records. */
|
|
18
|
+
records<V = Record<string, unknown>>(query?: RecordsQuery, options?: CallOptions): Promise<RecordsPage<V>>;
|
|
19
|
+
/** Every page of a query as an async iterator. The query is captured once and replayed unchanged for each page. */
|
|
20
|
+
eachPage<V = Record<string, unknown>>(query?: Omit<RecordsQuery, 'cursor'>, options?: CallOptions): AsyncGenerator<RecordsPage<V>, void, undefined>;
|
|
21
|
+
/** Every record a query matches, one at a time. */
|
|
22
|
+
eachRecord<V = Record<string, unknown>>(query?: Omit<RecordsQuery, 'cursor'>, options?: CallOptions): AsyncGenerator<DataRecord<V>, void, undefined>;
|
|
23
|
+
/** Up to 50 records by key in one round trip, in the order asked; the keys that could not be read are in `missing`. */
|
|
24
|
+
recordsByKeys<V = Record<string, unknown>>(keys: readonly string[], expansion?: ExpansionOptions, options?: CallOptions): Promise<BatchResult<V>>;
|
|
25
|
+
/** One record, or `null` when there is none (or the key may not read it). `throwIfMissing` makes that an error. */
|
|
26
|
+
record<V = Record<string, unknown>>(key: string, options?: RecordOptions & CallOptions): Promise<DataRecord<V> | null>;
|
|
27
|
+
/** The primitive under `record`: keeps the `ETag`, and sends `If-None-Match` when given, so an unchanged record is `notModified`. */
|
|
28
|
+
recordResponse<V = Record<string, unknown>>(key: string, options?: RecordOptions & CallOptions & {
|
|
29
|
+
ifNoneMatch?: string;
|
|
30
|
+
}): Promise<RecordResponse<V>>;
|
|
31
|
+
}
|
|
32
|
+
export declare function createDataClient(options: DataClientOptions): DataClient;
|
|
33
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings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,CAAC,CAAA;IACpJ,uHAAuH;IACvH,aAAa,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;IACjJ,mHAAmH;IACnH,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;IACtH,qIAAqI;IACrI,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,aAAa,GAAG,WAAW,GAAG;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAC/D,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;CAC9B;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAsEvE"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { DataApiError, DataNetworkError } from './errors.js';
|
|
2
|
+
import { buildBatchQuery, buildRecordQuery, buildRecordsQuery } from './query.js';
|
|
3
|
+
export const DEFAULT_BASE_URL = 'https://api.ebitex.io';
|
|
4
|
+
const ROOT = '/data/delivery/v1';
|
|
5
|
+
export function createDataClient(options) {
|
|
6
|
+
if (!options.apiKey)
|
|
7
|
+
throw new TypeError('createDataClient needs an apiKey.');
|
|
8
|
+
const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
9
|
+
const doFetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
10
|
+
async function send(path, query, init = {}) {
|
|
11
|
+
const headers = { Authorization: `Bearer ${options.apiKey}`, Accept: 'application/json' };
|
|
12
|
+
if (init.ifNoneMatch)
|
|
13
|
+
headers['If-None-Match'] = init.ifNoneMatch;
|
|
14
|
+
const url = `${base}${ROOT}${path}${query ? `?${query}` : ''}`;
|
|
15
|
+
try {
|
|
16
|
+
return await doFetch(url, { method: 'GET', headers, signal: init.signal });
|
|
17
|
+
}
|
|
18
|
+
catch (cause) {
|
|
19
|
+
if (cause instanceof DOMException && cause.name === 'AbortError')
|
|
20
|
+
throw cause;
|
|
21
|
+
// The message carries no URL: it can hold a search term, and logs are not a place for a visitor's query.
|
|
22
|
+
throw new DataNetworkError('The Data Delivery API could not be reached.', { cause });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function json(response) {
|
|
26
|
+
if (response.ok)
|
|
27
|
+
return (await response.json());
|
|
28
|
+
throw await toError(response);
|
|
29
|
+
}
|
|
30
|
+
async function* eachPage(query = {}, call = {}) {
|
|
31
|
+
if (query.cursor) {
|
|
32
|
+
throw new DataApiError(400, 'invalid_cursor', 'eachPage and eachRecord start from the beginning; to resume, call records() with a cursor.', null, null, true);
|
|
33
|
+
}
|
|
34
|
+
const frozen = { ...query };
|
|
35
|
+
let cursor;
|
|
36
|
+
for (;;) {
|
|
37
|
+
const page = await json(await send('/records', buildRecordsQuery({ ...frozen, cursor }), call));
|
|
38
|
+
yield page;
|
|
39
|
+
if (!page.nextCursor)
|
|
40
|
+
return;
|
|
41
|
+
cursor = page.nextCursor;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function recordResponse(key, opts = {}) {
|
|
45
|
+
if (!key)
|
|
46
|
+
throw new DataApiError(400, 'invalid_keys', 'A record key is required.', null, null, true);
|
|
47
|
+
const response = await send(`/records/${encodeURIComponent(key)}`, buildRecordQuery(opts), opts);
|
|
48
|
+
const etag = response.headers.get('ETag');
|
|
49
|
+
if (response.status === 304)
|
|
50
|
+
return { status: 'notModified', etag };
|
|
51
|
+
if (response.status === 404) {
|
|
52
|
+
const error = await toError(response);
|
|
53
|
+
if (error.code === 'record_not_found') {
|
|
54
|
+
if (opts.throwIfMissing)
|
|
55
|
+
throw error;
|
|
56
|
+
return { status: 'missing' };
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
return { status: 'ok', record: await json(response), etag };
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
models: async (call) => json(await send('/models', '', call)),
|
|
64
|
+
records: async (query, call) => json(await send('/records', buildRecordsQuery(query), call)),
|
|
65
|
+
eachPage,
|
|
66
|
+
async *eachRecord(query = {}, call = {}) {
|
|
67
|
+
for await (const page of eachPage(query, call))
|
|
68
|
+
yield* page.items;
|
|
69
|
+
},
|
|
70
|
+
recordsByKeys: async (keys, expansion, call) => json(await send('/records', buildBatchQuery(keys, expansion), call)),
|
|
71
|
+
async record(key, opts = {}) {
|
|
72
|
+
const result = await recordResponse(key, opts);
|
|
73
|
+
return result.status === 'ok' ? result.record : null;
|
|
74
|
+
},
|
|
75
|
+
recordResponse,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async function toError(response) {
|
|
79
|
+
const requestId = response.headers.get('X-Request-Id');
|
|
80
|
+
const retryAfter = Number(response.headers.get('Retry-After'));
|
|
81
|
+
let code = response.status === 401 ? 'unauthorized' : 'error';
|
|
82
|
+
let message = `The Data Delivery API answered ${response.status}.`;
|
|
83
|
+
let bodyRequestId = null;
|
|
84
|
+
try {
|
|
85
|
+
const body = (await response.json());
|
|
86
|
+
if (typeof body.error === 'string')
|
|
87
|
+
code = body.error;
|
|
88
|
+
if (typeof body.message === 'string' && body.message)
|
|
89
|
+
message = body.message;
|
|
90
|
+
if (typeof body.requestId === 'string')
|
|
91
|
+
bodyRequestId = body.requestId;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// An error with no JSON body (an edge page, an empty 401) still has a status and a request id.
|
|
95
|
+
}
|
|
96
|
+
return new DataApiError(response.status, code, message, requestId ?? bodyRequestId, Number.isFinite(retryAfter) && response.headers.has('Retry-After') ? retryAfter : null);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAYjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAEvD,MAAM,IAAI,GAAG,mBAAmB,CAAA;AAmChC,MAAM,UAAU,gBAAgB,CAAC,OAA0B;IACzD,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAA;IAC7E,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACtE,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;IAEjF,KAAK,UAAU,IAAI,CAAC,IAAY,EAAE,KAAa,EAAE,OAAuD,EAAE;QACxG,MAAM,OAAO,GAA2B,EAAE,aAAa,EAAE,UAAU,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAA;QACjH,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC,WAAW,CAAA;QACjE,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,IAA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,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAgE,CAAA;QACnG,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;YAAE,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;QACrD,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,GAAG,IAAI,CAAC,OAAO,CAAA;QAC5E,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ;YAAE,aAAa,GAAG,IAAI,CAAC,SAAS,CAAA;IACxE,CAAC;IAAC,MAAM,CAAC;QACP,+FAA+F;IACjG,CAAC;IACD,OAAO,IAAI,YAAY,CACrB,QAAQ,CAAC,MAAM,EACf,IAAI,EACJ,OAAO,EACP,SAAS,IAAI,aAAa,EAC1B,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CACvF,CAAA;AACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The server answered with a non-success status, or the request was refused before it was sent. */
|
|
2
|
+
export declare class DataApiError extends Error {
|
|
3
|
+
readonly name = "DataApiError";
|
|
4
|
+
/** The HTTP status; 400 for a request this client refused to send. */
|
|
5
|
+
readonly status: number;
|
|
6
|
+
/** The server's error code (`field_not_queryable`, `invalid_cursor`, …), or `unauthorized` / `error` when the body carried none. */
|
|
7
|
+
readonly code: string;
|
|
8
|
+
/** The `X-Request-Id` to quote to support, or null when the request never reached the server. */
|
|
9
|
+
readonly requestId: string | null;
|
|
10
|
+
/** From `Retry-After` on a `429`. */
|
|
11
|
+
readonly retryAfterSeconds: number | null;
|
|
12
|
+
/** True when this client refused the request itself, before any network call. */
|
|
13
|
+
readonly local: boolean;
|
|
14
|
+
constructor(status: number, code: string, message: string, requestId?: string | null, retryAfterSeconds?: number | null, local?: boolean);
|
|
15
|
+
}
|
|
16
|
+
/** The request could not complete: no connection, a DNS failure, an aborted request. `cause` is the underlying error. */
|
|
17
|
+
export declare class DataNetworkError extends Error {
|
|
18
|
+
readonly name = "DataNetworkError";
|
|
19
|
+
constructor(message: string, options?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,kBAAiB;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,oIAAoI;IACpI,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,iGAAiG;IACjG,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,qCAAqC;IACrC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;IACzC,iFAAiF;IACjF,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;gBAGrB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,iBAAiB,GAAE,MAAM,GAAG,IAAW,EACvC,KAAK,UAAQ;CAShB;AAED,yHAAyH;AACzH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,sBAAqB;gBAEtB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAG3D"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The server answered with a non-success status, or the request was refused before it was sent. */
|
|
2
|
+
export class DataApiError extends Error {
|
|
3
|
+
name = 'DataApiError';
|
|
4
|
+
/** The HTTP status; 400 for a request this client refused to send. */
|
|
5
|
+
status;
|
|
6
|
+
/** The server's error code (`field_not_queryable`, `invalid_cursor`, …), or `unauthorized` / `error` when the body carried none. */
|
|
7
|
+
code;
|
|
8
|
+
/** The `X-Request-Id` to quote to support, or null when the request never reached the server. */
|
|
9
|
+
requestId;
|
|
10
|
+
/** From `Retry-After` on a `429`. */
|
|
11
|
+
retryAfterSeconds;
|
|
12
|
+
/** True when this client refused the request itself, before any network call. */
|
|
13
|
+
local;
|
|
14
|
+
constructor(status, code, message, requestId = null, retryAfterSeconds = null, local = false) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.status = status;
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.requestId = requestId;
|
|
19
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
20
|
+
this.local = local;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** The request could not complete: no connection, a DNS failure, an aborted request. `cause` is the underlying error. */
|
|
24
|
+
export class DataNetworkError extends Error {
|
|
25
|
+
name = 'DataNetworkError';
|
|
26
|
+
constructor(message, options) {
|
|
27
|
+
super(message, options);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,GAAG,cAAc,CAAA;IAC9B,sEAAsE;IAC7D,MAAM,CAAQ;IACvB,oIAAoI;IAC3H,IAAI,CAAQ;IACrB,iGAAiG;IACxF,SAAS,CAAe;IACjC,qCAAqC;IAC5B,iBAAiB,CAAe;IACzC,iFAAiF;IACxE,KAAK,CAAS;IAEvB,YACE,MAAc,EACd,IAAY,EACZ,OAAe,EACf,YAA2B,IAAI,EAC/B,oBAAmC,IAAI,EACvC,KAAK,GAAG,KAAK;QAEb,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;QAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF;AAED,yHAAyH;AACzH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,IAAI,GAAG,kBAAkB,CAAA;IAElC,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACzB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createDataClient, DEFAULT_BASE_URL } from './client.js';
|
|
2
|
+
export type { CallOptions, DataClient, DataClientOptions } from './client.js';
|
|
3
|
+
export { DataApiError, DataNetworkError } from './errors.js';
|
|
4
|
+
export { expanded, isInline, isReference, readPointer } from './pointers.js';
|
|
5
|
+
export type { Pointer, PointerKind } from './pointers.js';
|
|
6
|
+
export { buildBatchQuery, buildRecordQuery, buildRecordsQuery, Limits } from './query.js';
|
|
7
|
+
export type { BatchResult, DataRecord, ExpansionOptions, Facets, FacetBucket, FieldDescriptor, FieldFilter, FilterOperator, InlineValue, ModelDescriptor, ModelsResult, RecordOptions, RecordResponse, RecordsPage, RecordsQuery, ReferenceValue, Scalar, } from './types.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAChE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC5E,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACzF,YAAY,EACV,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,MAAM,EACN,WAAW,EACX,eAAe,EACf,WAAW,EACX,cAAc,EACd,WAAW,EACX,eAAe,EACf,YAAY,EACZ,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,EACZ,cAAc,EACd,MAAM,GACP,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createDataClient, DEFAULT_BASE_URL } from './client.js';
|
|
2
|
+
export { DataApiError, DataNetworkError } from './errors.js';
|
|
3
|
+
export { expanded, isInline, isReference, readPointer } from './pointers.js';
|
|
4
|
+
export { buildBatchQuery, buildRecordQuery, buildRecordsQuery, Limits } from './query.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEhE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE5E,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DataRecord, InlineValue, ReferenceValue } from './types.js';
|
|
2
|
+
export type PointerKind = 'empty' | 'reference' | 'inline' | 'unrecognised';
|
|
3
|
+
export interface Pointer {
|
|
4
|
+
kind: PointerKind;
|
|
5
|
+
/** Exactly what was written, or null when the value names none. */
|
|
6
|
+
provider: string | null;
|
|
7
|
+
key: string | null;
|
|
8
|
+
mode: string | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The one answer to "is this value a pointer, and to what?" in this package. It classifies by the value's own shape and nothing else, and
|
|
12
|
+
* reads both spellings the API can deliver: the `component` envelope (`mode` of `reference` or `inline`) and a plain `{ provider, key }`
|
|
13
|
+
* with no `mode`. It is pinned by the same `pointer-cases.json` the platform's C# and TypeScript readers are, so a value that merely looks
|
|
14
|
+
* like a pointer cannot be read as one here and not there.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readPointer(value: unknown): Pointer;
|
|
17
|
+
/** True for a pointer to another record. */
|
|
18
|
+
export declare function isReference<V = Record<string, unknown>>(value: unknown): value is ReferenceValue<V>;
|
|
19
|
+
/** True for a value described inline by a model. */
|
|
20
|
+
export declare function isInline(value: unknown): value is InlineValue;
|
|
21
|
+
/**
|
|
22
|
+
* The record a reference was expanded to (`generations` or `expand` on the request), or `undefined` when the value is not a reference or is
|
|
23
|
+
* a bare pointer: not followed, a cycle, missing, or not readable by the key. Never an error, because each of those is an ordinary answer.
|
|
24
|
+
*/
|
|
25
|
+
export declare function expanded<V = Record<string, unknown>>(value: unknown): DataRecord<V> | undefined;
|
|
26
|
+
//# sourceMappingURL=pointers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointers.d.ts","sourceRoot":"","sources":["../src/pointers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEzE,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,cAAc,CAAA;AAE3E,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAA;IACjB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB;AAID;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiBnD;AAED,4CAA4C;AAC5C,wBAAgB,WAAW,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,CAEnG;AAED,oDAAoD;AACpD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAE7D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAM/F"}
|
package/dist/pointers.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const text = (value) => (typeof value === 'string' ? value : null);
|
|
2
|
+
/**
|
|
3
|
+
* The one answer to "is this value a pointer, and to what?" in this package. It classifies by the value's own shape and nothing else, and
|
|
4
|
+
* reads both spellings the API can deliver: the `component` envelope (`mode` of `reference` or `inline`) and a plain `{ provider, key }`
|
|
5
|
+
* with no `mode`. It is pinned by the same `pointer-cases.json` the platform's C# and TypeScript readers are, so a value that merely looks
|
|
6
|
+
* like a pointer cannot be read as one here and not there.
|
|
7
|
+
*/
|
|
8
|
+
export function readPointer(value) {
|
|
9
|
+
if (value === null || value === undefined)
|
|
10
|
+
return { kind: 'empty', provider: null, key: null, mode: null };
|
|
11
|
+
if (typeof value !== 'object' || Array.isArray(value))
|
|
12
|
+
return { kind: 'unrecognised', provider: null, key: null, mode: null };
|
|
13
|
+
const v = value;
|
|
14
|
+
const mode = text(v.mode);
|
|
15
|
+
if (mode === 'inline') {
|
|
16
|
+
const hasDocument = typeof v.document === 'object' && v.document !== null && !Array.isArray(v.document);
|
|
17
|
+
return { kind: hasDocument ? 'inline' : 'unrecognised', provider: null, key: null, mode };
|
|
18
|
+
}
|
|
19
|
+
const key = text(v.key);
|
|
20
|
+
if ((mode === null || mode === 'reference') && key !== null && key.length > 0) {
|
|
21
|
+
return { kind: 'reference', provider: text(v.provider), key, mode };
|
|
22
|
+
}
|
|
23
|
+
return { kind: 'unrecognised', provider: null, key: null, mode };
|
|
24
|
+
}
|
|
25
|
+
/** True for a pointer to another record. */
|
|
26
|
+
export function isReference(value) {
|
|
27
|
+
return readPointer(value).kind === 'reference';
|
|
28
|
+
}
|
|
29
|
+
/** True for a value described inline by a model. */
|
|
30
|
+
export function isInline(value) {
|
|
31
|
+
return readPointer(value).kind === 'inline';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The record a reference was expanded to (`generations` or `expand` on the request), or `undefined` when the value is not a reference or is
|
|
35
|
+
* a bare pointer: not followed, a cycle, missing, or not readable by the key. Never an error, because each of those is an ordinary answer.
|
|
36
|
+
*/
|
|
37
|
+
export function expanded(value) {
|
|
38
|
+
if (!isReference(value))
|
|
39
|
+
return undefined;
|
|
40
|
+
const record = value.record;
|
|
41
|
+
return typeof record === 'object' && record !== null && typeof record.key === 'string'
|
|
42
|
+
? record
|
|
43
|
+
: undefined;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=pointers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pointers.js","sourceRoot":"","sources":["../src/pointers.ts"],"names":[],"mappings":"AAYA,MAAM,IAAI,GAAG,CAAC,KAAc,EAAiB,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,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,CAAC,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAA;IACrE,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AAClE,CAAC;AAED,4CAA4C;AAC5C,MAAM,UAAU,WAAW,CAA8B,KAAc;IACrE,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,WAAW,CAAA;AAChD,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAA;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAA8B,KAAc;IAClE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IACzC,MAAM,MAAM,GAAI,KAA8B,CAAC,MAAM,CAAA;IACrD,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,OAAQ,MAA4B,CAAC,GAAG,KAAK,QAAQ;QAC3G,CAAC,CAAE,MAAwB;QAC3B,CAAC,CAAC,SAAS,CAAA;AACf,CAAC"}
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ExpansionOptions, RecordsQuery } from './types.js';
|
|
2
|
+
/** The limits the API documents. The server stays the authority: these only refuse, early, what it would refuse. */
|
|
3
|
+
export declare const Limits: {
|
|
4
|
+
readonly maxPageSize: 100;
|
|
5
|
+
readonly maxBatchKeys: 50;
|
|
6
|
+
readonly maxGenerations: 5;
|
|
7
|
+
readonly maxFacetFields: 5;
|
|
8
|
+
readonly maxFilters: 10;
|
|
9
|
+
readonly maxInValues: 50;
|
|
10
|
+
readonly maxSearch: 100;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* `encodeURIComponent` leaves `! ' ( ) *` alone; RFC 3986 percent-encoding, which the .NET client uses, does not. Escaping them here makes the two
|
|
14
|
+
* produce the same string for the same query, which `query-cases.json` asserts in both suites.
|
|
15
|
+
*/
|
|
16
|
+
export declare function encode(value: string): string;
|
|
17
|
+
/** The query string (no leading `?`) for a list request. The parameter order is fixed: model, search, filters, sort, limit, cursor, facets, generations, expand. */
|
|
18
|
+
export declare function buildRecordsQuery(query?: RecordsQuery): string;
|
|
19
|
+
/** The query string for `keys=a,b,c`: only `generations` and `expand` may accompany it. */
|
|
20
|
+
export declare function buildBatchQuery(keys: readonly string[], options?: ExpansionOptions): string;
|
|
21
|
+
/** The query string for one record. */
|
|
22
|
+
export declare function buildRecordQuery(options?: ExpansionOptions): string;
|
|
23
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAA+B,YAAY,EAAU,MAAM,YAAY,CAAA;AAErG,oHAAoH;AACpH,eAAO,MAAM,MAAM;;;;;;;;CAQT,CAAA;AAOV;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C;AAsCD,oKAAoK;AACpK,wBAAgB,iBAAiB,CAAC,KAAK,GAAE,YAAiB,GAAG,MAAM,CAsDlE;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAK/F;AAED,uCAAuC;AACvC,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAIvE"}
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { DataApiError } from './errors.js';
|
|
2
|
+
/** The limits the API documents. The server stays the authority: these only refuse, early, what it would refuse. */
|
|
3
|
+
export const Limits = {
|
|
4
|
+
maxPageSize: 100,
|
|
5
|
+
maxBatchKeys: 50,
|
|
6
|
+
maxGenerations: 5,
|
|
7
|
+
maxFacetFields: 5,
|
|
8
|
+
maxFilters: 10,
|
|
9
|
+
maxInValues: 50,
|
|
10
|
+
maxSearch: 100,
|
|
11
|
+
};
|
|
12
|
+
/** The operators in the order they are sent, so equal queries are equal strings whatever order an object listed them in. */
|
|
13
|
+
const OPERATORS = ['eq', 'in', 'prefix', 'gt', 'gte', 'lt', 'lte', 'exists'];
|
|
14
|
+
const local = (code, message) => new DataApiError(400, code, message, null, null, true);
|
|
15
|
+
/**
|
|
16
|
+
* `encodeURIComponent` leaves `! ' ( ) *` alone; RFC 3986 percent-encoding, which the .NET client uses, does not. Escaping them here makes the two
|
|
17
|
+
* produce the same string for the same query, which `query-cases.json` asserts in both suites.
|
|
18
|
+
*/
|
|
19
|
+
export function encode(value) {
|
|
20
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
function scalar(value, what) {
|
|
23
|
+
if (value instanceof Date) {
|
|
24
|
+
if (Number.isNaN(value.getTime()))
|
|
25
|
+
throw local('invalid_filter', `${what} is an invalid date.`);
|
|
26
|
+
return value.toISOString();
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'number') {
|
|
29
|
+
if (!Number.isFinite(value))
|
|
30
|
+
throw local('invalid_filter', `${what} is not a finite number.`);
|
|
31
|
+
return String(value);
|
|
32
|
+
}
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
function list(values, what) {
|
|
36
|
+
for (const v of values) {
|
|
37
|
+
if (v.includes(','))
|
|
38
|
+
throw local('invalid_filter', `${what} cannot contain a comma.`);
|
|
39
|
+
}
|
|
40
|
+
return values.map(encode).join(',');
|
|
41
|
+
}
|
|
42
|
+
function requireInt(value, min, max, code, message) {
|
|
43
|
+
if (!Number.isInteger(value) || value < min || value > max)
|
|
44
|
+
throw local(code, message);
|
|
45
|
+
}
|
|
46
|
+
function expansion(parts, options) {
|
|
47
|
+
if (options.generations !== undefined) {
|
|
48
|
+
requireInt(options.generations, 0, Limits.maxGenerations, 'invalid_generations', `generations is a whole number from 0 to ${Limits.maxGenerations}.`);
|
|
49
|
+
parts.push(`generations=${options.generations}`);
|
|
50
|
+
}
|
|
51
|
+
if (options.expand && options.expand.length > 0)
|
|
52
|
+
parts.push(`expand=${list(options.expand, 'expand')}`);
|
|
53
|
+
}
|
|
54
|
+
function normalise(filter) {
|
|
55
|
+
if (typeof filter === 'object' && !(filter instanceof Date))
|
|
56
|
+
return filter;
|
|
57
|
+
return { eq: filter };
|
|
58
|
+
}
|
|
59
|
+
/** The query string (no leading `?`) for a list request. The parameter order is fixed: model, search, filters, sort, limit, cursor, facets, generations, expand. */
|
|
60
|
+
export function buildRecordsQuery(query = {}) {
|
|
61
|
+
const parts = [];
|
|
62
|
+
const filters = query.filters ?? {};
|
|
63
|
+
const fieldIds = Object.keys(filters).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
64
|
+
const search = query.search?.trim();
|
|
65
|
+
if (search && search.length > Limits.maxSearch)
|
|
66
|
+
throw local('invalid_search', `search is at most ${Limits.maxSearch} characters.`);
|
|
67
|
+
const fieldSort = query.sort !== undefined && query.sort.replace(/^-/, '') !== 'name' && query.sort.replace(/^-/, '') !== 'updated';
|
|
68
|
+
const facets = query.facets ?? [];
|
|
69
|
+
if (!query.model && (fieldIds.length > 0 || facets.length > 0 || fieldSort)) {
|
|
70
|
+
throw local('model_required', 'Filters, facets and a field sort need a model: pass model.');
|
|
71
|
+
}
|
|
72
|
+
if (query.model)
|
|
73
|
+
parts.push(`model=${encode(query.model)}`);
|
|
74
|
+
if (search)
|
|
75
|
+
parts.push(`search=${encode(search)}`);
|
|
76
|
+
let filterCount = 0;
|
|
77
|
+
for (const id of fieldIds) {
|
|
78
|
+
const ops = normalise(filters[id]);
|
|
79
|
+
for (const op of OPERATORS) {
|
|
80
|
+
const operand = ops[op];
|
|
81
|
+
if (operand === undefined)
|
|
82
|
+
continue;
|
|
83
|
+
if (++filterCount > Limits.maxFilters)
|
|
84
|
+
throw local('invalid_filter', `At most ${Limits.maxFilters} filters.`);
|
|
85
|
+
const what = `filter ${id} ${op}`;
|
|
86
|
+
let value;
|
|
87
|
+
if (op === 'in') {
|
|
88
|
+
if (!Array.isArray(operand) || operand.length === 0 || operand.length > Limits.maxInValues) {
|
|
89
|
+
throw local('invalid_filter', `in takes 1 to ${Limits.maxInValues} values.`);
|
|
90
|
+
}
|
|
91
|
+
value = list(operand.map((v) => scalar(v, what)), what);
|
|
92
|
+
}
|
|
93
|
+
else if (op === 'exists') {
|
|
94
|
+
if (typeof operand !== 'boolean')
|
|
95
|
+
throw local('invalid_filter', 'exists is true or false.');
|
|
96
|
+
value = String(operand);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (Array.isArray(operand) || typeof operand === 'boolean' && op !== 'eq')
|
|
100
|
+
throw local('invalid_filter', `${what} takes one value.`);
|
|
101
|
+
value = encode(scalar(operand, what));
|
|
102
|
+
}
|
|
103
|
+
parts.push(op === 'eq' ? `filter[${encode(id)}]=${value}` : `filter[${encode(id)}][${op}]=${value}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (query.sort)
|
|
107
|
+
parts.push(`sort=${encode(query.sort)}`);
|
|
108
|
+
if (query.limit !== undefined) {
|
|
109
|
+
requireInt(query.limit, 1, Limits.maxPageSize, 'invalid_limit', `limit is a whole number from 1 to ${Limits.maxPageSize}.`);
|
|
110
|
+
parts.push(`limit=${query.limit}`);
|
|
111
|
+
}
|
|
112
|
+
if (query.cursor)
|
|
113
|
+
parts.push(`cursor=${encode(query.cursor)}`);
|
|
114
|
+
if (facets.length > 0) {
|
|
115
|
+
if (facets.length > Limits.maxFacetFields)
|
|
116
|
+
throw local('invalid_facets', `At most ${Limits.maxFacetFields} facets.`);
|
|
117
|
+
parts.push(`facets=${list(facets, 'facets')}`);
|
|
118
|
+
}
|
|
119
|
+
expansion(parts, query);
|
|
120
|
+
return parts.join('&');
|
|
121
|
+
}
|
|
122
|
+
/** The query string for `keys=a,b,c`: only `generations` and `expand` may accompany it. */
|
|
123
|
+
export function buildBatchQuery(keys, options = {}) {
|
|
124
|
+
if (keys.length === 0 || keys.length > Limits.maxBatchKeys)
|
|
125
|
+
throw local('invalid_keys', `keys takes 1 to ${Limits.maxBatchKeys} record keys.`);
|
|
126
|
+
const parts = [`keys=${list(keys, 'keys')}`];
|
|
127
|
+
expansion(parts, options);
|
|
128
|
+
return parts.join('&');
|
|
129
|
+
}
|
|
130
|
+
/** The query string for one record. */
|
|
131
|
+
export function buildRecordQuery(options = {}) {
|
|
132
|
+
const parts = [];
|
|
133
|
+
expansion(parts, options);
|
|
134
|
+
return parts.join('&');
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1C,oHAAoH;AACpH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,WAAW,EAAE,GAAG;IAChB,YAAY,EAAE,EAAE;IAChB,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,CAAC;IACjB,UAAU,EAAE,EAAE;IACd,WAAW,EAAE,EAAE;IACf,SAAS,EAAE,GAAG;CACN,CAAA;AAEV,4HAA4H;AAC5H,MAAM,SAAS,GAA8B,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;AAEvG,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,OAAe,EAAgB,EAAE,CAAC,IAAI,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI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UAA4B,EAAE;IACrF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY;QAAE,MAAM,KAAK,CAAC,cAAc,EAAE,mBAAmB,MAAM,CAAC,YAAY,eAAe,CAAC,CAAA;IAC9I,MAAM,KAAK,GAAG,CAAC,QAAQ,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;IAC5C,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACzB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC;AAED,uCAAuC;AACvC,MAAM,UAAU,gBAAgB,CAAC,UAA4B,EAAE;IAC7D,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IACzB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/** A reference to another record: `{ mode: 'reference', provider: 'data', key }`, with the target beside it as `record` when expanded. */
|
|
2
|
+
export interface ReferenceValue<V = Record<string, unknown>> {
|
|
3
|
+
mode?: 'reference';
|
|
4
|
+
provider?: string;
|
|
5
|
+
key: string;
|
|
6
|
+
record?: DataRecord<V>;
|
|
7
|
+
[extra: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** A value described inline by a model, stored in the record that holds it. */
|
|
10
|
+
export interface InlineValue {
|
|
11
|
+
mode: 'inline';
|
|
12
|
+
model?: string;
|
|
13
|
+
document: Record<string, unknown>;
|
|
14
|
+
[extra: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface DataRecord<V = Record<string, unknown>> {
|
|
17
|
+
key: string;
|
|
18
|
+
model: string;
|
|
19
|
+
name: string | null;
|
|
20
|
+
version: number;
|
|
21
|
+
updatedAtUtc: string;
|
|
22
|
+
/** Keyed by field id. A field the record holds no value for is absent, not null. */
|
|
23
|
+
values: V;
|
|
24
|
+
/** On a record fetched with `generations`: `truncated` is true when the 200-record expansion budget cut it short. */
|
|
25
|
+
meta?: {
|
|
26
|
+
truncated?: boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface FieldDescriptor {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
type: string;
|
|
33
|
+
mandatory: boolean;
|
|
34
|
+
list: boolean;
|
|
35
|
+
localized: boolean;
|
|
36
|
+
settings?: Record<string, unknown>;
|
|
37
|
+
/** Present only for a field the model declared queryable: which of the three it supports. */
|
|
38
|
+
queryable?: {
|
|
39
|
+
filter: boolean;
|
|
40
|
+
sort: boolean;
|
|
41
|
+
facet: boolean;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface ModelDescriptor {
|
|
45
|
+
key: string;
|
|
46
|
+
name: string;
|
|
47
|
+
description: string | null;
|
|
48
|
+
abstract: boolean;
|
|
49
|
+
/** The id of the field that carries a record's name, or null. */
|
|
50
|
+
nameField: string | null;
|
|
51
|
+
/** The key of the model this inherits from, or null when there is none or this key may not read it. */
|
|
52
|
+
parent: string | null;
|
|
53
|
+
fields: FieldDescriptor[];
|
|
54
|
+
}
|
|
55
|
+
export interface ModelsResult {
|
|
56
|
+
partition: {
|
|
57
|
+
key: string;
|
|
58
|
+
};
|
|
59
|
+
models: ModelDescriptor[];
|
|
60
|
+
}
|
|
61
|
+
export interface FacetBucket {
|
|
62
|
+
value: string | number | boolean;
|
|
63
|
+
count: number;
|
|
64
|
+
}
|
|
65
|
+
/** Field id to its most common values; the built-in `model` facet counts matches per concrete model. */
|
|
66
|
+
export type Facets = Record<string, FacetBucket[]>;
|
|
67
|
+
export interface RecordsPage<V = Record<string, unknown>> {
|
|
68
|
+
items: DataRecord<V>[];
|
|
69
|
+
/** Null on the last page. Send it back as `cursor` with the same query. */
|
|
70
|
+
nextCursor: string | null;
|
|
71
|
+
facets?: Facets;
|
|
72
|
+
meta?: {
|
|
73
|
+
truncated?: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface BatchResult<V = Record<string, unknown>> {
|
|
77
|
+
items: DataRecord<V>[];
|
|
78
|
+
/** The keys that could not be read: absent, or not readable by this key. */
|
|
79
|
+
missing: string[];
|
|
80
|
+
meta?: {
|
|
81
|
+
truncated?: boolean;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export type FilterOperator = 'eq' | 'in' | 'prefix' | 'gt' | 'gte' | 'lt' | 'lte' | 'exists';
|
|
85
|
+
/** A scalar operand. A `Date` is sent as an RFC 3339 instant. */
|
|
86
|
+
export type Scalar = string | number | boolean | Date;
|
|
87
|
+
/** A bare scalar means `eq`. An object names the operators; `in` takes an array, `exists` a boolean. */
|
|
88
|
+
export type FieldFilter = Scalar | {
|
|
89
|
+
eq?: Scalar;
|
|
90
|
+
in?: Scalar[];
|
|
91
|
+
prefix?: string;
|
|
92
|
+
gt?: Scalar;
|
|
93
|
+
gte?: Scalar;
|
|
94
|
+
lt?: Scalar;
|
|
95
|
+
lte?: Scalar;
|
|
96
|
+
exists?: boolean;
|
|
97
|
+
};
|
|
98
|
+
export interface ExpansionOptions {
|
|
99
|
+
/** 0 to 5 hops of references to follow; default 0. */
|
|
100
|
+
generations?: number;
|
|
101
|
+
/** Reference field ids to follow; without it every reference is followed. */
|
|
102
|
+
expand?: string[];
|
|
103
|
+
}
|
|
104
|
+
export interface RecordsQuery extends ExpansionOptions {
|
|
105
|
+
/** Lists this model's records and those of every model that inherits from it. Required for filters, field sorts and facets. */
|
|
106
|
+
model?: string;
|
|
107
|
+
search?: string;
|
|
108
|
+
filters?: Record<string, FieldFilter>;
|
|
109
|
+
/** `name` (default), `updated` or a sortable field id; a leading `-` is descending. */
|
|
110
|
+
sort?: string;
|
|
111
|
+
/** 1 to 100; default 25. */
|
|
112
|
+
limit?: number;
|
|
113
|
+
cursor?: string;
|
|
114
|
+
/** At most 5 facetable field ids, and/or `model`. */
|
|
115
|
+
facets?: string[];
|
|
116
|
+
}
|
|
117
|
+
export interface RecordOptions extends ExpansionOptions {
|
|
118
|
+
/** Throw `DataApiError` (`record_not_found`) instead of resolving to `null`. */
|
|
119
|
+
throwIfMissing?: boolean;
|
|
120
|
+
}
|
|
121
|
+
export type RecordResponse<V = Record<string, unknown>> = {
|
|
122
|
+
status: 'ok';
|
|
123
|
+
record: DataRecord<V>;
|
|
124
|
+
etag: string | null;
|
|
125
|
+
} | {
|
|
126
|
+
status: 'notModified';
|
|
127
|
+
etag: string | null;
|
|
128
|
+
} | {
|
|
129
|
+
status: 'missing';
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,0IAA0I;AAC1I,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACzD,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;IACtB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;CACzB;AAED,+EAA+E;AAC/E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrD,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,G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IACtD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,YAAa,SAAQ,gBAAgB;IACpD,+HAA+H;IAC/H,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IACrC,uFAAuF;IACvF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,gFAAgF;IAChF,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAClD;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC5D;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAC9C;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebitex/data-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The client for the ebitex Data Delivery API: typed queries with filters, sorts, facets, keyset paging and reference expansion, for a server or a browser.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ebitex",
|
|
7
|
+
"data",
|
|
8
|
+
"master-data",
|
|
9
|
+
"reference-data",
|
|
10
|
+
"delivery-api"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"homepage": "https://developers.ebitex.io/reference/data-sdk/",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.build.json",
|
|
30
|
+
"lint": "oxlint",
|
|
31
|
+
"test": "vitest run"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^24.0.0",
|
|
35
|
+
"oxlint": "^1.71.0",
|
|
36
|
+
"typescript": "~6.0.2",
|
|
37
|
+
"vitest": "^4.1.10"
|
|
38
|
+
}
|
|
39
|
+
}
|