@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 +3 -0
- package/lib/decorators.ts +1 -0
- package/lib/mappers.ts +4 -3
- package/lib/meta.ts +2 -0
- package/lib/{index.d.ts → types.ts} +6 -6
- package/package.json +10 -2
package/index.ts
CHANGED
package/lib/decorators.ts
CHANGED
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
|
|
4
|
+
export function fromJson<Schema extends object, Json extends object>(
|
|
5
|
+
schema: new () => Schema,
|
|
5
6
|
json: Json
|
|
6
|
-
):
|
|
7
|
+
): Schema {
|
|
7
8
|
const result = {} as Record<string, any>
|
|
8
9
|
const instance = new schema()
|
|
9
10
|
|
package/lib/meta.ts
CHANGED
|
@@ -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
|
|
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.
|
|
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": [
|
|
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/*",
|