@orpc/shared 0.16.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,6 +2,10 @@ import {
2
2
  convertToStandardError
3
3
  } from "./chunk-CCTAECMC.js";
4
4
 
5
+ // src/constants.ts
6
+ var ORPC_HANDLER_HEADER = "x-orpc-handler";
7
+ var ORPC_HANDLER_VALUE = "orpc";
8
+
5
9
  // src/hook.ts
6
10
  async function executeWithHooks(options) {
7
11
  const executes = convertToArray(options.hooks?.execute);
@@ -116,6 +120,34 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
116
120
  return { maps, values };
117
121
  }
118
122
 
123
+ // src/proxy.ts
124
+ function createCallableObject(obj, func) {
125
+ const proxy = new Proxy(func, {
126
+ has(target, key) {
127
+ return Reflect.has(obj, key) || Reflect.has(target, key);
128
+ },
129
+ ownKeys(target) {
130
+ return Array.from(new Set(Reflect.ownKeys(obj).concat(...Reflect.ownKeys(target))));
131
+ },
132
+ get(target, key) {
133
+ if (!Reflect.has(target, key) || Reflect.has(obj, key)) {
134
+ return Reflect.get(obj, key);
135
+ }
136
+ return Reflect.get(target, key);
137
+ },
138
+ defineProperty(_, key, descriptor) {
139
+ return Reflect.defineProperty(obj, key, descriptor);
140
+ },
141
+ set(_, key, value2) {
142
+ return Reflect.set(obj, key, value2);
143
+ },
144
+ deleteProperty(target, key) {
145
+ return Reflect.deleteProperty(target, key) && Reflect.deleteProperty(obj, key);
146
+ }
147
+ });
148
+ return proxy;
149
+ }
150
+
119
151
  // src/value.ts
120
152
  function value(value2) {
121
153
  if (typeof value2 === "function") {
@@ -128,7 +160,10 @@ function value(value2) {
128
160
  import { isPlainObject as isPlainObject2 } from "is-what";
129
161
  import { guard, mapEntries, mapValues, omit, trim } from "radash";
130
162
  export {
163
+ ORPC_HANDLER_HEADER,
164
+ ORPC_HANDLER_VALUE,
131
165
  convertToArray,
166
+ createCallableObject,
132
167
  executeWithHooks,
133
168
  findDeepMatches,
134
169
  get,
@@ -0,0 +1,3 @@
1
+ export declare const ORPC_HANDLER_HEADER = "x-orpc-handler";
2
+ export declare const ORPC_HANDLER_VALUE = "orpc";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -29,7 +29,7 @@ export interface Hooks<TInput, TOutput, TContext, TMeta extends (Record<string,
29
29
  onError?: Arrayable<(state: OnErrorState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>;
30
30
  onFinish?: Arrayable<(state: OnSuccessState<TInput, TOutput> | OnErrorState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>;
31
31
  }
32
- export declare function executeWithHooks<TInput, TOutput, TContext, TMeta extends (Record<string, unknown> & {
32
+ export declare function executeWithHooks<TInput, TOutput, TContext, TMeta extends (Record<string, any> & {
33
33
  next?: never;
34
34
  }) | undefined>(options: {
35
35
  hooks?: Hooks<TInput, TOutput, TContext, TMeta>;
@@ -1,7 +1,9 @@
1
+ export * from './constants';
1
2
  export * from './function';
2
3
  export * from './hook';
3
4
  export * from './json';
4
5
  export * from './object';
6
+ export * from './proxy';
5
7
  export * from './value';
6
8
  export { isPlainObject } from 'is-what';
7
9
  export { guard, mapEntries, mapValues, omit, trim } from 'radash';
@@ -0,0 +1,3 @@
1
+ import type { AnyFunction } from './function';
2
+ export declare function createCallableObject<TObject extends object, TFunc extends AnyFunction>(obj: TObject, func: TFunc): TObject & TFunc;
3
+ //# sourceMappingURL=proxy.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/shared",
3
3
  "type": "module",
4
- "version": "0.16.0",
4
+ "version": "0.18.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {