@orpc/shared 0.0.0-next.fe39bf3 → 0.0.0-next.fea68c1

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/README.md ADDED
@@ -0,0 +1,68 @@
1
+ <div align="center">
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
3
+ </div>
4
+
5
+ <h1></h1>
6
+
7
+ <div align="center">
8
+ <a href="https://codecov.io/gh/unnoq/orpc">
9
+ <img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@orpc/shared">
12
+ <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fshared?logo=npm" />
13
+ </a>
14
+ <a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
15
+ <img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
16
+ </a>
17
+ <a href="https://discord.gg/TXEbwRBvQn">
18
+ <img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
19
+ </a>
20
+ </div>
21
+
22
+ <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
+
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
25
+
26
+ ---
27
+
28
+ ## Highlights
29
+
30
+ - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
+ - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
+ - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
+ - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
+ - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
+ - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
+ - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
+ - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
+ - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
+ - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
+ - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
+ - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
+ - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
+ - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
+ - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
+ - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
46
+
47
+ ## Documentation
48
+
49
+ You can find the full documentation [here](https://orpc.unnoq.com).
50
+
51
+ ## Packages
52
+
53
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+ - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
+ - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+
62
+ ## `@orpc/shared`
63
+
64
+ Provides shared utilities for oRPC packages.
65
+
66
+ ## License
67
+
68
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
package/dist/index.js CHANGED
@@ -48,6 +48,9 @@ function isObject(value2) {
48
48
  const proto = Object.getPrototypeOf(value2);
49
49
  return proto === Object.prototype || !proto || !proto.constructor;
50
50
  }
51
+ function isTypescriptObject(value2) {
52
+ return !!value2 && (typeof value2 === "object" || typeof value2 === "function");
53
+ }
51
54
 
52
55
  // src/error.ts
53
56
  function toError(error) {
@@ -68,6 +71,19 @@ function toError(error) {
68
71
  return new Error("Unknown error", { cause: error });
69
72
  }
70
73
 
74
+ // src/function.ts
75
+ function once(fn) {
76
+ let cached;
77
+ return () => {
78
+ if (cached) {
79
+ return cached.result;
80
+ }
81
+ const result = fn();
82
+ cached = { result };
83
+ return result;
84
+ };
85
+ }
86
+
71
87
  // src/interceptor.ts
72
88
  function onStart(callback) {
73
89
  return async (options, ...rest) => {
@@ -122,6 +138,25 @@ async function intercept(interceptors, options, main) {
122
138
  return await next(options);
123
139
  }
124
140
 
141
+ // src/iterator.ts
142
+ function isAsyncIteratorObject(maybe) {
143
+ if (!maybe || typeof maybe !== "object") {
144
+ return false;
145
+ }
146
+ return Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
147
+ }
148
+
149
+ // src/json.ts
150
+ function parseEmptyableJSON(text) {
151
+ if (!text) {
152
+ return void 0;
153
+ }
154
+ return JSON.parse(text);
155
+ }
156
+ function stringifyJSON(value2) {
157
+ return JSON.stringify(value2);
158
+ }
159
+
125
160
  // src/value.ts
126
161
  function value(value2, ...args) {
127
162
  if (typeof value2 === "function") {
@@ -138,7 +173,9 @@ export {
138
173
  group,
139
174
  guard,
140
175
  intercept,
176
+ isAsyncIteratorObject,
141
177
  isObject,
178
+ isTypescriptObject,
142
179
  mapEntries,
143
180
  mapValues,
144
181
  omit,
@@ -146,8 +183,11 @@ export {
146
183
  onFinish,
147
184
  onStart,
148
185
  onSuccess,
186
+ once,
187
+ parseEmptyableJSON,
149
188
  retry,
150
189
  set,
190
+ stringifyJSON,
151
191
  toError,
152
192
  trim,
153
193
  value
@@ -1,2 +1,3 @@
1
1
  export type AnyFunction = (...args: any[]) => any;
2
+ export declare function once<T extends () => any>(fn: T): () => ReturnType<T>;
2
3
  //# sourceMappingURL=function.d.ts.map
@@ -2,6 +2,8 @@ export * from './chain';
2
2
  export * from './error';
3
3
  export * from './function';
4
4
  export * from './interceptor';
5
+ export * from './iterator';
6
+ export * from './json';
5
7
  export * from './object';
6
8
  export * from './types';
7
9
  export * from './value';
@@ -0,0 +1,2 @@
1
+ export declare function isAsyncIteratorObject(maybe: unknown): maybe is AsyncIteratorObject<any, any, any>;
2
+ //# sourceMappingURL=iterator.d.ts.map
@@ -0,0 +1,3 @@
1
+ export declare function parseEmptyableJSON(text: string | null | undefined): unknown;
2
+ export declare function stringifyJSON<T>(value: T): undefined extends T ? undefined | string : string;
3
+ //# sourceMappingURL=json.d.ts.map
@@ -9,4 +9,8 @@ export declare function findDeepMatches(check: (value: unknown) => boolean, payl
9
9
  * Check if the value is an object even it created by `Object.create(null)` or more tricky way.
10
10
  */
11
11
  export declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
12
+ /**
13
+ * Check if the value satisfy a `object` type in typescript
14
+ */
15
+ export declare function isTypescriptObject(value: unknown): value is object & Record<PropertyKey, unknown>;
12
16
  //# sourceMappingURL=object.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.fe39bf3",
4
+ "version": "0.0.0-next.fea68c1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {