mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 14:18:43 +08:00
dev: AppES predicate transform for old name retry lookup
This commit is contained in:
parent
f1a8e98431
commit
eaaca2e9b9
@ -24,7 +24,7 @@ const { DB_WRITE } = require("../../services/database/consts");
|
||||
const { Context } = require("../../util/context");
|
||||
const { stream_to_buffer } = require("../../util/streamutil");
|
||||
const { origin_from_url } = require("../../util/urlutil");
|
||||
const { Eq, Like, Or } = require("../query/query");
|
||||
const { Eq, Like, Or, And } = require("../query/query");
|
||||
const { BaseES } = require("./BaseES");
|
||||
|
||||
const uuidv4 = require('uuid').v4;
|
||||
@ -213,6 +213,35 @@ class AppES extends BaseES {
|
||||
|
||||
return result;
|
||||
},
|
||||
async retry_predicate_rewrite ({ predicate }) {
|
||||
const recurse = async (predicate) => {
|
||||
if ( predicate instanceof Or ) {
|
||||
return new Or({
|
||||
children: await Promise.all(
|
||||
predicate.children.map(recurse)
|
||||
),
|
||||
});
|
||||
}
|
||||
if ( predicate instanceof And ) {
|
||||
return new And({
|
||||
children: await Promise.all(
|
||||
predicate.children.map(recurse)
|
||||
),
|
||||
});
|
||||
}
|
||||
if ( predicate instanceof Eq ) {
|
||||
if ( predicate.key === 'name' ) {
|
||||
const svc_oldAppName = this.context.get('services').get('old-app-name');
|
||||
const name_info = await svc_oldAppName.check_app_name(predicate.value);
|
||||
return new Eq({
|
||||
key: 'uid',
|
||||
value: name_info?.app_uid,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
return await recurse(predicate);
|
||||
},
|
||||
async read_transform (entity) {
|
||||
// Add file associations
|
||||
const rows = await this.db.read(
|
||||
|
@ -68,6 +68,7 @@ class BaseES extends AdvancedBase {
|
||||
const public_wrappers = [
|
||||
'upsert', 'read', 'delete', 'select',
|
||||
'read_transform',
|
||||
'retry_predicate_rewrite',
|
||||
];
|
||||
|
||||
this.impl_methods = this._get_merged_static_object('METHODS');
|
||||
@ -99,7 +100,14 @@ class BaseES extends AdvancedBase {
|
||||
.create(`ES:${this.entity_name}:${this.constructor.name}`);
|
||||
}
|
||||
async read (uid) {
|
||||
const entity = await this.call_on_impl_('read', uid);
|
||||
let entity = await this.call_on_impl_('read', uid);
|
||||
if ( ! entity ) {
|
||||
const retry_predicate = await this.retry_predicate_rewrite(uid);
|
||||
if ( retry_predicate ) {
|
||||
entity = await this.call_on_impl_('read',
|
||||
{ predicate: retry_predicate });
|
||||
}
|
||||
}
|
||||
if ( ! this.impl_methods.read_transform ) return entity;
|
||||
return await this.read_transform(entity);
|
||||
}
|
||||
@ -121,6 +129,12 @@ class BaseES extends AdvancedBase {
|
||||
}));
|
||||
}
|
||||
|
||||
async retry_predicate_rewrite ({ predicate }) {
|
||||
if ( ! this.impl_methods.retry_predicate_rewrite ) return;
|
||||
return await this.call_on_impl_('retry_predicate_rewrite', { predicate });
|
||||
}
|
||||
|
||||
|
||||
async read_transform (entity) {
|
||||
if ( ! entity ) return entity;
|
||||
if ( ! this.impl_methods.read_transform ) return entity;
|
||||
|
Loading…
Reference in New Issue
Block a user