mirror of
https://github.com/unjs/unstorage.git
synced 2025-12-08 21:26:09 +00:00
build: esm-only dist (#686)
This commit is contained in:
parent
d1c7ce0ee7
commit
730a455ece
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@ __*
|
||||
test/fs-storage/**
|
||||
.env
|
||||
.wrangler
|
||||
tsconfig.tsbuildinfo
|
||||
|
||||
@ -1,25 +1,13 @@
|
||||
import { defineBuildConfig } from "unbuild";
|
||||
import { defineBuildConfig } from "obuild/config";
|
||||
|
||||
export default defineBuildConfig({
|
||||
declaration: true,
|
||||
rollup: {
|
||||
emitCJS: true,
|
||||
},
|
||||
entries: [
|
||||
"src/index",
|
||||
"src/server",
|
||||
{
|
||||
type: "transform",
|
||||
input: "src/drivers/",
|
||||
outDir: "drivers",
|
||||
format: "esm",
|
||||
},
|
||||
{
|
||||
input: "src/drivers/",
|
||||
outDir: "drivers",
|
||||
format: "cjs",
|
||||
ext: "cjs",
|
||||
declaration: false,
|
||||
outDir: "dist/drivers",
|
||||
},
|
||||
],
|
||||
externals: ["mongodb", "unstorage", /unstorage\/drivers\//],
|
||||
});
|
||||
|
||||
46
package.json
46
package.json
@ -6,36 +6,24 @@
|
||||
"repository": "unjs/unstorage",
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./drivers/*": {
|
||||
"types": "./drivers/*.d.ts",
|
||||
"import": "./drivers/*.mjs",
|
||||
"require": "./drivers/*.cjs"
|
||||
},
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./server": {
|
||||
"types": "./dist/server.d.ts",
|
||||
"import": "./dist/server.mjs",
|
||||
"require": "./dist/server.cjs"
|
||||
}
|
||||
"./drivers/*": "./drivers/*.mjs",
|
||||
".": "./dist/index.mjs",
|
||||
"./server": "./dist/server.mjs"
|
||||
},
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"main": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.mts",
|
||||
"files": [
|
||||
"dist",
|
||||
"drivers",
|
||||
"server.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"bench": "jiti test/server.bench.ts",
|
||||
"build": "pnpm gen-drivers && unbuild",
|
||||
"gen-drivers": "jiti scripts/gen-drivers.ts",
|
||||
"bench": "node test/server.bench.ts",
|
||||
"build": "pnpm gen-drivers && obuild",
|
||||
"dev": "vitest",
|
||||
"gen-drivers": "jiti scripts/gen-drivers.ts",
|
||||
"lint": "eslint . && prettier -c .",
|
||||
"lint:fix": "eslint . --fix && prettier -w .",
|
||||
"prepack": "pnpm build",
|
||||
@ -97,10 +85,10 @@
|
||||
"mlly": "^1.8.0",
|
||||
"mongodb": "^6.20.0",
|
||||
"mongodb-memory-server": "^10.2.1",
|
||||
"obuild": "^0.2.1",
|
||||
"prettier": "^3.6.2",
|
||||
"scule": "^1.3.0",
|
||||
"typescript": "^5.9.2",
|
||||
"unbuild": "^3.6.1",
|
||||
"uploadthing": "^7.7.4",
|
||||
"vite": "^7.1.6",
|
||||
"vitest": "^3.2.4",
|
||||
@ -125,6 +113,7 @@
|
||||
"db0": ">=0.2.1",
|
||||
"idb-keyval": "^6.2.1",
|
||||
"ioredis": "^5.4.2",
|
||||
"mongodb": "^6.20.0",
|
||||
"uploadthing": "^7.4.4"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
@ -182,21 +171,24 @@
|
||||
"ioredis": {
|
||||
"optional": true
|
||||
},
|
||||
"mongodb": {
|
||||
"optional": true
|
||||
},
|
||||
"uploadthing": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"packageManager": "pnpm@10.17.0",
|
||||
"pnpm": {
|
||||
"ignoredBuiltDependencies": [
|
||||
"@parcel/watcher",
|
||||
"sharp",
|
||||
"workerd"
|
||||
],
|
||||
"onlyBuiltDependencies": [
|
||||
"better-sqlite3",
|
||||
"esbuild",
|
||||
"mongodb-memory-server"
|
||||
],
|
||||
"ignoredBuiltDependencies": [
|
||||
"@parcel/watcher",
|
||||
"sharp",
|
||||
"workerd"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
1568
pnpm-lock.yaml
generated
1568
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
||||
import { resolve } from "node:path";
|
||||
import { defineCommand, runMain } from "citty";
|
||||
import { listen } from "listhen";
|
||||
import { createStorage } from "./storage";
|
||||
import { createStorageServer } from "./server";
|
||||
import fsDriver from "./drivers/fs";
|
||||
import { createStorage } from "./storage.ts";
|
||||
import { createStorageServer } from "./server.ts";
|
||||
import fsDriver from "./drivers/fs.ts";
|
||||
|
||||
const main = defineCommand({
|
||||
meta: {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { defineDriver, createRequiredError } from "./utils";
|
||||
import { defineDriver, createRequiredError } from "./utils/index.ts";
|
||||
import { AppConfigurationClient } from "@azure/app-configuration";
|
||||
import { DefaultAzureCredential } from "@azure/identity";
|
||||
|
||||
@ -112,7 +112,7 @@ export default defineDriver((opts: AzureAppConfigurationOptions = {}) => {
|
||||
labelFilter,
|
||||
fields: ["key", "value", "label"],
|
||||
});
|
||||
const keys = [];
|
||||
const keys: string[] = [];
|
||||
for await (const setting of settings) {
|
||||
keys.push(d(setting.key));
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { createRequiredError, defineDriver } from "./utils";
|
||||
import { createRequiredError, defineDriver } from "./utils/index.ts";
|
||||
import { Container, CosmosClient } from "@azure/cosmos";
|
||||
import { DefaultAzureCredential } from "@azure/identity";
|
||||
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { createError, createRequiredError, defineDriver } from "./utils";
|
||||
import {
|
||||
createError,
|
||||
createRequiredError,
|
||||
defineDriver,
|
||||
} from "./utils/index.ts";
|
||||
import {
|
||||
SecretClient,
|
||||
type SecretClientOptions,
|
||||
@ -77,7 +81,7 @@ export default defineDriver((opts: AzureKeyVaultOptions) => {
|
||||
const secrets = getKeyVaultClient()
|
||||
.listPropertiesOfSecrets()
|
||||
.byPage({ maxPageSize: opts.pageSize || 25 });
|
||||
const keys = [];
|
||||
const keys: string[] = [];
|
||||
for await (const page of secrets) {
|
||||
const pageKeys = page.map((secret) => decode(secret.name));
|
||||
keys.push(...pageKeys);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { createError, defineDriver } from "./utils";
|
||||
import { createError, defineDriver } from "./utils/index.ts";
|
||||
import {
|
||||
BlobServiceClient,
|
||||
ContainerClient,
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { createError, createRequiredError, defineDriver } from "./utils";
|
||||
import {
|
||||
createError,
|
||||
createRequiredError,
|
||||
defineDriver,
|
||||
} from "./utils/index.ts";
|
||||
import {
|
||||
TableClient,
|
||||
AzureNamedKeyCredential,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Preferences } from "@capacitor/preferences";
|
||||
|
||||
import { defineDriver, joinKeys, normalizeKey } from "./utils";
|
||||
import { defineDriver, joinKeys, normalizeKey } from "./utils/index.ts";
|
||||
|
||||
const DRIVER_NAME = "capacitor-preferences";
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/// <reference types="@cloudflare/workers-types" />
|
||||
import { defineDriver, joinKeys } from "./utils";
|
||||
import { getKVBinding } from "./utils/cloudflare";
|
||||
import { defineDriver, joinKeys } from "./utils/index.ts";
|
||||
import { getKVBinding } from "./utils/cloudflare.ts";
|
||||
export interface KVOptions {
|
||||
binding?: string | KVNamespace;
|
||||
|
||||
@ -24,7 +24,7 @@ export default defineDriver((opts: KVOptions) => {
|
||||
async function getKeys(base: string = "") {
|
||||
base = r(base);
|
||||
const binding = getKVBinding(opts.binding);
|
||||
const keys = [];
|
||||
const keys: { name: string }[] = [];
|
||||
let cursor: string | undefined = undefined;
|
||||
do {
|
||||
const kvList = await binding.list({ prefix: base || undefined, cursor });
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
createRequiredError,
|
||||
defineDriver,
|
||||
joinKeys,
|
||||
} from "./utils";
|
||||
} from "./utils/index.ts";
|
||||
|
||||
interface KVAuthAPIToken {
|
||||
/**
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/// <reference types="@cloudflare/workers-types" />
|
||||
import { defineDriver, joinKeys } from "./utils";
|
||||
import { getR2Binding } from "./utils/cloudflare";
|
||||
import { defineDriver, joinKeys } from "./utils/index.ts";
|
||||
import { getR2Binding } from "./utils/cloudflare.ts";
|
||||
|
||||
export interface CloudflareR2Options {
|
||||
binding?: string | R2Bucket;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { Database } from "db0";
|
||||
import { createError, defineDriver } from "./utils";
|
||||
import { createError, defineDriver } from "./utils/index.ts";
|
||||
|
||||
interface ResultSchema {
|
||||
rows: Array<{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { openKv, type Kv } from "@deno/kv";
|
||||
import { defineDriver } from "./utils/index";
|
||||
import denoKV from "./deno-kv";
|
||||
import { defineDriver } from "./utils/index.ts";
|
||||
import denoKV from "./deno-kv.ts";
|
||||
|
||||
// https://docs.deno.com/deploy/kv/manual/node/
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { defineDriver, createError, normalizeKey } from "./utils/index";
|
||||
import { defineDriver, createError, normalizeKey } from "./utils/index.ts";
|
||||
import type { Kv, KvKey } from "@deno/kv";
|
||||
|
||||
// https://docs.deno.com/deploy/kv/manual/
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
import { existsSync, promises as fsp, Stats } from "node:fs";
|
||||
import { resolve, join } from "node:path";
|
||||
import { createError, createRequiredError, defineDriver } from "./utils";
|
||||
import {
|
||||
createError,
|
||||
createRequiredError,
|
||||
defineDriver,
|
||||
} from "./utils/index.ts";
|
||||
import {
|
||||
readFile,
|
||||
writeFile,
|
||||
readdirRecursive,
|
||||
rmRecursive,
|
||||
unlink,
|
||||
} from "./utils/node-fs";
|
||||
} from "./utils/node-fs.ts";
|
||||
|
||||
export interface FSStorageOptions {
|
||||
base?: string;
|
||||
|
||||
@ -2,14 +2,18 @@ import { existsSync, promises as fsp, Stats } from "node:fs";
|
||||
import { resolve, relative, join } from "node:path";
|
||||
import { FSWatcher, type ChokidarOptions, watch } from "chokidar";
|
||||
import anymatch from "anymatch";
|
||||
import { createError, createRequiredError, defineDriver } from "./utils";
|
||||
import {
|
||||
createError,
|
||||
createRequiredError,
|
||||
defineDriver,
|
||||
} from "./utils/index.ts";
|
||||
import {
|
||||
readFile,
|
||||
writeFile,
|
||||
readdirRecursive,
|
||||
rmRecursive,
|
||||
unlink,
|
||||
} from "./utils/node-fs";
|
||||
} from "./utils/node-fs.ts";
|
||||
|
||||
export interface FSStorageOptions {
|
||||
base?: string;
|
||||
@ -29,8 +33,7 @@ export default defineDriver((userOptions: FSStorageOptions = {}) => {
|
||||
}
|
||||
|
||||
const base = resolve(userOptions.base);
|
||||
|
||||
const ignore = anymatch(
|
||||
const ignore = (anymatch as any)(
|
||||
userOptions.ignore || ["**/node_modules/**", "**/.git/**"]
|
||||
);
|
||||
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { createError, createRequiredError, defineDriver } from "./utils";
|
||||
import {
|
||||
createError,
|
||||
createRequiredError,
|
||||
defineDriver,
|
||||
} from "./utils/index.ts";
|
||||
import { $fetch } from "ofetch";
|
||||
import { withTrailingSlash, joinURL } from "ufo";
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { TransactionOptions } from "..";
|
||||
import { defineDriver } from "./utils";
|
||||
import type { TransactionOptions } from "../types.ts";
|
||||
import { defineDriver } from "./utils/index.ts";
|
||||
import { type FetchError, $fetch as _fetch } from "ofetch";
|
||||
import { joinURL } from "ufo";
|
||||
|
||||
@ -69,8 +69,8 @@ export default defineDriver((opts: HTTPOptions) => {
|
||||
method: "HEAD",
|
||||
headers: getHeaders(topts),
|
||||
});
|
||||
let mtime = undefined;
|
||||
let ttl = undefined;
|
||||
let mtime: Date | undefined;
|
||||
let ttl: number | undefined;
|
||||
const _lastModified = res.headers.get("last-modified");
|
||||
if (_lastModified) {
|
||||
mtime = new Date(_lastModified);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { defineDriver } from "./utils";
|
||||
import { defineDriver } from "./utils/index.ts";
|
||||
import {
|
||||
get,
|
||||
set,
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { createRequiredError, defineDriver, normalizeKey } from "./utils";
|
||||
import {
|
||||
createRequiredError,
|
||||
defineDriver,
|
||||
normalizeKey,
|
||||
} from "./utils/index.ts";
|
||||
|
||||
export interface LocalStorageOptions {
|
||||
base?: string;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { defineDriver } from "./utils";
|
||||
import { defineDriver } from "./utils/index.ts";
|
||||
import { LRUCache } from "lru-cache";
|
||||
|
||||
type LRUCacheOptions = LRUCache.OptionsBase<string, any, any> &
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { defineDriver } from "./utils";
|
||||
import { defineDriver } from "./utils/index.ts";
|
||||
|
||||
const DRIVER_NAME = "memory";
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { createRequiredError, defineDriver } from "./utils";
|
||||
import { createRequiredError, defineDriver } from "./utils/index.ts";
|
||||
import { MongoClient, type Collection, type MongoClientOptions } from "mongodb";
|
||||
|
||||
export interface MongoDbOptions {
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import { createError, createRequiredError, defineDriver } from "./utils";
|
||||
import type { GetKeysOptions } from "..";
|
||||
import {
|
||||
createError,
|
||||
createRequiredError,
|
||||
defineDriver,
|
||||
} from "./utils/index.ts";
|
||||
import type { GetKeysOptions } from "../types.ts";
|
||||
import { getStore, getDeployStore } from "@netlify/blobs";
|
||||
import type {
|
||||
Store,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { defineDriver } from "./utils";
|
||||
import { defineDriver } from "./utils/index.ts";
|
||||
|
||||
const DRIVER_NAME = "null";
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { defineDriver } from "./utils";
|
||||
import type { Driver } from "..";
|
||||
import { normalizeKey } from "./utils";
|
||||
import { defineDriver } from "./utils/index.ts";
|
||||
import type { Driver } from "../types.ts";
|
||||
import { normalizeKey } from "./utils/index.ts";
|
||||
|
||||
export interface OverlayStorageOptions {
|
||||
layers: Driver[];
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { createRequiredError, defineDriver } from "./utils";
|
||||
import { createRequiredError, defineDriver } from "./utils/index.ts";
|
||||
import type { ExecutedQuery, Connection } from "@planetscale/database";
|
||||
import { connect } from "@planetscale/database";
|
||||
import { fetch } from "node-fetch-native";
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { defineDriver, joinKeys } from "./utils";
|
||||
// TODO: use named import in v2
|
||||
import Redis, {
|
||||
Cluster,
|
||||
type ClusterNode,
|
||||
type ClusterOptions,
|
||||
type RedisOptions as _RedisOptions,
|
||||
import { defineDriver, joinKeys } from "./utils/index.ts";
|
||||
import { Cluster, Redis } from "ioredis";
|
||||
|
||||
import type {
|
||||
ClusterOptions,
|
||||
ClusterNode,
|
||||
RedisOptions as _RedisOptions,
|
||||
} from "ioredis";
|
||||
|
||||
export interface RedisOptions extends _RedisOptions {
|
||||
|
||||
@ -3,7 +3,7 @@ import {
|
||||
createRequiredError,
|
||||
normalizeKey,
|
||||
createError,
|
||||
} from "./utils";
|
||||
} from "./utils/index.ts";
|
||||
import { AwsClient } from "aws4fetch";
|
||||
|
||||
export interface S3DriverOptions {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { defineDriver } from "./utils";
|
||||
import localstorage, { type LocalStorageOptions } from "./localstorage";
|
||||
import { defineDriver } from "./utils/index.ts";
|
||||
import localstorage, { type LocalStorageOptions } from "./localstorage.ts";
|
||||
|
||||
export interface SessionStorageOptions extends LocalStorageOptions {}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { defineDriver, normalizeKey } from "./utils";
|
||||
import { defineDriver, normalizeKey } from "./utils/index.ts";
|
||||
import { UTApi } from "uploadthing/server";
|
||||
|
||||
// Reference: https://docs.uploadthing.com
|
||||
@ -39,7 +39,7 @@ export default defineDriver<UploadThingOptions, UTApi>((opts = {}) => {
|
||||
};
|
||||
|
||||
const toFile = (key: string, value: BlobPart) => {
|
||||
return Object.assign(new Blob([value]), <FileEsque>{
|
||||
return Object.assign(new Blob([value]), {
|
||||
name: key,
|
||||
customId: key,
|
||||
}) satisfies FileEsque;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { type RedisConfigNodejs, Redis } from "@upstash/redis";
|
||||
import { defineDriver, normalizeKey, joinKeys } from "./utils";
|
||||
import { defineDriver, normalizeKey, joinKeys } from "./utils/index.ts";
|
||||
|
||||
export interface UpstashOptions extends Partial<RedisConfigNodejs> {
|
||||
/**
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/// <reference types="@cloudflare/workers-types" />
|
||||
import { createError } from "./index";
|
||||
import { createError } from "./index.ts";
|
||||
|
||||
export function getBinding(binding: KVNamespace | R2Bucket | string) {
|
||||
let bindingName = "[binding]";
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { Driver } from "../..";
|
||||
import type { Driver } from "../../types.ts";
|
||||
|
||||
type DriverFactory<OptionsT, InstanceT> = (
|
||||
opts: OptionsT
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
import { del, head, list, put } from "@vercel/blob";
|
||||
import { defineDriver, normalizeKey, joinKeys, createError } from "./utils";
|
||||
import {
|
||||
defineDriver,
|
||||
normalizeKey,
|
||||
joinKeys,
|
||||
createError,
|
||||
} from "./utils/index.ts";
|
||||
|
||||
export interface VercelBlobOptions {
|
||||
/**
|
||||
@ -106,7 +111,7 @@ export default defineDriver<VercelBlobOptions>((opts) => {
|
||||
if (blob) await del(blob.url, { token: getToken() });
|
||||
},
|
||||
async getKeys(base: string) {
|
||||
const blobs = [];
|
||||
const blobs: any[] = [];
|
||||
let cursor: string | undefined = undefined;
|
||||
do {
|
||||
const listBlobResult: Awaited<ReturnType<typeof list>> = await list({
|
||||
@ -128,7 +133,7 @@ export default defineDriver<VercelBlobOptions>((opts) => {
|
||||
},
|
||||
async clear(base) {
|
||||
let cursor: string | undefined = undefined;
|
||||
const blobs = [];
|
||||
const blobs: any[] = [];
|
||||
do {
|
||||
const listBlobResult: Awaited<ReturnType<typeof list>> = await list({
|
||||
token: getToken(),
|
||||
|
||||
@ -2,7 +2,12 @@ import { createClient } from "@vercel/kv";
|
||||
import type { VercelKV } from "@vercel/kv";
|
||||
import type { RedisConfigNodejs } from "@upstash/redis";
|
||||
|
||||
import { defineDriver, normalizeKey, joinKeys, createError } from "./utils";
|
||||
import {
|
||||
defineDriver,
|
||||
normalizeKey,
|
||||
joinKeys,
|
||||
createError,
|
||||
} from "./utils/index.ts";
|
||||
|
||||
export interface VercelKVOptions extends Partial<RedisConfigNodejs> {
|
||||
/**
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { defineDriver, normalizeKey, joinKeys } from "./utils";
|
||||
import { defineDriver, normalizeKey, joinKeys } from "./utils/index.ts";
|
||||
import type { RuntimeCache } from "@vercel/functions";
|
||||
|
||||
export interface VercelCacheOptions {
|
||||
|
||||
10
src/index.ts
10
src/index.ts
@ -1,11 +1,11 @@
|
||||
export * from "./storage";
|
||||
export * from "./types";
|
||||
export * from "./utils";
|
||||
export * from "./storage.ts";
|
||||
export * from "./types.ts";
|
||||
export * from "./utils.ts";
|
||||
|
||||
export { defineDriver } from "./drivers/utils";
|
||||
export { defineDriver } from "./drivers/utils/index.ts";
|
||||
|
||||
export {
|
||||
builtinDrivers,
|
||||
type BuiltinDriverName,
|
||||
type BuiltinDriverOptions,
|
||||
} from "./_drivers";
|
||||
} from "./_drivers.ts";
|
||||
|
||||
@ -11,9 +11,9 @@ import {
|
||||
type EventHandler,
|
||||
H3Event,
|
||||
} from "h3";
|
||||
import type { Storage, TransactionOptions, StorageMeta } from "./types";
|
||||
import { stringify } from "./_utils";
|
||||
import { normalizeKey, normalizeBaseKey } from "./utils";
|
||||
import type { Storage, TransactionOptions, StorageMeta } from "./types.ts";
|
||||
import { stringify } from "./_utils.ts";
|
||||
import { normalizeKey, normalizeBaseKey } from "./utils.ts";
|
||||
|
||||
export type StorageServerRequest = {
|
||||
event: H3Event;
|
||||
|
||||
@ -7,16 +7,21 @@ import type {
|
||||
StorageValue,
|
||||
WatchEvent,
|
||||
TransactionOptions,
|
||||
} from "./types";
|
||||
import memory from "./drivers/memory";
|
||||
import { asyncCall, deserializeRaw, serializeRaw, stringify } from "./_utils";
|
||||
} from "./types.ts";
|
||||
import memory from "./drivers/memory.ts";
|
||||
import {
|
||||
asyncCall,
|
||||
deserializeRaw,
|
||||
serializeRaw,
|
||||
stringify,
|
||||
} from "./_utils.ts";
|
||||
import {
|
||||
normalizeKey,
|
||||
normalizeBaseKey,
|
||||
joinKeys,
|
||||
filterKeyByDepth,
|
||||
filterKeyByBase,
|
||||
} from "./utils";
|
||||
} from "./utils.ts";
|
||||
|
||||
interface StorageCTX {
|
||||
mounts: Record<string, Driver>;
|
||||
@ -347,7 +352,7 @@ export function createStorage<T extends StorageValue>(
|
||||
base = normalizeBaseKey(base);
|
||||
const mounts = getMounts(base, true);
|
||||
let maskedMounts: string[] = [];
|
||||
const allKeys = [];
|
||||
const allKeys: string[] = [];
|
||||
let allMountsSupportMaxDepth = true;
|
||||
for (const mount of mounts) {
|
||||
if (!mount.driver.flags?.maxDepth) {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { Storage, StorageValue, TransactionOptions } from "./types";
|
||||
import type { Storage, StorageValue, TransactionOptions } from "./types.ts";
|
||||
|
||||
type StorageKeys = Array<keyof Storage>;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import driver from "../../src/drivers/azure-app-configuration";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/azure-app-configuration.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe.skip("drivers: azure-app-configuration", () => {
|
||||
testDriver({
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import driver from "../../src/drivers/azure-cosmos";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/azure-cosmos.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe.skip("drivers: azure-cosmos", () => {
|
||||
testDriver({
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import driver from "../../src/drivers/azure-key-vault";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/azure-key-vault.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe.skip(
|
||||
"drivers: azure-key-vault",
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { describe, expect, beforeAll, afterAll, test } from "vitest";
|
||||
import driver from "../../src/drivers/azure-storage-blob";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/azure-storage-blob.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { AccountSASPermissions, BlobServiceClient } from "@azure/storage-blob";
|
||||
import { ChildProcess, exec } from "node:child_process";
|
||||
import { createStorage } from "../../src";
|
||||
import { createStorage } from "../../src/index.ts";
|
||||
|
||||
describe.skip("drivers: azure-storage-blob", () => {
|
||||
let azuriteProcess: ChildProcess;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, beforeAll, afterAll } from "vitest";
|
||||
import driver from "../../src/drivers/azure-storage-table";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/azure-storage-table.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { TableClient } from "@azure/data-tables";
|
||||
import { ChildProcess, exec } from "node:child_process";
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, vi } from "vitest";
|
||||
import driver from "../../src/drivers/capacitor-preferences";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/capacitor-preferences.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { afterEach } from "node:test";
|
||||
|
||||
vi.mock("@capacitor/preferences", () => {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/// <reference types="@cloudflare/workers-types" />
|
||||
import { describe, expect, test, afterAll } from "vitest";
|
||||
import { createStorage, snapshot } from "../../src";
|
||||
import CloudflareKVBinding from "../../src/drivers/cloudflare-kv-binding";
|
||||
import { testDriver } from "./utils";
|
||||
import { createStorage, snapshot } from "../../src/index.ts";
|
||||
import CloudflareKVBinding from "../../src/drivers/cloudflare-kv-binding.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { getPlatformProxy } from "wrangler";
|
||||
|
||||
describe("drivers: cloudflare-kv", async () => {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import cfKvHttpDriver from "../../src/drivers/cloudflare-kv-http";
|
||||
import { testDriver } from "./utils";
|
||||
import cfKvHttpDriver from "../../src/drivers/cloudflare-kv-http.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
const accountId = process.env.VITE_CLOUDFLARE_ACC_ID;
|
||||
const namespaceId = process.env.VITE_CLOUDFLARE_KV_NS_ID;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/// <reference types="@cloudflare/workers-types" />
|
||||
import { describe, test, expect, afterAll } from "vitest";
|
||||
import { createStorage, snapshot } from "../../src";
|
||||
import CloudflareR2Binding from "../../src/drivers/cloudflare-r2-binding";
|
||||
import { testDriver } from "./utils";
|
||||
import { createStorage, snapshot } from "../../src/index.ts";
|
||||
import CloudflareR2Binding from "../../src/drivers/cloudflare-r2-binding.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { getPlatformProxy } from "wrangler";
|
||||
|
||||
describe("drivers: cloudflare-r2-binding", async () => {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { afterAll, describe, expect, it } from "vitest";
|
||||
import { createDatabase } from "db0";
|
||||
import db0Driver from "../../src/drivers/db0";
|
||||
import { testDriver } from "./utils";
|
||||
import db0Driver from "../../src/drivers/db0.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
const drivers = [
|
||||
{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { createServer } from "node:http";
|
||||
import { createStorage } from "../../src";
|
||||
import { createStorage } from "../../src/index.ts";
|
||||
import denoKV from "../../src/drivers/deno-kv.ts";
|
||||
import { createStorageServer } from "../../src/server";
|
||||
import { createStorageServer } from "../../src/server.ts";
|
||||
|
||||
const storage = createStorage({
|
||||
driver: denoKV({
|
||||
|
||||
@ -3,7 +3,7 @@ import { exec, execSync, type ChildProcess } from "node:child_process";
|
||||
import { describe, beforeAll, afterAll } from "vitest";
|
||||
import { getRandomPort, waitForPort } from "get-port-please";
|
||||
import httpDriver from "../../src/drivers/http.ts";
|
||||
import { testDriver } from "./utils";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
let hasDeno: boolean;
|
||||
// prettier-ignore
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { resolve } from "node:path";
|
||||
import { readFile } from "../../src/drivers/utils/node-fs";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/fs-lite";
|
||||
import { readFile } from "../../src/drivers/utils/node-fs.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import driver from "../../src/drivers/fs-lite.ts";
|
||||
|
||||
describe("drivers: fs-lite", () => {
|
||||
const dir = resolve(__dirname, "tmp/fs-lite");
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { resolve } from "node:path";
|
||||
import { readFile, writeFile } from "../../src/drivers/utils/node-fs";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/fs";
|
||||
import { readFile, writeFile } from "../../src/drivers/utils/node-fs.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import driver from "../../src/drivers/fs.ts";
|
||||
|
||||
describe("drivers: fs", () => {
|
||||
const dir = resolve(__dirname, "tmp/fs");
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import driver from "../../src/drivers/github";
|
||||
import { createStorage } from "../../src";
|
||||
import driver from "../../src/drivers/github.ts";
|
||||
import { createStorage } from "../../src/index.ts";
|
||||
|
||||
describe("drivers: github", () => {
|
||||
const storage = createStorage({
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { describe, afterAll, expect, it } from "vitest";
|
||||
import driver from "../../src/drivers/http";
|
||||
import { createStorage } from "../../src";
|
||||
import { createStorageServer } from "../../src/server";
|
||||
import driver from "../../src/drivers/http.ts";
|
||||
import { createStorage } from "../../src/index.ts";
|
||||
import { createStorageServer } from "../../src/server.ts";
|
||||
import { listen } from "listhen";
|
||||
import { testDriver } from "./utils";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe("drivers: http", async () => {
|
||||
const remoteStorage = createStorage();
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import driver from "../../src/drivers/indexedb";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/indexedb.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import "fake-indexeddb/auto";
|
||||
import { createStorage } from "../../src";
|
||||
import { createStorage } from "../../src/index.ts";
|
||||
|
||||
describe("drivers: indexeddb", () => {
|
||||
testDriver({ driver: driver({ dbName: "test-db" }) });
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import driver from "../../src/drivers/localstorage";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/localstorage.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { JSDOM } from "jsdom";
|
||||
|
||||
describe("drivers: localstorage", () => {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { it, describe, expect } from "vitest";
|
||||
import driver from "../../src/drivers/lru-cache";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/lru-cache.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe("drivers: lru-cache", () => {
|
||||
testDriver({
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import driver from "../../src/drivers/memory";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/memory.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe("drivers: memory", () => {
|
||||
testDriver({
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { afterAll, describe, expect, it } from "vitest";
|
||||
import driver from "../../src/drivers/mongodb";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/mongodb.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { MongoMemoryServer } from "mongodb-memory-server";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { afterAll, beforeAll, describe } from "vitest";
|
||||
import driver from "../../src/drivers/netlify-blobs";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/netlify-blobs.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { BlobsServer } from "@netlify/blobs/server";
|
||||
import { resolve } from "node:path";
|
||||
import { rm, mkdir } from "node:fs/promises";
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import driver from "../../src/drivers/null";
|
||||
import { createStorage } from "../../src";
|
||||
import driver from "../../src/drivers/null.ts";
|
||||
import { createStorage } from "../../src/index.ts";
|
||||
|
||||
describe("drivers: null", async () => {
|
||||
const storage = createStorage({ driver: driver() });
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { describe } from "vitest";
|
||||
import driver from "../../src/drivers/overlay";
|
||||
import memory from "../../src/drivers/memory";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/overlay.ts";
|
||||
import memory from "../../src/drivers/memory.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe("drivers: overlay", () => {
|
||||
const [s1, s2] = [memory(), memory()];
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { describe, vi, it, expect } from "vitest";
|
||||
import * as ioredis from "ioredis-mock";
|
||||
import redisDriver from "../../src/drivers/redis";
|
||||
import { testDriver } from "./utils";
|
||||
import * as ioredisMock from "ioredis-mock";
|
||||
import redisDriver from "../../src/drivers/redis.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
vi.mock("ioredis", () => ioredis);
|
||||
vi.mock("ioredis", () => ({ ...ioredisMock, Redis: ioredisMock.default }));
|
||||
|
||||
describe("drivers: redis", () => {
|
||||
const driver = redisDriver({
|
||||
@ -20,7 +20,9 @@ describe("drivers: redis", () => {
|
||||
await ctx.storage.setItem("s2:a", "test_data");
|
||||
await ctx.storage.setItem("s3:a?q=1", "test_data");
|
||||
|
||||
const client = new ioredis.default("ioredis://localhost:6379/0");
|
||||
const client = new (ioredisMock as any).default(
|
||||
"ioredis://localhost:6379/0"
|
||||
);
|
||||
const keys = await client.keys("*");
|
||||
expect(keys).toMatchInlineSnapshot(`
|
||||
[
|
||||
@ -33,7 +35,9 @@ describe("drivers: redis", () => {
|
||||
});
|
||||
|
||||
it("exposes instance", () => {
|
||||
expect(driver.getInstance?.()).toBeInstanceOf(ioredis.default);
|
||||
expect(driver.getInstance?.()).toBeInstanceOf(
|
||||
(ioredisMock as any).default
|
||||
);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import s3Driver from "../../src/drivers/s3";
|
||||
import { testDriver } from "./utils";
|
||||
import s3Driver from "../../src/drivers/s3.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import { AwsClient } from "aws4fetch";
|
||||
|
||||
const accessKeyId = process.env.VITE_S3_ACCESS_KEY_ID;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { JSDOM } from "jsdom";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import driver from "../../src/drivers/session-storage";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/session-storage.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe("drivers: session-storage", () => {
|
||||
const jsdom = new JSDOM("", {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import driver from "../../src/drivers/uploadthing";
|
||||
import { testDriver } from "./utils";
|
||||
import driver from "../../src/drivers/uploadthing.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
const utfsToken = process.env.VITE_UPLOADTHING_TOKEN;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import { testDriver } from "./utils";
|
||||
import upstashDriver from "../../src/drivers/upstash";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import upstashDriver from "../../src/drivers/upstash.ts";
|
||||
|
||||
const url = process.env.VITE_UPSTASH_REDIS_REST_URL;
|
||||
const token = process.env.VITE_UPSTASH_REDIS_REST_TOKEN;
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
type Driver,
|
||||
createStorage,
|
||||
restoreSnapshot,
|
||||
} from "../../src";
|
||||
} from "../../src/index.ts";
|
||||
|
||||
export interface TestContext {
|
||||
storage: Storage;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import { testDriver } from "./utils";
|
||||
import vercelBlobDriver from "../../src/drivers/vercel-blob";
|
||||
import { testDriver } from "./utils.ts";
|
||||
import vercelBlobDriver from "../../src/drivers/vercel-blob.ts";
|
||||
|
||||
const token = process.env.VITE_VERCEL_BLOB_READ_WRITE_TOKEN;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe } from "vitest";
|
||||
import vercelKVDriver from "../../src/drivers/vercel-kv";
|
||||
import { testDriver } from "./utils";
|
||||
import vercelKVDriver from "../../src/drivers/vercel-kv.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
const hasEnv = process.env.KV_REST_API_URL && process.env.KV_REST_API_TOKEN;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import vercelRuntimeCacheDriver from "../../src/drivers/vercel-runtime-cache";
|
||||
import { testDriver } from "./utils";
|
||||
import vercelRuntimeCacheDriver from "../../src/drivers/vercel-runtime-cache.ts";
|
||||
import { testDriver } from "./utils.ts";
|
||||
|
||||
describe("drivers: vercel-runtime-cache", async () => {
|
||||
testDriver({
|
||||
|
||||
@ -2,8 +2,8 @@ import { readFile } from "node:fs/promises";
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { listen } from "listhen";
|
||||
import { $fetch } from "ofetch";
|
||||
import { createStorage } from "../src";
|
||||
import { createStorageServer } from "../src/server";
|
||||
import { createStorage } from "../src/index.ts";
|
||||
import { createStorageServer } from "../src/server.ts";
|
||||
import fsDriver from "../src/drivers/fs.ts";
|
||||
import httpDriver from "../src/drivers/http.ts";
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { describe, it, expectTypeOf } from "vitest";
|
||||
import { createStorage, prefixStorage } from "../src";
|
||||
import type { Storage, StorageValue } from "../src";
|
||||
import { createStorage, prefixStorage } from "../src/index.ts";
|
||||
import type { Storage, StorageValue } from "../src/index.ts";
|
||||
|
||||
describe("types", () => {
|
||||
it("default types for storage", async () => {
|
||||
|
||||
@ -5,9 +5,9 @@ import {
|
||||
snapshot,
|
||||
restoreSnapshot,
|
||||
prefixStorage,
|
||||
} from "../src";
|
||||
import memory from "../src/drivers/memory";
|
||||
import fs from "../src/drivers/fs";
|
||||
} from "../src/index.ts";
|
||||
import memory from "../src/drivers/memory.ts";
|
||||
import fs from "../src/drivers/fs.ts";
|
||||
|
||||
const data = {
|
||||
"etc:conf": "test",
|
||||
|
||||
@ -1,25 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "preserve",
|
||||
"moduleResolution": "bundler",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"moduleDetection": "force",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"allowJs": true,
|
||||
"resolveJsonModule": true,
|
||||
"strict": true,
|
||||
"isolatedModules": true,
|
||||
"isolatedModules": false, // TODO
|
||||
"verbatimModuleSyntax": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitAny": false, // TODO
|
||||
"noImplicitOverride": true,
|
||||
"noEmit": true,
|
||||
"allowImportingTsExtensions": true,
|
||||
"skipLibCheck": true,
|
||||
"composite": true,
|
||||
// "isolatedDeclarations": true,
|
||||
"allowImportingTsExtensions": true,
|
||||
"types": ["node", "deno"],
|
||||
"paths": {
|
||||
"unstorage/drivers/*": ["./src/drivers/*"]
|
||||
"unstorage/drivers/*": ["./src/drivers/*.ts"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"include": ["src", "test"]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user