Socket
Socket
Sign inDemoInstall

tsynamo

Package Overview
Dependencies
146
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.0.5

92

dist/index.d.ts

@@ -1,2 +0,2 @@

import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
import { QueryCommand, GetCommand, DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';

@@ -80,11 +80,19 @@ type AttributesNode = {

} ? Omit<T, "_SK"> : T;
/**
* Returns a subset of a table's properties.
*/
type SelectAttributes<Table, Attributes extends ReadonlyArray<keyof Table>> = {
[A in Attributes[number]]: Table[A];
};
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type RecursiveSelectAttributes<Table, Properties> = Properties extends [
infer First,
...infer Rest
] ? First extends keyof Table ? {
[key in First]: RecursiveSelectAttributes<Table[First], Rest>;
} : [
First,
Table
] extends [`${number}`, any[]] ? RecursiveSelectAttributes<As<Table, any[]>[number], Rest>[] : never : Table;
type SelectAttributes<Table, Attributes extends ReadonlyArray<string>> = IntersectionToSingleObject<UnionToIntersection<RecursiveSelectAttributes<Table, ParsePath<Attributes[number]>>>>;
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends object ? DeepPartial<T[P]> : T[P];
};
type IntersectionToSingleObject<T> = T extends infer U ? {
[K in keyof U]: U[K];
} : never;
type GetFromPath<Obj, Path> = RecursiveGet<Obj, ParsePath<Path>>;

@@ -107,22 +115,13 @@ type ParsePath<Path, Properties extends string[] = [], CurrentProp extends string = ""> = Path extends `${infer First}${infer Rest}` ? First extends "." | "[" | "]" ? ParsePath<Rest, [

type ObjectKeyPaths<T> = T extends Record<PropertyKey, unknown> ? keyof T extends infer Key ? Key extends string | number ? T[Key] extends Record<PropertyKey, unknown> ? `${Key}.${ObjectKeyPaths<T[Key]>}` : Key : never : never : never;
type IsTuple<T> = T extends [any, ...any] ? true : false;
/**
* Generate union from 0 to N
* RangeToN<3> => 0 | 1 | 2 | 3
*/
type RangeToN<N extends number, Result extends any[] = []> = Result["length"] extends N ? Result[number] : RangeToN<N, [...Result, Result["length"]]>;
type ObjectFullPaths<T> = T extends Record<PropertyKey, unknown> ? keyof T extends infer Key ? Key extends string | number ? T[Key] extends Record<PropertyKey, unknown> ? // If it's an object, concatenate the key and rest of the path recursively
`${Key}` | `${Key}.${ObjectFullPaths<T[Key]>}` : T[Key] extends (infer A)[] ? IsTuple<T[Key]> extends true ? `${Key}` | `${Key}${ObjectFullPaths<{
[SpecificKey in RangeToN<T[Key]["length"]> as `[${SpecificKey}]`]: T[Key][SpecificKey];
}>}` : `${Key}` | `${Key}[${number}]` | `${Key}[${number}].${ObjectFullPaths<A[][number]>}` : `${Key}` : never : never : never;
interface GetQueryBuilderInterface<DDB, Table extends keyof DDB, O> {
keys<Keys extends PickPk<DDB[Table]> & PickSkRequired<DDB[Table]>>(pk: Keys): GetQueryBuilderInterface<DDB, Table, O>;
consistentRead(enabled: boolean): GetQueryBuilderInterface<DDB, Table, O>;
attributes<A extends ReadonlyArray<keyof DDB[Table]> & string[]>(attributes: A): GetQueryBuilderInterface<DDB, Table, SelectAttributes<DDB[Table], A>>;
execute(): Promise<StripKeys<DeepPartial<O>> | undefined>;
}
declare class GetQueryBuilder<DDB, Table extends keyof DDB, O extends DDB[Table]> implements GetQueryBuilderInterface<DDB, Table, O> {
#private;
constructor(props: GetQueryBuilderProps);
keys<Keys extends PickPk<DDB[Table]> & PickSkRequired<DDB[Table]>>(keys: Keys): GetQueryBuilder<DDB, Table, O>;
consistentRead(enabled: boolean): GetQueryBuilderInterface<DDB, Table, O>;
attributes<A extends readonly (keyof DDB[Table])[] & string[]>(attributes: A): GetQueryBuilderInterface<DDB, Table, SelectAttributes<DDB[Table], A>>;
execute: () => Promise<StripKeys<DeepPartial<O>> | undefined>;
}
interface GetQueryBuilderProps {
readonly node: GetNode;
readonly ddbClient: DynamoDBDocumentClient;
}
type AttributeExistsFunctionExpression = {

@@ -214,2 +213,40 @@ readonly kind: "AttributeExistsFunctionExpression";

declare class QueryCompiler {
compile(rootNode: QueryNode): QueryCommand;
compile(rootNode: GetNode): GetCommand;
compileGetNode(getNode: GetNode): GetCommand;
compileQueryNode(queryNode: QueryNode): QueryCommand;
compileAttributeNamesNode(node?: AttributesNode): {
ProjectionExpression: string | undefined;
ExpressionAttributeNames: Record<string, string> | undefined;
};
compileAttributeName(path: string): {
expressionAttributeName: string;
attributeNameMap: Record<string, string>;
};
compileFilterExpression: (expression: FilterExpressionNode, filterExpressionAttributeValues: Map<string, unknown>, attributeNames: Map<string, string>) => string;
compileFilterExpressionJoinNodes: ({ expr }: FilterExpressionJoinTypeNode, filterExpressionAttributeValues: Map<string, unknown>, attributeNames: Map<string, string>) => string;
compileKeyConditionExpression: (keyConditions: KeyConditionNode[], keyConditionAttributeValues: Map<string, unknown>, attributeNames: Map<string, string>) => string;
}
interface GetQueryBuilderInterface<DDB, Table extends keyof DDB, O> {
keys<Keys extends PickPk<DDB[Table]> & PickSkRequired<DDB[Table]>>(pk: Keys): GetQueryBuilderInterface<DDB, Table, O>;
consistentRead(enabled: boolean): GetQueryBuilderInterface<DDB, Table, O>;
attributes<A extends readonly ObjectFullPaths<DDB[Table]>[] & string[]>(attributes: A): GetQueryBuilderInterface<DDB, Table, SelectAttributes<DDB[Table], A>>;
execute(): Promise<StripKeys<DeepPartial<O>> | undefined>;
}
declare class GetQueryBuilder<DDB, Table extends keyof DDB, O extends DDB[Table]> implements GetQueryBuilderInterface<DDB, Table, O> {
#private;
constructor(props: GetQueryBuilderProps);
keys<Keys extends PickPk<DDB[Table]> & PickSkRequired<DDB[Table]>>(keys: Keys): GetQueryBuilder<DDB, Table, O>;
consistentRead(enabled: boolean): GetQueryBuilderInterface<DDB, Table, O>;
attributes<A extends readonly ObjectFullPaths<DDB[Table]>[] & string[]>(attributes: A): GetQueryBuilderInterface<DDB, Table, SelectAttributes<DDB[Table], A>>;
execute: () => Promise<StripKeys<DeepPartial<O>> | undefined>;
}
interface GetQueryBuilderProps {
readonly node: GetNode;
readonly ddbClient: DynamoDBDocumentClient;
readonly queryCompiler: QueryCompiler;
}
interface QueryQueryBuilderInterface<DDB, Table extends keyof DDB, O> {

@@ -246,3 +283,3 @@ execute(): Promise<StripKeys<DeepPartial<O>>[] | undefined>;

consistentRead(enabled: boolean): QueryQueryBuilderInterface<DDB, Table, O>;
attributes<A extends ReadonlyArray<keyof DDB[Table]> & string[]>(attributes: A): QueryQueryBuilderInterface<DDB, Table, SelectAttributes<DDB[Table], A>>;
attributes<A extends readonly ObjectFullPaths<DDB[Table]>[] & string[]>(attributes: A): QueryQueryBuilderInterface<DDB, Table, SelectAttributes<DDB[Table], A>>;
_getNode(): QueryNode;

@@ -291,2 +328,3 @@ }

readonly ddbClient: DynamoDBDocumentClient;
readonly queryCompiler: QueryCompiler;
}

@@ -293,0 +331,0 @@

@@ -5,6 +5,6 @@ 'use strict';

var l=class s{#e;constructor(e){this.#e=e;}keys(e){return new s({...this.#e,node:{...this.#e.node,keys:{kind:"KeysNode",keys:e}}})}consistentRead(e){return new s({...this.#e,node:{...this.#e.node,consistentRead:{kind:"ConsistentReadNode",enabled:e}}})}attributes(e){return new s({...this.#e,node:{...this.#e.node,attributes:{kind:"AttributesNode",attributes:e}}})}execute=async()=>{let e=new libDynamodb.GetCommand({TableName:this.#e.node.table?.table,Key:this.#e.node.keys?.keys,ConsistentRead:this.#e.node.consistentRead?.enabled,AttributesToGet:this.#e.node.attributes?.attributes});return (await this.#e.ddbClient.send(e)).Item??void 0}};var a=class s{#e;constructor(e){this.#e=e;}keyCondition(...e){if(e[1]==="begins_with"){let[r,t,n]=e;return new s({...this.#e,node:{...this.#e.node,keyConditions:this.#e.node.keyConditions.concat({kind:"KeyConditionNode",operation:{kind:"BeginsWithFunctionExpression",key:r,substr:n}})}})}else if(e[1]==="BETWEEN"){let[r,t,n,i]=e;return new s({...this.#e,node:{...this.#e.node,keyConditions:this.#e.node.keyConditions.concat({kind:"KeyConditionNode",operation:{kind:"BetweenConditionExpression",key:r,left:n,right:i}})}})}else {let[r,t,n]=e;return new s({...this.#e,node:{...this.#e.node,keyConditions:this.#e.node.keyConditions.concat({kind:"KeyConditionNode",operation:{kind:"KeyConditionComparatorExpression",operation:t,key:r,value:n}})}})}}_filterExpression(e,...r){if(r[1]==="begins_with"){let[t,n,i]=r;return new s({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat({kind:"FilterExpressionJoinTypeNode",expr:{kind:"BeginsWithFunctionExpression",key:t,substr:i},joinType:e})}}})}else if(r[1]==="attribute_exists"||r[1]==="attribute_not_exists"){let[t,n]=r,i;return n==="attribute_exists"?i={kind:"AttributeExistsFunctionExpression",key:t}:i={kind:"AttributeNotExistsFunctionExpression",key:t},new s({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat({kind:"FilterExpressionJoinTypeNode",expr:i,joinType:e})}}})}else if(r[1]==="BETWEEN"){let[t,n,i,o]=r;return new s({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat({kind:"FilterExpressionJoinTypeNode",expr:{kind:"BetweenConditionExpression",key:t,left:i,right:o},joinType:e})}}})}else if(typeof r[0]!="function"&&r[0]!=="NOT"&&typeof r[1]!="function"&&r[1]!==void 0&&r[2]!==void 0){let[t,n,i]=r;return new s({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat({kind:"FilterExpressionJoinTypeNode",joinType:e,expr:{kind:"FilterExpressionComparatorExpressions",key:t,operation:n,value:i}})}}})}else if(typeof r[0]=="function"||typeof r[1]=="function"){let t;if(typeof r[0]=="function"?t=r[0]:typeof r[1]=="function"&&(t=r[1]),!t)throw new Error("Could not find builder");let n=new s({...this.#e,node:{...this.#e.node,filterExpression:{expressions:[],kind:"FilterExpressionNode"}}}),i=t(n),{filterExpression:o}=i._getNode(),u={kind:"FilterExpressionJoinTypeNode",expr:o,joinType:e};return r[0]==="NOT"&&(u={...u,expr:{kind:"FilterExpressionNotExpression",expr:o}}),new s({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat(u)}}})}throw new Error("Invalid arguments given to filterExpression")}filterExpression(...e){return this._filterExpression("AND",...e)}orFilterExpression(...e){return this._filterExpression("OR",...e)}limit(e){return new s({...this.#e,node:{...this.#e.node,limit:{kind:"LimitNode",limit:e}}})}_getNode(){return this.#e.node}scanIndexForward(e){return new s({...this.#e,node:{...this.#e.node,scanIndexForward:{kind:"ScanIndexForwardNode",enabled:e}}})}consistentRead(e){return new s({...this.#e,node:{...this.#e.node,consistentRead:{kind:"ConsistentReadNode",enabled:e}}})}attributes(e){return new s({...this.#e,node:{...this.#e.node,attributes:{kind:"AttributesNode",attributes:e}}})}compileFilterExpression=(e,r)=>{let t="";return e.expressions.forEach((n,i)=>{i!==0&&(t+=` ${n.joinType} `),t+=this.compileFilterExpressionJoinNodes(n,r);}),t};compileFilterExpressionJoinNodes=({expr:e},r)=>{let t="",i=`:filterExpressionValue${r.size}`;switch(e.kind){case"FilterExpressionNode":{t+="(",t+=this.compileFilterExpression(e,r),t+=")";break}case"FilterExpressionComparatorExpressions":{t+=`${e.key} ${e.operation} ${i}`,r.set(i,e.value);break}case"FilterExpressionNotExpression":{t+="NOT (",t+=this.compileFilterExpression(e.expr,r),t+=")";break}case"BetweenConditionExpression":{t+=`${e.key} BETWEEN ${i}left AND ${i}right`,r.set(`${i}left`,e.left),r.set(`${i}right`,e.right);break}case"AttributeExistsFunctionExpression":{t+=`attribute_exists(${e.key})`;break}case"AttributeNotExistsFunctionExpression":{t+=`attribute_not_exists(${e.key})`;break}case"BeginsWithFunctionExpression":t+=`begins_with(${e.key}, ${i})`,r.set(i,e.substr);}return t};compileKeyConditionExpression=e=>{let r="";return this.#e.node.keyConditions.forEach((t,n)=>{n!==0&&(r+=" AND ");let i=`:keyConditionValue${n}`;t.operation.kind==="KeyConditionComparatorExpression"?(r+=`${t.operation.key} ${t.operation.operation} ${i}`,e.set(i,t.operation.value)):t.operation.kind==="BetweenConditionExpression"?(r+=`${t.operation.key} BETWEEN ${i}left AND ${i}right`,e.set(`${i}left`,t.operation.left),e.set(`${i}right`,t.operation.right)):t.operation.kind==="BeginsWithFunctionExpression"&&(r+=`begins_with(${t.operation.key}, ${i})`,e.set(i,t.operation.substr));}),r};execute=async()=>{let e=new Map,r=new Map,t=this.compileKeyConditionExpression(e),n=this.compileFilterExpression(this.#e.node.filterExpression,r),i=new libDynamodb.QueryCommand({TableName:this.#e.node.table.table,KeyConditionExpression:t,FilterExpression:n||void 0,Limit:this.#e.node.limit?.limit,ExpressionAttributeValues:{...Object.fromEntries(e),...Object.fromEntries(r)},ScanIndexForward:this.#e.node.scanIndexForward?.enabled,ConsistentRead:this.#e.node.consistentRead?.enabled});return (await this.#e.ddbClient.send(i)).Items??void 0}};var y=class{#e;constructor(e){this.#e=e;}getItemFrom(e){return new l({node:{kind:"GetNode",table:{kind:"TableNode",table:e}},ddbClient:this.#e.ddbClient})}query(e){return new a({node:{kind:"QueryNode",table:{kind:"TableNode",table:e},keyConditions:[],filterExpression:{kind:"FilterExpressionNode",expressions:[]}},ddbClient:this.#e.ddbClient})}};var d=class extends y{constructor(e){super(e);}};
var p=(o,e)=>{Object.defineProperties(o.prototype,{then:{enumerable:!1,value:()=>{throw new Error(e)}}});};var y=class o{#e;constructor(e){this.#e=e;}keys(e){return new o({...this.#e,node:{...this.#e.node,keys:{kind:"KeysNode",keys:e}}})}consistentRead(e){return new o({...this.#e,node:{...this.#e.node,consistentRead:{kind:"ConsistentReadNode",enabled:e}}})}attributes(e){return new o({...this.#e,node:{...this.#e.node,attributes:{kind:"AttributesNode",attributes:e}}})}execute=async()=>{let e=this.#e.queryCompiler.compile(this.#e.node);return (await this.#e.ddbClient.send(e)).Item??void 0}};p(y,"Don't await GetQueryBuilder instances directly. To execute the query you need to call the `execute` method");var d=class o{#e;constructor(e){this.#e=e;}keyCondition(...e){if(e[1]==="begins_with"){let[t,n,r]=e;return new o({...this.#e,node:{...this.#e.node,keyConditions:this.#e.node.keyConditions.concat({kind:"KeyConditionNode",operation:{kind:"BeginsWithFunctionExpression",key:t,substr:r}})}})}else if(e[1]==="BETWEEN"){let[t,n,r,i]=e;return new o({...this.#e,node:{...this.#e.node,keyConditions:this.#e.node.keyConditions.concat({kind:"KeyConditionNode",operation:{kind:"BetweenConditionExpression",key:t,left:r,right:i}})}})}else {let[t,n,r]=e;return new o({...this.#e,node:{...this.#e.node,keyConditions:this.#e.node.keyConditions.concat({kind:"KeyConditionNode",operation:{kind:"KeyConditionComparatorExpression",operation:n,key:t,value:r}})}})}}_filterExpression(e,...t){if(t[1]==="begins_with"){let[n,r,i]=t;return new o({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat({kind:"FilterExpressionJoinTypeNode",expr:{kind:"BeginsWithFunctionExpression",key:n,substr:i},joinType:e})}}})}else if(t[1]==="attribute_exists"||t[1]==="attribute_not_exists"){let[n,r]=t,i;return r==="attribute_exists"?i={kind:"AttributeExistsFunctionExpression",key:n}:i={kind:"AttributeNotExistsFunctionExpression",key:n},new o({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat({kind:"FilterExpressionJoinTypeNode",expr:i,joinType:e})}}})}else if(t[1]==="BETWEEN"){let[n,r,i,s]=t;return new o({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat({kind:"FilterExpressionJoinTypeNode",expr:{kind:"BetweenConditionExpression",key:n,left:i,right:s},joinType:e})}}})}else if(typeof t[0]!="function"&&t[0]!=="NOT"&&typeof t[1]!="function"&&t[1]!==void 0&&t[2]!==void 0){let[n,r,i]=t;return new o({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat({kind:"FilterExpressionJoinTypeNode",joinType:e,expr:{kind:"FilterExpressionComparatorExpressions",key:n,operation:r,value:i}})}}})}else if(typeof t[0]=="function"||typeof t[1]=="function"){let n;if(typeof t[0]=="function"?n=t[0]:typeof t[1]=="function"&&(n=t[1]),!n)throw new Error("Could not find builder");let r=new o({...this.#e,node:{...this.#e.node,filterExpression:{expressions:[],kind:"FilterExpressionNode"}}}),i=n(r),{filterExpression:s}=i._getNode(),l={kind:"FilterExpressionJoinTypeNode",expr:s,joinType:e};return t[0]==="NOT"&&(l={...l,expr:{kind:"FilterExpressionNotExpression",expr:s}}),new o({...this.#e,node:{...this.#e.node,filterExpression:{...this.#e.node.filterExpression,expressions:this.#e.node.filterExpression.expressions.concat(l)}}})}throw new Error("Invalid arguments given to filterExpression")}filterExpression(...e){return this._filterExpression("AND",...e)}orFilterExpression(...e){return this._filterExpression("OR",...e)}limit(e){return new o({...this.#e,node:{...this.#e.node,limit:{kind:"LimitNode",limit:e}}})}_getNode(){return this.#e.node}scanIndexForward(e){return new o({...this.#e,node:{...this.#e.node,scanIndexForward:{kind:"ScanIndexForwardNode",enabled:e}}})}consistentRead(e){return new o({...this.#e,node:{...this.#e.node,consistentRead:{kind:"ConsistentReadNode",enabled:e}}})}attributes(e){return new o({...this.#e,node:{...this.#e.node,attributes:{kind:"AttributesNode",attributes:e}}})}execute=async()=>{let e=this.#e.queryCompiler.compile(this.#e.node);return (await this.#e.ddbClient.send(e)).Items??void 0}};p(d,"Don't await QueryQueryBuilder instances directly. To execute the query you need to call the `execute` method");var D=class{#e;constructor(e){this.#e=e;}getItemFrom(e){return new y({node:{kind:"GetNode",table:{kind:"TableNode",table:e}},ddbClient:this.#e.ddbClient,queryCompiler:this.#e.queryCompiler})}query(e){return new d({node:{kind:"QueryNode",table:{kind:"TableNode",table:e},keyConditions:[],filterExpression:{kind:"FilterExpressionNode",expressions:[]}},ddbClient:this.#e.ddbClient,queryCompiler:this.#e.queryCompiler})}};var Q=/\[\d+\]/g,b=o=>o.split(".").map(e=>`#${e}`).join("."),x=o=>o.replaceAll(Q,"").split(".").map(e=>[`#${e}`,e]);function B(o,e){for(let t in e)o.set(t,e[t]);}var c=class{compile(e){switch(e.kind){case"GetNode":return this.compileGetNode(e);case"QueryNode":return this.compileQueryNode(e)}}compileGetNode(e){let{table:t,keys:n,consistentRead:r,attributes:i}=e,{ProjectionExpression:s,ExpressionAttributeNames:l}=this.compileAttributeNamesNode(i);return new libDynamodb.GetCommand({TableName:t.table,Key:n?.keys,ConsistentRead:r?.enabled,ProjectionExpression:s,ExpressionAttributeNames:l})}compileQueryNode(e){let{table:t,filterExpression:n,keyConditions:r,limit:i,scanIndexForward:s,consistentRead:l,attributes:u}=e,a=new Map,f=new Map,m=new Map,h=this.compileKeyConditionExpression(r,f,a),O=this.compileFilterExpression(n,m,a),{ProjectionExpression:T,ExpressionAttributeNames:K}=this.compileAttributeNamesNode(u);return new libDynamodb.QueryCommand({TableName:t.table,KeyConditionExpression:h,FilterExpression:O||void 0,Limit:i?.limit,ExpressionAttributeValues:{...Object.fromEntries(f),...Object.fromEntries(m)},ScanIndexForward:s?.enabled,ConsistentRead:l?.enabled,ProjectionExpression:T,ExpressionAttributeNames:a.size>0?{...Object.fromEntries(a),...K}:void 0})}compileAttributeNamesNode(e){let t=e?.attributes.map(r=>b(r)).join(", "),n=e?.attributes.map(r=>x(r)).reduce((r,i)=>(i.forEach(([s,l])=>{r[s]=l;}),r),{});return {ProjectionExpression:t,ExpressionAttributeNames:n}}compileAttributeName(e){let t=b(e),n=x(e).reduce((r,[i,s])=>(r[i]=s,r),{});return {expressionAttributeName:t,attributeNameMap:n}}compileFilterExpression=(e,t,n)=>{let r="";return e.expressions.forEach((i,s)=>{s!==0&&(r+=` ${i.joinType} `),r+=this.compileFilterExpressionJoinNodes(i,t,n);}),r};compileFilterExpressionJoinNodes=({expr:e},t,n)=>{let r="",s=`:filterExpressionValue${t.size}`,l;if("key"in e){let{expressionAttributeName:u,attributeNameMap:a}=this.compileAttributeName(e.key);l=u,B(n,a);}switch(e.kind){case"FilterExpressionNode":{r+="(",r+=this.compileFilterExpression(e,t,n),r+=")";break}case"FilterExpressionComparatorExpressions":{r+=`${l} ${e.operation} ${s}`,t.set(s,e.value);break}case"FilterExpressionNotExpression":{r+="NOT (",r+=this.compileFilterExpression(e.expr,t,n),r+=")";break}case"BetweenConditionExpression":{r+=`${l} BETWEEN ${s}left AND ${s}right`,t.set(`${s}left`,e.left),t.set(`${s}right`,e.right);break}case"AttributeExistsFunctionExpression":{r+=`attribute_exists(${l})`;break}case"AttributeNotExistsFunctionExpression":{r+=`attribute_not_exists(${l})`;break}case"BeginsWithFunctionExpression":{r+=`begins_with(${l}, ${s})`,t.set(s,e.substr);break}}return r};compileKeyConditionExpression=(e,t,n)=>{let r="";return e.forEach((i,s)=>{s!==0&&(r+=" AND ");let{expressionAttributeName:l,attributeNameMap:u}=this.compileAttributeName(i.operation.key),a=`:keyConditionValue${s}`;i.operation.kind==="KeyConditionComparatorExpression"?(r+=`${l} ${i.operation.operation} ${a}`,t.set(a,i.operation.value)):i.operation.kind==="BetweenConditionExpression"?(r+=`${l} BETWEEN ${a}left AND ${a}right`,t.set(`${a}left`,i.operation.left),t.set(`${a}right`,i.operation.right)):i.operation.kind==="BeginsWithFunctionExpression"&&(r+=`begins_with(${l}, ${a})`,t.set(a,i.operation.substr)),B(n,u);}),r}};var E=class extends D{constructor(e){let t=new c;super({...e,queryCompiler:t});}};
exports.Tsynamo = d;
exports.Tsynamo = E;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map
{
"name": "tsynamo",
"author": "woltsu",
"version": "0.0.4",
"version": "0.0.5",
"description": "Typed query builder for DynamoDB",

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

@@ -8,3 +8,4 @@ # Tsynamo

> [!NOTE]
> Currently this is a POC and a WIP, and only supports the basic get item query.
> Currently this is a POC and a WIP. Currently, `get-item` and `query` operations are
> supported, but I am planning to add support for the rest of the operations too.

@@ -27,3 +28,3 @@ ![](https://github.com/woltsu/tsynamo/blob/main/assets/demo.gif)

First, you need to define the types for your DynamoDB tables:
1. Define the types for your DynamoDB tables:

@@ -43,5 +44,5 @@ ```ts

> Notice that you can have multiple tables in the DDB schema. You can also have nested attributes in the table.
> Notice that you can have multiple tables in the DDB schema. Nested attributes are supported too.
Then, you need to create the DynamoDB Document Client:
2. Create a DynamoDB document client:

@@ -61,3 +62,3 @@ ```ts

Finally, create a Tsynamo client with the defined DynamoDB types and client:
3. Create a Tsynamo client with the defined DynamoDB types and client:

@@ -154,2 +155,17 @@ ```ts

### NOT filter expression
```ts
await tsynamoClient
.query("UserEvents")
.keyCondition("userId", "=", "123")
.filterExpression("NOT", (qb) =>
qb.filterExpression("eventType", "=", "LOG_IN")
)
.execute();
```
> This would compile as the following FilterExpression:
> `NOT eventType = "LOG_IN"`, i.e. return all events whose types is not "LOG_IN"
## Delete item

@@ -170,1 +186,8 @@

WIP
# Contributors
<p>
<a href="https://github.com/woltsu/tsynamo/graphs/contributors">
<img src="https://contrib.rocks/image?repo=woltsu/tsynamo" />
</a>
</p>

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc