@le-space/node 0.1.33 → 0.1.35

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 (2) hide show
  1. package/index.js +19 -3
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -275,6 +275,15 @@ function compatibleCrns(crns, excludedHashes = []) {
275
275
  return true;
276
276
  });
277
277
  }
278
+ function hasCrnCapacity(crn, spec) {
279
+ if (!spec) return true;
280
+ const usage = crn.system_usage;
281
+ if (!usage) return true;
282
+ const cpuOk = usage.cpu?.count == null || usage.cpu.count >= spec.vcpus;
283
+ const memoryOk = usage.mem?.available_kB == null || usage.mem.available_kB >= spec.memoryMiB * 1024;
284
+ const diskOk = usage.disk?.available_kB == null || usage.disk.available_kB >= spec.diskMiB * 1024;
285
+ return cpuOk && memoryOk && diskOk;
286
+ }
278
287
  function scoreSortedCrns(crns) {
279
288
  return [...crns].sort((left, right) => {
280
289
  const rightScore = typeof right.score === "number" ? right.score : Number(right.score ?? Number.NEGATIVE_INFINITY);
@@ -285,6 +294,11 @@ function scoreSortedCrns(crns) {
285
294
  return leftName.localeCompare(rightName);
286
295
  });
287
296
  }
297
+ function filterDeployableCrns(crns, options = {}) {
298
+ return scoreSortedCrns(
299
+ compatibleCrns(crns, options.excludedHashes).filter((crn) => hasCrnCapacity(crn, options.spec))
300
+ );
301
+ }
288
302
  async function resolveHostIp(host, options) {
289
303
  if (!host) return null;
290
304
  if (isIpAddress(host)) return host;
@@ -371,10 +385,10 @@ async function enrichCrnsWithGeo(crns, options) {
371
385
  );
372
386
  }
373
387
  async function listGeocodedCrns(options) {
374
- const sortedCrns = scoreSortedCrns(compatibleCrns(await fetchCrns({
388
+ const sortedCrns = filterDeployableCrns(await fetchCrns({
375
389
  url: options.url,
376
390
  fetch: options.fetch
377
- })));
391
+ }));
378
392
  const geocodedCrns = await enrichCrnsWithGeo(
379
393
  sortedCrns.slice(0, Math.max(1, Number(options.limit) || 30)),
380
394
  options
@@ -388,7 +402,9 @@ async function listGeocodedCrns(options) {
388
402
  async function rankCandidateCrns(crns, options) {
389
403
  const preferredCountryCode = normalizeCountryCode(options.preferredCountryCode);
390
404
  const geoLimit = Math.max(1, Number(options.geoLimit) || 30);
391
- const sortedCrns = scoreSortedCrns(compatibleCrns(crns, options.excludedHashes));
405
+ const sortedCrns = filterDeployableCrns(crns, {
406
+ excludedHashes: options.excludedHashes
407
+ });
392
408
  if (!preferredCountryCode || sortedCrns.length === 0) {
393
409
  return sortedCrns;
394
410
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/node",
3
- "version": "0.1.33",
3
+ "version": "0.1.35",
4
4
  "description": "Node and GitHub Actions adapters for shared Aleph tooling.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,9 +16,9 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@le-space/core": "0.1.33",
20
- "@le-space/shared-types": "0.1.33",
21
- "@le-space/rootfs": "0.1.33",
19
+ "@le-space/core": "0.1.35",
20
+ "@le-space/shared-types": "0.1.35",
21
+ "@le-space/rootfs": "0.1.35",
22
22
  "ethers": "^6.15.0"
23
23
  }
24
24
  }