Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit 053cbe4

Browse files
committed
UUID, json/x path
1 parent 21b9e5a commit 053cbe4

8 files changed

Lines changed: 298 additions & 2 deletions

File tree

package-lock.json

Lines changed: 107 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/filter-jsonpath/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dev": "yaakcli dev ./src/index.js"
88
},
99
"dependencies": {
10-
"jsonpath-plus": "^9.0.0"
10+
"jsonpath-plus": "^10.3.0"
1111
},
1212
"devDependencies": {
1313
"@types/jsonpath": "^0.2.4"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@yaakapp/template-function-json",
3+
"private": true,
4+
"version": "0.0.1",
5+
"scripts": {
6+
"build": "yaakcli build ./src/index.ts",
7+
"dev": "yaakcli dev ./src/index.js"
8+
},
9+
"dependencies": {
10+
"jsonpath-plus": "^10.3.0"
11+
},
12+
"devDependencies": {
13+
"@types/jsonpath": "^0.2.4"
14+
}
15+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
2+
import { JSONPath } from 'jsonpath-plus';
3+
4+
export const plugin: PluginDefinition = {
5+
templateFunctions: [
6+
{
7+
name: 'json.jsonpath',
8+
description: 'Filter JSON-formatted text using JSONPath syntax',
9+
args: [
10+
{ type: 'text', name: 'input', label: 'Input', multiLine: true, placeholder: '{ "foo": "bar" }' },
11+
{ type: 'text', name: 'query', label: 'Query', placeholder: '$..foo' },
12+
{ type: 'checkbox', name: 'formatted', label: 'Format Output' },
13+
],
14+
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
15+
try {
16+
const parsed = JSON.parse(String(args.values.input));
17+
const query = String(args.values.query ?? '$').trim();
18+
let filtered = JSONPath({ path: query, json: parsed });
19+
if (Array.isArray(filtered)) {
20+
filtered = filtered[0];
21+
}
22+
23+
if (args.values.formatted) {
24+
return JSON.stringify(filtered, null, 2);
25+
} else {
26+
return JSON.stringify(filtered);
27+
}
28+
} catch (e) {
29+
return null;
30+
}
31+
},
32+
},
33+
{
34+
name: 'json.escape',
35+
description: 'Escape a JSON string, useful when using the output in JSON values',
36+
args: [
37+
{ type: 'text', name: 'input', label: 'Input', multiLine: true, placeholder: 'Hello "World"' },
38+
],
39+
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
40+
const input = String(args.values.input ?? '');
41+
return input.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
42+
},
43+
},
44+
],
45+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@yaakapp/template-function-uuid",
3+
"private": true,
4+
"version": "0.0.1",
5+
"scripts": {
6+
"build": "yaakcli build ./src/index.ts",
7+
"dev": "yaakcli dev ./src/index.js"
8+
},
9+
"dependencies": {
10+
"uuid": "^11.1.0"
11+
}
12+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
2+
import { v1, v3, v4, v5, v6, v7 } from 'uuid';
3+
4+
export const plugin: PluginDefinition = {
5+
templateFunctions: [
6+
{
7+
name: 'uuid.v1',
8+
description: 'Generate a UUID V1',
9+
args: [],
10+
async onRender(_ctx: Context, _args: CallTemplateFunctionArgs): Promise<string | null> {
11+
return v1();
12+
},
13+
},
14+
{
15+
name: 'uuid.v3',
16+
description: 'Generate a UUID V3',
17+
args: [
18+
{ type: 'text', name: 'name', label: 'Name' },
19+
{
20+
type: 'text',
21+
name: 'namespace',
22+
label: 'Namespace UUID',
23+
description: 'A valid UUID to use as the namespace',
24+
placeholder: '24ced880-3bf4-11f0-8329-cd053d577f0e',
25+
},
26+
],
27+
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
28+
return v3(String(args.values.name), String(args.values.namespace));
29+
},
30+
},
31+
{
32+
name: 'uuid.v4',
33+
description: 'Generate a UUID V4',
34+
args: [],
35+
async onRender(_ctx: Context, _args: CallTemplateFunctionArgs): Promise<string | null> {
36+
return v4();
37+
},
38+
},
39+
{
40+
name: 'uuid.v5',
41+
description: 'Generate a UUID V5',
42+
args: [
43+
{ type: 'text', name: 'name', label: 'Name' },
44+
{ type: 'text', name: 'namespace', label: 'Namespace' },
45+
],
46+
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
47+
return v5(String(args.values.name), String(args.values.namespace));
48+
},
49+
},
50+
{
51+
name: 'uuid.v6',
52+
description: 'Generate a UUID V6',
53+
args: [
54+
{
55+
type: 'text',
56+
name: 'timestamp',
57+
label: 'Timestamp',
58+
optional: true,
59+
description: 'Can be any format that can be parsed by JavaScript new Date(...)',
60+
placeholder: '2025-05-28T11:15:00Z',
61+
},
62+
],
63+
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
64+
return v6({ msecs: new Date(String(args.values.timestamp)).getTime() });
65+
},
66+
},
67+
{
68+
name: 'uuid.v7',
69+
description: 'Generate a UUID V7',
70+
args: [],
71+
async onRender(_ctx: Context, _args: CallTemplateFunctionArgs): Promise<string | null> {
72+
return v7();
73+
},
74+
},
75+
],
76+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@yaakapp/template-function-xml",
3+
"private": true,
4+
"version": "0.0.1",
5+
"scripts": {
6+
"build": "yaakcli build ./src/index.ts",
7+
"dev": "yaakcli dev ./src/index.js"
8+
},
9+
"dependencies": {
10+
"@xmldom/xmldom": "^0.8.10",
11+
"xpath": "^0.0.34"
12+
}
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { DOMParser } from '@xmldom/xmldom';
2+
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
3+
import xpath from 'xpath';
4+
5+
export const plugin: PluginDefinition = {
6+
templateFunctions: [{
7+
name: 'xml.xpath',
8+
description: 'Filter XML-formatted text using XPath syntax',
9+
args: [
10+
{ type: 'text', name: 'input', label: 'Input', multiLine: true, placeholder: '<foo></foo>' },
11+
{ type: 'text', name: 'query', label: 'Query', placeholder: '//foo' },
12+
],
13+
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
14+
try {
15+
const doc = new DOMParser().parseFromString(String(args.values.input), 'text/xml');
16+
let result = xpath.select(String(args.values.query), doc, false);
17+
if (Array.isArray(result)) {
18+
return String(result.map(c => String(c.firstChild))[0]);
19+
} else if (result instanceof Node) {
20+
return String(result.firstChild);
21+
} else {
22+
return String(result);
23+
}
24+
} catch (e) {
25+
return null;
26+
}
27+
},
28+
}],
29+
};

0 commit comments

Comments
 (0)