@mailwoman/core 2.1.0 → 3.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/out/api/APIClient.d.ts +57 -0
- package/out/api/APIClient.d.ts.map +1 -0
- package/out/api/APIClient.js +108 -0
- package/out/api/APIClient.js.map +1 -0
- package/out/api/headless.d.ts +17 -0
- package/out/api/headless.d.ts.map +1 -0
- package/out/api/headless.js +18 -0
- package/out/api/headless.js.map +1 -0
- package/out/api/index.d.ts +11 -0
- package/out/api/index.d.ts.map +1 -0
- package/out/api/index.js +11 -0
- package/out/api/index.js.map +1 -0
- package/out/api/responses.d.ts +48 -0
- package/out/api/responses.d.ts.map +1 -0
- package/out/api/responses.js +68 -0
- package/out/api/responses.js.map +1 -0
- package/out/collections.d.ts +66 -0
- package/out/collections.d.ts.map +1 -0
- package/out/collections.js +97 -0
- package/out/collections.js.map +1 -0
- package/out/db/schema.d.ts +21 -0
- package/out/db/schema.d.ts.map +1 -0
- package/out/db/schema.js +16 -0
- package/out/db/schema.js.map +1 -0
- package/out/decoder/build-tree.d.ts +14 -1
- package/out/decoder/build-tree.d.ts.map +1 -1
- package/out/decoder/build-tree.js +37 -9
- package/out/decoder/build-tree.js.map +1 -1
- package/out/decoder/proposals-to-tree.d.ts.map +1 -1
- package/out/decoder/proposals-to-tree.js +2 -0
- package/out/decoder/proposals-to-tree.js.map +1 -1
- package/out/decoder/serialize-xml.d.ts +22 -1
- package/out/decoder/serialize-xml.d.ts.map +1 -1
- package/out/decoder/serialize-xml.js +64 -4
- package/out/decoder/serialize-xml.js.map +1 -1
- package/out/decoder/types.d.ts +45 -0
- package/out/decoder/types.d.ts.map +1 -1
- package/out/decoder/types.js +6 -0
- package/out/decoder/types.js.map +1 -1
- package/out/errors/index.d.ts +9 -0
- package/out/errors/index.d.ts.map +1 -0
- package/out/errors/index.js +9 -0
- package/out/errors/index.js.map +1 -0
- package/out/errors/schema.d.ts +69 -0
- package/out/errors/schema.d.ts.map +1 -0
- package/out/errors/schema.js +102 -0
- package/out/errors/schema.js.map +1 -0
- package/out/identifiers.d.ts +18 -0
- package/out/identifiers.d.ts.map +1 -0
- package/out/identifiers.js +49 -0
- package/out/identifiers.js.map +1 -0
- package/out/index.d.ts +3 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -4
- package/out/index.js.map +1 -1
- package/out/kysley/adapter.d.ts +13 -0
- package/out/kysley/adapter.d.ts.map +1 -0
- package/out/kysley/adapter.js +25 -0
- package/out/kysley/adapter.js.map +1 -0
- package/out/kysley/client.d.ts +16 -0
- package/out/kysley/client.d.ts.map +1 -0
- package/out/kysley/client.js +22 -0
- package/out/kysley/client.js.map +1 -0
- package/out/kysley/dialect-config.d.ts +27 -0
- package/out/kysley/dialect-config.d.ts.map +1 -0
- package/out/kysley/dialect-config.js +7 -0
- package/out/kysley/dialect-config.js.map +1 -0
- package/out/kysley/dialect.d.ts +39 -0
- package/out/kysley/dialect.d.ts.map +1 -0
- package/out/kysley/dialect.js +49 -0
- package/out/kysley/dialect.js.map +1 -0
- package/out/kysley/driver.d.ts +22 -0
- package/out/kysley/driver.d.ts.map +1 -0
- package/out/kysley/driver.js +114 -0
- package/out/kysley/driver.js.map +1 -0
- package/out/lifecycle/ServiceSymbol.d.ts +59 -0
- package/out/lifecycle/ServiceSymbol.d.ts.map +1 -0
- package/out/lifecycle/ServiceSymbol.js +62 -0
- package/out/lifecycle/ServiceSymbol.js.map +1 -0
- package/out/lifecycle/index.d.ts +11 -0
- package/out/lifecycle/index.d.ts.map +1 -0
- package/out/lifecycle/index.js +11 -0
- package/out/lifecycle/index.js.map +1 -0
- package/out/lifecycle/lru-cache.d.ts +22 -0
- package/out/lifecycle/lru-cache.d.ts.map +1 -0
- package/out/lifecycle/lru-cache.js +31 -0
- package/out/lifecycle/lru-cache.js.map +1 -0
- package/out/lifecycle/services.d.ts +145 -0
- package/out/lifecycle/services.d.ts.map +1 -0
- package/out/lifecycle/services.js +190 -0
- package/out/lifecycle/services.js.map +1 -0
- package/out/logging/index.d.ts +7 -0
- package/out/logging/index.d.ts.map +1 -0
- package/out/logging/index.js +7 -0
- package/out/logging/index.js.map +1 -0
- package/out/logging/shared.d.ts +60 -0
- package/out/logging/shared.d.ts.map +1 -0
- package/out/logging/shared.js +100 -0
- package/out/logging/shared.js.map +1 -0
- package/out/logging/tables.d.ts +7 -0
- package/out/logging/tables.d.ts.map +1 -0
- package/out/logging/tables.js +75 -0
- package/out/logging/tables.js.map +1 -0
- package/out/objects.d.ts +96 -0
- package/out/objects.d.ts.map +1 -0
- package/out/objects.js +96 -0
- package/out/objects.js.map +1 -0
- package/out/parser/proposal-pipeline.d.ts.map +1 -1
- package/out/parser/proposal-pipeline.js +0 -1
- package/out/parser/proposal-pipeline.js.map +1 -1
- package/out/pipeline/index.d.ts +14 -0
- package/out/pipeline/index.d.ts.map +1 -0
- package/out/pipeline/index.js +11 -0
- package/out/pipeline/index.js.map +1 -0
- package/out/pipeline/reconcile.d.ts +135 -0
- package/out/pipeline/reconcile.d.ts.map +1 -0
- package/out/pipeline/reconcile.js +355 -0
- package/out/pipeline/reconcile.js.map +1 -0
- package/out/pipeline/runtime-pipeline.d.ts +29 -0
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -0
- package/out/pipeline/runtime-pipeline.js +339 -0
- package/out/pipeline/runtime-pipeline.js.map +1 -0
- package/out/pipeline/span-logit-aggregation.d.ts +57 -0
- package/out/pipeline/span-logit-aggregation.d.ts.map +1 -0
- package/out/pipeline/span-logit-aggregation.js +105 -0
- package/out/pipeline/span-logit-aggregation.js.map +1 -0
- package/out/pipeline/types.d.ts +215 -0
- package/out/pipeline/types.d.ts.map +1 -0
- package/out/pipeline/types.js +16 -0
- package/out/pipeline/types.js.map +1 -0
- package/out/resolver/index.d.ts +9 -0
- package/out/resolver/index.d.ts.map +1 -0
- package/out/resolver/index.js +8 -0
- package/out/resolver/index.js.map +1 -0
- package/out/resolver/resolve.d.ts +21 -0
- package/out/resolver/resolve.d.ts.map +1 -0
- package/out/resolver/resolve.js +118 -0
- package/out/resolver/resolve.js.map +1 -0
- package/out/resolver/types.d.ts +118 -0
- package/out/resolver/types.d.ts.map +1 -0
- package/out/resolver/types.js +26 -0
- package/out/resolver/types.js.map +1 -0
- package/out/resources/git.d.ts +1 -1
- package/out/resources/index.d.ts +0 -1
- package/out/resources/index.d.ts.map +1 -1
- package/out/resources/index.js +0 -1
- package/out/resources/index.js.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.d.ts +0 -1
- package/out/resources/whosonfirst/DataSourceCache.d.ts.map +1 -1
- package/out/resources/whosonfirst/DataSourceCache.js +0 -1
- package/out/resources/whosonfirst/DataSourceCache.js.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts +2 -2
- package/out/resources/whosonfirst/PlacetypeDataSource.d.ts.map +1 -1
- package/out/resources/whosonfirst/PlacetypeDataSource.js +9 -6
- package/out/resources/whosonfirst/PlacetypeDataSource.js.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts +23 -1
- package/out/resources/whosonfirst/placetypes/admin.d.ts.map +1 -1
- package/out/resources/whosonfirst/placetypes/admin.js +14 -1
- package/out/resources/whosonfirst/placetypes/admin.js.map +1 -1
- package/out/routing/index.d.ts +67 -0
- package/out/routing/index.d.ts.map +1 -0
- package/out/routing/index.js +114 -0
- package/out/routing/index.js.map +1 -0
- package/out/sets.d.ts +2 -0
- package/out/sets.d.ts.map +1 -0
- package/out/sets.js +2 -0
- package/out/sets.js.map +1 -0
- package/package.json +28 -2
- package/out/resources/db/index.d.ts +0 -57
- package/out/resources/db/index.d.ts.map +0 -1
- package/out/resources/db/index.js +0 -57
- package/out/resources/db/index.js.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { type IRuntimeLogger } from "@mailwoman/core/logging";
|
|
7
|
+
import { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse, type CreateAxiosDefaults } from "axios";
|
|
8
|
+
import { type AxiosCacheInstance, type CacheAxiosResponse, type CacheOptions } from "axios-cache-interceptor";
|
|
9
|
+
export type { IRuntimeLogger };
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for an API client.
|
|
12
|
+
*/
|
|
13
|
+
export interface APIClientConfig {
|
|
14
|
+
/**
|
|
15
|
+
* The logged display name of the API client.
|
|
16
|
+
*/
|
|
17
|
+
displayName: string;
|
|
18
|
+
/**
|
|
19
|
+
* Options for caching responses.
|
|
20
|
+
*/
|
|
21
|
+
caching?: CacheOptions;
|
|
22
|
+
/**
|
|
23
|
+
* How many requests to make per minute before enforcing a cooldown.
|
|
24
|
+
*/
|
|
25
|
+
requestsPerMinute?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Axios configuration.
|
|
28
|
+
*/
|
|
29
|
+
axios?: CreateAxiosDefaults;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A base class for API clients used in Mailwoman, providing features like request cooldowns,
|
|
33
|
+
* response caching, and integrated logging.
|
|
34
|
+
*/
|
|
35
|
+
export declare class APIClient<C extends APIClientConfig = APIClientConfig> extends EventTarget implements AsyncDisposable {
|
|
36
|
+
#private;
|
|
37
|
+
readonly config: C;
|
|
38
|
+
get $cooldown(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* The prefixed logger for the API client.
|
|
41
|
+
*/
|
|
42
|
+
readonly logger: IRuntimeLogger;
|
|
43
|
+
/**
|
|
44
|
+
* The Axios instance for the API client.
|
|
45
|
+
*/
|
|
46
|
+
readonly axios: AxiosInstance | AxiosCacheInstance;
|
|
47
|
+
constructor(config: C);
|
|
48
|
+
/**
|
|
49
|
+
* Perform a fetch operation using the API's Axios instance.
|
|
50
|
+
*/
|
|
51
|
+
fetch: <T>(options: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
|
|
52
|
+
protected setCooldown: (nextCooldown: number) => void;
|
|
53
|
+
protected updateCooldownAfterResponse: (response: CacheAxiosResponse | AxiosResponse) => CacheAxiosResponse | AxiosResponse<unknown, unknown>;
|
|
54
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
55
|
+
toString(): string;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=APIClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"APIClient.d.ts","sourceRoot":"","sources":["../../api/APIClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAc,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,OAAO,CAAA;AACxH,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EAEjB,MAAM,yBAAyB,CAAA;AAIhC,YAAY,EAAE,cAAc,EAAE,CAAA;AAE9B;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAA;IAEtB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;OAEG;IACH,KAAK,CAAC,EAAE,mBAAmB,CAAA;CAC3B;AAED;;;GAGG;AACH,qBAAa,SAAS,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,CAAE,SAAQ,WAAY,YAAW,eAAe;;IACjH,SAAgB,MAAM,EAAE,CAAC,CAAA;IAOzB,IAAW,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAEpC;IAED;;OAEG;IACH,SAAgB,MAAM,EAAE,cAAc,CAAA;IACtC;;OAEG;IACH,SAAgB,KAAK,EAAE,aAAa,GAAG,kBAAkB,CAAA;gBAE7C,MAAM,EAAE,CAAC;IAyCrB;;OAEG;IACI,KAAK,GAAU,CAAC,EAAE,SAAS,kBAAkB,KAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAM/E;IAED,SAAS,CAAC,WAAW,GAAI,cAAc,MAAM,KAAG,IAAI,CAYnD;IAED,SAAS,CAAC,2BAA2B,GACpC,UAAU,kBAAkB,GAAG,aAAa,KAC1C,kBAAkB,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAkBtD;IAEY,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAYnC,QAAQ;CAGxB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { ConsoleLogger } from "@mailwoman/core/logging";
|
|
7
|
+
import Axios, {} from "axios";
|
|
8
|
+
import { setupCache, } from "axios-cache-interceptor";
|
|
9
|
+
import { ServiceSymbol } from "../lifecycle/ServiceSymbol.js";
|
|
10
|
+
import { delegateAxiosError } from "./responses.js";
|
|
11
|
+
/**
|
|
12
|
+
* A base class for API clients used in Mailwoman, providing features like request cooldowns,
|
|
13
|
+
* response caching, and integrated logging.
|
|
14
|
+
*/
|
|
15
|
+
export class APIClient extends EventTarget {
|
|
16
|
+
config;
|
|
17
|
+
#cooldownWithResolvers = null;
|
|
18
|
+
#requestInterval = 0;
|
|
19
|
+
#requestCountWithinCooldown = 0;
|
|
20
|
+
#lastRequestTime = 0;
|
|
21
|
+
get $cooldown() {
|
|
22
|
+
return this.#cooldownWithResolvers?.promise || Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The prefixed logger for the API client.
|
|
26
|
+
*/
|
|
27
|
+
logger;
|
|
28
|
+
/**
|
|
29
|
+
* The Axios instance for the API client.
|
|
30
|
+
*/
|
|
31
|
+
axios;
|
|
32
|
+
constructor(config) {
|
|
33
|
+
super();
|
|
34
|
+
this.config = config;
|
|
35
|
+
this.logger = ConsoleLogger.prefix(config.displayName);
|
|
36
|
+
const axiosInstance = Axios.create({
|
|
37
|
+
...config.axios,
|
|
38
|
+
});
|
|
39
|
+
if (config.caching) {
|
|
40
|
+
this.axios = setupCache(axiosInstance, {
|
|
41
|
+
debug: (msg) => {
|
|
42
|
+
this.logger.info(msg);
|
|
43
|
+
},
|
|
44
|
+
ttl: 60 * 60 * 1000, // 1 hour
|
|
45
|
+
...config.caching,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.axios = axiosInstance;
|
|
50
|
+
}
|
|
51
|
+
this.axios.interceptors.response.use((response) => {
|
|
52
|
+
const cachedLabel = response.cached ? " (cached)" : "(uncached)";
|
|
53
|
+
this.logger.debug(`${response.status} ${cachedLabel} ${response.config.method?.toUpperCase()}: ${response.config.url}`);
|
|
54
|
+
return response;
|
|
55
|
+
});
|
|
56
|
+
this.axios.interceptors.response.use(undefined, delegateAxiosError);
|
|
57
|
+
this.#requestInterval = typeof config.requestsPerMinute === "number" ? 60000 / config.requestsPerMinute : 0;
|
|
58
|
+
if (this.#requestInterval) {
|
|
59
|
+
this.axios.interceptors.response.use(this.updateCooldownAfterResponse);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Perform a fetch operation using the API's Axios instance.
|
|
64
|
+
*/
|
|
65
|
+
fetch = async (options) => {
|
|
66
|
+
await this.$cooldown;
|
|
67
|
+
const method = options.method?.toUpperCase() || "GET";
|
|
68
|
+
this.logger.debug(`${method}: ${options.url}`);
|
|
69
|
+
return this.axios(options);
|
|
70
|
+
};
|
|
71
|
+
setCooldown = (nextCooldown) => {
|
|
72
|
+
const nextCooldownWithResolvers = Promise.withResolvers();
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
this.#requestCountWithinCooldown = 0;
|
|
75
|
+
nextCooldownWithResolvers.resolve();
|
|
76
|
+
this.dispatchEvent(new Event("cooldown_end"));
|
|
77
|
+
}, nextCooldown);
|
|
78
|
+
this.#cooldownWithResolvers = nextCooldownWithResolvers;
|
|
79
|
+
this.dispatchEvent(new Event("cooldown_start"));
|
|
80
|
+
};
|
|
81
|
+
updateCooldownAfterResponse = (response) => {
|
|
82
|
+
this.#cooldownWithResolvers?.resolve();
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
const previousRequestTime = this.#lastRequestTime;
|
|
85
|
+
this.#lastRequestTime = now;
|
|
86
|
+
if (!this.config.requestsPerMinute)
|
|
87
|
+
return response;
|
|
88
|
+
this.#requestCountWithinCooldown++;
|
|
89
|
+
const elapsed = now - previousRequestTime;
|
|
90
|
+
const cooldown = this.#requestInterval - elapsed;
|
|
91
|
+
if (this.#requestCountWithinCooldown >= this.config.requestsPerMinute) {
|
|
92
|
+
this.setCooldown(cooldown);
|
|
93
|
+
}
|
|
94
|
+
return response;
|
|
95
|
+
};
|
|
96
|
+
async [Symbol.asyncDispose]() {
|
|
97
|
+
this.#cooldownWithResolvers?.resolve();
|
|
98
|
+
const storedCache = this.config.caching?.storage;
|
|
99
|
+
if (ServiceSymbol.isAsyncDisposable(storedCache)) {
|
|
100
|
+
await storedCache[Symbol.asyncDispose]();
|
|
101
|
+
}
|
|
102
|
+
return Promise.resolve();
|
|
103
|
+
}
|
|
104
|
+
toString() {
|
|
105
|
+
return `${this.config.displayName} API Client`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=APIClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"APIClient.js","sourceRoot":"","sources":["../../api/APIClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAuB,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,EAAE,EAA6F,MAAM,OAAO,CAAA;AACxH,OAAO,EAIN,UAAU,GACV,MAAM,yBAAyB,CAA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AW,CAAC,EAAE,CAAC;YAClD,MAAM,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAA;QACzC,CAAC;QAED,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IACzB,CAAC;IAEe,QAAQ;QACvB,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,aAAa,CAAA;IAC/C,CAAC;CACD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Headless browser utilities.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Common user agent strings.
|
|
10
|
+
*/
|
|
11
|
+
export declare enum UserAgent {
|
|
12
|
+
/**
|
|
13
|
+
* IPad OS 13.0 Safari.
|
|
14
|
+
*/
|
|
15
|
+
iPadSafari = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15"
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=headless.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless.d.ts","sourceRoot":"","sources":["../../api/headless.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,oBAAY,SAAS;IACpB;;OAEG;IACH,UAAU,wHAAwH;CAClI"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Headless browser utilities.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Common user agent strings.
|
|
10
|
+
*/
|
|
11
|
+
export var UserAgent;
|
|
12
|
+
(function (UserAgent) {
|
|
13
|
+
/**
|
|
14
|
+
* IPad OS 13.0 Safari.
|
|
15
|
+
*/
|
|
16
|
+
UserAgent["iPadSafari"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15";
|
|
17
|
+
})(UserAgent || (UserAgent = {}));
|
|
18
|
+
//# sourceMappingURL=headless.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless.js","sourceRoot":"","sources":["../../api/headless.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACpB;;OAEG;IACH,+IAAkI,CAAA;AACnI,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Core API utilities.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./APIClient.js";
|
|
9
|
+
export * from "./headless.js";
|
|
10
|
+
export * from "./responses.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
package/out/api/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Core API utilities.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./APIClient.js";
|
|
9
|
+
export * from "./headless.js";
|
|
10
|
+
export * from "./responses.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* API response utilities.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A response container, wrapping the actual response body.
|
|
10
|
+
*/
|
|
11
|
+
export interface ResponseContainer<Body> {
|
|
12
|
+
data: Body;
|
|
13
|
+
}
|
|
14
|
+
export type ResponseLike<Body> = ResponseContainer<Body> | Body;
|
|
15
|
+
/**
|
|
16
|
+
* Type-helper to pluck the response body, possibly from within an Axios response.
|
|
17
|
+
*
|
|
18
|
+
* This is useful when normalizing a new Axios response and a cached local response.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export type ExtractResponseData<T> = T extends ResponseContainer<infer Body> ? Body : T;
|
|
23
|
+
/**
|
|
24
|
+
* Type-helper to recursively pluck the `data` property from a response body.
|
|
25
|
+
*
|
|
26
|
+
* This is useful when an API nests the actual response body within a `data` property.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export type ExtractResponseBodyData<Body> = Body extends {
|
|
31
|
+
data: infer Data;
|
|
32
|
+
} ? ExtractResponseBodyData<Data> : Body;
|
|
33
|
+
/**
|
|
34
|
+
* Helper function to recursively pluck the `data` property from a response body.
|
|
35
|
+
*
|
|
36
|
+
* This is useful when an API nests the actual response body within a `data` property.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare function pluckResponseData<Body>(responseContainer: ResponseContainer<Body>): ExtractResponseBodyData<Body>;
|
|
41
|
+
export declare function checkConnectivity(connectivityURL?: URL | string): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Delegate Axios errors to an appropriate error handler.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export declare function delegateAxiosError(error: unknown): Promise<unknown>;
|
|
48
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../api/responses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,IAAI;IACtC,IAAI,EAAE,IAAI,CAAA;CACV;AAED,MAAM,MAAM,YAAY,CAAC,IAAI,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAE/D;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,iBAAiB,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,CAAA;AAmBvF;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,CAAC,IAAI,IAAI,IAAI,SAAS;IACxD,IAAI,EAAE,MAAM,IAAI,CAAA;CAChB,GACE,uBAAuB,CAAC,IAAI,CAAC,GAC7B,IAAI,CAAA;AAEP;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;AASlH,wBAAgB,iBAAiB,CAChC,eAAe,GAAE,GAAG,GAAG,MAA6D,GAClF,OAAO,CAAC,OAAO,CAAC,CAMlB;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CA0CzE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* API response utilities.
|
|
7
|
+
*/
|
|
8
|
+
import { AxiosError, HttpStatusCode, isAxiosError } from "axios";
|
|
9
|
+
import { ResourceError } from "../errors/schema.js";
|
|
10
|
+
import { ConsoleLogger } from "../logging/index.js";
|
|
11
|
+
function isResponseContainer(input) {
|
|
12
|
+
return typeof input === "object" && input !== null && "data" in input;
|
|
13
|
+
}
|
|
14
|
+
function pluckResponseBody(input) {
|
|
15
|
+
if (isResponseContainer(input))
|
|
16
|
+
return input.data;
|
|
17
|
+
return input;
|
|
18
|
+
}
|
|
19
|
+
export function pluckResponseData(input) {
|
|
20
|
+
const body = pluckResponseBody(input);
|
|
21
|
+
if (isResponseContainer(body))
|
|
22
|
+
return pluckResponseData(body);
|
|
23
|
+
return body;
|
|
24
|
+
}
|
|
25
|
+
export function checkConnectivity(connectivityURL = "https://connectivitycheck.gstatic.com/generate_204") {
|
|
26
|
+
return fetch(connectivityURL, {
|
|
27
|
+
method: "HEAD",
|
|
28
|
+
})
|
|
29
|
+
.then((response) => response.ok)
|
|
30
|
+
.catch(() => false);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Delegate Axios errors to an appropriate error handler.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export async function delegateAxiosError(error) {
|
|
38
|
+
{
|
|
39
|
+
if (!isAxiosError(error))
|
|
40
|
+
return Promise.reject(error);
|
|
41
|
+
const { response, code: networkErrorCode } = error;
|
|
42
|
+
if (networkErrorCode === "ENOTFOUND") {
|
|
43
|
+
const internetReachable = await checkConnectivity();
|
|
44
|
+
if (!internetReachable)
|
|
45
|
+
throw ResourceError.from(500, "Could not reach host. Are we connected to the internet?", "axios", "network", "unreachable");
|
|
46
|
+
}
|
|
47
|
+
if (!response)
|
|
48
|
+
throw ResourceError.from(500, "Internal Server Error", "axios", "response", "missing");
|
|
49
|
+
if (response.status === HttpStatusCode.Unauthorized) {
|
|
50
|
+
throw ResourceError.from(401, "Unauthorized");
|
|
51
|
+
}
|
|
52
|
+
if (!networkErrorCode) {
|
|
53
|
+
throw ResourceError.from(500, "Internal Server Error", "axios", "code", "missing");
|
|
54
|
+
}
|
|
55
|
+
switch (networkErrorCode) {
|
|
56
|
+
case AxiosError.ERR_NETWORK:
|
|
57
|
+
throw ResourceError.from(503, "Service Unavailable");
|
|
58
|
+
case AxiosError.ERR_CANCELED:
|
|
59
|
+
case AxiosError.ECONNABORTED:
|
|
60
|
+
case AxiosError.ETIMEDOUT:
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
default:
|
|
63
|
+
ConsoleLogger.warn(`Unhandled network error: ${networkErrorCode}`);
|
|
64
|
+
}
|
|
65
|
+
return Promise.reject(error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../api/responses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAsBnD,SAAS,mBAAmB,CAAO,KAAyB;IAC3D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,CAAA;AACtE,CAAC;AAOD,SAAS,iBAAiB,CAAO,KAAqC;IACrE,IAAI,mBAAmB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,IAAI,CAAA;IAEjD,OAAO,KAAK,CAAA;AACb,CAAC;AAuB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,CAAC;QAED,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACvB,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;QACnF,CAAC;QAED,QAAQ,gBAAgB,EAAE,CAAC;YAC1B,KAAK,UAAU,CAAC,WAAW;gBAC1B,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAA;YACrD,KAAK,UAAU,CAAC,YAAY,CAAC;YAC7B,KAAK,UAAU,CAAC,YAAY,CAAC;YAC7B,KAAK,UAAU,CAAC,SAAS;gBACxB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;YACzB;gBACC,aAAa,CAAC,IAAI,CAAC,4BAA4B,gBAAgB,EAAE,CAAC,CAAA;QACpE,CAAC;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Extracts the property keys of an object that are of type `number`.
|
|
8
|
+
*/
|
|
9
|
+
export type NumericProperties<T> = {
|
|
10
|
+
[K in keyof T]: T[K] extends number ? K : never;
|
|
11
|
+
}[keyof T];
|
|
12
|
+
/**
|
|
13
|
+
* Given an iterable of objects, returns the sum of the specified property.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sumOf<T extends object>(iterable: Iterable<T>, prop: NumericProperties<T>): number;
|
|
16
|
+
/**
|
|
17
|
+
* Given an iterable, returns an array of arrays of the specified size.
|
|
18
|
+
*
|
|
19
|
+
* This is useful for batching asynchronous operations.
|
|
20
|
+
*
|
|
21
|
+
* @param collection The collection to batch.
|
|
22
|
+
* @param batchSize The size of each batch.
|
|
23
|
+
*
|
|
24
|
+
* @returns An iterable of arrays of the specified size.
|
|
25
|
+
*/
|
|
26
|
+
export declare function take<T>(collection: Iterable<T>, batchSize: number): Iterable<T[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Convenience function to await an async iterable.
|
|
29
|
+
*/
|
|
30
|
+
export declare function iterateInParallel<T>(asyncIterable: AsyncIterable<T>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Given an iterable of values, maps each value to a record of the value and the result of the
|
|
33
|
+
* callback.
|
|
34
|
+
*
|
|
35
|
+
* This is a convenience function when an iterable needs mapping to an object-like structure.
|
|
36
|
+
*
|
|
37
|
+
* @category Collections
|
|
38
|
+
* @category Object
|
|
39
|
+
*/
|
|
40
|
+
export declare function pivot<T extends PropertyKey, C extends (value: T) => Promise<unknown> | unknown>(
|
|
41
|
+
/**
|
|
42
|
+
* The iterable to pivot.
|
|
43
|
+
*/
|
|
44
|
+
iterable: Iterable<T>,
|
|
45
|
+
/**
|
|
46
|
+
* The callback to transform each value.
|
|
47
|
+
*/
|
|
48
|
+
callback: C): ReturnType<C> extends PromiseLike<infer U> ? Promise<Record<T, U>> : Record<T, ReturnType<C>>;
|
|
49
|
+
/**
|
|
50
|
+
* Type-predicate for checking if a value is iterable.
|
|
51
|
+
*
|
|
52
|
+
* @category Type Guard
|
|
53
|
+
* @category Object
|
|
54
|
+
*/
|
|
55
|
+
export declare function isIterable<T>(input: unknown): input is Iterable<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Iterable that can be checked for the existence of a member.
|
|
58
|
+
*/
|
|
59
|
+
export interface IndexedIterable<T = unknown> extends Iterable<T> {
|
|
60
|
+
has(value: T): boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Type-predicate for checking if an member within an iterable can be checked for existence.
|
|
64
|
+
*/
|
|
65
|
+
export declare function isIndexedIterable<T>(value: Iterable<T>): value is IndexedIterable<T>;
|
|
66
|
+
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -0,0 +1 @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AAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAElE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAChE,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAA;CACtB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,eAAe,CAAC,CAAC,CAAC,CAEpF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Given an iterable of objects, returns the sum of the specified property.
|
|
8
|
+
*/
|
|
9
|
+
export function sumOf(iterable, prop) {
|
|
10
|
+
let total = 0;
|
|
11
|
+
for (const item of iterable) {
|
|
12
|
+
total += item[prop];
|
|
13
|
+
}
|
|
14
|
+
return total;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Given an iterable, returns an array of arrays of the specified size.
|
|
18
|
+
*
|
|
19
|
+
* This is useful for batching asynchronous operations.
|
|
20
|
+
*
|
|
21
|
+
* @param collection The collection to batch.
|
|
22
|
+
* @param batchSize The size of each batch.
|
|
23
|
+
*
|
|
24
|
+
* @returns An iterable of arrays of the specified size.
|
|
25
|
+
*/
|
|
26
|
+
export function* take(collection, batchSize) {
|
|
27
|
+
const batch = [];
|
|
28
|
+
for (const item of collection) {
|
|
29
|
+
batch.push(item);
|
|
30
|
+
if (batch.length === batchSize) {
|
|
31
|
+
yield batch;
|
|
32
|
+
batch.length = 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (batch.length > 0) {
|
|
36
|
+
yield batch;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convenience function to await an async iterable.
|
|
41
|
+
*/
|
|
42
|
+
export async function iterateInParallel(asyncIterable) {
|
|
43
|
+
for await (const _ of asyncIterable) {
|
|
44
|
+
/* empty */
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Given an iterable of values, maps each value to a record of the value and the result of the
|
|
49
|
+
* callback.
|
|
50
|
+
*
|
|
51
|
+
* This is a convenience function when an iterable needs mapping to an object-like structure.
|
|
52
|
+
*
|
|
53
|
+
* @category Collections
|
|
54
|
+
* @category Object
|
|
55
|
+
*/
|
|
56
|
+
export function pivot(
|
|
57
|
+
/**
|
|
58
|
+
* The iterable to pivot.
|
|
59
|
+
*/
|
|
60
|
+
iterable,
|
|
61
|
+
/**
|
|
62
|
+
* The callback to transform each value.
|
|
63
|
+
*/
|
|
64
|
+
callback) {
|
|
65
|
+
const entries = [];
|
|
66
|
+
let foundThenable = false;
|
|
67
|
+
for (const value of iterable) {
|
|
68
|
+
const result = callback(value);
|
|
69
|
+
if (result && typeof result === "object" && "then" in result) {
|
|
70
|
+
foundThenable = true;
|
|
71
|
+
}
|
|
72
|
+
entries.push([value, result]);
|
|
73
|
+
}
|
|
74
|
+
if (foundThenable) {
|
|
75
|
+
return Promise.all(entries.map(([key, value]) => {
|
|
76
|
+
return Promise.resolve(value).then((resolvedValue) => [key, resolvedValue]);
|
|
77
|
+
})).then(Object.fromEntries);
|
|
78
|
+
}
|
|
79
|
+
const pivotedRecord = Object.fromEntries(entries);
|
|
80
|
+
return pivotedRecord;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Type-predicate for checking if a value is iterable.
|
|
84
|
+
*
|
|
85
|
+
* @category Type Guard
|
|
86
|
+
* @category Object
|
|
87
|
+
*/
|
|
88
|
+
export function isIterable(input) {
|
|
89
|
+
return Symbol.iterator in Object(input);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Type-predicate for checking if an member within an iterable can be checked for existence.
|
|
93
|
+
*/
|
|
94
|
+
export function isIndexedIterable(value) {
|
|
95
|
+
return value && typeof value.has === "function";
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../collections.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH;;GAEG;AACH,MAAM,UAAU,KAAK,CAAmB,QAAqB,EAAE,IAA0B;IACxF,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC7B,KAAK,IAAI,IAAI,CAAC,IAAI,CAAW,CAAA;IAC9B,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,SAAS,CAAC,CAAC,IAAI,CAAI,UAAuB,EAAE,SAAiB;IAClE,MAAM,KAAK,GAAQ,EAAE,CAAA;IAErB,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEhB,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,KAAK,CAAA;YAEX,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;QACjB,CAAC;IACF,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,KAAK,CAAA;IACZ,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAI,aAA+B;IACzE,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,aAAa,EAAE,CAAC;QACrC,WAAW;IACZ,CAAC;AACF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK;AACpB;;GAEG;AACH,QAAqB;AACrB;;GAEG;AACH,QAAW;IAEX,MAAM,OAAO,GAA8B,EAAE,CAAA;IAC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
|
+
* Shared `Database` typing for the Kysely client at `core/kysley/client.ts`.
|
|
7
|
+
*
|
|
8
|
+
* This file intentionally ships an empty schema. Consumers that want compile-time table typing
|
|
9
|
+
* should extend `Kysely<TheirSchema>` directly rather than baking a schema into core — the WOF
|
|
10
|
+
* resolver (Phase 4.2), corpus adapters, and any future consumer all touch different tables.
|
|
11
|
+
*
|
|
12
|
+
* The exported `Database` interface exists so `client.ts` has a target for `Kysely<Database>` and
|
|
13
|
+
* the boilerplate compiles without forcing a concrete schema commitment.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Empty schema marker. Consumers declare their own schema interface and pass it directly to `new
|
|
17
|
+
* Kysely<MySchema>({...})` or instantiate `new DatabaseClient<MySchema>(...)` once `DatabaseClient`
|
|
18
|
+
* becomes generic (Phase 4.2 work).
|
|
19
|
+
*/
|
|
20
|
+
export type Database = Record<string, never>;
|
|
21
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA"}
|
package/out/db/schema.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Shared `Database` typing for the Kysely client at `core/kysley/client.ts`.
|
|
7
|
+
*
|
|
8
|
+
* This file intentionally ships an empty schema. Consumers that want compile-time table typing
|
|
9
|
+
* should extend `Kysely<TheirSchema>` directly rather than baking a schema into core — the WOF
|
|
10
|
+
* resolver (Phase 4.2), corpus adapters, and any future consumer all touch different tables.
|
|
11
|
+
*
|
|
12
|
+
* The exported `Database` interface exists so `client.ts` has a target for `Kysely<Database>` and
|
|
13
|
+
* the boilerplate compiles without forcing a concrete schema commitment.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
|
@@ -21,11 +21,24 @@
|
|
|
21
21
|
* as attributes.
|
|
22
22
|
*/
|
|
23
23
|
import type { AddressTree, DecoderToken } from "./types.js";
|
|
24
|
+
/**
|
|
25
|
+
* Optional caller-supplied attribution stamped on every emitted node. The BIO stream comes from a
|
|
26
|
+
* single model, so there's no per-span variation — one source for the whole tree.
|
|
27
|
+
*
|
|
28
|
+
* Phase 4.3 may overlay a resolver-derived attribution per node on top of this baseline.
|
|
29
|
+
*/
|
|
30
|
+
export interface BuildTreeOpts {
|
|
31
|
+
source?: string;
|
|
32
|
+
sourceId?: string;
|
|
33
|
+
}
|
|
24
34
|
/**
|
|
25
35
|
* Build an `AddressTree` from a raw input string and the token stream produced by the model.
|
|
26
36
|
*
|
|
27
37
|
* @param raw The original input as fed to the tokenizer.
|
|
28
38
|
* @param tokens Model output: one entry per piece with predicted BIO label + confidence.
|
|
39
|
+
* @param opts Optional attribution stamped on every emitted node. Callers in the neural pipeline
|
|
40
|
+
* pass `{ source: "neural", sourceId: <model-card-version> }` to mark provenance for the XML
|
|
41
|
+
* serializer's `src` attribute.
|
|
29
42
|
*/
|
|
30
|
-
export declare function buildAddressTree(raw: string, tokens: DecoderToken[]): AddressTree;
|
|
43
|
+
export declare function buildAddressTree(raw: string, tokens: DecoderToken[], opts?: BuildTreeOpts): AddressTree;
|
|
31
44
|
//# sourceMappingURL=build-tree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-tree.d.ts","sourceRoot":"","sources":["../../decoder/build-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EAAe,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"build-tree.d.ts","sourceRoot":"","sources":["../../decoder/build-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,KAAK,EAAe,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAExE;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AA4FD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,IAAI,GAAE,aAAkB,GAAG,WAAW,CAY3G"}
|