@orpc/shared 0.0.0-next.ee0aeaf → 0.0.0-next.fd1db03

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
@@ -3,19 +3,19 @@ import {
3
3
  } from "./chunk-CCTAECMC.js";
4
4
 
5
5
  // src/constants.ts
6
- var ORPC_PROTOCOL_HEADER = "x-orpc-protocol";
7
- var ORPC_PROTOCOL_VALUE = "orpc";
6
+ var ORPC_HANDLER_HEADER = "x-orpc-handler";
7
+ var ORPC_HANDLER_VALUE = "orpc";
8
8
 
9
9
  // src/hook.ts
10
10
  async function executeWithHooks(options) {
11
- const executes = convertToArray(options.hooks?.execute);
11
+ const interceptors = convertToArray(options.hooks?.interceptor);
12
12
  const onStarts = convertToArray(options.hooks?.onStart);
13
13
  const onSuccesses = convertToArray(options.hooks?.onSuccess);
14
14
  const onErrors = convertToArray(options.hooks?.onError);
15
15
  const onFinishes = convertToArray(options.hooks?.onFinish);
16
16
  let currentExecuteIndex = 0;
17
17
  const next = async () => {
18
- const execute = executes[currentExecuteIndex];
18
+ const execute = interceptors[currentExecuteIndex];
19
19
  if (execute) {
20
20
  currentExecuteIndex++;
21
21
  return await execute(options.input, options.context, {
@@ -120,6 +120,34 @@ function findDeepMatches(check, payload, segments = [], maps = [], values = [])
120
120
  return { maps, values };
121
121
  }
122
122
 
123
+ // src/proxy.ts
124
+ function createCallableObject(obj, handler) {
125
+ const proxy = new Proxy(handler, {
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
+
123
151
  // src/value.ts
124
152
  function value(value2) {
125
153
  if (typeof value2 === "function") {
@@ -132,9 +160,10 @@ function value(value2) {
132
160
  import { isPlainObject as isPlainObject2 } from "is-what";
133
161
  import { guard, mapEntries, mapValues, omit, trim } from "radash";
134
162
  export {
135
- ORPC_PROTOCOL_HEADER,
136
- ORPC_PROTOCOL_VALUE,
163
+ ORPC_HANDLER_HEADER,
164
+ ORPC_HANDLER_VALUE,
137
165
  convertToArray,
166
+ createCallableObject,
138
167
  executeWithHooks,
139
168
  findDeepMatches,
140
169
  get,
@@ -1,3 +1,3 @@
1
- export declare const ORPC_PROTOCOL_HEADER = "x-orpc-protocol";
2
- export declare const ORPC_PROTOCOL_VALUE = "orpc";
1
+ export declare const ORPC_HANDLER_HEADER = "x-orpc-handler";
2
+ export declare const ORPC_HANDLER_VALUE = "orpc";
3
3
  //# sourceMappingURL=constants.d.ts.map
@@ -23,13 +23,13 @@ export interface BaseHookMeta<TOutput> {
23
23
  export interface Hooks<TInput, TOutput, TContext, TMeta extends (Record<string, any> & {
24
24
  next?: never;
25
25
  }) | undefined> {
26
- execute?: Arrayable<(input: TInput, context: TContext, meta: (TMeta extends undefined ? unknown : TMeta) & BaseHookMeta<TOutput>) => Promise<TOutput>>;
26
+ interceptor?: Arrayable<(input: TInput, context: TContext, meta: (TMeta extends undefined ? unknown : TMeta) & BaseHookMeta<TOutput>) => Promise<TOutput>>;
27
27
  onStart?: Arrayable<(state: OnStartState<TInput>, context: TContext, meta: TMeta) => Promisable<void>>;
28
28
  onSuccess?: Arrayable<(state: OnSuccessState<TInput, TOutput>, context: TContext, meta: TMeta) => Promisable<void>>;
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>;
@@ -3,6 +3,7 @@ export * from './function';
3
3
  export * from './hook';
4
4
  export * from './json';
5
5
  export * from './object';
6
+ export * from './proxy';
6
7
  export * from './value';
7
8
  export { isPlainObject } from 'is-what';
8
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, THandler extends AnyFunction>(obj: TObject, handler: THandler): TObject & THandler;
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.0.0-next.ee0aeaf",
4
+ "version": "0.0.0-next.fd1db03",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {