b23-lib 1.7.7 → 1.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Classes/Cart.mjs +1 -1
- package/dist/Classes/Customer.d.mts +6 -4
- package/dist/Classes/Customer.d.ts +6 -4
- package/dist/Classes/Customer.js.map +1 -1
- package/dist/Classes/Customer.mjs.map +1 -1
- package/dist/Classes/Order.mjs +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/Dynamodb/index.d.mts +3 -3
- package/dist/Dynamodb/index.d.ts +3 -3
- package/dist/Dynamodb/index.js +1 -1
- package/dist/Dynamodb/index.js.map +1 -1
- package/dist/Dynamodb/index.mjs +1 -1
- package/dist/Dynamodb/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/Classes/Cart.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a as a$1}from'../chunk-FL244D6L.mjs';import'../chunk-WU6FFDBS.mjs';import'../chunk-
|
|
1
|
+
import {a as a$1}from'../chunk-FL244D6L.mjs';import'../chunk-WU6FFDBS.mjs';import'../chunk-DKI6BDWK.mjs';import'../chunk-763MN5XV.mjs';import'../chunk-65X54TKF.mjs';import'../chunk-XZG7Y2WO.mjs';import'../chunk-DM2BJMLJ.mjs';import'../chunk-ATUUYYQT.mjs';var l=(e=>(e.ACTIVE="ACTIVE",e.FROZEN="FROZEN",e.MERGED="MERGED",e.ORDERED="ORDERED",e))(l||{}),n=class extends Error{constructor(t){super(`Line item with ID '${t}' not found in the cart.`),this.name="LineItemNotFoundError";}},c={expiresAtInSeconds:120*24*60*60},a=class extends a$1{state;expireAt;config;constructor(t,r=new Date,i=c){super(t,r),this.state=t.state,this.expireAt=t.expireAt&&typeof t.expireAt=="number"?t.expireAt:Math.floor(r.getTime()/1e3)+i.expiresAtInSeconds,this.config=i,this.updateCartTotals();}getState(){return this.state}getExpireAt(){return this.expireAt}isActive(){let t=Math.ceil(Date.now()/1e3);return this.state==="ACTIVE"&&this.expireAt>t}clearCartItems(){this.lineItems=[],this.coupons=[],this.updateCartTotals();}addLineItem(t){let r=t.getProductKey(),i=t.getVariantId(),e=this.lineItems.findIndex(s=>s.getProductKey()===r&&s.getVariantId()===i);return e>=0?this.lineItems[e].addSubItems(t.getSubItems(),!0):this.lineItems.push(t),this.updateCartTotals(),e>=0?e:this.lineItems.length-1}updateLineItem(t,r,i){let e=this.lineItems,s=e.findIndex(u=>u.getId()===t);if(s<0)throw new n(t);return e[s].addSubItems([{size:r,quantity:i}],!1),this.updateCartTotals(),s}removeLineItem(t){let i=this.lineItems.findIndex(e=>e.getId()===t);if(i<0)throw new n(t);return this.lineItems.splice(i,1),this.updateCartTotals(),i}getDetails(){return {...super.getDetails(),state:this.getState(),expireAt:this.getExpireAt()}}};export{l as CartState,c as DEFAULT_CART_CONFIG,n as LineItemNotFoundError,a as default};//# sourceMappingURL=Cart.mjs.map
|
|
2
2
|
//# sourceMappingURL=Cart.mjs.map
|
|
@@ -14,7 +14,7 @@ declare enum CustomerStatus {
|
|
|
14
14
|
type CustomerAttributes = BaseAttributes & {
|
|
15
15
|
id: string;
|
|
16
16
|
email: string;
|
|
17
|
-
phone
|
|
17
|
+
phone?: string;
|
|
18
18
|
firstName: string;
|
|
19
19
|
lastName: string;
|
|
20
20
|
isEmailVerified?: boolean;
|
|
@@ -23,7 +23,9 @@ type CustomerAttributes = BaseAttributes & {
|
|
|
23
23
|
type CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & {
|
|
24
24
|
customerStatus: CustomerStatus[];
|
|
25
25
|
};
|
|
26
|
-
type CustomerData = Required<CustomerDataWithArrayStatus
|
|
26
|
+
type CustomerData = Required<Omit<CustomerDataWithArrayStatus, 'phone'>> & {
|
|
27
|
+
phone?: string;
|
|
28
|
+
};
|
|
27
29
|
type CustomerDataWithOutId = Omit<CustomerData, 'id'>;
|
|
28
30
|
/**
|
|
29
31
|
* Represents a customer entity, managing customer information and status.
|
|
@@ -31,7 +33,7 @@ type CustomerDataWithOutId = Omit<CustomerData, 'id'>;
|
|
|
31
33
|
declare class CustomerModel extends BaseModel {
|
|
32
34
|
protected id: string;
|
|
33
35
|
protected email: string;
|
|
34
|
-
protected phone
|
|
36
|
+
protected phone?: string;
|
|
35
37
|
protected firstName: string;
|
|
36
38
|
protected lastName: string;
|
|
37
39
|
protected isEmailVerified: boolean;
|
|
@@ -65,7 +67,7 @@ declare class CustomerModel extends BaseModel {
|
|
|
65
67
|
* Gets the phone number of the customer.
|
|
66
68
|
* @returns The phone number.
|
|
67
69
|
*/
|
|
68
|
-
getPhone(): string;
|
|
70
|
+
getPhone(): string | undefined;
|
|
69
71
|
/**
|
|
70
72
|
* Gets the first name of the customer.
|
|
71
73
|
* @returns The first name.
|
|
@@ -14,7 +14,7 @@ declare enum CustomerStatus {
|
|
|
14
14
|
type CustomerAttributes = BaseAttributes & {
|
|
15
15
|
id: string;
|
|
16
16
|
email: string;
|
|
17
|
-
phone
|
|
17
|
+
phone?: string;
|
|
18
18
|
firstName: string;
|
|
19
19
|
lastName: string;
|
|
20
20
|
isEmailVerified?: boolean;
|
|
@@ -23,7 +23,9 @@ type CustomerAttributes = BaseAttributes & {
|
|
|
23
23
|
type CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & {
|
|
24
24
|
customerStatus: CustomerStatus[];
|
|
25
25
|
};
|
|
26
|
-
type CustomerData = Required<CustomerDataWithArrayStatus
|
|
26
|
+
type CustomerData = Required<Omit<CustomerDataWithArrayStatus, 'phone'>> & {
|
|
27
|
+
phone?: string;
|
|
28
|
+
};
|
|
27
29
|
type CustomerDataWithOutId = Omit<CustomerData, 'id'>;
|
|
28
30
|
/**
|
|
29
31
|
* Represents a customer entity, managing customer information and status.
|
|
@@ -31,7 +33,7 @@ type CustomerDataWithOutId = Omit<CustomerData, 'id'>;
|
|
|
31
33
|
declare class CustomerModel extends BaseModel {
|
|
32
34
|
protected id: string;
|
|
33
35
|
protected email: string;
|
|
34
|
-
protected phone
|
|
36
|
+
protected phone?: string;
|
|
35
37
|
protected firstName: string;
|
|
36
38
|
protected lastName: string;
|
|
37
39
|
protected isEmailVerified: boolean;
|
|
@@ -65,7 +67,7 @@ declare class CustomerModel extends BaseModel {
|
|
|
65
67
|
* Gets the phone number of the customer.
|
|
66
68
|
* @returns The phone number.
|
|
67
69
|
*/
|
|
68
|
-
getPhone(): string;
|
|
70
|
+
getPhone(): string | undefined;
|
|
69
71
|
/**
|
|
70
72
|
* Gets the first name of the customer.
|
|
71
73
|
* @returns The first name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Customer.ts"],"names":["BaseModel","data","date","id","authType","requestId","lambdaName","fieldName","value","CustomerStatus","CustomerModel","withId","customerStatus"],"mappings":"sEA4BA,IAAqBA,CAAAA,CAArB,KAA+B,CACnB,YAAA,CACA,QACA,SACA,CAAA,UAAA,CACA,WAQV,WAAYC,CAAAA,CAAAA,CAAsBC,EAAa,IAAI,IAAA,CAAQ,CACzD,IAAK,CAAA,YAAA,CAAe,CAAE,GAAGD,CAAAA,CAAK,YAAa,CAC3C,CAAA,IAAA,CAAK,QAAUA,CAAK,CAAA,OAAA,EAAW,EAC/B,IAAK,CAAA,SAAA,CAAYA,EAAK,SAAa,EAAA,CAAC,MAAM,IAAK,CAAA,KAAA,CAAMA,EAAK,SAAS,CAAC,EAElE,IAAI,IAAA,CAAKA,EAAK,SAAS,CAAA,CAAE,WAAY,EAAA,CAErCC,CAAK,CAAA,WAAA,GACP,IAAK,CAAA,UAAA,CAAaD,EAAK,UAAc,EAAA,CAAC,MAAM,IAAK,CAAA,KAAA,CAAMA,EAAK,UAAU,CAAC,EACnE,IAAI,IAAA,CAAKA,EAAK,UAAU,CAAA,CAAE,aAC1BC,CAAAA,CAAAA,CAAK,aAET,CAAA,IAAA,CAAK,WAAa,CAAE,GAAGD,EAAK,UAAW,EACzC,CAMA,U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sB,CACpB,OAAO,IAAK,CAAA,QACd,CAOA,kBAAA,EAA8B,CAC5B,OAAO,IAAA,CAAK,eACd,CAOA,iBAAA,EAAsC,CACpC,OAAO,KAAA,CAAM,KAAK,IAAK,CAAA,cAAc,CACvC,CAQA,iBAAA,CAAkBC,EAAyC,CACzD,OAAO,KAAK,cAAe,CAAA,GAAA,CAAIA,CAAc,CAC/C,CACF","file":"Customer.js","sourcesContent":["import { AuthType } from \"../Auth\";\r\nimport { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type ModifiedBy = {\r\n id?: string;\r\n authType?: string;\r\n requestId?: string;\r\n lambdaName?: string;\r\n}\r\n\r\nexport type BaseAttributes = {\r\n customFields?: CustomFields;\r\n version?: number;\r\n createdAt?: ISODateTime;\r\n modifiedAt?: ISODateTime;\r\n modifiedBy?: ModifiedBy;\r\n};\r\n\r\nexport type BaseData = Required<BaseAttributes>;\r\n\r\n/**\r\n * Provides common foundational properties and methods for other data models.\r\n * Handles tracking of custom fields, versioning, and timestamps.\r\n */\r\nexport default class BaseModel {\r\n protected customFields: CustomFields;\r\n protected version: number;\r\n protected createdAt: ISODateTime;\r\n protected modifiedAt: ISODateTime;\r\n protected modifiedBy: ModifiedBy;\r\n\r\n /**\r\n * Creates an instance of BaseModel.\r\n * Initializes common properties like timestamps, version, and custom fields.\r\n * @param data - Optional initial attributes for the base model.\r\n * @param date - Optional date object to use for default timestamps (defaults to current time).\r\n */\r\n constructor(data: BaseAttributes, date: Date = new Date()) {\r\n this.customFields = { ...data.customFields };\r\n this.version = data.version ?? 1;\r\n this.createdAt = data.createdAt && !isNaN(Date.parse(data.createdAt))\r\n ?\r\n new Date(data.createdAt).toISOString()\r\n :\r\n date.toISOString();\r\n this.modifiedAt = data.modifiedAt && !isNaN(Date.parse(data.modifiedAt))\r\n ? new Date(data.modifiedAt).toISOString()\r\n : date.toISOString();\r\n\r\n this.modifiedBy = { ...data.modifiedBy };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the base model's current state.\r\n * @returns BaseData object containing common properties.\r\n */\r\n getDetails(): BaseData {\r\n return {\r\n customFields: this.getAllCustomFields(), // Use getter to return a copy\r\n version: this.getVersion(),\r\n createdAt: this.getCreatedAt(),\r\n modifiedAt: this.getModifiedAt(),\r\n modifiedBy: this.getModifiedBy(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current version number of the model instance.\r\n * @returns The version number.\r\n */\r\n getVersion(): number {\r\n return this.version;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as an ISO 8601 string.\r\n * @returns The creation timestamp string.\r\n */\r\n getCreatedAt(): string {\r\n return this.createdAt;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as a Unix epoch time (milliseconds).\r\n * @returns The creation time in milliseconds since the epoch.\r\n */\r\n getCreatedAtTime(): number {\r\n return new Date(this.createdAt).getTime();\r\n }\r\n\r\n\r\n /**\r\n * Gets the last modification timestamp as an ISO 8601 string.\r\n * @returns The last modification timestamp string.\r\n */\r\n getModifiedAt(): string {\r\n return this.modifiedAt;\r\n }\r\n\r\n /**\r\n * Gets the last modification timestamp as a Unix epoch time (milliseconds).\r\n * @returns The last modification time in milliseconds since the epoch.\r\n */\r\n getModifiedAtTime(): number {\r\n return new Date(this.modifiedAt).getTime();\r\n }\r\n\r\n /**\r\n * Gets the identifier of the user or process that last modified the instance.\r\n * @returns\r\n */\r\n getModifiedBy(): ModifiedBy {\r\n return { ...this.modifiedBy };\r\n }\r\n\r\n /**\r\n * Sets the identifier of the user or process that last modified the instance.\r\n * @param modifiedBy - The identifier string.\r\n */\r\n setModifiedBy(id?: string, authType?: AuthType, requestId?: string, lambdaName?: string): void {\r\n this.modifiedBy = {\r\n id,\r\n authType,\r\n requestId,\r\n lambdaName,\r\n };\r\n }\r\n\r\n /**\r\n * Retrieves the value of a specific custom field.\r\n * @param fieldName - The name (key) of the custom field to retrieve.\r\n * @returns The value of the custom field, or null if the field does not exist.\r\n */\r\n getCustomField(fieldName: string): any {\r\n return this.customFields[fieldName] ?? null;\r\n }\r\n\r\n /**\r\n * Sets the value of a specific custom field.\r\n * Also updates the modification timestamp and increments the version.\r\n * @param fieldName - The name (key) of the custom field to set.\r\n * @param value - The value to assign to the custom field.\r\n */\r\n setCustomField(fieldName: string, value: any): void {\r\n this.customFields[fieldName] = value;\r\n }\r\n\r\n /**\r\n * Retrieves a shallow copy of all custom fields associated with the instance.\r\n * @returns An object containing all custom fields.\r\n */\r\n getAllCustomFields(): CustomFields {\r\n return { ...this.customFields };\r\n }\r\n}\r\n","import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\n\r\nexport enum CustomerStatus {\r\n CREATED = \"CREATED\",\r\n REGISTERED_USER = \"REGISTERED_USER\",\r\n ACTIVATED_USER = \"ACTIVATED_USER\",\r\n EMAIL_OTP = \"EMAIL_OTP\",\r\n EMAIL_PASSWORD = \"EMAIL_PASSWORD\",\r\n PHONE_OTP = \"PHONE_OTP\",\r\n}\r\n\r\nexport type CustomerAttributes = BaseAttributes & {\r\n id: string;\r\n email: string;\r\n phone: string;\r\n firstName: string;\r\n lastName: string;\r\n isEmailVerified?: boolean;\r\n customerStatus?: Set<CustomerStatus>;\r\n};\r\n\r\n\r\ntype CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & { customerStatus: CustomerStatus[]; }\r\nexport type CustomerData = Required<CustomerDataWithArrayStatus>;\r\nexport type CustomerDataWithOutId = Omit<CustomerData, 'id'>;\r\n\r\n/**\r\n * Represents a customer entity, managing customer information and status.\r\n */\r\nexport default class CustomerModel extends BaseModel {\r\n protected id: string;\r\n protected email: string;\r\n protected phone: string;\r\n protected firstName: string;\r\n protected lastName: string;\r\n protected isEmailVerified: boolean;\r\n protected customerStatus: Set<CustomerStatus>;\r\n\r\n /**\r\n * Creates an instance of CustomerModel.\r\n * Initializes customer properties and ensures the CREATED status is always present.\r\n * @param data - The initial attributes for the customer.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CustomerAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.email = data.email;\r\n this.phone = data.phone;\r\n this.firstName = data.firstName;\r\n this.lastName = data.lastName;\r\n this.isEmailVerified = data.isEmailVerified ?? false;\r\n this.customerStatus = new Set<CustomerStatus>(\r\n [...(data.customerStatus ? Array.from<CustomerStatus>(data.customerStatus) : []), CustomerStatus.CREATED]\r\n );\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the customer's current state.\r\n * Can optionally exclude the customer ID. Includes base model details.\r\n * @param withId - If true, includes the 'id' field. Defaults to false.\r\n * @returns CustomerData or CustomerDataWithOutId object suitable for serialization.\r\n */\r\n getDetails(withId?: false): CustomerDataWithOutId;\r\n getDetails(withId: true): CustomerData;\r\n getDetails(withId: boolean = false): CustomerData | CustomerDataWithOutId {\r\n return {\r\n ...super.getDetails(),\r\n ...(withId ? { id: this.getId() } : {}),\r\n email: this.getEmail(),\r\n phone: this.getPhone(),\r\n firstName: this.getFirstName(),\r\n lastName: this.getLastName(),\r\n isEmailVerified: this.getIsEmailVerified(),\r\n customerStatus: this.getCustomerStatus()\r\n };\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for the customer.\r\n * @returns The customer ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the email address of the customer.\r\n * @returns The email address.\r\n */\r\n getEmail(): string {\r\n return this.email;\r\n }\r\n\r\n /**\r\n * Gets the phone number of the customer.\r\n * @returns The phone number.\r\n */\r\n getPhone(): string {\r\n return this.phone;\r\n }\r\n\r\n\r\n /**\r\n * Gets the first name of the customer.\r\n * @returns The first name.\r\n */\r\n getFirstName(): string {\r\n return this.firstName;\r\n }\r\n\r\n\r\n /**\r\n * Gets the last name of the customer.\r\n * @returns The last name.\r\n */\r\n getLastName(): string {\r\n return this.lastName;\r\n }\r\n\r\n\r\n /**\r\n * Checks if the customer's email address has been verified.\r\n * @returns True if the email is verified, false otherwise.\r\n */\r\n getIsEmailVerified(): boolean {\r\n return this.isEmailVerified;\r\n }\r\n\r\n\r\n /**\r\n * Gets the customer's current statuses as an array.\r\n * @returns An array of CustomerStatus enum values.\r\n */\r\n getCustomerStatus(): CustomerStatus[] {\r\n return Array.from(this.customerStatus);\r\n }\r\n\r\n /**\r\n * Checks if the customer has a specific status.\r\n * Note: This method currently returns void. It should likely return boolean.\r\n * @param customerStatus - The status to check for.\r\n * @returns return boolean: true if the status exists, false otherwise.\r\n */\r\n hasCustomerStatus(customerStatus: CustomerStatus): boolean {\r\n return this.customerStatus.has(customerStatus);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/Customer.ts"],"names":["BaseModel","data","date","id","authType","requestId","lambdaName","fieldName","value","CustomerStatus","CustomerModel","withId","customerStatus"],"mappings":"sEA4BA,IAAqBA,CAAAA,CAArB,KAA+B,CACnB,YAAA,CACA,QACA,SACA,CAAA,UAAA,CACA,WAQV,WAAYC,CAAAA,CAAAA,CAAsBC,EAAa,IAAI,IAAA,CAAQ,CACzD,IAAK,CAAA,YAAA,CAAe,CAAE,GAAGD,CAAAA,CAAK,YAAa,CAC3C,CAAA,IAAA,CAAK,QAAUA,CAAK,CAAA,OAAA,EAAW,EAC/B,IAAK,CAAA,SAAA,CAAYA,EAAK,SAAa,EAAA,CAAC,MAAM,IAAK,CAAA,KAAA,CAAMA,EAAK,SAAS,CAAC,EAElE,IAAI,IAAA,CAAKA,EAAK,SAAS,CAAA,CAAE,WAAY,EAAA,CAErCC,CAAK,CAAA,WAAA,GACP,IAAK,CAAA,UAAA,CAAaD,EAAK,UAAc,EAAA,CAAC,MAAM,IAAK,CAAA,KAAA,CAAMA,EAAK,UAAU,CAAC,EACnE,IAAI,IAAA,CAAKA,EAAK,UAAU,CAAA,CAAE,aAC1BC,CAAAA,CAAAA,CAAK,aAET,CAAA,IAAA,CAAK,WAAa,CAAE,GAAGD,EAAK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,KAAK,SACd,CAOA,aAAsB,CACpB,OAAO,IAAK,CAAA,QACd,CAOA,kBAAA,EAA8B,CAC5B,OAAO,IAAA,CAAK,eACd,CAOA,iBAAA,EAAsC,CACpC,OAAO,KAAA,CAAM,KAAK,IAAK,CAAA,cAAc,CACvC,CAQA,iBAAA,CAAkBC,EAAyC,CACzD,OAAO,KAAK,cAAe,CAAA,GAAA,CAAIA,CAAc,CAC/C,CACF","file":"Customer.js","sourcesContent":["import { AuthType } from \"../Auth\";\r\nimport { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type ModifiedBy = {\r\n id?: string;\r\n authType?: string;\r\n requestId?: string;\r\n lambdaName?: string;\r\n}\r\n\r\nexport type BaseAttributes = {\r\n customFields?: CustomFields;\r\n version?: number;\r\n createdAt?: ISODateTime;\r\n modifiedAt?: ISODateTime;\r\n modifiedBy?: ModifiedBy;\r\n};\r\n\r\nexport type BaseData = Required<BaseAttributes>;\r\n\r\n/**\r\n * Provides common foundational properties and methods for other data models.\r\n * Handles tracking of custom fields, versioning, and timestamps.\r\n */\r\nexport default class BaseModel {\r\n protected customFields: CustomFields;\r\n protected version: number;\r\n protected createdAt: ISODateTime;\r\n protected modifiedAt: ISODateTime;\r\n protected modifiedBy: ModifiedBy;\r\n\r\n /**\r\n * Creates an instance of BaseModel.\r\n * Initializes common properties like timestamps, version, and custom fields.\r\n * @param data - Optional initial attributes for the base model.\r\n * @param date - Optional date object to use for default timestamps (defaults to current time).\r\n */\r\n constructor(data: BaseAttributes, date: Date = new Date()) {\r\n this.customFields = { ...data.customFields };\r\n this.version = data.version ?? 1;\r\n this.createdAt = data.createdAt && !isNaN(Date.parse(data.createdAt))\r\n ?\r\n new Date(data.createdAt).toISOString()\r\n :\r\n date.toISOString();\r\n this.modifiedAt = data.modifiedAt && !isNaN(Date.parse(data.modifiedAt))\r\n ? new Date(data.modifiedAt).toISOString()\r\n : date.toISOString();\r\n\r\n this.modifiedBy = { ...data.modifiedBy };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the base model's current state.\r\n * @returns BaseData object containing common properties.\r\n */\r\n getDetails(): BaseData {\r\n return {\r\n customFields: this.getAllCustomFields(), // Use getter to return a copy\r\n version: this.getVersion(),\r\n createdAt: this.getCreatedAt(),\r\n modifiedAt: this.getModifiedAt(),\r\n modifiedBy: this.getModifiedBy(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current version number of the model instance.\r\n * @returns The version number.\r\n */\r\n getVersion(): number {\r\n return this.version;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as an ISO 8601 string.\r\n * @returns The creation timestamp string.\r\n */\r\n getCreatedAt(): string {\r\n return this.createdAt;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as a Unix epoch time (milliseconds).\r\n * @returns The creation time in milliseconds since the epoch.\r\n */\r\n getCreatedAtTime(): number {\r\n return new Date(this.createdAt).getTime();\r\n }\r\n\r\n\r\n /**\r\n * Gets the last modification timestamp as an ISO 8601 string.\r\n * @returns The last modification timestamp string.\r\n */\r\n getModifiedAt(): string {\r\n return this.modifiedAt;\r\n }\r\n\r\n /**\r\n * Gets the last modification timestamp as a Unix epoch time (milliseconds).\r\n * @returns The last modification time in milliseconds since the epoch.\r\n */\r\n getModifiedAtTime(): number {\r\n return new Date(this.modifiedAt).getTime();\r\n }\r\n\r\n /**\r\n * Gets the identifier of the user or process that last modified the instance.\r\n * @returns\r\n */\r\n getModifiedBy(): ModifiedBy {\r\n return { ...this.modifiedBy };\r\n }\r\n\r\n /**\r\n * Sets the identifier of the user or process that last modified the instance.\r\n * @param modifiedBy - The identifier string.\r\n */\r\n setModifiedBy(id?: string, authType?: AuthType, requestId?: string, lambdaName?: string): void {\r\n this.modifiedBy = {\r\n id,\r\n authType,\r\n requestId,\r\n lambdaName,\r\n };\r\n }\r\n\r\n /**\r\n * Retrieves the value of a specific custom field.\r\n * @param fieldName - The name (key) of the custom field to retrieve.\r\n * @returns The value of the custom field, or null if the field does not exist.\r\n */\r\n getCustomField(fieldName: string): any {\r\n return this.customFields[fieldName] ?? null;\r\n }\r\n\r\n /**\r\n * Sets the value of a specific custom field.\r\n * Also updates the modification timestamp and increments the version.\r\n * @param fieldName - The name (key) of the custom field to set.\r\n * @param value - The value to assign to the custom field.\r\n */\r\n setCustomField(fieldName: string, value: any): void {\r\n this.customFields[fieldName] = value;\r\n }\r\n\r\n /**\r\n * Retrieves a shallow copy of all custom fields associated with the instance.\r\n * @returns An object containing all custom fields.\r\n */\r\n getAllCustomFields(): CustomFields {\r\n return { ...this.customFields };\r\n }\r\n}\r\n","import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\n\r\nexport enum CustomerStatus {\r\n CREATED = \"CREATED\",\r\n REGISTERED_USER = \"REGISTERED_USER\",\r\n ACTIVATED_USER = \"ACTIVATED_USER\",\r\n EMAIL_OTP = \"EMAIL_OTP\",\r\n EMAIL_PASSWORD = \"EMAIL_PASSWORD\",\r\n PHONE_OTP = \"PHONE_OTP\",\r\n}\r\n\r\nexport type CustomerAttributes = BaseAttributes & {\r\n id: string;\r\n email: string;\r\n phone?: string;\r\n firstName: string;\r\n lastName: string;\r\n isEmailVerified?: boolean;\r\n customerStatus?: Set<CustomerStatus>;\r\n};\r\n\r\n\r\ntype CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & { customerStatus: CustomerStatus[]; }\r\nexport type CustomerData = Required<Omit<CustomerDataWithArrayStatus, 'phone'>> & { phone?: string};\r\nexport type CustomerDataWithOutId = Omit<CustomerData, 'id'>;\r\n\r\n/**\r\n * Represents a customer entity, managing customer information and status.\r\n */\r\nexport default class CustomerModel extends BaseModel {\r\n protected id: string;\r\n protected email: string;\r\n protected phone?: string;\r\n protected firstName: string;\r\n protected lastName: string;\r\n protected isEmailVerified: boolean;\r\n protected customerStatus: Set<CustomerStatus>;\r\n\r\n /**\r\n * Creates an instance of CustomerModel.\r\n * Initializes customer properties and ensures the CREATED status is always present.\r\n * @param data - The initial attributes for the customer.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CustomerAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.email = data.email;\r\n this.phone = data.phone;\r\n this.firstName = data.firstName;\r\n this.lastName = data.lastName;\r\n this.isEmailVerified = data.isEmailVerified ?? false;\r\n this.customerStatus = new Set<CustomerStatus>(\r\n [...(data.customerStatus ? Array.from<CustomerStatus>(data.customerStatus) : []), CustomerStatus.CREATED]\r\n );\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the customer's current state.\r\n * Can optionally exclude the customer ID. Includes base model details.\r\n * @param withId - If true, includes the 'id' field. Defaults to false.\r\n * @returns CustomerData or CustomerDataWithOutId object suitable for serialization.\r\n */\r\n getDetails(withId?: false): CustomerDataWithOutId;\r\n getDetails(withId: true): CustomerData;\r\n getDetails(withId: boolean = false): CustomerData | CustomerDataWithOutId {\r\n return {\r\n ...super.getDetails(),\r\n ...(withId ? { id: this.getId() } : {}),\r\n email: this.getEmail(),\r\n phone: this.getPhone(),\r\n firstName: this.getFirstName(),\r\n lastName: this.getLastName(),\r\n isEmailVerified: this.getIsEmailVerified(),\r\n customerStatus: this.getCustomerStatus()\r\n };\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for the customer.\r\n * @returns The customer ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the email address of the customer.\r\n * @returns The email address.\r\n */\r\n getEmail(): string {\r\n return this.email;\r\n }\r\n\r\n /**\r\n * Gets the phone number of the customer.\r\n * @returns The phone number.\r\n */\r\n getPhone(): string | undefined {\r\n return this.phone;\r\n }\r\n\r\n\r\n /**\r\n * Gets the first name of the customer.\r\n * @returns The first name.\r\n */\r\n getFirstName(): string {\r\n return this.firstName;\r\n }\r\n\r\n\r\n /**\r\n * Gets the last name of the customer.\r\n * @returns The last name.\r\n */\r\n getLastName(): string {\r\n return this.lastName;\r\n }\r\n\r\n\r\n /**\r\n * Checks if the customer's email address has been verified.\r\n * @returns True if the email is verified, false otherwise.\r\n */\r\n getIsEmailVerified(): boolean {\r\n return this.isEmailVerified;\r\n }\r\n\r\n\r\n /**\r\n * Gets the customer's current statuses as an array.\r\n * @returns An array of CustomerStatus enum values.\r\n */\r\n getCustomerStatus(): CustomerStatus[] {\r\n return Array.from(this.customerStatus);\r\n }\r\n\r\n /**\r\n * Checks if the customer has a specific status.\r\n * Note: This method currently returns void. It should likely return boolean.\r\n * @param customerStatus - The status to check for.\r\n * @returns return boolean: true if the status exists, false otherwise.\r\n */\r\n hasCustomerStatus(customerStatus: CustomerStatus): boolean {\r\n return this.customerStatus.has(customerStatus);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Classes/Customer.ts"],"names":["CustomerStatus","CustomerModel","BaseModel","data","date","withId","customerStatus"],"mappings":"6CAEO,IAAKA,OACVA,CAAA,CAAA,OAAA,CAAU,UACVA,CAAA,CAAA,eAAA,CAAkB,kBAClBA,CAAA,CAAA,cAAA,CAAiB,iBACjBA,CAAA,CAAA,SAAA,CAAY,YACZA,CAAA,CAAA,cAAA,CAAiB,iBACjBA,CAAA,CAAA,SAAA,CAAY,YANFA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CA2BSC,EAArB,cAA2CC,GAAU,CACzC,EACA,CAAA,KAAA,CACA,MACA,SACA,CAAA,QAAA,CACA,gBACA,cAQV,CAAA,WAAA,CAAYC,EAA0BC,CAAa,CAAA,IAAI,KAAQ,CAC7D,KAAA,CAAMD,EAAMC,CAAI,CAAA,CAChB,KAAK,EAAKD,CAAAA,CAAAA,CAAK,GACf,IAAK,CAAA,KAAA,CAAQA,EAAK,KAClB,CAAA,IAAA,CAAK,MAAQA,CAAK,CAAA,KAAA,CAClB,KAAK,SAAYA,CAAAA,CAAAA,CAAK,UACtB,IAAK,CAAA,QAAA,CAAWA,EAAK,QACrB,CAAA,IAAA,CAAK,gBAAkBA,CAAK,CAAA,eAAA,EAAmB,GAC/C,IAAK,CAAA,cAAA,CAAiB,IAAI,GACxB,CAAA,CAAC,GAAIA,CAAK,CAAA,cAAA,CAAiB,MAAM,IAAqBA,CAAAA,CAAAA,CAAK,cAAc,CAAI,CAAA,GAAK,SAAsB,CAC1G,EACF,CAUA,UAAA,CAAWE,EAAkB,CAA6C,CAAA,CAAA,CACxE,OAAO,CACL,GAAG,KAAM,CAAA,UAAA,GACT,GAAIA,CAAAA,CAAS,CAAE,EAAI,CAAA,IAAA,CAAK,OAAQ,CAAA,CAAI,EACpC,CAAA,KAAA,CAAO,KAAK,QAAS,EAAA,CACrB,MAAO,IAAK,CAAA,QAAA,GACZ,SAAW,CAAA,IAAA,CAAK,cAChB,CAAA,QAAA,CAAU,KAAK,WAAY,EAAA,CAC3B,gBAAiB,IAAK,CAAA,kBAAA,GACtB,cAAgB,CAAA,IAAA,CAAK,mBACvB,CACF,CAMA,KAAgB,EAAA,CACd,OAAO,IAAK,CAAA,EACd,CAMA,QAAmB,EAAA,CACjB,OAAO,IAAK,CAAA,KACd,CAMA,
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Customer.ts"],"names":["CustomerStatus","CustomerModel","BaseModel","data","date","withId","customerStatus"],"mappings":"6CAEO,IAAKA,OACVA,CAAA,CAAA,OAAA,CAAU,UACVA,CAAA,CAAA,eAAA,CAAkB,kBAClBA,CAAA,CAAA,cAAA,CAAiB,iBACjBA,CAAA,CAAA,SAAA,CAAY,YACZA,CAAA,CAAA,cAAA,CAAiB,iBACjBA,CAAA,CAAA,SAAA,CAAY,YANFA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CA2BSC,EAArB,cAA2CC,GAAU,CACzC,EACA,CAAA,KAAA,CACA,MACA,SACA,CAAA,QAAA,CACA,gBACA,cAQV,CAAA,WAAA,CAAYC,EAA0BC,CAAa,CAAA,IAAI,KAAQ,CAC7D,KAAA,CAAMD,EAAMC,C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OAAO,IAAA,CAAK,eAAe,GAAIA,CAAAA,CAAc,CAC/C,CACF","file":"Customer.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\n\r\nexport enum CustomerStatus {\r\n CREATED = \"CREATED\",\r\n REGISTERED_USER = \"REGISTERED_USER\",\r\n ACTIVATED_USER = \"ACTIVATED_USER\",\r\n EMAIL_OTP = \"EMAIL_OTP\",\r\n EMAIL_PASSWORD = \"EMAIL_PASSWORD\",\r\n PHONE_OTP = \"PHONE_OTP\",\r\n}\r\n\r\nexport type CustomerAttributes = BaseAttributes & {\r\n id: string;\r\n email: string;\r\n phone?: string;\r\n firstName: string;\r\n lastName: string;\r\n isEmailVerified?: boolean;\r\n customerStatus?: Set<CustomerStatus>;\r\n};\r\n\r\n\r\ntype CustomerDataWithArrayStatus = Omit<CustomerAttributes, 'customerStatus'> & BaseData & { customerStatus: CustomerStatus[]; }\r\nexport type CustomerData = Required<Omit<CustomerDataWithArrayStatus, 'phone'>> & { phone?: string};\r\nexport type CustomerDataWithOutId = Omit<CustomerData, 'id'>;\r\n\r\n/**\r\n * Represents a customer entity, managing customer information and status.\r\n */\r\nexport default class CustomerModel extends BaseModel {\r\n protected id: string;\r\n protected email: string;\r\n protected phone?: string;\r\n protected firstName: string;\r\n protected lastName: string;\r\n protected isEmailVerified: boolean;\r\n protected customerStatus: Set<CustomerStatus>;\r\n\r\n /**\r\n * Creates an instance of CustomerModel.\r\n * Initializes customer properties and ensures the CREATED status is always present.\r\n * @param data - The initial attributes for the customer.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: CustomerAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.email = data.email;\r\n this.phone = data.phone;\r\n this.firstName = data.firstName;\r\n this.lastName = data.lastName;\r\n this.isEmailVerified = data.isEmailVerified ?? false;\r\n this.customerStatus = new Set<CustomerStatus>(\r\n [...(data.customerStatus ? Array.from<CustomerStatus>(data.customerStatus) : []), CustomerStatus.CREATED]\r\n );\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the customer's current state.\r\n * Can optionally exclude the customer ID. Includes base model details.\r\n * @param withId - If true, includes the 'id' field. Defaults to false.\r\n * @returns CustomerData or CustomerDataWithOutId object suitable for serialization.\r\n */\r\n getDetails(withId?: false): CustomerDataWithOutId;\r\n getDetails(withId: true): CustomerData;\r\n getDetails(withId: boolean = false): CustomerData | CustomerDataWithOutId {\r\n return {\r\n ...super.getDetails(),\r\n ...(withId ? { id: this.getId() } : {}),\r\n email: this.getEmail(),\r\n phone: this.getPhone(),\r\n firstName: this.getFirstName(),\r\n lastName: this.getLastName(),\r\n isEmailVerified: this.getIsEmailVerified(),\r\n customerStatus: this.getCustomerStatus()\r\n };\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for the customer.\r\n * @returns The customer ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the email address of the customer.\r\n * @returns The email address.\r\n */\r\n getEmail(): string {\r\n return this.email;\r\n }\r\n\r\n /**\r\n * Gets the phone number of the customer.\r\n * @returns The phone number.\r\n */\r\n getPhone(): string | undefined {\r\n return this.phone;\r\n }\r\n\r\n\r\n /**\r\n * Gets the first name of the customer.\r\n * @returns The first name.\r\n */\r\n getFirstName(): string {\r\n return this.firstName;\r\n }\r\n\r\n\r\n /**\r\n * Gets the last name of the customer.\r\n * @returns The last name.\r\n */\r\n getLastName(): string {\r\n return this.lastName;\r\n }\r\n\r\n\r\n /**\r\n * Checks if the customer's email address has been verified.\r\n * @returns True if the email is verified, false otherwise.\r\n */\r\n getIsEmailVerified(): boolean {\r\n return this.isEmailVerified;\r\n }\r\n\r\n\r\n /**\r\n * Gets the customer's current statuses as an array.\r\n * @returns An array of CustomerStatus enum values.\r\n */\r\n getCustomerStatus(): CustomerStatus[] {\r\n return Array.from(this.customerStatus);\r\n }\r\n\r\n /**\r\n * Checks if the customer has a specific status.\r\n * Note: This method currently returns void. It should likely return boolean.\r\n * @param customerStatus - The status to check for.\r\n * @returns return boolean: true if the status exists, false otherwise.\r\n */\r\n hasCustomerStatus(customerStatus: CustomerStatus): boolean {\r\n return this.customerStatus.has(customerStatus);\r\n }\r\n}\r\n"]}
|
package/dist/Classes/Order.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a as a$1}from'../chunk-FL244D6L.mjs';import'../chunk-WU6FFDBS.mjs';import'../chunk-
|
|
1
|
+
import {a as a$1}from'../chunk-FL244D6L.mjs';import'../chunk-WU6FFDBS.mjs';import'../chunk-DKI6BDWK.mjs';import'../chunk-763MN5XV.mjs';import'../chunk-65X54TKF.mjs';import'../chunk-XZG7Y2WO.mjs';import'../chunk-DM2BJMLJ.mjs';import'../chunk-ATUUYYQT.mjs';var a=(t=>(t.PENDING_PAYMENT="PENDING_PAYMENT",t.PROCESSING="PROCESSING",t.SHIPPED="SHIPPED",t.PARTIALLY_SHIPPED="PARTIALLY_SHIPPED",t.DELIVERED="DELIVERED",t.CANCELLED="CANCELLED",t.RETURNED="RETURNED",t.REFUNDED="REFUNDED",t))(a||{}),s=class extends a$1{orderNumber;cartId;paymentStatus;holdReason;state;constructor(e,i=new Date){super(e,i),this.orderNumber=e.orderNumber,this.cartId=e.cartId,this.paymentStatus=e.paymentStatus,this.holdReason=e.holdReason||"",this.state=e.state;}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getDetails(){return {...super.getDetails(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),orderNumber:this.getOrderNumber(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};export{a as OrderState,s as default};//# sourceMappingURL=Order.mjs.map
|
|
2
2
|
//# sourceMappingURL=Order.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as default}from'../chunk-FL244D6L.mjs';import'../chunk-WU6FFDBS.mjs';import'../chunk-
|
|
1
|
+
export{a as default}from'../chunk-FL244D6L.mjs';import'../chunk-WU6FFDBS.mjs';import'../chunk-DKI6BDWK.mjs';import'../chunk-763MN5XV.mjs';import'../chunk-65X54TKF.mjs';import'../chunk-XZG7Y2WO.mjs';import'../chunk-DM2BJMLJ.mjs';import'../chunk-ATUUYYQT.mjs';//# sourceMappingURL=ShoppingContainer.mjs.map
|
|
2
2
|
//# sourceMappingURL=ShoppingContainer.mjs.map
|
|
@@ -42,7 +42,7 @@ declare class DynamoDBUtility {
|
|
|
42
42
|
* @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.
|
|
43
43
|
* @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.
|
|
44
44
|
*/
|
|
45
|
-
putItem(TableName: string, item: object, condition: string, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
45
|
+
putItem(TableName: string, item: object, condition: string | null, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
46
46
|
/**
|
|
47
47
|
* Executes multiple write operations (Put, Update, Delete, ConditionCheck) as a single atomic transaction.
|
|
48
48
|
* @param transactItems - An array of TransactWriteItem objects describing the operations. Keys and Put items will be automatically marshalled.
|
|
@@ -124,7 +124,7 @@ declare class DynamoDBUtility {
|
|
|
124
124
|
* @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.
|
|
125
125
|
* @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.
|
|
126
126
|
*/
|
|
127
|
-
updateItem(TableName: string, key: object, condition: string, update: string, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
127
|
+
updateItem(TableName: string, key: object, condition: string | null, update: string, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
128
128
|
/**
|
|
129
129
|
* Deletes a single item from a DynamoDB table using its primary key.
|
|
130
130
|
* @param TableName - The name of the table.
|
|
@@ -136,7 +136,7 @@ declare class DynamoDBUtility {
|
|
|
136
136
|
* @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.
|
|
137
137
|
* @returns A promise that resolves to the unmarshalled attributes of the deleted item (based on ReturnValues), or an empty object.
|
|
138
138
|
*/
|
|
139
|
-
deleteItem(TableName: string, key: object, condition: string, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
139
|
+
deleteItem(TableName: string, key: object, condition: string | null, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
140
140
|
/**
|
|
141
141
|
* Queries items from a DynamoDB secondary index based on a key condition expression.
|
|
142
142
|
* @param TableName - The name of the table.
|
package/dist/Dynamodb/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ declare class DynamoDBUtility {
|
|
|
42
42
|
* @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.
|
|
43
43
|
* @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.
|
|
44
44
|
*/
|
|
45
|
-
putItem(TableName: string, item: object, condition: string, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
45
|
+
putItem(TableName: string, item: object, condition: string | null, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
46
46
|
/**
|
|
47
47
|
* Executes multiple write operations (Put, Update, Delete, ConditionCheck) as a single atomic transaction.
|
|
48
48
|
* @param transactItems - An array of TransactWriteItem objects describing the operations. Keys and Put items will be automatically marshalled.
|
|
@@ -124,7 +124,7 @@ declare class DynamoDBUtility {
|
|
|
124
124
|
* @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.
|
|
125
125
|
* @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.
|
|
126
126
|
*/
|
|
127
|
-
updateItem(TableName: string, key: object, condition: string, update: string, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
127
|
+
updateItem(TableName: string, key: object, condition: string | null, update: string, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
128
128
|
/**
|
|
129
129
|
* Deletes a single item from a DynamoDB table using its primary key.
|
|
130
130
|
* @param TableName - The name of the table.
|
|
@@ -136,7 +136,7 @@ declare class DynamoDBUtility {
|
|
|
136
136
|
* @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.
|
|
137
137
|
* @returns A promise that resolves to the unmarshalled attributes of the deleted item (based on ReturnValues), or an empty object.
|
|
138
138
|
*/
|
|
139
|
-
deleteItem(TableName: string, key: object, condition: string, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
139
|
+
deleteItem(TableName: string, key: object, condition: string | null, attributeName?: Record<string, string> | null, attributeValue?: Record<string, AttributeValue> | null, ReturnValues?: ReturnValue | null, ReturnValuesOnFailure?: ReturnValuesOnConditionCheckFailure | null): Promise<Record<string, any>>;
|
|
140
140
|
/**
|
|
141
141
|
* Queries items from a DynamoDB secondary index based on a key condition expression.
|
|
142
142
|
* @param TableName - The name of the table.
|
package/dist/Dynamodb/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var clientDynamodb=require('@aws-sdk/client-dynamodb'),utilDynamodb=require('@aws-sdk/util-dynamodb');var g=class{client;returnItemCollectionMetrics;logCapacity;region;marshall=utilDynamodb.marshall;unmarshall=utilDynamodb.unmarshall;ReturnValue=clientDynamodb.ReturnValue;ReturnItemCollectionMetrics=clientDynamodb.ReturnItemCollectionMetrics;ReturnValuesOnConditionCheckFailure=clientDynamodb.ReturnValuesOnConditionCheckFailure;constructor({region:
|
|
1
|
+
'use strict';var clientDynamodb=require('@aws-sdk/client-dynamodb'),utilDynamodb=require('@aws-sdk/util-dynamodb');var g=class{client;returnItemCollectionMetrics;logCapacity;region;marshall=utilDynamodb.marshall;unmarshall=utilDynamodb.unmarshall;ReturnValue=clientDynamodb.ReturnValue;ReturnItemCollectionMetrics=clientDynamodb.ReturnItemCollectionMetrics;ReturnValuesOnConditionCheckFailure=clientDynamodb.ReturnValuesOnConditionCheckFailure;constructor({region:t,returnItemCollectionMetrics:n=clientDynamodb.ReturnItemCollectionMetrics.NONE,logCapacity:s=!1}){this.region=t,this.returnItemCollectionMetrics=n??clientDynamodb.ReturnItemCollectionMetrics.NONE,this.logCapacity=s??!1,this.client=new clientDynamodb.DynamoDBClient({region:this.region});}log(t,n,s){this.logCapacity&&console.log(t,"Capacity:",n,"Size:",s);}async putItem(t,n,s,i,e,o=clientDynamodb.ReturnValue.NONE,a=clientDynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD){let r={TableName:t,Item:utilDynamodb.marshall(n,{removeUndefinedValues:!0,convertClassInstanceToMap:!0}),ConditionExpression:s??void 0,ExpressionAttributeNames:i??void 0,ExpressionAttributeValues:e??void 0,ReturnValues:o??clientDynamodb.ReturnValue.NONE,ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.INDEXES,ReturnValuesOnConditionCheckFailure:a??clientDynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD,ReturnItemCollectionMetrics:this.returnItemCollectionMetrics},l=new clientDynamodb.PutItemCommand(r),u=await this.client.send(l);return this.log("Put",u.ConsumedCapacity,u.ItemCollectionMetrics),utilDynamodb.unmarshall(u.Attributes||{})}async transactWriteItems(t){let n={TransactItems:t.map(e=>(e.Put?.Item&&(e.Put.Item=utilDynamodb.marshall(e.Put.Item,{removeUndefinedValues:!0,convertClassInstanceToMap:!0})),e.Update?.Key&&(e.Update.Key=utilDynamodb.marshall(e.Update.Key)),e.Delete?.Key&&(e.Delete.Key=utilDynamodb.marshall(e.Delete.Key)),e.ConditionCheck?.Key&&(e.ConditionCheck.Key=utilDynamodb.marshall(e.ConditionCheck.Key)),e)),ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.INDEXES,ReturnItemCollectionMetrics:this.returnItemCollectionMetrics},s=new clientDynamodb.TransactWriteItemsCommand(n),i=await this.client.send(s);this.log("Transaction",i.ConsumedCapacity,i.ItemCollectionMetrics);}async getItem(t,n,s=!1,i,e){let o={TableName:t,Key:utilDynamodb.marshall(n),ConsistentRead:s??!1,ProjectionExpression:i??void 0,ExpressionAttributeNames:e??void 0,ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.TOTAL},a=new clientDynamodb.GetItemCommand(o),r=await this.client.send(a);return this.log("Read",r.ConsumedCapacity),utilDynamodb.unmarshall(r.Item||{})}async batchGetItem(t,n,s=!1,i,e){let o={RequestItems:{[t]:{Keys:n.map(l=>utilDynamodb.marshall(l)),ConsistentRead:s??!1,ProjectionExpression:i??void 0,ExpressionAttributeNames:e??void 0}},ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.TOTAL},a=new clientDynamodb.BatchGetItemCommand(o),r=await this.client.send(a);return this.log("BatchRead",r.ConsumedCapacity),r.Responses?.[t]?.map(l=>utilDynamodb.unmarshall(l))||[]}async queryItems(t,n,s=!1,i,e,o,a){let r={TableName:t,KeyConditionExpression:n,ExpressionAttributeValues:o??void 0,ConsistentRead:s??!1,ProjectionExpression:i??void 0,ExpressionAttributeNames:e??void 0,ExclusiveStartKey:a??void 0,ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.TOTAL},l=new clientDynamodb.QueryCommand(r),u=await this.client.send(l);return this.log("Query",u.ConsumedCapacity),{items:u.Items?.map(c=>utilDynamodb.unmarshall(c))||[],lastEvaluatedKey:u.LastEvaluatedKey}}async scanItems(t,n,s=!1,i,e,o,a){let r={TableName:t,FilterExpression:n??void 0,ExpressionAttributeValues:o??void 0,ConsistentRead:s??!1,ProjectionExpression:i??void 0,ExpressionAttributeNames:e??void 0,ExclusiveStartKey:a??void 0,ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.TOTAL},l=new clientDynamodb.ScanCommand(r),u=await this.client.send(l);return this.log("Scan",u.ConsumedCapacity),{items:u.Items?.map(c=>utilDynamodb.unmarshall(c))||[],lastEvaluatedKey:u.LastEvaluatedKey}}async partiQL(t,n=[],s,i=!1){let e={Statement:t,Parameters:n??[],ConsistentRead:i??!1,NextToken:s??void 0,ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.INDEXES},o=new clientDynamodb.ExecuteStatementCommand(e),a=await this.client.send(o);return this.log("PartiQL",a.ConsumedCapacity),{Items:a.Items?.map(r=>utilDynamodb.unmarshall(r))||[],nextToken:a.NextToken,lastEvaluatedKey:a.LastEvaluatedKey}}async updateItem(t,n,s,i,e,o,a=clientDynamodb.ReturnValue.UPDATED_NEW,r=clientDynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD){let l={TableName:t,Key:utilDynamodb.marshall(n),ConditionExpression:s??void 0,UpdateExpression:i,ExpressionAttributeNames:e??void 0,ExpressionAttributeValues:o??void 0,ReturnValues:a??clientDynamodb.ReturnValue.UPDATED_NEW,ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.INDEXES,ReturnValuesOnConditionCheckFailure:r??clientDynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD,ReturnItemCollectionMetrics:this.returnItemCollectionMetrics},u=new clientDynamodb.UpdateItemCommand(l),c=await this.client.send(u);return this.log("Update",c.ConsumedCapacity,c.ItemCollectionMetrics),utilDynamodb.unmarshall(c.Attributes||{})}async deleteItem(t,n,s,i,e,o=clientDynamodb.ReturnValue.ALL_OLD,a=clientDynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD){let r={TableName:t,Key:utilDynamodb.marshall(n),ConditionExpression:s??void 0,ExpressionAttributeNames:i??void 0,ExpressionAttributeValues:e??void 0,ReturnValues:o??clientDynamodb.ReturnValue.ALL_OLD,ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.INDEXES,ReturnValuesOnConditionCheckFailure:a??clientDynamodb.ReturnValuesOnConditionCheckFailure.ALL_OLD,ReturnItemCollectionMetrics:this.returnItemCollectionMetrics},l=new clientDynamodb.DeleteItemCommand(r),u=await this.client.send(l);return this.log("Delete",u.ConsumedCapacity,u.ItemCollectionMetrics),utilDynamodb.unmarshall(u.Attributes||{})}async getItemByIndex(t,n,s,i=!1,e,o,a,r){let l={TableName:t,IndexName:n,KeyConditionExpression:s,ExpressionAttributeValues:a??void 0,ExclusiveStartKey:r??void 0,ConsistentRead:i??!1,ProjectionExpression:e??void 0,ExpressionAttributeNames:o??void 0,ReturnConsumedCapacity:clientDynamodb.ReturnConsumedCapacity.INDEXES},u=new clientDynamodb.QueryCommand(l),c=await this.client.send(u);return this.log("GetItemByIndex",c.ConsumedCapacity),{Items:c.Items?.map(E=>utilDynamodb.unmarshall(E))||[],lastEvaluatedKey:c.LastEvaluatedKey}}},W=g;module.exports=W;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Dynamodb/index.ts"],"names":["DynamoDBUtility","marshall","unmarshall","ReturnValue","ReturnItemCollectionMetrics","ReturnValuesOnConditionCheckFailure","region","returnItemCollectionMetrics","logCapacity","DynamoDBClient","message","capacity","size","TableName","item","condition","attributeName","attributeValue","ReturnValues","ReturnValuesOnFailure","input","ReturnConsumedCapacity","command","PutItemCommand","result","transactItems","TransactWriteItemsCommand","key","consistent","projection","GetItemCommand","keys","BatchGetItemCommand","keyCondition","lastEvaluatedKey","QueryCommand","filterExpression","ScanCommand","statement","parameter","nextToken","ExecuteStatementCommand","update","UpdateItemCommand","DeleteItemCommand","index","Dynamodb_default"],"mappings":"mHAoCMA,IAAAA,CAAAA,CAAN,KAAsB,CACV,MAAA,CACA,4BACA,WACA,CAAA,MAAA,CAER,SAAWC,qBACX,CAAA,UAAA,CAAaC,uBACb,CAAA,WAAA,CAAcC,0BACd,CAAA,2BAAA,CAA8BC,2CAC9B,mCAAsCC,CAAAA,kDAAAA,CAEtC,YAAY,CACR,MAAA,CAAAC,EACA,2BAAAC,CAAAA,CAAAA,CAA8BH,0CAA4B,CAAA,IAAA,CAC1D,WAAAI,CAAAA,CAAAA,CAAc,EAClB,CAA2B,CAAA,CACvB,KAAK,MAASF,CAAAA,CAAAA,CACd,KAAK,2BAA8BC,CAAAA,CAAAA,EAA+BH,0CAA4B,CAAA,IAAA,CAC9F,IAAK,CAAA,WAAA,CAAcI,GAAe,CAClC,CAAA,CAAA,IAAA,CAAK,O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AAA,CAAK,MAAO,CAAA,IAAA,CAAKF,CAAO,CAAA,CAC7C,YAAK,GAAI,CAAA,QAAA,CAAUE,EAAO,gBAAkBA,CAAAA,CAAAA,CAAO,qBAAqB,CACjEtB,CAAAA,uBAAAA,CAAWsB,CAAO,CAAA,UAAA,EAAc,EAAE,CAC7C,CAcA,MAAM,eACFX,CACAgC,CAAAA,CAAAA,CACAZ,EACAL,CAA6B,CAAA,CAAA,CAAA,CAC7BC,CACAb,CAAAA,CAAAA,CACAC,CACAiB,CAAAA,CAAAA,CACF,CACE,IAAMd,CAAAA,CAA2B,CAC7B,SAAA,CAAAP,CACA,CAAA,SAAA,CAAWgC,EACX,sBAAwBZ,CAAAA,CAAAA,CACxB,yBAA2BhB,CAAAA,CAAAA,EAAkB,KAC7C,CAAA,CAAA,iBAAA,CAAmBiB,GAAoB,KACvC,CAAA,CAAA,cAAA,CAAgBN,GAAc,CAC9B,CAAA,CAAA,oBAAA,CAAsBC,GAAc,KACpC,CAAA,CAAA,wBAAA,CAA0Bb,CAAiB,EAAA,KAAA,CAAA,CAC3C,sBAAwBK,CAAAA,qCAAAA,CAAuB,OACnD,CAEMC,CAAAA,CAAAA,CAAU,IAAIa,2BAAaf,CAAAA,CAAK,EAChCI,CAAS,CAAA,MAAM,IAAK,CAAA,MAAA,CAAO,IAAKF,CAAAA,CAAO,EAC7C,OAAK,IAAA,CAAA,GAAA,CAAI,iBAAkBE,CAAO,CAAA,gBAAgB,EAC3C,CACH,KAAA,CAAOA,CAAO,CAAA,KAAA,EAAO,GAAIV,CAAAA,CAAAA,EAAQZ,wBAAWY,CAAI,CAAC,CAAK,EAAA,EACtD,CAAA,gBAAA,CAAkBU,EAAO,gBAC7B,CACJ,CACJ,CAAA,CAEOsB,CAAQ9C,CAAAA","file":"index.js","sourcesContent":["import {\r\n BatchGetItemCommand,\r\n BatchGetItemCommandInput,\r\n DeleteItemCommand,\r\n DeleteItemCommandInput,\r\n DynamoDBClient,\r\n ExecuteStatementCommand,\r\n ExecuteStatementCommandInput,\r\n GetItemCommand,\r\n GetItemCommandInput,\r\n PutItemCommand,\r\n PutItemCommandInput,\r\n QueryCommand,\r\n QueryCommandInput,\r\n ScanCommand,\r\n ScanCommandInput,\r\n TransactWriteItemsCommand,\r\n TransactWriteItemsCommandInput,\r\n UpdateItemCommand,\r\n UpdateItemCommandInput,\r\n AttributeValue,\r\n ReturnConsumedCapacity,\r\n ReturnValue,\r\n ReturnValuesOnConditionCheckFailure,\r\n ReturnItemCollectionMetrics,\r\n TransactWriteItem,\r\n} from '@aws-sdk/client-dynamodb';\r\n\r\nimport { marshall, unmarshall } from '@aws-sdk/util-dynamodb';\r\n\r\ntype DynamoDBUtilityOptions = {\r\n region: string;\r\n returnItemCollectionMetrics?: ReturnItemCollectionMetrics | null;\r\n logCapacity?: boolean | null;\r\n};\r\n\r\nclass DynamoDBUtility {\r\n private client: DynamoDBClient;\r\n private returnItemCollectionMetrics: ReturnItemCollectionMetrics;\r\n private logCapacity: boolean;\r\n private region: string;\r\n\r\n marshall = marshall;\r\n unmarshall = unmarshall;\r\n ReturnValue = ReturnValue;\r\n ReturnItemCollectionMetrics = ReturnItemCollectionMetrics;\r\n ReturnValuesOnConditionCheckFailure = ReturnValuesOnConditionCheckFailure;\r\n\r\n constructor({\r\n region,\r\n returnItemCollectionMetrics = ReturnItemCollectionMetrics.NONE,\r\n logCapacity = false\r\n }: DynamoDBUtilityOptions) {\r\n this.region = region;\r\n this.returnItemCollectionMetrics = returnItemCollectionMetrics ?? ReturnItemCollectionMetrics.NONE;\r\n this.logCapacity = logCapacity ?? false;\r\n this.client = new DynamoDBClient({ region: this.region });\r\n }\r\n\r\n private log(message: string, capacity: any, size?: any) {\r\n if (this.logCapacity) {\r\n console.log(message, 'Capacity:', capacity, 'Size:', size);\r\n }\r\n }\r\n\r\n /**\r\n * Puts (creates or replaces) an item into a DynamoDB table.\r\n * @param TableName - The name of the table.\r\n * @param item - The item object to put into the table.\r\n * @param condition - A condition expression that must be met for the put operation to succeed.\r\n * @param attributeName - Optional map of expression attribute names.\r\n * @param attributeValue - Optional map of expression attribute values used in the condition expression.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD). Defaults to NONE.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.\r\n */\r\n async putItem(\r\n TableName: string,\r\n item: object,\r\n condition: string,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.NONE,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: PutItemCommandInput = {\r\n TableName,\r\n Item: marshall(item, {\r\n removeUndefinedValues: true,\r\n convertClassInstanceToMap: true,\r\n }),\r\n ConditionExpression: condition,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.NONE,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new PutItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Put', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Executes multiple write operations (Put, Update, Delete, ConditionCheck) as a single atomic transaction.\r\n * @param transactItems - An array of TransactWriteItem objects describing the operations. Keys and Put items will be automatically marshalled.\r\n * @returns A promise that resolves when the transaction completes. Throws an error if the transaction fails.\r\n */\r\n async transactWriteItems(transactItems: TransactWriteItem[]) {\r\n const input: TransactWriteItemsCommandInput = {\r\n TransactItems: transactItems.map((item) => {\r\n if (item.Put?.Item) {\r\n item.Put.Item = marshall(item.Put.Item, {\r\n removeUndefinedValues: true,\r\n convertClassInstanceToMap: true,\r\n });\r\n }\r\n if (item.Update?.Key) {\r\n item.Update.Key = marshall(item.Update.Key);\r\n }\r\n if (item.Delete?.Key) {\r\n item.Delete.Key = marshall(item.Delete.Key);\r\n }\r\n if (item.ConditionCheck?.Key) {\r\n item.ConditionCheck.Key = marshall(item.ConditionCheck.Key);\r\n }\r\n return item;\r\n }),\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new TransactWriteItemsCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Transaction', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n }\r\n\r\n /**\r\n * Retrieves a single item from a DynamoDB table using its primary key.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to retrieve.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in the projection expression.\r\n * @returns A promise that resolves to the unmarshalled item object, or an empty object if the item is not found.\r\n */\r\n async getItem(\r\n TableName: string,\r\n key: object,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null\r\n ) {\r\n const input: GetItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new GetItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Read', result.ConsumedCapacity);\r\n return unmarshall(result.Item || {});\r\n }\r\n\r\n /**\r\n * Retrieves multiple items from one or more tables in a batch operation. This implementation targets a single table.\r\n * @param TableName - The name of the table.\r\n * @param keys - An array of objects, each representing a primary key of an item to retrieve.\r\n * @param consistent - Optional flag for strongly consistent read for this table. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in the projection expression.\r\n * @returns A promise that resolves to an array of unmarshalled item objects found for the given keys.\r\n */\r\n async batchGetItem(\r\n TableName: string,\r\n keys: object[],\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null\r\n ) {\r\n const input: BatchGetItemCommandInput = {\r\n RequestItems: {\r\n [TableName]: {\r\n Keys: keys.map((key) => marshall(key)),\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n },\r\n },\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new BatchGetItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('BatchRead', result.ConsumedCapacity);\r\n return result.Responses?.[TableName]?.map((item) => unmarshall(item)) || [];\r\n }\r\n\r\n /**\r\n * Queries items from a DynamoDB table or index based on a key condition expression.\r\n * @param TableName - The name of the table.\r\n * @param keyCondition - The key condition expression to filter items.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the key condition expression.\r\n * @param lastEvaluatedKey - Optional key from a previous query response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async queryItems(\r\n TableName: string,\r\n keyCondition: string,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: QueryCommandInput = {\r\n TableName,\r\n KeyConditionExpression: keyCondition,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new QueryCommand(input);\r\n const result = await this.client.send(command);\r\n\r\n this.log('Query', result.ConsumedCapacity);\r\n return {\r\n items: result.Items?.map((item) => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Scans (reads all items) a DynamoDB table or index, optionally filtering results. Use Scan operations judiciously.\r\n * @param TableName - The name of the table.\r\n * @param filterExpression - Optional filter expression to apply after the scan.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false. Not recommended for scans.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the filter expression.\r\n * @param lastEvaluatedKey - Optional key from a previous scan response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async scanItems(\r\n TableName: string,\r\n filterExpression?: string | null,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: ScanCommandInput = {\r\n TableName,\r\n FilterExpression: filterExpression ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new ScanCommand(input);\r\n const result = await this.client.send(command);\r\n\r\n this.log('Scan', result.ConsumedCapacity);\r\n return {\r\n items: result.Items?.map((item) => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Executes a PartiQL statement against DynamoDB.\r\n * @param statement - The PartiQL statement string.\r\n * @param parameter - Optional array of AttributeValue parameters for the statement. Defaults to an empty array.\r\n * @param nextToken - Optional token from a previous PartiQL response to continue pagination.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and optional nextToken/lastEvaluatedKey for pagination.\r\n */\r\n async partiQL(\r\n statement: string,\r\n parameter: AttributeValue[] | null = [],\r\n nextToken?: string | null,\r\n consistent: boolean | null = false\r\n ) {\r\n const input: ExecuteStatementCommandInput = {\r\n Statement: statement,\r\n Parameters: parameter ?? [],\r\n ConsistentRead: consistent ?? false,\r\n NextToken: nextToken ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n };\r\n\r\n const command = new ExecuteStatementCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('PartiQL', result.ConsumedCapacity);\r\n return {\r\n Items: result.Items?.map((item) => unmarshall(item)) || [],\r\n nextToken: result.NextToken,\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Updates an existing item in a DynamoDB table.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to update.\r\n * @param condition - A condition expression that must be met for the update operation to succeed.\r\n * @param update - An update expression specifying the attribute modifications.\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in expressions.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD, UPDATED_NEW). Defaults to UPDATED_NEW.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.\r\n */\r\n async updateItem(\r\n TableName: string,\r\n key: object,\r\n condition: string,\r\n update: string,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.UPDATED_NEW,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: UpdateItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConditionExpression: condition,\r\n UpdateExpression: update,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.UPDATED_NEW,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new UpdateItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Update', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Deletes a single item from a DynamoDB table using its primary key.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to delete.\r\n * @param condition - A condition expression that must be met for the delete operation to succeed.\r\n * @param attributeName - Optional map of expression attribute names used in the condition expression.\r\n * @param attributeValue - Optional map of expression attribute values used in the condition expression.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD). Defaults to ALL_OLD.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes of the deleted item (based on ReturnValues), or an empty object.\r\n */\r\n async deleteItem(\r\n TableName: string,\r\n key: object,\r\n condition: string,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.ALL_OLD,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: DeleteItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConditionExpression: condition,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.ALL_OLD,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new DeleteItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Delete', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Queries items from a DynamoDB secondary index based on a key condition expression.\r\n * @param TableName - The name of the table.\r\n * @param index - The name of the secondary index to query.\r\n * @param keyCondition - The key condition expression to filter items within the index.\r\n * @param consistent - Optional flag for strongly consistent read (only applicable if the index supports it). Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the key condition expression.\r\n * @param lastEvaluatedKey - Optional key from a previous query response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async getItemByIndex(\r\n TableName: string,\r\n index: string,\r\n keyCondition: string,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: QueryCommandInput = {\r\n TableName,\r\n IndexName: index,\r\n KeyConditionExpression: keyCondition,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES\r\n }\r\n\r\n const command = new QueryCommand(input);\r\n const result = await this.client.send(command);\r\n this.log(\"GetItemByIndex\", result.ConsumedCapacity);\r\n return {\r\n Items: result.Items?.map(item => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n}\r\n\r\nexport default DynamoDBUtility;\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Dynamodb/index.ts"],"names":["DynamoDBUtility","marshall","unmarshall","ReturnValue","ReturnItemCollectionMetrics","ReturnValuesOnConditionCheckFailure","region","returnItemCollectionMetrics","logCapacity","DynamoDBClient","message","capacity","size","TableName","item","condition","attributeName","attributeValue","ReturnValues","ReturnValuesOnFailure","input","ReturnConsumedCapacity","command","PutItemCommand","result","transactItems","TransactWriteItemsCommand","key","consistent","projection","GetItemCommand","keys","BatchGetItemCommand","keyCondition","lastEvaluatedKey","QueryCommand","filterExpression","ScanCommand","statement","parameter","nextToken","ExecuteStatementCommand","update","UpdateItemCommand","DeleteItemCommand","index","Dynamodb_default"],"mappings":"mHAoCMA,IAAAA,CAAAA,CAAN,KAAsB,CACV,MAAA,CACA,4BACA,WACA,CAAA,MAAA,CAER,SAAWC,qBACX,CAAA,UAAA,CAAaC,uBACb,CAAA,WAAA,CAAcC,0BACd,CAAA,2BAAA,CAA8BC,2CAC9B,mCAAsCC,CAAAA,kDAAAA,CAEtC,YAAY,CACR,MAAA,CAAAC,EACA,2BAAAC,CAAAA,CAAAA,CAA8BH,0CAA4B,CAAA,IAAA,CAC1D,WAAAI,CAAAA,CAAAA,CAAc,EAClB,CAA2B,C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,CAAAA,CAAAA,EAAQZ,wBAAWY,CAAI,CAAC,CAAK,EAAA,EACtD,CAAA,gBAAA,CAAkBU,EAAO,gBAC7B,CACJ,CACJ,CAAA,CAEOsB,CAAQ9C,CAAAA","file":"index.js","sourcesContent":["import {\r\n BatchGetItemCommand,\r\n BatchGetItemCommandInput,\r\n DeleteItemCommand,\r\n DeleteItemCommandInput,\r\n DynamoDBClient,\r\n ExecuteStatementCommand,\r\n ExecuteStatementCommandInput,\r\n GetItemCommand,\r\n GetItemCommandInput,\r\n PutItemCommand,\r\n PutItemCommandInput,\r\n QueryCommand,\r\n QueryCommandInput,\r\n ScanCommand,\r\n ScanCommandInput,\r\n TransactWriteItemsCommand,\r\n TransactWriteItemsCommandInput,\r\n UpdateItemCommand,\r\n UpdateItemCommandInput,\r\n AttributeValue,\r\n ReturnConsumedCapacity,\r\n ReturnValue,\r\n ReturnValuesOnConditionCheckFailure,\r\n ReturnItemCollectionMetrics,\r\n TransactWriteItem,\r\n} from '@aws-sdk/client-dynamodb';\r\n\r\nimport { marshall, unmarshall } from '@aws-sdk/util-dynamodb';\r\n\r\ntype DynamoDBUtilityOptions = {\r\n region: string;\r\n returnItemCollectionMetrics?: ReturnItemCollectionMetrics | null;\r\n logCapacity?: boolean | null;\r\n};\r\n\r\nclass DynamoDBUtility {\r\n private client: DynamoDBClient;\r\n private returnItemCollectionMetrics: ReturnItemCollectionMetrics;\r\n private logCapacity: boolean;\r\n private region: string;\r\n\r\n marshall = marshall;\r\n unmarshall = unmarshall;\r\n ReturnValue = ReturnValue;\r\n ReturnItemCollectionMetrics = ReturnItemCollectionMetrics;\r\n ReturnValuesOnConditionCheckFailure = ReturnValuesOnConditionCheckFailure;\r\n\r\n constructor({\r\n region,\r\n returnItemCollectionMetrics = ReturnItemCollectionMetrics.NONE,\r\n logCapacity = false\r\n }: DynamoDBUtilityOptions) {\r\n this.region = region;\r\n this.returnItemCollectionMetrics = returnItemCollectionMetrics ?? ReturnItemCollectionMetrics.NONE;\r\n this.logCapacity = logCapacity ?? false;\r\n this.client = new DynamoDBClient({ region: this.region });\r\n }\r\n\r\n private log(message: string, capacity: any, size?: any) {\r\n if (this.logCapacity) {\r\n console.log(message, 'Capacity:', capacity, 'Size:', size);\r\n }\r\n }\r\n\r\n /**\r\n * Puts (creates or replaces) an item into a DynamoDB table.\r\n * @param TableName - The name of the table.\r\n * @param item - The item object to put into the table.\r\n * @param condition - A condition expression that must be met for the put operation to succeed.\r\n * @param attributeName - Optional map of expression attribute names.\r\n * @param attributeValue - Optional map of expression attribute values used in the condition expression.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD). Defaults to NONE.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.\r\n */\r\n async putItem(\r\n TableName: string,\r\n item: object,\r\n condition: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.NONE,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: PutItemCommandInput = {\r\n TableName,\r\n Item: marshall(item, {\r\n removeUndefinedValues: true,\r\n convertClassInstanceToMap: true,\r\n }),\r\n ConditionExpression: condition ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.NONE,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new PutItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Put', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Executes multiple write operations (Put, Update, Delete, ConditionCheck) as a single atomic transaction.\r\n * @param transactItems - An array of TransactWriteItem objects describing the operations. Keys and Put items will be automatically marshalled.\r\n * @returns A promise that resolves when the transaction completes. Throws an error if the transaction fails.\r\n */\r\n async transactWriteItems(transactItems: TransactWriteItem[]) {\r\n const input: TransactWriteItemsCommandInput = {\r\n TransactItems: transactItems.map((item) => {\r\n if (item.Put?.Item) {\r\n item.Put.Item = marshall(item.Put.Item, {\r\n removeUndefinedValues: true,\r\n convertClassInstanceToMap: true,\r\n });\r\n }\r\n if (item.Update?.Key) {\r\n item.Update.Key = marshall(item.Update.Key);\r\n }\r\n if (item.Delete?.Key) {\r\n item.Delete.Key = marshall(item.Delete.Key);\r\n }\r\n if (item.ConditionCheck?.Key) {\r\n item.ConditionCheck.Key = marshall(item.ConditionCheck.Key);\r\n }\r\n return item;\r\n }),\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new TransactWriteItemsCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Transaction', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n }\r\n\r\n /**\r\n * Retrieves a single item from a DynamoDB table using its primary key.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to retrieve.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in the projection expression.\r\n * @returns A promise that resolves to the unmarshalled item object, or an empty object if the item is not found.\r\n */\r\n async getItem(\r\n TableName: string,\r\n key: object,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null\r\n ) {\r\n const input: GetItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new GetItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Read', result.ConsumedCapacity);\r\n return unmarshall(result.Item || {});\r\n }\r\n\r\n /**\r\n * Retrieves multiple items from one or more tables in a batch operation. This implementation targets a single table.\r\n * @param TableName - The name of the table.\r\n * @param keys - An array of objects, each representing a primary key of an item to retrieve.\r\n * @param consistent - Optional flag for strongly consistent read for this table. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in the projection expression.\r\n * @returns A promise that resolves to an array of unmarshalled item objects found for the given keys.\r\n */\r\n async batchGetItem(\r\n TableName: string,\r\n keys: object[],\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null\r\n ) {\r\n const input: BatchGetItemCommandInput = {\r\n RequestItems: {\r\n [TableName]: {\r\n Keys: keys.map((key) => marshall(key)),\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n },\r\n },\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new BatchGetItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('BatchRead', result.ConsumedCapacity);\r\n return result.Responses?.[TableName]?.map((item) => unmarshall(item)) || [];\r\n }\r\n\r\n /**\r\n * Queries items from a DynamoDB table or index based on a key condition expression.\r\n * @param TableName - The name of the table.\r\n * @param keyCondition - The key condition expression to filter items.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the key condition expression.\r\n * @param lastEvaluatedKey - Optional key from a previous query response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async queryItems(\r\n TableName: string,\r\n keyCondition: string,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: QueryCommandInput = {\r\n TableName,\r\n KeyConditionExpression: keyCondition,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new QueryCommand(input);\r\n const result = await this.client.send(command);\r\n\r\n this.log('Query', result.ConsumedCapacity);\r\n return {\r\n items: result.Items?.map((item) => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Scans (reads all items) a DynamoDB table or index, optionally filtering results. Use Scan operations judiciously.\r\n * @param TableName - The name of the table.\r\n * @param filterExpression - Optional filter expression to apply after the scan.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false. Not recommended for scans.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the filter expression.\r\n * @param lastEvaluatedKey - Optional key from a previous scan response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async scanItems(\r\n TableName: string,\r\n filterExpression?: string | null,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: ScanCommandInput = {\r\n TableName,\r\n FilterExpression: filterExpression ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new ScanCommand(input);\r\n const result = await this.client.send(command);\r\n\r\n this.log('Scan', result.ConsumedCapacity);\r\n return {\r\n items: result.Items?.map((item) => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Executes a PartiQL statement against DynamoDB.\r\n * @param statement - The PartiQL statement string.\r\n * @param parameter - Optional array of AttributeValue parameters for the statement. Defaults to an empty array.\r\n * @param nextToken - Optional token from a previous PartiQL response to continue pagination.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and optional nextToken/lastEvaluatedKey for pagination.\r\n */\r\n async partiQL(\r\n statement: string,\r\n parameter: AttributeValue[] | null = [],\r\n nextToken?: string | null,\r\n consistent: boolean | null = false\r\n ) {\r\n const input: ExecuteStatementCommandInput = {\r\n Statement: statement,\r\n Parameters: parameter ?? [],\r\n ConsistentRead: consistent ?? false,\r\n NextToken: nextToken ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n };\r\n\r\n const command = new ExecuteStatementCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('PartiQL', result.ConsumedCapacity);\r\n return {\r\n Items: result.Items?.map((item) => unmarshall(item)) || [],\r\n nextToken: result.NextToken,\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Updates an existing item in a DynamoDB table.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to update.\r\n * @param condition - A condition expression that must be met for the update operation to succeed.\r\n * @param update - An update expression specifying the attribute modifications.\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in expressions.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD, UPDATED_NEW). Defaults to UPDATED_NEW.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.\r\n */\r\n async updateItem(\r\n TableName: string,\r\n key: object,\r\n condition: string | null,\r\n update: string,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.UPDATED_NEW,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: UpdateItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConditionExpression: condition ?? undefined,\r\n UpdateExpression: update,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.UPDATED_NEW,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new UpdateItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Update', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Deletes a single item from a DynamoDB table using its primary key.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to delete.\r\n * @param condition - A condition expression that must be met for the delete operation to succeed.\r\n * @param attributeName - Optional map of expression attribute names used in the condition expression.\r\n * @param attributeValue - Optional map of expression attribute values used in the condition expression.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD). Defaults to ALL_OLD.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes of the deleted item (based on ReturnValues), or an empty object.\r\n */\r\n async deleteItem(\r\n TableName: string,\r\n key: object,\r\n condition: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.ALL_OLD,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: DeleteItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConditionExpression: condition ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.ALL_OLD,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new DeleteItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Delete', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Queries items from a DynamoDB secondary index based on a key condition expression.\r\n * @param TableName - The name of the table.\r\n * @param index - The name of the secondary index to query.\r\n * @param keyCondition - The key condition expression to filter items within the index.\r\n * @param consistent - Optional flag for strongly consistent read (only applicable if the index supports it). Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the key condition expression.\r\n * @param lastEvaluatedKey - Optional key from a previous query response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async getItemByIndex(\r\n TableName: string,\r\n index: string,\r\n keyCondition: string,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: QueryCommandInput = {\r\n TableName,\r\n IndexName: index,\r\n KeyConditionExpression: keyCondition,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES\r\n }\r\n\r\n const command = new QueryCommand(input);\r\n const result = await this.client.send(command);\r\n this.log(\"GetItemByIndex\", result.ConsumedCapacity);\r\n return {\r\n Items: result.Items?.map(item => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n}\r\n\r\nexport default DynamoDBUtility;\r\n"]}
|
package/dist/Dynamodb/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {ReturnValue,ReturnItemCollectionMetrics,ReturnValuesOnConditionCheckFailure,DynamoDBClient,ReturnConsumedCapacity,PutItemCommand,TransactWriteItemsCommand,GetItemCommand,BatchGetItemCommand,QueryCommand,ScanCommand,ExecuteStatementCommand,UpdateItemCommand,DeleteItemCommand}from'@aws-sdk/client-dynamodb';import {marshall,unmarshall}from'@aws-sdk/util-dynamodb';var g=class{client;returnItemCollectionMetrics;logCapacity;region;marshall=marshall;unmarshall=unmarshall;ReturnValue=ReturnValue;ReturnItemCollectionMetrics=ReturnItemCollectionMetrics;ReturnValuesOnConditionCheckFailure=ReturnValuesOnConditionCheckFailure;constructor({region:
|
|
1
|
+
import {ReturnValue,ReturnItemCollectionMetrics,ReturnValuesOnConditionCheckFailure,DynamoDBClient,ReturnConsumedCapacity,PutItemCommand,TransactWriteItemsCommand,GetItemCommand,BatchGetItemCommand,QueryCommand,ScanCommand,ExecuteStatementCommand,UpdateItemCommand,DeleteItemCommand}from'@aws-sdk/client-dynamodb';import {marshall,unmarshall}from'@aws-sdk/util-dynamodb';var g=class{client;returnItemCollectionMetrics;logCapacity;region;marshall=marshall;unmarshall=unmarshall;ReturnValue=ReturnValue;ReturnItemCollectionMetrics=ReturnItemCollectionMetrics;ReturnValuesOnConditionCheckFailure=ReturnValuesOnConditionCheckFailure;constructor({region:t,returnItemCollectionMetrics:n=ReturnItemCollectionMetrics.NONE,logCapacity:s=!1}){this.region=t,this.returnItemCollectionMetrics=n??ReturnItemCollectionMetrics.NONE,this.logCapacity=s??!1,this.client=new DynamoDBClient({region:this.region});}log(t,n,s){this.logCapacity&&console.log(t,"Capacity:",n,"Size:",s);}async putItem(t,n,s,i,e,o=ReturnValue.NONE,a=ReturnValuesOnConditionCheckFailure.ALL_OLD){let r={TableName:t,Item:marshall(n,{removeUndefinedValues:!0,convertClassInstanceToMap:!0}),ConditionExpression:s??void 0,ExpressionAttributeNames:i??void 0,ExpressionAttributeValues:e??void 0,ReturnValues:o??ReturnValue.NONE,ReturnConsumedCapacity:ReturnConsumedCapacity.INDEXES,ReturnValuesOnConditionCheckFailure:a??ReturnValuesOnConditionCheckFailure.ALL_OLD,ReturnItemCollectionMetrics:this.returnItemCollectionMetrics},l=new PutItemCommand(r),u=await this.client.send(l);return this.log("Put",u.ConsumedCapacity,u.ItemCollectionMetrics),unmarshall(u.Attributes||{})}async transactWriteItems(t){let n={TransactItems:t.map(e=>(e.Put?.Item&&(e.Put.Item=marshall(e.Put.Item,{removeUndefinedValues:!0,convertClassInstanceToMap:!0})),e.Update?.Key&&(e.Update.Key=marshall(e.Update.Key)),e.Delete?.Key&&(e.Delete.Key=marshall(e.Delete.Key)),e.ConditionCheck?.Key&&(e.ConditionCheck.Key=marshall(e.ConditionCheck.Key)),e)),ReturnConsumedCapacity:ReturnConsumedCapacity.INDEXES,ReturnItemCollectionMetrics:this.returnItemCollectionMetrics},s=new TransactWriteItemsCommand(n),i=await this.client.send(s);this.log("Transaction",i.ConsumedCapacity,i.ItemCollectionMetrics);}async getItem(t,n,s=!1,i,e){let o={TableName:t,Key:marshall(n),ConsistentRead:s??!1,ProjectionExpression:i??void 0,ExpressionAttributeNames:e??void 0,ReturnConsumedCapacity:ReturnConsumedCapacity.TOTAL},a=new GetItemCommand(o),r=await this.client.send(a);return this.log("Read",r.ConsumedCapacity),unmarshall(r.Item||{})}async batchGetItem(t,n,s=!1,i,e){let o={RequestItems:{[t]:{Keys:n.map(l=>marshall(l)),ConsistentRead:s??!1,ProjectionExpression:i??void 0,ExpressionAttributeNames:e??void 0}},ReturnConsumedCapacity:ReturnConsumedCapacity.TOTAL},a=new BatchGetItemCommand(o),r=await this.client.send(a);return this.log("BatchRead",r.ConsumedCapacity),r.Responses?.[t]?.map(l=>unmarshall(l))||[]}async queryItems(t,n,s=!1,i,e,o,a){let r={TableName:t,KeyConditionExpression:n,ExpressionAttributeValues:o??void 0,ConsistentRead:s??!1,ProjectionExpression:i??void 0,ExpressionAttributeNames:e??void 0,ExclusiveStartKey:a??void 0,ReturnConsumedCapacity:ReturnConsumedCapacity.TOTAL},l=new QueryCommand(r),u=await this.client.send(l);return this.log("Query",u.ConsumedCapacity),{items:u.Items?.map(c=>unmarshall(c))||[],lastEvaluatedKey:u.LastEvaluatedKey}}async scanItems(t,n,s=!1,i,e,o,a){let r={TableName:t,FilterExpression:n??void 0,ExpressionAttributeValues:o??void 0,ConsistentRead:s??!1,ProjectionExpression:i??void 0,ExpressionAttributeNames:e??void 0,ExclusiveStartKey:a??void 0,ReturnConsumedCapacity:ReturnConsumedCapacity.TOTAL},l=new ScanCommand(r),u=await this.client.send(l);return this.log("Scan",u.ConsumedCapacity),{items:u.Items?.map(c=>unmarshall(c))||[],lastEvaluatedKey:u.LastEvaluatedKey}}async partiQL(t,n=[],s,i=!1){let e={Statement:t,Parameters:n??[],ConsistentRead:i??!1,NextToken:s??void 0,ReturnConsumedCapacity:ReturnConsumedCapacity.INDEXES},o=new ExecuteStatementCommand(e),a=await this.client.send(o);return this.log("PartiQL",a.ConsumedCapacity),{Items:a.Items?.map(r=>unmarshall(r))||[],nextToken:a.NextToken,lastEvaluatedKey:a.LastEvaluatedKey}}async updateItem(t,n,s,i,e,o,a=ReturnValue.UPDATED_NEW,r=ReturnValuesOnConditionCheckFailure.ALL_OLD){let l={TableName:t,Key:marshall(n),ConditionExpression:s??void 0,UpdateExpression:i,ExpressionAttributeNames:e??void 0,ExpressionAttributeValues:o??void 0,ReturnValues:a??ReturnValue.UPDATED_NEW,ReturnConsumedCapacity:ReturnConsumedCapacity.INDEXES,ReturnValuesOnConditionCheckFailure:r??ReturnValuesOnConditionCheckFailure.ALL_OLD,ReturnItemCollectionMetrics:this.returnItemCollectionMetrics},u=new UpdateItemCommand(l),c=await this.client.send(u);return this.log("Update",c.ConsumedCapacity,c.ItemCollectionMetrics),unmarshall(c.Attributes||{})}async deleteItem(t,n,s,i,e,o=ReturnValue.ALL_OLD,a=ReturnValuesOnConditionCheckFailure.ALL_OLD){let r={TableName:t,Key:marshall(n),ConditionExpression:s??void 0,ExpressionAttributeNames:i??void 0,ExpressionAttributeValues:e??void 0,ReturnValues:o??ReturnValue.ALL_OLD,ReturnConsumedCapacity:ReturnConsumedCapacity.INDEXES,ReturnValuesOnConditionCheckFailure:a??ReturnValuesOnConditionCheckFailure.ALL_OLD,ReturnItemCollectionMetrics:this.returnItemCollectionMetrics},l=new DeleteItemCommand(r),u=await this.client.send(l);return this.log("Delete",u.ConsumedCapacity,u.ItemCollectionMetrics),unmarshall(u.Attributes||{})}async getItemByIndex(t,n,s,i=!1,e,o,a,r){let l={TableName:t,IndexName:n,KeyConditionExpression:s,ExpressionAttributeValues:a??void 0,ExclusiveStartKey:r??void 0,ConsistentRead:i??!1,ProjectionExpression:e??void 0,ExpressionAttributeNames:o??void 0,ReturnConsumedCapacity:ReturnConsumedCapacity.INDEXES},u=new QueryCommand(l),c=await this.client.send(u);return this.log("GetItemByIndex",c.ConsumedCapacity),{Items:c.Items?.map(E=>unmarshall(E))||[],lastEvaluatedKey:c.LastEvaluatedKey}}},Q=g;export{Q as default};//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Dynamodb/index.ts"],"names":["DynamoDBUtility","marshall","unmarshall","ReturnValue","ReturnItemCollectionMetrics","ReturnValuesOnConditionCheckFailure","region","returnItemCollectionMetrics","logCapacity","DynamoDBClient","message","capacity","size","TableName","item","condition","attributeName","attributeValue","ReturnValues","ReturnValuesOnFailure","input","ReturnConsumedCapacity","command","PutItemCommand","result","transactItems","TransactWriteItemsCommand","key","consistent","projection","GetItemCommand","keys","BatchGetItemCommand","keyCondition","lastEvaluatedKey","QueryCommand","filterExpression","ScanCommand","statement","parameter","nextToken","ExecuteStatementCommand","update","UpdateItemCommand","DeleteItemCommand","index","Dynamodb_default"],"mappings":"mXAoCMA,IAAAA,CAAAA,CAAN,KAAsB,CACV,MAAA,CACA,4BACA,WACA,CAAA,MAAA,CAER,SAAWC,QACX,CAAA,UAAA,CAAaC,UACb,CAAA,WAAA,CAAcC,WACd,CAAA,2BAAA,CAA8BC,4BAC9B,mCAAsCC,CAAAA,mCAAAA,CAEtC,YAAY,CACR,MAAA,CAAAC,EACA,2BAAAC,CAAAA,CAAAA,CAA8BH,2BAA4B,CAAA,IAAA,CAC1D,WAAAI,CAAAA,CAAAA,CAAc,EAClB,CAA2B,CAAA,CACvB,KAAK,MAASF,CAAAA,CAAAA,CACd,KAAK,2BAA8BC,CAAAA,CAAAA,EAA+BH,2BAA4B,CAAA,IAAA,CAC9F,IAAK,CAAA,WAAA,CAAcI,GAAe,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AA,CAAK,MAAO,CAAA,IAAA,CAAKF,CAAO,CAAA,CAC7C,YAAK,GAAI,CAAA,QAAA,CAAUE,EAAO,gBAAkBA,CAAAA,CAAAA,CAAO,qBAAqB,CACjEtB,CAAAA,UAAAA,CAAWsB,CAAO,CAAA,UAAA,EAAc,EAAE,CAC7C,CAcA,MAAM,eACFX,CACAgC,CAAAA,CAAAA,CACAZ,EACAL,CAA6B,CAAA,CAAA,CAAA,CAC7BC,CACAb,CAAAA,CAAAA,CACAC,CACAiB,CAAAA,CAAAA,CACF,CACE,IAAMd,CAAAA,CAA2B,CAC7B,SAAA,CAAAP,CACA,CAAA,SAAA,CAAWgC,EACX,sBAAwBZ,CAAAA,CAAAA,CACxB,yBAA2BhB,CAAAA,CAAAA,EAAkB,KAC7C,CAAA,CAAA,iBAAA,CAAmBiB,GAAoB,KACvC,CAAA,CAAA,cAAA,CAAgBN,GAAc,CAC9B,CAAA,CAAA,oBAAA,CAAsBC,GAAc,KACpC,CAAA,CAAA,wBAAA,CAA0Bb,CAAiB,EAAA,KAAA,CAAA,CAC3C,sBAAwBK,CAAAA,sBAAAA,CAAuB,OACnD,CAEMC,CAAAA,CAAAA,CAAU,IAAIa,YAAaf,CAAAA,CAAK,EAChCI,CAAS,CAAA,MAAM,IAAK,CAAA,MAAA,CAAO,IAAKF,CAAAA,CAAO,EAC7C,OAAK,IAAA,CAAA,GAAA,CAAI,iBAAkBE,CAAO,CAAA,gBAAgB,EAC3C,CACH,KAAA,CAAOA,CAAO,CAAA,KAAA,EAAO,GAAIV,CAAAA,CAAAA,EAAQZ,WAAWY,CAAI,CAAC,CAAK,EAAA,EACtD,CAAA,gBAAA,CAAkBU,EAAO,gBAC7B,CACJ,CACJ,CAAA,CAEOsB,CAAQ9C,CAAAA","file":"index.mjs","sourcesContent":["import {\r\n BatchGetItemCommand,\r\n BatchGetItemCommandInput,\r\n DeleteItemCommand,\r\n DeleteItemCommandInput,\r\n DynamoDBClient,\r\n ExecuteStatementCommand,\r\n ExecuteStatementCommandInput,\r\n GetItemCommand,\r\n GetItemCommandInput,\r\n PutItemCommand,\r\n PutItemCommandInput,\r\n QueryCommand,\r\n QueryCommandInput,\r\n ScanCommand,\r\n ScanCommandInput,\r\n TransactWriteItemsCommand,\r\n TransactWriteItemsCommandInput,\r\n UpdateItemCommand,\r\n UpdateItemCommandInput,\r\n AttributeValue,\r\n ReturnConsumedCapacity,\r\n ReturnValue,\r\n ReturnValuesOnConditionCheckFailure,\r\n ReturnItemCollectionMetrics,\r\n TransactWriteItem,\r\n} from '@aws-sdk/client-dynamodb';\r\n\r\nimport { marshall, unmarshall } from '@aws-sdk/util-dynamodb';\r\n\r\ntype DynamoDBUtilityOptions = {\r\n region: string;\r\n returnItemCollectionMetrics?: ReturnItemCollectionMetrics | null;\r\n logCapacity?: boolean | null;\r\n};\r\n\r\nclass DynamoDBUtility {\r\n private client: DynamoDBClient;\r\n private returnItemCollectionMetrics: ReturnItemCollectionMetrics;\r\n private logCapacity: boolean;\r\n private region: string;\r\n\r\n marshall = marshall;\r\n unmarshall = unmarshall;\r\n ReturnValue = ReturnValue;\r\n ReturnItemCollectionMetrics = ReturnItemCollectionMetrics;\r\n ReturnValuesOnConditionCheckFailure = ReturnValuesOnConditionCheckFailure;\r\n\r\n constructor({\r\n region,\r\n returnItemCollectionMetrics = ReturnItemCollectionMetrics.NONE,\r\n logCapacity = false\r\n }: DynamoDBUtilityOptions) {\r\n this.region = region;\r\n this.returnItemCollectionMetrics = returnItemCollectionMetrics ?? ReturnItemCollectionMetrics.NONE;\r\n this.logCapacity = logCapacity ?? false;\r\n this.client = new DynamoDBClient({ region: this.region });\r\n }\r\n\r\n private log(message: string, capacity: any, size?: any) {\r\n if (this.logCapacity) {\r\n console.log(message, 'Capacity:', capacity, 'Size:', size);\r\n }\r\n }\r\n\r\n /**\r\n * Puts (creates or replaces) an item into a DynamoDB table.\r\n * @param TableName - The name of the table.\r\n * @param item - The item object to put into the table.\r\n * @param condition - A condition expression that must be met for the put operation to succeed.\r\n * @param attributeName - Optional map of expression attribute names.\r\n * @param attributeValue - Optional map of expression attribute values used in the condition expression.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD). Defaults to NONE.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.\r\n */\r\n async putItem(\r\n TableName: string,\r\n item: object,\r\n condition: string,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.NONE,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: PutItemCommandInput = {\r\n TableName,\r\n Item: marshall(item, {\r\n removeUndefinedValues: true,\r\n convertClassInstanceToMap: true,\r\n }),\r\n ConditionExpression: condition,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.NONE,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new PutItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Put', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Executes multiple write operations (Put, Update, Delete, ConditionCheck) as a single atomic transaction.\r\n * @param transactItems - An array of TransactWriteItem objects describing the operations. Keys and Put items will be automatically marshalled.\r\n * @returns A promise that resolves when the transaction completes. Throws an error if the transaction fails.\r\n */\r\n async transactWriteItems(transactItems: TransactWriteItem[]) {\r\n const input: TransactWriteItemsCommandInput = {\r\n TransactItems: transactItems.map((item) => {\r\n if (item.Put?.Item) {\r\n item.Put.Item = marshall(item.Put.Item, {\r\n removeUndefinedValues: true,\r\n convertClassInstanceToMap: true,\r\n });\r\n }\r\n if (item.Update?.Key) {\r\n item.Update.Key = marshall(item.Update.Key);\r\n }\r\n if (item.Delete?.Key) {\r\n item.Delete.Key = marshall(item.Delete.Key);\r\n }\r\n if (item.ConditionCheck?.Key) {\r\n item.ConditionCheck.Key = marshall(item.ConditionCheck.Key);\r\n }\r\n return item;\r\n }),\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new TransactWriteItemsCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Transaction', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n }\r\n\r\n /**\r\n * Retrieves a single item from a DynamoDB table using its primary key.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to retrieve.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in the projection expression.\r\n * @returns A promise that resolves to the unmarshalled item object, or an empty object if the item is not found.\r\n */\r\n async getItem(\r\n TableName: string,\r\n key: object,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null\r\n ) {\r\n const input: GetItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new GetItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Read', result.ConsumedCapacity);\r\n return unmarshall(result.Item || {});\r\n }\r\n\r\n /**\r\n * Retrieves multiple items from one or more tables in a batch operation. This implementation targets a single table.\r\n * @param TableName - The name of the table.\r\n * @param keys - An array of objects, each representing a primary key of an item to retrieve.\r\n * @param consistent - Optional flag for strongly consistent read for this table. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in the projection expression.\r\n * @returns A promise that resolves to an array of unmarshalled item objects found for the given keys.\r\n */\r\n async batchGetItem(\r\n TableName: string,\r\n keys: object[],\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null\r\n ) {\r\n const input: BatchGetItemCommandInput = {\r\n RequestItems: {\r\n [TableName]: {\r\n Keys: keys.map((key) => marshall(key)),\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n },\r\n },\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new BatchGetItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('BatchRead', result.ConsumedCapacity);\r\n return result.Responses?.[TableName]?.map((item) => unmarshall(item)) || [];\r\n }\r\n\r\n /**\r\n * Queries items from a DynamoDB table or index based on a key condition expression.\r\n * @param TableName - The name of the table.\r\n * @param keyCondition - The key condition expression to filter items.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the key condition expression.\r\n * @param lastEvaluatedKey - Optional key from a previous query response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async queryItems(\r\n TableName: string,\r\n keyCondition: string,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: QueryCommandInput = {\r\n TableName,\r\n KeyConditionExpression: keyCondition,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new QueryCommand(input);\r\n const result = await this.client.send(command);\r\n\r\n this.log('Query', result.ConsumedCapacity);\r\n return {\r\n items: result.Items?.map((item) => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Scans (reads all items) a DynamoDB table or index, optionally filtering results. Use Scan operations judiciously.\r\n * @param TableName - The name of the table.\r\n * @param filterExpression - Optional filter expression to apply after the scan.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false. Not recommended for scans.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the filter expression.\r\n * @param lastEvaluatedKey - Optional key from a previous scan response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async scanItems(\r\n TableName: string,\r\n filterExpression?: string | null,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: ScanCommandInput = {\r\n TableName,\r\n FilterExpression: filterExpression ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new ScanCommand(input);\r\n const result = await this.client.send(command);\r\n\r\n this.log('Scan', result.ConsumedCapacity);\r\n return {\r\n items: result.Items?.map((item) => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Executes a PartiQL statement against DynamoDB.\r\n * @param statement - The PartiQL statement string.\r\n * @param parameter - Optional array of AttributeValue parameters for the statement. Defaults to an empty array.\r\n * @param nextToken - Optional token from a previous PartiQL response to continue pagination.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and optional nextToken/lastEvaluatedKey for pagination.\r\n */\r\n async partiQL(\r\n statement: string,\r\n parameter: AttributeValue[] | null = [],\r\n nextToken?: string | null,\r\n consistent: boolean | null = false\r\n ) {\r\n const input: ExecuteStatementCommandInput = {\r\n Statement: statement,\r\n Parameters: parameter ?? [],\r\n ConsistentRead: consistent ?? false,\r\n NextToken: nextToken ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n };\r\n\r\n const command = new ExecuteStatementCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('PartiQL', result.ConsumedCapacity);\r\n return {\r\n Items: result.Items?.map((item) => unmarshall(item)) || [],\r\n nextToken: result.NextToken,\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Updates an existing item in a DynamoDB table.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to update.\r\n * @param condition - A condition expression that must be met for the update operation to succeed.\r\n * @param update - An update expression specifying the attribute modifications.\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in expressions.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD, UPDATED_NEW). Defaults to UPDATED_NEW.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.\r\n */\r\n async updateItem(\r\n TableName: string,\r\n key: object,\r\n condition: string,\r\n update: string,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.UPDATED_NEW,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: UpdateItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConditionExpression: condition,\r\n UpdateExpression: update,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.UPDATED_NEW,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new UpdateItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Update', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Deletes a single item from a DynamoDB table using its primary key.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to delete.\r\n * @param condition - A condition expression that must be met for the delete operation to succeed.\r\n * @param attributeName - Optional map of expression attribute names used in the condition expression.\r\n * @param attributeValue - Optional map of expression attribute values used in the condition expression.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD). Defaults to ALL_OLD.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes of the deleted item (based on ReturnValues), or an empty object.\r\n */\r\n async deleteItem(\r\n TableName: string,\r\n key: object,\r\n condition: string,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.ALL_OLD,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: DeleteItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConditionExpression: condition,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.ALL_OLD,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new DeleteItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Delete', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Queries items from a DynamoDB secondary index based on a key condition expression.\r\n * @param TableName - The name of the table.\r\n * @param index - The name of the secondary index to query.\r\n * @param keyCondition - The key condition expression to filter items within the index.\r\n * @param consistent - Optional flag for strongly consistent read (only applicable if the index supports it). Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the key condition expression.\r\n * @param lastEvaluatedKey - Optional key from a previous query response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async getItemByIndex(\r\n TableName: string,\r\n index: string,\r\n keyCondition: string,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: QueryCommandInput = {\r\n TableName,\r\n IndexName: index,\r\n KeyConditionExpression: keyCondition,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES\r\n }\r\n\r\n const command = new QueryCommand(input);\r\n const result = await this.client.send(command);\r\n this.log(\"GetItemByIndex\", result.ConsumedCapacity);\r\n return {\r\n Items: result.Items?.map(item => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n}\r\n\r\nexport default DynamoDBUtility;\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Dynamodb/index.ts"],"names":["DynamoDBUtility","marshall","unmarshall","ReturnValue","ReturnItemCollectionMetrics","ReturnValuesOnConditionCheckFailure","region","returnItemCollectionMetrics","logCapacity","DynamoDBClient","message","capacity","size","TableName","item","condition","attributeName","attributeValue","ReturnValues","ReturnValuesOnFailure","input","ReturnConsumedCapacity","command","PutItemCommand","result","transactItems","TransactWriteItemsCommand","key","consistent","projection","GetItemCommand","keys","BatchGetItemCommand","keyCondition","lastEvaluatedKey","QueryCommand","filterExpression","ScanCommand","statement","parameter","nextToken","ExecuteStatementCommand","update","UpdateItemCommand","DeleteItemCommand","index","Dynamodb_default"],"mappings":"mXAoCMA,IAAAA,CAAAA,CAAN,KAAsB,CACV,MAAA,CACA,4BACA,WACA,CAAA,MAAA,CAER,SAAWC,QACX,CAAA,UAAA,CAAaC,UACb,CAAA,WAAA,CAAcC,WACd,CAAA,2BAAA,CAA8BC,4BAC9B,mCAAsCC,CAAAA,mCAAAA,CAEtC,YAAY,CACR,MAAA,CAAAC,EACA,2BAAAC,CAAAA,CAAAA,CAA8BH,2BAA4B,CAAA,IAAA,CAC1D,WAAAI,CAAAA,CAAAA,CAAc,EAClB,CAA2B,CAAA,C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C,CAAK,EAAA,EACtD,CAAA,gBAAA,CAAkBU,EAAO,gBAC7B,CACJ,CACJ,CAAA,CAEOsB,CAAQ9C,CAAAA","file":"index.mjs","sourcesContent":["import {\r\n BatchGetItemCommand,\r\n BatchGetItemCommandInput,\r\n DeleteItemCommand,\r\n DeleteItemCommandInput,\r\n DynamoDBClient,\r\n ExecuteStatementCommand,\r\n ExecuteStatementCommandInput,\r\n GetItemCommand,\r\n GetItemCommandInput,\r\n PutItemCommand,\r\n PutItemCommandInput,\r\n QueryCommand,\r\n QueryCommandInput,\r\n ScanCommand,\r\n ScanCommandInput,\r\n TransactWriteItemsCommand,\r\n TransactWriteItemsCommandInput,\r\n UpdateItemCommand,\r\n UpdateItemCommandInput,\r\n AttributeValue,\r\n ReturnConsumedCapacity,\r\n ReturnValue,\r\n ReturnValuesOnConditionCheckFailure,\r\n ReturnItemCollectionMetrics,\r\n TransactWriteItem,\r\n} from '@aws-sdk/client-dynamodb';\r\n\r\nimport { marshall, unmarshall } from '@aws-sdk/util-dynamodb';\r\n\r\ntype DynamoDBUtilityOptions = {\r\n region: string;\r\n returnItemCollectionMetrics?: ReturnItemCollectionMetrics | null;\r\n logCapacity?: boolean | null;\r\n};\r\n\r\nclass DynamoDBUtility {\r\n private client: DynamoDBClient;\r\n private returnItemCollectionMetrics: ReturnItemCollectionMetrics;\r\n private logCapacity: boolean;\r\n private region: string;\r\n\r\n marshall = marshall;\r\n unmarshall = unmarshall;\r\n ReturnValue = ReturnValue;\r\n ReturnItemCollectionMetrics = ReturnItemCollectionMetrics;\r\n ReturnValuesOnConditionCheckFailure = ReturnValuesOnConditionCheckFailure;\r\n\r\n constructor({\r\n region,\r\n returnItemCollectionMetrics = ReturnItemCollectionMetrics.NONE,\r\n logCapacity = false\r\n }: DynamoDBUtilityOptions) {\r\n this.region = region;\r\n this.returnItemCollectionMetrics = returnItemCollectionMetrics ?? ReturnItemCollectionMetrics.NONE;\r\n this.logCapacity = logCapacity ?? false;\r\n this.client = new DynamoDBClient({ region: this.region });\r\n }\r\n\r\n private log(message: string, capacity: any, size?: any) {\r\n if (this.logCapacity) {\r\n console.log(message, 'Capacity:', capacity, 'Size:', size);\r\n }\r\n }\r\n\r\n /**\r\n * Puts (creates or replaces) an item into a DynamoDB table.\r\n * @param TableName - The name of the table.\r\n * @param item - The item object to put into the table.\r\n * @param condition - A condition expression that must be met for the put operation to succeed.\r\n * @param attributeName - Optional map of expression attribute names.\r\n * @param attributeValue - Optional map of expression attribute values used in the condition expression.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD). Defaults to NONE.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.\r\n */\r\n async putItem(\r\n TableName: string,\r\n item: object,\r\n condition: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.NONE,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: PutItemCommandInput = {\r\n TableName,\r\n Item: marshall(item, {\r\n removeUndefinedValues: true,\r\n convertClassInstanceToMap: true,\r\n }),\r\n ConditionExpression: condition ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.NONE,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new PutItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Put', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Executes multiple write operations (Put, Update, Delete, ConditionCheck) as a single atomic transaction.\r\n * @param transactItems - An array of TransactWriteItem objects describing the operations. Keys and Put items will be automatically marshalled.\r\n * @returns A promise that resolves when the transaction completes. Throws an error if the transaction fails.\r\n */\r\n async transactWriteItems(transactItems: TransactWriteItem[]) {\r\n const input: TransactWriteItemsCommandInput = {\r\n TransactItems: transactItems.map((item) => {\r\n if (item.Put?.Item) {\r\n item.Put.Item = marshall(item.Put.Item, {\r\n removeUndefinedValues: true,\r\n convertClassInstanceToMap: true,\r\n });\r\n }\r\n if (item.Update?.Key) {\r\n item.Update.Key = marshall(item.Update.Key);\r\n }\r\n if (item.Delete?.Key) {\r\n item.Delete.Key = marshall(item.Delete.Key);\r\n }\r\n if (item.ConditionCheck?.Key) {\r\n item.ConditionCheck.Key = marshall(item.ConditionCheck.Key);\r\n }\r\n return item;\r\n }),\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new TransactWriteItemsCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Transaction', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n }\r\n\r\n /**\r\n * Retrieves a single item from a DynamoDB table using its primary key.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to retrieve.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in the projection expression.\r\n * @returns A promise that resolves to the unmarshalled item object, or an empty object if the item is not found.\r\n */\r\n async getItem(\r\n TableName: string,\r\n key: object,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null\r\n ) {\r\n const input: GetItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new GetItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Read', result.ConsumedCapacity);\r\n return unmarshall(result.Item || {});\r\n }\r\n\r\n /**\r\n * Retrieves multiple items from one or more tables in a batch operation. This implementation targets a single table.\r\n * @param TableName - The name of the table.\r\n * @param keys - An array of objects, each representing a primary key of an item to retrieve.\r\n * @param consistent - Optional flag for strongly consistent read for this table. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in the projection expression.\r\n * @returns A promise that resolves to an array of unmarshalled item objects found for the given keys.\r\n */\r\n async batchGetItem(\r\n TableName: string,\r\n keys: object[],\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null\r\n ) {\r\n const input: BatchGetItemCommandInput = {\r\n RequestItems: {\r\n [TableName]: {\r\n Keys: keys.map((key) => marshall(key)),\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n },\r\n },\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new BatchGetItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('BatchRead', result.ConsumedCapacity);\r\n return result.Responses?.[TableName]?.map((item) => unmarshall(item)) || [];\r\n }\r\n\r\n /**\r\n * Queries items from a DynamoDB table or index based on a key condition expression.\r\n * @param TableName - The name of the table.\r\n * @param keyCondition - The key condition expression to filter items.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the key condition expression.\r\n * @param lastEvaluatedKey - Optional key from a previous query response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async queryItems(\r\n TableName: string,\r\n keyCondition: string,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: QueryCommandInput = {\r\n TableName,\r\n KeyConditionExpression: keyCondition,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new QueryCommand(input);\r\n const result = await this.client.send(command);\r\n\r\n this.log('Query', result.ConsumedCapacity);\r\n return {\r\n items: result.Items?.map((item) => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Scans (reads all items) a DynamoDB table or index, optionally filtering results. Use Scan operations judiciously.\r\n * @param TableName - The name of the table.\r\n * @param filterExpression - Optional filter expression to apply after the scan.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false. Not recommended for scans.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the filter expression.\r\n * @param lastEvaluatedKey - Optional key from a previous scan response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async scanItems(\r\n TableName: string,\r\n filterExpression?: string | null,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: ScanCommandInput = {\r\n TableName,\r\n FilterExpression: filterExpression ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.TOTAL,\r\n };\r\n\r\n const command = new ScanCommand(input);\r\n const result = await this.client.send(command);\r\n\r\n this.log('Scan', result.ConsumedCapacity);\r\n return {\r\n items: result.Items?.map((item) => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Executes a PartiQL statement against DynamoDB.\r\n * @param statement - The PartiQL statement string.\r\n * @param parameter - Optional array of AttributeValue parameters for the statement. Defaults to an empty array.\r\n * @param nextToken - Optional token from a previous PartiQL response to continue pagination.\r\n * @param consistent - Optional flag for strongly consistent read. Defaults to false.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and optional nextToken/lastEvaluatedKey for pagination.\r\n */\r\n async partiQL(\r\n statement: string,\r\n parameter: AttributeValue[] | null = [],\r\n nextToken?: string | null,\r\n consistent: boolean | null = false\r\n ) {\r\n const input: ExecuteStatementCommandInput = {\r\n Statement: statement,\r\n Parameters: parameter ?? [],\r\n ConsistentRead: consistent ?? false,\r\n NextToken: nextToken ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n };\r\n\r\n const command = new ExecuteStatementCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('PartiQL', result.ConsumedCapacity);\r\n return {\r\n Items: result.Items?.map((item) => unmarshall(item)) || [],\r\n nextToken: result.NextToken,\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n\r\n /**\r\n * Updates an existing item in a DynamoDB table.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to update.\r\n * @param condition - A condition expression that must be met for the update operation to succeed.\r\n * @param update - An update expression specifying the attribute modifications.\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in expressions.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD, UPDATED_NEW). Defaults to UPDATED_NEW.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes returned by the operation (based on ReturnValues), or an empty object.\r\n */\r\n async updateItem(\r\n TableName: string,\r\n key: object,\r\n condition: string | null,\r\n update: string,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.UPDATED_NEW,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: UpdateItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConditionExpression: condition ?? undefined,\r\n UpdateExpression: update,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.UPDATED_NEW,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new UpdateItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Update', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Deletes a single item from a DynamoDB table using its primary key.\r\n * @param TableName - The name of the table.\r\n * @param key - An object representing the primary key of the item to delete.\r\n * @param condition - A condition expression that must be met for the delete operation to succeed.\r\n * @param attributeName - Optional map of expression attribute names used in the condition expression.\r\n * @param attributeValue - Optional map of expression attribute values used in the condition expression.\r\n * @param ReturnValues - Optional instruction on what values to return (e.g., NONE, ALL_OLD). Defaults to ALL_OLD.\r\n * @param ReturnValuesOnFailure - Optional instruction on what values to return if the condition check fails. Defaults to ALL_OLD.\r\n * @returns A promise that resolves to the unmarshalled attributes of the deleted item (based on ReturnValues), or an empty object.\r\n */\r\n async deleteItem(\r\n TableName: string,\r\n key: object,\r\n condition: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n ReturnValues: ReturnValue | null = ReturnValue.ALL_OLD,\r\n ReturnValuesOnFailure: ReturnValuesOnConditionCheckFailure | null = ReturnValuesOnConditionCheckFailure.ALL_OLD\r\n ) {\r\n const input: DeleteItemCommandInput = {\r\n TableName,\r\n Key: marshall(key),\r\n ConditionExpression: condition ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ReturnValues: ReturnValues ?? ReturnValue.ALL_OLD,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES,\r\n ReturnValuesOnConditionCheckFailure: ReturnValuesOnFailure ?? ReturnValuesOnConditionCheckFailure.ALL_OLD,\r\n ReturnItemCollectionMetrics: this.returnItemCollectionMetrics,\r\n };\r\n\r\n const command = new DeleteItemCommand(input);\r\n const result = await this.client.send(command);\r\n this.log('Delete', result.ConsumedCapacity, result.ItemCollectionMetrics);\r\n return unmarshall(result.Attributes || {});\r\n }\r\n\r\n /**\r\n * Queries items from a DynamoDB secondary index based on a key condition expression.\r\n * @param TableName - The name of the table.\r\n * @param index - The name of the secondary index to query.\r\n * @param keyCondition - The key condition expression to filter items within the index.\r\n * @param consistent - Optional flag for strongly consistent read (only applicable if the index supports it). Defaults to false.\r\n * @param projection - Optional string specifying the attributes to retrieve (projection expression).\r\n * @param attributeName - Optional map of expression attribute names used in expressions.\r\n * @param attributeValue - Optional map of expression attribute values used in the key condition expression.\r\n * @param lastEvaluatedKey - Optional key from a previous query response to continue pagination.\r\n * @returns A promise that resolves to an object containing the array of unmarshalled items and the optional lastEvaluatedKey for pagination.\r\n */\r\n async getItemByIndex(\r\n TableName: string,\r\n index: string,\r\n keyCondition: string,\r\n consistent: boolean | null = false,\r\n projection?: string | null,\r\n attributeName?: Record<string, string> | null,\r\n attributeValue?: Record<string, AttributeValue> | null,\r\n lastEvaluatedKey?: Record<string, AttributeValue> | null\r\n ) {\r\n const input: QueryCommandInput = {\r\n TableName,\r\n IndexName: index,\r\n KeyConditionExpression: keyCondition,\r\n ExpressionAttributeValues: attributeValue ?? undefined,\r\n ExclusiveStartKey: lastEvaluatedKey ?? undefined,\r\n ConsistentRead: consistent ?? false,\r\n ProjectionExpression: projection ?? undefined,\r\n ExpressionAttributeNames: attributeName ?? undefined,\r\n ReturnConsumedCapacity: ReturnConsumedCapacity.INDEXES\r\n }\r\n\r\n const command = new QueryCommand(input);\r\n const result = await this.client.send(command);\r\n this.log(\"GetItemByIndex\", result.ConsumedCapacity);\r\n return {\r\n Items: result.Items?.map(item => unmarshall(item)) || [],\r\n lastEvaluatedKey: result.LastEvaluatedKey,\r\n };\r\n }\r\n}\r\n\r\nexport default DynamoDBUtility;\r\n"]}
|