wip: zen
This commit is contained in:
@@ -119,6 +119,7 @@ const ZEN_MODELS = [
|
|||||||
new sst.Secret("ZEN_MODELS5"),
|
new sst.Secret("ZEN_MODELS5"),
|
||||||
new sst.Secret("ZEN_MODELS6"),
|
new sst.Secret("ZEN_MODELS6"),
|
||||||
new sst.Secret("ZEN_MODELS7"),
|
new sst.Secret("ZEN_MODELS7"),
|
||||||
|
new sst.Secret("ZEN_MODELS8"),
|
||||||
]
|
]
|
||||||
const ZEN_BLACK = new sst.Secret("ZEN_BLACK")
|
const ZEN_BLACK = new sst.Secret("ZEN_BLACK")
|
||||||
const STRIPE_SECRET_KEY = new sst.Secret("STRIPE_SECRET_KEY")
|
const STRIPE_SECRET_KEY = new sst.Secret("STRIPE_SECRET_KEY")
|
||||||
|
|||||||
@@ -8,33 +8,25 @@ const stage = process.argv[2]
|
|||||||
if (!stage) throw new Error("Stage is required")
|
if (!stage) throw new Error("Stage is required")
|
||||||
|
|
||||||
const root = path.resolve(process.cwd(), "..", "..", "..")
|
const root = path.resolve(process.cwd(), "..", "..", "..")
|
||||||
|
const PARTS = 8
|
||||||
|
|
||||||
// read the secret
|
// read the secret
|
||||||
const ret = await $`bun sst secret list`.cwd(root).text()
|
const ret = await $`bun sst secret list`.cwd(root).text()
|
||||||
const lines = ret.split("\n")
|
const lines = ret.split("\n")
|
||||||
const value1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[1]
|
const values = Array.from({ length: PARTS }, (_, i) => {
|
||||||
const value2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1]
|
const value = lines
|
||||||
const value3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1]
|
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}`))
|
||||||
const value4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1]
|
?.split("=")
|
||||||
const value5 = lines.find((line) => line.startsWith("ZEN_MODELS5"))?.split("=")[1]
|
.slice(1)
|
||||||
const value6 = lines.find((line) => line.startsWith("ZEN_MODELS6"))?.split("=")[1]
|
.join("=")
|
||||||
const value7 = lines.find((line) => line.startsWith("ZEN_MODELS7"))?.split("=")[1]
|
if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
|
||||||
if (!value1) throw new Error("ZEN_MODELS1 not found")
|
return value
|
||||||
if (!value2) throw new Error("ZEN_MODELS2 not found")
|
})
|
||||||
if (!value3) throw new Error("ZEN_MODELS3 not found")
|
|
||||||
if (!value4) throw new Error("ZEN_MODELS4 not found")
|
|
||||||
if (!value5) throw new Error("ZEN_MODELS5 not found")
|
|
||||||
if (!value6) throw new Error("ZEN_MODELS6 not found")
|
|
||||||
if (!value7) throw new Error("ZEN_MODELS7 not found")
|
|
||||||
|
|
||||||
// validate value
|
// validate value
|
||||||
ZenData.validate(JSON.parse(value1 + value2 + value3 + value4 + value5 + value6 + value7))
|
ZenData.validate(JSON.parse(values.join("")))
|
||||||
|
|
||||||
// update the secret
|
// update the secret
|
||||||
await $`bun sst secret set ZEN_MODELS1 ${value1} --stage ${stage}`
|
for (let i = 0; i < PARTS; i++) {
|
||||||
await $`bun sst secret set ZEN_MODELS2 ${value2} --stage ${stage}`
|
await $`bun sst secret set ZEN_MODELS${i + 1} --stage ${stage} -- ${values[i]}`
|
||||||
await $`bun sst secret set ZEN_MODELS3 ${value3} --stage ${stage}`
|
}
|
||||||
await $`bun sst secret set ZEN_MODELS4 ${value4} --stage ${stage}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS5 ${value5} --stage ${stage}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS6 ${value6} --stage ${stage}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS7 ${value7} --stage ${stage}`
|
|
||||||
|
|||||||
@@ -8,32 +8,25 @@ const stage = process.argv[2]
|
|||||||
if (!stage) throw new Error("Stage is required")
|
if (!stage) throw new Error("Stage is required")
|
||||||
|
|
||||||
const root = path.resolve(process.cwd(), "..", "..", "..")
|
const root = path.resolve(process.cwd(), "..", "..", "..")
|
||||||
|
const PARTS = 8
|
||||||
|
|
||||||
// read the secret
|
// read the secret
|
||||||
const ret = await $`bun sst secret list --stage ${stage}`.cwd(root).text()
|
const ret = await $`bun sst secret list --stage ${stage}`.cwd(root).text()
|
||||||
const lines = ret.split("\n")
|
const lines = ret.split("\n")
|
||||||
const value1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[1]
|
const values = Array.from({ length: PARTS }, (_, i) => {
|
||||||
const value2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1]
|
const value = lines
|
||||||
const value3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1]
|
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}`))
|
||||||
const value4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1]
|
?.split("=")
|
||||||
const value5 = lines.find((line) => line.startsWith("ZEN_MODELS5"))?.split("=")[1]
|
.slice(1)
|
||||||
const value6 = lines.find((line) => line.startsWith("ZEN_MODELS6"))?.split("=")[1]
|
.join("=")
|
||||||
const value7 = lines.find((line) => line.startsWith("ZEN_MODELS7"))?.split("=")[1]
|
if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
|
||||||
if (!value1) throw new Error("ZEN_MODELS1 not found")
|
return value
|
||||||
if (!value2) throw new Error("ZEN_MODELS2 not found")
|
})
|
||||||
if (!value3) throw new Error("ZEN_MODELS3 not found")
|
|
||||||
if (!value4) throw new Error("ZEN_MODELS4 not found")
|
|
||||||
if (!value5) throw new Error("ZEN_MODELS5 not found")
|
|
||||||
if (!value6) throw new Error("ZEN_MODELS6 not found")
|
|
||||||
if (!value7) throw new Error("ZEN_MODELS7 not found")
|
|
||||||
// validate value
|
// validate value
|
||||||
ZenData.validate(JSON.parse(value1 + value2 + value3 + value4 + value5 + value6 + value7))
|
ZenData.validate(JSON.parse(values.join("")))
|
||||||
|
|
||||||
// update the secret
|
// update the secret
|
||||||
await $`bun sst secret set ZEN_MODELS1 ${value1}`
|
for (let i = 0; i < PARTS; i++) {
|
||||||
await $`bun sst secret set ZEN_MODELS2 ${value2}`
|
await $`bun sst secret set ZEN_MODELS${i + 1} -- ${values[i]}`
|
||||||
await $`bun sst secret set ZEN_MODELS3 ${value3}`
|
}
|
||||||
await $`bun sst secret set ZEN_MODELS4 ${value4}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS5 ${value5}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS6 ${value6}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS7 ${value7}`
|
|
||||||
|
|||||||
@@ -7,34 +7,24 @@ import { ZenData } from "../src/model"
|
|||||||
|
|
||||||
const root = path.resolve(process.cwd(), "..", "..", "..")
|
const root = path.resolve(process.cwd(), "..", "..", "..")
|
||||||
const models = await $`bun sst secret list`.cwd(root).text()
|
const models = await $`bun sst secret list`.cwd(root).text()
|
||||||
|
const PARTS = 8
|
||||||
|
|
||||||
// read the line starting with "ZEN_MODELS"
|
// read the line starting with "ZEN_MODELS"
|
||||||
const lines = models.split("\n")
|
const lines = models.split("\n")
|
||||||
const oldValue1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[1]
|
const oldValues = Array.from({ length: PARTS }, (_, i) => {
|
||||||
const oldValue2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1]
|
const value = lines
|
||||||
const oldValue3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1]
|
.find((line) => line.startsWith(`ZEN_MODELS${i + 1}`))
|
||||||
const oldValue4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1]
|
?.split("=")
|
||||||
const oldValue5 = lines.find((line) => line.startsWith("ZEN_MODELS5"))?.split("=")[1]
|
.slice(1)
|
||||||
const oldValue6 = lines.find((line) => line.startsWith("ZEN_MODELS6"))?.split("=")[1]
|
.join("=")
|
||||||
const oldValue7 = lines.find((line) => line.startsWith("ZEN_MODELS7"))?.split("=")[1]
|
if (!value) throw new Error(`ZEN_MODELS${i + 1} not found`)
|
||||||
if (!oldValue1) throw new Error("ZEN_MODELS1 not found")
|
return value
|
||||||
if (!oldValue2) throw new Error("ZEN_MODELS2 not found")
|
})
|
||||||
if (!oldValue3) throw new Error("ZEN_MODELS3 not found")
|
|
||||||
if (!oldValue4) throw new Error("ZEN_MODELS4 not found")
|
|
||||||
if (!oldValue5) throw new Error("ZEN_MODELS5 not found")
|
|
||||||
if (!oldValue6) throw new Error("ZEN_MODELS6 not found")
|
|
||||||
if (!oldValue7) throw new Error("ZEN_MODELS7 not found")
|
|
||||||
|
|
||||||
// store the prettified json to a temp file
|
// store the prettified json to a temp file
|
||||||
const filename = `models-${Date.now()}.json`
|
const filename = `models-${Date.now()}.json`
|
||||||
const tempFile = Bun.file(path.join(os.tmpdir(), filename))
|
const tempFile = Bun.file(path.join(os.tmpdir(), filename))
|
||||||
await tempFile.write(
|
await tempFile.write(JSON.stringify(JSON.parse(oldValues.join("")), null, 2))
|
||||||
JSON.stringify(
|
|
||||||
JSON.parse(oldValue1 + oldValue2 + oldValue3 + oldValue4 + oldValue5 + oldValue6 + oldValue7),
|
|
||||||
null,
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
console.log("tempFile", tempFile.name)
|
console.log("tempFile", tempFile.name)
|
||||||
|
|
||||||
// open temp file in vim and read the file on close
|
// open temp file in vim and read the file on close
|
||||||
@@ -43,19 +33,11 @@ const newValue = JSON.stringify(JSON.parse(await tempFile.text()))
|
|||||||
ZenData.validate(JSON.parse(newValue))
|
ZenData.validate(JSON.parse(newValue))
|
||||||
|
|
||||||
// update the secret
|
// update the secret
|
||||||
const chunk = Math.ceil(newValue.length / 7)
|
const chunk = Math.ceil(newValue.length / PARTS)
|
||||||
const newValue1 = newValue.slice(0, chunk)
|
const newValues = Array.from({ length: PARTS }, (_, i) =>
|
||||||
const newValue2 = newValue.slice(chunk, chunk * 2)
|
newValue.slice(chunk * i, i === PARTS - 1 ? undefined : chunk * (i + 1)),
|
||||||
const newValue3 = newValue.slice(chunk * 2, chunk * 3)
|
)
|
||||||
const newValue4 = newValue.slice(chunk * 3, chunk * 4)
|
|
||||||
const newValue5 = newValue.slice(chunk * 4, chunk * 5)
|
|
||||||
const newValue6 = newValue.slice(chunk * 5, chunk * 6)
|
|
||||||
const newValue7 = newValue.slice(chunk * 6)
|
|
||||||
|
|
||||||
await $`bun sst secret set ZEN_MODELS1 ${newValue1}`
|
for (let i = 0; i < PARTS; i++) {
|
||||||
await $`bun sst secret set ZEN_MODELS2 ${newValue2}`
|
await $`bun sst secret set ZEN_MODELS${i + 1} -- ${newValues[i]}`
|
||||||
await $`bun sst secret set ZEN_MODELS3 ${newValue3}`
|
}
|
||||||
await $`bun sst secret set ZEN_MODELS4 ${newValue4}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS5 ${newValue5}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS6 ${newValue6}`
|
|
||||||
await $`bun sst secret set ZEN_MODELS7 ${newValue7}`
|
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ export namespace ZenData {
|
|||||||
Resource.ZEN_MODELS4.value +
|
Resource.ZEN_MODELS4.value +
|
||||||
Resource.ZEN_MODELS5.value +
|
Resource.ZEN_MODELS5.value +
|
||||||
Resource.ZEN_MODELS6.value +
|
Resource.ZEN_MODELS6.value +
|
||||||
Resource.ZEN_MODELS7.value,
|
Resource.ZEN_MODELS7.value +
|
||||||
|
Resource.ZEN_MODELS8.value,
|
||||||
)
|
)
|
||||||
return ModelsSchema.parse(json)
|
return ModelsSchema.parse(json)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user