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