rajt 0.0.24 → 0.0.26
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 +1 -1
- package/package.json +7 -1
- package/src/action.ts +2 -2
- package/src/dev.ts +1 -1
- package/src/dynamodb/model.ts +4 -4
- package/src/enum.ts +75 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -18,4 +18,4 @@
|
|
|
18
18
|
|
|
19
19
|
## License
|
|
20
20
|
|
|
21
|
-
This package is licensed under the [MIT license](https://github.com/attla/rajt/blob/main/LICENSE) © [Zunq](https://zunq.com)
|
|
21
|
+
This package is licensed under the [MIT license](https://github.com/attla/rajt/blob/main/LICENSE) © [Zunq](https://zunq.com)
|
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.
|
|
4
|
+
"version": "0.0.26",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -49,6 +49,12 @@
|
|
|
49
49
|
"tsx": "^4.19.3",
|
|
50
50
|
"typescript": "^5.8.3"
|
|
51
51
|
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"bun-types": "^1.2.14"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18.0.0"
|
|
57
|
+
},
|
|
52
58
|
"resolutions": {
|
|
53
59
|
"@smithy/types": "^4.3.0"
|
|
54
60
|
},
|
package/src/action.ts
CHANGED
|
@@ -101,7 +101,7 @@ export default abstract class Action {
|
|
|
101
101
|
|
|
102
102
|
async body<E>() {
|
|
103
103
|
const cType = this.context.req.header('Content-Type')
|
|
104
|
-
if (!cType) return {}
|
|
104
|
+
if (!cType) return {} as E
|
|
105
105
|
|
|
106
106
|
if (/^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/.test(cType)) {
|
|
107
107
|
return await this.json<E>()
|
|
@@ -114,7 +114,7 @@ export default abstract class Action {
|
|
|
114
114
|
return await this.form() as E
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
return {}
|
|
117
|
+
return {} as E
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
get response() {
|
package/src/dev.ts
CHANGED
|
@@ -17,7 +17,7 @@ const middlewares = await getMiddlewares()
|
|
|
17
17
|
middlewares.forEach(mw => registerMiddleware(mw.handle))
|
|
18
18
|
|
|
19
19
|
Ability.fromRoutes(routes)
|
|
20
|
-
Ability.roles = jsonImport('
|
|
20
|
+
Ability.roles = jsonImport('../../../../roles.json')
|
|
21
21
|
|
|
22
22
|
const fetch = createApp({ routes }).fetch
|
|
23
23
|
|
package/src/dynamodb/model.ts
CHANGED
|
@@ -105,7 +105,7 @@ export default class AbstractModel<T extends object> {
|
|
|
105
105
|
keys = this.#getItemKey(item, key)
|
|
106
106
|
this.#validateKeys(keys)
|
|
107
107
|
// @ts-ignore
|
|
108
|
-
item = { ...keys, V: Compact.encode(this
|
|
108
|
+
item = { ...keys, V: Compact.encode(this.#getItemWithoutKeys(item), this.#meta.fields) }
|
|
109
109
|
} else {
|
|
110
110
|
this.#validateKeys(item)
|
|
111
111
|
}
|
|
@@ -120,7 +120,7 @@ export default class AbstractModel<T extends object> {
|
|
|
120
120
|
keys = this.#getItemKey(attrs, key)
|
|
121
121
|
this.#validateKeys(keys)
|
|
122
122
|
// @ts-ignore
|
|
123
|
-
attrs = { V: Compact.encode(this
|
|
123
|
+
attrs = { V: Compact.encode(this.#getItemWithoutKeys(attrs), this.#meta.fields) }
|
|
124
124
|
} else {
|
|
125
125
|
this.#validateKeys(attrs)
|
|
126
126
|
}
|
|
@@ -226,7 +226,7 @@ export default class AbstractModel<T extends object> {
|
|
|
226
226
|
if (this.#meta.keys?.SK) {
|
|
227
227
|
if (key.length > 1)
|
|
228
228
|
// @ts-ignore
|
|
229
|
-
keys[this
|
|
229
|
+
keys[this.#meta.keys.SK] = key[1]
|
|
230
230
|
else if (this.#meta.defaultSK)
|
|
231
231
|
keys[this.#meta.keys.SK] = this.#meta.defaultSK
|
|
232
232
|
}
|
|
@@ -284,7 +284,7 @@ export default class AbstractModel<T extends object> {
|
|
|
284
284
|
if (!keys) keys = this.#getItemKey(item)
|
|
285
285
|
|
|
286
286
|
// @ts-ignore
|
|
287
|
-
return model.withKey(keys[this
|
|
287
|
+
return model.withKey(keys[this.#meta.keys.PK], keys[this.#meta.keys.SK] || undefined)
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
return new this.#cls(item)
|
package/src/enum.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
type EnumType<T> = T extends string[]
|
|
2
|
+
? { [K in T[number]]: K }
|
|
3
|
+
: T extends Record<string, string | number>
|
|
4
|
+
? T
|
|
5
|
+
: never
|
|
6
|
+
|
|
7
|
+
type EnumValue<T> = T extends string[]
|
|
8
|
+
? T[number]
|
|
9
|
+
: T extends Record<string, infer V>
|
|
10
|
+
? V
|
|
11
|
+
: never
|
|
12
|
+
|
|
13
|
+
type EnumStatic<T> = {
|
|
14
|
+
has(search: string | number): boolean
|
|
15
|
+
key(search: string | number): string | null
|
|
16
|
+
value(search: string | number): EnumValue<T> | null
|
|
17
|
+
readonly keys: string[]
|
|
18
|
+
readonly values: Array<EnumValue<T>>
|
|
19
|
+
toObject(): EnumType<T>
|
|
20
|
+
} & EnumType<T>
|
|
21
|
+
|
|
22
|
+
export default function Enum<T extends string[] | Record<string, string | number>>(definition: T): EnumStatic<T> {
|
|
23
|
+
const enumObj = Array.isArray(definition)
|
|
24
|
+
? Object.fromEntries(definition.map(key => [key, key])) as EnumType<T>
|
|
25
|
+
: definition as EnumType<T>
|
|
26
|
+
|
|
27
|
+
const keyToValueMap = new Map<string | number, string | number>()
|
|
28
|
+
const valueToKeyMap = new Map<string | number, string>()
|
|
29
|
+
|
|
30
|
+
Object.entries(enumObj).forEach(([key, value]) => {
|
|
31
|
+
keyToValueMap.set(key, value)
|
|
32
|
+
valueToKeyMap.set(String(value), key)
|
|
33
|
+
if (typeof value === 'number') valueToKeyMap.set(value.toString(), key)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const GeneratedEnum = class {
|
|
37
|
+
static has(search: string | number): boolean {
|
|
38
|
+
return keyToValueMap.has(search as string) || valueToKeyMap.has(String(search))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static key(search: string | number): string | null {
|
|
42
|
+
if (keyToValueMap.has(search as string))
|
|
43
|
+
return search as string
|
|
44
|
+
|
|
45
|
+
return valueToKeyMap.get(String(search)) || null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static value(search: string | number): EnumValue<T> | null {
|
|
49
|
+
if (keyToValueMap.has(search as string))
|
|
50
|
+
return keyToValueMap.get(search as string) as EnumValue<T>
|
|
51
|
+
|
|
52
|
+
return valueToKeyMap.has(String(search))
|
|
53
|
+
? keyToValueMap.get(valueToKeyMap.get(String(search))!) as EnumValue<T>
|
|
54
|
+
: null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static get keys(): string[] {
|
|
58
|
+
return Object.keys(enumObj)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static get values(): Array<EnumValue<T>> {
|
|
62
|
+
return Object.values(enumObj) as Array<EnumValue<T>>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static toObject(): EnumType<T> {
|
|
66
|
+
return { ...enumObj }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Object.entries(enumObj).forEach(([key, value]) => {
|
|
71
|
+
(GeneratedEnum as any)[key] = value
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
return GeneratedEnum as unknown as EnumStatic<T>
|
|
75
|
+
}
|
package/src/index.ts
CHANGED