@wal-li/core
v1.2.0
Published
Build Secure, Scalable, and Smart Servers with Ease.
Downloads
71
Readme
@wal-li/core
Pre-requisites
Make sure your project has:
- Node.js 18+.
reflect-metadatapackage.
If you're using typescript, make sure tsconfig is match with this:
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES2020",
"esModuleInterop": true,
"strict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}Getting Started
npm i -D @wal-li/coreExample
import { Container, Server, Start } from '@wal-li/core';
const container = new Container();
container.register(Server);
container.execute(Start);
const server = container.resolve<Server>(Server);Features
Dependency Injection
TBD
Security
ID Generator
As computational power increases, random IDs tend to become longer to enhance security. However, this does not guarantee protection. Random IDs can still be exposed through various risks, and once compromised, they are difficult to secure again. Therefore, random IDs are not always necessary, especially for internal systems.
Sequential IDs provide several advantages over random ones. Although they are predictable, we can protect them through additional mechanisms such as passwords, encrypted keys, or access tokens.
- Short and compact
- Naturally sortable
With proper design, sequential IDs can be used safely in distributed systems without collisions, using techniques like unique machine identifiers, timestamps, or sequence generators.
In @wal-li/core, we use a 64-bit sequential ID, defined as follows:
[ 1-bit ][ 42-bit ][ 10-bit ][ 10-bit ]
(sign bit)(timestamp)(machine id)(sequence)| Field | Space |
| ---------- | -------------- |
| sign bit | 1 (always 0) |
| timestamp | 139 years |
| machine id | 1024 machines |
| sequence | 2048 ids |
import { uniqid } from '@wal-li/core';
uniqid();
uniqid.machine = 6;
uniqid.epoch = +new Date();
uniqid();Server
Create
TBD
Routing
- Static Routes:
/abc/def.html. - Dynamic Routes:
/abc/[tag]-[group]/[name].[ext]. - Group Routes:
/abc/(group)/def.html- Thegroupsegment is ignored,/abc/def.htmlis matched. - Catch-all Routes:
/abc/[...slug]- Everything after the/abc/segment is captured in theslugvariable. - Optional Catch-all Routes:
/abc/[[...slug]]- Everything after the/abc/segment is captured in theslugvariable.- If the path is
/abc, theslugwill beundefined. - If the path is
/abc/, theslugwill be empty ('');
- If the path is
FAQ
Why not using vitest?
Vite uses ESBuild which doesn't support "emitDecoratorMetadata" in tsconfig, since ESBuild doesn't have its own type system implemented. (https://stackoverflow.com/questions/68570519/why-cant-reflect-metadata-be-used-in-vite)
Why CommonJS?
TypeScript with ESM doesn't satisfy the requirements of the framework and related products, such as Jest and Isolated-VM. So, CommonJS it is.
License
MIT.
