@distilled.cloud/typesense 1.0.0-rc.2 → 1.0.0-rc.21

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.
Files changed (49) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +33 -0
  3. package/lib/.lazy.json +1 -0
  4. package/lib/_bundle/lazy.js +4 -0
  5. package/lib/_bundle/sdk.js +2 -0
  6. package/lib/_bundle/sdk.js.map +1 -0
  7. package/lib/credentials.d.ts +18 -5
  8. package/lib/credentials.d.ts.map +1 -1
  9. package/lib/credentials.js +1 -42
  10. package/lib/errors.d.ts +20 -16
  11. package/lib/errors.d.ts.map +1 -1
  12. package/lib/errors.js +1 -24
  13. package/lib/index.d.ts +5 -5
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.js +1 -9
  16. package/lib/index.lazy.js +6 -0
  17. package/lib/index.lazy.js.map +1 -0
  18. package/lib/protocol.d.ts +10 -12
  19. package/lib/protocol.d.ts.map +1 -1
  20. package/lib/protocol.js +1 -31
  21. package/lib/retry.d.ts +2 -2
  22. package/lib/retry.d.ts.map +1 -1
  23. package/lib/retry.js +1 -33
  24. package/lib/services/index.d.ts.map +1 -1
  25. package/lib/services/index.js +0 -2
  26. package/lib/services/typesense.d.ts +1319 -1574
  27. package/lib/services/typesense.d.ts.map +1 -1
  28. package/lib/services/typesense.js +112 -2916
  29. package/lib/services/typesense.js.map +1 -1
  30. package/lib/services.lazy/index.js +3 -0
  31. package/lib/services.lazy/typesense.js +4 -0
  32. package/lib/traits.d.ts +1 -1
  33. package/lib/traits.d.ts.map +1 -1
  34. package/lib/traits.js +1 -11
  35. package/package.json +40 -17
  36. package/src/credentials.ts +32 -27
  37. package/src/errors.ts +19 -16
  38. package/src/index.ts +5 -9
  39. package/src/protocol.ts +28 -33
  40. package/src/retry.ts +6 -10
  41. package/src/services/typesense.ts +4377 -5048
  42. package/src/traits.ts +1 -1
  43. package/lib/credentials.js.map +0 -1
  44. package/lib/errors.js.map +0 -1
  45. package/lib/index.js.map +0 -1
  46. package/lib/protocol.js.map +0 -1
  47. package/lib/retry.js.map +0 -1
  48. package/lib/services/index.js.map +0 -1
  49. package/lib/traits.js.map +0 -1
package/src/errors.ts CHANGED
@@ -23,29 +23,24 @@ export {
23
23
  DEFAULT_ERRORS,
24
24
  API_ERRORS,
25
25
  } from "@distilled.cloud/core/errors";
26
- import type { DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
27
-
28
- import * as Schema from "effect/Schema";
29
26
  import * as Category from "@distilled.cloud/core/category";
27
+ import type { DefaultErrors as CoreDefaultErrors } from "@distilled.cloud/core/errors";
28
+ import { API_ERRORS, UnknownErrorFields } from "@distilled.cloud/core/errors";
29
+ import * as Schema from "@distilled.cloud/core/schema-lite-typed";
30
30
 
31
31
  // Unknown Typesense error - returned when an error code is not recognized
32
- export class UnknownTypesenseError extends Schema.TaggedErrorClass<UnknownTypesenseError>()(
33
- "UnknownTypesenseError",
34
- {
35
- code: Schema.optional(Schema.String),
36
- message: Schema.optional(Schema.String),
37
- body: Schema.Unknown,
38
- },
39
- ).pipe(Category.withServerError) {}
32
+ export class UnknownTypesenseError
33
+ extends /*@__PURE__*/ Schema.TaggedError<UnknownTypesenseError>()(
34
+ "UnknownTypesenseError",
35
+ UnknownErrorFields,
36
+ ) {}
40
37
 
41
38
  // Schema parse error wrapper
42
- export class TypesenseParseError extends Schema.TaggedErrorClass<TypesenseParseError>()(
43
- "TypesenseParseError",
44
- {
39
+ export class TypesenseParseError
40
+ extends /*@__PURE__*/ Schema.TaggedError<TypesenseParseError>()("TypesenseParseError", {
45
41
  body: Schema.Unknown,
46
42
  cause: Schema.Unknown,
47
- },
48
- ).pipe(Category.withParseError) {}
43
+ }).pipe(Category.withParseError) {}
49
44
 
50
45
  /**
51
46
  * Errors that any Typesense operation may surface in addition to
@@ -58,3 +53,11 @@ export type ClientErrors = TypesenseParseError | UnknownTypesenseError;
58
53
  * core plus the client-level fallback/decode errors.
59
54
  */
60
55
  export type DefaultErrors = CoreDefaultErrors | ClientErrors;
56
+
57
+ /**
58
+ * The errors declared on the Typesense service: any operation can return them,
59
+ * and every generated operation lists them as its `serviceErrors`. Today that
60
+ * is each of core's status classes (401, 403, 404, 429, the 5xx ...).
61
+ */
62
+ export const TypesenseServiceErrors = API_ERRORS;
63
+ export type TypesenseServiceError = InstanceType<(typeof TypesenseServiceErrors)[number]>;
package/src/index.ts CHANGED
@@ -1,17 +1,13 @@
1
1
  /**
2
- * @distilled.cloud/typesense — Typesense SDK for Effect.
2
+ * @distilled.cloud/typesense -- Typesense SDK for Effect.
3
3
  *
4
- * `./services` is generated by `scripts/generate.ts` from the Smithy model
5
- * in `.generated-specs` (converted from the Typesense OpenAPI spec by
6
- * `scripts/convert.ts`). Everything else in this folder is hand-written.
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,11 @@
1
+ import type { ErrorOf } from "@distilled.cloud/core/protocol";
2
+ import { restProtocol, unknownErrorProps } from "@distilled.cloud/core/protocol-rest";
1
3
  /**
2
- * TypesenseProtocol — the shared bearer/header-auth REST factory from core,
4
+ * TypesenseProtocol -- the shared bearer/header-auth REST factory from core,
3
5
  * instantiated with Typesense's specifics:
4
6
  *
5
7
  * request: base URL from the caller's credentials (Typesense has no fixed
6
- * default — self-hosted servers and per-cluster Cloud URLs), auth
8
+ * default -- self-hosted servers and per-cluster Cloud URLs), auth
7
9
  * via the `X-TYPESENSE-API-KEY` header
8
10
  *
9
11
  * response: plain JSON, no envelope. Non-2xx bodies decode against
@@ -12,41 +14,34 @@
12
14
  * the shared HTTP status map, then UnknownTypesenseError.
13
15
  */
14
16
  import * as Effect from "effect/Effect";
15
- 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
- import { type Config, Credentials, formatHeaders } from "./credentials.ts";
22
- import { type DefaultErrors, UnknownTypesenseError } from "./errors.ts";
17
+ import type * as HttpClient from "effect/http/HttpClient";
18
+ import { Credentials, formatHeaders } from "./credentials.ts";
19
+ import {
20
+ UnknownTypesenseError,
21
+ TypesenseParseError,
22
+ type TypesenseServiceError,
23
+ } from "./errors.ts";
23
24
 
24
25
  /**
25
- * Error channel shared by every generated Typesense operation. Generated
26
- * service files annotate operations with `API.OperationMethod<I, O,
27
- * TypesenseOpError, TypesenseOpContext>` explicitly so the compiler never
28
- * infers these back out of the schema generics.
26
+ * What every generated Typesense operation fails with besides its own errors:
27
+ * the service's errors, the protocol's, and what resolving the credentials
28
+ * fails with. Generated service files annotate operations with
29
+ * `API.OperationMethod<I, O, TypesenseOpError, TypesenseOpContext>` explicitly
30
+ * so the compiler never infers these back out of the schema generics.
29
31
  */
30
- export type TypesenseOpError =
31
- | DefaultErrors
32
- | ConfigError
33
- | HttpClientError.HttpClientError;
32
+ export type TypesenseOpError = TypesenseServiceError | ErrorOf<typeof TypesenseProtocol>;
34
33
 
35
34
  /** Context (requirements) shared by every generated Typesense operation. */
36
35
  export type TypesenseOpContext = Credentials | HttpClient.HttpClient;
37
36
 
38
- export const TypesenseProtocol: Layer.Layer<API.Protocol> =
39
- makeRestProtocol<Config>({
40
- // Resolved on the calling fiber, per request — the Credentials service
41
- // holds an effect, so lazily-resolved keys Just Work.
42
- credentials: Effect.gen(function* () {
43
- const resolve = yield* Credentials;
44
- return yield* resolve;
45
- }),
46
- baseUrl: (creds) => creds.apiBaseUrl,
47
- headers: formatHeaders,
48
- // Typesense's ApiResponse error body is `{ message }` — covered by the
49
- // factory's default envelope reader.
50
- unknownError: ({ message, body }) =>
51
- new UnknownTypesenseError({ message, body }),
52
- });
37
+ export const TypesenseProtocol = /*@__PURE__*/ restProtocol({
38
+ // Resolved on the calling fiber, per request -- the Credentials service
39
+ // holds an effect, so lazily-resolved keys Just Work.
40
+ credentials: /*@__PURE__*/ Effect.flatten(Credentials),
41
+ baseUrl: (creds) => creds.apiBaseUrl,
42
+ headers: formatHeaders,
43
+ // Typesense's ApiResponse error body is `{ message }` -- covered by the
44
+ // factory's default envelope reader.
45
+ unknownError: (info) => new UnknownTypesenseError(unknownErrorProps(info)),
46
+ parseError: ({ body, cause }) => new TypesenseParseError({ body, cause }),
47
+ });
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);