From 2c54a8c35cd8d83afeef36e0ce1d3afd31e4cc59 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 30 Jun 2023 01:21:43 +0300 Subject: [PATCH 01/38] update: TS interfaces --- package-lock.json | 386 +++++++++++++++++++++++++++++++++++- package.json | 13 +- scripts/buildInterfaces.mjs | 60 ++++++ 3 files changed, 445 insertions(+), 14 deletions(-) create mode 100644 scripts/buildInterfaces.mjs diff --git a/package-lock.json b/package-lock.json index 9e2cffdf..a30780d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1115,6 +1115,17 @@ "to-fast-properties": "^2.0.0" } }, + "@bcherny/json-schema-ref-parser": { + "version": "10.0.5-fork", + "resolved": "https://registry.npmjs.org/@bcherny/json-schema-ref-parser/-/json-schema-ref-parser-10.0.5-fork.tgz", + "integrity": "sha512-E/jKbPoca1tfUPj3iSbitDZTGnq6FUFjkH6L8U2oDwSuwK1WhnnVtCG7oFOTg/DDnyoXbQYUiUiGOibHqaGVnw==", + "requires": { + "@jsdevtools/ono": "^7.1.3", + "@types/json-schema": "^7.0.6", + "call-me-maybe": "^1.0.1", + "js-yaml": "^4.1.0" + } + }, "@es-joy/jsdoccomment": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.12.0.tgz", @@ -1203,9 +1214,8 @@ "dev": true }, "@exabyte-io/esse.js": { - "version": "2023.6.20-0", - "resolved": "https://registry.npmjs.org/@exabyte-io/esse.js/-/esse.js-2023.6.20-0.tgz", - "integrity": "sha512-KFab2+Z8BDKXWDuK7DYFYEpyaOLUespLIxZwqaJ4fKJQRk7KZ6U0FmXGkZVFdrmPgAzwMOhDO2M04pYB7q4OYw==", + "version": "git+https://github.com/Exabyte-io/esse.git#96b99275ebe4b3116ad7e330962d0b7e6dbefed4", + "from": "git+https://github.com/Exabyte-io/esse.git#update/SOF-6535", "requires": { "@babel/cli": "7.16.0", "@babel/core": "7.16.0", @@ -1361,18 +1371,57 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "@jsdevtools/ono": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", + "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==" + }, "@nicolo-ribaudo/chokidar-2": { "version": "2.1.8-no-fsevents.3", "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/chokidar-2/-/chokidar-2-2.1.8-no-fsevents.3.tgz", "integrity": "sha512-s88O1aVtXftvp5bCPB7WnmXc5IwOZZ7YPuwNPt+GtOOXpPvad1LfbmjYv+qII7zP6RU2QGnqve27dnLycEnyEQ==", "optional": true }, + "@types/glob": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==", + "requires": { + "@types/minimatch": "*", + "@types/node": "*" + } + }, + "@types/json-schema": { + "version": "7.0.12", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", + "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==" + }, "@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "@types/lodash": { + "version": "4.14.195", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.195.tgz", + "integrity": "sha512-Hwx9EUgdwf2GLarOjQp5ZH8ZmblzcbTBC2wtQWNKARBSxM9ezRIAUpeDTgoQRAFB0+8CNWXVA9+MaSOzOF3nPg==" + }, + "@types/minimatch": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==" + }, + "@types/node": { + "version": "20.3.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.2.tgz", + "integrity": "sha512-vOBLVQeCQfIcF/2Y7eKFTqrMnizK5lRNQ7ykML/5RuwVXVWxYkgwS7xbt4B6fKCUPgbSL5FSsjHQpaGQP/dQmw==" + }, + "@types/prettier": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.3.tgz", + "integrity": "sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==" + }, "@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", @@ -1452,6 +1501,11 @@ "color-convert": "^1.9.0" } }, + "any-promise": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", + "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==" + }, "anymatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", @@ -1494,6 +1548,11 @@ "@babel/runtime-corejs3": "^7.10.2" } }, + "array-back": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz", + "integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==" + }, "array-includes": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.5.tgz", @@ -1696,6 +1755,11 @@ "get-intrinsic": "^1.0.2" } }, + "call-me-maybe": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.2.tgz", + "integrity": "sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==" + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -1770,6 +1834,18 @@ "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", "dev": true }, + "cli-color": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.3.tgz", + "integrity": "sha512-OkoZnxyC4ERN3zLzZaY9Emb7f/MhBOIpePv0Ycok0fJYT+Ouo00UBEIwsVsr0yoow++n5YWlSUgST9GKhNHiRQ==", + "requires": { + "d": "^1.0.1", + "es5-ext": "^0.10.61", + "es6-iterator": "^2.0.3", + "memoizee": "^0.4.15", + "timers-ext": "^0.1.7" + } + }, "cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -1895,6 +1971,40 @@ "integrity": "sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==", "dev": true }, + "command-line-args": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.1.tgz", + "integrity": "sha512-H4UfQhZyakIjC74I9d34fGYDwk3XpSr17QhEd0Q3I9Xq1CETHo4Hcuo87WyWHpAF1aSLjLRf5lD9ZGX2qStUvg==", + "requires": { + "array-back": "^3.1.0", + "find-replace": "^3.0.0", + "lodash.camelcase": "^4.3.0", + "typical": "^4.0.0" + } + }, + "command-line-usage": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/command-line-usage/-/command-line-usage-6.1.3.tgz", + "integrity": "sha512-sH5ZSPr+7UStsloltmDh7Ce5fb8XPlHyoPzTpyyMuYCtervL65+ubVZ6Q61cFtFl62UyJlc8/JwERRbAFPUqgw==", + "requires": { + "array-back": "^4.0.2", + "chalk": "^2.4.2", + "table-layout": "^1.0.2", + "typical": "^5.2.0" + }, + "dependencies": { + "array-back": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-4.0.2.tgz", + "integrity": "sha512-NbdMezxqf94cnNfWLL7V/im0Ub+Anbb0IoZhvzie8+4HJ4nMQuzHuy49FkGYCJK2yAloZ3meiB6AVMClbrI1vg==" + }, + "typical": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/typical/-/typical-5.2.0.tgz", + "integrity": "sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg==" + } + } + }, "commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -1998,6 +2108,15 @@ "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz", "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" }, + "d": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", + "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", + "requires": { + "es5-ext": "^0.10.50", + "type": "^1.0.1" + } + }, "dag-map": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/dag-map/-/dag-map-1.0.2.tgz", @@ -2037,6 +2156,11 @@ "type-detect": "^4.0.0" } }, + "deep-extend": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" + }, "deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -2075,6 +2199,15 @@ "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", "dev": true }, + "directory-tree": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/directory-tree/-/directory-tree-3.5.1.tgz", + "integrity": "sha512-HqjZ49fDzUnKYUhHxVw9eKBqbQ+lL0v4kSBInlDlaktmLtGoV9tC54a6A0ZfYeIrkMHWTE6MwwmUXP477+UEKQ==", + "requires": { + "command-line-args": "^5.2.0", + "command-line-usage": "^6.1.1" + } + }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -2161,12 +2294,52 @@ "is-symbol": "^1.0.2" } }, + "es5-ext": { + "version": "0.10.62", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.62.tgz", + "integrity": "sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==", + "requires": { + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.3", + "next-tick": "^1.1.0" + } + }, "es6-error": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", "dev": true }, + "es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", + "requires": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, + "es6-symbol": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", + "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", + "requires": { + "d": "^1.0.1", + "ext": "^1.1.2" + } + }, + "es6-weak-map": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz", + "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", + "requires": { + "d": "1", + "es5-ext": "^0.10.46", + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.1" + } + }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", @@ -2742,6 +2915,15 @@ "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==" }, + "event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", + "requires": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "execa": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", @@ -2759,6 +2941,21 @@ "strip-final-newline": "^2.0.0" } }, + "ext": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", + "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", + "requires": { + "type": "^2.7.2" + }, + "dependencies": { + "type": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", + "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" + } + } + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2815,6 +3012,14 @@ "pkg-dir": "^3.0.0" } }, + "find-replace": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", + "integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==", + "requires": { + "array-back": "^3.0.1" + } + }, "find-up": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", @@ -2944,6 +3149,11 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, + "get-stdin": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", + "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==" + }, "get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", @@ -2981,6 +3191,14 @@ "is-glob": "^4.0.1" } }, + "glob-promise": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/glob-promise/-/glob-promise-4.2.2.tgz", + "integrity": "sha512-xcUzJ8NWN5bktoTIX7eOclO1Npxd/dyVqUJxlLIDasT4C7KZyqlPIwkdJ0Ypiy3p2ZKahTjK4M9uC3sNSfNMzw==", + "requires": { + "@types/glob": "^7.1.3" + } + }, "globals": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", @@ -3265,6 +3483,11 @@ "isobject": "^3.0.1" } }, + "is-promise": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", + "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" + }, "is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -3577,6 +3800,27 @@ "lodash": "^4.17.20" } }, + "json-schema-to-typescript": { + "version": "13.0.2", + "resolved": "https://registry.npmjs.org/json-schema-to-typescript/-/json-schema-to-typescript-13.0.2.tgz", + "integrity": "sha512-TCaEVW4aI2FmMQe7f98mvr3/oiVmXEC1xZjkTZ9L/BSoTXFlC7p64mD5AD2d8XWycNBQZUnHwXL5iVXt1HWwNQ==", + "requires": { + "@bcherny/json-schema-ref-parser": "10.0.5-fork", + "@types/json-schema": "^7.0.11", + "@types/lodash": "^4.14.182", + "@types/prettier": "^2.6.1", + "cli-color": "^2.0.2", + "get-stdin": "^8.0.0", + "glob": "^7.1.6", + "glob-promise": "^4.2.2", + "is-glob": "^4.0.3", + "lodash": "^4.17.21", + "minimist": "^1.2.6", + "mkdirp": "^1.0.4", + "mz": "^2.7.0", + "prettier": "^2.6.2" + } + }, "json-stable-stringify": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.2.tgz", @@ -3760,6 +4004,11 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, + "lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" + }, "lodash.debounce": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", @@ -3920,6 +4169,14 @@ "yallist": "^4.0.0" } }, + "lru-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz", + "integrity": "sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ==", + "requires": { + "es5-ext": "~0.10.2" + } + }, "make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", @@ -3954,6 +4211,21 @@ "is-buffer": "~1.1.1" } }, + "memoizee": { + "version": "0.4.15", + "resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.15.tgz", + "integrity": "sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==", + "requires": { + "d": "^1.0.1", + "es5-ext": "^0.10.53", + "es6-weak-map": "^2.0.3", + "event-emitter": "^0.3.5", + "is-promise": "^2.2.2", + "lru-queue": "^0.1.0", + "next-tick": "^1.1.0", + "timers-ext": "^0.1.7" + } + }, "memory-cache": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz", @@ -3992,14 +4264,18 @@ "minimist": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "mixwith": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/mixwith/-/mixwith-0.1.1.tgz", "integrity": "sha512-DQsf/liljH/9e+94jR+xfK8vlKceeKdOM9H9UEXLwGuvEEpO6debNtJ9yt1ZKzPKPrwqGxzMdu0BR1fnQb6i4A==" }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" + }, "mocha": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.2.2.tgz", @@ -4181,6 +4457,16 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "mz": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", + "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", + "requires": { + "any-promise": "^1.0.0", + "object-assign": "^4.0.1", + "thenify-all": "^1.0.0" + } + }, "nanoid": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.1.tgz", @@ -4193,6 +4479,11 @@ "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, + "next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, "node-preload": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", @@ -4455,8 +4746,7 @@ "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "dev": true + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==" }, "object-inspect": { "version": "1.12.2", @@ -4675,8 +4965,7 @@ "prettier": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", - "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", - "dev": true + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==" }, "prettier-linter-helpers": { "version": "1.0.0", @@ -4742,6 +5031,11 @@ "picomatch": "^2.2.1" } }, + "reduce-flatten": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/reduce-flatten/-/reduce-flatten-2.0.0.tgz", + "integrity": "sha512-EJ4UNY/U1t2P/2k6oqotuX2Cc3T6nxJwsM0N0asT7dhrtH1ltUxDn4NalSYmPE2rCkVpcf/X6R0wDwcFpzhd4w==" + }, "regenerate": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", @@ -5220,6 +5514,29 @@ } } }, + "table-layout": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/table-layout/-/table-layout-1.0.2.tgz", + "integrity": "sha512-qd/R7n5rQTRFi+Zf2sk5XVVd9UQl6ZkduPFC3S7WEGJAmetDTjY3qPN50eSKzwuzEyQKy5TN2TiZdkIjos2L6A==", + "requires": { + "array-back": "^4.0.1", + "deep-extend": "~0.6.0", + "typical": "^5.2.0", + "wordwrapjs": "^4.0.0" + }, + "dependencies": { + "array-back": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-4.0.2.tgz", + "integrity": "sha512-NbdMezxqf94cnNfWLL7V/im0Ub+Anbb0IoZhvzie8+4HJ4nMQuzHuy49FkGYCJK2yAloZ3meiB6AVMClbrI1vg==" + }, + "typical": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/typical/-/typical-5.2.0.tgz", + "integrity": "sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg==" + } + } + }, "test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -5237,12 +5554,37 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, + "thenify": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz", + "integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==", + "requires": { + "any-promise": "^1.0.0" + } + }, + "thenify-all": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", + "integrity": "sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==", + "requires": { + "thenify": ">= 3.1.0 < 4" + } + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "timers-ext": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/timers-ext/-/timers-ext-0.1.7.tgz", + "integrity": "sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==", + "requires": { + "es5-ext": "~0.10.46", + "next-tick": "1" + } + }, "tiny-emitter": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.0.2.tgz", @@ -5295,6 +5637,11 @@ "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", "dev": true }, + "type": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", + "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" + }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -5330,6 +5677,11 @@ "is-typedarray": "^1.0.0" } }, + "typical": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", + "integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==" + }, "unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -5483,6 +5835,22 @@ "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "dev": true }, + "wordwrapjs": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/wordwrapjs/-/wordwrapjs-4.0.1.tgz", + "integrity": "sha512-kKlNACbvHrkpIw6oPeYDSmdCTu2hdMHoyXLTcUKala++lx5Y+wjJ/e474Jqv5abnVmwxw08DiTuHmw69lJGksA==", + "requires": { + "reduce-flatten": "^2.0.0", + "typical": "^5.2.0" + }, + "dependencies": { + "typical": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/typical/-/typical-5.2.0.tgz", + "integrity": "sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg==" + } + } + }, "workerpool": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.0.tgz", diff --git a/package.json b/package.json index ee2b4a4f..b3143f79 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,13 @@ "description": "COre DEfinitions in JS for Mat3ra.com (Exabyte.io)", "scripts": { "test": "nyc --reporter=text mocha --recursive --bail --require @babel/register/lib --require tests/setup.js tests", - "lint": "eslint src tests && prettier --write src tests", + "lint": "eslint src tests scripts && prettier --write src tests scripts", "lint:fix": "eslint --fix --cache src tests && prettier --write src tests", "transpile": "babel --out-dir dist src", - "postinstall": "npm run transpile", + "postinstall": "npm run transpile && npm run buildInterfaces", "prettier": "prettier --check src tests", - "prepare": "husky install" + "prepare": "husky install", + "buildInterfaces": "node scripts/buildInterfaces.mjs" }, "repository": { "type": "git", @@ -50,7 +51,7 @@ "@babel/preset-react": "7.16.7", "@babel/register": "^7.16.0", "@babel/runtime-corejs3": "7.16.8", - "@exabyte-io/esse.js": "2023.6.20-0", + "@exabyte-io/esse.js": "git+https://github.com/Exabyte-io/esse.git#update/SOF-6535", "ajv": "4.1.7", "crypto-js": "^4.1.1", "js-yaml": "^4.1.0", @@ -61,7 +62,9 @@ "nunjucks": "^3.2.4", "underscore": "^1.13.3", "underscore.string": "^3.3.4", - "uuid": "8.3.2" + "uuid": "8.3.2", + "directory-tree": "^3.5.1", + "json-schema-to-typescript": "^13.0.2" }, "devDependencies": { "@exabyte-io/eslint-config": "^2022.11.17-0", diff --git a/scripts/buildInterfaces.mjs b/scripts/buildInterfaces.mjs new file mode 100644 index 00000000..d8cdd14f --- /dev/null +++ b/scripts/buildInterfaces.mjs @@ -0,0 +1,60 @@ +/* eslint-disable no-await-in-loop */ +/* eslint-disable no-restricted-syntax */ +/* eslint-disable import/no-extraneous-dependencies */ +import directoryTree from "directory-tree"; +import fs from "fs/promises"; +import { compileFromFile } from "json-schema-to-typescript"; +import path from "path"; + +const typesPath = "./dist/types.d.ts"; +const schemaFolder = "node_modules/@exabyte-io/esse.js/schema"; + +await fs.writeFile(typesPath, "/* eslint-disable */\n\n"); + +const tree = directoryTree(schemaFolder, { extensions: /\.json$/ }); + +async function walkTree({ children }, cb) { + for (const item of children || []) { + if (item.children) { + await walkTree(item, cb); + } else { + await cb(item); + } + } +} + +const typesHash = {}; + +await walkTree(tree, async (item) => { + const ts = await compileFromFile(item.path, { + cwd: path.dirname(item.path), + bannerComment: `/** ${item.path} **/`, + }); + + const exports = ts.split("export "); + + exports.forEach((v) => { + const result = v.match(/^interface\s+\w+/g) || v.match(/^type\s+\w+/g); + + if (result) { + const typeName = result[0]; + + if (!typesHash[typeName] || v.indexOf("&") !== -1) { + /** + * In some cases types may be defined with bugs: sometimes "properties" are ignored when the "allOf" is present in the schema. + * We assume that type that contains "&" in it's definition is 100% correct (allOf + properties) => replace previously defined type if exists + */ + console.log(`Add ${typeName}`); + typesHash[typeName] = `export ${v}`; + } else { + // The type has been declared already + console.log(`Found ${typeName}`); + } + } else { + // expect bannerComment here + typesHash[item.path] = v; + } + }); +}); + +await fs.appendFile(typesPath, Object.values(typesHash).join("\n")); From 7fd496c7bcce808bbe7bfbacbd19b4ad69534ed8 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 30 Jun 2023 01:23:17 +0300 Subject: [PATCH 02/38] chore: remove eslint comment --- scripts/buildInterfaces.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/buildInterfaces.mjs b/scripts/buildInterfaces.mjs index d8cdd14f..f4214fc9 100644 --- a/scripts/buildInterfaces.mjs +++ b/scripts/buildInterfaces.mjs @@ -1,6 +1,5 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable no-restricted-syntax */ -/* eslint-disable import/no-extraneous-dependencies */ import directoryTree from "directory-tree"; import fs from "fs/promises"; import { compileFromFile } from "json-schema-to-typescript"; From e0c6fc299f3445e5a510b1b43361a6a51bc382d6 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 30 Jun 2023 01:27:55 +0300 Subject: [PATCH 03/38] chore: test installation --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b3143f79..a3a28a33 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lint": "eslint src tests scripts && prettier --write src tests scripts", "lint:fix": "eslint --fix --cache src tests && prettier --write src tests", "transpile": "babel --out-dir dist src", - "postinstall": "npm run transpile && npm run buildInterfaces", + "postinstall": "npm run transpile", "prettier": "prettier --check src tests", "prepare": "husky install", "buildInterfaces": "node scripts/buildInterfaces.mjs" From e9f6f45d74d2dd2f7b5143fb9eb701d852b09127 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 30 Jun 2023 01:32:55 +0300 Subject: [PATCH 04/38] chore: add scripts to package exports --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index a3a28a33..36290064 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "./constants": "./dist/constants.js", "./math": "./dist/math.js", "./JSONSchemasInterface": "./dist/JSONSchemasInterface.js", + "./scripts/buildInterfaces.mjs": "./scripts/buildInterfaces.mjs", "./dist/context": "./dist/context/index.js", "./dist/entity": "./dist/entity/index.js", "./dist/utils": "./dist/utils/index.js", From 111ec9ee75694ca53f105580ee0ac13a535fc1df Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 30 Jun 2023 01:35:16 +0300 Subject: [PATCH 05/38] chore: add scripts to files in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36290064..c6ae68d9 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "./constants": "./dist/constants.js", "./math": "./dist/math.js", "./JSONSchemasInterface": "./dist/JSONSchemasInterface.js", - "./scripts/buildInterfaces.mjs": "./scripts/buildInterfaces.mjs", "./dist/context": "./dist/context/index.js", "./dist/entity": "./dist/entity/index.js", "./dist/utils": "./dist/utils/index.js", @@ -35,6 +34,7 @@ "files": [ "/dist", "/src", + "/scripts", ".babelrc" ], "author": "Exabyte Inc.", From 5c992a75d45e8ebc5b8478e496e04d34cd69a026 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 30 Jun 2023 01:36:48 +0300 Subject: [PATCH 06/38] chore: add buildInterfaces to postinstall --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c6ae68d9..279713c9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lint": "eslint src tests scripts && prettier --write src tests scripts", "lint:fix": "eslint --fix --cache src tests && prettier --write src tests", "transpile": "babel --out-dir dist src", - "postinstall": "npm run transpile", + "postinstall": "npm run transpile && npm run buildInterfaces", "prettier": "prettier --check src tests", "prepare": "husky install", "buildInterfaces": "node scripts/buildInterfaces.mjs" From af4dcb8535bf518b7117466aee81c97bd9867f93 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 30 Jun 2023 17:03:00 +0300 Subject: [PATCH 07/38] chore: change types file name --- package.json | 3 ++- scripts/buildInterfaces.mjs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 279713c9..126b2d78 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "./dist/utils": "./dist/utils/index.js", "./dist/constants": "./dist/constants.js", "./dist/math": "./dist/math.js", - "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js" + "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js", + "./dist/types": "./dist/types.ts" }, "files": [ "/dist", diff --git a/scripts/buildInterfaces.mjs b/scripts/buildInterfaces.mjs index f4214fc9..c0a680f7 100644 --- a/scripts/buildInterfaces.mjs +++ b/scripts/buildInterfaces.mjs @@ -5,7 +5,7 @@ import fs from "fs/promises"; import { compileFromFile } from "json-schema-to-typescript"; import path from "path"; -const typesPath = "./dist/types.d.ts"; +const typesPath = "./dist/types.ts"; const schemaFolder = "node_modules/@exabyte-io/esse.js/schema"; await fs.writeFile(typesPath, "/* eslint-disable */\n\n"); From 99098c39156ebec6efb7d8f02a721292dd89b522 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Wed, 5 Jul 2023 18:17:50 +0300 Subject: [PATCH 08/38] update: new JSONSchema logic --- package-lock.json | 25 +++++ package.json | 9 +- scripts/buildInterfaces.js | 56 ++++++++++ scripts/buildInterfaces.mjs | 59 ---------- src/JSONSchemasInterface.js | 39 ++++--- tests/JSONSchemasInterface.tests.js | 161 +++++++++++++++++----------- tests/in_memory.tests.js | 21 +++- tests/utils/yaml.combine.tests.js | 1 + 8 files changed, 226 insertions(+), 145 deletions(-) create mode 100644 scripts/buildInterfaces.js delete mode 100644 scripts/buildInterfaces.mjs diff --git a/package-lock.json b/package-lock.json index a30780d4..f8e7992a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,18 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@apidevtools/json-schema-ref-parser": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-10.1.0.tgz", + "integrity": "sha512-3e+viyMuXdrcK8v5pvP+SDoAQ77FH6OyRmuK48SZKmdHJRFm87RsSs8qm6kP39a/pOPURByJw+OXzQIqcfmKtA==", + "requires": { + "@jsdevtools/ono": "^7.1.3", + "@types/json-schema": "^7.0.11", + "@types/lodash.clonedeep": "^4.5.7", + "js-yaml": "^4.1.0", + "lodash.clonedeep": "^4.5.0" + } + }, "@babel/cli": { "version": "7.16.0", "resolved": "https://registry.npmjs.org/@babel/cli/-/cli-7.16.0.tgz", @@ -1407,6 +1419,14 @@ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.195.tgz", "integrity": "sha512-Hwx9EUgdwf2GLarOjQp5ZH8ZmblzcbTBC2wtQWNKARBSxM9ezRIAUpeDTgoQRAFB0+8CNWXVA9+MaSOzOF3nPg==" }, + "@types/lodash.clonedeep": { + "version": "4.5.7", + "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.7.tgz", + "integrity": "sha512-ccNqkPptFIXrpVqUECi60/DFxjNKsfoQxSQsgcBJCX/fuX1wgyQieojkcWH/KpE3xzLoWN/2k+ZeGqIN3paSvw==", + "requires": { + "@types/lodash": "*" + } + }, "@types/minimatch": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", @@ -4009,6 +4029,11 @@ "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" }, + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" + }, "lodash.debounce": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", diff --git a/package.json b/package.json index 126b2d78..848ff633 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "postinstall": "npm run transpile && npm run buildInterfaces", "prettier": "prettier --check src tests", "prepare": "husky install", - "buildInterfaces": "node scripts/buildInterfaces.mjs" + "buildInterfaces": "node scripts/buildInterfaces.js" }, "repository": { "type": "git", @@ -45,6 +45,7 @@ "license": "Apache-2.0", "homepage": "https://github.com/Exabyte-io/code.js", "dependencies": { + "@apidevtools/json-schema-ref-parser": "^10.1.0", "@babel/cli": "7.16.0", "@babel/core": "7.16.0", "@babel/eslint-parser": "7.16.3", @@ -56,17 +57,17 @@ "@exabyte-io/esse.js": "git+https://github.com/Exabyte-io/esse.git#update/SOF-6535", "ajv": "4.1.7", "crypto-js": "^4.1.1", + "directory-tree": "^3.5.1", "js-yaml": "^4.1.0", "json-schema-merge-allof": "^0.8.1", + "json-schema-to-typescript": "^13.0.2", "lodash": "^4.17.21", "mathjs": "^3.9.0", "mixwith": "^0.1.1", "nunjucks": "^3.2.4", "underscore": "^1.13.3", "underscore.string": "^3.3.4", - "uuid": "8.3.2", - "directory-tree": "^3.5.1", - "json-schema-to-typescript": "^13.0.2" + "uuid": "8.3.2" }, "devDependencies": { "@exabyte-io/eslint-config": "^2022.11.17-0", diff --git a/scripts/buildInterfaces.js b/scripts/buildInterfaces.js new file mode 100644 index 00000000..e79aaac9 --- /dev/null +++ b/scripts/buildInterfaces.js @@ -0,0 +1,56 @@ +const fs = require("fs"); +const { compile } = require("json-schema-to-typescript"); +const { makeSchemaId, makeSchemaRef } = require("@exabyte-io/esse.js/lib/js/esse/utils"); + +/** + * Compiles ESSE JSON schemas to TypeScript interfaces/types + * @param {Object} globalSchema + * @param {String} savePath + * @returns {Promise} + * @example + * await compileTS(esseSchema, "./dist/types.ts"); + */ +async function compileTS(globalSchema, savePath) { + const preparedDefinitions = Object.entries(globalSchema.definitions).reduce( + (newDefinitions, [key, schema]) => { + if (schema.allOf && schema.properties) { + return [ + ...newDefinitions, + [ + key, + { + ...schema, + allOf: [ + ...schema.allOf, + makeSchemaRef(`${schema.schemaId}-properties`), + ], + properties: null, + }, + ], + [ + makeSchemaId(`${schema.schemaId}-properties`), + { + schemaId: `${schema.schemaId}-properties`, + type: "object", + properties: schema.properties, + }, + ], + ]; + } + + return [...newDefinitions, [key, schema]]; + }, + [], + ); + + const compiled = await compile({ + ...globalSchema, + definitions: Object.fromEntries(preparedDefinitions), + }); + + fs.writeFileSync(savePath, compiled); +} + +module.exports = { + compileTS, +}; diff --git a/scripts/buildInterfaces.mjs b/scripts/buildInterfaces.mjs deleted file mode 100644 index c0a680f7..00000000 --- a/scripts/buildInterfaces.mjs +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable no-await-in-loop */ -/* eslint-disable no-restricted-syntax */ -import directoryTree from "directory-tree"; -import fs from "fs/promises"; -import { compileFromFile } from "json-schema-to-typescript"; -import path from "path"; - -const typesPath = "./dist/types.ts"; -const schemaFolder = "node_modules/@exabyte-io/esse.js/schema"; - -await fs.writeFile(typesPath, "/* eslint-disable */\n\n"); - -const tree = directoryTree(schemaFolder, { extensions: /\.json$/ }); - -async function walkTree({ children }, cb) { - for (const item of children || []) { - if (item.children) { - await walkTree(item, cb); - } else { - await cb(item); - } - } -} - -const typesHash = {}; - -await walkTree(tree, async (item) => { - const ts = await compileFromFile(item.path, { - cwd: path.dirname(item.path), - bannerComment: `/** ${item.path} **/`, - }); - - const exports = ts.split("export "); - - exports.forEach((v) => { - const result = v.match(/^interface\s+\w+/g) || v.match(/^type\s+\w+/g); - - if (result) { - const typeName = result[0]; - - if (!typesHash[typeName] || v.indexOf("&") !== -1) { - /** - * In some cases types may be defined with bugs: sometimes "properties" are ignored when the "allOf" is present in the schema. - * We assume that type that contains "&" in it's definition is 100% correct (allOf + properties) => replace previously defined type if exists - */ - console.log(`Add ${typeName}`); - typesHash[typeName] = `export ${v}`; - } else { - // The type has been declared already - console.log(`Found ${typeName}`); - } - } else { - // expect bannerComment here - typesHash[item.path] = v; - } - }); -}); - -await fs.appendFile(typesPath, Object.values(typesHash).join("\n")); diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index 16747d74..efe175bd 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -1,4 +1,4 @@ -import { schemas } from "@exabyte-io/esse.js/schemas"; +import RefParser from "@apidevtools/json-schema-ref-parser"; import Ajv from "ajv"; import mergeAllOf from "json-schema-merge-allof"; @@ -47,15 +47,15 @@ export class JSONSchemasInterface { * @returns {Object.} resolved JSON schema */ static schemaById(schemaId) { - if (!schemasCache.has(schemaId)) { - const originalSchema = schemas.find((schema) => schema.schemaId === schemaId); + // if (!schemasCache.has(schemaId)) { + // const originalSchema = schemas.find((schema) => schema.schemaId === schemaId); - if (!originalSchema) { - throw new Error(`Schema not found: ${schemaId}`); - } + // if (!originalSchema) { + // throw new Error(`Schema not found: ${schemaId}`); + // } - this.registerSchema(originalSchema); - } + // this.registerSchema(originalSchema); + // } return schemasCache.get(schemaId); } @@ -64,16 +64,20 @@ export class JSONSchemasInterface { * * @param {Object} - external schema */ - static registerSchema(originalSchema) { - const schema = mergeAllOf(removeSchemaIdsAfterAllOf(originalSchema), { - resolvers: { - defaultResolver: mergeAllOf.options.resolvers.title, - }, - }); + static async registerGlobalSchema(globalSchema) { + const { definitions } = await RefParser.dereference(globalSchema); - schemasCache.set(schema.schemaId, schema); + schemasCache.clear(); - return schema; + Object.values(definitions).forEach((originalSchema) => { + const schema = mergeAllOf(removeSchemaIdsAfterAllOf(originalSchema), { + resolvers: { + defaultResolver: mergeAllOf.options.resolvers.title, + }, + }); + + schemasCache.set(schema.schemaId, schema); + }); } /** @@ -99,7 +103,8 @@ export class JSONSchemasInterface { */ static matchSchema(query) { const searchFields = Object.keys(query); - return schemas.find((schema) => { + + return Array.from(schemasCache.values()).find((schema) => { return searchFields.every((field) => { const { $regex } = query[field]; return new RegExp($regex).test(schema[field]); diff --git a/tests/JSONSchemasInterface.tests.js b/tests/JSONSchemasInterface.tests.js index bee7f0f4..2c57a365 100644 --- a/tests/JSONSchemasInterface.tests.js +++ b/tests/JSONSchemasInterface.tests.js @@ -1,14 +1,25 @@ +/* eslint-disable no-unused-expressions */ import { assert, expect } from "chai"; import { JSONSchemasInterface } from "../src/JSONSchemasInterface"; describe("JSONSchemasInterface", () => { - it("can find schema", () => { - const schema = JSONSchemasInterface.schemaById("workflow"); - expect(schema).to.be.an("object"); - }); + it("can match schemas", async () => { + await JSONSchemasInterface.registerGlobalSchema({ + definitions: { + workflow: { + schemaId: "workflow", + $schema: "http://json-schema.org/draft-04/schema#", + title: "System in-set schema", + properties: { + prop: { + type: "string", + }, + }, + }, + }, + }); - it("can match schemas", () => { const schema = JSONSchemasInterface.matchSchema({ schemaId: { $regex: "workflow", @@ -18,61 +29,79 @@ describe("JSONSchemasInterface", () => { expect(schema).to.be.an("object"); }); - it("can find registered schemas; the schema is merged and clean", () => { - JSONSchemasInterface.registerSchema({ - schemaId: "system/in-set", - $schema: "http://json-schema.org/draft-04/schema#", - title: "System in-set schema", - properties: { - inSet: { - type: "array", - items: { - allOf: [ - { - schemaId: "system/entity-reference", - $schema: "http://json-schema.org/draft-04/schema#", - title: "entity reference schema", - properties: { - _id: { - description: "entity identity", - type: "string", - }, - cls: { - description: "entity class", - type: "string", - }, - slug: { - description: "entity slug", - type: "string", - }, - }, - }, - { - type: "object", - properties: { - type: { - type: "string", + it("can find registered schemas; the schema is merged and clean", async () => { + await JSONSchemasInterface.registerGlobalSchema({ + definitions: { + "in-memory-entity-base": { + schemaId: "in-memory-entity/base", + $schema: "http://json-schema.org/draft-04/schema#", + title: "System in-set schema", + properties: { + _id: { + type: "string", + }, + type: { + type: "string", + }, + }, + }, + "system-in-set": { + schemaId: "system/in-set", + $schema: "http://json-schema.org/draft-04/schema#", + title: "System in-set schema", + properties: { + inSet: { + type: "array", + items: { + allOf: [ + { + schemaId: "system/entity-reference", + $schema: "http://json-schema.org/draft-04/schema#", + title: "entity reference schema", + properties: { + _id: { + description: "entity identity", + type: "string", + }, + cls: { + description: "entity class", + type: "string", + }, + slug: { + description: "entity slug", + type: "string", + }, + }, }, - index: { - type: "number", + { + type: "object", + properties: { + type: { + type: "string", + }, + index: { + type: "number", + }, + }, }, - }, + ], }, - ], + }, + valueMapFunction: { + description: + "Specifies the function to convert the currentValue in UI.", + type: "string", + enum: [ + "toString", + "toContactUs", + "toPlusMinusSign", + "toUnlimited", + "toSupportSeverity", + ], + default: "toString", + }, }, }, - valueMapFunction: { - description: "Specifies the function to convert the currentValue in UI.", - type: "string", - enum: [ - "toString", - "toContactUs", - "toPlusMinusSign", - "toUnlimited", - "toSupportSeverity", - ], - default: "toString", - }, }, }); @@ -89,16 +118,20 @@ describe("JSONSchemasInterface", () => { expect(schema.properties.valueMapFunction.enum[4]).to.be.an("string"); }); - it("can create a validation function for a schema by schema id", () => { - JSONSchemasInterface.registerSchema({ - schemaId: "test/person", - $schema: "http://json-schema.org/draft-04/schema#", - type: "object", - properties: { - name: { type: "string" }, - age: { type: "integer", minimum: 18 }, + it("can create a validation function for a schema by schema id", async () => { + await JSONSchemasInterface.registerGlobalSchema({ + definitions: { + "test-person": { + schemaId: "test/person", + $schema: "http://json-schema.org/draft-04/schema#", + type: "object", + properties: { + name: { type: "string" }, + age: { type: "integer", minimum: 18 }, + }, + required: ["name", "age"], + }, }, - required: ["name", "age"], }); const personValid = { name: "John Doe", age: 30 }; const personInvalid = { name: "John Doe", age: 15 }; diff --git a/tests/in_memory.tests.js b/tests/in_memory.tests.js index 4ed053d5..c4e370ad 100644 --- a/tests/in_memory.tests.js +++ b/tests/in_memory.tests.js @@ -2,6 +2,7 @@ import { expect } from "chai"; import { InMemoryEntity } from "../src/entity/in_memory"; +import { JSONSchemasInterface } from "../src/JSONSchemasInterface"; import { registerClassName } from "../src/utils/schemas"; describe("InMemoryEntity", () => { @@ -48,7 +49,7 @@ describe("InMemoryEntity", () => { expect(JSON.stringify(entity.toJSON())).to.be.equal(JSON.stringify(obj)); }); - it("jsonSchema returns correct registered schema", () => { + it("jsonSchema returns correct registered schema", async () => { class RegisteredEntity extends InMemoryEntity { static get customJsonSchemaProperties() { return { @@ -61,6 +62,24 @@ describe("InMemoryEntity", () => { registerClassName(RegisteredEntity.name, "in-memory-entity/base"); + await JSONSchemasInterface.registerGlobalSchema({ + definitions: { + "in-memory-entity-base": { + schemaId: "in-memory-entity/base", + $schema: "http://json-schema.org/draft-04/schema#", + title: "System in-set schema", + properties: { + _id: { + type: "string", + }, + type: { + type: "string", + }, + }, + }, + }, + }); + expect(RegisteredEntity.jsonSchema).to.be.an("object"); expect(RegisteredEntity.jsonSchema).to.have.nested.property("properties._id"); // check mix schemas expect(RegisteredEntity.jsonSchema).to.have.nested.property("properties.nested.type"); // check custom properties diff --git a/tests/utils/yaml.combine.tests.js b/tests/utils/yaml.combine.tests.js index 6fed1956..04065f50 100644 --- a/tests/utils/yaml.combine.tests.js +++ b/tests/utils/yaml.combine.tests.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-expressions */ import { expect } from "chai"; import fs from "fs"; import yaml from "js-yaml"; From cb1440114768621da3f7f8a3641d8ef7602da09e Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Wed, 5 Jul 2023 18:19:54 +0300 Subject: [PATCH 09/38] chore: clean package.json --- package-lock.json | 115 ---------------------------------------------- package.json | 6 +-- 2 files changed, 2 insertions(+), 119 deletions(-) diff --git a/package-lock.json b/package-lock.json index f8e7992a..58586a6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1568,11 +1568,6 @@ "@babel/runtime-corejs3": "^7.10.2" } }, - "array-back": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz", - "integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==" - }, "array-includes": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.5.tgz", @@ -1991,40 +1986,6 @@ "integrity": "sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==", "dev": true }, - "command-line-args": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.1.tgz", - "integrity": "sha512-H4UfQhZyakIjC74I9d34fGYDwk3XpSr17QhEd0Q3I9Xq1CETHo4Hcuo87WyWHpAF1aSLjLRf5lD9ZGX2qStUvg==", - "requires": { - "array-back": "^3.1.0", - "find-replace": "^3.0.0", - "lodash.camelcase": "^4.3.0", - "typical": "^4.0.0" - } - }, - "command-line-usage": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/command-line-usage/-/command-line-usage-6.1.3.tgz", - "integrity": "sha512-sH5ZSPr+7UStsloltmDh7Ce5fb8XPlHyoPzTpyyMuYCtervL65+ubVZ6Q61cFtFl62UyJlc8/JwERRbAFPUqgw==", - "requires": { - "array-back": "^4.0.2", - "chalk": "^2.4.2", - "table-layout": "^1.0.2", - "typical": "^5.2.0" - }, - "dependencies": { - "array-back": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/array-back/-/array-back-4.0.2.tgz", - "integrity": "sha512-NbdMezxqf94cnNfWLL7V/im0Ub+Anbb0IoZhvzie8+4HJ4nMQuzHuy49FkGYCJK2yAloZ3meiB6AVMClbrI1vg==" - }, - "typical": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/typical/-/typical-5.2.0.tgz", - "integrity": "sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg==" - } - } - }, "commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -2176,11 +2137,6 @@ "type-detect": "^4.0.0" } }, - "deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" - }, "deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -2219,15 +2175,6 @@ "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", "dev": true }, - "directory-tree": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/directory-tree/-/directory-tree-3.5.1.tgz", - "integrity": "sha512-HqjZ49fDzUnKYUhHxVw9eKBqbQ+lL0v4kSBInlDlaktmLtGoV9tC54a6A0ZfYeIrkMHWTE6MwwmUXP477+UEKQ==", - "requires": { - "command-line-args": "^5.2.0", - "command-line-usage": "^6.1.1" - } - }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -3032,14 +2979,6 @@ "pkg-dir": "^3.0.0" } }, - "find-replace": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", - "integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==", - "requires": { - "array-back": "^3.0.1" - } - }, "find-up": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", @@ -4024,11 +3963,6 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, - "lodash.camelcase": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", - "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" - }, "lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", @@ -5056,11 +4990,6 @@ "picomatch": "^2.2.1" } }, - "reduce-flatten": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/reduce-flatten/-/reduce-flatten-2.0.0.tgz", - "integrity": "sha512-EJ4UNY/U1t2P/2k6oqotuX2Cc3T6nxJwsM0N0asT7dhrtH1ltUxDn4NalSYmPE2rCkVpcf/X6R0wDwcFpzhd4w==" - }, "regenerate": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", @@ -5539,29 +5468,6 @@ } } }, - "table-layout": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/table-layout/-/table-layout-1.0.2.tgz", - "integrity": "sha512-qd/R7n5rQTRFi+Zf2sk5XVVd9UQl6ZkduPFC3S7WEGJAmetDTjY3qPN50eSKzwuzEyQKy5TN2TiZdkIjos2L6A==", - "requires": { - "array-back": "^4.0.1", - "deep-extend": "~0.6.0", - "typical": "^5.2.0", - "wordwrapjs": "^4.0.0" - }, - "dependencies": { - "array-back": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/array-back/-/array-back-4.0.2.tgz", - "integrity": "sha512-NbdMezxqf94cnNfWLL7V/im0Ub+Anbb0IoZhvzie8+4HJ4nMQuzHuy49FkGYCJK2yAloZ3meiB6AVMClbrI1vg==" - }, - "typical": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/typical/-/typical-5.2.0.tgz", - "integrity": "sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg==" - } - } - }, "test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -5702,11 +5608,6 @@ "is-typedarray": "^1.0.0" } }, - "typical": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", - "integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==" - }, "unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -5860,22 +5761,6 @@ "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "dev": true }, - "wordwrapjs": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/wordwrapjs/-/wordwrapjs-4.0.1.tgz", - "integrity": "sha512-kKlNACbvHrkpIw6oPeYDSmdCTu2hdMHoyXLTcUKala++lx5Y+wjJ/e474Jqv5abnVmwxw08DiTuHmw69lJGksA==", - "requires": { - "reduce-flatten": "^2.0.0", - "typical": "^5.2.0" - }, - "dependencies": { - "typical": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/typical/-/typical-5.2.0.tgz", - "integrity": "sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg==" - } - } - }, "workerpool": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.0.tgz", diff --git a/package.json b/package.json index 848ff633..a4cb8de4 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lint": "eslint src tests scripts && prettier --write src tests scripts", "lint:fix": "eslint --fix --cache src tests && prettier --write src tests", "transpile": "babel --out-dir dist src", - "postinstall": "npm run transpile && npm run buildInterfaces", + "postinstall": "npm run transpile", "prettier": "prettier --check src tests", "prepare": "husky install", "buildInterfaces": "node scripts/buildInterfaces.js" @@ -29,8 +29,7 @@ "./dist/utils": "./dist/utils/index.js", "./dist/constants": "./dist/constants.js", "./dist/math": "./dist/math.js", - "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js", - "./dist/types": "./dist/types.ts" + "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js" }, "files": [ "/dist", @@ -57,7 +56,6 @@ "@exabyte-io/esse.js": "git+https://github.com/Exabyte-io/esse.git#update/SOF-6535", "ajv": "4.1.7", "crypto-js": "^4.1.1", - "directory-tree": "^3.5.1", "js-yaml": "^4.1.0", "json-schema-merge-allof": "^0.8.1", "json-schema-to-typescript": "^13.0.2", From 28ce39dc11099a6796bdffb815652f4a4879683b Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Wed, 5 Jul 2023 21:06:40 +0300 Subject: [PATCH 10/38] chore: use new esse interface --- scripts/buildInterfaces.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/buildInterfaces.js b/scripts/buildInterfaces.js index e79aaac9..4cbf7708 100644 --- a/scripts/buildInterfaces.js +++ b/scripts/buildInterfaces.js @@ -1,6 +1,6 @@ const fs = require("fs"); const { compile } = require("json-schema-to-typescript"); -const { makeSchemaId, makeSchemaRef } = require("@exabyte-io/esse.js/lib/js/esse/utils"); +const { makeFlatSchemaId, makeFlatSchemaRef } = require("@exabyte-io/esse.js/lib/js/esse/utils"); /** * Compiles ESSE JSON schemas to TypeScript interfaces/types @@ -22,13 +22,13 @@ async function compileTS(globalSchema, savePath) { ...schema, allOf: [ ...schema.allOf, - makeSchemaRef(`${schema.schemaId}-properties`), + makeFlatSchemaRef(`${schema.schemaId}-properties`), ], properties: null, }, ], [ - makeSchemaId(`${schema.schemaId}-properties`), + makeFlatSchemaId(`${schema.schemaId}-properties`), { schemaId: `${schema.schemaId}-properties`, type: "object", From ae2e2ad30b3c968e36ed31069a71dd33707add26 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Wed, 5 Jul 2023 21:13:04 +0300 Subject: [PATCH 11/38] chore: export all schema utils --- src/utils/schemas.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/schemas.js b/src/utils/schemas.js index f1ed2a79..c68e5b7d 100644 --- a/src/utils/schemas.js +++ b/src/utils/schemas.js @@ -2,6 +2,8 @@ import lodash from "lodash"; import { JSONSchemasInterface } from "../JSONSchemasInterface"; +export * from "@exabyte-io/esse.js/lib/js/esse/utils"; + export const schemas = {}; /** From c73e50c655f667ef9480b53fb08a80d791419874 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Wed, 5 Jul 2023 21:34:03 +0300 Subject: [PATCH 12/38] chore: export esse chema --- src/entity/in_memory.js | 1 - src/utils/schemas.js | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/entity/in_memory.js b/src/entity/in_memory.js index b0844c3a..b7a7cada 100644 --- a/src/entity/in_memory.js +++ b/src/entity/in_memory.js @@ -1,6 +1,5 @@ import lodash from "lodash"; -// import { ESSE } from "@exabyte-io/esse.js"; import { clone, deepClone } from "../utils/clone"; import { getSchemaByClassName } from "../utils/schemas"; diff --git a/src/utils/schemas.js b/src/utils/schemas.js index c68e5b7d..e7ac0d46 100644 --- a/src/utils/schemas.js +++ b/src/utils/schemas.js @@ -2,6 +2,8 @@ import lodash from "lodash"; import { JSONSchemasInterface } from "../JSONSchemasInterface"; +export * as esseSchema from "@exabyte-io/esse.js/schemas"; + export * from "@exabyte-io/esse.js/lib/js/esse/utils"; export const schemas = {}; From fd3b65585acb4b60baca75b2c4696cf3aea5e450 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Thu, 6 Jul 2023 14:50:20 +0300 Subject: [PATCH 13/38] update: remove this.customJsonSchemaProperties functionality --- src/entity/in_memory.js | 34 +--------------------------------- tests/in_memory.tests.js | 11 +---------- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/src/entity/in_memory.js b/src/entity/in_memory.js index b7a7cada..37796332 100644 --- a/src/entity/in_memory.js +++ b/src/entity/in_memory.js @@ -190,45 +190,13 @@ export class InMemoryEntity { return filtered[0]; } - /** - * @summary If there any nested in-memory entities, first resolve them - * and then mix with original schema in baseJSONSchema() - * @returns {Object.|null} - * @example - * class Workflow extends InMemoryEntity { - * get customJsonSchemaProperties() { - * return { - * subworkflows: { - * type: 'array', - * items: Subworkflow.jsonSchema - * } - * }; - * } - * } - */ - static get customJsonSchemaProperties() { - return null; - } - /** * Returns class JSON schema * @returns {Object} schema */ static get jsonSchema() { try { - if (!this.customJsonSchemaProperties) { - return getSchemaByClassName(this.name); - } - - const { properties, ...schema } = getSchemaByClassName(this.name); - - return { - ...schema, - properties: { - ...properties, - ...this.customJsonSchemaProperties, - }, - }; + return getSchemaByClassName(this.name); } catch (e) { console.error(e.stack); throw e; diff --git a/tests/in_memory.tests.js b/tests/in_memory.tests.js index c4e370ad..70534c9a 100644 --- a/tests/in_memory.tests.js +++ b/tests/in_memory.tests.js @@ -50,15 +50,7 @@ describe("InMemoryEntity", () => { }); it("jsonSchema returns correct registered schema", async () => { - class RegisteredEntity extends InMemoryEntity { - static get customJsonSchemaProperties() { - return { - nested: { - type: "string", - }, - }; - } - } + class RegisteredEntity extends InMemoryEntity {} registerClassName(RegisteredEntity.name, "in-memory-entity/base"); @@ -82,6 +74,5 @@ describe("InMemoryEntity", () => { expect(RegisteredEntity.jsonSchema).to.be.an("object"); expect(RegisteredEntity.jsonSchema).to.have.nested.property("properties._id"); // check mix schemas - expect(RegisteredEntity.jsonSchema).to.have.nested.property("properties.nested.type"); // check custom properties }); }); From d996141370f6ada858de2d24cd675023eea1c5d1 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Thu, 6 Jul 2023 21:21:45 +0300 Subject: [PATCH 14/38] chore: test old code --- src/JSONSchemasInterface.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index efe175bd..2d256818 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -1,4 +1,5 @@ import RefParser from "@apidevtools/json-schema-ref-parser"; +import { schemas } from "@exabyte-io/esse.js/schemas"; import Ajv from "ajv"; import mergeAllOf from "json-schema-merge-allof"; @@ -47,19 +48,35 @@ export class JSONSchemasInterface { * @returns {Object.} resolved JSON schema */ static schemaById(schemaId) { - // if (!schemasCache.has(schemaId)) { - // const originalSchema = schemas.find((schema) => schema.schemaId === schemaId); + if (!schemasCache.has(schemaId)) { + const originalSchema = schemas.find((schema) => schema.schemaId === schemaId); - // if (!originalSchema) { - // throw new Error(`Schema not found: ${schemaId}`); - // } + if (!originalSchema) { + throw new Error(`Schema not found: ${schemaId}`); + } - // this.registerSchema(originalSchema); - // } + this.registerSchema(originalSchema); + } return schemasCache.get(schemaId); } + /** + * + * @param {Object} - external schema + */ + static registerSchema(originalSchema) { + const schema = mergeAllOf(removeSchemaIdsAfterAllOf(originalSchema), { + resolvers: { + defaultResolver: mergeAllOf.options.resolvers.title, + }, + }); + + schemasCache.set(schema.schemaId, schema); + + return schema; + } + /** * * @param {Object} - external schema From 6855d2dddec1128f3df132a92ddfab1c5e93a841 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Thu, 6 Jul 2023 21:45:31 +0300 Subject: [PATCH 15/38] chore: test old code --- src/utils/schemas.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/schemas.js b/src/utils/schemas.js index e7ac0d46..6803c680 100644 --- a/src/utils/schemas.js +++ b/src/utils/schemas.js @@ -1,11 +1,12 @@ +import globalSchema from "@exabyte-io/esse.js/schema"; import lodash from "lodash"; import { JSONSchemasInterface } from "../JSONSchemasInterface"; -export * as esseSchema from "@exabyte-io/esse.js/schemas"; - export * from "@exabyte-io/esse.js/lib/js/esse/utils"; +export const esseSchema = globalSchema; + export const schemas = {}; /** From b3a5dad8306c8ac98ddcff66cba61107a658b643 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Thu, 6 Jul 2023 21:50:20 +0300 Subject: [PATCH 16/38] chore: test old code --- src/entity/in_memory.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/entity/in_memory.js b/src/entity/in_memory.js index 37796332..b7a7cada 100644 --- a/src/entity/in_memory.js +++ b/src/entity/in_memory.js @@ -190,13 +190,45 @@ export class InMemoryEntity { return filtered[0]; } + /** + * @summary If there any nested in-memory entities, first resolve them + * and then mix with original schema in baseJSONSchema() + * @returns {Object.|null} + * @example + * class Workflow extends InMemoryEntity { + * get customJsonSchemaProperties() { + * return { + * subworkflows: { + * type: 'array', + * items: Subworkflow.jsonSchema + * } + * }; + * } + * } + */ + static get customJsonSchemaProperties() { + return null; + } + /** * Returns class JSON schema * @returns {Object} schema */ static get jsonSchema() { try { - return getSchemaByClassName(this.name); + if (!this.customJsonSchemaProperties) { + return getSchemaByClassName(this.name); + } + + const { properties, ...schema } = getSchemaByClassName(this.name); + + return { + ...schema, + properties: { + ...properties, + ...this.customJsonSchemaProperties, + }, + }; } catch (e) { console.error(e.stack); throw e; From a0ad0bc0b4ab5049749ff70fd37a8cc8bfdbcdc0 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Thu, 6 Jul 2023 22:46:59 +0300 Subject: [PATCH 17/38] chore: use new esse --- src/utils/schemas.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/schemas.js b/src/utils/schemas.js index 6803c680..9149284f 100644 --- a/src/utils/schemas.js +++ b/src/utils/schemas.js @@ -3,7 +3,7 @@ import lodash from "lodash"; import { JSONSchemasInterface } from "../JSONSchemasInterface"; -export * from "@exabyte-io/esse.js/lib/js/esse/utils"; +export * from "@exabyte-io/esse.js/lib/js/esse/schemaUtils"; export const esseSchema = globalSchema; From d594ee99ffdce24e6fe16aa809fc0acf0cebe603 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Thu, 6 Jul 2023 23:06:27 +0300 Subject: [PATCH 18/38] chore: fix files --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index a4cb8de4..6ec084cd 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "files": [ "/dist", "/src", - "/scripts", ".babelrc" ], "author": "Exabyte Inc.", From 21bed9884d65c31bdfbdb2ce577bcebda6d46bcc Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Thu, 6 Jul 2023 23:14:24 +0300 Subject: [PATCH 19/38] chore: test --- src/JSONSchemasInterface.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index 2d256818..dc640f64 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -1,4 +1,4 @@ -import RefParser from "@apidevtools/json-schema-ref-parser"; +// import RefParser from "@apidevtools/json-schema-ref-parser"; import { schemas } from "@exabyte-io/esse.js/schemas"; import Ajv from "ajv"; import mergeAllOf from "json-schema-merge-allof"; From 8c133b386e9a2a05669fbbdefd5a6666d013932f Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Thu, 6 Jul 2023 23:23:52 +0300 Subject: [PATCH 20/38] chore: fix files --- package.json | 2 +- src/JSONSchemasInterface.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6ec084cd..9821866e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "license": "Apache-2.0", "homepage": "https://github.com/Exabyte-io/code.js", "dependencies": { - "@apidevtools/json-schema-ref-parser": "^10.1.0", + "@apidevtools/json-schema-ref-parser": "^10.0.1", "@babel/cli": "7.16.0", "@babel/core": "7.16.0", "@babel/eslint-parser": "7.16.3", diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index dc640f64..2d256818 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -1,4 +1,4 @@ -// import RefParser from "@apidevtools/json-schema-ref-parser"; +import RefParser from "@apidevtools/json-schema-ref-parser"; import { schemas } from "@exabyte-io/esse.js/schemas"; import Ajv from "ajv"; import mergeAllOf from "json-schema-merge-allof"; From 957a84d28eadc5438ea059b77ee9df2f1f25c884 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 13:31:20 +0300 Subject: [PATCH 21/38] update: remove old schemas usage --- src/JSONSchemasInterface.js | 27 --------------------------- src/entity/in_memory.js | 34 +--------------------------------- 2 files changed, 1 insertion(+), 60 deletions(-) diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index 2d256818..26901e8b 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -1,5 +1,4 @@ import RefParser from "@apidevtools/json-schema-ref-parser"; -import { schemas } from "@exabyte-io/esse.js/schemas"; import Ajv from "ajv"; import mergeAllOf from "json-schema-merge-allof"; @@ -48,35 +47,9 @@ export class JSONSchemasInterface { * @returns {Object.} resolved JSON schema */ static schemaById(schemaId) { - if (!schemasCache.has(schemaId)) { - const originalSchema = schemas.find((schema) => schema.schemaId === schemaId); - - if (!originalSchema) { - throw new Error(`Schema not found: ${schemaId}`); - } - - this.registerSchema(originalSchema); - } - return schemasCache.get(schemaId); } - /** - * - * @param {Object} - external schema - */ - static registerSchema(originalSchema) { - const schema = mergeAllOf(removeSchemaIdsAfterAllOf(originalSchema), { - resolvers: { - defaultResolver: mergeAllOf.options.resolvers.title, - }, - }); - - schemasCache.set(schema.schemaId, schema); - - return schema; - } - /** * * @param {Object} - external schema diff --git a/src/entity/in_memory.js b/src/entity/in_memory.js index b7a7cada..37796332 100644 --- a/src/entity/in_memory.js +++ b/src/entity/in_memory.js @@ -190,45 +190,13 @@ export class InMemoryEntity { return filtered[0]; } - /** - * @summary If there any nested in-memory entities, first resolve them - * and then mix with original schema in baseJSONSchema() - * @returns {Object.|null} - * @example - * class Workflow extends InMemoryEntity { - * get customJsonSchemaProperties() { - * return { - * subworkflows: { - * type: 'array', - * items: Subworkflow.jsonSchema - * } - * }; - * } - * } - */ - static get customJsonSchemaProperties() { - return null; - } - /** * Returns class JSON schema * @returns {Object} schema */ static get jsonSchema() { try { - if (!this.customJsonSchemaProperties) { - return getSchemaByClassName(this.name); - } - - const { properties, ...schema } = getSchemaByClassName(this.name); - - return { - ...schema, - properties: { - ...properties, - ...this.customJsonSchemaProperties, - }, - }; + return getSchemaByClassName(this.name); } catch (e) { console.error(e.stack); throw e; From 8d21d4b125e3b6b08389df249c55e8251b49e124 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 14:38:18 +0300 Subject: [PATCH 22/38] chore: new deref lib --- package-lock.json | 25 ------------------------- package.json | 2 +- src/JSONSchemasInterface.js | 4 ++-- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 58586a6f..e0530331 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,18 +4,6 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "@apidevtools/json-schema-ref-parser": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-10.1.0.tgz", - "integrity": "sha512-3e+viyMuXdrcK8v5pvP+SDoAQ77FH6OyRmuK48SZKmdHJRFm87RsSs8qm6kP39a/pOPURByJw+OXzQIqcfmKtA==", - "requires": { - "@jsdevtools/ono": "^7.1.3", - "@types/json-schema": "^7.0.11", - "@types/lodash.clonedeep": "^4.5.7", - "js-yaml": "^4.1.0", - "lodash.clonedeep": "^4.5.0" - } - }, "@babel/cli": { "version": "7.16.0", "resolved": "https://registry.npmjs.org/@babel/cli/-/cli-7.16.0.tgz", @@ -1419,14 +1407,6 @@ "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.195.tgz", "integrity": "sha512-Hwx9EUgdwf2GLarOjQp5ZH8ZmblzcbTBC2wtQWNKARBSxM9ezRIAUpeDTgoQRAFB0+8CNWXVA9+MaSOzOF3nPg==" }, - "@types/lodash.clonedeep": { - "version": "4.5.7", - "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.7.tgz", - "integrity": "sha512-ccNqkPptFIXrpVqUECi60/DFxjNKsfoQxSQsgcBJCX/fuX1wgyQieojkcWH/KpE3xzLoWN/2k+ZeGqIN3paSvw==", - "requires": { - "@types/lodash": "*" - } - }, "@types/minimatch": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", @@ -3963,11 +3943,6 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, - "lodash.clonedeep": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" - }, "lodash.debounce": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", diff --git a/package.json b/package.json index 9821866e..fba9f428 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "license": "Apache-2.0", "homepage": "https://github.com/Exabyte-io/code.js", "dependencies": { - "@apidevtools/json-schema-ref-parser": "^10.0.1", + "json-schema-deref-sync": "0.14.0", "@babel/cli": "7.16.0", "@babel/core": "7.16.0", "@babel/eslint-parser": "7.16.3", diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index 26901e8b..6950d73d 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -1,5 +1,5 @@ -import RefParser from "@apidevtools/json-schema-ref-parser"; import Ajv from "ajv"; +import deref from "json-schema-deref-sync"; import mergeAllOf from "json-schema-merge-allof"; const schemasCache = new Map(); @@ -55,7 +55,7 @@ export class JSONSchemasInterface { * @param {Object} - external schema */ static async registerGlobalSchema(globalSchema) { - const { definitions } = await RefParser.dereference(globalSchema); + const { definitions } = deref(globalSchema); schemasCache.clear(); From 145522dbf702feaa0f0351cab84a42c6bb288f9d Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 14:53:08 +0300 Subject: [PATCH 23/38] chore: new deref lib deasync --- src/JSONSchemasInterface.js | 2 +- tests/JSONSchemasInterface.tests.js | 6 +++--- tests/in_memory.tests.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index 6950d73d..26276937 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -54,7 +54,7 @@ export class JSONSchemasInterface { * * @param {Object} - external schema */ - static async registerGlobalSchema(globalSchema) { + static registerGlobalSchema(globalSchema) { const { definitions } = deref(globalSchema); schemasCache.clear(); diff --git a/tests/JSONSchemasInterface.tests.js b/tests/JSONSchemasInterface.tests.js index 2c57a365..1822927b 100644 --- a/tests/JSONSchemasInterface.tests.js +++ b/tests/JSONSchemasInterface.tests.js @@ -5,7 +5,7 @@ import { JSONSchemasInterface } from "../src/JSONSchemasInterface"; describe("JSONSchemasInterface", () => { it("can match schemas", async () => { - await JSONSchemasInterface.registerGlobalSchema({ + JSONSchemasInterface.registerGlobalSchema({ definitions: { workflow: { schemaId: "workflow", @@ -30,7 +30,7 @@ describe("JSONSchemasInterface", () => { }); it("can find registered schemas; the schema is merged and clean", async () => { - await JSONSchemasInterface.registerGlobalSchema({ + JSONSchemasInterface.registerGlobalSchema({ definitions: { "in-memory-entity-base": { schemaId: "in-memory-entity/base", @@ -119,7 +119,7 @@ describe("JSONSchemasInterface", () => { }); it("can create a validation function for a schema by schema id", async () => { - await JSONSchemasInterface.registerGlobalSchema({ + JSONSchemasInterface.registerGlobalSchema({ definitions: { "test-person": { schemaId: "test/person", diff --git a/tests/in_memory.tests.js b/tests/in_memory.tests.js index 70534c9a..dbf44147 100644 --- a/tests/in_memory.tests.js +++ b/tests/in_memory.tests.js @@ -54,7 +54,7 @@ describe("InMemoryEntity", () => { registerClassName(RegisteredEntity.name, "in-memory-entity/base"); - await JSONSchemasInterface.registerGlobalSchema({ + JSONSchemasInterface.registerGlobalSchema({ definitions: { "in-memory-entity-base": { schemaId: "in-memory-entity/base", From 63c892a931508244f7a06c3dec1bbc0f7aef5ab2 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 15:57:47 +0300 Subject: [PATCH 24/38] chore: move buildInterfaces script --- {scripts => src/utils}/buildInterfaces.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {scripts => src/utils}/buildInterfaces.js (100%) diff --git a/scripts/buildInterfaces.js b/src/utils/buildInterfaces.js similarity index 100% rename from scripts/buildInterfaces.js rename to src/utils/buildInterfaces.js From 4abe511ecaec1ee7aa687a5709c701845c297684 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 17:12:28 +0300 Subject: [PATCH 25/38] fix: compileTS script --- src/utils/{buildInterfaces.js => compileTS.js} | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) rename src/utils/{buildInterfaces.js => compileTS.js} (82%) diff --git a/src/utils/buildInterfaces.js b/src/utils/compileTS.js similarity index 82% rename from src/utils/buildInterfaces.js rename to src/utils/compileTS.js index 4cbf7708..207594c1 100644 --- a/src/utils/buildInterfaces.js +++ b/src/utils/compileTS.js @@ -1,6 +1,6 @@ -const fs = require("fs"); -const { compile } = require("json-schema-to-typescript"); -const { makeFlatSchemaId, makeFlatSchemaRef } = require("@exabyte-io/esse.js/lib/js/esse/utils"); +import { makeFlatSchemaId, makeFlatSchemaRef } from "@exabyte-io/esse.js/lib/js/esse/schemaUtils"; +import fs from "fs/promises"; +import { compile } from "json-schema-to-typescript"; /** * Compiles ESSE JSON schemas to TypeScript interfaces/types @@ -10,7 +10,7 @@ const { makeFlatSchemaId, makeFlatSchemaRef } = require("@exabyte-io/esse.js/lib * @example * await compileTS(esseSchema, "./dist/types.ts"); */ -async function compileTS(globalSchema, savePath) { +export async function compileTS(globalSchema, savePath) { const preparedDefinitions = Object.entries(globalSchema.definitions).reduce( (newDefinitions, [key, schema]) => { if (schema.allOf && schema.properties) { @@ -48,9 +48,5 @@ async function compileTS(globalSchema, savePath) { definitions: Object.fromEntries(preparedDefinitions), }); - fs.writeFileSync(savePath, compiled); + await fs.writeFile(savePath, compiled); } - -module.exports = { - compileTS, -}; From 16e323a663662c543f2f51108d44dd528cb6eab3 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 17:21:06 +0300 Subject: [PATCH 26/38] fix: compileTS script --- src/utils/compileTS.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/utils/compileTS.js b/src/utils/compileTS.js index 207594c1..18e4e43b 100644 --- a/src/utils/compileTS.js +++ b/src/utils/compileTS.js @@ -43,10 +43,16 @@ export async function compileTS(globalSchema, savePath) { [], ); - const compiled = await compile({ - ...globalSchema, - definitions: Object.fromEntries(preparedDefinitions), - }); + const compiled = await compile( + { + ...globalSchema, + definitions: Object.fromEntries(preparedDefinitions), + }, + "", + { + unreachableDefinitions: true, + }, + ); await fs.writeFile(savePath, compiled); } From c3610677b9cf14bd53db678c4f72af418b43d3b9 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 17:33:48 +0300 Subject: [PATCH 27/38] chore: export compileTs --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index fba9f428..9032009f 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "./dist/utils": "./dist/utils/index.js", "./dist/constants": "./dist/constants.js", "./dist/math": "./dist/math.js", + "./dist/compileTS": "./dist/compileTS.js", "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js" }, "files": [ From aa6c81c523aad81e1c361fe8905d7e80cdc591e3 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 17:36:25 +0300 Subject: [PATCH 28/38] chore: export compileTs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9032009f..e1782d3a 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "./dist/utils": "./dist/utils/index.js", "./dist/constants": "./dist/constants.js", "./dist/math": "./dist/math.js", - "./dist/compileTS": "./dist/compileTS.js", + "./dist/compileTS": "./dist/utils/compileTS.js", "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js" }, "files": [ From ec689cce0601b778d07efa5af6118059fc664179 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 17:38:17 +0300 Subject: [PATCH 29/38] chore: export schemas --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index e1782d3a..ef2f9587 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "./dist/constants": "./dist/constants.js", "./dist/math": "./dist/math.js", "./dist/compileTS": "./dist/utils/compileTS.js", + "./dist/schemas": "./dist/utils/schemas.js", "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js" }, "files": [ From da1d51e368eb616c11293942402c53244817d70d Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 22:06:53 +0300 Subject: [PATCH 30/38] chore: bin folder with scripts --- package.json | 4 ++-- src/{utils => bin}/compileTS.js | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{utils => bin}/compileTS.js (100%) diff --git a/package.json b/package.json index ef2f9587..7b3b24b2 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,9 @@ "./dist/utils": "./dist/utils/index.js", "./dist/constants": "./dist/constants.js", "./dist/math": "./dist/math.js", - "./dist/compileTS": "./dist/utils/compileTS.js", "./dist/schemas": "./dist/utils/schemas.js", - "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js" + "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js", + "./dist/bin/compileTS": "./dist/bin/compileTS.js" }, "files": [ "/dist", diff --git a/src/utils/compileTS.js b/src/bin/compileTS.js similarity index 100% rename from src/utils/compileTS.js rename to src/bin/compileTS.js From 140307684f42be831e7d74a15fbb86fd50786bc0 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 22:33:55 +0300 Subject: [PATCH 31/38] chore: import schemas for meteor --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 7b3b24b2..379a3324 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "./dist/constants": "./dist/constants.js", "./dist/math": "./dist/math.js", "./dist/schemas": "./dist/utils/schemas.js", + "./dist/utils/schemas": "./dist/utils/schemas.js", "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js", "./dist/bin/compileTS": "./dist/bin/compileTS.js" }, From 8cc292c0340378c194ade4e4c83cea524d194618 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 7 Jul 2023 22:38:50 +0300 Subject: [PATCH 32/38] chore: import schemas for meteor --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 379a3324..3cb3019a 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "./dist/utils": "./dist/utils/index.js", "./dist/constants": "./dist/constants.js", "./dist/math": "./dist/math.js", - "./dist/schemas": "./dist/utils/schemas.js", "./dist/utils/schemas": "./dist/utils/schemas.js", "./dist/JSONSchemasInterface": "./dist/JSONSchemasInterface.js", "./dist/bin/compileTS": "./dist/bin/compileTS.js" From caf287298eda7082f6a2c12924692eb3c9790646 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Mon, 10 Jul 2023 13:20:01 +0300 Subject: [PATCH 33/38] chore: clean package.json --- package.json | 5 +- tests/fixtures/yaml_combine_tag.yml | 110 ++++++++++++++-------------- 2 files changed, 57 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index 3cb3019a..37ce0f52 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,12 @@ "description": "COre DEfinitions in JS for Mat3ra.com (Exabyte.io)", "scripts": { "test": "nyc --reporter=text mocha --recursive --bail --require @babel/register/lib --require tests/setup.js tests", - "lint": "eslint src tests scripts && prettier --write src tests scripts", + "lint": "eslint src tests && prettier --write src tests", "lint:fix": "eslint --fix --cache src tests && prettier --write src tests", "transpile": "babel --out-dir dist src", "postinstall": "npm run transpile", "prettier": "prettier --check src tests", - "prepare": "husky install", - "buildInterfaces": "node scripts/buildInterfaces.js" + "prepare": "husky install" }, "repository": { "type": "git", diff --git a/tests/fixtures/yaml_combine_tag.yml b/tests/fixtures/yaml_combine_tag.yml index 406f4fc5..965a9bc9 100644 --- a/tests/fixtures/yaml_combine_tag.yml +++ b/tests/fixtures/yaml_combine_tag.yml @@ -2,10 +2,10 @@ case1: !combine name: mytest forEach: - - key: a - values: [1, 2] - - key: b - values: [3, 4] + - key: a + values: [1, 2] + - key: b + values: [3, 4] config: c: 5 @@ -17,8 +17,8 @@ case2: !combine case3: !combine name: mytest forEach: - - key: a - - key: b + - key: a + - key: b # parse a custom !combine tag with an empty forEach key and a config key case4: !combine @@ -35,10 +35,10 @@ case5: !combine two: 2 four: 4 forEach: - - key: a - values: [1] - - key: b - values: ["two", "four"] + - key: a + values: [1] + - key: b + values: ["two", "four"] config: c: 5 @@ -46,27 +46,27 @@ case5: !combine case6: !combine name: mytest forEach: - - key: b - values: [3, 4] + - key: b + values: [3, 4] config: a: 1 extraConfigs: - - name: additional property - x: 7 + - name: additional property + x: 7 # parse a custom !combine tag with additional property from !combine tag case7: !combine name: mytest forEach: - - key: b - values: [3, 4] + - key: b + values: [3, 4] config: a: 1 extraConfigs: !combine name: additional property forEach: - - key: x - values: [7, 8] + - key: x + values: [7, 8] config: y: 9 @@ -78,8 +78,8 @@ case8: !combine two: 2 four: 4 forEach: - - key: b - values: ["two", "four", null] + - key: b + values: ["two", "four", null] config: a: 1 @@ -98,48 +98,48 @@ case9: !combine case10: !combine name: ignore test forEach: - - key: a.b - values: [1, 2, null] - - key: a.c - values: [3] - - key: d - values: [4] + - key: a.b + values: [1, 2, null] + - key: a.c + values: [3] + - key: d + values: [4] exclusions: - - ["a.b" , "d"] + - ["a.b", "d"] # use the push action to add value to an array parameter case11: !combine name: push test forEach: - - key: units - action: push - values: - - a: 1 - - a: 2 - - a: 3 - - key: units - action: push - values: - - b: 4 - - b: 5 + - key: units + action: push + values: + - a: 1 + - a: 2 + - a: 3 + - key: units + action: push + values: + - b: 4 + - b: 5 # use cloned objects when pushing to array case12: !combine name: push test forEach: - - key: units - action: push - values: !combine - name: "Wave function: Plane wave" - config: - categories: - tier1: qm - tier2: wf - type: pw - tags: - - plane wave - schema: !esse "methods-directory/physical/pw" - - key: units - action: push - values: - - b: 4 - - b: 5 + - key: units + action: push + values: !combine + name: "Wave function: Plane wave" + config: + categories: + tier1: qm + tier2: wf + type: pw + tags: + - plane wave + schema: !esse "methods-directory/physical/pw" + - key: units + action: push + values: + - b: 4 + - b: 5 From d4e2de59de8bece8c1dde79dd7e984c6a1a87482 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Tue, 11 Jul 2023 13:48:53 +0300 Subject: [PATCH 34/38] chore: resolve esse schemas --- src/JSONSchemasInterface.js | 7 +++++++ src/utils/schemas.js | 3 --- src/utils/yaml.js | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index 26276937..7de50a14 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -1,7 +1,10 @@ +import baseSchema from "@exabyte-io/esse.js/schema"; import Ajv from "ajv"; import deref from "json-schema-deref-sync"; import mergeAllOf from "json-schema-merge-allof"; +export const esseSchema = baseSchema; + const schemasCache = new Map(); /** @@ -47,6 +50,10 @@ export class JSONSchemasInterface { * @returns {Object.} resolved JSON schema */ static schemaById(schemaId) { + if (schemasCache.size === 0) { + JSONSchemasInterface.registerGlobalSchema(esseSchema); + } + return schemasCache.get(schemaId); } diff --git a/src/utils/schemas.js b/src/utils/schemas.js index 9149284f..d79f098c 100644 --- a/src/utils/schemas.js +++ b/src/utils/schemas.js @@ -1,12 +1,9 @@ -import globalSchema from "@exabyte-io/esse.js/schema"; import lodash from "lodash"; import { JSONSchemasInterface } from "../JSONSchemasInterface"; export * from "@exabyte-io/esse.js/lib/js/esse/schemaUtils"; -export const esseSchema = globalSchema; - export const schemas = {}; /** diff --git a/src/utils/yaml.js b/src/utils/yaml.js index adc8bf85..6caf9a0b 100644 --- a/src/utils/yaml.js +++ b/src/utils/yaml.js @@ -3,7 +3,7 @@ import yaml from "js-yaml"; import lodash from "lodash"; import path from "path"; -import { JSONSchemasInterface } from "../JSONSchemasInterface"; +import { esseSchema, JSONSchemasInterface } from "../JSONSchemasInterface"; import { safeMakeArray } from "./array"; import { renderTextWithSubstitutes } from "./str"; @@ -155,6 +155,7 @@ export const esseType = new yaml.Type("!esse", { }, construct(data) { try { + JSONSchemasInterface.registerGlobalSchema(esseSchema); const { filePath: schemaId, objPath } = splitReference(data); const schema = JSONSchemasInterface.schemaById(schemaId); if (objPath) { From 63abf8fbfc5863d7c0a120f4924268337703b396 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Tue, 11 Jul 2023 14:06:01 +0300 Subject: [PATCH 35/38] chore: fix tests --- src/JSONSchemasInterface.js | 10 ++++++++++ src/utils/yaml.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/JSONSchemasInterface.js b/src/JSONSchemasInterface.js index 7de50a14..a8b509e7 100644 --- a/src/JSONSchemasInterface.js +++ b/src/JSONSchemasInterface.js @@ -44,6 +44,8 @@ function removeSchemaIdsAfterAllOf(schema, clean = false) { } export class JSONSchemasInterface { + _schema = null; + /** * * @param {string} schemaId id of JSON schema from ESSE @@ -62,6 +64,14 @@ export class JSONSchemasInterface { * @param {Object} - external schema */ static registerGlobalSchema(globalSchema) { + if (JSONSchemasInterface._schema === globalSchema) { + // performance optimization: + // skip resolving as we already did it for the same globalSchema object + return; + } + + JSONSchemasInterface._schema = globalSchema; + const { definitions } = deref(globalSchema); schemasCache.clear(); diff --git a/src/utils/yaml.js b/src/utils/yaml.js index 6caf9a0b..eaa51e3f 100644 --- a/src/utils/yaml.js +++ b/src/utils/yaml.js @@ -161,7 +161,7 @@ export const esseType = new yaml.Type("!esse", { if (objPath) { return lodash.get(schema, objPath); } - return schema; + return schema || data; } catch (e) { return data; } From e1255b7c6aff868a0e4a6b59807047209398f2f4 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 14 Jul 2023 15:47:58 +0300 Subject: [PATCH 36/38] chore: add docstrings --- src/bin/compileTS.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin/compileTS.js b/src/bin/compileTS.js index 18e4e43b..8b742d6e 100644 --- a/src/bin/compileTS.js +++ b/src/bin/compileTS.js @@ -14,6 +14,10 @@ export async function compileTS(globalSchema, savePath) { const preparedDefinitions = Object.entries(globalSchema.definitions).reduce( (newDefinitions, [key, schema]) => { if (schema.allOf && schema.properties) { + /** + * The current version of json-schema-to-typescript ignores properties if there is allOf array in the schema. + * To fix the issue here we are creating a separate schema from properties and add it to the allOf array + */ return [ ...newDefinitions, [ From 743564d5c162937f43f44da1c1da96af8ae52bd9 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 28 Jul 2023 12:55:13 +0300 Subject: [PATCH 37/38] chore: new esse --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 37ce0f52..767fca30 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@babel/preset-react": "7.16.7", "@babel/register": "^7.16.0", "@babel/runtime-corejs3": "7.16.8", - "@exabyte-io/esse.js": "git+https://github.com/Exabyte-io/esse.git#update/SOF-6535", + "@exabyte-io/esse.js": "2023.7.14-0", "ajv": "4.1.7", "crypto-js": "^4.1.1", "js-yaml": "^4.1.0", From ba8ebb84235e4a7ce5a7318bbf1645837dfcee12 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 28 Jul 2023 12:58:19 +0300 Subject: [PATCH 38/38] chore: new esse --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 767fca30..307d0bdd 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@babel/preset-react": "7.16.7", "@babel/register": "^7.16.0", "@babel/runtime-corejs3": "7.16.8", - "@exabyte-io/esse.js": "2023.7.14-0", + "@exabyte-io/esse.js": "2023.7.28-0", "ajv": "4.1.7", "crypto-js": "^4.1.1", "js-yaml": "^4.1.0",