swarpc - v0.19.0
    Preparing search index...

    Changelog

    All notable changes to this project will be documented in this file.

    The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

    • .broadcast.once and .broadcast.onceBy. Works just like .once or .onceBy, but sends the request to multiple nodes just like .broadcast.
    • Convenience properties on the return value of broadcasted calls
    • .broadcast{.once,.onceBy,}.orThrow(): aggregate method that throws if any node failed and returns the array of results otherwise.
    • nodes property in the third ("tools") argument of procedure implementations, containing the set of all available node IDs.
    • Client#destroy to terminate workers and disconnect event listeners.
    • Client:options.nodeIds to specify the list of node IDs to use instead of generating them automatically.
    • Request cancellations now throw a RequestCancelledError instead of just a Error. Useful to specifically catch cancellation errors.
    • Prevent starting a client if some method names clash with reserved names (onceBy, destroy). The complete list is available on the exported constant RESERVED_PROCEDURE_NAMES.
    • "Once mode": a way to call methods that auto-cancel previous ongoing calls to the same method. See the documentation for more details.
    • Previous release did not contain the newly built files, this one does.
    • Hook arguments' type unions were not correctly discriminated. The behavior documented in the 0.17.0 changelog entry is now correctly implemented.
    • BREAKING: Hooks now receive a single object argument instead of two positional arguments. This greatly helps with type narrowing if you check for the procedure name.

      Before:

      Client(procedures, {
      hooks: {
      success(procedure, data) {
      if (procedure === "getUser") {
      // `data` is not narrowed down to the type returned by `getUser` :(
      }
      },
      },
      });

      After:

      Client(procedures, {
      hooks: {
      success({ procedure, data }) {
      if (procedure === "getUser") {
      // `data` is now correctly narrowed down to the type returned by `getUser` :)
      }
      },
      },
      });

      To update, simply change your hook implementations to use a single object argument and destructure (or not) the properties you need from it.

    • Type of procedure implementations' input argument was incorrectly specified as Schema.InferInput<InputSchema>, it is now Schema.InferOutput<InputSchema>, as the server receives the transformed input object.

      For example, if you had the following procedure declaration:

      export const procedures = {
      ...
      foo: {
      input: type('string.date.parse').
      ...
      }
      }

      Before, the implementation would show this type

      server.foo((input, onProgress) => {
      // ^?: string
      ...
      })

      It now correctly shows

      server.foo((input, onProgress) => {
      // ^?: Date
      ...
      })
    • The package is now much smaller, clocking in at around 3kB (minified + gzipped) instead of 44 kB ! This is thanks to the removal of internal APIs' type definitions, source maps, and the only runtime dependency, arktype (type-checking code is now hand-written, there wasn't a lot of it anyway).
    • BREAKING: The logger options in the third argument of procedure implementations has been removed. Just use console.log instead:

      - server.myProcedure(async (args, onProgress, { logger }) => {
      + server.myProcedure(async (args, onProgress) => {
      -   logger.info("Doing something")
      +   console.log("Doing something")
      });
      
    • Functions and types for internal things have been removed from the public API. The only remaining API surface is the one documented in the README (Server, Client and their related types).

    • Console logs called from within procedures' implementations had their message weirdly colored. The logs are now correctly prefixed with node & request IDs
    • Support for any Standard Schema-compliant validation library, instead of just ArkType
    • BREAKING: Client#(method name).broadcast:onProgress now receives a map of nodeId to progress values, which makes aggregating individual nodes' progress data into a single coherent progress value easier:

      import { sum } from "./utils";

      await client.thing.broadcast(67, (ps) =>
      console.log((sum(ps.values()) / ps.size) * 100 + "% done"),
      );
    • Procedure implementations now have access to nodeId, the ID of the node executing the request, in the tools argument.
    • A new option, Client:option.nodes, to control the number of nodes (worker instances) to spin up
    • A way to broadcast requests to multiple (or all) nodes at once with Client#(method name).broadcast
    • BREAKING: Client:options.worker is now either a string (path to the worker's source code) or a class, not an instance
    • BREAKING: When Client:options.worker is set, the Client now launches by default navigator.hardwareConcurrency nodes (worker instances) and dispatches requests to them in a balanced way.
    • Client:options.localStorage to define a Server-accessible polyfilled localStorage with data (See #32)
    • BREAKING: Server#start is now asynchronous, but does not take an argument anymore.
    • sw&rpc now handles Shared Workers correctly
    • Server:options.worker is correctly typed
    • A undefined-valued result message was sent after a thrown implementation error, resulting in a internal 'No pending request handlers' error
    • "Invalid entry point" error when trying to import Swarpc
    • Type of Server#start's self parameter now correctly accepts both Window and Worker contexts.
    • build problems when using Vite
    • client-side hooks
    • messages not intended for swarpc are ignored by the server