@mastra/factory 0.2.2-alpha.1 → 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 +10 -0
- package/dist/auth.js +401 -334
- 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.js +441 -39622
- package/dist/factory.js.map +1 -1
- package/dist/index.js +2 -39633
- 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 -3672
- 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.js +1272 -1881
- 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.js +400 -345
- 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.js +845 -4022
- 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 -912
- 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 -28615
- 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.js +438 -683
- 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.js +91 -65
- 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.js +777 -706
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +322 -348
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.js +1266 -1148
- 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.js +29 -22
- package/dist/timing.js.map +1 -1
- package/dist/workspace.js +236 -477
- package/dist/workspace.js.map +1 -1
- package/package.json +8 -8
- 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,352 +1,326 @@
|
|
|
1
|
-
// src/storage/domains/source-control/inmemory.ts
|
|
2
1
|
import { randomUUID } from "crypto";
|
|
2
|
+
//#region src/storage/domains/source-control/inmemory.ts
|
|
3
|
+
/** In-memory provider-scoped source-control handle for route tests. */
|
|
3
4
|
var SourceControlStorageInMemory = class {
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
id: randomUUID(),
|
|
322
|
-
...input,
|
|
323
|
-
sandboxId: null,
|
|
324
|
-
sandboxWorkdir: null,
|
|
325
|
-
materializedAt: null,
|
|
326
|
-
createdAt: now,
|
|
327
|
-
updatedAt: now
|
|
328
|
-
};
|
|
329
|
-
this.sessionsRows.push(session);
|
|
330
|
-
return session;
|
|
331
|
-
},
|
|
332
|
-
setSandbox: async ({
|
|
333
|
-
id,
|
|
334
|
-
sandboxId,
|
|
335
|
-
sandboxWorkdir
|
|
336
|
-
}) => {
|
|
337
|
-
const row = this.sessionsRows.find((candidate) => candidate.id === id);
|
|
338
|
-
if (row) Object.assign(row, { sandboxId, sandboxWorkdir, updatedAt: /* @__PURE__ */ new Date() });
|
|
339
|
-
},
|
|
340
|
-
markMaterialized: async ({ id }) => {
|
|
341
|
-
const row = this.sessionsRows.find((candidate) => candidate.id === id);
|
|
342
|
-
if (row) Object.assign(row, { materializedAt: /* @__PURE__ */ new Date(), updatedAt: /* @__PURE__ */ new Date() });
|
|
343
|
-
},
|
|
344
|
-
delete: async (id) => {
|
|
345
|
-
this.sessionsRows.splice(0, this.sessionsRows.length, ...this.sessionsRows.filter((row) => row.id !== id));
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
};
|
|
349
|
-
export {
|
|
350
|
-
SourceControlStorageInMemory
|
|
5
|
+
integrationId;
|
|
6
|
+
installationsRows = [];
|
|
7
|
+
repositoriesRows = [];
|
|
8
|
+
connectionsRows = [];
|
|
9
|
+
projectRepositoriesRows = [];
|
|
10
|
+
sandboxesRows = [];
|
|
11
|
+
worktreesRows = [];
|
|
12
|
+
sessionsRows = [];
|
|
13
|
+
constructor(integrationId = "github") {
|
|
14
|
+
this.integrationId = integrationId;
|
|
15
|
+
}
|
|
16
|
+
installations = {
|
|
17
|
+
list: async ({ orgId }) => this.installationsRows.filter((row) => row.orgId === orgId),
|
|
18
|
+
get: async ({ orgId, id }) => this.installationsRows.find((row) => row.orgId === orgId && row.id === id) ?? null,
|
|
19
|
+
findByExternalId: async ({ orgId, externalId }) => this.installationsRows.find((row) => row.orgId === orgId && row.externalId === externalId) ?? null,
|
|
20
|
+
upsert: async (input) => {
|
|
21
|
+
const existing = this.installationsRows.find((row) => row.orgId === input.orgId && row.externalId === input.externalId);
|
|
22
|
+
if (existing) {
|
|
23
|
+
Object.assign(existing, {
|
|
24
|
+
connectedByUserId: input.connectedByUserId,
|
|
25
|
+
accountName: input.accountName ?? null,
|
|
26
|
+
accountType: input.accountType ?? null,
|
|
27
|
+
providerMetadata: input.providerMetadata ?? {}
|
|
28
|
+
});
|
|
29
|
+
return existing;
|
|
30
|
+
}
|
|
31
|
+
const created = {
|
|
32
|
+
id: randomUUID(),
|
|
33
|
+
integrationId: this.integrationId,
|
|
34
|
+
orgId: input.orgId,
|
|
35
|
+
connectedByUserId: input.connectedByUserId,
|
|
36
|
+
externalId: input.externalId,
|
|
37
|
+
accountName: input.accountName ?? null,
|
|
38
|
+
accountType: input.accountType ?? null,
|
|
39
|
+
providerMetadata: input.providerMetadata ?? {},
|
|
40
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
41
|
+
};
|
|
42
|
+
this.installationsRows.push(created);
|
|
43
|
+
return created;
|
|
44
|
+
},
|
|
45
|
+
delete: async ({ orgId, id }) => {
|
|
46
|
+
const index = this.installationsRows.findIndex((row) => row.orgId === orgId && row.id === id);
|
|
47
|
+
if (index < 0) return false;
|
|
48
|
+
this.installationsRows.splice(index, 1);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
repositories = {
|
|
53
|
+
list: async ({ orgId, installationId }) => {
|
|
54
|
+
return await this.installations.get({
|
|
55
|
+
orgId,
|
|
56
|
+
id: installationId
|
|
57
|
+
}) ? this.repositoriesRows.filter((row) => row.installationId === installationId) : [];
|
|
58
|
+
},
|
|
59
|
+
get: async ({ orgId, id }) => {
|
|
60
|
+
const row = this.repositoriesRows.find((candidate) => candidate.id === id);
|
|
61
|
+
if (!row) return null;
|
|
62
|
+
return await this.installations.get({
|
|
63
|
+
orgId,
|
|
64
|
+
id: row.installationId
|
|
65
|
+
}) ? row : null;
|
|
66
|
+
},
|
|
67
|
+
findByExternalId: async ({ orgId, installationId, externalId }) => {
|
|
68
|
+
return (await this.repositories.list({
|
|
69
|
+
orgId,
|
|
70
|
+
installationId
|
|
71
|
+
})).find((row) => row.externalId === externalId) ?? null;
|
|
72
|
+
},
|
|
73
|
+
findBySlug: async ({ orgId, installationId, slug }) => {
|
|
74
|
+
return (await this.repositories.list({
|
|
75
|
+
orgId,
|
|
76
|
+
installationId
|
|
77
|
+
})).find((row) => row.slug === slug) ?? null;
|
|
78
|
+
},
|
|
79
|
+
upsert: async ({ orgId, input }) => {
|
|
80
|
+
if (!await this.installations.get({
|
|
81
|
+
orgId,
|
|
82
|
+
id: input.installationId
|
|
83
|
+
})) throw new Error("Source-control installation not found");
|
|
84
|
+
const existing = this.repositoriesRows.find((row) => row.installationId === input.installationId && row.externalId === input.externalId);
|
|
85
|
+
const now = /* @__PURE__ */ new Date();
|
|
86
|
+
if (existing) {
|
|
87
|
+
Object.assign(existing, {
|
|
88
|
+
slug: input.slug,
|
|
89
|
+
defaultBranch: input.defaultBranch,
|
|
90
|
+
providerMetadata: input.providerMetadata ?? {},
|
|
91
|
+
updatedAt: now
|
|
92
|
+
});
|
|
93
|
+
return existing;
|
|
94
|
+
}
|
|
95
|
+
const created = {
|
|
96
|
+
id: randomUUID(),
|
|
97
|
+
installationId: input.installationId,
|
|
98
|
+
externalId: input.externalId,
|
|
99
|
+
slug: input.slug,
|
|
100
|
+
defaultBranch: input.defaultBranch,
|
|
101
|
+
providerMetadata: input.providerMetadata ?? {},
|
|
102
|
+
createdAt: now,
|
|
103
|
+
updatedAt: now
|
|
104
|
+
};
|
|
105
|
+
this.repositoriesRows.push(created);
|
|
106
|
+
return created;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
connections = {
|
|
110
|
+
list: async ({ factoryProjectId }) => this.connectionsRows.filter((row) => row.factoryProjectId === factoryProjectId),
|
|
111
|
+
get: async ({ orgId, id }) => {
|
|
112
|
+
const row = this.connectionsRows.find((candidate) => candidate.id === id);
|
|
113
|
+
if (!row) return null;
|
|
114
|
+
return await this.installations.get({
|
|
115
|
+
orgId,
|
|
116
|
+
id: row.installationId
|
|
117
|
+
}) ? row : null;
|
|
118
|
+
},
|
|
119
|
+
create: async (input) => {
|
|
120
|
+
if (!await this.installations.get({
|
|
121
|
+
orgId: input.orgId,
|
|
122
|
+
id: input.installationId
|
|
123
|
+
})) throw new Error("Source-control installation not found");
|
|
124
|
+
const existing = this.connectionsRows.find((row) => row.factoryProjectId === input.factoryProjectId && row.integrationId === this.integrationId && row.installationId === input.installationId);
|
|
125
|
+
if (existing) return existing;
|
|
126
|
+
const created = {
|
|
127
|
+
id: randomUUID(),
|
|
128
|
+
factoryProjectId: input.factoryProjectId,
|
|
129
|
+
integrationId: this.integrationId,
|
|
130
|
+
installationId: input.installationId,
|
|
131
|
+
createdByUserId: input.createdByUserId,
|
|
132
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
133
|
+
};
|
|
134
|
+
this.connectionsRows.push(created);
|
|
135
|
+
return created;
|
|
136
|
+
},
|
|
137
|
+
delete: async ({ orgId, id }) => {
|
|
138
|
+
if (!await this.connections.get({
|
|
139
|
+
orgId,
|
|
140
|
+
id
|
|
141
|
+
})) return false;
|
|
142
|
+
this.connectionsRows.splice(0, this.connectionsRows.length, ...this.connectionsRows.filter((row) => row.id !== id));
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
projectRepositories = {
|
|
147
|
+
list: async ({ orgId, connectionId }) => await this.connections.get({
|
|
148
|
+
orgId,
|
|
149
|
+
id: connectionId
|
|
150
|
+
}) ? this.projectRepositoriesRows.filter((row) => row.connectionId === connectionId) : [],
|
|
151
|
+
listByExternalRepository: async ({ installationExternalId, repositoryExternalId }) => {
|
|
152
|
+
const targets = [];
|
|
153
|
+
for (const installation of this.installationsRows.filter((row) => row.externalId === installationExternalId)) {
|
|
154
|
+
const repository = this.repositoriesRows.find((row) => row.installationId === installation.id && row.externalId === repositoryExternalId);
|
|
155
|
+
if (!repository) continue;
|
|
156
|
+
for (const projectRepository of this.projectRepositoriesRows.filter((row) => row.repositoryId === repository.id)) {
|
|
157
|
+
const connection = this.connectionsRows.find((row) => row.id === projectRepository.connectionId && row.installationId === installation.id && row.integrationId === this.integrationId);
|
|
158
|
+
if (!connection) continue;
|
|
159
|
+
targets.push({
|
|
160
|
+
orgId: installation.orgId,
|
|
161
|
+
factoryProjectId: connection.factoryProjectId,
|
|
162
|
+
projectRepository
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return targets;
|
|
167
|
+
},
|
|
168
|
+
get: async ({ orgId, id }) => {
|
|
169
|
+
const row = this.projectRepositoriesRows.find((candidate) => candidate.id === id);
|
|
170
|
+
if (!row) return null;
|
|
171
|
+
return await this.connections.get({
|
|
172
|
+
orgId,
|
|
173
|
+
id: row.connectionId
|
|
174
|
+
}) ? row : null;
|
|
175
|
+
},
|
|
176
|
+
link: async (input) => {
|
|
177
|
+
const connection = await this.connections.get({
|
|
178
|
+
orgId: input.orgId,
|
|
179
|
+
id: input.connectionId
|
|
180
|
+
});
|
|
181
|
+
const repository = await this.repositories.get({
|
|
182
|
+
orgId: input.orgId,
|
|
183
|
+
id: input.repositoryId
|
|
184
|
+
});
|
|
185
|
+
if (!connection || !repository || repository.installationId !== connection.installationId) throw new Error("Source-control connection or repository not found");
|
|
186
|
+
const existing = this.projectRepositoriesRows.find((row) => row.connectionId === input.connectionId && row.repositoryId === input.repositoryId);
|
|
187
|
+
if (existing) return existing;
|
|
188
|
+
const now = /* @__PURE__ */ new Date();
|
|
189
|
+
const created = {
|
|
190
|
+
id: randomUUID(),
|
|
191
|
+
connectionId: input.connectionId,
|
|
192
|
+
repositoryId: input.repositoryId,
|
|
193
|
+
createdByUserId: input.createdByUserId,
|
|
194
|
+
branch: input.branch ?? null,
|
|
195
|
+
sandboxProvider: input.sandboxProvider,
|
|
196
|
+
sandboxWorkdir: input.sandboxWorkdir,
|
|
197
|
+
setupCommand: input.setupCommand ?? null,
|
|
198
|
+
createdAt: now,
|
|
199
|
+
updatedAt: now
|
|
200
|
+
};
|
|
201
|
+
this.projectRepositoriesRows.push(created);
|
|
202
|
+
return created;
|
|
203
|
+
},
|
|
204
|
+
update: async ({ orgId, id, input }) => {
|
|
205
|
+
const row = await this.projectRepositories.get({
|
|
206
|
+
orgId,
|
|
207
|
+
id
|
|
208
|
+
});
|
|
209
|
+
if (!row) return null;
|
|
210
|
+
Object.assign(row, input, { updatedAt: /* @__PURE__ */ new Date() });
|
|
211
|
+
return row;
|
|
212
|
+
},
|
|
213
|
+
unlink: async ({ orgId, id }) => {
|
|
214
|
+
if (!await this.projectRepositories.get({
|
|
215
|
+
orgId,
|
|
216
|
+
id
|
|
217
|
+
})) return false;
|
|
218
|
+
this.projectRepositoriesRows.splice(0, this.projectRepositoriesRows.length, ...this.projectRepositoriesRows.filter((row) => row.id !== id));
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
sandboxes = {
|
|
223
|
+
getOrCreate: async ({ projectRepository, userId }) => {
|
|
224
|
+
const existing = this.sandboxesRows.find((row) => row.projectRepositoryId === projectRepository.id && row.userId === userId);
|
|
225
|
+
if (existing) return existing;
|
|
226
|
+
const created = {
|
|
227
|
+
id: randomUUID(),
|
|
228
|
+
projectRepositoryId: projectRepository.id,
|
|
229
|
+
userId,
|
|
230
|
+
sandboxId: null,
|
|
231
|
+
sandboxWorkdir: projectRepository.sandboxWorkdir,
|
|
232
|
+
materializedAt: null,
|
|
233
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
234
|
+
};
|
|
235
|
+
this.sandboxesRows.push(created);
|
|
236
|
+
return created;
|
|
237
|
+
},
|
|
238
|
+
getById: async ({ id }) => this.sandboxesRows.find((row) => row.id === id) ?? null,
|
|
239
|
+
setWorkdir: async ({ id, sandboxWorkdir }) => {
|
|
240
|
+
const row = this.sandboxesRows.find((candidate) => candidate.id === id);
|
|
241
|
+
if (row) Object.assign(row, {
|
|
242
|
+
sandboxWorkdir,
|
|
243
|
+
materializedAt: null
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
setSandboxId: async ({ id, sandboxId }) => {
|
|
247
|
+
const row = this.sandboxesRows.find((candidate) => candidate.id === id);
|
|
248
|
+
if (row) row.sandboxId = sandboxId;
|
|
249
|
+
},
|
|
250
|
+
clearBinding: async ({ id }) => {
|
|
251
|
+
const row = this.sandboxesRows.find((candidate) => candidate.id === id);
|
|
252
|
+
if (row) Object.assign(row, {
|
|
253
|
+
sandboxId: null,
|
|
254
|
+
materializedAt: null
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
markMaterialized: async ({ id }) => {
|
|
258
|
+
const row = this.sandboxesRows.find((candidate) => candidate.id === id);
|
|
259
|
+
if (row) row.materializedAt = /* @__PURE__ */ new Date();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
worktrees = {
|
|
263
|
+
upsert: async (input) => {
|
|
264
|
+
const existing = this.worktreesRows.find((row) => row.projectRepositoryId === input.projectRepositoryId && row.userId === input.userId && row.branch === input.branch);
|
|
265
|
+
if (existing) {
|
|
266
|
+
existing.baseBranch = input.baseBranch;
|
|
267
|
+
existing.worktreePath = input.worktreePath;
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this.worktreesRows.push({
|
|
271
|
+
id: randomUUID(),
|
|
272
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
273
|
+
...input
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
list: async ({ projectRepositoryId, userId }) => this.worktreesRows.filter((row) => row.projectRepositoryId === projectRepositoryId && row.userId === userId),
|
|
277
|
+
get: async ({ projectRepositoryId, userId, branch }) => this.worktreesRows.find((row) => row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch) ?? null,
|
|
278
|
+
findByPath: async ({ projectRepositoryId, userId, worktreePath }) => this.worktreesRows.find((row) => row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.worktreePath === worktreePath) ?? null,
|
|
279
|
+
delete: async ({ projectRepositoryId, userId, branch }) => {
|
|
280
|
+
this.worktreesRows.splice(0, this.worktreesRows.length, ...this.worktreesRows.filter((row) => !(row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch)));
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
sessions = {
|
|
284
|
+
list: async ({ projectRepositoryId, userId }) => this.sessionsRows.filter((row) => row.projectRepositoryId === projectRepositoryId && row.userId === userId),
|
|
285
|
+
getBySessionId: async (sessionId) => this.sessionsRows.find((row) => row.sessionId === sessionId) ?? null,
|
|
286
|
+
getForBranch: async ({ projectRepositoryId, userId, branch }) => this.sessionsRows.find((row) => row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch) ?? null,
|
|
287
|
+
create: async (input) => {
|
|
288
|
+
const existing = await this.sessions.getForBranch(input);
|
|
289
|
+
if (existing) return existing;
|
|
290
|
+
const now = /* @__PURE__ */ new Date();
|
|
291
|
+
const session = {
|
|
292
|
+
id: randomUUID(),
|
|
293
|
+
...input,
|
|
294
|
+
sandboxId: null,
|
|
295
|
+
sandboxWorkdir: null,
|
|
296
|
+
materializedAt: null,
|
|
297
|
+
createdAt: now,
|
|
298
|
+
updatedAt: now
|
|
299
|
+
};
|
|
300
|
+
this.sessionsRows.push(session);
|
|
301
|
+
return session;
|
|
302
|
+
},
|
|
303
|
+
setSandbox: async ({ id, sandboxId, sandboxWorkdir }) => {
|
|
304
|
+
const row = this.sessionsRows.find((candidate) => candidate.id === id);
|
|
305
|
+
if (row) Object.assign(row, {
|
|
306
|
+
sandboxId,
|
|
307
|
+
sandboxWorkdir,
|
|
308
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
markMaterialized: async ({ id }) => {
|
|
312
|
+
const row = this.sessionsRows.find((candidate) => candidate.id === id);
|
|
313
|
+
if (row) Object.assign(row, {
|
|
314
|
+
materializedAt: /* @__PURE__ */ new Date(),
|
|
315
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
delete: async (id) => {
|
|
319
|
+
this.sessionsRows.splice(0, this.sessionsRows.length, ...this.sessionsRows.filter((row) => row.id !== id));
|
|
320
|
+
}
|
|
321
|
+
};
|
|
351
322
|
};
|
|
323
|
+
//#endregion
|
|
324
|
+
export { SourceControlStorageInMemory };
|
|
325
|
+
|
|
352
326
|
//# sourceMappingURL=inmemory.js.map
|