@mastra/factory 0.0.0 → 0.1.0-alpha.3
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/CHANGELOG.md +23 -0
- package/LICENSE.md +30 -0
- package/dist/auth.d.ts +181 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +370 -0
- package/dist/auth.js.map +1 -0
- package/dist/capabilities/connection.d.ts +9 -0
- package/dist/capabilities/connection.d.ts.map +1 -0
- package/dist/capabilities/connection.js +1 -0
- package/dist/capabilities/connection.js.map +1 -0
- package/dist/capabilities/intake.d.ts +93 -0
- package/dist/capabilities/intake.d.ts.map +1 -0
- package/dist/capabilities/intake.js +1 -0
- package/dist/capabilities/intake.js.map +1 -0
- package/dist/capabilities/version-control.d.ts +239 -0
- package/dist/capabilities/version-control.d.ts.map +1 -0
- package/dist/capabilities/version-control.js +1 -0
- package/dist/capabilities/version-control.js.map +1 -0
- package/dist/factory.d.ts +145 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +38245 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38245 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/base.d.ts +197 -0
- package/dist/integrations/base.d.ts.map +1 -0
- package/dist/integrations/base.js +1 -0
- package/dist/integrations/base.js.map +1 -0
- package/dist/integrations/github/config.d.ts +60 -0
- package/dist/integrations/github/config.d.ts.map +1 -0
- package/dist/integrations/github/config.js +28 -0
- package/dist/integrations/github/config.js.map +1 -0
- package/dist/integrations/github/factory-session.d.ts +12 -0
- package/dist/integrations/github/factory-session.d.ts.map +1 -0
- package/dist/integrations/github/factory-session.js +41 -0
- package/dist/integrations/github/factory-session.js.map +1 -0
- package/dist/integrations/github/integration.d.ts +191 -0
- package/dist/integrations/github/integration.d.ts.map +1 -0
- package/dist/integrations/github/integration.js +3001 -0
- package/dist/integrations/github/integration.js.map +1 -0
- package/dist/integrations/github/issue-triage.d.ts +27 -0
- package/dist/integrations/github/issue-triage.d.ts.map +1 -0
- package/dist/integrations/github/issue-triage.js +82 -0
- package/dist/integrations/github/issue-triage.js.map +1 -0
- package/dist/integrations/github/project-lock.d.ts +78 -0
- package/dist/integrations/github/project-lock.d.ts.map +1 -0
- package/dist/integrations/github/project-lock.js +70 -0
- package/dist/integrations/github/project-lock.js.map +1 -0
- package/dist/integrations/github/provenance.d.ts +27 -0
- package/dist/integrations/github/provenance.d.ts.map +1 -0
- package/dist/integrations/github/provenance.js +104 -0
- package/dist/integrations/github/provenance.js.map +1 -0
- package/dist/integrations/github/routes.d.ts +72 -0
- package/dist/integrations/github/routes.d.ts.map +1 -0
- package/dist/integrations/github/routes.js +1834 -0
- package/dist/integrations/github/routes.js.map +1 -0
- package/dist/integrations/github/sandbox.d.ts +268 -0
- package/dist/integrations/github/sandbox.d.ts.map +1 -0
- package/dist/integrations/github/sandbox.js +381 -0
- package/dist/integrations/github/sandbox.js.map +1 -0
- package/dist/integrations/github/session-subscriptions.d.ts +23 -0
- package/dist/integrations/github/session-subscriptions.d.ts.map +1 -0
- package/dist/integrations/github/session-subscriptions.js +190 -0
- package/dist/integrations/github/session-subscriptions.js.map +1 -0
- package/dist/integrations/github/subscriptions.d.ts +54 -0
- package/dist/integrations/github/subscriptions.d.ts.map +1 -0
- package/dist/integrations/github/subscriptions.js +70 -0
- package/dist/integrations/github/subscriptions.js.map +1 -0
- package/dist/integrations/github/webhook.d.ts +87 -0
- package/dist/integrations/github/webhook.d.ts.map +1 -0
- package/dist/integrations/github/webhook.js +381 -0
- package/dist/integrations/github/webhook.js.map +1 -0
- package/dist/integrations/linear/agent-tools.d.ts +34 -0
- package/dist/integrations/linear/agent-tools.d.ts.map +1 -0
- package/dist/integrations/linear/agent-tools.js +108 -0
- package/dist/integrations/linear/agent-tools.js.map +1 -0
- package/dist/integrations/linear/integration.d.ts +233 -0
- package/dist/integrations/linear/integration.d.ts.map +1 -0
- package/dist/integrations/linear/integration.js +962 -0
- package/dist/integrations/linear/integration.js.map +1 -0
- package/dist/integrations/linear/routes.d.ts +61 -0
- package/dist/integrations/linear/routes.d.ts.map +1 -0
- package/dist/integrations/linear/routes.js +242 -0
- package/dist/integrations/linear/routes.js.map +1 -0
- package/dist/integrations/linear/storage.d.ts +65 -0
- package/dist/integrations/linear/storage.d.ts.map +1 -0
- package/dist/integrations/linear/storage.js +1 -0
- package/dist/integrations/linear/storage.js.map +1 -0
- package/dist/integrations/platform/api-client.d.ts +24 -0
- package/dist/integrations/platform/api-client.d.ts.map +1 -0
- package/dist/integrations/platform/api-client.js +153 -0
- package/dist/integrations/platform/api-client.js.map +1 -0
- package/dist/integrations/platform/github/event-worker.d.ts +44 -0
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -0
- package/dist/integrations/platform/github/event-worker.js +585 -0
- package/dist/integrations/platform/github/event-worker.js.map +1 -0
- package/dist/integrations/platform/github/integration.d.ts +36 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -0
- package/dist/integrations/platform/github/integration.js +3253 -0
- package/dist/integrations/platform/github/integration.js.map +1 -0
- package/dist/integrations/platform/linear/integration.d.ts +46 -0
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -0
- package/dist/integrations/platform/linear/integration.js +891 -0
- package/dist/integrations/platform/linear/integration.js.map +1 -0
- package/dist/integrations/workos/integration.d.ts +39 -0
- package/dist/integrations/workos/integration.d.ts.map +1 -0
- package/dist/integrations/workos/integration.js +96 -0
- package/dist/integrations/workos/integration.js.map +1 -0
- package/dist/routes/config.d.ts +220 -0
- package/dist/routes/config.d.ts.map +1 -0
- package/dist/routes/config.js +770 -0
- package/dist/routes/config.js.map +1 -0
- package/dist/routes/fs.d.ts +105 -0
- package/dist/routes/fs.d.ts.map +1 -0
- package/dist/routes/fs.js +294 -0
- package/dist/routes/fs.js.map +1 -0
- package/dist/routes/intake.d.ts +23 -0
- package/dist/routes/intake.d.ts.map +1 -0
- package/dist/routes/intake.js +179 -0
- package/dist/routes/intake.js.map +1 -0
- package/dist/routes/oauth.d.ts +43 -0
- package/dist/routes/oauth.d.ts.map +1 -0
- package/dist/routes/oauth.js +25058 -0
- package/dist/routes/oauth.js.map +1 -0
- package/dist/routes/projects.d.ts +19 -0
- package/dist/routes/projects.d.ts.map +1 -0
- package/dist/routes/projects.js +395 -0
- package/dist/routes/projects.js.map +1 -0
- package/dist/routes/provider-credentials.d.ts +81 -0
- package/dist/routes/provider-credentials.d.ts.map +1 -0
- package/dist/routes/provider-credentials.js +68 -0
- package/dist/routes/provider-credentials.js.map +1 -0
- package/dist/routes/route.d.ts +48 -0
- package/dist/routes/route.d.ts.map +1 -0
- package/dist/routes/route.js +11 -0
- package/dist/routes/route.js.map +1 -0
- package/dist/routes/skills.d.ts +30 -0
- package/dist/routes/skills.d.ts.map +1 -0
- package/dist/routes/skills.js +181 -0
- package/dist/routes/skills.js.map +1 -0
- package/dist/routes/surface.d.ts +83 -0
- package/dist/routes/surface.d.ts.map +1 -0
- package/dist/routes/surface.js +28519 -0
- package/dist/routes/surface.js.map +1 -0
- package/dist/routes/tenant-credentials.d.ts +74 -0
- package/dist/routes/tenant-credentials.d.ts.map +1 -0
- package/dist/routes/tenant-credentials.js +181 -0
- package/dist/routes/tenant-credentials.js.map +1 -0
- package/dist/routes/work-items.d.ts +40 -0
- package/dist/routes/work-items.d.ts.map +1 -0
- package/dist/routes/work-items.js +902 -0
- package/dist/routes/work-items.js.map +1 -0
- package/dist/rules/binding-context.d.ts +5 -0
- package/dist/rules/binding-context.d.ts.map +1 -0
- package/dist/rules/binding-context.js +40 -0
- package/dist/rules/binding-context.js.map +1 -0
- package/dist/rules/defaults.d.ts +9 -0
- package/dist/rules/defaults.d.ts.map +1 -0
- package/dist/rules/defaults.js +334 -0
- package/dist/rules/defaults.js.map +1 -0
- package/dist/rules/dispatcher.d.ts +40 -0
- package/dist/rules/dispatcher.d.ts.map +1 -0
- package/dist/rules/dispatcher.js +695 -0
- package/dist/rules/dispatcher.js.map +1 -0
- package/dist/rules/github-service.d.ts +29 -0
- package/dist/rules/github-service.d.ts.map +1 -0
- package/dist/rules/github-service.js +474 -0
- package/dist/rules/github-service.js.map +1 -0
- package/dist/rules/index.d.ts +7 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +583 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/linear-service.d.ts +27 -0
- package/dist/rules/linear-service.d.ts.map +1 -0
- package/dist/rules/linear-service.js +343 -0
- package/dist/rules/linear-service.js.map +1 -0
- package/dist/rules/processor.d.ts +54 -0
- package/dist/rules/processor.d.ts.map +1 -0
- package/dist/rules/processor.js +629 -0
- package/dist/rules/processor.js.map +1 -0
- package/dist/rules/resolve.d.ts +17 -0
- package/dist/rules/resolve.d.ts.map +1 -0
- package/dist/rules/resolve.js +27 -0
- package/dist/rules/resolve.js.map +1 -0
- package/dist/rules/start-coordinator.d.ts +58 -0
- package/dist/rules/start-coordinator.d.ts.map +1 -0
- package/dist/rules/start-coordinator.js +136 -0
- package/dist/rules/start-coordinator.js.map +1 -0
- package/dist/rules/tools.d.ts +10 -0
- package/dist/rules/tools.d.ts.map +1 -0
- package/dist/rules/tools.js +93 -0
- package/dist/rules/tools.js.map +1 -0
- package/dist/rules/transition-service.d.ts +32 -0
- package/dist/rules/transition-service.d.ts.map +1 -0
- package/dist/rules/transition-service.js +474 -0
- package/dist/rules/transition-service.js.map +1 -0
- package/dist/rules/types.d.ts +225 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +33 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/rules/validation.d.ts +11 -0
- package/dist/rules/validation.d.ts.map +1 -0
- package/dist/rules/validation.js +310 -0
- package/dist/rules/validation.js.map +1 -0
- package/dist/sandbox/fleet.d.ts +208 -0
- package/dist/sandbox/fleet.d.ts.map +1 -0
- package/dist/sandbox/fleet.js +259 -0
- package/dist/sandbox/fleet.js.map +1 -0
- package/dist/sandbox/reattach.d.ts +3 -0
- package/dist/sandbox/reattach.d.ts.map +1 -0
- package/dist/sandbox/reattach.js +9 -0
- package/dist/sandbox/reattach.js.map +1 -0
- package/dist/server-error.d.ts +12 -0
- package/dist/server-error.d.ts.map +1 -0
- package/dist/server-error.js +20 -0
- package/dist/server-error.js.map +1 -0
- package/dist/skills/service.d.ts +48 -0
- package/dist/skills/service.d.ts.map +1 -0
- package/dist/skills/service.js +45 -0
- package/dist/skills/service.js.map +1 -0
- package/dist/spa-static.d.ts +34 -0
- package/dist/spa-static.d.ts.map +1 -0
- package/dist/spa-static.js +73 -0
- package/dist/spa-static.js.map +1 -0
- package/dist/state-signing.d.ts +48 -0
- package/dist/state-signing.d.ts.map +1 -0
- package/dist/state-signing.js +48 -0
- package/dist/state-signing.js.map +1 -0
- package/dist/storage/domains/audit/agent-audit.d.ts +27 -0
- package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -0
- package/dist/storage/domains/audit/agent-audit.js +65 -0
- package/dist/storage/domains/audit/agent-audit.js.map +1 -0
- package/dist/storage/domains/audit/base.d.ts +140 -0
- package/dist/storage/domains/audit/base.d.ts.map +1 -0
- package/dist/storage/domains/audit/base.js +127 -0
- package/dist/storage/domains/audit/base.js.map +1 -0
- package/dist/storage/domains/audit/domain.d.ts +69 -0
- package/dist/storage/domains/audit/domain.d.ts.map +1 -0
- package/dist/storage/domains/audit/domain.js +165 -0
- package/dist/storage/domains/audit/domain.js.map +1 -0
- package/dist/storage/domains/credentials/base.d.ts +134 -0
- package/dist/storage/domains/credentials/base.d.ts.map +1 -0
- package/dist/storage/domains/credentials/base.js +257 -0
- package/dist/storage/domains/credentials/base.js.map +1 -0
- package/dist/storage/domains/intake/base.d.ts +38 -0
- package/dist/storage/domains/intake/base.d.ts.map +1 -0
- package/dist/storage/domains/intake/base.js +62 -0
- package/dist/storage/domains/intake/base.js.map +1 -0
- package/dist/storage/domains/integrations/base.d.ts +126 -0
- package/dist/storage/domains/integrations/base.d.ts.map +1 -0
- package/dist/storage/domains/integrations/base.js +252 -0
- package/dist/storage/domains/integrations/base.js.map +1 -0
- package/dist/storage/domains/model-packs/base.d.ts +49 -0
- package/dist/storage/domains/model-packs/base.d.ts.map +1 -0
- package/dist/storage/domains/model-packs/base.js +95 -0
- package/dist/storage/domains/model-packs/base.js.map +1 -0
- package/dist/storage/domains/projects/base.d.ts +55 -0
- package/dist/storage/domains/projects/base.d.ts.map +1 -0
- package/dist/storage/domains/projects/base.js +99 -0
- package/dist/storage/domains/projects/base.js.map +1 -0
- package/dist/storage/domains/queue-health/base.d.ts +52 -0
- package/dist/storage/domains/queue-health/base.d.ts.map +1 -0
- package/dist/storage/domains/queue-health/base.js +87 -0
- package/dist/storage/domains/queue-health/base.js.map +1 -0
- package/dist/storage/domains/source-control/base.d.ts +288 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -0
- package/dist/storage/domains/source-control/base.js +722 -0
- package/dist/storage/domains/source-control/base.js.map +1 -0
- package/dist/storage/domains/source-control/inmemory.d.ts +158 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/source-control/inmemory.js +348 -0
- package/dist/storage/domains/source-control/inmemory.js.map +1 -0
- package/dist/storage/domains/work-items/base.d.ts +412 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -0
- package/dist/storage/domains/work-items/base.js +1174 -0
- package/dist/storage/domains/work-items/base.js.map +1 -0
- package/dist/storage/domains/work-items/metrics.d.ts +101 -0
- package/dist/storage/domains/work-items/metrics.d.ts.map +1 -0
- package/dist/storage/domains/work-items/metrics.js +203 -0
- package/dist/storage/domains/work-items/metrics.js.map +1 -0
- package/dist/workspace.d.ts +20 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +364 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +19 -19
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
// src/storage/domains/source-control/base.ts
|
|
2
|
+
import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
|
|
3
|
+
var FACTORY_PROJECTS = "factory_projects";
|
|
4
|
+
var INSTALLATIONS = "source_control_installations";
|
|
5
|
+
var REPOSITORIES = "source_control_repositories";
|
|
6
|
+
var CONNECTIONS = "factory_project_source_control_connections";
|
|
7
|
+
var PROJECT_REPOSITORIES = "factory_project_repositories";
|
|
8
|
+
var SANDBOXES = "source_control_project_repository_sandboxes";
|
|
9
|
+
var WORKTREES = "source_control_worktrees";
|
|
10
|
+
var SESSIONS = "source_control_sessions";
|
|
11
|
+
var SOURCE_CONTROL_SCHEMAS = [
|
|
12
|
+
{
|
|
13
|
+
name: INSTALLATIONS,
|
|
14
|
+
columns: {
|
|
15
|
+
id: { type: "uuid-pk" },
|
|
16
|
+
integration_id: { type: "text" },
|
|
17
|
+
org_id: { type: "text" },
|
|
18
|
+
connected_by_user_id: { type: "text" },
|
|
19
|
+
external_id: { type: "text" },
|
|
20
|
+
account_name: { type: "text", nullable: true },
|
|
21
|
+
account_type: { type: "text", nullable: true },
|
|
22
|
+
provider_metadata: { type: "json" },
|
|
23
|
+
created_at: { type: "timestamp" }
|
|
24
|
+
},
|
|
25
|
+
uniqueIndexes: [
|
|
26
|
+
{
|
|
27
|
+
name: "source_control_installations_integration_org_external_unique",
|
|
28
|
+
columns: ["integration_id", "org_id", "external_id"]
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: REPOSITORIES,
|
|
34
|
+
columns: {
|
|
35
|
+
id: { type: "uuid-pk" },
|
|
36
|
+
installation_id: { type: "text" },
|
|
37
|
+
external_id: { type: "text" },
|
|
38
|
+
slug: { type: "text" },
|
|
39
|
+
default_branch: { type: "text", default: "main" },
|
|
40
|
+
provider_metadata: { type: "json" },
|
|
41
|
+
created_at: { type: "timestamp" },
|
|
42
|
+
updated_at: { type: "timestamp" }
|
|
43
|
+
},
|
|
44
|
+
uniqueIndexes: [
|
|
45
|
+
{
|
|
46
|
+
name: "source_control_repositories_installation_external_unique",
|
|
47
|
+
columns: ["installation_id", "external_id"]
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
indexes: [
|
|
51
|
+
{
|
|
52
|
+
name: "source_control_repositories_installation_slug_idx",
|
|
53
|
+
columns: ["installation_id", "slug"]
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: CONNECTIONS,
|
|
59
|
+
columns: {
|
|
60
|
+
id: { type: "uuid-pk" },
|
|
61
|
+
factory_project_id: { type: "text" },
|
|
62
|
+
integration_id: { type: "text" },
|
|
63
|
+
installation_id: { type: "text" },
|
|
64
|
+
created_by_user_id: { type: "text" },
|
|
65
|
+
created_at: { type: "timestamp" }
|
|
66
|
+
},
|
|
67
|
+
uniqueIndexes: [
|
|
68
|
+
{
|
|
69
|
+
name: "factory_project_source_control_connections_project_integration_installation_unique",
|
|
70
|
+
columns: ["factory_project_id", "integration_id", "installation_id"]
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
indexes: [
|
|
74
|
+
{
|
|
75
|
+
name: "factory_project_source_control_connections_project_idx",
|
|
76
|
+
columns: ["factory_project_id"]
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: PROJECT_REPOSITORIES,
|
|
82
|
+
columns: {
|
|
83
|
+
id: { type: "uuid-pk" },
|
|
84
|
+
connection_id: { type: "text" },
|
|
85
|
+
repository_id: { type: "text" },
|
|
86
|
+
created_by_user_id: { type: "text" },
|
|
87
|
+
branch: { type: "text", nullable: true },
|
|
88
|
+
sandbox_provider: { type: "text" },
|
|
89
|
+
sandbox_workdir: { type: "text" },
|
|
90
|
+
setup_command: { type: "text", nullable: true },
|
|
91
|
+
created_at: { type: "timestamp" },
|
|
92
|
+
updated_at: { type: "timestamp" }
|
|
93
|
+
},
|
|
94
|
+
uniqueIndexes: [
|
|
95
|
+
{
|
|
96
|
+
name: "factory_project_repositories_connection_repository_unique",
|
|
97
|
+
columns: ["connection_id", "repository_id"]
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
indexes: [
|
|
101
|
+
{
|
|
102
|
+
name: "factory_project_repositories_connection_idx",
|
|
103
|
+
columns: ["connection_id"]
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: SANDBOXES,
|
|
109
|
+
columns: {
|
|
110
|
+
id: { type: "uuid-pk" },
|
|
111
|
+
project_repository_id: { type: "text" },
|
|
112
|
+
user_id: { type: "text" },
|
|
113
|
+
sandbox_id: { type: "text", nullable: true },
|
|
114
|
+
sandbox_workdir: { type: "text" },
|
|
115
|
+
materialized_at: { type: "timestamp", nullable: true },
|
|
116
|
+
created_at: { type: "timestamp" }
|
|
117
|
+
},
|
|
118
|
+
uniqueIndexes: [
|
|
119
|
+
{
|
|
120
|
+
name: "source_control_project_repository_sandboxes_link_user_unique",
|
|
121
|
+
columns: ["project_repository_id", "user_id"]
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: WORKTREES,
|
|
127
|
+
columns: {
|
|
128
|
+
id: { type: "uuid-pk" },
|
|
129
|
+
project_repository_id: { type: "text" },
|
|
130
|
+
user_id: { type: "text" },
|
|
131
|
+
branch: { type: "text" },
|
|
132
|
+
base_branch: { type: "text" },
|
|
133
|
+
worktree_path: { type: "text" },
|
|
134
|
+
created_at: { type: "timestamp" }
|
|
135
|
+
},
|
|
136
|
+
uniqueIndexes: [
|
|
137
|
+
{
|
|
138
|
+
name: "source_control_worktrees_project_repository_user_branch_unique",
|
|
139
|
+
columns: ["project_repository_id", "user_id", "branch"]
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: SESSIONS,
|
|
145
|
+
columns: {
|
|
146
|
+
id: { type: "uuid-pk" },
|
|
147
|
+
session_id: { type: "text" },
|
|
148
|
+
project_repository_id: { type: "text" },
|
|
149
|
+
org_id: { type: "text" },
|
|
150
|
+
user_id: { type: "text" },
|
|
151
|
+
branch: { type: "text" },
|
|
152
|
+
base_branch: { type: "text" },
|
|
153
|
+
sandbox_id: { type: "text", nullable: true },
|
|
154
|
+
sandbox_workdir: { type: "text", nullable: true },
|
|
155
|
+
materialized_at: { type: "timestamp", nullable: true },
|
|
156
|
+
created_at: { type: "timestamp" },
|
|
157
|
+
updated_at: { type: "timestamp" }
|
|
158
|
+
},
|
|
159
|
+
uniqueIndexes: [
|
|
160
|
+
{ name: "source_control_sessions_session_id_unique", columns: ["session_id"] },
|
|
161
|
+
{
|
|
162
|
+
name: "source_control_sessions_repository_user_branch_unique",
|
|
163
|
+
columns: ["project_repository_id", "user_id", "branch"]
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
];
|
|
168
|
+
function toInstallation(row) {
|
|
169
|
+
return {
|
|
170
|
+
id: row.id,
|
|
171
|
+
integrationId: row.integration_id,
|
|
172
|
+
orgId: row.org_id,
|
|
173
|
+
connectedByUserId: row.connected_by_user_id,
|
|
174
|
+
externalId: row.external_id,
|
|
175
|
+
accountName: row.account_name,
|
|
176
|
+
accountType: row.account_type,
|
|
177
|
+
providerMetadata: row.provider_metadata,
|
|
178
|
+
createdAt: row.created_at
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function toRepository(row) {
|
|
182
|
+
return {
|
|
183
|
+
id: row.id,
|
|
184
|
+
installationId: row.installation_id,
|
|
185
|
+
externalId: row.external_id,
|
|
186
|
+
slug: row.slug,
|
|
187
|
+
defaultBranch: row.default_branch,
|
|
188
|
+
providerMetadata: row.provider_metadata,
|
|
189
|
+
createdAt: row.created_at,
|
|
190
|
+
updatedAt: row.updated_at
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function toConnection(row) {
|
|
194
|
+
return {
|
|
195
|
+
id: row.id,
|
|
196
|
+
factoryProjectId: row.factory_project_id,
|
|
197
|
+
integrationId: row.integration_id,
|
|
198
|
+
installationId: row.installation_id,
|
|
199
|
+
createdByUserId: row.created_by_user_id,
|
|
200
|
+
createdAt: row.created_at
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function toProjectRepository(row) {
|
|
204
|
+
return {
|
|
205
|
+
id: row.id,
|
|
206
|
+
connectionId: row.connection_id,
|
|
207
|
+
repositoryId: row.repository_id,
|
|
208
|
+
createdByUserId: row.created_by_user_id,
|
|
209
|
+
branch: row.branch,
|
|
210
|
+
sandboxProvider: row.sandbox_provider,
|
|
211
|
+
sandboxWorkdir: row.sandbox_workdir,
|
|
212
|
+
setupCommand: row.setup_command,
|
|
213
|
+
createdAt: row.created_at,
|
|
214
|
+
updatedAt: row.updated_at
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function toSandbox(row) {
|
|
218
|
+
return {
|
|
219
|
+
id: row.id,
|
|
220
|
+
projectRepositoryId: row.project_repository_id,
|
|
221
|
+
userId: row.user_id,
|
|
222
|
+
sandboxId: row.sandbox_id,
|
|
223
|
+
sandboxWorkdir: row.sandbox_workdir,
|
|
224
|
+
materializedAt: row.materialized_at,
|
|
225
|
+
createdAt: row.created_at
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function toWorktree(row) {
|
|
229
|
+
return {
|
|
230
|
+
id: row.id,
|
|
231
|
+
projectRepositoryId: row.project_repository_id,
|
|
232
|
+
userId: row.user_id,
|
|
233
|
+
branch: row.branch,
|
|
234
|
+
baseBranch: row.base_branch,
|
|
235
|
+
worktreePath: row.worktree_path,
|
|
236
|
+
createdAt: row.created_at
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function toSession(row) {
|
|
240
|
+
return {
|
|
241
|
+
id: row.id,
|
|
242
|
+
sessionId: row.session_id,
|
|
243
|
+
projectRepositoryId: row.project_repository_id,
|
|
244
|
+
orgId: row.org_id,
|
|
245
|
+
userId: row.user_id,
|
|
246
|
+
branch: row.branch,
|
|
247
|
+
baseBranch: row.base_branch,
|
|
248
|
+
sandboxId: row.sandbox_id,
|
|
249
|
+
sandboxWorkdir: row.sandbox_workdir,
|
|
250
|
+
materializedAt: row.materialized_at,
|
|
251
|
+
createdAt: row.created_at,
|
|
252
|
+
updatedAt: row.updated_at
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
var SourceControlStorage = class extends FactoryStorageDomain {
|
|
256
|
+
constructor() {
|
|
257
|
+
super("source-control");
|
|
258
|
+
}
|
|
259
|
+
async init() {
|
|
260
|
+
await this.ensureCollections(SOURCE_CONTROL_SCHEMAS);
|
|
261
|
+
}
|
|
262
|
+
async dangerouslyClearAll() {
|
|
263
|
+
await this.ops.deleteMany(SESSIONS, {});
|
|
264
|
+
await this.ops.deleteMany(WORKTREES, {});
|
|
265
|
+
await this.ops.deleteMany(SANDBOXES, {});
|
|
266
|
+
await this.ops.deleteMany(PROJECT_REPOSITORIES, {});
|
|
267
|
+
await this.ops.deleteMany(CONNECTIONS, {});
|
|
268
|
+
await this.ops.deleteMany(REPOSITORIES, {});
|
|
269
|
+
await this.ops.deleteMany(INSTALLATIONS, {});
|
|
270
|
+
}
|
|
271
|
+
forIntegration(integrationId) {
|
|
272
|
+
if (!integrationId.trim()) throw new Error("[SourceControlStorage] integrationId must not be empty.");
|
|
273
|
+
const db = () => this.ops;
|
|
274
|
+
const getInstallation = async (args) => {
|
|
275
|
+
const row = await db().findOne(INSTALLATIONS, {
|
|
276
|
+
id: args.id,
|
|
277
|
+
integration_id: integrationId,
|
|
278
|
+
org_id: args.orgId
|
|
279
|
+
});
|
|
280
|
+
return row ? toInstallation(row) : null;
|
|
281
|
+
};
|
|
282
|
+
const requireInstallation = async (args) => {
|
|
283
|
+
const installation = await getInstallation(args);
|
|
284
|
+
if (!installation)
|
|
285
|
+
throw new Error("Source-control installation not found for this organization and integration.");
|
|
286
|
+
return installation;
|
|
287
|
+
};
|
|
288
|
+
const getRepository = async (args) => {
|
|
289
|
+
const row = await db().findOne(REPOSITORIES, { id: args.id });
|
|
290
|
+
if (!row || !await getInstallation({ orgId: args.orgId, id: row.installation_id })) return null;
|
|
291
|
+
return toRepository(row);
|
|
292
|
+
};
|
|
293
|
+
const requireRepository = async (args) => {
|
|
294
|
+
const repository = await getRepository(args);
|
|
295
|
+
if (!repository) throw new Error("Source-control repository not found for this organization and integration.");
|
|
296
|
+
return repository;
|
|
297
|
+
};
|
|
298
|
+
const getConnection = async (args) => {
|
|
299
|
+
const row = await db().findOne(CONNECTIONS, { id: args.id, integration_id: integrationId });
|
|
300
|
+
if (!row) return null;
|
|
301
|
+
const project = await db().findOne(FACTORY_PROJECTS, {
|
|
302
|
+
id: row.factory_project_id,
|
|
303
|
+
org_id: args.orgId
|
|
304
|
+
});
|
|
305
|
+
if (!project || !await getInstallation({ orgId: args.orgId, id: row.installation_id })) return null;
|
|
306
|
+
return toConnection(row);
|
|
307
|
+
};
|
|
308
|
+
const requireConnection = async (args) => {
|
|
309
|
+
const connection = await getConnection(args);
|
|
310
|
+
if (!connection)
|
|
311
|
+
throw new Error("Project source-control connection not found for this organization and integration.");
|
|
312
|
+
return connection;
|
|
313
|
+
};
|
|
314
|
+
const getProjectRepository = async (args) => {
|
|
315
|
+
const row = await db().findOne(PROJECT_REPOSITORIES, { id: args.id });
|
|
316
|
+
if (!row || !await getConnection({ orgId: args.orgId, id: row.connection_id })) return null;
|
|
317
|
+
return toProjectRepository(row);
|
|
318
|
+
};
|
|
319
|
+
const getProjectRepositoryById = async (id) => {
|
|
320
|
+
const row = await db().findOne(PROJECT_REPOSITORIES, { id });
|
|
321
|
+
if (!row) return null;
|
|
322
|
+
const connection = await db().findOne(CONNECTIONS, {
|
|
323
|
+
id: row.connection_id,
|
|
324
|
+
integration_id: integrationId
|
|
325
|
+
});
|
|
326
|
+
return connection ? toProjectRepository(row) : null;
|
|
327
|
+
};
|
|
328
|
+
const requireProjectRepositoryById = async (id) => {
|
|
329
|
+
const projectRepository = await getProjectRepositoryById(id);
|
|
330
|
+
if (!projectRepository) throw new Error("Project repository not found for this integration.");
|
|
331
|
+
return projectRepository;
|
|
332
|
+
};
|
|
333
|
+
const getSandbox = async (id) => {
|
|
334
|
+
const row = await db().findOne(SANDBOXES, { id });
|
|
335
|
+
if (!row || !await getProjectRepositoryById(row.project_repository_id)) return null;
|
|
336
|
+
return toSandbox(row);
|
|
337
|
+
};
|
|
338
|
+
const requireSandbox = async (id) => {
|
|
339
|
+
const sandbox = await getSandbox(id);
|
|
340
|
+
if (!sandbox) throw new Error("Project-repository sandbox not found for this integration.");
|
|
341
|
+
return sandbox;
|
|
342
|
+
};
|
|
343
|
+
return {
|
|
344
|
+
integrationId,
|
|
345
|
+
installations: {
|
|
346
|
+
list: async ({ orgId }) => (await db().findMany(INSTALLATIONS, {
|
|
347
|
+
integration_id: integrationId,
|
|
348
|
+
org_id: orgId
|
|
349
|
+
})).map(toInstallation),
|
|
350
|
+
get: getInstallation,
|
|
351
|
+
findByExternalId: async ({ orgId, externalId }) => {
|
|
352
|
+
const row = await db().findOne(INSTALLATIONS, {
|
|
353
|
+
integration_id: integrationId,
|
|
354
|
+
org_id: orgId,
|
|
355
|
+
external_id: externalId
|
|
356
|
+
});
|
|
357
|
+
return row ? toInstallation(row) : null;
|
|
358
|
+
},
|
|
359
|
+
upsert: async (input) => {
|
|
360
|
+
const row = await db().upsertOne(
|
|
361
|
+
INSTALLATIONS,
|
|
362
|
+
["integration_id", "org_id", "external_id"],
|
|
363
|
+
{
|
|
364
|
+
integration_id: integrationId,
|
|
365
|
+
org_id: input.orgId,
|
|
366
|
+
connected_by_user_id: input.connectedByUserId,
|
|
367
|
+
external_id: input.externalId,
|
|
368
|
+
account_name: input.accountName ?? null,
|
|
369
|
+
account_type: input.accountType ?? null,
|
|
370
|
+
provider_metadata: input.providerMetadata ?? {},
|
|
371
|
+
created_at: /* @__PURE__ */ new Date()
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
return toInstallation(row);
|
|
375
|
+
},
|
|
376
|
+
delete: async ({ orgId, id }) => {
|
|
377
|
+
const installation = await getInstallation({ orgId, id });
|
|
378
|
+
if (!installation) return false;
|
|
379
|
+
await db().deleteMany(INSTALLATIONS, { id, integration_id: integrationId, org_id: orgId });
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
repositories: {
|
|
384
|
+
list: async ({ orgId, installationId }) => {
|
|
385
|
+
await requireInstallation({ orgId, id: installationId });
|
|
386
|
+
return (await db().findMany(REPOSITORIES, { installation_id: installationId })).map(
|
|
387
|
+
toRepository
|
|
388
|
+
);
|
|
389
|
+
},
|
|
390
|
+
get: getRepository,
|
|
391
|
+
findByExternalId: async ({ orgId, installationId, externalId }) => {
|
|
392
|
+
await requireInstallation({ orgId, id: installationId });
|
|
393
|
+
const row = await db().findOne(REPOSITORIES, {
|
|
394
|
+
installation_id: installationId,
|
|
395
|
+
external_id: externalId
|
|
396
|
+
});
|
|
397
|
+
return row ? toRepository(row) : null;
|
|
398
|
+
},
|
|
399
|
+
findBySlug: async ({ orgId, installationId, slug }) => {
|
|
400
|
+
await requireInstallation({ orgId, id: installationId });
|
|
401
|
+
const row = await db().findOne(REPOSITORIES, { installation_id: installationId, slug });
|
|
402
|
+
return row ? toRepository(row) : null;
|
|
403
|
+
},
|
|
404
|
+
upsert: async ({ orgId, input }) => {
|
|
405
|
+
await requireInstallation({ orgId, id: input.installationId });
|
|
406
|
+
const now = /* @__PURE__ */ new Date();
|
|
407
|
+
const row = await db().upsertOne(REPOSITORIES, ["installation_id", "external_id"], {
|
|
408
|
+
installation_id: input.installationId,
|
|
409
|
+
external_id: input.externalId,
|
|
410
|
+
slug: input.slug,
|
|
411
|
+
default_branch: input.defaultBranch,
|
|
412
|
+
provider_metadata: input.providerMetadata ?? {},
|
|
413
|
+
created_at: now,
|
|
414
|
+
updated_at: now
|
|
415
|
+
});
|
|
416
|
+
return toRepository(row);
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
connections: {
|
|
420
|
+
list: async ({ orgId, factoryProjectId }) => {
|
|
421
|
+
const project = await db().findOne(FACTORY_PROJECTS, {
|
|
422
|
+
id: factoryProjectId,
|
|
423
|
+
org_id: orgId
|
|
424
|
+
});
|
|
425
|
+
if (!project) return [];
|
|
426
|
+
return (await db().findMany(CONNECTIONS, {
|
|
427
|
+
factory_project_id: factoryProjectId,
|
|
428
|
+
integration_id: integrationId
|
|
429
|
+
})).map(toConnection);
|
|
430
|
+
},
|
|
431
|
+
get: getConnection,
|
|
432
|
+
create: async (input) => {
|
|
433
|
+
const project = await db().findOne(FACTORY_PROJECTS, {
|
|
434
|
+
id: input.factoryProjectId,
|
|
435
|
+
org_id: input.orgId
|
|
436
|
+
});
|
|
437
|
+
if (!project) throw new Error("Factory project not found for this organization.");
|
|
438
|
+
await requireInstallation({ orgId: input.orgId, id: input.installationId });
|
|
439
|
+
try {
|
|
440
|
+
const row = await db().insertOne(CONNECTIONS, {
|
|
441
|
+
factory_project_id: input.factoryProjectId,
|
|
442
|
+
integration_id: integrationId,
|
|
443
|
+
installation_id: input.installationId,
|
|
444
|
+
created_by_user_id: input.createdByUserId,
|
|
445
|
+
created_at: /* @__PURE__ */ new Date()
|
|
446
|
+
});
|
|
447
|
+
return toConnection(row);
|
|
448
|
+
} catch (error) {
|
|
449
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
450
|
+
const row = await db().findOne(CONNECTIONS, {
|
|
451
|
+
factory_project_id: input.factoryProjectId,
|
|
452
|
+
integration_id: integrationId,
|
|
453
|
+
installation_id: input.installationId
|
|
454
|
+
});
|
|
455
|
+
if (!row) throw error;
|
|
456
|
+
return toConnection(row);
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
delete: async ({ orgId, id }) => {
|
|
460
|
+
const connection = await getConnection({ orgId, id });
|
|
461
|
+
if (!connection) return false;
|
|
462
|
+
const projectRepositories = await db().findMany(PROJECT_REPOSITORIES, {
|
|
463
|
+
connection_id: id
|
|
464
|
+
});
|
|
465
|
+
for (const projectRepository of projectRepositories) {
|
|
466
|
+
await db().deleteMany(SESSIONS, { project_repository_id: projectRepository.id });
|
|
467
|
+
await db().deleteMany(WORKTREES, { project_repository_id: projectRepository.id });
|
|
468
|
+
await db().deleteMany(SANDBOXES, { project_repository_id: projectRepository.id });
|
|
469
|
+
}
|
|
470
|
+
await db().deleteMany(PROJECT_REPOSITORIES, { connection_id: id });
|
|
471
|
+
await db().deleteMany(CONNECTIONS, { id, integration_id: integrationId });
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
projectRepositories: {
|
|
476
|
+
list: async ({ orgId, connectionId }) => {
|
|
477
|
+
await requireConnection({ orgId, id: connectionId });
|
|
478
|
+
return (await db().findMany(PROJECT_REPOSITORIES, { connection_id: connectionId })).map(toProjectRepository);
|
|
479
|
+
},
|
|
480
|
+
listByExternalRepository: async ({ installationExternalId, repositoryExternalId }) => {
|
|
481
|
+
const targets = [];
|
|
482
|
+
const installations = await db().findMany(INSTALLATIONS, {
|
|
483
|
+
integration_id: integrationId,
|
|
484
|
+
external_id: installationExternalId
|
|
485
|
+
});
|
|
486
|
+
for (const installation of installations) {
|
|
487
|
+
const repository = await db().findOne(REPOSITORIES, {
|
|
488
|
+
installation_id: installation.id,
|
|
489
|
+
external_id: repositoryExternalId
|
|
490
|
+
});
|
|
491
|
+
if (!repository) continue;
|
|
492
|
+
const links = await db().findMany(PROJECT_REPOSITORIES, {
|
|
493
|
+
repository_id: repository.id
|
|
494
|
+
});
|
|
495
|
+
for (const link of links) {
|
|
496
|
+
const connection = await db().findOne(CONNECTIONS, {
|
|
497
|
+
id: link.connection_id,
|
|
498
|
+
integration_id: integrationId,
|
|
499
|
+
installation_id: installation.id
|
|
500
|
+
});
|
|
501
|
+
if (!connection) continue;
|
|
502
|
+
const project = await db().findOne(FACTORY_PROJECTS, {
|
|
503
|
+
id: connection.factory_project_id,
|
|
504
|
+
org_id: installation.org_id
|
|
505
|
+
});
|
|
506
|
+
if (!project) continue;
|
|
507
|
+
targets.push({
|
|
508
|
+
orgId: installation.org_id,
|
|
509
|
+
factoryProjectId: connection.factory_project_id,
|
|
510
|
+
projectRepository: toProjectRepository(link)
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return targets;
|
|
515
|
+
},
|
|
516
|
+
get: getProjectRepository,
|
|
517
|
+
link: async (input) => {
|
|
518
|
+
const connection = await requireConnection({ orgId: input.orgId, id: input.connectionId });
|
|
519
|
+
const repository = await requireRepository({ orgId: input.orgId, id: input.repositoryId });
|
|
520
|
+
if (repository.installationId !== connection.installationId) {
|
|
521
|
+
throw new Error("Repository does not belong to the connection installation.");
|
|
522
|
+
}
|
|
523
|
+
const now = /* @__PURE__ */ new Date();
|
|
524
|
+
const row = await db().upsertOne(
|
|
525
|
+
PROJECT_REPOSITORIES,
|
|
526
|
+
["connection_id", "repository_id"],
|
|
527
|
+
{
|
|
528
|
+
connection_id: input.connectionId,
|
|
529
|
+
repository_id: input.repositoryId,
|
|
530
|
+
created_by_user_id: input.createdByUserId,
|
|
531
|
+
branch: input.branch ?? null,
|
|
532
|
+
sandbox_provider: input.sandboxProvider,
|
|
533
|
+
sandbox_workdir: input.sandboxWorkdir,
|
|
534
|
+
setup_command: input.setupCommand ?? null,
|
|
535
|
+
created_at: now,
|
|
536
|
+
updated_at: now
|
|
537
|
+
}
|
|
538
|
+
);
|
|
539
|
+
return toProjectRepository(row);
|
|
540
|
+
},
|
|
541
|
+
update: async ({ orgId, id, input }) => {
|
|
542
|
+
const existing = await getProjectRepository({ orgId, id });
|
|
543
|
+
if (!existing) return null;
|
|
544
|
+
const patch = { updated_at: /* @__PURE__ */ new Date() };
|
|
545
|
+
if (input.branch !== void 0) patch.branch = input.branch;
|
|
546
|
+
if (input.sandboxProvider !== void 0) patch.sandbox_provider = input.sandboxProvider;
|
|
547
|
+
if (input.sandboxWorkdir !== void 0) patch.sandbox_workdir = input.sandboxWorkdir;
|
|
548
|
+
if (input.setupCommand !== void 0) patch.setup_command = input.setupCommand;
|
|
549
|
+
await db().updateMany(PROJECT_REPOSITORIES, { id }, patch);
|
|
550
|
+
return getProjectRepository({ orgId, id });
|
|
551
|
+
},
|
|
552
|
+
unlink: async ({ orgId, id }) => {
|
|
553
|
+
const existing = await getProjectRepository({ orgId, id });
|
|
554
|
+
if (!existing) return false;
|
|
555
|
+
await db().deleteMany(SESSIONS, { project_repository_id: id });
|
|
556
|
+
await db().deleteMany(WORKTREES, { project_repository_id: id });
|
|
557
|
+
await db().deleteMany(SANDBOXES, { project_repository_id: id });
|
|
558
|
+
await db().deleteMany(PROJECT_REPOSITORIES, { id });
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
sandboxes: {
|
|
563
|
+
getOrCreate: async ({ projectRepository, userId }) => {
|
|
564
|
+
await requireProjectRepositoryById(projectRepository.id);
|
|
565
|
+
const where = { project_repository_id: projectRepository.id, user_id: userId };
|
|
566
|
+
const existing = await db().findOne(SANDBOXES, where);
|
|
567
|
+
if (existing) return toSandbox(existing);
|
|
568
|
+
try {
|
|
569
|
+
const row = await db().insertOne(SANDBOXES, {
|
|
570
|
+
...where,
|
|
571
|
+
sandbox_id: null,
|
|
572
|
+
sandbox_workdir: projectRepository.sandboxWorkdir,
|
|
573
|
+
materialized_at: null,
|
|
574
|
+
created_at: /* @__PURE__ */ new Date()
|
|
575
|
+
});
|
|
576
|
+
return toSandbox(row);
|
|
577
|
+
} catch (error) {
|
|
578
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
579
|
+
const row = await db().findOne(SANDBOXES, where);
|
|
580
|
+
if (!row) throw error;
|
|
581
|
+
return toSandbox(row);
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
getById: ({ id }) => getSandbox(id),
|
|
585
|
+
setSandboxId: async ({ id, sandboxId }) => {
|
|
586
|
+
await requireSandbox(id);
|
|
587
|
+
await db().updateMany(SANDBOXES, { id }, { sandbox_id: sandboxId });
|
|
588
|
+
},
|
|
589
|
+
clearBinding: async ({ id }) => {
|
|
590
|
+
await requireSandbox(id);
|
|
591
|
+
await db().updateMany(SANDBOXES, { id }, { sandbox_id: null, materialized_at: null });
|
|
592
|
+
},
|
|
593
|
+
markMaterialized: async ({ id }) => {
|
|
594
|
+
await requireSandbox(id);
|
|
595
|
+
await db().updateMany(SANDBOXES, { id }, { materialized_at: /* @__PURE__ */ new Date() });
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
worktrees: {
|
|
599
|
+
upsert: async (input) => {
|
|
600
|
+
await requireProjectRepositoryById(input.projectRepositoryId);
|
|
601
|
+
await db().upsertOne(WORKTREES, ["project_repository_id", "user_id", "branch"], {
|
|
602
|
+
project_repository_id: input.projectRepositoryId,
|
|
603
|
+
user_id: input.userId,
|
|
604
|
+
branch: input.branch,
|
|
605
|
+
base_branch: input.baseBranch,
|
|
606
|
+
worktree_path: input.worktreePath,
|
|
607
|
+
created_at: /* @__PURE__ */ new Date()
|
|
608
|
+
});
|
|
609
|
+
},
|
|
610
|
+
list: async ({ projectRepositoryId, userId }) => {
|
|
611
|
+
if (!await getProjectRepositoryById(projectRepositoryId)) return [];
|
|
612
|
+
const rows = await db().findMany(WORKTREES, {
|
|
613
|
+
project_repository_id: projectRepositoryId,
|
|
614
|
+
user_id: userId
|
|
615
|
+
});
|
|
616
|
+
return rows.map(toWorktree);
|
|
617
|
+
},
|
|
618
|
+
get: async ({ projectRepositoryId, userId, branch }) => {
|
|
619
|
+
if (!await getProjectRepositoryById(projectRepositoryId)) return null;
|
|
620
|
+
const row = await db().findOne(WORKTREES, {
|
|
621
|
+
project_repository_id: projectRepositoryId,
|
|
622
|
+
user_id: userId,
|
|
623
|
+
branch
|
|
624
|
+
});
|
|
625
|
+
return row ? toWorktree(row) : null;
|
|
626
|
+
},
|
|
627
|
+
findByPath: async ({ projectRepositoryId, userId, worktreePath }) => {
|
|
628
|
+
if (!await getProjectRepositoryById(projectRepositoryId)) return null;
|
|
629
|
+
const row = await db().findOne(WORKTREES, {
|
|
630
|
+
project_repository_id: projectRepositoryId,
|
|
631
|
+
user_id: userId,
|
|
632
|
+
worktree_path: worktreePath
|
|
633
|
+
});
|
|
634
|
+
return row ? toWorktree(row) : null;
|
|
635
|
+
},
|
|
636
|
+
delete: async ({ projectRepositoryId, userId, branch }) => {
|
|
637
|
+
await requireProjectRepositoryById(projectRepositoryId);
|
|
638
|
+
await db().deleteMany(WORKTREES, {
|
|
639
|
+
project_repository_id: projectRepositoryId,
|
|
640
|
+
user_id: userId,
|
|
641
|
+
branch
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
sessions: {
|
|
646
|
+
list: async ({ projectRepositoryId, userId }) => {
|
|
647
|
+
if (!await getProjectRepositoryById(projectRepositoryId)) return [];
|
|
648
|
+
return (await db().findMany(SESSIONS, {
|
|
649
|
+
project_repository_id: projectRepositoryId,
|
|
650
|
+
user_id: userId
|
|
651
|
+
})).map(toSession);
|
|
652
|
+
},
|
|
653
|
+
getBySessionId: async (sessionId) => {
|
|
654
|
+
const row = await db().findOne(SESSIONS, { session_id: sessionId });
|
|
655
|
+
return row && await getProjectRepositoryById(row.project_repository_id) ? toSession(row) : null;
|
|
656
|
+
},
|
|
657
|
+
getForBranch: async ({ projectRepositoryId, userId, branch }) => {
|
|
658
|
+
if (!await getProjectRepositoryById(projectRepositoryId)) return null;
|
|
659
|
+
const row = await db().findOne(SESSIONS, {
|
|
660
|
+
project_repository_id: projectRepositoryId,
|
|
661
|
+
user_id: userId,
|
|
662
|
+
branch
|
|
663
|
+
});
|
|
664
|
+
return row ? toSession(row) : null;
|
|
665
|
+
},
|
|
666
|
+
create: async (input) => {
|
|
667
|
+
await requireProjectRepositoryById(input.projectRepositoryId);
|
|
668
|
+
const existing = await db().findOne(SESSIONS, {
|
|
669
|
+
project_repository_id: input.projectRepositoryId,
|
|
670
|
+
user_id: input.userId,
|
|
671
|
+
branch: input.branch
|
|
672
|
+
});
|
|
673
|
+
if (existing) return toSession(existing);
|
|
674
|
+
const now = /* @__PURE__ */ new Date();
|
|
675
|
+
try {
|
|
676
|
+
const row = await db().insertOne(SESSIONS, {
|
|
677
|
+
session_id: input.sessionId,
|
|
678
|
+
project_repository_id: input.projectRepositoryId,
|
|
679
|
+
org_id: input.orgId,
|
|
680
|
+
user_id: input.userId,
|
|
681
|
+
branch: input.branch,
|
|
682
|
+
base_branch: input.baseBranch,
|
|
683
|
+
sandbox_id: null,
|
|
684
|
+
sandbox_workdir: null,
|
|
685
|
+
materialized_at: null,
|
|
686
|
+
created_at: now,
|
|
687
|
+
updated_at: now
|
|
688
|
+
});
|
|
689
|
+
return toSession(row);
|
|
690
|
+
} catch (error) {
|
|
691
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
692
|
+
const row = await db().findOne(SESSIONS, {
|
|
693
|
+
project_repository_id: input.projectRepositoryId,
|
|
694
|
+
user_id: input.userId,
|
|
695
|
+
branch: input.branch
|
|
696
|
+
});
|
|
697
|
+
if (!row) throw error;
|
|
698
|
+
return toSession(row);
|
|
699
|
+
}
|
|
700
|
+
},
|
|
701
|
+
setSandbox: async ({ id, sandboxId, sandboxWorkdir }) => {
|
|
702
|
+
await db().updateMany(
|
|
703
|
+
SESSIONS,
|
|
704
|
+
{ id },
|
|
705
|
+
{ sandbox_id: sandboxId, sandbox_workdir: sandboxWorkdir, updated_at: /* @__PURE__ */ new Date() }
|
|
706
|
+
);
|
|
707
|
+
},
|
|
708
|
+
markMaterialized: async ({ id }) => {
|
|
709
|
+
await db().updateMany(SESSIONS, { id }, { materialized_at: /* @__PURE__ */ new Date(), updated_at: /* @__PURE__ */ new Date() });
|
|
710
|
+
},
|
|
711
|
+
delete: async (id) => {
|
|
712
|
+
await db().deleteMany(SESSIONS, { id });
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
export {
|
|
719
|
+
SOURCE_CONTROL_SCHEMAS,
|
|
720
|
+
SourceControlStorage
|
|
721
|
+
};
|
|
722
|
+
//# sourceMappingURL=base.js.map
|