@abyss-project/console 1.0.40 → 1.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -2
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/constants/index.js +1 -0
- package/dist/types/constants/workflow.constants.d.ts +9 -0
- package/dist/types/constants/workflow.constants.js +12 -0
- package/dist/types/interface/models/workflow-trigger.model.d.ts +1 -4
- package/dist/types/interface/models/workflow-webhook.model.d.ts +1 -0
- package/dist/utils/webhook-trigger.utils.d.ts +1 -6
- package/dist/utils/webhook-trigger.utils.js +33 -318
- package/dist/workflow-expressions/index.d.ts +5 -17
- package/dist/workflow-expressions/index.js +9 -58
- package/dist/workflow-expressions/resolver.d.ts +2 -6
- package/dist/workflow-expressions/resolver.js +31 -220
- package/dist/workflow-expressions/types.d.ts +21 -118
- package/dist/workflow-expressions/types.js +2 -20
- package/package.json +1 -1
- package/dist/expressions/functions/array.d.ts +0 -2
- package/dist/expressions/functions/array.js +0 -252
- package/dist/expressions/functions/crypto.d.ts +0 -2
- package/dist/expressions/functions/crypto.js +0 -101
- package/dist/expressions/functions/datetime.d.ts +0 -2
- package/dist/expressions/functions/datetime.js +0 -256
- package/dist/expressions/functions/index.d.ts +0 -7
- package/dist/expressions/functions/index.js +0 -46
- package/dist/expressions/functions/math.d.ts +0 -2
- package/dist/expressions/functions/math.js +0 -174
- package/dist/expressions/functions/string.d.ts +0 -2
- package/dist/expressions/functions/string.js +0 -301
- package/dist/expressions/functions/utility.d.ts +0 -2
- package/dist/expressions/functions/utility.js +0 -230
- package/dist/expressions/helpers.d.ts +0 -26
- package/dist/expressions/helpers.js +0 -132
- package/dist/expressions/index.d.ts +0 -5
- package/dist/expressions/index.js +0 -16
- package/dist/expressions/mapper.d.ts +0 -9
- package/dist/expressions/mapper.js +0 -88
- package/dist/expressions/parser.d.ts +0 -3
- package/dist/expressions/parser.js +0 -97
- package/dist/expressions/pipes/array-pipes.d.ts +0 -2
- package/dist/expressions/pipes/array-pipes.js +0 -248
- package/dist/expressions/pipes/index.d.ts +0 -8
- package/dist/expressions/pipes/index.js +0 -40
- package/dist/expressions/pipes/object-pipes.d.ts +0 -2
- package/dist/expressions/pipes/object-pipes.js +0 -243
- package/dist/expressions/pipes/string-pipes.d.ts +0 -9
- package/dist/expressions/pipes/string-pipes.js +0 -178
- package/dist/expressions/resolver.d.ts +0 -12
- package/dist/expressions/resolver.js +0 -88
- package/dist/expressions/types.d.ts +0 -36
- package/dist/expressions/types.js +0 -2
- package/dist/workflow-expressions/functions/array.d.ts +0 -2
- package/dist/workflow-expressions/functions/array.js +0 -252
- package/dist/workflow-expressions/functions/crypto.d.ts +0 -2
- package/dist/workflow-expressions/functions/crypto.js +0 -101
- package/dist/workflow-expressions/functions/datetime.d.ts +0 -2
- package/dist/workflow-expressions/functions/datetime.js +0 -256
- package/dist/workflow-expressions/functions/index.d.ts +0 -7
- package/dist/workflow-expressions/functions/index.js +0 -46
- package/dist/workflow-expressions/functions/math.d.ts +0 -2
- package/dist/workflow-expressions/functions/math.js +0 -174
- package/dist/workflow-expressions/functions/string.d.ts +0 -2
- package/dist/workflow-expressions/functions/string.js +0 -301
- package/dist/workflow-expressions/functions/utility.d.ts +0 -2
- package/dist/workflow-expressions/functions/utility.js +0 -230
- package/dist/workflow-expressions/helpers.d.ts +0 -71
- package/dist/workflow-expressions/helpers.js +0 -262
- package/dist/workflow-expressions/parser.d.ts +0 -8
- package/dist/workflow-expressions/parser.js +0 -456
- package/dist/workflow-expressions/pipes/array-pipes.d.ts +0 -2
- package/dist/workflow-expressions/pipes/array-pipes.js +0 -248
- package/dist/workflow-expressions/pipes/index.d.ts +0 -8
- package/dist/workflow-expressions/pipes/index.js +0 -40
- package/dist/workflow-expressions/pipes/object-pipes.d.ts +0 -2
- package/dist/workflow-expressions/pipes/object-pipes.js +0 -243
- package/dist/workflow-expressions/pipes/string-pipes.d.ts +0 -9
- package/dist/workflow-expressions/pipes/string-pipes.js +0 -178
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.utilityFunctions = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
exports.utilityFunctions = {
|
|
6
|
-
uuid: {
|
|
7
|
-
name: 'uuid',
|
|
8
|
-
description: 'Generates a random UUID v4',
|
|
9
|
-
category: 'utility',
|
|
10
|
-
signature: 'uuid()',
|
|
11
|
-
args: [],
|
|
12
|
-
returnType: 'string',
|
|
13
|
-
examples: ['{{fn.uuid()}}', '{{uuid()}}'],
|
|
14
|
-
execute: () => (0, uuid_1.v4)(),
|
|
15
|
-
},
|
|
16
|
-
coalesce: {
|
|
17
|
-
name: 'coalesce',
|
|
18
|
-
description: 'Returns the first non-null/undefined value',
|
|
19
|
-
category: 'utility',
|
|
20
|
-
signature: 'coalesce(value1, value2, ...)',
|
|
21
|
-
args: [
|
|
22
|
-
{
|
|
23
|
-
name: 'values',
|
|
24
|
-
type: 'any',
|
|
25
|
-
required: true,
|
|
26
|
-
description: 'Values to check',
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
returnType: 'any',
|
|
30
|
-
examples: ['{{fn.coalesce(trigger.name, "Anonymous")}}'],
|
|
31
|
-
execute: (...args) => {
|
|
32
|
-
for (const arg of args) {
|
|
33
|
-
if (arg !== null && arg !== undefined) {
|
|
34
|
-
return arg;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
typeOf: {
|
|
41
|
-
name: 'typeOf',
|
|
42
|
-
description: 'Returns the type of a value',
|
|
43
|
-
category: 'utility',
|
|
44
|
-
signature: 'typeOf(value)',
|
|
45
|
-
args: [
|
|
46
|
-
{
|
|
47
|
-
name: 'value',
|
|
48
|
-
type: 'any',
|
|
49
|
-
required: true,
|
|
50
|
-
description: 'Value to check',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
returnType: 'string',
|
|
54
|
-
examples: ['{{fn.typeOf(trigger.data)}}'],
|
|
55
|
-
execute: (value) => {
|
|
56
|
-
if (value === null)
|
|
57
|
-
return 'null';
|
|
58
|
-
if (Array.isArray(value))
|
|
59
|
-
return 'array';
|
|
60
|
-
return typeof value;
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
isNull: {
|
|
64
|
-
name: 'isNull',
|
|
65
|
-
description: 'Checks if a value is null or undefined',
|
|
66
|
-
category: 'utility',
|
|
67
|
-
signature: 'isNull(value)',
|
|
68
|
-
args: [
|
|
69
|
-
{
|
|
70
|
-
name: 'value',
|
|
71
|
-
type: 'any',
|
|
72
|
-
required: true,
|
|
73
|
-
description: 'Value to check',
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
returnType: 'boolean',
|
|
77
|
-
examples: ['{{fn.isNull(trigger.optional)}}'],
|
|
78
|
-
execute: (value) => value === null || value === undefined,
|
|
79
|
-
},
|
|
80
|
-
isEmpty: {
|
|
81
|
-
name: 'isEmpty',
|
|
82
|
-
description: 'Checks if a value is empty (null, undefined, empty string, empty array, or empty object)',
|
|
83
|
-
category: 'utility',
|
|
84
|
-
signature: 'isEmpty(value)',
|
|
85
|
-
args: [
|
|
86
|
-
{
|
|
87
|
-
name: 'value',
|
|
88
|
-
type: 'any',
|
|
89
|
-
required: true,
|
|
90
|
-
description: 'Value to check',
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
returnType: 'boolean',
|
|
94
|
-
examples: ['{{fn.isEmpty(trigger.description)}}'],
|
|
95
|
-
execute: (value) => {
|
|
96
|
-
if (value === null || value === undefined)
|
|
97
|
-
return true;
|
|
98
|
-
if (typeof value === 'string')
|
|
99
|
-
return value.length === 0;
|
|
100
|
-
if (Array.isArray(value))
|
|
101
|
-
return value.length === 0;
|
|
102
|
-
if (typeof value === 'object')
|
|
103
|
-
return Object.keys(value).length === 0;
|
|
104
|
-
return false;
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
default: {
|
|
108
|
-
name: 'default',
|
|
109
|
-
description: 'Returns a default value if the input is null, undefined, or empty',
|
|
110
|
-
category: 'utility',
|
|
111
|
-
signature: 'default(value, defaultValue)',
|
|
112
|
-
args: [
|
|
113
|
-
{
|
|
114
|
-
name: 'value',
|
|
115
|
-
type: 'any',
|
|
116
|
-
required: true,
|
|
117
|
-
description: 'Input value',
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
name: 'defaultValue',
|
|
121
|
-
type: 'any',
|
|
122
|
-
required: true,
|
|
123
|
-
description: 'Default value',
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
returnType: 'any',
|
|
127
|
-
examples: ['{{fn.default(trigger.name, "Unknown")}}'],
|
|
128
|
-
execute: (value, defaultValue) => {
|
|
129
|
-
if (value === null || value === undefined)
|
|
130
|
-
return defaultValue;
|
|
131
|
-
if (typeof value === 'string' && value.length === 0)
|
|
132
|
-
return defaultValue;
|
|
133
|
-
if (Array.isArray(value) && value.length === 0)
|
|
134
|
-
return defaultValue;
|
|
135
|
-
return value;
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
toNumber: {
|
|
139
|
-
name: 'toNumber',
|
|
140
|
-
description: 'Converts a value to a number',
|
|
141
|
-
category: 'utility',
|
|
142
|
-
signature: 'toNumber(value)',
|
|
143
|
-
args: [
|
|
144
|
-
{
|
|
145
|
-
name: 'value',
|
|
146
|
-
type: 'any',
|
|
147
|
-
required: true,
|
|
148
|
-
description: 'Value to convert',
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
returnType: 'number',
|
|
152
|
-
examples: ['{{fn.toNumber(trigger.stringNum)}}'],
|
|
153
|
-
execute: (value) => Number(value),
|
|
154
|
-
},
|
|
155
|
-
toString: {
|
|
156
|
-
name: 'toString',
|
|
157
|
-
description: 'Converts a value to a string',
|
|
158
|
-
category: 'utility',
|
|
159
|
-
signature: 'toString(value)',
|
|
160
|
-
args: [
|
|
161
|
-
{
|
|
162
|
-
name: 'value',
|
|
163
|
-
type: 'any',
|
|
164
|
-
required: true,
|
|
165
|
-
description: 'Value to convert',
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
returnType: 'string',
|
|
169
|
-
examples: ['{{fn.toString(trigger.number)}}'],
|
|
170
|
-
execute: (value) => String(value),
|
|
171
|
-
},
|
|
172
|
-
toBoolean: {
|
|
173
|
-
name: 'toBoolean',
|
|
174
|
-
description: 'Converts a value to a boolean',
|
|
175
|
-
category: 'utility',
|
|
176
|
-
signature: 'toBoolean(value)',
|
|
177
|
-
args: [
|
|
178
|
-
{
|
|
179
|
-
name: 'value',
|
|
180
|
-
type: 'any',
|
|
181
|
-
required: true,
|
|
182
|
-
description: 'Value to convert',
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
|
-
returnType: 'boolean',
|
|
186
|
-
examples: ['{{fn.toBoolean(trigger.flag)}}'],
|
|
187
|
-
execute: (value) => Boolean(value),
|
|
188
|
-
},
|
|
189
|
-
parseJSON: {
|
|
190
|
-
name: 'parseJSON',
|
|
191
|
-
description: 'Parses a JSON string',
|
|
192
|
-
category: 'utility',
|
|
193
|
-
signature: 'parseJSON(str)',
|
|
194
|
-
args: [
|
|
195
|
-
{
|
|
196
|
-
name: 'str',
|
|
197
|
-
type: 'string',
|
|
198
|
-
required: true,
|
|
199
|
-
description: 'JSON string',
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
returnType: 'any',
|
|
203
|
-
examples: ['{{fn.parseJSON(trigger.jsonData)}}'],
|
|
204
|
-
execute: (str) => {
|
|
205
|
-
try {
|
|
206
|
-
return JSON.parse(String(str));
|
|
207
|
-
}
|
|
208
|
-
catch {
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
toJSON: {
|
|
214
|
-
name: 'toJSON',
|
|
215
|
-
description: 'Converts a value to a JSON string',
|
|
216
|
-
category: 'utility',
|
|
217
|
-
signature: 'toJSON(value)',
|
|
218
|
-
args: [
|
|
219
|
-
{
|
|
220
|
-
name: 'value',
|
|
221
|
-
type: 'any',
|
|
222
|
-
required: true,
|
|
223
|
-
description: 'Value to convert',
|
|
224
|
-
},
|
|
225
|
-
],
|
|
226
|
-
returnType: 'string',
|
|
227
|
-
examples: ['{{fn.toJSON(trigger.data)}}'],
|
|
228
|
-
execute: (value) => JSON.stringify(value),
|
|
229
|
-
},
|
|
230
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare function buildExpressionString(path: string, operations?: Array<{
|
|
2
|
-
name: string;
|
|
3
|
-
args: unknown[];
|
|
4
|
-
}>): string;
|
|
5
|
-
export declare function buildReferenceString(type: string, id: string): string;
|
|
6
|
-
export declare function hasExpressions(str: string): boolean;
|
|
7
|
-
export declare function hasReferences(str: string): boolean;
|
|
8
|
-
export declare function isInsideExpression(text: string, cursorPos: number): boolean;
|
|
9
|
-
export declare function extractPaths(str: string): string[];
|
|
10
|
-
export declare function parseOperations(opsStr: string): Array<{
|
|
11
|
-
name: string;
|
|
12
|
-
args: unknown[];
|
|
13
|
-
}>;
|
|
14
|
-
export declare function getCurrentExpressionContext(text: string, cursorPos: number): {
|
|
15
|
-
isInExpression: boolean;
|
|
16
|
-
expressionStart: number;
|
|
17
|
-
expressionContent: string;
|
|
18
|
-
cursorOffsetInExpression: number;
|
|
19
|
-
currentPath: string;
|
|
20
|
-
expression: string;
|
|
21
|
-
start: number;
|
|
22
|
-
end: number;
|
|
23
|
-
path: string;
|
|
24
|
-
} | null;
|
|
25
|
-
export declare function getValueType(value: unknown): string;
|
|
26
|
-
export {};
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getValueType = exports.getCurrentExpressionContext = exports.parseOperations = exports.extractPaths = exports.isInsideExpression = exports.hasReferences = exports.hasExpressions = exports.buildReferenceString = exports.buildExpressionString = void 0;
|
|
4
|
-
function buildExpressionString(path, operations) {
|
|
5
|
-
let expr = `{{${path}`;
|
|
6
|
-
if (operations && operations.length > 0) {
|
|
7
|
-
const opsStr = operations
|
|
8
|
-
.map((op) => {
|
|
9
|
-
if (op.args.length === 0) {
|
|
10
|
-
return op.name;
|
|
11
|
-
}
|
|
12
|
-
const argsStr = op.args
|
|
13
|
-
.map((arg) => (typeof arg === 'string' ? `"${arg}"` : String(arg)))
|
|
14
|
-
.join(', ');
|
|
15
|
-
return `${op.name}(${argsStr})`;
|
|
16
|
-
})
|
|
17
|
-
.join(' | ');
|
|
18
|
-
expr += ` | ${opsStr}`;
|
|
19
|
-
}
|
|
20
|
-
expr += '}}';
|
|
21
|
-
return expr;
|
|
22
|
-
}
|
|
23
|
-
exports.buildExpressionString = buildExpressionString;
|
|
24
|
-
function buildReferenceString(type, id) {
|
|
25
|
-
return `@${type}:${id}`;
|
|
26
|
-
}
|
|
27
|
-
exports.buildReferenceString = buildReferenceString;
|
|
28
|
-
function hasExpressions(str) {
|
|
29
|
-
return /\{\{.+?\}\}/.test(str);
|
|
30
|
-
}
|
|
31
|
-
exports.hasExpressions = hasExpressions;
|
|
32
|
-
function hasReferences(str) {
|
|
33
|
-
return /@\w+:[a-zA-Z0-9-_]+/.test(str);
|
|
34
|
-
}
|
|
35
|
-
exports.hasReferences = hasReferences;
|
|
36
|
-
function isInsideExpression(text, cursorPos) {
|
|
37
|
-
const beforeCursor = text.substring(0, cursorPos);
|
|
38
|
-
const lastOpenBrace = beforeCursor.lastIndexOf('{{');
|
|
39
|
-
const lastCloseBrace = beforeCursor.lastIndexOf('}}');
|
|
40
|
-
return lastOpenBrace > lastCloseBrace && lastOpenBrace !== -1;
|
|
41
|
-
}
|
|
42
|
-
exports.isInsideExpression = isInsideExpression;
|
|
43
|
-
function extractPaths(str) {
|
|
44
|
-
const matches = str.matchAll(/\{\{(.+?)\}\}/g);
|
|
45
|
-
return Array.from(matches, (m) => {
|
|
46
|
-
const expr = m[1].trim();
|
|
47
|
-
const [path] = expr.split('|');
|
|
48
|
-
return path.trim();
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
exports.extractPaths = extractPaths;
|
|
52
|
-
function parseOperations(opsStr) {
|
|
53
|
-
if (!opsStr || !opsStr.trim()) {
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
const operations = [];
|
|
57
|
-
const parts = opsStr.split('|').map((p) => p.trim());
|
|
58
|
-
for (const part of parts) {
|
|
59
|
-
if (!part) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
const match = part.match(/^(\w+)(?:\(([^)]*)\))?$/);
|
|
63
|
-
if (match) {
|
|
64
|
-
const [, name, argsStr] = match;
|
|
65
|
-
const args = [];
|
|
66
|
-
if (argsStr) {
|
|
67
|
-
const argParts = argsStr.split(',').map((a) => a.trim());
|
|
68
|
-
for (const arg of argParts) {
|
|
69
|
-
if (arg.startsWith('"') || arg.startsWith("'")) {
|
|
70
|
-
args.push(arg.slice(1, -1));
|
|
71
|
-
}
|
|
72
|
-
else if (!isNaN(Number(arg))) {
|
|
73
|
-
args.push(Number(arg));
|
|
74
|
-
}
|
|
75
|
-
else if (arg === 'true' || arg === 'false') {
|
|
76
|
-
args.push(arg === 'true');
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
args.push(arg);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
operations.push({ name, args });
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return operations;
|
|
87
|
-
}
|
|
88
|
-
exports.parseOperations = parseOperations;
|
|
89
|
-
function getCurrentExpressionContext(text, cursorPos) {
|
|
90
|
-
if (!isInsideExpression(text, cursorPos)) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
const beforeCursor = text.substring(0, cursorPos);
|
|
94
|
-
const afterCursor = text.substring(cursorPos);
|
|
95
|
-
const start = beforeCursor.lastIndexOf('{{') + 2;
|
|
96
|
-
const endMatch = afterCursor.match(/\}\}/);
|
|
97
|
-
const end = endMatch && endMatch.index !== undefined
|
|
98
|
-
? cursorPos + endMatch.index
|
|
99
|
-
: text.length;
|
|
100
|
-
const expression = text.substring(start, end);
|
|
101
|
-
const [path] = expression.split('|');
|
|
102
|
-
const expressionContent = expression.trim();
|
|
103
|
-
const cursorOffsetInExpression = cursorPos - start;
|
|
104
|
-
const contentUpToCursor = expression.substring(0, cursorOffsetInExpression);
|
|
105
|
-
const match = contentUpToCursor.match(/([a-zA-Z_][a-zA-Z0-9_]*(?:\["[^"]*"\]|\['[^']*'\]|\[[^\]]*\]|\.(?:[a-zA-Z_][a-zA-Z0-9_]*))*\.?[a-zA-Z0-9_]*)$/);
|
|
106
|
-
const currentPath = match && match[1] ? match[1] : '';
|
|
107
|
-
return {
|
|
108
|
-
isInExpression: true,
|
|
109
|
-
expressionStart: start,
|
|
110
|
-
expressionContent,
|
|
111
|
-
cursorOffsetInExpression,
|
|
112
|
-
currentPath,
|
|
113
|
-
expression: expression.trim(),
|
|
114
|
-
start,
|
|
115
|
-
end,
|
|
116
|
-
path: path.trim(),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
exports.getCurrentExpressionContext = getCurrentExpressionContext;
|
|
120
|
-
function getValueType(value) {
|
|
121
|
-
if (value === null) {
|
|
122
|
-
return 'null';
|
|
123
|
-
}
|
|
124
|
-
if (value === undefined) {
|
|
125
|
-
return 'undefined';
|
|
126
|
-
}
|
|
127
|
-
if (Array.isArray(value)) {
|
|
128
|
-
return 'array';
|
|
129
|
-
}
|
|
130
|
-
return typeof value;
|
|
131
|
-
}
|
|
132
|
-
exports.getValueType = getValueType;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type { ResourceMapping, ExpressionToken, ExpressionParserConfig, ParsedExpression, ExpressionMappingOptions, } from './types';
|
|
2
|
-
export { parseExpression, stringifyExpression } from './parser';
|
|
3
|
-
export { convertToDisplayFormat, convertToSaveFormat, extractMappings, validateExpression, createResourceMapping, } from './mapper';
|
|
4
|
-
export type { ExpressionContext, ResolverOptions } from './resolver';
|
|
5
|
-
export { resolveExpression, isDynamicExpression, extractPaths } from './resolver';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractPaths = exports.isDynamicExpression = exports.resolveExpression = exports.createResourceMapping = exports.validateExpression = exports.extractMappings = exports.convertToSaveFormat = exports.convertToDisplayFormat = exports.stringifyExpression = exports.parseExpression = void 0;
|
|
4
|
-
var parser_1 = require("./parser");
|
|
5
|
-
Object.defineProperty(exports, "parseExpression", { enumerable: true, get: function () { return parser_1.parseExpression; } });
|
|
6
|
-
Object.defineProperty(exports, "stringifyExpression", { enumerable: true, get: function () { return parser_1.stringifyExpression; } });
|
|
7
|
-
var mapper_1 = require("./mapper");
|
|
8
|
-
Object.defineProperty(exports, "convertToDisplayFormat", { enumerable: true, get: function () { return mapper_1.convertToDisplayFormat; } });
|
|
9
|
-
Object.defineProperty(exports, "convertToSaveFormat", { enumerable: true, get: function () { return mapper_1.convertToSaveFormat; } });
|
|
10
|
-
Object.defineProperty(exports, "extractMappings", { enumerable: true, get: function () { return mapper_1.extractMappings; } });
|
|
11
|
-
Object.defineProperty(exports, "validateExpression", { enumerable: true, get: function () { return mapper_1.validateExpression; } });
|
|
12
|
-
Object.defineProperty(exports, "createResourceMapping", { enumerable: true, get: function () { return mapper_1.createResourceMapping; } });
|
|
13
|
-
var resolver_1 = require("./resolver");
|
|
14
|
-
Object.defineProperty(exports, "resolveExpression", { enumerable: true, get: function () { return resolver_1.resolveExpression; } });
|
|
15
|
-
Object.defineProperty(exports, "isDynamicExpression", { enumerable: true, get: function () { return resolver_1.isDynamicExpression; } });
|
|
16
|
-
Object.defineProperty(exports, "extractPaths", { enumerable: true, get: function () { return resolver_1.extractPaths; } });
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ResourceMapping, ExpressionMappingOptions } from './types';
|
|
2
|
-
export declare function convertToDisplayFormat<TSource = string>(expression: string, mappings: ResourceMapping<TSource>[], options?: ExpressionMappingOptions): string;
|
|
3
|
-
export declare function convertToSaveFormat<TSource = string>(expression: string, mappings: ResourceMapping<TSource>[], options?: ExpressionMappingOptions): string;
|
|
4
|
-
export declare function extractMappings<TSource = string>(expression: string, mappings: ResourceMapping<TSource>[]): ResourceMapping<TSource>[];
|
|
5
|
-
export declare function validateExpression<TSource = string>(expression: string, mappings: ResourceMapping<TSource>[]): {
|
|
6
|
-
valid: boolean;
|
|
7
|
-
missingReferences: string[];
|
|
8
|
-
};
|
|
9
|
-
export declare function createResourceMapping<TSource = string>(source: TSource, resourceId: string, resourceName: string, pathBuilder: (source: TSource, identifier: string) => string): ResourceMapping<TSource>;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createResourceMapping = exports.validateExpression = exports.extractMappings = exports.convertToSaveFormat = exports.convertToDisplayFormat = void 0;
|
|
4
|
-
const parser_1 = require("./parser");
|
|
5
|
-
function convertToDisplayFormat(expression, mappings, options = {}) {
|
|
6
|
-
const opts = {
|
|
7
|
-
strict: false,
|
|
8
|
-
preserveUnknown: true,
|
|
9
|
-
...options,
|
|
10
|
-
};
|
|
11
|
-
if (!expression) {
|
|
12
|
-
return expression;
|
|
13
|
-
}
|
|
14
|
-
let result = expression;
|
|
15
|
-
const sortedMappings = [...mappings].sort((a, b) => b.savePath.length - a.savePath.length);
|
|
16
|
-
for (const mapping of sortedMappings) {
|
|
17
|
-
const escapedSavePath = escapeRegExp(mapping.savePath);
|
|
18
|
-
const regex = new RegExp(escapedSavePath, 'g');
|
|
19
|
-
result = result.replace(regex, mapping.displayPath);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
exports.convertToDisplayFormat = convertToDisplayFormat;
|
|
24
|
-
function convertToSaveFormat(expression, mappings, options = {}) {
|
|
25
|
-
const opts = {
|
|
26
|
-
strict: false,
|
|
27
|
-
preserveUnknown: true,
|
|
28
|
-
...options,
|
|
29
|
-
};
|
|
30
|
-
if (!expression) {
|
|
31
|
-
return expression;
|
|
32
|
-
}
|
|
33
|
-
let result = expression;
|
|
34
|
-
const sortedMappings = [...mappings].sort((a, b) => b.displayPath.length - a.displayPath.length);
|
|
35
|
-
for (const mapping of sortedMappings) {
|
|
36
|
-
const escapedDisplayPath = escapeRegExp(mapping.displayPath);
|
|
37
|
-
const regex = new RegExp(escapedDisplayPath, 'g');
|
|
38
|
-
result = result.replace(regex, mapping.savePath);
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
exports.convertToSaveFormat = convertToSaveFormat;
|
|
43
|
-
function extractMappings(expression, mappings) {
|
|
44
|
-
if (!expression) {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
const parsed = (0, parser_1.parseExpression)(expression);
|
|
48
|
-
const usedMappings = [];
|
|
49
|
-
for (const reference of parsed.references) {
|
|
50
|
-
const mapping = mappings.find((m) => m.displayPath.includes(reference.source) || m.savePath.includes(reference.source));
|
|
51
|
-
if (mapping && !usedMappings.includes(mapping)) {
|
|
52
|
-
usedMappings.push(mapping);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return usedMappings;
|
|
56
|
-
}
|
|
57
|
-
exports.extractMappings = extractMappings;
|
|
58
|
-
function validateExpression(expression, mappings) {
|
|
59
|
-
if (!expression) {
|
|
60
|
-
return { valid: true, missingReferences: [] };
|
|
61
|
-
}
|
|
62
|
-
const parsed = (0, parser_1.parseExpression)(expression);
|
|
63
|
-
const missingReferences = [];
|
|
64
|
-
for (const reference of parsed.references) {
|
|
65
|
-
const hasMapping = mappings.some((m) => m.displayPath.includes(reference.source) || m.savePath.includes(reference.source));
|
|
66
|
-
if (!hasMapping) {
|
|
67
|
-
missingReferences.push(`${reference.source}.${reference.path}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
valid: missingReferences.length === 0,
|
|
72
|
-
missingReferences,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
exports.validateExpression = validateExpression;
|
|
76
|
-
function escapeRegExp(str) {
|
|
77
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
78
|
-
}
|
|
79
|
-
function createResourceMapping(source, resourceId, resourceName, pathBuilder) {
|
|
80
|
-
return {
|
|
81
|
-
source,
|
|
82
|
-
resourceId,
|
|
83
|
-
resourceName,
|
|
84
|
-
displayPath: pathBuilder(source, resourceName),
|
|
85
|
-
savePath: pathBuilder(source, resourceId),
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
exports.createResourceMapping = createResourceMapping;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { ExpressionToken, ExpressionParserConfig, ParsedExpression } from './types';
|
|
2
|
-
export declare function parseExpression(expression: string, config?: ExpressionParserConfig): ParsedExpression;
|
|
3
|
-
export declare function stringifyExpression(tokens: ExpressionToken[], config?: ExpressionParserConfig): string;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringifyExpression = exports.parseExpression = void 0;
|
|
4
|
-
const DEFAULT_CONFIG = {
|
|
5
|
-
openDelimiter: '{{',
|
|
6
|
-
closeDelimiter: '}}',
|
|
7
|
-
trimExpressions: true,
|
|
8
|
-
};
|
|
9
|
-
function parseExpression(expression, config = {}) {
|
|
10
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
11
|
-
const tokens = [];
|
|
12
|
-
const references = [];
|
|
13
|
-
let currentPosition = 0;
|
|
14
|
-
let isDynamic = false;
|
|
15
|
-
while (currentPosition < expression.length) {
|
|
16
|
-
const openIndex = expression.indexOf(cfg.openDelimiter, currentPosition);
|
|
17
|
-
if (openIndex === -1) {
|
|
18
|
-
const remaining = expression.slice(currentPosition);
|
|
19
|
-
if (remaining) {
|
|
20
|
-
tokens.push({ type: 'text', value: remaining });
|
|
21
|
-
}
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
if (openIndex > currentPosition) {
|
|
25
|
-
tokens.push({
|
|
26
|
-
type: 'text',
|
|
27
|
-
value: expression.slice(currentPosition, openIndex),
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
const closeIndex = expression.indexOf(cfg.closeDelimiter, openIndex + cfg.openDelimiter.length);
|
|
31
|
-
if (closeIndex === -1) {
|
|
32
|
-
tokens.push({
|
|
33
|
-
type: 'text',
|
|
34
|
-
value: expression.slice(openIndex),
|
|
35
|
-
});
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
const rawExpression = expression.slice(openIndex, closeIndex + cfg.closeDelimiter.length);
|
|
39
|
-
let expressionContent = expression.slice(openIndex + cfg.openDelimiter.length, closeIndex);
|
|
40
|
-
if (cfg.trimExpressions) {
|
|
41
|
-
expressionContent = expressionContent.trim();
|
|
42
|
-
}
|
|
43
|
-
const referenceMatch = parseReference(expressionContent);
|
|
44
|
-
if (referenceMatch) {
|
|
45
|
-
references.push(referenceMatch);
|
|
46
|
-
}
|
|
47
|
-
tokens.push({
|
|
48
|
-
type: 'expression',
|
|
49
|
-
value: expressionContent,
|
|
50
|
-
raw: rawExpression,
|
|
51
|
-
});
|
|
52
|
-
isDynamic = true;
|
|
53
|
-
currentPosition = closeIndex + cfg.closeDelimiter.length;
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
tokens,
|
|
57
|
-
isDynamic,
|
|
58
|
-
references,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
exports.parseExpression = parseExpression;
|
|
62
|
-
function parseReference(expression) {
|
|
63
|
-
expression = expression.trim();
|
|
64
|
-
const dotMatch = expression.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\.(.+)$/);
|
|
65
|
-
if (dotMatch) {
|
|
66
|
-
return {
|
|
67
|
-
source: dotMatch[1],
|
|
68
|
-
path: dotMatch[2],
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const bracketMatch = expression.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[['"](.+?)['"]\]$/);
|
|
72
|
-
if (bracketMatch) {
|
|
73
|
-
return {
|
|
74
|
-
source: bracketMatch[1],
|
|
75
|
-
path: bracketMatch[2],
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
function stringifyExpression(tokens, config = {}) {
|
|
81
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
82
|
-
return tokens
|
|
83
|
-
.map((token) => {
|
|
84
|
-
if (token.type === 'text') {
|
|
85
|
-
return token.value;
|
|
86
|
-
}
|
|
87
|
-
if (token.type === 'expression') {
|
|
88
|
-
return token.raw || `${cfg.openDelimiter}${token.value}${cfg.closeDelimiter}`;
|
|
89
|
-
}
|
|
90
|
-
if (token.type === 'reference') {
|
|
91
|
-
return `${cfg.openDelimiter}${token.source}.${token.path}${cfg.closeDelimiter}`;
|
|
92
|
-
}
|
|
93
|
-
return '';
|
|
94
|
-
})
|
|
95
|
-
.join('');
|
|
96
|
-
}
|
|
97
|
-
exports.stringifyExpression = stringifyExpression;
|