@zap-js/client 0.0.8 → 0.1.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/cli/commands/build.js +49 -16
- package/dist/cli/commands/dev.js +3 -29
- package/dist/cli/utils/binary-resolver.d.ts +22 -0
- package/dist/cli/utils/binary-resolver.js +71 -0
- package/dist/runtime/browser.d.ts +112 -0
- package/dist/runtime/browser.js +136 -0
- package/dist/runtime/client.d.ts +12 -0
- package/dist/runtime/client.js +12 -0
- package/dist/runtime/index.js +7 -0
- package/dist/runtime/node.d.ts +22 -0
- package/dist/runtime/node.js +43 -0
- package/dist/runtime/server.d.ts +12 -0
- package/dist/runtime/server.js +12 -0
- package/package.json +26 -4
- package/bin/zap +0 -0
- package/bin/zap-codegen +0 -0
|
@@ -2,6 +2,7 @@ import { execSync } from 'child_process';
|
|
|
2
2
|
import { join, resolve } from 'path';
|
|
3
3
|
import { existsSync, mkdirSync, copyFileSync, readdirSync, statSync, rmSync, writeFileSync } from 'fs';
|
|
4
4
|
import { cliLogger } from '../utils/logger.js';
|
|
5
|
+
import { resolveBinary, getPlatformIdentifier } from '../utils/binary-resolver.js';
|
|
5
6
|
/**
|
|
6
7
|
* Build for production
|
|
7
8
|
*/
|
|
@@ -60,7 +61,37 @@ export async function buildCommand(options) {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
async function buildRust(outputDir, options) {
|
|
63
|
-
|
|
64
|
+
const projectDir = process.cwd();
|
|
65
|
+
// STEP 1: Try to use pre-built binary from platform package
|
|
66
|
+
const prebuiltBinary = resolveBinary('zap', projectDir);
|
|
67
|
+
if (prebuiltBinary && existsSync(prebuiltBinary)) {
|
|
68
|
+
cliLogger.spinner('rust', 'Using pre-built binary...');
|
|
69
|
+
const platformId = getPlatformIdentifier();
|
|
70
|
+
try {
|
|
71
|
+
// Copy pre-built binary to output directory
|
|
72
|
+
const destBinary = join(outputDir, 'bin', 'zap');
|
|
73
|
+
copyFileSync(prebuiltBinary, destBinary);
|
|
74
|
+
execSync(`chmod +x "${destBinary}"`, { stdio: 'pipe' });
|
|
75
|
+
cliLogger.succeedSpinner('rust', `Using pre-built binary for ${platformId}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
cliLogger.failSpinner('rust', 'Failed to copy pre-built binary');
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// STEP 2: No pre-built binary found - check if we can build from source
|
|
84
|
+
const cargoTomlPath = join(projectDir, 'Cargo.toml');
|
|
85
|
+
if (!existsSync(cargoTomlPath)) {
|
|
86
|
+
cliLogger.failSpinner('rust', 'No binary available');
|
|
87
|
+
throw new Error('Cannot build: No pre-built binary found and no Cargo.toml to build from source.\n' +
|
|
88
|
+
'\n' +
|
|
89
|
+
'Solutions:\n' +
|
|
90
|
+
`1. Install platform package: npm install @zap-js/${getPlatformIdentifier()}\n` +
|
|
91
|
+
'2. Or build from source by cloning the ZapJS repository');
|
|
92
|
+
}
|
|
93
|
+
// STEP 3: Build from source with cargo
|
|
94
|
+
cliLogger.spinner('rust', 'Building Rust backend from source (release mode)...');
|
|
64
95
|
const args = ['build', '--release', '--bin', 'zap'];
|
|
65
96
|
if (options.target) {
|
|
66
97
|
args.push('--target', options.target);
|
|
@@ -122,7 +153,7 @@ async function buildRust(outputDir, options) {
|
|
|
122
153
|
const destBinary = join(outputDir, 'bin', 'zap');
|
|
123
154
|
copyFileSync(srcBinary, destBinary);
|
|
124
155
|
execSync(`chmod +x "${destBinary}"`, { stdio: 'pipe' });
|
|
125
|
-
cliLogger.succeedSpinner('rust', 'Rust backend built (release + LTO)');
|
|
156
|
+
cliLogger.succeedSpinner('rust', 'Rust backend built from source (release + LTO)');
|
|
126
157
|
}
|
|
127
158
|
catch (error) {
|
|
128
159
|
cliLogger.failSpinner('rust', 'Rust build failed');
|
|
@@ -188,22 +219,24 @@ async function typeCheck() {
|
|
|
188
219
|
}
|
|
189
220
|
async function runCodegen() {
|
|
190
221
|
const projectDir = process.cwd();
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
222
|
+
// Try to resolve codegen binary using binary resolver
|
|
223
|
+
let codegenBinary = resolveBinary('zap-codegen', projectDir);
|
|
224
|
+
// If not found, try workspace target locations (for development)
|
|
225
|
+
if (!codegenBinary) {
|
|
226
|
+
const possiblePaths = [
|
|
227
|
+
join(projectDir, '../../target/release/zap-codegen'),
|
|
228
|
+
join(projectDir, '../../target/aarch64-apple-darwin/release/zap-codegen'),
|
|
229
|
+
join(projectDir, '../../target/x86_64-unknown-linux-gnu/release/zap-codegen'),
|
|
230
|
+
join(projectDir, 'target/release/zap-codegen'),
|
|
231
|
+
];
|
|
232
|
+
for (const path of possiblePaths) {
|
|
233
|
+
if (existsSync(path)) {
|
|
234
|
+
codegenBinary = path;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
204
237
|
}
|
|
205
238
|
}
|
|
206
|
-
// Try global zap-codegen as fallback
|
|
239
|
+
// Try global zap-codegen as final fallback
|
|
207
240
|
if (!codegenBinary) {
|
|
208
241
|
try {
|
|
209
242
|
execSync('which zap-codegen', { stdio: 'pipe' });
|
package/dist/cli/commands/dev.js
CHANGED
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
1
|
import { DevServer } from '../../dev-server/index.js';
|
|
4
2
|
import { cliLogger } from '../utils/logger.js';
|
|
5
|
-
|
|
6
|
-
* Auto-detect pre-built binaries in bin/ directory
|
|
7
|
-
*/
|
|
8
|
-
function detectBinaries(projectDir) {
|
|
9
|
-
const binDir = path.join(projectDir, 'bin');
|
|
10
|
-
const result = {};
|
|
11
|
-
// Check for zap binary
|
|
12
|
-
const zapBinary = path.join(binDir, 'zap');
|
|
13
|
-
const zapBinaryExe = path.join(binDir, 'zap.exe');
|
|
14
|
-
if (existsSync(zapBinary)) {
|
|
15
|
-
result.binaryPath = zapBinary;
|
|
16
|
-
}
|
|
17
|
-
else if (existsSync(zapBinaryExe)) {
|
|
18
|
-
result.binaryPath = zapBinaryExe;
|
|
19
|
-
}
|
|
20
|
-
// Check for zap-codegen binary
|
|
21
|
-
const codegenBinary = path.join(binDir, 'zap-codegen');
|
|
22
|
-
const codegenBinaryExe = path.join(binDir, 'zap-codegen.exe');
|
|
23
|
-
if (existsSync(codegenBinary)) {
|
|
24
|
-
result.codegenBinaryPath = codegenBinary;
|
|
25
|
-
}
|
|
26
|
-
else if (existsSync(codegenBinaryExe)) {
|
|
27
|
-
result.codegenBinaryPath = codegenBinaryExe;
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
3
|
+
import { detectBinaries, getPlatformIdentifier } from '../utils/binary-resolver.js';
|
|
31
4
|
/**
|
|
32
5
|
* Start development server with hot reload
|
|
33
6
|
*
|
|
@@ -54,7 +27,8 @@ export async function devCommand(options) {
|
|
|
54
27
|
};
|
|
55
28
|
// Log if using pre-built binaries
|
|
56
29
|
if (config.binaryPath) {
|
|
57
|
-
|
|
30
|
+
const platformId = getPlatformIdentifier();
|
|
31
|
+
cliLogger.info(`Using pre-built binary for ${platformId}`, config.binaryPath);
|
|
58
32
|
}
|
|
59
33
|
const server = new DevServer(config);
|
|
60
34
|
// Handle graceful shutdown
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the path to a ZapJS binary using multiple strategies:
|
|
3
|
+
* 1. Platform-specific npm package (@zap-js/darwin-arm64, etc.)
|
|
4
|
+
* 2. Local bin/ directory in user's project (for development/custom builds)
|
|
5
|
+
* 3. Returns null to trigger cargo build fallback
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveBinary(binaryName: 'zap' | 'zap-codegen', projectDir?: string): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Detects both zap and zap-codegen binaries
|
|
10
|
+
*/
|
|
11
|
+
export declare function detectBinaries(projectDir: string): {
|
|
12
|
+
binaryPath?: string;
|
|
13
|
+
codegenBinaryPath?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Gets the platform identifier (e.g., "darwin-arm64")
|
|
17
|
+
*/
|
|
18
|
+
export declare function getPlatformIdentifier(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a platform-specific package is installed
|
|
21
|
+
*/
|
|
22
|
+
export declare function isPlatformPackageInstalled(): boolean;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = path.dirname(__filename);
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the path to a ZapJS binary using multiple strategies:
|
|
8
|
+
* 1. Platform-specific npm package (@zap-js/darwin-arm64, etc.)
|
|
9
|
+
* 2. Local bin/ directory in user's project (for development/custom builds)
|
|
10
|
+
* 3. Returns null to trigger cargo build fallback
|
|
11
|
+
*/
|
|
12
|
+
export function resolveBinary(binaryName, projectDir) {
|
|
13
|
+
const platform = process.platform;
|
|
14
|
+
const arch = process.arch;
|
|
15
|
+
// Strategy 1: Try platform-specific npm package
|
|
16
|
+
const platformPkg = `@zap-js/${platform}-${arch}`;
|
|
17
|
+
try {
|
|
18
|
+
// Try to resolve the platform package
|
|
19
|
+
const pkgPath = require.resolve(`${platformPkg}/package.json`);
|
|
20
|
+
const binPath = path.join(path.dirname(pkgPath), 'bin', binaryName);
|
|
21
|
+
if (existsSync(binPath)) {
|
|
22
|
+
return binPath;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
// Platform package not installed, continue to next strategy
|
|
27
|
+
}
|
|
28
|
+
// Strategy 2: Check local bin/ directory in user's project
|
|
29
|
+
if (projectDir) {
|
|
30
|
+
const localBin = path.join(projectDir, 'bin', binaryName);
|
|
31
|
+
const localBinExe = path.join(projectDir, 'bin', `${binaryName}.exe`);
|
|
32
|
+
if (existsSync(localBin)) {
|
|
33
|
+
return localBin;
|
|
34
|
+
}
|
|
35
|
+
if (existsSync(localBinExe)) {
|
|
36
|
+
return localBinExe;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Strategy 3: Return null (will trigger cargo build)
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Detects both zap and zap-codegen binaries
|
|
44
|
+
*/
|
|
45
|
+
export function detectBinaries(projectDir) {
|
|
46
|
+
const binaryPath = resolveBinary('zap', projectDir);
|
|
47
|
+
const codegenBinaryPath = resolveBinary('zap-codegen', projectDir);
|
|
48
|
+
return {
|
|
49
|
+
binaryPath: binaryPath || undefined,
|
|
50
|
+
codegenBinaryPath: codegenBinaryPath || undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the platform identifier (e.g., "darwin-arm64")
|
|
55
|
+
*/
|
|
56
|
+
export function getPlatformIdentifier() {
|
|
57
|
+
return `${process.platform}-${process.arch}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a platform-specific package is installed
|
|
61
|
+
*/
|
|
62
|
+
export function isPlatformPackageInstalled() {
|
|
63
|
+
const platformPkg = `@zap-js/${getPlatformIdentifier()}`;
|
|
64
|
+
try {
|
|
65
|
+
require.resolve(`${platformPkg}/package.json`);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe exports for @zap-js/client
|
|
3
|
+
*
|
|
4
|
+
* This entry point contains NO Node.js imports and is safe to use in:
|
|
5
|
+
* - Vite builds
|
|
6
|
+
* - Webpack builds
|
|
7
|
+
* - Browser environments
|
|
8
|
+
* - React/Vue/Svelte applications
|
|
9
|
+
*
|
|
10
|
+
* For server-side functionality, use @zap-js/client/node instead.
|
|
11
|
+
*/
|
|
12
|
+
export { RouterProvider, useRouter, useParams, usePathname, useSearchParams, useRouteMatch, useIsPending, Link, NavLink, Outlet, Redirect, type Router, type RouteDefinition, type RouteMatch, type RouterState, type NavigateOptions, type LinkProps, } from './router.js';
|
|
13
|
+
export { ErrorBoundary, DefaultErrorComponent, RouteErrorContext, createRouteError, ZapError, type ZapRouteError, type ErrorComponentProps, type ErrorComponent, } from './error-boundary.js';
|
|
14
|
+
export { useRouteError, useIsErrorState, useErrorState, } from './hooks.js';
|
|
15
|
+
export { getCsrfToken, useCsrfToken, createCsrfFetch, CsrfTokenInput, CsrfForm, addCsrfToFormData, getCsrfHeaders, type CsrfConfig, type CsrfTokenInputProps, type CsrfFormProps, } from './csrf.js';
|
|
16
|
+
export { composeMiddleware, requireAuth, requireRole, routeLogger, preloadData, type MiddlewareContext, type MiddlewareResult, type MiddlewareFunction, type RouteMiddleware, } from './middleware.js';
|
|
17
|
+
export * from './streaming-utils.js';
|
|
18
|
+
export * from './websockets-utils.js';
|
|
19
|
+
export type { Handler, ZapRequest, ZapHandlerResponse, RouteConfig, HttpMethod, MiddlewareConfig, FileRouteConfig, StreamChunk, StreamingHandler, AnyHandler, StreamStartMessage, StreamChunkMessage, StreamEndMessage, StreamMessage, WsConnection, WsHandler, WsConnectMessage, WsMessageMessage, WsCloseMessage, WsSendMessage, WsMessage, } from './types.js';
|
|
20
|
+
export { isInvokeHandlerMessage, isHandlerResponseMessage, isErrorMessage, isHealthCheckMessage, isHealthCheckResponseMessage, isRpcResponseMessage, isRpcErrorMessage, isAsyncIterable, } from './types.js';
|
|
21
|
+
/**
|
|
22
|
+
* Router namespace - all routing functionality
|
|
23
|
+
* Usage: import { router } from '@zap-js/client/browser'
|
|
24
|
+
*/
|
|
25
|
+
import { RouterProvider, useRouter as useRouterFn, useParams as useParamsFn, usePathname as usePathnameFn, useSearchParams as useSearchParamsFn, useRouteMatch as useRouteMatchFn, useIsPending as useIsPendingFn, Link, NavLink, Outlet, Redirect } from './router.js';
|
|
26
|
+
export declare const router: {
|
|
27
|
+
readonly RouterProvider: typeof RouterProvider;
|
|
28
|
+
readonly useRouter: typeof useRouterFn;
|
|
29
|
+
readonly useParams: typeof useParamsFn;
|
|
30
|
+
readonly usePathname: typeof usePathnameFn;
|
|
31
|
+
readonly useSearchParams: typeof useSearchParamsFn;
|
|
32
|
+
readonly useRouteMatch: typeof useRouteMatchFn;
|
|
33
|
+
readonly useIsPending: typeof useIsPendingFn;
|
|
34
|
+
readonly Link: typeof Link;
|
|
35
|
+
readonly NavLink: typeof NavLink;
|
|
36
|
+
readonly Outlet: typeof Outlet;
|
|
37
|
+
readonly Redirect: typeof Redirect;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Errors namespace - error handling and boundaries
|
|
41
|
+
* Usage: import { errors } from '@zap-js/client/browser'
|
|
42
|
+
*/
|
|
43
|
+
import { ErrorBoundary, DefaultErrorComponent, createRouteError, ZapError } from './error-boundary.js';
|
|
44
|
+
import { useRouteError, useIsErrorState, useErrorState } from './hooks.js';
|
|
45
|
+
export declare const errors: {
|
|
46
|
+
readonly ErrorBoundary: typeof ErrorBoundary;
|
|
47
|
+
readonly DefaultErrorComponent: typeof DefaultErrorComponent;
|
|
48
|
+
readonly createRouteError: typeof createRouteError;
|
|
49
|
+
readonly ZapError: typeof ZapError;
|
|
50
|
+
readonly useRouteError: typeof useRouteError;
|
|
51
|
+
readonly useIsErrorState: typeof useIsErrorState;
|
|
52
|
+
readonly useErrorState: typeof useErrorState;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Middleware namespace - route middleware utilities
|
|
56
|
+
* Usage: import { middleware } from '@zap-js/client/browser'
|
|
57
|
+
*/
|
|
58
|
+
import { composeMiddleware, requireAuth, requireRole, routeLogger, preloadData } from './middleware.js';
|
|
59
|
+
export declare const middleware: {
|
|
60
|
+
readonly compose: typeof composeMiddleware;
|
|
61
|
+
readonly requireAuth: typeof requireAuth;
|
|
62
|
+
readonly requireRole: typeof requireRole;
|
|
63
|
+
readonly logger: typeof routeLogger;
|
|
64
|
+
readonly preloadData: typeof preloadData;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Types namespace - type definitions and guards
|
|
68
|
+
* Usage: import { types } from '@zap-js/client/browser'
|
|
69
|
+
*/
|
|
70
|
+
import * as TypeGuards from './types.js';
|
|
71
|
+
export declare const types: {
|
|
72
|
+
readonly isInvokeHandlerMessage: typeof TypeGuards.isInvokeHandlerMessage;
|
|
73
|
+
readonly isHandlerResponseMessage: typeof TypeGuards.isHandlerResponseMessage;
|
|
74
|
+
readonly isErrorMessage: typeof TypeGuards.isErrorMessage;
|
|
75
|
+
readonly isHealthCheckMessage: typeof TypeGuards.isHealthCheckMessage;
|
|
76
|
+
readonly isHealthCheckResponseMessage: typeof TypeGuards.isHealthCheckResponseMessage;
|
|
77
|
+
readonly isRpcResponseMessage: typeof TypeGuards.isRpcResponseMessage;
|
|
78
|
+
readonly isRpcErrorMessage: typeof TypeGuards.isRpcErrorMessage;
|
|
79
|
+
readonly isAsyncIterable: typeof TypeGuards.isAsyncIterable;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* WebSockets namespace - WebSocket utilities and helpers
|
|
83
|
+
* Usage: import { websockets } from '@zap-js/client/browser'
|
|
84
|
+
*/
|
|
85
|
+
import * as WebSocketUtils from './websockets-utils.js';
|
|
86
|
+
export declare const websockets: {
|
|
87
|
+
readonly isWsMessage: typeof WebSocketUtils.isWsMessage;
|
|
88
|
+
readonly broadcast: typeof WebSocketUtils.broadcast;
|
|
89
|
+
readonly broadcastExcept: typeof WebSocketUtils.broadcastExcept;
|
|
90
|
+
readonly sendJson: typeof WebSocketUtils.sendJson;
|
|
91
|
+
readonly parseMessage: typeof WebSocketUtils.parseMessage;
|
|
92
|
+
readonly createErrorMessage: typeof WebSocketUtils.createErrorMessage;
|
|
93
|
+
readonly createSuccessMessage: typeof WebSocketUtils.createSuccessMessage;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Streaming namespace - Streaming response utilities
|
|
97
|
+
* Usage: import { streaming } from '@zap-js/client/browser'
|
|
98
|
+
*/
|
|
99
|
+
import * as StreamingUtils from './streaming-utils.js';
|
|
100
|
+
export declare const streaming: {
|
|
101
|
+
readonly isAsyncIterable: typeof TypeGuards.isAsyncIterable;
|
|
102
|
+
readonly createChunk: typeof StreamingUtils.createChunk;
|
|
103
|
+
readonly createStream: typeof StreamingUtils.createStream;
|
|
104
|
+
readonly streamJson: typeof StreamingUtils.streamJson;
|
|
105
|
+
readonly streamSSE: typeof StreamingUtils.streamSSE;
|
|
106
|
+
readonly mapStream: typeof StreamingUtils.mapStream;
|
|
107
|
+
readonly filterStream: typeof StreamingUtils.filterStream;
|
|
108
|
+
readonly batchStream: typeof StreamingUtils.batchStream;
|
|
109
|
+
readonly delayStream: typeof StreamingUtils.delayStream;
|
|
110
|
+
readonly fromReadableStream: typeof StreamingUtils.fromReadableStream;
|
|
111
|
+
readonly intervalStream: typeof StreamingUtils.intervalStream;
|
|
112
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe exports for @zap-js/client
|
|
3
|
+
*
|
|
4
|
+
* This entry point contains NO Node.js imports and is safe to use in:
|
|
5
|
+
* - Vite builds
|
|
6
|
+
* - Webpack builds
|
|
7
|
+
* - Browser environments
|
|
8
|
+
* - React/Vue/Svelte applications
|
|
9
|
+
*
|
|
10
|
+
* For server-side functionality, use @zap-js/client/node instead.
|
|
11
|
+
*/
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Router Exports (Client-side)
|
|
14
|
+
// ============================================================================
|
|
15
|
+
export {
|
|
16
|
+
// Provider
|
|
17
|
+
RouterProvider,
|
|
18
|
+
// Hooks
|
|
19
|
+
useRouter, useParams, usePathname, useSearchParams, useRouteMatch, useIsPending,
|
|
20
|
+
// Components
|
|
21
|
+
Link, NavLink, Outlet, Redirect, } from './router.js';
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Error Handling Exports
|
|
24
|
+
// ============================================================================
|
|
25
|
+
export { ErrorBoundary, DefaultErrorComponent, RouteErrorContext, createRouteError, ZapError, } from './error-boundary.js';
|
|
26
|
+
export { useRouteError, useIsErrorState, useErrorState, } from './hooks.js';
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// CSRF Protection Exports
|
|
29
|
+
// ============================================================================
|
|
30
|
+
export { getCsrfToken, useCsrfToken, createCsrfFetch, CsrfTokenInput, CsrfForm, addCsrfToFormData, getCsrfHeaders, } from './csrf.js';
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// Middleware Exports (Pure TypeScript, no Node.js deps)
|
|
33
|
+
// ============================================================================
|
|
34
|
+
export { composeMiddleware, requireAuth, requireRole, routeLogger, preloadData, } from './middleware.js';
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Utility Exports (Browser-safe)
|
|
37
|
+
// ============================================================================
|
|
38
|
+
export * from './streaming-utils.js';
|
|
39
|
+
export * from './websockets-utils.js';
|
|
40
|
+
// Re-export type guards (pure functions, no Node.js deps)
|
|
41
|
+
export { isInvokeHandlerMessage, isHandlerResponseMessage, isErrorMessage, isHealthCheckMessage, isHealthCheckResponseMessage, isRpcResponseMessage, isRpcErrorMessage, isAsyncIterable, } from './types.js';
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// Namespace Exports for Convenience
|
|
44
|
+
// ============================================================================
|
|
45
|
+
/**
|
|
46
|
+
* Router namespace - all routing functionality
|
|
47
|
+
* Usage: import { router } from '@zap-js/client/browser'
|
|
48
|
+
*/
|
|
49
|
+
import { RouterProvider, useRouter as useRouterFn, useParams as useParamsFn, usePathname as usePathnameFn, useSearchParams as useSearchParamsFn, useRouteMatch as useRouteMatchFn, useIsPending as useIsPendingFn, Link, NavLink, Outlet, Redirect, } from './router.js';
|
|
50
|
+
export const router = {
|
|
51
|
+
RouterProvider,
|
|
52
|
+
useRouter: useRouterFn,
|
|
53
|
+
useParams: useParamsFn,
|
|
54
|
+
usePathname: usePathnameFn,
|
|
55
|
+
useSearchParams: useSearchParamsFn,
|
|
56
|
+
useRouteMatch: useRouteMatchFn,
|
|
57
|
+
useIsPending: useIsPendingFn,
|
|
58
|
+
Link,
|
|
59
|
+
NavLink,
|
|
60
|
+
Outlet,
|
|
61
|
+
Redirect,
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Errors namespace - error handling and boundaries
|
|
65
|
+
* Usage: import { errors } from '@zap-js/client/browser'
|
|
66
|
+
*/
|
|
67
|
+
import { ErrorBoundary, DefaultErrorComponent, createRouteError, ZapError, } from './error-boundary.js';
|
|
68
|
+
import { useRouteError, useIsErrorState, useErrorState, } from './hooks.js';
|
|
69
|
+
export const errors = {
|
|
70
|
+
ErrorBoundary,
|
|
71
|
+
DefaultErrorComponent,
|
|
72
|
+
createRouteError,
|
|
73
|
+
ZapError,
|
|
74
|
+
useRouteError,
|
|
75
|
+
useIsErrorState,
|
|
76
|
+
useErrorState,
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Middleware namespace - route middleware utilities
|
|
80
|
+
* Usage: import { middleware } from '@zap-js/client/browser'
|
|
81
|
+
*/
|
|
82
|
+
import { composeMiddleware, requireAuth, requireRole, routeLogger, preloadData, } from './middleware.js';
|
|
83
|
+
export const middleware = {
|
|
84
|
+
compose: composeMiddleware,
|
|
85
|
+
requireAuth,
|
|
86
|
+
requireRole,
|
|
87
|
+
logger: routeLogger,
|
|
88
|
+
preloadData,
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Types namespace - type definitions and guards
|
|
92
|
+
* Usage: import { types } from '@zap-js/client/browser'
|
|
93
|
+
*/
|
|
94
|
+
import * as TypeGuards from './types.js';
|
|
95
|
+
export const types = {
|
|
96
|
+
isInvokeHandlerMessage: TypeGuards.isInvokeHandlerMessage,
|
|
97
|
+
isHandlerResponseMessage: TypeGuards.isHandlerResponseMessage,
|
|
98
|
+
isErrorMessage: TypeGuards.isErrorMessage,
|
|
99
|
+
isHealthCheckMessage: TypeGuards.isHealthCheckMessage,
|
|
100
|
+
isHealthCheckResponseMessage: TypeGuards.isHealthCheckResponseMessage,
|
|
101
|
+
isRpcResponseMessage: TypeGuards.isRpcResponseMessage,
|
|
102
|
+
isRpcErrorMessage: TypeGuards.isRpcErrorMessage,
|
|
103
|
+
isAsyncIterable: TypeGuards.isAsyncIterable,
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* WebSockets namespace - WebSocket utilities and helpers
|
|
107
|
+
* Usage: import { websockets } from '@zap-js/client/browser'
|
|
108
|
+
*/
|
|
109
|
+
import * as WebSocketUtils from './websockets-utils.js';
|
|
110
|
+
export const websockets = {
|
|
111
|
+
isWsMessage: WebSocketUtils.isWsMessage,
|
|
112
|
+
broadcast: WebSocketUtils.broadcast,
|
|
113
|
+
broadcastExcept: WebSocketUtils.broadcastExcept,
|
|
114
|
+
sendJson: WebSocketUtils.sendJson,
|
|
115
|
+
parseMessage: WebSocketUtils.parseMessage,
|
|
116
|
+
createErrorMessage: WebSocketUtils.createErrorMessage,
|
|
117
|
+
createSuccessMessage: WebSocketUtils.createSuccessMessage,
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Streaming namespace - Streaming response utilities
|
|
121
|
+
* Usage: import { streaming } from '@zap-js/client/browser'
|
|
122
|
+
*/
|
|
123
|
+
import * as StreamingUtils from './streaming-utils.js';
|
|
124
|
+
export const streaming = {
|
|
125
|
+
isAsyncIterable: StreamingUtils.isAsyncIterable,
|
|
126
|
+
createChunk: StreamingUtils.createChunk,
|
|
127
|
+
createStream: StreamingUtils.createStream,
|
|
128
|
+
streamJson: StreamingUtils.streamJson,
|
|
129
|
+
streamSSE: StreamingUtils.streamSSE,
|
|
130
|
+
mapStream: StreamingUtils.mapStream,
|
|
131
|
+
filterStream: StreamingUtils.filterStream,
|
|
132
|
+
batchStream: StreamingUtils.batchStream,
|
|
133
|
+
delayStream: StreamingUtils.delayStream,
|
|
134
|
+
fromReadableStream: StreamingUtils.fromReadableStream,
|
|
135
|
+
intervalStream: StreamingUtils.intervalStream,
|
|
136
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client exports for @zap-js/client
|
|
3
|
+
*
|
|
4
|
+
* Semantic alias for browser.ts - provides all browser-safe functionality.
|
|
5
|
+
* Use this when you want to be explicit about client-side code.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { router } from '@zap-js/client/client';
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export * from './browser.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client exports for @zap-js/client
|
|
3
|
+
*
|
|
4
|
+
* Semantic alias for browser.ts - provides all browser-safe functionality.
|
|
5
|
+
* Use this when you want to be explicit about client-side code.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { router } from '@zap-js/client/client';
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export * from './browser.js';
|
package/dist/runtime/index.js
CHANGED
|
@@ -3,6 +3,13 @@ import { tmpdir } from "os";
|
|
|
3
3
|
import { existsSync, readFileSync } from "fs";
|
|
4
4
|
import { ProcessManager } from "./process-manager.js";
|
|
5
5
|
import { IpcServer } from "./ipc-client.js";
|
|
6
|
+
// DEPRECATION WARNING - Show in development only
|
|
7
|
+
if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') {
|
|
8
|
+
console.warn('\x1b[33m[DEPRECATION]\x1b[0m Importing from @zap-js/client is deprecated.\n' +
|
|
9
|
+
'Use explicit imports:\n' +
|
|
10
|
+
' - Server/Node.js: import { Zap } from "@zap-js/client/node"\n' +
|
|
11
|
+
' - Browser/Client: import { router } from "@zap-js/client/browser"');
|
|
12
|
+
}
|
|
6
13
|
// Re-export type guards
|
|
7
14
|
export { isInvokeHandlerMessage, isHandlerResponseMessage, isErrorMessage, isHealthCheckMessage, isHealthCheckResponseMessage, isRpcResponseMessage, isRpcErrorMessage, isAsyncIterable, } from "./types.js";
|
|
8
15
|
// Re-export internal modules for dev-server usage
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js exports for @zap-js/client
|
|
3
|
+
*
|
|
4
|
+
* This entry point includes server-side functionality that requires Node.js:
|
|
5
|
+
* - Zap class (server instance)
|
|
6
|
+
* - ProcessManager (manages Rust binary)
|
|
7
|
+
* - IpcServer/IpcClient (inter-process communication)
|
|
8
|
+
* - Logger (server-side logging)
|
|
9
|
+
* - RPC client utilities
|
|
10
|
+
*
|
|
11
|
+
* For browser/client-side functionality, use @zap-js/client/browser instead.
|
|
12
|
+
*/
|
|
13
|
+
export { Zap } from './index.js';
|
|
14
|
+
export { ProcessManager } from './process-manager.js';
|
|
15
|
+
export { IpcServer, IpcClient } from './ipc-client.js';
|
|
16
|
+
export { rpcCall } from './rpc-client.js';
|
|
17
|
+
export { Logger, logger, type LogContext, type LogLevel, type ChildLogger } from './logger.js';
|
|
18
|
+
export type { Handler, ZapRequest, ZapHandlerResponse, ZapConfig, RouteConfig, MiddlewareConfig, StaticFileConfig, StaticFileOptions, FileRouteConfig, ZapOptions, IpcMessage, InvokeHandlerMessage, HandlerResponseMessage, ErrorMessage, HealthCheckMessage, HealthCheckResponseMessage, HttpMethod, InternalHandlerFunction, RpcMessage, RpcCallMessage, RpcResponseMessage, RpcErrorMessage, PendingRequest, SecurityConfig, SecurityHeadersConfig, HstsConfig, RateLimitConfig, CorsConfig, ObservabilityConfig, StreamChunk, StreamingHandler, AnyHandler, StreamStartMessage, StreamChunkMessage, StreamEndMessage, StreamMessage, WsConnection, WsHandler, WsConnectMessage, WsMessageMessage, WsCloseMessage, WsSendMessage, WsMessage, } from './types.js';
|
|
19
|
+
export { isInvokeHandlerMessage, isHandlerResponseMessage, isErrorMessage, isHealthCheckMessage, isHealthCheckResponseMessage, isRpcResponseMessage, isRpcErrorMessage, isAsyncIterable, } from './types.js';
|
|
20
|
+
export { composeMiddleware, requireAuth, requireRole, routeLogger, preloadData, type MiddlewareContext, type MiddlewareResult, type MiddlewareFunction, type RouteMiddleware, } from './middleware.js';
|
|
21
|
+
export { RouterProvider, useRouter, useParams, usePathname, useSearchParams, useRouteMatch, useIsPending, Link, NavLink, Outlet, Redirect, type Router, type RouteDefinition, type RouteMatch, type RouterState, type NavigateOptions, type LinkProps, ErrorBoundary, DefaultErrorComponent, RouteErrorContext, createRouteError, ZapError, type ZapRouteError, type ErrorComponentProps, type ErrorComponent, useRouteError, useIsErrorState, useErrorState, getCsrfToken, useCsrfToken, createCsrfFetch, CsrfTokenInput, CsrfForm, addCsrfToFormData, getCsrfHeaders, type CsrfConfig, type CsrfTokenInputProps, type CsrfFormProps, router, errors, middleware, types, websockets, streaming, } from './index.js';
|
|
22
|
+
export { default } from './index.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js exports for @zap-js/client
|
|
3
|
+
*
|
|
4
|
+
* This entry point includes server-side functionality that requires Node.js:
|
|
5
|
+
* - Zap class (server instance)
|
|
6
|
+
* - ProcessManager (manages Rust binary)
|
|
7
|
+
* - IpcServer/IpcClient (inter-process communication)
|
|
8
|
+
* - Logger (server-side logging)
|
|
9
|
+
* - RPC client utilities
|
|
10
|
+
*
|
|
11
|
+
* For browser/client-side functionality, use @zap-js/client/browser instead.
|
|
12
|
+
*/
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Server-Side Core Exports
|
|
15
|
+
// ============================================================================
|
|
16
|
+
export { Zap } from './index.js';
|
|
17
|
+
export { ProcessManager } from './process-manager.js';
|
|
18
|
+
export { IpcServer, IpcClient } from './ipc-client.js';
|
|
19
|
+
export { rpcCall } from './rpc-client.js';
|
|
20
|
+
export { Logger, logger } from './logger.js';
|
|
21
|
+
// Re-export type guards
|
|
22
|
+
export { isInvokeHandlerMessage, isHandlerResponseMessage, isErrorMessage, isHealthCheckMessage, isHealthCheckResponseMessage, isRpcResponseMessage, isRpcErrorMessage, isAsyncIterable, } from './types.js';
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Middleware Exports
|
|
25
|
+
// ============================================================================
|
|
26
|
+
export { composeMiddleware, requireAuth, requireRole, routeLogger, preloadData, } from './middleware.js';
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Re-export Browser-Safe Functionality
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Note: Server code might also need router, errors, etc. for SSR
|
|
31
|
+
export {
|
|
32
|
+
// Router
|
|
33
|
+
RouterProvider, useRouter, useParams, usePathname, useSearchParams, useRouteMatch, useIsPending, Link, NavLink, Outlet, Redirect,
|
|
34
|
+
// Error handling
|
|
35
|
+
ErrorBoundary, DefaultErrorComponent, RouteErrorContext, createRouteError, ZapError, useRouteError, useIsErrorState, useErrorState,
|
|
36
|
+
// CSRF
|
|
37
|
+
getCsrfToken, useCsrfToken, createCsrfFetch, CsrfTokenInput, CsrfForm, addCsrfToFormData, getCsrfHeaders,
|
|
38
|
+
// Utilities
|
|
39
|
+
router, errors, middleware, types, websockets, streaming, } from './index.js';
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// Default Export
|
|
42
|
+
// ============================================================================
|
|
43
|
+
export { default } from './index.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server exports for @zap-js/client
|
|
3
|
+
*
|
|
4
|
+
* Semantic alias for node.ts - provides all server-side functionality.
|
|
5
|
+
* Use this when you want to be explicit about server-side code.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Zap } from '@zap-js/client/server';
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export * from './node.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server exports for @zap-js/client
|
|
3
|
+
*
|
|
4
|
+
* Semantic alias for node.ts - provides all server-side functionality.
|
|
5
|
+
* Use this when you want to be explicit about server-side code.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Zap } from '@zap-js/client/server';
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export * from './node.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zap-js/client",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "High-performance fullstack React framework - Client package",
|
|
5
5
|
"homepage": "https://github.com/saint0x/zapjs",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,24 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./index.d.ts",
|
|
19
|
-
"
|
|
19
|
+
"node": "./dist/runtime/node.js",
|
|
20
|
+
"default": "./dist/runtime/browser.js"
|
|
21
|
+
},
|
|
22
|
+
"./node": {
|
|
23
|
+
"types": "./index.d.ts",
|
|
24
|
+
"default": "./dist/runtime/node.js"
|
|
25
|
+
},
|
|
26
|
+
"./server": {
|
|
27
|
+
"types": "./index.d.ts",
|
|
28
|
+
"default": "./dist/runtime/server.js"
|
|
29
|
+
},
|
|
30
|
+
"./browser": {
|
|
31
|
+
"types": "./index.d.ts",
|
|
32
|
+
"default": "./dist/runtime/browser.js"
|
|
33
|
+
},
|
|
34
|
+
"./client": {
|
|
35
|
+
"types": "./index.d.ts",
|
|
36
|
+
"default": "./dist/runtime/client.js"
|
|
20
37
|
},
|
|
21
38
|
"./router": "./dist/router/index.js"
|
|
22
39
|
},
|
|
@@ -24,8 +41,7 @@
|
|
|
24
41
|
"zap": "./dist/cli/index.js"
|
|
25
42
|
},
|
|
26
43
|
"files": [
|
|
27
|
-
"dist"
|
|
28
|
-
"bin"
|
|
44
|
+
"dist"
|
|
29
45
|
],
|
|
30
46
|
"scripts": {
|
|
31
47
|
"build": "tsc",
|
|
@@ -49,10 +65,16 @@
|
|
|
49
65
|
"ora": "^6.0.0",
|
|
50
66
|
"react": "^18.0.0",
|
|
51
67
|
"react-dom": "^18.0.0",
|
|
68
|
+
"strip-ansi": "^7.0.0",
|
|
52
69
|
"tsx": "^4.21.0",
|
|
53
70
|
"vite": "^5.0.0",
|
|
54
71
|
"ws": "^8.16.0"
|
|
55
72
|
},
|
|
73
|
+
"optionalDependencies": {
|
|
74
|
+
"@zap-js/darwin-arm64": "0.1.0",
|
|
75
|
+
"@zap-js/darwin-x64": "0.1.0",
|
|
76
|
+
"@zap-js/linux-x64": "0.1.0"
|
|
77
|
+
},
|
|
56
78
|
"peerDependencies": {
|
|
57
79
|
"react": "^18.0.0",
|
|
58
80
|
"react-dom": "^18.0.0"
|
package/bin/zap
DELETED
|
Binary file
|
package/bin/zap-codegen
DELETED
|
Binary file
|