@lokascript/framework 2.0.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.
Files changed (181) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +142 -0
  3. package/dist/aot/aot-orchestrator.d.ts +75 -0
  4. package/dist/aot/aot-orchestrator.d.ts.map +1 -0
  5. package/dist/aot/domain-scanner.d.ts +27 -0
  6. package/dist/aot/domain-scanner.d.ts.map +1 -0
  7. package/dist/aot/index.d.ts +8 -0
  8. package/dist/aot/index.d.ts.map +1 -0
  9. package/dist/aot/types.d.ts +103 -0
  10. package/dist/aot/types.d.ts.map +1 -0
  11. package/dist/api/create-dsl.d.ts +91 -0
  12. package/dist/api/create-dsl.d.ts.map +1 -0
  13. package/dist/api/dispatcher.d.ts +108 -0
  14. package/dist/api/dispatcher.d.ts.map +1 -0
  15. package/dist/api/domain-registry.d.ts +152 -0
  16. package/dist/api/domain-registry.d.ts.map +1 -0
  17. package/dist/api/index.d.ts +7 -0
  18. package/dist/api/index.d.ts.map +1 -0
  19. package/dist/api/index.js +2082 -0
  20. package/dist/api/index.js.map +1 -0
  21. package/dist/core/index.d.ts +7 -0
  22. package/dist/core/index.d.ts.map +1 -0
  23. package/dist/core/index.js +2674 -0
  24. package/dist/core/index.js.map +1 -0
  25. package/dist/core/logger.d.ts +32 -0
  26. package/dist/core/logger.d.ts.map +1 -0
  27. package/dist/core/pattern-matching/index.d.ts +6 -0
  28. package/dist/core/pattern-matching/index.d.ts.map +1 -0
  29. package/dist/core/pattern-matching/index.js +1239 -0
  30. package/dist/core/pattern-matching/index.js.map +1 -0
  31. package/dist/core/pattern-matching/pattern-matcher.d.ts +239 -0
  32. package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -0
  33. package/dist/core/pattern-matching/utils/index.d.ts +6 -0
  34. package/dist/core/pattern-matching/utils/index.d.ts.map +1 -0
  35. package/dist/core/pattern-matching/utils/possessive-keywords.d.ts +38 -0
  36. package/dist/core/pattern-matching/utils/possessive-keywords.d.ts.map +1 -0
  37. package/dist/core/pattern-matching/utils/type-validation.d.ts +63 -0
  38. package/dist/core/pattern-matching/utils/type-validation.d.ts.map +1 -0
  39. package/dist/core/tokenization/base-tokenizer.d.ts +344 -0
  40. package/dist/core/tokenization/base-tokenizer.d.ts.map +1 -0
  41. package/dist/core/tokenization/char-classifiers.d.ts +56 -0
  42. package/dist/core/tokenization/char-classifiers.d.ts.map +1 -0
  43. package/dist/core/tokenization/default-extractors.d.ts +48 -0
  44. package/dist/core/tokenization/default-extractors.d.ts.map +1 -0
  45. package/dist/core/tokenization/extractors/index.d.ts +9 -0
  46. package/dist/core/tokenization/extractors/index.d.ts.map +1 -0
  47. package/dist/core/tokenization/extractors/operator.d.ts +23 -0
  48. package/dist/core/tokenization/extractors/operator.d.ts.map +1 -0
  49. package/dist/core/tokenization/extractors/punctuation.d.ts +22 -0
  50. package/dist/core/tokenization/extractors/punctuation.d.ts.map +1 -0
  51. package/dist/core/tokenization/extractors.d.ts +61 -0
  52. package/dist/core/tokenization/extractors.d.ts.map +1 -0
  53. package/dist/core/tokenization/index.d.ts +11 -0
  54. package/dist/core/tokenization/index.d.ts.map +1 -0
  55. package/dist/core/tokenization/index.js +1345 -0
  56. package/dist/core/tokenization/index.js.map +1 -0
  57. package/dist/core/tokenization/morphology/index.d.ts +5 -0
  58. package/dist/core/tokenization/morphology/index.d.ts.map +1 -0
  59. package/dist/core/tokenization/morphology/types.d.ts +110 -0
  60. package/dist/core/tokenization/morphology/types.d.ts.map +1 -0
  61. package/dist/core/tokenization/token-utils.d.ts +111 -0
  62. package/dist/core/tokenization/token-utils.d.ts.map +1 -0
  63. package/dist/core/types.d.ts +382 -0
  64. package/dist/core/types.d.ts.map +1 -0
  65. package/dist/core/types.js +108 -0
  66. package/dist/core/types.js.map +1 -0
  67. package/dist/generation/diagnostics.d.ts +120 -0
  68. package/dist/generation/diagnostics.d.ts.map +1 -0
  69. package/dist/generation/index.d.ts +7 -0
  70. package/dist/generation/index.d.ts.map +1 -0
  71. package/dist/generation/index.js +339 -0
  72. package/dist/generation/index.js.map +1 -0
  73. package/dist/generation/pattern-generator.d.ts +48 -0
  74. package/dist/generation/pattern-generator.d.ts.map +1 -0
  75. package/dist/generation/renderer.d.ts +115 -0
  76. package/dist/generation/renderer.d.ts.map +1 -0
  77. package/dist/grammar/index.d.ts +10 -0
  78. package/dist/grammar/index.d.ts.map +1 -0
  79. package/dist/grammar/index.js +391 -0
  80. package/dist/grammar/index.js.map +1 -0
  81. package/dist/grammar/transformer.d.ts +56 -0
  82. package/dist/grammar/transformer.d.ts.map +1 -0
  83. package/dist/grammar/types.d.ts +236 -0
  84. package/dist/grammar/types.d.ts.map +1 -0
  85. package/dist/index.cjs +4454 -0
  86. package/dist/index.cjs.map +1 -0
  87. package/dist/index.d.ts +46 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/index.js +4336 -0
  90. package/dist/index.js.map +1 -0
  91. package/dist/interfaces/dictionary.d.ts +82 -0
  92. package/dist/interfaces/dictionary.d.ts.map +1 -0
  93. package/dist/interfaces/index.d.ts +10 -0
  94. package/dist/interfaces/index.d.ts.map +1 -0
  95. package/dist/interfaces/profile-provider.d.ts +67 -0
  96. package/dist/interfaces/profile-provider.d.ts.map +1 -0
  97. package/dist/interfaces/value-extractor.d.ts +168 -0
  98. package/dist/interfaces/value-extractor.d.ts.map +1 -0
  99. package/dist/multilingual/index.d.ts +8 -0
  100. package/dist/multilingual/index.d.ts.map +1 -0
  101. package/dist/multilingual/index.js +1 -0
  102. package/dist/multilingual/index.js.map +1 -0
  103. package/dist/parsing/index.d.ts +8 -0
  104. package/dist/parsing/index.d.ts.map +1 -0
  105. package/dist/parsing/index.js +1415 -0
  106. package/dist/parsing/index.js.map +1 -0
  107. package/dist/parsing/multi-statement.d.ts +265 -0
  108. package/dist/parsing/multi-statement.d.ts.map +1 -0
  109. package/dist/schema/command-schema.d.ts +78 -0
  110. package/dist/schema/command-schema.d.ts.map +1 -0
  111. package/dist/schema/index.d.ts +5 -0
  112. package/dist/schema/index.d.ts.map +1 -0
  113. package/dist/schema/index.js +25 -0
  114. package/dist/schema/index.js.map +1 -0
  115. package/dist/test-setup.d.ts +9 -0
  116. package/dist/test-setup.d.ts.map +1 -0
  117. package/dist/testing/index.d.ts +50 -0
  118. package/dist/testing/index.d.ts.map +1 -0
  119. package/dist/testing/index.js +16969 -0
  120. package/dist/testing/index.js.map +1 -0
  121. package/package.json +122 -0
  122. package/src/__test__/fixtures/sql-dsl.ts +232 -0
  123. package/src/__test__/sql-integration.test.ts +189 -0
  124. package/src/__test__/test-utils.ts +260 -0
  125. package/src/aot/aot-orchestrator.test.ts +413 -0
  126. package/src/aot/aot-orchestrator.ts +238 -0
  127. package/src/aot/domain-scanner.ts +178 -0
  128. package/src/aot/index.ts +8 -0
  129. package/src/aot/types.ts +124 -0
  130. package/src/api/create-dsl.ts +367 -0
  131. package/src/api/dispatcher.test.ts +336 -0
  132. package/src/api/dispatcher.ts +222 -0
  133. package/src/api/domain-registry.test.ts +336 -0
  134. package/src/api/domain-registry.ts +500 -0
  135. package/src/api/index.ts +7 -0
  136. package/src/core/index.ts +7 -0
  137. package/src/core/logger.ts +130 -0
  138. package/src/core/pattern-matching/index.ts +6 -0
  139. package/src/core/pattern-matching/pattern-matcher.test.ts +900 -0
  140. package/src/core/pattern-matching/pattern-matcher.ts +1548 -0
  141. package/src/core/pattern-matching/pattern-matcher.ts.backup +1267 -0
  142. package/src/core/pattern-matching/utils/index.ts +6 -0
  143. package/src/core/pattern-matching/utils/possessive-keywords.ts +55 -0
  144. package/src/core/pattern-matching/utils/type-validation.test.ts +316 -0
  145. package/src/core/pattern-matching/utils/type-validation.ts +134 -0
  146. package/src/core/tokenization/base-tokenizer.ts +916 -0
  147. package/src/core/tokenization/char-classifiers.ts +79 -0
  148. package/src/core/tokenization/create-simple-tokenizer.test.ts +260 -0
  149. package/src/core/tokenization/default-extractors.ts +69 -0
  150. package/src/core/tokenization/extractors/index.ts +9 -0
  151. package/src/core/tokenization/extractors/operator.ts +75 -0
  152. package/src/core/tokenization/extractors/punctuation.ts +39 -0
  153. package/src/core/tokenization/extractors.ts +452 -0
  154. package/src/core/tokenization/index.ts +11 -0
  155. package/src/core/tokenization/morphology/index.ts +5 -0
  156. package/src/core/tokenization/morphology/types.ts +211 -0
  157. package/src/core/tokenization/token-utils.ts +252 -0
  158. package/src/core/types.ts +589 -0
  159. package/src/generation/diagnostics.test.ts +171 -0
  160. package/src/generation/diagnostics.ts +239 -0
  161. package/src/generation/index.ts +7 -0
  162. package/src/generation/pattern-generator.test.ts +430 -0
  163. package/src/generation/pattern-generator.ts +315 -0
  164. package/src/generation/renderer.test.ts +266 -0
  165. package/src/generation/renderer.ts +244 -0
  166. package/src/grammar/index.ts +12 -0
  167. package/src/grammar/transformer.ts +159 -0
  168. package/src/grammar/types.ts +630 -0
  169. package/src/index.ts +157 -0
  170. package/src/interfaces/dictionary.ts +123 -0
  171. package/src/interfaces/index.ts +10 -0
  172. package/src/interfaces/profile-provider.ts +88 -0
  173. package/src/interfaces/value-extractor.ts +435 -0
  174. package/src/multilingual/index.ts +9 -0
  175. package/src/parsing/index.ts +27 -0
  176. package/src/parsing/multi-statement.test.ts +480 -0
  177. package/src/parsing/multi-statement.ts +648 -0
  178. package/src/schema/command-schema.ts +118 -0
  179. package/src/schema/index.ts +5 -0
  180. package/src/test-setup.ts +45 -0
  181. package/src/testing/index.ts +137 -0
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Command Schema Types
3
+ *
4
+ * Defines the structure of DSL commands for pattern generation.
5
+ * These schemas are language-neutral and describe the semantic structure
6
+ * of commands rather than their surface syntax.
7
+ */
8
+
9
+ import type { ActionType, SemanticRole, SemanticValue, ExpectedType } from '../core/types';
10
+
11
+ /**
12
+ * Command schema - defines a DSL command's structure.
13
+ */
14
+ export interface CommandSchema {
15
+ /** The action type (command name) */
16
+ readonly action: ActionType;
17
+
18
+ /** Human-readable description */
19
+ readonly description: string;
20
+
21
+ /** Roles this command accepts */
22
+ readonly roles: RoleSpec[];
23
+
24
+ /** The primary role (what the command acts on) */
25
+ readonly primaryRole: SemanticRole;
26
+
27
+ /** Category for grouping (DSL-specific) */
28
+ readonly category: string;
29
+
30
+ /** Whether this command typically has a body (like event handlers, blocks) */
31
+ readonly hasBody?: boolean;
32
+
33
+ /** Notes about special handling or usage */
34
+ readonly notes?: string;
35
+ }
36
+
37
+ /**
38
+ * Role specification - defines a semantic role in a command.
39
+ */
40
+ export interface RoleSpec {
41
+ /** The semantic role */
42
+ readonly role: SemanticRole;
43
+
44
+ /** Description of what this role represents */
45
+ readonly description: string;
46
+
47
+ /** Whether this role is required */
48
+ readonly required: boolean;
49
+
50
+ /** Expected value types */
51
+ readonly expectedTypes: Array<ExpectedType>;
52
+
53
+ /** Default value if not provided */
54
+ readonly default?: SemanticValue;
55
+
56
+ /** Position hint for SVO languages (higher = earlier) */
57
+ readonly svoPosition?: number;
58
+
59
+ /** Position hint for SOV languages (higher = earlier) */
60
+ readonly sovPosition?: number;
61
+
62
+ /**
63
+ * Override the default role marker for this command.
64
+ * Maps language code to the marker to use (e.g., { en: 'from', ja: 'から' }).
65
+ * If not specified, uses the language profile's default roleMarker.
66
+ */
67
+ readonly markerOverride?: Record<string, string>;
68
+
69
+ /**
70
+ * Override the rendering marker separately from parsing.
71
+ * Used when the parsing grammar differs from rendered output.
72
+ * Maps language code to the rendering marker.
73
+ */
74
+ readonly renderOverride?: Record<string, string>;
75
+
76
+ /**
77
+ * When true, this role captures all remaining tokens until the next
78
+ * recognized marker keyword or end of input, joining their values
79
+ * with spaces into a single ExpressionValue.
80
+ *
81
+ * Only meaningful for the last role in a sequence or a role followed
82
+ * by a marked role. Default: false.
83
+ */
84
+ readonly greedy?: boolean;
85
+ }
86
+
87
+ /**
88
+ * Helper to create a command schema with sensible defaults.
89
+ * Provides defaults for description, category, and primaryRole.
90
+ */
91
+ export function defineCommand(
92
+ schema: Partial<CommandSchema> & Pick<CommandSchema, 'action' | 'roles'>
93
+ ): CommandSchema {
94
+ return {
95
+ description: schema.description || `${schema.action} command`,
96
+ category: schema.category || 'general',
97
+ primaryRole: schema.primaryRole || schema.roles[0]?.role || 'patient',
98
+ ...schema,
99
+ action: schema.action,
100
+ roles: schema.roles,
101
+ } as CommandSchema;
102
+ }
103
+
104
+ /**
105
+ * Helper to create a role spec with sensible defaults.
106
+ * Provides default for description.
107
+ */
108
+ export function defineRole(
109
+ role: Partial<RoleSpec> & Pick<RoleSpec, 'role' | 'required' | 'expectedTypes'>
110
+ ): RoleSpec {
111
+ return {
112
+ description: role.description || `${role.role} role`,
113
+ ...role,
114
+ role: role.role,
115
+ required: role.required,
116
+ expectedTypes: role.expectedTypes,
117
+ };
118
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Schema types for defining DSL commands
3
+ */
4
+
5
+ export * from './command-schema';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Global test setup for @lokascript/framework
3
+ * Runs before each test file to provide a clean testing environment
4
+ */
5
+
6
+ import { beforeEach, afterEach, vi } from 'vitest';
7
+
8
+ // Mock console methods to reduce test output noise
9
+ const consoleMethods = ['log', 'error', 'warn', 'info', 'debug'] as const;
10
+
11
+ beforeEach(() => {
12
+ // Reset all mocks before each test
13
+ vi.clearAllMocks();
14
+
15
+ // Mock console methods for cleaner test output
16
+ // Tests that specifically need console output can restore these
17
+ consoleMethods.forEach(method => {
18
+ if (method in console) {
19
+ vi.spyOn(console, method).mockImplementation(() => {});
20
+ }
21
+ });
22
+ });
23
+
24
+ afterEach(() => {
25
+ // Restore console methods after each test
26
+ consoleMethods.forEach(method => {
27
+ if (method in console) {
28
+ const spy = vi.mocked(console[method]);
29
+ if (spy && spy.mockRestore) {
30
+ spy.mockRestore();
31
+ }
32
+ }
33
+ });
34
+
35
+ // Clean up timers
36
+ vi.clearAllTimers();
37
+ });
38
+
39
+ /**
40
+ * Cleanup utility for manual cleanup in tests
41
+ */
42
+ export function cleanupGlobalState(): void {
43
+ vi.clearAllMocks();
44
+ vi.clearAllTimers();
45
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @lokascript/framework/testing — Test utilities for domain packages
3
+ *
4
+ * Provides assertion helpers and type guards for testing domain DSLs
5
+ * built on the framework. Import from '@lokascript/framework/testing'
6
+ * in test files only (requires vitest as a peer dependency).
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { expectSemanticNode, isLiteralValue } from '@lokascript/framework/testing';
11
+ *
12
+ * test('parses select command', () => {
13
+ * const node = dsl.parse('select name from users', 'en');
14
+ * expectSemanticNode(node, 'select', { columns: 'name', source: 'users' });
15
+ * });
16
+ * ```
17
+ */
18
+
19
+ import { expect } from 'vitest';
20
+ import type {
21
+ SemanticNode,
22
+ CommandSemanticNode,
23
+ SemanticValue,
24
+ LiteralValue,
25
+ SelectorValue,
26
+ ExpressionValue,
27
+ ReferenceValue,
28
+ } from '../core/types';
29
+
30
+ // =============================================================================
31
+ // Assertion Helpers
32
+ // =============================================================================
33
+
34
+ /**
35
+ * Assert that a semantic node has the expected action and role values.
36
+ * Role values can be strings (matched against `value` or `raw`) or full SemanticValue objects.
37
+ */
38
+ export function expectSemanticNode(
39
+ node: SemanticNode,
40
+ action: string,
41
+ roles: Record<string, string | SemanticValue>
42
+ ): void {
43
+ expect(node.kind).toBe('command');
44
+ expect(node.action).toBe(action);
45
+
46
+ const commandNode = node as CommandSemanticNode;
47
+
48
+ for (const [role, expectedValue] of Object.entries(roles)) {
49
+ const actualValue = commandNode.roles.get(role);
50
+ expect(actualValue, `Role '${role}' should be defined`).toBeDefined();
51
+
52
+ if (typeof expectedValue === 'string') {
53
+ if (actualValue && 'value' in actualValue) {
54
+ expect(actualValue.value).toBe(expectedValue);
55
+ } else if (actualValue && 'raw' in actualValue) {
56
+ expect(actualValue.raw).toBe(expectedValue);
57
+ }
58
+ } else {
59
+ expect(actualValue).toEqual(expectedValue);
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Assert that a value is a literal semantic value with the expected value.
66
+ */
67
+ export function expectLiteralValue(
68
+ value: SemanticValue | undefined,
69
+ expectedValue: string | number | boolean
70
+ ): void {
71
+ expect(value).toBeDefined();
72
+ expect(value).toHaveProperty('type', 'literal');
73
+ expect(value).toHaveProperty('value', expectedValue);
74
+ }
75
+
76
+ /**
77
+ * Assert that a value is a selector semantic value.
78
+ */
79
+ export function expectSelectorValue(
80
+ value: SemanticValue | undefined,
81
+ expectedSelector: string,
82
+ expectedKind?: SelectorValue['selectorKind']
83
+ ): void {
84
+ expect(value).toBeDefined();
85
+ expect(value).toHaveProperty('type', 'selector');
86
+ expect(value).toHaveProperty('value', expectedSelector);
87
+ if (expectedKind) {
88
+ expect(value).toHaveProperty('selectorKind', expectedKind);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Assert that a value is an expression semantic value.
94
+ */
95
+ export function expectExpressionValue(value: SemanticValue | undefined, expectedRaw: string): void {
96
+ expect(value).toBeDefined();
97
+ expect(value).toHaveProperty('type', 'expression');
98
+ expect(value).toHaveProperty('raw', expectedRaw);
99
+ }
100
+
101
+ /**
102
+ * Assert that a value is a reference semantic value.
103
+ */
104
+ export function expectReferenceValue(value: SemanticValue | undefined, expectedRef: string): void {
105
+ expect(value).toBeDefined();
106
+ expect(value).toHaveProperty('type', 'reference');
107
+ expect(value).toHaveProperty('value', expectedRef);
108
+ }
109
+
110
+ // =============================================================================
111
+ // Type Guards
112
+ // =============================================================================
113
+
114
+ /** Type guard for LiteralValue */
115
+ export function isLiteralValue(value: SemanticValue): value is LiteralValue {
116
+ return value.type === 'literal';
117
+ }
118
+
119
+ /** Type guard for SelectorValue */
120
+ export function isSelectorValue(value: SemanticValue): value is SelectorValue {
121
+ return value.type === 'selector';
122
+ }
123
+
124
+ /** Type guard for ExpressionValue */
125
+ export function isExpressionValue(value: SemanticValue): value is ExpressionValue {
126
+ return value.type === 'expression';
127
+ }
128
+
129
+ /** Type guard for ReferenceValue */
130
+ export function isReferenceValue(value: SemanticValue): value is ReferenceValue {
131
+ return value.type === 'reference';
132
+ }
133
+
134
+ /** Type guard for CommandSemanticNode */
135
+ export function isCommandNode(node: SemanticNode): node is CommandSemanticNode {
136
+ return node.kind === 'command';
137
+ }