@vite-hub/kv 0.7.0 → 0.9.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 (35) hide show
  1. package/README.md +2 -0
  2. package/dist/cli.js +2 -2
  3. package/dist/{cloudflare-env-Cpy3Bqdn.js → cloudflare-env-JD7uO5-i.js} +0 -4
  4. package/dist/{cloudflare-kv-hMdZQZz1.js → cloudflare-kv-CkrnHHnv.js} +4 -4
  5. package/dist/{cloudflare-kv-local-DO1g7PrA.js → cloudflare-kv-local-qb92SO8d.js} +3 -3
  6. package/dist/{config-Dr4GKknB.js → config-CZ4CZy9h.js} +4 -4
  7. package/dist/{create-storage-DrhV0F4S.js → create-storage-DeGjkDl8.js} +1 -1
  8. package/dist/{cursor-history-MzSrXXXX.js → cursor-history-KSuS5xrH.js} +1 -1
  9. package/dist/{database-DJp7XHhu.js → database-CtQO7n6H.js} +6 -6
  10. package/dist/{deno-kv-DwcTL95B.js → deno-kv-ClGWU3yO.js} +2 -2
  11. package/dist/{dev-peer-D0vOxmrD.js → dev-peer-CpFxuBAP.js} +0 -24
  12. package/dist/{driver-Cvu4k8t4.d.ts → driver-CZTAQ_07.d.ts} +1 -1
  13. package/dist/{error-diagnostics-DAi25E6F.js → error-diagnostics-C7c-Bfrl.js} +2 -2
  14. package/dist/{errors-kZRpu7Wa.js → errors-BV0MKLrD.js} +1 -1
  15. package/dist/errors.js +1 -1
  16. package/dist/{fs-lite-4ccAiYae.js → fs-lite-Bmcw5tUV.js} +124 -140
  17. package/dist/fs-lite-D33j4kWD.js +1 -0
  18. package/dist/index.js +56 -58
  19. package/dist/{operations-UeAgPdtY.js → operations-CbpFdf91.js} +17 -24
  20. package/dist/{operations-BKAO0rkO.js → operations-mNN-HppH.js} +2 -3
  21. package/dist/operations.js +3 -10
  22. package/dist/{redis-shared-DEwmedD5.js → redis-shared-DIUSIQAC.js} +1 -1
  23. package/dist/runtime/cloudflare-kv.d.ts +1 -1
  24. package/dist/runtime/cloudflare-kv.js +1 -1
  25. package/dist/runtime/cloudflare-request-env.js +1 -1
  26. package/dist/runtime/nitro-plugin.js +1 -1
  27. package/dist/runtime/redis-driver.d.ts +1 -1
  28. package/dist/runtime/redis-driver.js +3 -5
  29. package/dist/runtime/upstash-driver.d.ts +1 -1
  30. package/dist/runtime/upstash-driver.js +2 -2
  31. package/dist/{upstash-BKkqGQGE.js → upstash-CiqFI55W.js} +2 -2
  32. package/dist/vite.d.ts +1 -0
  33. package/dist/vite.js +40 -55
  34. package/package.json +4 -4
  35. package/dist/fs-lite-BMY853UK.js +0 -1
package/dist/vite.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import { r as __toESM } from "./rolldown-runtime-DegdyBIC.js";
2
2
  import { n as invariantError, t as invariant } from "./invariant-Dj2R1eMr.js";
3
3
  import { a as resolve$1, i as relative$1, n as relativeDefinitionFile, r as dirname$1 } from "./inspect-BWMcVWD8.js";
4
- import { t as addViteHubDevPeerDevHandler } from "./dev-peer-D0vOxmrD.js";
4
+ import { t as addViteHubDevPeerDevHandler } from "./dev-peer-CpFxuBAP.js";
5
5
  import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
6
- import { A as readViteHubDevServerFile, C as markViteConfigPlugin, F as internalErrorDiagnostics, M as removeViteHubDevServerFile, P as writeViteHubDevServerFile, S as isServerEnvironment, T as shouldSkipViteProviderBuild, b as createNoExternalAddition, p as operationRpcPath, r as collectOperationContributions, v as VITEHUB_PROJECT_ROOT, w as resolveViteHubProjectRoot, x as hasNitroConfigContext, y as contributeServerEnv } from "./operations-BKAO0rkO.js";
7
- import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, n as kvRedisEnvHint, o as resolveHostPreset, r as normalizeKVOptions } from "./config-Dr4GKknB.js";
8
- import { n as kvErrorDiagnostics } from "./error-diagnostics-DAi25E6F.js";
9
- import { n as resolveUpstashRuntimeValues } from "./upstash-BKkqGQGE.js";
6
+ import { A as readViteHubDevServerFile, C as markViteConfigPlugin, F as internalErrorDiagnostics, M as removeViteHubDevServerFile, P as writeViteHubDevServerFile, S as isServerEnvironment, T as shouldSkipViteProviderBuild, b as createNoExternalAddition, p as operationRpcPath, r as collectOperationContributions, v as VITEHUB_PROJECT_ROOT, w as resolveViteHubProjectRoot, x as hasNitroConfigContext, y as contributeServerEnv } from "./operations-mNN-HppH.js";
7
+ import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, n as kvRedisEnvHint, o as resolveHostPreset, r as normalizeKVOptions } from "./config-CZ4CZy9h.js";
8
+ import { n as kvErrorDiagnostics } from "./error-diagnostics-C7c-Bfrl.js";
9
+ import { n as resolveUpstashRuntimeValues } from "./upstash-CiqFI55W.js";
10
10
  import { createRequire, isBuiltin } from "node:module";
11
11
  import { access, copyFile, cp, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
12
12
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
13
13
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
14
+ import { fileURLToPath, pathToFileURL } from "node:url";
14
15
  import { formatDiagnostic } from "nostics";
15
16
  import { tmpdir } from "node:os";
16
- import { fileURLToPath, pathToFileURL } from "node:url";
17
17
  import { createHash } from "node:crypto";
18
18
  // ../internal/src/build/paths.ts
19
19
  function resolveRuntimeModule(packageDir, modulePath) {
@@ -513,11 +513,9 @@ function isRelativeSpecifier(path) {
513
513
  function isBareSpecifier(id) {
514
514
  return !/^(?:\.{1,2}(?:[\\/]|$)|[\\/]|[A-Za-z]:[\\/]|\0|#|[a-z][a-z0-9+.-]*:)/i.test(id);
515
515
  }
516
- /** The folder that a relative import of `importer` resolves from, as esbuild's `resolveDir`. */
517
516
  function importerDir(importer, workingDir) {
518
517
  return importer && isAbsolute(importer) ? dirname(importer) : workingDir;
519
518
  }
520
- /** Rolldown resolves a specifier from an importer file. A bundle entry has none, so use a file in the working folder. */
521
519
  function importerFor(importer, workingDir) {
522
520
  return importer ?? join(workingDir, "__vitehub_entry__.js");
523
521
  }
@@ -550,11 +548,6 @@ function collectPackageExportCandidates(packageName, exportsValue, packageRelati
550
548
  }
551
549
  return candidates;
552
550
  }
553
- /**
554
- * Resolves `specifier` from a resolveId hook without running that hook again. `flag` in `custom` also skips the hook in
555
- * resolutions that other plugins start from this one. `skipSelf` is still needed: when two equal resolutions run at the
556
- * same time, Rolldown 1.2 can give one of them no `custom`, and the hook would then wait on its own resolution.
557
- */
558
551
  function resolveFrom(context, specifier, request, workingDir, flag) {
559
552
  return context.resolve(specifier, importerFor(request.importer, workingDir), {
560
553
  custom: {
@@ -871,9 +864,6 @@ function createWasmModulePlugin(outdir, workingDir, copy) {
871
864
  }
872
865
  };
873
866
  }
874
- /**
875
- * Leaves package imports external. Resolve package.json import mappings first, and preserve unmapped host imports.
876
- */
877
867
  function createExternalPackagesPlugin() {
878
868
  return {
879
869
  name: "vitehub-external-packages",
@@ -959,7 +949,6 @@ function createOptionalImportPlugin() {
959
949
  }
960
950
  };
961
951
  }
962
- /** Matches import paths as esbuild's `external` does: `*` is a wildcard, and a package name also matches its subpaths. */
963
952
  function createExternalMatcher(patterns) {
964
953
  if (!patterns?.length) return;
965
954
  const matchers = patterns.map((pattern) => {
@@ -971,7 +960,6 @@ function createExternalMatcher(patterns) {
971
960
  });
972
961
  return (id) => matchers.some((matches) => matches(id));
973
962
  }
974
- /** Returns the modules of the chunks that no chunk loaded from the entry chunk imports. */
975
963
  function findUnusedChunkModules(chunks) {
976
964
  const used = new Set(chunks.filter((chunk) => chunk.isEntry));
977
965
  for (const chunk of used) for (const other of chunks) if (!used.has(other) && chunk.code.includes(other.fileName)) used.add(other);
@@ -3298,7 +3286,6 @@ function publishedPackagePaths(packageDir) {
3298
3286
  entries
3299
3287
  };
3300
3288
  }
3301
- /** Copies a file or folder and follows links. `node_modules` folders and paths that disappear during the copy are skipped. */
3302
3289
  async function copyTree(source, target) {
3303
3290
  const info = await unlessGone(() => stat(source));
3304
3291
  if (!info) return;
@@ -4939,10 +4926,6 @@ const runs = shared[runsKey] ??= /* @__PURE__ */ new Map();
4939
4926
  const startedKey = Symbol.for("vitehub.hints.started");
4940
4927
  const startedShared = globalThis;
4941
4928
  const started = startedShared[startedKey] ??= /* @__PURE__ */ new WeakSet();
4942
- /**
4943
- * The report of the ViteHub project root, where the other generated files go. A Nuxt app with `srcDir: "app"` has its
4944
- * Vite root in `app/`, one folder below.
4945
- */
4946
4929
  function hintsFile(config) {
4947
4930
  const projectRoot = Reflect.get(config, VITEHUB_PROJECT_ROOT);
4948
4931
  return resolve(typeof projectRoot === "string" ? projectRoot : resolveViteHubProjectRoot(config.root), viteHubHintsFile);
@@ -5780,11 +5763,11 @@ function serializeCloudflareRuntime(config) {
5780
5763
  }
5781
5764
  function getNitroCloudflareKVNamespaces(target) {
5782
5765
  if (!isRecord(target)) return [];
5783
- const cloudflare = Reflect.get(target, "cloudflare");
5766
+ const cloudflare = target.cloudflare;
5784
5767
  if (!isRecord(cloudflare)) return [];
5785
- const wrangler = Reflect.get(cloudflare, "wrangler");
5768
+ const wrangler = cloudflare.wrangler;
5786
5769
  if (!isRecord(wrangler)) return [];
5787
- const namespaces = Reflect.get(wrangler, "kv_namespaces");
5770
+ const namespaces = wrangler.kv_namespaces;
5788
5771
  if (!Array.isArray(namespaces)) return [];
5789
5772
  return namespaces.flatMap((namespace) => {
5790
5773
  let normalized;
@@ -5794,11 +5777,7 @@ function getNitroCloudflareKVNamespaces(target) {
5794
5777
  return [];
5795
5778
  }
5796
5779
  if (!isProviderJsonRecord(normalized)) return [];
5797
- const binding = Reflect.get(normalized, "binding");
5798
- const id = Reflect.get(normalized, "id");
5799
- const previewId = Reflect.get(normalized, "preview_id");
5800
- const experimentalRemote = Reflect.get(normalized, "experimental_remote");
5801
- const remote = Reflect.get(normalized, "remote");
5780
+ const { binding, id, preview_id: previewId, experimental_remote: experimentalRemote, remote } = normalized;
5802
5781
  if (typeof binding !== "string") return [];
5803
5782
  if (id !== void 0 && typeof id !== "string") return [];
5804
5783
  if (previewId !== void 0 && typeof previewId !== "string") return [];
@@ -5808,7 +5787,7 @@ function getNitroCloudflareKVNamespaces(target) {
5808
5787
  });
5809
5788
  }
5810
5789
  function getResolvedNitroConfig(config) {
5811
- return Reflect.get(config, "nitro");
5790
+ return "nitro" in config ? config.nitro : void 0;
5812
5791
  }
5813
5792
  function reconcileNitroCloudflareKV(target, kv, ownedNamespaces, provisionState) {
5814
5793
  configureNitroCloudflareRequestEnv(target, kv);
@@ -5822,7 +5801,7 @@ function reconcileNitroCloudflareKV(target, kv, ownedNamespaces, provisionState)
5822
5801
  if (kv) configureCloudflareKV(target, kv, provisionState);
5823
5802
  }
5824
5803
  function configureNitroCloudflareKV(config, options, input, ownedNamespaces, provisionState) {
5825
- const nitro = Reflect.get(config, "nitro");
5804
+ const nitro = "nitro" in config ? config.nitro : void 0;
5826
5805
  if (!isRecord(nitro)) return false;
5827
5806
  const target = nitro;
5828
5807
  const namespaces = target.cloudflare?.wrangler?.kv_namespaces;
@@ -5831,7 +5810,7 @@ function configureNitroCloudflareKV(config, options, input, ownedNamespaces, pro
5831
5810
  const kv = resolveKVViteConfig(options, input).kv;
5832
5811
  configureNitroCloudflareRequestEnv(target, kv);
5833
5812
  configureNitroPlugin(target, kv);
5834
- if (Reflect.get(config, "__vitehubNitroConfigContext") === true) configureNitroStorage(target, kv);
5813
+ if ("__vitehubNitroConfigContext" in config && config["__vitehubNitroConfigContext"] === true) configureNitroStorage(target, kv);
5835
5814
  if (kv) {
5836
5815
  const existingNamespaces = new Set(target.cloudflare?.wrangler?.kv_namespaces);
5837
5816
  configureCloudflareKV(target, kv, provisionState);
@@ -5863,6 +5842,7 @@ function hubKV(options, input = {}) {
5863
5842
  let resolved;
5864
5843
  let providerOutput;
5865
5844
  let runtimeConfig;
5845
+ let configReady;
5866
5846
  let projectRoot = process.cwd();
5867
5847
  const getConfig = () => runtimeConfig ??= resolveKVViteConfig(options, resolutionInput());
5868
5848
  const providerOutputGenerations = createProviderDeploymentOutputGenerationState();
@@ -5877,6 +5857,25 @@ function hubKV(options, input = {}) {
5877
5857
  });
5878
5858
  if (hint) reportViteHubHint(config, hint);
5879
5859
  }
5860
+ async function resolveRuntimeConfig(config) {
5861
+ resolved = config;
5862
+ startViteHubHints(config);
5863
+ if (config.command) command = config.command;
5864
+ mode = config.mode ?? mode;
5865
+ projectRoot = resolveViteHubProjectRoot(config.root || process.cwd());
5866
+ viteEnv = loadAllEnv((await import("vite")).loadEnv, mode, config.envDir === false ? false : resolve(config.root || process.cwd(), config.envDir ?? "."));
5867
+ databasePlugin = findDatabasePlugin(config.plugins);
5868
+ await databasePlugin?.api?.whenConfigResolved?.();
5869
+ providerOutput = useProviderOutputCatalog(config);
5870
+ runtimeConfig = resolveKVViteConfig(options, resolutionInput());
5871
+ const provisionState = readProvisionStateSync(projectRoot);
5872
+ if (nitroOptions) reconcileNitroCloudflareKV(nitroOptions, runtimeConfig.kv, ownedNitroNamespaces, provisionState);
5873
+ if (hasNitroConfigContext(config) || isRecord(getResolvedNitroConfig(config))) nitroOwned = configureNitroCloudflareKV(config, options, resolutionInput(), ownedNitroNamespaces, provisionState);
5874
+ if (!config.command && command === "build" && Reflect.get(config, "__vitehubNuxtHints")) reportRedisEnvHint({
5875
+ ...config,
5876
+ command
5877
+ });
5878
+ }
5880
5879
  return {
5881
5880
  name: KV_VITE_PLUGIN_NAME,
5882
5881
  enforce: "post",
@@ -5886,7 +5885,8 @@ function hubKV(options, input = {}) {
5886
5885
  hosting: hosting(),
5887
5886
  postgresDatabase: postgresDatabase()
5888
5887
  }),
5889
- getConfig
5888
+ getConfig,
5889
+ whenConfigResolved: () => configReady
5890
5890
  },
5891
5891
  nitro: {
5892
5892
  name: "@vite-hub/kv/cloudflare-bindings",
@@ -5931,7 +5931,7 @@ function hubKV(options, input = {}) {
5931
5931
  default: kv.store,
5932
5932
  ...kv.stores
5933
5933
  }).map(([name, store]) => {
5934
- const database = Reflect.get(store, "database");
5934
+ const database = "database" in store ? store.database : void 0;
5935
5935
  return [name, {
5936
5936
  driver: store.driver,
5937
5937
  ..."base" in store && store.base ? { base: store.base } : {},
@@ -5986,7 +5986,7 @@ function hubKV(options, input = {}) {
5986
5986
  command = env?.command ?? "build";
5987
5987
  configuredHosting = resolveHostPreset({
5988
5988
  hosting: input.hosting,
5989
- nitro: Reflect.get(config, "nitro"),
5989
+ nitro: "nitro" in config ? config.nitro : void 0,
5990
5990
  env: {}
5991
5991
  });
5992
5992
  resolvedNitroPreset = void 0;
@@ -5995,7 +5995,7 @@ function hubKV(options, input = {}) {
5995
5995
  projectRoot = resolveViteHubProjectRoot(config.root || process.cwd());
5996
5996
  viteEnv = loadAllEnv((await import("vite")).loadEnv, mode, config.envDir === false ? false : resolve(config.root || process.cwd(), config.envDir ?? "."));
5997
5997
  nitroOwned = configureNitroCloudflareKV(config, options, resolutionInput(), ownedNitroNamespaces, readProvisionStateSync(projectRoot));
5998
- const inspectedKV = Reflect.get(config, "vitehubCliDiscovery") === true && mode !== "development" ? resolveKVViteConfig(options, {
5998
+ const inspectedKV = "vitehubCliDiscovery" in config && config.vitehubCliDiscovery === true && mode !== "development" ? resolveKVViteConfig(options, {
5999
5999
  hosting: hosting(),
6000
6000
  postgresDatabase: postgresDatabase()
6001
6001
  }).kv : getConfig().kv;
@@ -6005,23 +6005,8 @@ function hubKV(options, input = {}) {
6005
6005
  },
6006
6006
  configResolved: {
6007
6007
  order: "pre",
6008
- async handler(config) {
6009
- resolved = config;
6010
- startViteHubHints(config);
6011
- if (config.command) command = config.command;
6012
- mode = config.mode ?? mode;
6013
- projectRoot = resolveViteHubProjectRoot(config.root || process.cwd());
6014
- viteEnv = loadAllEnv((await import("vite")).loadEnv, mode, config.envDir === false ? false : resolve(config.root || process.cwd(), config.envDir ?? "."));
6015
- databasePlugin = findDatabasePlugin(config.plugins);
6016
- providerOutput = useProviderOutputCatalog(config);
6017
- runtimeConfig = resolveKVViteConfig(options, resolutionInput());
6018
- const provisionState = readProvisionStateSync(projectRoot);
6019
- if (nitroOptions) reconcileNitroCloudflareKV(nitroOptions, runtimeConfig.kv, ownedNitroNamespaces, provisionState);
6020
- if (hasNitroConfigContext(config) || isRecord(getResolvedNitroConfig(config))) nitroOwned = configureNitroCloudflareKV(config, options, resolutionInput(), ownedNitroNamespaces, provisionState);
6021
- if (!config.command && command === "build" && Reflect.get(config, "__vitehubNuxtHints")) reportRedisEnvHint({
6022
- ...config,
6023
- command
6024
- });
6008
+ handler(config) {
6009
+ return configReady = resolveRuntimeConfig(config);
6025
6010
  }
6026
6011
  },
6027
6012
  configureServer(server) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/kv",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Vite-first key-value storage primitives and integration for ViteHub.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -70,7 +70,7 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@valibot/to-json-schema": "^1.8.0",
73
- "@vite-hub/runtime": "0.7.0",
73
+ "@vite-hub/runtime": "0.9.0",
74
74
  "birpc": "^4.2.0",
75
75
  "defu": "^6.1.7",
76
76
  "destr": "^2.0.5",
@@ -84,7 +84,7 @@
84
84
  "@types/node": "^24.19.2",
85
85
  "@electric-sql/pglite": "^0.5.17",
86
86
  "@libsql/client": "^0.18.0",
87
- "@vite-hub/database": "0.7.0",
87
+ "@vite-hub/database": "0.9.0",
88
88
  "@types/pg": "^8.23.1",
89
89
  "@types/proper-lockfile": "4.1.4",
90
90
  "@vite-hub/internal": "0.0.1",
@@ -100,7 +100,7 @@
100
100
  },
101
101
  "peerDependencies": {
102
102
  "@upstash/redis": "^1.41.0",
103
- "@vite-hub/database": "0.7.0",
103
+ "@vite-hub/database": "0.9.0",
104
104
  "vite": ">=8.0.0"
105
105
  },
106
106
  "peerDependenciesMeta": {
@@ -1 +0,0 @@
1
- export { t as default } from "./fs-lite-4ccAiYae.js";