Handle SpacetimeDB migration imports with chunked uploads
Some checks failed
CI / verify (push) Has been cancelled
Some checks failed
CI / verify (push) Has been cancelled
This commit is contained in:
@@ -4,6 +4,10 @@ import path from 'node:path';
|
||||
|
||||
export function parseArgs(argv) {
|
||||
const options = {
|
||||
chunkSize: parseOptionalPositiveInteger(
|
||||
process.env.GENARRATIVE_SPACETIME_MIGRATION_CHUNK_SIZE,
|
||||
'GENARRATIVE_SPACETIME_MIGRATION_CHUNK_SIZE',
|
||||
),
|
||||
database:
|
||||
process.env.GENARRATIVE_SPACETIME_MAINCLOUD_DATABASE ||
|
||||
process.env.GENARRATIVE_SPACETIME_DATABASE ||
|
||||
@@ -48,6 +52,8 @@ export function parseArgs(argv) {
|
||||
options.token = readValue(arg);
|
||||
} else if (arg === '--bootstrap-secret') {
|
||||
options.bootstrapSecret = readValue(arg);
|
||||
} else if (arg === '--chunk-size') {
|
||||
options.chunkSize = parsePositiveInteger(readValue(arg), arg);
|
||||
} else if (arg === '--operator-identity') {
|
||||
options.operatorIdentity = readValue(arg);
|
||||
} else if (arg === '--note') {
|
||||
@@ -81,6 +87,25 @@ export function parseArgs(argv) {
|
||||
return options;
|
||||
}
|
||||
|
||||
export function parsePositiveInteger(value, name) {
|
||||
if (!/^[1-9][0-9]*$/u.test(String(value).trim())) {
|
||||
throw new Error(`${name} 必须是正整数。`);
|
||||
}
|
||||
|
||||
const parsed = Number.parseInt(String(value).trim(), 10);
|
||||
if (!Number.isSafeInteger(parsed)) {
|
||||
throw new Error(`${name} 超出安全整数范围。`);
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function parseOptionalPositiveInteger(value, name) {
|
||||
if (!value) {
|
||||
return 0;
|
||||
}
|
||||
return parsePositiveInteger(value, name);
|
||||
}
|
||||
|
||||
export function buildSpacetimeCallArgs(options, procedureName, input) {
|
||||
if (!options.database) {
|
||||
throw new Error('必须传入 --database。');
|
||||
|
||||
Reference in New Issue
Block a user