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
228
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.6acfc62 to 0.0.0-next.6affcc9

dist/src/types.d.ts

234

dist/index.js

@@ -1,7 +0,53 @@

// src/constants.ts
var ORPC_HANDLER_HEADER = "x-orpc-handler";
var ORPC_HANDLER_VALUE = "orpc";
// src/object.ts
function set(root, segments, value2) {
const ref = { root };
let currentRef = ref;
let preSegment = "root";
for (const segment of segments) {
currentRef = currentRef[preSegment];
preSegment = segment;
}
currentRef[preSegment] = value2;
return ref.root;
}
function get(root, segments) {
const ref = { root };
let currentRef = ref;
let preSegment = "root";
for (const segment of segments) {
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
return void 0;
}
currentRef = currentRef[preSegment];
preSegment = segment;
}
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
return void 0;
}
return currentRef[preSegment];
}
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
if (check(payload)) {
maps.push(segments);
values.push(payload);
} else if (Array.isArray(payload)) {
payload.forEach((v, i) => {
findDeepMatches(check, v, [...segments, i], maps, values);
});
} else if (isObject(payload)) {
for (const key in payload) {
findDeepMatches(check, payload[key], [...segments, key], maps, values);
}
}
return { maps, values };
}
function isObject(value2) {
if (!value2 || typeof value2 !== "object") {
return false;
}
const proto = Object.getPrototypeOf(value2);
return proto === Object.prototype || !proto || !proto.constructor;
}
// src/error.ts
import { isPlainObject } from "is-what";
function toError(error) {

@@ -14,3 +60,3 @@ if (error instanceof Error) {

}
if (isPlainObject(error)) {
if (isObject(error)) {
if ("message" in error && typeof error.message === "string") {

@@ -26,73 +72,2 @@ return new Error(error.message, { cause: error });

// src/function.ts
function once(fn) {
let cached;
return () => {
if (cached) {
return cached.result;
}
const result = fn();
cached = { result };
return result;
};
}
// 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 onStart2 of onStarts) {
await onStart2(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/interceptor.ts

@@ -139,99 +114,15 @@ function onStart(callback) {

let index = 0;
const next = async (nextOptions = options) => {
const next = async (options2) => {
const interceptor = interceptors[index++];
if (!interceptor) {
return await main(nextOptions);
return await main(options2);
}
return await interceptor({
...nextOptions,
next
...options2,
next: (newOptions = options2) => next(newOptions)
});
};
return await next();
return await next(options);
}
// 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) {
const ref = { root };
let currentRef = ref;
let preSegment = "root";
for (const segment of segments) {
currentRef = currentRef[preSegment];
preSegment = segment;
}
currentRef[preSegment] = value2;
return ref.root;
}
function get(root, segments) {
const ref = { root };
let currentRef = ref;
let preSegment = "root";
for (const segment of segments) {
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
return void 0;
}
currentRef = currentRef[preSegment];
preSegment = segment;
}
if (typeof currentRef !== "object" && typeof currentRef !== "function" || currentRef === null) {
return void 0;
}
return currentRef[preSegment];
}
function findDeepMatches(check, payload, segments = [], maps = [], values = []) {
if (check(payload)) {
maps.push(segments);
values.push(payload);
} else if (Array.isArray(payload)) {
payload.forEach((v, i) => {
findDeepMatches(check, v, [...segments, i], maps, values);
});
} else if (isPlainObject2(payload)) {
for (const key in payload) {
findDeepMatches(check, payload[key], [...segments, key], maps, values);
}
}
return { maps, values };
}
// 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);
}
});
return proxy;
}
// src/value.ts

@@ -246,10 +137,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,

@@ -260,3 +145,3 @@ get,

intercept,
isPlainObject3 as isPlainObject,
isObject,
mapEntries,

@@ -269,4 +154,3 @@ mapValues,

onSuccess,
once,
parseJSONSafely,
retry,
set,

@@ -273,0 +157,0 @@ toError,

export type AnyFunction = (...args: any[]) => any;
export declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
//# sourceMappingURL=function.d.ts.map
export * from './chain';
export * from './constants';
export * from './error';
export * from './function';
export * from './hook';
export * from './interceptor';
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
import type { Promisable } from 'type-fest';
import type { AnyFunction } from './function';
export type InterceptableOptions = Record<string, any>;

@@ -24,3 +23,2 @@ export type InterceptorOptions<TOptions extends InterceptableOptions, TResult> = Omit<TOptions, 'next'> & {

}, TRest extends any[]>(callback: NoInfer<(result: Awaited<ReturnType<TOptions['next']>>, options: TOptions, ...rest: TRest) => Promisable<void>>): (options: TOptions, ...rest: TRest) => Promise<Awaited<ReturnType<TOptions['next']>>>;
export type InferError<T extends AnyFunction> = T extends Interceptor<any, any, infer TError> ? TError : unknown;
/**

@@ -27,0 +25,0 @@ * Can used for interceptors or middlewares

@@ -8,2 +8,6 @@ export type Segment = string | number;

};
/**
* 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>;
//# 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.6acfc62",
"version": "0.0.0-next.6affcc9",
"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