ic-mops 0.39.2 → 0.41.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 (183) hide show
  1. package/.DS_Store +0 -0
  2. package/.eslintrc.json +0 -0
  3. package/.gitignore +1 -0
  4. package/.npmrc +2 -1
  5. package/CHANGELOG.md +8 -0
  6. package/DEVELOPMENT.md +25 -0
  7. package/README.md +0 -0
  8. package/api/actors.ts +2 -2
  9. package/api/downloadPackageFiles.ts +9 -6
  10. package/api/getHighestVersion.ts +1 -1
  11. package/api/index.ts +0 -0
  12. package/api/network.ts +1 -1
  13. package/api/resolveVersion.ts +1 -1
  14. package/bundle/bench/bench-canister.mo +87 -0
  15. package/bundle/bench/user-bench.mo +14 -0
  16. package/bundle/bin/moc-wrapper.sh +3 -0
  17. package/bundle/bin/mops.js +3 -0
  18. package/bundle/cli.js +88 -0
  19. package/bundle/cli.tgz +0 -0
  20. package/bundle/declarations/bench/bench.did +26 -0
  21. package/bundle/declarations/bench/bench.did.d.ts +29 -0
  22. package/bundle/declarations/bench/bench.did.js +26 -0
  23. package/bundle/declarations/bench/index.d.ts +50 -0
  24. package/bundle/declarations/bench/index.js +41 -0
  25. package/bundle/declarations/main/index.d.ts +50 -0
  26. package/bundle/declarations/main/index.js +41 -0
  27. package/bundle/declarations/main/main.did +426 -0
  28. package/bundle/declarations/main/main.did.d.ts +352 -0
  29. package/bundle/declarations/main/main.did.js +404 -0
  30. package/bundle/declarations/storage/index.d.ts +50 -0
  31. package/bundle/declarations/storage/index.js +30 -0
  32. package/bundle/declarations/storage/storage.did +46 -0
  33. package/bundle/declarations/storage/storage.did.d.ts +37 -0
  34. package/bundle/declarations/storage/storage.did.js +38 -0
  35. package/bundle/package.json +31 -0
  36. package/bundle/templates/README.md +13 -0
  37. package/bundle/templates/licenses/Apache-2.0 +202 -0
  38. package/bundle/templates/licenses/Apache-2.0-NOTICE +13 -0
  39. package/bundle/templates/licenses/MIT +21 -0
  40. package/bundle/templates/mops-publish.yml +17 -0
  41. package/bundle/templates/mops-test.yml +22 -0
  42. package/bundle/templates/src/lib.mo +15 -0
  43. package/bundle/templates/test/lib.test.mo +4 -0
  44. package/bundle-package-json.ts +14 -0
  45. package/cache.ts +3 -3
  46. package/cli.ts +25 -21
  47. package/commands/add.ts +6 -6
  48. package/commands/available-updates.ts +2 -2
  49. package/commands/bench/bench-canister.mo +0 -0
  50. package/commands/bench/user-bench.mo +0 -0
  51. package/commands/bench-replica.ts +10 -10
  52. package/commands/bench.ts +96 -56
  53. package/commands/bump.ts +2 -2
  54. package/commands/docs.ts +1 -1
  55. package/commands/import-identity.ts +2 -2
  56. package/commands/init.ts +9 -9
  57. package/commands/install-all.ts +4 -4
  58. package/commands/install-local.ts +1 -1
  59. package/commands/install.ts +2 -2
  60. package/commands/outdated.ts +0 -0
  61. package/commands/publish.ts +34 -35
  62. package/commands/remove.ts +8 -8
  63. package/commands/search.ts +2 -2
  64. package/commands/self.ts +75 -0
  65. package/commands/sources.ts +0 -0
  66. package/commands/sync.ts +8 -8
  67. package/commands/template.ts +11 -12
  68. package/commands/test/mmf1.ts +18 -18
  69. package/commands/test/reporters/compact-reporter.ts +5 -5
  70. package/commands/test/reporters/files-reporter.ts +3 -3
  71. package/commands/test/reporters/reporter.ts +3 -3
  72. package/commands/test/reporters/silent-reporter.ts +4 -4
  73. package/commands/test/reporters/verbose-reporter.ts +3 -3
  74. package/commands/test/test.ts +10 -10
  75. package/commands/test/utils.ts +1 -1
  76. package/commands/toolchain/index.ts +9 -9
  77. package/commands/toolchain/moc.ts +2 -2
  78. package/commands/toolchain/pocket-ic.ts +6 -31
  79. package/commands/toolchain/toolchain-utils.ts +11 -11
  80. package/commands/toolchain/wasmtime.ts +2 -2
  81. package/commands/transfer-ownership.ts +2 -2
  82. package/commands/update.ts +4 -4
  83. package/commands/user.ts +2 -2
  84. package/commands/whoami.ts +0 -0
  85. package/declarations/bench/bench.did.d.ts +3 -0
  86. package/declarations/main/main.did +27 -1
  87. package/declarations/main/main.did.d.ts +26 -1
  88. package/declarations/main/main.did.js +27 -1
  89. package/declarations/storage/index.d.ts +0 -0
  90. package/declarations/storage/index.js +0 -0
  91. package/declarations/storage/storage.did +0 -0
  92. package/declarations/storage/storage.did.d.ts +0 -0
  93. package/declarations/storage/storage.did.js +0 -0
  94. package/dist/api/downloadPackageFiles.d.ts +1 -1
  95. package/dist/api/downloadPackageFiles.js +4 -0
  96. package/dist/bin/moc-wrapper.sh +3 -0
  97. package/dist/bin/mops.d.ts +1 -1
  98. package/dist/bin/mops.js +2 -1
  99. package/dist/bundle-package-json.d.ts +1 -0
  100. package/dist/bundle-package-json.js +11 -0
  101. package/dist/check-requirements.d.ts +3 -0
  102. package/dist/check-requirements.js +39 -0
  103. package/dist/cli.js +19 -18
  104. package/dist/commands/bench/bench-canister.mo +0 -0
  105. package/dist/commands/bench/user-bench.mo +0 -0
  106. package/dist/commands/bench-replica.d.ts +3 -1
  107. package/dist/commands/bench-replica.js +2 -2
  108. package/dist/commands/bench.d.ts +5 -2
  109. package/dist/commands/bench.js +66 -29
  110. package/dist/commands/init.js +1 -1
  111. package/dist/commands/publish.d.ts +1 -0
  112. package/dist/commands/publish.js +25 -25
  113. package/dist/commands/self.d.ts +3 -0
  114. package/dist/commands/self.js +62 -0
  115. package/dist/commands/template.js +9 -10
  116. package/dist/commands/test/mmf1.js +1 -1
  117. package/dist/commands/test/test.js +2 -2
  118. package/dist/commands/toolchain/pocket-ic.d.ts +1 -5
  119. package/dist/commands/toolchain/pocket-ic.js +4 -27
  120. package/dist/commands/toolchain/toolchain-utils.d.ts +1 -1
  121. package/dist/commands/toolchain/toolchain-utils.js +7 -7
  122. package/dist/commands/transfer-ownership.js +1 -1
  123. package/dist/declarations/bench/bench.did.d.ts +3 -0
  124. package/dist/declarations/main/main.did +27 -1
  125. package/dist/declarations/main/main.did.d.ts +26 -1
  126. package/dist/declarations/main/main.did.js +27 -1
  127. package/dist/declarations/storage/index.d.ts +0 -0
  128. package/dist/declarations/storage/index.js +0 -0
  129. package/dist/declarations/storage/storage.did +0 -0
  130. package/dist/declarations/storage/storage.did.d.ts +0 -0
  131. package/dist/declarations/storage/storage.did.js +0 -0
  132. package/dist/helpers/find-changelog-entry.d.ts +1 -0
  133. package/dist/helpers/find-changelog-entry.js +24 -0
  134. package/dist/mops.d.ts +1 -0
  135. package/dist/mops.js +5 -1
  136. package/dist/package.json +20 -26
  137. package/dist/release-cli.d.ts +1 -0
  138. package/dist/release-cli.js +37 -0
  139. package/dist/remove-scripts.d.ts +1 -0
  140. package/dist/remove-scripts.js +5 -0
  141. package/dist/templates/README.md +0 -0
  142. package/dist/templates/licenses/Apache-2.0 +0 -0
  143. package/dist/templates/licenses/Apache-2.0-NOTICE +0 -0
  144. package/dist/templates/licenses/MIT +0 -0
  145. package/dist/templates/mops-publish.yml +0 -0
  146. package/dist/templates/mops-test.yml +0 -0
  147. package/dist/templates/src/lib.mo +0 -0
  148. package/dist/templates/test/lib.test.mo +0 -0
  149. package/dist/templates.d.ts +1 -0
  150. package/dist/templates.js +4 -0
  151. package/dist/vessel.js +1 -1
  152. package/global.d.ts +0 -0
  153. package/helpers/find-changelog-entry.ts +27 -0
  154. package/helpers/get-dfx-version.ts +1 -1
  155. package/helpers/get-moc-path.ts +1 -1
  156. package/helpers/get-moc-version.ts +1 -1
  157. package/integrity.ts +16 -16
  158. package/mops.ts +22 -17
  159. package/notify-installs.ts +2 -2
  160. package/package.json +28 -19
  161. package/parallel.ts +1 -1
  162. package/pem.ts +5 -5
  163. package/release-cli.ts +62 -0
  164. package/remove-scripts.ts +6 -0
  165. package/resolve-packages.ts +9 -9
  166. package/templates/README.md +0 -0
  167. package/templates/licenses/Apache-2.0 +0 -0
  168. package/templates/licenses/Apache-2.0-NOTICE +0 -0
  169. package/templates/licenses/MIT +0 -0
  170. package/templates/mops-publish.yml +0 -0
  171. package/templates/mops-test.yml +0 -0
  172. package/templates/src/lib.mo +0 -0
  173. package/templates/test/lib.test.mo +0 -0
  174. package/templates.ts +5 -0
  175. package/tsconfig.json +1 -1
  176. package/types.ts +25 -25
  177. package/vessel.ts +16 -16
  178. package/commands/self-update.ts +0 -6
  179. package/dist/commands/replica.d.ts +0 -36
  180. package/dist/commands/replica.js +0 -103
  181. package/dist/commands/self-update.d.ts +0 -3
  182. package/dist/commands/self-update.js +0 -5
  183. /package/bin/{mops.ts → mops.js} +0 -0
package/.DS_Store ADDED
Binary file
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/.npmrc CHANGED
@@ -1 +1,2 @@
1
- save-exact = true
1
+ save-exact = true
2
+ # omit = optional
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Mops CLI Changelog
2
+
3
+ ## 0.41.0
4
+ - Add `mops self update` command to update the CLI to the latest version
5
+ - Add `mops self uninstall` command to uninstall the CLI
6
+
7
+ ## 0.40.0
8
+ - Publish package benchmarks
package/DEVELOPMENT.md ADDED
@@ -0,0 +1,25 @@
1
+ # Mops CLI
2
+
3
+ 1. Update the version in `package.json` using `npm version` command.
4
+
5
+ 2. Update changelog in `CHANGELOG.md` file.
6
+
7
+ 3. Publish.
8
+
9
+ ## Publish to npm
10
+ ```
11
+ npm publish
12
+ ```
13
+
14
+ ## Publish on chain
15
+
16
+ 1. Prepeare release
17
+ ```
18
+ npm run release
19
+ ```
20
+
21
+ 2. Deploy canister
22
+ (from root of the project)
23
+ ```
24
+ dfx deploy --network ic --no-wallet cli
25
+ ```
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) {
@@ -0,0 +1,87 @@
1
+ import Nat64 "mo:base/Nat64";
2
+ import Nat "mo:base/Nat";
3
+ import Debug "mo:base/Debug";
4
+ import ExperimentalInternetComputer "mo:base/ExperimentalInternetComputer";
5
+ import Prim "mo:prim";
6
+ import Bench "mo:bench";
7
+
8
+ import UserBench "./user-bench"; // file path will be replaced with the *.bench.mo file path
9
+
10
+ actor class() {
11
+ var benchOpt : ?Bench.Bench = null;
12
+
13
+ public func init() : async Bench.BenchSchema {
14
+ let bench = UserBench.init();
15
+ benchOpt := ?bench;
16
+ bench.getSchema();
17
+ };
18
+
19
+ public query func getSchema() : async Bench.BenchSchema {
20
+ let ?bench = benchOpt else Debug.trap("bench not initialized");
21
+ bench.getSchema();
22
+ };
23
+
24
+ func _getStats() : Bench.BenchResult {
25
+ {
26
+ instructions = 0;
27
+ rts_heap_size = Prim.rts_heap_size();
28
+ rts_memory_size = Prim.rts_memory_size();
29
+ rts_total_allocation = Prim.rts_total_allocation();
30
+ rts_mutator_instructions = Prim.rts_mutator_instructions();
31
+ rts_collector_instructions = Prim.rts_collector_instructions();
32
+ }
33
+ };
34
+
35
+ func _diffStats(before : Bench.BenchResult, after : Bench.BenchResult) : Bench.BenchResult {
36
+ {
37
+ instructions = after.instructions - before.instructions;
38
+ rts_heap_size = after.rts_heap_size - before.rts_heap_size;
39
+ rts_memory_size = after.rts_memory_size - before.rts_memory_size;
40
+ rts_total_allocation = after.rts_total_allocation - before.rts_total_allocation;
41
+ rts_mutator_instructions = after.rts_mutator_instructions - before.rts_mutator_instructions;
42
+ rts_collector_instructions = after.rts_collector_instructions - before.rts_collector_instructions;
43
+ }
44
+ };
45
+
46
+ func _runCell(rowIndex : Nat, colIndex : Nat) : Bench.BenchResult {
47
+ let ?bench = benchOpt else Debug.trap("bench not initialized");
48
+ let statsBefore = _getStats();
49
+
50
+ let instructions = Nat64.toNat(ExperimentalInternetComputer.countInstructions(func() {
51
+ bench.runCell(rowIndex, colIndex);
52
+ }));
53
+
54
+ let statsAfter = _getStats();
55
+ _diffStats(statsBefore, { statsAfter with instructions });
56
+ };
57
+
58
+ func _runCellAwait(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
59
+ let ?bench = benchOpt else Debug.trap("bench not initialized");
60
+ let statsBefore = _getStats();
61
+
62
+ let instructions = Nat64.toNat(ExperimentalInternetComputer.countInstructions(func() {
63
+ bench.runCell(rowIndex, colIndex);
64
+ }));
65
+
66
+ await (func() : async () {})();
67
+
68
+ let statsAfter = _getStats();
69
+ _diffStats(statsBefore, { statsAfter with instructions });
70
+ };
71
+
72
+ public query func getStats() : async Bench.BenchResult {
73
+ _getStats();
74
+ };
75
+
76
+ public query func runCellQuery(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
77
+ _runCell(rowIndex, colIndex);
78
+ };
79
+
80
+ public func runCellUpdate(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
81
+ _runCell(rowIndex, colIndex);
82
+ };
83
+
84
+ public func runCellUpdateAwait(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
85
+ await _runCellAwait(rowIndex, colIndex);
86
+ };
87
+ };
@@ -0,0 +1,14 @@
1
+ import Nat "mo:base/Nat";
2
+ import Iter "mo:base/Iter";
3
+ import Buffer "mo:base/Buffer";
4
+ import Vector "mo:vector/Class";
5
+ import Bench "mo:bench";
6
+
7
+ // placeholder file that will be replaced with the *.bench.mo file
8
+ module {
9
+ public func init() : Bench.Bench {
10
+ let bench = Bench.Bench();
11
+ // benchmark code goes here...
12
+ bench;
13
+ };
14
+ };
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+ mocPath="$(mops toolchain bin moc --fallback)"
3
+ $mocPath "$@"
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import '../cli.js';