ic-mops 0.18.2 → 0.19.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.
@@ -3,13 +3,13 @@ import chalk from 'chalk';
3
3
  import path from 'path';
4
4
  import prompts from 'prompts';
5
5
  import del from 'del';
6
- import {globalCacheDir} from '../mops.js';
6
+ import {globalConfigDir} from '../mops.js';
7
7
  import {encrypt} from '../pem.js';
8
8
 
9
9
  export async function importPem(data) {
10
10
  try {
11
- if (!fs.existsSync(globalCacheDir)) {
12
- fs.mkdirSync(globalCacheDir);
11
+ if (!fs.existsSync(globalConfigDir)) {
12
+ fs.mkdirSync(globalConfigDir);
13
13
  }
14
14
 
15
15
  let res = await prompts({
@@ -31,8 +31,8 @@ export async function importPem(data) {
31
31
  }
32
32
  }
33
33
 
34
- let identityPem = path.resolve(globalCacheDir, 'identity.pem');
35
- let identityPemEncrypted = path.resolve(globalCacheDir, 'identity.pem.encrypted');
34
+ let identityPem = path.resolve(globalConfigDir, 'identity.pem');
35
+ let identityPemEncrypted = path.resolve(globalConfigDir, 'identity.pem.encrypted');
36
36
 
37
37
  del.sync([identityPem, identityPemEncrypted], {force: true});
38
38
 
@@ -4,9 +4,10 @@ import {mainActor} from '../mops.js';
4
4
 
5
5
  export async function search(text) {
6
6
  let actor = await mainActor();
7
- let res = await actor.search(text);
7
+ let res = await actor.search(text, [], []);
8
+ let packages = res[0];
8
9
 
9
- if (!res.length) {
10
+ if (!packages.length) {
10
11
  console.log('Packages not found');
11
12
  return;
12
13
  }
@@ -20,9 +21,9 @@ export async function search(text) {
20
21
  }
21
22
  };
22
23
 
23
- let maxNameLength = Math.max(...res.map(a => a.config.name.length));
24
+ let maxNameLength = Math.max(...packages.map(a => a.config.name.length));
24
25
 
25
- let table = res.map((item) => {
26
+ let table = packages.map((item) => {
26
27
  return {
27
28
  NAME: chalk.bold(item.config.name),
28
29
  DESCRIPTION: ellipsis(item.config.description, process.stdout.columns - 40 - maxNameLength),
@@ -77,6 +77,7 @@ type Result =
77
77
  };
78
78
  type PublishingId = text;
79
79
  type PublishingErr = text;
80
+ type PageCount = nat;
80
81
  type PackageSummary__1 =
81
82
  record {
82
83
  config: PackageConfigV2__1;
@@ -184,6 +185,7 @@ service : {
184
185
  finishPublish: (PublishingId) -> (Result);
185
186
  getAirdropAmount: () -> (nat) query;
186
187
  getAirdropAmountAll: () -> (nat) query;
188
+ getAllPackages: (nat, nat) -> (vec PackageSummary, PageCount) query;
187
189
  getApiVersion: () -> (Text) query;
188
190
  getDefaultPackages: (text) -> (vec record {
189
191
  PackageName__1;
@@ -197,6 +199,7 @@ service : {
197
199
  getHighestVersion: (PackageName__1) -> (Result_5) query;
198
200
  getMostDownloadedPackages: () -> (vec PackageSummary) query;
199
201
  getMostDownloadedPackagesIn7Days: () -> (vec PackageSummary) query;
202
+ getNewPackages: () -> (vec PackageSummary) query;
200
203
  getPackageDetails: (PackageName__1, Ver) -> (Result_4) query;
201
204
  getRecentlyUpdatedPackages: () -> (vec PackageSummary) query;
202
205
  getStoragesStats: () -> (vec record {
@@ -207,7 +210,7 @@ service : {
207
210
  getTotalPackages: () -> (nat) query;
208
211
  getUser: (principal) -> (opt User__1) query;
209
212
  notifyInstall: (PackageName__1, Ver) -> () oneway;
210
- search: (Text) -> (vec PackageSummary) query;
213
+ search: (Text, opt nat, opt nat) -> (vec PackageSummary, PageCount) query;
211
214
  setUserProp: (text, text) -> (Result_3);
212
215
  startFileUpload: (PublishingId, Text, nat, blob) -> (Result_2);
213
216
  startPublish: (PackageConfigV2) -> (Result_1);
@@ -94,6 +94,7 @@ export interface PackageSummary__1 {
94
94
  'config' : PackageConfigV2__1,
95
95
  'publication' : PackagePublication,
96
96
  }
97
+ export type PageCount = bigint;
97
98
  export type PublishingErr = string;
98
99
  export type PublishingId = string;
99
100
  export type Result = { 'ok' : null } |
@@ -150,6 +151,10 @@ export interface _SERVICE {
150
151
  'finishPublish' : ActorMethod<[PublishingId], Result>,
151
152
  'getAirdropAmount' : ActorMethod<[], bigint>,
152
153
  'getAirdropAmountAll' : ActorMethod<[], bigint>,
154
+ 'getAllPackages' : ActorMethod<
155
+ [bigint, bigint],
156
+ [Array<PackageSummary>, PageCount]
157
+ >,
153
158
  'getApiVersion' : ActorMethod<[], Text>,
154
159
  'getDefaultPackages' : ActorMethod<
155
160
  [string],
@@ -167,6 +172,7 @@ export interface _SERVICE {
167
172
  'getHighestVersion' : ActorMethod<[PackageName__1], Result_5>,
168
173
  'getMostDownloadedPackages' : ActorMethod<[], Array<PackageSummary>>,
169
174
  'getMostDownloadedPackagesIn7Days' : ActorMethod<[], Array<PackageSummary>>,
175
+ 'getNewPackages' : ActorMethod<[], Array<PackageSummary>>,
170
176
  'getPackageDetails' : ActorMethod<[PackageName__1, Ver], Result_4>,
171
177
  'getRecentlyUpdatedPackages' : ActorMethod<[], Array<PackageSummary>>,
172
178
  'getStoragesStats' : ActorMethod<[], Array<[StorageId, StorageStats]>>,
@@ -174,7 +180,10 @@ export interface _SERVICE {
174
180
  'getTotalPackages' : ActorMethod<[], bigint>,
175
181
  'getUser' : ActorMethod<[Principal], [] | [User__1]>,
176
182
  'notifyInstall' : ActorMethod<[PackageName__1, Ver], undefined>,
177
- 'search' : ActorMethod<[Text], Array<PackageSummary>>,
183
+ 'search' : ActorMethod<
184
+ [Text, [] | [bigint], [] | [bigint]],
185
+ [Array<PackageSummary>, PageCount]
186
+ >,
178
187
  'setUserProp' : ActorMethod<[string, string], Result_3>,
179
188
  'startFileUpload' : ActorMethod<
180
189
  [PublishingId, Text, bigint, Uint8Array | number[]],
@@ -2,20 +2,6 @@ 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 });
19
5
  const User = IDL.Record({
20
6
  'id' : IDL.Principal,
21
7
  'emailVerified' : IDL.Bool,
@@ -53,6 +39,7 @@ export const idlFactory = ({ IDL }) => {
53
39
  'license' : IDL.Text,
54
40
  'readme' : IDL.Text,
55
41
  });
42
+ const Time = IDL.Int;
56
43
  const PackagePublication = IDL.Record({
57
44
  'storage' : IDL.Principal,
58
45
  'time' : Time,
@@ -67,6 +54,20 @@ export const idlFactory = ({ IDL }) => {
67
54
  'config' : PackageConfigV2__1,
68
55
  'publication' : PackagePublication,
69
56
  });
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 });
70
71
  const PackageSummary__1 = IDL.Record({
71
72
  'ownerInfo' : User,
72
73
  'owner' : IDL.Principal,
@@ -141,6 +142,11 @@ export const idlFactory = ({ IDL }) => {
141
142
  'finishPublish' : IDL.Func([PublishingId], [Result], []),
142
143
  'getAirdropAmount' : IDL.Func([], [IDL.Nat], ['query']),
143
144
  'getAirdropAmountAll' : IDL.Func([], [IDL.Nat], ['query']),
145
+ 'getAllPackages' : IDL.Func(
146
+ [IDL.Nat, IDL.Nat],
147
+ [IDL.Vec(PackageSummary), PageCount],
148
+ ['query'],
149
+ ),
144
150
  'getApiVersion' : IDL.Func([], [Text], ['query']),
145
151
  'getDefaultPackages' : IDL.Func(
146
152
  [IDL.Text],
@@ -169,6 +175,7 @@ export const idlFactory = ({ IDL }) => {
169
175
  [IDL.Vec(PackageSummary)],
170
176
  ['query'],
171
177
  ),
178
+ 'getNewPackages' : IDL.Func([], [IDL.Vec(PackageSummary)], ['query']),
172
179
  'getPackageDetails' : IDL.Func(
173
180
  [PackageName__1, Ver],
174
181
  [Result_4],
@@ -188,7 +195,11 @@ export const idlFactory = ({ IDL }) => {
188
195
  'getTotalPackages' : IDL.Func([], [IDL.Nat], ['query']),
189
196
  'getUser' : IDL.Func([IDL.Principal], [IDL.Opt(User__1)], ['query']),
190
197
  'notifyInstall' : IDL.Func([PackageName__1, Ver], [], ['oneway']),
191
- 'search' : IDL.Func([Text], [IDL.Vec(PackageSummary)], ['query']),
198
+ 'search' : IDL.Func(
199
+ [Text, IDL.Opt(IDL.Nat), IDL.Opt(IDL.Nat)],
200
+ [IDL.Vec(PackageSummary), PageCount],
201
+ ['query'],
202
+ ),
192
203
  'setUserProp' : IDL.Func([IDL.Text, IDL.Text], [Result_3], []),
193
204
  'startFileUpload' : IDL.Func(
194
205
  [PublishingId, Text, IDL.Nat, IDL.Vec(IDL.Nat8)],
package/mops.js CHANGED
@@ -5,6 +5,7 @@ import fetch from 'node-fetch';
5
5
  import path from 'path';
6
6
  import fs from 'fs';
7
7
  import prompts from 'prompts';
8
+ import ncp from 'ncp';
8
9
 
9
10
  import {idlFactory} from './declarations/main/main.did.js';
10
11
  import {idlFactory as storageIdlFactory} from './declarations/storage/storage.did.js';
@@ -18,7 +19,57 @@ export let apiVersion = '1.2';
18
19
 
19
20
  let networkFile = new URL('./network.txt', import.meta.url);
20
21
 
21
- export let globalCacheDir = path.resolve(process.env.HOME || process.env.APPDATA, 'mops');
22
+ export let globalConfigDir;
23
+ export let globalCacheDir;
24
+
25
+ // OS specific dirs
26
+ if (process.platform == 'win32') {
27
+ globalConfigDir = path.join(process.env.LOCALAPPDATA, 'mops/config');
28
+ globalCacheDir = path.join(process.env.LOCALAPPDATA, 'mops/cache');
29
+ }
30
+ else if (process.platform == 'darwin') {
31
+ globalConfigDir = path.join(process.env.HOME, 'Library/Application Support/mops');
32
+ globalCacheDir = path.join(process.env.HOME, 'Library/Caches/mops');
33
+ }
34
+ else {
35
+ globalConfigDir = path.join(process.env.HOME, '.config/mops');
36
+ globalCacheDir = path.join(process.env.HOME, '.cache/mops');
37
+ }
38
+ // XDG overrides
39
+ if (process.env.XDG_CONFIG_HOME) {
40
+ globalConfigDir = path.join(process.env.XDG_CONFIG_HOME, 'mops');
41
+ }
42
+ if (process.env.XDG_CACHE_HOME) {
43
+ globalCacheDir = path.join(process.env.XDG_CACHE_HOME, 'mops');
44
+ }
45
+
46
+ // temp: move old config to new location
47
+ let oldGlobalConfigDir = path.resolve(process.env.HOME || process.env.APPDATA, 'mops');
48
+ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalConfigDir)) {
49
+ fs.mkdirSync(globalConfigDir, {recursive: true});
50
+ if (fs.existsSync(path.join(oldGlobalConfigDir, 'identity.pem'))) {
51
+ fs.copyFileSync(path.join(oldGlobalConfigDir, 'identity.pem'), path.join(globalConfigDir, 'identity.pem'));
52
+ }
53
+ if (fs.existsSync(path.join(oldGlobalConfigDir, 'identity.pem.encrypted'))) {
54
+ fs.copyFileSync(path.join(oldGlobalConfigDir, 'identity.pem.encrypted'), path.join(globalConfigDir, 'identity.pem.encrypted'));
55
+ }
56
+ console.log('Moved config to ' + chalk.green(globalConfigDir));
57
+ }
58
+
59
+ // temp: move old cache to new location
60
+ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalCacheDir)) {
61
+ fs.mkdirSync(globalCacheDir, {recursive: true});
62
+ ncp.ncp(path.join(oldGlobalConfigDir, 'packages'), path.join(globalCacheDir, 'packages'), {
63
+ stopOnErr: true,
64
+ clobber: false,
65
+ }, (err) => {
66
+ if (err) {
67
+ console.log('Error moving config: ', err);
68
+ fs.rmSync(globalCacheDir, {recursive: true, force: true});
69
+ }
70
+ });
71
+ console.log('Moved cache to ' + chalk.green(globalCacheDir));
72
+ }
22
73
 
23
74
  export function setNetwork(network) {
24
75
  fs.writeFileSync(networkFile, network);
@@ -31,11 +82,10 @@ export function getNetwork() {
31
82
  }
32
83
 
33
84
  if (network === 'local') {
34
- let ids = JSON.parse(fs.readFileSync(new URL('../.dfx/local/canister_ids.json', import.meta.url)).toString());
35
85
  return {
36
86
  network,
37
87
  host: 'http://127.0.0.1:4943',
38
- canisterId: ids.main.local,
88
+ canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
39
89
  };
40
90
  }
41
91
  else if (network === 'staging') {
@@ -55,8 +105,8 @@ export function getNetwork() {
55
105
  }
56
106
 
57
107
  export let getIdentity = async () => {
58
- let identityPem = path.resolve(globalCacheDir, 'identity.pem');
59
- let identityPemEncrypted = path.resolve(globalCacheDir, 'identity.pem.encrypted');
108
+ let identityPem = path.resolve(globalConfigDir, 'identity.pem');
109
+ let identityPemEncrypted = path.resolve(globalConfigDir, 'identity.pem.encrypted');
60
110
  if (fs.existsSync(identityPemEncrypted)) {
61
111
  let res = await prompts({
62
112
  type: 'password',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.18.2",
3
+ "version": "0.19.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "cli.js"