适用于 Datastar 超媒体框架的 Common Lisp SDK
Common Lisp SDK for the Datastar Hypermedia Framework

原始链接: https://github.com/fsmunoz/datastar-cl

## Datastar-CL:Common Lisp SDK 概要 Datastar-CL 是 Datastar SDK 的 Common Lisp 实现,设计紧密遵循 Datastar 架构决策记录。它使用 CLOS 提供核心 SDK 功能,围绕用于服务器发送事件 (SSE) 的 `sse-generator` 类构建。 该 SDK 支持两种 Web 服务器方法:Hunchentoot 和 Clack(带有 Woo 或 Hunchentoot 后端)。虽然 Clack+Woo 是可行的,但对于需要大量并发 SSE 连接的应用程序,建议使用 Hunchentoot,因为 Woo 的工作线程存在限制。它使用 JZON 进行 JSON 解析,但这并非强制要求。 最近的添加包括 zstd 压缩支持。示例应用程序,包括 2D 太阳系模拟器(“Data SPICE”)和 Horizons JPL API 浏览器,展示了 SDK 的功能,特别是 SSE 流。全面的测试,包括边缘情况处理,可在 `test/` 目录中找到,以及服务器设置示例。 该项目采用 MIT 许可证,并通过 Quicklisp 轻松访问:`(ql:quickload "datastar-cl")`。

## Datastar Common Lisp SDK 发布 开发者 fsmunoz 发布了 Datastar 超媒体框架的 Common Lisp SDK,旨在简化 Lisp 的使用。该 SDK 专注于处理围绕 Datastar 简单 API 的复杂性,包括维护 SSE 流、压缩(目前为 zstd)以及与 Hunchentoot 和 Clack 等 Web 框架的兼容性。 为了演示该 SDK,fsmunoz 使用 NASA 的 SPICE 工具包和 JPL Horizons API 构建了卡西尼-惠更斯任务的模拟,网址为 [https://dataspice.interlaye.red/](https://dataspice.interlaye.red/)。 讨论强调了 SSE 连接阻塞事件循环的问题,以及使用 Wookie 等库的潜在解决方案。SPICE 应用程序使用 Fortran 解析数据,因为现有的 CL-SPICE 库存在限制,选择 Fortran 是出于熟悉性和易用性的考虑,而非完全的 Lisp 实现。开发者计划为 SDK 添加示例,以便更容易采用。
相关文章

原文

https://github.com/fsmunoz/datastar-cl/actions/workflows/sdk-test.yml/badge.svg

================================================================

       |             
      / \            DATASTAR HYPERMEDIA FRAMEWORK
     /___\          
    |  D  |          
    | C*L |                '(DATASTAR-CL)    
    |     |                 
   /|  |  |\
  | |_ |__| |              COMMON LISP SDK
  |/  /.\  \|            

================================================================

This is a Common Lisp implementation of the Datastar SDK, following the Datastar Architecture Decision Record (ADR) as closely as possible, making the necessary adjustments for Common Lisp.

Focus has been on implementing the core SDK functionality, with additional utilities planned.

Clone the repository somewhere ASDF2 can find it (~~/src/lisp~ is commonly already configured), and use Quicklisp to load it:

(ql:quickload "datastar-cl")

The SDK uses CLOS and is based on a sse-generator class, that currently has two subclasses:

  1. hunchentoot-sse-generator: used with the Hunchentoot web server.
  2. clack-sse-generator: used with the Clack web application environment.

Both approaches use a stream, although in different ways and initialized differently. For Clack, the work done is at the Lack level, and has been tested with both Hunchentoot and Woo.

We are currently using JZON as the JSON parser in two places: read-signals and patch-signals. This is not a hard requirement to remove, but for now it allows immediate use and testing of the library.

SSE and Common Lisp webservers

When using Clack with Woo, SSE connections are limited by Woo’s worker thread count. Each SSE connection blocks one worker for its entire duration. This is a fundamental architectural constraint - see SSE-WOO-LIMITATIONS.org for details and practical solutions.

For applications with many SSE connections, Hunchentoot is recommended (no connection limit), or using a polling approach. By default, Hunchentoot (and Clack+Hunchentoot) uses a push approach, while Clack+Woo defaults to poll.

The test/ directory has some basic examples. Additionally, the following projects use it

  • Data SPICE: uses Datastar-CL for a 2D simulation of the solar system and Cassini-Huygens probe; written in parallel with the SDK to showcase it and also make sure it worked.
  • Horizons JPL API explorer: in the same theme, but a vastly simplified app that queries the Horizons API for solar system data.

The Horizons JPL app is very simple – one single file – and should show the essentials. The Data SPICE application shows SSE streaming.

Support for compression was recently added, currently covering all backends but limited to zstd: read COMPRESSION.org for details.

The test/ directory contains the code to setup and start the supported servers, Hunchentoot and Clack (with Woo and Hunchentoot backends, others can be added). It’s also a good place to use as an example of how the SDK can be used, especially since there are some differences depending on the backend (Hunchentoot or Clack). SSE has a specific test file that can also serve as an example, and some important edge cases (like what happens when connections are interrupted) are tested as well.

The code follows Datastar’s licence choice, the MIT license.

联系我们 contact @ memedata.com