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
bcea58d2
Commit
bcea58d2
authored
May 07, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
put everything in metadata
parent
127e7cbd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
19 deletions
+30
-19
src/decorators.ts
src/decorators.ts
+1
-8
src/def/constants.ts
src/def/constants.ts
+2
-0
src/def/interfaces.ts
src/def/interfaces.ts
+1
-4
src/register.ts
src/register.ts
+13
-6
tests/inject-using.spec.ts
tests/inject-using.spec.ts
+13
-1
No files found.
src/decorators.ts
View file @
bcea58d2
...
...
@@ -96,14 +96,7 @@ export const InjectContext = (select?: Selection) =>
export
const
InjectApp
=
()
=>
InjectSystem
((
obj
)
=>
obj
.
__ctx
.
app
);
export
const
InjectConfig
=
()
=>
InjectSystem
((
obj
)
=>
obj
.
__config
);
export
const
InjectLogger
=
(
name
?:
string
)
=>
InjectSystem
((
obj
,
config
)
=>
obj
.
__ctx
.
logger
(
name
||
config
.
name
||
Object
.
getPrototypeOf
(
Object
.
getPrototypeOf
(
obj
))?.
constructor
?.
name
||
'
default
'
,
),
);
InjectSystem
((
obj
)
=>
obj
.
__ctx
.
logger
(
name
||
obj
.
constructor
.
name
));
export
const
Caller
=
()
=>
InjectSystem
((
obj
)
=>
{
const
targetCtx
:
Context
=
obj
[
Context
.
current
]
||
obj
.
__ctx
;
...
...
src/def/constants.ts
View file @
bcea58d2
...
...
@@ -28,3 +28,5 @@ export interface MetadataMap {
KoishiPredefineSchema
:
Schema
|
ClassType
<
any
>
;
KoishiPredefineName
:
string
;
}
export
const
ThirdEyeSym
=
Symbol
(
'
ThirdEyeSym
'
);
src/def/interfaces.ts
View file @
bcea58d2
...
...
@@ -5,10 +5,7 @@ export * from 'koishi-decorators/dist/src/def/interfaces';
// Command stuff
export
type
SystemInjectFun
=
<
T
=
any
>
(
obj
:
PluginClass
<
T
>
,
pluginMeta
:
KoishiPluginRegistrationOptions
<
T
>
,
)
=>
any
;
export
type
SystemInjectFun
=
<
T
=
any
>
(
obj
:
PluginClass
<
T
>
)
=>
any
;
export
interface
ProvideOptions
{
immediate
?:
boolean
;
...
...
src/register.ts
View file @
bcea58d2
...
...
@@ -12,6 +12,7 @@ import { reflector } from './meta/meta-fetch';
import
{
SchemaClass
}
from
'
schemastery-gen
'
;
import
_
from
'
lodash
'
;
import
{
Registrar
,
Type
}
from
'
koishi-decorators
'
;
import
{
PluginName
,
PluginSchema
,
UsingService
}
from
'
./decorators
'
;
export
interface
KoishiPluginRegistrationOptions
<
T
=
any
>
{
name
?:
string
;
...
...
@@ -52,19 +53,26 @@ export function DefinePlugin<T = any>(
new
(...
args
:
any
[]):
any
;
}
&
KoishiPluginRegistrationOptions
<
T
>
,
>
(
originalClass
:
C
)
{
if
(
options
.
name
)
{
PluginName
(
options
.
name
)(
originalClass
);
}
if
(
options
.
schema
)
{
PluginSchema
(
options
.
schema
)(
originalClass
);
}
if
(
options
.
using
)
{
UsingService
(...
options
.
using
)(
originalClass
);
}
const
newClass
=
class
extends
originalClass
implements
PluginClass
{
static
get
Config
()
{
const
schemaType
=
reflector
.
get
(
'
KoishiPredefineSchema
'
,
newClass
)
||
reflector
.
get
(
'
KoishiPredefineSchema
'
,
originalClass
)
||
options
.
schema
;
reflector
.
get
(
'
KoishiPredefineSchema
'
,
originalClass
);
return
schemaType
?
SchemaClass
(
schemaType
)
:
undefined
;
}
static
get
using
()
{
const
list
=
reflector
.
getArray
(
KoishiAddUsingList
,
originalClass
)
.
concat
(
options
.
using
||
[])
.
concat
(
reflector
.
getArray
(
KoishiAddUsingList
,
newClass
));
return
_
.
uniq
(
list
);
}
...
...
@@ -81,7 +89,7 @@ export function DefinePlugin<T = any>(
Object
.
defineProperty
(
this
,
key
,
{
configurable
:
true
,
enumerable
:
true
,
get
:
()
=>
valueFunction
(
this
,
options
),
get
:
()
=>
valueFunction
(
this
),
});
}
}
...
...
@@ -135,7 +143,7 @@ export function DefinePlugin<T = any>(
methodKey
,
);
if
(
partialUsing
.
length
)
{
const
name
=
`
${
options
.
name
||
original
Class
.
name
}
-
${
methodKey
}
`
;
const
name
=
`
${
new
Class
.
name
}
-
${
methodKey
}
`
;
const
innerPlugin
:
Plugin
.
Object
=
{
name
,
using
:
partialUsing
,
...
...
@@ -233,7 +241,6 @@ export function DefinePlugin<T = any>(
get
:
()
=>
reflector
.
get
(
'
KoishiPredefineName
'
,
newClass
)
||
reflector
.
get
(
'
KoishiPredefineName
'
,
originalClass
)
||
options
.
name
||
originalClass
.
name
,
});
return
newClass
;
...
...
tests/inject-using.spec.ts
View file @
bcea58d2
import
{
DefinePlugin
,
Inject
,
UsingService
}
from
'
..
'
;
import
{
RegisterSchema
,
SchemaProperty
}
from
'
..
'
;
import
{
Assets
,
Bot
,
Cache
,
Context
}
from
'
koishi
'
;
import
{
PluginName
,
UsingService
,
Inject
,
PluginSchema
}
from
'
../src/decorators
'
;
import
{
DefinePlugin
}
from
'
../src/register
'
;
@
RegisterSchema
()
class
Config
{
@
SchemaProperty
()
foo
:
string
;
}
describe
(
'
InjectUsing
'
,
()
=>
{
@
PluginSchema
(
Config
)
@
PluginName
(
'
foo-plugin
'
)
@
UsingService
(
'
router
'
)
@
DefinePlugin
({
using
:
[
'
database
'
]
})
@
UsingService
(
'
http
'
)
...
...
@@ -17,6 +27,8 @@ describe('InjectUsing', () => {
}
it
(
'
Should include injected using services
'
,
()
=>
{
expect
(
MyPlugin
.
name
).
toBe
(
'
foo-plugin
'
);
expect
(
MyPlugin
[
'
Config
'
]).
toEqual
(
Config
);
const
usingList
=
(
MyPlugin
as
any
).
using
as
(
keyof
Context
.
Services
)[];
expect
(
usingList
).
toBeInstanceOf
(
Array
);
expect
(
usingList
.
length
).
toEqual
(
5
);
...
...
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