dyno-table 2.5.1 → 2.6.0

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.
Files changed (58) hide show
  1. package/dist/builders/batch-builder.d.ts +249 -0
  2. package/dist/builders/builder-types.d.ts +123 -0
  3. package/dist/builders/condition-check-builder.d.ts +149 -0
  4. package/dist/builders/delete-builder.d.ts +208 -0
  5. package/dist/builders/entity-aware-builders.d.ts +127 -0
  6. package/dist/builders/filter-builder.d.ts +294 -0
  7. package/dist/builders/get-builder.d.ts +191 -0
  8. package/dist/builders/index.d.ts +14 -0
  9. package/dist/builders/paginator.d.ts +151 -0
  10. package/dist/builders/put-builder.d.ts +317 -0
  11. package/dist/builders/query-builder.d.ts +218 -0
  12. package/dist/builders/result-iterator.d.ts +55 -0
  13. package/dist/builders/scan-builder.d.ts +109 -0
  14. package/dist/builders/transaction-builder.d.ts +462 -0
  15. package/dist/builders/types.d.ts +25 -0
  16. package/dist/builders/update-builder.d.ts +372 -0
  17. package/dist/builders.d.ts +1 -4
  18. package/dist/{chunk-U6MQGB6Y.js → chunk-JZB6TYST.js} +133 -136
  19. package/dist/{chunk-ZXM6LPRV.cjs → chunk-Z334X72N.cjs} +133 -136
  20. package/dist/conditions.d.ts +705 -3
  21. package/dist/entity/ddb-indexing.d.ts +45 -0
  22. package/dist/entity/entity.d.ts +188 -0
  23. package/dist/entity/index-utils.d.ts +24 -0
  24. package/dist/entity.cjs +4 -4
  25. package/dist/entity.d.ts +1 -261
  26. package/dist/entity.js +1 -1
  27. package/dist/errors.d.ts +212 -0
  28. package/dist/expression.d.ts +9 -0
  29. package/dist/index-definition.d.ts +10 -0
  30. package/dist/index.cjs +25 -25
  31. package/dist/index.d.ts +16 -273
  32. package/dist/index.js +1 -1
  33. package/dist/operation-types.d.ts +8 -0
  34. package/dist/standard-schema.d.ts +2 -4
  35. package/dist/table.d.ts +13 -8
  36. package/dist/types.d.ts +6 -9
  37. package/dist/utils/chunk-array.d.ts +9 -0
  38. package/dist/utils/debug-expression.d.ts +32 -0
  39. package/dist/utils/debug-transaction.d.ts +17 -0
  40. package/dist/utils/error-factory.d.ts +162 -0
  41. package/dist/utils/error-utils.d.ts +170 -0
  42. package/dist/utils/index.d.ts +7 -0
  43. package/dist/utils/partition-key-template.d.ts +30 -0
  44. package/dist/utils/sort-key-template.d.ts +33 -0
  45. package/dist/utils.d.ts +1 -66
  46. package/package.json +12 -10
  47. package/dist/builders.d.cts +0 -4
  48. package/dist/conditions-BSAcZswY.d.ts +0 -731
  49. package/dist/conditions-C8bM__Pn.d.cts +0 -731
  50. package/dist/conditions.d.cts +0 -3
  51. package/dist/entity.d.cts +0 -261
  52. package/dist/index-Bc-ra0im.d.ts +0 -3042
  53. package/dist/index-CPCmWsEv.d.cts +0 -3042
  54. package/dist/index.d.cts +0 -273
  55. package/dist/standard-schema.d.cts +0 -57
  56. package/dist/table.d.cts +0 -165
  57. package/dist/types.d.cts +0 -29
  58. package/dist/utils.d.cts +0 -66
@@ -0,0 +1,45 @@
1
+ import type { Table } from "../table";
2
+ import type { DynamoItem } from "../types";
3
+ import type { IndexDefinition } from "./entity";
4
+ /**
5
+ * Helper class for building indexes for DynamoDB operations
6
+ */
7
+ export declare class IndexBuilder<T extends DynamoItem> {
8
+ private readonly table;
9
+ private readonly indexes;
10
+ /**
11
+ * Creates a new IndexBuilder instance
12
+ *
13
+ * @param table - The DynamoDB table instance
14
+ * @param indexes - The index definitions
15
+ */
16
+ constructor(table: Table, indexes?: Record<string, IndexDefinition<T>>);
17
+ /**
18
+ * Build index attributes for item creation
19
+ *
20
+ * @param item - The item to generate indexes for
21
+ * @param options - Options for building indexes
22
+ * @returns Record of GSI attribute names to their values
23
+ */
24
+ buildForCreate(item: T, options?: {
25
+ excludeReadOnly?: boolean;
26
+ }): Record<string, string>;
27
+ /**
28
+ * Build index attributes for item updates
29
+ *
30
+ * @param currentData - The current data before update
31
+ * @param updates - The update data
32
+ * @param options - Options for building indexes
33
+ * @returns Record of GSI attribute names to their updated values
34
+ */
35
+ buildForUpdate(currentData: T, updates: Partial<T>, options?: {
36
+ forceRebuildIndexes?: string[];
37
+ }): Record<string, string>;
38
+ /**
39
+ * Check if a key has undefined values
40
+ *
41
+ * @param key - The index key to check
42
+ * @returns True if the key contains undefined values, false otherwise
43
+ */
44
+ private hasUndefinedValues;
45
+ }
@@ -0,0 +1,188 @@
1
+ import type { DeleteBuilder, GetBuilder, Path, PathType, PutBuilder, QueryBuilder, ScanBuilder, TransactionBuilder, UpdateBuilder, UpdateCommandParams } from "../builders";
2
+ import { type Condition, type ConditionOperator, type PrimaryKey, type PrimaryKeyWithoutExpression } from "../conditions";
3
+ import type { StandardSchemaV1 } from "../standard-schema";
4
+ import type { Table } from "../table";
5
+ import type { DynamoItem, Index, TableConfig } from "../types";
6
+ export type QueryFunction<_T extends DynamoItem, I, R> = (input: I) => R;
7
+ export type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R> & {
8
+ schema?: StandardSchemaV1<I>;
9
+ };
10
+ export type QueryRecord<T extends DynamoItem> = {
11
+ [K: string]: QueryFunctionWithSchema<T, any, any>;
12
+ };
13
+ export type MappedQueries<T extends DynamoItem, Q extends QueryRecord<T>> = {
14
+ [K in keyof Q]: Q[K] extends QueryFunctionWithSchema<T, infer I, infer R> ? (input: I) => R : never;
15
+ };
16
+ export type QueryEntity<T extends DynamoItem> = {
17
+ scan: () => ScanBuilder<T>;
18
+ get: (key: PrimaryKeyWithoutExpression) => EntityGetBuilder<T>;
19
+ query: (keyCondition: PrimaryKey) => QueryBuilder<T, TableConfig>;
20
+ };
21
+ type SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;
22
+ type PathSetElementType<T, K extends Path<T>> = SetElementType<PathType<T, K>>;
23
+ export type EntityPutBuilder<T extends DynamoItem> = PutBuilder<T> & {
24
+ readonly entityName: string;
25
+ };
26
+ export type EntityGetBuilder<T extends DynamoItem> = GetBuilder<T> & {
27
+ readonly entityName: string;
28
+ };
29
+ export type EntityDeleteBuilder = DeleteBuilder & {
30
+ readonly entityName: string;
31
+ };
32
+ export type EntityUpdateBuilder<T extends DynamoItem> = {
33
+ readonly entityName: string;
34
+ set(values: Partial<T>): EntityUpdateBuilder<T>;
35
+ set<K extends Path<T>>(path: K, value: PathType<T, K>): EntityUpdateBuilder<T>;
36
+ remove<K extends Path<T>>(path: K): EntityUpdateBuilder<T>;
37
+ add<K extends Path<T>>(path: K, value: PathType<T, K>): EntityUpdateBuilder<T>;
38
+ deleteElementsFromSet<K extends Path<T>>(path: K, value: PathSetElementType<T, K>[] | Set<PathSetElementType<T, K>>): EntityUpdateBuilder<T>;
39
+ condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): EntityUpdateBuilder<T>;
40
+ returnValues(returnValues: "ALL_NEW" | "UPDATED_NEW" | "ALL_OLD" | "UPDATED_OLD" | "NONE"): EntityUpdateBuilder<T>;
41
+ toDynamoCommand(): UpdateCommandParams;
42
+ withTransaction(transaction: TransactionBuilder): void;
43
+ debug(): ReturnType<UpdateBuilder<T>["debug"]>;
44
+ execute(): Promise<{
45
+ item?: T;
46
+ }>;
47
+ forceIndexRebuild(indexes: string | string[]): EntityUpdateBuilder<T>;
48
+ getForceRebuildIndexes(): string[];
49
+ };
50
+ interface Settings {
51
+ /**
52
+ * Defaults to "entityType"
53
+ */
54
+ entityTypeAttributeName?: string;
55
+ timestamps?: {
56
+ createdAt?: {
57
+ /**
58
+ * ISO vs Unix trade-offs
59
+ *
60
+ * Both options support between, greater than and less than comparisons.
61
+ *
62
+ * ISO:
63
+ * - Human readable, but requires more storage space
64
+ * - Does not work with DynamoDBs TTL feature.
65
+ *
66
+ * UNIX:
67
+ * - Less readable, but requires less storage space.
68
+ * - Works with DynamoDBs TTL feature.
69
+ */
70
+ format: "ISO" | "UNIX";
71
+ /**
72
+ * Defaults to "createdAt"
73
+ */
74
+ attributeName?: string;
75
+ };
76
+ updatedAt?: {
77
+ /**
78
+ * ISO vs Unix trade-offs
79
+ *
80
+ * Both options support between, greater than and less than comparisons.
81
+ *
82
+ * ISO:
83
+ * - Human readable, but requires more storage space
84
+ * - Does not work with DynamoDBs TTL feature.
85
+ *
86
+ * UNIX:
87
+ * - Less readable, but requires less storage space.
88
+ * - Works with DynamoDBs TTL feature.
89
+ */
90
+ format: "ISO" | "UNIX";
91
+ /**
92
+ * Defaults to "updatedAt"
93
+ */
94
+ attributeName?: string;
95
+ };
96
+ };
97
+ }
98
+ export interface EntityConfig<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
99
+ name: string;
100
+ schema: StandardSchemaV1<TInput, T>;
101
+ primaryKey: IndexDefinition<I>;
102
+ indexes?: Record<string, IndexDefinition<T>>;
103
+ queries: Q;
104
+ settings?: Settings;
105
+ }
106
+ export interface EntityRepository<
107
+ /**
108
+ * The Entity Type (output type)
109
+ */
110
+ T extends DynamoItem,
111
+ /**
112
+ * The Input Type (for create operations)
113
+ */
114
+ TInput extends DynamoItem = T,
115
+ /**
116
+ * The Primary Index (Partition index) Type
117
+ */
118
+ I extends DynamoItem = T,
119
+ /**
120
+ * The Queries object
121
+ */
122
+ Q extends QueryRecord<T> = QueryRecord<T>> {
123
+ create: (data: TInput) => EntityPutBuilder<T>;
124
+ upsert: (data: TInput & I) => EntityPutBuilder<T>;
125
+ get: (key: I) => EntityGetBuilder<T>;
126
+ update: (key: I, data: Partial<T>) => EntityUpdateBuilder<T>;
127
+ delete: (key: I) => EntityDeleteBuilder;
128
+ query: MappedQueries<T, Q>;
129
+ scan: () => ScanBuilder<T>;
130
+ }
131
+ export interface EntityDefinition<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
132
+ name: string;
133
+ createRepository: (table: Table) => EntityRepository<T, TInput, I, Q>;
134
+ }
135
+ /**
136
+ * Creates an entity definition with type-safe operations
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * interface User {
141
+ * id: string;
142
+ * name: string;
143
+ * }
144
+ *
145
+ * const UserEntity = defineEntity<User>({
146
+ * name: "User",
147
+ * schema: userSchema,
148
+ * primaryKey: primaryKey,
149
+ * });
150
+ * ```
151
+ */
152
+ export declare function defineEntity<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(config: EntityConfig<T, TInput, I, Q>): EntityDefinition<T, TInput, I, Q>;
153
+ export declare function createQueries<T extends DynamoItem>(): {
154
+ input: <I>(schema: StandardSchemaV1<I>) => {
155
+ query: <R extends ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>(handler: (params: {
156
+ input: I;
157
+ entity: QueryEntity<T>;
158
+ }) => R) => QueryFunctionWithSchema<T, I, R>;
159
+ };
160
+ };
161
+ /**
162
+ * Defines a DynamoDB index configuration
163
+ */
164
+ export interface IndexDefinition<T extends DynamoItem> extends Index<T> {
165
+ /** The name of the index */
166
+ name: string;
167
+ /** Whether the index is read-only */
168
+ isReadOnly: boolean;
169
+ /** Function to generate the index key from an item */
170
+ generateKey: (item: T) => {
171
+ pk: string;
172
+ sk?: string;
173
+ };
174
+ }
175
+ export declare function createIndex(): {
176
+ input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => {
177
+ partitionKey: <P extends (item: T) => string>(pkFn: P) => {
178
+ sortKey: <S extends (item: T) => string>(skFn: S) => IndexDefinition<T> & {
179
+ readOnly: (value?: boolean) => IndexDefinition<T>;
180
+ };
181
+ withoutSortKey: () => IndexDefinition<T> & {
182
+ readOnly: (value?: boolean) => IndexDefinition<T>;
183
+ };
184
+ };
185
+ readOnly: (value?: boolean) => /*elided*/ any;
186
+ };
187
+ };
188
+ export {};
@@ -0,0 +1,24 @@
1
+ import type { Table } from "../table";
2
+ import type { DynamoItem } from "../types";
3
+ import type { IndexDefinition } from "./entity";
4
+ /**
5
+ * Builds secondary indexes for an item based on the configured indexes
6
+ *
7
+ * @param dataForKeyGeneration - The validated data to generate keys from
8
+ * @param table - The DynamoDB table instance containing GSI configurations
9
+ * @param indexes - The index definitions
10
+ * @param excludeReadOnly - Whether to exclude read-only indexes
11
+ * @returns Record of GSI attribute names to their values
12
+ */
13
+ export declare function buildIndexes<T extends DynamoItem>(dataForKeyGeneration: T, table: Table, indexes: Record<string, IndexDefinition<T>> | undefined, excludeReadOnly?: boolean): Record<string, string>;
14
+ /**
15
+ * Builds index updates for an item based on the configured indexes
16
+ *
17
+ * @param currentData - The current data before update
18
+ * @param updates - The update data
19
+ * @param table - The DynamoDB table instance containing GSI configurations
20
+ * @param indexes - The index definitions
21
+ * @param forceRebuildIndexes - Array of index names to force rebuild even if readonly
22
+ * @returns Record of GSI attribute names to their updated values
23
+ */
24
+ export declare function buildIndexUpdates<T extends DynamoItem>(currentData: T, updates: Partial<T>, table: Table, indexes: Record<string, IndexDefinition<T>> | undefined, forceRebuildIndexes?: string[]): Record<string, string>;
package/dist/entity.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkZXM6LPRV_cjs = require('./chunk-ZXM6LPRV.cjs');
3
+ var chunkZ334X72N_cjs = require('./chunk-Z334X72N.cjs');
4
4
  require('./chunk-ELULXDSB.cjs');
5
5
  require('./chunk-7UJJ7JXM.cjs');
6
6
 
@@ -8,13 +8,13 @@ require('./chunk-7UJJ7JXM.cjs');
8
8
 
9
9
  Object.defineProperty(exports, "createIndex", {
10
10
  enumerable: true,
11
- get: function () { return chunkZXM6LPRV_cjs.createIndex; }
11
+ get: function () { return chunkZ334X72N_cjs.createIndex; }
12
12
  });
13
13
  Object.defineProperty(exports, "createQueries", {
14
14
  enumerable: true,
15
- get: function () { return chunkZXM6LPRV_cjs.createQueries; }
15
+ get: function () { return chunkZ334X72N_cjs.createQueries; }
16
16
  });
17
17
  Object.defineProperty(exports, "defineEntity", {
18
18
  enumerable: true,
19
- get: function () { return chunkZXM6LPRV_cjs.defineEntity; }
19
+ get: function () { return chunkZ334X72N_cjs.defineEntity; }
20
20
  });
package/dist/entity.d.ts CHANGED
@@ -1,261 +1 @@
1
- import { s as Path, t as PathType, b as Condition, c as ConditionOperator, P as PrimaryKeyWithoutExpression, a as PrimaryKey } from './conditions-BSAcZswY.js';
2
- import { P as PutBuilder, G as GetBuilder, U as UpdateBuilder, p as UpdateCommandParams, T as TransactionBuilder, D as DeleteBuilder, S as ScanBuilder, Q as QueryBuilder } from './index-Bc-ra0im.js';
3
- import { StandardSchemaV1 } from './standard-schema.js';
4
- import { Table } from './table.js';
5
- import { DynamoItem, Index, TableConfig } from './types.js';
6
- import '@aws-sdk/lib-dynamodb';
7
-
8
- type SetElementType<T> = T extends Set<infer U> ? U : T extends Array<infer U> ? U : never;
9
- type PathSetElementType<T, K extends Path<T>> = SetElementType<PathType<T, K>>;
10
- /**
11
- * Entity-aware wrapper for PutBuilder that automatically provides entity name to batch operations
12
- */
13
- type EntityAwarePutBuilder<T extends DynamoItem> = PutBuilder<T> & {
14
- readonly entityName: string;
15
- };
16
- /**
17
- * Entity-aware wrapper for GetBuilder that automatically provides entity name to batch operations
18
- */
19
- type EntityAwareGetBuilder<T extends DynamoItem> = GetBuilder<T> & {
20
- readonly entityName: string;
21
- };
22
- /**
23
- * Entity-aware wrapper for DeleteBuilder that automatically provides entity name to batch operations
24
- */
25
- type EntityAwareDeleteBuilder = DeleteBuilder & {
26
- readonly entityName: string;
27
- };
28
- /**
29
- * Entity-aware wrapper for UpdateBuilder that adds forceIndexRebuild functionality
30
- * and automatically provides entity name to batch operations
31
- */
32
- declare class EntityAwareUpdateBuilder<T extends DynamoItem> {
33
- private forceRebuildIndexes;
34
- readonly entityName: string;
35
- private builder;
36
- private entityConfig?;
37
- private updateDataApplied;
38
- constructor(builder: UpdateBuilder<T>, entityName: string);
39
- /**
40
- * Configure entity-specific logic for automatic timestamp generation and index updates
41
- */
42
- configureEntityLogic(config: {
43
- data: Partial<T>;
44
- key: T;
45
- table: Table;
46
- indexes: Record<string, IndexDefinition<T>> | undefined;
47
- generateTimestamps: () => Record<string, string | number>;
48
- buildIndexUpdates: (currentData: T, updates: Partial<T>, table: Table, indexes: Record<string, IndexDefinition<T>> | undefined, forceRebuildIndexes?: string[]) => Record<string, string>;
49
- }): void;
50
- /**
51
- * Forces a rebuild of one or more readonly indexes during the update operation.
52
- *
53
- * By default, readonly indexes are not updated during entity updates to prevent
54
- * errors when required index attributes are missing. This method allows you to
55
- * override that behavior and force specific indexes to be rebuilt.
56
- *
57
- * @example
58
- * ```typescript
59
- * // Force rebuild a single readonly index
60
- * const result = await repo.update({ id: 'TREX-001' }, { status: 'ACTIVE' })
61
- * .forceIndexRebuild('gsi1')
62
- * .execute();
63
- *
64
- * // Force rebuild multiple readonly indexes
65
- * const result = await repo.update({ id: 'TREX-001' }, { status: 'ACTIVE' })
66
- * .forceIndexRebuild(['gsi1', 'gsi2'])
67
- * .execute();
68
- *
69
- * // Chain with other update operations
70
- * const result = await repo.update({ id: 'TREX-001' }, { status: 'ACTIVE' })
71
- * .set('lastUpdated', new Date().toISOString())
72
- * .forceIndexRebuild('gsi1')
73
- * .condition(op => op.eq('status', 'INACTIVE'))
74
- * .execute();
75
- * ```
76
- *
77
- * @param indexes - A single index name or array of index names to force rebuild
78
- * @returns The builder instance for method chaining
79
- */
80
- forceIndexRebuild(indexes: string | string[]): this;
81
- /**
82
- * Gets the list of indexes that should be force rebuilt.
83
- * This is used internally by entity update logic.
84
- *
85
- * @returns Array of index names to force rebuild
86
- */
87
- getForceRebuildIndexes(): string[];
88
- /**
89
- * Apply entity-specific update data (timestamps and index updates)
90
- * This is called automatically when needed
91
- */
92
- private applyEntityUpdates;
93
- set(values: Partial<T>): this;
94
- set<K extends Path<T>>(path: K, value: PathType<T, K>): this;
95
- remove<K extends Path<T>>(path: K): this;
96
- add<K extends Path<T>>(path: K, value: PathType<T, K>): this;
97
- deleteElementsFromSet<K extends Path<T>>(path: K, value: PathSetElementType<T, K>[] | Set<PathSetElementType<T, K>>): this;
98
- condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
99
- returnValues(returnValues: "ALL_NEW" | "UPDATED_NEW" | "ALL_OLD" | "UPDATED_OLD" | "NONE"): this;
100
- toDynamoCommand(): UpdateCommandParams;
101
- withTransaction(transaction: TransactionBuilder): void;
102
- debug(): ReturnType<UpdateBuilder<T>["debug"]>;
103
- execute(): Promise<{
104
- item?: T;
105
- }>;
106
- }
107
-
108
- type QueryFunction<_T extends DynamoItem, I, R> = (input: I) => R;
109
- type QueryFunctionWithSchema<T extends DynamoItem, I, R> = QueryFunction<T, I, R> & {
110
- schema?: StandardSchemaV1<I>;
111
- };
112
- type QueryRecord<T extends DynamoItem> = {
113
- [K: string]: QueryFunctionWithSchema<T, any, any>;
114
- };
115
- type MappedQueries<T extends DynamoItem, Q extends QueryRecord<T>> = {
116
- [K in keyof Q]: Q[K] extends QueryFunctionWithSchema<T, infer I, infer R> ? (input: I) => R : never;
117
- };
118
- type QueryEntity<T extends DynamoItem> = {
119
- scan: () => ScanBuilder<T>;
120
- get: (key: PrimaryKeyWithoutExpression) => EntityAwareGetBuilder<T>;
121
- query: (keyCondition: PrimaryKey) => QueryBuilder<T, TableConfig>;
122
- };
123
- interface Settings {
124
- /**
125
- * Defaults to "entityType"
126
- */
127
- entityTypeAttributeName?: string;
128
- timestamps?: {
129
- createdAt?: {
130
- /**
131
- * ISO vs Unix trade-offs
132
- *
133
- * Both options support between, greater than and less than comparisons.
134
- *
135
- * ISO:
136
- * - Human readable, but requires more storage space
137
- * - Does not work with DynamoDBs TTL feature.
138
- *
139
- * UNIX:
140
- * - Less readable, but requires less storage space.
141
- * - Works with DynamoDBs TTL feature.
142
- */
143
- format: "ISO" | "UNIX";
144
- /**
145
- * Defaults to "createdAt"
146
- */
147
- attributeName?: string;
148
- };
149
- updatedAt?: {
150
- /**
151
- * ISO vs Unix trade-offs
152
- *
153
- * Both options support between, greater than and less than comparisons.
154
- *
155
- * ISO:
156
- * - Human readable, but requires more storage space
157
- * - Does not work with DynamoDBs TTL feature.
158
- *
159
- * UNIX:
160
- * - Less readable, but requires less storage space.
161
- * - Works with DynamoDBs TTL feature.
162
- */
163
- format: "ISO" | "UNIX";
164
- /**
165
- * Defaults to "updatedAt"
166
- */
167
- attributeName?: string;
168
- };
169
- };
170
- }
171
- interface EntityConfig<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>> {
172
- name: string;
173
- schema: StandardSchemaV1<TInput, T>;
174
- primaryKey: IndexDefinition<I>;
175
- indexes?: Record<string, IndexDefinition<T>>;
176
- queries: Q;
177
- settings?: Settings;
178
- }
179
- interface EntityRepository<
180
- /**
181
- * The Entity Type (output type)
182
- */
183
- T extends DynamoItem,
184
- /**
185
- * The Input Type (for create operations)
186
- */
187
- TInput extends DynamoItem = T,
188
- /**
189
- * The Primary Index (Partition index) Type
190
- */
191
- I extends DynamoItem = T,
192
- /**
193
- * The Queries object
194
- */
195
- Q extends QueryRecord<T> = QueryRecord<T>> {
196
- create: (data: TInput) => EntityAwarePutBuilder<T>;
197
- upsert: (data: TInput & I) => EntityAwarePutBuilder<T>;
198
- get: (key: I) => EntityAwareGetBuilder<T>;
199
- update: (key: I, data: Partial<T>) => EntityAwareUpdateBuilder<T>;
200
- delete: (key: I) => EntityAwareDeleteBuilder;
201
- query: MappedQueries<T, Q>;
202
- scan: () => ScanBuilder<T>;
203
- }
204
- /**
205
- * Creates an entity definition with type-safe operations
206
- *
207
- * @example
208
- * ```typescript
209
- * interface User {
210
- * id: string;
211
- * name: string;
212
- * }
213
- *
214
- * const UserEntity = defineEntity<User>({
215
- * name: "User",
216
- * schema: userSchema,
217
- * primaryKey: primaryKey,
218
- * });
219
- * ```
220
- */
221
- declare function defineEntity<T extends DynamoItem, TInput extends DynamoItem = T, I extends DynamoItem = T, Q extends QueryRecord<T> = QueryRecord<T>>(config: EntityConfig<T, TInput, I, Q>): {
222
- name: string;
223
- createRepository: (table: Table) => EntityRepository<T, TInput, I, Q>;
224
- };
225
- declare function createQueries<T extends DynamoItem>(): {
226
- input: <I>(schema: StandardSchemaV1<I>) => {
227
- query: <R extends ScanBuilder<T> | QueryBuilder<T, TableConfig> | GetBuilder<T>>(handler: (params: {
228
- input: I;
229
- entity: QueryEntity<T>;
230
- }) => R) => QueryFunctionWithSchema<T, I, R>;
231
- };
232
- };
233
- /**
234
- * Defines a DynamoDB index configuration
235
- */
236
- interface IndexDefinition<T extends DynamoItem> extends Index<T> {
237
- /** The name of the index */
238
- name: string;
239
- /** Whether the index is read-only */
240
- isReadOnly: boolean;
241
- /** Function to generate the index key from an item */
242
- generateKey: (item: T) => {
243
- pk: string;
244
- sk?: string;
245
- };
246
- }
247
- declare function createIndex(): {
248
- input: <T extends DynamoItem>(schema: StandardSchemaV1<T>) => {
249
- partitionKey: <P extends (item: T) => string>(pkFn: P) => {
250
- sortKey: <S extends (item: T) => string>(skFn: S) => IndexDefinition<T> & {
251
- readOnly: (value?: boolean) => IndexDefinition<T>;
252
- };
253
- withoutSortKey: () => IndexDefinition<T> & {
254
- readOnly: (value?: boolean) => IndexDefinition<T>;
255
- };
256
- };
257
- readOnly: (value?: boolean) => /*elided*/ any;
258
- };
259
- };
260
-
261
- export { type EntityConfig, type EntityRepository, type IndexDefinition, type MappedQueries, type QueryEntity, type QueryFunction, type QueryFunctionWithSchema, type QueryRecord, createIndex, createQueries, defineEntity };
1
+ export * from "./entity/entity";
package/dist/entity.js CHANGED
@@ -1,3 +1,3 @@
1
- export { createIndex, createQueries, defineEntity } from './chunk-U6MQGB6Y.js';
1
+ export { createIndex, createQueries, defineEntity } from './chunk-JZB6TYST.js';
2
2
  import './chunk-FF7FYGDH.js';
3
3
  import './chunk-2WIBY7PZ.js';