betterddb 0.4.1 → 0.4.2

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.
@@ -1,64 +1,129 @@
1
1
  import { z } from 'zod';
2
- import { DynamoDB } from 'aws-sdk';
3
2
  import { QueryBuilder } from './builders/query-builder';
4
3
  import { ScanBuilder } from './builders/scan-builder';
5
4
  import { UpdateBuilder } from './builders/update-builder';
6
5
  import { CreateBuilder } from './builders/create-builder';
7
6
  import { GetBuilder } from './builders/get-builder';
8
7
  import { DeleteBuilder } from './builders/delete-builder';
9
- export type SchemaType<S extends z.ZodType<any>> = z.infer<S>;
8
+ import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
10
9
  export type PrimaryKeyValue = string | number;
11
- export type KeyDefinition<S extends z.ZodType<any>> = keyof SchemaType<S> | {
12
- build: (rawKey: Partial<SchemaType<S>>) => string;
10
+ /**
11
+ * A key definition can be either a simple key (a property name)
12
+ * or an object containing a build function that computes the value.
13
+ * (In this design, the attribute name is provided separately.)
14
+ */
15
+ export type KeyDefinition<T> = keyof T | {
16
+ build: (rawKey: Partial<T>) => string;
13
17
  };
14
- export interface PrimaryKeyConfig<S extends z.ZodType<any>> {
18
+ /**
19
+ * Configuration for a primary (partition) key.
20
+ */
21
+ export interface PrimaryKeyConfig<T> {
22
+ /** The attribute name for the primary key in DynamoDB */
15
23
  name: string;
16
- definition: KeyDefinition<S>;
24
+ /** How to compute the key value; if a keyof T, then the raw value is used;
25
+ * if an object, the build function is used.
26
+ */
27
+ definition: KeyDefinition<T>;
17
28
  }
18
- export interface SortKeyConfig<S extends z.ZodType<any>> {
29
+ /**
30
+ * Configuration for a sort key.
31
+ */
32
+ export interface SortKeyConfig<T> {
33
+ /** The attribute name for the sort key in DynamoDB */
19
34
  name: string;
20
- definition: KeyDefinition<S>;
35
+ /** How to compute the sort key value */
36
+ definition: KeyDefinition<T>;
21
37
  }
22
- export interface GSIConfig<S extends z.ZodType<any>> {
38
+ /**
39
+ * Configuration for a Global Secondary Index (GSI).
40
+ */
41
+ export interface GSIConfig<T> {
42
+ /** The name of the GSI in DynamoDB */
23
43
  name: string;
24
- primary: PrimaryKeyConfig<S>;
25
- sort?: SortKeyConfig<S>;
44
+ /** The primary key configuration for the GSI */
45
+ primary: PrimaryKeyConfig<T>;
46
+ /** The sort key configuration for the GSI, if any */
47
+ sort?: SortKeyConfig<T>;
26
48
  }
27
- export interface KeysConfig<S extends z.ZodType<any>> {
28
- primary: PrimaryKeyConfig<S>;
29
- sort?: SortKeyConfig<S>;
49
+ /**
50
+ * Keys configuration for the table.
51
+ */
52
+ export interface KeysConfig<T> {
53
+ primary: PrimaryKeyConfig<T>;
54
+ sort?: SortKeyConfig<T>;
30
55
  gsis?: {
31
- [gsiName: string]: GSIConfig<S>;
56
+ [gsiName: string]: GSIConfig<T>;
32
57
  };
33
58
  }
34
- export interface BetterDDBOptions<S extends z.ZodType<any>> {
35
- schema: S;
59
+ /**
60
+ * Options for initializing BetterDDB.
61
+ */
62
+ export interface BetterDDBOptions<T> {
63
+ schema: z.AnyZodObject;
36
64
  tableName: string;
37
65
  entityName: string;
38
- keys: KeysConfig<S>;
39
- client: DynamoDB.DocumentClient;
66
+ keys: KeysConfig<T>;
67
+ client: DynamoDBDocumentClient;
68
+ /**
69
+ * If true, automatically inject timestamp fields:
70
+ * - On create, sets both `createdAt` and `updatedAt`
71
+ * - On update, sets `updatedAt`
72
+ *
73
+ * (T should include these fields if enabled.)
74
+ */
40
75
  autoTimestamps?: boolean;
41
76
  }
42
- export declare class BetterDDB<S extends z.ZodType<any>> {
43
- protected schema: S;
77
+ /**
78
+ * BetterDDB is a definition-based DynamoDB wrapper library.
79
+ */
80
+ export declare class BetterDDB<T> {
81
+ protected schema: z.AnyZodObject;
44
82
  protected tableName: string;
45
83
  protected entityName: string;
46
- protected client: DynamoDB.DocumentClient;
47
- protected keys: KeysConfig<S>;
84
+ protected client: DynamoDBDocumentClient;
85
+ protected keys: KeysConfig<T>;
48
86
  protected autoTimestamps: boolean;
49
- constructor(options: BetterDDBOptions<S>);
50
- getKeys(): KeysConfig<S>;
87
+ constructor(options: BetterDDBOptions<T>);
88
+ getKeys(): KeysConfig<T>;
51
89
  getTableName(): string;
52
- getClient(): DynamoDB.DocumentClient;
53
- getSchema(): S;
90
+ getClient(): DynamoDBDocumentClient;
91
+ getSchema(): z.AnyZodObject;
54
92
  getAutoTimestamps(): boolean;
55
- protected getKeyValue(def: KeyDefinition<S>, rawKey: Partial<SchemaType<S>>): string;
56
- buildKey(rawKey: Partial<SchemaType<S>>): Record<string, any>;
57
- buildIndexes(rawItem: Partial<SchemaType<S>>): Record<string, any>;
58
- create(item: SchemaType<S>): CreateBuilder<SchemaType<S>>;
59
- get(rawKey: Partial<SchemaType<S>>): GetBuilder<SchemaType<S>>;
60
- update(key: Partial<SchemaType<S>>, expectedVersion?: number): UpdateBuilder<SchemaType<S>>;
61
- delete(rawKey: Partial<SchemaType<S>>): DeleteBuilder<SchemaType<S>>;
62
- query(key: Partial<SchemaType<S>>): QueryBuilder<SchemaType<S>>;
63
- scan(): ScanBuilder<SchemaType<S>>;
93
+ protected getKeyValue(def: KeyDefinition<T>, rawKey: Partial<T>): string;
94
+ /**
95
+ * Build the primary key from a raw key object.
96
+ */
97
+ buildKey(rawKey: Partial<T>): Record<string, any>;
98
+ /**
99
+ * Build index attributes for each defined GSI.
100
+ */
101
+ buildIndexes(rawItem: Partial<T>): Record<string, any>;
102
+ /**
103
+ * Create an item:
104
+ * - Computes primary key and index attributes,
105
+ * - Optionally injects timestamps,
106
+ * - Validates the item and writes it to DynamoDB.
107
+ */
108
+ create(item: T): CreateBuilder<T>;
109
+ /**
110
+ * Get an item by its primary key.
111
+ */
112
+ get(rawKey: Partial<T>): GetBuilder<T>;
113
+ /**
114
+ * Update an item.
115
+ */
116
+ update(key: Partial<T>, expectedVersion?: number): UpdateBuilder<T>;
117
+ /**
118
+ * Delete an item.
119
+ */
120
+ delete(rawKey: Partial<T>): DeleteBuilder<T>;
121
+ /**
122
+ * Query items.
123
+ */
124
+ query(key: Partial<T>): QueryBuilder<T>;
125
+ /**
126
+ * Scan for items.
127
+ */
128
+ scan(): ScanBuilder<T>;
64
129
  }
package/lib/betterddb.js CHANGED
@@ -7,15 +7,18 @@ const update_builder_1 = require("./builders/update-builder");
7
7
  const create_builder_1 = require("./builders/create-builder");
8
8
  const get_builder_1 = require("./builders/get-builder");
9
9
  const delete_builder_1 = require("./builders/delete-builder");
10
+ /**
11
+ * BetterDDB is a definition-based DynamoDB wrapper library.
12
+ */
10
13
  class BetterDDB {
11
14
  constructor(options) {
12
15
  var _a;
13
16
  this.schema = options.schema;
14
17
  this.tableName = options.tableName;
15
18
  this.entityName = options.entityName.toUpperCase();
19
+ this.keys = options.keys;
16
20
  this.client = options.client;
17
21
  this.autoTimestamps = (_a = options.autoTimestamps) !== null && _a !== void 0 ? _a : false;
18
- this.keys = options.keys;
19
22
  }
20
23
  getKeys() {
21
24
  return this.keys;
@@ -32,49 +35,106 @@ class BetterDDB {
32
35
  getAutoTimestamps() {
33
36
  return this.autoTimestamps;
34
37
  }
38
+ // Helper: Retrieve the key value from a KeyDefinition.
35
39
  getKeyValue(def, rawKey) {
36
40
  if (typeof def === 'string' || typeof def === 'number' || typeof def === 'symbol') {
37
41
  return String(rawKey[def]);
38
42
  }
39
- return def.build(rawKey);
43
+ else {
44
+ return def.build(rawKey);
45
+ }
40
46
  }
47
+ /**
48
+ * Build the primary key from a raw key object.
49
+ */
41
50
  buildKey(rawKey) {
42
51
  const keyObj = {};
43
- const { primary, sort } = this.keys;
44
- keyObj[primary.name] = this.getKeyValue(primary.definition, rawKey);
45
- if (sort) {
46
- keyObj[sort.name] = this.getKeyValue(sort.definition, rawKey);
52
+ // For primary (partition) key:
53
+ const pkConfig = this.keys.primary;
54
+ keyObj[pkConfig.name] =
55
+ (typeof pkConfig.definition === 'string' ||
56
+ typeof pkConfig.definition === 'number' ||
57
+ typeof pkConfig.definition === 'symbol')
58
+ ? String(rawKey[pkConfig.definition])
59
+ : pkConfig.definition.build(rawKey);
60
+ // For sort key, if defined:
61
+ if (this.keys.sort) {
62
+ const skConfig = this.keys.sort;
63
+ keyObj[skConfig.name] =
64
+ (typeof skConfig.definition === 'string' ||
65
+ typeof skConfig.definition === 'number' ||
66
+ typeof skConfig.definition === 'symbol')
67
+ ? String(rawKey[skConfig.definition])
68
+ : skConfig.definition.build(rawKey);
47
69
  }
48
70
  return keyObj;
49
71
  }
72
+ /**
73
+ * Build index attributes for each defined GSI.
74
+ */
50
75
  buildIndexes(rawItem) {
51
76
  const indexAttributes = {};
52
77
  if (this.keys.gsis) {
53
- Object.entries(this.keys.gsis).forEach(([_, gsiConfig]) => {
54
- const { primary, sort } = gsiConfig;
55
- indexAttributes[primary.name] = this.getKeyValue(primary.definition, rawItem);
56
- if (sort) {
57
- indexAttributes[sort.name] = this.getKeyValue(sort.definition, rawItem);
78
+ for (const gsiName in this.keys.gsis) {
79
+ const gsiConfig = this.keys.gsis[gsiName];
80
+ // Compute primary index attribute.
81
+ const primaryConfig = gsiConfig.primary;
82
+ indexAttributes[primaryConfig.name] =
83
+ (typeof primaryConfig.definition === 'string' ||
84
+ typeof primaryConfig.definition === 'number' ||
85
+ typeof primaryConfig.definition === 'symbol')
86
+ ? String(rawItem[primaryConfig.definition])
87
+ : primaryConfig.definition.build(rawItem);
88
+ // Compute sort index attribute if provided.
89
+ if (gsiConfig.sort) {
90
+ const sortConfig = gsiConfig.sort;
91
+ indexAttributes[sortConfig.name] =
92
+ (typeof sortConfig.definition === 'string' ||
93
+ typeof sortConfig.definition === 'number' ||
94
+ typeof sortConfig.definition === 'symbol')
95
+ ? String(rawItem[sortConfig.definition])
96
+ : sortConfig.definition.build(rawItem);
58
97
  }
59
- });
98
+ }
60
99
  }
61
100
  return indexAttributes;
62
101
  }
102
+ /**
103
+ * Create an item:
104
+ * - Computes primary key and index attributes,
105
+ * - Optionally injects timestamps,
106
+ * - Validates the item and writes it to DynamoDB.
107
+ */
63
108
  create(item) {
64
109
  return new create_builder_1.CreateBuilder(this, item);
65
110
  }
111
+ /**
112
+ * Get an item by its primary key.
113
+ */
66
114
  get(rawKey) {
67
115
  return new get_builder_1.GetBuilder(this, rawKey);
68
116
  }
117
+ /**
118
+ * Update an item.
119
+ */
69
120
  update(key, expectedVersion) {
70
121
  return new update_builder_1.UpdateBuilder(this, key, expectedVersion);
71
122
  }
123
+ /**
124
+ * Delete an item.
125
+ */
72
126
  delete(rawKey) {
73
127
  return new delete_builder_1.DeleteBuilder(this, rawKey);
74
128
  }
129
+ /**
130
+ * Query items.
131
+ */
75
132
  query(key) {
76
133
  return new query_builder_1.QueryBuilder(this, key);
77
134
  }
135
+ /**
136
+ * Scan for items.
137
+ */
78
138
  scan() {
79
139
  return new scan_builder_1.ScanBuilder(this);
80
140
  }
@@ -1,15 +1,14 @@
1
- import { DynamoDB } from 'aws-sdk';
1
+ import { TransactWriteItem } from '@aws-sdk/client-dynamodb';
2
2
  import { BetterDDB } from '../betterddb';
3
- import { z } from 'zod';
4
- export declare class CreateBuilder<S extends z.ZodType<any>> {
3
+ export declare class CreateBuilder<T> {
5
4
  private parent;
6
5
  private item;
7
6
  private extraTransactItems;
8
- constructor(parent: BetterDDB<S>, item: S);
9
- execute(): Promise<S>;
10
- transactWrite(ops: DynamoDB.DocumentClient.TransactWriteItemList | DynamoDB.DocumentClient.TransactWriteItem): this;
11
- toTransactPut(): DynamoDB.DocumentClient.TransactWriteItem;
12
- then<TResult1 = S, TResult2 = never>(onfulfilled?: ((value: S) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
13
- catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<S | TResult>;
14
- finally(onfinally?: (() => void) | null): Promise<S>;
7
+ constructor(parent: BetterDDB<T>, item: T);
8
+ execute(): Promise<T>;
9
+ transactWrite(ops: TransactWriteItem[] | TransactWriteItem): this;
10
+ toTransactPut(): TransactWriteItem;
11
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
12
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
13
+ finally(onfinally?: (() => void) | null): Promise<T>;
15
14
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CreateBuilder = void 0;
4
+ const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
4
5
  class CreateBuilder {
5
6
  constructor(parent, item) {
6
7
  this.parent = parent;
@@ -13,9 +14,9 @@ class CreateBuilder {
13
14
  const myTransactItem = this.toTransactPut();
14
15
  // Combine with extra transaction items.
15
16
  const allItems = [...this.extraTransactItems, myTransactItem];
16
- await this.parent.getClient().transactWrite({
17
+ await this.parent.getClient().send(new lib_dynamodb_1.TransactWriteCommand({
17
18
  TransactItems: allItems
18
- }).promise();
19
+ }));
19
20
  // After transaction, retrieve the updated item.
20
21
  const result = await this.parent.get(this.item).execute();
21
22
  if (result === null) {
@@ -38,10 +39,10 @@ class CreateBuilder {
38
39
  // Compute and merge index attributes.
39
40
  const indexAttributes = this.parent.buildIndexes(validated);
40
41
  finalItem = { ...finalItem, ...indexAttributes };
41
- await this.parent.getClient().put({
42
+ await this.parent.getClient().send(new lib_dynamodb_1.PutCommand({
42
43
  TableName: this.parent.getTableName(),
43
44
  Item: finalItem
44
- }).promise();
45
+ }));
45
46
  return validated;
46
47
  }
47
48
  }
@@ -1,19 +1,18 @@
1
- import { DynamoDB } from 'aws-sdk';
2
1
  import { BetterDDB } from '../betterddb';
3
- import { z } from 'zod';
4
- export declare class DeleteBuilder<S extends z.ZodType<any>> {
2
+ import { TransactWriteItem } from '@aws-sdk/client-dynamodb';
3
+ export declare class DeleteBuilder<T> {
5
4
  private parent;
6
5
  private key;
7
6
  private condition?;
8
7
  private extraTransactItems;
9
- constructor(parent: BetterDDB<S>, key: Partial<S>);
8
+ constructor(parent: BetterDDB<T>, key: Partial<T>);
10
9
  /**
11
10
  * Specify a condition expression for the delete operation.
12
11
  */
13
12
  withCondition(expression: string, attributeValues: Record<string, any>): this;
14
13
  execute(): Promise<void>;
15
- transactWrite(ops: DynamoDB.DocumentClient.TransactWriteItemList | DynamoDB.DocumentClient.TransactWriteItem): this;
16
- toTransactDelete(): DynamoDB.DocumentClient.TransactWriteItem;
14
+ transactWrite(ops: TransactWriteItem[] | TransactWriteItem): this;
15
+ toTransactDelete(): TransactWriteItem;
17
16
  then<TResult1 = void, TResult2 = never>(onfulfilled?: ((value: void) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
18
17
  catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<void | TResult>;
19
18
  finally(onfinally?: (() => void) | null): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeleteBuilder = void 0;
4
+ const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
4
5
  class DeleteBuilder {
5
6
  constructor(parent, key) {
6
7
  this.parent = parent;
@@ -26,9 +27,9 @@ class DeleteBuilder {
26
27
  const myTransactItem = this.toTransactDelete();
27
28
  // Combine with extra transaction items.
28
29
  const allItems = [...this.extraTransactItems, myTransactItem];
29
- await this.parent.getClient().transactWrite({
30
+ await this.parent.getClient().send(new lib_dynamodb_1.TransactWriteCommand({
30
31
  TransactItems: allItems
31
- }).promise();
32
+ }));
32
33
  // After transaction, retrieve the updated item.
33
34
  const result = await this.parent.get(this.key).execute();
34
35
  if (result === null) {
@@ -44,7 +45,7 @@ class DeleteBuilder {
44
45
  params.ConditionExpression = this.condition.expression;
45
46
  params.ExpressionAttributeValues = this.condition.attributeValues;
46
47
  }
47
- await this.parent.getClient().delete(params).promise();
48
+ await this.parent.getClient().send(new lib_dynamodb_1.DeleteCommand(params));
48
49
  }
49
50
  }
50
51
  transactWrite(ops) {
@@ -1,21 +1,20 @@
1
- import { DynamoDB } from 'aws-sdk';
2
1
  import { BetterDDB } from '../betterddb';
3
- import { z } from 'zod';
4
- export declare class GetBuilder<S extends z.ZodType<any>> {
2
+ import { TransactGetItem } from '@aws-sdk/client-dynamodb';
3
+ export declare class GetBuilder<T> {
5
4
  private parent;
6
5
  private key;
7
6
  private projectionExpression?;
8
7
  private expressionAttributeNames;
9
8
  private extraTransactItems;
10
- constructor(parent: BetterDDB<S>, key: Partial<S>);
9
+ constructor(parent: BetterDDB<T>, key: Partial<T>);
11
10
  /**
12
11
  * Specify a projection by providing an array of attribute names.
13
12
  */
14
- withProjection(attributes: (keyof S)[]): this;
15
- execute(): Promise<S | null>;
16
- transactGet(ops: DynamoDB.DocumentClient.TransactGetItemList | DynamoDB.DocumentClient.TransactGetItem): this;
17
- toTransactGet(): DynamoDB.DocumentClient.TransactGetItem;
18
- then<TResult1 = S | null, TResult2 = never>(onfulfilled?: ((value: S | null) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
19
- catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<S | null | TResult>;
20
- finally(onfinally?: (() => void) | null): Promise<S | null>;
13
+ withProjection(attributes: (keyof T)[]): this;
14
+ execute(): Promise<T | null>;
15
+ transactGet(ops: TransactGetItem[] | TransactGetItem): this;
16
+ toTransactGet(): TransactGetItem;
17
+ then<TResult1 = T | null, TResult2 = never>(onfulfilled?: ((value: T | null) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
18
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | null | TResult>;
19
+ finally(onfinally?: (() => void) | null): Promise<T | null>;
21
20
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetBuilder = void 0;
4
+ const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
4
5
  class GetBuilder {
5
6
  constructor(parent, key) {
6
7
  this.parent = parent;
@@ -24,9 +25,9 @@ class GetBuilder {
24
25
  const myTransactItem = this.toTransactGet();
25
26
  // Combine with extra transaction items.
26
27
  const allItems = [...this.extraTransactItems, myTransactItem];
27
- await this.parent.getClient().transactGet({
28
+ await this.parent.getClient().send(new lib_dynamodb_1.TransactGetCommand({
28
29
  TransactItems: allItems
29
- }).promise();
30
+ }));
30
31
  // After transaction, retrieve the updated item.
31
32
  const result = await this.parent.get(this.key).execute();
32
33
  return result;
@@ -40,7 +41,7 @@ class GetBuilder {
40
41
  params.ProjectionExpression = this.projectionExpression;
41
42
  params.ExpressionAttributeNames = this.expressionAttributeNames;
42
43
  }
43
- const result = await this.parent.getClient().get(params).promise();
44
+ const result = await this.parent.getClient().send(new lib_dynamodb_1.GetCommand(params));
44
45
  if (!result.Item)
45
46
  return null;
46
47
  return this.parent.getSchema().parse(result.Item);
@@ -1,6 +1,5 @@
1
1
  import { BetterDDB } from '../betterddb';
2
- import { z } from 'zod';
3
- export declare class QueryBuilder<S extends z.ZodType<any>> {
2
+ export declare class QueryBuilder<T> {
4
3
  private parent;
5
4
  private key;
6
5
  private filters;
@@ -11,18 +10,18 @@ export declare class QueryBuilder<S extends z.ZodType<any>> {
11
10
  private limit?;
12
11
  private lastKey?;
13
12
  private ascending;
14
- constructor(parent: BetterDDB<S>, key: Partial<S>);
13
+ constructor(parent: BetterDDB<T>, key: Partial<T>);
15
14
  usingIndex(indexName: string): this;
16
15
  sortAscending(): this;
17
16
  sortDescending(): this;
18
- where(attribute: keyof S, operator: 'eq' | 'begins_with' | 'between', values: any | [any, any]): this;
17
+ where(attribute: keyof T, operator: 'eq' | 'begins_with' | 'between', values: any | [any, any]): this;
19
18
  limitResults(limit: number): this;
20
19
  startFrom(lastKey: Record<string, any>): this;
21
20
  /**
22
21
  * Executes the query and returns a Promise that resolves with an array of items.
23
22
  */
24
- execute(): Promise<S[]>;
25
- then<TResult1 = S[], TResult2 = never>(onfulfilled?: ((value: S[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
26
- catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<S[] | TResult>;
27
- finally(onfinally?: (() => void) | null): Promise<S[]>;
23
+ execute(): Promise<T[]>;
24
+ then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
25
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T[] | TResult>;
26
+ finally(onfinally?: (() => void) | null): Promise<T[]>;
28
27
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QueryBuilder = void 0;
4
+ const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
4
5
  class QueryBuilder {
5
6
  constructor(parent, key) {
6
7
  this.parent = parent;
@@ -89,7 +90,7 @@ class QueryBuilder {
89
90
  if (this.filters.length > 0) {
90
91
  params.FilterExpression = this.filters.join(' AND ');
91
92
  }
92
- const result = await this.parent.getClient().query(params).promise();
93
+ const result = await this.parent.getClient().send(new lib_dynamodb_1.QueryCommand(params));
93
94
  return this.parent.getSchema().array().parse(result.Items);
94
95
  }
95
96
  // Thenable implementation.
@@ -1,21 +1,20 @@
1
1
  import { BetterDDB } from '../betterddb';
2
- import { z } from 'zod';
3
- export declare class ScanBuilder<S extends z.ZodType<any>> {
2
+ export declare class ScanBuilder<T> {
4
3
  private parent;
5
4
  private filters;
6
5
  private expressionAttributeNames;
7
6
  private expressionAttributeValues;
8
7
  private limit?;
9
8
  private lastKey?;
10
- constructor(parent: BetterDDB<S>);
11
- where(attribute: keyof S, operator: 'eq' | 'begins_with' | 'between', values: any | [any, any]): this;
9
+ constructor(parent: BetterDDB<T>);
10
+ where(attribute: keyof T, operator: 'eq' | 'begins_with' | 'between', values: any | [any, any]): this;
12
11
  limitResults(limit: number): this;
13
12
  startFrom(lastKey: Record<string, any>): this;
14
13
  /**
15
14
  * Executes the scan and returns a Promise that resolves with an array of items.
16
15
  */
17
- execute(): Promise<S[]>;
18
- then<TResult1 = S[], TResult2 = never>(onfulfilled?: ((value: S[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
19
- catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<S[] | TResult>;
20
- finally(onfinally?: (() => void) | null): Promise<S[]>;
16
+ execute(): Promise<T[]>;
17
+ then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
18
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T[] | TResult>;
19
+ finally(onfinally?: (() => void) | null): Promise<T[]>;
21
20
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ScanBuilder = void 0;
4
+ const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
4
5
  class ScanBuilder {
5
6
  constructor(parent) {
6
7
  this.parent = parent;
@@ -59,7 +60,7 @@ class ScanBuilder {
59
60
  if (this.filters.length > 0) {
60
61
  params.FilterExpression = this.filters.join(' AND ');
61
62
  }
62
- const result = await this.parent.getClient().scan(params).promise();
63
+ const result = await this.parent.getClient().send(new lib_dynamodb_1.ScanCommand(params));
63
64
  return this.parent.getSchema().array().parse(result.Items);
64
65
  }
65
66
  // Thenable implementation.
@@ -1,18 +1,17 @@
1
- import { DynamoDB } from 'aws-sdk';
2
1
  import { BetterDDB } from '../betterddb';
3
- import { z } from 'zod';
4
- export declare class UpdateBuilder<S extends z.ZodType<any>> {
2
+ import { TransactWriteItem } from '@aws-sdk/client-dynamodb';
3
+ export declare class UpdateBuilder<T> {
5
4
  private parent;
6
5
  private key;
7
6
  private actions;
8
7
  private condition?;
9
8
  private expectedVersion?;
10
9
  private extraTransactItems;
11
- constructor(parent: BetterDDB<S>, key: Partial<S>, expectedVersion?: number);
12
- set(attrs: Partial<S>): this;
13
- remove(attrs: (keyof S)[]): this;
14
- add(attrs: Partial<Record<keyof S, number | Set<any>>>): this;
15
- delete(attrs: Partial<Record<keyof S, Set<any>>>): this;
10
+ constructor(parent: BetterDDB<T>, key: Partial<T>, expectedVersion?: number);
11
+ set(attrs: Partial<T>): this;
12
+ remove(attrs: (keyof T)[]): this;
13
+ add(attrs: Partial<Record<keyof T, number | Set<any>>>): this;
14
+ delete(attrs: Partial<Record<keyof T, Set<any>>>): this;
16
15
  /**
17
16
  * Adds a condition expression to the update.
18
17
  */
@@ -20,7 +19,7 @@ export declare class UpdateBuilder<S extends z.ZodType<any>> {
20
19
  /**
21
20
  * Specifies additional transaction items to include when executing this update as a transaction.
22
21
  */
23
- transactWrite(ops: DynamoDB.DocumentClient.TransactWriteItemList | DynamoDB.DocumentClient.TransactWriteItem): this;
22
+ transactWrite(ops: TransactWriteItem[] | TransactWriteItem): this;
24
23
  /**
25
24
  * Builds the update expression and associated maps.
26
25
  */
@@ -28,9 +27,9 @@ export declare class UpdateBuilder<S extends z.ZodType<any>> {
28
27
  /**
29
28
  * Returns a transaction update item that can be included in a transactWrite call.
30
29
  */
31
- toTransactUpdate(): DynamoDB.DocumentClient.TransactWriteItem;
30
+ toTransactUpdate(): TransactWriteItem;
32
31
  /**
33
32
  * Commits the update immediately by calling the parent's update method.
34
33
  */
35
- execute(): Promise<S>;
34
+ execute(): Promise<T>;
36
35
  }