mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-15 19:42:26 -06:00
Compare commits
1 Commits
file-resto
...
api-utils
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8fac876ca |
217
.eslintrc.js
217
.eslintrc.js
@@ -15,10 +15,9 @@ module.exports = {
|
||||
|
||||
overrides: [
|
||||
{
|
||||
files: ['cli.{,c,m}js', '*-cli.{,c,m}js', '**/*cli*/**/*.{,c,m}js', '**/scripts/**.{,c,m}js'],
|
||||
files: ['cli.{,c,m}js', '*-cli.{,c,m}js', '**/*cli*/**/*.{,c,m}js'],
|
||||
rules: {
|
||||
'n/no-process-exit': 'off',
|
||||
'n/shebang': 'off',
|
||||
'no-console': 'off',
|
||||
},
|
||||
},
|
||||
@@ -39,12 +38,6 @@ module.exports = {
|
||||
version: '>=16',
|
||||
},
|
||||
],
|
||||
'n/no-unsupported-features/es-builtins': [
|
||||
'error',
|
||||
{
|
||||
version: '>=16',
|
||||
},
|
||||
],
|
||||
'n/no-unsupported-features/es-syntax': [
|
||||
'error',
|
||||
{
|
||||
@@ -53,212 +46,6 @@ module.exports = {
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['@xen-orchestra/{web-core,lite,web}/**/*.{vue,ts}'],
|
||||
parser: 'vue-eslint-parser',
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
parser: '@typescript-eslint/parser',
|
||||
},
|
||||
plugins: ['import'],
|
||||
extends: [
|
||||
'plugin:import/recommended',
|
||||
'plugin:import/typescript',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:vue/vue3-essential',
|
||||
],
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
typescript: true,
|
||||
'eslint-import-resolver-custom-alias': {
|
||||
alias: {
|
||||
'@core': '../web-core/lib',
|
||||
'@': './src',
|
||||
},
|
||||
extensions: ['.ts'],
|
||||
packages: ['@xen-orchestra/lite', '@xen-orchestra/web'],
|
||||
},
|
||||
},
|
||||
},
|
||||
globals: {
|
||||
XO_LITE_VERSION: true,
|
||||
XO_LITE_GIT_HEAD: true,
|
||||
},
|
||||
rules: {
|
||||
'import/order': [
|
||||
'error',
|
||||
{
|
||||
groups: ['builtin', 'object', 'internal', ['type', 'external']],
|
||||
alphabetize: {
|
||||
order: 'asc',
|
||||
caseInsensitive: true,
|
||||
},
|
||||
pathGroups: [
|
||||
{
|
||||
pattern: '@/**',
|
||||
group: 'internal',
|
||||
},
|
||||
{
|
||||
pattern: '@core/**',
|
||||
group: 'internal',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'no-void': ['error', { allowAsStatement: true }],
|
||||
'n/no-missing-import': 'off', // using 'import' plugin instead, to support TS aliases
|
||||
'no-redeclare': 'off', // automatically checked by the TypeScript compiler
|
||||
'no-dupe-class-members': 'off', // automatically checked by the TypeScript compiler
|
||||
'no-undef': 'off', // automatically checked by the TypeScript compiler
|
||||
'no-use-before-define': 'off', // replaced with the rule below
|
||||
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'vue/multi-word-component-names': 'off',
|
||||
// Vue 3 - Strongly Recommended
|
||||
'vue/attribute-hyphenation': 'error',
|
||||
'vue/component-definition-name-casing': 'error',
|
||||
'vue/first-attribute-linebreak': 'error',
|
||||
'vue/html-closing-bracket-newline': 'off', // Conflicts with Prettier
|
||||
'vue/html-closing-bracket-spacing': 'error',
|
||||
'vue/html-end-tags': 'error',
|
||||
'vue/html-indent': 'off', // Conflicts with Prettier
|
||||
'vue/html-quotes': 'error',
|
||||
'vue/html-self-closing': ['error', { html: { void: 'always', normal: 'always', component: 'always' } }],
|
||||
'vue/max-attributes-per-line': 'off', // Conflicts with Prettier
|
||||
'vue/multiline-html-element-content-newline': 'error',
|
||||
'vue/mustache-interpolation-spacing': 'error',
|
||||
'vue/no-multi-spaces': 'error',
|
||||
'vue/no-spaces-around-equal-signs-in-attribute': 'error',
|
||||
'vue/no-template-shadow': 'error',
|
||||
'vue/prop-name-casing': 'error',
|
||||
'vue/require-default-prop': 'off', // https://github.com/vuejs/eslint-plugin-vue/issues/2051
|
||||
'vue/require-explicit-emits': 'error',
|
||||
'vue/require-prop-types': 'error',
|
||||
'vue/singleline-html-element-content-newline': 'off',
|
||||
'vue/v-bind-style': 'error',
|
||||
'vue/v-on-event-hyphenation': ['error', 'always', { autofix: true }],
|
||||
'vue/v-on-style': 'error',
|
||||
'vue/v-slot-style': 'error',
|
||||
// Vue 3 - Recommended
|
||||
'vue/attributes-order': 'error',
|
||||
'vue/no-lone-template': 'error',
|
||||
'vue/no-multiple-slot-args': 'error',
|
||||
'vue/no-v-html': 'error',
|
||||
'vue/this-in-template': 'error',
|
||||
// Vue 3 - Uncategorized
|
||||
'vue/block-lang': ['error', { script: { lang: 'ts' }, style: { lang: 'postcss' } }],
|
||||
'vue/block-order': ['error', { order: ['template', 'script', 'style'] }],
|
||||
'vue/block-tag-newline': ['error', { singleline: 'consistent', multiline: 'always', maxEmptyLines: 0 }],
|
||||
'vue/component-api-style': ['error', ['script-setup']],
|
||||
'vue/component-name-in-template-casing': ['error', 'PascalCase', { registeredComponentsOnly: false }],
|
||||
'vue/custom-event-name-casing': ['error', 'camelCase'],
|
||||
'vue/define-emits-declaration': ['error', 'type-literal'],
|
||||
'vue/define-macros-order': [
|
||||
'error',
|
||||
{
|
||||
order: ['defineOptions', 'defineProps', 'defineEmits', 'defineModel', 'defineSlots'],
|
||||
defineExposeLast: true,
|
||||
},
|
||||
],
|
||||
'vue/define-props-declaration': ['error', 'type-based'],
|
||||
'vue/enforce-style-attribute': ['error', { allow: ['scoped', 'module'] }],
|
||||
'vue/html-button-has-type': 'error',
|
||||
'vue/html-comment-content-newline': ['error', { singleline: 'never', multiline: 'always' }],
|
||||
'vue/html-comment-content-spacing': ['error', 'always'],
|
||||
'vue/no-duplicate-attr-inheritance': 'error',
|
||||
'vue/no-empty-component-block': 'error',
|
||||
'vue/no-multiple-objects-in-class': 'error',
|
||||
'vue/no-ref-object-reactivity-loss': 'error',
|
||||
'vue/no-required-prop-with-default': 'error',
|
||||
'vue/no-static-inline-styles': 'error',
|
||||
'vue/no-template-target-blank': 'error',
|
||||
'vue/no-undef-components': ['error', { ignorePatterns: ['RouterLink', 'RouterView', 'I18nT'] }],
|
||||
'vue/no-undef-properties': 'error',
|
||||
'vue/no-unused-refs': 'error',
|
||||
'vue/no-use-v-else-with-v-for': 'error',
|
||||
'vue/no-useless-mustaches': 'error',
|
||||
'vue/no-useless-v-bind': 'error',
|
||||
'vue/no-v-text': 'error',
|
||||
'vue/padding-line-between-blocks': 'error',
|
||||
'vue/prefer-define-options': 'error',
|
||||
'vue/prefer-separate-static-class': 'error',
|
||||
'vue/prefer-true-attribute-shorthand': 'error',
|
||||
'vue/require-macro-variable-name': 'error',
|
||||
'vue/valid-define-options': 'error',
|
||||
},
|
||||
},
|
||||
// Specific rules for XO i18n-related files
|
||||
{
|
||||
files: [
|
||||
'@xen-orchestra/lite/**/*.{vue,ts,json}',
|
||||
'@xen-orchestra/web/**/*.{vue,ts,json}',
|
||||
'@xen-orchestra/web-core/**/*.{vue,ts,json}',
|
||||
],
|
||||
extends: ['plugin:@intlify/vue-i18n/base'],
|
||||
settings: {
|
||||
'vue-i18n': {
|
||||
localeDir: [
|
||||
'@xen-orchestra/lite/src/locales/*.json',
|
||||
'@xen-orchestra/web/src/locales/*.json',
|
||||
'@xen-orchestra/web-core/lib/locales/*.json',
|
||||
],
|
||||
messageSyntaxVersion: '^9.9.0',
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
strict: 'off',
|
||||
'no-irregular-whitespace': 'off',
|
||||
'@intlify/vue-i18n/no-deprecated-i18n-component': 'error',
|
||||
'@intlify/vue-i18n/no-deprecated-i18n-place-attr': 'error',
|
||||
'@intlify/vue-i18n/no-deprecated-i18n-places-prop': 'error',
|
||||
'@intlify/vue-i18n/no-deprecated-modulo-syntax': 'error',
|
||||
'@intlify/vue-i18n/no-deprecated-tc': 'error',
|
||||
'@intlify/vue-i18n/no-html-messages': 'error',
|
||||
'@intlify/vue-i18n/no-i18n-t-path-prop': 'error',
|
||||
'@intlify/vue-i18n/no-missing-keys': 'error',
|
||||
'@intlify/vue-i18n/no-raw-text': [
|
||||
'error',
|
||||
{
|
||||
ignoreText: ['Xen Orchestra Lite', 'Xen Orchestra', 'XO Lite', 'XCP-ng', 'XO 5', '404', '⚠️'],
|
||||
},
|
||||
],
|
||||
'@intlify/vue-i18n/no-v-html': 'error',
|
||||
'@intlify/vue-i18n/valid-message-syntax': 'error',
|
||||
'@intlify/vue-i18n/no-duplicate-keys-in-locale': 'error',
|
||||
'@intlify/vue-i18n/no-missing-keys-in-other-locales': ['error', { ignoreLocales: ['de', 'fa'] }],
|
||||
},
|
||||
},
|
||||
// Specific rules for XO dev-related files
|
||||
{
|
||||
files: [
|
||||
'@xen-orchestra/lite/src/stories/**/*',
|
||||
'@xen-orchestra/lite/src/components/component-story/**/*',
|
||||
'@xen-orchestra/web/src/pages/dev/**/*',
|
||||
'@xen-orchestra/lite/src/views/story/**/*',
|
||||
],
|
||||
rules: {
|
||||
'@intlify/vue-i18n/no-raw-text': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['@xen-orchestra/{web-core,lite,web}/src/pages/**/*.vue'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
'vue/multi-word-component-names': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['@xen-orchestra/{web-core,lite,web}/typed-router.d.ts'],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
'eslint-comments/disable-enable-pair': 'off',
|
||||
'eslint-comments/no-unlimited-disable': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
parserOptions: {
|
||||
@@ -284,7 +71,7 @@ module.exports = {
|
||||
// this rule can prevent race condition bugs like parallel `a += await foo()`
|
||||
//
|
||||
// as it has a lots of false positive, it is only enabled as a warning for now
|
||||
'require-atomic-updates': ['warn', { allowProperties: true }],
|
||||
'require-atomic-updates': 'warn',
|
||||
|
||||
strict: 'error',
|
||||
},
|
||||
|
||||
48
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
48
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: 'status: triaging :triangular_flag_on_post:, type: bug :bug:'
|
||||
assignees: ''
|
||||
---
|
||||
|
||||
1. ⚠️ **If you don't follow this template, the issue will be closed**.
|
||||
2. ⚠️ **If your issue can't be easily reproduced, please report it [on the forum first](https://xcp-ng.org/forum/category/12/xen-orchestra)**.
|
||||
|
||||
Are you using XOA or XO from the sources?
|
||||
|
||||
If XOA:
|
||||
|
||||
- which release channel? (`stable` vs `latest`)
|
||||
- please consider creating a support ticket in [your dedicated support area](https://xen-orchestra.com/#!/member/support)
|
||||
|
||||
If XO from the sources:
|
||||
|
||||
- Provide **your commit number**. If it's older than a week, we won't investigate
|
||||
- Don't forget to [read this first](https://xen-orchestra.com/docs/community.html)
|
||||
- As well as follow [this guide](https://xen-orchestra.com/docs/community.html#report-a-bug)
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Environment (please provide the following information):**
|
||||
|
||||
- Node: [e.g. 16.12.1]
|
||||
- hypervisor: [e.g. XCP-ng 8.2.0]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
119
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
119
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
@@ -1,119 +0,0 @@
|
||||
name: Bug Report
|
||||
description: Create a report to help us improve
|
||||
labels: ['type: bug :bug:', 'status: triaging :triangular_flag_on_post:']
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
1. ⚠️ **If you don't follow this template, the issue will be closed**.
|
||||
2. ⚠️ **If your issue can't be easily reproduced, please report it [on the forum first](https://xcp-ng.org/forum/category/12/xen-orchestra)**.
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: '## Are you using XOA or XO from the sources?'
|
||||
- type: dropdown
|
||||
id: xo-origin
|
||||
attributes:
|
||||
label: Are you using XOA or XO from the sources?
|
||||
options:
|
||||
- XOA
|
||||
- XO from the sources
|
||||
- both
|
||||
validations:
|
||||
required: false
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: '### If XOA:'
|
||||
- type: dropdown
|
||||
id: xoa-channel
|
||||
attributes:
|
||||
label: Which release channel?
|
||||
description: please consider creating a support ticket in [your dedicated support area](https://xen-orchestra.com/#!/member/support)
|
||||
options:
|
||||
- stable
|
||||
- latest
|
||||
- both
|
||||
validations:
|
||||
required: false
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: '### If XO from the sources:'
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
- Don't forget to [read this first](https://xen-orchestra.com/docs/community.html)
|
||||
- As well as follow [this guide](https://xen-orchestra.com/docs/community.html#report-a-bug)
|
||||
- type: input
|
||||
id: xo-sources-commit-number
|
||||
attributes:
|
||||
label: Provide your commit number
|
||||
description: If it's older than a week, we won't investigate
|
||||
placeholder: e.g. 579f0
|
||||
validations:
|
||||
required: false
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: '## Bug description:'
|
||||
- type: textarea
|
||||
id: bug-description
|
||||
attributes:
|
||||
label: Describe the bug
|
||||
description: A clear and concise description of what the bug is
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: error-message
|
||||
attributes:
|
||||
label: Error message
|
||||
render: Text
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: To reproduce
|
||||
description: 'Steps to reproduce the behavior:'
|
||||
value: |
|
||||
1. Go to '...'
|
||||
2. Click on '...'
|
||||
3. Scroll down to '...'
|
||||
4. See error
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: expected-behavior
|
||||
attributes:
|
||||
label: Expected behavior
|
||||
description: A clear and concise description of what you expected to happen
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: Screenshots
|
||||
description: If applicable, add screenshots to help explain your problem
|
||||
validations:
|
||||
required: false
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: '## Environment (please provide the following information):'
|
||||
- type: input
|
||||
id: node-version
|
||||
attributes:
|
||||
label: Node
|
||||
placeholder: e.g. 16.12.1
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: hypervisor-version
|
||||
attributes:
|
||||
label: Hypervisor
|
||||
placeholder: e.g. XCP-ng 8.2.0
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: additional-context
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Add any other context about the problem here
|
||||
validations:
|
||||
required: false
|
||||
34
.github/workflows/ci.yml
vendored
34
.github/workflows/ci.yml
vendored
@@ -5,46 +5,28 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# https://github.com/actions/checkout
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y curl qemu-utils python3-vmdkstream git libxml2-utils libfuse2 nbdkit
|
||||
|
||||
# https://turbo.build/repo/docs/guides/ci-vendors/github-actions#caching-with-github-actionscache
|
||||
- name: Cache Turbo
|
||||
uses: actions/cache@v4
|
||||
# https://github.com/actions/cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '.turbo'
|
||||
key: ${{ runner.os }}-turbo-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-turbo-
|
||||
|
||||
# https://github.com/actions/setup-node
|
||||
path: '**/node_modules/.cache/turbo'
|
||||
key: ${{ runner.os }}-turbo-cache
|
||||
- name: Setup Node environment
|
||||
uses: actions/setup-node@v4
|
||||
# https://github.com/actions/setup-node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '20'
|
||||
node-version: '18'
|
||||
cache: 'yarn'
|
||||
|
||||
- name: Install project dependencies
|
||||
run: yarn
|
||||
|
||||
- name: Ensure packages are sorted in CHANGELOG.unreleased.md
|
||||
run: ./scripts/gen-deps-list.js --check-order > /dev/null
|
||||
|
||||
- name: Ensure yarn.lock is up-to-date
|
||||
run: git diff --exit-code yarn.lock
|
||||
|
||||
- name: Build the project
|
||||
run: yarn build
|
||||
|
||||
- name: Unit tests
|
||||
run: yarn test-unit
|
||||
|
||||
- name: Lint tests
|
||||
run: yarn test-lint
|
||||
|
||||
- name: Integration tests
|
||||
run: sudo yarn test-integration
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -30,12 +30,8 @@ pnpm-debug.log.*
|
||||
yarn-error.log
|
||||
yarn-error.log.*
|
||||
.env
|
||||
*.tsbuildinfo
|
||||
|
||||
# code coverage
|
||||
.nyc_output/
|
||||
coverage/
|
||||
.turbo/
|
||||
|
||||
# https://node-tap.org/dot-tap-folder/
|
||||
.tap/
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# Ignore Handlebars files because partials are not currently supported
|
||||
# https://github.com/prettier/prettier/issues/11834
|
||||
**/*.hbs
|
||||
|
||||
# Generated files
|
||||
/@xen-orchestra/web/typed-router.d.ts
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it, beforeEach } = require('node:test')
|
||||
const { describe, it, beforeEach } = require('test')
|
||||
const assert = require('assert').strict
|
||||
const { spy } = require('sinon')
|
||||
|
||||
|
||||
@@ -30,9 +30,11 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"sinon": "^18.0.0"
|
||||
"sinon": "^17.0.1",
|
||||
"tap": "^16.3.0",
|
||||
"test": "^3.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
const assert = require('assert')
|
||||
|
||||
const { coalesceCalls } = require('./')
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
const assert = require('node:assert').strict
|
||||
|
||||
const { compose } = require('./')
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,42 +62,6 @@ decorateClass(Foo, {
|
||||
})
|
||||
```
|
||||
|
||||
### `decorateObject(object, map)`
|
||||
|
||||
Decorates an object the same way `decorateClass()` decorates a class:
|
||||
|
||||
```js
|
||||
import { decorateObject } from '@vates/decorate-with'
|
||||
|
||||
const object = {
|
||||
get bar() {
|
||||
// body
|
||||
},
|
||||
|
||||
set bar(value) {
|
||||
// body
|
||||
},
|
||||
|
||||
baz() {
|
||||
// body
|
||||
},
|
||||
}
|
||||
|
||||
decorateObject(object, {
|
||||
// getter and/or setter
|
||||
bar: {
|
||||
// without arguments
|
||||
get: lodash.memoize,
|
||||
|
||||
// with arguments
|
||||
set: [lodash.debounce, 150],
|
||||
},
|
||||
|
||||
// method (with or without arguments)
|
||||
baz: lodash.curry,
|
||||
})
|
||||
```
|
||||
|
||||
### `perInstance(fn, ...args)`
|
||||
|
||||
Helper to decorate the method by instance instead of for the whole class.
|
||||
|
||||
@@ -80,42 +80,6 @@ decorateClass(Foo, {
|
||||
})
|
||||
```
|
||||
|
||||
### `decorateObject(object, map)`
|
||||
|
||||
Decorates an object the same way `decorateClass()` decorates a class:
|
||||
|
||||
```js
|
||||
import { decorateObject } from '@vates/decorate-with'
|
||||
|
||||
const object = {
|
||||
get bar() {
|
||||
// body
|
||||
},
|
||||
|
||||
set bar(value) {
|
||||
// body
|
||||
},
|
||||
|
||||
baz() {
|
||||
// body
|
||||
},
|
||||
}
|
||||
|
||||
decorateObject(object, {
|
||||
// getter and/or setter
|
||||
bar: {
|
||||
// without arguments
|
||||
get: lodash.memoize,
|
||||
|
||||
// with arguments
|
||||
set: [lodash.debounce, 150],
|
||||
},
|
||||
|
||||
// method (with or without arguments)
|
||||
baz: lodash.curry,
|
||||
})
|
||||
```
|
||||
|
||||
### `perInstance(fn, ...args)`
|
||||
|
||||
Helper to decorate the method by instance instead of for the whole class.
|
||||
|
||||
@@ -14,13 +14,10 @@ function applyDecorator(decorator, value) {
|
||||
}
|
||||
|
||||
exports.decorateClass = exports.decorateMethodsWith = function decorateClass(klass, map) {
|
||||
return decorateObject(klass.prototype, map)
|
||||
}
|
||||
|
||||
function decorateObject(object, map) {
|
||||
const { prototype } = klass
|
||||
for (const name of Object.keys(map)) {
|
||||
const decorator = map[name]
|
||||
const descriptor = getOwnPropertyDescriptor(object, name)
|
||||
const descriptor = getOwnPropertyDescriptor(prototype, name)
|
||||
if (typeof decorator === 'function' || Array.isArray(decorator)) {
|
||||
descriptor.value = applyDecorator(decorator, descriptor.value)
|
||||
} else {
|
||||
@@ -33,11 +30,10 @@ function decorateObject(object, map) {
|
||||
}
|
||||
}
|
||||
|
||||
defineProperty(object, name, descriptor)
|
||||
defineProperty(prototype, name, descriptor)
|
||||
}
|
||||
return object
|
||||
return klass
|
||||
}
|
||||
exports.decorateObject = decorateObject
|
||||
|
||||
exports.perInstance = function perInstance(fn, decorator, ...args) {
|
||||
const map = new WeakMap()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
|
||||
const { decorateClass, decorateWith, decorateMethodsWith, perInstance } = require('./')
|
||||
|
||||
|
||||
@@ -20,12 +20,15 @@
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "2.1.0",
|
||||
"version": "2.0.0",
|
||||
"engines": {
|
||||
"node": ">=8.10"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const test = require('node:test')
|
||||
const test = require('test')
|
||||
|
||||
const diff = require('./index.js')
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
const { useFakeTimers, spy, assert } = require('sinon')
|
||||
|
||||
const { createDebounceResource } = require('./debounceResource')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
const { spy, assert } = require('sinon')
|
||||
|
||||
const { deduped } = require('./deduped')
|
||||
|
||||
@@ -14,21 +14,22 @@
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.5",
|
||||
"engines": {
|
||||
"node": ">=8.10"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/multi-key-map": "^0.2.0",
|
||||
"@xen-orchestra/async-map": "^0.1.2",
|
||||
"@xen-orchestra/log": "^0.7.0",
|
||||
"@xen-orchestra/log": "^0.6.0",
|
||||
"ensure-array": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"sinon": "^18.0.0"
|
||||
"sinon": "^17.0.1",
|
||||
"test": "^3.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ function assertListeners(t, event, listeners) {
|
||||
}
|
||||
|
||||
t.beforeEach(function (t) {
|
||||
// work around https://github.com/tapjs/tapjs/issues/998
|
||||
t.context = {}
|
||||
|
||||
t.context.ee = new EventEmitter()
|
||||
t.context.em = new EventListenersManager(t.context.ee)
|
||||
})
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
"version": "1.0.1",
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "tap --allow-incomplete-coverage"
|
||||
"test": "tap --branches=72"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^18.7.0"
|
||||
"tap": "^16.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
Mount a vhd generated by xen-orchestra to filesystem
|
||||
|
||||
### Library
|
||||
|
||||
```js
|
||||
import { mount } from 'fuse-vhd'
|
||||
|
||||
// return a disposable, see promise-toolbox/Disposable
|
||||
// unmount automatically when disposable is disposed
|
||||
// in case of differencing VHD, it mounts the full chain
|
||||
await mount(handler, diskId, mountPoint)
|
||||
```
|
||||
|
||||
### cli
|
||||
|
||||
From the install folder :
|
||||
|
||||
```
|
||||
cli.mjs <remoteUrl> <vhdPathInRemote> <mountPoint>
|
||||
```
|
||||
|
||||
After installing the package
|
||||
|
||||
```
|
||||
xo-fuse-vhd <remoteUrl> <vhdPathInRemote> <mountPoint>
|
||||
```
|
||||
|
||||
remoteUrl can be found by using cli in `@xen-orchestra/fs` , for example a local remote will have a url like `file:///path/to/remote/root`
|
||||
@@ -1,59 +0,0 @@
|
||||
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||
|
||||
# @vates/fuse-vhd
|
||||
|
||||
[](https://npmjs.org/package/@vates/fuse-vhd)  [](https://bundlephobia.com/result?p=@vates/fuse-vhd) [](https://npmjs.org/package/@vates/fuse-vhd)
|
||||
|
||||
## Install
|
||||
|
||||
Installation of the [npm package](https://npmjs.org/package/@vates/fuse-vhd):
|
||||
|
||||
```sh
|
||||
npm install --save @vates/fuse-vhd
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Mount a vhd generated by xen-orchestra to filesystem
|
||||
|
||||
### Library
|
||||
|
||||
```js
|
||||
import { mount } from 'fuse-vhd'
|
||||
|
||||
// return a disposable, see promise-toolbox/Disposable
|
||||
// unmount automatically when disposable is disposed
|
||||
// in case of differencing VHD, it mounts the full chain
|
||||
await mount(handler, diskId, mountPoint)
|
||||
```
|
||||
|
||||
### cli
|
||||
|
||||
From the install folder :
|
||||
|
||||
```
|
||||
cli.mjs <remoteUrl> <vhdPathInRemote> <mountPoint>
|
||||
```
|
||||
|
||||
After installing the package
|
||||
|
||||
```
|
||||
xo-fuse-vhd <remoteUrl> <vhdPathInRemote> <mountPoint>
|
||||
```
|
||||
|
||||
remoteUrl can be found by using cli in `@xen-orchestra/fs` , for example a local remote will have a url like `file:///path/to/remote/root`
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are _very_ welcomed, either on the documentation or on
|
||||
the code.
|
||||
|
||||
You may:
|
||||
|
||||
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||
you've encountered;
|
||||
- fork and create a pull request.
|
||||
|
||||
## License
|
||||
|
||||
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import Disposable from 'promise-toolbox/Disposable'
|
||||
import { getSyncedHandler } from '@xen-orchestra/fs'
|
||||
|
||||
import { mount } from './index.mjs'
|
||||
|
||||
async function* main([remoteUrl, vhdPathInRemote, mountPoint]) {
|
||||
if (mountPoint === undefined) {
|
||||
throw new TypeError('missing arg: cli <remoteUrl> <vhdPathInRemote> <mountPoint>')
|
||||
}
|
||||
const handler = yield getSyncedHandler({ url: remoteUrl })
|
||||
const mounted = await mount(handler, vhdPathInRemote, mountPoint)
|
||||
|
||||
let disposePromise
|
||||
process.on('SIGINT', async () => {
|
||||
// ensure single dispose
|
||||
if (!disposePromise) {
|
||||
disposePromise = mounted.dispose()
|
||||
}
|
||||
await disposePromise
|
||||
process.exit()
|
||||
})
|
||||
}
|
||||
|
||||
Disposable.wrap(main)(process.argv.slice(2))
|
||||
@@ -1,11 +1,8 @@
|
||||
import LRU from 'lru-cache'
|
||||
import Fuse from 'fuse-native'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { VhdSynthetic } from 'vhd-lib'
|
||||
import { Disposable, fromCallback } from 'promise-toolbox'
|
||||
|
||||
const { warn } = createLogger('vates:fuse-vhd')
|
||||
|
||||
// build a s stat object from https://github.com/fuse-friends/fuse-native/blob/master/test/fixtures/stat.js
|
||||
const stat = st => ({
|
||||
mtime: st.mtime || new Date(),
|
||||
@@ -55,16 +52,13 @@ export const mount = Disposable.factory(async function* mount(handler, diskPath,
|
||||
},
|
||||
read(path, fd, buf, len, pos, cb) {
|
||||
if (path === '/vhd0') {
|
||||
return vhd.readRawData(pos, len, cache, buf).then(cb, error => {
|
||||
warn('read error', { path, len, pos, error })
|
||||
cb(Fuse.EIO)
|
||||
})
|
||||
return vhd.readRawData(pos, len, cache, buf).then(cb)
|
||||
}
|
||||
throw new Error(`read file ${path} not exists`)
|
||||
},
|
||||
})
|
||||
return new Disposable(
|
||||
() => fromCallback(cb => fuse.unmount(cb)),
|
||||
fromCallback(cb => fuse.mount(cb))
|
||||
() => fromCallback(() => fuse.unmount()),
|
||||
fromCallback(() => fuse.mount())
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vates/fuse-vhd",
|
||||
"version": "2.1.2",
|
||||
"version": "2.0.0",
|
||||
"license": "ISC",
|
||||
"private": false,
|
||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/fuse-vhd",
|
||||
@@ -19,15 +19,10 @@
|
||||
},
|
||||
"main": "./index.mjs",
|
||||
"dependencies": {
|
||||
"@xen-orchestra/fs": "^4.2.0",
|
||||
"@xen-orchestra/log": "^0.7.0",
|
||||
"fuse-native": "^2.2.6",
|
||||
"lru-cache": "^7.14.0",
|
||||
"promise-toolbox": "^0.21.0",
|
||||
"vhd-lib": "^4.11.1"
|
||||
},
|
||||
"bin": {
|
||||
"xo-fuse-vhd": "./cli.mjs"
|
||||
"vhd-lib": "^4.8.0"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public"
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
The use for this librariy is to create a composite key from a JSON value, ignoring objects identity and properties order.
|
||||
|
||||
The hash algorithm used is intended to be fast and with low collisions and is not guaranteed to be be secure.
|
||||
|
||||
The hash is encoded using [Base64 URL](https://en.wikipedia.org/wiki/Base64#URL_applications) to make it easy to use in URLs and filenames.
|
||||
|
||||
```js
|
||||
import { jsonHash } from '@vates/json-hash'
|
||||
|
||||
console.log(jsonHash('foo'))
|
||||
// → "siEyldVkkW-JpqQkVVZ8h8P0gPzXocFeIg8X1xaaeQs"
|
||||
|
||||
// order of properties is ignored
|
||||
console.log(jsonHash({ foo: 0, bar: 1 }))
|
||||
// → "JckoRSMIBjNlgEWIXhgpBOuyLQYqABZqvf1ccb3BPg0"
|
||||
console.log(jsonHash({ bar: 1, foo: 0 }))
|
||||
// → "JckoRSMIBjNlgEWIXhgpBOuyLQYqABZqvf1ccb3BPg0"
|
||||
```
|
||||
@@ -1 +0,0 @@
|
||||
../../scripts/npmignore
|
||||
@@ -1,51 +0,0 @@
|
||||
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||
|
||||
# @vates/json-hash
|
||||
|
||||
[](https://npmjs.org/package/@vates/json-hash)  [](https://bundlephobia.com/result?p=@vates/json-hash) [](https://npmjs.org/package/@vates/json-hash)
|
||||
|
||||
> Compute a stable hash from a JSON-ifiable value
|
||||
|
||||
## Install
|
||||
|
||||
Installation of the [npm package](https://npmjs.org/package/@vates/json-hash):
|
||||
|
||||
```sh
|
||||
npm install --save @vates/json-hash
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The use for this librariy is to create a composite key from a JSON value, ignoring objects identity and properties order.
|
||||
|
||||
The hash algorithm used is intended to be fast and with low collisions and is not guaranteed to be be secure.
|
||||
|
||||
The hash is encoded using [Base64 URL](https://en.wikipedia.org/wiki/Base64#URL_applications) to make it easy to use in URLs and filenames.
|
||||
|
||||
```js
|
||||
import { jsonHash } from '@vates/json-hash'
|
||||
|
||||
console.log(jsonHash('foo'))
|
||||
// → "siEyldVkkW-JpqQkVVZ8h8P0gPzXocFeIg8X1xaaeQs"
|
||||
|
||||
// order of properties is ignored
|
||||
console.log(jsonHash({ foo: 0, bar: 1 }))
|
||||
// → "JckoRSMIBjNlgEWIXhgpBOuyLQYqABZqvf1ccb3BPg0"
|
||||
console.log(jsonHash({ bar: 1, foo: 0 }))
|
||||
// → "JckoRSMIBjNlgEWIXhgpBOuyLQYqABZqvf1ccb3BPg0"
|
||||
```
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are _very_ welcomed, either on the documentation or on
|
||||
the code.
|
||||
|
||||
You may:
|
||||
|
||||
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||
you've encountered;
|
||||
- fork and create a pull request.
|
||||
|
||||
## License
|
||||
|
||||
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)
|
||||
@@ -1,38 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const { createHash } = require('node:crypto')
|
||||
|
||||
function updateJsonHash(value, hash) {
|
||||
if (value !== null && typeof value === 'object') {
|
||||
if (Array.isArray(value)) {
|
||||
hash.update('[')
|
||||
for (const item of value) {
|
||||
updateJsonHash(item, hash)
|
||||
|
||||
// trailing is not a big deal because it does not need to be valid JSON
|
||||
hash.update(',')
|
||||
}
|
||||
hash.update(']')
|
||||
} else {
|
||||
hash.update('{')
|
||||
for (const key of Object.keys(value).sort()) {
|
||||
updateJsonHash(key, hash)
|
||||
hash.update(':')
|
||||
updateJsonHash(value[key], hash)
|
||||
|
||||
// trailing is not a big deal because it does not need to be valid JSON
|
||||
hash.update(',')
|
||||
}
|
||||
hash.update('}')
|
||||
}
|
||||
} else {
|
||||
hash.update(JSON.stringify(value))
|
||||
}
|
||||
}
|
||||
|
||||
exports.jsonHash = function jsonHash(value) {
|
||||
// this hash does not need to be secure, it just needs to be fast and with low collisions
|
||||
const hash = createHash('sha256')
|
||||
updateJsonHash(value, hash)
|
||||
return hash.digest('base64url')
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const { jsonHash } = require('@vates/json-hash')
|
||||
const assert = require('node:assert/strict')
|
||||
const test = require('node:test')
|
||||
|
||||
const cases = [
|
||||
[null, 'dCNOmK_nSY-12vHzasLXiswzlGT5UHA7jAGYkvmCuQs'],
|
||||
[42, 'c0dctApWjo2ooEXO0RATfhWfiQrE2og7axfcZRs6gEk'],
|
||||
['foo', 'siEyldVkkW-JpqQkVVZ8h8P0gPzXocFeIg8X1xaaeQs'],
|
||||
[[], 'T1PNoYwrqgwDVLtfmj7L5e0Sq02OEbqHPC8RFhICuUU'],
|
||||
[{}, 'RBNvo1WzZ4oRRq0W9-hknpT7T8If536DEMBg9hyq_4o'],
|
||||
[{ a: 1, b: 2 }, 'LMjVxyj2vtMZ3W1cZ2cJrQij5zn7FBOlPiyBB38OmFE'],
|
||||
[{ b: 2, a: 1 }, 'LMjVxyj2vtMZ3W1cZ2cJrQij5zn7FBOlPiyBB38OmFE'],
|
||||
]
|
||||
|
||||
for (const [value, hash] of cases) {
|
||||
test(JSON.stringify(value), function () {
|
||||
assert.equal(jsonHash(value), hash)
|
||||
})
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "@vates/json-hash",
|
||||
"description": "Compute a stable hash from a JSON-ifiable value",
|
||||
"keywords": [
|
||||
"hash",
|
||||
"json",
|
||||
"stable"
|
||||
],
|
||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/json-hash",
|
||||
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||
"repository": {
|
||||
"directory": "@vates/json-hash",
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Vates SAS",
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "0.2.0",
|
||||
"engines": {
|
||||
"node": ">=14.18.0"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
const assert = require('node:assert')
|
||||
|
||||
const { MultiKeyMap } = require('./')
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ export default class NbdClient {
|
||||
#exportSize
|
||||
|
||||
#waitBeforeReconnect
|
||||
#readAhead
|
||||
#readBlockRetries
|
||||
#reconnectRetry
|
||||
#connectTimeout
|
||||
@@ -54,6 +55,7 @@ export default class NbdClient {
|
||||
connectTimeout = 6e4,
|
||||
messageTimeout = 6e4,
|
||||
waitBeforeReconnect = 1e3,
|
||||
readAhead = 10,
|
||||
readBlockRetries = 5,
|
||||
reconnectRetry = 5,
|
||||
} = {}
|
||||
@@ -63,6 +65,7 @@ export default class NbdClient {
|
||||
this.#exportName = exportname
|
||||
this.#serverCert = cert
|
||||
this.#waitBeforeReconnect = waitBeforeReconnect
|
||||
this.#readAhead = readAhead
|
||||
this.#readBlockRetries = readBlockRetries
|
||||
this.#reconnectRetry = reconnectRetry
|
||||
this.#connectTimeout = connectTimeout
|
||||
|
||||
@@ -6,10 +6,7 @@ import { createLogger } from '@xen-orchestra/log'
|
||||
const { warn } = createLogger('vates:nbd-client:multi')
|
||||
export default class MultiNbdClient {
|
||||
#clients = []
|
||||
#nbdConcurrency
|
||||
#options
|
||||
#readAhead
|
||||
#settings
|
||||
|
||||
get exportSize() {
|
||||
return this.#clients[0].exportSize
|
||||
@@ -17,64 +14,38 @@ export default class MultiNbdClient {
|
||||
|
||||
constructor(settings, { nbdConcurrency = 8, readAhead = 16, ...options } = {}) {
|
||||
this.#readAhead = readAhead
|
||||
this.#options = options
|
||||
this.#nbdConcurrency = nbdConcurrency
|
||||
if (!Array.isArray(settings)) {
|
||||
settings = [settings]
|
||||
}
|
||||
this.#settings = settings
|
||||
for (let i = 0; i < nbdConcurrency; i++) {
|
||||
this.#clients.push(
|
||||
new NbdClient(settings[i % settings.length], { ...options, readAhead: Math.ceil(readAhead / nbdConcurrency) })
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* open nbdConcurrency connections to NBD servers
|
||||
* it must obtain at least one connection to succeed
|
||||
* it tries to spread connections on multiple host
|
||||
*/
|
||||
async connect() {
|
||||
const candidates = [...this.#settings]
|
||||
|
||||
const promises = []
|
||||
const baseOptions = this.#options
|
||||
const _connect = async () => {
|
||||
if (candidates.length === 0) {
|
||||
return
|
||||
}
|
||||
// a little bit of randomization to spread the load
|
||||
const nbdInfo = candidates[Math.floor(Math.random() * candidates.length)]
|
||||
const client = new NbdClient(nbdInfo, {
|
||||
...baseOptions,
|
||||
readAhead: Math.ceil(this.#readAhead / this.#nbdConcurrency),
|
||||
})
|
||||
const connectedClients = []
|
||||
for (const clientId in this.#clients) {
|
||||
const client = this.#clients[clientId]
|
||||
try {
|
||||
await client.connect()
|
||||
this.#clients.push(client)
|
||||
connectedClients.push(client)
|
||||
} catch (err) {
|
||||
client.disconnect().catch(() => {})
|
||||
// do not hammer unreachable hosts, once failed, remove from the list
|
||||
const candidateIndex = candidates.findIndex(({ address }) => address === nbdInfo.address)
|
||||
if (candidateIndex >= 0) {
|
||||
// this candidate may have already been deleted by another parallel promise
|
||||
candidates.splice(candidateIndex, 1)
|
||||
}
|
||||
|
||||
warn(`can't connect to one nbd client`, { err })
|
||||
// retry with another candidate (if available)
|
||||
return _connect()
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < this.#nbdConcurrency; i++) {
|
||||
promises.push(_connect())
|
||||
}
|
||||
await Promise.all(promises)
|
||||
|
||||
if (this.#clients.length === 0) {
|
||||
if (connectedClients.length === 0) {
|
||||
throw new Error(`Fail to connect to any Nbd client`)
|
||||
}
|
||||
if (this.#clients.length < this.#nbdConcurrency) {
|
||||
if (connectedClients.length < this.#clients.length) {
|
||||
warn(
|
||||
`incomplete connection by multi Nbd, only ${this.#clients.length} over ${this.#nbdConcurrency} expected clients`
|
||||
`incomplete connection by multi Nbd, only ${connectedClients.length} over ${
|
||||
this.#clients.length
|
||||
} expected clients`
|
||||
)
|
||||
this.#clients = connectedClients
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "3.1.1",
|
||||
"version": "3.0.0",
|
||||
"engines": {
|
||||
"node": ">=14.0"
|
||||
},
|
||||
@@ -22,16 +22,16 @@
|
||||
"@vates/async-each": "^1.0.0",
|
||||
"@vates/read-chunk": "^1.2.0",
|
||||
"@xen-orchestra/async-map": "^0.1.2",
|
||||
"@xen-orchestra/log": "^0.7.0",
|
||||
"@xen-orchestra/log": "^0.6.0",
|
||||
"promise-toolbox": "^0.21.0",
|
||||
"xen-api": "^4.4.0"
|
||||
"xen-api": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^18.7.0",
|
||||
"tap": "^16.3.0",
|
||||
"tmp": "^0.2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test-integration": "tap --allow-incomplete-coverage"
|
||||
"test-integration": "tap --lines 97 --functions 95 --branches 74 --statements 97 tests/*.integ.mjs"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,14 +78,15 @@ async function killNbdKit() {
|
||||
)
|
||||
}
|
||||
|
||||
test('it works secured network', async tap => {
|
||||
test('it works with unsecured network', async tap => {
|
||||
const path = await createTempFile(FILE_SIZE)
|
||||
|
||||
let nbdServer = await spawnNbdKit(path)
|
||||
const connectionSettings = {
|
||||
address: '127.0.0.1',
|
||||
exportname: 'MY_SECRET_EXPORT',
|
||||
cert: `-----BEGIN CERTIFICATE-----
|
||||
const client = new MultiNbdClient(
|
||||
{
|
||||
address: '127.0.0.1',
|
||||
exportname: 'MY_SECRET_EXPORT',
|
||||
cert: `-----BEGIN CERTIFICATE-----
|
||||
MIIDazCCAlOgAwIBAgIUeHpQ0IeD6BmP2zgsv3LV3J4BI/EwDQYJKoZIhvcNAQEL
|
||||
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
|
||||
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMzA1MTcxMzU1MzBaFw0yNDA1
|
||||
@@ -107,18 +108,12 @@ CYu1Xn/FVPx1HoRgWc7E8wFhDcA/P3SJtfIQWHB9FzSaBflKGR4t8WCE2eE8+cTB
|
||||
57ABhfYpMlZ4aHjuN1bL
|
||||
-----END CERTIFICATE-----
|
||||
`,
|
||||
}
|
||||
const invalid = {
|
||||
address: '500.500.500.500',
|
||||
port: 0,
|
||||
exportname: 'nop',
|
||||
}
|
||||
// it should work even with some broken servers
|
||||
const nbdInfos = [connectionSettings, connectionSettings, invalid]
|
||||
const client = new MultiNbdClient(nbdInfos, {
|
||||
nbdConcurrency: 4,
|
||||
readAhead: 2,
|
||||
})
|
||||
},
|
||||
{
|
||||
nbdConcurrency: 1,
|
||||
readAhead: 2,
|
||||
}
|
||||
)
|
||||
|
||||
await client.connect()
|
||||
tap.equal(client.exportSize, BigInt(FILE_SIZE))
|
||||
@@ -161,18 +156,3 @@ CYu1Xn/FVPx1HoRgWc7E8wFhDcA/P3SJtfIQWHB9FzSaBflKGR4t8WCE2eE8+cTB
|
||||
nbdServer.kill()
|
||||
await fs.unlink(path)
|
||||
})
|
||||
|
||||
test('fails if server does not answer', async () => {
|
||||
const client = new MultiNbdClient(
|
||||
{
|
||||
address: '500.500.500.500',
|
||||
port: 0,
|
||||
exportname: 'nop',
|
||||
},
|
||||
{
|
||||
nbdConcurrency: 1,
|
||||
readAhead: 2,
|
||||
}
|
||||
)
|
||||
await assert.rejects(client.connect())
|
||||
})
|
||||
|
||||
@@ -17,20 +17,7 @@ import https from 'node:https'
|
||||
import util from 'util'
|
||||
import soap from 'soap'
|
||||
import Cookie from 'soap-cookie' // required for session persistence
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
|
||||
const { warn } = createLogger('xo:node-vsphere-soap:client')
|
||||
class VmwareError extends Error {
|
||||
constructor(rawError) {
|
||||
super(rawError.body)
|
||||
const matches = rawError.body?.match(/<faultstring[^>]*>(.*)<\/faultstring>/im)
|
||||
this.message = matches?.[1] ?? rawError.message
|
||||
this.name = 'VmwareError'
|
||||
this.stack = rawError.stack
|
||||
// not putting the cause since the error failed to be stringified correctly down the road
|
||||
warn(rawError)
|
||||
}
|
||||
}
|
||||
// Client class
|
||||
// inherits from EventEmitter
|
||||
// possible events: connect, error, ready
|
||||
@@ -44,20 +31,14 @@ export function Client(vCenterHostname, username, password, sslVerify) {
|
||||
EventEmitter.call(this)
|
||||
|
||||
// sslVerify argument handling
|
||||
// don't use any proxy to connect to the esxi
|
||||
if (sslVerify) {
|
||||
this.clientopts = {
|
||||
request: axios.create({
|
||||
proxy: false,
|
||||
}),
|
||||
}
|
||||
this.clientopts = {}
|
||||
} else {
|
||||
this.clientopts = {
|
||||
request: axios.create({
|
||||
httpsAgent: new https.Agent({
|
||||
rejectUnauthorized: false,
|
||||
}),
|
||||
proxy: false,
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -153,9 +134,8 @@ Client.prototype._connect = function () {
|
||||
self.clientopts,
|
||||
function (err, client) {
|
||||
if (err) {
|
||||
const vErr = new VmwareError(err)
|
||||
self.emit('error', vErr)
|
||||
throw vErr
|
||||
self.emit('error', err)
|
||||
throw err
|
||||
}
|
||||
|
||||
self.client = client // save client for later use
|
||||
@@ -164,7 +144,6 @@ Client.prototype._connect = function () {
|
||||
.runCommand('RetrieveServiceContent', { _this: 'ServiceInstance' })
|
||||
.once('result', function (result, raw, soapHeader) {
|
||||
if (!result.returnval) {
|
||||
// this is a domain/server error return it as is
|
||||
self.status = 'disconnected'
|
||||
self.emit('error', raw)
|
||||
return
|
||||
@@ -223,7 +202,7 @@ Client.prototype._close = function () {
|
||||
function _soapErrorHandler(self, emitter, command, args, err) {
|
||||
err = err || { body: 'general error' }
|
||||
|
||||
if (err.body?.match(/session is not authenticated/)) {
|
||||
if (err.body.match(/session is not authenticated/)) {
|
||||
self.status = 'disconnected'
|
||||
process.removeAllListeners('beforeExit')
|
||||
|
||||
@@ -235,19 +214,16 @@ function _soapErrorHandler(self, emitter, command, args, err) {
|
||||
emitter.emit('result', result, raw, soapHeader)
|
||||
})
|
||||
.once('error', function (err) {
|
||||
const vErr = new VmwareError(err)
|
||||
emitter.emit('error', vErr)
|
||||
throw vErr
|
||||
emitter.emit('error', err.body)
|
||||
throw err
|
||||
})
|
||||
} else {
|
||||
const vErr = new VmwareError(err)
|
||||
emitter.emit('error', vErr)
|
||||
throw vErr
|
||||
emitter.emit('error', err.body)
|
||||
throw err
|
||||
}
|
||||
} else {
|
||||
const vErr = new VmwareError(err)
|
||||
emitter.emit('error', vErr)
|
||||
throw vErr
|
||||
emitter.emit('error', err.body)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vates/node-vsphere-soap",
|
||||
"version": "2.1.1",
|
||||
"version": "2.0.0",
|
||||
"description": "interface to vSphere SOAP/WSDL from node for interfacing with vCenter or ESXi, forked from node-vsphere-soap",
|
||||
"main": "lib/client.mjs",
|
||||
"author": "reedog117",
|
||||
@@ -11,11 +11,13 @@
|
||||
},
|
||||
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||
"dependencies": {
|
||||
"@xen-orchestra/log": "^0.7.0",
|
||||
"axios": "^1.4.0",
|
||||
"soap": "^1.0.0",
|
||||
"soap-cookie": "^0.10.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.3.0"
|
||||
},
|
||||
"keywords": [
|
||||
"vsphere",
|
||||
"vcenter",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import assert from 'assert'
|
||||
import { describe, it } from 'node:test'
|
||||
import { describe, it } from 'test'
|
||||
|
||||
import * as vc from '../lib/client.mjs'
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
### `replace(value, replacement)`
|
||||
|
||||
> Recursively replace sensitive entries with a replacement value.
|
||||
|
||||
```js
|
||||
import { replace } from '@vates/obfuscate'
|
||||
|
||||
replace({ username: 'foo', password: 'bar' }, 'obfuscated')
|
||||
// → { username: 'foo', password: 'obfuscated'}
|
||||
```
|
||||
|
||||
### `obfuscate(value)`
|
||||
|
||||
> Recursively replace sensitive entries with a special tag.
|
||||
|
||||
```js
|
||||
import { obfuscate } from '@vates/obfuscate'
|
||||
|
||||
obfuscate({ username: 'foo', password: 'bar' })
|
||||
// → {
|
||||
// username: 'foo',
|
||||
// password: 'obfuscated-q3oi6d9X8uenGvdLnHk2',
|
||||
// }
|
||||
```
|
||||
|
||||
### `merge(newValue, oldValue)`
|
||||
|
||||
> Replace entries obfuscated by `obfuscate()` in the new value by entries from the old one.
|
||||
>
|
||||
> This is especially useful to give an obfuscated value to a client, let them modify it, and then merge modified and unmodified values.
|
||||
|
||||
```js
|
||||
import { obfuscate, merge } from '@vates/obfuscate'
|
||||
|
||||
const original = { username: 'foo', password: 'bar', token: 'baz' }
|
||||
|
||||
// compute an obfuscated value to send to a client
|
||||
const obfuscated = obfuscate(original)
|
||||
|
||||
// let the client update any entries
|
||||
obfuscated.token = 'qux'
|
||||
|
||||
// merge the updated value with the original one
|
||||
merge(obfuscated, original)
|
||||
// → { username: 'foo', password: 'bar', token: 'qux' }
|
||||
```
|
||||
@@ -1 +0,0 @@
|
||||
../../scripts/npmignore
|
||||
@@ -1,77 +0,0 @@
|
||||
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||
|
||||
# @vates/obfuscate
|
||||
|
||||
[](https://npmjs.org/package/@vates/obfuscate)  [](https://bundlephobia.com/result?p=@vates/obfuscate) [](https://npmjs.org/package/@vates/obfuscate)
|
||||
|
||||
## Install
|
||||
|
||||
Installation of the [npm package](https://npmjs.org/package/@vates/obfuscate):
|
||||
|
||||
```sh
|
||||
npm install --save @vates/obfuscate
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### `replace(value, replacement)`
|
||||
|
||||
> Recursively replace sensitive entries with a replacement value.
|
||||
|
||||
```js
|
||||
import { replace } from '@vates/obfuscate'
|
||||
|
||||
replace({ username: 'foo', password: 'bar' }, 'obfuscated')
|
||||
// → { username: 'foo', password: 'obfuscated'}
|
||||
```
|
||||
|
||||
### `obfuscate(value)`
|
||||
|
||||
> Recursively replace sensitive entries with a special tag.
|
||||
|
||||
```js
|
||||
import { obfuscate } from '@vates/obfuscate'
|
||||
|
||||
obfuscate({ username: 'foo', password: 'bar' })
|
||||
// → {
|
||||
// username: 'foo',
|
||||
// password: 'obfuscated-q3oi6d9X8uenGvdLnHk2',
|
||||
// }
|
||||
```
|
||||
|
||||
### `merge(newValue, oldValue)`
|
||||
|
||||
> Replace entries obfuscated by `obfuscate()` in the new value by entries from the old one.
|
||||
>
|
||||
> This is especially useful to give an obfuscated value to a client, let them modify it, and then merge modified and unmodified values.
|
||||
|
||||
```js
|
||||
import { obfuscate, merge } from '@vates/obfuscate'
|
||||
|
||||
const original = { username: 'foo', password: 'bar', token: 'baz' }
|
||||
|
||||
// compute an obfuscated value to send to a client
|
||||
const obfuscated = obfuscate(original)
|
||||
|
||||
// let the client update any entries
|
||||
obfuscated.token = 'qux'
|
||||
|
||||
// merge the updated value with the original one
|
||||
merge(obfuscated, original)
|
||||
// → { username: 'foo', password: 'bar', token: 'qux' }
|
||||
```
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are _very_ welcomed, either on the documentation or on
|
||||
the code.
|
||||
|
||||
You may:
|
||||
|
||||
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||
you've encountered;
|
||||
- fork and create a pull request.
|
||||
|
||||
## License
|
||||
|
||||
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "@vates/obfuscate",
|
||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/obfuscate",
|
||||
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||
"repository": {
|
||||
"directory": "@vates/obfuscate",
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Vates SAS",
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "0.1.0",
|
||||
"engines": {
|
||||
"node": ">=8.10"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public"
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,6 @@ function assert(name, value) {
|
||||
}
|
||||
}
|
||||
|
||||
const WHITESPACES = /\s+/g
|
||||
function cleanToken(otp) {
|
||||
// remove whitespaces
|
||||
//
|
||||
// some OTP clients add whitespaces for better readability (e.g. `XXX XXX`)
|
||||
// and users might be tempted to write them
|
||||
return otp && otp.replace(WHITESPACES, '')
|
||||
}
|
||||
|
||||
// https://github.com/google/google-authenticator/wiki/Key-Uri-Format
|
||||
function generateUri(protocol, label, params) {
|
||||
assert('label', typeof label === 'string')
|
||||
@@ -73,7 +64,7 @@ export function generateHotpUri({ counter, digits, issuer, label, secret }) {
|
||||
}
|
||||
|
||||
export async function verifyHotp(token, opts) {
|
||||
return cleanToken(token) === (await generateHotp(opts))
|
||||
return token === (await generateHotp(opts))
|
||||
}
|
||||
|
||||
function totpCounter(period = 30, timestamp = Math.floor(Date.now() / 1e3)) {
|
||||
@@ -94,7 +85,6 @@ export async function verifyTotp(token, { period, timestamp, window = 1, ...opts
|
||||
const counter = totpCounter(period, timestamp)
|
||||
const end = counter + window
|
||||
opts.counter = counter - window
|
||||
token = cleanToken(token)
|
||||
while (opts.counter <= end) {
|
||||
if (token === (await generateHotp(opts))) {
|
||||
return true
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { strict as assert } from 'node:assert'
|
||||
import test from 'node:test'
|
||||
import { describe, it } from 'tap/mocha'
|
||||
|
||||
import {
|
||||
generateHotp,
|
||||
@@ -11,8 +11,6 @@ import {
|
||||
verifyTotp,
|
||||
} from './index.mjs'
|
||||
|
||||
const { describe, it } = test
|
||||
|
||||
describe('generateSecret', function () {
|
||||
it('generates a string of 32 chars', async function () {
|
||||
const secret = generateSecret()
|
||||
@@ -22,7 +22,7 @@
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "1.1.0",
|
||||
"version": "1.0.0",
|
||||
"engines": {
|
||||
"node": ">=15"
|
||||
},
|
||||
@@ -31,6 +31,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "tap"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^16.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,9 @@ exports.parseDuration = value => {
|
||||
if (typeof value === 'number') {
|
||||
return value
|
||||
}
|
||||
if (typeof value === 'string' && value !== '') {
|
||||
const duration = ms(value)
|
||||
if (duration !== undefined) {
|
||||
return duration
|
||||
}
|
||||
const duration = ms(value)
|
||||
if (duration === undefined) {
|
||||
throw new TypeError(`not a valid duration: ${value}`)
|
||||
}
|
||||
throw new TypeError(`not a valid duration: ${value}`)
|
||||
return duration
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import { parseDuration } from '@vates/parse-duration'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
describe('parseDuration()', () => {
|
||||
it('should parse string', () => {
|
||||
const input = '2 days'
|
||||
const expected = 172800000
|
||||
assert.strictEqual(parseDuration(input), expected)
|
||||
})
|
||||
|
||||
it('should return its input if already a number', () => {
|
||||
const input = 172800000
|
||||
assert.strictEqual(parseDuration(input), input)
|
||||
})
|
||||
|
||||
for (const input of [undefined, '', 'invalid duration']) {
|
||||
it('should throw an error for ' + input, () => {
|
||||
assert.throws(() => parseDuration(input), { message: `not a valid duration: ${input}` })
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -27,7 +27,6 @@
|
||||
"ms": "^2.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"postversion": "npm publish --access public"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert/strict')
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('tap').mocha
|
||||
|
||||
const { every, not, some } = require('./')
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "tap"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^16.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
const assert = require('node:assert').strict
|
||||
|
||||
const { Readable } = require('stream')
|
||||
|
||||
@@ -25,12 +25,15 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"author": {
|
||||
"name": "Vates SAS",
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"isutf8": "^4.0.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
const assert = require('node:assert').strict
|
||||
|
||||
const { Readable } = require('stream')
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,15 +49,6 @@ const result = await task.runInside(fn)
|
||||
// if fn rejects, the task will be marked as failed
|
||||
// if fn resolves, the task will be marked as succeeded
|
||||
const result = await task.run(fn)
|
||||
|
||||
// manually starts the task
|
||||
task.start()
|
||||
|
||||
// manually finishes the task in success state
|
||||
task.success(result)
|
||||
|
||||
// manually finishes the task in failure state
|
||||
task.failure(error)
|
||||
```
|
||||
|
||||
Inside a task:
|
||||
@@ -81,27 +72,6 @@ Task.warning(message, data)
|
||||
Task.set(property, value)
|
||||
```
|
||||
|
||||
### `Task.run([opts], fn, ...args)`
|
||||
|
||||
This is a convenient shortcut to `new Task(opts).run(() => fn(...args))`.
|
||||
|
||||
```js
|
||||
// options can be passed
|
||||
await Task.run({ properties: { name: 'foo' } }, fn)
|
||||
|
||||
// arguments can be passed
|
||||
await Task.run(fn, 'foo', 'bar')
|
||||
|
||||
// context (this) is forwarded
|
||||
await Task.run.call(object, object.method)
|
||||
|
||||
// as a convenience, you can pass a method name directly
|
||||
await Task.run.call(object, 'method')
|
||||
|
||||
// everything together
|
||||
await Task.run.call(object, 'method', 'foo', 'bar')
|
||||
```
|
||||
|
||||
### `combineEvents`
|
||||
|
||||
Create a consolidated log from individual events.
|
||||
|
||||
@@ -65,15 +65,6 @@ const result = await task.runInside(fn)
|
||||
// if fn rejects, the task will be marked as failed
|
||||
// if fn resolves, the task will be marked as succeeded
|
||||
const result = await task.run(fn)
|
||||
|
||||
// manually starts the task
|
||||
task.start()
|
||||
|
||||
// manually finishes the task in success state
|
||||
task.success(result)
|
||||
|
||||
// manually finishes the task in failure state
|
||||
task.failure(error)
|
||||
```
|
||||
|
||||
Inside a task:
|
||||
@@ -97,27 +88,6 @@ Task.warning(message, data)
|
||||
Task.set(property, value)
|
||||
```
|
||||
|
||||
### `Task.run([opts], fn, ...args)`
|
||||
|
||||
This is a convenient shortcut to `new Task(opts).run(() => fn(...args))`.
|
||||
|
||||
```js
|
||||
// options can be passed
|
||||
await Task.run({ properties: { name: 'foo' } }, fn)
|
||||
|
||||
// arguments can be passed
|
||||
await Task.run(fn, 'foo', 'bar')
|
||||
|
||||
// context (this) is forwarded
|
||||
await Task.run.call(object, object.method)
|
||||
|
||||
// as a convenience, you can pass a method name directly
|
||||
await Task.run.call(object, 'method')
|
||||
|
||||
// everything together
|
||||
await Task.run.call(object, 'method', 'foo', 'bar')
|
||||
```
|
||||
|
||||
### `combineEvents`
|
||||
|
||||
Create a consolidated log from individual events.
|
||||
|
||||
@@ -44,8 +44,6 @@ exports.makeOnProgress = function ({ onRootTaskEnd = noop, onRootTaskStart = noo
|
||||
} else if (type === 'property') {
|
||||
;(taskLog.properties ?? (taskLog.properties = { __proto__: null }))[event.name] = event.value
|
||||
} else if (type === 'end') {
|
||||
taskLogs.delete(id)
|
||||
|
||||
taskLog.end = event.timestamp
|
||||
taskLog.result = event.result
|
||||
taskLog.status = event.status
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert').strict
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
|
||||
const { makeOnProgress } = require('./combineEvents.js')
|
||||
const { Task } = require('./index.js')
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
const assert = require('node:assert').strict
|
||||
const { AsyncLocalStorage } = require('node:async_hooks')
|
||||
|
||||
function alreadyEnded() {
|
||||
throw new Error('task has already ended')
|
||||
}
|
||||
|
||||
// define a read-only, non-enumerable, non-configurable property
|
||||
function define(object, property, value) {
|
||||
Object.defineProperty(object, property, { value })
|
||||
@@ -25,7 +21,7 @@ const asyncStorage = global[asyncStorageKey] ?? (global[asyncStorageKey] = new A
|
||||
|
||||
const getTask = () => asyncStorage.getStore()
|
||||
|
||||
class Task {
|
||||
exports.Task = class Task {
|
||||
static get abortSignal() {
|
||||
const task = getTask()
|
||||
if (task !== undefined) {
|
||||
@@ -33,25 +29,29 @@ class Task {
|
||||
}
|
||||
}
|
||||
|
||||
static run(...args) {
|
||||
let opts = args[0]
|
||||
let fn
|
||||
if (typeof opts === 'object') {
|
||||
args.shift()
|
||||
fn = args[0]
|
||||
} else {
|
||||
fn = opts
|
||||
opts = undefined
|
||||
static info(message, data) {
|
||||
const task = getTask()
|
||||
if (task !== undefined) {
|
||||
task.#emit('info', { data, message })
|
||||
}
|
||||
args.shift()
|
||||
}
|
||||
|
||||
const thisArg = this !== Task ? this : undefined
|
||||
static run(opts, fn) {
|
||||
return new this(opts).run(fn)
|
||||
}
|
||||
|
||||
if (typeof fn !== 'function') {
|
||||
fn = this[fn]
|
||||
static set(name, value) {
|
||||
const task = getTask()
|
||||
if (task !== undefined) {
|
||||
task.#emit('property', { name, value })
|
||||
}
|
||||
}
|
||||
|
||||
return new Task(opts).run(() => fn.apply(thisArg, args))
|
||||
static warning(message, data) {
|
||||
const task = getTask()
|
||||
if (task !== undefined) {
|
||||
task.#emit('warning', { data, message })
|
||||
}
|
||||
}
|
||||
|
||||
static wrap(opts, fn) {
|
||||
@@ -110,7 +110,9 @@ class Task {
|
||||
this.#emit('abortionRequested', { reason: signal.reason })
|
||||
|
||||
if (!this.#running) {
|
||||
this.#end(FAILURE, signal.reason)
|
||||
const status = FAILURE
|
||||
this.#status = status
|
||||
this.#emit('end', { result: signal.reason, status })
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -121,41 +123,25 @@ class Task {
|
||||
}
|
||||
|
||||
#emit(type, data) {
|
||||
assert.equal(this.#startData, undefined, 'task has not started yet')
|
||||
|
||||
data.id = this.id
|
||||
data.timestamp = Date.now()
|
||||
data.type = type
|
||||
this.#onProgress(data)
|
||||
}
|
||||
|
||||
#end(status, result) {
|
||||
assert.equal(this.#status, PENDING)
|
||||
assert.equal(this.#running, false)
|
||||
|
||||
this.#emit('end', { status, result })
|
||||
this.#onProgress = alreadyEnded
|
||||
this.#status = status
|
||||
}
|
||||
|
||||
failure(error) {
|
||||
this.#end(FAILURE, error)
|
||||
}
|
||||
|
||||
info(message, data) {
|
||||
this.#emit('info', { data, message })
|
||||
}
|
||||
|
||||
#maybeStart() {
|
||||
if (this.#startData !== undefined) {
|
||||
this.start()
|
||||
const startData = this.#startData
|
||||
if (startData !== undefined) {
|
||||
this.#startData = undefined
|
||||
this.#emit('start', startData)
|
||||
}
|
||||
}
|
||||
|
||||
async run(fn) {
|
||||
const result = await this.runInside(fn)
|
||||
if (this.status === PENDING) {
|
||||
this.#end(SUCCESS, result)
|
||||
this.#status = SUCCESS
|
||||
this.#emit('end', { status: SUCCESS, result })
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -169,40 +155,18 @@ class Task {
|
||||
this.#maybeStart()
|
||||
|
||||
try {
|
||||
const result = await asyncStorage.run(this, fn, this)
|
||||
const result = await asyncStorage.run(this, fn)
|
||||
this.#running = false
|
||||
return result
|
||||
} catch (result) {
|
||||
this.#running = false
|
||||
this.#end(FAILURE, result)
|
||||
const status = FAILURE
|
||||
|
||||
this.#status = status
|
||||
this.#emit('end', { status, result })
|
||||
throw result
|
||||
}
|
||||
}
|
||||
|
||||
set(name, value) {
|
||||
assert.equal(this.status, PENDING)
|
||||
|
||||
this.#emit('property', { name, value })
|
||||
}
|
||||
|
||||
start() {
|
||||
const startData = this.#startData
|
||||
assert.notEqual(startData, undefined, 'task has already started')
|
||||
|
||||
this.#startData = undefined
|
||||
this.#emit('start', startData)
|
||||
}
|
||||
|
||||
success(result) {
|
||||
this.#end(SUCCESS, result)
|
||||
}
|
||||
|
||||
warning(message, data) {
|
||||
assert.equal(this.status, PENDING)
|
||||
|
||||
this.#emit('warning', { data, message })
|
||||
}
|
||||
|
||||
wrap(fn) {
|
||||
const task = this
|
||||
return function taskRun() {
|
||||
@@ -217,15 +181,3 @@ class Task {
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Task = Task
|
||||
|
||||
// setup static aliases
|
||||
for (const name of ['info', 'set', 'warning']) {
|
||||
const method = Task.prototype[name]
|
||||
Task[name] = function () {
|
||||
const task = getTask()
|
||||
if (task !== undefined) {
|
||||
return method.apply(task, arguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert').strict
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
|
||||
const { makeOnProgress } = require('./combineEvents.js')
|
||||
const { Task } = require('./index.js')
|
||||
|
||||
const noop = Function.prototype
|
||||
@@ -145,43 +144,6 @@ describe('Task', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#failure()', function () {
|
||||
const error = new Error()
|
||||
|
||||
it('throws if the task has not started yet', function () {
|
||||
const task = createTask()
|
||||
|
||||
assert.throws(() => task.failure(error), { message: 'task has not started yet' })
|
||||
})
|
||||
|
||||
it('throws if the task is running', function () {
|
||||
const task = createTask()
|
||||
task.runInside(noop)
|
||||
|
||||
assert.throws(() => task.failure(error), { code: 'ERR_ASSERTION' })
|
||||
})
|
||||
|
||||
it('throws if the task has already finished', function () {
|
||||
const task = createTask()
|
||||
task.start()
|
||||
task.success()
|
||||
|
||||
assert.throws(() => task.failure(error), { code: 'ERR_ASSERTION' })
|
||||
})
|
||||
|
||||
it('finishes the task and mark it as failed', function () {
|
||||
const task = createTask()
|
||||
task.start()
|
||||
task.failure(error)
|
||||
|
||||
assertEvent(task, {
|
||||
status: 'failure',
|
||||
result: error,
|
||||
type: 'end',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('.info()', function () {
|
||||
it('does nothing when run outside a task', function () {
|
||||
Task.info('foo')
|
||||
@@ -200,44 +162,6 @@ describe('Task', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('.run()', function () {
|
||||
function fn(...args) {
|
||||
Task.set('baz', 'qux')
|
||||
|
||||
return [this, ...args]
|
||||
}
|
||||
const obj = { fn }
|
||||
|
||||
it('accepts optional options', async function () {
|
||||
assert.deepEqual(
|
||||
await Task.run(
|
||||
{
|
||||
properties: { foo: 'bar' },
|
||||
onProgress: makeOnProgress({
|
||||
onRootTaskEnd(log) {
|
||||
assert.deepEqual(log.properties, { __proto__: null, foo: 'bar', baz: 'qux' })
|
||||
},
|
||||
}),
|
||||
},
|
||||
fn
|
||||
),
|
||||
[undefined]
|
||||
)
|
||||
})
|
||||
|
||||
it('accepts optional arguments', async function () {
|
||||
assert.deepEqual(await Task.run(fn, 'foo', 'bar'), [undefined, 'foo', 'bar'])
|
||||
})
|
||||
|
||||
it('accepts optional context', async function () {
|
||||
assert.deepEqual(await Task.run.call('foo', fn), ['foo'])
|
||||
})
|
||||
|
||||
it('accepts a method name instead of a function', async function () {
|
||||
assert.deepEqual(await Task.run.call(obj, 'fn'), [obj])
|
||||
})
|
||||
})
|
||||
|
||||
describe('.set()', function () {
|
||||
it('does nothing when run outside a task', function () {
|
||||
Task.set('progress', 10)
|
||||
@@ -256,84 +180,6 @@ describe('Task', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#set()', function () {
|
||||
const name = 'progress'
|
||||
const value = 10
|
||||
|
||||
it('throws when the task is not started', function () {
|
||||
const task = createTask()
|
||||
assert.throws(() => task.set(name, value), { message: 'task has not started yet' })
|
||||
})
|
||||
|
||||
it(`emits an property message`, async function () {
|
||||
const task = createTask()
|
||||
await task.run(async () => {
|
||||
await Task.run(() => {
|
||||
task.set(name, value)
|
||||
|
||||
assertEvent(task, {
|
||||
name,
|
||||
type: 'property',
|
||||
value,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('#start', function () {
|
||||
it('starts the task', function () {
|
||||
const task = createTask()
|
||||
task.start()
|
||||
|
||||
assertEvent(task, { type: 'start' })
|
||||
})
|
||||
|
||||
it('throws when the task has already started', function () {
|
||||
const task = createTask()
|
||||
task.start()
|
||||
|
||||
assert.throws(() => task.start(), { message: 'task has already started' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('#success()', function () {
|
||||
const result = {}
|
||||
|
||||
it('throws if the task has not started yet', function () {
|
||||
const task = createTask()
|
||||
|
||||
assert.throws(() => task.success(result), { message: 'task has not started yet' })
|
||||
})
|
||||
|
||||
it('throws if the task is running', function () {
|
||||
const task = createTask()
|
||||
task.runInside(noop)
|
||||
|
||||
assert.throws(() => task.success(result), { code: 'ERR_ASSERTION' })
|
||||
})
|
||||
|
||||
it('throws if the task has already finished', function () {
|
||||
const task = createTask()
|
||||
task.start()
|
||||
task.success()
|
||||
|
||||
assert.throws(() => task.success(result), { code: 'ERR_ASSERTION' })
|
||||
})
|
||||
|
||||
it('finishes the task and mark it as successful', function () {
|
||||
const task = createTask()
|
||||
task.start()
|
||||
task.success(result)
|
||||
|
||||
assertEvent(task, {
|
||||
status: 'success',
|
||||
result,
|
||||
type: 'end',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('.warning()', function () {
|
||||
it('does nothing when run outside a task', function () {
|
||||
Task.warning('foo')
|
||||
@@ -352,30 +198,6 @@ describe('Task', function () {
|
||||
})
|
||||
})
|
||||
|
||||
for (const type of ['info', 'warning']) {
|
||||
describe(`#${type}()`, function () {
|
||||
it('throws when the task is not started', function () {
|
||||
const task = createTask()
|
||||
assert.throws(() => task[type]('foo'), { message: 'task has not started yet' })
|
||||
})
|
||||
|
||||
it(`emits an ${type} message`, async function () {
|
||||
const task = createTask()
|
||||
await task.run(async () => {
|
||||
await Task.run(() => {
|
||||
task[type]('foo')
|
||||
|
||||
assertEvent(task, {
|
||||
data: undefined,
|
||||
message: 'foo',
|
||||
type,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
describe('#id', function () {
|
||||
it('can be set', function () {
|
||||
const task = createTask()
|
||||
|
||||
@@ -13,13 +13,16 @@
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "0.5.0",
|
||||
"version": "0.2.0",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"test": "^3.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"exports": {
|
||||
".": "./index.js",
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
### Formatting
|
||||
|
||||
```js
|
||||
import { xmlRpcFormatter } from '@vates/xml-rpc/formatter'
|
||||
|
||||
// There is a dedicated method per XML-RPC tag (`array`, `string`, etc.)
|
||||
xmlRpcFormatter.format_methodCall({
|
||||
methodName: 'examples.getStateName',
|
||||
params: [40],
|
||||
})
|
||||
// → {
|
||||
// name: 'methodCall',
|
||||
// children: [
|
||||
// {
|
||||
// name: 'methodName',
|
||||
// children: [ 'examples.getStateName' ]
|
||||
// },
|
||||
// {
|
||||
// name: 'params',
|
||||
// children: [
|
||||
// {
|
||||
// name: 'param',
|
||||
// children: [ { name: 'value', children: [ '40' ] } ]
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
|
||||
// There is a dedicated method to format a JS value
|
||||
xmlRpcFormatter.format_js(new Date(900684535000))
|
||||
// → {
|
||||
// name: 'dateTime.iso8601',
|
||||
// children: [ '1998-07-17T14:08:55.000Z' ]
|
||||
// }
|
||||
```
|
||||
|
||||
Formatting XML is out of this library's scope, but you can achieve it easily with
|
||||
`@vates/xml`:
|
||||
|
||||
```js
|
||||
import { formatXml } from '@vates/xml/format'
|
||||
|
||||
// it can now be passed to the XML-RPC parser
|
||||
const tree = xmlRpcFormatter.format_methodCall({
|
||||
methodName: 'examples.getStateName',
|
||||
params: [40],
|
||||
})
|
||||
|
||||
// avoid any indentation or new lines as it will confuse many XML-RPC parsers.
|
||||
const xml = formatXml(tree, { indent: 0 })
|
||||
```
|
||||
|
||||
### Parsing
|
||||
|
||||
```js
|
||||
import { xmlRpcParser } from '@vates/xml-rpc/parser'
|
||||
|
||||
xmlRpcParser.parse({
|
||||
name: 'methodResponse',
|
||||
children: [
|
||||
{
|
||||
name: 'params',
|
||||
children: [
|
||||
{
|
||||
name: 'param',
|
||||
children: [
|
||||
{
|
||||
name: 'value',
|
||||
children: [
|
||||
{
|
||||
name: 'string',
|
||||
children: ['South Dakota'],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
// { params: [ 'South Dakota' ] }
|
||||
|
||||
// There is a dedicated method per XML-RPC tag (`array`, `string`, etc.)
|
||||
xmlRpcParser.parse_array({
|
||||
name: 'array',
|
||||
children: [
|
||||
{
|
||||
name: 'data',
|
||||
children: [
|
||||
{
|
||||
name: 'value',
|
||||
children: [{ name: 'boolean', children: ['1'] }],
|
||||
},
|
||||
{
|
||||
name: 'value',
|
||||
children: [{ name: 'int', children: ['42'] }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
// [ true, 42 ]
|
||||
```
|
||||
|
||||
Parsing XML is out of this library's scope, but you can achieve it easily with
|
||||
`@vates/xml`:
|
||||
|
||||
```js
|
||||
import { parseXml } from '@vates/xml/parse'
|
||||
|
||||
const xml = `
|
||||
<?xml version="1.0"?>
|
||||
<methodResponse>
|
||||
<params>
|
||||
<param>
|
||||
<value><string>South Dakota</string></value>
|
||||
</param>
|
||||
</params>
|
||||
</methodResponse>
|
||||
`
|
||||
|
||||
// do not normalize or trim whitespaces as it will break string values
|
||||
const tree = parseXml(xml, { normalize: false, trim: false })
|
||||
|
||||
// it can now be passed to the XML-RPC parser
|
||||
xmlRpcParser.parse(tree)
|
||||
```
|
||||
@@ -1 +0,0 @@
|
||||
../../scripts/npmignore
|
||||
@@ -1,162 +0,0 @@
|
||||
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||
|
||||
# @vates/xml-rpc
|
||||
|
||||
[](https://npmjs.org/package/@vates/xml-rpc)  [](https://bundlephobia.com/result?p=@vates/xml-rpc) [](https://npmjs.org/package/@vates/xml-rpc)
|
||||
|
||||
> Parse and format XML-RPC messages, do not handle transport or XML
|
||||
|
||||
## Install
|
||||
|
||||
Installation of the [npm package](https://npmjs.org/package/@vates/xml-rpc):
|
||||
|
||||
```sh
|
||||
npm install --save @vates/xml-rpc
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Formatting
|
||||
|
||||
```js
|
||||
import { xmlRpcFormatter } from '@vates/xml-rpc/formatter'
|
||||
|
||||
// There is a dedicated method per XML-RPC tag (`array`, `string`, etc.)
|
||||
xmlRpcFormatter.format_methodCall({
|
||||
methodName: 'examples.getStateName',
|
||||
params: [40],
|
||||
})
|
||||
// → {
|
||||
// name: 'methodCall',
|
||||
// children: [
|
||||
// {
|
||||
// name: 'methodName',
|
||||
// children: [ 'examples.getStateName' ]
|
||||
// },
|
||||
// {
|
||||
// name: 'params',
|
||||
// children: [
|
||||
// {
|
||||
// name: 'param',
|
||||
// children: [ { name: 'value', children: [ '40' ] } ]
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
|
||||
// There is a dedicated method to format a JS value
|
||||
xmlRpcFormatter.format_js(new Date(900684535000))
|
||||
// → {
|
||||
// name: 'dateTime.iso8601',
|
||||
// children: [ '1998-07-17T14:08:55.000Z' ]
|
||||
// }
|
||||
```
|
||||
|
||||
Formatting XML is out of this library's scope, but you can achieve it easily with
|
||||
`@vates/xml`:
|
||||
|
||||
```js
|
||||
import { formatXml } from '@vates/xml/format'
|
||||
|
||||
// it can now be passed to the XML-RPC parser
|
||||
const tree = xmlRpcFormatter.format_methodCall({
|
||||
methodName: 'examples.getStateName',
|
||||
params: [40],
|
||||
})
|
||||
|
||||
// avoid any indentation or new lines as it will confuse many XML-RPC parsers.
|
||||
const xml = formatXml(tree, { indent: 0 })
|
||||
```
|
||||
|
||||
### Parsing
|
||||
|
||||
```js
|
||||
import { xmlRpcParser } from '@vates/xml-rpc/parser'
|
||||
|
||||
xmlRpcParser.parse({
|
||||
name: 'methodResponse',
|
||||
children: [
|
||||
{
|
||||
name: 'params',
|
||||
children: [
|
||||
{
|
||||
name: 'param',
|
||||
children: [
|
||||
{
|
||||
name: 'value',
|
||||
children: [
|
||||
{
|
||||
name: 'string',
|
||||
children: ['South Dakota'],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
// { params: [ 'South Dakota' ] }
|
||||
|
||||
// There is a dedicated method per XML-RPC tag (`array`, `string`, etc.)
|
||||
xmlRpcParser.parse_array({
|
||||
name: 'array',
|
||||
children: [
|
||||
{
|
||||
name: 'data',
|
||||
children: [
|
||||
{
|
||||
name: 'value',
|
||||
children: [{ name: 'boolean', children: ['1'] }],
|
||||
},
|
||||
{
|
||||
name: 'value',
|
||||
children: [{ name: 'int', children: ['42'] }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
// [ true, 42 ]
|
||||
```
|
||||
|
||||
Parsing XML is out of this library's scope, but you can achieve it easily with
|
||||
`@vates/xml`:
|
||||
|
||||
```js
|
||||
import { parseXml } from '@vates/xml/parse'
|
||||
|
||||
const xml = `
|
||||
<?xml version="1.0"?>
|
||||
<methodResponse>
|
||||
<params>
|
||||
<param>
|
||||
<value><string>South Dakota</string></value>
|
||||
</param>
|
||||
</params>
|
||||
</methodResponse>
|
||||
`
|
||||
|
||||
// do not normalize or trim whitespaces as it will break string values
|
||||
const tree = parseXml(xml, { normalize: false, trim: false })
|
||||
|
||||
// it can now be passed to the XML-RPC parser
|
||||
xmlRpcParser.parse(tree)
|
||||
```
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are _very_ welcomed, either on the documentation or on
|
||||
the code.
|
||||
|
||||
You may:
|
||||
|
||||
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||
you've encountered;
|
||||
- fork and create a pull request.
|
||||
|
||||
## License
|
||||
|
||||
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)
|
||||
@@ -1,104 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
function node(name, attributes, children) {
|
||||
if (Array.isArray(attributes)) {
|
||||
children = attributes
|
||||
attributes = undefined
|
||||
}
|
||||
|
||||
return { name, attributes, children }
|
||||
}
|
||||
|
||||
class XmlRpcFormatter {
|
||||
format_js(value) {
|
||||
const type = typeof value
|
||||
if (type === 'object') {
|
||||
return value === null
|
||||
? this.format_nil()
|
||||
: value instanceof Date
|
||||
? this['format_dateTime.iso8601'](value)
|
||||
: Array.isArray(value)
|
||||
? this.format_array(value)
|
||||
: Buffer.isBuffer(value)
|
||||
? this.format_base64(value)
|
||||
: this.format_struct(value)
|
||||
}
|
||||
|
||||
return this['format_' + type](value)
|
||||
}
|
||||
|
||||
format_array(values) {
|
||||
return node('array', [node('data', values.map(this.format_value, this))])
|
||||
}
|
||||
|
||||
format_base64(buf) {
|
||||
return node('base64', [buf.toString('base64')])
|
||||
}
|
||||
|
||||
format_boolean(bool) {
|
||||
return node('boolean', [bool ? '1' : '0'])
|
||||
}
|
||||
|
||||
'format_dateTime.iso8601'(date) {
|
||||
return node('dateTime.iso8601', [date.toISOString()])
|
||||
}
|
||||
|
||||
format_double(str) {
|
||||
return node('double', [String(str)])
|
||||
}
|
||||
|
||||
format_fault(val) {
|
||||
return node('fault', [this.format_value(val)])
|
||||
}
|
||||
|
||||
format_i4(str) {
|
||||
return node('i4', [String(str)])
|
||||
}
|
||||
|
||||
format_int(str) {
|
||||
return node('int', [String(str)])
|
||||
}
|
||||
|
||||
format_member([name, value]) {
|
||||
return node('member', [node('name', [name]), this.format_value(value)])
|
||||
}
|
||||
|
||||
format_methodCall({ methodName, params }) {
|
||||
return node('methodCall', [node('methodName', [methodName]), this.format_params(params)])
|
||||
}
|
||||
|
||||
format_methodResponse({ fault, params }) {
|
||||
return node('methodResponse', [fault !== undefined ? this.format_fault(fault) : this.format_params(params)])
|
||||
}
|
||||
|
||||
format_nil() {
|
||||
return node('nil')
|
||||
}
|
||||
|
||||
format_number(num) {
|
||||
return Number.isInteger(num) ? this.format_int(num) : this.format_double(num)
|
||||
}
|
||||
|
||||
format_param(value) {
|
||||
return node('param', [this.format_value(value)])
|
||||
}
|
||||
|
||||
format_params(params) {
|
||||
return node('params', params.map(this.format_param, this))
|
||||
}
|
||||
|
||||
format_string(str) {
|
||||
return str
|
||||
}
|
||||
|
||||
format_struct(struct) {
|
||||
return node('struct', Object.entries(struct).map(this.format_member, this))
|
||||
}
|
||||
|
||||
format_value(value) {
|
||||
return node('value', [this.format_js(value)])
|
||||
}
|
||||
}
|
||||
exports.Formatter = XmlRpcFormatter
|
||||
|
||||
exports.xmlRpcFormatter = new XmlRpcFormatter()
|
||||
@@ -1,32 +0,0 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "@vates/xml-rpc",
|
||||
"description": "Parse and format XML-RPC messages, do not handle transport or XML",
|
||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/xml-rpc",
|
||||
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||
"repository": {
|
||||
"directory": "@vates/xml-rpc",
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Vates SAS",
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "1.0.0",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vates/xml": "^2.0.0"
|
||||
},
|
||||
"exports": {
|
||||
"./formatter": "./formatter.js",
|
||||
"./parser": "./parser.js"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
function toValue(node) {
|
||||
const obj = { __proto__: null }
|
||||
for (const child of node.children) {
|
||||
if (typeof child === 'string') {
|
||||
return child
|
||||
}
|
||||
|
||||
const { name } = child
|
||||
if (Object.hasOwn(obj, name)) {
|
||||
const prev = obj[name]
|
||||
if (Array.isArray(obj, name)) {
|
||||
prev.push(child)
|
||||
} else {
|
||||
obj[name] = [prev, child]
|
||||
}
|
||||
} else {
|
||||
obj[name] = child
|
||||
}
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/XML-RPC#Data_types
|
||||
class XmlRpcParser {
|
||||
parse(node) {
|
||||
return this['parse_' + node.name](node)
|
||||
}
|
||||
|
||||
parse_array({ children: [data] }) {
|
||||
return data.children.map(this.parse_value, this)
|
||||
}
|
||||
|
||||
parse_base64({ children: [str] }) {
|
||||
return Buffer.from(str, 'base64')
|
||||
}
|
||||
|
||||
parse_boolean({ children: [str] }) {
|
||||
return Boolean(Number(str))
|
||||
}
|
||||
|
||||
'parse_dateTime.iso8601'({ children: [str] }) {
|
||||
const date = new Date(str)
|
||||
|
||||
// date successfully parsed
|
||||
if (!Number.isNaN(+date)) {
|
||||
return date
|
||||
}
|
||||
|
||||
// XML-RPC dates may use YYYYMMDD instead of YYYY-MM-DD which ECMAScript
|
||||
// does not parse
|
||||
return new Date(str.slice(0, 4) + '-' + str.slice(4, 6) + '-' + str.slice(6))
|
||||
}
|
||||
|
||||
parse_double({ children: [str] }) {
|
||||
return Number(str)
|
||||
}
|
||||
|
||||
parse_fault({ children: [value] }) {
|
||||
return this.parse_value(value)
|
||||
}
|
||||
|
||||
parse_i4({ children: [str] }) {
|
||||
return Number(str)
|
||||
}
|
||||
|
||||
parse_int({ children: [str] }) {
|
||||
return Number(str)
|
||||
}
|
||||
|
||||
parse_member(member) {
|
||||
member = toValue(member)
|
||||
return [member.name.children[0], this.parse_value(member.value)]
|
||||
}
|
||||
|
||||
parse_methodCall(methodCall) {
|
||||
methodCall = toValue(methodCall)
|
||||
return {
|
||||
methodName: methodCall.methodName.children[0],
|
||||
params: this.parse_params(methodCall.params),
|
||||
}
|
||||
}
|
||||
|
||||
parse_methodResponse(methodResponse) {
|
||||
methodResponse = toValue(methodResponse)
|
||||
|
||||
const { fault } = methodResponse
|
||||
if (fault !== undefined) {
|
||||
return { fault: this.parse_fault(fault) }
|
||||
}
|
||||
|
||||
return { params: this.parse_params(methodResponse.params) }
|
||||
}
|
||||
|
||||
parse_nil() {
|
||||
return null
|
||||
}
|
||||
|
||||
parse_param(param) {
|
||||
return this.parse_value(param.children[0])
|
||||
}
|
||||
|
||||
parse_params(params) {
|
||||
return params.children.map(this.parse_param, this)
|
||||
}
|
||||
|
||||
parse_string({ children: [str] }) {
|
||||
return str
|
||||
}
|
||||
|
||||
parse_struct(struct) {
|
||||
return Object.fromEntries(struct.children.map(this.parse_member, this))
|
||||
}
|
||||
|
||||
parse_value({ children }) {
|
||||
if (children.length === 0) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const child = children[0]
|
||||
|
||||
// can be a plain string
|
||||
if (typeof child === 'string') {
|
||||
return child
|
||||
}
|
||||
|
||||
return this.parse(child)
|
||||
}
|
||||
}
|
||||
exports.XmlRpcParser = XmlRpcParser
|
||||
|
||||
exports.xmlRpcParser = new XmlRpcParser()
|
||||
@@ -1,19 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const { formatXml } = require('@vates/xml/format')
|
||||
const { join } = require('node:path')
|
||||
const { parseXml } = require('@vates/xml/parse')
|
||||
const { readFileSync } = require('node:fs')
|
||||
const { xmlRpcFormatter } = require('@vates/xml-rpc/formatter')
|
||||
const assert = require('node:assert/strict')
|
||||
const test = require('node:test')
|
||||
|
||||
const methodCall = require('./methodCall.js')
|
||||
|
||||
test(function () {
|
||||
const xmlTree = parseXml(readFileSync(join(__dirname, 'methodCall.xml')))
|
||||
|
||||
const xmlRpc = xmlRpcFormatter.format_methodCall(methodCall)
|
||||
|
||||
assert.deepEqual(parseXml(formatXml(xmlRpc)), xmlTree)
|
||||
})
|
||||
@@ -1,16 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
methodName: 'examples.getStateName',
|
||||
params: [
|
||||
[1404, 'Something here'],
|
||||
Buffer.from([121, 111, 117, 32, 99, 97, 110, 39, 116, 32, 114, 101, 97, 100, 32, 116, 104, 105, 115, 33]),
|
||||
true,
|
||||
new Date('1998-07-17T14:08:55.000Z'),
|
||||
-12.53,
|
||||
42,
|
||||
'Hello world!',
|
||||
{ foo: 1, bar: 2 },
|
||||
null,
|
||||
],
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<methodCall>
|
||||
<methodName>examples.getStateName</methodName>
|
||||
<params>
|
||||
<param>
|
||||
<value>
|
||||
<array>
|
||||
<data>
|
||||
<value>
|
||||
<int>1404</int>
|
||||
</value>
|
||||
<value>
|
||||
Something here
|
||||
</value>
|
||||
</data>
|
||||
</array>
|
||||
</value>
|
||||
</param>
|
||||
<param>
|
||||
<value>
|
||||
<base64>eW91IGNhbid0IHJlYWQgdGhpcyE=</base64>
|
||||
</value>
|
||||
</param>
|
||||
<param>
|
||||
<value>
|
||||
<boolean>1</boolean>
|
||||
</value>
|
||||
</param>
|
||||
<param>
|
||||
<value>
|
||||
<dateTime.iso8601>1998-07-17T14:08:55.000Z</dateTime.iso8601>
|
||||
</value>
|
||||
</param>
|
||||
<param>
|
||||
<value>
|
||||
<double>-12.53</double>
|
||||
</value>
|
||||
</param>
|
||||
<param>
|
||||
<value>
|
||||
<int>42</int>
|
||||
</value>
|
||||
</param>
|
||||
<param>
|
||||
<value>
|
||||
Hello world!
|
||||
</value>
|
||||
</param>
|
||||
<param>
|
||||
<value>
|
||||
<struct>
|
||||
<member>
|
||||
<name>foo</name>
|
||||
<value>
|
||||
<int>1</int>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>bar</name>
|
||||
<value>
|
||||
<int>2</int>
|
||||
</value>
|
||||
</member>
|
||||
</struct>
|
||||
</value>
|
||||
</param>
|
||||
<param>
|
||||
<value>
|
||||
<nil />
|
||||
</value>
|
||||
</param>
|
||||
</params>
|
||||
</methodCall>
|
||||
@@ -1,32 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const { join } = require('node:path')
|
||||
const { parseXml } = require('@vates/xml/parse')
|
||||
const { readFileSync } = require('node:fs')
|
||||
const { xmlRpcParser } = require('@vates/xml-rpc/parser')
|
||||
const assert = require('node:assert/strict')
|
||||
const test = require('node:test')
|
||||
|
||||
const methodCall = require('./methodCall.js')
|
||||
|
||||
test('parser.parse()', function () {
|
||||
const xml = String(readFileSync(join(__dirname, 'methodCall.xml')))
|
||||
const xmlRpc = parseXml(xml)
|
||||
|
||||
assert.deepEqual(xmlRpcParser.parse(xmlRpc), methodCall)
|
||||
})
|
||||
|
||||
test('datetime without dashes nor milliseconds', function () {
|
||||
assert.deepEqual(
|
||||
xmlRpcParser.parse({ name: 'dateTime.iso8601', children: ['19980717T14:08:55Z'] }),
|
||||
new Date('1998-07-17T14:08:55Z')
|
||||
)
|
||||
})
|
||||
|
||||
test('i4 support', function () {
|
||||
assert.equal(xmlRpcParser.parse({ name: 'i4', children: ['42'] }), 42)
|
||||
})
|
||||
|
||||
test('string support', function () {
|
||||
assert.equal(xmlRpcParser.parse({ name: 'string', children: ['foo'] }), 'foo')
|
||||
})
|
||||
@@ -1,56 +0,0 @@
|
||||
### `parseXml(xml, [opts])`
|
||||
|
||||
> Based on [`sax`](https://www.npmjs.com/package/sax)
|
||||
|
||||
`opts` is an optional object which can contain the following options:
|
||||
|
||||
- `normalize = true`: if true, then turn any whitespace into a single space
|
||||
- `strict = true`: whether or not to be a jerk
|
||||
- `trim = true`: whether or not to trim text nodes
|
||||
|
||||
```js
|
||||
import { parseXml } from '@xen-orchestra/xml/parse'
|
||||
|
||||
const tree = parseXml(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tag1 attr1="value1" attr2="value2">
|
||||
Text & entities
|
||||
<tag2 />
|
||||
<tag2 />
|
||||
<ns:tag3 />
|
||||
</tag1>
|
||||
`)
|
||||
// → {
|
||||
// name: 'tag1',
|
||||
// attributes: { attr1: 'value1', attr2: 'value2' },
|
||||
// children: [
|
||||
// 'Text & entities',
|
||||
// { name: 'tag2', attributes: {}, children: [] },
|
||||
// { name: 'tag2', attributes: {}, children: [] },
|
||||
// { name: 'ns:tag3', attributes: {}, children: [] }
|
||||
// ]
|
||||
// }
|
||||
```
|
||||
|
||||
### `formatXml(tree, [opts])`
|
||||
|
||||
`opts` is an optional object which can contain the following options:
|
||||
|
||||
- `includeDeclaration = true`: whether to include an XML declaration
|
||||
- `indent = 2`: string or number of spaces to use to indent; if an empty string or `0`, no indent or new lines will be used
|
||||
|
||||
```js
|
||||
import { formatXml } from '@xen-orchestra/xml/format'
|
||||
|
||||
formatXml({
|
||||
name: 'tag1',
|
||||
attributes: { attr1: 'value1', attr2: 'value2' },
|
||||
children: ['Text & entities', { name: 'tag2' }, { name: 'tag2' }, { name: 'ns:tag3' }],
|
||||
})
|
||||
// → <?xml version="1.0" encoding="UTF-8"?>
|
||||
// <tag1 attr1="value1" attr2="value2">
|
||||
// Text & entities
|
||||
// <tag2 />
|
||||
// <tag2 />
|
||||
// <ns:tag3 />
|
||||
// </tag1>
|
||||
```
|
||||
@@ -1 +0,0 @@
|
||||
../../scripts/npmignore
|
||||
@@ -1,89 +0,0 @@
|
||||
<!-- DO NOT EDIT MANUALLY, THIS FILE HAS BEEN GENERATED -->
|
||||
|
||||
# @vates/xml
|
||||
|
||||
[](https://npmjs.org/package/@vates/xml)  [](https://bundlephobia.com/result?p=@vates/xml) [](https://npmjs.org/package/@vates/xml)
|
||||
|
||||
> Simple XML formatting/parsing
|
||||
|
||||
## Install
|
||||
|
||||
Installation of the [npm package](https://npmjs.org/package/@vates/xml):
|
||||
|
||||
```sh
|
||||
npm install --save @vates/xml
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### `parseXml(xml, [opts])`
|
||||
|
||||
> Based on [`sax`](https://www.npmjs.com/package/sax)
|
||||
|
||||
`opts` is an optional object which can contain the following options:
|
||||
|
||||
- `normalize = true`: if true, then turn any whitespace into a single space
|
||||
- `strict = true`: whether or not to be a jerk
|
||||
- `trim = true`: whether or not to trim text nodes
|
||||
|
||||
```js
|
||||
import { parseXml } from '@xen-orchestra/xml/parse'
|
||||
|
||||
const tree = parseXml(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tag1 attr1="value1" attr2="value2">
|
||||
Text & entities
|
||||
<tag2 />
|
||||
<tag2 />
|
||||
<ns:tag3 />
|
||||
</tag1>
|
||||
`)
|
||||
// → {
|
||||
// name: 'tag1',
|
||||
// attributes: { attr1: 'value1', attr2: 'value2' },
|
||||
// children: [
|
||||
// 'Text & entities',
|
||||
// { name: 'tag2', attributes: {}, children: [] },
|
||||
// { name: 'tag2', attributes: {}, children: [] },
|
||||
// { name: 'ns:tag3', attributes: {}, children: [] }
|
||||
// ]
|
||||
// }
|
||||
```
|
||||
|
||||
### `formatXml(tree, [opts])`
|
||||
|
||||
`opts` is an optional object which can contain the following options:
|
||||
|
||||
- `includeDeclaration = true`: whether to include an XML declaration
|
||||
- `indent = 2`: string or number of spaces to use to indent; if an empty string or `0`, no indent or new lines will be used
|
||||
|
||||
```js
|
||||
import { formatXml } from '@xen-orchestra/xml/format'
|
||||
|
||||
formatXml({
|
||||
name: 'tag1',
|
||||
attributes: { attr1: 'value1', attr2: 'value2' },
|
||||
children: ['Text & entities', { name: 'tag2' }, { name: 'tag2' }, { name: 'ns:tag3' }],
|
||||
})
|
||||
// → <?xml version="1.0" encoding="UTF-8"?>
|
||||
// <tag1 attr1="value1" attr2="value2">
|
||||
// Text & entities
|
||||
// <tag2 />
|
||||
// <tag2 />
|
||||
// <ns:tag3 />
|
||||
// </tag1>
|
||||
```
|
||||
|
||||
## Contributions
|
||||
|
||||
Contributions are _very_ welcomed, either on the documentation or on
|
||||
the code.
|
||||
|
||||
You may:
|
||||
|
||||
- report any [issue](https://github.com/vatesfr/xen-orchestra/issues)
|
||||
you've encountered;
|
||||
- fork and create a pull request.
|
||||
|
||||
## License
|
||||
|
||||
[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr)
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
const { inspect } = require('node:util')
|
||||
const { formatXml } = require('@vates/xml/format')
|
||||
const { parseXml } = require('@vates/xml/parse')
|
||||
const { readFileSync } = require('node:fs')
|
||||
|
||||
function log(val) {
|
||||
process.stdout.write(inspect(val, false, null, true))
|
||||
process.stdout.write('\n')
|
||||
}
|
||||
|
||||
function main([inputPath = 0]) {
|
||||
const input = readFileSync(inputPath)
|
||||
|
||||
// attempt to parse from JSON
|
||||
let data
|
||||
try {
|
||||
data = JSON.parse(input)
|
||||
} catch (error) {
|
||||
// fallback to XML
|
||||
log(parseXml(input))
|
||||
return
|
||||
}
|
||||
|
||||
process.stdout.write(formatXml(data))
|
||||
}
|
||||
main(process.argv.slice(2))
|
||||
@@ -1,64 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const ENTITIES = {
|
||||
'"': '"',
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
}
|
||||
const RE = new RegExp(Object.keys(ENTITIES).join('|'), 'g')
|
||||
function replace(match) {
|
||||
return ENTITIES[match]
|
||||
}
|
||||
function escape(str) {
|
||||
return str.replace(RE, replace)
|
||||
}
|
||||
|
||||
function formatNode(node, depth) {
|
||||
const indent = this.indent.repeat(depth)
|
||||
|
||||
if (typeof node === 'object') {
|
||||
const line = [indent, '<', node.name]
|
||||
const { attributes } = node
|
||||
if (attributes !== undefined) {
|
||||
for (const name of Object.keys(attributes)) {
|
||||
line.push(' ', name, '="', escape(attributes[name]), '"')
|
||||
}
|
||||
}
|
||||
|
||||
const { children } = node
|
||||
if (children === undefined || children.length === 0) {
|
||||
line.push(' />')
|
||||
this.lines.push(line.join(''))
|
||||
} else {
|
||||
line.push('>')
|
||||
this.lines.push(line.join(''))
|
||||
|
||||
for (const child of children) {
|
||||
formatNode.call(this, child, depth + 1)
|
||||
}
|
||||
|
||||
this.lines.push(indent + '</' + node.name + '>')
|
||||
}
|
||||
} else {
|
||||
// string (or scalar)
|
||||
this.lines.push(indent + escape(String(node)))
|
||||
}
|
||||
}
|
||||
|
||||
exports.formatXml = function formatXml(tree, { includeDeclaration = true, indent = 2 } = {}) {
|
||||
const lines = []
|
||||
|
||||
if (includeDeclaration) {
|
||||
lines.push('<?xml version="1.0" encoding="UTF-8"?>')
|
||||
}
|
||||
|
||||
const ctx = {
|
||||
lines,
|
||||
indent: typeof indent === 'number' ? ' '.repeat(indent) : indent,
|
||||
}
|
||||
formatNode.call(ctx, tree, 0)
|
||||
|
||||
return lines.join(indent !== 0 && indent !== '' ? '\n' : '')
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "@vates/xml",
|
||||
"description": "Simple XML formatting/parsing",
|
||||
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/xml",
|
||||
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||
"repository": {
|
||||
"directory": "@vates/xml",
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||
},
|
||||
"author": {
|
||||
"name": "Vates SAS",
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"license": "ISC",
|
||||
"version": "2.0.0",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"dependencies": {
|
||||
"sax": "^1.3.0"
|
||||
},
|
||||
"exports": {
|
||||
"./format": "./format.js",
|
||||
"./parse": "./parse.js"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const sax = require('sax')
|
||||
|
||||
exports.parseXml = function parseXml(xml, { normalize = true, strict = true, trim = true } = {}) {
|
||||
const stack = [{ children: [] }]
|
||||
|
||||
const parser = sax.parser(strict, { normalize, trim })
|
||||
parser.ontext = text => {
|
||||
stack[stack.length - 1].children.push(text)
|
||||
}
|
||||
parser.onopentag = ({ name, attributes }) => {
|
||||
stack.push({ name, attributes, children: [] })
|
||||
}
|
||||
parser.onclosetag = () => {
|
||||
const node = stack.pop()
|
||||
stack[stack.length - 1].children.push(node)
|
||||
}
|
||||
|
||||
parser.write(xml).close()
|
||||
|
||||
return stack[0].children[0]
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
{
|
||||
"name": "tag1",
|
||||
"attributes": {
|
||||
"attr1": "value1",
|
||||
"attr2": "value2"
|
||||
},
|
||||
"children": [
|
||||
"Text & entities",
|
||||
{
|
||||
"name": "tag2",
|
||||
"attributes": {},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "tag2",
|
||||
"attributes": {},
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"name": "ns:tag3",
|
||||
"attributes": {},
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tag1 attr1="value1" attr2="value2">
|
||||
Text & entities
|
||||
<tag2 />
|
||||
<tag2 />
|
||||
<ns:tag3 />
|
||||
</tag1>
|
||||
@@ -1,18 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const { formatXml } = require('@vates/xml/format')
|
||||
const { join } = require('node:path')
|
||||
const { readFileSync } = require('node:fs')
|
||||
const assert = require('node:assert/strict')
|
||||
const test = require('node:test')
|
||||
|
||||
test('format()', function () {
|
||||
const xml = String(readFileSync(join(__dirname, 'data.xml')))
|
||||
const tree = JSON.parse(readFileSync(join(__dirname, 'data.json')))
|
||||
|
||||
assert.equal(formatXml(tree) + '\n', xml)
|
||||
})
|
||||
|
||||
test('supports missing attributes and children', function () {
|
||||
assert.equal(formatXml({ name: 'foo' }, { includeDeclaration: false }), '<foo />')
|
||||
})
|
||||
@@ -1,14 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const { parseXml } = require('@vates/xml/parse')
|
||||
const { readFileSync } = require('node:fs')
|
||||
const { join } = require('node:path')
|
||||
const assert = require('node:assert/strict')
|
||||
const test = require('node:test')
|
||||
|
||||
test('parse()', function () {
|
||||
const xml = String(readFileSync(join(__dirname, 'data.xml')))
|
||||
const tree = JSON.parse(readFileSync(join(__dirname, 'data.json')))
|
||||
|
||||
assert.deepEqual(parseXml(xml), tree)
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const { describe, it } = require('node:test')
|
||||
const { describe, it } = require('test')
|
||||
const assert = require('assert').strict
|
||||
const sinon = require('sinon')
|
||||
|
||||
|
||||
@@ -32,9 +32,10 @@
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish",
|
||||
"test": "node --test"
|
||||
"test": "node--test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"sinon": "^18.0.0"
|
||||
"sinon": "^17.0.1",
|
||||
"test": "^3.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,10 +130,6 @@ class AuditCore {
|
||||
return nValid
|
||||
}
|
||||
|
||||
get(id) {
|
||||
return this._storage.get(id)
|
||||
}
|
||||
|
||||
async *getFrom(newest) {
|
||||
const storage = this._storage
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('assert/strict')
|
||||
const { afterEach, describe, it } = require('node:test')
|
||||
const { afterEach, describe, it } = require('tap').mocha
|
||||
|
||||
const { AlteredRecordError, AuditCore, MissingRecordError, NULL_ID, Storage } = require('.')
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||
},
|
||||
"version": "0.3.1",
|
||||
"version": "0.2.3",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public",
|
||||
"test": "node --test"
|
||||
"test": "tap --lines 67 --functions 92 --branches 52 --statements 67"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/decorate-with": "^2.1.0",
|
||||
"@xen-orchestra/log": "^0.7.0",
|
||||
"@vates/decorate-with": "^2.0.0",
|
||||
"@xen-orchestra/log": "^0.6.0",
|
||||
"golike-defer": "^0.5.1",
|
||||
"object-hash": "^2.0.1"
|
||||
},
|
||||
@@ -26,5 +26,8 @@
|
||||
"author": {
|
||||
"name": "Vates SAS",
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^16.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||
"dependencies": {
|
||||
"@xen-orchestra/async-map": "^0.1.2",
|
||||
"@xen-orchestra/backups": "^0.54.1",
|
||||
"@xen-orchestra/fs": "^4.2.0",
|
||||
"@xen-orchestra/backups": "^0.44.3",
|
||||
"@xen-orchestra/fs": "^4.1.3",
|
||||
"filenamify": "^6.0.0",
|
||||
"getopts": "^2.2.5",
|
||||
"lodash": "^4.17.15",
|
||||
@@ -27,7 +27,7 @@
|
||||
"scripts": {
|
||||
"postversion": "npm publish --access public"
|
||||
},
|
||||
"version": "1.0.25",
|
||||
"version": "1.0.14",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"author": {
|
||||
"name": "Vates SAS",
|
||||
|
||||
@@ -49,25 +49,26 @@ export class HealthCheckVmBackup {
|
||||
}
|
||||
|
||||
// wait for the 'Running' event to be really stored in local xapi object cache
|
||||
|
||||
restoredVm = await xapi.waitObjectState(restoredVm.$ref, vm => vm.power_state === 'Running', {
|
||||
timeout: remainingTimeout,
|
||||
timeoutMessage: refOrUuid =>
|
||||
`local xapi did not get Running state for VM ${refOrUuid} after ${timeout / 1000} second`,
|
||||
})
|
||||
|
||||
const running = new Date()
|
||||
remainingTimeout -= running - started
|
||||
|
||||
if (remainingTimeout < 0) {
|
||||
throw new Error(`local xapi did not get Running state for VM ${restoredId} after ${timeout / 1000} second`)
|
||||
}
|
||||
// wait for the guest tool version to be defined
|
||||
await xapi.waitObjectState(restoredVm.guest_metrics, gm => gm?.PV_drivers_version?.major !== undefined, {
|
||||
timeout: remainingTimeout,
|
||||
timeoutMessage: refOrUuid =>
|
||||
`timeout reached while waiting for ${refOrUuid} to report the driver version through the Xen tools. Please check or update the Xen tools.`,
|
||||
})
|
||||
|
||||
const guestToolsReady = new Date()
|
||||
remainingTimeout -= guestToolsReady - running
|
||||
if (remainingTimeout < 0) {
|
||||
throw new Error(`local xapi did not get he guest tools check ${restoredId} after ${timeout / 1000} second`)
|
||||
}
|
||||
|
||||
if (waitForScript) {
|
||||
const startedRestoredVm = await xapi.waitObjectState(
|
||||
@@ -78,10 +79,19 @@ export class HealthCheckVmBackup {
|
||||
vm.xenstore_data['vm-data/xo-backup-health-check'] === 'failure'),
|
||||
{
|
||||
timeout: remainingTimeout,
|
||||
timeoutMessage: refOrUuid =>
|
||||
`timeout reached while waiting for ${refOrUuid} to report the startup script execution.`,
|
||||
}
|
||||
)
|
||||
const scriptOk = new Date()
|
||||
remainingTimeout -= scriptOk - guestToolsReady
|
||||
if (remainingTimeout < 0) {
|
||||
throw new Error(
|
||||
`Backup health check script did not update vm-data/xo-backup-health-check of ${restoredId} after ${
|
||||
timeout / 1000
|
||||
} second, got ${
|
||||
startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check']
|
||||
} instead of 'success' or 'failure'`
|
||||
)
|
||||
}
|
||||
|
||||
if (startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check'] !== 'success') {
|
||||
const message = startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check-error']
|
||||
|
||||
@@ -160,10 +160,10 @@ export class ImportVmBackup {
|
||||
// update the stream with the negative vhd stream
|
||||
stream = await negativeVhd.stream()
|
||||
vdis[vdiRef].baseVdi = snapshotCandidate
|
||||
} catch (error) {
|
||||
} catch (err) {
|
||||
// can be a broken VHD chain, a vhd chain with a key backup, ....
|
||||
// not an irrecuperable error, don't dispose parentVhd, and fallback to full restore
|
||||
warn(`can't use differential restore`, { error })
|
||||
warn(`can't use differential restore`, err)
|
||||
disposableDescendants?.dispose()
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ export class ImportVmBackup {
|
||||
|
||||
async #decorateIncrementalVmMetadata() {
|
||||
const { additionnalVmTag, mapVdisSrs, useDifferentialRestore } = this._importIncrementalVmSettings
|
||||
|
||||
|
||||
const ignoredVdis = new Set(
|
||||
Object.entries(mapVdisSrs)
|
||||
.filter(([_, srUuid]) => srUuid === null)
|
||||
|
||||
@@ -18,7 +18,6 @@ import fromEvent from 'promise-toolbox/fromEvent'
|
||||
import groupBy from 'lodash/groupBy.js'
|
||||
import pDefer from 'promise-toolbox/defer'
|
||||
import pickBy from 'lodash/pickBy.js'
|
||||
import reduce from 'lodash/reduce.js'
|
||||
import tar from 'tar'
|
||||
import zlib from 'zlib'
|
||||
|
||||
@@ -36,8 +35,6 @@ export const DIR_XO_CONFIG_BACKUPS = 'xo-config-backups'
|
||||
|
||||
export const DIR_XO_POOL_METADATA_BACKUPS = 'xo-pool-metadata-backups'
|
||||
|
||||
const IMMUTABILTY_METADATA_FILENAME = '/immutability.json'
|
||||
|
||||
const { debug, warn } = createLogger('xo:backups:RemoteAdapter')
|
||||
|
||||
const compareTimestamp = (a, b) => a.timestamp - b.timestamp
|
||||
@@ -107,13 +104,10 @@ export class RemoteAdapter {
|
||||
async *_getLvmLogicalVolumes(devicePath, pvId, vgName) {
|
||||
yield this._getLvmPhysicalVolume(devicePath, pvId && (await this._findPartition(devicePath, pvId)))
|
||||
|
||||
debug('activate LVM volume group', { vgName })
|
||||
await fromCallback(execFile, 'vgchange', ['-ay', vgName])
|
||||
try {
|
||||
debug('get LVM volume group name and path', { vgName })
|
||||
yield lvs(['lv_name', 'lv_path'], vgName)
|
||||
} finally {
|
||||
debug('deactivate LVM volume group', { vgName })
|
||||
await fromCallback(execFile, 'vgchange', ['-an', vgName])
|
||||
}
|
||||
}
|
||||
@@ -124,22 +118,15 @@ export class RemoteAdapter {
|
||||
args.push('-o', partition.start * 512, '--sizelimit', partition.size)
|
||||
}
|
||||
args.push('--show', '-f', devicePath)
|
||||
|
||||
debug('attach loop device', { devicePath, partition })
|
||||
const path = (await fromCallback(execFile, 'losetup', args)).trim()
|
||||
try {
|
||||
debug('list LVM physical volume', { path })
|
||||
await fromCallback(execFile, 'pvscan', ['--cache', path])
|
||||
|
||||
yield path
|
||||
} finally {
|
||||
try {
|
||||
const vgNames = await pvs('vg_name', path)
|
||||
|
||||
debug('deactivate LVM volume groups', { vgNames })
|
||||
await fromCallback(execFile, 'vgchange', ['-an', ...vgNames])
|
||||
} finally {
|
||||
debug('detach loop device', { path })
|
||||
await fromCallback(execFile, 'losetup', ['-d', path])
|
||||
}
|
||||
}
|
||||
@@ -160,7 +147,6 @@ export class RemoteAdapter {
|
||||
|
||||
const path = yield getTmpDir()
|
||||
const mount = options => {
|
||||
debug('mount device', { devicePath, mountPath: path })
|
||||
return fromCallback(execFile, 'mount', [
|
||||
`--options=${options.join(',')}`,
|
||||
`--source=${devicePath}`,
|
||||
@@ -178,7 +164,6 @@ export class RemoteAdapter {
|
||||
try {
|
||||
yield path
|
||||
} finally {
|
||||
debug('umount device', { devicePath, mountPath: path })
|
||||
await fromCallback(execFile, 'umount', ['--lazy', path])
|
||||
}
|
||||
}
|
||||
@@ -204,14 +189,13 @@ export class RemoteAdapter {
|
||||
// check if we will be allowed to merge a a vhd created in this adapter
|
||||
// with the vhd at path `path`
|
||||
async isMergeableParent(packedParentUid, path) {
|
||||
return await Disposable.use(VhdSynthetic.fromVhdChain(this.handler, path), vhd => {
|
||||
return await Disposable.use(openVhd(this.handler, path), vhd => {
|
||||
// this baseUuid is not linked with this vhd
|
||||
if (!vhd.footer.uuid.equals(packedParentUid)) {
|
||||
return false
|
||||
}
|
||||
|
||||
// check if all the chain is composed of vhd directory
|
||||
const isVhdDirectory = vhd.checkVhdsClass(VhdDirectory)
|
||||
const isVhdDirectory = vhd instanceof VhdDirectory
|
||||
return isVhdDirectory
|
||||
? this.useVhdDirectory() && this.#getCompressionType() === vhd.compressionType
|
||||
: !this.useVhdDirectory()
|
||||
@@ -348,8 +332,6 @@ export class RemoteAdapter {
|
||||
|
||||
const diskPath = handler.getFilePath('/' + diskId)
|
||||
const mountDir = yield getTmpDir()
|
||||
|
||||
debug('mount VHD (vhdimount)', { diskPath, mountPath: mountDir })
|
||||
await fromCallback(execFile, 'vhdimount', [diskPath, mountDir])
|
||||
try {
|
||||
let max = 0
|
||||
@@ -371,7 +353,6 @@ export class RemoteAdapter {
|
||||
|
||||
yield `${mountDir}/${maxEntry}`
|
||||
} finally {
|
||||
debug('umount VHD (fusermount)', { diskPath, mountPath: mountDir })
|
||||
await fromCallback(execFile, 'fusermount', ['-uz', mountDir])
|
||||
}
|
||||
}
|
||||
@@ -768,37 +749,10 @@ export class RemoteAdapter {
|
||||
}
|
||||
|
||||
async readVmBackupMetadata(path) {
|
||||
let json
|
||||
let isImmutable = false
|
||||
let remoteIsImmutable = false
|
||||
// if the remote is immutable, check if this metadatas are also immutables
|
||||
try {
|
||||
// this file is not encrypted
|
||||
await this._handler._readFile(IMMUTABILTY_METADATA_FILENAME)
|
||||
remoteIsImmutable = true
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// this will trigger an EPERM error if the file is immutable
|
||||
json = await this.handler.readFile(path, { flag: 'r+' })
|
||||
// s3 handler don't respect flags
|
||||
} catch (err) {
|
||||
// retry without triggerring immutbaility check ,only on immutable remote
|
||||
if (err.code === 'EPERM' && remoteIsImmutable) {
|
||||
isImmutable = true
|
||||
json = await this._handler.readFile(path, { flag: 'r' })
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
// _filename is a private field used to compute the backup id
|
||||
//
|
||||
// it's enumerable to make it cacheable
|
||||
const metadata = { ...JSON.parse(json), _filename: path, isImmutable }
|
||||
const metadata = { ...JSON.parse(await this._handler.readFile(path)), _filename: path }
|
||||
|
||||
// backups created on XenServer < 7.1 via JSON in XML-RPC transports have boolean values encoded as integers, which make them unusable with more recent XAPIs
|
||||
if (typeof metadata.vm.is_a_template === 'number') {
|
||||
@@ -842,29 +796,6 @@ export class RemoteAdapter {
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
|
||||
#computeTotalBackupSizeRecursively(backups) {
|
||||
return reduce(
|
||||
backups,
|
||||
(prev, backup) => {
|
||||
const _backup = Array.isArray(backup) ? this.#computeTotalBackupSizeRecursively(backup) : backup
|
||||
return {
|
||||
onDisk: prev.onDisk + (_backup.onDisk ?? _backup.size),
|
||||
}
|
||||
},
|
||||
{ onDisk: 0 }
|
||||
)
|
||||
}
|
||||
|
||||
async getTotalVmBackupSize() {
|
||||
return this.#computeTotalBackupSizeRecursively(await this.listAllVmBackups())
|
||||
}
|
||||
|
||||
async getTotalBackupSize() {
|
||||
const vmBackupSize = await this.getTotalVmBackupSize()
|
||||
// @TODO: add `getTotalXoBackupSize` and `getTotalPoolBackupSize` once `size` is implemented by fs
|
||||
return vmBackupSize
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(RemoteAdapter.prototype, {
|
||||
|
||||
@@ -21,7 +21,7 @@ export class RestoreMetadataBackup {
|
||||
})
|
||||
} else {
|
||||
const metadata = JSON.parse(await handler.readFile(join(backupId, 'metadata.json')))
|
||||
const dataFileName = resolve('/', backupId, metadata.data ?? 'data.json').slice(1)
|
||||
const dataFileName = resolve(backupId, metadata.data ?? 'data.json')
|
||||
const data = await handler.readFile(dataFileName)
|
||||
|
||||
// if data is JSON, sent it as a plain string, otherwise, consider the data as binary and encode it
|
||||
|
||||
@@ -2,10 +2,7 @@ import { createLogger } from '@xen-orchestra/log'
|
||||
import { catchGlobalErrors } from '@xen-orchestra/log/configure'
|
||||
|
||||
import Disposable from 'promise-toolbox/Disposable'
|
||||
import humanFormat from 'human-format'
|
||||
import ignoreErrors from 'promise-toolbox/ignoreErrors'
|
||||
import mapValues from 'lodash/mapValues.js'
|
||||
import ms from 'ms'
|
||||
import { compose } from '@vates/compose'
|
||||
import { createCachedLookup } from '@vates/cached-dns.lookup'
|
||||
import { createDebounceResource } from '@vates/disposable/debounceResource.js'
|
||||
@@ -23,7 +20,7 @@ createCachedLookup().patchGlobal()
|
||||
|
||||
const logger = createLogger('xo:backups:worker')
|
||||
catchGlobalErrors(logger)
|
||||
const { debug, info, warn } = logger
|
||||
const { debug } = logger
|
||||
|
||||
class BackupWorker {
|
||||
#config
|
||||
@@ -152,27 +149,6 @@ process.on('message', async message => {
|
||||
debug('message received', { message })
|
||||
|
||||
if (message.action === 'run') {
|
||||
const resourceStart = process.resourceUsage()
|
||||
const timeStart = process.hrtime.bigint()
|
||||
info('starting backup')
|
||||
|
||||
process.on('exit', exitCode => {
|
||||
const resourceUsage = mapValues(process.resourceUsage(), (end, key) => end - resourceStart[key])
|
||||
const cpuTotal = resourceUsage.userCPUTime + resourceUsage.systemCPUTime
|
||||
const duration = Number((process.hrtime.bigint() - timeStart) / 1000n) // in μs
|
||||
|
||||
info('process will exit', {
|
||||
duration,
|
||||
exitCode,
|
||||
resourceUsage,
|
||||
summary: {
|
||||
duration: ms(duration / 1000),
|
||||
cpuUsage: Math.round((100 * cpuTotal) / duration) + '%',
|
||||
memoryUsage: humanFormat.bytes(resourceUsage.maxRSS * 1024),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
const backupWorker = new BackupWorker(message.data)
|
||||
try {
|
||||
const result = message.runWithLogs
|
||||
@@ -201,16 +177,8 @@ process.on('message', async message => {
|
||||
status: 'failure',
|
||||
})
|
||||
} finally {
|
||||
info('backup has ended')
|
||||
await ignoreErrors.call(backupWorker.debounceResource.flushAll())
|
||||
process.disconnect()
|
||||
|
||||
setTimeout(() => {
|
||||
warn('worker process did not exit automatically, forcing...')
|
||||
|
||||
// eslint-disable-next-line n/no-process-exit
|
||||
process.exit()
|
||||
}, 30e3).unref()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import test from 'node:test'
|
||||
import test from 'test'
|
||||
import { strict as assert } from 'node:assert'
|
||||
|
||||
import tmp from 'tmp'
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user