Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ginger.io/beyonce

Package Overview
Dependencies
Maintainers
8
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ginger.io/beyonce - npm Package Compare versions

Comparing version 0.0.33 to 0.0.34

12

dist/dynamo/Beyonce.d.ts

@@ -10,2 +10,8 @@ import { JayZ } from "@ginger.io/jay-z";

};
export declare type GetOptions = {
consistentRead?: boolean;
};
export declare type QueryOptions = {
consistentRead?: boolean;
};
/** A thin wrapper around the DynamoDB sdk client that

@@ -20,3 +26,3 @@ * does auto mapping between JSON <=> DynamoDB Items

/** Retrieve a single Item out of Dynamo */
get<T extends TaggedModel>(key: PartitionAndSortKey<T>): Promise<T | undefined>;
get<T extends TaggedModel>(key: PartitionAndSortKey<T>, options?: GetOptions): Promise<T | undefined>;
delete<T extends TaggedModel>(key: PartitionAndSortKey<T>): Promise<void>;

@@ -27,4 +33,4 @@ /** BatchGet items */

}): Promise<GroupedModels<ExtractKeyType<T>>>;
query<T extends TaggedModel>(key: PartitionKey<T> | PartitionKeyAndSortKeyPrefix<T>): QueryBuilder<T>;
queryGSI<T extends TaggedModel>(gsiName: string, gsiKey: PartitionKey<T>): QueryBuilder<T>;
query<T extends TaggedModel>(key: PartitionKey<T> | PartitionKeyAndSortKeyPrefix<T>, options?: QueryOptions): QueryBuilder<T>;
queryGSI<T extends TaggedModel>(gsiName: string, gsiKey: PartitionKey<T>, options?: QueryOptions): QueryBuilder<T>;
/** Write an item into Dynamo */

@@ -31,0 +37,0 @@ put<T extends TaggedModel>(item: T): Promise<void>;

@@ -28,3 +28,3 @@ "use strict";

/** Retrieve a single Item out of Dynamo */
get(key) {
get(key, options = {}) {
return __awaiter(this, void 0, void 0, function* () {

@@ -34,2 +34,3 @@ const { Item: item } = yield this.client

TableName: this.table.tableName,
ConsistentRead: options.consistentRead,
Key: {

@@ -92,3 +93,3 @@ [this.table.partitionKeyName]: key.partitionKey,

}
query(key) {
query(key, options = {}) {
const { table, jayz } = this;

@@ -100,5 +101,6 @@ return new QueryBuilder_1.QueryBuilder({

jayz: jayz,
consistentRead: options.consistentRead,
});
}
queryGSI(gsiName, gsiKey) {
queryGSI(gsiName, gsiKey, options = {}) {
const { table, jayz } = this;

@@ -111,2 +113,3 @@ return new QueryBuilder_1.QueryBuilder({

jayz,
consistentRead: options.consistentRead,
});

@@ -113,0 +116,0 @@ }

@@ -12,2 +12,3 @@ import { JayZ } from "@ginger.io/jay-z";

jayz?: JayZ;
consistentRead?: boolean;
};

@@ -20,5 +21,6 @@ declare type GSIQueryParams<T extends TaggedModel> = {

jayz?: JayZ;
consistentRead?: boolean;
};
export declare type Cursor = Record<string, any>;
export declare type QueryOptions = {
export declare type IteratorOptions = {
cursor?: Cursor;

@@ -40,3 +42,3 @@ pageSize?: number;

exec(): Promise<GroupedModels<T>>;
iterator(options?: QueryOptions): PaginatedQueryResults<T>;
iterator(options?: IteratorOptions): PaginatedQueryResults<T>;
private executeQuery;

@@ -43,0 +45,0 @@ private buildQuery;

@@ -118,3 +118,3 @@ "use strict";

if (isTableQuery(this.config)) {
const { table } = this.config;
const { table, consistentRead } = this.config;
const keyCondition = this.buildKeyConditionForTable(this.config);

@@ -125,2 +125,3 @@ const { expression, attributeNames, attributeValues } = this.build();

TableName: table.tableName,
ConsistentRead: consistentRead,
KeyConditionExpression: keyCondition,

@@ -136,3 +137,3 @@ ExpressionAttributeNames: attributeNames,

else {
const { table } = this.config;
const { table, consistentRead } = this.config;
const keyCondition = this.buildKeyConditionForGSI(this.config);

@@ -143,2 +144,3 @@ const { expression, attributeNames, attributeValues } = this.build();

TableName: table.tableName,
ConsistentRead: consistentRead,
IndexName: this.config.gsiName,

@@ -145,0 +147,0 @@ KeyConditionExpression: keyCondition,

{
"name": "@ginger.io/beyonce",
"version": "0.0.33",
"version": "0.0.34",
"description": "Type-safe DynamoDB query builder for TypeScript. Designed with single-table architecture in mind.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -23,2 +23,10 @@ import { JayZ } from "@ginger.io/jay-z"

export type GetOptions = {
consistentRead?: boolean
}
export type QueryOptions = {
consistentRead?: boolean
}
/** A thin wrapper around the DynamoDB sdk client that

@@ -41,3 +49,4 @@ * does auto mapping between JSON <=> DynamoDB Items

async get<T extends TaggedModel>(
key: PartitionAndSortKey<T>
key: PartitionAndSortKey<T>,
options: GetOptions = {}
): Promise<T | undefined> {

@@ -47,2 +56,3 @@ const { Item: item } = await this.client

TableName: this.table.tableName,
ConsistentRead: options.consistentRead,
Key: {

@@ -115,3 +125,4 @@ [this.table.partitionKeyName]: key.partitionKey,

query<T extends TaggedModel>(
key: PartitionKey<T> | PartitionKeyAndSortKeyPrefix<T>
key: PartitionKey<T> | PartitionKeyAndSortKeyPrefix<T>,
options: QueryOptions = {}
): QueryBuilder<T> {

@@ -124,2 +135,3 @@ const { table, jayz } = this

jayz: jayz,
consistentRead: options.consistentRead,
})

@@ -130,3 +142,4 @@ }

gsiName: string,
gsiKey: PartitionKey<T>
gsiKey: PartitionKey<T>,
options: QueryOptions = {}
): QueryBuilder<T> {

@@ -140,2 +153,3 @@ const { table, jayz } = this

jayz,
consistentRead: options.consistentRead,
})

@@ -142,0 +156,0 @@ }

@@ -15,2 +15,3 @@ import { JayZ } from "@ginger.io/jay-z"

jayz?: JayZ
consistentRead?: boolean
}

@@ -24,2 +25,3 @@

jayz?: JayZ
consistentRead?: boolean
}

@@ -29,3 +31,3 @@

export type QueryOptions = {
export type IteratorOptions = {
cursor?: Cursor

@@ -73,3 +75,3 @@ pageSize?: number

async *iterator(options: QueryOptions = {}): PaginatedQueryResults<T> {
async *iterator(options: IteratorOptions = {}): PaginatedQueryResults<T> {
for await (const response of this.executeQuery(options)) {

@@ -89,3 +91,3 @@ yield {

private async *executeQuery(
options: QueryOptions = {}
options: IteratorOptions = {}
): AsyncGenerator<RawQueryResults<T>, RawQueryResults<T>> {

@@ -126,6 +128,6 @@ const { db } = this.config

private buildQuery(
options: QueryOptions
options: IteratorOptions
): DynamoDB.DocumentClient.QueryInput {
if (isTableQuery(this.config)) {
const { table } = this.config
const { table, consistentRead } = this.config
const keyCondition = this.buildKeyConditionForTable(this.config)

@@ -137,2 +139,3 @@ const { expression, attributeNames, attributeValues } = this.build()

TableName: table.tableName,
ConsistentRead: consistentRead,
KeyConditionExpression: keyCondition,

@@ -147,3 +150,3 @@ ExpressionAttributeNames: attributeNames,

} else {
const { table } = this.config
const { table, consistentRead } = this.config
const keyCondition = this.buildKeyConditionForGSI(this.config)

@@ -155,2 +158,3 @@ const { expression, attributeNames, attributeValues } = this.build()

TableName: table.tableName,
ConsistentRead: consistentRead,
IndexName: this.config.gsiName,

@@ -157,0 +161,0 @@ KeyConditionExpression: keyCondition,

@@ -14,2 +14,5 @@ import { FixedDataKeyProvider, JayZ } from "@ginger.io/jay-z"

import { setup } from "./util"
import { Beyonce } from "../../main/dynamo/Beyonce"
import { table } from "./models"
import { DynamoDB } from "aws-sdk"

@@ -22,2 +25,29 @@ describe("Beyonce", () => {

it("should support a consistentRead option on get", async () => {
await setup()
const [musician, _, __] = aMusicianWithTwoSongs()
const mockGet = jest.fn(() => ({
promise: () =>
Promise.resolve({
Item: musician,
}),
}))
const db = new Beyonce(table, new DynamoDB({ region: "us-west-2" }))
;(db as any).client.get = mockGet
await db.get(MusicianModel.key({ id: musician.id }), {
consistentRead: true,
})
expect(mockGet).toHaveBeenCalledWith({
TableName: table.tableName,
Key: {
pk: "musician-1",
sk: "musician-1",
},
ConsistentRead: true,
})
})
it("should put and delete an item using pk + sk", async () => {

@@ -35,2 +65,15 @@ await testPutAndDeleteItem()

it("should set consistent read on queries", async () => {
const db = await setup()
const query = await (db as any)
.query(MusicianModel.partitionKey({ id: "musician-1" }), {
consistentRead: true,
})
.buildQuery({})
expect(query).toMatchObject({
ConsistentRead: true,
})
})
it("should query for only single type of model", async () => {

@@ -37,0 +80,0 @@ await testQueryForSingleTypeOfModel()

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc