@vite-hub/kv 0.0.4 → 0.3.1

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 (63) hide show
  1. package/README.md +110 -14
  2. package/dist/batch--v0ri69O.js +40 -0
  3. package/dist/cli-DpPhz_Ek.d.ts +163 -0
  4. package/dist/cli.d.ts +17 -0
  5. package/dist/cli.js +469 -0
  6. package/dist/cloudflare-env-lOtHHsgP.js +46 -0
  7. package/dist/cloudflare-env-lookup-Bs0VDpU5.js +42 -0
  8. package/dist/cloudflare-kv-BIEUFzRT.js +187 -0
  9. package/dist/cloudflare-kv-local-BBw3ZT1K.js +71 -0
  10. package/dist/config-BXEVoZE3.js +250 -0
  11. package/dist/{dist-DDW1iC5f.js → create-storage-BGsrQKw3.js} +266 -115
  12. package/dist/cursor-history-BqIQePNP.js +165 -0
  13. package/dist/database-72Jk3VVk.js +250 -0
  14. package/dist/deno-kv-BM9mYdUp.js +128 -0
  15. package/dist/dev-peer-CHafxbtj.js +238 -0
  16. package/dist/driver-BwxgaQ-f.d.ts +15 -0
  17. package/dist/durability.d.ts +17 -0
  18. package/dist/durability.js +53 -0
  19. package/dist/error-diagnostics-BxqvtEIb.js +147 -0
  20. package/dist/errors-DbwufFZp.js +60 -0
  21. package/dist/errors.d.ts +23 -7
  22. package/dist/errors.js +2 -20
  23. package/dist/fs-lite-BLZId9_P.js +386 -0
  24. package/dist/fs-lite-RAoxu8L0.js +2 -0
  25. package/dist/index.d.ts +10 -4
  26. package/dist/index.js +364 -109
  27. package/dist/inspect-BIKQsqX4.js +118 -0
  28. package/dist/invariant-DolT9EEx.js +22 -0
  29. package/dist/main-F3Y22_uV.js +2353 -0
  30. package/dist/object-Da1zyPCR.js +11 -0
  31. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  32. package/dist/operations-B-WZ7P1h.js +1351 -0
  33. package/dist/operations-Ch-gKaey.js +441 -0
  34. package/dist/operations.d.ts +75 -0
  35. package/dist/operations.js +318 -0
  36. package/dist/redis-shared-E5mahECF.js +94 -0
  37. package/dist/results-p7nPCnaJ.js +6 -0
  38. package/dist/rolldown-runtime-CMFfr-1z.js +26 -0
  39. package/dist/runtime/cloudflare-kv.d.ts +3 -4
  40. package/dist/runtime/cloudflare-kv.js +1 -23
  41. package/dist/runtime/cloudflare-request-env.d.ts +7 -0
  42. package/dist/runtime/cloudflare-request-env.js +11 -0
  43. package/dist/runtime/nitro-plugin.d.ts +12 -0
  44. package/dist/runtime/nitro-plugin.js +22 -0
  45. package/dist/runtime/redis-driver.d.ts +11 -0
  46. package/dist/runtime/redis-driver.js +113 -0
  47. package/dist/runtime/unstorage-driver.d.ts +14 -0
  48. package/dist/runtime/unstorage-driver.js +33 -0
  49. package/dist/runtime/upstash-driver.d.ts +4 -6
  50. package/dist/runtime/upstash-driver.js +60 -110
  51. package/dist/{driver-BT9WefKi.d.ts → types-Bj3EQoRg.d.ts} +16 -11
  52. package/dist/types-DEiKew_3.d.ts +312 -0
  53. package/dist/upstash-DDlqTttY.js +40 -0
  54. package/dist/utils2-FozcTsmb.js +31 -0
  55. package/dist/virtual-module.d.ts +2 -0
  56. package/dist/virtual.d.ts +1 -1
  57. package/dist/vite.d.ts +159 -14
  58. package/dist/vite.js +1329 -2898
  59. package/package.json +68 -19
  60. package/dist/config-aM9Ae7tH.js +0 -110
  61. package/dist/deno-kv-cJx3jU10.js +0 -69
  62. package/dist/fs-lite-BxzdiJSi.js +0 -79
  63. package/dist/types-CO0DRjJa.d.ts +0 -78
@@ -0,0 +1,31 @@
1
+ //#region ../../node_modules/.pnpm/unstorage@2.0.0-beta.0/node_modules/unstorage/dist/_chunks/utils2.mjs
2
+ function normalizeKey(key) {
3
+ if (!key) return "";
4
+ return key.split("?")[0]?.replace(/[/\\]/g, ":").replace(/:+/g, ":").replace(/^:|:$/g, "") || "";
5
+ }
6
+ function hasDotSegment(key) {
7
+ return key.split(":").some((segment) => segment === "." || segment === "..");
8
+ }
9
+ function joinKeys(...keys) {
10
+ return normalizeKey(keys.join(":"));
11
+ }
12
+ function normalizeBaseKey(base) {
13
+ base = normalizeKey(base);
14
+ return base ? base + ":" : "";
15
+ }
16
+ function filterKeyByDepth(key, depth) {
17
+ if (depth === void 0) return true;
18
+ let substrCount = 0;
19
+ let index = key.indexOf(":");
20
+ while (index > -1) {
21
+ substrCount++;
22
+ index = key.indexOf(":", index + 1);
23
+ }
24
+ return substrCount <= depth;
25
+ }
26
+ function filterKeyByBase(key, base) {
27
+ if (base) return key.startsWith(base) && key[key.length - 1] !== "$";
28
+ return key[key.length - 1] !== "$";
29
+ }
30
+ //#endregion
31
+ export { normalizeBaseKey as a, joinKeys as i, filterKeyByDepth as n, normalizeKey as o, hasDotSegment as r, filterKeyByBase as t };
@@ -1,6 +1,8 @@
1
1
  declare module "#vitehub/kv/config" {
2
2
  export const hosting: string | undefined
3
3
  export const kv: false | import("./index.js").ResolvedKVModuleOptions
4
+ /** Loads the databases of the app. Set when a store uses the `database` driver. */
5
+ export const loadDatabases: (() => Promise<Record<string, { db: object } | undefined>>) | undefined
4
6
  const config: { hosting?: string, kv: typeof kv }
5
7
  export default config
6
8
  }
package/dist/virtual.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /// <reference path="./virtual-module.d.ts" />
2
- export { };
2
+ export {}
package/dist/vite.d.ts CHANGED
@@ -1,26 +1,164 @@
1
- import { c as KVModuleOptions, g as ResolvedKVModuleOptions } from "./types-CO0DRjJa.js";
1
+ import { C as KVOptions, F as ResolvedKVModuleOptions } from "./types-DEiKew_3.js";
2
+ import { r as ViteHubCliPluginMetadata } from "./cli-DpPhz_Ek.js";
3
+ import { n as OperationContributionEntry } from "./operation-definition-8gOe-ubD.js";
2
4
  import { Plugin } from "vite";
3
-
4
5
  //#region src/config.d.ts
5
6
  interface KVResolutionInput {
7
+ /**
8
+ * `vite dev`. A store is then local unless it sets `remote: true`: inference never selects Upstash, and a Cloudflare
9
+ * store falls back to `fs-lite` when the runtime has no binding. Builds leave it unset.
10
+ */
11
+ dev?: boolean;
6
12
  env?: Record<string, string | undefined>;
7
13
  hosting?: string;
14
+ /**
15
+ * The app has a Default Database on Postgres. A build without a KV driver then infers the `database` driver on Node.
16
+ * The KV Vite plugin finds it in the Database Definitions.
17
+ */
18
+ postgresDatabase?: boolean;
8
19
  }
9
20
  //#endregion
10
21
  //#region src/vite-config.d.ts
11
- declare const KV_VITE_PLUGIN_NAME = "@vite-hub/kv/vite";
12
- declare const KV_VIRTUAL_CONFIG_ID = "#vitehub/kv/config";
22
+ export declare const KV_VITE_PLUGIN_NAME = "@vite-hub/kv/vite";
23
+ export declare const KV_VIRTUAL_CONFIG_ID = "#vitehub/kv/config";
13
24
  interface KVViteRuntimeConfig {
14
25
  hosting?: string;
15
26
  kv: false | ResolvedKVModuleOptions;
16
27
  }
17
- declare function resolveKVViteConfig(kv: KVModuleOptions | undefined, input?: KVResolutionInput): KVViteRuntimeConfig;
28
+ export declare function resolveKVViteConfig(kv: KVOptions | undefined, input?: KVResolutionInput): KVViteRuntimeConfig;
29
+ //#endregion
30
+ //#region ../internal/src/deployment.d.ts
31
+ /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
32
+ type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
33
+ //#endregion
34
+ //#region ../internal/src/inspect.d.ts
35
+ interface ViteHubDefinitionField {
36
+ label: string;
37
+ value: string;
38
+ }
39
+ /** Serializable summary of one discovered Definition. Files are relative to the project root. */
40
+ interface ViteHubDefinitionSummary {
41
+ fields: readonly ViteHubDefinitionField[];
42
+ file: string;
43
+ name: string;
44
+ source: string;
45
+ }
46
+ /** Lists the Definitions that one owner package discovered for the resolved Vite config. */
47
+ interface ViteHubDefinitionInspector {
48
+ /** Stable singular kind, for example `queue` or `rate-limit`. */
49
+ kind: string;
50
+ label: string;
51
+ list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
52
+ }
53
+ /** One generated Provider Output file or directory that an owner package can write. */
54
+ interface ViteHubProviderOutputEntry {
55
+ description: string;
56
+ owner: string;
57
+ /** Absolute path. */
58
+ path: string;
59
+ }
60
+ /**
61
+ * Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
62
+ * The CLI sets `provider-output` when only a generated Wrangler config names the id.
63
+ */
64
+ type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
65
+ /** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
66
+ interface ViteHubResourceSummary {
67
+ /** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
68
+ binding?: string;
69
+ /** Definition or store name. */
70
+ definition: string;
71
+ /** Env variable that supplied the id when `source` is `env`. */
72
+ env?: string;
73
+ host: "cloudflare" | "vercel";
74
+ id?: string;
75
+ /** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
76
+ kind: string;
77
+ /** Resource name on the host, when the config names it. */
78
+ name?: string;
79
+ /** Explains how the host finds the resource when no id or name is known locally. */
80
+ note?: string;
81
+ owner: string;
82
+ /** Absent when no id is known yet. */
83
+ source?: ViteHubResourceIdSource;
84
+ }
85
+ interface ViteHubInspectionContributor {
86
+ definitions?: readonly ViteHubDefinitionInspector[];
87
+ providerOutput?: readonly ViteHubProviderOutputEntry[];
88
+ resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
89
+ }
90
+ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
91
+ interface ViteHubInspectionPluginMetadata {
92
+ inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
93
+ }
94
+ //#endregion
95
+ //#region ../internal/src/build/deployment-plan-output.d.ts
96
+ /**
97
+ * One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
98
+ * a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
99
+ * It holds names only, so `vitehub deploy` can check the host without booting Vite. It never holds a value.
100
+ */
101
+ interface DeploymentEnvEntry {
102
+ /** The declaration path, such as `env.server.github.token`, when it is safe to show. Primitive entries have none. */
103
+ path?: string;
104
+ /** The host variable names, in read order. The first name that is set supplies the value. */
105
+ names: readonly string[];
106
+ /** Any variable whose name starts with this prefix supplies the value, such as `VITEHUB_CONSOLE_KEY_`. */
107
+ prefix?: string;
108
+ required: boolean;
109
+ secret: boolean;
110
+ /** A default supplies the value when no name is set. */
111
+ hasDefault: boolean;
112
+ /** The primitives that read these names, such as `blob`. Server Env declarations have none. */
113
+ owners?: readonly string[];
114
+ }
115
+ /** What a primitive needs to know to name the variables it reads in the deployed app. */
116
+ interface DeploymentEnvContext {
117
+ host: ViteHubHost;
118
+ }
119
+ /**
120
+ * The host variables that a primitive reads itself, outside the Server Env registry, for one host and its resolved
121
+ * config. A Vite plugin exposes it as `api.deploymentEnv`, and the build writes the result to `deployment.json`.
122
+ * Return names only, never values.
123
+ */
124
+ type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
125
+ //#endregion
126
+ //#region ../internal/src/durability.d.ts
127
+ /**
128
+ * One durability reporter that a primitive's Vite plugin contributes through `vitehub.durability`. The Node server
129
+ * imports `export` from `module` at boot and calls it with `input` and the server environment. It returns the
130
+ * `Durability` lines of `@vite-hub/runtime/durability`.
131
+ */
132
+ interface DurabilityContribution {
133
+ /** The primitive that the reporter describes, such as `kv`. Other reporters find its result by this id. */
134
+ primitive: string;
135
+ /** The absolute file of the reporter module. */
136
+ module: string;
137
+ export: string;
138
+ /**
139
+ * The resolved configuration of the primitive, as plain JSON data. The build writes it into the server with
140
+ * `JSON.stringify`, so do not put credentials here.
141
+ */
142
+ input: unknown;
143
+ }
144
+ /** The `vitehub.durability` field of a primitive's Vite plugin. */
145
+ interface DurabilityPluginMetadata {
146
+ /** Called after Vite resolves the config. Return an empty list when the primitive is off. */
147
+ durability?: () => readonly DurabilityContribution[];
148
+ }
18
149
  //#endregion
19
150
  //#region src/vite.d.ts
20
- interface KVVitePluginAPI {
151
+ /**
152
+ * File path of the unstorage driver over a KV store. Options: `store` (default: the default store) and `base` (a key prefix).
153
+ * ViteHub mounts it at `kv`, `kv-<store>`, and, with `cache: { driver: "kv" }`, at `cache`.
154
+ */
155
+ export declare const kvStorageDriver: string;
156
+ export interface KVVitePluginAPI {
157
+ /** The variables that the KV stores read on the deployed host. See `kvDeploymentEnv()`. */
158
+ deploymentEnv: DeploymentEnvContribution;
21
159
  getConfig: () => KVViteRuntimeConfig;
22
160
  }
23
- type KVVitePlugin = Plugin & {
161
+ export type KVVitePlugin = Plugin & {
24
162
  api: KVVitePluginAPI;
25
163
  nitro: {
26
164
  name: string;
@@ -28,9 +166,16 @@ type KVVitePlugin = Plugin & {
28
166
  options: NitroCloudflareKVTarget;
29
167
  }) => void;
30
168
  };
169
+ vitehub: ViteHubCliPluginMetadata & ViteHubInspectionPluginMetadata & DurabilityPluginMetadata & {
170
+ operations: readonly OperationContributionEntry[];
171
+ };
31
172
  };
32
- declare function hubKvOptionalPeerResolver(): Plugin;
173
+ export declare function hubKVOptionalPeerResolver(): Plugin;
33
174
  interface NitroCloudflareKVTarget {
175
+ handlers?: unknown[];
176
+ kv?: Record<string, unknown>;
177
+ storage?: Record<string, unknown>;
178
+ plugins?: string[];
34
179
  cloudflare?: {
35
180
  wrangler?: {
36
181
  kv_namespaces?: Array<{
@@ -40,11 +185,11 @@ interface NitroCloudflareKVTarget {
40
185
  };
41
186
  };
42
187
  }
43
- declare function hubKv(options?: KVModuleOptions): KVVitePlugin;
44
- declare module "vite" {
45
- interface UserConfig {
46
- kv?: KVModuleOptions;
47
- }
188
+ export interface KVViteInput extends Pick<KVResolutionInput, "hosting"> {
189
+ /** The module that exports the app's `databases`, for the `database` driver. Default `@vite-hub/database/runtime/registry`. */
190
+ databaseImport?: string;
48
191
  }
192
+ /** `input.hosting` names the host preset for driver inference, as `vitehub()` passes it. Without it, KV reads the host from env. */
193
+ export declare function hubKV(options?: KVOptions, input?: KVViteInput): KVVitePlugin;
49
194
  //#endregion
50
- export { KVVitePlugin, KVVitePluginAPI, type KVViteRuntimeConfig, KV_VIRTUAL_CONFIG_ID, KV_VITE_PLUGIN_NAME, hubKv, hubKvOptionalPeerResolver, resolveKVViteConfig };
195
+ export type { KVViteRuntimeConfig };