Skip to content

Commit

Permalink
fix: include type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Aug 8, 2024
1 parent 50149fd commit 8b11d22
Show file tree
Hide file tree
Showing 30 changed files with 208 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:

- run: npm run lint

- run: npm run types

- run: npm test

- run: npx semantic-release
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ jobs:

- run: npm run lint

- run: npm run types

- run: npm test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tmp/**/*
coverage
.vscode
.nyc_output/
.tap/
.tap/
types/
21 changes: 14 additions & 7 deletions lib/classes/asset.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import mime from "mime";
import path from "node:path";

/**
* @typedef {object} AssetOptions
* @property {string} [pathname]
* @property {string} [version]
* @property {string} [name]
* @property {string} [type]
* @property {string} [org]
*/

/**
* Meta information about an Asset.
* @class Asset
*/
const Asset = class Asset {
/**
* Creates an instance of Asset.
* @param {string} [base=''] Base file path. Should contain the extension of the asset.
* @param {string} [dir=''] Directory path to the asset. Will be prefixed to "base".
* @memberof Asset
* @param {AssetOptions} options
*/
constructor({
pathname = "",
Expand All @@ -19,7 +24,9 @@ const Asset = class Asset {
type = "",
org = "",
} = {}) {
this._mimeType = mime.getType(pathname) || "application/octet-stream";
this._mimeType =
/** @type {string} */ (mime.getType(pathname)) ||
"application/octet-stream";
this._type = type.toLowerCase();
this._size = -1;

Expand Down Expand Up @@ -83,7 +90,7 @@ const Asset = class Asset {
return {
integrity: this.integrity,
pathname: this.pathname,
mimeType: this._mimeType,
mimeType: this.mimeType,
type: this.type,
size: this.size,
};
Expand Down
1 change: 1 addition & 0 deletions lib/classes/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Package = class Package {
author = {},
} = {}) {
this._version = version;
// @ts-expect-error
this._created = Math.floor(new Date() / 1000);
this._author = author;
this._type = type;
Expand Down
11 changes: 11 additions & 0 deletions lib/handlers/alias.delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ import { decodeUriComponent } from "../utils/utils.js";
import HttpOutgoing from "../classes/http-outgoing.js";
import config from "../utils/defaults.js";

/**
* @typedef {object} AliasDeleteOptions
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const AliasDel = class AliasDel {
/**
* @param {AliasDeleteOptions} options
*/
constructor({ organizations, cacheControl, logger, sink } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl;
Expand Down
11 changes: 11 additions & 0 deletions lib/handlers/alias.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ import { createFilePathToAlias } from "../utils/path-builders-fs.js";
import HttpOutgoing from "../classes/http-outgoing.js";
import config from "../utils/defaults.js";

/**
* @typedef {object} AliasGetOptions
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const AliasGet = class AliasGet {
/**
* @param {AliasGetOptions} options
*/
constructor({ organizations, cacheControl, logger, sink } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl || "public, max-age=1200";
Expand Down
12 changes: 11 additions & 1 deletion lib/handlers/alias.post.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ import Alias from "../classes/alias.js";
import config from "../utils/defaults.js";
import { decodeUriComponent, writeJSON } from "../utils/utils.js";

/**
* @typedef {object} AliasPostOptions
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const AliasPost = class AliasPost {
/**
* @param {AliasPostOptions} options
*/
constructor({ organizations, cacheControl, logger, sink } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl;
Expand All @@ -37,7 +48,6 @@ const AliasPost = class AliasPost {
this._orgRegistry = new Map(this._organizations);

this._multipart = new MultipartParser({
pkgMaxFileSize: this._pkgMaxFileSize,
legalFields: ["version"],
sink: this._sink,
});
Expand Down
12 changes: 11 additions & 1 deletion lib/handlers/alias.put.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ import Author from "../classes/author.js";
import Alias from "../classes/alias.js";
import config from "../utils/defaults.js";

/**
* @typedef {object} AliasPutOptions
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const AliasPut = class AliasPut {
/**
* @param {AliasPutOptions} options
*/
constructor({ organizations, cacheControl, logger, sink } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl;
Expand All @@ -37,7 +48,6 @@ const AliasPut = class AliasPut {
this._orgRegistry = new Map(this._organizations);

this._multipart = new MultipartParser({
pkgMaxFileSize: this._pkgMaxFileSize,
legalFields: ["version"],
sink: this._sink,
});
Expand Down
13 changes: 11 additions & 2 deletions lib/handlers/auth.post.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ import HttpOutgoing from "../classes/http-outgoing.js";
import Author from "../classes/author.js";
import config from "../utils/defaults.js";

/**
* @typedef {object} AuthPostOptions
* @property {string} [authKey]
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const AuthPost = class AuthPost {
/**
* @param {AuthPostOptions} options
*/
constructor({ organizations, cacheControl, authKey, logger } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl;
Expand All @@ -29,9 +40,7 @@ const AuthPost = class AuthPost {
this._orgRegistry = new Map(this._organizations);

this._multipart = new MultipartParser({
pkgMaxFileSize: this._pkgMaxFileSize,
legalFields: ["key"],
sink: this._sink,
});
}

Expand Down
12 changes: 12 additions & 0 deletions lib/handlers/map.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import HttpOutgoing from "../classes/http-outgoing.js";
import config from "../utils/defaults.js";
import { decodeUriComponent } from "../utils/utils.js";

/**
* @typedef {object} MapGetOptions
* @property {boolean} [etag]
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const MapGet = class MapGet {
/**
* @param {MapGetOptions} options
*/
constructor({ organizations, cacheControl, logger, sink, etag } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl || "public, max-age=31536000, immutable";
Expand Down
13 changes: 13 additions & 0 deletions lib/handlers/map.put.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@ import {
readJSON,
} from "../utils/utils.js";

/**
* @typedef {object} MapPutOptions
* @property {number} [mapMaxFileSize]
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const MapPut = class MapPut {
/**
*
* @param {MapPutOptions} options
*/
constructor({
mapMaxFileSize,
organizations,
Expand Down
13 changes: 13 additions & 0 deletions lib/handlers/pkg.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ import HttpOutgoing from "../classes/http-outgoing.js";
import Asset from "../classes/asset.js";
import config from "../utils/defaults.js";

/**
* @typedef {object} PkgGetOptions
* @property {boolean} [etag]
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const PkgGet = class PkgGet {
/**
*
* @param {PkgGetOptions} options
*/
constructor({ organizations, cacheControl, logger, sink, etag } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl || "public, max-age=31536000, immutable";
Expand Down
12 changes: 12 additions & 0 deletions lib/handlers/pkg.log.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import { decodeUriComponent } from "../utils/utils.js";
import HttpOutgoing from "../classes/http-outgoing.js";
import config from "../utils/defaults.js";

/**
* @typedef {object} PkgLogOptions
* @property {boolean} [etag]
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const PkgLog = class PkgLog {
/**
* @param {PkgLogOptions} options
*/
constructor({ organizations, cacheControl, logger, sink, etag } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl || "no-cache";
Expand Down
12 changes: 12 additions & 0 deletions lib/handlers/pkg.put.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ import Package from "../classes/package.js";
import Author from "../classes/author.js";
import config from "../utils/defaults.js";

/**
* @typedef {object} PkgPutOptions
* @property {number} [pkgMaxFileSize=10000000]
* @property {string} [cacheControl]
* @property {Array<[string, string]>} [organizations] List of key-value pairs [hostname, organization]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const PkgPut = class PkgPut {
/**
* @param {PkgPutOptions} options
*/
constructor({
pkgMaxFileSize,
organizations,
Expand Down
12 changes: 12 additions & 0 deletions lib/handlers/versions.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import { decodeUriComponent } from "../utils/utils.js";
import HttpOutgoing from "../classes/http-outgoing.js";
import config from "../utils/defaults.js";

/**
* @typedef {object} VersionsGetOptions
* @property {string} [cacheControl="no-cache"]
* @property {boolean} [etag=true]
* @property {Array<[string, string]>} [organizations]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const VersionsGet = class VersionsGet {
/**
* @param {VersionsGetOptions} options
*/
constructor({ organizations, cacheControl, logger, sink, etag } = {}) {
this._organizations = organizations || config.organizations;
this._cacheControl = cacheControl || "no-cache";
Expand Down
12 changes: 12 additions & 0 deletions lib/multipart/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ import FormField from "./form-field.js";
import FormFile from "./form-file.js";
import Asset from "../classes/asset.js";

/**
* @typedef {object} MultipartParserOptions
* @property {number} [pkgMaxFileSize=10000000]
* @property {string[]} [legalFields]
* @property {string[]} [legalFiles]
* @property {import("@eik/sink").default} [sink]
* @property {import("abslog").AbstractLoggerOptions} [logger]
*/

const MultipartParser = class MultipartParser {
/**
* @param {MultipartParserOptions} options
*/
constructor({ pkgMaxFileSize, legalFields, legalFiles, logger, sink } = {}) {
this._pkgMaxFileSize = pkgMaxFileSize;
this._legalFields = legalFields || [];
Expand Down
Loading

0 comments on commit 8b11d22

Please sign in to comment.