mops icon indicating copy to clipboard operation
mops copied to clipboard

Mops inside web browser

Open infu opened this issue 2 years ago • 3 comments

I want to mops libraries in Blast, but importing this module probably wont work. You probably won't be making a browser client. All I need to know how to get its packages. I assume they are zipped and stored inside a canister somehow

infu avatar Nov 05 '23 09:11 infu

To search packages you can use main actor from ic-mops npm package.

Packages are not zipped, and can be downloaded. I can move files downloading logic to a separate function and expose it, would it be helpful? Let's say it will return mapping filename->source for a package.

ZenVoich avatar Nov 06 '23 13:11 ZenVoich

That will be very helpful yes.

infu avatar Nov 07 '23 11:11 infu

Implemented in mops 0.34.0

How to use:

  1. Add mops dependency:
npm i ic-mops
  1. Search and download:
import {mainActor, downloadPackageFiles} from 'ic-mops/api';

let mopsActor = await mainActor();

// search
let limit = 100n;
let searchText = 'ba';
let [packages, _pageCount] = await mopsActor.search(searchText, [limit], []);
console.log(packages.map((pkg) => {
	return pkg.config.name;
}));

// download
let files = await downloadPackageFiles('base');
// or with version
// let files = await downloadPackageFiles('base', '0.10.1');
for (let [filename, data] of files.entries()) {
	console.log(filename, new TextDecoder().decode(new Uint8Array(data)));
}

ZenVoich avatar Nov 14 '23 09:11 ZenVoich