@arkitektio/bsx 0.0.0 → 1.0.1
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/package.json +2 -2
- package/dist/renderer/base_v1.json +0 -1541
- package/dist/renderer/functions/argumentSchemas.d.ts +0 -19
- package/dist/renderer/functions/argumentSchemas.d.ts.map +0 -1
- package/dist/renderer/functions/argumentSchemas.js +0 -35
- package/dist/renderer/functions/argumentSchemas.js.map +0 -1
- package/dist/renderer/functions/base.d.ts +0 -3
- package/dist/renderer/functions/base.d.ts.map +0 -1
- package/dist/renderer/functions/base.js +0 -159
- package/dist/renderer/functions/base.js.map +0 -1
- package/dist/renderer/functions/coerce.d.ts +0 -2
- package/dist/renderer/functions/coerce.d.ts.map +0 -1
- package/dist/renderer/functions/coerce.js +0 -73
- package/dist/renderer/functions/coerce.js.map +0 -1
- package/dist/renderer/functions/effects.d.ts +0 -4
- package/dist/renderer/functions/effects.d.ts.map +0 -1
- package/dist/renderer/functions/effects.js +0 -102
- package/dist/renderer/functions/effects.js.map +0 -1
- package/dist/renderer/functions/format.d.ts +0 -2
- package/dist/renderer/functions/format.d.ts.map +0 -1
- package/dist/renderer/functions/format.js +0 -134
- package/dist/renderer/functions/format.js.map +0 -1
- package/dist/renderer/functions/lists.d.ts +0 -2
- package/dist/renderer/functions/lists.d.ts.map +0 -1
- package/dist/renderer/functions/lists.js +0 -139
- package/dist/renderer/functions/lists.js.map +0 -1
- package/dist/renderer/functions/logic.d.ts +0 -3
- package/dist/renderer/functions/logic.d.ts.map +0 -1
- package/dist/renderer/functions/logic.js +0 -37
- package/dist/renderer/functions/logic.js.map +0 -1
- package/dist/renderer/functions/math.d.ts +0 -4
- package/dist/renderer/functions/math.d.ts.map +0 -1
- package/dist/renderer/functions/math.js +0 -61
- package/dist/renderer/functions/math.js.map +0 -1
- package/dist/renderer/functions/objects.d.ts +0 -2
- package/dist/renderer/functions/objects.d.ts.map +0 -1
- package/dist/renderer/functions/objects.js +0 -42
- package/dist/renderer/functions/objects.js.map +0 -1
- package/dist/renderer/functions/strings.d.ts +0 -4
- package/dist/renderer/functions/strings.d.ts.map +0 -1
- package/dist/renderer/functions/strings.js +0 -115
- package/dist/renderer/functions/strings.js.map +0 -1
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* Argument schemas shared by the catalog functions.
|
|
4
|
-
*
|
|
5
|
-
* Blok arguments arrive from JSON and from data-model paths, so a "number" is
|
|
6
|
-
* routinely a numeric string. These schemas accept the tolerant input a payload
|
|
7
|
-
* actually carries while still rejecting genuine nonsense with a message that
|
|
8
|
-
* names the offending value — `z.coerce.number()` would quietly turn `"abc"`
|
|
9
|
-
* into `NaN` and poison everything downstream.
|
|
10
|
-
*/
|
|
11
|
-
export declare const numericSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>;
|
|
12
|
-
export declare const integerSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<number, string | number>>;
|
|
13
|
-
/** Anything renderable as text. */
|
|
14
|
-
export declare const textSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodTransform<string, string | number | boolean>>;
|
|
15
|
-
/** Any value, judged by JavaScript truthiness — what a UI condition wants. */
|
|
16
|
-
export declare const truthySchema: z.ZodUnknown;
|
|
17
|
-
export declare const listSchema: z.ZodArray<z.ZodUnknown>;
|
|
18
|
-
export declare const recordSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
19
|
-
//# sourceMappingURL=argumentSchemas.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"argumentSchemas.d.ts","sourceRoot":"","sources":["../../../src/renderer/functions/argumentSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB;;;;;;;;GAQG;AAEH,eAAO,MAAM,aAAa,qGActB,CAAC;AAEL,eAAO,MAAM,aAAa,qGAExB,CAAC;AAEH,mCAAmC;AACnC,eAAO,MAAM,UAAU,6HAEa,CAAC;AAErC,8EAA8E;AAC9E,eAAO,MAAM,YAAY,cAAc,CAAC;AAExC,eAAO,MAAM,UAAU,0BAAuB,CAAC;AAE/C,eAAO,MAAM,YAAY,wCAAoC,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* Argument schemas shared by the catalog functions.
|
|
4
|
-
*
|
|
5
|
-
* Blok arguments arrive from JSON and from data-model paths, so a "number" is
|
|
6
|
-
* routinely a numeric string. These schemas accept the tolerant input a payload
|
|
7
|
-
* actually carries while still rejecting genuine nonsense with a message that
|
|
8
|
-
* names the offending value — `z.coerce.number()` would quietly turn `"abc"`
|
|
9
|
-
* into `NaN` and poison everything downstream.
|
|
10
|
-
*/
|
|
11
|
-
export const numericSchema = z
|
|
12
|
-
.union([z.number(), z.string()])
|
|
13
|
-
.transform((value, ctx) => {
|
|
14
|
-
const parsed = typeof value === 'number' ? value : Number(value.trim());
|
|
15
|
-
if (!Number.isFinite(parsed)) {
|
|
16
|
-
ctx.addIssue({
|
|
17
|
-
code: 'custom',
|
|
18
|
-
message: `Expected a number, received ${JSON.stringify(value)}.`,
|
|
19
|
-
});
|
|
20
|
-
return z.NEVER;
|
|
21
|
-
}
|
|
22
|
-
return parsed;
|
|
23
|
-
});
|
|
24
|
-
export const integerSchema = numericSchema.refine(Number.isInteger, {
|
|
25
|
-
message: 'Expected a whole number.',
|
|
26
|
-
});
|
|
27
|
-
/** Anything renderable as text. */
|
|
28
|
-
export const textSchema = z
|
|
29
|
-
.union([z.string(), z.number(), z.boolean()])
|
|
30
|
-
.transform(value => String(value));
|
|
31
|
-
/** Any value, judged by JavaScript truthiness — what a UI condition wants. */
|
|
32
|
-
export const truthySchema = z.unknown();
|
|
33
|
-
export const listSchema = z.array(z.unknown());
|
|
34
|
-
export const recordSchema = z.record(z.string(), z.unknown());
|
|
35
|
-
//# sourceMappingURL=argumentSchemas.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"argumentSchemas.js","sourceRoot":"","sources":["../../../src/renderer/functions/argumentSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC;KAC3B,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;KAC/B,SAAS,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACxB,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAExE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,GAAG,CAAC,QAAQ,CAAC;YACX,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,+BAA+B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG;SACjE,CAAC,CAAC;QACH,OAAO,CAAC,CAAC,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE;IAClE,OAAO,EAAE,0BAA0B;CACpC,CAAC,CAAC;AAEH,mCAAmC;AACnC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC;KACxB,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5C,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAErC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;AAExC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/renderer/functions/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,sBAAsB,EAA8B,MAAM,YAAY,CAAC;AAyGxG,eAAO,MAAM,aAAa,EAAE,sBAAsB,EAmHjD,CAAC"}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { createBlokFunction } from '../runtime/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* The operations of the server's base catalog (`base@1`: rekuest
|
|
5
|
-
* `rekuest_core/catalogs/base_v1.json`, copied byte for byte into arkitekt-spec),
|
|
6
|
-
* under their own names and with their own argument keys, so a blok the server
|
|
7
|
-
* accepts evaluates here exactly as written: `@utils.if(condition=x, then=a,
|
|
8
|
-
* otherwise=b)`, `@utils.sub(a, b)`.
|
|
9
|
-
*
|
|
10
|
-
* The semantics are the catalog's, not this client's looser ones next door:
|
|
11
|
-
* equality is deep JSON equality, a comparison of non-numbers is false, and
|
|
12
|
-
* arithmetic on non-numbers (or a zero divisor) is null. `base.test.ts` checks
|
|
13
|
-
* that every operation of the catalog is here.
|
|
14
|
-
*/
|
|
15
|
-
const BASE_RETURNS = {
|
|
16
|
-
BOOL: 'boolean',
|
|
17
|
-
FLOAT: 'number',
|
|
18
|
-
INT: 'number',
|
|
19
|
-
ANY: 'unknown',
|
|
20
|
-
};
|
|
21
|
-
const operation = (name, returns, description, keys, execute) => createBlokFunction({
|
|
22
|
-
name,
|
|
23
|
-
description,
|
|
24
|
-
returnType: BASE_RETURNS[returns],
|
|
25
|
-
purity: 'pure',
|
|
26
|
-
// Missing reads as null, as the catalog says; each operation decides what that means.
|
|
27
|
-
schema: z.object(Object.fromEntries(keys.map(key => [key, z.unknown().optional()]))),
|
|
28
|
-
}, args => execute(args));
|
|
29
|
-
/** A number, or null for anything that is not one (a numeric string counts). */
|
|
30
|
-
const toNumber = (value) => {
|
|
31
|
-
if (typeof value === 'number')
|
|
32
|
-
return Number.isFinite(value) ? value : null;
|
|
33
|
-
if (typeof value === 'string' && value.trim() !== '') {
|
|
34
|
-
const parsed = Number(value);
|
|
35
|
-
return Number.isFinite(parsed) ? parsed : null;
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
};
|
|
39
|
-
/** JSON text with object keys sorted, so equal values compare equal. */
|
|
40
|
-
const canonical = (value) => JSON.stringify(value ?? null, (_key, inner) => inner && typeof inner === 'object' && !Array.isArray(inner)
|
|
41
|
-
? Object.fromEntries(Object.entries(inner).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
42
|
-
: inner);
|
|
43
|
-
const deepEquals = (a, b) => canonical(a) === canonical(b);
|
|
44
|
-
const lengthOf = (value) => {
|
|
45
|
-
if (value == null)
|
|
46
|
-
return 0;
|
|
47
|
-
if (typeof value === 'string' || Array.isArray(value))
|
|
48
|
-
return value.length;
|
|
49
|
-
if (typeof value === 'object')
|
|
50
|
-
return Object.keys(value).length;
|
|
51
|
-
return null;
|
|
52
|
-
};
|
|
53
|
-
const ordering = (compare) => (args) => {
|
|
54
|
-
const a = toNumber(args.a);
|
|
55
|
-
const b = toNumber(args.b);
|
|
56
|
-
return a !== null && b !== null && compare(a, b);
|
|
57
|
-
};
|
|
58
|
-
const arithmetic = (compute) => (args) => {
|
|
59
|
-
const a = toNumber(args.a);
|
|
60
|
-
const b = toNumber(args.b);
|
|
61
|
-
if (a === null || b === null)
|
|
62
|
-
return null;
|
|
63
|
-
const result = compute(a, b);
|
|
64
|
-
return result === null || !Number.isFinite(result) ? null : result;
|
|
65
|
-
};
|
|
66
|
-
/** RFC 6901: `/a/0/b`, `~1` for `/` and `~0` for `~`. The empty pointer is the value itself. */
|
|
67
|
-
const readPointer = (value, pointer) => {
|
|
68
|
-
if (pointer === '')
|
|
69
|
-
return value;
|
|
70
|
-
const tokens = (pointer.startsWith('/') ? pointer.slice(1) : pointer)
|
|
71
|
-
.split('/')
|
|
72
|
-
.map(token => token.replace(/~1/g, '/').replace(/~0/g, '~'));
|
|
73
|
-
let current = value;
|
|
74
|
-
for (const token of tokens) {
|
|
75
|
-
if (Array.isArray(current)) {
|
|
76
|
-
if (!/^(0|[1-9]\d*)$/.test(token))
|
|
77
|
-
return null;
|
|
78
|
-
current = current[Number(token)];
|
|
79
|
-
}
|
|
80
|
-
else if (current && typeof current === 'object') {
|
|
81
|
-
current = current[token];
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
if (current === undefined)
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
return current ?? null;
|
|
90
|
-
};
|
|
91
|
-
const text = (value) => (typeof value === 'string' ? value : null);
|
|
92
|
-
export const baseFunctions = [
|
|
93
|
-
operation('eq', 'BOOL', 'True if a equals b (deep JSON equality).', ['a', 'b'], args => deepEquals(args.a, args.b)),
|
|
94
|
-
operation('ne', 'BOOL', 'True if a does not equal b (deep JSON equality).', ['a', 'b'], args => !deepEquals(args.a, args.b)),
|
|
95
|
-
operation('gt', 'BOOL', 'True if a > b. Non-numbers compare false.', ['a', 'b'], ordering((a, b) => a > b)),
|
|
96
|
-
operation('gte', 'BOOL', 'True if a >= b. Non-numbers compare false.', ['a', 'b'], ordering((a, b) => a >= b)),
|
|
97
|
-
operation('lt', 'BOOL', 'True if a < b. Non-numbers compare false.', ['a', 'b'], ordering((a, b) => a < b)),
|
|
98
|
-
operation('lte', 'BOOL', 'True if a <= b. Non-numbers compare false.', ['a', 'b'], ordering((a, b) => a <= b)),
|
|
99
|
-
operation('between', 'BOOL', 'True if min <= value <= max (inclusive). Non-numbers compare false.', ['value', 'min', 'max'], args => {
|
|
100
|
-
const [value, min, max] = [toNumber(args.value), toNumber(args.min), toNumber(args.max)];
|
|
101
|
-
return value !== null && min !== null && max !== null && min <= value && value <= max;
|
|
102
|
-
}),
|
|
103
|
-
operation('and', 'BOOL', 'Logical conjunction of two booleans. Nest calls for more operands.', ['a', 'b'], args => args.a === true && args.b === true),
|
|
104
|
-
operation('or', 'BOOL', 'Logical disjunction of two booleans. Nest calls for more operands.', ['a', 'b'], args => args.a === true || args.b === true),
|
|
105
|
-
operation('not', 'BOOL', 'Logical negation.', ['a'], args => args.a !== true),
|
|
106
|
-
operation('if', 'ANY', 'Returns then if condition is true, otherwise otherwise.', ['condition', 'then', 'otherwise'], args => (args.condition === true ? args.then : args.otherwise) ?? null),
|
|
107
|
-
operation('is_null', 'BOOL', 'True if a is null or missing.', ['a'], args => args.a == null),
|
|
108
|
-
operation('is_set', 'BOOL', 'True if a is neither null nor missing.', ['a'], args => args.a != null),
|
|
109
|
-
operation('len', 'INT', 'Length of a string, list or dict. Null counts as 0.', ['a'], args => lengthOf(args.a)),
|
|
110
|
-
operation('len_between', 'BOOL', 'True if min <= len(value) <= max (inclusive). Omit max for no upper bound.', ['value', 'min', 'max'], args => {
|
|
111
|
-
const length = lengthOf(args.value);
|
|
112
|
-
const min = toNumber(args.min);
|
|
113
|
-
const max = args.max == null ? null : toNumber(args.max);
|
|
114
|
-
return length !== null && min !== null && length >= min && (max === null || length <= max);
|
|
115
|
-
}),
|
|
116
|
-
operation('is_empty', 'BOOL', 'True if a is null or has length 0.', ['a'], args => lengthOf(args.a) === 0),
|
|
117
|
-
operation('contains', 'BOOL', 'True if haystack contains needle: substring for strings, membership for lists, key presence for dicts.', ['haystack', 'needle'], args => {
|
|
118
|
-
const { haystack, needle } = args;
|
|
119
|
-
if (typeof haystack === 'string')
|
|
120
|
-
return typeof needle === 'string' && haystack.includes(needle);
|
|
121
|
-
if (Array.isArray(haystack))
|
|
122
|
-
return haystack.some(item => deepEquals(item, needle));
|
|
123
|
-
if (haystack && typeof haystack === 'object')
|
|
124
|
-
return typeof needle === 'string' && needle in haystack;
|
|
125
|
-
return false;
|
|
126
|
-
}),
|
|
127
|
-
operation('in', 'BOOL', 'True if value is a member of options.', ['value', 'options'], args => Array.isArray(args.options) && args.options.some(option => deepEquals(option, args.value))),
|
|
128
|
-
operation('matches', 'BOOL', 'True if the whole of value matches the regular expression pattern.', ['value', 'pattern'], args => {
|
|
129
|
-
const [value, pattern] = [text(args.value), text(args.pattern)];
|
|
130
|
-
if (value === null || pattern === null)
|
|
131
|
-
return false;
|
|
132
|
-
try {
|
|
133
|
-
return new RegExp(`^(?:${pattern})$`, 'u').test(value);
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
}),
|
|
139
|
-
operation('starts_with', 'BOOL', 'True if value starts with prefix.', ['value', 'prefix'], args => {
|
|
140
|
-
const [value, prefix] = [text(args.value), text(args.prefix)];
|
|
141
|
-
return value !== null && prefix !== null && value.startsWith(prefix);
|
|
142
|
-
}),
|
|
143
|
-
operation('ends_with', 'BOOL', 'True if value ends with suffix.', ['value', 'suffix'], args => {
|
|
144
|
-
const [value, suffix] = [text(args.value), text(args.suffix)];
|
|
145
|
-
return value !== null && suffix !== null && value.endsWith(suffix);
|
|
146
|
-
}),
|
|
147
|
-
operation('get', 'ANY', 'Reads path (a JSON pointer) out of value; null when the path does not resolve.', ['value', 'path'], args => (typeof args.path === 'string' ? readPointer(args.value, args.path) : null)),
|
|
148
|
-
operation('coalesce', 'ANY', 'The first of a, b that is not null.', ['a', 'b'], args => args.a ?? args.b ?? null),
|
|
149
|
-
operation('add', 'FLOAT', 'a + b. Non-numbers yield null.', ['a', 'b'], arithmetic((a, b) => a + b)),
|
|
150
|
-
operation('sub', 'FLOAT', 'a - b. Non-numbers yield null.', ['a', 'b'], arithmetic((a, b) => a - b)),
|
|
151
|
-
operation('mul', 'FLOAT', 'a * b. Non-numbers yield null.', ['a', 'b'], arithmetic((a, b) => a * b)),
|
|
152
|
-
operation('div', 'FLOAT', 'a / b (float division). Non-numbers and division by zero yield null.', ['a', 'b'], arithmetic((a, b) => (b === 0 ? null : a / b))),
|
|
153
|
-
operation('mod', 'FLOAT', 'a modulo b, with the sign of the divisor (Python semantics). Non-numbers and a zero divisor yield null.', ['a', 'b'], arithmetic((a, b) => (b === 0 ? null : ((a % b) + b) % b))),
|
|
154
|
-
operation('neg', 'FLOAT', '-a. Non-numbers yield null.', ['a'], args => {
|
|
155
|
-
const a = toNumber(args.a);
|
|
156
|
-
return a === null ? null : -a;
|
|
157
|
-
}),
|
|
158
|
-
];
|
|
159
|
-
//# sourceMappingURL=base.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/renderer/functions/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,kBAAkB,EAA2D,MAAM,YAAY,CAAC;AAExG;;;;;;;;;;;GAWG;AAEH,MAAM,YAAY,GAA2C;IAC3D,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,QAAQ;IACf,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,SAAS;CACf,CAAC;AAEF,MAAM,SAAS,GAAG,CAChB,IAAY,EACZ,OAAkC,EAClC,WAAmB,EACnB,IAAuB,EACvB,OAAmD,EAC3B,EAAE,CAC1B,kBAAkB,CAChB;IACE,IAAI;IACJ,WAAW;IACX,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC;IACjC,MAAM,EAAE,MAAM;IACd,sFAA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C,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAC3D;IACD,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE;QACrE,MAAM,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC,CAAC;CACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coerce.d.ts","sourceRoot":"","sources":["../../../src/renderer/functions/coerce.ts"],"names":[],"mappings":"AA6FA,eAAO,MAAM,eAAe,+CAK3B,CAAC"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { createBlokFunction } from '../runtime/index.js';
|
|
3
|
-
const anyValue = z.object({ value: z.unknown() });
|
|
4
|
-
const typeOfFunction = createBlokFunction({
|
|
5
|
-
name: 'type.of',
|
|
6
|
-
description: 'Names the type of a value: null, list, object, string, number, or boolean.',
|
|
7
|
-
returnType: 'string',
|
|
8
|
-
purity: 'pure',
|
|
9
|
-
schema: anyValue,
|
|
10
|
-
}, args => {
|
|
11
|
-
if (args.value === null || args.value === undefined) {
|
|
12
|
-
return 'null';
|
|
13
|
-
}
|
|
14
|
-
if (Array.isArray(args.value)) {
|
|
15
|
-
return 'list';
|
|
16
|
-
}
|
|
17
|
-
return typeof args.value;
|
|
18
|
-
});
|
|
19
|
-
const toStringFunction = createBlokFunction({
|
|
20
|
-
name: 'type.toString',
|
|
21
|
-
description: 'Converts any value to a string.',
|
|
22
|
-
returnType: 'string',
|
|
23
|
-
purity: 'pure',
|
|
24
|
-
schema: anyValue,
|
|
25
|
-
}, args => {
|
|
26
|
-
if (args.value == null) {
|
|
27
|
-
return '';
|
|
28
|
-
}
|
|
29
|
-
return typeof args.value === 'object'
|
|
30
|
-
? JSON.stringify(args.value)
|
|
31
|
-
: String(args.value);
|
|
32
|
-
});
|
|
33
|
-
const toNumberFunction = createBlokFunction({
|
|
34
|
-
name: 'type.toNumber',
|
|
35
|
-
description: 'Converts a value to a number, or falls back when it cannot.',
|
|
36
|
-
returnType: 'number',
|
|
37
|
-
purity: 'pure',
|
|
38
|
-
schema: z.object({ value: z.unknown(), fallback: z.number().optional() }),
|
|
39
|
-
}, args => {
|
|
40
|
-
const parsed = Number(typeof args.value === 'string' ? args.value.trim() : args.value);
|
|
41
|
-
if (Number.isFinite(parsed)) {
|
|
42
|
-
return parsed;
|
|
43
|
-
}
|
|
44
|
-
if (args.fallback !== undefined) {
|
|
45
|
-
return args.fallback;
|
|
46
|
-
}
|
|
47
|
-
throw new Error(`Cannot convert ${JSON.stringify(args.value)} to a number.`);
|
|
48
|
-
});
|
|
49
|
-
const toBooleanFunction = createBlokFunction({
|
|
50
|
-
name: 'type.toBoolean',
|
|
51
|
-
description: 'Converts a value to a boolean, treating "false" and "0" as false.',
|
|
52
|
-
returnType: 'boolean',
|
|
53
|
-
purity: 'pure',
|
|
54
|
-
schema: anyValue,
|
|
55
|
-
}, args => {
|
|
56
|
-
// A checkbox state that round-tripped through JSON arrives as the *string*
|
|
57
|
-
// "false", which is truthy in JavaScript and the wrong answer here.
|
|
58
|
-
if (typeof args.value === 'string') {
|
|
59
|
-
const normalized = args.value.trim().toLowerCase();
|
|
60
|
-
if (normalized === 'false' || normalized === '0' || normalized === '') {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
return Boolean(args.value);
|
|
66
|
-
});
|
|
67
|
-
export const coerceFunctions = [
|
|
68
|
-
typeOfFunction,
|
|
69
|
-
toStringFunction,
|
|
70
|
-
toNumberFunction,
|
|
71
|
-
toBooleanFunction,
|
|
72
|
-
];
|
|
73
|
-
//# sourceMappingURL=coerce.js.map
|
|
@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C,WAAW,EAAE,CAAC;QACnD,IAAI,UAAU,KAAK,OAAO,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc;IACd,gBAAgB;IAChB,gBAAgB;IAChB,iBAAiB;CAClB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../../src/renderer/functions/effects.ts"],"names":[],"mappings":"AA0FA,6EAA6E;AAC7E,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAyBlD,eAAO,MAAM,eAAe,+CAO3B,CAAC"}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { blokPlatform, toast } from "../../platform.js";
|
|
3
|
-
import { createBlokFunction, createVariadicBlokFunction } from '../runtime/index.js';
|
|
4
|
-
import { recordSchema, textSchema } from './argumentSchemas.js';
|
|
5
|
-
/**
|
|
6
|
-
* Effectful functions. These are refused in value position by the preflight and
|
|
7
|
-
* only run from an action prop, so they cannot fire on every render.
|
|
8
|
-
*/
|
|
9
|
-
const describe = (values) => (values.length === 1 ? values[0] : values);
|
|
10
|
-
const createLoggerFunction = (level) => createVariadicBlokFunction({
|
|
11
|
-
name: `logger.${level}`,
|
|
12
|
-
description: `Logs its arguments to the console at ${level} level. For a message the user should see, use ui.toast.`,
|
|
13
|
-
returnType: 'unknown',
|
|
14
|
-
purity: 'effect',
|
|
15
|
-
item: z.unknown(),
|
|
16
|
-
min: 1,
|
|
17
|
-
}, values => {
|
|
18
|
-
const message = describe(values);
|
|
19
|
-
// Resolved at call time, not captured at module load, so the sink stays
|
|
20
|
-
// whatever `console` is when the action actually fires. No toast: a log
|
|
21
|
-
// line is for the author, and a logger in a loop would fill the island.
|
|
22
|
-
console[level](`blok logger.${level}`, message);
|
|
23
|
-
return message;
|
|
24
|
-
});
|
|
25
|
-
const copyFunction = createBlokFunction({
|
|
26
|
-
name: 'clipboard.copy',
|
|
27
|
-
description: 'Copies a value to the clipboard.',
|
|
28
|
-
returnType: 'void',
|
|
29
|
-
purity: 'effect',
|
|
30
|
-
schema: z.object({ value: textSchema, message: textSchema.optional() }),
|
|
31
|
-
}, args => {
|
|
32
|
-
void blokPlatform()
|
|
33
|
-
.copyText(args.value)
|
|
34
|
-
.then(() => toast.success(args.message ?? 'Copied to clipboard.'))
|
|
35
|
-
.catch(() => toast.error('Could not copy to the clipboard.'));
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* A toast is the one piece of UI a blok raises without a component: it is
|
|
39
|
-
* transient, app-owned chrome (the toast island, `core/notify`),
|
|
40
|
-
* so it belongs in action position like any other effect.
|
|
41
|
-
*/
|
|
42
|
-
const toastFunction = createBlokFunction({
|
|
43
|
-
name: 'ui.toast',
|
|
44
|
-
description: 'Shows a toast notification.',
|
|
45
|
-
returnType: 'void',
|
|
46
|
-
purity: 'effect',
|
|
47
|
-
schema: z.object({
|
|
48
|
-
message: textSchema.describe('The message to show.'),
|
|
49
|
-
description: textSchema.optional().describe('Secondary line under the message.'),
|
|
50
|
-
level: z
|
|
51
|
-
.enum(['default', 'success', 'info', 'warning', 'error'])
|
|
52
|
-
.optional()
|
|
53
|
-
.describe('Toast severity. Defaults to "default".'),
|
|
54
|
-
}),
|
|
55
|
-
}, args => {
|
|
56
|
-
const options = args.description ? { description: args.description } : undefined;
|
|
57
|
-
switch (args.level) {
|
|
58
|
-
case 'success':
|
|
59
|
-
toast.success(args.message, options);
|
|
60
|
-
break;
|
|
61
|
-
case 'info':
|
|
62
|
-
toast.info(args.message, options);
|
|
63
|
-
break;
|
|
64
|
-
case 'warning':
|
|
65
|
-
toast.warning(args.message, options);
|
|
66
|
-
break;
|
|
67
|
-
case 'error':
|
|
68
|
-
toast.error(args.message, options);
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
toast(args.message, options);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
/** The name a host intercepts (`invokeFunction`) to take a blok's answer. */
|
|
75
|
-
export const BLOK_ANSWER_FUNCTION = 'blok.answer';
|
|
76
|
-
/**
|
|
77
|
-
* A blok's answer to the task that asks with it: one object, keyed by the
|
|
78
|
-
* blok's returns (`blok.answer(values={'image': img})`). One declared argument,
|
|
79
|
-
* because a catalog operation names its arguments: the server refuses a call
|
|
80
|
-
* with keys its declaration lacks, and the returns differ per blok. Only a host
|
|
81
|
-
* showing an ask that still waits takes it; anywhere else nobody answers.
|
|
82
|
-
*/
|
|
83
|
-
const answerFunction = createBlokFunction({
|
|
84
|
-
name: BLOK_ANSWER_FUNCTION,
|
|
85
|
-
description: "Answers the task that asks with this blok. `values` is the answer, keyed by the blok's returns: blok.answer(values={'image': img}). Only where a task waits for the answer.",
|
|
86
|
-
returnType: 'void',
|
|
87
|
-
purity: 'effect',
|
|
88
|
-
schema: z.object({
|
|
89
|
-
values: recordSchema.describe("The answer, keyed by the blok's returns."),
|
|
90
|
-
}),
|
|
91
|
-
}, () => {
|
|
92
|
-
throw new Error('Nothing is waiting for an answer here.');
|
|
93
|
-
});
|
|
94
|
-
export const effectFunctions = [
|
|
95
|
-
answerFunction,
|
|
96
|
-
createLoggerFunction('info'),
|
|
97
|
-
createLoggerFunction('warn'),
|
|
98
|
-
createLoggerFunction('error'),
|
|
99
|
-
copyFunction,
|
|
100
|
-
toastFunction,
|
|
101
|
-
];
|
|
102
|
-
//# sourceMappingURL=effects.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"effects.js","sourceRoot":"","sources":["../../../src/renderer/functions/effects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OA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AAM;QACR,KAAK,OAAO;YACV,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACnC,MAAM;QACR;YACE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;AACH,CAAC,CACF,CAAC;AAEF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,kBAAkB,CACvC;IACE,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACT,6KAA6K;IAC/K,UAAU,EAAE,MAAM;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,0CAA0C,CAAC;KAC1E,CAAC;CACH,EACD,GAAG,EAAE;IACH,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC5D,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc;IACd,oBAAoB,CAAC,MAAM,CAAC;IAC5B,oBAAoB,CAAC,MAAM,CAAC;IAC5B,oBAAoB,CAAC,OAAO,CAAC;IAC7B,YAAY;IACZ,aAAa;CACd,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/renderer/functions/format.ts"],"names":[],"mappings":"AA6KA,eAAO,MAAM,eAAe,+CAS3B,CAAC"}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { createBlokFunction } from '../runtime/index.js';
|
|
3
|
-
import { integerSchema, numericSchema, textSchema } from './argumentSchemas.js';
|
|
4
|
-
/**
|
|
5
|
-
* Formatting runs through `Intl` with the viewer's own locale, so a dashboard
|
|
6
|
-
* renders in the reader's conventions rather than whatever the payload author
|
|
7
|
-
* hard-coded.
|
|
8
|
-
*/
|
|
9
|
-
const dateInputSchema = z.union([z.string(), z.number(), z.date()]).transform((value, ctx) => {
|
|
10
|
-
const parsed = value instanceof Date ? value : new Date(value);
|
|
11
|
-
if (Number.isNaN(parsed.getTime())) {
|
|
12
|
-
ctx.addIssue({
|
|
13
|
-
code: 'custom',
|
|
14
|
-
message: `Expected a date, received ${JSON.stringify(value)}.`,
|
|
15
|
-
});
|
|
16
|
-
return z.NEVER;
|
|
17
|
-
}
|
|
18
|
-
return parsed;
|
|
19
|
-
});
|
|
20
|
-
const numberFunction = createBlokFunction({
|
|
21
|
-
name: 'fmt.number',
|
|
22
|
-
description: 'Formats a number for the viewer locale.',
|
|
23
|
-
returnType: 'string',
|
|
24
|
-
purity: 'pure',
|
|
25
|
-
schema: z.object({
|
|
26
|
-
value: numericSchema,
|
|
27
|
-
minimumFractionDigits: integerSchema.optional(),
|
|
28
|
-
maximumFractionDigits: integerSchema.optional(),
|
|
29
|
-
}),
|
|
30
|
-
}, args => new Intl.NumberFormat(undefined, {
|
|
31
|
-
minimumFractionDigits: args.minimumFractionDigits,
|
|
32
|
-
maximumFractionDigits: args.maximumFractionDigits,
|
|
33
|
-
}).format(args.value));
|
|
34
|
-
const percentFunction = createBlokFunction({
|
|
35
|
-
name: 'fmt.percent',
|
|
36
|
-
description: 'Formats a 0–1 ratio as a percentage.',
|
|
37
|
-
returnType: 'string',
|
|
38
|
-
purity: 'pure',
|
|
39
|
-
schema: z.object({ value: numericSchema, precision: integerSchema.optional() }),
|
|
40
|
-
}, args => new Intl.NumberFormat(undefined, {
|
|
41
|
-
style: 'percent',
|
|
42
|
-
maximumFractionDigits: args.precision ?? 0,
|
|
43
|
-
}).format(args.value));
|
|
44
|
-
const currencyFunction = createBlokFunction({
|
|
45
|
-
name: 'fmt.currency',
|
|
46
|
-
description: 'Formats a number as a currency amount.',
|
|
47
|
-
returnType: 'string',
|
|
48
|
-
purity: 'pure',
|
|
49
|
-
schema: z.object({ value: numericSchema, currency: textSchema }),
|
|
50
|
-
}, args => new Intl.NumberFormat(undefined, { style: 'currency', currency: args.currency }).format(args.value));
|
|
51
|
-
const BYTE_UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
|
|
52
|
-
const bytesFunction = createBlokFunction({
|
|
53
|
-
name: 'fmt.bytes',
|
|
54
|
-
description: 'Formats a byte count with a unit suffix.',
|
|
55
|
-
returnType: 'string',
|
|
56
|
-
purity: 'pure',
|
|
57
|
-
schema: z.object({ value: numericSchema, precision: integerSchema.optional() }),
|
|
58
|
-
}, args => {
|
|
59
|
-
const sign = args.value < 0 ? '-' : '';
|
|
60
|
-
let remaining = Math.abs(args.value);
|
|
61
|
-
let unitIndex = 0;
|
|
62
|
-
while (remaining >= 1000 && unitIndex < BYTE_UNITS.length - 1) {
|
|
63
|
-
remaining /= 1000;
|
|
64
|
-
unitIndex += 1;
|
|
65
|
-
}
|
|
66
|
-
const precision = args.precision ?? (unitIndex === 0 ? 0 : 1);
|
|
67
|
-
return `${sign}${remaining.toFixed(precision)} ${BYTE_UNITS[unitIndex]}`;
|
|
68
|
-
});
|
|
69
|
-
const dateFunction = createBlokFunction({
|
|
70
|
-
name: 'fmt.date',
|
|
71
|
-
description: 'Formats a date for the viewer locale.',
|
|
72
|
-
returnType: 'string',
|
|
73
|
-
purity: 'pure',
|
|
74
|
-
schema: z.object({
|
|
75
|
-
value: dateInputSchema,
|
|
76
|
-
dateStyle: z.enum(['full', 'long', 'medium', 'short']).optional(),
|
|
77
|
-
}),
|
|
78
|
-
}, args => new Intl.DateTimeFormat(undefined, { dateStyle: args.dateStyle ?? 'medium' }).format(args.value));
|
|
79
|
-
const dateTimeFunction = createBlokFunction({
|
|
80
|
-
name: 'fmt.datetime',
|
|
81
|
-
description: 'Formats a date and time for the viewer locale.',
|
|
82
|
-
returnType: 'string',
|
|
83
|
-
purity: 'pure',
|
|
84
|
-
schema: z.object({
|
|
85
|
-
value: dateInputSchema,
|
|
86
|
-
dateStyle: z.enum(['full', 'long', 'medium', 'short']).optional(),
|
|
87
|
-
timeStyle: z.enum(['full', 'long', 'medium', 'short']).optional(),
|
|
88
|
-
}),
|
|
89
|
-
}, args => new Intl.DateTimeFormat(undefined, {
|
|
90
|
-
dateStyle: args.dateStyle ?? 'medium',
|
|
91
|
-
timeStyle: args.timeStyle ?? 'short',
|
|
92
|
-
}).format(args.value));
|
|
93
|
-
const RELATIVE_UNITS = [
|
|
94
|
-
{ unit: 'year', ms: 365 * 24 * 60 * 60 * 1000 },
|
|
95
|
-
{ unit: 'month', ms: 30 * 24 * 60 * 60 * 1000 },
|
|
96
|
-
{ unit: 'day', ms: 24 * 60 * 60 * 1000 },
|
|
97
|
-
{ unit: 'hour', ms: 60 * 60 * 1000 },
|
|
98
|
-
{ unit: 'minute', ms: 60 * 1000 },
|
|
99
|
-
{ unit: 'second', ms: 1000 },
|
|
100
|
-
];
|
|
101
|
-
const relativeTimeFunction = createBlokFunction({
|
|
102
|
-
name: 'fmt.relativeTime',
|
|
103
|
-
description: 'Formats a date relative to now ("3 hours ago").',
|
|
104
|
-
returnType: 'string',
|
|
105
|
-
// Reads the clock, so it is not referentially transparent — but it has no
|
|
106
|
-
// side effects, which is what `pure` gates. It refreshes when the node
|
|
107
|
-
// re-renders for another reason, not on a timer of its own.
|
|
108
|
-
purity: 'pure',
|
|
109
|
-
schema: z.object({ value: dateInputSchema }),
|
|
110
|
-
}, args => {
|
|
111
|
-
const deltaMs = args.value.getTime() - Date.now();
|
|
112
|
-
const formatter = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' });
|
|
113
|
-
const match = RELATIVE_UNITS.find(candidate => Math.abs(deltaMs) >= candidate.ms) ??
|
|
114
|
-
RELATIVE_UNITS[RELATIVE_UNITS.length - 1];
|
|
115
|
-
return formatter.format(Math.round(deltaMs / match.ms), match.unit);
|
|
116
|
-
});
|
|
117
|
-
const jsonFunction = createBlokFunction({
|
|
118
|
-
name: 'fmt.json',
|
|
119
|
-
description: 'Renders any value as JSON.',
|
|
120
|
-
returnType: 'string',
|
|
121
|
-
purity: 'pure',
|
|
122
|
-
schema: z.object({ value: z.unknown(), indent: integerSchema.optional() }),
|
|
123
|
-
}, args => JSON.stringify(args.value, null, args.indent ?? 0) ?? String(args.value));
|
|
124
|
-
export const formatFunctions = [
|
|
125
|
-
numberFunction,
|
|
126
|
-
percentFunction,
|
|
127
|
-
currencyFunction,
|
|
128
|
-
bytesFunction,
|
|
129
|
-
dateFunction,
|
|
130
|
-
dateTimeFunction,
|
|
131
|
-
relativeTimeFunction,
|
|
132
|
-
jsonFunction,
|
|
133
|
-
];
|
|
134
|
-
//# sourceMappingURL=format.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/renderer/functions/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,kBAAkB,EAAC,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAE3E;;;;GAIG;AAEH,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAC3F,MAAM,MAAM,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAE/D,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QACnC,GAAG,CAAC,QAAQ,CAAC;YACX,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,6BAA6B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG;SAC/D,C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