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
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
This commit is contained in:
@@ -22,6 +22,7 @@ export interface FakePackage {
|
||||
}
|
||||
|
||||
export interface FixtureModuleOptions {
|
||||
readonly databaseAbi?: 1;
|
||||
readonly id?: string;
|
||||
readonly version?: string;
|
||||
readonly serverSource?: string;
|
||||
@@ -55,19 +56,27 @@ async function write(file: string, contents: string | Uint8Array): Promise<void>
|
||||
const defaultServer = (
|
||||
id: string,
|
||||
version: string,
|
||||
databaseAbi?: 1,
|
||||
) => `import { defineModuleRuntime } from "@ekklesia/module-sdk";
|
||||
export default defineModuleRuntime({ id: ${JSON.stringify(id)}, version: ${JSON.stringify(version)}, register() {} });
|
||||
export default defineModuleRuntime({ ${databaseAbi === 1 ? "database: { abi: 1 }, " : ""}id: ${JSON.stringify(id)}, version: ${JSON.stringify(version)}, register() {} });
|
||||
`;
|
||||
|
||||
const schemaSource = (
|
||||
id: string,
|
||||
) => `import { createModuleTable, defineModuleSchema } from "@ekklesia/module-sdk";
|
||||
const schemaSource = (id: string, databaseAbi?: 1) => `${
|
||||
databaseAbi === 1
|
||||
? 'import { moduleDrizzleSchemaMetadata } from "@ekklesia/module-database/drizzle";'
|
||||
: 'import { defineModuleSchema } from "@ekklesia/module-sdk";'
|
||||
}
|
||||
import { createModuleTable } from "@ekklesia/module-sdk";
|
||||
import { text, uuid } from "drizzle-orm/pg-core";
|
||||
export const records = createModuleTable(${JSON.stringify(id)})("records", {
|
||||
id: uuid("id").primaryKey(),
|
||||
value: text("value").notNull(),
|
||||
});
|
||||
export default defineModuleSchema({ moduleId: ${JSON.stringify(id)}, tables: { records } });
|
||||
export default ${
|
||||
databaseAbi === 1
|
||||
? `moduleDrizzleSchemaMetadata(${JSON.stringify(id)}, { records })`
|
||||
: `defineModuleSchema({ moduleId: ${JSON.stringify(id)}, tables: { records } })`
|
||||
};
|
||||
`;
|
||||
|
||||
export async function fixtureModule(options: FixtureModuleOptions = {}): Promise<string> {
|
||||
@@ -76,6 +85,7 @@ export async function fixtureModule(options: FixtureModuleOptions = {}): Promise
|
||||
const root = await scratchDirectory("ekklesia-pack-fixture-");
|
||||
const moduleDirectory = path.join(root, id);
|
||||
const tableName = `${id.replaceAll("-", "_")}_records`;
|
||||
const usesModuleDatabase = options.withModuleDatabase || options.databaseAbi === 1;
|
||||
|
||||
const baseManifest: Record<string, unknown> = {
|
||||
manifestVersion: 8,
|
||||
@@ -83,6 +93,7 @@ export async function fixtureModule(options: FixtureModuleOptions = {}): Promise
|
||||
name: `${id} module`,
|
||||
version,
|
||||
compatibility: { platform: "^0.1.0", moduleSdk: "^0.1.0" },
|
||||
...(options.databaseAbi === 1 ? { database: { abi: 1 } } : {}),
|
||||
capabilities: [],
|
||||
permissions: [],
|
||||
entrypoints: {
|
||||
@@ -108,7 +119,7 @@ export async function fixtureModule(options: FixtureModuleOptions = {}): Promise
|
||||
scripts: { build: "tsc" },
|
||||
dependencies: {
|
||||
"@ekklesia/module-sdk": "workspace:*",
|
||||
...(options.withModuleDatabase ? { "@ekklesia/module-database": "workspace:*" } : {}),
|
||||
...(usesModuleDatabase ? { "@ekklesia/module-database": "workspace:*" } : {}),
|
||||
"drizzle-orm": "0.45.2",
|
||||
},
|
||||
devDependencies: { typescript: "7.0.2" },
|
||||
@@ -121,12 +132,15 @@ export async function fixtureModule(options: FixtureModuleOptions = {}): Promise
|
||||
);
|
||||
await write(
|
||||
path.join(moduleDirectory, "dist/server/index.js"),
|
||||
options.serverSource ?? defaultServer(id, version),
|
||||
options.serverSource ?? defaultServer(id, version, options.databaseAbi),
|
||||
);
|
||||
await write(path.join(moduleDirectory, "dist/server/index.js.map"), '{"version":3}\n');
|
||||
await write(path.join(moduleDirectory, "dist/server/index.d.ts"), "export {};\n");
|
||||
if (options.withSchema) {
|
||||
await write(path.join(moduleDirectory, "dist/schema/index.js"), schemaSource(id));
|
||||
await write(
|
||||
path.join(moduleDirectory, "dist/schema/index.js"),
|
||||
schemaSource(id, options.databaseAbi),
|
||||
);
|
||||
}
|
||||
await write(path.join(moduleDirectory, "src/server/index.ts"), "export {};\n");
|
||||
await write(path.join(moduleDirectory, "tests/server.test.ts"), "export {};\n");
|
||||
@@ -171,7 +185,7 @@ export async function fixtureModule(options: FixtureModuleOptions = {}): Promise
|
||||
await realpath(path.join(packageRoot, "node_modules", "@ekklesia", "module-sdk")),
|
||||
path.join(modules, "@ekklesia", "module-sdk"),
|
||||
);
|
||||
if (options.withModuleDatabase) {
|
||||
if (usesModuleDatabase) {
|
||||
await symlink(
|
||||
await realpath(path.join(packageRoot, "node_modules", "@ekklesia", "module-database")),
|
||||
path.join(modules, "@ekklesia", "module-database"),
|
||||
|
||||
Reference in New Issue
Block a user