@alchemy.run/turso 0.0.0 → 2.0.0-beta.85

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 (83) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +68 -4
  3. package/lib/ApiToken.d.ts +82 -0
  4. package/lib/ApiToken.d.ts.map +1 -0
  5. package/lib/ApiToken.js +128 -0
  6. package/lib/ApiToken.js.map +1 -0
  7. package/lib/AuthProvider.d.ts +36 -0
  8. package/lib/AuthProvider.d.ts.map +1 -0
  9. package/lib/AuthProvider.js +85 -0
  10. package/lib/AuthProvider.js.map +1 -0
  11. package/lib/Connect.d.ts +79 -0
  12. package/lib/Connect.d.ts.map +1 -0
  13. package/lib/Connect.js +22 -0
  14. package/lib/Connect.js.map +1 -0
  15. package/lib/Contributions.d.ts +7 -0
  16. package/lib/Contributions.d.ts.map +1 -0
  17. package/lib/Contributions.js +6 -0
  18. package/lib/Contributions.js.map +1 -0
  19. package/lib/Credentials.d.ts +39 -0
  20. package/lib/Credentials.d.ts.map +1 -0
  21. package/lib/Credentials.js +76 -0
  22. package/lib/Credentials.js.map +1 -0
  23. package/lib/Database.d.ts +226 -0
  24. package/lib/Database.d.ts.map +1 -0
  25. package/lib/Database.js +277 -0
  26. package/lib/Database.js.map +1 -0
  27. package/lib/DatabaseToken.d.ts +104 -0
  28. package/lib/DatabaseToken.d.ts.map +1 -0
  29. package/lib/DatabaseToken.js +133 -0
  30. package/lib/DatabaseToken.js.map +1 -0
  31. package/lib/Group.d.ts +102 -0
  32. package/lib/Group.d.ts.map +1 -0
  33. package/lib/Group.js +171 -0
  34. package/lib/Group.js.map +1 -0
  35. package/lib/GroupToken.d.ts +57 -0
  36. package/lib/GroupToken.d.ts.map +1 -0
  37. package/lib/GroupToken.js +88 -0
  38. package/lib/GroupToken.js.map +1 -0
  39. package/lib/Hrana.d.ts +42 -0
  40. package/lib/Hrana.d.ts.map +1 -0
  41. package/lib/Hrana.js +109 -0
  42. package/lib/Hrana.js.map +1 -0
  43. package/lib/ManageDatabases.d.ts +73 -0
  44. package/lib/ManageDatabases.d.ts.map +1 -0
  45. package/lib/ManageDatabases.js +81 -0
  46. package/lib/ManageDatabases.js.map +1 -0
  47. package/lib/OrganizationInvite.d.ts +46 -0
  48. package/lib/OrganizationInvite.d.ts.map +1 -0
  49. package/lib/OrganizationInvite.js +72 -0
  50. package/lib/OrganizationInvite.js.map +1 -0
  51. package/lib/OrganizationMember.d.ts +47 -0
  52. package/lib/OrganizationMember.d.ts.map +1 -0
  53. package/lib/OrganizationMember.js +81 -0
  54. package/lib/OrganizationMember.js.map +1 -0
  55. package/lib/OrganizationSettings.d.ts +52 -0
  56. package/lib/OrganizationSettings.d.ts.map +1 -0
  57. package/lib/OrganizationSettings.js +93 -0
  58. package/lib/OrganizationSettings.js.map +1 -0
  59. package/lib/Providers.d.ts +24 -0
  60. package/lib/Providers.d.ts.map +1 -0
  61. package/lib/Providers.js +42 -0
  62. package/lib/Providers.js.map +1 -0
  63. package/lib/index.d.ts +14 -0
  64. package/lib/index.d.ts.map +1 -0
  65. package/lib/index.js +14 -0
  66. package/lib/index.js.map +1 -0
  67. package/package.json +54 -3
  68. package/src/ApiToken.ts +207 -0
  69. package/src/AuthProvider.ts +113 -0
  70. package/src/Connect.ts +103 -0
  71. package/src/Contributions.ts +9 -0
  72. package/src/Credentials.ts +112 -0
  73. package/src/Database.ts +519 -0
  74. package/src/DatabaseToken.ts +213 -0
  75. package/src/Group.ts +269 -0
  76. package/src/GroupToken.ts +127 -0
  77. package/src/Hrana.ts +184 -0
  78. package/src/ManageDatabases.ts +195 -0
  79. package/src/OrganizationInvite.ts +118 -0
  80. package/src/OrganizationMember.ts +122 -0
  81. package/src/OrganizationSettings.ts +145 -0
  82. package/src/Providers.ts +67 -0
  83. package/src/index.ts +20 -0
@@ -0,0 +1,79 @@
1
+ import * as Binding from "alchemy/Binding";
2
+ import type { RuntimeContext } from "alchemy/RuntimeContext";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import type * as Redacted from "effect/Redacted";
6
+ import type { Database } from "./Database.ts";
7
+ import { type TokenAuthorization } from "./DatabaseToken.ts";
8
+ /**
9
+ * libSQL connection accessors for one Turso database. Resolving them does
10
+ * not open a connection; pass the client to `SQL.LibSQL` or
11
+ * `Drizzle.LibSQL`, or read `url` / `authToken` for `@libsql/client`.
12
+ */
13
+ export interface ConnectClient {
14
+ /** libSQL URL of the database (`libsql://<hostname>`). */
15
+ url: Effect.Effect<string, never, RuntimeContext>;
16
+ /** SQL auth token for the database. */
17
+ authToken: Effect.Effect<Redacted.Redacted<string>, never, RuntimeContext>;
18
+ }
19
+ export interface ConnectOptions {
20
+ /**
21
+ * Access level of the token minted for this host.
22
+ * @default "full-access"
23
+ */
24
+ authorization?: TokenAuthorization;
25
+ }
26
+ /**
27
+ * Connect to a Turso database from a Worker, Lambda, or other host. The
28
+ * host gets the database's URL and its own {@link DatabaseToken}. Your
29
+ * Turso API token stays on your machine.
30
+ *
31
+ * ### Querying a Database
32
+ * **Example:** Effect SQL over a Turso database
33
+ * ```typescript
34
+ * Effect.gen(function* () {
35
+ * const conn = yield* Turso.Connect(Db);
36
+ * const sql = yield* SQL.LibSQL(conn);
37
+ * return {
38
+ * fetch: Effect.gen(function* () {
39
+ * return yield* HttpServerResponse.json(yield* sql`SELECT 1 AS value`);
40
+ * }),
41
+ * };
42
+ * }).pipe(Effect.provide(Turso.ConnectHttp));
43
+ * ```
44
+ *
45
+ * **Example:** Drizzle over a Turso database
46
+ * ```typescript
47
+ * const conn = yield* Turso.Connect(Db);
48
+ * const db = yield* Drizzle.LibSQL(conn, { relations });
49
+ * ```
50
+ *
51
+ * **Example:** AWS Lambda (install the native libSQL client)
52
+ * ```typescript
53
+ * export default class Api extends Lambda.Function<Api>()(
54
+ * "Api",
55
+ * { main: import.meta.url, build: { install: ["@libsql/client"] } },
56
+ * Effect.gen(function* () {
57
+ * const sql = yield* SQL.LibSQL(yield* Turso.Connect(Db));
58
+ * // ...
59
+ * }).pipe(Effect.provide(Turso.ConnectHttp)),
60
+ * ) {}
61
+ * ```
62
+ *
63
+ * **Example:** Read-only access
64
+ * ```typescript
65
+ * const conn = yield* Turso.Connect(Db, { authorization: "read-only" });
66
+ * ```
67
+ *
68
+ * @binding
69
+ * @product Database
70
+ */
71
+ export interface Connect extends Binding.Service<Connect, "Turso.Connect", (database: Database, options?: ConnectOptions) => Effect.Effect<ConnectClient>> {
72
+ }
73
+ export declare const Connect: Connect;
74
+ /**
75
+ * Host-independent implementation: the URL and a per-host token are bound
76
+ * as environment values, so it works on any Platform host.
77
+ */
78
+ export declare const ConnectHttp: Layer.Layer<Connect, never, never>;
79
+ //# sourceMappingURL=Connect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Connect.d.ts","sourceRoot":"","sources":["../src/Connect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;IAClD,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,WAAW,OAAQ,SAAQ,OAAO,CAAC,OAAO,CAC9C,OAAO,EACP,eAAe,EACf,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAC/E;CAAG;AAEJ,eAAO,MAAM,OAAO,SAA4C,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,WAAW,oCAiBvB,CAAC"}
package/lib/Connect.js ADDED
@@ -0,0 +1,22 @@
1
+ import * as Binding from "alchemy/Binding";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import { DatabaseToken } from "./DatabaseToken.js";
5
+ export const Connect = Binding.Service("Turso.Connect");
6
+ /**
7
+ * Host-independent implementation: the URL and a per-host token are bound
8
+ * as environment values, so it works on any Platform host.
9
+ */
10
+ export const ConnectHttp = Layer.effect(Connect, Effect.gen(function* () {
11
+ const Token = yield* DatabaseToken;
12
+ return Effect.fn(function* (database, options) {
13
+ const host = yield* Binding.Host;
14
+ const authorization = options?.authorization ?? "full-access";
15
+ const token = yield* Token(`${host?.LogicalId ?? ""}${database.LogicalId}${authorization === "read-only" ? "ReadOnly" : ""}Token`, { database: database.name, authorization });
16
+ return {
17
+ url: yield* database.url,
18
+ authToken: yield* token.token,
19
+ };
20
+ });
21
+ }));
22
+ //# sourceMappingURL=Connect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Connect.js","sourceRoot":"","sources":["../src/Connect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAE,aAAa,EAA2B,MAAM,oBAAoB,CAAC;AAyE5E,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAU,eAAe,CAAC,CAAC;AAEjE;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CACrC,OAAO,EACP,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,aAAa,CAAC;IACnC,OAAO,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAkB,EAAE,OAAwB;QACtE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QACjC,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,aAAa,CAAC;QAC9D,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,KAAK,CACxB,GAAG,IAAI,EAAE,SAAS,IAAI,EAAE,GAAG,QAAQ,CAAC,SAAS,GAAG,aAAa,KAAK,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EACtG,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,CAC3C,CAAC;QACF,OAAO;YACL,GAAG,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG;YACxB,SAAS,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK;SACN,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import * as Contributions from "alchemy/Contributions";
2
+ declare const _default: {
3
+ readonly name: "turso";
4
+ readonly auth: Contributions.Lazy<import("effect/Layer").Layer<never, never, import("alchemy/Auth/Registry").AuthProviders | import("effect/FileSystem").FileSystem | import("effect/Path").Path>>;
5
+ };
6
+ export default _default;
7
+ //# sourceMappingURL=Contributions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Contributions.d.ts","sourceRoot":"","sources":["../src/Contributions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,uBAAuB,CAAC;;;;;AAEvD,wBAMG"}
@@ -0,0 +1,6 @@
1
+ import * as Contributions from "alchemy/Contributions";
2
+ export default Contributions.make({
3
+ name: "turso",
4
+ auth: Contributions.lazy(() => import("./AuthProvider.js"), (module) => module.TursoAuth),
5
+ });
6
+ //# sourceMappingURL=Contributions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Contributions.js","sourceRoot":"","sources":["../src/Contributions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,uBAAuB,CAAC;AAEvD,eAAe,aAAa,CAAC,IAAI,CAAC;IAChC,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,aAAa,CAAC,IAAI,CACtB,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,EACjC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAC7B;CACF,CAAC,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { Credentials } from "@distilled.cloud/turso/Credentials";
2
+ import * as Context from "effect/Context";
3
+ import * as Effect from "effect/Effect";
4
+ import * as HttpClient from "effect/http/HttpClient";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Redacted from "effect/Redacted";
7
+ export { Credentials, CredentialsFromEnv, DEFAULT_API_BASE_URL, } from "@distilled.cloud/turso/Credentials";
8
+ declare const Organization_base: Context.ServiceClass<Organization, "Turso.Organization", Effect.Effect<string, never, never>>;
9
+ /**
10
+ * The Turso organization slug every org-scoped Platform API call targets.
11
+ * Holds an effect so the slug is resolved (and, when not configured,
12
+ * discovered from the API token) on first use, never at layer build.
13
+ */
14
+ export declare class Organization extends Organization_base {
15
+ }
16
+ /** The organization slug for the current Turso credentials. */
17
+ export declare const organization: Effect.Effect<string, never, Organization>;
18
+ /**
19
+ * Build Turso `Credentials` + `Organization` from an explicit API token.
20
+ * Useful for tests or when the caller already has a token in hand.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * Effect.provide(Turso.fromToken({ apiToken: "...", organization: "my-org" }))
25
+ * ```
26
+ */
27
+ export declare const fromToken: (input: {
28
+ apiToken: string | Redacted.Redacted<string>;
29
+ organization?: string;
30
+ apiBaseUrl?: string;
31
+ }) => Layer.Layer<Credentials | Organization, never, HttpClient.HttpClient>;
32
+ /**
33
+ * Build Turso `Credentials` + `Organization` that resolve through the
34
+ * Alchemy AuthProvider: environment credentials (`TURSO_API_TOKEN`) when
35
+ * present, otherwise the selected profile. Resolution is deferred until the
36
+ * first API call, so building the provider layers never needs a profile.
37
+ */
38
+ export declare const fromAuthProvider: () => Layer.Layer<Credentials | Organization, never, import("alchemy/Auth/Registry").AuthProviders | HttpClient.HttpClient | import("alchemy/Auth/Profile").ProfileStore>;
39
+ //# sourceMappingURL=Credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Credentials.d.ts","sourceRoot":"","sources":["../src/Credentials.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAwB,MAAM,oCAAoC,CAAC;AAGvF,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,oCAAoC,CAAC;;AAE5C;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,iBAEjC;CAAG;AAEJ,+DAA+D;AAC/D,eAAO,MAAM,YAAY,4CAEvB,CAAC;AAgDH;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,UAAW;IAC/B,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,0EAOmC,CAAC;AAErC;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,2KAM1B,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { ConfigError } from "@distilled.cloud/core/errors";
2
+ import { Credentials, DEFAULT_API_BASE_URL } from "@distilled.cloud/turso/Credentials";
3
+ import * as turso from "@distilled.cloud/turso/turso";
4
+ import { lazyCredentials, orDieCredentialsUnavailable } from "alchemy/Auth/Resolve";
5
+ import * as Context from "effect/Context";
6
+ import * as Effect from "effect/Effect";
7
+ import * as HttpClient from "effect/http/HttpClient";
8
+ import * as Layer from "effect/Layer";
9
+ import * as Redacted from "effect/Redacted";
10
+ import { TURSO_AUTH_PROVIDER_NAME } from "./AuthProvider.js";
11
+ export { Credentials, CredentialsFromEnv, DEFAULT_API_BASE_URL, } from "@distilled.cloud/turso/Credentials";
12
+ /**
13
+ * The Turso organization slug every org-scoped Platform API call targets.
14
+ * Holds an effect so the slug is resolved (and, when not configured,
15
+ * discovered from the API token) on first use, never at layer build.
16
+ */
17
+ export class Organization extends Context.Service()("Turso.Organization") {
18
+ }
19
+ /** The organization slug for the current Turso credentials. */
20
+ export const organization = Effect.gen(function* () {
21
+ return yield* yield* Organization;
22
+ });
23
+ /**
24
+ * Discover the organization an API token acts on: the token's own
25
+ * organization when it is org-scoped, else the account's only organization.
26
+ */
27
+ const discoverOrganization = Effect.gen(function* () {
28
+ const orgs = yield* turso.listOrganizations({});
29
+ if (orgs.length === 1 && orgs[0]?.slug) {
30
+ return orgs[0].slug;
31
+ }
32
+ return yield* new ConfigError({
33
+ message: orgs.length === 0
34
+ ? "Turso: this API token has no organizations."
35
+ : `Turso: this API token can access ${orgs.length} organizations (${orgs
36
+ .map((org) => org.slug)
37
+ .join(", ")}). Set TURSO_ORGANIZATION or configure the organization in your profile.`,
38
+ });
39
+ });
40
+ const make = (resolve) => Effect.gen(function* () {
41
+ const http = yield* HttpClient.HttpClient;
42
+ const credentials = Effect.map(resolve, (creds) => ({
43
+ apiKey: creds.apiToken,
44
+ apiBaseUrl: creds.apiBaseUrl,
45
+ }));
46
+ // `Organization` is typed as never failing, so a credentials failure dies
47
+ // here; the engine still reports it as `CredentialsRequired`.
48
+ const organization = yield* resolve.pipe(Effect.orDie, Effect.flatMap((creds) => creds.organization !== undefined && creds.organization.length > 0
49
+ ? Effect.succeed(creds.organization)
50
+ : discoverOrganization.pipe(Effect.provideService(Credentials, credentials), Effect.provideService(HttpClient.HttpClient, http), orDieCredentialsUnavailable(TURSO_AUTH_PROVIDER_NAME))), Effect.cached);
51
+ return Context.make(Credentials, credentials).pipe(Context.add(Organization, organization));
52
+ });
53
+ /**
54
+ * Build Turso `Credentials` + `Organization` from an explicit API token.
55
+ * Useful for tests or when the caller already has a token in hand.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * Effect.provide(Turso.fromToken({ apiToken: "...", organization: "my-org" }))
60
+ * ```
61
+ */
62
+ export const fromToken = (input) => Effect.succeed({
63
+ type: "apiToken",
64
+ apiToken: typeof input.apiToken === "string" ? Redacted.make(input.apiToken) : input.apiToken,
65
+ apiBaseUrl: input.apiBaseUrl ?? DEFAULT_API_BASE_URL,
66
+ organization: input.organization,
67
+ source: { type: "stored" },
68
+ }).pipe(make, Layer.effectContext);
69
+ /**
70
+ * Build Turso `Credentials` + `Organization` that resolve through the
71
+ * Alchemy AuthProvider: environment credentials (`TURSO_API_TOKEN`) when
72
+ * present, otherwise the selected profile. Resolution is deferred until the
73
+ * first API call, so building the provider layers never needs a profile.
74
+ */
75
+ export const fromAuthProvider = () => Layer.effectContext(lazyCredentials()(TURSO_AUTH_PROVIDER_NAME, (creds) => creds).pipe(Effect.flatMap(make)));
76
+ //# sourceMappingURL=Credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Credentials.js","sourceRoot":"","sources":["../src/Credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BA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,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;AAC9F,CAAC,CAAC,CAAC;AAEL;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAIzB,EAAE,EAAE,CACH,MAAM,CAAC,OAAO,CAA2B;IACvC,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ;IAC7F,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,oBAAoB;IACpD,YAAY,EAAE,KAAK,CAAC,YAAY;IAChC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;CAC3B,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CACnC,KAAK,CAAC,aAAa,CACjB,eAAe,EAAyC,CACtD,wBAAwB,EACxB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CACjB,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAC7B,CAAC"}
@@ -0,0 +1,226 @@
1
+ import { type MigrationsInput } from "@alchemy.run/sql/Migrations";
2
+ import * as turso from "@distilled.cloud/turso/turso";
3
+ import * as Provider from "alchemy/Provider";
4
+ import { Resource } from "alchemy/Resource";
5
+ import * as Redacted from "effect/Redacted";
6
+ import type { Providers } from "./Providers.ts";
7
+ declare const DatabaseUnexpectedResponse_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
8
+ readonly _tag: "DatabaseUnexpectedResponse";
9
+ } & Readonly<A>;
10
+ export declare class DatabaseUnexpectedResponse extends DatabaseUnexpectedResponse_base<{
11
+ readonly message: string;
12
+ readonly cause?: unknown;
13
+ }> {
14
+ }
15
+ export interface DatabaseSeed {
16
+ /**
17
+ * `"database"` copies an existing database (optionally at a point in
18
+ * time). `"database_upload"` creates an empty database awaiting an upload
19
+ * of a SQLite file.
20
+ */
21
+ type: "database" | "database_upload";
22
+ /** Name of the source database when `type` is `"database"`. */
23
+ name?: string;
24
+ /**
25
+ * ISO 8601 recovery point within the source database's retention window
26
+ * (24 hours, or 30 days on the Scaler plan).
27
+ */
28
+ timestamp?: string;
29
+ }
30
+ export interface DatabaseEncryption {
31
+ /**
32
+ * Base64-encoded encryption key: 32 bytes for `aes256gcm`,
33
+ * `chacha20poly1305`, and the `aegis256` variants; 16 bytes for
34
+ * `aes128gcm` and the `aegis128l` variants.
35
+ */
36
+ key: Redacted.Redacted<string>;
37
+ /** Encryption cipher. */
38
+ cipher: "aes256gcm" | "aes128gcm" | "chacha20poly1305" | "aegis128l" | "aegis128x2" | "aegis128x4" | "aegis256" | "aegis256x2" | "aegis256x4" | (string & {});
39
+ }
40
+ export interface DatabaseProps {
41
+ /**
42
+ * Database name, unique within the organization. Lowercase letters,
43
+ * numbers, and dashes, at most 64 characters. If omitted, a unique name
44
+ * is generated from the stack, stage, and logical ID. Changing it
45
+ * replaces the database.
46
+ */
47
+ name?: string;
48
+ /**
49
+ * Name of the group the database is created in (e.g. `group.name`).
50
+ * Changing it replaces the database.
51
+ */
52
+ group: string;
53
+ /**
54
+ * Seed the new database from an existing database or a pending upload.
55
+ * Only used when the database is created.
56
+ */
57
+ seed?: DatabaseSeed;
58
+ /**
59
+ * Encrypt the database at rest with your own key. Only used when the
60
+ * database is created; changing it replaces the database. Requires a Pro
61
+ * or Enterprise plan.
62
+ */
63
+ encryption?: DatabaseEncryption;
64
+ /**
65
+ * Maximum size of the database, in bytes or with a unit (e.g. `"256mb"`,
66
+ * `"1gb"`). When omitted, the current limit is left unchanged. Only
67
+ * legacy databases support it — Turso rejects it for databases created on
68
+ * the current platform ("size_limit is not supported for db-api
69
+ * controlled databases").
70
+ */
71
+ sizeLimit?: string;
72
+ /**
73
+ * Allow other databases to be attached to this one with `ATTACH`. Not
74
+ * supported on AWS-hosted databases, which reject the setting.
75
+ * @default false
76
+ */
77
+ allowAttach?: boolean;
78
+ /**
79
+ * Reject every read query.
80
+ * @default false
81
+ */
82
+ blockReads?: boolean;
83
+ /**
84
+ * Reject every write query.
85
+ * @default false
86
+ */
87
+ blockWrites?: boolean;
88
+ /**
89
+ * Prevent the database from being deleted. While enabled, destroying or
90
+ * replacing the database fails; set it to `false` and deploy first.
91
+ * @default false
92
+ */
93
+ deleteProtection?: boolean;
94
+ /**
95
+ * IP addresses and CIDR blocks allowed to connect. Empty or omitted means
96
+ * no IP restriction. Requires a paid plan.
97
+ */
98
+ allowedIps?: string[];
99
+ /**
100
+ * AWS VPC endpoint IDs (`vpce-...`) allowed to connect. Empty or omitted
101
+ * means no VPC endpoint restriction. Requires a paid plan.
102
+ */
103
+ allowedAwsVpcIds?: string[];
104
+ /**
105
+ * SQL migrations to apply on deploy. Accepts a directory path, a
106
+ * `Drizzle.Schema` resource, or `{ dir, table? }`.
107
+ *
108
+ * Bookkeeping lives in Alchemy's `__alchemy_migrations` table. A database
109
+ * previously migrated by drizzle-kit is adopted by a one-way conversion on
110
+ * first deploy.
111
+ */
112
+ migrations?: MigrationsInput;
113
+ /**
114
+ * Paths to additional `.sql` files to apply after migrations. Each file is
115
+ * hashed; only files whose contents change are re-applied.
116
+ */
117
+ importFiles?: string[];
118
+ }
119
+ export interface DatabaseAttributes {
120
+ /** Database UUID. */
121
+ dbId: string;
122
+ /** Database name. */
123
+ name: string;
124
+ /** The organization slug that owns the database. */
125
+ organization: string;
126
+ /** Name of the group the database belongs to. */
127
+ group: string;
128
+ /** DNS hostname for libSQL and HTTP connections. */
129
+ hostname: string;
130
+ /** libSQL connection URL (`libsql://<hostname>`), for `@libsql/client`. */
131
+ url: string;
132
+ /** HTTPS URL (`https://<hostname>`) of the Hrana-over-HTTP endpoint. */
133
+ httpUrl: string;
134
+ /** Primary location of the database. */
135
+ primaryRegion: string;
136
+ /** Every location the database runs in. */
137
+ regions: string[];
138
+ /** Maximum database size, or `undefined` when unlimited. */
139
+ sizeLimit: string | undefined;
140
+ /** Whether other databases may be attached. */
141
+ allowAttach: boolean;
142
+ /** Whether reads are blocked. */
143
+ blockReads: boolean;
144
+ /** Whether writes are blocked. */
145
+ blockWrites: boolean;
146
+ /** Whether delete protection is enabled. */
147
+ deleteProtection: boolean;
148
+ /** IP addresses and CIDR blocks allowed to connect. */
149
+ allowedIps: string[];
150
+ /** AWS VPC endpoint IDs allowed to connect. */
151
+ allowedAwsVpcIds: string[];
152
+ /** Directory containing migration files, if configured. */
153
+ migrationsDir: string | undefined;
154
+ /** Table used to track applied migrations, if configured. */
155
+ migrationsTable: string | undefined;
156
+ /** Content hashes for the last applied migration files. */
157
+ migrationsHashes: Record<string, string>;
158
+ /** Content hashes for the last applied import files. */
159
+ importHashes: Record<string, string>;
160
+ }
161
+ export type Database = Resource<"Turso.Database", DatabaseProps, DatabaseAttributes, never, Providers>;
162
+ /**
163
+ * A Turso database: a SQLite database that lives in a {@link Group}.
164
+ * Connect to it from a Worker or Lambda with {@link Connect}, or create a
165
+ * {@link DatabaseToken} for other apps.
166
+ * @see https://docs.turso.tech/concepts#databases
167
+ *
168
+ * ### Creating a Database
169
+ * **Example:** Database in a group
170
+ * ```typescript
171
+ * const group = yield* Turso.Group("Group", { location: "aws-us-east-1" });
172
+ * const db = yield* Turso.Database("Db", { group: group.name });
173
+ * ```
174
+ *
175
+ * **Example:** Database with delete protection and an IP allowlist
176
+ * ```typescript
177
+ * const db = yield* Turso.Database("Db", {
178
+ * group: group.name,
179
+ * deleteProtection: true,
180
+ * allowedIps: ["203.0.113.0/24"],
181
+ * });
182
+ * ```
183
+ *
184
+ * ### Branching
185
+ * **Example:** Copy an existing database
186
+ * ```typescript
187
+ * const preview = yield* Turso.Database("Preview", {
188
+ * group: group.name,
189
+ * seed: { type: "database", name: db.name },
190
+ * });
191
+ * ```
192
+ *
193
+ * ### Migrations
194
+ * Point `migrations` at a folder of `.sql` files (or a `Drizzle.Schema`).
195
+ * Pending migrations are applied in order on each deploy.
196
+ *
197
+ * **Example:** Apply migrations from a directory
198
+ * ```typescript
199
+ * const db = yield* Turso.Database("Db", {
200
+ * group: group.name,
201
+ * migrations: "./migrations",
202
+ * });
203
+ * ```
204
+ *
205
+ * **Example:** Seed with SQL files
206
+ * ```typescript
207
+ * const db = yield* Turso.Database("Db", {
208
+ * group: group.name,
209
+ * importFiles: ["./seed/users.sql"],
210
+ * });
211
+ * ```
212
+ *
213
+ * ### Querying from a Worker
214
+ * **Example:** Drizzle over a Turso database
215
+ * ```typescript
216
+ * const conn = yield* Turso.Connect(Db);
217
+ * const db = yield* Drizzle.LibSQL(conn);
218
+ * ```
219
+ *
220
+ * @resource
221
+ * @product Database
222
+ */
223
+ export declare const Database: import("alchemy/Resource").ResourceClass<Database>;
224
+ export declare const DatabaseProvider: () => import("effect/Layer").Layer<Provider.Provider<Database>, never, import("effect/FileSystem").FileSystem | import("./Credentials.ts").Organization | import("effect/Path").Path | import("alchemy/Stack").Stack | import("alchemy/Stage").Stage | turso.TursoOpContext>;
225
+ export {};
226
+ //# sourceMappingURL=Database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../src/Database.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,eAAe,EACrB,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,KAAK,MAAM,8BAA8B,CAAC;AAItD,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAA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