@mostfeatured/dbi 0.2.13 → 0.2.15

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.
Files changed (45) hide show
  1. package/dist/src/types/Components/HTMLComponentsV2/index.d.ts +33 -1
  2. package/dist/src/types/Components/HTMLComponentsV2/index.d.ts.map +1 -1
  3. package/dist/src/types/Components/HTMLComponentsV2/index.js +408 -82
  4. package/dist/src/types/Components/HTMLComponentsV2/index.js.map +1 -1
  5. package/dist/src/types/Components/HTMLComponentsV2/parser.d.ts +52 -0
  6. package/dist/src/types/Components/HTMLComponentsV2/parser.d.ts.map +1 -1
  7. package/dist/src/types/Components/HTMLComponentsV2/parser.js +275 -0
  8. package/dist/src/types/Components/HTMLComponentsV2/parser.js.map +1 -1
  9. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.d.ts +26 -0
  10. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.d.ts.map +1 -1
  11. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.js +509 -34
  12. package/dist/src/types/Components/HTMLComponentsV2/svelteParser.js.map +1 -1
  13. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.d.ts +10 -0
  14. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.d.ts.map +1 -1
  15. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.js +76 -11
  16. package/dist/src/types/Components/HTMLComponentsV2/svelteRenderer.js.map +1 -1
  17. package/dist/test/index.js +76 -3
  18. package/dist/test/index.js.map +1 -1
  19. package/docs/ADVANCED_FEATURES.md +4 -0
  20. package/docs/API_REFERENCE.md +4 -0
  21. package/docs/CHAT_INPUT.md +4 -0
  22. package/docs/COMPONENTS.md +4 -0
  23. package/docs/EVENTS.md +4 -0
  24. package/docs/GETTING_STARTED.md +4 -0
  25. package/docs/LOCALIZATION.md +4 -0
  26. package/docs/README.md +4 -0
  27. package/docs/SVELTE_COMPONENTS.md +162 -6
  28. package/docs/llm/ADVANCED_FEATURES.txt +521 -0
  29. package/docs/llm/API_REFERENCE.txt +659 -0
  30. package/docs/llm/CHAT_INPUT.txt +514 -0
  31. package/docs/llm/COMPONENTS.txt +595 -0
  32. package/docs/llm/EVENTS.txt +449 -0
  33. package/docs/llm/GETTING_STARTED.txt +296 -0
  34. package/docs/llm/LOCALIZATION.txt +501 -0
  35. package/docs/llm/README.txt +193 -0
  36. package/docs/llm/SVELTE_COMPONENTS.txt +566 -0
  37. package/generated/svelte-dbi.d.ts +122 -0
  38. package/package.json +1 -1
  39. package/src/types/Components/HTMLComponentsV2/index.ts +466 -94
  40. package/src/types/Components/HTMLComponentsV2/parser.ts +317 -0
  41. package/src/types/Components/HTMLComponentsV2/svelteParser.ts +567 -35
  42. package/src/types/Components/HTMLComponentsV2/svelteRenderer.ts +91 -13
  43. package/test/index.ts +76 -3
  44. package/test/product-showcase.svelte +380 -24
  45. package/llm.txt +0 -1088
@@ -1,20 +1,31 @@
1
1
  import { compile } from "svelte/compiler";
2
2
  import { DBI } from "../../../DBI";
3
3
  import { NamespaceEnums } from "../../../../generated/namespaceData";
4
- import { parseHTMLComponentsV2 } from "./parser";
5
- import { parseSvelteComponent, createHandlerContext, SvelteComponentInfo, HandlerContextResult } from "./svelteParser";
4
+ import { parseHTMLComponentsV2, parseHTMLComponentsV2Multi } from "./parser";
5
+ import { parseSvelteComponent, createHandlerContext, SvelteComponentInfo, HandlerContextResult, validateSvelteComponent, logValidationWarnings } from "./svelteParser";
6
6
  import * as stuffs from "stuffs";
7
7
  import * as vm from "vm";
8
8
 
9
9
  export interface SvelteRenderOptions {
10
10
  data?: Record<string, any>;
11
11
  ttl?: number;
12
+ /** If true, skips validation warnings (useful for production) */
13
+ skipValidation?: boolean;
14
+ }
15
+
16
+ export interface ModalDefinition {
17
+ title: string;
18
+ customId: string;
19
+ components: any[];
20
+ modalId: string;
12
21
  }
13
22
 
14
23
  export interface SvelteRenderResult {
15
24
  components: any[];
16
25
  handlers: Map<string, { handlerFn: Function, context: any }>;
17
26
  componentInfo: SvelteComponentInfo;
27
+ /** Modal definitions parsed from <components type="modal"> elements */
28
+ modals: Map<string, ModalDefinition>;
18
29
  }
19
30
 
20
31
  /**
@@ -26,21 +37,70 @@ export async function renderSvelteComponent(
26
37
  dbiName: string,
27
38
  options: SvelteRenderOptions = {}
28
39
  ): Promise<SvelteRenderResult> {
29
- const { data = {}, ttl = 0 } = options;
40
+ const { data = {}, ttl = 0, skipValidation = false } = options;
30
41
 
31
42
  // Parse the Svelte component to extract handlers
32
43
  // This also injects auto-generated names into elements without name attribute
33
44
  const componentInfo = await parseSvelteComponent(source, data);
34
45
 
46
+ // Validate the component and log warnings (only on first render, not re-renders)
47
+ if (!skipValidation && !data.$ref) {
48
+ const warnings = validateSvelteComponent(componentInfo, data, dbiName);
49
+ if (warnings.length > 0) {
50
+ logValidationWarnings(warnings);
51
+ }
52
+ }
53
+
35
54
  // Use the processed source (with auto-generated names injected)
36
55
  const processedSource = componentInfo.processedSource;
37
56
 
38
57
  // Compile the Svelte component for SSR (Svelte 5)
39
- const compiled = compile(processedSource, {
40
- generate: "server",
41
- css: "injected",
42
- dev: false,
43
- } as any);
58
+ let compiled;
59
+ try {
60
+ compiled = compile(processedSource, {
61
+ generate: "server",
62
+ css: "injected",
63
+ dev: false,
64
+ } as any);
65
+ } catch (compileError: any) {
66
+ // Format Svelte compile error with helpful details
67
+ const errorMessage = compileError.message || 'Unknown compile error';
68
+ const location = compileError.start || compileError.loc || compileError.position;
69
+ let details = errorMessage;
70
+
71
+ if (location) {
72
+ const lines = processedSource.split('\n');
73
+ const lineNum = location.line || 1;
74
+ const column = location.column || 0;
75
+ const errorLine = lines[lineNum - 1] || '';
76
+ const prevLine = lines[lineNum - 2] || '';
77
+ const nextLine = lines[lineNum] || '';
78
+
79
+ details = `
80
+ Svelte Compile Error at line ${lineNum}, column ${column}:
81
+ ${errorMessage}
82
+
83
+ ${lineNum > 1 ? `${lineNum - 1} | ${prevLine}\n` : ''}${lineNum} | ${errorLine}
84
+ ${' '.repeat(String(lineNum).length + 3 + column)}^
85
+ ${nextLine ? `${lineNum + 1} | ${nextLine}` : ''}
86
+ `.trim();
87
+ }
88
+
89
+ // Check for common mistakes and add hints
90
+ let hint = '';
91
+ if (errorMessage.includes('Unexpected token')) {
92
+ hint = '\n\nšŸ’” Hint: Check for missing closing tags, unclosed braces, or invalid JavaScript syntax.';
93
+ } else if (errorMessage.includes('is not defined')) {
94
+ hint = '\n\nšŸ’” Hint: Make sure all variables are declared in $props() or as local variables.';
95
+ } else if (errorMessage.includes('Expected')) {
96
+ hint = '\n\nšŸ’” Hint: There might be a syntax error in your template or script.';
97
+ }
98
+
99
+ const enhancedError = new Error(`[DBI-Svelte] Failed to compile component "${dbiName}":\n${details}${hint}`);
100
+ (enhancedError as any).originalError = compileError;
101
+ (enhancedError as any).type = 'svelte-compile-error';
102
+ throw enhancedError;
103
+ }
44
104
 
45
105
  // Create a module context for the compiled code
46
106
  let html = "";
@@ -53,8 +113,23 @@ export async function renderSvelteComponent(
53
113
  // Pass data properties as top-level props (Svelte 5 expects flat props object)
54
114
  const renderResult = render(Component, { props: data });
55
115
  html = renderResult.body || "";
56
- } catch (error) {
57
- throw error;
116
+ } catch (runtimeError: any) {
117
+ // Format runtime error with helpful details
118
+ const errorMessage = runtimeError.message || 'Unknown runtime error';
119
+ let hint = '';
120
+
121
+ if (errorMessage.includes('is not a function')) {
122
+ hint = '\n\nšŸ’” Hint: A function you are trying to call is undefined. Check handler names.';
123
+ } else if (errorMessage.includes('Cannot read properties of undefined') || errorMessage.includes('undefined is not an object')) {
124
+ hint = '\n\nšŸ’” Hint: You are trying to access a property of an undefined value. Check your data object.';
125
+ } else if (errorMessage.includes('is not defined')) {
126
+ hint = '\n\nšŸ’” Hint: A variable is used but not declared. Make sure it is in $props() or declared locally.';
127
+ }
128
+
129
+ const enhancedError = new Error(`[DBI-Svelte] Runtime error in component "${dbiName}":\n${errorMessage}${hint}`);
130
+ (enhancedError as any).originalError = runtimeError;
131
+ (enhancedError as any).type = 'svelte-runtime-error';
132
+ throw enhancedError;
58
133
  }
59
134
 
60
135
  // For Svelte mode, inject state into interactive elements as a ref
@@ -102,8 +177,10 @@ export async function renderSvelteComponent(
102
177
  });
103
178
  }
104
179
 
105
- // Parse the rendered HTML to Discord components
106
- const components = parseHTMLComponentsV2(dbi, html, dbiName, { data, ttl });
180
+ // Parse the rendered HTML to Discord components (with modal support)
181
+ const parseResult = parseHTMLComponentsV2Multi(dbi, html, dbiName, { data, ttl });
182
+ const components = parseResult.components;
183
+ const modals = parseResult.modals;
107
184
 
108
185
  // Create handler context (also captures $effect callbacks)
109
186
  const handlerContext = createHandlerContext(componentInfo.scriptContent, data);
@@ -126,7 +203,8 @@ export async function renderSvelteComponent(
126
203
  return {
127
204
  components,
128
205
  handlers,
129
- componentInfo
206
+ componentInfo,
207
+ modals
130
208
  };
131
209
  }
132
210
 
package/test/index.ts CHANGED
@@ -26,8 +26,7 @@ dbi.register(({ ChatInput, HTMLComponentsV2 }) => {
26
26
  HTMLComponentsV2({
27
27
  name: "product-showcase",
28
28
  mode: 'svelte',
29
- file: path.join(__dirname, "product-showcase.svelte"),
30
- onExecute(ctx) {}
29
+ file: path.join(__dirname, "product-showcase.svelte")
31
30
  });
32
31
 
33
32
  // Test command
@@ -73,6 +72,78 @@ dbi.register(({ ChatInput, HTMLComponentsV2 }) => {
73
72
  category: "Furniture",
74
73
  rating: 4.6,
75
74
  stock: 31
75
+ },
76
+ {
77
+ name: "Webcam 4K",
78
+ description: "Ultra HD webcam with autofocus and noise-canceling mic",
79
+ price: 129,
80
+ image: "https://cdn.discordapp.com/embed/avatars/4.png",
81
+ category: "Electronics",
82
+ rating: 4.7,
83
+ stock: 15
84
+ },
85
+ {
86
+ name: "Desk Lamp",
87
+ description: "LED desk lamp with adjustable brightness and color temperature",
88
+ price: 45,
89
+ image: "https://cdn.discordapp.com/embed/avatars/0.png",
90
+ category: "Furniture",
91
+ rating: 4.4,
92
+ stock: 60
93
+ },
94
+ {
95
+ name: "Headphone Stand",
96
+ description: "Aluminum headphone stand with cable holder",
97
+ price: 35,
98
+ image: "https://cdn.discordapp.com/embed/avatars/1.png",
99
+ category: "Accessories",
100
+ rating: 4.2,
101
+ stock: 28
102
+ },
103
+ {
104
+ name: "Gaming Headset",
105
+ description: "7.1 surround sound gaming headset with RGB lighting",
106
+ price: 99,
107
+ image: "https://cdn.discordapp.com/embed/avatars/2.png",
108
+ category: "Electronics",
109
+ rating: 4.6,
110
+ stock: 35
111
+ },
112
+ {
113
+ name: "Mouse Pad XL",
114
+ description: "Extended mouse pad with stitched edges, 900x400mm",
115
+ price: 25,
116
+ image: "https://cdn.discordapp.com/embed/avatars/3.png",
117
+ category: "Accessories",
118
+ rating: 4.8,
119
+ stock: 100
120
+ },
121
+ {
122
+ name: "Ergonomic Chair",
123
+ description: "Mesh office chair with lumbar support and adjustable armrests",
124
+ price: 299,
125
+ image: "https://cdn.discordapp.com/embed/avatars/4.png",
126
+ category: "Furniture",
127
+ rating: 4.9,
128
+ stock: 8
129
+ },
130
+ {
131
+ name: "Cable Management Kit",
132
+ description: "Complete kit with cable clips, ties, and sleeve",
133
+ price: 19,
134
+ image: "https://cdn.discordapp.com/embed/avatars/0.png",
135
+ category: "Accessories",
136
+ rating: 4.1,
137
+ stock: 75
138
+ },
139
+ {
140
+ name: "Portable SSD 1TB",
141
+ description: "Ultra-fast portable SSD with USB 3.2 Gen 2",
142
+ price: 109,
143
+ image: "https://cdn.discordapp.com/embed/avatars/1.png",
144
+ category: "Electronics",
145
+ rating: 4.7,
146
+ stock: 22
76
147
  }
77
148
  ];
78
149
 
@@ -84,7 +155,9 @@ dbi.register(({ ChatInput, HTMLComponentsV2 }) => {
84
155
  currentIndex: 0,
85
156
  cart: [],
86
157
  view: 'browse',
87
- elapsedTime: 0
158
+ elapsedTime: 0,
159
+ reviews: [],
160
+ editingProduct: null
88
161
  }
89
162
  });
90
163
  }