Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions dist/src/app/components/basket.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,20 @@ const basket = {
},
save() {
return __awaiter(this, void 0, void 0, function* () {
const { data } = yield axios({
yield axios({
method: 'PUT',
data: this.data,
url: this.basketPath(),
}).then((response) => {
const { data } = response;
alert(`${this.name} contents updated!`);
this.data = data;
}).catch((axiosError) => {
const { data: _errorData } = axiosError.response;
const { error, details } = _errorData;
const _message = `${error} - ${details}`;
alert(_message);
});
alert(`${this.name} contents updated!`);
this.data = data;
});
},
openShareModal() {
Expand Down
16 changes: 16 additions & 0 deletions dist/src/app/components/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
// External Files
const axios = require('axios');
const jsonEditor = require('vue-json-editor').default;
// Configs
const configs = require('../config.ts');
// Templates
Expand All @@ -32,10 +33,22 @@ const explorer = {
explorerOnboarding,
basket,
modal,
'json-edit': jsonEditor,
},
data() {
return {
basket: null,
schemaModalVisible: false,
schemaExample: {
_schema: {
toppings: { type: 'array' },
size: { type: 'string' },
price: { type: 'number' },
},
toppings: ['pepperoni', 'mushrooms', 'hot peppers'],
size: 'large',
price: 19.99,
},
};
},
computed: {
Expand Down Expand Up @@ -129,6 +142,9 @@ const explorer = {
this.viewBasket(name);
}
},
toggleSchemaModal() {
this.schemaModalVisible = !this.schemaModalVisible;
},
},
};
module.exports = explorer;
6 changes: 0 additions & 6 deletions dist/src/app/components/explorerEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const configs = require('../config.ts');
// Constants
const API_PATH = configs.apiPath;
const DOCS_PATH = configs.docsPath;
// Templates
const explorerEmptyTemplate = require('../templates/explorerEmpty.html');
const explorerEmpty = {
Expand All @@ -15,10 +14,5 @@ const explorerEmpty = {
apiPath: API_PATH,
};
},
methods: {
showDocs() {
window.location.href = DOCS_PATH;
},
},
};
module.exports = explorerEmpty;
6 changes: 3 additions & 3 deletions dist/src/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/src/bundle.js.map

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions dist/src/models/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
// Extarnal Libs
const class_validator_1 = require("class-validator");
const merge = require("deepmerge");
const ajv_1 = __importDefault(require("ajv"));
// External Files
const block_1 = require("../decorators/block");
const dataStore = __importStar(require("../services/dataStore"));
Expand All @@ -53,6 +54,7 @@ class Block {
this.createdAt = createdAt;
this.account = null;
this.updatedAt = null;
this.schema = null;
this.redisKey = `account:${this.accountUUID}::block:${this.name}`;
}
static get(accountUUID, name) {
Expand All @@ -76,6 +78,7 @@ class Block {
update(newData) {
return __awaiter(this, void 0, void 0, function* () {
const _updatedPayload = merge(this.payload, newData);
this.validateSchema(_updatedPayload);
this.payload = _updatedPayload;
this.updatedAt = new Date();
yield this.store();
Expand Down Expand Up @@ -129,13 +132,44 @@ class Block {
this.payload = payload;
this.createdAt = createdAt ? new Date(createdAt) : new Date();
this.updatedAt = updatedAt ? new Date(updatedAt) : null;
this.loadSchema();
});
}
hydrateAccount() {
return __awaiter(this, void 0, void 0, function* () {
this.account = yield account_1.default.get(this.accountUUID);
});
}
loadSchema() {
const { _schema } = this.payload;
if (_schema) {
this.schema = {
type: 'object',
additionalProperties: true,
properties: Object.assign({}, _schema),
};
}
}
validateSchema(payload) {
if (!this.schema) {
return;
}
delete this.schema._schema;
const _ajv = new ajv_1.default({ strict: false });
const _validate = _ajv.compile(this.schema);
const _valid = _validate(payload);
if (!_valid) {
const _errors = this.formatValidationErrors(_validate.errors);
throw new Error(`Schema validation failed: ${_errors}`);
}
}
formatValidationErrors(errors) {
return errors.map((error) => {
const { instancePath, message } = error;
const _key = instancePath.replace('/', '');
return `'${_key}' ${message}`;
});
}
}
_a = Block;
Block.lifeSpanDays = Number(process.env.BLOCK_LIFESPAN);
Expand Down Expand Up @@ -168,4 +202,8 @@ __decorate([
(0, class_validator_1.IsNotEmpty)(),
(0, class_validator_1.IsString)()
], Block.prototype, "redisKey", void 0);
__decorate([
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsObject)()
], Block.prototype, "schema", void 0);
exports.default = Block;
1 change: 1 addition & 0 deletions dist/src/models/publicBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class PublicBlock {
sanitizedBlock() {
const _sanitizedBlock = this.block.sanitize();
delete _sanitizedBlock._metadata;
delete _sanitizedBlock._schema;
return _sanitizedBlock;
}
hydrate() {
Expand Down
Loading
Loading