@devbro/pashmak 0.1.48 → 0.1.49
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/DatabaseServiceProvider.d.mts +4 -1
- package/dist/DatabaseServiceProvider.mjs +5 -2
- package/dist/DatabaseServiceProvider.mjs.map +1 -1
- package/dist/app/console/StartCommand.d.mts +1 -0
- package/dist/app/console/StartCommand.mjs +5 -2
- package/dist/app/console/StartCommand.mjs.map +1 -1
- package/dist/app/console/generate/GenerateApiDocsCommand.d.mts +34 -2
- package/dist/app/console/generate/GenerateApiDocsCommand.mjs +183 -100
- package/dist/app/console/generate/GenerateApiDocsCommand.mjs.map +1 -1
- package/dist/app/console/project/base_project/src/config/storages.ts.tpl +2 -2
- package/dist/bin/DatabaseServiceProvider.cjs +8 -2
- package/dist/bin/app/console/DefaultCommand.cjs +45 -17
- package/dist/bin/app/console/KeyGenerateCommand.cjs +45 -17
- package/dist/bin/app/console/StartCommand.cjs +50 -19
- package/dist/bin/app/console/generate/GenerateApiDocsCommand.cjs +229 -118
- package/dist/bin/app/console/generate/GenerateControllerCommand.cjs +45 -17
- package/dist/bin/app/console/generate/index.cjs +229 -118
- package/dist/bin/app/console/index.cjs +234 -120
- package/dist/bin/app/console/migrate/GenerateMigrateCommand.cjs +45 -17
- package/dist/bin/app/console/migrate/MigrateCommand.cjs +45 -17
- package/dist/bin/app/console/migrate/MigrateRollbackCommand.cjs +45 -17
- package/dist/bin/app/console/migrate/index.cjs +45 -17
- package/dist/bin/app/console/queue/GenerateQueueMigrateCommand.cjs +45 -17
- package/dist/bin/cache.cjs +45 -17
- package/dist/bin/facades.cjs +45 -17
- package/dist/bin/factories.cjs +45 -17
- package/dist/bin/http.cjs +45 -17
- package/dist/bin/index.cjs +243 -126
- package/dist/bin/middlewares.cjs +45 -17
- package/dist/bin/queue.cjs +45 -17
- package/dist/bin/router.cjs +3 -5
- package/dist/factories.mjs +45 -2
- package/dist/factories.mjs.map +1 -1
- package/dist/http.mjs +1 -1
- package/dist/http.mjs.map +1 -1
- package/dist/queue.d.mts +1 -1
- package/dist/queue.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -77,6 +77,7 @@ var MiddlewareFactory = class {
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
// ../neko-router/dist/CompiledRoute.mjs
|
|
80
|
+
var import_neko_helper = require("@devbro/neko-helper");
|
|
80
81
|
var CompiledRoute = class {
|
|
81
82
|
static {
|
|
82
83
|
__name(this, "CompiledRoute");
|
|
@@ -97,7 +98,7 @@ var CompiledRoute = class {
|
|
|
97
98
|
for (const middleware of [...this.globalMiddlewares, ...this.route.getMiddlewares()]) {
|
|
98
99
|
if (middleware instanceof Middleware) {
|
|
99
100
|
this.middlewares.push(middleware);
|
|
100
|
-
} else if (
|
|
101
|
+
} else if ((0, import_neko_helper.isClass)(middleware)) {
|
|
101
102
|
this.middlewares.push(middleware.getInstance({}));
|
|
102
103
|
} else if (typeof middleware === "function") {
|
|
103
104
|
this.middlewares.push(MiddlewareFactory.create(middleware));
|
|
@@ -106,9 +107,6 @@ var CompiledRoute = class {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
isClass(func) {
|
|
110
|
-
return typeof func === "function" && /^class\s/.test(Function.prototype.toString.call(func));
|
|
111
|
-
}
|
|
112
110
|
async run() {
|
|
113
111
|
return await this.runMiddlewares(this.middlewares, this.request, this.response);
|
|
114
112
|
}
|
|
@@ -244,7 +242,7 @@ var Route = class {
|
|
|
244
242
|
i = start;
|
|
245
243
|
} else if (char === "*") {
|
|
246
244
|
let start = i + 1;
|
|
247
|
-
while (start < path3.length && /[a-zA-Z0-9_
|
|
245
|
+
while (start < path3.length && /[a-zA-Z0-9_]/.test(path3[start])) {
|
|
248
246
|
start++;
|
|
249
247
|
}
|
|
250
248
|
tokens.push({ type: "WILDCARD", value: path3.slice(i + 1, start) });
|
|
@@ -455,7 +453,7 @@ var Router = class {
|
|
|
455
453
|
|
|
456
454
|
// src/facades.mts
|
|
457
455
|
var import_neko_scheduler = require("@devbro/neko-scheduler");
|
|
458
|
-
var
|
|
456
|
+
var import_neko_helper3 = require("@devbro/neko-helper");
|
|
459
457
|
var import_neko_context3 = require("@devbro/neko-context");
|
|
460
458
|
var import_neko_storage2 = require("@devbro/neko-storage");
|
|
461
459
|
var import_neko_mailer2 = require("@devbro/neko-mailer");
|
|
@@ -496,7 +494,7 @@ __export(queue_exports, {
|
|
|
496
494
|
DatabaseTransport: () => DatabaseTransport
|
|
497
495
|
});
|
|
498
496
|
__reExport(queue_exports, require("@devbro/neko-queue"));
|
|
499
|
-
var
|
|
497
|
+
var import_neko_helper2 = require("@devbro/neko-helper");
|
|
500
498
|
var import_neko_context2 = require("@devbro/neko-context");
|
|
501
499
|
var DatabaseTransport = class {
|
|
502
500
|
static {
|
|
@@ -557,7 +555,7 @@ var DatabaseTransport = class {
|
|
|
557
555
|
}, "processMessage");
|
|
558
556
|
constructor(config3 = {}) {
|
|
559
557
|
this.config = { ...this.config, ...config3 };
|
|
560
|
-
this.repeater = (0,
|
|
558
|
+
this.repeater = (0, import_neko_helper2.createRepeater)(
|
|
561
559
|
this.processMessage,
|
|
562
560
|
this.config.listen_interval * 1e3
|
|
563
561
|
);
|
|
@@ -625,6 +623,24 @@ import_neko_queue.QueueTransportFactory.register("database", (opt) => {
|
|
|
625
623
|
import_neko_queue.QueueTransportFactory.register("memory", (opt) => {
|
|
626
624
|
return new import_neko_queue.MemoryTransport(opt);
|
|
627
625
|
});
|
|
626
|
+
import_neko_queue.QueueTransportFactory.register("sqs", (opt) => {
|
|
627
|
+
return new import_neko_queue.AwsSqsTransport(opt);
|
|
628
|
+
});
|
|
629
|
+
import_neko_queue.QueueTransportFactory.register("amqp", (opt) => {
|
|
630
|
+
return new import_neko_queue.AmqpTransport(opt);
|
|
631
|
+
});
|
|
632
|
+
import_neko_queue.QueueTransportFactory.register("redis", (opt) => {
|
|
633
|
+
return new import_neko_queue.RedisTransport(opt);
|
|
634
|
+
});
|
|
635
|
+
import_neko_queue.QueueTransportFactory.register("async", (opt) => {
|
|
636
|
+
return new import_neko_queue.AsyncTransport();
|
|
637
|
+
});
|
|
638
|
+
import_neko_queue.QueueTransportFactory.register("azure_service_bus", (opt) => {
|
|
639
|
+
return new import_neko_queue.AzureServiceBusTransport(opt);
|
|
640
|
+
});
|
|
641
|
+
import_neko_queue.QueueTransportFactory.register("google_pubsub", (opt) => {
|
|
642
|
+
return new import_neko_queue.GooglePubSubTransport(opt);
|
|
643
|
+
});
|
|
628
644
|
var CacheProviderFactory = class _CacheProviderFactory {
|
|
629
645
|
static {
|
|
630
646
|
__name(this, "CacheProviderFactory");
|
|
@@ -655,12 +671,24 @@ import_neko_storage.StorageProviderFactory.register("local", (opt) => {
|
|
|
655
671
|
import_neko_storage.StorageProviderFactory.register("s3", (opt) => {
|
|
656
672
|
return new import_neko_storage.AWSS3StorageProvider(opt);
|
|
657
673
|
});
|
|
674
|
+
import_neko_storage.StorageProviderFactory.register("gcp", (opt) => {
|
|
675
|
+
return new import_neko_storage.GCPStorageProvider(opt);
|
|
676
|
+
});
|
|
677
|
+
import_neko_storage.StorageProviderFactory.register("azure", (opt) => {
|
|
678
|
+
return new import_neko_storage.AzureBlobStorageProvider(opt);
|
|
679
|
+
});
|
|
680
|
+
import_neko_storage.StorageProviderFactory.register("ftp", (opt) => {
|
|
681
|
+
return new import_neko_storage.FTPStorageProvider(opt);
|
|
682
|
+
});
|
|
683
|
+
import_neko_storage.StorageProviderFactory.register("sftp", (opt) => {
|
|
684
|
+
return new import_neko_storage.SFTPStorageProvider(opt);
|
|
685
|
+
});
|
|
658
686
|
|
|
659
687
|
// src/facades.mts
|
|
660
688
|
var import_neko_cache2 = require("@devbro/neko-cache");
|
|
661
689
|
var import_neko_queue2 = require("@devbro/neko-queue");
|
|
662
|
-
var router = (0,
|
|
663
|
-
var scheduler = (0,
|
|
690
|
+
var router = (0, import_neko_helper3.createSingleton)(() => new Router());
|
|
691
|
+
var scheduler = (0, import_neko_helper3.createSingleton)(() => {
|
|
664
692
|
const rc = new import_neko_scheduler.Scheduler();
|
|
665
693
|
rc.setErrorHandler((err, job) => {
|
|
666
694
|
logger().error({
|
|
@@ -672,7 +700,7 @@ var scheduler = (0, import_neko_helper2.createSingleton)(() => {
|
|
|
672
700
|
return rc;
|
|
673
701
|
});
|
|
674
702
|
var db = /* @__PURE__ */ __name((label = "default") => (0, import_neko_context3.ctx)().getOrThrow(["database", label]), "db");
|
|
675
|
-
var storage = (0,
|
|
703
|
+
var storage = (0, import_neko_helper3.createSingleton)((label = "default") => {
|
|
676
704
|
let storage_config = import_neko_config.config.get(["storages", label].join("."));
|
|
677
705
|
const provider = import_neko_storage2.StorageProviderFactory.create(
|
|
678
706
|
storage_config.provider,
|
|
@@ -680,7 +708,7 @@ var storage = (0, import_neko_helper2.createSingleton)((label = "default") => {
|
|
|
680
708
|
);
|
|
681
709
|
return new import_neko_storage2.Storage(provider);
|
|
682
710
|
});
|
|
683
|
-
var cli = (0,
|
|
711
|
+
var cli = (0, import_neko_helper3.createSingleton)(() => {
|
|
684
712
|
const [node, app, ...args] = process.argv;
|
|
685
713
|
return new import_clipanion.Cli({
|
|
686
714
|
binaryLabel: `My Application`,
|
|
@@ -688,13 +716,13 @@ var cli = (0, import_neko_helper2.createSingleton)(() => {
|
|
|
688
716
|
binaryVersion: `1.0.0`
|
|
689
717
|
});
|
|
690
718
|
});
|
|
691
|
-
var httpServer = (0,
|
|
719
|
+
var httpServer = (0, import_neko_helper3.createSingleton)(() => {
|
|
692
720
|
const server = new http_exports.HttpServer();
|
|
693
721
|
server.setErrorHandler(handleHttpErrors);
|
|
694
722
|
server.setRouter(router());
|
|
695
723
|
return server;
|
|
696
724
|
});
|
|
697
|
-
var logger = (0,
|
|
725
|
+
var logger = (0, import_neko_helper3.createSingleton)((label) => {
|
|
698
726
|
const logger_config = import_neko_config.config.get(["loggers", label].join("."));
|
|
699
727
|
const rc = new import_neko_logger.Logger(logger_config);
|
|
700
728
|
rc.setExtrasFunction((message) => {
|
|
@@ -703,7 +731,7 @@ var logger = (0, import_neko_helper2.createSingleton)((label) => {
|
|
|
703
731
|
});
|
|
704
732
|
return rc;
|
|
705
733
|
});
|
|
706
|
-
var mailer = (0,
|
|
734
|
+
var mailer = (0, import_neko_helper3.createSingleton)((label) => {
|
|
707
735
|
const mailer_config = import_neko_config.config.get(["mailer", label].join("."));
|
|
708
736
|
const provider = import_neko_mailer2.MailerProviderFactory.create(
|
|
709
737
|
mailer_config.provider,
|
|
@@ -712,7 +740,7 @@ var mailer = (0, import_neko_helper2.createSingleton)((label) => {
|
|
|
712
740
|
const rc = new import_neko_mailer2.Mailer(provider);
|
|
713
741
|
return rc;
|
|
714
742
|
});
|
|
715
|
-
var queue = (0,
|
|
743
|
+
var queue = (0, import_neko_helper3.createSingleton)((label) => {
|
|
716
744
|
const queue_config = import_neko_config.config.get(["queues", label].join("."));
|
|
717
745
|
if (!queue_config) {
|
|
718
746
|
throw new Error(`Queue configuration for '${label}' not found`);
|
|
@@ -723,7 +751,7 @@ var queue = (0, import_neko_helper2.createSingleton)((label) => {
|
|
|
723
751
|
);
|
|
724
752
|
return new import_neko_queue2.QueueConnection(provider);
|
|
725
753
|
});
|
|
726
|
-
var cache = (0,
|
|
754
|
+
var cache = (0, import_neko_helper3.createSingleton)((label) => {
|
|
727
755
|
const cache_config = import_neko_config.config.get(["caches", label].join("."));
|
|
728
756
|
if (!cache_config) {
|
|
729
757
|
throw new Error(`Cache configuration for '${label}' not found`);
|
|
@@ -745,144 +773,155 @@ var config_exports = {};
|
|
|
745
773
|
__reExport(config_exports, require("@devbro/neko-config"));
|
|
746
774
|
|
|
747
775
|
// src/app/console/generate/GenerateApiDocsCommand.mts
|
|
748
|
-
var
|
|
776
|
+
var import_neko_helper4 = require("@devbro/neko-helper");
|
|
749
777
|
var GenerateApiDocsCommand = class extends import_clipanion2.Command {
|
|
750
778
|
static {
|
|
751
779
|
__name(this, "GenerateApiDocsCommand");
|
|
752
780
|
}
|
|
753
|
-
static paths = [
|
|
754
|
-
[`make`, `apidocs`],
|
|
755
|
-
[`generate`, `apidocs`]
|
|
756
|
-
];
|
|
781
|
+
static paths = [[`generate`, `apidocsv2`]];
|
|
757
782
|
static usage = import_clipanion2.Command.Usage({
|
|
758
783
|
category: `Generate`,
|
|
759
784
|
description: `Generate OpenAPI documentation from routes`,
|
|
760
785
|
details: `
|
|
761
|
-
This command generates OpenAPI 3.0 specification documentation by analyzing
|
|
786
|
+
This command utility generates OpenAPI 3.0 specification documentation by analyzing
|
|
762
787
|
your application's routes and merging with example files.
|
|
763
788
|
|
|
764
|
-
|
|
765
|
-
-
|
|
766
|
-
-
|
|
767
|
-
-
|
|
768
|
-
- Response schemas
|
|
769
|
-
|
|
770
|
-
The command will merge files specified in config.api_docs.merge_files
|
|
771
|
-
and output the final documentation to config.api_docs.output.
|
|
789
|
+
Subcommands:
|
|
790
|
+
- generate-from-routes: Generate OpenAPI spec from registered routes
|
|
791
|
+
- generate-base: Generate base OpenAPI specification structure
|
|
792
|
+
- merge-files: Merge multiple OpenAPI files into final documentation
|
|
772
793
|
|
|
794
|
+
|
|
773
795
|
This command depends on config data. make sure your default config contains the following:
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
796
|
+
|
|
797
|
+
\`\`\`
|
|
798
|
+
api_docs: {
|
|
799
|
+
|
|
800
|
+
merge_files: [
|
|
801
|
+
|
|
802
|
+
path.join(__dirname, '../..', 'private', 'openapi_base.json'),
|
|
803
|
+
|
|
804
|
+
path.join(__dirname, '../..', 'private', 'openapi_from_routes.json'),
|
|
805
|
+
|
|
806
|
+
path.join(__dirname, '../..', 'private', 'openapi_from_tests.json'),
|
|
807
|
+
|
|
808
|
+
path.join(__dirname, '../..', 'private', 'openapi_other_user_changes.json'),
|
|
809
|
+
|
|
810
|
+
],
|
|
811
|
+
|
|
812
|
+
output: path.join(__dirname, '../..', 'public', 'openapi.json'),
|
|
813
|
+
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
\`\`\`
|
|
782
817
|
`,
|
|
783
|
-
examples: [
|
|
818
|
+
examples: [
|
|
819
|
+
[
|
|
820
|
+
`Generate from routes`,
|
|
821
|
+
`$0 generate apidocsv2 generate-from-routes --output path/to/output.json`
|
|
822
|
+
],
|
|
823
|
+
[
|
|
824
|
+
`Generate base spec`,
|
|
825
|
+
`$0 generate apidocsv2 generate-base --output path/to/output.json`
|
|
826
|
+
],
|
|
827
|
+
[`Merge files`, `$0 generate apidocsv2 merge-files`],
|
|
828
|
+
[`Show help`, `$0 generate apidocsv2 --help`]
|
|
829
|
+
]
|
|
830
|
+
});
|
|
831
|
+
subcommand = import_clipanion2.Option.String({ required: false });
|
|
832
|
+
output = import_clipanion2.Option.String(`--output,-o`, {
|
|
833
|
+
description: `Output file path for generated documentation`
|
|
784
834
|
});
|
|
785
|
-
|
|
786
|
-
description: `
|
|
835
|
+
config = import_clipanion2.Option.String(`--config,-c`, {
|
|
836
|
+
description: `Path in config to get details from (default: api_docs)`,
|
|
837
|
+
required: false
|
|
787
838
|
});
|
|
788
839
|
async execute() {
|
|
789
|
-
if (this.
|
|
840
|
+
if (!this.subcommand) {
|
|
790
841
|
this.context.stdout.write(
|
|
791
842
|
this.constructor.usage?.toString() || "No help available\n"
|
|
792
843
|
);
|
|
793
844
|
return 0;
|
|
794
845
|
}
|
|
795
|
-
|
|
796
|
-
|
|
846
|
+
switch (this.subcommand) {
|
|
847
|
+
case "generate-from-routes":
|
|
848
|
+
return await this.executeGenerateFromRoutes();
|
|
849
|
+
case "generate-base":
|
|
850
|
+
return await this.executeGenerateBase();
|
|
851
|
+
case "merge-files":
|
|
852
|
+
return await this.executeMergeFiles();
|
|
853
|
+
default:
|
|
854
|
+
this.context.stderr.write(`Unknown subcommand: ${this.subcommand}
|
|
797
855
|
`);
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
title: "API Documentation",
|
|
803
|
-
version: "1.0.0",
|
|
804
|
-
description: "Auto-generated API documentation"
|
|
805
|
-
},
|
|
806
|
-
servers: [
|
|
807
|
-
{
|
|
808
|
-
url: "/",
|
|
809
|
-
description: "Local server"
|
|
810
|
-
}
|
|
811
|
-
],
|
|
812
|
-
paths: {}
|
|
813
|
-
};
|
|
814
|
-
for (const route of routes) {
|
|
815
|
-
const routePath = route.path;
|
|
816
|
-
const openApiPath = routePath.replace(/:([a-zA-Z0-9_]+)/g, "{$1}");
|
|
817
|
-
if (!openApiSpec.paths[openApiPath]) {
|
|
818
|
-
openApiSpec.paths[openApiPath] = {};
|
|
819
|
-
}
|
|
820
|
-
for (const method of route.methods) {
|
|
821
|
-
const lowerMethod = method.toLowerCase();
|
|
822
|
-
if (lowerMethod === "head") {
|
|
823
|
-
continue;
|
|
824
|
-
}
|
|
825
|
-
openApiSpec.paths[openApiPath][lowerMethod] = {
|
|
826
|
-
summary: `${method} ${routePath}`,
|
|
827
|
-
description: `Endpoint for ${method} ${routePath}`,
|
|
828
|
-
parameters: this.extractParameters(routePath),
|
|
829
|
-
responses: {
|
|
830
|
-
"200": {
|
|
831
|
-
description: "Successful response",
|
|
832
|
-
content: {
|
|
833
|
-
"application/json": {
|
|
834
|
-
schema: {
|
|
835
|
-
type: "object"
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
},
|
|
840
|
-
"500": {
|
|
841
|
-
description: "Internal server error"
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
};
|
|
845
|
-
if (["post", "put", "patch"].includes(lowerMethod)) {
|
|
846
|
-
openApiSpec.paths[openApiPath][lowerMethod].requestBody = {
|
|
847
|
-
required: true,
|
|
848
|
-
content: {
|
|
849
|
-
"application/json": {
|
|
850
|
-
schema: {
|
|
851
|
-
type: "object"
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
}
|
|
857
|
-
}
|
|
856
|
+
this.context.stdout.write(
|
|
857
|
+
this.constructor.usage?.toString() || "No help available\n"
|
|
858
|
+
);
|
|
859
|
+
return 1;
|
|
858
860
|
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
+
}
|
|
862
|
+
async executeGenerateFromRoutes() {
|
|
863
|
+
this.context.stdout.write(
|
|
864
|
+
`Generating OpenAPI documentation from routes...
|
|
865
|
+
`
|
|
866
|
+
);
|
|
867
|
+
const openApiSpec = this.generateFromRoutes();
|
|
868
|
+
const outputPath = this.output || import_path2.default.join(config_exports.config.get("private_path"), "openapi_from_routes.json");
|
|
869
|
+
await fs.mkdir(import_path2.default.dirname(outputPath), { recursive: true });
|
|
861
870
|
await fs.writeFile(
|
|
862
871
|
outputPath,
|
|
863
872
|
JSON.stringify(openApiSpec, null, 2),
|
|
864
873
|
"utf-8"
|
|
865
874
|
);
|
|
866
875
|
this.context.stdout.write(
|
|
867
|
-
`OpenAPI documentation generated at: ${outputPath}
|
|
876
|
+
`OpenAPI routes documentation generated at: ${outputPath}
|
|
877
|
+
`
|
|
878
|
+
);
|
|
879
|
+
this.context.stdout.write(
|
|
880
|
+
`Total routes documented: ${Object.keys(openApiSpec.paths).length}
|
|
868
881
|
`
|
|
869
882
|
);
|
|
870
|
-
|
|
883
|
+
return 0;
|
|
884
|
+
}
|
|
885
|
+
async executeGenerateBase() {
|
|
886
|
+
this.context.stdout.write(`Generating base OpenAPI specification...
|
|
887
|
+
`);
|
|
888
|
+
const baseSpec = this.getBaseOpenApiSpec();
|
|
889
|
+
const outputPath = this.output || import_path2.default.join(config_exports.config.get("private_path"), "openapi_base.json");
|
|
890
|
+
await fs.mkdir(import_path2.default.dirname(outputPath), { recursive: true });
|
|
891
|
+
await fs.writeFile(outputPath, JSON.stringify(baseSpec, null, 2), "utf-8");
|
|
892
|
+
this.context.stdout.write(
|
|
893
|
+
`Base OpenAPI specification generated at: ${outputPath}
|
|
894
|
+
`
|
|
895
|
+
);
|
|
896
|
+
return 0;
|
|
897
|
+
}
|
|
898
|
+
async executeMergeFiles() {
|
|
899
|
+
this.context.stdout.write(`Merging OpenAPI files...
|
|
871
900
|
`);
|
|
872
|
-
let
|
|
901
|
+
let configPath = this.config || "api_docs";
|
|
902
|
+
const files_to_merge = config_exports.config.get(`${configPath}.merge_files`);
|
|
873
903
|
let final_api_docs = {};
|
|
874
|
-
for (
|
|
875
|
-
|
|
876
|
-
|
|
904
|
+
for (const file_path of files_to_merge) {
|
|
905
|
+
try {
|
|
906
|
+
const file_json = JSON.parse(await fs.readFile(file_path, "utf8"));
|
|
907
|
+
final_api_docs = import_neko_helper4.Arr.deepMerge(final_api_docs, file_json);
|
|
908
|
+
this.context.stdout.write(` Merged: ${file_path}
|
|
909
|
+
`);
|
|
910
|
+
} catch (error) {
|
|
911
|
+
this.context.stderr.write(
|
|
912
|
+
` Warning: Could not read ${file_path}: ${error.message}
|
|
913
|
+
`
|
|
914
|
+
);
|
|
915
|
+
}
|
|
877
916
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
);
|
|
917
|
+
const outputPath = this.output || config_exports.config.get(`${configPath}.output`);
|
|
918
|
+
await fs.mkdir(import_path2.default.dirname(outputPath), { recursive: true });
|
|
919
|
+
await fs.writeFile(outputPath, JSON.stringify(final_api_docs, null, 2));
|
|
882
920
|
this.context.stdout.write(
|
|
883
|
-
`
|
|
921
|
+
`Final OpenAPI document written to: ${outputPath}
|
|
884
922
|
`
|
|
885
923
|
);
|
|
924
|
+
return 0;
|
|
886
925
|
}
|
|
887
926
|
extractParameters(routePath) {
|
|
888
927
|
const paramRegex = /:([a-zA-Z0-9_]+)/g;
|
|
@@ -901,6 +940,78 @@ var GenerateApiDocsCommand = class extends import_clipanion2.Command {
|
|
|
901
940
|
}
|
|
902
941
|
return parameters;
|
|
903
942
|
}
|
|
943
|
+
generateFromRoutes() {
|
|
944
|
+
const openApiSpec = {
|
|
945
|
+
paths: {}
|
|
946
|
+
};
|
|
947
|
+
const routes = router().routes;
|
|
948
|
+
for (const route of routes) {
|
|
949
|
+
const routePath = route.path;
|
|
950
|
+
const openApiPath = routePath.replace(/\/$/g, "");
|
|
951
|
+
if (!openApiSpec.paths[openApiPath]) {
|
|
952
|
+
openApiSpec.paths[openApiPath] = {};
|
|
953
|
+
}
|
|
954
|
+
for (const method of route.methods) {
|
|
955
|
+
const lowerMethod = method.toLowerCase();
|
|
956
|
+
if (lowerMethod === "head") {
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
openApiSpec.paths[openApiPath][lowerMethod] = {
|
|
960
|
+
summary: `${routePath}`,
|
|
961
|
+
description: `Endpoint for ${method} ${routePath}`,
|
|
962
|
+
security: [],
|
|
963
|
+
parameters: this.extractParameters(routePath),
|
|
964
|
+
responses: {}
|
|
965
|
+
};
|
|
966
|
+
if (["post", "put", "patch"].includes(lowerMethod)) {
|
|
967
|
+
openApiSpec.paths[openApiPath][lowerMethod].requestBody = {
|
|
968
|
+
required: true,
|
|
969
|
+
content: {
|
|
970
|
+
"application/json": {
|
|
971
|
+
schema: {
|
|
972
|
+
type: "object"
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
return openApiSpec;
|
|
981
|
+
}
|
|
982
|
+
getBaseOpenApiSpec() {
|
|
983
|
+
const openApiSpec = {
|
|
984
|
+
openapi: "3.0.0",
|
|
985
|
+
info: {
|
|
986
|
+
title: "API Documentation",
|
|
987
|
+
version: "1.0.0",
|
|
988
|
+
description: "Auto-generated API documentation"
|
|
989
|
+
},
|
|
990
|
+
servers: [
|
|
991
|
+
{
|
|
992
|
+
url: "/",
|
|
993
|
+
description: "Local server"
|
|
994
|
+
}
|
|
995
|
+
],
|
|
996
|
+
components: {
|
|
997
|
+
securitySchemes: {
|
|
998
|
+
bearerAuth: {
|
|
999
|
+
type: "http",
|
|
1000
|
+
scheme: "bearer",
|
|
1001
|
+
bearerFormat: "JWT",
|
|
1002
|
+
description: "JWT token authentication"
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
},
|
|
1006
|
+
security: [
|
|
1007
|
+
{
|
|
1008
|
+
bearerAuth: []
|
|
1009
|
+
}
|
|
1010
|
+
],
|
|
1011
|
+
paths: {}
|
|
1012
|
+
};
|
|
1013
|
+
return openApiSpec;
|
|
1014
|
+
}
|
|
904
1015
|
};
|
|
905
1016
|
cli().register(GenerateApiDocsCommand);
|
|
906
1017
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -77,6 +77,7 @@ var MiddlewareFactory = class {
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
// ../neko-router/dist/CompiledRoute.mjs
|
|
80
|
+
var import_neko_helper = require("@devbro/neko-helper");
|
|
80
81
|
var CompiledRoute = class {
|
|
81
82
|
static {
|
|
82
83
|
__name(this, "CompiledRoute");
|
|
@@ -97,7 +98,7 @@ var CompiledRoute = class {
|
|
|
97
98
|
for (const middleware of [...this.globalMiddlewares, ...this.route.getMiddlewares()]) {
|
|
98
99
|
if (middleware instanceof Middleware) {
|
|
99
100
|
this.middlewares.push(middleware);
|
|
100
|
-
} else if (
|
|
101
|
+
} else if ((0, import_neko_helper.isClass)(middleware)) {
|
|
101
102
|
this.middlewares.push(middleware.getInstance({}));
|
|
102
103
|
} else if (typeof middleware === "function") {
|
|
103
104
|
this.middlewares.push(MiddlewareFactory.create(middleware));
|
|
@@ -106,9 +107,6 @@ var CompiledRoute = class {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
isClass(func) {
|
|
110
|
-
return typeof func === "function" && /^class\s/.test(Function.prototype.toString.call(func));
|
|
111
|
-
}
|
|
112
110
|
async run() {
|
|
113
111
|
return await this.runMiddlewares(this.middlewares, this.request, this.response);
|
|
114
112
|
}
|
|
@@ -244,7 +242,7 @@ var Route = class {
|
|
|
244
242
|
i = start;
|
|
245
243
|
} else if (char === "*") {
|
|
246
244
|
let start = i + 1;
|
|
247
|
-
while (start < path3.length && /[a-zA-Z0-9_
|
|
245
|
+
while (start < path3.length && /[a-zA-Z0-9_]/.test(path3[start])) {
|
|
248
246
|
start++;
|
|
249
247
|
}
|
|
250
248
|
tokens.push({ type: "WILDCARD", value: path3.slice(i + 1, start) });
|
|
@@ -455,7 +453,7 @@ var Router = class {
|
|
|
455
453
|
|
|
456
454
|
// src/facades.mts
|
|
457
455
|
var import_neko_scheduler = require("@devbro/neko-scheduler");
|
|
458
|
-
var
|
|
456
|
+
var import_neko_helper3 = require("@devbro/neko-helper");
|
|
459
457
|
var import_neko_context3 = require("@devbro/neko-context");
|
|
460
458
|
var import_neko_storage2 = require("@devbro/neko-storage");
|
|
461
459
|
var import_neko_mailer2 = require("@devbro/neko-mailer");
|
|
@@ -496,7 +494,7 @@ __export(queue_exports, {
|
|
|
496
494
|
DatabaseTransport: () => DatabaseTransport
|
|
497
495
|
});
|
|
498
496
|
__reExport(queue_exports, require("@devbro/neko-queue"));
|
|
499
|
-
var
|
|
497
|
+
var import_neko_helper2 = require("@devbro/neko-helper");
|
|
500
498
|
var import_neko_context2 = require("@devbro/neko-context");
|
|
501
499
|
var DatabaseTransport = class {
|
|
502
500
|
static {
|
|
@@ -557,7 +555,7 @@ var DatabaseTransport = class {
|
|
|
557
555
|
}, "processMessage");
|
|
558
556
|
constructor(config3 = {}) {
|
|
559
557
|
this.config = { ...this.config, ...config3 };
|
|
560
|
-
this.repeater = (0,
|
|
558
|
+
this.repeater = (0, import_neko_helper2.createRepeater)(
|
|
561
559
|
this.processMessage,
|
|
562
560
|
this.config.listen_interval * 1e3
|
|
563
561
|
);
|
|
@@ -625,6 +623,24 @@ import_neko_queue.QueueTransportFactory.register("database", (opt) => {
|
|
|
625
623
|
import_neko_queue.QueueTransportFactory.register("memory", (opt) => {
|
|
626
624
|
return new import_neko_queue.MemoryTransport(opt);
|
|
627
625
|
});
|
|
626
|
+
import_neko_queue.QueueTransportFactory.register("sqs", (opt) => {
|
|
627
|
+
return new import_neko_queue.AwsSqsTransport(opt);
|
|
628
|
+
});
|
|
629
|
+
import_neko_queue.QueueTransportFactory.register("amqp", (opt) => {
|
|
630
|
+
return new import_neko_queue.AmqpTransport(opt);
|
|
631
|
+
});
|
|
632
|
+
import_neko_queue.QueueTransportFactory.register("redis", (opt) => {
|
|
633
|
+
return new import_neko_queue.RedisTransport(opt);
|
|
634
|
+
});
|
|
635
|
+
import_neko_queue.QueueTransportFactory.register("async", (opt) => {
|
|
636
|
+
return new import_neko_queue.AsyncTransport();
|
|
637
|
+
});
|
|
638
|
+
import_neko_queue.QueueTransportFactory.register("azure_service_bus", (opt) => {
|
|
639
|
+
return new import_neko_queue.AzureServiceBusTransport(opt);
|
|
640
|
+
});
|
|
641
|
+
import_neko_queue.QueueTransportFactory.register("google_pubsub", (opt) => {
|
|
642
|
+
return new import_neko_queue.GooglePubSubTransport(opt);
|
|
643
|
+
});
|
|
628
644
|
var CacheProviderFactory = class _CacheProviderFactory {
|
|
629
645
|
static {
|
|
630
646
|
__name(this, "CacheProviderFactory");
|
|
@@ -655,12 +671,24 @@ import_neko_storage.StorageProviderFactory.register("local", (opt) => {
|
|
|
655
671
|
import_neko_storage.StorageProviderFactory.register("s3", (opt) => {
|
|
656
672
|
return new import_neko_storage.AWSS3StorageProvider(opt);
|
|
657
673
|
});
|
|
674
|
+
import_neko_storage.StorageProviderFactory.register("gcp", (opt) => {
|
|
675
|
+
return new import_neko_storage.GCPStorageProvider(opt);
|
|
676
|
+
});
|
|
677
|
+
import_neko_storage.StorageProviderFactory.register("azure", (opt) => {
|
|
678
|
+
return new import_neko_storage.AzureBlobStorageProvider(opt);
|
|
679
|
+
});
|
|
680
|
+
import_neko_storage.StorageProviderFactory.register("ftp", (opt) => {
|
|
681
|
+
return new import_neko_storage.FTPStorageProvider(opt);
|
|
682
|
+
});
|
|
683
|
+
import_neko_storage.StorageProviderFactory.register("sftp", (opt) => {
|
|
684
|
+
return new import_neko_storage.SFTPStorageProvider(opt);
|
|
685
|
+
});
|
|
658
686
|
|
|
659
687
|
// src/facades.mts
|
|
660
688
|
var import_neko_cache2 = require("@devbro/neko-cache");
|
|
661
689
|
var import_neko_queue2 = require("@devbro/neko-queue");
|
|
662
|
-
var router = (0,
|
|
663
|
-
var scheduler = (0,
|
|
690
|
+
var router = (0, import_neko_helper3.createSingleton)(() => new Router());
|
|
691
|
+
var scheduler = (0, import_neko_helper3.createSingleton)(() => {
|
|
664
692
|
const rc = new import_neko_scheduler.Scheduler();
|
|
665
693
|
rc.setErrorHandler((err, job) => {
|
|
666
694
|
logger().error({
|
|
@@ -672,7 +700,7 @@ var scheduler = (0, import_neko_helper2.createSingleton)(() => {
|
|
|
672
700
|
return rc;
|
|
673
701
|
});
|
|
674
702
|
var db = /* @__PURE__ */ __name((label = "default") => (0, import_neko_context3.ctx)().getOrThrow(["database", label]), "db");
|
|
675
|
-
var storage = (0,
|
|
703
|
+
var storage = (0, import_neko_helper3.createSingleton)((label = "default") => {
|
|
676
704
|
let storage_config = import_neko_config.config.get(["storages", label].join("."));
|
|
677
705
|
const provider = import_neko_storage2.StorageProviderFactory.create(
|
|
678
706
|
storage_config.provider,
|
|
@@ -680,7 +708,7 @@ var storage = (0, import_neko_helper2.createSingleton)((label = "default") => {
|
|
|
680
708
|
);
|
|
681
709
|
return new import_neko_storage2.Storage(provider);
|
|
682
710
|
});
|
|
683
|
-
var cli = (0,
|
|
711
|
+
var cli = (0, import_neko_helper3.createSingleton)(() => {
|
|
684
712
|
const [node, app, ...args] = process.argv;
|
|
685
713
|
return new import_clipanion.Cli({
|
|
686
714
|
binaryLabel: `My Application`,
|
|
@@ -688,13 +716,13 @@ var cli = (0, import_neko_helper2.createSingleton)(() => {
|
|
|
688
716
|
binaryVersion: `1.0.0`
|
|
689
717
|
});
|
|
690
718
|
});
|
|
691
|
-
var httpServer = (0,
|
|
719
|
+
var httpServer = (0, import_neko_helper3.createSingleton)(() => {
|
|
692
720
|
const server = new http_exports.HttpServer();
|
|
693
721
|
server.setErrorHandler(handleHttpErrors);
|
|
694
722
|
server.setRouter(router());
|
|
695
723
|
return server;
|
|
696
724
|
});
|
|
697
|
-
var logger = (0,
|
|
725
|
+
var logger = (0, import_neko_helper3.createSingleton)((label) => {
|
|
698
726
|
const logger_config = import_neko_config.config.get(["loggers", label].join("."));
|
|
699
727
|
const rc = new import_neko_logger.Logger(logger_config);
|
|
700
728
|
rc.setExtrasFunction((message) => {
|
|
@@ -703,7 +731,7 @@ var logger = (0, import_neko_helper2.createSingleton)((label) => {
|
|
|
703
731
|
});
|
|
704
732
|
return rc;
|
|
705
733
|
});
|
|
706
|
-
var mailer = (0,
|
|
734
|
+
var mailer = (0, import_neko_helper3.createSingleton)((label) => {
|
|
707
735
|
const mailer_config = import_neko_config.config.get(["mailer", label].join("."));
|
|
708
736
|
const provider = import_neko_mailer2.MailerProviderFactory.create(
|
|
709
737
|
mailer_config.provider,
|
|
@@ -712,7 +740,7 @@ var mailer = (0, import_neko_helper2.createSingleton)((label) => {
|
|
|
712
740
|
const rc = new import_neko_mailer2.Mailer(provider);
|
|
713
741
|
return rc;
|
|
714
742
|
});
|
|
715
|
-
var queue = (0,
|
|
743
|
+
var queue = (0, import_neko_helper3.createSingleton)((label) => {
|
|
716
744
|
const queue_config = import_neko_config.config.get(["queues", label].join("."));
|
|
717
745
|
if (!queue_config) {
|
|
718
746
|
throw new Error(`Queue configuration for '${label}' not found`);
|
|
@@ -723,7 +751,7 @@ var queue = (0, import_neko_helper2.createSingleton)((label) => {
|
|
|
723
751
|
);
|
|
724
752
|
return new import_neko_queue2.QueueConnection(provider);
|
|
725
753
|
});
|
|
726
|
-
var cache = (0,
|
|
754
|
+
var cache = (0, import_neko_helper3.createSingleton)((label) => {
|
|
727
755
|
const cache_config = import_neko_config.config.get(["caches", label].join("."));
|
|
728
756
|
if (!cache_config) {
|
|
729
757
|
throw new Error(`Cache configuration for '${label}' not found`);
|