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