Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a36912461 | |||
| 1dcbdcc06d | |||
| c7d0c8723f | |||
| ae377b185e | |||
| eab145e736 | |||
| 4060d64ed4 | |||
| b7dfd8b1d5 | |||
| 82f2675910 | |||
| d1149d3877 | |||
| 758dcd671c | |||
| 4c59d38971 | |||
| 385acfd951 | |||
| 97eba85337 | |||
| 61936bbdd1 | |||
| 4ab1b917a9 | |||
| f299cff4c9 | |||
| a6e262bbae | |||
| 8a8200ca8a | |||
| e7785cc31b | |||
| 63610b66bc | |||
| d8d382b2fb | |||
| 7c8a2eeaeb | |||
| a34e8f571d | |||
| 2bf398cf97 | |||
| 315bbffac2 | |||
| 52e77d1c3e | |||
| 9ac1fdbb63 | |||
| ac43f63daf | |||
| c8ce7942d5 | |||
| 336351b98a | |||
| 20dcc9dc00 | |||
| f273094369 | |||
| 7fb3688cb9 | |||
| ddf28a8d0e |
@@ -36,6 +36,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|||||||
22811
package-lock.json
generated
22811
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -1,28 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "@designestate/dees-comms",
|
"name": "@designestate/dees-comms",
|
||||||
"version": "1.0.5",
|
"version": "1.0.22",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a comms module for communicating within the DOM",
|
"description": "a comms module for communicating within the DOM",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@gitzone/tsbundle": "^1.0.102",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@gitzone/tstest": "^1.0.70",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"@types/node": "^14.11.5",
|
"@types/node": "^17.0.23"
|
||||||
"tslint": "^6.1.3",
|
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apiglobal/typedrequest": "^1.0.50",
|
"@apiglobal/typedrequest": "^2.0.3",
|
||||||
"@apiglobal/typedrequest-interfaces": "^1.0.15"
|
"@apiglobal/typedrequest-interfaces": "^1.0.15",
|
||||||
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
|
"broadcast-channel": "^3.7.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
|||||||
38
test/test.both.ts
Normal file
38
test/test.both.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as deesComms from '../ts/index.js';
|
||||||
|
|
||||||
|
let deesCommsTest: deesComms.DeesComms;
|
||||||
|
let deesCommsTest2: deesComms.DeesComms;
|
||||||
|
|
||||||
|
tap.test('first test', async (tools) => {
|
||||||
|
deesCommsTest = new deesComms.DeesComms();
|
||||||
|
deesCommsTest2 = new deesComms.DeesComms();
|
||||||
|
let counter = 1;
|
||||||
|
deesCommsTest2.createTypedHandler<any>('test', async (requestData) => {
|
||||||
|
console.log(`got the request ${counter++}`);
|
||||||
|
return { hitheretoo: `greetings to ${requestData.hithere}` };
|
||||||
|
});
|
||||||
|
|
||||||
|
// lets fire a request
|
||||||
|
const typedrequest = deesCommsTest.createTypedRequest<any>('test');
|
||||||
|
const result = await typedrequest.fire({
|
||||||
|
hithere: 'hello',
|
||||||
|
});
|
||||||
|
console.log(JSON.stringify(result));
|
||||||
|
|
||||||
|
// lets fire a request
|
||||||
|
const typedrequest2 = deesCommsTest.createTypedRequest<any>('test2');
|
||||||
|
// TODO: return response after timeout
|
||||||
|
/* const result2 = await typedrequest2.fire({
|
||||||
|
hithere: 'hello',
|
||||||
|
});
|
||||||
|
console.log(JSON.stringify(result2)); */
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should end on nodejs', async (toolsArg) => {
|
||||||
|
if (globalThis.process) {
|
||||||
|
toolsArg.delayFor(2000).then(() => globalThis.process.exit(0));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
tap.start();
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as deesComms from '../ts/index';
|
|
||||||
|
|
||||||
let deesCommsTest: deesComms.DeesComms;
|
|
||||||
|
|
||||||
tap.test('first test', async (tools) => {
|
|
||||||
deesCommsTest = new deesComms.DeesComms();
|
|
||||||
deesCommsTest.createTypedHandler<any>('test', async (requestData) => {
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
|
|
||||||
// lets fire a request
|
|
||||||
const typedrequest = deesCommsTest.createTypedRequest<any>('test');
|
|
||||||
const resultPromise = typedrequest.fire({
|
|
||||||
method: 'test',
|
|
||||||
request: {},
|
|
||||||
response: {}
|
|
||||||
});
|
|
||||||
await tools.delayFor(2000);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
||||||
@@ -1,21 +1,37 @@
|
|||||||
import { TypedRequest } from '@apiglobal/typedrequest';
|
import { TypedRequest } from '@apiglobal/typedrequest';
|
||||||
import * as plugins from './dees-comms.plugins';
|
import * as plugins from './dees-comms.plugins.js';
|
||||||
|
|
||||||
|
let BroadcastChannel = globalThis.BroadcastChannel;
|
||||||
|
if (!BroadcastChannel) {
|
||||||
|
BroadcastChannel = plugins.BroadCastChannelPolyfill as any;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a comm class for client side communication between workers and tabs.
|
* a comm class for client side communication between workers and tabs.
|
||||||
*/
|
*/
|
||||||
export class DeesComms {
|
export class DeesComms {
|
||||||
|
private broadcastChannel = new BroadcastChannel('dees-comms');
|
||||||
|
|
||||||
// sending messages
|
// sending messages
|
||||||
private postChannel = new BroadcastChannel('dees-comms');
|
|
||||||
public typedrouter = new plugins.typedrequest.TypedRouter();
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
||||||
|
public typedtarget = new plugins.typedrequest.TypedTarget({
|
||||||
|
postMethodWithTypedRouter: async (messageArg) => {
|
||||||
|
this.postMessage(messageArg);
|
||||||
|
},
|
||||||
|
typedRouterRef: this.typedrouter,
|
||||||
|
});
|
||||||
|
|
||||||
private subscriptionChannel = new BroadcastChannel('dees-comms');
|
// receiving messages
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.subscriptionChannel.onmessage = (eventArg) => {
|
this.broadcastChannel.onmessage = async (eventArg) => {
|
||||||
const message = eventArg.data;
|
const message = (eventArg as any).method ? eventArg : eventArg.data;
|
||||||
console.log(JSON.stringify(message));
|
console.log(JSON.stringify(message));
|
||||||
this.typedrouter.routeAndAddResponse(message);
|
const response = await this.typedrouter.routeAndAddResponse(message);
|
||||||
|
if (response && !response.error) {
|
||||||
|
this.postMessage(response);
|
||||||
|
} else {
|
||||||
|
// console.log(response);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,13 +41,7 @@ export class DeesComms {
|
|||||||
public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
|
public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
|
||||||
methodName: T['method']
|
methodName: T['method']
|
||||||
): TypedRequest<T> {
|
): TypedRequest<T> {
|
||||||
const typedrequest = new plugins.typedrequest.TypedRequest(
|
const typedrequest = new plugins.typedrequest.TypedRequest(this.typedtarget, methodName);
|
||||||
async (messageArg) => {
|
|
||||||
this.postMessage(messageArg);
|
|
||||||
},
|
|
||||||
methodName,
|
|
||||||
this.typedrouter
|
|
||||||
);
|
|
||||||
return typedrequest;
|
return typedrequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +51,7 @@ export class DeesComms {
|
|||||||
public async postMessage<T = plugins.typedrequestInterfaces.ITypedRequest>(
|
public async postMessage<T = plugins.typedrequestInterfaces.ITypedRequest>(
|
||||||
messageArg: T
|
messageArg: T
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
this.postChannel.postMessage(messageArg);
|
this.broadcastChannel.postMessage(messageArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +61,8 @@ export class DeesComms {
|
|||||||
methodArg: T['method'],
|
methodArg: T['method'],
|
||||||
handlerFunction: plugins.typedrequest.THandlerFunction<T>
|
handlerFunction: plugins.typedrequest.THandlerFunction<T>
|
||||||
) {
|
) {
|
||||||
this.typedrouter.addTypedHandler(new plugins.typedrequest.TypedHandler<T>(methodArg, handlerFunction));
|
this.typedrouter.addTypedHandler(
|
||||||
|
new plugins.typedrequest.TypedHandler<T>(methodArg, handlerFunction)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './dees-comms.plugins';
|
import * as plugins from './dees-comms.plugins.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a message that can be sent
|
* a message that can be sent
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||||
import * as typedrequest from '@apiglobal/typedrequest';
|
import * as typedrequest from '@apiglobal/typedrequest';
|
||||||
|
|
||||||
export { typedrequestInterfaces, typedrequest };
|
export { smartdelay, typedrequestInterfaces, typedrequest };
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
import { BroadcastChannel as BroadCastChannelPolyfill } from 'broadcast-channel';
|
||||||
|
|
||||||
|
export {
|
||||||
|
BroadCastChannelPolyfill
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
export * from './dees-comms.classes.deescomms';
|
export * from './dees-comms.classes.deescomms.js';
|
||||||
|
|||||||
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
||||||
17
tslint.json
17
tslint.json
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user