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.
- package/README.md +51 -47
- package/index.ts +2 -2
- package/package.json +10 -9
- package/src/cli.test.ts +28 -10
- package/src/cli.ts +196 -33
- package/src/git-bootstrap.test.ts +40 -0
- package/src/git-bootstrap.ts +110 -0
- package/src/naming.test.ts +1 -0
- package/src/naming.ts +23 -0
- package/src/post-scaffold.test.ts +19 -0
- package/src/post-scaffold.ts +17 -4
- package/src/profiles.ts +2 -5
- package/src/scaffold.test.ts +232 -41
- package/src/scaffold.ts +81 -36
- package/src/service.test.ts +30 -0
- package/src/service.ts +65 -0
- package/src/vault.test.ts +61 -1
- package/src/vault.ts +77 -15
- package/templates/shared/.github/workflows/ci.yml +2 -1
- package/templates/shared/.github/workflows/deploy.yml +2 -0
- package/templates/shared/README.md +124 -47
- package/templates/shared/grafana/alerts.yaml +54 -0
- package/templates/shared/grafana/waitlist-dashboard.json +63 -0
- package/templates/shared/scripts/authctl.ts +231 -0
- package/templates/shared/scripts/cloudrun/bootstrap.ts +14 -5
- package/templates/shared/scripts/cloudrun/cleanup.ts +64 -4
- package/templates/shared/scripts/cloudrun/cli.ts +329 -7
- package/templates/shared/scripts/cloudrun/config.ts +11 -4
- package/templates/shared/scripts/cloudrun/deploy.ts +0 -4
- package/templates/shared/scripts/cloudrun/lib.ts +174 -41
- package/templates/shared/scripts/cloudrun/neon.ts +45 -0
- package/templates/shared/scripts/dev.ts +22 -0
- package/templates/shared/scripts/ensure-local-db.ts +3 -0
- package/templates/shared/scripts/local-docker.ts +63 -0
- package/templates/shared/scripts/local-env.ts +27 -0
- package/templates/shared/scripts/seed.ts +73 -0
- package/templates/shared/scripts/wait-for-db.ts +32 -0
- package/templates/shared/service.config.ts +59 -0
- package/templates/shared/service.yaml +24 -44
- package/templates/targets/workers/.github/workflows/ci.yml +19 -0
- package/templates/targets/workers/.github/workflows/deploy.yml +19 -0
- package/templates/targets/workers/Makefile +33 -0
- package/templates/targets/workers/README.md +75 -0
- package/templates/targets/workers/package.json +35 -0
- package/templates/targets/workers/scripts/workers/cli.ts +402 -0
- package/templates/targets/workers/src/auth.ts +178 -0
- package/templates/targets/workers/src/index.ts +198 -0
- package/templates/targets/workers/src/storage.ts +370 -0
- package/templates/targets/workers/test/app.test.ts +108 -0
- package/templates/targets/workers/tsconfig.json +11 -0
- package/templates/targets/workers/wrangler.toml +24 -0
- package/templates/variants/bun-connectrpc/Makefile +14 -8
- package/templates/variants/bun-connectrpc/gen/protos/waitlist/v1/waitlist_pb.ts +424 -0
- package/templates/variants/bun-connectrpc/migrations/0000_init.sql +12 -55
- package/templates/variants/bun-connectrpc/package.json +12 -5
- package/templates/variants/bun-connectrpc/protos/waitlist/v1/waitlist.proto +91 -0
- package/templates/variants/bun-connectrpc/scripts/codegen.ts +1 -1
- package/templates/variants/bun-connectrpc/scripts/migrate.ts +4 -1
- package/templates/variants/bun-connectrpc/src/auth.ts +200 -0
- package/templates/variants/bun-connectrpc/src/db/repository.ts +67 -420
- package/templates/variants/bun-connectrpc/src/db/schema.ts +15 -64
- package/templates/variants/bun-connectrpc/src/index.ts +76 -176
- package/templates/variants/bun-connectrpc/src/temporal/activities.ts +14 -0
- package/templates/variants/bun-connectrpc/src/temporal/worker.ts +38 -0
- package/templates/variants/bun-connectrpc/src/temporal/workflows.ts +10 -0
- package/templates/variants/bun-connectrpc/src/waitlist/service.ts +172 -0
- package/templates/variants/bun-connectrpc/src/waitlist/types.ts +45 -0
- package/templates/variants/bun-connectrpc/test/app.test.ts +4 -4
- package/templates/variants/bun-connectrpc/test/waitlist.integration.test.ts +71 -0
- package/templates/variants/bun-hono/Makefile +14 -8
- package/templates/variants/bun-hono/migrations/0000_init.sql +12 -55
- package/templates/variants/bun-hono/package.json +12 -5
- package/templates/variants/bun-hono/scripts/migrate.ts +4 -1
- package/templates/variants/bun-hono/src/auth.ts +181 -0
- package/templates/variants/bun-hono/src/db/repository.ts +68 -421
- package/templates/variants/bun-hono/src/db/schema.ts +15 -64
- package/templates/variants/bun-hono/src/index.ts +65 -180
- package/templates/variants/bun-hono/src/temporal/activities.ts +14 -0
- package/templates/variants/bun-hono/src/temporal/worker.ts +38 -0
- package/templates/variants/bun-hono/src/temporal/workflows.ts +10 -0
- package/templates/variants/bun-hono/src/waitlist/service.ts +166 -0
- package/templates/variants/bun-hono/src/waitlist/types.ts +50 -0
- package/templates/variants/bun-hono/test/app.test.ts +72 -41
- package/templates/variants/bun-hono/test/waitlist.integration.test.ts +102 -0
- package/templates/variants/go-chi/Makefile +27 -11
- package/templates/variants/go-chi/atlas.hcl +8 -0
- package/templates/variants/go-chi/cmd/server/main.go +21 -10
- package/templates/variants/go-chi/go.mod +1 -3
- package/templates/variants/go-chi/internal/app/service.go +202 -685
- package/templates/variants/go-chi/internal/auth/middleware.go +289 -0
- package/templates/variants/go-chi/internal/auth/middleware_test.go +38 -0
- package/templates/variants/go-chi/internal/config/config.go +27 -11
- package/templates/variants/go-chi/internal/httpapi/routes.go +78 -157
- package/templates/variants/go-chi/internal/httpapi/waitlist_integration_test.go +199 -0
- package/templates/variants/go-chi/internal/temporal/activities.go +27 -0
- package/templates/variants/go-chi/internal/temporal/worker.go +42 -0
- package/templates/variants/go-chi/internal/temporal/workflows.go +18 -0
- package/templates/variants/go-chi/migrations/0000_init.sql +12 -55
- package/templates/variants/go-chi/migrations/atlas.sum +2 -0
- package/templates/variants/go-chi/package.json +7 -1
- package/templates/variants/go-connectrpc/Makefile +26 -9
- package/templates/variants/go-connectrpc/atlas.hcl +8 -0
- package/templates/variants/go-connectrpc/buf.gen.yaml +2 -2
- package/templates/variants/go-connectrpc/cmd/server/main.go +23 -12
- package/templates/variants/go-connectrpc/gen/waitlist/v1/waitlist.pb.go +960 -0
- package/templates/variants/go-connectrpc/gen/waitlist/v1/waitlistv1connect/waitlist.connect.go +283 -0
- package/templates/variants/go-connectrpc/go.mod +1 -1
- package/templates/variants/go-connectrpc/internal/app/service.go +202 -685
- package/templates/variants/go-connectrpc/internal/auth/middleware.go +289 -0
- package/templates/variants/go-connectrpc/internal/auth/middleware_test.go +38 -0
- package/templates/variants/go-connectrpc/internal/config/config.go +27 -11
- package/templates/variants/go-connectrpc/internal/connectapi/handler.go +78 -201
- package/templates/variants/go-connectrpc/internal/connectapi/waitlist_integration_test.go +122 -0
- package/templates/variants/go-connectrpc/internal/httpapi/routes.go +147 -9
- package/templates/variants/go-connectrpc/internal/temporal/activities.go +27 -0
- package/templates/variants/go-connectrpc/internal/temporal/worker.go +42 -0
- package/templates/variants/go-connectrpc/internal/temporal/workflows.go +18 -0
- package/templates/variants/go-connectrpc/migrations/0000_init.sql +12 -55
- package/templates/variants/go-connectrpc/migrations/atlas.sum +2 -0
- package/templates/variants/go-connectrpc/package.json +7 -1
- package/templates/variants/go-connectrpc/protos/waitlist/v1/waitlist.proto +93 -0
- package/templates/root/.github/workflows/buf-publish.yml +0 -19
- package/templates/root/.github/workflows/ci.yml +0 -26
- package/templates/root/.github/workflows/deploy.yml +0 -22
- package/templates/root/Dockerfile +0 -23
- package/templates/root/README.md +0 -69
- package/templates/root/buf.gen.yaml +0 -10
- package/templates/root/buf.yaml +0 -9
- package/templates/root/cmd/server/main.go +0 -44
- package/templates/root/gen/dns/v1/dns.pb.go +0 -623
- package/templates/root/gen/dns/v1/dnsv1connect/dns.connect.go +0 -192
- package/templates/root/go.mod +0 -10
- package/templates/root/internal/app/service.go +0 -152
- package/templates/root/internal/app/token_source.go +0 -50
- package/templates/root/internal/cloudflare/client.go +0 -160
- package/templates/root/internal/config/config.go +0 -55
- package/templates/root/internal/connectapi/handler.go +0 -79
- package/templates/root/internal/httpapi/routes.go +0 -93
- package/templates/root/internal/vault/client.go +0 -148
- package/templates/root/package.json +0 -12
- package/templates/root/protos/dns/v1/dns.proto +0 -58
- package/templates/root/scripts/cloudrun/bootstrap.ts +0 -65
- package/templates/root/scripts/cloudrun/config.ts +0 -50
- package/templates/root/scripts/cloudrun/deploy.ts +0 -41
- package/templates/root/scripts/cloudrun/lib.ts +0 -244
- package/templates/root/service.yaml +0 -50
- package/templates/root/test/go.test.ts +0 -19
- package/templates/shared/scripts/cloudrun/integrations.ts +0 -111
- package/templates/variants/bun-connectrpc/gen/protos/chat/v1/chat_pb.ts +0 -1078
- package/templates/variants/bun-connectrpc/protos/chat/v1/chat.proto +0 -228
- package/templates/variants/bun-connectrpc/src/chat/service.ts +0 -384
- package/templates/variants/bun-connectrpc/src/chat/types.ts +0 -142
- package/templates/variants/bun-connectrpc/src/storage.ts +0 -72
- package/templates/variants/bun-connectrpc/src/webhooks.ts +0 -35
- package/templates/variants/bun-connectrpc/test/list-messages.integration.test.ts +0 -182
- package/templates/variants/bun-hono/src/chat/service.ts +0 -384
- package/templates/variants/bun-hono/src/chat/types.ts +0 -142
- package/templates/variants/bun-hono/src/storage.ts +0 -72
- package/templates/variants/bun-hono/src/webhooks.ts +0 -35
- package/templates/variants/bun-hono/test/list-messages.integration.test.ts +0 -256
- package/templates/variants/go-chi/buf.gen.yaml +0 -12
- package/templates/variants/go-chi/buf.yaml +0 -9
- package/templates/variants/go-chi/cmd/migrate/main.go +0 -101
- package/templates/variants/go-chi/internal/httpapi/list_messages_integration_test.go +0 -298
- package/templates/variants/go-chi/protos/chat/v1/chat.proto +0 -219
- package/templates/variants/go-connectrpc/cmd/migrate/main.go +0 -101
- package/templates/variants/go-connectrpc/gen/chat/v1/chat.pb.go +0 -2512
- package/templates/variants/go-connectrpc/gen/chat/v1/chatv1connect/chat.connect.go +0 -571
- package/templates/variants/go-connectrpc/internal/connectapi/list_messages_integration_test.go +0 -216
- package/templates/variants/go-connectrpc/protos/chat/v1/chat.proto +0 -232
- /package/bin/{create-svc.mjs → service.mjs} +0 -0
package/templates/variants/go-connectrpc/internal/connectapi/list_messages_integration_test.go
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
package connectapi
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"context"
|
|
5
|
-
"fmt"
|
|
6
|
-
"net/http"
|
|
7
|
-
"net/http/httptest"
|
|
8
|
-
"os"
|
|
9
|
-
"strings"
|
|
10
|
-
"testing"
|
|
11
|
-
"time"
|
|
12
|
-
|
|
13
|
-
"connectrpc.com/connect"
|
|
14
|
-
_ "github.com/jackc/pgx/v5/stdlib"
|
|
15
|
-
"github.com/jmoiron/sqlx"
|
|
16
|
-
|
|
17
|
-
chatv1 "{{MODULE_PATH}}/gen/chat/v1"
|
|
18
|
-
chatv1connect "{{MODULE_PATH}}/gen/chat/v1/chatv1connect"
|
|
19
|
-
"{{MODULE_PATH}}/internal/app"
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
func TestListMessagesPaginationIncludesAttachmentMetadata(t *testing.T) {
|
|
23
|
-
databaseURL := strings.TrimSpace(os.Getenv("DATABASE_URL"))
|
|
24
|
-
if databaseURL == "" {
|
|
25
|
-
t.Skip("DATABASE_URL is required for integration test")
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
t.Setenv("ATTACHMENT_PUBLIC_BASE_URL", "https://storage.test")
|
|
29
|
-
|
|
30
|
-
db, err := app.OpenDatabase(context.Background(), databaseURL)
|
|
31
|
-
if err != nil {
|
|
32
|
-
t.Fatalf("open database: %v", err)
|
|
33
|
-
}
|
|
34
|
-
t.Cleanup(func() { _ = db.Close() })
|
|
35
|
-
|
|
36
|
-
if _, err := db.ExecContext(context.Background(), `
|
|
37
|
-
truncate table
|
|
38
|
-
webhook_events,
|
|
39
|
-
attachments,
|
|
40
|
-
messages,
|
|
41
|
-
conversation_participants,
|
|
42
|
-
conversations,
|
|
43
|
-
users
|
|
44
|
-
restart identity cascade`); err != nil {
|
|
45
|
-
t.Fatalf("truncate tables: %v", err)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
storage := newFakeStorage()
|
|
49
|
-
service := app.NewChatService(db, storage, app.GenericWebhookAdapter{})
|
|
50
|
-
path, handler := NewHandler(service)
|
|
51
|
-
mux := http.NewServeMux()
|
|
52
|
-
mux.Handle(path, handler)
|
|
53
|
-
server := httptest.NewServer(mux)
|
|
54
|
-
t.Cleanup(server.Close)
|
|
55
|
-
|
|
56
|
-
client := chatv1connect.NewChatServiceClient(http.DefaultClient, server.URL)
|
|
57
|
-
|
|
58
|
-
createUserResponse, err := client.CreateUser(context.Background(), connect.NewRequest(&chatv1.CreateUserRequest{
|
|
59
|
-
Username: "alice",
|
|
60
|
-
DisplayName: "Alice",
|
|
61
|
-
}))
|
|
62
|
-
if err != nil {
|
|
63
|
-
t.Fatalf("create user: %v", err)
|
|
64
|
-
}
|
|
65
|
-
userID := createUserResponse.Msg.GetUser().GetId()
|
|
66
|
-
|
|
67
|
-
createConversationResponse, err := client.CreateConversation(context.Background(), connect.NewRequest(&chatv1.CreateConversationRequest{
|
|
68
|
-
CreatedByUserId: userID,
|
|
69
|
-
Title: "General",
|
|
70
|
-
ParticipantUserIds: []string{userID},
|
|
71
|
-
}))
|
|
72
|
-
if err != nil {
|
|
73
|
-
t.Fatalf("create conversation: %v", err)
|
|
74
|
-
}
|
|
75
|
-
conversationID := createConversationResponse.Msg.GetConversation().GetId()
|
|
76
|
-
|
|
77
|
-
messageIDs := make([]string, 0, 55)
|
|
78
|
-
for index := 1; index <= 55; index++ {
|
|
79
|
-
response, err := client.CreateMessage(context.Background(), connect.NewRequest(&chatv1.CreateMessageRequest{
|
|
80
|
-
ConversationId: conversationID,
|
|
81
|
-
UserId: userID,
|
|
82
|
-
Body: fmt.Sprintf("message-%d", index),
|
|
83
|
-
}))
|
|
84
|
-
if err != nil {
|
|
85
|
-
t.Fatalf("create message %d: %v", index, err)
|
|
86
|
-
}
|
|
87
|
-
messageIDs = append(messageIDs, response.Msg.GetMessage().GetId())
|
|
88
|
-
}
|
|
89
|
-
rewriteMessageTimestamps(t, db, messageIDs)
|
|
90
|
-
|
|
91
|
-
uploadResponse, err := client.CreateAttachmentUpload(context.Background(), connect.NewRequest(&chatv1.CreateAttachmentUploadRequest{
|
|
92
|
-
ConversationId: conversationID,
|
|
93
|
-
UserId: userID,
|
|
94
|
-
Filename: "photo.png",
|
|
95
|
-
ContentType: "image/png",
|
|
96
|
-
ByteSize: 1234,
|
|
97
|
-
}))
|
|
98
|
-
if err != nil {
|
|
99
|
-
t.Fatalf("create attachment upload: %v", err)
|
|
100
|
-
}
|
|
101
|
-
storage.set(uploadResponse.Msg.GetAttachment().GetPublicUrl(), "image/png", 1234)
|
|
102
|
-
if _, err := client.FinalizeAttachment(context.Background(), connect.NewRequest(&chatv1.FinalizeAttachmentRequest{
|
|
103
|
-
AttachmentId: uploadResponse.Msg.GetAttachment().GetId(),
|
|
104
|
-
MessageId: messageIDs[54],
|
|
105
|
-
})); err != nil {
|
|
106
|
-
t.Fatalf("finalize attachment: %v", err)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
firstPage, err := client.ListMessages(context.Background(), connect.NewRequest(&chatv1.ListMessagesRequest{
|
|
110
|
-
ConversationId: conversationID,
|
|
111
|
-
}))
|
|
112
|
-
if err != nil {
|
|
113
|
-
t.Fatalf("list messages first page: %v", err)
|
|
114
|
-
}
|
|
115
|
-
if len(firstPage.Msg.GetMessages()) != 50 {
|
|
116
|
-
t.Fatalf("expected 50 messages, got %d", len(firstPage.Msg.GetMessages()))
|
|
117
|
-
}
|
|
118
|
-
if firstPage.Msg.GetMessages()[0].GetBody() != "message-55" {
|
|
119
|
-
t.Fatalf("expected newest message first, got %s", firstPage.Msg.GetMessages()[0].GetBody())
|
|
120
|
-
}
|
|
121
|
-
if firstPage.Msg.GetMessages()[49].GetBody() != "message-6" {
|
|
122
|
-
t.Fatalf("expected oldest message on first page to be message-6, got %s", firstPage.Msg.GetMessages()[49].GetBody())
|
|
123
|
-
}
|
|
124
|
-
if firstPage.Msg.GetNextCursor() == "" {
|
|
125
|
-
t.Fatal("expected next cursor on first page")
|
|
126
|
-
}
|
|
127
|
-
attachments := firstPage.Msg.GetMessages()[0].GetAttachments()
|
|
128
|
-
if len(attachments) != 1 {
|
|
129
|
-
t.Fatalf("expected attachment metadata on newest message, got %#v", attachments)
|
|
130
|
-
}
|
|
131
|
-
if attachments[0].GetPublicUrl() != uploadResponse.Msg.GetAttachment().GetPublicUrl() {
|
|
132
|
-
t.Fatalf("expected public_url %s, got %s", uploadResponse.Msg.GetAttachment().GetPublicUrl(), attachments[0].GetPublicUrl())
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
secondPage, err := client.ListMessages(context.Background(), connect.NewRequest(&chatv1.ListMessagesRequest{
|
|
136
|
-
ConversationId: conversationID,
|
|
137
|
-
Cursor: firstPage.Msg.GetNextCursor(),
|
|
138
|
-
}))
|
|
139
|
-
if err != nil {
|
|
140
|
-
t.Fatalf("list messages second page: %v", err)
|
|
141
|
-
}
|
|
142
|
-
expectedBodies := []string{"message-5", "message-4", "message-3", "message-2", "message-1"}
|
|
143
|
-
if len(secondPage.Msg.GetMessages()) != len(expectedBodies) {
|
|
144
|
-
t.Fatalf("expected %d messages on second page, got %d", len(expectedBodies), len(secondPage.Msg.GetMessages()))
|
|
145
|
-
}
|
|
146
|
-
for index, body := range expectedBodies {
|
|
147
|
-
if secondPage.Msg.GetMessages()[index].GetBody() != body {
|
|
148
|
-
t.Fatalf("expected %s at index %d, got %s", body, index, secondPage.Msg.GetMessages()[index].GetBody())
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if secondPage.Msg.GetNextCursor() != "" {
|
|
152
|
-
t.Fatalf("expected no next cursor on final page, got %s", secondPage.Msg.GetNextCursor())
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
type fakeStorage struct {
|
|
157
|
-
metadata map[string]struct {
|
|
158
|
-
contentType string
|
|
159
|
-
byteSize int64
|
|
160
|
-
publicURL string
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
func newFakeStorage() *fakeStorage {
|
|
165
|
-
return &fakeStorage{metadata: map[string]struct {
|
|
166
|
-
contentType string
|
|
167
|
-
byteSize int64
|
|
168
|
-
publicURL string
|
|
169
|
-
}{}}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
func (f *fakeStorage) CreateSignedUpload(_ context.Context, attachmentID string, conversationID string, filename string, contentType string) (string, string, app.UploadTarget, string, error) {
|
|
173
|
-
key := fmt.Sprintf("attachments/%s/%s/%s", conversationID, attachmentID, filename)
|
|
174
|
-
return "test-bucket", key, app.UploadTarget{
|
|
175
|
-
Method: http.MethodPut,
|
|
176
|
-
URL: "https://uploads.test/" + key,
|
|
177
|
-
Headers: map[string]string{
|
|
178
|
-
"Content-Type": contentType,
|
|
179
|
-
},
|
|
180
|
-
}, "https://storage.test/" + key, nil
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
func (f *fakeStorage) GetObjectMetadata(_ context.Context, bucket string, key string) (string, int64, string, error) {
|
|
184
|
-
entry, ok := f.metadata[bucket+"/"+key]
|
|
185
|
-
if !ok {
|
|
186
|
-
return "", 0, "", fmt.Errorf("missing metadata for %s/%s", bucket, key)
|
|
187
|
-
}
|
|
188
|
-
return entry.contentType, entry.byteSize, entry.publicURL, nil
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
func (f *fakeStorage) set(publicURL string, contentType string, byteSize int64) {
|
|
192
|
-
key := strings.TrimPrefix(publicURL, "https://storage.test/")
|
|
193
|
-
f.metadata["test-bucket/"+key] = struct {
|
|
194
|
-
contentType string
|
|
195
|
-
byteSize int64
|
|
196
|
-
publicURL string
|
|
197
|
-
}{
|
|
198
|
-
contentType: contentType,
|
|
199
|
-
byteSize: byteSize,
|
|
200
|
-
publicURL: publicURL,
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
func rewriteMessageTimestamps(t *testing.T, db *sqlx.DB, messageIDs []string) {
|
|
205
|
-
t.Helper()
|
|
206
|
-
baseTime := time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC)
|
|
207
|
-
for index, messageID := range messageIDs {
|
|
208
|
-
createdAt := baseTime.Add(time.Duration(index+1) * time.Second)
|
|
209
|
-
if _, err := db.ExecContext(context.Background(), `
|
|
210
|
-
update messages
|
|
211
|
-
set created_at = $2, updated_at = $2
|
|
212
|
-
where id = $1`, messageID, createdAt); err != nil {
|
|
213
|
-
t.Fatalf("rewrite message timestamp: %v", err)
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
@@ -1,232 +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
|
-
repeated MessageAttachment attachments = 8;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
message MessageAttachment {
|
|
56
|
-
string id = 1;
|
|
57
|
-
string filename = 2;
|
|
58
|
-
string content_type = 3;
|
|
59
|
-
int64 byte_size = 4;
|
|
60
|
-
string status = 5;
|
|
61
|
-
string public_url = 6;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
message Attachment {
|
|
65
|
-
string id = 1;
|
|
66
|
-
string conversation_id = 2;
|
|
67
|
-
string message_id = 3;
|
|
68
|
-
string uploaded_by_user_id = 4;
|
|
69
|
-
string storage_bucket = 5;
|
|
70
|
-
string storage_key = 6;
|
|
71
|
-
string content_type = 7;
|
|
72
|
-
int64 byte_size = 8;
|
|
73
|
-
string filename = 9;
|
|
74
|
-
string status = 10;
|
|
75
|
-
string public_url = 11;
|
|
76
|
-
string created_at = 12;
|
|
77
|
-
string updated_at = 13;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
message UploadTarget {
|
|
81
|
-
string method = 1;
|
|
82
|
-
string url = 2;
|
|
83
|
-
map<string, string> headers = 3;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
message CreateUserRequest {
|
|
87
|
-
string username = 1;
|
|
88
|
-
string display_name = 2;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
message CreateUserResponse {
|
|
92
|
-
User user = 1;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
message GetUserRequest {
|
|
96
|
-
string user_id = 1;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
message GetUserResponse {
|
|
100
|
-
User user = 1;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
message GetUserByUsernameRequest {
|
|
104
|
-
string username = 1;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
message GetUserByUsernameResponse {
|
|
108
|
-
User user = 1;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
message CreateConversationRequest {
|
|
112
|
-
string created_by_user_id = 1;
|
|
113
|
-
string title = 2;
|
|
114
|
-
repeated string participant_user_ids = 3;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
message CreateConversationResponse {
|
|
118
|
-
Conversation conversation = 1;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
message GetConversationRequest {
|
|
122
|
-
string conversation_id = 1;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
message GetConversationResponse {
|
|
126
|
-
Conversation conversation = 1;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
message UpdateConversationRequest {
|
|
130
|
-
string conversation_id = 1;
|
|
131
|
-
string title = 2;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
message UpdateConversationResponse {
|
|
135
|
-
Conversation conversation = 1;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
message DeleteConversationRequest {
|
|
139
|
-
string conversation_id = 1;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
message DeleteConversationResponse {}
|
|
143
|
-
|
|
144
|
-
message AddConversationParticipantRequest {
|
|
145
|
-
string conversation_id = 1;
|
|
146
|
-
string user_id = 2;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
message AddConversationParticipantResponse {
|
|
150
|
-
Conversation conversation = 1;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
message RemoveConversationParticipantRequest {
|
|
154
|
-
string conversation_id = 1;
|
|
155
|
-
string user_id = 2;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
message RemoveConversationParticipantResponse {}
|
|
159
|
-
|
|
160
|
-
message ListMessagesRequest {
|
|
161
|
-
string conversation_id = 1;
|
|
162
|
-
string cursor = 2;
|
|
163
|
-
int32 limit = 3;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
message ListMessagesResponse {
|
|
167
|
-
repeated Message messages = 1;
|
|
168
|
-
string next_cursor = 2;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
message CreateMessageRequest {
|
|
172
|
-
string conversation_id = 1;
|
|
173
|
-
string user_id = 2;
|
|
174
|
-
string body = 3;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
message CreateMessageResponse {
|
|
178
|
-
Message message = 1;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
message UpdateMessageRequest {
|
|
182
|
-
string conversation_id = 1;
|
|
183
|
-
string message_id = 2;
|
|
184
|
-
string body = 3;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
message UpdateMessageResponse {
|
|
188
|
-
Message message = 1;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
message DeleteMessageRequest {
|
|
192
|
-
string conversation_id = 1;
|
|
193
|
-
string message_id = 2;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
message DeleteMessageResponse {}
|
|
197
|
-
|
|
198
|
-
message CreateAttachmentUploadRequest {
|
|
199
|
-
string conversation_id = 1;
|
|
200
|
-
string user_id = 2;
|
|
201
|
-
string filename = 3;
|
|
202
|
-
string content_type = 4;
|
|
203
|
-
int64 byte_size = 5;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
message CreateAttachmentUploadResponse {
|
|
207
|
-
Attachment attachment = 1;
|
|
208
|
-
UploadTarget upload = 2;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
message FinalizeAttachmentRequest {
|
|
212
|
-
string attachment_id = 1;
|
|
213
|
-
string message_id = 2;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
message FinalizeAttachmentResponse {
|
|
217
|
-
Attachment attachment = 1;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
message GetAttachmentRequest {
|
|
221
|
-
string attachment_id = 1;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
message GetAttachmentResponse {
|
|
225
|
-
Attachment attachment = 1;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
message DeleteAttachmentRequest {
|
|
229
|
-
string attachment_id = 1;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
message DeleteAttachmentResponse {}
|
|
File without changes
|