diff --git a/.circleci/config.yml b/.circleci/config.yml index 334cf7e9939..0dcca1d322b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,69 +1,319 @@ version: 2.1 executors: - linux: + pw-focal-development: docker: - - image: cimg/base:stable -orbs: - node: circleci/node@4.5.1 - browser-tools: circleci/browser-tools@1.1.3 -jobs: - test: + - image: mcr.microsoft.com/playwright:v1.39.0-focal + environment: + NODE_ENV: development # Needed to ensure 'dist' folder created and devDependencies installed + PERCY_POSTINSTALL_BROWSER: "true" # Needed to store the percy browser in cache deps + PERCY_LOGLEVEL: "debug" # Enable DEBUG level logging for Percy (Issue: https://github.com/nasa/openmct/issues/5742) + ubuntu: + machine: + image: ubuntu-2204:current + docker_layer_caching: true +parameters: + BUST_CACHE: + description: "Set this with the CircleCI UI Trigger Workflow button (boolean = true) to bust the cache!" + default: false + type: boolean +commands: + build_and_install: + description: "All steps used to build and install. Will use cache if found" parameters: node-version: type: string - browser: - type: string - always-pass: - type: boolean - executor: linux steps: - checkout - - restore_cache: - key: deps-{{ .Branch }}--<< parameters.node-version >>--{{ checksum "package.json" }} + - restore_cache_cmd: + node-version: << parameters.node-version >> - node/install: node-version: << parameters.node-version >> - - node/install-packages: - override-ci-command: npm install - - when: # Just to save time until caching saves the browser bin - condition: - equal: [ "FirefoxESR", <> ] - steps: - - browser-tools/install-firefox: - version: "78.11.0esr" #https://archive.mozilla.org/pub/firefox/releases/ - - when: # Just to save time until caching saves the browser bin + - run: npm install --no-audit --progress=false + restore_cache_cmd: + description: "Custom command for restoring cache with the ability to bust cache. When BUST_CACHE is set to true, jobs will not restore cache" + parameters: + node-version: + type: string + steps: + - when: condition: - equal: [ "ChromeHeadless", <> ] + equal: [false, << pipeline.parameters.BUST_CACHE >>] steps: - - browser-tools/install-chrome: - replace-existing: false + - restore_cache: + key: deps--{{ arch }}--{{ .Branch }}--<< parameters.node-version >>--{{ checksum "package.json" }}-{{ checksum ".circleci/config.yml" }} + save_cache_cmd: + description: "Custom command for saving cache." + parameters: + node-version: + type: string + steps: - save_cache: - key: deps-{{ .Branch }}--<< parameters.node-version >>--{{ checksum "package.json" }} + key: deps--{{ arch }}--{{ .Branch }}--<< parameters.node-version >>--{{ checksum "package.json" }}-{{ checksum ".circleci/config.yml" }} paths: - ~/.npm - - ~/.cache - node_modules - - run: npm run test:coverage -- --browsers=<> || <> + generate_and_store_version_and_filesystem_artifacts: + description: "Track important packages and files" + steps: + - run: | + [[ $EUID -ne 0 ]] && (sudo mkdir -p /tmp/artifacts && sudo chmod 777 /tmp/artifacts) || (mkdir -p /tmp/artifacts && chmod 777 /tmp/artifacts) + printenv NODE_ENV >> /tmp/artifacts/NODE_ENV.txt || true + npm -v >> /tmp/artifacts/npm-version.txt + node -v >> /tmp/artifacts/node-version.txt + ls -latR >> /tmp/artifacts/dir.txt + - store_artifacts: + path: /tmp/artifacts/ + generate_e2e_code_cov_report: + description: "Generate e2e code coverage artifacts and publish to codecov.io. Needed to that we can ignore the exit code status of the npm run test" + parameters: + suite: + type: string + steps: + - run: npm run cov:e2e:report || true + - run: npm run cov:e2e:<>:publish +orbs: + node: circleci/node@5.1.0 + browser-tools: circleci/browser-tools@1.3.0 +jobs: + npm-audit: + parameters: + node-version: + type: string + executor: pw-focal-development + steps: + - build_and_install: + node-version: <> + - run: npm audit --audit-level=low + - generate_and_store_version_and_filesystem_artifacts + lint: + parameters: + node-version: + type: string + executor: pw-focal-development + steps: + - build_and_install: + node-version: <> + - run: npm run lint + - generate_and_store_version_and_filesystem_artifacts + unit-test: + parameters: + node-version: + type: string + executor: pw-focal-development + steps: + - build_and_install: + node-version: <> + - browser-tools/install-chrome: + replace-existing: false + - run: + command: | + mkdir -p dist/reports/tests/ + TESTFILES=$(circleci tests glob "src/**/*Spec.js") + echo "$TESTFILES" | circleci tests run --command="xargs npm run test" --verbose + - run: npm run cov:unit:publish + - save_cache_cmd: + node-version: <> - store_test_results: path: dist/reports/tests/ - store_artifacts: - path: dist/reports/ + path: coverage + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + e2e-test: + parameters: + suite: #stable or full + type: string + executor: pw-focal-development + parallelism: 7 + steps: + - build_and_install: + node-version: lts/hydrogen + - when: #Only install chrome-beta when running the 'full' suite to save $$$ + condition: + equal: ["full", <>] + steps: + - run: npx playwright install chrome-beta + - run: + command: | + mkdir test-results + TESTFILES=$(circleci tests glob "e2e/**/*.spec.js") + echo "$TESTFILES" | circleci tests run --command="xargs npm run test:e2e:<>" --verbose --split-by=timings + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_e2e_code_cov_report: + suite: <> + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: coverage + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + e2e-mobile: + executor: pw-focal-development + steps: + - build_and_install: + node-version: lts/hydrogen + - run: npm run test:e2e:mobile + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_e2e_code_cov_report: + suite: full + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: coverage + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + e2e-couchdb: + executor: ubuntu + steps: + - build_and_install: + node-version: lts/hydrogen + - run: npx playwright@1.39.0 install #Necessary for bare ubuntu machine + - run: | + export $(cat src/plugins/persistence/couch/.env.ci | xargs) + docker-compose -f src/plugins/persistence/couch/couchdb-compose.yaml up --detach + sleep 3 + bash src/plugins/persistence/couch/setup-couchdb.sh + - run: sh src/plugins/persistence/couch/replace-localstorage-with-couchdb-indexhtml.sh #Replace LocalStorage Plugin with CouchDB + - run: npm run test:e2e:couchdb + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_e2e_code_cov_report: + suite: full #add to full suite + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: coverage + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + mem-test: + executor: pw-focal-development + steps: + - build_and_install: + node-version: lts/hydrogen + - run: npm run test:perf:memory + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + perf-test: + executor: pw-focal-development + steps: + - build_and_install: + node-version: lts/hydrogen + - run: npm run test:perf:localhost + - run: npm run test:perf:contract + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always run codecov reports regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + visual-a11y-tests: + parameters: + suite: + type: string # ci or full + executor: pw-focal-development + steps: + - build_and_install: + node-version: lts/hydrogen + - run: npm run test:e2e:visual:<> + - store_test_results: + path: test-results/results.xml + - store_artifacts: + path: test-results + - store_artifacts: + path: html-test-results + - when: + condition: + equal: [42, 42] # Always generate version artifacts regardless of test failure https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957/2 + steps: + - generate_and_store_version_and_filesystem_artifacts + workflows: - matrix-tests: + overall-circleci-commit-status: #These jobs run on every commit jobs: - - test: - name: node10-chrome - node-version: lts/dubnium - browser: ChromeHeadless - always-pass: false - - test: - name: node12-firefoxESR - node-version: lts/erbium - browser: FirefoxESR - always-pass: true - - test: - name: node14-chrome - node-version: lts/fermium - browser: ChromeHeadless - always-pass: true - + - lint: + name: node20-lint + node-version: lts/iron + - unit-test: + name: node18-chrome + node-version: lts/hydrogen + - e2e-test: + name: e2e-stable + suite: stable + - e2e-mobile + - visual-a11y-tests: + name: visual-a11y-test-ci + suite: ci + the-nightly: #These jobs do not run on PRs, but against master at night + jobs: + - unit-test: + name: node20-chrome-nightly + node-version: lts/iron + - unit-test: + name: node18-chrome + node-version: lts/hydrogen + - npm-audit: + node-version: lts/hydrogen + - e2e-test: + name: e2e-full-nightly + suite: full + - e2e-mobile + - perf-test + - mem-test + - visual-a11y-tests: + name: visual-a11y-test-nightly + suite: full + - e2e-couchdb + triggers: + - schedule: + cron: "0 0 * * *" + filters: + branches: + only: + - master diff --git a/.cspell.json b/.cspell.json new file mode 100644 index 00000000000..9afde5db7cd --- /dev/null +++ b/.cspell.json @@ -0,0 +1,513 @@ +{ + "version": "0.2", + "language": "en,en-us", + "words": [ + "gress", + "doctoc", + "minmax", + "openmct", + "datasources", + "recieved", + "evalute", + "Sinewave", + "deregistration", + "unregisters", + "configutation", + "configuation", + "codecov", + "carryforward", + "Chacon", + "Straub", + "OWASP", + "Testathon", + "exploratorily", + "Testathons", + "testathon", + "npmjs", + "publishj", + "treeitem", + "timespan", + "Timespan", + "spinbutton", + "popout", + "textbox", + "tablist", + "Telem", + "codecoverage", + "browserless", + "networkidle", + "nums", + "mgmt", + "faultname", + "gantt", + "sharded", + "perfromance", + "MMOC", + "codegen", + "Unfortuantely", + "viewports", + "updatesnapshots", + "excercised", + "Circel", + "browsercontexts", + "miminum", + "testcase", + "testsuite", + "domcontentloaded", + "Tracefile", + "lcov", + "linecov", + "Browserless", + "webserver", + "yamcs", + "quickstart", + "subobject", + "autosize", + "Horz", + "vehicula", + "Praesent", + "pharetra", + "Duis", + "eget", + "arcu", + "elementum", + "mauris", + "Donec", + "nunc", + "quis", + "Proin", + "elit", + "Nunc", + "Aenean", + "mollis", + "hendrerit", + "Vestibulum", + "placerat", + "velit", + "augue", + "Quisque", + "mattis", + "lectus", + "rutrum", + "Fusce", + "tincidunt", + "nibh", + "blandit", + "urna", + "Nullam", + "congue", + "enim", + "Morbi", + "bibendum", + "Vivamus", + "imperdiet", + "Pellentesque", + "cursus", + "Aliquam", + "orci", + "Suspendisse", + "amet", + "justo", + "Etiam", + "vestibulum", + "ullamcorper", + "Cras", + "aliquet", + "Mauris", + "Nulla", + "scelerisque", + "viverra", + "metus", + "condimentum", + "varius", + "nulla", + "sapien", + "Curabitur", + "tristique", + "Nonsectetur", + "convallis", + "accumsan", + "lacus", + "posuere", + "turpis", + "egestas", + "feugiat", + "tortor", + "faucibus", + "euismod", + "pratices", + "pathing", + "pases", + "testcases", + "Noneditable", + "listitem", + "Gantt", + "timelist", + "timestrip", + "networkevents", + "fetchpriority", + "persistable", + "Persistable", + "persistability", + "Persistability", + "testdata", + "Testdata", + "metdata", + "timeconductor", + "contenteditable", + "autoscale", + "Autoscale", + "prepan", + "sinewave", + "cyanish", + "driv", + "searchbox", + "datetime", + "timeframe", + "recents", + "recentobjects", + "gsearch", + "Disp", + "Cloc", + "noselect", + "requestfailed", + "viewlarge", + "Imageurl", + "thumbstrip", + "checkmark", + "Unshelve", + "autosized", + "chacskaylo", + "numberfield", + "OPENMCT", + "Autoflow", + "Timelist", + "faultmanagement", + "GEOSPATIAL", + "geospatial", + "plotspatial", + "annnotation", + "keystrings", + "undelete", + "sometag", + "containee", + "composability", + "mutables", + "Mutables", + "composee", + "handleoutsideclick", + "Datetime", + "Perc", + "autodismiss", + "filetree", + "deeptailor", + "keystring", + "reindex", + "unlisten", + "symbolsfont", + "ellipsize", + "dismissable", + "TIMESYSTEM", + "Metadatas", + "stalenes", + "receieves", + "unsub", + "callbacktwo", + "unsubscribetwo", + "telem", + "Telemetery", + "unemitted", + "granually", + "timesystem", + "metadatas", + "iteratees", + "metadatum", + "printj", + "sprintf", + "unlisteners", + "amts", + "reregistered", + "hudsonfoo", + "onclone", + "autoflow", + "xdescribe", + "mockmct", + "Autoflowed", + "plotly", + "relayout", + "Plotly", + "Yaxis", + "showlegend", + "textposition", + "xaxis", + "automargin", + "fixedrange", + "yaxis", + "Axistype", + "showline", + "bglayer", + "autorange", + "hoverinfo", + "dotful", + "Dotful", + "cartesianlayer", + "scatterlayer", + "textfont", + "ampm", + "cdef", + "horz", + "STYLEABLE", + "styleable", + "afff", + "shdw", + "braintree", + "vals", + "Subobject", + "Shdw", + "Movebar", + "inspectable", + "Stringformatter", + "sclk", + "Objectpath", + "Keystring", + "duplicatable", + "composees", + "Composees", + "Composee", + "callthrough", + "objectpath", + "createable", + "noneditable", + "Classname", + "classname", + "selectedfaults", + "accum", + "newpersisted", + "Metadatum", + "MCWS", + "YAMCS", + "frameid", + "containerid", + "mmgis", + "PERC", + "curval", + "viewbox", + "mutablegauge", + "Flatbush", + "flatbush", + "Indicies", + "Marqueed", + "NSEW", + "nsew", + "vrover", + "gimbled", + "Pannable", + "unsynced", + "Unsynced", + "pannable", + "autoscroll", + "TIMESTRIP", + "TWENTYFOUR", + "FULLSIZE", + "intialize", + "Timestrip", + "spyon", + "Unlistener", + "multipane", + "DATESTRING", + "akhenry", + "Niklas", + "Hertzen", + "Kash", + "Nouroozi", + "Bostock", + "BOSTOCK", + "Arnout", + "Kazemier", + "Karolis", + "Narkevicius", + "Ashkenas", + "Madhavan", + "Iskren", + "Ivov", + "Chernev", + "Borshchov", + "painterro", + "sheetjs", + "Yuxi", + "ACITON", + "localstorage", + "Linkto", + "Painterro", + "Editability", + "filteredsnapshots", + "Fromimage", + "muliple", + "notebookstorage", + "Andpage", + "pixelize", + "Quickstart", + "indexhtml", + "youradminpassword", + "chttpd", + "sourcefiles", + "USERPASS", + "XPUT", + "adipiscing", + "eiusmod", + "tempor", + "incididunt", + "labore", + "dolore", + "aliqua", + "perspiciatis", + "iteree", + "submodels", + "symlog", + "Plottable", + "antisymlog", + "docstrings", + "webglcontextlost", + "gridlines", + "Xaxis", + "Crosshairs", + "telemetrylimit", + "xscale", + "yscale", + "untracks", + "swatched", + "NULLVALUE", + "unobserver", + "unsubscriber", + "drap", + "Averager", + "averager", + "movecolumnfromindex", + "callout", + "Konqueror", + "unmark", + "hitarea", + "Hitarea", + "Unmark", + "controlbar", + "reactified", + "perc", + "DHMS", + "timespans", + "timeframes", + "Timesystems", + "Hilite", + "datetimes", + "momentified", + "ucontents", + "TIMELIST", + "Timeframe", + "Guirk", + "resizeable", + "iframing", + "Btns", + "Ctrls", + "Chakra", + "Petch", + "propor", + "phoneandtablet", + "desktopandtablet", + "Imgs", + "UNICODES", + "datatable", + "csvg", + "cpath", + "cellipse", + "xlink", + "cstyle", + "bfill", + "ctitle", + "eicon", + "interactability", + "AFFORDANCES", + "affordance", + "scrollcontainer", + "Icomoon", + "icomoon", + "configurability", + "btns", + "AUTOFLOW", + "DATETIME", + "infobubble", + "thumbsbubble", + "codehilite", + "vscroll", + "bgsize", + "togglebutton", + "Hacskaylo", + "noie", + "fullscreen", + "horiz", + "menubutton", + "SNAPSHOTTING", + "snapshotting", + "PAINTERRO", + "ptro", + "PLOTLY", + "gridlayer", + "xtick", + "ytick", + "subobjects", + "Ucontents", + "Userand", + "Userbefore", + "brdr", + "pushs", + "ALPH", + "Recents", + "Qbert", + "Infobubble", + "haslink", + "VPID", + "vpid", + "updatedtest", + "KHTML", + "Chromezilla", + "Safarifox", + "deregistering", + "hundredtized", + "dhms", + "unthrottled", + "Codecov", + "dont", + "mediump", + "sinonjs", + "generatedata", + "grandsearch", + "websockets", + "swgs", + "memlab", + "devmode", + "blockquote", + "blockquotes", + "Blockquote", + "Blockquotes", + "oger", + "lcovonly", + "gcov", + "WCAG", + "stackedplot", + "Andale", + "unnormalized", + "checksnapshots", + "specced", + "composables", + "countup" + ], + "dictionaries": ["npm", "softwareTerms", "node", "html", "css", "bash", "en_US", "en-gb", "misc"], + "ignorePaths": [ + "package.json", + "dist/**", + "package-lock.json", + "node_modules", + "coverage", + "*.log", + "html-test-results", + "test-results" + ] +} diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 00000000000..e29c5879252 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,181 @@ +const LEGACY_FILES = ['example/**']; +module.exports = { + env: { + browser: true, + es6: true, + jasmine: true, + amd: true + }, + globals: { + _: 'readonly' + }, + plugins: ['prettier', 'unicorn', 'simple-import-sort'], + extends: [ + 'eslint:recommended', + 'plugin:compat/recommended', + 'plugin:vue/vue3-recommended', + 'plugin:you-dont-need-lodash-underscore/compatible', + 'plugin:prettier/recommended', + 'plugin:no-unsanitized/DOM' + ], + parser: 'vue-eslint-parser', + parserOptions: { + parser: '@babel/eslint-parser', + requireConfigFile: false, + allowImportExportEverywhere: true, + ecmaVersion: 2015, + ecmaFeatures: { + impliedStrict: true + } + }, + rules: { + 'simple-import-sort/imports': 'warn', + 'simple-import-sort/exports': 'warn', + 'vue/no-deprecated-dollar-listeners-api': 'warn', + 'vue/no-deprecated-events-api': 'warn', + 'vue/no-v-for-template-key': 'off', + 'vue/no-v-for-template-key-on-child': 'error', + 'prettier/prettier': 'error', + 'you-dont-need-lodash-underscore/omit': 'off', + 'you-dont-need-lodash-underscore/throttle': 'off', + 'you-dont-need-lodash-underscore/flatten': 'off', + 'you-dont-need-lodash-underscore/get': 'off', + 'no-bitwise': 'error', + curly: 'error', + eqeqeq: 'error', + 'guard-for-in': 'error', + 'no-extend-native': 'error', + 'no-inner-declarations': 'off', + 'no-use-before-define': ['error', 'nofunc'], + 'no-caller': 'error', + 'no-irregular-whitespace': 'error', + 'no-new': 'error', + 'no-shadow': 'error', + 'no-undef': 'error', + 'no-unused-vars': [ + 'error', + { + vars: 'all', + args: 'none' + } + ], + 'no-console': 'off', + 'new-cap': [ + 'error', + { + capIsNew: false, + properties: false + } + ], + 'dot-notation': 'error', + + // https://eslint.org/docs/rules/no-case-declarations + 'no-case-declarations': 'error', + // https://eslint.org/docs/rules/max-classes-per-file + 'max-classes-per-file': ['error', 1], + // https://eslint.org/docs/rules/no-eq-null + 'no-eq-null': 'error', + // https://eslint.org/docs/rules/no-eval + 'no-eval': 'error', + // https://eslint.org/docs/rules/no-implicit-globals + 'no-implicit-globals': 'error', + // https://eslint.org/docs/rules/no-implied-eval + 'no-implied-eval': 'error', + // https://eslint.org/docs/rules/no-lone-blocks + 'no-lone-blocks': 'error', + // https://eslint.org/docs/rules/no-loop-func + 'no-loop-func': 'error', + // https://eslint.org/docs/rules/no-new-func + 'no-new-func': 'error', + // https://eslint.org/docs/rules/no-new-wrappers + 'no-new-wrappers': 'error', + // https://eslint.org/docs/rules/no-octal-escape + 'no-octal-escape': 'error', + // https://eslint.org/docs/rules/no-proto + 'no-proto': 'error', + // https://eslint.org/docs/rules/no-return-await + 'no-return-await': 'error', + // https://eslint.org/docs/rules/no-script-url + 'no-script-url': 'error', + // https://eslint.org/docs/rules/no-self-compare + 'no-self-compare': 'error', + // https://eslint.org/docs/rules/no-sequences + 'no-sequences': 'error', + // https://eslint.org/docs/rules/no-unmodified-loop-condition + 'no-unmodified-loop-condition': 'error', + // https://eslint.org/docs/rules/no-useless-call + 'no-useless-call': 'error', + // https://eslint.org/docs/rules/no-nested-ternary + 'no-nested-ternary': 'error', + // https://eslint.org/docs/rules/no-useless-computed-key + 'no-useless-computed-key': 'error', + // https://eslint.org/docs/rules/no-var + 'no-var': 'error', + // https://eslint.org/docs/rules/one-var + 'one-var': ['error', 'never'], + // https://eslint.org/docs/rules/default-case-last + 'default-case-last': 'error', + // https://eslint.org/docs/rules/default-param-last + 'default-param-last': 'error', + // https://eslint.org/docs/rules/grouped-accessor-pairs + 'grouped-accessor-pairs': 'error', + // https://eslint.org/docs/rules/no-constructor-return + 'no-constructor-return': 'error', + // https://eslint.org/docs/rules/array-callback-return + 'array-callback-return': 'error', + // https://eslint.org/docs/rules/no-invalid-this + 'no-invalid-this': 'error', // Believe this one actually surfaces some bugs + // https://eslint.org/docs/rules/func-style + 'func-style': ['error', 'declaration'], + // https://eslint.org/docs/rules/no-unused-expressions + 'no-unused-expressions': 'error', + // https://eslint.org/docs/rules/no-useless-concat + 'no-useless-concat': 'error', + // https://eslint.org/docs/rules/radix + radix: 'error', + // https://eslint.org/docs/rules/require-await + 'require-await': 'error', + // https://eslint.org/docs/rules/no-alert + 'no-alert': 'error', + // https://eslint.org/docs/rules/no-useless-constructor + 'no-useless-constructor': 'error', + // https://eslint.org/docs/rules/no-duplicate-imports + 'no-duplicate-imports': 'error', + + // https://eslint.org/docs/rules/no-implicit-coercion + 'no-implicit-coercion': 'error', + //https://eslint.org/docs/rules/no-unneeded-ternary + 'no-unneeded-ternary': 'error', + 'unicorn/filename-case': [ + 'error', + { + cases: { + pascalCase: true + }, + ignore: ['^.*\\.js$'] + } + ], + 'vue/first-attribute-linebreak': 'error', + 'vue/multiline-html-element-content-newline': 'off', + 'vue/singleline-html-element-content-newline': 'off', + 'vue/no-mutating-props': 'off' // TODO: Remove this rule and fix resulting errors + }, + overrides: [ + { + files: LEGACY_FILES, + rules: { + 'no-unused-vars': [ + 'error', + { + vars: 'all', + args: 'none', + varsIgnorePattern: 'controller' + } + ], + 'no-nested-ternary': 'off', + 'no-var': 'off', + 'one-var': 'off' + } + } + ] +}; diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 03a5b1fefe0..00000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,270 +0,0 @@ -const LEGACY_FILES = ["platform/**", "example/**"]; -module.exports = { - "env": { - "browser": true, - "es6": true, - "jasmine": true, - "amd": true - }, - "globals": { - "_": "readonly" - }, - "extends": [ - "eslint:recommended", - "plugin:vue/recommended", - "plugin:you-dont-need-lodash-underscore/compatible" - ], - "parser": "vue-eslint-parser", - "parserOptions": { - "parser": "babel-eslint", - "allowImportExportEverywhere": true, - "ecmaVersion": 2015, - "ecmaFeatures": { - "impliedStrict": true - } - }, - "rules": { - "you-dont-need-lodash-underscore/omit": "off", - "you-dont-need-lodash-underscore/throttle": "off", - "you-dont-need-lodash-underscore/flatten": "off", - "no-bitwise": "error", - "curly": "error", - "eqeqeq": "error", - "guard-for-in": "error", - "no-extend-native": "error", - "no-inner-declarations": "off", - "no-use-before-define": ["error", "nofunc"], - "no-caller": "error", - "no-sequences": "error", - "no-irregular-whitespace": "error", - "no-new": "error", - "no-shadow": "error", - "no-undef": "error", - "no-unused-vars": [ - "error", - { - "vars": "all", - "args": "none" - } - ], - "no-console": "off", - "no-trailing-spaces": "error", - "space-before-function-paren": [ - "error", - { - "anonymous": "always", - "asyncArrow": "always", - "named": "never" - } - ], - "array-bracket-spacing": "error", - "space-in-parens": "error", - "space-before-blocks": "error", - "comma-dangle": "error", - "eol-last": "error", - "new-cap": [ - "error", - { - "capIsNew": false, - "properties": false - } - ], - "dot-notation": "error", - "indent": ["error", 4], - - // https://eslint.org/docs/rules/no-case-declarations - "no-case-declarations": "error", - // https://eslint.org/docs/rules/max-classes-per-file - "max-classes-per-file": ["error", 1], - // https://eslint.org/docs/rules/no-eq-null - "no-eq-null": "error", - // https://eslint.org/docs/rules/no-eval - "no-eval": "error", - // https://eslint.org/docs/rules/no-floating-decimal - "no-floating-decimal": "error", - // https://eslint.org/docs/rules/no-implicit-globals - "no-implicit-globals": "error", - // https://eslint.org/docs/rules/no-implied-eval - "no-implied-eval": "error", - // https://eslint.org/docs/rules/no-lone-blocks - "no-lone-blocks": "error", - // https://eslint.org/docs/rules/no-loop-func - "no-loop-func": "error", - // https://eslint.org/docs/rules/no-new-func - "no-new-func": "error", - // https://eslint.org/docs/rules/no-new-wrappers - "no-new-wrappers": "error", - // https://eslint.org/docs/rules/no-octal-escape - "no-octal-escape": "error", - // https://eslint.org/docs/rules/no-proto - "no-proto": "error", - // https://eslint.org/docs/rules/no-return-await - "no-return-await": "error", - // https://eslint.org/docs/rules/no-script-url - "no-script-url": "error", - // https://eslint.org/docs/rules/no-self-compare - "no-self-compare": "error", - // https://eslint.org/docs/rules/no-sequences - "no-sequences": "error", - // https://eslint.org/docs/rules/no-unmodified-loop-condition - "no-unmodified-loop-condition": "error", - // https://eslint.org/docs/rules/no-useless-call - "no-useless-call": "error", - // https://eslint.org/docs/rules/wrap-iife - "wrap-iife": "error", - // https://eslint.org/docs/rules/no-nested-ternary - "no-nested-ternary": "error", - // https://eslint.org/docs/rules/switch-colon-spacing - "switch-colon-spacing": "error", - // https://eslint.org/docs/rules/no-useless-computed-key - "no-useless-computed-key": "error", - // https://eslint.org/docs/rules/rest-spread-spacing - "rest-spread-spacing": ["error"], - // https://eslint.org/docs/rules/no-var - "no-var": "error", - // https://eslint.org/docs/rules/one-var - "one-var": ["error", "never"], - // https://eslint.org/docs/rules/default-case-last - "default-case-last": "error", - // https://eslint.org/docs/rules/default-param-last - "default-param-last": "error", - // https://eslint.org/docs/rules/grouped-accessor-pairs - "grouped-accessor-pairs": "error", - // https://eslint.org/docs/rules/no-constructor-return - "no-constructor-return": "error", - // https://eslint.org/docs/rules/array-callback-return - "array-callback-return": "error", - // https://eslint.org/docs/rules/no-invalid-this - "no-invalid-this": "error", // Believe this one actually surfaces some bugs - // https://eslint.org/docs/rules/func-style - "func-style": ["error", "declaration"], - // https://eslint.org/docs/rules/no-unused-expressions - "no-unused-expressions": "error", - // https://eslint.org/docs/rules/no-useless-concat - "no-useless-concat": "error", - // https://eslint.org/docs/rules/radix - "radix": "error", - // https://eslint.org/docs/rules/require-await - "require-await": "error", - // https://eslint.org/docs/rules/no-alert - "no-alert": "error", - // https://eslint.org/docs/rules/no-useless-constructor - "no-useless-constructor": "error", - // https://eslint.org/docs/rules/no-duplicate-imports - "no-duplicate-imports": "error", - - // https://eslint.org/docs/rules/no-implicit-coercion - "no-implicit-coercion": "error", - //https://eslint.org/docs/rules/no-unneeded-ternary - "no-unneeded-ternary": "error", - // https://eslint.org/docs/rules/semi - "semi": ["error", "always"], - // https://eslint.org/docs/rules/no-multi-spaces - "no-multi-spaces": "error", - // https://eslint.org/docs/rules/key-spacing - "key-spacing": ["error", { - "afterColon": true - }], - // https://eslint.org/docs/rules/keyword-spacing - "keyword-spacing": ["error", { - "before": true, - "after": true - }], - // https://eslint.org/docs/rules/comma-spacing - // Also requires one line code fix - "comma-spacing": ["error", { - "after": true - }], - //https://eslint.org/docs/rules/no-whitespace-before-property - "no-whitespace-before-property": "error", - // https://eslint.org/docs/rules/object-curly-newline - "object-curly-newline": ["error", { - "consistent": true, - "multiline": true - }], - // https://eslint.org/docs/rules/object-property-newline - "object-property-newline": "error", - // https://eslint.org/docs/rules/brace-style - "brace-style": "error", - // https://eslint.org/docs/rules/no-multiple-empty-lines - "no-multiple-empty-lines": ["error", {"max": 1}], - // https://eslint.org/docs/rules/operator-linebreak - "operator-linebreak": ["error", "before", {"overrides": {"=": "after"}}], - // https://eslint.org/docs/rules/padding-line-between-statements - "padding-line-between-statements": ["error", { - "blankLine": "always", - "prev": "multiline-block-like", - "next": "*" - }, { - "blankLine": "always", - "prev": "*", - "next": "return" - }], - // https://eslint.org/docs/rules/space-infix-ops - "space-infix-ops": "error", - // https://eslint.org/docs/rules/space-unary-ops - "space-unary-ops": ["error", { - "words": true, - "nonwords": false - }], - // https://eslint.org/docs/rules/arrow-spacing - "arrow-spacing": "error", - // https://eslint.org/docs/rules/semi-spacing - "semi-spacing": ["error", { - "before": false, - "after": true - }], - - "vue/html-indent": [ - "error", - 4, - { - "attribute": 1, - "baseIndent": 0, - "closeBracket": 0, - "alignAttributesVertically": true, - "ignores": [] - } - ], - "vue/html-self-closing": ["error", - { - "html": { - "void": "never", - "normal": "never", - "component": "always" - }, - "svg": "always", - "math": "always" - } - ], - "vue/max-attributes-per-line": ["error", { - "singleline": 1, - "multiline": { - "max": 1, - "allowFirstLine": true - } - }], - "vue/multiline-html-element-content-newline": "off", - "vue/singleline-html-element-content-newline": "off", - "vue/no-mutating-props": "off" - - }, - "overrides": [ - { - "files": LEGACY_FILES, - "rules": { - "no-unused-vars": [ - "warn", - { - "vars": "all", - "args": "none", - "varsIgnorePattern": "controller" - } - ], - "no-nested-ternary": "off", - "no-var": "off", - "one-var": "off" - } - } - ] -}; diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000000..839df6c0f94 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,16 @@ +# git-blame ignored revisions +# To configure, run: +# git config blame.ignoreRevsFile .git-blame-ignore-revs +# Requires Git > 2.23 +# See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt + +# vue-eslint update 2019 +14a0f84c1bcd56886d7c9e4e6afa8f7d292734e5 +# eslint changes 2022 +d80b6923541704ab925abf0047cbbc58735c27e2 +# Copyright year update 2022 +4a9744e916d24122a81092f6b7950054048ba860 +# Copyright year update 2023 +8040b275fcf2ba71b42cd72d4daa64bb25c19c2d +# Apply `prettier` formatting +caa7bc6faebc204f67aedae3e35fb0d0d3ce27a7 diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 1bb9855519e..2fd6b809176 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -17,15 +17,6 @@ assignees: '' #### Expected vs Current Behavior -#### Impact Check List - - -- [ ] Data loss or misrepresented data? -- [ ] Regression? Did this used to work or has it always been broken? -- [ ] Is there a workaround available? -- [ ] Does this impact a critical component? -- [ ] Is this just a visual bug? - #### Steps to Reproduce @@ -35,10 +26,22 @@ assignees: '' 4. #### Environment + * Open MCT Version: * Deployment Type: * OS: * Browser: +#### Impact Check List + +- [ ] Data loss or misrepresented data? +- [ ] Regression? Did this used to work or has it always been broken? +- [ ] Is there a workaround available? +- [ ] Does this impact a critical component? +- [ ] Is this just a visual bug with no functional impact? +- [ ] Does this block the execution of e2e tests? +- [ ] Does this have an impact on Performance? + #### Additional Information diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 8113ed2ebcc..433f68345d3 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,4 +2,4 @@ blank_issues_enabled: true contact_links: - name: Discussions url: https://github.com/nasa/openmct/discussions - about: Got a question? + about: Have a question about the project? diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 4a8ee014b19..00000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,23 +0,0 @@ - - - ---- -name: Feature Request -about: Suggest an idea for this project - ---- - - - -**Is your feature request related to a problem? Please describe.** - - -**Describe the solution you'd like** - - -**Describe alternatives you've considered** - diff --git a/.github/ISSUE_TEMPLATE/maintenance-type.md b/.github/ISSUE_TEMPLATE/maintenance-type.md new file mode 100644 index 00000000000..3f15ca292ea --- /dev/null +++ b/.github/ISSUE_TEMPLATE/maintenance-type.md @@ -0,0 +1,11 @@ +--- +name: Maintenance +about: Add, update or remove documentation, tests, or dependencies. +title: '' +labels: type:maintenance +assignees: '' + +--- + +#### Summary + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 3dc93e2b3f9..34ab10e6a93 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,12 +1,29 @@ + +Closes + +### Describe your changes: + + ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing document](https://github.com/nasa/openmct/blob/master/CONTRIBUTING.md)? * [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/nasa/openmct/pulls) for the same update/change? +* [ ] Is this a [notable change](../docs/src/process/release.md) that will require a special callout in the release notes? For example, will this break compatibility with existing APIs or projects that consume these plugins? ### Author Checklist * [ ] Changes address original issue? -* [ ] Unit tests included and/or updated with changes? -* [ ] Command line build passes? +* [ ] Tests included and/or updated with changes? * [ ] Has this been smoke tested? -* [ ] Testing instructions included in associated issue? +* [ ] Have you associated this PR with a `type:` label? Note: this is not necessarily the same as the original issue. +* [ ] Have you associated a milestone with this PR? Note: leave blank if unsure. +* [ ] Is this a breaking change to be called out in the release notes? +* [ ] Testing instructions included in associated issue OR is this a dependency/testcase change? + +### Reviewer Checklist + +* [ ] Changes appear to address issue? +* [ ] Reviewer has tested changes by following the provided instructions? +* [ ] Changes appear not to be breaking changes? +* [ ] Appropriate automated tests included? +* [ ] Code style and in-line documentation are appropriate? diff --git a/.github/codeql/codeql-config.yml b/.github/codeql/codeql-config.yml new file mode 100644 index 00000000000..98f45f4da86 --- /dev/null +++ b/.github/codeql/codeql-config.yml @@ -0,0 +1 @@ +name: 'Custom CodeQL config' diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000000..d963da512ce --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,42 @@ +version: 2 +updates: + - package-ecosystem: 'npm' + directory: '/' + schedule: + interval: 'weekly' + open-pull-requests-limit: 10 + rebase-strategy: 'disabled' + labels: + - 'pr:daveit' + - 'pr:e2e' + - 'type:maintenance' + - 'dependencies' + - 'pr:platform' + ignore: + #We have to source the playwright container which is not detected by Dependabot + - dependency-name: '@playwright/test' + - dependency-name: 'playwright-core' + #Lots of noise in these type patch releases. + - dependency-name: '@babel/eslint-parser' + update-types: ['version-update:semver-patch'] + - dependency-name: 'eslint-plugin-vue' + update-types: ['version-update:semver-patch'] + - dependency-name: 'babel-loader' + update-types: ['version-update:semver-patch'] + - dependency-name: 'sinon' + update-types: ['version-update:semver-patch'] + - dependency-name: 'moment-timezone' + update-types: ['version-update:semver-patch'] + - dependency-name: '@types/lodash' + update-types: ['version-update:semver-patch'] + - dependency-name: 'marked' + update-types: ['version-update:semver-patch'] + - package-ecosystem: 'github-actions' + directory: '/' + schedule: + interval: 'daily' + rebase-strategy: 'disabled' + labels: + - 'pr:daveit' + - 'type:maintenance' + - 'dependencies' diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 00000000000..cbf00175036 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,26 @@ +changelog: + categories: + - title: 💥 Notable Changes + labels: + - notable_change + - title: 🏕 Features + labels: + - type:feature + - title: 🎉 Enhancements + labels: + - type:enhancement + exclude: + labels: + - type:feature + - title: 🔧 Maintenance + labels: + - type:maintenance + - title: ⚡ Performance + labels: + - performance + - title: 👒 Dependencies + labels: + - dependencies + - title: 🐛 Bug Fixes + labels: + - "*" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000000..d3ca94594a9 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,44 @@ +name: 'CodeQL' + +on: + push: + branches: [master, 'release/*'] + pull_request: + branches: [master, 'release/*'] + paths-ignore: + - '**/*Spec.js' + - '**/*.md' + - '**/*.txt' + - '**/*.yml' + - '**/*.yaml' + - '**/*.spec.js' + - '**/*.config.js' + schedule: + - cron: '28 21 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + config-file: ./.github/codeql/codeql-config.yml + languages: javascript + queries: security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/e2e-couchdb.yml b/.github/workflows/e2e-couchdb.yml new file mode 100644 index 00000000000..5333ee82f14 --- /dev/null +++ b/.github/workflows/e2e-couchdb.yml @@ -0,0 +1,88 @@ +name: 'e2e-couchdb' +on: + push: + branches: master + workflow_dispatch: + pull_request: + types: + - labeled + - opened + schedule: + - cron: '0 0 * * *' +jobs: + e2e-couchdb: + if: contains(github.event.pull_request.labels.*.name, 'pr:e2e:couchdb') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'opened' + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 'lts/hydrogen' + + - name: Cache NPM dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - run: npm install --cache ~/.npm --no-audit --progress=false + + - name: Login to DockerHub + uses: docker/login-action@v3 + continue-on-error: true + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - run: npx playwright@1.39.0 install + + - name: Start CouchDB Docker Container and Init with Setup Scripts + run: | + export $(cat src/plugins/persistence/couch/.env.ci | xargs) + docker-compose -f src/plugins/persistence/couch/couchdb-compose.yaml up --detach + sleep 3 + bash src/plugins/persistence/couch/setup-couchdb.sh + bash src/plugins/persistence/couch/replace-localstorage-with-couchdb-indexhtml.sh + + - name: Run CouchDB Tests + env: + COMMIT_INFO_SHA: ${{github.event.pull_request.head.sha }} + run: npm run test:e2e:couchdb + + - name: Publish Results to Codecov.io + env: + SUPER_SECRET: ${{ secrets.CODECOV_TOKEN }} + run: npm run cov:e2e:full:publish + + - name: Archive test results + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + path: test-results + + - name: Archive html test results + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + path: html-test-results + + - name: Remove pr:e2e:couchdb label (if present) + if: always() + uses: actions/github-script@v6 + with: + script: | + const { owner, repo, number } = context.issue; + const labelToRemove = 'pr:e2e:couchdb'; + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number: number, + name: labelToRemove + }); + } catch (error) { + core.warning(`Failed to remove ' + labelToRemove + ' label: ${error.message}`); + } diff --git a/.github/workflows/e2e-flakefinder.yml b/.github/workflows/e2e-flakefinder.yml new file mode 100644 index 00000000000..de9095fb63c --- /dev/null +++ b/.github/workflows/e2e-flakefinder.yml @@ -0,0 +1,61 @@ +name: 'pr:e2e:flakefinder' + +on: +# push: +# branches: master + workflow_dispatch: +# pull_request: +# types: +# - labeled +# - opened +# schedule: +# - cron: '0 0 * * *' + +jobs: + e2e-flakefinder: + if: contains(github.event.pull_request.labels.*.name, 'pr:e2e:flakefinder') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event.action == 'opened' + runs-on: ubuntu-latest + timeout-minutes: 120 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 'lts/hydrogen' + + - name: Cache NPM dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - run: npx playwright@1.39.0 install + - run: npm install --cache ~/.npm --no-audit --progress=false + + - name: Run E2E Tests (Repeated 10 Times) + run: npm run test:e2e:stable -- --retries=0 --repeat-each=10 --max-failures=50 + + - name: Archive test results + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + path: test-results + + - name: Remove pr:e2e:flakefinder label (if present) + if: always() + uses: actions/github-script@v6 + with: + script: | + const { owner, repo, number } = context.issue; + const labelToRemove = 'pr:e2e:flakefinder'; + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number: number, + name: labelToRemove + }); + } catch (error) { + core.warning(`Failed to remove ' + labelToRemove + ' label: ${error.message}`); + } diff --git a/.github/workflows/e2e-perf.yml b/.github/workflows/e2e-perf.yml new file mode 100644 index 00000000000..2255bde61b4 --- /dev/null +++ b/.github/workflows/e2e-perf.yml @@ -0,0 +1,58 @@ +name: 'e2e-perf' +on: + push: + branches: master + workflow_dispatch: + pull_request: + types: + - labeled + - opened + schedule: + - cron: '0 0 * * *' +jobs: + e2e-full: + if: contains(github.event.pull_request.labels.*.name, 'pr:e2e:perf') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 'lts/hydrogen' + + - name: Cache NPM dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - run: npx playwright@1.39.0 install + - run: npm install --cache ~/.npm --no-audit --progress=false + - run: npm run test:perf:localhost + - run: npm run test:perf:contract + - run: npm run test:perf:memory + - name: Archive test results + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + path: test-results + + - name: Remove pr:e2e:perf label (if present) + if: always() + uses: actions/github-script@v6 + with: + script: | + const { owner, repo, number } = context.issue; + const labelToRemove = 'pr:e2e:perf'; + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number: number, + name: labelToRemove + }); + } catch (error) { + core.warning(`Failed to remove ' + labelToRemove + ' label: ${error.message}`); + } diff --git a/.github/workflows/e2e-pr.yml b/.github/workflows/e2e-pr.yml new file mode 100644 index 00000000000..25deadb4f66 --- /dev/null +++ b/.github/workflows/e2e-pr.yml @@ -0,0 +1,68 @@ +name: 'e2e-pr' +on: + push: + branches: master + workflow_dispatch: + pull_request: + types: + - labeled + - opened + schedule: + - cron: '0 0 * * *' +jobs: + e2e-full: + if: contains(github.event.pull_request.labels.*.name, 'pr:e2e') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 'lts/hydrogen' + + - name: Cache NPM dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - run: npx playwright@1.39.0 install + - run: npx playwright install chrome-beta + - run: npm install --cache ~/.npm --no-audit --progress=false + - run: npm run test:e2e:full -- --max-failures=40 + - run: npm run cov:e2e:report || true + - shell: bash + env: + SUPER_SECRET: ${{ secrets.CODECOV_TOKEN }} + run: | + npm run cov:e2e:full:publish + - name: Archive test results + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + path: test-results + + - name: Remove pr:e2e label (if present) + if: always() + uses: actions/github-script@v6 + with: + script: | + const { owner, repo, number } = context.issue; + const labelToRemove = 'pr:e2e'; + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number: number, + name: labelToRemove + }); + } catch (error) { + core.warning(`Failed to remove ' + labelToRemove + ' label: ${error.message}`); + } diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml deleted file mode 100644 index 4a67227c0b5..00000000000 --- a/.github/workflows/lighthouse.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: lighthouse -on: - workflow_dispatch: - inputs: - version: - description: 'Which branch do you want to test?' # Limited to branch for now - required: false - default: 'master' -jobs: - lighthouse: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.version }} - - uses: actions/setup-node@v2 - with: - node-version: '14' - - run: npm install && npm install -g @lhci/cli #Don't want to include this in our deps - - run: lhci autorun \ No newline at end of file diff --git a/.github/workflows/npm-prerelease.yml b/.github/workflows/npm-prerelease.yml new file mode 100644 index 00000000000..df00a0a7a13 --- /dev/null +++ b/.github/workflows/npm-prerelease.yml @@ -0,0 +1,37 @@ +# This workflow will run tests using node and then publish a package to npmjs when a prerelease is created +# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages + +name: npm_prerelease + +on: + release: + types: [prereleased] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/hydrogen + - run: npm install + - run: | + echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> ~/.npmrc + npm whoami + npm publish --access=public --tag unstable openmct + # - run: npm test + + publish-npm-prerelease: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/hydrogen + registry-url: https://registry.npmjs.org/ + - run: npm install + - run: npm publish --access=public --tag unstable + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/pr-platform.yml b/.github/workflows/pr-platform.yml new file mode 100644 index 00000000000..dfd14859e73 --- /dev/null +++ b/.github/workflows/pr-platform.yml @@ -0,0 +1,70 @@ +name: 'pr-platform' +on: + push: + branches: master + workflow_dispatch: + pull_request: + types: + - labeled + - opened + schedule: + - cron: '0 0 * * *' +jobs: + pr-platform: + if: contains(github.event.pull_request.labels.*.name, 'pr:platform') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + node_version: + - lts/iron + - lts/hydrogen + architecture: + - x64 + + name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node_version }} + architecture: ${{ matrix.architecture }} + + - name: Cache NPM dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.node_version }}- + + - run: npm install --cache ~/.npm --no-audit --progress=false + + - run: npm test + + - run: npm run lint -- --quiet + + - name: Remove pr:platform label (if present) + if: always() + uses: actions/github-script@v6 + with: + script: | + const { owner, repo, number } = context.issue; + const labelToRemove = 'pr:platform'; + try { + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number: number, + name: labelToRemove + }); + } catch (error) { + core.warning(`Failed to remove ' + labelToRemove + ' label: ${error.message}`); + } diff --git a/.github/workflows/prcop-config.json b/.github/workflows/prcop-config.json new file mode 100644 index 00000000000..a85deb7564a --- /dev/null +++ b/.github/workflows/prcop-config.json @@ -0,0 +1,19 @@ +{ + "linters": [ + { + "name": "descriptionRegexp", + "config": { + "regexp": "[x|X]] Testing instructions", + "errorMessage": ":police_officer: PR Description does not confirm that associated issue(s) contain Testing instructions" + } + }, + { + "name": "descriptionMinWords", + "config": { + "minWordsCount": 160, + "errorMessage": ":police_officer: Please, be sure to use existing PR template." + } + } + ], + "disableWord": "pr:daveit" +} diff --git a/.github/workflows/prcop.yml b/.github/workflows/prcop.yml new file mode 100644 index 00000000000..e933f7319ee --- /dev/null +++ b/.github/workflows/prcop.yml @@ -0,0 +1,38 @@ +name: PRCop + +on: + pull_request: + types: + - labeled + - unlabeled + - opened + - reopened + - synchronize + - edited + pull_request_review_comment: + types: + - created +env: + LABELS: ${{ join( github.event.pull_request.labels.*.name, ' ' ) }} +jobs: + prcop: + runs-on: ubuntu-latest + name: Template Check + steps: + - name: Linting Pull Request + uses: makaroni4/prcop@v1.0.35 + with: + config-file: '.github/workflows/prcop-config.json' + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + check-type-label: + name: Check type Label + runs-on: ubuntu-latest + steps: + - if: contains( env.LABELS, 'type:' ) == false + run: exit 1 + check-milestone: + name: Check Milestone + runs-on: ubuntu-latest + steps: + - if: github.event.pull_request.milestone == null && contains( env.LABELS, 'no milestone' ) == false + run: exit 1 diff --git a/.gitignore b/.gitignore index 76bb23dc5c4..e3185bee0b4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,8 @@ *.idea *.iml -# External dependencies +# VSCode +.vscode/settings.json # Build output target @@ -24,23 +25,28 @@ dist # Mac OS X Finder .DS_Store -# Closed source libraries -closed-lib - # Node, Bower dependencies node_modules bower_components -# Protractor logs -protractor/logs - # npm-debug log npm-debug.log # karma reports report.*.json -# Lighthouse reports -.lighthouseci +# e2e test artifacts +test-results +html-test-results + +# couchdb scripting artifacts +src/plugins/persistence/couch/.env.local +index.html.bak + +# codecov artifacts +.nyc_output +coverage +codecov +# :( package-lock.json diff --git a/.npmignore b/.npmignore index 99b47432aac..1bdde6a5f59 100644 --- a/.npmignore +++ b/.npmignore @@ -1,35 +1,30 @@ -*.scssc -*.zip -*.gzip -*.tgz -*.DS_Store - -*.sass-cache -*COMPILE.css - -# Intellij project configuration files -*.idea -*.iml - -# External dependencies - -# Build output -target - -# Mac OS X Finder -.DS_Store - -# Closed source libraries -closed-lib - -# Node, Bower dependencies -node_modules -bower_components - -Procfile - -# Protractor logs -protractor/logs - -# npm-debug log -npm-debug.log +# Ignore everything first (will not ignore special files like LICENSE.md, +# README.md, and package.json)... +/**/* + +# ...but include these folders... +!/dist/**/* +!/src/**/* + +# We might be able to remove this if it is not imported by any project directly. +# https://github.com/nasa/openmct/issues/4992 +!/example/**/* + +# ...except for these files in the above folders. +/src/**/*Spec.js +/src/**/test/ +# TODO move test utils into test/ folders +/src/utils/testing.js + +# Also include these special top-level files. +!copyright-notice.js +!copyright-notice.html +!index.html +!openmct.js +!SECURITY.md + +# Add e2e tests to npm package +!/e2e/**/* + +# ... except our test-data folder files. +/e2e/test-data/*.json diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000000..3b9d59d669d --- /dev/null +++ b/.npmrc @@ -0,0 +1,7 @@ +loglevel=warn + +#Prevent folks from ignoring an important error when building from source +engine-strict=true + +# Dont include lockfile +package-lock=false \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000000..1a2f5bd2045 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/* \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000000..2c26753b090 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,27 @@ +# Docs +*.md + +# Build output +target +dist + +# Mac OS X Finder +.DS_Store + +# Node dependencies +node_modules + +# npm-debug log +npm-debug.log + +# karma reports +report.*.json + +# e2e test artifacts +test-results +html-test-results + +# codecov artifacts +.nyc_output +coverage +codecov diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000000..479112ec1d6 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "trailingComma": "none", + "singleQuote": true, + "printWidth": 100, + "endOfLine": "auto" +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000000..24ebdbe6fb2 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,14 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "Vue.volar", + "Vue.vscode-typescript-vue-plugin", + "dbaeumer.vscode-eslint", + "rvest.vs-code-prettier-eslint" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": ["octref.vetur"] +} diff --git a/.webpack/webpack.common.js b/.webpack/webpack.common.js new file mode 100644 index 00000000000..1dc3af7ba6a --- /dev/null +++ b/.webpack/webpack.common.js @@ -0,0 +1,185 @@ +/* +This is the OpenMCT common webpack file. It is imported by the other three webpack configurations: + - webpack.prod.js - the production configuration for OpenMCT (default) + - webpack.dev.js - the development configuration for OpenMCT + - webpack.coverage.js - imports webpack.dev.js and adds code coverage +There are separate npm scripts to use these configurations, though simply running `npm install` +will use the default production configuration. +*/ +import { execSync } from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +import CopyWebpackPlugin from 'copy-webpack-plugin'; +import MiniCssExtractPlugin from 'mini-css-extract-plugin'; +import { VueLoaderPlugin } from 'vue-loader'; +import webpack from 'webpack'; +let gitRevision = 'error-retrieving-revision'; +let gitBranch = 'error-retrieving-branch'; + +const packageDefinition = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url))); + +try { + gitRevision = execSync('git rev-parse HEAD').toString().trim(); + gitBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); +} catch (err) { + console.warn(err); +} + +const projectRootDir = fileURLToPath(new URL('../', import.meta.url)); + +/** @type {import('webpack').Configuration} */ +const config = { + context: projectRootDir, + devServer: { + client: { + progress: true, + overlay: { + // Disable overlay for runtime errors. + // See: https://github.com/webpack/webpack-dev-server/issues/4771 + runtimeErrors: false + } + } + }, + entry: { + openmct: './openmct.js', + generatorWorker: './example/generator/generatorWorker.js', + couchDBChangesFeed: './src/plugins/persistence/couch/CouchChangesFeed.js', + inMemorySearchWorker: './src/api/objects/InMemorySearchWorker.js', + espressoTheme: './src/plugins/themes/espresso-theme.scss', + snowTheme: './src/plugins/themes/snow-theme.scss' + }, + output: { + globalObject: 'this', + filename: '[name].js', + path: path.resolve(projectRootDir, 'dist'), + library: 'openmct', + libraryExport: 'default', + libraryTarget: 'umd', + publicPath: '', + hashFunction: 'xxhash64', + clean: true + }, + resolve: { + alias: { + '@': path.join(projectRootDir, 'src'), + legacyRegistry: path.join(projectRootDir, 'src/legacyRegistry'), + csv: 'comma-separated-values', + EventEmitter: 'eventemitter3', + bourbon: 'bourbon.scss', + 'plotly-basic': 'plotly.js-basic-dist-min', + 'plotly-gl2d': 'plotly.js-gl2d-dist-min', + printj: 'printj/printj.mjs', + styles: path.join(projectRootDir, 'src/styles'), + MCT: path.join(projectRootDir, 'src/MCT'), + testUtils: path.join(projectRootDir, 'src/utils/testUtils.js'), + objectUtils: path.join(projectRootDir, 'src/api/objects/object-utils.js'), + utils: path.join(projectRootDir, 'src/utils'), + vue: 'vue/dist/vue.esm-bundler' + } + }, + plugins: [ + new webpack.DefinePlugin({ + __OPENMCT_VERSION__: `'${packageDefinition.version}'`, + __OPENMCT_BUILD_DATE__: `'${new Date()}'`, + __OPENMCT_REVISION__: `'${gitRevision}'`, + __OPENMCT_BUILD_BRANCH__: `'${gitBranch}'`, + __VUE_OPTIONS_API__: true, // enable/disable Options API support, default: true + __VUE_PROD_DEVTOOLS__: false // enable/disable devtools support in production, default: false + }), + new VueLoaderPlugin(), + new CopyWebpackPlugin({ + patterns: [ + { + from: 'src/images/favicons', + to: 'favicons' + }, + { + from: './index.html', + transform: function (content) { + return content.toString().replace(/dist\//g, ''); + } + }, + { + from: 'src/plugins/imagery/layers', + to: 'imagery' + } + ] + }), + new MiniCssExtractPlugin({ + filename: '[name].css', + chunkFilename: '[name].css' + }), + // Add a UTF-8 BOM to CSS output to avoid random mojibake + new webpack.BannerPlugin({ + test: /.*Theme\.css$/, + raw: true, + banner: '@charset "UTF-8";' + }) + ], + module: { + rules: [ + { + test: /\.(sc|sa|c)ss$/, + use: [ + MiniCssExtractPlugin.loader, + { + loader: 'css-loader' + }, + { + loader: 'resolve-url-loader' + }, + { + loader: 'sass-loader', + options: { sourceMap: true } + } + ] + }, + { + test: /\.vue$/, + loader: 'vue-loader', + options: { + compilerOptions: { + hoistStatic: false, + whitespace: 'preserve' + } + } + }, + { + test: /\.html$/, + type: 'asset/source' + }, + { + test: /\.(jpg|jpeg|png|svg)$/, + type: 'asset/resource', + generator: { + filename: 'images/[name][ext]' + } + }, + { + test: /\.ico$/, + type: 'asset/resource', + generator: { + filename: 'icons/[name][ext]' + } + }, + { + test: /\.(woff|woff2?|eot|ttf)$/, + type: 'asset/resource', + generator: { + filename: 'fonts/[name][ext]' + } + } + ] + }, + stats: 'errors-warnings', + performance: { + // We should eventually consider chunking to decrease + // these values + maxEntrypointSize: 27000000, + maxAssetSize: 27000000 + } +}; + +export default config; diff --git a/.webpack/webpack.coverage.js b/.webpack/webpack.coverage.js new file mode 100644 index 00000000000..14d11fe7bc1 --- /dev/null +++ b/.webpack/webpack.coverage.js @@ -0,0 +1,35 @@ +/* +This file extends the webpack.dev.js config to add babel istanbul coverage. +OpenMCT Continuous Integration servers use this configuration to add code coverage +information to pull requests. +*/ + +import config from './webpack.dev.js'; +// eslint-disable-next-line no-undef +const CI = process.env.CI === 'true'; + +config.devtool = CI ? false : undefined; + +config.devServer.hot = false; + +config.module.rules.push({ + test: /\.js$/, + exclude: /(Spec\.js$)|(node_modules)/, + use: { + loader: 'babel-loader', + options: { + retainLines: true, + // eslint-disable-next-line no-undef + plugins: [ + [ + 'babel-plugin-istanbul', + { + extension: ['.js', '.vue'] + } + ] + ] + } + } +}); + +export default config; diff --git a/.webpack/webpack.dev.js b/.webpack/webpack.dev.js new file mode 100644 index 00000000000..3d18812e97d --- /dev/null +++ b/.webpack/webpack.dev.js @@ -0,0 +1,48 @@ +/* +This configuration should be used for development purposes. It contains full source map, a +devServer (which be invoked using by `npm start`), and a non-minified Vue.js distribution. +If OpenMCT is to be used for a production server, use webpack.prod.js instead. +*/ +import path from 'path'; +import webpack from 'webpack'; +import { merge } from 'webpack-merge'; +import { fileURLToPath } from 'node:url'; + +import common from './webpack.common.js'; + +export default merge(common, { + mode: 'development', + watchOptions: { + // Since we use require.context, webpack is watching the entire directory. + // We need to exclude any files we don't want webpack to watch. + // See: https://webpack.js.org/configuration/watch/#watchoptions-exclude + ignored: [ + '**/{node_modules,dist,docs,e2e}', // All files in node_modules, dist, docs, e2e, + '**/{*.yml,Procfile,webpack*.js,babel*.js,package*.json,tsconfig.json}', // Config files + '**/*.{sh,md,png,ttf,woff,svg}', // Non source files + '**/.*' // dotfiles and dotfolders + ] + }, + plugins: [ + new webpack.DefinePlugin({ + __OPENMCT_ROOT_RELATIVE__: '"dist/"' + }) + ], + devtool: 'eval-source-map', + devServer: { + devMiddleware: { + writeToDisk: (filePathString) => { + const filePath = path.parse(filePathString); + const shouldWrite = !filePath.base.includes('hot-update'); + + return shouldWrite; + } + }, + watchFiles: ['**/*.css'], + static: { + directory: fileURLToPath(new URL('../dist', import.meta.url)), + publicPath: '/dist', + watch: false + } + } +}); diff --git a/.webpack/webpack.prod.js b/.webpack/webpack.prod.js new file mode 100644 index 00000000000..9224625a128 --- /dev/null +++ b/.webpack/webpack.prod.js @@ -0,0 +1,19 @@ +/* +This configuration should be used for production installs. +It is the default webpack configuration. +*/ + +import webpack from 'webpack'; +import { merge } from 'webpack-merge'; + +import common from './webpack.common.js'; + +export default merge(common, { + mode: 'production', + plugins: [ + new webpack.DefinePlugin({ + __OPENMCT_ROOT_RELATIVE__: '""' + }) + ], + devtool: 'source-map' +}); diff --git a/API.md b/API.md index 229425b94e1..ded6724a6df 100644 --- a/API.md +++ b/API.md @@ -1,11 +1,14 @@ -**Table of Contents** +**Table of Contents** -- [Building Applications With Open MCT](#building-applications-with-open-mct) +- [Developing Applications With Open MCT](#developing-applications-with-open-mct) - [Scope and purpose of this document](#scope-and-purpose-of-this-document) - [Building From Source](#building-from-source) - [Starting an Open MCT application](#starting-an-open-mct-application) + - [Types](#types) + - [Using Types](#using-types) + - [Limitations](#limitations) - [Plugins](#plugins) - [Defining and Installing a New Plugin](#defining-and-installing-a-new-plugin) - [Domain Objects and Identifiers](#domain-objects-and-identifiers) @@ -23,11 +26,11 @@ - [Value Hints](#value-hints) - [The Time Conductor and Telemetry](#the-time-conductor-and-telemetry) - [Telemetry Providers](#telemetry-providers) - - [Telemetry Requests and Responses.](#telemetry-requests-and-responses) + - [Telemetry Requests and Responses](#telemetry-requests-and-responses) - [Request Strategies **draft**](#request-strategies-draft) - [`latest` request strategy](#latest-request-strategy) - [`minmax` request strategy](#minmax-request-strategy) - - [Telemetry Formats **draft**](#telemetry-formats-draft) + - [Telemetry Formats](#telemetry-formats) - [Registering Formats](#registering-formats) - [Telemetry Data](#telemetry-data) - [Telemetry Datums](#telemetry-datums) @@ -41,8 +44,10 @@ - [Clocks](#clocks) - [Defining and registering clocks](#defining-and-registering-clocks) - [Getting and setting active clock](#getting-and-setting-active-clock) - - [Stopping an active clock](#stopping-an-active-clock) + - [⚠️ \[DEPRECATED\] Stopping an active clock](#️-deprecated-stopping-an-active-clock) - [Clock Offsets](#clock-offsets) + - [Time Modes](#time-modes) + - [Time Mode Helper Methods](#time-mode-helper-methods) - [Time Events](#time-events) - [List of Time Events](#list-of-time-events) - [The Time Conductor](#the-time-conductor) @@ -52,26 +57,27 @@ - [The URL Status Indicator](#the-url-status-indicator) - [Creating a Simple Indicator](#creating-a-simple-indicator) - [Custom Indicators](#custom-indicators) + - [Priority API](#priority-api) + - [Priority Types](#priority-types) -# Building Applications With Open MCT +# Developing Applications With Open MCT ## Scope and purpose of this document -This document is intended to serve as a reference for developing an application -based on Open MCT. It will provide details of the API functions necessary to -extend the Open MCT platform meet common use cases such as integrating with a telemetry source. +This document is intended to serve as a reference for developing an application +based on Open MCT. It will provide details of the API functions necessary to +extend the Open MCT platform meet common use cases such as integrating with a telemetry source. -The best place to start is with the [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial). -These will walk you through the process of getting up and running with Open +The best place to start is with the [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial). +These will walk you through the process of getting up and running with Open MCT, as well as addressing some common developer use cases. -## Building From Source +## Building From Source -The latest version of Open MCT is available from [our GitHub repository](https://github.com/nasa/openmct). -If you have `git`, and `node` installed, you can build Open MCT with the -commands +The latest version of Open MCT is available from [our GitHub repository](https://github.com/nasa/openmct). +If you have `git`, and `node` installed, you can build Open MCT with the commands ```bash git clone https://github.com/nasa/openmct.git @@ -79,28 +85,31 @@ cd openmct npm install ``` -These commands will fetch the Open MCT source from our GitHub repository, and -build a minified version that can be included in your application. The output -of the build process is placed in a `dist` folder under the openmct source -directory, which can be copied out to another location as needed. The contents -of this folder will include a minified javascript file named `openmct.js` as -well as assets such as html, css, and images necessary for the UI. +These commands will fetch the Open MCT source from our GitHub repository, and +build a minified version that can be included in your application. The output +of the build process is placed in a `dist` folder under the openmct source +directory, which can be copied out to another location as needed. The contents +of this folder will include a minified javascript file named `openmct.js` as +well as assets such as html, css, and images necessary for the UI. ## Starting an Open MCT application -To start a minimally functional Open MCT application, it is necessary to -include the Open MCT distributable, enable some basic plugins, and bootstrap -the application. The tutorials walk through the process of getting Open MCT up -and running from scratch, but provided below is a minimal HTML template that -includes Open MCT, installs some basic plugins, and bootstraps the application. -It assumes that Open MCT is installed under an `openmct` subdirectory, as -described in [Building From Source](#building-from-source). +> [!WARNING] +> Open MCT provides a development server via `webpack-dev-server` (`npm start`). **This should be used for development purposes only and should never be deployed to a production environment**. -This approach includes openmct using a simple script tag, resulting in a global -variable named `openmct`. This `openmct` object is used subsequently to make -API calls. +To start a minimally functional Open MCT application, it is necessary to +include the Open MCT distributable, enable some basic plugins, and bootstrap +the application. The tutorials walk through the process of getting Open MCT up +and running from scratch, but provided below is a minimal HTML template that +includes Open MCT, installs some basic plugins, and bootstraps the application. +It assumes that Open MCT is installed under an `openmct` subdirectory, as +described in [Building From Source](#building-from-source). -Open MCT is packaged as a UMD (Universal Module Definition) module, so common +This approach includes openmct using a simple script tag, resulting in a global +variable named `openmct`. This `openmct` object is used subsequently to make +API calls. + +Open MCT is packaged as a UMD (Universal Module Definition) module, so common script loaders are also supported. ```html @@ -121,17 +130,59 @@ script loaders are also supported. ``` -The Open MCT library included above requires certain assets such as html -templates, images, and css. If you installed Open MCT from GitHub as described +The Open MCT library included above requires certain assets such as html +templates, images, and css. If you installed Open MCT from GitHub as described in the section on [Building from Source](#building-from-source) then these -assets will have been downloaded along with the Open MCT javascript library. +assets will have been downloaded along with the Open MCT javascript library. -There are some plugins bundled with the application that provide UI, -persistence, and other default configuration which are necessary to be able to -do anything with the application initially. Any of these plugins can, in -principle, be replaced with a custom plugin. The included plugins are +There are some plugins bundled with the application that provide UI, +persistence, and other default configuration which are necessary to be able to +do anything with the application initially. Any of these plugins can, in +principle, be replaced with a custom plugin. The included plugins are documented in the [Included Plugins](#included-plugins) section. +## Types + +The Open MCT library includes its own TypeScript declaration files which can be +used to provide code hints and typechecking in your own Open MCT application. + +Open MCT's type declarations are generated via `tsc` from JSDoc-style comment +blocks. For more information on this, [check out TypeScript's documentation](https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html). + +### Using Types + +In order to use Open MCT's provided types in your own application, create a +`jsconfig.js` at the root of your project with this minimal configuration: + +```json +{ + "compilerOptions": { + "baseUrl": "./", + "target": "es6", + "checkJs": true, + "moduleResolution": "node", + "paths": { + "openmct": ["node_modules/openmct/dist/openmct.d.ts"] + } + } +} +``` + +Then, simply import and use `openmct` in your application: + +```js +import openmct from "openmct"; +``` + +### Limitations + +The effort to add types for Open MCT's public API is ongoing, and the provided +type declarations may be incomplete. + +If you would like to contribute types to Open MCT, please check out +[TypeScript's documentation](https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html) on generating type declarations from JSDoc-style comment blocks. +Then read through our [contributing guide](https://github.com/nasa/openmct/blob/f7cf3f72c2efd46da7ce5719c5e52c8806d166f0/CONTRIBUTING.md) and open a PR! + ## Plugins ### Defining and Installing a New Plugin @@ -144,10 +195,10 @@ openmct.install(function install(openmctAPI) { ``` New plugins are installed in Open MCT by calling `openmct.install`, and -providing a plugin installation function. This function will be invoked on -application startup with one parameter - the openmct API object. A common -approach used in the Open MCT codebase is to define a plugin as a function that -returns this installation function. This allows configuration to be specified +providing a plugin installation function. This function will be invoked on +application startup with one parameter - the openmct API object. A common +approach used in the Open MCT codebase is to define a plugin as a function that +returns this installation function. This allows configuration to be specified when the plugin is included. eg. @@ -160,16 +211,16 @@ This approach can be seen in all of the [plugins provided with Open MCT](https:/ ## Domain Objects and Identifiers -_Domain Objects_ are the basic entities that represent domain knowledge in Open -MCT. The temperature sensor on a solar panel, an overlay plot comparing the -results of all temperature sensors, the command dictionary for a spacecraft, -the individual commands in that dictionary, the "My Items" folder: All of these +_Domain Objects_ are the basic entities that represent domain knowledge in Open +MCT. The temperature sensor on a solar panel, an overlay plot comparing the +results of all temperature sensors, the command dictionary for a spacecraft, +the individual commands in that dictionary, the "My Items" folder: All of these things are domain objects. A _Domain Object_ is simply a javascript object with some standard attributes. -An example of a _Domain Object_ is the "My Items" object which is a folder in -which a user can persist any objects that they create. The My Items object -looks like this: +An example of a _Domain Object_ is the "My Items" object which is a folder in +which a user can persist any objects that they create. The My Items object +looks like this: ```javascript { @@ -188,23 +239,24 @@ looks like this: The main attributes to note are the `identifier`, and `type` attributes. -* `identifier`: A composite key that provides a universally unique identifier +- `identifier`: A composite key that provides a universally unique identifier for this object. The `namespace` and `key` are used to identify the object. - The `key` must be unique within the namespace. -* `type`: All objects in Open MCT have a type. Types allow you to form an - ontology of knowledge and provide an abstraction for grouping, visualizing, - and interpreting data. Details on how to define a new object type are - provided below. + The `key` must be unique within the namespace. +- `type`: All objects in Open MCT have a type. Types allow you to form an + ontology of knowledge and provide an abstraction for grouping, visualizing, + and interpreting data. Details on how to define a new object type are + provided below. -Open MCT uses a number of builtin types. Typically you are going to want to +Open MCT uses a number of builtin types. Typically you are going to want to define your own when extending Open MCT. ### Domain Object Types -Custom types may be registered via the `addType` function on the Open MCT Type +Custom types may be registered via the `addType` function on the Open MCT Type registry. eg. + ```javascript openmct.types.addType('example.my-type', { name: "My Type", @@ -214,57 +266,68 @@ openmct.types.addType('example.my-type', { ``` The `addType` function accepts two arguments: -* A `string` key identifying the type. This key is used when specifying a type + +- A `string` key identifying the type. This key is used when specifying a type for an object. We recommend prefixing your types with a namespace to avoid conflicts with other plugins. -* An object type specification. An object type definition supports the following -attributes - * `name`: a `string` naming this object type - * `description`: a `string` specifying a longer-form description of this type - * `initialize`: a `function` which initializes the model for new domain objects - of this type. This can be used for setting default values on an object when +- An object type specification. An object type definition supports the following +attributes + - `name`: a `string` naming this object type + - `description`: a `string` specifying a longer-form description of this type + - `initialize`: a `function` which initializes the model for new domain objects + of this type. This can be used for setting default values on an object when it is instantiated. - * `creatable`: A `boolean` indicating whether users should be allowed to create - this type (default: `false`). This will determine whether the type appears + - `creatable`: A `boolean` indicating whether users should be allowed to create + this type (default: `false`). This will determine whether the type appears in the `Create` menu. - * `cssClass`: A `string` specifying a CSS class to apply to each representation - of this object. This is used for specifying an icon to appear next to each + - `cssClass`: A `string` specifying a CSS class to apply to each representation + of this object. This is used for specifying an icon to appear next to each object of this type. -The [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial) provide a -step-by-step examples of writing code for Open MCT that includes a [section on +The [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial) provide a +step-by-step examples of writing code for Open MCT that includes a [section on defining a new object type](https://github.com/nasa/openmct-tutorial#step-3---providing-objects). ## Root Objects -In many cases, you'd like a certain object (or a certain hierarchy of objects) -to be accessible from the top level of the application (the tree on the left-hand -side of Open MCT.) For example, it is typical to expose a telemetry dictionary +In many cases, you'd like a certain object (or a certain hierarchy of objects) +to be accessible from the top level of the application (the tree on the left-hand +side of Open MCT.) For example, it is typical to expose a telemetry dictionary as a hierarchy of telemetry-providing domain objects in this fashion. To do so, use the `addRoot` method of the object API. eg. + ```javascript openmct.objects.addRoot({ - namespace: "example.namespace", - key: "my-key" - }); + namespace: "example.namespace", + key: "my-key" +}, +openmct.priority.HIGH); ``` -The `addRoot` function takes a single [object identifier](#domain-objects-and-identifiers) -as an argument. +The `addRoot` function takes a two arguments, the first can be an [object identifier](#domain-objects-and-identifiers) for a root level object, or an array of identifiers for root +level objects, or a function that returns a promise for an identifier or an array of root level objects, the second is a [priority](#priority-api) or numeric value. + +When using the `getAll` method of the object API, they will be returned in order of priority. + +eg. + +```javascript +openmct.objects.addRoot(identifier, openmct.priority.LOW); // low = -1000, will appear last in composition or tree +openmct.objects.addRoot(otherIdentifier, openmct.priority.HIGH); // high = 1000, will appear first in composition or tree +``` -Root objects are loaded just like any other objects, i.e. via an object -provider. +Root objects are loaded just like any other objects, i.e. via an object provider. ## Object Providers -An Object Provider is used to build _Domain Objects_, typically retrieved from -some source such as a persistence store or telemetry dictionary. In order to -integrate telemetry from a new source an object provider will need to be created -that can build objects representing telemetry points exposed by the telemetry -source. The API call to define a new object provider is fairly straightforward. +An Object Provider is used to build _Domain Objects_, typically retrieved from +some source such as a persistence store or telemetry dictionary. In order to +integrate telemetry from a new source an object provider will need to be created +that can build objects representing telemetry points exposed by the telemetry +source. The API call to define a new object provider is fairly straightforward. Here's a very simple example: ```javascript @@ -278,14 +341,15 @@ openmct.objects.addProvider('example.namespace', { } }); ``` + The `addProvider` function takes two arguments: -* `namespace`: A `string` representing the namespace that this object provider +- `namespace`: A `string` representing the namespace that this object provider will provide objects for. -* `provider`: An `object` with a single function, `get`. This function accepts an -[Identifier](#domain-objects-and-identifiers) for the object to be provided. -It is expected that the `get` function will return a -[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) +- `provider`: An `object` with a single function, `get`. This function accepts an +[Identifier](#domain-objects-and-identifiers) for the object to be provided. +It is expected that the `get` function will return a +[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves with the object being requested. In future, object providers will support other methods to enable other operations with persistence stores, such as creating, updating, and deleting objects. @@ -300,8 +364,8 @@ may be cases where you want to provide the composition of a certain object ### Adding Composition Providers -You may want to populate a hierarchy under a custom root-level object based on -the contents of a telemetry dictionary. To do this, you can add a new +You may want to populate a hierarchy under a custom root-level object based on +the contents of a telemetry dictionary. To do this, you can add a new Composition Provider: ```javascript @@ -314,19 +378,20 @@ openmct.composition.addProvider({ } }); ``` -The `addProvider` function accepts a Composition Provider object as its sole + +The `addProvider` function accepts a Composition Provider object as its sole argument. A Composition Provider is a javascript object exposing two functions: -* `appliesTo`: A `function` that accepts a `domainObject` argument, and returns -a `boolean` value indicating whether this composition provider applies to the +- `appliesTo`: A `function` that accepts a `domainObject` argument, and returns +a `boolean` value indicating whether this composition provider applies to the given object. -* `load`: A `function` that accepts a `domainObject` as an argument, and returns +- `load`: A `function` that accepts a `domainObject` as an argument, and returns a `Promise` that resolves with an array of [Identifier](#domain-objects-and-identifiers). These identifiers will be used to fetch Domain Objects from an [Object Provider](#object-provider) ### Default Composition Provider -The default composition provider applies to any domain object with a -`composition` property. The value of `composition` should be an array of +The default composition provider applies to any domain object with a +`composition` property. The value of `composition` should be an array of identifiers, e.g.: ```javascript @@ -360,7 +425,7 @@ Open MCT are stable and documentation is included below. There are two main tasks for integrating telemetry sources-- describing telemetry objects with relevant metadata, and then providing telemetry data for those objects. You'll use an [Object Provider](#object-providers) to provide objects with the necessary [Telemetry Metadata](#telemetry-metadata), and then register a [Telemetry Provider](#telemetry-providers) to retrieve telemetry data for those objects. Alternatively, you can register a telemetry metadata provider to provide the necessary telemetry metadata. -For a step-by-step guide to building a telemetry adapter, please see the +For a step-by-step guide to building a telemetry adapter, please see the [Open MCT Tutorials](https://github.com/nasa/openmct-tutorial). #### Telemetry Metadata @@ -380,7 +445,7 @@ A telemetry object is a domain object with a telemetry property. To take an exa { "key": "value", "name": "Value", - "units": "kilograms", + "unit": "kilograms", "format": "float", "min": 0, "max": 100, @@ -415,29 +480,27 @@ attribute | type | flags | notes `name` | string | optional | a human readable label for this field. If omitted, defaults to `key`. `source` | string | optional | identifies the property of a datum where this value is stored. If omitted, defaults to `key`. `format` | string | optional | a specific format identifier, mapping to a formatter. If omitted, uses a default formatter. For enumerations, use `enum`. For timestamps, use `utc` if you are using utc dates, otherwise use a key mapping to your custom date format. -`units` | string | optional | the units of this value, e.g. `km`, `seconds`, `parsecs` +`unit` | string | optional | the unit of this value, e.g. `km`, `seconds`, `parsecs` `min` | number | optional | the minimum possible value of this measurement. Will be used by plots, gauges, etc to automatically set a min value. `max` | number | optional | the maximum possible value of this measurement. Will be used by plots, gauges, etc to automatically set a max value. `enumerations` | array | optional | for objects where `format` is `"enum"`, this array tracks all possible enumerations of the value. Each entry in this array is an object, with a `value` property that is the numerical value of the enumeration, and a `string` property that is the text value of the enumeration. ex: `{"value": 0, "string": "OFF"}`. If you use an enumerations array, `min` and `max` will be set automatically for you. - ###### Value Hints Each telemetry value description has an object defining hints. Keys in this object represent the hint itself, and the value represents the weight of that hint. A lower weight means the hint has a higher priority. For example, multiple values could be hinted for use as the y-axis of a plot (raw, engineering), but the highest priority would be the default choice. Likewise, a table will use hints to determine the default order of columns. Known hints: -* `domain`: Values with a `domain` hint will be used for the x-axis of a plot, and tables will render columns for these values first. -* `range`: Values with a `range` hint will be used as the y-axis on a plot, and tables will render columns for these values after the `domain` values. -* `image`: Indicates that the value may be interpreted as the URL to an image file, in which case appropriate views will be made available. -* `imageDownloadName`: Indicates that the value may be interpreted as the name of the image file. +- `domain`: Values with a `domain` hint will be used for the x-axis of a plot, and tables will render columns for these values first. +- `range`: Values with a `range` hint will be used as the y-axis on a plot, and tables will render columns for these values after the `domain` values. +- `image`: Indicates that the value may be interpreted as the URL to an image file, in which case appropriate views will be made available. +- `imageDownloadName`: Indicates that the value may be interpreted as the name of the image file. -##### The Time Conductor and Telemetry +##### The Time Conductor and Telemetry Open MCT provides a number of ways to pivot through data and link data via time. The Time Conductor helps synchronize multiple views around the same time. -In order for the time conductor to work, there will always be an active "time system". All telemetry metadata *must* have a telemetry value with a `key` that matches the `key` of the active time system. You can use the `source` attribute on the value metadata to remap this to a different field in the telemetry datum-- especially useful if you are working with disparate datasources that have different field mappings. - +In order for the time conductor to work, there will always be an active "time system". All telemetry metadata _must_ have a telemetry value with a `key` that matches the `key` of the active time system. You can use the `source` attribute on the value metadata to remap this to a different field in the telemetry datum-- especially useful if you are working with disparate datasources that have different field mappings. #### Telemetry Providers @@ -445,14 +508,14 @@ Telemetry providers are responsible for providing historical and real-time telem A telemetry provider is a javascript object with up to four methods: -* `supportsSubscribe(domainObject, callback, options)` optional. Must be implemented to provide realtime telemetry. Should return `true` if the provider supports subscriptions for the given domain object (and request options). -* `subscribe(domainObject, callback, options)` required if `supportsSubscribe` is implemented. Establish a subscription for realtime data for the given domain object. Should invoke `callback` with a single telemetry datum every time data is received. Must return an unsubscribe function. Multiple views can subscribe to the same telemetry object, so it should always return a new unsubscribe function. -* `supportsRequest(domainObject, options)` optional. Must be implemented to provide historical telemetry. Should return `true` if the provider supports historical requests for the given domain object. -* `request(domainObject, options)` required if `supportsRequest` is implemented. Must return a promise for an array of telemetry datums that fulfills the request. The `options` argument will include a `start`, `end`, and `domain` attribute representing the query bounds. See [Telemetry Requests and Responses](#telemetry-requests-and-responses) for more info on how to respond to requests. -* `supportsMetadata(domainObject)` optional. Implement and return `true` for objects that you want to provide dynamic metadata for. -* `getMetadata(domainObject)` required if `supportsMetadata` is implemented. Must return a valid telemetry metadata definition that includes at least one valueMetadata definition. -* `supportsLimits(domainObject)` optional. Implement and return `true` for domain objects that you want to provide a limit evaluator for. -* `getLimitEvaluator(domainObject)` required if `supportsLimits` is implemented. Must return a valid LimitEvaluator for a given domain object. +- `supportsSubscribe(domainObject, callback, options)` optional. Must be implemented to provide realtime telemetry. Should return `true` if the provider supports subscriptions for the given domain object (and request options). +- `subscribe(domainObject, callback, options)` required if `supportsSubscribe` is implemented. Establish a subscription for realtime data for the given domain object. Should invoke `callback` with a single telemetry datum every time data is received. Must return an unsubscribe function. Multiple views can subscribe to the same telemetry object, so it should always return a new unsubscribe function. +- `supportsRequest(domainObject, options)` optional. Must be implemented to provide historical telemetry. Should return `true` if the provider supports historical requests for the given domain object. +- `request(domainObject, options)` required if `supportsRequest` is implemented. Must return a promise for an array of telemetry datums that fulfills the request. The `options` argument will include a `start`, `end`, and `domain` attribute representing the query bounds. See [Telemetry Requests and Responses](#telemetry-requests-and-responses) for more info on how to respond to requests. +- `supportsMetadata(domainObject)` optional. Implement and return `true` for objects that you want to provide dynamic metadata for. +- `getMetadata(domainObject)` required if `supportsMetadata` is implemented. Must return a valid telemetry metadata definition that includes at least one valueMetadata definition. +- `supportsLimits(domainObject)` optional. Implement and return `true` for domain objects that you want to provide a limit evaluator for. +- `getLimitEvaluator(domainObject)` required if `supportsLimits` is implemented. Must return a valid LimitEvaluator for a given domain object. Telemetry providers are registered by calling `openmct.telemetry.addProvider(provider)`, e.g. @@ -465,7 +528,7 @@ openmct.telemetry.addProvider({ Note: it is not required to implement all of the methods on every provider. Depending on the complexity of your implementation, it may be helpful to instantiate and register your realtime, historical, and metadata providers separately. -#### Telemetry Requests and Responses. +#### Telemetry Requests and Responses Telemetry requests support time bounded queries. A call to a _Telemetry Provider_'s `request` function will include an `options` argument. These are simply javascript objects with attributes for the request parameters. An example of a telemetry request object with a start and end time is included below: @@ -481,6 +544,8 @@ In this case, the `domain` is the currently selected time-system, and the start A telemetry provider's `request` method should return a promise for an array of telemetry datums. These datums must be sorted by `domain` in ascending order. +The telemetry provider's `request` method will also return an object `signal` with an `aborted` property with a value `true` if the request has been aborted by user navigation. This can be used to trigger actions when a request has been aborted. + #### Request Strategies **draft** To improve performance views may request a certain strategy for data reduction. These are intended to improve visualization performance by reducing the amount of data needed to be sent to the client. These strategies will be indicated by additional parameters in the request options. You may choose to handle them or ignore them. @@ -496,6 +561,7 @@ the number of results it desires. The `size` parameter is a hint; views must not assume the response will have the exact number of results requested. example: + ```javascript { start: 1487981997240, @@ -511,6 +577,7 @@ This strategy says "I want the latest data point in this time range". A provide ##### `minmax` request strategy example: + ```javascript { start: 1487981997240, @@ -523,38 +590,111 @@ example: MinMax queries are issued by plots, and may be issued by other types as well. The aim is to reduce the amount of data returned but still faithfully represent the full extent of the data. In order to do this, the view calculates the maximum data resolution it can display (i.e. the number of horizontal pixels in a plot) and sends that as the `size`. The response should include at least one minimum and one maximum value per point of resolution. -#### Telemetry Formats **draft** - -Telemetry format objects define how to interpret and display telemetry data. -They have a simple structure: - -* `key`: A `string` that uniquely identifies this formatter. -* `format`: A `function` that takes a raw telemetry value, and returns a - human-readable `string` representation of that value. It has one required - argument, and three optional arguments that provide context and can be used - for returning scaled representations of a value. An example of this is - representing time values in a scale such as the time conductor scale. There - are multiple ways of representing a point in time, and by providing a minimum - scale value, maximum scale value, and a count, it's possible to provide more - useful representations of time given the provided limitations. - * `value`: The raw telemetry value in its native type. - * `minValue`: An __optional__ argument specifying the minimum displayed - value. - * `maxValue`: An __optional__ argument specifying the maximum displayed - value. - * `count`: An __optional__ argument specifying the number of displayed - values. -* `parse`: A `function` that takes a `string` representation of a telemetry - value, and returns the value in its native type. **Note** parse might receive an already-parsed value. This function should be idempotent. -* `validate`: A `function` that takes a `string` representation of a telemetry - value, and returns a `boolean` value indicating whether the provided string - can be parsed. +#### Telemetry Formats + +Telemetry format objects define how to interpret and display telemetry data. +They have a simple structure, provided here as a TypeScript interface: + +```ts +interface Formatter { + key: string; // A string that uniquely identifies this formatter. + + format: ( + value: any, // The raw telemetry value in its native type. + minValue?: number, // An optional argument specifying the minimum displayed value. + maxValue?: number, // An optional argument specifying the maximum displayed value. + count?: number // An optional argument specifying the number of displayed values. + ) => string; // Returns a human-readable string representation of the provided value. + + parse: ( + value: string | any // A string representation of a telemetry value or an already-parsed value. + ) => any; // Returns the value in its native type. This function should be idempotent. + + validate: (value: string) => boolean; // Takes a string representation of a telemetry value and returns a boolean indicating whether the provided string can be parsed. +} +``` + +##### Built-in Formats + +Open MCT on its own defines a handful of built-in formats: + +###### **Number Format (default):** + +Applied to data with `format: 'number'` +```js +valueMetadata = { + format: 'number' + // ... +}; +``` + +```ts +interface NumberFormatter extends Formatter { + parse: (x: any) => number; + format: (x: number) => string; + validate: (value: any) => boolean; +} +``` +###### **String Format**: + +Applied to data with `format: 'string'` +```js +valueMetadata = { + format: 'string' + // ... +}; +``` +```ts +interface StringFormatter extends Formatter { + parse: (value: any) => string; + format: (value: string) => string; + validate: (value: any) => boolean; +} +``` + +###### **Enum Format**: +Applied to data with `format: 'enum'` +```js +valueMetadata = { + format: 'enum', + enumerations: [ + { + value: 1, + string: 'APPLE' + }, + { + value: 2, + string: 'PEAR', + }, + { + value: 3, + string: 'ORANGE' + }] + // ... +}; +``` + +Creates a two-way mapping between enum string and value to be used in the `parse` and `format` methods. +Ex: +- `formatter.parse('APPLE') === 1;` +- `formatter.format(1) === 'APPLE';` + +```ts +interface EnumFormatter extends Formatter { + parse: (value: string) => string; + format: (value: number) => string; + validate: (value: any) => boolean; +} +``` ##### Registering Formats +Formats implement the following interface (provided here as TypeScript for simplicity): + + Formats are registered with the Telemetry API using the `addFormat` function. eg. -``` javascript +```javascript openmct.telemetry.addFormat({ key: 'number-to-string', format: function (number) { @@ -572,9 +712,9 @@ openmct.telemetry.addFormat({ #### Telemetry Data A single telemetry point is considered a Datum, and is represented by a standard -javascript object. Realtime subscriptions (obtained via __subscribe__) will +javascript object. Realtime subscriptions (obtained via **subscribe**) will invoke the supplied callback once for each telemetry datum recieved. Telemetry -requests (obtained via __request__) will return a promise for an array of +requests (obtained via **request**) will return a promise for an array of telemetry datums. ##### Telemetry Datums @@ -595,14 +735,14 @@ section. #### Limit Evaluators **draft** -Limit evaluators allow a telemetry integrator to define which limits exist for a +Limit evaluators allow a telemetry integrator to define which limits exist for a telemetry endpoint and how limits should be applied to telemetry from a given domain object. A limit evaluator can implement the `evalute` method which is used to define how limits -should be applied to telemetry and the `getLimits` method which is used to specify +should be applied to telemetry and the `getLimits` method which is used to specify what the limit values are for different limit levels. -Limit levels can be mapped to one of 5 colors for visualization: +Limit levels can be mapped to one of 5 colors for visualization: `purple`, `red`, `orange`, `yellow` and `cyan`. For an example of a limit evaluator, take a look at `examples/generator/SinewaveLimitProvider.js`. @@ -611,30 +751,30 @@ For an example of a limit evaluator, take a look at `examples/generator/Sinewave The APIs for requesting telemetry from Open MCT -- e.g. for use in custom views -- are currently in draft state and are being revised. If you'd like to experiment with them before they are finalized, please contact the team via the contact-us link on our website. - ## Time API Open MCT provides API for managing the temporal state of the application. -Central to this is the concept of "time bounds". Views in Open MCT will -typically show telemetry data for some prescribed date range, and the Time API +Central to this is the concept of "time bounds". Views in Open MCT will +typically show telemetry data for some prescribed date range, and the Time API provides a way to centrally manage these bounds. -The Time API exposes a number of methods for querying and setting the temporal +The Time API exposes a number of methods for querying and setting the temporal state of the application, and emits events to inform listeners when the state changes. -Because the data displayed tends to be time domain data, Open MCT must always +Because the data displayed tends to be time domain data, Open MCT must always have at least one time system installed and activated. When you download Open -MCT, it will be pre-configured to use the UTC time system, which is installed and activated, along with other default plugins, in `index.html`. Installing and activating a time system is simple, and is covered -[in the next section](#defining-and-registering-time-systems). +MCT, it will be pre-configured to use the UTC time system, which is installed and activated, +along with other default plugins, in `index.html`. Installing and activating a time system +is simple, and is covered [in the next section](#defining-and-registering-time-systems). ### Time Systems and Bounds #### Defining and Registering Time Systems -The time bounds of an Open MCT application are defined as numbers, and a Time -System gives meaning and context to these numbers so that they can be correctly -interpreted. Time Systems are JavaScript objects that provide some information -about the current time reference frame. An example of defining and registering +The time bounds of an Open MCT application are defined as numbers, and a Time +System gives meaning and context to these numbers so that they can be correctly +interpreted. Time Systems are JavaScript objects that provide some information +about the current time reference frame. An example of defining and registering a new time system is given below: ``` javascript @@ -648,91 +788,109 @@ openmct.time.addTimeSystem({ }); ``` -The example above defines a new utc based time system. In fact, this time system -is configured and activated by default from `index.html` in the default -installation of Open MCT if you download the source from GitHub. Some details of +The example above defines a new utc based time system. In fact, this time system +is configured and activated by default from `index.html` in the default +installation of Open MCT if you download the source from GitHub. Some details of each of the required properties is provided below. -* `key`: A `string` that uniquely identifies this time system. -* `name`: A `string` providing a brief human readable label. If the [Time Conductor](#the-time-conductor) +- `key`: A `string` that uniquely identifies this time system. +- `name`: A `string` providing a brief human readable label. If the [Time Conductor](#the-time-conductor) plugin is enabled, this name will identify the time system in a dropdown menu. -* `cssClass`: A class name `string` that will be applied to the time system when -it appears in the UI. This will be used to represent the time system with an icon. -There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss), -or a custom class can be used here. -* `timeFormat`: A `string` corresponding to the key of a registered -[telemetry time format](#telemetry-formats). The format will be used for -displaying discrete timestamps from telemetry streams when this time system is -activated. If the [UTCTimeSystem](#included-plugins) is enabled, then the `utc` +- `cssClass`: A class name `string` that will be applied to the time system when +it appears in the UI. This will be used to represent the time system with an icon. +There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss), +or a custom class can be used here. +- `timeFormat`: A `string` corresponding to the key of a registered +[telemetry time format](#telemetry-formats). The format will be used for +displaying discrete timestamps from telemetry streams when this time system is +activated. If the [UTCTimeSystem](#included-plugins) is enabled, then the `utc` format can be used if this is a utc-based time system -* `durationFormat`: A `string` corresponding to the key of a registered -[telemetry time format](#telemetry-formats). The format will be used for -displaying time ranges, for example `00:15:00` might be used to represent a time +- `durationFormat`: A `string` corresponding to the key of a registered +[telemetry time format](#telemetry-formats). The format will be used for +displaying time ranges, for example `00:15:00` might be used to represent a time period of fifteen minutes. These are used by the Time Conductor plugin to specify -relative time offsets. If the [UTCTimeSystem](#included-plugins) is enabled, +relative time offsets. If the [UTCTimeSystem](#included-plugins) is enabled, then the `duration` format can be used if this is a utc-based time system -* `isUTCBased`: A `boolean` that defines whether this time system represents -numbers in UTC terrestrial time. +- `isUTCBased`: A `boolean` that defines whether this time system represents +numbers in UTC terrestrial time. #### Getting and Setting the Active Time System -Once registered, a time system can be activated by calling `timeSystem` with -the timeSystem `key` or an instance of the time system. If you are not using a -[clock](#clocks), you must also specify valid [bounds](#time-bounds) for the -timeSystem. +Once registered, a time system can be activated by calling `setTimeSystem` with +the timeSystem `key` or an instance of the time system. You can also specify +valid [bounds](#time-bounds) for the timeSystem. ```javascript -openmct.time.timeSystem('utc', bounds); +openmct.time.setTimeSystem('utc', bounds); ``` -A time system can be immediately activated after registration: +The current time system can be retrieved as well by calling `getTimeSystem`. + +```javascript +openmct.time.getTimeSystem(); +``` + +A time system can be immediately activated after registration: ```javascript openmct.time.addTimeSystem(utcTimeSystem); -openmct.time.timeSystem(utcTimeSystem, bounds); +openmct.time.setTimeSystem(utcTimeSystem, bounds); ``` -Setting the active time system will trigger a [`'timeSystem'`](#time-events) -event. If you supplied bounds, a [`'bounds'`](#time-events) event will be triggered afterwards with your newly supplied bounds. +Setting the active time system will trigger a [`'timeSystemChanged'`](#time-events) +event. If you supplied bounds, a [`'boundsChanged'`](#time-events) event will be triggered afterwards with your newly supplied bounds. + +> ⚠️ **Deprecated** +> - The method `timeSystem()` is deprecated. Please use `getTimeSystem()` and `setTimeSystem()` as a replacement. + + #### Time Bounds -The TimeAPI provides a getter/setter for querying and setting time bounds. Time +The TimeAPI provides a getter and setter for querying and setting time bounds. Time bounds are simply an object with a `start` and an end `end` attribute. -* `start`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems). +- `start`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems). This will be used as the beginning of the time period displayed by time-responsive telemetry views. -* `end`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems). +- `end`: A `number` representing a moment in time in the active [Time System](#defining-and-registering-time-systems). This will be used as the end of the time period displayed by time-responsive telemetry views. -If invoked with bounds, it will set the new time bounds system-wide. If invoked -without any parameters, it will return the current application-wide time bounds. +New bounds can be set system wide by calling `setBounds` with [bounds](#time-bounds). ``` javascript const ONE_HOUR = 60 * 60 * 1000; let now = Date.now(); -openmct.time.bounds({start: now - ONE_HOUR, now); +openmct.time.setBounds({start: now - ONE_HOUR, now); +``` + +Calling `getBounds` will return the current application-wide time bounds. + +``` javascript +openmct.time.getBounds(); ``` -To respond to bounds change events, listen for the [`'bounds'`](#time-events) +To respond to bounds change events, listen for the [`'boundsChanged'`](#time-events) event. +> ⚠️ **Deprecated** +> - The method `bounds()` is deprecated and will be removed in a future release. Please use `getBounds()` and `setBounds()` as a replacement. + ### Clocks -The Time API can be set to follow a clock source which will cause the bounds -to be updated automatically whenever the clock source "ticks". A clock is simply -an object that supports registration of listeners and periodically invokes its -listeners with a number. Open MCT supports registration of new clock sources that -tick on almost anything. A tick occurs when the clock invokes callback functions -registered by its listeners with a new time value. - -An example of a clock source is the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js) -which emits the current time in UTC every 100ms. Clocks can tick on anything. For -example, a clock could be defined to provide the timestamp of any new data -received via a telemetry subscription. This would have the effect of advancing -the bounds of views automatically whenever data is received. A clock could also +The Time API requires a clock source which will cause the bounds to be updated +automatically whenever the clock source "ticks". A clock is simply an object that +supports registration of listeners and periodically invokes its listeners with a +number. Open MCT supports registration of new clock sources that tick on almost +anything. A tick occurs when the clock invokes callback functions registered by its +listeners with a new time value. + +An example of a clock source is the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js) +which emits the current time in UTC every 100ms. Clocks can tick on anything. For +example, a clock could be defined to provide the timestamp of any new data +received via a telemetry subscription. This would have the effect of advancing +the bounds of views automatically whenever data is received. A clock could also be defined to tick on some remote timing source. The values provided by clocks are simple `number`s, which are interpreted in the @@ -742,32 +900,32 @@ context of the active [Time System](#defining-and-registering-time-systems). A clock is an object that defines certain required metadata and functions: -* `key`: A `string` uniquely identifying this clock. This can be used later to +- `key`: A `string` uniquely identifying this clock. This can be used later to reference the clock in places such as the [Time Conductor configuration](#time-conductor-configuration) -* `cssClass`: A `string` identifying a CSS class to apply to this clock when it's -displayed in the UI. This will be used to represent the time system with an icon. -There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss), -or a custom class can be used here. -* `name`: A `string` providing a human-readable identifier for the clock source. -This will be displayed in the clock selector menu in the Time Conductor UI -component, if active. -* `description`: An __optional__ `string` providing a longer description of the -clock. The description will be visible in the clock selection menu in the Time +- `cssClass`: A `string` identifying a CSS class to apply to this clock when it's +displayed in the UI. This will be used to represent the time system with an icon. +There are a number of built-in icon classes [available in Open MCT](https://github.com/nasa/openmct/blob/master/platform/commonUI/general/res/sass/_glyphs.scss), +or a custom class can be used here. +- `name`: A `string` providing a human-readable identifier for the clock source. +This will be displayed in the clock selector menu in the Time Conductor UI +component, if active. +- `description`: An **optional** `string` providing a longer description of the +clock. The description will be visible in the clock selection menu in the Time Conductor plugin. -* `on`: A `function` supporting registration of a new callback that will be +- `on`: A `function` supporting registration of a new callback that will be invoked when the clock next ticks. It will be invoked with two arguments: - * `eventName`: A `string` specifying the event to listen on. For now, clocks + - `eventName`: A `string` specifying the event to listen on. For now, clocks support one event - `tick`. - * `callback`: A `function` that will be invoked when this clock ticks. The + - `callback`: A `function` that will be invoked when this clock ticks. The function must be invoked with one parameter - a `number` representing a valid time in the current time system. -* `off`: A `function` that allows deregistration of a tick listener. It accepts +- `off`: A `function` that allows deregistration of a tick listener. It accepts the same arguments as `on`. -* `currentValue`: A `function` that returns a `number` representing a point in -time in the active time system. It should be the last value provided by a tick, +- `currentValue`: A `function` that returns a `number` representing a point in +time in the active time system. It should be the last value provided by a tick, or some default value if no ticking has yet occurred. -A new clock can be registered using the `addClock` function exposed by the Time +A new clock can be registered using the `addClock` function exposed by the Time API: ```javascript @@ -794,63 +952,128 @@ An example clock implementation is provided in the form of the [LocalClock](http #### Getting and setting active clock -Once registered a clock can be activated by calling the `clock` function on the -Time API passing in the key or instance of a registered clock. Only one clock -may be active at once, so activating a clock will deactivate any currently -active clock. [`clockOffsets`](#clock-offsets) must be specified when changing a clock. - -Setting the clock triggers a [`'clock'`](#time-events) event, followed by a [`'clockOffsets'`](#time-events) event, and then a [`'bounds'`](#time-events) event as the offsets are applied to the clock's currentValue(). +Once registered a clock can be activated by calling the `setClock` function on the +Time API passing in the key or instance of a registered clock. Only one clock +may be active at once, so activating a clock will deactivate any currently +active clock and start the new clock. [`clockOffsets`](#clock-offsets) must be specified when changing a clock. +Setting the clock triggers a [`'clockChanged'`](#time-events) event, followed by a [`'clockOffsetsChanged'`](#time-events) event, and then a [`'boundsChanged'`](#time-events) event as the offsets are applied to the clock's currentValue(). ``` -openmct.time.clock(someClock, clockOffsets); +openmct.time.setClock(someClock, clockOffsets); ``` Upon being activated, the time API will listen for tick events on the clock by calling `clock.on`. -The currently active clock (if any) can be retrieved by calling the same -function without any arguments. +The currently active clock can be retrieved by calling `getClock`. + +``` +openmct.time.getClock(); +``` -#### Stopping an active clock +> ⚠️ **Deprecated** +> - The method `clock()` is deprecated and will be removed in a future release. Please use `getClock()` and `setClock()` as a replacement. -The `stopClock` method can be used to stop an active clock, and to clear it. It +#### ⚠️ [DEPRECATED] Stopping an active clock + +_As of July 2023, this method will be deprecated. Open MCT will always have a ticking clock._ + +The `stopClock` method can be used to stop an active clock, and to clear it. It will stop the clock from ticking, and set the active clock to `undefined`. ``` javascript openmct.time.stopClock(); ``` +> ⚠️ **Deprecated** +> - The method `stopClock()` is deprecated and will be removed in a future release. + #### Clock Offsets -When a clock is active, the time bounds of the application will be updated -automatically each time the clock "ticks". The bounds are calculated based on -the current value provided by the active clock (via its `tick` event, or its -`currentValue()` method). +When in Real-time [mode](#time-modes), the time bounds of the application will be updated automatically each time the +clock "ticks". The bounds are calculated based on the current value provided by +the active clock (via its `tick` event, or its `currentValue()` method). Unlike bounds, which represent absolute time values, clock offsets represent relative time spans. Offsets are defined as an object with two properties: -* `start`: A `number` that must be < 0 and which is used to calculate the start -bounds on each clock tick. The start offset will be calculated relative to the +- `start`: A `number` that must be < 0 and which is used to calculate the start +bounds on each clock tick. The start offset will be calculated relative to the value provided by a clock's tick callback, or its `currentValue()` function. -* `end`: A `number` that must be >= 0 and which is used to calculate the end +- `end`: A `number` that must be >= 0 and which is used to calculate the end bounds on each clock tick. -The `clockOffsets` function can be used to get or set clock offsets. For example, -to show the last fifteen minutes in a ms-based time system: +The `setClockOffsets` function can be used to get or set clock offsets. For example, +to show the last fifteen minutes in a ms-based time system: ```javascript var FIFTEEN_MINUTES = 15 * 60 * 1000; -openmct.time.clockOffsets({ +openmct.time.setClockOffsets({ start: -FIFTEEN_MINUTES, end: 0 }) ``` -__Note:__ Setting the clock offsets will trigger an immediate bounds change, as -new bounds will be calculated based on the `currentValue()` of the active clock. -Clock offsets are only relevant when a clock source is active. +The `getClockOffsets` method will return the currently set clock offsets. + +```javascript +openmct.time.getClockOffsets() +``` + +**Note:** Setting the clock offsets will trigger an immediate bounds change, as +new bounds will be calculated based on the `currentValue()` of the active clock. +Clock offsets are only relevant when in Real-time [mode](#time-modes). + +> ⚠️ **Deprecated** +> - The method `clockOffsets()` is deprecated and will be removed in a future release. Please use `getClockOffsets()` and `setClockOffsets()` as a replacement. + +### Time Modes + +There are two time modes in Open MCT, "Fixed" and "Real-time". In Real-time mode the +time bounds of the application will be updated automatically each time the clock "ticks". +The bounds are calculated based on the current value provided by the active clock. In +Fixed mode, the time bounds are set for a specified time range. When Open MCT is first +initialized, it will be in Real-time mode. + +The `setMode` method can be used to set the current time mode. It accepts a mode argument, +`'realtime'` or `'fixed'` and it also accepts an optional [offsets](#clock-offsets)/[bounds](#time-bounds) argument dependent +on the current mode. + +``` javascript +openmct.time.setMode('fixed'); +openmct.time.setMode('fixed', bounds); // with optional bounds +``` + +or + +``` javascript +openmct.time.setMode('realtime'); +openmct.time.setMode('realtime', offsets); // with optional offsets +``` + +The `getMode` method will return the current time mode, either `'realtime'` or `'fixed'`. + +``` javascript +openmct.time.getMode(); +``` + +#### Time Mode Helper Methods + +There are two methods available to determine the current time mode in Open MCT programmatically, +`isRealTime` and `isFixed`. Each one will return a boolean value based on the current mode. + +``` javascript +if (openmct.time.isRealTime()) { + // do real-time stuff +} +``` + +``` javascript +if (openmct.time.isFixed()) { + // do fixed-time stuff +} +``` ### Time Events @@ -859,7 +1082,7 @@ The Time API is a standard event emitter; you can register callbacks for events For example: ``` javascript -openmct.time.on('bounds', function callback (newBounds, tick) { +openmct.time.on('boundsChanged', function callback (newBounds, tick) { // Do something with new bounds }); ``` @@ -868,89 +1091,97 @@ openmct.time.on('bounds', function callback (newBounds, tick) { The events emitted by the Time API are: -* `bounds`: emitted whenever the bounds change. The callback will be invoked +- `boundsChanged`: emitted whenever the bounds change. The callback will be invoked with two arguments: - * `bounds`: A [bounds](#getting-and-setting-bounds) bounds object + - `bounds`: A [bounds](#getting-and-setting-bounds) bounds object representing a new time period bound by the specified start and send times. - * `tick`: A `boolean` indicating whether or not this bounds change is due to - a "tick" from a [clock source](#clocks). This information can be useful - when determining a strategy for fetching telemetry data in response to a - bounds change event. For example, if the bounds change was automatic, and - is due to a tick then it's unlikely that you would need to perform a - historical data query. It should be sufficient to just show any new - telemetry received via subscription since the last tick, and optionally to - discard any older data that now falls outside of the currently set bounds. - If `tick` is false,then the bounds change was not due to an automatic tick, - and a query for historical data may be necessary, depending on your data + - `tick`: A `boolean` indicating whether or not this bounds change is due to + a "tick" from a [clock source](#clocks). This information can be useful + when determining a strategy for fetching telemetry data in response to a + bounds change event. For example, if the bounds change was automatic, and + is due to a tick then it's unlikely that you would need to perform a + historical data query. It should be sufficient to just show any new + telemetry received via subscription since the last tick, and optionally to + discard any older data that now falls outside of the currently set bounds. + If `tick` is false,then the bounds change was not due to an automatic tick, + and a query for historical data may be necessary, depending on your data caching strategy, and how significantly the start bound has changed. -* `timeSystem`: emitted whenever the active time system changes. The callback will be invoked with a single argument: - * `timeSystem`: The newly active [time system](#defining-and-registering-time-systems). -* `clock`: emitted whenever the clock changes. The callback will be invoked +- `timeSystemChanged`: emitted whenever the active time system changes. The callback will be invoked with a single argument: + - `timeSystem`: The newly active [time system](#defining-and-registering-time-systems). +- `clockChanged`: emitted whenever the clock changes. The callback will be invoked with a single argument: - * `clock`: The newly active [clock](#clocks), or `undefined` if an active + - `clock`: The newly active [clock](#clocks), or `undefined` if an active clock has been deactivated. -* `clockOffsets`: emitted whenever the active clock offsets change. The +- `clockOffsetsChanged`: emitted whenever the active clock offsets change. The callback will be invoked with a single argument: - * `clockOffsets`: The new [clock offsets](#clock-offsets). + - `clockOffsets`: The new [clock offsets](#clock-offsets). +- `modeChanged`: emitted whenever the time [mode](#time-modes) changed. The callback will + be invoked with one argument: + - `mode`: A string representation of the current time mode, either `'realtime'` or `'fixed'`. +> ⚠️ **Deprecated Events** (These will be removed in a future release): +> - `bounds` → `boundsChanged` +> - `timeSystem` → `timeSystemChanged` +> - `clock` → `clockChanged` +> - `clockOffsets` → `clockOffsetsChanged` ### The Time Conductor -The Time Conductor provides a user interface for managing time bounds in Open +The Time Conductor provides a user interface for managing time bounds in Open MCT. It allows a user to select from configured time systems and clocks, and to set bounds and clock offsets. -If activated, the time conductor must be provided with configuration options, +If activated, the time conductor must be provided with configuration options, detailed below. #### Time Conductor Configuration -The time conductor is configured by specifying the options that will be -available to the user from the menus in the time conductor. These will determine -the clocks available from the conductor, the time systems available for each -clock, and some default bounds and clock offsets for each combination of clock -and time system. By default, the conductor always supports a `fixed` mode where +The time conductor is configured by specifying the options that will be +available to the user from the menus in the time conductor. These will determine +the clocks available from the conductor, the time systems available for each +clock, and some default bounds and clock offsets for each combination of clock +and time system. By default, the conductor always supports a `fixed` mode where no clock is active. To specify configuration for fixed mode, simply leave out a `clock` attribute in the configuration entry object. -Configuration is provided as an `array` of menu options. Each entry of the +Configuration is provided as an `array` of menu options. Each entry of the array is an object with some properties specifying configuration. The configuration -options specified are slightly different depending on whether or not it is for +options specified are slightly different depending on whether or not it is for an active clock mode. -__Configuration for Fixed Time Mode (no active clock)__ +**Configuration for Fixed Time Mode (no active clock)** -* `timeSystem`: A `string`, the key for the time system that this configuration +- `timeSystem`: A `string`, the key for the time system that this configuration relates to. -* `bounds`: A [`Time Bounds`](#time-bounds) object. These bounds will be applied -when the user selects the time system specified in the previous `timeSystem` +- `bounds`: A [`Time Bounds`](#time-bounds) object. These bounds will be applied +when the user selects the time system specified in the previous `timeSystem` property. -* `zoomOutLimit`: An __optional__ `number` specifying the longest period of time -that can be represented by the conductor when zooming. If a `zoomOutLimit` is -provided, then a `zoomInLimit` must also be provided. If provided, the zoom +- `zoomOutLimit`: An **optional** `number` specifying the longest period of time +that can be represented by the conductor when zooming. If a `zoomOutLimit` is +provided, then a `zoomInLimit` must also be provided. If provided, the zoom slider will automatically become available in the Time Conductor UI. -* `zoomInLimit`: An __optional__ `number` specifying the shortest period of time -that can be represented by the conductor when zooming. If a `zoomInLimit` is -provided, then a `zoomOutLimit` must also be provided. If provided, the zoom +- `zoomInLimit`: An **optional** `number` specifying the shortest period of time +that can be represented by the conductor when zooming. If a `zoomInLimit` is +provided, then a `zoomOutLimit` must also be provided. If provided, the zoom slider will automatically become available in the Time Conductor UI. -__Configuration for Active Clock__ +**Configuration for Active Clock** -* `clock`: A `string`, the `key` of the clock that this configuration applies to. -* `timeSystem`: A `string`, the key for the time system that this configuration -relates to. Separate configuration must be provided for each time system that you +- `clock`: A `string`, the `key` of the clock that this configuration applies to. +- `timeSystem`: A `string`, the key for the time system that this configuration +relates to. Separate configuration must be provided for each time system that you wish to be available to users when they select the specified clock. -* `clockOffsets`: A [`clockOffsets`](#clock-offsets) object that will be -automatically applied when the combination of clock and time system specified in +- `clockOffsets`: A [`clockOffsets`](#clock-offsets) object that will be +automatically applied when the combination of clock and time system specified in this configuration is selected from the UI. #### Example conductor configuration -An example time conductor configuration is provided below. It sets up some -default options for the [UTCTimeSystem](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/UTCTimeSystem.js) -and [LocalTimeSystem](https://github.com/nasa/openmct/blob/master/src/plugins/localTimeSystem/LocalTimeSystem.js), -in both fixed mode, and for the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js) -source. In this configutation, the local clock supports both the UTCTimeSystem -and LocalTimeSystem. Configuration for fixed bounds mode is specified by omitting +An example time conductor configuration is provided below. It sets up some +default options for the [UTCTimeSystem](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/UTCTimeSystem.js) +and [LocalTimeSystem](https://github.com/nasa/openmct/blob/master/src/plugins/localTimeSystem/LocalTimeSystem.js), +in both fixed mode, and for the [LocalClock](https://github.com/nasa/openmct/blob/master/src/plugins/utcTimeSystem/LocalClock.js) +source. In this configutation, the local clock supports both the UTCTimeSystem +and LocalTimeSystem. Configuration for fixed bounds mode is specified by omitting a clock key. ``` javascript @@ -986,26 +1217,27 @@ openmct.install(openmct.plugins.Conductor({ ## Indicators -Indicators are small widgets that reside at the bottom of the screen and are visible from +Indicators are small widgets that reside at the bottom of the screen and are visible from every screen in Open MCT. They can be used to convey system state using an icon and text. -Typically an indicator will display an icon (customizable with a CSS class) that will +Typically an indicator will display an icon (customizable with a CSS class) that will reveal additional information when the mouse cursor is hovered over it. ### The URL Status Indicator -A common use case for indicators is to convey the state of some external system such as a -persistence backend or HTTP server. So long as this system is accessible via HTTP request, -Open MCT provides a general purpose indicator to show whether the server is available and -returing a 2xx status code. The URL Status Indicator is made available as a default plugin. See -the [documentation](./src/plugins/URLIndicatorPlugin) for details on how to install and configure the +A common use case for indicators is to convey the state of some external system such as a +persistence backend or HTTP server. So long as this system is accessible via HTTP request, +Open MCT provides a general purpose indicator to show whether the server is available and +returning a 2xx status code. The URL Status Indicator is made available as a default plugin. See +the [documentation](./src/plugins/URLIndicatorPlugin) for details on how to install and configure the URL Status Indicator. ### Creating a Simple Indicator -A simple indicator with an icon and some text can be created and added with minimal code. An indicator +A simple indicator with an icon and some text can be created and added with minimal code. An indicator of this type exposes functions for customizing the text, icon, and style of the indicator. eg. + ``` javascript var myIndicator = openmct.indicators.simpleIndicator(); myIndicator.text("Hello World!"); @@ -1014,24 +1246,24 @@ openmct.indicators.add(myIndicator); This will create a new indicator and add it to the bottom of the screen in Open MCT. By default, the indicator will appear as an information icon. Hovering over the icon will -reveal the text set via the call to `.text()`. The Indicator object returned by the API +reveal the text set via the call to `.text()`. The Indicator object returned by the API call exposes a number of functions for customizing the content and appearance of the indicator: -* `.text([text])`: Gets or sets the text shown when the user hovers over the indicator. -Accepts an __optional__ `string` argument that, if provided, will be used to set the text. -Hovering over the indicator will expand it to its full size, revealing this text alongside +- `.text([text])`: Gets or sets the text shown when the user hovers over the indicator. +Accepts an **optional** `string` argument that, if provided, will be used to set the text. +Hovering over the indicator will expand it to its full size, revealing this text alongside the icon. Returns the currently set text as a `string`. -* `.description([description])`: Gets or sets the indicator's description. Accepts an -__optional__ `string` argument that, if provided, will be used to set the text. The description -allows for more detail to be provided in a tooltip when the user hovers over the indicator. +- `.description([description])`: Gets or sets the indicator's description. Accepts an +**optional** `string` argument that, if provided, will be used to set the text. The description +allows for more detail to be provided in a tooltip when the user hovers over the indicator. Returns the currently set text as a `string`. -* `.iconClass([className])`: Gets or sets the CSS class used to define the icon. Accepts an __optional__ -`string` parameter to be used to set the class applied to the indicator. Any of -[the built-in glyphs](https://nasa.github.io/openmct/style-guide/#/browse/styleguide:home/glyphs?view=styleguide.glyphs) -may be used here, or a custom CSS class can be provided. Returns the currently defined CSS +- `.iconClass([className])`: Gets or sets the CSS class used to define the icon. Accepts an **optional** +`string` parameter to be used to set the class applied to the indicator. Any of +[the built-in glyphs](https://nasa.github.io/openmct/style-guide/#/browse/styleguide:home/glyphs?view=styleguide.glyphs) +may be used here, or a custom CSS class can be provided. Returns the currently defined CSS class as a `string`. -* `.statusClass([className])`: Gets or sets the CSS class used to determine status. Accepts an __optional __ -`string` parameter to be used to set a status class applied to the indicator. May be used to apply +- `.statusClass([className])`: Gets or sets the CSS class used to determine status. Accepts an __optional__ +`string` parameter to be used to set a status class applied to the indicator. May be used to apply different colors to indicate status. ### Custom Indicators @@ -1049,3 +1281,84 @@ A completely custom indicator can be added by simply providing a DOM element to element: domNode }); ``` + +## Priority API + +Open MCT provides some built-in priority values that can be used in the application for view providers, indicators, root object order, and more. + +### Priority Types + +Currently, the Open MCT Priority API provides (type: numeric value): + +- HIGH: 1000 +- Default: 0 +- LOW: -1000 + +View provider Example: + +``` javascript + class ViewProvider { + ... + priority() { + return openmct.priority.HIGH; + } +} +``` + +## Visibility-Based Rendering in View Providers + +To enhance performance and resource efficiency in OpenMCT, a visibility-based rendering feature has been added. This feature is designed to defer the execution of rendering logic for views that are not currently visible. It ensures that views are only updated when they are in the viewport, similar to how modern browsers handle rendering of inactive tabs but optimized for the OpenMCT tabbed display. It also works when views are scrolled outside the viewport (e.g., in a Display Layout). + +### Overview + +The show function is responsible for the rendering of a view. An [Intersection Observer](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) is used internally to determine whether the view is visible. This observer drives the visibility-based rendering feature, accessed via the `renderWhenVisible` function provided in the `viewOptions` parameter. + +### Implementing Visibility-Based Rendering + +The `renderWhenVisible` function is passed to the show function as part of the `viewOptions` object. This function can be used for all rendering logic that would otherwise be executed within a `requestAnimationFrame` call. When called, `renderWhenVisible` will either execute the provided function immediately (via `requestAnimationFrame`) if the view is currently visible, or defer its execution until the view becomes visible. + +Additionally, `renderWhenVisible` returns a boolean value indicating whether the provided function was executed immediately (`true`) or deferred (`false`). + +Monitoring of visibility begins after the first call to `renderWhenVisible` is made. + +Here’s the signature for the show function: + +`show(element, isEditing, viewOptions)` + + * `element` (HTMLElement) - The DOM element where the view should be rendered. + * `isEditing` (boolean) - Indicates whether the view is in editing mode. + * `viewOptions` (Object) - An object with configuration options for the view, including: + * `renderWhenVisible` (Function) - This function wraps the `requestAnimationFrame` and only triggers the provided render logic when the view is visible in the viewport. + +### Example + +An OpenMCT view provider might implement the show function as follows: + +```js +// Define your view provider +const myViewProvider = { + // ... other properties and methods ... + show: function (element, isEditing, viewOptions) { + // Callback for rendering view content + const renderCallback = () => { + // Your view rendering logic goes here + }; + + // Use the renderWhenVisible function to ensure rendering only happens when view is visible + const wasRenderedImmediately = viewOptions.renderWhenVisible(renderCallback); + + // Optionally handle the immediate rendering return value + if (wasRenderedImmediately) { + console.debug('🪞 Rendering triggered immediately as the view is visible.'); + } else { + console.debug('🛑 Rendering has been deferred until the view becomes visible.'); + } + } +}; +``` + + +Note that `renderWhenVisible` defers rendering while the view is not visible and caters to the latest execution call. This provides responsiveness for dynamic content while ensuring performance optimizations. + +Ensure your view logic is prepared to handle potentially multiple deferrals if using this API, as only the last call to renderWhenVisible will be queued for execution upon the view becoming visible. + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c3ad0ec1d3a..674059c34de 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ accept changes from external contributors. The short version: -1. Write your contribution or describe your idea in the form of an [GitHub issue](https://github.com/nasa/openmct/issues/new/choose) or [Starting a GitHub Discussion](https://github.com/nasa/openmct/discussions) +1. Write your contribution or describe your idea in the form of a [GitHub issue](https://github.com/nasa/openmct/issues/new/choose) or [start a GitHub discussion](https://github.com/nasa/openmct/discussions). 2. Make sure your contribution meets code, test, and commit message standards as described below. 3. Submit a pull request from a topic branch back to `master`. Include a check @@ -18,13 +18,13 @@ The short version: for review.) 4. Respond to any discussion. When the reviewer decides it's ready, they will merge back `master` and fill out their own check list. -5. If you are a first-time contributor, please see [this discussion](https://github.com/nasa/openmct/discussions/3821) for further information. +5. If you are a first-time contributor, please see [this discussion](https://github.com/nasa/openmct/discussions/3821) for further information. ## Contribution Process Open MCT uses git for software version control, and for branching and merging. The central repository is at -https://github.com/nasa/openmct.git. +. ### Roles @@ -116,6 +116,7 @@ the pull request containing the reviewer checklist (from below) and complete the merge back to the master branch. Additionally: + * Every pull request must link to the issue that it addresses. Eg. “Addresses #1234” or “Closes #1234”. This is the responsibility of the pull request’s __author__. If no issue exists, [create one](https://github.com/nasa/openmct/issues/new/choose). * Every __author__ must include testing instructions. These instructions should identify the areas of code affected, and some minimal test steps. If addressing a bug, reproduction steps should be included, if they were not included in the original issue. If reproduction steps were included on the original issue, and are sufficient, refer to them. * A pull request that closes an issue should say so in the description. Including the text “Closes #1234” will cause the linked issue to be automatically closed when the pull request is merged. This is the responsibility of the pull request’s __author__. @@ -132,25 +133,26 @@ changes. ### Code Standards -JavaScript sources in Open MCT must satisfy the ESLint rules defined in -this repository. This is verified by the command line build. +JavaScript sources in Open MCT must satisfy the [ESLint](https://eslint.org/) rules defined in +this repository. [Prettier](https://prettier.io/) is used in conjunction with ESLint to enforce code style +via automated formatting. These are verified by the command line build. #### Code Guidelines The following guidelines are provided for anyone contributing source code to the Open MCT project: -1. Write clean code. Here’s a good summary - https://github.com/ryanmcdermott/clean-code-javascript. +1. Write clean code. Here’s a good summary - . 1. Include JSDoc for any exposed API (e.g. public methods, classes). 1. Include non-JSDoc comments as-needed for explaining private variables, - methods, or algorithms when they are non-obvious. Otherwise code + methods, or algorithms when they are non-obvious. Otherwise code should be self-documenting. 1. Classes and Vue components should use camel case, first letter capitalized (e.g. SomeClassName). 1. Methods, variables, fields, events, and function names should use camelCase, first letter lower-case (e.g. someVariableName). 1. Source files that export functions should use camelCase, first letter lower-case (eg. testTools.js) -1. Constants (variables or fields which are meant to be declared and - initialized statically, and never changed) should use only capital +1. Constants (variables or fields which are meant to be declared and + initialized statically, and never changed) should use only capital letters, with underscores between words (e.g. SOME_CONSTANT). They should always be declared as `const`s 1. File names should be the name of the exported class, plus a .js extension (e.g. SomeClassName.js). @@ -159,21 +161,25 @@ The following guidelines are provided for anyone contributing source code to the (e.g. as arguments to a forEach call). Anonymous functions should always be arrow functions. 1. Named functions are preferred over functions assigned to variables. eg. + ```JavaScript function renameObject(object, newName) { Object.name = newName; } ``` + is preferable to + ```JavaScript const rename = (object, newName) => { Object.name = newName; } ``` + 1. Avoid deep nesting (especially of functions), except where necessary (e.g. due to closure scope). 1. End with a single new-line character. -1. Always use ES6 `Class`es and inheritence rather than the pre-ES6 prototypal +1. Always use ES6 `Class`es and inheritance rather than the pre-ES6 prototypal pattern. 1. Within a given function's scope, do not mix declarations and imperative code, and present these in the following order: @@ -182,19 +188,24 @@ The following guidelines are provided for anyone contributing source code to the * Finally, the returned value. A single return statement at the end of the function should be used, except where an early return would improve code clarity. 1. Avoid the use of "magic" values. eg. + ```JavaScript const UNAUTHORIZED = 401; if (responseCode === UNAUTHORIZED) ``` + is preferable to + ```JavaScript if (responseCode === 401) ``` + 1. Use the ternary operator only for simple cases such as variable assignment. Nested ternaries should be avoided in all cases. -1. Test specs should reside alongside the source code they test, not in a separate directory. +1. Unit Test specs should reside alongside the source code they test, not in a separate directory. 1. Organize code by feature, not by type. eg. - ``` + + ```txt - telemetryTable - row TableRow.js @@ -206,8 +217,10 @@ The following guidelines are provided for anyone contributing source code to the plugin.js pluginSpec.js ``` + is preferable to - ``` + + ```txt - telemetryTable - components TableRow.vue @@ -219,47 +232,10 @@ The following guidelines are provided for anyone contributing source code to the plugin.js pluginSpec.js ``` + Deviations from Open MCT code style guidelines require two-party agreement, typically from the author of the change and its reviewer. -### Test Standards - -Automated testing shall occur whenever changes are merged into the main -development branch and must be confirmed alongside any pull request. - -Automated tests are tests which exercise plugins, API, and utility classes. -Tests are subject to code review along with the actual implementation, to -ensure that tests are applicable and useful. - -Examples of useful tests: -* Tests which replicate bugs (or their root causes) to verify their - resolution. -* Tests which reflect details from software specifications. -* Tests which exercise edge or corner cases among inputs. -* Tests which verify expected interactions with other components in the - system. - -#### Guidelines -* 100% statement coverage is achievable and desirable. -* Do blackbox testing. Test external behaviors, not internal details. Write tests that describe what your plugin is supposed to do. How it does this doesn't matter, so don't test it. -* Unit test specs for plugins should be defined at the plugin level. Start with one test spec per plugin named pluginSpec.js, and as this test spec grows too big, break it up into multiple test specs that logically group related tests. -* Unit tests for API or for utility functions and classes may be defined at a per-source file level. -* Wherever possible only use and mock public API, builtin functions, and UI in your test specs. Do not directly invoke any private functions. ie. only call or mock functions and objects exposed by openmct.* (eg. openmct.telemetry, openmct.objectView, etc.), and builtin browser functions (fetch, requestAnimationFrame, setTimeout, etc.). -* Where builtin functions have been mocked, be sure to clear them between tests. -* Test at an appropriate level of isolation. Eg. - * If you’re testing a view, you do not need to test the whole application UI, you can just fetch the view provider using the public API and render the view into an element that you have created. - * You do not need to test that the view switcher works, there should be separate tests for that. - * You do not need to test that telemetry providers work, you can mock openmct.telemetry.request() to feed test data to the view. - * Use your best judgement when deciding on appropriate scope. -* Automated tests for plugins should start by actually installing the plugin being tested, and then test that installing the plugin adds the desired features and behavior to Open MCT, observing the above rules. -* All variables used in a test spec, including any instances of the Open MCT API should be declared inside of an appropriate block scope (not at the root level of the source file), and should be initialized in the relevant beforeEach block. `beforeEach` is preferable to `beforeAll` to avoid leaking of state between tests. -* A `afterEach` or `afterAll` should be used to do any clean up necessary to prevent leakage of state between test specs. This can happen when functions on `window` are wrapped, or when the URL is changed. [A convenience function](https://github.com/nasa/openmct/blob/master/src/utils/testing.js#L59) is provided for resetting the URL and clearing builtin spies between tests. -* If writing unit tests for legacy Angular code be sure to follow [best practices in order to avoid memory leaks](https://www.thecodecampus.de/blog/avoid-memory-leaks-angularjs-unit-tests/). - -#### Examples -* [Example of an automated test spec for an object view plugin](https://github.com/nasa/openmct/blob/master/src/plugins/telemetryTable/pluginSpec.js) -* [Example of an automated test spec for API](https://github.com/nasa/openmct/blob/master/src/api/time/TimeAPISpec.js) - ### Commit Message Standards Commit messages should: @@ -295,13 +271,13 @@ these standards. ## Issue Reporting -Issues are tracked at https://github.com/nasa/openmct/issues. +Issues are tracked at . Issue severity is categorized as follows (in ascending order): * _Trivial_: Minimal impact on the usefulness and functionality of the software; a "nice-to-have." Visual impact without functional impact, * _Medium_: Some impairment of use, but simple workarounds exist -* _Critical_: Significant loss of functionality or impairment of use. Display of telemetry data is not affected though. +* _Critical_: Significant loss of functionality or impairment of use. Display of telemetry data is not affected though. Complex workarounds exist. * _Blocker_: Major functionality is impaired or lost, threatening mission success. Display of telemetry data is impaired or blocked by the bug, which could lead to loss of situational awareness. ## Check Lists @@ -310,21 +286,4 @@ The following check lists should be completed and attached to pull requests when they are filed (author checklist) and when they are merged (reviewer checklist). -### Author Checklist - [Within PR Template](.github/PULL_REQUEST_TEMPLATE.md) - -### Reviewer Checklist - -* [ ] Changes appear to address issue? -* [ ] Appropriate unit tests included? -* [ ] Code style and in-line documentation are appropriate? -* [ ] Commit messages meet standards? -* [ ] Has associated issue been labelled `unverified`? (only applicable if this PR closes the issue) -* [ ] Has associated issue been labelled `bug`? (only applicable if this PR is for a bug fix) -* [ ] List of Acceptance Tests Performed. - -Write out a small list of tests performed with just enough detail for another developer on the team -to execute. - -i.e. ```When Clicking on Add button, new `object` appears in dropdown.``` \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index 04d36576a28..6f5fecba6c3 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # Open MCT License -Open MCT, Copyright (c) 2014-2021, United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All rights reserved. +Open MCT, Copyright (c) 2014-2024, United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All rights reserved. Open MCT is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. diff --git a/Procfile b/Procfile deleted file mode 100644 index 1e13b4ae057..00000000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: node app.js --port $PORT diff --git a/README.md b/README.md index 77a573cede8..78335fbb99c 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,49 @@ -# Open MCT [![license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/nasa/openmct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/nasa/openmct/context:javascript) +# Open MCT [![license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) [![codecov](https://codecov.io/gh/nasa/openmct/branch/master/graph/badge.svg?token=7DQIipp3ej)](https://codecov.io/gh/nasa/openmct) [![This project is using Percy.io for visual regression testing.](https://percy.io/static/images/percy-badge.svg)](https://percy.io/b2e34b17/openmct) [![npm version](https://img.shields.io/npm/v/openmct.svg)](https://www.npmjs.com/package/openmct) ![CodeQL](https://github.com/nasa/openmct/workflows/CodeQL/badge.svg) Open MCT (Open Mission Control Technologies) is a next-generation mission control framework for visualization of data on desktop and mobile devices. It is developed at NASA's Ames Research Center, and is being used by NASA for data analysis of spacecraft missions, as well as planning and operation of experimental rover systems. As a generalizable and open source framework, Open MCT could be used as the basis for building applications for planning, operation, and analysis of any systems producing telemetry data. -Please visit our [Official Site](https://nasa.github.io/openmct/) and [Getting Started Guide](https://nasa.github.io/openmct/getting-started/) +> [!NOTE] +> Please visit our [Official Site](https://nasa.github.io/openmct/) and [Getting Started Guide](https://nasa.github.io/openmct/getting-started/) + Once you've created something amazing with Open MCT, showcase your work in our GitHub Discussions [Show and Tell](https://github.com/nasa/openmct/discussions/categories/show-and-tell) section. We love seeing unique and wonderful implementations of Open MCT! -## See Open MCT in Action +![Screen Shot 2022-11-23 at 9 51 36 AM](https://user-images.githubusercontent.com/4215777/203617422-4d912bfc-766f-4074-8324-409d9bbe7c05.png) -Try Open MCT now with our [live demo](https://openmct-demo.herokuapp.com/). -![Demo](https://nasa.github.io/openmct/static/res/images/Open-MCT.Browse.Layout.Mars-Weather-1.jpg) ## Building and Running Open MCT Locally Building and running Open MCT in your local dev environment is very easy. Be sure you have [Git](https://git-scm.com/downloads) and [Node.js](https://nodejs.org/) installed, then follow the directions below. Need additional information? Check out the [Getting Started](https://nasa.github.io/openmct/getting-started/) page on our website. (These instructions assume you are installing as a non-root user; developers have [reported issues](https://github.com/nasa/openmct/issues/1151) running these steps with root privileges.) -1. Clone the source code +1. Clone the source code: + +``` +git clone https://github.com/nasa/openmct.git +``` - `git clone https://github.com/nasa/openmct.git` +2. (Optional) Install the correct node version using [nvm](https://github.com/nvm-sh/nvm): -2. Install development dependencies +``` +nvm install +``` - `npm install` +3. Install development dependencies (Note: Check the `package.json` engine for our tested and supported node versions): -3. Run a local development server +``` +npm install +``` - `npm start` +4. Run a local development server: -Open MCT is now running, and can be accessed by pointing a web browser at [http://localhost:8080/](http://localhost:8080/) +``` +npm start +``` -## Open MCT v1.0.0 -This represents a major overhaul of Open MCT with significant changes under the hood. We aim to maintain backward compatibility but if you do find compatibility issues, please let us know by filing an issue in this repository. If you are having major issues with v1.0.0 please check-out the v0.14.0 tag until we can resolve them for you. +> [!IMPORTANT] +> Open MCT is now running, and can be accessed by pointing a web browser at [http://localhost:8080/](http://localhost:8080/) -If you are migrating an application built with Open MCT as a dependency to v1.0.0 from an earlier version, please refer to [our migration guide](https://nasa.github.io/openmct/documentation/migration-guide). +Open MCT is built using [`npm`](http://npmjs.com/) and [`webpack`](https://webpack.js.org/). ## Documentation @@ -45,14 +55,24 @@ The clearest examples for developing Open MCT plugins are in the [tutorials](https://github.com/nasa/openmct-tutorial) provided in our documentation. -We want Open MCT to be as easy to use, install, run, and develop for as -possible, and your feedback will help us get there! Feedback can be provided via [GitHub issues](https://github.com/nasa/openmct/issues/new/choose), [Starting a GitHub Discussion](https://github.com/nasa/openmct/discussions), or by emailing us at [arc-dl-openmct@mail.nasa.gov](mailto:arc-dl-openmct@mail.nasa.gov). +> [!NOTE] +> We want Open MCT to be as easy to use, install, run, and develop for as +> possible, and your feedback will help us get there! +> Feedback can be provided via [GitHub issues](https://github.com/nasa/openmct/issues/new/choose), +> [Starting a GitHub Discussion](https://github.com/nasa/openmct/discussions), +> or by emailing us at [arc-dl-openmct@mail.nasa.gov](mailto:arc-dl-openmct@mail.nasa.gov). -## Building Applications With Open MCT +## Developing Applications With Open MCT -Open MCT is built using [`npm`](http://npmjs.com/) and [`webpack`](https://webpack.js.org/). +For more on developing with Open MCT, see our documentation for a guide on [Developing Applications with Open MCT](./API.md#starting-an-open-mct-application). -See our documentation for a guide on [building Applications with Open MCT](https://github.com/nasa/openmct/blob/master/API.md#starting-an-open-mct-application). +## Compatibility + +This is a fast moving project and we do our best to test and support the widest possible range of browsers, operating systems, and nodejs APIs. We have a published list of support available in our package.json's `browserslist` key. + +The project uses `nvm` to ensure the node and npm version used, is coherent in all projects. Install nvm (non-windows), [here](https://github.com/nvm-sh/nvm) or the windows equivalent [here](https://github.com/coreybutler/nvm-windows) + +If you encounter an issue with a particular browser, OS, or nodejs API, please file a [GitHub issue](https://github.com/nasa/openmct/issues/new/choose) ## Plugins @@ -63,11 +83,14 @@ that is intended to be added or removed as a single unit. As well as providing an extension mechanism, most of the core Open MCT codebase is also written as plugins. -For information on writing plugins, please see [our API documentation](https://github.com/nasa/openmct/blob/master/API.md#plugins). +For information on writing plugins, please see [our API documentation](./API.md#plugins). ## Tests -Tests are written for [Jasmine 3](https://jasmine.github.io/api/3.1/global) +Our automated test coverage comes in the form of unit, e2e, visual, performance, and security tests. + +### Unit Tests +Unit Tests are written for [Jasmine](https://jasmine.github.io/api/edge/global) and run by [Karma](http://karma-runner.github.io). To run: `npm test` @@ -76,14 +99,35 @@ The test suite is configured to load any scripts ending with `Spec.js` found in the `src` hierarchy. Full configuration details are found in `karma.conf.js`. By convention, unit test scripts should be located alongside the units that they test; for example, `src/foo/Bar.js` would be -tested by `src/foo/BarSpec.js`. (For legacy reasons, some existing tests may -be located in separate `test` folders near the units they test, but the -naming convention is otherwise the same.) +tested by `src/foo/BarSpec.js`. + +### e2e, Visual, and Performance tests +The e2e, Visual, and Performance tests are written for playwright and run by playwright's new test runner [@playwright/test](https://playwright.dev/). + +To run the e2e tests which are part of every commit: + +`npm run test:e2e:stable` + +To run the visual test suite: + +`npm run test:e2e:visual` + +To run the performance tests: + +`npm run test:perf` -### Test Reporting +The test suite is configured to all tests located in `e2e/tests/` ending in `*.e2e.spec.js`. For more about the e2e test suite, please see the [README](./e2e/README.md) -When `npm test` is run, test results will be written as HTML to -`dist/reports/tests/`. Code coverage information is written to `dist/reports/coverage`. +### Security Tests +Each commit is analyzed for known security vulnerabilities using [CodeQL](https://codeql.github.com/docs/codeql-language-guides/codeql-library-for-javascript/). The list of CWE coverage items is available in the [CodeQL docs](https://codeql.github.com/codeql-query-help/javascript-cwe/). The CodeQL workflow is specified in the [CodeQL analysis file](./.github/workflows/codeql-analysis.yml) and the custom [CodeQL config](./.github/codeql/codeql-config.yml). + +### Test Reporting and Code Coverage + +Each test suite generates a report in CircleCI. For a complete overview of testing functionality, please see our [Circle CI Test Insights Dashboard](https://app.circleci.com/insights/github/nasa/openmct/workflows/the-nightly/overview?branch=master&reporting-window=last-30-days) + +Our code coverage is generated during the runtime of our unit, e2e, and visual tests. The combination of those reports is published to [codecov.io](https://app.codecov.io/gh/nasa/openmct/) + +For more on the specifics of our code coverage setup, [see](TESTING.md#code-coverage) # Glossary @@ -124,3 +168,33 @@ documentation, may presume an understanding of these terms. user makes another such choice.) * _namespace_: A name used to identify a persistence store. A running open MCT application could potentially use multiple persistence stores, with the + +## Open MCT v2.0.0 +Support for our legacy bundle-based API, and the libraries that it was built on (like Angular 1.x), have now been removed entirely from this repository. + +For now if you have an Open MCT application that makes use of the legacy API, [a plugin](https://github.com/nasa/openmct-legacy-plugin) is provided that bootstraps the legacy bundling mechanism and API. This plugin will not be maintained over the long term however, and the legacy support plugin will not be tested for compatibility with future versions of Open MCT. It is provided for convenience only. + +### How do I know if I am using legacy API? +You might still be using legacy API if your source code + +* Contains files named bundle.js, or bundle.json, +* Makes calls to `openmct.$injector()`, or `openmct.$angular`, +* Makes calls to `openmct.legacyRegistry`, `openmct.legacyExtension`, or `openmct.legacyBundle`. + + +### What should I do if I am using legacy API? +Please refer to [the modern Open MCT API](https://nasa.github.io/openmct/documentation/). Post any questions to the [Discussions section](https://github.com/nasa/openmct/discussions) of the Open MCT GitHub repository. + +## Related Repos + +> [!NOTE] +> Although Open MCT functions as a standalone project, it is primarily an extensible framework intended to be used as a dependency with users' own plugins and packaging. Furthermore, Open MCT is intended to be used with an HTTP server such as Apache or Nginx. A great example of hosting Open MCT with Apache is `openmct-quickstart` and can be found in the table below. + +| Repository | Description | +| --- | --- | +| [openmct-tutorial](https://github.com/nasa/openmct-tutorial) | A great place for beginners to learn how to use and extend Open MCT. | +| [openmct-quickstart](https://github.com/scottbell/openmct-quickstart) | A working example of Open MCT integrated with Apache HTTP server, YAMCS telemetry, and Couch DB for persistence. +| [Open MCT YAMCS Plugin](https://github.com/akhenry/openmct-yamcs) | Plugin for integrating YAMCS telemetry and command server with Open MCT. | +| [openmct-performance](https://github.com/unlikelyzero/openmct-performance) | Resources for performance testing Open MCT. | +| [openmct-as-a-dependency](https://github.com/unlikelyzero/openmct-as-a-dependency) | An advanced guide for users on how to build, develop, and test Open MCT when it's used as a dependency. | + diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000000..aba8fb1b4e1 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,31 @@ +# Security Policy + +The Open MCT team secures our code base using a combination of code review, dependency review, and periodic security reviews. Static analysis performed during automated verification additionally safeguards against common coding errors which may result in vulnerabilities. + +### Reporting a Vulnerability + +For general defects, please for a [Bug Report](https://github.com/nasa/openmct/issues/new/choose) + +To report a vulnerability for Open MCT please send a detailed report to [arc-dl-openmct](mailto:arc-dl-openmct@mail.nasa.gov). + +See our [top-level security policy](https://github.com/nasa/openmct/security/policy) for additional information. + +### CodeQL and LGTM + +The [CodeQL GitHub Actions workflow](https://github.com/nasa/openmct/blob/master/.github/workflows/codeql-analysis.yml) is available to the public. To review the results, fork the repository and run the CodeQL workflow. + +CodeQL is run for every pull-request in GitHub Actions. + +The project is also monitored by [LGTM](https://lgtm.com/projects/g/nasa/openmct/) and is available to public. + +### ESLint + +Static analysis is run for every push on the master branch and every pull request on all branches in Github Actions. + +For more information about ESLint, visit https://eslint.org/. + +### General Support + +For additional support, please open a [Github Discussion](https://github.com/nasa/openmct/discussions). + +If you wish to report a cybersecurity incident or concern, please contact the NASA Security Operations Center either by phone at 1-877-627-2732 or via email address soc@nasa.gov. diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 00000000000..68e4e3ad1fa --- /dev/null +++ b/TESTING.md @@ -0,0 +1,120 @@ +# Testing +Open MCT Testing is iterating and improving at a rapid pace. This document serves to capture and index existing testing documentation and house documentation which no other obvious location as our testing evolves. + +## General Testing Process +Documentation located [here](./docs/src/process/testing/plan.md) + +## Unit Testing +Unit testing is essential part of our test strategy and complements our e2e testing strategy. + +#### Unit Test Guidelines +* Unit Test specs should reside alongside the source code they test, not in a separate directory. +* Unit test specs for plugins should be defined at the plugin level. Start with one test spec per plugin named pluginSpec.js, and as this test spec grows too big, break it up into multiple test specs that logically group related tests. +* Unit tests for API or for utility functions and classes may be defined at a per-source file level. +* Wherever possible only use and mock public API, builtin functions, and UI in your test specs. Do not directly invoke any private functions. ie. only call or mock functions and objects exposed by openmct.* (eg. openmct.telemetry, openmct.objectView, etc.), and builtin browser functions (fetch, requestAnimationFrame, setTimeout, etc.). +* Where builtin functions have been mocked, be sure to clear them between tests. +* Test at an appropriate level of isolation. Eg. + * If you’re testing a view, you do not need to test the whole application UI, you can just fetch the view provider using the public API and render the view into an element that you have created. + * You do not need to test that the view switcher works, there should be separate tests for that. + * You do not need to test that telemetry providers work, you can mock openmct.telemetry.request() to feed test data to the view. + * Use your best judgement when deciding on appropriate scope. +* Automated tests for plugins should start by actually installing the plugin being tested, and then test that installing the plugin adds the desired features and behavior to Open MCT, observing the above rules. +* All variables used in a test spec, including any instances of the Open MCT API should be declared inside of an appropriate block scope (not at the root level of the source file), and should be initialized in the relevant beforeEach block. `beforeEach` is preferable to `beforeAll` to avoid leaking of state between tests. +* A `afterEach` or `afterAll` should be used to do any clean up necessary to prevent leakage of state between test specs. This can happen when functions on `window` are wrapped, or when the URL is changed. [A convenience function](https://github.com/nasa/openmct/blob/master/src/utils/testing.js#L59) is provided for resetting the URL and clearing builtin spies between tests. + +#### Unit Test Examples +* [Example of an automated test spec for an object view plugin](https://github.com/nasa/openmct/blob/master/src/plugins/telemetryTable/pluginSpec.js) +* [Example of an automated test spec for API](https://github.com/nasa/openmct/blob/master/src/api/time/TimeAPISpec.js) + +#### Unit Testing Execution + +The unit tests can be executed in one of two ways: +`npm run test` which runs the entire suite against headless chrome +`npm run test:debug` for debugging the tests in realtime in an active chrome session. + +## e2e, performance, and visual testing +Documentation located [here](./e2e/README.md) + +## Code Coverage + +It's up to the individual developer as to whether they want to add line coverage in the form of a unit test or e2e test. + +Line Code Coverage is generated by our unit tests and e2e tests, then combined by ([Codecov.io Flags](https://docs.codecov.com/docs/flags)), and finally reported in GitHub PRs by Codecov.io's PR Bot. This workflow gives a comprehensive (if flawed) view of line coverage. + +### Karma-istanbul + +Line coverage is generated by our `karma-coverage-istanbul-reporter` package as defined in our `karma.conf.js` file: + +```js + coverageIstanbulReporter: { + fixWebpackSourcePaths: true, + skipFilesWithNoCoverage: true, + dir: 'coverage/unit', //Sets coverage file to be consumed by codecov.io + reports: ['lcovonly'] + }, +``` + +Once the file is generated, it can be published to codecov with + +```json + "cov:unit:publish": "codecov --disable=gcov -f ./coverage/unit/lcov.info -F unit", +``` + +### e2e +The e2e line coverage is a bit more complex than the karma implementation. This is the general sequence of events: + +1. Each e2e suite will start webpack with the ```npm run start:coverage``` command with config `webpack.coverage.js` and the `babel-plugin-istanbul` plugin to generate code coverage during e2e test execution using our custom [baseFixture](./baseFixtures.js). +1. During testcase execution, each e2e shard will generate its piece of the larger coverage suite. **This coverage file is not merged**. The raw coverage file is stored in a `.nyc_report` directory. +1. [nyc](https://github.com/istanbuljs/nyc) converts this directory into a `lcov` file with the following command `npm run cov:e2e:report` +1. Most of the tests are run in the '@stable' configuration and focus on chrome/ubuntu at a single resolution. This coverage is published to codecov with `npm run cov:e2e:stable:publish`. +1. The rest of our coverage only appears when run against `@unstable` tests, persistent datastore (couchdb), non-ubuntu machines, and non-chrome browsers with the `npm run cov:e2e:full:publish` flag. Since this happens about once a day, we have leveraged codecov.io's carryforward flag to report on lines covered outside of each commit on an individual PR. + + +### Limitations in our code coverage reporting +Our code coverage implementation has some known limitations: +- [Variability](https://github.com/nasa/openmct/issues/5811) +- [Accuracy](https://github.com/nasa/openmct/issues/7015) +- [Vue instrumentation gaps](https://github.com/nasa/openmct/issues/4973) + +## Troubleshooting CI +The following is an evolving guide to troubleshoot CI and PR issues. + +### Github Checks failing +There are a few reasons that your GitHub PR could be failing beyond simple failed tests. +* Required Checks. We're leveraging required checks in GitHub so that we can quickly and precisely control what becomes and informational failure vs a hard requirement. The only way to determine the difference between a required vs information check is check for the `(Required)` emblem next to the step details in GitHub Checks. +* Not all required checks are run per commit. You may need to manually trigger addition GitHub checks with a `pr: