nighthouse
Advanced tools
Comparing version 0.0.2 to 1.0.1
@@ -6,3 +6,3 @@ export * from './coder'; | ||
export * from './options'; | ||
export * from './protocol'; | ||
export * from './transport'; | ||
export * from './types'; |
@@ -22,3 +22,3 @@ "use strict"; | ||
__exportStar(require("./options"), exports); | ||
__exportStar(require("./protocol"), exports); | ||
__exportStar(require("./transport"), exports); | ||
__exportStar(require("./types"), exports); |
import { Transport } from "./transport"; | ||
import { Auth, ClientMessage, InputEvent, ServerMessage, SingleVerb, StreamingVerb } from "./types"; | ||
import { Auth, ClientMessage, InputEvent, ServerMessage, SingleVerb } from "./protocol"; | ||
import { Logger } from "./log"; | ||
import { Coder } from "./coder"; | ||
import { LaserMetrics } from "./protocol/metrics"; | ||
/** A connection to the lighthouse. */ | ||
@@ -24,6 +25,26 @@ export declare class Lighthouse { | ||
streamModel(user?: string): AsyncIterable<ServerMessage<unknown>>; | ||
/** Fetches lamp server metrics. */ | ||
getLaserMetrics(): Promise<ServerMessage<LaserMetrics>>; | ||
/** Combines PUT and CREATE. Requires CREATE and WRITE permission. */ | ||
post<T>(path: string[], payload: T): Promise<ServerMessage<unknown>>; | ||
/** Updates the resource at the given path with the given payload. Requires WRITE permission. */ | ||
put<T>(path: string[], payload: T): Promise<ServerMessage<unknown>>; | ||
/** Creates a resource at the given path. Requires CREATE permission. */ | ||
create(path: string[]): Promise<ServerMessage<unknown>>; | ||
/** Deletes a resource at the given path. Requires DELETE permission. */ | ||
delete(path: string[]): Promise<ServerMessage<unknown>>; | ||
/** Creates a directory at the given path. Requires CREATE permission. */ | ||
mkdir(path: string[]): Promise<ServerMessage<unknown>>; | ||
/** Lists the directory tree at the given path. Requires READ permission. */ | ||
list(path: string[]): Promise<ServerMessage<unknown>>; | ||
/** Gets the resource at the given path. Requires READ permission. */ | ||
get(path: string[]): Promise<ServerMessage<unknown>>; | ||
/** Links the given source to the given destination path. Requires WRITE permission for the destination and READ for the source. */ | ||
link(srcPath: string[], destPath: string[]): Promise<ServerMessage<unknown>>; | ||
/** Unlinks the given source from the given destination path. Requires WRITE permission for the destination. */ | ||
unlink(srcPath: string[], destPath: string[]): Promise<ServerMessage<unknown>>; | ||
/** Performs a single request to the given path with the given payload. */ | ||
perform<T>(verb: SingleVerb, path: string[], payload: T): Promise<ServerMessage<unknown>>; | ||
/** Performs a streaming request to the given path with the given payload. */ | ||
stream<T>(verb: StreamingVerb, path: string[], payload: T): AsyncIterable<ServerMessage<unknown>>; | ||
stream<T>(path: string[], payload: T): AsyncIterable<ServerMessage<unknown>>; | ||
/** Sends a request. */ | ||
@@ -30,0 +51,0 @@ private sendRequest; |
@@ -75,3 +75,3 @@ "use strict"; | ||
exports.Lighthouse = void 0; | ||
var types_1 = require("./types"); | ||
var protocol_1 = require("./protocol"); | ||
var log_1 = require("./log"); | ||
@@ -102,3 +102,3 @@ var coder_1 = require("./coder"); | ||
message = coder.decode(raw); | ||
if (!(0, types_1.isServerMessage)(message)) return [3 /*break*/, 2]; | ||
if (!(0, protocol_1.isServerMessage)(message)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.handle(message)]; | ||
@@ -134,3 +134,6 @@ case 1: | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, this.perform('PUT', ['user', user, 'model'], payload)]; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.put(['user', user, 'model'], payload)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
@@ -145,3 +148,3 @@ }); | ||
switch (_a.label) { | ||
case 0: return [5 /*yield**/, __values(__asyncDelegator(__asyncValues(this.stream('STREAM', ['user', user, 'model'], {}))))]; | ||
case 0: return [5 /*yield**/, __values(__asyncDelegator(__asyncValues(this.stream(['user', user, 'model'], {}))))]; | ||
case 1: return [4 /*yield*/, __await.apply(void 0, [_a.sent()])]; | ||
@@ -155,2 +158,112 @@ case 2: | ||
}; | ||
/** Fetches lamp server metrics. */ | ||
Lighthouse.prototype.getLaserMetrics = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.get(['metrics', 'laser'])]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Combines PUT and CREATE. Requires CREATE and WRITE permission. */ | ||
Lighthouse.prototype.post = function (path, payload) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('POST', path, payload)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Updates the resource at the given path with the given payload. Requires WRITE permission. */ | ||
Lighthouse.prototype.put = function (path, payload) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('PUT', path, payload)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Creates a resource at the given path. Requires CREATE permission. */ | ||
Lighthouse.prototype.create = function (path) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('CREATE', path, {})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Deletes a resource at the given path. Requires DELETE permission. */ | ||
Lighthouse.prototype.delete = function (path) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('DELETE', path, {})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Creates a directory at the given path. Requires CREATE permission. */ | ||
Lighthouse.prototype.mkdir = function (path) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('MKDIR', path, {})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Lists the directory tree at the given path. Requires READ permission. */ | ||
Lighthouse.prototype.list = function (path) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('LIST', path, {})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Gets the resource at the given path. Requires READ permission. */ | ||
Lighthouse.prototype.get = function (path) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('GET', path, {})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Links the given source to the given destination path. Requires WRITE permission for the destination and READ for the source. */ | ||
Lighthouse.prototype.link = function (srcPath, destPath) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('LINK', destPath, srcPath)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Unlinks the given source from the given destination path. Requires WRITE permission for the destination. */ | ||
Lighthouse.prototype.unlink = function (srcPath, destPath) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.perform('UNLINK', destPath, srcPath)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Performs a single request to the given path with the given payload. */ | ||
@@ -172,3 +285,3 @@ Lighthouse.prototype.perform = function (verb, path, payload) { | ||
/** Performs a streaming request to the given path with the given payload. */ | ||
Lighthouse.prototype.stream = function (verb, path, payload) { | ||
Lighthouse.prototype.stream = function (path, payload) { | ||
return __asyncGenerator(this, arguments, function stream_1() { | ||
@@ -178,3 +291,3 @@ var requestId; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, __await(this.sendRequest(verb, path, payload))]; | ||
case 0: return [4 /*yield*/, __await(this.sendRequest('STREAM', path, payload))]; | ||
case 1: | ||
@@ -181,0 +294,0 @@ requestId = _a.sent(); |
import { LogHandler } from "./log"; | ||
import { Auth } from "./types"; | ||
import { Auth } from "./protocol"; | ||
/** Configuration options for a lighthouse connection. */ | ||
@@ -4,0 +4,0 @@ export interface Options { |
{ | ||
"name": "nighthouse", | ||
"version": "0.0.2", | ||
"version": "1.0.1", | ||
"description": "Lightweight Project Lighthouse client for JavaScript", | ||
@@ -5,0 +5,0 @@ "workspaces": [ |
# Nighthouse | ||
[![Build](https://github.com/fwcd/nighthouse/actions/workflows/build.yml/badge.svg)](https://github.com/fwcd/nighthouse/actions/workflows/build.yml) | ||
[![Docs](https://github.com/fwcd/nighthouse/actions/workflows/docs.yml/badge.svg)](https://fwcd.github.io/nighthouse) | ||
[![npm](https://img.shields.io/npm/v/nighthouse)](https://www.npmjs.com/package/nighthouse) | ||
[![Build](https://github.com/ProjectLighthouseCAU/nighthouse/actions/workflows/build.yml/badge.svg)](https://github.com/ProjectLighthouseCAU/nighthouse/actions/workflows/build.yml) | ||
[![Docs](https://github.com/ProjectLighthouseCAU/nighthouse/actions/workflows/docs.yml/badge.svg)](https://projectlighthousecau.github.io/nighthouse) | ||
@@ -6,0 +7,0 @@ A lightweight, asynchronous Project Lighthouse client for JavaScript that runs both in the browser and Node.js environments. |
@@ -6,3 +6,3 @@ export * from './coder'; | ||
export * from './options'; | ||
export * from './protocol'; | ||
export * from './transport'; | ||
export * from './types'; |
import { Transport } from "./transport"; | ||
import { Auth, ClientMessage, InputEvent, isServerMessage, ServerMessage, SingleVerb, StreamingVerb, Verb } from "./types"; | ||
import { Auth, ClientMessage, InputEvent, isServerMessage, ServerMessage, SingleVerb, Verb } from "./protocol"; | ||
import { Logger, NoopLogHandler } from "./log"; | ||
import { Coder, MessagePackCoder } from "./coder"; | ||
import { LaserMetrics } from "./protocol/metrics"; | ||
@@ -41,3 +42,3 @@ /** A connection to the lighthouse. */ | ||
async putModel(payload: Uint8Array | InputEvent, user: string = this.auth.USER): Promise<ServerMessage<unknown>> { | ||
return this.perform('PUT', ['user', user, 'model'], payload); | ||
return await this.put(['user', user, 'model'], payload); | ||
} | ||
@@ -47,5 +48,55 @@ | ||
async *streamModel(user: string = this.auth.USER): AsyncIterable<ServerMessage<unknown>> { | ||
yield* this.stream('STREAM', ['user', user, 'model'], {}); | ||
yield* this.stream(['user', user, 'model'], {}); | ||
} | ||
/** Fetches lamp server metrics. */ | ||
async getLaserMetrics(): Promise<ServerMessage<LaserMetrics>> { | ||
return await this.get(['metrics', 'laser']) as ServerMessage<LaserMetrics>; | ||
} | ||
/** Combines PUT and CREATE. Requires CREATE and WRITE permission. */ | ||
async post<T>(path: string[], payload: T): Promise<ServerMessage<unknown>> { | ||
return await this.perform('POST', path, payload); | ||
} | ||
/** Updates the resource at the given path with the given payload. Requires WRITE permission. */ | ||
async put<T>(path: string[], payload: T): Promise<ServerMessage<unknown>> { | ||
return await this.perform('PUT', path, payload); | ||
} | ||
/** Creates a resource at the given path. Requires CREATE permission. */ | ||
async create(path: string[]): Promise<ServerMessage<unknown>> { | ||
return await this.perform('CREATE', path, {}); | ||
} | ||
/** Deletes a resource at the given path. Requires DELETE permission. */ | ||
async delete(path: string[]): Promise<ServerMessage<unknown>> { | ||
return await this.perform('DELETE', path, {}); | ||
} | ||
/** Creates a directory at the given path. Requires CREATE permission. */ | ||
async mkdir(path: string[]): Promise<ServerMessage<unknown>> { | ||
return await this.perform('MKDIR', path, {}); | ||
} | ||
/** Lists the directory tree at the given path. Requires READ permission. */ | ||
async list(path: string[]): Promise<ServerMessage<unknown>> { | ||
return await this.perform('LIST', path, {}); | ||
} | ||
/** Gets the resource at the given path. Requires READ permission. */ | ||
async get(path: string[]): Promise<ServerMessage<unknown>> { | ||
return await this.perform('GET', path, {}); | ||
} | ||
/** Links the given source to the given destination path. Requires WRITE permission for the destination and READ for the source. */ | ||
async link(srcPath: string[], destPath: string[]): Promise<ServerMessage<unknown>> { | ||
return await this.perform('LINK', destPath, srcPath); | ||
} | ||
/** Unlinks the given source from the given destination path. Requires WRITE permission for the destination. */ | ||
async unlink(srcPath: string[], destPath: string[]): Promise<ServerMessage<unknown>> { | ||
return await this.perform('UNLINK', destPath, srcPath); | ||
} | ||
/** Performs a single request to the given path with the given payload. */ | ||
@@ -58,4 +109,4 @@ async perform<T>(verb: SingleVerb, path: string[], payload: T): Promise<ServerMessage<unknown>> { | ||
/** Performs a streaming request to the given path with the given payload. */ | ||
async *stream<T>(verb: StreamingVerb, path: string[], payload: T): AsyncIterable<ServerMessage<unknown>> { | ||
const requestId = await this.sendRequest(verb, path, payload); | ||
async *stream<T>(path: string[], payload: T): AsyncIterable<ServerMessage<unknown>> { | ||
const requestId = await this.sendRequest('STREAM', path, payload); | ||
yield* this.receiveStreaming(requestId); | ||
@@ -62,0 +113,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { LogHandler, LogLevel } from "./log"; | ||
import { Auth } from "./types"; | ||
import { LogHandler } from "./log"; | ||
import { Auth } from "./protocol"; | ||
@@ -4,0 +4,0 @@ /** Configuration options for a lighthouse connection. */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
145059
72
1775
1
45