rajt 0.0.26 → 0.0.28

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,11 +1,12 @@
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.26",
4
+ "version": "0.0.28",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.ts",
9
+ "./auth": "./src/auth/index.ts",
9
10
  "./dynamodb": "./src/dynamodb/index.ts",
10
11
  "./dynamodb/types": "./src/dynamodb/types.ts",
11
12
  "./http": "./src/http.ts",
@@ -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<M extends object, S extends ZodTypeAny>(
7
+ export function Repository<
8
+ S extends ZodTypeAny,
9
+ B extends new (...args: any[]) => any
10
+ >(
8
11
  schema: S,
9
- model: new (...args: any[]) => M,
12
+ base?: B | ModelOpts,
10
13
  opts?: ModelOpts
11
14
  ) {
12
- const BaseSchemaClass = Schema(schema, model)
13
- _model(BaseSchemaClass, opts)
15
+ const isClass = typeof base === 'function'
16
+ type M = z.infer<S>
14
17
 
15
- return class extends BaseSchemaClass {
16
- static model = Dynamodb.model<M>(BaseSchemaClass as unknown as new (...args: any[]) => M)
17
- } as unknown as (typeof BaseSchemaClass) & {
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
  }