@volter/twin-turbopuffer 0.1.0
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 +202 -0
- package/README.md +145 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +27 -0
- package/dist/src/generated/surface.gen.json +1 -0
- package/dist/src/generated/ui.gen.json +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +65 -0
- package/dist/src/key-gate.d.ts +3 -0
- package/dist/src/key-gate.js +39 -0
- package/dist/src/manifest.d.ts +2 -0
- package/dist/src/manifest.js +28 -0
- package/dist/src/screens/dashboard.d.ts +11 -0
- package/dist/src/screens/dashboard.js +191 -0
- package/dist/src/semantics/namespaces.d.ts +5 -0
- package/dist/src/semantics/namespaces.js +17 -0
- package/dist/src/turbopuffer-capabilities.d.ts +6 -0
- package/dist/src/turbopuffer-capabilities.js +442 -0
- package/dist/src/turbopuffer-conformance.d.ts +8 -0
- package/dist/src/turbopuffer-conformance.js +102 -0
- package/dist/src/turbopuffer-connector.d.ts +34 -0
- package/dist/src/turbopuffer-connector.js +152 -0
- package/dist/src/turbopuffer-filter.d.ts +57 -0
- package/dist/src/turbopuffer-filter.js +286 -0
- package/dist/src/turbopuffer-server.d.ts +23 -0
- package/dist/src/turbopuffer-server.js +72 -0
- package/dist/src/turbopuffer-stem.d.ts +1 -0
- package/dist/src/turbopuffer-stem.js +133 -0
- package/dist/src/turbopuffer-store.d.ts +80 -0
- package/dist/src/turbopuffer-store.js +1304 -0
- package/dist/src/turbopuffer-text.d.ts +44 -0
- package/dist/src/turbopuffer-text.js +189 -0
- package/dist/src/turbopuffer-twin.d.ts +25 -0
- package/dist/src/turbopuffer-twin.js +406 -0
- package/package.json +56 -0
- package/src/cli.ts +28 -0
- package/src/generated/surface.gen.json +1 -0
- package/src/generated/ui.gen.json +1 -0
- package/src/index.ts +92 -0
- package/src/key-gate.ts +39 -0
- package/src/manifest.ts +63 -0
- package/src/screens/dashboard.tsx +214 -0
- package/src/semantics/namespaces.ts +30 -0
- package/src/turbopuffer-capabilities.ts +455 -0
- package/src/turbopuffer-conformance.ts +101 -0
- package/src/turbopuffer-connector.ts +153 -0
- package/src/turbopuffer-filter.ts +277 -0
- package/src/turbopuffer-server.ts +81 -0
- package/src/turbopuffer-stem.ts +104 -0
- package/src/turbopuffer-store.ts +1157 -0
- package/src/turbopuffer-text.ts +204 -0
- package/src/turbopuffer-twin.ts +429 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# @volter/twin-turbopuffer
|
|
2
|
+
|
|
3
|
+
A local, stateful twin of the [Turbopuffer](https://turbopuffer.com) API (v2 namespaces), built on
|
|
4
|
+
`@volter/world-core`. The unmodified `@turbopuffer/turbopuffer` client writes documents into it and
|
|
5
|
+
queries them back: filters, BM25 full-text ranking, attribute ordering, exact vector distance and
|
|
6
|
+
counts are computed from the stored documents, deterministically.
|
|
7
|
+
|
|
8
|
+
The motivating consumer is Dub's partner search (`apps/web/lib/api/partners/search/providers/
|
|
9
|
+
turbopuffer.ts`): its sync jobs `write` `upsert_rows` with a declared schema and `deletes`, its
|
|
10
|
+
search runs a `multiQuery` of BM25 branches with `last_as_prefix`, `ContainsAllTokens` and program /
|
|
11
|
+
group / tag filters, its count runs `aggregate_by: { total: ['Count'] }`, and its maintenance script
|
|
12
|
+
calls `deleteAll`.
|
|
13
|
+
|
|
14
|
+
## Pointing a client at it
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
world-turbopuffer serve --port 8787 --root ./state
|
|
18
|
+
TURBOPUFFER_API_KEY=anything TURBOPUFFER_BASE_URL='http://127.0.0.1:8787/{region}' node app.js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
In a World, `volter-world init` wires this for you: the service exports `TURBOPUFFER_TWIN_URL` and
|
|
22
|
+
`TURBOPUFFER_BASE_URL=${url}/{region}`. The `{region}` placeholder is required: the SDK throws
|
|
23
|
+
"region is set, but would be ignored" when a caller passes `region` (Dub passes `aws-us-east-1`)
|
|
24
|
+
and the base URL has no placeholder. The twin accepts and ignores the leading region segment.
|
|
25
|
+
|
|
26
|
+
## Grounded wire
|
|
27
|
+
|
|
28
|
+
Grounded in the installed `@turbopuffer/turbopuffer@2.8.0` (`src/` paths below are that package's).
|
|
29
|
+
|
|
30
|
+
| Fact | Value | Source |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| Default host | `https://{region}.turbopuffer.com`, e.g. `aws-us-east-1.turbopuffer.com` | `src/client.ts:273` |
|
|
33
|
+
| Region | `region` option or `TURBOPUFFER_REGION`; required when the URL has `{region}` | `src/client.ts:255`, `274-286` |
|
|
34
|
+
| Base URL override | `TURBOPUFFER_BASE_URL` (or `baseURL`); `{region}` is substituted into it | `src/client.ts:253`, `281` |
|
|
35
|
+
| Auth | `Authorization: Bearer <apiKey>` (`TURBOPUFFER_API_KEY`) | `src/client.ts:254`, `383` |
|
|
36
|
+
| Request headers | `Accept: application/json`, `Accept-Encoding: identity`, `User-Agent`, `X-Stainless-*`, `Prefer: respond-async` | `src/client.ts:858-864`, `src/internal/custom/respond-async.ts` |
|
|
37
|
+
| Request body | JSON; gzip only with `compression: true` (default false) | `src/client.ts:299`, `812` |
|
|
38
|
+
| Node transport | undici `Agent.request`, selected by the `#fetch` import map for the `node` condition | `package.json` `imports`, `src/internal/custom/fetch-node.ts` |
|
|
39
|
+
| List namespaces | `GET /v1/namespaces?prefix&page_size&cursor` → `{ namespaces: [{id}], next_cursor }` | `src/client.ts:368`, `src/core/pagination.ts:123` |
|
|
40
|
+
| Write | `POST /v2/namespaces/{ns}` | `src/resources/namespaces.ts:174` |
|
|
41
|
+
| deleteAll | `DELETE /v2/namespaces/{ns}` → `{ status: 'OK' }` | `namespaces.ts:46`, `1100` |
|
|
42
|
+
| Query | `POST /v2/namespaces/{ns}/query` | `namespaces.ts:104` |
|
|
43
|
+
| multiQuery | `POST /v2/namespaces/{ns}/query?stainless_overload=multiQuery` with `{ queries }` | `namespaces.ts:90` |
|
|
44
|
+
| Metadata | `GET /v2/namespaces/{ns}/metadata` | `namespaces.ts:79` |
|
|
45
|
+
| Schema | `GET` / `POST /v1/namespaces/{ns}/schema` | `namespaces.ts:126`, `163` |
|
|
46
|
+
| Cache warm | `GET /v1/namespaces/{ns}/hint_cache_warm` | `namespaces.ts:68` |
|
|
47
|
+
| Write response | `{ status: 'OK', message, rows_affected, rows_upserted?, rows_patched?, rows_deleted?, *_ids?, billing }` | `namespaces.ts:1231-1294` |
|
|
48
|
+
| Query response | `{ rows?, aggregations?, billing, performance }`; a row is `{ id, $dist?, ...attributes }` | `namespaces.ts:850-868`, `1159-1175` |
|
|
49
|
+
| FTS defaults | tokenizer `word_v4`, `k1` 1.2, `b` 0.75, case-insensitive, stopwords kept (`remove_stopwords` false since January 2026), no stemming, `max_token_length` 39 | `namespaces.ts:474-526` |
|
|
50
|
+
| Filterable default | full-text attributes are not filterable unless `filterable: true` | `namespaces.ts:249-253` |
|
|
51
|
+
| Errors | status → `BadRequestError` 400, `AuthenticationError` 401, `NotFoundError` 404, … | `src/core/error.ts` |
|
|
52
|
+
|
|
53
|
+
Under Node the SDK sends through undici's `Agent.request`, which neither the injector's
|
|
54
|
+
http/https/fetch patches nor `HTTPS_PROXY` reach, so `TURBOPUFFER_BASE_URL` is the interception.
|
|
55
|
+
The descriptor also claims the regional hosts (`^(aws|gcp|azure)-….turbopuffer.com$`) for runtimes
|
|
56
|
+
that use the fetch build (Bun, edge).
|
|
57
|
+
|
|
58
|
+
## Coverage
|
|
59
|
+
|
|
60
|
+
Modelled (each has a `done` capability with a verify in `src/turbopuffer-capabilities.ts`):
|
|
61
|
+
|
|
62
|
+
- **write**: `upsert_rows`, `upsert_columns`, `patch_rows`, `patch_columns`, `deletes`,
|
|
63
|
+
`delete_by_filter`, `patch_by_filter`, `schema`, `distance_metric`, `return_affected_ids`,
|
|
64
|
+
`disable_backpressure` (accepted; the twin has no backpressure). One write request is one kernel
|
|
65
|
+
action. Extrapolated, not in the SDK: the twin applies it in the order filtered deletes →
|
|
66
|
+
filtered patches → upserts → patches → deletes.
|
|
67
|
+
Upserts replace the whole document; patches merge and never create; a `null` value removes the
|
|
68
|
+
attribute. Attribute types are declared or inferred on first write (`string`, `int`, `float`,
|
|
69
|
+
`bool`, `[]string`, …) and a mismatched value or type change is refused with 400.
|
|
70
|
+
- **query**: `filters` (Eq, NotEq, In, NotIn, Contains, NotContains, ContainsAny, NotContainsAny,
|
|
71
|
+
Lt/Lte/Gt/Gte, AnyLt/AnyLte/AnyGt/AnyGte, Glob/NotGlob/IGlob/NotIGlob, ContainsAllTokens,
|
|
72
|
+
ContainsAnyToken with `last_as_prefix`, And/Or/Not); `rank_by` BM25 (with `last_as_prefix`,
|
|
73
|
+
`Sum`, `Max`, `Product`), attribute order (`[attr, asc|desc]` and lists of them), and
|
|
74
|
+
`[vector, ANN|kNN, q]` with exact `cosine_distance` / `euclidean_squared`; `top_k` / `limit`
|
|
75
|
+
(default 10); `include_attributes` / `exclude_attributes`; `aggregate_by` Count, Count(attr),
|
|
76
|
+
Sum(attr); `consistency` (the twin is always strongly consistent); `multiQuery`.
|
|
77
|
+
- **namespaces**: list (prefix, cursor paging), metadata, schema read and update, cache-warm hint,
|
|
78
|
+
deleteAll. A query, metadata or schema read on a namespace that does not exist answers 404.
|
|
79
|
+
- **auth**: a missing or empty Bearer key is 401; `--token` makes the twin demand one exact key.
|
|
80
|
+
- **real state system**: `performTurbopufferAction` replays a recorded write / deleteAll / schema
|
|
81
|
+
update against the vendor; `syncTurbopufferFromRemote` observes namespaces, schema and documents
|
|
82
|
+
(paged by id) from a real account.
|
|
83
|
+
|
|
84
|
+
Semantics a caller depends on: an attribute a document does not carry reads as null, so `NotIn`,
|
|
85
|
+
`NotEq` and `NotContainsAny` match it (Dub omits `groupId`/`country` for exactly this). A
|
|
86
|
+
comparison filter on a non-filterable attribute is refused with 400; the token filters require
|
|
87
|
+
`full_text_search` on the attribute.
|
|
88
|
+
|
|
89
|
+
### Deterministic, not byte-equal
|
|
90
|
+
|
|
91
|
+
Scores and tokens are deterministic but are not Turbopuffer's exact numbers. `word_v2` is modelled
|
|
92
|
+
as maximal runs of Unicode letters, digits, marks and `_` (so a URL splits into its components, as
|
|
93
|
+
Dub measured); English stopwords are the 33-word Lucene list; BM25 is textbook Okapi with the
|
|
94
|
+
Lucene IDF `ln(1 + (N − n + 0.5)/(n + 0.5))` over the namespace's documents carrying the attribute;
|
|
95
|
+
a `last_as_prefix` final token contributes a constant 1 per matching document (Dub observed that a
|
|
96
|
+
single-token prefix query scores every match exactly 1). Ties order by id ascending. Error message
|
|
97
|
+
strings and the `{ status: 'error', error }` body are the twin's own reading (this build had no
|
|
98
|
+
account to probe); the SDK surfaces that body verbatim as `APIError.error`, and the statuses map to
|
|
99
|
+
the SDK's error classes. `billing` and `performance` are deterministic (logical bytes from the stored JSON,
|
|
100
|
+
zero timings, a "hot" cache).
|
|
101
|
+
|
|
102
|
+
Also the twin's own choices, not grounded in the SDK: namespace names `[A-Za-z0-9-_.]{1,128}`;
|
|
103
|
+
`page_size` at most 1000; `deletes` counts every requested id in `rows_deleted`; an undeclared
|
|
104
|
+
integer attribute is inferred as `int`; an attribute a row lacks projects as `null` when named in
|
|
105
|
+
`include_attributes`; a token filter whose every token is dropped (stopwords) matches nothing; id
|
|
106
|
+
comparisons order numbers before strings. A namespace refreshed from a real account whose
|
|
107
|
+
full-text config the twin does not model (the default `word_v4`, stemming, another language) is
|
|
108
|
+
stored, but BM25 and token filters on it are refused with a 400 naming the gap.
|
|
109
|
+
|
|
110
|
+
### Planned (todo)
|
|
111
|
+
|
|
112
|
+
Refused with a 400 or 404 naming the gap, never answered with a fabricated success: conditional
|
|
113
|
+
writes (`upsert_condition` / `patch_condition` / `delete_condition`), `copy_from_namespace`,
|
|
114
|
+
`branch_from_namespace`, `encryption`, `sharding`, `respond-async` polling (the twin answers
|
|
115
|
+
synchronously, which the SDK accepts), write backpressure, metadata PATCH (pinning), explain_query,
|
|
116
|
+
recall, `group_by`, `compute_attributes`, `aggregate_by` together with `rank_by`, `limit.per`,
|
|
117
|
+
`rerank_by`, rank expressions beyond BM25/Sum/Max/Product, highlights, Regex / Fuzzy /
|
|
118
|
+
ContainsTokenSequence filters, tokenizers other than `word_v2` and `pre_tokenized_array` (including
|
|
119
|
+
the default `word_v4`, so `full_text_search: true` is refused), stemming, non-English languages,
|
|
120
|
+
byte-equal BM25 scores, base64 vectors, named / multi / sparse vectors, server-side embedding, the
|
|
121
|
+
v1 namespace API older SDKs call, and the vendor's literal error strings.
|
|
122
|
+
|
|
123
|
+
The capability verifies were written but not run in the build that added this pack; the evidence
|
|
124
|
+
recorded there was the real `@turbopuffer/turbopuffer@2.8.0` client, constructed as Dub constructs
|
|
125
|
+
it, performing Dub's write → multiQuery → count → delete → deleteAll sequence against a served twin
|
|
126
|
+
through `TURBOPUFFER_BASE_URL`. The census `baseline` stays 0 until the catalog gate measures it.
|
|
127
|
+
|
|
128
|
+
### No UI mirror
|
|
129
|
+
|
|
130
|
+
Turbopuffer is used from code: an application writes and queries namespaces through the SDK. The
|
|
131
|
+
turbopuffer.com dashboard manages API keys, billing and namespace inspection; the work does not
|
|
132
|
+
happen there.
|
|
133
|
+
|
|
134
|
+
## Layout
|
|
135
|
+
|
|
136
|
+
| File | Role |
|
|
137
|
+
|---|---|
|
|
138
|
+
| `src/turbopuffer-twin.ts` | routing, auth, the error envelope, kernel reads and writes |
|
|
139
|
+
| `src/turbopuffer-store.ts` | namespaces and documents as tree subjects; pure write and query |
|
|
140
|
+
| `src/turbopuffer-filter.ts` | the filter language |
|
|
141
|
+
| `src/turbopuffer-text.ts` | tokenizer and BM25 |
|
|
142
|
+
| `src/turbopuffer-server.ts` | the fetch adapter and server |
|
|
143
|
+
| `src/turbopuffer-connector.ts` | perform and refresh adapters |
|
|
144
|
+
| `src/turbopuffer-capabilities.ts` | the capability manifest |
|
|
145
|
+
| `src/turbopuffer-conformance.ts` | endpoint probes and router census |
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { keepProcessAlive } from '@volter/world-core/lifecycle';
|
|
3
|
+
// world-turbopuffer CLI: serve the KERNEL-BACKED Turbopuffer twin, or run conformance. State lives
|
|
4
|
+
// in the @volter/world-core log under --root. Conformance is dev-only + lazy-imported.
|
|
5
|
+
import { hasFlag, optionValue } from '@volter/world-core/args';
|
|
6
|
+
import { createTurbopufferTwinServer } from "./turbopuffer-server.js";
|
|
7
|
+
const [cmd, ...rest] = process.argv.slice(2);
|
|
8
|
+
const port = Number(optionValue(rest, '--port', String(process.env.PORT ?? '0'))) || undefined;
|
|
9
|
+
const root = optionValue(rest, '--root') || process.env.VOLTER_STATE_DIR || undefined;
|
|
10
|
+
const token = optionValue(rest, '--token') || undefined;
|
|
11
|
+
const readOnly = hasFlag(rest, '--read-only');
|
|
12
|
+
if (cmd === 'serve' || cmd === undefined) {
|
|
13
|
+
const s = await createTurbopufferTwinServer({ readOnly, ...(root ? { root } : {}), ...(port ? { port } : {}), ...(token ? { token } : {}) });
|
|
14
|
+
process.stdout.write(`turbopuffer twin (v2 namespaces: write, query, multiQuery, deleteAll, metadata, schema)${readOnly ? ' [read-only]' : ''} at http://127.0.0.1:${s.port}\n`
|
|
15
|
+
+ ` point the SDK at it with TURBOPUFFER_BASE_URL=http://127.0.0.1:${s.port}/{region} and any non-empty TURBOPUFFER_API_KEY\n`);
|
|
16
|
+
await keepProcessAlive();
|
|
17
|
+
}
|
|
18
|
+
else if (cmd === 'conformance') {
|
|
19
|
+
const { checkTurbopufferConformance } = await import("./turbopuffer-conformance.js");
|
|
20
|
+
const report = await checkTurbopufferConformance(root ? { root } : {});
|
|
21
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
22
|
+
if (!report.ok)
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
process.stdout.write('Usage: world-turbopuffer serve|conformance [--port N] [--root DIR] [--token KEY] [--read-only]\n');
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"generatedBy":"scripts/derive-pack.ts","spec":"openapi.yaml.gz","format":"openapi","version":"0.0.1","resources":[{"name":"NamespaceSummary","schema":"NamespaceSummary","fields":[{"name":"id","type":"string","nullable":false,"required":true}],"stateCandidates":[],"expandable":[]}],"operations":[{"id":"get_v1_namespaces","method":"get","path":"/v1/namespaces","pathParams":[],"query":[{"name":"cursor","type":"string","required":false},{"name":"page_size","type":"integer","required":false},{"name":"prefix","type":"string","required":false}],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"NamespaceSummary","list":true,"key":"namespaces"},"class":"list","resource":"NamespaceSummary"},{"id":"post_v1_namespaces_namespace_debug_recall","method":"post","path":"/v1/namespaces/{namespace}/_debug/recall","pathParams":["namespace"],"query":[],"body":[{"name":"filters","type":"any","required":false},{"name":"include_ground_truth","type":"boolean","required":false},{"name":"num","type":"integer","required":false},{"name":"rank_by","type":"any","required":false},{"name":"top_k","type":"integer","required":false}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"get_v1_namespaces_namespace_hint_cache_warm","method":"get","path":"/v1/namespaces/{namespace}/hint_cache_warm","pathParams":["namespace"],"query":[],"body":[],"bodyEncoding":"none","successStatus":202,"class":"computed"},{"id":"get_v1_namespaces_namespace_metadata","method":"get","path":"/v1/namespaces/{namespace}/metadata","pathParams":["namespace"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"},{"id":"patch_v1_namespaces_namespace_metadata","method":"patch","path":"/v1/namespaces/{namespace}/metadata","pathParams":["namespace"],"query":[],"body":[{"name":"pinning","type":"union","required":false}],"bodyEncoding":"json","successStatus":200,"class":"update"},{"id":"get_v1_namespaces_namespace_operations_token","method":"get","path":"/v1/namespaces/{namespace}/operations/{token}","pathParams":["namespace","token"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"},{"id":"get_v1_namespaces_namespace_schema","method":"get","path":"/v1/namespaces/{namespace}/schema","pathParams":["namespace"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"},{"id":"post_v1_namespaces_namespace_schema","method":"post","path":"/v1/namespaces/{namespace}/schema","pathParams":["namespace"],"query":[],"body":[],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"post_v2_namespaces_namespace","method":"post","path":"/v2/namespaces/{namespace}","pathParams":["namespace"],"query":[],"body":[{"name":"branch_from_namespace","type":"BranchFromNamespaceParams","required":false},{"name":"copy_from_namespace","type":"CopyFromNamespaceParams","required":false},{"name":"delete_by_filter","type":"any","required":false},{"name":"delete_by_filter_allow_partial","type":"boolean","required":false},{"name":"delete_condition","type":"any","required":false},{"name":"deletes","type":"array","required":false},{"name":"disable_backpressure","type":"boolean","required":false},{"name":"distance_metric","type":"DistanceMetric","required":false},{"name":"encryption","type":"Encryption","required":false},{"name":"patch_by_filter","type":"PatchByFilter","required":false},{"name":"patch_by_filter_allow_partial","type":"boolean","required":false},{"name":"patch_columns","type":"Columns","required":false},{"name":"patch_condition","type":"any","required":false},{"name":"patch_rows","type":"array","required":false},{"name":"return_affected_ids","type":"boolean","required":false},{"name":"schema","type":"object","required":false},{"name":"sharding","type":"ShardingConfig","required":false},{"name":"upsert_columns","type":"Columns","required":false},{"name":"upsert_condition","type":"any","required":false},{"name":"upsert_rows","type":"array","required":false}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"delete_v2_namespaces_namespace","method":"delete","path":"/v2/namespaces/{namespace}","pathParams":["namespace"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"delete"},{"id":"post_v2_namespaces_namespace_explain_query","method":"post","path":"/v2/namespaces/{namespace}/explain_query","pathParams":["namespace"],"query":[],"body":[],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"get_v2_namespaces_namespace_metadata","method":"get","path":"/v2/namespaces/{namespace}/metadata","pathParams":["namespace"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"},{"id":"post_v2_namespaces_namespace_query","method":"post","path":"/v2/namespaces/{namespace}/query","pathParams":["namespace"],"query":[],"body":[],"bodyEncoding":"json","successStatus":200,"class":"non-resource"}]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"generatedBy":"scripts/derive-pack.ts","resources":{}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TwinPack } from '@volter/world-core';
|
|
2
|
+
export { handleTurbopufferTwinRequest, extractTurbopufferApiKey, normalizeTurbopufferPath, turbopufferTwinSnapshot, } from './turbopuffer-twin.js';
|
|
3
|
+
export type { TurbopufferTwinRequest, TurbopufferTwinResponse } from './turbopuffer-twin.js';
|
|
4
|
+
export { createTurbopufferTwinFetch, createTurbopufferTwinServer } from './turbopuffer-server.js';
|
|
5
|
+
export type { TurbopufferTwinFetchOptions } from './turbopuffer-server.js';
|
|
6
|
+
export { performTurbopufferAction, syncTurbopufferFromReal, syncTurbopufferFromRemote, mapSchemaAttr } from './turbopuffer-connector.js';
|
|
7
|
+
export { SERVICE, TURBOPUFFER_RESOURCE_TYPES, TurbopufferError, applyWrite, runQuery, loadNamespaces, schemaWire, cosineDistance, euclideanSquared, } from './turbopuffer-store.js';
|
|
8
|
+
export type { NamespaceState, AttrConfig, Doc } from './turbopuffer-store.js';
|
|
9
|
+
export { compileFilter } from './turbopuffer-filter.js';
|
|
10
|
+
export { tokenize, queryTerms, bm25Score, buildCorpus, DEFAULT_FTS } from './turbopuffer-text.js';
|
|
11
|
+
export declare const pack: TwinPack;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// @volter/twin-turbopuffer — the Turbopuffer API twin (v2 namespaces), built on @volter/world-core.
|
|
2
|
+
// Namespaces and their documents are kernel state; writes (upsert/patch/delete by id or filter,
|
|
3
|
+
// with schema and distance metric) land as one kernel action per request; queries filter, BM25-rank
|
|
4
|
+
// (deterministic, see turbopuffer-text.ts), order by attribute, rank by exact vector distance and
|
|
5
|
+
// count. See README ## Coverage for what is modelled and what fails loudly.
|
|
6
|
+
import { registerPack } from '@volter/world-core';
|
|
7
|
+
import { performTurbopufferAction, syncTurbopufferFromRemote } from "./turbopuffer-connector.js";
|
|
8
|
+
export { handleTurbopufferTwinRequest, extractTurbopufferApiKey, normalizeTurbopufferPath, turbopufferTwinSnapshot, } from "./turbopuffer-twin.js";
|
|
9
|
+
export { createTurbopufferTwinFetch, createTurbopufferTwinServer } from "./turbopuffer-server.js";
|
|
10
|
+
export { performTurbopufferAction, syncTurbopufferFromReal, syncTurbopufferFromRemote, mapSchemaAttr } from "./turbopuffer-connector.js";
|
|
11
|
+
export { SERVICE, TURBOPUFFER_RESOURCE_TYPES, TurbopufferError, applyWrite, runQuery, loadNamespaces, schemaWire, cosineDistance, euclideanSquared, } from "./turbopuffer-store.js";
|
|
12
|
+
export { compileFilter } from "./turbopuffer-filter.js";
|
|
13
|
+
export { tokenize, queryTerms, bm25Score, buildCorpus, DEFAULT_FTS } from "./turbopuffer-text.js";
|
|
14
|
+
// Registry descriptor (TwinPack) — the SINGLE HOME for this vendor's world-facing facts.
|
|
15
|
+
// `bun scripts/pack-facts.ts` compiles `adoption` / `hosts` / `endpointEnv` into
|
|
16
|
+
// packages/world-core/generated/pack-facts.json; re-run it after ANY edit below.
|
|
17
|
+
export const pack = {
|
|
18
|
+
vendor: 'turbopuffer',
|
|
19
|
+
transport: 'rest',
|
|
20
|
+
protocol: '2',
|
|
21
|
+
archetype: 'crud',
|
|
22
|
+
bin: 'world-turbopuffer',
|
|
23
|
+
resources: ['namespace', 'document'],
|
|
24
|
+
specSource: 'the OpenAPI document @turbopuffer/turbopuffer@2.8.0 was generated from (spec/openapi.yaml.gz, provenance in spec/SOURCE.md), with its generator pseudo-paths folded into the operations turbopuffer documents (spec/patches.json); the calls dubinc/dub makes (apps/web/lib/api/partners/search/providers/turbopuffer.ts).',
|
|
25
|
+
description: 'Turbopuffer v2 namespaces twin — write (upsert/patch/delete rows or columns, delete/patch by filter, schema, distance_metric), query (filters, BM25 with last_as_prefix and Sum/Max/Product, attribute order, exact ANN, Count/Sum aggregates), multiQuery, deleteAll, metadata, schema, list namespaces. Deterministic BM25 (textbook Okapi over a word_v2 approximation — not byte-equal to the vendor). Kernel-backed, no mirror; unmodelled surface answers 400/404 naming its todo.',
|
|
26
|
+
refresh: { every: '15m', onDemand: { atMost: '30s' } },
|
|
27
|
+
stateSystem: { perform: performTurbopufferAction, refresh: syncTurbopufferFromRemote },
|
|
28
|
+
// An upsert of a caller-chosen id: the vendor's own idempotence, so the branch re-send lands cleanly.
|
|
29
|
+
roundTrip: {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
path: '/v2/namespaces/round-trip',
|
|
32
|
+
body: { upsert_rows: [{ id: 'round-trip', title: 'round trip' }] },
|
|
33
|
+
headers: { authorization: 'Bearer round-trip' },
|
|
34
|
+
},
|
|
35
|
+
// ADOPTION — the official Node client (`@turbopuffer/turbopuffer`, the scope is Turbopuffer's
|
|
36
|
+
// alone), the official Python client (`turbopuffer` on PyPI), and the TURBOPUFFER_ env stem
|
|
37
|
+
// (TURBOPUFFER_API_KEY / _REGION / _BASE_URL, all read by the SDK in client.ts).
|
|
38
|
+
adoption: {
|
|
39
|
+
sdks: ['@turbopuffer/turbopuffer'],
|
|
40
|
+
pypi: ['turbopuffer'],
|
|
41
|
+
scopes: ['@turbopuffer/'],
|
|
42
|
+
envStems: ['TURBOPUFFER'],
|
|
43
|
+
},
|
|
44
|
+
// INTERCEPTION — the SDK's default base URL is `https://{region}.turbopuffer.com`
|
|
45
|
+
// (client.ts:273), the region filled from the `region` option or TURBOPUFFER_REGION: regional
|
|
46
|
+
// hosts such as aws-us-east-1.turbopuffer.com and gcp-us-central1.turbopuffer.com.
|
|
47
|
+
hosts: [{ hostPattern: '^(?:aws|gcp|azure)-[a-z0-9-]+\\.turbopuffer\\.com$' },
|
|
48
|
+
// the dashboard's sign-in and API keys pages and the World's sign-up door (screens/dashboard.tsx); the rest of
|
|
49
|
+
// turbopuffer.com (its site and docs) is left alone
|
|
50
|
+
{ host: 'turbopuffer.com', pathPattern: '^/(login|dashboard|_twin/users)(/|$)' },
|
|
51
|
+
],
|
|
52
|
+
// WORLD WIRING — under Node the SDK sends through undici's `Agent.request`
|
|
53
|
+
// (internal/custom/fetch-node.ts, selected by the package's `#fetch` import map for the `node`
|
|
54
|
+
// condition), which neither the injector's http/https/fetch patches nor HTTPS_PROXY reach. The
|
|
55
|
+
// SDK's own `TURBOPUFFER_BASE_URL` (client.ts:253) is the interception. It must carry the
|
|
56
|
+
// `{region}` placeholder: a client that passes `region` (Dub passes "aws-us-east-1") throws
|
|
57
|
+
// "region is set, but would be ignored" against a base URL without one (client.ts:282-285). The
|
|
58
|
+
// twin accepts and ignores that leading region segment.
|
|
59
|
+
endpointEnv: {
|
|
60
|
+
name: 'TURBOPUFFER_TWIN_URL',
|
|
61
|
+
templates: { TURBOPUFFER_BASE_URL: '${url}/{region}' },
|
|
62
|
+
note: 'grounded in @turbopuffer/turbopuffer@2.8.0 src/client.ts:253-288 (TURBOPUFFER_BASE_URL, {region} placeholder substitution) and internal/custom/fetch-node.ts (undici Agent.request under node, outside the injector); the injector also claims the regional *.turbopuffer.com hosts for fetch-based runtimes.',
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
registerPack(pack);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The API key gate, in front of the derived dispatch. "The HTTP API expects the API key to be formatted as a standard
|
|
2
|
+
// Bearer token and passed in the Authorization header", and keys are made and expired on the dashboard
|
|
3
|
+
// (https://turbopuffer.com/docs/auth; screens/dashboard.tsx).
|
|
4
|
+
//
|
|
5
|
+
// What the gate refuses, and where turbopuffer's documentation stops:
|
|
6
|
+
// - a key the dashboard made and then expired, and a key of turbopuffer's form (`tpuf_…`) the dashboard never made:
|
|
7
|
+
// 401, the twin's reading. turbopuffer's pages print only the error body (https://turbopuffer.com/docs/api-overview)
|
|
8
|
+
// and name no status for a bad key; 401 is the status turbopuffer's own client reads as a failed authentication
|
|
9
|
+
// (`if (status === 401) return new AuthenticationError(...)`, https://raw.githubusercontent.com/turbopuffer/turbopuffer-typescript/v2.8.0/src/core/error.ts).
|
|
10
|
+
// - a key without the permission an operation needs, only where turbopuffer says which: listing namespaces "is available
|
|
11
|
+
// to API keys with list or admin permissions" (https://turbopuffer.com/docs/namespaces). 403, the twin's reading, by
|
|
12
|
+
// the same client line's neighbour (`if (status === 403) return new PermissionDeniedError(...)`); no page prints the
|
|
13
|
+
// answer for a key that lacks a permission. The messages are the twin's.
|
|
14
|
+
// Every other operation admits any live key: the docs name read/write permissions without saying which endpoint needs
|
|
15
|
+
// which, so the twin enforces none of them (manifest.ts records the gap).
|
|
16
|
+
// A key that is not of turbopuffer's form is the World's own (a World pointing an application at the twin with a key
|
|
17
|
+
// of its choosing) and is not checked here; the request handler still refuses a request with no key (401).
|
|
18
|
+
import { createHash } from 'node:crypto';
|
|
19
|
+
const refuse = (status, error) => Response.json({ status: 'error', error }, { status });
|
|
20
|
+
/** Operations whose permission turbopuffer documents, and the permissions that admit a key to each. */
|
|
21
|
+
const NEEDS = { get_v1_namespaces: ['list', 'admin'] };
|
|
22
|
+
/** The gate's answer for a request to `operation`, or undefined when it may pass. */
|
|
23
|
+
export function keyGate(ctx, request, operation) {
|
|
24
|
+
const m = /^bearer\s+(\S+)\s*$/i.exec(request.headers.get('authorization') ?? '');
|
|
25
|
+
const key = m?.[1];
|
|
26
|
+
if (!key || !key.startsWith('tpuf_'))
|
|
27
|
+
return undefined;
|
|
28
|
+
const sha = createHash('sha256').update(key).digest('hex');
|
|
29
|
+
const held = ctx.rowsRaw('_api_key').find((k) => k.key_sha256 === sha);
|
|
30
|
+
if (!held)
|
|
31
|
+
return refuse(401, 'unauthorized: the API key is not valid');
|
|
32
|
+
if (held.expired_at)
|
|
33
|
+
return refuse(401, 'unauthorized: the API key has expired');
|
|
34
|
+
const needs = NEEDS[operation];
|
|
35
|
+
const grants = Array.isArray(held.grants) ? held.grants : [];
|
|
36
|
+
if (needs && !needs.some((g) => grants.includes(g)))
|
|
37
|
+
return refuse(403, `forbidden: this API key needs the ${needs.join(' or ')} permission`);
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const manifest = {
|
|
2
|
+
vendor: 'turbopuffer',
|
|
3
|
+
service: 'turbopuffer',
|
|
4
|
+
body: {},
|
|
5
|
+
// the core mints no id (it owns no operation); a document's id is the caller's
|
|
6
|
+
ids: { template: '{prefix}_{n}' },
|
|
7
|
+
time: 'iso',
|
|
8
|
+
error: { status: 'error', error: '{message}' },
|
|
9
|
+
readOnly: { status: 405, message: 'read_only: this twin was started read-only; writes are refused' },
|
|
10
|
+
malformedBody: { status: 400, message: 'invalid request: body is not valid JSON' },
|
|
11
|
+
notFound: { status: 404, message: 'not found' },
|
|
12
|
+
// GET /v1/namespaces answers `{namespaces, next_cursor}`, paged by `cursor` and `page_size`
|
|
13
|
+
// (https://turbopuffer.com/docs/namespaces); the handler answers it. Required by the type; the core lists nothing.
|
|
14
|
+
list: { style: 'envelope', envelope: { namespaces: '{data}' }, limit: { param: 'page_size', default: 100, max: 1000 } },
|
|
15
|
+
deleted: {},
|
|
16
|
+
// turbopuffer's dashboard (https://turbopuffer.com/docs/auth: "You can create and expire tokens in the dashboard"):
|
|
17
|
+
// its sign-in, and the page where an organization's API keys are made and expired (screens/dashboard.tsx)
|
|
18
|
+
screens: [{
|
|
19
|
+
id: 'login', kind: 'flow', host: 'turbopuffer.com', path: '/login',
|
|
20
|
+
demand: 'every dashboard page asks who is signed in', status: 'done',
|
|
21
|
+
controls: ['Email', 'Password', 'Continue'], source: 'https://turbopuffer.com/docs/auth',
|
|
22
|
+
}, {
|
|
23
|
+
id: 'api-keys', kind: 'workspace', host: 'turbopuffer.com', path: '/dashboard/api-keys',
|
|
24
|
+
demand: 'every API key a customer uses is made here, and expired here when it is rotated or the customer leaves', status: 'done',
|
|
25
|
+
controls: ['Name', 'Read', 'Write', 'List', 'Admin', 'Create API key', 'Expire'], source: 'https://turbopuffer.com/docs/auth',
|
|
26
|
+
}],
|
|
27
|
+
resources: {},
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SemanticsContext } from '@volter/world-core';
|
|
2
|
+
export declare const DASHBOARD_HOST = "turbopuffer.com";
|
|
3
|
+
export declare const GRANTS: readonly ["read", "write", "list", "admin"];
|
|
4
|
+
export type Grant = (typeof GRANTS)[number];
|
|
5
|
+
type Row = Record<string, unknown>;
|
|
6
|
+
/** The organization's live and expired keys, oldest first. */
|
|
7
|
+
export declare function keysOf(ctx: SemanticsContext, organization: string): Row[];
|
|
8
|
+
/** turbopuffer.com's pages and the World's sign-up door, or undefined for any other path. `contextFor` gives the
|
|
9
|
+
* pack's semantics context for a request. */
|
|
10
|
+
export declare function dashboard(request: Request, contextFor: (request: Request) => Promise<SemanticsContext>): Promise<Response | undefined>;
|
|
11
|
+
export {};
|