GithubHelp home page GithubHelp logo

dynamo-types's People

Contributors

breath103 avatar davidjnelson avatar ktwbc avatar mooyoul avatar myaerocode avatar renovate-bot avatar semantic-release-bot avatar vingle-suzy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dynamo-types's Issues

ES5 support

Due to this project NPM distribution is compiled as ES6,
typescript projects targets ES5 does not compatible with this lib.
(ex,
Table class in this repo compiled as es6, so compiled result using class keyword.
Which cause error with ES5 complied project uses apply keyword (invoke class "TypeError: Class constructor Table cannot be invoked without 'new'")
)
why not use ES5 for backward compatibility?

Improve documentation

I have read the full documentation, but still I have some questions:

  • How to define local secondary indexes and global secondary indexes?
  • How to query for local secondary indexes and global secondary indexes?
  • When using .query() and the result is paginated, does it resolve all pages automatically? Or is there an operator to do so?

error connecting

Hi,
Can you please share one example of connecting & creating table using orm.

Is there a way to apply filters expression on query

Hi,
thanks for your project!
I'm trying to use your library to execute get and queries on DynamoDB. I'd like to know if there is a way to apply also filters in a query operation, in my case on a GSI.
Is there also a way to use ExclusiveStartKey for the next query call?
Thanks

Query.GlobalSecondayIndex.scan doesn’t pass IndexName

The scan method on the GSI query class doesn’t actually pass the IndexName property. So it actually performs a scan on the table instead of the GSI.

This seems unintentional, since a scan can performed on the table using the Query.PrimaryKey.scan method.

Feature Request: Ability to specify type in decorator, to allow Class type

Putting this in as a feature request (which I may try to tackle)

When you define your table class, the variables are all expected to be primative types, suchas:

export class DynamoTest extends Table {

  @Decorator.HashPrimaryKey('id')
  public static readonly primaryKey: Query.HashPrimaryKey<DynamoTest, string>;

  @Decorator.Attribute({ name: "id" })
  id: string;

  @Decorator.Attribute({ name: "status" })
  status: string;

  @Decorator.Attribute({ name: "user" })
  user: Object;

  @Decorator.Writer()
  public static readonly writer: Query.Writer<DynamoTest>;

}

The problem is that in the case of User here, I don't want to just define a generic object, I want to use my User class I have defined:

export class User {
  id: number;
  name: string;
  email: string;
}

If I define my Table to use this:

 @Decorator.Attribute({ name: "user" })
  user: User;

it will error out because it's not a type that the library recognizes.

I still want it to be an Object (which based on node_modules/dynamo-types/src/decorator/attribute.ts gets translated into a Map) but a very specific object so my other code hinting works.

I'm thinking the solution is to allow the Decorator to have an optional Type field that would be an override, such as:

 @Decorator.Attribute({ name: "user", type: Object })
  user: User;

So if the type is in the attribute, use that before autodetecting and that would let the variable itself be defined by an actual class name.

basically:

export function Attribute<T>(options: { name?: string, timeToLive?: true, type?: string } = {}) {

batch write ignoring failed writes

The response back from DocumentClient on BatchWrite will include any failed writes, which usually need to be resubmitted (sometimes with a linear backoff)

The call from DynamoDb returns UnprocessedItems but batch_write.js will not check this, and this results in missed items when writing batches to the table.

will try and submit a PR when I have time but I have code from a different attempt which was working but would need to be redone to fit in with how this file works

async.forEachOf(arrParams, function (params: DynamoDB.DocumentClient.BatchWriteItemInput, key: number, eachDone: Callback) {

      let backoffCount = 1;

      let processItemsCallback = (error: AWSError, result: DynamoDB.DocumentClient.BatchWriteItemRequestMap) => {
        
        if (error) {
          return eachDone(error);
        } else {
          if (Object.keys(result.UnprocessedItems).length !== 0) {

            let params: any = {};
            params.RequestItems = result.UnprocessedItems;

            backoffCount++;

            setTimeout(() => {
              dynamoDb.batchWrite(params, processItemsCallback);
            }, 1000 * backoffCount);

          } else {
            eachDone();
          }
        }
      };

      dynamoDb.batchWrite(params, processItemsCallback);

    }, function done(err: Error) {
    ...etc

Add AWS config to documentation

This module looks awesome but I wonder how to use it with AWS. The readme shows no configuration of region, accessKeyId and secretAccessKey.

Also I wonder if it works with aws-sdk and if I might pass in my existing instance of it.

Could you add this to the readme example? Thanks so much!

node version?

error [email protected]: The engine "node" is incompatible with this module. Expected version "8.10.*". Got "8.16.0"

Is there anything specific that will break on the later 8 LTS?

This repository will no longer be maintained.

I suppose this might be confusing, even saddening news for contributors of this repository.
This library initially developed while building Vingle.
Since it doesn't contains any business logic, We nurtured this as open source from very beginning - to share the benefit of it with wider serverless & AWS & Typescript communities, and to get contributions from those communities as well

But since all of its core contributors left Vingle at 2020, including myself and @mooyoul @deerFried,
we got into situation where Vingle orgs owns the repository, yet there is nobody in Vingle who can actively maintain the repository.
As a solution, we tried to transfer this repository along with other open source libraries to public github org dedicated on those libraries, serverless-seoul, In order to keep the contribution / issues / PR history.
but we've asked to put this back to under Vingle org, with mentioning of legal obligation for copy rights to company.

As a result, we have no choice but to hard fork this repository.
We're trying to achieve those things by doing so:

  • No central entity such as company or corporation on future of those libraries
  • Keeping the door open for future contributions
  • Active maintenance, including full documentation

@MyAeroCode @ktwbc @rogueturnip @lorenzocastelli @MickL @benhutchins @NoelBaron @brianjd @mikecann @thakursunakshi @singhdeepme @sanchaysdn @evaneus @civilizeddev @tscj3490 @mihirogi @justin-gerhardt
Thanks for your contributions, sorry for the not optimal result here. please refer Dynamorm for further maintenance and contribution, we'll be actively maintaining this repo - we've just added documents -

thanks.

nativeType returns null, throwing an error from _nativeTypeToAttributeMetadataType

Using 2.3.3 release and the sample class from docs:

import {
  Config,
  Decorator,
  Query,
  Table,
} from "dynamo-types";
 
@Decorator.Table({ name: `table_name` })
export class CardStat extends Table {
  @Decorator.HashPrimaryKey("card_id")
  public static readonly primaryKey: Query.HashPrimaryKey<CardStat, number>;
 
  @Decorator.Writer()
  public static readonly writer: Query.Writer<CardStat>;
 
  @Decorator.Attribute({ name: "card_id" })
  public cardId: number;
 
  @Decorator.Attribute({ name: "impressions_count" })
  public impressionsCount: number = 0;
 
  @Decorator.Attribute({ name: "shares" })
  public shares: number = 0;
}

When I try to use this class I get an error because Reflect.getMetadata() returns null here:
https://github.com/balmbees/dynamo-typeorm/blob/master/src/decorator/attribute.ts#L8

Stacktrace:

"Error","stackTrace":["Error: Unsupported type undefined","at _nativeTypeToAttributeMetadataType (/Users/e/dev/p/node_modules/dynamo-types/dst/decorator/attribute.js:35:15)","at Attribute (/Users/e/dev/p/node_modules/dynamo-types/dst/decorator/attribute.js:13:19)","at DecorateProperty (/Users/e/dev/p/node_modules/reflect-metadata/Reflect.js:553:33)","at Object.decorate (/Users/e/dev/p/node_modules/reflect-metadata/Reflect.js:123:24)","at __decorate (/Users/e/dev/p/.build/src/db/Card.js:4:92)","at Object.<anonymous> (/Users/e/dev/p/.build/src/db/Card.js:17:1)","at Module._compile (module.js:569:30)","at Object.Module._extensions..js (module.js:580:10)","at Module.load (module.js:503:32)","at tryModuleLoad (module.js:466:12)","at Function.Module._load (module.js:458:3)","at Module.require (module.js:513:17)","at require (internal/module.js:11:18)","at Object.<anonymous> (/Users/e/dev/p/.build/src/db/fixtures.js:11:16)","at Module._compile (module.js:569:30)","at Object.Module._extensions..js (module.js:580:10)","at Module.load (module.js:503:32)","at tryModuleLoad (module.js:466:12)","at Function.Module._load (module.js:458:3)","at Module.require (module.js:513:17)","at require (internal/module.js:11:18)","at Object.<anonymous> (/Users/e/dev/p/.build/src/graphql/index.js:8:20)","at Module._compile (module.js:569:30)","at Object.Module._extensions..js (module.js:580:10)","at Module.load (module.js:503:32)","at tryModuleLoad (module.js:466:12)","at Function.Module._load (module.js:458:3)","at Module.require (module.js:513:17)","at require (internal/module.js:11:18)","at Object.createHandler (/Users/e/dev/p/node_modules/serverless-offline/src/functionHelper.js:35:21)","at handler (/Users/e/dev/p/node_modules/serverless-offline/src/index.js:500:40)","at Object.internals.handler 

Scan on global secondary index?

Is the scan() command missing from the global secondary index? I see both query() and scan() in primary but only query() in the global_secondary_index.ts file even though scan() is supported by DDB there too.

Remove `Decorator` namespace

Doesnt it make sense to remove the Decorator namespace for all decorators?

E.g.@Decorator.Table() to @Table().

As a reference I would like to point to TypeORM or Angular which dont prefix their decorators, too.

CreateTable fails when using TTL field with local-dynamo

If you are using the local-dynamo for unit testing, and your Class definition for your table uses the TTL feature via { timeToLive: true } , CreateTable() fails with an UnknownOperationException

Example in class:

 @Decorator.Attribute({ name: 'ttl_expire_epoch', timeToLive: true })
  public ttl_expire_epoch: number;

In this code in create_table:

const ttlAttribute = metadata.attributes.find(attr => !!attr.timeToLive);
        if (ttlAttribute) {
            yield metadata.connection.client.updateTimeToLive({
                TableName: metadata.name,
                TimeToLiveSpecification: {
                    Enabled: true,
                    AttributeName: ttlAttribute.name,
                }
            }).promise();
        }

This really should be local-dynamo's issue to ignore commands that are not applicable locally instead of throwing an error, but if we are able to test for that condition and skip in CreateTable() that would also work around the problem.

As a temporary workaround, I just trap the error in my unit test code to ignore it and go on

before((done) => {

    MyDynamoTable.createTable().then((result) => {
      done();
    }).catch((error) => {
      if (error.code === 'UnknownOperationException') {
        // console.log('Ignoring UnknownOperationException error');
        // This error happens because our table has a TTL field which local-dynamo doesn't support. DynamoTypes attempts to create
        // it which is rejected. But this isn't necessary for local testing, so we can ignore this. In case of other errors,
        // throw the error again to show the failure
        done();
      } else {
        done(error);
      }
    });
  });

Increment value in DynamoDB table

Hi! Thanks for the library! I've a question: Is it possible to update an item stored in the dynamoDB table incrementing a value without read it, update the value and finally write again.

Using the aws-sdk you can do something like it:
dynamoDB.updateItem({ TableName: "Users", Key: { "UserId": { S: "c6af9ac6-7b61" } }, ExpressionAttributeValues: { ":inc": {N: "1"} }, UpdateExpression: "ADD loginCount :inc" })
Thanks!

updates on lists

Hi,

Great library, found it very useful in my project and I've been able to figure out most things by looking at the code, however, I'm stuck on one item.

I'm trying to do updates on an item that contains a List of tags. I've used this example:

// UpdateItem calls
await Card.primaryKey.update(12345, { likesCount: ["ADD", 1] }, { 
  condition: { id: attributeExists() } ,
});

as a basis for it but where I'm stuck is based on the Dynamo documents I should be able to do a tags: ["SET", "tag1", "tag2", "tag3"] and it will modify the list. When I do this it fails for me. I'm hoping there is something simple I'm missing.

Thanks!

no initializer error

I'm running into the following error when trying to define a class:

import { Decorator, Query, Table } from "dynamo-types";

@Decorator.Table({ name: `users` })
export default class User extends Table {
  @Decorator.HashPrimaryKey("id")
  public static readonly primaryKey: Query.HashPrimaryKey<User, string>;

  @Decorator.Writer()
  public static readonly writer: Query.Writer<User>;

  @Decorator.Attribute()
  public id: string;

  @Decorator.Attribute()
  public name: string;

  @Decorator.Attribute()
  public email: string;

  @Decorator.Attribute()
  public image: string;
}

The error is on any of the @Decorator.Attribute fields:

Property 'image' has no initializer and is not definitely assigned in the constructor.ts(2564)

If I define a constructor though, it says I don't conform to the interface defined here:

new(): T;
.

I was looking at extending that interface to new(...args: any[]) but was curious why I would need to do that.

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.