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

@plasmicapp/query

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plasmicapp/query - npm Package Compare versions

Comparing version 0.1.72 to 0.1.73

./dist/index.js

5

dist/index.d.ts

@@ -1,2 +0,3 @@

export { useSWRConfig } from 'swr';
export { addLoadingStateListener, LoadingStateListener, PlasmicPrepassContext, PlasmicQueryDataProvider, SWRResponse, useMutablePlasmicQueryData, usePlasmicDataConfig, usePlasmicQueryData, wrapLoadingFetcher, isPlasmicPrepass, } from './query-data';
export { useSWRConfig } from "swr";
export { addLoadingStateListener, isPlasmicPrepass, PlasmicPrepassContext, PlasmicQueryDataProvider, useMutablePlasmicQueryData, usePlasmicDataConfig, usePlasmicQueryData, wrapLoadingFetcher, } from "./query-data";
export type { LoadingStateListener, SWRResponse } from "./query-data";

251

dist/index.js

@@ -0,8 +1,249 @@

"use client";
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
'use strict'
// src/index.tsx
var src_exports = {};
__export(src_exports, {
PlasmicPrepassContext: () => PlasmicPrepassContext,
PlasmicQueryDataProvider: () => PlasmicQueryDataProvider,
addLoadingStateListener: () => addLoadingStateListener,
isPlasmicPrepass: () => isPlasmicPrepass,
useMutablePlasmicQueryData: () => useMutablePlasmicQueryData,
usePlasmicDataConfig: () => usePlasmicDataConfig,
usePlasmicQueryData: () => usePlasmicQueryData,
useSWRConfig: () => import_swr2.useSWRConfig,
wrapLoadingFetcher: () => wrapLoadingFetcher
});
module.exports = __toCommonJS(src_exports);
if (process.env.NODE_ENV === 'production') {
module.exports = require('./query.cjs.production.min.js')
} else {
module.exports = require('./query.cjs.development.js')
// src/query-data.tsx
var import_react = __toESM(require("react"));
var import_swr = __toESM(require("swr"));
var __SWRConfig = void 0;
var mutateKeys = (invalidateKey) => {
if (__SWRConfig) {
const { cache, mutate } = __SWRConfig;
(invalidateKey != null ? [invalidateKey] : Array.from(cache.keys())).forEach((key) => {
mutate(key);
});
}
};
function getPlasmicDefaultSWROptions(opts) {
return {
revalidateIfStale: !!(opts == null ? void 0 : opts.isMutable),
revalidateOnFocus: false,
revalidateOnReconnect: false
};
}
function usePlasmicQueryData(key, fetcher) {
const prepassCtx = import_react.default.useContext(PrepassContext);
const opts = getPlasmicDefaultSWROptions();
if (prepassCtx) {
opts.suspense = true;
}
const config = (0, import_swr.useSWRConfig)();
import_react.default.useEffect(() => {
__SWRConfig = config;
}, [config]);
const wrappedFetcher = import_react.default.useMemo(
() => wrapLoadingFetcher(fetcher),
[fetcher]
);
const resp = (0, import_swr.default)(key, wrappedFetcher, opts);
if (resp.data !== void 0) {
return { data: resp.data };
} else if (resp.error) {
return { error: resp.error };
} else {
return { isLoading: true };
}
}
function useMutablePlasmicQueryData(key, fetcher, options) {
const prepassCtx = import_react.default.useContext(PrepassContext);
const opts = __spreadValues(__spreadValues({}, getPlasmicDefaultSWROptions({ isMutable: true })), options);
if (prepassCtx) {
opts.suspense = true;
}
const config = (0, import_swr.useSWRConfig)();
import_react.default.useEffect(() => {
__SWRConfig = config;
}, [config]);
const [isLoading, setIsLoading] = import_react.default.useState(false);
const fetcherWrapper = import_react.default.useCallback(
(...args) => __async(this, null, function* () {
setIsLoading(true);
try {
return yield wrapLoadingFetcher(fetcher)(...args);
} finally {
setIsLoading(false);
}
}),
[fetcher]
);
const laggyDataRef = import_react.default.useRef();
const { isValidating, mutate, data, error } = (0, import_swr.default)(
key,
fetcherWrapper,
opts
);
import_react.default.useEffect(() => {
if (data !== void 0) {
laggyDataRef.current = data;
}
}, [data]);
return import_react.default.useMemo(
() => __spreadValues(__spreadValues({
isValidating,
mutate,
isLoading: data === void 0 && error === void 0 || isLoading
}, data !== void 0 ? { data } : error === void 0 && laggyDataRef.current ? (
// Show previous data if available
{ data: laggyDataRef.current, isLagging: true }
) : {}), error !== void 0 ? { error } : {}),
[isValidating, mutate, data, error, isLoading]
);
}
function PlasmicQueryDataProvider(props) {
const { children, suspense, prefetchedCache } = props;
const prepass = import_react.default.useContext(PrepassContext);
if (prepass) {
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
} else {
return /* @__PURE__ */ import_react.default.createElement(
import_swr.SWRConfig,
{
value: {
fallback: prefetchedCache != null ? prefetchedCache : {},
suspense
}
},
children
);
}
}
var PrepassContext = import_react.default.createContext(false);
function PlasmicPrepassContext(props) {
const { cache, children } = props;
return /* @__PURE__ */ import_react.default.createElement(PrepassContext.Provider, { value: true }, /* @__PURE__ */ import_react.default.createElement(
import_swr.SWRConfig,
{
value: {
provider: () => cache,
suspense: true,
fallback: {}
}
},
children
));
}
var usePlasmicDataConfig = import_swr.useSWRConfig;
var loadingCount = 0;
var listeners = [];
function addLoadingStateListener(listener, opts) {
listeners.push(listener);
if (opts == null ? void 0 : opts.immediate) {
listener(loadingCount > 0);
}
return () => {
listeners.splice(listeners.indexOf(listener), 1);
};
}
function wrapLoadingFetcher(fetcher) {
return (...args) => __async(this, null, function* () {
if (loadingCount === 0) {
listeners.forEach((listener) => listener(true));
}
loadingCount += 1;
try {
const res = fetcher(...args);
return isPromiseLike(res) ? yield res : res;
} finally {
loadingCount -= 1;
if (loadingCount === 0) {
listeners.forEach((listener) => listener(false));
}
}
});
}
function isPromiseLike(x) {
return !!x && typeof x === "object" && "then" in x && typeof x.then === "function";
}
function isPlasmicPrepass() {
var _a, _b, _c;
return !!((_c = (_b = (_a = import_react.default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) == null ? void 0 : _a.ReactCurrentDispatcher) == null ? void 0 : _b.current) == null ? void 0 : _c.isPlasmicPrepass);
}
// src/index.tsx
var import_swr2 = require("swr");
if (typeof window !== "undefined") {
const root = window;
const maybeExistingMutateAllKeys = root.__SWRMutateAllKeys;
root.__SWRMutateAllKeys = (invalidateKey) => {
mutateKeys(invalidateKey);
if (typeof maybeExistingMutateAllKeys === "function") {
maybeExistingMutateAllKeys(invalidateKey);
}
};
}
//# sourceMappingURL=index.js.map

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

import React, { PropsWithChildren } from 'react';
import { Fetcher, Key, SWRConfiguration, SWRResponse } from 'swr';
import { FullConfiguration } from 'swr/dist/types';
export type { SWRResponse } from 'swr';
export declare const mutateKeys: (invalidateKey?: string | undefined) => void;
import React, { PropsWithChildren } from "react";
import { Fetcher, Key, SWRConfiguration, SWRResponse, useSWRConfig } from "swr";
export type { SWRResponse } from "swr";
export declare const mutateKeys: (invalidateKey?: string) => void;
/**

@@ -43,4 +42,4 @@ * Fetches data asynchronously. This data should be considered immutable for the

}>): React.JSX.Element;
export declare function usePlasmicDataConfig(): FullConfiguration;
export declare type LoadingStateListener = (isLoading: boolean) => void;
export declare const usePlasmicDataConfig: typeof useSWRConfig;
export type LoadingStateListener = (isLoading: boolean) => void;
/**

@@ -47,0 +46,0 @@ * Subscribes to whether any loading is happening via @plasmicapp/query.

{
"version": "0.1.72",
"version": "0.1.73",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"types": "./dist/index.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.esm.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.js"
}
},
"files": [

@@ -13,6 +21,7 @@ "dist"

"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"build": "yarn build:types && yarn build:index",
"build:types": "yarn tsc",
"build:index": "node ../../build.mjs ./src/index.tsx --use-client",
"test": "yarn --cwd=../.. test --passWithNoTests",
"lint": "tsdx lint",
"lint": "eslint",
"prepare": "if-env PREPARE_NO_BUILD=true || yarn build",

@@ -23,39 +32,17 @@ "size": "size-limit",

"peerDependencies": {
"react": ">=16"
"react": ">=16.8.0"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"name": "@plasmicapp/query",
"author": "Chung Wu",
"module": "dist/query.esm.js",
"size-limit": [
{
"path": "dist/query.cjs.production.min.js",
"path": "dist/index.js",
"limit": "10 KB"
},
{
"path": "dist/query.esm.js",
"limit": "10 KB"
}
],
"devDependencies": {
"@size-limit/preset-small-lib": "^7.0.4",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"husky": "^7.0.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup-plugin-banner2": "^1.2.2",
"size-limit": "^7.0.4",
"tsdx": "^0.14.1",
"tslib": "^2.3.1"
"react-dom": "^18.2.0"
},

@@ -65,3 +52,3 @@ "dependencies": {

},
"gitHead": "3b71c9fba9c00aea3d7197feefc45da8813b7e7a"
"gitHead": "061bfb393e0e5faabf92ef07b21e60107a5e7971"
}
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