Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nicot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
nicot
Commits
5b6498b0
Commit
5b6498b0
authored
Apr 17, 2024
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add JsonColumn
parent
92dc3bc9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
4 deletions
+36
-4
src/decorators/property.ts
src/decorators/property.ts
+22
-1
src/utility/insert-field.ts
src/utility/insert-field.ts
+14
-3
No files found.
src/decorators/property.ts
View file @
5b6498b0
...
...
@@ -12,6 +12,7 @@ import {
IsString
,
MaxLength
,
Min
,
ValidateNested
,
}
from
'
class-validator
'
;
import
{
WithPrecisionColumnType
,
...
...
@@ -19,9 +20,14 @@ import {
}
from
'
typeorm/driver/types/ColumnTypes
'
;
import
{
ColumnWithWidthOptions
}
from
'
typeorm/decorator/options/ColumnWithWidthOptions
'
;
import
{
ColumnNumericOptions
}
from
'
typeorm/decorator/options/ColumnNumericOptions
'
;
import
{
Exclude
,
Transform
}
from
'
class-transformer
'
;
import
{
Exclude
,
Transform
,
Type
}
from
'
class-transformer
'
;
import
{
BigintTransformer
}
from
'
../utility/bigint
'
;
import
{
Metadata
}
from
'
../utility/metadata
'
;
import
{
ClassOrArray
,
getClassFromClassOrArray
,
ParseType
,
}
from
'
../utility/insert-field
'
;
export
interface
OpenAPIOptions
<
T
>
{
description
?:
string
;
...
...
@@ -190,6 +196,21 @@ export const BoolColumn = (
swaggerDecorator
(
options
,
{
type
:
Boolean
}),
]);
export
const
JsonColumn
=
<
C
extends
ClassOrArray
>
(
definition
:
C
,
options
:
PropertyOptions
<
ParseType
<
C
>>
=
{},
):
PropertyDecorator
=>
{
const
cl
=
getClassFromClassOrArray
(
definition
);
return
MergePropertyDecorators
([
Index
(),
Type
(()
=>
cl
),
ValidateNested
(),
Column
(
'
jsonb
'
,
columnDecoratorOptions
(
options
)),
validatorDecorator
(
options
),
swaggerDecorator
(
options
,
{
type
:
definition
}),
]);
};
export
const
NotColumn
=
(
options
:
OpenAPIOptions
<
any
>
=
{},
):
PropertyDecorator
=>
...
...
src/utility/insert-field.ts
View file @
5b6498b0
...
...
@@ -30,6 +30,14 @@ type TypeFromInsertOptions<O extends InsertOptions> = O extends InsertOptions<
|
(
O
extends
{
options
:
{
required
:
true
}
}
?
never
:
undefined
)
:
never
;
type
Merge
<
T
,
U
>
=
{
[
K
in
keyof
T
|
keyof
U
]:
K
extends
keyof
T
?
T
[
K
]
:
K
extends
keyof
U
?
U
[
K
]
:
never
;
};
export
function
InsertField
<
C
extends
AnyClass
,
M
extends
Record
<
string
,
InsertOptions
>
,
...
...
@@ -37,9 +45,12 @@ export function InsertField<
cl
:
C
,
map
:
M
,
newName
?:
string
,
):
new
(...
args
:
ParamsFromClass
<
C
>
)
=>
TypeFromClass
<
C
>
&
{
):
new
(...
args
:
ParamsFromClass
<
C
>
)
=>
Merge
<
{
[
F
in
keyof
M
]:
TypeFromInsertOptions
<
M
[
F
]
>
;
}
{
},
TypeFromClass
<
C
>
>
{
const
extendedCl
=
class
extends
cl
{};
for
(
const
key
in
map
)
{
ApiProperty
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment