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
5a2257f6
Commit
5a2257f6
authored
May 21, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restrict possible decorated plugins
parent
1413edf7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
16 deletions
+24
-16
src/decorators.ts
src/decorators.ts
+3
-2
src/def/interfaces.ts
src/def/interfaces.ts
+6
-0
src/register.ts
src/register.ts
+10
-3
tests/if.spec.ts
tests/if.spec.ts
+1
-1
tests/inject-using.spec.ts
tests/inject-using.spec.ts
+4
-10
No files found.
src/decorators.ts
View file @
5a2257f6
...
...
@@ -12,6 +12,7 @@ import {
KoishiSystemInjectSymKeys
,
ProvideOptions
,
SystemInjectFun
,
TypedMethodDecorator
,
}
from
'
./def
'
;
import
{
TopLevelAction
}
from
'
koishi-decorators
'
;
import
{
ModelClassType
,
ModelRegistrar
}
from
'
minato-decorators
'
;
...
...
@@ -126,11 +127,11 @@ export const PluginName = (name: string) =>
export
const
If
=
<
T
>
(
func
:
Condition
<
boolean
,
T
,
[
Record
<
string
,
any
>
]
>
,
):
MethodDecorator
=>
Metadata
.
append
(
'
KoishiIf
'
,
func
);
):
TypedMethodDecorator
<
T
>
=>
Metadata
.
append
(
'
KoishiIf
'
,
func
);
export
const
For
=
<
T
>
(
func
:
Condition
<
Iterable
<
Record
<
string
,
any
>>
,
T
,
[
Record
<
string
,
any
>
]
>
,
):
MethodDecorator
=>
Metadata
.
append
(
'
KoishiFor
'
,
func
);
):
TypedMethodDecorator
<
T
>
=>
Metadata
.
append
(
'
KoishiFor
'
,
func
);
export
const
UseModel
=
(...
models
:
ModelClassType
[]):
ClassDecorator
=>
TopLevelAction
((
ctx
)
=>
{
...
...
src/def/interfaces.ts
View file @
5a2257f6
...
...
@@ -47,3 +47,9 @@ export type MapPluginToConfig<M extends Dict<PluginClass>> = {
export
type
MapPluginToConfigWithSelection
<
M
extends
Dict
<
PluginClass
>>
=
{
[
K
in
keyof
M
]:
ClassPluginConfig
<
M
[
K
]
>
&
Selection
;
};
export
type
TypedMethodDecorator
<
T
>
=
<
P
>
(
target
:
T
,
propertyKey
:
string
|
symbol
,
descriptor
:
TypedPropertyDescriptor
<
P
>
,
)
=>
void
;
src/register.ts
View file @
5a2257f6
...
...
@@ -8,6 +8,7 @@ import {
KoishiServiceProvideSym
,
KoishiSystemInjectSym
,
KoishiSystemInjectSymKeys
,
PluginClass
,
ThirdEyeSym
,
}
from
'
./def
'
;
import
{
reflector
}
from
'
./meta/meta-fetch
'
;
...
...
@@ -18,7 +19,8 @@ import { PluginName, PluginSchema, UsingService } from './decorators';
export
interface
KoishiPluginRegistrationOptions
<
T
=
any
>
{
name
?:
string
;
schema
?:
Schema
<
any
,
T
>
|
Type
<
T
>
;
schema
?:
Schema
<
T
>
|
Type
<
T
>
;
Config
?:
Schema
<
T
>
|
Type
<
T
>
;
using
?:
(
keyof
Context
.
Services
)[];
}
...
...
@@ -47,13 +49,18 @@ export interface LifecycleEvents {
onDisconnect
?():
void
|
Promise
<
void
>
;
}
export
function
DefinePlugin
<
T
=
any
>
(
export
function
DefinePlugin
<
T
>
(
options
?:
KoishiPluginRegistrationOptions
<
T
>
,
):
<
C
extends
PluginClass
<
T
>>
(
plugin
:
C
,
)
=>
C
&
KoishiPluginRegistrationOptions
<
T
>
;
export
function
DefinePlugin
<
T
>
(
options
:
KoishiPluginRegistrationOptions
<
T
>
=
{},
)
{
return
function
<
C
extends
{
new
(...
args
:
any
[]):
any
;
}
&
KoishiPluginRegistrationOptions
<
T
>
,
},
>
(
originalClass
:
C
)
{
if
(
options
.
name
)
{
PluginName
(
options
.
name
)(
originalClass
);
...
...
tests/if.spec.ts
View file @
5a2257f6
...
...
@@ -24,7 +24,7 @@ class MyPlugin2 extends BasePlugin<{
prefix
:
string
;
commands
:
{
name
:
string
;
return
:
string
}[];
}
>
{
@
For
<
MyPlugin2
>
(({
config
})
=>
config
.
commands
)
@
For
(({
config
})
=>
config
.
commands
)
@
If
<
MyPlugin2
>
((
_
,
def
)
=>
def
.
name
!==
'
badthing
'
)
@
UseCommand
(
'
{{name}}
'
)
onCommand
(
...
...
tests/inject-using.spec.ts
View file @
5a2257f6
import
{
RegisterSchema
,
SchemaProperty
}
from
'
..
'
;
import
{
RegisterSchema
,
SchemaProperty
,
StarterPlugin
}
from
'
..
'
;
import
{
Assets
,
Bot
,
Cache
,
Context
}
from
'
koishi
'
;
import
{
Inject
,
PluginName
,
PluginSchema
,
UsingService
,
}
from
'
../src/decorators
'
;
import
{
Inject
,
PluginName
,
UsingService
}
from
'
../src/decorators
'
;
import
{
DefinePlugin
}
from
'
../src/register
'
;
@
RegisterSchema
()
...
...
@@ -15,12 +10,11 @@ class Config {
}
describe
(
'
InjectUsing
'
,
()
=>
{
@
PluginSchema
(
Config
)
@
PluginName
(
'
foo-plugin
'
)
@
UsingService
(
'
router
'
)
@
DefinePlugin
({
using
:
[
'
database
'
]
})
@
DefinePlugin
({
using
:
[
'
database
'
]
,
schema
:
Config
})
@
UsingService
(
'
http
'
)
class
MyPlugin
{
class
MyPlugin
extends
StarterPlugin
(
Config
)
{
@
Inject
(
true
)
cache
:
Cache
;
...
...
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