rajt 0.0.31 → 0.0.32

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.31",
4
+ "version": "0.0.32",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
package/src/auth/token.ts CHANGED
@@ -40,7 +40,7 @@ export class Token {
40
40
  }
41
41
 
42
42
  static parse(token: string) {
43
- const host = this.host(Envir.get('FLOW_SERVER') || c.cx.req.header('host') || '')
43
+ const host = this.host(Envir.get('FLOW_SERVER'))
44
44
 
45
45
  return Factory.parse(token)
46
46
  .issuedBy(host)
@@ -67,8 +67,8 @@ export class Token {
67
67
  this.#name = name
68
68
  }
69
69
 
70
- static host(url: string | null | undefined): string {
71
- if (!url) return ''
70
+ static host(url?: string | null | undefined): string {
71
+ if (!url) url = c.cx.req.url || c.cx.req.header('host') || ''
72
72
 
73
73
  let formattedUrl = String(url)
74
74
  if (!formattedUrl.startsWith('http'))
@@ -17,7 +17,7 @@ import getLength from '../utils/lenght'
17
17
 
18
18
  export default class AbstractModel<T extends object> {
19
19
  #meta: ModelMetadata
20
- #cls!: Model<T>
20
+ cls?: Model<T>
21
21
  lastKey?: Record<string, any>
22
22
  #db: DynamoDBDocumentClient
23
23
  #queryBuilder?: QueryBuilder
@@ -35,6 +35,7 @@ export default class AbstractModel<T extends object> {
35
35
 
36
36
  if (typeof (cls as ModelMetadata).table === 'string') {
37
37
  this.#meta = cls as ModelMetadata
38
+ this.cls = model?.cls
38
39
  return
39
40
  }
40
41
 
@@ -43,7 +44,7 @@ export default class AbstractModel<T extends object> {
43
44
  throw new Error('Missing model metadata')
44
45
 
45
46
  this.#meta = meta
46
- this.#cls = cls as Model<T>
47
+ this.cls = cls as Model<T>
47
48
  }
48
49
 
49
50
  get table(): string {
@@ -272,21 +273,20 @@ export default class AbstractModel<T extends object> {
272
273
  }
273
274
 
274
275
  #processItems(items: any[] | undefined, filterFn?: Filter<T>): T[] {
275
- if (!items) return []
276
-
277
- items = this.#meta.zip ? Compact.smartDecode<T[]>(items, this.#meta.fields) : items as T[]
276
+ if (!items || !items.length) return []
277
+ items = items.map(item => this.#processItem(item))
278
278
  return filterFn ? items.filter(filterFn) : items
279
279
  }
280
280
 
281
281
  #processItem(item: any, keys?: Record<string, string>): T {
282
282
  if (this.#meta.zip && item?.V) {
283
- const model = new this.#cls(Compact.decode(item.V, this.#meta.fields))
283
+ const model = new this.cls!(Compact.decode<T>(item.V, this.#meta.fields))
284
284
  if (!keys) keys = this.#getItemKey(item)
285
285
 
286
286
  // @ts-ignore
287
287
  return model.withKey(keys[this.#meta.keys.PK], keys[this.#meta.keys.SK] || undefined)
288
288
  }
289
289
 
290
- return new this.#cls(item)
290
+ return new this.cls!(item)
291
291
  }
292
292
  }