ic-mops 0.45.3 → 0.45.4-pre.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 (104) hide show
  1. package/.eslintrc.json +0 -0
  2. package/.gitignore +0 -0
  3. package/CHANGELOG.md +1 -0
  4. package/README.md +0 -0
  5. package/api/actors.ts +25 -17
  6. package/api/downloadPackageFiles.ts +0 -0
  7. package/api/getHighestVersion.ts +0 -0
  8. package/api/index.ts +0 -0
  9. package/api/network.ts +0 -0
  10. package/api/resolveVersion.ts +0 -0
  11. package/cache.ts +10 -3
  12. package/commands/bench/bench-canister.mo +0 -0
  13. package/commands/bench/user-bench.mo +0 -0
  14. package/commands/bump.ts +0 -0
  15. package/commands/docs.ts +0 -0
  16. package/commands/import-identity.ts +0 -0
  17. package/commands/outdated.ts +0 -0
  18. package/commands/search.ts +0 -0
  19. package/commands/sources.ts +0 -0
  20. package/commands/sync.ts +0 -0
  21. package/commands/template.ts +0 -0
  22. package/commands/test/mmf1.ts +0 -0
  23. package/commands/test/reporters/compact-reporter.ts +0 -0
  24. package/commands/test/reporters/files-reporter.ts +0 -0
  25. package/commands/test/reporters/reporter.ts +0 -0
  26. package/commands/test/reporters/silent-reporter.ts +0 -0
  27. package/commands/test/reporters/verbose-reporter.ts +0 -0
  28. package/commands/test/utils.ts +0 -0
  29. package/commands/toolchain/moc.ts +0 -0
  30. package/commands/toolchain/pocket-ic.ts +0 -0
  31. package/commands/toolchain/toolchain-utils.ts +0 -0
  32. package/commands/toolchain/wasmtime.ts +0 -0
  33. package/commands/transfer-ownership.ts +0 -0
  34. package/commands/update.ts +0 -0
  35. package/commands/user.ts +0 -0
  36. package/commands/whoami.ts +0 -0
  37. package/declarations/storage/index.d.ts +0 -0
  38. package/declarations/storage/index.js +0 -0
  39. package/declarations/storage/storage.did +0 -0
  40. package/declarations/storage/storage.did.d.ts +0 -0
  41. package/declarations/storage/storage.did.js +0 -0
  42. package/dist/api/actors.js +19 -13
  43. package/dist/cache.js +8 -3
  44. package/dist/commands/bench/bench-canister.mo +0 -0
  45. package/dist/commands/bench/user-bench.mo +0 -0
  46. package/dist/declarations/storage/index.d.ts +0 -0
  47. package/dist/declarations/storage/index.js +0 -0
  48. package/dist/declarations/storage/storage.did +0 -0
  49. package/dist/declarations/storage/storage.did.d.ts +0 -0
  50. package/dist/declarations/storage/storage.did.js +0 -0
  51. package/dist/package.json +1 -1
  52. package/dist/templates/README.md +0 -0
  53. package/dist/templates/licenses/Apache-2.0 +0 -0
  54. package/dist/templates/licenses/Apache-2.0-NOTICE +0 -0
  55. package/dist/templates/licenses/MIT +0 -0
  56. package/dist/templates/mops-publish.yml +0 -0
  57. package/dist/templates/mops-test.yml +0 -0
  58. package/dist/templates/src/lib.mo +0 -0
  59. package/dist/templates/test/lib.test.mo +0 -0
  60. package/global.d.ts +0 -0
  61. package/helpers/get-dfx-version.ts +0 -0
  62. package/helpers/get-moc-path.ts +0 -0
  63. package/helpers/get-moc-version.ts +0 -0
  64. package/package.json +1 -1
  65. package/parallel.ts +0 -0
  66. package/templates/README.md +0 -0
  67. package/templates/licenses/Apache-2.0 +0 -0
  68. package/templates/licenses/Apache-2.0-NOTICE +0 -0
  69. package/templates/licenses/MIT +0 -0
  70. package/templates/mops-publish.yml +0 -0
  71. package/templates/mops-test.yml +0 -0
  72. package/templates/src/lib.mo +0 -0
  73. package/templates/test/lib.test.mo +0 -0
  74. package/.DS_Store +0 -0
  75. package/bundle/bench/bench-canister.mo +0 -87
  76. package/bundle/bench/user-bench.mo +0 -14
  77. package/bundle/bin/moc-wrapper.sh +0 -40
  78. package/bundle/bin/mops.js +0 -3
  79. package/bundle/cli.js +0 -163
  80. package/bundle/cli.tgz +0 -0
  81. package/bundle/declarations/bench/bench.did +0 -26
  82. package/bundle/declarations/bench/bench.did.d.ts +0 -29
  83. package/bundle/declarations/bench/bench.did.js +0 -26
  84. package/bundle/declarations/bench/index.d.ts +0 -50
  85. package/bundle/declarations/bench/index.js +0 -40
  86. package/bundle/declarations/main/index.d.ts +0 -50
  87. package/bundle/declarations/main/index.js +0 -40
  88. package/bundle/declarations/main/main.did +0 -438
  89. package/bundle/declarations/main/main.did.d.ts +0 -360
  90. package/bundle/declarations/main/main.did.js +0 -412
  91. package/bundle/declarations/storage/index.d.ts +0 -50
  92. package/bundle/declarations/storage/index.js +0 -30
  93. package/bundle/declarations/storage/storage.did +0 -46
  94. package/bundle/declarations/storage/storage.did.d.ts +0 -40
  95. package/bundle/declarations/storage/storage.did.js +0 -38
  96. package/bundle/package.json +0 -31
  97. package/bundle/templates/README.md +0 -13
  98. package/bundle/templates/licenses/Apache-2.0 +0 -202
  99. package/bundle/templates/licenses/Apache-2.0-NOTICE +0 -13
  100. package/bundle/templates/licenses/MIT +0 -21
  101. package/bundle/templates/mops-publish.yml +0 -17
  102. package/bundle/templates/mops-test.yml +0 -22
  103. package/bundle/templates/src/lib.mo +0 -15
  104. package/bundle/templates/test/lib.test.mo +0 -4
package/.eslintrc.json CHANGED
File without changes
package/.gitignore CHANGED
File without changes
package/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Mops CLI Changelog
2
2
 
3
3
  ## unreleased
4
+ - `mops cache clean` now cleans local cache too (`.mops` folder)
4
5
 
5
6
  ## 0.45.3
6
7
  - Fixed bug with missing `tar` package
package/README.md CHANGED
File without changes
package/api/actors.ts CHANGED
@@ -8,18 +8,34 @@ import {_SERVICE as _STORAGE_SERVICE} from '../declarations/storage/storage.did.
8
8
  import {getEndpoint} from './network.js';
9
9
  import {getNetwork} from './network.js';
10
10
 
11
- export let mainActor = async (identity ?: Identity) : Promise<_SERVICE> => {
12
- let network = getNetwork();
13
- let host = getEndpoint(network).host;
14
- let canisterId = getEndpoint(network).canisterId;
11
+ let agentPromiseByPrincipal = new Map <string, Promise<HttpAgent>>();
12
+
13
+ let getAgent = async (identity ?: Identity) : Promise<HttpAgent> => {
14
+ let principal = identity ? identity?.getPrincipal().toText() : '';
15
+ let agentPromise = agentPromiseByPrincipal.get(principal);
15
16
 
16
- // @ts-ignore exactOptionalPropertyTypes
17
- let agent = new HttpAgent({host, identity});
17
+ if (!agentPromise) {
18
+ let network = getNetwork();
19
+ let host = getEndpoint(network).host;
18
20
 
19
- if (network === 'local') {
20
- await agent.fetchRootKey();
21
+ agentPromise = HttpAgent.create({
22
+ host,
23
+ identity,
24
+ shouldFetchRootKey: network === 'local',
25
+ verifyQuerySignatures: process.env.MOPS_VERIFY_QUERY_SIGNATURES !== 'false',
26
+ });
27
+
28
+ agentPromiseByPrincipal.set(principal, agentPromise);
21
29
  }
22
30
 
31
+ return agentPromise;
32
+ };
33
+
34
+ export let mainActor = async (identity ?: Identity) : Promise<_SERVICE> => {
35
+ let agent = await getAgent(identity);
36
+ let network = getNetwork();
37
+ let canisterId = getEndpoint(network).canisterId;
38
+
23
39
  return Actor.createActor(idlFactory, {
24
40
  agent,
25
41
  canisterId,
@@ -27,15 +43,7 @@ export let mainActor = async (identity ?: Identity) : Promise<_SERVICE> => {
27
43
  };
28
44
 
29
45
  export let storageActor = async (storageId : Principal, identity ?: Identity) : Promise<_STORAGE_SERVICE> => {
30
- let network = getNetwork();
31
- let host = getEndpoint(network).host;
32
-
33
- // @ts-ignore exactOptionalPropertyTypes
34
- let agent = new HttpAgent({host, identity});
35
-
36
- if (network === 'local') {
37
- await agent.fetchRootKey();
38
- }
46
+ let agent = await getAgent(identity);
39
47
 
40
48
  return Actor.createActor(storageIdlFactory, {
41
49
  agent,
File without changes
File without changes
package/api/index.ts CHANGED
File without changes
package/api/network.ts CHANGED
File without changes
File without changes
package/cache.ts CHANGED
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import ncp from 'ncp';
4
4
  import getFolderSize from 'get-folder-size';
5
5
 
6
- import {getDependencyType, globalCacheDir, parseGithubURL} from './mops.js';
6
+ import {getDependencyType, getRootDir, globalCacheDir, parseGithubURL} from './mops.js';
7
7
  import {getPackageId} from './helpers/get-package-id.js';
8
8
 
9
9
  export let show = () => {
@@ -73,6 +73,13 @@ export let cacheSize = async () => {
73
73
  };
74
74
 
75
75
  export let cleanCache = async () => {
76
- let dir = path.join(globalCacheDir);
77
- fs.rmSync(dir, {recursive: true, force: true});
76
+ if (!globalCacheDir.endsWith('mops/cache') && !globalCacheDir.endsWith('/mops')) {
77
+ throw new Error('Invalid cache directory: ' + globalCacheDir);
78
+ }
79
+
80
+ // local cache
81
+ fs.rmSync(path.join(getRootDir(), '.mops'), {recursive: true, force: true});
82
+
83
+ // global cache
84
+ fs.rmSync(globalCacheDir, {recursive: true, force: true});
78
85
  };
File without changes
File without changes
package/commands/bump.ts CHANGED
File without changes
package/commands/docs.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
package/commands/sync.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/commands/user.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -3,28 +3,34 @@ import { idlFactory } from '../declarations/main/main.did.js';
3
3
  import { idlFactory as storageIdlFactory } from '../declarations/storage/storage.did.js';
4
4
  import { getEndpoint } from './network.js';
5
5
  import { getNetwork } from './network.js';
6
+ let agentPromiseByPrincipal = new Map();
7
+ let getAgent = async (identity) => {
8
+ let principal = identity ? identity?.getPrincipal().toText() : '';
9
+ let agentPromise = agentPromiseByPrincipal.get(principal);
10
+ if (!agentPromise) {
11
+ let network = getNetwork();
12
+ let host = getEndpoint(network).host;
13
+ agentPromise = HttpAgent.create({
14
+ host,
15
+ identity,
16
+ shouldFetchRootKey: network === 'local',
17
+ verifyQuerySignatures: process.env.MOPS_VERIFY_QUERY_SIGNATURES !== 'false',
18
+ });
19
+ agentPromiseByPrincipal.set(principal, agentPromise);
20
+ }
21
+ return agentPromise;
22
+ };
6
23
  export let mainActor = async (identity) => {
24
+ let agent = await getAgent(identity);
7
25
  let network = getNetwork();
8
- let host = getEndpoint(network).host;
9
26
  let canisterId = getEndpoint(network).canisterId;
10
- // @ts-ignore exactOptionalPropertyTypes
11
- let agent = new HttpAgent({ host, identity });
12
- if (network === 'local') {
13
- await agent.fetchRootKey();
14
- }
15
27
  return Actor.createActor(idlFactory, {
16
28
  agent,
17
29
  canisterId,
18
30
  });
19
31
  };
20
32
  export let storageActor = async (storageId, identity) => {
21
- let network = getNetwork();
22
- let host = getEndpoint(network).host;
23
- // @ts-ignore exactOptionalPropertyTypes
24
- let agent = new HttpAgent({ host, identity });
25
- if (network === 'local') {
26
- await agent.fetchRootKey();
27
- }
33
+ let agent = await getAgent(identity);
28
34
  return Actor.createActor(storageIdlFactory, {
29
35
  agent,
30
36
  canisterId: storageId,
package/dist/cache.js CHANGED
@@ -2,7 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import ncp from 'ncp';
4
4
  import getFolderSize from 'get-folder-size';
5
- import { getDependencyType, globalCacheDir, parseGithubURL } from './mops.js';
5
+ import { getDependencyType, getRootDir, globalCacheDir, parseGithubURL } from './mops.js';
6
6
  import { getPackageId } from './helpers/get-package-id.js';
7
7
  export let show = () => {
8
8
  return globalCacheDir;
@@ -59,6 +59,11 @@ export let cacheSize = async () => {
59
59
  return (size / 1024 / 1024).toFixed(2) + ' MB';
60
60
  };
61
61
  export let cleanCache = async () => {
62
- let dir = path.join(globalCacheDir);
63
- fs.rmSync(dir, { recursive: true, force: true });
62
+ if (!globalCacheDir.endsWith('mops/cache') && !globalCacheDir.endsWith('/mops')) {
63
+ throw new Error('Invalid cache directory: ' + globalCacheDir);
64
+ }
65
+ // local cache
66
+ fs.rmSync(path.join(getRootDir(), '.mops'), { recursive: true, force: true });
67
+ // global cache
68
+ fs.rmSync(globalCacheDir, { recursive: true, force: true });
64
69
  };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.45.3",
3
+ "version": "0.45.4-pre.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "bin/mops.js",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/global.d.ts CHANGED
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.45.3",
3
+ "version": "0.45.4-pre.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/bin/mops.js",
package/parallel.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/.DS_Store DELETED
Binary file
@@ -1,87 +0,0 @@
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
- };
@@ -1,14 +0,0 @@
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
- };
@@ -1,40 +0,0 @@
1
- #!/bin/bash
2
-
3
- # set -e
4
-
5
- findRootDir() {
6
- dir="$(pwd)"
7
- while [[ "$dir" != "" && ! -e "$dir/mops.toml" ]]; do
8
- dir=${dir%/*}
9
- done
10
- echo "$dir"
11
- }
12
-
13
- rootDir=$(findRootDir)
14
- mopsToml="$rootDir/mops.toml"
15
-
16
- if [[ $rootDir == "" ]] || [[ ! -f $mopsToml ]]; then
17
- mocPath="$(mops toolchain bin moc --fallback)"
18
- else
19
- if command -v openssl >/dev/null 2>&1; then
20
- mopsTomlHash=$(openssl sha256 $mopsToml | awk -F'= ' '{print $2}')
21
- else
22
- mopsTomlHash=$(shasum $mopsToml -a 256 | awk -F' ' '{print $1}')
23
- fi;
24
-
25
- cached="$rootDir/.mops/moc-$mopsTomlHash"
26
-
27
- if [ -f $cached ]; then
28
- mocPath=$(cat $cached)
29
- if [[ "$mocPath" != *"/moc" ]] ; then
30
- mocPath="$(mops toolchain bin moc --fallback)"
31
- echo -n $mocPath > "$cached"
32
- fi;
33
- else
34
- mkdir -p "$(dirname $cached)"
35
- mocPath="$(mops toolchain bin moc --fallback)"
36
- echo -n $mocPath > "$cached"
37
- fi;
38
- fi;
39
-
40
- $mocPath "$@"
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import '../cli.js';