Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dotcom-tool-kit/types

Package Overview
Dependencies
Maintainers
2
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotcom-tool-kit/types - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

31

lib/index.d.ts
import type { Logger } from 'winston';
import { Schema, SchemaOutput } from './schema';
export declare abstract class Task<O extends Schema = Record<string, never>> {
declare const typeSymbol: unique symbol;
export interface Invalid {
valid: false;
reasons: string[];
}
export interface Valid<T> {
valid: true;
value: T;
}
export declare type Validated<T> = Invalid | Valid<T>;
export declare function mapValidated<T, U>(validated: Validated<T>, f: (val: T) => U): Validated<U>;
export declare function mapValidationError<T>(validated: Validated<T>, f: (reasons: string[]) => string[]): Validated<T>;
export declare function joinValidated<T, U>(first: Validated<T>, second: Validated<U>): Validated<[T, U]>;
export declare function reduceValidated<T>(validated: Validated<T>[]): Validated<T[]>;
declare abstract class Base {
static version: string;
version: string;
static get [typeSymbol](): symbol;
get [typeSymbol](): symbol;
static is<T extends Base>(objectToCheck: any): objectToCheck is T;
static isCompatible<T extends Base>(objectToCheck: unknown): Validated<T>;
}
export declare abstract class Task<O extends Schema = Record<string, never>> extends Base {
static description: string;
static plugin?: Plugin;
static id?: string;
static get [typeSymbol](): symbol;
get [typeSymbol](): symbol;
static defaultOptions: Record<string, unknown>;

@@ -16,3 +40,3 @@ options: SchemaOutput<O>;

} & typeof Task;
export declare abstract class Hook {
export declare abstract class Hook extends Base {
id?: string;

@@ -22,2 +46,4 @@ plugin?: Plugin;

static description?: string;
static get [typeSymbol](): symbol;
get [typeSymbol](): symbol;
constructor(logger: Logger);

@@ -53,2 +79,3 @@ abstract check(): Promise<boolean>;

}
export {};
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hook = exports.Task = void 0;
class Task {
exports.Hook = exports.Task = exports.reduceValidated = exports.joinValidated = exports.mapValidationError = exports.mapValidated = void 0;
const tslib_1 = require("tslib");
const logger_1 = require("@dotcom-tool-kit/logger");
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
const path_1 = (0, tslib_1.__importDefault)(require("path"));
const semver_1 = (0, tslib_1.__importDefault)(require("semver"));
const packageJsonPath = path_1.default.resolve(__dirname, '../package.json');
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf8'));
const version = packageJson.version;
// uses Symbol.for, not Symbol, so that they're compatible across different
// @dotcom-tool-kit/types instances
// used as the name for the property we use to identify classes
const typeSymbol = Symbol.for('@dotcom-tool-kit/types');
// used to identify the Base, Task and Hook classes
const baseSymbol = Symbol.for('@dotcom-tool-kit/types/base');
const taskSymbol = Symbol.for('@dotcom-tool-kit/types/task');
const hookSymbol = Symbol.for('@dotcom-tool-kit/types/hook');
function mapValidated(validated, f) {
if (validated.valid) {
return { valid: true, value: f(validated.value) };
}
else {
return validated;
}
}
exports.mapValidated = mapValidated;
function mapValidationError(validated, f) {
if (validated.valid) {
return validated;
}
else {
return { valid: false, reasons: f(validated.reasons) };
}
}
exports.mapValidationError = mapValidationError;
function joinValidated(first, second) {
if (first.valid) {
if (second.valid) {
return { valid: true, value: [first.value, second.value] };
}
else {
return second;
}
}
else {
if (second.valid) {
return first;
}
else {
return { valid: false, reasons: [...first.reasons, ...second.reasons] };
}
}
}
exports.joinValidated = joinValidated;
function reduceValidated(validated) {
let sequenced = { valid: true, value: [] };
for (const val of validated) {
if (sequenced.valid) {
if (val.valid) {
sequenced.value.push(val.value);
}
else {
sequenced = { valid: false, reasons: val.reasons };
}
}
else if (!val.valid) {
sequenced.reasons.push(...val.reasons);
}
}
return sequenced;
}
exports.reduceValidated = reduceValidated;
class Base {
constructor() {
this.version = version;
}
static get [typeSymbol]() {
return baseSymbol;
}
get [typeSymbol]() {
return baseSymbol;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static is(objectToCheck) {
return objectToCheck[typeSymbol] === this[typeSymbol];
}
static isCompatible(objectToCheck) {
if (!this.is(objectToCheck)) {
return {
valid: false,
reasons: [
`${logger_1.styles.plugin('@dotcom-tool-kit/types')} type symbol is missing, make sure that this object derives from the ${logger_1.styles.code('Task')} or ${logger_1.styles.code('Hook')} class defined by the plugin`
]
};
}
// an 'objectToCheck' from a plugin is compatible with this CLI if its
// version is semver-compatible with the @dotcom-tool-kit/types included by
// the CLI (which is what's calling this). so, prepend ^ to our version,
// and check our version satisfies that.
// this lets e.g. a CLI that includes types@2.2.0 load any plugin
// that depends on any higher minor version of types.
const range = `^${this.version}`;
if (semver_1.default.satisfies(objectToCheck.version, range)) {
return { valid: true, value: objectToCheck };
}
else {
return {
valid: false,
reasons: [
`object is from an outdated version of ${logger_1.styles.plugin('@dotcom-tool-kit/types')}, make sure you're using at least version ${logger_1.styles.heading(this.version)} of the plugin`
]
};
}
}
}
Base.version = version;
class Task extends Base {
constructor(logger, options = {}) {
super();
const staticThis = this.constructor;

@@ -10,10 +126,23 @@ this.options = Object.assign({}, staticThis.defaultOptions, options);

}
static get [typeSymbol]() {
return taskSymbol;
}
get [typeSymbol]() {
return taskSymbol;
}
}
exports.Task = Task;
Task.defaultOptions = {};
class Hook {
class Hook extends Base {
constructor(logger) {
super();
this.logger = logger.child({ hook: this.constructor.name });
}
static get [typeSymbol]() {
return hookSymbol;
}
get [typeSymbol]() {
return hookSymbol;
}
}
exports.Hook = Hook;

7

package.json
{
"name": "@dotcom-tool-kit/types",
"version": "2.3.0",
"version": "2.4.0",
"description": "",

@@ -27,4 +27,6 @@ "main": "lib",

"@dotcom-tool-kit/error": "^2.0.0",
"@dotcom-tool-kit/logger": "^2.1.0",
"lodash.isplainobject": "^4.0.6",
"lodash.mapvalues": "^4.6.0"
"lodash.mapvalues": "^4.6.0",
"semver": "^7.3.7"
},

@@ -36,4 +38,5 @@ "devDependencies": {

"@types/prompts": "^2.0.14",
"@types/semver": "^7.3.9",
"winston": "^3.5.1"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc