dev: expose more core definitions to extensions

This commit is contained in:
KernelDeimos
2024-11-01 15:39:25 -04:00
parent a614145250
commit 4b6c70fa5e
2 changed files with 19 additions and 3 deletions

View File

@@ -57,7 +57,13 @@ const install = async ({ services, app, useapi, modapi }) => {
def('Module', AdvancedBase);
def('Library', Library);
def('core.util.helpers', require('./helpers'));
def('puter.middlewares.auth', require('./middleware/auth2'));
def('puter.middlewares.anticsrf', require('./middleware/anticsrf'));
def('core.APIError', require('./api/APIError'));
def('core', require('./services/auth/Actor'), { assign: true });
});
// === LIBRARIES ===
@@ -69,7 +75,7 @@ const install = async ({ services, app, useapi, modapi }) => {
services.registerService('lib-type-tagged', LibTypeTagged);
});
modapi.libdir('lib.core', './util');
modapi.libdir('core.util', './util');
// === SERVICES ===

View File

@@ -79,7 +79,7 @@ let default_fn = () => {
};
const library = {
use,
def: (name, value) => {
def: (name, value, options = {}) => {
const parts = name.split('.');
let obj = use;
for ( const part of parts.slice(0, -1) ) {
@@ -89,7 +89,17 @@ let default_fn = () => {
obj = obj[part];
}
obj[parts[parts.length - 1]] = value;
const lastpart = parts[parts.length - 1];
if ( options.assign ) {
if ( ! obj[lastpart] ) {
obj[lastpart] = {};
}
Object.assign(obj[lastpart], value);
return;
}
obj[lastpart] = value;
},
withuse: fn => {
return globalwith({