Initial commit: n8n Strike API node

- Add Strike API credentials configuration
- Implement Strike node with 9 resources (Account, Balance, Currency Exchange, Deposit, Invoice, Payment, Payment Method, Payout, Rates)
- Add comprehensive operation descriptions for all resources
- Include CLAUDE.MD documentation
- Set up build configuration with TypeScript, ESLint, and Prettier

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-10 11:00:38 +01:00
commit 5605b9b49a
8925 changed files with 1417728 additions and 0 deletions

88
node_modules/@n8n/errors/LICENSE.md generated vendored Normal file
View File

@ -0,0 +1,88 @@
# License
Portions of this software are licensed as follows:
- Content of branches other than the main branch (i.e. "master") are not licensed.
- Source code files that contain ".ee." in their filename or ".ee" in their dirname are NOT licensed under
the Sustainable Use License.
To use source code files that contain ".ee." in their filename or ".ee" in their dirname you must hold a
valid n8n Enterprise License specifically allowing you access to such source code files and as defined
in "LICENSE_EE.md".
- All third party components incorporated into the n8n Software are licensed under the original license
provided by the owner of the applicable component.
- Content outside of the above mentioned files or restrictions is available under the "Sustainable Use
License" as defined below.
## Sustainable Use License
Version 1.0
### Acceptance
By using the software, you agree to all of the terms and conditions below.
### Copyright License
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license
to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject
to the limitations below.
### Limitations
You may use or modify the software only for your own internal business purposes or for non-commercial or
personal use. You may distribute the software or provide it to others only if you do so free of charge for
non-commercial purposes. You may not alter, remove, or obscure any licensing, copyright, or other notices of
the licensor in the software. Any use of the licensors trademarks is subject to applicable law.
### Patents
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to
license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case
subject to the limitations and conditions in this license. This license does not cover any patent claims that
you cause to be infringed by modifications or additions to the software. If you or your company make any
written claim that the software infringes or contributes to infringement of any patent, your patent license
for the software granted under these terms ends immediately. If your company makes such a claim, your patent
license ends immediately for work on behalf of your company.
### Notices
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these
terms. If you modify the software, you must include in any modified copies of the software a prominent notice
stating that you have modified the software.
### No Other Rights
These terms do not imply any licenses other than those expressly granted in these terms.
### Termination
If you use the software in violation of these terms, such use is not licensed, and your license will
automatically terminate. If the licensor provides you with a notice of your violation, and you cease all
violation of this license no later than 30 days after you receive that notice, your license will be reinstated
retroactively. However, if you violate these terms after such reinstatement, any additional violation of these
terms will cause your license to terminate automatically and permanently.
### No Liability
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will
not be liable to you for any damages arising out of these terms or the use or nature of the software, under
any kind of legal claim.
### Definitions
The “licensor” is the entity offering these terms.
The “software” is the software the licensor makes available under these terms, including any portion of it.
“You” refers to the individual or entity agreeing to these terms.
“Your company” is any legal entity, sole proprietorship, or other kind of organization that you work for, plus
all organizations that have control over, are under the control of, or are under common control with that
organization. Control means ownership of substantially all the assets of an entity, or the power to direct its
management and policies by vote, contract, or otherwise. Control can be direct or indirect.
“Your license” is the license granted to you for the software under these terms.
“Use” means anything you do with the software requiring your license.
“Trademark” means trademarks, service marks, and similar rights.

27
node_modules/@n8n/errors/LICENSE_EE.md generated vendored Normal file
View File

@ -0,0 +1,27 @@
# The n8n Enterprise License (the “Enterprise License”)
Copyright (c) 2022-present n8n GmbH.
With regard to the n8n Software:
This software and associated documentation files (the "Software") may only be used in production, if
you (and any entity that you represent) hold a valid n8n Enterprise license corresponding to your
usage. Subject to the foregoing sentence, you are free to modify this Software and publish patches
to the Software. You agree that n8n and/or its licensors (as applicable) retain all right, title and
interest in and to all such modifications and/or patches, and all such modifications and/or patches
may only be used, copied, modified, displayed, distributed, or otherwise exploited with a valid n8n
Enterprise license for the corresponding usage. Notwithstanding the foregoing, you may copy and
modify the Software for development and testing purposes, without requiring a subscription. You
agree that n8n and/or its licensors (as applicable) retain all right, title and interest in and to
all such modifications. You are not granted any other rights beyond what is expressly stated herein.
Subject to the foregoing, it is forbidden to copy, merge, publish, distribute, sublicense, and/or
sell the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For all third party components incorporated into the n8n Software, those components are licensed
under the original license provided by the owner of the applicable component.

9
node_modules/@n8n/errors/dist/application.error.d.ts generated vendored Normal file
View File

@ -0,0 +1,9 @@
import type { Event } from '@sentry/node';
import type { ErrorLevel, ReportingOptions } from './types';
export declare class ApplicationError extends Error {
level: ErrorLevel;
readonly tags: NonNullable<Event['tags']>;
readonly extra?: Event['extra'];
readonly packageName?: string;
constructor(message: string, { level, tags, extra, ...rest }?: ErrorOptions & ReportingOptions);
}

24
node_modules/@n8n/errors/dist/application.error.js generated vendored Normal file
View File

@ -0,0 +1,24 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationError = void 0;
const callsites_1 = __importDefault(require("callsites"));
class ApplicationError extends Error {
constructor(message, { level, tags = {}, extra, ...rest } = {}) {
super(message, rest);
this.level = level ?? 'error';
this.tags = tags;
this.extra = extra;
try {
const filePath = (0, callsites_1.default)()[2].getFileName() ?? '';
const match = /packages\/([^\/]+)\//.exec(filePath)?.[1];
if (match)
this.tags.packageName = match;
}
catch { }
}
}
exports.ApplicationError = ApplicationError;
//# sourceMappingURL=application.error.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"application.error.js","sourceRoot":"","sources":["../src/application.error.ts"],"names":[],"mappings":";;;;;;AACA,0DAAkC;AAOlC,MAAa,gBAAiB,SAAQ,KAAK;IAS1C,YACC,OAAe,EACf,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,IAAI,KAAsC,EAAE;QAE1E,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,OAAO,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,IAAA,mBAAS,GAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC;YAEpD,MAAM,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAEzD,IAAI,KAAK;gBAAE,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAE1C,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;CACD;AA3BD,4CA2BC"}

1
node_modules/@n8n/errors/dist/build.tsbuildinfo generated vendored Normal file

File diff suppressed because one or more lines are too long

2
node_modules/@n8n/errors/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,2 @@
export { ApplicationError } from './application.error';
export type * from './types';

6
node_modules/@n8n/errors/dist/index.js generated vendored Normal file
View File

@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationError = void 0;
var application_error_1 = require("./application.error");
Object.defineProperty(exports, "ApplicationError", { enumerable: true, get: function () { return application_error_1.ApplicationError; } });
//# sourceMappingURL=index.js.map

1
node_modules/@n8n/errors/dist/index.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA"}

11
node_modules/@n8n/errors/dist/types.d.ts generated vendored Normal file
View File

@ -0,0 +1,11 @@
import type { Event } from '@sentry/node';
export type ErrorLevel = 'fatal' | 'error' | 'warning' | 'info';
export type ErrorTags = NonNullable<Event['tags']>;
export type ReportingOptions = {
shouldReport?: boolean;
shouldBeLogged?: boolean;
level?: ErrorLevel;
tags?: ErrorTags;
extra?: Event['extra'];
executionId?: string;
};

3
node_modules/@n8n/errors/dist/types.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

1
node_modules/@n8n/errors/dist/types.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}

42
node_modules/@n8n/errors/package.json generated vendored Normal file
View File

@ -0,0 +1,42 @@
{
"name": "@n8n/errors",
"version": "0.5.0",
"main": "dist/index.js",
"module": "src/index.ts",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"LICENSE.md",
"LICENSE_EE.md"
],
"devDependencies": {
"@sentry/node": "^9.42.1",
"@n8n/typescript-config": "1.3.0"
},
"dependencies": {
"callsites": "3.1.0"
},
"license": "SEE LICENSE IN LICENSE.md",
"homepage": "https://n8n.io",
"author": {
"name": "Jan Oberhauser",
"email": "jan@n8n.io"
},
"repository": {
"type": "git",
"url": "git+https://github.com/n8n-io/n8n.git"
},
"scripts": {
"clean": "rimraf dist .turbo",
"dev": "pnpm watch",
"typecheck": "tsc --noEmit",
"build": "tsc -p tsconfig.build.json",
"format": "biome format --write .",
"format:check": "biome ci .",
"lint": "eslint . --quiet",
"lint:fix": "eslint . --fix",
"watch": "tsc -p tsconfig.build.json --watch",
"test": "echo \"WARNING: no test specified\" && exit 0",
"test:dev": "echo \"WARNING: no test specified\" && exit 0"
}
}

201
node_modules/@n8n/tournament/LICENSE.md generated vendored Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2023 n8n GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

23
node_modules/@n8n/tournament/dist/Analysis.d.ts generated vendored Normal file
View File

@ -0,0 +1,23 @@
import type { ExpressionAnalysis } from './ExpressionBuilder';
interface TmplOrTournament {
tmpl: boolean;
tournament: boolean;
}
interface TmplSame {
same: true;
expression?: SanitizedString;
}
interface TmplDiff {
same: false;
expression: SanitizedString | 'UNPARSEABLE';
has?: ExpressionAnalysis['has'];
parserError?: TmplOrTournament;
}
export type TmplDifference = TmplSame | TmplDiff;
export declare const getTmplDifference: (expr: string, dataNodeName: string) => TmplDifference;
export interface SanitizedString {
value: string;
sanitized: 'ACTUALLY_SANITIZED_DO_NOT_MANUALLY_MAKE_THIS_OBJECT';
}
export declare const stripIdentifyingInformation: (expr: string) => SanitizedString;
export {};

134
node_modules/@n8n/tournament/dist/Analysis.js generated vendored Normal file
View File

@ -0,0 +1,134 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripIdentifyingInformation = exports.getTmplDifference = void 0;
const tmpl = __importStar(require("@n8n_io/riot-tmpl"));
const recast_1 = require("recast");
const Differ_1 = require("./Differ");
const ExpressionBuilder_1 = require("./ExpressionBuilder");
const ExpressionSplitter_1 = require("./ExpressionSplitter");
const getTmplDifference = (expr, dataNodeName) => {
if (!expr) {
return { same: true };
}
if (tmpl.brackets.settings.brackets !== '{{ }}') {
tmpl.brackets.set('{{ }}');
}
let tournParsed;
let tmplParsed;
let analysis;
try {
[tournParsed, analysis] = (0, ExpressionBuilder_1.getExpressionCode)(expr, dataNodeName, { before: [], after: [] });
}
catch (e) {
tournParsed = null;
analysis = null;
}
try {
tmplParsed = tmpl.tmpl.getStr(expr);
}
catch (e) {
tmplParsed = null;
}
if ((analysis === null || analysis === void 0 ? void 0 : analysis.has.function) || (analysis === null || analysis === void 0 ? void 0 : analysis.has.templateString)) {
return {
same: false,
expression: (0, exports.stripIdentifyingInformation)(expr),
has: analysis.has,
};
}
if (tournParsed === null && tmplParsed === null) {
return { same: true };
}
else if (tournParsed === null) {
return {
same: false,
expression: 'UNPARSEABLE',
parserError: {
tmpl: false,
tournament: true,
},
};
}
else if (tmplParsed === null) {
return {
same: false,
expression: (0, exports.stripIdentifyingInformation)(expr),
parserError: {
tmpl: true,
tournament: false,
},
};
}
const different = (0, Differ_1.isDifferent)(tmplParsed, tournParsed);
if (different) {
return {
same: false,
expression: (0, exports.stripIdentifyingInformation)(expr),
};
}
return { same: true, expression: (0, exports.stripIdentifyingInformation)(expr) };
};
exports.getTmplDifference = getTmplDifference;
const CHAR_REPLACE = /\S/gu;
const replaceValue = (value) => {
return value.replace(CHAR_REPLACE, 'v');
};
const stripIdentifyingInformation = (expr) => {
const chunks = (0, ExpressionBuilder_1.getParsedExpression)(expr);
for (const chunk of chunks) {
if (chunk.type === 'text') {
chunk.text = replaceValue(chunk.text);
}
else {
(0, recast_1.visit)(chunk.parsed, {
visitLiteral(path) {
this.traverse(path);
if (typeof path.node.value === 'string') {
path.node.value = replaceValue(path.node.value);
}
},
visitStringLiteral(path) {
this.traverse(path);
path.node.value = replaceValue(path.node.value);
},
visitTemplateElement(path) {
this.traverse(path);
if (path.node.value.cooked !== null) {
path.node.value.cooked = replaceValue(path.node.value.cooked);
}
path.node.value.raw = replaceValue(path.node.value.raw);
},
});
chunk.text = (0, recast_1.print)(chunk.parsed).code;
}
}
return {
value: (0, ExpressionSplitter_1.joinExpression)(chunks),
sanitized: 'ACTUALLY_SANITIZED_DO_NOT_MANUALLY_MAKE_THIS_OBJECT',
};
};
exports.stripIdentifyingInformation = stripIdentifyingInformation;
//# sourceMappingURL=Analysis.js.map

1
node_modules/@n8n/tournament/dist/Analysis.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"Analysis.js","sourceRoot":"","sources":["../src/Analysis.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0C;AAC1C,mCAAsC;AACtC,qCAAuC;AAGvC,2DAA6E;AAC7E,6DAAsD;AAkB/C,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,YAAoB,EAAkB,EAAE;IACvF,IAAI,CAAC,IAAI,EAAE;QACV,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;KACtB;IACD,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,KAAK,OAAO,EAAE;QAChD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KAC3B;IACD,IAAI,WAA0B,CAAC;IAC/B,IAAI,UAAyB,CAAC;IAC9B,IAAI,QAAmC,CAAC;IACxC,IAAI;QACH,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,IAAA,qCAAiB,EAAC,IAAI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I;oBACxB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACpB,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,IAAI,EAAE;wBACpC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;qBAC9D;oBACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACzD,CAAC;aACD,CAAC,CAAC;YACH,KAAK,CAAC,IAAI,GAAG,IAAA,cAAK,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;SACtC;KACD;IAED,OAAO;QACN,KAAK,EAAE,IAAA,mCAAc,EAAC,MAAM,CAAC;QAC7B,SAAS,EAAE,qDAAqD;KAChE,CAAC;AACH,CAAC,CAAC;AAlCW,QAAA,2BAA2B,+BAkCtC"}

3
node_modules/@n8n/tournament/dist/Constants.d.ts generated vendored Normal file
View File

@ -0,0 +1,3 @@
import type { CatchClauseKind, ExpressionKind, PatternKind, PropertyKind, StatementKind, VariableDeclaratorKind } from 'ast-types/lib/gen/kinds';
export declare const EXEMPT_IDENTIFIER_LIST: string[];
export type ParentKind = ExpressionKind | StatementKind | PropertyKind | PatternKind | VariableDeclaratorKind | CatchClauseKind;

13
node_modules/@n8n/tournament/dist/Constants.js generated vendored Normal file
View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EXEMPT_IDENTIFIER_LIST = void 0;
exports.EXEMPT_IDENTIFIER_LIST = [
'isFinite',
'isNaN',
'NaN',
'Date',
'RegExp',
'Math',
'undefined',
];
//# sourceMappingURL=Constants.js.map

1
node_modules/@n8n/tournament/dist/Constants.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../src/Constants.ts"],"names":[],"mappings":";;;AASa,QAAA,sBAAsB,GAAG;IACrC,UAAU;IACV,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,MAAM;IACN,WAAW;CACX,CAAC"}

1
node_modules/@n8n/tournament/dist/Differ.d.ts generated vendored Normal file
View File

@ -0,0 +1 @@
export declare const isDifferent: (tmpl: string, tourn: string) => boolean;

80
node_modules/@n8n/tournament/dist/Differ.js generated vendored Normal file
View File

@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDifferent = void 0;
const recast_1 = require("recast");
const Parser_1 = require("./Parser");
const isWrapped = (node) => {
var _a;
return ((_a = node.program.body[1]) === null || _a === void 0 ? void 0 : _a.type) === 'TryStatement';
};
const getWrapped = (node) => {
var _a;
return (_a = node.program.body[1]) === null || _a === void 0 ? void 0 : _a.block.body[0];
};
const isMultiPartExpression = (node) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
return (((_a = node.program.body[1]) === null || _a === void 0 ? void 0 : _a.type) === 'ReturnStatement' &&
((_b = node.program.body[1].argument) === null || _b === void 0 ? void 0 : _b.type) === 'CallExpression' &&
((_d = (_c = node.program.body[1].argument) === null || _c === void 0 ? void 0 : _c.arguments[0]) === null || _d === void 0 ? void 0 : _d.type) === 'Literal' &&
((_f = (_e = node.program.body[1].argument) === null || _e === void 0 ? void 0 : _e.arguments[0]) === null || _f === void 0 ? void 0 : _f.value) === '' &&
((_g = node.program.body[1].argument) === null || _g === void 0 ? void 0 : _g.callee.type) === 'MemberExpression' &&
((_h = node.program.body[1].argument) === null || _h === void 0 ? void 0 : _h.callee.object.type) === 'ArrayExpression' &&
((_j = node.program.body[1].argument) === null || _j === void 0 ? void 0 : _j.callee.property.type) === 'Identifier' &&
((_k = node.program.body[1].argument) === null || _k === void 0 ? void 0 : _k.callee.property.name) === 'join');
};
const getMultiPartExpression = (node) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
if (!(((_a = node.program.body[1]) === null || _a === void 0 ? void 0 : _a.type) === 'ReturnStatement' &&
((_b = node.program.body[1].argument) === null || _b === void 0 ? void 0 : _b.type) === 'CallExpression' &&
((_d = (_c = node.program.body[1].argument) === null || _c === void 0 ? void 0 : _c.arguments[0]) === null || _d === void 0 ? void 0 : _d.type) === 'Literal' &&
((_f = (_e = node.program.body[1].argument) === null || _e === void 0 ? void 0 : _e.arguments[0]) === null || _f === void 0 ? void 0 : _f.value) === '' &&
((_g = node.program.body[1].argument) === null || _g === void 0 ? void 0 : _g.callee.type) === 'MemberExpression' &&
((_h = node.program.body[1].argument) === null || _h === void 0 ? void 0 : _h.callee.object.type) === 'ArrayExpression')) {
return [];
}
return node.program.body[1].argument.callee.object.elements
.map((e) => {
if ((e === null || e === void 0 ? void 0 : e.type) !== 'CallExpression' ||
e.callee.type !== 'MemberExpression' ||
e.callee.object.type !== 'FunctionExpression') {
return null;
}
const maybeExpr = e.callee.object.body.body[0];
if (maybeExpr.type !== 'TryStatement') {
return maybeExpr;
}
return maybeExpr.block.body[0];
})
.filter((e) => e !== null);
};
const isDifferent = (tmpl, tourn) => {
const tmplParsed = (0, recast_1.parse)(tmpl, {
parser: { parse: Parser_1.parseWithEsprimaNext },
});
const tournParsed = (0, recast_1.parse)(tourn, {
parser: { parse: Parser_1.parseWithEsprimaNext },
});
const problemPaths = [];
let same = recast_1.types.astNodesAreEquivalent(tmplParsed, tournParsed, problemPaths);
if (!same) {
if (isWrapped(tournParsed) && !isWrapped(tmplParsed)) {
const tournWrapped = getWrapped(tournParsed);
same = recast_1.types.astNodesAreEquivalent(tmplParsed.program.body[1], tournWrapped);
}
else if (isMultiPartExpression(tournParsed) && isMultiPartExpression(tmplParsed)) {
const tournExprs = getMultiPartExpression(tournParsed);
const tmplExprs = getMultiPartExpression(tmplParsed);
if (tournExprs.length === tmplExprs.length) {
for (let i = 0; i < tournExprs.length; i++) {
same = recast_1.types.astNodesAreEquivalent(tmplExprs[i], tournExprs[i], problemPaths);
if (!same) {
break;
}
}
}
}
}
return !same;
};
exports.isDifferent = isDifferent;
//# sourceMappingURL=Differ.js.map

1
node_modules/@n8n/tournament/dist/Differ.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"Differ.js","sourceRoot":"","sources":["../src/Differ.ts"],"names":[],"mappings":";;;AACA,mCAAsC;AACtC,qCAAgD;AAEhD,MAAM,SAAS,GAAG,CAAC,IAA2B,EAAW,EAAE;;IAC1D,OAAO,CAAA,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,IAAI,MAAK,cAAc,CAAC;AACtD,CAAC,CAAC;AACF,MAAM,UAAU,GAAG,CAAC,IAA2B,EAAE,EAAE;;IAClD,OAAO,MAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAmC,0CAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAAC,IAA2B,EAAW,EAAE;;IACtE,OAAO,CACN,CAAA,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,IAAI,MAAK,iBAAiB;QAChD,CAAA,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,0CAAE,IAAI,MAAK,gBAAgB;QACxD,CAAA,MAAA,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,0CAAE,SAAS,CAAC,CAAC,CAAC,0CAAE,IAAI,MAAK,SAAS;QAC/D,CAAA,MAAA,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,0CAAE,SAAS,CAAC,CAAC,CAAC,0CAAE,KAAK,MAAK,EAAE;QACzD,CAAA,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,0CAA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Y,CAAC,CAAC;IAQ9E,IAAI,CAAC,IAAI,EAAE;QACV,IAAI,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YAErD,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;YAC7C,IAAI,GAAG,cAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;SAC7E;aAAM,IAAI,qBAAqB,CAAC,WAAW,CAAC,IAAI,qBAAqB,CAAC,UAAU,CAAC,EAAE;YAEnF,MAAM,UAAU,GAAG,sBAAsB,CAAC,WAAW,CAAC,CAAC;YACvD,MAAM,SAAS,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC;YACrD,IAAI,UAAU,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE;gBAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBAC3C,IAAI,GAAG,cAAK,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;oBAC9E,IAAI,CAAC,IAAI,EAAE;wBACV,MAAM;qBACN;iBACD;aACD;SACD;KACD;IAED,OAAO,CAAC,IAAI,CAAC;AACd,CAAC,CAAC;AAtCW,QAAA,WAAW,eAsCtB"}

7
node_modules/@n8n/tournament/dist/Evaluator.d.ts generated vendored Normal file
View File

@ -0,0 +1,7 @@
import type { ReturnValue, Tournament } from '.';
export interface ExpressionEvaluator {
evaluate(code: string, data: unknown): ReturnValue;
}
export interface ExpressionEvaluatorClass {
new (instance: Tournament): ExpressionEvaluator;
}

3
node_modules/@n8n/tournament/dist/Evaluator.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=Evaluator.js.map

1
node_modules/@n8n/tournament/dist/Evaluator.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"Evaluator.js","sourceRoot":"","sources":["../src/Evaluator.ts"],"names":[],"mappings":""}

View File

@ -0,0 +1,15 @@
import type { types } from 'recast';
import type { ExpressionCode, ExpressionText } from './ExpressionSplitter';
import type { TournamentHooks } from './ast';
export interface ExpressionAnalysis {
has: {
function: boolean;
templateString: boolean;
};
}
type ParsedCode = ExpressionCode & {
parsed: types.namedTypes.File;
};
export declare const getParsedExpression: (expr: string) => Array<ExpressionText | ParsedCode>;
export declare const getExpressionCode: (expr: string, dataNodeName: string, hooks: TournamentHooks) => [string, ExpressionAnalysis];
export {};

186
node_modules/@n8n/tournament/dist/ExpressionBuilder.js generated vendored Normal file
View File

@ -0,0 +1,186 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExpressionCode = exports.getParsedExpression = void 0;
const recast_1 = require("recast");
const ast_types_1 = require("ast-types");
const VariablePolyfill_1 = require("./VariablePolyfill");
const ExpressionSplitter_1 = require("./ExpressionSplitter");
const Parser_1 = require("./Parser");
const v = ast_types_1.builders.identifier('v');
const shouldAlwaysWrapList = ['window', 'global', 'this'];
const shouldWrapInTry = (node) => {
let shouldWrap = false;
(0, recast_1.visit)(node, {
visitMemberExpression() {
shouldWrap = true;
return false;
},
visitCallExpression() {
shouldWrap = true;
return false;
},
visitIdentifier(path) {
if (shouldAlwaysWrapList.includes(path.node.name)) {
shouldWrap = true;
return false;
}
this.traverse(path);
return;
},
});
return shouldWrap;
};
const hasFunction = (node) => {
let hasFn = false;
(0, recast_1.visit)(node, {
visitFunctionExpression() {
hasFn = true;
return false;
},
visitFunctionDeclaration() {
hasFn = true;
return false;
},
visitArrowFunctionExpression() {
hasFn = true;
return false;
},
});
return hasFn;
};
const hasTemplateString = (node) => {
let hasTemp = false;
(0, recast_1.visit)(node, {
visitTemplateLiteral(path) {
if (path.node.expressions.length) {
hasTemp = true;
return false;
}
this.traverse(path);
return;
},
});
return hasTemp;
};
const wrapInErrorHandler = (node) => {
return ast_types_1.builders.tryStatement(ast_types_1.builders.blockStatement([node]), ast_types_1.builders.catchClause(ast_types_1.builders.identifier('e'), null, ast_types_1.builders.blockStatement([
ast_types_1.builders.expressionStatement(ast_types_1.builders.callExpression(ast_types_1.builders.identifier('E'), [ast_types_1.builders.identifier('e'), ast_types_1.builders.thisExpression()])),
])));
};
const maybeWrapExpr = (expr) => {
if (expr.trimStart()[0] === '{') {
return '(' + expr + ')';
}
return expr;
};
const buildFunctionBody = (expr) => {
return ast_types_1.builders.blockStatement([
ast_types_1.builders.expressionStatement(ast_types_1.builders.assignmentExpression('=', v, expr)),
ast_types_1.builders.returnStatement(ast_types_1.builders.conditionalExpression(ast_types_1.builders.logicalExpression('||', ast_types_1.builders.logicalExpression('||', v, ast_types_1.builders.binaryExpression('===', v, ast_types_1.builders.literal(0))), ast_types_1.builders.binaryExpression('===', v, ast_types_1.builders.literal(false))), v, ast_types_1.builders.literal(''))),
]);
};
const fixStringNewLines = (node) => {
const replace = (str) => {
return str.replace(/\n/g, '\\n');
};
(0, recast_1.visit)(node, {
visitTemplateElement(path) {
this.traverse(path);
const el = ast_types_1.builders.templateElement({
cooked: path.node.value.cooked === null ? null : replace(path.node.value.cooked),
raw: replace(path.node.value.raw),
}, path.node.tail);
path.replace(el);
},
});
return node;
};
const getParsedExpression = (expr) => {
return (0, ExpressionSplitter_1.splitExpression)(expr).map((chunk) => {
if (chunk.type === 'code') {
const code = maybeWrapExpr(chunk.text);
const node = (0, recast_1.parse)(code, {
parser: { parse: Parser_1.parseWithEsprimaNext },
});
return { ...chunk, parsed: node };
}
return chunk;
});
};
exports.getParsedExpression = getParsedExpression;
const getExpressionCode = (expr, dataNodeName, hooks) => {
var _a, _b;
const chunks = (0, exports.getParsedExpression)(expr);
const newProg = ast_types_1.builders.program([
ast_types_1.builders.variableDeclaration('var', [ast_types_1.builders.variableDeclarator(VariablePolyfill_1.globalIdentifier, ast_types_1.builders.objectExpression([]))]),
]);
let dataNode = ast_types_1.builders.thisExpression();
const hasFn = chunks.filter((c) => c.type === 'code').some((c) => hasFunction(c.parsed));
if (hasFn) {
dataNode = ast_types_1.builders.identifier(dataNodeName);
newProg.body.push(ast_types_1.builders.variableDeclaration('var', [ast_types_1.builders.variableDeclarator(dataNode, ast_types_1.builders.thisExpression())]));
}
const hasTempString = chunks.filter((c) => c.type === 'code').some((c) => hasTemplateString(c.parsed));
if (chunks.length > 2 ||
chunks[0].text !== '' ||
(chunks[0].text === '' && chunks.length === 1)) {
let parts = [];
for (const chunk of chunks) {
if (chunk.type === 'text') {
parts.push(ast_types_1.builders.literal(chunk.text));
}
else {
const fixed = fixStringNewLines(chunk.parsed);
for (const hook of hooks.before) {
hook(fixed, dataNode);
}
const parsed = (_a = (0, VariablePolyfill_1.jsVariablePolyfill)(fixed, dataNode)) === null || _a === void 0 ? void 0 : _a[0];
if (!parsed || parsed.type !== 'ExpressionStatement') {
throw new SyntaxError('Not a expression statement');
}
for (const hook of hooks.after) {
hook(parsed, dataNode);
}
const functionBody = buildFunctionBody(parsed.expression);
if (shouldWrapInTry(parsed)) {
functionBody.body = [
wrapInErrorHandler(functionBody.body[0]),
ast_types_1.builders.expressionStatement(ast_types_1.builders.identifier('')),
functionBody.body[1],
];
}
parts.push(ast_types_1.builders.callExpression(ast_types_1.builders.memberExpression(ast_types_1.builders.functionExpression(null, [v], functionBody), ast_types_1.builders.identifier('call')), [ast_types_1.builders.thisExpression()]));
}
}
if (chunks.length < 2) {
newProg.body.push(ast_types_1.builders.returnStatement(parts[0]));
}
else {
parts = parts.filter((i) => !(i.type === 'Literal' && i.value === ''));
newProg.body.push(ast_types_1.builders.returnStatement(ast_types_1.builders.callExpression(ast_types_1.builders.memberExpression(ast_types_1.builders.arrayExpression(parts), ast_types_1.builders.identifier('join')), [
ast_types_1.builders.literal(''),
])));
}
}
else {
const fixed = fixStringNewLines(chunks[1].parsed);
for (const hook of hooks.before) {
hook(fixed, dataNode);
}
const parsed = (_b = (0, VariablePolyfill_1.jsVariablePolyfill)(fixed, dataNode)) === null || _b === void 0 ? void 0 : _b[0];
if (!parsed || parsed.type !== 'ExpressionStatement') {
throw new SyntaxError('Not a expression statement');
}
for (const hook of hooks.after) {
hook(parsed, dataNode);
}
let retData = ast_types_1.builders.returnStatement(parsed.expression);
if (shouldWrapInTry(parsed)) {
retData = wrapInErrorHandler(retData);
}
newProg.body.push(retData);
}
return [(0, recast_1.print)(newProg).code, { has: { function: hasFn, templateString: hasTempString } }];
};
exports.getExpressionCode = getExpressionCode;
//# sourceMappingURL=ExpressionBuilder.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,13 @@
export interface ExpressionText {
type: 'text';
text: string;
}
export interface ExpressionCode {
type: 'code';
text: string;
hasClosingBrackets: boolean;
}
export type ExpressionChunk = ExpressionCode | ExpressionText;
export declare const escapeCode: (text: string) => string;
export declare const splitExpression: (expression: string) => ExpressionChunk[];
export declare const joinExpression: (parts: ExpressionChunk[]) => string;

View File

@ -0,0 +1,87 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.joinExpression = exports.splitExpression = exports.escapeCode = void 0;
const OPEN_BRACKET = /(?<brackets>\{\{)/;
const CLOSE_BRACKET = /(?<brackets>\}\})/;
const escapeCode = (text) => {
return text.replace('\\}}', '}}');
};
exports.escapeCode = escapeCode;
const normalizeBackslashes = (text) => {
return text.replace(/\\\\/g, '\\');
};
const splitExpression = (expression) => {
var _a, _b, _c;
const chunks = [];
let searchingFor = 'open';
let activeRegex = OPEN_BRACKET;
let buffer = '';
let index = 0;
while (index < expression.length) {
const expr = expression.slice(index);
const res = activeRegex.exec(expr);
if (!(res === null || res === void 0 ? void 0 : res.groups)) {
buffer += expr;
if (searchingFor === 'open') {
chunks.push({
type: 'text',
text: buffer,
});
}
else {
chunks.push({
type: 'code',
text: (0, exports.escapeCode)(buffer),
hasClosingBrackets: false,
});
}
break;
}
const beforeMatch = expr.slice(0, res.index);
const backslashCount = (_c = (_b = (_a = beforeMatch.match(/\\*$/)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
const isEscaped = backslashCount % 2 === 1;
if (isEscaped) {
buffer += expr.slice(0, res.index + '{{'.length);
index += res.index + '{{'.length;
}
else {
buffer += expr.slice(0, res.index);
if (searchingFor === 'open') {
chunks.push({
type: 'text',
text: normalizeBackslashes(buffer),
});
searchingFor = 'close';
activeRegex = CLOSE_BRACKET;
}
else {
chunks.push({
type: 'code',
text: (0, exports.escapeCode)(buffer),
hasClosingBrackets: true,
});
searchingFor = 'open';
activeRegex = OPEN_BRACKET;
}
index += res.index + 2;
buffer = '';
}
}
return chunks;
};
exports.splitExpression = splitExpression;
const escapeTmplExpression = (part) => {
return part.replace('}}', '\\}}');
};
const joinExpression = (parts) => {
return parts
.map((chunk) => {
if (chunk.type === 'code') {
return `{{${escapeTmplExpression(chunk.text)}${chunk.hasClosingBrackets ? '}}' : ''}`;
}
return chunk.text;
})
.join('');
};
exports.joinExpression = joinExpression;
//# sourceMappingURL=ExpressionSplitter.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ExpressionSplitter.js","sourceRoot":"","sources":["../src/ExpressionSplitter.ts"],"names":[],"mappings":";;;AAeA,MAAM,YAAY,GAAG,mBAAmB,CAAC;AACzC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAEnC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;AAEF,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAU,EAAE;IACrD,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC;AAEK,MAAM,eAAe,GAAG,CAAC,UAAkB,EAAqB,EAAE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C;IACnB,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC,CAAC;AACZ,CAAC,CAAC;AATW,QAAA,cAAc,kBASzB"}

View File

@ -0,0 +1,8 @@
import type { ExpressionEvaluator, ReturnValue, Tournament } from '.';
export declare class FunctionEvaluator implements ExpressionEvaluator {
private instance;
private _codeCache;
constructor(instance: Tournament);
private getFunction;
evaluate(expr: string, data: unknown): ReturnValue;
}

24
node_modules/@n8n/tournament/dist/FunctionEvaluator.js generated vendored Normal file
View File

@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionEvaluator = void 0;
class FunctionEvaluator {
constructor(instance) {
this.instance = instance;
this._codeCache = {};
}
getFunction(expr) {
if (expr in this._codeCache) {
return this._codeCache[expr];
}
const [code] = this.instance.getExpressionCode(expr);
const func = new Function('E', code + ';');
this._codeCache[expr] = func;
return func;
}
evaluate(expr, data) {
const fn = this.getFunction(expr);
return fn.call(data, this.instance.errorHandler);
}
}
exports.FunctionEvaluator = FunctionEvaluator;
//# sourceMappingURL=FunctionEvaluator.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"FunctionEvaluator.js","sourceRoot":"","sources":["../src/FunctionEvaluator.ts"],"names":[],"mappings":";;;AAEA,MAAa,iBAAiB;IAG7B,YAAoB,QAAoB;QAApB,aAAQ,GAAR,QAAQ,CAAY;QAFhC,eAAU,GAA6B,EAAE,CAAC;IAEP,CAAC;IAEpC,WAAW,CAAC,IAAY;QAC/B,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;SAC7B;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACrD,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,IAAI,GAAG,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,QAAQ,CAAC,IAAY,EAAE,IAAa;QACnC,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAClC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;CACD;AAnBD,8CAmBC"}

1
node_modules/@n8n/tournament/dist/Parser.d.ts generated vendored Normal file
View File

@ -0,0 +1 @@
export declare function parseWithEsprimaNext(source: string, options?: any): any;

27
node_modules/@n8n/tournament/dist/Parser.js generated vendored Normal file
View File

@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseWithEsprimaNext = void 0;
const esprima_next_1 = require("esprima-next");
const util_1 = require("recast/lib/util");
function parseWithEsprimaNext(source, options) {
try {
const ast = (0, esprima_next_1.parse)(source, {
loc: true,
locations: true,
comment: true,
range: (0, util_1.getOption)(options, 'range', false),
tolerant: (0, util_1.getOption)(options, 'tolerant', true),
tokens: true,
jsx: (0, util_1.getOption)(options, 'jsx', false),
sourceType: (0, util_1.getOption)(options, 'sourceType', 'module'),
});
return ast;
}
catch (error) {
if (error instanceof Error)
throw new SyntaxError(error.message);
throw error;
}
}
exports.parseWithEsprimaNext = parseWithEsprimaNext;
//# sourceMappingURL=Parser.js.map

1
node_modules/@n8n/tournament/dist/Parser.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"Parser.js","sourceRoot":"","sources":["../src/Parser.ts"],"names":[],"mappings":";;;AAAA,+CAAqD;AAErD,0CAA4C;AAE5C,SAAgB,oBAAoB,CAAC,MAAc,EAAE,OAAa;IACjE,IAAI;QACH,MAAM,GAAG,GAAG,IAAA,oBAAY,EAAC,MAAM,EAAE;YAChC,GAAG,EAAE,IAAI;YACT,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAA,gBAAS,EAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAY;YACpD,QAAQ,EAAE,IAAA,gBAAS,EAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAY;YACzD,MAAM,EAAE,IAAI;YACZ,GAAG,EAAE,IAAA,gBAAS,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAY;YAChD,UAAU,EAAE,IAAA,gBAAS,EAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAW;SAC/C,CAAC,CAAC;QAEpB,OAAO,GAAG,CAAC;KACX;IAAC,OAAO,KAAK,EAAE;QACf,IAAI,KAAK,YAAY,KAAK;YAAE,MAAM,IAAI,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjE,MAAM,KAAK,CAAC;KACZ;AACF,CAAC;AAlBD,oDAkBC"}

View File

@ -0,0 +1,6 @@
import type { types } from 'recast';
import type { StatementKind } from 'ast-types/lib/gen/kinds';
import type { namedTypes } from 'ast-types';
export declare const globalIdentifier: namedTypes.Identifier;
export type DataNode = namedTypes.ThisExpression | namedTypes.Identifier;
export declare const jsVariablePolyfill: (ast: types.namedTypes.File, dataNode: DataNode) => StatementKind[] | undefined;

253
node_modules/@n8n/tournament/dist/VariablePolyfill.js generated vendored Normal file
View File

@ -0,0 +1,253 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsVariablePolyfill = exports.globalIdentifier = void 0;
const recast_1 = require("recast");
const ast_types_1 = require("ast-types");
const Constants_1 = require("./Constants");
function assertNever(value) {
return true;
}
exports.globalIdentifier = ast_types_1.builders.identifier(typeof window !== 'object' ? 'global' : 'window');
const buildGlobalSwitch = (node, dataNode) => {
return ast_types_1.builders.memberExpression(ast_types_1.builders.conditionalExpression(ast_types_1.builders.binaryExpression('in', ast_types_1.builders.literal(node.name), dataNode), dataNode, exports.globalIdentifier), ast_types_1.builders.identifier(node.name));
};
const isInScope = (path) => {
let scope = path.scope;
while (scope !== null) {
if (scope.declares(path.node.name)) {
return true;
}
scope = scope.parent;
}
return false;
};
const polyfillExceptions = ['this', 'window', 'global'];
const polyfillVar = (path, dataNode, force = false) => {
if (!force) {
if (isInScope(path)) {
return;
}
}
if (polyfillExceptions.includes(path.node.name)) {
return;
}
path.replace(buildGlobalSwitch(path.node, dataNode));
};
const customPatches = {
MemberExpression(path, parent, dataNode) {
if (parent.object === path.node || parent.computed) {
polyfillVar(path, dataNode);
}
},
OptionalMemberExpression(path, parent, dataNode) {
if (parent.object === path.node) {
polyfillVar(path, dataNode);
}
},
Property(path, parent, dataNode) {
var _a, _b, _c;
if (path.node !== parent.value) {
return;
}
const objPattern = (_b = (_a = path.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.node;
if (!objPattern) {
return;
}
const objParent = (_c = path.parent.parent.parent) === null || _c === void 0 ? void 0 : _c.node;
if (!objParent) {
return;
}
if (objParent.type === 'VariableDeclarator' && objParent.id === objPattern) {
return;
}
parent.shorthand = false;
polyfillVar(path, dataNode);
},
AssignmentPattern(path, parent, dataNode) {
if (parent.right === path.node) {
polyfillVar(path, dataNode);
}
},
VariableDeclarator(path, parent, dataNode) {
if (parent.init === path.node) {
polyfillVar(path, dataNode);
}
},
};
const jsVariablePolyfill = (ast, dataNode) => {
(0, recast_1.visit)(ast, {
visitImportExpression(_path) {
throw new Error('Imports are not supported');
},
visitIdentifier(path) {
this.traverse(path);
const parent = path.parent.node;
if (Constants_1.EXEMPT_IDENTIFIER_LIST.includes(path.node.name)) {
return;
}
switch (parent.type) {
case 'AssignmentPattern':
case 'Property':
case 'MemberExpression':
case 'OptionalMemberExpression':
case 'VariableDeclarator':
if (!customPatches[parent.type]) {
throw new Error(`Couldn\'t find custom patcher for parent type: ${parent.type}`);
}
customPatches[parent.type](path, parent, dataNode);
break;
case 'BinaryExpression':
case 'UnaryExpression':
case 'ArrayExpression':
case 'AssignmentExpression':
case 'SequenceExpression':
case 'YieldExpression':
case 'UpdateExpression':
case 'LogicalExpression':
case 'ConditionalExpression':
case 'NewExpression':
case 'CallExpression':
case 'OptionalCallExpression':
case 'TaggedTemplateExpression':
case 'TemplateLiteral':
case 'AwaitExpression':
case 'ImportExpression':
case 'ForStatement':
case 'IfStatement':
case 'WhileStatement':
case 'ForInStatement':
case 'ForOfStatement':
case 'SwitchStatement':
case 'ReturnStatement':
case 'DoWhileStatement':
case 'ExpressionStatement':
case 'ForAwaitStatement':
case 'ThrowStatement':
case 'WithStatement':
case 'TupleExpression':
polyfillVar(path, dataNode);
break;
case 'Super':
case 'Identifier':
case 'ArrowFunctionExpression':
case 'FunctionDeclaration':
case 'FunctionExpression':
case 'ThisExpression':
case 'ObjectExpression':
case 'MetaProperty':
case 'ChainExpression':
case 'PrivateName':
case 'ParenthesizedExpression':
case 'Import':
case 'VariableDeclaration':
case 'CatchClause':
case 'BlockStatement':
case 'TryStatement':
case 'EmptyStatement':
case 'LabeledStatement':
case 'BreakStatement':
case 'ContinueStatement':
case 'DebuggerStatement':
case 'ImportDeclaration':
case 'ExportDeclaration':
case 'ExportAllDeclaration':
case 'ExportDefaultDeclaration':
case 'Noop':
case 'ClassMethod':
case 'ClassPrivateMethod':
case 'RestElement':
case 'ArrayPattern':
case 'ObjectPattern':
case 'ClassExpression':
case 'RecordExpression':
case 'V8IntrinsicIdentifier':
case 'TopicReference':
case 'MethodDefinition':
case 'ClassDeclaration':
case 'ClassProperty':
case 'StaticBlock':
case 'ClassBody':
case 'ExportNamedDeclaration':
case 'ClassPrivateProperty':
case 'ClassAccessorProperty':
case 'PropertyPattern':
break;
case 'SpreadElementPattern':
case 'SpreadPropertyPattern':
case 'ClassPropertyDefinition':
break;
case 'DeclareClass':
case 'DeclareModule':
case 'DeclareVariable':
case 'DeclareFunction':
case 'DeclareInterface':
case 'DeclareTypeAlias':
case 'DeclareOpaqueType':
case 'DeclareModuleExports':
case 'DeclareExportDeclaration':
case 'DeclareExportAllDeclaration':
case 'InterfaceDeclaration':
case 'TypeAlias':
case 'OpaqueType':
case 'EnumDeclaration':
case 'TypeCastExpression':
break;
case 'TSAsExpression':
case 'TSTypeParameter':
case 'TSTypeAssertion':
case 'TSDeclareMethod':
case 'TSIndexSignature':
case 'TSDeclareFunction':
case 'TSMethodSignature':
case 'TSEnumDeclaration':
case 'TSExportAssignment':
case 'TSNonNullExpression':
case 'TSPropertySignature':
case 'TSModuleDeclaration':
case 'TSParameterProperty':
case 'TSTypeCastExpression':
case 'TSSatisfiesExpression':
case 'TSTypeAliasDeclaration':
case 'TSInterfaceDeclaration':
case 'TSImportEqualsDeclaration':
case 'TSExternalModuleReference':
case 'TSInstantiationExpression':
case 'TSTypeParameterDeclaration':
case 'TSCallSignatureDeclaration':
case 'TSNamespaceExportDeclaration':
case 'TSConstructSignatureDeclaration':
break;
case 'DirectiveLiteral':
case 'StringLiteral':
case 'NumericLiteral':
case 'BigIntLiteral':
case 'NullLiteral':
case 'Literal':
case 'RegExpLiteral':
case 'BooleanLiteral':
case 'DecimalLiteral':
break;
case 'DoExpression':
case 'BindExpression':
break;
case 'JSXIdentifier':
case 'JSXText':
case 'JSXElement':
case 'JSXFragment':
case 'JSXMemberExpression':
case 'JSXExpressionContainer':
break;
case 'ComprehensionExpression':
case 'GeneratorExpression':
polyfillVar(path, dataNode);
break;
default:
assertNever(parent);
break;
}
},
});
return ast.program.body;
};
exports.jsVariablePolyfill = jsVariablePolyfill;
//# sourceMappingURL=VariablePolyfill.js.map

File diff suppressed because one or more lines are too long

11
node_modules/@n8n/tournament/dist/ast.d.ts generated vendored Normal file
View File

@ -0,0 +1,11 @@
export type { types as astTypes } from 'recast';
export { visit as astVisit } from 'recast';
export { builders as astBuilders, type namedTypes as astNamedTypes } from 'ast-types';
import type { types } from 'recast';
import type { namedTypes } from 'ast-types';
export interface TournamentHooks {
before: ASTBeforeHook[];
after: ASTAfterHook[];
}
export type ASTAfterHook = (ast: namedTypes.ExpressionStatement, dataNode: namedTypes.ThisExpression | namedTypes.Identifier) => void;
export type ASTBeforeHook = (ast: types.namedTypes.File, dataNode: namedTypes.ThisExpression | namedTypes.Identifier) => void;

8
node_modules/@n8n/tournament/dist/ast.js generated vendored Normal file
View File

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.astBuilders = exports.astVisit = void 0;
var recast_1 = require("recast");
Object.defineProperty(exports, "astVisit", { enumerable: true, get: function () { return recast_1.visit; } });
var ast_types_1 = require("ast-types");
Object.defineProperty(exports, "astBuilders", { enumerable: true, get: function () { return ast_types_1.builders; } });
//# sourceMappingURL=ast.js.map

1
node_modules/@n8n/tournament/dist/ast.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":";;;AACA,iCAA2C;AAAlC,kGAAA,KAAK,OAAY;AAC1B,uCAAsF;AAA7E,wGAAA,QAAQ,OAAe"}

1
node_modules/@n8n/tournament/dist/build.tsbuildinfo generated vendored Normal file

File diff suppressed because one or more lines are too long

18
node_modules/@n8n/tournament/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,18 @@
import type { ExpressionAnalysis } from './ExpressionBuilder';
import type { ExpressionEvaluatorClass } from './Evaluator';
import type { TournamentHooks } from './ast';
export type { TmplDifference } from './Analysis';
export type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator';
export * from './ast';
export type ReturnValue = string | null | (() => unknown);
export declare class Tournament {
errorHandler: (error: Error) => void;
private _dataNodeName;
private readonly astHooks;
private evaluator;
constructor(errorHandler?: (error: Error) => void, _dataNodeName?: string, Evaluator?: ExpressionEvaluatorClass, astHooks?: TournamentHooks);
setEvaluator(Evaluator: ExpressionEvaluatorClass): void;
getExpressionCode(expr: string): [string, ExpressionAnalysis];
tmplDiff(expr: string): import("./Analysis").TmplDifference;
execute(expr: string, data: unknown): ReturnValue;
}

47
node_modules/@n8n/tournament/dist/index.js generated vendored Normal file
View File

@ -0,0 +1,47 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tournament = void 0;
const ExpressionBuilder_1 = require("./ExpressionBuilder");
const Analysis_1 = require("./Analysis");
const FunctionEvaluator_1 = require("./FunctionEvaluator");
__exportStar(require("./ast"), exports);
const DATA_NODE_NAME = '___n8n_data';
class Tournament {
constructor(errorHandler = () => { }, _dataNodeName = DATA_NODE_NAME, Evaluator = FunctionEvaluator_1.FunctionEvaluator, astHooks = { before: [], after: [] }) {
this.errorHandler = errorHandler;
this._dataNodeName = _dataNodeName;
this.astHooks = astHooks;
this.setEvaluator(Evaluator);
}
setEvaluator(Evaluator) {
this.evaluator = new Evaluator(this);
}
getExpressionCode(expr) {
return (0, ExpressionBuilder_1.getExpressionCode)(expr, this._dataNodeName, this.astHooks);
}
tmplDiff(expr) {
return (0, Analysis_1.getTmplDifference)(expr, this._dataNodeName);
}
execute(expr, data) {
if (!expr) {
return expr;
}
return this.evaluator.evaluate(expr, data);
}
}
exports.Tournament = Tournament;
//# sourceMappingURL=index.js.map

1
node_modules/@n8n/tournament/dist/index.js.map generated vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2DAAwD;AAExD,yCAA+C;AAE/C,2DAAwD;AAKxD,wCAAsB;AAEtB,MAAM,cAAc,GAAG,aAAa,CAAC;AAGrC,MAAa,UAAU;IAGtB,YACQ,eAAuC,GAAG,EAAE,GAAE,CAAC,EAC9C,gBAAwB,cAAc,EAC9C,YAAsC,qCAAiB,EACtC,WAA4B,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QAH/D,iBAAY,GAAZ,YAAY,CAAmC;QAC9C,kBAAa,GAAb,aAAa,CAAyB;QAE7B,aAAQ,GAAR,QAAQ,CAA6C;QAEtE,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IAED,YAAY,CAAC,SAAmC;QAC/C,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,iBAAiB,CAAC,IAAY;QAC7B,OAAO,IAAA,qCAAiB,EAAC,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,QAAQ,CAAC,IAAY;QACpB,OAAO,IAAA,4BAAiB,EAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,CAAC,IAAY,EAAE,IAAa;QAGlC,IAAI,CAAC,IAAI,EAAE;YACV,OAAO,IAAI,CAAC;SACZ;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;CACD;AAhCD,gCAgCC"}

65
node_modules/@n8n/tournament/package.json generated vendored Normal file
View File

@ -0,0 +1,65 @@
{
"name": "@n8n/tournament",
"version": "1.0.6",
"description": "Output compatible rewrite of riot tmpl",
"main": "dist/index.js",
"module": "src/index.ts",
"types": "dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./src/index.ts",
"types": "./dist/index.d.ts"
},
"./*": "./*"
},
"scripts": {
"start": "ts-node src/index.ts",
"build": "tsc -p ./tsconfig.build.json",
"prepack": "pnpm build",
"test": "jest",
"lint": "eslint .",
"lintfix": "eslint . --fix"
},
"engines": {
"node": ">=20.15",
"pnpm": ">=9.5"
},
"files": [
"src/",
"dist/",
"LICENSE.md",
"package.json",
"tsconfig.json"
],
"packageManager": "pnpm@9.6.0",
"keywords": [],
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@n8n_io/eslint-config": "^0.0.2",
"@types/jest": "^29.5.0",
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"eslint": "^8.38.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-n8n-local-rules": "^1.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-unicorn": "^48.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"jest": "^29.5.0",
"nodemon": "^2.0.20",
"prettier": "^3.0.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"tsc-alias": "^1.8.7",
"typescript": "^5.0.0"
},
"dependencies": {
"@n8n_io/riot-tmpl": "^4.0.1",
"ast-types": "^0.16.1",
"esprima-next": "^5.8.4",
"recast": "^0.22.0"
}
}

138
node_modules/@n8n/tournament/src/Analysis.ts generated vendored Normal file
View File

@ -0,0 +1,138 @@
import * as tmpl from '@n8n_io/riot-tmpl';
import { print, visit } from 'recast';
import { isDifferent } from './Differ';
import type { ExpressionAnalysis } from './ExpressionBuilder';
import { getExpressionCode, getParsedExpression } from './ExpressionBuilder';
import { joinExpression } from './ExpressionSplitter';
interface TmplOrTournament {
tmpl: boolean;
tournament: boolean;
}
interface TmplSame {
same: true;
expression?: SanitizedString;
}
interface TmplDiff {
same: false;
expression: SanitizedString | 'UNPARSEABLE';
has?: ExpressionAnalysis['has'];
parserError?: TmplOrTournament;
}
export type TmplDifference = TmplSame | TmplDiff;
export const getTmplDifference = (expr: string, dataNodeName: string): TmplDifference => {
if (!expr) {
return { same: true };
}
if (tmpl.brackets.settings.brackets !== '{{ }}') {
tmpl.brackets.set('{{ }}');
}
let tournParsed: string | null;
let tmplParsed: string | null;
let analysis: ExpressionAnalysis | null;
try {
[tournParsed, analysis] = getExpressionCode(expr, dataNodeName, { before: [], after: [] });
} catch (e) {
tournParsed = null;
analysis = null;
}
try {
tmplParsed = tmpl.tmpl.getStr(expr);
} catch (e) {
tmplParsed = null;
}
if (analysis?.has.function || analysis?.has.templateString) {
return {
same: false,
expression: stripIdentifyingInformation(expr),
has: analysis.has,
};
}
if (tournParsed === null && tmplParsed === null) {
// Bad expression
return { same: true };
} else if (tournParsed === null) {
// Unparsable expression for tournament
return {
same: false,
expression: 'UNPARSEABLE',
parserError: {
tmpl: false,
tournament: true,
},
};
} else if (tmplParsed === null) {
// Unparsable expression for tmpl
return {
same: false,
expression: stripIdentifyingInformation(expr),
parserError: {
tmpl: true,
tournament: false,
},
};
}
const different = isDifferent(tmplParsed, tournParsed);
if (different) {
// Different output
return {
same: false,
expression: stripIdentifyingInformation(expr),
};
}
// Same, nothing to report
return { same: true, expression: stripIdentifyingInformation(expr) };
};
const CHAR_REPLACE = /\S/gu;
// Replace all non-whitespace characters with the letter v.
// This should work with all characters since we're just
// matching on all non-whitespace characters, including
// anything outside the ASCII code points.
const replaceValue = (value: string): string => {
return value.replace(CHAR_REPLACE, 'v');
};
export interface SanitizedString {
value: string;
sanitized: 'ACTUALLY_SANITIZED_DO_NOT_MANUALLY_MAKE_THIS_OBJECT';
}
export const stripIdentifyingInformation = (expr: string): SanitizedString => {
const chunks = getParsedExpression(expr);
for (const chunk of chunks) {
if (chunk.type === 'text') {
chunk.text = replaceValue(chunk.text);
} else {
visit(chunk.parsed, {
visitLiteral(path) {
this.traverse(path);
if (typeof path.node.value === 'string') {
path.node.value = replaceValue(path.node.value);
}
},
visitStringLiteral(path) {
this.traverse(path);
path.node.value = replaceValue(path.node.value);
},
visitTemplateElement(path) {
this.traverse(path);
if (path.node.value.cooked !== null) {
path.node.value.cooked = replaceValue(path.node.value.cooked);
}
path.node.value.raw = replaceValue(path.node.value.raw);
},
});
chunk.text = print(chunk.parsed).code;
}
}
return {
value: joinExpression(chunks),
sanitized: 'ACTUALLY_SANITIZED_DO_NOT_MANUALLY_MAKE_THIS_OBJECT',
};
};

26
node_modules/@n8n/tournament/src/Constants.ts generated vendored Normal file
View File

@ -0,0 +1,26 @@
import type {
CatchClauseKind,
ExpressionKind,
PatternKind,
PropertyKind,
StatementKind,
VariableDeclaratorKind,
} from 'ast-types/lib/gen/kinds';
export const EXEMPT_IDENTIFIER_LIST = [
'isFinite',
'isNaN',
'NaN',
'Date',
'RegExp',
'Math',
'undefined',
];
export type ParentKind =
| ExpressionKind
| StatementKind
| PropertyKind
| PatternKind
| VariableDeclaratorKind
| CatchClauseKind;

94
node_modules/@n8n/tournament/src/Differ.ts generated vendored Normal file
View File

@ -0,0 +1,94 @@
import type { StatementKind } from 'ast-types/lib/gen/kinds';
import { types, parse } from 'recast';
import { parseWithEsprimaNext } from './Parser';
const isWrapped = (node: types.namedTypes.File): boolean => {
return node.program.body[1]?.type === 'TryStatement';
};
const getWrapped = (node: types.namedTypes.File) => {
return (node.program.body[1] as types.namedTypes.TryStatement)?.block.body[0];
};
const isMultiPartExpression = (node: types.namedTypes.File): boolean => {
return (
node.program.body[1]?.type === 'ReturnStatement' &&
node.program.body[1].argument?.type === 'CallExpression' &&
node.program.body[1].argument?.arguments[0]?.type === 'Literal' &&
node.program.body[1].argument?.arguments[0]?.value === '' &&
node.program.body[1].argument?.callee.type === 'MemberExpression' &&
node.program.body[1].argument?.callee.object.type === 'ArrayExpression' &&
node.program.body[1].argument?.callee.property.type === 'Identifier' &&
node.program.body[1].argument?.callee.property.name === 'join'
);
};
const getMultiPartExpression = (node: types.namedTypes.File): StatementKind[] => {
if (
!(
node.program.body[1]?.type === 'ReturnStatement' &&
node.program.body[1].argument?.type === 'CallExpression' &&
node.program.body[1].argument?.arguments[0]?.type === 'Literal' &&
node.program.body[1].argument?.arguments[0]?.value === '' &&
node.program.body[1].argument?.callee.type === 'MemberExpression' &&
node.program.body[1].argument?.callee.object.type === 'ArrayExpression'
)
) {
return [];
}
return node.program.body[1].argument.callee.object.elements
.map((e) => {
if (
e?.type !== 'CallExpression' ||
e.callee.type !== 'MemberExpression' ||
e.callee.object.type !== 'FunctionExpression'
) {
return null;
}
const maybeExpr = e.callee.object.body.body[0];
if (maybeExpr.type !== 'TryStatement') {
return maybeExpr;
}
return maybeExpr.block.body[0];
})
.filter((e) => e !== null) as StatementKind[];
};
export const isDifferent = (tmpl: string, tourn: string): boolean => {
const tmplParsed = parse(tmpl, {
parser: { parse: parseWithEsprimaNext },
}) as types.namedTypes.File;
const tournParsed = parse(tourn, {
parser: { parse: parseWithEsprimaNext },
}) as types.namedTypes.File;
const problemPaths: any[] = [];
let same = types.astNodesAreEquivalent(tmplParsed, tournParsed, problemPaths);
// So we sometimes wrap single value expressions when tmpl doesn't.
// This causes our code to obviously be different to tmpl's. It's
// actually more of a bug on tmpl's side and it's incredibly hard
// to match exactly on our end. I think this is an acceptable difference
// in behaviours and shouldn't cause any issues since an exception will
// be raised either way.
if (!same) {
if (isWrapped(tournParsed) && !isWrapped(tmplParsed)) {
// This is a single part expression that might be wrapped
const tournWrapped = getWrapped(tournParsed);
same = types.astNodesAreEquivalent(tmplParsed.program.body[1], tournWrapped);
} else if (isMultiPartExpression(tournParsed) && isMultiPartExpression(tmplParsed)) {
// This is a multi part expression that may be wrapped internally
const tournExprs = getMultiPartExpression(tournParsed);
const tmplExprs = getMultiPartExpression(tmplParsed);
if (tournExprs.length === tmplExprs.length) {
for (let i = 0; i < tournExprs.length; i++) {
same = types.astNodesAreEquivalent(tmplExprs[i], tournExprs[i], problemPaths);
if (!same) {
break;
}
}
}
}
}
return !same;
};

9
node_modules/@n8n/tournament/src/Evaluator.ts generated vendored Normal file
View File

@ -0,0 +1,9 @@
import type { ReturnValue, Tournament } from '.';
export interface ExpressionEvaluator {
evaluate(code: string, data: unknown): ReturnValue;
}
export interface ExpressionEvaluatorClass {
new (instance: Tournament): ExpressionEvaluator;
}

297
node_modules/@n8n/tournament/src/ExpressionBuilder.ts generated vendored Normal file
View File

@ -0,0 +1,297 @@
import type { namedTypes } from 'ast-types';
import type { types } from 'recast';
import { parse, visit, print } from 'recast';
import { builders as b } from 'ast-types';
import type { ExpressionKind, StatementKind } from 'ast-types/lib/gen/kinds';
import { globalIdentifier, jsVariablePolyfill } from './VariablePolyfill';
import type { DataNode } from './VariablePolyfill';
import { splitExpression } from './ExpressionSplitter';
import type { ExpressionCode, ExpressionText } from './ExpressionSplitter';
import { parseWithEsprimaNext } from './Parser';
import type { TournamentHooks } from './ast';
export interface ExpressionAnalysis {
has: {
function: boolean;
templateString: boolean;
};
}
const v = b.identifier('v');
const shouldAlwaysWrapList = ['window', 'global', 'this'];
const shouldWrapInTry = (node: namedTypes.ASTNode) => {
let shouldWrap = false;
visit(node, {
visitMemberExpression() {
shouldWrap = true;
return false;
},
visitCallExpression() {
shouldWrap = true;
return false;
},
visitIdentifier(path) {
if (shouldAlwaysWrapList.includes(path.node.name)) {
shouldWrap = true;
return false;
}
this.traverse(path);
return;
},
});
return shouldWrap;
};
const hasFunction = (node: types.namedTypes.ASTNode) => {
let hasFn = false;
visit(node, {
visitFunctionExpression() {
hasFn = true;
return false;
},
visitFunctionDeclaration() {
hasFn = true;
return false;
},
visitArrowFunctionExpression() {
hasFn = true;
return false;
},
});
return hasFn;
};
const hasTemplateString = (node: types.namedTypes.ASTNode) => {
let hasTemp = false;
visit(node, {
visitTemplateLiteral(path) {
if (path.node.expressions.length) {
hasTemp = true;
return false;
}
this.traverse(path);
return;
},
});
return hasTemp;
};
const wrapInErrorHandler = (node: StatementKind) => {
return b.tryStatement(
b.blockStatement([node]),
b.catchClause(
b.identifier('e'),
null,
b.blockStatement([
b.expressionStatement(
b.callExpression(b.identifier('E'), [b.identifier('e'), b.thisExpression()]),
),
]),
),
);
};
const maybeWrapExpr = (expr: string): string => {
if (expr.trimStart()[0] === '{') {
return '(' + expr + ')';
}
return expr;
};
const buildFunctionBody = (expr: ExpressionKind) => {
return b.blockStatement([
// v = (<actual expression>)
b.expressionStatement(b.assignmentExpression('=', v, expr)),
// Return value or empty string on some falsy values
// return v || v === 0 || v === false ? v : 0
// The ordering is important for AST nodes to match
// tmpl's output
b.returnStatement(
b.conditionalExpression(
b.logicalExpression(
'||',
b.logicalExpression('||', v, b.binaryExpression('===', v, b.literal(0))),
b.binaryExpression('===', v, b.literal(false)),
),
v,
b.literal(''),
),
),
]);
};
type ParsedCode = ExpressionCode & { parsed: types.namedTypes.File };
// This replaces any actual new lines with \n's. This only happens in
// template strings.
const fixStringNewLines = (node: types.namedTypes.File): types.namedTypes.File => {
const replace = (str: string): string => {
return str.replace(/\n/g, '\\n');
};
visit(node, {
visitTemplateElement(path) {
this.traverse(path);
const el = b.templateElement(
{
cooked: path.node.value.cooked === null ? null : replace(path.node.value.cooked),
raw: replace(path.node.value.raw),
},
path.node.tail,
);
path.replace(el);
},
});
return node;
};
export const getParsedExpression = (expr: string): Array<ExpressionText | ParsedCode> => {
return splitExpression(expr).map<ExpressionText | ParsedCode>((chunk) => {
if (chunk.type === 'code') {
const code = maybeWrapExpr(chunk.text);
const node = parse(code, {
parser: { parse: parseWithEsprimaNext },
}) as types.namedTypes.File;
return { ...chunk, parsed: node };
}
return chunk;
});
};
export const getExpressionCode = (
expr: string,
dataNodeName: string,
hooks: TournamentHooks,
): [string, ExpressionAnalysis] => {
const chunks = getParsedExpression(expr);
const newProg = b.program([
b.variableDeclaration('var', [b.variableDeclarator(globalIdentifier, b.objectExpression([]))]),
]);
// This is what's used to access that's passed in. For compatibility we us
// `this` unless the expression contains a function. If it contains an
// expression we instead assign a different variable to hold onto the contents
// of `this` (default: `___n8n_data`) since functions aren't compatibility
// anyway.
let dataNode: DataNode = b.thisExpression();
const hasFn = (chunks.filter((c) => c.type === 'code') as ParsedCode[]).some((c) =>
hasFunction(c.parsed),
);
if (hasFn) {
dataNode = b.identifier(dataNodeName);
newProg.body.push(
b.variableDeclaration('var', [b.variableDeclarator(dataNode, b.thisExpression())]),
);
}
const hasTempString = (chunks.filter((c) => c.type === 'code') as ParsedCode[]).some((c) =>
hasTemplateString(c.parsed),
);
// So for compatibility we parse expressions the same way that `tmpl` does.
// This means we always have an initial text chunk but if there's only a blank
// text chunk and a code chunk then we want to return the actual value of the
// expression, not turn it into a string.
if (
chunks.length > 2 ||
chunks[0].text !== '' ||
// This is a blank expression. It should just return an empty string
(chunks[0].text === '' && chunks.length === 1)
) {
let parts: ExpressionKind[] = [];
for (const chunk of chunks) {
// This is just a text chunks, push it up as a literal.
if (chunk.type === 'text') {
parts.push(b.literal(chunk.text));
// This is a code chunk so do some magic
} else {
const fixed = fixStringNewLines(chunk.parsed);
for (const hook of hooks.before) {
hook(fixed, dataNode);
}
const parsed = jsVariablePolyfill(fixed, dataNode)?.[0];
if (!parsed || parsed.type !== 'ExpressionStatement') {
throw new SyntaxError('Not a expression statement');
}
for (const hook of hooks.after) {
hook(parsed, dataNode);
}
const functionBody = buildFunctionBody(parsed.expression);
if (shouldWrapInTry(parsed)) {
// Wraps the body of our expression function in a try/catch
// to match tmpl
functionBody.body = [
wrapInErrorHandler(functionBody.body[0]),
// This is for tmpl compat. It puts a ; after the try/catch
// creating an empty statement. emptyStatement is just printed
// to nothing so we use an expression statement with a blank
// identifier.
b.expressionStatement(b.identifier('')),
functionBody.body[1],
];
}
// Turn our expression into a function call with bound this. The function
// it create has a parameter called `v` that we don't actually set. I think
// this is a hack around only being able to use `var` and not `let`/`const`.
parts.push(
b.callExpression(
b.memberExpression(b.functionExpression(null, [v], functionBody), b.identifier('call')),
[b.thisExpression()],
),
);
}
}
// Just return the raw string if it's just a single string
if (chunks.length < 2) {
newProg.body.push(b.returnStatement(parts[0]));
} else {
// Filter out empty string literals for compat
parts = parts.filter((i) => !(i.type === 'Literal' && i.value === ''));
newProg.body.push(
b.returnStatement(
b.callExpression(b.memberExpression(b.arrayExpression(parts), b.identifier('join')), [
b.literal(''),
]),
),
);
}
} else {
const fixed = fixStringNewLines((chunks[1] as ParsedCode).parsed);
for (const hook of hooks.before) {
hook(fixed, dataNode);
}
const parsed = jsVariablePolyfill(fixed, dataNode)?.[0];
if (!parsed || parsed.type !== 'ExpressionStatement') {
throw new SyntaxError('Not a expression statement');
}
for (const hook of hooks.after) {
hook(parsed, dataNode);
}
let retData: StatementKind = b.returnStatement(parsed.expression);
if (shouldWrapInTry(parsed)) {
retData = wrapInErrorHandler(retData);
}
newProg.body.push(retData);
}
return [print(newProg).code, { has: { function: hasFn, templateString: hasTempString } }];
};

108
node_modules/@n8n/tournament/src/ExpressionSplitter.ts generated vendored Normal file
View File

@ -0,0 +1,108 @@
export interface ExpressionText {
type: 'text';
text: string;
}
export interface ExpressionCode {
type: 'code';
text: string;
// tmpl has different behaviours if the last expression
// doesn't close itself.
hasClosingBrackets: boolean;
}
export type ExpressionChunk = ExpressionCode | ExpressionText;
const OPEN_BRACKET = /(?<brackets>\{\{)/;
const CLOSE_BRACKET = /(?<brackets>\}\})/;
export const escapeCode = (text: string): string => {
return text.replace('\\}}', '}}');
};
const normalizeBackslashes = (text: string): string => {
return text.replace(/\\\\/g, '\\');
};
export const splitExpression = (expression: string): ExpressionChunk[] => {
const chunks: ExpressionChunk[] = [];
let searchingFor: 'open' | 'close' = 'open';
let activeRegex = OPEN_BRACKET;
let buffer = '';
let index = 0;
while (index < expression.length) {
const expr = expression.slice(index);
const res = activeRegex.exec(expr);
// No more brackets. If it's a closing bracket
// this is sort of valid so we accept it but mark
// that it has no closing bracket.
if (!res?.groups) {
buffer += expr;
if (searchingFor === 'open') {
chunks.push({
type: 'text',
text: buffer,
});
} else {
chunks.push({
type: 'code',
text: escapeCode(buffer),
hasClosingBrackets: false,
});
}
break;
}
const beforeMatch = expr.slice(0, res.index);
const backslashCount = beforeMatch.match(/\\*$/)?.[0]?.length ?? 0;
const isEscaped = backslashCount % 2 === 1;
if (isEscaped) {
buffer += expr.slice(0, res.index + '{{'.length);
index += res.index + '{{'.length;
} else {
buffer += expr.slice(0, res.index);
if (searchingFor === 'open') {
chunks.push({
type: 'text',
text: normalizeBackslashes(buffer),
});
searchingFor = 'close';
activeRegex = CLOSE_BRACKET;
} else {
chunks.push({
type: 'code',
text: escapeCode(buffer),
hasClosingBrackets: true,
});
searchingFor = 'open';
activeRegex = OPEN_BRACKET;
}
index += res.index + 2;
buffer = '';
}
}
return chunks;
};
// Expressions only have closing brackets escaped
const escapeTmplExpression = (part: string) => {
return part.replace('}}', '\\}}');
};
export const joinExpression = (parts: ExpressionChunk[]): string => {
return parts
.map((chunk) => {
if (chunk.type === 'code') {
return `{{${escapeTmplExpression(chunk.text)}${chunk.hasClosingBrackets ? '}}' : ''}`;
}
return chunk.text;
})
.join('');
};

22
node_modules/@n8n/tournament/src/FunctionEvaluator.ts generated vendored Normal file
View File

@ -0,0 +1,22 @@
import type { ExpressionEvaluator, ReturnValue, Tournament } from '.';
export class FunctionEvaluator implements ExpressionEvaluator {
private _codeCache: Record<string, Function> = {};
constructor(private instance: Tournament) {}
private getFunction(expr: string): Function {
if (expr in this._codeCache) {
return this._codeCache[expr];
}
const [code] = this.instance.getExpressionCode(expr);
const func = new Function('E', code + ';');
this._codeCache[expr] = func;
return func;
}
evaluate(expr: string, data: unknown): ReturnValue {
const fn = this.getFunction(expr);
return fn.call(data, this.instance.errorHandler);
}
}

23
node_modules/@n8n/tournament/src/Parser.ts generated vendored Normal file
View File

@ -0,0 +1,23 @@
import { parse as esprimaParse } from 'esprima-next';
import type { Config as EsprimaConfig } from 'esprima-next';
import { getOption } from 'recast/lib/util';
export function parseWithEsprimaNext(source: string, options?: any): any {
try {
const ast = esprimaParse(source, {
loc: true,
locations: true,
comment: true,
range: getOption(options, 'range', false) as boolean,
tolerant: getOption(options, 'tolerant', true) as boolean,
tokens: true,
jsx: getOption(options, 'jsx', false) as boolean,
sourceType: getOption(options, 'sourceType', 'module') as string,
} as EsprimaConfig);
return ast;
} catch (error) {
if (error instanceof Error) throw new SyntaxError(error.message);
throw error;
}
}

313
node_modules/@n8n/tournament/src/VariablePolyfill.ts generated vendored Normal file
View File

@ -0,0 +1,313 @@
import type { types } from 'recast';
import { visit } from 'recast';
import type { StatementKind, VariableDeclaratorKind } from 'ast-types/lib/gen/kinds';
import type { NodePath } from 'ast-types/lib/node-path';
import type { namedTypes } from 'ast-types';
import { builders as b } from 'ast-types';
import type { ParentKind } from './Constants';
import { EXEMPT_IDENTIFIER_LIST } from './Constants';
function assertNever(value: never): value is never {
return true;
}
export const globalIdentifier = b.identifier(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
typeof window !== 'object' ? 'global' : 'window',
);
const buildGlobalSwitch = (node: types.namedTypes.Identifier, dataNode: DataNode) => {
return b.memberExpression(
b.conditionalExpression(
b.binaryExpression('in', b.literal(node.name), dataNode),
dataNode,
globalIdentifier,
),
b.identifier(node.name),
);
};
const isInScope = (path: NodePath<types.namedTypes.Identifier>) => {
let scope = path.scope;
while (scope !== null) {
if (scope.declares(path.node.name)) {
return true;
}
scope = scope.parent;
}
return false;
};
const polyfillExceptions = ['this', 'window', 'global'];
const polyfillVar = (
path: NodePath<types.namedTypes.Identifier>,
dataNode: DataNode,
force: boolean = false,
) => {
if (!force) {
if (isInScope(path)) {
// console.log('In scope', path.node.name);
return;
}
}
// For tmpl compat we ignore these identifiers
if (polyfillExceptions.includes(path.node.name)) {
return;
}
path.replace(buildGlobalSwitch(path.node, dataNode));
};
export type DataNode = namedTypes.ThisExpression | namedTypes.Identifier;
type CustomPatcher = (
path: NodePath<types.namedTypes.Identifier>,
parent: any,
dataNode: DataNode,
) => void;
const customPatches: Partial<Record<ParentKind['type'], CustomPatcher>> = {
MemberExpression(path, parent: namedTypes.MemberExpression, dataNode) {
if (parent.object === path.node || parent.computed) {
polyfillVar(path, dataNode);
}
},
OptionalMemberExpression(path, parent: namedTypes.OptionalMemberExpression, dataNode) {
if (parent.object === path.node) {
polyfillVar(path, dataNode);
}
},
Property(path, parent: namedTypes.Property, dataNode) {
if (path.node !== parent.value) {
return;
}
const objPattern: namedTypes.ObjectPattern = path.parent?.parent?.node;
if (!objPattern) {
return;
}
const objParent: VariableDeclaratorKind = path.parent.parent.parent?.node;
if (!objParent) {
return;
}
if (objParent.type === 'VariableDeclarator' && objParent.id === objPattern) {
return;
}
parent.shorthand = false;
polyfillVar(path, dataNode);
},
AssignmentPattern(path, parent: namedTypes.AssignmentPattern, dataNode) {
if (parent.right === path.node) {
polyfillVar(path, dataNode);
}
},
VariableDeclarator(path, parent: namedTypes.VariableDeclarator, dataNode) {
if (parent.init === path.node) {
polyfillVar(path, dataNode);
}
},
};
export const jsVariablePolyfill = (
ast: types.namedTypes.File,
dataNode: DataNode,
): StatementKind[] | undefined => {
visit(ast, {
visitImportExpression(_path) {
throw new Error('Imports are not supported');
},
visitIdentifier(path) {
this.traverse(path);
const parent: ParentKind = path.parent.node;
// This is for tmpl compat
if (EXEMPT_IDENTIFIER_LIST.includes(path.node.name)) {
return;
}
switch (parent.type) {
case 'AssignmentPattern':
case 'Property':
case 'MemberExpression':
case 'OptionalMemberExpression':
case 'VariableDeclarator':
if (!customPatches[parent.type]) {
throw new Error(`Couldn\'t find custom patcher for parent type: ${parent.type}`);
}
customPatches[parent.type]!(path, parent, dataNode);
break;
case 'BinaryExpression':
case 'UnaryExpression':
case 'ArrayExpression':
case 'AssignmentExpression':
case 'SequenceExpression':
case 'YieldExpression':
case 'UpdateExpression':
case 'LogicalExpression':
case 'ConditionalExpression':
case 'NewExpression':
case 'CallExpression':
case 'OptionalCallExpression':
case 'TaggedTemplateExpression':
case 'TemplateLiteral':
case 'AwaitExpression':
case 'ImportExpression':
case 'ForStatement':
case 'IfStatement':
case 'WhileStatement':
case 'ForInStatement':
case 'ForOfStatement':
case 'SwitchStatement':
case 'ReturnStatement':
case 'DoWhileStatement':
case 'ExpressionStatement':
case 'ForAwaitStatement':
case 'ThrowStatement':
case 'WithStatement':
case 'TupleExpression':
polyfillVar(path, dataNode);
break;
// Do nothing
case 'Super':
case 'Identifier':
case 'ArrowFunctionExpression':
case 'FunctionDeclaration':
case 'FunctionExpression':
case 'ThisExpression':
case 'ObjectExpression':
case 'MetaProperty':
case 'ChainExpression':
case 'PrivateName':
case 'ParenthesizedExpression':
case 'Import':
case 'VariableDeclaration':
case 'CatchClause':
case 'BlockStatement':
case 'TryStatement':
case 'EmptyStatement':
case 'LabeledStatement':
case 'BreakStatement':
case 'ContinueStatement':
case 'DebuggerStatement':
case 'ImportDeclaration':
case 'ExportDeclaration':
case 'ExportAllDeclaration':
case 'ExportDefaultDeclaration':
case 'Noop':
case 'ClassMethod':
case 'ClassPrivateMethod':
case 'RestElement':
case 'ArrayPattern':
case 'ObjectPattern':
case 'ClassExpression':
case 'RecordExpression':
case 'V8IntrinsicIdentifier':
case 'TopicReference':
case 'MethodDefinition':
case 'ClassDeclaration':
case 'ClassProperty':
case 'StaticBlock':
case 'ClassBody':
case 'ExportNamedDeclaration':
case 'ClassPrivateProperty':
case 'ClassAccessorProperty':
case 'PropertyPattern':
break;
// I can't seem to figure out what causes these
case 'SpreadElementPattern':
case 'SpreadPropertyPattern':
case 'ClassPropertyDefinition':
break;
// Flow types
case 'DeclareClass':
case 'DeclareModule':
case 'DeclareVariable':
case 'DeclareFunction':
case 'DeclareInterface':
case 'DeclareTypeAlias':
case 'DeclareOpaqueType':
case 'DeclareModuleExports':
case 'DeclareExportDeclaration':
case 'DeclareExportAllDeclaration':
case 'InterfaceDeclaration':
case 'TypeAlias':
case 'OpaqueType':
case 'EnumDeclaration':
case 'TypeCastExpression':
break;
// Typescript types
case 'TSAsExpression':
case 'TSTypeParameter':
case 'TSTypeAssertion':
case 'TSDeclareMethod':
case 'TSIndexSignature':
case 'TSDeclareFunction':
case 'TSMethodSignature':
case 'TSEnumDeclaration':
case 'TSExportAssignment':
case 'TSNonNullExpression':
case 'TSPropertySignature':
case 'TSModuleDeclaration':
case 'TSParameterProperty':
case 'TSTypeCastExpression':
case 'TSSatisfiesExpression':
case 'TSTypeAliasDeclaration':
case 'TSInterfaceDeclaration':
case 'TSImportEqualsDeclaration':
case 'TSExternalModuleReference':
case 'TSInstantiationExpression':
case 'TSTypeParameterDeclaration':
case 'TSCallSignatureDeclaration':
case 'TSNamespaceExportDeclaration':
case 'TSConstructSignatureDeclaration':
break;
// Literals that can't contain an identifier
case 'DirectiveLiteral':
case 'StringLiteral':
case 'NumericLiteral':
case 'BigIntLiteral':
case 'NullLiteral':
case 'Literal':
case 'RegExpLiteral':
case 'BooleanLiteral':
case 'DecimalLiteral':
break;
// Proposals that are stage 0 or 1
case 'DoExpression':
case 'BindExpression':
break;
// JSX stuff. We don't support this so just do nothing.
case 'JSXIdentifier':
case 'JSXText':
case 'JSXElement':
case 'JSXFragment':
case 'JSXMemberExpression':
case 'JSXExpressionContainer':
break;
// I _think_ these are obsolete features proposed as part of ECMAScript 7.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features#legacy_generator_and_iterator
case 'ComprehensionExpression':
case 'GeneratorExpression':
polyfillVar(path, dataNode);
break;
default:
// This is a simple type guard that guarantees we haven't missed
// a case. It'll result in a type error at compile time.
assertNever(parent);
break;
}
},
});
return ast.program.body as StatementKind[];
};

21
node_modules/@n8n/tournament/src/ast.ts generated vendored Normal file
View File

@ -0,0 +1,21 @@
export type { types as astTypes } from 'recast';
export { visit as astVisit } from 'recast';
export { builders as astBuilders, type namedTypes as astNamedTypes } from 'ast-types';
import type { types } from 'recast';
import type { namedTypes } from 'ast-types';
export interface TournamentHooks {
before: ASTBeforeHook[];
after: ASTAfterHook[];
}
export type ASTAfterHook = (
ast: namedTypes.ExpressionStatement,
dataNode: namedTypes.ThisExpression | namedTypes.Identifier,
) => void;
export type ASTBeforeHook = (
ast: types.namedTypes.File,
dataNode: namedTypes.ThisExpression | namedTypes.Identifier,
) => void;

47
node_modules/@n8n/tournament/src/index.ts generated vendored Normal file
View File

@ -0,0 +1,47 @@
import { getExpressionCode } from './ExpressionBuilder';
import type { ExpressionAnalysis } from './ExpressionBuilder';
import { getTmplDifference } from './Analysis';
import type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator';
import { FunctionEvaluator } from './FunctionEvaluator';
import type { TournamentHooks } from './ast';
export type { TmplDifference } from './Analysis';
export type { ExpressionEvaluator, ExpressionEvaluatorClass } from './Evaluator';
export * from './ast';
const DATA_NODE_NAME = '___n8n_data';
export type ReturnValue = string | null | (() => unknown);
export class Tournament {
private evaluator!: ExpressionEvaluator;
constructor(
public errorHandler: (error: Error) => void = () => {},
private _dataNodeName: string = DATA_NODE_NAME,
Evaluator: ExpressionEvaluatorClass = FunctionEvaluator,
private readonly astHooks: TournamentHooks = { before: [], after: [] },
) {
this.setEvaluator(Evaluator);
}
setEvaluator(Evaluator: ExpressionEvaluatorClass) {
this.evaluator = new Evaluator(this);
}
getExpressionCode(expr: string): [string, ExpressionAnalysis] {
return getExpressionCode(expr, this._dataNodeName, this.astHooks);
}
tmplDiff(expr: string) {
return getTmplDifference(expr, this._dataNodeName);
}
execute(expr: string, data: unknown): ReturnValue {
// This is to match tmpl. This will only really happen if
// an empty expression is passed in.
if (!expr) {
return expr;
}
return this.evaluator.evaluate(expr, data);
}
}

25
node_modules/@n8n/tournament/tsconfig.json generated vendored Normal file
View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"strict": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es2019",
"lib": ["es2019", "es2020", "es2022.error"],
"removeComments": true,
"useUnknownInCatchVariables": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"preserveConstEnums": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"incremental": true,
"declaration": true,
"sourceMap": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts", "test/**/*.ts"],
"exclude": ["**/dist/**/*", "**/node_modules/**/*"]
}