orm-dynamodb 1.0.0 → 1.0.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.
Files changed (3) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +76 -42
  3. package/package.json +13 -3
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a fee
167
+ for, acceptance of support, warranty, indemnity, or other liability
168
+ obligations and/or rights consistent with this License. However, in
169
+ accepting such obligations, You may act only on Your own behalf and
170
+ on Your sole responsibility, not on behalf of any other Contributor,
171
+ and only if You agree to indemnify, defend, and hold each Contributor
172
+ harmless for any liability incurred by, or claims asserted against,
173
+ such Contributor by reason of your accepting any such warranty or
174
+ additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,16 +1,31 @@
1
1
  # orm-dynamodb
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/orm-dynamodb.svg)](https://www.npmjs.com/package/orm-dynamodb)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+
3
6
  Lightweight TypeScript decorators for modeling DynamoDB items as classes.
4
7
 
5
- ## Install
8
+ ## ✨ Features
9
+
10
+ - 🎯 **Type-safe decorators** for DynamoDB entities with full TypeScript support
11
+ - 🔗 **Entity relationships** with `@LinkObject` and `@LinkArray` decorators and automatic link loading
12
+ - 🔄 **Custom serialization** with `@ToDbModel` and `@FromDbModel` transformers
13
+ - ⏰ **Automatic timestamps** for `createdAt` and `updatedAt`
14
+ - 🛠️ **Intuitive API** with `insert()`, `update()`, `delete()`, `get()`, and `query()` methods
15
+ - 🚀 **Zero configuration** - works out of the box with AWS SDK v3
16
+ - 📦 **Tiny footprint** - lightweight with minimal dependencies
17
+
18
+ ## 📦 Install
6
19
 
7
20
  ```bash
8
21
  npm install orm-dynamodb
9
22
  ```
10
23
 
11
- The package depends on `@aws-sdk/client-dynamodb` and `@aws-sdk/lib-dynamodb`.
24
+ **Dependencies:** `@aws-sdk/client-dynamodb` and `@aws-sdk/lib-dynamodb`
12
25
 
13
- Your TypeScript config must enable decorators:
26
+ ### TypeScript Configuration
27
+
28
+ Enable decorators in your `tsconfig.json`:
14
29
 
15
30
  ```json
16
31
  {
@@ -21,7 +36,7 @@ Your TypeScript config must enable decorators:
21
36
  }
22
37
  ```
23
38
 
24
- ## Quick Start
39
+ ## 🚀 Quick Start
25
40
 
26
41
  ```ts
27
42
  import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
@@ -30,7 +45,7 @@ import {
30
45
  Entity,
31
46
  FromDbModel,
32
47
  HashKeyValue,
33
- Link,
48
+ LinkObject,
34
49
  SortKeyValue,
35
50
  ToDbModel
36
51
  } from 'orm-dynamodb';
@@ -75,7 +90,7 @@ class Post extends BaseEntity {
75
90
  title: string;
76
91
  publishedAt: Date | null;
77
92
 
78
- @Link(Author)
93
+ @LinkObject(Author)
79
94
  author: Author | undefined;
80
95
 
81
96
  constructor(slug: string = '', title: string = '', publishedAt: Date | null = null) {
@@ -104,7 +119,7 @@ async function run() {
104
119
  const post = new Post('decorators-with-dynamodb', 'Decorators With DynamoDB', new Date());
105
120
  post.author = new Author('ada-lovelace', 'Ada Lovelace');
106
121
 
107
- await post.save();
122
+ await post.insert();
108
123
 
109
124
  const loaded = await Post.get('decorators-with-dynamodb');
110
125
  await loaded?.loadLinks();
@@ -113,28 +128,48 @@ async function run() {
113
128
  }
114
129
  ```
115
130
 
116
- ## API
117
-
118
- The package exports:
119
-
120
- - `BaseEntity`
121
- - `Entity`
122
- - `HashKeyValue`
123
- - `SortKeyValue`
124
- - `Link`
125
- - `ToDbModel`
126
- - `FromDbModel`
127
-
128
- Core capabilities:
129
-
130
- - explicit DynamoDB client configuration via `BaseEntity.configure(...)` or `@Entity(..., dbClient)`
131
- - `save()`, `update()`, and `delete()` instance methods
132
- - `get()`, `query()`, and common query helpers on the entity class
133
- - linked entity references with `@Link(...)` and `loadLinks()`
134
- - custom read/write mapping with `@ToDbModel` and `@FromDbModel`
135
- - automatic `createdAt` and `updatedAt` timestamps
136
-
137
- ## Local Development
131
+ ## 📚 API
132
+
133
+ ### Decorators & Classes
134
+
135
+ - **`BaseEntity`** - Base class for all entities with CRUD operations
136
+ - **`@Entity(tableName, hashKey, sortKey?, dbClient?)`** - Marks a class as a DynamoDB entity
137
+ - **`@HashKeyValue`** - Defines the hash key value getter
138
+ - **`@SortKeyValue`** - Defines the sort key value getter
139
+ - **`@LinkObject(EntityClass, options?)`** - Creates a reference to a single entity (options: `{ inline?: boolean }`)
140
+ - **`@LinkArray(EntityClass, options?)`** - Creates a reference to an array of entities (options: `{ inline?: boolean }`)
141
+ - **`@ToDbModel`** - Custom serialization when writing to DynamoDB
142
+ - **`@FromDbModel`** - Custom deserialization when reading from DynamoDB
143
+
144
+ ### Core Methods
145
+
146
+ **Iinsert()` - Insert or update the entity (cascade saves linked entities)
147
+ - `update(attributes)` - Partial update of the entity
148
+ - `delete()` - Remove the entity from DynamoDB
149
+ - `loadLinks()` - Load all linked entities
150
+
151
+ **Static Methods:**
152
+ - `get(sortKeyValue)` - Retrieve a single entity by sort key
153
+ - `query(options)` - Query entities with custom options
154
+ - `queryAll(limit?)` - Query all entities in the partition
155
+ - `queryEquals(sortKeyValue, limit?)` - Query entities with exact sort key match
156
+ - `queryStartsWith(prefix, limit?)` - Query entities with sort key prefix
157
+ - `queryBetween(start, end, limit?)` - Query entities with sort key in range
158
+ - `queryGreaterThan(value, limit?)` - Query entities with sort key greater than value
159
+ - `queryLessThan(value, limit?)` - Query entities with sort key less than valuesort key
160
+ - `query(options)` - Query entities in the partition
161
+ - `configure(client)` - Set the DynamoDB client globally
162
+
163
+ ### Features
164
+
165
+ - ✅ Explicit DynamoDB client configuration via `BaseEntity.configure(...)` or `@Entity(..., dbClient)`
166
+ - ✅ Automatic `createdAt` and `updatedAt` timestamp management
167
+ - ✅ Type-safe entity relationships with `@LinkObject` and `@LinkArray` decorators
168
+ - ✅ Lazy loading of linked entities with `loadLinks()`
169
+ - ✅ Custom transformation between domain models and DynamoDB items
170
+ - ✅ Inline and non-inline link storage options
171
+
172
+ ## 🛠️ Development
138
173
 
139
174
  Install dependencies:
140
175
 
@@ -160,22 +195,21 @@ Check what will be published:
160
195
  npm run pack:check
161
196
  ```
162
197
 
163
- ## Publish
198
+ ## 📝 License
164
199
 
165
- Make sure the package name in `package.json` is the one you want to publish and is available on npm, then:
200
+ Apache-2.0
166
201
 
167
- ```bash
168
- npm login
169
- npm publish
170
- ```
202
+ ## ⚠️ Important Notes
203
+
204
+ - Static lookups assume the hash key can be derived from a default-constructed instance
205
+ - Query helpers operate within a single partition key value
206
+ - Link loading issues individual `GetCommand` calls per linked record
207
+ - This is a lightweight utility, not a schema or migration system
171
208
 
172
- If you rename the package, update the import path in this README to match.
209
+ ## 📖 Examples
173
210
 
174
- ## Notes
211
+ See [examples.ts](./examples.ts) for examples.
175
212
 
176
- - Static lookups assume the hash key can be derived from a default-constructed instance.
177
- - Query helpers all operate within a single partition key value.
178
- - Link loading currently issues individual `GetCommand` calls per linked record.
179
- - This is a lightweight utility, not a schema or migration system.
213
+ ## 🤝 Contributing
180
214
 
181
- See [examples.ts](./examples.ts) for a fuller usage example.
215
+ Contributions are welcome! Please feel free to submit a Pull Request.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orm-dynamodb",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Lightweight TypeScript decorators for modeling DynamoDB items as classes",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,7 +12,8 @@
12
12
  },
13
13
  "files": [
14
14
  "dist",
15
- "README.md"
15
+ "README.md",
16
+ "LICENSE"
16
17
  ],
17
18
  "sideEffects": false,
18
19
  "scripts": {
@@ -32,7 +33,16 @@
32
33
  "orm",
33
34
  "typescript"
34
35
  ],
35
- "license": "ISC",
36
+ "author": "",
37
+ "license": "Apache-2.0",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": ""
41
+ },
42
+ "bugs": {
43
+ "url": ""
44
+ },
45
+ "homepage": "https://github.com/ssz360/DynamoDB-ORM",
36
46
  "dependencies": {
37
47
  "@aws-sdk/client-dynamodb": "^3.0.0",
38
48
  "@aws-sdk/lib-dynamodb": "^3.0.0",