Skip to content

Bug: LiveMessage value is not generic #655

Description

@draylegend

Describe the bug

https://github.com/surrealdb/surrealdb.js/blob/main/packages/sdk/src/types/live.ts#L19

LiveSubscription<T> is generic, but LiveMessage is not — value is hardcoded as Record<string, unknown>, so the type parameter T passed to db.live<T>() never reaches the subscriber callback. This forces consumers to cast r.value even though the type is known at the call site.

Steps to reproduce

const l = await db.live<Booking & { object: Object }>(new Table('booking'));
let unsub: () => void;

export const CalendarStore = signalStore(
  { providedIn: 'root' },
  withEntities<Booking & { object: Object }>(),
  withHooks(s => ({
    onInit: async () => {
      const data = await db
        .select<Booking & { object: Object }>(new Table('booking'))
        .fetch('object');

      patchState(s, setAllEntities(data, { selectId: e => e.id.toString() }));

      unsub = l.subscribe(async r => {
        if (r.action === 'DELETE') {
          patchState(s, removeEntity(r.recordId.toString()));
        } else if (r.action === 'CREATE' || r.action == 'UPDATE') {
          patchState(
            s,
            upsertEntity(r.value, { selectId: e => e.id.toString() }),
          );
        }
      });
    },
    onDestroy: unsub,
  })),
);

Expected behaviour

LiveMessage<T> with value: T
Actual: LiveMessage with value: Record<string, unknown>

SurrealDB version

3.2.0-dev

JavaScript SDK version

2.0.8

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct (repository /surrealdb.js)

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions