@le-space/core 0.1.34 → 0.1.36

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 (3) hide show
  1. package/index.d.ts +10 -1
  2. package/index.js +20 -3
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -31,6 +31,15 @@ declare function resolveRootfsReference(itemHash: string, options: {
31
31
  declare const DEFAULT_CRN_LIST_URL = "https://crns-list.aleph.sh/crns.json";
32
32
  declare const DEFAULT_COUNTRY_LOOKUP_BASE_URL = "https://api.country.is";
33
33
  declare const DEFAULT_DNS_RESOLVE_URL = "https://dns.google/resolve";
34
+ interface CrnCapacitySpec {
35
+ vcpus: number;
36
+ memoryMiB: number;
37
+ diskMiB: number;
38
+ }
39
+ declare function filterDeployableCrns<TCrn extends CrnRecord>(crns: ReadonlyArray<TCrn>, options?: {
40
+ excludedHashes?: ReadonlyArray<string>;
41
+ spec?: CrnCapacitySpec | null;
42
+ }): TCrn[];
34
43
  declare function fetchCrns(options: {
35
44
  url?: string;
36
45
  fetch: FetchLike;
@@ -591,4 +600,4 @@ declare function verifyUcGoPeerReachability(args: {
591
600
  checks: Record<string, Record<string, unknown>>;
592
601
  }>;
593
602
 
594
- export { DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_CHANNEL, DEFAULT_COUNTRY_LOOKUP_BASE_URL, DEFAULT_CRN_LIST_URL, DEFAULT_DNS_RESOLVE_URL, DEFAULT_INSTANCE_PORT_FORWARDS, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_SCHEDULER_ALLOCATION_URL, DEFAULT_TWO_N_SIX_HASH_URL, type FetchLike, type FetchLikeResponse, type HttpProbeResult, ITEM_HASH_RE, type JsonFetchLike, type JsonFetchLikeResponse, type PaymentQuote, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, type TierSpec, broadcastAlephMessage, buildPaymentQuote, cleanupFailedDeployment, configureUcGoPeer, createDeploymentIntent, createInstanceContent, createPortForwardAggregateContent, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmRuntime, findCrnByHash, forgetAlephMessages, inspectDeploymentResult, inspectMessageResult, isInvalidMessageFormatResponse, isRetryableBroadcastFailure, isValidSshPublicKey, listGeocodedCrns, mergePortFlagMaps, mergeRequiredPortForwards, messageTypeFromEnvelope, normalizeBroadcastStatus, normalizeExecution, normalizeExistingPortForwardEntry, normalizeMessageStatus, normalizeProxyUrl, normalizeSshPublicKey, notifyCrnAllocation, portForwardLabel, postBroadcastPayload, probeRootfsGateway, publishAggregateKey, quoteRequiredBudgetUnits, rankCandidateCrns, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, selectedTier, signAlephMessage, signaturePayload, tierSpec, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForSetupEndpoint, waitForVmRuntime };
603
+ export { type CrnCapacitySpec, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_CHANNEL, DEFAULT_COUNTRY_LOOKUP_BASE_URL, DEFAULT_CRN_LIST_URL, DEFAULT_DNS_RESOLVE_URL, DEFAULT_INSTANCE_PORT_FORWARDS, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_SCHEDULER_ALLOCATION_URL, DEFAULT_TWO_N_SIX_HASH_URL, type FetchLike, type FetchLikeResponse, type HttpProbeResult, ITEM_HASH_RE, type JsonFetchLike, type JsonFetchLikeResponse, type PaymentQuote, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, type TierSpec, broadcastAlephMessage, buildPaymentQuote, cleanupFailedDeployment, configureUcGoPeer, createDeploymentIntent, createInstanceContent, createPortForwardAggregateContent, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmRuntime, filterDeployableCrns, findCrnByHash, forgetAlephMessages, inspectDeploymentResult, inspectMessageResult, isInvalidMessageFormatResponse, isRetryableBroadcastFailure, isValidSshPublicKey, listGeocodedCrns, mergePortFlagMaps, mergeRequiredPortForwards, messageTypeFromEnvelope, normalizeBroadcastStatus, normalizeExecution, normalizeExistingPortForwardEntry, normalizeMessageStatus, normalizeProxyUrl, normalizeSshPublicKey, notifyCrnAllocation, portForwardLabel, postBroadcastPayload, probeRootfsGateway, publishAggregateKey, quoteRequiredBudgetUnits, rankCandidateCrns, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, selectedTier, signAlephMessage, signaturePayload, tierSpec, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForSetupEndpoint, waitForVmRuntime };
package/index.js CHANGED
@@ -213,6 +213,15 @@ function compatibleCrns(crns, excludedHashes = []) {
213
213
  return true;
214
214
  });
215
215
  }
216
+ function hasCrnCapacity(crn, spec) {
217
+ if (!spec) return true;
218
+ const usage = crn.system_usage;
219
+ if (!usage) return true;
220
+ const cpuOk = usage.cpu?.count == null || usage.cpu.count >= spec.vcpus;
221
+ const memoryOk = usage.mem?.available_kB == null || usage.mem.available_kB >= spec.memoryMiB * 1024;
222
+ const diskOk = usage.disk?.available_kB == null || usage.disk.available_kB >= spec.diskMiB * 1024;
223
+ return cpuOk && memoryOk && diskOk;
224
+ }
216
225
  function scoreSortedCrns(crns) {
217
226
  return [...crns].sort((left, right) => {
218
227
  const rightScore = typeof right.score === "number" ? right.score : Number(right.score ?? Number.NEGATIVE_INFINITY);
@@ -223,6 +232,11 @@ function scoreSortedCrns(crns) {
223
232
  return leftName.localeCompare(rightName);
224
233
  });
225
234
  }
235
+ function filterDeployableCrns(crns, options = {}) {
236
+ return scoreSortedCrns(
237
+ compatibleCrns(crns, options.excludedHashes).filter((crn) => hasCrnCapacity(crn, options.spec))
238
+ );
239
+ }
226
240
  async function resolveHostIp(host, options) {
227
241
  if (!host) return null;
228
242
  if (isIpAddress(host)) return host;
@@ -309,10 +323,10 @@ async function enrichCrnsWithGeo(crns, options) {
309
323
  );
310
324
  }
311
325
  async function listGeocodedCrns(options) {
312
- const sortedCrns = scoreSortedCrns(compatibleCrns(await fetchCrns({
326
+ const sortedCrns = filterDeployableCrns(await fetchCrns({
313
327
  url: options.url,
314
328
  fetch: options.fetch
315
- })));
329
+ }));
316
330
  const geocodedCrns = await enrichCrnsWithGeo(
317
331
  sortedCrns.slice(0, Math.max(1, Number(options.limit) || 30)),
318
332
  options
@@ -326,7 +340,9 @@ async function listGeocodedCrns(options) {
326
340
  async function rankCandidateCrns(crns, options) {
327
341
  const preferredCountryCode = normalizeCountryCode(options.preferredCountryCode);
328
342
  const geoLimit = Math.max(1, Number(options.geoLimit) || 30);
329
- const sortedCrns = scoreSortedCrns(compatibleCrns(crns, options.excludedHashes));
343
+ const sortedCrns = filterDeployableCrns(crns, {
344
+ excludedHashes: options.excludedHashes
345
+ });
330
346
  if (!preferredCountryCode || sortedCrns.length === 0) {
331
347
  return sortedCrns;
332
348
  }
@@ -1843,6 +1859,7 @@ export {
1843
1859
  fetchSchedulerAllocation,
1844
1860
  fetchUcGoPeerMetadata,
1845
1861
  fetchVmRuntime,
1862
+ filterDeployableCrns,
1846
1863
  findCrnByHash,
1847
1864
  forgetAlephMessages,
1848
1865
  inspectDeploymentResult,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/core",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,6 +16,6 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@le-space/shared-types": "0.1.34"
19
+ "@le-space/shared-types": "0.1.36"
20
20
  }
21
21
  }