@nuraly/runtime 0.1.3 → 0.1.5

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 (49) hide show
  1. package/components/ui/nuraly-ui/packages/common/dist/shared/controllers/dropdown.controller.d.ts +0 -1
  2. package/components/ui/nuraly-ui/packages/common/dist/shared/controllers/dropdown.interface.d.ts +0 -2
  3. package/components/ui/nuraly-ui/packages/common/dist/shared/controllers/theme.controller.d.ts +0 -1
  4. package/components/ui/nuraly-ui/packages/common/dist/shared/event-handler-mixin.d.ts +0 -1
  5. package/components/ui/nuraly-ui/packages/common/dist/shared/theme-mixin.d.ts +0 -1
  6. package/components/ui/nuraly-ui/packages/common/dist/shared/themes.d.ts +0 -1
  7. package/components/ui/nuraly-ui/packages/common/dist/shared/utils.d.ts +60 -0
  8. package/components/ui/nuraly-ui/packages/common/dist/shared/validation.types.d.ts +108 -0
  9. package/components/ui/nuraly-ui/src/components/radio-group/radio-group.component.ts +1 -1
  10. package/components/ui/nuraly-ui/src/components/radio-group/radio-group.types.ts +1 -0
  11. package/dist/CodeEditor-BiNku87K.js +808 -0
  12. package/dist/{CodeEditor-Ch2tv9BE.js → CodeEditor-G6E8PUI7.js} +14593 -14607
  13. package/dist/{SmartAttributeHandler-hoSLpm1Y.js → SmartAttributeHandler-C9vS-cHW.js} +1 -1
  14. package/dist/SmartAttributeHandler-u-ZHGueR.js +193 -0
  15. package/dist/assets/editor.worker-C_S4Avdt.js +11 -0
  16. package/dist/assets/{html.worker-BSmGlhXp.js → html.worker-DfuQASUV.js} +18 -18
  17. package/dist/assets/json.worker-Cucz4wxY.js +42 -0
  18. package/dist/assets/{ts.worker-DyHHPhrh.js → ts.worker-Dme6S0YK.js} +78 -78
  19. package/dist/cssMode-B7NVlrDV.js +1443 -0
  20. package/dist/{freemarker2-DNc2IxPf.js → freemarker2-DS_7G9b8.js} +1 -1
  21. package/dist/{handlebars-CIbFckEw.js → handlebars-BDyyLkzw.js} +1 -1
  22. package/dist/{html-nRs_fneU.js → html-DphGFjig.js} +1 -1
  23. package/dist/{htmlMode-BjehA1YF.js → htmlMode-4zNnSWFo.js} +278 -281
  24. package/dist/index-B4yIOSMd.js +3847 -0
  25. package/dist/{javascript-Bn0HduZA.js → javascript-CC1jWyQy.js} +1 -1
  26. package/dist/{jsonMode-CfGfcJRX.js → jsonMode-Bfzb6wZf.js} +369 -372
  27. package/dist/{liquid-m4D_LCnC.js → liquid-lTBpqagR.js} +1 -1
  28. package/dist/{mdx-CakMRbCr.js → mdx-DX66Bp07.js} +1 -1
  29. package/dist/{micro-app-entry-CI1Rupdh.js → micro-app-entry-DDsAWUJh.js} +5138 -5322
  30. package/dist/micro-app.bundle.js +1 -1
  31. package/dist/micro-app.js +9775 -0
  32. package/dist/{python-oJwaiPUY.js → python-BGUhyO4G.js} +1 -1
  33. package/dist/{razor-u_dd4rqc.js → razor-DEVWQFSa.js} +1 -1
  34. package/dist/runtime.js +401 -0
  35. package/dist/style.css +1 -1
  36. package/dist/tsMode-CYFi80Jf.js +800 -0
  37. package/dist/{typescript-Bjs2N5Be.js → typescript-B1xIbH_T.js} +1 -1
  38. package/dist/{wgsl-Bv2xeo60.js → wgsl-C9yjop46.js} +1 -1
  39. package/dist/{xml-BCveATLl.js → xml-DmdvyqrE.js} +1 -1
  40. package/dist/{yaml-BfWQPJQi.js → yaml-LGNo48fy.js} +1 -1
  41. package/package.json +2 -2
  42. package/utils/register-components.ts +1 -1
  43. package/vite.config.ts +8 -8
  44. package/dist/.claude/settings.local.json +0 -9
  45. package/dist/assets/editor.worker-vBWydyGC.js +0 -11
  46. package/dist/assets/json.worker-Dqnoedz4.js +0 -42
  47. package/dist/cssMode-Bt2uK8XM.js +0 -1446
  48. package/dist/micro-app.bundle.umd.cjs +0 -5051
  49. package/dist/tsMode-DlZ38d3D.js +0 -813
@@ -0,0 +1,808 @@
1
+ import { css, LitElement, html } from 'lit';
2
+ import { property, customElement } from 'lit/decorators.js';
3
+ import { createRef, ref } from 'lit/directives/ref.js';
4
+ import * as monaco from '/Users/aymen/Desktop/projects/nuraly/stack/services/studio/node_modules/monaco-editor/esm/vs/editor/editor.main.js';
5
+ import { registerCompletion } from '/Users/aymen/Desktop/projects/nuraly/stack/services/studio/node_modules/monacopilot/build/index.mjs';
6
+ import styles from '/Users/aymen/Desktop/projects/nuraly/stack/services/studio/node_modules/monaco-editor/min/vs/editor/editor.main.css?inline';
7
+ import editorWorker from '/Users/aymen/Desktop/projects/nuraly/stack/services/studio/node_modules/monaco-editor/esm/vs/editor/editor.worker.js?worker';
8
+ import tsWorker from '/Users/aymen/Desktop/projects/nuraly/stack/services/studio/node_modules/monaco-editor/esm/vs/language/typescript/ts.worker.js?worker';
9
+ import htmlWorker from '/Users/aymen/Desktop/projects/nuraly/stack/services/studio/node_modules/monaco-editor/esm/vs/language/html/html.worker.js?worker';
10
+ import jsonWorker from '/Users/aymen/Desktop/projects/nuraly/stack/services/studio/node_modules/monaco-editor/esm/vs/language/json/json.worker.js?worker';
11
+
12
+ const databaseTypeDefinitions = `
13
+ /**
14
+ * Database configuration options
15
+ */
16
+ interface DatabaseOptions {
17
+ timeout?: number;
18
+ headers?: Record<string, string>;
19
+ [key: string]: any;
20
+ }
21
+
22
+ /**
23
+ * Table schema definition for creating tables
24
+ */
25
+ interface TableSchema {
26
+ [key: string]: {
27
+ type: string;
28
+ nullable?: boolean;
29
+ default?: any;
30
+ [key: string]: any;
31
+ };
32
+ }
33
+
34
+ /**
35
+ * Options for select queries including relations and criteria
36
+ */
37
+ interface SelectOptions {
38
+ relations?: RelationDefinition[];
39
+ criteria?: Record<string, any>;
40
+ fields?: string[];
41
+ limit?: number;
42
+ offset?: number;
43
+ orderBy?: string;
44
+ orderDirection?: 'ASC' | 'DESC';
45
+ [key: string]: any;
46
+ }
47
+
48
+ /**
49
+ * Relation definition for joins
50
+ */
51
+ interface RelationDefinition {
52
+ table: string;
53
+ localField: string;
54
+ foreignField: string;
55
+ type: 'inner' | 'left' | 'right' | 'outer';
56
+ }
57
+
58
+ /**
59
+ * Join definition for complex queries
60
+ */
61
+ interface JoinDefinition {
62
+ table: string;
63
+ on: string;
64
+ type?: string;
65
+ }
66
+
67
+ /**
68
+ * Batch operation definition
69
+ */
70
+ interface BatchOperation {
71
+ method: string;
72
+ table: string;
73
+ data?: Record<string, any>;
74
+ criteria?: Record<string, any>;
75
+ options?: SelectOptions;
76
+ }
77
+
78
+ /**
79
+ * Pagination result with metadata
80
+ */
81
+ interface PaginationResult<T> {
82
+ data: T[];
83
+ count: number;
84
+ pagination: {
85
+ currentPage: number;
86
+ pageSize: number;
87
+ totalRecords: number;
88
+ totalPages: number;
89
+ hasNextPage: boolean;
90
+ hasPrevPage: boolean;
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Backup data structure
96
+ */
97
+ interface BackupData {
98
+ tableName: string;
99
+ timestamp: string;
100
+ recordCount: number;
101
+ data: Record<string, any>[];
102
+ }
103
+
104
+ /**
105
+ * Static Database Client for Nuraly Database Manager
106
+ *
107
+ * A comprehensive JavaScript class that provides a clean static interface for all database operations
108
+ * including table management, data operations, joins, and advanced queries.
109
+ */
110
+ declare class Database {
111
+ /**
112
+ * Configure the Database client
113
+ * @param baseUrl The base URL of the database API (default: /api/v1/database)
114
+ * @param options Additional configuration options
115
+ */
116
+ static configure(baseUrl?: string, options?: DatabaseOptions): void;
117
+
118
+ // HEALTH & INFO METHODS
119
+ /**
120
+ * Check the health status of the database service
121
+ * @returns Health status
122
+ */
123
+ static health(): Promise<any>;
124
+
125
+ /**
126
+ * Get database connection information and metadata
127
+ * @returns Database info
128
+ */
129
+ static getInfo(): Promise<any>;
130
+
131
+ // TABLE MANAGEMENT METHODS
132
+ /**
133
+ * Create a new table with specified schema
134
+ * @param tableName Name of the table to create
135
+ * @param schema Table schema definition
136
+ * @param options Additional options
137
+ * @returns Creation result
138
+ */
139
+ static createTable(tableName: string, schema: TableSchema, options?: Record<string, any>): Promise<any>;
140
+
141
+ /**
142
+ * Update existing table schema (add columns)
143
+ * @param tableName Name of the table to update
144
+ * @param schema New columns to add
145
+ * @returns Update result
146
+ */
147
+ static updateSchema(tableName: string, schema: TableSchema): Promise<any>;
148
+
149
+ /**
150
+ * Drop a table
151
+ * @param tableName Name of the table to drop
152
+ * @returns Drop result
153
+ */
154
+ static dropTable(tableName: string): Promise<any>;
155
+
156
+ /**
157
+ * List all tables in the database
158
+ * @returns List of tables
159
+ */
160
+ static listTables(): Promise<any>;
161
+
162
+ /**
163
+ * Get table schema information
164
+ * @param tableName Name of the table
165
+ * @returns Table schema
166
+ */
167
+ static getTableSchema(tableName: string): Promise<any>;
168
+
169
+ /**
170
+ * Execute comprehensive schema queries for database introspection
171
+ * @param type Type of schema query (LIST_TABLES, DESCRIBE_TABLE, TABLE_EXISTS, GET_INFO, LIST_INDEXES, GET_CONSTRAINTS, GET_FOREIGN_KEYS)
172
+ * @param tableName Name of the table (optional, required for table-specific queries)
173
+ * @returns Schema query result
174
+ */
175
+ static schemaQuery(type: string, tableName?: string): Promise<any>;
176
+
177
+ /**
178
+ * Check if a table exists in the database
179
+ * @param tableName Name of the table to check
180
+ * @returns True if table exists, false otherwise
181
+ */
182
+ static tableExists(tableName: string): Promise<boolean>;
183
+
184
+ /**
185
+ * Get all column information for a specific table
186
+ * @param tableName Name of the table
187
+ * @returns Column information including types, constraints, and defaults
188
+ */
189
+ static columns(tableName: string): Promise<any>;
190
+
191
+ /**
192
+ * Get database information and metadata
193
+ * @returns Database information and metadata
194
+ */
195
+ static getDatabaseInfo(): Promise<any>;
196
+
197
+ /**
198
+ * Get table constraints (primary keys, foreign keys, unique constraints, etc.)
199
+ * @param tableName Name of the table
200
+ * @returns Table constraints information
201
+ */
202
+ static getConstraints(tableName: string): Promise<any>;
203
+
204
+ /**
205
+ * Get foreign key relationships for a table
206
+ * @param tableName Name of the table
207
+ * @returns Foreign key information and relationships
208
+ */
209
+ static getForeignKeys(tableName: string): Promise<any>;
210
+
211
+ // DATA OPERATION METHODS
212
+ /**
213
+ * Insert data into a table
214
+ * @param tableName Name of the table
215
+ * @param data Data to insert
216
+ * @returns Insert result
217
+ */
218
+ static insert(tableName: string, data: Record<string, any>): Promise<any>;
219
+
220
+ /**
221
+ * Bulk insert multiple records
222
+ * @param tableName Name of the table
223
+ * @param records Array of records to insert
224
+ * @returns Array of insert results
225
+ */
226
+ static bulkInsert(tableName: string, records: Record<string, any>[]): Promise<any[]>;
227
+
228
+ /**
229
+ * Unified select method that handles both regular queries and queries with relations (joins)
230
+ * @param tableName Name of the table
231
+ * @param options Query options
232
+ * @returns Select result
233
+ */
234
+ static select(tableName: string, options?: SelectOptions): Promise<any>;
235
+
236
+ /**
237
+ * Update data in a table
238
+ * @param tableName Name of the table
239
+ * @param data Data to update
240
+ * @param criteria Update criteria
241
+ * @returns Update result
242
+ */
243
+ static update(tableName: string, data: Record<string, any>, criteria: Record<string, any>): Promise<any>;
244
+
245
+ /**
246
+ * Delete data from a table
247
+ * @param tableName Name of the table
248
+ * @param criteria Delete criteria
249
+ * @returns Delete result
250
+ */
251
+ static delete(tableName: string, criteria: Record<string, any>): Promise<any>;
252
+
253
+ // AGGREGATION & ANALYSIS METHODS
254
+ /**
255
+ * Count records in a table
256
+ * @param tableName Name of the table
257
+ * @param criteria Count criteria (optional)
258
+ * @returns Count result
259
+ */
260
+ static count(tableName: string, criteria?: Record<string, any>): Promise<any>;
261
+
262
+ /**
263
+ * Calculate sum of a field
264
+ * @param tableName Name of the table
265
+ * @param field Field to sum
266
+ * @param criteria Filter criteria (optional)
267
+ * @returns Sum result
268
+ */
269
+ static sum(tableName: string, field: string, criteria?: Record<string, any>): Promise<any>;
270
+
271
+ /**
272
+ * Calculate average of a field
273
+ * @param tableName Name of the table
274
+ * @param field Field to average
275
+ * @param criteria Filter criteria (optional)
276
+ * @returns Average result
277
+ */
278
+ static avg(tableName: string, field: string, criteria?: Record<string, any>): Promise<any>;
279
+
280
+ /**
281
+ * Find maximum value of a field
282
+ * @param tableName Name of the table
283
+ * @param field Field to find max
284
+ * @param criteria Filter criteria (optional)
285
+ * @returns Max result
286
+ */
287
+ static max(tableName: string, field: string, criteria?: Record<string, any>): Promise<any>;
288
+
289
+ /**
290
+ * Find minimum value of a field
291
+ * @param tableName Name of the table
292
+ * @param field Field to find min
293
+ * @param criteria Filter criteria (optional)
294
+ * @returns Min result
295
+ */
296
+ static min(tableName: string, field: string, criteria?: Record<string, any>): Promise<any>;
297
+
298
+ /**
299
+ * Group by field with aggregation
300
+ * @param tableName Name of the table
301
+ * @param groupField Field to group by
302
+ * @param aggregateFields Fields to aggregate
303
+ * @param aggregateOperations Aggregation operations
304
+ * @param criteria Filter criteria (optional)
305
+ * @returns Group by result
306
+ */
307
+ static groupBy(tableName: string, groupField: string, aggregateFields: string[], aggregateOperations: string[], criteria?: Record<string, any>): Promise<any>;
308
+
309
+ // INDEX MANAGEMENT METHODS
310
+ /**
311
+ * Create an index on table fields
312
+ * @param tableName Name of the table
313
+ * @param indexName Name of the index
314
+ * @param fields Fields to index
315
+ * @param indexType Type of index (btree, hash, etc.)
316
+ * @returns Index creation result
317
+ */
318
+ static createIndex(tableName: string, indexName: string, fields: string[], indexType?: string): Promise<any>;
319
+
320
+ /**
321
+ * Drop an index
322
+ * @param tableName Name of the table
323
+ * @param indexName Name of the index to drop
324
+ * @returns Index drop result
325
+ */
326
+ static dropIndex(tableName: string, indexName: string): Promise<any>;
327
+
328
+ /**
329
+ * List all indexes for a table
330
+ * @param tableName Name of the table
331
+ * @returns List of indexes
332
+ */
333
+ static listIndexes(tableName: string): Promise<any>;
334
+
335
+ // ADVANCED QUERY METHODS
336
+ /**
337
+ * Execute raw SQL query
338
+ * @param sql SQL query to execute
339
+ * @param parameters Query parameters (optional)
340
+ * @returns Query result
341
+ */
342
+ static executeSQL(sql: string, parameters?: any[]): Promise<any>;
343
+
344
+ /**
345
+ * Perform a complex join query
346
+ * @param mainTable Main table for the join
347
+ * @param joins Array of join specifications
348
+ * @param options Additional query options
349
+ * @returns Join result
350
+ */
351
+ static join(mainTable: string, joins: JoinDefinition[], options?: Record<string, any>): Promise<any>;
352
+
353
+ // BATCH OPERATION METHODS
354
+ /**
355
+ * Execute multiple operations in sequence
356
+ * @param operations Array of operations to execute
357
+ * @returns Array of results
358
+ */
359
+ static batch(operations: BatchOperation[]): Promise<any[]>;
360
+
361
+ // UTILITY METHODS
362
+ /**
363
+ * Get paginated results
364
+ * @param tableName Name of the table
365
+ * @param page Page number (1-based)
366
+ * @param pageSize Number of records per page
367
+ * @param options Additional query options
368
+ * @returns Paginated results with metadata
369
+ */
370
+ static paginate(tableName: string, page?: number, pageSize?: number, options?: SelectOptions): Promise<PaginationResult<any>>;
371
+
372
+ /**
373
+ * Search records with text matching
374
+ * @param tableName Name of the table
375
+ * @param searchTerm Term to search for
376
+ * @param searchFields Fields to search in
377
+ * @param options Additional options
378
+ * @returns Search results
379
+ */
380
+ static search(tableName: string, searchTerm: string, searchFields: string[], options?: SelectOptions): Promise<any>;
381
+
382
+ /**
383
+ * Backup table data to JSON
384
+ * @param tableName Name of the table to backup
385
+ * @returns Backup data
386
+ */
387
+ static backup(tableName: string): Promise<BackupData>;
388
+
389
+ /**
390
+ * Restore table data from backup
391
+ * @param backupData Backup data object
392
+ * @param clearFirst Whether to clear existing data first
393
+ * @returns Restore result
394
+ */
395
+ static restore(backupData: BackupData, clearFirst?: boolean): Promise<any>;
396
+ }
397
+
398
+ declare const Database: typeof Database;
399
+ `;
400
+
401
+ var __defProp = Object.defineProperty;
402
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
403
+ var __decorateClass = (decorators, target, key, kind) => {
404
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
405
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
406
+ if (decorator = decorators[i])
407
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
408
+ if (kind && result) __defProp(target, key, result);
409
+ return result;
410
+ };
411
+ if (typeof self !== "undefined") {
412
+ self.MonacoEnvironment = {
413
+ getWorker(_, label) {
414
+ if (label === "typescript" || label === "javascript") {
415
+ return new tsWorker();
416
+ }
417
+ if (label === "json") {
418
+ return new jsonWorker();
419
+ }
420
+ if (label === "html") {
421
+ return new htmlWorker();
422
+ }
423
+ return new editorWorker();
424
+ }
425
+ };
426
+ }
427
+ let CodeEditor = class extends LitElement {
428
+ constructor() {
429
+ super(...arguments);
430
+ this.isEditorReady = false;
431
+ this.theme = "";
432
+ this.container = createRef();
433
+ }
434
+ render() {
435
+ return html`
436
+ <style>
437
+ ${styles}
438
+ </style>
439
+ <main ${ref(this.container)}></main>
440
+ `;
441
+ }
442
+ /**
443
+ * Returns the current code contents
444
+ */
445
+ getValue() {
446
+ return this.editor?.getValue() ?? "";
447
+ }
448
+ /**
449
+ * Allows external code to update various Monaco editor options
450
+ */
451
+ setOptions(value) {
452
+ this.editor?.updateOptions(value);
453
+ }
454
+ /**
455
+ * Set up custom IntelliSense for TypeScript/JavaScript
456
+ */
457
+ setupCustomIntelliSense() {
458
+ monaco.languages.typescript.typescriptDefaults.addExtraLib(
459
+ databaseTypeDefinitions,
460
+ "database-types.d.ts"
461
+ );
462
+ monaco.languages.typescript.javascriptDefaults.addExtraLib(
463
+ databaseTypeDefinitions,
464
+ "database-types.d.ts"
465
+ );
466
+ monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
467
+ target: monaco.languages.typescript.ScriptTarget.ES2020,
468
+ allowNonTsExtensions: true,
469
+ moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
470
+ module: monaco.languages.typescript.ModuleKind.CommonJS,
471
+ noEmit: true,
472
+ esModuleInterop: true,
473
+ jsx: monaco.languages.typescript.JsxEmit.React,
474
+ reactNamespace: "React",
475
+ allowJs: true,
476
+ typeRoots: ["node_modules/@types"]
477
+ });
478
+ monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
479
+ target: monaco.languages.typescript.ScriptTarget.ES2020,
480
+ allowNonTsExtensions: true,
481
+ moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
482
+ module: monaco.languages.typescript.ModuleKind.CommonJS,
483
+ noEmit: true,
484
+ esModuleInterop: true,
485
+ allowJs: true,
486
+ checkJs: false
487
+ });
488
+ monaco.languages.registerCompletionItemProvider(["javascript", "typescript"], {
489
+ provideCompletionItems: (model, position) => {
490
+ const suggestions = [];
491
+ suggestions.push({
492
+ label: "Database",
493
+ kind: monaco.languages.CompletionItemKind.Class,
494
+ insertText: "Database",
495
+ documentation: "Static Database Client for Nuraly Database Manager",
496
+ detail: "class Database"
497
+ });
498
+ const dbOperations = [
499
+ {
500
+ label: "Database.select",
501
+ kind: monaco.languages.CompletionItemKind.Method,
502
+ insertText: 'Database.select(${1:"tableName"}, {${2:}})',
503
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
504
+ documentation: "Select data from a table with optional criteria and relations",
505
+ detail: "(method) Database.select(tableName: string, options?: SelectOptions): Promise<any>"
506
+ },
507
+ {
508
+ label: "Database.insert",
509
+ kind: monaco.languages.CompletionItemKind.Method,
510
+ insertText: 'Database.insert(${1:"tableName"}, ${2:{}})',
511
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
512
+ documentation: "Insert data into a table",
513
+ detail: "(method) Database.insert(tableName: string, data: Record<string, any>): Promise<any>"
514
+ },
515
+ {
516
+ label: "Database.update",
517
+ kind: monaco.languages.CompletionItemKind.Method,
518
+ insertText: 'Database.update(${1:"tableName"}, ${2:{}}, ${3:{}})',
519
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
520
+ documentation: "Update data in a table",
521
+ detail: "(method) Database.update(tableName: string, data: Record<string, any>, criteria: Record<string, any>): Promise<any>"
522
+ },
523
+ {
524
+ label: "Database.delete",
525
+ kind: monaco.languages.CompletionItemKind.Method,
526
+ insertText: 'Database.delete(${1:"tableName"}, ${2:{}})',
527
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
528
+ documentation: "Delete data from a table",
529
+ detail: "(method) Database.delete(tableName: string, criteria: Record<string, any>): Promise<any>"
530
+ },
531
+ {
532
+ label: "Database.createTable",
533
+ kind: monaco.languages.CompletionItemKind.Method,
534
+ insertText: 'Database.createTable(${1:"tableName"}, {\n ${2:field}: { type: ${3:"varchar"}, nullable: ${4:false} }\n})',
535
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
536
+ documentation: "Create a new table with specified schema",
537
+ detail: "(method) Database.createTable(tableName: string, schema: TableSchema, options?: Record<string, any>): Promise<any>"
538
+ },
539
+ {
540
+ label: "Database.paginate",
541
+ kind: monaco.languages.CompletionItemKind.Method,
542
+ insertText: 'Database.paginate(${1:"tableName"}, ${2:1}, ${3:10}, ${4:{}})',
543
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
544
+ documentation: "Get paginated results with metadata",
545
+ detail: "(method) Database.paginate(tableName: string, page?: number, pageSize?: number, options?: SelectOptions): Promise<PaginationResult<any>>"
546
+ },
547
+ {
548
+ label: "Database.schemaQuery",
549
+ kind: monaco.languages.CompletionItemKind.Method,
550
+ insertText: 'Database.schemaQuery(${1:"LIST_TABLES"}${2:, "tableName"})',
551
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
552
+ documentation: "Execute schema queries for database introspection",
553
+ detail: "(method) Database.schemaQuery(type: string, tableName?: string): Promise<any>"
554
+ },
555
+ {
556
+ label: "Database.join",
557
+ kind: monaco.languages.CompletionItemKind.Method,
558
+ insertText: 'Database.join(${1:"mainTable"}, [\n { table: ${2:"joinTable"}, on: ${3:"field1 = field2"}, type: ${4:"inner"} }\n], ${5:{}})',
559
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
560
+ documentation: "Perform complex join queries",
561
+ detail: "(method) Database.join(mainTable: string, joins: JoinDefinition[], options?: Record<string, any>): Promise<any>"
562
+ }
563
+ ];
564
+ suggestions.push(...dbOperations);
565
+ return { suggestions };
566
+ }
567
+ });
568
+ monaco.languages.registerHoverProvider(["javascript", "typescript"], {
569
+ provideHover: (model, position) => {
570
+ const word = model.getWordAtPosition(position);
571
+ if (!word) return;
572
+ const hoverDocs = {
573
+ "Database": {
574
+ contents: [
575
+ { value: "**Database**" },
576
+ { value: "Static Database Client for Nuraly Database Manager" },
577
+ { value: "Provides a comprehensive interface for database operations including:" },
578
+ { value: "- Table management (create, drop, schema operations)" },
579
+ { value: "- Data operations (select, insert, update, delete)" },
580
+ { value: "- Advanced queries (joins, aggregations, pagination)" },
581
+ { value: "- Schema introspection and management" },
582
+ { value: '```typescript\n// Configure the client\nDatabase.configure("/api/v1/database");\n\n// Create a table\nawait Database.createTable("users", {\n name: { type: "varchar", nullable: false },\n email: { type: "varchar", nullable: false }\n});\n\n// Insert data\nawait Database.insert("users", {\n name: "John Doe",\n email: "john@example.com"\n});\n```' }
583
+ ]
584
+ }
585
+ };
586
+ return hoverDocs[word.word] || null;
587
+ }
588
+ });
589
+ }
590
+ /**
591
+ * Create the Monaco editor once the element has rendered
592
+ */
593
+ firstUpdated() {
594
+ if (!this.container.value) {
595
+ console.error("CodeEditor: Container element not available in firstUpdated");
596
+ return;
597
+ }
598
+ monaco.languages.register({ id: "mylang" });
599
+ monaco.languages.setMonarchTokensProvider("mylang", {
600
+ tokenizer: {
601
+ root: [
602
+ [/#.*$/, "comment"],
603
+ [/\b(begin|end|if|else|while)\b/, "keyword"],
604
+ [/[=+\-*/]/, "operator"],
605
+ [/\d+/, "number"]
606
+ ]
607
+ }
608
+ });
609
+ try {
610
+ this.editor = monaco.editor.create(this.container.value, {
611
+ value: this.getCode(),
612
+ language: this.getLang(),
613
+ theme: this.getTheme(),
614
+ fontSize: 13,
615
+ automaticLayout: true,
616
+ readOnly: this.readonly ?? false
617
+ });
618
+ this.isEditorReady = true;
619
+ } catch (error) {
620
+ console.error("CodeEditor: Failed to create editor instance", error);
621
+ return;
622
+ }
623
+ this.setupCustomIntelliSense();
624
+ registerCompletion(monaco, this.editor, {
625
+ language: this.getLang(),
626
+ // Your API endpoint for handling completion requests
627
+ endpoint: "/api/v1/copilot/completion"
628
+ });
629
+ this.editor.getModel()?.onDidChangeContent(() => {
630
+ this.dispatchEvent(
631
+ new CustomEvent("change", { detail: { value: this.getValue() } })
632
+ );
633
+ });
634
+ this.registerKeyboardEvents();
635
+ window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
636
+ monaco.editor.setTheme(this.getTheme());
637
+ });
638
+ }
639
+ /**
640
+ * Register keyboard event handlers for the editor
641
+ */
642
+ registerKeyboardEvents() {
643
+ if (!this.editor) return;
644
+ this.editor.onKeyDown((e) => {
645
+ this.dispatchEvent(
646
+ new CustomEvent("editor-keydown", {
647
+ detail: {
648
+ event: e,
649
+ key: e.browserEvent.key,
650
+ code: e.browserEvent.code,
651
+ ctrlKey: e.browserEvent.ctrlKey,
652
+ shiftKey: e.browserEvent.shiftKey,
653
+ altKey: e.browserEvent.altKey,
654
+ metaKey: e.browserEvent.metaKey
655
+ }
656
+ })
657
+ );
658
+ });
659
+ this.editor.onKeyUp((e) => {
660
+ this.dispatchEvent(
661
+ new CustomEvent("editor-keyup", {
662
+ detail: {
663
+ event: e,
664
+ key: e.browserEvent.key,
665
+ code: e.browserEvent.code,
666
+ ctrlKey: e.browserEvent.ctrlKey,
667
+ shiftKey: e.browserEvent.shiftKey,
668
+ altKey: e.browserEvent.altKey,
669
+ metaKey: e.browserEvent.metaKey
670
+ }
671
+ })
672
+ );
673
+ });
674
+ }
675
+ /**
676
+ * Dispose of the editor and its model when the element is removed
677
+ * from the DOM. This prevents stale listeners from piling up.
678
+ */
679
+ disconnectedCallback() {
680
+ super.disconnectedCallback();
681
+ if (this.editor) {
682
+ const model = this.editor.getModel();
683
+ this.editor.dispose();
684
+ model?.dispose();
685
+ this.editor = void 0;
686
+ }
687
+ this.isEditorReady = false;
688
+ }
689
+ /**
690
+ * Whenever the `code` property changes, update the editor’s text if needed
691
+ */
692
+ update(changedProperties) {
693
+ super.update(changedProperties);
694
+ if (!this.isEditorReady) {
695
+ return;
696
+ }
697
+ if (changedProperties.has("code") && this.code !== changedProperties.get("code")) {
698
+ if (!this.editor) {
699
+ return;
700
+ }
701
+ const model = this.editor.getModel();
702
+ if (!model) {
703
+ return;
704
+ }
705
+ const cursorPosition = this.editor.getPosition();
706
+ if (this.code !== this.getValue()) {
707
+ try {
708
+ this.editor.setValue(this.code ?? "");
709
+ if (cursorPosition) {
710
+ this.editor.setPosition(cursorPosition);
711
+ }
712
+ } catch (e) {
713
+ }
714
+ }
715
+ }
716
+ if (changedProperties.has("readonly") && this.readonly !== changedProperties.get("readonly")) {
717
+ try {
718
+ this.editor?.updateOptions({
719
+ readOnly: this.readonly ?? false
720
+ });
721
+ } catch (e) {
722
+ }
723
+ }
724
+ if (changedProperties.has("language") && this.language !== changedProperties.get("language")) {
725
+ try {
726
+ if (this.editor && this.editor.getModel()) {
727
+ monaco.editor.setModelLanguage(
728
+ this.editor.getModel(),
729
+ this.language || "plaintext"
730
+ );
731
+ }
732
+ } catch (e) {
733
+ }
734
+ }
735
+ if (changedProperties.has("theme") && this.theme !== changedProperties.get("theme")) {
736
+ try {
737
+ this.editor?.updateOptions({
738
+ theme: this.theme
739
+ });
740
+ } catch (e) {
741
+ }
742
+ }
743
+ }
744
+ /**
745
+ * If the user hasn't passed any `code`, we look for a <script> child
746
+ * or fallback to an empty string
747
+ */
748
+ getCode() {
749
+ if (this.code) return this.code;
750
+ const file = this.getFile();
751
+ return file ? file.innerHTML.trim() : "";
752
+ }
753
+ /**
754
+ * If the user hasn't passed any `language`, we look for a <script> child
755
+ * or fallback to "plaintext"
756
+ */
757
+ getLang() {
758
+ if (this.language) return this.language;
759
+ const file = this.getFile();
760
+ if (!file) return "plaintext";
761
+ const type = file.getAttribute("type") || "text/plain";
762
+ return type.split("/").pop() || "plaintext";
763
+ }
764
+ /**
765
+ * Figure out which theme Monaco should use
766
+ */
767
+ getTheme() {
768
+ if (this.theme) return this.theme;
769
+ return this.isDark() ? "vs-dark" : "vs-light";
770
+ }
771
+ isDark() {
772
+ return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
773
+ }
774
+ /**
775
+ * If we have a <script> child, return it (this is just a convenience to allow:
776
+ * <code-editor><script type="text/javascript">const x=1;<\/script></code-editor>)
777
+ */
778
+ getFile() {
779
+ return this.children.length > 0 ? this.children[0] : null;
780
+ }
781
+ };
782
+ CodeEditor.styles = css`
783
+ :host {
784
+ --editor-width: 100%;
785
+ --editor-height: 100%;
786
+ }
787
+ main {
788
+ width: var(--editor-width);
789
+ height: var(--editor-height);
790
+ }
791
+ `;
792
+ __decorateClass([
793
+ property({ type: Boolean, attribute: "readonly" })
794
+ ], CodeEditor.prototype, "readonly", 2);
795
+ __decorateClass([
796
+ property()
797
+ ], CodeEditor.prototype, "theme", 2);
798
+ __decorateClass([
799
+ property()
800
+ ], CodeEditor.prototype, "language", 2);
801
+ __decorateClass([
802
+ property()
803
+ ], CodeEditor.prototype, "code", 2);
804
+ CodeEditor = __decorateClass([
805
+ customElement("code-editor")
806
+ ], CodeEditor);
807
+
808
+ export { CodeEditor };