rajt 0.0.44 → 0.0.45

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rajt",
3
3
  "description": "A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.",
4
- "version": "0.0.44",
4
+ "version": "0.0.45",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
@@ -13,6 +13,7 @@ import type { ModelMetadata, Keys, Model, Filter } from './types'
13
13
  import { getModelMetadata } from './decorators'
14
14
  import QueryBuilder from './query-builder'
15
15
  import Compact from './compact'
16
+ import { isArraySchema } from './schema'
16
17
  import getLength from '../utils/lenght'
17
18
 
18
19
  export default class AbstractModel<T extends object> {
@@ -280,13 +281,23 @@ export default class AbstractModel<T extends object> {
280
281
 
281
282
  #processItem(item: any, keys?: Record<string, string>): T {
282
283
  if (this.#meta.zip && item?.V) {
283
- const model = new this.cls!(Compact.decode<T>(item.V, this.#meta.fields))
284
+ const value = Compact.decode<T>(item.V, this.#meta.fields)
285
+ const model = isArraySchema(this.#meta.fields) && Array.isArray(value)
286
+ ? value.map(v => new this.cls!(v))
287
+ : new this.cls!(value)
288
+
284
289
  if (!keys) keys = this.#getItemKey(item)
285
290
 
286
- // @ts-ignore
287
- return model.withKey(keys[this.#meta.keys.PK], keys[this.#meta.keys.SK] || undefined)
291
+ return this.#withKey(model as T, keys)
288
292
  }
289
293
 
290
294
  return new this.cls!(item)
291
295
  }
296
+
297
+ #withKey(model: T, keys: Record<string, string>): T {
298
+ // @ts-ignore
299
+ if (Array.isArray(model)) return model.map(m => this.#withKey(m))
300
+ // @ts-ignore
301
+ return model.withKey(keys[this.#meta.keys.PK], keys[this.#meta.keys.SK] || undefined)
302
+ }
292
303
  }