@vlad_kramarukha/json-statham 1.1.1 → 1.2.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 +2 -10
- package/lib/decorators.ts +31 -0
- package/package.json +1 -1
- package/lib/decorators/field.ts +0 -7
- package/lib/decorators/fieldName.ts +0 -5
- package/lib/decorators/mapper.ts +0 -5
- package/lib/decorators/schema.ts +0 -5
- package/lib/decorators/skip.ts +0 -4
- package/lib/decorators/skipIf.ts +0 -5
- package/lib/decorators/value.ts +0 -5
package/index.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
/* Decorators */
|
|
2
|
-
|
|
3
|
-
import skip from './lib/decorators/skip.ts'
|
|
4
|
-
import skipIf from './lib/decorators/skipIf.ts'
|
|
5
|
-
import schema from './lib/decorators/schema.ts'
|
|
6
|
-
import value from './lib/decorators/value.ts'
|
|
7
|
-
import mapper from './lib/decorators/mapper.ts'
|
|
8
|
-
import fieldName from './lib/decorators/fieldName.ts'
|
|
2
|
+
export * as decorators from './lib/decorators.ts'
|
|
9
3
|
|
|
10
4
|
/* Mappers */
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export default { field, skip, skipIf, schema, value, mapper, fieldName, fromJson, toJson }
|
|
5
|
+
export * as mappers from './lib/mappers.ts'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Meta from './meta.ts'
|
|
2
|
+
|
|
3
|
+
function field(options: FieldOptions) {
|
|
4
|
+
return <Target extends object>(target: Target, property: keyof Target) => {
|
|
5
|
+
Meta.addMeta(target, property, options)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function fieldName(fieldName: string, reconstruct = false) {
|
|
10
|
+
return field({ fieldName, reconstruct })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function mapper<Record extends object>(mapper: Mapper<Record>) {
|
|
14
|
+
return field({ mapper })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function schema(schema: FieldOptions['schema'], isArray: FieldOptions['isArray'] = false) {
|
|
18
|
+
return field({ schema, isArray })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function value(value: any) {
|
|
22
|
+
return field({ value })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function skipIf(skipMapper: SkipMapper) {
|
|
26
|
+
return field({ skip: skipMapper })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const skip = field({ skip: true })
|
|
30
|
+
|
|
31
|
+
export { field, fieldName, mapper, schema, value, skipIf, skip }
|
package/package.json
CHANGED
package/lib/decorators/field.ts
DELETED
package/lib/decorators/mapper.ts
DELETED
package/lib/decorators/schema.ts
DELETED
package/lib/decorators/skip.ts
DELETED
package/lib/decorators/skipIf.ts
DELETED