Skip to content

Expand static types#206

Draft
dawsontoth wants to merge 16 commits intomainfrom
typeical
Draft

Expand static types#206
dawsontoth wants to merge 16 commits intomainfrom
typeical

Conversation

@dawsontoth
Copy link
Contributor

@dawsontoth dawsontoth commented Mar 10, 2026

I did a few things here:

  1. I fixed a bug I found in getIndexedValues
  2. I fixed the schema description for shard in the config-root.schema.json
  3. I added interfaces describing the methods and stuff we have on tables and resources, shuffling things around a little bit to facilitate that

Why? Well, it will more easily describe our tables and resources for consumers. I shifted the tables and databases to point people at these interfaces instead of at the return value of makeTable. These are a lot easier for IDEs, agents, and humans to read as a result. It will also let people guard their types when using static methods themselves.

Here's the question, though: what should be described in the interfaces for statics? What shouldn't be described, because its an internal implementation detail?

@dawsontoth dawsontoth changed the title fix: Remove v1+v2, defaulting to v1, and expand table interface Expand static types Mar 10, 2026
@dawsontoth dawsontoth marked this pull request as ready for review March 10, 2026 18:52
@dawsontoth dawsontoth requested a review from a team as a code owner March 10, 2026 18:52
Copy link
Member

@kriszyp kriszyp left a comment

Choose a reason for hiding this comment

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

Lots of great stuff, thank you for working on this!

import { Context, Id, ResourceInterface, type ResourceStaticInterface } from './ResourceInterface.ts';
import { DBI } from './DatabaseInterface.ts';

export interface Table<Record extends object = any> extends TableInterface<Record> {
Copy link
Member

Choose a reason for hiding this comment

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

Are these all things we are exposing in our public interface, or things that we have declare internally for consistency? We certainly don't document these nor ever want users accessing most of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should only put stuff in that we want to expose, IMO

import { Context, Id, ResourceInterface, type ResourceStaticInterface } from './ResourceInterface.ts';
import { DBI } from './DatabaseInterface.ts';

export interface Table<Record extends object = any> extends TableInterface<Record> {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I understand the different between the TableInterface and the TableStaticInterface. All the properties on TableInterface are statics, so not sure how it is less static than the other statics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yeah, I muddled things up there a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the Table and the TableInterface weren't different -- I collapsed Table and TableInterface together, which is consistent with how we were using ResourceInterface.

TableStaticInterface, on the other hand, expresses the type that was being computed off of ReturnType<typeof makeTable>. It can be constructed, and when it does, it returns a TableInterface (just like ResourceInterface vs ResourceStaticInterface). I built it off of all of the static methods on the table class. The methods between the two are a bit different, as are the argument orders.

I think I need to take a pass through the CRUD methods for tables (which aren't static) to make sure they're accurately described in the interface, because we have a different order there vs what the Resource class expects. So that will be more updates for TableInterface.

Copy link
Contributor

@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.

Nice! Wish we had these types a long time ago! Couple of small nits that you can accept/ignore/punt.

@dawsontoth dawsontoth force-pushed the typeical branch 5 times, most recently from 7d7872b to caebdc4 Compare March 11, 2026 17:56
Copy link
Member

@kriszyp kriszyp left a comment

Choose a reason for hiding this comment

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

Is this kinda still in draft? Do you want me to put together a list of desired exposed properties/methods on tables?

* @param target - If included, is an identifier/query that specifies the requested target to retrieve and query
*/
get(target: RequestTargetOrId): Record | AsyncIterable<Record> | Promise<Record | AsyncIterable<Record>>;
get(target: RequestTargetOrId): AsyncIterable<Record> | Promise<Record>;
Copy link
Member

Choose a reason for hiding this comment

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

Above you are using ExtendedIterable, which is more correct, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kriszyp yup, still in draft -- we need a status between draft and ready, "ready to be torn apart" ;D

@dawsontoth dawsontoth marked this pull request as draft March 12, 2026 15:48
import type { Context, Id, ResourceInterface, ResourceStaticInterface } from './ResourceInterface.ts';
import type { DBI } from './DatabaseInterface.ts';

export interface TableInterface<Record extends object = any> extends ResourceInterface<Record> {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think any of these are table instance methods or properties except getExpiresAt() and getUpdatedTime().

remove: (valueToRemove, id: Id, options?: unknown) => void;
}

export interface TableStaticInterface<Record extends object = any> extends ResourceStaticInterface<Record> {
Copy link
Member

Choose a reason for hiding this comment

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

I think we probably want to expose these properties:

  • attributes
  • createdTimeProperty
  • databaseName
  • expirationMS
  • getResidencyById
  • primaryKey
  • replicate
  • schemaDefined
  • sealed
  • tableName
  • updatedTimeProperty

And methods:

  • addAttributes
  • coerceId
  • getRecordCount
  • getSize
  • getNewId
  • getStorageStats
  • removeAttributes
  • setTTLExpiration
  • sourcedFrom

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.

3 participants