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]>
125 lines
4.1 KiB
TypeScript
125 lines
4.1 KiB
TypeScript
import { describe, expect, expectTypeOf, it, vi } from "vitest";
|
|
import {
|
|
defineModuleRuntime,
|
|
EMPTY_MODULE_CONFIGURATION,
|
|
isModuleHttpMethod,
|
|
MODULE_HTTP_METHODS,
|
|
type ModuleHttpRouteRegistrar,
|
|
type ModuleRegistrationContext,
|
|
type ModuleRuntimeDefinitionWithDatabase,
|
|
type ModuleRuntimeDefinitionWithoutDatabase,
|
|
} from "../src/index.js";
|
|
|
|
describe("defineModuleRuntime", () => {
|
|
it("types the ABI executor for a database module, and no database at all otherwise", () => {
|
|
defineModuleRuntime({
|
|
database: { abi: 1 },
|
|
id: "example",
|
|
version: "0.1.0",
|
|
start({ services }) {
|
|
expectTypeOf(services.database.query).toBeFunction();
|
|
expectTypeOf(services.database.abiVersion).toEqualTypeOf<1>();
|
|
// @ts-expect-error ABI-v1 modules never receive the legacy Drizzle facade.
|
|
services.database.select();
|
|
},
|
|
register({ http }) {
|
|
http.route({
|
|
handler: (_request, { services }) => {
|
|
expectTypeOf(services.database.abiVersion).toEqualTypeOf<1>();
|
|
return new Response();
|
|
},
|
|
maxBodyBytes: 0,
|
|
method: "GET",
|
|
path: "/",
|
|
permission: "example.read",
|
|
});
|
|
},
|
|
});
|
|
|
|
defineModuleRuntime({
|
|
id: "no-database",
|
|
version: "0.1.0",
|
|
start({ services }) {
|
|
// The SDK never types the legacy Drizzle facade (ADR 0053): a module without the ABI has
|
|
// no database to reach.
|
|
expectTypeOf(services.database).toBeNever();
|
|
},
|
|
});
|
|
});
|
|
|
|
it("types the result as the SDK's own named interfaces, so a module's declarations can name it", () => {
|
|
// A module that emits declarations names its default export's type; with an inferred literal
|
|
// type that would reach into packages a standalone module does not depend on directly.
|
|
expectTypeOf(
|
|
defineModuleRuntime({ database: { abi: 1 }, id: "example", version: "0.1.0" }),
|
|
).toEqualTypeOf<ModuleRuntimeDefinitionWithDatabase>();
|
|
expectTypeOf(
|
|
defineModuleRuntime({ id: "example", version: "0.1.0" }),
|
|
).toEqualTypeOf<ModuleRuntimeDefinitionWithoutDatabase>();
|
|
});
|
|
|
|
it("defines a frozen server runtime without duplicating the static manifest", async () => {
|
|
const start = vi.fn();
|
|
const runtime = defineModuleRuntime({
|
|
id: "example",
|
|
start,
|
|
version: "0.1.0",
|
|
});
|
|
|
|
expect(runtime).toEqual({ id: "example", start, version: "0.1.0" });
|
|
expect(Object.isFrozen(runtime)).toBe(true);
|
|
});
|
|
|
|
it("rejects invalid runtime definitions", () => {
|
|
expect(() =>
|
|
defineModuleRuntime({
|
|
id: "Not Valid",
|
|
version: "0.1.0",
|
|
}),
|
|
).toThrow("Invalid Ekklesia module runtime definition.");
|
|
});
|
|
|
|
it("re-exports the module-http contract so a module's register hook can declare routes", async () => {
|
|
expect(MODULE_HTTP_METHODS).toContain("GET");
|
|
expect(isModuleHttpMethod("GET")).toBe(true);
|
|
expect(isModuleHttpMethod("get")).toBe(false);
|
|
|
|
const registeredRoutes: unknown[] = [];
|
|
const http: ModuleHttpRouteRegistrar = {
|
|
route: (definition) => {
|
|
registeredRoutes.push(definition);
|
|
},
|
|
};
|
|
const runtime = defineModuleRuntime({
|
|
id: "example",
|
|
version: "0.1.0",
|
|
register({ http: registrar }) {
|
|
registrar.route({
|
|
method: "GET",
|
|
path: "/records",
|
|
permission: "example.records.read",
|
|
maxBodyBytes: 0,
|
|
handler: () => new Response(null, { status: 204 }),
|
|
});
|
|
},
|
|
});
|
|
|
|
const context: ModuleRegistrationContext = {
|
|
capabilities: {
|
|
provide: () => undefined,
|
|
resolve: () => undefined,
|
|
},
|
|
// A module declaring no configuration still receives an empty snapshot rather than
|
|
// `undefined`, so module code never branches on whether the platform supplied one.
|
|
config: EMPTY_MODULE_CONFIGURATION,
|
|
http,
|
|
moduleId: "example",
|
|
realtime: { channel: () => undefined },
|
|
};
|
|
await runtime.register?.(context);
|
|
|
|
expect(registeredRoutes).toHaveLength(1);
|
|
expect(registeredRoutes[0]).toMatchObject({ method: "GET", path: "/records" });
|
|
});
|
|
});
|