wexts 4.0.0 → 4.1.5
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 +49 -49
- package/bin/wexts.cjs +2 -2
- package/package.json +153 -148
- package/templates/.dockerignore +43 -43
- package/templates/.env.example +17 -17
- package/templates/Dockerfile +60 -60
- package/templates/Procfile +1 -1
- package/templates/README.md +67 -67
- package/templates/api-sdk.ts +115 -115
- package/templates/docker-compose.yml +34 -34
- package/templates/nestjs-api/.env.example +3 -3
- package/templates/nestjs-api/README.md +87 -87
- package/templates/nestjs-api/nest-cli.json +6 -6
- package/templates/nestjs-api/package.json +40 -40
- package/templates/nestjs-api/prisma/migrations/20251123205437_init/migration.sql +24 -24
- package/templates/nestjs-api/prisma/migrations/migration_lock.toml +3 -3
- package/templates/nestjs-api/prisma/schema.prisma +29 -29
- package/templates/nestjs-api/src/app.module.ts +17 -17
- package/templates/nestjs-api/src/auth/auth.controller.ts +27 -27
- package/templates/nestjs-api/src/auth/auth.module.ts +37 -37
- package/templates/nestjs-api/src/auth/auth.service.ts +86 -86
- package/templates/nestjs-api/src/auth/dto/auth.dto.ts +22 -22
- package/templates/nestjs-api/src/auth/guards/jwt-auth.guard.ts +5 -5
- package/templates/nestjs-api/src/auth/strategies/jwt.strategy.ts +27 -27
- package/templates/nestjs-api/src/main.ts +32 -32
- package/templates/nestjs-api/src/prisma/prisma.module.ts +9 -9
- package/templates/nestjs-api/src/prisma/prisma.service.ts +14 -14
- package/templates/nestjs-api/src/todos/dto/todo.dto.ts +24 -24
- package/templates/nestjs-api/src/todos/todos.controller.ts +39 -39
- package/templates/nestjs-api/src/todos/todos.module.ts +11 -11
- package/templates/nestjs-api/src/todos/todos.service.ts +53 -53
- package/templates/nestjs-api/src/users/users.controller.ts +14 -14
- package/templates/nestjs-api/src/users/users.module.ts +12 -12
- package/templates/nestjs-api/src/users/users.service.ts +19 -19
- package/templates/nestjs-api/tsconfig.json +39 -39
- package/templates/nextjs-web/README.md +76 -76
- package/templates/nextjs-web/app/actions/auth.ts +108 -108
- package/templates/nextjs-web/app/dashboard/error.tsx +39 -39
- package/templates/nextjs-web/app/dashboard/loading.tsx +14 -14
- package/templates/nextjs-web/app/dashboard/page.tsx +5 -5
- package/templates/nextjs-web/app/globals.css +93 -93
- package/templates/nextjs-web/app/layout.tsx +29 -29
- package/templates/nextjs-web/app/login/page.tsx +5 -5
- package/templates/nextjs-web/app/page.tsx +28 -28
- package/templates/nextjs-web/app/register/page.tsx +5 -5
- package/templates/nextjs-web/components/ui/button.tsx +56 -56
- package/templates/nextjs-web/components/ui/card.tsx +79 -79
- package/templates/nextjs-web/components/ui/input.tsx +25 -25
- package/templates/nextjs-web/components/ui/label.tsx +24 -24
- package/templates/nextjs-web/features/auth/LoginForm.tsx +140 -140
- package/templates/nextjs-web/features/auth/RegisterForm.tsx +159 -159
- package/templates/nextjs-web/features/auth/api.ts +35 -35
- package/templates/nextjs-web/features/auth/index.ts +3 -3
- package/templates/nextjs-web/features/dashboard/DashboardView.tsx +204 -204
- package/templates/nextjs-web/features/dashboard/api.ts +9 -9
- package/templates/nextjs-web/features/dashboard/components.tsx +74 -74
- package/templates/nextjs-web/features/dashboard/index.ts +3 -3
- package/templates/nextjs-web/hooks/index.ts +4 -4
- package/templates/nextjs-web/lib/api-client.ts +89 -89
- package/templates/nextjs-web/lib/api.ts +115 -115
- package/templates/nextjs-web/lib/axios-global-config.ts +17 -17
- package/templates/nextjs-web/lib/utils.ts +6 -6
- package/templates/nextjs-web/lib/wexts-client.ts +4 -4
- package/templates/nextjs-web/next-env.d.ts +6 -6
- package/templates/nextjs-web/next.config.ts +20 -20
- package/templates/nextjs-web/package.json +37 -37
- package/templates/nextjs-web/postcss.config.js +6 -6
- package/templates/nextjs-web/tailwind.config.ts +69 -69
- package/templates/nextjs-web/tsconfig.json +41 -41
- package/templates/nixpacks.toml +11 -11
- package/templates/root-package.json +31 -31
- package/templates/server.ts +66 -66
- package/templates/tsconfig.json +30 -30
- package/dist/chunk-2KAQYLVN.js +0 -1
- package/dist/chunk-2KAQYLVN.js.map +0 -1
- package/dist/chunk-2LJVUMXW.js +0 -228
- package/dist/chunk-2LJVUMXW.js.map +0 -1
- package/dist/chunk-7QKLIVRF.js +0 -94
- package/dist/chunk-7QKLIVRF.js.map +0 -1
- package/dist/chunk-7WULUGLH.mjs +0 -22
- package/dist/chunk-7WULUGLH.mjs.map +0 -1
- package/dist/chunk-BG56B4DE.js +0 -106
- package/dist/chunk-BG56B4DE.js.map +0 -1
- package/dist/chunk-CLM5PNSG.mjs +0 -496
- package/dist/chunk-CLM5PNSG.mjs.map +0 -1
- package/dist/chunk-DNLGCKTT.js +0 -31
- package/dist/chunk-DNLGCKTT.js.map +0 -1
- package/dist/chunk-JHOVXH3X.mjs +0 -65
- package/dist/chunk-JHOVXH3X.mjs.map +0 -1
- package/dist/chunk-MXINIFPC.js +0 -105
- package/dist/chunk-MXINIFPC.js.map +0 -1
- package/dist/chunk-SE32ZPOZ.js +0 -496
- package/dist/chunk-SE32ZPOZ.js.map +0 -1
- package/dist/chunk-UAL54DVV.mjs +0 -106
- package/dist/chunk-UAL54DVV.mjs.map +0 -1
- package/dist/chunk-WCKSKU3C.js +0 -65
- package/dist/chunk-WCKSKU3C.js.map +0 -1
- package/dist/chunk-WU6FW77M.mjs +0 -105
- package/dist/chunk-WU6FW77M.mjs.map +0 -1
- package/dist/chunk-XE4OXN2W.js +0 -12
- package/dist/chunk-XE4OXN2W.js.map +0 -1
- package/dist/chunk-YBM3IJEA.mjs +0 -94
- package/dist/chunk-YBM3IJEA.mjs.map +0 -1
- package/dist/chunk-YN6WIWNQ.mjs +0 -228
- package/dist/chunk-YN6WIWNQ.mjs.map +0 -1
- package/dist/chunk-YSLEF5C5.mjs +0 -1
- package/dist/chunk-YSLEF5C5.mjs.map +0 -1
- package/dist/chunk-ZX7QIN24.mjs +0 -31
- package/dist/chunk-ZX7QIN24.mjs.map +0 -1
- package/dist/cli/index.d.mts +0 -11
- package/dist/cli/index.d.ts +0 -11
- package/dist/cli/index.js +0 -332
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/index.mjs +0 -334
- package/dist/cli/index.mjs.map +0 -1
- package/dist/client/index.d.mts +0 -21
- package/dist/client/index.d.ts +0 -21
- package/dist/client/index.js +0 -12
- package/dist/client/index.js.map +0 -1
- package/dist/client/index.mjs +0 -12
- package/dist/client/index.mjs.map +0 -1
- package/dist/codegen/index.d.mts +0 -2
- package/dist/codegen/index.d.ts +0 -2
- package/dist/codegen/index.js +0 -15
- package/dist/codegen/index.js.map +0 -1
- package/dist/codegen/index.mjs +0 -15
- package/dist/codegen/index.mjs.map +0 -1
- package/dist/decorators-BT1FFqN0.d.mts +0 -29
- package/dist/decorators-DvS58PqC.d.ts +0 -29
- package/dist/dev-server/index.d.mts +0 -1
- package/dist/dev-server/index.d.ts +0 -1
- package/dist/dev-server/index.js +0 -13
- package/dist/dev-server/index.js.map +0 -1
- package/dist/dev-server/index.mjs +0 -13
- package/dist/dev-server/index.mjs.map +0 -1
- package/dist/index-7QeQEf37.d.ts +0 -92
- package/dist/index-7RvU-jGE.d.mts +0 -66
- package/dist/index-7RvU-jGE.d.ts +0 -66
- package/dist/index-8nzxy0NN.d.mts +0 -92
- package/dist/index-Co5ZsLqq.d.ts +0 -58
- package/dist/index-D94W1__r.d.mts +0 -58
- package/dist/index-DQmyVp6F.d.mts +0 -27
- package/dist/index-KL_1BrQb.d.ts +0 -27
- package/dist/index.d.mts +0 -258
- package/dist/index.d.ts +0 -258
- package/dist/index.js +0 -410
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -410
- package/dist/index.mjs.map +0 -1
- package/dist/nest/index.d.mts +0 -3
- package/dist/nest/index.d.ts +0 -3
- package/dist/nest/index.js +0 -38
- package/dist/nest/index.js.map +0 -1
- package/dist/nest/index.mjs +0 -38
- package/dist/nest/index.mjs.map +0 -1
- package/dist/next/index.d.mts +0 -66
- package/dist/next/index.d.ts +0 -66
- package/dist/next/index.js +0 -226
- package/dist/next/index.js.map +0 -1
- package/dist/next/index.mjs +0 -188
- package/dist/next/index.mjs.map +0 -1
- package/dist/rpc/index.d.mts +0 -2
- package/dist/rpc/index.d.ts +0 -2
- package/dist/rpc/index.js +0 -23
- package/dist/rpc/index.js.map +0 -1
- package/dist/rpc/index.mjs +0 -23
- package/dist/rpc/index.mjs.map +0 -1
- package/dist/runtime/index.d.mts +0 -55
- package/dist/runtime/index.d.ts +0 -55
- package/dist/runtime/index.js +0 -213
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/index.mjs +0 -213
- package/dist/runtime/index.mjs.map +0 -1
- package/dist/types/index.d.mts +0 -12
- package/dist/types/index.d.ts +0 -12
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -3
- package/dist/types/index.mjs.map +0 -1
- package/dist/types-7d_fC-C3.d.mts +0 -32
- package/dist/types-7d_fC-C3.d.ts +0 -32
- package/dist/vercel-builder/index.d.mts +0 -58
- package/dist/vercel-builder/index.d.ts +0 -58
- package/dist/vercel-builder/index.js +0 -330
- package/dist/vercel-builder/index.js.map +0 -1
- package/dist/vercel-builder/index.mjs +0 -330
- package/dist/vercel-builder/index.mjs.map +0 -1
- package/templates/nestjs-api/package-lock.json +0 -5623
- package/templates/nextjs-web/package-lock.json +0 -3254
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/logger.ts"],"sourcesContent":["export enum LogLevel {\n DEBUG = 0,\n INFO = 1,\n WARN = 2,\n ERROR = 3,\n}\n\nexport interface LoggerOptions {\n level?: LogLevel;\n prefix?: string;\n timestamp?: boolean;\n}\n\nexport class Logger {\n private level: LogLevel;\n private prefix: string;\n private timestamp: boolean;\n\n constructor(options: LoggerOptions = {}) {\n this.level = options.level ?? LogLevel.INFO;\n this.prefix = options.prefix ?? '[Fusion]';\n this.timestamp = options.timestamp ?? true;\n }\n\n private formatMessage(level: string, ...args: any[]): string {\n const timestamp = this.timestamp ? `[${new Date().toISOString()}]` : '';\n return `${timestamp} ${this.prefix} ${level}: ${args.join(' ')}`;\n }\n\n debug(...args: any[]): void {\n if (this.level <= LogLevel.DEBUG) {\n console.log(this.formatMessage('DEBUG', ...args));\n }\n }\n\n info(...args: any[]): void {\n if (this.level <= LogLevel.INFO) {\n console.log(this.formatMessage('INFO', ...args));\n }\n }\n\n warn(...args: any[]): void {\n if (this.level <= LogLevel.WARN) {\n console.warn(this.formatMessage('WARN', ...args));\n }\n }\n\n error(...args: any[]): void {\n if (this.level <= LogLevel.ERROR) {\n console.error(this.formatMessage('ERROR', ...args));\n }\n }\n\n success(...args: any[]): void {\n console.log(this.formatMessage('✓', ...args));\n }\n}\n\n// Export singleton instance\nexport const logger = new Logger();\n\n// Export factory\nexport function createLogger(options: LoggerOptions): Logger {\n return new Logger(options);\n}\n"],"mappings":";;;;;AAAO,IAAKA,WAAAA,0BAAAA,WAAAA;;;;;SAAAA;;AAaL,IAAMC,SAAN,MAAMA;EAbb,OAaaA;;;EACDC;EACAC;EACAC;EAER,YAAYC,UAAyB,CAAC,GAAG;AACrC,SAAKH,QAAQG,QAAQH,SAAK;AAC1B,SAAKC,SAASE,QAAQF,UAAU;AAChC,SAAKC,YAAYC,QAAQD,aAAa;EAC1C;EAEQE,cAAcJ,UAAkBK,MAAqB;AACzD,UAAMH,YAAY,KAAKA,YAAY,KAAI,oBAAII,KAAAA,GAAOC,YAAW,CAAA,MAAQ;AACrE,WAAO,GAAGL,SAAAA,IAAa,KAAKD,MAAM,IAAID,KAAAA,KAAUK,KAAKG,KAAK,GAAA,CAAA;EAC9D;EAEAC,SAASJ,MAAmB;AACxB,QAAI,KAAKL,SAAK,GAAoB;AAC9BU,cAAQC,IAAI,KAAKP,cAAc,SAAA,GAAYC,IAAAA,CAAAA;IAC/C;EACJ;EAEAO,QAAQP,MAAmB;AACvB,QAAI,KAAKL,SAAK,GAAmB;AAC7BU,cAAQC,IAAI,KAAKP,cAAc,QAAA,GAAWC,IAAAA,CAAAA;IAC9C;EACJ;EAEAQ,QAAQR,MAAmB;AACvB,QAAI,KAAKL,SAAK,GAAmB;AAC7BU,cAAQG,KAAK,KAAKT,cAAc,QAAA,GAAWC,IAAAA,CAAAA;IAC/C;EACJ;EAEAS,SAAST,MAAmB;AACxB,QAAI,KAAKL,SAAK,GAAoB;AAC9BU,cAAQI,MAAM,KAAKV,cAAc,SAAA,GAAYC,IAAAA,CAAAA;IACjD;EACJ;EAEAU,WAAWV,MAAmB;AAC1BK,YAAQC,IAAI,KAAKP,cAAc,UAAA,GAAQC,IAAAA,CAAAA;EAC3C;AACJ;AAGO,IAAMW,SAAS,IAAIjB,OAAAA;AAGnB,SAASkB,aAAad,SAAsB;AAC/C,SAAO,IAAIJ,OAAOI,OAAAA;AACtB;AAFgBc;","names":["LogLevel","Logger","level","prefix","timestamp","options","formatMessage","args","Date","toISOString","join","debug","console","log","info","warn","error","success","logger","createLogger"]}
|
package/dist/chunk-MXINIFPC.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunkXE4OXN2Wjs = require('./chunk-XE4OXN2W.js');
|
|
4
|
-
|
|
5
|
-
// src/client/fetcher.ts
|
|
6
|
-
var FusionFetcher = class {
|
|
7
|
-
static {
|
|
8
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, this, "FusionFetcher");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
constructor(baseUrl = "/api") {
|
|
12
|
-
this.baseUrl = baseUrl;
|
|
13
|
-
}
|
|
14
|
-
async request(method, path, body) {
|
|
15
|
-
const headers = {
|
|
16
|
-
"Content-Type": "application/json"
|
|
17
|
-
};
|
|
18
|
-
if (typeof window !== "undefined") {
|
|
19
|
-
const token = localStorage.getItem("fusion_token");
|
|
20
|
-
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
21
|
-
}
|
|
22
|
-
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
23
|
-
method,
|
|
24
|
-
headers,
|
|
25
|
-
body: body ? JSON.stringify(body) : void 0
|
|
26
|
-
});
|
|
27
|
-
if (!response.ok) {
|
|
28
|
-
throw new Error(`Fusion API Error: ${response.status} ${response.statusText}`);
|
|
29
|
-
}
|
|
30
|
-
if (response.status === 204) {
|
|
31
|
-
return void 0;
|
|
32
|
-
}
|
|
33
|
-
return response.json();
|
|
34
|
-
}
|
|
35
|
-
get(path) {
|
|
36
|
-
return this.request("GET", path);
|
|
37
|
-
}
|
|
38
|
-
post(path, body) {
|
|
39
|
-
return this.request("POST", path, body);
|
|
40
|
-
}
|
|
41
|
-
put(path, body) {
|
|
42
|
-
return this.request("PUT", path, body);
|
|
43
|
-
}
|
|
44
|
-
delete(path) {
|
|
45
|
-
return this.request("DELETE", path);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var apiFetcher = new FusionFetcher();
|
|
49
|
-
function createWextsRpcClient(manifest, options = {}) {
|
|
50
|
-
const services = new Set((_nullishCoalesce(_optionalChain([manifest, 'optionalAccess', _ => _.services]), () => ( []))).map((service) => service.name));
|
|
51
|
-
const methodMap = /* @__PURE__ */ new Map();
|
|
52
|
-
for (const service of _nullishCoalesce(_optionalChain([manifest, 'optionalAccess', _2 => _2.services]), () => ( []))) {
|
|
53
|
-
methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));
|
|
54
|
-
}
|
|
55
|
-
const createServiceProxy = /* @__PURE__ */ _chunkXE4OXN2Wjs.__name.call(void 0, (serviceName) => new Proxy({}, {
|
|
56
|
-
get(_target, methodName) {
|
|
57
|
-
if (typeof methodName !== "string") return void 0;
|
|
58
|
-
if (methodName === "then") return void 0;
|
|
59
|
-
const knownMethods = methodMap.get(serviceName);
|
|
60
|
-
if (knownMethods && !knownMethods.has(methodName)) {
|
|
61
|
-
throw new Error(`Wexts RPC method not found: ${serviceName}.${methodName}`);
|
|
62
|
-
}
|
|
63
|
-
return (...args) => invokeRpc(serviceName, methodName, args, options);
|
|
64
|
-
}
|
|
65
|
-
}), "createServiceProxy");
|
|
66
|
-
return new Proxy({}, {
|
|
67
|
-
get(_target, serviceName) {
|
|
68
|
-
if (typeof serviceName !== "string") return void 0;
|
|
69
|
-
if (serviceName === "then") return void 0;
|
|
70
|
-
if (services.size > 0 && !services.has(serviceName)) {
|
|
71
|
-
throw new Error(`Wexts RPC service not found: ${serviceName}`);
|
|
72
|
-
}
|
|
73
|
-
return createServiceProxy(serviceName);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, createWextsRpcClient, "createWextsRpcClient");
|
|
78
|
-
async function invokeRpc(serviceName, methodName, args, options) {
|
|
79
|
-
const fetchImpl = _nullishCoalesce(options.fetch, () => ( fetch));
|
|
80
|
-
const baseUrl = _nullishCoalesce(options.baseUrl, () => ( "/rpc"));
|
|
81
|
-
const headers = {
|
|
82
|
-
"Content-Type": "application/json",
|
|
83
|
-
...await _asyncNullishCoalesce(await _optionalChain([options, 'access', _3 => _3.getHeaders, 'optionalCall', _4 => _4()]), async () => ( {}))
|
|
84
|
-
};
|
|
85
|
-
const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {
|
|
86
|
-
method: "POST",
|
|
87
|
-
headers,
|
|
88
|
-
body: JSON.stringify({
|
|
89
|
-
args
|
|
90
|
-
})
|
|
91
|
-
});
|
|
92
|
-
if (!response.ok) {
|
|
93
|
-
throw new Error(`Wexts RPC Error: ${response.status} ${response.statusText}`);
|
|
94
|
-
}
|
|
95
|
-
const payload = await response.json();
|
|
96
|
-
return payload.data;
|
|
97
|
-
}
|
|
98
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, invokeRpc, "invokeRpc");
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
exports.FusionFetcher = FusionFetcher; exports.apiFetcher = apiFetcher; exports.createWextsRpcClient = createWextsRpcClient;
|
|
105
|
-
//# sourceMappingURL=chunk-MXINIFPC.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Volumes/Projects/wexts/packages/dist/chunk-MXINIFPC.js","../src/client/fetcher.ts"],"names":["FusionFetcher","baseUrl","request","method","path","body","headers","window","token","localStorage","getItem","undefined","service","Map","serviceName","methodName","createWextsRpcClient","options","fetch","encodeURIComponent","args","response","data","invokeRpc"],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACFO,IAAMA,cAAAA,EAAN,MAAMA;ADIb,ECJA,OAAaA;ADKb,IAAI,qCAAM,IAAK,EAAE,eAAe,CAAC;AACjC,EAAE;AACF,ECNYC;ADOZ,ECLI,WAAA,CAAYA,QAAAA,EAAkB,MAAA,EAAQ;AAClC,IAAA,IAAA,CAAKA,QAAAA,EAAUA,OAAAA;ADMvB,ECLI;ADMJ,ECJI,MAAcC,OAAAA,CAAWC,MAAAA,EAAgBC,IAAAA,EAAcC,IAAAA,EAAwB;AAC3E,IAAA,MAAMC,QAAAA,EAAkC;ADKhD,MCJY,cAAA,EAAgB;ADK5B,ICJQ,CAAA;AAGA,IAAA,GAAA,CAAI,OAAOC,OAAAA,IAAW,WAAA,EAAa;AAC/B,MAAA,MAAMC,MAAAA,EAAQC,YAAAA,CAAaC,OAAAA,CAAQ,cAAA,CAAA;AACnC,MAAA,GAAA,CAAIF,KAAAA,EAAOF,OAAAA,CAAQ,eAAA,EAAA,EAAmB,CAAA,OAAA,EAAUE,KAAAA,CAAAA,CAAAA;AACpD,IAAA;AAEmD,IAAA;AAC/CL,MAAAA;AACAG,MAAAA;AACoCK,MAAAA;AACxC,IAAA;AAEkB,IAAA;AACsC,MAAA;AACxD,IAAA;AAE6B,IAAA;AAClBA,MAAAA;AACX,IAAA;AAEoB,IAAA;AACxB,EAAA;AAEqB,EAAA;AAAgCP,IAAAA;AAAO,EAAA;AAC3B,EAAA;AAAuCC,IAAAA;AAAO,EAAA;AAC/C,EAAA;AAAsCA,IAAAA;AAAO,EAAA;AACrD,EAAA;AAAmCD,IAAAA;AAAO,EAAA;AACtE;AAE8BJ;AAYS;AAEsBY,EAAAA;AACnCC,EAAAA;AAE0B,EAAA;AACY,IAAA;AAC5D,EAAA;AAE4BC,EAAAA;AACD,IAAA;AACwBH,MAAAA;AACTA,MAAAA;AAECG,MAAAA;AACgB,MAAA;AACAA,QAAAA;AACnD,MAAA;AAEsDC,MAAAA;AAC1D,IAAA;AAXuB,EAAA;AAcN,EAAA;AACO,IAAA;AACwBJ,MAAAA;AACTA,MAAAA;AACkB,MAAA;AACDG,QAAAA;AACpD,MAAA;AAE0BA,MAAAA;AAC9B,IAAA;AACJ,EAAA;AACJ;AApCgBE;AA0CZC;AAEmCC,EAAAA;AACA,EAAA;AACnB,EAAA;AACI,IAAA;AACqB,IAAA;AACzC,EAAA;AAC+CC,EAAAA;AACnC,IAAA;AACRb,IAAAA;AACqB,IAAA;AAAEc,MAAAA;AAAK,IAAA;AAChC,EAAA;AAEkB,EAAA;AACyCC,IAAAA;AAC3D,EAAA;AAEmC,EAAA;AACpBC,EAAAA;AACnB;AAxBeC;ADO6C;AACA;AACA;AACA;AACA;AACA","file":"/Volumes/Projects/wexts/packages/dist/chunk-MXINIFPC.js","sourcesContent":[null,"import type { RpcManifest, RpcInvocationResponse } from '../rpc/types';\n\nexport class FusionFetcher {\n private baseUrl: string;\n\n constructor(baseUrl: string = '/api') {\n this.baseUrl = baseUrl;\n }\n\n private async request<T>(method: string, path: string, body?: any): Promise<T> {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Automatically attach Fusion Token if present\n if (typeof window !== 'undefined') {\n const token = localStorage.getItem('fusion_token');\n if (token) headers['Authorization'] = `Bearer ${token}`;\n }\n\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new Error(`Fusion API Error: ${response.status} ${response.statusText}`);\n }\n\n if (response.status === 204) {\n return undefined as T;\n }\n\n return response.json();\n }\n\n get<T>(path: string) { return this.request<T>('GET', path); }\n post<T>(path: string, body: any) { return this.request<T>('POST', path, body); }\n put<T>(path: string, body: any) { return this.request<T>('PUT', path, body); }\n delete<T>(path: string) { return this.request<T>('DELETE', path); }\n}\n\nexport const apiFetcher = new FusionFetcher();\n\nexport interface WextsRpcClientOptions {\n baseUrl?: string;\n fetch?: typeof fetch;\n getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;\n}\n\nexport type WextsRpcClient = Record<string, Record<string, (...args: unknown[]) => Promise<unknown>>>;\n\nexport function createWextsRpcClient(\n manifest: Pick<RpcManifest, 'services'> | undefined,\n options: WextsRpcClientOptions = {}\n): WextsRpcClient {\n const services = new Set((manifest?.services ?? []).map((service) => service.name));\n const methodMap = new Map<string, Set<string>>();\n\n for (const service of manifest?.services ?? []) {\n methodMap.set(service.name, new Set(service.methods.map((method) => method.name)));\n }\n\n const createServiceProxy = (serviceName: string) => new Proxy({}, {\n get(_target, methodName) {\n if (typeof methodName !== 'string') return undefined;\n if (methodName === 'then') return undefined;\n\n const knownMethods = methodMap.get(serviceName);\n if (knownMethods && !knownMethods.has(methodName)) {\n throw new Error(`Wexts RPC method not found: ${serviceName}.${methodName}`);\n }\n\n return (...args: unknown[]) => invokeRpc(serviceName, methodName, args, options);\n },\n }) as Record<string, (...args: unknown[]) => Promise<unknown>>;\n\n return new Proxy({}, {\n get(_target, serviceName) {\n if (typeof serviceName !== 'string') return undefined;\n if (serviceName === 'then') return undefined;\n if (services.size > 0 && !services.has(serviceName)) {\n throw new Error(`Wexts RPC service not found: ${serviceName}`);\n }\n\n return createServiceProxy(serviceName);\n },\n }) as WextsRpcClient;\n}\n\nasync function invokeRpc(\n serviceName: string,\n methodName: string,\n args: unknown[],\n options: WextsRpcClientOptions\n): Promise<unknown> {\n const fetchImpl = options.fetch ?? fetch;\n const baseUrl = options.baseUrl ?? '/rpc';\n const headers = {\n 'Content-Type': 'application/json',\n ...(await options.getHeaders?.() ?? {}),\n };\n const response = await fetchImpl(`${baseUrl}/${encodeURIComponent(serviceName)}/${encodeURIComponent(methodName)}`, {\n method: 'POST',\n headers,\n body: JSON.stringify({ args }),\n });\n\n if (!response.ok) {\n throw new Error(`Wexts RPC Error: ${response.status} ${response.statusText}`);\n }\n\n const payload = await response.json() as RpcInvocationResponse;\n return payload.data;\n}\n"]}
|
package/dist/chunk-SE32ZPOZ.js
DELETED
|
@@ -1,496 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
-
|
|
3
|
-
var _chunkWCKSKU3Cjs = require('./chunk-WCKSKU3C.js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkXE4OXN2Wjs = require('./chunk-XE4OXN2W.js');
|
|
8
|
-
|
|
9
|
-
// src/codegen/index.ts
|
|
10
|
-
var codegen_exports = {};
|
|
11
|
-
_chunkXE4OXN2Wjs.__export.call(void 0, codegen_exports, {
|
|
12
|
-
ClientGenerator: () => ClientGenerator,
|
|
13
|
-
CodegenWatcher: () => CodegenWatcher,
|
|
14
|
-
NestJSParser: () => NestJSParser,
|
|
15
|
-
generateRpcClient: () => generateRpcClient
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// src/codegen/parser.ts
|
|
19
|
-
var _path = require('path'); var path = _interopRequireWildcard(_path); var path2 = _interopRequireWildcard(_path); var path3 = _interopRequireWildcard(_path);
|
|
20
|
-
var _typescript = require('typescript'); var ts = _interopRequireWildcard(_typescript);
|
|
21
|
-
var RPC_SERVICE_DECORATORS = /* @__PURE__ */ new Set([
|
|
22
|
-
"RpcService",
|
|
23
|
-
"WextsRpcService"
|
|
24
|
-
]);
|
|
25
|
-
var RPC_METHOD_DECORATORS = /* @__PURE__ */ new Set([
|
|
26
|
-
"RpcMethod",
|
|
27
|
-
"WextsRpc"
|
|
28
|
-
]);
|
|
29
|
-
var REQUIRE_AUTH_DECORATORS = /* @__PURE__ */ new Set([
|
|
30
|
-
"RequireAuth"
|
|
31
|
-
]);
|
|
32
|
-
var NestJSParser = class {
|
|
33
|
-
static {
|
|
34
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, this, "NestJSParser");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
constructor(projectPath) {
|
|
39
|
-
this.projectPath = projectPath;
|
|
40
|
-
const configPath = ts.findConfigFile(projectPath, ts.sys.fileExists, "tsconfig.json");
|
|
41
|
-
if (!configPath) {
|
|
42
|
-
throw new Error("tsconfig.json not found");
|
|
43
|
-
}
|
|
44
|
-
const config = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
45
|
-
const parsedConfig = ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(configPath));
|
|
46
|
-
this.program = ts.createProgram(parsedConfig.fileNames, parsedConfig.options);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Find all controllers with @FusionController decorator
|
|
50
|
-
*/
|
|
51
|
-
findFusionControllers() {
|
|
52
|
-
const controllers = [];
|
|
53
|
-
const sourceFiles = this.program.getSourceFiles();
|
|
54
|
-
for (const sourceFile of sourceFiles) {
|
|
55
|
-
if (sourceFile.fileName.includes("node_modules")) continue;
|
|
56
|
-
if (!sourceFile.fileName.includes(".controller.ts")) continue;
|
|
57
|
-
const fileControllers = this.parseSourceFile(sourceFile);
|
|
58
|
-
controllers.push(...fileControllers);
|
|
59
|
-
}
|
|
60
|
-
return controllers;
|
|
61
|
-
}
|
|
62
|
-
findRpcManifest() {
|
|
63
|
-
const services = [];
|
|
64
|
-
for (const sourceFile of this.program.getSourceFiles()) {
|
|
65
|
-
if (sourceFile.fileName.includes("node_modules")) continue;
|
|
66
|
-
if (!sourceFile.fileName.endsWith(".ts")) continue;
|
|
67
|
-
if (sourceFile.fileName.endsWith(".d.ts")) continue;
|
|
68
|
-
services.push(...this.parseRpcServices(sourceFile));
|
|
69
|
-
}
|
|
70
|
-
services.sort((a, b) => a.name.localeCompare(b.name));
|
|
71
|
-
for (const service of services) {
|
|
72
|
-
service.methods.sort((a, b) => a.name.localeCompare(b.name));
|
|
73
|
-
}
|
|
74
|
-
if (services.length === 0) {
|
|
75
|
-
return {
|
|
76
|
-
schemaVersion: 1,
|
|
77
|
-
services
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
schemaVersion: 1,
|
|
82
|
-
services
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
parseSourceFile(sourceFile) {
|
|
86
|
-
const controllers = [];
|
|
87
|
-
ts.forEachChild(sourceFile, (node) => {
|
|
88
|
-
if (ts.isClassDeclaration(node) && node.name) {
|
|
89
|
-
const controllerInfo = this.parseController(node);
|
|
90
|
-
if (controllerInfo) {
|
|
91
|
-
controllers.push(controllerInfo);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
return controllers;
|
|
96
|
-
}
|
|
97
|
-
parseController(classNode) {
|
|
98
|
-
const decorators = ts.getDecorators(classNode);
|
|
99
|
-
if (!decorators) return null;
|
|
100
|
-
let controllerPrefix = "";
|
|
101
|
-
let isFusionController = false;
|
|
102
|
-
for (const decorator of decorators) {
|
|
103
|
-
const expr = decorator.expression;
|
|
104
|
-
if (ts.isCallExpression(expr) && ts.isIdentifier(expr.expression)) {
|
|
105
|
-
const decoratorName = expr.expression.text;
|
|
106
|
-
if (decoratorName === "FusionController") {
|
|
107
|
-
isFusionController = true;
|
|
108
|
-
if (expr.arguments.length > 0) {
|
|
109
|
-
const arg = expr.arguments[0];
|
|
110
|
-
if (ts.isStringLiteral(arg)) {
|
|
111
|
-
controllerPrefix = arg.text;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (!isFusionController) return null;
|
|
118
|
-
const routes = this.parseRoutes(classNode);
|
|
119
|
-
const className = _optionalChain([classNode, 'access', _ => _.name, 'optionalAccess', _2 => _2.text]) || "Unknown";
|
|
120
|
-
return {
|
|
121
|
-
name: className,
|
|
122
|
-
prefix: controllerPrefix,
|
|
123
|
-
routes: routes.map((r) => ({
|
|
124
|
-
...r,
|
|
125
|
-
controllerName: className
|
|
126
|
-
}))
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
parseRoutes(classNode) {
|
|
130
|
-
const routes = [];
|
|
131
|
-
classNode.members.forEach((member) => {
|
|
132
|
-
if (ts.isMethodDeclaration(member)) {
|
|
133
|
-
const decorators = ts.getDecorators(member);
|
|
134
|
-
if (!decorators) return;
|
|
135
|
-
for (const decorator of decorators) {
|
|
136
|
-
const expr = decorator.expression;
|
|
137
|
-
if (ts.isCallExpression(expr) && ts.isIdentifier(expr.expression)) {
|
|
138
|
-
const decoratorName = expr.expression.text;
|
|
139
|
-
let method = null;
|
|
140
|
-
let routePath = "";
|
|
141
|
-
if (decoratorName === "FusionGet") method = "GET";
|
|
142
|
-
else if (decoratorName === "FusionPost") method = "POST";
|
|
143
|
-
else if (decoratorName === "FusionPut") method = "PUT";
|
|
144
|
-
else if (decoratorName === "FusionDelete") method = "DELETE";
|
|
145
|
-
if (method) {
|
|
146
|
-
if (expr.arguments.length > 0) {
|
|
147
|
-
const arg = expr.arguments[0];
|
|
148
|
-
if (ts.isStringLiteral(arg)) {
|
|
149
|
-
routePath = arg.text;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const handlerName = member.name.text;
|
|
153
|
-
routes.push({
|
|
154
|
-
method,
|
|
155
|
-
path: routePath,
|
|
156
|
-
handler: handlerName,
|
|
157
|
-
controllerName: ""
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
return routes;
|
|
165
|
-
}
|
|
166
|
-
parseRpcServices(sourceFile) {
|
|
167
|
-
const services = [];
|
|
168
|
-
const rootDir = path.resolve(this.projectPath);
|
|
169
|
-
ts.forEachChild(sourceFile, (node) => {
|
|
170
|
-
if (!ts.isClassDeclaration(node) || !node.name) return;
|
|
171
|
-
const serviceDecorator = this.findDecorator(node, RPC_SERVICE_DECORATORS);
|
|
172
|
-
if (!serviceDecorator) return;
|
|
173
|
-
const className = node.name.text;
|
|
174
|
-
const serviceOptions = this.readDecoratorOptions(serviceDecorator);
|
|
175
|
-
const classRequiresAuth = serviceOptions.requireAuth || this.hasDecorator(node, REQUIRE_AUTH_DECORATORS);
|
|
176
|
-
const serviceName = serviceOptions.name || toStableServiceName(className);
|
|
177
|
-
const methods = this.parseRpcMethods(node, classRequiresAuth, sourceFile);
|
|
178
|
-
if (methods.length === 0) return;
|
|
179
|
-
services.push({
|
|
180
|
-
name: serviceName,
|
|
181
|
-
className,
|
|
182
|
-
importPath: toPosixPath(path.relative(rootDir, sourceFile.fileName).replace(/\.ts$/, "")),
|
|
183
|
-
requireAuth: classRequiresAuth,
|
|
184
|
-
methods
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
return services;
|
|
188
|
-
}
|
|
189
|
-
parseRpcMethods(classNode, classRequiresAuth, sourceFile) {
|
|
190
|
-
const methods = [];
|
|
191
|
-
for (const member of classNode.members) {
|
|
192
|
-
if (!ts.isMethodDeclaration(member)) continue;
|
|
193
|
-
if (!ts.isIdentifier(member.name)) continue;
|
|
194
|
-
const methodDecorator = this.findDecorator(member, RPC_METHOD_DECORATORS);
|
|
195
|
-
if (!methodDecorator) continue;
|
|
196
|
-
const handlerName = member.name.text;
|
|
197
|
-
const methodOptions = this.readDecoratorOptions(methodDecorator);
|
|
198
|
-
const requireAuth = classRequiresAuth || methodOptions.requireAuth || this.hasDecorator(member, REQUIRE_AUTH_DECORATORS);
|
|
199
|
-
methods.push({
|
|
200
|
-
name: methodOptions.name || handlerName,
|
|
201
|
-
handlerName,
|
|
202
|
-
requireAuth,
|
|
203
|
-
parameters: member.parameters.map((parameter) => this.parseParameter(parameter, sourceFile)),
|
|
204
|
-
returnType: member.type ? getNodeText(member.type, sourceFile) : "unknown"
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
return methods;
|
|
208
|
-
}
|
|
209
|
-
parseParameter(parameter, sourceFile) {
|
|
210
|
-
return {
|
|
211
|
-
name: ts.isIdentifier(parameter.name) ? parameter.name.text : parameter.name.getText(),
|
|
212
|
-
type: parameter.type ? getNodeText(parameter.type, sourceFile) : "unknown",
|
|
213
|
-
optional: Boolean(parameter.questionToken || parameter.initializer)
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
findDecorator(node, names) {
|
|
217
|
-
const decorators = ts.getDecorators(node);
|
|
218
|
-
if (!decorators) return void 0;
|
|
219
|
-
return decorators.find((decorator) => {
|
|
220
|
-
const name = getDecoratorName(decorator);
|
|
221
|
-
return Boolean(name && names.has(name));
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
hasDecorator(node, names) {
|
|
225
|
-
return Boolean(this.findDecorator(node, names));
|
|
226
|
-
}
|
|
227
|
-
readDecoratorOptions(decorator) {
|
|
228
|
-
const expression = decorator.expression;
|
|
229
|
-
if (!ts.isCallExpression(expression)) return {};
|
|
230
|
-
const firstArg = expression.arguments[0];
|
|
231
|
-
if (!firstArg) return {};
|
|
232
|
-
if (ts.isStringLiteral(firstArg)) {
|
|
233
|
-
return {
|
|
234
|
-
name: firstArg.text
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
if (!ts.isObjectLiteralExpression(firstArg)) return {};
|
|
238
|
-
const result = {};
|
|
239
|
-
for (const property of firstArg.properties) {
|
|
240
|
-
if (!ts.isPropertyAssignment(property) || !ts.isIdentifier(property.name)) continue;
|
|
241
|
-
if (property.name.text === "name" && ts.isStringLiteral(property.initializer)) {
|
|
242
|
-
result.name = property.initializer.text;
|
|
243
|
-
}
|
|
244
|
-
if (property.name.text === "requireAuth") {
|
|
245
|
-
if (property.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
246
|
-
result.requireAuth = true;
|
|
247
|
-
} else if (property.initializer.kind === ts.SyntaxKind.FalseKeyword) {
|
|
248
|
-
result.requireAuth = false;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return result;
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
function getDecoratorName(decorator) {
|
|
256
|
-
const expression = decorator.expression;
|
|
257
|
-
if (ts.isIdentifier(expression)) return expression.text;
|
|
258
|
-
if (ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)) {
|
|
259
|
-
return expression.expression.text;
|
|
260
|
-
}
|
|
261
|
-
return void 0;
|
|
262
|
-
}
|
|
263
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, getDecoratorName, "getDecoratorName");
|
|
264
|
-
function toStableServiceName(className) {
|
|
265
|
-
const withoutSuffix = className.replace(/(Service|Controller)$/, "");
|
|
266
|
-
return withoutSuffix.charAt(0).toLowerCase() + withoutSuffix.slice(1);
|
|
267
|
-
}
|
|
268
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, toStableServiceName, "toStableServiceName");
|
|
269
|
-
function toPosixPath(filePath) {
|
|
270
|
-
return filePath.split(path.sep).join(path.posix.sep);
|
|
271
|
-
}
|
|
272
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, toPosixPath, "toPosixPath");
|
|
273
|
-
function getNodeText(node, sourceFile) {
|
|
274
|
-
return sourceFile.text.slice(node.getStart(sourceFile), node.getEnd());
|
|
275
|
-
}
|
|
276
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, getNodeText, "getNodeText");
|
|
277
|
-
|
|
278
|
-
// src/core/filesystem.ts
|
|
279
|
-
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
280
|
-
|
|
281
|
-
var _util = require('util');
|
|
282
|
-
var readFile2 = _util.promisify.call(void 0, fs.readFile);
|
|
283
|
-
var writeFile2 = _util.promisify.call(void 0, fs.writeFile);
|
|
284
|
-
var mkdir2 = _util.promisify.call(void 0, fs.mkdir);
|
|
285
|
-
var access2 = _util.promisify.call(void 0, fs.access);
|
|
286
|
-
var FileSystem = class {
|
|
287
|
-
static {
|
|
288
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, this, "FileSystem");
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Read file as string
|
|
292
|
-
*/
|
|
293
|
-
async readFile(filePath, encoding = "utf-8") {
|
|
294
|
-
return readFile2(filePath, encoding);
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Write file
|
|
298
|
-
*/
|
|
299
|
-
async writeFile(filePath, content) {
|
|
300
|
-
await this.ensureDir(path2.dirname(filePath));
|
|
301
|
-
return writeFile2(filePath, content, "utf-8");
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Read JSON file
|
|
305
|
-
*/
|
|
306
|
-
async readJSON(filePath) {
|
|
307
|
-
const content = await this.readFile(filePath);
|
|
308
|
-
return JSON.parse(content);
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Write JSON file
|
|
312
|
-
*/
|
|
313
|
-
async writeJSON(filePath, data, pretty = true) {
|
|
314
|
-
const content = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
|
|
315
|
-
return this.writeFile(filePath, content);
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Check if file/directory exists
|
|
319
|
-
*/
|
|
320
|
-
async exists(filePath) {
|
|
321
|
-
try {
|
|
322
|
-
await access2(filePath, fs.constants.F_OK);
|
|
323
|
-
return true;
|
|
324
|
-
} catch (e) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Ensure directory exists (create if not)
|
|
330
|
-
*/
|
|
331
|
-
async ensureDir(dirPath) {
|
|
332
|
-
if (!await this.exists(dirPath)) {
|
|
333
|
-
await mkdir2(dirPath, {
|
|
334
|
-
recursive: true
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Copy file
|
|
340
|
-
*/
|
|
341
|
-
async copyFile(src, dest) {
|
|
342
|
-
const content = await this.readFile(src);
|
|
343
|
-
await this.writeFile(dest, content);
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Read directory
|
|
347
|
-
*/
|
|
348
|
-
readDir(dirPath) {
|
|
349
|
-
return _util.promisify.call(void 0, fs.readdir)(dirPath);
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
var filesystem = new FileSystem();
|
|
353
|
-
|
|
354
|
-
// src/codegen/generator.ts
|
|
355
|
-
|
|
356
|
-
var ClientGenerator = class {
|
|
357
|
-
static {
|
|
358
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, this, "ClientGenerator");
|
|
359
|
-
}
|
|
360
|
-
async generate(options) {
|
|
361
|
-
const { manifest, outputPath, manifestFileName = "wexts.rpc.manifest.json", clientFileName = "client.ts" } = options;
|
|
362
|
-
if (manifest.services.length === 0) {
|
|
363
|
-
throw new Error("No Wexts RPC services found. Add @RpcService() to a Nest provider and @RpcMethod() to at least one method.");
|
|
364
|
-
}
|
|
365
|
-
const sortedManifest = sortManifest(manifest);
|
|
366
|
-
const clientCode = this.generateRpcClientCode(sortedManifest);
|
|
367
|
-
await filesystem.writeJSON(path3.join(outputPath, manifestFileName), sortedManifest, true);
|
|
368
|
-
await filesystem.writeFile(path3.join(outputPath, clientFileName), clientCode);
|
|
369
|
-
const indexCode = `export * from './client';
|
|
370
|
-
`;
|
|
371
|
-
await filesystem.writeFile(path3.join(outputPath, "index.ts"), indexCode);
|
|
372
|
-
}
|
|
373
|
-
generateRpcClientCode(manifest) {
|
|
374
|
-
const manifestJson = JSON.stringify(manifest, null, 2);
|
|
375
|
-
return `import { createWextsRpcClient, type WextsRpcClientOptions } from 'wexts/client';
|
|
376
|
-
import type { RpcManifest } from 'wexts/rpc';
|
|
377
|
-
|
|
378
|
-
const manifest = ${manifestJson} satisfies RpcManifest;
|
|
379
|
-
|
|
380
|
-
${this.generateClientInterface(manifest)}
|
|
381
|
-
|
|
382
|
-
export function createWextsClient(options?: WextsRpcClientOptions): WextsClient {
|
|
383
|
-
return createWextsRpcClient(manifest, options) as unknown as WextsClient;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
export const wexts = createWextsClient();
|
|
387
|
-
`;
|
|
388
|
-
}
|
|
389
|
-
generateClientInterface(manifest) {
|
|
390
|
-
const services = manifest.services.map((service) => this.generateServiceInterface(service)).join("\n");
|
|
391
|
-
return `export interface WextsClient {
|
|
392
|
-
${services}}
|
|
393
|
-
`;
|
|
394
|
-
}
|
|
395
|
-
generateServiceInterface(service) {
|
|
396
|
-
const methods = service.methods.map((method) => ` ${method.name}: (${this.parametersToSignature(method)}) => Promise<${normalizeReturnType(method.returnType)}>;`).join("\n");
|
|
397
|
-
return ` ${service.name}: {
|
|
398
|
-
${methods}
|
|
399
|
-
};
|
|
400
|
-
`;
|
|
401
|
-
}
|
|
402
|
-
parametersToSignature(method) {
|
|
403
|
-
return method.parameters.map((parameter) => `${parameter.name}${parameter.optional ? "?" : ""}: ${parameter.type}`).join(", ");
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
async function generateRpcClient(options) {
|
|
407
|
-
const parser = new NestJSParser(options.projectPath);
|
|
408
|
-
const manifest = parser.findRpcManifest();
|
|
409
|
-
const generator = new ClientGenerator();
|
|
410
|
-
await generator.generate({
|
|
411
|
-
manifest,
|
|
412
|
-
outputPath: options.outputPath,
|
|
413
|
-
manifestFileName: options.manifestFileName,
|
|
414
|
-
clientFileName: options.clientFileName
|
|
415
|
-
});
|
|
416
|
-
return sortManifest(manifest);
|
|
417
|
-
}
|
|
418
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, generateRpcClient, "generateRpcClient");
|
|
419
|
-
function sortManifest(manifest) {
|
|
420
|
-
return {
|
|
421
|
-
schemaVersion: 1,
|
|
422
|
-
services: [
|
|
423
|
-
...manifest.services
|
|
424
|
-
].sort((a, b) => a.name.localeCompare(b.name)).map((service) => ({
|
|
425
|
-
...service,
|
|
426
|
-
methods: [
|
|
427
|
-
...service.methods
|
|
428
|
-
].sort((a, b) => a.name.localeCompare(b.name))
|
|
429
|
-
}))
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, sortManifest, "sortManifest");
|
|
433
|
-
function normalizeReturnType(returnType) {
|
|
434
|
-
const match = returnType.match(/^Promise<(.+)>$/);
|
|
435
|
-
return _nullishCoalesce(_optionalChain([match, 'optionalAccess', _3 => _3[1]]), () => ( returnType));
|
|
436
|
-
}
|
|
437
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, normalizeReturnType, "normalizeReturnType");
|
|
438
|
-
|
|
439
|
-
// src/codegen/watcher.ts
|
|
440
|
-
var _chokidar = require('chokidar'); var chokidar = _interopRequireWildcard(_chokidar);
|
|
441
|
-
var CodegenWatcher = (_class = class {constructor() { _class.prototype.__init.call(this); }
|
|
442
|
-
static {
|
|
443
|
-
_chunkXE4OXN2Wjs.__name.call(void 0, this, "CodegenWatcher");
|
|
444
|
-
}
|
|
445
|
-
__init() {this.watcher = null}
|
|
446
|
-
async watch(options) {
|
|
447
|
-
const { projectPath, outputPath, pattern = "**/*.controller.ts" } = options;
|
|
448
|
-
_chunkWCKSKU3Cjs.logger.info("\u{1F440} Watching for controller changes...");
|
|
449
|
-
await this.generateClient(projectPath, outputPath);
|
|
450
|
-
this.watcher = chokidar.watch(pattern, {
|
|
451
|
-
cwd: projectPath,
|
|
452
|
-
ignored: /node_modules/,
|
|
453
|
-
persistent: true
|
|
454
|
-
});
|
|
455
|
-
this.watcher.on("change", async (path4) => {
|
|
456
|
-
_chunkWCKSKU3Cjs.logger.info(`\u{1F4DD} Controller changed: ${path4}`);
|
|
457
|
-
await this.generateClient(projectPath, outputPath);
|
|
458
|
-
});
|
|
459
|
-
this.watcher.on("add", async (path4) => {
|
|
460
|
-
_chunkWCKSKU3Cjs.logger.info(`\u2795 New controller: ${path4}`);
|
|
461
|
-
await this.generateClient(projectPath, outputPath);
|
|
462
|
-
});
|
|
463
|
-
this.watcher.on("unlink", async (path4) => {
|
|
464
|
-
_chunkWCKSKU3Cjs.logger.info(`\u2796 Controller removed: ${path4}`);
|
|
465
|
-
await this.generateClient(projectPath, outputPath);
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
async stop() {
|
|
469
|
-
if (this.watcher) {
|
|
470
|
-
await this.watcher.close();
|
|
471
|
-
this.watcher = null;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
async generateClient(projectPath, outputPath) {
|
|
475
|
-
try {
|
|
476
|
-
const manifest = await generateRpcClient({
|
|
477
|
-
projectPath,
|
|
478
|
-
outputPath
|
|
479
|
-
});
|
|
480
|
-
_chunkWCKSKU3Cjs.logger.success(`Generated client for ${manifest.services.length} RPC service(s)`);
|
|
481
|
-
} catch (error) {
|
|
482
|
-
_chunkWCKSKU3Cjs.logger.error("Failed to generate client:", error.message);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}, _class);
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
exports.FileSystem = FileSystem; exports.filesystem = filesystem; exports.NestJSParser = NestJSParser; exports.ClientGenerator = ClientGenerator; exports.generateRpcClient = generateRpcClient; exports.CodegenWatcher = CodegenWatcher; exports.codegen_exports = codegen_exports;
|
|
496
|
-
//# sourceMappingURL=chunk-SE32ZPOZ.js.map
|