@alienplatform/sdk 1.14.1 → 2.0.1
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/dist/dist.js +371 -275
- package/dist/index.d.ts +22 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -14356
- package/dist/native.d.ts +26 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +2 -0
- package/dist/worker-runtime/channel.d.ts +25 -0
- package/dist/worker-runtime/channel.d.ts.map +1 -0
- package/dist/worker-runtime/errors.d.ts +79 -0
- package/dist/worker-runtime/errors.d.ts.map +1 -0
- package/dist/worker-runtime/event-loop.d.ts +43 -0
- package/dist/worker-runtime/event-loop.d.ts.map +1 -0
- package/dist/{generated → worker-runtime/generated}/control.d.ts +15 -15
- package/dist/worker-runtime/generated/control.d.ts.map +1 -0
- package/dist/worker-runtime/generated/google/protobuf/duration.d.ts.map +1 -0
- package/dist/worker-runtime/generated/google/protobuf/timestamp.d.ts.map +1 -0
- package/dist/{generated → worker-runtime/generated}/wait_until.d.ts +29 -29
- package/dist/worker-runtime/generated/wait_until.d.ts.map +1 -0
- package/dist/worker-runtime/grpc-utils.d.ts +23 -0
- package/dist/worker-runtime/grpc-utils.d.ts.map +1 -0
- package/dist/worker-runtime/index.d.ts +33 -0
- package/dist/worker-runtime/index.d.ts.map +1 -0
- package/dist/{src.js → worker-runtime/index.js} +9370 -4035
- package/dist/worker-runtime/registry.d.ts +169 -0
- package/dist/worker-runtime/registry.d.ts.map +1 -0
- package/dist/worker-runtime/service-definitions.d.ts +12 -0
- package/dist/worker-runtime/service-definitions.d.ts.map +1 -0
- package/dist/worker-runtime/wait-until-manager.d.ts +34 -0
- package/dist/worker-runtime/wait-until-manager.d.ts.map +1 -0
- package/package.json +18 -38
- package/.turbo/turbo-build.log +0 -30
- package/AGENTS.md +0 -70
- package/dist/bearerTokenAuthenticationPolicy.js +0 -3028
- package/dist/bindings/artifact-registry.d.ts +0 -88
- package/dist/bindings/artifact-registry.d.ts.map +0 -1
- package/dist/bindings/build.d.ts +0 -67
- package/dist/bindings/build.d.ts.map +0 -1
- package/dist/bindings/index.d.ts +0 -13
- package/dist/bindings/index.d.ts.map +0 -1
- package/dist/bindings/kv.d.ts +0 -113
- package/dist/bindings/kv.d.ts.map +0 -1
- package/dist/bindings/postgres.d.ts +0 -90
- package/dist/bindings/postgres.d.ts.map +0 -1
- package/dist/bindings/postgres.test.d.ts +0 -2
- package/dist/bindings/postgres.test.d.ts.map +0 -1
- package/dist/bindings/queue.d.ts +0 -81
- package/dist/bindings/queue.d.ts.map +0 -1
- package/dist/bindings/service-account.d.ts +0 -46
- package/dist/bindings/service-account.d.ts.map +0 -1
- package/dist/bindings/storage.d.ts +0 -164
- package/dist/bindings/storage.d.ts.map +0 -1
- package/dist/bindings/vault.d.ts +0 -65
- package/dist/bindings/vault.d.ts.map +0 -1
- package/dist/bindings/worker.d.ts +0 -72
- package/dist/bindings/worker.d.ts.map +0 -1
- package/dist/channel.d.ts +0 -39
- package/dist/channel.d.ts.map +0 -1
- package/dist/checksum.js +0 -6176
- package/dist/commands/client.d.ts +0 -47
- package/dist/commands/client.d.ts.map +0 -1
- package/dist/commands/errors.d.ts +0 -198
- package/dist/commands/errors.d.ts.map +0 -1
- package/dist/commands/index.d.ts +0 -23
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js +0 -387
- package/dist/commands/types.d.ts +0 -40
- package/dist/commands/types.d.ts.map +0 -1
- package/dist/commands.d.ts +0 -55
- package/dist/commands.d.ts.map +0 -1
- package/dist/context.d.ts +0 -182
- package/dist/context.d.ts.map +0 -1
- package/dist/dist-cjs.js +0 -15258
- package/dist/dist2.js +0 -1239
- package/dist/errors.d.ts +0 -359
- package/dist/errors.d.ts.map +0 -1
- package/dist/es5.js +0 -1720
- package/dist/esm.js +0 -18068
- package/dist/esm2.js +0 -3166
- package/dist/event-streams.js +0 -770
- package/dist/events.d.ts +0 -163
- package/dist/events.d.ts.map +0 -1
- package/dist/generated/artifact_registry.d.ts +0 -302
- package/dist/generated/artifact_registry.d.ts.map +0 -1
- package/dist/generated/build.d.ts +0 -184
- package/dist/generated/build.d.ts.map +0 -1
- package/dist/generated/container.d.ts +0 -101
- package/dist/generated/container.d.ts.map +0 -1
- package/dist/generated/control.d.ts.map +0 -1
- package/dist/generated/google/protobuf/duration.d.ts.map +0 -1
- package/dist/generated/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/generated/kv.d.ts +0 -182
- package/dist/generated/kv.d.ts.map +0 -1
- package/dist/generated/queue.d.ts +0 -127
- package/dist/generated/queue.d.ts.map +0 -1
- package/dist/generated/service_account.d.ts +0 -112
- package/dist/generated/service_account.d.ts.map +0 -1
- package/dist/generated/storage.d.ts +0 -784
- package/dist/generated/storage.d.ts.map +0 -1
- package/dist/generated/vault.d.ts +0 -107
- package/dist/generated/vault.d.ts.map +0 -1
- package/dist/generated/wait_until.d.ts.map +0 -1
- package/dist/generated/worker.d.ts +0 -107
- package/dist/generated/worker.d.ts.map +0 -1
- package/dist/global.d.ts +0 -208
- package/dist/global.d.ts.map +0 -1
- package/dist/grpc-utils.d.ts +0 -25
- package/dist/grpc-utils.d.ts.map +0 -1
- package/dist/jws.js +0 -611
- package/dist/open.js +0 -461
- package/dist/rolldown-runtime.js +0 -44
- package/dist/src2.js +0 -114032
- package/dist/types.d.ts +0 -337
- package/dist/types.d.ts.map +0 -1
- package/dist/wait-until.d.ts +0 -115
- package/dist/wait-until.d.ts.map +0 -1
- package/scripts/generate-proto.sh +0 -46
- package/src/bindings/AGENTS.md +0 -105
- package/src/bindings/artifact-registry.ts +0 -317
- package/src/bindings/build.ts +0 -195
- package/src/bindings/index.ts +0 -13
- package/src/bindings/kv.ts +0 -240
- package/src/bindings/postgres.test.ts +0 -17
- package/src/bindings/postgres.ts +0 -446
- package/src/bindings/queue.ts +0 -191
- package/src/bindings/service-account.ts +0 -113
- package/src/bindings/storage.ts +0 -536
- package/src/bindings/vault.ts +0 -133
- package/src/bindings/worker.ts +0 -164
- package/src/channel.ts +0 -102
- package/src/commands/client.ts +0 -446
- package/src/commands/errors.ts +0 -126
- package/src/commands/index.ts +0 -41
- package/src/commands/types.ts +0 -52
- package/src/commands.ts +0 -76
- package/src/context.ts +0 -368
- package/src/errors.ts +0 -280
- package/src/events.ts +0 -511
- package/src/generated/artifact_registry.ts +0 -2096
- package/src/generated/build.ts +0 -1311
- package/src/generated/container.ts +0 -503
- package/src/generated/control.ts +0 -2018
- package/src/generated/google/protobuf/duration.ts +0 -196
- package/src/generated/google/protobuf/timestamp.ts +0 -226
- package/src/generated/kv.ts +0 -1169
- package/src/generated/queue.ts +0 -753
- package/src/generated/service_account.ts +0 -814
- package/src/generated/storage.ts +0 -3820
- package/src/generated/vault.ts +0 -543
- package/src/generated/wait_until.ts +0 -829
- package/src/generated/worker.ts +0 -759
- package/src/global.ts +0 -287
- package/src/grpc-utils.ts +0 -159
- package/src/index.ts +0 -160
- package/src/types.ts +0 -397
- package/src/wait-until.ts +0 -273
- package/tsconfig.json +0 -8
- package/tsdown.config.ts +0 -17
- /package/dist/{generated → worker-runtime/generated}/google/protobuf/duration.d.ts +0 -0
- /package/dist/{generated → worker-runtime/generated}/google/protobuf/timestamp.d.ts +0 -0
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ArtifactRegistry binding implementation.
|
|
3
|
-
*
|
|
4
|
-
* Provides container image repository management.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { type Channel, createClient } from "nice-grpc"
|
|
8
|
-
import {
|
|
9
|
-
ArtifactRegistryServiceDefinition,
|
|
10
|
-
ComputeServiceType as ComputeServiceTypeProto,
|
|
11
|
-
type Credentials,
|
|
12
|
-
type CrossAccountAccess as CrossAccountAccessProto,
|
|
13
|
-
type CrossAccountPermissions as CrossAccountPermissionsProto,
|
|
14
|
-
type ArtifactRegistryServiceClient as GeneratedClient,
|
|
15
|
-
ArtifactRegistryPermissions as PermissionsProto,
|
|
16
|
-
type RepositoryResult,
|
|
17
|
-
} from "../generated/artifact_registry.js"
|
|
18
|
-
import { wrapGrpcCall } from "../grpc-utils.js"
|
|
19
|
-
import type {
|
|
20
|
-
ArtifactRegistryCredentials,
|
|
21
|
-
ArtifactRegistryPermissions,
|
|
22
|
-
ComputeServiceType,
|
|
23
|
-
CrossAccountAccess,
|
|
24
|
-
CrossAccountPermissions,
|
|
25
|
-
RepositoryInfo,
|
|
26
|
-
} from "../types.js"
|
|
27
|
-
|
|
28
|
-
// Permission map
|
|
29
|
-
const permissionMap: Record<ArtifactRegistryPermissions, PermissionsProto> = {
|
|
30
|
-
pull: PermissionsProto.PULL,
|
|
31
|
-
"push-pull": PermissionsProto.PUSH_PULL,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* ArtifactRegistry binding for container repository management.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* import { artifactRegistry } from "@alienplatform/sdk"
|
|
40
|
-
*
|
|
41
|
-
* const registry = artifactRegistry("my-registry")
|
|
42
|
-
*
|
|
43
|
-
* // Create a repository
|
|
44
|
-
* const repo = await registry.createRepository("my-app")
|
|
45
|
-
* console.log("Repository URI:", repo.uri)
|
|
46
|
-
*
|
|
47
|
-
* // Generate push credentials
|
|
48
|
-
* const creds = await registry.generateCredentials("my-app", "push-pull")
|
|
49
|
-
* console.log("Username:", creds.username)
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export class ArtifactRegistry {
|
|
53
|
-
private readonly client: GeneratedClient
|
|
54
|
-
private readonly bindingName: string
|
|
55
|
-
|
|
56
|
-
constructor(channel: Channel, bindingName: string) {
|
|
57
|
-
this.client = createClient(ArtifactRegistryServiceDefinition, channel)
|
|
58
|
-
this.bindingName = bindingName
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Create a repository.
|
|
63
|
-
*
|
|
64
|
-
* @param repoName - Name of the repository
|
|
65
|
-
* @returns Repository information
|
|
66
|
-
*/
|
|
67
|
-
async createRepository(repoName: string): Promise<RepositoryInfo> {
|
|
68
|
-
return await wrapGrpcCall(
|
|
69
|
-
"ArtifactRegistryService",
|
|
70
|
-
"CreateRepository",
|
|
71
|
-
async () => {
|
|
72
|
-
const response = await this.client.createRepository({
|
|
73
|
-
bindingName: this.bindingName,
|
|
74
|
-
repoName,
|
|
75
|
-
})
|
|
76
|
-
return this.fromProtoResult(response.result!)
|
|
77
|
-
},
|
|
78
|
-
{ bindingName: this.bindingName },
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Get repository details.
|
|
84
|
-
*
|
|
85
|
-
* @param repoId - Repository ID
|
|
86
|
-
* @returns Repository information
|
|
87
|
-
*/
|
|
88
|
-
async getRepository(repoId: string): Promise<RepositoryInfo> {
|
|
89
|
-
return await wrapGrpcCall(
|
|
90
|
-
"ArtifactRegistryService",
|
|
91
|
-
"GetRepository",
|
|
92
|
-
async () => {
|
|
93
|
-
const response = await this.client.getRepository({
|
|
94
|
-
bindingName: this.bindingName,
|
|
95
|
-
repoId,
|
|
96
|
-
})
|
|
97
|
-
return this.fromProtoResult(response.result!)
|
|
98
|
-
},
|
|
99
|
-
{ bindingName: this.bindingName },
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Add cross-account access to a repository.
|
|
105
|
-
*
|
|
106
|
-
* @param repoId - Repository ID
|
|
107
|
-
* @param access - Cross-account access configuration
|
|
108
|
-
*/
|
|
109
|
-
async addCrossAccountAccess(repoId: string, access: CrossAccountAccess): Promise<void> {
|
|
110
|
-
await wrapGrpcCall(
|
|
111
|
-
"ArtifactRegistryService",
|
|
112
|
-
"AddCrossAccountAccess",
|
|
113
|
-
async () => {
|
|
114
|
-
await this.client.addCrossAccountAccess({
|
|
115
|
-
bindingName: this.bindingName,
|
|
116
|
-
repoId,
|
|
117
|
-
access: this.toProtoCrossAccountAccess(access),
|
|
118
|
-
})
|
|
119
|
-
},
|
|
120
|
-
{ bindingName: this.bindingName },
|
|
121
|
-
)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Remove cross-account access from a repository.
|
|
126
|
-
*
|
|
127
|
-
* @param repoId - Repository ID
|
|
128
|
-
* @param access - Cross-account access configuration to remove
|
|
129
|
-
*/
|
|
130
|
-
async removeCrossAccountAccess(repoId: string, access: CrossAccountAccess): Promise<void> {
|
|
131
|
-
await wrapGrpcCall(
|
|
132
|
-
"ArtifactRegistryService",
|
|
133
|
-
"RemoveCrossAccountAccess",
|
|
134
|
-
async () => {
|
|
135
|
-
await this.client.removeCrossAccountAccess({
|
|
136
|
-
bindingName: this.bindingName,
|
|
137
|
-
repoId,
|
|
138
|
-
access: this.toProtoCrossAccountAccess(access),
|
|
139
|
-
})
|
|
140
|
-
},
|
|
141
|
-
{ bindingName: this.bindingName },
|
|
142
|
-
)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get current cross-account access permissions for a repository.
|
|
147
|
-
*
|
|
148
|
-
* @param repoId - Repository ID
|
|
149
|
-
* @returns Current cross-account permissions
|
|
150
|
-
*/
|
|
151
|
-
async getCrossAccountAccess(repoId: string): Promise<CrossAccountPermissions> {
|
|
152
|
-
return await wrapGrpcCall(
|
|
153
|
-
"ArtifactRegistryService",
|
|
154
|
-
"GetCrossAccountAccess",
|
|
155
|
-
async () => {
|
|
156
|
-
const response = await this.client.getCrossAccountAccess({
|
|
157
|
-
bindingName: this.bindingName,
|
|
158
|
-
repoId,
|
|
159
|
-
})
|
|
160
|
-
return this.fromProtoCrossAccountPermissions(response.permissions!)
|
|
161
|
-
},
|
|
162
|
-
{ bindingName: this.bindingName },
|
|
163
|
-
)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Generate credentials for repository access.
|
|
168
|
-
*
|
|
169
|
-
* @param repoId - Repository ID
|
|
170
|
-
* @param permissions - Permission level (pull or push-pull)
|
|
171
|
-
* @param ttlSeconds - Optional TTL in seconds
|
|
172
|
-
* @returns Repository credentials
|
|
173
|
-
*/
|
|
174
|
-
async generateCredentials(
|
|
175
|
-
repoId: string,
|
|
176
|
-
permissions: ArtifactRegistryPermissions,
|
|
177
|
-
ttlSeconds?: number,
|
|
178
|
-
): Promise<ArtifactRegistryCredentials> {
|
|
179
|
-
return await wrapGrpcCall(
|
|
180
|
-
"ArtifactRegistryService",
|
|
181
|
-
"GenerateCredentials",
|
|
182
|
-
async () => {
|
|
183
|
-
const response = await this.client.generateCredentials({
|
|
184
|
-
bindingName: this.bindingName,
|
|
185
|
-
repoId,
|
|
186
|
-
permissions: permissionMap[permissions],
|
|
187
|
-
ttlSeconds,
|
|
188
|
-
})
|
|
189
|
-
return this.fromProtoCredentials(response.credentials!)
|
|
190
|
-
},
|
|
191
|
-
{ bindingName: this.bindingName },
|
|
192
|
-
)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Delete a repository.
|
|
197
|
-
*
|
|
198
|
-
* @param repoId - Repository ID
|
|
199
|
-
*/
|
|
200
|
-
async deleteRepository(repoId: string): Promise<void> {
|
|
201
|
-
await wrapGrpcCall(
|
|
202
|
-
"ArtifactRegistryService",
|
|
203
|
-
"DeleteRepository",
|
|
204
|
-
async () => {
|
|
205
|
-
await this.client.deleteRepository({
|
|
206
|
-
bindingName: this.bindingName,
|
|
207
|
-
repoId,
|
|
208
|
-
})
|
|
209
|
-
},
|
|
210
|
-
{ bindingName: this.bindingName },
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Private helpers
|
|
215
|
-
|
|
216
|
-
private fromProtoResult(proto: RepositoryResult): RepositoryInfo {
|
|
217
|
-
return {
|
|
218
|
-
name: proto.name,
|
|
219
|
-
uri: proto.uri ?? "",
|
|
220
|
-
createdAt: proto.createdAt ? new Date(proto.createdAt) : undefined,
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private fromProtoCredentials(proto: Credentials): ArtifactRegistryCredentials {
|
|
225
|
-
return {
|
|
226
|
-
authMethod: proto.authMethod === 1 ? "bearer" : "basic",
|
|
227
|
-
username: proto.username,
|
|
228
|
-
password: proto.password,
|
|
229
|
-
expiresAt: proto.expiresAt ? new Date(proto.expiresAt) : undefined,
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
private toProtoCrossAccountAccess(access: CrossAccountAccess): CrossAccountAccessProto {
|
|
234
|
-
if (access.type === "aws") {
|
|
235
|
-
return {
|
|
236
|
-
aws: {
|
|
237
|
-
accountIds: access.aws.accountIds,
|
|
238
|
-
allowedServiceTypes: access.aws.allowedServiceTypes.map(st =>
|
|
239
|
-
this.computeServiceTypeToProto(st),
|
|
240
|
-
),
|
|
241
|
-
roleArns: access.aws.roleArns,
|
|
242
|
-
regions: access.aws.regions,
|
|
243
|
-
},
|
|
244
|
-
gcp: undefined,
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return {
|
|
248
|
-
aws: undefined,
|
|
249
|
-
gcp: {
|
|
250
|
-
projectNumbers: access.gcp.projectNumbers,
|
|
251
|
-
allowedServiceTypes: access.gcp.allowedServiceTypes.map(st =>
|
|
252
|
-
this.computeServiceTypeToProto(st),
|
|
253
|
-
),
|
|
254
|
-
serviceAccountEmails: access.gcp.serviceAccountEmails,
|
|
255
|
-
},
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
private fromProtoCrossAccountAccess(proto: CrossAccountAccessProto): CrossAccountAccess {
|
|
260
|
-
if (proto.aws) {
|
|
261
|
-
return {
|
|
262
|
-
type: "aws",
|
|
263
|
-
aws: {
|
|
264
|
-
accountIds: proto.aws.accountIds,
|
|
265
|
-
allowedServiceTypes: proto.aws.allowedServiceTypes
|
|
266
|
-
.map(st => this.protoToComputeServiceType(st))
|
|
267
|
-
.filter((st): st is ComputeServiceType => st !== undefined),
|
|
268
|
-
roleArns: proto.aws.roleArns,
|
|
269
|
-
regions: proto.aws.regions,
|
|
270
|
-
},
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (proto.gcp) {
|
|
274
|
-
return {
|
|
275
|
-
type: "gcp",
|
|
276
|
-
gcp: {
|
|
277
|
-
projectNumbers: proto.gcp.projectNumbers,
|
|
278
|
-
allowedServiceTypes: proto.gcp.allowedServiceTypes
|
|
279
|
-
.map(st => this.protoToComputeServiceType(st))
|
|
280
|
-
.filter((st): st is ComputeServiceType => st !== undefined),
|
|
281
|
-
serviceAccountEmails: proto.gcp.serviceAccountEmails,
|
|
282
|
-
},
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
throw new Error("Invalid CrossAccountAccess: neither aws nor gcp set")
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
private fromProtoCrossAccountPermissions(
|
|
289
|
-
proto: CrossAccountPermissionsProto,
|
|
290
|
-
): CrossAccountPermissions {
|
|
291
|
-
if (!proto.access) {
|
|
292
|
-
throw new Error("Invalid CrossAccountPermissions: access is missing")
|
|
293
|
-
}
|
|
294
|
-
return {
|
|
295
|
-
access: this.fromProtoCrossAccountAccess(proto.access),
|
|
296
|
-
lastUpdated: proto.lastUpdated,
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
private computeServiceTypeToProto(st: ComputeServiceType): ComputeServiceTypeProto {
|
|
301
|
-
switch (st) {
|
|
302
|
-
case "worker":
|
|
303
|
-
return ComputeServiceTypeProto.WORKER
|
|
304
|
-
default:
|
|
305
|
-
return ComputeServiceTypeProto.UNRECOGNIZED
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
private protoToComputeServiceType(st: ComputeServiceTypeProto): ComputeServiceType | undefined {
|
|
310
|
-
switch (st) {
|
|
311
|
-
case ComputeServiceTypeProto.WORKER:
|
|
312
|
-
return "worker"
|
|
313
|
-
default:
|
|
314
|
-
return undefined
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
package/src/bindings/build.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build binding implementation.
|
|
3
|
-
*
|
|
4
|
-
* Provides build execution capabilities.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { BuildStatus } from "@alienplatform/core"
|
|
8
|
-
import { type Channel, createClient } from "nice-grpc"
|
|
9
|
-
import {
|
|
10
|
-
type BuildConfig as BuildConfigProto,
|
|
11
|
-
type BuildExecution as BuildExecutionProto,
|
|
12
|
-
BuildServiceDefinition,
|
|
13
|
-
BuildStatus as BuildStatusProto,
|
|
14
|
-
ComputeType,
|
|
15
|
-
type BuildServiceClient as GeneratedBuildServiceClient,
|
|
16
|
-
} from "../generated/build.js"
|
|
17
|
-
import { wrapGrpcCall } from "../grpc-utils.js"
|
|
18
|
-
import type { BuildExecution, BuildStartConfig } from "../types.js"
|
|
19
|
-
|
|
20
|
-
// Map proto status to core BuildStatus (matches Rust: Unspecified → Failed)
|
|
21
|
-
const statusMap: Record<number, BuildStatus> = {
|
|
22
|
-
[BuildStatusProto.BUILD_STATUS_UNSPECIFIED]: "FAILED",
|
|
23
|
-
[BuildStatusProto.BUILD_STATUS_QUEUED]: "QUEUED",
|
|
24
|
-
[BuildStatusProto.BUILD_STATUS_RUNNING]: "RUNNING",
|
|
25
|
-
[BuildStatusProto.BUILD_STATUS_SUCCEEDED]: "SUCCEEDED",
|
|
26
|
-
[BuildStatusProto.BUILD_STATUS_FAILED]: "FAILED",
|
|
27
|
-
[BuildStatusProto.BUILD_STATUS_CANCELLED]: "CANCELLED",
|
|
28
|
-
[BuildStatusProto.BUILD_STATUS_TIMED_OUT]: "TIMED_OUT",
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Map compute type to proto
|
|
32
|
-
const computeTypeMap: Record<string, ComputeType> = {
|
|
33
|
-
small: ComputeType.COMPUTE_TYPE_SMALL,
|
|
34
|
-
medium: ComputeType.COMPUTE_TYPE_MEDIUM,
|
|
35
|
-
large: ComputeType.COMPUTE_TYPE_LARGE,
|
|
36
|
-
"x-large": ComputeType.COMPUTE_TYPE_XLARGE,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Build binding for executing build operations.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* import { build } from "@alienplatform/sdk"
|
|
45
|
-
*
|
|
46
|
-
* const builder = build("my-builder")
|
|
47
|
-
*
|
|
48
|
-
* // Start a build
|
|
49
|
-
* const execution = await builder.start({
|
|
50
|
-
* script: "npm run build",
|
|
51
|
-
* computeType: "medium",
|
|
52
|
-
* timeoutSeconds: 600,
|
|
53
|
-
* })
|
|
54
|
-
*
|
|
55
|
-
* // Wait for completion
|
|
56
|
-
* const result = await builder.waitForCompletion(execution.id)
|
|
57
|
-
* console.log("Build status:", result.status)
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export class Build {
|
|
61
|
-
private readonly client: GeneratedBuildServiceClient
|
|
62
|
-
private readonly bindingName: string
|
|
63
|
-
|
|
64
|
-
constructor(channel: Channel, bindingName: string) {
|
|
65
|
-
this.client = createClient(BuildServiceDefinition, channel)
|
|
66
|
-
this.bindingName = bindingName
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Start a new build.
|
|
71
|
-
*
|
|
72
|
-
* @param config - Build configuration
|
|
73
|
-
* @returns Build execution information
|
|
74
|
-
*/
|
|
75
|
-
async start(config: BuildStartConfig): Promise<BuildExecution> {
|
|
76
|
-
const protoConfig = this.toProtoConfig(config)
|
|
77
|
-
|
|
78
|
-
return await wrapGrpcCall(
|
|
79
|
-
"BuildService",
|
|
80
|
-
"StartBuild",
|
|
81
|
-
async () => {
|
|
82
|
-
const response = await this.client.startBuild({
|
|
83
|
-
bindingName: this.bindingName,
|
|
84
|
-
config: protoConfig,
|
|
85
|
-
})
|
|
86
|
-
return this.fromProtoExecution(response.execution!)
|
|
87
|
-
},
|
|
88
|
-
{ bindingName: this.bindingName },
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get the status of a build.
|
|
94
|
-
*
|
|
95
|
-
* @param buildId - Build execution ID
|
|
96
|
-
* @returns Build execution information
|
|
97
|
-
*/
|
|
98
|
-
async getStatus(buildId: string): Promise<BuildExecution> {
|
|
99
|
-
return await wrapGrpcCall(
|
|
100
|
-
"BuildService",
|
|
101
|
-
"GetBuildStatus",
|
|
102
|
-
async () => {
|
|
103
|
-
const response = await this.client.getBuildStatus({
|
|
104
|
-
bindingName: this.bindingName,
|
|
105
|
-
buildId,
|
|
106
|
-
})
|
|
107
|
-
return this.fromProtoExecution(response.execution!)
|
|
108
|
-
},
|
|
109
|
-
{ bindingName: this.bindingName },
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Stop a running build.
|
|
115
|
-
*
|
|
116
|
-
* @param buildId - Build execution ID
|
|
117
|
-
*/
|
|
118
|
-
async stop(buildId: string): Promise<void> {
|
|
119
|
-
await wrapGrpcCall(
|
|
120
|
-
"BuildService",
|
|
121
|
-
"StopBuild",
|
|
122
|
-
async () => {
|
|
123
|
-
await this.client.stopBuild({
|
|
124
|
-
bindingName: this.bindingName,
|
|
125
|
-
buildId,
|
|
126
|
-
})
|
|
127
|
-
},
|
|
128
|
-
{ bindingName: this.bindingName },
|
|
129
|
-
)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Wait for a build to complete.
|
|
134
|
-
*
|
|
135
|
-
* @param buildId - Build execution ID
|
|
136
|
-
* @param options - Polling options
|
|
137
|
-
* @returns Final build execution information
|
|
138
|
-
*/
|
|
139
|
-
async waitForCompletion(
|
|
140
|
-
buildId: string,
|
|
141
|
-
options?: { pollIntervalMs?: number; timeoutMs?: number },
|
|
142
|
-
): Promise<BuildExecution> {
|
|
143
|
-
const pollInterval = options?.pollIntervalMs ?? 5000
|
|
144
|
-
const timeout = options?.timeoutMs ?? 30 * 60 * 1000 // 30 minutes default
|
|
145
|
-
const startTime = Date.now()
|
|
146
|
-
|
|
147
|
-
while (Date.now() - startTime < timeout) {
|
|
148
|
-
const execution = await this.getStatus(buildId)
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
execution.status === "SUCCEEDED" ||
|
|
152
|
-
execution.status === "FAILED" ||
|
|
153
|
-
execution.status === "CANCELLED" ||
|
|
154
|
-
execution.status === "TIMED_OUT"
|
|
155
|
-
) {
|
|
156
|
-
return execution
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
await new Promise(resolve => setTimeout(resolve, pollInterval))
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
throw new Error(`Build ${buildId} did not complete within timeout`)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Private helpers
|
|
166
|
-
|
|
167
|
-
private toProtoConfig(config: BuildStartConfig): BuildConfigProto {
|
|
168
|
-
return {
|
|
169
|
-
script: config.script,
|
|
170
|
-
environment: config.environment ?? {},
|
|
171
|
-
computeType: config.computeType
|
|
172
|
-
? (computeTypeMap[config.computeType] ?? ComputeType.COMPUTE_TYPE_UNSPECIFIED)
|
|
173
|
-
: ComputeType.COMPUTE_TYPE_UNSPECIFIED,
|
|
174
|
-
timeoutSeconds: config.timeoutSeconds,
|
|
175
|
-
monitoring: config.monitoring
|
|
176
|
-
? {
|
|
177
|
-
endpoint: config.monitoring.endpoint,
|
|
178
|
-
headers: config.monitoring.headers ?? {},
|
|
179
|
-
logsUri: config.monitoring.logsUri ?? "/v1/logs",
|
|
180
|
-
tlsEnabled: config.monitoring.tlsEnabled ?? true,
|
|
181
|
-
tlsVerify: config.monitoring.tlsVerify ?? true,
|
|
182
|
-
}
|
|
183
|
-
: undefined,
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
private fromProtoExecution(proto: BuildExecutionProto): BuildExecution {
|
|
188
|
-
return {
|
|
189
|
-
id: proto.id,
|
|
190
|
-
status: statusMap[proto.status] ?? "QUEUED",
|
|
191
|
-
startTime: proto.startTime ? new Date(proto.startTime) : undefined,
|
|
192
|
-
endTime: proto.endTime ? new Date(proto.endTime) : undefined,
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
package/src/bindings/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Binding exports.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { Storage } from "./storage.js"
|
|
6
|
-
export { Kv } from "./kv.js"
|
|
7
|
-
export { Queue } from "./queue.js"
|
|
8
|
-
export { Vault } from "./vault.js"
|
|
9
|
-
export { Build } from "./build.js"
|
|
10
|
-
export { ArtifactRegistry } from "./artifact-registry.js"
|
|
11
|
-
export { WorkerBinding } from "./worker.js"
|
|
12
|
-
export { ServiceAccount } from "./service-account.js"
|
|
13
|
-
export { getPostgresConnection, type PostgresConnection } from "./postgres.js"
|