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

@orpc/shared

Package Overview
Dependencies
Maintainers
0
Versions
225
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orpc/shared - npm Package Compare versions

Comparing version 0.0.0-next.c6c659d to 0.0.0-next.ca29a36

dist/src/chain.d.ts

255

dist/index.js

@@ -1,96 +0,2 @@

// src/constants.ts
var ORPC_HANDLER_HEADER = "x-orpc-handler";
var ORPC_HANDLER_VALUE = "orpc";
// src/error.ts
import { isPlainObject } from "is-what";
function toError(error) {
if (error instanceof Error) {
return error;
}
if (typeof error === "string") {
return new Error(error, { cause: error });
}
if (isPlainObject(error)) {
if ("message" in error && typeof error.message === "string") {
return new Error(error.message, { cause: error });
}
if ("name" in error && typeof error.name === "string") {
return new Error(error.name, { cause: error });
}
}
return new Error("Unknown error", { cause: error });
}
// src/hook.ts
async function executeWithHooks(options) {
const interceptors = convertToArray(options.hooks?.interceptor);
const onStarts = convertToArray(options.hooks?.onStart);
const onSuccesses = convertToArray(options.hooks?.onSuccess);
const onErrors = convertToArray(options.hooks?.onError);
const onFinishes = convertToArray(options.hooks?.onFinish);
let currentExecuteIndex = 0;
const next = async () => {
const execute = interceptors[currentExecuteIndex];
if (execute) {
currentExecuteIndex++;
return await execute(options.input, options.context, {
...options.meta,
next
});
}
let state = { status: "pending", input: options.input, output: void 0, error: void 0 };
try {
for (const onStart of onStarts) {
await onStart(state, options.context, options.meta);
}
const output = await options.execute();
state = { status: "success", input: options.input, output, error: void 0 };
for (let i = onSuccesses.length - 1; i >= 0; i--) {
await onSuccesses[i](state, options.context, options.meta);
}
} catch (e) {
state = { status: "error", input: options.input, error: toError(e), output: void 0 };
for (let i = onErrors.length - 1; i >= 0; i--) {
try {
await onErrors[i](state, options.context, options.meta);
} catch (e2) {
state = { status: "error", input: options.input, error: toError(e2), output: void 0 };
}
}
}
for (let i = onFinishes.length - 1; i >= 0; i--) {
try {
await onFinishes[i](state, options.context, options.meta);
} catch (e) {
state = { status: "error", input: options.input, error: toError(e), output: void 0 };
}
}
if (state.status === "error") {
throw state.error;
}
return state.output;
};
return await next();
}
function convertToArray(value2) {
if (value2 === void 0) {
return [];
}
return Array.isArray(value2) ? value2 : [value2];
}
// src/json.ts
function parseJSONSafely(text) {
if (text === "")
return void 0;
try {
return JSON.parse(text);
} catch {
return text;
}
}
// src/object.ts
import { isPlainObject as isPlainObject2 } from "is-what";
function set(root, segments, value2) {

@@ -131,3 +37,3 @@ const ref = { root };

});
} else if (isPlainObject2(payload)) {
} else if (isObject(payload)) {
for (const key in payload) {

@@ -139,31 +45,118 @@ findDeepMatches(check, payload[key], [...segments, key], maps, values);

}
function isObject(value2) {
if (!value2 || typeof value2 !== "object") {
return false;
}
const proto = Object.getPrototypeOf(value2);
return proto === Object.prototype || !proto || !proto.constructor;
}
function isTypescriptObject(value2) {
return !!value2 && (typeof value2 === "object" || typeof value2 === "function");
}
// src/proxy.ts
function createCallableObject(obj, handler) {
const proxy = new Proxy(handler, {
has(target, key) {
return Reflect.has(obj, key) || Reflect.has(target, key);
},
ownKeys(target) {
return Array.from(new Set(Reflect.ownKeys(obj).concat(...Reflect.ownKeys(target))));
},
get(target, key) {
if (!Reflect.has(target, key) || Reflect.has(obj, key)) {
return Reflect.get(obj, key);
}
return Reflect.get(target, key);
},
defineProperty(_, key, descriptor) {
return Reflect.defineProperty(obj, key, descriptor);
},
set(_, key, value2) {
return Reflect.set(obj, key, value2);
},
deleteProperty(target, key) {
return Reflect.deleteProperty(target, key) && Reflect.deleteProperty(obj, key);
// src/error.ts
function toError(error) {
if (error instanceof Error) {
return error;
}
if (typeof error === "string") {
return new Error(error, { cause: error });
}
if (isObject(error)) {
if ("message" in error && typeof error.message === "string") {
return new Error(error.message, { cause: error });
}
});
return proxy;
if ("name" in error && typeof error.name === "string") {
return new Error(error.name, { cause: error });
}
}
return new Error("Unknown error", { cause: error });
}
// src/function.ts
function once(fn) {
let cached;
return () => {
if (cached) {
return cached.result;
}
const result = fn();
cached = { result };
return result;
};
}
// src/interceptor.ts
function onStart(callback) {
return async (options, ...rest) => {
await callback(options, ...rest);
return await options.next();
};
}
function onSuccess(callback) {
return async (options, ...rest) => {
const result = await options.next();
await callback(result, options, ...rest);
return result;
};
}
function onError(callback) {
return async (options, ...rest) => {
try {
return await options.next();
} catch (error) {
await callback(error, options, ...rest);
throw error;
}
};
}
function onFinish(callback) {
let state;
return async (options, ...rest) => {
try {
const result = await options.next();
state = [result, void 0, "success"];
return result;
} catch (error) {
state = [void 0, error, "error"];
throw error;
} finally {
await callback(state, options, ...rest);
}
};
}
async function intercept(interceptors, options, main) {
let index = 0;
const next = async (options2) => {
const interceptor = interceptors[index++];
if (!interceptor) {
return await main(options2);
}
return await interceptor({
...options2,
next: (newOptions = options2) => next(newOptions)
});
};
return await next(options);
}
// src/iterator.ts
function isAsyncIteratorObject(maybe) {
if (!maybe || typeof maybe !== "object") {
return false;
}
return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
}
// src/json.ts
function parseEmptyableJSON(text) {
if (!text) {
return void 0;
}
return JSON.parse(text);
}
function stringifyJSON(value2) {
return JSON.stringify(value2);
}
// src/value.ts

@@ -178,10 +171,4 @@ function value(value2, ...args) {

// src/index.ts
import { isPlainObject as isPlainObject3 } from "is-what";
import { group, guard, mapEntries, mapValues, omit, trim } from "radash";
import { group, guard, mapEntries, mapValues, omit, retry, trim } from "radash";
export {
ORPC_HANDLER_HEADER,
ORPC_HANDLER_VALUE,
convertToArray,
createCallableObject,
executeWithHooks,
findDeepMatches,

@@ -191,8 +178,18 @@ get,

guard,
isPlainObject3 as isPlainObject,
intercept,
isAsyncIteratorObject,
isObject,
isTypescriptObject,
mapEntries,
mapValues,
omit,
parseJSONSafely,
onError,
onFinish,
onStart,
onSuccess,
once,
parseEmptyableJSON,
retry,
set,
stringifyJSON,
toError,

@@ -199,0 +196,0 @@ trim,

export type AnyFunction = (...args: any[]) => any;
export declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
//# sourceMappingURL=function.d.ts.map

@@ -1,12 +0,12 @@

export * from './constants';
export * from './chain';
export * from './error';
export * from './function';
export * from './hook';
export * from './interceptor';
export * from './iterator';
export * from './json';
export * from './object';
export * from './proxy';
export * from './types';
export * from './value';
export { isPlainObject } from 'is-what';
export { group, guard, mapEntries, mapValues, omit, trim } from 'radash';
export type * from 'type-fest';
export { group, guard, mapEntries, mapValues, omit, retry, trim } from 'radash';
export type { IsEqual, IsNever, PartialDeep, Promisable } from 'type-fest';
//# sourceMappingURL=index.d.ts.map

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

export declare function parseJSONSafely(text: string): unknown;
export declare function parseEmptyableJSON(text: string | null | undefined): unknown;
export declare function stringifyJSON<T>(value: T): undefined extends T ? undefined | string : string;
//# sourceMappingURL=json.d.ts.map
export type Segment = string | number;
export declare function set(root: Readonly<Record<string, unknown> | unknown[]>, segments: Readonly<Segment[]>, value: unknown): unknown;
export declare function set(root: unknown, segments: Readonly<Segment[]>, value: unknown): unknown;
export declare function get(root: Readonly<Record<string, unknown> | unknown[]>, segments: Readonly<Segment[]>): unknown;

@@ -8,2 +8,10 @@ export declare function findDeepMatches(check: (value: unknown) => boolean, payload: unknown, segments?: Segment[], maps?: Segment[][], values?: unknown[]): {

};
/**
* Check if the value is an object even it created by `Object.create(null)` or more tricky way.
*/
export declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
/**
* Check if the value satisfy a `object` type in typescript
*/
export declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
//# sourceMappingURL=object.d.ts.map
import type { Promisable } from 'type-fest';
export type Value<T, TArgs extends any[] = []> = T | ((...args: TArgs) => Promisable<T>);
export declare function value<T extends Value<any, TArgs>, TArgs extends any[] = []>(value: T, ...args: TArgs): Promise<T extends Value<infer U, any> ? U : never>;
export declare function value<T, TArgs extends any[]>(value: Value<T, TArgs>, ...args: NoInfer<TArgs>): Promise<T extends Value<infer U, any> ? U : never>;
//# sourceMappingURL=value.d.ts.map
{
"name": "@orpc/shared",
"type": "module",
"version": "0.0.0-next.c6c659d",
"version": "0.0.0-next.ca29a36",
"license": "MIT",

@@ -32,4 +32,2 @@ "homepage": "https://orpc.unnoq.com",

"dependencies": {
"@standard-schema/spec": "1.0.0-beta.4",
"is-what": "^5.0.2",
"radash": "^12.1.0",

@@ -36,0 +34,0 @@ "type-fest": "^4.26.1"

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