json-joy

repository·master·Indexed 21 days ago

https://github.com/streamich/json-joy

A high-performance library for real-time and collaborative JSON editing centered around the JSON CRDT protocol. The project includes a collection of libraries for building collaborative editing apps, featuring binary data utilities (Reader, Writer, StreamingReader), Base64 encoding/decoding, a bidirectional communication abstraction (@jsonjoy.com/channel), JIT code generation (@jsonjoy.com/codegen), and UI components like ClickableJson and collaborative Ace Editor for React.

Tokens
391.7K
Snippets
1.3K
Records
1.9K
Agent score
77%

What's inside json-joy

  1. Overview of json-joy

    master

    json-joy is a library designed for real-time and collaborative editing of JSON data models. Its primary focus is the implementation of the JSON CRDT protocol, a Conflict-free Replicated Data Type that allows multiple replicas to merge changes seamlessly without conflicts.

    Beyond CRDTs, the library provides high-performance implementations for various JSON-related utilities, including codecs (CBOR, MessagePack, etc.), JSON Patch, JSON Schema validation, and JSON Expressions.

  2. Overview of @jsonjoy.com/rpc-client features

    master

    The @jsonjoy.com/rpc-client is a browser client for JSON Reactive RPC servers. It connects to an @jsonjoy.com/rpc-server instance over WebSocket or HTTP and provides the following capabilities:

    • Transports: WebSocket and HTTP (fetch) via @jsonjoy.com/channel.
    • Codecs: Support for Compact, Binary, and JSON-RPC 2.0.
    • Reliability: Automatic reconnection via PersistentChannel.
    • Type Safety: TypeScript-typed RPC calls.
  3. What is @jsonjoy.com/codegen and when to use it

    master

    The @jsonjoy.com/codegen package is a no-dependencies, low-level, high-performance JIT (Just-In-Time) code generation package for JavaScript. It is designed to generate optimized JavaScript functions at runtime based on schemas, templates, or runtime data.

    When to use JIT code generation

    You should use this package when you have advance knowledge of data structures or execution patterns and need to avoid the overhead of generic processing. Common use cases include:

    • Deep equality comparison: Generating an optimized function to compare objects against a known structure (as seen in the json-equal library).
    • JSON Patch execution: Generating optimized functions to apply patches when the operations are known beforehand (as seen in the json-patch library).
    • Schema-based validation: Generating highly optimized validation and serialization functions from a json-type schema to avoid generic overhead.
    • Custom runtime logic: Creating performance-critical code that benefits from JIT compilation based on specific runtime data.
  4. Overview of JSON CRDT

    master
    JSON CRDT is a Conflict-free Replicated Data Type (CRDT) implementation specifically designed for JSON structures. It allows multiple users or nodes to perform concurrent operations on a JSON document while ensuring that all replicas eventually converge to the same state without a central coordinator. This package provides the core logic for managing shared JSON state in collaborative environments.
  5. Overview of @jsonjoy.com/rpc-server backends and surface

    master

    The @jsonjoy.com/rpc-server package provides an HTTP/1.1 and WebSocket server that exposes Reactive JSON-RPC methods. It supports three RPC protocols (Compact, Binary, JSON-RPC 2.0) and three value codecs (JSON, CBOR, MessagePack) via content-type negotiation.

    Available Backends

    • Node http backend: Uses RpcServer or Http1Server (built on top of Node's http/https with a built-in WebSocket implementation).
    • uWebSockets backend: Uses RpcApp (an alternative backend, often used for testing or high performance).

    Per-request Data

    • ConnectionContext: Used for managing per-request data, token extraction, and codec negotiation.
  6. Available JSON Joy CLI executables

    master

    JSON Joy provides several CLI tools for manipulating and querying JSON documents:

    • json-pack: Encodes a JSON document into MessagePack format.
    • json-unpack: Decodes a JSON document from MessagePack format.
    • json-pointer: Finds a specific value within a JSON document using JSON Pointer syntax.
    • json-patch: Applies a JSON Patch to a JSON document.
    • json-pack-test: Runs tests against the json-pack CLI.
    • json-pointer-test: Runs tests against the json-pointer CLI.
    • json-patch-test: Runs tests against the json-patch CLI.
  7. NFSv3 Protocol Implementation Overview

    master

    The NFSv3 implementation in json-pack provides complete support for the RFC 1813 protocol, covering three distinct layers:

    • NFSv3: Core NFS version 3 protocol operations.
    • MOUNT: The Mount protocol (defined in Appendix I of RFC 1813).
    • NLM: The Network Lock Manager protocol version 4 (defined in Appendix II of RFC 1813).
  8. Features of `@jsonjoy.com/rpc-server`

    master

    The @jsonjoy.com/rpc-server package provides a robust JSON RPC implementation with the following capabilities:

    • Transport Support: HTTP/1.1 server with path-based routing (via @jsonjoy.com/jit-router) and WebSocket upgrade handling with a built-in frame codec (no external WS dependency).
    • Security: TLS support with automatic secure context refresh, CORS support, and authentication token extraction from headers, query parameters, or cookies.
    • Codec & Encoding:
      • RPC Codecs: Supports Compact, Binary, and JSON-RPC 2.0.
      • Value Encodings: Supports JSON, CBOR, and MessagePack.
      • Negotiation: Automatic codec negotiation based on the Content-type header.
  9. Use @jsonjoy.com/rpc-codec-base for RPC message codecs

    master

    The @jsonjoy.com/rpc-codec-base package provides the foundational types and utilities required to implement RPC (Remote Procedure Call) message codecs. It defines the core interfaces and constants used across the json-joy ecosystem for message serialization and streaming.

    Key components include:

    • MsgStreamCodec: An interface for codecs that handle message streams.
    • MsgCodec: An interface for standard message codecs.
    • RpcMessageFormat: Constants defining the supported codec formats.
    • getTypeEncoder: A helper function used by codec implementations to handle type encoding.
    import {RpcMessageFormat} from '@jsonjoy.com/rpc-codec-base';
    import type {MsgStreamCodec} from '@jsonjoy.com/rpc-codec-base';
  10. Use JIT-compiled JSON encoders with json-type

    master

    The json-type package provides JIT-compiled encoders for four wire formats: JSON text, JSON binary, CBOR, and MessagePack. Each encoder takes a type schema and produces a specialized function that writes data without per-call schema lookups.

    Note: json-type only generates the encoders. For decoders, use the @jsonjoy.com/json-pack package.

    import {t, JsonTextCodegen} from '@jsonjoy.com/json-type';
    
    const User = t.Object(
      t.Key('id', t.str),
      t.Key('age', t.Number({format: 'u32'})),
    );
    
    const toJson = JsonTextCodegen.get(User);
    
    toJson({id: 'u_1', age: 30});
    // '{"id":"u_1","age":30}'