@vlad_kramarukha/json-statham 1.2.2 → 1.3.1

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/index.ts CHANGED
@@ -3,3 +3,6 @@ export { field, fieldName, mapper, schema, value, skipIf, skip } from './lib/dec
3
3
 
4
4
  /* Mappers */
5
5
  export { fromJson, toJson } from './lib/mappers.ts'
6
+
7
+ /* Types */
8
+ export { type FieldOptions, type Mapper, type SkipMapper } from './lib/types.ts'
package/lib/decorators.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import Meta from './meta.ts'
2
+ import type { FieldOptions, Mapper, SkipMapper } from './types.ts'
2
3
 
3
4
  function field(options: FieldOptions) {
4
5
  return <Target extends object>(target: Target, property: keyof Target) => {
package/lib/mappers.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import Meta from './meta.ts'
2
+ import type { FieldOptions, MetaInfo } from './types.ts'
2
3
 
3
- export function fromJson<Schema, Json extends object>(
4
- schema: new () => Schema & MetaInfo,
4
+ export function fromJson<Schema extends object, Json extends object>(
5
+ schema: new () => Schema,
5
6
  json: Json
6
- ): (Schema & MetaInfo) | Schema {
7
+ ): Schema {
7
8
  const result = {} as Record<string, any>
8
9
  const instance = new schema()
9
10
 
package/lib/meta.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { FieldOptions, MetaInfo } from './types.ts'
2
+
1
3
  const META_KEY = Symbol('meta')
2
4
 
3
5
  const pt = (target: object) => target.constructor.prototype
@@ -1,22 +1,22 @@
1
- interface Mapper<Record extends object> {
1
+ export interface Mapper<Record extends object = any> {
2
2
  from?: (field: any, record: Record) => any
3
3
  to?: (field: any, record: Record) => any
4
4
  }
5
5
 
6
- interface SkipMapper {
6
+ export interface SkipMapper {
7
7
  <Record>(field: any, record: Record): boolean
8
8
  }
9
9
 
10
- interface FieldOptions {
10
+ export interface FieldOptions<Record extends object = any> {
11
11
  skip?: boolean | SkipMapper
12
12
  value?: any
13
- mapper?: Mapper
13
+ mapper?: Mapper<Record>
14
14
  fieldName?: string
15
15
  isArray?: boolean
16
16
  reconstruct?: boolean
17
17
  schema?: new () => object
18
18
  }
19
19
 
20
- interface MetaInfo {
21
- [p: string]: FieldOptions | SimpleFieldOptions
20
+ export interface MetaInfo {
21
+ [p: string]: FieldOptions
22
22
  }
package/package.json CHANGED
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "name": "@vlad_kramarukha/json-statham",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "author": "Vlad Kramarukha",
5
5
  "private": false,
6
6
  "description": "TS library for data mapping",
7
+ "main": "index.ts",
7
8
  "module": "index.ts",
8
9
  "type": "module",
9
10
  "license": "Apache-2.0",
10
- "keywords": ["TS", "JSON", "mapping", "data", "schema", "Jason Statham"],
11
+ "keywords": [
12
+ "TS",
13
+ "JSON",
14
+ "mapping",
15
+ "data",
16
+ "schema",
17
+ "Jason Statham"
18
+ ],
11
19
  "files": [
12
20
  "index.ts",
13
21
  "lib/*",