mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
- Removed all Snow consensus code and dependencies - Replaced snow.Context with consensuscontext.Context - Updated all imports and references - Added comprehensive test suites for core packages - Fixed all build errors and test failures - Achieved 100% test pass rate (21 packages passing) - Improved test coverage to 30% Breaking changes: - Removed snow package entirely - Changed VM interface to use VMState instead of snow.State - Updated ChainContext structure Tests added: - core/app_error_test.go: 100% coverage - core/bootstrap_test.go: comprehensive concurrent tests - core/health_test.go: full integration tests - validators/validators_test.go: complete interface tests - version/version_test.go: 100% coverage - codec/codec_test.go: marshal/unmarshal tests - context/context_test.go: all functions tested
78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
var identity = require('../../nodes/identity.js');
|
|
var toJS = require('../../nodes/toJS.js');
|
|
var YAMLMap = require('../../nodes/YAMLMap.js');
|
|
var YAMLSeq = require('../../nodes/YAMLSeq.js');
|
|
var pairs = require('./pairs.js');
|
|
|
|
class YAMLOMap extends YAMLSeq.YAMLSeq {
|
|
constructor() {
|
|
super();
|
|
this.add = YAMLMap.YAMLMap.prototype.add.bind(this);
|
|
this.delete = YAMLMap.YAMLMap.prototype.delete.bind(this);
|
|
this.get = YAMLMap.YAMLMap.prototype.get.bind(this);
|
|
this.has = YAMLMap.YAMLMap.prototype.has.bind(this);
|
|
this.set = YAMLMap.YAMLMap.prototype.set.bind(this);
|
|
this.tag = YAMLOMap.tag;
|
|
}
|
|
/**
|
|
* If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
|
|
* but TypeScript won't allow widening the signature of a child method.
|
|
*/
|
|
toJSON(_, ctx) {
|
|
if (!ctx)
|
|
return super.toJSON(_);
|
|
const map = new Map();
|
|
if (ctx?.onCreate)
|
|
ctx.onCreate(map);
|
|
for (const pair of this.items) {
|
|
let key, value;
|
|
if (identity.isPair(pair)) {
|
|
key = toJS.toJS(pair.key, '', ctx);
|
|
value = toJS.toJS(pair.value, key, ctx);
|
|
}
|
|
else {
|
|
key = toJS.toJS(pair, '', ctx);
|
|
}
|
|
if (map.has(key))
|
|
throw new Error('Ordered maps must not include duplicate keys');
|
|
map.set(key, value);
|
|
}
|
|
return map;
|
|
}
|
|
static from(schema, iterable, ctx) {
|
|
const pairs$1 = pairs.createPairs(schema, iterable, ctx);
|
|
const omap = new this();
|
|
omap.items = pairs$1.items;
|
|
return omap;
|
|
}
|
|
}
|
|
YAMLOMap.tag = 'tag:yaml.org,2002:omap';
|
|
const omap = {
|
|
collection: 'seq',
|
|
identify: value => value instanceof Map,
|
|
nodeClass: YAMLOMap,
|
|
default: false,
|
|
tag: 'tag:yaml.org,2002:omap',
|
|
resolve(seq, onError) {
|
|
const pairs$1 = pairs.resolvePairs(seq, onError);
|
|
const seenKeys = [];
|
|
for (const { key } of pairs$1.items) {
|
|
if (identity.isScalar(key)) {
|
|
if (seenKeys.includes(key.value)) {
|
|
onError(`Ordered maps must not include duplicate keys: ${key.value}`);
|
|
}
|
|
else {
|
|
seenKeys.push(key.value);
|
|
}
|
|
}
|
|
}
|
|
return Object.assign(new YAMLOMap(), pairs$1);
|
|
},
|
|
createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx)
|
|
};
|
|
|
|
exports.YAMLOMap = YAMLOMap;
|
|
exports.omap = omap;
|