@nyc-transit-kit/soda3 0.1.1 → 0.1.3
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/package.json +3 -3
- package/src/client.ts +8 -2
- package/src/errors.ts +7 -0
- package/src/index.ts +10 -2
- package/src/internal/services.ts +23 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyc-transit-kit/soda3",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"test": "bun test ./test"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nyc-transit-kit/contracts": "0.1.
|
|
28
|
-
"effect": "4.0.0-beta.
|
|
27
|
+
"@nyc-transit-kit/contracts": "0.1.3",
|
|
28
|
+
"effect": "4.0.0-beta.92"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
package/src/client.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export { catalogSearch } from "./catalog"
|
|
2
2
|
export { exportResponse } from "./export"
|
|
3
3
|
export { Soda3HttpLive } from "./internal/http"
|
|
4
|
-
export type { Soda3ClientConfigShape } from "./internal/services"
|
|
5
|
-
export {
|
|
4
|
+
export type { Soda3ClientConfigShape, Soda3LayerOptions } from "./internal/services"
|
|
5
|
+
export {
|
|
6
|
+
Soda3ClientConfig,
|
|
7
|
+
Soda3Live,
|
|
8
|
+
soda3ConfigLayer,
|
|
9
|
+
soda3FetchLayer,
|
|
10
|
+
soda3Layer
|
|
11
|
+
} from "./internal/services"
|
|
6
12
|
export { queryRows } from "./query"
|
package/src/errors.ts
CHANGED
|
@@ -47,5 +47,12 @@ export type Soda3ClientError =
|
|
|
47
47
|
| TimeoutError
|
|
48
48
|
| RetryExhaustedError
|
|
49
49
|
|
|
50
|
+
export const isSoda3ClientError = (value: unknown): value is Soda3ClientError =>
|
|
51
|
+
value instanceof InvalidInputError ||
|
|
52
|
+
value instanceof ProviderHttpError ||
|
|
53
|
+
value instanceof ProviderContractError ||
|
|
54
|
+
value instanceof TimeoutError ||
|
|
55
|
+
value instanceof RetryExhaustedError
|
|
56
|
+
|
|
50
57
|
export const isRetryableProviderError = (error: Soda3ClientError): error is ProviderHttpError =>
|
|
51
58
|
error._tag === "ProviderHttpError" && error.retryable
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export const packageName = "@nyc-transit-kit/soda3"
|
|
2
2
|
export { buildCatalogSearchUrl, catalogSearch } from "./catalog"
|
|
3
|
-
export type { Soda3ClientConfigShape } from "./client"
|
|
4
|
-
export {
|
|
3
|
+
export type { Soda3ClientConfigShape, Soda3LayerOptions } from "./client"
|
|
4
|
+
export {
|
|
5
|
+
Soda3ClientConfig,
|
|
6
|
+
Soda3HttpLive,
|
|
7
|
+
Soda3Live,
|
|
8
|
+
soda3ConfigLayer,
|
|
9
|
+
soda3FetchLayer,
|
|
10
|
+
soda3Layer
|
|
11
|
+
} from "./client"
|
|
5
12
|
export {
|
|
6
13
|
buildExportUrl,
|
|
7
14
|
buildQueryUrl,
|
|
@@ -16,6 +23,7 @@ export type { Soda3ClientError } from "./errors"
|
|
|
16
23
|
export {
|
|
17
24
|
InvalidInputError,
|
|
18
25
|
isRetryableProviderError,
|
|
26
|
+
isSoda3ClientError,
|
|
19
27
|
ProviderContractError,
|
|
20
28
|
ProviderHttpError,
|
|
21
29
|
RetryExhaustedError,
|
package/src/internal/services.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Context from "effect/Context"
|
|
2
2
|
import * as Layer from "effect/Layer"
|
|
3
|
+
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient"
|
|
3
4
|
import { Soda3HttpLive } from "./http"
|
|
4
5
|
|
|
5
6
|
export interface Soda3ClientConfigShape {
|
|
@@ -8,6 +9,10 @@ export interface Soda3ClientConfigShape {
|
|
|
8
9
|
readonly timeoutMs?: number
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
export interface Soda3LayerOptions extends Soda3ClientConfigShape {
|
|
13
|
+
readonly fetch?: typeof fetch
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
export class Soda3ClientConfig extends Context.Service<Soda3ClientConfig, Soda3ClientConfigShape>()(
|
|
12
17
|
"@nyc-transit-kit/soda3/Soda3ClientConfig"
|
|
13
18
|
) {
|
|
@@ -16,4 +21,21 @@ export class Soda3ClientConfig extends Context.Service<Soda3ClientConfig, Soda3C
|
|
|
16
21
|
})
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
export const
|
|
24
|
+
export const soda3ConfigLayer = (options: Soda3ClientConfigShape = {}) =>
|
|
25
|
+
Layer.succeed(Soda3ClientConfig)({
|
|
26
|
+
retryTimes: options.retryTimes ?? 0,
|
|
27
|
+
...(options.appToken === undefined ? {} : { appToken: options.appToken }),
|
|
28
|
+
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs })
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
export const soda3FetchLayer = (fetchImplementation?: typeof fetch) =>
|
|
32
|
+
fetchImplementation === undefined
|
|
33
|
+
? Soda3HttpLive
|
|
34
|
+
: FetchHttpClient.layer.pipe(
|
|
35
|
+
Layer.provide(Layer.succeed(FetchHttpClient.Fetch, fetchImplementation))
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
export const soda3Layer = (options: Soda3LayerOptions = {}) =>
|
|
39
|
+
Layer.mergeAll(soda3ConfigLayer(options), soda3FetchLayer(options.fetch))
|
|
40
|
+
|
|
41
|
+
export const Soda3Live = soda3Layer()
|