Skip to content

Commit

Permalink
feat: add app metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jun 16, 2024
1 parent 8ebf1ce commit f7216b9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/om/definitions/PropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PropType extends AdvancedBase {
new WeakConstructorTrait(),
]

static create (context, data) {
static create (context, data, k) {
const chains = {};
const super_type = data.from && (() => {
const registry = context.get('registry');
Expand All @@ -51,7 +51,7 @@ class PropType extends AdvancedBase {
}

return new PropType({
chains,
chains, name: k,
});
}

Expand Down
30 changes: 30 additions & 0 deletions packages/backend/src/om/entitystorage/SQLES.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,29 @@ class SQLES extends BaseES {
let value = data[col_name];
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;
}
const entity = await Entity.create({ om: this.om }, entity_data);
Expand Down Expand Up @@ -286,6 +309,13 @@ class SQLES extends BaseES {
}

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.hasOwnProperty('id') ) {
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/om/mappings/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ module.exports = {
// so I've doubled that and rounded up
maxlen: 7000,
},
metadata: {
type: 'json',
},
maximize_on_start: 'flag',
background: 'flag',
subdomain: {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/services/RegistrantService.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RegistrantService extends BaseService {
if ( data[k].from && ! seen.has(data[k].from) ) {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE apps ADD COLUMN "metadata" JSON DEFAULT NULL;

0 comments on commit f7216b9

Please sign in to comment.