Compare commits

...

10 Commits

8 changed files with 19691 additions and 2 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

8
.presetterrc.json Normal file
View File

@ -0,0 +1,8 @@
{
"preset": [
"@lumeweb/presetter-kernel-module-preset"
],
"config": {
"official": true
}
}

6
CHANGELOG.md Normal file
View File

@ -0,0 +1,6 @@
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/kernel-network-registry/compare/v0.0.1...v0.1.0-develop.1) (2023-07-19)
### Features
* initial version ([60be134](https://git.lumeweb.com/LumeWeb/kernel-network-registry/commit/60be1346596c3413134d97dd195567ba2a2e5314))

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2023 LumeWeb Copyright (c) 2023 Hammer Technologies LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -1,2 +1,2 @@
# kernel-module-network-registry # kernel-network-registry

19584
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "@lumeweb/kernel-network-registry",
"version": "0.1.0-develop.1",
"type": "module",
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/kernel-network-registry.git"
},
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"dependencies": {
"@lumeweb/libkernel": "^0.1.0-develop.20"
},
"devDependencies": {
"@lumeweb/presetter-kernel-module-preset": "^0.1.0-develop.43"
}
}

57
src/index.ts Normal file
View File

@ -0,0 +1,57 @@
import { ActiveQuery, addHandler } from "@lumeweb/libkernel/module";
const types: Set<string> = new Set<string>();
const networks: Map<string, Set<string>> = new Map<string, Set<string>>();
addHandler("registerType", handleRegisterType);
addHandler("getTypes", handleGetTypes);
addHandler("getNetworkTypes", handleGetNetworkType);
addHandler("registerNetwork", handleRegisterNetwork);
function handleRegisterType(aq: ActiveQuery) {
types.add(aq.callerInput);
aq.respond();
}
function handleGetTypes(aq: ActiveQuery) {
aq.respond([...types.values()]);
}
function handleRegisterNetwork(aq: ActiveQuery) {
if (!("types" in aq.callerInput)) {
aq.reject("types missing");
return;
}
if (!Array.isArray(aq.callerInput.types)) {
aq.reject("types must be an array");
return;
}
let network = networks.get(aq.domain);
if (network) {
aq.callerInput.type.forEach((item) => network?.add(item));
} else {
networks.set(aq.domain, new Set([aq.callerInput.types]));
}
aq.respond();
}
function handleGetNetworkType(aq: ActiveQuery) {
if (!("module" in aq.callerInput)) {
aq.reject("module missing");
return;
}
if (!networks.has(aq.callerInput.module)) {
aq.reject("module is not registered");
return;
}
aq.respond([
...(networks.get(aq.callerInput.module) as Set<string>).values(),
]);
}