Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
0cee1dfb
Commit
0cee1dfb
authored
3 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
refactor: better getChart result type
parent
0d3757f2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/backend/src/services/chart/core.ts
+14
-2
14 additions, 2 deletions
packages/backend/src/services/chart/core.ts
with
14 additions
and
2 deletions
packages/backend/src/services/chart/core.ts
+
14
−
2
View file @
0cee1dfb
...
...
@@ -70,6 +70,18 @@ type ChartResult<T extends Schema> = {
[
P
in
keyof
T
]:
number
[];
};
type
UnionToIntersection
<
T
>
=
(
T
extends
any
?
(
x
:
T
)
=>
any
:
never
)
extends
(
x
:
infer
R
)
=>
any
?
R
:
never
;
type
UnflattenSingleton
<
K
extends
string
,
V
>
=
K
extends
`
${
infer
A
}
.
${
infer
B
}
`
?
{
[
_
in
A
]:
UnflattenSingleton
<
B
,
V
>
;
}
:
{
[
_
in
K
]:
V
;
};
type
Unflatten
<
T
extends
Record
<
string
,
any
>>
=
UnionToIntersection
<
{
[
K
in
Extract
<
keyof
T
,
string
>
]:
UnflattenSingleton
<
K
,
T
[
K
]
>
;
}[
Extract
<
keyof
T
,
string
>
]
>
;
/**
* 様々なチャートの管理を司るクラス
*/
...
...
@@ -642,12 +654,12 @@ export default abstract class Chart<T extends Schema> {
}
@
autobind
public
async
getChart
(
span
:
'
hour
'
|
'
day
'
,
amount
:
number
,
cursor
:
Date
|
null
,
group
:
string
|
null
=
null
):
Promise
<
Record
<
string
,
unknown
>>
{
public
async
getChart
(
span
:
'
hour
'
|
'
day
'
,
amount
:
number
,
cursor
:
Date
|
null
,
group
:
string
|
null
=
null
):
Promise
<
Unflatten
<
ChartResult
<
T
>
>>
{
const
result
=
await
this
.
getChartRaw
(
span
,
amount
,
cursor
,
group
);
const
object
=
{};
for
(
const
[
k
,
v
]
of
Object
.
entries
(
result
))
{
nestedProperty
.
set
(
object
,
k
,
v
);
}
return
object
;
return
object
as
Unflatten
<
ChartResult
<
T
>>
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment