Skip to content

Latest commit

 

History

History

packages

README.md

Workspace packages

This directory holds Studio's bun workspace packages: code staged as separate packages inside this repository before it moves to a repository of its own. The grant register, packages/grant-register/, @libredb/grant-register, is the exception: it holds the schema and reader of an engine's grants and LibreDB's review of each engine Studio still serves through its legacy adapter, and stays in Studio's repository until those engines move, unlike the packages staged for a repository of their own. A package engine's grant is its own manifest's grants member for a package Studio bundles, and its providers lock entry's for an operator's package, instead (docs/providers/CONTRACT.md, M-84). The root package.json declares them with "workspaces": ["packages/*"]. The first package is packages/provider-sdk/, @libredb/provider-sdk: the provider contract's schema, its generated types and its validator under /manifest, the value codec and the JSON text and byte count readers under /values, the error record's contract under /errors, the call surface a provider package implements, with the metadata-only projection and its check and the function table's slots and answer check, under /calls, the SQL grammar facts, Studio's shared SQL writing functions, the declared column types collector, Studio's SQL span and word readers and the grammar compiler that turns declared grammar facts into a grammar under /sql, the row helpers (column naming and rows keyed by position) under /rows, the JSON values a console body is read into and the console grammar (a dialect and route table as data, the line tokeniser, the one reader of a request text and its refusals, the refused route sentence and the body readers) and the shell word reader (one command line read as words by the POSIX shell's quoting, its refusals, the line tokeniser and the quoting of a word) under /console, the vector family's pure layer (what a vector field, a score and a count are, and the checks, readers and labels every vector engine shares) under /vector, the order of object paths under /objects, the HTTP request a provider dials with (the origin builder, the endpoint joiner, the text transport and the failure wording) under /net, the gRPC channel a provider dials with, its credentials and its TLS reader under /grpc, which needs @grpc/grpc-js, the SDK's one optional peer dependency, and which the package root does not carry, what an SQL dialect composes agent statements with (the composed statement building blocks, the catalog cell readers, and the table index and helpers a catalog capture builder fills) under /agent, the bounded XML reader a provider reads a service's XML answers with (the tree reader, the walk over the elements a caller keeps and the text cutter, every bound passed in by the caller) under /xml, the tokenizer an engine states as data for its editor language and the one interpreter that reads it (the refusals the manifest validator also reads, the compiler and the line tokenizer, whose patterns run on a matcher that never backtracks within a step budget per line) under /tokenizer, and the memory test transport its tests and the kit call a provider through under /testing (docs/providers/CONTRACT.md).

Layout

A workspace package is a directory packages/<name>/ holding a package.json. Its source is under packages/<name>/src/ and its tests are under packages/<name>/tests/, with packages/<name>/tests/live/ left to be run by hand, as the root's tests/live/ is. A provider package also holds the build modules its build script runs, outside src/ and tests/ ("Provider packages" below), and the package import rule reads them as code. Nothing else under packages/ is code. A file such as this README is not a package, and a directory without a package.json is refused by name by every gate that lists packages, so a stray directory never holds tests that silently do not run.

scripts/workspace-packages.mjs states this rule once, and the gates below read it from there.

Provider packages

A database provider can live as a workspace package named for its type-id, packages/provider-<type-id>/. It holds the three legs of the provider triad: its code under src/, its doc as docs/<type-id>.md, and its integration test as tests/integration/<type-id>-provider.test.ts. A type-id lives in exactly one layout, so the change that moves a provider here deletes its legacy code under src/lib/db/providers/, its docs/providers/<type-id>.md and its tests/integration/db/<type-id>-provider.test.ts. A package serves only the type-id its directory names, until the provider manifest can declare several, so a doc or an integration test for another type-id in any package is refused. The agent leg has no place in a package yet, so a type-id whose granted statement language is non-null stays in the legacy layout until the change that moves it gives its package one, unless its manifest states that language as data (statementLanguageData), whose overlay is the manifest's own and which keeps no agent leg file in core. tests/unit/db/provider-triad.test.ts holds these rules for every shipped type-id, and tests/helpers/provider-layout.ts is how a test finds a provider's files in either layout. A provider package's manifest is packages/provider-<type-id>/libredb-provider.json, the artifact's own name and place. Its package.json has a build script, node <file> for a JavaScript module the package holds outside src/ and tests/, that takes --outdir <absolute directory> and writes the manifest's runtime.entry and every other file the artifact needs there, among them the file an engine's sample member names as its asset, with its attribution beside it. Studio reads a declared sample only from a package its distribution bundles (docs/SEED_CONNECTIONS.md, "A sample a provider package declares"). bun run providers:pack runs that script and places the artifact in a providers directory (docs/TOOLCHAIN.md, "The provider pack step (providers:pack)").

Install

bunfig.toml sets [install] linker = "hoisted". Without it, bun 1.4.4 installs a workspace root with its isolated linker as soon as one package exists, which moves every dependency under node_modules/.bun and changes the layout Studio builds, tests and ships with. With it, the layout stays the one a root without packages gets, and each package is linked at node_modules/<name>. The linker is not recorded in bun.lock, so the setting has to travel with every install, the images' included.

Imports

Every module a package holds, its source, its tests and the modules its build script runs, imports its own files, Node built-ins, the names its package.json declares and @libredb/provider-sdk, and a module of its tests may also import a bun: module such as bun:test. A package's build script is node <file> for a module it holds outside src/ and tests/, named by a path of letters, digits, ., _, - and / with no .. segment, and the package has no prebuild or postbuild script, which bun run build runs around the build. In this repository a build module, a module outside src/ and tests/, also imports no child_process, and a package directory holds no bunfig.toml in any case of its letters, which can make the build's node run Bun. The rule reads the specifiers written in a module, so a computed import() or a createRequire call is not judged. A package never imports an @/ path or a path out of its own directory, so it depends on no other package's internals and on none of Studio's, and moving it to a repository of its own changes no import. Studio's own code, under src/, bin/, scripts/, tests/, e2e/ and vscode-extension/src/, reaches a package only by its name, never by a path into packages/, so what Studio sees of a package is what its exports publish. Studio's own code never imports a provider package, by name or by path, so a provider's code reaches Studio only through admission; @libredb/provider-sdk and @libredb/provider-loader are the two @libredb/provider- names it imports. The published library's composed module, .lib-build/library-bundled-packages.mjs, is a git-ignored build output outside Studio's code directories: the library's stage step writes it from its lock's data, and it imports a staged artifact by its path in the staging directory, never packages/ or a package name, and only for a package the stage step admitted (scripts/library-providers.ts). Nor does it import a driver a provider package declares in its dependencies, optionalDependencies or peerDependencies, unless CORE_IMPORTED_DRIVERS in scripts/check-build-output.ts names that importer, so a driver leaves Studio with its engine. A package never imports or declares another provider package: only @libredb/provider-sdk, and @libredb/provider-kit in its tests and its devDependencies. A root file that imports a package by name needs the package in the root devDependencies as "workspace:*", or knip reports it as unlisted. tests/unit/package-imports.test.ts holds these rules.

Docker

Each Dockerfile installs its dependencies from a partial file set, and two files change what that install does without failing it. Without bunfig.toml the image installs with the isolated linker, and without a package's package.json a frozen install skips the package and still exits 0. So the deps stage copies package.json bun.lock bunfig.toml together, and adding a package adds one line to each of the three Dockerfiles, before RUN bun install --frozen-lockfile:

COPY packages/<name>/package.json ./packages/<name>/

A wildcard COPY would flatten the directories, so each package has its own line. tests/unit/docker-workspace-install.test.ts fails when a Dockerfile lacks one. The builder stage asserts that .next/standalone/packages does not exist, and scripts/lib/prune-standalone-payload.sh removes packages/ from every standalone payload.

Library

@libredb/studio on npm cannot depend on an unpublished package, so the library build (tsup.config.ts) bundles every workspace package, its code and its declarations, by the names scripts/workspace-packages.mjs lists. The declaration build resolves a package through TypeScript paths that map each of its exports entries, the root and every subpath, to the entry's file under packages/<name>/ (workspacePackageSourcePaths), so rollup-plugin-dts inlines the package's declarations, its own relative imports included, instead of leaving an import of the unpublished package. Every exports entry is therefore one path string; a conditional-exports object is refused by name, because no single source file stands for it. A package is never a root dependencies, peerDependencies or optionalDependencies entry, since a consumer's install would look for it on the registry; the root may list it under devDependencies. Every dependencies and peerDependencies name of a package is also a root dependencies or peerDependencies name, because the bundled package's drivers are the library's own. A provider package is the exception to that rule: nothing under src/ imports one, so the library bundles no provider package's source, and a provider package ships as its own packed artifact with its driver inside. The library's build imports each carried artifact's entry by its path in dist/providers/, from the module its stage step wrote (docs/TOOLCHAIN.md, build:lib). bun run lib:load enforces all of this on the packed package (docs/TOOLCHAIN.md, "The packed library loads (lib:load)").

The SDK tarball

bun run sdk:pack -- --out <dir> builds @libredb/provider-sdk into a tarball of ES modules with declarations that a provider developer outside the repository installs with npm. The repository's packages/provider-sdk/package.json keeps its entry points on the source; the packed package.json points them at dist/, written at pack time. The build runs in a temporary directory and writes nothing into the repository. docs/TOOLCHAIN.md, "The SDK tarball (sdk:pack)", records why and what the pack test checks.

Planes

Tests resolve source: a package's exports, main, module and types point under its src/, and no test under tests/ or packages/<name>/tests/ imports a dist/ path, @libredb/studio by name or a package's dist/ subpath. bun run lib:load, bun run lib:lock and the lock module's build test (tests/unit/scripts/build-lock-module.test.ts), which builds the module it runs, the SDK's pack test (packages/provider-sdk/tests/pack.test.ts), which builds the tarball it reads, and the out-of-tree acceptance (scripts/out-of-tree-acceptance.ts), which packs the tarball it installs, are the only paths through a built artifact. tests/unit/source-plane.test.ts holds both rules.

Gates

Every gate that finds its files by a src/ or tests/ path also reads a package:

  • The test runner (tests/runner/discover.ts) runs packages/<name>/tests/ beside tests/, and accepts a selector under either.
  • The focused-test guard (scripts/only-check.mjs) reads the tracked files under packages/<name>/tests/.
  • The coverage merge (scripts/merge-lcov.mjs) keeps packages/<name>/src/ records, so a package's uncovered line counts against the coverage floor, and bun run coverage:check passes --packages-from=., so a package with a src/ directory and no record fails it by name.
  • SonarCloud (sonar-project.properties) reads a package's src/ as source and its tests/ as tests.
  • Biome (biome.json files.includes) formats packages/**.
  • oxlint and ESLint lint the whole tree, and the type-aware ESLint block also covers packages/*/src/**/*.ts.
  • ESLint refuses process.env, process.cwd(), globalThis, global and console in packages/provider-*/src/ (the kit excepted), with no inline disable (docs/TOOLCHAIN.md, "Provider source coupling lint").
  • knip analyses each package as a workspace, through the root package.json workspaces.
  • The root tsc checks every .ts file under the root, packages included.
  • The packed library check (bun run lib:load) fails on a dist or a packed manifest that names a package, and on a package dependency the root does not declare.
  • The package import rule (tests/unit/package-imports.test.ts) reads every module of every package and its build script, and every core file that names packages/, as "Imports" says.
  • The VS Code extension's bundle checks (vscode-extension/scripts/bundle-checks.mjs) refuse package code in the host bundle, and in the webview bundle every package file but the SDK's SQL grammar, row helper, vector and tagged JSON entries.

tests/unit/package-gates.test.ts plants a violation in a throwaway package for the install, Biome, ESLint and knip, and fails when one of them stops seeing it. docs/TOOLCHAIN.md, "Workspace packages (packages/)", records the measurements behind these choices.