@upstash/redis
Advanced tools
Comparing version 0.1.5 to 0.1.6
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -19,8 +10,8 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
*/ | ||
function parseOptions(url, token, edgeUrl, readFromEdge) { | ||
function parseOptions(url, token, edgeUrl, readFromEdge, requestOptions = {}) { | ||
if (typeof url === 'object' && url !== null) { | ||
return parseOptions(url.url, url.token, url.edgeUrl, url.readFromEdge); | ||
return parseOptions(url.url, url.token, url.edgeUrl, url.readFromEdge, url.requestOptions); | ||
} | ||
// try auto fill from env variables | ||
if (!url && typeof window === 'undefined') { | ||
// try auto fill from env variables | ||
url = process.env.UPSTASH_REDIS_REST_URL; | ||
@@ -30,4 +21,6 @@ token = process.env.UPSTASH_REDIS_REST_TOKEN; | ||
} | ||
readFromEdge = edgeUrl ? readFromEdge !== null && readFromEdge !== void 0 ? readFromEdge : true : false; | ||
return edgeUrl ? { url, token, edgeUrl, readFromEdge } : { url, token }; | ||
readFromEdge = edgeUrl ? readFromEdge ?? true : false; | ||
return edgeUrl | ||
? { url: url, token, edgeUrl, readFromEdge, requestOptions } | ||
: { url: url, token, requestOptions }; | ||
} | ||
@@ -37,39 +30,45 @@ /** | ||
*/ | ||
function fetchData(url, options, init) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const res = yield (0, isomorphic_unfetch_1.default)(url, Object.assign(Object.assign({}, init), { headers: Object.assign({ Authorization: `Bearer ${options.token}` }, init.headers) })); | ||
const data = yield res.json(); | ||
if (!res.ok) { | ||
if (data.error) | ||
throw data.error; | ||
throw `Upstash failed with (${res.status}): ${JSON.stringify(data, null, 2)}`; | ||
} | ||
let edge = false; | ||
let cache = null; | ||
switch (res.headers.get('x-cache')) { | ||
case 'Hit from cloudfront': | ||
edge = true; | ||
cache = 'hit'; | ||
break; | ||
case 'Miss from cloudfront': | ||
edge = true; | ||
cache = 'miss'; | ||
break; | ||
} | ||
return { | ||
data: data.result, | ||
error: null, | ||
metadata: { edge, cache }, | ||
}; | ||
async function fetchData(url, options, init) { | ||
try { | ||
const res = await (0, isomorphic_unfetch_1.default)(url, { | ||
...init, | ||
headers: { | ||
Authorization: `Bearer ${options.token}`, | ||
...init.headers, | ||
...options.requestOptions?.headers, | ||
}, | ||
...options.requestOptions, | ||
}); | ||
const data = await res.json(); | ||
if (!res.ok) { | ||
if (data.error) | ||
throw data.error; | ||
throw `Upstash failed with (${res.status}): ${JSON.stringify(data, null, 2)}`; | ||
} | ||
catch (err) { | ||
return { | ||
data: null, | ||
// @ts-ignore | ||
error: err, | ||
metadata: { edge: false, cache: null }, | ||
}; | ||
let edge = false; | ||
let cache = null; | ||
switch (res.headers.get('x-cache')) { | ||
case 'Hit from cloudfront': | ||
edge = true; | ||
cache = 'hit'; | ||
break; | ||
case 'Miss from cloudfront': | ||
edge = true; | ||
cache = 'miss'; | ||
break; | ||
} | ||
}); | ||
return { | ||
data: data.result, | ||
error: null, | ||
metadata: { edge, cache }, | ||
}; | ||
} | ||
catch (err) { | ||
return { | ||
data: null, | ||
// @ts-ignore | ||
error: err, | ||
metadata: { edge: false, cache: null }, | ||
}; | ||
} | ||
} | ||
@@ -80,3 +79,2 @@ /** | ||
function request(options, config, ...parts) { | ||
var _a; | ||
if (!options.url) { | ||
@@ -86,3 +84,3 @@ throw 'Database url not found?'; | ||
if (!options.edgeUrl) { | ||
if (options.readFromEdge || (config === null || config === void 0 ? void 0 : config.edge)) { | ||
if (options.readFromEdge || config?.edge) { | ||
throw 'You need to set Edge Url to read from edge.'; | ||
@@ -96,3 +94,3 @@ } | ||
else if (options.edgeUrl) { | ||
fromEdge = (_a = config === null || config === void 0 ? void 0 : config.edge) !== null && _a !== void 0 ? _a : true; | ||
fromEdge = config?.edge ?? true; | ||
} | ||
@@ -99,0 +97,0 @@ if (fromEdge) { |
@@ -6,2 +6,3 @@ export declare type ClientObjectProps = { | ||
readFromEdge?: boolean; | ||
requestOptions?: undefined | RequestInit; | ||
}; | ||
@@ -8,0 +9,0 @@ export declare type EdgeCacheType = null | 'miss' | 'hit'; |
@@ -1,25 +0,11 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch")); | ||
import fetch from 'isomorphic-unfetch'; | ||
/** | ||
* Parse Options | ||
*/ | ||
function parseOptions(url, token, edgeUrl, readFromEdge) { | ||
function parseOptions(url, token, edgeUrl, readFromEdge, requestOptions = {}) { | ||
if (typeof url === 'object' && url !== null) { | ||
return parseOptions(url.url, url.token, url.edgeUrl, url.readFromEdge); | ||
return parseOptions(url.url, url.token, url.edgeUrl, url.readFromEdge, url.requestOptions); | ||
} | ||
// try auto fill from env variables | ||
if (!url && typeof window === 'undefined') { | ||
// try auto fill from env variables | ||
url = process.env.UPSTASH_REDIS_REST_URL; | ||
@@ -29,4 +15,6 @@ token = process.env.UPSTASH_REDIS_REST_TOKEN; | ||
} | ||
readFromEdge = edgeUrl ? readFromEdge !== null && readFromEdge !== void 0 ? readFromEdge : true : false; | ||
return edgeUrl ? { url, token, edgeUrl, readFromEdge } : { url, token }; | ||
readFromEdge = edgeUrl ? readFromEdge ?? true : false; | ||
return edgeUrl | ||
? { url: url, token, edgeUrl, readFromEdge, requestOptions } | ||
: { url: url, token, requestOptions }; | ||
} | ||
@@ -36,39 +24,45 @@ /** | ||
*/ | ||
function fetchData(url, options, init) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const res = yield (0, isomorphic_unfetch_1.default)(url, Object.assign(Object.assign({}, init), { headers: Object.assign({ Authorization: `Bearer ${options.token}` }, init.headers) })); | ||
const data = yield res.json(); | ||
if (!res.ok) { | ||
if (data.error) | ||
throw data.error; | ||
throw `Upstash failed with (${res.status}): ${JSON.stringify(data, null, 2)}`; | ||
} | ||
let edge = false; | ||
let cache = null; | ||
switch (res.headers.get('x-cache')) { | ||
case 'Hit from cloudfront': | ||
edge = true; | ||
cache = 'hit'; | ||
break; | ||
case 'Miss from cloudfront': | ||
edge = true; | ||
cache = 'miss'; | ||
break; | ||
} | ||
return { | ||
data: data.result, | ||
error: null, | ||
metadata: { edge, cache }, | ||
}; | ||
async function fetchData(url, options, init) { | ||
try { | ||
const res = await fetch(url, { | ||
...init, | ||
headers: { | ||
Authorization: `Bearer ${options.token}`, | ||
...init.headers, | ||
...options.requestOptions?.headers, | ||
}, | ||
...options.requestOptions, | ||
}); | ||
const data = await res.json(); | ||
if (!res.ok) { | ||
if (data.error) | ||
throw data.error; | ||
throw `Upstash failed with (${res.status}): ${JSON.stringify(data, null, 2)}`; | ||
} | ||
catch (err) { | ||
return { | ||
data: null, | ||
// @ts-ignore | ||
error: err, | ||
metadata: { edge: false, cache: null }, | ||
}; | ||
let edge = false; | ||
let cache = null; | ||
switch (res.headers.get('x-cache')) { | ||
case 'Hit from cloudfront': | ||
edge = true; | ||
cache = 'hit'; | ||
break; | ||
case 'Miss from cloudfront': | ||
edge = true; | ||
cache = 'miss'; | ||
break; | ||
} | ||
}); | ||
return { | ||
data: data.result, | ||
error: null, | ||
metadata: { edge, cache }, | ||
}; | ||
} | ||
catch (err) { | ||
return { | ||
data: null, | ||
// @ts-ignore | ||
error: err, | ||
metadata: { edge: false, cache: null }, | ||
}; | ||
} | ||
} | ||
@@ -79,3 +73,2 @@ /** | ||
function request(options, config, ...parts) { | ||
var _a; | ||
if (!options.url) { | ||
@@ -85,3 +78,3 @@ throw 'Database url not found?'; | ||
if (!options.edgeUrl) { | ||
if (options.readFromEdge || (config === null || config === void 0 ? void 0 : config.edge)) { | ||
if (options.readFromEdge || config?.edge) { | ||
throw 'You need to set Edge Url to read from edge.'; | ||
@@ -95,3 +88,3 @@ } | ||
else if (options.edgeUrl) { | ||
fromEdge = (_a = config === null || config === void 0 ? void 0 : config.edge) !== null && _a !== void 0 ? _a : true; | ||
fromEdge = config?.edge ?? true; | ||
} | ||
@@ -620,2 +613,2 @@ if (fromEdge) { | ||
} | ||
exports.default = upstash; | ||
export default upstash; |
@@ -1,12 +0,3 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.randomkey = exports.pttl = exports.pexpireat = exports.pexpire = exports.persist = exports.keys = exports.expireat = exports.expire = exports.exists = exports.del = exports.hvals = exports.hsetnx = exports.hset = exports.hscan = exports.hmset = exports.hmget = exports.hlen = exports.hkeys = exports.hincrbyfloat = exports.hincrby = exports.hgetall = exports.hget = exports.hexists = exports.hdel = exports.ping = exports.echo = exports.setbit = exports.getbit = exports.bitpos = exports.bitop = exports.bitcount = exports.strlen = exports.setrange = exports.setnx = exports.setex = exports.set = exports.psetex = exports.msetnx = exports.mset = exports.mget = exports.incrbyfloat = exports.incrby = exports.incr = exports.getset = exports.getrange = exports.get = exports.decrby = exports.decr = exports.append = exports.auth = void 0; | ||
exports.zrangebylex = exports.zrange = exports.zpopmin = exports.zpopmax = exports.zlexcount = exports.zinterstore = exports.zincrby = exports.zcount = exports.zcard = exports.zadd = exports.sunionstore = exports.sunion = exports.srem = exports.srandmember = exports.spop = exports.smove = exports.smembers = exports.sismember = exports.sinterstore = exports.sinter = exports.sdiffstore = exports.sdiff = exports.scard = exports.sadd = exports.time = exports.info = exports.flushdb = exports.flushall = exports.dbsize = exports.rpushx = exports.rpush = exports.rpoplpush = exports.rpop = exports.ltrim = exports.lset = exports.lrem = exports.lrange = exports.lpushx = exports.lpush = exports.lpop = exports.llen = exports.linsert = exports.lindex = exports.unlink = exports.type = exports.ttl = exports.touch = exports.scan = exports.renamenx = exports.rename = void 0; | ||
exports.zunionstore = exports.zscore = exports.zrevrank = exports.zrevrangebyscore = exports.zrevrangebylex = exports.zrevrange = exports.zremrangebyscore = exports.zremrangebyrank = exports.zremrangebylex = exports.zrem = exports.zrank = exports.zrangebyscore = void 0; | ||
const client_1 = __importDefault(require("./client")); | ||
exports.default = client_1.default; | ||
_a = (0, client_1.default)(), exports.auth = _a.auth, exports.append = _a.append, exports.decr = _a.decr, exports.decrby = _a.decrby, exports.get = _a.get, exports.getrange = _a.getrange, exports.getset = _a.getset, exports.incr = _a.incr, exports.incrby = _a.incrby, exports.incrbyfloat = _a.incrbyfloat, exports.mget = _a.mget, exports.mset = _a.mset, exports.msetnx = _a.msetnx, exports.psetex = _a.psetex, exports.set = _a.set, exports.setex = _a.setex, exports.setnx = _a.setnx, exports.setrange = _a.setrange, exports.strlen = _a.strlen, exports.bitcount = _a.bitcount, exports.bitop = _a.bitop, exports.bitpos = _a.bitpos, exports.getbit = _a.getbit, exports.setbit = _a.setbit, exports.echo = _a.echo, exports.ping = _a.ping, exports.hdel = _a.hdel, exports.hexists = _a.hexists, exports.hget = _a.hget, exports.hgetall = _a.hgetall, exports.hincrby = _a.hincrby, exports.hincrbyfloat = _a.hincrbyfloat, exports.hkeys = _a.hkeys, exports.hlen = _a.hlen, exports.hmget = _a.hmget, exports.hmset = _a.hmset, exports.hscan = _a.hscan, exports.hset = _a.hset, exports.hsetnx = _a.hsetnx, exports.hvals = _a.hvals, exports.del = _a.del, exports.exists = _a.exists, exports.expire = _a.expire, exports.expireat = _a.expireat, exports.keys = _a.keys, exports.persist = _a.persist, exports.pexpire = _a.pexpire, exports.pexpireat = _a.pexpireat, exports.pttl = _a.pttl, exports.randomkey = _a.randomkey, exports.rename = _a.rename, exports.renamenx = _a.renamenx, exports.scan = _a.scan, exports.touch = _a.touch, exports.ttl = _a.ttl, exports.type = _a.type, exports.unlink = _a.unlink, exports.lindex = _a.lindex, exports.linsert = _a.linsert, exports.llen = _a.llen, exports.lpop = _a.lpop, exports.lpush = _a.lpush, exports.lpushx = _a.lpushx, exports.lrange = _a.lrange, exports.lrem = _a.lrem, exports.lset = _a.lset, exports.ltrim = _a.ltrim, exports.rpop = _a.rpop, exports.rpoplpush = _a.rpoplpush, exports.rpush = _a.rpush, exports.rpushx = _a.rpushx, exports.dbsize = _a.dbsize, exports.flushall = _a.flushall, exports.flushdb = _a.flushdb, exports.info = _a.info, exports.time = _a.time, exports.sadd = _a.sadd, exports.scard = _a.scard, exports.sdiff = _a.sdiff, exports.sdiffstore = _a.sdiffstore, exports.sinter = _a.sinter, exports.sinterstore = _a.sinterstore, exports.sismember = _a.sismember, exports.smembers = _a.smembers, exports.smove = _a.smove, exports.spop = _a.spop, exports.srandmember = _a.srandmember, exports.srem = _a.srem, exports.sunion = _a.sunion, exports.sunionstore = _a.sunionstore, exports.zadd = _a.zadd, exports.zcard = _a.zcard, exports.zcount = _a.zcount, exports.zincrby = _a.zincrby, exports.zinterstore = _a.zinterstore, exports.zlexcount = _a.zlexcount, exports.zpopmax = _a.zpopmax, exports.zpopmin = _a.zpopmin, exports.zrange = _a.zrange, exports.zrangebylex = _a.zrangebylex, exports.zrangebyscore = _a.zrangebyscore, exports.zrank = _a.zrank, exports.zrem = _a.zrem, exports.zremrangebylex = _a.zremrangebylex, exports.zremrangebyrank = _a.zremrangebyrank, exports.zremrangebyscore = _a.zremrangebyscore, exports.zrevrange = _a.zrevrange, exports.zrevrangebylex = _a.zrevrangebylex, exports.zrevrangebyscore = _a.zrevrangebyscore, exports.zrevrank = _a.zrevrank, exports.zscore = _a.zscore, exports.zunionstore = _a.zunionstore; | ||
import upstash from './client'; | ||
export default upstash; | ||
export const { auth, append, decr, decrby, get, getrange, getset, incr, incrby, incrbyfloat, mget, mset, msetnx, psetex, set, setex, setnx, setrange, strlen, bitcount, bitop, bitpos, getbit, setbit, echo, ping, hdel, hexists, hget, hgetall, hincrby, hincrbyfloat, hkeys, hlen, hmget, hmset, hscan, hset, hsetnx, hvals, del, exists, expire, expireat, keys, persist, pexpire, pexpireat, pttl, randomkey, rename, renamenx, scan, touch, ttl, type, unlink, lindex, linsert, llen, lpop, lpush, lpushx, lrange, lrem, lset, ltrim, rpop, rpoplpush, rpush, rpushx, dbsize, flushall, flushdb, info, time, sadd, scard, sdiff, sdiffstore, sinter, sinterstore, sismember, smembers, smove, spop, srandmember, srem, sunion, sunionstore, zadd, zcard, zcount, zincrby, zinterstore, zlexcount, zpopmax, zpopmin, zrange, zrangebylex, zrangebyscore, zrank, zrem, zremrangebylex, zremrangebyrank, zremrangebyscore, zrevrange, zrevrangebylex, zrevrangebyscore, zrevrank, zscore, zunionstore, } = upstash(); |
@@ -6,2 +6,3 @@ export declare type ClientObjectProps = { | ||
readFromEdge?: boolean; | ||
requestOptions?: undefined | RequestInit; | ||
}; | ||
@@ -8,0 +9,0 @@ export declare type EdgeCacheType = null | 'miss' | 'hit'; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; |
{ | ||
"name": "@upstash/redis", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "An HTTP/REST based Redis client built on top of Upstash REST API.", | ||
"author": "Adem ilter <adem@upstash.com>", | ||
"license": "MIT", | ||
"main": "dist/main/index.js", | ||
"types": "dist/main/index.d.ts", | ||
"main": "dist/main/index-cjs.js", | ||
"module": "dist/module/index.js", | ||
"jsdelivr": "dist/umd/upstash-redis.js", | ||
"unpkg": "dist/umd/upstash-redis.js", | ||
"types": "dist/module/index.d.ts", | ||
"scripts": { | ||
@@ -18,3 +16,2 @@ "clean": "rimraf dist", | ||
"build:module": "tsc -p tsconfig.module.json", | ||
"build:umd": "webpack", | ||
"test": "jest --runInBand && npm run size", | ||
@@ -39,18 +36,12 @@ "size": "size-limit" | ||
"ts-loader": "^9.2.6", | ||
"typescript": "^4.5.2", | ||
"webpack": "^5.64.1", | ||
"webpack-cli": "^4.9.1" | ||
"typescript": "^4.5.2" | ||
}, | ||
"size-limit": [ | ||
{ | ||
"path": "dist/main/index.js", | ||
"limit": "5 KB" | ||
"path": "dist/main/index-cjs.js", | ||
"limit": "4 KB" | ||
}, | ||
{ | ||
"path": "dist/module/index.js", | ||
"limit": "5 KB" | ||
}, | ||
{ | ||
"path": "dist/umd/upstash-redis.js", | ||
"limit": "5 KB" | ||
"limit": "4 KB" | ||
} | ||
@@ -57,0 +48,0 @@ ], |
@@ -19,10 +19,17 @@ import fetch from 'isomorphic-unfetch'; | ||
edgeUrl?: string, | ||
readFromEdge?: boolean | ||
readFromEdge?: boolean, | ||
requestOptions: undefined | RequestInit = {} | ||
): ClientObjectProps { | ||
if (typeof url === 'object' && url !== null) { | ||
return parseOptions(url.url, url.token, url.edgeUrl, url.readFromEdge); | ||
return parseOptions( | ||
url.url, | ||
url.token, | ||
url.edgeUrl, | ||
url.readFromEdge, | ||
url.requestOptions | ||
); | ||
} | ||
// try auto fill from env variables | ||
if (!url && typeof window === 'undefined') { | ||
// try auto fill from env variables | ||
url = process.env.UPSTASH_REDIS_REST_URL; | ||
@@ -35,3 +42,5 @@ token = process.env.UPSTASH_REDIS_REST_TOKEN; | ||
return edgeUrl ? { url, token, edgeUrl, readFromEdge } : { url, token }; | ||
return edgeUrl | ||
? { url: url as string, token, edgeUrl, readFromEdge, requestOptions } | ||
: { url: url as string, token, requestOptions }; | ||
} | ||
@@ -53,3 +62,5 @@ | ||
...init.headers, | ||
...options.requestOptions?.headers, | ||
}, | ||
...options.requestOptions, | ||
}); | ||
@@ -56,0 +67,0 @@ |
@@ -6,2 +6,3 @@ export type ClientObjectProps = { | ||
readFromEdge?: boolean; | ||
requestOptions?: undefined | RequestInit; | ||
}; | ||
@@ -8,0 +9,0 @@ |
{ | ||
"include": ["src"], | ||
"files": ["src/index-cjs.ts"], | ||
"exclude": ["./**/dist", "node_modules"], | ||
"compilerOptions": { | ||
"declaration": true, | ||
"lib": ["esnext", "dom"], | ||
"module": "commonjs", | ||
"lib": ["ESNext", "DOM"], | ||
"module": "CommonJS", | ||
"rootDir": "src", | ||
"outDir": "dist/main", | ||
"target": "es2015", | ||
"target": "ESNext", | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"moduleResolution": "Node", | ||
"forceConsistentCasingInFileNames": true, | ||
@@ -18,7 +18,4 @@ "stripInternal": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"swr": ["./src/index.ts"] | ||
}, | ||
"typeRoots": ["./src/types", "node_modules/@types"] | ||
} | ||
} |
{ | ||
"extends": "./tsconfig", | ||
"files": ["src/index.ts"], | ||
"compilerOptions": { | ||
"outDir": "dist/module", | ||
"module": "ESNext" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
13
2776
1
93753
22
1