@kalyptos/bifrost 5.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/dist/client.d.ts +12 -8
- package/dist/client.js +17 -12
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +12 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# @kalyptos/bifrost
|
|
2
2
|
|
|
3
|
-
TypeScript client for the Bifrost API.
|
|
3
|
+
TypeScript client for the Bifrost API.
|
|
4
4
|
|
|
5
|
-
ESM with no runtime dependencies. It
|
|
5
|
+
ESM with no runtime dependencies. It uses the global `fetch` (Node 18 or later, or a browser) unless
|
|
6
|
+
you pass your own.
|
|
6
7
|
|
|
7
8
|
```sh
|
|
8
9
|
npm install @kalyptos/bifrost
|
|
@@ -20,8 +21,10 @@ const { matches } = await bifrost.resolve({ input: 'Rådhuspladsen 1, København
|
|
|
20
21
|
|
|
21
22
|
`resolve`, `search` and `project` take one request and return one result, or take an array and
|
|
22
23
|
return a batch. A batch item that fails is still a result: `{ input, matches: [], error }`.
|
|
23
|
-
`token` is optional: a string, or a function that gives the token for each request.
|
|
24
|
-
|
|
24
|
+
`token` is optional: a string, or a function that gives the token for each request. `fetch` is
|
|
25
|
+
optional too: the client sends every request through it, for retries, logging or tests. Every call,
|
|
26
|
+
`compose` too, takes `{ signal }` as its last argument, to cancel it. A response that is not 2xx
|
|
27
|
+
throws `BifrostError` with `status` and `detail`.
|
|
25
28
|
|
|
26
29
|
## Compose
|
|
27
30
|
|
package/dist/client.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ export type Token = string | (() => string | Promise<string>);
|
|
|
4
4
|
export interface BifrostOptions {
|
|
5
5
|
baseUrl: string;
|
|
6
6
|
token?: Token;
|
|
7
|
+
fetch?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
export interface CallOptions {
|
|
10
|
+
signal?: AbortSignal;
|
|
7
11
|
}
|
|
8
12
|
export interface ValidationIssue {
|
|
9
13
|
loc: (string | number)[];
|
|
@@ -18,12 +22,12 @@ export declare class BifrostError extends Error {
|
|
|
18
22
|
}
|
|
19
23
|
export declare class Bifrost {
|
|
20
24
|
#private;
|
|
21
|
-
constructor({ baseUrl, token }: BifrostOptions);
|
|
22
|
-
resolve(body: ResolveRequest): Promise<MatchResult>;
|
|
23
|
-
resolve(body: ResolveRequest[]): Promise<MatchResult[]>;
|
|
24
|
-
search<T extends SearchTarget>(body: SearchRequest<string, T
|
|
25
|
-
search<T extends SearchTarget>(body: SearchRequest<string, T>[]): Promise<MatchResult<SearchMatch<T>>[]>;
|
|
26
|
-
project(body: ProjectRequest): Promise<ProjectResult>;
|
|
27
|
-
project(body: ProjectRequest[]): Promise<ProjectResult[]>;
|
|
28
|
-
compose<S extends Shape>(fn: (q: Recorder) => S): Promise<Decoded<S>>;
|
|
25
|
+
constructor({ baseUrl, token, fetch }: BifrostOptions);
|
|
26
|
+
resolve(body: ResolveRequest, options?: CallOptions): Promise<MatchResult>;
|
|
27
|
+
resolve(body: ResolveRequest[], options?: CallOptions): Promise<MatchResult[]>;
|
|
28
|
+
search<T extends SearchTarget>(body: SearchRequest<string, T>, options?: CallOptions): Promise<MatchResult<SearchMatch<T>>>;
|
|
29
|
+
search<T extends SearchTarget>(body: SearchRequest<string, T>[], options?: CallOptions): Promise<MatchResult<SearchMatch<T>>[]>;
|
|
30
|
+
project(body: ProjectRequest, options?: CallOptions): Promise<ProjectResult>;
|
|
31
|
+
project(body: ProjectRequest[], options?: CallOptions): Promise<ProjectResult[]>;
|
|
32
|
+
compose<S extends Shape>(fn: (q: Recorder) => S, options?: CallOptions): Promise<Decoded<S>>;
|
|
29
33
|
}
|
package/dist/client.js
CHANGED
|
@@ -12,33 +12,38 @@ export class BifrostError extends Error {
|
|
|
12
12
|
export class Bifrost {
|
|
13
13
|
#baseUrl;
|
|
14
14
|
#token;
|
|
15
|
-
|
|
15
|
+
#fetch;
|
|
16
|
+
constructor({ baseUrl, token, fetch }) {
|
|
16
17
|
this.#baseUrl = baseUrl.replace(/\/+$/, '');
|
|
17
18
|
this.#token = token;
|
|
19
|
+
this.#fetch = fetch;
|
|
18
20
|
}
|
|
19
|
-
resolve(body) {
|
|
20
|
-
return this.#post('/resolve', body);
|
|
21
|
+
resolve(body, options) {
|
|
22
|
+
return this.#post('/resolve', body, options);
|
|
21
23
|
}
|
|
22
|
-
search(body) {
|
|
23
|
-
return this.#post('/search', body);
|
|
24
|
+
search(body, options) {
|
|
25
|
+
return this.#post('/search', body, options);
|
|
24
26
|
}
|
|
25
|
-
project(body) {
|
|
26
|
-
return this.#post('/project', body);
|
|
27
|
+
project(body, options) {
|
|
28
|
+
return this.#post('/project', body, options);
|
|
27
29
|
}
|
|
28
|
-
async compose(fn) {
|
|
30
|
+
async compose(fn, options) {
|
|
29
31
|
const { steps, decode } = record(fn);
|
|
30
|
-
const outputs = (await this.#post('/compose', { steps }));
|
|
32
|
+
const outputs = (await this.#post('/compose', { steps }, options));
|
|
31
33
|
return decode(outputs);
|
|
32
34
|
}
|
|
33
|
-
async #post(path, body) {
|
|
35
|
+
async #post(path, body, { signal } = {}) {
|
|
34
36
|
const headers = { 'content-type': 'application/json' };
|
|
35
37
|
const token = typeof this.#token === 'function' ? await this.#token() : this.#token;
|
|
36
38
|
if (token)
|
|
37
39
|
headers.authorization = `Bearer ${token}`;
|
|
38
|
-
|
|
40
|
+
// called unbound and looked up per call: a browser rejects fetch with a foreign this
|
|
41
|
+
const send = this.#fetch ?? globalThis.fetch;
|
|
42
|
+
const res = await send(this.#baseUrl + path, {
|
|
39
43
|
method: 'POST',
|
|
40
44
|
headers,
|
|
41
|
-
body: JSON.stringify(body)
|
|
45
|
+
body: JSON.stringify(body),
|
|
46
|
+
...(signal && { signal })
|
|
42
47
|
});
|
|
43
48
|
if (!res.ok)
|
|
44
49
|
throw new BifrostError(res.status, await detailOf(res));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Bifrost, BifrostError } from './client.js';
|
|
2
|
-
export type { BifrostOptions, ErrorDetail, Token, ValidationIssue } from './client.js';
|
|
2
|
+
export type { BifrostOptions, CallOptions, ErrorDetail, Token, ValidationIssue } from './client.js';
|
|
3
3
|
export type { CodeSlot, Decoded, Handle, Mapped, ProjectBody, Recorder, RefHandle, Shape, Slot, Step } from './compose.js';
|
|
4
4
|
export type * from './types.js';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ProjectTarget = 'unit' | 'entrance' | 'street' | 'postcode' | 'city' | 'ejendom' | 'kommune' | 'sogn' | 'region' | 'retskreds' | 'politikreds' | 'opstillingskreds' | 'ejerlav';
|
|
1
|
+
export type ProjectTarget = 'unit' | 'entrance' | 'street' | 'postcode' | 'city' | 'ejendom' | 'jordstykke' | 'kommune' | 'sogn' | 'region' | 'retskreds' | 'politikreds' | 'opstillingskreds' | 'ejerlav';
|
|
2
2
|
export type ProjectRoot = ProjectTarget;
|
|
3
3
|
export type SearchTarget = Exclude<ProjectTarget, 'unit' | 'entrance'> | 'stednavn';
|
|
4
4
|
export type FeatureKind = ProjectTarget | 'stednavn';
|
|
@@ -86,6 +86,7 @@ export interface PropertyRefs {
|
|
|
86
86
|
complete: boolean;
|
|
87
87
|
}
|
|
88
88
|
export interface Parcel {
|
|
89
|
+
id: string;
|
|
89
90
|
matrikelnummer: string | null;
|
|
90
91
|
ejerlavskode: number | null;
|
|
91
92
|
ejerlav: string | null;
|
|
@@ -116,8 +117,12 @@ export interface Components {
|
|
|
116
117
|
sub_locality?: string;
|
|
117
118
|
stednavn?: string;
|
|
118
119
|
type?: string;
|
|
120
|
+
bfenummer?: number;
|
|
121
|
+
/** on an ejendom match: deprecated, read ejendom.parcels */
|
|
119
122
|
matrikelnummer?: string;
|
|
123
|
+
/** on an ejendom match: deprecated, read ejendom.parcels */
|
|
120
124
|
ejerlavskode?: number;
|
|
125
|
+
/** on an ejendom match: deprecated, read ejendom.parcels */
|
|
121
126
|
ejerlav?: string;
|
|
122
127
|
postcodes?: Area<'postcode', 'city'>[];
|
|
123
128
|
kommuner?: Area<'kommunekode', 'kommune'>[];
|
|
@@ -131,10 +136,16 @@ export interface StednavnRef {
|
|
|
131
136
|
kind: 'stednavn';
|
|
132
137
|
id: string;
|
|
133
138
|
}
|
|
139
|
+
export interface Alias {
|
|
140
|
+
result: string;
|
|
141
|
+
from: string;
|
|
142
|
+
to: string;
|
|
143
|
+
}
|
|
134
144
|
export interface Match<R extends Ref | StednavnRef = Ref> {
|
|
135
145
|
ref: R;
|
|
136
146
|
refs: Partial<Record<FeatureKind, string>>;
|
|
137
147
|
result: string;
|
|
148
|
+
aliases?: Alias[];
|
|
138
149
|
lifecycle: Lifecycle | null;
|
|
139
150
|
components: Components;
|
|
140
151
|
ejendom?: Ejendom;
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// wire types, mirroring app/src/bifrost/api/
|
|
1
|
+
// wire types, mirroring app/src/bifrost/api/requests.py and wire.py
|
|
2
2
|
export {};
|