@cordisjs/loader
Advanced tools
Comparing version 0.8.4 to 0.8.5
@@ -64,3 +64,9 @@ /// <reference types="node" resolution-mode="require"/> | ||
} | ||
export function group(ctx: Context, config: Entry.Options[]): void; | ||
export const kGroup: unique symbol; | ||
export interface GroupOptions { | ||
initial?: Omit<Entry.Options, 'id'>[]; | ||
allowd?: string[]; | ||
} | ||
export function createGroup(config?: Entry.Options[], options?: GroupOptions): (ctx: Context, config: Entry.Options[]) => void; | ||
export const group: (ctx: Context, config: Entry.Options[]) => void; | ||
export namespace Entry { | ||
@@ -67,0 +73,0 @@ interface Options { |
@@ -327,27 +327,35 @@ var __defProp = Object.defineProperty; | ||
}; | ||
function group(ctx, config) { | ||
for (const entry of config) { | ||
ctx.loader.update(ctx, entry); | ||
var kGroup = Symbol("cordis.group"); | ||
function createGroup(config, options = {}) { | ||
options.initial = config; | ||
function group2(ctx, config2) { | ||
for (const entry of config2) { | ||
ctx.loader.update(ctx, entry); | ||
} | ||
ctx.accept((neo) => { | ||
const old = ctx.scope.config; | ||
const oldMap = Object.fromEntries(old.map((entry) => [entry.id || Symbol("anonymous"), entry])); | ||
const neoMap = Object.fromEntries(neo.map((entry) => [entry.id || Symbol("anonymous"), entry])); | ||
for (const id of Reflect.ownKeys({ ...oldMap, ...neoMap })) { | ||
if (!neoMap[id]) { | ||
ctx.loader.remove(ctx, oldMap[id]); | ||
} else { | ||
ctx.loader.update(ctx, neoMap[id]); | ||
} | ||
} | ||
}, { passive: true }); | ||
ctx.on("dispose", () => { | ||
for (const entry of ctx.scope.config) { | ||
ctx.loader.remove(ctx, entry); | ||
} | ||
}); | ||
} | ||
ctx.accept((neo) => { | ||
const old = ctx.scope.config; | ||
const oldMap = Object.fromEntries(old.map((entry) => [entry.id || Symbol("anonymous"), entry])); | ||
const neoMap = Object.fromEntries(neo.map((entry) => [entry.id || Symbol("anonymous"), entry])); | ||
for (const id of Reflect.ownKeys({ ...oldMap, ...neoMap })) { | ||
if (!neoMap[id]) { | ||
ctx.loader.remove(ctx, oldMap[id]); | ||
} else { | ||
ctx.loader.update(ctx, neoMap[id]); | ||
} | ||
} | ||
}, { passive: true }); | ||
ctx.on("dispose", () => { | ||
for (const entry of ctx.scope.config) { | ||
ctx.loader.remove(ctx, entry); | ||
} | ||
}); | ||
__name(group2, "group"); | ||
defineProperty(group2, "inject", ["loader"]); | ||
defineProperty(group2, "reusable", true); | ||
defineProperty(group2, kGroup, options); | ||
return group2; | ||
} | ||
__name(group, "group"); | ||
defineProperty(group, "inject", ["loader"]); | ||
defineProperty(group, "reusable", true); | ||
__name(createGroup, "createGroup"); | ||
var group = createGroup(); | ||
var shared_default = Loader; | ||
@@ -407,5 +415,7 @@ | ||
Loader, | ||
createGroup, | ||
src_default as default, | ||
group | ||
group, | ||
kGroup | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -327,33 +327,43 @@ var __defProp = Object.defineProperty; | ||
}; | ||
function group(ctx, config) { | ||
for (const entry of config) { | ||
ctx.loader.update(ctx, entry); | ||
var kGroup = Symbol("cordis.group"); | ||
function createGroup(config, options = {}) { | ||
options.initial = config; | ||
function group2(ctx, config2) { | ||
for (const entry of config2) { | ||
ctx.loader.update(ctx, entry); | ||
} | ||
ctx.accept((neo) => { | ||
const old = ctx.scope.config; | ||
const oldMap = Object.fromEntries(old.map((entry) => [entry.id || Symbol("anonymous"), entry])); | ||
const neoMap = Object.fromEntries(neo.map((entry) => [entry.id || Symbol("anonymous"), entry])); | ||
for (const id of Reflect.ownKeys({ ...oldMap, ...neoMap })) { | ||
if (!neoMap[id]) { | ||
ctx.loader.remove(ctx, oldMap[id]); | ||
} else { | ||
ctx.loader.update(ctx, neoMap[id]); | ||
} | ||
} | ||
}, { passive: true }); | ||
ctx.on("dispose", () => { | ||
for (const entry of ctx.scope.config) { | ||
ctx.loader.remove(ctx, entry); | ||
} | ||
}); | ||
} | ||
ctx.accept((neo) => { | ||
const old = ctx.scope.config; | ||
const oldMap = Object.fromEntries(old.map((entry) => [entry.id || Symbol("anonymous"), entry])); | ||
const neoMap = Object.fromEntries(neo.map((entry) => [entry.id || Symbol("anonymous"), entry])); | ||
for (const id of Reflect.ownKeys({ ...oldMap, ...neoMap })) { | ||
if (!neoMap[id]) { | ||
ctx.loader.remove(ctx, oldMap[id]); | ||
} else { | ||
ctx.loader.update(ctx, neoMap[id]); | ||
} | ||
} | ||
}, { passive: true }); | ||
ctx.on("dispose", () => { | ||
for (const entry of ctx.scope.config) { | ||
ctx.loader.remove(ctx, entry); | ||
} | ||
}); | ||
__name(group2, "group"); | ||
defineProperty(group2, "inject", ["loader"]); | ||
defineProperty(group2, "reusable", true); | ||
defineProperty(group2, kGroup, options); | ||
return group2; | ||
} | ||
__name(group, "group"); | ||
defineProperty(group, "inject", ["loader"]); | ||
defineProperty(group, "reusable", true); | ||
__name(createGroup, "createGroup"); | ||
var group = createGroup(); | ||
var shared_default = Loader; | ||
export { | ||
Loader, | ||
createGroup, | ||
shared_default as default, | ||
group | ||
group, | ||
kGroup | ||
}; | ||
//# sourceMappingURL=shared.js.map |
{ | ||
"name": "@cordisjs/loader", | ||
"description": "Loader for cordis", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"type": "module", | ||
@@ -40,12 +40,12 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@cordisjs/core": "^3.13.4" | ||
"@cordisjs/core": "^3.13.5" | ||
}, | ||
"peerDependencies": { | ||
"@cordisjs/core": "^3.13.4" | ||
"@cordisjs/core": "^3.13.5" | ||
}, | ||
"dependencies": { | ||
"cosmokit": "^1.5.2", | ||
"dotenv": "^16.3.1", | ||
"cosmokit": "^1.6.2", | ||
"dotenv": "^16.4.5", | ||
"js-yaml": "^4.1.0" | ||
} | ||
} |
@@ -265,33 +265,49 @@ import { Context, EffectScope, ForkScope, Service } from '@cordisjs/core' | ||
export function group(ctx: Context, config: Entry.Options[]) { | ||
for (const entry of config) { | ||
ctx.loader.update(ctx, entry) | ||
} | ||
export const kGroup = Symbol('cordis.group') | ||
ctx.accept((neo: Entry.Options[]) => { | ||
// update config reference | ||
const old = ctx.scope.config as Entry.Options[] | ||
const oldMap: any = Object.fromEntries(old.map(entry => [entry.id || Symbol('anonymous'), entry])) | ||
const neoMap: any = Object.fromEntries(neo.map(entry => [entry.id || Symbol('anonymous'), entry])) | ||
export interface GroupOptions { | ||
initial?: Omit<Entry.Options, 'id'>[] | ||
allowd?: string[] | ||
} | ||
// update inner plugins | ||
for (const id of Reflect.ownKeys({ ...oldMap, ...neoMap })) { | ||
if (!neoMap[id]) { | ||
ctx.loader.remove(ctx, oldMap[id]) | ||
} else { | ||
ctx.loader.update(ctx, neoMap[id]) | ||
} | ||
export function createGroup(config?: Entry.Options[], options: GroupOptions = {}) { | ||
options.initial = config | ||
function group(ctx: Context, config: Entry.Options[]) { | ||
for (const entry of config) { | ||
ctx.loader.update(ctx, entry) | ||
} | ||
}, { passive: true }) | ||
ctx.on('dispose', () => { | ||
for (const entry of ctx.scope.config as Entry.Options[]) { | ||
ctx.loader.remove(ctx, entry) | ||
} | ||
}) | ||
ctx.accept((neo: Entry.Options[]) => { | ||
// update config reference | ||
const old = ctx.scope.config as Entry.Options[] | ||
const oldMap: any = Object.fromEntries(old.map(entry => [entry.id || Symbol('anonymous'), entry])) | ||
const neoMap: any = Object.fromEntries(neo.map(entry => [entry.id || Symbol('anonymous'), entry])) | ||
// update inner plugins | ||
for (const id of Reflect.ownKeys({ ...oldMap, ...neoMap })) { | ||
if (!neoMap[id]) { | ||
ctx.loader.remove(ctx, oldMap[id]) | ||
} else { | ||
ctx.loader.update(ctx, neoMap[id]) | ||
} | ||
} | ||
}, { passive: true }) | ||
ctx.on('dispose', () => { | ||
for (const entry of ctx.scope.config as Entry.Options[]) { | ||
ctx.loader.remove(ctx, entry) | ||
} | ||
}) | ||
} | ||
defineProperty(group, 'inject', ['loader']) | ||
defineProperty(group, 'reusable', true) | ||
defineProperty(group, kGroup, options) | ||
return group | ||
} | ||
defineProperty(group, 'inject', ['loader']) | ||
defineProperty(group, 'reusable', true) | ||
export const group = createGroup() | ||
export default Loader |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
AI-detected potential security risk
Supply chain riskAI has determined that this package may contain potential security issues or vulnerabilities.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
61266
1311
20
3
Updatedcosmokit@^1.6.2
Updateddotenv@^16.4.5