Fix StartOS 0.4 TypeScript packaging to match SDK API
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
export declare class AbortedError extends Error {
|
||||
readonly muteUnhandled: true;
|
||||
cause?: unknown;
|
||||
constructor(message?: string, options?: {
|
||||
cause?: unknown;
|
||||
});
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AbortedError = void 0;
|
||||
class AbortedError extends Error {
|
||||
constructor(message, options) {
|
||||
super(message);
|
||||
this.muteUnhandled = true;
|
||||
this.name = 'AbortedError';
|
||||
if (options?.cause !== undefined)
|
||||
this.cause = options.cause;
|
||||
}
|
||||
}
|
||||
exports.AbortedError = AbortedError;
|
||||
//# sourceMappingURL=AbortedError.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"AbortedError.js","sourceRoot":"","sources":["../../../../base/lib/util/AbortedError.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IAIrC,YAAY,OAAgB,EAAE,OAA6B;QACzD,KAAK,CAAC,OAAO,CAAC,CAAA;QAJP,kBAAa,GAAG,IAAa,CAAA;QAKpC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,OAAO,EAAE,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;IAC9D,CAAC;CACF;AATD,oCASC"}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
declare const dropId: unique symbol;
|
||||
export type DropRef = {
|
||||
[dropId]: number;
|
||||
};
|
||||
export declare abstract class Drop {
|
||||
private static weak;
|
||||
private static registry;
|
||||
private static idCtr;
|
||||
private dropId?;
|
||||
private dropRef?;
|
||||
protected constructor();
|
||||
protected register(): void;
|
||||
private weak;
|
||||
abstract onDrop(): void;
|
||||
drop(): void;
|
||||
leak(): this;
|
||||
}
|
||||
export declare class DropPromise<T> implements Promise<T> {
|
||||
private readonly promise;
|
||||
private static dropFns;
|
||||
private static registry;
|
||||
private static idCtr;
|
||||
private dropId;
|
||||
private dropRef;
|
||||
[Symbol.toStringTag]: string;
|
||||
private constructor();
|
||||
static of<T>(promise: Promise<T>, dropFn?: () => void): DropPromise<T>;
|
||||
static ref<T>(promise: Promise<T>, dropRef: DropRef): DropPromise<T>;
|
||||
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
||||
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
|
||||
finally(onfinally?: (() => void) | null | undefined): Promise<T>;
|
||||
}
|
||||
export declare class DropGenerator<T = unknown, TReturn = any, TNext = unknown> implements AsyncGenerator<T, TReturn, TNext> {
|
||||
private readonly generator;
|
||||
private static dropFns;
|
||||
private static registry;
|
||||
private static idCtr;
|
||||
private dropId;
|
||||
private dropRef;
|
||||
[Symbol.asyncIterator]: () => this;
|
||||
private constructor();
|
||||
static of<T, TReturn, TNext>(generator: AsyncGenerator<T, TReturn, TNext>, dropFn?: () => void): DropGenerator<T, TReturn, TNext>;
|
||||
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
|
||||
return(value: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
|
||||
throw(e: any): Promise<IteratorResult<T, TReturn>>;
|
||||
}
|
||||
export {};
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
"use strict";
|
||||
var _a, _b;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DropGenerator = exports.DropPromise = exports.Drop = void 0;
|
||||
const dropId = Symbol('id');
|
||||
class Drop {
|
||||
constructor() {
|
||||
this.dropId = Drop.idCtr++;
|
||||
this.dropRef = { [dropId]: this.dropId };
|
||||
const weak = this.weak();
|
||||
Drop.weak[this.dropId] = weak;
|
||||
Drop.registry.register(this.dropRef, this.dropId, this.dropRef);
|
||||
return new Proxy(this, {
|
||||
set(target, prop, value) {
|
||||
if (prop === 'dropRef' || prop == 'dropId')
|
||||
return false;
|
||||
target[prop] = value;
|
||||
weak[prop] = value;
|
||||
return true;
|
||||
},
|
||||
});
|
||||
}
|
||||
register() { }
|
||||
weak() {
|
||||
const weak = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
||||
if (this.dropRef)
|
||||
weak.ref = new WeakRef(this.dropRef);
|
||||
return weak;
|
||||
}
|
||||
drop() {
|
||||
if (!this.dropRef || !this.dropId)
|
||||
return;
|
||||
this.onDrop();
|
||||
this.leak();
|
||||
}
|
||||
leak() {
|
||||
if (!this.dropRef || !this.dropId)
|
||||
return this;
|
||||
Drop.registry.unregister(this.dropRef);
|
||||
delete Drop.weak[this.dropId];
|
||||
delete this.dropRef;
|
||||
delete this.dropId;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.Drop = Drop;
|
||||
Drop.weak = {};
|
||||
Drop.registry = new FinalizationRegistry((id) => {
|
||||
const weak = Drop.weak[id];
|
||||
if (weak)
|
||||
weak.drop();
|
||||
});
|
||||
Drop.idCtr = 0;
|
||||
class DropPromise {
|
||||
constructor(promise, dropFnOrRef) {
|
||||
this.promise = promise;
|
||||
this[_a] = 'DropPromise';
|
||||
if (dropFnOrRef && dropId in dropFnOrRef) {
|
||||
this.dropId = dropFnOrRef[dropId];
|
||||
this.dropRef = dropFnOrRef;
|
||||
return;
|
||||
}
|
||||
this.dropId = DropPromise.idCtr++;
|
||||
this.dropRef = { [dropId]: this.dropId };
|
||||
if (dropFnOrRef)
|
||||
DropPromise.dropFns[this.dropId] = dropFnOrRef;
|
||||
DropPromise.registry.register(this.dropRef, this.dropId, this.dropRef);
|
||||
}
|
||||
static of(promise, dropFn) {
|
||||
return new DropPromise(promise, dropFn);
|
||||
}
|
||||
static ref(promise, dropRef) {
|
||||
return new DropPromise(promise, dropRef);
|
||||
}
|
||||
then(onfulfilled, onrejected) {
|
||||
return DropPromise.ref(this.promise.then(onfulfilled, onrejected), this.dropRef);
|
||||
}
|
||||
catch(onrejected) {
|
||||
return DropPromise.ref(this.promise.catch(onrejected), this.dropRef);
|
||||
}
|
||||
finally(onfinally) {
|
||||
return DropPromise.ref(this.promise.finally(onfinally), this.dropRef);
|
||||
}
|
||||
}
|
||||
exports.DropPromise = DropPromise;
|
||||
_a = Symbol.toStringTag;
|
||||
DropPromise.dropFns = {};
|
||||
DropPromise.registry = new FinalizationRegistry((id) => {
|
||||
const drop = DropPromise.dropFns[id];
|
||||
if (drop) {
|
||||
drop();
|
||||
delete DropPromise.dropFns[id];
|
||||
}
|
||||
});
|
||||
DropPromise.idCtr = 0;
|
||||
class DropGenerator {
|
||||
constructor(generator, dropFn) {
|
||||
this.generator = generator;
|
||||
this[_b] = () => this;
|
||||
this.dropId = DropGenerator.idCtr++;
|
||||
this.dropRef = { [dropId]: this.dropId };
|
||||
if (dropFn)
|
||||
DropGenerator.dropFns[this.dropId] = dropFn;
|
||||
DropGenerator.registry.register(this.dropRef, this.dropId, this.dropRef);
|
||||
}
|
||||
static of(generator, dropFn) {
|
||||
return new DropGenerator(generator, dropFn);
|
||||
}
|
||||
next(...args) {
|
||||
return DropPromise.ref(this.generator.next(...args), this.dropRef);
|
||||
}
|
||||
return(value) {
|
||||
return DropPromise.ref(this.generator.return(value), this.dropRef);
|
||||
}
|
||||
throw(e) {
|
||||
return DropPromise.ref(this.generator.throw(e), this.dropRef);
|
||||
}
|
||||
}
|
||||
exports.DropGenerator = DropGenerator;
|
||||
_b = Symbol.asyncIterator;
|
||||
DropGenerator.dropFns = {};
|
||||
DropGenerator.registry = new FinalizationRegistry((id) => {
|
||||
const drop = DropGenerator.dropFns[id];
|
||||
if (drop) {
|
||||
drop();
|
||||
delete DropGenerator.dropFns[id];
|
||||
}
|
||||
});
|
||||
DropGenerator.idCtr = 0;
|
||||
//# sourceMappingURL=Drop.js.map
|
||||
+1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AAC,OAAO,CAAC,CAAA;IAC/D,CAAC;;AAxCH,sCAyCC;KA3BE,MAAM,CAAC,aAAa;AAXN,qBAAO,GAAiC,EAAE,AAAnC,CAAmC;AAC1C,sBAAQ,GAAG,IAAI,oBAAoB,CAAC,CAAC,EAAU,EAAE,EAAE;IAChE,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACtC,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,EAAE,CAAA;QACN,OAAO,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAClC,CAAC;AACH,CAAC,CAAC,AANqB,CAMrB;AACa,mBAAK,GAAW,CAAC,AAAZ,CAAY"}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { Effects } from '../Effects';
|
||||
import { PackageId } from '../osBindings';
|
||||
import { Watchable } from './Watchable';
|
||||
export declare class GetContainerIp extends Watchable<string> {
|
||||
readonly opts: {
|
||||
packageId?: PackageId;
|
||||
};
|
||||
protected readonly label = "GetContainerIp";
|
||||
constructor(effects: Effects, opts?: {
|
||||
packageId?: PackageId;
|
||||
});
|
||||
protected fetch(callback?: () => void): Promise<string>;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetContainerIp = void 0;
|
||||
const Watchable_1 = require("./Watchable");
|
||||
class GetContainerIp extends Watchable_1.Watchable {
|
||||
constructor(effects, opts = {}) {
|
||||
super(effects);
|
||||
this.opts = opts;
|
||||
this.label = 'GetContainerIp';
|
||||
}
|
||||
fetch(callback) {
|
||||
return this.effects.getContainerIp({ ...this.opts, callback });
|
||||
}
|
||||
}
|
||||
exports.GetContainerIp = GetContainerIp;
|
||||
//# sourceMappingURL=GetContainerIp.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GetContainerIp.js","sourceRoot":"","sources":["../../../../base/lib/util/GetContainerIp.ts"],"names":[],"mappings":";;;AAEA,2CAAuC;AAEvC,MAAa,cAAe,SAAQ,qBAAiB;IAGnD,YACE,OAAgB,EACP,OAAkC,EAAE;QAE7C,KAAK,CAAC,OAAO,CAAC,CAAA;QAFL,SAAI,GAAJ,IAAI,CAAgC;QAJ5B,UAAK,GAAG,gBAAgB,CAAA;IAO3C,CAAC;IAES,KAAK,CAAC,QAAqB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IAChE,CAAC;CACF;AAbD,wCAaC"}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import { Effects } from '../Effects';
|
||||
import { Host, HostId, PackageId } from '../osBindings';
|
||||
import { Watchable } from './Watchable';
|
||||
export declare class GetHostInfo extends Watchable<Host | null> {
|
||||
readonly opts: {
|
||||
hostId: HostId;
|
||||
packageId?: PackageId;
|
||||
};
|
||||
protected readonly label = "GetHostInfo";
|
||||
constructor(effects: Effects, opts: {
|
||||
hostId: HostId;
|
||||
packageId?: PackageId;
|
||||
});
|
||||
protected fetch(callback?: () => void): Promise<Host | null>;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetHostInfo = void 0;
|
||||
const Watchable_1 = require("./Watchable");
|
||||
class GetHostInfo extends Watchable_1.Watchable {
|
||||
constructor(effects, opts) {
|
||||
super(effects);
|
||||
this.opts = opts;
|
||||
this.label = 'GetHostInfo';
|
||||
}
|
||||
fetch(callback) {
|
||||
return this.effects.getHostInfo({ ...this.opts, callback });
|
||||
}
|
||||
}
|
||||
exports.GetHostInfo = GetHostInfo;
|
||||
//# sourceMappingURL=GetHostInfo.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GetHostInfo.js","sourceRoot":"","sources":["../../../../base/lib/util/GetHostInfo.ts"],"names":[],"mappings":";;;AAEA,2CAAuC;AAEvC,MAAa,WAAY,SAAQ,qBAAsB;IAGrD,YACE,OAAgB,EACP,IAA+C;QAExD,KAAK,CAAC,OAAO,CAAC,CAAA;QAFL,SAAI,GAAJ,IAAI,CAA2C;QAJvC,UAAK,GAAG,aAAa,CAAA;IAOxC,CAAC;IAES,KAAK,CAAC,QAAqB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC7D,CAAC;CACF;AAbD,kCAaC"}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { Effects } from '../Effects';
|
||||
import { Watchable } from './Watchable';
|
||||
export declare class GetOutboundGateway extends Watchable<string> {
|
||||
protected readonly label = "GetOutboundGateway";
|
||||
constructor(effects: Effects);
|
||||
protected fetch(callback?: () => void): Promise<string>;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetOutboundGateway = void 0;
|
||||
const Watchable_1 = require("./Watchable");
|
||||
class GetOutboundGateway extends Watchable_1.Watchable {
|
||||
constructor(effects) {
|
||||
super(effects);
|
||||
this.label = 'GetOutboundGateway';
|
||||
}
|
||||
fetch(callback) {
|
||||
return this.effects.getOutboundGateway({ callback });
|
||||
}
|
||||
}
|
||||
exports.GetOutboundGateway = GetOutboundGateway;
|
||||
//# sourceMappingURL=GetOutboundGateway.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GetOutboundGateway.js","sourceRoot":"","sources":["../../../../base/lib/util/GetOutboundGateway.ts"],"names":[],"mappings":";;;AACA,2CAAuC;AAEvC,MAAa,kBAAmB,SAAQ,qBAAiB;IAGvD,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAA;QAHG,UAAK,GAAG,oBAAoB,CAAA;IAI/C,CAAC;IAES,KAAK,CAAC,QAAqB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;IACtD,CAAC;CACF;AAVD,gDAUC"}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { Effects } from '../Effects';
|
||||
import { Manifest, PackageId } from '../osBindings';
|
||||
import { Watchable } from './Watchable';
|
||||
export declare class GetServiceManifest<Mapped = Manifest | null> extends Watchable<Manifest | null, Mapped> {
|
||||
readonly opts: {
|
||||
packageId: PackageId;
|
||||
};
|
||||
protected readonly label = "GetServiceManifest";
|
||||
constructor(effects: Effects, opts: {
|
||||
packageId: PackageId;
|
||||
}, options?: {
|
||||
map?: (value: Manifest | null) => Mapped;
|
||||
eq?: (a: Mapped, b: Mapped) => boolean;
|
||||
});
|
||||
protected fetch(callback?: () => void): Promise<Manifest>;
|
||||
}
|
||||
export declare function getServiceManifest(effects: Effects, packageId: PackageId): GetServiceManifest<Manifest | null>;
|
||||
export declare function getServiceManifest<Mapped>(effects: Effects, packageId: PackageId, map: (manifest: Manifest | null) => Mapped, eq?: (a: Mapped, b: Mapped) => boolean): GetServiceManifest<Mapped>;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetServiceManifest = void 0;
|
||||
exports.getServiceManifest = getServiceManifest;
|
||||
const deepEqual_1 = require("./deepEqual");
|
||||
const Watchable_1 = require("./Watchable");
|
||||
class GetServiceManifest extends Watchable_1.Watchable {
|
||||
constructor(effects, opts, options) {
|
||||
super(effects, options);
|
||||
this.opts = opts;
|
||||
this.label = 'GetServiceManifest';
|
||||
}
|
||||
fetch(callback) {
|
||||
return this.effects.getServiceManifest({ ...this.opts, callback });
|
||||
}
|
||||
}
|
||||
exports.GetServiceManifest = GetServiceManifest;
|
||||
function getServiceManifest(effects, packageId, map, eq) {
|
||||
return new GetServiceManifest(effects, { packageId }, {
|
||||
map: map ?? ((a) => a),
|
||||
eq: eq ?? ((a, b) => (0, deepEqual_1.deepEqual)(a, b)),
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=GetServiceManifest.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GetServiceManifest.js","sourceRoot":"","sources":["../../../../base/lib/util/GetServiceManifest.ts"],"names":[],"mappings":";;;AAqCA,gDAcC;AAjDD,2CAAuC;AACvC,2CAAuC;AAEvC,MAAa,kBAA6C,SAAQ,qBAGjE;IAGC,YACE,OAAgB,EACP,IAA8B,EACvC,OAGC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QANd,SAAI,GAAJ,IAAI,CAA0B;QAJtB,UAAK,GAAG,oBAAoB,CAAA;IAW/C,CAAC;IAES,KAAK,CAAC,QAAqB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IACpE,CAAC;CACF;AApBD,gDAoBC;AAYD,SAAgB,kBAAkB,CAChC,OAAgB,EAChB,SAAoB,EACpB,GAA2C,EAC3C,EAAsC;IAEtC,OAAO,IAAI,kBAAkB,CAC3B,OAAO,EACP,EAAE,SAAS,EAAE,EACb;QACE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAW,CAAC;QAChC,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAA,qBAAS,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACtC,CACF,CAAA;AACH,CAAC"}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { Effects } from '../Effects';
|
||||
import { Watchable } from './Watchable';
|
||||
export declare class GetSslCertificate extends Watchable<[string, string, string]> {
|
||||
readonly opts: {
|
||||
hostnames: string[];
|
||||
algorithm?: 'ecdsa' | 'ed25519';
|
||||
};
|
||||
protected readonly label = "GetSslCertificate";
|
||||
constructor(effects: Effects, opts: {
|
||||
hostnames: string[];
|
||||
algorithm?: 'ecdsa' | 'ed25519';
|
||||
});
|
||||
protected fetch(callback?: () => void): Promise<[string, string, string]>;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetSslCertificate = void 0;
|
||||
const Watchable_1 = require("./Watchable");
|
||||
class GetSslCertificate extends Watchable_1.Watchable {
|
||||
constructor(effects, opts) {
|
||||
super(effects);
|
||||
this.opts = opts;
|
||||
this.label = 'GetSslCertificate';
|
||||
}
|
||||
fetch(callback) {
|
||||
return this.effects.getSslCertificate({ ...this.opts, callback });
|
||||
}
|
||||
}
|
||||
exports.GetSslCertificate = GetSslCertificate;
|
||||
//# sourceMappingURL=GetSslCertificate.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GetSslCertificate.js","sourceRoot":"","sources":["../../../../base/lib/util/GetSslCertificate.ts"],"names":[],"mappings":";;;AACA,2CAAuC;AAEvC,MAAa,iBAAkB,SAAQ,qBAAmC;IAGxE,YACE,OAAgB,EACP,IAGR;QAED,KAAK,CAAC,OAAO,CAAC,CAAA;QALL,SAAI,GAAJ,IAAI,CAGZ;QAPgB,UAAK,GAAG,mBAAmB,CAAA;IAU9C,CAAC;IAES,KAAK,CAAC,QAAqB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IACnE,CAAC;CACF;AAhBD,8CAgBC"}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { Effects } from '../Effects';
|
||||
import { PackageId, StatusInfo } from '../osBindings';
|
||||
import { Watchable } from './Watchable';
|
||||
export declare class GetStatus extends Watchable<StatusInfo | null> {
|
||||
readonly opts: {
|
||||
packageId?: PackageId;
|
||||
};
|
||||
protected readonly label = "GetStatus";
|
||||
constructor(effects: Effects, opts?: {
|
||||
packageId?: PackageId;
|
||||
});
|
||||
protected fetch(callback?: () => void): Promise<StatusInfo | null>;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetStatus = void 0;
|
||||
const Watchable_1 = require("./Watchable");
|
||||
class GetStatus extends Watchable_1.Watchable {
|
||||
constructor(effects, opts = {}) {
|
||||
super(effects);
|
||||
this.opts = opts;
|
||||
this.label = 'GetStatus';
|
||||
}
|
||||
fetch(callback) {
|
||||
return this.effects.getStatus({ ...this.opts, callback });
|
||||
}
|
||||
}
|
||||
exports.GetStatus = GetStatus;
|
||||
//# sourceMappingURL=GetStatus.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GetStatus.js","sourceRoot":"","sources":["../../../../base/lib/util/GetStatus.ts"],"names":[],"mappings":";;;AAEA,2CAAuC;AAEvC,MAAa,SAAU,SAAQ,qBAA4B;IAGzD,YACE,OAAgB,EACP,OAAkC,EAAE;QAE7C,KAAK,CAAC,OAAO,CAAC,CAAA;QAFL,SAAI,GAAJ,IAAI,CAAgC;QAJ5B,UAAK,GAAG,WAAW,CAAA;IAOtC,CAAC;IAES,KAAK,CAAC,QAAqB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC3D,CAAC;CACF;AAbD,8BAaC"}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { Effects } from '../Effects';
|
||||
import * as T from '../types';
|
||||
import { Watchable } from './Watchable';
|
||||
export declare class GetSystemSmtp extends Watchable<T.SmtpValue | null> {
|
||||
protected readonly label = "GetSystemSmtp";
|
||||
constructor(effects: Effects);
|
||||
protected fetch(callback?: () => void): Promise<T.SmtpValue | null>;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetSystemSmtp = void 0;
|
||||
const Watchable_1 = require("./Watchable");
|
||||
class GetSystemSmtp extends Watchable_1.Watchable {
|
||||
constructor(effects) {
|
||||
super(effects);
|
||||
this.label = 'GetSystemSmtp';
|
||||
}
|
||||
fetch(callback) {
|
||||
return this.effects.getSystemSmtp({ callback });
|
||||
}
|
||||
}
|
||||
exports.GetSystemSmtp = GetSystemSmtp;
|
||||
//# sourceMappingURL=GetSystemSmtp.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"GetSystemSmtp.js","sourceRoot":"","sources":["../../../../base/lib/util/GetSystemSmtp.ts"],"names":[],"mappings":";;;AAEA,2CAAuC;AAEvC,MAAa,aAAc,SAAQ,qBAA6B;IAG9D,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAA;QAHG,UAAK,GAAG,eAAe,CAAA;IAI1C,CAAC;IAES,KAAK,CAAC,QAAqB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;IACjD,CAAC;CACF;AAVD,sCAUC"}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
import { Effects } from '../Effects';
|
||||
export declare abstract class Watchable<Raw, Mapped = Raw> {
|
||||
readonly effects: Effects;
|
||||
protected readonly mapFn: (value: Raw) => Mapped;
|
||||
protected readonly eqFn: (a: Mapped, b: Mapped) => boolean;
|
||||
constructor(effects: Effects, options?: {
|
||||
map?: (value: Raw) => Mapped;
|
||||
eq?: (a: Mapped, b: Mapped) => boolean;
|
||||
});
|
||||
/**
|
||||
* Fetch the current value, optionally registering a callback for change notification.
|
||||
* The callback should be invoked when the underlying data changes.
|
||||
*/
|
||||
protected abstract fetch(callback?: () => void): Promise<Raw>;
|
||||
protected abstract readonly label: string;
|
||||
/**
|
||||
* Produce a stream of raw values. Default implementation uses fetch() with
|
||||
* effects callback in a loop. Override for custom subscription mechanisms
|
||||
* (e.g. fs.watch).
|
||||
*/
|
||||
protected produce(abort: AbortSignal): AsyncGenerator<Raw, void>;
|
||||
/**
|
||||
* Lifecycle hook called when const() registers a subscription.
|
||||
* Return a cleanup function to be called when the subscription ends.
|
||||
* Override for side effects like FileHelper's consts tracking.
|
||||
*/
|
||||
protected onConstRegistered(_value: Mapped): (() => void) | void;
|
||||
/**
|
||||
* Internal generator that maps raw values and deduplicates using eq.
|
||||
*/
|
||||
private watchGen;
|
||||
/**
|
||||
* Returns the value. Reruns the context from which it has been called if the underlying value changes
|
||||
*/
|
||||
const(): Promise<Mapped>;
|
||||
/**
|
||||
* Returns the value. Does nothing if the value changes
|
||||
*/
|
||||
once(): Promise<Mapped>;
|
||||
/**
|
||||
* Watches the value. Returns an async iterator that yields whenever the value changes
|
||||
*/
|
||||
watch(abort?: AbortSignal): AsyncGenerator<Mapped, never, unknown>;
|
||||
/**
|
||||
* Watches the value. Takes a custom callback function to run whenever the value changes
|
||||
*/
|
||||
onChange(callback: (value: Mapped | undefined, error?: Error) => {
|
||||
cancel: boolean;
|
||||
} | Promise<{
|
||||
cancel: boolean;
|
||||
}>): void;
|
||||
/**
|
||||
* Watches the value. Returns when the predicate is true
|
||||
*/
|
||||
waitFor(pred: (value: Mapped) => boolean): Promise<Mapped>;
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Watchable = void 0;
|
||||
const AbortedError_1 = require("./AbortedError");
|
||||
const deepEqual_1 = require("./deepEqual");
|
||||
const Drop_1 = require("./Drop");
|
||||
class Watchable {
|
||||
constructor(effects, options) {
|
||||
this.effects = effects;
|
||||
this.mapFn = options?.map ?? ((a) => a);
|
||||
this.eqFn = options?.eq ?? ((a, b) => (0, deepEqual_1.deepEqual)(a, b));
|
||||
}
|
||||
/**
|
||||
* Produce a stream of raw values. Default implementation uses fetch() with
|
||||
* effects callback in a loop. Override for custom subscription mechanisms
|
||||
* (e.g. fs.watch).
|
||||
*/
|
||||
async *produce(abort) {
|
||||
const resolveCell = { resolve: () => { } };
|
||||
this.effects.onLeaveContext(() => {
|
||||
resolveCell.resolve();
|
||||
});
|
||||
abort.addEventListener('abort', () => resolveCell.resolve());
|
||||
while (this.effects.isInContext && !abort.aborted) {
|
||||
let callback = () => { };
|
||||
const waitForNext = new Promise((resolve) => {
|
||||
callback = resolve;
|
||||
resolveCell.resolve = resolve;
|
||||
});
|
||||
yield await this.fetch(() => callback());
|
||||
await waitForNext;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Lifecycle hook called when const() registers a subscription.
|
||||
* Return a cleanup function to be called when the subscription ends.
|
||||
* Override for side effects like FileHelper's consts tracking.
|
||||
*/
|
||||
onConstRegistered(_value) { }
|
||||
/**
|
||||
* Internal generator that maps raw values and deduplicates using eq.
|
||||
*/
|
||||
async *watchGen(abort) {
|
||||
let prev = null;
|
||||
for await (const raw of this.produce(abort)) {
|
||||
if (abort.aborted)
|
||||
return;
|
||||
const mapped = this.mapFn(raw);
|
||||
if (!prev || !this.eqFn(prev.value, mapped)) {
|
||||
prev = { value: mapped };
|
||||
yield mapped;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the value. Reruns the context from which it has been called if the underlying value changes
|
||||
*/
|
||||
async const() {
|
||||
const abort = new AbortController();
|
||||
const gen = this.watchGen(abort.signal);
|
||||
const res = await gen.next();
|
||||
const value = res.value;
|
||||
if (this.effects.constRetry) {
|
||||
const constRetry = this.effects.constRetry;
|
||||
const cleanup = this.onConstRegistered(value);
|
||||
gen.next().then((a) => {
|
||||
abort.abort();
|
||||
cleanup?.();
|
||||
if (!a.done) {
|
||||
constRetry();
|
||||
}
|
||||
}, () => {
|
||||
abort.abort();
|
||||
cleanup?.();
|
||||
});
|
||||
}
|
||||
else {
|
||||
abort.abort();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Returns the value. Does nothing if the value changes
|
||||
*/
|
||||
async once() {
|
||||
return this.mapFn(await this.fetch());
|
||||
}
|
||||
/**
|
||||
* Watches the value. Returns an async iterator that yields whenever the value changes
|
||||
*/
|
||||
watch(abort) {
|
||||
const ctrl = new AbortController();
|
||||
abort?.addEventListener('abort', () => ctrl.abort());
|
||||
return Drop_1.DropGenerator.of((async function* (gen) {
|
||||
yield* gen;
|
||||
throw new AbortedError_1.AbortedError();
|
||||
})(this.watchGen(ctrl.signal)), () => ctrl.abort());
|
||||
}
|
||||
/**
|
||||
* Watches the value. Takes a custom callback function to run whenever the value changes
|
||||
*/
|
||||
onChange(callback) {
|
||||
;
|
||||
(async () => {
|
||||
const ctrl = new AbortController();
|
||||
for await (const value of this.watchGen(ctrl.signal)) {
|
||||
try {
|
||||
const res = await callback(value);
|
||||
if (res.cancel) {
|
||||
ctrl.abort();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`callback function threw an error @ ${this.label}.onChange`, e);
|
||||
}
|
||||
}
|
||||
})()
|
||||
.catch((e) => callback(undefined, e))
|
||||
.catch((e) => console.error(`callback function threw an error @ ${this.label}.onChange`, e));
|
||||
}
|
||||
/**
|
||||
* Watches the value. Returns when the predicate is true
|
||||
*/
|
||||
waitFor(pred) {
|
||||
const ctrl = new AbortController();
|
||||
return Drop_1.DropPromise.of(Promise.resolve().then(async () => {
|
||||
for await (const next of this.watchGen(ctrl.signal)) {
|
||||
if (pred(next)) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
throw new AbortedError_1.AbortedError();
|
||||
}), () => ctrl.abort());
|
||||
}
|
||||
}
|
||||
exports.Watchable = Watchable;
|
||||
//# sourceMappingURL=Watchable.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Watchable.js","sourceRoot":"","sources":["../../../../base/lib/util/Watchable.ts"],"names":[],"mappings":";;;AACA,iDAA6C;AAC7C,2CAAuC;AACvC,iCAAmD;AAEnD,MAAsB,SAAS;IAI7B,YACW,OAAgB,EACzB,OAGC;QAJQ,YAAO,GAAP,OAAO,CAAS;Q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AC;YACH,CAAC;QACH,CAAC,CAAC,EAAE;aACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;aACpC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CACX,OAAO,CAAC,KAAK,CACX,sCAAsC,IAAI,CAAC,KAAK,WAAW,EAC3D,CAAC,CACF,CACF,CAAA;IACL,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAgC;QACtC,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAA;QAClC,OAAO,kBAAW,CAAC,EAAE,CACnB,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YAChC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;gBACpD,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBACf,OAAO,IAAI,CAAA;gBACb,CAAC;YACH,CAAC;YACD,MAAM,IAAI,2BAAY,EAAE,CAAA;QAC1B,CAAC,CAAC,EACF,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CACnB,CAAA;IACH,CAAC;CACF;AA5KD,8BA4KC"}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Converts an unknown thrown value into an Error instance.
|
||||
* If `e` is already an Error, wraps it; if a string, uses it as the message;
|
||||
* otherwise JSON-serializes it as the error message.
|
||||
*
|
||||
* @param e - The unknown value to convert
|
||||
* @returns An Error instance
|
||||
*/
|
||||
export declare const asError: (e: unknown) => Error;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.asError = void 0;
|
||||
/**
|
||||
* Converts an unknown thrown value into an Error instance.
|
||||
* If `e` is already an Error, wraps it; if a string, uses it as the message;
|
||||
* otherwise JSON-serializes it as the error message.
|
||||
*
|
||||
* @param e - The unknown value to convert
|
||||
* @returns An Error instance
|
||||
*/
|
||||
const asError = (e) => {
|
||||
if (e instanceof Error) {
|
||||
return e;
|
||||
}
|
||||
if (typeof e === 'string') {
|
||||
return new Error(`${e}`);
|
||||
}
|
||||
return new Error(`${JSON.stringify(e)}`);
|
||||
};
|
||||
exports.asError = asError;
|
||||
//# sourceMappingURL=asError.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"asError.js","sourceRoot":"","sources":["../../../../base/lib/util/asError.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACI,MAAM,OAAO,GAAG,CAAC,CAAU,EAAE,EAAE;IACpC,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;QACvB,OAAO,CAAC,CAAA;IACV,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC1B,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC1B,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC1C,CAAC,CAAA;AARY,QAAA,OAAO,WAQnB"}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Performs a deep structural equality check across all provided arguments.
|
||||
* Returns true only if every argument is deeply equal to every other argument.
|
||||
* Handles primitives, arrays, and plain objects (JSON-like) recursively.
|
||||
*
|
||||
* Non-plain objects (Set, Map, Date, etc.) are compared by reference only,
|
||||
* since Object.keys() does not enumerate their contents.
|
||||
*
|
||||
* @param args - Two or more values to compare for deep equality
|
||||
* @returns True if all arguments are deeply equal
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* deepEqual({ a: 1 }, { a: 1 }) // true
|
||||
* deepEqual([1, 2], [1, 2], [1, 2]) // true
|
||||
* deepEqual({ a: 1 }, { a: 2 }) // false
|
||||
* ```
|
||||
*/
|
||||
export declare function deepEqual(...args: unknown[]): boolean;
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.deepEqual = deepEqual;
|
||||
/**
|
||||
* Performs a deep structural equality check across all provided arguments.
|
||||
* Returns true only if every argument is deeply equal to every other argument.
|
||||
* Handles primitives, arrays, and plain objects (JSON-like) recursively.
|
||||
*
|
||||
* Non-plain objects (Set, Map, Date, etc.) are compared by reference only,
|
||||
* since Object.keys() does not enumerate their contents.
|
||||
*
|
||||
* @param args - Two or more values to compare for deep equality
|
||||
* @returns True if all arguments are deeply equal
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* deepEqual({ a: 1 }, { a: 1 }) // true
|
||||
* deepEqual([1, 2], [1, 2], [1, 2]) // true
|
||||
* deepEqual({ a: 1 }, { a: 2 }) // false
|
||||
* ```
|
||||
*/
|
||||
function deepEqual(...args) {
|
||||
const objects = args.filter((x) => typeof x === 'object' && x !== null);
|
||||
if (objects.length === 0) {
|
||||
for (const x of args)
|
||||
if (x !== args[0])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (objects.length !== args.length)
|
||||
return false;
|
||||
if (objects.some(Array.isArray) && !objects.every(Array.isArray))
|
||||
return false;
|
||||
if (objects.some((x) => !Array.isArray(x) && Object.getPrototypeOf(x) !== Object.prototype)) {
|
||||
return (objects.reduce((a, b) => (a === b ? a : null), objects[0]) !== null);
|
||||
}
|
||||
const allKeys = new Set(objects.flatMap((x) => Object.keys(x)));
|
||||
for (const key of allKeys) {
|
||||
for (const x of objects) {
|
||||
if (!(key in x))
|
||||
return false;
|
||||
if (!deepEqual(objects[0][key], x[key]))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//# sourceMappingURL=deepEqual.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"deepEqual.js","sourceRoot":"","sources":["../../../../base/lib/util/deepEqual.ts"],"names":[],"mappings":";;AAkBA,8BA8B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,OAAO,EAAE,CAAC;QAC1B,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAA;YAC7B,IAAI,CAAC,SAAS,CAAE,OAAO,CAAC,CAAC,CAAS,CAAC,GAAG,CAAC,EAAG,CAAS,CAAC,GAAG,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAA;QACzE,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Computes the partial difference between two values.
|
||||
* Returns `undefined` if the values are equal, or `{ diff }` containing only the changed parts.
|
||||
* For arrays, the diff contains only items in `next` that have no deep-equal counterpart in `prev`.
|
||||
* For objects, the diff contains only keys whose values changed.
|
||||
*
|
||||
* @param prev - The original value
|
||||
* @param next - The updated value
|
||||
* @returns An object containing the diff, or `undefined` if the values are equal
|
||||
*/
|
||||
export declare function partialDiff<T>(prev: T, next: T): {
|
||||
diff: Partial<T>;
|
||||
} | undefined;
|
||||
/**
|
||||
* Deeply merges multiple values together. Objects are merged key-by-key recursively.
|
||||
* Arrays are merged by appending items that are not already present (by deep equality).
|
||||
* Primitives are resolved by taking the last argument.
|
||||
*
|
||||
* @param args - The values to merge, applied left to right
|
||||
* @returns The merged result
|
||||
*/
|
||||
export declare function deepMerge(...args: unknown[]): unknown;
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.partialDiff = partialDiff;
|
||||
exports.deepMerge = deepMerge;
|
||||
/**
|
||||
* Computes the partial difference between two values.
|
||||
* Returns `undefined` if the values are equal, or `{ diff }` containing only the changed parts.
|
||||
* For arrays, the diff contains only items in `next` that have no deep-equal counterpart in `prev`.
|
||||
* For objects, the diff contains only keys whose values changed.
|
||||
*
|
||||
* @param prev - The original value
|
||||
* @param next - The updated value
|
||||
* @returns An object containing the diff, or `undefined` if the values are equal
|
||||
*/
|
||||
function partialDiff(prev, next) {
|
||||
if (prev === next) {
|
||||
return;
|
||||
}
|
||||
else if (Array.isArray(prev) && Array.isArray(next)) {
|
||||
const res = { diff: [] };
|
||||
for (let newItem of next) {
|
||||
let anyEq = false;
|
||||
for (let oldItem of prev) {
|
||||
if (!partialDiff(oldItem, newItem)) {
|
||||
anyEq = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!anyEq) {
|
||||
res.diff.push(newItem);
|
||||
}
|
||||
}
|
||||
if (res.diff.length) {
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (typeof prev === 'object' && typeof next === 'object') {
|
||||
if (prev === null || next === null)
|
||||
return { diff: next };
|
||||
const res = { diff: {} };
|
||||
const keys = Object.keys(next);
|
||||
for (let key in prev) {
|
||||
if (!keys.includes(key))
|
||||
keys.push(key);
|
||||
}
|
||||
for (let key of keys) {
|
||||
const diff = partialDiff(prev[key], next[key]);
|
||||
if (diff) {
|
||||
res.diff[key] = diff.diff;
|
||||
}
|
||||
}
|
||||
if (Object.keys(res.diff).length) {
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return { diff: next };
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Deeply merges multiple values together. Objects are merged key-by-key recursively.
|
||||
* Arrays are merged by appending items that are not already present (by deep equality).
|
||||
* Primitives are resolved by taking the last argument.
|
||||
*
|
||||
* @param args - The values to merge, applied left to right
|
||||
* @returns The merged result
|
||||
*/
|
||||
function deepMerge(...args) {
|
||||
const lastItem = args[args.length - 1];
|
||||
if (typeof lastItem !== 'object' || !lastItem)
|
||||
return lastItem;
|
||||
if (Array.isArray(lastItem))
|
||||
return deepMergeList(...args.filter((x) => Array.isArray(x)));
|
||||
return deepMergeObject(...args.filter((x) => typeof x === 'object' && x && !Array.isArray(x)));
|
||||
}
|
||||
function deepMergeList(...args) {
|
||||
const res = [];
|
||||
for (let arg of args) {
|
||||
for (let item of arg) {
|
||||
if (!res.some((x) => !partialDiff(x, item))) {
|
||||
res.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
function deepMergeObject(...args) {
|
||||
const lastItem = args[args.length - 1];
|
||||
if (args.length === 0)
|
||||
return lastItem;
|
||||
if (args.length === 1)
|
||||
args.unshift({});
|
||||
const allKeys = new Set(args.flatMap((x) => Object.keys(x)));
|
||||
for (const key of allKeys) {
|
||||
const filteredValues = args.flatMap((x) => key in x ? [x[key]] : []);
|
||||
args[0][key] = deepMerge(...filteredValues);
|
||||
}
|
||||
return args[0];
|
||||
}
|
||||
//# sourceMappingURL=deepMerge.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"deepMerge.js","sourceRoot":"","sources":["../../../../base/lib/util/deepMerge.ts"],"names":[],"mappings":";;AAUA,kCA8CC;AAUD,8BAYC;AA9ED;;;;;;;;;GASG;AACH,SAAgB,WAAW,CACzB,IAAO,EACP,IAAO;IAEP,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAM;IACR,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACtD,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,EAAW,EAAE,CAAA;QACjC,KAAK,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACzB,IAAI,KAAK,GAAG,KAAK,CAAA;YACjB,KAAK,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;gBACzB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;oBACnC,KAAK,GAAG,IAAI,CAAA;oBACZ,MAAK;gBACP,CAAC;YACH,CAAC;YACD,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC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AC,CAAA;IACvC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC5D,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CACxC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAE,CAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAClC,CACA;QAAC,IAAY,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,cAAc,CAAC,CAAA;IACvD,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,CAAQ,CAAA;AACvB,CAAC"}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { DefaultString } from '../actions/input/inputSpecTypes';
|
||||
/**
|
||||
* Resolves a DefaultString spec into a concrete string value.
|
||||
* If the spec is a plain string, returns it directly.
|
||||
* If it is a random-string specification, generates a random string accordingly.
|
||||
*
|
||||
* @param defaultSpec - A string literal or a random-string generation spec
|
||||
* @returns The resolved default string value
|
||||
*/
|
||||
export declare function getDefaultString(defaultSpec: DefaultString): string;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getDefaultString = getDefaultString;
|
||||
const getRandomString_1 = require("./getRandomString");
|
||||
/**
|
||||
* Resolves a DefaultString spec into a concrete string value.
|
||||
* If the spec is a plain string, returns it directly.
|
||||
* If it is a random-string specification, generates a random string accordingly.
|
||||
*
|
||||
* @param defaultSpec - A string literal or a random-string generation spec
|
||||
* @returns The resolved default string value
|
||||
*/
|
||||
function getDefaultString(defaultSpec) {
|
||||
if (typeof defaultSpec === 'string') {
|
||||
return defaultSpec;
|
||||
}
|
||||
else {
|
||||
return (0, getRandomString_1.getRandomString)(defaultSpec);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=getDefaultString.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getDefaultString.js","sourceRoot":"","sources":["../../../../base/lib/util/getDefaultString.ts"],"names":[],"mappings":";;AAWA,4CAMC;AAhBD,uDAAmD;AAEnD;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,WAA0B;IACzD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,WAAW,CAAA;IACpB,CAAC;SAAM,CAAC;QACN,OAAO,IAAA,iCAAe,EAAC,WAAW,CAAC,CAAA;IACrC,CAAC;AACH,CAAC"}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare function getRandomCharInSet(charset: string): string;
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
"use strict";
|
||||
// a,g,h,A-Z,,,,-
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getRandomCharInSet = getRandomCharInSet;
|
||||
function getRandomCharInSet(charset) {
|
||||
const set = stringToCharSet(charset);
|
||||
let charIdx = Math.floor((crypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32) * set.len);
|
||||
for (let range of set.ranges) {
|
||||
if (range.len > charIdx) {
|
||||
return String.fromCharCode(range.start.charCodeAt(0) + charIdx);
|
||||
}
|
||||
charIdx -= range.len;
|
||||
}
|
||||
throw new Error('unreachable');
|
||||
}
|
||||
function stringToCharSet(charset) {
|
||||
let set = { ranges: [], len: 0 };
|
||||
let start = null;
|
||||
let end = null;
|
||||
let in_range = false;
|
||||
for (let char of charset) {
|
||||
switch (char) {
|
||||
case ',':
|
||||
if (start !== null && end !== null) {
|
||||
if (start.charCodeAt(0) > end.charCodeAt(0)) {
|
||||
throw new Error('start > end of charset');
|
||||
}
|
||||
const len = end.charCodeAt(0) - start.charCodeAt(0) + 1;
|
||||
set.ranges.push({
|
||||
start,
|
||||
end,
|
||||
len,
|
||||
});
|
||||
set.len += len;
|
||||
start = null;
|
||||
end = null;
|
||||
in_range = false;
|
||||
}
|
||||
else if (start !== null && !in_range) {
|
||||
set.len += 1;
|
||||
set.ranges.push({ start, end: start, len: 1 });
|
||||
start = null;
|
||||
}
|
||||
else if (start !== null && in_range) {
|
||||
end = ',';
|
||||
}
|
||||
else if (start === null && end === null && !in_range) {
|
||||
start = ',';
|
||||
}
|
||||
else {
|
||||
throw new Error('unexpected ","');
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
if (start === null) {
|
||||
start = '-';
|
||||
}
|
||||
else if (!in_range) {
|
||||
in_range = true;
|
||||
}
|
||||
else if (in_range && end === null) {
|
||||
end = '-';
|
||||
}
|
||||
else {
|
||||
throw new Error('unexpected "-"');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (start === null) {
|
||||
start = char;
|
||||
}
|
||||
else if (in_range && end === null) {
|
||||
end = char;
|
||||
}
|
||||
else {
|
||||
throw new Error(`unexpected "${char}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (start !== null && end !== null) {
|
||||
if (start.charCodeAt(0) > end.charCodeAt(0)) {
|
||||
throw new Error('start > end of charset');
|
||||
}
|
||||
const len = end.charCodeAt(0) - start.charCodeAt(0) + 1;
|
||||
set.ranges.push({
|
||||
start,
|
||||
end,
|
||||
len,
|
||||
});
|
||||
set.len += len;
|
||||
}
|
||||
else if (start !== null) {
|
||||
set.len += 1;
|
||||
set.ranges.push({
|
||||
start,
|
||||
end: start,
|
||||
len: 1,
|
||||
});
|
||||
}
|
||||
return set;
|
||||
}
|
||||
//# sourceMappingURL=getRandomCharInSet.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getRandomCharInSet.js","sourceRoot":"","sources":["../../../../base/lib/util/getRandomCharInSet.ts"],"names":[],"mappings":";AAAA,iBAAiB;;AAEjB,gDAYC;AAZD,SAAgB,kBAAkB,CAAC,OAAe;IAChD,MAAM,GAAG,GAAG,eAA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;YACP;gBACE,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBACnB,KAAK,GAAG,IAAI,CAAA;gBACd,CAAC;qBAAM,IAAI,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;oBACpC,GAAG,GAAG,IAAI,CAAA;gBACZ,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,GAAG,CAAC,CAAA;gBACzC,CAAC;QACL,CAAC;IACH,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACnC,IAAI,KAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,GAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;QAC3C,CAAC;QACD,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QACvD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YACd,KAAK;YACL,GAAG;YACH,GAAG;SACJ,CAAC,CAAA;QACF,GAAG,CAAC,GAAG,IAAI,GAAG,CAAA;IAChB,CAAC;SAAM,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1B,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;QACZ,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YACd,KAAK;YACL,GAAG,EAAE,KAAK;YACV,GAAG,EAAE,CAAC;SACP,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import { RandomString } from '../actions/input/inputSpecTypes';
|
||||
export declare function getRandomString(generator: RandomString): string;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getRandomString = getRandomString;
|
||||
const getRandomCharInSet_1 = require("./getRandomCharInSet");
|
||||
function getRandomString(generator) {
|
||||
let s = '';
|
||||
for (let i = 0; i < generator.len; i++) {
|
||||
s = s + (0, getRandomCharInSet_1.getRandomCharInSet)(generator.charset);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
//# sourceMappingURL=getRandomString.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getRandomString.js","sourceRoot":"","sources":["../../../../base/lib/util/getRandomString.ts"],"names":[],"mappings":";;AAGA,0CAOC;AATD,6DAAyD;AAEzD,SAAgB,eAAe,CAAC,SAAuB;IACrD,IAAI,CAAC,GAAG,EAAE,CAAA;IACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,CAAC,GAAG,CAAC,GAAG,IAAA,uCAAkB,EAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAC/C,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC"}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
import { PackageId, ServiceInterfaceId, ServiceInterfaceType } from '../types';
|
||||
import { AddressInfo, Host, Hostname, HostnameInfo } from '../types';
|
||||
import { Effects } from '../Effects';
|
||||
import { Watchable } from './Watchable';
|
||||
export type UrlString = string;
|
||||
export type HostId = string;
|
||||
export declare const getHostname: (url: string) => Hostname | null;
|
||||
/**
|
||||
* The kinds of hostnames that can be filtered on.
|
||||
*
|
||||
* - `'mdns'` — mDNS / Bonjour `.local` hostnames
|
||||
* - `'domain'` — any os-managed domain name (matches both `'private-domain'` and `'public-domain'` metadata kinds)
|
||||
* - `'ip'` — shorthand for both `'ipv4'` and `'ipv6'`
|
||||
* - `'ipv4'` — IPv4 addresses only
|
||||
* - `'ipv6'` — IPv6 addresses only
|
||||
* - `'localhost'` — loopback addresses (`localhost`, `127.0.0.1`, `::1`)
|
||||
* - `'link-local'` — IPv6 link-local addresses (fe80::/10)
|
||||
* - `'bridge'` — The LXC bridge interface
|
||||
* - `'plugin'` — hostnames provided by a plugin package
|
||||
*/
|
||||
type FilterKinds = 'mdns' | 'domain' | 'ip' | 'ipv4' | 'ipv6' | 'localhost' | 'link-local' | 'bridge' | 'plugin';
|
||||
/**
|
||||
* Describes which hostnames to include (or exclude) when filtering a `Filled` address.
|
||||
*
|
||||
* Every field is optional — omitted fields impose no constraint.
|
||||
* Filters are composable: the `.filter()` method intersects successive filters,
|
||||
* and the `exclude` field inverts a nested filter.
|
||||
*/
|
||||
export type Filter = {
|
||||
/** Keep only hostnames with the given visibility. `'public'` = externally reachable, `'private'` = LAN-only. */
|
||||
visibility?: 'public' | 'private';
|
||||
/** Keep only hostnames whose metadata kind matches. A single kind or array of kinds. `'ip'` expands to `['ipv4','ipv6']`, `'domain'` matches both `'private-domain'` and `'public-domain'`. */
|
||||
kind?: FilterKinds | FilterKinds[];
|
||||
/** Arbitrary predicate — hostnames for which this returns `false` are excluded. */
|
||||
predicate?: (h: HostnameInfo) => boolean;
|
||||
/** Keep only plugin hostnames provided by this package. Implies `kind: 'plugin'`. */
|
||||
pluginId?: PackageId;
|
||||
/** A nested filter whose matches are *removed* from the result (logical NOT). */
|
||||
exclude?: Filter;
|
||||
};
|
||||
type VisibilityFilter<V extends 'public' | 'private'> = V extends 'public' ? (HostnameInfo & {
|
||||
public: true;
|
||||
}) | VisibilityFilter<Exclude<V, 'public'>> : V extends 'private' ? (HostnameInfo & {
|
||||
public: false;
|
||||
}) | VisibilityFilter<Exclude<V, 'private'>> : never;
|
||||
type KindFilter<K extends FilterKinds> = K extends 'mdns' ? (HostnameInfo & {
|
||||
metadata: {
|
||||
kind: 'mdns';
|
||||
};
|
||||
}) | KindFilter<Exclude<K, 'mdns'>> : K extends 'domain' ? (HostnameInfo & {
|
||||
metadata: {
|
||||
kind: 'private-domain';
|
||||
};
|
||||
}) | (HostnameInfo & {
|
||||
metadata: {
|
||||
kind: 'public-domain';
|
||||
};
|
||||
}) | KindFilter<Exclude<K, 'domain'>> : K extends 'ipv4' ? (HostnameInfo & {
|
||||
metadata: {
|
||||
kind: 'ipv4';
|
||||
};
|
||||
}) | KindFilter<Exclude<K, 'ipv4'>> : K extends 'ipv6' ? (HostnameInfo & {
|
||||
metadata: {
|
||||
kind: 'ipv6';
|
||||
};
|
||||
}) | KindFilter<Exclude<K, 'ipv6'>> : K extends 'plugin' ? (HostnameInfo & {
|
||||
metadata: {
|
||||
kind: 'plugin';
|
||||
};
|
||||
}) | KindFilter<Exclude<K, 'plugin'>> : K extends 'ip' ? KindFilter<Exclude<K, 'ip'> | 'ipv4' | 'ipv6'> : never;
|
||||
type FilterReturnTy<F extends Filter> = F extends {
|
||||
visibility: infer V extends 'public' | 'private';
|
||||
} ? VisibilityFilter<V> & FilterReturnTy<Omit<F, 'visibility'>> : F extends {
|
||||
kind: (infer K extends FilterKinds) | (infer K extends FilterKinds)[];
|
||||
} ? KindFilter<K> & FilterReturnTy<Omit<F, 'kind'>> : F extends {
|
||||
predicate: (h: HostnameInfo) => h is infer H extends HostnameInfo;
|
||||
} ? H & FilterReturnTy<Omit<F, 'predicate'>> : F extends {
|
||||
exclude: infer E extends Filter;
|
||||
} ? HostnameInfo extends FilterReturnTy<E> ? HostnameInfo : Exclude<HostnameInfo, FilterReturnTy<E>> : HostnameInfo;
|
||||
declare const nonLocalFilter: {
|
||||
readonly exclude: {
|
||||
readonly kind: ("localhost" | "link-local" | "bridge")[];
|
||||
};
|
||||
};
|
||||
declare const publicFilter: {
|
||||
readonly visibility: "public";
|
||||
};
|
||||
type Formats = 'hostname-info' | 'urlstring' | 'url';
|
||||
type FormatReturnTy<F extends Filter, Format extends Formats> = Format extends 'hostname-info' ? FilterReturnTy<F> | FormatReturnTy<F, Exclude<Format, 'hostname-info'>> : Format extends 'url' ? URL | FormatReturnTy<F, Exclude<Format, 'url'>> : Format extends 'urlstring' ? UrlString | FormatReturnTy<F, Exclude<Format, 'urlstring'>> : never;
|
||||
/**
|
||||
* A resolved address with its hostnames already populated, plus helpers
|
||||
* for filtering, formatting, and converting hostnames to URLs.
|
||||
*
|
||||
* Filters are chainable and each call returns a new `Filled` narrowed to the
|
||||
* matching subset of hostnames:
|
||||
*
|
||||
* ```ts
|
||||
* addresses.nonLocal // exclude localhost & link-local
|
||||
* addresses.public // only publicly-reachable hostnames
|
||||
* addresses.filter({ kind: 'domain' }) // only domain-name hostnames
|
||||
* addresses.filter({ visibility: 'private' }) // only LAN-reachable hostnames
|
||||
* addresses.nonLocal.filter({ kind: 'ip' }) // chainable — non-local IPs only
|
||||
* ```
|
||||
*/
|
||||
export type Filled<F extends Filter = {}> = {
|
||||
/** The hostnames that survived all applied filters. */
|
||||
hostnames: HostnameInfo[];
|
||||
/** Convert a single hostname into a fully-formed URL string, applying the address's scheme, username, and suffix. */
|
||||
toUrl: (h: HostnameInfo) => UrlString;
|
||||
/**
|
||||
* Return every hostname in the requested format.
|
||||
*
|
||||
* - `'urlstring'` (default) — formatted URL strings
|
||||
* - `'url'` — `URL` objects
|
||||
* - `'hostname-info'` — raw `HostnameInfo` objects
|
||||
*/
|
||||
format: <Format extends Formats = 'urlstring'>(format?: Format) => FormatReturnTy<{}, Format>[];
|
||||
/**
|
||||
* Apply an arbitrary {@link Filter} and return a new `Filled` containing only
|
||||
* the hostnames that match. Filters compose: calling `.filter()` on an
|
||||
* already-filtered `Filled` intersects the constraints.
|
||||
*/
|
||||
filter: <NewFilter extends Filter>(filter: NewFilter) => Filled<NewFilter & Filter>;
|
||||
/**
|
||||
* Apply multiple filters and return hostnames that match **any** of them (union / OR).
|
||||
*
|
||||
* ```ts
|
||||
* addresses.matchesAny([{ kind: 'domain' }, { kind: 'mdns' }])
|
||||
* ```
|
||||
*/
|
||||
matchesAny: <NewFilters extends Filter[]>(filters: [...NewFilters]) => Filled<NewFilters[number] & F>;
|
||||
/** Shorthand filter that excludes `localhost` and IPv6 link-local addresses — keeps only network-reachable hostnames. */
|
||||
nonLocal: Filled<typeof nonLocalFilter & Filter>;
|
||||
/** Shorthand filter that keeps only publicly-reachable hostnames (those with `public: true`). */
|
||||
public: Filled<typeof publicFilter & Filter>;
|
||||
};
|
||||
export type FilledAddressInfo = AddressInfo & Filled;
|
||||
export type ServiceInterfaceFilled = {
|
||||
id: string;
|
||||
/** The title of this field to be displayed */
|
||||
name: string;
|
||||
/** Human readable description, used as tooltip usually */
|
||||
description: string;
|
||||
/** Whether or not to mask the URIs for this interface. Useful if the URIs contain sensitive information, such as a password, macaroon, or API key */
|
||||
masked: boolean;
|
||||
/** Information about the host for this binding */
|
||||
host: Host | null;
|
||||
/** URI information */
|
||||
addressInfo: FilledAddressInfo | null;
|
||||
/** Indicates if we are a ui/p2p/api for the kind of interface that this is representing */
|
||||
type: ServiceInterfaceType;
|
||||
};
|
||||
export declare const addressHostToUrl: ({ scheme, sslScheme, username, suffix }: AddressInfo, hostname: HostnameInfo) => UrlString;
|
||||
/**
|
||||
* Filters out localhost and IPv6 link-local hostnames from a list.
|
||||
* Equivalent to the `nonLocal` filter on `Filled` addresses.
|
||||
*/
|
||||
export declare function filterNonLocal(hostnames: HostnameInfo[]): HostnameInfo[];
|
||||
export declare const filledAddress: (host: Host, addressInfo: AddressInfo) => FilledAddressInfo;
|
||||
export declare class GetServiceInterface<Mapped = ServiceInterfaceFilled | null> extends Watchable<ServiceInterfaceFilled | null, Mapped> {
|
||||
readonly opts: {
|
||||
id: string;
|
||||
packageId?: string;
|
||||
};
|
||||
protected readonly label = "GetServiceInterface";
|
||||
constructor(effects: Effects, opts: {
|
||||
id: string;
|
||||
packageId?: string;
|
||||
}, options?: {
|
||||
map?: (value: ServiceInterfaceFilled | null) => Mapped;
|
||||
eq?: (a: Mapped, b: Mapped) => boolean;
|
||||
});
|
||||
protected fetch(callback?: () => void): Promise<ServiceInterfaceFilled | null>;
|
||||
}
|
||||
export declare function getOwnServiceInterface(effects: Effects, id: ServiceInterfaceId): GetServiceInterface;
|
||||
export declare function getOwnServiceInterface<Mapped>(effects: Effects, id: ServiceInterfaceId, map: (interfaces: ServiceInterfaceFilled | null) => Mapped, eq?: (a: Mapped, b: Mapped) => boolean): GetServiceInterface<Mapped>;
|
||||
export declare function getServiceInterface(effects: Effects, opts: {
|
||||
id: ServiceInterfaceId;
|
||||
packageId: PackageId;
|
||||
}): GetServiceInterface;
|
||||
export declare function getServiceInterface<Mapped>(effects: Effects, opts: {
|
||||
id: ServiceInterfaceId;
|
||||
packageId: PackageId;
|
||||
}, map: (interfaces: ServiceInterfaceFilled | null) => Mapped, eq?: (a: Mapped, b: Mapped) => boolean): GetServiceInterface<Mapped>;
|
||||
export {};
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetServiceInterface = exports.filledAddress = exports.addressHostToUrl = exports.getHostname = void 0;
|
||||
exports.filterNonLocal = filterNonLocal;
|
||||
exports.getOwnServiceInterface = getOwnServiceInterface;
|
||||
exports.getServiceInterface = getServiceInterface;
|
||||
const Host_1 = require("../interfaces/Host");
|
||||
const ip_1 = require("./ip");
|
||||
const deepEqual_1 = require("./deepEqual");
|
||||
const once_1 = require("./once");
|
||||
const Watchable_1 = require("./Watchable");
|
||||
const getHostnameRegex = /^(\w+:\/\/)?([^\/\:]+)(:\d{1,3})?(\/)?/;
|
||||
const getHostname = (url) => {
|
||||
const founds = url.match(getHostnameRegex)?.[2];
|
||||
if (!founds)
|
||||
return null;
|
||||
const parts = founds.split('@');
|
||||
const last = parts[parts.length - 1];
|
||||
return last;
|
||||
};
|
||||
exports.getHostname = getHostname;
|
||||
const nonLocalFilter = {
|
||||
exclude: {
|
||||
kind: ['localhost', 'link-local', 'bridge'],
|
||||
},
|
||||
};
|
||||
const publicFilter = {
|
||||
visibility: 'public',
|
||||
};
|
||||
const either = (...args) => (a) => args.some((x) => x(a));
|
||||
const negate = (fn) => (a) => !fn(a);
|
||||
const unique = (values) => Array.from(new Set(values));
|
||||
const addressHostToUrl = ({ scheme, sslScheme, username, suffix }, hostname) => {
|
||||
const effectiveScheme = hostname.ssl ? sslScheme : scheme;
|
||||
let host;
|
||||
if (hostname.metadata.kind === 'ipv6') {
|
||||
host = ip_1.IPV6_LINK_LOCAL.contains(hostname.hostname)
|
||||
? `[${hostname.hostname}%${hostname.metadata.scopeId}]`
|
||||
: `[${hostname.hostname}]`;
|
||||
}
|
||||
else {
|
||||
host = hostname.hostname;
|
||||
}
|
||||
let portStr = '';
|
||||
if (hostname.port !== null) {
|
||||
const excludePort = effectiveScheme &&
|
||||
effectiveScheme in Host_1.knownProtocols &&
|
||||
hostname.port ===
|
||||
Host_1.knownProtocols[effectiveScheme]
|
||||
.defaultPort;
|
||||
if (!excludePort)
|
||||
portStr = `:${hostname.port}`;
|
||||
}
|
||||
return `${effectiveScheme ? `${effectiveScheme}://` : ''}${username ? `${username}@` : ''}${host}${portStr}${suffix}`;
|
||||
};
|
||||
exports.addressHostToUrl = addressHostToUrl;
|
||||
function filterRec(hostnames, filter, invert) {
|
||||
if (filter.predicate) {
|
||||
const pred = filter.predicate;
|
||||
hostnames = hostnames.filter((h) => invert !== pred(h));
|
||||
}
|
||||
if (filter.visibility === 'public')
|
||||
hostnames = hostnames.filter((h) => invert !== h.public);
|
||||
if (filter.visibility === 'private')
|
||||
hostnames = hostnames.filter((h) => invert !== !h.public);
|
||||
if (filter.kind) {
|
||||
const kind = new Set(Array.isArray(filter.kind) ? filter.kind : [filter.kind]);
|
||||
if (kind.has('ip')) {
|
||||
kind.add('ipv4');
|
||||
kind.add('ipv6');
|
||||
}
|
||||
hostnames = hostnames.filter((h) => invert !==
|
||||
((kind.has('mdns') && h.metadata.kind === 'mdns') ||
|
||||
(kind.has('domain') &&
|
||||
(h.metadata.kind === 'private-domain' ||
|
||||
h.metadata.kind === 'public-domain')) ||
|
||||
(kind.has('ipv4') && h.metadata.kind === 'ipv4') ||
|
||||
(kind.has('ipv6') && h.metadata.kind === 'ipv6') ||
|
||||
(kind.has('localhost') &&
|
||||
['localhost', '127.0.0.1', '::1'].includes(h.hostname)) ||
|
||||
(kind.has('link-local') &&
|
||||
h.metadata.kind === 'ipv6' &&
|
||||
ip_1.IPV6_LINK_LOCAL.contains(ip_1.IpAddress.parse(h.hostname))) ||
|
||||
(kind.has('bridge') &&
|
||||
h.metadata.kind === 'ipv4' &&
|
||||
h.metadata.gateway === 'lxcbr0') ||
|
||||
(kind.has('plugin') && h.metadata.kind === 'plugin')));
|
||||
}
|
||||
if (filter.pluginId) {
|
||||
const id = filter.pluginId;
|
||||
hostnames = hostnames.filter((h) => invert !==
|
||||
(h.metadata.kind === 'plugin' && h.metadata.packageId === id));
|
||||
}
|
||||
if (filter.exclude)
|
||||
return filterRec(hostnames, filter.exclude, !invert);
|
||||
return hostnames;
|
||||
}
|
||||
function isPublicIp(h) {
|
||||
return h.public && (h.metadata.kind === 'ipv4' || h.metadata.kind === 'ipv6');
|
||||
}
|
||||
function enabledAddresses(addr) {
|
||||
return addr.available.filter((h) => {
|
||||
if (isPublicIp(h)) {
|
||||
// Public IPs: disabled by default, explicitly enabled via SocketAddr string
|
||||
if (h.port === null)
|
||||
return true;
|
||||
const sa = h.metadata.kind === 'ipv6'
|
||||
? `[${h.hostname}]:${h.port}`
|
||||
: `${h.hostname}:${h.port}`;
|
||||
return addr.enabled.includes(sa);
|
||||
}
|
||||
else {
|
||||
// Everything else: enabled by default, explicitly disabled via [hostname, port] tuple
|
||||
return !addr.disabled.some(([hostname, port]) => hostname === h.hostname && port === (h.port ?? 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Filters out localhost and IPv6 link-local hostnames from a list.
|
||||
* Equivalent to the `nonLocal` filter on `Filled` addresses.
|
||||
*/
|
||||
function filterNonLocal(hostnames) {
|
||||
return filterRec(hostnames, nonLocalFilter, false);
|
||||
}
|
||||
const filledAddress = (host, addressInfo) => {
|
||||
const toUrl = exports.addressHostToUrl.bind(null, addressInfo);
|
||||
const binding = host.bindings[addressInfo.internalPort];
|
||||
const hostnames = binding ? enabledAddresses(binding.addresses) : [];
|
||||
function filledAddressFromHostnames(hostnames) {
|
||||
const getNonLocal = (0, once_1.once)(() => filledAddressFromHostnames(filterRec(hostnames, nonLocalFilter, false)));
|
||||
const getPublic = (0, once_1.once)(() => filledAddressFromHostnames(filterRec(hostnames, publicFilter, false)));
|
||||
return {
|
||||
...addressInfo,
|
||||
hostnames,
|
||||
toUrl,
|
||||
format: (format) => {
|
||||
let res = hostnames;
|
||||
if (format === 'hostname-info')
|
||||
return res;
|
||||
const urls = hostnames.map(toUrl);
|
||||
if (format === 'url')
|
||||
res = urls.map((u) => new URL(u));
|
||||
else
|
||||
res = urls;
|
||||
return res;
|
||||
},
|
||||
filter: (filter) => {
|
||||
return filledAddressFromHostnames(filterRec(hostnames, filter, false));
|
||||
},
|
||||
matchesAny: (filters) => {
|
||||
const seen = new Set();
|
||||
const union = [];
|
||||
for (const f of filters) {
|
||||
for (const h of filterRec(hostnames, f, false)) {
|
||||
if (!seen.has(h)) {
|
||||
seen.add(h);
|
||||
union.push(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
return filledAddressFromHostnames(union);
|
||||
},
|
||||
get nonLocal() {
|
||||
return getNonLocal();
|
||||
},
|
||||
get public() {
|
||||
return getPublic();
|
||||
},
|
||||
};
|
||||
}
|
||||
return filledAddressFromHostnames(hostnames);
|
||||
};
|
||||
exports.filledAddress = filledAddress;
|
||||
const makeInterfaceFilled = async ({ effects, id, packageId, callback, }) => {
|
||||
const serviceInterfaceValue = await effects.getServiceInterface({
|
||||
serviceInterfaceId: id,
|
||||
packageId,
|
||||
callback,
|
||||
});
|
||||
if (!serviceInterfaceValue) {
|
||||
return null;
|
||||
}
|
||||
const hostId = serviceInterfaceValue.addressInfo.hostId;
|
||||
const host = await effects.getHostInfo({
|
||||
packageId,
|
||||
hostId,
|
||||
callback,
|
||||
});
|
||||
const interfaceFilled = {
|
||||
...serviceInterfaceValue,
|
||||
host,
|
||||
addressInfo: host
|
||||
? (0, exports.filledAddress)(host, serviceInterfaceValue.addressInfo)
|
||||
: null,
|
||||
};
|
||||
return interfaceFilled;
|
||||
};
|
||||
class GetServiceInterface extends Watchable_1.Watchable {
|
||||
constructor(effects, opts, options) {
|
||||
super(effects, options);
|
||||
this.opts = opts;
|
||||
this.label = 'GetServiceInterface';
|
||||
}
|
||||
fetch(callback) {
|
||||
return makeInterfaceFilled({
|
||||
effects: this.effects,
|
||||
id: this.opts.id,
|
||||
packageId: this.opts.packageId,
|
||||
callback,
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.GetServiceInterface = GetServiceInterface;
|
||||
function getOwnServiceInterface(effects, id, map, eq) {
|
||||
return new GetServiceInterface(effects, { id }, {
|
||||
map: map ?? ((a) => a),
|
||||
eq: eq ?? ((a, b) => (0, deepEqual_1.deepEqual)(a, b)),
|
||||
});
|
||||
}
|
||||
function getServiceInterface(effects, opts, map, eq) {
|
||||
return new GetServiceInterface(effects, opts, {
|
||||
map: map ?? ((a) => a),
|
||||
eq: eq ?? ((a, b) => (0, deepEqual_1.deepEqual)(a, b)),
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=getServiceInterface.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+25
@@ -0,0 +1,25 @@
|
||||
import { Effects } from '../Effects';
|
||||
import { PackageId } from '../osBindings';
|
||||
import { ServiceInterfaceFilled } from './getServiceInterface';
|
||||
import { Watchable } from './Watchable';
|
||||
export declare class GetServiceInterfaces<Mapped = ServiceInterfaceFilled[]> extends Watchable<ServiceInterfaceFilled[], Mapped> {
|
||||
readonly opts: {
|
||||
packageId?: string;
|
||||
};
|
||||
protected readonly label = "GetServiceInterfaces";
|
||||
constructor(effects: Effects, opts: {
|
||||
packageId?: string;
|
||||
}, options?: {
|
||||
map?: (value: ServiceInterfaceFilled[]) => Mapped;
|
||||
eq?: (a: Mapped, b: Mapped) => boolean;
|
||||
});
|
||||
protected fetch(callback?: () => void): Promise<ServiceInterfaceFilled[]>;
|
||||
}
|
||||
export declare function getOwnServiceInterfaces(effects: Effects): GetServiceInterfaces;
|
||||
export declare function getOwnServiceInterfaces<Mapped>(effects: Effects, map: (interfaces: ServiceInterfaceFilled[]) => Mapped, eq?: (a: Mapped, b: Mapped) => boolean): GetServiceInterfaces<Mapped>;
|
||||
export declare function getServiceInterfaces(effects: Effects, opts: {
|
||||
packageId: PackageId;
|
||||
}): GetServiceInterfaces;
|
||||
export declare function getServiceInterfaces<Mapped>(effects: Effects, opts: {
|
||||
packageId: PackageId;
|
||||
}, map: (interfaces: ServiceInterfaceFilled[]) => Mapped, eq?: (a: Mapped, b: Mapped) => boolean): GetServiceInterfaces<Mapped>;
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetServiceInterfaces = void 0;
|
||||
exports.getOwnServiceInterfaces = getOwnServiceInterfaces;
|
||||
exports.getServiceInterfaces = getServiceInterfaces;
|
||||
const deepEqual_1 = require("./deepEqual");
|
||||
const getServiceInterface_1 = require("./getServiceInterface");
|
||||
const Watchable_1 = require("./Watchable");
|
||||
const makeManyInterfaceFilled = async ({ effects, packageId, callback, }) => {
|
||||
const serviceInterfaceValues = await effects.listServiceInterfaces({
|
||||
packageId,
|
||||
callback,
|
||||
});
|
||||
const serviceInterfacesFilled = await Promise.all(Object.values(serviceInterfaceValues).map(async (serviceInterfaceValue) => {
|
||||
const hostId = serviceInterfaceValue.addressInfo.hostId;
|
||||
const host = await effects.getHostInfo({
|
||||
packageId,
|
||||
hostId,
|
||||
callback,
|
||||
});
|
||||
if (!host) {
|
||||
throw new Error(`host ${hostId} not found!`);
|
||||
}
|
||||
return {
|
||||
...serviceInterfaceValue,
|
||||
host,
|
||||
addressInfo: (0, getServiceInterface_1.filledAddress)(host, serviceInterfaceValue.addressInfo),
|
||||
};
|
||||
}));
|
||||
return serviceInterfacesFilled;
|
||||
};
|
||||
class GetServiceInterfaces extends Watchable_1.Watchable {
|
||||
constructor(effects, opts, options) {
|
||||
super(effects, options);
|
||||
this.opts = opts;
|
||||
this.label = 'GetServiceInterfaces';
|
||||
}
|
||||
fetch(callback) {
|
||||
return makeManyInterfaceFilled({
|
||||
effects: this.effects,
|
||||
packageId: this.opts.packageId,
|
||||
callback,
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.GetServiceInterfaces = GetServiceInterfaces;
|
||||
function getOwnServiceInterfaces(effects, map, eq) {
|
||||
return new GetServiceInterfaces(effects, {}, {
|
||||
map: map ?? ((a) => a),
|
||||
eq: eq ?? ((a, b) => (0, deepEqual_1.deepEqual)(a, b)),
|
||||
});
|
||||
}
|
||||
function getServiceInterfaces(effects, opts, map, eq) {
|
||||
return new GetServiceInterfaces(effects, opts, {
|
||||
map: map ?? ((a) => a),
|
||||
eq: eq ?? ((a, b) => (0, deepEqual_1.deepEqual)(a, b)),
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=getServiceInterfaces.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getServiceInterfaces.js","sourceRoot":"","sources":["../../../../base/lib/util/getServiceInterfaces.ts"],"names":[],"mappings":";;;AAwEA,0DAaC;AAYD,oDAUC;AAzGD,2CAAuC;AACvC,+DAA6E;AAC7E,2CAAuC;AAEvC,MAAM,uBAAuB,GAAG,KAAK,EAAE,EACrC,OAAO,EACP,SAAS,EACT,QAAQ,GAKT,EAAE,EAAE;IACH,MAAM,sBAAsB,GAAG,MAAM,OAAO,CAAC,qBAAqB,CAAC;QACjE,SAAS;QACT,QAAQ;KACT,CAAC,CAAA;IAEF,MAAM,uBAAuB,GAA6B,MAAM,OAAO,CAAC,GAAG,CACzE,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,qBAAqB,EAAE,EAAE;QACxE,MAAM,MAAM,GAAG,qBAAqB,CAAC,WAAW,CAAC,MAAM,CAAA;QACvD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,WAAW,C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,EAAE,IAAI,EAAE;QACrD,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAW,CAAC;QAChC,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAA,qBAAS,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACtC,CAAC,CAAA;AACJ,CAAC"}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* A vertex (node) in a directed graph, holding metadata and a list of connected edges.
|
||||
* @typeParam VMetadata - The type of metadata stored on vertices
|
||||
* @typeParam EMetadata - The type of metadata stored on edges
|
||||
*/
|
||||
export type Vertex<VMetadata = null, EMetadata = null> = {
|
||||
metadata: VMetadata;
|
||||
edges: Array<Edge<EMetadata, VMetadata>>;
|
||||
};
|
||||
/**
|
||||
* A directed edge connecting two vertices, with its own metadata.
|
||||
* @typeParam EMetadata - The type of metadata stored on edges
|
||||
* @typeParam VMetadata - The type of metadata stored on the connected vertices
|
||||
*/
|
||||
export type Edge<EMetadata = null, VMetadata = null> = {
|
||||
metadata: EMetadata;
|
||||
from: Vertex<VMetadata, EMetadata>;
|
||||
to: Vertex<VMetadata, EMetadata>;
|
||||
};
|
||||
/**
|
||||
* A directed graph data structure supporting vertex/edge management and graph traversal algorithms
|
||||
* including breadth-first search, reverse BFS, and shortest path computation.
|
||||
*
|
||||
* @typeParam VMetadata - The type of metadata stored on vertices
|
||||
* @typeParam EMetadata - The type of metadata stored on edges
|
||||
*/
|
||||
export declare class Graph<VMetadata = null, EMetadata = null> {
|
||||
private readonly vertices;
|
||||
constructor();
|
||||
/**
|
||||
* Serializes the graph to a JSON string for debugging.
|
||||
* @param metadataRepr - Optional function to transform metadata values before serialization
|
||||
* @returns A pretty-printed JSON string of the graph structure
|
||||
*/
|
||||
dump(metadataRepr?: (metadata: VMetadata | EMetadata) => any): string;
|
||||
/**
|
||||
* Adds a new vertex to the graph, optionally connecting it to existing vertices via edges.
|
||||
* @param metadata - The metadata to attach to the new vertex
|
||||
* @param fromEdges - Edges pointing from existing vertices to this new vertex
|
||||
* @param toEdges - Edges pointing from this new vertex to existing vertices
|
||||
* @returns The newly created vertex
|
||||
*/
|
||||
addVertex(metadata: VMetadata, fromEdges: Array<Omit<Edge<EMetadata, VMetadata>, 'to'>>, toEdges: Array<Omit<Edge<EMetadata, VMetadata>, 'from'>>): Vertex<VMetadata, EMetadata>;
|
||||
/**
|
||||
* Returns a generator that yields all vertices matching the predicate.
|
||||
* @param predicate - A function to test each vertex
|
||||
* @returns A generator of matching vertices
|
||||
*/
|
||||
findVertex(predicate: (vertex: Vertex<VMetadata, EMetadata>) => boolean): Generator<Vertex<VMetadata, EMetadata>, null>;
|
||||
/**
|
||||
* Adds a directed edge between two existing vertices.
|
||||
* @param metadata - The metadata to attach to the edge
|
||||
* @param from - The source vertex
|
||||
* @param to - The destination vertex
|
||||
* @returns The newly created edge
|
||||
*/
|
||||
addEdge(metadata: EMetadata, from: Vertex<VMetadata, EMetadata>, to: Vertex<VMetadata, EMetadata>): Edge<EMetadata, VMetadata>;
|
||||
/**
|
||||
* Performs a breadth-first traversal following outgoing edges from the starting vertex or vertices.
|
||||
* @param from - A starting vertex, or a predicate to select multiple starting vertices
|
||||
* @returns A generator yielding vertices in BFS order
|
||||
*/
|
||||
breadthFirstSearch(from: Vertex<VMetadata, EMetadata> | ((vertex: Vertex<VMetadata, EMetadata>) => boolean)): Generator<Vertex<VMetadata, EMetadata>, null>;
|
||||
/**
|
||||
* Performs a reverse breadth-first traversal following incoming edges from the starting vertex or vertices.
|
||||
* @param to - A starting vertex, or a predicate to select multiple starting vertices
|
||||
* @returns A generator yielding vertices in reverse BFS order
|
||||
*/
|
||||
reverseBreadthFirstSearch(to: Vertex<VMetadata, EMetadata> | ((vertex: Vertex<VMetadata, EMetadata>) => boolean)): Generator<Vertex<VMetadata, EMetadata>, null>;
|
||||
/**
|
||||
* Finds the shortest path (by edge count) between two vertices using BFS.
|
||||
* @param from - The starting vertex, or a predicate to select starting vertices
|
||||
* @param to - The target vertex, or a predicate to identify target vertices
|
||||
* @returns An array of edges forming the shortest path, or `null` if no path exists
|
||||
*/
|
||||
shortestPath(from: Vertex<VMetadata, EMetadata> | ((vertex: Vertex<VMetadata, EMetadata>) => boolean), to: Vertex<VMetadata, EMetadata> | ((vertex: Vertex<VMetadata, EMetadata>) => boolean)): Array<Edge<EMetadata, VMetadata>> | null;
|
||||
}
|
||||
+272
@@ -0,0 +1,272 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Graph = void 0;
|
||||
/**
|
||||
* A directed graph data structure supporting vertex/edge management and graph traversal algorithms
|
||||
* including breadth-first search, reverse BFS, and shortest path computation.
|
||||
*
|
||||
* @typeParam VMetadata - The type of metadata stored on vertices
|
||||
* @typeParam EMetadata - The type of metadata stored on edges
|
||||
*/
|
||||
class Graph {
|
||||
constructor() {
|
||||
this.vertices = [];
|
||||
}
|
||||
/**
|
||||
* Serializes the graph to a JSON string for debugging.
|
||||
* @param metadataRepr - Optional function to transform metadata values before serialization
|
||||
* @returns A pretty-printed JSON string of the graph structure
|
||||
*/
|
||||
dump(metadataRepr = (a) => a) {
|
||||
const seen = new WeakSet();
|
||||
return JSON.stringify(this.vertices, (k, v) => {
|
||||
if (k === 'metadata')
|
||||
return metadataRepr(v);
|
||||
if (k === 'from')
|
||||
return metadataRepr(v.metadata);
|
||||
if (k === 'to')
|
||||
return metadataRepr(v.metadata);
|
||||
return v;
|
||||
}, 2);
|
||||
}
|
||||
/**
|
||||
* Adds a new vertex to the graph, optionally connecting it to existing vertices via edges.
|
||||
* @param metadata - The metadata to attach to the new vertex
|
||||
* @param fromEdges - Edges pointing from existing vertices to this new vertex
|
||||
* @param toEdges - Edges pointing from this new vertex to existing vertices
|
||||
* @returns The newly created vertex
|
||||
*/
|
||||
addVertex(metadata, fromEdges, toEdges) {
|
||||
const vertex = {
|
||||
metadata,
|
||||
edges: [],
|
||||
};
|
||||
for (let edge of fromEdges) {
|
||||
const vEdge = {
|
||||
metadata: edge.metadata,
|
||||
from: edge.from,
|
||||
to: vertex,
|
||||
};
|
||||
edge.from.edges.push(vEdge);
|
||||
vertex.edges.push(vEdge);
|
||||
}
|
||||
for (let edge of toEdges) {
|
||||
const vEdge = {
|
||||
metadata: edge.metadata,
|
||||
from: vertex,
|
||||
to: edge.to,
|
||||
};
|
||||
edge.to.edges.push(vEdge);
|
||||
vertex.edges.push(vEdge);
|
||||
}
|
||||
this.vertices.push(vertex);
|
||||
return vertex;
|
||||
}
|
||||
/**
|
||||
* Returns a generator that yields all vertices matching the predicate.
|
||||
* @param predicate - A function to test each vertex
|
||||
* @returns A generator of matching vertices
|
||||
*/
|
||||
findVertex(predicate) {
|
||||
const veritces = this.vertices;
|
||||
function* gen() {
|
||||
for (let vertex of veritces) {
|
||||
if (predicate(vertex)) {
|
||||
yield vertex;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return gen();
|
||||
}
|
||||
/**
|
||||
* Adds a directed edge between two existing vertices.
|
||||
* @param metadata - The metadata to attach to the edge
|
||||
* @param from - The source vertex
|
||||
* @param to - The destination vertex
|
||||
* @returns The newly created edge
|
||||
*/
|
||||
addEdge(metadata, from, to) {
|
||||
const edge = {
|
||||
metadata,
|
||||
from,
|
||||
to,
|
||||
};
|
||||
edge.from.edges.push(edge);
|
||||
edge.to.edges.push(edge);
|
||||
return edge;
|
||||
}
|
||||
/**
|
||||
* Performs a breadth-first traversal following outgoing edges from the starting vertex or vertices.
|
||||
* @param from - A starting vertex, or a predicate to select multiple starting vertices
|
||||
* @returns A generator yielding vertices in BFS order
|
||||
*/
|
||||
breadthFirstSearch(from) {
|
||||
const visited = [];
|
||||
function* rec(vertex) {
|
||||
if (visited.includes(vertex)) {
|
||||
return null;
|
||||
}
|
||||
visited.push(vertex);
|
||||
yield vertex;
|
||||
let generators = vertex.edges
|
||||
.filter((e) => e.from === vertex)
|
||||
.map((e) => rec(e.to));
|
||||
while (generators.length) {
|
||||
let prev = generators;
|
||||
generators = [];
|
||||
for (let gen of prev) {
|
||||
const next = gen.next();
|
||||
if (!next.done) {
|
||||
generators.push(gen);
|
||||
yield next.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (from instanceof Function) {
|
||||
let generators = this.vertices.filter(from).map(rec);
|
||||
return (function* () {
|
||||
while (generators.length) {
|
||||
let prev = generators;
|
||||
generators = [];
|
||||
for (let gen of prev) {
|
||||
const next = gen.next();
|
||||
if (!next.done) {
|
||||
generators.push(gen);
|
||||
yield next.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
})();
|
||||
}
|
||||
else {
|
||||
return rec(from);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Performs a reverse breadth-first traversal following incoming edges from the starting vertex or vertices.
|
||||
* @param to - A starting vertex, or a predicate to select multiple starting vertices
|
||||
* @returns A generator yielding vertices in reverse BFS order
|
||||
*/
|
||||
reverseBreadthFirstSearch(to) {
|
||||
const visited = [];
|
||||
function* rec(vertex) {
|
||||
if (visited.includes(vertex)) {
|
||||
return null;
|
||||
}
|
||||
visited.push(vertex);
|
||||
yield vertex;
|
||||
let generators = vertex.edges
|
||||
.filter((e) => e.to === vertex)
|
||||
.map((e) => rec(e.from));
|
||||
while (generators.length) {
|
||||
let prev = generators;
|
||||
generators = [];
|
||||
for (let gen of prev) {
|
||||
const next = gen.next();
|
||||
if (!next.done) {
|
||||
generators.push(gen);
|
||||
yield next.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (to instanceof Function) {
|
||||
let generators = this.vertices.filter(to).map(rec);
|
||||
return (function* () {
|
||||
while (generators.length) {
|
||||
let prev = generators;
|
||||
generators = [];
|
||||
for (let gen of prev) {
|
||||
const next = gen.next();
|
||||
if (!next.done) {
|
||||
generators.push(gen);
|
||||
yield next.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
})();
|
||||
}
|
||||
else {
|
||||
return rec(to);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Finds the shortest path (by edge count) between two vertices using BFS.
|
||||
* @param from - The starting vertex, or a predicate to select starting vertices
|
||||
* @param to - The target vertex, or a predicate to identify target vertices
|
||||
* @returns An array of edges forming the shortest path, or `null` if no path exists
|
||||
*/
|
||||
shortestPath(from, to) {
|
||||
const isDone = to instanceof Function
|
||||
? to
|
||||
: (v) => v === to;
|
||||
const path = [];
|
||||
const visited = [];
|
||||
function* check(vertex, path) {
|
||||
if (isDone(vertex)) {
|
||||
return path;
|
||||
}
|
||||
if (visited.includes(vertex)) {
|
||||
return null;
|
||||
}
|
||||
visited.push(vertex);
|
||||
yield;
|
||||
let generators = vertex.edges
|
||||
.filter((e) => e.from === vertex)
|
||||
.map((e) => check(e.to, [...path, e]));
|
||||
while (generators.length) {
|
||||
let prev = generators;
|
||||
generators = [];
|
||||
for (let gen of prev) {
|
||||
const next = gen.next();
|
||||
if (next.done === true) {
|
||||
if (next.value) {
|
||||
return next.value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
generators.push(gen);
|
||||
yield;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (from instanceof Function) {
|
||||
let generators = this.vertices.filter(from).map((v) => check(v, []));
|
||||
while (generators.length) {
|
||||
let prev = generators;
|
||||
generators = [];
|
||||
for (let gen of prev) {
|
||||
const next = gen.next();
|
||||
if (next.done === true) {
|
||||
if (next.value) {
|
||||
return next.value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
generators.push(gen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const gen = check(from, []);
|
||||
while (true) {
|
||||
const next = gen.next();
|
||||
if (next.done) {
|
||||
return next.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.Graph = Graph;
|
||||
//# sourceMappingURL=graph.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Converts a human-readable time string to milliseconds.
|
||||
* Supports units: `ms`, `s`, `m`, `h`, `d`. If a number is passed, it is returned as-is.
|
||||
*
|
||||
* @param time - A time string (e.g. `"500ms"`, `"1.5s"`, `"2h"`) or a numeric millisecond value
|
||||
* @returns The time in milliseconds, or `undefined` if `time` is falsy
|
||||
* @throws Error if the string format is invalid
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* inMs("2s") // 2000
|
||||
* inMs("1.5h") // 5400000
|
||||
* inMs(500) // 500
|
||||
* ```
|
||||
*/
|
||||
export declare const inMs: (time?: string | number) => number | undefined;
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.inMs = void 0;
|
||||
const matchTimeRegex = /^\s*(\d+)?(\.\d+)?\s*(ms|s|m|h|d)/;
|
||||
const unitMultiplier = (unit) => {
|
||||
if (!unit)
|
||||
return 1;
|
||||
if (unit === 'ms')
|
||||
return 1;
|
||||
if (unit === 's')
|
||||
return 1000;
|
||||
if (unit === 'm')
|
||||
return 1000 * 60;
|
||||
if (unit === 'h')
|
||||
return 1000 * 60 * 60;
|
||||
if (unit === 'd')
|
||||
return 1000 * 60 * 60 * 24;
|
||||
throw new Error(`Invalid unit: ${unit}`);
|
||||
};
|
||||
const digitsMs = (digits, multiplier) => {
|
||||
if (!digits)
|
||||
return 0;
|
||||
const value = parseInt(digits.slice(1));
|
||||
const divideBy = multiplier / Math.pow(10, digits.length - 1);
|
||||
return Math.round(value * divideBy);
|
||||
};
|
||||
/**
|
||||
* Converts a human-readable time string to milliseconds.
|
||||
* Supports units: `ms`, `s`, `m`, `h`, `d`. If a number is passed, it is returned as-is.
|
||||
*
|
||||
* @param time - A time string (e.g. `"500ms"`, `"1.5s"`, `"2h"`) or a numeric millisecond value
|
||||
* @returns The time in milliseconds, or `undefined` if `time` is falsy
|
||||
* @throws Error if the string format is invalid
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* inMs("2s") // 2000
|
||||
* inMs("1.5h") // 5400000
|
||||
* inMs(500) // 500
|
||||
* ```
|
||||
*/
|
||||
const inMs = (time) => {
|
||||
if (typeof time === 'number')
|
||||
return time;
|
||||
if (!time)
|
||||
return undefined;
|
||||
const matches = time.match(matchTimeRegex);
|
||||
if (!matches)
|
||||
throw new Error(`Invalid time format: ${time}`);
|
||||
const [_, leftHandSide, digits, unit] = matches;
|
||||
const multiplier = unitMultiplier(unit);
|
||||
const firstValue = parseInt(leftHandSide || '0') * multiplier;
|
||||
const secondValue = digitsMs(digits, multiplier);
|
||||
return firstValue + secondValue;
|
||||
};
|
||||
exports.inMs = inMs;
|
||||
//# sourceMappingURL=inMs.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"inMs.js","sourceRoot":"","sources":["../../../../base/lib/util/inMs.ts"],"names":[],"mappings":";;;AAAA,MAAM,cAAc,GAAG,mCAAmC,CAAA;AAE1D,MAAM,cAAc,GAAG,CAAC,IAAa,EAAE,EAAE;IACvC,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,CAAA;IACnB,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,CAAC,CAAA;IAC3B,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,IAAI,CAAA;IAC7B,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,IAAI,GAAG,EAAE,CAAA;IAClC,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA;IACvC,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;IAC5C,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAA;AAC1C,CAAC,CAAA;AACD,MAAM,QAAQ,GAAG,CAAC,MAAqB,EAAE,UAAkB,EAAE,EAAE;IAC7D,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,CAAA;IACrB,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACvC,MAAM,QAAQ,GAAG,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC7D,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAA;AACrC,CAAC,CAAA;AACD;;;;;;;;;;;;;;GAcG;AACI,MAAM,IAAI,GAAG,CAAC,IAAsB,EAAE,EAAE;IAC7C,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IACzC,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IAC1C,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAA;IAC7D,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,OAAO,CAAA;IAC/C,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;IACvC,MAAM,UAAU,GAAG,QAAQ,CAAC,YAAY,IAAI,GAAG,CAAC,GAAG,UAAU,CAAA;IAC7D,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAEhD,OAAO,UAAU,GAAG,WAAW,CAAA;AACjC,CAAC,CAAA;AAXY,QAAA,IAAI,QAWhB"}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
export { addressHostToUrl } from './getServiceInterface';
|
||||
export { getDefaultString } from './getDefaultString';
|
||||
export * from './ip';
|
||||
export { GetServiceInterface, getServiceInterface, filledAddress, filterNonLocal, } from './getServiceInterface';
|
||||
export { getServiceInterfaces } from './getServiceInterfaces';
|
||||
export { once } from './once';
|
||||
export { asError } from './asError';
|
||||
export * as Patterns from './patterns';
|
||||
export * from './typeHelpers';
|
||||
export { Watchable } from './Watchable';
|
||||
export { GetContainerIp } from './GetContainerIp';
|
||||
export { GetHostInfo } from './GetHostInfo';
|
||||
export { GetOutboundGateway } from './GetOutboundGateway';
|
||||
export { GetServiceManifest, getServiceManifest } from './GetServiceManifest';
|
||||
export { GetSslCertificate } from './GetSslCertificate';
|
||||
export { GetStatus } from './GetStatus';
|
||||
export { GetSystemSmtp } from './GetSystemSmtp';
|
||||
export { Graph, Vertex } from './graph';
|
||||
export { inMs } from './inMs';
|
||||
export { splitCommand } from './splitCommand';
|
||||
export { nullIfEmpty } from './nullIfEmpty';
|
||||
export { deepMerge, partialDiff } from './deepMerge';
|
||||
export { deepEqual } from './deepEqual';
|
||||
export { AbortedError } from './AbortedError';
|
||||
export * as regexes from './regexes';
|
||||
export { stringFromStdErrOut } from './stringFromStdErrOut';
|
||||
export { logErrorOnce } from './logErrorOnce';
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.logErrorOnce = exports.stringFromStdErrOut = exports.regexes = exports.AbortedError = exports.deepEqual = exports.partialDiff = exports.deepMerge = exports.nullIfEmpty = exports.splitCommand = exports.inMs = exports.Graph = exports.GetSystemSmtp = exports.GetStatus = exports.GetSslCertificate = exports.getServiceManifest = exports.GetServiceManifest = exports.GetOutboundGateway = exports.GetHostInfo = exports.GetContainerIp = exports.Watchable = exports.Patterns = exports.asError = exports.once = exports.getServiceInterfaces = exports.filterNonLocal = exports.filledAddress = exports.getServiceInterface = exports.GetServiceInterface = exports.getDefaultString = exports.addressHostToUrl = void 0;
|
||||
/// Currently being used
|
||||
var getServiceInterface_1 = require("./getServiceInterface");
|
||||
Object.defineProperty(exports, "addressHostToUrl", { enumerable: true, get: function () { return getServiceInterface_1.addressHostToUrl; } });
|
||||
var getDefaultString_1 = require("./getDefaultString");
|
||||
Object.defineProperty(exports, "getDefaultString", { enumerable: true, get: function () { return getDefaultString_1.getDefaultString; } });
|
||||
__exportStar(require("./ip"), exports);
|
||||
/// Not being used, but known to be browser compatible
|
||||
var getServiceInterface_2 = require("./getServiceInterface");
|
||||
Object.defineProperty(exports, "GetServiceInterface", { enumerable: true, get: function () { return getServiceInterface_2.GetServiceInterface; } });
|
||||
Object.defineProperty(exports, "getServiceInterface", { enumerable: true, get: function () { return getServiceInterface_2.getServiceInterface; } });
|
||||
Object.defineProperty(exports, "filledAddress", { enumerable: true, get: function () { return getServiceInterface_2.filledAddress; } });
|
||||
Object.defineProperty(exports, "filterNonLocal", { enumerable: true, get: function () { return getServiceInterface_2.filterNonLocal; } });
|
||||
var getServiceInterfaces_1 = require("./getServiceInterfaces");
|
||||
Object.defineProperty(exports, "getServiceInterfaces", { enumerable: true, get: function () { return getServiceInterfaces_1.getServiceInterfaces; } });
|
||||
var once_1 = require("./once");
|
||||
Object.defineProperty(exports, "once", { enumerable: true, get: function () { return once_1.once; } });
|
||||
var asError_1 = require("./asError");
|
||||
Object.defineProperty(exports, "asError", { enumerable: true, get: function () { return asError_1.asError; } });
|
||||
exports.Patterns = __importStar(require("./patterns"));
|
||||
__exportStar(require("./typeHelpers"), exports);
|
||||
var Watchable_1 = require("./Watchable");
|
||||
Object.defineProperty(exports, "Watchable", { enumerable: true, get: function () { return Watchable_1.Watchable; } });
|
||||
var GetContainerIp_1 = require("./GetContainerIp");
|
||||
Object.defineProperty(exports, "GetContainerIp", { enumerable: true, get: function () { return GetContainerIp_1.GetContainerIp; } });
|
||||
var GetHostInfo_1 = require("./GetHostInfo");
|
||||
Object.defineProperty(exports, "GetHostInfo", { enumerable: true, get: function () { return GetHostInfo_1.GetHostInfo; } });
|
||||
var GetOutboundGateway_1 = require("./GetOutboundGateway");
|
||||
Object.defineProperty(exports, "GetOutboundGateway", { enumerable: true, get: function () { return GetOutboundGateway_1.GetOutboundGateway; } });
|
||||
var GetServiceManifest_1 = require("./GetServiceManifest");
|
||||
Object.defineProperty(exports, "GetServiceManifest", { enumerable: true, get: function () { return GetServiceManifest_1.GetServiceManifest; } });
|
||||
Object.defineProperty(exports, "getServiceManifest", { enumerable: true, get: function () { return GetServiceManifest_1.getServiceManifest; } });
|
||||
var GetSslCertificate_1 = require("./GetSslCertificate");
|
||||
Object.defineProperty(exports, "GetSslCertificate", { enumerable: true, get: function () { return GetSslCertificate_1.GetSslCertificate; } });
|
||||
var GetStatus_1 = require("./GetStatus");
|
||||
Object.defineProperty(exports, "GetStatus", { enumerable: true, get: function () { return GetStatus_1.GetStatus; } });
|
||||
var GetSystemSmtp_1 = require("./GetSystemSmtp");
|
||||
Object.defineProperty(exports, "GetSystemSmtp", { enumerable: true, get: function () { return GetSystemSmtp_1.GetSystemSmtp; } });
|
||||
var graph_1 = require("./graph");
|
||||
Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return graph_1.Graph; } });
|
||||
var inMs_1 = require("./inMs");
|
||||
Object.defineProperty(exports, "inMs", { enumerable: true, get: function () { return inMs_1.inMs; } });
|
||||
var splitCommand_1 = require("./splitCommand");
|
||||
Object.defineProperty(exports, "splitCommand", { enumerable: true, get: function () { return splitCommand_1.splitCommand; } });
|
||||
var nullIfEmpty_1 = require("./nullIfEmpty");
|
||||
Object.defineProperty(exports, "nullIfEmpty", { enumerable: true, get: function () { return nullIfEmpty_1.nullIfEmpty; } });
|
||||
var deepMerge_1 = require("./deepMerge");
|
||||
Object.defineProperty(exports, "deepMerge", { enumerable: true, get: function () { return deepMerge_1.deepMerge; } });
|
||||
Object.defineProperty(exports, "partialDiff", { enumerable: true, get: function () { return deepMerge_1.partialDiff; } });
|
||||
var deepEqual_1 = require("./deepEqual");
|
||||
Object.defineProperty(exports, "deepEqual", { enumerable: true, get: function () { return deepEqual_1.deepEqual; } });
|
||||
var AbortedError_1 = require("./AbortedError");
|
||||
Object.defineProperty(exports, "AbortedError", { enumerable: true, get: function () { return AbortedError_1.AbortedError; } });
|
||||
exports.regexes = __importStar(require("./regexes"));
|
||||
var stringFromStdErrOut_1 = require("./stringFromStdErrOut");
|
||||
Object.defineProperty(exports, "stringFromStdErrOut", { enumerable: true, get: function () { return stringFromStdErrOut_1.stringFromStdErrOut; } });
|
||||
var logErrorOnce_1 = require("./logErrorOnce");
|
||||
Object.defineProperty(exports, "logErrorOnce", { enumerable: true, get: function () { return logErrorOnce_1.logErrorOnce; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../base/lib/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wBAAwB;AACxB,6DAAwD;AAA/C,uHAAA,gBAAgB,OAAA;AACzB,uDAAqD;AAA5C,oHAAA,gBAAgB,OAAA;AACzB,uCAAoB;AAEpB,sDAAsD;AACtD,6DAK8B;AAJ5B,0HAAA,mBAAmB,OAAA;AACnB,0HAAA,mBAAmB,OAAA;AACnB,oHAAA,aAAa,OAAA;AACb,qHAAA,cAAc,OAAA;AAEhB,+DAA6D;AAApD,4HAAA,oBAAoB,OAAA;AAC7B,+BAA6B;AAApB,4FAAA,IAAI,OAAA;AACb,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,uDAAsC;AACtC,gDAA6B;AAC7B,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAClB,mDAAiD;AAAxC,gHAAA,cAAc,OAAA;AACvB,6CAA2C;AAAlC,0GAAA,WAAW,OAAA;AACpB,2DAAyD;AAAhD,wHAAA,kBAAkB,OAAA;AAC3B,2DAA6E;AAApE,wHAAA,kBAAkB,OAAA;AAAE,wHAAA,kBAAkB,OAAA;AAC/C,yDAAuD;AAA9C,sHAAA,iBAAiB,OAAA;AAC1B,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAClB,iDAA+C;AAAtC,8GAAA,aAAa,OAAA;AACtB,iCAAuC;AAA9B,8FAAA,KAAK,OAAA;AACd,+BAA6B;AAApB,4FAAA,IAAI,OAAA;AACb,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,6CAA2C;AAAlC,0GAAA,WAAW,OAAA;AACpB,yCAAoD;AAA3C,sGAAA,SAAS,OAAA;AAAE,wGAAA,WAAW,OAAA;AAC/B,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAClB,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,qDAAoC;AACpC,6DAA2D;AAAlD,0HAAA,mBAAmB,OAAA;AAC5B,+CAA6C;AAApC,4GAAA,YAAY,OAAA"}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Represents an IPv4 or IPv6 address as raw octets with arithmetic and comparison operations.
|
||||
*
|
||||
* IPv4 addresses have 4 octets, IPv6 addresses have 16 octets.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const ip = IpAddress.parse("192.168.1.1")
|
||||
* const next = ip.add(1) // 192.168.1.2
|
||||
* ```
|
||||
*/
|
||||
export declare class IpAddress {
|
||||
octets: number[];
|
||||
private renderedAddress;
|
||||
private renderedOctets;
|
||||
protected constructor(octets: number[], renderedAddress: string);
|
||||
/**
|
||||
* Parses an IP address string into an IpAddress instance.
|
||||
* Supports both IPv4 dotted-decimal and IPv6 colon-hex notation (including `::` shorthand).
|
||||
* @param address - The IP address string to parse
|
||||
* @returns A new IpAddress instance
|
||||
* @throws Error if the address format is invalid
|
||||
*/
|
||||
static parse(address: string): IpAddress;
|
||||
/**
|
||||
* Creates an IpAddress from a raw octet array.
|
||||
* @param octets - Array of 4 octets (IPv4) or 16 octets (IPv6), each 0-255
|
||||
* @returns A new IpAddress instance
|
||||
* @throws Error if the octet array length is not 4 or 16, or any octet exceeds 255
|
||||
*/
|
||||
static fromOctets(octets: number[]): IpAddress;
|
||||
/** Returns true if this is an IPv4 address (4 octets). */
|
||||
isIpv4(): boolean;
|
||||
/** Returns true if this is an IPv6 address (16 octets). */
|
||||
isIpv6(): boolean;
|
||||
/** Returns true if this is a public IPv4 address (not in any private range). */
|
||||
isPublic(): boolean;
|
||||
/**
|
||||
* Returns a new IpAddress incremented by `n`.
|
||||
* @param n - The integer amount to add (fractional part is truncated)
|
||||
* @returns A new IpAddress with the result
|
||||
* @throws Error on overflow
|
||||
*/
|
||||
add(n: number): IpAddress;
|
||||
/**
|
||||
* Returns a new IpAddress decremented by `n`.
|
||||
* @param n - The integer amount to subtract (fractional part is truncated)
|
||||
* @returns A new IpAddress with the result
|
||||
* @throws Error on underflow
|
||||
*/
|
||||
sub(n: number): IpAddress;
|
||||
/**
|
||||
* Compares this address to another, returning -1, 0, or 1.
|
||||
* @param other - An IpAddress instance or string to compare against
|
||||
* @returns -1 if this < other, 0 if equal, 1 if this > other
|
||||
*/
|
||||
cmp(other: string | IpAddress): -1 | 0 | 1;
|
||||
/** The string representation of this IP address (e.g. `"192.168.1.1"` or `"::1"`). Cached and recomputed only when octets change. */
|
||||
get address(): string;
|
||||
}
|
||||
/**
|
||||
* Represents an IP network (CIDR notation) combining an IP address with a prefix length.
|
||||
* Extends IpAddress with network-specific operations like containment checks and broadcast calculation.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const net = IpNet.parse("192.168.1.0/24")
|
||||
* net.contains("192.168.1.100") // true
|
||||
* net.broadcast() // 192.168.1.255
|
||||
* ```
|
||||
*/
|
||||
export declare class IpNet extends IpAddress {
|
||||
prefix: number;
|
||||
private constructor();
|
||||
/**
|
||||
* Creates an IpNet from an IpAddress and prefix length.
|
||||
* @param ip - The base IP address
|
||||
* @param prefix - The CIDR prefix length (0-32 for IPv4, 0-128 for IPv6)
|
||||
* @returns A new IpNet instance
|
||||
* @throws Error if prefix exceeds the address bit length
|
||||
*/
|
||||
static fromIpPrefix(ip: IpAddress, prefix: number): IpNet;
|
||||
/**
|
||||
* Parses a CIDR notation string (e.g. `"192.168.1.0/24"`) into an IpNet.
|
||||
* @param ipnet - The CIDR string to parse
|
||||
* @returns A new IpNet instance
|
||||
*/
|
||||
static parse(ipnet: string): IpNet;
|
||||
/**
|
||||
* Checks whether this network contains the given address or subnet.
|
||||
* @param address - An IP address or subnet (string, IpAddress, or IpNet)
|
||||
* @returns True if the address falls within this network's range
|
||||
*/
|
||||
contains(address: string | IpAddress | IpNet): boolean;
|
||||
/** Returns the network address (all host bits zeroed) for this subnet. */
|
||||
zero(): IpAddress;
|
||||
/** Returns the broadcast address (all host bits set to 1) for this subnet. */
|
||||
broadcast(): IpAddress;
|
||||
/** The CIDR notation string for this network (e.g. `"192.168.1.0/24"`). */
|
||||
get ipnet(): string;
|
||||
}
|
||||
/** All private IPv4 ranges: loopback (127.0.0.0/8), Class A (10.0.0.0/8), Class B (172.16.0.0/12), Class C (192.168.0.0/16). */
|
||||
export declare const PRIVATE_IPV4_RANGES: IpNet[];
|
||||
/** IPv4 loopback network (127.0.0.0/8). */
|
||||
export declare const IPV4_LOOPBACK: IpNet;
|
||||
/** IPv6 loopback address (::1/128). */
|
||||
export declare const IPV6_LOOPBACK: IpNet;
|
||||
/** IPv6 link-local network (fe80::/10). */
|
||||
export declare const IPV6_LINK_LOCAL: IpNet;
|
||||
/** Carrier-Grade NAT (CGNAT) address range (100.64.0.0/10), per RFC 6598. */
|
||||
export declare const CGNAT: IpNet;
|
||||
+338
@@ -0,0 +1,338 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CGNAT = exports.IPV6_LINK_LOCAL = exports.IPV6_LOOPBACK = exports.IPV4_LOOPBACK = exports.PRIVATE_IPV4_RANGES = exports.IpNet = exports.IpAddress = void 0;
|
||||
/**
|
||||
* Represents an IPv4 or IPv6 address as raw octets with arithmetic and comparison operations.
|
||||
*
|
||||
* IPv4 addresses have 4 octets, IPv6 addresses have 16 octets.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const ip = IpAddress.parse("192.168.1.1")
|
||||
* const next = ip.add(1) // 192.168.1.2
|
||||
* ```
|
||||
*/
|
||||
class IpAddress {
|
||||
constructor(octets, renderedAddress) {
|
||||
this.octets = octets;
|
||||
this.renderedAddress = renderedAddress;
|
||||
this.renderedOctets = [...octets];
|
||||
}
|
||||
/**
|
||||
* Parses an IP address string into an IpAddress instance.
|
||||
* Supports both IPv4 dotted-decimal and IPv6 colon-hex notation (including `::` shorthand).
|
||||
* @param address - The IP address string to parse
|
||||
* @returns A new IpAddress instance
|
||||
* @throws Error if the address format is invalid
|
||||
*/
|
||||
static parse(address) {
|
||||
let octets;
|
||||
if (address.includes(':')) {
|
||||
octets = new Array(16).fill(0);
|
||||
const segs = address.split(':');
|
||||
let idx = 0;
|
||||
let octIdx = 0;
|
||||
while (segs[idx]) {
|
||||
const num = parseInt(segs[idx], 16);
|
||||
octets[octIdx++] = num >> 8;
|
||||
octets[octIdx++] = num & 255;
|
||||
idx += 1;
|
||||
}
|
||||
const lastSegIdx = segs.length - 1;
|
||||
if (idx < lastSegIdx) {
|
||||
idx = lastSegIdx;
|
||||
octIdx = 15;
|
||||
while (segs[idx]) {
|
||||
const num = parseInt(segs[idx], 16);
|
||||
octets[octIdx--] = num & 255;
|
||||
octets[octIdx--] = num >> 8;
|
||||
idx -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
octets = address.split('.').map(Number);
|
||||
if (octets.length !== 4)
|
||||
throw new Error('invalid ipv4 address');
|
||||
}
|
||||
if (octets.some((o) => isNaN(o) || o > 255)) {
|
||||
throw new Error('invalid ip address');
|
||||
}
|
||||
return new IpAddress(octets, address);
|
||||
}
|
||||
/**
|
||||
* Creates an IpAddress from a raw octet array.
|
||||
* @param octets - Array of 4 octets (IPv4) or 16 octets (IPv6), each 0-255
|
||||
* @returns A new IpAddress instance
|
||||
* @throws Error if the octet array length is not 4 or 16, or any octet exceeds 255
|
||||
*/
|
||||
static fromOctets(octets) {
|
||||
if (octets.length == 4) {
|
||||
if (octets.some((o) => o > 255)) {
|
||||
throw new Error('invalid ip address');
|
||||
}
|
||||
return new IpAddress(octets, octets.join('.'));
|
||||
}
|
||||
else if (octets.length == 16) {
|
||||
if (octets.some((o) => o > 255)) {
|
||||
throw new Error('invalid ip address');
|
||||
}
|
||||
let pre = octets.slice(0, 8);
|
||||
while (pre[pre.length - 1] == 0) {
|
||||
pre.pop();
|
||||
}
|
||||
let post = octets.slice(8);
|
||||
while (post[0] == 0) {
|
||||
post.unshift();
|
||||
}
|
||||
if (pre.length + post.length == 16) {
|
||||
return new IpAddress(octets, octets.join(':'));
|
||||
}
|
||||
else {
|
||||
return new IpAddress(octets, pre.join(':') + '::' + post.join(':'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error('invalid ip address');
|
||||
}
|
||||
}
|
||||
/** Returns true if this is an IPv4 address (4 octets). */
|
||||
isIpv4() {
|
||||
return this.octets.length === 4;
|
||||
}
|
||||
/** Returns true if this is an IPv6 address (16 octets). */
|
||||
isIpv6() {
|
||||
return this.octets.length === 16;
|
||||
}
|
||||
/** Returns true if this is a public IPv4 address (not in any private range). */
|
||||
isPublic() {
|
||||
return this.isIpv4() && !exports.PRIVATE_IPV4_RANGES.some((r) => r.contains(this));
|
||||
}
|
||||
/**
|
||||
* Returns a new IpAddress incremented by `n`.
|
||||
* @param n - The integer amount to add (fractional part is truncated)
|
||||
* @returns A new IpAddress with the result
|
||||
* @throws Error on overflow
|
||||
*/
|
||||
add(n) {
|
||||
let octets = [...this.octets];
|
||||
n = Math.floor(n);
|
||||
for (let i = octets.length - 1; i >= 0; i--) {
|
||||
octets[i] += n;
|
||||
if (octets[i] > 255) {
|
||||
n = octets[i] >> 8;
|
||||
octets[i] &= 255;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (octets[0] > 255) {
|
||||
throw new Error('overflow incrementing ip');
|
||||
}
|
||||
return IpAddress.fromOctets(octets);
|
||||
}
|
||||
/**
|
||||
* Returns a new IpAddress decremented by `n`.
|
||||
* @param n - The integer amount to subtract (fractional part is truncated)
|
||||
* @returns A new IpAddress with the result
|
||||
* @throws Error on underflow
|
||||
*/
|
||||
sub(n) {
|
||||
let octets = [...this.octets];
|
||||
n = Math.floor(n);
|
||||
for (let i = octets.length - 1; i >= 0; i--) {
|
||||
octets[i] -= n;
|
||||
if (octets[i] < 0) {
|
||||
n = Math.ceil(Math.abs(octets[i]) / 256);
|
||||
octets[i] = ((octets[i] % 256) + 256) % 256;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (octets[0] < 0) {
|
||||
throw new Error('underflow decrementing ip');
|
||||
}
|
||||
return IpAddress.fromOctets(octets);
|
||||
}
|
||||
/**
|
||||
* Compares this address to another, returning -1, 0, or 1.
|
||||
* @param other - An IpAddress instance or string to compare against
|
||||
* @returns -1 if this < other, 0 if equal, 1 if this > other
|
||||
*/
|
||||
cmp(other) {
|
||||
if (typeof other === 'string')
|
||||
other = IpAddress.parse(other);
|
||||
const len = Math.max(this.octets.length, other.octets.length);
|
||||
for (let i = 0; i < len; i++) {
|
||||
const left = this.octets[i] || 0;
|
||||
const right = other.octets[i] || 0;
|
||||
if (left > right) {
|
||||
return 1;
|
||||
}
|
||||
else if (left < right) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/** The string representation of this IP address (e.g. `"192.168.1.1"` or `"::1"`). Cached and recomputed only when octets change. */
|
||||
get address() {
|
||||
if (this.renderedOctets.length === this.octets.length &&
|
||||
this.renderedOctets.every((o, idx) => o === this.octets[idx])) {
|
||||
// already rendered
|
||||
}
|
||||
else if (this.octets.length === 4) {
|
||||
this.renderedAddress = this.octets.join('.');
|
||||
this.renderedOctets = [...this.octets];
|
||||
}
|
||||
else if (this.octets.length === 16) {
|
||||
const contigZeros = this.octets.reduce((acc, x, idx) => {
|
||||
if (x === 0) {
|
||||
acc.current++;
|
||||
}
|
||||
else {
|
||||
acc.current = 0;
|
||||
}
|
||||
if (acc.current > acc.end - acc.start) {
|
||||
acc.end = idx + 1;
|
||||
acc.start = acc.end - acc.current;
|
||||
}
|
||||
return acc;
|
||||
}, { start: 0, end: 0, current: 0 });
|
||||
if (contigZeros.end - contigZeros.start >= 2) {
|
||||
return `${this.octets.slice(0, contigZeros.start).join(':')}::${this.octets.slice(contigZeros.end).join(':')}`;
|
||||
}
|
||||
this.renderedAddress = this.octets.join(':');
|
||||
this.renderedOctets = [...this.octets];
|
||||
}
|
||||
else {
|
||||
console.warn('invalid octet length for IpAddress', this.octets);
|
||||
}
|
||||
return this.renderedAddress;
|
||||
}
|
||||
}
|
||||
exports.IpAddress = IpAddress;
|
||||
/**
|
||||
* Represents an IP network (CIDR notation) combining an IP address with a prefix length.
|
||||
* Extends IpAddress with network-specific operations like containment checks and broadcast calculation.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const net = IpNet.parse("192.168.1.0/24")
|
||||
* net.contains("192.168.1.100") // true
|
||||
* net.broadcast() // 192.168.1.255
|
||||
* ```
|
||||
*/
|
||||
class IpNet extends IpAddress {
|
||||
constructor(octets, prefix, address) {
|
||||
super(octets, address);
|
||||
this.prefix = prefix;
|
||||
}
|
||||
/**
|
||||
* Creates an IpNet from an IpAddress and prefix length.
|
||||
* @param ip - The base IP address
|
||||
* @param prefix - The CIDR prefix length (0-32 for IPv4, 0-128 for IPv6)
|
||||
* @returns A new IpNet instance
|
||||
* @throws Error if prefix exceeds the address bit length
|
||||
*/
|
||||
static fromIpPrefix(ip, prefix) {
|
||||
if (prefix > ip.octets.length * 8) {
|
||||
throw new Error('invalid prefix');
|
||||
}
|
||||
return new IpNet(ip.octets, prefix, ip.address);
|
||||
}
|
||||
/**
|
||||
* Parses a CIDR notation string (e.g. `"192.168.1.0/24"`) into an IpNet.
|
||||
* @param ipnet - The CIDR string to parse
|
||||
* @returns A new IpNet instance
|
||||
*/
|
||||
static parse(ipnet) {
|
||||
const [address, prefixStr] = ipnet.split('/', 2);
|
||||
const ip = IpAddress.parse(address);
|
||||
const prefix = Number(prefixStr);
|
||||
return IpNet.fromIpPrefix(ip, prefix);
|
||||
}
|
||||
/**
|
||||
* Checks whether this network contains the given address or subnet.
|
||||
* @param address - An IP address or subnet (string, IpAddress, or IpNet)
|
||||
* @returns True if the address falls within this network's range
|
||||
*/
|
||||
contains(address) {
|
||||
if (typeof address === 'string')
|
||||
address = IpAddress.parse(address);
|
||||
if (address instanceof IpNet && address.prefix < this.prefix)
|
||||
return false;
|
||||
if (this.octets.length !== address.octets.length)
|
||||
return false;
|
||||
let prefix = this.prefix;
|
||||
let idx = 0;
|
||||
while (idx < this.octets.length && prefix >= 8) {
|
||||
if (this.octets[idx] !== address.octets[idx]) {
|
||||
return false;
|
||||
}
|
||||
idx += 1;
|
||||
prefix -= 8;
|
||||
}
|
||||
if (prefix === 0 || idx >= this.octets.length)
|
||||
return true;
|
||||
const mask = 255 ^ (255 >> prefix);
|
||||
return (this.octets[idx] & mask) === (address.octets[idx] & mask);
|
||||
}
|
||||
/** Returns the network address (all host bits zeroed) for this subnet. */
|
||||
zero() {
|
||||
let octets = [];
|
||||
let prefix = this.prefix;
|
||||
for (let idx = 0; idx < this.octets.length; idx++) {
|
||||
if (prefix >= 8) {
|
||||
octets[idx] = this.octets[idx];
|
||||
prefix -= 8;
|
||||
}
|
||||
else {
|
||||
const mask = 255 ^ (255 >> prefix);
|
||||
octets[idx] = this.octets[idx] & mask;
|
||||
prefix = 0;
|
||||
}
|
||||
}
|
||||
return IpAddress.fromOctets(octets);
|
||||
}
|
||||
/** Returns the broadcast address (all host bits set to 1) for this subnet. */
|
||||
broadcast() {
|
||||
let octets = [];
|
||||
let prefix = this.prefix;
|
||||
for (let idx = 0; idx < this.octets.length; idx++) {
|
||||
if (prefix >= 8) {
|
||||
octets[idx] = this.octets[idx];
|
||||
prefix -= 8;
|
||||
}
|
||||
else {
|
||||
const mask = 255 >> prefix;
|
||||
octets[idx] = this.octets[idx] | mask;
|
||||
prefix = 0;
|
||||
}
|
||||
}
|
||||
return IpAddress.fromOctets(octets);
|
||||
}
|
||||
/** The CIDR notation string for this network (e.g. `"192.168.1.0/24"`). */
|
||||
get ipnet() {
|
||||
return `${this.address}/${this.prefix}`;
|
||||
}
|
||||
}
|
||||
exports.IpNet = IpNet;
|
||||
/** All private IPv4 ranges: loopback (127.0.0.0/8), Class A (10.0.0.0/8), Class B (172.16.0.0/12), Class C (192.168.0.0/16). */
|
||||
exports.PRIVATE_IPV4_RANGES = [
|
||||
IpNet.parse('127.0.0.0/8'),
|
||||
IpNet.parse('10.0.0.0/8'),
|
||||
IpNet.parse('172.16.0.0/12'),
|
||||
IpNet.parse('192.168.0.0/16'),
|
||||
];
|
||||
/** IPv4 loopback network (127.0.0.0/8). */
|
||||
exports.IPV4_LOOPBACK = IpNet.parse('127.0.0.0/8');
|
||||
/** IPv6 loopback address (::1/128). */
|
||||
exports.IPV6_LOOPBACK = IpNet.parse('::1/128');
|
||||
/** IPv6 link-local network (fe80::/10). */
|
||||
exports.IPV6_LINK_LOCAL = IpNet.parse('fe80::/10');
|
||||
/** Carrier-Grade NAT (CGNAT) address range (100.64.0.0/10), per RFC 6598. */
|
||||
exports.CGNAT = IpNet.parse('100.64.0.0/10');
|
||||
//# sourceMappingURL=ip.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
||||
export declare function logErrorOnce(err: unknown): void;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.logErrorOnce = logErrorOnce;
|
||||
const loggedErrors = new WeakSet();
|
||||
function logErrorOnce(err) {
|
||||
if (typeof err === 'object' && err !== null) {
|
||||
if (loggedErrors.has(err))
|
||||
return;
|
||||
loggedErrors.add(err);
|
||||
}
|
||||
console.error(err);
|
||||
}
|
||||
//# sourceMappingURL=logErrorOnce.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"logErrorOnce.js","sourceRoot":"","sources":["../../../../base/lib/util/logErrorOnce.ts"],"names":[],"mappings":";;AAEA,oCAMC;AARD,MAAM,YAAY,GAAG,IAAI,OAAO,EAAU,CAAA;AAE1C,SAAgB,YAAY,CAAC,GAAY;IACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAM;QACjC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACvB,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AACpB,CAAC"}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* A useful tool when doing a getInputSpec.
|
||||
* Look into the inputSpec {@link FileHelper} for an example of the use.
|
||||
* @param s
|
||||
* @returns
|
||||
*/
|
||||
export declare function nullIfEmpty<A extends Record<string, any>>(s: null | A): A | null;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.nullIfEmpty = nullIfEmpty;
|
||||
/**
|
||||
* A useful tool when doing a getInputSpec.
|
||||
* Look into the inputSpec {@link FileHelper} for an example of the use.
|
||||
* @param s
|
||||
* @returns
|
||||
*/
|
||||
function nullIfEmpty(s) {
|
||||
if (s === null)
|
||||
return null;
|
||||
return Object.keys(s).length === 0 ? null : s;
|
||||
}
|
||||
//# sourceMappingURL=nullIfEmpty.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"nullIfEmpty.js","sourceRoot":"","sources":["../../../../base/lib/util/nullIfEmpty.ts"],"names":[],"mappings":";;AAMA,kCAGC;AATD;;;;;GAKG;AACH,SAAgB,WAAW,CAAgC,CAAW;IACpE,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC3B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAC/C,CAAC"}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Wraps a function so it is only executed once. Subsequent calls return the cached result.
|
||||
*
|
||||
* @param fn - The function to execute at most once
|
||||
* @returns A wrapper that lazily evaluates `fn` on first call and caches the result
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const getConfig = once(() => loadExpensiveConfig())
|
||||
* getConfig() // loads config
|
||||
* getConfig() // returns cached result
|
||||
* ```
|
||||
*/
|
||||
export declare function once<B>(fn: () => B): () => B;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.once = once;
|
||||
/**
|
||||
* Wraps a function so it is only executed once. Subsequent calls return the cached result.
|
||||
*
|
||||
* @param fn - The function to execute at most once
|
||||
* @returns A wrapper that lazily evaluates `fn` on first call and caches the result
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const getConfig = once(() => loadExpensiveConfig())
|
||||
* getConfig() // loads config
|
||||
* getConfig() // returns cached result
|
||||
* ```
|
||||
*/
|
||||
function once(fn) {
|
||||
let result = [];
|
||||
return () => {
|
||||
if (!result.length) {
|
||||
result = [fn()];
|
||||
}
|
||||
return result[0];
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=once.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"once.js","sourceRoot":"","sources":["../../../../base/lib/util/once.ts"],"names":[],"mappings":";;AAaA,oBAQC;AArBD;;;;;;;;;;;;GAYG;AACH,SAAgB,IAAI,CAAI,EAAW;IACjC,IAAI,MAAM,GAAa,EAAE,CAAA;IACzB,OAAO,GAAG,EAAE;QACV,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;QACjB,CAAC;QACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAA;IAClB,CAAC,CAAA;AACH,CAAC"}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { Pattern } from '../actions/input/inputSpecTypes';
|
||||
/** Pattern for validating IPv6 addresses. */
|
||||
export declare const ipv6: Pattern;
|
||||
/** Pattern for validating IPv4 addresses. */
|
||||
export declare const ipv4: Pattern;
|
||||
/** Pattern for validating hostnames (RFC-compliant). */
|
||||
export declare const hostname: Pattern;
|
||||
/** Pattern for validating `.local` mDNS hostnames. */
|
||||
export declare const localHostname: Pattern;
|
||||
/** Pattern for validating HTTP/HTTPS URLs. */
|
||||
export declare const url: Pattern;
|
||||
/** Pattern for validating `.local` URLs (mDNS/LAN). */
|
||||
export declare const localUrl: Pattern;
|
||||
/** Pattern for validating ASCII-only strings (printable characters). */
|
||||
export declare const ascii: Pattern;
|
||||
/** Pattern for validating fully qualified domain names (FQDNs). */
|
||||
export declare const domain: Pattern;
|
||||
/** Pattern for validating email addresses. */
|
||||
export declare const email: Pattern;
|
||||
/** Pattern for validating email addresses, optionally with a display name (e.g. `"John Doe <john@example.com>"`). */
|
||||
export declare const emailWithName: Pattern;
|
||||
/** Pattern for validating base64-encoded strings. */
|
||||
export declare const base64: Pattern;
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.base64 = exports.emailWithName = exports.email = exports.domain = exports.ascii = exports.localUrl = exports.url = exports.localHostname = exports.hostname = exports.ipv4 = exports.ipv6 = void 0;
|
||||
const regexes = __importStar(require("./regexes"));
|
||||
/** Pattern for validating IPv6 addresses. */
|
||||
exports.ipv6 = {
|
||||
regex: regexes.ipv6.matches(),
|
||||
description: 'Must be a valid IPv6 address',
|
||||
};
|
||||
/** Pattern for validating IPv4 addresses. */
|
||||
exports.ipv4 = {
|
||||
regex: regexes.ipv4.matches(),
|
||||
description: 'Must be a valid IPv4 address',
|
||||
};
|
||||
/** Pattern for validating hostnames (RFC-compliant). */
|
||||
exports.hostname = {
|
||||
regex: regexes.hostname.matches(),
|
||||
description: 'Must be a valid hostname',
|
||||
};
|
||||
/** Pattern for validating `.local` mDNS hostnames. */
|
||||
exports.localHostname = {
|
||||
regex: regexes.localHostname.matches(),
|
||||
description: 'Must be a valid ".local" hostname',
|
||||
};
|
||||
/** Pattern for validating HTTP/HTTPS URLs. */
|
||||
exports.url = {
|
||||
regex: regexes.url.matches(),
|
||||
description: 'Must be a valid URL',
|
||||
};
|
||||
/** Pattern for validating `.local` URLs (mDNS/LAN). */
|
||||
exports.localUrl = {
|
||||
regex: regexes.localUrl.matches(),
|
||||
description: 'Must be a valid ".local" URL',
|
||||
};
|
||||
/** Pattern for validating ASCII-only strings (printable characters). */
|
||||
exports.ascii = {
|
||||
regex: regexes.ascii.matches(),
|
||||
description: 'May only contain ASCII characters. See https://www.w3schools.com/charsets/ref_html_ascii.asp',
|
||||
};
|
||||
/** Pattern for validating fully qualified domain names (FQDNs). */
|
||||
exports.domain = {
|
||||
regex: regexes.domain.matches(),
|
||||
description: 'Must be a valid Fully Qualified Domain Name',
|
||||
};
|
||||
/** Pattern for validating email addresses. */
|
||||
exports.email = {
|
||||
regex: regexes.email.matches(),
|
||||
description: 'Must be a valid email address',
|
||||
};
|
||||
/** Pattern for validating email addresses, optionally with a display name (e.g. `"John Doe <john@example.com>"`). */
|
||||
exports.emailWithName = {
|
||||
regex: regexes.emailWithName.matches(),
|
||||
description: 'Must be a valid email address, optionally with a name',
|
||||
};
|
||||
/** Pattern for validating base64-encoded strings. */
|
||||
exports.base64 = {
|
||||
regex: regexes.base64.matches(),
|
||||
description: 'May only contain base64 characters. See https://base64.guru/learn/base64-characters',
|
||||
};
|
||||
//# sourceMappingURL=patterns.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../../../base/lib/util/patterns.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAAoC;AAEpC,6CAA6C;AAChC,QAAA,IAAI,GAAY;IAC3B,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE;IAC7B,WAAW,EAAE,8BAA8B;CAC5C,CAAA;AAED,6CAA6C;AAChC,QAAA,IAAI,GAAY;IAC3B,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE;IAC7B,WAAW,EAAE,8BAA8B;CAC5C,CAAA;AAED,wDAAwD;AAC3C,QAAA,QAAQ,GAAY;IAC/B,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE;IACjC,WAAW,EAAE,0BAA0B;CACxC,CAAA;AAED,sDAAsD;AACzC,QAAA,aAAa,GAAY;IACpC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE;IACtC,WAAW,EAAE,mCAAmC;CACjD,CAAA;AAED,8CAA8C;AACjC,QAAA,GAAG,GAAY;IAC1B,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE;IAC5B,WAAW,EAAE,qBAAqB;CACnC,CAAA;AAED,uDAAuD;AAC1C,QAAA,QAAQ,GAAY;IAC/B,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE;IACjC,WAAW,EAAE,8BAA8B;CAC5C,CAAA;AAED,wEAAwE;AAC3D,QAAA,KAAK,GAAY;IAC5B,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE;IAC9B,WAAW,EACT,8FAA8F;CACjG,CAAA;AAED,mEAAmE;AACtD,QAAA,MAAM,GAAY;IAC7B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE;IAC/B,WAAW,EAAE,6CAA6C;CAC3D,CAAA;AAED,8CAA8C;AACjC,QAAA,KAAK,GAAY;IAC5B,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE;IAC9B,WAAW,EAAE,+BAA+B;CAC7C,CAAA;AAED,qHAAqH;AACxG,QAAA,aAAa,GAAY;IACpC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE;IACtC,WAAW,EAAE,uDAAuD;CACrE,CAAA;AAED,qDAAqD;AACxC,QAAA,MAAM,GAAY;IAC7B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE;IAC/B,WAAW,EACT,qFAAqF;CACxF,CAAA"}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* A wrapper around RegExp that supports composition into larger patterns.
|
||||
* Provides helpers to produce anchored (full-match), grouped (sub-expression),
|
||||
* and unanchored (contains) regex source strings.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const digit = new ComposableRegex(/\d+/)
|
||||
* digit.matches() // "^\\d+$"
|
||||
* digit.contains() // "\\d+"
|
||||
* digit.asExpr() // "(\\d+)"
|
||||
* ```
|
||||
*/
|
||||
export declare class ComposableRegex {
|
||||
readonly regex: RegExp;
|
||||
constructor(regex: RegExp | string);
|
||||
/** Returns the regex source wrapped in a capturing group, suitable for embedding in a larger expression. */
|
||||
asExpr(): string;
|
||||
/** Returns the regex source anchored with `^...$` for full-string matching. */
|
||||
matches(): string;
|
||||
/** Returns the raw regex source string for substring/containment matching. */
|
||||
contains(): string;
|
||||
}
|
||||
/**
|
||||
* Escapes all regex special characters in a string so it can be used as a literal in a RegExp.
|
||||
* @param str - The string to escape
|
||||
* @returns The escaped string safe for regex interpolation
|
||||
*/
|
||||
export declare const escapeLiteral: (str: string) => string;
|
||||
/** Composable regex for matching IPv6 addresses (all standard forms including `::` shorthand). */
|
||||
export declare const ipv6: ComposableRegex;
|
||||
/** Composable regex for matching IPv4 addresses in dotted-decimal notation. */
|
||||
export declare const ipv4: ComposableRegex;
|
||||
/** Composable regex for matching RFC-compliant hostnames. */
|
||||
export declare const hostname: ComposableRegex;
|
||||
/** Composable regex for matching `.local` mDNS hostnames. */
|
||||
export declare const localHostname: ComposableRegex;
|
||||
/** Composable regex for matching HTTP/HTTPS URLs. */
|
||||
export declare const url: ComposableRegex;
|
||||
/** Composable regex for matching `.local` URLs (mDNS/LAN). */
|
||||
export declare const localUrl: ComposableRegex;
|
||||
/** Composable regex for matching printable ASCII characters (space through tilde). */
|
||||
export declare const ascii: ComposableRegex;
|
||||
/** Composable regex for matching fully qualified domain names. */
|
||||
export declare const domain: ComposableRegex;
|
||||
/** Composable regex for matching email addresses. */
|
||||
export declare const email: ComposableRegex;
|
||||
/** Composable regex for matching email addresses optionally preceded by a display name (e.g. `"Name <email>"`). */
|
||||
export declare const emailWithName: ComposableRegex;
|
||||
/** Composable regex for matching base64-encoded strings (no whitespace). */
|
||||
export declare const base64: ComposableRegex;
|
||||
/** Composable regex for matching base64-encoded strings that may contain interspersed whitespace. */
|
||||
export declare const base64Whitespace: ComposableRegex;
|
||||
/**
|
||||
* Creates a composable regex for matching PEM-encoded blocks with the given label.
|
||||
* @param label - The PEM label (e.g. `"CERTIFICATE"`, `"RSA PRIVATE KEY"`)
|
||||
* @returns A ComposableRegex matching `-----BEGIN <label>-----...-----END <label>-----`
|
||||
*/
|
||||
export declare const pem: (label: string) => ComposableRegex;
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.pem = exports.base64Whitespace = exports.base64 = exports.emailWithName = exports.email = exports.domain = exports.ascii = exports.localUrl = exports.url = exports.localHostname = exports.hostname = exports.ipv4 = exports.ipv6 = exports.escapeLiteral = exports.ComposableRegex = void 0;
|
||||
/**
|
||||
* A wrapper around RegExp that supports composition into larger patterns.
|
||||
* Provides helpers to produce anchored (full-match), grouped (sub-expression),
|
||||
* and unanchored (contains) regex source strings.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const digit = new ComposableRegex(/\d+/)
|
||||
* digit.matches() // "^\\d+$"
|
||||
* digit.contains() // "\\d+"
|
||||
* digit.asExpr() // "(\\d+)"
|
||||
* ```
|
||||
*/
|
||||
class ComposableRegex {
|
||||
constructor(regex) {
|
||||
if (regex instanceof RegExp) {
|
||||
this.regex = regex;
|
||||
}
|
||||
else {
|
||||
this.regex = new RegExp(regex);
|
||||
}
|
||||
}
|
||||
/** Returns the regex source wrapped in a capturing group, suitable for embedding in a larger expression. */
|
||||
asExpr() {
|
||||
return `(${this.regex.source})`;
|
||||
}
|
||||
/** Returns the regex source anchored with `^...$` for full-string matching. */
|
||||
matches() {
|
||||
return `^${this.regex.source}$`;
|
||||
}
|
||||
/** Returns the raw regex source string for substring/containment matching. */
|
||||
contains() {
|
||||
return this.regex.source;
|
||||
}
|
||||
}
|
||||
exports.ComposableRegex = ComposableRegex;
|
||||
/**
|
||||
* Escapes all regex special characters in a string so it can be used as a literal in a RegExp.
|
||||
* @param str - The string to escape
|
||||
* @returns The escaped string safe for regex interpolation
|
||||
*/
|
||||
const escapeLiteral = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
exports.escapeLiteral = escapeLiteral;
|
||||
/** Composable regex for matching IPv6 addresses (all standard forms including `::` shorthand). */
|
||||
// https://ihateregex.io/expr/ipv6/
|
||||
exports.ipv6 = new ComposableRegex(/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/);
|
||||
/** Composable regex for matching IPv4 addresses in dotted-decimal notation. */
|
||||
// https://ihateregex.io/expr/ipv4/
|
||||
exports.ipv4 = new ComposableRegex(/(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/);
|
||||
/** Composable regex for matching RFC-compliant hostnames. */
|
||||
exports.hostname = new ComposableRegex(/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])/);
|
||||
/** Composable regex for matching `.local` mDNS hostnames. */
|
||||
exports.localHostname = new ComposableRegex(/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.local/);
|
||||
/** Composable regex for matching HTTP/HTTPS URLs. */
|
||||
// https://ihateregex.io/expr/url/
|
||||
exports.url = new ComposableRegex(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/);
|
||||
/** Composable regex for matching `.local` URLs (mDNS/LAN). */
|
||||
exports.localUrl = new ComposableRegex(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.local\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)/);
|
||||
/** Composable regex for matching printable ASCII characters (space through tilde). */
|
||||
// https://ihateregex.io/expr/ascii/
|
||||
exports.ascii = new ComposableRegex(/[ -~]*/);
|
||||
/** Composable regex for matching fully qualified domain names. */
|
||||
exports.domain = new ComposableRegex(/[A-Za-z0-9.-]+\.[A-Za-z]{2,}/);
|
||||
/** Composable regex for matching email addresses. */
|
||||
// https://www.regular-expressions.info/email.html
|
||||
exports.email = new ComposableRegex(`[A-Za-z0-9._%+-]+@${exports.domain.asExpr()}`);
|
||||
/** Composable regex for matching email addresses optionally preceded by a display name (e.g. `"Name <email>"`). */
|
||||
exports.emailWithName = new ComposableRegex(`${exports.email.asExpr()}|([^<]*<${exports.email.asExpr()}>)`);
|
||||
/** Composable regex for matching base64-encoded strings (no whitespace). */
|
||||
//https://rgxdb.com/r/1NUN74O6
|
||||
exports.base64 = new ComposableRegex(/(?:[a-zA-Z0-9+\/]{4})*(?:|(?:[a-zA-Z0-9+\/]{3}=)|(?:[a-zA-Z0-9+\/]{2}==)|(?:[a-zA-Z0-9+\/]{1}===))/);
|
||||
/** Composable regex for matching base64-encoded strings that may contain interspersed whitespace. */
|
||||
//https://rgxdb.com/r/1NUN74O6
|
||||
exports.base64Whitespace = new ComposableRegex(/(?:([a-zA-Z0-9+\/]\s*){4})*(?:|(?:([a-zA-Z0-9+\/]\s*){3}=)|(?:([a-zA-Z0-9+\/]\s*){2}==)|(?:([a-zA-Z0-9+\/]\s*){1}===))/);
|
||||
/**
|
||||
* Creates a composable regex for matching PEM-encoded blocks with the given label.
|
||||
* @param label - The PEM label (e.g. `"CERTIFICATE"`, `"RSA PRIVATE KEY"`)
|
||||
* @returns A ComposableRegex matching `-----BEGIN <label>-----...-----END <label>-----`
|
||||
*/
|
||||
const pem = (label) => new ComposableRegex(`-----BEGIN ${(0, exports.escapeLiteral)(label)}-----\r?\n[a-zA-Z0-9+/\n\r=]*?\r?\n-----END ${(0, exports.escapeLiteral)(label)}-----`);
|
||||
exports.pem = pem;
|
||||
//# sourceMappingURL=regexes.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"regexes.js","sourceRoot":"","sources":["../../../../base/lib/util/regexes.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,eAAe;IAE1B,YAAY,KAAsB;QAChC,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;YAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QACpB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAA;QAChC,CAAC;IACH,CAAC;IACD,4GAA4G;IAC5G,MAAM;QACJ,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAA;IACjC,CAAC;IACD,+EAA+E;IAC/E,OAAO;QACL,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAA;IACjC,CAAC;IACD,8EAA8E;IAC9E,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;IAC1B,CAAC;CACF;AArBD,0CAqBC;AAED;;;;GAIG;AACI,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,EAAE,CAC3C,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;AAD/B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AAc,IAAA,qBAAa,EAAC,KAAK,CAAC,+CAA+C,IAAA,qBAAa,EAAC,KAAK,CAAC,OAAO,CAC7G,CAAA;AAHU,QAAA,GAAG,OAGb"}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { AllowReadonly } from '../types';
|
||||
/**
|
||||
* Normalizes a command into an argv-style string array.
|
||||
* If given a string, wraps it as `["sh", "-c", command]`.
|
||||
* If given a tuple, returns it as-is.
|
||||
*
|
||||
* @param command - A shell command string or a pre-split argv tuple
|
||||
* @returns An argv-style string array suitable for process execution
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* splitCommand("echo hello") // ["sh", "-c", "echo hello"]
|
||||
* splitCommand(["node", "index.js"]) // ["node", "index.js"]
|
||||
* ```
|
||||
*/
|
||||
export declare const splitCommand: (command: string | AllowReadonly<[string, ...string[]]>) => string[];
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.splitCommand = void 0;
|
||||
/**
|
||||
* Normalizes a command into an argv-style string array.
|
||||
* If given a string, wraps it as `["sh", "-c", command]`.
|
||||
* If given a tuple, returns it as-is.
|
||||
*
|
||||
* @param command - A shell command string or a pre-split argv tuple
|
||||
* @returns An argv-style string array suitable for process execution
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* splitCommand("echo hello") // ["sh", "-c", "echo hello"]
|
||||
* splitCommand(["node", "index.js"]) // ["node", "index.js"]
|
||||
* ```
|
||||
*/
|
||||
const splitCommand = (command) => {
|
||||
if (Array.isArray(command))
|
||||
return command;
|
||||
return ['sh', '-c', command];
|
||||
};
|
||||
exports.splitCommand = splitCommand;
|
||||
//# sourceMappingURL=splitCommand.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"splitCommand.js","sourceRoot":"","sources":["../../../../base/lib/util/splitCommand.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;GAaG;AACI,MAAM,YAAY,GAAG,CAC1B,OAAsD,EAC5C,EAAE;IACZ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAA;IAC1C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAiB,CAAC,CAAA;AACxC,CAAC,CAAA;AALY,QAAA,YAAY,gBAKxB"}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Extracts a string result from a stdout/stderr pair.
|
||||
* Returns `stdout` on success; rejects with `stderr` if it is non-empty.
|
||||
*
|
||||
* @param x - An object containing `stdout` and `stderr` strings
|
||||
* @returns A promise resolving to `stdout`, or rejecting with `stderr`
|
||||
*/
|
||||
export declare function stringFromStdErrOut(x: {
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}): Promise<string>;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.stringFromStdErrOut = stringFromStdErrOut;
|
||||
/**
|
||||
* Extracts a string result from a stdout/stderr pair.
|
||||
* Returns `stdout` on success; rejects with `stderr` if it is non-empty.
|
||||
*
|
||||
* @param x - An object containing `stdout` and `stderr` strings
|
||||
* @returns A promise resolving to `stdout`, or rejecting with `stderr`
|
||||
*/
|
||||
async function stringFromStdErrOut(x) {
|
||||
return x?.stderr ? Promise.reject(x.stderr) : x.stdout;
|
||||
}
|
||||
//# sourceMappingURL=stringFromStdErrOut.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"stringFromStdErrOut.js","sourceRoot":"","sources":["../../../../base/lib/util/stringFromStdErrOut.ts"],"names":[],"mappings":";;AAOA,kDAKC;AAZD;;;;;;GAMG;AACI,KAAK,UAAU,mBAAmB,CAAC,CAGzC;IACC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;AACxD,CAAC"}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import * as T from '../types';
|
||||
/**
|
||||
* Flattens an intersection type into a single object type for improved readability in IDE tooltips.
|
||||
* Arrays pass through unchanged; objects are remapped to a single flat type.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* type Merged = FlattenIntersection<{ a: 1 } & { b: 2 }>
|
||||
* // Result: { a: 1; b: 2 }
|
||||
* ```
|
||||
*/
|
||||
export type FlattenIntersection<T> = T extends ArrayLike<any> ? T : T extends object ? {} & {
|
||||
[P in keyof T]: T[P];
|
||||
} : T;
|
||||
/** Shorthand alias for {@link FlattenIntersection}. */
|
||||
export type _<T> = FlattenIntersection<T>;
|
||||
/**
|
||||
* Type guard that checks whether a value is a {@link T.KnownError}.
|
||||
* Returns true if the value is an object containing an `error` or `error-code` property.
|
||||
*
|
||||
* @param e - The value to check
|
||||
* @returns True if `e` is a KnownError
|
||||
*/
|
||||
export declare const isKnownError: (e: unknown) => e is T.KnownError;
|
||||
declare const affine: unique symbol;
|
||||
/**
|
||||
* A branded/nominal type wrapper using a unique symbol to make structurally identical types incompatible.
|
||||
* Useful for creating distinct type identities at the type level.
|
||||
*/
|
||||
export type Affine<A> = {
|
||||
[affine]: A;
|
||||
};
|
||||
type NeverPossible = {
|
||||
[affine]: string;
|
||||
};
|
||||
/**
|
||||
* Evaluates to `never` if `A` is `any`, otherwise resolves to `A`.
|
||||
* Useful for preventing `any` from silently propagating through generic constraints.
|
||||
*/
|
||||
export type NoAny<A> = NeverPossible extends A ? keyof NeverPossible extends keyof A ? never : A : A;
|
||||
type CapitalLetters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
|
||||
type Numbers = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
||||
type CapitalChars = CapitalLetters | Numbers;
|
||||
/**
|
||||
* Converts a PascalCase or camelCase string type to kebab-case at the type level.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* type Result = ToKebab<"FooBar"> // "foo-bar"
|
||||
* ```
|
||||
*/
|
||||
export type ToKebab<S extends string> = S extends string ? S extends `${infer Head}${CapitalChars}${infer Tail}` ? Head extends '' ? Tail extends '' ? Lowercase<S> : S extends `${infer Caps}${Tail}` ? Caps extends CapitalChars ? Tail extends CapitalLetters ? `${Lowercase<Caps>}-${Lowercase<Tail>}` : Tail extends `${CapitalLetters}${string}` ? `${ToKebab<Caps>}-${ToKebab<Tail>}` : `${ToKebab<Caps>}${ToKebab<Tail>}` : never : never : Tail extends '' ? S extends `${Head}${infer Caps}` ? Caps extends CapitalChars ? Head extends Lowercase<Head> ? Caps extends Numbers ? Head extends `${string}${Numbers}` ? never : `${ToKebab<Head>}-${Caps}` : `${ToKebab<Head>}-${ToKebab<Caps>}` : never : never : never : S extends `${Head}${infer Caps}${Tail}` ? Caps extends CapitalChars ? Head extends Lowercase<Head> ? Tail extends CapitalLetters ? `${ToKebab<Head>}-${ToKebab<Caps>}-${Lowercase<Tail>}` : Tail extends `${CapitalLetters}${string}` ? Head extends Numbers ? never : Head extends `${string}${Numbers}` ? never : `${Head}-${ToKebab<Caps>}-${ToKebab<Tail>}` : `${ToKebab<Head>}-${Lowercase<Caps>}${ToKebab<Tail>}` : never : never : never : S : never;
|
||||
/** A generic object type with string keys and unknown values. */
|
||||
export type StringObject = Record<string, unknown>;
|
||||
export {};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isKnownError = void 0;
|
||||
/**
|
||||
* Type guard that checks whether a value is a {@link T.KnownError}.
|
||||
* Returns true if the value is an object containing an `error` or `error-code` property.
|
||||
*
|
||||
* @param e - The value to check
|
||||
* @returns True if `e` is a KnownError
|
||||
*/
|
||||
const isKnownError = (e) => e instanceof Object && ('error' in e || 'error-code' in e);
|
||||
exports.isKnownError = isKnownError;
|
||||
function test() {
|
||||
// prettier-ignore
|
||||
const t = (a) => { };
|
||||
t(null);
|
||||
// @ts-expect-error
|
||||
t(null);
|
||||
}
|
||||
//# sourceMappingURL=typeHelpers.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"typeHelpers.js","sourceRoot":"","sources":["../../../../base/lib/util/typeHelpers.ts"],"names":[],"mappings":";;;AAqBA;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAAC,CAAU,EAAqB,EAAE,CAC5D,CAAC,YAAY,MAAM,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,YAAY,IAAI,CAAC,CAAC,CAAA;AAD/C,QAAA,YAAY,gBACmC;AA+G5D,SAAS,IAAI;IACX,kBAAkB;IAClB,MAAM,CAAC,GAAG,CAAO,CAIhB,EAAE,EAAE,GAAE,CAAC,CAAA;IACR,CAAC,CAA+B,IAAI,CAAC,CAAA;IACrC,mBAAmB;IACnB,CAAC,CAA+B,IAAI,CAAC,CAAA;AACvC,CAAC"}
|
||||
Reference in New Issue
Block a user