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

@ginger.io/beyonce

Package Overview
Dependencies
Maintainers
25
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.56 to 0.0.57

dist/dynamo/iterators/pagedIterator.d.ts

27

dist/dynamo/Beyonce.d.ts

@@ -5,20 +5,20 @@ import { JayZ } from "@ginger.io/jay-z";

import { QueryBuilder } from "./QueryBuilder";
import { ScanBuilder, ParallelScanConfig } from "./ScanBuilder";
import { ParallelScanConfig, ScanBuilder } from "./ScanBuilder";
import { Table } from "./Table";
import { ExtractKeyType, GroupedModels, TaggedModel } from "./types";
export declare type Options = {
export interface Options {
jayz?: JayZ;
xRayTracingEnabled?: boolean;
consistentReads?: boolean;
};
export declare type GetOptions = {
}
export interface GetOptions {
consistentRead?: boolean;
};
export declare type QueryOptions = {
}
export interface QueryOptions {
consistentRead?: boolean;
};
export declare type ScanOptions = {
}
export interface ScanOptions {
consistentRead?: boolean;
parallel?: ParallelScanConfig;
};
}
/** A thin wrapper around the DynamoDB sdk client that

@@ -52,2 +52,4 @@ * does auto mapping between JSON <=> DynamoDB Items

/** Write multiple items into Dynamo using a transaction.
*
* @deprecated -- use executeTransaction
*/

@@ -57,4 +59,11 @@ batchPutWithTransaction<T extends TaggedModel>(params: {

}): Promise<void>;
/** Perform N Dynamo operations in an atomic transaction */
executeTransaction<T extends TaggedModel>(params: {
putItems?: T[];
deleteItems?: PartitionAndSortKey<T>[];
}): Promise<void>;
private toTransactPut;
private toTransactDelete;
private maybeEncryptItem;
}
//# sourceMappingURL=Beyonce.d.ts.map

@@ -192,2 +192,4 @@ "use strict";

/** Write multiple items into Dynamo using a transaction.
*
* @deprecated -- use executeTransaction
*/

@@ -197,14 +199,38 @@ batchPutWithTransaction(params) {

const { items } = params;
const maybeEncryptedItemPromises = items.map((item) => __awaiter(this, void 0, void 0, function* () {
yield this.executeTransaction({ putItems: items });
});
}
/** Perform N Dynamo operations in an atomic transaction */
executeTransaction(params) {
return __awaiter(this, void 0, void 0, function* () {
const { putItems = [], deleteItems = [] } = params;
const requests = [];
const maybeEncryptedPutPromises = putItems.map((item) => __awaiter(this, void 0, void 0, function* () {
const maybeEncryptedItem = yield this.maybeEncryptItem(item);
return {
Put: { TableName: this.table.tableName, Item: maybeEncryptedItem }
};
requests.push(this.toTransactPut(maybeEncryptedItem));
}));
const maybeEncryptedItems = yield Promise.all(maybeEncryptedItemPromises);
yield this.client
.transactWrite({ TransactItems: maybeEncryptedItems })
.promise();
deleteItems.forEach((key) => requests.push(this.toTransactDelete(key)));
yield Promise.all(maybeEncryptedPutPromises);
yield this.client.transactWrite({ TransactItems: requests }).promise();
});
}
toTransactPut(item) {
return {
Put: {
TableName: this.table.tableName,
Item: item
}
};
}
toTransactDelete(key) {
return {
Delete: {
TableName: this.table.tableName,
Key: {
[this.table.partitionKeyName]: key.partitionKey,
[this.table.sortKeyName]: key.sortKey
}
}
};
}
maybeEncryptItem(item) {

@@ -211,0 +237,0 @@ return __awaiter(this, void 0, void 0, function* () {

import { JayZ } from "@ginger.io/jay-z";
import { DynamoDB } from "aws-sdk";
import { QueryExpressionBuilder } from "./expressions/QueryExpressionBuilder";
import { IteratorOptions, PaginatedIteratorResults } from "./iterators/types";
import { PartitionKey, PartitionKeyAndSortKeyPrefix } from "./keys";
import { IteratorOptions, PaginatedQueryResults } from "./pagedIterator";
import { Table } from "./Table";
import { GroupedModels, TaggedModel } from "./types";
declare type TableQueryConfig<T extends TaggedModel> = {
interface TableQueryConfig<T extends TaggedModel> {
db: DynamoDB.DocumentClient;

@@ -14,4 +14,4 @@ table: Table;

consistentRead?: boolean;
};
declare type GSIQueryConfig<T extends TaggedModel> = {
}
interface GSIQueryConfig<T extends TaggedModel> {
db: DynamoDB.DocumentClient;

@@ -23,3 +23,3 @@ table: Table;

consistentRead?: boolean;
};
}
/** Builds and executes parameters for a DynamoDB Query operation */

@@ -33,3 +33,3 @@ export declare class QueryBuilder<T extends TaggedModel> extends QueryExpressionBuilder<T> {

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

@@ -36,0 +36,0 @@ private buildKeyConditionForTable;

@@ -11,2 +11,3 @@ "use strict";

};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncValues = (this && this.__asyncValues) || function (o) {

@@ -19,3 +20,2 @@ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");

};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {

@@ -34,5 +34,7 @@ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");

exports.QueryBuilder = void 0;
const libsodium_wrappers_1 = require("libsodium-wrappers");
const QueryExpressionBuilder_1 = require("./expressions/QueryExpressionBuilder");
const groupModelsByType_1 = require("./groupModelsByType");
const pagedIterator_1 = require("./pagedIterator");
const pagedIterator_1 = require("./iterators/pagedIterator");
const util_1 = require("./iterators/util");
/** Builds and executes parameters for a DynamoDB Query operation */

@@ -52,4 +54,4 @@ class QueryBuilder extends QueryExpressionBuilder_1.QueryExpressionBuilder {

return __awaiter(this, void 0, void 0, function* () {
const query = this.createQueryInput({});
const iterator = pagedIterator_1.pagedIterator({}, ({ cursor, pageSize }) => (Object.assign(Object.assign({}, query), { ExclusiveStartKey: cursor, Limit: pageSize })), (query) => this.config.db.query(query).promise(), this.config.jayz);
const query = this.createQueryInput({ lastEvaluatedKey: undefined });
const iterator = pagedIterator_1.pagedIterator({ lastEvaluatedKey: undefined }, ({ lastEvaluatedKey, pageSize }) => (Object.assign(Object.assign({}, query), { ExclusiveStartKey: lastEvaluatedKey, Limit: pageSize })), (query) => this.config.db.query(query).promise(), this.config.jayz);
return pagedIterator_1.groupAllPages(iterator, this.modelTags);

@@ -61,4 +63,6 @@ });

var e_1, _a;
const query = this.createQueryInput(options);
const iterator = pagedIterator_1.pagedIterator(options, ({ cursor, pageSize }) => (Object.assign(Object.assign({}, query), { ExclusiveStartKey: cursor, Limit: pageSize })), (query) => this.config.db.query(query).promise(), this.config.jayz);
const iteratorOptions = util_1.toInternalIteratorOptions(options);
const query = this.createQueryInput(iteratorOptions);
const iterator = pagedIterator_1.pagedIterator(iteratorOptions, ({ lastEvaluatedKey, pageSize }) => (Object.assign(Object.assign({}, query), { ExclusiveStartKey: lastEvaluatedKey, Limit: pageSize })), (query) => this.config.db.query(query).promise(), this.config.jayz);
yield __await(libsodium_wrappers_1.ready);
try {

@@ -70,3 +74,3 @@ for (var iterator_2 = __asyncValues(iterator), iterator_2_1; iterator_2_1 = yield __await(iterator_2.next()), !iterator_2_1.done;) {

errors: response.errors,
cursor: response.lastEvaluatedKey
cursor: util_1.maybeSerializeCursor(response.lastEvaluatedKey)
});

@@ -102,3 +106,3 @@ }

FilterExpression: filterExp,
ExclusiveStartKey: options.cursor,
ExclusiveStartKey: options.lastEvaluatedKey,
ScanIndexForward: this.scanIndexForward,

@@ -121,3 +125,3 @@ Limit: options.pageSize

FilterExpression: filterExp,
ExclusiveStartKey: options.cursor,
ExclusiveStartKey: options.lastEvaluatedKey,
ScanIndexForward: this.scanIndexForward,

@@ -124,0 +128,0 @@ Limit: options.pageSize

import { JayZ } from "@ginger.io/jay-z";
import { DynamoDB } from "aws-sdk";
import { QueryExpressionBuilder } from "./expressions/QueryExpressionBuilder";
import { IteratorOptions, PaginatedQueryResults } from "./pagedIterator";
import { IteratorOptions, PaginatedIteratorResults } from "./iterators/types";
import { Table } from "./Table";
import { GroupedModels, TaggedModel } from "./types";
declare type ScanConfig<T extends TaggedModel> = {
interface ScanConfig<T extends TaggedModel> {
db: DynamoDB.DocumentClient;

@@ -13,7 +13,7 @@ table: Table;

parallel?: ParallelScanConfig;
};
export declare type ParallelScanConfig = {
}
export interface ParallelScanConfig {
segmentId: number;
totalSegments: number;
};
}
/** Builds and executes parameters for a DynamoDB Scan operation */

@@ -25,3 +25,3 @@ export declare class ScanBuilder<T extends TaggedModel> extends QueryExpressionBuilder<T> {

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

@@ -28,0 +28,0 @@ }

@@ -11,2 +11,3 @@ "use strict";

};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncValues = (this && this.__asyncValues) || function (o) {

@@ -19,3 +20,2 @@ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");

};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {

@@ -34,5 +34,7 @@ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");

exports.ScanBuilder = void 0;
const libsodium_wrappers_1 = require("libsodium-wrappers");
const QueryExpressionBuilder_1 = require("./expressions/QueryExpressionBuilder");
const groupModelsByType_1 = require("./groupModelsByType");
const pagedIterator_1 = require("./pagedIterator");
const pagedIterator_1 = require("./iterators/pagedIterator");
const util_1 = require("./iterators/util");
/** Builds and executes parameters for a DynamoDB Scan operation */

@@ -48,3 +50,3 @@ class ScanBuilder extends QueryExpressionBuilder_1.QueryExpressionBuilder {

const scanInput = this.createScanInput();
const iterator = pagedIterator_1.pagedIterator({}, ({ cursor, pageSize }) => (Object.assign(Object.assign({}, scanInput), { ExclusiveStartKey: cursor, Limit: pageSize })), (input) => this.config.db.scan(input).promise(), this.config.jayz);
const iterator = pagedIterator_1.pagedIterator({ lastEvaluatedKey: undefined }, ({ lastEvaluatedKey, pageSize }) => (Object.assign(Object.assign({}, scanInput), { ExclusiveStartKey: lastEvaluatedKey, Limit: pageSize })), (input) => this.config.db.scan(input).promise(), this.config.jayz);
return pagedIterator_1.groupAllPages(iterator, this.modelTags);

@@ -56,4 +58,6 @@ });

var e_1, _a;
const scanInput = this.createScanInput(options);
const iterator = pagedIterator_1.pagedIterator(options, ({ cursor, pageSize }) => (Object.assign(Object.assign({}, scanInput), { ExclusiveStartKey: cursor, Limit: pageSize })), (input) => this.config.db.scan(input).promise(), this.config.jayz);
const iteratorOptions = util_1.toInternalIteratorOptions(options);
const scanInput = this.createScanInput(iteratorOptions);
const iterator = pagedIterator_1.pagedIterator(iteratorOptions, ({ lastEvaluatedKey, pageSize }) => (Object.assign(Object.assign({}, scanInput), { ExclusiveStartKey: lastEvaluatedKey, Limit: pageSize })), (input) => this.config.db.scan(input).promise(), this.config.jayz);
yield __await(libsodium_wrappers_1.ready);
try {

@@ -65,3 +69,3 @@ for (var iterator_2 = __asyncValues(iterator), iterator_2_1; iterator_2_1 = yield __await(iterator_2.next()), !iterator_2_1.done;) {

errors: response.errors,
cursor: response.lastEvaluatedKey
cursor: util_1.maybeSerializeCursor(response.lastEvaluatedKey)
});

@@ -100,3 +104,3 @@ }

FilterExpression: filterExp,
ExclusiveStartKey: iteratorOptions === null || iteratorOptions === void 0 ? void 0 : iteratorOptions.cursor,
ExclusiveStartKey: iteratorOptions === null || iteratorOptions === void 0 ? void 0 : iteratorOptions.lastEvaluatedKey,
Limit: iteratorOptions === null || iteratorOptions === void 0 ? void 0 : iteratorOptions.pageSize,

@@ -103,0 +107,0 @@ Segment: parallel === null || parallel === void 0 ? void 0 : parallel.segmentId,

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

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

@@ -362,3 +362,3 @@ # Beyonce

```TypeScript
// Batch put several items in a transaction
// Batch put or delete several items in a transaction
const author1 = AuthorModel.create({

@@ -374,3 +374,3 @@ id: "1",

await beyonce.batchPutWithTransaction({ items: [author1, author2] })
await beyonce.executeTransaction({ putItems: [author1], deleteItems: [Author.key({ id: author2.id })] })
```

@@ -377,0 +377,0 @@

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

import { QueryBuilder } from "./QueryBuilder"
import { ScanBuilder, ParallelScanConfig } from "./ScanBuilder"
import { ParallelScanConfig, ScanBuilder } from "./ScanBuilder"
import { Table } from "./Table"

@@ -23,3 +23,3 @@ import { ExtractKeyType, GroupedModels, TaggedModel } from "./types"

export type Options = {
export interface Options {
jayz?: JayZ

@@ -30,11 +30,11 @@ xRayTracingEnabled?: boolean

export type GetOptions = {
export interface GetOptions {
consistentRead?: boolean
}
export type QueryOptions = {
export interface QueryOptions {
consistentRead?: boolean
}
export type ScanOptions = {
export interface ScanOptions {
consistentRead?: boolean

@@ -275,2 +275,4 @@ parallel?: ParallelScanConfig

/** Write multiple items into Dynamo using a transaction.
*
* @deprecated -- use executeTransaction
*/

@@ -281,15 +283,47 @@ async batchPutWithTransaction<T extends TaggedModel>(params: {

const { items } = params
const maybeEncryptedItemPromises = items.map(async (item) => {
await this.executeTransaction({ putItems: items })
}
/** Perform N Dynamo operations in an atomic transaction */
async executeTransaction<T extends TaggedModel>(params: {
putItems?: T[]
deleteItems?: PartitionAndSortKey<T>[]
}): Promise<void> {
const { putItems = [], deleteItems = [] } = params
const requests: DynamoDB.DocumentClient.TransactWriteItem[] = []
const maybeEncryptedPutPromises = putItems.map(async (item) => {
const maybeEncryptedItem = await this.maybeEncryptItem(item)
return {
Put: { TableName: this.table.tableName, Item: maybeEncryptedItem }
}
requests.push(this.toTransactPut(maybeEncryptedItem))
})
const maybeEncryptedItems = await Promise.all(maybeEncryptedItemPromises)
await this.client
.transactWrite({ TransactItems: maybeEncryptedItems })
.promise()
deleteItems.forEach((key) => requests.push(this.toTransactDelete(key)))
await Promise.all(maybeEncryptedPutPromises)
await this.client.transactWrite({ TransactItems: requests }).promise()
}
private toTransactPut<T extends TaggedModel>(
item: MaybeEncryptedItem<T>
): DynamoDB.DocumentClient.TransactWriteItem {
return {
Put: {
TableName: this.table.tableName,
Item: item
}
}
}
private toTransactDelete<T extends TaggedModel>(
key: PartitionAndSortKey<T>
): DynamoDB.DocumentClient.TransactWriteItem {
return {
Delete: {
TableName: this.table.tableName,
Key: {
[this.table.partitionKeyName]: key.partitionKey,
[this.table.sortKeyName]: key.sortKey
}
}
}
}
private async maybeEncryptItem<T extends TaggedModel>(

@@ -296,0 +330,0 @@ item: T

import { JayZ } from "@ginger.io/jay-z"
import { DynamoDB } from "aws-sdk"
import { DocumentClient } from "aws-sdk/clients/dynamodb"
import { ready } from "libsodium-wrappers"
import { QueryExpressionBuilder } from "./expressions/QueryExpressionBuilder"
import { groupModelsByType } from "./groupModelsByType"
import { PartitionKey, PartitionKeyAndSortKeyPrefix } from "./keys"
import { groupAllPages, pagedIterator } from "./iterators/pagedIterator"
import {
groupAllPages,
InternalIteratorOptions,
IteratorOptions,
pagedIterator,
PaginatedQueryResults
} from "./pagedIterator"
PaginatedIteratorResults
} from "./iterators/types"
import {
maybeSerializeCursor,
toInternalIteratorOptions
} from "./iterators/util"
import { PartitionKey, PartitionKeyAndSortKeyPrefix } from "./keys"
import { Table } from "./Table"
import { GroupedModels, TaggedModel } from "./types"
type TableQueryConfig<T extends TaggedModel> = {
interface TableQueryConfig<T extends TaggedModel> {
db: DynamoDB.DocumentClient

@@ -24,3 +29,3 @@ table: Table

type GSIQueryConfig<T extends TaggedModel> = {
interface GSIQueryConfig<T extends TaggedModel> {
db: DynamoDB.DocumentClient

@@ -51,8 +56,8 @@ table: Table

async exec(): Promise<GroupedModels<T>> {
const query = this.createQueryInput({})
const query = this.createQueryInput({ lastEvaluatedKey: undefined })
const iterator = pagedIterator<DocumentClient.QueryInput, T>(
{},
({ cursor, pageSize }) => ({
{ lastEvaluatedKey: undefined },
({ lastEvaluatedKey, pageSize }) => ({
...query,
ExclusiveStartKey: cursor,
ExclusiveStartKey: lastEvaluatedKey,
Limit: pageSize

@@ -67,9 +72,10 @@ }),

async *iterator(options: IteratorOptions = {}): PaginatedQueryResults<T> {
const query = this.createQueryInput(options)
async *iterator(options: IteratorOptions = {}): PaginatedIteratorResults<T> {
const iteratorOptions = toInternalIteratorOptions(options)
const query = this.createQueryInput(iteratorOptions)
const iterator = pagedIterator<DocumentClient.QueryInput, T>(
options,
({ cursor, pageSize }) => ({
iteratorOptions,
({ lastEvaluatedKey, pageSize }) => ({
...query,
ExclusiveStartKey: cursor,
ExclusiveStartKey: lastEvaluatedKey,
Limit: pageSize

@@ -81,2 +87,3 @@ }),

await ready
for await (const response of iterator) {

@@ -86,3 +93,3 @@ yield {

errors: response.errors,
cursor: response.lastEvaluatedKey
cursor: maybeSerializeCursor(response.lastEvaluatedKey)
}

@@ -99,3 +106,3 @@ }

private createQueryInput(
options: IteratorOptions
options: InternalIteratorOptions
): DynamoDB.DocumentClient.QueryInput {

@@ -115,3 +122,3 @@ if (isTableQuery(this.config)) {

FilterExpression: filterExp,
ExclusiveStartKey: options.cursor,
ExclusiveStartKey: options.lastEvaluatedKey,
ScanIndexForward: this.scanIndexForward,

@@ -134,3 +141,3 @@ Limit: options.pageSize

FilterExpression: filterExp,
ExclusiveStartKey: options.cursor,
ExclusiveStartKey: options.lastEvaluatedKey,
ScanIndexForward: this.scanIndexForward,

@@ -137,0 +144,0 @@ Limit: options.pageSize

import { JayZ } from "@ginger.io/jay-z"
import { DynamoDB } from "aws-sdk"
import { DocumentClient } from "aws-sdk/clients/dynamodb"
import { ready } from "libsodium-wrappers"
import { QueryExpressionBuilder } from "./expressions/QueryExpressionBuilder"
import { groupModelsByType } from "./groupModelsByType"
import { groupAllPages, pagedIterator } from "./iterators/pagedIterator"
import {
groupAllPages,
InternalIteratorOptions,
IteratorOptions,
pagedIterator,
PaginatedQueryResults
} from "./pagedIterator"
PaginatedIteratorResults
} from "./iterators/types"
import {
maybeSerializeCursor,
toInternalIteratorOptions
} from "./iterators/util"
import { Table } from "./Table"
import { GroupedModels, TaggedModel } from "./types"
type ScanConfig<T extends TaggedModel> = {
interface ScanConfig<T extends TaggedModel> {
db: DynamoDB.DocumentClient

@@ -23,3 +28,3 @@ table: Table

export type ParallelScanConfig = {
export interface ParallelScanConfig {
segmentId: number // 0-indexed -- i.e. first segment id is 0, not 1

@@ -42,6 +47,6 @@ totalSegments: number

const iterator = pagedIterator<DocumentClient.ScanInput, T>(
{},
({ cursor, pageSize }) => ({
{ lastEvaluatedKey: undefined },
({ lastEvaluatedKey, pageSize }) => ({
...scanInput,
ExclusiveStartKey: cursor,
ExclusiveStartKey: lastEvaluatedKey,
Limit: pageSize

@@ -56,9 +61,10 @@ }),

async *iterator(options: IteratorOptions = {}): PaginatedQueryResults<T> {
const scanInput = this.createScanInput(options)
async *iterator(options: IteratorOptions = {}): PaginatedIteratorResults<T> {
const iteratorOptions = toInternalIteratorOptions(options)
const scanInput = this.createScanInput(iteratorOptions)
const iterator = pagedIterator<DocumentClient.ScanInput, T>(
options,
({ cursor, pageSize }) => ({
iteratorOptions,
({ lastEvaluatedKey, pageSize }) => ({
...scanInput,
ExclusiveStartKey: cursor,
ExclusiveStartKey: lastEvaluatedKey,
Limit: pageSize

@@ -70,2 +76,3 @@ }),

await ready
for await (const response of iterator) {

@@ -75,3 +82,3 @@ yield {

errors: response.errors,
cursor: response.lastEvaluatedKey
cursor: maybeSerializeCursor(response.lastEvaluatedKey)
}

@@ -87,3 +94,3 @@ }

private createScanInput(iteratorOptions?: IteratorOptions) {
private createScanInput(iteratorOptions?: InternalIteratorOptions) {
const { table, consistentRead, parallel } = this.config

@@ -106,3 +113,3 @@ const { expression, attributeNames, attributeValues } = this.build()

FilterExpression: filterExp,
ExclusiveStartKey: iteratorOptions?.cursor,
ExclusiveStartKey: iteratorOptions?.lastEvaluatedKey,
Limit: iteratorOptions?.pageSize,

@@ -109,0 +116,0 @@ Segment: parallel?.segmentId,

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

it("should put and delete in the same transaction", async () => {
await testPutAndDeleteItemInTransaction()
})
it("should set consistent read on queries", async () => {

@@ -211,5 +215,11 @@ const db = await setup()

it("should put and delete an item using pk + sk with jayZ", async () => {
await testPutAndDeleteItem()
const jayZ = await createJayZ()
await testPutAndDeleteItem(jayZ)
})
it("should put and delete in the same transaction with jayZ", async () => {
const jayZ = await createJayZ()
await testPutAndDeleteItemInTransaction(jayZ)
})
it("should batchGet items with jayZ", async () => {

@@ -278,2 +288,21 @@ const jayZ = await createJayZ()

async function testPutAndDeleteItemInTransaction(jayZ?: JayZ) {
const db = await setup(jayZ)
const [musician, song1, song2] = aMusicianWithTwoSongs()
await db.executeTransaction({ putItems: [musician, song1] })
await db.executeTransaction({
putItems: [song2],
deleteItems: [SongModel.key({ musicianId: song1.musicianId, id: song1.id })]
})
expect(
await db.get(SongModel.key({ musicianId: song2.musicianId, id: song2.id }))
).toEqual(song2)
expect(
await db.get(SongModel.key({ musicianId: song1.musicianId, id: song1.id }))
).toEqual(undefined)
}
async function testPutAndRetrieveCompoundPartitionKey(jayZ?: JayZ) {

@@ -419,4 +448,4 @@ interface Person {

await db.batchPutWithTransaction({
items: [santana, slash, santanasSong, slashesSong]
await db.executeTransaction({
putItems: [santana, slash, santanasSong, slashesSong]
})

@@ -439,3 +468,3 @@

const [musician, song1, song2] = aMusicianWithTwoSongs()
await db.batchPutWithTransaction({ items: [musician, song1, song2] })
await db.executeTransaction({ putItems: [musician, song1, song2] })

@@ -442,0 +471,0 @@ const results = await db

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

const [musician, song1, song2] = aMusicianWithTwoSongs()
await db.batchPutWithTransaction({ items: [musician, song1, song2] })
await db.executeTransaction({ putItems: [musician, song1, song2] })

@@ -253,0 +253,0 @@ const result = await db

@@ -67,8 +67,8 @@ import { FixedDataKeyProvider, JayZ } from "@ginger.io/jay-z"

await Promise.all([
db.batchPutWithTransaction({ items: songs.slice(0, 5) }),
db.batchPutWithTransaction({ items: songs.slice(5, 10) }),
db.batchPutWithTransaction({ items: songs.slice(10, 15) }),
db.batchPutWithTransaction({ items: songs.slice(15) })
db.executeTransaction({ putItems: songs.slice(0, 5) }),
db.executeTransaction({ putItems: songs.slice(5, 10) }),
db.executeTransaction({ putItems: songs.slice(10, 15) }),
db.executeTransaction({ putItems: songs.slice(15) })
])
return songs
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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