@nangohq/nango-yaml
Advanced tools
Comparing version 0.41.0 to 0.41.1
@@ -62,3 +62,3 @@ import { getNativeDataType, getPotentialTypeAlias, isDisallowedType, shouldQuote } from './helpers.js'; | ||
parseFields({ fields, stack }) { | ||
const parsed = []; | ||
const parsed = new Map(); | ||
let dynamicField = null; | ||
@@ -82,2 +82,6 @@ for (const [nameTmp, value] of Object.entries(fields)) { | ||
for (const field of extendedFields.fields) { | ||
if (parsed.has(field.name)) { | ||
// field already exists | ||
continue; | ||
} | ||
if (field.dynamic) { | ||
@@ -87,3 +91,3 @@ dynamicField = field; | ||
else { | ||
parsed.push(field); | ||
parsed.set(field.name, field); | ||
} | ||
@@ -107,3 +111,3 @@ } | ||
} | ||
parsed.push({ name, value: acc, array: true, optional }); | ||
parsed.set(name, { name, value: acc, array: true, optional }); | ||
continue; | ||
@@ -113,3 +117,3 @@ } | ||
if (typeof value === 'boolean' || typeof value === 'number' || value === null || value === undefined) { | ||
parsed.push({ name, value, tsType: true }); | ||
parsed.set(name, { name, value, tsType: true }); | ||
continue; | ||
@@ -124,3 +128,3 @@ } | ||
} | ||
parsed.push({ name, value: acc, optional }); | ||
parsed.set(name, { name, value: acc, optional }); | ||
continue; | ||
@@ -137,3 +141,3 @@ } | ||
} | ||
parsed.push({ name, value: acc[0].value, union: true, optional }); | ||
parsed.set(name, { name, value: acc[0].value, union: true, optional }); | ||
continue; | ||
@@ -147,5 +151,11 @@ } | ||
const valueClean = isArray ? value.substring(0, value.length - 2) : value; | ||
// empty array | ||
if (valueClean === '') { | ||
this.errors.push(new ParserErrorTypeSyntax({ value, path: [parent, name] })); | ||
parsed.set(name, { name, value: valueClean, array: isArray, optional }); | ||
continue; | ||
} | ||
const alias = getPotentialTypeAlias(valueClean); | ||
if (alias) { | ||
parsed.push({ name, value: alias, tsType: true, array: isArray, optional }); | ||
parsed.set(name, { name, value: alias, tsType: true, array: isArray, optional }); | ||
continue; | ||
@@ -155,3 +165,3 @@ } | ||
if (!(native instanceof Error)) { | ||
parsed.push({ name, value: native, tsType: true, array: isArray, optional }); | ||
parsed.set(name, { name, value: native, tsType: true, array: isArray, optional }); | ||
continue; | ||
@@ -161,3 +171,3 @@ } | ||
this.errors.push(new ParserErrorTypeSyntax({ value: valueClean, path: [parent, name] })); | ||
parsed.push({ name, value: valueClean, array: isArray, optional }); | ||
parsed.set(name, { name, value: valueClean, array: isArray, optional }); | ||
continue; | ||
@@ -168,12 +178,12 @@ } | ||
if (isModel) { | ||
parsed.push({ name, value: valueClean, model: true, optional, array: isArray }); | ||
parsed.set(name, { name, value: valueClean, model: true, optional, array: isArray }); | ||
continue; | ||
} | ||
// Literal string | ||
parsed.push({ name, value: valueClean, array: isArray, optional }); | ||
parsed.set(name, { name, value: valueClean, array: isArray, optional }); | ||
} | ||
if (dynamicField) { | ||
parsed.push(dynamicField); | ||
parsed.set(dynamicField.name, dynamicField); | ||
} | ||
return parsed; | ||
return Array.from(parsed.values()); | ||
} | ||
@@ -180,0 +190,0 @@ } |
@@ -69,2 +69,18 @@ import { expect, describe, it } from 'vitest'; | ||
}); | ||
it('should handle duplicate field (ordered)', () => { | ||
const parser = new ModelsParser({ raw: { Test: { __extends: 'TestBase', id: 'string' }, TestBase: { id: 'number' } } }); | ||
parser.parseAll(); | ||
expect(Object.fromEntries(parser.parsed)).toStrictEqual({ | ||
Test: { name: 'Test', fields: [{ name: 'id', value: 'string', tsType: true, array: false, optional: false }] }, | ||
TestBase: { name: 'TestBase', fields: [{ name: 'id', value: 'number', tsType: true, array: false, optional: false }] } | ||
}); | ||
}); | ||
it('should handle duplicate field (unordered)', () => { | ||
const parser = new ModelsParser({ raw: { Test: { id: 'string', __extends: 'TestBase' }, TestBase: { id: 'number' } } }); | ||
parser.parseAll(); | ||
expect(Object.fromEntries(parser.parsed)).toStrictEqual({ | ||
Test: { name: 'Test', fields: [{ name: 'id', value: 'string', tsType: true, array: false, optional: false }] }, | ||
TestBase: { name: 'TestBase', fields: [{ name: 'id', value: 'number', tsType: true, array: false, optional: false }] } | ||
}); | ||
}); | ||
}); | ||
@@ -283,2 +299,7 @@ describe('object literal', () => { | ||
}); | ||
it('should throw on empty array type', () => { | ||
const parser = new ModelsParser({ raw: { Test: { user: '[]' } } }); | ||
parser.parseAll(); | ||
expect(parser.errors).toStrictEqual([new ParserErrorTypeSyntax({ value: '[]', path: ['Test', 'user'] })]); | ||
}); | ||
}); | ||
@@ -285,0 +306,0 @@ describe('typescript any', () => { |
@@ -41,3 +41,4 @@ import { NangoYamlParser } from './parser.js'; | ||
scopes: [], // Scopes was never allowed in v1 | ||
usedModels: [] | ||
usedModels: [], | ||
version: syncOrAction.version || '' | ||
}); | ||
@@ -68,3 +69,4 @@ } | ||
sync_type: 'incremental', | ||
webhookSubscriptions: [] | ||
webhookSubscriptions: [], | ||
version: syncOrAction.version || '' | ||
}); | ||
@@ -71,0 +73,0 @@ } |
@@ -36,3 +36,4 @@ import { expect, describe, it } from 'vitest'; | ||
usedModels: ['GithubIssue'], | ||
webhookSubscriptions: [] | ||
webhookSubscriptions: [], | ||
version: '' | ||
} | ||
@@ -50,3 +51,4 @@ ], | ||
type: 'action', | ||
usedModels: ['GithubIssue'] | ||
usedModels: ['GithubIssue'], | ||
version: '' | ||
} | ||
@@ -89,3 +91,4 @@ ] | ||
usedModels: ['Anonymous_provider_sync_hello_output'], | ||
webhookSubscriptions: [] | ||
webhookSubscriptions: [], | ||
version: '' | ||
} | ||
@@ -92,0 +95,0 @@ ], |
@@ -97,2 +97,3 @@ import { NangoYamlParser } from './parser.js'; | ||
runs: sync.runs, | ||
version: sync.version || '', | ||
track_deletes: sync.track_deletes || false, | ||
@@ -140,2 +141,3 @@ auto_start: sync.auto_start === false ? false : true, | ||
description: (action.description || '').trim(), | ||
version: action.version || '', | ||
scopes: this.getScopes(action), | ||
@@ -142,0 +144,0 @@ input: modelInput?.name || null, |
@@ -36,3 +36,4 @@ import { expect, describe, it } from 'vitest'; | ||
usedModels: ['GithubIssue'], | ||
webhookSubscriptions: [] | ||
webhookSubscriptions: [], | ||
version: '' | ||
} | ||
@@ -50,3 +51,4 @@ ], | ||
type: 'action', | ||
usedModels: ['GithubIssue', 'Anonymous_provider_action_createIssue_input'] | ||
usedModels: ['GithubIssue', 'Anonymous_provider_action_createIssue_input'], | ||
version: '' | ||
} | ||
@@ -97,3 +99,4 @@ ] | ||
type: 'action', | ||
usedModels: ['Start', 'Middle', 'End'] | ||
usedModels: ['Start', 'Middle', 'End'], | ||
version: '' | ||
} | ||
@@ -140,3 +143,4 @@ ] | ||
usedModels: ['Anonymous_provider_sync_top_output', 'Anonymous_provider_sync_top_input'], | ||
webhookSubscriptions: [] | ||
webhookSubscriptions: [], | ||
version: '' | ||
} | ||
@@ -143,0 +147,0 @@ ], |
{ | ||
"name": "@nangohq/nango-yaml", | ||
"version": "0.41.0", | ||
"version": "0.41.1", | ||
"type": "module", | ||
@@ -20,3 +20,3 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@nangohq/types": "^0.41.0", | ||
"@nangohq/types": "^0.41.1", | ||
"vitest": "1.6.0" | ||
@@ -23,0 +23,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
170332
2050