@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.
- package/LICENSE +201 -0
- package/README.md +68 -4
- package/lib/ApiToken.d.ts +82 -0
- package/lib/ApiToken.d.ts.map +1 -0
- package/lib/ApiToken.js +128 -0
- package/lib/ApiToken.js.map +1 -0
- package/lib/AuthProvider.d.ts +36 -0
- package/lib/AuthProvider.d.ts.map +1 -0
- package/lib/AuthProvider.js +85 -0
- package/lib/AuthProvider.js.map +1 -0
- package/lib/Connect.d.ts +79 -0
- package/lib/Connect.d.ts.map +1 -0
- package/lib/Connect.js +22 -0
- package/lib/Connect.js.map +1 -0
- package/lib/Contributions.d.ts +7 -0
- package/lib/Contributions.d.ts.map +1 -0
- package/lib/Contributions.js +6 -0
- package/lib/Contributions.js.map +1 -0
- package/lib/Credentials.d.ts +39 -0
- package/lib/Credentials.d.ts.map +1 -0
- package/lib/Credentials.js +76 -0
- package/lib/Credentials.js.map +1 -0
- package/lib/Database.d.ts +226 -0
- package/lib/Database.d.ts.map +1 -0
- package/lib/Database.js +277 -0
- package/lib/Database.js.map +1 -0
- package/lib/DatabaseToken.d.ts +104 -0
- package/lib/DatabaseToken.d.ts.map +1 -0
- package/lib/DatabaseToken.js +133 -0
- package/lib/DatabaseToken.js.map +1 -0
- package/lib/Group.d.ts +102 -0
- package/lib/Group.d.ts.map +1 -0
- package/lib/Group.js +171 -0
- package/lib/Group.js.map +1 -0
- package/lib/GroupToken.d.ts +57 -0
- package/lib/GroupToken.d.ts.map +1 -0
- package/lib/GroupToken.js +88 -0
- package/lib/GroupToken.js.map +1 -0
- package/lib/Hrana.d.ts +42 -0
- package/lib/Hrana.d.ts.map +1 -0
- package/lib/Hrana.js +109 -0
- package/lib/Hrana.js.map +1 -0
- package/lib/ManageDatabases.d.ts +73 -0
- package/lib/ManageDatabases.d.ts.map +1 -0
- package/lib/ManageDatabases.js +81 -0
- package/lib/ManageDatabases.js.map +1 -0
- package/lib/OrganizationInvite.d.ts +46 -0
- package/lib/OrganizationInvite.d.ts.map +1 -0
- package/lib/OrganizationInvite.js +72 -0
- package/lib/OrganizationInvite.js.map +1 -0
- package/lib/OrganizationMember.d.ts +47 -0
- package/lib/OrganizationMember.d.ts.map +1 -0
- package/lib/OrganizationMember.js +81 -0
- package/lib/OrganizationMember.js.map +1 -0
- package/lib/OrganizationSettings.d.ts +52 -0
- package/lib/OrganizationSettings.d.ts.map +1 -0
- package/lib/OrganizationSettings.js +93 -0
- package/lib/OrganizationSettings.js.map +1 -0
- package/lib/Providers.d.ts +24 -0
- package/lib/Providers.d.ts.map +1 -0
- package/lib/Providers.js +42 -0
- package/lib/Providers.js.map +1 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -0
- package/package.json +54 -3
- package/src/ApiToken.ts +207 -0
- package/src/AuthProvider.ts +113 -0
- package/src/Connect.ts +103 -0
- package/src/Contributions.ts +9 -0
- package/src/Credentials.ts +112 -0
- package/src/Database.ts +519 -0
- package/src/DatabaseToken.ts +213 -0
- package/src/Group.ts +269 -0
- package/src/GroupToken.ts +127 -0
- package/src/Hrana.ts +184 -0
- package/src/ManageDatabases.ts +195 -0
- package/src/OrganizationInvite.ts +118 -0
- package/src/OrganizationMember.ts +122 -0
- package/src/OrganizationSettings.ts +145 -0
- package/src/Providers.ts +67 -0
- package/src/index.ts +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,9 +1,73 @@
|
|
|
1
1
|
# @alchemy.run/turso
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turso for [Alchemy](https://alchemy.run). Declare SQLite databases, groups, and tokens in the same TypeScript program as the Workers that query them.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```sh
|
|
6
|
+
npm install alchemy @alchemy.run/turso @alchemy.run/cloudflare @alchemy.run/sql @effect/sql-libsql effect
|
|
7
|
+
```
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
A database with migrations, queried from a Cloudflare Worker:
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
```typescript
|
|
12
|
+
// src/worker.ts
|
|
13
|
+
import * as Cloudflare from "@alchemy.run/cloudflare";
|
|
14
|
+
import * as SQL from "@alchemy.run/sql/SQLite";
|
|
15
|
+
import * as Turso from "@alchemy.run/turso";
|
|
16
|
+
import * as Effect from "effect/Effect";
|
|
17
|
+
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
|
18
|
+
|
|
19
|
+
export const Db = Effect.gen(function* () {
|
|
20
|
+
const group = yield* Turso.Group("Group", { location: "aws-us-east-1" });
|
|
21
|
+
return yield* Turso.Database("Db", {
|
|
22
|
+
group: group.name,
|
|
23
|
+
migrations: "./migrations",
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export default Cloudflare.Worker(
|
|
28
|
+
"Worker",
|
|
29
|
+
{ main: import.meta.url },
|
|
30
|
+
Effect.gen(function* () {
|
|
31
|
+
// The Worker gets the database URL and its own scoped token.
|
|
32
|
+
const sql = yield* SQL.LibSQL(yield* Turso.Connect(Db));
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
fetch: Effect.gen(function* () {
|
|
36
|
+
const notes = yield* sql`SELECT * FROM notes`;
|
|
37
|
+
return yield* HttpServerResponse.json(notes);
|
|
38
|
+
}).pipe(Effect.orDie),
|
|
39
|
+
};
|
|
40
|
+
}).pipe(Effect.provide(Turso.ConnectHttp)),
|
|
41
|
+
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// alchemy.run.ts
|
|
46
|
+
import * as Alchemy from "alchemy";
|
|
47
|
+
import * as Cloudflare from "@alchemy.run/cloudflare";
|
|
48
|
+
import * as Turso from "@alchemy.run/turso";
|
|
49
|
+
import * as Effect from "effect/Effect";
|
|
50
|
+
import * as Layer from "effect/Layer";
|
|
51
|
+
import Worker from "./src/worker.ts";
|
|
52
|
+
|
|
53
|
+
export default Alchemy.Stack(
|
|
54
|
+
"MyApp",
|
|
55
|
+
{
|
|
56
|
+
providers: Layer.mergeAll(Cloudflare.providers(), Turso.providers()),
|
|
57
|
+
state: Cloudflare.state(),
|
|
58
|
+
},
|
|
59
|
+
Effect.gen(function* () {
|
|
60
|
+
const worker = yield* Worker;
|
|
61
|
+
return { url: worker.url };
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Turso databases are cheap, so a Worker can also create one per tenant with `Turso.ManageDatabases`.
|
|
67
|
+
|
|
68
|
+
## Learn more
|
|
69
|
+
|
|
70
|
+
- [Turso on alchemy.run](https://alchemy.run/turso)
|
|
71
|
+
- [Setup](https://alchemy.run/turso/setup)
|
|
72
|
+
- [Tutorial](https://alchemy.run/turso/tutorial/part-1)
|
|
73
|
+
- [Database per tenant](https://alchemy.run/turso/database-per-tenant)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as turso from "@distilled.cloud/turso/turso";
|
|
2
|
+
import * as Provider from "alchemy/Provider";
|
|
3
|
+
import { Resource } from "alchemy/Resource";
|
|
4
|
+
import * as Redacted from "effect/Redacted";
|
|
5
|
+
import type { Providers } from "./Providers.ts";
|
|
6
|
+
declare const ApiTokenUnexpectedResponse_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 & {
|
|
7
|
+
readonly _tag: "ApiTokenUnexpectedResponse";
|
|
8
|
+
} & Readonly<A>;
|
|
9
|
+
export declare class ApiTokenUnexpectedResponse extends ApiTokenUnexpectedResponse_base<{
|
|
10
|
+
readonly message: string;
|
|
11
|
+
readonly cause?: unknown;
|
|
12
|
+
}> {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A permission granted to a group-scoped API token. `read-only` and
|
|
16
|
+
* `full-access` are presets that expand to individual scopes.
|
|
17
|
+
*/
|
|
18
|
+
export type ApiTokenScope = "read" | "db:create" | "db:delete" | "db:configure" | "db:mint-token" | "db:rotate-creds" | "group:configure" | "group:mint-token" | "group:rotate-creds" | "read-only" | "full-access";
|
|
19
|
+
export interface ApiTokenProps {
|
|
20
|
+
/**
|
|
21
|
+
* Token name, unique within your account. If omitted, a unique name is
|
|
22
|
+
* generated from the stack, stage, and logical ID.
|
|
23
|
+
*/
|
|
24
|
+
name?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Restrict the token to one group of the organization (e.g.
|
|
27
|
+
* `group.name`). Requires `scopes`. Omit for an organization-scoped token.
|
|
28
|
+
*/
|
|
29
|
+
group?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Permissions of a group-scoped token. Required (and non-empty) when
|
|
32
|
+
* `group` is set. `db:mint-token` issues new SQL tokens;
|
|
33
|
+
* `db:rotate-creds` invalidates every SQL token of a database.
|
|
34
|
+
*/
|
|
35
|
+
scopes?: ApiTokenScope[];
|
|
36
|
+
}
|
|
37
|
+
export interface ApiTokenAttributes {
|
|
38
|
+
/** Token ID. */
|
|
39
|
+
id: string;
|
|
40
|
+
/** Token name. */
|
|
41
|
+
name: string;
|
|
42
|
+
/** The organization slug the token is restricted to. */
|
|
43
|
+
organization: string;
|
|
44
|
+
/** The group the token is restricted to, if group-scoped. */
|
|
45
|
+
group: string | undefined;
|
|
46
|
+
/** The expanded scopes of a group-scoped token. */
|
|
47
|
+
scopes: string[];
|
|
48
|
+
/** The Platform API token, sent as `Authorization: Bearer <token>`. */
|
|
49
|
+
token: Redacted.Redacted<string>;
|
|
50
|
+
}
|
|
51
|
+
export type ApiToken = Resource<"Turso.ApiToken", ApiTokenProps, ApiTokenAttributes, never, Providers>;
|
|
52
|
+
/**
|
|
53
|
+
* A Turso API token. It lets an app create and delete groups and databases.
|
|
54
|
+
* To run SQL, use a {@link DatabaseToken} instead. Limit it to one group
|
|
55
|
+
* with `group` and `scopes` to give an app only the access it needs.
|
|
56
|
+
*
|
|
57
|
+
* Turso only shows the token once, when it's created, so Alchemy stores it
|
|
58
|
+
* in state as a `Redacted` value. Changing a prop creates a new token, and
|
|
59
|
+
* destroying it cancels the token.
|
|
60
|
+
* @see https://docs.turso.tech/api-reference/tokens/create
|
|
61
|
+
*
|
|
62
|
+
* ### Creating a Token
|
|
63
|
+
* **Example:** Token for the whole organization
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const token = yield* Turso.ApiToken("Ci", {});
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* **Example:** Token that can only create databases in one group
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const token = yield* Turso.ApiToken("Tenants", {
|
|
71
|
+
* group: group.name,
|
|
72
|
+
* scopes: ["read", "db:create", "db:delete", "db:mint-token"],
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @resource
|
|
77
|
+
* @product API Token
|
|
78
|
+
*/
|
|
79
|
+
export declare const ApiToken: import("alchemy/Resource").ResourceClass<ApiToken>;
|
|
80
|
+
export declare const ApiTokenProvider: () => import("effect/Layer").Layer<Provider.Provider<ApiToken>, never, import("./Credentials.ts").Organization | import("alchemy/Stack").Stack | import("alchemy/Stage").Stage | turso.TursoOpContext>;
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=ApiToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiToken.d.ts","sourceRoot":"","sources":["../src/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L,SAAS,CACV,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,QAAQ,oDAAuC,CAAC;AAK7D,eAAO,MAAM,gBAAgB,wMAkG1B,CAAC"}
|
package/lib/ApiToken.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as turso from "@distilled.cloud/turso/turso";
|
|
2
|
+
import { Unowned } from "alchemy/AdoptPolicy";
|
|
3
|
+
import { deepEqual, isResolved } from "alchemy/Diff";
|
|
4
|
+
import { createPhysicalName } from "alchemy/PhysicalName";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import { Resource } from "alchemy/Resource";
|
|
7
|
+
import * as Data from "effect/Data";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Redacted from "effect/Redacted";
|
|
10
|
+
import { organization } from "./Credentials.js";
|
|
11
|
+
export class ApiTokenUnexpectedResponse extends Data.TaggedError("ApiTokenUnexpectedResponse") {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A Turso API token. It lets an app create and delete groups and databases.
|
|
15
|
+
* To run SQL, use a {@link DatabaseToken} instead. Limit it to one group
|
|
16
|
+
* with `group` and `scopes` to give an app only the access it needs.
|
|
17
|
+
*
|
|
18
|
+
* Turso only shows the token once, when it's created, so Alchemy stores it
|
|
19
|
+
* in state as a `Redacted` value. Changing a prop creates a new token, and
|
|
20
|
+
* destroying it cancels the token.
|
|
21
|
+
* @see https://docs.turso.tech/api-reference/tokens/create
|
|
22
|
+
*
|
|
23
|
+
* ### Creating a Token
|
|
24
|
+
* **Example:** Token for the whole organization
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const token = yield* Turso.ApiToken("Ci", {});
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* **Example:** Token that can only create databases in one group
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const token = yield* Turso.ApiToken("Tenants", {
|
|
32
|
+
* group: group.name,
|
|
33
|
+
* scopes: ["read", "db:create", "db:delete", "db:mint-token"],
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @resource
|
|
38
|
+
* @product API Token
|
|
39
|
+
*/
|
|
40
|
+
export const ApiToken = Resource("Turso.ApiToken");
|
|
41
|
+
const tokenName = (id, name) => name ? Effect.succeed(name) : createPhysicalName({ id, maxLength: 64, delimiter: "-" });
|
|
42
|
+
export const ApiTokenProvider = () => Provider.effect(ApiToken, Effect.gen(function* () {
|
|
43
|
+
const observe = (name) => turso
|
|
44
|
+
.listAPITokens({})
|
|
45
|
+
.pipe(Effect.map(({ tokens }) => (tokens ?? []).find((t) => t.name === name)));
|
|
46
|
+
const revoke = (name) => turso.revokeAPIToken({ tokenName: name }).pipe(Effect.asVoid, Effect.catchTag("NotFound", () => Effect.void));
|
|
47
|
+
return {
|
|
48
|
+
stables: ["id", "name", "organization", "group", "scopes", "token"],
|
|
49
|
+
diff: Effect.fn(function* ({ id, olds, news, output }) {
|
|
50
|
+
if (!isResolved(news))
|
|
51
|
+
return undefined;
|
|
52
|
+
const name = output?.name ?? (yield* tokenName(id, olds?.name));
|
|
53
|
+
// Turso tokens are immutable: any change mints a new one.
|
|
54
|
+
if ((news.name !== undefined && news.name !== name) ||
|
|
55
|
+
news.group !== olds?.group ||
|
|
56
|
+
!deepEqual(news.scopes ?? [], olds?.scopes ?? [])) {
|
|
57
|
+
// A pinned name can't be held by two tokens at once.
|
|
58
|
+
return {
|
|
59
|
+
action: "replace",
|
|
60
|
+
deleteFirst: news.name !== undefined && news.name === name,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
read: Effect.fn(function* ({ id, olds, output, previous }) {
|
|
65
|
+
const name = output?.name ?? (yield* tokenName(id, olds?.name));
|
|
66
|
+
const observed = yield* observe(name);
|
|
67
|
+
if (!observed)
|
|
68
|
+
return undefined;
|
|
69
|
+
if (output !== undefined && output.id === observed.id)
|
|
70
|
+
return output;
|
|
71
|
+
// The generation a delete-first replacement is about to revoke.
|
|
72
|
+
if (previous !== undefined && previous.id === observed.id)
|
|
73
|
+
return previous;
|
|
74
|
+
// The secret is only revealed at creation, so a token we have no
|
|
75
|
+
// state for can't be adopted with its value — reconcile re-mints.
|
|
76
|
+
return Unowned({
|
|
77
|
+
id: observed.id ?? "",
|
|
78
|
+
name,
|
|
79
|
+
organization: observed.organization ?? "",
|
|
80
|
+
group: observed.group,
|
|
81
|
+
scopes: observed.scopes ?? [],
|
|
82
|
+
token: Redacted.make(""),
|
|
83
|
+
});
|
|
84
|
+
}),
|
|
85
|
+
reconcile: Effect.fn(function* ({ id, news, output, session }) {
|
|
86
|
+
const org = output?.organization ?? (yield* organization);
|
|
87
|
+
const name = output?.name ?? (yield* tokenName(id, news.name));
|
|
88
|
+
// Observe
|
|
89
|
+
const observed = yield* observe(name);
|
|
90
|
+
if (observed &&
|
|
91
|
+
output &&
|
|
92
|
+
Redacted.value(output.token) !== "" &&
|
|
93
|
+
output.id === observed.id) {
|
|
94
|
+
return output;
|
|
95
|
+
}
|
|
96
|
+
// Ensure — a token we hold no secret for (a lost create, or an
|
|
97
|
+
// adoption) is revoked and re-minted.
|
|
98
|
+
if (observed) {
|
|
99
|
+
yield* session.note(`Re-minting API token ${name}...`);
|
|
100
|
+
yield* revoke(name);
|
|
101
|
+
}
|
|
102
|
+
const created = yield* turso.createAPIToken({
|
|
103
|
+
tokenName: name,
|
|
104
|
+
organization: org,
|
|
105
|
+
group: news.group,
|
|
106
|
+
scopes: news.scopes,
|
|
107
|
+
});
|
|
108
|
+
if (!created.token || !created.id) {
|
|
109
|
+
return yield* new ApiTokenUnexpectedResponse({
|
|
110
|
+
message: `Turso returned no token for ${name}`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const minted = yield* observe(name);
|
|
114
|
+
return {
|
|
115
|
+
id: created.id,
|
|
116
|
+
name,
|
|
117
|
+
organization: minted?.organization ?? org,
|
|
118
|
+
group: minted?.group ?? news.group,
|
|
119
|
+
scopes: minted?.scopes ?? [],
|
|
120
|
+
token: created.token,
|
|
121
|
+
};
|
|
122
|
+
}),
|
|
123
|
+
delete: Effect.fn(function* ({ output }) {
|
|
124
|
+
yield* revoke(output.name);
|
|
125
|
+
}),
|
|
126
|
+
};
|
|
127
|
+
}));
|
|
128
|
+
//# sourceMappingURL=ApiToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiToken.js","sourceRoot":"","sources":["../src/ApiToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,MAAM,OAAO,0BAA2B,SAAQ,IAAI,CAAC,WAAW,CAAC,4BAA4B,CAG3F;CAAG;AA6DL;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAW,gBAAgB,CAAC,CAAC;AAE7D,MAAM,SAAS,GAAG,CAAC,EAAU,EAAE,IAAwB,EAAE,EAAE,CACzD,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAA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0BAA0B,CAAC;oBAC3C,OAAO,EAAE,+BAA+B,IAAI,EAAE;iBAC/C,CAAC,CAAC;YACL,CAAC;YACD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACpC,OAAO;gBACL,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,IAAI;gBACJ,YAAY,EAAE,MAAM,EAAE,YAAY,IAAI,GAAG;gBACzC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC,KAAK;gBAClC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,EAAE;gBAC5B,KAAK,EAAE,OAAO,CAAC,KAAK;aACrB,CAAC;QACJ,CAAC,CAAC;QACF,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE;YACrC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type StoredAuthConfig } from "alchemy/Auth/StoredAuthProvider";
|
|
2
|
+
import * as Redacted from "effect/Redacted";
|
|
3
|
+
/**
|
|
4
|
+
* Canonical name registered in the AuthProviders registry. Use this key to
|
|
5
|
+
* look up the Turso AuthProvider from inside provider Layers.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TURSO_AUTH_PROVIDER_NAME = "Turso";
|
|
8
|
+
export type TursoAuthConfig = StoredAuthConfig;
|
|
9
|
+
/**
|
|
10
|
+
* Resolved Turso Platform API credentials.
|
|
11
|
+
*
|
|
12
|
+
* Turso has no OAuth application flow — the Platform API authenticates
|
|
13
|
+
* with API tokens only (`turso auth api-tokens mint <name>`). The
|
|
14
|
+
* organization is optional: when omitted it is discovered from the token
|
|
15
|
+
* (an organization-scoped token, or an account with a single organization).
|
|
16
|
+
*/
|
|
17
|
+
export interface TursoResolvedCredentials {
|
|
18
|
+
type: "apiToken";
|
|
19
|
+
apiToken: Redacted.Redacted<string>;
|
|
20
|
+
apiBaseUrl: string;
|
|
21
|
+
organization: string | undefined;
|
|
22
|
+
source: {
|
|
23
|
+
type: TursoAuthConfig["method"] | "env";
|
|
24
|
+
details?: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Layer that registers the Turso AuthProvider into the AuthProviders
|
|
29
|
+
* registry when built. Included in `Turso.providers()` so the alchemy CLI
|
|
30
|
+
* (`alchemy profile edit`) can configure it.
|
|
31
|
+
*/
|
|
32
|
+
export declare const TursoAuth: import("effect/Layer").Layer<never, never, import("alchemy/Auth/Registry").AuthProviders | import("effect/FileSystem").FileSystem | import("effect/Path").Path>;
|
|
33
|
+
/** Schema of Turso's inline API-token values. */
|
|
34
|
+
export declare const TursoStoredCredentials: import("effect/Schema").Codec<import("alchemy/Auth/StoredAuthProvider").StoredValues, import("alchemy/Auth/StoredAuthProvider").StoredValues, never, never>;
|
|
35
|
+
export type TursoStoredCredentials = typeof TursoStoredCredentials.Type;
|
|
36
|
+
//# sourceMappingURL=AuthProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../src/AuthProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,UAAU,CAAC;AAEhD,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,MAAM,EAAE;QAAE,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvE;AAqED;;;;GAIG;AACH,eAAO,MAAM,SAAS,iKAAkB,CAAC;AAEzC,iDAAiD;AACjD,eAAO,MAAM,sBAAsB,6JAAyB,CAAC;AAC7D,MAAM,MAAM,sBAAsB,GAAG,OAAO,sBAAsB,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { DEFAULT_API_BASE_URL } from "@distilled.cloud/turso/Credentials";
|
|
2
|
+
import { AuthError } from "alchemy/Auth/AuthProvider";
|
|
3
|
+
import { getEnv, getEnvRedacted } from "alchemy/Auth/Env";
|
|
4
|
+
import { makeStoredAuthProvider, storedSecret, storedValueText, } from "alchemy/Auth/StoredAuthProvider";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Redacted from "effect/Redacted";
|
|
7
|
+
/**
|
|
8
|
+
* Canonical name registered in the AuthProviders registry. Use this key to
|
|
9
|
+
* look up the Turso AuthProvider from inside provider Layers.
|
|
10
|
+
*/
|
|
11
|
+
export const TURSO_AUTH_PROVIDER_NAME = "Turso";
|
|
12
|
+
const readEnvironment = Effect.gen(function* () {
|
|
13
|
+
const apiToken = yield* getEnvRedacted("TURSO_API_TOKEN");
|
|
14
|
+
const apiKey = yield* getEnvRedacted("TURSO_API_KEY");
|
|
15
|
+
const token = apiToken ?? apiKey;
|
|
16
|
+
if (token === undefined || Redacted.value(token).trim().length === 0) {
|
|
17
|
+
return yield* AuthError.make({
|
|
18
|
+
message: "Turso CI credentials not found. Set TURSO_API_TOKEN or TURSO_API_KEY.",
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
type: "apiToken",
|
|
23
|
+
apiToken: Redacted.make(Redacted.value(token).trim()),
|
|
24
|
+
apiBaseUrl: (yield* getEnv("TURSO_API_BASE_URL")) ?? DEFAULT_API_BASE_URL,
|
|
25
|
+
organization: yield* getEnv("TURSO_ORGANIZATION"),
|
|
26
|
+
source: {
|
|
27
|
+
type: "env",
|
|
28
|
+
details: apiToken === undefined ? "TURSO_API_KEY" : "TURSO_API_TOKEN",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
const tursoAuth = makeStoredAuthProvider({
|
|
33
|
+
provider: TURSO_AUTH_PROVIDER_NAME,
|
|
34
|
+
fields: [
|
|
35
|
+
{
|
|
36
|
+
name: "apiToken",
|
|
37
|
+
label: "Turso API Token",
|
|
38
|
+
description: "Mint one with `turso auth api-tokens mint alchemy`.",
|
|
39
|
+
secret: true,
|
|
40
|
+
validate: (value) => (value.trim().length === 0 ? "Required" : undefined),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "organization",
|
|
44
|
+
label: "Turso Organization (slug)",
|
|
45
|
+
description: "Defaults to the token's organization when it has exactly one.",
|
|
46
|
+
optional: true,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
toResolved: (values, source) => ({
|
|
50
|
+
type: "apiToken",
|
|
51
|
+
apiToken: storedSecret(values.apiToken) ?? Redacted.make(""),
|
|
52
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
53
|
+
organization: storedValueText(values.organization),
|
|
54
|
+
source: { type: source },
|
|
55
|
+
}),
|
|
56
|
+
readEnvironment,
|
|
57
|
+
environment: [
|
|
58
|
+
{
|
|
59
|
+
name: "TURSO_API_TOKEN",
|
|
60
|
+
required: true,
|
|
61
|
+
secret: true,
|
|
62
|
+
alternatives: ["TURSO_API_KEY"],
|
|
63
|
+
description: "Turso Platform API token.",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "TURSO_ORGANIZATION",
|
|
67
|
+
required: false,
|
|
68
|
+
description: "Organization slug; defaults to the token's only organization.",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "TURSO_API_BASE_URL",
|
|
72
|
+
required: false,
|
|
73
|
+
description: "Platform API base URL override.",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Layer that registers the Turso AuthProvider into the AuthProviders
|
|
79
|
+
* registry when built. Included in `Turso.providers()` so the alchemy CLI
|
|
80
|
+
* (`alchemy profile edit`) can configure it.
|
|
81
|
+
*/
|
|
82
|
+
export const TursoAuth = tursoAuth.layer;
|
|
83
|
+
/** Schema of Turso's inline API-token values. */
|
|
84
|
+
export const TursoStoredCredentials = tursoAuth.storedSchema;
|
|
85
|
+
//# sourceMappingURL=AuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","sourceRoot":"","sources":["../src/AuthProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,eAAe,GAEhB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAoBhD,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IACtD,MAAM,KAAK,GAAG,QAAQ,IAAI,MAAM,CAAC;IACjC,IAAI,KAAK,KAAK,SAAS,IAAI,QA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