ic-mops 0.33.0 → 0.34.0

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.
Files changed (50) hide show
  1. package/api/actors.ts +45 -0
  2. package/api/downloadPackageFiles.ts +78 -0
  3. package/api/getHighestVersion.ts +6 -0
  4. package/api/index.ts +4 -0
  5. package/api/network.ts +24 -0
  6. package/api/resolveVersion.ts +12 -0
  7. package/cli.ts +18 -4
  8. package/commands/add.ts +2 -1
  9. package/commands/available-updates.ts +1 -1
  10. package/commands/init.ts +2 -1
  11. package/commands/install.ts +26 -49
  12. package/commands/publish.ts +4 -2
  13. package/commands/search.ts +2 -3
  14. package/commands/transfer-ownership.ts +4 -2
  15. package/commands/user.ts +5 -2
  16. package/dist/api/actors.d.ts +6 -0
  17. package/dist/api/actors.js +32 -0
  18. package/dist/api/downloadPackageFiles.d.ts +12 -0
  19. package/dist/api/downloadPackageFiles.js +62 -0
  20. package/dist/api/getHighestVersion.d.ts +1 -0
  21. package/dist/api/getHighestVersion.js +5 -0
  22. package/dist/api/index.d.ts +4 -0
  23. package/dist/api/index.js +4 -0
  24. package/dist/api/network.d.ts +5 -0
  25. package/dist/api/network.js +23 -0
  26. package/dist/api/resolveVersion.d.ts +1 -0
  27. package/dist/api/resolveVersion.js +11 -0
  28. package/dist/cli.d.ts +3 -0
  29. package/dist/cli.js +11 -5
  30. package/dist/commands/add.js +2 -1
  31. package/dist/commands/available-updates.js +1 -1
  32. package/dist/commands/init.js +2 -1
  33. package/dist/commands/install.js +22 -43
  34. package/dist/commands/publish.js +4 -2
  35. package/dist/commands/search.js +2 -3
  36. package/dist/commands/transfer-ownership.js +4 -2
  37. package/dist/commands/user.js +4 -2
  38. package/dist/helpers/download-package-files.d.ts +12 -0
  39. package/dist/helpers/download-package-files.js +62 -0
  40. package/dist/helpers/resolve-version.d.ts +1 -0
  41. package/dist/helpers/resolve-version.js +11 -0
  42. package/dist/integrity.js +2 -1
  43. package/dist/mops.d.ts +6 -12
  44. package/dist/mops.js +15 -70
  45. package/dist/notify-installs.js +2 -1
  46. package/dist/package.json +1 -1
  47. package/integrity.ts +2 -1
  48. package/mops.ts +24 -85
  49. package/notify-installs.ts +2 -1
  50. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -7,7 +7,9 @@ import { init } from './commands/init.js';
7
7
  import { publish } from './commands/publish.js';
8
8
  import { importPem } from './commands/import-identity.js';
9
9
  import { sources } from './commands/sources.js';
10
- import { checkApiCompatibility, getNetwork, setNetwork, apiVersion, checkConfigFile, mainActor } from './mops.js';
10
+ import { checkApiCompatibility, setNetwork, apiVersion, checkConfigFile, getNetworkFile, getIdentity } from './mops.js';
11
+ import { getNetwork } from './api/network.js';
12
+ import { mainActor } from './api/actors.js';
11
13
  import { whoami } from './commands/whoami.js';
12
14
  import { installAll } from './commands/install-all.js';
13
15
  import { search } from './commands/search.js';
@@ -24,7 +26,10 @@ import { outdated } from './commands/outdated.js';
24
26
  import { update } from './commands/update.js';
25
27
  import { bench } from './commands/bench.js';
26
28
  import { transferOwnership } from './commands/transfer-ownership.js';
27
- // import {docs} from './commands/docs.js';
29
+ let networkFile = getNetworkFile();
30
+ if (fs.existsSync(networkFile)) {
31
+ globalThis.MOPS_NETWORK = fs.readFileSync(networkFile).toString() || 'ic';
32
+ }
28
33
  program.name('mops');
29
34
  // --version
30
35
  let packageJson = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)).toString());
@@ -119,7 +124,7 @@ program
119
124
  .alias('gn')
120
125
  .description('Get network')
121
126
  .action(async () => {
122
- console.log(getNetwork().network);
127
+ console.log(getNetwork());
123
128
  });
124
129
  // import-identity
125
130
  program
@@ -247,11 +252,12 @@ program
247
252
  await setUserProp(prop, value);
248
253
  }
249
254
  });
250
- // airdrop
255
+ // temp: airdrop
251
256
  program
252
257
  .command('airdrop <check|claim> [canister]')
253
258
  .action(async (sub, canister) => {
254
- let main = await mainActor(true);
259
+ let identity = await getIdentity();
260
+ let main = await mainActor(identity);
255
261
  if (sub === 'check') {
256
262
  let amount = await main.getAirdropAmount();
257
263
  if (amount === 0n) {
@@ -1,7 +1,8 @@
1
1
  import path from 'node:path';
2
2
  import chalk from 'chalk';
3
3
  import logUpdate from 'log-update';
4
- import { checkConfigFile, getGithubCommit, getHighestVersion, parseGithubURL, readConfig, writeConfig } from '../mops.js';
4
+ import { checkConfigFile, getGithubCommit, parseGithubURL, readConfig, writeConfig } from '../mops.js';
5
+ import { getHighestVersion } from '../api/getHighestVersion.js';
5
6
  import { installFromGithub } from '../vessel.js';
6
7
  import { install } from './install.js';
7
8
  import { notifyInstalls } from '../notify-installs.js';
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import { mainActor } from '../mops.js';
2
+ import { mainActor } from '../api/actors.js';
3
3
  // [pkg, oldVersion, newVersion]
4
4
  export async function getAvailableUpdates(config, pkg) {
5
5
  let deps = Object.values(config.dependencies || {});
@@ -3,7 +3,8 @@ import path from 'node:path';
3
3
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
4
4
  import chalk from 'chalk';
5
5
  import prompts from 'prompts';
6
- import { checkApiCompatibility, mainActor, writeConfig } from '../mops.js';
6
+ import { checkApiCompatibility, writeConfig } from '../mops.js';
7
+ import { mainActor } from '../api/actors.js';
7
8
  import { installAll } from './install-all.js';
8
9
  import { readVesselConfig } from '../vessel.js';
9
10
  import { template } from './template.js';
@@ -2,10 +2,13 @@ import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import logUpdate from 'log-update';
4
4
  import chalk from 'chalk';
5
- import { checkConfigFile, formatDir, getHighestVersion, mainActor, progressBar, readConfig, storageActor } from '../mops.js';
5
+ import { checkConfigFile, formatDir, progressBar, readConfig } from '../mops.js';
6
+ import { getHighestVersion } from '../api/getHighestVersion.js';
7
+ import { storageActor } from '../api/actors.js';
6
8
  import { parallel } from '../parallel.js';
7
9
  import { installFromGithub } from '../vessel.js';
8
10
  import { addCache, copyCache, isCached } from '../cache.js';
11
+ import { downloadFile, getPackageFilesInfo } from '../api/downloadPackageFiles.js';
9
12
  export async function install(pkg, version = '', { verbose = false, silent = false, dep = false } = {}) {
10
13
  if (!checkConfigFile()) {
11
14
  return false;
@@ -27,7 +30,6 @@ export async function install(pkg, version = '', { verbose = false, silent = fal
27
30
  version = versionRes.ok;
28
31
  }
29
32
  let dir = formatDir(pkg, version);
30
- let actor = await mainActor();
31
33
  let alreadyInstalled = false;
32
34
  // already installed
33
35
  if (fs.existsSync(dir)) {
@@ -41,53 +43,30 @@ export async function install(pkg, version = '', { verbose = false, silent = fal
41
43
  }
42
44
  // download
43
45
  else {
44
- let [packageDetailsRes, filesIdsRes] = await Promise.all([
45
- actor.getPackageDetails(pkg, version),
46
- actor.getFileIds(pkg, version),
47
- ]);
48
- if ('err' in packageDetailsRes) {
49
- console.log(chalk.red('Error: ') + packageDetailsRes.err);
50
- return false;
51
- }
52
- let packageDetails = packageDetailsRes.ok;
53
- if ('err' in filesIdsRes) {
54
- console.log(chalk.red('Error: ') + filesIdsRes.err);
55
- return false;
56
- }
57
- let filesIds = filesIdsRes.ok;
58
- total = filesIds.length + 2;
59
- let storage = await storageActor(packageDetails.publication.storage);
60
- // download files
61
- let filesData = new Map;
62
46
  let threads = 16;
63
47
  // GitHub Actions fails with "fetch failed" if there are multiple concurrent actions
64
48
  if (process.env.GITHUB_ENV) {
65
49
  threads = 4;
66
50
  }
67
- await parallel(threads, filesIds, async (fileId) => {
68
- let fileMetaRes = await storage.getFileMeta(fileId);
69
- if ('err' in fileMetaRes) {
70
- console.log(chalk.red('ERR: ') + fileMetaRes.err);
71
- return;
51
+ try {
52
+ let { storageId, fileIds } = await getPackageFilesInfo(pkg, version);
53
+ total = fileIds.length + 2;
54
+ let filesData = new Map;
55
+ let storage = await storageActor(storageId);
56
+ await parallel(threads, fileIds, async (fileId) => {
57
+ let { path, data } = await downloadFile(storage, fileId);
58
+ filesData.set(path, data);
59
+ progress();
60
+ });
61
+ // write files to disk
62
+ for (let [filePath, data] of filesData.entries()) {
63
+ fs.mkdirSync(path.join(dir, path.dirname(filePath)), { recursive: true });
64
+ fs.writeFileSync(path.join(dir, filePath), Buffer.from(data));
72
65
  }
73
- let fileMeta = fileMetaRes.ok;
74
- let buffer = Buffer.from([]);
75
- for (let i = 0n; i < fileMeta.chunkCount; i++) {
76
- let chunkRes = await storage.downloadChunk(fileId, i);
77
- if ('err' in chunkRes) {
78
- console.log(chalk.red('ERR: ') + chunkRes.err);
79
- return;
80
- }
81
- let chunk = chunkRes.ok;
82
- buffer = Buffer.concat([buffer, Buffer.from(chunk)]);
83
- }
84
- filesData.set(fileMeta.path, buffer);
85
- progress();
86
- });
87
- // write files to disk
88
- for (let [filePath, buffer] of filesData.entries()) {
89
- fs.mkdirSync(path.join(dir, path.dirname(filePath)), { recursive: true });
90
- fs.writeFileSync(path.join(dir, filePath), buffer);
66
+ }
67
+ catch (err) {
68
+ console.error(chalk.red('Error: ') + err);
69
+ return false;
91
70
  }
92
71
  // add to cache
93
72
  await addCache(`${pkg}@${version}`, dir);
@@ -7,7 +7,8 @@ import { minimatch } from 'minimatch';
7
7
  import prompts from 'prompts';
8
8
  import { fromMarkdown } from 'mdast-util-from-markdown';
9
9
  import { toMarkdown } from 'mdast-util-to-markdown';
10
- import { checkConfigFile, getRootDir, mainActor, progressBar, readConfig } from '../mops.js';
10
+ import { checkConfigFile, getIdentity, getRootDir, progressBar, readConfig } from '../mops.js';
11
+ import { mainActor } from '../api/actors.js';
11
12
  import { parallel } from '../parallel.js';
12
13
  import { docs } from './docs.js';
13
14
  import { testWithReporter } from './test/test.js';
@@ -238,7 +239,8 @@ export async function publish(options = {}) {
238
239
  logUpdate(`Uploading files ${progressBar(step, total)}`);
239
240
  }
240
241
  // upload config
241
- let actor = await mainActor(true);
242
+ let identity = await getIdentity();
243
+ let actor = await mainActor(identity);
242
244
  progress();
243
245
  let publishing = await actor.startPublish(backendPkgConfig);
244
246
  if ('err' in publishing) {
@@ -1,10 +1,9 @@
1
1
  import asTable from 'as-table';
2
2
  import chalk from 'chalk';
3
- import { mainActor } from '../mops.js';
3
+ import { mainActor } from '../api/actors.js';
4
4
  export async function search(text) {
5
5
  let actor = await mainActor();
6
- let res = await actor.search(text, [], []);
7
- let packages = res[0];
6
+ let [packages, _pageCount] = await actor.search(text, [], []);
8
7
  if (!packages.length) {
9
8
  console.log('Packages not found');
10
9
  return;
@@ -1,5 +1,6 @@
1
1
  import chalk from 'chalk';
2
- import { checkConfigFile, mainActor, readConfig } from '../mops.js';
2
+ import { checkConfigFile, getIdentity, readConfig } from '../mops.js';
3
+ import { mainActor } from '../api/actors.js';
3
4
  import { Principal } from '@dfinity/principal';
4
5
  import prompts from 'prompts';
5
6
  export async function transferOwnership(toPrincipal) {
@@ -24,7 +25,8 @@ export async function transferOwnership(toPrincipal) {
24
25
  if (!confirm) {
25
26
  return;
26
27
  }
27
- let actor = await mainActor(true);
28
+ let identity = await getIdentity();
29
+ let actor = await mainActor(identity);
28
30
  let res = await actor.transferOwnership(config.package?.name || '', principal);
29
31
  if ('ok' in res) {
30
32
  console.log(chalk.green('Success!'));
@@ -1,5 +1,6 @@
1
1
  import chalk from 'chalk';
2
- import { getIdentity, mainActor } from '../mops.js';
2
+ import { getIdentity } from '../mops.js';
3
+ import { mainActor } from '../api/actors.js';
3
4
  export async function getUserProp(prop) {
4
5
  let actor = await mainActor();
5
6
  let identity = await getIdentity();
@@ -12,7 +13,8 @@ export async function getUserProp(prop) {
12
13
  console.log(res[0]?.[prop] || '');
13
14
  }
14
15
  export async function setUserProp(prop, value) {
15
- let actor = await mainActor(true);
16
+ let identity = await getIdentity();
17
+ let actor = await mainActor(identity);
16
18
  let res = await actor.setUserProp(prop, value);
17
19
  if ('ok' in res) {
18
20
  console.log(chalk.green('Success!'));
@@ -0,0 +1,12 @@
1
+ import { Principal } from '@dfinity/principal';
2
+ import { Storage } from '../declarations/storage/storage.did.js';
3
+ export declare function downloadPackageFiles(pkg: string, version?: string, threads?: number, onLoad?: (_fileIds: string[], _fileId: string) => void): Promise<Map<string, string>>;
4
+ export declare function getPackageFilesInfo(pkg: string, version: string): Promise<{
5
+ storageId: Principal;
6
+ fileIds: string[];
7
+ }>;
8
+ export declare function getFileIds(pkg: string, version: string): Promise<string[]>;
9
+ export declare function downloadFile(storage: Storage, fileId: string): Promise<{
10
+ path: string;
11
+ data: Array<number>;
12
+ }>;
@@ -0,0 +1,62 @@
1
+ import { mainActor, storageActor } from '../mops.js';
2
+ import { parallel } from '../parallel.js';
3
+ import { resolveVersion } from './resolve-version.js';
4
+ export async function downloadPackageFiles(pkg, version = '', threads = 8, onLoad = (_fileIds, _fileId) => { }) {
5
+ version = await resolveVersion(pkg, version);
6
+ let { storageId, fileIds } = await getPackageFilesInfo(pkg, version);
7
+ let storage = await storageActor(storageId);
8
+ let filesData = new Map;
9
+ await parallel(threads, fileIds, async (fileId) => {
10
+ let { path, data } = await downloadFile(storage, fileId);
11
+ filesData.set(path, data);
12
+ onLoad(fileIds, fileId);
13
+ });
14
+ return filesData;
15
+ }
16
+ // get package files meta
17
+ export async function getPackageFilesInfo(pkg, version) {
18
+ let actor = await mainActor();
19
+ let [packageDetailsRes, fileIds] = await Promise.all([
20
+ actor.getPackageDetails(pkg, version),
21
+ getFileIds(pkg, version),
22
+ ]);
23
+ if ('err' in packageDetailsRes) {
24
+ throw packageDetailsRes.err;
25
+ }
26
+ let packageDetails = packageDetailsRes.ok;
27
+ return {
28
+ storageId: packageDetails.publication.storage,
29
+ fileIds,
30
+ };
31
+ }
32
+ // get package files ids
33
+ export async function getFileIds(pkg, version) {
34
+ let actor = await mainActor();
35
+ let fileIdsRes = await actor.getFileIds(pkg, version);
36
+ if ('err' in fileIdsRes) {
37
+ throw fileIdsRes.err;
38
+ }
39
+ let filesIds = fileIdsRes.ok;
40
+ return filesIds;
41
+ }
42
+ // download single file
43
+ export async function downloadFile(storage, fileId) {
44
+ let fileMetaRes = await storage.getFileMeta(fileId);
45
+ if ('err' in fileMetaRes) {
46
+ throw fileMetaRes.err;
47
+ }
48
+ let fileMeta = fileMetaRes.ok;
49
+ let data = [];
50
+ for (let i = 0n; i < fileMeta.chunkCount; i++) {
51
+ let chunkRes = await storage.downloadChunk(fileId, i);
52
+ if ('err' in chunkRes) {
53
+ throw chunkRes.err;
54
+ }
55
+ let chunk = chunkRes.ok;
56
+ data = [...data, ...chunk];
57
+ }
58
+ return {
59
+ path: fileMeta.path,
60
+ data: data,
61
+ };
62
+ }
@@ -0,0 +1 @@
1
+ export declare function resolveVersion(pkg: string, version?: string): Promise<string>;
@@ -0,0 +1,11 @@
1
+ import { getHighestVersion } from '../mops.js';
2
+ export async function resolveVersion(pkg, version = '') {
3
+ if (!version) {
4
+ let versionRes = await getHighestVersion(pkg);
5
+ if ('err' in versionRes) {
6
+ throw versionRes.err;
7
+ }
8
+ version = versionRes.ok;
9
+ }
10
+ return version;
11
+ }
package/dist/integrity.js CHANGED
@@ -2,7 +2,8 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { sha256 } from '@noble/hashes/sha256';
4
4
  import { bytesToHex } from '@noble/hashes/utils';
5
- import { getDependencyType, getRootDir, mainActor } from './mops.js';
5
+ import { getDependencyType, getRootDir } from './mops.js';
6
+ import { mainActor } from './api/actors.js';
6
7
  import { resolvePackages } from './resolve-packages.js';
7
8
  export async function checkIntegrity(lock) {
8
9
  let force = !!lock;
package/dist/mops.d.ts CHANGED
@@ -1,25 +1,18 @@
1
1
  import { Identity } from '@dfinity/agent';
2
- import { _SERVICE } from './declarations/main/main.did.js';
3
- import { _SERVICE as _STORAGE_SERVICE } from './declarations/storage/storage.did.js';
4
2
  import { Config } from './types.js';
5
- import { Principal } from '@dfinity/principal';
3
+ import { mainActor, storageActor } from './api/actors.js';
4
+ import { getNetwork } from './api/network.js';
5
+ import { getHighestVersion } from './api/getHighestVersion.js';
6
6
  export declare let apiVersion: string;
7
7
  export declare let globalConfigDir: string;
8
8
  export declare let globalCacheDir: string;
9
+ export declare function getNetworkFile(): string | URL;
9
10
  export declare function setNetwork(network: string): void;
10
- export declare function getNetwork(): {
11
- network: string;
12
- host: string;
13
- canisterId: string;
14
- };
15
11
  export declare let getIdentity: () => Promise<Identity | undefined>;
16
- export declare let mainActor: (useIdentity?: boolean) => Promise<_SERVICE>;
17
- export declare let storageActor: (storageId: Principal, useIdentity?: boolean) => Promise<_STORAGE_SERVICE>;
18
12
  export declare function getClosestConfigFile(dir?: string): string;
19
13
  export declare function getRootDir(): string;
20
14
  export declare function checkConfigFile(): boolean;
21
15
  export declare function progressBar(step: number, total: number): string;
22
- export declare function getHighestVersion(pkgName: string): Promise<import("./declarations/main/main.did.js").Result_5>;
23
16
  export declare function parseGithubURL(href: string): {
24
17
  org: string;
25
18
  gitName: string;
@@ -27,10 +20,11 @@ export declare function parseGithubURL(href: string): {
27
20
  commitHash: string;
28
21
  };
29
22
  export declare function getGithubCommit(repo: string, ref: string): Promise<any>;
30
- export declare function getDependencyType(version: string): "mops" | "github" | "local";
23
+ export declare function getDependencyType(version: string): "local" | "mops" | "github";
31
24
  export declare function readConfig(configFile?: string): Config;
32
25
  export declare function writeConfig(config: Config, configFile?: string): void;
33
26
  export declare function formatDir(name: string, version: string): string;
34
27
  export declare function formatGithubDir(name: string, repo: string): string;
35
28
  export declare function readDfxJson(): any;
36
29
  export declare function checkApiCompatibility(): Promise<boolean>;
30
+ export { getNetwork, mainActor, storageActor, getHighestVersion, };
package/dist/mops.js CHANGED
@@ -1,26 +1,19 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs';
3
- import { Actor, HttpAgent } from '@dfinity/agent';
4
3
  import TOML from '@iarna/toml';
5
4
  import chalk from 'chalk';
6
5
  import prompts from 'prompts';
7
6
  import ncp from 'ncp';
8
7
  import fetch from 'node-fetch';
9
- import { idlFactory } from './declarations/main/index.js';
10
- import { idlFactory as storageIdlFactory } from './declarations/storage/index.js';
11
8
  import { decodeFile } from './pem.js';
9
+ import { mainActor, storageActor } from './api/actors.js';
10
+ import { getNetwork } from './api/network.js';
11
+ import { getHighestVersion } from './api/getHighestVersion.js';
12
12
  if (!global.fetch) {
13
13
  global.fetch = fetch;
14
14
  }
15
15
  // (!) make changes in pair with backend
16
16
  export let apiVersion = '1.2';
17
- let networkFile = '';
18
- try {
19
- networkFile = new URL('./network.txt', import.meta.url);
20
- }
21
- catch {
22
- networkFile = path.join(__dirname, 'network.txt');
23
- }
24
17
  export let globalConfigDir = '';
25
18
  export let globalCacheDir = '';
26
19
  // OS specific dirs
@@ -69,35 +62,18 @@ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalCacheDir)) {
69
62
  });
70
63
  console.log('Moved cache to ' + chalk.green(globalCacheDir));
71
64
  }
72
- export function setNetwork(network) {
73
- fs.writeFileSync(networkFile, network);
74
- }
75
- export function getNetwork() {
76
- let network = 'ic';
77
- if (fs.existsSync(networkFile)) {
78
- network = fs.readFileSync(networkFile).toString() || 'ic';
79
- }
80
- if (network === 'staging') {
81
- return {
82
- network,
83
- host: 'https://icp-api.io',
84
- canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
85
- };
65
+ export function getNetworkFile() {
66
+ let networkFile = '';
67
+ try {
68
+ networkFile = new URL('./network.txt', import.meta.url);
86
69
  }
87
- else if (network === 'ic') {
88
- return {
89
- network,
90
- host: 'https://icp-api.io',
91
- canisterId: 'oknww-riaaa-aaaam-qaf6a-cai',
92
- };
93
- }
94
- else {
95
- return {
96
- network,
97
- host: 'http://127.0.0.1:4943',
98
- canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
99
- };
70
+ catch {
71
+ networkFile = path.join(__dirname, 'network.txt');
100
72
  }
73
+ return networkFile;
74
+ }
75
+ export function setNetwork(network) {
76
+ fs.writeFileSync(getNetworkFile(), network);
101
77
  }
102
78
  export let getIdentity = async () => {
103
79
  let identityPem = path.resolve(globalConfigDir, 'identity.pem');
@@ -115,35 +91,6 @@ export let getIdentity = async () => {
115
91
  }
116
92
  return undefined;
117
93
  };
118
- export let mainActor = async (useIdentity = false) => {
119
- let network = getNetwork().network;
120
- let host = getNetwork().host;
121
- let canisterId = getNetwork().canisterId;
122
- let identity = useIdentity ? await getIdentity() : undefined;
123
- // @ts-ignore exactOptionalPropertyTypes
124
- let agent = new HttpAgent({ host, identity });
125
- if (network === 'local') {
126
- await agent.fetchRootKey();
127
- }
128
- return Actor.createActor(idlFactory, {
129
- agent,
130
- canisterId,
131
- });
132
- };
133
- export let storageActor = async (storageId, useIdentity = false) => {
134
- let network = getNetwork().network;
135
- let host = getNetwork().host;
136
- let identity = useIdentity && await getIdentity();
137
- // @ts-ignore exactOptionalPropertyTypes
138
- let agent = new HttpAgent({ host, identity });
139
- if (network === 'local') {
140
- await agent.fetchRootKey();
141
- }
142
- return Actor.createActor(storageIdlFactory, {
143
- agent,
144
- canisterId: storageId,
145
- });
146
- };
147
94
  export function getClosestConfigFile(dir = process.cwd()) {
148
95
  if (!path.basename(dir)) {
149
96
  throw '';
@@ -173,10 +120,6 @@ export function progressBar(step, total) {
173
120
  let done = Math.round(step / total * 10);
174
121
  return `[${':'.repeat(done)}${' '.repeat(Math.max(0, 10 - done))}]`;
175
122
  }
176
- export async function getHighestVersion(pkgName) {
177
- let actor = await mainActor();
178
- return actor.getHighestVersion(pkgName);
179
- }
180
123
  export function parseGithubURL(href) {
181
124
  const url = new URL(href);
182
125
  let branchAndSha = url.hash?.substring(1).split('@');
@@ -292,3 +235,5 @@ export async function checkApiCompatibility() {
292
235
  }
293
236
  return true;
294
237
  }
238
+ // compatibility with older versions
239
+ export { getNetwork, mainActor, storageActor, getHighestVersion, };
@@ -1,4 +1,5 @@
1
- import { getDependencyType, mainActor } from './mops.js';
1
+ import { getDependencyType } from './mops.js';
2
+ import { mainActor } from './api/actors.js';
2
3
  import { resolvePackages } from './resolve-packages.js';
3
4
  export async function notifyInstalls(names) {
4
5
  let resolvedPackages = await resolvePackages();
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/cli.js"
package/integrity.ts CHANGED
@@ -2,7 +2,8 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import {sha256} from '@noble/hashes/sha256';
4
4
  import {bytesToHex} from '@noble/hashes/utils';
5
- import {getDependencyType, getRootDir, mainActor} from './mops.js';
5
+ import {getDependencyType, getRootDir} from './mops.js';
6
+ import {mainActor} from './api/actors.js';
6
7
  import {resolvePackages} from './resolve-packages.js';
7
8
 
8
9
  type LockFileV1 = {