@app-studio/realtime-core 0.1.0

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 ADDED
@@ -0,0 +1,35 @@
1
+ # @app-studio/realtime-core
2
+
3
+ Core event contract for App Studio realtime packages.
4
+
5
+ ```ts
6
+ import {createRealtimeEvent, RealtimeEventSchema} from '@app-studio/realtime-core';
7
+
8
+ const event = createRealtimeEvent({
9
+ type: 'task.progress',
10
+ runId: 'run_123',
11
+ seq: 1,
12
+ scope: {projectId: 'project_123'},
13
+ visibility: 'project',
14
+ payload: {taskId: 'task_123', progressPct: 42},
15
+ });
16
+
17
+ RealtimeEventSchema.parse(event);
18
+ ```
19
+
20
+ The core package is framework-free. It does not know about NestJS, Prisma, React, Socket.IO, or Pub/Sub.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install @app-studio/realtime-core
26
+ ```
27
+
28
+ ## Package boundary
29
+
30
+ - `@app-studio/realtime-core` owns event shape definitions, validation, and shared cursor/deduplication primitives.
31
+ - It has no runtime peers and no framework coupling; transport and persistence layers are implemented in companion packages.
32
+
33
+ ## License
34
+
35
+ This package is proprietary to the App Studio team and marked `UNLICENSED` in `package.json`.
@@ -0,0 +1,6 @@
1
+ export declare const REALTIME_V1: 1;
2
+ export declare const REALTIME_EVENT_VISIBILITY: readonly ["user", "project", "admin", "debug", "internal"];
3
+ export type RealtimeEventVisibility = (typeof REALTIME_EVENT_VISIBILITY)[number];
4
+ export declare const REALTIME_EVENT_STATUS: readonly ["pending", "assigned", "running", "paused", "blocked", "waiting_input", "review", "completed", "failed", "cancelled", "expired", "archived"];
5
+ export type RealtimeEventStatus = (typeof REALTIME_EVENT_STATUS)[number];
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,EAAG,CAAU,CAAC;AAEtC,eAAO,MAAM,yBAAyB,4DAM5B,CAAC;AAEX,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7C,eAAO,MAAM,qBAAqB,wJAaxB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REALTIME_EVENT_STATUS = exports.REALTIME_EVENT_VISIBILITY = exports.REALTIME_V1 = void 0;
4
+ exports.REALTIME_V1 = 1;
5
+ exports.REALTIME_EVENT_VISIBILITY = [
6
+ 'user',
7
+ 'project',
8
+ 'admin',
9
+ 'debug',
10
+ 'internal',
11
+ ];
12
+ exports.REALTIME_EVENT_STATUS = [
13
+ 'pending',
14
+ 'assigned',
15
+ 'running',
16
+ 'paused',
17
+ 'blocked',
18
+ 'waiting_input',
19
+ 'review',
20
+ 'completed',
21
+ 'failed',
22
+ 'cancelled',
23
+ 'expired',
24
+ 'archived',
25
+ ];
26
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,CAAU,CAAC;AAEzB,QAAA,yBAAyB,GAAG;IACvC,MAAM;IACN,SAAS;IACT,OAAO;IACP,OAAO;IACP,UAAU;CACF,CAAC;AAKE,QAAA,qBAAqB,GAAG;IACnC,SAAS;IACT,UAAU;IACV,SAAS;IACT,QAAQ;IACR,SAAS;IACT,eAAe;IACf,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,WAAW;IACX,SAAS;IACT,UAAU;CACF,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { RealtimeEvent } from './schema';
2
+ export type RealtimeCursor = {
3
+ mode: 'seq';
4
+ runId: string;
5
+ seq: number;
6
+ } | {
7
+ mode: 'id';
8
+ id: string;
9
+ };
10
+ export declare function cursorFromEvent(event: RealtimeEvent, mode?: 'seq' | 'id'): RealtimeCursor;
11
+ export declare function eventIsAfterCursor(event: RealtimeEvent, cursor?: RealtimeCursor): boolean;
12
+ export declare function cursorToQuery(cursor?: RealtimeCursor): Record<string, string>;
13
+ //# sourceMappingURL=cursor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../src/cursor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AAE5C,MAAM,MAAM,cAAc,GACtB;IAAC,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAC,GACzC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,CAAC;AAE7B,wBAAgB,eAAe,CAC7B,KAAK,EAAE,aAAa,EACpB,IAAI,GAAE,KAAK,GAAG,IAAY,GACzB,cAAc,CAKhB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAIT;AAED,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAI7E"}
package/dist/cursor.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cursorFromEvent = cursorFromEvent;
4
+ exports.eventIsAfterCursor = eventIsAfterCursor;
5
+ exports.cursorToQuery = cursorToQuery;
6
+ function cursorFromEvent(event, mode = 'seq') {
7
+ if (mode === 'id') {
8
+ return { mode, id: event.id };
9
+ }
10
+ return { mode, runId: event.runId, seq: event.seq };
11
+ }
12
+ function eventIsAfterCursor(event, cursor) {
13
+ if (!cursor)
14
+ return true;
15
+ if (cursor.mode === 'id')
16
+ return event.id > cursor.id;
17
+ return event.runId === cursor.runId && event.seq > cursor.seq;
18
+ }
19
+ function cursorToQuery(cursor) {
20
+ if (!cursor)
21
+ return {};
22
+ if (cursor.mode === 'id')
23
+ return { afterId: cursor.id };
24
+ return { runId: cursor.runId, afterSeq: String(cursor.seq) };
25
+ }
26
+ //# sourceMappingURL=cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.js","sourceRoot":"","sources":["../src/cursor.ts"],"names":[],"mappings":";;AAMA,0CAQC;AAED,gDAOC;AAED,sCAIC;AAvBD,SAAgB,eAAe,CAC7B,KAAoB,EACpB,OAAqB,KAAK;IAE1B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,EAAC,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAC,CAAC;IAC9B,CAAC;IACD,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAC,CAAC;AACpD,CAAC;AAED,SAAgB,kBAAkB,CAChC,KAAoB,EACpB,MAAuB;IAEvB,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;IACtD,OAAO,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;AAChE,CAAC;AAED,SAAgB,aAAa,CAAC,MAAuB;IACnD,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,EAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAC,CAAC;IACtD,OAAO,EAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { RealtimeEvent } from './schema';
2
+ export type RealtimeEventIdentity = Pick<RealtimeEvent, 'id'>;
3
+ export declare class RealtimeDeduper<TEvent extends RealtimeEventIdentity = RealtimeEvent> {
4
+ private readonly maxEntries;
5
+ private readonly seen;
6
+ private readonly order;
7
+ constructor(maxEntries?: number);
8
+ accept(event: TEvent): boolean;
9
+ has(eventId: string): boolean;
10
+ clear(): void;
11
+ private trim;
12
+ }
13
+ //# sourceMappingURL=deduper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deduper.d.ts","sourceRoot":"","sources":["../src/deduper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AAE5C,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAE9D,qBAAa,eAAe,CAC1B,MAAM,SAAS,qBAAqB,GAAG,aAAa;IAKxC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAHvC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;gBAET,UAAU,SAAO;IAE9C,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAQ9B,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI7B,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,IAAI;CAMb"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RealtimeDeduper = void 0;
4
+ class RealtimeDeduper {
5
+ maxEntries;
6
+ seen = new Set();
7
+ order = [];
8
+ constructor(maxEntries = 4096) {
9
+ this.maxEntries = maxEntries;
10
+ }
11
+ accept(event) {
12
+ if (this.seen.has(event.id))
13
+ return false;
14
+ this.seen.add(event.id);
15
+ this.order.push(event.id);
16
+ this.trim();
17
+ return true;
18
+ }
19
+ has(eventId) {
20
+ return this.seen.has(eventId);
21
+ }
22
+ clear() {
23
+ this.seen.clear();
24
+ this.order.length = 0;
25
+ }
26
+ trim() {
27
+ while (this.order.length > this.maxEntries) {
28
+ const oldest = this.order.shift();
29
+ if (oldest)
30
+ this.seen.delete(oldest);
31
+ }
32
+ }
33
+ }
34
+ exports.RealtimeDeduper = RealtimeDeduper;
35
+ //# sourceMappingURL=deduper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deduper.js","sourceRoot":"","sources":["../src/deduper.ts"],"names":[],"mappings":";;;AAIA,MAAa,eAAe;IAMG;IAHZ,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IACzB,KAAK,GAAa,EAAE,CAAC;IAEtC,YAA6B,aAAa,IAAI;QAAjB,eAAU,GAAV,UAAU,CAAO;IAAG,CAAC;IAElD,MAAM,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,OAAO,KAAK,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,OAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IACxB,CAAC;IAEO,IAAI;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YAClC,IAAI,MAAM;gBAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;CACF;AA/BD,0CA+BC"}
@@ -0,0 +1,23 @@
1
+ import { type RealtimeEventStatus, type RealtimeEventVisibility } from './constants';
2
+ import type { RealtimeJsonValue } from './json';
3
+ import { type RealtimeEvent, type RealtimeScope } from './schema';
4
+ export interface CreateRealtimeEventInput<TType extends string = string, TPayload extends RealtimeJsonValue = RealtimeJsonValue> {
5
+ type: TType;
6
+ runId: string;
7
+ seq: number;
8
+ payload: TPayload;
9
+ scope?: RealtimeScope;
10
+ visibility?: RealtimeEventVisibility;
11
+ status?: RealtimeEventStatus;
12
+ source?: string;
13
+ parentEventId?: string;
14
+ meta?: Record<string, RealtimeJsonValue>;
15
+ id?: string;
16
+ timestamp?: string;
17
+ }
18
+ export type TypedRealtimeEvent<TType extends string, TPayload extends RealtimeJsonValue> = RealtimeEvent & {
19
+ type: TType;
20
+ payload: TPayload;
21
+ };
22
+ export declare function createRealtimeEvent<TType extends string, TPayload extends RealtimeJsonValue>(input: CreateRealtimeEventInput<TType, TPayload>): TypedRealtimeEvent<TType, TPayload>;
23
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,mBAAmB,EAAE,KAAK,uBAAuB,EAAC,MAAM,aAAa,CAAC;AAChG,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,wBAAwB,CACvC,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,QAAQ,SAAS,iBAAiB,GAAG,iBAAiB;IAEtD,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,QAAQ,CAAC;IAClB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IACzC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,kBAAkB,CAC5B,KAAK,SAAS,MAAM,EACpB,QAAQ,SAAS,iBAAiB,IAChC,aAAa,GAAG;IAAC,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAC,CAAC;AAErD,wBAAgB,mBAAmB,CACjC,KAAK,SAAS,MAAM,EACpB,QAAQ,SAAS,iBAAiB,EAElC,KAAK,EAAE,wBAAwB,CAAC,KAAK,EAAE,QAAQ,CAAC,GAC/C,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAkBrC"}
package/dist/event.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRealtimeEvent = createRealtimeEvent;
4
+ const ulid_1 = require("ulid");
5
+ const constants_1 = require("./constants");
6
+ const schema_1 = require("./schema");
7
+ function createRealtimeEvent(input) {
8
+ const event = schema_1.RealtimeEventSchema.parse({
9
+ v: constants_1.REALTIME_V1,
10
+ id: input.id ?? `evt_${(0, ulid_1.ulid)()}`,
11
+ type: input.type,
12
+ runId: input.runId,
13
+ seq: input.seq,
14
+ timestamp: input.timestamp ?? new Date().toISOString(),
15
+ scope: input.scope ?? {},
16
+ visibility: input.visibility ?? 'user',
17
+ status: input.status,
18
+ source: input.source,
19
+ parentEventId: input.parentEventId,
20
+ payload: input.payload,
21
+ meta: input.meta,
22
+ });
23
+ return event;
24
+ }
25
+ //# sourceMappingURL=event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":";;AAgCA,kDAuBC;AAvDD,+BAA0B;AAC1B,2CAAgG;AAEhG,qCAIkB;AAyBlB,SAAgB,mBAAmB,CAIjC,KAAgD;IAEhD,MAAM,KAAK,GAAG,4BAAmB,CAAC,KAAK,CAAC;QACtC,CAAC,EAAE,uBAAW;QACd,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,OAAO,IAAA,WAAI,GAAE,EAAE;QAC/B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACtD,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE;QACxB,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,MAAM;QACtC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC,CAAC;IAEH,OAAO,KAA4C,CAAC;AACtD,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from './constants';
2
+ export * from './cursor';
3
+ export * from './deduper';
4
+ export * from './event';
5
+ export * from './json';
6
+ export * from './schema';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./constants"), exports);
18
+ __exportStar(require("./cursor"), exports);
19
+ __exportStar(require("./deduper"), exports);
20
+ __exportStar(require("./event"), exports);
21
+ __exportStar(require("./json"), exports);
22
+ __exportStar(require("./schema"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,0CAAwB;AACxB,yCAAuB;AACvB,2CAAyB"}
package/dist/json.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ export type RealtimeJsonValue = null | string | number | boolean | RealtimeJsonValue[] | {
3
+ [key: string]: RealtimeJsonValue;
4
+ };
5
+ export declare const RealtimeJsonValueSchema: z.ZodType<RealtimeJsonValue>;
6
+ export declare function toRealtimeJsonValue(value: unknown): RealtimeJsonValue;
7
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,MAAM,MAAM,iBAAiB,GACzB,IAAI,GACJ,MAAM,GACN,MAAM,GACN,OAAO,GACP,iBAAiB,EAAE,GACnB;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAAC,CAAC;AAEvC,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAUhE,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,CAErE"}
package/dist/json.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RealtimeJsonValueSchema = void 0;
4
+ exports.toRealtimeJsonValue = toRealtimeJsonValue;
5
+ const zod_1 = require("zod");
6
+ exports.RealtimeJsonValueSchema = zod_1.z.lazy(() => zod_1.z.union([
7
+ zod_1.z.null(),
8
+ zod_1.z.string(),
9
+ zod_1.z.number(),
10
+ zod_1.z.boolean(),
11
+ zod_1.z.array(exports.RealtimeJsonValueSchema),
12
+ zod_1.z.record(zod_1.z.string(), exports.RealtimeJsonValueSchema),
13
+ ]));
14
+ function toRealtimeJsonValue(value) {
15
+ return exports.RealtimeJsonValueSchema.parse(value);
16
+ }
17
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":";;;AAsBA,kDAEC;AAxBD,6BAAsB;AAUT,QAAA,uBAAuB,GAAiC,OAAC,CAAC,IAAI,CACzE,GAAG,EAAE,CACH,OAAC,CAAC,KAAK,CAAC;IACN,OAAC,CAAC,IAAI,EAAE;IACR,OAAC,CAAC,MAAM,EAAE;IACV,OAAC,CAAC,MAAM,EAAE;IACV,OAAC,CAAC,OAAO,EAAE;IACX,OAAC,CAAC,KAAK,CAAC,+BAAuB,CAAC;IAChC,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,+BAAuB,CAAC;CAC9C,CAAC,CACL,CAAC;AAEF,SAAgB,mBAAmB,CAAC,KAAc;IAChD,OAAO,+BAAuB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,116 @@
1
+ import { z } from 'zod';
2
+ export declare const RealtimeEventIdSchema: z.ZodString;
3
+ export declare const RealtimeEventTypeSchema: z.ZodString;
4
+ export declare const RealtimeScopeSchema: z.ZodObject<{
5
+ tenantId: z.ZodOptional<z.ZodString>;
6
+ projectId: z.ZodOptional<z.ZodString>;
7
+ threadId: z.ZodOptional<z.ZodString>;
8
+ userId: z.ZodOptional<z.ZodString>;
9
+ channelId: z.ZodOptional<z.ZodString>;
10
+ }, z.core.$strict>;
11
+ export type RealtimeScope = z.infer<typeof RealtimeScopeSchema>;
12
+ export declare const RealtimeEventSchema: z.ZodObject<{
13
+ v: z.ZodLiteral<1>;
14
+ id: z.ZodString;
15
+ type: z.ZodString;
16
+ runId: z.ZodString;
17
+ seq: z.ZodNumber;
18
+ timestamp: z.ZodString;
19
+ scope: z.ZodDefault<z.ZodObject<{
20
+ tenantId: z.ZodOptional<z.ZodString>;
21
+ projectId: z.ZodOptional<z.ZodString>;
22
+ threadId: z.ZodOptional<z.ZodString>;
23
+ userId: z.ZodOptional<z.ZodString>;
24
+ channelId: z.ZodOptional<z.ZodString>;
25
+ }, z.core.$strict>>;
26
+ visibility: z.ZodDefault<z.ZodEnum<{
27
+ user: "user";
28
+ project: "project";
29
+ admin: "admin";
30
+ debug: "debug";
31
+ internal: "internal";
32
+ }>>;
33
+ status: z.ZodOptional<z.ZodEnum<{
34
+ pending: "pending";
35
+ assigned: "assigned";
36
+ running: "running";
37
+ paused: "paused";
38
+ blocked: "blocked";
39
+ waiting_input: "waiting_input";
40
+ review: "review";
41
+ completed: "completed";
42
+ failed: "failed";
43
+ cancelled: "cancelled";
44
+ expired: "expired";
45
+ archived: "archived";
46
+ }>>;
47
+ source: z.ZodOptional<z.ZodString>;
48
+ parentEventId: z.ZodOptional<z.ZodString>;
49
+ payload: z.ZodType<import("./json").RealtimeJsonValue, unknown, z.core.$ZodTypeInternals<import("./json").RealtimeJsonValue, unknown>>;
50
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<import("./json").RealtimeJsonValue, unknown, z.core.$ZodTypeInternals<import("./json").RealtimeJsonValue, unknown>>>>;
51
+ }, z.core.$strict>;
52
+ export type RealtimeEvent = z.infer<typeof RealtimeEventSchema>;
53
+ export type RealtimeEventType = RealtimeEvent['type'];
54
+ export declare function createRealtimeEventSchema<TType extends string, TPayload extends z.ZodType>(type: TType, payload: TPayload): z.ZodObject<{
55
+ v: z.ZodLiteral<1>;
56
+ id: z.ZodString;
57
+ runId: z.ZodString;
58
+ seq: z.ZodNumber;
59
+ timestamp: z.ZodString;
60
+ scope: z.ZodDefault<z.ZodObject<{
61
+ tenantId: z.ZodOptional<z.ZodString>;
62
+ projectId: z.ZodOptional<z.ZodString>;
63
+ threadId: z.ZodOptional<z.ZodString>;
64
+ userId: z.ZodOptional<z.ZodString>;
65
+ channelId: z.ZodOptional<z.ZodString>;
66
+ }, z.core.$strict>>;
67
+ visibility: z.ZodDefault<z.ZodEnum<{
68
+ user: "user";
69
+ project: "project";
70
+ admin: "admin";
71
+ debug: "debug";
72
+ internal: "internal";
73
+ }>>;
74
+ status: z.ZodOptional<z.ZodEnum<{
75
+ pending: "pending";
76
+ assigned: "assigned";
77
+ running: "running";
78
+ paused: "paused";
79
+ blocked: "blocked";
80
+ waiting_input: "waiting_input";
81
+ review: "review";
82
+ completed: "completed";
83
+ failed: "failed";
84
+ cancelled: "cancelled";
85
+ expired: "expired";
86
+ archived: "archived";
87
+ }>>;
88
+ source: z.ZodOptional<z.ZodString>;
89
+ parentEventId: z.ZodOptional<z.ZodString>;
90
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<import("./json").RealtimeJsonValue, unknown, z.core.$ZodTypeInternals<import("./json").RealtimeJsonValue, unknown>>>>;
91
+ type: z.ZodLiteral<TType>;
92
+ payload: TPayload;
93
+ }, z.core.$strict>;
94
+ export declare function parseRealtimeEvent(input: unknown): RealtimeEvent;
95
+ export declare function safeParseRealtimeEvent(input: unknown): z.ZodSafeParseResult<{
96
+ v: 1;
97
+ id: string;
98
+ type: string;
99
+ runId: string;
100
+ seq: number;
101
+ timestamp: string;
102
+ scope: {
103
+ tenantId?: string | undefined;
104
+ projectId?: string | undefined;
105
+ threadId?: string | undefined;
106
+ userId?: string | undefined;
107
+ channelId?: string | undefined;
108
+ };
109
+ visibility: "user" | "project" | "admin" | "debug" | "internal";
110
+ payload: import("./json").RealtimeJsonValue;
111
+ status?: "pending" | "assigned" | "running" | "paused" | "blocked" | "waiting_input" | "review" | "completed" | "failed" | "cancelled" | "expired" | "archived" | undefined;
112
+ source?: string | undefined;
113
+ parentEventId?: string | undefined;
114
+ meta?: Record<string, import("./json").RealtimeJsonValue> | undefined;
115
+ }>;
116
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAQtB,eAAO,MAAM,qBAAqB,aAEO,CAAC;AAE1C,eAAO,MAAM,uBAAuB,aAIW,CAAC;AAEhD,eAAO,MAAM,mBAAmB;;;;;;kBAQrB,CAAC;AAEZ,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgBrB,CAAC;AAEZ,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;AAEtD,wBAAgB,yBAAyB,CACvC,KAAK,SAAS,MAAM,EACpB,QAAQ,SAAS,CAAC,CAAC,OAAO,EAC1B,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAK/B;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAEhE;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;GAEpD"}
package/dist/schema.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RealtimeEventSchema = exports.RealtimeScopeSchema = exports.RealtimeEventTypeSchema = exports.RealtimeEventIdSchema = void 0;
4
+ exports.createRealtimeEventSchema = createRealtimeEventSchema;
5
+ exports.parseRealtimeEvent = parseRealtimeEvent;
6
+ exports.safeParseRealtimeEvent = safeParseRealtimeEvent;
7
+ const zod_1 = require("zod");
8
+ const constants_1 = require("./constants");
9
+ const json_1 = require("./json");
10
+ exports.RealtimeEventIdSchema = zod_1.z
11
+ .string()
12
+ .regex(/^evt_[0-9A-HJKMNP-TV-Z]{26}$/i);
13
+ exports.RealtimeEventTypeSchema = zod_1.z
14
+ .string()
15
+ .min(3)
16
+ .max(120)
17
+ .regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/);
18
+ exports.RealtimeScopeSchema = zod_1.z
19
+ .object({
20
+ tenantId: zod_1.z.string().min(1).optional(),
21
+ projectId: zod_1.z.string().min(1).optional(),
22
+ threadId: zod_1.z.string().min(1).optional(),
23
+ userId: zod_1.z.string().min(1).optional(),
24
+ channelId: zod_1.z.string().min(1).optional(),
25
+ })
26
+ .strict();
27
+ exports.RealtimeEventSchema = zod_1.z
28
+ .object({
29
+ v: zod_1.z.literal(constants_1.REALTIME_V1),
30
+ id: exports.RealtimeEventIdSchema,
31
+ type: exports.RealtimeEventTypeSchema,
32
+ runId: zod_1.z.string().min(1),
33
+ seq: zod_1.z.number().int().positive(),
34
+ timestamp: zod_1.z.string().datetime(),
35
+ scope: exports.RealtimeScopeSchema.default({}),
36
+ visibility: zod_1.z.enum(constants_1.REALTIME_EVENT_VISIBILITY).default('user'),
37
+ status: zod_1.z.enum(constants_1.REALTIME_EVENT_STATUS).optional(),
38
+ source: zod_1.z.string().max(120).optional(),
39
+ parentEventId: exports.RealtimeEventIdSchema.optional(),
40
+ payload: json_1.RealtimeJsonValueSchema,
41
+ meta: zod_1.z.record(zod_1.z.string(), json_1.RealtimeJsonValueSchema).optional(),
42
+ })
43
+ .strict();
44
+ function createRealtimeEventSchema(type, payload) {
45
+ return exports.RealtimeEventSchema.extend({
46
+ type: zod_1.z.literal(type),
47
+ payload,
48
+ });
49
+ }
50
+ function parseRealtimeEvent(input) {
51
+ return exports.RealtimeEventSchema.parse(input);
52
+ }
53
+ function safeParseRealtimeEvent(input) {
54
+ return exports.RealtimeEventSchema.safeParse(input);
55
+ }
56
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":";;;AAmDA,8DAQC;AAED,gDAEC;AAED,wDAEC;AAnED,6BAAsB;AACtB,2CAIqB;AACrB,iCAA+C;AAElC,QAAA,qBAAqB,GAAG,OAAC;KACnC,MAAM,EAAE;KACR,KAAK,CAAC,+BAA+B,CAAC,CAAC;AAE7B,QAAA,uBAAuB,GAAG,OAAC;KACrC,MAAM,EAAE;KACR,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,GAAG,CAAC;KACR,KAAK,CAAC,qCAAqC,CAAC,CAAC;AAEnC,QAAA,mBAAmB,GAAG,OAAC;KACjC,MAAM,CAAC;IACN,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtC,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACvC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACtC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACpC,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACxC,CAAC;KACD,MAAM,EAAE,CAAC;AAIC,QAAA,mBAAmB,GAAG,OAAC;KACjC,MAAM,CAAC;IACN,CAAC,EAAE,OAAC,CAAC,OAAO,CAAC,uBAAW,CAAC;IACzB,EAAE,EAAE,6BAAqB;IACzB,IAAI,EAAE,+BAAuB;IAC7B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACxB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAChC,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,KAAK,EAAE,2BAAmB,CAAC,OAAO,CAAC,EAAE,CAAC;IACtC,UAAU,EAAE,OAAC,CAAC,IAAI,CAAC,qCAAyB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7D,MAAM,EAAE,OAAC,CAAC,IAAI,CAAC,iCAAqB,CAAC,CAAC,QAAQ,EAAE;IAChD,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;IACtC,aAAa,EAAE,6BAAqB,CAAC,QAAQ,EAAE;IAC/C,OAAO,EAAE,8BAAuB;IAChC,IAAI,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,8BAAuB,CAAC,CAAC,QAAQ,EAAE;CAC/D,CAAC;KACD,MAAM,EAAE,CAAC;AAKZ,SAAgB,yBAAyB,CAGvC,IAAW,EAAE,OAAiB;IAC9B,OAAO,2BAAmB,CAAC,MAAM,CAAC;QAChC,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QACrB,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,OAAO,2BAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED,SAAgB,sBAAsB,CAAC,KAAc;IACnD,OAAO,2BAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@app-studio/realtime-core",
3
+ "version": "0.1.0",
4
+ "license": "UNLICENSED",
5
+ "type": "commonjs",
6
+ "description": "Core realtime event envelope, schemas, cursor helpers, and deduplication utilities.",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "engines": {
10
+ "node": ">=20"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/rize-network/realtime.git",
15
+ "directory": "packages/realtime-core"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md"
23
+ ],
24
+ "dependencies": {
25
+ "ulid": "^2.4.0",
26
+ "zod": "^4.3.6"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.0.0",
30
+ "typescript": "^5.9.3"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc -p tsconfig.json",
34
+ "test": "tsc -p tsconfig.test.json && node --test $(find dist-test -name '*.test.js' -print)"
35
+ }
36
+ }