mount-observer 0.1.28 → 0.1.30

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/README.md CHANGED
@@ -1555,6 +1555,264 @@ The handler looks for the nearest scope container using `.closest()`:
1555
1555
 
1556
1556
  IDs are generated using a global counter (via `Symbol.for`) to ensure uniqueness across multiple module instances. Generated IDs follow the pattern `gid-0`, `gid-1`, `gid-2`, etc.
1557
1557
 
1558
+ ## Scoped Parser Registry for EMC Scripts
1559
+
1560
+ The scoped parser registry system enables lazy-loading of complex parsers for enhancement attributes while maintaining framework isolation. Each synthesizer element (be-hive, htmx-container, alpine-scope, etc.) maintains its own parser registry to prevent conflicts between different framework libraries.
1561
+
1562
+ **Why use scoped parser registries?**
1563
+
1564
+ - Lazy load complex parsers only when needed (e.g., nested-regex-groups)
1565
+ - Maintain framework isolation (HTMX, Alpine, be-hive can coexist)
1566
+ - Declarative parser loading via HTML script tags
1567
+ - Programmatic parser registration for dynamic scenarios
1568
+ - Automatic parser waiting before enhancement initialization
1569
+ - Built-in parsers remain globally available
1570
+
1571
+ ### Basic Usage - Declarative Parser Loading
1572
+
1573
+ Load parsers declaratively using `<script type="emc-parser">` elements:
1574
+
1575
+ ```html
1576
+ <be-hive>
1577
+ <!-- Load parser first -->
1578
+ <script type="emc-parser"
1579
+ src="nested-regex-groups/parser.js"
1580
+ parser-name="nestedRegexGroups"></script>
1581
+
1582
+ <!-- Then load enhancement that depends on it -->
1583
+ <script type="emc"
1584
+ src="be-switched/emc.json"
1585
+ wait-for-parsers="nestedRegexGroups"></script>
1586
+ </be-hive>
1587
+
1588
+ <script type="module">
1589
+ import { MountObserver } from 'mount-observer/MountObserver.js';
1590
+
1591
+ // Bootstrap the handlers
1592
+ new MountObserver({
1593
+ do: 'builtIns.emcScript'
1594
+ }).observe(document);
1595
+ </script>
1596
+ ```
1597
+
1598
+ **What happens:**
1599
+
1600
+ 1. The `emc-parser` script loads the parser module via dynamic import
1601
+ 2. Parser is registered in the be-hive element's scoped registry
1602
+ 3. `parser-registered` event is dispatched
1603
+ 4. The `emc` script waits for the parser to be registered
1604
+ 5. Once ready, the enhancement is processed with access to the parser
1605
+
1606
+ ### Multiple Parsers
1607
+
1608
+ Wait for multiple parsers using space-delimited names:
1609
+
1610
+ ```html
1611
+ <be-hive>
1612
+ <script type="emc-parser" src="parser1.js" parser-name="parser1"></script>
1613
+ <script type="emc-parser" src="parser2.js" parser-name="parser2"></script>
1614
+
1615
+ <!-- Wait for both parsers -->
1616
+ <script type="emc"
1617
+ src="my-enhancement/emc.json"
1618
+ wait-for-parsers="parser1 parser2"></script>
1619
+ </be-hive>
1620
+ ```
1621
+
1622
+ ### Custom Timeout
1623
+
1624
+ Configure parser loading timeout (default: 60 seconds):
1625
+
1626
+ ```html
1627
+ <be-hive>
1628
+ <script type="emc-parser" src="slow-parser.js" parser-name="slowParser"></script>
1629
+
1630
+ <!-- Wait up to 2 minutes -->
1631
+ <script type="emc"
1632
+ src="my-enhancement/emc.json"
1633
+ wait-for-parsers="slowParser"
1634
+ data-parser-timeout="120000"></script>
1635
+ </be-hive>
1636
+ ```
1637
+
1638
+ ### Programmatic Parser Registration
1639
+
1640
+ Register parsers programmatically via JavaScript:
1641
+
1642
+ ```html
1643
+ <be-hive id="myHive">
1644
+ <script type="emc"
1645
+ src="my-enhancement/emc.json"
1646
+ wait-for-parsers="customParser"></script>
1647
+ </be-hive>
1648
+
1649
+ <script type="module">
1650
+ import { registerParser } from 'assign-gingerly/parserRegistry.js';
1651
+
1652
+ // Load parser programmatically
1653
+ const parser = await import('./custom-parser.js');
1654
+ const beHive = document.getElementById('myHive');
1655
+
1656
+ registerParser(beHive, 'customParser', parser.default);
1657
+ </script>
1658
+ ```
1659
+
1660
+ ### Parser Interface
1661
+
1662
+ Parsers are simple functions that transform attribute string values:
1663
+
1664
+ ```javascript
1665
+ // my-parser.js
1666
+ export default function parse(value) {
1667
+ // Transform the string value
1668
+ if (value === null) return null;
1669
+
1670
+ // Your parsing logic here
1671
+ return parsedValue;
1672
+ }
1673
+ ```
1674
+
1675
+ **Requirements:**
1676
+ - Parser must be a function with signature `(v: string | null) => any`
1677
+ - Must be exported as the default export
1678
+ - Should handle `null` values appropriately
1679
+ - Should throw descriptive errors for invalid input
1680
+
1681
+ ### Scoped vs Global Parsers
1682
+
1683
+ **Scoped parsers** (registered in be-hive elements):
1684
+ - Isolated to a specific synthesizer element and its descendants
1685
+ - Different frameworks can use the same parser names without conflicts
1686
+ - Registered via `emc-parser` scripts or `registerParser()`
1687
+
1688
+ **Global parsers** (built-in):
1689
+ - Available everywhere without registration
1690
+ - Includes: `timestamp`, `date`, `csv`, `int`, `float`, `boolean`, `json`
1691
+ - Fallback when parser not found in scoped registry
1692
+
1693
+ **Resolution order:**
1694
+ 1. Check scoped registry (if synthesizer element exists)
1695
+ 2. Fall back to global registry
1696
+ 3. Throw error if not found in either
1697
+
1698
+ ### Shadow DOM Syndication
1699
+
1700
+ Parser registries are scoped to synthesizer elements and apply to all shadow roots within that scope:
1701
+
1702
+ ```html
1703
+ <!-- Syndicator in document root -->
1704
+ <be-hive>
1705
+ <script type="emc-parser" src="parser.js" parser-name="myParser"></script>
1706
+ <script type="emc" src="enhancement/emc.json" wait-for-parsers="myParser"></script>
1707
+ </be-hive>
1708
+
1709
+ <!-- Component with shadow root -->
1710
+ <my-component>
1711
+ #shadow
1712
+ <!-- Subscriber receives scripts from syndicator -->
1713
+ <be-hive></be-hive>
1714
+
1715
+ <!-- Elements here can use the parser -->
1716
+ <div be-switched="...">Content</div>
1717
+ </my-component>
1718
+ ```
1719
+
1720
+ **How it works:**
1721
+ 1. Parser script is syndicated to shadow root's be-hive
1722
+ 2. Parser is registered in the shadow root's scoped registry
1723
+ 3. EMC script is syndicated and waits for parser
1724
+ 4. Enhancements in shadow root have access to the parser
1725
+
1726
+ ### Error Handling
1727
+
1728
+ **Parser loading errors:**
1729
+
1730
+ ```html
1731
+ <!-- Parser module fails to load -->
1732
+ <script type="emc-parser"
1733
+ src="broken-parser.js"
1734
+ parser-name="broken"
1735
+ data-parser-error="Module not found"></script>
1736
+ ```
1737
+
1738
+ **Parser waiting timeout:**
1739
+
1740
+ ```html
1741
+ <!-- EMC script times out waiting for parser -->
1742
+ <script type="emc"
1743
+ src="my-enhancement/emc.json"
1744
+ wait-for-parsers="missingParser"
1745
+ data-emc-error="Timeout waiting for parsers: missingParser"></script>
1746
+ ```
1747
+
1748
+ **Error messages include:**
1749
+ - Which parser(s) are missing
1750
+ - Which EMC script is waiting
1751
+ - Suggestions to check parser-name and script order
1752
+
1753
+ ### Complete Example
1754
+
1755
+ ```html
1756
+ <!DOCTYPE html>
1757
+ <html>
1758
+ <head>
1759
+ <script type="module">
1760
+ import { MountObserver } from 'mount-observer/MountObserver.js';
1761
+ import { Synthesizer } from 'mount-observer/Synthesizer.js';
1762
+
1763
+ // Define synthesizer element
1764
+ class BeHive extends Synthesizer {}
1765
+ customElements.define('be-hive', BeHive);
1766
+ </script>
1767
+ </head>
1768
+ <body>
1769
+ <!-- Syndicator with parser and enhancement -->
1770
+ <be-hive>
1771
+ <!-- Load complex parser -->
1772
+ <script type="emc-parser"
1773
+ src="nested-regex-groups/parser.js"
1774
+ parser-name="nestedRegexGroups"></script>
1775
+
1776
+ <!-- Enhancement that uses the parser -->
1777
+ <script type="emc"
1778
+ src="be-switched/emc.json"
1779
+ wait-for-parsers="nestedRegexGroups"></script>
1780
+ </be-hive>
1781
+
1782
+ <!-- Component using the enhancement -->
1783
+ <my-component>
1784
+ #shadow
1785
+ <be-hive></be-hive>
1786
+
1787
+ <!-- This element will be enhanced -->
1788
+ <div be-switched="case1: /pattern1/ | case2: /pattern2/">
1789
+ Content
1790
+ </div>
1791
+ </my-component>
1792
+ </body>
1793
+ </html>
1794
+ ```
1795
+
1796
+ ### Benefits
1797
+
1798
+ - **Lazy loading**: Load parsers only when needed
1799
+ - **Framework isolation**: Different frameworks don't conflict
1800
+ - **Declarative**: HTML-first approach with script tags
1801
+ - **Flexible**: Supports both declarative and programmatic registration
1802
+ - **Automatic**: Parser waiting handled by the framework
1803
+ - **Scoped**: Each synthesizer has its own parser registry
1804
+ - **Efficient**: Parsers are cached and reused
1805
+
1806
+ ### Requirements
1807
+
1808
+ - Must import `mount-observer/handlers/EMCParserScript.js` for parser loading
1809
+ - Must import `mount-observer/handlers/EMCScript.js` for EMC processing
1810
+ - Must use a synthesizer element (be-hive, etc.) for scoped registries
1811
+ - Parser modules must export a function as default export
1812
+ - EMC scripts must specify `wait-for-parsers` attribute to wait for parsers
1813
+
1814
+ [Implemented as Scoped Parser Registry requirement](.kiro/specs/scoped-parser-registry-requirements.md)
1815
+
1558
1816
 
1559
1817
  # Thorough Exposition Begins Here
1560
1818
 
package/Synthesizer.js CHANGED
@@ -11,6 +11,8 @@ import 'mount-observer/handlers/HoistTemplate.js';
11
11
  import { hoist } from 'mount-observer/handlers/HoistTemplate.js';
12
12
  import { emc } from 'mount-observer/handlers/EMCScript.js';
13
13
  import 'mount-observer/handlers/EMCScript.js';
14
+ import 'mount-observer/handlers/EMCParserScript.js';
15
+ import { emcParser } from 'mount-observer/handlers/EMCParserScript.js';
14
16
  /**
15
17
  * Track which root nodes have already had handlers activated.
16
18
  * Uses WeakSet to avoid memory leaks when nodes are garbage collected.
@@ -53,7 +55,7 @@ export class Synthesizer extends HTMLElement {
53
55
  * List of built-in handlers to activate.
54
56
  */
55
57
  static builtInHandlers = [
56
- mos, scriptExport, include, hoist, emc
58
+ mos, scriptExport, include, hoist, emcParser, emc
57
59
  ];
58
60
  connectedCallback() {
59
61
  // Synthesizer elements are infrastructure, not UI
@@ -145,7 +147,7 @@ export class Synthesizer extends HTMLElement {
145
147
  */
146
148
  #initializeSyndicator() {
147
149
  // Process existing script elements
148
- const scripts = this.querySelectorAll('script[type="mountobserver"], script[type="emc"]');
150
+ const scripts = this.querySelectorAll('script[type="mountobserver"], script[type="emc"], script[type="emc-parser"]');
149
151
  scripts.forEach(script => {
150
152
  if (this.checkIfAllowed(script)) {
151
153
  this.#broadcastScript(script);
@@ -157,7 +159,7 @@ export class Synthesizer extends HTMLElement {
157
159
  for (const node of mutation.addedNodes) {
158
160
  if (node instanceof HTMLScriptElement) {
159
161
  const type = node.getAttribute('type');
160
- if (type === 'mountobserver' || type === 'emc') {
162
+ if (type === 'mountobserver' || type === 'emc' || type === 'emc-parser') {
161
163
  if (this.checkIfAllowed(node)) {
162
164
  this.#broadcastScript(node);
163
165
  }
@@ -190,7 +192,7 @@ export class Synthesizer extends HTMLElement {
190
192
  }
191
193
  // Process existing scripts from syndicator
192
194
  // Only process scripts that pass the syndicator's filtering
193
- const scripts = syndicator.querySelectorAll('script[type="mountobserver"], script[type="emc"]');
195
+ const scripts = syndicator.querySelectorAll('script[type="mountobserver"], script[type="emc"], script[type="emc-parser"]');
194
196
  scripts.forEach(script => {
195
197
  if (syndicator.checkIfAllowed(script)) {
196
198
  this.#processScript(script);
package/Synthesizer.ts CHANGED
@@ -12,6 +12,8 @@ import 'mount-observer/handlers/HoistTemplate.js';
12
12
  import {hoist} from 'mount-observer/handlers/HoistTemplate.js';
13
13
  import {emc} from 'mount-observer/handlers/EMCScript.js';
14
14
  import 'mount-observer/handlers/EMCScript.js';
15
+ import 'mount-observer/handlers/EMCParserScript.js';
16
+ import {emcParser} from 'mount-observer/handlers/EMCParserScript.js';
15
17
 
16
18
  /**
17
19
  * Track which root nodes have already had handlers activated.
@@ -57,7 +59,7 @@ export abstract class Synthesizer extends HTMLElement {
57
59
  * List of built-in handlers to activate.
58
60
  */
59
61
  protected static builtInHandlers = [
60
- mos, scriptExport, include, hoist, emc
62
+ mos, scriptExport, include, hoist, emcParser, emc
61
63
  ];
62
64
 
63
65
  connectedCallback(): void {
@@ -164,7 +166,7 @@ export abstract class Synthesizer extends HTMLElement {
164
166
  */
165
167
  #initializeSyndicator(): void {
166
168
  // Process existing script elements
167
- const scripts = this.querySelectorAll('script[type="mountobserver"], script[type="emc"]');
169
+ const scripts = this.querySelectorAll('script[type="mountobserver"], script[type="emc"], script[type="emc-parser"]');
168
170
  scripts.forEach(script => {
169
171
  if (this.checkIfAllowed(script as HTMLScriptElement)) {
170
172
  this.#broadcastScript(script as HTMLScriptElement);
@@ -177,7 +179,7 @@ export abstract class Synthesizer extends HTMLElement {
177
179
  for (const node of mutation.addedNodes) {
178
180
  if (node instanceof HTMLScriptElement) {
179
181
  const type = node.getAttribute('type');
180
- if (type === 'mountobserver' || type === 'emc') {
182
+ if (type === 'mountobserver' || type === 'emc' || type === 'emc-parser') {
181
183
  if (this.checkIfAllowed(node)) {
182
184
  this.#broadcastScript(node);
183
185
  }
@@ -215,7 +217,7 @@ export abstract class Synthesizer extends HTMLElement {
215
217
 
216
218
  // Process existing scripts from syndicator
217
219
  // Only process scripts that pass the syndicator's filtering
218
- const scripts = syndicator.querySelectorAll('script[type="mountobserver"], script[type="emc"]');
220
+ const scripts = syndicator.querySelectorAll('script[type="mountobserver"], script[type="emc"], script[type="emc-parser"]');
219
221
  scripts.forEach(script => {
220
222
  if (syndicator.checkIfAllowed(script as HTMLScriptElement)) {
221
223
  this.#processScript(script as HTMLScriptElement);
@@ -0,0 +1,108 @@
1
+ import { EvtRt } from '../EvtRt.js';
2
+ import { getParserRegistry } from 'assign-gingerly/parserRegistry.js';
3
+ /**
4
+ * Handler for EMC Parser Script Elements.
5
+ * Processes script[type="emc-parser"] elements to load and register parser modules
6
+ * in the containing synthesizer element's scoped parser registry.
7
+ *
8
+ * Usage:
9
+ * <script type="emc-parser" src="./my-parser.js" parser-name="myParser"></script>
10
+ *
11
+ * The parser module should export a parser function as the default export:
12
+ * export default function myParser(v: string | null): any { ... }
13
+ */
14
+ export class EMCParserScriptHandler extends EvtRt {
15
+ // Static properties define default MountConfig constraints
16
+ static matching = 'script[type="emc-parser"]';
17
+ static whereInstanceOf = HTMLScriptElement;
18
+ async mount(mountedElement, mountConfig, context) {
19
+ this.abort(); // Clean up event listeners (one-time operation)
20
+ const scriptElement = mountedElement;
21
+ // Read required attributes
22
+ const src = scriptElement.getAttribute('src');
23
+ const parserName = scriptElement.getAttribute('parser-name');
24
+ // Validate required attributes
25
+ if (!src) {
26
+ const errorMsg = 'EMCParserScript: missing src attribute';
27
+ console.error(errorMsg, scriptElement);
28
+ scriptElement.setAttribute('data-parser-error', 'missing src attribute');
29
+ return;
30
+ }
31
+ if (!parserName) {
32
+ const errorMsg = 'EMCParserScript: missing parser-name attribute';
33
+ console.error(errorMsg, scriptElement);
34
+ scriptElement.setAttribute('data-parser-error', 'missing parser-name attribute');
35
+ return;
36
+ }
37
+ // Find containing synthesizer element
38
+ const synthesizerElement = this.findContainingSynthesizer(scriptElement);
39
+ if (!synthesizerElement) {
40
+ const errorMsg = 'EMCParserScript: no containing synthesizer element found';
41
+ console.error(errorMsg, scriptElement);
42
+ scriptElement.setAttribute('data-parser-error', 'no containing synthesizer element');
43
+ return;
44
+ }
45
+ try {
46
+ // Dynamic import the parser module
47
+ const module = await import(src);
48
+ // Get parser function from default export
49
+ const parser = module.default;
50
+ // Validate parser is a function
51
+ if (typeof parser !== 'function') {
52
+ throw new Error(`Parser module "${src}" must export a function as default export. ` +
53
+ `Received: ${typeof parser}`);
54
+ }
55
+ // Get scoped registry and register parser
56
+ const registry = getParserRegistry(synthesizerElement);
57
+ registry.register(parserName, parser);
58
+ // Dispatch parser-registered event
59
+ scriptElement.dispatchEvent(new CustomEvent('parser-registered', {
60
+ detail: { parserName },
61
+ bubbles: true
62
+ }));
63
+ }
64
+ catch (error) {
65
+ const errorMessage = error instanceof Error ? error.message : String(error);
66
+ console.error(`Failed to load parser "${parserName}" from "${src}":`, errorMessage);
67
+ scriptElement.setAttribute('data-parser-error', errorMessage);
68
+ }
69
+ }
70
+ /**
71
+ * Find the nearest ancestor synthesizer element.
72
+ * Traverses up through shadow root boundaries.
73
+ * Looks for elements with data-synthesizer attribute, be-hive tag, or __isSynthesizer property.
74
+ */
75
+ findContainingSynthesizer(element) {
76
+ let current = element;
77
+ while (current) {
78
+ if (current instanceof Element) {
79
+ // Check for synthesizer marker or known synthesizer tag names
80
+ if (current.hasAttribute('data-synthesizer') ||
81
+ current.localName === 'be-hive' ||
82
+ current.__isSynthesizer === true) {
83
+ return current;
84
+ }
85
+ }
86
+ // Try parent element
87
+ if (current.parentElement) {
88
+ current = current.parentElement;
89
+ }
90
+ // Try shadow root host
91
+ else if (current instanceof ShadowRoot) {
92
+ current = current.host;
93
+ }
94
+ // Try parent node (for document fragments)
95
+ else if (current.parentNode) {
96
+ current = current.parentNode;
97
+ }
98
+ else {
99
+ break;
100
+ }
101
+ }
102
+ return undefined;
103
+ }
104
+ }
105
+ // Register built-in handler
106
+ import { MountObserver } from '../MountObserver.js';
107
+ export const emcParser = 'builtIns.emcParserScript';
108
+ MountObserver.define(emcParser, EMCParserScriptHandler);
@@ -76,8 +76,6 @@ export class EMCParserScriptHandler extends EvtRt {
76
76
  bubbles: true
77
77
  }));
78
78
 
79
- console.log(`Registered parser "${parserName}" from ${src}`);
80
-
81
79
  } catch (error) {
82
80
  const errorMessage = error instanceof Error ? error.message : String(error);
83
81
  console.error(`Failed to load parser "${parserName}" from "${src}":`, errorMessage);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
7
7
  "dependencies": {
8
- "assign-gingerly": "0.0.27",
8
+ "assign-gingerly": "0.0.28",
9
9
  "id-generation": "0.0.4"
10
10
  },
11
11
  "devDependencies": {
@@ -112,7 +112,7 @@ export type ParserFunction<T = any> =
112
112
  | ((attrValue: string | null) => any)
113
113
  | ((attrValue: string | null, context?: ParserContext<T>) => any);
114
114
 
115
- export interface AttrConfig<T = any> {
115
+ export interface AttrConfig<T = unknown, TParserConfig = unknown> {
116
116
  /**
117
117
  * Type of the property value (JSON-serializable string format)
118
118
  */
@@ -152,6 +152,12 @@ export interface AttrConfig<T = any> {
152
152
  | ParserFunction<T>
153
153
  | string
154
154
  ;
155
+
156
+ /**
157
+ * configuration information needed by a custom parser to properly
158
+ * parse the attribute.
159
+ */
160
+ parserConfig?: TParserConfig;
155
161
 
156
162
  /**
157
163
  * Default value to use when attribute is missing
@@ -0,0 +1,28 @@
1
+ export interface Specifier {
2
+ selector?: string;
3
+ prop?: string;
4
+ }
5
+
6
+ export interface EndUserProps{
7
+ invokeParamSets: Array<InvokingParameters>,
8
+ }
9
+
10
+ export interface AllProps extends EndUserProps{
11
+ enhancedElement: Element;
12
+ rawStatements: Array<string>,
13
+ }
14
+
15
+ export type AP = AllProps;
16
+
17
+ export type PAP = Partial<AP>;
18
+
19
+ export type ProPAP = Promise<PAP>
20
+
21
+ export interface Actions{
22
+ hydrate(self: AP): ProPAP;
23
+ }
24
+
25
+ export interface InvokingParameters {
26
+ remoteSpecifier: Specifier,
27
+ localEventType?: string,
28
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Type definitions for nested-regex-groups
3
+ *
4
+ * These types can be imported in JavaScript files using JSDoc:
5
+ * @example
6
+ * // In JavaScript:
7
+ * /** @type {import('nested-regex-groups').ParseResult} *\/
8
+ * const result = parser('input');
9
+ */
10
+
11
+ /**
12
+ * Result of a successful parse operation
13
+ */
14
+ export interface ParseSuccess<T = any> {
15
+ success: true;
16
+ value: T;
17
+ matched: string;
18
+ rest: string;
19
+ }
20
+
21
+ /**
22
+ * Result of a failed parse operation
23
+ */
24
+ export interface ParseFailure {
25
+ success: false;
26
+ error: string;
27
+ position?: number;
28
+ }
29
+
30
+ /**
31
+ * Union type for parse results
32
+ */
33
+ export type ParseResult<T = any> = ParseSuccess<T> | ParseFailure;
34
+
35
+ /**
36
+ * A pattern definition with metadata (internal use with compiled RegExp)
37
+ */
38
+ export interface ParsePattern {
39
+ name: string;
40
+ regex: RegExp;
41
+ description?: string;
42
+ /**
43
+ * Optional mapping from regex group names to dot-notation paths
44
+ * Example: { user_name: 'user.name', user_domain: 'user.domain' }
45
+ */
46
+ groupMap?: Record<string, string>;
47
+ }
48
+
49
+ /**
50
+ * Pattern configuration for parsePatterns and parsePattern functions
51
+ * Used when loading patterns from JSON or defining patterns as strings
52
+ */
53
+ export interface PatternConfig {
54
+ name: string;
55
+ pattern: string;
56
+ description?: string;
57
+ }
58
+
59
+ /**
60
+ * Options for nestedRegex function
61
+ */
62
+ export interface NestedRegexOptions {
63
+ /**
64
+ * Optional name for the pattern (used in error messages)
65
+ */
66
+ name?: string;
67
+ /**
68
+ * Optional mapping from regex group names to dot-notation paths
69
+ * Example: { user_name: 'user.name', user_domain: 'user.domain' }
70
+ */
71
+ groupMap?: Record<string, string>;
72
+ }
73
+
74
+ /**
75
+ * Options for creating a parser
76
+ */
77
+ export interface ParserOptions {
78
+ /**
79
+ * If true, returns detailed error information when no pattern matches
80
+ */
81
+ verbose?: boolean;
82
+ }
83
+
84
+ /**
85
+ * Result type for parsing multiple statements
86
+ */
87
+ export interface StatementsResult<T = any> {
88
+ success: boolean;
89
+ statements: Array<{
90
+ pattern?: string;
91
+ value?: T;
92
+ error?: string;
93
+ matched?: string;
94
+ }>;
95
+ }