-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(market): on-demand loading for versions
- Loading branch information
Showing
12 changed files
with
111 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,37 @@ | ||
import { Context, Dict, Schema } from 'koishi' | ||
import { Context, Dict } from 'koishi' | ||
import { DataService } from '@koishijs/plugin-console' | ||
import { DependencyMetaKey, RemotePackage } from '@koishijs/registry' | ||
import { Dependency } from './installer' | ||
import { throttle } from 'throttle-debounce' | ||
|
||
declare module '@koishijs/plugin-console' { | ||
interface Events { | ||
'market/install'(deps: Dict<string>): Promise<number> | ||
class DependencyProvider extends DataService<Dict<Dependency>> { | ||
constructor(public ctx: Context) { | ||
super(ctx, 'dependencies', { authority: 4 }) | ||
} | ||
} | ||
|
||
class Dependencies extends DataService<Dependencies.Payload> { | ||
constructor(public ctx: Context, public config: Dependencies.Config) { | ||
super(ctx, 'dependencies', { authority: 4 }) | ||
async get() { | ||
return this.ctx.installer.getDeps() | ||
} | ||
} | ||
|
||
ctx.console.addListener('market/install', async (deps) => { | ||
const code = await ctx.installer.install(deps) | ||
this.refresh() | ||
this.ctx.console.packages?.refresh() | ||
return code | ||
}, { authority: 4 }) | ||
class RegistryProvider extends DataService<Dict<Dict<Pick<RemotePackage, DependencyMetaKey>>>> { | ||
constructor(public ctx: Context) { | ||
super(ctx, 'registry', { authority: 4 }) | ||
} | ||
|
||
stop() { | ||
this.flushData.cancel() | ||
} | ||
|
||
flushData = throttle(500, () => { | ||
console.log(this.ctx.installer.tempCache) | ||
this.ctx.console.broadcast('market/registry', this.ctx.installer.tempCache) | ||
this.ctx.installer.tempCache = {} | ||
}) | ||
|
||
async get(force = false) { | ||
return this.ctx.installer.get(force) | ||
} | ||
} | ||
|
||
namespace Dependencies { | ||
export interface Config {} | ||
export const Config: Schema<Config> = Schema.object({}) | ||
|
||
export interface Payload { | ||
dependencies: Dict<Dependency> | ||
registry: Dict<Dict<Pick<RemotePackage, DependencyMetaKey>>> | ||
async get() { | ||
return this.ctx.installer.fullCache | ||
} | ||
} | ||
|
||
export default Dependencies | ||
export { DependencyProvider, RegistryProvider } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.