ts-typed-api 0.1.3 → 0.1.4

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/client.js CHANGED
@@ -1,6 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiClient = exports.FetchHttpClientAdapter = void 0;
4
+ // Browser compatibility: Mock Buffer if not available (Node.js specific)
5
+ if (typeof globalThis !== 'undefined' && typeof globalThis.Buffer === 'undefined') {
6
+ // Create a minimal Buffer mock for browser environments
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ globalThis.Buffer = {
9
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
+ isBuffer: (_obj) => false,
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ from: (data, _encoding) => {
13
+ if (typeof data === 'string') {
14
+ return new TextEncoder().encode(data);
15
+ }
16
+ return new Uint8Array(data);
17
+ },
18
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
19
+ alloc: (size, _fill) => new Uint8Array(size),
20
+ allocUnsafe: (size) => new Uint8Array(size),
21
+ concat: (list, totalLength) => {
22
+ const total = totalLength || list.reduce((acc, arr) => acc + arr.length, 0);
23
+ const result = new Uint8Array(total);
24
+ let offset = 0;
25
+ for (const arr of list) {
26
+ result.set(arr, offset);
27
+ offset += arr.length;
28
+ }
29
+ return result;
30
+ }
31
+ };
32
+ }
4
33
  // --- Fetch Implementation of the Adapter ---
5
34
  /**
6
35
  * An HttpClientAdapter implementation that uses the native Fetch API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-typed-api",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A lightweight, type-safe RPC library for TypeScript with Zod validation",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/client.ts CHANGED
@@ -1,3 +1,33 @@
1
+ // Browser compatibility: Mock Buffer if not available (Node.js specific)
2
+ if (typeof globalThis !== 'undefined' && typeof globalThis.Buffer === 'undefined') {
3
+ // Create a minimal Buffer mock for browser environments
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ (globalThis as any).Buffer = {
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
+ isBuffer: (_obj: any) => false,
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
+ from: (data: any, _encoding?: string) => {
10
+ if (typeof data === 'string') {
11
+ return new TextEncoder().encode(data);
12
+ }
13
+ return new Uint8Array(data);
14
+ },
15
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
+ alloc: (size: number, _fill?: any) => new Uint8Array(size),
17
+ allocUnsafe: (size: number) => new Uint8Array(size),
18
+ concat: (list: Uint8Array[], totalLength?: number) => {
19
+ const total = totalLength || list.reduce((acc, arr) => acc + arr.length, 0);
20
+ const result = new Uint8Array(total);
21
+ let offset = 0;
22
+ for (const arr of list) {
23
+ result.set(arr, offset);
24
+ offset += arr.length;
25
+ }
26
+ return result;
27
+ }
28
+ };
29
+ }
30
+
1
31
  import {
2
32
  type ApiDefinitionSchema as BaseApiDefinitionSchema, // Renamed for clarity
3
33
  type ApiClientParams,