Comments (7)
@m-radzikowski yeap, I've already created MR due to comas issue #29
from dynamodb-onetable.
Thanks for the commas and pk/sk missing the type. For JavaScript this defaults to String, but agree it is needed by TypeScript to drive the typing.
Thanks. Can you explain the "User.balance field type Number is incompatible"? Are you saying the Number type is not working? I don't think the "balance" field is used as pk/sk in any of the examples.
Thanks.
from dynamodb-onetable.
Thanks. Can you explain the "User.balance field type Number is incompatible"? Are you saying the Number type is not working? I don't think the "balance" field is used as pk/sk in any of the examples.
@mobsense yes, when schema in Table has a field with Number type, you get an error I posted:
Type '{ type: NumberConstructor; default: number; }' is not assignable to type 'OneFieldSchema'.
It does not have to be used anywhere, just the declaration alone is problematic.
from dynamodb-onetable.
It looks like the issue isn't with Number but with the default type for numbers.
Can you please try the following patch
type OneFieldSchema = {
crypt?: boolean,
default?: (() => any) | string | number | boolean | object,
This changes the default type to permit number and boolean as well.
from dynamodb-onetable.
Hey y'all, I do believe this is still an issue. I wanted to try out dynamodb-onetable in TypeScript an hit type errors immediately. Riffing off of one of the examples, I wrote this:
const oneFieldSchema: OneFieldSchema = { type: String, value: 'card:${id}' }
const oneModelSchema: OneModelSchema = { pk: oneFieldSchema }
new Model(table, 'Card', {
fields: oneModelSchema
})
However, this gives a type error at fields
, which is supposed to have type
{
[key: string]: OneModelSchema
}
as defined here. It seems to me that there is one too many levels of nesting in the TypeScript definitions, and that fields
should have type OneModelSchema
directly.
from dynamodb-onetable.
Hi Mark, thanks for digging into this. I've reopened the issue and have tested and applied your pull request.
Testing around the issue, and creating some unit tests for this revealed a couple of other issues that we are addressing.
We've been migrating our internal tests to use Jest and add to the repo. I expect to push this tomorrow.
Generally, we find it easier to define schema centrally via the Table constructor. You can certainly do it per model, but I think it is easier via the schema.models in the table constructor and then use the following to create the type and the model.
type CardType = Entity<typeof DefaultSchema.models.Card>
let Card: Model<CardType> = table.getModel('Card')
I've mocked up your code sample and used it in our tests. I've defined the schema as a plain object. I've then derived the CardType from the schema. By giving to the Model constructor, the returned model "Card" is fully typed. and Card.create is fully typed.
With your patch (thank you), this works well.
import {AWS, Client, Entity, Model, Table, dump, print} from './utils/init'
test('Debug', async () => {
const table = new Table({
name: 'TypeScriptDebugTestTable',
client: Client,
schema: {
indexes: {primary: {hash: 'pk'}},
models: {},
}
})
await table.createTable()
const CardSchema = {
pk: { type: String, value: 'card:${id}' },
id: { type: String },
issuer: { type: String },
}
type CardType = Entity<typeof CardSchema>
let Card = new Model<CardType>(table, 'Card', { fields: CardSchema })
let card = await Card.create({id: 'x4567', issuer: 'visa'}, {hidden: true})
console.log(card.issuer)
//. Will fail console.log(card.x)
expect(card.issuer).toBe('visa')
expect(card.pk).toBe('card:x4567')
await table.deleteTable('DeleteTableForever')
})
from dynamodb-onetable.
Thanks a lot, @mobsense!
from dynamodb-onetable.
Related Issues (20)
- Error on pagination query HOT 3
- count: true param is not returning count value HOT 7
- BatchWrite does not handle Unprocessed Items correctly and ignores them HOT 1
- "?boolean" in Table.d.ts triggers typescript build error HOT 2
- model.upsert({ ...data }) returns a data with encrypted values HOT 2
- Need release to resolve Typescript ESM Resolution issues HOT 2
- params.fields are not respected when using table.getItem() or table.queryItems()
- Metrics.d.ts should not include function interfaces declared as 'async' HOT 7
- Improve: Prohibit the removal of nested object required fields. HOT 1
- Feature: Across entities query HOT 3
- Empty strings are filtered out HOT 2
- Cannot resolve type when ESM HOT 3
- Compound global index not updated if only 1 of 2 properties passed to the update function HOT 1
- Updating unique template field does not remove unique record HOT 2
- "CredentialsProviderError: The SSO session associated with this profile has expired" in "overview" sample... HOT 2
- Create method does not create the sort key if one attribute is undefined HOT 4
- Connecting OneTable to a local dynamodb instance
- Support for Mapped Types HOT 3
- Please Help: Update Problem (referenced attribute) HOT 3
- OneSchema type for getCurrentSchema() not set HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dynamodb-onetable.