juxscript 1.1.245 → 1.1.246
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/lib/components/dataframe.d.ts +1 -0
- package/dist/lib/components/dataframe.d.ts.map +1 -0
- package/dist/lib/components/dataframe.js +1 -0
- package/dist/lib/components/include.d.ts +86 -0
- package/dist/lib/components/include.d.ts.map +1 -0
- package/{lib/components/include.ts → dist/lib/components/include.js} +57 -100
- package/dist/lib/components/tag.d.ts +27 -0
- package/dist/lib/components/tag.d.ts.map +1 -0
- package/{lib/components/tag.ts → dist/lib/components/tag.js} +14 -25
- package/dist/lib/index.d.ts +17 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/{index.js → dist/lib/index.js} +4 -2
- package/dist/lib/utils/codeparser.d.ts +29 -0
- package/dist/lib/utils/codeparser.d.ts.map +1 -0
- package/{lib/utils/codeparser.ts → dist/lib/utils/codeparser.js} +64 -91
- package/dist/lib/utils/fetch.d.ts +176 -0
- package/dist/lib/utils/fetch.d.ts.map +1 -0
- package/{lib/utils/fetch.ts → dist/lib/utils/fetch.js} +80 -206
- package/dist/lib/utils/formatId.d.ts +16 -0
- package/dist/lib/utils/formatId.d.ts.map +1 -0
- package/{lib/utils/formatId.ts → dist/lib/utils/formatId.js} +7 -8
- package/dist/lib/utils/idgen.d.ts +2 -0
- package/dist/lib/utils/idgen.d.ts.map +1 -0
- package/{lib/utils/idgen.ts → dist/lib/utils/idgen.js} +2 -4
- package/package.json +2 -7
- package/lib/components/dataframe.ts +0 -0
- package/lib/styles/animations.css +0 -218
- package/lib/styles/foundation.css +0 -542
- package/lib/styles/gradients.css +0 -326
- package/lib/styles/link.css +0 -158
- package/lib/styles/modal.css +0 -402
- package/lib/styles/modifiers.css +0 -103
- package/lib/styles/nav.css +0 -322
- package/lib/styles/shadcn.css +0 -960
- package/lib/styles/stacks.css +0 -132
- package/lib/styles/themes.css +0 -486
|
@@ -12,18 +12,15 @@ const KEYWORDS = new Set([
|
|
|
12
12
|
'!=', '!==', '+', '-', '*', '/', '%', '++', '--', '&&', '||', '!', '<', '>',
|
|
13
13
|
'<=', '>=', '=>', '...', '.', ',', '(', ')', '{', '}', '[', ']', ':', '?'
|
|
14
14
|
]);
|
|
15
|
-
|
|
16
15
|
/**
|
|
17
16
|
* Categorized token sets for semantic highlighting
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
18
|
// Control flow keywords (loops, conditionals, etc.)
|
|
21
19
|
const CONTROL_FLOW = new Set([
|
|
22
20
|
'if', 'else', 'switch', 'case', 'default',
|
|
23
21
|
'for', 'while', 'do', 'break', 'continue',
|
|
24
22
|
'return', 'throw', 'try', 'catch', 'finally'
|
|
25
23
|
]);
|
|
26
|
-
|
|
27
24
|
// Declaration keywords
|
|
28
25
|
const DECLARATIONS = new Set([
|
|
29
26
|
'const', 'let', 'var', 'function', 'class',
|
|
@@ -31,23 +28,19 @@ const DECLARATIONS = new Set([
|
|
|
31
28
|
'interface', 'type', 'enum', 'namespace',
|
|
32
29
|
'static', 'get', 'set', 'extends'
|
|
33
30
|
]);
|
|
34
|
-
|
|
35
31
|
// Operator keywords
|
|
36
32
|
const OPERATORS = new Set([
|
|
37
33
|
'new', 'delete', 'typeof', 'instanceof',
|
|
38
34
|
'void', 'await', 'yield', 'in', 'of'
|
|
39
35
|
]);
|
|
40
|
-
|
|
41
36
|
// Special keywords
|
|
42
37
|
const SPECIAL = new Set([
|
|
43
38
|
'this', 'super', 'async', 'debugger', 'with'
|
|
44
39
|
]);
|
|
45
|
-
|
|
46
40
|
// JUX-specific keywords
|
|
47
41
|
const JUX_KEYWORDS = new Set([
|
|
48
42
|
'jux', 'state', 'registry', 'render', 'bind', 'sync'
|
|
49
43
|
]);
|
|
50
|
-
|
|
51
44
|
// Combine all keywords for quick lookup
|
|
52
45
|
const ALL_KEYWORDS = new Set([
|
|
53
46
|
...CONTROL_FLOW,
|
|
@@ -56,17 +49,10 @@ const ALL_KEYWORDS = new Set([
|
|
|
56
49
|
...SPECIAL,
|
|
57
50
|
...JUX_KEYWORDS
|
|
58
51
|
]);
|
|
59
|
-
|
|
60
|
-
export interface ParsedLine {
|
|
61
|
-
lineNumber: number;
|
|
62
|
-
html: string;
|
|
63
|
-
raw: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
52
|
/**
|
|
67
53
|
* Escape HTML entities
|
|
68
54
|
*/
|
|
69
|
-
function escapeHtml(text
|
|
55
|
+
function escapeHtml(text) {
|
|
70
56
|
return text
|
|
71
57
|
.replace(/&/g, '&')
|
|
72
58
|
.replace(/</g, '<')
|
|
@@ -74,110 +60,116 @@ function escapeHtml(text: string): string {
|
|
|
74
60
|
.replace(/"/g, '"')
|
|
75
61
|
.replace(/'/g, ''');
|
|
76
62
|
}
|
|
77
|
-
|
|
78
63
|
/**
|
|
79
64
|
* Parse code into lines - CHARACTER-BY-CHARACTER TOKENIZATION
|
|
80
65
|
*/
|
|
81
|
-
export function parseCode(code
|
|
66
|
+
export function parseCode(code, language = 'javascript') {
|
|
82
67
|
const lines = code.split('\n');
|
|
83
|
-
|
|
84
68
|
return lines.map((line, index) => ({
|
|
85
69
|
lineNumber: index + 1,
|
|
86
70
|
html: tokenizeLine(line),
|
|
87
71
|
raw: line
|
|
88
72
|
}));
|
|
89
73
|
}
|
|
90
|
-
|
|
91
74
|
/**
|
|
92
75
|
* Get the appropriate CSS class for a keyword
|
|
93
76
|
*/
|
|
94
|
-
function getKeywordClass(word
|
|
95
|
-
if (CONTROL_FLOW.has(word))
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
if (
|
|
77
|
+
function getKeywordClass(word) {
|
|
78
|
+
if (CONTROL_FLOW.has(word))
|
|
79
|
+
return 'token-control';
|
|
80
|
+
if (DECLARATIONS.has(word))
|
|
81
|
+
return 'token-declaration';
|
|
82
|
+
if (OPERATORS.has(word))
|
|
83
|
+
return 'token-operator-keyword';
|
|
84
|
+
if (SPECIAL.has(word))
|
|
85
|
+
return 'token-special';
|
|
86
|
+
if (JUX_KEYWORDS.has(word))
|
|
87
|
+
return 'token-jux';
|
|
100
88
|
return 'token-keyword'; // fallback
|
|
101
89
|
}
|
|
102
|
-
|
|
103
90
|
/**
|
|
104
91
|
* Check if character is a structural punctuation (braces, brackets, parens)
|
|
105
92
|
*/
|
|
106
|
-
function isStructural(char
|
|
93
|
+
function isStructural(char) {
|
|
107
94
|
return '(){}[]'.includes(char);
|
|
108
95
|
}
|
|
109
|
-
|
|
110
96
|
/**
|
|
111
97
|
* Check if character is a delimiter (semicolon, comma, colon)
|
|
112
98
|
*/
|
|
113
|
-
function isDelimiter(char
|
|
99
|
+
function isDelimiter(char) {
|
|
114
100
|
return ';,:'.includes(char);
|
|
115
101
|
}
|
|
116
|
-
|
|
117
102
|
/**
|
|
118
103
|
* Check if character is an operator
|
|
119
104
|
*/
|
|
120
|
-
function isOperator(char
|
|
105
|
+
function isOperator(char) {
|
|
121
106
|
return '+-*/%=<>!&|^~?'.includes(char);
|
|
122
107
|
}
|
|
123
|
-
|
|
124
108
|
/**
|
|
125
109
|
* Check if character starts a multi-char operator
|
|
126
110
|
*/
|
|
127
|
-
function consumeOperator(line
|
|
111
|
+
function consumeOperator(line, i) {
|
|
128
112
|
const char = line[i];
|
|
129
113
|
const next = line[i + 1];
|
|
130
114
|
const next2 = line[i + 2];
|
|
131
|
-
|
|
132
115
|
// Three-char operators
|
|
133
|
-
if (char === '=' && next === '=' && next2 === '=')
|
|
134
|
-
|
|
135
|
-
if (char === '
|
|
136
|
-
|
|
116
|
+
if (char === '=' && next === '=' && next2 === '=')
|
|
117
|
+
return '===';
|
|
118
|
+
if (char === '!' && next === '=' && next2 === '=')
|
|
119
|
+
return '!==';
|
|
120
|
+
if (char === '>' && next === '>' && next2 === '>')
|
|
121
|
+
return '>>>';
|
|
137
122
|
// Two-char operators
|
|
138
|
-
if (char === '=' && next === '=')
|
|
139
|
-
|
|
140
|
-
if (char === '
|
|
141
|
-
|
|
142
|
-
if (char === '
|
|
143
|
-
|
|
144
|
-
if (char === '
|
|
145
|
-
|
|
146
|
-
if (char === '
|
|
147
|
-
|
|
148
|
-
if (char === '
|
|
149
|
-
|
|
150
|
-
if (char === '
|
|
151
|
-
|
|
123
|
+
if (char === '=' && next === '=')
|
|
124
|
+
return '==';
|
|
125
|
+
if (char === '!' && next === '=')
|
|
126
|
+
return '!=';
|
|
127
|
+
if (char === '<' && next === '=')
|
|
128
|
+
return '<=';
|
|
129
|
+
if (char === '>' && next === '=')
|
|
130
|
+
return '>=';
|
|
131
|
+
if (char === '&' && next === '&')
|
|
132
|
+
return '&&';
|
|
133
|
+
if (char === '|' && next === '|')
|
|
134
|
+
return '||';
|
|
135
|
+
if (char === '+' && next === '+')
|
|
136
|
+
return '++';
|
|
137
|
+
if (char === '-' && next === '-')
|
|
138
|
+
return '--';
|
|
139
|
+
if (char === '=' && next === '>')
|
|
140
|
+
return '=>';
|
|
141
|
+
if (char === '>' && next === '>')
|
|
142
|
+
return '>>';
|
|
143
|
+
if (char === '<' && next === '<')
|
|
144
|
+
return '<<';
|
|
145
|
+
if (char === '*' && next === '*')
|
|
146
|
+
return '**';
|
|
147
|
+
if (char === '.' && next === '.' && next2 === '.')
|
|
148
|
+
return '...';
|
|
152
149
|
// Single-char operator
|
|
153
150
|
return char;
|
|
154
151
|
}
|
|
155
|
-
|
|
156
152
|
/**
|
|
157
153
|
* Tokenize a single line character-by-character with semantic categories
|
|
158
154
|
*/
|
|
159
|
-
function tokenizeLine(line
|
|
160
|
-
if (!line.trim())
|
|
161
|
-
|
|
155
|
+
function tokenizeLine(line) {
|
|
156
|
+
if (!line.trim())
|
|
157
|
+
return ' ';
|
|
162
158
|
let result = '';
|
|
163
159
|
let i = 0;
|
|
164
160
|
const len = line.length;
|
|
165
|
-
|
|
166
161
|
// Check for comment at start
|
|
167
162
|
if (line.trim().startsWith('//')) {
|
|
168
163
|
return `<span class="token-comment">${escapeHtml(line)}</span>`;
|
|
169
164
|
}
|
|
170
|
-
|
|
171
165
|
while (i < len) {
|
|
172
166
|
const char = line[i];
|
|
173
|
-
|
|
174
167
|
// Whitespace - preserve
|
|
175
168
|
if (/\s/.test(char)) {
|
|
176
169
|
result += char;
|
|
177
170
|
i++;
|
|
178
171
|
continue;
|
|
179
172
|
}
|
|
180
|
-
|
|
181
173
|
// Comment (// or /* */)
|
|
182
174
|
if (char === '/' && i + 1 < len) {
|
|
183
175
|
if (line[i + 1] === '/') {
|
|
@@ -185,7 +177,8 @@ function tokenizeLine(line: string): string {
|
|
|
185
177
|
const comment = line.slice(i);
|
|
186
178
|
result += `<span class="token-comment">${escapeHtml(comment)}</span>`;
|
|
187
179
|
break;
|
|
188
|
-
}
|
|
180
|
+
}
|
|
181
|
+
else if (line[i + 1] === '*') {
|
|
189
182
|
// Block comment start
|
|
190
183
|
const commentEnd = line.indexOf('*/', i + 2);
|
|
191
184
|
if (commentEnd !== -1) {
|
|
@@ -196,12 +189,10 @@ function tokenizeLine(line: string): string {
|
|
|
196
189
|
}
|
|
197
190
|
}
|
|
198
191
|
}
|
|
199
|
-
|
|
200
192
|
// String literals (single, double, backtick)
|
|
201
193
|
if (char === '"' || char === "'" || char === '`') {
|
|
202
194
|
let j = i + 1;
|
|
203
195
|
let escaped = false;
|
|
204
|
-
|
|
205
196
|
// Find matching quote
|
|
206
197
|
while (j < len) {
|
|
207
198
|
if (escaped) {
|
|
@@ -209,43 +200,36 @@ function tokenizeLine(line: string): string {
|
|
|
209
200
|
j++;
|
|
210
201
|
continue;
|
|
211
202
|
}
|
|
212
|
-
|
|
213
203
|
if (line[j] === '\\') {
|
|
214
204
|
escaped = true;
|
|
215
205
|
j++;
|
|
216
206
|
continue;
|
|
217
207
|
}
|
|
218
|
-
|
|
219
208
|
if (line[j] === char) {
|
|
220
209
|
j++;
|
|
221
210
|
break;
|
|
222
211
|
}
|
|
223
|
-
|
|
224
212
|
j++;
|
|
225
213
|
}
|
|
226
|
-
|
|
227
214
|
const str = line.slice(i, j);
|
|
228
215
|
result += `<span class="token-string">${escapeHtml(str)}</span>`;
|
|
229
216
|
i = j;
|
|
230
217
|
continue;
|
|
231
218
|
}
|
|
232
|
-
|
|
233
219
|
// Word (identifier or keyword)
|
|
234
220
|
if (/[a-zA-Z_$]/.test(char)) {
|
|
235
221
|
const word = consumeWord(line, i);
|
|
236
222
|
const escaped = escapeHtml(word);
|
|
237
|
-
|
|
238
223
|
if (ALL_KEYWORDS.has(word)) {
|
|
239
224
|
const tokenClass = getKeywordClass(word);
|
|
240
225
|
result += `<span class="${tokenClass}">${escaped}</span>`;
|
|
241
|
-
}
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
242
228
|
result += escaped;
|
|
243
229
|
}
|
|
244
|
-
|
|
245
230
|
i += word.length;
|
|
246
231
|
continue;
|
|
247
232
|
}
|
|
248
|
-
|
|
249
233
|
// Number
|
|
250
234
|
if (/\d/.test(char)) {
|
|
251
235
|
const num = consumeNumber(line, i);
|
|
@@ -253,7 +237,6 @@ function tokenizeLine(line: string): string {
|
|
|
253
237
|
i += num.length;
|
|
254
238
|
continue;
|
|
255
239
|
}
|
|
256
|
-
|
|
257
240
|
// Operators (multi-char)
|
|
258
241
|
if (isOperator(char)) {
|
|
259
242
|
const op = consumeOperator(line, i);
|
|
@@ -261,74 +244,65 @@ function tokenizeLine(line: string): string {
|
|
|
261
244
|
i += op.length;
|
|
262
245
|
continue;
|
|
263
246
|
}
|
|
264
|
-
|
|
265
247
|
// Structural punctuation (braces, brackets, parens)
|
|
266
248
|
if (isStructural(char)) {
|
|
267
249
|
result += `<span class="token-structural">${escapeHtml(char)}</span>`;
|
|
268
250
|
i++;
|
|
269
251
|
continue;
|
|
270
252
|
}
|
|
271
|
-
|
|
272
253
|
// Delimiters (semicolon, comma, colon)
|
|
273
254
|
if (isDelimiter(char)) {
|
|
274
255
|
result += `<span class="token-delimiter">${escapeHtml(char)}</span>`;
|
|
275
256
|
i++;
|
|
276
257
|
continue;
|
|
277
258
|
}
|
|
278
|
-
|
|
279
259
|
// Everything else - just escape and append
|
|
280
260
|
result += escapeHtml(char);
|
|
281
261
|
i++;
|
|
282
262
|
}
|
|
283
|
-
|
|
284
263
|
return result || ' ';
|
|
285
264
|
}
|
|
286
|
-
|
|
287
265
|
/**
|
|
288
266
|
* Consume a complete word (identifier)
|
|
289
267
|
*/
|
|
290
|
-
function consumeWord(line
|
|
268
|
+
function consumeWord(line, start) {
|
|
291
269
|
let i = start;
|
|
292
270
|
while (i < line.length && /[a-zA-Z0-9_$]/.test(line[i])) {
|
|
293
271
|
i++;
|
|
294
272
|
}
|
|
295
273
|
return line.substring(start, i);
|
|
296
274
|
}
|
|
297
|
-
|
|
298
275
|
/**
|
|
299
276
|
* Consume a complete number
|
|
300
277
|
*/
|
|
301
|
-
function consumeNumber(line
|
|
278
|
+
function consumeNumber(line, start) {
|
|
302
279
|
let i = start;
|
|
303
280
|
let hasDot = false;
|
|
304
|
-
|
|
305
281
|
while (i < line.length) {
|
|
306
282
|
const char = line[i];
|
|
307
|
-
|
|
308
283
|
if (/\d/.test(char)) {
|
|
309
284
|
i++;
|
|
310
|
-
}
|
|
285
|
+
}
|
|
286
|
+
else if (char === '.' && !hasDot) {
|
|
311
287
|
hasDot = true;
|
|
312
288
|
i++;
|
|
313
|
-
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
314
291
|
break;
|
|
315
292
|
}
|
|
316
293
|
}
|
|
317
|
-
|
|
318
294
|
return line.substring(start, i);
|
|
319
295
|
}
|
|
320
|
-
|
|
321
296
|
/**
|
|
322
297
|
* Render a parsed line
|
|
323
298
|
*/
|
|
324
|
-
export function renderLineWithTokens(parsedLine
|
|
299
|
+
export function renderLineWithTokens(parsedLine) {
|
|
325
300
|
return parsedLine.html;
|
|
326
301
|
}
|
|
327
|
-
|
|
328
302
|
/**
|
|
329
303
|
* Generate CSS for syntax highlighting
|
|
330
304
|
*/
|
|
331
|
-
export function getSyntaxHighlightCSS()
|
|
305
|
+
export function getSyntaxHighlightCSS() {
|
|
332
306
|
return `
|
|
333
307
|
/* Semantic Code Highlighting */
|
|
334
308
|
.jux-code {
|
|
@@ -427,7 +401,6 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
427
401
|
}
|
|
428
402
|
`;
|
|
429
403
|
}
|
|
430
|
-
|
|
431
404
|
export default {
|
|
432
405
|
parse: parseCode,
|
|
433
406
|
renderLine: renderLineWithTokens,
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jux Fetch Utility
|
|
3
|
+
*
|
|
4
|
+
* A lightweight fetch wrapper with sensible defaults, error handling, and method chaining.
|
|
5
|
+
* Includes configuration helpers for juxconfig.js integration.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* // Configure once (optional)
|
|
9
|
+
* jux.fetch.config({
|
|
10
|
+
* baseUrl: 'https://api.example.com',
|
|
11
|
+
* credentials: 'include',
|
|
12
|
+
* timeout: 10000,
|
|
13
|
+
* log: 'errors',
|
|
14
|
+
* onUnauthorized: () => window.location.href = '/login'
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Simple GET
|
|
18
|
+
* const { data, error } = await jux.fetch('/users').send();
|
|
19
|
+
*
|
|
20
|
+
* // Method chaining
|
|
21
|
+
* const { data, error } = await jux.fetch('/users')
|
|
22
|
+
* .method('POST')
|
|
23
|
+
* .body({ name: 'John' })
|
|
24
|
+
* .params({ limit: 10 })
|
|
25
|
+
* .timeout(5000)
|
|
26
|
+
* .log(true)
|
|
27
|
+
* .send();
|
|
28
|
+
*
|
|
29
|
+
* // With juxconfig services
|
|
30
|
+
* const { data } = await jux.fetch('/users')
|
|
31
|
+
* .baseUrl(jux.fetch.getServiceUrl('database'))
|
|
32
|
+
* .send();
|
|
33
|
+
*
|
|
34
|
+
* // Service client helper
|
|
35
|
+
* const db = jux.fetch.serviceClient('database');
|
|
36
|
+
* const { data } = await db.fetch('/users').send();
|
|
37
|
+
*/
|
|
38
|
+
export type LogLevel = boolean | 'errors';
|
|
39
|
+
export interface FetchConfig {
|
|
40
|
+
baseUrl?: string;
|
|
41
|
+
credentials?: RequestCredentials;
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
timeout?: number;
|
|
44
|
+
log?: LogLevel;
|
|
45
|
+
onUnauthorized?: () => void;
|
|
46
|
+
onError?: (error: FetchError) => void;
|
|
47
|
+
}
|
|
48
|
+
export interface FetchOptions extends Omit<RequestInit, 'body'> {
|
|
49
|
+
params?: Record<string, any>;
|
|
50
|
+
body?: any;
|
|
51
|
+
timeout?: number;
|
|
52
|
+
log?: LogLevel;
|
|
53
|
+
onUnauthorized?: () => void;
|
|
54
|
+
onError?: (error: FetchError) => void;
|
|
55
|
+
parseResponse?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface FetchError {
|
|
58
|
+
message: string;
|
|
59
|
+
status?: number;
|
|
60
|
+
statusText?: string;
|
|
61
|
+
data?: any;
|
|
62
|
+
}
|
|
63
|
+
export interface FetchResult<T = any> {
|
|
64
|
+
data: T | null;
|
|
65
|
+
error: FetchError | null;
|
|
66
|
+
status: number;
|
|
67
|
+
response: Response;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Configure global fetch defaults
|
|
71
|
+
*/
|
|
72
|
+
export declare function configureFetch(config: FetchConfig): void;
|
|
73
|
+
/**
|
|
74
|
+
* FetchBuilder class for method chaining
|
|
75
|
+
*/
|
|
76
|
+
declare class FetchBuilder<T = any> {
|
|
77
|
+
url: string;
|
|
78
|
+
options: FetchOptions;
|
|
79
|
+
constructor(url: string, options?: FetchOptions);
|
|
80
|
+
method(value: string): this;
|
|
81
|
+
body(value: any): this;
|
|
82
|
+
params(value: Record<string, any>): this;
|
|
83
|
+
headers(value: Record<string, string>): this;
|
|
84
|
+
header(key: string, value: string): this;
|
|
85
|
+
timeout(value: number): this;
|
|
86
|
+
credentials(value: RequestCredentials): this;
|
|
87
|
+
log(value: LogLevel): this;
|
|
88
|
+
parseResponse(value: boolean): this;
|
|
89
|
+
onUnauthorized(callback: () => void): this;
|
|
90
|
+
onError(callback: (error: FetchError) => void): this;
|
|
91
|
+
/**
|
|
92
|
+
* Execute the fetch request
|
|
93
|
+
*/
|
|
94
|
+
send(): Promise<FetchResult<T>>;
|
|
95
|
+
/**
|
|
96
|
+
* Alias for send()
|
|
97
|
+
*/
|
|
98
|
+
fetch(): Promise<FetchResult<T>>;
|
|
99
|
+
/**
|
|
100
|
+
* Make the builder thenable (Promise-like) so it can be awaited directly
|
|
101
|
+
* This allows: await jux.fetch('/users') without needing .send()
|
|
102
|
+
*/
|
|
103
|
+
then<TResult1 = FetchResult<T>, TResult2 = never>(onfulfilled?: ((value: FetchResult<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
104
|
+
/**
|
|
105
|
+
* Make the builder catchable for Promise.catch()
|
|
106
|
+
*/
|
|
107
|
+
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<FetchResult<T> | TResult>;
|
|
108
|
+
/**
|
|
109
|
+
* Make the builder finally-able for Promise.finally()
|
|
110
|
+
*/
|
|
111
|
+
finally(onfinally?: (() => void) | null): Promise<FetchResult<T>>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create a fetch builder
|
|
115
|
+
*/
|
|
116
|
+
export declare function juxFetch<T = any>(url: string, options?: FetchOptions): FetchBuilder<T>;
|
|
117
|
+
/**
|
|
118
|
+
* Convenience methods for common HTTP verbs
|
|
119
|
+
*/
|
|
120
|
+
export declare const fetchHelpers: {
|
|
121
|
+
get: <T = any>(url: string, options?: Omit<FetchOptions, "method">) => FetchBuilder<T>;
|
|
122
|
+
post: <T = any>(url: string, body?: any, options?: Omit<FetchOptions, "method" | "body">) => FetchBuilder<T>;
|
|
123
|
+
put: <T = any>(url: string, body?: any, options?: Omit<FetchOptions, "method" | "body">) => FetchBuilder<T>;
|
|
124
|
+
patch: <T = any>(url: string, body?: any, options?: Omit<FetchOptions, "method" | "body">) => FetchBuilder<T>;
|
|
125
|
+
delete: <T = any>(url: string, options?: Omit<FetchOptions, "method">) => FetchBuilder<T>;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Fetch multiple URLs in parallel
|
|
129
|
+
*/
|
|
130
|
+
export declare function fetchAll<T = any>(urls: string[], options?: FetchOptions): Promise<FetchResult<T>[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Get a service URL from window.juxConfig
|
|
133
|
+
*/
|
|
134
|
+
export declare function getServiceUrl(serviceName: string): string | null;
|
|
135
|
+
/**
|
|
136
|
+
* Create a fetch instance preconfigured for a specific service
|
|
137
|
+
*
|
|
138
|
+
* Usage:
|
|
139
|
+
* const api = jux.fetch.serviceClient('database');
|
|
140
|
+
* const { data } = await api.fetch('/users').send();
|
|
141
|
+
*/
|
|
142
|
+
export declare function serviceClient(serviceName: string): {
|
|
143
|
+
fetch: (url: string, options?: any) => FetchBuilder<any>;
|
|
144
|
+
baseUrl: string | null;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Setup fetch from juxconfig
|
|
148
|
+
* Call this in your bootstrap function
|
|
149
|
+
*
|
|
150
|
+
* Usage:
|
|
151
|
+
* export default {
|
|
152
|
+
* bootstrap: [
|
|
153
|
+
* async function initFetch() {
|
|
154
|
+
* await jux.fetch.setupConfig();
|
|
155
|
+
* }
|
|
156
|
+
* ]
|
|
157
|
+
* };
|
|
158
|
+
*/
|
|
159
|
+
export declare function setupConfig(): Promise<{
|
|
160
|
+
services: any;
|
|
161
|
+
getServiceUrl: typeof getServiceUrl;
|
|
162
|
+
} | undefined>;
|
|
163
|
+
export declare const fetchAPI: typeof juxFetch & {
|
|
164
|
+
all: typeof fetchAll;
|
|
165
|
+
get: <T = any>(url: string, options?: Omit<FetchOptions, "method">) => FetchBuilder<T>;
|
|
166
|
+
post: <T = any>(url: string, body?: any, options?: Omit<FetchOptions, "method" | "body">) => FetchBuilder<T>;
|
|
167
|
+
put: <T = any>(url: string, body?: any, options?: Omit<FetchOptions, "method" | "body">) => FetchBuilder<T>;
|
|
168
|
+
patch: <T = any>(url: string, body?: any, options?: Omit<FetchOptions, "method" | "body">) => FetchBuilder<T>;
|
|
169
|
+
delete: <T = any>(url: string, options?: Omit<FetchOptions, "method">) => FetchBuilder<T>;
|
|
170
|
+
config: typeof configureFetch;
|
|
171
|
+
setupConfig: typeof setupConfig;
|
|
172
|
+
getServiceUrl: typeof getServiceUrl;
|
|
173
|
+
serviceClient: typeof serviceClient;
|
|
174
|
+
};
|
|
175
|
+
export {};
|
|
176
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../lib/utils/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE1C,MAAM,WAAW,WAAW;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,QAAQ,CAA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