ic-mops 0.39.2 → 0.40.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 (229) hide show
  1. package/.eslintrc.json +0 -0
  2. package/.gitignore +1 -0
  3. package/README.md +0 -0
  4. package/api/actors.ts +2 -2
  5. package/api/downloadPackageFiles.ts +9 -6
  6. package/api/getHighestVersion.ts +1 -1
  7. package/api/index.ts +0 -0
  8. package/api/network.ts +1 -1
  9. package/api/resolveVersion.ts +1 -1
  10. package/cache.ts +3 -3
  11. package/cli.ts +3 -2
  12. package/commands/add.ts +6 -6
  13. package/commands/available-updates.ts +2 -2
  14. package/commands/bench/bench-canister.mo +0 -0
  15. package/commands/bench/user-bench.mo +0 -0
  16. package/commands/bench-replica.ts +10 -10
  17. package/commands/bench.ts +96 -56
  18. package/commands/bump.ts +2 -2
  19. package/commands/docs.ts +1 -1
  20. package/commands/import-identity.ts +2 -2
  21. package/commands/init.ts +9 -9
  22. package/commands/install-all.ts +4 -4
  23. package/commands/install-local.ts +1 -1
  24. package/commands/install.ts +2 -2
  25. package/commands/outdated.ts +0 -0
  26. package/commands/publish.ts +34 -9
  27. package/commands/remove.ts +8 -8
  28. package/commands/search.ts +2 -2
  29. package/commands/sources.ts +0 -0
  30. package/commands/sync.ts +8 -8
  31. package/commands/template.ts +2 -2
  32. package/commands/test/mmf1.ts +18 -18
  33. package/commands/test/reporters/compact-reporter.ts +5 -5
  34. package/commands/test/reporters/files-reporter.ts +3 -3
  35. package/commands/test/reporters/reporter.ts +3 -3
  36. package/commands/test/reporters/silent-reporter.ts +4 -4
  37. package/commands/test/reporters/verbose-reporter.ts +3 -3
  38. package/commands/test/test.ts +10 -10
  39. package/commands/test/utils.ts +1 -1
  40. package/commands/toolchain/index.ts +9 -9
  41. package/commands/toolchain/moc.ts +2 -2
  42. package/commands/toolchain/pocket-ic.ts +6 -31
  43. package/commands/toolchain/toolchain-utils.ts +11 -11
  44. package/commands/toolchain/wasmtime.ts +2 -2
  45. package/commands/transfer-ownership.ts +2 -2
  46. package/commands/update.ts +4 -4
  47. package/commands/user.ts +2 -2
  48. package/commands/whoami.ts +0 -0
  49. package/declarations/bench/bench.did.d.ts +3 -0
  50. package/declarations/main/main.did +27 -1
  51. package/declarations/main/main.did.d.ts +26 -1
  52. package/declarations/main/main.did.js +27 -1
  53. package/declarations/storage/index.d.ts +0 -0
  54. package/declarations/storage/index.js +0 -0
  55. package/declarations/storage/storage.did +0 -0
  56. package/declarations/storage/storage.did.d.ts +0 -0
  57. package/declarations/storage/storage.did.js +0 -0
  58. package/dist/api/actors.d.ts +0 -0
  59. package/dist/api/actors.js +0 -0
  60. package/dist/api/downloadPackageFiles.d.ts +1 -1
  61. package/dist/api/downloadPackageFiles.js +4 -0
  62. package/dist/api/getHighestVersion.d.ts +0 -0
  63. package/dist/api/getHighestVersion.js +0 -0
  64. package/dist/api/index.d.ts +0 -0
  65. package/dist/api/index.js +0 -0
  66. package/dist/api/network.d.ts +0 -0
  67. package/dist/api/network.js +0 -0
  68. package/dist/api/resolveVersion.d.ts +0 -0
  69. package/dist/api/resolveVersion.js +0 -0
  70. package/dist/bin/moc-wrapper.sh +3 -0
  71. package/dist/bin/mops.d.ts +0 -0
  72. package/dist/bin/mops.js +0 -0
  73. package/dist/bundle-package-json.d.ts +1 -0
  74. package/dist/bundle-package-json.js +11 -0
  75. package/dist/cache.d.ts +0 -0
  76. package/dist/cache.js +0 -0
  77. package/dist/cli.d.ts +0 -0
  78. package/dist/cli.js +1 -0
  79. package/dist/commands/add.d.ts +0 -0
  80. package/dist/commands/add.js +0 -0
  81. package/dist/commands/available-updates.d.ts +0 -0
  82. package/dist/commands/available-updates.js +0 -0
  83. package/dist/commands/bench/bench-canister.mo +0 -0
  84. package/dist/commands/bench/user-bench.mo +0 -0
  85. package/dist/commands/bench-replica.d.ts +3 -1
  86. package/dist/commands/bench-replica.js +2 -2
  87. package/dist/commands/bench.d.ts +5 -2
  88. package/dist/commands/bench.js +66 -29
  89. package/dist/commands/bump.d.ts +0 -0
  90. package/dist/commands/bump.js +0 -0
  91. package/dist/commands/docs.d.ts +0 -0
  92. package/dist/commands/docs.js +0 -0
  93. package/dist/commands/import-identity.d.ts +0 -0
  94. package/dist/commands/import-identity.js +0 -0
  95. package/dist/commands/init.d.ts +0 -0
  96. package/dist/commands/init.js +1 -1
  97. package/dist/commands/install-all.d.ts +0 -0
  98. package/dist/commands/install-all.js +0 -0
  99. package/dist/commands/install-local.d.ts +0 -0
  100. package/dist/commands/install-local.js +0 -0
  101. package/dist/commands/install.d.ts +0 -0
  102. package/dist/commands/install.js +0 -0
  103. package/dist/commands/outdated.d.ts +0 -0
  104. package/dist/commands/outdated.js +0 -0
  105. package/dist/commands/publish.d.ts +1 -0
  106. package/dist/commands/publish.js +24 -1
  107. package/dist/commands/remove.d.ts +0 -0
  108. package/dist/commands/remove.js +0 -0
  109. package/dist/commands/search.d.ts +0 -0
  110. package/dist/commands/search.js +0 -0
  111. package/dist/commands/self-update.d.ts +0 -0
  112. package/dist/commands/self-update.js +0 -0
  113. package/dist/commands/self.d.ts +3 -0
  114. package/dist/commands/self.js +62 -0
  115. package/dist/commands/sources.d.ts +0 -0
  116. package/dist/commands/sources.js +0 -0
  117. package/dist/commands/sync.d.ts +0 -0
  118. package/dist/commands/sync.js +0 -0
  119. package/dist/commands/template.d.ts +0 -0
  120. package/dist/commands/template.js +0 -0
  121. package/dist/commands/test/mmf1.d.ts +0 -0
  122. package/dist/commands/test/mmf1.js +1 -1
  123. package/dist/commands/test/reporters/compact-reporter.d.ts +0 -0
  124. package/dist/commands/test/reporters/compact-reporter.js +0 -0
  125. package/dist/commands/test/reporters/files-reporter.d.ts +0 -0
  126. package/dist/commands/test/reporters/files-reporter.js +0 -0
  127. package/dist/commands/test/reporters/reporter.d.ts +0 -0
  128. package/dist/commands/test/reporters/reporter.js +0 -0
  129. package/dist/commands/test/reporters/silent-reporter.d.ts +0 -0
  130. package/dist/commands/test/reporters/silent-reporter.js +0 -0
  131. package/dist/commands/test/reporters/verbose-reporter.d.ts +0 -0
  132. package/dist/commands/test/reporters/verbose-reporter.js +0 -0
  133. package/dist/commands/test/test.d.ts +0 -0
  134. package/dist/commands/test/test.js +2 -2
  135. package/dist/commands/test/utils.d.ts +0 -0
  136. package/dist/commands/test/utils.js +0 -0
  137. package/dist/commands/toolchain/index.d.ts +0 -0
  138. package/dist/commands/toolchain/index.js +0 -0
  139. package/dist/commands/toolchain/moc.d.ts +0 -0
  140. package/dist/commands/toolchain/moc.js +0 -0
  141. package/dist/commands/toolchain/pocket-ic.d.ts +1 -5
  142. package/dist/commands/toolchain/pocket-ic.js +4 -27
  143. package/dist/commands/toolchain/toolchain-utils.d.ts +1 -1
  144. package/dist/commands/toolchain/toolchain-utils.js +7 -7
  145. package/dist/commands/toolchain/wasmtime.d.ts +0 -0
  146. package/dist/commands/toolchain/wasmtime.js +0 -0
  147. package/dist/commands/transfer-ownership.d.ts +0 -0
  148. package/dist/commands/transfer-ownership.js +1 -1
  149. package/dist/commands/update.d.ts +0 -0
  150. package/dist/commands/update.js +0 -0
  151. package/dist/commands/user.d.ts +0 -0
  152. package/dist/commands/user.js +0 -0
  153. package/dist/commands/whoami.d.ts +0 -0
  154. package/dist/commands/whoami.js +0 -0
  155. package/dist/declarations/bench/bench.did +0 -0
  156. package/dist/declarations/bench/bench.did.d.ts +3 -0
  157. package/dist/declarations/bench/bench.did.js +0 -0
  158. package/dist/declarations/bench/index.d.ts +0 -0
  159. package/dist/declarations/bench/index.js +0 -0
  160. package/dist/declarations/main/index.d.ts +0 -0
  161. package/dist/declarations/main/index.js +0 -0
  162. package/dist/declarations/main/main.did +27 -1
  163. package/dist/declarations/main/main.did.d.ts +26 -1
  164. package/dist/declarations/main/main.did.js +27 -1
  165. package/dist/declarations/storage/index.d.ts +0 -0
  166. package/dist/declarations/storage/index.js +0 -0
  167. package/dist/declarations/storage/storage.did +0 -0
  168. package/dist/declarations/storage/storage.did.d.ts +0 -0
  169. package/dist/declarations/storage/storage.did.js +0 -0
  170. package/dist/helpers/find-changelog-entry.d.ts +1 -0
  171. package/dist/helpers/find-changelog-entry.js +24 -0
  172. package/dist/helpers/get-dfx-version.d.ts +0 -0
  173. package/dist/helpers/get-dfx-version.js +0 -0
  174. package/dist/helpers/get-moc-path.d.ts +0 -0
  175. package/dist/helpers/get-moc-path.js +0 -0
  176. package/dist/helpers/get-moc-version.d.ts +0 -0
  177. package/dist/helpers/get-moc-version.js +0 -0
  178. package/dist/integrity.d.ts +0 -0
  179. package/dist/integrity.js +0 -0
  180. package/dist/mops.d.ts +0 -0
  181. package/dist/mops.js +1 -1
  182. package/dist/notify-installs.d.ts +0 -0
  183. package/dist/notify-installs.js +0 -0
  184. package/dist/package.json +1 -1
  185. package/dist/parallel.d.ts +0 -0
  186. package/dist/parallel.js +0 -0
  187. package/dist/pem.d.ts +0 -0
  188. package/dist/pem.js +0 -0
  189. package/dist/release-cli.d.ts +1 -0
  190. package/dist/release-cli.js +35 -0
  191. package/dist/remove-scripts.d.ts +1 -0
  192. package/dist/remove-scripts.js +5 -0
  193. package/dist/resolve-packages.d.ts +0 -0
  194. package/dist/resolve-packages.js +0 -0
  195. package/dist/templates/README.md +0 -0
  196. package/dist/templates/licenses/Apache-2.0 +0 -0
  197. package/dist/templates/licenses/Apache-2.0-NOTICE +0 -0
  198. package/dist/templates/licenses/MIT +0 -0
  199. package/dist/templates/mops-publish.yml +0 -0
  200. package/dist/templates/mops-test.yml +0 -0
  201. package/dist/templates/src/lib.mo +0 -0
  202. package/dist/templates/test/lib.test.mo +0 -0
  203. package/dist/types.d.ts +0 -0
  204. package/dist/types.js +0 -0
  205. package/dist/vessel.d.ts +0 -0
  206. package/dist/vessel.js +1 -1
  207. package/global.d.ts +0 -0
  208. package/helpers/get-dfx-version.ts +1 -1
  209. package/helpers/get-moc-path.ts +1 -1
  210. package/helpers/get-moc-version.ts +1 -1
  211. package/integrity.ts +16 -16
  212. package/mops.ts +17 -17
  213. package/notify-installs.ts +2 -2
  214. package/package.json +1 -1
  215. package/parallel.ts +1 -1
  216. package/pem.ts +5 -5
  217. package/resolve-packages.ts +9 -9
  218. package/templates/README.md +0 -0
  219. package/templates/licenses/Apache-2.0 +0 -0
  220. package/templates/licenses/Apache-2.0-NOTICE +0 -0
  221. package/templates/licenses/MIT +0 -0
  222. package/templates/mops-publish.yml +0 -0
  223. package/templates/mops-test.yml +0 -0
  224. package/templates/src/lib.mo +0 -0
  225. package/templates/test/lib.test.mo +0 -0
  226. package/types.ts +25 -25
  227. package/vessel.ts +16 -16
  228. package/dist/commands/replica.d.ts +0 -36
  229. package/dist/commands/replica.js +0 -103
package/.eslintrc.json CHANGED
File without changes
package/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  node_modules
2
2
  dist
3
+ bundle
3
4
  cli.js
4
5
  identity.pem
5
6
  network.txt
package/README.md CHANGED
File without changes
package/api/actors.ts CHANGED
@@ -9,7 +9,7 @@ import {_SERVICE as _STORAGE_SERVICE} from '../declarations/storage/storage.did.
9
9
  import {getEndpoint} from './network.js';
10
10
  import {getNetwork} from './network.js';
11
11
 
12
- export let mainActor = async (identity?: Identity): Promise<_SERVICE> => {
12
+ export let mainActor = async (identity ?: Identity) : Promise<_SERVICE> => {
13
13
  let network = getNetwork();
14
14
  let host = getEndpoint(network).host;
15
15
  let canisterId = getEndpoint(network).canisterId;
@@ -27,7 +27,7 @@ export let mainActor = async (identity?: Identity): Promise<_SERVICE> => {
27
27
  });
28
28
  };
29
29
 
30
- export let storageActor = async (storageId: Principal, identity?: Identity): Promise<_STORAGE_SERVICE> => {
30
+ export let storageActor = async (storageId : Principal, identity ?: Identity) : Promise<_STORAGE_SERVICE> => {
31
31
  let network = getNetwork();
32
32
  let host = getEndpoint(network).host;
33
33
 
@@ -4,14 +4,14 @@ import {resolveVersion} from './resolveVersion.js';
4
4
  import {parallel} from '../parallel.js';
5
5
  import {Storage} from '../declarations/storage/storage.did.js';
6
6
 
7
- export async function downloadPackageFiles(pkg: string, version = '', threads = 8, onLoad = (_fileIds: string[], _fileId: string) => {}): Promise<Map<string, Array<number>>> {
7
+ export async function downloadPackageFiles(pkg : string, version = '', threads = 8, onLoad = (_fileIds : string[], _fileId : string) => {}) : Promise<Map<string, Array<number>>> {
8
8
  version = await resolveVersion(pkg, version);
9
9
 
10
10
  let {storageId, fileIds} = await getPackageFilesInfo(pkg, version);
11
11
  let storage = await storageActor(storageId);
12
12
 
13
13
  let filesData = new Map<string, Array<number>>();
14
- await parallel(threads, fileIds, async (fileId: string) => {
14
+ await parallel(threads, fileIds, async (fileId : string) => {
15
15
  let {path, data} = await downloadFile(storage, fileId);
16
16
  filesData.set(path, data);
17
17
  onLoad(fileIds, fileId);
@@ -21,7 +21,7 @@ export async function downloadPackageFiles(pkg: string, version = '', threads =
21
21
  }
22
22
 
23
23
  // get package files meta
24
- export async function getPackageFilesInfo(pkg: string, version: string): Promise<{ storageId: Principal, fileIds: string[] }> {
24
+ export async function getPackageFilesInfo(pkg : string, version : string) : Promise<{ storageId : Principal, fileIds : string[] }> {
25
25
  let actor = await mainActor();
26
26
 
27
27
  let [packageDetailsRes, fileIds] = await Promise.all([
@@ -41,7 +41,7 @@ export async function getPackageFilesInfo(pkg: string, version: string): Promise
41
41
  }
42
42
 
43
43
  // get package files ids
44
- export async function getFileIds(pkg: string, version: string): Promise<string[]> {
44
+ export async function getFileIds(pkg : string, version : string) : Promise<string[]> {
45
45
  let actor = await mainActor();
46
46
  let fileIdsRes = await actor.getFileIds(pkg, version);
47
47
 
@@ -54,14 +54,17 @@ export async function getFileIds(pkg: string, version: string): Promise<string[]
54
54
  }
55
55
 
56
56
  // download single file
57
- export async function downloadFile(storage: Storage, fileId: string): Promise<{ path: string, data: Array<number> }> {
57
+ export async function downloadFile(storage : Storage | string, fileId : string) : Promise<{path : string, data : Array<number>;}> {
58
+ if (typeof storage === 'string') {
59
+ storage = await storageActor(Principal.fromText(storage));
60
+ }
58
61
  let fileMetaRes = await storage.getFileMeta(fileId);
59
62
  if ('err' in fileMetaRes) {
60
63
  throw fileMetaRes.err;
61
64
  }
62
65
  let fileMeta = fileMetaRes.ok;
63
66
 
64
- let data: Array<number> = [];
67
+ let data : Array<number> = [];
65
68
  for (let i = 0n; i < fileMeta.chunkCount; i++) {
66
69
  let chunkRes = await storage.downloadChunk(fileId, i);
67
70
  if ('err' in chunkRes) {
@@ -1,6 +1,6 @@
1
1
  import {mainActor} from './actors.js';
2
2
 
3
- export async function getHighestVersion(pkgName: string) {
3
+ export async function getHighestVersion(pkgName : string) {
4
4
  let actor = await mainActor();
5
5
  return actor.getHighestVersion(pkgName);
6
6
  }
package/api/index.ts CHANGED
File without changes
package/api/network.ts CHANGED
@@ -2,7 +2,7 @@ export function getNetwork() {
2
2
  return globalThis.MOPS_NETWORK || 'ic';
3
3
  }
4
4
 
5
- export function getEndpoint(network: string) {
5
+ export function getEndpoint(network : string) {
6
6
  if (network === 'staging') {
7
7
  return {
8
8
  host: 'https://icp-api.io',
@@ -1,6 +1,6 @@
1
1
  import {getHighestVersion} from './getHighestVersion.js';
2
2
 
3
- export async function resolveVersion(pkg: string, version = ''): Promise<string> {
3
+ export async function resolveVersion(pkg : string, version = '') : Promise<string> {
4
4
  if (!version) {
5
5
  let versionRes = await getHighestVersion(pkg);
6
6
  if ('err' in versionRes) {
package/cache.ts CHANGED
@@ -5,12 +5,12 @@ import getFolderSize from 'get-folder-size';
5
5
 
6
6
  import {globalCacheDir} from './mops.js';
7
7
 
8
- export let isCached = (pkgId: string) => {
8
+ export let isCached = (pkgId : string) => {
9
9
  let dir = path.join(globalCacheDir, 'packages', pkgId);
10
10
  return fs.existsSync(dir);
11
11
  };
12
12
 
13
- export let addCache = (pkgId: string, source: string) => {
13
+ export let addCache = (pkgId : string, source : string) => {
14
14
  let dest = path.join(globalCacheDir, 'packages', pkgId);
15
15
  fs.mkdirSync(dest, {recursive: true});
16
16
 
@@ -24,7 +24,7 @@ export let addCache = (pkgId: string, source: string) => {
24
24
  });
25
25
  };
26
26
 
27
- export let copyCache = (pkgId: string, dest: string) => {
27
+ export let copyCache = (pkgId : string, dest : string) => {
28
28
  let source = path.join(globalCacheDir, 'packages', pkgId);
29
29
  fs.mkdirSync(dest, {recursive: true});
30
30
 
package/cli.ts CHANGED
@@ -30,7 +30,7 @@ import {Tool} from './types.js';
30
30
 
31
31
  declare global {
32
32
  // eslint-disable-next-line no-var
33
- var MOPS_NETWORK: string;
33
+ var MOPS_NETWORK : string;
34
34
  }
35
35
 
36
36
  let networkFile = getNetworkFile();
@@ -121,6 +121,7 @@ program
121
121
  .description('Publish package to the mops registry')
122
122
  .option('--no-docs', 'Do not generate docs')
123
123
  .option('--no-test', 'Do not run tests')
124
+ .option('--no-bench', 'Do not run benchmarks')
124
125
  .action(async (options) => {
125
126
  if (!checkConfigFile()) {
126
127
  process.exit(1);
@@ -366,7 +367,7 @@ toolchainCommand
366
367
  .command('update')
367
368
  .description('Update specified tool or all tools to the latest version and update mops.toml')
368
369
  .addArgument(new Argument('[tool]').choices(['moc', 'wasmtime', 'pocket-ic']))
369
- .action(async (tool?: Tool) => {
370
+ .action(async (tool ?: Tool) => {
370
371
  if (!checkConfigFile()) {
371
372
  process.exit(1);
372
373
  }
package/commands/add.ts CHANGED
@@ -9,13 +9,13 @@ import {notifyInstalls} from '../notify-installs.js';
9
9
  import {checkIntegrity} from '../integrity.js';
10
10
 
11
11
  type AddOptions = {
12
- verbose?: boolean;
13
- dev?: boolean;
14
- lock?: 'update' | 'ignore';
12
+ verbose ?: boolean;
13
+ dev ?: boolean;
14
+ lock ?: 'update' | 'ignore';
15
15
  };
16
16
 
17
17
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
- export async function add(name: string, {verbose = false, dev = false, lock}: AddOptions = {}, asName?: string) {
18
+ export async function add(name : string, {verbose = false, dev = false, lock} : AddOptions = {}, asName ?: string) {
19
19
  if (!checkConfigFile()) {
20
20
  return;
21
21
  }
@@ -32,7 +32,7 @@ export async function add(name: string, {verbose = false, dev = false, lock}: Ad
32
32
  }
33
33
  }
34
34
 
35
- let pkgDetails: any;
35
+ let pkgDetails : any;
36
36
 
37
37
  // local package
38
38
  if (name.startsWith('./') || name.startsWith('../') || name.startsWith('/')) {
@@ -64,7 +64,7 @@ export async function add(name: string, {verbose = false, dev = false, lock}: Ad
64
64
  }
65
65
  // mops package
66
66
  else {
67
- let ver: string;
67
+ let ver : string;
68
68
  if (name.includes('@')) {
69
69
  // @ts-ignore
70
70
  [name, ver] = name.split('@');
@@ -3,13 +3,13 @@ import {mainActor} from '../api/actors.js';
3
3
  import {Config} from '../types.js';
4
4
 
5
5
  // [pkg, oldVersion, newVersion]
6
- export async function getAvailableUpdates(config: Config, pkg?: string): Promise<Array<[string, string, string]>> {
6
+ export async function getAvailableUpdates(config : Config, pkg ?: string) : Promise<Array<[string, string, string]>> {
7
7
  let deps = Object.values(config.dependencies || {});
8
8
  let devDeps = Object.values(config['dev-dependencies'] || {});
9
9
  let allDeps = [...deps, ...devDeps].filter((dep) => dep.version);
10
10
  let depsToUpdate = pkg ? allDeps.filter((dep) => dep.name === pkg) : allDeps;
11
11
 
12
- let getCurrentVersion = (pkg: string) => {
12
+ let getCurrentVersion = (pkg : string) => {
13
13
  for (let dep of allDeps) {
14
14
  if (dep.name === pkg && dep.version) {
15
15
  return dep.version;
File without changes
File without changes
@@ -10,16 +10,16 @@ import {toolchain} from './toolchain/index.js';
10
10
  export class BenchReplica {
11
11
  type : 'dfx' | 'pocket-ic';
12
12
  verbose = false;
13
- canisters: Record<string, {cwd: string; canisterId: string; actor: any;}> = {};
14
- pocketIc?: PocketIc;
13
+ canisters : Record<string, {cwd : string; canisterId : string; actor : any;}> = {};
14
+ pocketIc ?: PocketIc;
15
15
 
16
- constructor(type: 'dfx' | 'pocket-ic', verbose = false) {
16
+ constructor(type : 'dfx' | 'pocket-ic', verbose = false) {
17
17
  this.type = type;
18
18
  this.verbose = verbose;
19
19
  }
20
20
 
21
- async start() {
22
- console.log(`Starting ${this.type} replica...`);
21
+ async start({silent = false} = {}) {
22
+ silent || console.log(`Starting ${this.type} replica...`);
23
23
 
24
24
  if (this.type == 'dfx') {
25
25
  await this.stop();
@@ -48,7 +48,7 @@ export class BenchReplica {
48
48
  }
49
49
  }
50
50
 
51
- async deploy(name: string, wasm: string, cwd: string = process.cwd()) {
51
+ async deploy(name : string, wasm : string, cwd : string = process.cwd()) {
52
52
  if (this.type === 'dfx') {
53
53
  await execaCommand(`dfx deploy ${name} --mode reinstall --yes --identity anonymous`, {cwd, stdio: this.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe']});
54
54
  let canisterId = execSync(`dfx canister id ${name}`, {cwd}).toString().trim();
@@ -69,16 +69,16 @@ export class BenchReplica {
69
69
  }
70
70
  }
71
71
 
72
- getActor(name: string): unknown {
72
+ getActor(name : string) : unknown {
73
73
  return this.canisters[name]?.actor;
74
74
  }
75
75
 
76
- getCanisterId(name: string): string {
76
+ getCanisterId(name : string) : string {
77
77
  return this.canisters[name]?.canisterId || '';
78
78
  }
79
79
 
80
- dfxJson(canisterName: string) {
81
- let canisters: Record<string, any> = {};
80
+ dfxJson(canisterName : string) {
81
+ let canisters : Record<string, any> = {};
82
82
  if (canisterName) {
83
83
  canisters[canisterName] = {
84
84
  type: 'custom',
package/commands/bench.ts CHANGED
@@ -8,7 +8,7 @@ import logUpdate from 'log-update';
8
8
  import {execaCommand} from 'execa';
9
9
  import stringWidth from 'string-width';
10
10
 
11
- import {getRootDir} from '../mops.js';
11
+ import {getRootDir, readConfig} from '../mops.js';
12
12
  import {parallel} from '../parallel.js';
13
13
  import {absToRel} from './test/utils.js';
14
14
  import {getMocVersion} from '../helpers/get-moc-version.js';
@@ -16,7 +16,8 @@ import {getDfxVersion} from '../helpers/get-dfx-version.js';
16
16
  import {getMocPath} from '../helpers/get-moc-path.js';
17
17
  import {sources} from './sources.js';
18
18
 
19
- import {BenchResult, BenchSchema, _SERVICE} from '../declarations/bench/bench.did.js';
19
+ import {Benchmark, Benchmarks} from '../declarations/main/main.did.js';
20
+ import {BenchResult, _SERVICE} from '../declarations/bench/bench.did.js';
20
21
  import {BenchReplica} from './bench-replica.js';
21
22
 
22
23
  let ignore = [
@@ -32,31 +33,42 @@ let globConfig = {
32
33
  };
33
34
 
34
35
  type BenchOptions = {
35
- replica: 'dfx' | 'pocket-ic',
36
- replicaVersion: string,
37
- moc: string,
38
- gc: 'copying' | 'compacting' | 'generational' | 'incremental',
39
- forceGc: boolean,
40
- save: boolean,
41
- compare: boolean,
42
- verbose: boolean,
36
+ replica : 'dfx' | 'pocket-ic',
37
+ replicaVersion : string,
38
+ compiler : 'moc',
39
+ compilerVersion : string,
40
+ gc : 'copying' | 'compacting' | 'generational' | 'incremental',
41
+ forceGc : boolean,
42
+ save : boolean,
43
+ compare : boolean,
44
+ verbose : boolean,
45
+ silent : boolean,
46
+
43
47
  };
44
48
 
45
- export async function bench(filter = '', optionsArg: Partial<BenchOptions> = {}): Promise<boolean> {
46
- let defaultOptions: BenchOptions = {
49
+ export async function bench(filter = '', optionsArg : Partial<BenchOptions> = {}) : Promise<Benchmarks> {
50
+ let defaultOptions : BenchOptions = {
47
51
  replica: 'dfx',
48
- moc: getMocVersion(),
49
- replicaVersion: '0.0.0',
52
+ replicaVersion: '',
53
+ compiler: 'moc',
54
+ compilerVersion: getMocVersion(),
50
55
  gc: 'copying',
51
56
  forceGc: true,
52
57
  save: false,
53
58
  compare: false,
54
59
  verbose: false,
60
+ silent: false,
55
61
  };
56
62
 
57
- let options: BenchOptions = {...defaultOptions, ...optionsArg};
63
+ let options : BenchOptions = {...defaultOptions, ...optionsArg};
58
64
 
59
- options.replicaVersion = options.replica == 'dfx' ? getDfxVersion() : '1.0.0';
65
+ if (options.replica == 'dfx') {
66
+ options.replicaVersion = getDfxVersion();
67
+ }
68
+ else if (options.replica == 'pocket-ic') {
69
+ let config = readConfig();
70
+ options.replicaVersion = config.toolchain?.['pocket-ic'] || '';
71
+ }
60
72
 
61
73
  options.verbose && console.log(options);
62
74
 
@@ -70,12 +82,14 @@ export async function bench(filter = '', optionsArg: Partial<BenchOptions> = {})
70
82
  let files = globSync(path.join(rootDir, globStr), globConfig);
71
83
  if (!files.length) {
72
84
  if (filter) {
73
- console.log(`No benchmark files found for filter '${filter}'`);
74
- return false;
85
+ options.silent || console.log(`No benchmark files found for filter '${filter}'`);
86
+ return [];
87
+ }
88
+ if (!options.silent) {
89
+ console.log('No *.bench.mo files found');
90
+ console.log('Put your benchmark code in \'bench\' directory in *.bench.mo files');
75
91
  }
76
- console.log('No *.bench.mo files found');
77
- console.log('Put your benchmark code in \'bench\' directory in *.bench.mo files');
78
- return false;
92
+ return [];
79
93
  }
80
94
 
81
95
  files.sort();
@@ -84,18 +98,20 @@ export async function bench(filter = '', optionsArg: Partial<BenchOptions> = {})
84
98
  fs.rmSync(benchDir, {recursive: true, force: true});
85
99
  fs.mkdirSync(benchDir, {recursive: true});
86
100
 
87
- console.log('Benchmark files:');
88
- for (let file of files) {
89
- console.log(chalk.gray(`• ${absToRel(file)}`));
101
+ if (!options.silent) {
102
+ console.log('Benchmark files:');
103
+ for (let file of files) {
104
+ console.log(chalk.gray(`• ${absToRel(file)}`));
105
+ }
106
+ console.log('');
107
+ console.log('='.repeat(50));
108
+ console.log('');
90
109
  }
91
- console.log('');
92
- console.log('='.repeat(50));
93
- console.log('');
94
110
 
95
- await replica.start();
111
+ await replica.start({silent: options.silent});
96
112
 
97
- console.log('Deploying canisters...');
98
- await parallel(os.cpus().length, files, async (file: string) => {
113
+ options.silent || console.log('Deploying canisters...');
114
+ await parallel(os.cpus().length, files, async (file : string) => {
99
115
  try {
100
116
  await deployBenchFile(file, options, replica);
101
117
  }
@@ -106,12 +122,17 @@ export async function bench(filter = '', optionsArg: Partial<BenchOptions> = {})
106
122
  }
107
123
  });
108
124
 
109
- await parallel(1, files, async (file: string) => {
110
- console.log('\n' + '—'.repeat(50));
111
- console.log(`\nRunning ${chalk.gray(absToRel(file))}...`);
112
- console.log('');
125
+ let benchResults : Benchmarks = [];
126
+
127
+ await parallel(1, files, async (file : string) => {
128
+ if (!options.silent) {
129
+ console.log('\n' + '—'.repeat(50));
130
+ console.log(`\nRunning ${chalk.gray(absToRel(file))}...`);
131
+ console.log('');
132
+ }
113
133
  try {
114
- await runBenchFile(file, options, replica);
134
+ let benchResult = await runBenchFile(file, options, replica);
135
+ benchResults.push(benchResult);
115
136
  }
116
137
  catch (err) {
117
138
  console.error('Unexpected error. Stopping replica...');
@@ -120,15 +141,15 @@ export async function bench(filter = '', optionsArg: Partial<BenchOptions> = {})
120
141
  }
121
142
  });
122
143
 
123
- console.log('Stopping replica...');
144
+ options.silent || console.log('Stopping replica...');
124
145
  await replica.stop();
125
146
 
126
147
  fs.rmSync(benchDir, {recursive: true, force: true});
127
148
 
128
- return true;
149
+ return benchResults;
129
150
  }
130
151
 
131
- function getMocArgs(options: BenchOptions): string {
152
+ function getMocArgs(options : BenchOptions) : string {
132
153
  let args = '';
133
154
  if (options.forceGc) {
134
155
  args += ' --force-gc';
@@ -139,7 +160,7 @@ function getMocArgs(options: BenchOptions): string {
139
160
  return args;
140
161
  }
141
162
 
142
- async function deployBenchFile(file: string, options: BenchOptions, replica: BenchReplica): Promise<void> {
163
+ async function deployBenchFile(file : string, options : BenchOptions, replica : BenchReplica) : Promise<void> {
143
164
  let rootDir = getRootDir();
144
165
  let tempDir = path.join(rootDir, '.mops/.bench/', path.parse(file).name);
145
166
  let canisterName = path.parse(file).name;
@@ -173,12 +194,7 @@ async function deployBenchFile(file: string, options: BenchOptions, replica: Ben
173
194
  options.verbose && console.timeEnd(`init ${canisterName}`);
174
195
  }
175
196
 
176
- type RunBenchFileResult = {
177
- schema: BenchSchema,
178
- results: Map<string, BenchResult>,
179
- };
180
-
181
- async function runBenchFile(file: string, options: BenchOptions, replica: BenchReplica): Promise<RunBenchFileResult> {
197
+ async function runBenchFile(file : string, options : BenchOptions, replica : BenchReplica) : Promise<Benchmark> {
182
198
  let rootDir = getRootDir();
183
199
  let canisterName = path.parse(file).name;
184
200
 
@@ -186,7 +202,7 @@ async function runBenchFile(file: string, options: BenchOptions, replica: BenchR
186
202
  let schema = await actor.getSchema();
187
203
 
188
204
  // load previous results
189
- let prevResults: Map<string, BenchResult> | undefined;
205
+ let prevResults : Map<string, BenchResult> | undefined;
190
206
  let resultsJsonFile = path.join(rootDir, '.bench', `${path.parse(file).name}.json`);
191
207
  if (options.compare) {
192
208
  if (fs.existsSync(resultsJsonFile)) {
@@ -200,11 +216,14 @@ async function runBenchFile(file: string, options: BenchOptions, replica: BenchR
200
216
 
201
217
  let results = new Map<string, BenchResult>();
202
218
 
203
- let formatNumber = (n: bigint | number): string => {
219
+ let instructionsCells : bigint[][] = Array.from({length: schema.rows.length}, () => []);
220
+ let heapCells : bigint[][] = Array.from({length: schema.rows.length}, () => []);
221
+
222
+ let formatNumber = (n : bigint | number) : string => {
204
223
  return n.toLocaleString('en-US').replaceAll(',', '_');
205
224
  };
206
225
 
207
- let getTable = (prop: keyof BenchResult): string => {
226
+ let getTable = (prop : keyof BenchResult) : string => {
208
227
  let resArr = [['', ...schema.cols]];
209
228
 
210
229
  for (let [_rowIndex, row] of schema.rows.entries()) {
@@ -222,7 +241,7 @@ async function runBenchFile(file: string, options: BenchOptions, replica: BenchR
222
241
  let percent = (Number(res[prop]) - Number(prevRes[prop])) / Number(prevRes[prop]) * 100;
223
242
  let sign = percent > 0 ? '+' : '';
224
243
  let percentText = percent == 0 ? '0%' : sign + percent.toFixed(2) + '%';
225
- let color: keyof typeof chalk = percent == 0 ? 'gray' : (percent > 0 ? 'red' : 'green');
244
+ let color : keyof typeof chalk = percent == 0 ? 'gray' : (percent > 0 ? 'red' : 'green');
226
245
  diff = ` (${chalk[color](percentText)})`;
227
246
  }
228
247
  else {
@@ -255,18 +274,22 @@ async function runBenchFile(file: string, options: BenchOptions, replica: BenchR
255
274
  `);
256
275
  };
257
276
 
258
- if (!process.env.CI) {
277
+ if (!process.env.CI && !options.silent) {
259
278
  printResults();
260
279
  }
261
280
 
262
281
  // run all cells
263
282
  for (let [rowIndex, row] of schema.rows.entries()) {
264
283
  for (let [colIndex, col] of schema.cols.entries()) {
265
- // let res = await actor.runCellQuery(BigInt(rowIndex), BigInt(colIndex));
266
- // let res = await actor.runCellUpdate(BigInt(rowIndex), BigInt(colIndex));
267
284
  let res = await actor.runCellUpdateAwait(BigInt(rowIndex), BigInt(colIndex));
268
285
  results.set(`${row}:${col}`, res);
269
- if (!process.env.CI) {
286
+
287
+ // @ts-ignore
288
+ instructionsCells[rowIndex][colIndex] = res.instructions;
289
+ // @ts-ignore
290
+ heapCells[rowIndex][colIndex] = res.rts_heap_size;
291
+
292
+ if (!process.env.CI && !options.silent) {
270
293
  printResults();
271
294
  }
272
295
  }
@@ -280,9 +303,9 @@ async function runBenchFile(file: string, options: BenchOptions, replica: BenchR
280
303
  // save results
281
304
  if (options.save) {
282
305
  console.log(`Saving results to ${chalk.gray(absToRel(resultsJsonFile))}`);
283
- let json: Record<any, any> = {
306
+ let json : Record<any, any> = {
284
307
  version: 1,
285
- moc: options.moc,
308
+ moc: options.compilerVersion,
286
309
  replica: options.replica,
287
310
  replicaVersion: options.replicaVersion,
288
311
  gc: options.gc,
@@ -300,5 +323,22 @@ async function runBenchFile(file: string, options: BenchOptions, replica: BenchR
300
323
  }, 2));
301
324
  }
302
325
 
303
- return {schema, results};
326
+ // for backend
327
+ return {
328
+ name: schema.name,
329
+ description: schema.description,
330
+ file: absToRel(file),
331
+ gc: options.gc,
332
+ forceGC: options.forceGc,
333
+ replica: options.replica,
334
+ replicaVersion: options.replicaVersion,
335
+ compiler: options.compiler,
336
+ compilerVersion: options.compilerVersion,
337
+ rows: schema.rows,
338
+ cols: schema.cols,
339
+ metrics: [
340
+ ['instructions', instructionsCells],
341
+ ['rts_heap_size', heapCells],
342
+ ],
343
+ };
304
344
  }
package/commands/bump.ts CHANGED
@@ -2,7 +2,7 @@ import prompts from 'prompts';
2
2
  import chalk from 'chalk';
3
3
  import {checkConfigFile, readConfig, writeConfig} from '../mops.js';
4
4
 
5
- export async function bump(part: string) {
5
+ export async function bump(part : string) {
6
6
  if (!checkConfigFile()) {
7
7
  return;
8
8
  }
@@ -44,7 +44,7 @@ export async function bump(part: string) {
44
44
  console.log(`Updated version: ${chalk.green.bold(config.package.version)}`);
45
45
  }
46
46
 
47
- function updateVersion(version: string, part: string) {
47
+ function updateVersion(version : string, part : string) {
48
48
  let parts = version.split('.');
49
49
  let idx = ['major', 'minor', 'patch'].indexOf(part);
50
50
  if (!parts[idx]) {
package/commands/docs.ts CHANGED
@@ -10,7 +10,7 @@ import streamToPromise from 'stream-to-promise';
10
10
  import {getRootDir} from '../mops.js';
11
11
  import {toolchain} from './toolchain/index.js';
12
12
 
13
- let moDocPath: string;
13
+ let moDocPath : string;
14
14
 
15
15
  export async function docs({silent = false} = {}) {
16
16
  let rootDir = getRootDir();
@@ -7,10 +7,10 @@ import {globalConfigDir} from '../mops.js';
7
7
  import {encrypt} from '../pem.js';
8
8
 
9
9
  type ImportIdentityOptions = {
10
- encrypt: boolean;
10
+ encrypt : boolean;
11
11
  };
12
12
 
13
- export async function importPem(data: string, options: ImportIdentityOptions = {encrypt: true}) {
13
+ export async function importPem(data : string, options : ImportIdentityOptions = {encrypt: true}) {
14
14
  try {
15
15
  if (!fs.existsSync(globalConfigDir)) {
16
16
  fs.mkdirSync(globalConfigDir);
package/commands/init.ts CHANGED
@@ -21,7 +21,7 @@ export async function init({yes = false} = {}) {
21
21
 
22
22
  console.log('Initializing...');
23
23
 
24
- let config: Config = {};
24
+ let config : Config = {};
25
25
 
26
26
  if (yes) {
27
27
  await applyInit({
@@ -36,7 +36,7 @@ export async function init({yes = false} = {}) {
36
36
 
37
37
  // migrate from vessel
38
38
  let vesselFile = path.join(process.cwd(), 'vessel.dhall');
39
- let vesselConfig: VesselConfig = {dependencies: [], 'dev-dependencies': []};
39
+ let vesselConfig : VesselConfig = {dependencies: [], 'dev-dependencies': []};
40
40
 
41
41
  if (existsSync(vesselFile)) {
42
42
  console.log('Reading vessel.dhall file');
@@ -47,7 +47,7 @@ export async function init({yes = false} = {}) {
47
47
  }
48
48
 
49
49
  if (vesselConfig.dependencies) {
50
- let deps: Dependencies = {};
50
+ let deps : Dependencies = {};
51
51
  deps = {};
52
52
 
53
53
  for (const dep of (vesselConfig.dependencies || [])) {
@@ -63,7 +63,7 @@ export async function init({yes = false} = {}) {
63
63
  onCancel() {
64
64
  console.log('aborted');
65
65
  process.exit(0);
66
- }
66
+ },
67
67
  };
68
68
 
69
69
  // type
@@ -162,11 +162,11 @@ export async function init({yes = false} = {}) {
162
162
  }
163
163
 
164
164
  type ApplyInitOptions = {
165
- type: 'project' | 'package';
166
- config: Config;
167
- setupWorkflow: boolean;
168
- addTest: boolean;
169
- copyrightOwner: string;
165
+ type : 'project' | 'package';
166
+ config : Config;
167
+ setupWorkflow : boolean;
168
+ addTest : boolean;
169
+ copyrightOwner : string;
170
170
  }
171
171
 
172
172
  async function applyInit({type, config, setupWorkflow, addTest, copyrightOwner} : ApplyInitOptions) {