@distilled.cloud/turso 1.0.0-rc.11 → 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 +4 -0
- package/lib/response-validation.test.d.ts.map +1 -0
- package/lib/response-validation.test.js +38 -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 +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @distilled.cloud/turso
|
|
2
|
+
|
|
3
|
+
Effect-native SDK for [turso](https://www.npmjs.com/package/@distilled.cloud/turso).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @distilled.cloud/turso 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 Turso from "@distilled.cloud/turso";
|
|
17
|
+
|
|
18
|
+
const program = Effect.gen(function* () {
|
|
19
|
+
const result = yield* Turso.listAPITokens({});
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const Live = Layer.mergeAll(
|
|
24
|
+
FetchHttpClient.layer,
|
|
25
|
+
Turso.CredentialsFromEnv,
|
|
26
|
+
Turso.TursoProtocol,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
program.pipe(Effect.provide(Live), Effect.runPromise);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Auth
|
|
33
|
+
|
|
34
|
+
Required: `TURSO_API_KEY`. Sent as `Authorization: Bearer`.
|
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":"AAiBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,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,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACpB,aAAa,GACb,WAAW,GACX,eAAe,CAAC,eAAe,CAAC;AAEpC,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAEjE,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CA2BhD,CAAC"}
|
package/lib/protocol.js
CHANGED
|
@@ -18,7 +18,7 @@ import * as Effect from "effect/Effect";
|
|
|
18
18
|
import * as Redacted from "effect/Redacted";
|
|
19
19
|
import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
20
20
|
import { Credentials } from "./credentials.js";
|
|
21
|
-
import { UnknownTursoError } from "./errors.js";
|
|
21
|
+
import { UnknownTursoError, TursoParseError, } from "./errors.js";
|
|
22
22
|
export const TursoProtocol = makeRestProtocol({
|
|
23
23
|
// The Credentials service holds an effect — resolving it here (per
|
|
24
24
|
// request) picks up rotations. Its error channel is erased at the protocol
|
|
@@ -42,5 +42,6 @@ export const TursoProtocol = makeRestProtocol({
|
|
|
42
42
|
message,
|
|
43
43
|
body,
|
|
44
44
|
}),
|
|
45
|
+
parseError: ({ body, cause }) => new TursoParseError({ body, cause }),
|
|
45
46
|
});
|
|
46
47
|
//# 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;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EACL,iBAAiB,EAEjB,eAAe,GAChB,MAAM,aAAa,CAAC;AAgBrB,MAAM,CAAC,MAAM,aAAa,GACxB,gBAAgB,CAAS;IACvB,mEAAmE;IACnE,2EAA2E;IAC3E,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,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACnB,aAAa,EAAE,UAAU,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;KACxD,CAAC;IACF,yEAAyE;IACzE,sEAAsE;IACtE,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CACxC,IAAI,iBAAiB,CAAC;QACpB,IAAI,EACF,OAAO,IAAI,KAAK,QAAQ;YACtB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,KAAK,SAAS;gBAClB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;gBACd,CAAC,CAAC,SAAS;QACjB,OAAO;QACP,IAAI;KACL,CAAC;IACJ,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;CACtE,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-validation.test.d.ts","sourceRoot":"","sources":["../src/response-validation.test.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAyClD,eAAO,MAAM,oBAAoB,EAAE,CAAC,eAAe,CAAC,SAAS,CAAC,YAAY,CAAC,GACvE,IAAI,GACJ,KAAY,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 * as Layer from "effect/Layer";
|
|
5
|
+
import * as Redacted from "effect/Redacted";
|
|
6
|
+
import { Credentials, DEFAULT_API_BASE_URL } from "./credentials.js";
|
|
7
|
+
import { TursoParseError } from "./errors.js";
|
|
8
|
+
import * as Retry from "./retry.js";
|
|
9
|
+
import { validateAPIToken } from "./services/turso.js";
|
|
10
|
+
const TestCredentials = Layer.succeed(Credentials, Effect.succeed({
|
|
11
|
+
apiKey: Redacted.make("test"),
|
|
12
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
13
|
+
}));
|
|
14
|
+
// validateAPIToken declares `{ exp?: number }` (all optional).
|
|
15
|
+
const run = (body) => runValidationModes(validateAPIToken({}).pipe(Retry.none, Effect.provide(TestCredentials)), { body });
|
|
16
|
+
describe("Turso response validation", () => {
|
|
17
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
18
|
+
const body = { exp: 1_900_000_000 };
|
|
19
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
20
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
21
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
22
|
+
});
|
|
23
|
+
test("a member with the wrong type: lenient returns it, strict fails", async () => {
|
|
24
|
+
const body = { exp: "never" };
|
|
25
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
26
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
27
|
+
expect(strict._tag).toBe("Failure");
|
|
28
|
+
expect(strict.failure).toBeInstanceOf(TursoParseError);
|
|
29
|
+
});
|
|
30
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
31
|
+
const { lenient, strict } = await run("not json");
|
|
32
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
33
|
+
expect(strict.failure).toBeInstanceOf(TursoParseError);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
// TursoParseError is part of every operation's declared error type.
|
|
37
|
+
export const parseErrorIsDeclared = true;
|
|
38
|
+
//# 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,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CACnC,WAAW,EACX,MAAM,CAAC,OAAO,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;IAC7B,UAAU,EAAE,oBAAoB;CACjC,CAAC,CACH,CAAC;AAEF,+DAA+D;AAC/D,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAC3B,kBAAkB,CAChB,gBAAgB,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EA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,GAAG,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACxE,MAAM,CAAE,MAAc,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAErB,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/turso",
|
|
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",
|
|
@@ -65,15 +65,15 @@
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@distilled.cloud/core": "1.0.0-rc.
|
|
68
|
+
"@distilled.cloud/core": "1.0.0-rc.13"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/bun": "1.3.14",
|
|
72
72
|
"@types/node": "26.2.0",
|
|
73
|
-
"@effect/platform-bun": "
|
|
73
|
+
"@effect/platform-bun": "^4.0.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"effect": "
|
|
76
|
+
"effect": "^4.0.0"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "tsc -b",
|
package/src/protocol.ts
CHANGED
|
@@ -17,13 +17,17 @@
|
|
|
17
17
|
import * as Effect from "effect/Effect";
|
|
18
18
|
import type * as Layer from "effect/Layer";
|
|
19
19
|
import * as Redacted from "effect/Redacted";
|
|
20
|
-
import type * as HttpClient from "effect/
|
|
21
|
-
import type * as HttpClientError from "effect/
|
|
20
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
21
|
+
import type * as HttpClientError from "effect/http/HttpClientError";
|
|
22
22
|
import type * as API from "@distilled.cloud/core/api";
|
|
23
23
|
import { makeRestProtocol } from "@distilled.cloud/core/protocol-rest";
|
|
24
24
|
import type { ConfigError } from "@distilled.cloud/core/errors";
|
|
25
25
|
import { Credentials, type Config } from "./credentials.ts";
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
UnknownTursoError,
|
|
28
|
+
type DefaultErrors,
|
|
29
|
+
TursoParseError,
|
|
30
|
+
} from "./errors.ts";
|
|
27
31
|
|
|
28
32
|
/**
|
|
29
33
|
* Error channel shared by every generated Turso operation. Generated service
|
|
@@ -65,4 +69,5 @@ export const TursoProtocol: Layer.Layer<API.Protocol> =
|
|
|
65
69
|
message,
|
|
66
70
|
body,
|
|
67
71
|
}),
|
|
72
|
+
parseError: ({ body, cause }) => new TursoParseError({ body, cause }),
|
|
68
73
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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 * as Layer from "effect/Layer";
|
|
5
|
+
import * as Redacted from "effect/Redacted";
|
|
6
|
+
import { Credentials, DEFAULT_API_BASE_URL } from "./credentials.ts";
|
|
7
|
+
import { TursoParseError } from "./errors.ts";
|
|
8
|
+
import * as Retry from "./retry.ts";
|
|
9
|
+
import { validateAPIToken } from "./services/turso.ts";
|
|
10
|
+
import type { TursoOpError } from "./protocol.ts";
|
|
11
|
+
|
|
12
|
+
const TestCredentials = Layer.succeed(
|
|
13
|
+
Credentials,
|
|
14
|
+
Effect.succeed({
|
|
15
|
+
apiKey: Redacted.make("test"),
|
|
16
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// validateAPIToken declares `{ exp?: number }` (all optional).
|
|
21
|
+
const run = (body: string) =>
|
|
22
|
+
runValidationModes(
|
|
23
|
+
validateAPIToken({}).pipe(Retry.none, Effect.provide(TestCredentials)),
|
|
24
|
+
{ body },
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
describe("Turso response validation", () => {
|
|
28
|
+
test("a matching body succeeds unchanged in both modes", async () => {
|
|
29
|
+
const body = { exp: 1_900_000_000 };
|
|
30
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
31
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
32
|
+
expect(strict).toMatchObject({ _tag: "Success", success: body });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("a member with the wrong type: lenient returns it, strict fails", async () => {
|
|
36
|
+
const body = { exp: "never" };
|
|
37
|
+
const { lenient, strict } = await run(JSON.stringify(body));
|
|
38
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: body });
|
|
39
|
+
expect(strict._tag).toBe("Failure");
|
|
40
|
+
expect((strict as any).failure).toBeInstanceOf(TursoParseError);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("a non-JSON body: lenient returns the text, strict fails", async () => {
|
|
44
|
+
const { lenient, strict } = await run("not json");
|
|
45
|
+
expect(lenient).toMatchObject({ _tag: "Success", success: "not json" });
|
|
46
|
+
expect((strict as any).failure).toBeInstanceOf(TursoParseError);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// TursoParseError is part of every operation's declared error type.
|
|
51
|
+
export const parseErrorIsDeclared: [TursoParseError] extends [TursoOpError]
|
|
52
|
+
? true
|
|
53
|
+
: false = true;
|