Skip to content

Proposed v1.0.0 of Schema Codegen#1

Merged
dawsontoth merged 16 commits intomainfrom
release-v1
Mar 9, 2026
Merged

Proposed v1.0.0 of Schema Codegen#1
dawsontoth merged 16 commits intomainfrom
release-v1

Conversation

@dawsontoth
Copy link
Contributor

This PR mostly adds the workflows that we'll want, but it also formatted the code that I put together. Review whatever you feel like reviewing! Or just try it out on your project.

During dev, you'll want to git clone this repo, cd into it, and then (npm link && cd ~/path-to-your-app && npm link @harperfast/schema-codegen).

Then configure this in your app's config.yaml:

config.yaml:

'@harperfast/schema-codegen':
  package: '@harperfast/schema-codegen'
  globalTypes: 'schemas/globalTypes.d.ts'
  schemaTypes: 'schemas/types.ts'

and when you harper dev ., it will generate stuff in those two files for you:

globalTypes.d.ts:

/**
 Generated from your schema files
 Manual changes will be lost!
 > harper dev .
 */
import type { Table } from 'harperdb';
import type { Device, other_Device } from './types.ts';

declare module 'harperdb' {
	export const tables: {
		Devices: { new(...args: any[]): Table<Device> };
	};

	export const databases: {
		data: {
			Devices: { new(...args: any[]): Table<Device> };
		};
		other: {
			Devices: { new(...args: any[]): Table<other_Device> };
		};
	};
}

types.ts:

/**
 Generated from HarperDB schema
 Manual changes will be lost!
 > harper dev .
 */
export interface Device {
	id: string;
	userId: string;
	name?: string;
	lastActive?: number;
	status?: string;
	command?: string;
	commandTimestamp?: number;
	commandArgument?: any;
	lastActionByHuman?: number;
	instigatorDeviceId?: string;
}

export type NewDevice = Omit<Device, 'id'>;
export type Devices = Device[];
export type { Device as DeviceRecord };
export type DeviceRecords = Device[];
export type NewDeviceRecord = Omit<Device, 'id'>;

export interface other_Device {
	id: any;
	__createdtime__?: any;
	__updatedtime__?: any;
}

export type other_NewDevice = Omit<other_Device, 'id'>;
export type other_Devices = other_Device[];
export type { other_Device as other_DeviceRecord };
export type other_DeviceRecords = other_Device[];
export type other_NewDeviceRecord = Omit<other_Device, 'id'>;

@dawsontoth dawsontoth requested a review from a team March 4, 2026 17:36
@dawsontoth dawsontoth requested a review from cb1kenobi March 9, 2026 18:46
@dawsontoth
Copy link
Contributor Author

@cb1kenobi addressed everything!

@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you're curious, here's rocksdb-js' oxfmt config: https://github.com/HarperFast/rocksdb-js/blob/main/.oxfmtrc.json. Most of the settings are the defaults and could have been omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've got it down to the minimum in this repo -- are there other ones that you think should be the norm for Harper? Single quotes and tabs.

{
	"$schema": "./node_modules/oxfmt/configuration_schema.json",
	"singleQuote": true,
	"useTabs": true
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, I'll start applying this consistently across other repos I touch like Studio, Agent and create harper.

Copy link

@cb1kenobi cb1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dawsontoth dawsontoth merged commit 2a5f7e2 into main Mar 9, 2026
9 checks passed
@dawsontoth dawsontoth deleted the release-v1 branch March 9, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants