feat: add app metadata

This commit is contained in:
KernelDeimos 2024-06-16 16:04:18 -04:00 committed by Eric Dubé
parent 8ebf1cec3f
commit f7216b9567
5 changed files with 37 additions and 3 deletions

View File

@ -24,7 +24,7 @@ class PropType extends AdvancedBase {
new WeakConstructorTrait(), new WeakConstructorTrait(),
] ]
static create (context, data) { static create (context, data, k) {
const chains = {}; const chains = {};
const super_type = data.from && (() => { const super_type = data.from && (() => {
const registry = context.get('registry'); const registry = context.get('registry');
@ -51,7 +51,7 @@ class PropType extends AdvancedBase {
} }
return new PropType({ return new PropType({
chains, chains, name: k,
}); });
} }

View File

@ -194,6 +194,29 @@ class SQLES extends BaseES {
let value = data[col_name]; let value = data[col_name];
value = await prop.sql_dereference(value); value = await prop.sql_dereference(value);
// TODO: This is not an ideal implementation,
// but this is only 6 lines of code so doing this
// "properly" is not sensible at this time.
//
// This is here because:
// - SQLES has access to the "db" object
//
// Writing this in `json`'s `sql_reference` method
// is also not ideal because that places the concern
// of supporting different database backends to
// property types.
//
// Best solution: SQLES has a SQLRefinements by
// composition. This SQLRefinements is applied
// to property types for the duration of this
// function.
if ( prop.typ.name === 'json' ) {
value = this.db.case({
mysql: () => value,
otherwise: () => JSON.parse(value ?? '{}'),
})();
}
entity_data[prop.name] = value; entity_data[prop.name] = value;
} }
const entity = await Entity.create({ om: this.om }, entity_data); const entity = await Entity.create({ om: this.om }, entity_data);
@ -287,6 +310,13 @@ class SQLES extends BaseES {
value = await prop.sql_reference(value); value = await prop.sql_reference(value);
// TODO: This is done here for consistency;
// see the larger comment in sql_row_to_entity_
// which does the reverse operation.
if ( prop.typ.name === 'json' ) {
value = JSON.stringify(value);
}
if ( value && options.use_id ) { if ( value && options.use_id ) {
if ( value.hasOwnProperty('id') ) { if ( value.hasOwnProperty('id') ) {
value = value.id; value = value.id;

View File

@ -50,6 +50,9 @@ module.exports = {
// so I've doubled that and rounded up // so I've doubled that and rounded up
maxlen: 7000, maxlen: 7000,
}, },
metadata: {
type: 'json',
},
maximize_on_start: 'flag', maximize_on_start: 'flag',
background: 'flag', background: 'flag',
subdomain: { subdomain: {

View File

@ -55,7 +55,7 @@ class RegistrantService extends BaseService {
if ( data[k].from && ! seen.has(data[k].from) ) { if ( data[k].from && ! seen.has(data[k].from) ) {
throw new Error(`Super type "${data[k].from}" not found for property type "${k}"`); throw new Error(`Super type "${data[k].from}" not found for property type "${k}"`);
} }
collection.set(k, PropType.create(ctx, data[k])); collection.set(k, PropType.create(ctx, data[k], k));
seen.add(k); seen.add(k);
} }
} }

View File

@ -0,0 +1 @@
ALTER TABLE apps ADD COLUMN "metadata" JSON DEFAULT NULL;