33 Commits
Author SHA1 Message Date
The_River 1788d17f0a Merge pull request 'fix: hand npm the release artifact's absolute path, so publishing finds it' (#83) from fix/publish-absolute-artifact-path into main
CI / verify (push) Successful in 1m6s
CI / infrastructure-smoke (push) Successful in 36s
CI / migration-smoke (push) Successful in 1m56s
CI / package-release (push) Successful in 34s
CI / image-build (push) Successful in 11s
CI / deploy-smoke (same-origin) (push) Successful in 49s
CI / deploy-smoke (split) (push) Successful in 1m22s
CI / package-publication (push) Successful in 47s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/83
Reviewed-by: The_River <[email protected]>
2026-10-08 23:22:00 +00:00
ekklesiaandClaude Opus 5.5 1caffc5f26 fix: hand npm the release artifact's absolute path, so publishing finds it
CI / verify (pull_request) Successful in 1m5s
CI / infrastructure-smoke (pull_request) Successful in 37s
CI / migration-smoke (pull_request) Successful in 1m52s
CI / package-release (pull_request) Successful in 34s
CI / image-build (pull_request) Successful in 24s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m30s
CI / package-publication (pull_request) Successful in 49s
The first real 0.2.0 publish failed on its first package with ENOENT:
"Publishing ekklesia-contracts-0.2.0.tgz failed: npm error code ENOENT".

The publish workflow passes a relative release path,
--release "$(find package-train …)", which is
package-train/ekklesia-packages-0.2.0. The tool validated the artifacts
relative to the job's working directory, but ran npm in its own
temporary home (cwd /tmp/ekklesia-publish-XXXXXX) with the same relative
path, package-train/ekklesia-packages-0.2.0/ekklesia-contracts-0.2.0.tgz,
which there names nothing. The disposable-registry suite always passed
an absolute path, so it never saw this.

- loadReleaseTrain resolves the release directory once; every artifact
  path is absolute from validation on, and npm is given only that exact
  file's absolute path (anything else is refused at the npm boundary).
- Just before each upload the file is checked against the validated
  bytes once more; the tool logs the absolute path it publishes, and a
  failure names it with npm's path/syscall lines (npm's temporary home
  masked, the token never shown).
- Regression tests: unit tests with a recording npm (relative nested
  release from another cwd; npm's argv, cwd, and the file's existence; a
  changed artifact refused before npm runs), which fail on the previous
  tool; and a disposable-Gitea test that runs the CLI exactly as the
  workflow does, from the Actions artifact layout, round-tripping all
  nine packages byte for byte.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 17:51:22 -05:00
The_River debb8df3ce Merge pull request 'chore(release): prepare 0.2.0' (#82) from chore/release-0.2.0 into main
CI / verify (push) Successful in 1m6s
CI / infrastructure-smoke (push) Successful in 36s
CI / migration-smoke (push) Successful in 1m55s
CI / package-release (push) Successful in 35s
CI / image-build (push) Successful in 11s
CI / deploy-smoke (same-origin) (push) Successful in 49s
CI / deploy-smoke (split) (push) Successful in 1m22s
CI / package-publication (push) Successful in 41s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/82
Reviewed-by: The_River <[email protected]>
2026-10-08 22:36:19 +00:00
ekklesiaandClaude Opus 5.5 98e59d4ba0 chore(release): prepare 0.2.0
CI / verify (pull_request) Successful in 1m5s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m52s
CI / package-release (pull_request) Successful in 35s
CI / image-build (pull_request) Successful in 31s
CI / deploy-smoke (same-origin) (pull_request) Successful in 45s
CI / deploy-smoke (split) (pull_request) Successful in 1m30s
CI / package-publication (pull_request) Successful in 44s
Every platform workspace package and every public @ekklesia/* package
declares 0.2.0, and the deploy README's image build example names it.
templates/module keeps its own version.

0.2.0, not 0.1.3: before 1.0 a minor version is the breaking one
(docs/development/releases.md, ADR 0054), and since 0.1.2 main has
broken modules, module authors, and operators:
- #64 (ADR 0048): one generic image; installed modules live outside it;
- #66, #72 (ADR 0049, 0050): modules install as Module Package v1, and
  move to the Module Database ABI;
- #71: the manifest v8 cutover; v7 manifests are refused;
- #79 (ADR 0053): the curated SDK drops defineModuleSchema and the
  legacy ModuleDatabase type;
plus #67 (AGPL), #74, #77 (licensing, native targets), and the public
package train (#80, #81). It is also the first package train to publish:
0.1.2 never will be.

Because 0.2.0 is outside ^0.1.0, the same change moves to ^0.2.0:
- the standalone fixture's @ekklesia ranges and its exact module-pack pin;
- the compatibility ranges of the modules built for this release: the
  template, the standalone fixture, and the native proof module;
- the test fixtures that model a module of the current release, or the
  current platform's versions;
- the module-development guide's examples, and the release guide, which
  now names what a minor bump moves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 17:26:13 -05:00
The_River 22404ea2d4 Merge pull request 'feat: publish the exact @ekklesia package train to the npm registry (ADR 0053)' (#81) from feat/package-train-publication into main
CI / verify (push) Successful in 1m1s
CI / infrastructure-smoke (push) Successful in 36s
CI / migration-smoke (push) Successful in 1m53s
CI / package-release (push) Successful in 32s
CI / image-build (push) Successful in 11s
CI / deploy-smoke (same-origin) (push) Successful in 42s
CI / deploy-smoke (split) (push) Successful in 1m22s
CI / package-publication (push) Successful in 42s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/81
Reviewed-by: The_River <[email protected]>
2026-10-08 16:31:57 +00:00
ekklesiaandClaude Opus 5.5 486356a01e docs: ADR 0054, Ekklesia's module-development packages are publicly readable before launch
CI / verify (pull_request) Successful in 1m4s
CI / infrastructure-smoke (pull_request) Successful in 36s
CI / migration-smoke (pull_request) Successful in 1m46s
CI / package-release (pull_request) Successful in 33s
CI / image-build (pull_request) Successful in 22s
CI / deploy-smoke (same-origin) (pull_request) Successful in 48s
CI / deploy-smoke (split) (pull_request) Successful in 1m27s
CI / package-publication (pull_request) Successful in 43s
ADR 0053 was accepted assuming a private package phase before launch. The
project owner has decided otherwise: Ekklesia is not secret, its source is
already public, and only publication must be restricted.

ADR 0054 supersedes ADR 0053 only where it describes that phase as
private or requires authenticated package reads. Packages may be read
anonymously, which is neither a launch nor an API stability promise
beyond pre-1.0 SemVer; publication stays authenticated and restricted;
published versions stay immutable; the River_of_Glory_Church Gitea
namespace is an acceptable host; a public launch remains a separate
decision. Every other ADR 0053 decision is unchanged.

ADR 0053 gets only a cross-reference line. The ADR index, the release and
module-development guides, the README status, and the publish workflow's
comment now point at ADR 0054.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 10:24:17 -05:00
ekklesiaandClaude Opus 5.5 1f30c86d4f fix: hand the proven release train on from a directory the artifact actions upload
CI / verify (pull_request) Successful in 1m4s
CI / infrastructure-smoke (pull_request) Successful in 38s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / package-release (pull_request) Successful in 32s
CI / image-build (pull_request) Successful in 22s
CI / deploy-smoke (same-origin) (pull_request) Successful in 49s
CI / deploy-smoke (split) (pull_request) Successful in 1m39s
CI / package-publication (pull_request) Successful in 59s
The CI package-release gate passed, but the upload found no files: the
artifact actions leave hidden files out, and .package-release starts
with a dot. Keep the release in package-train instead, in both
workflows, and test that no artifact path is hidden.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 09:56:06 -05:00
ekklesiaandClaude Opus 5.5 d3c62e63bf feat: publish the exact @ekklesia package train to the npm registry (ADR 0053)
CI / verify (pull_request) Successful in 1m1s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / package-release (pull_request) Failing after 43s
CI / package-publication (pull_request) Skipped
CI / image-build (pull_request) Successful in 29s
CI / deploy-smoke (split) (pull_request) Canceled after 0s
CI / deploy-smoke (same-origin) (pull_request) Canceled after 38s
Publishes one package release train to the Gitea npm registry under
River_of_Glory_Church, whose packages are publicly readable on purpose:
exactly the .tgz files the package-release gate proved, and nothing else.
Nothing is published by this change.

- scripts/publish-package-train.ts validates the whole local train before
  any request (gate manifest hash, version, revision, unmodified source,
  the nine packages, every artifact's size, SHA-256, integrity,
  SHA256SUMS line, and inner package.json), then publishes in dependency
  order with `npm publish <file.tgz>` under a staging tag. Each package
  is reconciled first (absent: publish; same bytes: accept; other bytes:
  hard stop, version burned), then read back: metadata (name, version,
  integrity, dependency maps, normalized bin, tarball on the registry)
  and the tarball itself, byte for byte, also anonymously. `latest` moves
  only after all nine verify; reruns converge and never delete anything.
  It writes a publication record. The token comes from
  EKKLESIA_PACKAGES_PUBLISH_TOKEN only, through a temporary npm config
  that refers to the variable.
- scripts/test-package-publication.sh proves it against a disposable
  Gitea 1.27.2 with public owners, a publisher team and an outsider:
  anonymous reads, refused unauthorized publishing, byte-identical round
  trips, the registry's own 409, partial-train recovery, the burned
  version hard stop, and dist-tag retry convergence.
- CI: package-release keeps its proven release and hands it on as an
  artifact with its manifest hash; the new package-publication job
  publishes exactly that artifact to the disposable Gitea. Artifact
  actions v3 (node20): v4 refuses any server other than github.com.
- .github/workflows/publish-packages.yml publishes to the real registry
  only by manual dispatch on main, after its own gate run, with the
  secret in the publish step alone.
- docs: the public-read model, the workflow, the record, credentials,
  immutability policy, provider moves, and the first-publication steps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 09:49:27 -05:00
The_River 57df2e15f2 Merge pull request 'feat: the public @ekklesia package release train, built, reproduced, and proven (ADR 0053)' (#80) from feat/public-package-release-train into main
CI / verify (push) Successful in 1m5s
CI / infrastructure-smoke (push) Successful in 37s
CI / migration-smoke (push) Successful in 1m54s
CI / package-release (push) Successful in 32s
CI / image-build (push) Successful in 10s
CI / deploy-smoke (same-origin) (push) Successful in 49s
CI / deploy-smoke (split) (push) Successful in 1m22s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/80
Reviewed-by: The_River <[email protected]>
2026-10-08 13:53:41 +00:00
ekklesiaandClaude Opus 5.5 4f1b1d68c7 fix: keep pnpm's package store out of the release builder's clean-source check
CI / verify (pull_request) Successful in 1m4s
CI / infrastructure-smoke (pull_request) Successful in 37s
CI / migration-smoke (pull_request) Successful in 1m54s
CI / package-release (pull_request) Successful in 32s
CI / image-build (pull_request) Successful in 30s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m32s
The package-release job failed its clean-tree assertion in CI. Reproduced
as root in a container with a bind-mounted checkout, as the Gitea runner
does: after checkout the tree is clean; `pnpm install --frozen-lockfile`
then creates `.pnpm-store/` (17,272 untracked files) at the checkout's
root, because pnpm keeps its store on the node_modules file system and
the checkout is its own mount; `pnpm build` changes nothing. No tracked
file is ever modified.

- `.pnpm-store/` is ignored, like node_modules: a package cache, never
  source. The clean-commit requirement is unchanged for every tracked
  file and every untracked file Git does not ignore.
- The clean-tree failure now lists `git status --short` and
  `git diff --stat`.
- Nothing is built before the clean-source assertion: the gate no longer
  runs a global `pnpm build` first. The builder asserts a clean tree,
  builds, then fails if its build changed the tree, before packing. Core's
  verifier is built after both releases, for the consumer proof only.
- Every secondary offline install (the second worktree, the consumer
  module) uses the workspace install's own store explicitly, since pnpm
  picks a store per file system and those directories are on another.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 08:43:19 -05:00
ekklesiaandClaude Opus 5.5 9debe4e891 feat: the public @ekklesia package release train, built, reproduced, and proven (ADR 0053)
CI / verify (pull_request) Successful in 1m2s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m52s
CI / package-release (pull_request) Failing after 16s
CI / image-build (pull_request) Successful in 29s
CI / deploy-smoke (same-origin) (pull_request) Successful in 44s
CI / deploy-smoke (split) (pull_request) Successful in 1m29s
Produces the exact public package tarballs of a platform release, validates
them, and proves a standalone module consumes those artifacts end to end.
Nothing is published and no credential is configured.

- scripts/package-release.ts (pnpm packages:release) is the canonical
  release builder: from a clean commit it rebuilds the nine public
  packages from clean output, packs each, inspects every tarball, checks
  the release set and coordinated versions, and only then writes
  ekklesia-packages-<version>/ with the tarballs, SHA256SUMS, and a
  provider-neutral manifest (ekklesia-package-train.json: version,
  revision, and each package's file, size, SHA-256, npm integrity).
- Packing uses a pack-only pnpm beforePacking hook (passed with
  --config.pnpmfile, never the workspace's install settings). pnpm inserts
  rewritten workspace: dependencies in async completion order, so two
  checkouts of one commit packed module-pack's package.json with keys in a
  different order; the hook restores the source key order (and the
  inspection enforces it). It also drops devDependencies, which named
  private packages outside the train.
- scripts/test-package-release.sh (pnpm test:package-release, the CI
  package-release gate) builds the train twice, the second time from a
  separate worktree, requires byte-identical release directories, then
  runs the standalone consumer proof on the release: manifest checked,
  offline install from the tarballs only, lockfile integrity equal to the
  manifest's, frozen-lockfile reinstall, no Drizzle, one React, contracts
  only transitive, every @ekklesia package and module-pack at the release
  version, skipLibCheck: false, UI build, pack, and Core verification.
- docs/development/releases.md documents the release order, the train,
  the artifacts, and the reproducibility findings; registry publication
  remains unimplemented.
- ADR 0053 is Accepted: everything it decides that does not need a
  registry is now proven, and registry provisioning is on its own
  Deferred list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 08:02:41 -05:00
The_River 7ea2d7883f Merge pull request 'feat: standalone module-build readiness for the public @ekklesia packages (ADR 0053)' (#79) from feat/standalone-module-build into main
CI / verify (push) Successful in 1m5s
CI / infrastructure-smoke (push) Successful in 36s
CI / migration-smoke (push) Successful in 1m54s
CI / standalone-module (push) Successful in 27s
CI / image-build (push) Successful in 11s
CI / deploy-smoke (same-origin) (push) Successful in 43s
CI / deploy-smoke (split) (push) Successful in 1m21s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/79
Reviewed-by: The_River <[email protected]>
2026-10-08 12:48:07 +00:00
ekklesiaandClaude Opus 5.5 aaa7ebfd84 fix: keep Drizzle out of every published declaration (ADR 0053)
CI / verify (pull_request) Successful in 1m2s
CI / infrastructure-smoke (pull_request) Successful in 37s
CI / migration-smoke (pull_request) Successful in 1m52s
CI / standalone-module (pull_request) Successful in 26s
CI / image-build (pull_request) Successful in 28s
CI / deploy-smoke (same-origin) (pull_request) Successful in 43s
CI / deploy-smoke (split) (pull_request) Successful in 1m30s
@ekklesia/contracts still emitted a type-only import of
drizzle-orm/node-postgres for the legacy ModuleDatabase facade, so a
standalone module type-checked only because skipLibCheck hid it.

- ModuleDatabase, LegacyModuleRuntimeServices and
  AnyModuleRuntimeServices move to core/src/modules/database.ts, beside
  the facade Core builds; the facade itself is unchanged.
- contracts' runtime, route, and services generics no longer name an
  ORM: the database type is a plain parameter defaulting to the ABI v1
  executor, and the legacy definition's database is opaque until Core
  specializes it. Core and apps/api name the legacy types from Core.
- contracts drops its drizzle-orm optional peer and devDependency;
  Drizzle stays public only through @ekklesia/module-database/drizzle.
- The facade's type-level test moves from contracts to Core.
- Regression proof: the standalone fixture type-checks with
  skipLibCheck: false against the packed tarballs, with no drizzle-orm
  installed (the smoke asserts both). Against the previous contracts
  tarball the same check fails with TS2307 on drizzle-orm/node-postgres.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 07:40:43 -05:00
ekklesiaandClaude Opus 5.5 89d5d0f2da feat: standalone module-build readiness for the public @ekklesia packages (ADR 0053)
CI / verify (pull_request) Successful in 1m2s
CI / infrastructure-smoke (pull_request) Successful in 28s
CI / migration-smoke (pull_request) Successful in 1m52s
CI / standalone-module (pull_request) Successful in 26s
CI / image-build (pull_request) Successful in 30s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m42s
Makes the public module-development package set usable from a module
repository outside the monorepo. Nothing is published.

- Curated @ekklesia/module-sdk: an explicit author API, no contracts
  barrel, no identity/authorization internals, no Drizzle and no legacy
  ModuleDatabase type. defineModuleRuntime returns the SDK's own named
  interfaces so a module's emitted declarations never reach into
  @ekklesia/contracts. defineModuleSchema is gone; createModuleTable and
  defineModuleSchemaMetadata live in @ekklesia/module-database.
- Drizzle: no longer a dependency of module-sdk or contracts. Core keeps
  the legacy Drizzle schema validator (moved to core/src/modules) and
  its legacy runtime support; drizzle-orm is an optional peer only.
- React is a peer (plus devDependency) of @ekklesia/ui; the boundary
  checker allows exactly that consumer-selected peer.
- @ekklesia/typescript-config is publishable; module-ui-host is private.
  Every public package carries "ekklesia.distribution":
  "module-development" and no monorepo-root prepack.
- module-pack reads the Node.js range from the module's own engines.node
  and recognizes Ekklesia packages by name plus that marker, so
  registry-installed packages are incorporated, SDK-compatibility
  checked, and never credited as third-party.
- scripts/pack-public-packages.ts (pnpm packages:pack) rebuilds, packs
  and inspects the nine public tarballs; scripts/test-standalone-module.sh
  (pnpm test:standalone-module, new CI job) installs them into a fixture
  module outside the repository and proves it typechecks, builds,
  packages, and verifies.
- Public-package boundary tests and module-development docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-08 07:28:54 -05:00
The_River 9426c83109 Merge pull request 'docs: propose ADR 0053, standalone module builds from Ekklesia packages over the npm registry protocol' (#78) from docs/adr-0053-module-package-distribution into main
CI / verify (push) Successful in 1m6s
CI / infrastructure-smoke (push) Successful in 28s
CI / migration-smoke (push) Successful in 1m54s
CI / image-build (push) Successful in 11s
CI / deploy-smoke (same-origin) (push) Successful in 43s
CI / deploy-smoke (split) (push) Successful in 1m23s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/78
Reviewed-by: The_River <[email protected]>
2026-10-08 02:10:19 +00:00
ekklesiaandClaude Opus 5.5 47e64c6f39 docs: propose ADR 0053, standalone module builds from Ekklesia packages over the npm registry protocol
CI / verify (pull_request) Successful in 1m9s
CI / infrastructure-smoke (pull_request) Successful in 37s
CI / migration-smoke (pull_request) Successful in 1m56s
CI / image-build (pull_request) Successful in 24s
CI / deploy-smoke (same-origin) (pull_request) Successful in 43s
CI / deploy-smoke (split) (pull_request) Successful in 1m38s
Defines the external module-development and package-distribution contract
that ADR 0049 deferred.

- Protocol, not provider: packages are distributed over the standard npm
  registry protocol. Gitea may host the private phase. Host-neutral
  lockfiles and an Ekklesia proxy are not required; a registry move may need
  one configuration change and a lockfile regeneration, while integrity hashes
  keep verifying content.
- Public set:
  - Author API: module-sdk, module-database, module-ui-sdk, design-tokens.
  - Tooling: module-ui-build, module-pack, typescript-config.
  - ui as a pre-1.0 component API.
  - contracts only as a transitive implementation dependency.
  - Core, apps, module-ui-host, and module-template stay unpublished.
- Curated SDK before first publication: no full contracts barrel, no forced
  Drizzle at the SDK root, and no legacy Drizzle database contract in the
  standalone surface. Drizzle support lives in module-database's adapter.
- Dependency rules: React/ReactDOM are peers of the public UI packages
  (bundling per ADR 0023 is unchanged); Drizzle is an optional peer only
  where the adapter needs it; modules put runtime packages in dependencies
  and tooling/config in devDependencies.
- Versioning: one coordinated 0.x release version equal to the platform
  version, with no mixed trains. Ranges go in source and exact artifacts in
  lockfiles; module-pack is pinned exactly; independent versions deferred.
- Standalone packaging: no monorepo checkout. The module declares its own
  Node range (engines.node). The packager recognizes Ekklesia packages by
  identity and metadata, not path. No monorepo-root commands at install time.
- Supply chain: immutable versions, frozen-lockfile integrity, and a
  pre-publication smoke that installs the packed tarballs into a clean
  standalone fixture and proves build, package, and verify. Signing deferred.
- Private phase: no committed secrets; credentials come from the
  environment; verify actual read access before the first publication.

Status Proposed. ADR 0047 (still proposed) must be revised against this. No
code, registry, credential, or Signage changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-07 20:46:32 -05:00
The_River 5803757153 Merge pull request 'feat: native linux-x64-glibc module packages and reviewed license supplements (ADR 0049, ADR 0052)' (#77) from feat/native-targets-license-supplements into main
CI / verify (push) Successful in 1m13s
CI / infrastructure-smoke (push) Successful in 37s
CI / migration-smoke (push) Successful in 1m58s
CI / image-build (push) Successful in 12s
CI / deploy-smoke (same-origin) (push) Successful in 42s
CI / deploy-smoke (split) (push) Successful in 1m23s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/77
Reviewed-by: The_River <[email protected]>
2026-10-08 01:29:37 +00:00
ekklesiaandClaude Opus 5.5 44d385cd7f feat: native linux-x64-glibc module packages and reviewed license supplements (ADR 0049, ADR 0052)
CI / verify (pull_request) Successful in 1m6s
CI / infrastructure-smoke (pull_request) Successful in 27s
CI / migration-smoke (pull_request) Successful in 1m54s
CI / image-build (pull_request) Successful in 29s
CI / deploy-smoke (same-origin) (pull_request) Successful in 43s
CI / deploy-smoke (split) (pull_request) Successful in 1m30s
Implements ADR 0049's deferred native target and ADR 0052's reviewed
license supplements. The proof case is a real module using sharp.
packageFormat stays 1, and `any` is unchanged.

Packager (@ekklesia/module-pack):
- --target linux-x64-glibc. Native or platform-specific packages, found by
  the same generic rule that refuses them in `any`, stay outside the bundle.
- Each native package's production closure is walked through its own
  dependencies, installed optionalDependencies that match the target, and
  required peers. It is copied as real files flat under node_modules/<name>,
  with no links, dev dependencies, declarations, source maps, or other
  platforms' packages. Missing or foreign-platform required dependencies,
  version conflicts, links, foreign machines, and Node.js range conflicts
  fail closed.
- runtime.nodeApi, nodeAbi, and libcVersion are read from the binaries by a
  small ELF reader: the addon's node_api_module_get_api_version_v1 and the
  newest GLIBC_ symbol version needed. No shelling out. A native target with
  no addon is refused.
- ADR 0052 supplements: package-provided material stays primary. An exact
  match on name, version, and ekklesia-content-v1 digest (sorted normalized
  paths with each file's size and SHA-256; no metadata) adds labelled
  material after the package's own. Any mismatch, a declared-licence
  conflict, or a malformed or unreviewed supplement file fails. Missing
  material with no supplement still fails.

Supplement for @img/[email protected]:
- 184 components and 143 unique texts, assembled from the exact upstream
  sources sharp-libvips v1.3.3 builds linux-x64 from: 27 C/C++ libraries,
  glib's gvdb, librsvg's Rust crates (reproduced with cargo tree), the Rust
  standard library at the rustc commit recorded in the binary, plus the
  LGPL-3.0, GPL-3.0, and MPL-2.0 texts. Each source is recorded with its
  SHA-256 in PROVENANCE.md.
- It pins digest ekklesia-content-v1:sha256:50647b0b…, which is identical
  from the installed copy and from the registry tarball.
- LGPL/MPL source-availability determinations stay open, as ADR 0052
  states. Nothing claims they are met.

Verifier (Core):
- linux-x64-glibc is accepted only on a host whose platform, arch, glibc
  family and version, and Node-API version (from Node itself) match.
- Every ELF file must be x86-64; every .node must be an ELF object.
- `any` packages now also refuse node_modules/ and ELF files.
- Contract: native metadata must state nodeApi or nodeAbi, and Linux targets
  libcVersion (ADR 0049).

Proof:
- A checked-in AGPL native fixture packs byte-identically from unrelated
  copies (8.86 MB) and verifies with Core's verifier.
- Extracted elsewhere, it runs a sharp resize and PNG round trip in an
  empty-environment process. Every resolution stays in the package, and
  only the package's addon and libvips plus host system libraries load.

Signage is untouched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-07 20:16:53 -05:00
The_River f53506b3f0 Merge pull request 'docs: propose ADR 0052, reviewed license supplements for redistributed dependencies' (#76) from docs/adr-0052-license-supplements into main
CI / verify (push) Successful in 1m5s
CI / infrastructure-smoke (push) Successful in 36s
CI / migration-smoke (push) Successful in 1m53s
CI / image-build (push) Successful in 12s
CI / deploy-smoke (same-origin) (push) Successful in 41s
CI / deploy-smoke (split) (push) Successful in 1m23s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/76
Reviewed-by: The_River <[email protected]>
2026-10-08 00:47:12 +00:00
ekklesiaandClaude Opus 5.5 951453c735 docs: ADR 0052, what supplement review is, and what the match digest covers
CI / verify (pull_request) Successful in 1m2s
CI / infrastructure-smoke (pull_request) Successful in 36s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / image-build (pull_request) Successful in 23s
CI / deploy-smoke (same-origin) (pull_request) Successful in 43s
CI / deploy-smoke (split) (pull_request) Successful in 1m31s
Two wording clarifications; no decision changes.

- Repository review of a supplement is project and code review of a build
  input. It is not legal review, and not proof that redistribution
  obligations are satisfied.
- The exact-match digest is deterministic over normalized redistributed
  relative paths and file bytes. It excludes host filesystem metadata,
  timestamps, ownership, permissions, and extraction or listing order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-07 19:39:52 -05:00
ekklesiaandClaude Opus 5.5 99f145a80c docs: propose ADR 0052, reviewed license supplements for redistributed dependencies
CI / verify (pull_request) Successful in 1m0s
CI / infrastructure-smoke (pull_request) Successful in 34s
CI / image-build (pull_request) Canceled after 0s
CI / deploy-smoke (same-origin) (pull_request) Canceled after 0s
CI / deploy-smoke (split) (pull_request) Canceled after 0s
CI / migration-smoke (pull_request) Canceled after 1m10s
When a redistributed dependency's own package omits licence material that
redistribution requires, the canonical packager may use a checked-in,
reviewed supplement. The motivating case is
@img/[email protected]: LGPL-3.0-or-later, and its shared
library contains about 29 libraries, but it ships no licence text or
notice for any of them.

ADR 0052 decides:
- package-provided material stays the preferred source and is never
  replaced;
- a supplement matches exact package name, version, and a packager-computed
  content integrity; any mismatch fails closed, with no fallback;
- supplements are immutable, reviewed build inputs with no network access
  during packaging;
- they may carry licence texts, copyright and attribution notices,
  provenance, corresponding-source information, and other accompanying
  material;
- merging is deterministic, and supplement material is labelled;
- a supplement never overrides a dependency's declared licence; a
  disagreement fails packaging;
- the mechanism is generic, with no package-specific code;
- missing material with no exact supplement still fails packaging;
- packageFormat stays 1.

It extends ADR 0049 only in the collection rule that ADR delegated to the
implementation. Legal and source-obligation determinations for LGPL, MPL,
and similar binaries are explicitly deferred: no written offer, URL, or
mirror is asserted to satisfy any licence.

Status Proposed. No implementation, no libvips supplement, and no Signage
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-07 19:37:11 -05:00
The_River 104a5145c8 Merge pull request 'test: give Core's import-safety tests a timeout that holds under full verify load' (#75) from test/import-safety-timeouts into main
CI / verify (push) Successful in 1m3s
CI / infrastructure-smoke (push) Successful in 28s
CI / migration-smoke (push) Successful in 1m48s
CI / image-build (push) Successful in 12s
CI / deploy-smoke (same-origin) (push) Successful in 48s
CI / deploy-smoke (split) (push) Successful in 1m22s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/75
Reviewed-by: The_River <[email protected]>
2026-10-08 00:18:06 +00:00
ekklesiaandClaude Opus 5.5 796ad4f16e test: give Core's import-safety tests a timeout that holds under full verify load
CI / verify (pull_request) Successful in 1m5s
CI / infrastructure-smoke (pull_request) Successful in 37s
CI / migration-smoke (pull_request) Successful in 1m55s
CI / image-build (pull_request) Successful in 24s
CI / deploy-smoke (same-origin) (pull_request) Successful in 49s
CI / deploy-smoke (split) (pull_request) Successful in 1m31s
Four Core tests prove that importing a module has no side effects. Each one
does a cold dynamic import() of a large Core source graph inside its test
body:
- doctor-import
- module-http-import
- cli-bootstrap-platform-owner
- cli-create-initial-owner (its first test)

Vitest transforms and evaluates that graph on demand, so the CPU-bound cost
counts against the default 5 s per-test timeout. Ordinary test files import
at the top level, outside any test timeout. There is no subprocess, shared
resource, or test bug.

Measured on six cores:
- alone: 0.7–1.2 s;
- alongside five other packages' suites, as in a full pnpm verify:
  3.0–5.4 s (doctor-import reached 5,400 ms).

A shared IMPORT_SAFETY_TEST_TIMEOUT_MS of 30 s (core/tests/support/
import-safety.ts) now applies to exactly these four tests. That is about five
times the slowest time measured under load, the same as the repository's
integration-test timeout, and still bounded, so an import that genuinely
hangs fails. Assertions, coverage, the global Vitest timeout, parallelism,
and production code are unchanged; there are no retries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-07 19:08:30 -05:00
The_River b1e3244c1d Merge pull request 'feat: Module Package v1 carries the module's own license (ADR 0051)' (#74) from feat/module-package-v1-licensing into main
CI / verify (push) Successful in 1m6s
CI / infrastructure-smoke (push) Successful in 38s
CI / migration-smoke (push) Successful in 2m7s
CI / image-build (push) Successful in 15s
CI / deploy-smoke (same-origin) (push) Successful in 56s
CI / deploy-smoke (split) (push) Successful in 1m23s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/74
Reviewed-by: The_River <[email protected]>
2026-10-08 00:03:01 +00:00
ekklesiaandClaude Opus 5.5 85fae9e07e feat: Module Package v1 carries the module's own license (ADR 0051)
CI / verify (pull_request) Successful in 58s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / image-build (pull_request) Successful in 30s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m32s
Every Module Package v1 now declares the module's license and carries its
text. packageFormat stays 1; pre-ADR-0051 metadata fails closed.

- Contracts: ekklesia.package.json requires an SPDX `license` expression,
  validated with spdx-expression-parse, with UNLICENSED and non-expressions
  refused. The `files` list must hold exactly one non-empty root LICENSE.
  The package contracts move to the @ekklesia/contracts/module-package
  subpath, so the SPDX parser and its data (spdx-exceptions and
  spdx-license-ids ship no licence files) never reach a module bundle
  through the SDK's re-export of the contracts root.
- Packager: reads the source package.json's string SPDX declaration and
  never invents one. It requires an explicit --license-file (a non-empty
  regular file, no symlink, no parent search, no download) and copies its
  bytes unchanged to LICENSE, listed with size and SHA-256 and covered by
  the archive digest. THIRD_PARTY_NOTICES stays third-party only, and
  bundled Ekklesia code stays in `incorporates`.
- Verifier: rejects missing or invalid license metadata, and a missing,
  unlisted, duplicated, or corrupted LICENSE, through the schema and the
  existing strict inventory.
- Template: packaged as AGPL-3.0-or-later with the repository's canonical
  LICENSE, passed explicitly (Dockerfile, smoke, docs). Packing it twice
  gives byte-identical archives.

Started by Codex; reviewed and completed in Claude Code (empty license-text
refusal, schema non-empty LICENSE, symlink and empty-file tests).

ADR 0051 is Accepted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-07 18:51:03 -05:00
The_River 30f61094e6 Merge pull request 'docs: propose ADR 0051 module package licensing' (#73) from docs/adr-0051-module-package-licensing into main
CI / verify (push) Successful in 1m6s
CI / infrastructure-smoke (push) Successful in 37s
CI / migration-smoke (push) Successful in 1m56s
CI / image-build (push) Successful in 12s
CI / deploy-smoke (same-origin) (push) Successful in 42s
CI / deploy-smoke (split) (push) Successful in 1m22s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/73
Reviewed-by: The_River <[email protected]>
2026-10-07 23:29:19 +00:00
ekklesia 1c7755d320 docs: propose ADR 0051 module package licensing
CI / verify (pull_request) Successful in 1m5s
CI / infrastructure-smoke (pull_request) Successful in 36s
CI / migration-smoke (pull_request) Successful in 1m54s
CI / image-build (pull_request) Successful in 23s
CI / deploy-smoke (same-origin) (pull_request) Successful in 41s
CI / deploy-smoke (split) (pull_request) Successful in 1m29s
2026-10-07 18:21:51 -05:00
The_River 42acdeb9e8 Merge pull request 'feat: transition module packages and template to database ABI v1' (#72) from feat/module-package-abi-v1-transition into main
CI / verify (push) Successful in 59s
CI / infrastructure-smoke (push) Successful in 36s
CI / migration-smoke (push) Successful in 1m53s
CI / image-build (push) Successful in 12s
CI / deploy-smoke (same-origin) (push) Successful in 49s
CI / deploy-smoke (split) (push) Successful in 1m21s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/72
Reviewed-by: The_River <[email protected]>
2026-10-07 23:14:49 +00:00
ekklesia 70854d234c feat: transition module packages to database ABI v1
CI / verify (pull_request) Successful in 1m1s
CI / infrastructure-smoke (pull_request) Successful in 36s
CI / migration-smoke (pull_request) Successful in 1m54s
CI / image-build (pull_request) Successful in 31s
CI / deploy-smoke (same-origin) (pull_request) Successful in 52s
CI / deploy-smoke (split) (pull_request) Successful in 1m32s
2026-10-07 18:00:04 -05:00
The_River 20ad1ae208 Merge pull request 'feat: deliver module database ABI through manifest v8' (#71) from feat/manifest-v8-database-abi into main
CI / verify (push) Successful in 1m4s
CI / infrastructure-smoke (push) Successful in 38s
CI / migration-smoke (push) Successful in 1m47s
CI / image-build (push) Successful in 12s
CI / deploy-smoke (same-origin) (push) Successful in 49s
CI / deploy-smoke (split) (push) Successful in 1m24s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/71
Reviewed-by: The_River <[email protected]>
2026-10-07 22:45:52 +00:00
ekklesia 49b4d4165d feat: deliver module database ABI by manifest
CI / verify (pull_request) Successful in 1m0s
CI / infrastructure-smoke (pull_request) Successful in 36s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / image-build (pull_request) Successful in 23s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m30s
2026-10-07 17:29:32 -05:00
The_River a1cdcb3ad1 Merge pull request 'feat: add module database ABI v1 adapters' (#70) from feat/module-database-abi-adapters into main
CI / verify (push) Successful in 1m4s
CI / infrastructure-smoke (push) Successful in 37s
CI / migration-smoke (push) Successful in 1m49s
CI / image-build (push) Successful in 11s
CI / deploy-smoke (same-origin) (push) Successful in 43s
CI / deploy-smoke (split) (push) Successful in 1m23s
Reviewed-on: https://git.riverofglorymn.org/River_of_Glory_Church/Ekklesia/pulls/70
Reviewed-by: The_River <[email protected]>
2026-10-07 22:00:06 +00:00
ekklesia 859675c3c7 feat: add module database ABI v1 adapters
CI / verify (pull_request) Successful in 58s
CI / infrastructure-smoke (pull_request) Successful in 35s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / image-build (pull_request) Successful in 29s
CI / deploy-smoke (same-origin) (pull_request) Successful in 49s
CI / deploy-smoke (split) (pull_request) Successful in 1m31s
2026-10-07 16:44:28 -05:00
325 changed files with 29985 additions and 791 deletions
+4
View File
@@ -6,3 +6,7 @@
*.gif binary *.gif binary
*.webp binary *.webp binary
*.woff2 binary *.woff2 binary
# Reviewed license supplements are named by the SHA-256 of their exact bytes (ADR 0052), so Git must
# never rewrite their line endings.
packages/module-pack/license-supplements/** -text
+123
View File
@@ -128,6 +128,129 @@ jobs:
if: always() if: always()
run: bash scripts/ci-sweep.sh --job run: bash scripts/ci-sweep.sh --job
package-release:
needs: verify
runs-on: ubuntu-latest
timeout-minutes: 15
# What the gate proved, for the job that consumes its artifact to check it received exactly that.
outputs:
version: ${{ steps.release.outputs.version }}
revision: ${{ steps.release.outputs.revision }}
manifest_sha256: ${{ steps.release.outputs.manifest_sha256 }}
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# `actions/checkout` defaults to leaving the job token in `.git/config`, where any later
# step — including one a pull request added to this file — could read or reuse it. Nothing
# in this workflow pushes, so the credential is never needed after checkout.
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .node-version
- name: Activate pinned pnpm
run: |
corepack enable
corepack prepare [email protected] --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
# ADR 0053's package release gate: build the public package train from this commit, build it
# again from a second checkout and require byte-identical artifacts, then install exactly those
# tarballs (offline, no registry) into a module outside this repository and prove it builds,
# packages, and verifies. Nothing is published and no credential exists here. A future publish
# job must depend on this job and publish only the artifacts it proved.
- name: Build, reproduce, and consume the public package train
run: pnpm test:package-release --keep package-train
- name: Describe the proven release train
id: release
run: |
release="$(find package-train -mindepth 1 -maxdepth 1 -type d)"
manifest="$release/ekklesia-package-train.json"
{
echo "version=$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).version' "$manifest")"
echo "revision=$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).source.revision' "$manifest")"
echo "manifest_sha256=$(sha256sum "$manifest" | cut -d' ' -f1)"
} >>"$GITHUB_OUTPUT"
cat "$manifest"
# The exact release artifacts, for the jobs that consume them, from a directory whose name does
# not start with a dot: the artifact actions leave hidden files out. Version 3 of the artifact
# actions: version 4 refuses any server that is not github.com, which this Gitea is not, while
# Gitea implements the protocol version 3 uses. A consumer checks the files, not the wrapper.
- name: Hand the release train on
uses: actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20
with:
name: package-train
path: package-train/
if-no-files-found: error
retention-days: 7
# The publication tool, given exactly the artifact the package-release job proved, against a
# disposable Gitea 1.27.2 (scripts/test-package-publication.sh). Never the real registry, and no
# credential: the disposable registry's accounts are created and discarded inside the job.
package-publication:
needs: package-release
runs-on: ubuntu-latest
timeout-minutes: 15
env:
# Names this job's stacks, so its final step removes exactly these (scripts/lib/ci-project.sh).
EKKLESIA_CI_JOB_KEY: package-publication
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
# A job the runner killed (cancelled, or past the runner's own time limit) never ran its
# cleanup. Anything a CI job left on this shared daemon more than three hours ago goes first.
- name: Sweep stale CI stacks from the runner
run: bash scripts/ci-sweep.sh --stale
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .node-version
- name: Activate pinned pnpm
run: |
corepack enable
corepack prepare [email protected] --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Receive the release train the gate proved
uses: actions/download-artifact@ad191675b41f6a5b46da9a048cb6893812da158b # v3.1.0-node20
with:
name: package-train
path: package-train/
- name: Check it is exactly that train
env:
EXPECTED_MANIFEST_SHA256: ${{ needs.package-release.outputs.manifest_sha256 }}
run: |
release="$(find package-train -mindepth 1 -maxdepth 1 -type d)"
actual="$(sha256sum "$release/ekklesia-package-train.json" | cut -d' ' -f1)"
if [[ -z "$EXPECTED_MANIFEST_SHA256" || "$actual" != "$EXPECTED_MANIFEST_SHA256" ]]; then
echo "The received release manifest is not the one the package-release job proved." >&2
exit 1
fi
(cd "$release" && sha256sum --check --strict SHA256SUMS)
- name: Publish it to a disposable Gitea, and prove the round trip and recovery
run: bash scripts/test-package-publication.sh --release "$(find package-train -mindepth 1 -maxdepth 1 -type d)"
# Whatever happened above, this job's own stacks do not outlive it.
- name: Remove this job's CI stacks
if: always()
run: bash scripts/ci-sweep.sh --job
image-build: image-build:
needs: verify needs: verify
runs-on: ubuntu-latest runs-on: ubuntu-latest
+133
View File
@@ -0,0 +1,133 @@
name: Publish packages
# Publishes one public @ekklesia/* package train (ADR 0053, docs/development/releases.md) to the
# npm registry: exactly the artifacts this run's package-release gate proves, and nothing else.
#
# Only ever started by hand, on `main`, by someone with write access to this repository: no pull
# request or push can start it. It needs the version-set commit of a release (`version` must equal
# the platform version there), and the repository secret EKKLESIA_PACKAGES_PUBLISH_TOKEN, a token of
# the dedicated publisher account with only the `write:package` scope. Packages are publicly
# readable (ADR 0054); publishing is what this protects.
on:
workflow_dispatch:
inputs:
version:
description: The package train version to publish, equal to the platform version on main.
required: true
type: string
permissions:
contents: read
# Never cancel a publication part way, and never run two at once. A rerun resumes safely.
concurrency:
group: publish-packages
cancel-in-progress: false
env:
# The only registry-specific setting: where the train is published.
EKKLESIA_PACKAGES_REGISTRY: https://git.riverofglorymn.org/api/packages/River_of_Glory_Church/npm/
jobs:
package-release:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 20
outputs:
version: ${{ steps.release.outputs.version }}
revision: ${{ steps.release.outputs.revision }}
manifest_sha256: ${{ steps.release.outputs.manifest_sha256 }}
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .node-version
- name: Activate pinned pnpm
run: |
corepack enable
corepack prepare [email protected] --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
# The same credential-free gate as CI: build, reproduce, and consume the train.
- name: Build, reproduce, and consume the public package train
run: pnpm test:package-release --keep package-train
- name: Describe the proven release train
id: release
run: |
release="$(find package-train -mindepth 1 -maxdepth 1 -type d)"
manifest="$release/ekklesia-package-train.json"
{
echo "version=$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).version' "$manifest")"
echo "revision=$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).source.revision' "$manifest")"
echo "manifest_sha256=$(sha256sum "$manifest" | cut -d' ' -f1)"
} >>"$GITHUB_OUTPUT"
# Artifact actions version 3: version 4 refuses any server that is not github.com. The directory
# name must not start with a dot: the artifact actions leave hidden files out.
- name: Hand the release train on
uses: actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20
with:
name: package-train
path: package-train/
if-no-files-found: error
retention-days: 90
publish:
needs: package-release
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
# Only for the publication tool itself: nothing is built or installed in this job.
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .node-version
- name: Receive the release train the gate proved
uses: actions/download-artifact@ad191675b41f6a5b46da9a048cb6893812da158b # v3.1.0-node20
with:
name: package-train
path: package-train/
# The tool validates the whole train against its manifest, that manifest against the gate's,
# its version against the request, and its revision against this commit, before it sends
# anything; then publishes, verifies every package byte for byte, and moves `latest` last.
- name: Publish the exact release train
env:
EKKLESIA_PACKAGES_PUBLISH_TOKEN: ${{ secrets.EKKLESIA_PACKAGES_PUBLISH_TOKEN }}
TRAIN_VERSION: ${{ inputs.version }}
TRAIN_REVISION: ${{ github.sha }}
MANIFEST_SHA256: ${{ needs.package-release.outputs.manifest_sha256 }}
run: |
node scripts/publish-package-train.ts \
--release "$(find package-train -mindepth 1 -maxdepth 1 -type d)" \
--registry "$EKKLESIA_PACKAGES_REGISTRY" \
--version "$TRAIN_VERSION" \
--revision "$TRAIN_REVISION" \
--manifest-sha256 "$MANIFEST_SHA256" \
--record publication-record.json \
--require-public-read
- name: Keep the publication record
uses: actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20
with:
name: package-train-publication-record
path: publication-record.json
if-no-files-found: error
retention-days: 90
+12
View File
@@ -1,4 +1,8 @@
node_modules/ node_modules/
# pnpm's content-addressed package store. pnpm keeps it beside node_modules on the same file system,
# so when the checkout is its own mount (a CI runner's workspace volume, a bind-mounted container),
# `pnpm install` creates it here, at the checkout's root. A package cache, never source.
.pnpm-store/
.turbo/ .turbo/
coverage/ coverage/
dist/ dist/
@@ -16,3 +20,11 @@ generated/*
core/.identity-schema-reference.ts core/.identity-schema-reference.ts
core/.identity-schema-check-* core/.identity-schema-check-*
# The packager tests copy fixture modules here (packages/module-pack/tests/support/fixture-module.ts).
packages/module-pack/.fixtures/
# `pnpm packages:release` writes package release trains here (scripts/package-release.ts).
.package-release/
# CI keeps the proven release here to hand it on as a workflow artifact (scripts/test-package-release.sh --keep).
/package-train/
+7
View File
@@ -78,6 +78,13 @@ ever disagree:
- `pnpm test:migrations:integration` — live, disposable-PostgreSQL evidence: migration discovery, - `pnpm test:migrations:integration` — live, disposable-PostgreSQL evidence: migration discovery,
planning, and execution, plus the `apps/api` HTTP transport (signup, sign-in, principal planning, and execution, plus the `apps/api` HTTP transport (signup, sign-in, principal
resolution, sign-out). Requires Docker. Run this for any change touching either area. resolution, sign-out). Requires Docker. Run this for any change touching either area.
- `pnpm test:package-release` — builds the public `@ekklesia/*` package train, proves it
reproducible, and proves a standalone module consumes exactly those tarballs. Publishes nothing.
Run it for any change to the public packages or their release tooling.
- `pnpm test:package-publication` — publishes a release train to a disposable Gitea (Docker) and
proves the publication tool. Never the real registry. The real publication is the manual
`Publish packages` workflow only; never run `scripts/publish-package-train.ts` against the real
registry without the user's explicit intent.
- `pnpm doctor` — read-only local readiness report. Never treat it as a substitute for `pnpm - `pnpm doctor` — read-only local readiness report. Never treat it as a substitute for `pnpm
verify` or the integration suite. verify` or the integration suite.
- `pnpm migrations:plan` / `pnpm migrations:apply` — read-only planning vs. mutating execution - `pnpm migrations:plan` / `pnpm migrations:apply` — read-only planning vs. mutating execution
+28 -5
View File
@@ -48,8 +48,31 @@ migration history is retained and reported, and blocks no other migration. A mod
as one **Ekklesia Module Package v1** as one **Ekklesia Module Package v1**
([ADR 0049](docs/architecture/decisions/0049-module-package-v1.md)): a deterministic `.tar.gz` and ([ADR 0049](docs/architecture/decisions/0049-module-package-v1.md)): a deterministic `.tar.gz` and
its SHA-256, produced by the canonical packager (`@ekklesia/module-pack`) with the module's backend its SHA-256, produced by the canonical packager (`@ekklesia/module-pack`) with the module's backend
bundled, and checked by Core's verifier before it is installed. Only the portable `any` target exists bundled, and checked by Core's verifier before it is installed. Two targets exist:
so far. Purge, native-target packages, signing, and any installer or marketplace do not exist yet. - the portable `any` target, for pure-JavaScript modules;
- `linux-x64-glibc`, for modules with a native dependency such as `sharp`. Its native runtime
packages are carried as real files under the package's `node_modules`, and the verifier checks the
host before anything is loaded.
Every package records the module's validated SPDX expression and carries its explicitly
supplied `LICENSE` bytes; dependency material remains separate in `THIRD_PARTY_NOTICES`. ABI-v1
packages may bundle a module-owned Drizzle version without coupling it to Core;
legacy-v8 packages retain their transitional exact-version check. Where a redistributed dependency
omits licence material, the packager may add reviewed licence supplements
([ADR 0052](docs/architecture/decisions/0052-reviewed-license-supplements.md)). Purge, other
operating-system or CPU targets, signing, and any installer or marketplace do not exist yet.
A module can be built in its own repository from Ekklesia's public module-development packages
([ADR 0053](docs/architecture/decisions/0053-standalone-module-development-packages.md)):
a curated `@ekklesia/module-sdk`, `@ekklesia/module-database`, the UI packages, and the build and
packaging tools. They are released as one coordinated train of tarballs with a release manifest,
and CI proves on every run that two builds of a commit are byte-identical and that a module outside
the repository installs, builds, packages, and verifies from those artifacts alone. A manual
workflow, the only way to publish, publishes exactly those artifacts to the npm registry and
verifies every package byte for byte. Anyone may read and install the packages before launch
([ADR 0054](docs/architecture/decisions/0054-public-package-reads-before-launch.md)). The first train
published will be the next platform release
([Releases and the public package train](docs/development/releases.md)).
Phase 4A added Core-owned identity foundations: a Core-owned Better Auth database schema Phase 4A added Core-owned identity foundations: a Core-owned Better Auth database schema
(`ekklesia_core_user`, `ekklesia_core_session`, `ekklesia_core_account`, (`ekklesia_core_user`, `ekklesia_core_session`, `ekklesia_core_account`,
@@ -506,8 +529,8 @@ reported `blocked · configuration_missing · bucket` — never imported, never
from inside its own `start` hook — and its required dependents block behind it through ADR 0028's from inside its own `start` hook — and its required dependents block behind it through ADR 0028's
existing mechanism. Doctor and `pnpm modules:validate` report the same thing while still importing no existing mechanism. Doctor and `pnpm modules:validate` report the same thing while still importing no
module code. That change introduced `manifestVersion: 5` as a hard cutover; the current strict module code. That change introduced `manifestVersion: 5` as a hard cutover; the current strict
manifest is version 7 after ADR 0033 added the optional display declaration and ADR 0041 added manifest is version 8 after ADR 0050 added the optional database ABI declaration. Version 8 is a
browser contributions. hard cutover; a version 7 source module or package must be updated and rebuilt.
**Ekklesia does not store secrets, and does not pretend to.** There is no encryption at rest here and **Ekklesia does not store secrets, and does not pretend to.** There is no encryption at rest here and
no key management, so a `secret` key's value is supplied by the deployment no key management, so a `secret` key's value is supplied by the deployment
@@ -841,7 +864,7 @@ is versioned with no dual acceptance; migrating is one `pnpm build`.
Phase 8 pass 3 lets one module contribute a browser renderer to a capability another module provides Phase 8 pass 3 lets one module contribute a browser renderer to a capability another module provides
([ADR 0041](docs/architecture/decisions/0041-module-browser-contributions.md)) — the browser half of ([ADR 0041](docs/architecture/decisions/0041-module-browser-contributions.md)) — the browser half of
the capability system Core has had since Phase 1. `manifestVersion: 7` declares a namespaced id, its the capability system Core has had since Phase 1. `manifestVersion: 8` declares a namespaced id, its
own version, a target capability, a compatible range, and one artifact, and nothing else: there is no own version, a target capability, a compatible range, and one artifact, and nothing else: there is no
payload schema, slot, ordering, or rendering hint anywhere, so Core cannot learn what any of it payload schema, slot, ordering, or rendering hint anywhere, so Core cannot learn what any of it
means. Publication requires that another eligible module provides the capability inside the declared means. Publication requires that another eligible module provides the capability inside the declared
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@ekklesia/api", "name": "@ekklesia/api",
"version": "0.1.2", "version": "0.2.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"private": true, "private": true,
"type": "module", "type": "module",
+6 -6
View File
@@ -1,6 +1,5 @@
import { import {
isAuthenticatedPrincipal, isAuthenticatedPrincipal,
type ModuleRuntimeServices,
type ModuleSecretSource, type ModuleSecretSource,
type RegisteredModuleHttpRoute, type RegisteredModuleHttpRoute,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
@@ -13,6 +12,7 @@ import type { DashboardStore } from "@ekklesia/core/dashboard";
import type { DeviceStore } from "@ekklesia/core/devices"; import type { DeviceStore } from "@ekklesia/core/devices";
import { type EkklesiaIdentityRuntime, IdentityRuntimeError } from "@ekklesia/core/identity"; import { type EkklesiaIdentityRuntime, IdentityRuntimeError } from "@ekklesia/core/identity";
import type { import type {
AnyModuleRuntimeServices,
DiscoveredModule, DiscoveredModule,
ModuleConfigurationLookup, ModuleConfigurationLookup,
ModuleConfigurationSettings, ModuleConfigurationSettings,
@@ -20,6 +20,7 @@ import type {
ModuleLifecycleSnapshot, ModuleLifecycleSnapshot,
ModuleLifecycleStore, ModuleLifecycleStore,
ModuleRealtimeRegistry, ModuleRealtimeRegistry,
ModuleRuntimeServicesLookup,
ModuleStorageLookup, ModuleStorageLookup,
ModuleUiPublicationRegistry, ModuleUiPublicationRegistry,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
@@ -62,11 +63,10 @@ export interface CreateApiAppOptions {
/** The started runtime's immutable module-owned realtime registry. Required explicitly even when /** The started runtime's immutable module-owned realtime registry. Required explicitly even when
* empty, for the same reason as module routes: application composition never guesses what ran. */ * empty, for the same reason as module routes: application composition never guesses what ran. */
readonly moduleRealtime: ModuleRealtimeRegistry; readonly moduleRealtime: ModuleRealtimeRegistry;
/** The same frozen services object the caller's started module runtime already passed to every /** The same per-module service lookup the caller's started module runtime used for every
* module's `start`/`stop` hooks (`apps/api/src/server.ts`) — reference-identical, never a fresh * module's `start`/`stop` hooks (`apps/api/src/server.ts`) — each handler receives its module's
* object built here, so a module's HTTP handlers and lifecycle hooks share exactly one * reference-identical service object, never a fresh facade or executor built per request. */
* `ModuleDatabase` for the lifetime of this API runtime. */ readonly moduleServices: ModuleRuntimeServicesLookup | AnyModuleRuntimeServices;
readonly moduleServices: ModuleRuntimeServices;
/** The platform's module UI publication policy — always the one Core builds from the exact /** The platform's module UI publication policy — always the one Core builds from the exact
* discovered inventory this runtime started (`createModuleUiPublicationRegistry`, * discovered inventory this runtime started (`createModuleUiPublicationRegistry`,
* `apps/api/src/server.ts`). Required rather than defaulted, for the same reason `moduleRoutes` * `apps/api/src/server.ts`). Required rather than defaulted, for the same reason `moduleRoutes`
+6 -1
View File
@@ -1,4 +1,4 @@
import type { ModuleDatabase } from "@ekklesia/contracts"; import type { ModuleDatabaseExecutor, ModuleId } from "@ekklesia/contracts";
import { import {
type AuthorizationDrizzleDatabase, type AuthorizationDrizzleDatabase,
createAuthorizationDrizzleView, createAuthorizationDrizzleView,
@@ -12,9 +12,11 @@ import { createDeviceDrizzleView, type DeviceDrizzleDatabase } from "@ekklesia/c
import { createIdentityDrizzleView, type IdentityDrizzleDatabase } from "@ekklesia/core/identity"; import { createIdentityDrizzleView, type IdentityDrizzleDatabase } from "@ekklesia/core/identity";
import { import {
createModuleConfigurationView, createModuleConfigurationView,
createModuleDatabaseExecutor,
createModuleDatabaseView, createModuleDatabaseView,
createModuleLifecycleView, createModuleLifecycleView,
type ModuleConfigurationDrizzleDatabase, type ModuleConfigurationDrizzleDatabase,
type ModuleDatabase,
type ModuleLifecycleDrizzleDatabase, type ModuleLifecycleDrizzleDatabase,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
@@ -24,6 +26,8 @@ export interface ApiDatabaseHandle {
readonly dashboard: DashboardDrizzleDatabase; readonly dashboard: DashboardDrizzleDatabase;
readonly identity: IdentityDrizzleDatabase; readonly identity: IdentityDrizzleDatabase;
readonly module: ModuleDatabase; readonly module: ModuleDatabase;
/** Builds one ABI-v1 executor attributed to exactly one module, over this handle's shared pool. */
readonly moduleExecutor: (moduleId: ModuleId) => ModuleDatabaseExecutor;
readonly moduleConfiguration: ModuleConfigurationDrizzleDatabase; readonly moduleConfiguration: ModuleConfigurationDrizzleDatabase;
readonly moduleLifecycle: ModuleLifecycleDrizzleDatabase; readonly moduleLifecycle: ModuleLifecycleDrizzleDatabase;
/** /**
@@ -76,6 +80,7 @@ export function createApiDatabase(
dashboard: createDashboardDrizzleView(pool), dashboard: createDashboardDrizzleView(pool),
identity: createIdentityDrizzleView(pool), identity: createIdentityDrizzleView(pool),
module: createModuleDatabaseView(pool), module: createModuleDatabaseView(pool),
moduleExecutor: (moduleId: ModuleId) => createModuleDatabaseExecutor(pool, { moduleId }),
moduleConfiguration: createModuleConfigurationView(pool), moduleConfiguration: createModuleConfigurationView(pool),
moduleLifecycle: createModuleLifecycleView(pool), moduleLifecycle: createModuleLifecycleView(pool),
ping: async (statementTimeoutMs: number) => { ping: async (statementTimeoutMs: number) => {
+20 -7
View File
@@ -1,14 +1,17 @@
import { import {
EMPTY_MODULE_CONFIGURATION, EMPTY_MODULE_CONFIGURATION,
EMPTY_MODULE_STORAGE, EMPTY_MODULE_STORAGE,
type ModuleDatabaseExecutor,
type ModuleId, type ModuleId,
type ModuleRouteHandlerContext, type ModuleRouteHandlerContext,
type ModuleRuntimeServices,
type RegisteredModuleHttpRoute, type RegisteredModuleHttpRoute,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import type { import type {
AnyModuleRuntimeServices,
ModuleConfigurationLookup, ModuleConfigurationLookup,
ModuleDatabase,
ModuleRealtimeRegistry, ModuleRealtimeRegistry,
ModuleRuntimeServicesLookup,
ModuleStorageLookup, ModuleStorageLookup,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import type { Context, Hono } from "hono"; import type { Context, Hono } from "hono";
@@ -37,14 +40,14 @@ export interface ModuleHttpRoutesOptions extends AuthorizationMiddlewareOptions
* received for this API runtime — never a fresh one built per request, and never touched for a * received for this API runtime — never a fresh one built per request, and never touched for a
* denied, trusted-origin-rejected, or `OPTIONS` request, since a handler is only ever invoked * denied, trusted-origin-rejected, or `OPTIONS` request, since a handler is only ever invoked
* after authorization succeeds. */ * after authorization succeeds. */
readonly services: ModuleRuntimeServices; readonly services: ModuleRuntimeServicesLookup | AnyModuleRuntimeServices;
/** /**
* Per-module frozen configuration snapshots — the exact map the module runtime started from * Per-module frozen configuration snapshots — the exact map the module runtime started from
* (ADR 0029), so a handler and that module's `start`/`stop` hooks receive the identical object * (ADR 0029), so a handler and that module's `start`/`stop` hooks receive the identical object
* rather than two independently resolved values. A module with no entry receives * rather than two independently resolved values. A module with no entry receives
* `EMPTY_MODULE_CONFIGURATION`, so `context.config` is always present. * `EMPTY_MODULE_CONFIGURATION`, so `context.config` is always present.
* *
* Unlike `services`, which is one shared object, this is keyed by module id: a handler can only * Like `services`, this is keyed by module id: a handler can only
* ever reach its own module's configuration, because that is the only entry looked up for it. * ever reach its own module's configuration, because that is the only entry looked up for it.
*/ */
readonly configurations: ModuleConfigurationLookup; readonly configurations: ModuleConfigurationLookup;
@@ -232,6 +235,11 @@ export function mountModuleHttpRoutes(
if (!options.registry.has(route.permission)) { if (!options.registry.has(route.permission)) {
throw new ModuleRouteConfigurationError(); throw new ModuleRouteConfigurationError();
} }
const services =
"get" in options.services ? options.services.get(route.moduleId) : options.services;
if (!services) {
throw new ModuleRouteConfigurationError();
}
const requireRoutePermission = requirePermission(middlewareOptions, route.permission); const requireRoutePermission = requirePermission(middlewareOptions, route.permission);
// The route's own conscious body contract (`route.maxBodyBytes` — 0 means no body accepted at // The route's own conscious body contract (`route.maxBodyBytes` — 0 means no body accepted at
@@ -243,19 +251,24 @@ export function mountModuleHttpRoutes(
const routeBodyLimit = platformBodyLimit(route.maxBodyBytes, route.bodyMode); const routeBodyLimit = platformBodyLimit(route.maxBodyBytes, route.bodyMode);
const path = moduleRoutePath(route.moduleId, route.path); const path = moduleRoutePath(route.moduleId, route.path);
const finalHandler = async (c: Context): Promise<Response> => { const finalHandler = async (c: Context): Promise<Response> => {
const context: ModuleRouteHandlerContext = Object.freeze({ const context = Object.freeze({
config: options.configurations.get(route.moduleId) ?? EMPTY_MODULE_CONFIGURATION, config: options.configurations.get(route.moduleId) ?? EMPTY_MODULE_CONFIGURATION,
moduleId: route.moduleId, moduleId: route.moduleId,
storage: options.storages.get(route.moduleId) ?? EMPTY_MODULE_STORAGE, storage: options.storages.get(route.moduleId) ?? EMPTY_MODULE_STORAGE,
params: Object.freeze({ ...c.req.param() }), params: Object.freeze({ ...c.req.param() }),
principal: getAuthorizedPrincipal(c), principal: getAuthorizedPrincipal(c),
realtime: options.realtime.publisherFor(route.moduleId), realtime: options.realtime.publisherFor(route.moduleId),
services: options.services, services,
}); }) as ModuleRouteHandlerContext<ModuleDatabase | ModuleDatabaseExecutor>;
let response: Response; let response: Response;
try { try {
response = await route.handler(c.req.raw, context); response = await (
route.handler as (
request: Request,
context: ModuleRouteHandlerContext<ModuleDatabase | ModuleDatabaseExecutor>,
) => PromiseLike<Response> | Response
)(c.req.raw, context);
} catch { } catch {
return sanitizedModuleHandlerFailure(c); return sanitizedModuleHandlerFailure(c);
} }
+15 -13
View File
@@ -1,11 +1,7 @@
import type { Socket } from "node:net"; import type { Socket } from "node:net";
import path from "node:path"; import path from "node:path";
import { pathToFileURL } from "node:url"; import { pathToFileURL } from "node:url";
import { import { EMPTY_MODULE_SECRET_SOURCE, type ModuleSecretSource } from "@ekklesia/contracts";
EMPTY_MODULE_SECRET_SOURCE,
type ModuleRuntimeServices,
type ModuleSecretSource,
} from "@ekklesia/contracts";
import { import {
createAuthorizationEvaluator, createAuthorizationEvaluator,
createAuthorizationStore, createAuthorizationStore,
@@ -21,12 +17,14 @@ import {
} from "@ekklesia/core/identity"; } from "@ekklesia/core/identity";
import { createSmtpMailProvider, type MailProvider } from "@ekklesia/core/mail"; import { createSmtpMailProvider, type MailProvider } from "@ekklesia/core/mail";
import { import {
type AnyModuleRuntimeServices,
createModuleConfigurationStore, createModuleConfigurationStore,
createModuleLifecycleStore, createModuleLifecycleStore,
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
type DiscoveredModule, type DiscoveredModule,
type ModuleConfigurationSettings, type ModuleConfigurationSettings,
type ModuleEligibilityResolution, type ModuleEligibilityResolution,
type ModuleRuntimeServicesLookup,
resolveModuleEligibility, resolveModuleEligibility,
type StartedModuleRuntime, type StartedModuleRuntime,
startDiscoveredModuleRuntime, startDiscoveredModuleRuntime,
@@ -393,16 +391,13 @@ function bindServer(
* (`prepareStartupModuleInventory`, `./platform-permissions.js`). * (`prepareStartupModuleInventory`, `./platform-permissions.js`).
* 2. Construct the one shared PostgreSQL pool (identity, authorization, and the module database * 2. Construct the one shared PostgreSQL pool (identity, authorization, and the module database
* facade each get a typed Drizzle view over it — see `./database.js`). * facade each get a typed Drizzle view over it — see `./database.js`).
* 3. Construct the frozen `ModuleRuntimeServices` (currently just `database`) from that same pool, * 3. Construct the Core identity runtime, authorization store, and evaluator from that pool.
* then the Core identity runtime, authorization store, and evaluator.
* 4. Read the stored module enablement configuration and resolve, from that exact same discovered * 4. Read the stored module enablement configuration and resolve, from that exact same discovered
* inventory, which modules are eligible to run (`resolveModuleEligibility`). * inventory, which modules are eligible to run (`resolveModuleEligibility`).
* 5. Start the module runtime from the eligible subset (`startDiscoveredModuleRuntime`) — never * 5. Start the module runtime from the eligible subset (`startDiscoveredModuleRuntime`) — never
* rediscovering modules a second time — passing it the same services object every module's * rediscovering modules a second time — passing the manifest-selected service map.
* `start`/`stop` hook receives.
* 6. Create the Hono application, mounting the started module runtime's published routes, publishing * 6. Create the Hono application, mounting the started module runtime's published routes, publishing
* UI for that same eligible set, and passing the exact same services object to every module HTTP * UI for that same eligible set, and passing the same per-module service map to HTTP handlers.
* handler.
* 7. Bind the Node HTTP server. * 7. Bind the Node HTTP server.
* *
* Discovery and permission composition happen before any pool, Better Auth instance, module * Discovery and permission composition happen before any pool, Better Auth instance, module
@@ -459,12 +454,10 @@ export async function startApi(
const storageProvider = config.storage ? createS3StorageProvider(config.storage) : undefined; const storageProvider = config.storage ? createS3StorageProvider(config.storage) : undefined;
const mailProvider = config.mail ? createSmtpMailProvider(config.mail) : undefined; const mailProvider = config.mail ? createSmtpMailProvider(config.mail) : undefined;
let services: ModuleRuntimeServices;
let runtime: ReturnType<typeof createIdentityRuntime>; let runtime: ReturnType<typeof createIdentityRuntime>;
let authorizationStore: ReturnType<typeof createAuthorizationStore>; let authorizationStore: ReturnType<typeof createAuthorizationStore>;
let deviceStore: ReturnType<typeof createDeviceStore>; let deviceStore: ReturnType<typeof createDeviceStore>;
try { try {
services = Object.freeze({ database: databaseHandle.module });
runtime = createIdentityRuntime({ runtime = createIdentityRuntime({
config: config.identity, config: config.identity,
db: databaseHandle.identity, db: databaseHandle.identity,
@@ -532,6 +525,15 @@ export async function startApi(
throw error; throw error;
} }
const services: ModuleRuntimeServicesLookup = new Map<string, AnyModuleRuntimeServices>(
eligibility.eligibleModules.map((module) => [
module.manifest.id,
module.manifest.database?.abi === 1
? Object.freeze({ database: databaseHandle.moduleExecutor(module.manifest.id) })
: Object.freeze({ database: databaseHandle.module }),
]),
);
// One scoped facade per eligible module, over the exact buckets that module's own manifest // One scoped facade per eligible module, over the exact buckets that module's own manifest
// declares. Built from the eligible set so a blocked module never receives storage at all. // declares. Built from the eligible set so a blocked module never receives storage at all.
const moduleStorages = createModuleStorageLookup( const moduleStorages = createModuleStorageLookup(
+12 -12
View File
@@ -221,9 +221,9 @@ async function applyCoreMigrations(url: string): Promise<void> {
const aggregate = await discoverAllMigrations({ const aggregate = await discoverAllMigrations({
coreMigrationsDirectory, coreMigrationsDirectory,
moduleDiscovery: { moduleDiscovery: {
moduleSdkVersion: "0.1.0", moduleSdkVersion: "0.2.0",
modulesDirectory: emptyModulesDirectory, modulesDirectory: emptyModulesDirectory,
platformVersion: "0.1.0", platformVersion: "0.2.0",
}, },
}); });
// Phase 4A's and Phase 4C pass 1's committed migrations must not have drifted while building // Phase 4A's and Phase 4C pass 1's committed migrations must not have drifted while building
@@ -339,10 +339,10 @@ async function createGatedRouteModule(
writeFile( writeFile(
path.join(moduleDirectory, "ekklesia.module.json"), path.join(moduleDirectory, "ekklesia.module.json"),
JSON.stringify({ JSON.stringify({
compatibility: { moduleSdk: "^0.1.0", platform: "^0.1.0" }, compatibility: { moduleSdk: "^0.2.0", platform: "^0.2.0" },
entrypoints: { server: "./dist/server/index.js" }, entrypoints: { server: "./dist/server/index.js" },
id, id,
manifestVersion: 7, manifestVersion: 8,
name: `${id} module`, name: `${id} module`,
permissions: [{ baseline: "public", description: "Gated drain probe.", id: permissionId }], permissions: [{ baseline: "public", description: "Gated drain probe.", id: permissionId }],
version: "0.1.0", version: "0.1.0",
@@ -386,11 +386,11 @@ async function createFixtureModule(
): Promise<void> { ): Promise<void> {
const moduleDirectory = path.join(modulesDirectory, id); const moduleDirectory = path.join(modulesDirectory, id);
const manifest = { const manifest = {
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
compatibility: { platform: "^0.1.0", moduleSdk: "^0.1.0" }, compatibility: { platform: "^0.2.0", moduleSdk: "^0.2.0" },
permissions: [], permissions: [],
entrypoints: { server: "./dist/server/index.js" }, entrypoints: { server: "./dist/server/index.js" },
...manifestOverrides, ...manifestOverrides,
@@ -521,10 +521,10 @@ async function createUiModule(
writeFile( writeFile(
path.join(moduleDirectory, "ekklesia.module.json"), path.join(moduleDirectory, "ekklesia.module.json"),
JSON.stringify({ JSON.stringify({
compatibility: { moduleSdk: "^0.1.0", platform: "^0.1.0" }, compatibility: { moduleSdk: "^0.2.0", platform: "^0.2.0" },
entrypoints: { server: "./dist/server/index.js", ui: "./dist/ui/index.js" }, entrypoints: { server: "./dist/server/index.js", ui: "./dist/ui/index.js" },
id, id,
manifestVersion: 7, manifestVersion: 8,
name: `${id} module`, name: `${id} module`,
version, version,
}), }),
@@ -2592,9 +2592,9 @@ describe.sequential("live API — installed module permission end-to-end", () =>
const report = await diagnoseEkklesia({ const report = await diagnoseEkklesia({
coreMigrationsDirectory, coreMigrationsDirectory,
moduleDiscovery: { moduleDiscovery: {
moduleSdkVersion: "0.1.0", moduleSdkVersion: "0.2.0",
modulesDirectory, modulesDirectory,
platformVersion: "0.1.0", platformVersion: "0.2.0",
}, },
runtimeRange: ">=0.0.0", runtimeRange: ">=0.0.0",
runtimeVersion: process.versions.node, runtimeVersion: process.versions.node,
@@ -3906,9 +3906,9 @@ describe.sequential("live API — module lifecycle governs what actually runs",
const aggregate = await discoverAllMigrations({ const aggregate = await discoverAllMigrations({
coreMigrationsDirectory, coreMigrationsDirectory,
moduleDiscovery: { moduleDiscovery: {
moduleSdkVersion: "0.1.0", moduleSdkVersion: "0.2.0",
modulesDirectory, modulesDirectory,
platformVersion: "0.1.0", platformVersion: "0.2.0",
}, },
}); });
expect(aggregate.discoveredModules.map((module) => module.manifest.id)).toEqual(["calendar"]); expect(aggregate.discoveredModules.map((module) => module.manifest.id)).toEqual(["calendar"]);
+4 -4
View File
@@ -1,8 +1,6 @@
import { import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type ModuleDatabase,
type ModuleRuntimeServices,
moduleIdSchema, moduleIdSchema,
parseEkklesiaUserId, parseEkklesiaUserId,
parsePermissionId, parsePermissionId,
@@ -20,6 +18,8 @@ import { IdentityRuntimeError } from "@ekklesia/core/identity";
import { import {
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
type ModuleUiPublicationRegistry, type ModuleUiPublicationRegistry,
StagedModuleRealtimeRegistry, StagedModuleRealtimeRegistry,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
@@ -48,9 +48,9 @@ function fakeRuntime(overrides: Partial<EkklesiaIdentityRuntime> = {}): Ekklesia
}; };
} }
/** A small typed fake `ModuleRuntimeServices` — these tests exercise `createApiApp`'s own wiring, /** A small typed fake `LegacyModuleRuntimeServices` — these tests exercise `createApiApp`'s own wiring,
* never real database behavior, so no PostgreSQL is required. */ * never real database behavior, so no PostgreSQL is required. */
function fakeModuleServices(): ModuleRuntimeServices { function fakeModuleServices(): LegacyModuleRuntimeServices {
const database = Object.freeze({ const database = Object.freeze({
delete: vi.fn(), delete: vi.fn(),
execute: vi.fn(), execute: vi.fn(),
+3 -3
View File
@@ -1,9 +1,7 @@
import { createHash } from "node:crypto"; import { createHash } from "node:crypto";
import { import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
type ModuleDatabase,
type ModuleRouteHandler, type ModuleRouteHandler,
type ModuleRuntimeServices,
parsePermissionId, parsePermissionId,
type RegisteredModuleHttpRoute, type RegisteredModuleHttpRoute,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
@@ -16,6 +14,8 @@ import type { EkklesiaIdentityRuntime } from "@ekklesia/core/identity";
import { import {
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
@@ -74,7 +74,7 @@ function fakeStore(): AuthorizationStore {
}; };
} }
function fakeModuleServices(): ModuleRuntimeServices { function fakeModuleServices(): LegacyModuleRuntimeServices {
return Object.freeze({ database: Object.freeze({}) as unknown as ModuleDatabase }); return Object.freeze({ database: Object.freeze({}) as unknown as ModuleDatabase });
} }
+4 -4
View File
@@ -5,8 +5,6 @@ import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type EkklesiaPrincipal, type EkklesiaPrincipal,
type ModuleDatabase,
type ModuleRuntimeServices,
parseEkklesiaUserId, parseEkklesiaUserId,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import { import {
@@ -20,6 +18,8 @@ import {
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
discoverModules, discoverModules,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import type { Hono } from "hono"; import type { Hono } from "hono";
import { afterEach, describe, expect, it, vi } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
@@ -77,7 +77,7 @@ async function createModule(modulesDirectory: string, fixture: ModuleFixture): P
...(fixture.withUi === false ? {} : { ui: "./dist/ui/index.js" }), ...(fixture.withUi === false ? {} : { ui: "./dist/ui/index.js" }),
}, },
id: fixture.id, id: fixture.id,
manifestVersion: 7, manifestVersion: 8,
name: fixture.name, name: fixture.name,
version: "1.0.0", version: "1.0.0",
}), }),
@@ -147,7 +147,7 @@ async function install(options: InstallOptions = {}): Promise<{ app: Hono }> {
moduleRealtime: EMPTY_MODULE_REALTIME_REGISTRY, moduleRealtime: EMPTY_MODULE_REALTIME_REGISTRY,
moduleServices: Object.freeze({ moduleServices: Object.freeze({
database: Object.freeze({}) as unknown as ModuleDatabase, database: Object.freeze({}) as unknown as ModuleDatabase,
}) as ModuleRuntimeServices, }) as LegacyModuleRuntimeServices,
moduleUi: createModuleUiPublicationRegistry(modules), moduleUi: createModuleUiPublicationRegistry(modules),
moduleLifecycle: { moduleLifecycle: {
snapshot: moduleLifecycleSnapshotFor(modules), snapshot: moduleLifecycleSnapshotFor(modules),
+2 -2
View File
@@ -118,13 +118,13 @@ async function createDisplayModuleDirectory(): Promise<string> {
writeFile( writeFile(
path.join(moduleDirectory, "ekklesia.module.json"), path.join(moduleDirectory, "ekklesia.module.json"),
JSON.stringify({ JSON.stringify({
compatibility: { moduleSdk: "^0.1.0", platform: "^0.1.0" }, compatibility: { moduleSdk: "^0.2.0", platform: "^0.2.0" },
entrypoints: { entrypoints: {
display: { artifact: "./dist/ui/display.js", permission: displayPermission }, display: { artifact: "./dist/ui/display.js", permission: displayPermission },
server: "./dist/server/index.js", server: "./dist/server/index.js",
}, },
id: "announcements", id: "announcements",
manifestVersion: 7, manifestVersion: 8,
name: "Announcements fixture", name: "Announcements fixture",
permissions: [ permissions: [
{ {
+3 -3
View File
@@ -1,8 +1,6 @@
import { import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
type ModuleDatabase,
type ModuleRouteHandler, type ModuleRouteHandler,
type ModuleRuntimeServices,
parsePermissionId, parsePermissionId,
type RegisteredModuleHttpRoute, type RegisteredModuleHttpRoute,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
@@ -15,6 +13,8 @@ import type { EkklesiaIdentityRuntime } from "@ekklesia/core/identity";
import { import {
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import { afterEach, describe, expect, it, vi } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
import { createApiApp } from "../src/app.js"; import { createApiApp } from "../src/app.js";
@@ -56,7 +56,7 @@ function fakeStore(): AuthorizationStore {
}; };
} }
function fakeModuleServices(): ModuleRuntimeServices { function fakeModuleServices(): LegacyModuleRuntimeServices {
return Object.freeze({ database: Object.freeze({}) as unknown as ModuleDatabase }); return Object.freeze({ database: Object.freeze({}) as unknown as ModuleDatabase });
} }
+6 -6
View File
@@ -104,11 +104,11 @@ async function createFixtureModule(
): Promise<void> { ): Promise<void> {
const moduleDirectory = path.join(modulesDirectory, id); const moduleDirectory = path.join(modulesDirectory, id);
const manifest = { const manifest = {
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
compatibility: { platform: "^0.1.0", moduleSdk: "^0.1.0" }, compatibility: { platform: "^0.2.0", moduleSdk: "^0.2.0" },
permissions: [], permissions: [],
entrypoints: { server: "./dist/server/index.js" }, entrypoints: { server: "./dist/server/index.js" },
...manifestOverrides, ...manifestOverrides,
@@ -267,10 +267,10 @@ function fakeDiscoveredModule(
): DiscoveredModule { ): DiscoveredModule {
const manifest = parseModuleManifest({ const manifest = parseModuleManifest({
capabilities: [], capabilities: [],
compatibility: { moduleSdk: "^0.1.0", platform: "^0.1.0" }, compatibility: { moduleSdk: "^0.2.0", platform: "^0.2.0" },
entrypoints: { server: "./dist/does-not-exist/index.js" }, entrypoints: { server: "./dist/does-not-exist/index.js" },
id, id,
manifestVersion: 7, manifestVersion: 8,
name: `${id} module`, name: `${id} module`,
permissions, permissions,
version: "0.1.0", version: "0.1.0",
@@ -1435,9 +1435,9 @@ describe("Ekklesia API module runtime startup and shutdown", () => {
const recorder = createEventRecorder(); const recorder = createEventRecorder();
await createWorkingFixtureModule(modulesDirectory, "calendar", recorder, { withRoute: true }); await createWorkingFixtureModule(modulesDirectory, "calendar", recorder, { withRoute: true });
const discovered = await (await import("@ekklesia/core/modules")).discoverModules({ const discovered = await (await import("@ekklesia/core/modules")).discoverModules({
moduleSdkVersion: "0.1.0", moduleSdkVersion: "0.2.0",
modulesDirectory, modulesDirectory,
platformVersion: "0.1.0", platformVersion: "0.2.0",
}); });
mockPoolAndAuth(); mockPoolAndAuth();
mockSuccessfulServe(); mockSuccessfulServe();
@@ -6,8 +6,6 @@ import {
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type EkklesiaPrincipal, type EkklesiaPrincipal,
type ModuleConfigurationDeclarationInput, type ModuleConfigurationDeclarationInput,
type ModuleDatabase,
type ModuleRuntimeServices,
parseEkklesiaUserId, parseEkklesiaUserId,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import { import {
@@ -22,10 +20,12 @@ import {
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
type DiscoveredModule, type DiscoveredModule,
discoverModules, discoverModules,
type LegacyModuleRuntimeServices,
type ModuleConfigurationRecord, type ModuleConfigurationRecord,
type ModuleConfigurationStore, type ModuleConfigurationStore,
ModuleConfigurationStoreError, ModuleConfigurationStoreError,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type ModuleDatabase,
resolveModuleEligibility, resolveModuleEligibility,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import type { Hono } from "hono"; import type { Hono } from "hono";
@@ -108,7 +108,7 @@ async function createModule(modulesDirectory: string, fixture: ModuleFixture): P
configuration: fixture.configuration ?? [], configuration: fixture.configuration ?? [],
entrypoints: { server: "./dist/server/index.js" }, entrypoints: { server: "./dist/server/index.js" },
id: fixture.id, id: fixture.id,
manifestVersion: 7, manifestVersion: 8,
name: `${fixture.id} module`, name: `${fixture.id} module`,
version: "1.0.0", version: "1.0.0",
}), }),
@@ -213,7 +213,7 @@ async function install(options: InstallOptions = {}): Promise<Installation> {
moduleRealtime: EMPTY_MODULE_REALTIME_REGISTRY, moduleRealtime: EMPTY_MODULE_REALTIME_REGISTRY,
moduleServices: Object.freeze({ moduleServices: Object.freeze({
database: Object.freeze({}) as unknown as ModuleDatabase, database: Object.freeze({}) as unknown as ModuleDatabase,
}) as ModuleRuntimeServices, }) as LegacyModuleRuntimeServices,
moduleUi: createModuleUiPublicationRegistry(eligibility.eligibleModules), moduleUi: createModuleUiPublicationRegistry(eligibility.eligibleModules),
runtime, runtime,
trustedOrigins: [trustedOrigin], trustedOrigins: [trustedOrigin],
+10 -4
View File
@@ -8,6 +8,7 @@ import {
createPostgresMigrationDatabase, createPostgresMigrationDatabase,
discoverAllMigrations, discoverAllMigrations,
} from "@ekklesia/core/migrations"; } from "@ekklesia/core/migrations";
import { moduleDatabaseExecutorModuleId } from "@ekklesia/core/modules";
import { Client, type QueryResultRow } from "pg"; import { Client, type QueryResultRow } from "pg";
import { afterAll, describe, expect, it } from "vitest"; import { afterAll, describe, expect, it } from "vitest";
import { createApiRuntimeConfig } from "../src/config.js"; import { createApiRuntimeConfig } from "../src/config.js";
@@ -211,9 +212,9 @@ async function applyCoreMigrations(url: string): Promise<void> {
const aggregate = await discoverAllMigrations({ const aggregate = await discoverAllMigrations({
coreMigrationsDirectory, coreMigrationsDirectory,
moduleDiscovery: { moduleDiscovery: {
moduleSdkVersion: "0.1.0", moduleSdkVersion: "0.2.0",
modulesDirectory: emptyModulesDirectory, modulesDirectory: emptyModulesDirectory,
platformVersion: "0.1.0", platformVersion: "0.2.0",
}, },
}); });
expect(aggregate.migrations.map((entry) => entry.identity)).toEqual([ expect(aggregate.migrations.map((entry) => entry.identity)).toEqual([
@@ -240,9 +241,9 @@ async function applyMigrationsWithModule(url: string): Promise<void> {
const aggregate = await discoverAllMigrations({ const aggregate = await discoverAllMigrations({
coreMigrationsDirectory, coreMigrationsDirectory,
moduleDiscovery: { moduleDiscovery: {
moduleSdkVersion: "0.1.0", moduleSdkVersion: "0.2.0",
modulesDirectory: fixtureModulesDirectory, modulesDirectory: fixtureModulesDirectory,
platformVersion: "0.1.0", platformVersion: "0.2.0",
}, },
}); });
// Core migrations aggregate first, exactly once each, and always before any module migration. // Core migrations aggregate first, exactly once each, and always before any module migration.
@@ -441,6 +442,11 @@ describe.sequential("live API — module database explicit migration ownership",
const handle = createApiDatabase(database.url); const handle = createApiDatabase(database.url);
expect(handle.module).toBeDefined(); expect(handle.module).toBeDefined();
const alpha = handle.moduleExecutor("alpha");
const beta = handle.moduleExecutor("beta");
expect(alpha).not.toBe(beta);
expect(moduleDatabaseExecutorModuleId(alpha)).toBe("alpha");
expect(moduleDatabaseExecutorModuleId(beta)).toBe("beta");
await handle.close(); await handle.close();
expect(await tableExists(database.url)).toBe(false); expect(await tableExists(database.url)).toBe(false);
+4 -4
View File
@@ -5,8 +5,6 @@ import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type EkklesiaPrincipal, type EkklesiaPrincipal,
type ModuleDatabase,
type ModuleRuntimeServices,
parseEkklesiaUserId, parseEkklesiaUserId,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import { import {
@@ -21,6 +19,8 @@ import {
type DiscoveredModule, type DiscoveredModule,
discoverModules, discoverModules,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import type { Hono } from "hono"; import type { Hono } from "hono";
import { afterEach, describe, expect, it, vi } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
@@ -105,7 +105,7 @@ async function createModule(modulesDirectory: string, fixture: ModuleFixture = {
: {}), : {}),
}, },
id, id,
manifestVersion: 7, manifestVersion: 8,
name: `${id} module`, name: `${id} module`,
permissions: fixture.display permissions: fixture.display
? [ ? [
@@ -155,7 +155,7 @@ interface Installation {
readonly modules: readonly DiscoveredModule[]; readonly modules: readonly DiscoveredModule[];
} }
function fakeServices(): ModuleRuntimeServices { function fakeServices(): LegacyModuleRuntimeServices {
return Object.freeze({ database: Object.freeze({}) as unknown as ModuleDatabase }); return Object.freeze({ database: Object.freeze({}) as unknown as ModuleDatabase });
} }
+46 -15
View File
@@ -1,13 +1,11 @@
import { import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type ModuleDatabase,
type ModuleRouteHandler, type ModuleRouteHandler,
type ModuleRouteHandlerContext, type ModuleRouteHandlerContext,
type ModuleRuntimeServices,
moduleRoutesOverlap, moduleRoutesOverlap,
parsePermissionId,
type PermissionId, type PermissionId,
parsePermissionId,
type RegisteredModuleHttpRoute, type RegisteredModuleHttpRoute,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import { import {
@@ -20,20 +18,23 @@ import type { EkklesiaIdentityRuntime } from "@ekklesia/core/identity";
import { import {
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
type ModuleRuntimeServicesLookup,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
import { createInMemoryDashboardStore } from "./support/in-memory-dashboard-store.js";
import { testDashboardHostAssets } from "./support/dashboard-host-assets.js";
import { readyHealth } from "./support/ready-health.js";
import { createApiApp } from "../src/app.js"; import { createApiApp } from "../src/app.js";
import { import {
canonicalizeVaryHeader, canonicalizeVaryHeader,
mergedVaryHeader,
ModuleRouteConfigurationError, ModuleRouteConfigurationError,
mergedVaryHeader,
} from "../src/module-http-routes.js"; } from "../src/module-http-routes.js";
import { emptyModuleLifecycle } from "./support/in-memory-module-lifecycle.js"; import { testDashboardHostAssets } from "./support/dashboard-host-assets.js";
import { createInMemoryDashboardStore } from "./support/in-memory-dashboard-store.js";
import { emptyModuleConfiguration } from "./support/in-memory-module-configuration.js"; import { emptyModuleConfiguration } from "./support/in-memory-module-configuration.js";
import { emptyModuleLifecycle } from "./support/in-memory-module-lifecycle.js";
import { emptyModuleStorage } from "./support/in-memory-module-storage.js"; import { emptyModuleStorage } from "./support/in-memory-module-storage.js";
import { readyHealth } from "./support/ready-health.js";
const trustedOrigin = "https://dashboard.example.test"; const trustedOrigin = "https://dashboard.example.test";
const untrustedOrigin = "https://evil.example.test"; const untrustedOrigin = "https://evil.example.test";
@@ -73,11 +74,11 @@ function moduleRoute(
return Object.freeze({ bodyMode: "buffered", maxBodyBytes: 1024, ...fields }); return Object.freeze({ bodyMode: "buffered", maxBodyBytes: 1024, ...fields });
} }
/** A small typed fake `ModuleRuntimeServices` — these tests exercise route mounting, /** A small typed fake `LegacyModuleRuntimeServices` — these tests exercise route mounting,
* authorization, and response sanitization, never real database behavior, so no PostgreSQL is * authorization, and response sanitization, never real database behavior, so no PostgreSQL is
* required. Each `database` method stays a distinct spy so a test can assert none of them were * required. Each `database` method stays a distinct spy so a test can assert none of them were
* ever called (denied, trusted-origin-rejected, and `OPTIONS` requests never reach a handler). */ * ever called (denied, trusted-origin-rejected, and `OPTIONS` requests never reach a handler). */
function fakeModuleServices(): ModuleRuntimeServices { function fakeModuleServices(): LegacyModuleRuntimeServices {
const database = Object.freeze({ const database = Object.freeze({
delete: vi.fn(), delete: vi.fn(),
execute: vi.fn(), execute: vi.fn(),
@@ -91,7 +92,7 @@ function fakeModuleServices(): ModuleRuntimeServices {
return Object.freeze({ database }); return Object.freeze({ database });
} }
function expectDatabaseFakeUntouched(services: ModuleRuntimeServices): void { function expectDatabaseFakeUntouched(services: LegacyModuleRuntimeServices): void {
expect(vi.mocked(services.database.select)).not.toHaveBeenCalled(); expect(vi.mocked(services.database.select)).not.toHaveBeenCalled();
expect(vi.mocked(services.database.selectDistinct)).not.toHaveBeenCalled(); expect(vi.mocked(services.database.selectDistinct)).not.toHaveBeenCalled();
expect(vi.mocked(services.database.selectDistinctOn)).not.toHaveBeenCalled(); expect(vi.mocked(services.database.selectDistinctOn)).not.toHaveBeenCalled();
@@ -107,7 +108,7 @@ function buildModuleApp(options: {
readonly registry: PermissionRegistry; readonly registry: PermissionRegistry;
readonly routes: readonly RegisteredModuleHttpRoute[]; readonly routes: readonly RegisteredModuleHttpRoute[];
readonly runtime?: EkklesiaIdentityRuntime; readonly runtime?: EkklesiaIdentityRuntime;
readonly services?: ModuleRuntimeServices; readonly services?: LegacyModuleRuntimeServices | ModuleRuntimeServicesLookup;
readonly trustedOrigins?: readonly string[]; readonly trustedOrigins?: readonly string[];
}) { }) {
const evaluator = options.evaluator ?? { const evaluator = options.evaluator ?? {
@@ -145,6 +146,36 @@ function permissionRegistry(
} }
describe("module HTTP route mounting", () => { describe("module HTTP route mounting", () => {
it("selects the owning module's stable service entry for its handler", async () => {
const calendar = fakeModuleServices();
const people = fakeModuleServices();
const services: ModuleRuntimeServicesLookup = new Map([
["calendar", calendar],
["people", people],
]);
let received: unknown;
const { app } = buildModuleApp({
registry: permissionRegistry([{ id: readPermission, baseline: "public" }]),
routes: [
moduleRoute({
handler: (_request, context) => {
received = context.services;
return Response.json({ ok: true });
},
method: "GET",
moduleId: "calendar",
path: "/services",
permission: readPermission,
}),
],
services,
});
expect((await app.request("/api/v1/modules/calendar/services")).status).toBe(200);
expect(received).toBe(calendar);
expect(received).not.toBe(people);
});
it('mounts a "/" route at exactly the module root, never with an added trailing slash', async () => { it('mounts a "/" route at exactly the module root, never with an added trailing slash', async () => {
const handler = vi.fn<ModuleRouteHandler>(async () => new Response("root", { status: 200 })); const handler = vi.fn<ModuleRouteHandler>(async () => new Response("root", { status: 200 }));
const { app } = buildModuleApp({ const { app } = buildModuleApp({
@@ -508,7 +539,7 @@ describe("module route authorization", () => {
expect(response.status).toBe(403); expect(response.status).toBe(403);
expect(await response.json()).toEqual({ code: "AUTHORIZATION_DENIED" }); expect(await response.json()).toEqual({ code: "AUTHORIZATION_DENIED" });
expect(handler).not.toHaveBeenCalled(); expect(handler).not.toHaveBeenCalled();
expectDatabaseFakeUntouched(services); expectDatabaseFakeUntouched(services as LegacyModuleRuntimeServices);
}); });
it("does not invoke the handler when principal resolution fails", async () => { it("does not invoke the handler when principal resolution fails", async () => {
@@ -637,7 +668,7 @@ describe("module route trusted-origin enforcement", () => {
} }
expect(handler).not.toHaveBeenCalled(); expect(handler).not.toHaveBeenCalled();
expect(evaluator.authorize).not.toHaveBeenCalled(); expect(evaluator.authorize).not.toHaveBeenCalled();
expectDatabaseFakeUntouched(services); expectDatabaseFakeUntouched(services as LegacyModuleRuntimeServices);
}); });
it("allows a trusted-origin state-changing request through to the handler", async () => { it("allows a trusted-origin state-changing request through to the handler", async () => {
@@ -766,7 +797,7 @@ describe("module route CORS", () => {
expect(handler).not.toHaveBeenCalled(); expect(handler).not.toHaveBeenCalled();
expect(evaluator.authorize).not.toHaveBeenCalled(); expect(evaluator.authorize).not.toHaveBeenCalled();
expectDatabaseFakeUntouched(services); expectDatabaseFakeUntouched(services as LegacyModuleRuntimeServices);
}); });
it("never reflects an untrusted origin for a module route", async () => { it("never reflects an untrusted origin for a module route", async () => {
@@ -5,8 +5,6 @@ import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type EkklesiaPrincipal, type EkklesiaPrincipal,
type ModuleDatabase,
type ModuleRuntimeServices,
parseEkklesiaUserId, parseEkklesiaUserId,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import { import {
@@ -20,6 +18,8 @@ import {
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
type DiscoveredModule, type DiscoveredModule,
discoverModules, discoverModules,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
type ModuleLifecycleStore, type ModuleLifecycleStore,
ModuleLifecycleStoreError, ModuleLifecycleStoreError,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
@@ -79,7 +79,7 @@ async function createModule(modulesDirectory: string, fixture: ModuleFixture): P
...(fixture.dependencies ? { dependencies: fixture.dependencies } : {}), ...(fixture.dependencies ? { dependencies: fixture.dependencies } : {}),
entrypoints: { server: "./dist/server/index.js", ui: "./dist/ui/index.js" }, entrypoints: { server: "./dist/server/index.js", ui: "./dist/ui/index.js" },
id: fixture.id, id: fixture.id,
manifestVersion: 7, manifestVersion: 8,
name: `${fixture.id} module`, name: `${fixture.id} module`,
version: "1.0.0", version: "1.0.0",
}), }),
@@ -189,7 +189,7 @@ async function install(options: InstallOptions = {}): Promise<Installation> {
moduleRealtime: EMPTY_MODULE_REALTIME_REGISTRY, moduleRealtime: EMPTY_MODULE_REALTIME_REGISTRY,
moduleServices: Object.freeze({ moduleServices: Object.freeze({
database: Object.freeze({}) as unknown as ModuleDatabase, database: Object.freeze({}) as unknown as ModuleDatabase,
}) as ModuleRuntimeServices, }) as LegacyModuleRuntimeServices,
moduleUi: createModuleUiPublicationRegistry(eligibility.eligibleModules), moduleUi: createModuleUiPublicationRegistry(eligibility.eligibleModules),
runtime, runtime,
trustedOrigins: [trustedOrigin], trustedOrigins: [trustedOrigin],
+4 -4
View File
@@ -4,9 +4,7 @@ import path from "node:path";
import { import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type ModuleDatabase,
type ModuleRealtimePublisher, type ModuleRealtimePublisher,
type ModuleRuntimeServices,
parseEkklesiaUserId, parseEkklesiaUserId,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import { import {
@@ -18,6 +16,8 @@ import type { EkklesiaIdentityRuntime } from "@ekklesia/core/identity";
import { import {
composePlatformPermissionRegistry, composePlatformPermissionRegistry,
discoverModules, discoverModules,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
type ModuleRealtimeRegistry, type ModuleRealtimeRegistry,
type ModuleRealtimeSubscription, type ModuleRealtimeSubscription,
startDiscoveredModuleRuntime, startDiscoveredModuleRuntime,
@@ -188,7 +188,7 @@ async function createFixtureModule(control: FixtureControl): Promise<{
compatibility: { moduleSdk: "^0.1.0", platform: "^0.1.0" }, compatibility: { moduleSdk: "^0.1.0", platform: "^0.1.0" },
entrypoints: { server: "./dist/server/index.js" }, entrypoints: { server: "./dist/server/index.js" },
id: "announcements", id: "announcements",
manifestVersion: 7, manifestVersion: 8,
name: "Announcements fixture", name: "Announcements fixture",
permissions: [ permissions: [
{ {
@@ -226,7 +226,7 @@ async function createFixtureModule(control: FixtureControl): Promise<{
return { directory, symbol }; return { directory, symbol };
} }
function services(): ModuleRuntimeServices { function services(): LegacyModuleRuntimeServices {
return Object.freeze({ database: Object.freeze({}) as ModuleDatabase }); return Object.freeze({ database: Object.freeze({}) as ModuleDatabase });
} }
+4 -4
View File
@@ -5,8 +5,6 @@ import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type EkklesiaPrincipal, type EkklesiaPrincipal,
type ModuleDatabase,
type ModuleRuntimeServices,
parseEkklesiaUserId, parseEkklesiaUserId,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import { import {
@@ -18,6 +16,8 @@ import {
composePlatformPermissionRegistry, composePlatformPermissionRegistry,
createModuleUiPublicationRegistry, createModuleUiPublicationRegistry,
discoverModules, discoverModules,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
startDiscoveredModuleRuntime, startDiscoveredModuleRuntime,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import { import {
@@ -129,7 +129,7 @@ async function createFixtureModule(
: {}), : {}),
}, },
id, id,
manifestVersion: 7, manifestVersion: 8,
name, name,
permissions: [ permissions: [
{ {
@@ -241,7 +241,7 @@ async function startHarness(options: HarnessOptions = {}): Promise<Harness> {
modulesDirectory, modulesDirectory,
platformVersion: "0.1.0", platformVersion: "0.1.0",
}); });
const services: ModuleRuntimeServices = Object.freeze({ const services: LegacyModuleRuntimeServices = Object.freeze({
database: Object.freeze({}) as unknown as ModuleDatabase, database: Object.freeze({}) as unknown as ModuleDatabase,
}); });
// The module's real runtime: its server entrypoint is imported, registered, and started, and the // The module's real runtime: its server entrypoint is imported, registered, and started, and the
+4 -4
View File
@@ -5,8 +5,6 @@ import {
ANONYMOUS_PRINCIPAL, ANONYMOUS_PRINCIPAL,
createAuthenticatedPrincipal, createAuthenticatedPrincipal,
type EkklesiaPrincipal, type EkklesiaPrincipal,
type ModuleDatabase,
type ModuleRuntimeServices,
parseEkklesiaUserId, parseEkklesiaUserId,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import { import {
@@ -21,6 +19,8 @@ import {
type DiscoveredModule, type DiscoveredModule,
discoverModules, discoverModules,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import type { Hono } from "hono"; import type { Hono } from "hono";
import { afterEach, describe, expect, it, vi } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
@@ -99,7 +99,7 @@ async function createModule(modulesDirectory: string, fixture: ModuleFixture): P
version: "1.0.0", version: "1.0.0",
})), })),
id: fixture.id, id: fixture.id,
manifestVersion: 7, manifestVersion: 8,
name: `${fixture.id} module`, name: `${fixture.id} module`,
permissions: (fixture.permissions ?? []).map((permission) => ({ permissions: (fixture.permissions ?? []).map((permission) => ({
...permission, ...permission,
@@ -192,7 +192,7 @@ async function install(options: InstallOptions): Promise<Installation> {
revokeGrant: vi.fn(), revokeGrant: vi.fn(),
revokePlatformOwner: vi.fn(), revokePlatformOwner: vi.fn(),
} as unknown as AuthorizationStore; } as unknown as AuthorizationStore;
const services: ModuleRuntimeServices = Object.freeze({ const services: LegacyModuleRuntimeServices = Object.freeze({
database: Object.freeze({}) as unknown as ModuleDatabase, database: Object.freeze({}) as unknown as ModuleDatabase,
}); });
const permissionRegistry = composePlatformPermissionRegistry(modules); const permissionRegistry = composePlatformPermissionRegistry(modules);
+5 -7
View File
@@ -1,11 +1,7 @@
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
import { import { ANONYMOUS_PRINCIPAL } from "@ekklesia/contracts";
ANONYMOUS_PRINCIPAL,
type ModuleDatabase,
type ModuleRuntimeServices,
} from "@ekklesia/contracts";
import type { AuthorizationEvaluator, AuthorizationStore } from "@ekklesia/core/authorization"; import type { AuthorizationEvaluator, AuthorizationStore } from "@ekklesia/core/authorization";
import type { EkklesiaIdentityRuntime } from "@ekklesia/core/identity"; import type { EkklesiaIdentityRuntime } from "@ekklesia/core/identity";
import { import {
@@ -14,6 +10,8 @@ import {
type DiscoveredModule, type DiscoveredModule,
discoverModules, discoverModules,
EMPTY_MODULE_REALTIME_REGISTRY, EMPTY_MODULE_REALTIME_REGISTRY,
type LegacyModuleRuntimeServices,
type ModuleDatabase,
} from "@ekklesia/core/modules"; } from "@ekklesia/core/modules";
import { loadModuleUi } from "@ekklesia/module-ui-host"; import { loadModuleUi } from "@ekklesia/module-ui-host";
import { MODULE_UI_ABI_VERSION, NO_MODULE_UI_CONTRIBUTIONS } from "@ekklesia/module-ui-sdk"; import { MODULE_UI_ABI_VERSION, NO_MODULE_UI_CONTRIBUTIONS } from "@ekklesia/module-ui-sdk";
@@ -139,7 +137,7 @@ async function createModule(modulesDirectory: string, fixture: ModuleFixture): P
version: "1.0.0", version: "1.0.0",
})), })),
id: fixture.id, id: fixture.id,
manifestVersion: 7, manifestVersion: 8,
name: `${fixture.id} module`, name: `${fixture.id} module`,
permissions: permissions:
fixture.display === undefined fixture.display === undefined
@@ -215,7 +213,7 @@ async function install(
: modules.filter((module) => publicationModuleIds.includes(module.manifest.id)); : modules.filter((module) => publicationModuleIds.includes(module.manifest.id));
const database = Object.freeze({}) as unknown as ModuleDatabase; const database = Object.freeze({}) as unknown as ModuleDatabase;
const services: ModuleRuntimeServices = Object.freeze({ database }); const services: LegacyModuleRuntimeServices = Object.freeze({ database });
const runtime: EkklesiaIdentityRuntime = { const runtime: EkklesiaIdentityRuntime = {
handleAuthRequest: vi.fn().mockResolvedValue(new Response(null, { status: 200 })), handleAuthRequest: vi.fn().mockResolvedValue(new Response(null, { status: 200 })),
// Anonymous, and every authorization decision denied: whatever this route does, it does it // Anonymous, and every authorization decision denied: whatever this route does, it does it
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@ekklesia/core", "name": "@ekklesia/core",
"version": "0.1.2", "version": "0.2.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"private": true, "private": true,
"type": "module", "type": "module",
+49 -2
View File
@@ -1,7 +1,54 @@
import type { ModuleDatabase } from "@ekklesia/contracts"; import type { ModuleDatabaseAbiRuntimeServices, ModuleRuntimeServices } from "@ekklesia/contracts";
import { drizzle } from "drizzle-orm/node-postgres"; import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres";
import type { Pool } from "pg"; import type { Pool } from "pg";
/**
* A trusted backend module's typed Drizzle query surface — the same query-building methods a
* platform-owned Drizzle instance exposes, restricted to exactly the operations a module needs to
* read and write its own tables. Derived with `Pick` from the real `drizzle-orm/node-postgres`
* database type rather than hand-declared, so every method keeps Drizzle's own table-aware
* argument and result inference exactly as-is — a module calling `database.select().from(table)`
* or `database.insert(table).values(...)` gets the identical typed builder a direct Drizzle caller
* would, with no `any`/`unknown` erasure anywhere in the chain.
*
* Deliberately excludes everything `NodePgDatabase` or the `drizzle(...)` factory otherwise
* exposes: `$client` (the raw `pg` client/pool), `_` (internal session/dialect/schema state),
* `query` (a relational-query builder tied to one schema, which would have to span every
* installed module's tables to exist here at all), `$cache`, `$count`, `$with`, `with`, and
* `refreshMaterializedView`. There is no connection string, pool, session, or dialect object
* reachable through this type. Carries no schema generic — a module brings its own Drizzle table
* objects to each call, so there is no global relational schema spanning every installed module for
* this type to leak.
*
* Core's own, private type (ADR 0053): it moved here from `@ekklesia/contracts` so no published
* package references Drizzle. New modules use the Module Database ABI v1 instead (ADR 0050), and
* the Module SDK never exposes this facade's type.
*
* This is an integration boundary, not a security sandbox: modules are trusted, compiled backend
* plugins that already run arbitrary code in this process, exactly like every other lifecycle hook
* and HTTP handler they define. `ModuleDatabase` exists to keep a module's code Drizzle-typed and
* decoupled from how the platform physically connects to PostgreSQL — not to defend against a
* malicious module, which this facade cannot do and does not attempt to do.
*/
export type ModuleDatabase = Pick<
NodePgDatabase,
| "select"
| "selectDistinct"
| "selectDistinctOn"
| "insert"
| "update"
| "delete"
| "execute"
| "transaction"
>;
/** The services a legacy module's hooks and handlers receive: the legacy facade. */
export type LegacyModuleRuntimeServices = ModuleRuntimeServices<ModuleDatabase>;
/** The services Core hands any started module: the legacy facade or the ABI v1 executor. */
export type AnyModuleRuntimeServices =
| LegacyModuleRuntimeServices
| ModuleDatabaseAbiRuntimeServices;
/** /**
* A typed `ModuleDatabase` view over an externally owned pool — the module-facing counterpart to * A typed `ModuleDatabase` view over an externally owned pool — the module-facing counterpart to
* `createIdentityDrizzleView` (`core/src/identity/database.ts`) and * `createIdentityDrizzleView` (`core/src/identity/database.ts`) and
+1
View File
@@ -9,6 +9,7 @@ export * from "./lifecycle-schema.js";
export * from "./lifecycle-store.js"; export * from "./lifecycle-store.js";
export * from "./migration-discovery.js"; export * from "./migration-discovery.js";
export * from "./modules-directory.js"; export * from "./modules-directory.js";
export * from "./module-package-host.js";
export * from "./module-package-verification.js"; export * from "./module-package-verification.js";
export * from "./permissions.js"; export * from "./permissions.js";
export * from "./realtime.js"; export * from "./realtime.js";
@@ -1,19 +1,15 @@
/**
* The legacy module schema definition (ADR 0007): a v8 module that declares no `database` default-
* exports `{ moduleId, tables }` with its Drizzle table objects themselves. Core alone validates it,
* for the legacy facade's deprecation window (ADR 0050). It lives here, beside Core's own Drizzle
* dependency, so that no package a module installs needs Drizzle at run time (ADR 0053).
*
* Erasable TypeScript with no relative imports: the verifier's probe imports this source file
* directly in tests (`module-package-probe.ts`).
*/
import { is } from "drizzle-orm"; import { is } from "drizzle-orm";
import { type AnyPgTable, PgTable } from "drizzle-orm/pg-core"; import { type AnyPgTable, PgTable } from "drizzle-orm/pg-core";
import { z } from "zod"; import { type ModuleId, moduleIdSchema } from "@ekklesia/contracts";
import { type ModuleId, moduleIdSchema } from "./identifiers.js";
export const POSTGRES_IDENTIFIER_MAX_LENGTH = 63;
export const moduleTableLocalNameSchema = z
.string()
.min(1)
.regex(/^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u, "Must be a lowercase snake-case table name.");
export const physicalModuleTableNameSchema = moduleTableLocalNameSchema.max(
POSTGRES_IDENTIFIER_MAX_LENGTH,
`Must not exceed ${POSTGRES_IDENTIFIER_MAX_LENGTH} characters.`,
);
export interface ModuleSchemaDefinition< export interface ModuleSchemaDefinition<
Tables extends Readonly<Record<string, AnyPgTable>> = Readonly<Record<string, AnyPgTable>>, Tables extends Readonly<Record<string, AnyPgTable>> = Readonly<Record<string, AnyPgTable>>,
@@ -35,23 +31,6 @@ function hasOnlyStringKeys(value: object, allowedKeys?: ReadonlySet<string>): bo
); );
} }
export function moduleTableNamespace(moduleId: ModuleId): string {
return moduleIdSchema.parse(moduleId).replaceAll("-", "_");
}
export function moduleTablePrefix(moduleId: ModuleId): string {
return `${moduleTableNamespace(moduleId)}_`;
}
export function moduleTableName(moduleId: ModuleId, localName: string): string {
const parsedLocalName = moduleTableLocalNameSchema.parse(localName);
const tableName = `${moduleTablePrefix(moduleId)}${parsedLocalName}`;
if (!physicalModuleTableNameSchema.safeParse(tableName).success) {
throw new RangeError("The namespaced PostgreSQL table name is invalid or too long.");
}
return tableName;
}
export function isModuleSchemaDefinition(value: unknown): value is ModuleSchemaDefinition { export function isModuleSchemaDefinition(value: unknown): value is ModuleSchemaDefinition {
try { try {
if ( if (
+59
View File
@@ -0,0 +1,59 @@
/**
* The facts about this host that decide whether a native Module Package v1 can run on it
* (ADR 0049): operating system, CPU, C library family and version, and Node-API version.
*
* Everything comes from Node.js itself (`process.platform`, `process.arch`, `process.versions`, and
* the diagnostic report's `glibcVersionRuntime`), never from running a system command. A fact Node
* cannot report is left undefined, and every check that needs it fails closed.
*/
export interface ModulePackageHost {
readonly platform: string;
readonly arch: string;
/** The C library on Linux: glibc with its runtime version, or undefined when it cannot be proven
* to be glibc (musl reports none). */
readonly libc?: { readonly family: "glibc"; readonly version: string };
/** `process.versions.napi`: the highest Node-API version this Node.js provides. */
readonly nodeApi?: number;
/** `process.versions.modules`: the ABI an ABI-specific addon must have been built for. */
readonly nodeAbi?: string;
}
function glibcVersion(): string | undefined {
try {
const header = (process.report?.getReport() as { header?: { glibcVersionRuntime?: unknown } })
?.header;
const version = header?.glibcVersionRuntime;
return typeof version === "string" && /^\d+\.\d+(?:\.\d+)?$/u.test(version)
? version
: undefined;
} catch {
return undefined;
}
}
export function currentModulePackageHost(): ModulePackageHost {
const libc = process.platform === "linux" ? glibcVersion() : undefined;
const nodeApi = Number(process.versions.napi);
return Object.freeze({
arch: process.arch,
...(libc === undefined
? {}
: { libc: Object.freeze({ family: "glibc" as const, version: libc }) }),
...(Number.isInteger(nodeApi) && nodeApi > 0 ? { nodeApi } : {}),
...(typeof process.versions.modules === "string" ? { nodeAbi: process.versions.modules } : {}),
platform: process.platform,
});
}
/** The native targets this platform can verify, with what each requires of a host. */
export const MODULE_PACKAGE_NATIVE_TARGETS: ReadonlyMap<
string,
{
readonly platform: string;
readonly arch: string;
readonly libc: "glibc";
readonly elfMachine: number;
}
> = new Map([
["linux-x64-glibc", { arch: "x64", elfMachine: 62, libc: "glibc", platform: "linux" }],
]);
+17 -5
View File
@@ -9,12 +9,18 @@
// The result travels over the IPC channel, never stdout, so nothing a module prints can forge it. // The result travels over the IPC channel, never stdout, so nothing a module prints can forge it.
// It carries fixed role and reason names only: never an error message, a path, or module output. // It carries fixed role and reason names only: never an error message, a path, or module output.
// //
// Written as erasable TypeScript with no relative imports, so Node can run the source file directly // Written as erasable TypeScript, so Node can run the source file directly in tests as well as the
// in tests as well as the compiled file in the image. // compiled file in the image. Its one relative import names the source file's own extension, which
// the build rewrites to `.js` (`rewriteRelativeImportExtensions`); that file follows the same rules.
import { pathToFileURL } from "node:url"; import { pathToFileURL } from "node:url";
import { parseModuleRuntimeDefinition, parseModuleSchemaDefinition } from "@ekklesia/contracts"; import {
parseModuleRuntimeDefinition,
parseModuleSchemaMetadataDefinition,
} from "@ekklesia/contracts";
import { parseModuleSchemaDefinition } from "./legacy-schema-definition.ts";
interface ProbeRequest { interface ProbeRequest {
readonly databaseAbi?: 1;
readonly moduleId: string; readonly moduleId: string;
readonly version: string; readonly version: string;
readonly entrypoints: Readonly<Record<string, string>>; readonly entrypoints: Readonly<Record<string, string>>;
@@ -22,7 +28,7 @@ interface ProbeRequest {
interface ProbeFailure { interface ProbeFailure {
readonly role: string; readonly role: string;
readonly reason: "export" | "identity" | "load"; readonly reason: "contract" | "export" | "identity" | "load";
} }
function defaultExport(namespace: unknown): unknown { function defaultExport(namespace: unknown): unknown {
@@ -51,8 +57,14 @@ async function probe(request: ProbeRequest): Promise<readonly ProbeFailure[]> {
if (definition.id !== request.moduleId || definition.version !== request.version) { if (definition.id !== request.moduleId || definition.version !== request.version) {
failures.push({ reason: "identity", role }); failures.push({ reason: "identity", role });
} }
if ((definition.database?.abi === 1) !== (request.databaseAbi === 1)) {
failures.push({ reason: "contract", role });
}
} else if (role === "schema") { } else if (role === "schema") {
const definition = parseModuleSchemaDefinition(defaultExport(namespace)); const definition =
request.databaseAbi === 1
? parseModuleSchemaMetadataDefinition(defaultExport(namespace))
: parseModuleSchemaDefinition(defaultExport(namespace));
if (definition.moduleId !== request.moduleId) { if (definition.moduleId !== request.moduleId) {
failures.push({ reason: "identity", role }); failures.push({ reason: "identity", role });
} }
+130 -22
View File
@@ -6,16 +6,23 @@ import path from "node:path";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import { import {
isVersionCompatible, isVersionCompatible,
type ModuleManifest,
safeParseModuleManifest,
} from "@ekklesia/contracts";
import {
MODULE_PACKAGE_ANY_TARGET, MODULE_PACKAGE_ANY_TARGET,
MODULE_PACKAGE_FORMAT, MODULE_PACKAGE_FORMAT,
MODULE_PACKAGE_METADATA_FILENAME, MODULE_PACKAGE_METADATA_FILENAME,
type ModuleManifest,
type ModulePackageMetadata, type ModulePackageMetadata,
safeParseModuleManifest,
safeParseModulePackageMetadata, safeParseModulePackageMetadata,
safeParseModulePackageRuntimePackage, safeParseModulePackageRuntimePackage,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts/module-package";
import { discoverModules, MODULE_MANIFEST_FILENAME, ModuleDiscoveryError } from "./discovery.js"; import { discoverModules, MODULE_MANIFEST_FILENAME, ModuleDiscoveryError } from "./discovery.js";
import {
currentModulePackageHost,
MODULE_PACKAGE_NATIVE_TARGETS,
type ModulePackageHost,
} from "./module-package-host.js";
import { discoverModuleMigrations, ModuleMigrationDiscoveryError } from "./migration-discovery.js"; import { discoverModuleMigrations, ModuleMigrationDiscoveryError } from "./migration-discovery.js";
import { import {
type ModulePackageArchive, type ModulePackageArchive,
@@ -45,6 +52,7 @@ import { discoverModuleSchemas, ModuleSchemaDiscoveryError } from "./schema-disc
export type ModulePackageVerificationErrorCode = export type ModulePackageVerificationErrorCode =
| ModulePackageArchiveErrorCode | ModulePackageArchiveErrorCode
| "MODULE_PACKAGE_DATABASE_RUNTIME_INCOMPATIBLE" | "MODULE_PACKAGE_DATABASE_RUNTIME_INCOMPATIBLE"
| "MODULE_PACKAGE_DATABASE_RUNTIME_UNEXPECTED"
| "MODULE_PACKAGE_DIGEST_MISMATCH" | "MODULE_PACKAGE_DIGEST_MISMATCH"
| "MODULE_PACKAGE_ENTRYPOINT_LOAD_FAILED" | "MODULE_PACKAGE_ENTRYPOINT_LOAD_FAILED"
| "MODULE_PACKAGE_EXTRACTION_FAILED" | "MODULE_PACKAGE_EXTRACTION_FAILED"
@@ -53,11 +61,14 @@ export type ModulePackageVerificationErrorCode =
| "MODULE_PACKAGE_FILE_UNLISTED" | "MODULE_PACKAGE_FILE_UNLISTED"
| "MODULE_PACKAGE_FORMAT_UNSUPPORTED" | "MODULE_PACKAGE_FORMAT_UNSUPPORTED"
| "MODULE_PACKAGE_IDENTITY_MISMATCH" | "MODULE_PACKAGE_IDENTITY_MISMATCH"
| "MODULE_PACKAGE_LIBC_INCOMPATIBLE"
| "MODULE_PACKAGE_MANIFEST_INVALID" | "MODULE_PACKAGE_MANIFEST_INVALID"
| "MODULE_PACKAGE_METADATA_INVALID" | "MODULE_PACKAGE_METADATA_INVALID"
| "MODULE_PACKAGE_METADATA_MISSING" | "MODULE_PACKAGE_METADATA_MISSING"
| "MODULE_PACKAGE_MODULE_INVALID" | "MODULE_PACKAGE_MODULE_INVALID"
| "MODULE_PACKAGE_NATIVE_FILE" | "MODULE_PACKAGE_NATIVE_FILE"
| "MODULE_PACKAGE_NATIVE_FILE_INCOMPATIBLE"
| "MODULE_PACKAGE_NODE_API_INCOMPATIBLE"
| "MODULE_PACKAGE_RUNTIME_INCOMPATIBLE" | "MODULE_PACKAGE_RUNTIME_INCOMPATIBLE"
| "MODULE_PACKAGE_RUNTIME_PACKAGE_INVALID" | "MODULE_PACKAGE_RUNTIME_PACKAGE_INVALID"
| "MODULE_PACKAGE_SDK_INCOMPATIBLE" | "MODULE_PACKAGE_SDK_INCOMPATIBLE"
@@ -67,6 +78,8 @@ export type ModulePackageVerificationErrorCode =
const messages: Readonly<Record<ModulePackageVerificationErrorCode, string>> = Object.freeze({ const messages: Readonly<Record<ModulePackageVerificationErrorCode, string>> = Object.freeze({
MODULE_PACKAGE_DATABASE_RUNTIME_INCOMPATIBLE: MODULE_PACKAGE_DATABASE_RUNTIME_INCOMPATIBLE:
"The package's bundled database runtime does not match this platform's (a transitional constraint).", "The package's bundled database runtime does not match this platform's (a transitional constraint).",
MODULE_PACKAGE_DATABASE_RUNTIME_UNEXPECTED:
"A Module Database ABI package must not carry a transitional database runtime.",
MODULE_PACKAGE_DIGEST_MISMATCH: "The archive does not match the SHA-256 it was given.", MODULE_PACKAGE_DIGEST_MISMATCH: "The archive does not match the SHA-256 it was given.",
MODULE_PACKAGE_ENTRYPOINT_LOAD_FAILED: MODULE_PACKAGE_ENTRYPOINT_LOAD_FAILED:
"A backend entrypoint could not be loaded from the package alone.", "A backend entrypoint could not be loaded from the package alone.",
@@ -80,12 +93,19 @@ const messages: Readonly<Record<ModulePackageVerificationErrorCode, string>> = O
"The package metadata, runtime package.json, and manifest disagree about the module's identity.", "The package metadata, runtime package.json, and manifest disagree about the module's identity.",
MODULE_PACKAGE_LAYOUT_INVALID: MODULE_PACKAGE_LAYOUT_INVALID:
"The archive must contain exactly one top-level module directory, with each path once.", "The archive must contain exactly one top-level module directory, with each path once.",
MODULE_PACKAGE_LIBC_INCOMPATIBLE:
"The package needs a newer C library than this host provides, or one it cannot establish.",
MODULE_PACKAGE_LINK: "The archive contains a link; module packages may contain none.", MODULE_PACKAGE_LINK: "The archive contains a link; module packages may contain none.",
MODULE_PACKAGE_MANIFEST_INVALID: "The package's module manifest is missing or invalid.", MODULE_PACKAGE_MANIFEST_INVALID: "The package's module manifest is missing or invalid.",
MODULE_PACKAGE_METADATA_INVALID: "The package metadata is invalid.", MODULE_PACKAGE_METADATA_INVALID: "The package metadata is invalid.",
MODULE_PACKAGE_METADATA_MISSING: "The archive contains no package metadata.", MODULE_PACKAGE_METADATA_MISSING: "The archive contains no package metadata.",
MODULE_PACKAGE_MODULE_INVALID: "The packaged module failed module validation.", MODULE_PACKAGE_MODULE_INVALID: "The packaged module failed module validation.",
MODULE_PACKAGE_NATIVE_FILE: "An any-target package contains a native file.", MODULE_PACKAGE_NATIVE_FILE:
"An any-target package contains a native file or a node_modules directory.",
MODULE_PACKAGE_NATIVE_FILE_INCOMPATIBLE:
"A native file in the package is not built for the package's target.",
MODULE_PACKAGE_NODE_API_INCOMPATIBLE:
"The package's addons need a Node-API version or Node.js ABI this host does not provide.",
MODULE_PACKAGE_RUNTIME_INCOMPATIBLE: MODULE_PACKAGE_RUNTIME_INCOMPATIBLE:
"The package needs a Node.js version this host does not run.", "The package needs a Node.js version this host does not run.",
MODULE_PACKAGE_RUNTIME_PACKAGE_INVALID: MODULE_PACKAGE_RUNTIME_PACKAGE_INVALID:
@@ -126,6 +146,8 @@ export interface ModulePackagePlatform {
readonly databaseRuntime: Readonly<Record<string, string>>; readonly databaseRuntime: Readonly<Record<string, string>>;
/** Defaults to the running process's Node.js version. */ /** Defaults to the running process's Node.js version. */
readonly nodeVersion?: string; readonly nodeVersion?: string;
/** Defaults to this process's own host (`currentModulePackageHost`). */
readonly host?: ModulePackageHost;
} }
export interface VerifyModulePackageOptions { export interface VerifyModulePackageOptions {
@@ -261,13 +283,20 @@ function checkCompatibility(
files: ReadonlyMap<string, Buffer>, files: ReadonlyMap<string, Buffer>,
platform: ModulePackagePlatform, platform: ModulePackagePlatform,
): void { ): void {
// This verifier implements the portable target only. Native targets are a later slice. if (metadata.target === MODULE_PACKAGE_ANY_TARGET) {
if (metadata.target !== MODULE_PACKAGE_ANY_TARGET) { // An any-target package bundles everything: no addon, no ELF object, no node_modules.
fail("MODULE_PACKAGE_TARGET_INCOMPATIBLE"); for (const [filePath, data] of files) {
} if (
if ([...files.keys()].some((filePath) => filePath.toLowerCase().endsWith(".node"))) { filePath.toLowerCase().endsWith(".node") ||
filePath.startsWith("node_modules/") ||
isElf(data)
) {
fail("MODULE_PACKAGE_NATIVE_FILE"); fail("MODULE_PACKAGE_NATIVE_FILE");
} }
}
} else {
checkNativeTarget(metadata, files, platform.host ?? currentModulePackageHost());
}
if (!isVersionCompatible(platform.nodeVersion ?? process.versions.node, metadata.runtime.node)) { if (!isVersionCompatible(platform.nodeVersion ?? process.versions.node, metadata.runtime.node)) {
fail("MODULE_PACKAGE_RUNTIME_INCOMPATIBLE"); fail("MODULE_PACKAGE_RUNTIME_INCOMPATIBLE");
} }
@@ -275,9 +304,15 @@ function checkCompatibility(
if (sdk !== undefined && !isVersionCompatible(sdk, manifest.compatibility.moduleSdk)) { if (sdk !== undefined && !isVersionCompatible(sdk, manifest.compatibility.moduleSdk)) {
fail("MODULE_PACKAGE_SDK_INCOMPATIBLE"); fail("MODULE_PACKAGE_SDK_INCOMPATIBLE");
} }
// Transitional (ADR 0049): today a module's Drizzle copy must be interchangeable with the if (manifest.database?.abi === 1) {
// platform's, because Core queries the module's tables with its own Drizzle instance. This is an if (metadata.transitional?.databaseRuntime !== undefined) {
// implementation constraint pending a Module Database ABI, not that ABI. fail("MODULE_PACKAGE_DATABASE_RUNTIME_UNEXPECTED");
}
return;
}
// Transitional legacy-v8 path (ADR 0049): Core queries the module's Drizzle tables with its own
// Drizzle instance, so a recorded module runtime must match. ABI-v1 packages return above: their
// bundled ORM is a private implementation detail and is never compared with Core's.
for (const [runtime, version] of Object.entries(metadata.transitional?.databaseRuntime ?? {})) { for (const [runtime, version] of Object.entries(metadata.transitional?.databaseRuntime ?? {})) {
if (platform.databaseRuntime[runtime] !== version) { if (platform.databaseRuntime[runtime] !== version) {
fail("MODULE_PACKAGE_DATABASE_RUNTIME_INCOMPATIBLE"); fail("MODULE_PACKAGE_DATABASE_RUNTIME_INCOMPATIBLE");
@@ -285,6 +320,74 @@ function checkCompatibility(
} }
} }
function isElf(data: Uint8Array): boolean {
return (
data.length >= 4 && data[0] === 0x7f && data[1] === 0x45 && data[2] === 0x4c && data[3] === 0x46
);
}
/** `2.41` → `2.41.0`, for comparison against a semantic-version range. */
function asSemver(version: string): string {
const parts = version.split(".");
return [...parts, "0", "0"].slice(0, 3).join(".");
}
/**
* A native target (ADR 0049): accepted only for a target this platform implements, on a host that
* provably matches it. Platform, CPU, C library family and minimum version, and the Node-API version
* or ABI the addons need are all checked; a fact the host cannot establish fails closed. Every ELF
* object in the package must be built for the target's machine, and every `.node` addon must be one.
*/
function checkNativeTarget(
metadata: ModulePackageMetadata,
files: ReadonlyMap<string, Buffer>,
host: ModulePackageHost,
): void {
const target = MODULE_PACKAGE_NATIVE_TARGETS.get(metadata.target);
if (
target === undefined ||
host.platform !== target.platform ||
host.arch !== target.arch ||
host.libc?.family !== target.libc
) {
fail("MODULE_PACKAGE_TARGET_INCOMPATIBLE");
}
const required = metadata.runtime.libcVersion;
if (
required === undefined ||
host.libc === undefined ||
!isVersionCompatible(asSemver(host.libc.version), required)
) {
fail("MODULE_PACKAGE_LIBC_INCOMPATIBLE");
}
const { nodeAbi, nodeApi } = metadata.runtime;
if (
(nodeApi === undefined && nodeAbi === undefined) ||
(nodeApi !== undefined && (host.nodeApi === undefined || host.nodeApi < nodeApi)) ||
(nodeAbi !== undefined && host.nodeAbi !== nodeAbi)
) {
fail("MODULE_PACKAGE_NODE_API_INCOMPATIBLE");
}
for (const [filePath, data] of files) {
const addon = filePath.toLowerCase().endsWith(".node");
if (!isElf(data)) {
if (addon) {
fail("MODULE_PACKAGE_NATIVE_FILE_INCOMPATIBLE");
}
continue;
}
// ELF64, little-endian, for the target's machine (e_machine at offset 18).
if (
data.length < 20 ||
data[4] !== 2 ||
data[5] !== 1 ||
data.readUInt16LE(18) !== target.elfMachine
) {
fail("MODULE_PACKAGE_NATIVE_FILE_INCOMPATIBLE");
}
}
}
/** Writes the archive's directories (`0755`) and files (`0644`) under `root`, which must not exist. /** Writes the archive's directories (`0755`) and files (`0644`) under `root`, which must not exist.
* Safe by construction: every path was validated as relative and non-escaping, and only directories * Safe by construction: every path was validated as relative and non-escaping, and only directories
* and regular files exist. Ownership is the writing process's, never the archive's. */ * and regular files exist. Ownership is the writing process's, never the archive's. */
@@ -314,8 +417,7 @@ function probeEntrypointPath(): string {
/** Loads every backend entrypoint in a short-lived child with an empty environment, and reports /** Loads every backend entrypoint in a short-lived child with an empty environment, and reports
* only whether each loaded and exported a definition naming this module. */ * only whether each loaded and exported a definition naming this module. */
async function loadEntrypoints( async function loadEntrypoints(
moduleId: string, manifest: Pick<ModuleManifest, "database" | "id" | "version">,
version: string,
entrypoints: Readonly<Record<string, string>>, entrypoints: Readonly<Record<string, string>>,
timeoutMs: number, timeoutMs: number,
): Promise<void> { ): Promise<void> {
@@ -332,13 +434,24 @@ async function loadEntrypoints(
} }
}; };
try { try {
child = fork(probeEntrypointPath(), [JSON.stringify({ entrypoints, moduleId, version })], { child = fork(
probeEntrypointPath(),
[
JSON.stringify({
...(manifest.database?.abi === 1 ? { databaseAbi: 1 } : {}),
entrypoints,
moduleId: manifest.id,
version: manifest.version,
}),
],
{
cwd: tmpdir(), cwd: tmpdir(),
env: {}, env: {},
execArgv: [], execArgv: [],
serialization: "json", serialization: "json",
stdio: ["ignore", "ignore", "ignore", "ipc"], stdio: ["ignore", "ignore", "ignore", "ipc"],
}); },
);
} catch { } catch {
finish("failed"); finish("failed");
return; return;
@@ -437,12 +550,7 @@ export async function verifyModulePackage(
// Executed only now, and first in isolation: a schema is imported in this process below only // Executed only now, and first in isolation: a schema is imported in this process below only
// after the probe proved it loads on its own. // after the probe proved it loads on its own.
await loadEntrypoints( await loadEntrypoints(manifest, entrypoints, options.loadTimeoutMs ?? 30_000);
metadata.module.id,
metadata.module.version,
entrypoints,
options.loadTimeoutMs ?? 30_000,
);
try { try {
await discoverModuleSchemas(discoveryOptions); await discoverModuleSchemas(discoveryOptions);
} catch (error) { } catch (error) {
+68 -26
View File
@@ -7,15 +7,16 @@ import {
EMPTY_MODULE_CONFIGURATION, EMPTY_MODULE_CONFIGURATION,
EMPTY_MODULE_STORAGE, EMPTY_MODULE_STORAGE,
type ModuleConfiguration, type ModuleConfiguration,
type ModuleDatabaseExecutor,
type ModuleHttpRouteRegistrar, type ModuleHttpRouteRegistrar,
type ModuleId, type ModuleId,
ModuleRealtimeError, ModuleRealtimeError,
type ModuleRealtimePublisher, type ModuleRealtimePublisher,
type ModuleRegistrationContext, type ModuleRegistrationContext,
type ModuleRouteDefinitionInput, type ModuleRouteDefinitionInput,
type ModuleRouteHandler,
type ModuleRuntimeContext, type ModuleRuntimeContext,
type ModuleRuntimeDefinition, type ModuleRuntimeDefinition,
type ModuleRuntimeServices,
type ModuleStorage, type ModuleStorage,
moduleRouteShapeKey, moduleRouteShapeKey,
moduleRoutesOverlap, moduleRoutesOverlap,
@@ -24,6 +25,7 @@ import {
type RegisteredModuleHttpRoute, type RegisteredModuleHttpRoute,
safeParseModuleRouteDefinition, safeParseModuleRouteDefinition,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import type { AnyModuleRuntimeServices, ModuleDatabase } from "./database.js";
import { import {
type DiscoveredModule, type DiscoveredModule,
discoverModules, discoverModules,
@@ -68,6 +70,7 @@ export type ModuleRuntimeIssueCode =
| "MODULE_ROUTE_PERMISSION_INVALID" | "MODULE_ROUTE_PERMISSION_INVALID"
| "MODULE_ROUTE_PERMISSION_UNDECLARED" | "MODULE_ROUTE_PERMISSION_UNDECLARED"
| "MODULE_RUNTIME_EXPORT_INVALID" | "MODULE_RUNTIME_EXPORT_INVALID"
| "MODULE_RUNTIME_DATABASE_MISMATCH"
| "MODULE_RUNTIME_ID_MISMATCH" | "MODULE_RUNTIME_ID_MISMATCH"
| "MODULE_RUNTIME_IMPORT_FAILED" | "MODULE_RUNTIME_IMPORT_FAILED"
| "MODULE_RUNTIME_VERSION_MISMATCH" | "MODULE_RUNTIME_VERSION_MISMATCH"
@@ -105,9 +108,8 @@ export interface StartedModuleRuntime {
/** /**
* Per-module frozen configuration snapshots, keyed by module id (ADR 0029). * Per-module frozen configuration snapshots, keyed by module id (ADR 0029).
* *
* A lookup rather than a field on `ModuleRuntimeServices`, because `services` is deliberately **one * A lookup rather than a field on `ModuleRuntimeServices`, because configuration is resolved and
* shared object identity every module receives** — a property this runtime has a test for — while * frozen per module independently of its live service object. A module with no entry receives
* configuration is per-module by definition. A module with no entry receives
* `EMPTY_MODULE_CONFIGURATION` rather than `undefined`, so `context.config` is always present and * `EMPTY_MODULE_CONFIGURATION` rather than `undefined`, so `context.config` is always present and
* module code never branches on whether the platform supplied one. * module code never branches on whether the platform supplied one.
*/ */
@@ -124,12 +126,33 @@ function configurationFor(
* Per-module scoped object storage, keyed by module id (ADR 0030). * Per-module scoped object storage, keyed by module id (ADR 0030).
* *
* A lookup for the same reason configuration is one, and emphatically **not** a field on * A lookup for the same reason configuration is one, and emphatically **not** a field on
* `ModuleRuntimeServices`: `services` is one shared object identity every module receives, while a * `ModuleRuntimeServices`: a storage facade is scoped to exactly the buckets one module declared.
* storage facade is scoped to exactly the buckets one module declared. Sharing it would hand every * Sharing it would hand every
* module every other module's storage. * module every other module's storage.
*/ */
export type ModuleStorageLookup = ReadonlyMap<string, ModuleStorage>; export type ModuleStorageLookup = ReadonlyMap<string, ModuleStorage>;
/** One frozen service object per module id. Legacy modules may point at objects wrapping the same
* facade; ABI-v1 modules each point at their own attributed executor. */
export type ModuleRuntimeServicesLookup = ReadonlyMap<string, AnyModuleRuntimeServices>;
export type ModuleRuntimeServicesSource = ModuleRuntimeServicesLookup | AnyModuleRuntimeServices;
function servicesFor(
services: ModuleRuntimeServicesSource,
module: DiscoveredModule,
): AnyModuleRuntimeServices {
const selected = "get" in services ? services.get(module.manifest.id) : services;
if (!selected) {
throw new TypeError(`Module ${module.manifest.id} has no runtime services.`);
}
const expectsAbi = module.manifest.database?.abi === 1;
const isAbi = "abiVersion" in selected.database && selected.database.abiVersion === 1;
if (expectsAbi !== isAbi) {
throw new TypeError(`Module ${module.manifest.id} has the wrong database service.`);
}
return selected;
}
function storageFor(storages: ModuleStorageLookup, moduleId: string): ModuleStorage { function storageFor(storages: ModuleStorageLookup, moduleId: string): ModuleStorage {
return storages.get(moduleId) ?? EMPTY_MODULE_STORAGE; return storages.get(moduleId) ?? EMPTY_MODULE_STORAGE;
} }
@@ -164,10 +187,9 @@ export interface ModuleRuntimeCompositionOptions extends ModuleRuntimeTimeoutOpt
export interface StartModuleRuntimeOptions export interface StartModuleRuntimeOptions
extends ModuleDiscoveryOptions, extends ModuleDiscoveryOptions,
ModuleRuntimeCompositionOptions { ModuleRuntimeCompositionOptions {
/** The same frozen services object every started module's `start`/`stop` hooks and (once /** The manifest-selected service object for each module. One module's `start`/`stop` hooks and
* `apps/api` mounts routes) HTTP handlers receive for this runtime — a required production * handlers receive its same entry; ABI-v1 entries carry distinct attributed executors. */
* dependency, never an optional test-only global. See `ModuleRuntimeServices`. */ readonly services: ModuleRuntimeServicesSource;
readonly services: ModuleRuntimeServices;
} }
interface LoadedModule { interface LoadedModule {
@@ -175,6 +197,13 @@ interface LoadedModule {
readonly discovered: DiscoveredModule; readonly discovered: DiscoveredModule;
} }
type AnyRegistrationHook = (
context: ModuleRegistrationContext<ModuleDatabase | ModuleDatabaseExecutor>,
) => unknown;
type AnyRuntimeHook = (
context: ModuleRuntimeContext<ModuleDatabase | ModuleDatabaseExecutor>,
) => unknown;
interface CapabilityRegistrationStage { interface CapabilityRegistrationStage {
readonly capabilities: CapabilityRegistrar; readonly capabilities: CapabilityRegistrar;
commit(): readonly ModuleRuntimeIssue[]; commit(): readonly ModuleRuntimeIssue[];
@@ -316,11 +345,11 @@ class StagedCapabilityRegistry {
createRuntimeContext( createRuntimeContext(
module: DiscoveredModule, module: DiscoveredModule,
phase: "rollback" | "start" | "stop", phase: "rollback" | "start" | "stop",
services: ModuleRuntimeServices, services: AnyModuleRuntimeServices,
config: ModuleConfiguration, config: ModuleConfiguration,
storage: ModuleStorage, storage: ModuleStorage,
realtime: ModuleRealtimePublisher, realtime: ModuleRealtimePublisher,
): ModuleRuntimeContext { ): ModuleRuntimeContext<ModuleDatabase | ModuleDatabaseExecutor> {
const capabilities: CapabilityResolver = Object.freeze({ const capabilities: CapabilityResolver = Object.freeze({
resolve: (capabilityId: CapabilityId): RegisteredCapability | undefined => { resolve: (capabilityId: CapabilityId): RegisteredCapability | undefined => {
this.#assertAccess(module, capabilityId, phase); this.#assertAccess(module, capabilityId, phase);
@@ -469,7 +498,7 @@ class StagedModuleHttpRoutes {
local.push( local.push(
Object.freeze({ Object.freeze({
bodyMode: parsed.data.bodyMode, bodyMode: parsed.data.bodyMode,
handler: parsed.data.handler, handler: parsed.data.handler as ModuleRouteHandler,
maxBodyBytes: parsed.data.maxBodyBytes, maxBodyBytes: parsed.data.maxBodyBytes,
method: parsed.data.method, method: parsed.data.method,
moduleId: module.manifest.id, moduleId: module.manifest.id,
@@ -555,6 +584,19 @@ async function loadRuntimeDefinitions(
), ),
); );
} }
const runtimeDeclaresAbi = definition.database?.abi === 1;
const manifestDeclaresAbi = discovered.manifest.database?.abi === 1;
if (runtimeDeclaresAbi !== manifestDeclaresAbi) {
matchesManifest = false;
issues.push(
runtimeIssue(
"MODULE_RUNTIME_DATABASE_MISMATCH",
"load",
discovered.manifest.id,
`Module runtime database declaration does not match manifest ${discovered.manifest.id}.`,
),
);
}
if (matchesManifest) { if (matchesManifest) {
loaded.push({ definition, discovered }); loaded.push({ definition, discovered });
} }
@@ -580,15 +622,15 @@ async function registerModules(
module.discovered.manifest.id, module.discovered.manifest.id,
new Set(module.discovered.manifest.permissions.map((declaration) => declaration.id)), new Set(module.discovered.manifest.permissions.map((declaration) => declaration.id)),
); );
const context: ModuleRegistrationContext = Object.freeze({ const context = Object.freeze({
capabilities: capabilityStage.capabilities, capabilities: capabilityStage.capabilities,
config: configurationFor(configurations, module.discovered.manifest.id), config: configurationFor(configurations, module.discovered.manifest.id),
http: routeStage.http, http: routeStage.http,
moduleId: module.discovered.manifest.id, moduleId: module.discovered.manifest.id,
realtime: realtimeStage.realtime, realtime: realtimeStage.realtime,
}); }) as ModuleRegistrationContext<ModuleDatabase | ModuleDatabaseExecutor>;
try { try {
await module.definition.register?.(context); await (module.definition.register as AnyRegistrationHook | undefined)?.(context);
} catch (error) { } catch (error) {
if (error instanceof ModuleRuntimeSignal) { if (error instanceof ModuleRuntimeSignal) {
throw new ModuleRuntimeError([error.issue]); throw new ModuleRuntimeError([error.issue]);
@@ -685,7 +727,7 @@ async function stopModules(
modules: readonly LoadedModule[], modules: readonly LoadedModule[],
registry: StagedCapabilityRegistry, registry: StagedCapabilityRegistry,
phase: "rollback" | "stop", phase: "rollback" | "stop",
services: ModuleRuntimeServices, services: ModuleRuntimeServicesSource,
configurations: ModuleConfigurationLookup, configurations: ModuleConfigurationLookup,
storages: ModuleStorageLookup, storages: ModuleStorageLookup,
realtimeRegistry: StagedModuleRealtimeRegistry, realtimeRegistry: StagedModuleRealtimeRegistry,
@@ -698,7 +740,7 @@ async function stopModules(
// A dependency may keep doing ordinary work while its dependents stop. Deactivate only the // A dependency may keep doing ordinary work while its dependents stop. Deactivate only the
// module whose stop hook is about to run, not every publisher at the beginning of the sequence. // module whose stop hook is about to run, not every publisher at the beginning of the sequence.
realtimeRegistry.deactivateModule(moduleId); realtimeRegistry.deactivateModule(moduleId);
const stop = module.definition.stop; const stop = module.definition.stop as AnyRuntimeHook | undefined;
if (!stop) { if (!stop) {
// No synthetic callback and no timer for a module that declares no stop hook. // No synthetic callback and no timer for a module that declares no stop hook.
continue; continue;
@@ -710,13 +752,13 @@ async function stopModules(
registry.createRuntimeContext( registry.createRuntimeContext(
module.discovered, module.discovered,
phase, phase,
services, servicesFor(services, module.discovered),
configurationFor(configurations, moduleId), configurationFor(configurations, moduleId),
storageFor(storages, moduleId), storageFor(storages, moduleId),
realtimeRegistry.publisherFor(moduleId), realtimeRegistry.publisherFor(moduleId),
) as ModuleRuntimeContext<ModuleDatabase | ModuleDatabaseExecutor>,
), ),
), ).then(() => undefined),
),
timeoutMs, timeoutMs,
); );
if (outcome === "timed-out") { if (outcome === "timed-out") {
@@ -750,7 +792,7 @@ async function stopModules(
async function startModules( async function startModules(
modules: readonly LoadedModule[], modules: readonly LoadedModule[],
registry: StagedCapabilityRegistry, registry: StagedCapabilityRegistry,
services: ModuleRuntimeServices, services: ModuleRuntimeServicesSource,
configurations: ModuleConfigurationLookup, configurations: ModuleConfigurationLookup,
storages: ModuleStorageLookup, storages: ModuleStorageLookup,
realtimeRegistry: StagedModuleRealtimeRegistry, realtimeRegistry: StagedModuleRealtimeRegistry,
@@ -766,15 +808,15 @@ async function startModules(
for (const module of modules) { for (const module of modules) {
rollbackCandidates.push(module); rollbackCandidates.push(module);
try { try {
await module.definition.start?.( await (module.definition.start as AnyRuntimeHook | undefined)?.(
registry.createRuntimeContext( registry.createRuntimeContext(
module.discovered, module.discovered,
"start", "start",
services, servicesFor(services, module.discovered),
configurationFor(configurations, module.discovered.manifest.id), configurationFor(configurations, module.discovered.manifest.id),
storageFor(storages, module.discovered.manifest.id), storageFor(storages, module.discovered.manifest.id),
realtimeRegistry.publisherFor(module.discovered.manifest.id), realtimeRegistry.publisherFor(module.discovered.manifest.id),
), ) as ModuleRuntimeContext<ModuleDatabase | ModuleDatabaseExecutor>,
); );
const missingSnapshots = realtimeRegistry.missingSnapshots(module.discovered.manifest.id); const missingSnapshots = realtimeRegistry.missingSnapshots(module.discovered.manifest.id);
if (missingSnapshots.length > 0) { if (missingSnapshots.length > 0) {
@@ -831,7 +873,7 @@ async function startModules(
*/ */
export async function startDiscoveredModuleRuntime( export async function startDiscoveredModuleRuntime(
discoveredModules: readonly DiscoveredModule[], discoveredModules: readonly DiscoveredModule[],
services: ModuleRuntimeServices, services: ModuleRuntimeServicesSource,
timeouts: ModuleRuntimeCompositionOptions = {}, timeouts: ModuleRuntimeCompositionOptions = {},
): Promise<StartedModuleRuntime> { ): Promise<StartedModuleRuntime> {
const modules = await loadRuntimeDefinitions(discoveredModules); const modules = await loadRuntimeDefinitions(discoveredModules);
+132 -12
View File
@@ -1,12 +1,16 @@
import { pathToFileURL } from "node:url"; import { pathToFileURL } from "node:url";
import { import {
type ModuleId, type ModuleId,
type ModuleSchemaDefinition, type ModuleSchemaMetadataDefinition,
moduleTableLocalNameSchema, moduleTableLocalNameSchema,
moduleTablePrefix, moduleTablePrefix,
parseModuleSchemaDefinition, parseModuleSchemaMetadataDefinition,
physicalModuleTableNameSchema, physicalModuleTableNameSchema,
} from "@ekklesia/contracts"; } from "@ekklesia/contracts";
import {
type ModuleSchemaDefinition,
parseModuleSchemaDefinition,
} from "./legacy-schema-definition.js";
import { is } from "drizzle-orm"; import { is } from "drizzle-orm";
import { type AnyPgTable, getTableConfig, PgColumn, PgTable } from "drizzle-orm/pg-core"; import { type AnyPgTable, getTableConfig, PgColumn, PgTable } from "drizzle-orm/pg-core";
import { import {
@@ -40,7 +44,9 @@ export interface DiscoveredModuleTable {
readonly exportName: string; readonly exportName: string;
readonly moduleId: ModuleId; readonly moduleId: ModuleId;
readonly name: string; readonly name: string;
readonly table: AnyPgTable; /** Present only for a temporary legacy-facade module. ABI-v1 schema discovery publishes no ORM
* object and contributes nothing to the legacy aggregate below. */
readonly table?: AnyPgTable;
} }
export interface DiscoveredModuleSchema { export interface DiscoveredModuleSchema {
@@ -55,21 +61,40 @@ export interface ModuleSchemaAggregate {
readonly tables: readonly DiscoveredModuleTable[]; readonly tables: readonly DiscoveredModuleTable[];
} }
interface LoadedModuleSchema { interface LoadedLegacyModuleSchema {
readonly definition: ModuleSchemaDefinition; readonly definition: ModuleSchemaDefinition;
readonly discovered: DiscoveredModule; readonly discovered: DiscoveredModule;
readonly mode: "legacy";
} }
interface LoadedAbiModuleSchema {
readonly definition: ModuleSchemaMetadataDefinition;
readonly discovered: DiscoveredModule;
readonly mode: "abi-v1";
}
type LoadedModuleSchema = LoadedLegacyModuleSchema | LoadedAbiModuleSchema;
interface InspectedModuleSchema { interface InspectedModuleSchema {
readonly discovered: DiscoveredModule; readonly discovered: DiscoveredModule;
readonly tables: ModuleTableCandidate[]; readonly tables: ModuleTableCandidate[];
} }
interface ModuleTableCandidate extends DiscoveredModuleTable { interface LegacyModuleTableCandidate extends DiscoveredModuleTable {
readonly mode: "legacy";
readonly foreignKeys: ReturnType<typeof getTableConfig>["foreignKeys"]; readonly foreignKeys: ReturnType<typeof getTableConfig>["foreignKeys"];
readonly path: string; readonly path: string;
readonly table: AnyPgTable;
} }
interface AbiModuleTableCandidate extends DiscoveredModuleTable {
readonly mode: "abi-v1";
readonly foreignKeys: ModuleSchemaMetadataDefinition["tables"][number]["foreignKeys"];
readonly path: string;
}
type ModuleTableCandidate = LegacyModuleTableCandidate | AbiModuleTableCandidate;
const drizzleTableIsAlias = Symbol.for("drizzle:IsAlias"); const drizzleTableIsAlias = Symbol.for("drizzle:IsAlias");
export class ModuleSchemaDiscoveryError extends Error { export class ModuleSchemaDiscoveryError extends Error {
@@ -156,9 +181,13 @@ async function loadSchemaDefinitions(discoveredModules: readonly DiscoveredModul
continue; continue;
} }
let definition: ModuleSchemaDefinition; let definition: ModuleSchemaDefinition | ModuleSchemaMetadataDefinition;
const mode = discovered.manifest.database?.abi === 1 ? "abi-v1" : "legacy";
try { try {
definition = parseModuleSchemaDefinition(defaultExport(moduleNamespace)); definition =
mode === "abi-v1"
? parseModuleSchemaMetadataDefinition(defaultExport(moduleNamespace))
: parseModuleSchemaDefinition(defaultExport(moduleNamespace));
} catch { } catch {
issues.push( issues.push(
issue( issue(
@@ -182,7 +211,11 @@ async function loadSchemaDefinitions(discoveredModules: readonly DiscoveredModul
continue; continue;
} }
loaded.push({ definition, discovered }); loaded.push(
mode === "abi-v1"
? { definition: definition as ModuleSchemaMetadataDefinition, discovered, mode }
: { definition: definition as ModuleSchemaDefinition, discovered, mode },
);
} }
return { issues, loaded }; return { issues, loaded };
@@ -197,6 +230,58 @@ function inspectTables(
for (const loaded of loadedSchemas) { for (const loaded of loadedSchemas) {
const moduleId = loaded.discovered.manifest.id; const moduleId = loaded.discovered.manifest.id;
if (loaded.mode === "abi-v1") {
const candidates: AbiModuleTableCandidate[] = [];
loaded.definition.tables.forEach((table, index) => {
const path = `tables.${index}`;
const candidate: AbiModuleTableCandidate = {
exportName: table.name,
foreignKeys: table.foreignKeys,
mode: "abi-v1",
moduleId,
name: table.name,
path,
};
const tablePrefix = moduleTablePrefix(moduleId);
if (!table.name.startsWith(tablePrefix)) {
issues.push(
issue(
"MODULE_SCHEMA_TABLE_NAMESPACE_INVALID",
moduleId,
`Table ${table.name} is not namespaced for module ${moduleId}.`,
{ path, tableName: table.name },
),
);
} else if (
!moduleTableLocalNameSchema.safeParse(table.name.slice(tablePrefix.length)).success
) {
issues.push(
issue(
"MODULE_SCHEMA_TABLE_NAME_INVALID",
moduleId,
`Module ${moduleId} has an invalid local table name.`,
{ path },
),
);
}
const existing = firstTableByName.get(table.name);
if (existing) {
issues.push(
issue(
"MODULE_SCHEMA_TABLE_DUPLICATE",
moduleId,
`Table ${table.name} is declared more than once.`,
{ path, tableName: table.name },
),
);
} else {
firstTableByName.set(table.name, candidate);
}
candidates.push(candidate);
});
inspectedModules.push({ discovered: loaded.discovered, tables: candidates });
continue;
}
const seenTables = new Set<AnyPgTable>(); const seenTables = new Set<AnyPgTable>();
const candidates: ModuleTableCandidate[] = []; const candidates: ModuleTableCandidate[] = [];
const entries = Object.entries(loaded.definition.tables).sort(([left], [right]) => const entries = Object.entries(loaded.definition.tables).sort(([left], [right]) =>
@@ -293,6 +378,7 @@ function inspectTables(
const candidate: ModuleTableCandidate = { const candidate: ModuleTableCandidate = {
exportName, exportName,
foreignKeys: config.foreignKeys, foreignKeys: config.foreignKeys,
mode: "legacy",
moduleId, moduleId,
name: config.name, name: config.name,
path, path,
@@ -321,8 +407,8 @@ function inspectTables(
} }
function validForeignKeyTarget( function validForeignKeyTarget(
foreignKey: ModuleTableCandidate["foreignKeys"][number], foreignKey: LegacyModuleTableCandidate["foreignKeys"][number],
candidate: ModuleTableCandidate, candidate: LegacyModuleTableCandidate,
): AnyPgTable | undefined { ): AnyPgTable | undefined {
try { try {
const reference = foreignKey.reference(); const reference = foreignKey.reference();
@@ -356,14 +442,42 @@ function inspectForeignKeys(
const ownerByTable = new Map<AnyPgTable, ModuleId>(); const ownerByTable = new Map<AnyPgTable, ModuleId>();
for (const inspected of inspectedModules) { for (const inspected of inspectedModules) {
for (const candidate of inspected.tables) { for (const candidate of inspected.tables) {
if (candidate.mode === "legacy") {
ownerByTable.set(candidate.table, candidate.moduleId); ownerByTable.set(candidate.table, candidate.moduleId);
} }
} }
}
for (const inspected of inspectedModules) { for (const inspected of inspectedModules) {
const moduleId = inspected.discovered.manifest.id; const moduleId = inspected.discovered.manifest.id;
const ownedTables = new Set(inspected.tables.map((candidate) => candidate.table)); const ownedTables = new Set(inspected.tables.map((candidate) => candidate.table));
for (const candidate of inspected.tables) { for (const candidate of inspected.tables) {
if (candidate.mode === "abi-v1") {
const ownedNames = new Set(inspected.tables.map((table) => table.name));
candidate.foreignKeys.forEach((foreignKey, foreignKeyIndex) => {
const path = `${candidate.path}.foreignKeys.${foreignKeyIndex}`;
if (!foreignKey.table.startsWith(moduleTablePrefix(moduleId))) {
issues.push(
issue(
"MODULE_SCHEMA_CROSS_MODULE_FOREIGN_KEY",
moduleId,
`Table ${candidate.name} has a foreign key outside module ${moduleId}.`,
{ path, tableName: candidate.name },
),
);
} else if (!ownedNames.has(foreignKey.table)) {
issues.push(
issue(
"MODULE_SCHEMA_FOREIGN_KEY_TARGET_MISSING",
moduleId,
`Table ${candidate.name} references a table not exported by module ${moduleId}.`,
{ path, tableName: candidate.name },
),
);
}
});
continue;
}
candidate.foreignKeys.forEach((foreignKey, foreignKeyIndex) => { candidate.foreignKeys.forEach((foreignKey, foreignKeyIndex) => {
const path = `${candidate.path}.foreignKeys.${foreignKeyIndex}`; const path = `${candidate.path}.foreignKeys.${foreignKeyIndex}`;
const foreignTable = validForeignKeyTarget(foreignKey, candidate); const foreignTable = validForeignKeyTarget(foreignKey, candidate);
@@ -446,7 +560,9 @@ function publishAggregate(
moduleId: inspected.discovered.manifest.id, moduleId: inspected.discovered.manifest.id,
tables: Object.freeze( tables: Object.freeze(
inspected.tables inspected.tables
.map(({ foreignKeys: _foreignKeys, path: _path, ...table }) => Object.freeze(table)) .map(({ foreignKeys: _foreignKeys, mode: _mode, path: _path, ...table }) =>
Object.freeze(table),
)
.sort((left, right) => compareText(left.exportName, right.exportName)), .sort((left, right) => compareText(left.exportName, right.exportName)),
), ),
}), }),
@@ -458,7 +574,11 @@ function publishAggregate(
.sort((left, right) => compareText(left.name, right.name)), .sort((left, right) => compareText(left.name, right.name)),
); );
const drizzleSchema = Object.freeze( const drizzleSchema = Object.freeze(
Object.fromEntries(tables.map((table) => [table.name, table.table] as const)), Object.fromEntries(
tables.flatMap((table) =>
table.table === undefined ? [] : [[table.name, table.table] as const],
),
),
); );
return Object.freeze({ discoveredModules, drizzleSchema, modules, tables }); return Object.freeze({ discoveredModules, drizzleSchema, modules, tables });
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
import { IMPORT_SAFETY_TEST_TIMEOUT_MS } from "./support/import-safety.js";
const poolConstructor = vi.hoisted(() => vi.fn()); const poolConstructor = vi.hoisted(() => vi.fn());
@@ -7,7 +8,9 @@ vi.mock("pg", () => ({ Pool: poolConstructor }));
describe("bootstrap-platform-owner CLI import safety", () => { describe("bootstrap-platform-owner CLI import safety", () => {
const originalEnv = { ...process.env }; const originalEnv = { ...process.env };
it("does not read DATABASE_URL, connect to PostgreSQL, or run bootstrap merely by importing the module", async () => { it(
"does not read DATABASE_URL, connect to PostgreSQL, or run bootstrap merely by importing the module",
async () => {
delete process.env.DATABASE_URL; delete process.env.DATABASE_URL;
// Under Vitest, process.argv[1] is never this file's own path, so isDirectExecution() is // Under Vitest, process.argv[1] is never this file's own path, so isDirectExecution() is
@@ -18,5 +21,7 @@ describe("bootstrap-platform-owner CLI import safety", () => {
expect(poolConstructor).not.toHaveBeenCalled(); expect(poolConstructor).not.toHaveBeenCalled();
process.env = originalEnv; process.env = originalEnv;
}); },
IMPORT_SAFETY_TEST_TIMEOUT_MS,
);
}); });
+7 -2
View File
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
import { IMPORT_SAFETY_TEST_TIMEOUT_MS } from "./support/import-safety.js";
const poolConstructor = vi.hoisted(() => vi.fn()); const poolConstructor = vi.hoisted(() => vi.fn());
@@ -7,7 +8,9 @@ vi.mock("pg", () => ({ Pool: poolConstructor }));
describe("create-initial-owner CLI import safety", () => { describe("create-initial-owner CLI import safety", () => {
const originalEnv = { ...process.env }; const originalEnv = { ...process.env };
it("does not read DATABASE_URL, connect to PostgreSQL, or create anything merely by importing the module", async () => { it(
"does not read DATABASE_URL, connect to PostgreSQL, or create anything merely by importing the module",
async () => {
delete process.env.DATABASE_URL; delete process.env.DATABASE_URL;
// Under Vitest, process.argv[1] is never this file's own path, so isDirectExecution() is false // Under Vitest, process.argv[1] is never this file's own path, so isDirectExecution() is false
@@ -18,7 +21,9 @@ describe("create-initial-owner CLI import safety", () => {
expect(poolConstructor).not.toHaveBeenCalled(); expect(poolConstructor).not.toHaveBeenCalled();
process.env = originalEnv; process.env = originalEnv;
}); },
IMPORT_SAFETY_TEST_TIMEOUT_MS,
);
it("reads no environment variable for the password", async () => { it("reads no environment variable for the password", async () => {
// The password is prompted for or read from standard input; it is deliberately never taken from // The password is prompted for or read from standard input; it is deliberately never taken from
+1 -1
View File
@@ -91,7 +91,7 @@ async function createModule(
writeFile( writeFile(
path.join(moduleDirectory, "ekklesia.module.json"), path.join(moduleDirectory, "ekklesia.module.json"),
JSON.stringify({ JSON.stringify({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
+1 -1
View File
@@ -59,7 +59,7 @@ async function createModule(modulesDirectory: string, fixture: ModuleFixture): P
: {}), : {}),
entrypoints: { server: "./dist/server/index.js", ui: "./dist/ui/index.js" }, entrypoints: { server: "./dist/server/index.js", ui: "./dist/ui/index.js" },
id: fixture.id, id: fixture.id,
manifestVersion: 7, manifestVersion: 8,
name: fixture.name, name: fixture.name,
version: "1.0.0", version: "1.0.0",
}), }),
+1 -1
View File
@@ -83,7 +83,7 @@ function discoveredModule(id: string, overrides: Record<string, unknown> = {}):
}, },
entrypoints: { server: "./dist/server.js" }, entrypoints: { server: "./dist/server.js" },
id, id,
manifestVersion: 7, manifestVersion: 8,
name: `${id} module`, name: `${id} module`,
permissions: [], permissions: [],
storage: { buckets: [] }, storage: { buckets: [] },
+7 -2
View File
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
import { IMPORT_SAFETY_TEST_TIMEOUT_MS } from "./support/import-safety.js";
const discoverModules = vi.fn(); const discoverModules = vi.fn();
const discoverModuleSchemas = vi.fn(); const discoverModuleSchemas = vi.fn();
@@ -22,7 +23,9 @@ vi.mock("../src/migrations/index.js", async (importOriginal) => ({
})); }));
describe("Doctor import safety", () => { describe("Doctor import safety", () => {
it("does not discover, connect, plan, or print when imported", async () => { it(
"does not discover, connect, plan, or print when imported",
async () => {
const log = vi.spyOn(console, "log").mockImplementation(() => undefined); const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
const error = vi.spyOn(console, "error").mockImplementation(() => undefined); const error = vi.spyOn(console, "error").mockImplementation(() => undefined);
@@ -41,5 +44,7 @@ describe("Doctor import safety", () => {
log.mockRestore(); log.mockRestore();
error.mockRestore(); error.mockRestore();
}); },
IMPORT_SAFETY_TEST_TIMEOUT_MS,
);
}); });
+10 -4
View File
@@ -1,8 +1,8 @@
import { type ModuleManifest, parsePermissionId } from "@ekklesia/contracts";
import { mkdtemp, rm } from "node:fs/promises"; import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import { type ModuleManifest, parsePermissionId } from "@ekklesia/contracts";
import { afterEach, describe, expect, it, vi } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
import { createPermissionRegistry, PermissionRegistryError } from "../src/authorization/index.js"; import { createPermissionRegistry, PermissionRegistryError } from "../src/authorization/index.js";
import { import {
@@ -32,7 +32,11 @@ const checksumA = "a".repeat(64);
const checksumB = "b".repeat(64); const checksumB = "b".repeat(64);
const checksumC = "c".repeat(64); const checksumC = "c".repeat(64);
function discoveredModule(id: string, version = "0.1.0"): DiscoveredModule { function discoveredModule(
id: string,
version = "0.1.0",
database?: { readonly abi: 1 },
): DiscoveredModule {
return { return {
contributions: [], contributions: [],
directory: `/unpublished/${id}`, directory: `/unpublished/${id}`,
@@ -41,13 +45,14 @@ function discoveredModule(id: string, version = "0.1.0"): DiscoveredModule {
capabilities: [], capabilities: [],
compatibility: { moduleSdk: "^0.1.0", platform: "^0.1.0" }, compatibility: { moduleSdk: "^0.1.0", platform: "^0.1.0" },
configuration: [], configuration: [],
...(database ? { database } : {}),
dependencies: { dependencies: {
capabilities: { optional: {}, required: {} }, capabilities: { optional: {}, required: {} },
modules: { optional: {}, required: {} }, modules: { optional: {}, required: {} },
}, },
entrypoints: { server: "./dist/server.js" }, entrypoints: { server: "./dist/server.js" },
id, id,
manifestVersion: 7, manifestVersion: 8,
name: `${id} module`, name: `${id} module`,
permissions: [], permissions: [],
storage: { buckets: [] }, storage: { buckets: [] },
@@ -294,7 +299,7 @@ describe("Ekklesia Doctor outbound email reporting", () => {
describe("Ekklesia Doctor diagnostics", () => { describe("Ekklesia Doctor diagnostics", () => {
it("publishes a healthy deterministic static report without database configuration", async () => { it("publishes a healthy deterministic static report without database configuration", async () => {
const people = discoveredModule("people"); const people = discoveredModule("people");
const calendar = discoveredModule("calendar", "0.2.0"); const calendar = discoveredModule("calendar", "0.2.0", { abi: 1 });
const inventory = migrationAggregate( const inventory = migrationAggregate(
[migration("people", "0000_initial", checksumA)], [migration("people", "0000_initial", checksumA)],
[people, calendar], [people, calendar],
@@ -327,6 +332,7 @@ describe("Ekklesia Doctor diagnostics", () => {
]); ]);
expect(check(report, "modules.discovery").details).toEqual(["people 0.1.0", "calendar 0.2.0"]); expect(check(report, "modules.discovery").details).toEqual(["people 0.1.0", "calendar 0.2.0"]);
expect(check(report, "modules.dependencies").details).toEqual(["Order: people → calendar"]); expect(check(report, "modules.dependencies").details).toEqual(["Order: people → calendar"]);
expect(check(report, "schemas.discovery")).toMatchObject({ status: "pass" });
expect(check(report, "modules.permissions")).toMatchObject({ expect(check(report, "modules.permissions")).toMatchObject({
details: ["0 permissions registered"], details: ["0 permissions registered"],
status: "pass", status: "pass",
@@ -1,12 +1,12 @@
{ {
"manifestVersion": 7, "manifestVersion": 8,
"id": "db-facade", "id": "db-facade",
"name": "Database Facade Integration Test Module", "name": "Database Facade Integration Test Module",
"description": "Test-only installed module fixture proving ModuleDatabase against real PostgreSQL. Never discovered by production startup, Doctor, or normal migration aggregation — only apps/api/tests/module-database.integration.ts points discovery at it explicitly.", "description": "Test-only installed module fixture proving ModuleDatabase against real PostgreSQL. Never discovered by production startup, Doctor, or normal migration aggregation — only apps/api/tests/module-database.integration.ts points discovery at it explicitly.",
"version": "0.1.0", "version": "0.1.0",
"compatibility": { "compatibility": {
"platform": "^0.1.0", "platform": "^0.2.0",
"moduleSdk": "^0.1.0" "moduleSdk": "^0.2.0"
}, },
"permissions": [ "permissions": [
{ {
@@ -0,0 +1,34 @@
import { alias, getTableConfig, integer, pgTable } from "drizzle-orm/pg-core";
import { describe, expect, it } from "vitest";
import { parseModuleSchemaDefinition } from "../src/modules/legacy-schema-definition.js";
describe("the legacy module schema definition", () => {
it("normalizes and freezes a typed schema definition without freezing its tables", () => {
const records = pgTable("example_records", { id: integer().primaryKey() });
const definition = parseModuleSchemaDefinition({
moduleId: "example",
tables: { records },
});
expect(definition.tables.records).toBe(records);
expect(getTableConfig(records).name).toBe("example_records");
expect(Object.isFrozen(definition)).toBe(true);
expect(Object.isFrozen(definition.tables)).toBe(true);
expect(Object.isFrozen(records)).toBe(false);
});
it("rejects malformed, empty, unknown, and non-PostgreSQL table definitions", () => {
const records = pgTable("example_records", { id: integer() });
const disguisedRecords = alias(records, "example_disguised_records");
expect(() => parseModuleSchemaDefinition({ moduleId: "example", tables: {} })).toThrow();
expect(() =>
parseModuleSchemaDefinition({ moduleId: "example", tables: { records: {} } }),
).toThrow();
expect(() =>
parseModuleSchemaDefinition({ moduleId: "example", tables: { records }, extra: true }),
).toThrow();
expect(() =>
parseModuleSchemaDefinition({ moduleId: "example", tables: { disguisedRecords } }),
).toThrow();
});
});
@@ -17,7 +17,7 @@ function fakeModule(
} = {}, } = {},
): DiscoveredModule { ): DiscoveredModule {
const manifest = parseModuleManifest({ const manifest = parseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "1.0.0", version: "1.0.0",
@@ -194,7 +194,7 @@ afterAll(async () => {
function manifestWith(configuration: readonly Record<string, unknown>[], id = "announcements") { function manifestWith(configuration: readonly Record<string, unknown>[], id = "announcements") {
return parseModuleManifest({ return parseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "1.0.0", version: "1.0.0",
+8 -8
View File
@@ -21,7 +21,7 @@ function manifestWith(
id = "announcements", id = "announcements",
) { ) {
return parseModuleManifest({ return parseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "1.0.0", version: "1.0.0",
@@ -92,7 +92,7 @@ describe("module configuration declarations", () => {
it("rejects two declarations of the same key, so an ordinary key and a secret can never collide", () => { it("rejects two declarations of the same key, so an ordinary key and a secret can never collide", () => {
const result = safeParseModuleManifest({ const result = safeParseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id: "announcements", id: "announcements",
name: "announcements module", name: "announcements module",
version: "1.0.0", version: "1.0.0",
@@ -114,7 +114,7 @@ describe("module configuration declarations", () => {
it("rejects a default on a secret, because a checked-in default credential is a leaked one", () => { it("rejects a default on a secret, because a checked-in default credential is a leaked one", () => {
const result = safeParseModuleManifest({ const result = safeParseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id: "announcements", id: "announcements",
name: "announcements module", name: "announcements module",
version: "1.0.0", version: "1.0.0",
@@ -130,7 +130,7 @@ describe("module configuration declarations", () => {
it("rejects a key that is both required and defaulted, which states an intent nothing can honour", () => { it("rejects a key that is both required and defaulted, which states an intent nothing can honour", () => {
const result = safeParseModuleManifest({ const result = safeParseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id: "announcements", id: "announcements",
name: "announcements module", name: "announcements module",
version: "1.0.0", version: "1.0.0",
@@ -169,7 +169,7 @@ describe("module configuration declarations", () => {
], ],
])("rejects %s", (_label, declaration) => { ])("rejects %s", (_label, declaration) => {
const result = safeParseModuleManifest({ const result = safeParseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id: "announcements", id: "announcements",
name: "announcements module", name: "announcements module",
version: "1.0.0", version: "1.0.0",
@@ -189,7 +189,7 @@ describe("module configuration declarations", () => {
"valueOf", "valueOf",
])("rejects the reserved object property name %s as a configuration key", (key) => { ])("rejects the reserved object property name %s as a configuration key", (key) => {
const result = safeParseModuleManifest({ const result = safeParseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id: "announcements", id: "announcements",
name: "announcements module", name: "announcements module",
version: "1.0.0", version: "1.0.0",
@@ -210,7 +210,7 @@ describe("module configuration declarations", () => {
"", "",
])("rejects the malformed configuration key %s", (key) => { ])("rejects the malformed configuration key %s", (key) => {
const result = safeParseModuleManifest({ const result = safeParseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id: "announcements", id: "announcements",
name: "announcements module", name: "announcements module",
version: "1.0.0", version: "1.0.0",
@@ -591,7 +591,7 @@ describe("configuration over a real discovered inventory", () => {
writeFile( writeFile(
path.join(moduleDirectory, "ekklesia.module.json"), path.join(moduleDirectory, "ekklesia.module.json"),
JSON.stringify({ JSON.stringify({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "1.0.0", version: "1.0.0",
@@ -1,8 +1,8 @@
import { integer, pgTable, text } from "drizzle-orm/pg-core"; import { integer, pgTable, text } from "drizzle-orm/pg-core";
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import type { ModuleDatabase, ModuleRuntimeServices } from "../src/index.js"; import type { LegacyModuleRuntimeServices, ModuleDatabase } from "../src/modules/database.js";
const testTable = pgTable("contracts_module_database_test", { const testTable = pgTable("core_module_database_type_test", {
id: integer("id").primaryKey(), id: integer("id").primaryKey(),
name: text("name").notNull(), name: text("name").notNull(),
}); });
@@ -68,16 +68,17 @@ function typeOnlyExclusions(database: ModuleDatabase): void {
} }
void typeOnlyExclusions; void typeOnlyExclusions;
/** Never invoked — proves `ModuleRuntimeServices` has exactly one field, `database`, typed as /** Never invoked — proves a legacy module's `ModuleRuntimeServices` has exactly one field,
* `ModuleDatabase`, with no storage/jobs/configuration/secrets/authorization field this phase. */ * `database`, typed as `ModuleDatabase`, with no storage/jobs/configuration/secrets/authorization
function typeOnlyServicesShape(services: ModuleRuntimeServices): void { * field this phase. */
function typeOnlyServicesShape(services: LegacyModuleRuntimeServices): void {
const database: ModuleDatabase = services.database; const database: ModuleDatabase = services.database;
void database; void database;
// @ts-expect-error `storage` does not exist on `ModuleRuntimeServices` yet. // @ts-expect-error `storage` does not exist on the services yet.
void services.storage; void services.storage;
// @ts-expect-error `jobs` does not exist on `ModuleRuntimeServices` yet. // @ts-expect-error `jobs` does not exist on the services yet.
void services.jobs; void services.jobs;
// @ts-expect-error `authorization` does not exist on `ModuleRuntimeServices` yet. // @ts-expect-error `authorization` does not exist on the services yet.
void services.authorization; void services.authorization;
} }
void typeOnlyServicesShape; void typeOnlyServicesShape;
+1 -1
View File
@@ -34,7 +34,7 @@ async function createModulesDirectory(): Promise<string> {
function manifestFor(id: string): Record<string, unknown> { function manifestFor(id: string): Record<string, unknown> {
return { return {
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
+7 -2
View File
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
import { IMPORT_SAFETY_TEST_TIMEOUT_MS } from "./support/import-safety.js";
const readdir = vi.fn(); const readdir = vi.fn();
const readFile = vi.fn(); const readFile = vi.fn();
@@ -14,7 +15,9 @@ vi.mock("node:fs/promises", async (importOriginal) => ({
})); }));
describe("module HTTP contract and runtime import safety", () => { describe("module HTTP contract and runtime import safety", () => {
it("performs no filesystem I/O merely by importing the module runtime or the module-http contract", async () => { it(
"performs no filesystem I/O merely by importing the module runtime or the module-http contract",
async () => {
await import("../src/modules/index.js"); await import("../src/modules/index.js");
await import("@ekklesia/contracts"); await import("@ekklesia/contracts");
@@ -22,5 +25,7 @@ describe("module HTTP contract and runtime import safety", () => {
expect(readFile).not.toHaveBeenCalled(); expect(readFile).not.toHaveBeenCalled();
expect(realpath).not.toHaveBeenCalled(); expect(realpath).not.toHaveBeenCalled();
expect(stat).not.toHaveBeenCalled(); expect(stat).not.toHaveBeenCalled();
}); },
IMPORT_SAFETY_TEST_TIMEOUT_MS,
);
}); });
@@ -200,7 +200,7 @@ afterAll(async () => {
* by eligibility resolution. */ * by eligibility resolution. */
function fakeModule(id: string, dependencies?: Record<string, unknown>): DiscoveredModule { function fakeModule(id: string, dependencies?: Record<string, unknown>): DiscoveredModule {
const manifest = parseModuleManifest({ const manifest = parseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "1.0.0", version: "1.0.0",
+2 -2
View File
@@ -22,7 +22,7 @@ function fakeModule(
} = {}, } = {},
): DiscoveredModule { ): DiscoveredModule {
const manifest = parseModuleManifest({ const manifest = parseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
@@ -344,7 +344,7 @@ describe("resolveModuleEligibility — over a real discovered inventory", () =>
writeFile( writeFile(
path.join(moduleDirectory, "ekklesia.module.json"), path.join(moduleDirectory, "ekklesia.module.json"),
JSON.stringify({ JSON.stringify({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
@@ -35,9 +35,9 @@ async function createModulesDirectory(): Promise<string> {
function discoveryOptions(modulesDirectory: string) { function discoveryOptions(modulesDirectory: string) {
return { return {
moduleSdkVersion: "0.1.0", moduleSdkVersion: "0.2.0",
modulesDirectory, modulesDirectory,
platformVersion: "0.1.0", platformVersion: "0.2.0",
}; };
} }
+314 -5
View File
@@ -3,8 +3,10 @@ import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
import { afterEach, describe, expect, it } from "vitest"; import { afterEach, describe, expect, it } from "vitest";
import { import {
type ModulePackageVerificationErrorCode, currentModulePackageHost,
type ModulePackageHost,
ModulePackageVerificationError, ModulePackageVerificationError,
type ModulePackageVerificationErrorCode,
verifyModulePackage, verifyModulePackage,
} from "../src/modules/index.js"; } from "../src/modules/index.js";
import { import {
@@ -16,8 +18,8 @@ import {
const platform = { const platform = {
databaseRuntime: { "drizzle-orm": "0.45.2" }, databaseRuntime: { "drizzle-orm": "0.45.2" },
moduleSdkVersion: "0.1.2", moduleSdkVersion: "0.2.0",
platformVersion: "0.1.2", platformVersion: "0.2.0",
} as const; } as const;
const temporaryDirectories: string[] = []; const temporaryDirectories: string[] = [];
@@ -72,13 +74,26 @@ function withEntry(entry: FixtureEntry): PackageFixtureOptions {
return { extraEntries: [entry] }; return { extraEntries: [entry] };
} }
function abiPackage(overrides: PackageFixtureOptions = {}): PackageFixtureOptions {
return {
manifest: (manifest) => ({ ...manifest, database: { abi: 1 } }),
schemaSource: `export default {
moduleId: "example",
tables: [{ name: "example_records", foreignKeys: [] }]
};\n`,
serverSource:
'export default { database: { abi: 1 }, id: "example", version: "0.1.0", register() {} };\n',
...overrides,
};
}
describe("Module Package v1 verification (ADR 0049)", () => { describe("Module Package v1 verification (ADR 0049)", () => {
it("verifies a valid any-target package, its digest, and its module", async () => { it("verifies a valid any-target package, its digest, and its module", async () => {
const { archivePath, sha256: digest } = await archiveFile(); const { archivePath, sha256: digest } = await archiveFile();
const result = await verifyModulePackage({ archivePath, expectedSha256: digest, platform }); const result = await verifyModulePackage({ archivePath, expectedSha256: digest, platform });
expect(result).toEqual({ expect(result).toEqual({
archiveSha256: digest, archiveSha256: digest,
fileCount: 8, fileCount: 9,
moduleId: "example", moduleId: "example",
target: "any", target: "any",
version: "0.1.0", version: "0.1.0",
@@ -91,6 +106,7 @@ describe("Module Package v1 verification (ADR 0049)", () => {
await verifyModulePackage({ archivePath, extractTo: target, platform }); await verifyModulePackage({ archivePath, extractTo: target, platform });
const names = (await readdir(target, { recursive: true })).sort(); const names = (await readdir(target, { recursive: true })).sort();
expect(names).toContain("ekklesia.package.json"); expect(names).toContain("ekklesia.package.json");
expect(names).toContain("LICENSE");
expect(names).toContain("dist/server/index.js"); expect(names).toContain("dist/server/index.js");
expect((await stat(target)).mode & 0o7777).toBe(0o755); expect((await stat(target)).mode & 0o7777).toBe(0o755);
expect((await stat(path.join(target, "dist", "server", "index.js"))).mode & 0o7777).toBe(0o644); expect((await stat(path.join(target, "dist", "server", "index.js"))).mode & 0o7777).toBe(0o644);
@@ -140,6 +156,88 @@ describe("Module Package v1 verification (ADR 0049)", () => {
); );
}); });
it.each([
["a missing license declaration", undefined],
["an empty license declaration", ""],
["UNLICENSED", "UNLICENSED"],
["a malformed SPDX expression", "MIT OR"],
])("fails package metadata with %s", async (_label, license) => {
await rejection(
{
metadata: (metadata) => {
const changed: Record<string, unknown> = { ...metadata, license };
if (license === undefined) {
delete changed.license;
}
return changed;
},
},
"MODULE_PACKAGE_METADATA_INVALID",
);
});
it("fails closed on pre-ADR-0051 metadata", async () => {
await rejection(
{
metadata: (metadata) => {
const old: Record<string, unknown> = { ...metadata };
delete old.license;
return old;
},
},
"MODULE_PACKAGE_METADATA_INVALID",
);
});
it("requires LICENSE at the canonical path in both payload and inventory", async () => {
await rejection(
{ tamper: (files) => void files.delete("LICENSE") },
"MODULE_PACKAGE_FILE_MISSING",
);
await rejection(
{
metadata: (metadata) => ({
...metadata,
files: (metadata.files as { path: string }[]).filter((file) => file.path !== "LICENSE"),
}),
},
"MODULE_PACKAGE_METADATA_INVALID",
);
await rejection(
withEntry({ path: "example/licenses/LICENSE", data: "attacker-chosen" }),
"MODULE_PACKAGE_FILE_UNLISTED",
);
await rejection(
withEntry({ path: "example/COPYING", data: "attacker-chosen" }),
"MODULE_PACKAGE_FILE_UNLISTED",
);
});
it("checks the listed LICENSE bytes, size, and digest", async () => {
await rejection(
{ tamper: (files) => files.set("LICENSE", Buffer.from("attacker-chosen")) },
"MODULE_PACKAGE_FILE_MISMATCH",
);
await rejection(
{
metadata: (metadata) => ({
...metadata,
files: (metadata.files as { path: string; size: number; sha256: string }[]).map((file) =>
file.path === "LICENSE" ? { ...file, size: file.size + 1 } : file,
),
}),
},
"MODULE_PACKAGE_FILE_MISMATCH",
);
});
it("rejects a duplicate LICENSE archive entry", async () => {
await rejection(
withEntry({ path: "example/LICENSE", data: "attacker-chosen" }),
"MODULE_PACKAGE_LAYOUT_INVALID",
);
});
it("fails when the manifest and the package disagree about the version", async () => { it("fails when the manifest and the package disagree about the version", async () => {
await rejection( await rejection(
{ manifest: (manifest) => ({ ...manifest, version: "0.2.0" }) }, { manifest: (manifest) => ({ ...manifest, version: "0.2.0" }) },
@@ -214,13 +312,51 @@ describe("Module Package v1 verification (ADR 0049)", () => {
}); });
}); });
it("verifies ABI-v1 plain schema metadata without comparing Drizzle with Core", async () => {
const { archivePath } = await archiveFile(abiPackage());
await expect(
verifyModulePackage({
archivePath,
platform: { ...platform, databaseRuntime: { "drizzle-orm": "99.0.0" } },
}),
).resolves.toMatchObject({ moduleId: "example" });
});
it("rejects transitional database runtime metadata from an ABI-v1 package", async () => {
await rejection(
abiPackage({
metadata: (metadata) => ({
...metadata,
transitional: { databaseRuntime: { "drizzle-orm": "0.45.2" } },
}),
}),
"MODULE_PACKAGE_DATABASE_RUNTIME_UNEXPECTED",
);
});
it("rejects an unsupported database ABI and malformed ABI-v1 schema metadata", async () => {
await rejection(
abiPackage({ manifest: (manifest) => ({ ...manifest, database: { abi: 2 } }) }),
"MODULE_PACKAGE_MANIFEST_INVALID",
);
const schemaError = await rejection(
abiPackage({
schemaSource:
'export default { moduleId: "example", tables: { records: "attacker-chosen" } };\n',
}),
"MODULE_PACKAGE_ENTRYPOINT_LOAD_FAILED",
);
expect(schemaError.message).not.toContain("attacker-chosen");
});
it("fails a target this platform cannot run", async () => { it("fails a target this platform cannot run", async () => {
await rejection( await rejection(
{ {
metadata: (metadata) => ({ metadata: (metadata) => ({
...metadata, ...metadata,
target: "linux-arm64-musl", target: "linux-arm64-musl",
runtime: { node: ">=20", nodeApi: 9 }, runtime: { libcVersion: ">=1.2.0", node: ">=20", nodeApi: 9 },
}), }),
}, },
"MODULE_PACKAGE_TARGET_INCOMPATIBLE", "MODULE_PACKAGE_TARGET_INCOMPATIBLE",
@@ -359,6 +495,179 @@ describe("Module Package v1 verification (ADR 0049)", () => {
}); });
}); });
describe("native targets (ADR 0049)", () => {
/** The first bytes of a 64-bit little-endian ELF object for `machine` (62 is x86-64). The
* verifier reads only the identification and machine fields. */
function elfHeader(machine = 62): Buffer {
const header = Buffer.alloc(64);
Buffer.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1]).copy(header);
header.writeUInt16LE(3, 16);
header.writeUInt16LE(machine, 18);
return header;
}
const linuxHost = {
arch: "x64",
libc: { family: "glibc", version: "2.41" },
nodeApi: 10,
nodeAbi: "137",
platform: "linux",
} as const;
function nativePackage(
overrides: {
readonly files?: Record<string, Uint8Array | string>;
readonly target?: string;
readonly runtime?: Record<string, unknown>;
} = {},
): PackageFixtureOptions {
return {
files: overrides.files ?? {
"node_modules/native-thing/index.js": "module.exports = {};\n",
"node_modules/native-thing/lib/native-thing.node": elfHeader(),
"node_modules/native-thing/package.json": '{"name":"native-thing","version":"1.0.0"}\n',
},
metadata: (metadata) => ({
...metadata,
runtime: overrides.runtime ?? {
libcVersion: ">=2.28.0",
node: ">=20",
nodeApi: 9,
},
target: overrides.target ?? "linux-x64-glibc",
}),
};
}
async function verifyOn(
options: PackageFixtureOptions,
host: ModulePackageHost,
): Promise<unknown> {
const { archivePath } = await archiveFile(options);
return verifyModulePackage({ archivePath, platform: { ...platform, host } });
}
async function refusedOn(
options: PackageFixtureOptions,
host: ModulePackageHost,
code: ModulePackageVerificationErrorCode,
): Promise<void> {
await expect(verifyOn(options, host)).rejects.toMatchObject({ code });
}
it("accepts linux-x64-glibc on a matching host, native node_modules and addon included", async () => {
await expect(verifyOn(nativePackage(), linuxHost)).resolves.toMatchObject({
moduleId: "example",
target: "linux-x64-glibc",
});
});
it("refuses another operating system, CPU, or C library family", async () => {
await refusedOn(
nativePackage(),
{ ...linuxHost, platform: "darwin" },
"MODULE_PACKAGE_TARGET_INCOMPATIBLE",
);
await refusedOn(
nativePackage(),
{ ...linuxHost, arch: "arm64" },
"MODULE_PACKAGE_TARGET_INCOMPATIBLE",
);
// musl reports no glibc version, so the host cannot be proven glibc.
const { libc: _libc, ...musl } = linuxHost;
await refusedOn(nativePackage(), musl, "MODULE_PACKAGE_TARGET_INCOMPATIBLE");
});
it("refuses a target this platform does not implement", async () => {
await refusedOn(
nativePackage({ target: "linux-arm64-glibc" }),
{ ...linuxHost, arch: "arm64" },
"MODULE_PACKAGE_TARGET_INCOMPATIBLE",
);
});
it("refuses a C library older than the package needs", async () => {
await refusedOn(
nativePackage(),
{ ...linuxHost, libc: { family: "glibc", version: "2.17" } },
"MODULE_PACKAGE_LIBC_INCOMPATIBLE",
);
await expect(
verifyOn(nativePackage(), { ...linuxHost, libc: { family: "glibc", version: "2.28" } }),
).resolves.toMatchObject({ target: "linux-x64-glibc" });
});
it("refuses a Node-API version or Node.js ABI the host does not provide", async () => {
await refusedOn(
nativePackage(),
{ ...linuxHost, nodeApi: 8 },
"MODULE_PACKAGE_NODE_API_INCOMPATIBLE",
);
const { nodeApi: _nodeApi, ...unknownApi } = linuxHost;
await refusedOn(nativePackage(), unknownApi, "MODULE_PACKAGE_NODE_API_INCOMPATIBLE");
await refusedOn(
nativePackage({ runtime: { libcVersion: ">=2.28.0", node: ">=20", nodeAbi: "115" } }),
linuxHost,
"MODULE_PACKAGE_NODE_API_INCOMPATIBLE",
);
});
it("refuses a native file built for another machine, or an addon that is not one", async () => {
await refusedOn(
nativePackage({
files: { "node_modules/native-thing/lib/native-thing.node": elfHeader(183) },
}),
linuxHost,
"MODULE_PACKAGE_NATIVE_FILE_INCOMPATIBLE",
);
await refusedOn(
nativePackage({
files: { "node_modules/native-thing/lib/libthing.so": elfHeader(183) },
}),
linuxHost,
"MODULE_PACKAGE_NATIVE_FILE_INCOMPATIBLE",
);
await refusedOn(
nativePackage({
files: { "node_modules/native-thing/lib/native-thing.node": "not an ELF object" },
}),
linuxHost,
"MODULE_PACKAGE_NATIVE_FILE_INCOMPATIBLE",
);
});
it("requires a native package to state its Node.js interface and, on Linux, its C library", async () => {
await rejection(
nativePackage({ runtime: { libcVersion: ">=2.28.0", node: ">=20" } }),
"MODULE_PACKAGE_METADATA_INVALID",
);
await rejection(
nativePackage({ runtime: { node: ">=20", nodeApi: 9 } }),
"MODULE_PACKAGE_METADATA_INVALID",
);
});
it("keeps any-target packages free of node_modules, addons, and ELF objects", async () => {
await rejection(
{ files: { "node_modules/thing/index.js": "module.exports = {};\n" } },
"MODULE_PACKAGE_NATIVE_FILE",
);
await rejection({ files: { "dist/thing.node": elfHeader() } }, "MODULE_PACKAGE_NATIVE_FILE");
await rejection({ files: { "dist/libthing.so": elfHeader() } }, "MODULE_PACKAGE_NATIVE_FILE");
});
it("establishes this host's facts from Node.js alone", () => {
const host = currentModulePackageHost();
expect(host.platform).toBe(process.platform);
expect(host.arch).toBe(process.arch);
expect(host.nodeApi).toBe(Number(process.versions.napi));
if (process.platform === "linux") {
const report = process.report.getReport() as { header?: { glibcVersionRuntime?: string } };
expect(host.libc?.version).toBe(report.header?.glibcVersionRuntime);
}
});
});
it("fails an archive without package metadata", async () => { it("fails an archive without package metadata", async () => {
const fixture = await modulePackageFixture(); const fixture = await modulePackageFixture();
const { gunzipSync, gzipSync } = await import("node:zlib"); const { gunzipSync, gzipSync } = await import("node:zlib");
+1 -1
View File
@@ -28,7 +28,7 @@ interface PermissionInput {
* is read by `composePlatformPermissionRegistry`; the rest exist only to satisfy the type. */ * is read by `composePlatformPermissionRegistry`; the rest exist only to satisfy the type. */
function fakeModule(id: string, permissions: readonly PermissionInput[] = []): DiscoveredModule { function fakeModule(id: string, permissions: readonly PermissionInput[] = []): DiscoveredModule {
const manifest = parseModuleManifest({ const manifest = parseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
+4 -7
View File
@@ -1,11 +1,8 @@
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
import type { import type { ModuleRealtimePublisher } from "@ekklesia/contracts";
ModuleDatabase, import type { LegacyModuleRuntimeServices, ModuleDatabase } from "../src/modules/database.js";
ModuleRealtimePublisher,
ModuleRuntimeServices,
} from "@ekklesia/contracts";
import { afterEach, describe, expect, it } from "vitest"; import { afterEach, describe, expect, it } from "vitest";
import { ModuleRuntimeError, startModuleRuntime } from "../src/modules/runtime.js"; import { ModuleRuntimeError, startModuleRuntime } from "../src/modules/runtime.js";
@@ -22,7 +19,7 @@ afterEach(async () => {
); );
}); });
function fakeServices(): ModuleRuntimeServices { function fakeServices(): LegacyModuleRuntimeServices {
return Object.freeze({ database: Object.freeze({}) as ModuleDatabase }); return Object.freeze({ database: Object.freeze({}) as ModuleDatabase });
} }
@@ -31,7 +28,7 @@ function manifest(
permissions: readonly Record<string, string>[] = [], permissions: readonly Record<string, string>[] = [],
): Record<string, unknown> { ): Record<string, unknown> {
return { return {
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
+98 -26
View File
@@ -1,21 +1,23 @@
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
import type { ModuleConfiguration, ModuleDatabaseExecutor } from "@ekklesia/contracts";
import type { import type {
ModuleConfiguration, AnyModuleRuntimeServices,
LegacyModuleRuntimeServices,
ModuleDatabase, ModuleDatabase,
ModuleRuntimeServices, } from "../src/modules/database.js";
} from "@ekklesia/contracts";
import { afterEach, describe, expect, it, vi } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
import { discoverModules } from "../src/modules/discovery.js"; import { discoverModules } from "../src/modules/discovery.js";
import { resolveModuleEligibility } from "../src/modules/lifecycle.js";
import { import {
ModuleDiscoveryError, ModuleDiscoveryError,
ModuleRuntimeError, ModuleRuntimeError,
type ModuleRuntimeIssueCode, type ModuleRuntimeIssueCode,
type ModuleRuntimeServicesLookup,
startDiscoveredModuleRuntime, startDiscoveredModuleRuntime,
startModuleRuntime, startModuleRuntime,
} from "../src/modules/index.js"; } from "../src/modules/index.js";
import { resolveModuleEligibility } from "../src/modules/lifecycle.js";
vi.mock("../src/modules/discovery.js", async (importOriginal) => { vi.mock("../src/modules/discovery.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../src/modules/discovery.js")>(); const actual = await importOriginal<typeof import("../src/modules/discovery.js")>();
@@ -52,12 +54,13 @@ function manifestFor(
id: string, id: string,
options: { options: {
capabilities?: Array<{ id: string; version: string }>; capabilities?: Array<{ id: string; version: string }>;
database?: { abi: 1 };
dependencies?: Record<string, unknown>; dependencies?: Record<string, unknown>;
permissions?: Array<{ id: string; baseline: string; description: string }>; permissions?: Array<{ id: string; baseline: string; description: string }>;
} = {}, } = {},
): Record<string, unknown> { ): Record<string, unknown> {
return { return {
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
@@ -67,6 +70,7 @@ function manifestFor(
}, },
capabilities: options.capabilities ?? [], capabilities: options.capabilities ?? [],
permissions: options.permissions ?? [], permissions: options.permissions ?? [],
...(options.database ? { database: options.database } : {}),
...(options.dependencies ? { dependencies: options.dependencies } : {}), ...(options.dependencies ? { dependencies: options.dependencies } : {}),
entrypoints: { entrypoints: {
server: "./dist/server/index.js", server: "./dist/server/index.js",
@@ -145,13 +149,29 @@ function fakeModuleDatabase(): ModuleDatabase {
}) as unknown as ModuleDatabase; }) as unknown as ModuleDatabase;
} }
function fakeModuleRuntimeServices(): ModuleRuntimeServices { function fakeModuleRuntimeServices(): ModuleRuntimeServicesLookup {
return Object.freeze({ database: fakeModuleDatabase() }); const services = new Map<string, LegacyModuleRuntimeServices>();
const database = fakeModuleDatabase();
return new Proxy(services, {
get(target, property, receiver) {
if (property === "get") {
return (moduleId: string) => {
let value = target.get(moduleId);
if (!value) {
value = Object.freeze({ database });
target.set(moduleId, value);
}
return value;
};
}
return Reflect.get(target, property, receiver);
},
});
} }
function runtimeOptions( function runtimeOptions(
modulesDirectory: string, modulesDirectory: string,
services: ModuleRuntimeServices = fakeModuleRuntimeServices(), services: ModuleRuntimeServicesLookup = fakeModuleRuntimeServices(),
) { ) {
return { return {
moduleSdkVersion: "0.1.0", moduleSdkVersion: "0.1.0",
@@ -1067,6 +1087,54 @@ describe("already-discovered module runtime", () => {
}); });
describe("module runtime services", () => { describe("module runtime services", () => {
it("delivers only the manifest-selected database mode and distinct ABI executors", async () => {
const modulesDirectory = await createModulesDirectory();
const recorder = createReferenceRecorder();
const legacyDatabase = fakeModuleDatabase();
const alphaExecutor = Object.freeze({
abiVersion: 1,
query: vi.fn(),
transaction: vi.fn(),
}) as unknown as ModuleDatabaseExecutor;
const betaExecutor = Object.freeze({
abiVersion: 1,
query: vi.fn(),
transaction: vi.fn(),
}) as unknown as ModuleDatabaseExecutor;
const services: ModuleRuntimeServicesLookup = new Map<string, AnyModuleRuntimeServices>([
["legacy", Object.freeze({ database: legacyDatabase })],
["alpha", Object.freeze({ database: alphaExecutor })],
["beta", Object.freeze({ database: betaExecutor })],
]);
await createRuntimeModule(modulesDirectory, "legacy", {
serverSource: `export default { id: "legacy", version: "0.1.0", start({ services }) { ${recorder.expression}.push(services.database); } };`,
});
for (const id of ["alpha", "beta"]) {
await createRuntimeModule(modulesDirectory, id, {
manifest: manifestFor(id, { database: { abi: 1 } }),
serverSource: `export default { database: { abi: 1 }, id: ${JSON.stringify(id)}, version: "0.1.0", start({ services }) { ${recorder.expression}.push(services.database); } };`,
});
}
const runtime = await startModuleRuntime(runtimeOptions(modulesDirectory, services));
expect(recorder.values).toEqual([alphaExecutor, betaExecutor, legacyDatabase]);
expect("select" in alphaExecutor).toBe(false);
expect(alphaExecutor).not.toBe(betaExecutor);
await runtime.stop();
});
it("rejects a runtime database declaration that disagrees with its manifest", async () => {
const modulesDirectory = await createModulesDirectory();
await createRuntimeModule(modulesDirectory, "mismatch", {
manifest: manifestFor("mismatch", { database: { abi: 1 } }),
serverSource: `export default { id: "mismatch", version: "0.1.0" };`,
});
const error = await captureRuntimeError(modulesDirectory);
expect(runtimeIssueCodes(error)).toContain("MODULE_RUNTIME_DATABASE_MISMATCH");
});
it("never gives register a services field, and gives start and stop the exact same services object", async () => { it("never gives register a services field, and gives start and stop the exact same services object", async () => {
const modulesDirectory = await createModulesDirectory(); const modulesDirectory = await createModulesDirectory();
const services = fakeModuleRuntimeServices(); const services = fakeModuleRuntimeServices();
@@ -1086,11 +1154,11 @@ describe("module runtime services", () => {
expect(registerServices.values).toEqual([undefined]); expect(registerServices.values).toEqual([undefined]);
expect(lifecycleServices.values).toHaveLength(2); expect(lifecycleServices.values).toHaveLength(2);
expect(lifecycleServices.values[0]).toBe(services); expect(lifecycleServices.values[0]).toBe(services.get("wired"));
expect(lifecycleServices.values[1]).toBe(services); expect(lifecycleServices.values[1]).toBe(services.get("wired"));
}); });
it("shares the exact same services object identity across every module's start hook", async () => { it("selects a stable services object per module rather than sharing one across modules", async () => {
const modulesDirectory = await createModulesDirectory(); const modulesDirectory = await createModulesDirectory();
const services = fakeModuleRuntimeServices(); const services = fakeModuleRuntimeServices();
const recorder = createReferenceRecorder(); const recorder = createReferenceRecorder();
@@ -1112,7 +1180,8 @@ describe("module runtime services", () => {
const runtime = await startModuleRuntime(runtimeOptions(modulesDirectory, services)); const runtime = await startModuleRuntime(runtimeOptions(modulesDirectory, services));
expect(recorder.values).toEqual([services, services]); expect(recorder.values).toEqual([services.get("alpha"), services.get("beta")]);
expect(recorder.values[0]).not.toBe(recorder.values[1]);
await runtime.stop(); await runtime.stop();
}); });
@@ -1141,23 +1210,26 @@ describe("module runtime services", () => {
startModuleRuntime(runtimeOptions(modulesDirectory, services)), startModuleRuntime(runtimeOptions(modulesDirectory, services)),
).rejects.toBeInstanceOf(ModuleRuntimeError); ).rejects.toBeInstanceOf(ModuleRuntimeError);
expect(recorder.values).toEqual([services, services]); expect(recorder.values).toEqual([services.get("started"), services.get("started")]);
}); });
it("starts and stops a zero-module runtime without ever touching the provided services", async () => { it("starts and stops a zero-module runtime without ever touching the provided services", async () => {
const modulesDirectory = await createModulesDirectory(); const modulesDirectory = await createModulesDirectory();
const services = fakeModuleRuntimeServices(); const database = fakeModuleDatabase();
const services: ModuleRuntimeServicesLookup = new Map([
["unused", Object.freeze({ database })],
]);
const runtime = await startModuleRuntime(runtimeOptions(modulesDirectory, services)); const runtime = await startModuleRuntime(runtimeOptions(modulesDirectory, services));
await runtime.stop(); await runtime.stop();
expect(runtime.modules).toEqual([]); expect(runtime.modules).toEqual([]);
expect(vi.mocked(services.database.select)).not.toHaveBeenCalled(); expect(vi.mocked(database.select)).not.toHaveBeenCalled();
expect(vi.mocked(services.database.insert)).not.toHaveBeenCalled(); expect(vi.mocked(database.insert)).not.toHaveBeenCalled();
expect(vi.mocked(services.database.update)).not.toHaveBeenCalled(); expect(vi.mocked(database.update)).not.toHaveBeenCalled();
expect(vi.mocked(services.database.delete)).not.toHaveBeenCalled(); expect(vi.mocked(database.delete)).not.toHaveBeenCalled();
expect(vi.mocked(services.database.execute)).not.toHaveBeenCalled(); expect(vi.mocked(database.execute)).not.toHaveBeenCalled();
expect(vi.mocked(services.database.transaction)).not.toHaveBeenCalled(); expect(vi.mocked(database.transaction)).not.toHaveBeenCalled();
}); });
}); });
@@ -1463,7 +1535,7 @@ describe("module configuration delivery (ADR 0029)", () => {
expect(recorder.values).toEqual([["object", []]]); expect(recorder.values).toEqual([["object", []]]);
}); });
it("keeps the services object one shared identity even though configuration is per-module", async () => { it("keeps each module's services object stable while configuration remains per-module", async () => {
const modulesDirectory = await createModulesDirectory(); const modulesDirectory = await createModulesDirectory();
const services = fakeModuleRuntimeServices(); const services = fakeModuleRuntimeServices();
const recorder = createReferenceRecorder(); const recorder = createReferenceRecorder();
@@ -1492,11 +1564,11 @@ describe("module configuration delivery (ADR 0029)", () => {
await runtime.stop(); await runtime.stop();
const [alphaServices, alphaConfig, bravoServices, bravoConfig] = recorder.values; const [alphaServices, alphaConfig, bravoServices, bravoConfig] = recorder.values;
// This is the reason configuration is a sibling of `services` rather than a field inside it: // Configuration remains a sibling of `services`: both are selected per module, but they are
// `services` is deliberately one shared object for the whole runtime, while configuration must // independently composed snapshots with separate contracts and lifetimes.
// differ per module. Both properties hold simultaneously. expect(alphaServices).toBe(services.get("alpha"));
expect(alphaServices).toBe(services); expect(bravoServices).toBe(services.get("bravo"));
expect(bravoServices).toBe(services); expect(alphaServices).not.toBe(bravoServices);
expect(alphaConfig).not.toBe(bravoConfig); expect(alphaConfig).not.toBe(bravoConfig);
expect((alphaConfig as ModuleConfiguration).getString("label")).toBe("alpha"); expect((alphaConfig as ModuleConfiguration).getString("label")).toBe("alpha");
expect((bravoConfig as ModuleConfiguration).getString("label")).toBe("bravo"); expect((bravoConfig as ModuleConfiguration).getString("label")).toBe("bravo");
+63 -2
View File
@@ -38,10 +38,14 @@ async function createModulesDirectory(): Promise<string> {
function manifestFor( function manifestFor(
id: string, id: string,
options: { dependencies?: Record<string, unknown>; schema?: string | false } = {}, options: {
database?: { abi: 1 };
dependencies?: Record<string, unknown>;
schema?: string | false;
} = {},
): Record<string, unknown> { ): Record<string, unknown> {
return { return {
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
@@ -49,6 +53,7 @@ function manifestFor(
...(options.dependencies ? { dependencies: options.dependencies } : {}), ...(options.dependencies ? { dependencies: options.dependencies } : {}),
capabilities: [], capabilities: [],
permissions: [], permissions: [],
...(options.database ? { database: options.database } : {}),
entrypoints: { entrypoints: {
server: "./dist/server/index.js", server: "./dist/server/index.js",
...(options.schema === false ? {} : { schema: options.schema ?? "./dist/schema/index.js" }), ...(options.schema === false ? {} : { schema: options.schema ?? "./dist/schema/index.js" }),
@@ -126,6 +131,62 @@ function issueCodes(error: ModuleSchemaDiscoveryError): ModuleSchemaDiscoveryIss
} }
describe("module schema discovery", () => { describe("module schema discovery", () => {
it("loads ABI-v1 schema entrypoints as plain metadata without importing an ORM", async () => {
const modulesDirectory = await createModulesDirectory();
await createSchemaModule(modulesDirectory, "calendar", {
manifest: manifestFor("calendar", { database: { abi: 1 } }),
schemaSource: `
export default {
moduleId: "calendar",
tables: [
{ name: "calendar_events", foreignKeys: [] },
{ name: "calendar_attendees", foreignKeys: [{ table: "calendar_events" }] }
]
};
`,
});
const aggregate = await discoverModuleSchemas(discoveryOptions(modulesDirectory));
expect(aggregate.tables.map((table) => table.name)).toEqual([
"calendar_attendees",
"calendar_events",
]);
expect(aggregate.tables.every((table) => table.table === undefined)).toBe(true);
expect(aggregate.drizzleSchema).toEqual({});
});
it("aggregates ABI-v1 prefix, duplicate, cross-module FK, missing target, and malformed errors", async () => {
const modulesDirectory = await createModulesDirectory();
await createSchemaModule(modulesDirectory, "alpha", {
manifest: manifestFor("alpha", { database: { abi: 1 } }),
schemaSource: `export default {
moduleId: "alpha",
tables: [
{ name: "wrong_records", foreignKeys: [] },
{ name: "alpha_records", foreignKeys: [{ table: "beta_records" }] },
{ name: "alpha_records", foreignKeys: [{ table: "alpha_missing" }] }
]
};`,
});
await createSchemaModule(modulesDirectory, "malformed", {
manifest: manifestFor("malformed", { database: { abi: 1 } }),
schemaSource: `export default { moduleId: "malformed", tables: [{ name: "malformed_rows", unknown: true }] };`,
});
const error = await captureSchemaError(modulesDirectory);
expect(issueCodes(error)).toEqual(
expect.arrayContaining([
"MODULE_SCHEMA_CROSS_MODULE_FOREIGN_KEY",
"MODULE_SCHEMA_EXPORT_INVALID",
"MODULE_SCHEMA_FOREIGN_KEY_TARGET_MISSING",
"MODULE_SCHEMA_TABLE_DUPLICATE",
"MODULE_SCHEMA_TABLE_NAMESPACE_INVALID",
]),
);
});
it("returns a frozen empty aggregate without importing module servers", async () => { it("returns a frozen empty aggregate without importing module servers", async () => {
const modulesDirectory = await createModulesDirectory(); const modulesDirectory = await createModulesDirectory();
const recorder = createGlobalEventRecorder(); const recorder = createGlobalEventRecorder();
+1 -1
View File
@@ -18,7 +18,7 @@ function fakeModule(
} = {}, } = {},
): DiscoveredModule { ): DiscoveredModule {
const manifest = parseModuleManifest({ const manifest = parseModuleManifest({
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "1.0.0", version: "1.0.0",
+1 -1
View File
@@ -79,7 +79,7 @@ async function createModule(modulesDirectory: string, fixture: ModuleFixture): P
version: contribution.version, version: contribution.version,
})), })),
id: fixture.id, id: fixture.id,
manifestVersion: 7, manifestVersion: 8,
name: `${fixture.id} module`, name: `${fixture.id} module`,
permissions: permissions:
fixture.display === undefined fixture.display === undefined
+1 -1
View File
@@ -1905,7 +1905,7 @@ describe.sequential("live PostgreSQL migration timeout precedence", () => {
describe.sequential("live PostgreSQL retained history for an uninstalled module", () => { describe.sequential("live PostgreSQL retained history for an uninstalled module", () => {
const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", ".."); const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
const templateModule = path.join(repositoryRoot, "templates", "module"); const templateModule = path.join(repositoryRoot, "templates", "module");
const versions = { moduleSdkVersion: "0.1.0", platformVersion: "0.1.0" } as const; const versions = { moduleSdkVersion: "0.2.0", platformVersion: "0.2.0" } as const;
async function coreWithoutNewestMigration(directory: string): Promise<string> { async function coreWithoutNewestMigration(directory: string): Promise<string> {
const target = path.join(directory, "core-drizzle"); const target = path.join(directory, "core-drizzle");
+19
View File
@@ -0,0 +1,19 @@
/**
* The per-test timeout for Core's import-safety tests, and only those.
*
* Each of these tests proves that importing a module does nothing (no I/O, no connection, no output)
* by performing a cold dynamic `import()` of a large Core source graph inside the test body. Vitest
* transforms and evaluates that whole graph on demand, and that work is CPU-bound. An ordinary test
* file's own top-level imports run before its tests start and fall under no per-test timeout; these
* deliberately do not, so the cost lands inside Vitest's default 5-second test timeout.
*
* Alone they take about 0.7–1.2 s. During a full `pnpm verify`, Turbo runs every package's suite at
* once and the CPU is saturated. Reproduced locally (six cores, Core's suite alongside five other
* packages' suites), the same tests took 3.0–5.4 s, and so timed out intermittently.
*
* 30 seconds is about five times the slowest time measured under load, which leaves room for slower
* shared CI runners. It matches the repository's integration-test timeout. It is still bounded, so a
* module that genuinely hangs while being imported, for example on a network call, still fails. The
* assertions themselves are unchanged: these tests fail on what an import does, never on speed.
*/
export const IMPORT_SAFETY_TEST_TIMEOUT_MS = 30_000;
@@ -50,11 +50,11 @@ export function manifestFor(
} = {}, } = {},
): Record<string, unknown> { ): Record<string, unknown> {
return { return {
manifestVersion: 7, manifestVersion: 8,
id, id,
name: `${id} module`, name: `${id} module`,
version: "0.1.0", version: "0.1.0",
compatibility: { platform: "^0.1.0", moduleSdk: "^0.1.0" }, compatibility: { platform: "^0.2.0", moduleSdk: "^0.2.0" },
...(options.dependencies ? { dependencies: options.dependencies } : {}), ...(options.dependencies ? { dependencies: options.dependencies } : {}),
capabilities: [], capabilities: [],
permissions: [], permissions: [],
+11 -2
View File
@@ -86,6 +86,7 @@ export interface PackageFixtureOptions {
readonly id?: string; readonly id?: string;
readonly version?: string; readonly version?: string;
readonly serverSource?: string; readonly serverSource?: string;
readonly schemaSource?: string;
readonly manifest?: (manifest: Record<string, unknown>) => Record<string, unknown>; readonly manifest?: (manifest: Record<string, unknown>) => Record<string, unknown>;
readonly runtimePackage?: Record<string, unknown>; readonly runtimePackage?: Record<string, unknown>;
readonly metadata?: (metadata: Record<string, unknown>) => Record<string, unknown>; readonly metadata?: (metadata: Record<string, unknown>) => Record<string, unknown>;
@@ -93,6 +94,8 @@ export interface PackageFixtureOptions {
readonly tamper?: (files: Map<string, Buffer>) => void; readonly tamper?: (files: Map<string, Buffer>) => void;
/** Entries appended after the package's own, under any path. */ /** Entries appended after the package's own, under any path. */
readonly extraEntries?: readonly FixtureEntry[]; readonly extraEntries?: readonly FixtureEntry[];
/** Extra payload files, listed in the metadata like every other file. */
readonly files?: Readonly<Record<string, Uint8Array | string>>;
} }
export interface PackageFixture { export interface PackageFixture {
@@ -125,6 +128,7 @@ export async function modulePackageFixture(
let files: Map<string, Buffer>; let files: Map<string, Buffer>;
try { try {
const created = await createMigrationModule(scratch, id, { const created = await createMigrationModule(scratch, id, {
...(options.schemaSource === undefined ? {} : { schemaSource: options.schemaSource }),
serverSource: serverSource:
options.serverSource ?? options.serverSource ??
`export default { id: ${JSON.stringify(id)}, version: ${JSON.stringify(version)}, register() {} };\n`, `export default { id: ${JSON.stringify(id)}, version: ${JSON.stringify(version)}, register() {} };\n`,
@@ -160,6 +164,10 @@ export async function modulePackageFixture(
), ),
); );
files.set("THIRD_PARTY_NOTICES", Buffer.from("No third-party software is included.\n")); files.set("THIRD_PARTY_NOTICES", Buffer.from("No third-party software is included.\n"));
files.set("LICENSE", Buffer.from("Example module license text.\n"));
for (const [filePath, data] of Object.entries(options.files ?? {})) {
files.set(filePath, Buffer.from(data));
}
const listed = [...files.entries()] const listed = [...files.entries()]
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)) .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
@@ -167,13 +175,14 @@ export async function modulePackageFixture(
const baseMetadata: Record<string, unknown> = { const baseMetadata: Record<string, unknown> = {
packageFormat: 1, packageFormat: 1,
module: { id, version }, module: { id, version },
license: "MIT",
target: "any", target: "any",
runtime: { node: ">=20" }, runtime: { node: ">=20" },
provenance: { provenance: {
revision: "86ae907f59458508e3277666cdd214f5bd7c1078", revision: "86ae907f59458508e3277666cdd214f5bd7c1078",
packager: { name: "@ekklesia/module-pack", version: "0.1.2" }, packager: { name: "@ekklesia/module-pack", version: "0.2.0" },
}, },
incorporates: { "@ekklesia/module-sdk": "0.1.2" }, incorporates: { "@ekklesia/module-sdk": "0.2.0" },
files: listed, files: listed,
}; };
const metadata = options.metadata ? options.metadata(baseMetadata) : baseMetadata; const metadata = options.metadata ? options.metadata(baseMetadata) : baseMetadata;
+2 -1
View File
@@ -2,7 +2,8 @@
"extends": "../packages/typescript-config/node.json", "extends": "../packages/typescript-config/node.json",
"compilerOptions": { "compilerOptions": {
"noEmit": true, "noEmit": true,
"types": ["node", "vitest/globals"] "types": ["node", "vitest/globals"],
"rewriteRelativeImportExtensions": true
}, },
"include": [ "include": [
"drizzle.config.ts", "drizzle.config.ts",
+2 -2
View File
@@ -500,10 +500,10 @@ finds its files:
```sh ```sh
docker build \ docker build \
--file deploy/Dockerfile \ --file deploy/Dockerfile \
--build-arg VERSION=0.1.2 \ --build-arg VERSION=0.2.0 \
--build-arg REVISION="$(git rev-parse HEAD)" \ --build-arg REVISION="$(git rev-parse HEAD)" \
--build-arg SOURCE=https://git.example.org/your-org/ekklesia \ --build-arg SOURCE=https://git.example.org/your-org/ekklesia \
--tag ekklesia:0.1.2 \ --tag ekklesia:0.2.0 \
. .
``` ```
@@ -0,0 +1,207 @@
# 0051: Module packages declare their own license and carry its text
- Status: Accepted
- Date: 2026-10-07
- Amends: [0049](0049-module-package-v1.md) — every Module Package v1 artifact gains an
authoritative package-level license declaration and a `LICENSE` payload. `packageFormat` stays 1.
- Related: [the repository license](../../../README.md#license),
[ADR 0048](0048-generic-image-and-installed-module-storage.md),
[ADR 0050](0050-module-database-abi-v1.md)
## Context
ADR 0049 makes a module release one immutable, self-contained package and already requires
`THIRD_PARTY_NOTICES` for code bundled from third-party dependencies. It deliberately says that no
package is a distributable release until license and notice collection is proven. The implemented
packager now generates those notices from the dependency code it actually bundles, but Module
Package v1 still does not declare the module's own license or carry the module's license text.
Those are different obligations. `THIRD_PARTY_NOTICES` excludes both the module itself and bundled
Ekklesia-owned packages. The source module's development `package.json` is not copied into the
package: the packager generates a minimal runtime `package.json` instead. Consequently, an archive
can preserve every third-party notice and still lose the authoritative declaration and text for the
work being distributed.
The repository and its workspace packages declare `AGPL-3.0-or-later`, and the repository carries
the GNU AGPL version 3 text in `LICENSE`. The canonical module template also declares
`AGPL-3.0-or-later` in its source `package.json`. Official Ekklesia modules use that license today,
but a packager cannot assume that every module has the platform's license. A module release must say
what license its own publisher actually declared and must carry the corresponding material.
The current `ekklesia.package.json` contract is strict: a reader refuses unknown fields. Adding a
required field therefore makes pre-change and post-change readers reject one another's artifacts.
That is intentional here, not a reason for `packageFormat: 2`. ADR 0049 has not admitted a
distributable v1 release without proven license handling; this decision completes that still-open v1
requirement before real modules are distributed. The packager and verifier must adopt the tightening
together, and strict readers fail closed during that cutover rather than silently misreading a
package.
## Decision
### The package declares the module's own license once
Every Module Package v1 `ekklesia.package.json` has a required top-level `license` field containing
the module's SPDX license expression:
```json
{
"packageFormat": 1,
"module": { "id": "example", "version": "0.1.0" },
"license": "AGPL-3.0-or-later"
}
```
`ekklesia.package.json.license` is the authoritative package-release declaration. The expression is
not repeated in `ekklesia.module.json` or in the generated runtime `package.json`. The module's
source `package.json` is a packaging input, not release metadata inside the finished artifact.
The source module must explicitly declare its license in its own project metadata. The canonical
packager reads the normal string `license` field from the source module's `package.json`, validates
it as a supported SPDX license expression, and preserves that declaration in
`ekklesia.package.json`. It refuses a missing, empty, `UNLICENSED`, legacy object-shaped, malformed,
or unsupported declaration. It never substitutes the Ekklesia platform's license and does not try
to decide whether a publisher chose an appropriate license.
For official Ekklesia modules today the declaration is `AGPL-3.0-or-later`, matching the repository
license. This is a fact about those modules, not a default the packager invents for other modules.
### The package carries the applicable license material
Every distributable Module Package v1 contains a regular file at this canonical path inside the
module directory:
```text
LICENSE
```
`LICENSE` contains the license material applicable to the module release. It is an ordinary payload
file under ADR 0049:
- it appears exactly once in the strict `files` list in `ekklesia.package.json`;
- its byte size and SHA-256 are recorded there;
- the archive SHA-256 covers it and the metadata that records it;
- it is immutable for that release and changes only by producing a different archive.
The license bytes must be available as an explicit source or build input. The canonical source is a
module-owned `LICENSE` file at the module source root. Tooling may also accept an explicitly named
license-text input when a workspace layout needs one, but it must place those bytes at the package's
canonical `LICENSE` path. It must not search ancestor directories and silently adopt a repository
license, generate project-specific license material, or download text from the network. The
in-repository template implementation may later add its own `LICENSE` input or explicitly select
the repository's AGPL text; this ADR does neither.
The packager validates that both inputs exist: the declared SPDX expression and the applicable
license text. It preserves the supplied text as deterministic package input. It is not a license
compatibility engine and does not offer legal advice.
### `THIRD_PARTY_NOTICES` remains a separate concern
`THIRD_PARTY_NOTICES` continues to describe third-party packages actually bundled into or included
with the module: their identities, versions, declared licenses, uses, and required license and notice
texts. It is not the module's own license file and cannot satisfy the `LICENSE` requirement.
The module itself is not added to `THIRD_PARTY_NOTICES`. A first-party module is not duplicated there
merely because it uses the same AGPL license as Ekklesia. `LICENSE` and `THIRD_PARTY_NOTICES` both
remain required because they describe different parts of the release.
### Bundled Ekklesia code
A module package may bundle Ekklesia-owned SDK, contracts, database adapter, UI, and related code.
`incorporates` continues to record the exact versions of those Ekklesia components. It is an
inventory and compatibility fact, not a second authoritative declaration of the module's license.
Today's official module packages and the Ekklesia components they incorporate are all
`AGPL-3.0-or-later`. Their package `LICENSE` therefore carries the applicable AGPL text once. The
package does not need one identical copy per incorporated Ekklesia component, and those components
do not move into `THIRD_PARTY_NOTICES` merely to obtain duplicate text.
This ADR does not decide every future combination of a community module's license with differently
licensed incorporated code. Publishers remain responsible for their choices and obligations. The
packager preserves declared information and required material; it does not judge broad license
compatibility.
### Packaging and verification fail closed
The implementation that follows this ADR must make the packager refuse a module when:
- its source project has no acceptable explicit SPDX license expression;
- its license-text input is missing or is not a regular file;
- producing the package would omit `LICENSE` from the strict payload.
The package verifier must refuse an artifact when:
- `ekklesia.package.json.license` is missing, malformed, or outside the expression syntax the
contract supports;
- the `LICENSE` payload is missing;
- `LICENSE` is absent from the exact `files` list; or
- its listed size or SHA-256 does not match its bytes, as with every other payload file.
This ADR does not implement those checks. The contracts, packager, verifier, fixtures, template,
and package proofs must change together in the implementation PR.
### Determinism and runtime metadata
`LICENSE` introduces no timestamp, generated host path, network lookup, or other environmental
input. The deterministic archive rules in ADR 0049 apply to it unchanged.
The generated runtime `package.json` remains minimal and is not authoritative for licensing. There
is no runtime need to add a `license` field there. `ekklesia.package.json` is the release metadata,
while the source module's `package.json` only supplies the publisher's declaration to the packager.
### Package format remains 1
`packageFormat` remains **1**. This is an additive tightening that completes ADR 0049's licensing
requirement before the first distributable Module Package v1 release. It does not change the archive
encoding, safety rules, target model, installation layout, or meaning of any existing field.
The strict metadata schema is preserved. A verifier that predates this decision refuses the new
unknown `license` field; an updated verifier refuses an old package that lacks it or lacks `LICENSE`.
Both outcomes are safe. There is no installed or published v1 release compatibility promise to
preserve because ADR 0049 explicitly withheld distributable-release status pending this work.
ADR 0050's database ABI decision is unaffected. Whether a package uses database ABI v1 or the legacy
database facade has no bearing on its license declaration or payload.
## Consequences
- A Module Package v1 release is self-describing about the module's own license and carries the
corresponding material without consulting its source repository or the network.
- Operators can audit the release declaration in `ekklesia.package.json`, the module's license in
`LICENSE`, and dependency obligations in `THIRD_PARTY_NOTICES` without conflating them.
- Module publishers must make both the SPDX declaration and license text explicit packaging inputs.
- The template and every package fixture must be updated before packaging succeeds, but only in the
later implementation PR.
- Existing development artifacts produced before this tightening are intentionally rejected and
rebuilt; none was a distributable v1 release under ADR 0049.
- Identical AGPL text is carried once for today's official module and incorporated Ekklesia code.
## Alternatives
- **Use only `THIRD_PARTY_NOTICES`.** Rejected: it describes third-party dependencies and explicitly
excludes the module itself and Ekklesia-owned incorporated packages.
- **Make the generated runtime `package.json` authoritative.** Rejected: it is deliberately minimal
runtime discovery metadata, and copying the declaration there would duplicate release metadata.
- **Copy the platform's license automatically.** Rejected: the platform cannot declare a module's
license for its publisher, and a community module may make a different declaration.
- **Search parent directories for `LICENSE`.** Rejected: the chosen file would depend on checkout
layout and could silently apply an unrelated repository's terms. An out-of-tree input must be
explicit.
- **Download standard license text while packaging.** Rejected: builds must remain offline,
deterministic, and independent of a mutable remote source.
- **Duplicate the AGPL text for every incorporated Ekklesia package.** Rejected: identical copies
add no information. `incorporates` records component identity and version; one applicable text is
sufficient for today's official packages.
- **Create `packageFormat: 2`.** Rejected: v1 has not crossed its own distributable-release boundary,
strict readers fail safely, and no archive or installation mechanism changes.
- **Make the packager decide license compatibility.** Rejected: preserving declarations and material
is mechanical; judging every present and future license combination is a broader legal and policy
problem.
## Deferred
- Implementing contract, packager, verifier, fixture, template, and package-proof changes.
- The exact set and version of SPDX expression syntax accepted by the implementation, beyond the
requirement that unsupported expressions fail closed.
- Broad policy for future mixed-license community modules and incorporated code.
- Container-image license distribution.
- Marketplace, installer, publisher verification, and package-signing policy.
@@ -0,0 +1,227 @@
# 0052: Reviewed license supplements cover redistributed dependencies whose packages omit required material
- Status: Proposed
- Date: 2026-10-07
- Extends: [0049](0049-module-package-v1.md), in one respect only. ADR 0049 left exactly how licence
and notice material is collected to the packager's implementation. That implementation, and the
module development guide, then took material only from a redistributed package's own files, or
from a predefined standard licence text that needs no project-specific lines. This ADR adds one
further source: a reviewed supplement. Everything else in ADR 0049 is unchanged, as is
`packageFormat`.
- Related: [ADR 0048](0048-generic-image-and-installed-module-storage.md),
[ADR 0051](0051-module-package-license-material.md)
## Context
ADR 0049 requires every Module Package v1 to carry `THIRD_PARTY_NOTICES`: the licence and notice
material that redistributing its third-party code requires. It also states that no package is a
distributable release until licence and notice collection is proven. The canonical packager collects
material from two places:
- the licence, copying, copyright, and notice files a redistributed package ships at its root;
- the standard text of the package's declared licence, but only when that text is complete without
project-specific lines (Apache-2.0 today).
A package that has neither stops packaging. That is fail-closed by design: an MIT or BSD package
without its file is refused, because its copyright line exists only in that file.
The first native-target module package needs a dependency that this rule cannot handle.
`@img/[email protected]` is the prebuilt libvips that `sharp` loads on Linux x64 with
glibc. It declares `LGPL-3.0-or-later`. The package itself, like its latest release 1.3.4, contains
only these files:
- `README.md`
- `versions.json`
- `lib/index.js`
- one glib header
- one shared library
That shared library includes about 29 libraries. Its README names each one and the licence it is
used under, mostly with a link:
- LGPL components, such as libvips, glib, and pango;
- cairo, under MPL-2.0;
- many BSD-, MIT-, zlib-, IJG-, and FreeType-licensed libraries.
The package ships no licence text and no copyright notice for any of them. No standard text can stand
in for that material: it includes per-project copyright notices and several different licences.
Options that were ruled out before this decision:
- **Downloading material while packaging.** Packaging must stay offline and deterministic (ADR 0049,
ADR 0051).
- **Inventing material.** A packager that guesses notices produces artifacts that look compliant and
may not be.
Ekklesia needs a way to carry material that a dependency's own package omits. It has to be reviewed
by people, tied to exactly the bytes it was reviewed for, and fail closed whenever that tie breaks.
Some of these licences may also impose obligations beyond carrying text: the LGPL and the MPL can
require recipients to be able to obtain corresponding source. Whether and how such an obligation is
met for a particular redistributed binary is a legal and compliance determination. This decision
does not make that determination.
## Decision
### Package-provided material stays the preferred source
The licence, copying, copyright, and notice material that a redistributed package ships remains the
primary source, collected exactly as it is today. Nothing in this ADR removes, replaces, or rewrites
package-provided material. A supplement only adds to it.
### A reviewed supplement fills what a package omits
When a redistributed dependency omits material that redistribution requires, the canonical Ekklesia
packager may use a **license supplement**: a checked-in, reviewed record of that material for one
exact dependency.
- **Where supplements live.** In the Ekklesia repository, as part of the canonical packager's own
versioned inputs. A supplement enters only through Ekklesia's normal reviewed change process, and
the change that adds it is its review. A given packager version therefore always carries the same
supplements.
- **What that review is.** Repository review of a supplement is project and code review of a build
input: whether its content, its exact match, and its provenance are what the change says they are.
It is not legal review, and it does not prove that any redistribution obligation is satisfied.
- **What a supplement may contain:**
- licence texts;
- copyright and attribution notices;
- provenance: where each piece of material was obtained, and which upstream component versions it
covers;
- corresponding-source information, such as where upstream source for the exact build is
published;
- other material that accompanies the dependency's redistribution.
- **Generic by construction.** Supplements are data. The mechanism contains no package-specific code
and treats every supplement identically, whether it is for libvips or for any other dependency.
### A supplement matches one exact package, or it fails closed
A supplement names exactly one redistributed package:
- its package name;
- its exact version;
- an integrity value for the package's contents: a digest the packager computes from the package's
redistributed files.
- **Deterministic.** It covers exactly each redistributed file's normalized relative path within
the package and its bytes, combined in an order defined by the paths themselves.
- **Host-independent.** It excludes filesystem metadata, timestamps, ownership, permissions, and
the order in which files were extracted or listed. The same package contents always give the
same digest, wherever and however they were installed.
- **Documented.** The implementation defines and documents the exact algorithm, which does not
depend on any package manager.
The packager uses a supplement only when all three match the package it is about to redistribute.
- **A mismatch on any of the three fails packaging.** This covers, for example, a supplement whose
name and version match but whose integrity differs. It never falls back to a nearby version, and
it never silently skips the supplement.
- **Every match is used.** A supplement that matches is always merged into the notices, including
when the package also ships some material of its own.
- **Gaps still fail.** If a dependency lacks required material and no exact supplement matches, the
packager stops, exactly as it does today.
### Supplements are immutable build inputs
- **Immutable.** A supplement is never edited in place to cover a different build. A changed
package, a new version, or different contents need a new supplement, reviewed again.
- **No network.** Packaging reads supplements from the packager's own inputs and never downloads
anything. Assembling a supplement's content is a separate, offline-reviewed curation step done
when the supplement is authored, never during packaging.
### Merging is deterministic and labelled
The notice generator merges package-provided material and supplement material deterministically. The
same packager version and the same inputs still produce a byte-identical `THIRD_PARTY_NOTICES`
(ADR 0049).
- **Order.** Within a dependency's entry, package-provided material comes first, then supplement
material.
- **Labelling.** Supplement material is marked as supplied by Ekklesia's reviewed supplement, never
presented as if it came from the package.
- **No other change.** Dependencies are still sorted, line endings normalized, and each dependency
keeps its own entry, exactly as before.
### A supplement never changes a dependency's declared licence
`THIRD_PARTY_NOTICES` keeps reporting the licence the dependency itself declares.
- **No override.** A supplement can add material about the components a dependency contains, but it
cannot replace, override, or rewrite the dependency's declared licence.
- **Consistency check.** A supplement records the declared licence it was reviewed against. If that
disagrees with the package's actual declaration, packaging fails.
### Legal and compliance determinations are not made here
A supplement can record corresponding-source information, but this ADR does not decide what
satisfies any licence's source obligation, and neither does the mechanism:
- the mechanism never asserts that a written offer, a source URL, a mirror, or any other arrangement
satisfies a licence;
- carrying a supplement shows that the reviewed material is present in the package. It does not
certify that the package is compliant;
- for every redistributed binary under the LGPL, the MPL, or any other licence with source or
similar obligations, the determination of whether and how those obligations are met is deferred.
It must be made, and verified, separately.
ADR 0049's release gate still applies. A package that redistributes such a binary does not become a
distributable release just because its supplement was merged. It becomes one only once that
binary's compliance determination has been made and verified.
### Scope
- **Third-party code only.** Supplements apply only to redistributed third-party dependencies,
whether bundled or copied into the package. They never apply to the module's own licence or
`LICENSE` (ADR 0051), or to incorporated Ekklesia packages.
- **No package format change.** `packageFormat` stays **1**. A supplement changes only the content of
`THIRD_PARTY_NOTICES`, which is already a listed, digested payload file. No metadata field, archive
rule, or verifier contract changes.
### The motivating case
`@img/[email protected]` is the first dependency expected to need a supplement. This ADR
does not curate it. Its supplement will be assembled, reviewed, and merged separately, together with
the native-target packaging work that redistributes it. The source-obligation determination for its
LGPL and MPL components remains open, as above.
## Consequences
- A dependency whose package omits required material can be redistributed after review, offline and
deterministically, instead of making native packaging impossible.
- Each supplement is tied to exact package bytes, so a changed or unexpected dependency fails
packaging rather than inheriting material reviewed for something else.
- Ekklesia takes on reviewing and maintaining supplements. Every version bump of a supplemented
dependency needs a new reviewed supplement before packaging works again.
- `THIRD_PARTY_NOTICES` can now contain material that did not come from the dependency's package. It
is always labelled.
- Carrying material and meeting obligations stay separate. Source-availability questions remain open
until they are determined per binary.
## Alternatives
- **Download licence material while packaging.** Rejected: packaging must stay offline,
deterministic, and independent of a mutable remote source (ADR 0049, ADR 0051).
- **Extend the standard-text list.** Rejected: standard texts only work when the licence needs no
project-specific line. Bundled native libraries need per-project copyright notices, and several
different licences.
- **Match supplements by name and version alone.** Rejected: identical versions can differ in content
across registries or rebuilds, and the material was reviewed for specific bytes.
- **Fall back to the nearest supplemented version.** Rejected: material reviewed for one build says
nothing reliable about another.
- **Let a supplement restate a dependency's licence.** Rejected: the declaration belongs to the
dependency's publisher. A supplement that could override it could misrepresent what is being
redistributed.
- **Per-package special cases in the packager** (for example, code that knows about libvips).
Rejected: every supplemented dependency would need new code, and review would be split between
code and data.
- **Treat a recorded source URL or written offer as satisfying copyleft obligations.** Rejected for
this ADR: that is a legal determination that has to be verified per binary, not assumed by a build
mechanism.
- **Supplements provided by module authors.** Not adopted now: the canonical packager uses only
supplements reviewed into Ekklesia. Whether module repositories may contribute their own reviewed
supplements is deferred.
## Deferred
- Implementing the mechanism in the canonical packager: the supplement format and storage location,
the integrity algorithm, the matching, the merge, and the tests.
- Curating and reviewing the supplement for `@img/[email protected]`.
- The legal and compliance determination of source obligations for each redistributed binary, and
how a determination is recorded.
- Whether the packager should refuse, or flag, packages whose supplements note an open determination.
- Supplements provided by module repositories.
- Recording which supplements were used in `ekklesia.package.json`, should that ever be needed.
@@ -0,0 +1,255 @@
# 0053: A module builds outside the monorepo, from Ekklesia packages published over the npm registry protocol
- Status: Accepted
- Date: 2026-10-07
- Superseded in part by: [0054](0054-public-package-reads-before-launch.md) — only where this ADR
describes the package phase before launch as private, or requires authenticated package reads.
- Extends: [0049](0049-module-package-v1.md). This is the step ADR 0049 deferred: "publishing the
Ekklesia SDK packages for module builds outside a platform workspace". A registry is used only to
build a module. Installing one stays registry-free: an installed package is self-contained, as ADR
0049 decided.
- Related: [ADR 0002](0002-pnpm-workspace-and-typescript.md),
[ADR 0006](0006-versioned-capabilities-and-compiled-module-runtime.md),
[ADR 0021](0021-modules-as-hostable-products.md),
[ADR 0023](0023-module-ui-build-pipeline.md),
[ADR 0039](0039-shared-design-tokens-and-elements.md),
[ADR 0047](0047-module-ci-harness.md),
[ADR 0048](0048-generic-image-and-installed-module-storage.md),
[ADR 0050](0050-module-database-abi-v1.md),
[ADR 0051](0051-module-package-license-material.md),
[ADR 0052](0052-reviewed-license-supplements.md)
## Context
Modules are independently versioned products in their own repositories (ADR 0021). Yet no module can
be built outside Ekklesia's monorepo today. Signage's continuous integration clones the platform at
a pinned commit, places Signage under `modules/signage`, and installs and builds inside that
workspace, because its Ekklesia dependencies exist only as `workspace:*` packages.
An investigation of the current packages found the following.
- **One coordinated version.** Every `@ekklesia/*` package, and the platform, is version 0.1.2. The
release process already bumps them together. The platform reports its Module SDK version, which
manifests' `compatibility.moduleSdk` ranges are checked against (ADR 0006), by reading
`@ekklesia/module-sdk`'s own package version.
- **The tarballs already stand alone.** `pnpm pack` rewrites `workspace:*` ranges to exact versions,
and each tarball carries only its built `dist`, declarations, and `LICENSE`. But every package's
`prepack` runs a command at the monorepo root, and `@ekklesia/typescript-config` is marked
`private`.
- **The SDK exposes everything.** `@ekklesia/module-sdk` re-exports the whole `@ekklesia/contracts`
barrel. That includes contracts no module needs, such as authorization and identity, and the
legacy Drizzle `ModuleDatabase` type. `@ekklesia/contracts` depends on `drizzle-orm` for that type,
so every module install pulls Drizzle in.
- Neither the module template nor Signage imports `@ekklesia/contracts` directly.
- **Frameworks are declared twice.** `@ekklesia/ui` lists `react`, and `@ekklesia/module-sdk` lists
`drizzle-orm`, as both a dependency and a peer dependency. That invites a second copy of a runtime
that must be single within one module bundle.
- **The canonical packager assumes the monorepo**, in two ways:
- it finds the module's Node.js range only through an enclosing `pnpm-workspace.yaml`;
- it decides that an Ekklesia package is the platform's own, not third-party, because its real
path does not contain `node_modules`.
An `@ekklesia/*` package installed from a registry would therefore be treated as third-party.
Packaging would omit it from `incorporates` and skip the Module SDK compatibility check.
- **The registry and its hosts.**
- The current private host is a Gitea 1.27.2 server. Its npm registry is enabled for the
organization, and that endpoint and the repositories are currently readable anonymously.
- pnpm leaves a tarball URL out of its lockfile only when the URL has the canonical
`<registry>/<name>/-/<name>-<version>.tgz` form. Gitea advertises another form, so lockfiles
produced against Gitea name the Gitea host.
- The integrity hashes in those lockfiles are independent of the host.
## Decision
### The npm registry protocol, not a provider
Ekklesia's module-development packages are distributed over the **standard npm registry protocol**,
and modules install them with ordinary pnpm or npm commands.
- **No provider is part of the architecture.** Not Gitea, GitHub, npmjs, or any other. A module
repository depends on the protocol and on a scope-to-registry mapping in normal npm/pnpm
configuration.
- **Gitea may host the private phase.** It is a host for this phase, not a permanent decision.
- **No host-neutral lockfile or Ekklesia proxy is required.** Moving to another registry may need a
one-time change of a module's registry configuration and a regeneration of its lockfile. The
integrity hashes keep verifying the package content across such a move.
A module repository's registry configuration is, for example:
```ini
# .npmrc, committed: where the @ekklesia scope lives, and nothing secret.
@ekklesia:registry=https://<registry endpoint>/
```
```ini
# User or CI configuration, never committed: the credential, from the environment.
//<registry endpoint>/:_authToken=${EKKLESIA_PACKAGES_TOKEN}
```
### The public package set
Only packages a module author needs are published. Nothing is published merely because it exists in
the workspace.
| Category | Packages |
| --- | --- |
| Author API | `@ekklesia/module-sdk`, `@ekklesia/module-database`, `@ekklesia/module-ui-sdk`, `@ekklesia/design-tokens` |
| Tooling | `@ekklesia/module-ui-build`, `@ekklesia/module-pack`, `@ekklesia/typescript-config` |
| Pre-1.0 component API | `@ekklesia/ui`: publishable, explicitly unstable before 1.0 |
| Implementation dependency only | `@ekklesia/contracts`: may be published because the packages above depend on it, but it is **not** a supported direct module-author API |
| Never published | `@ekklesia/core`, the applications, `@ekklesia/module-ui-host`, `@ekklesia/module-template`, and every other platform internal |
### A curated SDK surface
Before the first external publication, the author-facing SDK is narrowed.
- **A curated API.** `@ekklesia/module-sdk` exposes what a module author needs, and no longer
re-exports the complete `@ekklesia/contracts` barrel.
- **No forced Drizzle.** The stable SDK root does not make Drizzle a dependency of modules that do
not use it.
- **No legacy database contract.** The legacy Drizzle database contract (ADR 0016's facade type) is
not part of the standalone author-facing surface. Core still serves the legacy facade for its
deprecation window (ADR 0050). This decision only keeps its type out of what new standalone
modules build against.
- **Drizzle support lives in one place.** Drizzle-specific helpers belong to the
`@ekklesia/module-database` Drizzle adapter (ADR 0050).
### Dependency rules
These rules apply to the published packages:
- **React and ReactDOM** are peer dependencies of the public UI packages, plus development
dependencies for those packages' own builds and tests. This does not change ADR 0023: a module UI
artifact still bundles React. The peer only ensures there is one React in that bundle, the
module's own.
- **Drizzle** is an optional peer dependency only where the Drizzle adapter needs it.
- **Real implementation dependencies,** at run time or build time, remain normal dependencies.
These rules apply to a module repository:
- **Runtime and module-code packages** go in `dependencies`: the Author API packages, `@ekklesia/ui`,
React, and the module's ORM if it uses one.
- **Build tooling and configuration** go in `devDependencies`: `@ekklesia/module-ui-build`,
`@ekklesia/module-pack`, `@ekklesia/typescript-config`, and type packages.
### Versioning
- **One coordinated version during 0.x.** Every public Ekklesia module-development package uses one
release version, equal to the platform release version. The version the platform reports for
`moduleSdk` compatibility is therefore the version of the packages a module was built with.
- **No mixed trains.** Within a published train, Ekklesia-owned dependencies name the coordinated,
tested version, never a version from another train.
- **Ranges in source, exact artifacts in lockfiles.** A module may declare compatible ranges in its
source `package.json`; its lockfile pins exact artifacts with their integrity hashes.
- **`@ekklesia/module-pack` is pinned exactly.** A module repository pins it in its source
`package.json`, not only in its lockfile, because its version affects the package it produces.
- **Independent package versions are deferred.**
### Standalone packaging
- **No monorepo checkout.** A standalone module builds and packages from its own repository and its
installed dependencies.
- **Its own Node.js range.** The module declares its own Node.js compatibility, preferably in
`engines.node`, and the canonical packager reads it from there or from an explicit option. It
never requires an enclosing `pnpm-workspace.yaml`.
- **Ekklesia packages recognized by identity.** The canonical packager recognizes Ekklesia-owned
installed packages by explicit package identity and metadata, never by workspace path. So
`incorporates` and the Module SDK compatibility check (ADR 0049) work the same whether a package
came from the monorepo or from a registry. Ekklesia packages are never reported as third-party
software (ADR 0051).
- **No monorepo-root commands at install time.** Publishing workflows for the public packages run
their build in the platform's release pipeline. Nothing in a published package runs a
monorepo-root command when a consumer installs or packs it.
### Supply chain
- **Immutable versions.** A version is never republished with other content, and never withdrawn to
be reused.
- **Lockfiles.** pnpm lockfile integrity is part of the reproducibility model: modules install with a
frozen lockfile.
- **Release CI proves the tarballs before publication.** It must:
1. build and pack the public package set;
2. inspect every tarball: only the intended contents, a `LICENSE`, and no `workspace:` range;
3. install those tarballs into a clean standalone module fixture, outside any monorepo;
4. prove there that the fixture builds, packages with the canonical packager, and verifies.
Only then are the versions published.
- **Signing and provenance are deferred.**
### Registry access and the private phase
- **No secrets in module repositories.** Registry configuration for the scope is normal npm/pnpm
configuration.
- **Credentials from the environment.** Read and publish credentials come from environment or user
configuration: a read credential in module CI where reads need one, and a publish credential only
in Ekklesia's release pipeline.
- **No permanent provider.**
- **Verify access before the first publication.** Check the chosen registry's actual private and
read-access behaviour first. Ekklesia's packages must not be published unintentionally to a
registry that serves them anonymously while Ekklesia is not public.
### The release workflow
During 0.x, public package releases form a **coordinated SDK train** associated with platform
releases:
1. build;
2. pack;
3. standalone tarball smoke (see [Supply chain](#supply-chain));
4. publish immutable versions;
5. downstream module CI installs and tests those versions.
### Signage
The intended result is a normal standalone Signage repository:
- versioned `@ekklesia/*` dependencies;
- its own lockfile;
- continuous integration that installs, builds, packages, and verifies on its own.
That CI must not clone Ekklesia or place Signage under `modules/`. The migration itself is a separate
change.
## Consequences
- A module repository is an ordinary pnpm project. Clone it, install, build, and package it with the
canonical packager, with no Ekklesia checkout.
- Module authors see a smaller, deliberate API, and the platform can change its internal contracts
without breaking them.
- One coordinated version keeps compatibility simple: SDK version X is what platform version X
reports and accepts. The cost is republishing unchanged packages with each platform release.
- A registry move costs each module a configuration change and a lockfile regeneration, but no
source change. Package content stays verifiable by integrity hash throughout.
- Before the first publication, the SDK surface must be curated and the packager's two monorepo
assumptions removed. Both are breaking for code that relied on them.
- ADR 0047, still proposed, assembles a module into the platform workspace to test it. Before it is
accepted it must instead consume published packages and canonical module packages, consistent with
this decision and with ADR 0048.
## Alternatives
- **Git URL, tag, or commit dependencies.** Rejected: they tie modules to one Git host, need a build
on every install because `dist` is not committed, and cannot express version ranges.
- **Release-asset tarball URLs.** Rejected: each dependency becomes a host-specific URL, and ranges
cannot be resolved.
- **OCI artifacts for packages.** Rejected: npm and pnpm cannot install from them. (A harness image
is a different matter; see ADR 0047.)
- **Vendoring Ekklesia packages into each module repository.** Rejected: the copies drift, updates
are manual, and there would be no single canonical SDK.
- **Requiring host-neutral lockfiles, or an Ekklesia registry proxy that rewrites tarball URLs.** Not
required: a one-time lockfile regeneration on a registry move is an acceptable cost, and integrity
hashes already keep content verifiable. Ekklesia may still choose a stable endpoint later.
- **Publishing `@ekklesia/contracts` as a direct author API.** Rejected: it holds platform-wide
contracts. Modules get a curated surface through the SDK packages.
- **Externalizing React from module UI bundles to share one runtime.** Rejected again: ADR 0023's
reasoning stands, and peers only prevent duplicates within one bundle.
- **Independent versions per package now.** Deferred: during 0.x a coordinated train is simpler for
module authors and matches how the platform reports its SDK version.
## Deferred
- Provisioning a registry, and its credentials.
- Public publication on npmjs or any other public registry.
- Package signing and provenance.
- Independent package versioning.
- Dashboard and UI redesign.
- The Signage migration itself.
@@ -0,0 +1,85 @@
# 0054: Ekklesia's module-development packages are publicly readable before launch
- Status: Accepted
- Date: 2026-10-08
- Supersedes (partial): [0053](0053-standalone-module-development-packages.md) — only where it
describes the package phase before launch as private: "Gitea may host the private phase", the
read credential for module CI in "Registry access and the private phase", and its requirement
that packages not be served anonymously while Ekklesia is not public. Every other part of that ADR
remains accepted and unchanged: the npm registry protocol, the public package set and its
boundaries, the curated SDK, the dependency rules, the coordinated package train, exact release
artifacts, standalone module builds, provider portability, supply chain and immutability, and the
credential handling for publishing.
- Related: [ADR 0049](0049-module-package-v1.md)
## Context
ADR 0053 decided how Ekklesia's module-development packages (`@ekklesia/*`) are built, released, and
distributed over the npm registry protocol. It assumed that the phase before Ekklesia's public
launch would be private: module CI would carry a read credential where reads needed one, and the
first publication had to make sure the registry would not serve the packages anonymously.
Checking the chosen host before the first publication showed what keeping the packages private would
take:
- Gitea 1.27.2 decides package read access by the package **owner's** visibility, never a
repository's. The `River_of_Glory_Church` owner is a public organization, so its packages are
readable anonymously.
- That organization's repositories, Ekklesia's source among them, are already publicly readable.
- The instance allows self-registration, so "limited" visibility, readable by any signed-in user,
is readable by anyone who creates an account.
- Private packages would therefore need a separate private package owner, plus reader accounts and
read tokens for every module repository, every module's CI, and every developer.
The project owner has decided that Ekklesia is not secret. Its source is public; the project is
simply not being launched or promoted yet. Hiding the packages built from that public source would
protect nothing, and would still cost every module author an account and a token.
## Decision
1. **Ekklesia's module-development packages may be anonymously readable before the project's public
launch.** This covers the public package set of ADR 0053: search, metadata, and download.
2. **Readability is not a launch, and promises nothing more.** Public readability does not mean:
- that Ekklesia has been publicly launched;
- that the APIs are stable beyond the project's pre-1.0 SemVer policy;
- that third-party production use is supported;
- that a marketplace or public module ecosystem exists.
3. **Reading needs no authentication in this phase.** Installing `@ekklesia/*` needs no account,
reader account, read token, or authenticated install workflow. A module repository configures only
the scope's registry.
4. **Publication stays authenticated and tightly controlled.** Only Ekklesia's release process
publishes, with one dedicated publisher credential that holds nothing beyond package write
access, used only by that process, as ADR 0053's credential handling for publishing already
requires.
5. **Published versions stay immutable by Ekklesia policy.** A published version is never deleted or
republished with other bytes, whatever the registry technically allows.
6. **The current Gitea owner is an acceptable host.** The `River_of_Glory_Church` package namespace
on the current Gitea may host this phase, as long as publishing permission stays restricted to
the publisher. No private package organization is needed.
7. **A public launch is a separate decision.** Launching or promoting Ekklesia publicly, and anything
that changes for its packages then, is a product and release decision this ADR does not make.
## Consequences
- **Module authors and module CI need no Ekklesia credential.** The committed `.npmrc` scope mapping
is the whole registry configuration. ADR 0053's example of a read credential in user or CI
configuration is no longer needed in this phase.
- **ADR 0053's pre-publication access check changes meaning.** It now confirms that anonymous reads
work as intended and that publishing is refused without the publisher's permission, rather than
that reads are private. The disposable-registry suite proves both, and the publication tool can
require an anonymous download to match each published artifact.
- **Restricting publishing is now the whole access boundary**, so the publisher credential's scope,
where it is held, and who can reach it matter all the more.
- **Making the packages private again would be a new decision.** Package names, versions, and
contents already published stay public, because a published version is never deleted.
## Alternatives considered
- **A private package organization on the same Gitea.** Rejected: it hides nothing that is not
already public in the source, and it requires reader accounts and tokens for every module
repository, its CI, and every developer.
- **"Limited" package visibility.** Rejected: with self-registration open, anyone can read anyway,
while the configuration suggests otherwise.
- **Requiring sign-in for the whole instance.** Rejected: it would also hide the public
repositories.
- **Another registry for a private phase.** Unnecessary once reads are public.
+4
View File
@@ -59,3 +59,7 @@ ADRs capture durable choices that affect more than one package or phase.
- [0048: Ekklesia ships one generic image, and installed modules live outside it](0048-generic-image-and-installed-module-storage.md) — Accepted - [0048: Ekklesia ships one generic image, and installed modules live outside it](0048-generic-image-and-installed-module-storage.md) — Accepted
- [0049: A module release is one immutable, self-contained package: Ekklesia Module Package v1](0049-module-package-v1.md) — Accepted - [0049: A module release is one immutable, self-contained package: Ekklesia Module Package v1](0049-module-package-v1.md) — Accepted
- [0050: Module Database ABI v1: modules and Core exchange SQL, never ORM objects](0050-module-database-abi-v1.md) — Accepted - [0050: Module Database ABI v1: modules and Core exchange SQL, never ORM objects](0050-module-database-abi-v1.md) — Accepted
- [0051: Module packages declare their own license and carry its text](0051-module-package-license-material.md) — Accepted
- [0052: Reviewed license supplements cover redistributed dependencies whose packages omit required material](0052-reviewed-license-supplements.md) — Proposed
- [0053: A module builds outside the monorepo, from Ekklesia packages published over the npm registry protocol](0053-standalone-module-development-packages.md) — Accepted
- [0054: Ekklesia's module-development packages are publicly readable before launch](0054-public-package-reads-before-launch.md) — Accepted
+27 -10
View File
@@ -609,7 +609,7 @@ a sandbox: it is `open` precisely because module code is trusted, same-realm cod
[ADR 0041](decisions/0041-module-browser-contributions.md) lets one module contribute a browser [ADR 0041](decisions/0041-module-browser-contributions.md) lets one module contribute a browser
renderer to a capability another module provides — the browser half of the capability system Core has renderer to a capability another module provides — the browser half of the capability system Core has
had since ADR 0006. `manifestVersion: 7` declares a namespaced id, its own version, a target had since ADR 0006. `manifestVersion: 8` declares a namespaced id, its own version, a target
capability, a compatible range, and one artifact. That is the complete list: there is no payload capability, a compatible range, and one artifact. That is the complete list: there is no payload
schema, slot, ordering, or rendering hint anywhere in the platform, so Core cannot learn what a schema, slot, ordering, or rendering hint anywhere in the platform, so Core cannot learn what a
"slide" is because the declaration cannot express it. Discovery resolves the artifact through the "slide" is because the declaration cannot express it. Discovery resolves the artifact through the
@@ -679,14 +679,31 @@ Module Package v1, a deterministic `.tar.gz` with its SHA-256.
- **The packager.** `@ekklesia/module-pack` bundles the module's backend with every pure-JavaScript - **The packager.** `@ekklesia/module-pack` bundles the module's backend with every pure-JavaScript
dependency, the SDK, contracts, and Drizzle included. It copies the built browser artifacts and dependency, the SDK, contracts, and Drizzle included. It copies the built browser artifacts and
migrations, generates the runtime `package.json`, `ekklesia.package.json` with every file's digest, migrations, generates the runtime `package.json`, `ekklesia.package.json` with every file's digest,
and `THIRD_PARTY_NOTICES`, and writes the archive. copies the explicitly supplied module `LICENSE` bytes, generates `THIRD_PARTY_NOTICES` for bundled
third parties, and writes the archive. The source module's string SPDX expression is required and
becomes the package metadata's authoritative `license`; the packager neither infers nor downloads
license material.
- **Native target (`linux-x64-glibc`).** Native or platform-specific dependencies stay outside
the bundle. Each one is copied with exactly its production runtime closure, as real files flat
under the package's `node_modules/`, and only the platform packages that match the target are
included. The package's `runtime` records the Node-API version and minimum glibc version, both
read from the native binaries themselves.
- **License supplements.** Where a redistributed dependency omits required licence material,
reviewed supplements checked in with the packager add it
([ADR 0052](decisions/0052-reviewed-license-supplements.md)). Each supplement matches one exact
package name, version, and content digest; anything else fails closed.
- **The verifier.** Core's `verifyModulePackage` reads the archive in memory and refuses links, - **The verifier.** Core's `verifyModulePackage` reads the archive in memory and refuses links,
special files, and escaping paths. It checks every digest and identity, the target and runtime, special files, and escaping paths. It checks every digest and identity, the target and runtime,
and the transitional Drizzle agreement, runs the platform's own module and migration validation, runs the platform's own module, schema, and migration validation, and loads the backend once in a
and loads the backend once in a short-lived process with an empty environment. Only then does it short-lived process with an empty environment. Only then does it extract anything.
extract anything. - **A native package's host checks.** It is accepted only on a host whose operating system, CPU,
- **What exists today.** Only the `any` target. Drizzle agreement is recorded as transitional, not a C library family and version, and Node-API version Node.js itself reports as compatible.
database ABI. [ADR 0050](decisions/0050-module-database-abi-v1.md) defines the Module Database ABI - **ELF files.** Every ELF file in it must be built for the target's machine.
that removes it for modules that declare that ABI. Core's ABI v1 executor - **What an `any` package may not hold:** `node_modules`, addons, and ELF files.
(`createModuleDatabaseExecutor`) exists and is proven against PostgreSQL. No module can declare the - **What exists today.** The `any` and `linux-x64-glibc` targets. No other operating system or CPU
ABI or receive the executor yet: that needs manifest version 8. target exists yet. A manifest-v8 ABI module carries no
`transitional.databaseRuntime`; Drizzle may be bundled as its private implementation detail, and
Core validates plain schema metadata without comparing ORM versions. A version 8 module that
omits `database` remains on the temporary legacy facade and keeps ADR 0049's exact transitional
Drizzle agreement. The canonical template now demonstrates ABI v1. The legacy facade still
exists.
+10 -5
View File
@@ -136,11 +136,16 @@ These rules map platform ownership to filesystem and package boundaries. The exe
declared by the consumer. declared by the consumer.
- Code a workspace package ships (its `src/` and `bin/`, excluding tests and declaration files) - Code a workspace package ships (its `src/` and `bin/`, excluding tests and declaration files)
declares every runtime import in `dependencies` or `optionalDependencies`. A peer declaration may declares every runtime import in `dependencies` or `optionalDependencies`. A peer declaration may
stay beside it, but never replaces it: a workspace package is linked into its consumers as a stay beside it, but ordinarily never replaces it: a workspace package is linked into its consumers
directory, so its imports resolve from its own `node_modules`, where a consumer never satisfies a as a directory, so its imports resolve from its own `node_modules`, where a consumer never
peer, and a production install (`pnpm install --prod`, as the production image runs) omits satisfies a peer, and a production install (`pnpm install --prod`, as the production image runs)
development dependencies. Type-only imports are exempt; a `.tsx`/`.jsx` file counts as importing omits development dependencies. There are two narrow exceptions, each for one package and one
`react`, because the automatic JSX runtime imports `react/jsx-runtime` implicitly peer. `@ekklesia/module-database`'s `drizzle-orm` peer: modules choose that compatible runtime and
the Module Package v1 bundler incorporates it into their self-contained backend; Core never loads
the adapter package. And `@ekklesia/ui`'s `react` peer (ADR 0053): the shared elements are only
ever bundled into browser artifacts, and the consumer's own React must be the one in the bundle;
no production Node.js process loads them. Type-only imports are exempt; a `.tsx`/`.jsx` file counts as importing `react`,
because the automatic JSX runtime imports `react/jsx-runtime` implicitly
(`runtime-imports-are-production-dependencies`). (`runtime-imports-are-production-dependencies`).
- Workspace aliases are forbidden because they obscure package ownership in the dependency graph. - Workspace aliases are forbidden because they obscure package ownership in the dependency graph.
- Workspace package names are unique and shared packages declare a recognized architectural role. - Workspace package names are unique and shared packages declare a recognized architectural role.
+2 -1
View File
@@ -1403,7 +1403,8 @@ stays declarative and database-free. See
contract; this section covers only how `apps/api` composes and wires it. contract; this section covers only how `apps/api` composes and wires it.
- **`ModuleDatabase`.** A restricted, typed view over `NodePgDatabase` - **`ModuleDatabase`.** A restricted, typed view over `NodePgDatabase`
(`packages/contracts/src/module-database.ts`), exposing exactly `select`, `selectDistinct`, (`core/src/modules/database.ts`, Core's own type: no published package references Drizzle, per
ADR 0053), exposing exactly `select`, `selectDistinct`,
`selectDistinctOn`, `insert`, `update`, `delete`, `execute`, and `transaction`, each preserving `selectDistinctOn`, `insert`, `update`, `delete`, `execute`, and `transaction`, each preserving
Drizzle's own table-aware argument and result inference. It exposes no `$client`, no internal Drizzle's own table-aware argument and result inference. It exposes no `$client`, no internal
session/dialect state, no schema-bound relational `query` builder, and no connection string, session/dialect state, no schema-bound relational `query` builder, and no connection string,
+1 -1
View File
@@ -138,7 +138,7 @@ enforces those permissions while the module is disabled, because it mounts no ro
## Module permission composition ## Module permission composition
A module manifest's `permissions` array (introduced in `manifestVersion: 4`; the current strict A module manifest's `permissions` array (introduced in `manifestVersion: 4`; the current strict
manifest is version 7 — see manifest is version 8 — see
[Module development](../module-development/README.md#canonical-manifest)) declares permissions in [Module development](../module-development/README.md#canonical-manifest)) declares permissions in
the exact same `PermissionDeclaration` shape — but declaring one there only proves it is the exact same `PermissionDeclaration` shape — but declaring one there only proves it is
well-formed and correctly namespaced under the module's own id; it does not, by itself, register well-formed and correctly namespaced under the module's own id; it does not, by itself, register
+370
View File
@@ -0,0 +1,370 @@
# Releases and the public package train
An Ekklesia platform release is one version. The platform image, the private workspace packages,
and the public `@ekklesia/*` module-development packages all carry it. This page covers the order a
release happens in and the public package train
([ADR 0053](../architecture/decisions/0053-standalone-module-development-packages.md)): how its
artifacts are produced, what proves them, and how exactly those artifacts are published.
> **The packages are publicly readable, on purpose**
> ([ADR 0054](../architecture/decisions/0054-public-package-reads-before-launch.md)). Anyone can
> search, read, and install `@ekklesia/*` from the registry with no account and no token, like any
> public npm package. That is not a public launch: Ekklesia's source is already publicly readable,
> and the project is simply not promoted yet. Only **publishing** is restricted, to one manual,
> authenticated workflow. Before 1.0, the APIs may change between versions under the project's
> SemVer policy: a 0.x minor version may break them.
## Where each step sits
```text
version set ─▶ build ─▶ test ─▶ pack the public package train ─▶ standalone consumer proof
│
tag and release (maintainer) ◀─ publish the exact train (manual) ◀───┘
```
1. **Version set.** A `chore(release): prepare X` pull request sets the release version: the root
`package.json`, every platform workspace package (the module template versions as a module, not
with the platform), the image build example in `deploy/README.md`, and the standalone fixture's
exact `@ekklesia/module-pack` pin and `@ekklesia/*` ranges
(`tests/fixtures/standalone-module/package.json`). The tag must point at a commit that carries
the version it names.
A minor version (0.x → 0.(x+1)) is a breaking release before 1.0, so manifests that declare
`compatibility.platform` and `compatibility.moduleSdk` as `^0.x.0` no longer match it. In the
same pull request, move to the new range every module built for this release (the template, the
standalone fixture, the native proof module), the test fixtures that model a module of the
current release or the current platform, and the module-development guide's examples. A patch
version changes none of these.
2. **Build and test.** `pnpm verify`, the integration suite, and the deploy smoke, as for any change.
3. **Pack the public package train.** `pnpm packages:release` (below).
4. **Standalone consumer proof.** A module outside the repository consumes exactly those
artifacts (below).
5. **Publish the exact train.** By hand, with the `Publish packages` workflow on the version-set
commit on `main` ([Publishing the train](#publishing-the-train)). It publishes the artifacts its
own run's gate (steps 3 and 4) proved, and nothing else.
6. **Tag and release.** Unchanged: the maintainer tags the merge commit of the version-set pull
request. Nothing here creates, moves, or requires a tag.
Steps 2 to 4 run in CI on every pull request and on `main`, and CI also publishes each proven train
to a disposable registry (`package-publication`), never the real one. Step 5 runs only when a
maintainer starts it.
## The public package train
| Package | Role |
| --- | --- |
| `@ekklesia/module-sdk`, `@ekklesia/module-database`, `@ekklesia/module-ui-sdk`, `@ekklesia/design-tokens` | author API |
| `@ekklesia/module-ui-build`, `@ekklesia/module-pack`, `@ekklesia/typescript-config` | tooling |
| `@ekklesia/ui` | publishable, pre-1.0 component API |
| `@ekklesia/contracts` | implementation dependency of the packages above: published only because they need it, never a supported direct dependency of a module |
The list lives in `scripts/package-release.ts` (`PUBLIC_PACKAGES`). Every other workspace package is
`private`, and the release builder refuses to run if a package outside the list is publishable or
carries the `module-development` distribution marker.
- **One version.** Every package in the train has the platform release version.
- **One train.** Every `@ekklesia/*` dependency in a packed manifest names a package of the same
train at exactly that version. `workspace:` ranges become those exact versions when packed.
- **No independent versions.** A package cannot be released on its own.
## Producing the release artifacts
```bash
pnpm packages:release # writes .package-release/ekklesia-packages-<version>/
```
`scripts/package-release.ts`:
1. **Refuses a modified source tree, before it builds anything.** A release is built from a
commit. A tree is clean when `git status` shows no change to a tracked file and no untracked file
that Git does not ignore. Ignored files are build output and package-manager state:
`node_modules`, `dist`, `.turbo`, and pnpm's `.pnpm-store`, which pnpm creates at the checkout's
root when the checkout is its own mount (a CI runner's workspace volume). The failure lists every
change. `--allow-modified` exists for local development only; its manifest then says
`"modified": true`, and such a release must never be published.
2. **Checks the release set and versions** in the workspace.
3. **Rebuilds from clean output.** It removes each public package's `dist/` and rebuilds without the
build cache, so output from a deleted source file can never ship. It then checks the source tree
again: a build that changed a tracked file, or wrote an untracked one Git does not ignore, fails
the release, because what is packed must be exactly the commit.
4. **Packs each package with `pnpm pack`.** Pack-only pnpm hooks (`scripts/lib/pack-hooks.cjs`)
apply, never the workspace's install settings ([Reproducibility](#reproducibility)).
5. **Inspects every tarball.** It checks:
- the expected name, version, and file name;
- a `LICENSE`, and only the `files` the manifest declares, each built file with the source it
came from, and no source, test, or configuration file;
- no `workspace:` range, no `devDependencies`, no `publishConfig`, and no install-time lifecycle
script;
- only public `@ekklesia/*` dependencies, at the train's version;
- the distribution marker;
- no local path (the checkout, the home directory, or the temporary directory) in any file.
6. **Checks the set.** The release must hold exactly the expected tarballs: none missing, none extra.
7. **Writes the release directory only when everything passed,** in one step. It refuses to
overwrite one that exists.
```text
ekklesia-packages-<version>/
├── ekklesia-contracts-<version>.tgz
├── ekklesia-design-tokens-<version>.tgz
├── … one .tgz per package in the train
├── SHA256SUMS `sha256sum -c SHA256SUMS` compatible
└── ekklesia-package-train.json the release manifest
```
### The release manifest
`ekklesia-package-train.json` describes the train by content. It is provider-neutral: it names no
registry and is not a registry catalog.
```json
{
"packageTrain": 1,
"version": "0.2.0",
"source": { "modified": false, "revision": "<full commit id>" },
"packages": [
{
"file": "ekklesia-contracts-0.2.0.tgz",
"integrity": "sha512-<base64>",
"name": "@ekklesia/contracts",
"role": "implementation",
"sha256": "<hex>",
"size": 87379,
"version": "0.2.0"
}
]
}
```
`integrity` is the npm `dist.integrity` form: a registry computes the same value from the same
bytes, and a module's lockfile records it. The packages are sorted by name, and the file's bytes
depend only on the commit.
## Proving the artifacts
```bash
pnpm test:package-release # scripts/test-package-release.sh
```
1. **Builds the train** from this checkout. Nothing is built before it.
2. **Builds it again** from a second worktree of the same commit at another absolute path, and
requires both release directories to be byte-identical: every tarball, `SHA256SUMS`, and the
manifest.
3. **Builds Core's verifier**, then **runs the standalone consumer proof** (`scripts/test-standalone-module.sh --release <dir>`) on
that release:
- **The release is checked first.** Every artifact must match the manifest's size, SHA-256, and
integrity, and the release must not be built from a modified tree.
- **The fixture module installs from those tarballs alone.** It is
`tests/fixtures/standalone-module`, copied outside the repository. Every `@ekklesia/*`
package, direct or transitive, resolves to its release tarball. There is no workspace link and
no Ekklesia source checkout. The install runs offline: third-party packages come from the
workspace install's own pnpm store, named explicitly because pnpm otherwise picks a store per
file system, so no registry is involved at all.
- **The lockfile matches the release.** It must record each artifact's own integrity. The module
then reinstalls from the lockfile alone with `--frozen-lockfile`.
- **The install has the right shape.** There is no `drizzle-orm`, and exactly one `react`, which
`@ekklesia/ui` resolves to as well. `@ekklesia/contracts` is installed only transitively: it is
not in the module's `package.json` and not directly under `node_modules/@ekklesia`. Every
installed `@ekklesia/*` package, `module-pack` included, is exactly the release version, and
the fixture pins `module-pack` exactly.
- **The module builds.** It typechecks with `skipLibCheck: false`, so every published declaration
it reaches is checked, then builds its backend and UI.
- **It packages and verifies.** It is packed with the release's own `ekklesia-pack-module`, with
no workspace file present. Core's verifier then verifies it. The package must:
- incorporate the train's packages at the release version;
- name the release's module-pack as its packager;
- credit no Ekklesia package and exactly one React;
- contain no local path.
## Reproducibility
Two builds of the same commit produce byte-identical tarballs, and CI proves it on every run.
- **pnpm normalizes the tar entries.** Every entry gets the fixed modification time 1985-10-26, owner
0, and a mode of 0644, or 0755 when executable. The gzip header records no time.
- **The build output is deterministic,** and source maps use relative paths.
- **One nondeterminism came from pnpm itself.** pnpm rewrites `workspace:` ranges concurrently and
inserts each dependency as its lookup resolves. A package with more than one `workspace:`
dependency in one field could therefore be packed with those keys in a different order. Builds
from two checkouts of one commit differed in exactly that way: `@ekklesia/module-pack`'s
`package.json` ordered `@ekklesia/module-sdk` and `@ekklesia/module-database` differently.
- **The fix is pnpm's own hook.** The pack-only `beforePacking` hook puts each dependency map back
in the source `package.json`'s key order. It changes no name, range, or field. The tarball stays
an ordinary `pnpm pack` tarball.
- **The inspection enforces it.** It fails any packed map whose order differs from its source.
- **The hook also drops `devDependencies`** from packed manifests. A consumer never installs them,
and a tooling package's test-only development dependencies named private workspace packages
outside the train.
**What reproducibility does not cover:**
- The module package the consumer proof builds is deterministic only for a fixed install layout.
pnpm names a `file:` tarball's install directory after its path, and bundlers keep those names in
comments. So the proof always installs from the same relative path. From a registry, the directory
is simply `<name>@<version>`.
- Byte identity is proven for the pinned toolchain: Node.js from `.node-version`, and pnpm from
`packageManager`. Another Node.js or zlib build may compress differently. Each artifact's
integrity is recorded either way, and that, not byte identity, is what a publication step must
verify.
## Publishing the train
The registry is the Gitea npm registry under the `River_of_Glory_Church` owner:
```text
https://git.riverofglorymn.org/api/packages/River_of_Glory_Church/npm/
```
| Who | May |
| --- | --- |
| Anyone, signed in or not | search, read metadata, download, and install `@ekklesia/*` |
| The publisher account, through the publish workflow | publish new versions and move dist-tags |
| Anyone else | nothing more: publishing needs the publisher team's package write permission |
### The workflow
`.github/workflows/publish-packages.yml` (Actions → Publish packages → Run workflow, on `main`,
with the release version). Nothing else can start it: no pull request or push does, and CI holds no
registry credential at all.
1. **The gate.** `package-release` runs the same credential-free gate as CI (build, reproduce,
consume) and hands the proven release on as a workflow artifact, with its manifest's SHA-256.
2. **The publish job.** It builds and installs nothing. It downloads the artifact and runs
`scripts/publish-package-train.ts` with the secret `EKKLESIA_PACKAGES_PUBLISH_TOKEN`, which only
this step receives.
3. **The publication record** is kept as an artifact of the run.
### What the publication tool does
`scripts/publish-package-train.ts` publishes exactly the `.tgz` files in the release directory. It
never builds, packs, or edits a package, and it never deletes, unpublishes, or overwrites anything.
1. **Validates the whole train before sending anything.** The manifest must be the one the gate
proved (`--manifest-sha256`), for the requested version and this commit (`--revision`), from a
clean tree (`"modified": false`), with exactly the nine expected packages. Every artifact's file
name, size, SHA-256, integrity, `SHA256SUMS` line, and the `package.json` inside it must match.
2. **Publishes in dependency order.** Each package comes after the train packages it depends on,
then alphabetically. For each package:
- **absent:** `npm publish <file.tgz>` under the staging dist-tag `ekklesia-staging`, given the
artifact's absolute path (npm runs in a temporary directory of its own), after the file is
checked once more against the manifest. npm sends the file's own bytes and runs no script for a
file; the registry checks them against their integrity and stores them as they are;
- **present with the same bytes:** accepted as already published, and verified;
- **present with other bytes:** a hard stop. Nothing is deleted or overwritten, nothing after it
is published, and the version is burned ([Immutability](#immutability)).
3. **Reads every package back.** The registry's metadata must name the package and version, report
the artifact's integrity, and list the same `dependencies`, `peerDependencies`,
`optionalDependencies`, and `bin` as the tarball's `package.json` (npm writes `bin` paths without
a leading `./`). Its tarball URL must be on the configured registry, and the tarball it serves must
be the release artifact, byte for byte. With `--require-public-read`, an anonymous download must
give the same bytes too. A package is published only once all of that holds.
4. **Moves `latest` last.** Only when all nine are verified does `latest` move to the train, never
backwards past a newer version. The train is published when every package's `latest` agrees.
5. **Writes the publication record** (`--record`).
A rerun is always safe. It publishes only what is missing, accepts what is already there and
identical, and moves only the tags that are not yet right. A train interrupted after five packages,
or after four tags, finishes on the next run. No retry ever deletes anything.
### The publication record
Evidence that one train was published, not a second package catalog, and never a secret:
```json
{
"publicationRecord": 1,
"packageTrain": { "version": "0.2.0", "revision": "<commit>", "manifestSha256": "<hex>" },
"registry": "https://git.riverofglorymn.org/api/packages/River_of_Glory_Church/npm/",
"finalTag": "latest",
"completedAt": "<ISO time>",
"packages": [
{
"name": "@ekklesia/contracts",
"version": "0.2.0",
"file": "ekklesia-contracts-0.2.0.tgz",
"outcome": "published",
"artifact": { "sha256": "<hex>", "integrity": "sha512-…", "size": 87379 },
"registry": { "tarball": "<url>", "sha256": "<hex>", "integrity": "sha512-…", "publicRead": true },
"finalTag": "moved",
"distTags": { "ekklesia-staging": "0.2.0", "latest": "0.2.0" }
}
]
}
```
`outcome` is `published` or `already-present`. `finalTag` is `moved`, `already-current`, or
`kept-newer` (a newer version already holds `latest`).
### Credentials
- **One credential:** `EKKLESIA_PACKAGES_PUBLISH_TOKEN`, a repository Actions secret, used only by
the publish step. Nobody needs a token to read or install.
- **The publisher** is a dedicated account, member only of a `River_of_Glory_Church` team whose one
permission is Packages: Write. Its token has only the `write:package` scope. Gitea's
`write:package` also allows deleting packages; the tool never does, and nothing else uses the
token.
- **No token in git or in an `.npmrc`.** The tool writes a temporary npm configuration that refers to
the variable (`_authToken=${EKKLESIA_PACKAGES_PUBLISH_TOKEN}`), ignores every user, global, and
project npm configuration, sends the token only to the registry itself, and removes the
configuration afterwards.
- **What remains trusted:** Gitea gives repository secrets to workflows run for pull requests from
branches of this same repository, so anyone who can push a branch here could read the secret
through a changed workflow. Keep write access to this repository to the maintainers.
### Immutability
Gitea refuses to upload a version that exists (409). But it lets anyone with package write
permission delete a version, deletion leaves nothing behind, and an owner's package cleanup rules
can delete versions on a schedule. So immutability is Ekklesia's policy, not the registry's
guarantee:
- **A published version is never deleted,** by anyone, for any reason short of a security incident.
- **A version number is never reused with other bytes.** A version found on the registry with other
bytes is burned: investigate how it got there, and publish the train under a new version.
- **No package cleanup rule** may be configured for the `River_of_Glory_Church` owner.
- **The publisher never deletes.** The tool has no delete, unpublish, or overwrite, and its tests
check that.
Module lockfiles record each package's integrity, so a replaced package would fail every install of
it, rather than install silently.
### Moving to another registry
Only configuration changes: the registry URL (the workflow's `EKKLESIA_PACKAGES_REGISTRY`), the
publisher credential, and modules' `@ekklesia:registry`. Modules then regenerate their lockfiles,
because Gitea's tarball URLs are its own. Package sources, the train, its manifests, and every
artifact already built stay as they are; the same bytes keep the same integrity.
### Proving the publication machinery
`pnpm test:package-publication` (`scripts/test-package-publication.sh`, the CI `package-publication`
job) publishes a real release train to a disposable Gitea 1.27.2 configured like the real one:
public owners, a publisher team, and an outsider. In CI it publishes the very artifact the
`package-release` job handed on, after checking its manifest hash. It proves:
- anonymous search, metadata, and download work;
- publishing without credentials, or by a user outside the publisher team, fails;
- the round trip is byte-identical, also anonymously;
- the registry refuses a second upload of a published version;
- a train interrupted before its sixth package resumes, verifying the five and publishing the rest,
with `latest` untouched until all nine are verified;
- a version already published with other bytes stops the train, deleting and overwriting nothing,
and publishing nothing after it, on every retry;
- a train interrupted while moving `latest` converges on a rerun, moving only the missing tags.
### The first publication
The first train published is **0.2.0**, the next platform release, not 0.1.2. The `v0.1.2` tag
predates the curated SDK and this release tooling, so packages built now and called 0.1.2 would
claim to be source that 0.1.2 never contained.
Before it, an administrator of the Gitea instance:
1. creates the dedicated publisher account;
2. creates a `River_of_Glory_Church` team, for example `package-publishers`, with only the Packages
unit at Write, and adds the account to it;
3. creates a token for the account with only `write:package`, and stores it as the repository
Actions secret `EKKLESIA_PACKAGES_PUBLISH_TOKEN`;
4. checks that the owner has no package cleanup rule.
Then the release proceeds as usual: the version-set pull request merges, a maintainer starts
Publish packages on `main` with that version, and tags the commit once the train is published.
+63 -12
View File
@@ -598,24 +598,74 @@ CI / migration-smoke (pull_request)
Ekklesia Module Package v1 (ADR 0049) is proven at three levels, all in `pnpm verify`: Ekklesia Module Package v1 (ADR 0049) is proven at three levels, all in `pnpm verify`:
- `packages/contracts/tests/module-package.test.ts`: the `ekklesia.package.json` schema, target - `packages/contracts/tests/module-package.test.ts`: the `ekklesia.package.json` schema, required
names, and the generated runtime `package.json`. SPDX expression and `LICENSE` inventory entry, target names, and the generated runtime
`package.json`.
- `core/tests/module-package-verification.test.ts`: the verifier against hand-built archives, - `core/tests/module-package-verification.test.ts`: the verifier against hand-built archives,
including what the packager never produces. A valid package verifies and extracts with normalized including what the packager never produces. A valid package verifies and extracts with normalized
modes. A wrong digest, a corrupted or missing or unlisted file, disagreeing identities, an unknown modes. A wrong digest, a corrupted or missing or unlisted file, disagreeing identities, an unknown
format, unknown transitional metadata, an incompatible target, Node.js range, SDK, or database format, unknown transitional metadata, an incompatible target, Node.js range, SDK, or legacy
runtime, a missing entrypoint, a backend that imports something the package lacks, absolute and database runtime, ABI metadata carrying a forbidden transitional runtime, malformed ABI schema
metadata, missing or malformed license metadata, missing, unlisted, duplicated, or corrupted
`LICENSE`, a missing entrypoint, a backend that imports something the package lacks, absolute and
`..` paths, symbolic and hard links, device nodes and FIFOs, setuid and setgid entries, a second `..` paths, symbolic and hard links, device nodes and FIFOs, setuid and setgid entries, a second
top-level directory, and a duplicate entry each fail with their own sanitized code. The backend top-level directory, and a duplicate entry each fail with their own sanitized code. The backend
load check runs in a real child process. load check runs in a real child process and selects the schema contract from the manifest.
- `packages/module-pack/tests/native-target.test.ts`: the `linux-x64-glibc` target, with a real
native dependency (`sharp`). The checked-in proof module (`tests/fixtures/native-module`) is
packed, and the test proves:
- the package carries exactly sharp's discovered runtime closure, as real files;
- nothing from another platform, and no development dependency, is included;
- `runtime` matches what the binaries declare;
- the reviewed libvips supplement is merged and labelled;
- two packs from unrelated copies are byte-identical.
Core's own verifier then accepts the package, and the extracted package runs a real image
operation in a separate process with an empty environment. Node's resolution hooks and the
process's memory map show that nothing resolves or loads from outside the package except the
host's system libraries.
- `packages/module-pack/tests/native-closure.test.ts` breaks the closure rules one at a time, with
fake native packages built around the real sharp addon's bytes:
- which platform packages are kept and which are left out;
- missing and foreign-platform dependencies;
- version conflicts, links, a foreign machine, and Node.js range conflicts;
- an unneeded native target.
- `packages/module-pack/tests/supplements.test.ts` proves ADR 0052's mechanism:
- the documented content-digest algorithm;
- that the loader refuses anything unreviewed;
- that supplement material is merged after the package's own and labelled;
- that a supplement for another version, digest, or licence fails closed;
- that the shipped libvips supplement is intact and pins the installed package exactly.
- `packages/module-pack/tests/`: the packager against generated fixture modules (payload contents, - `packages/module-pack/tests/`: the packager against generated fixture modules (payload contents,
generated `package.json`, metadata, bundled backend with only built-in imports, refusal of native generated `package.json`, metadata, bundled backend with only built-in imports, refusal of native
and platform-specific dependencies and of unknown or textless licences, notices, byte-identical and platform-specific dependencies and of unknown or textless third-party licences, explicit
archives, normalized tar and gzip headers), and end to end against the built module template: module SPDX and license-file validation, unchanged `LICENSE` bytes and inventory digest, notices,
byte-identical archives, normalized tar and gzip headers), and end to end against the built module template:
packed twice to identical bytes without changing the workspace's install state, verified by Core's packed twice to identical bytes without changing the workspace's install state, verified by Core's
verifier, extracted elsewhere, and loaded with Node's own resolution hooks proving nothing outside verifier with a deliberately different Core Drizzle version, extracted elsewhere, and loaded with
the package is resolved. Turbo builds the template and Core first, and runs the template's own Node's own resolution hooks proving nothing outside the package is resolved. The package contains
tests (which rebuild its UI in place) before these. the repository's exact AGPL `LICENSE`, authoritative `AGPL-3.0-or-later` metadata, module-side
Drizzle but no `transitional.databaseRuntime`, and no tooling-only SPDX parser dependency. Turbo
builds the template and Core first, and runs the template's own tests (which rebuild its UI in
place) before these.
## The public package train
`pnpm test:package-release` (the CI `package-release` job) builds the public `@ekklesia/*` package
train, proves a second build from another checkout of the commit byte-identical, and installs
exactly those tarballs into the standalone fixture module, offline, which must typecheck with
`skipLibCheck: false`, build, package, and verify. It needs a clean source tree; pass
`-- --allow-modified` to try uncommitted changes locally. The release rules themselves (set,
versions, manifest inspection, release directory, manifest bytes, the pack hook) are unit-tested in
`tests/public-packages.test.ts`, part of `pnpm verify`. See
[Releases and the public package train](releases.md).
`pnpm test:package-publication` (the CI `package-publication` job, given the `package-release` job's
artifact) publishes a release train to a disposable Gitea 1.27.2 with Docker, never the real
registry, and proves the publication tool: byte-identical round trips, anonymous reads, refused
unauthorized publishing, partial-train recovery, the hard stop on a burned version, and dist-tag
convergence (`tests/package-publication.integration.ts`). The tool's own rules are unit-tested in
`tests/package-publication.test.ts`, part of `pnpm verify`.
## The generic platform image and the reference deployment ## The generic platform image and the reference deployment
@@ -634,8 +684,9 @@ These need Docker and build images locally; nothing is pushed or published.
- `pnpm deploy:smoke` (`scripts/smoke-deploy.sh`) runs the reference deployment end to end on the - `pnpm deploy:smoke` (`scripts/smoke-deploy.sh`) runs the reference deployment end to end on the
generic image with empty module storage. With `EKKLESIA_SMOKE_TOPOLOGY=split`, the same image also generic image with empty module storage. With `EKKLESIA_SMOKE_TOPOLOGY=split`, the same image also
runs the installed-module lifecycle: runs the installed-module lifecycle:
- the module template is packaged by the canonical packager (Module Package v1, ADR 0049), - the module template is packaged by the canonical packager (Module Package v1, ADR 0049 and
verified by the image's own verifier, and installed into module storage; ADR 0051), with its explicit AGPL declaration and license bytes, as ABI v1, verified by the
image's own verifier, and installed into module storage;
- its migration is planned and explicitly applied, and the API restarted; - its migration is planned and explicitly applied, and the API restarted;
- a real browser mounts it; - a real browser mounts it;
- it is removed and the API restarted, and Core still runs, migrations still plan and apply, and - it is removed and the API restarted, and Core still runs, migrations still plan and apply, and
+326 -46
View File
@@ -66,8 +66,126 @@ module with no migration history omits `entrypoints.migrations` and needs no pla
} }
``` ```
The package version must match the manifest and runtime-definition versions. Internal package The package version must match the manifest and runtime-definition versions. Inside this
dependencies use `workspace:` ranges and supported public package entrypoints. repository, Ekklesia package dependencies use `workspace:` ranges and supported public package
entrypoints. A module in its own repository depends on the published packages instead
([Developing a module in its own repository](#developing-a-module-in-its-own-repository)).
### Developing a module in its own repository
> **Status:** the packages are published by release
> ([ADR 0053](../architecture/decisions/0053-standalone-module-development-packages.md),
> [Releases and the public package train](../development/releases.md)). The first published train
> is 0.2.0, the platform release after 0.1.2.
A module does not need an Ekklesia checkout. Do not clone Ekklesia and put your module in its
`modules/` directory: your module is its own repository, and it depends on Ekklesia's
module-development packages like any other npm packages.
The packages are **publicly readable**
([ADR 0054](../architecture/decisions/0054-public-package-reads-before-launch.md)): installing them
needs no account, no token, and no access to Ekklesia's Gitea. That is not a public launch, and it
promises no API stability beyond the pre-1.0 SemVer policy. Only Ekklesia's release workflow can publish them. Point the `@ekklesia` scope at
the registry in your repository's committed `.npmrc`; that is all the configuration there is:
```ini
@ekklesia:registry=https://git.riverofglorymn.org/api/packages/River_of_Glory_Church/npm/
```
Then the module builds and packages like any other:
```bash
pnpm install
pnpm build
pnpm exec ekklesia-pack-module --module . --target any --out ../packages \
--license-file ./LICENSE --source-revision "$(git rev-parse HEAD)"
```
Before 1.0, a minor version may change these APIs (the project's SemVer policy). Pin the train you
build against with ranges in `package.json` and exact versions in your lockfile.
| Package | Where it goes | What it is |
| --- | --- | --- |
| `@ekklesia/module-sdk` | `dependencies` | `defineModuleRuntime`, routes, configuration, storage, realtime, principals |
| `@ekklesia/module-database` | `dependencies` | Module Database ABI v1 types, `sql`, schema metadata; `/drizzle` for Drizzle |
| `@ekklesia/module-ui-sdk` | `dependencies` | `defineModuleUi` and the host context |
| `@ekklesia/design-tokens` | `dependencies` | design-token names and helpers |
| `@ekklesia/ui` | `dependencies` | shared elements; a pre-1.0 API that may still change |
| `react`, `react-dom`, your ORM if any | `dependencies` | your own copies, bundled into your artifacts |
| `@ekklesia/module-ui-build` | `devDependencies` | `ekklesia-build-module-ui` |
| `@ekklesia/module-pack` | `devDependencies`, **exact version** | `ekklesia-pack-module` |
| `@ekklesia/typescript-config` | `devDependencies` | `node.json`, `browser-react.json`, ... |
`@ekklesia/contracts` is not a direct dependency. The packages above install it; never add or
import it yourself, because what it exports is the platform's, not a supported author API.
```json
{
"name": "@acme/notes",
"version": "0.1.0",
"license": "AGPL-3.0-or-later",
"private": true,
"type": "module",
"engines": { "node": ">=24.11.0 <25" },
"scripts": {
"build": "tsc --project tsconfig.build.json && ekklesia-build-module-ui"
},
"dependencies": {
"@ekklesia/module-database": "^0.2.0",
"@ekklesia/module-sdk": "^0.2.0",
"@ekklesia/module-ui-sdk": "^0.2.0",
"@ekklesia/ui": "^0.2.0",
"react": "19.2.8",
"react-dom": "19.2.8"
},
"devDependencies": {
"@ekklesia/module-pack": "0.2.0",
"@ekklesia/module-ui-build": "^0.2.0",
"@ekklesia/typescript-config": "^0.2.0",
"typescript": "7.0.2"
}
}
```
- **One coordinated version.** Every Ekklesia module-development package has the same version,
equal to the Ekklesia release it belongs to, and the platform checks your manifest's
`compatibility.moduleSdk` against it. Ranges in your `package.json` are fine; your lockfile pins
exact artifacts, and you install with a frozen lockfile.
- **Pin `@ekklesia/module-pack` exactly** in `package.json`, not only in the lockfile: its version
decides the package it produces.
- **`engines.node` is required.** The packager records your module's supported Node.js range from
`engines.node` in your `package.json`, and refuses to package without it
(`MODULE_PACK_RUNTIME_UNKNOWN`). It never looks for a workspace file.
- **No Drizzle unless you use it.** The Module SDK does not install Drizzle. A module that uses the
Drizzle adapter, `@ekklesia/module-database/drizzle`, adds `drizzle-orm` to its own
dependencies; it is an optional peer of that adapter only.
- **One React.** `@ekklesia/ui` takes React as a peer, so your bundle contains one React, your own.
Your UI artifacts still bundle it
([ADR 0023](../architecture/decisions/0023-module-ui-build-pipeline.md)).
- **esbuild's install script.** The UI build and the packager use esbuild, which runs an install
script. With pnpm, allow it in your repository's `pnpm-workspace.yaml`:
```yaml
allowBuilds:
esbuild: true
```
- **Lockfiles name the registry.** pnpm records Gitea's tarball URLs in your lockfile. If the
packages ever move to another registry, change `@ekklesia:registry` and regenerate the lockfile;
nothing else changes, and the integrity of every package stays the same.
- **TypeScript.** Extend the shared configurations by package name, for example
`"extends": "@ekklesia/typescript-config/node.json"` for the backend and
`@ekklesia/typescript-config/browser-react.json` for the UI.
Packaging and verification work exactly as for a module in this repository
([Packaging your module](#packaging-your-module)). The packager recognizes Ekklesia's packages by
their identity, not by where they are installed, so they are recorded under `incorporates` and never
credited as third-party software, wherever they came from.
Ekklesia proves this on every CI run: `pnpm test:package-release` builds the public packages of a
release as one train of tarballs, proves two builds identical, and installs exactly those tarballs
into a module outside the repository (`tests/fixtures/standalone-module`), with no workspace link
and no registry, then typechecks, builds, packages, and verifies it. Those exact artifacts are what
the release publishes ([Releases and the public package train](../development/releases.md)).
### An installed module is self-contained ### An installed module is self-contained
@@ -92,15 +210,17 @@ through no link, `NODE_PATH`, loader hook, or alias. The packager therefore bund
#### Packaging your module #### Packaging your module
Build your module, then run the packager from the workspace your module is built in. It is a Build your module, then run the packager from your module's directory. It is a development
development dependency like `@ekklesia/module-ui-build`: dependency like `@ekklesia/module-ui-build`, and it takes your module's supported Node.js range from
`engines.node` in its `package.json`:
```bash ```bash
pnpm exec ekklesia-pack-module --module . --target any --out ../packages \ pnpm exec ekklesia-pack-module --module . --target any --out ../packages \
--license-file ./LICENSE \
--source-revision "$(git rev-parse HEAD)" --source-revision "$(git rev-parse HEAD)"
``` ```
It writes `<id>-<version>-any.tar.gz` and its `.sha256` line, and nothing else anywhere: it never It writes `<id>-<version>-<target>.tar.gz` and its `.sha256` line, and nothing else anywhere: it never
installs, links, or deploys, so your workspace is left exactly as it was. Never run `pnpm deploy` in installs, links, or deploys, so your workspace is left exactly as it was. Never run `pnpm deploy` in
a workspace instead: it rewrites that workspace's install state to production-only. a workspace instead: it rewrites that workspace's install state to production-only.
@@ -110,13 +230,15 @@ The archive holds one directory named with your module id:
<id>/ <id>/
├── package.json generated: name, version, private, "type": "module", the layer marker ├── package.json generated: name, version, private, "type": "module", the layer marker
├── ekklesia.module.json your manifest, byte for byte ├── ekklesia.module.json your manifest, byte for byte
├── ekklesia.package.json package metadata: target, runtime, provenance, file digests ├── ekklesia.package.json package metadata: license, target, runtime, provenance, file digests
├── LICENSE your explicitly supplied module license material, byte for byte
├── THIRD_PARTY_NOTICES licence and notice text of every third-party package bundled ├── THIRD_PARTY_NOTICES licence and notice text of every third-party package bundled
├── dist/server/index.js your backend entrypoints, bundled ├── dist/server/index.js your backend entrypoints, bundled
├── dist/schema/index.js ├── dist/schema/index.js
├── dist/chunks/ code your backend entrypoints share ├── dist/chunks/ code your backend entrypoints share
├── dist/ui/ … dist/display/ … dist/contributions/ your browser artifacts, exactly as built ├── dist/ui/ … dist/display/ … dist/contributions/ your browser artifacts, exactly as built
└── drizzle/ your migrations ├── drizzle/ your migrations
└── node_modules/ a native target only: native runtime dependencies, as real files
``` ```
- **Bundled backend.** Your server, schema, and jobs entrypoints are bundled with every - **Bundled backend.** Your server, schema, and jobs entrypoints are bundled with every
@@ -127,23 +249,67 @@ The archive holds one directory named with your module id:
your development `package.json`, any `workspace:` range, and links of any kind. your development `package.json`, any `workspace:` range, and links of any kind.
- **Browser artifacts must be current.** The packager rebuilds them in memory and refuses an artifact - **Browser artifacts must be current.** The packager rebuilds them in memory and refuses an artifact
on disk that differs, so run your build first. on disk that differs, so run your build first.
- **`any` is the only target today.** A dependency that is native or platform-specific (a compiled - **Targets.**
addon, a package that declares an operating system or CPU, or one that loads a per-platform binary - **`any`** is for pure-JavaScript modules. A dependency that is native or platform-specific (a
such as `sharp`) cannot be in an `any` package, and packaging fails. Native targets come later. compiled addon, a package that declares an operating system or CPU, or one that loads a
- **Licences.** `THIRD_PARTY_NOTICES` credits every third-party package your bundles contain, with per-platform binary such as `sharp`) cannot be in an `any` package, and packaging fails.
its declared licence and the licence and notice files it ships. A package that declares no licence - **`linux-x64-glibc`** is for modules with such a dependency, on Linux, x86-64, and glibc. Pack
fails packaging, and so does one that ships no licence text, unless its licence's standard text is with `--target linux-x64-glibc` on a matching host, after installing your dependencies.
complete without a copyright line (Apache-2.0, which the packager then supplies and says so). The - **What a `linux-x64-glibc` package contains.**
Ekklesia platform's own packages are listed in `ekklesia.package.json` under `incorporates`. - **Native packages stay outside the bundle.** Your ordinary JavaScript dependencies are bundled
as before. Each native package is copied instead, with exactly its production runtime
dependencies, as real files flat under `node_modules/<name>`.
- **Only this target's platform packages are copied.** Optional platform packages for other
systems, development dependencies, declarations, and source maps are left out. Two versions of
one package, a link inside a native package, or a required dependency for another platform fail
packaging.
- **`runtime` is read from the binaries themselves.** It records the Node-API version your addons
declare (or the exact Node.js ABI of an ABI-specific addon) and the newest glibc symbol version
any copied binary needs. A native target for a module with no native addon is refused: use
`any`.
- **A native package fits one environment.** A `linux-x64-glibc` artifact runs only on Linux,
x86-64, glibc hosts that meet its recorded glibc and Node-API minimums. The verifier checks all of
that before it loads anything. Other operating systems and CPUs, including ARM, are not supported
yet.
- **Your module's licence.** Your source `package.json` must contain a non-empty string SPDX
expression. The packager validates its syntax, rejects `UNLICENSED`, and copies it unchanged to
the required `ekklesia.package.json.license`. `--license-file` is also required: it names the
regular file whose exact bytes become the root `LICENSE` payload and inventory entry. The
packager never searches parent directories, guesses text from the expression, or downloads it.
- **Third-party licences.** `THIRD_PARTY_NOTICES` separately credits every third-party package your
bundles contain, with its declared licence and the licence and notice files it ships. A dependency
that declares no licence fails packaging, and so does one that ships no licence text, unless its
licence's standard text is complete without a copyright line (Apache-2.0, which the packager then
supplies and says so). The module itself is not added to this notice file. Bundled Ekklesia
packages remain listed in `ekklesia.package.json` under `incorporates`; one applicable AGPL text
is sufficient for current official modules. An Ekklesia package is one named `@ekklesia/*` whose
`package.json` also carries `"ekklesia": { "distribution": "module-development" }`, whether it is
linked from this repository or installed from a registry; a package with only the name is
third-party.
- **Reviewed licence supplements.** Some dependencies omit material that redistribution requires.
For one of those, the packager adds material from a reviewed supplement checked in with it, after
the package's own material and labelled as such
([ADR 0052](../architecture/decisions/0052-reviewed-license-supplements.md)).
- **Exact match.** A supplement is used only for an exact package name, version, and content
digest. The digest covers the redistributed files' relative paths and bytes, and is documented in
`packages/module-pack/src/supplements.ts`. Any mismatch fails.
- **What it does not do.** A supplement never changes the licence the package declares. The first
supplement covers `@img/sharp-libvips-linux-x64` 1.3.3, the libvips binary `sharp` loads. It
records upstream sources, but whether the LGPL and MPL source obligations for that binary are met
is an open determination. A package that carries it is not yet treated as publicly
distributable.
- **Deterministic.** The same packager version and the same built inputs produce the same archive, - **Deterministic.** The same packager version and the same built inputs produce the same archive,
byte for byte, wherever the checkout is. byte for byte, wherever the checkout is.
**Drizzle, for now.** You define tables with your own copy of Drizzle, and Core runs your queries **Database ABI v1 is the current path.** A module that declares `"database": { "abi": 1 }` keeps
through the platform's Drizzle instance (see [Database access](#database-access)). Objects from two Drizzle and its exact version inside its own bundle as an implementation detail. Its package omits
copies interoperate only when the copies are interchangeable, so the current implementation requires `transitional.databaseRuntime`; Core validates the module's plain schema metadata and never compares
**exactly the Drizzle version the platform uses**: the one `@ekklesia/module-sdk` depends on. The the bundled Drizzle version with its own. The canonical template demonstrates this path with
package records it under `transitional`, and an installation refuses a package whose Drizzle differs. `@ekklesia/module-database/drizzle`.
This is a constraint of today's implementation, not a permanent contract.
A manifest-v8 module that omits `database` remains on the temporary legacy facade. Only that legacy
package records bundled Drizzle under `transitional.databaseRuntime`, and the verifier continues to
require exact agreement with Core. The legacy facade has not been removed.
#### Verifying a package #### Verifying a package
@@ -164,10 +330,13 @@ later version, `AGPL-3.0-or-later` ([LICENSE](../../LICENSE)), and official Ekkl
same license. Declare it in your module's development `package.json` same license. Declare it in your module's development `package.json`
(`"license": "AGPL-3.0-or-later"`), as the module template does. (`"license": "AGPL-3.0-or-later"`), as the module template does.
A Module Package v1 does not yet record a module's own license: its runtime `package.json` and A Module Package v1 records that validated expression in its required
`ekklesia.package.json` have fixed fields, and its contents are fixed, by ADR 0049. Carrying the `ekklesia.package.json.license` and contains the exact explicitly supplied bytes at `LICENSE`
module's license, and the license text for the Ekklesia code bundled into its backend, needs a ([ADR 0051](../architecture/decisions/0051-module-package-license-material.md)). The generated
change to that format. runtime `package.json` is not authoritative for licensing. `THIRD_PARTY_NOTICES` remains only for
redistributed third-party dependencies, while bundled Ekklesia components remain represented by
`incorporates`. This strict-reader addition keeps `packageFormat` at `1`; older pre-0051 artifacts
without the field and payload fail closed.
### Removing a module keeps its data ### Removing a module keeps its data
@@ -192,13 +361,13 @@ without executing module code:
```json ```json
{ {
"manifestVersion": 7, "manifestVersion": 8,
"id": "calendar", "id": "calendar",
"name": "Calendar", "name": "Calendar",
"version": "0.1.0", "version": "0.1.0",
"compatibility": { "compatibility": {
"platform": "^0.1.0", "platform": "^0.2.0",
"moduleSdk": "^0.1.0" "moduleSdk": "^0.2.0"
}, },
"dependencies": { "dependencies": {
"modules": { "modules": {
@@ -269,10 +438,10 @@ has its own exact semantic version because its public contract can evolve indepe
module release. Capability dependencies use semantic-version ranges. Optional means the provider module release. Capability dependencies use semantic-version ranges. Optional means the provider
may be absent; if it is installed, its capability version must be compatible. may be absent; if it is installed, its capability version must be compatible.
`manifestVersion: 7` (`packages/contracts/src/module-manifest.ts`) is a required, exact literal — a `manifestVersion: 8` (`packages/contracts/src/module-manifest.ts`) is a required, exact literal — a
version 6 manifest, and any other version, fails validation outright rather than being silently version 7 manifest, and any other version, fails validation outright rather than being silently
reinterpreted; there is no compatibility adapter or automatic migration between manifest versions. reinterpreted; there is no compatibility adapter or automatic migration between manifest versions.
Version 7 adds the optional `contributions` array Already-built version 7 packages must be rebuilt. Version 7 added the optional `contributions` array
([ADR 0041](../architecture/decisions/0041-module-browser-contributions.md)). A version 6 module that ([ADR 0041](../architecture/decisions/0041-module-browser-contributions.md)). A version 6 module that
contributes nothing changes only the version literal; every browser artifact remains independently contributes nothing changes only the version literal; every browser artifact remains independently
optional ([ADR 0033](../architecture/decisions/0033-display-kiosk-host-contract.md)). optional ([ADR 0033](../architecture/decisions/0033-display-kiosk-host-contract.md)).
@@ -1411,27 +1580,27 @@ export const events = moduleTable("events", {
}); });
``` ```
The production schema entrypoint in `src/schema/index.ts` wraps those same objects with the Module The production schema entrypoint in `src/schema/index.ts` turns those same objects into the plain
SDK ownership marker: schema metadata an ABI-v1 module declares:
```ts ```ts
import { defineModuleSchema } from "@ekklesia/module-sdk"; import { moduleDrizzleSchemaMetadata } from "@ekklesia/module-database/drizzle";
import { events } from "./tables.js"; import { events } from "./tables.js";
export { events } from "./tables.js"; export { events } from "./tables.js";
export default defineModuleSchema({ export default moduleDrizzleSchemaMetadata("calendar", { events });
moduleId: "calendar",
tables: { events }
});
``` ```
A module without an ORM declares the same metadata directly with `defineModuleSchemaMetadata` from
`@ekklesia/module-database`. A legacy-v8 module's schema entrypoint default-exports
`{ moduleId, tables }` with the Drizzle table objects themselves.
The prefix callback converts the module ID to a snake-case namespace and prefixes every local table The prefix callback converts the module ID to a snake-case namespace and prefixes every local table
name. Here the physical PostgreSQL name is `calendar_events`; `care-team` plus `members` becomes name. Here the physical PostgreSQL name is `calendar_events`; `care-team` plus `members` becomes
`care_team_members`. Local names must be lowercase snake case, and the complete physical identifier `care_team_members`. Local names must be lowercase snake case, and the complete physical identifier
must not exceed 63 characters. The SDK's `createModuleTable` provides the same convenience when a must not exceed 63 characters. `createModuleTable` from `@ekklesia/module-database/drizzle` provides
generator-facing pure declaration file is not needed; Core validates built metadata independently the same convenience; Core validates built metadata independently of either helper.
of either helper.
Schema definitions use PostgreSQL tables in the platform-managed default/public schema. They must Schema definitions use PostgreSQL tables in the platform-managed default/public schema. They must
be side-effect-free: do not connect to a database, read configuration, or perform I/O during import. be side-effect-free: do not connect to a database, read configuration, or perform I/O during import.
@@ -1462,9 +1631,10 @@ export default defineConfig({
``` ```
Keep `tables.ts` limited to Drizzle declarations so the stable generator can load it without Keep `tables.ts` limited to Drizzle declarations so the stable generator can load it without
executing the ESM Module SDK wrapper. `src/schema/index.ts` remains the production compiled schema executing the ESM module wrapper. For an ABI-v1 module, `src/schema/index.ts` remains the production
entrypoint and wraps those same exported table objects with `defineModuleSchema`; tables are not compiled schema entrypoint and converts those same table objects to plain metadata with
declared twice. `moduleDrizzleSchemaMetadata`; tables are not declared twice. A legacy-v8 module continues to export
them as `{ moduleId, tables }` while that facade exists.
Run the module's `migration:generate` script with a lowercase snake-case name, review the generated Run the module's `migration:generate` script with a lowercase snake-case name, review the generated
SQL and snapshot, and add the matching entry to `drizzle/meta/_ekklesia.json`. Every entry must SQL and snapshot, and add the matching entry to `drizzle/meta/_ekklesia.json`. Every entry must
@@ -1485,9 +1655,119 @@ destructive behavior. Review those properties explicitly. Core is the only migra
follows Drizzle's exact `--> statement-breakpoint` delimiter and never naively splits semicolons or follows Drizzle's exact `--> statement-breakpoint` delimiter and never naively splits semicolons or
falls back to non-transactional execution. falls back to non-transactional execution.
## Database access ## Module Database ABI v1
`context.services.database` — available in `start`, `stop`, and every authorized route handler, The stable database boundary is Module Database ABI v1: SQL text, ordered bound values, an explicit
row mode, low-level PostgreSQL result values, and callback-scoped transactions. ORM objects never
cross it. A manifest version 8 module opts in with `"database": { "abi": 1 }`; omitting `database`
selects the temporary legacy facade. “Legacy” here describes that facade, never a version 7
manifest. Core selects the service from the validated manifest and gives each ABI module its own
executor, reused by that module's lifecycle hooks and route handlers.
A Drizzle module imports the optional adapter subpath and declares its own exact compatible
`drizzle-orm` dependency. The adapter's peer range (`>=0.45.2 <0.46.0`) describes adapter API
compatibility; it is not a Core or platform compatibility range:
```ts
import { moduleDrizzle } from "@ekklesia/module-database/drizzle";
import { defineModuleRuntime } from "@ekklesia/module-sdk";
import * as schema from "./schema/tables.js";
export default defineModuleRuntime({
database: { abi: 1 },
id: "calendar",
version: "0.1.0",
async start({ services }) {
const db = moduleDrizzle(services.database, { schema });
const events = await db.select().from(schema.events);
},
});
```
The repeated runtime discriminator is what gives lifecycle and route-handler code the exact
`ModuleDatabaseExecutor` type instead of a legacy-or-ABI union. Core still chooses from the static
manifest and refuses startup when the runtime discriminator disagrees with it; neither contract can
silently receive the other service.
Drizzle compiles SQL and parameters before calling the ABI. The adapter always requests positional
(`rowMode: "array"`) results, gives those rows back to Drizzle in column order, and Drizzle applies
the module's own column decoders for bigint, numeric, dates/timestamps, JSON, byte arrays, nulls, and
supported arrays. This also makes joins with duplicate PostgreSQL column names unambiguous. Core
never imports this adapter and has no dependency on the module's Drizzle version. The adapter surface
is deliberately limited to `select`, `insert`, `update`, `delete`, and `transaction`; returning,
joins, and SQL expressions come from those normal Drizzle builders.
`db.transaction(callback)` maps to the ABI transaction callback. The callback receives another
Drizzle-facing database backed by the scoped ABI executor; a nested `.transaction()` maps to the
ABI's `savepoint` callback. Callback values and errors propagate, Core remains authoritative for
commit/rollback and escaped-scope behavior, and the adapter adds no retries or transaction-control
SQL.
Drizzle wraps execution failures in `DrizzleQueryError`. Recover the stable sanitized ABI error by
shape instead of using a PostgreSQL error instance, parsing a message, or reading `.cause.code`:
```ts
import { findEkklesiaDatabaseError } from "@ekklesia/module-database";
try {
await db.insert(schema.events).values(event);
} catch (error) {
const databaseError = findEkklesiaDatabaseError(error);
if (databaseError?.sqlState === "23505") {
// Handle a uniqueness conflict.
}
}
```
Modules that do not want Drizzle use the package's ORM-neutral tag. Every interpolation is one bound
value; v1 deliberately provides no dynamic-identifier or trusted-fragment escape hatch:
```ts
import { sql } from "@ekklesia/module-database";
const statement = sql`
SELECT id, title
FROM calendar_events
WHERE id = ${eventId}
`;
const result = await executor.query({ ...statement, rowMode: "object" });
```
The tag does not stringify values. Unsupported values pass through unchanged and the ABI executor
rejects them; strings containing quotes or SQL syntax always remain parameters.
ABI modules also export plain schema metadata rather than Drizzle objects. Drizzle users can derive
it on the module side; raw-SQL modules can write the same inert shape directly:
```ts
import { moduleDrizzleSchemaMetadata } from "@ekklesia/module-database/drizzle";
import * as tables from "./tables.js";
export default moduleDrizzleSchemaMetadata("calendar", tables);
```
The result is `{ moduleId, tables: [{ name, foreignKeys: [{ table }] }] }`. Core validates table
prefixes, duplicates, and same-module foreign-key targets from those strings and never inspects an
ABI module's ORM objects.
The canonical module template declares ABI v1, uses the module-side Drizzle adapter, and exports
plain schema metadata derived with `moduleDrizzleSchemaMetadata`. Its Module Package v1 still
bundles Drizzle, but carries no `transitional.databaseRuntime`: that version belongs to the module,
not Core.
## Legacy database access
> **New modules use [Module Database ABI v1](#module-database-abi-v1).** Core still serves the
> legacy facade described here for its deprecation window
> ([ADR 0050](../architecture/decisions/0050-module-database-abi-v1.md)), so existing legacy modules
> keep running. But the Module SDK no longer exposes the facade's type
> ([ADR 0053](../architecture/decisions/0053-standalone-module-development-packages.md)): built
> against the current SDK, a module that declares no database sees `services.database` as `never`,
> and the example below no longer typechecks. Migrate to ABI v1 rather than reaching for the type
> elsewhere.
For a version 8 manifest that omits `database`, `context.services.database` — available in `start`, `stop`, and every authorized route handler,
never in `register` — is a `ModuleDatabase`: a typed Drizzle query surface over exactly `select`, never in `register` — is a `ModuleDatabase`: a typed Drizzle query surface over exactly `select`,
`selectDistinct`, `selectDistinctOn`, `insert`, `update`, `delete`, `execute`, and `transaction`, `selectDistinct`, `selectDistinctOn`, `insert`, `update`, `delete`, `execute`, and `transaction`,
preserving Drizzle's own table-aware argument and result inference. It is the platform's only preserving Drizzle's own table-aware argument and result inference. It is the platform's only
+4 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ekklesia", "name": "ekklesia",
"version": "0.1.2", "version": "0.2.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"private": true, "private": true,
"type": "module", "type": "module",
@@ -38,9 +38,12 @@
"modules:pack": "turbo run build && node packages/module-pack/bin/ekklesia-pack-module.mjs", "modules:pack": "turbo run build && node packages/module-pack/bin/ekklesia-pack-module.mjs",
"modules:validate": "turbo run build && node core/dist/cli/validate-modules.js", "modules:validate": "turbo run build && node core/dist/cli/validate-modules.js",
"modules:verify-package": "turbo run build && node core/dist/cli/verify-module-package.js", "modules:verify-package": "turbo run build && node core/dist/cli/verify-module-package.js",
"packages:release": "node scripts/package-release.ts --out .package-release",
"test": "turbo run test test:root", "test": "turbo run test test:root",
"test:migrations:integration": "pnpm build && bash scripts/test-migrations-integration.sh", "test:migrations:integration": "pnpm build && bash scripts/test-migrations-integration.sh",
"test:root": "vitest run --config vitest.config.ts", "test:root": "vitest run --config vitest.config.ts",
"test:package-release": "bash scripts/test-package-release.sh",
"test:package-publication": "bash scripts/test-package-publication.sh",
"test:watch": "vitest", "test:watch": "vitest",
"typecheck": "turbo run typecheck typecheck:root", "typecheck": "turbo run typecheck typecheck:root",
"typecheck:root": "tsc --noEmit --project tsconfig.json", "typecheck:root": "tsc --noEmit --project tsconfig.json",
+9 -4
View File
@@ -1,6 +1,6 @@
{ {
"name": "@ekklesia/contracts", "name": "@ekklesia/contracts",
"version": "0.1.2", "version": "0.2.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"type": "module", "type": "module",
"files": [ "files": [
@@ -10,28 +10,33 @@
".": { ".": {
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
"import": "./dist/index.js" "import": "./dist/index.js"
},
"./module-package": {
"types": "./dist/module-package.d.ts",
"import": "./dist/module-package.js"
} }
}, },
"scripts": { "scripts": {
"build": "tsc --project tsconfig.build.json", "build": "tsc --project tsconfig.build.json",
"lint": "biome lint .", "lint": "biome lint .",
"prepack": "pnpm --workspace-root exec turbo run build --filter=@ekklesia/contracts",
"test": "vitest run", "test": "vitest run",
"typecheck": "tsc --noEmit --project tsconfig.json" "typecheck": "tsc --noEmit --project tsconfig.json"
}, },
"dependencies": { "dependencies": {
"drizzle-orm": "0.45.2",
"semver": "7.8.5", "semver": "7.8.5",
"spdx-expression-parse": "5.0.0",
"zod": "4.4.3" "zod": "4.4.3"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "2.5.3", "@biomejs/biome": "2.5.3",
"@types/node": "24.13.3", "@types/node": "24.13.3",
"@types/semver": "7.7.1", "@types/semver": "7.7.1",
"@types/spdx-expression-parse": "4.0.0",
"typescript": "7.0.2", "typescript": "7.0.2",
"vitest": "4.1.10" "vitest": "4.1.10"
}, },
"ekklesia": { "ekklesia": {
"layer": "contracts" "layer": "contracts",
"distribution": "module-development"
} }
} }
+2 -2
View File
@@ -9,9 +9,9 @@ export * from "./module-http.js";
export * from "./module-lifecycle.js"; export * from "./module-lifecycle.js";
export * from "./module-manifest.js"; export * from "./module-manifest.js";
export * from "./module-migration.js"; export * from "./module-migration.js";
export * from "./module-package.js";
export * from "./module-realtime.js"; export * from "./module-realtime.js";
export * from "./module-runtime.js"; export * from "./module-runtime.js";
export * from "./module-schema.js"; export * from "./module-schema-metadata.js";
export * from "./module-schema-names.js";
export * from "./module-storage.js"; export * from "./module-storage.js";
export * from "./versions.js"; export * from "./versions.js";
+9 -40
View File
@@ -1,50 +1,19 @@
import type { NodePgDatabase } from "drizzle-orm/node-postgres"; import type { ModuleDatabaseExecutor } from "./module-database-abi.js";
/**
* A trusted backend module's typed Drizzle query surface — the same query-building methods a
* platform-owned Drizzle instance exposes, restricted to exactly the operations a module needs to
* read and write its own tables. Derived with `Pick` from the real `drizzle-orm/node-postgres`
* database type rather than hand-declared, so every method keeps Drizzle's own table-aware
* argument and result inference exactly as-is — a module calling `database.select().from(table)`
* or `database.insert(table).values(...)` gets the identical typed builder a direct Drizzle caller
* would, with no `any`/`unknown` erasure anywhere in the chain.
*
* Deliberately excludes everything `NodePgDatabase` or the `drizzle(...)` factory otherwise
* exposes: `$client` (the raw `pg` client/pool), `_` (internal session/dialect/schema state),
* `query` (a relational-query builder tied to one schema, which would have to span every
* installed module's tables to exist here at all), `$cache`, `$count`, `$with`, `with`, and
* `refreshMaterializedView`. There is no connection string, pool, session, or dialect object
* reachable through this type. Carries no schema generic — a module brings its own Drizzle table
* objects (`@ekklesia/module-sdk`'s `defineModuleSchema`) to each call, so there is no global
* relational schema spanning every installed module for this type to leak.
*
* This is an integration boundary, not a security sandbox: modules are trusted, compiled backend
* plugins that already run arbitrary code in this process, exactly like every other lifecycle hook
* and HTTP handler they define. `ModuleDatabase` exists to keep a module's code Drizzle-typed and
* decoupled from how the platform physically connects to PostgreSQL — not to defend against a
* malicious module, which this facade cannot do and does not attempt to do.
*/
export type ModuleDatabase = Pick<
NodePgDatabase,
| "select"
| "selectDistinct"
| "selectDistinctOn"
| "insert"
| "update"
| "delete"
| "execute"
| "transaction"
>;
/** /**
* The complete set of platform-provided services a trusted module's `start`/`stop` lifecycle hooks * The complete set of platform-provided services a trusted module's `start`/`stop` lifecycle hooks
* and authorized HTTP route handlers receive — for this phase, exactly one: `database`. Frozen, and * and authorized HTTP route handlers receive — for this phase, exactly one: `database`. For a
* module that declares `database: { abi: 1 }` it is the Module Database ABI v1 executor; for a
* legacy module it is Core's legacy facade, whose type Core alone owns, so this package never
* references an ORM (ADR 0053). Frozen, and
* never handed to a module's `register` hook (`ModuleRegistrationContext` has no `services` field): * never handed to a module's `register` hook (`ModuleRegistrationContext` has no `services` field):
* registration stays declarative and database-free, exactly as before this contract existed. * registration stays declarative and database-free, exactly as before this contract existed.
* Deliberately has no storage, jobs, configuration, secrets, or authorization field yet — those * Deliberately has no storage, jobs, configuration, secrets, or authorization field yet — those
* remain out of scope until a later phase explicitly adds them here, one at a time, the same way * remain out of scope until a later phase explicitly adds them here, one at a time, the same way
* `database` was added. * `database` was added.
*/ */
export interface ModuleRuntimeServices { export interface ModuleRuntimeServices<Database = ModuleDatabaseExecutor> {
readonly database: ModuleDatabase; readonly database: Database;
} }
export type ModuleDatabaseAbiRuntimeServices = ModuleRuntimeServices<ModuleDatabaseExecutor>;
+13 -10
View File
@@ -3,6 +3,7 @@ import { type ModuleId, type PermissionId, permissionIdSchema } from "./identifi
import type { EkklesiaPrincipal } from "./identity.js"; import type { EkklesiaPrincipal } from "./identity.js";
import type { ModuleConfiguration } from "./module-configuration.js"; import type { ModuleConfiguration } from "./module-configuration.js";
import type { ModuleRuntimeServices } from "./module-database.js"; import type { ModuleRuntimeServices } from "./module-database.js";
import type { ModuleDatabaseExecutor } from "./module-database-abi.js";
import type { ModuleRealtimePublisher } from "./module-realtime.js"; import type { ModuleRealtimePublisher } from "./module-realtime.js";
import type { ModuleStorage } from "./module-storage.js"; import type { ModuleStorage } from "./module-storage.js";
@@ -271,7 +272,7 @@ export function moduleRoutesOverlap(
* behavior, and uncaught-handler sanitization; permission enforcement always completes before a * behavior, and uncaught-handler sanitization; permission enforcement always completes before a
* handler — and therefore any parameter validation it performs — can run. * handler — and therefore any parameter validation it performs — can run.
*/ */
export interface ModuleRouteHandlerContext { export interface ModuleRouteHandlerContext<Database = ModuleDatabaseExecutor> {
readonly moduleId: ModuleId; readonly moduleId: ModuleId;
readonly principal: EkklesiaPrincipal; readonly principal: EkklesiaPrincipal;
readonly params: Readonly<Record<string, string>>; readonly params: Readonly<Record<string, string>>;
@@ -279,7 +280,7 @@ export interface ModuleRouteHandlerContext {
* object, not a re-resolved one (ADR 0030). This is what lets a module stream an object straight * object, not a re-resolved one (ADR 0030). This is what lets a module stream an object straight
* into a `Response` without the browser ever learning that object storage exists. */ * into a `Response` without the browser ever learning that object storage exists. */
readonly storage: ModuleStorage; readonly storage: ModuleStorage;
readonly services: ModuleRuntimeServices; readonly services: ModuleRuntimeServices<Database>;
/** The identical module-scoped realtime publisher used by lifecycle hooks. */ /** The identical module-scoped realtime publisher used by lifecycle hooks. */
readonly realtime: ModuleRealtimePublisher; readonly realtime: ModuleRealtimePublisher;
/** The identical frozen configuration snapshot this module's `start`/`stop` hooks received — the /** The identical frozen configuration snapshot this module's `start`/`stop` hooks received — the
@@ -293,9 +294,9 @@ export interface ModuleRouteHandlerContext {
/** A framework-neutral Fetch handler: standard `Request` in, standard `Response` out. The full /** A framework-neutral Fetch handler: standard `Request` in, standard `Response` out. The full
* query string remains available through `Request.url`; there is no competing query or body * query string remains available through `Request.url`; there is no competing query or body
* abstraction. */ * abstraction. */
export type ModuleRouteHandler = ( export type ModuleRouteHandler<Database = ModuleDatabaseExecutor> = (
request: Request, request: Request,
context: ModuleRouteHandlerContext, context: ModuleRouteHandlerContext<Database>,
) => Awaitable<Response>; ) => Awaitable<Response>;
/** /**
@@ -311,7 +312,7 @@ export type ModuleRouteHandler = (
* path, CORS/origin policy, authentication behavior, grant/platform-owner state, middleware, audit * path, CORS/origin policy, authentication behavior, grant/platform-owner state, middleware, audit
* metadata, another module's namespace, or an unprotected/no-permission route. * metadata, another module's namespace, or an unprotected/no-permission route.
*/ */
export interface ModuleRouteDefinitionInput { export interface ModuleRouteDefinitionInput<Database = ModuleDatabaseExecutor> {
readonly method: ModuleHttpMethod; readonly method: ModuleHttpMethod;
readonly path: string; readonly path: string;
readonly permission: string; readonly permission: string;
@@ -322,12 +323,12 @@ export interface ModuleRouteDefinitionInput {
* existed meant, so adding this field changed no existing route's behaviour. * existed meant, so adding this field changed no existing route's behaviour.
*/ */
readonly bodyMode?: ModuleRouteBodyMode; readonly bodyMode?: ModuleRouteBodyMode;
readonly handler: ModuleRouteHandler; readonly handler: ModuleRouteHandler<Database>;
} }
/** The validated, canonical form of a `ModuleRouteDefinitionInput` — what `http.route` produces /** The validated, canonical form of a `ModuleRouteDefinitionInput` — what `http.route` produces
* only after every field passes its own grammar. */ * only after every field passes its own grammar. */
export interface ModuleRouteDefinition { export interface ModuleRouteDefinition<Database = ModuleDatabaseExecutor> {
readonly method: ModuleHttpMethod; readonly method: ModuleHttpMethod;
readonly path: ModuleRoutePath; readonly path: ModuleRoutePath;
readonly permission: PermissionId; readonly permission: PermissionId;
@@ -335,13 +336,13 @@ export interface ModuleRouteDefinition {
/** Always present in the canonical form, defaulted to `buffered`, so no consumer downstream has /** Always present in the canonical form, defaulted to `buffered`, so no consumer downstream has
* to re-apply the default and none of them can disagree about it. */ * to re-apply the default and none of them can disagree about it. */
readonly bodyMode: ModuleRouteBodyMode; readonly bodyMode: ModuleRouteBodyMode;
readonly handler: ModuleRouteHandler; readonly handler: ModuleRouteHandler<Database>;
} }
/** The Fetch-based registrar exposed as `context.http` during `register` only — never on /** The Fetch-based registrar exposed as `context.http` during `register` only — never on
* `ModuleRuntimeContext`, so `start`/`stop` cannot register a route after the fact. */ * `ModuleRuntimeContext`, so `start`/`stop` cannot register a route after the fact. */
export interface ModuleHttpRouteRegistrar { export interface ModuleHttpRouteRegistrar<Database = ModuleDatabaseExecutor> {
route(definition: ModuleRouteDefinitionInput): void; route(definition: ModuleRouteDefinitionInput<Database>): void;
} }
/** One published route in `StartedModuleRuntime`'s immutable route snapshot — the same validated /** One published route in `StartedModuleRuntime`'s immutable route snapshot — the same validated
@@ -355,6 +356,8 @@ export interface RegisteredModuleHttpRoute {
readonly permission: PermissionId; readonly permission: PermissionId;
readonly maxBodyBytes: number; readonly maxBodyBytes: number;
readonly bodyMode: ModuleRouteBodyMode; readonly bodyMode: ModuleRouteBodyMode;
/** Runtime-erased callback. Module authors get the database-mode-specific handler type through
* `ModuleHttpRouteRegistrar`; Core stores the validated callback opaquely in this snapshot. */
readonly handler: ModuleRouteHandler; readonly handler: ModuleRouteHandler;
} }
+17 -9
View File
@@ -68,6 +68,14 @@ const moduleStorageSchema = z
.strict() .strict()
.default(() => ({ buckets: [] })); .default(() => ({ buckets: [] }));
/** The database contract Core delivers to this module. Omitted means the temporary ADR 0016
* legacy facade; ABI v1 is the stable SQL boundary from ADR 0050. */
export const moduleDatabaseDeclarationSchema = z
.object({
abi: z.literal(1),
})
.strict();
/** /**
* A module's optional full-viewport display UI. The artifact is kept beside its access policy so a * A module's optional full-viewport display UI. The artifact is kept beside its access policy so a
* display can never be declared without saying which one of the module's own permissions protects * display can never be declared without saying which one of the module's own permissions protects
@@ -122,9 +130,9 @@ function reportDuplicates(
} }
/** /**
* The one manifest shape Core accepts. Version 6's strict top-level object rejects `contributions`, * The one manifest shape Core accepts. Version 7's strict top-level object rejects `database`, so
* so the static browser-contribution declaration is an incompatible shape change and the canonical * the static ABI declaration is an incompatible shape change and the canonical manifest moves to
* manifest moves to `manifestVersion: 7` rather than silently reinterpreting version 6. * `manifestVersion: 8` without silently reinterpreting version 7.
* *
* Configuration is declared **statically, in this inert document**, rather than registered by * Configuration is declared **statically, in this inert document**, rather than registered by
* executable module code, for one decisive reason: the platform validates a module's configuration * executable module code, for one decisive reason: the platform validates a module's configuration
@@ -133,14 +141,13 @@ function reportDuplicates(
* inside its own `start` hook. Discovery, `pnpm modules:validate`, and Doctor all read this without * inside its own `start` hook. Discovery, `pnpm modules:validate`, and Doctor all read this without
* importing a single line of module code, exactly as they always have. * importing a single line of module code, exactly as they always have.
* *
* Version 6, and every other version, fails validation: there is no compatibility adapter, no * Version 7, and every other version, fails validation: there is no compatibility adapter, no
* automatic conversion, and no dual acceptance, exactly as version 1 was rejected by version 2 * automatic conversion, and no dual acceptance, exactly as version 1 was rejected by version 2
* (ADR 0006), version 2 by version 3 (ADR 0014), version 3 by version 4 (ADR 0021), and version 5 * (ADR 0006), version 2 by version 3 (ADR 0014), version 3 by version 4 (ADR 0021), and version 7
* by version 6 (ADR 0033). One manifest document can therefore never be read as two different * by version 8 (ADR 0050). One manifest document can therefore never be read as two different
* versions. Upgrading a version 6 manifest is a one-character edit for a module that contributes * versions. A version 7 package must be rebuilt; omitting `database` selects the legacy facade.
* nothing: the new field defaults to empty.
*/ */
export const MODULE_MANIFEST_VERSION = 7; export const MODULE_MANIFEST_VERSION = 8;
export const moduleManifestSchema = z export const moduleManifestSchema = z
.object({ .object({
@@ -163,6 +170,7 @@ export const moduleManifestSchema = z
* module code during discovery. A module that needs nothing configured omits the field. */ * module code during discovery. A module that needs nothing configured omits the field. */
configuration: z.array(moduleConfigurationDeclarationSchema).default(() => []), configuration: z.array(moduleConfigurationDeclarationSchema).default(() => []),
storage: moduleStorageSchema, storage: moduleStorageSchema,
database: moduleDatabaseDeclarationSchema.optional(),
/** Compiled browser renderers this module offers to capabilities **other** modules provide /** Compiled browser renderers this module offers to capabilities **other** modules provide
* (ADR 0041). Inert data: Core validates identity, compatibility, and the artifact path, and * (ADR 0041). Inert data: Core validates identity, compatibility, and the artifact path, and
* never learns what a contribution renders. A module that contributes nothing omits the field. */ * never learns what a contribution renders. A module that contributes nothing omits the field. */
+58 -4
View File
@@ -1,4 +1,5 @@
import { z } from "zod"; import { z } from "zod";
import parseSpdxExpression from "spdx-expression-parse";
import { moduleIdSchema } from "./identifiers.js"; import { moduleIdSchema } from "./identifiers.js";
import { semanticVersionRangeSchema, semanticVersionSchema } from "./versions.js"; import { semanticVersionRangeSchema, semanticVersionSchema } from "./versions.js";
@@ -11,11 +12,30 @@ import { semanticVersionRangeSchema, semanticVersionSchema } from "./versions.js
*/ */
export const MODULE_PACKAGE_FORMAT = 1; export const MODULE_PACKAGE_FORMAT = 1;
export const MODULE_PACKAGE_LICENSE_FILENAME = "LICENSE";
export const MODULE_PACKAGE_METADATA_FILENAME = "ekklesia.package.json"; export const MODULE_PACKAGE_METADATA_FILENAME = "ekklesia.package.json";
export const MODULE_PACKAGE_NOTICES_FILENAME = "THIRD_PARTY_NOTICES"; export const MODULE_PACKAGE_NOTICES_FILENAME = "THIRD_PARTY_NOTICES";
/** The portable target: a package with no native or platform-specific file. */ /** The portable target: a package with no native or platform-specific file. */
export const MODULE_PACKAGE_ANY_TARGET = "any"; export const MODULE_PACKAGE_ANY_TARGET = "any";
/** The module publisher's package-level license declaration (ADR 0051). This validates SPDX syntax,
* not whether Ekklesia approves, recommends, or considers the license legally compatible. */
export const modulePackageLicenseExpressionSchema = z
.string()
.min(1)
.max(1024)
.superRefine((value, context) => {
if (value === "UNLICENSED") {
context.addIssue({ code: "custom", message: "Must be an SPDX license expression." });
return;
}
try {
parseSpdxExpression(value);
} catch {
context.addIssue({ code: "custom", message: "Must be an SPDX license expression." });
}
});
/** /**
* `any`, or `<platform>-<arch>[-<libc>]` in Node.js's own `process.platform` and `process.arch` * `any`, or `<platform>-<arch>[-<libc>]` in Node.js's own `process.platform` and `process.arch`
* vocabulary. On Linux the C library is required, because a native addon built against one does * vocabulary. On Linux the C library is required, because a native addon built against one does
@@ -87,10 +107,10 @@ const ekklesiaPackageNameSchema = z
* (ADR 0049). Strict at every level: a reader that finds a fact it does not understand must refuse * (ADR 0049). Strict at every level: a reader that finds a fact it does not understand must refuse
* the package rather than ignore it. * the package rather than ignore it.
* *
* `databaseRuntime` records the Drizzle version bundled with the module's backend, because Core runs * For a manifest-v8 module that omits `database`, `databaseRuntime` records the Drizzle version
* a module's queries through its own Drizzle instance over tables the module defined with its own * bundled with the module's backend because Core runs that legacy module's queries through its own
* copy. That is an implementation constraint pending a Module Database ABI decision, **not** a * Drizzle instance over the module's table objects. ABI-v1 packages must omit this fact: their ORM
* database contract a module may rely on. * stays module-side and Core receives only the stable SQL ABI.
*/ */
const modulePackageTransitionalSchema = z.strictObject({ const modulePackageTransitionalSchema = z.strictObject({
databaseRuntime: z databaseRuntime: z
@@ -104,6 +124,8 @@ export const modulePackageMetadataSchema = z
.strictObject({ .strictObject({
packageFormat: z.literal(MODULE_PACKAGE_FORMAT), packageFormat: z.literal(MODULE_PACKAGE_FORMAT),
module: z.strictObject({ id: moduleIdSchema, version: semanticVersionSchema }), module: z.strictObject({ id: moduleIdSchema, version: semanticVersionSchema }),
/** The module's authoritative package-release license declaration (ADR 0051). */
license: modulePackageLicenseExpressionSchema,
target: modulePackageTargetSchema, target: modulePackageTargetSchema,
runtime: modulePackageRuntimeSchema, runtime: modulePackageRuntimeSchema,
provenance: z.strictObject({ provenance: z.strictObject({
@@ -124,6 +146,16 @@ export const modulePackageMetadataSchema = z
files: z.array(modulePackageFileSchema), files: z.array(modulePackageFileSchema),
}) })
.superRefine((metadata, context) => { .superRefine((metadata, context) => {
const licenseFiles = metadata.files.filter(
(file) => file.path === MODULE_PACKAGE_LICENSE_FILENAME,
);
if (licenseFiles.length !== 1 || licenseFiles[0]?.size === 0) {
context.addIssue({
code: "custom",
message: "The payload must contain exactly one non-empty root LICENSE file.",
path: ["files"],
});
}
if ( if (
metadata.target === MODULE_PACKAGE_ANY_TARGET && metadata.target === MODULE_PACKAGE_ANY_TARGET &&
(metadata.runtime.nodeApi !== undefined || (metadata.runtime.nodeApi !== undefined ||
@@ -136,6 +168,24 @@ export const modulePackageMetadataSchema = z
path: ["runtime"], path: ["runtime"],
}); });
} }
if (metadata.target !== MODULE_PACKAGE_ANY_TARGET) {
// ADR 0049: a native package states what its addons need from Node.js and, on Linux, the
// minimum C library version.
if (metadata.runtime.nodeApi === undefined && metadata.runtime.nodeAbi === undefined) {
context.addIssue({
code: "custom",
message: "A native package states the Node-API version or Node.js ABI its addons need.",
path: ["runtime"],
});
}
if (metadata.target.startsWith("linux-") && metadata.runtime.libcVersion === undefined) {
context.addIssue({
code: "custom",
message: "A native Linux package states the minimum C library version it needs.",
path: ["runtime", "libcVersion"],
});
}
}
for (let index = 1; index < metadata.files.length; index += 1) { for (let index = 1; index < metadata.files.length; index += 1) {
const previous = metadata.files[index - 1]?.path ?? ""; const previous = metadata.files[index - 1]?.path ?? "";
const current = metadata.files[index]?.path ?? ""; const current = metadata.files[index]?.path ?? "";
@@ -157,6 +207,10 @@ export function safeParseModulePackageMetadata(input: unknown) {
return modulePackageMetadataSchema.safeParse(input); return modulePackageMetadataSchema.safeParse(input);
} }
export function safeParseModulePackageLicenseExpression(input: unknown) {
return modulePackageLicenseExpressionSchema.safeParse(input);
}
export function safeParseModulePackageTarget(input: unknown) { export function safeParseModulePackageTarget(input: unknown) {
return modulePackageTargetSchema.safeParse(input); return modulePackageTargetSchema.safeParse(input);
} }
+51 -15
View File
@@ -2,6 +2,7 @@ import type { CapabilityId, ModuleId } from "./identifiers.js";
import { moduleIdSchema } from "./identifiers.js"; import { moduleIdSchema } from "./identifiers.js";
import type { ModuleConfiguration } from "./module-configuration.js"; import type { ModuleConfiguration } from "./module-configuration.js";
import type { ModuleRuntimeServices } from "./module-database.js"; import type { ModuleRuntimeServices } from "./module-database.js";
import type { ModuleDatabaseExecutor } from "./module-database-abi.js";
import type { ModuleHttpRouteRegistrar } from "./module-http.js"; import type { ModuleHttpRouteRegistrar } from "./module-http.js";
import type { ModuleRealtimeChannelRegistrar, ModuleRealtimePublisher } from "./module-realtime.js"; import type { ModuleRealtimeChannelRegistrar, ModuleRealtimePublisher } from "./module-realtime.js";
import type { ModuleStorage } from "./module-storage.js"; import type { ModuleStorage } from "./module-storage.js";
@@ -24,12 +25,12 @@ export interface CapabilityRegistrar extends CapabilityResolver {
provide(capabilityId: CapabilityId, implementation: unknown): void; provide(capabilityId: CapabilityId, implementation: unknown): void;
} }
export interface ModuleRegistrationContext { export interface ModuleRegistrationContext<Database = ModuleDatabaseExecutor> {
readonly capabilities: CapabilityRegistrar; readonly capabilities: CapabilityRegistrar;
/** Available only during `register` — never on `ModuleRuntimeContext` — so a route can only ever /** Available only during `register` — never on `ModuleRuntimeContext` — so a route can only ever
* be declared while Core is still building the immutable startup snapshot, never added or removed * be declared while Core is still building the immutable startup snapshot, never added or removed
* afterward from `start`, `stop`, or any other post-registration code path. */ * afterward from `start`, `stop`, or any other post-registration code path. */
readonly http: ModuleHttpRouteRegistrar; readonly http: ModuleHttpRouteRegistrar<Database>;
/** Declarative, registration-only channel publication. Live publishing is available only from /** Declarative, registration-only channel publication. Live publishing is available only from
* runtime and request-handler contexts. */ * runtime and request-handler contexts. */
readonly realtime: ModuleRealtimeChannelRegistrar; readonly realtime: ModuleRealtimeChannelRegistrar;
@@ -49,10 +50,10 @@ export interface ModuleRegistrationContext {
* same frozen `services` object identity as the other, for a given API runtime — never a fresh * same frozen `services` object identity as the other, for a given API runtime — never a fresh
* `ModuleRuntimeServices` built per hook invocation. Unlike `ModuleRegistrationContext`, this never * `ModuleRuntimeServices` built per hook invocation. Unlike `ModuleRegistrationContext`, this never
* carries `http`: a route can only ever be declared during `register`. */ * carries `http`: a route can only ever be declared during `register`. */
export interface ModuleRuntimeContext { export interface ModuleRuntimeContext<Database = ModuleDatabaseExecutor> {
readonly capabilities: CapabilityResolver; readonly capabilities: CapabilityResolver;
readonly moduleId: ModuleId; readonly moduleId: ModuleId;
readonly services: ModuleRuntimeServices; readonly services: ModuleRuntimeServices<Database>;
/** /**
* This module's own scoped object storage (ADR 0030). * This module's own scoped object storage (ADR 0030).
* *
@@ -70,8 +71,8 @@ export interface ModuleRuntimeContext {
/** /**
* This module's own validated configuration, frozen for the lifetime of the process. * This module's own validated configuration, frozen for the lifetime of the process.
* *
* Deliberately **not** a field on `ModuleRuntimeServices`: that object is one shared instance * Deliberately **not** a field on `ModuleRuntimeServices`: that object holds live platform
* every module receives, and configuration is per-module by definition. It sits beside `moduleId` * services while configuration is a separately resolved snapshot. It sits beside `moduleId`
* — the context's other per-module fact — so the scoping is visible in the shape rather than * — the context's other per-module fact — so the scoping is visible in the shape rather than
* asserted in a comment. * asserted in a comment.
* *
@@ -82,15 +83,31 @@ export interface ModuleRuntimeContext {
readonly config: ModuleConfiguration; readonly config: ModuleConfiguration;
} }
export interface ModuleRuntimeDefinition { interface ModuleRuntimeDefinitionBase<Database> {
readonly id: ModuleId; readonly id: ModuleId;
readonly register?: (context: ModuleRegistrationContext) => Awaitable<void>; readonly register?: (context: ModuleRegistrationContext<Database>) => Awaitable<void>;
readonly start?: (context: ModuleRuntimeContext) => Awaitable<void>; readonly start?: (context: ModuleRuntimeContext<Database>) => Awaitable<void>;
readonly stop?: (context: ModuleRuntimeContext) => Awaitable<void>; readonly stop?: (context: ModuleRuntimeContext<Database>) => Awaitable<void>;
readonly version: string; readonly version: string;
} }
const runtimeDefinitionKeys = new Set(["id", "register", "start", "stop", "version"]); /** A module on the legacy database facade (ADR 0016), until its deprecation window ends (ADR 0050).
* The facade's type is Core's own, so here its database is opaque: Core specializes `Database`. */
export interface LegacyModuleRuntimeDefinition<Database = unknown>
extends ModuleRuntimeDefinitionBase<Database> {
readonly database?: never;
}
export interface ModuleDatabaseAbiRuntimeDefinition
extends ModuleRuntimeDefinitionBase<ModuleDatabaseExecutor> {
readonly database: { readonly abi: 1 };
}
export type ModuleRuntimeDefinition =
| LegacyModuleRuntimeDefinition
| ModuleDatabaseAbiRuntimeDefinition;
const runtimeDefinitionKeys = new Set(["database", "id", "register", "start", "stop", "version"]);
function isRecord(value: unknown): value is Record<string, unknown> { function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value); return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -107,6 +124,14 @@ export function isModuleRuntimeDefinition(value: unknown): value is ModuleRuntim
if (Object.keys(value).some((key) => !runtimeDefinitionKeys.has(key))) { if (Object.keys(value).some((key) => !runtimeDefinitionKeys.has(key))) {
return false; return false;
} }
if (
value.database !== undefined &&
(!isRecord(value.database) ||
Reflect.ownKeys(value.database).length !== 1 ||
value.database.abi !== 1)
) {
return false;
}
return [value.register, value.start, value.stop].every( return [value.register, value.start, value.stop].every(
(hook) => hook === undefined || typeof hook === "function", (hook) => hook === undefined || typeof hook === "function",
); );
@@ -116,11 +141,22 @@ export function parseModuleRuntimeDefinition(value: unknown): ModuleRuntimeDefin
if (!isModuleRuntimeDefinition(value)) { if (!isModuleRuntimeDefinition(value)) {
throw new TypeError("Invalid Ekklesia module runtime definition."); throw new TypeError("Invalid Ekklesia module runtime definition.");
} }
return Object.freeze({ const hooks = {
id: value.id,
version: value.version,
...(value.register ? { register: value.register } : {}), ...(value.register ? { register: value.register } : {}),
...(value.start ? { start: value.start } : {}), ...(value.start ? { start: value.start } : {}),
...(value.stop ? { stop: value.stop } : {}), ...(value.stop ? { stop: value.stop } : {}),
}); };
if (value.database) {
return Object.freeze({
database: Object.freeze({ abi: 1 as const }),
id: value.id,
version: value.version,
...hooks,
}) as ModuleDatabaseAbiRuntimeDefinition;
}
return Object.freeze({
id: value.id,
version: value.version,
...hooks,
}) as LegacyModuleRuntimeDefinition;
} }
@@ -0,0 +1,80 @@
import { z } from "zod";
import { moduleIdSchema } from "./identifiers.js";
import { physicalModuleTableNameSchema } from "./module-schema-names.js";
export const moduleSchemaForeignKeyMetadataSchema = z
.object({ table: physicalModuleTableNameSchema })
.strict();
export const moduleSchemaTableMetadataSchema = z
.object({
name: physicalModuleTableNameSchema,
foreignKeys: z.array(moduleSchemaForeignKeyMetadataSchema).default(() => []),
})
.strict();
/** The ABI-v1 schema entrypoint: inert Ekklesia-owned data, with no ORM object or executable
* callback anywhere in its shape. Ownership and foreign-key targets are validated by Core against
* the manifest module id and the complete table list. */
export const moduleSchemaMetadataDefinitionSchema = z
.object({
moduleId: moduleIdSchema,
tables: z.array(moduleSchemaTableMetadataSchema).min(1),
})
.strict();
export interface ModuleSchemaForeignKeyMetadata {
readonly table: string;
}
export interface ModuleSchemaTableMetadata {
readonly name: string;
readonly foreignKeys: readonly ModuleSchemaForeignKeyMetadata[];
}
export interface ModuleSchemaMetadataDefinition {
readonly moduleId: z.output<typeof moduleIdSchema>;
readonly tables: readonly ModuleSchemaTableMetadata[];
}
function isPlainData(value: unknown): boolean {
if (value === null || typeof value === "string") {
return true;
}
if (Array.isArray(value)) {
return value.every(isPlainData);
}
if (typeof value !== "object") {
return false;
}
const prototype = Object.getPrototypeOf(value);
return (
(prototype === Object.prototype || prototype === null) &&
Reflect.ownKeys(value).every(
(key) => typeof key === "string" && isPlainData((value as Record<string, unknown>)[key]),
)
);
}
export function parseModuleSchemaMetadataDefinition(
value: unknown,
): ModuleSchemaMetadataDefinition {
if (!isPlainData(value)) {
throw new TypeError("Invalid Ekklesia module schema metadata definition.");
}
const parsed = moduleSchemaMetadataDefinitionSchema.safeParse(value);
if (!parsed.success) {
throw new TypeError("Invalid Ekklesia module schema metadata definition.");
}
return Object.freeze({
moduleId: parsed.data.moduleId,
tables: Object.freeze(
parsed.data.tables.map((table) =>
Object.freeze({
foreignKeys: Object.freeze(
table.foreignKeys.map((foreignKey) => Object.freeze(foreignKey)),
),
name: table.name,
}),
),
),
});
}
@@ -0,0 +1,31 @@
import { z } from "zod";
import { type ModuleId, moduleIdSchema } from "./identifiers.js";
export const POSTGRES_IDENTIFIER_MAX_LENGTH = 63;
export const moduleTableLocalNameSchema = z
.string()
.min(1)
.regex(/^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u, "Must be a lowercase snake-case table name.");
export const physicalModuleTableNameSchema = moduleTableLocalNameSchema.max(
POSTGRES_IDENTIFIER_MAX_LENGTH,
`Must not exceed ${POSTGRES_IDENTIFIER_MAX_LENGTH} characters.`,
);
export function moduleTableNamespace(moduleId: ModuleId): string {
return moduleIdSchema.parse(moduleId).replaceAll("-", "_");
}
export function moduleTablePrefix(moduleId: ModuleId): string {
return `${moduleTableNamespace(moduleId)}_`;
}
export function moduleTableName(moduleId: ModuleId, localName: string): string {
const parsedLocalName = moduleTableLocalNameSchema.parse(localName);
const tableName = `${moduleTablePrefix(moduleId)}${parsedLocalName}`;
if (!physicalModuleTableNameSchema.safeParse(tableName).success) {
throw new RangeError("The namespaced PostgreSQL table name is invalid or too long.");
}
return tableName;
}
@@ -16,7 +16,7 @@ import {
function validManifest(): Record<string, unknown> { function validManifest(): Record<string, unknown> {
return { return {
manifestVersion: 7, manifestVersion: 8,
id: "calendar", id: "calendar",
name: "Calendar", name: "Calendar",
version: "0.1.0", version: "0.1.0",
@@ -42,6 +42,24 @@ function validManifest(): Record<string, unknown> {
} }
describe("module manifest contract", () => { describe("module manifest contract", () => {
it("accepts both manifest-v8 database modes", () => {
expect(parseModuleManifest(validManifest()).database).toBeUndefined();
expect(parseModuleManifest({ ...validManifest(), database: { abi: 1 } }).database).toEqual({
abi: 1,
});
});
it("rejects manifest v7, unsupported ABIs, malformed declarations, and unknown database fields", () => {
expect(safeParseModuleManifest({ ...validManifest(), manifestVersion: 7 }).success).toBe(false);
expect(safeParseModuleManifest({ ...validManifest(), database: { abi: 2 } }).success).toBe(
false,
);
expect(safeParseModuleManifest({ ...validManifest(), database: "abi-v1" }).success).toBe(false);
expect(
safeParseModuleManifest({ ...validManifest(), database: { abi: 1, driver: "drizzle" } })
.success,
).toBe(false);
});
it("normalizes a valid manifest with safe defaults", () => { it("normalizes a valid manifest with safe defaults", () => {
const manifest = parseModuleManifest(validManifest()); const manifest = parseModuleManifest(validManifest());
@@ -232,15 +250,15 @@ describe("module manifest contract", () => {
expect(safeParseModuleManifest(version5Manifest).success).toBe(false); expect(safeParseModuleManifest(version5Manifest).success).toBe(false);
}); });
it("rejects a version 6 manifest rather than silently interpreting it as version 7", () => { it("rejects a version 6 manifest rather than silently interpreting it as version 8", () => {
const version6Manifest = { ...validManifest(), manifestVersion: 6 }; const version6Manifest = { ...validManifest(), manifestVersion: 6 };
expect(safeParseModuleManifest(version6Manifest).success).toBe(false); expect(safeParseModuleManifest(version6Manifest).success).toBe(false);
}); });
it("accepts exactly one manifest version, so no document can be read as two versions", () => { it("accepts exactly one manifest version, so no document can be read as two versions", () => {
expect(MODULE_MANIFEST_VERSION).toBe(7); expect(MODULE_MANIFEST_VERSION).toBe(8);
for (const manifestVersion of [1, 2, 3, 4, 5, 6, 8, "7", 7.5, null]) { for (const manifestVersion of [1, 2, 3, 4, 5, 6, 7, 9, "8", 8.5, null]) {
expect(safeParseModuleManifest({ ...validManifest(), manifestVersion }).success).toBe(false); expect(safeParseModuleManifest({ ...validManifest(), manifestVersion }).success).toBe(false);
} }
expect( expect(
@@ -1,13 +1,15 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { import {
MODULE_PACKAGE_FORMAT, MODULE_PACKAGE_FORMAT,
MODULE_PACKAGE_LICENSE_FILENAME,
MODULE_PACKAGE_METADATA_FILENAME, MODULE_PACKAGE_METADATA_FILENAME,
modulePackageArchiveFileName, modulePackageArchiveFileName,
modulePackageRuntimePackage, modulePackageRuntimePackage,
safeParseModulePackageLicenseExpression,
safeParseModulePackageMetadata, safeParseModulePackageMetadata,
safeParseModulePackageRuntimePackage, safeParseModulePackageRuntimePackage,
safeParseModulePackageTarget, safeParseModulePackageTarget,
} from "../src/index.js"; } from "../src/module-package.js";
const digest = "a".repeat(64); const digest = "a".repeat(64);
@@ -15,6 +17,7 @@ function metadata(overrides: Record<string, unknown> = {}): Record<string, unkno
return { return {
packageFormat: 1, packageFormat: 1,
module: { id: "example", version: "0.1.0" }, module: { id: "example", version: "0.1.0" },
license: "AGPL-3.0-or-later",
target: "any", target: "any",
runtime: { node: ">=24.11.0 <25" }, runtime: { node: ">=24.11.0 <25" },
provenance: { provenance: {
@@ -24,6 +27,7 @@ function metadata(overrides: Record<string, unknown> = {}): Record<string, unkno
incorporates: { "@ekklesia/contracts": "0.1.2", "@ekklesia/module-sdk": "0.1.2" }, incorporates: { "@ekklesia/contracts": "0.1.2", "@ekklesia/module-sdk": "0.1.2" },
transitional: { databaseRuntime: { "drizzle-orm": "0.45.2" } }, transitional: { databaseRuntime: { "drizzle-orm": "0.45.2" } },
files: [ files: [
{ path: "LICENSE", size: 9, sha256: digest },
{ path: "THIRD_PARTY_NOTICES", size: 10, sha256: digest }, { path: "THIRD_PARTY_NOTICES", size: 10, sha256: digest },
{ path: "dist/server/index.js", size: 20, sha256: digest }, { path: "dist/server/index.js", size: 20, sha256: digest },
{ path: "ekklesia.module.json", size: 30, sha256: digest }, { path: "ekklesia.module.json", size: 30, sha256: digest },
@@ -36,12 +40,46 @@ function metadata(overrides: Record<string, unknown> = {}): Record<string, unkno
describe("Ekklesia Module Package v1 metadata (ADR 0049)", () => { describe("Ekklesia Module Package v1 metadata (ADR 0049)", () => {
it("names the format, its metadata file, and the recommended archive file name", () => { it("names the format, its metadata file, and the recommended archive file name", () => {
expect(MODULE_PACKAGE_FORMAT).toBe(1); expect(MODULE_PACKAGE_FORMAT).toBe(1);
expect(MODULE_PACKAGE_LICENSE_FILENAME).toBe("LICENSE");
expect(MODULE_PACKAGE_METADATA_FILENAME).toBe("ekklesia.package.json"); expect(MODULE_PACKAGE_METADATA_FILENAME).toBe("ekklesia.package.json");
expect(modulePackageArchiveFileName("example", "0.1.0", "any")).toBe( expect(modulePackageArchiveFileName("example", "0.1.0", "any")).toBe(
"example-0.1.0-any.tar.gz", "example-0.1.0-any.tar.gz",
); );
}); });
it("accepts SPDX license expressions and rejects non-expressions without a policy allowlist", () => {
for (const expression of [
"AGPL-3.0-or-later",
"MIT OR Apache-2.0",
"(MIT OR Apache-2.0) AND BSD-3-Clause",
]) {
expect(safeParseModulePackageLicenseExpression(expression).success, expression).toBe(true);
}
for (const expression of ["", "UNLICENSED", "MIT OR", "not a license", {}]) {
expect(safeParseModulePackageLicenseExpression(expression).success, String(expression)).toBe(
false,
);
}
});
it("requires the package license declaration and canonical LICENSE payload entry", () => {
const withoutLicense = metadata();
delete withoutLicense.license;
expect(safeParseModulePackageMetadata(withoutLicense).success).toBe(false);
const withoutLicenseFile = metadata();
withoutLicenseFile.files = (withoutLicenseFile.files as { path: string }[]).filter(
(file) => file.path !== "LICENSE",
);
expect(safeParseModulePackageMetadata(withoutLicenseFile).success).toBe(false);
const emptyLicenseFile = metadata();
emptyLicenseFile.files = (emptyLicenseFile.files as { path: string; size: number }[]).map(
(file) => (file.path === "LICENSE" ? { ...file, size: 0 } : file),
);
expect(safeParseModulePackageMetadata(emptyLicenseFile).success).toBe(false);
});
it("accepts a complete any-target package description", () => { it("accepts a complete any-target package description", () => {
expect(safeParseModulePackageMetadata(metadata()).success).toBe(true); expect(safeParseModulePackageMetadata(metadata()).success).toBe(true);
}); });
@@ -97,7 +135,9 @@ describe("Ekklesia Module Package v1 metadata (ADR 0049)", () => {
).toBe(false); ).toBe(false);
// Byte-wise, not locale order: upper case sorts before lower case. // Byte-wise, not locale order: upper case sorts before lower case.
expect( expect(
safeParseModulePackageMetadata(metadata({ files: [entry("THIRD"), entry("dist")] })).success, safeParseModulePackageMetadata(
metadata({ files: [entry("LICENSE"), entry("THIRD"), entry("dist")] }),
).success,
).toBe(true); ).toBe(true);
}); });
@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";
import { parseModuleSchemaMetadataDefinition } from "../src/index.js";
describe("module schema metadata contract", () => {
it("accepts and freezes plain ABI-v1 metadata", () => {
const definition = parseModuleSchemaMetadataDefinition({
moduleId: "calendar",
tables: [
{ name: "calendar_events" },
{ name: "calendar_attendees", foreignKeys: [{ table: "calendar_events" }] },
],
});
expect(definition).toEqual({
moduleId: "calendar",
tables: [
{ name: "calendar_events", foreignKeys: [] },
{ name: "calendar_attendees", foreignKeys: [{ table: "calendar_events" }] },
],
});
expect(Object.isFrozen(definition)).toBe(true);
expect(Object.isFrozen(definition.tables)).toBe(true);
expect(Object.isFrozen(definition.tables[1]?.foreignKeys)).toBe(true);
});
it("strictly rejects malformed, executable, and class-backed metadata", () => {
class Metadata {
moduleId = "calendar";
tables = [{ name: "calendar_events" }];
}
for (const value of [
{ moduleId: "calendar", tables: [] },
{ moduleId: "calendar", tables: [{ name: "calendar_events", unknown: true }] },
{ moduleId: "calendar", tables: [{ name: "calendar_events", foreignKeys: [{}] }] },
{ moduleId: "calendar", tables: [{ name: "calendar_events", inspect: () => undefined }] },
new Metadata(),
]) {
expect(() => parseModuleSchemaMetadataDefinition(value)).toThrow(
"Invalid Ekklesia module schema metadata definition.",
);
}
});
});
+1 -36
View File
@@ -1,11 +1,5 @@
import { alias, getTableConfig, integer } from "drizzle-orm/pg-core";
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { import { moduleTableName, physicalModuleTableNameSchema } from "../src/index.js";
moduleTableName,
parseModuleSchemaDefinition,
physicalModuleTableNameSchema,
} from "../src/index.js";
import { pgTable } from "drizzle-orm/pg-core";
describe("module schema contract", () => { describe("module schema contract", () => {
it("creates deterministic physical names from module and local identifiers", () => { it("creates deterministic physical names from module and local identifiers", () => {
@@ -22,33 +16,4 @@ describe("module schema contract", () => {
"The namespaced PostgreSQL table name is invalid or too long.", "The namespaced PostgreSQL table name is invalid or too long.",
); );
}); });
it("normalizes and freezes a typed schema definition without freezing its tables", () => {
const records = pgTable("example_records", { id: integer().primaryKey() });
const definition = parseModuleSchemaDefinition({
moduleId: "example",
tables: { records },
});
expect(definition.tables.records).toBe(records);
expect(getTableConfig(records).name).toBe("example_records");
expect(Object.isFrozen(definition)).toBe(true);
expect(Object.isFrozen(definition.tables)).toBe(true);
expect(Object.isFrozen(records)).toBe(false);
});
it("rejects malformed, empty, unknown, and non-PostgreSQL table definitions", () => {
const records = pgTable("example_records", { id: integer() });
const disguisedRecords = alias(records, "example_disguised_records");
expect(() => parseModuleSchemaDefinition({ moduleId: "example", tables: {} })).toThrow();
expect(() =>
parseModuleSchemaDefinition({ moduleId: "example", tables: { records: {} } }),
).toThrow();
expect(() =>
parseModuleSchemaDefinition({ moduleId: "example", tables: { records }, extra: true }),
).toThrow();
expect(() =>
parseModuleSchemaDefinition({ moduleId: "example", tables: { disguisedRecords } }),
).toThrow();
});
}); });
+3 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "@ekklesia/design-tokens", "name": "@ekklesia/design-tokens",
"version": "0.1.2", "version": "0.2.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"type": "module", "type": "module",
"files": [ "files": [
@@ -15,7 +15,6 @@
"scripts": { "scripts": {
"build": "tsc --project tsconfig.build.json", "build": "tsc --project tsconfig.build.json",
"lint": "biome lint .", "lint": "biome lint .",
"prepack": "pnpm --workspace-root exec turbo run build --filter=@ekklesia/design-tokens",
"test": "vitest run", "test": "vitest run",
"typecheck": "tsc --noEmit --project tsconfig.json && tsc --noEmit --project tsconfig.test.json" "typecheck": "tsc --noEmit --project tsconfig.json && tsc --noEmit --project tsconfig.test.json"
}, },
@@ -28,6 +27,7 @@
"vitest": "4.1.10" "vitest": "4.1.10"
}, },
"ekklesia": { "ekklesia": {
"layer": "design-tokens" "layer": "design-tokens",
"distribution": "module-development"
} }
} }
+47
View File
@@ -0,0 +1,47 @@
{
"name": "@ekklesia/module-database",
"version": "0.2.0",
"license": "AGPL-3.0-or-later",
"type": "module",
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./drizzle": {
"types": "./dist/drizzle.d.ts",
"import": "./dist/drizzle.js"
}
},
"scripts": {
"build": "tsc --project tsconfig.build.json",
"lint": "biome lint .",
"test": "vitest run",
"typecheck": "tsc --noEmit --project tsconfig.json"
},
"dependencies": {
"@ekklesia/contracts": "workspace:*"
},
"devDependencies": {
"@biomejs/biome": "2.5.3",
"@types/node": "24.13.3",
"drizzle-orm": "0.45.2",
"typescript": "7.0.2",
"vitest": "4.1.10"
},
"ekklesia": {
"layer": "module-sdk",
"distribution": "module-development"
},
"peerDependencies": {
"drizzle-orm": ">=0.45.2 <0.46.0"
},
"peerDependenciesMeta": {
"drizzle-orm": {
"optional": true
}
}
}
+126
View File
@@ -0,0 +1,126 @@
import type {
ModuleDatabaseExecutor,
ModuleDatabaseParameter,
ModuleDatabaseQueryable,
ModuleDatabaseTransaction,
ModuleId,
ModuleSchemaMetadataDefinition,
} from "@ekklesia/contracts";
import {
moduleTableName,
moduleTablePrefix,
parseModuleSchemaMetadataDefinition,
} from "@ekklesia/contracts";
import { type AnyPgTable, getTableConfig, pgTableCreator } from "drizzle-orm/pg-core";
import { drizzle, type PgRemoteDatabase } from "drizzle-orm/pg-proxy";
import type { DrizzleConfig } from "drizzle-orm/utils";
type MaybePromise<T> = Promise<T> | T;
type DrizzleSurface<TSchema extends Record<string, unknown>> = Pick<
PgRemoteDatabase<TSchema>,
"delete" | "insert" | "select" | "update"
>;
export type ModuleDrizzleTransaction<
TSchema extends Record<string, unknown> = Record<string, never>,
> = DrizzleSurface<TSchema> & {
transaction<T>(
callback: (transaction: ModuleDrizzleTransaction<TSchema>) => MaybePromise<T>,
): Promise<T>;
};
export type ModuleDrizzleDatabase<TSchema extends Record<string, unknown> = Record<string, never>> =
DrizzleSurface<TSchema> & {
transaction<T>(
callback: (transaction: ModuleDrizzleTransaction<TSchema>) => MaybePromise<T>,
): Promise<T>;
};
type TransactionRunner<TSchema extends Record<string, unknown>> = <T>(
callback: (transaction: ModuleDrizzleTransaction<TSchema>) => MaybePromise<T>,
) => Promise<T>;
function remoteDatabase<TSchema extends Record<string, unknown>>(
executor: ModuleDatabaseQueryable,
config: DrizzleConfig<TSchema>,
runTransaction: TransactionRunner<TSchema>,
): ModuleDrizzleDatabase<TSchema> {
const database = drizzle<TSchema>(async (text, parameters) => {
const result = await executor.query({
text,
// Drizzle performs column-specific parameter encoding before this callback. Values outside
// ABI v1 remain unchanged so the ABI executor, not the adapter, rejects them.
values: parameters as readonly ModuleDatabaseParameter[],
// Drizzle maps selected fields by position. Array rows also remain correct when a join returns
// duplicate PostgreSQL column names.
rowMode: "array",
});
return { rows: result.rows as unknown as unknown[][] };
}, config);
return Object.freeze({
delete: database.delete.bind(database),
insert: database.insert.bind(database),
select: database.select.bind(database),
transaction: runTransaction,
update: database.update.bind(database),
}) as ModuleDrizzleDatabase<TSchema>;
}
function transactionDatabase<TSchema extends Record<string, unknown>>(
transaction: ModuleDatabaseTransaction,
config: DrizzleConfig<TSchema>,
): ModuleDrizzleTransaction<TSchema> {
return remoteDatabase(transaction, config, (callback) =>
transaction.savepoint((savepoint) => callback(transactionDatabase(savepoint, config))),
);
}
/**
* Creates a module-owned Drizzle database backed exclusively by Module Database ABI v1 calls.
*
* Drizzle compiles and decodes on the module side. Core receives only SQL text, ordered parameter
* values, and `rowMode: "array"`. Top-level transactions use the ABI transaction callback; nested
* Drizzle transactions use ABI savepoints.
*/
export function moduleDrizzle<TSchema extends Record<string, unknown> = Record<string, never>>(
executor: ModuleDatabaseExecutor,
config: DrizzleConfig<TSchema> = {},
): ModuleDrizzleDatabase<TSchema> {
return remoteDatabase(executor, config, (callback) =>
executor.transaction((transaction) => callback(transactionDatabase(transaction, config))),
);
}
/** Derives the plain ABI-v1 schema entrypoint from a module's own Drizzle tables. Drizzle stays on
* this module-side adapter path; Core consumes only the returned strings and arrays. */
export function moduleDrizzleSchemaMetadata(
moduleId: ModuleId,
tables: Readonly<Record<string, AnyPgTable>>,
): ModuleSchemaMetadataDefinition {
const metadata = Object.entries(tables)
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
.map(([_exportName, table]) => {
const config = getTableConfig(table);
if (config.schema !== undefined && config.schema !== "public") {
throw new TypeError("Module schema metadata supports only the public PostgreSQL schema.");
}
return {
name: config.name,
foreignKeys: config.foreignKeys.map((foreignKey) => ({
table: getTableConfig(foreignKey.reference().foreignTable).name,
})),
};
});
return parseModuleSchemaMetadataDefinition({ moduleId, tables: metadata });
}
/**
* A Drizzle table factory for this module's tables: every table it creates gets the module's
* mandatory namespace (ADR 0007), so `createModuleTable("care-team")("members", …)` is the physical
* table `care_team_members`.
*/
export function createModuleTable(moduleId: ModuleId) {
moduleTablePrefix(moduleId);
return pgTableCreator((localName) => moduleTableName(moduleId, localName));
}
+96
View File
@@ -0,0 +1,96 @@
import {
isModuleDatabaseError,
type ModuleDatabaseError,
type ModuleDatabaseParameter,
type ModuleDatabaseQuery,
type ModuleSchemaMetadataDefinition,
parseModuleSchemaMetadataDefinition,
} from "@ekklesia/contracts";
/**
* `@ekklesia/module-database`: everything a module needs for the Module Database ABI v1 (ADR 0050),
* with no ORM. Drizzle support lives in the `@ekklesia/module-database/drizzle` subpath, the only
* place that needs Drizzle (ADR 0053).
*/
export {
isModuleDatabaseError,
MODULE_DATABASE_ABI_VERSION,
MODULE_DATABASE_ERROR_CODES,
type ModuleDatabaseAbiVersion,
type ModuleDatabaseArrayRow,
ModuleDatabaseError,
type ModuleDatabaseErrorCode,
type ModuleDatabaseExecutor,
type ModuleDatabaseField,
type ModuleDatabaseIsolationLevel,
type ModuleDatabaseObjectRow,
type ModuleDatabaseParameter,
type ModuleDatabaseQuery,
type ModuleDatabaseQueryable,
type ModuleDatabaseQueryResult,
type ModuleDatabaseRowMode,
type ModuleDatabaseScalar,
type ModuleDatabaseTransaction,
type ModuleDatabaseTransactionOptions,
type ModuleDatabaseValue,
type ModuleSchemaForeignKeyMetadata,
type ModuleSchemaMetadataDefinition,
type ModuleSchemaTableMetadata,
moduleTableName,
moduleTablePrefix,
} from "@ekklesia/contracts";
/**
* A module's plain schema metadata (ADR 0050): the tables it owns and their foreign keys, with no
* ORM object. Validated and frozen; a Drizzle module derives the same data with
* `moduleDrizzleSchemaMetadata` from `@ekklesia/module-database/drizzle`.
*/
export function defineModuleSchemaMetadata<const Definition extends ModuleSchemaMetadataDefinition>(
definition: Definition,
): Readonly<Definition> {
return parseModuleSchemaMetadataDefinition(definition) as Readonly<Definition>;
}
/** SQL text and values ready to pass directly to a Module Database ABI v1 executor. */
export type ModuleSqlQuery = Readonly<Required<Pick<ModuleDatabaseQuery, "text" | "values">>>;
/**
* Builds one PostgreSQL statement without ever interpolating a value into its text.
*
* Every interpolation becomes the next positional parameter. Dynamic identifiers and trusted SQL
* fragments are deliberately unsupported in v1: keep identifiers in the static template text.
*/
export function sql(
strings: TemplateStringsArray,
...values: readonly ModuleDatabaseParameter[]
): ModuleSqlQuery {
let text = strings[0] ?? "";
for (let index = 0; index < values.length; index += 1) {
text += `$${index + 1}${strings[index + 1] ?? ""}`;
}
return Object.freeze({ text, values: Object.freeze([...values]) });
}
export type EkklesiaDatabaseError = Pick<
ModuleDatabaseError,
"code" | "message" | "name" | "sqlState"
>;
/**
* Finds a stable Ekklesia database error through wrappers such as DrizzleQueryError.
*
* Callers inspect the returned `code` and `sqlState`; they never need a PostgreSQL driver error,
* `.cause.code`, or message parsing.
*/
export function findEkklesiaDatabaseError(value: unknown): EkklesiaDatabaseError | undefined {
const visited = new Set<unknown>();
let current = value;
while (current instanceof Error && !visited.has(current)) {
if (isModuleDatabaseError(current)) {
return current;
}
visited.add(current);
current = current.cause;
}
return undefined;
}
@@ -0,0 +1,48 @@
import { readFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const workspaceRoot = path.resolve(packageRoot, "..", "..");
async function text(relative: string): Promise<string> {
return readFile(path.resolve(workspaceRoot, relative), "utf8");
}
describe("the module-side database architecture", () => {
it("keeps the Drizzle adapter free of Core, pg, and Core-owned Drizzle types", async () => {
const source = await text("packages/module-database/src/drizzle.ts");
expect(source).not.toMatch(/@ekklesia\/core|from ["']pg["']|node-postgres/u);
expect(source).not.toMatch(/NodePgDatabase|NodePgTransaction/u);
expect(source).toContain("@ekklesia/contracts");
expect(source).toContain("drizzle-orm/pg-proxy");
});
it("keeps ABI v1 contracts free of ORM imports", async () => {
for (const file of ["module-database-abi.ts", "module-schema-metadata.ts"]) {
const source = await text(`packages/contracts/src/${file}`);
expect(source).not.toMatch(/(?:import|export).*drizzle-orm/u);
expect(source).not.toMatch(/(?:import|export).*kysely/u);
expect(source).not.toMatch(/(?:import|export).*\bpg\b/u);
}
});
it("makes Drizzle an optional ranged peer and keeps raw SQL independent from it", async () => {
const manifest = JSON.parse(await text("packages/module-database/package.json")) as Record<
string,
Record<string, string>
>;
expect(manifest.dependencies).not.toHaveProperty("drizzle-orm");
expect(manifest.peerDependencies?.["drizzle-orm"]).toBe(">=0.45.2 <0.46.0");
expect(manifest.peerDependenciesMeta?.["drizzle-orm"]).toEqual({ optional: true });
const rawSource = await text("packages/module-database/src/index.ts");
expect(rawSource).not.toContain("drizzle-orm");
});
it("does not introduce an adapter dependency into Core", async () => {
const manifest = await text("core/package.json");
expect(manifest).not.toContain("@ekklesia/module-database");
});
});
@@ -1,20 +1,17 @@
import { getTableConfig, integer } from "drizzle-orm/pg-core"; import { getTableConfig, integer } from "drizzle-orm/pg-core";
import { describe, expect, it } from "vitest"; import { describe, expect, it } from "vitest";
import { createModuleTable, defineModuleSchema } from "../src/index.js"; import { createModuleTable, moduleDrizzleSchemaMetadata } from "../src/drizzle.js";
describe("module schema authoring", () => { describe("Drizzle module tables", () => {
it("creates namespaced PostgreSQL tables and a typed frozen definition", () => { it("creates namespaced PostgreSQL tables that become plain schema metadata", () => {
const moduleTable = createModuleTable("care-team"); const moduleTable = createModuleTable("care-team");
const members = moduleTable("members", { id: integer().primaryKey() }); const members = moduleTable("members", { id: integer().primaryKey() });
const definition = defineModuleSchema({
moduleId: "care-team",
tables: { members },
});
expect(getTableConfig(members).name).toBe("care_team_members"); expect(getTableConfig(members).name).toBe("care_team_members");
expect(definition.tables.members).toBe(members); expect(moduleDrizzleSchemaMetadata("care-team", { members })).toEqual({
expect(Object.isFrozen(definition)).toBe(true); moduleId: "care-team",
expect(Object.isFrozen(definition.tables)).toBe(true); tables: [{ foreignKeys: [], name: "care_team_members" }],
});
}); });
it("rejects invalid module and logical table names", () => { it("rejects invalid module and logical table names", () => {
@@ -0,0 +1,437 @@
import {
type ModuleDatabaseArrayRow,
ModuleDatabaseError,
type ModuleDatabaseExecutor,
type ModuleDatabaseField,
type ModuleDatabaseObjectRow,
type ModuleDatabaseQuery,
type ModuleDatabaseQueryResult,
type ModuleDatabaseTransaction,
} from "@ekklesia/contracts";
import { and, sql as drizzleSql, eq } from "drizzle-orm";
import {
bigint,
customType,
date,
integer,
json,
jsonb,
numeric,
pgTable,
text,
timestamp,
} from "drizzle-orm/pg-core";
import { describe, expect, expectTypeOf, it } from "vitest";
import {
type ModuleDrizzleDatabase,
moduleDrizzle,
moduleDrizzleSchemaMetadata,
} from "../src/drizzle.js";
import { findEkklesiaDatabaseError } from "../src/index.js";
const bytea = customType<{ data: Uint8Array; driverData: Uint8Array }>({
dataType: () => "bytea",
});
const records = pgTable("calendar_records", {
amount: numeric("amount"),
bigId: bigint("big_id", { mode: "bigint" }).notNull(),
bytes: bytea("bytes"),
count: integer("count").notNull(),
createdAt: timestamp("created_at", { mode: "date", withTimezone: true }).notNull(),
day: date("day", { mode: "date" }).notNull(),
id: integer("id").primaryKey(),
localAt: timestamp("local_at", { mode: "date" }).notNull(),
metadata: jsonb("metadata"),
nullable: text("nullable"),
payload: json("payload"),
scores: bigint("scores", { mode: "bigint" }).array(),
tags: text("tags").array(),
title: text("title").notNull(),
});
const categories = pgTable("calendar_categories", {
id: integer("id").primaryKey(),
title: text("title").notNull(),
});
type Outcome = Error | ModuleDatabaseQueryResult<ModuleDatabaseArrayRow | ModuleDatabaseObjectRow>;
interface RecordedCall {
readonly query: ModuleDatabaseQuery;
readonly scope: string;
}
const noFields: readonly ModuleDatabaseField[] = [];
function result(
rows: readonly ModuleDatabaseArrayRow[],
command = "SELECT",
): ModuleDatabaseQueryResult<ModuleDatabaseArrayRow> {
return { command, fields: noFields, rowCount: rows.length, rows };
}
class FakeState {
readonly calls: RecordedCall[] = [];
readonly events: string[] = [];
readonly outcomes: Outcome[] = [];
}
class FakeTransaction implements ModuleDatabaseTransaction {
readonly abiVersion = 1;
constructor(
private readonly state: FakeState,
private readonly scope: string,
) {}
query(
query: ModuleDatabaseQuery & { readonly rowMode: "array" },
): Promise<ModuleDatabaseQueryResult<ModuleDatabaseArrayRow>>;
query(
query: ModuleDatabaseQuery & { readonly rowMode?: "object" },
): Promise<ModuleDatabaseQueryResult<ModuleDatabaseObjectRow>>;
query(
query: ModuleDatabaseQuery,
): Promise<ModuleDatabaseQueryResult<ModuleDatabaseObjectRow | ModuleDatabaseArrayRow>>;
async query(
query: ModuleDatabaseQuery,
): Promise<ModuleDatabaseQueryResult<ModuleDatabaseObjectRow | ModuleDatabaseArrayRow>> {
this.state.calls.push({ query, scope: this.scope });
this.state.events.push(`${this.scope}:query`);
const outcome = this.state.outcomes.shift() ?? result([]);
if (outcome instanceof Error) {
throw outcome;
}
return outcome;
}
async savepoint<T>(
callback: (savepoint: ModuleDatabaseTransaction) => Promise<T> | T,
): Promise<T> {
const scope = `${this.scope}.savepoint`;
this.state.events.push(`${scope}:begin`);
try {
const value = await callback(new FakeTransaction(this.state, scope));
this.state.events.push(`${scope}:release`);
return value;
} catch (error) {
this.state.events.push(`${scope}:rollback`);
throw error;
}
}
}
class FakeExecutor implements ModuleDatabaseExecutor {
readonly abiVersion = 1;
readonly state = new FakeState();
query(
query: ModuleDatabaseQuery & { readonly rowMode: "array" },
): Promise<ModuleDatabaseQueryResult<ModuleDatabaseArrayRow>>;
query(
query: ModuleDatabaseQuery & { readonly rowMode?: "object" },
): Promise<ModuleDatabaseQueryResult<ModuleDatabaseObjectRow>>;
query(
query: ModuleDatabaseQuery,
): Promise<ModuleDatabaseQueryResult<ModuleDatabaseObjectRow | ModuleDatabaseArrayRow>>;
async query(
query: ModuleDatabaseQuery,
): Promise<ModuleDatabaseQueryResult<ModuleDatabaseObjectRow | ModuleDatabaseArrayRow>> {
return new FakeTransaction(this.state, "executor").query(query);
}
async transaction<T>(
callback: (transaction: ModuleDatabaseTransaction) => Promise<T> | T,
): Promise<T> {
this.state.events.push("transaction:begin");
try {
const value = await callback(new FakeTransaction(this.state, "transaction"));
this.state.events.push("transaction:commit");
return value;
} catch (error) {
this.state.events.push("transaction:rollback");
throw error;
}
}
}
function setup(...outcomes: Outcome[]) {
const executor = new FakeExecutor();
executor.state.outcomes.push(...outcomes);
return { db: moduleDrizzle(executor), executor };
}
describe("moduleDrizzle query compilation and ABI mapping", () => {
it("derives plain Ekklesia schema metadata with foreign-key targets", () => {
const child = pgTable("calendar_children", {
id: integer("id").primaryKey(),
recordId: integer("record_id").references(() => records.id),
});
const metadata = moduleDrizzleSchemaMetadata("calendar", { records, child });
expect(metadata).toEqual({
moduleId: "calendar",
tables: [
{ name: "calendar_children", foreignKeys: [{ table: "calendar_records" }] },
{ name: "calendar_records", foreignKeys: [] },
],
});
expect(JSON.parse(JSON.stringify(metadata))).toEqual(metadata);
});
it("compiles a select and decodes its positional result on the module side", async () => {
const { db, executor } = setup(result([[7, "Launch"]]));
await expect(
db.select({ id: records.id, title: records.title }).from(records).where(eq(records.id, 7)),
).resolves.toEqual([{ id: 7, title: "Launch" }]);
expect(executor.state.calls).toEqual([
{
query: {
text: 'select "id", "title" from "calendar_records" where "calendar_records"."id" = $1',
values: [7],
rowMode: "array",
},
scope: "executor",
},
]);
});
it("compiles insert returning through the array-row ABI", async () => {
const { db, executor } = setup(result([[8, "New"]], "INSERT"));
await expect(
db
.insert(records)
.values({
bigId: 8n,
count: 1,
createdAt: new Date("2026-01-02T03:04:05.000Z"),
day: new Date("2026-01-02T00:00:00.000Z"),
id: 8,
localAt: new Date("2026-01-02T03:04:05.000Z"),
title: "New",
})
.returning({ id: records.id, title: records.title }),
).resolves.toEqual([{ id: 8, title: "New" }]);
expect(executor.state.calls[0]?.query).toMatchObject({
rowMode: "array",
values: [
8n,
1,
"2026-01-02T03:04:05.000Z",
"2026-01-02T00:00:00.000Z",
8,
"2026-01-02T03:04:05.000Z",
"New",
],
});
expect(executor.state.calls[0]?.query.text).toContain('insert into "calendar_records"');
expect(executor.state.calls[0]?.query.text).toContain('returning "id", "title"');
});
it("compiles an update returning with a SQL expression", async () => {
const { db, executor } = setup(result([[7, 4]], "UPDATE"));
await expect(
db
.update(records)
.set({ count: drizzleSql`${records.count} + 1` })
.where(and(eq(records.id, 7), eq(records.title, "Launch")))
.returning({ count: records.count, id: records.id }),
).resolves.toEqual([{ count: 7, id: 4 }]);
expect(executor.state.calls[0]?.query).toEqual({
text: 'update "calendar_records" set "count" = "calendar_records"."count" + 1 where ("calendar_records"."id" = $1 and "calendar_records"."title" = $2) returning "count", "id"',
values: [7, "Launch"],
rowMode: "array",
});
});
it("compiles delete returning", async () => {
const { db, executor } = setup(result([[7, "Old"]], "DELETE"));
await expect(
db
.delete(records)
.where(eq(records.id, 7))
.returning({ id: records.id, title: records.title }),
).resolves.toEqual([{ id: 7, title: "Old" }]);
expect(executor.state.calls[0]?.query).toEqual({
text: 'delete from "calendar_records" where "calendar_records"."id" = $1 returning "id", "title"',
values: [7],
rowMode: "array",
});
});
it("uses positions rather than duplicate database column names for joins", async () => {
const { db, executor } = setup(result([[9, "Category", 3, "Record"]]));
await expect(
db
.select({
categoryId: categories.id,
categoryTitle: categories.title,
recordId: records.id,
recordTitle: records.title,
})
.from(records)
.innerJoin(categories, eq(records.id, categories.id)),
).resolves.toEqual([
{ categoryId: 9, categoryTitle: "Category", recordId: 3, recordTitle: "Record" },
]);
expect(executor.state.calls[0]?.query.rowMode).toBe("array");
expect(executor.state.calls[0]?.query.text).toContain(
'select "calendar_categories"."id", "calendar_categories"."title", "calendar_records"."id", "calendar_records"."title"',
);
});
});
describe("moduleDrizzle result decoding", () => {
it("lets Drizzle decode every stable low-level ABI representation", async () => {
const bytes = new Uint8Array([0, 127, 255]);
const { db, executor } = setup(
result([
[
"1234567890.0123456789",
"12345678901234567890",
bytes,
"2026-01-02 03:04:05+00",
"2026-01-02",
"2026-01-02 03:04:05",
'{"kind":"jsonb"}',
null,
'{"kind":"json"}',
["3", "9007199254740993"],
["one", "two"],
],
]),
);
const rows = await db
.select({
amount: records.amount,
bigId: records.bigId,
bytes: records.bytes,
createdAt: records.createdAt,
day: records.day,
localAt: records.localAt,
metadata: records.metadata,
nullable: records.nullable,
payload: records.payload,
scores: records.scores,
tags: records.tags,
})
.from(records);
expect(rows).toEqual([
{
amount: "1234567890.0123456789",
bigId: 12_345_678_901_234_567_890n,
bytes,
createdAt: new Date("2026-01-02T03:04:05.000Z"),
day: new Date("2026-01-02T00:00:00.000Z"),
localAt: new Date("2026-01-02T03:04:05.000Z"),
metadata: { kind: "jsonb" },
nullable: null,
payload: { kind: "json" },
scores: [3n, 9_007_199_254_740_993n],
tags: ["one", "two"],
},
]);
expect(rows[0]?.bytes).toBe(bytes);
expect(executor.state.calls[0]?.query.rowMode).toBe("array");
});
});
describe("moduleDrizzle transactions", () => {
it("maps top-level and nested transactions to ABI callbacks and savepoints", async () => {
const { db, executor } = setup(result([[1]]), result([[2]]), result([[3]]));
const value = await db.transaction(async (transaction) => {
await transaction.select({ id: records.id }).from(records);
const nested = await transaction.transaction(async (savepoint) => {
await savepoint.select({ id: records.id }).from(records);
return "nested";
});
await transaction.select({ id: records.id }).from(records);
return `${nested}-result`;
});
expect(value).toBe("nested-result");
expect(executor.state.events).toEqual([
"transaction:begin",
"transaction:query",
"transaction.savepoint:begin",
"transaction.savepoint:query",
"transaction.savepoint:release",
"transaction:query",
"transaction:commit",
]);
expect(executor.state.calls.map((call) => call.scope)).toEqual([
"transaction",
"transaction.savepoint",
"transaction",
]);
});
it("propagates callback errors unchanged and leaves rollback to the ABI", async () => {
const { db, executor } = setup();
const failure = new Error("module callback failed");
await expect(
db.transaction(() => {
throw failure;
}),
).rejects.toBe(failure);
expect(executor.state.events).toEqual(["transaction:begin", "transaction:rollback"]);
});
it("rolls a rejected nested callback back to its ABI savepoint", async () => {
const { db, executor } = setup();
const failure = new Error("nested callback failed");
await expect(
db.transaction((transaction) => transaction.transaction(() => Promise.reject(failure))),
).rejects.toBe(failure);
expect(executor.state.events).toEqual([
"transaction:begin",
"transaction.savepoint:begin",
"transaction.savepoint:rollback",
"transaction:rollback",
]);
});
});
describe("moduleDrizzle error and type boundaries", () => {
it("recovers the stable ABI code and SQLSTATE from Drizzle's wrapper", async () => {
const databaseError = new ModuleDatabaseError("MODULE_DATABASE_QUERY_FAILED", {
sqlState: "23505",
});
const { db } = setup(databaseError);
let thrown: unknown;
try {
await db.select({ id: records.id }).from(records);
} catch (error) {
thrown = error;
}
expect(thrown).toBeInstanceOf(Error);
expect(findEkklesiaDatabaseError(thrown)).toBe(databaseError);
expect(findEkklesiaDatabaseError(thrown)).toMatchObject({
code: "MODULE_DATABASE_QUERY_FAILED",
sqlState: "23505",
});
expect(databaseError).not.toHaveProperty("query");
expect(databaseError).not.toHaveProperty("params");
expect(databaseError).not.toHaveProperty("detail");
expect(databaseError).not.toHaveProperty("hint");
});
it("retains the module's schema inference without Core or pg database types", () => {
const executor = new FakeExecutor();
const schema = { records };
const db = moduleDrizzle(executor, { schema });
expectTypeOf(db).toMatchTypeOf<ModuleDrizzleDatabase<typeof schema>>();
expectTypeOf(db.select().from(records)).resolves.toEqualTypeOf<
(typeof records.$inferSelect)[]
>();
expect(Object.keys(db).sort()).toEqual(["delete", "insert", "select", "transaction", "update"]);
expect(db).not.toHaveProperty("_");
expect(db).not.toHaveProperty("$client");
expect(db).not.toHaveProperty("execute");
expect(db).not.toHaveProperty("query");
});
});

Some files were not shown because too many files have changed in this diff Show More