diff --git a/.pnp.cjs b/.pnp.cjs index e59bec046..b1605a53e 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -3102,9 +3102,9 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@swc/jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.2.17"], ["ajv", "npm:8.9.0"], ["jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:27.5.1"], - ["js-yaml", "npm:4.1.0"], ["json5", "npm:2.2.0"], ["uuid", "npm:8.3.2"], + ["yaml", "npm:2.0.0-10"], ["yargs", "npm:17.3.1"] ], "linkType": "SOFT", @@ -3501,7 +3501,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@swc/core", "npm:1.2.135"], ["@swc/jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.2.17"], ["jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:27.5.1"], - ["js-yaml", "npm:4.1.0"] + ["yaml", "npm:2.0.0-10"] ], "linkType": "SOFT", }] @@ -11952,9 +11952,9 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["decompress", "npm:4.2.1"], ["decompress-targz", "npm:4.1.1"], ["jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:27.5.1"], - ["js-yaml", "npm:4.1.0"], ["ora", "npm:5.4.1"], - ["uuid", "npm:8.3.2"] + ["uuid", "npm:8.3.2"], + ["yaml", "npm:2.0.0-10"] ], "linkType": "SOFT", }] @@ -19243,6 +19243,13 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["yaml", "npm:1.10.2"] ], "linkType": "HARD", + }], + ["npm:2.0.0-10", { + "packageLocation": "./.yarn/cache/yaml-npm-2.0.0-10-334367b768-7a0bac2f80.zip/node_modules/yaml/", + "packageDependencies": [ + ["yaml", "npm:2.0.0-10"] + ], + "linkType": "HARD", }] ]], ["yaml-loader", [ diff --git a/.yarn/cache/yaml-npm-2.0.0-10-334367b768-7a0bac2f80.zip b/.yarn/cache/yaml-npm-2.0.0-10-334367b768-7a0bac2f80.zip new file mode 100644 index 000000000..6b5026a3f Binary files /dev/null and b/.yarn/cache/yaml-npm-2.0.0-10-334367b768-7a0bac2f80.zip differ diff --git a/packages/build/package.json b/packages/build/package.json index b48547a2c..3a6b83085 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -50,9 +50,9 @@ "@lowdefy/node-utils": "4.0.0-alpha.6", "@lowdefy/nunjucks": "4.0.0-alpha.6", "ajv": "8.9.0", - "js-yaml": "4.1.0", "json5": "2.2.0", "uuid": "8.3.2", + "yaml": "2.0.0-10", "yargs": "17.3.1" }, "devDependencies": { diff --git a/packages/build/src/build/buildRefs/parseRefContent.js b/packages/build/src/build/buildRefs/parseRefContent.js index 114371050..e1a2507d4 100644 --- a/packages/build/src/build/buildRefs/parseRefContent.js +++ b/packages/build/src/build/buildRefs/parseRefContent.js @@ -17,7 +17,7 @@ import { type } from '@lowdefy/helpers'; import { getFileExtension, getFileSubExtension } from '@lowdefy/node-utils'; import JSON5 from 'json5'; -import YAML from 'js-yaml'; +import YAML from 'yaml'; import parseNunjucks from './parseNunjucks.js'; @@ -31,7 +31,7 @@ function parseRefContent({ content, refDef }) { } if (ext === 'yaml' || ext === 'yml') { - return YAML.load(content); + return YAML.parse(content); } if (ext === 'json') { return JSON5.parse(content); diff --git a/packages/build/src/index.js b/packages/build/src/index.js index b823a6d20..8b9747792 100644 --- a/packages/build/src/index.js +++ b/packages/build/src/index.js @@ -97,6 +97,7 @@ async function build(options) { await buildIcons({ components, context }); await buildStyles({ components, context }); await cleanBuildDirectory({ context }); + await writeActionImports({ components, context }); await writeApp({ components, context }); await writeConnections({ components, context }); await writeRequests({ components, context }); diff --git a/packages/cli/package.json b/packages/cli/package.json index 361de82cb..733072539 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -47,9 +47,9 @@ "commander": "9.0.0", "decompress": "4.2.1", "decompress-targz": "4.1.1", - "js-yaml": "4.1.0", "ora": "5.4.1", - "uuid": "8.3.2" + "uuid": "8.3.2", + "yaml": "2.0.0-10" }, "devDependencies": { "@jest/globals": "27.5.1", diff --git a/packages/cli/src/utils/getLowdefyYaml.js b/packages/cli/src/utils/getLowdefyYaml.js index 60edd3a54..f3cef028a 100644 --- a/packages/cli/src/utils/getLowdefyYaml.js +++ b/packages/cli/src/utils/getLowdefyYaml.js @@ -17,7 +17,7 @@ import path from 'path'; import { get, type } from '@lowdefy/helpers'; import { readFile } from '@lowdefy/node-utils'; -import YAML from 'js-yaml'; +import YAML from 'yaml'; async function getLowdefyYaml({ configDirectory, command }) { let lowdefyYaml = await readFile(path.resolve(configDirectory, 'lowdefy.yaml')); @@ -34,7 +34,7 @@ async function getLowdefyYaml({ configDirectory, command }) { } let lowdefy; try { - lowdefy = YAML.load(lowdefyYaml); + lowdefy = YAML.parse(lowdefyYaml); } catch (error) { throw new Error(`Could not parse "lowdefy.yaml" file. Received error ${error.message}.`); } diff --git a/packages/docs/actions/JsAction.yaml b/packages/docs/actions/JsAction.yaml index a91b08592..d4c43ee9f 100644 --- a/packages/docs/actions/JsAction.yaml +++ b/packages/docs/actions/JsAction.yaml @@ -94,7 +94,7 @@ _ref: events: onInitAsync: - id: set_intercom_user - type: JsAction + type: JsAction # TODO: params: name: setIntercomUser blocks: @@ -203,7 +203,7 @@ _ref: type: Request params: search_products - id: apply_highlight # apply the highlight transformation to the request data. - type: JsAction + type: JsAction # TODO: params: name: highlightText args: @@ -271,7 +271,7 @@ _ref: events: onClick: - id: loop_requests - type: JsAction + type: JsAction # TODO: params: name: loopRequests args: diff --git a/packages/docs/concepts/custom-code.yaml b/packages/docs/concepts/custom-code.yaml index 3a421c3d9..dfd8b64d6 100644 --- a/packages/docs/concepts/custom-code.yaml +++ b/packages/docs/concepts/custom-code.yaml @@ -110,7 +110,7 @@ _ref: events: onEnter: - id: get_todos - type: JsAction + type: JsAction # TODO: params: name: fetchTodos # Trigger the custom JavaScript action. args: diff --git a/packages/docs/howto/generate-csv.yaml.njk b/packages/docs/howto/generate-csv.yaml.njk index 3bafd09ce..2b3950d40 100644 --- a/packages/docs/howto/generate-csv.yaml.njk +++ b/packages/docs/howto/generate-csv.yaml.njk @@ -47,9 +47,9 @@ _ref: title: Generate a CSV color: '#1890ff' events: - onClick: - - id: generate_csv - type: JsAction + onClick: [] + {# - id: generate_csv + type: JsAction # TODO: params: name: csvMake args: @@ -77,7 +77,7 @@ _ref: - - Username # an array of field definitions - Identifier - FirstName - - LastName + - LastName #} - id: md2 type: MarkdownWithCode @@ -211,7 +211,7 @@ _ref: events: onClick: - id: generate_csv - type: JsAction + type: JsAction # TODO: params: name: csvMake args: diff --git a/packages/docs/howto/generate-pdf.yaml.njk b/packages/docs/howto/generate-pdf.yaml.njk index aa61787cb..0a4ff1f96 100644 --- a/packages/docs/howto/generate-pdf.yaml.njk +++ b/packages/docs/howto/generate-pdf.yaml.njk @@ -90,13 +90,13 @@ _ref: qty: 2 price: 60.667 code: X12-49A - onClick: - - id: generate_pdf - type: JsAction + onClick: [] + {# - id: generate_pdf + type: JsAction # TODO: params: name: pdfMake args: - _ref: howto/generatePdf/inv_template.yaml + _ref: howto/generatePdf/inv_template.yaml #} - id: md2 type: MarkdownWithCode @@ -256,7 +256,7 @@ _ref: events: onClick: - id: make_pdf - type: JsAction + type: JsAction # TODO: params: name: pdfMake args: @@ -279,9 +279,9 @@ _ref: title: Download PDF icon: AiOutlinedDownload events: - onClick: - - id: make_pdf - type: JsAction + onClick: [] + {# - id: make_pdf + type: JsAction # TODO: params: name: pdfMake args: @@ -291,7 +291,7 @@ _ref: fontSize: 10 content: - text: This pdf has been generated with Lowdefy and pdfMake. - bold: true + bold: true #} - id: md4 type: MarkdownWithCode properties: @@ -370,7 +370,7 @@ _ref: events: onClick: - id: make_pdf - type: JsAction + type: JsAction # TODO: params: name: pdfMake args: @@ -635,13 +635,13 @@ _ref: qty: 2 price: 60.667 code: X12-49A - onClick: - - id: generate_pdf - type: JsAction + onClick: [] + {# - id: generate_pdf + type: JsAction # TODO: params: name: pdfMake args: - _ref: howto/generatePdf/inv_template.yaml + _ref: howto/generatePdf/inv_template.yaml #} - id: md5 type: MarkdownWithCode properties: diff --git a/packages/docs/howto/generateCsv/lowdefy.yaml b/packages/docs/howto/generateCsv/lowdefy.yaml index 1941df6d2..3e41236e6 100644 --- a/packages/docs/howto/generateCsv/lowdefy.yaml +++ b/packages/docs/howto/generateCsv/lowdefy.yaml @@ -23,36 +23,37 @@ pages: color: '#1890ff' events: onClick: - - id: generate_csv - type: JsAction - params: - name: csvMake - args: - - profiles.csv # csv filename - - - Username: booker12 # an array of data, usually a reference - Identifier: 9012 - FirstName: Rachel - LastName: Booker - - Username: grey07 - Identifier: 2070 - FirstName: Laura - LastName: Grey - - Username: johnson81 - Identifier: 4081 - FirstName: Craig - LastName: Johnson - - Username: jenkins46 - Identifier: 9346 - FirstName: Mary - LastName: Jenkins - - Username: smith79 - Identifier: 5079 - FirstName: Jamie - LastName: Smith - - - Username # an array of field definitions - - Identifier - - FirstName - - LastName + [] + # - id: generate_csv + # type: JsAction # TODO: + # params: + # name: csvMake + # args: + # - profiles.csv # csv filename + # - - Username: booker12 # an array of data, usually a reference + # Identifier: 9012 + # FirstName: Rachel + # LastName: Booker + # - Username: grey07 + # Identifier: 2070 + # FirstName: Laura + # LastName: Grey + # - Username: johnson81 + # Identifier: 4081 + # FirstName: Craig + # LastName: Johnson + # - Username: jenkins46 + # Identifier: 9346 + # FirstName: Mary + # LastName: Jenkins + # - Username: smith79 + # Identifier: 5079 + # FirstName: Jamie + # LastName: Smith + # - - Username # an array of field definitions + # - Identifier + # - FirstName + # - LastName footer: blocks: - id: footer diff --git a/packages/docs/howto/generatePdf/lowdefy.yaml b/packages/docs/howto/generatePdf/lowdefy.yaml index 497fd99e9..389af6e98 100644 --- a/packages/docs/howto/generatePdf/lowdefy.yaml +++ b/packages/docs/howto/generatePdf/lowdefy.yaml @@ -99,13 +99,14 @@ pages: color: '#1890ff' events: onClick: - - id: make_pdf - type: JsAction - params: - name: pdfMake - args: - _ref: - path: inv_template.yaml + [] + # - id: make_pdf + # type: JsAction # TODO: + # params: + # name: pdfMake + # args: + # _ref: + # path: inv_template.yaml footer: blocks: - id: footer diff --git a/packages/docs/operators/_actions.yaml b/packages/docs/operators/_actions.yaml index 33c714dde..5dae7d0ed 100644 --- a/packages/docs/operators/_actions.yaml +++ b/packages/docs/operators/_actions.yaml @@ -97,7 +97,7 @@ _ref: events: onClick: - id: get_normalized_eigenvector - type: JsAction + type: JsAction # TODO: params: name: getNormalizedEigenvector args: diff --git a/packages/docs/operators/_yaml.yaml b/packages/docs/operators/_yaml.yaml index a0076d908..3690b003a 100644 --- a/packages/docs/operators/_yaml.yaml +++ b/packages/docs/operators/_yaml.yaml @@ -25,22 +25,36 @@ _ref: - name: parse types: | ``` - (value: string): any + ({on: string, options?: object}): object + ([on: string, options?: object]): object ``` description: | The `_yaml.parse` method parses a YAML string into an object. arguments: | - ###### string - The string to parse. + ###### object + - `on: string`: String to parse. + - `options?: object`: Optional settings. See the [YAML.parse: method here](https://eemeli.org/yaml/#parse-options) for supported settings. + examples: | ###### Parse a YAML string: ```yaml - _yaml.parse: | - key: Value - boolean: true - array: - - 1 - - 2 + _yaml.parse: + on: | + key: Value + boolean: true + array: + - 1 + - 2 + ``` + or: + ```yaml + _yaml.parse: + - | + key: Value + boolean: true + array: + - 1 + - 2 ``` Returns: ``` @@ -61,17 +75,27 @@ _ref: arguments: | ###### object - `on: any`: The object to stringify. - - `options: object`: Optional settings. See the [YAML.dump method here](https://www.npmjs.com/package/js-yaml) for supported settings. + - `options?: object`: Optional settings. See the [YAML.stringify: method here](https://eemeli.org/yaml/#tostring-options) for supported settings. examples: | ###### Stringify an object as YAML: ```yaml _yaml.stringify: - key: Value - boolean: true - array: - - 1 - - 2 + on: + key: Value + boolean: true + array: + - 1 + - 2 + ``` + or: + ```yaml + _yaml.stringify: + - key: Value + boolean: true + array: + - 1 + - 2 ``` Returns (as a string): ```text diff --git a/packages/docs/templates/blocks/template.yaml.njk b/packages/docs/templates/blocks/template.yaml.njk index 58fee46bc..9440c1e18 100644 --- a/packages/docs/templates/blocks/template.yaml.njk +++ b/packages/docs/templates/blocks/template.yaml.njk @@ -75,10 +75,10 @@ events: _var: init_state_values onEnterAsync: - - id: connect_docsearch - type: JsAction + {# - id: connect_docsearch + type: JsAction # TODO: params: - name: connectDocsearch + name: connectDocsearch #} - id: post_telemetry type: Request messages: diff --git a/packages/docs/templates/blog.yaml.njk b/packages/docs/templates/blog.yaml.njk index c8c3a7fbd..5e7fdfb1c 100644 --- a/packages/docs/templates/blog.yaml.njk +++ b/packages/docs/templates/blog.yaml.njk @@ -44,10 +44,10 @@ events: type: string length: 16 onEnterAsync: - - id: connect_docsearch - type: JsAction + {# - id: connect_docsearch + type: JsAction # TODO: params: - name: connectDocsearch + name: connectDocsearch #} - id: post_telemetry type: Request messages: diff --git a/packages/docs/templates/general.yaml.njk b/packages/docs/templates/general.yaml.njk index 405aacc45..f20ce0d00 100644 --- a/packages/docs/templates/general.yaml.njk +++ b/packages/docs/templates/general.yaml.njk @@ -44,10 +44,10 @@ events: type: string length: 16 onEnterAsync: - - id: connect_docsearch - type: JsAction + {# - id: connect_docsearch + type: JsAction # TODO: params: - name: connectDocsearch + name: connectDocsearch #} - id: post_telemetry type: Request messages: @@ -121,4 +121,4 @@ areas: layout: contentGutter: 16 blocks: - _var: content \ No newline at end of file + _var: content diff --git a/packages/plugins/operators/operators-yaml/package.json b/packages/plugins/operators/operators-yaml/package.json index a9b92153e..713449ae2 100644 --- a/packages/plugins/operators/operators-yaml/package.json +++ b/packages/plugins/operators/operators-yaml/package.json @@ -45,7 +45,7 @@ "dependencies": { "@lowdefy/helpers": "4.0.0-alpha.6", "@lowdefy/operators": "4.0.0-alpha.6", - "js-yaml": "4.1.0" + "yaml": "2.0.0-10" }, "devDependencies": { "@swc/cli": "0.1.55", diff --git a/packages/plugins/operators/operators-yaml/src/operators/shared/yaml.js b/packages/plugins/operators/operators-yaml/src/operators/shared/yaml.js index e96e058a7..9b8d2c970 100644 --- a/packages/plugins/operators/operators-yaml/src/operators/shared/yaml.js +++ b/packages/plugins/operators/operators-yaml/src/operators/shared/yaml.js @@ -14,28 +14,31 @@ limitations under the License. */ -import YAML from 'js-yaml'; -import { serializer } from '@lowdefy/helpers'; +import YAML from 'yaml'; +import { serializer, type } from '@lowdefy/helpers'; import { runClass } from '@lowdefy/operators'; -function parse(input) { +// TODO: consider adding replacer and reviver args supported by yaml package. +function parse(input, options) { if (input === 'undefined') return undefined; - const loaded = YAML.load(input); + if (!type.isString(input)) { + throw new Error('requires a string type to parse.'); + } + const loaded = YAML.parse(input, options); return serializer.deserialize(loaded); } function stringify(input, options) { - return YAML.dump(serializer.serialize(input, { isoStringDates: true }), { - sortKeys: true, - ...options, - }); + if (input === undefined) return ''; + // TODO: option sortKeys: true, sort keys was supported by js-yaml and not by yaml. + return YAML.stringify(serializer.serialize(input, { isoStringDates: true }), options); } const functions = { parse, stringify }; const meta = { stringify: { namedArgs: ['on', 'options'], validTypes: ['object', 'array'] }, - parse: { singleArg: true, validTypes: ['string'] }, + parse: { namedArgs: ['on', 'options'], validTypes: ['object', 'array'] }, }; function _yaml({ params, location, methodName }) { diff --git a/packages/plugins/operators/operators-yaml/src/operators/shared/yaml.test.js b/packages/plugins/operators/operators-yaml/src/operators/shared/yaml.test.js index dc75fbfc0..c81350484 100644 --- a/packages/plugins/operators/operators-yaml/src/operators/shared/yaml.test.js +++ b/packages/plugins/operators/operators-yaml/src/operators/shared/yaml.test.js @@ -17,61 +17,62 @@ import yaml from './yaml.js'; test('_yaml.parse string unquoted', () => { - expect(yaml({ params: 'firstName', location: 'locationId', methodName: 'parse' })).toEqual( + expect(yaml({ params: ['firstName'], location: 'locationId', methodName: 'parse' })).toEqual( 'firstName' ); }); test('_yaml.parse string quoted', () => { - expect(yaml({ params: '"firstName"', location: 'locationId', methodName: 'parse' })).toEqual( + expect(yaml({ params: ['"firstName"'], location: 'locationId', methodName: 'parse' })).toEqual( 'firstName' ); }); test('_yaml.parse number', () => { - expect(yaml({ params: '1', location: 'locationId', methodName: 'parse' })).toEqual(1); + expect(yaml({ params: ['1'], location: 'locationId', methodName: 'parse' })).toEqual(1); }); test('_yaml.parse boolean true', () => { - expect(yaml({ params: 'true', location: 'locationId', methodName: 'parse' })).toEqual(true); + expect(yaml({ params: ['true'], location: 'locationId', methodName: 'parse' })).toEqual(true); }); test('_yaml.parse boolean false', () => { - expect(yaml({ params: 'false', location: 'locationId', methodName: 'parse' })).toEqual(false); + expect(yaml({ params: ['false'], location: 'locationId', methodName: 'parse' })).toEqual(false); }); test('_yaml.parse null', () => { - expect(yaml({ params: 'null', location: 'locationId', methodName: 'parse' })).toEqual(null); + expect(yaml({ params: ['null'], location: 'locationId', methodName: 'parse' })).toEqual(null); }); test('_yaml.parse undefined string', () => { - expect(yaml({ params: 'undefined', location: 'locationId', methodName: 'parse' })).toEqual( + expect(yaml({ params: ['undefined'], location: 'locationId', methodName: 'parse' })).toEqual( undefined ); }); test('_yaml.parse object not allowed', () => { - expect(() => yaml({ params: { a: 'b' }, location: 'locationId', methodName: 'parse' })) - .toThrowErrorMatchingInlineSnapshot(` - "Operator Error: _yaml.parse accepts one of the following types: string. - Received: {\\"_yaml.parse\\":{\\"a\\":\\"b\\"}} at locationId." - `); + expect(() => + yaml({ params: [{ a: 'b' }], location: 'locationId', methodName: 'parse' }) + ).toThrowErrorMatchingInlineSnapshot( + `"Operator Error: _yaml.parse - requires a string type to parse. Received: {\\"_yaml.parse\\":[{\\"a\\":\\"b\\"}]} at locationId."` + ); }); test('_yaml.parse date not supported', () => { - expect(() => yaml({ params: new Date(0), location: 'locationId', methodName: 'parse' })) - .toThrowErrorMatchingInlineSnapshot(` - "Operator Error: _yaml.parse accepts one of the following types: string. - Received: {\\"_yaml.parse\\":\\"1970-01-01T00:00:00.000Z\\"} at locationId." - `); + expect(() => + yaml({ params: [new Date(0)], location: 'locationId', methodName: 'parse' }) + ).toThrowErrorMatchingInlineSnapshot( + `"Operator Error: _yaml.parse - requires a string type to parse. Received: {\\"_yaml.parse\\":[\\"1970-01-01T00:00:00.000Z\\"]} at locationId."` + ); }); test('_yaml.parse array', () => { expect( yaml({ - params: `- a: a1 + params: [ + `- a: a1 - a: a2`, - + ], location: 'locationId', methodName: 'parse', }) @@ -81,8 +82,10 @@ test('_yaml.parse array', () => { test('_yaml.parse date array', () => { expect( yaml({ - params: `- _date: "1970-01-01T00:00:00.000Z" + params: [ + `- _date: "1970-01-01T00:00:00.000Z" - _date: "1970-01-01T00:00:00.001Z"`, + ], location: 'locationId', methodName: 'parse', }) @@ -92,7 +95,7 @@ test('_yaml.parse date array', () => { test('_yaml.parse date as object', () => { expect( yaml({ - params: `_date: "1970-01-01T00:00:00.000Z"`, + params: [`_date: "1970-01-01T00:00:00.000Z"`], location: 'locationId', methodName: 'parse', }) @@ -102,8 +105,10 @@ test('_yaml.parse date as object', () => { test('_yaml.parse date object', () => { expect( yaml({ - params: `a: + params: [ + `a: _date: "1970-01-01T00:00:00.000Z"`, + ], location: 'locationId', methodName: 'parse', }) @@ -111,11 +116,11 @@ test('_yaml.parse date object', () => { }); test('_yaml.parse non string', () => { - expect(() => yaml({ params: 123, location: 'locationId', methodName: 'parse' })) - .toThrowErrorMatchingInlineSnapshot(` - "Operator Error: _yaml.parse accepts one of the following types: string. - Received: {\\"_yaml.parse\\":123} at locationId." - `); + expect(() => + yaml({ params: [123], location: 'locationId', methodName: 'parse' }) + ).toThrowErrorMatchingInlineSnapshot( + `"Operator Error: _yaml.parse - requires a string type to parse. Received: {\\"_yaml.parse\\":[123]} at locationId."` + ); }); test('_yaml.stringify string', () => { @@ -159,7 +164,7 @@ test('_yaml.stringify undefined', () => { test('_yaml.stringify date', () => { expect(yaml({ params: [new Date(0)], location: 'locationId', methodName: 'stringify' })) .toMatchInlineSnapshot(` - "_date: '1970-01-01T00:00:00.000Z' + "_date: 1970-01-01T00:00:00.000Z " `); }); @@ -178,8 +183,8 @@ test('_yaml.stringify date array', () => { expect( yaml({ params: [[new Date(0), new Date(1)]], location: 'locationId', methodName: 'stringify' }) ).toMatchInlineSnapshot(` - "- _date: '1970-01-01T00:00:00.000Z' - - _date: '1970-01-01T00:00:00.001Z' + "- _date: 1970-01-01T00:00:00.000Z + - _date: 1970-01-01T00:00:00.001Z " `); }); @@ -188,55 +193,56 @@ test('_yaml.stringify date object', () => { expect(yaml({ params: [{ a: new Date(0) }], location: 'locationId', methodName: 'stringify' })) .toMatchInlineSnapshot(` "a: - _date: '1970-01-01T00:00:00.000Z' + _date: 1970-01-01T00:00:00.000Z " `); }); -test('_yaml.stringify date object with options: sortKeys: false', () => { - expect( - yaml({ - params: [{ b: new Date(0), a: new Date(0) }, { sortKeys: false }], - location: 'locationId', - methodName: 'stringify', - }) - ).toMatchInlineSnapshot(` - "b: - _date: '1970-01-01T00:00:00.000Z' - a: - _date: '1970-01-01T00:00:00.000Z' - " - `); -}); +// TODO: consider sortKeys implementation. +// test('_yaml.stringify date object with options: sortKeys: false', () => { +// expect( +// yaml({ +// params: [{ b: new Date(0), a: new Date(0) }, { sortKeys: false }], +// location: 'locationId', +// methodName: 'stringify', +// }) +// ).toMatchInlineSnapshot(` +// "b: +// _date: 1970-01-01T00:00:00.000Z +// a: +// _date: 1970-01-01T00:00:00.000Z +// " +// `); +// }); -test('_yaml.stringify as object with options: sortKeys: false', () => { - expect( - yaml({ - params: { on: { b: new Date(0), a: new Date(0) }, options: { sortKeys: false } }, - location: 'locationId', - methodName: 'stringify', - }) - ).toMatchInlineSnapshot(` - "b: - _date: '1970-01-01T00:00:00.000Z' - a: - _date: '1970-01-01T00:00:00.000Z' - " - `); -}); +// test('_yaml.stringify as object with options: sortKeys: false', () => { +// expect( +// yaml({ +// params: { on: { b: new Date(0), a: new Date(0) }, options: { sortKeys: false } }, +// location: 'locationId', +// methodName: 'stringify', +// }) +// ).toMatchInlineSnapshot(` +// "b: +// _date: 1970-01-01T00:00:00.000Z +// a: +// _date: 1970-01-01T00:00:00.000Z +// " +// `); +// }); -test('_yaml.stringify as object with options: sortKeys: true', () => { - expect( - yaml({ - params: { on: { b: new Date(0), a: new Date(0) }, options: { sortKeys: true } }, - location: 'locationId', - methodName: 'stringify', - }) - ).toMatchInlineSnapshot(` - "a: - _date: '1970-01-01T00:00:00.000Z' - b: - _date: '1970-01-01T00:00:00.000Z' - " - `); -}); +// test('_yaml.stringify as object with options: sortKeys: true', () => { +// expect( +// yaml({ +// params: { on: { b: new Date(0), a: new Date(0) }, options: { sortKeys: true } }, +// location: 'locationId', +// methodName: 'stringify', +// }) +// ).toMatchInlineSnapshot(` +// "a: +// _date: 1970-01-01T00:00:00.000Z +// b: +// _date: 1970-01-01T00:00:00.000Z +// " +// `); +// }); diff --git a/packages/server-dev/src/manager/utils/getLowdefyVersion.mjs b/packages/server-dev/src/manager/utils/getLowdefyVersion.mjs index d03a3cd99..6baff92c0 100644 --- a/packages/server-dev/src/manager/utils/getLowdefyVersion.mjs +++ b/packages/server-dev/src/manager/utils/getLowdefyVersion.mjs @@ -17,7 +17,7 @@ import path from 'path'; import { type } from '@lowdefy/helpers'; import { readFile } from '@lowdefy/node-utils'; -import YAML from 'js-yaml'; +import YAML from 'yaml'; async function getLowdefyVersion(context) { let lowdefyYaml = await readFile(path.join(context.directories.config, 'lowdefy.yaml')); @@ -29,7 +29,7 @@ async function getLowdefyVersion(context) { } let lowdefy; try { - lowdefy = YAML.load(lowdefyYaml); + lowdefy = YAML.parse(lowdefyYaml); } catch (error) { throw new Error(`Could not parse "lowdefy.yaml" file. Received error ${error.message}.`); } diff --git a/yarn.lock b/yarn.lock index 1fcf7f619..05920e221 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2245,9 +2245,9 @@ __metadata: "@swc/jest": 0.2.17 ajv: 8.9.0 jest: 27.5.1 - js-yaml: 4.1.0 json5: 2.2.0 uuid: 8.3.2 + yaml: 2.0.0-10 yargs: 17.3.1 bin: lowdefy-build: ./dist/scripts/run.js @@ -2586,7 +2586,7 @@ __metadata: "@swc/core": 1.2.135 "@swc/jest": 0.2.17 jest: 27.5.1 - js-yaml: 4.1.0 + yaml: 2.0.0-10 languageName: unknown linkType: soft @@ -9800,9 +9800,9 @@ __metadata: decompress: 4.2.1 decompress-targz: 4.1.1 jest: 27.5.1 - js-yaml: 4.1.0 ora: 5.4.1 uuid: 8.3.2 + yaml: 2.0.0-10 bin: lowdefy: ./dist/index.js languageName: unknown @@ -15860,6 +15860,13 @@ __metadata: languageName: node linkType: hard +"yaml@npm:2.0.0-10": + version: 2.0.0-10 + resolution: "yaml@npm:2.0.0-10" + checksum: 7a0bac2f80225da6008fb8ab887f43166fb2485cc3e1350185c43499c76841ea0ca9d79b40c0970e08ab3943f25ffb184e709fef7fb8b26d73987ed0452a91cc + languageName: node + linkType: hard + "yaml@npm:^1.10.0, yaml@npm:^1.7.2, yaml@npm:^1.8.3": version: 1.10.2 resolution: "yaml@npm:1.10.2"