@volter/twin-upstash 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.
Files changed (162) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +202 -0
  3. package/api/src/fetch.ts +54 -0
  4. package/api/src/generated/surface.gen.json +1 -0
  5. package/api/src/generated/ui.gen.json +1 -0
  6. package/api/src/index.ts +19 -0
  7. package/api/src/key-gate.ts +30 -0
  8. package/api/src/manifest.ts +103 -0
  9. package/api/src/screens/developer-api.tsx +106 -0
  10. package/api/src/screens/qstash.tsx +99 -0
  11. package/api/src/screens/session.tsx +125 -0
  12. package/api/src/screens/teams.tsx +114 -0
  13. package/api/src/semantics/backups.ts +90 -0
  14. package/api/src/semantics/index.ts +191 -0
  15. package/api/src/semantics/shared.ts +42 -0
  16. package/api/src/semantics/teams.ts +108 -0
  17. package/api/src/semantics/time.ts +40 -0
  18. package/dist/api/src/fetch.d.ts +15 -0
  19. package/dist/api/src/fetch.js +44 -0
  20. package/dist/api/src/fetch.ts +54 -0
  21. package/dist/api/src/generated/surface.gen.json +1 -0
  22. package/dist/api/src/generated/ui.gen.json +1 -0
  23. package/dist/api/src/index.ts +19 -0
  24. package/dist/api/src/key-gate.d.ts +3 -0
  25. package/dist/api/src/key-gate.js +30 -0
  26. package/dist/api/src/key-gate.ts +30 -0
  27. package/dist/api/src/manifest.d.ts +2 -0
  28. package/dist/api/src/manifest.js +81 -0
  29. package/dist/api/src/manifest.ts +103 -0
  30. package/dist/api/src/screens/developer-api.d.ts +3 -0
  31. package/dist/api/src/screens/developer-api.js +101 -0
  32. package/dist/api/src/screens/developer-api.tsx +106 -0
  33. package/dist/api/src/screens/qstash.d.ts +3 -0
  34. package/dist/api/src/screens/qstash.js +92 -0
  35. package/dist/api/src/screens/qstash.tsx +99 -0
  36. package/dist/api/src/screens/session.d.ts +9 -0
  37. package/dist/api/src/screens/session.js +118 -0
  38. package/dist/api/src/screens/session.tsx +125 -0
  39. package/dist/api/src/screens/teams.d.ts +3 -0
  40. package/dist/api/src/screens/teams.js +99 -0
  41. package/dist/api/src/screens/teams.tsx +114 -0
  42. package/dist/api/src/semantics/backups.d.ts +7 -0
  43. package/dist/api/src/semantics/backups.js +75 -0
  44. package/dist/api/src/semantics/backups.ts +90 -0
  45. package/dist/api/src/semantics/index.d.ts +10 -0
  46. package/dist/api/src/semantics/index.js +191 -0
  47. package/dist/api/src/semantics/index.ts +191 -0
  48. package/dist/api/src/semantics/shared.d.ts +21 -0
  49. package/dist/api/src/semantics/shared.js +34 -0
  50. package/dist/api/src/semantics/shared.ts +42 -0
  51. package/dist/api/src/semantics/teams.d.ts +13 -0
  52. package/dist/api/src/semantics/teams.js +100 -0
  53. package/dist/api/src/semantics/teams.ts +108 -0
  54. package/dist/api/src/semantics/time.d.ts +2 -0
  55. package/dist/api/src/semantics/time.js +34 -0
  56. package/dist/api/src/semantics/time.ts +40 -0
  57. package/dist/qstash/src/doors.d.ts +6 -0
  58. package/dist/qstash/src/doors.js +33 -0
  59. package/dist/qstash/src/doors.ts +51 -0
  60. package/dist/qstash/src/egress.d.ts +7 -0
  61. package/dist/qstash/src/egress.js +66 -0
  62. package/dist/qstash/src/egress.ts +58 -0
  63. package/dist/qstash/src/fetch.d.ts +7 -0
  64. package/dist/qstash/src/fetch.js +48 -0
  65. package/dist/qstash/src/fetch.ts +46 -0
  66. package/dist/qstash/src/generated/surface.gen.json +1 -0
  67. package/dist/qstash/src/generated/ui.gen.json +1 -0
  68. package/dist/qstash/src/index.ts +35 -0
  69. package/dist/qstash/src/manifest.d.ts +10 -0
  70. package/dist/qstash/src/manifest.js +105 -0
  71. package/dist/qstash/src/manifest.ts +134 -0
  72. package/dist/qstash/src/semantics/account.d.ts +29 -0
  73. package/dist/qstash/src/semantics/account.js +91 -0
  74. package/dist/qstash/src/semantics/account.ts +98 -0
  75. package/dist/qstash/src/semantics/delivery.d.ts +17 -0
  76. package/dist/qstash/src/semantics/delivery.js +274 -0
  77. package/dist/qstash/src/semantics/delivery.ts +264 -0
  78. package/dist/qstash/src/semantics/dlq.d.ts +4 -0
  79. package/dist/qstash/src/semantics/dlq.js +51 -0
  80. package/dist/qstash/src/semantics/dlq.ts +61 -0
  81. package/dist/qstash/src/semantics/index.d.ts +2 -0
  82. package/dist/qstash/src/semantics/index.js +10 -0
  83. package/dist/qstash/src/semantics/index.ts +13 -0
  84. package/dist/qstash/src/semantics/keys.d.ts +2 -0
  85. package/dist/qstash/src/semantics/keys.js +9 -0
  86. package/dist/qstash/src/semantics/keys.ts +14 -0
  87. package/dist/qstash/src/semantics/messages.d.ts +74 -0
  88. package/dist/qstash/src/semantics/messages.js +233 -0
  89. package/dist/qstash/src/semantics/messages.ts +249 -0
  90. package/dist/qstash/src/semantics/queues.d.ts +2 -0
  91. package/dist/qstash/src/semantics/queues.js +60 -0
  92. package/dist/qstash/src/semantics/queues.ts +66 -0
  93. package/dist/qstash/src/semantics/schedules.d.ts +19 -0
  94. package/dist/qstash/src/semantics/schedules.js +125 -0
  95. package/dist/qstash/src/semantics/schedules.ts +132 -0
  96. package/dist/qstash/src/semantics/shared.d.ts +45 -0
  97. package/dist/qstash/src/semantics/shared.js +115 -0
  98. package/dist/qstash/src/semantics/shared.ts +121 -0
  99. package/dist/qstash/src/semantics/urlgroups.d.ts +2 -0
  100. package/dist/qstash/src/semantics/urlgroups.js +58 -0
  101. package/dist/qstash/src/semantics/urlgroups.ts +69 -0
  102. package/dist/qstash/src/semantics/workflows.d.ts +44 -0
  103. package/dist/qstash/src/semantics/workflows.js +379 -0
  104. package/dist/qstash/src/semantics/workflows.ts +401 -0
  105. package/dist/qstash/src/signing.d.ts +4 -0
  106. package/dist/qstash/src/signing.js +16 -0
  107. package/dist/qstash/src/signing.ts +19 -0
  108. package/dist/src/cli.d.ts +2 -0
  109. package/dist/src/cli.js +35 -0
  110. package/dist/src/generated/surface.gen.json +1 -0
  111. package/dist/src/index.d.ts +18 -0
  112. package/dist/src/index.js +124 -0
  113. package/dist/src/manifest.d.ts +14 -0
  114. package/dist/src/manifest.js +8 -0
  115. package/dist/src/upstash-budget.d.ts +85 -0
  116. package/dist/src/upstash-budget.js +440 -0
  117. package/dist/src/upstash-capabilities.d.ts +4 -0
  118. package/dist/src/upstash-capabilities.js +1286 -0
  119. package/dist/src/upstash-conformance.d.ts +7 -0
  120. package/dist/src/upstash-conformance.js +119 -0
  121. package/dist/src/upstash-connector.d.ts +115 -0
  122. package/dist/src/upstash-connector.js +309 -0
  123. package/dist/src/upstash-lua.d.ts +140 -0
  124. package/dist/src/upstash-lua.js +1229 -0
  125. package/dist/src/upstash-server.d.ts +29 -0
  126. package/dist/src/upstash-server.js +81 -0
  127. package/dist/src/upstash-store.d.ts +114 -0
  128. package/dist/src/upstash-store.js +1663 -0
  129. package/dist/src/upstash-twin.d.ts +73 -0
  130. package/dist/src/upstash-twin.js +437 -0
  131. package/package.json +59 -0
  132. package/qstash/src/doors.ts +51 -0
  133. package/qstash/src/egress.ts +58 -0
  134. package/qstash/src/fetch.ts +46 -0
  135. package/qstash/src/generated/surface.gen.json +1 -0
  136. package/qstash/src/generated/ui.gen.json +1 -0
  137. package/qstash/src/index.ts +35 -0
  138. package/qstash/src/manifest.ts +134 -0
  139. package/qstash/src/semantics/account.ts +98 -0
  140. package/qstash/src/semantics/delivery.ts +264 -0
  141. package/qstash/src/semantics/dlq.ts +61 -0
  142. package/qstash/src/semantics/index.ts +13 -0
  143. package/qstash/src/semantics/keys.ts +14 -0
  144. package/qstash/src/semantics/messages.ts +249 -0
  145. package/qstash/src/semantics/queues.ts +66 -0
  146. package/qstash/src/semantics/schedules.ts +132 -0
  147. package/qstash/src/semantics/shared.ts +121 -0
  148. package/qstash/src/semantics/urlgroups.ts +69 -0
  149. package/qstash/src/semantics/workflows.ts +401 -0
  150. package/qstash/src/signing.ts +19 -0
  151. package/src/cli.ts +36 -0
  152. package/src/generated/surface.gen.json +1 -0
  153. package/src/index.ts +203 -0
  154. package/src/manifest.ts +26 -0
  155. package/src/upstash-budget.ts +486 -0
  156. package/src/upstash-capabilities.ts +1418 -0
  157. package/src/upstash-conformance.ts +131 -0
  158. package/src/upstash-connector.ts +340 -0
  159. package/src/upstash-lua.ts +1120 -0
  160. package/src/upstash-server.ts +103 -0
  161. package/src/upstash-store.ts +1437 -0
  162. package/src/upstash-twin.ts +465 -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,202 @@
1
+ # @volter/twin-upstash
2
+
3
+ A local **Upstash Redis** twin: a real, stateful Redis served over Upstash's REST protocol, built on
4
+ the shared `@volter/world-core` kernel.
5
+
6
+ Point the unmodified `@upstash/redis` SDK at it with nothing but its own `url` option and it works —
7
+ including `@upstash/ratelimit` layered on top, which genuinely enforces a limit because this twin
8
+ **runs its Lua**, rather than recognising it.
9
+
10
+ ```bash
11
+ bun packages/twin/upstash/src/cli.ts serve --port 8079
12
+ # then, in your app:
13
+ # UPSTASH_REDIS_REST_URL=http://127.0.0.1:8079
14
+ # UPSTASH_REDIS_REST_TOKEN=any-non-empty-token
15
+ ```
16
+
17
+ ## It is a Redis, not a shape-matcher
18
+
19
+ `GET` returns what `SET` actually wrote. `INCR` on `"abc"` raises the vendor's own
20
+ `ERR value is not an integer or out of range`. `LPUSH` against a string raises `WRONGTYPE`. A key
21
+ with a TTL stops existing — for `GET`, `EXISTS`, `TTL`, `TYPE`, `KEYS` and `DBSIZE` at once — once
22
+ the request clock passes its deadline. Strings, counters, hashes, sets, sorted sets, lists and
23
+ streams are all modeled with their real semantics, and every key is one kernel subject, so state
24
+ survives a restart against the same root.
25
+
26
+ The one place this matters most: **`SET … NX` on an existing key answers `null`, not `"OK"`.** The
27
+ real consumer this pack was grounded against (`dub`) branches on `res === null` in a dozen
28
+ distributed-lock and dedupe paths; a twin that answered `"OK"` would turn every one of them into a
29
+ silent no-op.
30
+
31
+ ## `EVAL` runs a Lua interpreter
32
+
33
+ `upstash-lua.ts` is a tokenizer, parser and evaluator for the Lua subset real Redis scripts use.
34
+ It was a deliberate choice over the cheaper alternative — recognising known script SHA1s and
35
+ dispatching to hand-written TypeScript — because recognition is a fake-success generator: it passes
36
+ for the exact bytes it memorised and silently mis-answers anything one character different, and the
37
+ whole point of `EVAL` is that the caller supplies the program.
38
+
39
+ So `@upstash/ratelimit`'s fixed-window, sliding-window and token-bucket scripts run **verbatim**, and
40
+ nothing about them is special-cased anywhere in this pack. Their SHA1s are used only the way real
41
+ Redis uses them: `EVALSHA` first, `NOSCRIPT No matching script. Please use EVAL.` on a miss, then
42
+ `EVAL`, then cached. (That error string is load-bearing — the SDK's `safeEval` greps for it to
43
+ decide whether to retry.)
44
+
45
+ Supported: locals, `if`/`elseif`/`else`, numeric and generic `for`, `while`, `repeat`/`until`,
46
+ `break`, tables, closures, the full Lua 5.1 operator set, and the `math`/`table`/`string`/`redis`
47
+ library subset scripts actually reach for. **Unsupported constructs fail loudly by name** —
48
+ `cjson`, `goto`, metatables, coroutines and Lua *patterns* in `string.find`/`gsub` each raise an
49
+ error saying so, rather than being quietly mis-evaluated.
50
+
51
+ The interpreter follows Lua, not JavaScript, where the two differ and it matters:
52
+
53
+ - `==` does **not** coerce across types, so `"3" == 3` is false. This is faithful to a real quirk:
54
+ `@upstash/ratelimit`'s `cachedFixedWindow` script compares a number against a raw `ARGV` string,
55
+ which never matches on real Redis either. Coercing would make this twin *more* correct than the
56
+ vendor and hide the caller's actual behaviour.
57
+ - Only `nil` and `false` are falsy — `0` and `""` are true.
58
+ - A nil bulk reply becomes Lua `false`; a Lua number returned to Redis is truncated toward zero; an
59
+ array reply stops at the first nil.
60
+ - `%` takes the sign of the divisor.
61
+
62
+ A script is **atomic**: one that raises part-way leaves nothing behind, including the writes it had
63
+ already made.
64
+
65
+ ## The REST protocol, including the parts that bite
66
+
67
+ Five request forms, all served:
68
+
69
+ | | |
70
+ |---|---|
71
+ | `POST /` | the whole command as a JSON array — `["SET","k","v","EX",100]` |
72
+ | `GET\|POST\|PUT\|HEAD /CMD/arg/…` | path-style, args percent-decoded, command name case-insensitive |
73
+ | `POST /set/k?EX=100` | the raw body becomes the last argument; query params become option tokens |
74
+ | `POST /pipeline` | an array of command arrays, non-atomic |
75
+ | `POST /multi-exec` | the same shape, as a transaction |
76
+
77
+ Three details that a naive twin gets wrong and that break the real SDK:
78
+
79
+ 1. **`/pipeline` is not optional.** `@upstash/redis` has `enableAutoPipelining: true` *by default*,
80
+ so a plain `await redis.get("k")` arrives at `POST /pipeline` with body `[["get","k"]]` — not at
81
+ `POST /`. A twin serving only `POST /` fails against a default-configured client.
82
+ 2. **A command error is HTTP 400, not 200.** The SDK has two error paths, and only the `!res.ok` one
83
+ appends its `, command was: […]` suffix. Serving 200 silently changes the error text every
84
+ consumer's tests assert on.
85
+ 3. **`Upstash-Encoding: base64` is on by default**, and its rule is subtler than the docs say: every
86
+ string in `result` is encoded at any array depth *except* the simple-**status** reply `OK`. A
87
+ bulk string whose value happens to be `"OK"` **is** encoded (`T0s=`), and `PING`'s status `PONG`
88
+ is encoded too. Getting this wrong is invisible in a curl session and catastrophic through the
89
+ SDK, whose `base64decode` swallows failures and returns its input — so an unencoded `"PONG"`
90
+ (valid base64!) decodes to mojibake instead of erroring.
91
+
92
+ Error semantics were probed rather than assumed. A **runtime** error (`WRONGTYPE`, a bad integer) is
93
+ reported per-item at HTTP 200 and does **not** abort — not in a pipeline and, contrary to intuition,
94
+ not in `/multi-exec` either, because Upstash's own docs say "all commands will be executed …
95
+ same semantics with Redis". A **queue-time** fault (an unavailable command, a bad arity) discards
96
+ the whole batch pre-execution at HTTP 400, with the transaction endpoint answering `EXECABORT …` or
97
+ `… at index N, discarding transaction`.
98
+
99
+ Auth accepts `Authorization: Bearer <t>`, a bare `Authorization: <t>` (undocumented but real), and
100
+ `?_token=`. A missing or wrong credential answers the vendor's literal 401 body:
101
+ `WRONGPASS invalid or missing auth token. See …`. Pass `--token` to make the twin demand a specific
102
+ one; omit it and any non-empty credential is accepted (a missing one is still refused).
103
+
104
+ ## Time is injected, never read from the wall
105
+
106
+ TTL expiry, rate-limit windows and stream ids all need a clock, and this repo forbids `Date.now()`
107
+ inside twin behaviour — a verify has to be bit-reproducible. So every time-dependent behaviour is
108
+ measured against **the request's own `occurredAt`**, the same timestamp the kernel stamps its action
109
+ with. A verify pins it and gets deterministic TTL arithmetic; to test *expiry* it issues the next
110
+ request with a later pinned instant, which is a clock advance expressed as data.
111
+ `createUpstashRedisTwinServer({ now })` exposes the same seam over HTTP, which is how the SDK
112
+ fidelity test proves a rate-limit window rolls over without racing anything.
113
+
114
+ Expiration is **lazy**, exactly like Redis: an expired key is not swept, it simply stops being
115
+ visible to every read at once.
116
+
117
+ ## Coverage
118
+
119
+ **Partial and honest.** The capability manifest (`upstash-capabilities.ts`) is the *real vendor
120
+ surface* as the denominator — enumerated top-down from Redis's own command groups as Upstash
121
+ supports them (string, bitmap, hash, list, set, sorted-set, HyperLogLog, geo, stream, JSON, pub/sub,
122
+ scripting, generic, server, transactions, connection) crossed with the REST protocol's own surface —
123
+ not a list of what was built. Whole families this twin has **not** built appear as `todo`s rather
124
+ than being left out of the count:
125
+
126
+ - **RedisJSON** (`JSON.SET`/`GET`/`ARRAPPEND`/`NUMINCRBY`…), **bitmaps** (`SETBIT`/`BITCOUNT`/
127
+ `BITFIELD`), **HyperLogLog** (`PFADD`/`PFCOUNT`), **geo** (`GEOADD`/`GEOSEARCH`).
128
+ - **Pub/Sub**, including the two SSE endpoints (`POST /monitor`, `POST /subscribe/{channel}`).
129
+ - **Stream consumer groups** (`XGROUP`/`XREADGROUP`/`XACK`/`XCLAIM`), `XREAD`, and `XTRIM`/`MAXLEN`.
130
+ - Set algebra (`SINTER`/`SUNION`/`SDIFF`), sorted-set `BYLEX` and `*STORE`, list `LMOVE`/`LINSERT`,
131
+ `HSCAN`, per-field hash TTLs, `GETRANGE`/`SETRANGE`/`LCS`, `COPY`, `DUMP`/`RESTORE`, `INFO`,
132
+ `CONFIG`, Redis **Functions**, and the `cjson`/`bit`/`struct` Lua libraries.
133
+ - The `resp2` response format, and the quota refusals (`ERR max daily request limit exceeded` and
134
+ friends) — Upstash documents those error strings but publishes no figures, and the grounding pass
135
+ could not trigger them, so their HTTP status is **unverified** and nothing here claims one.
136
+
137
+ Two options are **refused by name** rather than accepted-and-ignored, because silently not doing what
138
+ was asked is the fake success this repo forbids: `ZRANGE … BYLEX` and `XADD … MAXLEN|MINID`.
139
+
140
+ ### No UI mirror
141
+
142
+ Upstash Redis is an **API-first** vendor: an integrator *calls* it from code, and the Upstash console
143
+ is a database-config and metrics dashboard for keys, plans and usage graphs — not where the work
144
+ happens, and not an agent navigation target. So this pack ships no mirror and has no UI capabilities;
145
+ coverage is API + connector. (`ui-scope.json` records the same decision, and the manifest test
146
+ asserts that no UI capability ever appears here.)
147
+
148
+ ### SDK versions
149
+
150
+ Pinned exactly, and driven unmodified in `upstash-sdk.integration.test.ts`:
151
+ `@upstash/redis@1.35.7` and `@upstash/ratelimit@2.0.8`. "Unmodified" means un-patched, not
152
+ un-configured — the only thing done to either is passing `url`/`token` through the SDK's own public
153
+ constructor, with every other default (`enableAutoPipelining`, `responseEncoding: "base64"`,
154
+ `automaticDeserialization`, `readYourWrites`) left alone.
155
+
156
+ ## Connector
157
+
158
+ `pull` is **handle-driven**: Redis has no cheap "give me everything" endpoint (`KEYS *` is O(N) and
159
+ Upstash's own docs warn against it on a production database), so `pullUpstashRedisKeys` pulls the
160
+ current real value of keys the caller *names*, dispatching per type and folding them through
161
+ the kernel observation path — so a re-pull of identical state appends zero deltas. A key the vendor does not have is
162
+ skipped, never invented as an empty one.
163
+
164
+ `pullUpstashRedisScan` exists for callers who want a walk, and takes a hard `limit`; it is
165
+ deliberately **not** wired into the sync entrypoint, because that would put an unbounded walk of a
166
+ production keyspace one call away.
167
+
168
+ `push` is a filed `todo`, and deliberately so: a blind write-back into a production *cache* is
169
+ destructive in a way a push to a ticket tracker is not, and the safe design (an explicit key
170
+ allowlist plus a dry-run diff) has not been settled.
171
+
172
+ ## Rate budget
173
+
174
+ Upstash publishes a real scalar and it is enormous — **10,000 commands/sec** on Free, Pay-As-You-Go
175
+ and every Fixed plan up to 50 GB. Taken at face value that would license 600,000 calls a minute,
176
+ which is not a guard.
177
+
178
+ The limit that actually binds a connector loop is the **quota**: 500,000 commands per *month* on the
179
+ free tier (~11.6/minute sustained), and per-command billing on PAYG where the docs are explicit that
180
+ "one command is one billable request" and that each command inside a pipeline is billed
181
+ individually. So the ceiling (600 units / 60s at weight 2 = **300 commands/minute**) is sized against
182
+ spend, not throttling: 2,000× tighter than the documented rate limit so it can never be what trips
183
+ the vendor's own limiter, loose enough for a few-hundred-key pull to finish in one window, and tight
184
+ enough that burning the free monthly quota would take ~28 hours of looping instead of 50 seconds.
185
+ `scan` costs 8 because its cost scales with the customer's keyspace rather than the request.
186
+
187
+ See `upstash-budget.ts`; the mechanism is the kernel's shared `RateBudget`, and this pack
188
+ supplies only the numbers plus the choke point every connector entrypoint applies unconditionally.
189
+
190
+ ## Grounding
191
+
192
+ Three independent sources, cross-checked — see `spec-sources.json` for the full citation:
193
+
194
+ 1. **Docs** — the REST API page, the Redis-compatibility matrix, the troubleshooting pages and the
195
+ billing table.
196
+ 2. **SDK source** — the actually-installed `@upstash/redis@1.35.7` and `@upstash/ratelimit@2.0.8`
197
+ packages, read rather than recalled. This is where auto-pipelining's default, the `keepTtl`
198
+ camelCase quirk, the `EVAL` argument order and the `NOSCRIPT` fallback came from.
199
+ 3. **Live probes** of a real ephemeral Upstash database. Every literal error string, status code and
200
+ encoding rule in this pack came off that server, and it corrected the docs in five places —
201
+ including the docs' own stale `"value is not an int"` example, the undocumented HTTP 413, and
202
+ `OPTIONS` answering 200 rather than 405.
@@ -0,0 +1,54 @@
1
+ // The Developer API lane of the upstash pack (`api.upstash.com/v2`), as a plain fetch: the pack's router
2
+ // (../../src/upstash-server.ts) sends every request for api.upstash.com here, and every one for
3
+ // console.upstash.com (its sign-in, the Account > Developer API tab, Account > Teams and a team invitation's link, and the
4
+ // QStash page, screens/). What the World clock has made due is caught up first (semantics/time.ts). The generated surface is Upstash's own
5
+ // OpenAPI document; the key gate sits in front of the dispatch (key-gate.ts), then the kernel's cross-cutting checks
6
+ // (read-only, a malformed body), then the handlers (semantics/). An operation this lane does not serve is the gap,
7
+ // answered 404 in the document's Error schema (the twin's decision: the document declares no error response).
8
+ import { bindSemantics, coreFor, createDerivedFetch, crossCutting, semanticsContext, type DerivedOperation, type DerivedOwner, type DerivedSurface } from '@volter/world-core';
9
+ import surface from './generated/surface.gen.json' with { type: 'json' };
10
+ import { manifest } from './manifest.ts';
11
+ import { apiSemantics } from './semantics/index.ts';
12
+ import { keyGate } from './key-gate.ts';
13
+ import { developerApiPage } from './screens/developer-api.tsx';
14
+ import { sessionFlow } from './screens/session.tsx';
15
+ import { qstashPage } from './screens/qstash.tsx';
16
+ import { teamsPages } from './screens/teams.tsx';
17
+ import { catchUp } from './semantics/time.ts';
18
+
19
+ const SCREEN: DerivedOperation = { id: 'DeveloperApiPage', method: 'POST', path: '/account/api', class: 'action' };
20
+ const GATE: DerivedOperation = { id: 'TwinKeyGate', method: 'GET', path: '/v2/redis/databases', class: 'retrieve' };
21
+
22
+ export const API_HOST = 'api.upstash.com';
23
+ export const CONSOLE_HOST = 'console.upstash.com';
24
+
25
+ /** The lane's fetch: a request, and the vendor host it was sent to (api.upstash.com or console.upstash.com). */
26
+ export type UpstashRedisApiFetch = ((request: Request, host: string) => Promise<Response>) & {
27
+ owners(): Record<string, DerivedOwner>;
28
+ /** What the World clock has made due (a daily backup, a backup completing), caught up for a request another wire of
29
+ * the pack answers: the REST API's write lands after the night's backup, never inside it. */
30
+ catchUp(request: Request): Promise<void>;
31
+ };
32
+
33
+ export function createUpstashApiLaneFetch(options: { root?: string; readOnly?: boolean; clock?: () => string } = {}): UpstashRedisApiFetch {
34
+ const scope = { ...(options.root !== undefined ? { root: options.root } : {}), ...(options.clock ? { clock: options.clock } : {}) };
35
+ const derived = createDerivedFetch({
36
+ surface: surface as DerivedSurface,
37
+ handlers: bindSemantics(manifest, apiSemantics, scope),
38
+ core: coreFor(manifest, scope),
39
+ around: crossCutting(manifest, { readOnly: options.readOnly ?? false, ...scope }),
40
+ gap: () => Response.json({ code: 'not_found', message: 'Not Found' }, { status: 404 }),
41
+ });
42
+ const contextFor = (request: Request) => semanticsContext(manifest, request, SCREEN, scope);
43
+ const due = async (request: Request): Promise<void> => { if (!options.readOnly) await catchUp(await contextFor(new Request(request.url))); };
44
+ return Object.assign(async (request: Request, host: string): Promise<Response> => {
45
+ await due(request);
46
+ if (host === CONSOLE_HOST) {
47
+ const screen = (await sessionFlow(request.clone(), await contextFor(new Request(request.url)))) ?? (await qstashPage(request.clone(), contextFor))
48
+ ?? (await teamsPages(request.clone(), contextFor)) ?? (await developerApiPage(request, contextFor));
49
+ return screen ?? new Response('Not Found', { status: 404, headers: { 'content-type': 'text/plain' } });
50
+ }
51
+ const ctx = await semanticsContext(manifest, new Request(request.url, { headers: request.headers }), GATE, scope);
52
+ return keyGate(ctx, request) ?? derived(request);
53
+ }, { owners: () => derived.owners(), catchUp: due });
54
+ }
@@ -0,0 +1 @@
1
+ {"generatedBy":"scripts/derive-pack.ts","spec":"openapi.yaml.gz","format":"openapi","version":"1.0.0","basePath":"/v2","resources":[{"name":"AuditLog","schema":"AuditLog","fields":[{"name":"action","type":"integer","nullable":false},{"name":"action_string","type":"string","nullable":false},{"name":"actor","type":"string","nullable":false},{"name":"customer_id","type":"string","nullable":false},{"name":"entity","type":"string","nullable":false},{"name":"ip","type":"string","nullable":false},{"name":"log_id","type":"string","nullable":false},{"name":"notes","type":"string","nullable":false},{"name":"readable_format","type":"string","nullable":false},{"name":"reason","type":"string","nullable":false},{"name":"secondary_entity","type":"string","nullable":false},{"name":"source","type":"string","nullable":false},{"name":"third_entity","type":"string","nullable":false},{"name":"timestamp","type":"integer","nullable":false},{"name":"ttl","type":"integer","nullable":false}],"stateCandidates":[],"expandable":[]},{"name":"Backup","schema":"Backup","fields":[{"name":"backup_id","type":"string","nullable":false},{"name":"backup_size","type":"integer","nullable":false},{"name":"creation_time","type":"integer","nullable":false},{"name":"customer_id","type":"string","nullable":false},{"name":"daily_backup","type":"string","nullable":false,"enum":["true","false"]},{"name":"database_id","type":"string","nullable":false},{"name":"hourly_backup","type":"string","nullable":false,"enum":["true","false"]},{"name":"internal_backup_tag","type":"string","nullable":false},{"name":"name","type":"string","nullable":false},{"name":"state","type":"string","nullable":false,"enum":["pending","completed","failed"]}],"stateCandidates":[{"field":"daily_backup","values":["false","true"]},{"field":"hourly_backup","values":["false","true"]},{"field":"state","values":["completed","failed","pending"]}],"expandable":[]},{"name":"Database","schema":"Database","fields":[{"name":"all_members","type":"array","nullable":false},{"name":"auto_upgrade","type":"boolean","nullable":false},{"name":"budget","type":"integer","nullable":false},{"name":"consistent","type":"boolean","nullable":false},{"name":"creation_time","type":"integer","nullable":false},{"name":"customer_id","type":"string","nullable":false},{"name":"daily_backup_enabled","type":"boolean","nullable":false},{"name":"database_id","type":"string","nullable":false},{"name":"database_name","type":"string","nullable":false},{"name":"db_acl_default_user_status","type":"string","nullable":false,"enum":["true","false"]},{"name":"db_acl_enabled","type":"string","nullable":false,"enum":["true","false"]},{"name":"db_conn_idle_timeout","type":"integer","nullable":false},{"name":"db_disk_threshold","type":"integer","nullable":false},{"name":"db_eviction","type":"boolean","nullable":false},{"name":"db_lua_credits_per_min","type":"integer","nullable":false},{"name":"db_lua_timeout","type":"integer","nullable":false},{"name":"db_max_clients","type":"integer","nullable":false},{"name":"db_max_commands_per_second","type":"integer","nullable":false},{"name":"db_max_entry_size","type":"integer","nullable":false},{"name":"db_max_loads_per_sec","type":"integer","nullable":false},{"name":"db_max_request_size","type":"integer","nullable":false},{"name":"db_memory_threshold","type":"integer","nullable":false},{"name":"db_request_limit","type":"integer","nullable":false},{"name":"db_resource_size","type":"string","nullable":false,"enum":["S","M","L","XL","XXL","3XL"]},{"name":"db_store_max_idle","type":"integer","nullable":false},{"name":"db_type","type":"string","nullable":false,"enum":["bolt","badger","pebble"]},{"name":"endpoint","type":"string","nullable":false},{"name":"eviction","type":"boolean","nullable":false},{"name":"last_plan_upgrade_time","type":"integer","nullable":false},{"name":"modifying_state","type":"string","nullable":false},{"name":"password","type":"string","nullable":false},{"name":"port","type":"integer","nullable":false},{"name":"primary_members","type":"array","nullable":false},{"name":"primary_region","type":"string","nullable":false,"enum":["us-east-1","us-east-2","us-west-1","us-west-2","ca-central-1","eu-central-1","eu-west-1","eu-west-2","sa-east-1","ap-south-1","ap-northeast-1","ap-southeast-1","ap-southeast-2","af-south-1","us-central1","us-east4","europe-west1","asia-northeast1"]},{"name":"prod_pack_enabled","type":"boolean","nullable":false},{"name":"prometheus_enabled","type":"string","nullable":false,"enum":["true","false"]},{"name":"read_only_rest_token","type":"string","nullable":false},{"name":"read_regions","type":"array","nullable":false},{"name":"region","type":"string","nullable":false,"enum":["global"]},{"name":"replicas","type":"integer","nullable":false},{"name":"rest_token","type":"string","nullable":false},{"name":"securityAddons","type":"object","nullable":false},{"name":"state","type":"string","nullable":false,"enum":["active","suspended","passive"]},{"name":"tls","type":"boolean","nullable":false},{"name":"type","type":"string","nullable":false,"enum":["free","payg","pro","paid"]}],"stateCandidates":[{"field":"db_acl_default_user_status","values":["false","true"]},{"field":"db_acl_enabled","values":["false","true"]},{"field":"db_resource_size","values":["3XL","L","M","S","XL","XXL"]},{"field":"db_type","values":["badger","bolt","pebble"]},{"field":"primary_region","values":["af-south-1","ap-northeast-1","ap-south-1","ap-southeast-1","ap-southeast-2","asia-northeast1","ca-central-1","eu-central-1","eu-west-1","eu-west-2","europe-west1","sa-east-1","us-central1","us-east-1","us-east-2","us-east4","us-west-1","us-west-2"]},{"field":"prometheus_enabled","values":["false","true"]},{"field":"state","values":["active","passive","suspended"]},{"field":"type","values":["free","paid","payg","pro"]}],"expandable":[]},{"name":"QStashUser","schema":"QStashUser","fields":[{"name":"active","type":"boolean","nullable":false},{"name":"budget","type":"integer","nullable":false},{"name":"created_by","type":"string","nullable":false},{"name":"creation_time","type":"integer","nullable":false},{"name":"customer_id","type":"string","nullable":false},{"name":"deletion_time","type":"integer","nullable":false},{"name":"enterprise","type":"object","nullable":false},{"name":"id","type":"string","nullable":false},{"name":"last_plan_upgrade_time","type":"integer","nullable":false},{"name":"max_bandwidth_per_second","type":"integer","nullable":false},{"name":"max_delay","type":"integer","nullable":false},{"name":"max_dlq_retention_time_milis","type":"integer","nullable":false},{"name":"max_dlq_size","type":"integer","nullable":false},{"name":"max_endpoints_per_topic","type":"integer","nullable":false},{"name":"max_events_size","type":"integer","nullable":false},{"name":"max_global_parallelism","type":"integer","nullable":false},{"name":"max_message_size","type":"integer","nullable":false},{"name":"max_parallelism","type":"integer","nullable":false},{"name":"max_queues","type":"integer","nullable":false},{"name":"max_requests_per_day","type":"integer","nullable":false},{"name":"max_requests_per_day_hard","type":"integer","nullable":false},{"name":"max_requests_per_second","type":"integer","nullable":false},{"name":"max_retries","type":"integer","nullable":false},{"name":"max_schedules","type":"integer","nullable":false},{"name":"max_topics","type":"integer","nullable":false},{"name":"modifying_state","type":"string","nullable":false},{"name":"prod_pack_enabled","type":"boolean","nullable":false},{"name":"prometheus_enabled","type":"string","nullable":false,"enum":["true","false"]},{"name":"read_only_token","type":"string","nullable":false},{"name":"region","type":"string","nullable":false,"enum":["eu-central-1","us-east-1"]},{"name":"reserved_price","type":"integer","nullable":false},{"name":"reserved_type","type":"string","nullable":false},{"name":"state","type":"string","nullable":false},{"name":"timeout","type":"integer","nullable":false},{"name":"token","type":"string","nullable":false},{"name":"type","type":"string","nullable":false,"enum":["free","paid"]}],"stateCandidates":[{"field":"active","values":["false","true"]},{"field":"prometheus_enabled","values":["false","true"]},{"field":"region","values":["eu-central-1","us-east-1"]},{"field":"state","values":[]},{"field":"type","values":["free","paid"]}],"expandable":[]},{"name":"SearchIndex","schema":"SearchIndex","fields":[{"name":"creation_time","type":"integer","nullable":false},{"name":"customer_id","type":"string","nullable":false},{"name":"endpoint","type":"string","nullable":false},{"name":"id","type":"string","nullable":false},{"name":"input_enrichment_enabled","type":"boolean","nullable":false},{"name":"max_daily_queries","type":"integer","nullable":false},{"name":"max_daily_updates","type":"integer","nullable":false},{"name":"max_monthly_bandwidth","type":"integer","nullable":false},{"name":"max_monthly_reranks","type":"integer","nullable":false},{"name":"max_query_per_second","type":"integer","nullable":false},{"name":"max_reads_per_request","type":"integer","nullable":false},{"name":"max_vector_count","type":"integer","nullable":false},{"name":"max_writes_per_request","type":"integer","nullable":false},{"name":"max_writes_per_second","type":"integer","nullable":false},{"name":"name","type":"string","nullable":false},{"name":"read_only_token","type":"string","nullable":false},{"name":"region","type":"string","nullable":false,"enum":["eu-west-1","us-central1"]},{"name":"throughput_vector","type":"array","nullable":false},{"name":"token","type":"string","nullable":false},{"name":"type","type":"string","nullable":false,"enum":["free","payg","fixed"]},{"name":"vercel_email","type":"string","nullable":false}],"stateCandidates":[{"field":"region","values":["eu-west-1","us-central1"]},{"field":"type","values":["fixed","free","payg"]}],"expandable":[]},{"name":"Team","schema":"Team","fields":[{"name":"copy_cc","type":"boolean","nullable":false},{"name":"team_id","type":"string","nullable":false},{"name":"team_name","type":"string","nullable":false}],"stateCandidates":[],"expandable":[]},{"name":"TeamMember","schema":"TeamMember","fields":[{"name":"copy_cc","type":"boolean","nullable":false},{"name":"member_email","type":"string","nullable":false},{"name":"member_role","type":"string","nullable":false,"enum":["owner","admin","dev","finance"]},{"name":"team_id","type":"string","nullable":false},{"name":"team_name","type":"string","nullable":false}],"stateCandidates":[{"field":"member_role","values":["admin","dev","finance","owner"]}],"expandable":[]},{"name":"VectorIndex","schema":"VectorIndex","fields":[{"name":"creation_time","type":"number","nullable":false},{"name":"customer_id","type":"string","nullable":false},{"name":"dimension_count","type":"number","nullable":false},{"name":"embedding_model","type":"string","nullable":false,"enum":["BGE_SMALL_EN_V1_5","BGE_BASE_EN_V1_5","BGE_LARGE_EN_V1_5","BGE_M3"]},{"name":"endpoint","type":"string","nullable":false},{"name":"id","type":"string","nullable":false},{"name":"index_type","type":"string","nullable":false,"enum":["DENSE","SPARSE","HYBRID"]},{"name":"max_daily_queries","type":"number","nullable":false},{"name":"max_daily_updates","type":"number","nullable":false},{"name":"max_monthly_bandwidth","type":"number","nullable":false},{"name":"max_query_per_second","type":"number","nullable":false},{"name":"max_reads_per_request","type":"number","nullable":false},{"name":"max_total_metadata_size","type":"number","nullable":false},{"name":"max_vector_count","type":"number","nullable":false},{"name":"max_writes_per_request","type":"number","nullable":false},{"name":"max_writes_per_second","type":"number","nullable":false},{"name":"name","type":"string","nullable":false},{"name":"read_only_token","type":"string","nullable":false},{"name":"region","type":"string","nullable":false,"enum":["eu-west-1","us-east-1","us-central1"]},{"name":"reserved_price","type":"number","nullable":false},{"name":"similarity_function","type":"string","nullable":false,"enum":["COSINE","EUCLIDEAN","DOT_PRODUCT"]},{"name":"sparse_embedding_model","type":"string","nullable":false,"enum":["BM25","BGE_M3"]},{"name":"throughput_vector","type":"array","nullable":false},{"name":"token","type":"string","nullable":false},{"name":"type","type":"string","nullable":false,"enum":["free","payg","fixed"]}],"stateCandidates":[{"field":"embedding_model","values":["BGE_BASE_EN_V1_5","BGE_LARGE_EN_V1_5","BGE_M3","BGE_SMALL_EN_V1_5"]},{"field":"index_type","values":["DENSE","HYBRID","SPARSE"]},{"field":"region","values":["eu-west-1","us-central1","us-east-1"]},{"field":"similarity_function","values":["COSINE","DOT_PRODUCT","EUCLIDEAN"]},{"field":"sparse_embedding_model","values":["BGE_M3","BM25"]},{"field":"type","values":["fixed","free","payg"]}],"expandable":[]}],"operations":[{"id":"listAuditLogs","method":"get","path":"/auditlogs","pathParams":[],"query":[],"basePath":"","body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"AuditLog","list":true},"class":"list","resource":"AuditLog"},{"id":"disableQStashProdPack","method":"post","path":"/qstash/disable-prodpack/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"non-resource"},{"id":"enableQStashProdPack","method":"post","path":"/qstash/enable-prodpack/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"non-resource"},{"id":"getQStashIPv4","method":"get","path":"/qstash/ipv4","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"},{"id":"moveQStashToTeam","method":"post","path":"/qstash/move-to-team","pathParams":[],"query":[],"body":[{"name":"qstash_id","type":"string","required":true},{"name":"target_team_id","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"resetQStashToken","method":"post","path":"/qstash/rotate-token/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"QStashUser","list":false},"class":"action","resource":"QStashUser"},{"id":"setQStashPlan","method":"post","path":"/qstash/set-plan/{id}","pathParams":["id"],"query":[],"body":[{"name":"plan_name","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"getQStashStats","method":"get","path":"/qstash/stats/{id}","pathParams":["id"],"query":[{"name":"period","type":"string","required":false}],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"},{"id":"updateQStashBudget","method":"patch","path":"/qstash/update-budget/{id}","pathParams":["id"],"query":[],"body":[{"name":"budget","type":"integer","required":true}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"getQStashUser","method":"get","path":"/qstash/user/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"QStashUser","list":false},"class":"retrieve","resource":"QStashUser"},{"id":"listQStashUsers","method":"get","path":"/qstash/users","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"QStashUser","list":true},"class":"list","resource":"QStashUser"},{"id":"changePlan","method":"post","path":"/redis/{id}/change-plan","pathParams":["id"],"query":[],"body":[{"name":"auto_upgrade","type":"boolean","required":false},{"name":"database_id","type":"string","required":false},{"name":"plan_name","type":"string","required":true},{"name":"prod_pack_enabled","type":"boolean","required":false}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"createBackup","method":"post","path":"/redis/create-backup/{id}","pathParams":["id"],"query":[],"body":[{"name":"name","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"createDatabase","method":"post","path":"/redis/database","pathParams":[],"query":[],"body":[{"name":"budget","type":"integer","required":false},{"name":"database_name","type":"string","required":true},{"name":"eviction","type":"boolean","required":false},{"name":"plan","type":"string","required":false},{"name":"platform","type":"string","required":false},{"name":"primary_region","type":"string","required":true},{"name":"read_regions","type":"array","required":false},{"name":"region","type":"string","required":false},{"name":"tls","type":"boolean","required":false}],"bodyEncoding":"json","successStatus":200,"answers":{"resource":"Database","list":false},"class":"create","resource":"Database"},{"id":"getDatabase","method":"get","path":"/redis/database/{id}","pathParams":["id"],"query":[{"name":"credentials","type":"string","required":false}],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"Database","list":false},"class":"retrieve","resource":"Database"},{"id":"deleteDatabase","method":"delete","path":"/redis/database/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"delete","resource":"Database"},{"id":"listDatabases","method":"get","path":"/redis/databases","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"Database","list":true},"class":"list","resource":"Database"},{"id":"deleteBackup","method":"delete","path":"/redis/delete-backup/{id}/{backup_id}","pathParams":["id","backup_id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"delete"},{"id":"disableAutoUpgrade","method":"post","path":"/redis/disable-autoupgrade/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"non-resource"},{"id":"disableDailyBackup","method":"patch","path":"/redis/disable-dailybackup/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"non-resource"},{"id":"disableEviction","method":"post","path":"/redis/disable-eviction/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"non-resource"},{"id":"enableAutoUpgrade","method":"post","path":"/redis/enable-autoupgrade/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"non-resource"},{"id":"enableDailyBackup","method":"patch","path":"/redis/enable-dailybackup/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"non-resource"},{"id":"enableEviction","method":"post","path":"/redis/enable-eviction/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"non-resource"},{"id":"enableTls","method":"post","path":"/redis/enable-tls/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"Database","list":false},"class":"action","resource":"Database"},{"id":"listBackup","method":"get","path":"/redis/list-backup/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"Backup","list":true},"class":"list","resource":"Backup"},{"id":"moveToTeam","method":"post","path":"/redis/move-to-team","pathParams":[],"query":[],"body":[{"name":"database_id","type":"string","required":true},{"name":"team_id","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"renameDatabase","method":"post","path":"/redis/rename/{id}","pathParams":["id"],"query":[],"body":[{"name":"name","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"answers":{"resource":"Database","list":false},"class":"action","resource":"Database"},{"id":"resetPassword","method":"post","path":"/redis/reset-password/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"Database","list":false},"class":"action","resource":"Database"},{"id":"restoreBackup","method":"post","path":"/redis/restore-backup/{id}","pathParams":["id"],"query":[],"body":[{"name":"backup_id","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"getDatabaseStats","method":"get","path":"/redis/stats/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"},{"id":"updateBudget","method":"patch","path":"/redis/update-budget/{id}","pathParams":["id"],"query":[],"body":[{"name":"budget","type":"integer","required":true}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"updateRegions","method":"post","path":"/redis/update-regions/{id}","pathParams":["id"],"query":[],"body":[{"name":"read_regions","type":"array","required":true}],"bodyEncoding":"json","successStatus":200,"class":"non-resource"},{"id":"listSearchIndexes","method":"get","path":"/search","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"SearchIndex","list":true},"class":"computed","resource":"SearchIndex"},{"id":"createSearchIndex","method":"post","path":"/search","pathParams":[],"query":[],"body":[{"name":"name","type":"string","required":true},{"name":"region","type":"string","required":true},{"name":"type","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"answers":{"resource":"SearchIndex","list":false},"class":"create","resource":"SearchIndex"},{"id":"getSearchIndex","method":"get","path":"/search/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"SearchIndex","list":false},"class":"retrieve","resource":"SearchIndex"},{"id":"deleteSearchIndex","method":"delete","path":"/search/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"delete","resource":"SearchIndex"},{"id":"renameSearchIndex","method":"post","path":"/search/{id}/rename","pathParams":["id"],"query":[],"body":[{"name":"name","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"action","resource":"SearchIndex"},{"id":"resetSearchPassword","method":"post","path":"/search/{id}/reset-password","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"action","resource":"SearchIndex"},{"id":"getSearchIndexStats","method":"get","path":"/search/{id}/stats","pathParams":["id"],"query":[{"name":"period","type":"string","required":false}],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed","resource":"SearchIndex"},{"id":"transferSearchIndex","method":"post","path":"/search/{id}/transfer","pathParams":["id"],"query":[],"body":[{"name":"target_account","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"action","resource":"SearchIndex"},{"id":"getGlobalSearchStats","method":"get","path":"/search/stats","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"},{"id":"createTeam","method":"post","path":"/team","pathParams":[],"query":[],"body":[{"name":"copy_cc","type":"boolean","required":true},{"name":"team_name","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"answers":{"resource":"Team","list":false},"class":"action","resource":"Team"},{"id":"deleteTeam","method":"delete","path":"/team/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"delete"},{"id":"listTeams","method":"get","path":"/teams","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"Team","list":true},"class":"list","resource":"Team"},{"id":"getTeamMembers","method":"get","path":"/teams/{team_id}","pathParams":["team_id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"TeamMember","list":true},"class":"list","resource":"TeamMember"},{"id":"addTeamMember","method":"post","path":"/teams/member","pathParams":[],"query":[],"body":[{"name":"member_email","type":"string","required":true},{"name":"member_role","type":"string","required":true},{"name":"team_id","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"answers":{"resource":"TeamMember","list":false},"class":"action","resource":"TeamMember"},{"id":"deleteTeamMember","method":"delete","path":"/teams/member","pathParams":[],"query":[],"body":[{"name":"member_email","type":"string","required":true},{"name":"team_id","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"action"},{"id":"listIndices","method":"get","path":"/vector/index","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"VectorIndex","list":true},"class":"list","resource":"VectorIndex"},{"id":"createIndex","method":"post","path":"/vector/index","pathParams":[],"query":[],"body":[{"name":"dimension_count","type":"number","required":true},{"name":"embedding_model","type":"string","required":false},{"name":"index_type","type":"string","required":false},{"name":"name","type":"string","required":true},{"name":"region","type":"string","required":true},{"name":"similarity_function","type":"string","required":true},{"name":"sparse_embedding_model","type":"string","required":false},{"name":"type","type":"string","required":false}],"bodyEncoding":"json","successStatus":200,"answers":{"resource":"VectorIndex","list":false},"class":"create","resource":"VectorIndex"},{"id":"getIndex","method":"get","path":"/vector/index/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"answers":{"resource":"VectorIndex","list":false},"class":"retrieve","resource":"VectorIndex"},{"id":"deleteIndex","method":"delete","path":"/vector/index/{id}","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"delete","resource":"VectorIndex"},{"id":"renameIndex","method":"post","path":"/vector/index/{id}/rename","pathParams":["id"],"query":[],"body":[{"name":"name","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"action","resource":"VectorIndex"},{"id":"resetIndexPasswords","method":"post","path":"/vector/index/{id}/reset-password","pathParams":["id"],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"action","resource":"VectorIndex"},{"id":"setIndexPlan","method":"post","path":"/vector/index/{id}/setplan","pathParams":["id"],"query":[],"body":[{"name":"target_plan","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"action","resource":"VectorIndex"},{"id":"getVectorIndexStats","method":"get","path":"/vector/index/{id}/stats","pathParams":["id"],"query":[{"name":"period","type":"string","required":false}],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed","resource":"VectorIndex"},{"id":"transferIndex","method":"post","path":"/vector/index/{id}/transfer","pathParams":["id"],"query":[],"body":[{"name":"target_account","type":"string","required":true}],"bodyEncoding":"json","successStatus":200,"class":"action","resource":"VectorIndex"},{"id":"getGlobalVectorStats","method":"get","path":"/vector/index/stats","pathParams":[],"query":[],"body":[],"bodyEncoding":"none","successStatus":200,"class":"computed"}]}
@@ -0,0 +1 @@
1
+ {"generatedBy":"scripts/derive-pack.ts","resources":{"Database":{"retrieve":"/v2/redis/database/{id}","create":{"path":"/v2/redis/database","encoding":"json","body":[{"name":"budget","type":"integer","required":false},{"name":"database_name","type":"string","required":true},{"name":"eviction","type":"boolean","required":false},{"name":"plan","type":"string","required":false},{"name":"platform","type":"string","required":false},{"name":"primary_region","type":"string","required":true},{"name":"read_regions","type":"array","required":false},{"name":"region","type":"string","required":false},{"name":"tls","type":"boolean","required":false}]},"actions":[],"states":{},"embeds":{}},"Backup":{"list":"/v2/redis/list-backup/{id}","actions":[],"states":{"state":["completed","pending"]},"embeds":{}},"Team":{"actions":[],"states":{},"embeds":{}},"TeamMember":{"actions":[],"states":{},"embeds":{}}}}
@@ -0,0 +1,19 @@
1
+ // The Developer API lane of the upstash pack (api.upstash.com and console.upstash.com), as a plain fetch: the whole pack's
2
+ // fetch (the Redis REST wire, the Developer API and the console's pages, and QStash), whose owners are the operations this
3
+ // lane serves. Its life walks through all of them: a customer makes its API keys on the console, makes and changes its
4
+ // databases, backups and team through the Developer API, and its game reads and writes the databases through the REST API
5
+ // and publishes through QStash (journeys/customer-life.outline.md).
6
+ import type { DerivedFetch } from '@volter/world-core';
7
+ import { createUpstashRedisTwinFetch } from '../../src/upstash-server.ts';
8
+ import { createUpstashApiLaneFetch } from './fetch.ts';
9
+
10
+ export { manifest } from './manifest.ts';
11
+ export { createUpstashApiLaneFetch, API_HOST, CONSOLE_HOST, type UpstashRedisApiFetch } from './fetch.ts';
12
+ // how a journey reads a REST answer sent with Upstash-Encoding: base64: the pack's own view (../../src/index.ts)
13
+ export { answerViews } from '../../src/index.ts';
14
+
15
+ export function createUpstashApiTwinFetch(options: { root?: string; readOnly?: boolean } = {}): DerivedFetch {
16
+ const lane = createUpstashApiLaneFetch(options);
17
+ const pack = createUpstashRedisTwinFetch({ ...(options.root !== undefined ? { root: options.root } : {}), ...(options.readOnly !== undefined ? { readOnly: options.readOnly } : {}) });
18
+ return Object.assign((request: Request) => pack(request), { owners: () => lane.owners() });
19
+ }
@@ -0,0 +1,30 @@
1
+ // The Developer API lane's key gate, in front of its dispatch. "Upstash API uses HTTP Basic authentication. You should
2
+ // pass EMAIL and API_KEY as basic authentication username and password respectively"
3
+ // (https://upstash.com/docs/devops/developer-api/authentication); a key is made on the console's Developer API tab with a
4
+ // name, a permission (Read/Write or Read Only) and an expiration (https://upstash.com/docs/devops/developer-api/introduction).
5
+ //
6
+ // The gate admits exactly an email and a key this lane issued, live and unexpired: a key made on the console's Developer
7
+ // API tab (screens/developer-api.tsx) or, for an account a World needs of its own, one the World issues through
8
+ // `POST /_twin/users/:email/api-key` (screens/session.tsx). Where the reference stops and the twin decides: anything
9
+ // else (no well-formed Basic credential, an email or key the lane never issued, a deleted or expired key) answers 401
10
+ // {code: unauthorized}; a Read Only key asking for anything but a read answers 403 {code: forbidden}.
11
+ import { createHash } from 'node:crypto';
12
+ import type { SemanticsContext } from '@volter/world-core';
13
+
14
+ const refuse = (status: number, code: string, message: string): Response => Response.json({ code, message }, { status });
15
+
16
+ /** The gate's answer for a request, or undefined when it may pass. */
17
+ export function keyGate(ctx: SemanticsContext, request: Request): Response | undefined {
18
+ const m = /^basic\s+(\S+)$/i.exec(request.headers.get('authorization') ?? '');
19
+ const decoded = m ? Buffer.from(m[1]!, 'base64').toString('utf8') : '';
20
+ const colon = decoded.indexOf(':');
21
+ if (colon <= 0) return refuse(401, 'unauthorized', 'Unauthorized: send EMAIL:API_KEY as HTTP Basic authentication');
22
+ const email = decoded.slice(0, colon).toLowerCase();
23
+ const key = decoded.slice(colon + 1);
24
+ const sha = createHash('sha256').update(key).digest('hex');
25
+ const held = ctx.rowsRaw('_api_key').find((k) => k.email === email && k.key_sha256 === sha && k.deleted !== true
26
+ && (k.expires_at === null || String(k.expires_at) > ctx.occurredAt));
27
+ if (!held) return refuse(401, 'unauthorized', 'Unauthorized: the API key is not valid');
28
+ if (held.permission === 'read_only' && request.method !== 'GET') return refuse(403, 'forbidden', 'Forbidden: this API key is Read Only');
29
+ return undefined;
30
+ }