@distilled.cloud/typesense 1.0.0-rc.12 → 1.0.0-rc.13
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 +34 -0
- package/lib/protocol.d.ts +2 -2
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +2 -1
- package/lib/protocol.js.map +1 -1
- package/lib/response-validation.test.d.ts +6 -0
- package/lib/response-validation.test.d.ts.map +1 -0
- package/lib/response-validation.test.js +33 -0
- package/lib/response-validation.test.js.map +1 -0
- package/package.json +4 -4
- package/src/protocol.ts +8 -3
- package/src/response-validation.test.ts +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @distilled.cloud/typesense
|
|
2
|
+
|
|
3
|
+
Effect-native SDK for [typesense](https://www.npmjs.com/package/@distilled.cloud/typesense).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @distilled.cloud/typesense effect
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Effect, Layer } from "effect";
|
|
15
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
16
|
+
import * as Typesense from "@distilled.cloud/typesense";
|
|
17
|
+
|
|
18
|
+
const program = Effect.gen(function* () {
|
|
19
|
+
const result = yield* Typesense.listDocument({});
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const Live = Layer.mergeAll(
|
|
24
|
+
FetchHttpClient.layer,
|
|
25
|
+
Typesense.CredentialsFromEnv,
|
|
26
|
+
Typesense.TypesenseProtocol,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Auth
|
|
33
|
+
|
|
34
|
+
Required: `TYPESENSE_API_KEY`. Optional: `TYPESENSE_API_URL`.
|
package/lib/protocol.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as Layer from "effect/Layer";
|
|
2
|
-
import type * as HttpClient from "effect/
|
|
3
|
-
import type * as HttpClientError from "effect/
|
|
2
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
4
4
|
import type * as API from "@distilled.cloud/core/api";
|
|
5
5
|
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
6
6
|
import { Credentials } from "./credentials.ts";
|
package/lib/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,KAAK,GAAG,MAAM,2BAA2B,CAAC;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAe,WAAW,EAAiB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,WAAW,GACX,eAAe,CAAC,eAAe,CAAC;AAEpC,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAErE,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAepD,CAAC"}
|
package/lib/protocol.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import * as Effect from "effect/Effect";
|
|
15
15
|
import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
16
16
|
import { Credentials, formatHeaders } from "./credentials.js";
|
|
17
|
-
import { UnknownTypesenseError } from "./errors.js";
|
|
17
|
+
import { UnknownTypesenseError, TypesenseParseError, } from "./errors.js";
|
|
18
18
|
export const TypesenseProtocol = makeRestProtocol({
|
|
19
19
|
// Resolved on the calling fiber, per request — the Credentials service
|
|
20
20
|
// holds an effect, so lazily-resolved keys Just Work.
|
|
@@ -27,5 +27,6 @@ export const TypesenseProtocol = makeRestProtocol({
|
|
|
27
27
|
// Typesense's ApiResponse error body is `{ message }` — covered by the
|
|
28
28
|
// factory's default envelope reader.
|
|
29
29
|
unknownError: ({ message, body }) => new UnknownTypesenseError({ message, body }),
|
|
30
|
+
parseError: ({ body, cause }) => new TypesenseParseError({ body, cause }),
|
|
30
31
|
});
|
|
31
32
|
//# sourceMappingURL=protocol.js.map
|
package/lib/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAKxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAe,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAKxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAe,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAEL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAgBrB,MAAM,CAAC,MAAM,iBAAiB,GAC5B,gBAAgB,CAAS;IACvB,uEAAuE;IACvE,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;QACnC,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC;IACxB,CAAC,CAAC;IACF,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU;IACpC,OAAO,EAAE,aAAa;IACtB,uEAAuE;IACvE,qCAAqC;IACrC,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAClC,IAAI,qBAAqB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC9C,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;CAC1E,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TypesenseParseError } from "./errors.ts";
|
|
2
|
+
import type { TypesenseOpError } from "./protocol.ts";
|
|
3
|
+
export declare const parseErrorIsDeclared: [TypesenseParseError] extends [
|
|
4
|
+
TypesenseOpError
|
|
5
|
+
] ? true : false;
|
|
6
|
+
//# sourceMappingURL=response-validation.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.d.ts","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAuCtD,eAAO,MAAM,oBAAoB,EAAE,CAAC,mBAAmB,CAAC,SAAS;IAC/D,gBAAgB;CACjB,GACG,IAAI,GACJ,KAAY,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { runValidationModes } from "@distilled.cloud/core/testing";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { credentials } from "./credentials.js";
|
|
5
|
+
import { TypesenseParseError } from "./errors.js";
|
|
6
|
+
import * as Retry from "./retry.js";
|
|
7
|
+
import { getAliases } from "./services/typesense.js";
|
|
8
|
+
// getAliases declares `{ aliases: CollectionAlias[] }`.
|
|
9
|
+
const run = (body) => runValidationModes(getAliases({}).pipe(Retry.none, Effect.provide(credentials({ apiKey: "test", apiBaseUrl: "http://localhost:8108" }))), { body });
|
|
10
|
+
describe("Typesense response validation", () => {
|
|
11
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
12
|
+
const body = { aliases: [] };
|
|
13
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
14
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
15
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
16
|
+
});
|
|
17
|
+
test("a body missing required members: lenient returns it, strict fails", async () => {
|
|
18
|
+
const body = {};
|
|
19
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
20
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
21
|
+
expect(strict._tag).toBe("Failure");
|
|
22
|
+
expect(strict.failure).toBeInstanceOf(TypesenseParseError);
|
|
23
|
+
});
|
|
24
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
25
|
+
const { lenient, strict } = await run("not json");
|
|
26
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
27
|
+
expect(strict._tag).toBe("Failure");
|
|
28
|
+
expect(strict.failure).toBeInstanceOf(TypesenseParseError);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
// TypesenseParseError is part of every operation's declared error type.
|
|
32
|
+
export const parseErrorIsDeclared = true;
|
|
33
|
+
//# sourceMappingURL=response-validation.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.js","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,wDAAwD;AACxD,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAC3B,kBAAkB,CAChB,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CACjB,KAAK,CAAC,IAAI,EACV,MAAM,CAAC,OAAO,CACZ,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE,CAAC,CACrE,CACF,EACD,EAAE,IAAI,EAAE,CACT,CAAC;AAEJ,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAC7B,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS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 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/typesense",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/alchemy-run/distilled",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@distilled.cloud/core": "1.0.0-rc.
|
|
67
|
+
"@distilled.cloud/core": "1.0.0-rc.13"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/bun": "1.3.14",
|
|
71
71
|
"@types/node": "26.2.0",
|
|
72
|
-
"@effect/platform-bun": "
|
|
72
|
+
"@effect/platform-bun": "^4.0.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"effect": "
|
|
75
|
+
"effect": "^4.0.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsc -b",
|
package/src/protocol.ts
CHANGED
|
@@ -13,13 +13,17 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import * as Effect from "effect/Effect";
|
|
15
15
|
import type * as Layer from "effect/Layer";
|
|
16
|
-
import type * as HttpClient from "effect/
|
|
17
|
-
import type * as HttpClientError from "effect/
|
|
16
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
17
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
18
18
|
import type * as API from "@distilled.cloud/core/api";
|
|
19
19
|
import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
20
20
|
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
21
21
|
import { type Config, Credentials, formatHeaders } from "./credentials.ts";
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
type DefaultErrors,
|
|
24
|
+
UnknownTypesenseError,
|
|
25
|
+
TypesenseParseError,
|
|
26
|
+
} from "./errors.ts";
|
|
23
27
|
|
|
24
28
|
/**
|
|
25
29
|
* Error channel shared by every generated Typesense operation. Generated
|
|
@@ -49,4 +53,5 @@ export const TypesenseProtocol: Layer.Layer<API.Protocol> =
|
|
|
49
53
|
// factory's default envelope reader.
|
|
50
54
|
unknownError: ({ message, body }) =>
|
|
51
55
|
new UnknownTypesenseError({ message, body }),
|
|
56
|
+
parseError: ({ body, cause }) => new TypesenseParseError({ body, cause }),
|
|
52
57
|
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { runValidationModes } from "@distilled.cloud/core/testing";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { credentials } from "./credentials.ts";
|
|
5
|
+
import { TypesenseParseError } from "./errors.ts";
|
|
6
|
+
import * as Retry from "./retry.ts";
|
|
7
|
+
import { getAliases } from "./services/typesense.ts";
|
|
8
|
+
import type { TypesenseOpError } from "./protocol.ts";
|
|
9
|
+
|
|
10
|
+
// getAliases declares `{ aliases: CollectionAlias[] }`.
|
|
11
|
+
const run = (body: string) =>
|
|
12
|
+
runValidationModes(
|
|
13
|
+
getAliases({}).pipe(
|
|
14
|
+
Retry.none,
|
|
15
|
+
Effect.provide(
|
|
16
|
+
credentials({ apiKey: "test", apiBaseUrl: "http://localhost:8108" }),
|
|
17
|
+
),
|
|
18
|
+
),
|
|
19
|
+
{ body },
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
describe("Typesense response validation", () => {
|
|
23
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
24
|
+
const body = { aliases: [] };
|
|
25
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
26
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
27
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("a body missing required members: lenient returns it, strict fails", async () => {
|
|
31
|
+
const body = {};
|
|
32
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
33
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
34
|
+
expect(strict._tag).toBe("Failure");
|
|
35
|
+
expect((strict as any).failure).toBeInstanceOf(TypesenseParseError);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
39
|
+
const { lenient, strict } = await run("not json");
|
|
40
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
41
|
+
expect(strict._tag).toBe("Failure");
|
|
42
|
+
expect((strict as any).failure).toBeInstanceOf(TypesenseParseError);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// TypesenseParseError is part of every operation's declared error type.
|
|
47
|
+
export const parseErrorIsDeclared: [TypesenseParseError] extends [
|
|
48
|
+
TypesenseOpError,
|
|
49
|
+
]
|
|
50
|
+
? true
|
|
51
|
+
: false = true;
|