@vite-hub/rate-limit 0.1.0 → 0.3.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/README.md +18 -14
- package/dist/cli-szm60zN5.d.ts +163 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +12 -26
- package/dist/{cloudflare-DUDRACVB.js → cloudflare-otBvOPv4.js} +5 -4
- package/dist/{counters-pKORpgGd.d.ts → counters-DXpF67J_.d.ts} +3 -3
- package/dist/{counters-wdEMxDEY.js → counters-DgVdHwdL.js} +13 -6
- package/dist/dev-peer-CHafxbtj.js +238 -0
- package/dist/drivers/cloudflare.d.ts +1 -1
- package/dist/drivers/cloudflare.js +1 -1
- package/dist/drivers/kv.d.ts +2 -0
- package/dist/drivers/kv.js +92 -0
- package/dist/drivers/memory.d.ts +1 -1
- package/dist/drivers/memory.js +5 -5
- package/dist/durability.d.ts +12 -0
- package/dist/durability.js +35 -0
- package/dist/error-diagnostics-MgAnhRTP.js +234 -0
- package/dist/index.d.ts +16 -7
- package/dist/index.js +108 -38
- package/dist/{inspect-D-FzyM_x.js → inspect-B6gTdgy9.js} +7 -1
- package/dist/kv-C1wpLulE.d.ts +29 -0
- package/dist/{limiter-DBrMI4vi.js → kv-provider-C1S6dRTR.js} +16 -9
- package/dist/{operations-tNUdj3G4.d.ts → operation-definition-8gOe-ubD.d.ts} +37 -15
- package/dist/operations-BYRa7wpx.js +1355 -0
- package/dist/{operations-Bu-xulNd.js → operations-CLI9w3rO.js} +9 -14
- package/dist/operations.d.ts +9 -4
- package/dist/operations.js +51 -23
- package/dist/runtime.d.ts +21 -3
- package/dist/runtime.js +2 -2
- package/dist/state-BU-zcLNY.js +89 -0
- package/dist/{types-CQEJpgtz.d.ts → types-CMyR1JeW.d.ts} +43 -23
- package/dist/vite.d.ts +131 -21
- package/dist/vite.js +349 -2479
- package/package.json +21 -17
- package/dist/cli-Cniq99iX.d.ts +0 -85
- package/dist/error-diagnostics-CTAC_bbr.js +0 -56
- package/dist/h3-v1-request-qoGwJr5-.js +0 -235
- package/dist/operations-B09NnEjT.js +0 -1438
- package/dist/state-Ct7zR8fD.js +0 -43
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
import { r as ViteHubCliPluginMetadata } from "./cli-
|
|
2
|
-
import {
|
|
3
|
-
import { n as OperationContributionEntry } from "./
|
|
1
|
+
import { r as ViteHubCliPluginMetadata } from "./cli-szm60zN5.js";
|
|
2
|
+
import { s as RateLimitDeclaration, y as RateLimitOptions } from "./types-CMyR1JeW.js";
|
|
3
|
+
import { n as OperationContributionEntry } from "./operation-definition-8gOe-ubD.js";
|
|
4
4
|
import { Plugin } from "vite";
|
|
5
|
+
//#region ../internal/src/durability.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
|
|
8
|
+
* imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
|
|
9
|
+
* `Durability` lines of `@vite-hub/runtime/durability`.
|
|
10
|
+
*/
|
|
11
|
+
interface DurabilityContribution {
|
|
12
|
+
/** The primitive that the reporter describes, such as `kv`. Other reporters find its result by this id. */
|
|
13
|
+
primitive: string;
|
|
14
|
+
/** The absolute file of the reporter module. */
|
|
15
|
+
module: string;
|
|
16
|
+
export: string;
|
|
17
|
+
/**
|
|
18
|
+
* The resolved configuration of the primitive, as plain JSON data. The build writes it into the server with
|
|
19
|
+
* `JSON.stringify`, so do not put credentials here.
|
|
20
|
+
*/
|
|
21
|
+
input: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** The `vitehub.durability` field of a primitive's Vite plugin. */
|
|
24
|
+
interface DurabilityPluginMetadata {
|
|
25
|
+
/** Called after Vite resolves the config. Return an empty list when the primitive is off. */
|
|
26
|
+
durability?: () => readonly DurabilityContribution[];
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
5
29
|
//#region ../internal/src/inspect.d.ts
|
|
6
30
|
interface ViteHubDefinitionField {
|
|
7
31
|
label: string;
|
|
@@ -28,9 +52,35 @@ interface ViteHubProviderOutputEntry {
|
|
|
28
52
|
/** Absolute path. */
|
|
29
53
|
path: string;
|
|
30
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
|
|
57
|
+
* The CLI sets `provider-output` when only a generated Wrangler config names the id.
|
|
58
|
+
*/
|
|
59
|
+
type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
|
|
60
|
+
/** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
|
|
61
|
+
interface ViteHubResourceSummary {
|
|
62
|
+
/** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
|
|
63
|
+
binding?: string;
|
|
64
|
+
/** Definition or store name. */
|
|
65
|
+
definition: string;
|
|
66
|
+
/** Env variable that supplied the id when `source` is `env`. */
|
|
67
|
+
env?: string;
|
|
68
|
+
host: "cloudflare" | "vercel";
|
|
69
|
+
id?: string;
|
|
70
|
+
/** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
|
|
71
|
+
kind: string;
|
|
72
|
+
/** Resource name on the host, when the config names it. */
|
|
73
|
+
name?: string;
|
|
74
|
+
/** Explains how the host finds the resource when no id or name is known locally. */
|
|
75
|
+
note?: string;
|
|
76
|
+
owner: string;
|
|
77
|
+
/** Absent when no id is known yet. */
|
|
78
|
+
source?: ViteHubResourceIdSource;
|
|
79
|
+
}
|
|
31
80
|
interface ViteHubInspectionContributor {
|
|
32
81
|
definitions?: readonly ViteHubDefinitionInspector[];
|
|
33
82
|
providerOutput?: readonly ViteHubProviderOutputEntry[];
|
|
83
|
+
resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
|
|
34
84
|
}
|
|
35
85
|
type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
|
|
36
86
|
interface ViteHubInspectionPluginMetadata {
|
|
@@ -38,10 +88,11 @@ interface ViteHubInspectionPluginMetadata {
|
|
|
38
88
|
}
|
|
39
89
|
//#endregion
|
|
40
90
|
//#region src/discovery.d.ts
|
|
41
|
-
|
|
91
|
+
interface RateLimitDiscoveryOptions {
|
|
42
92
|
rootDir: string;
|
|
43
93
|
scanDirs?: string[];
|
|
44
|
-
}
|
|
94
|
+
}
|
|
95
|
+
export declare function discoverRateLimitDeclarations(options: RateLimitDiscoveryOptions): RateLimitDeclaration[];
|
|
45
96
|
//#endregion
|
|
46
97
|
//#region ../internal/src/console.d.ts
|
|
47
98
|
type MaybePromise<T> = T | Promise<T>;
|
|
@@ -51,7 +102,15 @@ interface ViteHubConsoleDefinitionCatalogView {
|
|
|
51
102
|
/** States which runtime data this catalog does not include. */
|
|
52
103
|
notice: string;
|
|
53
104
|
}
|
|
105
|
+
/** Lists Workspace Definitions like a catalog, and browses the refs, revisions, and files of the selected one. */
|
|
106
|
+
interface ViteHubConsoleWorkspaceBrowserView {
|
|
107
|
+
kind: "workspace-browser";
|
|
108
|
+
/** States which runtime data the browser does not include. */
|
|
109
|
+
notice: string;
|
|
110
|
+
}
|
|
54
111
|
interface ViteHubConsoleRecordColumn {
|
|
112
|
+
/** Set it for a column with few values, such as a status. The Console then filters the table by its values. */
|
|
113
|
+
filter?: boolean;
|
|
55
114
|
/** Key in `ViteHubConsoleRecord.cells`. */
|
|
56
115
|
key: string;
|
|
57
116
|
label: string;
|
|
@@ -76,8 +135,42 @@ interface ViteHubConsoleOperationColumn {
|
|
|
76
135
|
/** Dot path into each item of the result, such as `author.name` or `messages.0.body`. */
|
|
77
136
|
key: string;
|
|
78
137
|
label: string;
|
|
79
|
-
/**
|
|
80
|
-
|
|
138
|
+
/**
|
|
139
|
+
* `datetime` shows a time in milliseconds since the epoch as a relative date, such as `5m ago`. `excerpt` cuts a long
|
|
140
|
+
* text. `status` shows the value as a status with a colored dot, such as `Open`. `tones` picks the color of each value.
|
|
141
|
+
* `switch` shows a boolean as a switch that calls the `switch` operation.
|
|
142
|
+
*/
|
|
143
|
+
format?: "datetime" | "excerpt" | "status" | "switch";
|
|
144
|
+
/** The color of each value of a `status` column, such as `{ open: "info", resolved: "success" }`. Other values are neutral. */
|
|
145
|
+
tones?: Readonly<Record<string, "error" | "info" | "neutral" | "success" | "warning">>;
|
|
146
|
+
/**
|
|
147
|
+
* What a `switch` column calls when the user flips it: `operation` with an input that maps each key of `input` to a
|
|
148
|
+
* dot path of the item, and the column `key` to the new value. `{ operation: "skills.set", input: { name: "name" } }`
|
|
149
|
+
* on the column `enabled` calls `skills.set` with `{ name, enabled }`, then loads the list again. A user who may only
|
|
150
|
+
* read the section sees the switch disabled.
|
|
151
|
+
*/
|
|
152
|
+
switch?: {
|
|
153
|
+
operation: string;
|
|
154
|
+
input: Readonly<Record<string, string>>;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A button on each row that calls `operation` with the Console user, then loads the list again. `input` maps each input
|
|
159
|
+
* key to a dot path of the item, as a `switch` column does.
|
|
160
|
+
*/
|
|
161
|
+
interface ViteHubConsoleOperationAction {
|
|
162
|
+
label: string;
|
|
163
|
+
operation: string;
|
|
164
|
+
input: Readonly<Record<string, string>>;
|
|
165
|
+
/**
|
|
166
|
+
* The result is `{ url }`, such as a one-time link or a provider sign-in: the Console opens it in a new tab, and loads
|
|
167
|
+
* the list again when the person comes back. The URL must be `https:`, or `http:` on a loopback host.
|
|
168
|
+
*/
|
|
169
|
+
tab?: true;
|
|
170
|
+
/** Show the button only on rows where each dot path holds one of the listed values. */
|
|
171
|
+
when?: Readonly<Record<string, readonly string[]>>;
|
|
172
|
+
/** Ask this question before the call. `{path}` takes a value from the item. */
|
|
173
|
+
confirm?: string;
|
|
81
174
|
}
|
|
82
175
|
/** A chip above the list. Choosing it merges `input` into the operation input. The first chip is the default. */
|
|
83
176
|
interface ViteHubConsoleOperationFilter {
|
|
@@ -91,13 +184,24 @@ interface ViteHubConsoleOperationFilter {
|
|
|
91
184
|
* array of objects with an `id`. A failure of the operation, with its `fix`, shows where the list would be.
|
|
92
185
|
*/
|
|
93
186
|
interface ViteHubConsoleOperationView {
|
|
187
|
+
/** Buttons on each row. A user who may only read the section does not see them. */
|
|
188
|
+
actions?: readonly ViteHubConsoleOperationAction[];
|
|
94
189
|
columns: readonly ViteHubConsoleOperationColumn[];
|
|
190
|
+
/**
|
|
191
|
+
* Opens the item of a row in a side panel. `comment-thread` shows an item of `comments.list` as a comment thread
|
|
192
|
+
* where the user reads, replies, resolves, reopens, and mentions people. The panel calls the `comments.*` operations
|
|
193
|
+
* with the Console user, and `?thread=<id>` in the URL opens it.
|
|
194
|
+
*/
|
|
195
|
+
detail?: {
|
|
196
|
+
kind: "comment-thread";
|
|
197
|
+
};
|
|
95
198
|
filters?: readonly ViteHubConsoleOperationFilter[];
|
|
96
199
|
kind: "operation-view";
|
|
97
200
|
/**
|
|
98
201
|
* Makes each row a link: `{path}` placeholders take values from the item and are URL-encoded, and `{path:path}` takes an
|
|
99
|
-
* app path and encodes each segment (a value that is not an app path, such as `//evil.com/x`, gives no link).
|
|
100
|
-
* `
|
|
202
|
+
* app path and encodes each segment (a value that is not an app path, such as `//evil.com/x`, gives no link).
|
|
203
|
+
* `{path:href}` takes an app URL that is already encoded, with its query, as it is. Rows where `when.path` is not
|
|
204
|
+
* `when.equals` get none.
|
|
101
205
|
*/
|
|
102
206
|
link?: {
|
|
103
207
|
label?: string;
|
|
@@ -121,7 +225,17 @@ interface ViteHubConsoleAuthView {
|
|
|
121
225
|
notice: string;
|
|
122
226
|
}
|
|
123
227
|
interface ViteHubConsoleAuthSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleAuthView> {}
|
|
124
|
-
|
|
228
|
+
/**
|
|
229
|
+
* The webhooks of the app, their pending debounce timers, and their delivery log. The Console calls the `webhooks.*`
|
|
230
|
+
* operations of `@vite-hub/webhooks` with the Console user to list them, send a test, send a pending delivery now,
|
|
231
|
+
* cancel it, and redeliver. It has no build-time data.
|
|
232
|
+
*/
|
|
233
|
+
interface ViteHubConsoleWebhooksView {
|
|
234
|
+
kind: "webhooks";
|
|
235
|
+
notice: string;
|
|
236
|
+
}
|
|
237
|
+
interface ViteHubConsoleWebhooksSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleWebhooksView> {}
|
|
238
|
+
type ViteHubConsoleSectionView = ViteHubConsoleOperationView | ViteHubConsoleAuthView | ViteHubConsoleWebhooksView | ViteHubConsoleDefinitionCatalogView | ViteHubConsoleRecordTableView | ViteHubConsoleDocumentEditorView | ViteHubConsoleWorkspaceBrowserView;
|
|
125
239
|
/**
|
|
126
240
|
* The overview of a document editor section: document counts by state, the changes that wait for a publish, recent
|
|
127
241
|
* activity, and a New button per collection. It reads the owner `overview` action.
|
|
@@ -231,8 +345,8 @@ interface ViteHubConsoleServerExport {
|
|
|
231
345
|
/** Named export of `module`. */
|
|
232
346
|
export: string;
|
|
233
347
|
/**
|
|
234
|
-
*
|
|
235
|
-
* path that the application can import.
|
|
348
|
+
* Absolute path of the owner module, such as `ownModule(import.meta.url, "runtime/console")`, or an owner package
|
|
349
|
+
* specifier that the host maps to a module path that the application can import.
|
|
236
350
|
*/
|
|
237
351
|
module: string;
|
|
238
352
|
}
|
|
@@ -243,7 +357,8 @@ interface ViteHubConsoleServerExport {
|
|
|
243
357
|
interface ViteHubConsoleRuntimeReader extends ViteHubConsoleServerExport {}
|
|
244
358
|
/**
|
|
245
359
|
* A record table that also reads records at request time. The Console shows the build-time records of `read` first,
|
|
246
|
-
* then the records of the `runtime` reader. A runtime record
|
|
360
|
+
* then the records of the `runtime` reader. A runtime record updates the build-time record with the same id: its cells
|
|
361
|
+
* and fields replace the build-time ones with the same key or label.
|
|
247
362
|
*/
|
|
248
363
|
interface ViteHubConsoleRuntimeRecordTableSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleRecordTableView> {
|
|
249
364
|
/** Reads build-time records on the server. When omitted, the section has only runtime records. */
|
|
@@ -279,7 +394,7 @@ interface ViteHubConsoleDocumentEditorSection<TOptions = void> extends ViteHubCo
|
|
|
279
394
|
* A Console section that an owner package contributes. The owner defines the label, icon, view, and data reader.
|
|
280
395
|
* `TOptions` is the discovery context that the host passes to `read`.
|
|
281
396
|
*/
|
|
282
|
-
type ViteHubConsoleSectionContribution<TOptions = void> = ViteHubConsoleAuthSection | ViteHubConsoleDefinitionCatalogSection<TOptions> | ViteHubConsoleRecordTableSection<TOptions> | ViteHubConsoleRuntimeRecordTableSection<TOptions> | ViteHubConsoleDocumentEditorSection<TOptions> | ViteHubConsoleOperationSection;
|
|
397
|
+
type ViteHubConsoleSectionContribution<TOptions = void> = ViteHubConsoleAuthSection | ViteHubConsoleWebhooksSection | ViteHubConsoleDefinitionCatalogSection<TOptions> | ViteHubConsoleRecordTableSection<TOptions> | ViteHubConsoleRuntimeRecordTableSection<TOptions> | ViteHubConsoleDocumentEditorSection<TOptions> | ViteHubConsoleOperationSection;
|
|
283
398
|
/** A fix that the owner names for a feature the project lacks, such as `Add authorize to defineContent().` */
|
|
284
399
|
interface ViteHubConsoleDocumentHint {
|
|
285
400
|
/** One sentence that names the fix. Text in backticks shows as code. */
|
|
@@ -322,17 +437,12 @@ export declare function inspectRateLimitDefinitions(options: RateLimitInspection
|
|
|
322
437
|
export declare const rateLimitConsoleSection: ViteHubConsoleSectionContribution<RateLimitInspectionOptions>;
|
|
323
438
|
//#endregion
|
|
324
439
|
//#region src/vite.d.ts
|
|
325
|
-
export type RateLimitVitePluginOptions =
|
|
440
|
+
export type RateLimitVitePluginOptions = RateLimitOptions;
|
|
326
441
|
export type RateLimitVitePlugin = Plugin & {
|
|
327
|
-
vitehub: ViteHubCliPluginMetadata & ViteHubInspectionPluginMetadata & {
|
|
442
|
+
vitehub: ViteHubCliPluginMetadata & ViteHubInspectionPluginMetadata & DurabilityPluginMetadata & {
|
|
328
443
|
operations: readonly OperationContributionEntry[];
|
|
329
444
|
};
|
|
330
445
|
};
|
|
331
446
|
export declare function hubRateLimit(options?: RateLimitVitePluginOptions): RateLimitVitePlugin;
|
|
332
|
-
declare module "vite" {
|
|
333
|
-
interface UserConfig {
|
|
334
|
-
rateLimit?: RateLimitModuleOptions;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
447
|
//#endregion
|
|
338
448
|
export type { RateLimitInspectionOptions };
|