fn(worker_name$0, database_name$1, cron$2, api_token$3, handler$4) =>
#get_parts<@wasi.io>({
ids: $4.part_ids,
then: fn(parts$5) =>
#handle<@wasi.io>({
request: @http.request-of-url(method: "GET", url: "https://api.cloudflare.com/client/v4/accounts", headers: [], body: []),
secret_headers: [{name: "Authorization", prefix: "Bearer ", secret: $3}],
then: fn(result$6) =>
match $6 {
#error(error$7) =>
#done<@wasi.io>(@core.string-concat(left: "アカウントを読めませんでした: ", right: @http.error-text(error: $7))),
#ok(response$8) =>
let account_id$9 = @definy.json-string-field(json: @http.body-text(response: $8), key: "id");
let account_api$10 = @core.string-concat(left: "https://api.cloudflare.com/client/v4/accounts/", right: $9);
let script_url$11 = @std.string-join(items: [$10, "/workers/scripts/", $0], separator: "");
match @core.equal(left: $9, right: "") {
true =>
#done<@wasi.io>(@core.string-concat(left: "アカウントを読めませんでした: ", right: @http.body-text(response: $8))),
false =>
#handle<@wasi.io>({
request: @http.request-of-url(
method: "GET",
url: @std.string-join(items: [$10, "/d1/database?name=", $1], separator: ""),
headers: [],
body: []
),
secret_headers: [{name: "Authorization", prefix: "Bearer ", secret: $3}],
then: fn(result$12) =>
match $12 {
#error(error$13) =>
#done<@wasi.io>(@core.string-concat(
left: "D1 のデータベースを読めませんでした: ",
right: @http.error-text(error: $13)
)),
#ok(response$14) =>
let found$15 = @definy.json-string-field(json: @http.body-text(response: $14), key: "uuid");
match @core.equal(left: $15, right: "") {
false =>
@definy.deploy-service-script(
worker_name: $0,
database_name: $1,
database_id: $15,
cron: $2,
api_token: $3,
script_url: $11,
wasm: @core.compile-to-wasm(expr: $4.expression, parts: $5)
),
true =>
#handle<@wasi.io>({
request: @http.request-of-url(
method: "POST",
url: @core.string-concat(left: $10, right: "/d1/database"),
headers: [{name: "Content-Type", value: "application/json"}],
body: @core.string-to-bytes(
value: @std.string-join(items: ["{\"name\":", @definy.json-string-literal(value: $1), "}"], separator: "")
)
),
secret_headers: [{name: "Authorization", prefix: "Bearer ", secret: $3}],
then: fn(result$25) =>
match $25 {
#error(error$26) =>
#done<@wasi.io>(@core.string-concat(
left: "D1 のデータベースを作れませんでした: ",
right: @http.error-text(error: $26)
)),
#ok(response$27) =>
let created$28 = @definy.json-string-field(json: @http.body-text(response: $27), key: "uuid");
match @core.equal(left: $28, right: "") {
true =>
#done<@wasi.io>(@core.string-concat(
left: "D1 のデータベースを作れませんでした: ",
right: @http.body-text(response: $27)
)),
false =>
@definy.deploy-service-script(
worker_name: $0,
database_name: $1,
database_id: $28,
cron: $2,
api_token: $3,
script_url: $11,
wasm: @core.compile-to-wasm(expr: $4.expression, parts: $5)
)
}
}
})
}
}
})
}
}
})
})