mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
refactor(backend): rename traits to features
This commit is contained in:
parent
7aadae58ce
commit
f7d15bae41
@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { AsyncProviderTrait } = require("../../traits/AsyncProviderTrait");
|
||||
const { AsyncProviderFeature } = require("../../traits/AsyncProviderFeature");
|
||||
const { HLMkdir, QuickMkdir } = require("../hl_operations/hl_mkdir");
|
||||
const { Context } = require("../../util/context");
|
||||
const { HLWrite } = require("../hl_operations/hl_write");
|
||||
@ -32,8 +32,8 @@ const { HLRemove } = require("../hl_operations/hl_remove");
|
||||
|
||||
|
||||
class BatchCommand extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
new AsyncProviderTrait(),
|
||||
static FEATURES = [
|
||||
new AsyncProviderFeature(),
|
||||
]
|
||||
static async run (executor, parameters) {
|
||||
const instance = new this();
|
||||
|
@ -26,8 +26,8 @@ const StringParam = require('../../api/filesystem/StringParam');
|
||||
const FlagParam = require("../../api/filesystem/FlagParam");
|
||||
const UserParam = require('../../api/filesystem/UserParam');
|
||||
const FSNodeContext = require('../FSNodeContext');
|
||||
const { ContextAwareTrait } = require('../../traits/ContextAwareTrait');
|
||||
const { OtelTrait } = require('../../traits/OtelTrait');
|
||||
const { ContextAwareFeature } = require('../../traits/ContextAwareFeature');
|
||||
const { OtelFeature } = require('../../traits/OtelFeature');
|
||||
const { HLFilesystemOperation } = require('./definitions');
|
||||
const { is_valid_path } = require('../validation');
|
||||
const { HLRemove } = require('./hl_remove');
|
||||
@ -249,8 +249,8 @@ class HLMkdir extends HLFilesystemOperation {
|
||||
parent_directories_created: () => [],
|
||||
}
|
||||
|
||||
static TRAITS = [
|
||||
new OtelTrait([
|
||||
static FEATURES = [
|
||||
new OtelFeature([
|
||||
'_get_existing_parent',
|
||||
'_create_parents',
|
||||
]),
|
||||
|
@ -33,7 +33,7 @@ const { HLFilesystemOperation } = require("./definitions");
|
||||
const { MkTree } = require("./hl_mkdir");
|
||||
const { Actor } = require("../../services/auth/Actor");
|
||||
|
||||
class WriteCommonTrait {
|
||||
class WriteCommonFeature {
|
||||
install_in_instance (instance) {
|
||||
instance._verify_size = async function () {
|
||||
if (
|
||||
@ -84,8 +84,8 @@ class HLWrite extends HLFilesystemOperation {
|
||||
- create shortcuts
|
||||
`
|
||||
|
||||
static TRAITS = [
|
||||
new WriteCommonTrait(),
|
||||
static FEATURES = [
|
||||
new WriteCommonFeature(),
|
||||
]
|
||||
|
||||
static PARAMETERS = {
|
||||
|
@ -21,7 +21,7 @@ const { id2path } = require("../../helpers");
|
||||
|
||||
const { PuterPath } = require("../lib/PuterPath");
|
||||
const { NodeUIDSelector } = require("../node/selectors");
|
||||
const { OtelTrait } = require("../../traits/OtelTrait");
|
||||
const { OtelFeature } = require("../../traits/OtelFeature");
|
||||
const { Context } = require("../../util/context");
|
||||
const { DB_WRITE } = require("../../services/database/consts");
|
||||
|
||||
@ -195,8 +195,8 @@ class DatabaseFSEntryService extends AdvancedBase {
|
||||
static STATUS_READY = {};
|
||||
static STATUS_RUNNING_JOB = {};
|
||||
|
||||
static TRAITS = [
|
||||
new OtelTrait([
|
||||
static FEATURES = [
|
||||
new OtelFeature([
|
||||
'insert',
|
||||
'update',
|
||||
'delete',
|
||||
|
@ -17,13 +17,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { WeakConstructorTrait } = require("../traits/WeakConstructorTrait");
|
||||
const { WeakConstructorFeature } = require("../traits/WeakConstructorFeature");
|
||||
const { Eq, And } = require("./query/query");
|
||||
const { Entity } = require("./entitystorage/Entity");
|
||||
|
||||
class IdentifierUtil extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
new WeakConstructorTrait(),
|
||||
static FEATURES = [
|
||||
new WeakConstructorFeature(),
|
||||
]
|
||||
|
||||
async detect_identifier (object) {
|
||||
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { instance_ } = require("../../monitor/PerformanceMonitor");
|
||||
const { WeakConstructorTrait } = require("../../traits/WeakConstructorTrait");
|
||||
const { WeakConstructorFeature } = require("../../traits/WeakConstructorFeature");
|
||||
const { Property } = require("./Property");
|
||||
const { Entity } = require("../entitystorage/Entity");
|
||||
const FSNodeContext = require("../../filesystem/FSNodeContext");
|
||||
@ -29,13 +29,13 @@ const FSNodeContext = require("../../filesystem/FSNodeContext");
|
||||
* Both wrapping and registering are done by RegistrantService.
|
||||
*/
|
||||
class Mapping extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
static FEATURES = [
|
||||
// Whenever you can override something, it's reasonable to want
|
||||
// to pull the desired implementation from somewhere else to
|
||||
// avoid repeating yourself. Class constructors are one of a few
|
||||
// examples where this is typically not possible.
|
||||
// However, javascript is magic, and we do what we want.
|
||||
new WeakConstructorTrait(),
|
||||
new WeakConstructorFeature(),
|
||||
]
|
||||
|
||||
static create (context, data) {
|
||||
|
@ -17,11 +17,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { WeakConstructorTrait } = require("../../traits/WeakConstructorTrait");
|
||||
const { WeakConstructorFeature } = require("../../traits/WeakConstructorFeature");
|
||||
|
||||
class PropType extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
new WeakConstructorTrait(),
|
||||
static FEATURES = [
|
||||
new WeakConstructorFeature(),
|
||||
]
|
||||
|
||||
static create (context, data, k) {
|
||||
|
@ -17,11 +17,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { WeakConstructorTrait } = require("../../traits/WeakConstructorTrait");
|
||||
const { WeakConstructorFeature } = require("../../traits/WeakConstructorFeature");
|
||||
|
||||
class Property extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
new WeakConstructorTrait(),
|
||||
static FEATURES = [
|
||||
new WeakConstructorFeature(),
|
||||
]
|
||||
|
||||
static create (context, name, descriptor) {
|
||||
|
@ -17,15 +17,15 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { WeakConstructorTrait } = require("../../traits/WeakConstructorTrait");
|
||||
const { WeakConstructorFeature } = require("../../traits/WeakConstructorFeature");
|
||||
const { Context } = require("../../util/context");
|
||||
|
||||
/**
|
||||
* BaseES is a base class for Entity Store classes.
|
||||
*/
|
||||
class BaseES extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
new WeakConstructorTrait(),
|
||||
static FEATURES = [
|
||||
new WeakConstructorFeature(),
|
||||
]
|
||||
|
||||
// Default implementations
|
||||
|
@ -17,11 +17,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { WeakConstructorTrait } = require("../../traits/WeakConstructorTrait");
|
||||
const { WeakConstructorFeature } = require("../../traits/WeakConstructorFeature");
|
||||
|
||||
class Entity extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
new WeakConstructorTrait(),
|
||||
static FEATURES = [
|
||||
new WeakConstructorFeature(),
|
||||
]
|
||||
|
||||
constructor (args) {
|
||||
|
@ -21,14 +21,14 @@ const { BaseES } = require("./BaseES");
|
||||
|
||||
const APIError = require("../../api/APIError");
|
||||
const { Entity } = require("./Entity");
|
||||
const { WeakConstructorTrait } = require("../../traits/WeakConstructorTrait");
|
||||
const { WeakConstructorFeature } = require("../../traits/WeakConstructorFeature");
|
||||
const { And, Or, Eq, Like, Null, Predicate, PredicateUtil, IsNotNull } = require("../query/query");
|
||||
const { DB_WRITE } = require("../../services/database/consts");
|
||||
|
||||
class RawCondition extends AdvancedBase {
|
||||
// properties: sql:string, values:any[]
|
||||
static TRAITS = [
|
||||
new WeakConstructorTrait(),
|
||||
static FEATURES = [
|
||||
new WeakConstructorFeature(),
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -17,11 +17,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { WeakConstructorTrait } = require("../../traits/WeakConstructorTrait");
|
||||
const { WeakConstructorFeature } = require("../../traits/WeakConstructorFeature");
|
||||
|
||||
class Predicate extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
new WeakConstructorTrait(),
|
||||
static FEATURES = [
|
||||
new WeakConstructorFeature(),
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class EntityStoreService extends BaseService {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: can replace these with MethodProxyTrait
|
||||
// TODO: can replace these with MethodProxyFeature
|
||||
async create (entity) {
|
||||
return await this.upstream.upsert(entity, { old_entity: null });
|
||||
}
|
||||
|
@ -18,10 +18,10 @@
|
||||
*/
|
||||
const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const { Context } = require("../util/context");
|
||||
const { ContextAwareTrait } = require("../traits/ContextAwareTrait");
|
||||
const { OtelTrait } = require("../traits/OtelTrait");
|
||||
const { ContextAwareFeature } = require("../traits/ContextAwareFeature");
|
||||
const { OtelFeature } = require("../traits/OtelFeature");
|
||||
const APIError = require("../api/APIError");
|
||||
const { AssignableMethodsTrait } = require("../traits/AssignableMethodsTrait");
|
||||
const { AssignableMethodsFeature } = require("../traits/AssignableMethodsFeature");
|
||||
|
||||
const CONTEXT_KEY = Context.make_context_key('operation-trace');
|
||||
|
||||
@ -220,10 +220,10 @@ class OperationTraceService {
|
||||
}
|
||||
|
||||
class BaseOperation extends AdvancedBase {
|
||||
static TRAITS = [
|
||||
new ContextAwareTrait(),
|
||||
new OtelTrait(['run']),
|
||||
new AssignableMethodsTrait(),
|
||||
static FEATURES = [
|
||||
new ContextAwareFeature(),
|
||||
new OtelFeature(['run']),
|
||||
new AssignableMethodsFeature(),
|
||||
]
|
||||
|
||||
async run (values) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { get_user, get_app } = require("../../helpers");
|
||||
const { AssignableMethodsTrait } = require("../../traits/AssignableMethodsTrait");
|
||||
const { AssignableMethodsFeature } = require("../../traits/AssignableMethodsFeature");
|
||||
const { Context } = require("../../util/context");
|
||||
const BaseService = require("../BaseService");
|
||||
const { DB_WRITE } = require("../database/consts");
|
||||
|
@ -20,7 +20,7 @@ const { AdvancedBase } = require("@heyputer/puter-js-common");
|
||||
const APIError = require("../../api/APIError");
|
||||
const { Context } = require("../../util/context");
|
||||
const BaseService = require("../BaseService");
|
||||
const { SyncTrait } = require("../../traits/SyncTrait");
|
||||
const { SyncFeature } = require("../../traits/SyncFeature");
|
||||
const { DB_WRITE } = require("../database/consts");
|
||||
|
||||
const ts_to_sql = (ts) => Math.floor(ts / 1000);
|
||||
@ -31,8 +31,8 @@ class RateLimitService extends BaseService {
|
||||
kv: globalThis.kv,
|
||||
}
|
||||
|
||||
static TRAITS = [
|
||||
new SyncTrait([
|
||||
static FEATURES = [
|
||||
new SyncFeature([
|
||||
'check_and_increment',
|
||||
]),
|
||||
]
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
class AssignableMethodsTrait {
|
||||
class AssignableMethodsFeature {
|
||||
install_in_instance (instance) {
|
||||
const methods = instance._get_merged_static_object('METHODS');
|
||||
|
||||
@ -27,5 +27,5 @@ class AssignableMethodsTrait {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AssignableMethodsTrait
|
||||
AssignableMethodsFeature
|
||||
};
|
@ -16,18 +16,18 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
class AsyncProviderTrait {
|
||||
class AsyncProviderFeature {
|
||||
install_in_instance (instance) {
|
||||
instance.valueListeners_ = {};
|
||||
instance.valueFactories_ = {};
|
||||
instance.values_ = {};
|
||||
instance.rejections_ = {};
|
||||
|
||||
instance.provideValue = AsyncProviderTrait.prototype.provideValue;
|
||||
instance.rejectValue = AsyncProviderTrait.prototype.rejectValue;
|
||||
instance.awaitValue = AsyncProviderTrait.prototype.awaitValue;
|
||||
instance.onValue = AsyncProviderTrait.prototype.onValue;
|
||||
instance.setFactory = AsyncProviderTrait.prototype.setFactory;
|
||||
instance.provideValue = AsyncProviderFeature.prototype.provideValue;
|
||||
instance.rejectValue = AsyncProviderFeature.prototype.rejectValue;
|
||||
instance.awaitValue = AsyncProviderFeature.prototype.awaitValue;
|
||||
instance.onValue = AsyncProviderFeature.prototype.onValue;
|
||||
instance.setFactory = AsyncProviderFeature.prototype.setFactory;
|
||||
}
|
||||
|
||||
provideValue (key, value) {
|
||||
@ -116,5 +116,5 @@ class AsyncProviderTrait {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AsyncProviderTrait
|
||||
AsyncProviderFeature
|
||||
};
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
const { Context } = require("../util/context");
|
||||
|
||||
class ContextAwareTrait {
|
||||
class ContextAwareFeature {
|
||||
install_in_instance (instance) {
|
||||
instance.context = Context.get();
|
||||
instance.x = instance.context;
|
||||
@ -26,5 +26,5 @@ class ContextAwareTrait {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ContextAwareTrait,
|
||||
ContextAwareFeature,
|
||||
};
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
const { Context } = require("../util/context");
|
||||
|
||||
class OtelTrait {
|
||||
class OtelFeature {
|
||||
constructor (method_include_list) {
|
||||
this.method_include_list = method_include_list;
|
||||
}
|
||||
@ -44,7 +44,7 @@ class OtelTrait {
|
||||
}
|
||||
}
|
||||
|
||||
class SyncOtelTrait {
|
||||
class SyncOtelFeature {
|
||||
constructor (method_include_list) {
|
||||
this.method_include_list = method_include_list;
|
||||
}
|
||||
@ -72,5 +72,5 @@ class SyncOtelTrait {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
OtelTrait
|
||||
OtelFeature
|
||||
};
|
@ -18,7 +18,7 @@
|
||||
*/
|
||||
const { Lock } = require("../util/promise");
|
||||
|
||||
class SyncTrait {
|
||||
class SyncFeature {
|
||||
constructor (method_include_list) {
|
||||
this.method_include_list = method_include_list;
|
||||
}
|
||||
@ -37,5 +37,5 @@ class SyncTrait {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
SyncTrait,
|
||||
SyncFeature,
|
||||
};
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
class WeakConstructorTrait {
|
||||
class WeakConstructorFeature {
|
||||
install_in_instance(instance, { parameters }) {
|
||||
for ( const key in parameters ) {
|
||||
instance[key] = parameters[key];
|
||||
@ -25,5 +25,5 @@ class WeakConstructorTrait {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
WeakConstructorTrait,
|
||||
WeakConstructorFeature,
|
||||
};
|
@ -19,12 +19,12 @@
|
||||
// This doesn't go in ./bases because it logically depends on
|
||||
// both ./bases and ./traits, and ./traits depends on ./bases.
|
||||
|
||||
const { TraitBase } = require("./bases/TraitBase");
|
||||
const { FeatureBase } = require("./bases/FeatureBase");
|
||||
|
||||
class AdvancedBase extends TraitBase {
|
||||
static TRAITS = [
|
||||
require('./traits/NodeModuleDITrait'),
|
||||
require('./traits/PropertiesTrait'),
|
||||
class AdvancedBase extends FeatureBase {
|
||||
static FEATURES = [
|
||||
require('./features/NodeModuleDIFeature'),
|
||||
require('./features/PropertiesFeature'),
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,11 @@
|
||||
*/
|
||||
const { BasicBase } = require("./BasicBase");
|
||||
|
||||
class TraitBase extends BasicBase {
|
||||
class FeatureBase extends BasicBase {
|
||||
constructor (parameters, ...a) {
|
||||
super(parameters, ...a);
|
||||
for ( const trait of this.traits ) {
|
||||
trait.install_in_instance(
|
||||
for ( const feature of this.features ) {
|
||||
feature.install_in_instance(
|
||||
this,
|
||||
{
|
||||
parameters: parameters || {},
|
||||
@ -31,11 +31,11 @@ class TraitBase extends BasicBase {
|
||||
}
|
||||
}
|
||||
|
||||
get traits () {
|
||||
return this._get_merged_static_array('TRAITS');
|
||||
get features () {
|
||||
return this._get_merged_static_array('FEATURES');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
TraitBase,
|
||||
FeatureBase,
|
||||
};
|
Loading…
Reference in New Issue
Block a user