@krizaka/realtime 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pg.d.ts +1 -1
- package/dist/postgres.d.ts +1 -1
- package/dist/redis.d.ts +1 -1
- package/dist/{types-BP1h40fn.d.ts → types-DF6B0PAU.d.ts} +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ export function realtimeBus() {
|
|
|
53
53
|
postgres: pgChannel({ listen: process.env.DATABASE_DIRECT_URL!, notify: pool }),
|
|
54
54
|
channel: "myapp_events", // one NOTIFY channel per app
|
|
55
55
|
redisBus,
|
|
56
|
-
redisUrl: process.env.
|
|
56
|
+
redisUrl: process.env.REALTIME_REDIS_URL,
|
|
57
57
|
prefix: "myapp:rt:", // one key prefix per app on a shared server
|
|
58
58
|
}));
|
|
59
59
|
}
|
|
@@ -109,7 +109,7 @@ Both run `postgres` by default and keep `redis` one variable away.
|
|
|
109
109
|
`pnpm --filter @krizaka/realtime test` covers every adapter without a server (100 % enforced): the PostgreSQL bus over
|
|
110
110
|
an in-memory channel, `pgChannel` over a fake driver. The contract against real servers — two instances per adapter,
|
|
111
111
|
delivery under a second, order of a burst, presence announced once — runs with `REALTIME_IT=1`
|
|
112
|
-
(`pnpm --filter @krizaka/realtime test:integration`, `DATABASE_URL` and `
|
|
112
|
+
(`pnpm --filter @krizaka/realtime test:integration`, `DATABASE_URL` and `REALTIME_REDIS_URL`), in CI's "Realtime adapters" job.
|
|
113
113
|
|
|
114
114
|
## License
|
|
115
115
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PresenceOptions, R as RealtimeBus, a as PresenceState, C as ConnectionState, b as PresenceStore, c as PresenceChange, d as PresenceInfo, B as BusKind } from './types-
|
|
2
|
-
export { D as DEFAULT_PRESENCE, U as Unsubscribe, r as rank } from './types-
|
|
1
|
+
import { P as PresenceOptions, R as RealtimeBus, a as PresenceState, C as ConnectionState, b as PresenceStore, c as PresenceChange, d as PresenceInfo, B as BusKind } from './types-DF6B0PAU.js';
|
|
2
|
+
export { D as DEFAULT_PRESENCE, U as Unsubscribe, r as rank } from './types-DF6B0PAU.js';
|
|
3
3
|
import { PostgresChannel } from './postgres.js';
|
|
4
4
|
export { DEFAULT_CHANNEL, NOTIFY_LIMIT, PostgresBusOptions, postgresBus } from './postgres.js';
|
|
5
5
|
export { EventStreamControls, EventStreamOptions, SseFrame, eventStream, sseFrame } from './sse.js';
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ function createBus(config) {
|
|
|
22
22
|
return postgresBus({ ...config, db: config.postgres });
|
|
23
23
|
}
|
|
24
24
|
if (config.kind === "redis") {
|
|
25
|
-
if (!config.redisUrl) throw new Error("REALTIME_BUS=redis needs
|
|
25
|
+
if (!config.redisUrl) throw new Error("REALTIME_BUS=redis needs REALTIME_REDIS_URL");
|
|
26
26
|
if (!config.redisBus) throw new Error("REALTIME_BUS=redis needs redisBus from @krizaka/realtime/redis");
|
|
27
27
|
return config.redisBus({ ...config, url: config.redisUrl });
|
|
28
28
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @krizaka/realtime — the realtime layer behind one interface (`RealtimeBus`: publish / subscribe by channel, and\n * presence), three adapters chosen by configuration, and Server-Sent Events. It knows no product: the app wires it\n * once (its own `lib/realtime.ts`). The root entry needs no driver: the PostgreSQL adapter takes its connection by\n * injection (`@krizaka/realtime/pg` builds one on `pg`), the Redis adapter lives in `@krizaka/realtime/redis` (`ioredis`).\n */\nexport { memoryBus } from \"./memory\";\nexport { DEFAULT_CHANNEL, NOTIFY_LIMIT, postgresBus, type PostgresBusOptions, type PostgresChannel } from \"./postgres\";\nexport { type PresenceReplica, ReplicatedPresence, type ReplicatedPresenceOptions } from \"./presence\";\nexport { eventStream, type EventStreamControls, type EventStreamOptions, type SseFrame, sseFrame } from \"./sse\";\nexport * from \"./types\";\n\nimport { memoryBus } from \"./memory\";\nimport { postgresBus, type PostgresChannel } from \"./postgres\";\nimport type { RedisBusOptions } from \"./redis\";\nimport type { BusKind, PresenceOptions, RealtimeBus } from \"./types\";\n\nexport interface BusConfig extends Partial<PresenceOptions> {\n kind: BusKind;\n /** Required by `postgres`: the NOTIFY / LISTEN primitives (`pgChannel` from `@krizaka/realtime/pg`, or the app's own). */\n postgres?: PostgresChannel;\n /** The PostgreSQL NOTIFY channel (`postgres`; default `DEFAULT_CHANNEL`). */\n channel?: string;\n /** Required by `redis`: the `redisBus` of `@krizaka/realtime/redis` — passed in, so `ioredis` loads only when used. */\n redisBus?: (options: RedisBusOptions) => RealtimeBus;\n /** Required by `redis`. */\n redisUrl?: string;\n /** Prefix of every Redis key and channel (`redis`; default `DEFAULT_PREFIX`). */\n prefix?: string;\n}\n\n/** The bus a deployment asked for — refuses a configuration that cannot work rather than falling back silently. */\nexport function createBus(config: BusConfig): RealtimeBus {\n if (config.kind === \"memory\") return memoryBus(config);\n if (config.kind === \"postgres\") {\n if (!config.postgres) throw new Error(\"the postgres realtime bus needs a PostgreSQL channel\");\n return postgresBus({ ...config, db: config.postgres });\n }\n if (config.kind === \"redis\") {\n if (!config.redisUrl) throw new Error(\"REALTIME_BUS=redis needs
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @krizaka/realtime — the realtime layer behind one interface (`RealtimeBus`: publish / subscribe by channel, and\n * presence), three adapters chosen by configuration, and Server-Sent Events. It knows no product: the app wires it\n * once (its own `lib/realtime.ts`). The root entry needs no driver: the PostgreSQL adapter takes its connection by\n * injection (`@krizaka/realtime/pg` builds one on `pg`), the Redis adapter lives in `@krizaka/realtime/redis` (`ioredis`).\n */\nexport { memoryBus } from \"./memory\";\nexport { DEFAULT_CHANNEL, NOTIFY_LIMIT, postgresBus, type PostgresBusOptions, type PostgresChannel } from \"./postgres\";\nexport { type PresenceReplica, ReplicatedPresence, type ReplicatedPresenceOptions } from \"./presence\";\nexport { eventStream, type EventStreamControls, type EventStreamOptions, type SseFrame, sseFrame } from \"./sse\";\nexport * from \"./types\";\n\nimport { memoryBus } from \"./memory\";\nimport { postgresBus, type PostgresChannel } from \"./postgres\";\nimport type { RedisBusOptions } from \"./redis\";\nimport type { BusKind, PresenceOptions, RealtimeBus } from \"./types\";\n\nexport interface BusConfig extends Partial<PresenceOptions> {\n kind: BusKind;\n /** Required by `postgres`: the NOTIFY / LISTEN primitives (`pgChannel` from `@krizaka/realtime/pg`, or the app's own). */\n postgres?: PostgresChannel;\n /** The PostgreSQL NOTIFY channel (`postgres`; default `DEFAULT_CHANNEL`). */\n channel?: string;\n /** Required by `redis`: the `redisBus` of `@krizaka/realtime/redis` — passed in, so `ioredis` loads only when used. */\n redisBus?: (options: RedisBusOptions) => RealtimeBus;\n /** Required by `redis`. */\n redisUrl?: string;\n /** Prefix of every Redis key and channel (`redis`; default `DEFAULT_PREFIX`). */\n prefix?: string;\n}\n\n/** The bus a deployment asked for — refuses a configuration that cannot work rather than falling back silently. */\nexport function createBus(config: BusConfig): RealtimeBus {\n if (config.kind === \"memory\") return memoryBus(config);\n if (config.kind === \"postgres\") {\n if (!config.postgres) throw new Error(\"the postgres realtime bus needs a PostgreSQL channel\");\n return postgresBus({ ...config, db: config.postgres });\n }\n if (config.kind === \"redis\") {\n if (!config.redisUrl) throw new Error(\"REALTIME_BUS=redis needs REALTIME_REDIS_URL\");\n if (!config.redisBus) throw new Error(\"REALTIME_BUS=redis needs redisBus from @krizaka/realtime/redis\");\n return config.redisBus({ ...config, url: config.redisUrl });\n }\n throw new Error(`unknown realtime bus \"${String(config.kind)}\" (memory, postgres or redis)`);\n}\n\n/** Reads `REALTIME_BUS` (default `postgres`). */\nexport function busKind(value: string | undefined): BusKind {\n const kind = (value?.trim().toLowerCase() || \"postgres\") as BusKind;\n if (kind !== \"memory\" && kind !== \"postgres\" && kind !== \"redis\") throw new Error(`REALTIME_BUS must be memory, postgres or redis, not \"${value}\"`);\n return kind;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgCO,SAAS,UAAU,QAAgC;AACxD,MAAI,OAAO,SAAS,SAAU,QAAO,UAAU,MAAM;AACrD,MAAI,OAAO,SAAS,YAAY;AAC9B,QAAI,CAAC,OAAO,SAAU,OAAM,IAAI,MAAM,sDAAsD;AAC5F,WAAO,YAAY,EAAE,GAAG,QAAQ,IAAI,OAAO,SAAS,CAAC;AAAA,EACvD;AACA,MAAI,OAAO,SAAS,SAAS;AAC3B,QAAI,CAAC,OAAO,SAAU,OAAM,IAAI,MAAM,6CAA6C;AACnF,QAAI,CAAC,OAAO,SAAU,OAAM,IAAI,MAAM,gEAAgE;AACtG,WAAO,OAAO,SAAS,EAAE,GAAG,QAAQ,KAAK,OAAO,SAAS,CAAC;AAAA,EAC5D;AACA,QAAM,IAAI,MAAM,yBAAyB,OAAO,OAAO,IAAI,CAAC,+BAA+B;AAC7F;AAGO,SAAS,QAAQ,OAAoC;AAC1D,QAAM,OAAQ,OAAO,KAAK,EAAE,YAAY,KAAK;AAC7C,MAAI,SAAS,YAAY,SAAS,cAAc,SAAS,QAAS,OAAM,IAAI,MAAM,wDAAwD,KAAK,GAAG;AAClJ,SAAO;AACT;","names":[]}
|
package/dist/pg.d.ts
CHANGED
package/dist/postgres.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as PresenceOptions, R as RealtimeBus } from './types-
|
|
1
|
+
import { P as PresenceOptions, R as RealtimeBus } from './types-DF6B0PAU.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The two PostgreSQL primitives the adapter needs — injected, so this module depends on no database client. Bring
|
package/dist/redis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RedisOptions, Redis } from 'ioredis';
|
|
2
|
-
import { P as PresenceOptions, b as PresenceStore, C as ConnectionState, a as PresenceState, d as PresenceInfo, R as RealtimeBus } from './types-
|
|
2
|
+
import { P as PresenceOptions, b as PresenceStore, C as ConnectionState, a as PresenceState, d as PresenceInfo, R as RealtimeBus } from './types-DF6B0PAU.js';
|
|
3
3
|
|
|
4
4
|
interface RedisBusOptions extends Partial<PresenceOptions> {
|
|
5
5
|
/** `redis://` or `rediss://` (Redis or Valkey — DigitalOcean Managed Caching speaks the same protocol). */
|
|
@@ -59,6 +59,6 @@ interface RealtimeBus {
|
|
|
59
59
|
}
|
|
60
60
|
declare const DEFAULT_PRESENCE: PresenceOptions;
|
|
61
61
|
/** The rank of a state: a person is as present as their most present connection. */
|
|
62
|
-
declare const rank: (state: PresenceState) =>
|
|
62
|
+
declare const rank: (state: PresenceState) => 2 | 1 | 0;
|
|
63
63
|
|
|
64
64
|
export { type BusKind as B, type ConnectionState as C, DEFAULT_PRESENCE as D, type PresenceOptions as P, type RealtimeBus as R, type Unsubscribe as U, type PresenceState as a, type PresenceStore as b, type PresenceChange as c, type PresenceInfo as d, rank as r };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krizaka/realtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Realtime for Node apps behind one interface: a bus (publish / subscribe by channel) and presence (who is connected, by heartbeat and TTL), with memory, PostgreSQL LISTEN/NOTIFY and Redis / Valkey adapters, plus Server-Sent Events framing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"krizaka",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"tsup": "^8.5.1",
|
|
83
83
|
"typescript": "^5.9.0",
|
|
84
84
|
"vitest": "^4.1.11",
|
|
85
|
-
"@krizaka/config": "0.
|
|
85
|
+
"@krizaka/config": "0.3.0"
|
|
86
86
|
},
|
|
87
87
|
"engines": {
|
|
88
88
|
"node": ">=20"
|