diff --git a/packages/core/src/server/state/projects.js b/packages/core/src/server/state/projects.js index 1bdbae8..93fd14e 100644 --- a/packages/core/src/server/state/projects.js +++ b/packages/core/src/server/state/projects.js @@ -28,7 +28,10 @@ const projectResources = async (uuid, resourcePaths, latus) => { const {encode} = latus.get('%resource-controllers')(path); return ({ ...(await r), - [join(uuid, path)]: encode(await readFile(join(process.cwd(), 'projects', uuid, path))), + [join(uuid, path)]: await encode( + await readFile(join(process.cwd(), 'projects', uuid, path)), + latus, + ), }); }, {}); }; diff --git a/packages/entity/src/resource-controllers/entity/index.jsx b/packages/entity/src/resource-controllers/entity/index.jsx index 7f4419a..4b94d99 100644 --- a/packages/entity/src/resource-controllers/entity/index.jsx +++ b/packages/entity/src/resource-controllers/entity/index.jsx @@ -69,6 +69,16 @@ export default class EntityController extends JsonResourceController { ); } + static decode(encoded, latus) { + const {Entity} = latus.get('%resources'); + return super.decode(Entity.withoutDefaults(encoded)); + } + + static encode(buffer, latus) { + const {Entity} = latus.get('%resources'); + return Entity.withDefaults(super.encode(buffer)); + } + static get matcher() { return /\.entity\.json$/; } diff --git a/packages/entity/src/resource-controllers/entity/traits/index.jsx b/packages/entity/src/resource-controllers/entity/traits/index.jsx index 09f8a1f..691cdf6 100644 --- a/packages/entity/src/resource-controllers/entity/traits/index.jsx +++ b/packages/entity/src/resource-controllers/entity/traits/index.jsx @@ -1,6 +1,5 @@ import {join} from 'path'; -import {Trait as BaseTrait} from '@avocado/traits'; import { PropTypes, React, @@ -65,18 +64,13 @@ const Traits = ({ ); const TraitRenderers = latus.get('%trait-renderers'); const tabPanels = types.map((type) => { - const Trait = Traits[type] || BaseTrait; - const jsonWithDefaults = { - params: Trait.defaultParamsWith(json[type].params || {}), - state: Trait.defaultStateWith(json[type].state || {}), - }; const TraitRenderer = TraitRenderers[type] ? TraitRenderers[type] : NoTraitRenderer; return ( @@ -122,7 +116,7 @@ const Traits = ({ setIsSelecting(false); patch({ path: join(path, type), - value: {}, + value: Traits[type].withDefaults({}), }); }} types={suggestible} diff --git a/packages/json/src/server/packets/decorators/action.js b/packages/json/src/server/packets/decorators/action.js index 0608283..641a9c0 100644 --- a/packages/json/src/server/packets/decorators/action.js +++ b/packages/json/src/server/packets/decorators/action.js @@ -9,7 +9,7 @@ import {patchJsonResource} from '../../../state/json'; const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); -export default (Action) => class ProjectAction extends Action { +export default (Action, latus) => class ProjectAction extends Action { static async respond(packet, socket) { const {data: {type, payload}} = packet; @@ -18,9 +18,10 @@ export default (Action) => class ProjectAction extends Action { const {patch, project, uri} = payload; const path = join(process.cwd(), 'projects', project, uri); const buffer = await readFile(path); - const json = JSON.parse(buffer.toString('utf8')); + const {decode, encode} = latus.get('%resource-controllers')(uri); + const json = encode(buffer, latus); applyPatch(json, patch); - writeFile(path, JSON.stringify(json, null, 2)); + writeFile(path, decode(json, latus)); break; } default: