typed-bridge 2.0.8 → 2.0.9

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/context.md CHANGED
@@ -102,32 +102,32 @@ createMiddleware('user.*', async (req, res) => {
102
102
 
103
103
  ---
104
104
 
105
- ## **How to Validate with `$z` (Zod)**
105
+ ## **How to Validate Zod**
106
106
 
107
107
  ```ts
108
108
  // src/bridge/user/types.ts
109
- import { $z } from 'typed-bridge'
109
+ import { z } from 'zod'
110
110
 
111
111
  export const fetch = {
112
- args: $z.object({ id: $z.number().min(1) }),
113
- res: $z.object({
114
- id: $z.number(),
115
- name: $z.string(),
116
- email: $z.string().email(),
117
- createdAt: $z.date()
112
+ args: z.object({ id: z.number().min(1) }),
113
+ res: z.object({
114
+ id: z.number(),
115
+ name: z.string(),
116
+ email: z.string().email(),
117
+ createdAt: z.date()
118
118
  })
119
119
  }
120
120
  ```
121
121
 
122
122
  ```ts
123
123
  // src/bridge/user/index.ts (validated version)
124
- import { $z } from 'typed-bridge'
124
+ import { z } from 'zod'
125
125
  import * as types from './types.js'
126
126
 
127
127
  export const fetch = async (
128
- args: $z.infer<typeof types.fetch.args>,
128
+ args: z.infer<typeof types.fetch.args>,
129
129
  context: { userId?: number }
130
- ): Promise<$z.infer<typeof types.fetch.res>> => {
130
+ ): Promise<z.infer<typeof types.fetch.res>> => {
131
131
  args = types.fetch.args.parse(args)
132
132
  const user = users.find(u => u.id === args.id)
133
133
  if (!user) throw new Error(`User ${args.id} not found`)
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -41,6 +8,7 @@ const chalk_1 = __importDefault(require("chalk"));
41
8
  const compression_1 = __importDefault(require("compression"));
42
9
  const cors_1 = __importDefault(require("cors"));
43
10
  const express_1 = __importDefault(require("express"));
11
+ const path_1 = __importDefault(require("path"));
44
12
  const __1 = require("..");
45
13
  const helpers_1 = require("../helpers");
46
14
  const middlewares = [];
@@ -105,9 +73,9 @@ const createBridge = (bridge, port, path = '/bridge') => {
105
73
  setTimeout(next, __1.tbConfig.responseDelay);
106
74
  });
107
75
  // Server health
108
- Promise.resolve().then(() => __importStar(require('path'))).then(_path => app.use(_path.join(path, 'health'), (req, res) => {
76
+ app.use(path_1.default.join(path, 'health'), (req, res) => {
109
77
  res.sendStatus(200);
110
- }));
78
+ });
111
79
  app.use(path, bridgeHandler(bridge));
112
80
  const server = app.listen(port, () => (0, helpers_1.printStartLogs)(port));
113
81
  let shuttingDown = false;
@@ -1,4 +1,4 @@
1
- import { $z } from '@/index';
1
+ import { z } from 'zod';
2
2
  import * as types from './types';
3
3
  export interface User {
4
4
  id: number;
@@ -6,9 +6,9 @@ export interface User {
6
6
  email: string;
7
7
  createdAt: Date;
8
8
  }
9
- export declare const fetch: (args: $z.infer<typeof types.fetch.args>, context: {
9
+ export declare const fetch: (args: z.infer<typeof types.fetch.args>, context: {
10
10
  id: number;
11
- }) => Promise<$z.infer<typeof types.fetch.res>>;
11
+ }) => Promise<z.infer<typeof types.fetch.res>>;
12
12
  export declare const update: (args: {
13
13
  id: number;
14
14
  name?: string;
@@ -1,16 +1,16 @@
1
- import { $z } from '@/index';
1
+ import { z } from 'zod';
2
2
  export declare const fetch: {
3
- args: $z.ZodObject<{
4
- id: $z.ZodNumber;
5
- }, "strip", $z.ZodTypeAny, {
3
+ args: z.ZodObject<{
4
+ id: z.ZodNumber;
5
+ }, "strip", z.ZodTypeAny, {
6
6
  id: number;
7
7
  }, {
8
8
  id: number;
9
9
  }>;
10
- res: $z.ZodObject<{
11
- id: $z.ZodNumber;
12
- name: $z.ZodString;
13
- }, "strip", $z.ZodTypeAny, {
10
+ res: z.ZodObject<{
11
+ id: z.ZodNumber;
12
+ name: z.ZodString;
13
+ }, "strip", z.ZodTypeAny, {
14
14
  id: number;
15
15
  name: string;
16
16
  }, {
@@ -18,9 +18,9 @@ export declare const fetch: {
18
18
  name: string;
19
19
  }>;
20
20
  };
21
- export declare const userContext: $z.ZodObject<{
22
- id: $z.ZodNumber;
23
- }, "strip", $z.ZodTypeAny, {
21
+ export declare const userContext: z.ZodObject<{
22
+ id: z.ZodNumber;
23
+ }, "strip", z.ZodTypeAny, {
24
24
  id: number;
25
25
  }, {
26
26
  id: number;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.userContext = exports.fetch = void 0;
4
- const index_1 = require("@/index");
4
+ const zod_1 = require("zod");
5
5
  exports.fetch = {
6
- args: index_1.$z.object({
7
- id: index_1.$z.number().min(1)
6
+ args: zod_1.z.object({
7
+ id: zod_1.z.number().min(1)
8
8
  }),
9
- res: index_1.$z.object({
10
- id: index_1.$z.number(),
11
- name: index_1.$z.string()
9
+ res: zod_1.z.object({
10
+ id: zod_1.z.number(),
11
+ name: zod_1.z.string()
12
12
  })
13
13
  };
14
- exports.userContext = index_1.$z.object({
15
- id: index_1.$z.number()
14
+ exports.userContext = zod_1.z.object({
15
+ id: zod_1.z.number()
16
16
  });
@@ -1,3 +1,3 @@
1
- export declare const printStartLogs: (port: number) => Promise<void>;
1
+ export declare const printStartLogs: (port: number) => void;
2
2
  export declare const printStopLogs: () => void;
3
3
  export declare const matchesPattern: (str: string, pattern: string) => boolean;
@@ -1,46 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.matchesPattern = exports.printStopLogs = exports.printStartLogs = void 0;
40
7
  const chalk_1 = __importDefault(require("chalk"));
41
- const getLocalIPList = async () => {
42
- const os = await Promise.resolve().then(() => __importStar(require('os')));
43
- const interfaces = os.networkInterfaces();
8
+ const os_1 = __importDefault(require("os"));
9
+ const getLocalIPList = () => {
10
+ const interfaces = os_1.default.networkInterfaces();
44
11
  const ipList = [];
45
12
  Object.values(interfaces).forEach(ifaceArr => {
46
13
  ifaceArr?.forEach(iface => {
@@ -57,8 +24,8 @@ const getLocalIPList = async () => {
57
24
  return ipList;
58
25
  };
59
26
  const seperator = '\n-x-x-x-x-x-\n';
60
- const printStartLogs = async (port) => {
61
- const ipList = await getLocalIPList();
27
+ const printStartLogs = (port) => {
28
+ const ipList = getLocalIPList();
62
29
  console.log(ipList);
63
30
  console.log(seperator);
64
31
  console.log(chalk_1.default.bgWhite.black(' Typed Bridge '));
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import 'dotenv/config';
2
2
  export { Application, default as express, Express, NextFunction, Request, Response, Router } from 'express';
3
- export { z as $z } from 'zod';
4
3
  export { createBridge, createMiddleware, onShutdown } from './bridge';
5
4
  export { config as tbConfig } from './config';
package/dist/index.js CHANGED
@@ -3,13 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.tbConfig = exports.onShutdown = exports.createMiddleware = exports.createBridge = exports.$z = exports.Router = exports.express = void 0;
6
+ exports.tbConfig = exports.onShutdown = exports.createMiddleware = exports.createBridge = exports.Router = exports.express = void 0;
7
7
  require("dotenv/config");
8
8
  var express_1 = require("express");
9
9
  Object.defineProperty(exports, "express", { enumerable: true, get: function () { return __importDefault(express_1).default; } });
10
10
  Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
11
- var zod_1 = require("zod");
12
- Object.defineProperty(exports, "$z", { enumerable: true, get: function () { return zod_1.z; } });
13
11
  var bridge_1 = require("./bridge");
14
12
  Object.defineProperty(exports, "createBridge", { enumerable: true, get: function () { return bridge_1.createBridge; } });
15
13
  Object.defineProperty(exports, "createMiddleware", { enumerable: true, get: function () { return bridge_1.createMiddleware; } });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typed-bridge",
3
3
  "description": "Strictly typed server functions for typescript apps",
4
- "version": "2.0.8",
4
+ "version": "2.0.9",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "author": "neilveil",
@@ -28,8 +28,7 @@
28
28
  "express": "^5.1.0",
29
29
  "rollup": "^4.40.0",
30
30
  "rollup-plugin-dts": "^6.2.1",
31
- "typescript": "^5.8.3",
32
- "zod": "^3.24.3"
31
+ "typescript": "^5.8.3"
33
32
  },
34
33
  "devDependencies": {
35
34
  "@eslint/js": "^9.25.0",
@@ -47,7 +46,8 @@
47
46
  "rimraf": "^6.0.1",
48
47
  "ts-node": "^10.9.2",
49
48
  "tsconfig-paths": "^4.2.0",
50
- "typescript-eslint": "^8.30.1"
49
+ "typescript-eslint": "^8.30.1",
50
+ "zod": "^3.24.3"
51
51
  },
52
52
  "keywords": [
53
53
  "api",
package/readme.md CHANGED
@@ -230,33 +230,33 @@ createMiddleware('user.*', async (req, res) => {
230
230
  `types.ts`
231
231
 
232
232
  ```ts
233
- import { $z } from 'typed-bridge'
233
+ import { z } from 'zod'
234
234
 
235
235
  export const fetch = {
236
- args: $z.object({
237
- id: $z.number().min(1)
236
+ args: z.object({
237
+ id: z.number().min(1)
238
238
  }),
239
- res: $z.object({
240
- id: $z.number(),
241
- name: $z.string()
239
+ res: z.object({
240
+ id: z.number(),
241
+ name: z.string()
242
242
  })
243
243
  }
244
244
 
245
- export const userContext = $z.object({
246
- id: $z.number()
245
+ export const userContext = z.object({
246
+ id: z.number()
247
247
  })
248
248
  ```
249
249
 
250
250
  #### Use in bridge handler
251
251
 
252
252
  ```ts
253
- import { $z } from 'typed-bridge'
253
+ import { z } from 'zod'
254
254
  import * as types from './types'
255
255
 
256
256
  export const fetch = async (
257
- args: $z.infer<typeof types.fetch.args>,
257
+ args: z.infer<typeof types.fetch.args>,
258
258
  context: { id: number }
259
- ): Promise<$z.infer<typeof types.fetch.res>> => {
259
+ ): Promise<z.infer<typeof types.fetch.res>> => {
260
260
  args = types.fetch.args.parse(args)
261
261
 
262
262
  console.log(context)