Problem: the hexagonal refactor churns the backend tree for nine more phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper, compose/web image) must move to its own repo first so doc/layout rewrites land once on a backend-only tree. Change: - New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/ (updateURL repointed to oikos-web releases), compose/, own CI (web + desktop jobs), own deploy script (CI-green gate, TOCTOU guard, version-tagged images, prune-to-3), own webhook receiver on :9798 + launchd unit, own compose project publishing the same 8091:80. - Cutover executed on mac-mini in order: oikos stack's web service stopped+removed, oikos-web project brought up on 8091; outer Caddy untouched (targets the published port) — serving + Authentik flow + /wails 404 quirk verified post-cutover. - Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install targets, the compose web service, oikos-web from deploy.sh's fallback prune list; wails + go-keyring dropped from go.mod, vendor synced. - README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now point at the new repo; mbse + mascot design docs carry a path note. Risk: production SPA serving depends on the new pipeline now; rollback is versioned-image re-up of the old web service from a pre-split checkout (port 8091). Desktop builds installed before the split still check dtoro/oikos releases — one manual reinstall, noted in the oikos-web release notes. Verification: go vet, make test (race), make generate-check, golangci (no new findings; baseline down 400→365); post-cutover curls — localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
147 lines
3.8 KiB
JavaScript
147 lines
3.8 KiB
JavaScript
'use strict';
|
|
|
|
var IDENTIFIER = /^[a-z_$][a-z0-9_$-]*$/i;
|
|
var customRuleCode = require('./dotjs/custom');
|
|
var definitionSchema = require('./definition_schema');
|
|
|
|
module.exports = {
|
|
add: addKeyword,
|
|
get: getKeyword,
|
|
remove: removeKeyword,
|
|
validate: validateKeyword
|
|
};
|
|
|
|
|
|
/**
|
|
* Define custom keyword
|
|
* @this Ajv
|
|
* @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords).
|
|
* @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
|
|
* @return {Ajv} this for method chaining
|
|
*/
|
|
function addKeyword(keyword, definition) {
|
|
/* jshint validthis: true */
|
|
/* eslint no-shadow: 0 */
|
|
var RULES = this.RULES;
|
|
if (RULES.keywords[keyword])
|
|
throw new Error('Keyword ' + keyword + ' is already defined');
|
|
|
|
if (!IDENTIFIER.test(keyword))
|
|
throw new Error('Keyword ' + keyword + ' is not a valid identifier');
|
|
|
|
if (definition) {
|
|
this.validateKeyword(definition, true);
|
|
|
|
var dataType = definition.type;
|
|
if (Array.isArray(dataType)) {
|
|
for (var i=0; i<dataType.length; i++)
|
|
_addRule(keyword, dataType[i], definition);
|
|
} else {
|
|
_addRule(keyword, dataType, definition);
|
|
}
|
|
|
|
var metaSchema = definition.metaSchema;
|
|
if (metaSchema) {
|
|
if (definition.$data && this._opts.$data) {
|
|
metaSchema = {
|
|
anyOf: [
|
|
metaSchema,
|
|
{ '$ref': 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
|
|
]
|
|
};
|
|
}
|
|
definition.validateSchema = this.compile(metaSchema, true);
|
|
}
|
|
}
|
|
|
|
RULES.keywords[keyword] = RULES.all[keyword] = true;
|
|
|
|
|
|
function _addRule(keyword, dataType, definition) {
|
|
var ruleGroup;
|
|
for (var i=0; i<RULES.length; i++) {
|
|
var rg = RULES[i];
|
|
if (rg.type == dataType) {
|
|
ruleGroup = rg;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!ruleGroup) {
|
|
ruleGroup = { type: dataType, rules: [] };
|
|
RULES.push(ruleGroup);
|
|
}
|
|
|
|
var rule = {
|
|
keyword: keyword,
|
|
definition: definition,
|
|
custom: true,
|
|
code: customRuleCode,
|
|
implements: definition.implements
|
|
};
|
|
ruleGroup.rules.push(rule);
|
|
RULES.custom[keyword] = rule;
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
|
|
/**
|
|
* Get keyword
|
|
* @this Ajv
|
|
* @param {String} keyword pre-defined or custom keyword.
|
|
* @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
|
|
*/
|
|
function getKeyword(keyword) {
|
|
/* jshint validthis: true */
|
|
var rule = this.RULES.custom[keyword];
|
|
return rule ? rule.definition : this.RULES.keywords[keyword] || false;
|
|
}
|
|
|
|
|
|
/**
|
|
* Remove keyword
|
|
* @this Ajv
|
|
* @param {String} keyword pre-defined or custom keyword.
|
|
* @return {Ajv} this for method chaining
|
|
*/
|
|
function removeKeyword(keyword) {
|
|
/* jshint validthis: true */
|
|
var RULES = this.RULES;
|
|
delete RULES.keywords[keyword];
|
|
delete RULES.all[keyword];
|
|
delete RULES.custom[keyword];
|
|
for (var i=0; i<RULES.length; i++) {
|
|
var rules = RULES[i].rules;
|
|
for (var j=0; j<rules.length; j++) {
|
|
if (rules[j].keyword == keyword) {
|
|
rules.splice(j, 1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
|
|
|
|
/**
|
|
* Validate keyword definition
|
|
* @this Ajv
|
|
* @param {Object} definition keyword definition object.
|
|
* @param {Boolean} throwError true to throw exception if definition is invalid
|
|
* @return {boolean} validation result
|
|
*/
|
|
function validateKeyword(definition, throwError) {
|
|
validateKeyword.errors = null;
|
|
var v = this._validateKeyword = this._validateKeyword
|
|
|| this.compile(definitionSchema, true);
|
|
|
|
if (v(definition)) return true;
|
|
validateKeyword.errors = v.errors;
|
|
if (throwError)
|
|
throw new Error('custom keyword definition is invalid: ' + this.errorsText(v.errors));
|
|
else
|
|
return false;
|
|
}
|