Skip to content

Commit 1ea5e57

Browse files
committed
fix(appkit): generate a registry before the first operation
Signed-off-by: ditadi <victordperd@gmail.com>
1 parent 186f378 commit 1ea5e57

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎packages/appkit/src/type-generator/database/generate-operations.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,11 @@ async function contractsOf(
181181
/**
182182
* Discover `server/database/routes/*.ts`, write the lazy `routes.gen.ts` entry
183183
* that lists every module, and write the browser contract of each published
184-
* operation. Any malformed or duplicate declaration fails generation and
184+
* operation. A schema-only app gets an empty registry so development can
185+
* discover its first operation without restarting manually. Any malformed or duplicate declaration fails generation and
185186
* neutralizes the contracts; a declaration without authorization is skipped
186187
* with a warning, or fails in strict mode. Both files are created only while
187-
* the routes directory exists, and emptied once it is gone.
188+
* a schema or routes directory exists, and emptied once routes are gone.
188189
*/
189190
export async function generateDatabaseOperations(
190191
options: GenerateDatabaseOperationsOptions,
@@ -197,11 +198,14 @@ export async function generateDatabaseOperations(
197198
})
198199
?.isDirectory() ?? false;
199200
const files = routesPresent ? discoverRouteModules(options.appRoot) : [];
200-
if (routesPresent || fsSync.existsSync(routesFile)) {
201+
const schemaPresent = fsSync.existsSync(
202+
fromRoot(options.appRoot, SCHEMA_FILE),
203+
);
204+
if (schemaPresent || routesPresent || fsSync.existsSync(routesFile)) {
201205
await writeIfChanged(routesFile, renderDatabaseRoutes(files));
202206
}
203207
if (!routesPresent) {
204-
if (fsSync.existsSync(options.outFile)) {
208+
if (schemaPresent || fsSync.existsSync(options.outFile)) {
205209
await writeIfChanged(options.outFile, NEUTRAL_DATABASE_OPERATION_TYPES);
206210
}
207211
return;

‎packages/appkit/src/type-generator/database/tests/generate-operations.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,17 @@ export const databaseRoutes = {
181181
expect(types).not.toMatch(/^\s*import\b/m);
182182
});
183183

184-
test("creates nothing for an app without operation routes", async () => {
184+
test("creates a canonical empty registry and contracts for a schema-only app", async () => {
185185
const root = await app();
186186
await generate(root);
187+
expect(await read(root, ROUTES_FILE)).toContain("modules: []");
188+
expect(await read(root, TYPES_FILE)).toBe(NEUTRAL_DATABASE_OPERATION_TYPES);
189+
});
190+
191+
test("creates nothing for an app without a schema or operation routes", async () => {
192+
const root = await app();
193+
await fs.rm(path.join(root, "config"), { recursive: true });
194+
await generate(root);
187195
expect(await exists(root, ROUTES_FILE)).toBe(false);
188196
expect(await exists(root, TYPES_FILE)).toBe(false);
189197
});

0 commit comments

Comments
 (0)