@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.
Files changed (287) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE.md +30 -0
  3. package/dist/auth.d.ts +181 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +370 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/capabilities/connection.d.ts +9 -0
  8. package/dist/capabilities/connection.d.ts.map +1 -0
  9. package/dist/capabilities/connection.js +1 -0
  10. package/dist/capabilities/connection.js.map +1 -0
  11. package/dist/capabilities/intake.d.ts +93 -0
  12. package/dist/capabilities/intake.d.ts.map +1 -0
  13. package/dist/capabilities/intake.js +1 -0
  14. package/dist/capabilities/intake.js.map +1 -0
  15. package/dist/capabilities/version-control.d.ts +239 -0
  16. package/dist/capabilities/version-control.d.ts.map +1 -0
  17. package/dist/capabilities/version-control.js +1 -0
  18. package/dist/capabilities/version-control.js.map +1 -0
  19. package/dist/factory.d.ts +145 -0
  20. package/dist/factory.d.ts.map +1 -0
  21. package/dist/factory.js +38245 -0
  22. package/dist/factory.js.map +1 -0
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +38245 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/integrations/base.d.ts +197 -0
  28. package/dist/integrations/base.d.ts.map +1 -0
  29. package/dist/integrations/base.js +1 -0
  30. package/dist/integrations/base.js.map +1 -0
  31. package/dist/integrations/github/config.d.ts +60 -0
  32. package/dist/integrations/github/config.d.ts.map +1 -0
  33. package/dist/integrations/github/config.js +28 -0
  34. package/dist/integrations/github/config.js.map +1 -0
  35. package/dist/integrations/github/factory-session.d.ts +12 -0
  36. package/dist/integrations/github/factory-session.d.ts.map +1 -0
  37. package/dist/integrations/github/factory-session.js +41 -0
  38. package/dist/integrations/github/factory-session.js.map +1 -0
  39. package/dist/integrations/github/integration.d.ts +191 -0
  40. package/dist/integrations/github/integration.d.ts.map +1 -0
  41. package/dist/integrations/github/integration.js +3001 -0
  42. package/dist/integrations/github/integration.js.map +1 -0
  43. package/dist/integrations/github/issue-triage.d.ts +27 -0
  44. package/dist/integrations/github/issue-triage.d.ts.map +1 -0
  45. package/dist/integrations/github/issue-triage.js +82 -0
  46. package/dist/integrations/github/issue-triage.js.map +1 -0
  47. package/dist/integrations/github/project-lock.d.ts +78 -0
  48. package/dist/integrations/github/project-lock.d.ts.map +1 -0
  49. package/dist/integrations/github/project-lock.js +70 -0
  50. package/dist/integrations/github/project-lock.js.map +1 -0
  51. package/dist/integrations/github/provenance.d.ts +27 -0
  52. package/dist/integrations/github/provenance.d.ts.map +1 -0
  53. package/dist/integrations/github/provenance.js +104 -0
  54. package/dist/integrations/github/provenance.js.map +1 -0
  55. package/dist/integrations/github/routes.d.ts +72 -0
  56. package/dist/integrations/github/routes.d.ts.map +1 -0
  57. package/dist/integrations/github/routes.js +1834 -0
  58. package/dist/integrations/github/routes.js.map +1 -0
  59. package/dist/integrations/github/sandbox.d.ts +268 -0
  60. package/dist/integrations/github/sandbox.d.ts.map +1 -0
  61. package/dist/integrations/github/sandbox.js +381 -0
  62. package/dist/integrations/github/sandbox.js.map +1 -0
  63. package/dist/integrations/github/session-subscriptions.d.ts +23 -0
  64. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -0
  65. package/dist/integrations/github/session-subscriptions.js +190 -0
  66. package/dist/integrations/github/session-subscriptions.js.map +1 -0
  67. package/dist/integrations/github/subscriptions.d.ts +54 -0
  68. package/dist/integrations/github/subscriptions.d.ts.map +1 -0
  69. package/dist/integrations/github/subscriptions.js +70 -0
  70. package/dist/integrations/github/subscriptions.js.map +1 -0
  71. package/dist/integrations/github/webhook.d.ts +87 -0
  72. package/dist/integrations/github/webhook.d.ts.map +1 -0
  73. package/dist/integrations/github/webhook.js +381 -0
  74. package/dist/integrations/github/webhook.js.map +1 -0
  75. package/dist/integrations/linear/agent-tools.d.ts +34 -0
  76. package/dist/integrations/linear/agent-tools.d.ts.map +1 -0
  77. package/dist/integrations/linear/agent-tools.js +108 -0
  78. package/dist/integrations/linear/agent-tools.js.map +1 -0
  79. package/dist/integrations/linear/integration.d.ts +233 -0
  80. package/dist/integrations/linear/integration.d.ts.map +1 -0
  81. package/dist/integrations/linear/integration.js +962 -0
  82. package/dist/integrations/linear/integration.js.map +1 -0
  83. package/dist/integrations/linear/routes.d.ts +61 -0
  84. package/dist/integrations/linear/routes.d.ts.map +1 -0
  85. package/dist/integrations/linear/routes.js +242 -0
  86. package/dist/integrations/linear/routes.js.map +1 -0
  87. package/dist/integrations/linear/storage.d.ts +65 -0
  88. package/dist/integrations/linear/storage.d.ts.map +1 -0
  89. package/dist/integrations/linear/storage.js +1 -0
  90. package/dist/integrations/linear/storage.js.map +1 -0
  91. package/dist/integrations/platform/api-client.d.ts +24 -0
  92. package/dist/integrations/platform/api-client.d.ts.map +1 -0
  93. package/dist/integrations/platform/api-client.js +153 -0
  94. package/dist/integrations/platform/api-client.js.map +1 -0
  95. package/dist/integrations/platform/github/event-worker.d.ts +44 -0
  96. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -0
  97. package/dist/integrations/platform/github/event-worker.js +585 -0
  98. package/dist/integrations/platform/github/event-worker.js.map +1 -0
  99. package/dist/integrations/platform/github/integration.d.ts +36 -0
  100. package/dist/integrations/platform/github/integration.d.ts.map +1 -0
  101. package/dist/integrations/platform/github/integration.js +3253 -0
  102. package/dist/integrations/platform/github/integration.js.map +1 -0
  103. package/dist/integrations/platform/linear/integration.d.ts +46 -0
  104. package/dist/integrations/platform/linear/integration.d.ts.map +1 -0
  105. package/dist/integrations/platform/linear/integration.js +891 -0
  106. package/dist/integrations/platform/linear/integration.js.map +1 -0
  107. package/dist/integrations/workos/integration.d.ts +39 -0
  108. package/dist/integrations/workos/integration.d.ts.map +1 -0
  109. package/dist/integrations/workos/integration.js +96 -0
  110. package/dist/integrations/workos/integration.js.map +1 -0
  111. package/dist/routes/config.d.ts +220 -0
  112. package/dist/routes/config.d.ts.map +1 -0
  113. package/dist/routes/config.js +770 -0
  114. package/dist/routes/config.js.map +1 -0
  115. package/dist/routes/fs.d.ts +105 -0
  116. package/dist/routes/fs.d.ts.map +1 -0
  117. package/dist/routes/fs.js +294 -0
  118. package/dist/routes/fs.js.map +1 -0
  119. package/dist/routes/intake.d.ts +23 -0
  120. package/dist/routes/intake.d.ts.map +1 -0
  121. package/dist/routes/intake.js +179 -0
  122. package/dist/routes/intake.js.map +1 -0
  123. package/dist/routes/oauth.d.ts +43 -0
  124. package/dist/routes/oauth.d.ts.map +1 -0
  125. package/dist/routes/oauth.js +25058 -0
  126. package/dist/routes/oauth.js.map +1 -0
  127. package/dist/routes/projects.d.ts +19 -0
  128. package/dist/routes/projects.d.ts.map +1 -0
  129. package/dist/routes/projects.js +395 -0
  130. package/dist/routes/projects.js.map +1 -0
  131. package/dist/routes/provider-credentials.d.ts +81 -0
  132. package/dist/routes/provider-credentials.d.ts.map +1 -0
  133. package/dist/routes/provider-credentials.js +68 -0
  134. package/dist/routes/provider-credentials.js.map +1 -0
  135. package/dist/routes/route.d.ts +48 -0
  136. package/dist/routes/route.d.ts.map +1 -0
  137. package/dist/routes/route.js +11 -0
  138. package/dist/routes/route.js.map +1 -0
  139. package/dist/routes/skills.d.ts +30 -0
  140. package/dist/routes/skills.d.ts.map +1 -0
  141. package/dist/routes/skills.js +181 -0
  142. package/dist/routes/skills.js.map +1 -0
  143. package/dist/routes/surface.d.ts +83 -0
  144. package/dist/routes/surface.d.ts.map +1 -0
  145. package/dist/routes/surface.js +28519 -0
  146. package/dist/routes/surface.js.map +1 -0
  147. package/dist/routes/tenant-credentials.d.ts +74 -0
  148. package/dist/routes/tenant-credentials.d.ts.map +1 -0
  149. package/dist/routes/tenant-credentials.js +181 -0
  150. package/dist/routes/tenant-credentials.js.map +1 -0
  151. package/dist/routes/work-items.d.ts +40 -0
  152. package/dist/routes/work-items.d.ts.map +1 -0
  153. package/dist/routes/work-items.js +902 -0
  154. package/dist/routes/work-items.js.map +1 -0
  155. package/dist/rules/binding-context.d.ts +5 -0
  156. package/dist/rules/binding-context.d.ts.map +1 -0
  157. package/dist/rules/binding-context.js +40 -0
  158. package/dist/rules/binding-context.js.map +1 -0
  159. package/dist/rules/defaults.d.ts +9 -0
  160. package/dist/rules/defaults.d.ts.map +1 -0
  161. package/dist/rules/defaults.js +334 -0
  162. package/dist/rules/defaults.js.map +1 -0
  163. package/dist/rules/dispatcher.d.ts +40 -0
  164. package/dist/rules/dispatcher.d.ts.map +1 -0
  165. package/dist/rules/dispatcher.js +695 -0
  166. package/dist/rules/dispatcher.js.map +1 -0
  167. package/dist/rules/github-service.d.ts +29 -0
  168. package/dist/rules/github-service.d.ts.map +1 -0
  169. package/dist/rules/github-service.js +474 -0
  170. package/dist/rules/github-service.js.map +1 -0
  171. package/dist/rules/index.d.ts +7 -0
  172. package/dist/rules/index.d.ts.map +1 -0
  173. package/dist/rules/index.js +583 -0
  174. package/dist/rules/index.js.map +1 -0
  175. package/dist/rules/linear-service.d.ts +27 -0
  176. package/dist/rules/linear-service.d.ts.map +1 -0
  177. package/dist/rules/linear-service.js +343 -0
  178. package/dist/rules/linear-service.js.map +1 -0
  179. package/dist/rules/processor.d.ts +54 -0
  180. package/dist/rules/processor.d.ts.map +1 -0
  181. package/dist/rules/processor.js +629 -0
  182. package/dist/rules/processor.js.map +1 -0
  183. package/dist/rules/resolve.d.ts +17 -0
  184. package/dist/rules/resolve.d.ts.map +1 -0
  185. package/dist/rules/resolve.js +27 -0
  186. package/dist/rules/resolve.js.map +1 -0
  187. package/dist/rules/start-coordinator.d.ts +58 -0
  188. package/dist/rules/start-coordinator.d.ts.map +1 -0
  189. package/dist/rules/start-coordinator.js +136 -0
  190. package/dist/rules/start-coordinator.js.map +1 -0
  191. package/dist/rules/tools.d.ts +10 -0
  192. package/dist/rules/tools.d.ts.map +1 -0
  193. package/dist/rules/tools.js +93 -0
  194. package/dist/rules/tools.js.map +1 -0
  195. package/dist/rules/transition-service.d.ts +32 -0
  196. package/dist/rules/transition-service.d.ts.map +1 -0
  197. package/dist/rules/transition-service.js +474 -0
  198. package/dist/rules/transition-service.js.map +1 -0
  199. package/dist/rules/types.d.ts +225 -0
  200. package/dist/rules/types.d.ts.map +1 -0
  201. package/dist/rules/types.js +33 -0
  202. package/dist/rules/types.js.map +1 -0
  203. package/dist/rules/validation.d.ts +11 -0
  204. package/dist/rules/validation.d.ts.map +1 -0
  205. package/dist/rules/validation.js +310 -0
  206. package/dist/rules/validation.js.map +1 -0
  207. package/dist/sandbox/fleet.d.ts +208 -0
  208. package/dist/sandbox/fleet.d.ts.map +1 -0
  209. package/dist/sandbox/fleet.js +259 -0
  210. package/dist/sandbox/fleet.js.map +1 -0
  211. package/dist/sandbox/reattach.d.ts +3 -0
  212. package/dist/sandbox/reattach.d.ts.map +1 -0
  213. package/dist/sandbox/reattach.js +9 -0
  214. package/dist/sandbox/reattach.js.map +1 -0
  215. package/dist/server-error.d.ts +12 -0
  216. package/dist/server-error.d.ts.map +1 -0
  217. package/dist/server-error.js +20 -0
  218. package/dist/server-error.js.map +1 -0
  219. package/dist/skills/service.d.ts +48 -0
  220. package/dist/skills/service.d.ts.map +1 -0
  221. package/dist/skills/service.js +45 -0
  222. package/dist/skills/service.js.map +1 -0
  223. package/dist/spa-static.d.ts +34 -0
  224. package/dist/spa-static.d.ts.map +1 -0
  225. package/dist/spa-static.js +73 -0
  226. package/dist/spa-static.js.map +1 -0
  227. package/dist/state-signing.d.ts +48 -0
  228. package/dist/state-signing.d.ts.map +1 -0
  229. package/dist/state-signing.js +48 -0
  230. package/dist/state-signing.js.map +1 -0
  231. package/dist/storage/domains/audit/agent-audit.d.ts +27 -0
  232. package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -0
  233. package/dist/storage/domains/audit/agent-audit.js +65 -0
  234. package/dist/storage/domains/audit/agent-audit.js.map +1 -0
  235. package/dist/storage/domains/audit/base.d.ts +140 -0
  236. package/dist/storage/domains/audit/base.d.ts.map +1 -0
  237. package/dist/storage/domains/audit/base.js +127 -0
  238. package/dist/storage/domains/audit/base.js.map +1 -0
  239. package/dist/storage/domains/audit/domain.d.ts +69 -0
  240. package/dist/storage/domains/audit/domain.d.ts.map +1 -0
  241. package/dist/storage/domains/audit/domain.js +165 -0
  242. package/dist/storage/domains/audit/domain.js.map +1 -0
  243. package/dist/storage/domains/credentials/base.d.ts +134 -0
  244. package/dist/storage/domains/credentials/base.d.ts.map +1 -0
  245. package/dist/storage/domains/credentials/base.js +257 -0
  246. package/dist/storage/domains/credentials/base.js.map +1 -0
  247. package/dist/storage/domains/intake/base.d.ts +38 -0
  248. package/dist/storage/domains/intake/base.d.ts.map +1 -0
  249. package/dist/storage/domains/intake/base.js +62 -0
  250. package/dist/storage/domains/intake/base.js.map +1 -0
  251. package/dist/storage/domains/integrations/base.d.ts +126 -0
  252. package/dist/storage/domains/integrations/base.d.ts.map +1 -0
  253. package/dist/storage/domains/integrations/base.js +252 -0
  254. package/dist/storage/domains/integrations/base.js.map +1 -0
  255. package/dist/storage/domains/model-packs/base.d.ts +49 -0
  256. package/dist/storage/domains/model-packs/base.d.ts.map +1 -0
  257. package/dist/storage/domains/model-packs/base.js +95 -0
  258. package/dist/storage/domains/model-packs/base.js.map +1 -0
  259. package/dist/storage/domains/projects/base.d.ts +55 -0
  260. package/dist/storage/domains/projects/base.d.ts.map +1 -0
  261. package/dist/storage/domains/projects/base.js +99 -0
  262. package/dist/storage/domains/projects/base.js.map +1 -0
  263. package/dist/storage/domains/queue-health/base.d.ts +52 -0
  264. package/dist/storage/domains/queue-health/base.d.ts.map +1 -0
  265. package/dist/storage/domains/queue-health/base.js +87 -0
  266. package/dist/storage/domains/queue-health/base.js.map +1 -0
  267. package/dist/storage/domains/source-control/base.d.ts +288 -0
  268. package/dist/storage/domains/source-control/base.d.ts.map +1 -0
  269. package/dist/storage/domains/source-control/base.js +722 -0
  270. package/dist/storage/domains/source-control/base.js.map +1 -0
  271. package/dist/storage/domains/source-control/inmemory.d.ts +158 -0
  272. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -0
  273. package/dist/storage/domains/source-control/inmemory.js +348 -0
  274. package/dist/storage/domains/source-control/inmemory.js.map +1 -0
  275. package/dist/storage/domains/work-items/base.d.ts +412 -0
  276. package/dist/storage/domains/work-items/base.d.ts.map +1 -0
  277. package/dist/storage/domains/work-items/base.js +1174 -0
  278. package/dist/storage/domains/work-items/base.js.map +1 -0
  279. package/dist/storage/domains/work-items/metrics.d.ts +101 -0
  280. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -0
  281. package/dist/storage/domains/work-items/metrics.js +203 -0
  282. package/dist/storage/domains/work-items/metrics.js.map +1 -0
  283. package/dist/workspace.d.ts +20 -0
  284. package/dist/workspace.d.ts.map +1 -0
  285. package/dist/workspace.js +364 -0
  286. package/dist/workspace.js.map +1 -0
  287. 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