open-index/open-npm huggingface dataset:
npm package: @prsm/express-keepalive-ws
Description: This is a middleware that creates and exposes a `KeepAliveServer` instance (see [prsm/keepalive-ws](https://github.com/...).
Latest version: 1.2.8

# @prsm/express-keepalive-ws

This is a middleware that creates and exposes a `KeepAliveServer` instance (see [prsm/keepalive-ws](https://github.com/...).

```typescript
import express from "express";
import createWss, { type WSContext } from "@prsm/express-keepalive-ws";

const app = express();
const server = createServer(app);

const { middleware: ws, wss } = createWss({ /** ... */ });

app.use(ws);

// as a middleware:
app.use("/ws", async (req, res) => {
  if (req.ws) { // <-- req.ws will be defined if the request is a WebSocket request
    const ws = await req.ws(); // handle the upgrade and receive the client WebSocket
    ws.send("Hello WS!"); // send a message to the client
  } else {
    res.send("Hello HTTP!");
  }
});

// as a command server:
wss.registerCommand("echo", (c: WSContext) => {
  const { payload } = c;
  return `echo: ${payload}`;
});
```

Client-side usage (more at https://github.com/node-prism/keepalive-ws):

```typescript
import { KeepAliveClient } from "@prsm/keepalive-ws/client";

const opts = { shouldReconnect: true };
const ws = new KeepAliveClient("ws://localhost:PORT", opts);

const echo = await ws.command("echo", "hello!");
console.log(echo); // "echo: hello!"
```
npm package: @prsm/express-session-auth
Description: ## Requirements
Latest version: 1.6.4

# express-session-auth

## Requirements

- `express-session`: https://github.com/expressjs/session
- `cookie-parser`: https://github.com/expressjs/cookie-parser
- TypeORM
  - `express-session-auth` exports entities (`User`, `UserReset`, `UserRemember`, `UserConfirmation`) that you need to include in your datasource for migration/sync purposes.


## Quickstart

Wherever you create your express application, include the auth middleware and pass in your TypeORM datasource.

```typescript
import express from "express";
import { createServer } from "node:http";
import auth from "@prsm/express-session-auth";
import datasource from "./my-datasource";

const app = express();
const server = createServer(app);

// the auth middleware needs your datasource instance
app.use(auth({ datasource }));
```

Here's an example TypeORM datasource:

```typescript
// my-datasource.ts
import {
  User,
  UserConfirmation,
  UserRemember,
  UserReset,
} from "@prsm/express-session-auth";
import { DataSource } from "typeorm";

const datasource = new DataSource({
  type: "mysql", // express-session-auth supports mysql, postgres and sqlite (others not tested)
  host: process.env.DB_HOST,
  port: process.env.DB_PORT ? +process.env.DB_PORT : 3306,
  username: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  entities: [
    User,
    UserConfirmation,
    UserRemember,
    UserReset,
    /* the reset of your entities here */
  ],
});

export default datasource;
```

Environment variables and their defaults:

```bash
HTTP_PORT=3002

AUTH_SESSION_REMEMBER_DURATION=30d
AUTH_SESSION_REMEMBER_COOKIE_NAME=prsm.auth.remember
AUTH_SESSION_RESYNC_INTERVAL=30m
AUTH_MINIMUM_PASSWORD_LENGTH=8
AUTH_MAXIMUM_PASSWORD_LENGTH=64

DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=toor
DB_NAME=prsm
```

Because this middleware augments the `Request` object by adding an `auth` property, you will want to add the following to your `tsconfig.json` so that your language server doesn't flag references to `req.auth` as an error:

```json
{
  "include": [
    "src",
    "node_modules/@prsm/express-session-auth/express-session-auth.d.ts"
  ]
}
```
npm package: @prsm/from
Description: Fluent query builder for filtering, transforming, and aggregating arrays of objects
Author: nvms
Latest version: 1.0.1

<p align="center">
  <img src=".github/logo.svg" width="80" height="80" alt="from logo">
</p>

<h1 align="center">@prsm/from</h1>

Fluent query builder for filtering, transforming, and aggregating arrays of objects. Zero dependencies.

## Installation

```bash
npm install @prsm/from
```

## Usage

```ts
import { from, lt, eq, oneOf } from "@prsm/from"

const result = from(users)
  .where("age", lt(30))
  .where("role", eq("admin"))
  .sortBy("name", "asc")
  .skip(10)
  .take(5)
  .select(["name", "email"])
  .value()
```

## Operators

```ts
// comparison
from(items).where("score", gt(90))
from(items).where("score", between(80, 100))

// strings and arrays
from(items).where("name", includes("test"))
from(items).where("name", startsWith("A"))
from(items).where("tags", lengthGt(2))
from(items).where("tags", empty())

// existence
from(items).where("deletedAt", missing())
from(items).where("email", exists())

// collection
from(items).where("status", oneOf(["active", "pending"]))

// custom predicate
from(items).where((item) => item.score > item.threshold)
```

## Projection

```ts
from(items).select(["name", "email"])           // keep only these fields
from(items).omit(["password", "internal"])       // exclude these fields
from(items).map((item) => ({ label: item.name })) // transform
```

## Aggregation

Computed fields are added in order and can reference each other:

```ts
from(students)
  .aggregate({
    total: add("math", "english", "science"),
    average: div("total", 3),
  })
  .omit(["total"])
  .value()
```

Operators: `add`, `sub`, `mul`, `div`. Accept field paths, literal numbers, or other aggregate operators.

## Updates

Immutable by default:

```ts
// returns cloned array, original untouched
from(items).where("id", eq(1)).update("score", 100).value()

// wildcard maps array elements
from(items).update("tags.*", (t) => t.toUpperCase()).value()
```

Opt in to mutation:

```ts
from(items).where("id", eq(1)).updateMut("score", 100).value()
```

## Sorting and Pagination

```ts
from(items).sortBy("score", "desc").skip(10).take(5).value()
```

## Other

```ts
from(items).first()              // first match or undefined
from(items).count()              // number of results
from(items).groupBy("category")  // Record<string, T[]>
from(items).where(...).remove()  // returns matched items
from(items).where(...).removeMut().value()  // mutates in place
```

## License

Apache-2.0
npm package: @prsm/hash
Description: Simple salted string hashing on top of node:crypto
Author: nvms
Latest version: 2.0.1

# @prsm/hash

Salted string hashing on top of `node:crypto`. Zero dependencies. Defaults to `scrypt` for password-safe hashing.

## Installation

```bash
npm install @prsm/hash
```

## Usage

```js
import hash from "@prsm/hash"

const encoded = await hash.encode("my password")
// scrypt:UfH7lmEc5d...:6qG75Cp5hys...

await hash.verify(encoded, "my password")  // true
await hash.verify(encoded, "wrong")        // false
```

Each call to `encode()` generates a random salt, so the same input produces different hashes. `verify()` extracts the algorithm and salt from the hash string to compare.

## Algorithms

Default is `scrypt` (password-safe, ~5ms per hash). For fast non-security hashing, use `sha256` or `sha512`.

```js
import { Hasher } from "@prsm/hash"

const fast = new Hasher("sha256")
await fast.encode("not a password")

const secure = new Hasher("scrypt", 128)  // custom salt length
await secure.encode("a password")
```

## API

| Function | Description |
|---|---|
| `encode(string)` | Hash a string with a random salt. Returns a promise. |
| `verify(encoded, unencoded)` | Check if a string matches a hash. Returns a promise. |

## Hash Format

```
algorithm:salt:digest
```

Hashes are self-describing - `verify()` reads the algorithm from the hash string, so a scrypt hash can be verified by a sha256-configured instance and vice versa.

## License

Apache-2.0
npm package: @prsm/ids
Description: Short, obfuscated, collision-proof, reversible identifiers
Author: nvms
Latest version: 2.0.0

<p align="center">
  <img src=".github/logo.svg" width="80" height="80" alt="ids logo">
</p>

<h1 align="center">@prsm/ids</h1>

Short, obfuscated, collision-proof, reversible identifiers.

## Installation

```bash
npm install @prsm/ids
```

## Usage

```js
import id from "@prsm/ids"

id.encode(12389125) // "7rYTs_"
id.decode("7rYTs_") // 12389125
```

## Configuration

Set custom alphabet:
```js
id.setAlphabet("GZwBHpfWybgQ5d_2mM-jh84K69tqYknx7LN3zvDrcSJVRPXsCFT")
```

Randomize alphabet:
```js
id.randomizeAlphabet()
```

## API

| Function              | Description                               |
|-----------------------|-------------------------------------------|
| `encode(num)`         | Converts number to obfuscated string      |
| `decode(str)`         | Converts obfuscated string back to number |
| `setAlphabet(str)`    | Sets custom alphabet for encoding         |
| `getAlphabet()`       | Returns current alphabet                  |
| `randomizeAlphabet()` | Shuffles alphabet characters randomly     |

## Notes

- Maximum encodable value: 2,147,483,647 (MAX_INT32)
- Changing alphabet changes encoded values
- Encoded values must be decoded with same alphabet

## License

Apache-2.0