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