@arcosmos/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 +202 -0
- package/README.md +157 -2
- package/dist/api.d.ts +2695 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +34 -0
- package/dist/api.js.map +1 -0
- package/dist/client.d.ts +74 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +214 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +41 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +42 -0
- package/dist/errors.js.map +1 -0
- package/dist/helpers.d.ts +42 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +29 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/paging.d.ts +32 -0
- package/dist/paging.d.ts.map +1 -0
- package/dist/paging.js +46 -0
- package/dist/paging.js.map +1 -0
- package/dist/resources.d.ts +122 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +123 -0
- package/dist/resources.js.map +1 -0
- package/package.json +46 -3
- package/src/api.ts +2335 -0
- package/src/client.ts +261 -0
- package/src/errors.ts +58 -0
- package/src/helpers.ts +61 -0
- package/src/index.ts +12 -0
- package/src/paging.ts +60 -0
- package/src/resources.ts +175 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,158 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @arcosmos/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Arcosmos API from TypeScript. Its methods mirror the API's routes, its types come from
|
|
4
|
+
the API's own OpenAPI document, and it returns the API's JSON exactly as sent. Helpers turn the
|
|
5
|
+
values into `@arcosmos/astronomy`'s quantities and coordinates. Runs in Node, Deno, Bun, a
|
|
6
|
+
Worker or a browser (anywhere with `fetch`). Version 0.x: the surface may still change.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @arcosmos/sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
It is also published under the plain name `arcosmos`, which re-exports it whole at the same
|
|
13
|
+
version, so `npm install arcosmos` gives the same client.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Arcosmos, quantity, skyCoord } from '@arcosmos/sdk'
|
|
17
|
+
|
|
18
|
+
const astro = new Arcosmos() // reads ARCOSMOS_API_KEY, or new Arcosmos({ apiKey })
|
|
19
|
+
|
|
20
|
+
const { data: proxima } = await astro.objects.get('Proxima Centauri')
|
|
21
|
+
skyCoord(proxima.position!).galactic.toString() // "313.926 -1.91776"
|
|
22
|
+
const parallax = proxima.measurements.find((m) => m.quantity === 'parallax')!
|
|
23
|
+
quantity(parallax, 'angle').to('arcsec') // its error converted with it
|
|
24
|
+
|
|
25
|
+
for await (const star of astro.objects.nearby('Sun', { radius: '10 ly', has_planets: true })) {
|
|
26
|
+
console.log(star.object?.canonical_name, quantity(star.distance, 'length').to('ly').toString())
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Get a key at https://arcosmos.space/api-keys. Keep it on a server: a key in code a browser
|
|
31
|
+
downloads is anyone's.
|
|
32
|
+
|
|
33
|
+
## The methods
|
|
34
|
+
|
|
35
|
+
One method per route, named and grouped as the API's paths are. Path parameters come first,
|
|
36
|
+
then the query or body with the API's own names (snake_case), then options for the request.
|
|
37
|
+
The [API reference](https://api.arcosmos.space/api/v1/docs) documents every parameter and field,
|
|
38
|
+
and the same text is on each type here.
|
|
39
|
+
|
|
40
|
+
| Method | Route |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `objects.get(identifier)` | `GET /objects/{identifier}` |
|
|
43
|
+
| `objects.planets(identifier)` | `GET /objects/{identifier}/planets` |
|
|
44
|
+
| `objects.nearby(identifier, { radius })` | `GET /objects/{identifier}/nearby`, paged |
|
|
45
|
+
| `objects.distance(identifier, other)` | `GET /objects/{identifier}/distance/{other}` |
|
|
46
|
+
| `objects.resolve({ identifiers })` | `POST /objects/resolve` |
|
|
47
|
+
| `objects.members(identifier)`, `objects.parents(identifier)` | `GET /objects/{identifier}/members`, `/parents`, paged |
|
|
48
|
+
| `objects.solutions(identifier)` | `GET /objects/{identifier}/solutions` |
|
|
49
|
+
| `objects.system(identifier)` | `GET /objects/{identifier}/system` |
|
|
50
|
+
| `objects.cone(identifier, { radius })` | `GET /objects/{identifier}/cone`, paged |
|
|
51
|
+
| `objects.classifications(identifier)` | `GET /objects/{identifier}/classifications` |
|
|
52
|
+
| `sky.nearby({ ra, dec, distance, radius })` | `GET /sky/nearby`, paged |
|
|
53
|
+
| `sky.cone({ ra, dec, radius })` | `GET /sky/cone`, paged |
|
|
54
|
+
| `sky.match({ positions, radius })` | `POST /sky/match` |
|
|
55
|
+
| `stars.search(query)`, `stars.bright(query)` | `GET /stars`, `/stars/bright`, paged |
|
|
56
|
+
| `stars.all()` | `GET /stars/all`: the Response, an Arrow IPC stream |
|
|
57
|
+
| `exoplanets.search(query)` | `GET /exoplanets`, paged |
|
|
58
|
+
| `catalogs.list()`, `catalogs.get(id)` | `GET /catalogs`, `/catalogs/{id}` |
|
|
59
|
+
| `catalogs.record(id, key)` | `GET /catalogs/{id}/records/{key}` |
|
|
60
|
+
| `catalogs.cone(id, { ra, dec, radius })` | `GET /catalogs/{id}/cone`, paged |
|
|
61
|
+
| `types.list()`, `types.get(otype)` | `GET /types`, `/types/{otype}` |
|
|
62
|
+
| `names.complete({ q })` | `GET /names` |
|
|
63
|
+
| `account.get()` | `GET /account` |
|
|
64
|
+
| `apiKeys.get(id)`, `apiKeys.revoke(id)` | `GET`, `DELETE /api-keys/{id}` |
|
|
65
|
+
|
|
66
|
+
`astro.request(operationId, { path, query, body })` reaches any operation by its operationId,
|
|
67
|
+
typed the same way. Creating and listing keys belong to the website (they need a signed-in
|
|
68
|
+
person), so they have no method.
|
|
69
|
+
|
|
70
|
+
## Values
|
|
71
|
+
|
|
72
|
+
- **A quantity** in a query is text with a unit, as the API takes it (`'10 ly'`, `'30 arcsec'`),
|
|
73
|
+
or a `Quantity` of the right kind: `{ radius: q(3, 'pc') }`. The types allow only the units
|
|
74
|
+
the parameter takes; a Quantity in another unit of its kind is converted (`q(0.01, 'kpc')`
|
|
75
|
+
is sent in pc). A bound has no uncertainty, so a Quantity with one is refused.
|
|
76
|
+
- **Numbers** are sent in full, never in exponent form, and lists joined with commas.
|
|
77
|
+
- **Responses** are the API's JSON, unrounded and unconverted, with every uncertainty, limit,
|
|
78
|
+
reference and source as published. Nothing is parsed into objects for you.
|
|
79
|
+
- **`quantity(measurement, kind?)`** makes a `Quantity` of a measurement, with its limit and
|
|
80
|
+
its uncertainty in the form published: symmetric, asymmetric, percentiles, or the error
|
|
81
|
+
ellipse SIMBAD gives a proper motion. With a kind (`'angle'`), the type says so and it is
|
|
82
|
+
checked. A label (a spectral type) throws.
|
|
83
|
+
- **`skyCoord(position, motion?)`** makes a `SkyCoord` in ICRS, its `obstime` the position's
|
|
84
|
+
epoch as a Julian year in TT. Give it a distance or parallax, proper motions and a radial
|
|
85
|
+
velocity, chosen from the object's measurements, to move it with `applySpaceMotion`. A
|
|
86
|
+
SkyCoord takes no uncertainties yet, so pass plain values, such as `q(768.07, 'mas')`.
|
|
87
|
+
|
|
88
|
+
## Pages
|
|
89
|
+
|
|
90
|
+
A paged route returns a `Paged`. Await it for the first page, as the API sends it, or iterate
|
|
91
|
+
it for every result, which follows `metadata.page.next_cursor` with the same query:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const page = await astro.stars.search({ distance_max: '10 pc', sort: 'distance' })
|
|
95
|
+
page.metadata.page.total // how many there are
|
|
96
|
+
|
|
97
|
+
for await (const star of astro.stars.search({ distance_max: '10 pc' })) { ... }
|
|
98
|
+
for await (const page of astro.stars.search({ distance_max: '10 pc' }).pages()) { ... }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Nothing is sent until it is awaited or iterated, and the first page is asked for once.
|
|
102
|
+
|
|
103
|
+
## Errors
|
|
104
|
+
|
|
105
|
+
An error the API answers with is an `ArcosmosError`: its HTTP `status`, the API's `code` and
|
|
106
|
+
`message`, and the `details` that code carries. `is(code)` narrows them:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
try {
|
|
110
|
+
await astro.objects.get('tau CMa')
|
|
111
|
+
} catch (e) {
|
|
112
|
+
if (e instanceof ArcosmosError && e.is('ambiguous_identifier')) e.details.candidates // a 300
|
|
113
|
+
if (e instanceof ArcosmosError && e.is('not_found')) e.details?.suggestions // "Did you mean"
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- A code the API added after this SDK was built still arrives, as a string `is` doesn't know.
|
|
118
|
+
An answer that isn't the API's (a proxy's) has the code `http_<status>`.
|
|
119
|
+
- **Retries:** a `rate_limited` 429 waits out its `Retry-After` (up to 60 s) and tries again,
|
|
120
|
+
as do 502, 503 and 504 and a failed connection, with backoff, up to `maxRetries` (2). A spent
|
|
121
|
+
monthly quota (`quota_exceeded`) and a 500 are thrown at once.
|
|
122
|
+
- **No answer** is a `ConnectionError`, `timedOut` when the request ran past `timeout`
|
|
123
|
+
(60 s per attempt).
|
|
124
|
+
- **`astro.quota`** is the month's `limit`, `remaining` and `resetsAt`, from the last response
|
|
125
|
+
that carried them (keys on a plan do; first-party keys have no quota).
|
|
126
|
+
|
|
127
|
+
## Options
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
new Arcosmos({
|
|
131
|
+
apiKey, // default: the ARCOSMOS_API_KEY environment variable
|
|
132
|
+
baseUrl, // default: https://api.arcosmos.space/api/v1
|
|
133
|
+
fetch, // default: the global fetch
|
|
134
|
+
maxRetries: 2,
|
|
135
|
+
timeout: 60_000, // milliseconds, per attempt
|
|
136
|
+
})
|
|
137
|
+
astro.objects.get('Vega', { signal, timeout, maxRetries }) // per request
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## The contract
|
|
141
|
+
|
|
142
|
+
`src/api.ts` (the types and the operation table) is generated from `openapi.json`, which is
|
|
143
|
+
the document the API's source serves. After changing a route or schema in `api/`, run
|
|
144
|
+
`pnpm --filter @arcosmos/sdk generate` and commit both; `test/openapi.test.ts` fails until
|
|
145
|
+
then. The generator (`scripts/openapi-types.ts`) refuses a JSON Schema keyword it doesn't
|
|
146
|
+
know, rather than typing it loosely.
|
|
147
|
+
|
|
148
|
+
## Tests
|
|
149
|
+
|
|
150
|
+
`pnpm --filter @arcosmos/sdk test`: the client against a fake fetch (URLs, queries, bodies,
|
|
151
|
+
retries, errors, pages, the quota), the helpers against `@arcosmos/astronomy`, a check that
|
|
152
|
+
every operation has a method, paged exactly where the API pages, the types (`tsc` checks
|
|
153
|
+
`test/types.test.ts`), and the contract against the API's source.
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
Apache License 2.0, in `LICENSE`. The rest of the Arcosmos repository is under other licenses:
|
|
158
|
+
its `LICENSING.md` lists them.
|