@hyperfixi/vite-plugin 2.0.0 → 2.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/index.d.cts CHANGED
@@ -75,6 +75,22 @@ interface HyperfixiPluginOptions {
75
75
  * Enable verbose logging during development.
76
76
  */
77
77
  debug?: boolean;
78
+ /**
79
+ * Enable server-bridge route generation alongside bundle generation.
80
+ * Requires `@hyperfixi/server-bridge` to be installed as a peer dependency.
81
+ * If not installed, a warning is logged and the feature is silently skipped.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * hyperfixi({
86
+ * serverBridge: {
87
+ * framework: 'express',
88
+ * output: './server/routes',
89
+ * }
90
+ * })
91
+ * ```
92
+ */
93
+ serverBridge?: ServerBridgeOptions;
78
94
  /**
79
95
  * Enable semantic parsing for multilingual support.
80
96
  * - false: No semantic parsing (default, current behavior)
@@ -109,6 +125,26 @@ interface HyperfixiPluginOptions {
109
125
  * Useful for dynamic content not detectable at build time.
110
126
  */
111
127
  extraLanguages?: string[];
128
+ /**
129
+ * Register additional domains for scanning.
130
+ * Each domain declares its attribute patterns and keywords for detection.
131
+ * Runs alongside the default hyperscript scanner.
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * hyperfixi({
136
+ * domains: [
137
+ * {
138
+ * domain: 'sql',
139
+ * attributes: ['data-sql'],
140
+ * scriptTypes: ['text/sql-dsl'],
141
+ * keywords: { en: ['select', 'insert', 'update', 'delete'] },
142
+ * },
143
+ * ],
144
+ * })
145
+ * ```
146
+ */
147
+ domains?: DomainScanRule[];
112
148
  /**
113
149
  * Custom language keyword definitions.
114
150
  * Use this to add new languages or extend/override existing keyword detection.
@@ -206,6 +242,142 @@ interface AggregatedUsage {
206
242
  /** Map of file paths to their usage */
207
243
  fileUsage: Map<string, FileUsage>;
208
244
  }
245
+ /**
246
+ * Configuration for a domain's scanning rules in the Vite plugin.
247
+ */
248
+ interface DomainScanRule {
249
+ /** Domain name */
250
+ readonly domain: string;
251
+ /** Attribute names to scan for (e.g., ['data-sql', '_sql']) */
252
+ readonly attributes: readonly string[];
253
+ /** Script tag types to scan for (e.g., ['text/sql-dsl']) */
254
+ readonly scriptTypes?: readonly string[];
255
+ /** Keywords for command detection, keyed by language code */
256
+ readonly keywords?: Readonly<Record<string, readonly string[]>>;
257
+ }
258
+ /**
259
+ * Per-domain usage detected in a single file.
260
+ */
261
+ interface DomainFileUsage {
262
+ /** Domain name */
263
+ readonly domain: string;
264
+ /** Detected keywords/commands */
265
+ readonly detectedKeywords: Set<string>;
266
+ /** Languages detected */
267
+ readonly detectedLanguages: Set<string>;
268
+ /** Number of snippets found */
269
+ readonly snippetCount: number;
270
+ }
271
+ /**
272
+ * Aggregated usage across all files for a single domain.
273
+ */
274
+ interface DomainAggregatedUsage {
275
+ /** Domain name */
276
+ readonly domain: string;
277
+ /** All detected keywords across files */
278
+ readonly detectedKeywords: Set<string>;
279
+ /** All detected languages across files */
280
+ readonly detectedLanguages: Set<string>;
281
+ /** Number of files with this domain's usage */
282
+ readonly fileCount: number;
283
+ /** Total snippets across all files */
284
+ readonly totalSnippets: number;
285
+ }
286
+ /**
287
+ * Options for server-bridge route generation.
288
+ */
289
+ interface ServerBridgeOptions {
290
+ /** Target server framework (default: 'express') */
291
+ framework?: 'express' | 'hono' | 'openapi' | 'django' | 'fastapi';
292
+ /** Output directory for generated route files (default: './server/routes') */
293
+ output?: string;
294
+ /** Generate TypeScript (default: true) */
295
+ typescript?: boolean;
296
+ /** URL patterns to ignore */
297
+ ignore?: string[];
298
+ }
299
+
300
+ /**
301
+ * Domain Scanner for Vite Plugin
302
+ *
303
+ * Scans source files for domain-specific DSL usage based on configurable
304
+ * attribute patterns and keyword sets. Runs alongside the existing
305
+ * hyperscript Scanner as an opt-in feature.
306
+ */
307
+
308
+ /**
309
+ * Scanner that detects domain-specific syntax in source files.
310
+ * Complements the existing hyperscript Scanner.
311
+ */
312
+ declare class DomainScanner {
313
+ private rules;
314
+ /** Pre-compiled regex for fast hasAnyDomainUsage check */
315
+ private quickCheckPattern;
316
+ constructor(rules: readonly DomainScanRule[]);
317
+ /**
318
+ * Fast pre-check: does this code contain any domain-related attributes?
319
+ */
320
+ hasAnyDomainUsage(code: string): boolean;
321
+ /**
322
+ * Scan a file for all registered domain syntaxes.
323
+ * Returns one DomainFileUsage per domain that had matches.
324
+ */
325
+ scan(code: string, _id: string): DomainFileUsage[];
326
+ }
327
+ /**
328
+ * Convert a DomainDescriptor's scanConfig to a DomainScanRule.
329
+ * Returns null if the descriptor has no scanConfig.
330
+ *
331
+ * This allows DomainDescriptors from the framework to be used
332
+ * directly with the Vite plugin scanner.
333
+ */
334
+ declare function descriptorToScanRule(descriptor: {
335
+ name: string;
336
+ scanConfig?: {
337
+ attributes: readonly string[];
338
+ scriptTypes?: readonly string[];
339
+ keywords?: Readonly<Record<string, readonly string[]>>;
340
+ };
341
+ }): DomainScanRule | null;
342
+
343
+ /**
344
+ * Domain Aggregator
345
+ *
346
+ * Aggregates per-domain usage across files, following the same
347
+ * pattern as the existing hyperscript Aggregator.
348
+ */
349
+
350
+ /**
351
+ * Aggregates domain usage across multiple files.
352
+ */
353
+ declare class DomainAggregator {
354
+ private fileUsage;
355
+ private cache;
356
+ /**
357
+ * Add or update domain usage for a file.
358
+ * Returns true if usage changed (invalidates cache).
359
+ */
360
+ add(filePath: string, usage: DomainFileUsage[]): boolean;
361
+ /**
362
+ * Remove a file's domain usage.
363
+ * Returns true if the file was tracked.
364
+ */
365
+ remove(filePath: string): boolean;
366
+ /**
367
+ * Get aggregated usage across all files.
368
+ * Result is cached until add/remove changes it.
369
+ */
370
+ getUsage(): DomainAggregatedUsage[];
371
+ /**
372
+ * Get aggregated usage for a specific domain.
373
+ */
374
+ getUsageForDomain(domain: string): DomainAggregatedUsage | null;
375
+ /**
376
+ * Clear all tracked data.
377
+ */
378
+ clear(): void;
379
+ private isEqual;
380
+ }
209
381
 
210
382
  /**
211
383
  * Compiler
@@ -401,4 +573,4 @@ declare function getOptimalRegion(languages: Set<SupportedLanguage>): 'western'
401
573
  */
402
574
  declare function hyperfixi(options?: HyperfixiPluginOptions): Plugin;
403
575
 
404
- export { type AggregatedUsage, type CompileOptions, type CompiledHandler, type CustomLanguageKeywords, type FileUsage, type HyperfixiPluginOptions, REGIONS, SUPPORTED_LANGUAGES, type SupportedLanguage, clearCustomKeywords, clearSemanticParser, hyperfixi as default, detectLanguages, getAllLanguageCodes, getKeywordsForLanguage, getOptimalRegion, hasSemanticParser, hyperfixi, isNonLatinLanguage, registerCustomKeywords, setSemanticParser };
576
+ export { type AggregatedUsage, type CompileOptions, type CompiledHandler, type CustomLanguageKeywords, type DomainAggregatedUsage, DomainAggregator, type DomainFileUsage, type DomainScanRule, DomainScanner, type FileUsage, type HyperfixiPluginOptions, REGIONS, SUPPORTED_LANGUAGES, type ServerBridgeOptions, type SupportedLanguage, clearCustomKeywords, clearSemanticParser, hyperfixi as default, descriptorToScanRule, detectLanguages, getAllLanguageCodes, getKeywordsForLanguage, getOptimalRegion, hasSemanticParser, hyperfixi, isNonLatinLanguage, registerCustomKeywords, setSemanticParser };
package/dist/index.d.ts CHANGED
@@ -75,6 +75,22 @@ interface HyperfixiPluginOptions {
75
75
  * Enable verbose logging during development.
76
76
  */
77
77
  debug?: boolean;
78
+ /**
79
+ * Enable server-bridge route generation alongside bundle generation.
80
+ * Requires `@hyperfixi/server-bridge` to be installed as a peer dependency.
81
+ * If not installed, a warning is logged and the feature is silently skipped.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * hyperfixi({
86
+ * serverBridge: {
87
+ * framework: 'express',
88
+ * output: './server/routes',
89
+ * }
90
+ * })
91
+ * ```
92
+ */
93
+ serverBridge?: ServerBridgeOptions;
78
94
  /**
79
95
  * Enable semantic parsing for multilingual support.
80
96
  * - false: No semantic parsing (default, current behavior)
@@ -109,6 +125,26 @@ interface HyperfixiPluginOptions {
109
125
  * Useful for dynamic content not detectable at build time.
110
126
  */
111
127
  extraLanguages?: string[];
128
+ /**
129
+ * Register additional domains for scanning.
130
+ * Each domain declares its attribute patterns and keywords for detection.
131
+ * Runs alongside the default hyperscript scanner.
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * hyperfixi({
136
+ * domains: [
137
+ * {
138
+ * domain: 'sql',
139
+ * attributes: ['data-sql'],
140
+ * scriptTypes: ['text/sql-dsl'],
141
+ * keywords: { en: ['select', 'insert', 'update', 'delete'] },
142
+ * },
143
+ * ],
144
+ * })
145
+ * ```
146
+ */
147
+ domains?: DomainScanRule[];
112
148
  /**
113
149
  * Custom language keyword definitions.
114
150
  * Use this to add new languages or extend/override existing keyword detection.
@@ -206,6 +242,142 @@ interface AggregatedUsage {
206
242
  /** Map of file paths to their usage */
207
243
  fileUsage: Map<string, FileUsage>;
208
244
  }
245
+ /**
246
+ * Configuration for a domain's scanning rules in the Vite plugin.
247
+ */
248
+ interface DomainScanRule {
249
+ /** Domain name */
250
+ readonly domain: string;
251
+ /** Attribute names to scan for (e.g., ['data-sql', '_sql']) */
252
+ readonly attributes: readonly string[];
253
+ /** Script tag types to scan for (e.g., ['text/sql-dsl']) */
254
+ readonly scriptTypes?: readonly string[];
255
+ /** Keywords for command detection, keyed by language code */
256
+ readonly keywords?: Readonly<Record<string, readonly string[]>>;
257
+ }
258
+ /**
259
+ * Per-domain usage detected in a single file.
260
+ */
261
+ interface DomainFileUsage {
262
+ /** Domain name */
263
+ readonly domain: string;
264
+ /** Detected keywords/commands */
265
+ readonly detectedKeywords: Set<string>;
266
+ /** Languages detected */
267
+ readonly detectedLanguages: Set<string>;
268
+ /** Number of snippets found */
269
+ readonly snippetCount: number;
270
+ }
271
+ /**
272
+ * Aggregated usage across all files for a single domain.
273
+ */
274
+ interface DomainAggregatedUsage {
275
+ /** Domain name */
276
+ readonly domain: string;
277
+ /** All detected keywords across files */
278
+ readonly detectedKeywords: Set<string>;
279
+ /** All detected languages across files */
280
+ readonly detectedLanguages: Set<string>;
281
+ /** Number of files with this domain's usage */
282
+ readonly fileCount: number;
283
+ /** Total snippets across all files */
284
+ readonly totalSnippets: number;
285
+ }
286
+ /**
287
+ * Options for server-bridge route generation.
288
+ */
289
+ interface ServerBridgeOptions {
290
+ /** Target server framework (default: 'express') */
291
+ framework?: 'express' | 'hono' | 'openapi' | 'django' | 'fastapi';
292
+ /** Output directory for generated route files (default: './server/routes') */
293
+ output?: string;
294
+ /** Generate TypeScript (default: true) */
295
+ typescript?: boolean;
296
+ /** URL patterns to ignore */
297
+ ignore?: string[];
298
+ }
299
+
300
+ /**
301
+ * Domain Scanner for Vite Plugin
302
+ *
303
+ * Scans source files for domain-specific DSL usage based on configurable
304
+ * attribute patterns and keyword sets. Runs alongside the existing
305
+ * hyperscript Scanner as an opt-in feature.
306
+ */
307
+
308
+ /**
309
+ * Scanner that detects domain-specific syntax in source files.
310
+ * Complements the existing hyperscript Scanner.
311
+ */
312
+ declare class DomainScanner {
313
+ private rules;
314
+ /** Pre-compiled regex for fast hasAnyDomainUsage check */
315
+ private quickCheckPattern;
316
+ constructor(rules: readonly DomainScanRule[]);
317
+ /**
318
+ * Fast pre-check: does this code contain any domain-related attributes?
319
+ */
320
+ hasAnyDomainUsage(code: string): boolean;
321
+ /**
322
+ * Scan a file for all registered domain syntaxes.
323
+ * Returns one DomainFileUsage per domain that had matches.
324
+ */
325
+ scan(code: string, _id: string): DomainFileUsage[];
326
+ }
327
+ /**
328
+ * Convert a DomainDescriptor's scanConfig to a DomainScanRule.
329
+ * Returns null if the descriptor has no scanConfig.
330
+ *
331
+ * This allows DomainDescriptors from the framework to be used
332
+ * directly with the Vite plugin scanner.
333
+ */
334
+ declare function descriptorToScanRule(descriptor: {
335
+ name: string;
336
+ scanConfig?: {
337
+ attributes: readonly string[];
338
+ scriptTypes?: readonly string[];
339
+ keywords?: Readonly<Record<string, readonly string[]>>;
340
+ };
341
+ }): DomainScanRule | null;
342
+
343
+ /**
344
+ * Domain Aggregator
345
+ *
346
+ * Aggregates per-domain usage across files, following the same
347
+ * pattern as the existing hyperscript Aggregator.
348
+ */
349
+
350
+ /**
351
+ * Aggregates domain usage across multiple files.
352
+ */
353
+ declare class DomainAggregator {
354
+ private fileUsage;
355
+ private cache;
356
+ /**
357
+ * Add or update domain usage for a file.
358
+ * Returns true if usage changed (invalidates cache).
359
+ */
360
+ add(filePath: string, usage: DomainFileUsage[]): boolean;
361
+ /**
362
+ * Remove a file's domain usage.
363
+ * Returns true if the file was tracked.
364
+ */
365
+ remove(filePath: string): boolean;
366
+ /**
367
+ * Get aggregated usage across all files.
368
+ * Result is cached until add/remove changes it.
369
+ */
370
+ getUsage(): DomainAggregatedUsage[];
371
+ /**
372
+ * Get aggregated usage for a specific domain.
373
+ */
374
+ getUsageForDomain(domain: string): DomainAggregatedUsage | null;
375
+ /**
376
+ * Clear all tracked data.
377
+ */
378
+ clear(): void;
379
+ private isEqual;
380
+ }
209
381
 
210
382
  /**
211
383
  * Compiler
@@ -401,4 +573,4 @@ declare function getOptimalRegion(languages: Set<SupportedLanguage>): 'western'
401
573
  */
402
574
  declare function hyperfixi(options?: HyperfixiPluginOptions): Plugin;
403
575
 
404
- export { type AggregatedUsage, type CompileOptions, type CompiledHandler, type CustomLanguageKeywords, type FileUsage, type HyperfixiPluginOptions, REGIONS, SUPPORTED_LANGUAGES, type SupportedLanguage, clearCustomKeywords, clearSemanticParser, hyperfixi as default, detectLanguages, getAllLanguageCodes, getKeywordsForLanguage, getOptimalRegion, hasSemanticParser, hyperfixi, isNonLatinLanguage, registerCustomKeywords, setSemanticParser };
576
+ export { type AggregatedUsage, type CompileOptions, type CompiledHandler, type CustomLanguageKeywords, type DomainAggregatedUsage, DomainAggregator, type DomainFileUsage, type DomainScanRule, DomainScanner, type FileUsage, type HyperfixiPluginOptions, REGIONS, SUPPORTED_LANGUAGES, type ServerBridgeOptions, type SupportedLanguage, clearCustomKeywords, clearSemanticParser, hyperfixi as default, descriptorToScanRule, detectLanguages, getAllLanguageCodes, getKeywordsForLanguage, getOptimalRegion, hasSemanticParser, hyperfixi, isNonLatinLanguage, registerCustomKeywords, setSemanticParser };