@lark-apaas/fullstack-nestjs-core 1.0.6-alpha.0 → 1.0.6-alpha.1

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/index.cjs CHANGED
@@ -34,8 +34,8 @@ var index_exports = {};
34
34
  __export(index_exports, {
35
35
  CsrfMiddleware: () => CsrfMiddleware,
36
36
  CsrfTokenMiddleware: () => CsrfTokenMiddleware,
37
- DevToolsModule: () => import_nestjs_openapi_devtools2.DevToolsModule,
38
- DevToolsV2Module: () => import_nestjs_openapi_devtools2.DevToolsV2Module,
37
+ DevToolsModule: () => DevToolsModule,
38
+ DevToolsV2Module: () => DevToolsV2Module,
39
39
  PlatformModule: () => PlatformModule,
40
40
  UserContextMiddleware: () => UserContextMiddleware,
41
41
  ViewContextMiddleware: () => ViewContextMiddleware,
@@ -372,7 +372,152 @@ PlatformModule = _ts_decorate5([
372
372
  // src/setup.ts
373
373
  var import_nestjs_logger2 = require("@lark-apaas/nestjs-logger");
374
374
  var import_cookie_parser = __toESM(require("cookie-parser"), 1);
375
- var import_nestjs_openapi_devtools = require("@lark-apaas/nestjs-openapi-devtools");
375
+
376
+ // src/modules/devtool-v2/index.ts
377
+ var import_swagger = require("@nestjs/swagger");
378
+ var import_node_fs4 = require("fs");
379
+ var import_node_path4 = require("path");
380
+
381
+ // src/modules/devtool-v2/helper.ts
382
+ var import_node_path = require("path");
383
+ var import_node_fs = require("fs");
384
+ function normalizeBasePath(rawBasePath) {
385
+ const normalizedBasePath = rawBasePath.startsWith("/") ? rawBasePath : `/${rawBasePath}`;
386
+ return normalizedBasePath.endsWith("/") ? normalizedBasePath.slice(0, -1) : normalizedBasePath;
387
+ }
388
+ __name(normalizeBasePath, "normalizeBasePath");
389
+ function resolveOptsWithDefaultValue(options) {
390
+ const basePath = normalizeBasePath(options.basePath || "/");
391
+ const docsPath = normalizeBasePath(options.docsPath || `api/docs`);
392
+ return {
393
+ ...options,
394
+ needSetupServer: options.needSetupServer ?? false,
395
+ basePath,
396
+ docsPath: `${basePath}${docsPath}`,
397
+ openapiOut: options.openapiOut || "./client/src/api/gen/openapi.json",
398
+ clientSdkOut: options.clientSdkOut || "./client/src/api/gen",
399
+ needGenerateClientSdk: options.needGenerateClientSdk ?? true,
400
+ swaggerOptions: {
401
+ title: options.swaggerOptions?.title ?? "NestJS Fullstack API",
402
+ version: options.swaggerOptions?.version ?? "1.0.0",
403
+ customSiteTitle: options.swaggerOptions?.customSiteTitle ?? "API Documentation",
404
+ customCss: options.swaggerOptions?.customCss ?? ".swagger-ui .topbar { display: none }"
405
+ }
406
+ };
407
+ }
408
+ __name(resolveOptsWithDefaultValue, "resolveOptsWithDefaultValue");
409
+ function ensureDirAndWrite(filePath, content) {
410
+ const dir = (0, import_node_path.dirname)(filePath);
411
+ (0, import_node_fs.mkdirSync)(dir, {
412
+ recursive: true
413
+ });
414
+ (0, import_node_fs.writeFileSync)(filePath, content);
415
+ }
416
+ __name(ensureDirAndWrite, "ensureDirAndWrite");
417
+
418
+ // src/modules/devtool-v2/plugins/client-config-generator.ts
419
+ var import_node_fs2 = require("fs");
420
+ var import_node_path2 = require("path");
421
+ function generateClientConfig(options) {
422
+ const configFilePath = (0, import_node_path2.resolve)(options.outputPath, "client.config.ts");
423
+ const configContent = `// This file is auto-generated by @hey-api/openapi-ts
424
+ import axios from 'axios';
425
+ import type { CreateClientConfig } from './client';
426
+ export const createClientConfig: CreateClientConfig = (config) => ({
427
+ axios
428
+ });
429
+ `;
430
+ (0, import_node_fs2.writeFileSync)(configFilePath, configContent, "utf-8");
431
+ return configFilePath;
432
+ }
433
+ __name(generateClientConfig, "generateClientConfig");
434
+
435
+ // src/modules/devtool-v2/plugins/add-ts-nocheck.ts
436
+ var import_node_fs3 = require("fs");
437
+ var import_node_path3 = require("path");
438
+ function addTsNocheckToGeneratedFiles(outputPath) {
439
+ const files = getAllTsFiles(outputPath);
440
+ for (const filePath of files) {
441
+ addTsNocheckToFile(filePath);
442
+ }
443
+ }
444
+ __name(addTsNocheckToGeneratedFiles, "addTsNocheckToGeneratedFiles");
445
+ function getAllTsFiles(dirPath) {
446
+ const files = [];
447
+ const entries = (0, import_node_fs3.readdirSync)(dirPath);
448
+ for (const entry of entries) {
449
+ const fullPath = (0, import_node_path3.join)(dirPath, entry);
450
+ const stat = (0, import_node_fs3.statSync)(fullPath);
451
+ if (stat.isDirectory()) {
452
+ files.push(...getAllTsFiles(fullPath));
453
+ } else if (stat.isFile() && entry.endsWith(".ts")) {
454
+ files.push(fullPath);
455
+ }
456
+ }
457
+ return files;
458
+ }
459
+ __name(getAllTsFiles, "getAllTsFiles");
460
+ function addTsNocheckToFile(filePath) {
461
+ const content = (0, import_node_fs3.readFileSync)(filePath, "utf-8");
462
+ const newContent = `// @ts-nocheck
463
+ ${content}`;
464
+ (0, import_node_fs3.writeFileSync)(filePath, newContent, "utf-8");
465
+ }
466
+ __name(addTsNocheckToFile, "addTsNocheckToFile");
467
+
468
+ // src/modules/devtool-v2/index.ts
469
+ var DevToolsV2Module = class {
470
+ static {
471
+ __name(this, "DevToolsV2Module");
472
+ }
473
+ static async mount(app, opts = {}) {
474
+ const options = resolveOptsWithDefaultValue(opts);
475
+ const baseDirname = process.cwd();
476
+ const builder = new import_swagger.DocumentBuilder().setTitle(options.swaggerOptions.title).setVersion(options.swaggerOptions.version);
477
+ const document = import_swagger.SwaggerModule.createDocument(app, builder.build());
478
+ if (options.needSetupServer) {
479
+ import_swagger.SwaggerModule.setup(options.docsPath, app, document, {
480
+ customSiteTitle: options.swaggerOptions.customSiteTitle,
481
+ customCss: options.swaggerOptions.customCss,
482
+ swaggerOptions: {
483
+ persistAuthorization: true
484
+ }
485
+ });
486
+ console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
487
+ }
488
+ const openapiPath = (0, import_node_path4.resolve)(baseDirname, options.openapiOut);
489
+ ensureDirAndWrite(openapiPath, JSON.stringify(document, null, 2));
490
+ if (options.needGenerateClientSdk) {
491
+ const clientSdkOutPath = (0, import_node_path4.resolve)(baseDirname, options.clientSdkOut);
492
+ (0, import_node_fs4.mkdirSync)(clientSdkOutPath, {
493
+ recursive: true
494
+ });
495
+ const { createClient } = await import("@hey-api/openapi-ts");
496
+ await createClient({
497
+ input: openapiPath,
498
+ output: {
499
+ path: clientSdkOutPath
500
+ },
501
+ plugins: [
502
+ "@hey-api/typescript",
503
+ "@hey-api/sdk",
504
+ {
505
+ name: "@hey-api/client-axios",
506
+ runtimeConfigPath: (0, import_node_path4.join)(clientSdkOutPath, "./client.config.ts")
507
+ }
508
+ ]
509
+ });
510
+ addTsNocheckToGeneratedFiles(clientSdkOutPath);
511
+ ensureDirAndWrite(openapiPath, JSON.stringify(document, null, 2));
512
+ generateClientConfig({
513
+ outputPath: clientSdkOutPath
514
+ });
515
+ console.log("[OpenAPI] \u5BFC\u51FA openapi.json \u5E76\u751F\u6210 axios SDK \u2705");
516
+ }
517
+ }
518
+ };
519
+
520
+ // src/setup.ts
376
521
  async function configureApp(app) {
377
522
  app.useLogger(app.get(import_nestjs_logger2.AppLogger));
378
523
  app.flushLogs();
@@ -380,20 +525,99 @@ async function configureApp(app) {
380
525
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
381
526
  app.setGlobalPrefix(globalPrefix);
382
527
  if (process.env.NODE_ENV !== "production") {
383
- try {
384
- await import_nestjs_openapi_devtools.DevToolsV2Module.mount(app, {
385
- basePath: process.env.CLIENT_BASE_PATH,
386
- docsPath: "/api_docs"
387
- });
388
- } catch (err) {
389
- console.error("[OpenAPI] OpenAPI \u751F\u6210\u5931\u8D25:", err);
390
- }
528
+ await DevToolsV2Module.mount(app, {
529
+ basePath: process.env.CLIENT_BASE_PATH,
530
+ docsPath: "/api_docs"
531
+ });
391
532
  }
392
533
  }
393
534
  __name(configureApp, "configureApp");
394
535
 
536
+ // src/modules/devtool/index.ts
537
+ var import_swagger2 = require("@nestjs/swagger");
538
+ var import_node_fs6 = require("fs");
539
+ var import_node_path6 = require("path");
540
+
541
+ // src/modules/devtool/helper.ts
542
+ var import_node_path5 = require("path");
543
+ var import_node_fs5 = require("fs");
544
+ function normalizeBasePath2(rawBasePath) {
545
+ const normalizedBasePath = rawBasePath.startsWith("/") ? rawBasePath : `/${rawBasePath}`;
546
+ return normalizedBasePath.endsWith("/") ? normalizedBasePath.slice(0, -1) : normalizedBasePath;
547
+ }
548
+ __name(normalizeBasePath2, "normalizeBasePath");
549
+ function resolveOptsWithDefaultValue2(options) {
550
+ const basePath = normalizeBasePath2(options.basePath || "/");
551
+ const docsPath = normalizeBasePath2(options.docsPath || `api/docs`);
552
+ return {
553
+ ...options,
554
+ needSetupServer: options.needSetupServer ?? false,
555
+ basePath,
556
+ docsPath: `${basePath}${docsPath}`,
557
+ openapiOut: options.openapiOut || "./client/src/api/gen/openapi.json",
558
+ clientSdkOut: options.clientSdkOut || "./client/src/api/gen",
559
+ needGenerateClientSdk: options.needGenerateClientSdk ?? true,
560
+ swaggerOptions: {
561
+ title: options.swaggerOptions?.title ?? "NestJS Fullstack API",
562
+ version: options.swaggerOptions?.version ?? "1.0.0",
563
+ customSiteTitle: options.swaggerOptions?.customSiteTitle ?? "API Documentation",
564
+ customCss: options.swaggerOptions?.customCss ?? ".swagger-ui .topbar { display: none }"
565
+ }
566
+ };
567
+ }
568
+ __name(resolveOptsWithDefaultValue2, "resolveOptsWithDefaultValue");
569
+ function ensureDirAndWrite2(filePath, content) {
570
+ const dir = (0, import_node_path5.dirname)(filePath);
571
+ (0, import_node_fs5.mkdirSync)(dir, {
572
+ recursive: true
573
+ });
574
+ (0, import_node_fs5.writeFileSync)(filePath, content);
575
+ }
576
+ __name(ensureDirAndWrite2, "ensureDirAndWrite");
577
+
578
+ // src/modules/devtool/index.ts
579
+ var DevToolsModule = class {
580
+ static {
581
+ __name(this, "DevToolsModule");
582
+ }
583
+ static async mount(app, opts = {}) {
584
+ const options = resolveOptsWithDefaultValue2(opts);
585
+ const baseDirname = process.cwd();
586
+ const builder = new import_swagger2.DocumentBuilder().setTitle(options.swaggerOptions.title).setVersion(options.swaggerOptions.version);
587
+ const document = import_swagger2.SwaggerModule.createDocument(app, builder.build(), {
588
+ operationIdFactory: /* @__PURE__ */ __name((_c, m) => m, "operationIdFactory")
589
+ });
590
+ if (options.needSetupServer) {
591
+ import_swagger2.SwaggerModule.setup(options.docsPath, app, document, {
592
+ customSiteTitle: options.swaggerOptions.customSiteTitle,
593
+ customCss: options.swaggerOptions.customCss,
594
+ swaggerOptions: {
595
+ persistAuthorization: true
596
+ }
597
+ });
598
+ console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
599
+ }
600
+ const openapiPath = (0, import_node_path6.resolve)(baseDirname, options.openapiOut);
601
+ ensureDirAndWrite2(openapiPath, JSON.stringify(document, null, 2));
602
+ if (options.needGenerateClientSdk) {
603
+ const clientSdkOutPath = (0, import_node_path6.resolve)(baseDirname, options.clientSdkOut);
604
+ (0, import_node_fs6.mkdirSync)(clientSdkOutPath, {
605
+ recursive: true
606
+ });
607
+ const { generate } = await import("openapi-typescript-codegen");
608
+ await generate({
609
+ input: openapiPath,
610
+ output: clientSdkOutPath,
611
+ httpClient: "axios",
612
+ useOptions: false,
613
+ exportServices: true
614
+ });
615
+ console.log("[OpenAPI] \u5BFC\u51FA openapi.json \u5E76\u751F\u6210 axios SDK \u2705");
616
+ }
617
+ }
618
+ };
619
+
395
620
  // src/index.ts
396
- var import_nestjs_openapi_devtools2 = require("@lark-apaas/nestjs-openapi-devtools");
397
621
  __reExport(index_exports, require("@lark-apaas/nestjs-authnpaas"), module.exports);
398
622
  __reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports);
399
623
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.cts CHANGED
@@ -1,6 +1,5 @@
1
- import { NestModule, DynamicModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
1
+ import { NestModule, DynamicModule, MiddlewareConsumer, INestApplication, NestMiddleware } from '@nestjs/common';
2
2
  import { NestExpressApplication } from '@nestjs/platform-express';
3
- export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
4
3
  import { Request, Response, NextFunction } from 'express';
5
4
  export * from '@lark-apaas/nestjs-authnpaas';
6
5
  export * from '@lark-apaas/nestjs-datapaas';
@@ -52,6 +51,47 @@ declare class PlatformModule implements NestModule {
52
51
 
53
52
  declare function configureApp(app: NestExpressApplication): Promise<void>;
54
53
 
54
+ interface DevToolsOptions$1 {
55
+ basePath?: string;
56
+ docsPath?: string;
57
+ openapiOut?: string;
58
+ needSetupServer?: boolean;
59
+ needGenerateClientSdk?: boolean;
60
+ clientSdkOut?: string;
61
+ swaggerOptions?: {
62
+ title?: string;
63
+ version?: string;
64
+ customSiteTitle?: string;
65
+ customCss?: string;
66
+ };
67
+ }
68
+
69
+ /**
70
+ * @deprecated 该模块已被废弃,不建议使用,建议使用 DevToolsV2Module
71
+ */
72
+ declare class DevToolsModule {
73
+ static mount(app: INestApplication, opts?: DevToolsOptions$1): Promise<void>;
74
+ }
75
+
76
+ interface DevToolsOptions {
77
+ basePath?: string;
78
+ docsPath?: string;
79
+ openapiOut?: string;
80
+ needSetupServer?: boolean;
81
+ needGenerateClientSdk?: boolean;
82
+ clientSdkOut?: string;
83
+ swaggerOptions?: {
84
+ title?: string;
85
+ version?: string;
86
+ customSiteTitle?: string;
87
+ customCss?: string;
88
+ };
89
+ }
90
+
91
+ declare class DevToolsV2Module {
92
+ static mount(app: INestApplication, opts?: DevToolsOptions): Promise<void>;
93
+ }
94
+
55
95
  interface CsrfTokenOptions {
56
96
  cookieKey?: string;
57
97
  cookieMaxAge?: number;
@@ -83,4 +123,4 @@ declare class ViewContextMiddleware implements NestMiddleware {
83
123
  use(req: Request, res: Response, next: NextFunction): void;
84
124
  }
85
125
 
86
- export { CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
126
+ export { CsrfMiddleware, CsrfTokenMiddleware, DevToolsModule, DevToolsV2Module, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { NestModule, DynamicModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
1
+ import { NestModule, DynamicModule, MiddlewareConsumer, INestApplication, NestMiddleware } from '@nestjs/common';
2
2
  import { NestExpressApplication } from '@nestjs/platform-express';
3
- export { DevToolsModule, DevToolsOptions, DevToolsV2Module, DevToolsV2Options } from '@lark-apaas/nestjs-openapi-devtools';
4
3
  import { Request, Response, NextFunction } from 'express';
5
4
  export * from '@lark-apaas/nestjs-authnpaas';
6
5
  export * from '@lark-apaas/nestjs-datapaas';
@@ -52,6 +51,47 @@ declare class PlatformModule implements NestModule {
52
51
 
53
52
  declare function configureApp(app: NestExpressApplication): Promise<void>;
54
53
 
54
+ interface DevToolsOptions$1 {
55
+ basePath?: string;
56
+ docsPath?: string;
57
+ openapiOut?: string;
58
+ needSetupServer?: boolean;
59
+ needGenerateClientSdk?: boolean;
60
+ clientSdkOut?: string;
61
+ swaggerOptions?: {
62
+ title?: string;
63
+ version?: string;
64
+ customSiteTitle?: string;
65
+ customCss?: string;
66
+ };
67
+ }
68
+
69
+ /**
70
+ * @deprecated 该模块已被废弃,不建议使用,建议使用 DevToolsV2Module
71
+ */
72
+ declare class DevToolsModule {
73
+ static mount(app: INestApplication, opts?: DevToolsOptions$1): Promise<void>;
74
+ }
75
+
76
+ interface DevToolsOptions {
77
+ basePath?: string;
78
+ docsPath?: string;
79
+ openapiOut?: string;
80
+ needSetupServer?: boolean;
81
+ needGenerateClientSdk?: boolean;
82
+ clientSdkOut?: string;
83
+ swaggerOptions?: {
84
+ title?: string;
85
+ version?: string;
86
+ customSiteTitle?: string;
87
+ customCss?: string;
88
+ };
89
+ }
90
+
91
+ declare class DevToolsV2Module {
92
+ static mount(app: INestApplication, opts?: DevToolsOptions): Promise<void>;
93
+ }
94
+
55
95
  interface CsrfTokenOptions {
56
96
  cookieKey?: string;
57
97
  cookieMaxAge?: number;
@@ -83,4 +123,4 @@ declare class ViewContextMiddleware implements NestMiddleware {
83
123
  use(req: Request, res: Response, next: NextFunction): void;
84
124
  }
85
125
 
86
- export { CsrfMiddleware, CsrfTokenMiddleware, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
126
+ export { CsrfMiddleware, CsrfTokenMiddleware, DevToolsModule, DevToolsV2Module, PlatformModule, type PlatformModuleOptions, UserContextMiddleware, ViewContextMiddleware, configureApp };
package/dist/index.js CHANGED
@@ -330,7 +330,152 @@ PlatformModule = _ts_decorate5([
330
330
  // src/setup.ts
331
331
  import { AppLogger as AppLogger2 } from "@lark-apaas/nestjs-logger";
332
332
  import cookieParser from "cookie-parser";
333
- import { DevToolsV2Module } from "@lark-apaas/nestjs-openapi-devtools";
333
+
334
+ // src/modules/devtool-v2/index.ts
335
+ import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
336
+ import { mkdirSync as mkdirSync2 } from "fs";
337
+ import { resolve as resolve2, join as join2 } from "path";
338
+
339
+ // src/modules/devtool-v2/helper.ts
340
+ import { dirname } from "path";
341
+ import { writeFileSync, mkdirSync } from "fs";
342
+ function normalizeBasePath(rawBasePath) {
343
+ const normalizedBasePath = rawBasePath.startsWith("/") ? rawBasePath : `/${rawBasePath}`;
344
+ return normalizedBasePath.endsWith("/") ? normalizedBasePath.slice(0, -1) : normalizedBasePath;
345
+ }
346
+ __name(normalizeBasePath, "normalizeBasePath");
347
+ function resolveOptsWithDefaultValue(options) {
348
+ const basePath = normalizeBasePath(options.basePath || "/");
349
+ const docsPath = normalizeBasePath(options.docsPath || `api/docs`);
350
+ return {
351
+ ...options,
352
+ needSetupServer: options.needSetupServer ?? false,
353
+ basePath,
354
+ docsPath: `${basePath}${docsPath}`,
355
+ openapiOut: options.openapiOut || "./client/src/api/gen/openapi.json",
356
+ clientSdkOut: options.clientSdkOut || "./client/src/api/gen",
357
+ needGenerateClientSdk: options.needGenerateClientSdk ?? true,
358
+ swaggerOptions: {
359
+ title: options.swaggerOptions?.title ?? "NestJS Fullstack API",
360
+ version: options.swaggerOptions?.version ?? "1.0.0",
361
+ customSiteTitle: options.swaggerOptions?.customSiteTitle ?? "API Documentation",
362
+ customCss: options.swaggerOptions?.customCss ?? ".swagger-ui .topbar { display: none }"
363
+ }
364
+ };
365
+ }
366
+ __name(resolveOptsWithDefaultValue, "resolveOptsWithDefaultValue");
367
+ function ensureDirAndWrite(filePath, content) {
368
+ const dir = dirname(filePath);
369
+ mkdirSync(dir, {
370
+ recursive: true
371
+ });
372
+ writeFileSync(filePath, content);
373
+ }
374
+ __name(ensureDirAndWrite, "ensureDirAndWrite");
375
+
376
+ // src/modules/devtool-v2/plugins/client-config-generator.ts
377
+ import { writeFileSync as writeFileSync2 } from "fs";
378
+ import { resolve } from "path";
379
+ function generateClientConfig(options) {
380
+ const configFilePath = resolve(options.outputPath, "client.config.ts");
381
+ const configContent = `// This file is auto-generated by @hey-api/openapi-ts
382
+ import axios from 'axios';
383
+ import type { CreateClientConfig } from './client';
384
+ export const createClientConfig: CreateClientConfig = (config) => ({
385
+ axios
386
+ });
387
+ `;
388
+ writeFileSync2(configFilePath, configContent, "utf-8");
389
+ return configFilePath;
390
+ }
391
+ __name(generateClientConfig, "generateClientConfig");
392
+
393
+ // src/modules/devtool-v2/plugins/add-ts-nocheck.ts
394
+ import { readdirSync, readFileSync, writeFileSync as writeFileSync3, statSync } from "fs";
395
+ import { join } from "path";
396
+ function addTsNocheckToGeneratedFiles(outputPath) {
397
+ const files = getAllTsFiles(outputPath);
398
+ for (const filePath of files) {
399
+ addTsNocheckToFile(filePath);
400
+ }
401
+ }
402
+ __name(addTsNocheckToGeneratedFiles, "addTsNocheckToGeneratedFiles");
403
+ function getAllTsFiles(dirPath) {
404
+ const files = [];
405
+ const entries = readdirSync(dirPath);
406
+ for (const entry of entries) {
407
+ const fullPath = join(dirPath, entry);
408
+ const stat = statSync(fullPath);
409
+ if (stat.isDirectory()) {
410
+ files.push(...getAllTsFiles(fullPath));
411
+ } else if (stat.isFile() && entry.endsWith(".ts")) {
412
+ files.push(fullPath);
413
+ }
414
+ }
415
+ return files;
416
+ }
417
+ __name(getAllTsFiles, "getAllTsFiles");
418
+ function addTsNocheckToFile(filePath) {
419
+ const content = readFileSync(filePath, "utf-8");
420
+ const newContent = `// @ts-nocheck
421
+ ${content}`;
422
+ writeFileSync3(filePath, newContent, "utf-8");
423
+ }
424
+ __name(addTsNocheckToFile, "addTsNocheckToFile");
425
+
426
+ // src/modules/devtool-v2/index.ts
427
+ var DevToolsV2Module = class {
428
+ static {
429
+ __name(this, "DevToolsV2Module");
430
+ }
431
+ static async mount(app, opts = {}) {
432
+ const options = resolveOptsWithDefaultValue(opts);
433
+ const baseDirname = process.cwd();
434
+ const builder = new DocumentBuilder().setTitle(options.swaggerOptions.title).setVersion(options.swaggerOptions.version);
435
+ const document = SwaggerModule.createDocument(app, builder.build());
436
+ if (options.needSetupServer) {
437
+ SwaggerModule.setup(options.docsPath, app, document, {
438
+ customSiteTitle: options.swaggerOptions.customSiteTitle,
439
+ customCss: options.swaggerOptions.customCss,
440
+ swaggerOptions: {
441
+ persistAuthorization: true
442
+ }
443
+ });
444
+ console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
445
+ }
446
+ const openapiPath = resolve2(baseDirname, options.openapiOut);
447
+ ensureDirAndWrite(openapiPath, JSON.stringify(document, null, 2));
448
+ if (options.needGenerateClientSdk) {
449
+ const clientSdkOutPath = resolve2(baseDirname, options.clientSdkOut);
450
+ mkdirSync2(clientSdkOutPath, {
451
+ recursive: true
452
+ });
453
+ const { createClient } = await import("@hey-api/openapi-ts");
454
+ await createClient({
455
+ input: openapiPath,
456
+ output: {
457
+ path: clientSdkOutPath
458
+ },
459
+ plugins: [
460
+ "@hey-api/typescript",
461
+ "@hey-api/sdk",
462
+ {
463
+ name: "@hey-api/client-axios",
464
+ runtimeConfigPath: join2(clientSdkOutPath, "./client.config.ts")
465
+ }
466
+ ]
467
+ });
468
+ addTsNocheckToGeneratedFiles(clientSdkOutPath);
469
+ ensureDirAndWrite(openapiPath, JSON.stringify(document, null, 2));
470
+ generateClientConfig({
471
+ outputPath: clientSdkOutPath
472
+ });
473
+ console.log("[OpenAPI] \u5BFC\u51FA openapi.json \u5E76\u751F\u6210 axios SDK \u2705");
474
+ }
475
+ }
476
+ };
477
+
478
+ // src/setup.ts
334
479
  async function configureApp(app) {
335
480
  app.useLogger(app.get(AppLogger2));
336
481
  app.flushLogs();
@@ -338,27 +483,106 @@ async function configureApp(app) {
338
483
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
339
484
  app.setGlobalPrefix(globalPrefix);
340
485
  if (process.env.NODE_ENV !== "production") {
341
- try {
342
- await DevToolsV2Module.mount(app, {
343
- basePath: process.env.CLIENT_BASE_PATH,
344
- docsPath: "/api_docs"
345
- });
346
- } catch (err) {
347
- console.error("[OpenAPI] OpenAPI \u751F\u6210\u5931\u8D25:", err);
348
- }
486
+ await DevToolsV2Module.mount(app, {
487
+ basePath: process.env.CLIENT_BASE_PATH,
488
+ docsPath: "/api_docs"
489
+ });
349
490
  }
350
491
  }
351
492
  __name(configureApp, "configureApp");
352
493
 
494
+ // src/modules/devtool/index.ts
495
+ import { SwaggerModule as SwaggerModule2, DocumentBuilder as DocumentBuilder2 } from "@nestjs/swagger";
496
+ import { mkdirSync as mkdirSync4 } from "fs";
497
+ import { resolve as resolve3 } from "path";
498
+
499
+ // src/modules/devtool/helper.ts
500
+ import { dirname as dirname2 } from "path";
501
+ import { writeFileSync as writeFileSync4, mkdirSync as mkdirSync3 } from "fs";
502
+ function normalizeBasePath2(rawBasePath) {
503
+ const normalizedBasePath = rawBasePath.startsWith("/") ? rawBasePath : `/${rawBasePath}`;
504
+ return normalizedBasePath.endsWith("/") ? normalizedBasePath.slice(0, -1) : normalizedBasePath;
505
+ }
506
+ __name(normalizeBasePath2, "normalizeBasePath");
507
+ function resolveOptsWithDefaultValue2(options) {
508
+ const basePath = normalizeBasePath2(options.basePath || "/");
509
+ const docsPath = normalizeBasePath2(options.docsPath || `api/docs`);
510
+ return {
511
+ ...options,
512
+ needSetupServer: options.needSetupServer ?? false,
513
+ basePath,
514
+ docsPath: `${basePath}${docsPath}`,
515
+ openapiOut: options.openapiOut || "./client/src/api/gen/openapi.json",
516
+ clientSdkOut: options.clientSdkOut || "./client/src/api/gen",
517
+ needGenerateClientSdk: options.needGenerateClientSdk ?? true,
518
+ swaggerOptions: {
519
+ title: options.swaggerOptions?.title ?? "NestJS Fullstack API",
520
+ version: options.swaggerOptions?.version ?? "1.0.0",
521
+ customSiteTitle: options.swaggerOptions?.customSiteTitle ?? "API Documentation",
522
+ customCss: options.swaggerOptions?.customCss ?? ".swagger-ui .topbar { display: none }"
523
+ }
524
+ };
525
+ }
526
+ __name(resolveOptsWithDefaultValue2, "resolveOptsWithDefaultValue");
527
+ function ensureDirAndWrite2(filePath, content) {
528
+ const dir = dirname2(filePath);
529
+ mkdirSync3(dir, {
530
+ recursive: true
531
+ });
532
+ writeFileSync4(filePath, content);
533
+ }
534
+ __name(ensureDirAndWrite2, "ensureDirAndWrite");
535
+
536
+ // src/modules/devtool/index.ts
537
+ var DevToolsModule = class {
538
+ static {
539
+ __name(this, "DevToolsModule");
540
+ }
541
+ static async mount(app, opts = {}) {
542
+ const options = resolveOptsWithDefaultValue2(opts);
543
+ const baseDirname = process.cwd();
544
+ const builder = new DocumentBuilder2().setTitle(options.swaggerOptions.title).setVersion(options.swaggerOptions.version);
545
+ const document = SwaggerModule2.createDocument(app, builder.build(), {
546
+ operationIdFactory: /* @__PURE__ */ __name((_c, m) => m, "operationIdFactory")
547
+ });
548
+ if (options.needSetupServer) {
549
+ SwaggerModule2.setup(options.docsPath, app, document, {
550
+ customSiteTitle: options.swaggerOptions.customSiteTitle,
551
+ customCss: options.swaggerOptions.customCss,
552
+ swaggerOptions: {
553
+ persistAuthorization: true
554
+ }
555
+ });
556
+ console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
557
+ }
558
+ const openapiPath = resolve3(baseDirname, options.openapiOut);
559
+ ensureDirAndWrite2(openapiPath, JSON.stringify(document, null, 2));
560
+ if (options.needGenerateClientSdk) {
561
+ const clientSdkOutPath = resolve3(baseDirname, options.clientSdkOut);
562
+ mkdirSync4(clientSdkOutPath, {
563
+ recursive: true
564
+ });
565
+ const { generate } = await import("openapi-typescript-codegen");
566
+ await generate({
567
+ input: openapiPath,
568
+ output: clientSdkOutPath,
569
+ httpClient: "axios",
570
+ useOptions: false,
571
+ exportServices: true
572
+ });
573
+ console.log("[OpenAPI] \u5BFC\u51FA openapi.json \u5E76\u751F\u6210 axios SDK \u2705");
574
+ }
575
+ }
576
+ };
577
+
353
578
  // src/index.ts
354
- import { DevToolsModule, DevToolsV2Module as DevToolsV2Module2 } from "@lark-apaas/nestjs-openapi-devtools";
355
579
  export * from "@lark-apaas/nestjs-authnpaas";
356
580
  export * from "@lark-apaas/nestjs-datapaas";
357
581
  export {
358
582
  CsrfMiddleware,
359
583
  CsrfTokenMiddleware,
360
584
  DevToolsModule,
361
- DevToolsV2Module2 as DevToolsV2Module,
585
+ DevToolsV2Module,
362
586
  PlatformModule,
363
587
  UserContextMiddleware,
364
588
  ViewContextMiddleware,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.0.6-alpha.0",
3
+ "version": "1.0.6-alpha.1",
4
4
  "description": "FullStack Nestjs Core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,11 +38,12 @@
38
38
  "lint:fix": "eslint src --ext .ts --fix"
39
39
  },
40
40
  "dependencies": {
41
+ "@hey-api/openapi-ts": "^0.87.0",
41
42
  "@lark-apaas/nestjs-authnpaas": "^1.0.0",
42
- "@lark-apaas/nestjs-datapaas": "^1.0.1",
43
+ "@lark-apaas/nestjs-datapaas": "1.0.5-alpha.0",
43
44
  "@lark-apaas/nestjs-logger": "^1.0.0",
44
- "@lark-apaas/nestjs-openapi-devtools": "^1.0.0",
45
- "cookie-parser": "^1.4.7"
45
+ "cookie-parser": "^1.4.7",
46
+ "openapi-typescript-codegen": "^0.29.0"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@nestjs/common": "^10.4.20",