Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swr-devtools

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swr-devtools - npm Package Compare versions

Comparing version 1.0.0 to 1.2.0

37

cjs/createSWRDevTools.js

@@ -42,17 +42,2 @@ "use strict";

var injected = new WeakSet();
// TOOD: we have to support more types
var convertToSerializableObject = function (value) {
return value instanceof Error ? { message: value.message } : value;
};
var convertValue = function (value) {
if (typeof value !== "object" || value === null)
return value;
if (Array.isArray(value)) {
return value.map(convertToSerializableObject);
}
return Object.keys(value).reduce(function (acc, cacheKey) {
var _a;
return (__assign(__assign({}, acc), (_a = {}, _a[cacheKey] = convertToSerializableObject(value[cacheKey]), _a)));
}, {});
};
var inject = function (cache) {

@@ -62,6 +47,6 @@ return (0, swr_cache_1.injectSWRCache)(cache, function (key, value) {

type: "updated_swr_cache",
payload: {
payload: (0, swr_cache_1.serializePayload)({
key: key,
value: convertValue(value),
},
value: value,
}),
}, "*");

@@ -132,6 +117,6 @@ });

type: "request_start",
payload: {
payload: (0, swr_cache_1.serializePayload)({
key: (0, swr_1.unstable_serialize)(args[0]),
id: id,
},
}),
}, "*");

@@ -147,3 +132,3 @@ try {

id: id,
data: convertToSerializableObject(r),
data: r,
};

@@ -153,3 +138,3 @@ events.emit("request_success", payload);

type: "request_success",
payload: payload,
payload: (0, swr_cache_1.serializePayload)(payload),
}, "*");

@@ -163,3 +148,3 @@ return r;

id: id,
error: convertToSerializableObject(e),
error: e,
};

@@ -169,3 +154,3 @@ events.emit("request_error", payload);

type: "request_error",
payload: payload,
payload: (0, swr_cache_1.serializePayload)(payload),
}, "*");

@@ -196,6 +181,6 @@ throw e;

type: "request_discarded",
payload: {
payload: (0, swr_cache_1.serializePayload)({
key: (0, swr_1.unstable_serialize)(args[0]),
id: requestIdRef.current,
},
}),
}, "*");

@@ -202,0 +187,0 @@ return config.onDiscarded ? config.onDiscarded.apply(null, args) : null;

export { SWRDevTools, SWRDevToolsContext } from "./SWRDevTools";
export { DevToolsMessage, createSWRDevtools } from "./createSWRDevTools";
export { deserializePayload } from "./swr-cache";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSWRDevtools = exports.SWRDevToolsContext = exports.SWRDevTools = void 0;
exports.deserializePayload = exports.createSWRDevtools = exports.SWRDevToolsContext = exports.SWRDevTools = void 0;
var SWRDevTools_1 = require("./SWRDevTools");

@@ -9,2 +9,4 @@ Object.defineProperty(exports, "SWRDevTools", { enumerable: true, get: function () { return SWRDevTools_1.SWRDevTools; } });

Object.defineProperty(exports, "createSWRDevtools", { enumerable: true, get: function () { return createSWRDevTools_1.createSWRDevtools; } });
var swr_cache_1 = require("./swr-cache");
Object.defineProperty(exports, "deserializePayload", { enumerable: true, get: function () { return swr_cache_1.deserializePayload; } });
//# sourceMappingURL=index.js.map

@@ -13,2 +13,4 @@ import { Cache } from "swr";

};
export declare const serializePayload: (payload: any) => string;
export declare const deserializePayload: (payload: any) => any;
export declare const injectSWRCache: (cache: Cache, watcher: (key: string, value: any) => void) => void;

@@ -15,0 +17,0 @@ export declare const convertToDevToolsCacheData: (key: string, value: any) => {

@@ -13,4 +13,16 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertToDevToolsCacheData = exports.injectSWRCache = void 0;
exports.convertToDevToolsCacheData = exports.injectSWRCache = exports.deserializePayload = exports.serializePayload = void 0;
var superjson_1 = __importDefault(require("superjson"));
var serializePayload = function (payload) { return superjson_1.default.stringify(payload); };
exports.serializePayload = serializePayload;
var deserializePayload = function (payload) {
// this check is required to support the case using the SWRDevTools component directly
// In this case, the payload is not serialized
return typeof payload === "string" ? superjson_1.default.parse(payload) : payload;
};
exports.deserializePayload = deserializePayload;
var injectSWRCache = function (cache, watcher) {

@@ -17,0 +29,0 @@ // intercept operations modifying the cache store

@@ -15,3 +15,3 @@ var __assign = (this && this.__assign) || function () {

import { unstable_serialize } from "swr";
import { injectSWRCache } from "./swr-cache";
import { injectSWRCache, serializePayload } from "./swr-cache";
var EventEmitter = /** @class */ (function () {

@@ -40,17 +40,2 @@ function EventEmitter() {

var injected = new WeakSet();
// TOOD: we have to support more types
var convertToSerializableObject = function (value) {
return value instanceof Error ? { message: value.message } : value;
};
var convertValue = function (value) {
if (typeof value !== "object" || value === null)
return value;
if (Array.isArray(value)) {
return value.map(convertToSerializableObject);
}
return Object.keys(value).reduce(function (acc, cacheKey) {
var _a;
return (__assign(__assign({}, acc), (_a = {}, _a[cacheKey] = convertToSerializableObject(value[cacheKey]), _a)));
}, {});
};
var inject = function (cache) {

@@ -60,6 +45,6 @@ return injectSWRCache(cache, function (key, value) {

type: "updated_swr_cache",
payload: {
payload: serializePayload({
key: key,
value: convertValue(value),
},
value: value,
}),
}, "*");

@@ -130,6 +115,6 @@ });

type: "request_start",
payload: {
payload: serializePayload({
key: unstable_serialize(args[0]),
id: id,
},
}),
}, "*");

@@ -145,3 +130,3 @@ try {

id: id,
data: convertToSerializableObject(r),
data: r,
};

@@ -151,3 +136,3 @@ events.emit("request_success", payload);

type: "request_success",
payload: payload,
payload: serializePayload(payload),
}, "*");

@@ -161,3 +146,3 @@ return r;

id: id,
error: convertToSerializableObject(e),
error: e,
};

@@ -167,3 +152,3 @@ events.emit("request_error", payload);

type: "request_error",
payload: payload,
payload: serializePayload(payload),
}, "*");

@@ -194,6 +179,6 @@ throw e;

type: "request_discarded",
payload: {
payload: serializePayload({
key: unstable_serialize(args[0]),
id: requestIdRef.current,
},
}),
}, "*");

@@ -200,0 +185,0 @@ return config.onDiscarded ? config.onDiscarded.apply(null, args) : null;

export { SWRDevTools, SWRDevToolsContext } from "./SWRDevTools";
export { DevToolsMessage, createSWRDevtools } from "./createSWRDevTools";
export { deserializePayload } from "./swr-cache";
export { SWRDevTools, SWRDevToolsContext } from "./SWRDevTools";
export { createSWRDevtools } from "./createSWRDevTools";
export { deserializePayload } from "./swr-cache";
//# sourceMappingURL=index.js.map

@@ -13,2 +13,4 @@ import { Cache } from "swr";

};
export declare const serializePayload: (payload: any) => string;
export declare const deserializePayload: (payload: any) => any;
export declare const injectSWRCache: (cache: Cache, watcher: (key: string, value: any) => void) => void;

@@ -15,0 +17,0 @@ export declare const convertToDevToolsCacheData: (key: string, value: any) => {

@@ -12,2 +12,9 @@ var __assign = (this && this.__assign) || function () {

};
import superjson from "superjson";
export var serializePayload = function (payload) { return superjson.stringify(payload); };
export var deserializePayload = function (payload) {
// this check is required to support the case using the SWRDevTools component directly
// In this case, the payload is not serialized
return typeof payload === "string" ? superjson.parse(payload) : payload;
};
export var injectSWRCache = function (cache, watcher) {

@@ -14,0 +21,0 @@ // intercept operations modifying the cache store

{
"name": "swr-devtools",
"version": "1.0.0",
"version": "1.2.0",
"description": "A React component for SWR DevTools",

@@ -52,8 +52,11 @@ "main": "cjs/index.js",

"devDependencies": {
"@types/react": "^18.0.15",
"@types/react": "^18.0.20",
"react": "^18.2.0",
"swr": "^2.0.0-beta.6",
"typescript": "^4.7.4"
"swr": "^2.0.0-beta.7",
"typescript": "^4.8.3"
},
"gitHead": "9e91ff45ca9d84ccd85c9468dd579035c07b9e4f"
"dependencies": {
"superjson": "^1.11.0"
},
"gitHead": "c14a5fe0e5b3b9bcd1526071caf14f8d9fae3b3f"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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