Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
cordis-decorators
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
cordis-decorators
Commits
b2222766
Commit
b2222766
authored
Jul 21, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add internal service
parent
76173704
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
2 deletions
+58
-2
src/decorators/plugin.ts
src/decorators/plugin.ts
+11
-0
src/registrar.ts
src/registrar.ts
+8
-2
tests/internal.spec.ts
tests/internal.spec.ts
+39
-0
No files found.
src/decorators/plugin.ts
View file @
b2222766
...
@@ -24,3 +24,14 @@ export function Inject(addUsing?: boolean): PropertyDecorator;
...
@@ -24,3 +24,14 @@ export function Inject(addUsing?: boolean): PropertyDecorator;
export
function
Inject
(...
args
:
[(
string
|
boolean
)?,
boolean
?])
{
export
function
Inject
(...
args
:
[(
string
|
boolean
)?,
boolean
?])
{
return
pluginDecorators
.
Inject
(...
args
);
return
pluginDecorators
.
Inject
(...
args
);
}
}
export
function
Internal
():
MethodDecorator
&
PropertyDecorator
{
return
(
obj
,
key
,
des
?)
=>
{
const
cls
=
obj
.
constructor
as
Context
.
MixinOptions
;
const
field
=
des
?
'
methods
'
:
'
properties
'
;
if
(
!
cls
[
field
])
{
cls
[
field
]
=
[];
}
cls
[
field
].
push
(
key
);
};
}
src/registrar.ts
View file @
b2222766
...
@@ -85,8 +85,9 @@ export namespace Registrar {
...
@@ -85,8 +85,9 @@ export namespace Registrar {
ctx
:
Ctx
;
ctx
:
Ctx
;
};
};
export
interface
ProvideOptions
extends
Context
.
ServiceOptions
{
export
interface
ProvideOptions
{
immediate
?:
boolean
;
immediate
?:
boolean
;
internal
?:
boolean
;
}
}
export
interface
ProvideDefinition
<
C
extends
Context
>
extends
ProvideOptions
{
export
interface
ProvideDefinition
<
C
extends
Context
>
extends
ProvideOptions
{
serviceName
:
string
;
serviceName
:
string
;
...
@@ -517,7 +518,12 @@ export class Registrar<Ctx extends Context> {
...
@@ -517,7 +518,12 @@ export class Registrar<Ctx extends Context> {
name
:
string
,
name
:
string
,
options
?:
Registrar
.
ProvideOptions
,
options
?:
Registrar
.
ProvideOptions
,
):
ClassDecorator
=>
{
):
ClassDecorator
=>
{
Context
.
service
(
name
,
options
);
if
(
options
?.
internal
)
{
return
(
cls
)
=>
{
Context
.
service
(
name
,
cls
);
};
}
Context
.
service
(
name
);
return
this
.
metadata
.
append
(
'
CordisPluginProvide
'
,
{
return
this
.
metadata
.
append
(
'
CordisPluginProvide
'
,
{
...
options
,
...
options
,
serviceName
:
name
,
serviceName
:
name
,
...
...
tests/internal.spec.ts
0 → 100644
View file @
b2222766
import
{
Inject
,
Internal
,
Provide
}
from
'
../src/decorators
'
;
import
{
DefinePlugin
,
StarterPlugin
}
from
'
./utility/decorators
'
;
import
{
LifecycleEvents
}
from
'
../src/plugin-def
'
;
import
{
Context
}
from
'
cordis
'
;
declare
module
'
cordis
'
{
// eslint-disable-next-line @typescript-eslint/no-namespace
interface
Context
{
foo
:
string
;
bar
():
number
;
baz
:
MyInternalService
;
}
}
@
Provide
(
'
baz
'
,
{
internal
:
true
})
@
DefinePlugin
()
class
MyInternalService
extends
StarterPlugin
()
{
@
Internal
()
foo
:
string
;
@
Internal
()
bar
()
{
return
5
;
}
}
describe
(
'
Apply and Connect in koishi-thirdeye
'
,
()
=>
{
let
app
:
Context
;
beforeEach
(()
=>
{
app
=
new
Context
();
});
it
(
'
should load internal service
'
,
()
=>
{
app
.
foo
=
'
msg
'
;
expect
(
app
.
foo
).
toBe
(
'
msg
'
);
expect
(
app
.
bar
()).
toBe
(
5
);
expect
(
app
.
baz
.
foo
).
toBe
(
'
msg
'
);
expect
(
app
.
baz
.
bar
()).
toBe
(
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