Conversation
kriszyp
left a comment
There was a problem hiding this comment.
Lots of great stuff, thank you for working on this!
resources/TableInterface.ts
Outdated
| import { Context, Id, ResourceInterface, type ResourceStaticInterface } from './ResourceInterface.ts'; | ||
| import { DBI } from './DatabaseInterface.ts'; | ||
|
|
||
| export interface Table<Record extends object = any> extends TableInterface<Record> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
We should only put stuff in that we want to expose, IMO
resources/TableInterface.ts
Outdated
| import { Context, Id, ResourceInterface, type ResourceStaticInterface } from './ResourceInterface.ts'; | ||
| import { DBI } from './DatabaseInterface.ts'; | ||
|
|
||
| export interface Table<Record extends object = any> extends TableInterface<Record> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ah, yeah, I muddled things up there a bit.
There was a problem hiding this comment.
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.
cb1kenobi
left a comment
There was a problem hiding this comment.
Nice! Wish we had these types a long time ago! Couple of small nits that you can accept/ignore/punt.
7d7872b to
caebdc4
Compare
kriszyp
left a comment
There was a problem hiding this comment.
Is this kinda still in draft? Do you want me to put together a list of desired exposed properties/methods on tables?
resources/Table.ts
Outdated
| * @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>; |
There was a problem hiding this comment.
Above you are using ExtendedIterable, which is more correct, I think.
There was a problem hiding this comment.
@kriszyp yup, still in draft -- we need a status between draft and ready, "ready to be torn apart" ;D
The `return values.push` would return integers or null directly.
Since I’m not sure, let’s leave it.
| 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> { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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
I did a few things here:
shardin the config-root.schema.jsonWhy? Well, it will more easily describe our tables and resources for consumers. I shifted the
tablesanddatabasesto 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?