create-svc 0.1.10 → 0.1.12

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 (171) hide show
  1. package/README.md +51 -47
  2. package/index.ts +2 -2
  3. package/package.json +10 -9
  4. package/src/cli.test.ts +28 -10
  5. package/src/cli.ts +196 -33
  6. package/src/git-bootstrap.test.ts +40 -0
  7. package/src/git-bootstrap.ts +110 -0
  8. package/src/naming.test.ts +1 -0
  9. package/src/naming.ts +23 -0
  10. package/src/post-scaffold.test.ts +19 -0
  11. package/src/post-scaffold.ts +17 -4
  12. package/src/profiles.ts +2 -5
  13. package/src/scaffold.test.ts +232 -41
  14. package/src/scaffold.ts +81 -36
  15. package/src/service.test.ts +30 -0
  16. package/src/service.ts +65 -0
  17. package/src/vault.test.ts +61 -1
  18. package/src/vault.ts +77 -15
  19. package/templates/shared/.github/workflows/ci.yml +2 -1
  20. package/templates/shared/.github/workflows/deploy.yml +2 -0
  21. package/templates/shared/README.md +124 -47
  22. package/templates/shared/grafana/alerts.yaml +54 -0
  23. package/templates/shared/grafana/waitlist-dashboard.json +63 -0
  24. package/templates/shared/scripts/authctl.ts +231 -0
  25. package/templates/shared/scripts/cloudrun/bootstrap.ts +14 -5
  26. package/templates/shared/scripts/cloudrun/cleanup.ts +64 -4
  27. package/templates/shared/scripts/cloudrun/cli.ts +329 -7
  28. package/templates/shared/scripts/cloudrun/config.ts +11 -4
  29. package/templates/shared/scripts/cloudrun/deploy.ts +0 -4
  30. package/templates/shared/scripts/cloudrun/lib.ts +174 -41
  31. package/templates/shared/scripts/cloudrun/neon.ts +45 -0
  32. package/templates/shared/scripts/dev.ts +22 -0
  33. package/templates/shared/scripts/ensure-local-db.ts +3 -0
  34. package/templates/shared/scripts/local-docker.ts +63 -0
  35. package/templates/shared/scripts/local-env.ts +27 -0
  36. package/templates/shared/scripts/seed.ts +73 -0
  37. package/templates/shared/scripts/wait-for-db.ts +32 -0
  38. package/templates/shared/service.config.ts +59 -0
  39. package/templates/shared/service.yaml +24 -44
  40. package/templates/targets/workers/.github/workflows/ci.yml +19 -0
  41. package/templates/targets/workers/.github/workflows/deploy.yml +19 -0
  42. package/templates/targets/workers/Makefile +33 -0
  43. package/templates/targets/workers/README.md +75 -0
  44. package/templates/targets/workers/package.json +35 -0
  45. package/templates/targets/workers/scripts/workers/cli.ts +402 -0
  46. package/templates/targets/workers/src/auth.ts +178 -0
  47. package/templates/targets/workers/src/index.ts +198 -0
  48. package/templates/targets/workers/src/storage.ts +370 -0
  49. package/templates/targets/workers/test/app.test.ts +108 -0
  50. package/templates/targets/workers/tsconfig.json +11 -0
  51. package/templates/targets/workers/wrangler.toml +24 -0
  52. package/templates/variants/bun-connectrpc/Makefile +14 -8
  53. package/templates/variants/bun-connectrpc/gen/protos/waitlist/v1/waitlist_pb.ts +424 -0
  54. package/templates/variants/bun-connectrpc/migrations/0000_init.sql +12 -55
  55. package/templates/variants/bun-connectrpc/package.json +12 -5
  56. package/templates/variants/bun-connectrpc/protos/waitlist/v1/waitlist.proto +91 -0
  57. package/templates/variants/bun-connectrpc/scripts/codegen.ts +1 -1
  58. package/templates/variants/bun-connectrpc/scripts/migrate.ts +4 -1
  59. package/templates/variants/bun-connectrpc/src/auth.ts +200 -0
  60. package/templates/variants/bun-connectrpc/src/db/repository.ts +67 -420
  61. package/templates/variants/bun-connectrpc/src/db/schema.ts +15 -64
  62. package/templates/variants/bun-connectrpc/src/index.ts +76 -176
  63. package/templates/variants/bun-connectrpc/src/temporal/activities.ts +14 -0
  64. package/templates/variants/bun-connectrpc/src/temporal/worker.ts +38 -0
  65. package/templates/variants/bun-connectrpc/src/temporal/workflows.ts +10 -0
  66. package/templates/variants/bun-connectrpc/src/waitlist/service.ts +172 -0
  67. package/templates/variants/bun-connectrpc/src/waitlist/types.ts +45 -0
  68. package/templates/variants/bun-connectrpc/test/app.test.ts +4 -4
  69. package/templates/variants/bun-connectrpc/test/waitlist.integration.test.ts +71 -0
  70. package/templates/variants/bun-hono/Makefile +14 -8
  71. package/templates/variants/bun-hono/migrations/0000_init.sql +12 -55
  72. package/templates/variants/bun-hono/package.json +12 -5
  73. package/templates/variants/bun-hono/scripts/migrate.ts +4 -1
  74. package/templates/variants/bun-hono/src/auth.ts +181 -0
  75. package/templates/variants/bun-hono/src/db/repository.ts +68 -421
  76. package/templates/variants/bun-hono/src/db/schema.ts +15 -64
  77. package/templates/variants/bun-hono/src/index.ts +65 -180
  78. package/templates/variants/bun-hono/src/temporal/activities.ts +14 -0
  79. package/templates/variants/bun-hono/src/temporal/worker.ts +38 -0
  80. package/templates/variants/bun-hono/src/temporal/workflows.ts +10 -0
  81. package/templates/variants/bun-hono/src/waitlist/service.ts +166 -0
  82. package/templates/variants/bun-hono/src/waitlist/types.ts +50 -0
  83. package/templates/variants/bun-hono/test/app.test.ts +72 -41
  84. package/templates/variants/bun-hono/test/waitlist.integration.test.ts +102 -0
  85. package/templates/variants/go-chi/Makefile +27 -11
  86. package/templates/variants/go-chi/atlas.hcl +8 -0
  87. package/templates/variants/go-chi/cmd/server/main.go +21 -10
  88. package/templates/variants/go-chi/go.mod +1 -3
  89. package/templates/variants/go-chi/internal/app/service.go +202 -685
  90. package/templates/variants/go-chi/internal/auth/middleware.go +289 -0
  91. package/templates/variants/go-chi/internal/auth/middleware_test.go +38 -0
  92. package/templates/variants/go-chi/internal/config/config.go +27 -11
  93. package/templates/variants/go-chi/internal/httpapi/routes.go +78 -157
  94. package/templates/variants/go-chi/internal/httpapi/waitlist_integration_test.go +199 -0
  95. package/templates/variants/go-chi/internal/temporal/activities.go +27 -0
  96. package/templates/variants/go-chi/internal/temporal/worker.go +42 -0
  97. package/templates/variants/go-chi/internal/temporal/workflows.go +18 -0
  98. package/templates/variants/go-chi/migrations/0000_init.sql +12 -55
  99. package/templates/variants/go-chi/migrations/atlas.sum +2 -0
  100. package/templates/variants/go-chi/package.json +7 -1
  101. package/templates/variants/go-connectrpc/Makefile +26 -9
  102. package/templates/variants/go-connectrpc/atlas.hcl +8 -0
  103. package/templates/variants/go-connectrpc/buf.gen.yaml +2 -2
  104. package/templates/variants/go-connectrpc/cmd/server/main.go +23 -12
  105. package/templates/variants/go-connectrpc/gen/waitlist/v1/waitlist.pb.go +960 -0
  106. package/templates/variants/go-connectrpc/gen/waitlist/v1/waitlistv1connect/waitlist.connect.go +283 -0
  107. package/templates/variants/go-connectrpc/go.mod +1 -1
  108. package/templates/variants/go-connectrpc/internal/app/service.go +202 -685
  109. package/templates/variants/go-connectrpc/internal/auth/middleware.go +289 -0
  110. package/templates/variants/go-connectrpc/internal/auth/middleware_test.go +38 -0
  111. package/templates/variants/go-connectrpc/internal/config/config.go +27 -11
  112. package/templates/variants/go-connectrpc/internal/connectapi/handler.go +78 -201
  113. package/templates/variants/go-connectrpc/internal/connectapi/waitlist_integration_test.go +122 -0
  114. package/templates/variants/go-connectrpc/internal/httpapi/routes.go +147 -9
  115. package/templates/variants/go-connectrpc/internal/temporal/activities.go +27 -0
  116. package/templates/variants/go-connectrpc/internal/temporal/worker.go +42 -0
  117. package/templates/variants/go-connectrpc/internal/temporal/workflows.go +18 -0
  118. package/templates/variants/go-connectrpc/migrations/0000_init.sql +12 -55
  119. package/templates/variants/go-connectrpc/migrations/atlas.sum +2 -0
  120. package/templates/variants/go-connectrpc/package.json +7 -1
  121. package/templates/variants/go-connectrpc/protos/waitlist/v1/waitlist.proto +93 -0
  122. package/templates/root/.github/workflows/buf-publish.yml +0 -19
  123. package/templates/root/.github/workflows/ci.yml +0 -26
  124. package/templates/root/.github/workflows/deploy.yml +0 -22
  125. package/templates/root/Dockerfile +0 -23
  126. package/templates/root/README.md +0 -69
  127. package/templates/root/buf.gen.yaml +0 -10
  128. package/templates/root/buf.yaml +0 -9
  129. package/templates/root/cmd/server/main.go +0 -44
  130. package/templates/root/gen/dns/v1/dns.pb.go +0 -623
  131. package/templates/root/gen/dns/v1/dnsv1connect/dns.connect.go +0 -192
  132. package/templates/root/go.mod +0 -10
  133. package/templates/root/internal/app/service.go +0 -152
  134. package/templates/root/internal/app/token_source.go +0 -50
  135. package/templates/root/internal/cloudflare/client.go +0 -160
  136. package/templates/root/internal/config/config.go +0 -55
  137. package/templates/root/internal/connectapi/handler.go +0 -79
  138. package/templates/root/internal/httpapi/routes.go +0 -93
  139. package/templates/root/internal/vault/client.go +0 -148
  140. package/templates/root/package.json +0 -12
  141. package/templates/root/protos/dns/v1/dns.proto +0 -58
  142. package/templates/root/scripts/cloudrun/bootstrap.ts +0 -65
  143. package/templates/root/scripts/cloudrun/config.ts +0 -50
  144. package/templates/root/scripts/cloudrun/deploy.ts +0 -41
  145. package/templates/root/scripts/cloudrun/lib.ts +0 -244
  146. package/templates/root/service.yaml +0 -50
  147. package/templates/root/test/go.test.ts +0 -19
  148. package/templates/shared/scripts/cloudrun/integrations.ts +0 -111
  149. package/templates/variants/bun-connectrpc/gen/protos/chat/v1/chat_pb.ts +0 -1078
  150. package/templates/variants/bun-connectrpc/protos/chat/v1/chat.proto +0 -228
  151. package/templates/variants/bun-connectrpc/src/chat/service.ts +0 -384
  152. package/templates/variants/bun-connectrpc/src/chat/types.ts +0 -142
  153. package/templates/variants/bun-connectrpc/src/storage.ts +0 -72
  154. package/templates/variants/bun-connectrpc/src/webhooks.ts +0 -35
  155. package/templates/variants/bun-connectrpc/test/list-messages.integration.test.ts +0 -182
  156. package/templates/variants/bun-hono/src/chat/service.ts +0 -384
  157. package/templates/variants/bun-hono/src/chat/types.ts +0 -142
  158. package/templates/variants/bun-hono/src/storage.ts +0 -72
  159. package/templates/variants/bun-hono/src/webhooks.ts +0 -35
  160. package/templates/variants/bun-hono/test/list-messages.integration.test.ts +0 -256
  161. package/templates/variants/go-chi/buf.gen.yaml +0 -12
  162. package/templates/variants/go-chi/buf.yaml +0 -9
  163. package/templates/variants/go-chi/cmd/migrate/main.go +0 -101
  164. package/templates/variants/go-chi/internal/httpapi/list_messages_integration_test.go +0 -298
  165. package/templates/variants/go-chi/protos/chat/v1/chat.proto +0 -219
  166. package/templates/variants/go-connectrpc/cmd/migrate/main.go +0 -101
  167. package/templates/variants/go-connectrpc/gen/chat/v1/chat.pb.go +0 -2512
  168. package/templates/variants/go-connectrpc/gen/chat/v1/chatv1connect/chat.connect.go +0 -571
  169. package/templates/variants/go-connectrpc/internal/connectapi/list_messages_integration_test.go +0 -216
  170. package/templates/variants/go-connectrpc/protos/chat/v1/chat.proto +0 -232
  171. /package/bin/{create-svc.mjs → service.mjs} +0 -0
@@ -1,219 +0,0 @@
1
- syntax = "proto3";
2
-
3
- package chat.v1;
4
-
5
- option go_package = "{{MODULE_PATH}}/gen/chat/v1;chatv1";
6
-
7
- service ChatService {
8
- rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
9
- rpc GetUser(GetUserRequest) returns (GetUserResponse);
10
- rpc GetUserByUsername(GetUserByUsernameRequest) returns (GetUserByUsernameResponse);
11
- rpc CreateConversation(CreateConversationRequest) returns (CreateConversationResponse);
12
- rpc GetConversation(GetConversationRequest) returns (GetConversationResponse);
13
- rpc UpdateConversation(UpdateConversationRequest) returns (UpdateConversationResponse);
14
- rpc DeleteConversation(DeleteConversationRequest) returns (DeleteConversationResponse);
15
- rpc AddConversationParticipant(AddConversationParticipantRequest) returns (AddConversationParticipantResponse);
16
- rpc RemoveConversationParticipant(RemoveConversationParticipantRequest) returns (RemoveConversationParticipantResponse);
17
- rpc ListMessages(ListMessagesRequest) returns (ListMessagesResponse);
18
- rpc CreateMessage(CreateMessageRequest) returns (CreateMessageResponse);
19
- rpc UpdateMessage(UpdateMessageRequest) returns (UpdateMessageResponse);
20
- rpc DeleteMessage(DeleteMessageRequest) returns (DeleteMessageResponse);
21
- rpc CreateAttachmentUpload(CreateAttachmentUploadRequest) returns (CreateAttachmentUploadResponse);
22
- rpc FinalizeAttachment(FinalizeAttachmentRequest) returns (FinalizeAttachmentResponse);
23
- rpc GetAttachment(GetAttachmentRequest) returns (GetAttachmentResponse);
24
- rpc DeleteAttachment(DeleteAttachmentRequest) returns (DeleteAttachmentResponse);
25
- }
26
-
27
- message User {
28
- string id = 1;
29
- string username = 2;
30
- string display_name = 3;
31
- string created_at = 4;
32
- string updated_at = 5;
33
- }
34
-
35
- message Conversation {
36
- string id = 1;
37
- string title = 2;
38
- string created_by_user_id = 3;
39
- repeated User participants = 4;
40
- string created_at = 5;
41
- string updated_at = 6;
42
- }
43
-
44
- message Message {
45
- string id = 1;
46
- string conversation_id = 2;
47
- string user_id = 3;
48
- string body = 4;
49
- string edited_at = 5;
50
- string created_at = 6;
51
- string updated_at = 7;
52
- }
53
-
54
- message Attachment {
55
- string id = 1;
56
- string conversation_id = 2;
57
- string message_id = 3;
58
- string uploaded_by_user_id = 4;
59
- string storage_bucket = 5;
60
- string storage_key = 6;
61
- string content_type = 7;
62
- int64 byte_size = 8;
63
- string filename = 9;
64
- string status = 10;
65
- string public_url = 11;
66
- string created_at = 12;
67
- string updated_at = 13;
68
- }
69
-
70
- message UploadTarget {
71
- string method = 1;
72
- string url = 2;
73
- map<string, string> headers = 3;
74
- }
75
-
76
- message CreateUserRequest {
77
- string username = 1;
78
- string display_name = 2;
79
- }
80
-
81
- message CreateUserResponse {
82
- User user = 1;
83
- }
84
-
85
- message GetUserRequest {
86
- string user_id = 1;
87
- }
88
-
89
- message GetUserResponse {
90
- User user = 1;
91
- }
92
-
93
- message GetUserByUsernameRequest {
94
- string username = 1;
95
- }
96
-
97
- message GetUserByUsernameResponse {
98
- User user = 1;
99
- }
100
-
101
- message CreateConversationRequest {
102
- string created_by_user_id = 1;
103
- string title = 2;
104
- repeated string participant_user_ids = 3;
105
- }
106
-
107
- message CreateConversationResponse {
108
- Conversation conversation = 1;
109
- }
110
-
111
- message GetConversationRequest {
112
- string conversation_id = 1;
113
- }
114
-
115
- message GetConversationResponse {
116
- Conversation conversation = 1;
117
- }
118
-
119
- message UpdateConversationRequest {
120
- string conversation_id = 1;
121
- string title = 2;
122
- }
123
-
124
- message UpdateConversationResponse {
125
- Conversation conversation = 1;
126
- }
127
-
128
- message DeleteConversationRequest {
129
- string conversation_id = 1;
130
- }
131
-
132
- message DeleteConversationResponse {}
133
-
134
- message AddConversationParticipantRequest {
135
- string conversation_id = 1;
136
- string user_id = 2;
137
- }
138
-
139
- message AddConversationParticipantResponse {
140
- Conversation conversation = 1;
141
- }
142
-
143
- message RemoveConversationParticipantRequest {
144
- string conversation_id = 1;
145
- string user_id = 2;
146
- }
147
-
148
- message RemoveConversationParticipantResponse {}
149
-
150
- message ListMessagesRequest {
151
- string conversation_id = 1;
152
- }
153
-
154
- message ListMessagesResponse {
155
- repeated Message messages = 1;
156
- }
157
-
158
- message CreateMessageRequest {
159
- string conversation_id = 1;
160
- string user_id = 2;
161
- string body = 3;
162
- }
163
-
164
- message CreateMessageResponse {
165
- Message message = 1;
166
- }
167
-
168
- message UpdateMessageRequest {
169
- string conversation_id = 1;
170
- string message_id = 2;
171
- string body = 3;
172
- }
173
-
174
- message UpdateMessageResponse {
175
- Message message = 1;
176
- }
177
-
178
- message DeleteMessageRequest {
179
- string conversation_id = 1;
180
- string message_id = 2;
181
- }
182
-
183
- message DeleteMessageResponse {}
184
-
185
- message CreateAttachmentUploadRequest {
186
- string conversation_id = 1;
187
- string user_id = 2;
188
- string filename = 3;
189
- string content_type = 4;
190
- int64 byte_size = 5;
191
- }
192
-
193
- message CreateAttachmentUploadResponse {
194
- Attachment attachment = 1;
195
- UploadTarget upload = 2;
196
- }
197
-
198
- message FinalizeAttachmentRequest {
199
- string attachment_id = 1;
200
- string message_id = 2;
201
- }
202
-
203
- message FinalizeAttachmentResponse {
204
- Attachment attachment = 1;
205
- }
206
-
207
- message GetAttachmentRequest {
208
- string attachment_id = 1;
209
- }
210
-
211
- message GetAttachmentResponse {
212
- Attachment attachment = 1;
213
- }
214
-
215
- message DeleteAttachmentRequest {
216
- string attachment_id = 1;
217
- }
218
-
219
- message DeleteAttachmentResponse {}
@@ -1,101 +0,0 @@
1
- package main
2
-
3
- import (
4
- "context"
5
- "log"
6
- "os"
7
- "sort"
8
- "strings"
9
- "time"
10
-
11
- _ "github.com/jackc/pgx/v5/stdlib"
12
- "github.com/jmoiron/sqlx"
13
-
14
- "{{MODULE_PATH}}/internal/app"
15
- "{{MODULE_PATH}}/internal/config"
16
- )
17
-
18
- func main() {
19
- cfg, err := config.Load()
20
- if err != nil {
21
- log.Fatal(err)
22
- }
23
-
24
- db, err := app.OpenDatabase(context.Background(), cfg.DatabaseURL)
25
- if err != nil {
26
- db, err = waitForDatabase(cfg.DatabaseURL, 30*time.Second)
27
- if err != nil {
28
- log.Fatal(err)
29
- }
30
- }
31
-
32
- if _, err := db.ExecContext(context.Background(), `
33
- create table if not exists schema_migrations (
34
- version text primary key,
35
- applied_at timestamptz not null default now()
36
- )`); err != nil {
37
- log.Fatal(err)
38
- }
39
-
40
- entries, err := os.ReadDir("migrations")
41
- if err != nil {
42
- log.Fatal(err)
43
- }
44
-
45
- versions := make([]string, 0, len(entries))
46
- for _, entry := range entries {
47
- if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".sql") {
48
- continue
49
- }
50
- versions = append(versions, entry.Name())
51
- }
52
- sort.Strings(versions)
53
-
54
- for _, version := range versions {
55
- var count int
56
- if err := db.GetContext(context.Background(), &count, `select count(*) from schema_migrations where version = $1`, version); err != nil {
57
- log.Fatal(err)
58
- }
59
- if count > 0 {
60
- continue
61
- }
62
-
63
- sqlBytes, err := os.ReadFile("migrations/" + version)
64
- if err != nil {
65
- log.Fatal(err)
66
- }
67
-
68
- tx, err := db.BeginTxx(context.Background(), nil)
69
- if err != nil {
70
- log.Fatal(err)
71
- }
72
- if _, err := tx.ExecContext(context.Background(), string(sqlBytes)); err != nil {
73
- _ = tx.Rollback()
74
- log.Fatal(err)
75
- }
76
- if _, err := tx.ExecContext(context.Background(), `insert into schema_migrations (version) values ($1)`, version); err != nil {
77
- _ = tx.Rollback()
78
- log.Fatal(err)
79
- }
80
- if err := tx.Commit(); err != nil {
81
- log.Fatal(err)
82
- }
83
- log.Printf("applied migration %s", version)
84
- }
85
- }
86
-
87
- func waitForDatabase(databaseURL string, timeout time.Duration) (*sqlx.DB, error) {
88
- deadline := time.Now().Add(timeout)
89
- var lastErr error
90
-
91
- for time.Now().Before(deadline) {
92
- db, err := app.OpenDatabase(context.Background(), databaseURL)
93
- if err == nil {
94
- return db, nil
95
- }
96
- lastErr = err
97
- time.Sleep(time.Second)
98
- }
99
-
100
- return nil, lastErr
101
- }