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

@evergis/api

Package Overview
Dependencies
Maintainers
4
Versions
329
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@evergis/api - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

24

es/services/Notification.d.ts

@@ -1,11 +0,13 @@

import { EventHandler, Handler, sGisEvent } from '@evergis/sgis/es/EventHandler';
import { NotificationService } from '../__generated__/NotificationService';
import { IHttpClient } from '../__generated__/HttpClient';
import { ServiceInfoDc } from '../__generated__/data-contracts';
export declare class Notification extends EventHandler {
private readonly notification;
declare type NotificationHandler<Data, Result> = (event: NotificationEvent<Data>) => Result;
export declare class Notification extends NotificationService {
private readonly emitter;
private ws?;
constructor(info: ServiceInfoDc, http: IHttpClient);
subscribe(tag: string, callback: Handler): Promise<void>;
unsubscribe(tag: string, callback: Handler): Promise<void>;
getSubscriptionList(): Promise<string[]>;
on<Data, Result>(tag: string, handler: NotificationHandler<Data, Result>): void;
off<Data, Result>(tag: string, handler: NotificationHandler<Data, Result>): void;
subscribe(tag: string): Promise<void>;
unsubscribe(tag: string): Promise<void>;
connectWs(url: string, sessionId?: string): void;

@@ -16,8 +18,6 @@ private onWsConnected;

}
export declare class NotificationEvent extends sGisEvent {
static type: string;
private tag;
private data;
constructor(tag: string, data: any);
static getHandler<Data>(tag: string, handler: (data: Data) => Promise<void> | void): Handler;
export declare class NotificationEvent<Data> {
data: Data;
constructor(data: Data);
}
export {};

@@ -1,6 +0,6 @@

import { EventHandler, sGisEvent, } from '@evergis/sgis/es/EventHandler';
import { NotificationService } from '../__generated__/NotificationService';
export class Notification extends EventHandler {
import { EventEmitter } from '@evergis/event-emitter';
export class Notification extends NotificationService {
constructor(info, http) {
super();
super(info, http);
this.onWsConnected = () => {

@@ -13,27 +13,34 @@ console.log('WebSocket connection established.');

this.onWsMessage = (event) => {
let message = JSON.parse(event.data);
console.log('WS MESSAGE: ' + JSON.stringify(message));
if (message.type === 'notification') {
this.fire(new NotificationEvent(message.data.tag, message.data.data));
let message = {};
try {
message = JSON.parse(event.data);
}
catch (e) {
// ignore
}
if (message.type === 'notification' && message.data) {
const { tag, data } = message.data;
tag && this.emitter.emit(tag, new NotificationEvent(data));
}
};
this.notification = new NotificationService(info, http);
this.emitter = new EventEmitter();
}
async subscribe(tag, callback) {
const subscriptions = await this.notification.getSubscriptionList();
on(tag, handler) {
this.emitter.on(tag, handler);
}
off(tag, handler) {
this.emitter.off(tag, handler);
}
async subscribe(tag) {
const subscriptions = await this.getSubscriptionList();
if (!subscriptions.includes(tag)) {
await this.notification.subscribeOperation(tag);
await this.subscribeOperation(tag);
}
super.on(NotificationEvent.type, callback);
}
async unsubscribe(tag, callback) {
const subscriptions = await this.notification.getSubscriptionList();
async unsubscribe(tag) {
const subscriptions = await this.getSubscriptionList();
if (subscriptions.includes(tag)) {
await this.notification.unsubscribeOperation(tag);
await this.unsubscribeOperation(tag);
}
super.off(NotificationEvent.type, callback);
}
getSubscriptionList() {
return this.notification.getSubscriptionList();
}
connectWs(url, sessionId) {

@@ -47,17 +54,7 @@ const wsUrl = url.replace('http://', 'ws://').replace('https://', 'wss://');

}
export class NotificationEvent extends sGisEvent {
constructor(tag, data) {
super(NotificationEvent.type);
this.tag = tag;
export class NotificationEvent {
constructor(data) {
this.data = data;
}
static getHandler(tag, handler) {
return (event) => {
const notifyEvent = event;
if (notifyEvent.tag === tag)
handler(notifyEvent.data);
};
}
}
NotificationEvent.type = 'notification';
//# sourceMappingURL=Notification.js.map
import { SchedulerService as SchedulerServiceBase } from '../__generated__/SchedulerService';
import { BufferTaskParametersDc, CopyTaskParametersDc, FilterCopyTaskParametersDc, PipelineTaskParametersDc, SubtractionTaskParametersDc, TaskInfoDc, UnionTaskParametersDc } from '../__generated__/data-contracts';
import { BufferTaskParametersDc, CopyTaskParametersDc, FilterCopyTaskParametersDc, PipelineTaskParametersDc, SubtractionTaskParametersDc, TaskProgressDc, UnionTaskParametersDc } from '../__generated__/data-contracts';
import { Notification } from './';
export declare class Scheduler extends SchedulerServiceBase {
private notification?;
init(notification: Notification): void;
runCopyTask(parameters?: CopyTaskParametersDc): Promise<TaskInfoDc>;
runBufferTask(parameters?: BufferTaskParametersDc): Promise<TaskInfoDc>;
runUnionTask(parameters?: UnionTaskParametersDc): Promise<TaskInfoDc>;
runSubtractionTask(parameters?: SubtractionTaskParametersDc): Promise<TaskInfoDc>;
runFilterCopyTask(parameters?: FilterCopyTaskParametersDc): Promise<TaskInfoDc>;
runPipelineTask(parameters?: PipelineTaskParametersDc): Promise<TaskInfoDc>;
waitTaskCompleted(id: string): Promise<TaskInfoDc>;
init(notification: Notification): Promise<void>;
runCopyTask(parameters?: CopyTaskParametersDc): Promise<TaskProgressDc>;
runBufferTask(parameters?: BufferTaskParametersDc): Promise<TaskProgressDc>;
runUnionTask(parameters?: UnionTaskParametersDc): Promise<TaskProgressDc>;
runSubtractionTask(parameters?: SubtractionTaskParametersDc): Promise<TaskProgressDc>;
runFilterCopyTask(parameters?: FilterCopyTaskParametersDc): Promise<TaskProgressDc>;
runPipelineTask(parameters?: PipelineTaskParametersDc): Promise<TaskProgressDc>;
waitTaskCompleted(id: string): Promise<TaskProgressDc>;
private resolveTaskStatus;
private processTaskId;
}
import { SchedulerService as SchedulerServiceBase } from '../__generated__/SchedulerService';
import { NotificationEvent } from './Notification';
const NotificationTag = 'server_task';
const SERVER_TASK = 'server_task';
export class Scheduler extends SchedulerServiceBase {
init(notification) {
this.notification = notification;
return this.notification.subscribe(SERVER_TASK);
}

@@ -34,27 +34,28 @@ async runCopyTask(parameters) {

return new Promise(async (resolve, reject) => {
const taskInfo = await this.getTaskInfo(id);
if (taskInfo.status === 'Completed') {
resolve(taskInfo);
}
else if (taskInfo.status === 'Failed' ||
taskInfo.status === 'Canceled') {
reject(taskInfo.status);
}
let handler = NotificationEvent.getHandler(NotificationTag, async (data) => {
if (data.id !== id || !this.notification)
return;
if (data.status === 'Completed') {
resolve(data);
await this.notification.unsubscribe(NotificationTag, handler);
const taskProgress = await this.getTaskProgress(id);
this.resolveTaskStatus(taskProgress, resolve, reject);
const taskResultCallback = async ({ data, }) => {
const taskFinished = data.taskId === id &&
data.status &&
['Completed', 'Failed', 'Canceled'].includes(data.status);
if (taskFinished) {
const taskProgress = await this.getTaskProgress(id);
this.notification &&
this.notification.off(SERVER_TASK, taskResultCallback);
this.resolveTaskStatus(taskProgress, resolve, reject);
}
else if (data.status === 'Failed' || data.status === 'Canceled') {
reject(data.status);
await this.notification.unsubscribe(NotificationTag, handler);
}
});
if (this.notification) {
await this.notification.subscribe(NotificationTag, handler);
}
};
this.notification &&
this.notification.on(SERVER_TASK, taskResultCallback);
});
}
resolveTaskStatus(taskProgress, resolve, reject) {
if (taskProgress.status === 'Completed') {
resolve(taskProgress);
}
else if (taskProgress.status === 'Failed' ||
taskProgress.status === 'Canceled') {
reject(taskProgress.status);
}
}
processTaskId(taskId) {

@@ -61,0 +62,0 @@ if (taskId) {

{
"name": "@evergis/api",
"version": "0.1.3",
"version": "0.1.4",
"license": "ISC",

@@ -34,2 +34,3 @@ "author": "everpoint",

"dependencies": {
"@evergis/event-emitter": "^1.0.0",
"ky": "^0.11.1",

@@ -36,0 +37,0 @@ "query-string": "^6.7.0"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc