Summary
When generating types for a Harper 5.x application whose schema places tables in databases whose names contain hyphens, the generated globalTypes.d.ts and types.ts are invalid TypeScript and do not augment the module the app actually imports. The output produces hundreds of tsc errors and provides no usable typing for databases.
I hit three distinct problems (the first two are hard blockers).
Environment
- Harper:
5.1.9
@harperfast/schema-codegen: reproduced on both 1.1.1 and 2.0.0-beta.1
- TypeScript:
5.9.x, tsc --noEmit
- App imports Harper via the
harper package (Harper 5.x), not harperdb.
Issue 1 — Generated module augmentation targets harperdb, not harper
generateTablesDTS.js hardcodes the module name:
// utils/generateTablesDTS.js
content += `import type { Table } from 'harperdb';\n`; // line 18
content += `declare module 'harperdb' {\n`; // line 42
In Harper 5.x the runtime package is harper. Apps do import { databases } from "harper", so a declare module 'harperdb' augmentation never attaches — databases stays untyped (or falls back to the base type), defeating the purpose of the generated .d.ts.
Expected: emit declare module 'harper' (or make the target package configurable) for Harper 5.x projects.
Issue 2 — Invalid TypeScript identifiers for tables in hyphenated databases
Type names are built by concatenating the database name and table name without sanitizing the result into a valid identifier:
// utils/generateTS.js (lines 22–25)
const dbPrefix =
table.databaseName && table.databaseName !== 'data' ? `${table.databaseName}_` : '';
const plural = `${dbPrefix}${table.tableName}`;
const singular = `${dbPrefix}${singularize(table.tableName)}`;
For a database named metrics-github, this emits identifiers like metrics-github_Repository. A hyphen is not a legal identifier character, so TypeScript parses metrics-github_Repository as the subtraction metrics - github_Repository. Every interface in types.ts and every reference in globalTypes.d.ts for a hyphenated database is invalid:
// generated types.ts
export interface metrics-github_Repository { ... } // ❌ invalid identifier
// generated globalTypes.d.ts
Repository: { new(...args: any[]): Table<metrics-github_Repository> }; // ❌
This alone produced ~1100 tsc errors in our project.
Expected: sanitize the prefix into a valid identifier (e.g. metrics-github → metrics_github or metricsGithub) consistently in both the declaration site and all reference sites.
Issue 3 — Codegen emits types for every database on the connected instance (no scoping)
collectTables() iterates the entire live databases object, so the output includes every database present on the Harper instance, not just the ones belonging to this application. On a shared local instance, unrelated databases/tables (from other projects) get written into the app's types.ts/globalTypes.d.ts.
Expected (enhancement): a way to scope generation to the application's own databases (e.g. those declared in the project's schema.graphql), or at least an include/exclude option.
Reproduction
- Harper 5.1.9 app importing from the
harper package.
- Schema with a table in a hyphenated database:
type Repository @table(database: "metrics-github") @export {
id: ID @primaryKey
name: String
}
- Enable the extension in
config.yaml:
"@harperfast/schema-codegen":
package: "@harperfast/schema-codegen"
globalTypes: "schemas/globalTypes.d.ts"
schemaTypes: "schemas/types.ts"
- Run
harper dev . and let it generate.
- Inspect the output:
globalTypes.d.ts contains declare module 'harperdb' (Issue 1)
types.ts contains export interface metrics-github_Repository { ... } (Issue 2)
- extra unrelated databases appear if the instance hosts more than this app (Issue 3)
tsc --noEmit over the generated files → hundreds of errors.
Impact
With hyphenated multi-database schemas on Harper 5.x, the generated types are unusable; we had to hand-write a module augmentation as a workaround. Issues 1 and 2 look like small, well-scoped fixes (module string + identifier sanitization).
Summary
When generating types for a Harper 5.x application whose schema places tables in databases whose names contain hyphens, the generated
globalTypes.d.tsandtypes.tsare invalid TypeScript and do not augment the module the app actually imports. The output produces hundreds oftscerrors and provides no usable typing fordatabases.I hit three distinct problems (the first two are hard blockers).
Environment
5.1.9@harperfast/schema-codegen: reproduced on both1.1.1and2.0.0-beta.15.9.x,tsc --noEmitharperpackage (Harper 5.x), notharperdb.Issue 1 — Generated module augmentation targets
harperdb, notharpergenerateTablesDTS.jshardcodes the module name:In Harper 5.x the runtime package is
harper. Apps doimport { databases } from "harper", so adeclare module 'harperdb'augmentation never attaches —databasesstays untyped (or falls back to the base type), defeating the purpose of the generated.d.ts.Expected: emit
declare module 'harper'(or make the target package configurable) for Harper 5.x projects.Issue 2 — Invalid TypeScript identifiers for tables in hyphenated databases
Type names are built by concatenating the database name and table name without sanitizing the result into a valid identifier:
For a database named
metrics-github, this emits identifiers likemetrics-github_Repository. A hyphen is not a legal identifier character, so TypeScript parsesmetrics-github_Repositoryas the subtractionmetrics - github_Repository. Every interface intypes.tsand every reference inglobalTypes.d.tsfor a hyphenated database is invalid:This alone produced ~1100
tscerrors in our project.Expected: sanitize the prefix into a valid identifier (e.g.
metrics-github→metrics_githubormetricsGithub) consistently in both the declaration site and all reference sites.Issue 3 — Codegen emits types for every database on the connected instance (no scoping)
collectTables()iterates the entire livedatabasesobject, so the output includes every database present on the Harper instance, not just the ones belonging to this application. On a shared local instance, unrelated databases/tables (from other projects) get written into the app'stypes.ts/globalTypes.d.ts.Expected (enhancement): a way to scope generation to the application's own databases (e.g. those declared in the project's
schema.graphql), or at least an include/exclude option.Reproduction
harperpackage.config.yaml:harper dev .and let it generate.globalTypes.d.tscontainsdeclare module 'harperdb'(Issue 1)types.tscontainsexport interface metrics-github_Repository { ... }(Issue 2)tsc --noEmitover the generated files → hundreds of errors.Impact
With hyphenated multi-database schemas on Harper 5.x, the generated types are unusable; we had to hand-write a module augmentation as a workaround. Issues 1 and 2 look like small, well-scoped fixes (module string + identifier sanitization).