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

@capable-health/hooks

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capable-health/hooks - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

dist/index.mjs

27

dist/index.d.ts
import { UseQueryOptions, UseMutationOptions, UseQueryResult, UseMutationResult } from '@tanstack/react-query';
import { CapableClient } from '@capable-health/client/dist/src/index';
import { CapableClient } from '@capable-health/client';
import React from 'react';
declare type CapableClientWithoutRequest = Omit<CapableClient, "request">;
declare type HttpVerbs = "GET" | "POST" | "PATCH" | "DELETE";
declare type CapableClientEntityMethods<Entities extends CapableClientWithoutRequest, HttpVerb extends HttpVerbs> = {
declare type GetCapableClientHooks<Entities extends CapableClientWithoutRequest> = {
-readonly [Entity in keyof Entities]: {
[Method in Extract<keyof CapableClient[Entity], `${Lowercase<HttpVerb>}${string}`>]: (client: CapableClient, entity: Entity, method: Method, parameters: Parameters<CapableClient[Entity][Method]>[0], reactQueryOptions: Method extends `get${string}` ? UseQueryOptions : UseMutationOptions) => Method extends `get${string}` ? UseQueryResult : UseMutationResult;
[Method in Exclude<keyof CapableClient[Entity], "httpRequest">]: (parameters?: Parameters<CapableClient[Entity][Method]>[0], options?: Method extends `get${string}` ? UseQueryOptions : UseMutationOptions) => Method extends `get${string}` ? UseQueryResult : UseMutationResult;
};
};
declare type UseGetByMethodByEntity = CapableClientEntityMethods<CapableClientWithoutRequest, "GET">;
declare type UseGetByEntity = {
[Key in keyof UseGetByMethodByEntity]: UseGetByMethodByEntity[Key][keyof UseGetByMethodByEntity[Key]];
};
declare type UseGet = UseGetByEntity[keyof UseGetByMethodByEntity];
declare const useGet: UseGet;
declare type UsePostByMethodByEntity = CapableClientEntityMethods<CapableClientWithoutRequest, "POST">;
declare type UsePostByEntity = {
[Key in keyof UsePostByMethodByEntity]: UsePostByMethodByEntity[Key][keyof UsePostByMethodByEntity[Key]];
};
declare type UsePost = UsePostByEntity[keyof UsePostByMethodByEntity];
declare const usePost: UsePost;
declare const CapableClientHooksContext: React.Context<GetCapableClientHooks<CapableClientWithoutRequest>>;
declare const CapableClientHooksProvider: ({ children, capableClient }: {
children: React.ReactNode;
capableClient: CapableClient;
}) => JSX.Element;
export { UseGet, UsePost, useGet, usePost };
export { CapableClientHooksContext, CapableClientHooksProvider };

@@ -1,2 +0,95 @@

"use strict";var o=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var y in t)o(e,y,{get:t[y],enumerable:!0})},E=(e,t,y,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of p(t))!u.call(e,s)&&s!==y&&o(e,s,{get:()=>t[s],enumerable:!(i=r(t,s))||i.enumerable});return e};var C=e=>E(o({},"__esModule",{value:!0}),e);var h={};l(h,{useGet:()=>U,usePost:()=>B});module.exports=C(h);var n=require("@tanstack/react-query"),U=(e,t,y,i={},s={})=>(0,n.useQuery)([t,JSON.stringify(i)],async()=>await e[t][y](i).data,s),B=(e,t,y,i={},s={})=>{let a=(0,n.useQueryClient)();return(0,n.useMutation)(async()=>await e[t][y](i),{onSuccess:()=>{a.invalidateQueries([t,JSON.stringify(i)])},...s})};
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.tsx
var src_exports = {};
__export(src_exports, {
CapableClientHooksContext: () => CapableClientHooksContext,
CapableClientHooksProvider: () => CapableClientHooksProvider
});
module.exports = __toCommonJS(src_exports);
// src/useCapableClient.tsx
var import_react_query = require("@tanstack/react-query");
var import_react = __toESM(require("react"));
var queryClient = new import_react_query.QueryClient();
var CapableClientHooksContext = (0, import_react.createContext)({});
var CapableClientHooksProvider = ({ children, capableClient }) => {
const capableClientHooks = {};
const entityNames = Object.keys(capableClient);
entityNames.forEach((entityName) => {
if (entityName === "request") {
return;
}
if (!capableClientHooks[entityName]) {
capableClientHooks[entityName] = {};
}
const classEntity = capableClient[entityName];
for (const method in classEntity) {
if (method === "httpRequest") {
continue;
}
if (method.includes("get")) {
const useCapableClientQuery = (parameters, options = {}) => (0, import_react_query.useQuery)(
[entityName, JSON.stringify(parameters)],
async () => {
const entity = capableClient[entityName];
if (method in entity) {
const response = await entity[method](parameters);
return response.data;
}
},
options
);
capableClientHooks[entityName][method] = useCapableClientQuery;
} else {
const useCapableClientMutation = (parameters, options = {}) => {
const queryClient2 = (0, import_react_query.useQueryClient)();
return (0, import_react_query.useMutation)(
async () => {
const entity = capableClient[entityName];
if (method in entity) {
return await entity[method](parameters);
}
},
{
onSuccess: () => {
queryClient2.invalidateQueries([entityName, JSON.stringify(parameters)]);
},
...options
}
);
};
capableClientHooks[entityName][method] = useCapableClientMutation;
}
}
});
return /* @__PURE__ */ import_react.default.createElement(import_react_query.QueryClientProvider, {
client: queryClient
}, /* @__PURE__ */ import_react.default.createElement(CapableClientHooksContext.Provider, {
value: capableClientHooks
}, children));
};
//# sourceMappingURL=index.js.map
{
"name": "@capable-health/hooks",
"version": "0.1.0",
"version": "0.1.1",
"sideEffects": false,

@@ -21,2 +21,3 @@ "main": "./src/index.ts",

"@types/jest": "^29.0.3",
"@types/node": "^18.11.18",
"@types/react": "^18.0.17",

@@ -32,4 +33,3 @@ "@types/react-dom": "^18.0.6",

"@capable-health/eslint-config-custom": "0.0.0",
"@capable-health/tsconfig": "0.0.2",
"@capable-health/client": "0.0.12"
"@capable-health/tsconfig": "0.0.2"
},

@@ -39,3 +39,4 @@ "dependencies": {

"react": "18.2.0",
"react-dom": "18.2.0"
"react-dom": "18.2.0",
"@capable-health/client": "0.0.18"
},

@@ -47,5 +48,5 @@ "publishConfig": {

"lint": "eslint .",
"build": "tsup --format esm,cjs,iife --minify --dts --legacy-output --external react",
"build": "tsup src/index.tsx --format esm,cjs --dts --external react",
"dev": "pnpm build --watch"
}
}

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