ic-mops 0.19.1 → 0.20.1
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.
- package/.gitignore +3 -0
- package/{cache.js → cache.ts} +8 -8
- package/{cli.js → cli.ts} +5 -5
- package/commands/{add.js → add.ts} +16 -8
- package/commands/{bump.js → bump.ts} +5 -5
- package/commands/{docs.js → docs.ts} +10 -10
- package/commands/{import-identity.js → import-identity.ts} +7 -7
- package/commands/{init.js → init.ts} +20 -17
- package/commands/{install-all.js → install-all.ts} +1 -1
- package/commands/{install.js → install.ts} +11 -11
- package/commands/{mmf1.js → mmf1.ts} +20 -18
- package/commands/{publish.js → publish.ts} +29 -16
- package/commands/{remove.js → remove.ts} +23 -16
- package/commands/{search.js → search.ts} +2 -2
- package/commands/self-update.ts +6 -0
- package/commands/{sources.js → sources.ts} +30 -24
- package/commands/{template.js → template.ts} +2 -2
- package/commands/{test.js → test.ts} +24 -19
- package/commands/{user.js → user.ts} +7 -2
- package/declarations/main/index.js +0 -2
- package/declarations/main/main.did +4 -1
- package/declarations/main/main.did.d.ts +4 -4
- package/declarations/main/main.did.js +20 -20
- package/declarations/storage/index.d.ts +50 -0
- package/declarations/storage/index.js +3 -11
- package/dist/cache.d.ts +5 -0
- package/dist/cache.js +46 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +265 -0
- package/dist/commands/add.d.ts +4 -0
- package/dist/commands/add.js +82 -0
- package/dist/commands/bump.d.ts +1 -0
- package/dist/commands/bump.js +50 -0
- package/dist/commands/docs.d.ts +3 -0
- package/dist/commands/docs.js +78 -0
- package/dist/commands/import-identity.d.ts +1 -0
- package/dist/commands/import-identity.js +47 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +82 -0
- package/dist/commands/install-all.d.ts +4 -0
- package/dist/commands/install-all.js +29 -0
- package/dist/commands/install.d.ts +5 -0
- package/dist/commands/install.js +110 -0
- package/dist/commands/mmf1.d.ts +21 -0
- package/dist/commands/mmf1.js +93 -0
- package/dist/commands/publish.d.ts +3 -0
- package/dist/commands/publish.js +254 -0
- package/dist/commands/remove.d.ts +5 -0
- package/dist/commands/remove.js +83 -0
- package/dist/commands/search.d.ts +1 -0
- package/dist/commands/search.js +36 -0
- package/dist/commands/self-update.d.ts +3 -0
- package/dist/commands/self-update.js +5 -0
- package/dist/commands/sources.d.ts +3 -0
- package/dist/commands/sources.js +124 -0
- package/dist/commands/template.d.ts +1 -0
- package/dist/commands/template.js +28 -0
- package/dist/commands/test.d.ts +4 -0
- package/dist/commands/test.js +201 -0
- package/dist/commands/user.d.ts +2 -0
- package/dist/commands/user.js +23 -0
- package/dist/commands/whoami.d.ts +1 -0
- package/dist/commands/whoami.js +11 -0
- package/dist/declarations/main/index.d.ts +50 -0
- package/dist/declarations/main/index.js +41 -0
- package/dist/declarations/main/main.did +222 -0
- package/dist/declarations/main/main.did.d.ts +198 -0
- package/dist/declarations/main/main.did.js +218 -0
- package/dist/declarations/storage/index.d.ts +50 -0
- package/dist/declarations/storage/index.js +30 -0
- package/dist/declarations/storage/storage.did +46 -0
- package/dist/declarations/storage/storage.did.d.ts +37 -0
- package/dist/declarations/storage/storage.did.js +38 -0
- package/dist/mops.d.ts +33 -0
- package/dist/mops.js +259 -0
- package/dist/package.json +79 -0
- package/dist/parallel.d.ts +1 -0
- package/dist/parallel.js +24 -0
- package/dist/pem.d.ts +5 -0
- package/dist/pem.js +49 -0
- package/dist/templates/mops-test.yml +30 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.js +1 -0
- package/dist/vessel.d.ts +19 -0
- package/dist/vessel.js +154 -0
- package/global.d.ts +2 -0
- package/{mops.js → mops.ts} +56 -45
- package/package.json +44 -19
- package/{parallel.js → parallel.ts} +2 -2
- package/{pem.js → pem.ts} +12 -11
- package/templates/mops-test.yml +1 -1
- package/tsconfig.json +16 -0
- package/types.ts +29 -0
- package/{vessel.js → vessel.ts} +37 -25
- package/commands/self-update.js +0 -6
- /package/commands/{whoami.js → whoami.ts} +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import del from 'del';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import {deleteSync} from 'del';
|
|
4
3
|
import chalk from 'chalk';
|
|
5
|
-
import {formatDir, formatGithubDir} from '../mops.js';
|
|
4
|
+
import {formatDir, formatGithubDir, checkConfigFile, readConfig, writeConfig} from '../mops.js';
|
|
5
|
+
import {Config, Dependency} from '../types.js';
|
|
6
6
|
|
|
7
|
-
export async function remove(name, {dev, verbose, dryRun} = {}) {
|
|
7
|
+
export async function remove(name: string, {dev = false, verbose = false, dryRun = false} = {}) {
|
|
8
8
|
if (!checkConfigFile()) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function getTransitiveDependencies(config, exceptPkgId) {
|
|
12
|
+
function getTransitiveDependencies(config: Config, exceptPkgId: string) {
|
|
13
13
|
let deps = Object.values(config.dependencies || {});
|
|
14
14
|
let devDeps = Object.values(config['dev-dependencies'] || {});
|
|
15
15
|
return [...deps, ...devDeps]
|
|
@@ -21,15 +21,21 @@ export async function remove(name, {dev, verbose, dryRun} = {}) {
|
|
|
21
21
|
}).flat();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function getTransitiveDependenciesOf(name, version, repo) {
|
|
25
|
-
let pkgDir =
|
|
24
|
+
function getTransitiveDependenciesOf(name: string, version: string | undefined, repo?: string) {
|
|
25
|
+
let pkgDir = '';
|
|
26
|
+
if (repo) {
|
|
27
|
+
pkgDir = formatGithubDir(name, repo);
|
|
28
|
+
}
|
|
29
|
+
else if (version) {
|
|
30
|
+
pkgDir = formatDir(name, version);
|
|
31
|
+
}
|
|
26
32
|
let configFile = pkgDir + '/mops.toml';
|
|
27
33
|
if (!fs.existsSync(configFile)) {
|
|
28
34
|
verbose && console.log('no config', configFile);
|
|
29
35
|
return [];
|
|
30
36
|
}
|
|
31
37
|
let config = readConfig(configFile);
|
|
32
|
-
let deps = Object.values(config.dependencies || {}).map((dep) => {
|
|
38
|
+
let deps: Dependency[] = Object.values(config.dependencies || {}).map((dep) => {
|
|
33
39
|
return [dep, ...getTransitiveDependenciesOf(dep.name, dep.version)];
|
|
34
40
|
}).flat();
|
|
35
41
|
return deps;
|
|
@@ -37,6 +43,7 @@ export async function remove(name, {dev, verbose, dryRun} = {}) {
|
|
|
37
43
|
|
|
38
44
|
let config = readConfig();
|
|
39
45
|
let deps = dev ? config['dev-dependencies'] : config.dependencies;
|
|
46
|
+
deps = deps || {};
|
|
40
47
|
let pkgDetails = deps[name];
|
|
41
48
|
|
|
42
49
|
if (!pkgDetails) {
|
|
@@ -66,22 +73,22 @@ export async function remove(name, {dev, verbose, dryRun} = {}) {
|
|
|
66
73
|
if (dep.repo) {
|
|
67
74
|
pkgDir = formatGithubDir(dep.name, dep.repo);
|
|
68
75
|
}
|
|
69
|
-
else {
|
|
76
|
+
else if (dep.version) {
|
|
70
77
|
pkgDir = formatDir(dep.name, dep.version);
|
|
71
78
|
}
|
|
72
|
-
if (fs.existsSync(pkgDir)) {
|
|
73
|
-
dryRun ||
|
|
79
|
+
if (pkgDir && fs.existsSync(pkgDir)) {
|
|
80
|
+
dryRun || deleteSync([`${pkgDir}`]);
|
|
74
81
|
verbose && console.log(`Removed local cache ${pkgDir}`);
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
// remove from config
|
|
79
|
-
if (dev) {
|
|
80
|
-
delete config['dev-dependencies'][name];
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
86
|
+
if (!dev && config.dependencies) {
|
|
83
87
|
delete config.dependencies[name];
|
|
84
88
|
}
|
|
89
|
+
if (dev && config['dev-dependencies']) {
|
|
90
|
+
delete config['dev-dependencies'][name];
|
|
91
|
+
}
|
|
85
92
|
dryRun || writeConfig(config);
|
|
86
93
|
|
|
87
94
|
console.log(chalk.green('Package removed ') + `${name} = "${version}"`);
|
|
@@ -2,7 +2,7 @@ import asTable from 'as-table';
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import {mainActor} from '../mops.js';
|
|
4
4
|
|
|
5
|
-
export async function search(text) {
|
|
5
|
+
export async function search(text: string) {
|
|
6
6
|
let actor = await mainActor();
|
|
7
7
|
let res = await actor.search(text, [], []);
|
|
8
8
|
let packages = res[0];
|
|
@@ -12,7 +12,7 @@ export async function search(text) {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
let ellipsis = (text, max) => {
|
|
15
|
+
let ellipsis = (text: string, max: number) => {
|
|
16
16
|
if (text.length <= max) {
|
|
17
17
|
return text;
|
|
18
18
|
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import {checkConfigFile, formatDir, formatGithubDir, parseGithubURL, readConfig} from '../mops.js';
|
|
5
|
-
import {readVesselConfig} from '../vessel.js';
|
|
5
|
+
import {VesselConfig, readVesselConfig} from '../vessel.js';
|
|
6
|
+
import {Config, Dependency} from '../types.js';
|
|
6
7
|
|
|
7
8
|
// TODO: resolve conflicts
|
|
8
|
-
export async function sources({verbose} = {}) {
|
|
9
|
+
export async function sources({verbose = false} = {}) {
|
|
9
10
|
if (!checkConfigFile()) {
|
|
10
11
|
return [];
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
let packages = {};
|
|
14
|
-
let versions = {};
|
|
14
|
+
let packages: Record<string, Dependency & {isRoot: boolean}> = {};
|
|
15
|
+
let versions: Record<string, string[]> = {};
|
|
15
16
|
|
|
16
|
-
let compareVersions = (a, b) => {
|
|
17
|
-
let ap = a.split('.').map(x => x
|
|
18
|
-
let bp = b.split('.').map(x => x
|
|
17
|
+
let compareVersions = (a: string = '0.0.0', b: string = '0.0.0') => {
|
|
18
|
+
let ap = a.split('.').map((x: string) => parseInt(x)) as [number, number, number];
|
|
19
|
+
let bp = b.split('.').map((x: string) => parseInt(x)) as [number, number, number];
|
|
19
20
|
if (ap[0] - bp[0]) {
|
|
20
21
|
return Math.sign(ap[0] - bp[0]);
|
|
21
22
|
}
|
|
@@ -30,7 +31,7 @@ export async function sources({verbose} = {}) {
|
|
|
30
31
|
|
|
31
32
|
const gitVerRegex = new RegExp(/v(\d{1,2}\.\d{1,2}\.\d{1,2})(-.*)?$/);
|
|
32
33
|
|
|
33
|
-
const compareGitVersions = (repoA, repoB) => {
|
|
34
|
+
const compareGitVersions = (repoA: string, repoB: string) => {
|
|
34
35
|
const {branch: a} = parseGithubURL(repoA);
|
|
35
36
|
const {branch: b} = parseGithubURL(repoB);
|
|
36
37
|
|
|
@@ -45,7 +46,7 @@ export async function sources({verbose} = {}) {
|
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
let collectDeps = async (config, isRoot = false) => {
|
|
49
|
+
let collectDeps = async (config: Config | VesselConfig, isRoot = false) => {
|
|
49
50
|
let allDeps = [...Object.values(config.dependencies || {})];
|
|
50
51
|
if (isRoot) {
|
|
51
52
|
allDeps = [...allDeps, ...Object.values(config['dev-dependencies'] || {})];
|
|
@@ -57,13 +58,15 @@ export async function sources({verbose} = {}) {
|
|
|
57
58
|
if (
|
|
58
59
|
isRoot
|
|
59
60
|
|| !packages[name]
|
|
60
|
-
|| !packages[name]
|
|
61
|
+
|| !packages[name]?.isRoot
|
|
61
62
|
&& (
|
|
62
|
-
repo && packages[name]
|
|
63
|
-
|| compareVersions(packages[name]
|
|
63
|
+
repo && packages[name]?.repo && compareGitVersions(packages[name]?.repo || '', repo) === -1
|
|
64
|
+
|| compareVersions(packages[name]?.version, version) === -1)
|
|
64
65
|
) {
|
|
65
|
-
packages[name] =
|
|
66
|
-
|
|
66
|
+
packages[name] = {
|
|
67
|
+
...pkgDetails,
|
|
68
|
+
isRoot,
|
|
69
|
+
};
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
let nestedConfig;
|
|
@@ -72,12 +75,12 @@ export async function sources({verbose} = {}) {
|
|
|
72
75
|
const dir = formatGithubDir(name, repo);
|
|
73
76
|
nestedConfig = await readVesselConfig(dir) || {};
|
|
74
77
|
}
|
|
75
|
-
else if (!pkgDetails.path) {
|
|
76
|
-
const
|
|
77
|
-
nestedConfig = readConfig(
|
|
78
|
+
else if (!pkgDetails.path && version) {
|
|
79
|
+
const file = formatDir(name, version) + '/mops.toml';
|
|
80
|
+
nestedConfig = readConfig(file);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
if (!pkgDetails.path) {
|
|
83
|
+
if (nestedConfig && !pkgDetails.path) {
|
|
81
84
|
await collectDeps(nestedConfig);
|
|
82
85
|
}
|
|
83
86
|
|
|
@@ -87,10 +90,10 @@ export async function sources({verbose} = {}) {
|
|
|
87
90
|
|
|
88
91
|
if (repo) {
|
|
89
92
|
const {branch} = parseGithubURL(repo);
|
|
90
|
-
versions[name]
|
|
93
|
+
versions[name]?.push(branch);
|
|
91
94
|
}
|
|
92
|
-
else {
|
|
93
|
-
versions[name]
|
|
95
|
+
else if (version) {
|
|
96
|
+
versions[name]?.push(version);
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
};
|
|
@@ -117,9 +120,12 @@ export async function sources({verbose} = {}) {
|
|
|
117
120
|
else if (pkg.repo) {
|
|
118
121
|
pkgDir = path.relative(process.cwd(), formatGithubDir(name, pkg.repo));
|
|
119
122
|
}
|
|
120
|
-
else {
|
|
123
|
+
else if (pkg.version) {
|
|
121
124
|
pkgDir = path.relative(process.cwd(), formatDir(name, pkg.version));
|
|
122
125
|
}
|
|
126
|
+
else {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
123
129
|
|
|
124
130
|
// append baseDir
|
|
125
131
|
let pkgBaseDir;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {spawn, execSync} from 'child_process';
|
|
1
|
+
import {spawn, execSync, ChildProcessWithoutNullStreams} from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
2
5
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
6
|
+
import {globSync} from 'glob';
|
|
4
7
|
import chokidar from 'chokidar';
|
|
5
8
|
import debounce from 'debounce';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import fs from 'fs';
|
|
8
|
-
import os from 'os';
|
|
9
9
|
|
|
10
10
|
import {MMF1} from './mmf1.js';
|
|
11
11
|
import {sources} from './sources.js';
|
|
@@ -65,9 +65,9 @@ let mocPath = process.env.DFX_MOC_PATH;
|
|
|
65
65
|
export async function runAll(filter = '') {
|
|
66
66
|
let start = Date.now();
|
|
67
67
|
let rootDir = getRootDir();
|
|
68
|
-
let files = [];
|
|
69
|
-
let libFiles =
|
|
70
|
-
if (libFiles
|
|
68
|
+
let files: string[] = [];
|
|
69
|
+
let libFiles = globSync('**/test?(s)/lib.mo', globConfig);
|
|
70
|
+
if (libFiles[0]) {
|
|
71
71
|
files = [libFiles[0]];
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
@@ -75,7 +75,7 @@ export async function runAll(filter = '') {
|
|
|
75
75
|
if (filter) {
|
|
76
76
|
globStr = `**/test?(s)/**/*${filter}*.mo`;
|
|
77
77
|
}
|
|
78
|
-
files =
|
|
78
|
+
files = globSync(path.join(rootDir, globStr), globConfig);
|
|
79
79
|
}
|
|
80
80
|
if (!files.length) {
|
|
81
81
|
if (filter) {
|
|
@@ -107,7 +107,11 @@ export async function runAll(filter = '') {
|
|
|
107
107
|
|
|
108
108
|
let i = 0;
|
|
109
109
|
|
|
110
|
-
await parallel(os.cpus().length, files, async (file) => {
|
|
110
|
+
await parallel(os.cpus().length, files, async (file: string) => {
|
|
111
|
+
if (!mocPath) {
|
|
112
|
+
mocPath = 'moc';
|
|
113
|
+
}
|
|
114
|
+
|
|
111
115
|
let mmf = new MMF1('store');
|
|
112
116
|
|
|
113
117
|
let wasiMode = fs.readFileSync(file, 'utf8').startsWith('// @testmode wasi');
|
|
@@ -165,12 +169,12 @@ export async function runAll(filter = '') {
|
|
|
165
169
|
return failed === 0;
|
|
166
170
|
}
|
|
167
171
|
|
|
168
|
-
function absToRel(p) {
|
|
172
|
+
function absToRel(p: string) {
|
|
169
173
|
let rootDir = getRootDir();
|
|
170
174
|
return path.relative(rootDir, path.resolve(p));
|
|
171
175
|
}
|
|
172
176
|
|
|
173
|
-
function pipeMMF(proc, mmf) {
|
|
177
|
+
function pipeMMF(proc: ChildProcessWithoutNullStreams, mmf: MMF1) {
|
|
174
178
|
return new Promise((resolve) => {
|
|
175
179
|
// stdout
|
|
176
180
|
proc.stdout.on('data', (data) => {
|
|
@@ -184,9 +188,9 @@ function pipeMMF(proc, mmf) {
|
|
|
184
188
|
|
|
185
189
|
// stderr
|
|
186
190
|
proc.stderr.on('data', (data) => {
|
|
187
|
-
let text = data.toString().trim();
|
|
191
|
+
let text: string = data.toString().trim();
|
|
188
192
|
let failedLine = '';
|
|
189
|
-
text = text.replace(/([\w+._/-]+):(\d+).(\d+)(-\d+.\d+)/g, (
|
|
193
|
+
text = text.replace(/([\w+._/-]+):(\d+).(\d+)(-\d+.\d+)/g, (_m0, m1: string, m2: string, m3: string) => {
|
|
190
194
|
// change absolute file path to relative
|
|
191
195
|
// change :line:col-line:col to :line:col to work in vscode
|
|
192
196
|
let res = `${absToRel(m1)}:${m2}:${m3}`;
|
|
@@ -197,14 +201,15 @@ function pipeMMF(proc, mmf) {
|
|
|
197
201
|
|
|
198
202
|
// show failed line
|
|
199
203
|
let content = fs.readFileSync(m1);
|
|
200
|
-
let lines = content.toString().split('\n');
|
|
204
|
+
let lines = content.toString().split('\n') || [];
|
|
201
205
|
failedLine += chalk.dim`\n ...`;
|
|
202
|
-
|
|
203
|
-
|
|
206
|
+
let lineBefore = lines[+m2 - 2];
|
|
207
|
+
if (lineBefore) {
|
|
208
|
+
failedLine += chalk.dim`\n ${+m2 - 1}\t| ${lineBefore.replaceAll('\t', ' ')}`;
|
|
204
209
|
}
|
|
205
|
-
failedLine += `\n${chalk.redBright`->`} ${m2}\t| ${lines[m2 - 1]
|
|
210
|
+
failedLine += `\n${chalk.redBright`->`} ${m2}\t| ${lines[+m2 - 1]?.replaceAll('\t', ' ')}`;
|
|
206
211
|
if (lines.length > +m2) {
|
|
207
|
-
failedLine += chalk.dim`\n ${+m2 + 1}\t| ${lines[m2]
|
|
212
|
+
failedLine += chalk.dim`\n ${+m2 + 1}\t| ${lines[+m2]?.replaceAll('\t', ' ')}`;
|
|
208
213
|
}
|
|
209
214
|
failedLine += chalk.dim`\n ...`;
|
|
210
215
|
return res;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import {getIdentity, mainActor} from '../mops.js';
|
|
3
3
|
|
|
4
|
-
export async function getUserProp(prop) {
|
|
4
|
+
export async function getUserProp(prop: string) {
|
|
5
5
|
let actor = await mainActor();
|
|
6
6
|
let identity = await getIdentity();
|
|
7
|
+
if (!identity) {
|
|
8
|
+
console.log(chalk.red('Error: ') + 'No identity found');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
7
11
|
let res = await actor.getUser(identity.getPrincipal());
|
|
12
|
+
// @ts-ignore
|
|
8
13
|
console.log(res[0]?.[prop] || '');
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
export async function setUserProp(prop, value) {
|
|
16
|
+
export async function setUserProp(prop: string, value: string) {
|
|
12
17
|
let actor = await mainActor(true);
|
|
13
18
|
let res = await actor.setUserProp(prop, value);
|
|
14
19
|
if ('ok' in res) {
|
|
@@ -185,7 +185,6 @@ service : {
|
|
|
185
185
|
finishPublish: (PublishingId) -> (Result);
|
|
186
186
|
getAirdropAmount: () -> (nat) query;
|
|
187
187
|
getAirdropAmountAll: () -> (nat) query;
|
|
188
|
-
getAllPackages: (nat, nat) -> (vec PackageSummary, PageCount) query;
|
|
189
188
|
getApiVersion: () -> (Text) query;
|
|
190
189
|
getDefaultPackages: (text) -> (vec record {
|
|
191
190
|
PackageName__1;
|
|
@@ -201,6 +200,10 @@ service : {
|
|
|
201
200
|
getMostDownloadedPackagesIn7Days: () -> (vec PackageSummary) query;
|
|
202
201
|
getNewPackages: () -> (vec PackageSummary) query;
|
|
203
202
|
getPackageDetails: (PackageName__1, Ver) -> (Result_4) query;
|
|
203
|
+
getPackagesByCategory: () -> (vec record {
|
|
204
|
+
text;
|
|
205
|
+
vec PackageSummary;
|
|
206
|
+
}) query;
|
|
204
207
|
getRecentlyUpdatedPackages: () -> (vec PackageSummary) query;
|
|
205
208
|
getStoragesStats: () -> (vec record {
|
|
206
209
|
StorageId;
|
|
@@ -151,10 +151,6 @@ export interface _SERVICE {
|
|
|
151
151
|
'finishPublish' : ActorMethod<[PublishingId], Result>,
|
|
152
152
|
'getAirdropAmount' : ActorMethod<[], bigint>,
|
|
153
153
|
'getAirdropAmountAll' : ActorMethod<[], bigint>,
|
|
154
|
-
'getAllPackages' : ActorMethod<
|
|
155
|
-
[bigint, bigint],
|
|
156
|
-
[Array<PackageSummary>, PageCount]
|
|
157
|
-
>,
|
|
158
154
|
'getApiVersion' : ActorMethod<[], Text>,
|
|
159
155
|
'getDefaultPackages' : ActorMethod<
|
|
160
156
|
[string],
|
|
@@ -174,6 +170,10 @@ export interface _SERVICE {
|
|
|
174
170
|
'getMostDownloadedPackagesIn7Days' : ActorMethod<[], Array<PackageSummary>>,
|
|
175
171
|
'getNewPackages' : ActorMethod<[], Array<PackageSummary>>,
|
|
176
172
|
'getPackageDetails' : ActorMethod<[PackageName__1, Ver], Result_4>,
|
|
173
|
+
'getPackagesByCategory' : ActorMethod<
|
|
174
|
+
[],
|
|
175
|
+
Array<[string, Array<PackageSummary>]>
|
|
176
|
+
>,
|
|
177
177
|
'getRecentlyUpdatedPackages' : ActorMethod<[], Array<PackageSummary>>,
|
|
178
178
|
'getStoragesStats' : ActorMethod<[], Array<[StorageId, StorageStats]>>,
|
|
179
179
|
'getTotalDownloads' : ActorMethod<[], bigint>,
|
|
@@ -2,6 +2,20 @@ export const idlFactory = ({ IDL }) => {
|
|
|
2
2
|
const PublishingId = IDL.Text;
|
|
3
3
|
const Err = IDL.Text;
|
|
4
4
|
const Result = IDL.Variant({ 'ok' : IDL.Null, 'err' : Err });
|
|
5
|
+
const Text = IDL.Text;
|
|
6
|
+
const PackageName__1 = IDL.Text;
|
|
7
|
+
const Version = IDL.Text;
|
|
8
|
+
const PackageId = IDL.Text;
|
|
9
|
+
const Time = IDL.Int;
|
|
10
|
+
const DownloadsSnapshot__1 = IDL.Record({
|
|
11
|
+
'startTime' : Time,
|
|
12
|
+
'endTime' : Time,
|
|
13
|
+
'downloads' : IDL.Nat,
|
|
14
|
+
});
|
|
15
|
+
const Ver = IDL.Text;
|
|
16
|
+
const FileId = IDL.Text;
|
|
17
|
+
const Result_6 = IDL.Variant({ 'ok' : IDL.Vec(FileId), 'err' : Err });
|
|
18
|
+
const Result_5 = IDL.Variant({ 'ok' : Ver, 'err' : Err });
|
|
5
19
|
const User = IDL.Record({
|
|
6
20
|
'id' : IDL.Principal,
|
|
7
21
|
'emailVerified' : IDL.Bool,
|
|
@@ -39,7 +53,6 @@ export const idlFactory = ({ IDL }) => {
|
|
|
39
53
|
'license' : IDL.Text,
|
|
40
54
|
'readme' : IDL.Text,
|
|
41
55
|
});
|
|
42
|
-
const Time = IDL.Int;
|
|
43
56
|
const PackagePublication = IDL.Record({
|
|
44
57
|
'storage' : IDL.Principal,
|
|
45
58
|
'time' : Time,
|
|
@@ -54,20 +67,6 @@ export const idlFactory = ({ IDL }) => {
|
|
|
54
67
|
'config' : PackageConfigV2__1,
|
|
55
68
|
'publication' : PackagePublication,
|
|
56
69
|
});
|
|
57
|
-
const PageCount = IDL.Nat;
|
|
58
|
-
const Text = IDL.Text;
|
|
59
|
-
const PackageName__1 = IDL.Text;
|
|
60
|
-
const Version = IDL.Text;
|
|
61
|
-
const PackageId = IDL.Text;
|
|
62
|
-
const DownloadsSnapshot__1 = IDL.Record({
|
|
63
|
-
'startTime' : Time,
|
|
64
|
-
'endTime' : Time,
|
|
65
|
-
'downloads' : IDL.Nat,
|
|
66
|
-
});
|
|
67
|
-
const Ver = IDL.Text;
|
|
68
|
-
const FileId = IDL.Text;
|
|
69
|
-
const Result_6 = IDL.Variant({ 'ok' : IDL.Vec(FileId), 'err' : Err });
|
|
70
|
-
const Result_5 = IDL.Variant({ 'ok' : Ver, 'err' : Err });
|
|
71
70
|
const PackageSummary__1 = IDL.Record({
|
|
72
71
|
'ownerInfo' : User,
|
|
73
72
|
'owner' : IDL.Principal,
|
|
@@ -115,6 +114,7 @@ export const idlFactory = ({ IDL }) => {
|
|
|
115
114
|
'githubVerified' : IDL.Bool,
|
|
116
115
|
'github' : IDL.Text,
|
|
117
116
|
});
|
|
117
|
+
const PageCount = IDL.Nat;
|
|
118
118
|
const Result_3 = IDL.Variant({ 'ok' : IDL.Null, 'err' : IDL.Text });
|
|
119
119
|
const Result_2 = IDL.Variant({ 'ok' : FileId, 'err' : Err });
|
|
120
120
|
const PackageConfigV2 = IDL.Record({
|
|
@@ -142,11 +142,6 @@ export const idlFactory = ({ IDL }) => {
|
|
|
142
142
|
'finishPublish' : IDL.Func([PublishingId], [Result], []),
|
|
143
143
|
'getAirdropAmount' : IDL.Func([], [IDL.Nat], ['query']),
|
|
144
144
|
'getAirdropAmountAll' : IDL.Func([], [IDL.Nat], ['query']),
|
|
145
|
-
'getAllPackages' : IDL.Func(
|
|
146
|
-
[IDL.Nat, IDL.Nat],
|
|
147
|
-
[IDL.Vec(PackageSummary), PageCount],
|
|
148
|
-
['query'],
|
|
149
|
-
),
|
|
150
145
|
'getApiVersion' : IDL.Func([], [Text], ['query']),
|
|
151
146
|
'getDefaultPackages' : IDL.Func(
|
|
152
147
|
[IDL.Text],
|
|
@@ -181,6 +176,11 @@ export const idlFactory = ({ IDL }) => {
|
|
|
181
176
|
[Result_4],
|
|
182
177
|
['query'],
|
|
183
178
|
),
|
|
179
|
+
'getPackagesByCategory' : IDL.Func(
|
|
180
|
+
[],
|
|
181
|
+
[IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(PackageSummary)))],
|
|
182
|
+
['query'],
|
|
183
|
+
),
|
|
184
184
|
'getRecentlyUpdatedPackages' : IDL.Func(
|
|
185
185
|
[],
|
|
186
186
|
[IDL.Vec(PackageSummary)],
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ActorSubclass,
|
|
3
|
+
HttpAgentOptions,
|
|
4
|
+
ActorConfig,
|
|
5
|
+
Agent,
|
|
6
|
+
} from "@dfinity/agent";
|
|
7
|
+
import type { Principal } from "@dfinity/principal";
|
|
8
|
+
import type { IDL } from "@dfinity/candid";
|
|
9
|
+
|
|
10
|
+
import { _SERVICE } from './storage.did';
|
|
11
|
+
|
|
12
|
+
export declare const idlFactory: IDL.InterfaceFactory;
|
|
13
|
+
export declare const canisterId: string;
|
|
14
|
+
|
|
15
|
+
export declare interface CreateActorOptions {
|
|
16
|
+
/**
|
|
17
|
+
* @see {@link Agent}
|
|
18
|
+
*/
|
|
19
|
+
agent?: Agent;
|
|
20
|
+
/**
|
|
21
|
+
* @see {@link HttpAgentOptions}
|
|
22
|
+
*/
|
|
23
|
+
agentOptions?: HttpAgentOptions;
|
|
24
|
+
/**
|
|
25
|
+
* @see {@link ActorConfig}
|
|
26
|
+
*/
|
|
27
|
+
actorOptions?: ActorConfig;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister.
|
|
32
|
+
* @constructs {@link ActorSubClass}
|
|
33
|
+
* @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to
|
|
34
|
+
* @param {CreateActorOptions} options - see {@link CreateActorOptions}
|
|
35
|
+
* @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions
|
|
36
|
+
* @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent
|
|
37
|
+
* @see {@link HttpAgentOptions}
|
|
38
|
+
* @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor
|
|
39
|
+
* @see {@link ActorConfig}
|
|
40
|
+
*/
|
|
41
|
+
export declare const createActor: (
|
|
42
|
+
canisterId: string | Principal,
|
|
43
|
+
options?: CreateActorOptions
|
|
44
|
+
) => ActorSubclass<_SERVICE>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Intialized Actor using default settings, ready to talk to a canister using its candid interface
|
|
48
|
+
* @constructs {@link ActorSubClass}
|
|
49
|
+
*/
|
|
50
|
+
export declare const storage: ActorSubclass<_SERVICE>;
|
|
@@ -3,18 +3,16 @@ import { Actor, HttpAgent } from "@dfinity/agent";
|
|
|
3
3
|
// Imports and re-exports candid interface
|
|
4
4
|
import { idlFactory } from './storage.did.js';
|
|
5
5
|
export { idlFactory } from './storage.did.js';
|
|
6
|
-
// CANISTER_ID is replaced by webpack based on node environment
|
|
7
|
-
export const canisterId = process.env.STORAGE_CANISTER_ID;
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
|
-
*
|
|
8
|
+
*
|
|
11
9
|
* @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
|
|
12
10
|
* @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig}} [options]
|
|
13
11
|
* @return {import("@dfinity/agent").ActorSubclass<import("./storage.did.js")._SERVICE>}
|
|
14
12
|
*/
|
|
15
13
|
export const createActor = (canisterId, options) => {
|
|
16
14
|
const agent = new HttpAgent({ ...options?.agentOptions });
|
|
17
|
-
|
|
15
|
+
|
|
18
16
|
// Fetch root key for certificate validation during development
|
|
19
17
|
if(process.env.NODE_ENV !== "production") {
|
|
20
18
|
agent.fetchRootKey().catch(err=>{
|
|
@@ -29,10 +27,4 @@ export const canisterId = process.env.STORAGE_CANISTER_ID;
|
|
|
29
27
|
canisterId,
|
|
30
28
|
...options?.actorOptions,
|
|
31
29
|
});
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* A ready-to-use agent for the storage canister
|
|
36
|
-
* @type {import("@dfinity/agent").ActorSubclass<import("./storage.did.js")._SERVICE>}
|
|
37
|
-
*/
|
|
38
|
-
export const storage = createActor(canisterId);
|
|
30
|
+
};
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare let isCached: (pkgId: string) => boolean;
|
|
2
|
+
export declare let addCache: (pkgId: string, source: string) => Promise<void>;
|
|
3
|
+
export declare let copyCache: (pkgId: string, dest: string) => Promise<void>;
|
|
4
|
+
export declare let cacheSize: () => Promise<string>;
|
|
5
|
+
export declare let cleanCache: () => Promise<void>;
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import ncp from 'ncp';
|
|
4
|
+
import getFolderSize from 'get-folder-size';
|
|
5
|
+
import { globalCacheDir } from './mops.js';
|
|
6
|
+
export let isCached = (pkgId) => {
|
|
7
|
+
let dir = path.join(globalCacheDir, 'packages', pkgId);
|
|
8
|
+
return fs.existsSync(dir);
|
|
9
|
+
};
|
|
10
|
+
export let addCache = (pkgId, source) => {
|
|
11
|
+
let dest = path.join(globalCacheDir, 'packages', pkgId);
|
|
12
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
ncp.ncp(source, dest, { stopOnErr: true }, (err) => {
|
|
15
|
+
if (err) {
|
|
16
|
+
reject(err);
|
|
17
|
+
}
|
|
18
|
+
resolve();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
export let copyCache = (pkgId, dest) => {
|
|
23
|
+
let source = path.join(globalCacheDir, 'packages', pkgId);
|
|
24
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
ncp.ncp(source, dest, { stopOnErr: true }, (err) => {
|
|
27
|
+
if (err) {
|
|
28
|
+
reject(err);
|
|
29
|
+
}
|
|
30
|
+
resolve();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export let cacheSize = async () => {
|
|
35
|
+
let dir = path.join(globalCacheDir, 'packages');
|
|
36
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
37
|
+
let size = await getFolderSize.strict(dir);
|
|
38
|
+
if (size < 1024 * 1024) {
|
|
39
|
+
return (size / 1024).toFixed(2) + ' KB';
|
|
40
|
+
}
|
|
41
|
+
return (size / 1024 / 1024).toFixed(2) + ' MB';
|
|
42
|
+
};
|
|
43
|
+
export let cleanCache = async () => {
|
|
44
|
+
let dir = path.join(globalCacheDir, 'packages');
|
|
45
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
46
|
+
};
|
package/dist/cli.d.ts
ADDED