@lark-apaas/fullstack-nestjs-core 1.0.3-alpha.7 → 1.0.3-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +119 -12
  2. package/dist/index.js +119 -12
  3. package/package.json +2 -1
package/dist/index.cjs CHANGED
@@ -367,12 +367,12 @@ var import_path = require("path");
367
367
  var import_hbs = require("hbs");
368
368
  var import_cookie_parser = __toESM(require("cookie-parser"), 1);
369
369
 
370
- // src/modules/devtool/index.ts
370
+ // src/modules/devtool-v2/index.ts
371
371
  var import_swagger = require("@nestjs/swagger");
372
- var import_node_fs2 = require("fs");
373
- var import_node_path2 = require("path");
372
+ var import_node_fs3 = require("fs");
373
+ var import_node_path3 = require("path");
374
374
 
375
- // src/modules/devtool/helper.ts
375
+ // src/modules/devtool-v2/helper.ts
376
376
  var import_node_path = require("path");
377
377
  var import_node_fs = require("fs");
378
378
  function normalizeBasePath(rawBasePath) {
@@ -409,10 +409,27 @@ function ensureDirAndWrite(filePath, content) {
409
409
  }
410
410
  __name(ensureDirAndWrite, "ensureDirAndWrite");
411
411
 
412
- // src/modules/devtool/index.ts
413
- var DevToolsModule = class {
412
+ // src/modules/devtool-v2/plugins/client-config-generator.ts
413
+ var import_node_fs2 = require("fs");
414
+ var import_node_path2 = require("path");
415
+ function generateClientConfig(options) {
416
+ const configFilePath = (0, import_node_path2.resolve)(options.outputPath, "client.config.ts");
417
+ const configContent = `// This file is auto-generated by @hey-api/openapi-ts
418
+ import axios from 'axios';
419
+ import type { CreateClientConfig } from './client';
420
+ export const createClientConfig: CreateClientConfig = (config) => ({
421
+ axios
422
+ });
423
+ `;
424
+ (0, import_node_fs2.writeFileSync)(configFilePath, configContent, "utf-8");
425
+ return configFilePath;
426
+ }
427
+ __name(generateClientConfig, "generateClientConfig");
428
+
429
+ // src/modules/devtool-v2/index.ts
430
+ var DevToolsV2Module = class {
414
431
  static {
415
- __name(this, "DevToolsModule");
432
+ __name(this, "DevToolsV2Module");
416
433
  }
417
434
  static async mount(app, opts = {}) {
418
435
  const options = resolveOptsWithDefaultValue(opts);
@@ -429,13 +446,16 @@ var DevToolsModule = class {
429
446
  });
430
447
  console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
431
448
  }
432
- const openapiPath = (0, import_node_path2.resolve)(baseDirname, options.openapiOut);
449
+ const openapiPath = (0, import_node_path3.resolve)(baseDirname, options.openapiOut);
433
450
  ensureDirAndWrite(openapiPath, JSON.stringify(document, null, 2));
434
451
  if (options.needGenerateClientSdk) {
435
- const clientSdkOutPath = (0, import_node_path2.resolve)(baseDirname, options.clientSdkOut);
436
- (0, import_node_fs2.mkdirSync)(clientSdkOutPath, {
452
+ const clientSdkOutPath = (0, import_node_path3.resolve)(baseDirname, options.clientSdkOut);
453
+ (0, import_node_fs3.mkdirSync)(clientSdkOutPath, {
437
454
  recursive: true
438
455
  });
456
+ generateClientConfig({
457
+ outputPath: clientSdkOutPath
458
+ });
439
459
  const { createClient } = await import("@hey-api/openapi-ts");
440
460
  await createClient({
441
461
  input: openapiPath,
@@ -445,7 +465,10 @@ var DevToolsModule = class {
445
465
  plugins: [
446
466
  "@hey-api/typescript",
447
467
  "@hey-api/sdk",
448
- "@hey-api/client-axios"
468
+ {
469
+ name: "@hey-api/client-axios",
470
+ runtimeConfigPath: (0, import_node_path3.join)(clientSdkOutPath, "./client.config.ts")
471
+ }
449
472
  ]
450
473
  });
451
474
  ensureDirAndWrite(openapiPath, JSON.stringify(document, null, 2));
@@ -465,7 +488,7 @@ async function configureApp(app, options) {
465
488
  app.setViewEngine("html");
466
489
  app.engine("html", import_hbs.__express);
467
490
  if (process.env.NODE_ENV !== "production") {
468
- await DevToolsModule.mount(app, {
491
+ await DevToolsV2Module.mount(app, {
469
492
  basePath: process.env.CLIENT_BASE_PATH,
470
493
  docsPath: "/api_docs"
471
494
  });
@@ -473,6 +496,90 @@ async function configureApp(app, options) {
473
496
  }
474
497
  __name(configureApp, "configureApp");
475
498
 
499
+ // src/modules/devtool/index.ts
500
+ var import_swagger2 = require("@nestjs/swagger");
501
+ var import_node_fs5 = require("fs");
502
+ var import_node_path5 = require("path");
503
+
504
+ // src/modules/devtool/helper.ts
505
+ var import_node_path4 = require("path");
506
+ var import_node_fs4 = require("fs");
507
+ function normalizeBasePath2(rawBasePath) {
508
+ const normalizedBasePath = rawBasePath.startsWith("/") ? rawBasePath : `/${rawBasePath}`;
509
+ return normalizedBasePath.endsWith("/") ? normalizedBasePath.slice(0, -1) : normalizedBasePath;
510
+ }
511
+ __name(normalizeBasePath2, "normalizeBasePath");
512
+ function resolveOptsWithDefaultValue2(options) {
513
+ const basePath = normalizeBasePath2(options.basePath || "/");
514
+ const docsPath = normalizeBasePath2(options.docsPath || `api/docs`);
515
+ return {
516
+ ...options,
517
+ needSetupServer: options.needSetupServer ?? false,
518
+ basePath,
519
+ docsPath: `${basePath}${docsPath}`,
520
+ openapiOut: options.openapiOut || "./client/src/api/gen/openapi.json",
521
+ clientSdkOut: options.clientSdkOut || "./client/src/api/gen",
522
+ needGenerateClientSdk: options.needGenerateClientSdk ?? true,
523
+ swaggerOptions: {
524
+ title: options.swaggerOptions?.title ?? "NestJS Fullstack API",
525
+ version: options.swaggerOptions?.version ?? "1.0.0",
526
+ customSiteTitle: options.swaggerOptions?.customSiteTitle ?? "API Documentation",
527
+ customCss: options.swaggerOptions?.customCss ?? ".swagger-ui .topbar { display: none }"
528
+ }
529
+ };
530
+ }
531
+ __name(resolveOptsWithDefaultValue2, "resolveOptsWithDefaultValue");
532
+ function ensureDirAndWrite2(filePath, content) {
533
+ const dir = (0, import_node_path4.dirname)(filePath);
534
+ (0, import_node_fs4.mkdirSync)(dir, {
535
+ recursive: true
536
+ });
537
+ (0, import_node_fs4.writeFileSync)(filePath, content);
538
+ }
539
+ __name(ensureDirAndWrite2, "ensureDirAndWrite");
540
+
541
+ // src/modules/devtool/index.ts
542
+ var DevToolsModule = class {
543
+ static {
544
+ __name(this, "DevToolsModule");
545
+ }
546
+ static async mount(app, opts = {}) {
547
+ const options = resolveOptsWithDefaultValue2(opts);
548
+ const baseDirname = process.cwd();
549
+ const builder = new import_swagger2.DocumentBuilder().setTitle(options.swaggerOptions.title).setVersion(options.swaggerOptions.version);
550
+ const document = import_swagger2.SwaggerModule.createDocument(app, builder.build(), {
551
+ operationIdFactory: /* @__PURE__ */ __name((_c, m) => m, "operationIdFactory")
552
+ });
553
+ if (options.needSetupServer) {
554
+ import_swagger2.SwaggerModule.setup(options.docsPath, app, document, {
555
+ customSiteTitle: options.swaggerOptions.customSiteTitle,
556
+ customCss: options.swaggerOptions.customCss,
557
+ swaggerOptions: {
558
+ persistAuthorization: true
559
+ }
560
+ });
561
+ console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
562
+ }
563
+ const openapiPath = (0, import_node_path5.resolve)(baseDirname, options.openapiOut);
564
+ ensureDirAndWrite2(openapiPath, JSON.stringify(document, null, 2));
565
+ if (options.needGenerateClientSdk) {
566
+ const clientSdkOutPath = (0, import_node_path5.resolve)(baseDirname, options.clientSdkOut);
567
+ (0, import_node_fs5.mkdirSync)(clientSdkOutPath, {
568
+ recursive: true
569
+ });
570
+ const { generate } = await import("openapi-typescript-codegen");
571
+ await generate({
572
+ input: openapiPath,
573
+ output: clientSdkOutPath,
574
+ httpClient: "axios",
575
+ useOptions: false,
576
+ exportServices: true
577
+ });
578
+ console.log("[OpenAPI] \u5BFC\u51FA openapi.json \u5E76\u751F\u6210 axios SDK \u2705");
579
+ }
580
+ }
581
+ };
582
+
476
583
  // src/index.ts
477
584
  __reExport(index_exports, require("@lark-apaas/nestjs-authnpaas"), module.exports);
478
585
  __reExport(index_exports, require("@lark-apaas/nestjs-datapaas"), module.exports);
package/dist/index.js CHANGED
@@ -322,16 +322,16 @@ PlatformModule = _ts_decorate5([
322
322
 
323
323
  // src/setup.ts
324
324
  import { AppLogger as AppLogger2 } from "@lark-apaas/nestjs-logger";
325
- import { join } from "path";
325
+ import { join as join2 } from "path";
326
326
  import { __express as hbsExpressEngine } from "hbs";
327
327
  import cookieParser from "cookie-parser";
328
328
 
329
- // src/modules/devtool/index.ts
329
+ // src/modules/devtool-v2/index.ts
330
330
  import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
331
331
  import { mkdirSync as mkdirSync2 } from "fs";
332
- import { resolve } from "path";
332
+ import { resolve as resolve2, join } from "path";
333
333
 
334
- // src/modules/devtool/helper.ts
334
+ // src/modules/devtool-v2/helper.ts
335
335
  import { dirname } from "path";
336
336
  import { writeFileSync, mkdirSync } from "fs";
337
337
  function normalizeBasePath(rawBasePath) {
@@ -368,10 +368,27 @@ function ensureDirAndWrite(filePath, content) {
368
368
  }
369
369
  __name(ensureDirAndWrite, "ensureDirAndWrite");
370
370
 
371
- // src/modules/devtool/index.ts
372
- var DevToolsModule = class {
371
+ // src/modules/devtool-v2/plugins/client-config-generator.ts
372
+ import { writeFileSync as writeFileSync2 } from "fs";
373
+ import { resolve } from "path";
374
+ function generateClientConfig(options) {
375
+ const configFilePath = resolve(options.outputPath, "client.config.ts");
376
+ const configContent = `// This file is auto-generated by @hey-api/openapi-ts
377
+ import axios from 'axios';
378
+ import type { CreateClientConfig } from './client';
379
+ export const createClientConfig: CreateClientConfig = (config) => ({
380
+ axios
381
+ });
382
+ `;
383
+ writeFileSync2(configFilePath, configContent, "utf-8");
384
+ return configFilePath;
385
+ }
386
+ __name(generateClientConfig, "generateClientConfig");
387
+
388
+ // src/modules/devtool-v2/index.ts
389
+ var DevToolsV2Module = class {
373
390
  static {
374
- __name(this, "DevToolsModule");
391
+ __name(this, "DevToolsV2Module");
375
392
  }
376
393
  static async mount(app, opts = {}) {
377
394
  const options = resolveOptsWithDefaultValue(opts);
@@ -388,13 +405,16 @@ var DevToolsModule = class {
388
405
  });
389
406
  console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
390
407
  }
391
- const openapiPath = resolve(baseDirname, options.openapiOut);
408
+ const openapiPath = resolve2(baseDirname, options.openapiOut);
392
409
  ensureDirAndWrite(openapiPath, JSON.stringify(document, null, 2));
393
410
  if (options.needGenerateClientSdk) {
394
- const clientSdkOutPath = resolve(baseDirname, options.clientSdkOut);
411
+ const clientSdkOutPath = resolve2(baseDirname, options.clientSdkOut);
395
412
  mkdirSync2(clientSdkOutPath, {
396
413
  recursive: true
397
414
  });
415
+ generateClientConfig({
416
+ outputPath: clientSdkOutPath
417
+ });
398
418
  const { createClient } = await import("@hey-api/openapi-ts");
399
419
  await createClient({
400
420
  input: openapiPath,
@@ -404,7 +424,10 @@ var DevToolsModule = class {
404
424
  plugins: [
405
425
  "@hey-api/typescript",
406
426
  "@hey-api/sdk",
407
- "@hey-api/client-axios"
427
+ {
428
+ name: "@hey-api/client-axios",
429
+ runtimeConfigPath: join(clientSdkOutPath, "./client.config.ts")
430
+ }
408
431
  ]
409
432
  });
410
433
  ensureDirAndWrite(openapiPath, JSON.stringify(document, null, 2));
@@ -420,11 +443,11 @@ async function configureApp(app, options) {
420
443
  app.use(cookieParser());
421
444
  const globalPrefix = process.env.CLIENT_BASE_PATH ?? "";
422
445
  app.setGlobalPrefix(globalPrefix);
423
- app.setBaseViewsDir(join(process.cwd(), options?.viewsDir ?? "dist/client"));
446
+ app.setBaseViewsDir(join2(process.cwd(), options?.viewsDir ?? "dist/client"));
424
447
  app.setViewEngine("html");
425
448
  app.engine("html", hbsExpressEngine);
426
449
  if (process.env.NODE_ENV !== "production") {
427
- await DevToolsModule.mount(app, {
450
+ await DevToolsV2Module.mount(app, {
428
451
  basePath: process.env.CLIENT_BASE_PATH,
429
452
  docsPath: "/api_docs"
430
453
  });
@@ -432,6 +455,90 @@ async function configureApp(app, options) {
432
455
  }
433
456
  __name(configureApp, "configureApp");
434
457
 
458
+ // src/modules/devtool/index.ts
459
+ import { SwaggerModule as SwaggerModule2, DocumentBuilder as DocumentBuilder2 } from "@nestjs/swagger";
460
+ import { mkdirSync as mkdirSync4 } from "fs";
461
+ import { resolve as resolve3 } from "path";
462
+
463
+ // src/modules/devtool/helper.ts
464
+ import { dirname as dirname2 } from "path";
465
+ import { writeFileSync as writeFileSync3, mkdirSync as mkdirSync3 } from "fs";
466
+ function normalizeBasePath2(rawBasePath) {
467
+ const normalizedBasePath = rawBasePath.startsWith("/") ? rawBasePath : `/${rawBasePath}`;
468
+ return normalizedBasePath.endsWith("/") ? normalizedBasePath.slice(0, -1) : normalizedBasePath;
469
+ }
470
+ __name(normalizeBasePath2, "normalizeBasePath");
471
+ function resolveOptsWithDefaultValue2(options) {
472
+ const basePath = normalizeBasePath2(options.basePath || "/");
473
+ const docsPath = normalizeBasePath2(options.docsPath || `api/docs`);
474
+ return {
475
+ ...options,
476
+ needSetupServer: options.needSetupServer ?? false,
477
+ basePath,
478
+ docsPath: `${basePath}${docsPath}`,
479
+ openapiOut: options.openapiOut || "./client/src/api/gen/openapi.json",
480
+ clientSdkOut: options.clientSdkOut || "./client/src/api/gen",
481
+ needGenerateClientSdk: options.needGenerateClientSdk ?? true,
482
+ swaggerOptions: {
483
+ title: options.swaggerOptions?.title ?? "NestJS Fullstack API",
484
+ version: options.swaggerOptions?.version ?? "1.0.0",
485
+ customSiteTitle: options.swaggerOptions?.customSiteTitle ?? "API Documentation",
486
+ customCss: options.swaggerOptions?.customCss ?? ".swagger-ui .topbar { display: none }"
487
+ }
488
+ };
489
+ }
490
+ __name(resolveOptsWithDefaultValue2, "resolveOptsWithDefaultValue");
491
+ function ensureDirAndWrite2(filePath, content) {
492
+ const dir = dirname2(filePath);
493
+ mkdirSync3(dir, {
494
+ recursive: true
495
+ });
496
+ writeFileSync3(filePath, content);
497
+ }
498
+ __name(ensureDirAndWrite2, "ensureDirAndWrite");
499
+
500
+ // src/modules/devtool/index.ts
501
+ var DevToolsModule = class {
502
+ static {
503
+ __name(this, "DevToolsModule");
504
+ }
505
+ static async mount(app, opts = {}) {
506
+ const options = resolveOptsWithDefaultValue2(opts);
507
+ const baseDirname = process.cwd();
508
+ const builder = new DocumentBuilder2().setTitle(options.swaggerOptions.title).setVersion(options.swaggerOptions.version);
509
+ const document = SwaggerModule2.createDocument(app, builder.build(), {
510
+ operationIdFactory: /* @__PURE__ */ __name((_c, m) => m, "operationIdFactory")
511
+ });
512
+ if (options.needSetupServer) {
513
+ SwaggerModule2.setup(options.docsPath, app, document, {
514
+ customSiteTitle: options.swaggerOptions.customSiteTitle,
515
+ customCss: options.swaggerOptions.customCss,
516
+ swaggerOptions: {
517
+ persistAuthorization: true
518
+ }
519
+ });
520
+ console.log(`[OpenAPI] Swagger UI \u5DF2\u6302\u8F7D\u81F3 ${options.docsPath}`);
521
+ }
522
+ const openapiPath = resolve3(baseDirname, options.openapiOut);
523
+ ensureDirAndWrite2(openapiPath, JSON.stringify(document, null, 2));
524
+ if (options.needGenerateClientSdk) {
525
+ const clientSdkOutPath = resolve3(baseDirname, options.clientSdkOut);
526
+ mkdirSync4(clientSdkOutPath, {
527
+ recursive: true
528
+ });
529
+ const { generate } = await import("openapi-typescript-codegen");
530
+ await generate({
531
+ input: openapiPath,
532
+ output: clientSdkOutPath,
533
+ httpClient: "axios",
534
+ useOptions: false,
535
+ exportServices: true
536
+ });
537
+ console.log("[OpenAPI] \u5BFC\u51FA openapi.json \u5E76\u751F\u6210 axios SDK \u2705");
538
+ }
539
+ }
540
+ };
541
+
435
542
  // src/index.ts
436
543
  export * from "@lark-apaas/nestjs-authnpaas";
437
544
  export * from "@lark-apaas/nestjs-datapaas";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-nestjs-core",
3
- "version": "1.0.3-alpha.7",
3
+ "version": "1.0.3-alpha.9",
4
4
  "description": "FullStack Nestjs Core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -41,6 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@hey-api/openapi-ts": "^0.86.11",
44
+ "openapi-typescript-codegen": "^0.29.0",
44
45
  "@lark-apaas/nestjs-authnpaas": "^1.0.0",
45
46
  "@lark-apaas/nestjs-datapaas": "^1.0.1",
46
47
  "@lark-apaas/nestjs-logger": "^1.0.0",