Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Thirdeye
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
Koishi Thirdeye
Commits
acb983b3
Commit
acb983b3
authored
Nov 20, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix things of schema register
parent
27420ac9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
9 deletions
+29
-9
src/decorators.ts
src/decorators.ts
+4
-2
src/def/constants.ts
src/def/constants.ts
+2
-2
src/def/interfaces.ts
src/def/interfaces.ts
+6
-0
src/register.ts
src/register.ts
+17
-5
No files found.
src/decorators.ts
View file @
acb983b3
...
...
@@ -18,6 +18,7 @@ import {
MetadataMap
,
OnContextFunction
,
Selection
,
SystemInjectFun
,
}
from
'
./def
'
;
import
'
reflect-metadata
'
;
import
{
App
,
Argv
,
Command
,
Context
,
FieldCollector
,
Session
}
from
'
koishi
'
;
...
...
@@ -208,7 +209,7 @@ export function Provide(
return
Metadata
.
appendUnique
(
KoishiServiceProvideSym
,
name
);
}
const
InjectSystem
=
(
fun
:
(
obj
:
PluginClass
)
=>
any
)
=>
const
InjectSystem
=
(
fun
:
SystemInjectFun
)
=>
Metadata
.
set
(
KoishiSystemInjectSym
,
fun
,
KoishiSystemInjectSymKeys
);
export
const
InjectContext
=
(
select
?:
Selection
)
=>
...
...
@@ -223,9 +224,10 @@ export const InjectApp = () => InjectSystem((obj) => obj.__ctx.app);
export
const
InjectConfig
=
(
raw
=
false
)
=>
InjectSystem
((
obj
)
=>
(
raw
?
obj
.
__rawConfig
:
obj
.
__config
));
export
const
InjectLogger
=
(
name
?:
string
)
=>
InjectSystem
((
obj
)
=>
InjectSystem
((
obj
,
config
)
=>
obj
.
__ctx
.
logger
(
name
||
config
.
name
||
Object
.
getPrototypeOf
(
Object
.
getPrototypeOf
(
obj
))?.
constructor
?.
name
||
'
default
'
,
),
...
...
src/def/constants.ts
View file @
acb983b3
...
...
@@ -4,8 +4,8 @@ import {
CommandDefinitionFun
,
DoRegisterConfig
,
OnContextFunction
,
SystemInjectFun
,
}
from
'
./interfaces
'
;
import
{
PluginClass
}
from
'
../register
'
;
export
const
KoishiOnContextScope
=
'
KoishiOnContextScope
'
;
export
const
KoishiDoRegister
=
'
KoishiDoRegister
'
;
...
...
@@ -33,5 +33,5 @@ export interface MetadataArrayMap {
export
interface
MetadataMap
{
KoishiDoRegister
:
DoRegisterConfig
;
KoishiServiceInjectSym
:
keyof
Context
.
Services
;
KoishiSystemInjectSym
:
(
obj
:
PluginClass
)
=>
any
;
KoishiSystemInjectSym
:
SystemInjectFun
;
}
src/def/interfaces.ts
View file @
acb983b3
...
...
@@ -13,6 +13,7 @@ import {
User
,
}
from
'
koishi
'
;
import
{
MetadataArrayMap
,
MetadataMap
}
from
'
./constants
'
;
import
{
KoishiPluginRegistrationOptions
,
PluginClass
}
from
'
../register
'
;
export
interface
Type
<
T
=
any
>
extends
Function
{
new
(...
args
:
any
[]):
T
;
...
...
@@ -142,3 +143,8 @@ export type CommandPutConfig<
>
=
MappingStruct
<
CommandPutConfigMap
,
K
>
;
export
type
CommandDefinitionFun
=
(
cmd
:
Command
)
=>
Command
;
export
type
SystemInjectFun
=
<
T
=
any
>
(
obj
:
PluginClass
<
T
>
,
pluginMeta
:
KoishiPluginRegistrationOptions
<
T
>
,
)
=>
any
;
src/register.ts
View file @
acb983b3
...
...
@@ -51,14 +51,26 @@ function getContextFromFilters(ctx: Context, filters: OnContextFunction[]) {
return
targetCtx
;
}
function
getSchemaFromOption
<
T
>
(
schema
:
Schema
<
T
>
|
Type
<
T
>
):
Schema
<
T
>
{
if
(
!
schema
)
{
return
;
}
if
(
typeof
schema
!==
'
function
'
)
{
return
schema
;
}
return
schemaFromClass
(
schema
);
}
export
function
KoishiPlugin
<
T
=
any
>
(
options
:
KoishiPluginRegistrationOptions
<
T
>
=
{},
)
{
return
function
<
C
extends
{
new
(...
args
:
any
[]):
any
;
schema
?:
Schema
}
>
(
originalClass
:
C
,
)
{
return
function
<
C
extends
{
new
(...
args
:
any
[]):
any
;
schema
?:
Schema
;
name
?:
string
}
>
(
originalClass
:
C
)
{
const
newClass
=
class
extends
originalClass
implements
PluginClass
{
static
schema
=
options
.
schema
||
originalClass
.
schema
||
undefined
;
static
schema
=
getSchemaFromOption
(
options
.
schema
||
originalClass
.
schema
,
);
__ctx
:
Context
;
__config
:
T
;
__rawConfig
:
T
;
...
...
@@ -73,7 +85,7 @@ export function KoishiPlugin<T = any>(
Object
.
defineProperty
(
this
,
key
,
{
configurable
:
true
,
enumerable
:
true
,
get
:
()
=>
valueFunction
(
this
),
get
:
()
=>
valueFunction
(
this
,
options
),
});
}
}
...
...
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