New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cf-workers-query

Package Overview
Dependencies
Maintainers
0
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cf-workers-query - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## 0.3.5 (2024-07-25)
This was a version bump only, there were no code changes.
## 0.3.4 (2024-07-25)

@@ -2,0 +6,0 @@

2

package.json
{
"name": "cf-workers-query",
"version": "0.3.4",
"version": "0.3.5",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Automatically cache and revalidate data in Cloudflare Workers. Using the Cache API and Execution Context",

@@ -1,13 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.invalidateQuery = exports.getCFExecutionContext = exports.defineCFExecutionContext = exports.CacheApiAdaptor = exports.createQuery = void 0;
var create_query_1 = require("./lib/create-query");
Object.defineProperty(exports, "createQuery", { enumerable: true, get: function () { return create_query_1.createQuery; } });
var cache_api_1 = require("./lib/cache-api");
Object.defineProperty(exports, "CacheApiAdaptor", { enumerable: true, get: function () { return cache_api_1.CacheApiAdaptor; } });
var context_1 = require("./lib/context");
Object.defineProperty(exports, "defineCFExecutionContext", { enumerable: true, get: function () { return context_1.defineCFExecutionContext; } });
Object.defineProperty(exports, "getCFExecutionContext", { enumerable: true, get: function () { return context_1.getCFExecutionContext; } });
var invalidate_query_1 = require("./lib/invalidate-query");
Object.defineProperty(exports, "invalidateQuery", { enumerable: true, get: function () { return invalidate_query_1.invalidateQuery; } });
//# sourceMappingURL=index.js.map
export { createQuery } from './lib/create-query';
export { CacheApiAdaptor } from './lib/cache-api';
export { defineCFExecutionContext, getCFExecutionContext } from './lib/context';
export { invalidateQuery } from './lib/invalidate-query';

@@ -1,8 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheApiAdaptor = exports.CACHE_URL = void 0;
const tslib_1 = require("tslib");
exports.CACHE_URL = 'INTERNAL_CF_WORKERS_QUERY_CACHE_HOSTNAME.local';
import { __awaiter } from "tslib";
export const CACHE_URL = 'INTERNAL_CF_WORKERS_QUERY_CACHE_HOSTNAME.local';
const CACHE_LAST_MODIFIED_HEADER = 'cf-workers-query-cache-last-modified';
class CacheApiAdaptor {
export class CacheApiAdaptor {
constructor(ctx = {}) {

@@ -14,3 +11,3 @@ var _a, _b;

retrieve(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return __awaiter(this, void 0, void 0, function* () {
const cache = yield caches.open(this.cacheName);

@@ -36,3 +33,3 @@ const cacheKey = key instanceof URL ? key : this.buildCacheKey(key);

update(key, value, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return __awaiter(this, void 0, void 0, function* () {
var _a;

@@ -58,3 +55,3 @@ const cache = yield caches.open(this.cacheName);

delete(key) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return __awaiter(this, void 0, void 0, function* () {
const cache = yield caches.open(this.cacheName);

@@ -77,6 +74,4 @@ const response = new Response(null, {

buildCacheKey(key) {
return `https://${exports.CACHE_URL}/entry/${key.join('/')}`;
return `https://${CACHE_URL}/entry/${key.join('/')}`;
}
}
exports.CacheApiAdaptor = CacheApiAdaptor;
//# sourceMappingURL=cache-api.js.map

@@ -1,10 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineCFExecutionContext = exports.getCFExecutionContext = void 0;
const node_async_hooks_1 = require("node:async_hooks");
const AsyncLocaleStorageContext = new node_async_hooks_1.AsyncLocalStorage();
const getCFExecutionContext = () => AsyncLocaleStorageContext.getStore();
exports.getCFExecutionContext = getCFExecutionContext;
const defineCFExecutionContext = (context, func) => AsyncLocaleStorageContext.run(context, func);
exports.defineCFExecutionContext = defineCFExecutionContext;
//# sourceMappingURL=context.js.map
import { AsyncLocalStorage } from 'node:async_hooks';
const AsyncLocaleStorageContext = new AsyncLocalStorage();
export const getCFExecutionContext = () => AsyncLocaleStorageContext.getStore();
export const defineCFExecutionContext = (context, func) => AsyncLocaleStorageContext.run(context, func);

@@ -1,9 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createQuery = void 0;
const tslib_1 = require("tslib");
const context_1 = require("./context");
const cache_api_1 = require("./cache-api");
const nanoid_1 = require("nanoid");
const createQuery = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ queryKey, queryFn, gcTime, staleTime, revalidate, retry, retryDelay, executionCtx, cacheName, throwOnError, }) {
import { __awaiter } from "tslib";
import { getCFExecutionContext } from './context';
import { CacheApiAdaptor } from './cache-api';
import { nanoid } from 'nanoid';
export const createQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ queryKey, queryFn, gcTime, staleTime, revalidate, retry, retryDelay, executionCtx, cacheName, throwOnError, }) {
try {

@@ -14,6 +11,6 @@ if (!queryKey) {

}
const cache = new cache_api_1.CacheApiAdaptor({ maxAge: gcTime, cacheName });
const cache = new CacheApiAdaptor({ maxAge: gcTime, cacheName });
const cacheKey = queryKey;
const invalidate = () => cache.delete(cacheKey);
const context = executionCtx !== null && executionCtx !== void 0 ? executionCtx : (0, context_1.getCFExecutionContext)();
const context = executionCtx !== null && executionCtx !== void 0 ? executionCtx : getCFExecutionContext();
if (!revalidate) {

@@ -24,5 +21,5 @@ const cachedData = yield cache.retrieve(cacheKey);

if (isStale && context) {
const staleId = (0, nanoid_1.nanoid)();
const staleId = nanoid();
yield cache.update([...cacheKey, 'dedupe'], staleId);
const refreshFunc = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const refreshFunc = () => __awaiter(void 0, void 0, void 0, function* () {
var _a;

@@ -62,3 +59,2 @@ const { data: cachedStaleId } = (_a = (yield cache.retrieve([...cacheKey, 'dedupe']))) !== null && _a !== void 0 ? _a : {};

});
exports.createQuery = createQuery;
const defaultRetryDelay = (attemptIndex) => Math.min(1000 * Math.pow(2, attemptIndex), 30000);

@@ -73,3 +69,3 @@ function handleRetryDelay(failureCount, error, retryDelay = defaultRetryDelay) {

}
const handleQueryFnWithRetry = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ queryFn, retry = 0, failureCount = 0, retryDelay, throwOnError, }) {
const handleQueryFnWithRetry = (_a) => __awaiter(void 0, [_a], void 0, function* ({ queryFn, retry = 0, failureCount = 0, retryDelay, throwOnError, }) {
try {

@@ -103,2 +99,1 @@ const data = yield queryFn();

});
//# sourceMappingURL=create-query.js.map

@@ -1,10 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cache = void 0;
const tslib_1 = require("tslib");
const create_query_1 = require("./create-query");
const cache = (_a) => {
var { cacheKey } = _a, options = tslib_1.__rest(_a, ["cacheKey"]);
return (ctx, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const { data: response } = yield (0, create_query_1.createQuery)(Object.assign(Object.assign({}, options), { queryKey: typeof cacheKey === 'function' ? cacheKey(ctx) : cacheKey, queryFn: () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
import { __awaiter, __rest } from "tslib";
import { createQuery } from './create-query';
export const cache = (_a) => {
var { cacheKey } = _a, options = __rest(_a, ["cacheKey"]);
return (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
const { data: response } = yield createQuery(Object.assign(Object.assign({}, options), { queryKey: typeof cacheKey === 'function' ? cacheKey(ctx) : cacheKey, queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
yield next();

@@ -16,3 +13,1 @@ return ctx.res;

};
exports.cache = cache;
//# sourceMappingURL=hono.js.map

@@ -1,10 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.invalidateQuery = void 0;
const cache_api_1 = require("./cache-api");
const invalidateQuery = ({ queryKey, cacheName, }) => {
const cache = new cache_api_1.CacheApiAdaptor({ cacheName });
import { CacheApiAdaptor } from './cache-api';
export const invalidateQuery = ({ queryKey, cacheName, }) => {
const cache = new CacheApiAdaptor({ cacheName });
return cache.delete(queryKey);
};
exports.invalidateQuery = invalidateQuery;
//# sourceMappingURL=invalidate-query.js.map
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc