Skip to content

Release v0.8.0

Compare
Choose a tag to compare
@kearfy kearfy released this 06 Jun 10:02
· 149 commits to main since this release
3404d44

Notes on this release

  • Breaking: Fix typings for .select(), .create(), .update(), .merge(), .patch(), .delete()

    • After this PR, all of the above mentioned functions will always return an array, regardless of the method or if you are selecting a table or a specific record.
    • The .select() methods now returns an array instead of a single item.
    • The .change() method is renamed to .merge().
    • The .modify() method is renamed to .patch().
    • The above mentioned functions now always return an array, never a single item or undefined.
  • Breaking: The .use() function now accepts an object as an argument .use({ ns, db }).

  • You can now pass an auth property to the second argument of the constructor and connect functions. This can be a token string or an object you would pass to the .signin() function.

  • You can now pass a pair of { ns, db } to the second argument of the constructor and connect functions.

  • The auth state and ns/db combo will now be remembered after a possible WebSocket disconnect and will automatically be restored.

  • Added back the Live Queries implementation (read down below)

Live Queries implementation

Start a live query

const uuid = await surreal.live<{
    id: string;
    prop: number;
}>("query...", (data) => {
    if (data.action === 'CLOSE") return;
    console.log(data.result);
});

Register another listener for an LQ

await surreal.listenLive<{
    id: string;
    prop: number;
}>("uuid...", (data) => {
    if (data.action === 'CLOSE") return;
    console.log("Second listener! ", data.result);
});

Kill a LQ

await surreal.kill("uuid...");

Data in callback

type close = {
    action: "CLOSE",
    detail: "SOCKET_CLOSED" | "QUERY_KILLED"
};

type create = {
    action: "CREATE";
    result: Record<string, unknown>;  // Generic type that was passed, always extends default type
};

type update = {
    action: "UPDATE";
    result: Record<string, unknown>;  // Generic type that was passed, always extends default type
};

type delete = {
    action: "DELETE";
    result: Record<string, unknown>;  // Generic type that was passed, always extends default type
};

What's Changed

  • Fix typings for .select(), .create(), .update(), .merge(), .patch(), .delete() by @kearfy in #104
  • Remember auth across possible disconnects by @kearfy in #118
  • Live Queries implementation by @kearfy in #112
  • Bump v0.8.0 by @kearfy in #126

Full Changelog: v0.7.3...v0.8.0 (might not completely align with above notes, v0.7.3 was a little bit quirky)