/*
* This attempts to track an issue with ajv and standalone module generation which appears to happen
* only on Deno and only on ESM modules provided by skypack (or esm.sh).
*
* A minimal reproduction on Deno follows
*/
// On Deno, we import from skypack. This gets 8.8.2 as of 2021-12-15:
// import Ajv from "https://cdn.skypack.dev/ajv";
// import standalone from "https://cdn.skypack.dev/ajv/dist/standalone";
//
// the same issue happens if we import from esm.sh:
//
// import Ajv from "https://esm.sh/ajv";
// import standalone from "https://esm.sh/ajv/dist/standalone";
// on node v17.1.0 on runkit:
var Ajv = require('ajv');
var standalone = require('ajv/dist/standalone');
ajv = new Ajv({
allErrors: true, code: { source: true }
});
var schema = {
"type": "object",
"properties": {
"f1": { "type": "string" },
"f2": {
"type": "array",
"items": { "$ref": "navigation-item" }
}
},
"additionalProperties": false,
"$id": "navigation-item"
};
var data = {};
var validate = ajv.compile(schema);
var moduleSrc = standalone(ajv, { "navigation-item": "navigation-item" });
/* the call above fails on Deno v1.16.4. The error message is:
> const moduleSrc = standalone(ajv, { "navigation-item": "navigation-item" })
--> starting at object with constructor 'SchemaEnv'
| property 'refs' -> object with constructor 'Object'
--- property 'navigation-item' closes the circle
at JSON.stringify (<anonymous>)
at safeStringify (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/compile/codegen/code.js:138:17)
at interpolate (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/compile/codegen/code.js:131:78)
at addCodeArg (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/compile/codegen/code.js:91:17)
at Object._ (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/compile/codegen/code.js:66:7)
at refValidateCode (https://cdn.skypack.dev/-/ajv@v8.8.2-oHh4dWmHmt5cH6zohUYk/dist=es2019,mode=imports/unoptimized/dist/standalone/index.js:63:35)
at https://cdn.skypack.dev/-/ajv@v8.8.2-7PXBFgVwJaIVYRDIomxs/dist=es2019,mode=imports/optimized/ajv.js:287:76
at Set.forEach (<anonymous>)
at ValueScope._reduceValues (https://cdn.skypack.dev/-/ajv@v8.8.2-7PXBFgVwJaIVYRDIomxs/dist=es2019,mode=imports/optimized/ajv.js:279:12)
at ValueScope.scopeCode (https://cdn.skypack.dev/-/ajv@v8.8.2-7PXBFgVwJaIVYRDIomxs/dist=es2019,mode=imports/optimized/ajv.js:266:19)
*/
console.log(moduleSrc);
// console.log(validate.errors);