@distilled.cloud/typesense 1.0.0-rc.2 → 1.0.0-rc.20
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 +34 -0
- package/lib/.lazy.json +1 -0
- package/lib/_bundle/lazy.js +4 -0
- package/lib/_bundle/sdk.js +2 -0
- package/lib/_bundle/sdk.js.map +1 -0
- package/lib/credentials.d.ts +14 -5
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +1 -42
- package/lib/errors.d.ts +13 -16
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -24
- package/lib/index.d.ts +5 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -9
- package/lib/index.lazy.js +6 -0
- package/lib/{index.js.map → index.lazy.js.map} +1 -1
- package/lib/protocol.d.ts +6 -5
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +1 -31
- package/lib/retry.d.ts +2 -2
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -33
- package/lib/services/index.js +0 -2
- package/lib/services/typesense.d.ts +1312 -1579
- package/lib/services/typesense.d.ts.map +1 -1
- package/lib/services/typesense.js +111 -2916
- package/lib/services/typesense.js.map +1 -1
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/typesense.js +4 -0
- package/lib/traits.d.ts +1 -1
- package/lib/traits.js +1 -11
- package/package.json +40 -17
- package/src/credentials.ts +19 -21
- package/src/errors.ts +11 -16
- package/src/index.ts +5 -9
- package/src/protocol.ts +23 -24
- package/src/retry.ts +6 -10
- package/src/services/typesense.ts +4238 -5037
- package/src/traits.ts +1 -1
- package/lib/credentials.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/protocol.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/services/index.js.map +0 -1
- package/lib/traits.js.map +0 -1
package/src/index.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @distilled.cloud/typesense
|
|
2
|
+
* @distilled.cloud/typesense -- Typesense SDK for Effect.
|
|
3
3
|
*
|
|
4
|
-
* `./services` is generated by `scripts/generate.ts` from the Smithy model
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy model that
|
|
5
|
+
* `scripts/convert.ts` converts from the Typesense OpenAPI spec. Everything
|
|
6
|
+
* else in this folder is hand-written.
|
|
7
7
|
*/
|
|
8
8
|
export * from "./credentials.ts";
|
|
9
9
|
export * from "./errors.ts";
|
|
10
10
|
export * as T from "./traits.ts";
|
|
11
|
-
export {
|
|
12
|
-
TypesenseProtocol,
|
|
13
|
-
type TypesenseOpError,
|
|
14
|
-
type TypesenseOpContext,
|
|
15
|
-
} from "./protocol.ts";
|
|
11
|
+
export { TypesenseProtocol, type TypesenseOpError, type TypesenseOpContext } from "./protocol.ts";
|
|
16
12
|
export * as Retry from "./retry.ts";
|
|
17
13
|
export * as Services from "./services/index.ts";
|
package/src/protocol.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import type * as API from "@distilled.cloud/core/api";
|
|
2
|
+
import type { ConfigError, InvalidInput } from "@distilled.cloud/core/errors";
|
|
3
|
+
import { makeRestProtocol, unknownErrorProps } from "@distilled.cloud/core/protocol-rest";
|
|
4
|
+
import type { SdkError } from "@distilled.cloud/core/sdk-error";
|
|
1
5
|
/**
|
|
2
|
-
* TypesenseProtocol
|
|
6
|
+
* TypesenseProtocol -- the shared bearer/header-auth REST factory from core,
|
|
3
7
|
* instantiated with Typesense's specifics:
|
|
4
8
|
*
|
|
5
9
|
* request: base URL from the caller's credentials (Typesense has no fixed
|
|
6
|
-
* default
|
|
10
|
+
* default -- self-hosted servers and per-cluster Cloud URLs), auth
|
|
7
11
|
* via the `X-TYPESENSE-API-KEY` header
|
|
8
12
|
*
|
|
9
13
|
* response: plain JSON, no envelope. Non-2xx bodies decode against
|
|
@@ -12,14 +16,11 @@
|
|
|
12
16
|
* the shared HTTP status map, then UnknownTypesenseError.
|
|
13
17
|
*/
|
|
14
18
|
import * as Effect from "effect/Effect";
|
|
19
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
20
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
15
21
|
import type * as Layer from "effect/Layer";
|
|
16
|
-
import type * as HttpClient from "effect/unstable/http/HttpClient";
|
|
17
|
-
import type * as HttpClientError from "effect/unstable/http/HttpClientError";
|
|
18
|
-
import type * as API from "@distilled.cloud/core/api";
|
|
19
|
-
import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
20
|
-
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
21
22
|
import { type Config, Credentials, formatHeaders } from "./credentials.ts";
|
|
22
|
-
import { type DefaultErrors, UnknownTypesenseError } from "./errors.ts";
|
|
23
|
+
import { type DefaultErrors, UnknownTypesenseError, TypesenseParseError } from "./errors.ts";
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Error channel shared by every generated Typesense operation. Generated
|
|
@@ -30,23 +31,21 @@ import { type DefaultErrors, UnknownTypesenseError } from "./errors.ts";
|
|
|
30
31
|
export type TypesenseOpError =
|
|
31
32
|
| DefaultErrors
|
|
32
33
|
| ConfigError
|
|
33
|
-
| HttpClientError.HttpClientError
|
|
34
|
+
| HttpClientError.HttpClientError
|
|
35
|
+
| InvalidInput
|
|
36
|
+
| SdkError;
|
|
34
37
|
|
|
35
38
|
/** Context (requirements) shared by every generated Typesense operation. */
|
|
36
39
|
export type TypesenseOpContext = Credentials | HttpClient.HttpClient;
|
|
37
40
|
|
|
38
|
-
export const TypesenseProtocol: Layer.Layer<API.Protocol> =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// factory's default envelope reader.
|
|
50
|
-
unknownError: ({ message, body }) =>
|
|
51
|
-
new UnknownTypesenseError({ message, body }),
|
|
52
|
-
});
|
|
41
|
+
export const TypesenseProtocol: Layer.Layer<API.Protocol> = /*@__PURE__*/ makeRestProtocol<Config>({
|
|
42
|
+
// Resolved on the calling fiber, per request -- the Credentials service
|
|
43
|
+
// holds an effect, so lazily-resolved keys Just Work.
|
|
44
|
+
credentials: /*@__PURE__*/ Effect.flatMap(Credentials, (resolve) => resolve),
|
|
45
|
+
baseUrl: (creds) => creds.apiBaseUrl,
|
|
46
|
+
headers: formatHeaders,
|
|
47
|
+
// Typesense's ApiResponse error body is `{ message }` -- covered by the
|
|
48
|
+
// factory's default envelope reader.
|
|
49
|
+
unknownError: (info) => new UnknownTypesenseError(unknownErrorProps(info)),
|
|
50
|
+
parseError: ({ body, cause }) => new TypesenseParseError({ body, cause }),
|
|
51
|
+
});
|
package/src/retry.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Policy, throttlingFactory, transientFactory } from "@distilled.cloud/core/retry";
|
|
1
2
|
/**
|
|
2
3
|
* Typesense retry configuration.
|
|
3
4
|
*
|
|
@@ -17,11 +18,6 @@
|
|
|
17
18
|
import * as Context from "effect/Context";
|
|
18
19
|
import * as Effect from "effect/Effect";
|
|
19
20
|
import * as Layer from "effect/Layer";
|
|
20
|
-
import {
|
|
21
|
-
type Policy,
|
|
22
|
-
throttlingFactory,
|
|
23
|
-
transientFactory,
|
|
24
|
-
} from "@distilled.cloud/core/retry";
|
|
25
21
|
|
|
26
22
|
export {
|
|
27
23
|
type Options,
|
|
@@ -37,19 +33,19 @@ export {
|
|
|
37
33
|
} from "@distilled.cloud/core/retry";
|
|
38
34
|
|
|
39
35
|
/** Context tag for configuring retry behavior of Typesense API calls. */
|
|
40
|
-
export class Retry extends Context.Service<Retry, Policy>()("TypesenseRetry") {}
|
|
36
|
+
export class Retry extends /*@__PURE__*/ Context.Service<Retry, Policy>()("TypesenseRetry") {}
|
|
41
37
|
|
|
42
38
|
/** Provides a custom retry policy to every Typesense API call below it. */
|
|
43
39
|
export const policy = (optionsOrFactory: Policy) =>
|
|
44
40
|
Effect.provide(Layer.succeed(Retry, optionsOrFactory));
|
|
45
41
|
|
|
46
42
|
/** Disables all automatic retries. */
|
|
47
|
-
export const none = Effect.provide(
|
|
48
|
-
Layer.succeed(Retry, { while: () => false }),
|
|
43
|
+
export const none = /*@__PURE__*/ Effect.provide(
|
|
44
|
+
/*@__PURE__*/ Layer.succeed(Retry, { while: () => false }),
|
|
49
45
|
);
|
|
50
46
|
|
|
51
47
|
/** Apply the throttling retry policy (retries throttling errors indefinitely). */
|
|
52
|
-
export const throttling = policy(throttlingFactory);
|
|
48
|
+
export const throttling = /*@__PURE__*/ policy(throttlingFactory);
|
|
53
49
|
|
|
54
50
|
/** Apply the transient retry policy (retries all transient errors indefinitely). */
|
|
55
|
-
export const transient = policy(transientFactory);
|
|
51
|
+
export const transient = /*@__PURE__*/ policy(transientFactory);
|