Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Schemastery Gen
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
Schemastery Gen
Commits
63d729e6
Commit
63d729e6
authored
Nov 30, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rework dict
parent
7d7f9196
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
src/decorators/define-property.ts
src/decorators/define-property.ts
+3
-1
src/decorators/register.ts
src/decorators/register.ts
+8
-1
src/def/interfaces.ts
src/def/interfaces.ts
+13
-3
No files found.
src/decorators/define-property.ts
View file @
63d729e6
...
...
@@ -21,10 +21,12 @@ export function SchemaProperty(options: SchemaOptions = {}): PropertyDecorator {
options
.
type
=
'
any
'
;
}
}
const
typeInSchema
=
options
.
schema
?.
type
;
if
(
nativeType
===
Array
&&
options
.
array
!==
false
&&
options
.
schema
?.
type
!==
'
tuple
'
typeInSchema
!==
'
array
'
&&
typeInSchema
!==
'
tuple
'
)
{
options
.
array
=
true
;
}
...
...
src/decorators/register.ts
View file @
63d729e6
...
...
@@ -42,7 +42,13 @@ function applyOptionsToSchema(schema: Schema, options: SchemaClassOptions) {
function
getPropertySchemaFromOptions
<
PT
>
(
options
:
SchemaOptions
):
Schema
<
PT
>
{
let
schema
=
getBasePropertySchemaFromOptions
(
options
);
if
(
options
.
dict
)
{
schema
=
Schema
.
dict
(
schema
).
default
({});
const
skeySchema
=
(
options
.
dict
===
true
?
Schema
.
string
()
:
((
Schema
.
from
(
options
.
dict
)
as
unknown
)
as
Schema
<
any
,
string
>
))
as
Schema
<
any
,
string
>
;
schema
=
Schema
.
dict
(
schema
,
skeySchema
).
default
({});
}
if
(
options
.
array
)
{
schema
=
Schema
.
array
(
schema
).
default
([]);
...
...
@@ -89,6 +95,7 @@ export function schemaFromClass<T>(cl: ClassType<T>): Schema<Partial<T>, T> {
const
schemaFields
:
(
keyof
Schema
)[]
=
[
'
type
'
,
'
sKey
'
,
'
inner
'
,
'
list
'
,
'
dict
'
,
...
...
src/def/interfaces.ts
View file @
63d729e6
...
...
@@ -2,17 +2,27 @@ import Schema from 'schemastery';
export
type
ClassType
<
T
>
=
{
new
(...
args
:
any
[]):
T
};
export
type
SchemaType
=
export
type
Schema
Native
Type
=
|
'
string
'
|
'
number
'
|
'
boolean
'
|
'
object
'
|
'
any
'
|
'
never
'
|
'
never
'
;
export
type
SchemaSource
=
|
null
|
undefined
|
string
|
number
|
boolean
|
Schema
// eslint-disable-next-line @typescript-eslint/ban-types
|
Function
|
{
new
(...
args
:
any
[]):
any
};
export
type
SchemaType
=
SchemaNativeType
|
SchemaSource
;
export
interface
SchemaClassOptions
extends
Schema
.
Meta
<
any
>
{
desc
?:
string
;
allowUnknown
?:
boolean
;
// for backward compatibility
...
...
@@ -20,7 +30,7 @@ export interface SchemaClassOptions extends Schema.Meta<any> {
export
interface
SchemaOptions
extends
SchemaClassOptions
{
schema
?:
Schema
<
any
>
;
dict
?:
boolean
;
dict
?:
boolean
|
Schema
<
any
,
string
>
|
string
;
array
?:
boolean
;
type
?:
SchemaType
;
}
...
...
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