@fusedio/widget-sdk 0.1.0 → 0.2.0
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/bridge.js +14 -9
- package/dist/bundle.js +2 -2
- package/dist/define-catalog.d.ts +5 -3
- package/dist/define-catalog.js +4 -1
- package/dist/define-component.js +4 -1
- package/dist/form.js +18 -12
- package/dist/hooks/sql-source-overrides.d.ts +16 -0
- package/dist/hooks/sql-source-overrides.js +29 -0
- package/dist/hooks/use-allowed-sources.js +12 -9
- package/dist/hooks/use-allowed-udf-names.js +11 -8
- package/dist/hooks/use-canvas-params.js +12 -9
- package/dist/hooks/use-duckdb-sql.d.ts +1 -1
- package/dist/hooks/use-duckdb-sql.js +78 -58
- package/dist/hooks/use-fused-param-with-form.d.ts +18 -0
- package/dist/hooks/use-fused-param-with-form.js +56 -0
- package/dist/hooks/use-fused-param.js +34 -31
- package/dist/hooks/use-json-ui-edge-animation.js +6 -3
- package/dist/hooks/use-json-ui-log.js +23 -18
- package/dist/hooks/use-json-ui-udf-info.js +6 -3
- package/dist/hooks/use-param-substitution.js +25 -22
- package/dist/hooks/use-udf-output.js +33 -24
- package/dist/hooks/use-upload-access-check.js +9 -6
- package/dist/hooks/use-url-signing.js +22 -17
- package/dist/index.d.ts +3 -0
- package/dist/index.js +69 -19
- package/dist/protocol.js +8 -4
- package/dist/types.js +2 -1
- package/dist/utils/parse-style.d.ts +9 -0
- package/dist/utils/parse-style.js +27 -0
- package/dist/utils/sql-placeholders.js +36 -22
- package/package.json +2 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Pure parsing/substitution utilities for widget SQL strings.
|
|
3
4
|
*
|
|
@@ -10,15 +11,28 @@
|
|
|
10
11
|
* These helpers are also used by the host (workbench bridge) for VFS
|
|
11
12
|
* registration; lifting them into the SDK keeps a single source of truth.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SIGNABLE_URL_LITERAL_REGEX = exports.SQL_SOURCE_PLACEHOLDER_REGEX = exports.SQL_PARAM_REGEX = void 0;
|
|
16
|
+
exports.escapeSqlValue = escapeSqlValue;
|
|
17
|
+
exports.substituteSqlParams = substituteSqlParams;
|
|
18
|
+
exports.extractSqlParams = extractSqlParams;
|
|
19
|
+
exports.parseOverridesString = parseOverridesString;
|
|
20
|
+
exports.parseSqlUdfPlaceholders = parseSqlUdfPlaceholders;
|
|
21
|
+
exports.extractSignableUrls = extractSignableUrls;
|
|
22
|
+
exports.rewriteSignedUrls = rewriteSignedUrls;
|
|
23
|
+
exports.getDollarRefName = getDollarRefName;
|
|
24
|
+
exports.resolveOverrideValue = resolveOverrideValue;
|
|
25
|
+
exports.canonicalOverrideKey = canonicalOverrideKey;
|
|
26
|
+
exports.computePlaceholderKey = computePlaceholderKey;
|
|
27
|
+
exports.SQL_PARAM_REGEX = /\$([a-zA-Z_][a-zA-Z0-9_]*)/g;
|
|
28
|
+
exports.SQL_SOURCE_PLACEHOLDER_REGEX = /\{\{(\w+)(?:\?([^}]*))?\}\}/g;
|
|
15
29
|
/**
|
|
16
30
|
* Matches `'scheme://...'` literals inside a SQL string. We deliberately
|
|
17
31
|
* limit to single-quoted string literals so that bare identifiers or
|
|
18
32
|
* comments containing a URL-like token aren't treated as paths to sign.
|
|
19
33
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
exports.SIGNABLE_URL_LITERAL_REGEX = /'((?:s3|gs|fd):\/\/[^'\n]+)'/g;
|
|
35
|
+
function escapeSqlValue(value) {
|
|
22
36
|
if (value == null)
|
|
23
37
|
return "''";
|
|
24
38
|
if (typeof value === "number" && !Number.isNaN(value))
|
|
@@ -46,8 +60,8 @@ function isInsideSingleQuotedSqlString(sql, offset) {
|
|
|
46
60
|
* `$param` lives inside a single-quoted string literal, only the raw
|
|
47
61
|
* quote-escaped value is spliced in so we don't add nested quotes.
|
|
48
62
|
*/
|
|
49
|
-
|
|
50
|
-
return sql.replace(SQL_PARAM_REGEX, (_match, paramName, offset) => {
|
|
63
|
+
function substituteSqlParams(sql, paramValues) {
|
|
64
|
+
return sql.replace(exports.SQL_PARAM_REGEX, (_match, paramName, offset) => {
|
|
51
65
|
const value = paramValues[paramName];
|
|
52
66
|
const raw = value == null ? "" : String(value);
|
|
53
67
|
if (isInsideSingleQuotedSqlString(sql, offset)) {
|
|
@@ -57,11 +71,11 @@ export function substituteSqlParams(sql, paramValues) {
|
|
|
57
71
|
});
|
|
58
72
|
}
|
|
59
73
|
/** Extract all SQL parameter names from `$param_name` references. */
|
|
60
|
-
|
|
74
|
+
function extractSqlParams(sql) {
|
|
61
75
|
const seen = new Set();
|
|
62
76
|
const out = [];
|
|
63
|
-
SQL_PARAM_REGEX.lastIndex = 0;
|
|
64
|
-
for (const m of sql.matchAll(SQL_PARAM_REGEX)) {
|
|
77
|
+
exports.SQL_PARAM_REGEX.lastIndex = 0;
|
|
78
|
+
for (const m of sql.matchAll(exports.SQL_PARAM_REGEX)) {
|
|
65
79
|
const name = m[1];
|
|
66
80
|
if (seen.has(name))
|
|
67
81
|
continue;
|
|
@@ -70,7 +84,7 @@ export function extractSqlParams(sql) {
|
|
|
70
84
|
}
|
|
71
85
|
return out;
|
|
72
86
|
}
|
|
73
|
-
|
|
87
|
+
function parseOverridesString(rawOverrides) {
|
|
74
88
|
if (!rawOverrides)
|
|
75
89
|
return null;
|
|
76
90
|
const result = {};
|
|
@@ -105,11 +119,11 @@ export function parseOverridesString(rawOverrides) {
|
|
|
105
119
|
* occurrences in source order, preserving duplicates so callers can
|
|
106
120
|
* substitute by start/end offsets.
|
|
107
121
|
*/
|
|
108
|
-
|
|
122
|
+
function parseSqlUdfPlaceholders(sql) {
|
|
109
123
|
const placeholders = [];
|
|
110
124
|
let match;
|
|
111
|
-
SQL_SOURCE_PLACEHOLDER_REGEX.lastIndex = 0;
|
|
112
|
-
while ((match = SQL_SOURCE_PLACEHOLDER_REGEX.exec(sql)) !== null) {
|
|
125
|
+
exports.SQL_SOURCE_PLACEHOLDER_REGEX.lastIndex = 0;
|
|
126
|
+
while ((match = exports.SQL_SOURCE_PLACEHOLDER_REGEX.exec(sql)) !== null) {
|
|
113
127
|
const [fullMatch, name, rawOverrides] = match;
|
|
114
128
|
placeholders.push({
|
|
115
129
|
match: fullMatch,
|
|
@@ -125,14 +139,14 @@ export function parseSqlUdfPlaceholders(sql) {
|
|
|
125
139
|
* Extract every signable URL appearing as a single-quoted string literal,
|
|
126
140
|
* deduped, in first-occurrence order.
|
|
127
141
|
*/
|
|
128
|
-
|
|
142
|
+
function extractSignableUrls(sql) {
|
|
129
143
|
if (!sql)
|
|
130
144
|
return [];
|
|
131
145
|
const seen = new Set();
|
|
132
146
|
const out = [];
|
|
133
|
-
SIGNABLE_URL_LITERAL_REGEX.lastIndex = 0;
|
|
147
|
+
exports.SIGNABLE_URL_LITERAL_REGEX.lastIndex = 0;
|
|
134
148
|
let match;
|
|
135
|
-
while ((match = SIGNABLE_URL_LITERAL_REGEX.exec(sql)) !== null) {
|
|
149
|
+
while ((match = exports.SIGNABLE_URL_LITERAL_REGEX.exec(sql)) !== null) {
|
|
136
150
|
const url = match[1];
|
|
137
151
|
if (!seen.has(url)) {
|
|
138
152
|
seen.add(url);
|
|
@@ -146,10 +160,10 @@ export function extractSignableUrls(sql) {
|
|
|
146
160
|
* from `signedMap`. Literals whose URL is missing from the map are left
|
|
147
161
|
* untouched.
|
|
148
162
|
*/
|
|
149
|
-
|
|
163
|
+
function rewriteSignedUrls(sql, signedMap) {
|
|
150
164
|
if (!sql)
|
|
151
165
|
return sql;
|
|
152
|
-
return sql.replace(SIGNABLE_URL_LITERAL_REGEX, (literal, url) => {
|
|
166
|
+
return sql.replace(exports.SIGNABLE_URL_LITERAL_REGEX, (literal, url) => {
|
|
153
167
|
const signed = signedMap[url];
|
|
154
168
|
if (!signed)
|
|
155
169
|
return literal;
|
|
@@ -161,7 +175,7 @@ export function rewriteSignedUrls(sql, signedMap) {
|
|
|
161
175
|
// ============================================================================
|
|
162
176
|
const DOLLAR_REF_RE = /^\$([a-zA-Z_][a-zA-Z0-9_]*)$/;
|
|
163
177
|
/** Return the param name if `value` is a single `$name` reference. */
|
|
164
|
-
|
|
178
|
+
function getDollarRefName(value) {
|
|
165
179
|
const trimmed = value.trim();
|
|
166
180
|
const m = DOLLAR_REF_RE.exec(trimmed);
|
|
167
181
|
return m ? m[1] : null;
|
|
@@ -172,7 +186,7 @@ export function getDollarRefName(value) {
|
|
|
172
186
|
* missing entirely (key not in the map), marks the result as `unresolved`
|
|
173
187
|
* so callers can keep the placeholder pending until upstream params settle.
|
|
174
188
|
*/
|
|
175
|
-
|
|
189
|
+
function resolveOverrideValue(rawValue, paramValues) {
|
|
176
190
|
const m = DOLLAR_REF_RE.exec(rawValue);
|
|
177
191
|
if (!m) {
|
|
178
192
|
return { value: rawValue, unresolved: false };
|
|
@@ -191,13 +205,13 @@ export function resolveOverrideValue(rawValue, paramValues) {
|
|
|
191
205
|
* Canonical registry key for `(name, overrides)`. Bare placeholders use the
|
|
192
206
|
* name alone; overrides are sorted by key and joined with `&`.
|
|
193
207
|
*/
|
|
194
|
-
|
|
208
|
+
function canonicalOverrideKey(overrides) {
|
|
195
209
|
return Object.keys(overrides)
|
|
196
210
|
.sort()
|
|
197
211
|
.map((k) => `${k}=${overrides[k]}`)
|
|
198
212
|
.join("&");
|
|
199
213
|
}
|
|
200
|
-
|
|
214
|
+
function computePlaceholderKey(name, overrides) {
|
|
201
215
|
if (!overrides)
|
|
202
216
|
return name;
|
|
203
217
|
return `${name}#${canonicalOverrideKey(overrides)}`;
|
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusedio/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "SDK for building custom json-ui components for the Fused workbench",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"main": "dist/index.js",
|
|
8
7
|
"types": "dist/index.d.ts",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
10
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"
|
|
11
|
+
"default": "./dist/index.js"
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
14
|
"files": [
|