go-duck-cli 1.0.8 → 1.1.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.
Files changed (70) hide show
  1. package/README.md +30 -15
  2. package/generators/ai_docs.js +130 -0
  3. package/generators/broker.js +63 -0
  4. package/generators/config.js +149 -7
  5. package/generators/devops.js +210 -43
  6. package/generators/docs.js +23 -4
  7. package/generators/elasticsearch.js +263 -0
  8. package/generators/kratos.js +229 -41
  9. package/generators/metering.js +280 -48
  10. package/generators/migrations.js +92 -198
  11. package/generators/mqtt.js +2 -39
  12. package/generators/multitenancy.js +274 -71
  13. package/generators/nats.js +39 -0
  14. package/generators/outbox.js +171 -0
  15. package/generators/postgrest.js +7 -3
  16. package/generators/postman.js +405 -0
  17. package/generators/repository.js +27 -0
  18. package/generators/router.js +27 -0
  19. package/generators/security.js +95 -14
  20. package/generators/serverless.js +147 -0
  21. package/generators/storage.js +589 -0
  22. package/generators/swagger.js +84 -60
  23. package/generators/telemetry.js +23 -32
  24. package/generators/websocket.js +55 -21
  25. package/index.js +481 -116
  26. package/package.json +6 -4
  27. package/parser/gdl.js +163 -24
  28. package/templates/docs/index.html.hbs +5 -5
  29. package/templates/docs/layout.hbs +221 -62
  30. package/templates/docs/pages/audit.hbs +83 -35
  31. package/templates/docs/pages/cli.hbs +18 -0
  32. package/templates/docs/pages/configuration.hbs +241 -0
  33. package/templates/docs/pages/datadog.hbs +46 -0
  34. package/templates/docs/pages/elasticsearch.hbs +121 -0
  35. package/templates/docs/pages/federation.hbs +241 -0
  36. package/templates/docs/pages/gdl-advanced.hbs +91 -0
  37. package/templates/docs/pages/gdl-annotations.hbs +137 -0
  38. package/templates/docs/pages/gdl-entities.hbs +134 -0
  39. package/templates/docs/pages/gdl-relationships.hbs +80 -0
  40. package/templates/docs/pages/gdl.hbs +60 -204
  41. package/templates/docs/pages/graphql.hbs +58 -44
  42. package/templates/docs/pages/grpc.hbs +53 -90
  43. package/templates/docs/pages/hybrid-store.hbs +127 -0
  44. package/templates/docs/pages/index.hbs +418 -149
  45. package/templates/docs/pages/keycloak.hbs +43 -0
  46. package/templates/docs/pages/legend.hbs +116 -0
  47. package/templates/docs/pages/mosquitto.hbs +39 -0
  48. package/templates/docs/pages/multitenancy.hbs +139 -71
  49. package/templates/docs/pages/otel.hbs +40 -0
  50. package/templates/docs/pages/realtime.hbs +38 -12
  51. package/templates/docs/pages/redis.hbs +40 -0
  52. package/templates/docs/pages/rest.hbs +120 -202
  53. package/templates/docs/pages/saga.hbs +94 -0
  54. package/templates/docs/pages/security.hbs +150 -44
  55. package/templates/docs/pages/serverless.hbs +157 -0
  56. package/templates/docs/pages/storage.hbs +127 -0
  57. package/templates/docs/pages/wizard.hbs +683 -0
  58. package/templates/docs/triple_identity_registry.png +0 -0
  59. package/templates/go/controller.go.hbs +287 -283
  60. package/templates/go/entity.go.hbs +17 -15
  61. package/templates/go/main.go.hbs +47 -180
  62. package/templates/go/migrator.go.hbs +65 -0
  63. package/templates/go/router.go.hbs +272 -0
  64. package/templates/graphql/resolver.go.hbs +53 -34
  65. package/templates/graphql/schema.graphql.hbs +17 -5
  66. package/templates/kratos/service.go.hbs +169 -34
  67. package/templates/proto/entity.proto.hbs +10 -14
  68. package/test_nested.gdl +21 -0
  69. package/templates/docs/intro.mp4 +0 -0
  70. package/test_parser.js +0 -9
@@ -0,0 +1,147 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import chalk from 'chalk';
4
+
5
+ export const generateServerlessHandler = async (outputDir, config) => {
6
+ if (!config.serverless?.enabled) return;
7
+
8
+ console.log(chalk.blue(' Scaffolding Elite Serverless Adapter (Build-Tag Native)...'));
9
+
10
+ const handlerGo = `//go:build lambda
11
+ // +build lambda
12
+
13
+ package main
14
+
15
+ import (
16
+ "context"
17
+ "log"
18
+
19
+ "{{app_name}}/config"
20
+ "{{app_name}}/router"
21
+ "github.com/aws/aws-lambda-go/events"
22
+ "github.com/aws/aws-lambda-go/lambda"
23
+ ginadapter "github.com/awslabs/aws-lambda-go-api-proxy/gin"
24
+ )
25
+
26
+ var ginLambda *ginadapter.GinLambda
27
+
28
+ func init() {
29
+ log.Println("🦆 [SERVERLESS-LAMBDA] Initializing GO-DUCK Elite Gateway...")
30
+
31
+ cfg, err := config.LoadConfig()
32
+ if err != nil {
33
+ log.Fatalf("🦆 [CRITICAL] Failed to load config: %v", err)
34
+ }
35
+
36
+ // Initialize the shared GO-DUCK router
37
+ r := router.SetupRouter(cfg)
38
+ ginLambda = ginadapter.New(r)
39
+ }
40
+
41
+ func Handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
42
+ return ginLambda.ProxyWithContext(ctx, req)
43
+ }
44
+
45
+ func main() {
46
+ lambda.Start(Handler)
47
+ }
48
+ `;
49
+
50
+ await fs.writeFile(
51
+ path.join(outputDir, 'lambda_main.go'),
52
+ handlerGo.replace(/{{app_name}}/g, config.name)
53
+ );
54
+
55
+
56
+ // --- Google Cloud Functions (HTTP Trigger) ---
57
+ const gcfHandlerGo = `//go:build gcf
58
+ // +build gcf
59
+
60
+ package entrypoint
61
+
62
+ import (
63
+ "net/http"
64
+ "sync"
65
+ "log"
66
+
67
+ "{{app_name}}/config"
68
+ "{{app_name}}/router"
69
+ "github.com/GoogleCloudPlatform/functions-framework-go/functions"
70
+ )
71
+
72
+ var (
73
+ initialOnce sync.Once
74
+ h http.Handler
75
+ )
76
+
77
+ func init() {
78
+ functions.HTTP("GoDuckEntry", GoDuckEntry)
79
+ }
80
+
81
+ func GoDuckEntry(w http.ResponseWriter, r *http.Request) {
82
+ initialOnce.Do(func() {
83
+ log.Println("🦆 [SERVERLESS-GCF] Initializing GO-DUCK Elite Gateway...")
84
+ cfg, err := config.LoadConfig()
85
+ if err != nil {
86
+ log.Fatalf("🦆 [CRITICAL] Failed to load config: %v", err)
87
+ }
88
+ h = router.SetupRouter(cfg)
89
+ })
90
+ h.ServeHTTP(w, r)
91
+ }
92
+ `;
93
+
94
+ await fs.writeFile(
95
+ path.join(outputDir, 'gcf_handler.go'),
96
+ gcfHandlerGo.replace(/{{app_name}}/g, config.name)
97
+ );
98
+
99
+ // --- Vercel Edge Serverless ---
100
+ const vercelHandlerGo = `package handler
101
+
102
+ import (
103
+ "net/http"
104
+ "sync"
105
+ "log"
106
+
107
+ "{{app_name}}/config"
108
+ "{{app_name}}/router"
109
+ )
110
+
111
+ var (
112
+ initialOnce sync.Once
113
+ h http.Handler
114
+ )
115
+
116
+ func Handler(w http.ResponseWriter, r *http.Request) {
117
+ initialOnce.Do(func() {
118
+ log.Println("🦆 [SERVERLESS-VERCEL] Initializing GO-DUCK Elite Gateway...")
119
+ cfg, err := config.LoadConfig()
120
+ if err != nil {
121
+ log.Fatalf("🦆 [CRITICAL] Failed to load config: %v", err)
122
+ }
123
+ h = router.SetupRouter(cfg)
124
+ })
125
+ h.ServeHTTP(w, r)
126
+ }
127
+ `;
128
+
129
+ const vercelDir = path.join(outputDir, 'api');
130
+ await fs.ensureDir(vercelDir);
131
+ await fs.writeFile(
132
+ path.join(vercelDir, 'index.go'),
133
+ vercelHandlerGo.replace(/{{app_name}}/g, config.name)
134
+ );
135
+
136
+ // Generate vercel.json for wildcard routing
137
+ const vercelJson = {
138
+ "version": 2,
139
+ "rewrites": [
140
+ { "source": "/(.*)", "destination": "/api/index" }
141
+ ]
142
+ };
143
+ await fs.writeJson(path.join(outputDir, 'vercel.json'), vercelJson, { spaces: 2 });
144
+
145
+ console.log(chalk.gray(' - Generated Global Serverless Handlers: lambda_main.go, gcf_handler.go, api/index.go (Vercel), vercel.json'));
146
+ };
147
+