dyna-record 0.4.11 → 0.5.1
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/README.md +53 -6
- package/dist/src/DynaRecord.d.ts +28 -19
- package/dist/src/DynaRecord.d.ts.map +1 -1
- package/dist/src/DynaRecord.js +24 -6
- package/dist/src/Logger.d.ts.map +1 -1
- package/dist/src/Logger.js +0 -1
- package/dist/src/decorators/Entity.d.ts +1 -1
- package/dist/src/decorators/Entity.d.ts.map +1 -1
- package/dist/src/decorators/Entity.js +3 -5
- package/dist/src/decorators/Table.d.ts +1 -1
- package/dist/src/decorators/Table.d.ts.map +1 -1
- package/dist/src/decorators/Table.js +2 -4
- package/dist/src/decorators/attributes/BooleanAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/BooleanAttribute.js +7 -9
- package/dist/src/decorators/attributes/DateAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/DateAttribute.js +8 -10
- package/dist/src/decorators/attributes/EnumAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/EnumAttribute.js +7 -9
- package/dist/src/decorators/attributes/ForeignKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ForeignKeyAttribute.js +9 -11
- package/dist/src/decorators/attributes/NumberAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/NumberAttribute.js +7 -9
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts +40 -17
- package/dist/src/decorators/attributes/ObjectAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/ObjectAttribute.js +80 -29
- package/dist/src/decorators/attributes/PartitionKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/PartitionKeyAttribute.js +6 -8
- package/dist/src/decorators/attributes/SortKeyAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/SortKeyAttribute.js +6 -8
- package/dist/src/decorators/attributes/StringAttribute.d.ts.map +1 -1
- package/dist/src/decorators/attributes/StringAttribute.js +7 -9
- package/dist/src/decorators/attributes/serializers.d.ts +4 -3
- package/dist/src/decorators/attributes/serializers.d.ts.map +1 -1
- package/dist/src/decorators/attributes/serializers.js +2 -1
- package/dist/src/decorators/attributes/types.d.ts +20 -6
- package/dist/src/decorators/attributes/types.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.d.ts.map +1 -1
- package/dist/src/decorators/relationships/BelongsTo.js +7 -9
- package/dist/src/decorators/relationships/HasAndBelongsToMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasAndBelongsToMany.js +13 -15
- package/dist/src/decorators/relationships/HasMany.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasMany.js +15 -17
- package/dist/src/decorators/relationships/HasOne.d.ts.map +1 -1
- package/dist/src/decorators/relationships/HasOne.js +7 -9
- package/dist/src/metadata/AttributeMetadata.d.ts +3 -0
- package/dist/src/metadata/AttributeMetadata.d.ts.map +1 -1
- package/dist/src/metadata/AttributeMetadata.js +5 -0
- package/dist/src/metadata/EntityMetadata.d.ts +2 -2
- package/dist/src/metadata/EntityMetadata.d.ts.map +1 -1
- package/dist/src/metadata/EntityMetadata.js +8 -1
- package/dist/src/metadata/MetadataStorage.d.ts.map +1 -1
- package/dist/src/metadata/MetadataStorage.js +6 -6
- package/dist/src/metadata/TableMetadata.d.ts.map +1 -1
- package/dist/src/metadata/TableMetadata.js +7 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/BelongsToRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasAndBelongsToManyRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasManyRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/HasOneRelationship.js +1 -3
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.d.ts.map +1 -1
- package/dist/src/metadata/relationship-metadata/OwnedByRelationship.js +1 -3
- package/dist/src/metadata/types.d.ts +14 -3
- package/dist/src/metadata/types.d.ts.map +1 -1
- package/dist/src/metadata/utils.js +4 -4
- package/dist/src/operations/Create/Create.js +3 -5
- package/dist/src/operations/Delete/Delete.d.ts.map +1 -1
- package/dist/src/operations/Delete/Delete.js +3 -2
- package/dist/src/operations/FindById/FindById.d.ts.map +1 -1
- package/dist/src/operations/FindById/FindById.js +4 -4
- package/dist/src/operations/Query/Query.d.ts.map +1 -1
- package/dist/src/operations/Query/Query.js +2 -1
- package/dist/src/operations/Update/Update.d.ts +6 -1
- package/dist/src/operations/Update/Update.d.ts.map +1 -1
- package/dist/src/operations/Update/Update.js +41 -17
- package/dist/src/operations/Update/types.d.ts +14 -4
- package/dist/src/operations/Update/types.d.ts.map +1 -1
- package/dist/src/operations/types.d.ts +1 -1
- package/dist/src/operations/types.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.d.ts +4 -3
- package/dist/src/operations/utils/expressionBuilder.d.ts.map +1 -1
- package/dist/src/operations/utils/expressionBuilder.js +66 -2
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts +19 -0
- package/dist/src/operations/utils/flattenObjectForUpdate.d.ts.map +1 -0
- package/dist/src/operations/utils/flattenObjectForUpdate.js +45 -0
- package/dist/src/operations/utils/index.d.ts +2 -0
- package/dist/src/operations/utils/index.d.ts.map +1 -1
- package/dist/src/operations/utils/index.js +2 -0
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts +8 -0
- package/dist/src/operations/utils/mergePartialObjectAttributes.d.ts.map +1 -0
- package/dist/src/operations/utils/mergePartialObjectAttributes.js +60 -0
- package/dist/src/operations/utils/types.d.ts +16 -0
- package/dist/src/operations/utils/types.d.ts.map +1 -1
- package/dist/src/operations/utils/utils.d.ts +2 -2
- package/dist/src/operations/utils/utils.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query-utils/QueryBuilder.js +11 -7
- package/dist/src/query-utils/types.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.d.ts.map +1 -1
- package/dist/src/relationships/JoinTable.js +4 -3
- package/dist/src/utils.d.ts +4 -4
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +13 -11
- package/package.json +10 -12
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Note: ACID compliant according to DynamoDB [limitations](https://docs.aws.amazon
|
|
|
22
22
|
- [Query](#query)
|
|
23
23
|
- [Filtering on Object Attributes](#filtering-on-object-attributes)
|
|
24
24
|
- [Update](#update)
|
|
25
|
+
- [Updating Object Attributes](#updating-object-attributes)
|
|
25
26
|
- [Delete](#delete)
|
|
26
27
|
- [Type Safety Features](#type-safety-features)
|
|
27
28
|
- [Best Practices](#best-practices)
|
|
@@ -197,18 +198,15 @@ const addressSchema = {
|
|
|
197
198
|
class Store extends MyTable {
|
|
198
199
|
@ObjectAttribute({ alias: "Address", schema: addressSchema })
|
|
199
200
|
public readonly address: InferObjectSchema<typeof addressSchema>;
|
|
200
|
-
|
|
201
|
-
@ObjectAttribute({ alias: "Metadata", schema: metaSchema, nullable: true })
|
|
202
|
-
public readonly metadata?: InferObjectSchema<typeof metaSchema>;
|
|
203
201
|
}
|
|
204
202
|
```
|
|
205
203
|
|
|
206
204
|
- **Supported field types:** `"string"`, `"number"`, `"boolean"`, `"date"` (stored as ISO strings, exposed as `Date` objects), `"enum"` (via `values`), nested `"object"` (via `fields`), and `"array"` (via `items`)
|
|
207
|
-
- **Nullable fields:** Set `nullable: true` on individual fields within the schema to
|
|
208
|
-
- **
|
|
205
|
+
- **Nullable fields:** Set `nullable: true` on individual non-object fields within the schema to make them optional
|
|
206
|
+
- **Object attributes are never nullable:** DynamoDB cannot update nested document paths (e.g., `address.geo.lat`) if the parent object does not exist. To prevent this, `@ObjectAttribute` fields always exist as at least an empty object `{}`. Nested object fields within the schema are also never nullable. Non-object fields (primitives, enums, dates, arrays) can still be nullable.
|
|
209
207
|
- **Alias support:** Use the `alias` option to map to a different DynamoDB attribute name
|
|
210
208
|
- **Storage:** Objects are stored as native DynamoDB Map types
|
|
211
|
-
- **
|
|
209
|
+
- **Partial updates:** Updates are partial — only the fields you provide are modified. Omitted fields are preserved. Nested objects are recursively merged. See [Updating Object Attributes](#updating-object-attributes)
|
|
212
210
|
- **Filtering:** Object attributes support dot-path filtering in queries — see [Filtering on Object Attributes](#filtering-on-object-attributes)
|
|
213
211
|
|
|
214
212
|
##### Enum fields
|
|
@@ -696,6 +694,55 @@ await Pet.update("123", {
|
|
|
696
694
|
});
|
|
697
695
|
```
|
|
698
696
|
|
|
697
|
+
#### Updating Object Attributes
|
|
698
|
+
|
|
699
|
+
Object attribute updates are **partial** — only the fields you provide are modified, and omitted fields are preserved. This uses DynamoDB document path expressions under the hood (e.g., `SET #address.#street = :address_street`) for efficient field-level updates.
|
|
700
|
+
|
|
701
|
+
```typescript
|
|
702
|
+
// Only updates street — city, zip, geo, etc. are preserved
|
|
703
|
+
await Store.update("123", {
|
|
704
|
+
address: { street: "456 New St" }
|
|
705
|
+
});
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
**Nested objects** are recursively merged:
|
|
709
|
+
|
|
710
|
+
```typescript
|
|
711
|
+
// Only updates lat — lng and accuracy are preserved
|
|
712
|
+
await Store.update("123", {
|
|
713
|
+
address: {
|
|
714
|
+
geo: { lat: 42 }
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
**Nullable fields** within the object can be removed by setting them to `null`:
|
|
720
|
+
|
|
721
|
+
```typescript
|
|
722
|
+
// Removes zip, preserves all other fields
|
|
723
|
+
await Store.update("123", {
|
|
724
|
+
address: { zip: null }
|
|
725
|
+
});
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
**Arrays** within objects are **full replacement** (not merged):
|
|
729
|
+
|
|
730
|
+
```typescript
|
|
731
|
+
// Replaces the entire tags array
|
|
732
|
+
await Store.update("123", {
|
|
733
|
+
address: { tags: ["new-tag-1", "new-tag-2"] }
|
|
734
|
+
});
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
The instance `update` method returns a deep-merged result, preserving existing fields:
|
|
738
|
+
|
|
739
|
+
```typescript
|
|
740
|
+
const updated = await storeInstance.update({
|
|
741
|
+
address: { street: "New Street" }
|
|
742
|
+
});
|
|
743
|
+
// updated.address.city → still has the original value
|
|
744
|
+
```
|
|
745
|
+
|
|
699
746
|
#### Instance Method
|
|
700
747
|
|
|
701
748
|
There is an instance `update` method that has the same rules above, but returns the full updated instance.
|
package/dist/src/DynaRecord.d.ts
CHANGED
|
@@ -73,12 +73,12 @@ declare abstract class DynaRecord implements DynaRecordBase {
|
|
|
73
73
|
static findById<T extends DynaRecord>(this: EntityClass<T>, id: string, options?: undefined): Promise<Optional<EntityAttributesInstance<T>>>;
|
|
74
74
|
static findById<T extends DynaRecord, Inc extends IncludedAssociations<T> = []>(this: EntityClass<T>, id: string, options: FindByIdOptions<T, Inc>): Promise<Optional<FindByIdIncludesRes<T, Inc>>>;
|
|
75
75
|
/**
|
|
76
|
-
* Query an EntityPartition by EntityId
|
|
77
|
-
* QueryByIndex not supported. Use Query with keys
|
|
78
|
-
* @param {string}
|
|
76
|
+
* Query an EntityPartition by EntityId (string) or by PartitionKey/SortKey conditions (object).
|
|
77
|
+
* QueryByIndex not supported with this overload. Use Query with keys and indexName option if needed.
|
|
78
|
+
* @param {string | EntityKeyConditions<T>} key - Entity Id (string) or an object with PartitionKey and optional SortKey conditions.
|
|
79
79
|
* @param {Object=} options - QueryOptions. Supports filter, consistentRead and skCondition. indexName is not supported
|
|
80
80
|
*
|
|
81
|
-
* @example By partition key only
|
|
81
|
+
* @example By partition key only (string shorthand)
|
|
82
82
|
* ```typescript
|
|
83
83
|
* const user = await User.query("123");
|
|
84
84
|
* ```
|
|
@@ -101,36 +101,29 @@ declare abstract class DynaRecord implements DynaRecordBase {
|
|
|
101
101
|
* createdAt: "2023-11-21T12:31:21.148Z"
|
|
102
102
|
* }
|
|
103
103
|
* });
|
|
104
|
+
* ```
|
|
104
105
|
*
|
|
105
106
|
* @example Query as consistent read
|
|
106
107
|
* ```typescript
|
|
107
108
|
* const user = await User.query("123", { consistentRead: true })
|
|
108
109
|
* ```
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
static query<T extends DynaRecord>(this: EntityClass<T>, key: string, options?: OptionsWithoutIndex): Promise<QueryResults<T>>;
|
|
112
|
-
/**
|
|
113
|
-
* Query by PartitionKey and optional SortKey/Filter/Index conditions without and index
|
|
114
|
-
* When querying without an index the key conditions must be the PartitionKey and SortKey defined on the entity
|
|
115
|
-
* @param {Object} key - PartitionKey value and optional SortKey condition. Keys must be attributes defined on the model
|
|
116
|
-
* @param {Object=} options - QueryBuilderOptions
|
|
117
110
|
*
|
|
118
|
-
* @example By partition key only
|
|
111
|
+
* @example By partition key only (object form)
|
|
119
112
|
* ```typescript
|
|
120
113
|
* const user = await User.query({ pk: "User#123" });
|
|
121
114
|
* ```
|
|
122
115
|
*
|
|
123
|
-
* @example By partition key and sort key exact match
|
|
116
|
+
* @example By partition key and sort key exact match (object form)
|
|
124
117
|
* ```typescript
|
|
125
118
|
* const user = await User.query({ pk: "User#123", sk: "Profile#123" });
|
|
126
119
|
* ```
|
|
127
120
|
*
|
|
128
|
-
* @example By partition key and sort key begins with
|
|
121
|
+
* @example By partition key and sort key begins with (object form)
|
|
129
122
|
* ```typescript
|
|
130
123
|
* const user = await User.query({ pk: "User#123", sk: { $beginsWith: "Profile" } });
|
|
131
124
|
* ```
|
|
132
125
|
*
|
|
133
|
-
* @example With filter (arbitrary example)
|
|
126
|
+
* @example With filter (object form, arbitrary example)
|
|
134
127
|
* ```typescript
|
|
135
128
|
* const result = await User.query(
|
|
136
129
|
* {
|
|
@@ -143,7 +136,7 @@ declare abstract class DynaRecord implements DynaRecordBase {
|
|
|
143
136
|
* $or: [
|
|
144
137
|
* {
|
|
145
138
|
* name: "John",
|
|
146
|
-
* email: { $beginsWith: "testing }
|
|
139
|
+
* email: { $beginsWith: "testing" }
|
|
147
140
|
* },
|
|
148
141
|
* {
|
|
149
142
|
* name: "Jane",
|
|
@@ -163,7 +156,7 @@ declare abstract class DynaRecord implements DynaRecordBase {
|
|
|
163
156
|
* const user = await User.query({ pk: "User#123", consistentRead: true });
|
|
164
157
|
* ```
|
|
165
158
|
*/
|
|
166
|
-
static query<T extends DynaRecord>(this: EntityClass<T>, key: EntityKeyConditions<T>, options?: OptionsWithoutIndex): Promise<QueryResults<T>>;
|
|
159
|
+
static query<T extends DynaRecord>(this: EntityClass<T>, key: string | EntityKeyConditions<T>, options?: OptionsWithoutIndex): Promise<QueryResults<T>>;
|
|
167
160
|
/**
|
|
168
161
|
* Query by PartitionKey and optional SortKey/Filter/Index conditions with an index
|
|
169
162
|
* When querying on an index, any of the entities attributes can be part of the key condition
|
|
@@ -231,12 +224,21 @@ declare abstract class DynaRecord implements DynaRecordBase {
|
|
|
231
224
|
* { referentialIntegrityCheck: false }
|
|
232
225
|
* );
|
|
233
226
|
* ```
|
|
227
|
+
*
|
|
228
|
+
* @example Partial update of an ObjectAttribute (only provided fields are modified, omitted fields are preserved)
|
|
229
|
+
* ```typescript
|
|
230
|
+
* await User.update("userId", { address: { street: "456 Oak Ave" } });
|
|
231
|
+
* ```
|
|
234
232
|
*/
|
|
235
233
|
static update<T extends DynaRecord>(this: EntityClass<T>, id: string, attributes: UpdateOptions<T>, options?: {
|
|
236
234
|
referentialIntegrityCheck?: boolean;
|
|
237
235
|
}): Promise<void>;
|
|
238
236
|
/**
|
|
239
|
-
* Same as the static `update` method but on an instance. Returns the full updated instance
|
|
237
|
+
* Same as the static `update` method but on an instance. Returns the full updated instance.
|
|
238
|
+
*
|
|
239
|
+
* For `@ObjectAttribute` fields, the returned instance deep merges the partial update
|
|
240
|
+
* with the existing object value — omitted fields are preserved, and fields set to `null`
|
|
241
|
+
* are removed.
|
|
240
242
|
*
|
|
241
243
|
* @example Updating an entity.
|
|
242
244
|
* ```typescript
|
|
@@ -248,6 +250,13 @@ declare abstract class DynaRecord implements DynaRecordBase {
|
|
|
248
250
|
* const updatedInstance = await instance.update({ email: "newemail@example.com", someKey: null });
|
|
249
251
|
* ```
|
|
250
252
|
*
|
|
253
|
+
* @example Partial ObjectAttribute update with deep merge
|
|
254
|
+
* ```typescript
|
|
255
|
+
* // instance.address is { street: "123 Main", city: "Springfield", zip: 12345 }
|
|
256
|
+
* const updated = await instance.update({ address: { street: "456 Oak Ave" } });
|
|
257
|
+
* // updated.address is { street: "456 Oak Ave", city: "Springfield", zip: 12345 }
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
251
260
|
* @example With referential integrity check disabled
|
|
252
261
|
* ```typescript
|
|
253
262
|
* const updatedInstance = await instance.update(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynaRecord.d.ts","sourceRoot":"","sources":["../../src/DynaRecord.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAsB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9E,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EAExB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,MAAM,EACN,KAAK,aAAa,EAElB,KAAK,aAAa,EAGlB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAEtB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"DynaRecord.d.ts","sourceRoot":"","sources":["../../src/DynaRecord.ts"],"names":[],"mappings":"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"}
|
package/dist/src/DynaRecord.js
CHANGED
|
@@ -70,7 +70,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
70
70
|
const metadata_1 = __importStar(require("./metadata"));
|
|
71
71
|
const decorators_1 = require("./decorators");
|
|
72
72
|
const operations_1 = require("./operations");
|
|
73
|
-
const utils_1 = require("./utils");
|
|
73
|
+
const utils_1 = require("./operations/utils");
|
|
74
|
+
const utils_2 = require("./utils");
|
|
74
75
|
/**
|
|
75
76
|
* Serves as an abstract base class for entities in the ORM system. It defines standard fields such as `id`, `type`, `createdAt`, and `updatedAt`, and provides static methods for CRUD operations and queries. This class encapsulates common behaviors and properties that all entities share, leveraging decorators for attribute metadata and supporting operations like finding, creating, updating, and deleting entities.
|
|
76
77
|
*
|
|
@@ -195,13 +196,22 @@ let DynaRecord = (() => {
|
|
|
195
196
|
* { referentialIntegrityCheck: false }
|
|
196
197
|
* );
|
|
197
198
|
* ```
|
|
199
|
+
*
|
|
200
|
+
* @example Partial update of an ObjectAttribute (only provided fields are modified, omitted fields are preserved)
|
|
201
|
+
* ```typescript
|
|
202
|
+
* await User.update("userId", { address: { street: "456 Oak Ave" } });
|
|
203
|
+
* ```
|
|
198
204
|
*/
|
|
199
205
|
static async update(id, attributes, options) {
|
|
200
206
|
const op = new operations_1.Update(this);
|
|
201
207
|
await op.run(id, attributes, options);
|
|
202
208
|
}
|
|
203
209
|
/**
|
|
204
|
-
* Same as the static `update` method but on an instance. Returns the full updated instance
|
|
210
|
+
* Same as the static `update` method but on an instance. Returns the full updated instance.
|
|
211
|
+
*
|
|
212
|
+
* For `@ObjectAttribute` fields, the returned instance deep merges the partial update
|
|
213
|
+
* with the existing object value — omitted fields are preserved, and fields set to `null`
|
|
214
|
+
* are removed.
|
|
205
215
|
*
|
|
206
216
|
* @example Updating an entity.
|
|
207
217
|
* ```typescript
|
|
@@ -213,6 +223,13 @@ let DynaRecord = (() => {
|
|
|
213
223
|
* const updatedInstance = await instance.update({ email: "newemail@example.com", someKey: null });
|
|
214
224
|
* ```
|
|
215
225
|
*
|
|
226
|
+
* @example Partial ObjectAttribute update with deep merge
|
|
227
|
+
* ```typescript
|
|
228
|
+
* // instance.address is { street: "123 Main", city: "Springfield", zip: 12345 }
|
|
229
|
+
* const updated = await instance.update({ address: { street: "456 Oak Ave" } });
|
|
230
|
+
* // updated.address is { street: "456 Oak Ave", city: "Springfield", zip: 12345 }
|
|
231
|
+
* ```
|
|
232
|
+
*
|
|
216
233
|
* @example With referential integrity check disabled
|
|
217
234
|
* ```typescript
|
|
218
235
|
* const updatedInstance = await instance.update(
|
|
@@ -226,11 +243,12 @@ let DynaRecord = (() => {
|
|
|
226
243
|
const op = new operations_1.Update(InstanceClass);
|
|
227
244
|
const updatedAttributes = await op.run(this.id, attributes, options);
|
|
228
245
|
const clone = structuredClone(this);
|
|
229
|
-
|
|
230
|
-
|
|
246
|
+
const entityAttrs = metadata_1.default.getEntityAttributes(InstanceClass.name);
|
|
247
|
+
// Deep merge ObjectAttributes, shallow assign everything else
|
|
248
|
+
(0, utils_1.mergePartialObjectAttributes)(clone, updatedAttributes, entityAttrs);
|
|
231
249
|
const updatedInstance = Object.fromEntries(Object.entries(clone).filter(([_, value]) => value !== null));
|
|
232
250
|
// Return the updated instance, which is of type `this`
|
|
233
|
-
return (0,
|
|
251
|
+
return (0, utils_2.createInstance)(InstanceClass, updatedInstance);
|
|
234
252
|
}
|
|
235
253
|
/**
|
|
236
254
|
* Delete an entity by ID
|
|
@@ -270,7 +288,7 @@ let DynaRecord = (() => {
|
|
|
270
288
|
if (tableItem[typeAlias] !== this.name) {
|
|
271
289
|
throw new Error("Unable to convert dynamo item to entity. Invalid type");
|
|
272
290
|
}
|
|
273
|
-
return (0,
|
|
291
|
+
return (0, utils_2.tableItemToEntity)(this, tableItem);
|
|
274
292
|
}
|
|
275
293
|
/**
|
|
276
294
|
* Get the partition key for an entity
|
package/dist/src/Logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/Logger.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,cAAM,MAAM;IACV;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,IAAI;IAMnB;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI;IAIzD;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI;IAI3D;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI;IAI7D;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI;CAG5D;AAED,eAAe,MAAM,CAAC"}
|
package/dist/src/Logger.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-extraneous-class */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
4
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
4
|
/**
|
|
6
5
|
* Facilitates logging throughout the ORM system with support for different log levels: log, warn, error, and info. Logging can be toggled through the `DYNA_RECORD_LOGGING_ENABLED` environment variable. When enabled, logs are output to the console, allowing for easy tracking and debugging of the system's operations.
|
|
@@ -18,6 +18,6 @@ import type DynaRecord from "../DynaRecord";
|
|
|
18
18
|
* ```
|
|
19
19
|
* In this example, the `User` class is marked as an entity using the `@Entity` decorator. This designation registers the `User` class within the ORM's metadata system, making it a recognized entity for the ORM to manage. The registration process involves associating the class with its corresponding table name and any additional metadata required by the ORM to handle instances of this class effectively.
|
|
20
20
|
*/
|
|
21
|
-
declare function Entity
|
|
21
|
+
declare function Entity(target: new () => DynaRecord, _context: ClassDecoratorContext): void;
|
|
22
22
|
export default Entity;
|
|
23
23
|
//# sourceMappingURL=Entity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../../src/decorators/Entity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../../src/decorators/Entity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,iBAAS,MAAM,CACb,MAAM,EAAE,UAAU,UAAU,EAC5B,QAAQ,EAAE,qBAAqB,GAC9B,IAAI,CAKN;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -23,10 +23,8 @@ const metadata_1 = __importDefault(require("../metadata"));
|
|
|
23
23
|
* ```
|
|
24
24
|
* In this example, the `User` class is marked as an entity using the `@Entity` decorator. This designation registers the `User` class within the ORM's metadata system, making it a recognized entity for the ORM to manage. The registration process involves associating the class with its corresponding table name and any additional metadata required by the ORM to handle instances of this class effectively.
|
|
25
25
|
*/
|
|
26
|
-
function Entity(target,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
metadata_1.default.addEntity(target, tableClassName);
|
|
30
|
-
}
|
|
26
|
+
function Entity(target, _context) {
|
|
27
|
+
const tableClassName = Object.getPrototypeOf(target).name;
|
|
28
|
+
metadata_1.default.addEntity(target, tableClassName);
|
|
31
29
|
}
|
|
32
30
|
exports.default = Entity;
|
|
@@ -17,6 +17,6 @@ import type DynaRecord from "../DynaRecord";
|
|
|
17
17
|
* ```
|
|
18
18
|
* In this example, the `@Table` decorator is applied to the `User` class, specifying custom table metadata options, including the table name (`users`) and the schema (`public`). These options are registered with the ORM, which then uses them to correctly map the `User` entity to the corresponding table in the database. This mapping is critical for executing ORM operations such as querying, inserting, and updating records in the `users` table.
|
|
19
19
|
*/
|
|
20
|
-
declare function Table(props: TableMetadataOptions): (target: typeof DynaRecord,
|
|
20
|
+
declare function Table(props: TableMetadataOptions): (target: typeof DynaRecord, _context: ClassDecoratorContext) => void;
|
|
21
21
|
export default Table;
|
|
22
22
|
//# sourceMappingURL=Table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../src/decorators/Table.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,KAAK,CAAC,KAAK,EAAE,oBAAoB,YACf,OAAO,UAAU,
|
|
1
|
+
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../src/decorators/Table.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,KAAK,CAAC,KAAK,EAAE,oBAAoB,YACf,OAAO,UAAU,YAAY,qBAAqB,UAG5E;AAED,eAAe,KAAK,CAAC"}
|
|
@@ -22,10 +22,8 @@ const metadata_1 = __importDefault(require("../metadata"));
|
|
|
22
22
|
* In this example, the `@Table` decorator is applied to the `User` class, specifying custom table metadata options, including the table name (`users`) and the schema (`public`). These options are registered with the ORM, which then uses them to correctly map the `User` entity to the corresponding table in the database. This mapping is critical for executing ORM operations such as querying, inserting, and updating records in the `users` table.
|
|
23
23
|
*/
|
|
24
24
|
function Table(props) {
|
|
25
|
-
return function (target,
|
|
26
|
-
|
|
27
|
-
metadata_1.default.addTable(target.name, props);
|
|
28
|
-
}
|
|
25
|
+
return function (target, _context) {
|
|
26
|
+
metadata_1.default.addTable(target.name, props);
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
29
|
exports.default = Table;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BooleanAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/BooleanAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,gBAAgB,CACvB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"BooleanAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/BooleanAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,gBAAgB,CACvB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,OAAO,EACjB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAW9C;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -30,16 +30,14 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
30
30
|
*/
|
|
31
31
|
function BooleanAttribute(props) {
|
|
32
32
|
return function (_value, context) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...props
|
|
40
|
-
});
|
|
33
|
+
context.addInitializer(function () {
|
|
34
|
+
metadata_1.default.addEntityAttribute(this.constructor.name, {
|
|
35
|
+
attributeName: context.name.toString(),
|
|
36
|
+
nullable: props?.nullable,
|
|
37
|
+
type: zod_1.z.boolean(),
|
|
38
|
+
...props
|
|
41
39
|
});
|
|
42
|
-
}
|
|
40
|
+
});
|
|
43
41
|
};
|
|
44
42
|
}
|
|
45
43
|
exports.default = BooleanAttribute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/DateAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,IAAI,EACd,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"DateAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/DateAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,IAAI,EACd,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAY9C;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -33,17 +33,15 @@ const serializers_1 = require("./serializers");
|
|
|
33
33
|
*/
|
|
34
34
|
function DateAttribute(props) {
|
|
35
35
|
return function (_value, context) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
...props
|
|
44
|
-
});
|
|
36
|
+
context.addInitializer(function () {
|
|
37
|
+
metadata_1.default.addEntityAttribute(this.constructor.name, {
|
|
38
|
+
attributeName: context.name.toString(),
|
|
39
|
+
nullable: props?.nullable,
|
|
40
|
+
serializers: serializers_1.dateSerializer,
|
|
41
|
+
type: zod_1.z.date(),
|
|
42
|
+
...props
|
|
45
43
|
});
|
|
46
|
-
}
|
|
44
|
+
});
|
|
47
45
|
};
|
|
48
46
|
}
|
|
49
47
|
exports.default = DateAttribute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/EnumAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAG5D,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EACnC,KAAK,CAAC,CAAC,SAAS,oBAAoB,EACpC,KAAK,EAAE,CAAC,YAEE,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"EnumAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/EnumAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAG5D,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,aAAa,CACpB,CAAC,SAAS,UAAU,EACpB,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EACnC,KAAK,CAAC,CAAC,SAAS,oBAAoB,EACpC,KAAK,EAAE,CAAC,YAEE,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAW9C;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -28,16 +28,14 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
28
28
|
*/
|
|
29
29
|
function EnumAttribute(props) {
|
|
30
30
|
return function (_value, context) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
...props
|
|
38
|
-
});
|
|
31
|
+
context.addInitializer(function () {
|
|
32
|
+
metadata_1.default.addEntityAttribute(this.constructor.name, {
|
|
33
|
+
attributeName: context.name.toString(),
|
|
34
|
+
nullable: props.nullable,
|
|
35
|
+
type: zod_1.z.enum(props.values),
|
|
36
|
+
...props
|
|
39
37
|
});
|
|
40
|
-
}
|
|
38
|
+
});
|
|
41
39
|
};
|
|
42
40
|
}
|
|
43
41
|
exports.default = EnumAttribute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForeignKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/ForeignKeyAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,iBAAS,mBAAmB,CAC1B,YAAY,SAAS,UAAU,EAC/B,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,gBAAgB,EAC1B,SAAS,EAAE,MAAM,WAAW,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,YAE3C,SAAS,WACR,yBAAyB,CAChC,CAAC,EACD,CAAC,CAAC,UAAU,CAAC,SAAS,IAAI,GACtB,kBAAkB,CAAC,YAAY,CAAC,GAChC,UAAU,CAAC,YAAY,CAAC,EAC5B,CAAC,CACF,
|
|
1
|
+
{"version":3,"file":"ForeignKeyAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/ForeignKeyAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,iBAAS,mBAAmB,CAC1B,YAAY,SAAS,UAAU,EAC/B,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,gBAAgB,EAC1B,SAAS,EAAE,MAAM,WAAW,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,YAE3C,SAAS,WACR,yBAAyB,CAChC,CAAC,EACD,CAAC,CAAC,UAAU,CAAC,SAAS,IAAI,GACtB,kBAAkB,CAAC,YAAY,CAAC,GAChC,UAAU,CAAC,YAAY,CAAC,EAC5B,CAAC,CACF,UAcJ;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -41,18 +41,16 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
41
41
|
*/
|
|
42
42
|
function ForeignKeyAttribute(getTarget, props) {
|
|
43
43
|
return function (_value, context) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
...props
|
|
53
|
-
});
|
|
44
|
+
context.addInitializer(function () {
|
|
45
|
+
const targetEntity = getTarget();
|
|
46
|
+
metadata_1.default.addEntityAttribute(this.constructor.name, {
|
|
47
|
+
attributeName: context.name.toString(),
|
|
48
|
+
nullable: props?.nullable,
|
|
49
|
+
type: zod_1.z.string(),
|
|
50
|
+
foreignKeyTarget: targetEntity,
|
|
51
|
+
...props
|
|
54
52
|
});
|
|
55
|
-
}
|
|
53
|
+
});
|
|
56
54
|
};
|
|
57
55
|
}
|
|
58
56
|
exports.default = ForeignKeyAttribute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/NumberAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,eAAe,CACtB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"NumberAttribute.d.ts","sourceRoot":"","sources":["../../../../src/decorators/attributes/NumberAttribute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iBAAS,eAAe,CACtB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,gBAAgB,EAC1B,KAAK,CAAC,EAAE,CAAC,YAEC,SAAS,WACR,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAW9C;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -30,16 +30,14 @@ const metadata_1 = __importDefault(require("../../metadata"));
|
|
|
30
30
|
*/
|
|
31
31
|
function NumberAttribute(props) {
|
|
32
32
|
return function (_value, context) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
...props
|
|
40
|
-
});
|
|
33
|
+
context.addInitializer(function () {
|
|
34
|
+
metadata_1.default.addEntityAttribute(this.constructor.name, {
|
|
35
|
+
attributeName: context.name.toString(),
|
|
36
|
+
nullable: props?.nullable,
|
|
37
|
+
type: zod_1.z.number(),
|
|
38
|
+
...props
|
|
41
39
|
});
|
|
42
|
-
}
|
|
40
|
+
});
|
|
43
41
|
};
|
|
44
42
|
}
|
|
45
43
|
exports.default = NumberAttribute;
|