rajt 0.0.26 → 0.0.27
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 +1 -1
- package/src/dynamodb/repository.ts +15 -9
package/package.json
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import { ZodTypeAny } from 'zod'
|
|
1
|
+
import { z, ZodTypeAny } from 'zod'
|
|
2
2
|
import { Dynamodb } from './client'
|
|
3
3
|
import { Schema } from './schema'
|
|
4
4
|
import { _model } from './decorators'
|
|
5
5
|
import type { ModelOpts } from './types'
|
|
6
6
|
|
|
7
|
-
export function Repository<
|
|
7
|
+
export function Repository<
|
|
8
|
+
S extends ZodTypeAny,
|
|
9
|
+
B extends new (...args: any[]) => any
|
|
10
|
+
>(
|
|
8
11
|
schema: S,
|
|
9
|
-
|
|
12
|
+
base?: B | ModelOpts,
|
|
10
13
|
opts?: ModelOpts
|
|
11
14
|
) {
|
|
12
|
-
const
|
|
13
|
-
|
|
15
|
+
const isClass = typeof base === 'function'
|
|
16
|
+
type M = z.infer<S>
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
const Repo = Schema(schema, isClass ? base : undefined)
|
|
19
|
+
_model(Repo, isClass ? opts : base)
|
|
20
|
+
|
|
21
|
+
return class extends Repo {
|
|
22
|
+
static model = Dynamodb.model<M>(Repo as any)
|
|
23
|
+
} as unknown as (typeof Repo) & {
|
|
24
|
+
new (...args: any[]): InstanceType<typeof Repo>
|
|
18
25
|
model: ReturnType<typeof Dynamodb.model<M>>
|
|
19
|
-
new (...args: any[]): InstanceType<typeof BaseSchemaClass>
|
|
20
26
|
}
|
|
21
27
|
}
|