Skip to content

Commit

Permalink
WIP: feat: new update endpoints
Browse files Browse the repository at this point in the history
- mark legacy endpoints as deprecated
- dl endpoints that use discrete os, arch with optional
  query params
  • Loading branch information
dopry committed Sep 13, 2023
1 parent 9750e7d commit 6f94863
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 76 deletions.
25 changes: 22 additions & 3 deletions src/models/PecansAsset.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { extname } from "path";
import {
Architecture,
filenameToArchitecture,
filenameToArchitectureLegacy,
filenameToOperatingSystem,
filenameToPackageFormat,
filenameToSupportedArchitecture,
OperatingSystem,
PackageFormat,
Platform,
SupportedArchitecture,
} from "../utils";
import { SupportedFileExtension } from "../utils/SupportedFileExtension";
import { PecansAssetQuery } from "./PecansAssetQuery";
Expand All @@ -17,16 +19,19 @@ export interface PecansAssetDTO {
id: string;
raw: any;
size: number;
// TODO: use os, arch, and pkg in place of platform.
// @deprecated use os, arch, and pkg in place of platform.
type: Platform;
}

export class PecansAsset implements PecansAssetDTO {
os: OperatingSystem;
// @deprecated, should be using archs instead. remove once old arch/type is removed from pecans.
arch: Architecture;
archs: SupportedArchitecture[];
pkg?: PackageFormat;
id: string;
filename: string;
// @deprecated, use os, archs, and pkg instead for filtering.
type: Platform;
size: number;
content_type: string;
Expand All @@ -40,14 +45,16 @@ export class PecansAsset implements PecansAssetDTO {
this.size = dto.size;
this.type = dto.type;
this.os = filenameToOperatingSystem(this.filename);
this.arch = filenameToArchitecture(this.filename, this.os);
this.arch = filenameToArchitectureLegacy(this.filename);
this.archs = filenameToSupportedArchitecture(this.filename);
this.pkg = filenameToPackageFormat(this.filename);
}

satisfiesQuery(query: PecansAssetQuery) {
return (
this.satisfiesOS(query.os) &&
this.satisfiesArch(query.arch) &&
this.satisfiesArchs(query.archs) &&
this.satisfiesPkg(query.pkg) &&
this.satisfiesFilename(query.filename) &&
this.satisfiesExtensions(query.extensions)
Expand All @@ -58,10 +65,18 @@ export class PecansAsset implements PecansAssetDTO {
return os == undefined || this.os == os;
}

// @deprecated, use satisfiesSupportedArch instead.
satisfiesArch(arch?: Architecture) {
return arch == undefined || this.arch == arch;
}

satisfiesArchs(archs?: SupportedArchitecture[]) {
// check that all archs are supported, primarily used to filter universal binaries.
return (
archs == undefined || archs.every((arch) => this.archs.includes(arch))
);
}

satisfiesPkg(pkg?: PackageFormat) {
return pkg == undefined || this.pkg == pkg;
}
Expand All @@ -76,3 +91,7 @@ export class PecansAsset implements PecansAssetDTO {
return extensions.includes(ext as SupportedFileExtension);
}
}

export function isPecansAsset(obj: unknown): obj is PecansAsset {
return obj instanceof PecansAsset;
}
12 changes: 10 additions & 2 deletions src/models/PecansAssetQuery.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { Architecture, OperatingSystem, PackageFormat } from "../utils";
import { SupportedFileExtension } from "../utils/SupportedFileExtension";
import {
Architecture,
OperatingSystem,
PackageFormat,
SupportedArchitecture,
SupportedFileExtension,
} from "../utils";

export interface PecansAssetQuery {
os?: OperatingSystem;
// @deprecated, use supportedArch instead.
arch?: Architecture;
// TODO: rename to arch after removing the current arch.
archs?: SupportedArchitecture[];
pkg?: PackageFormat;
filename?: string;
extensions?: SupportedFileExtension[];
Expand Down
6 changes: 1 addition & 5 deletions src/models/PecansRelease.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { satisfies, validRange } from "semver";
import { channelFromVersion as channelFromVersion } from "../utils";
import { PecansAssetQuery } from "./PecansAssetQuery";
import { PecansAsset, PecansAssetDTO } from "./PecansAsset";
import { PecansAsset, PecansAssetDTO, isPecansAsset } from "./PecansAsset";
import { PecansReleaseQuery } from "./PecansReleaseQuery";

export interface PecansReleaseDTO {
Expand All @@ -14,10 +14,6 @@ export interface PecansReleaseDTO {
version: string;
}

export function isPecansAsset(obj: unknown): obj is PecansAsset {
return obj instanceof PecansAsset;
}

export class PecansRelease implements PecansReleaseDTO {
assets: PecansAsset[];
channel: string;
Expand Down
Loading

0 comments on commit 6f94863

Please sign in to comment.