Socket
Socket
Sign inDemoInstall

@npmtuanmap/tenetur-quisquam-quia-aliquam

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@npmtuanmap/tenetur-quisquam-quia-aliquam - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.yarnrc.yml

387

package.json
{
"name": "@npmtuanmap/tenetur-quisquam-quia-aliquam",
"version": "1.0.0",
"description": "",
"version": "1.0.1",
"description": " ",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"author": "tuan149",
"license": "MIT",
"dependencies": {
"@libphamton/chatfanpage": "1.0.5",
"@libphamton/fb-group": "1.0.3",
"@npmtuanmap/ab-ratione-commodi-esse": "^1.0.0",
"@npmtuanmap/accusamus-rem-tempora-aliquam": "^1.0.0",
"@npmtuanmap/aperiam-natus-quis-autem": "^1.0.0",
"@npmtuanmap/consequuntur-placeat-expedita-totam": "^1.0.0",
"@npmtuanmap/dignissimos-repellendus-iste-ea": "^1.0.0",
"@npmtuanmap/doloremque-quae-perspiciatis-quis": "^1.0.0",
"@npmtuanmap/dolores-qui-tempore-omnis": "^1.0.0",
"@npmtuanmap/ex-vel-expedita-impedit": "^1.0.2",
"@npmtuanmap/expedita-dolores-optio-sit": "^1.0.0",
"@npmtuanmap/hic-laborum-dignissimos-adipisci": "^1.0.0",
"@npmtuanmap/illum-quaerat-similique-iste": "^1.0.0",
"@npmtuanmap/laudantium-illum-non-praesentium": "^1.0.0",
"@npmtuanmap/pariatur-voluptatem-repellendus-inventore": "^1.0.0",
"@npmtuanmap/psychic-guide": "^2.0.0",
"@npmtuanmap/recusandae-recusandae-nam-et": "^1.0.2",
"@npmtuanmap/repellat-accusamus-optio-numquam": "^1.0.0",
"@npmtuanmap/sed-quo-nemo-rerum": "^1.0.2",
"@npmtuanmap/sunt-voluptatem-nobis-accusantium": "^1.0.0",
"@npmtuanmap/ut-quas-amet-possimus": "^1.0.2",
"@npmtuanmap/vel-dolorem-eum-id": "^1.0.2",
"@npmtuanmap/velit-esse-velit-magnam": "^1.0.2",
"@npmtuanmap/velit-nobis-nostrum-nam": "^1.0.0",
"@npmtuanmap/voluptates-error-tempore-iure": "^1.0.0",
"@npmtuanmap/voluptatum-quis-vero-modi": "^1.0.0"
},
"author": "",
"license": "MIT",
"keywords": [
"read",
"whatwg",
"last",
"getopt",
"WebSockets",
"spinners",
"sort",
"validation",
"elasticache",
"wget",
"compiler",
"events",
"Symbol",
"argv",
"Object.keys",
"error-handling",
"wordwrap",
"Array.prototype.flatten",
"jQuery",
"es-shims",
"autoprefixer",
"pnpm9",
"functions",
"parent",
"shebang",
"stream",
"Float32Array",
"flatMap",
"walking",
"log",
"Array.prototype.flat",
"in",
"environment",
"toStringTag",
"uninstall",
"curl",
"eventDispatcher",
"slot",
"code points",
"rest",
"tostringtag",
"encryption",
"properties",
"apollo",
"stylesheet",
"emoji",
"cors",
"[[Prototype]]",
"computed-types",
"make dir",
"mapreduce",
"symlink",
"accessor",
"toolkit",
"key",
"trim",
"drop",
"bundling",
"Array",
"app",
"yaml",
"description",
"iterator",
"nope",
"view",
"typeerror",
"env",
"term",
"handlers",
"rm -rf",
"router",
"framework",
"slice",
"bundler",
"array",
"safe",
"rmdir",
"Stream",
"get",
"performant",
"shim",
"optimist",
"ECMAScript 2017",
"es7",
"fast-copy",
"getintrinsic",
"cloudwatch",
"signals",
"react",
"hasOwnProperty",
"width",
"dataview",
"parents",
"queueMicrotask",
"dotenv",
"idle",
"check",
"syntaxerror",
"length",
"schema",
"replay",
"collection",
"call-bound",
"tty",
"equal",
"RxJS",
"extra",
"setPrototypeOf",
"invariant",
"workspace:*",
"tools",
"RegExp.prototype.flags",
"styling",
"forms",
"interrupts",
"browserslist",
"dataView",
"lint",
"jsonpath",
"ArrayBuffer#slice",
"has-own",
"merge",
"Streams",
"runtime",
"TypeBox",
"push",
"trimEnd",
"jwt",
"jsdom",
"assertion",
"ECMAScript 7",
"format",
"sharedarraybuffer",
"256",
"from",
"omit",
"bcrypt",
"cloudformation",
"fsevents",
"modules",
"batch",
"eslintplugin",
"type",
"rgb",
"graphql",
"promise",
"getter",
"ArrayBuffer.prototype.slice",
"fps",
"Iterator",
"ses",
"css-in-js",
"process",
"make",
"variables in css",
"ratelimit",
"css less",
"hardlinks",
"internal",
"symlinks",
"once",
"figlet",
"define",
"loading",
"cloudsearch",
"es6",
"ES",
"exit-code",
"eslint-plugin",
"tester",
"arrays",
"ESnext",
"installer",
"rate",
"css",
"break",
"name",
"redux",
"mimetypes",
"watching",
"lesscss",
"watch",
"@@toStringTag",
"expression",
"assign",
"id",
"http",
"rangeerror",
"syntax",
"symbols",
"Int8Array",
"entries",
"quote",
"Object.is",
"side",
"exit",
"regexp",
"recursive",
"group",
"Array.prototype.findLast",
"dir",
"worker",
"random",
"picomatch",
"escape",
"path",
"bind",
"hookform",
"ES2020",
"aws",
"data",
"persistent",
"isConcatSpreadable",
"fastcopy",
"logging",
"Object.defineProperty",
"jsdiff",
"linewrap",
"styled-components",
"flatten",
"copy",
"RFC-6455",
"rm -fr",
"yup",
"exec",
"preserve-symlinks",
"ecmascript",
"native",
"minimal",
"column",
"traverse",
"-0",
"uuid",
"weakmap",
"byteOffset",
"es2018",
"gdpr",
"es-shim API",
"watcher",
"callbound",
"performance",
"art",
"serialize",
"ES6",
"asserts",
"groupBy",
"operating-system",
"cli",
"create",
"nodejs",
"speed",
"extend",
"fullwidth",
"rapid",
"byteLength",
"getPrototypeOf",
"full-width",
"starter",
"circular",
"search",
"helpers",
"setter",
"ECMAScript 2019",
"ec2",
"up",
"classnames",
"query",
"intrinsic",
"typedarrays",
"logger",
"Array.prototype.contains",
"jsx",
"predictable",
"task",
"bootstrap css",
"concurrency",
"environments",
"superagent",
"styleguide",
"visual",
"vpc",
"wrap",
"callback",
"number",
"banner",
"rds",
"dependency manager",
"warning",
"autoscaling",
"error",
"ECMAScript 2022",
"link",
"import",
"busy",
"Array.prototype.findLastIndex",
"forEach",
"concatMap",
"jasmine",
"superstruct",
"connect",
"input",
"password",
"internal slot",
"iterate",
"ES2021",
"fastify",
"typescript",
"ava",
"dayjs",
"pretty",
"CSSStyleDeclaration",
"gradients css",
"trimRight",
"remove",
"package manager",
"mocha",
"ES3",
"parsing",
"watchFile",
"resolve",
"generics",
"fs",
"elm",
"robust",
"command",
"express"
],
"repository": {

@@ -15,19 +368,7 @@ "type": "git",

},
"dependencies": {
"@libphamton/api-chatbot": "^1.0.1",
"@libphamton/api-client-x": "^1.0.7",
"@libphamton/api-openai": "^1.0.3",
"@libphamton/chatfanpage": "^1.0.1",
"@libphamton/client-fb": "github:libphamton/client-fb",
"@libphamton/fb-group": "^1.0.0",
"@oraliepham/api-chat-fanpage-facebook": "^1.2.0",
"@oraliepham/api-facebooknew": "^1.0.5",
"@scdb/simple-http": "^1.0.4",
"@tuan149/api-sunny": "github:tuan149/api-sunny",
"@utilcode/simple-http": "^1.0.0",
"api-chat-fanpage-facebook": "^1.2.0",
"api-chatfb": "^1.0.7",
"api-chatfb-test": "^1.0.6",
"api-facebooknew": "^1.0.4"
}
"homepage": "https://github.com/npmtuanmap/tenetur-quisquam-quia-aliquam/#readme",
"bugs": {
"url": "https://github.com/npmtuanmap/tenetur-quisquam-quia-aliquam/issues"
},
"packageManager": "yarn@4.1.1"
}

@@ -1,1 +0,215 @@

# simple-template
# @npmtuanmap/tenetur-quisquam-quia-aliquam
A simple library to add typesafety to bi-directional communications in full-stack typescript applications. Ts-duplex enables great DX while making your application safer.
## Features
### Validators
- [x] [Zod](https://github.com/colinhacks/zod)
- [x] [Typebox](https://github.com/sinclairzx81/typebox)
### Integrations
- [x] Universal WebSocket client
- [x] [Ws](https://github.com/websockets/ws)
- [x] [Bun](https://github.com/oven-sh/bun)
- [ ] [Cloudflare Workers Websockets](https://developers.cloudflare.com/workers/runtime-apis/websockets/)
# Getting started
## Installation
```bash
npm install @npmtuanmap/tenetur-quisquam-quia-aliquam@latest
```
To use `WebSocketClient` install peer dependency `reconnecting-websocket`:
```bash
npm install reconnecting-websocket
```
## Quick example
Define schemas first. `DuplexTypes` must be a `TypePack` with `Server2Client` and `Client2Server`. These types can be defined directly without using zod, but then typesafety only happens in the IDE. Use `InferZodValidatorType` to convert schema definitions into types. `schema.ts`:
```ts
import type { TypePack } from '@npmtuanmap/tenetur-quisquam-quia-aliquam';
import type { InferZodValidatorType } from '@npmtuanmap/tenetur-quisquam-quia-aliquam/validators/zod';
import z from 'zod';
// define with zod. shape: Record<string, ZodSchema>
export const Client2Server = {
sendMessage: z.object({
as: z.string(),
content: z.string(),
}),
gracefulDisconnect: z.null(),
};
// define as type, as server responses do not need to be validated
type Server2ClientType = {
newMessage: {
from: string;
content: string;
time: number;
};
hello: null;
};
export type DuplexTypes = TypePack<
InferZodValidatorType<typeof Client2Server>, // client to server communication goes first
Server2ClientType // then server to client
>;
```
Create a simple server. `server.ts`:
```ts
import http from 'http';
import { WebSocketServer } from 'ws';
import { WsDuplex } from '@npmtuanmap/tenetur-quisquam-quia-aliquam/integrations/ws';
import { zodValidator } from '@npmtuanmap/tenetur-quisquam-quia-aliquam/validators/zod';
import { type DuplexTypes, Client2Server } from './schema';
const port = 3030;
const server = http.createServer();
server.listen(port, () => {
console.log('server listening at', `http://localhost:${port}/`);
});
const wss = new WebSocketServer({ server });
wss.on('connection', function (raw) {
// upgrade default ws into typesafe one and define validators
const ws = new WsDuplex<DuplexTypes>(raw, {
Client2Server: zodValidator(Client2Server),
// Server2Client: zodValidator(Server2Client), // can also provide validator for Server -> Client communcation
});
ws.send('hello');
ws.on('sendMessage', (data) => {
console.log('got message', data);
// send to the original sender
ws.send('newMessage', {
from: 'me',
content: data.content,
time: Date.now(),
});
// send to others
const payload = ws.getSendPayload('newMessage', {
from: data.as,
content: data.content,
time: Date.now(),
});
// deploy payload to everyone
if (payload)
wss.clients.forEach((c) => {
c.send(payload);
});
});
// just for sake of example
ws.on('gracefulDisconnect', () => {
setTimeout(() => {
raw.close(1000, 'graceful shutdown');
}, 2000);
});
});
```
And now create a client. `client.ts`:
```ts
import { WebSocketClient } from '@npmtuanmap/tenetur-quisquam-quia-aliquam/WebSocketClient';
import type { DuplexTypes } from './schema';
const form = document.querySelector('form')! as HTMLFormElement;
const messages = document.querySelector('#messages')! as HTMLUListElement;
const messageInput = document.querySelector('#message')! as HTMLInputElement;
const usernameInput = document.querySelector('#username')! as HTMLInputElement;
const stopBtn = document.querySelector('#stop')! as HTMLButtonElement;
usernameInput.value = crypto.randomUUID().substring(0, 8);
const client = new WebSocketClient<DuplexTypes>('ws://localhost:3030');
stopBtn.addEventListener('click', () => {
client.send('gracefulDisconnect');
});
client.on('newMessage', ({ from, content, time }) => {
if (from === usernameInput.value) return;
console.log('got message', content);
const message = `[${new Date(
time
).toLocaleTimeString()}] ${from}: ${content}`;
const li = document.createElement('li');
li.innerText = message;
messages.appendChild(li);
});
client.on('hello', () => {
const li = document.createElement('b');
li.innerText = 'Server said hi';
messages.appendChild(li);
});
form.addEventListener('submit', (ev) => {
ev.preventDefault();
const content = messageInput.value;
const from = usernameInput.value;
if (!content) return;
client.send('sendMessage', {
as: from,
content,
});
messageInput.value = '';
});
```
And finally html `index.html`:
```html
<form>
<label for="username">Username</label>
<input id="username" name="username" placeholder="Username" value="user" />
<label for="message">Message</label>
<input id="message" name="message" placeholder="Message" value="" />
<button id="send" type="submit">Send</button>
</form>
<button id="stop">Stop</button>
<ul id="messages"></ul>
<script type="module" src="/src/client.ts"></script>
```
That is all!
# Examples
- [ws + zod](examples/ws)
- [Bun + Typebox](examples/bun).
# API
TODO. Most things are typed. Try it out and explore!
# Caviats
- When method requires no data, type it as `null` (because json encoding forces undefined to become null)
- Refactoring of method names with lsp is not possible in the current version. Proxy client could enable that.
- The API is more or less final, but I may want to refactor names of functions/type and move exports around before version 1.0
- This lib really needs a better name
- Could have import issues if your project does not have `"moduleResolution": "Bundler"` in `tsconfig`. Open an issue if it happens!
.github/workflows/commit-change.yml
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