diff --git a/package-lock.json b/package-lock.json index 30ad5e68..fdb8fdcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,14 +15,14 @@ "@dfinity/ic-management": "^6.1.1", "@dfinity/identity": "^2.3.0", "@dfinity/principal": "^2.3.0", - "@junobuild/admin": "^0.5.0-next-2025-06-01", - "@junobuild/cdn": "^0.1.0-next-2025-06-01", - "@junobuild/cli-tools": "^0.2.0-next-2025-06-01", + "@junobuild/admin": "^0.5.0-next-2025-06-02.1", + "@junobuild/cdn": "^0.1.0-next-2025-06-02.1", + "@junobuild/cli-tools": "^0.2.0-next-2025-06-02.1", "@junobuild/config": "^0.1.8", "@junobuild/config-loader": "^0.2.1", - "@junobuild/core": "^0.1.15-next-2025-06-01", + "@junobuild/core": "^0.1.15-next-2025-06-02.1", "@junobuild/did-tools": "^0.2.1", - "@junobuild/storage": "^0.2.0-next-2025-06-01", + "@junobuild/storage": "^0.2.0-next-2025-06-02.1", "@junobuild/utils": "^0.1.3", "chokidar": "^4.0.3", "conf": "^13.1.0", @@ -1464,9 +1464,9 @@ } }, "node_modules/@junobuild/admin": { - "version": "0.5.0-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/admin/-/admin-0.5.0-next-2025-06-01.tgz", - "integrity": "sha512-94Wu/9z6DB4E++oLClu8I6Je6hnszqwz3WNjqDpCBCrTXAd9K2o8LZ/DC5fruCbx24whE6Jisltwk2f/LtS82g==", + "version": "0.5.0-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/admin/-/admin-0.5.0-next-2025-06-02.1.tgz", + "integrity": "sha512-R0wqlMar44mDNwrIcpA1ODa2HHi9tDk9YnwQQIr6jO4adQUSKKubEmZS1HG2MYo9qoWptP6NvpibGrK+NkjzKw==", "license": "MIT", "peerDependencies": { "@dfinity/agent": "*", @@ -1481,9 +1481,9 @@ } }, "node_modules/@junobuild/cdn": { - "version": "0.1.0-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/cdn/-/cdn-0.1.0-next-2025-06-01.tgz", - "integrity": "sha512-QbXh9pR2RDmYB8D8z8tFcMulIax6w82k9Rf8eJ32QO9Rp1QL1+mqX7wrmSv+WftXXz0njgk9MrtRHeaJUHkV6A==", + "version": "0.1.0-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/cdn/-/cdn-0.1.0-next-2025-06-02.1.tgz", + "integrity": "sha512-oKOPJ8dAW0y0qCEMnLiAWQP5RVM34rJfCZrKM39o4oFlEiXc/k7oUT4pEO1DRCLjJNW46W+faU95OJwRbhL4lg==", "license": "MIT", "peerDependencies": { "@dfinity/agent": "*", @@ -1497,9 +1497,9 @@ } }, "node_modules/@junobuild/cli-tools": { - "version": "0.2.0-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/cli-tools/-/cli-tools-0.2.0-next-2025-06-01.tgz", - "integrity": "sha512-KUnrAr+6PKA5KxlcMebS8Pn8GcPl6QOR4mHgrPf5/ZRpB9N9K5yC/LetGu/Xgz30zJMPkVLreRH+1XSMc+zAbg==", + "version": "0.2.0-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/cli-tools/-/cli-tools-0.2.0-next-2025-06-02.1.tgz", + "integrity": "sha512-+T/qsdTtFOO+vd5CAguCgRSB+4biqZz54jUNYCPWKyZ7V9g2gjodrNPeb3zg5mouDOqhmjsA37VekPVfOIWIPw==", "license": "MIT", "dependencies": { "file-type": "^21.0.0", @@ -1536,9 +1536,9 @@ } }, "node_modules/@junobuild/core": { - "version": "0.1.15-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/core/-/core-0.1.15-next-2025-06-01.tgz", - "integrity": "sha512-4/UhZdrzNnCEDow0elZ5Tm0rpukaa7ACg2ZtwRgGiFB0mmgf/OyZIYwHLXF/w/r3BsEUv7MGoWy9CBo1dm1ckA==", + "version": "0.1.15-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/core/-/core-0.1.15-next-2025-06-02.1.tgz", + "integrity": "sha512-VZOf07PGOPlj/W1UXRj8wwUl1w5E/RMnAunwnpnAYbzjlNv3eih5rdP2JPqXO6SzDMUSVD46sp/y26sYGE7c5A==", "license": "MIT", "dependencies": { "@junobuild/errors": "*", @@ -1591,9 +1591,9 @@ } }, "node_modules/@junobuild/storage": { - "version": "0.2.0-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/storage/-/storage-0.2.0-next-2025-06-01.tgz", - "integrity": "sha512-wNuiAlk8xKJJMA/nw7JAk+Uc0ErK/Qdi2UP6LCLbrjyw1Umn7d/RCHAWekt9BA2H/G808Sp/rzdypLiDhHEnNg==", + "version": "0.2.0-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/storage/-/storage-0.2.0-next-2025-06-02.1.tgz", + "integrity": "sha512-de1BKkemggrlBa6y94h7zH63lmDYFG2xhJjBJA8imbl5yZD9oNXw9pc1CMVjm57PNzmd32CmudySJN9H732DZQ==", "license": "MIT", "peerDependencies": { "@dfinity/agent": "*", @@ -8011,21 +8011,21 @@ } }, "@junobuild/admin": { - "version": "0.5.0-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/admin/-/admin-0.5.0-next-2025-06-01.tgz", - "integrity": "sha512-94Wu/9z6DB4E++oLClu8I6Je6hnszqwz3WNjqDpCBCrTXAd9K2o8LZ/DC5fruCbx24whE6Jisltwk2f/LtS82g==", + "version": "0.5.0-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/admin/-/admin-0.5.0-next-2025-06-02.1.tgz", + "integrity": "sha512-R0wqlMar44mDNwrIcpA1ODa2HHi9tDk9YnwQQIr6jO4adQUSKKubEmZS1HG2MYo9qoWptP6NvpibGrK+NkjzKw==", "requires": {} }, "@junobuild/cdn": { - "version": "0.1.0-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/cdn/-/cdn-0.1.0-next-2025-06-01.tgz", - "integrity": "sha512-QbXh9pR2RDmYB8D8z8tFcMulIax6w82k9Rf8eJ32QO9Rp1QL1+mqX7wrmSv+WftXXz0njgk9MrtRHeaJUHkV6A==", + "version": "0.1.0-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/cdn/-/cdn-0.1.0-next-2025-06-02.1.tgz", + "integrity": "sha512-oKOPJ8dAW0y0qCEMnLiAWQP5RVM34rJfCZrKM39o4oFlEiXc/k7oUT4pEO1DRCLjJNW46W+faU95OJwRbhL4lg==", "requires": {} }, "@junobuild/cli-tools": { - "version": "0.2.0-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/cli-tools/-/cli-tools-0.2.0-next-2025-06-01.tgz", - "integrity": "sha512-KUnrAr+6PKA5KxlcMebS8Pn8GcPl6QOR4mHgrPf5/ZRpB9N9K5yC/LetGu/Xgz30zJMPkVLreRH+1XSMc+zAbg==", + "version": "0.2.0-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/cli-tools/-/cli-tools-0.2.0-next-2025-06-02.1.tgz", + "integrity": "sha512-+T/qsdTtFOO+vd5CAguCgRSB+4biqZz54jUNYCPWKyZ7V9g2gjodrNPeb3zg5mouDOqhmjsA37VekPVfOIWIPw==", "requires": { "file-type": "^21.0.0", "listr": "^0.14.3", @@ -8046,9 +8046,9 @@ "requires": {} }, "@junobuild/core": { - "version": "0.1.15-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/core/-/core-0.1.15-next-2025-06-01.tgz", - "integrity": "sha512-4/UhZdrzNnCEDow0elZ5Tm0rpukaa7ACg2ZtwRgGiFB0mmgf/OyZIYwHLXF/w/r3BsEUv7MGoWy9CBo1dm1ckA==", + "version": "0.1.15-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/core/-/core-0.1.15-next-2025-06-02.1.tgz", + "integrity": "sha512-VZOf07PGOPlj/W1UXRj8wwUl1w5E/RMnAunwnpnAYbzjlNv3eih5rdP2JPqXO6SzDMUSVD46sp/y26sYGE7c5A==", "requires": { "@junobuild/errors": "*", "@junobuild/storage": "*", @@ -8074,9 +8074,9 @@ "requires": {} }, "@junobuild/storage": { - "version": "0.2.0-next-2025-06-01", - "resolved": "https://registry.npmjs.org/@junobuild/storage/-/storage-0.2.0-next-2025-06-01.tgz", - "integrity": "sha512-wNuiAlk8xKJJMA/nw7JAk+Uc0ErK/Qdi2UP6LCLbrjyw1Umn7d/RCHAWekt9BA2H/G808Sp/rzdypLiDhHEnNg==", + "version": "0.2.0-next-2025-06-02.1", + "resolved": "https://registry.npmjs.org/@junobuild/storage/-/storage-0.2.0-next-2025-06-02.1.tgz", + "integrity": "sha512-de1BKkemggrlBa6y94h7zH63lmDYFG2xhJjBJA8imbl5yZD9oNXw9pc1CMVjm57PNzmd32CmudySJN9H732DZQ==", "requires": {} }, "@junobuild/utils": { diff --git a/package.json b/package.json index 2c32a0a3..acf7dd19 100644 --- a/package.json +++ b/package.json @@ -30,14 +30,14 @@ "@dfinity/ic-management": "^6.1.1", "@dfinity/identity": "^2.3.0", "@dfinity/principal": "^2.3.0", - "@junobuild/admin": "^0.5.0-next-2025-06-01", - "@junobuild/cdn": "^0.1.0-next-2025-06-01", - "@junobuild/cli-tools": "^0.2.0-next-2025-06-01", + "@junobuild/admin": "^0.5.0-next-2025-06-02.1", + "@junobuild/cdn": "^0.1.0-next-2025-06-02.1", + "@junobuild/cli-tools": "^0.2.0-next-2025-06-02.1", "@junobuild/config": "^0.1.8", "@junobuild/config-loader": "^0.2.1", - "@junobuild/core": "^0.1.15-next-2025-06-01", + "@junobuild/core": "^0.1.15-next-2025-06-02.1", "@junobuild/did-tools": "^0.2.1", - "@junobuild/storage": "^0.2.0-next-2025-06-01", + "@junobuild/storage": "^0.2.0-next-2025-06-02.1", "@junobuild/utils": "^0.1.3", "chokidar": "^4.0.3", "conf": "^13.1.0", diff --git a/src/commands/functions.ts b/src/commands/functions.ts index 7c0c67ed..ab9d2adc 100644 --- a/src/commands/functions.ts +++ b/src/commands/functions.ts @@ -2,8 +2,10 @@ import {red} from 'kleur'; import {logHelpFunctionsBuild} from '../help/functions.build.help'; import {logHelpFunctionsEject} from '../help/functions.eject.help'; import {logHelpFunctions} from '../help/functions.help'; +import {logHelpFunctionsUpgrade} from '../help/functions.upgrade.help'; import {build} from '../services/functions/build/build.services'; import {eject} from '../services/functions/eject/eject.services'; +import {upgradeFunctions} from '../services/functions/upgrade/upgrade.services'; export const functions = async (args?: string[]) => { const [subCommand] = args ?? []; @@ -15,6 +17,9 @@ export const functions = async (args?: string[]) => { case 'build': await build(args); break; + case 'upgrade': + await upgradeFunctions(args); + break; default: console.log(red('Unknown subcommand.')); logHelpFunctions(args); @@ -31,6 +36,9 @@ export const helpFunctions = (args?: string[]) => { case 'eject': logHelpFunctionsEject(args); break; + case 'upgrade': + logHelpFunctionsUpgrade(args); + break; default: logHelpFunctions(args); } diff --git a/src/constants/dev.constants.ts b/src/constants/dev.constants.ts index 7c0247b2..1211d338 100644 --- a/src/constants/dev.constants.ts +++ b/src/constants/dev.constants.ts @@ -45,3 +45,5 @@ export const PACKAGE_JSON_PATH = join(process.cwd(), 'package.json'); export const SPUTNIK_INDEX_MJS = 'sputnik.index.mjs'; export const DEPLOY_SPUTNIK_PATH = join(DEPLOY_LOCAL_REPLICA_PATH, SPUTNIK_INDEX_MJS); + +export const SATELLITE_OUTPUT = join(DEPLOY_LOCAL_REPLICA_PATH, 'satellite.wasm'); diff --git a/src/constants/functions.constants.ts b/src/constants/functions.constants.ts new file mode 100644 index 00000000..64ad0ec6 --- /dev/null +++ b/src/constants/functions.constants.ts @@ -0,0 +1 @@ +export const CDN_RELEASES_FULL_PATH = '/_juno/releases'; diff --git a/src/constants/help.constants.ts b/src/constants/help.constants.ts index b0a08d61..1215b5fb 100644 --- a/src/constants/help.constants.ts +++ b/src/constants/help.constants.ts @@ -25,6 +25,7 @@ export const WHOAMI_DESCRIPTION = export const DEV_START_DESCRIPTION = 'Start a local Internet Computer network in a container.'; +export const FUNCTIONS_UPGRADE_DESCRIPTION = 'Upgrade your serverless functions.'; export const FUNCTIONS_BUILD_DESCRIPTION = 'Build your serverless functions.'; export const FUNCTIONS_EJECT_DESCRIPTION = 'Generate the required files to begin developing serverless functions in your project.'; @@ -41,3 +42,9 @@ export const CHANGES_REJECT_DESCRIPTION = 'Reject a change.'; export const OPTION_KEEP_STAGED = `${yellow('-k, --keep-staged')} Keep staged assets in memory after applying the change.`; export const OPTION_HASH = `${yellow('-s, --hash')} The expected hash of all included changes (for verification).`; export const OPTION_HELP = `${yellow('-h, --help')} Output usage information.`; + +export const OPTIONS_UPGRADE = `${yellow('-r, --reset')} Reset to the initial state. + ${yellow('-cc, --clear-chunks')} Clear any previously uploaded WASM chunks (applies if the WASM size is greater than 2MB). + ${yellow('-ns, --no-snapshot')} Skip creating a snapshot before upgrading.`; + +export const NOTE_KEEP_STAGED = `The option ${yellow('--keep-staged')} only applies when ${yellow('--no-apply')} is NOT used (i.e. the change is applied immediately).`; diff --git a/src/help/deploy.help.ts b/src/help/deploy.help.ts index 2ef4d5b5..3245548b 100644 --- a/src/help/deploy.help.ts +++ b/src/help/deploy.help.ts @@ -1,5 +1,10 @@ import {cyan, green, yellow} from 'kleur'; -import {DEPLOY_DESCRIPTION, OPTION_HELP, OPTION_KEEP_STAGED} from '../constants/help.constants'; +import { + DEPLOY_DESCRIPTION, + NOTE_KEEP_STAGED, + OPTION_HELP, + OPTION_KEEP_STAGED +} from '../constants/help.constants'; import {helpMode, helpOutput} from './common.help'; import {TITLE} from './help'; @@ -15,7 +20,7 @@ Options: Notes: -- The option ${yellow('--keep-staged')} only applies when ${yellow('--no-apply')} is NOT used (i.e. the change is applied immediately).`; +- ${NOTE_KEEP_STAGED}`; const doc = `${DEPLOY_DESCRIPTION} diff --git a/src/help/functions.help.ts b/src/help/functions.help.ts index 0aac1f17..98870db1 100644 --- a/src/help/functions.help.ts +++ b/src/help/functions.help.ts @@ -8,6 +8,7 @@ const usage = `Usage: ${green('juno')} ${cyan('functions')} ${magenta(' { + console.log(helpOutput(args) === 'doc' ? doc : help); +}; diff --git a/src/help/upgrade.help.ts b/src/help/upgrade.help.ts index 7dd49856..7754f8b1 100644 --- a/src/help/upgrade.help.ts +++ b/src/help/upgrade.help.ts @@ -1,5 +1,5 @@ import {cyan, green, yellow} from 'kleur'; -import {OPTION_HELP, UPGRADE_DESCRIPTION} from '../constants/help.constants'; +import {OPTION_HELP, OPTIONS_UPGRADE, UPGRADE_DESCRIPTION} from '../constants/help.constants'; import {helpMode, helpOutput} from './common.help'; import {TITLE} from './help'; import {TARGET_OPTION_NOTE, targetOption} from './target.help'; @@ -9,9 +9,7 @@ const usage = `Usage: ${green('juno')} ${cyan('upgrade')} ${yellow('[options]')} Options: ${targetOption('upgrade')} ${yellow('-s, --src')} An optional local gzipped WASM file for the upgrade. By default, the CDN will be used. - ${yellow('-r, --reset')} Reset to the initial state. - ${yellow('-cc, --clear-chunks')} Clear any previously uploaded WASM chunks (applies if the WASM size is greater than 2MB). - ${yellow('-ns, --no-snapshot')} Skip creating a snapshot before upgrading. + ${OPTIONS_UPGRADE} ${helpMode} ${OPTION_HELP} diff --git a/src/services/functions/build/build.rust.services.ts b/src/services/functions/build/build.rust.services.ts index 88037e59..d78c0fd0 100644 --- a/src/services/functions/build/build.rust.services.ts +++ b/src/services/functions/build/build.rust.services.ts @@ -15,6 +15,7 @@ import { DEVELOPER_PROJECT_SATELLITE_PATH, IC_WASM_MIN_VERSION, JUNO_PACKAGE_JSON_PATH, + SATELLITE_OUTPUT, TARGET_PATH } from '../../../constants/dev.constants'; import type {BuildArgs} from '../../../types/build'; @@ -29,7 +30,6 @@ import {readPackageJson} from '../../../utils/pkg.utils'; import {confirmAndExit} from '../../../utils/prompt.utils'; const CARGO_RELEASE_DIR = join(process.cwd(), 'target', 'wasm32-unknown-unknown', 'release'); -const SATELLITE_OUTPUT = join(DEPLOY_LOCAL_REPLICA_PATH, 'satellite.wasm'); const SATELLITE_PROJECT_NAME = 'satellite'; export const buildRust = async ({path}: Pick = {}) => { diff --git a/src/services/functions/upgrade/upgrade.services.ts b/src/services/functions/upgrade/upgrade.services.ts new file mode 100644 index 00000000..d9630a73 --- /dev/null +++ b/src/services/functions/upgrade/upgrade.services.ts @@ -0,0 +1,34 @@ +import {hasArgs, nextArg} from '@junobuild/cli-tools'; +import {SATELLITE_OUTPUT} from '../../../constants/dev.constants'; +import {type UpgradeFunctionsParams} from '../../../types/functions'; +import {assertConfigAndLoadSatelliteContext} from '../../../utils/satellite.utils'; +import {upgradeSatelliteWithSrc} from '../../modules/upgrade/upgrade.satellite.services'; +import {upgradeFunctionsWithProposal} from './upgrade.with-proposal.services'; + +export const upgradeFunctions = async (args?: string[]) => { + const {satellite} = await assertConfigAndLoadSatelliteContext(args); + + const srcArgs = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); + const src = srcArgs ?? `${SATELLITE_OUTPUT}.gz`; + + const immediate = hasArgs({args, options: ['-i', '--immediate']}); + + if (immediate) { + await upgradeImmediate({ + args, + src, + satellite + }); + return; + } + + await upgradeFunctionsWithProposal({ + args, + src, + satellite + }); +}; + +const upgradeImmediate = async (params: UpgradeFunctionsParams) => { + await upgradeSatelliteWithSrc(params); +}; diff --git a/src/services/functions/upgrade/upgrade.with-proposal.services.ts b/src/services/functions/upgrade/upgrade.with-proposal.services.ts new file mode 100644 index 00000000..e7eccbfd --- /dev/null +++ b/src/services/functions/upgrade/upgrade.with-proposal.services.ts @@ -0,0 +1,142 @@ +import {isNullish} from '@dfinity/utils'; +import {uploadAssetWithProposal} from '@junobuild/cdn'; +import { + type DeployResultWithProposal, + deploySatelliteWasmWithProposal, + type FilePaths, + hasArgs, + type UploadFileStorageWithProposal +} from '@junobuild/cli-tools'; +import {red} from 'kleur'; +import {CDN_RELEASES_FULL_PATH} from '../../../constants/functions.constants'; +import {type UpgradeFunctionsParams} from '../../../types/functions'; +import type {SatelliteParametersWithId} from '../../../types/satellite'; +import {readWasmFileMetadata} from '../../../utils/wasm.utils'; +import {assertSatelliteMemorySize} from '../../assets/deploy/deploy.assert.services'; +import {type UploadFileFnParamsWithProposal} from '../../assets/deploy/deploy.execute.services'; +import {clearProposalStagedAssets} from '../../changes/changes.clear.services'; +import {upgradeSatelliteWithSrc} from '../../modules/upgrade/upgrade.satellite.services'; + +export const upgradeFunctionsWithProposal = async (params: UpgradeFunctionsParams) => { + const result = await deployWasmWithProposal(params); + + if (result.result !== 'deployed') { + return; + } + + console.log(''); + + await upgradeSatelliteWithSrc(params); +}; + +const deployWasmWithProposal = async ({ + args, + src, + satellite +}: UpgradeFunctionsParams): Promise => { + const {junoPackage, gzipped} = await readWasmFileMetadata({path: src}); + + if (isNullish(junoPackage)) { + console.log(red('No Juno Package metadata detected.')); + console.log('Are you using the latest libraries and tooling?'); + return {result: 'error'}; + } + + const {version} = junoPackage; + + if (!gzipped) { + console.log(red('The submitted WASM file must be gzipped.')); + return {result: 'error'}; + } + + const fullPath = `${CDN_RELEASES_FULL_PATH}/satellite-v${version}-${crypto.randomUUID()}.wasm.gz`; + + const result = await uploadWasmWithProposal({ + satellite, + version, + args, + filePath: src, + fullPath + }); + + if (result.result !== 'deployed') { + return result; + } + + const {proposalId} = result; + + await clearProposalStagedAssets({ + args, + proposalId + }); + + return result; +}; + +const uploadWasmWithProposal = async ({ + args, + satellite, + fullPath, + filePath, + version +}: Omit & + FilePaths & {version: string}): Promise => { + const noCommit = hasArgs({args, options: ['-na', '--no-apply']}); + + const uploadFileFn = async ({ + filename, + fullPath: storagePath, + data, + collection, + headers = [], + encoding, + satellite, + proposalId + }: UploadFileFnParamsWithProposal) => { + await uploadAssetWithProposal({ + cdn: {satellite}, + proposalId, + asset: { + filename, + fullPath: storagePath ?? fullPath, + // @ts-expect-error type incompatibility NodeJS vs bundle + data, + collection, + headers, + encoding + } + }); + }; + + const uploadFile = async (params: UploadFileStorageWithProposal) => { + const paramsWithSatellite: UploadFileStorageWithProposal & { + satellite: SatelliteParametersWithId; + } = { + ...params, + satellite + }; + + await uploadFileFn(paramsWithSatellite); + }; + + const assertMemory = async () => { + await assertSatelliteMemorySize(args); + }; + + return await deploySatelliteWasmWithProposal({ + deploy: { + uploadFile, + fullPath, + filePath, + token: crypto.randomUUID(), + assertMemory + }, + proposal: { + autoCommit: !noCommit, + cdn: { + satellite + }, + version + } + }); +}; diff --git a/src/services/modules/upgrade/upgrade-assert.services.ts b/src/services/modules/upgrade/upgrade-assert.services.ts index e03c966c..10b56a6d 100644 --- a/src/services/modules/upgrade/upgrade-assert.services.ts +++ b/src/services/modules/upgrade/upgrade-assert.services.ts @@ -54,6 +54,6 @@ export const assertUpgradeHash = async ({ reset }: Required>) => { await confirmAndExit( - `The Wasm hash to be applied for the upgrade is ${cyan(hash)}.${NEW_CMD_LINE}Start upgrade${reset ? ' and reset' : ''} now?` + `The Wasm hash for the upgrade is ${cyan(hash)}.${NEW_CMD_LINE}Start upgrade${reset ? ' and reset' : ''} now?` ); }; diff --git a/src/services/modules/upgrade/upgrade.satellite.services.ts b/src/services/modules/upgrade/upgrade.satellite.services.ts index 738f606a..98251e45 100644 --- a/src/services/modules/upgrade/upgrade.satellite.services.ts +++ b/src/services/modules/upgrade/upgrade.satellite.services.ts @@ -56,11 +56,26 @@ const upgradeSatelliteCustom = async ({ }): Promise<{success: boolean; err?: unknown}> => { const src = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); - if (src === undefined) { + if (isNullish(src)) { console.log(red('No source file provided.')); return {success: false}; } + return await upgradeSatelliteWithSrc({ + satellite, + src + }); +}; + +export const upgradeSatelliteWithSrc = async ({ + satellite, + src, + args +}: { + satellite: SatelliteParameters; + src: string; + args?: string[]; +}): Promise<{success: boolean; err?: unknown}> => { // TODO: option to be removed const currentVersion = await satelliteVersion({ satellite diff --git a/src/services/modules/upgrade/upgrade.services.ts b/src/services/modules/upgrade/upgrade.services.ts index cf13be30..3bad0602 100644 --- a/src/services/modules/upgrade/upgrade.services.ts +++ b/src/services/modules/upgrade/upgrade.services.ts @@ -73,7 +73,7 @@ const executeUpgradeWasm = async ({ spinner.stop(); if (err instanceof UpgradeCodeUnchangedError) { - console.log(`${yellow(err.message)}`); + console.log(yellow(err.message)); return; } diff --git a/src/types/functions.ts b/src/types/functions.ts new file mode 100644 index 00000000..5b82e081 --- /dev/null +++ b/src/types/functions.ts @@ -0,0 +1,7 @@ +import {type SatelliteParametersWithId} from './satellite'; + +export interface UpgradeFunctionsParams { + src: string; + satellite: SatelliteParametersWithId; + args?: string[]; +}