Giter Club home page Giter Club logo

Comments (13)

liammullan avatar liammullan commented on July 21, 2024 1

Good stuff, thanks Michael, I'll have a look at this as soon as I can and ping you back if any issues

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

Good spelunking!

We're prototyping the fetch method and exploring different options.

The alternative is: to use queryItems and groupByType as described in the README. We are exploring a cleaner way to read item collections using fetch.

Can you share your final .d.ts type definition?

from dynamodb-onetable.

liammullan avatar liammullan commented on July 21, 2024

Thanks for introducing me to a new word!

I didn't do anything with the .d.ts file, I just did a horrid cast to any:

    items = await table.fetch(["User", "UserProfile"], {pk: `User:${id}`}) as any // error in types file

    const users: UserType[] = items.User
    const profiles: UserProfileType[] = items.UserProfile

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

We're still not quite ready to cement the API for fetch. All ideas are welcome.

I'll get the .d.ts type fixed so you can experiment without the cast.

from dynamodb-onetable.

liammullan avatar liammullan commented on July 21, 2024

Perfect, many thanks.

Re the groupByType you mentioned, the README has this:

items = db.groupByType(items)

... but doesn't mention what "db" is? (Perhaps I'm being a bit dense here!)

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

We use db sometimes for table. It is a Table instance.

I'll fix the doc for that.

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

Just pushed to the REPO:

Added a type for fetch() and groupByType to Table.d.ts.

export type EntityGroup = {
    [key: string]: AnyEntity
};

fetch(models: string[], properties: OneProperties, params?: OneParams): Promise<EntityGroup>;
groupByType(items: AnyEntity[]): EntityGroup;

And added a test/typescript-tennant.ts which does some basic exercise of the fetch API.

Though still not documented (fetch), here is the usage:

let collection = await table.fetch(['Account', 'User'], {pk: `account#${account.id}`})

You give a list of model types and the PK. Fetch has an implicit params.parse == true.
Returns similar to groupByType.

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

Fixed in 1.5.5.

Please give some feedback about the API. I'd like to settle on this and document it.

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

I'll keep this issue open until fetch is released fully.

from dynamodb-onetable.

liammullan avatar liammullan commented on July 21, 2024

Apologies Michael, I've been pulled onto something else briefly, I'll ping you back about this asap

from dynamodb-onetable.

liammullan avatar liammullan commented on July 21, 2024

Hey, so with the change to table.fetch... if you key into the EntityGroup the .d.ts says we get a single AnyEntity value, but in reality we get AnyEntity[] don't we?

As far as the fetch api itself goes it is useful, for sure. I can't help wondering whether we could get stronger typing. E.g. rather than keying into a collection by string (type name) could we key by model - i.e. Model<T> - with the value being T[]? May not be possible, I haven't delved into the code.

Cheers!

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

Understand. You would need to iterate the models first parameter.

Alternatively we could do something like:

let collection = await fetch<User, Account>(['User', 'Account'], {pk})

Otherwise, you would need to iterate the models array and construct type types from that. Not sure if TypeScript can enumerate arrays like we do when iterating the schema to create the model types.

from dynamodb-onetable.

mobsense avatar mobsense commented on July 21, 2024

We're going to document the current implementation for now.

from dynamodb-onetable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.