@atomic-ehr/fhirpath 0.0.1-canary.0c6931e.20250727185306

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 (85) hide show
  1. package/README.md +473 -0
  2. package/dist/index.d.ts +462 -0
  3. package/dist/index.js +10307 -0
  4. package/dist/index.js.map +1 -0
  5. package/package.json +58 -0
  6. package/src/analyzer/analyzer.ts +499 -0
  7. package/src/analyzer/model-provider.ts +244 -0
  8. package/src/analyzer/schemas/index.ts +2 -0
  9. package/src/analyzer/schemas/types.ts +40 -0
  10. package/src/analyzer/types.ts +142 -0
  11. package/src/api/builder.ts +157 -0
  12. package/src/api/errors.ts +145 -0
  13. package/src/api/expression.ts +156 -0
  14. package/src/api/index.ts +122 -0
  15. package/src/api/inspect.ts +99 -0
  16. package/src/api/registry.ts +128 -0
  17. package/src/api/types.ts +210 -0
  18. package/src/compiler/compiler.ts +546 -0
  19. package/src/compiler/index.ts +2 -0
  20. package/src/compiler/prototype-context-adapter.ts +99 -0
  21. package/src/compiler/types.ts +24 -0
  22. package/src/index.ts +107 -0
  23. package/src/interpreter/README.md +78 -0
  24. package/src/interpreter/interpreter.ts +475 -0
  25. package/src/interpreter/types.ts +108 -0
  26. package/src/lexer/char-tables.ts +37 -0
  27. package/src/lexer/errors.ts +31 -0
  28. package/src/lexer/index.ts +5 -0
  29. package/src/lexer/lexer.ts +745 -0
  30. package/src/lexer/token.ts +104 -0
  31. package/src/lexer2/index.md +232 -0
  32. package/src/lexer2/index.perf.test.ts +68 -0
  33. package/src/lexer2/index.test.ts +549 -0
  34. package/src/lexer2/index.ts +1251 -0
  35. package/src/lexer2/notes.md +173 -0
  36. package/src/lexer2/optimization-summary.md +718 -0
  37. package/src/parser/ast-factory.ts +220 -0
  38. package/src/parser/ast.ts +144 -0
  39. package/src/parser/collection-parser.ts +89 -0
  40. package/src/parser/diagnostic-messages.ts +216 -0
  41. package/src/parser/diagnostics.ts +85 -0
  42. package/src/parser/error-reporter.ts +230 -0
  43. package/src/parser/index.ts +3 -0
  44. package/src/parser/literal-parser.ts +103 -0
  45. package/src/parser/parse-error.ts +16 -0
  46. package/src/parser/parser-error-factory.ts +141 -0
  47. package/src/parser/parser-state.ts +134 -0
  48. package/src/parser/parser.ts +1272 -0
  49. package/src/parser/pprint.ts +169 -0
  50. package/src/parser/precedence-manager.ts +64 -0
  51. package/src/parser/source-mapper.ts +248 -0
  52. package/src/parser/special-constructs.ts +142 -0
  53. package/src/parser/token-navigator.ts +110 -0
  54. package/src/parser/types.ts +60 -0
  55. package/src/parser2/index.md +177 -0
  56. package/src/parser2/index.perf.test.ts +184 -0
  57. package/src/parser2/index.test.ts +305 -0
  58. package/src/parser2/index.ts +578 -0
  59. package/src/parser2/optimization-summary.md +176 -0
  60. package/src/registry/default-analyzers.ts +257 -0
  61. package/src/registry/default-compilers.ts +31 -0
  62. package/src/registry/index.ts +96 -0
  63. package/src/registry/operations/arithmetic.ts +506 -0
  64. package/src/registry/operations/collection.ts +425 -0
  65. package/src/registry/operations/comparison.ts +432 -0
  66. package/src/registry/operations/existence.ts +703 -0
  67. package/src/registry/operations/filtering.ts +358 -0
  68. package/src/registry/operations/literals.ts +341 -0
  69. package/src/registry/operations/logical.ts +439 -0
  70. package/src/registry/operations/math.ts +128 -0
  71. package/src/registry/operations/membership.ts +132 -0
  72. package/src/registry/operations/navigation.ts +52 -0
  73. package/src/registry/operations/string.ts +507 -0
  74. package/src/registry/operations/subsetting.ts +174 -0
  75. package/src/registry/operations/type-checking.ts +162 -0
  76. package/src/registry/operations/type-conversion.ts +404 -0
  77. package/src/registry/operations/type-operators.ts +308 -0
  78. package/src/registry/operations/utility.ts +644 -0
  79. package/src/registry/registry.ts +146 -0
  80. package/src/registry/types.ts +161 -0
  81. package/src/registry/utils/evaluation-helpers.ts +93 -0
  82. package/src/registry/utils/index.ts +3 -0
  83. package/src/registry/utils/type-system.ts +173 -0
  84. package/src/runtime/context.ts +158 -0
  85. package/src/runtime/debug-context.ts +135 -0
@@ -0,0 +1,210 @@
1
+ import type { ASTNode } from '../parser/ast';
2
+ import type { TypeRef } from '../analyzer/types';
3
+ import type { RuntimeContext } from '../runtime/context';
4
+
5
+ // Core expression interface
6
+ export interface FHIRPathExpression {
7
+ readonly ast: ASTNode;
8
+ evaluate(input?: any, context?: EvaluationContext): any[];
9
+ compile(options?: CompileOptions): CompiledExpression;
10
+ analyze(options?: AnalyzeOptions): AnalysisResult;
11
+ toString(): string;
12
+ }
13
+
14
+ // Compiled expression function
15
+ export interface CompiledExpression {
16
+ (input?: any, context?: EvaluationContext): any[];
17
+ readonly source: string;
18
+ }
19
+
20
+ // Evaluation context for expressions
21
+ export interface EvaluationContext {
22
+ variables?: Record<string, any>;
23
+ environment?: Record<string, any>;
24
+ modelProvider?: ModelProvider;
25
+ customFunctions?: CustomFunctionMap;
26
+ }
27
+
28
+ // Custom function definition
29
+ export type CustomFunction = (
30
+ context: RuntimeContext,
31
+ input: any[],
32
+ ...args: any[]
33
+ ) => any[];
34
+
35
+ export type CustomFunctionMap = Record<string, CustomFunction>;
36
+
37
+ // Model provider interface
38
+ export interface ModelProvider {
39
+ resolveType(typeName: string): TypeRef | undefined;
40
+ getTypeHierarchy(typeName: string): string[];
41
+ getProperties(typeName: string): PropertyDefinition[];
42
+ getTypeName?(type: TypeRef): string;
43
+ }
44
+
45
+ export interface PropertyDefinition {
46
+ name: string;
47
+ type: string;
48
+ isCollection: boolean;
49
+ isRequired: boolean;
50
+ }
51
+
52
+ // Compilation options
53
+ export interface CompileOptions {
54
+ optimize?: boolean;
55
+ sourceMap?: boolean;
56
+ }
57
+
58
+ // Analysis options
59
+ export interface AnalyzeOptions {
60
+ modelProvider?: ModelProvider;
61
+ strict?: boolean;
62
+ }
63
+
64
+ // Analysis result
65
+ export interface AnalysisResult {
66
+ type: TypeRef;
67
+ isSingleton: boolean;
68
+ errors: AnalysisError[];
69
+ warnings: AnalysisWarning[];
70
+ }
71
+
72
+ export interface AnalysisError {
73
+ message: string;
74
+ location?: Location;
75
+ code: string;
76
+ }
77
+
78
+ export interface AnalysisWarning {
79
+ message: string;
80
+ location?: Location;
81
+ code: string;
82
+ }
83
+
84
+ export interface Location {
85
+ line: number;
86
+ column: number;
87
+ offset: number;
88
+ length: number;
89
+ }
90
+
91
+ // Registry API types
92
+ export interface RegistryAPI {
93
+ // List operations by type
94
+ listFunctions(): OperationMetadata[];
95
+ listOperators(): OperationMetadata[];
96
+ listAllOperations(): OperationMetadata[];
97
+
98
+ // Check existence
99
+ hasOperation(name: string): boolean;
100
+ hasFunction(name: string): boolean;
101
+ hasOperator(symbol: string): boolean;
102
+
103
+ // Get operation metadata (read-only view)
104
+ getOperationInfo(name: string): OperationInfo | undefined;
105
+
106
+ // Extension validation
107
+ canRegisterFunction(name: string): boolean;
108
+ }
109
+
110
+ // Simplified metadata for public consumption
111
+ export interface OperationMetadata {
112
+ name: string;
113
+ kind: 'function' | 'operator' | 'literal';
114
+ syntax: {
115
+ notation: string; // e.g., "a + b", "substring(start, length)"
116
+ };
117
+ }
118
+
119
+ export interface OperationInfo extends OperationMetadata {
120
+ signature: {
121
+ input?: {
122
+ types?: string[];
123
+ cardinality?: 'singleton' | 'collection' | 'any';
124
+ };
125
+ parameters?: Array<{
126
+ name: string;
127
+ types?: string[];
128
+ cardinality?: 'singleton' | 'collection' | 'any';
129
+ optional?: boolean;
130
+ }>;
131
+ output?: {
132
+ type?: string | 'dynamic';
133
+ cardinality?: 'singleton' | 'collection' | 'preserve-input';
134
+ };
135
+ };
136
+ description?: string;
137
+ examples?: string[];
138
+ }
139
+
140
+ // Builder interfaces
141
+ export interface FHIRPathBuilder {
142
+ withModelProvider(provider: ModelProvider): this;
143
+ withCustomFunction(name: string, fn: CustomFunction): this;
144
+ withVariable(name: string, value: any): this;
145
+ build(): FHIRPathAPI;
146
+ }
147
+
148
+ export interface FHIRPathAPI {
149
+ parse(expression: string): FHIRPathExpression;
150
+ evaluate(expression: string | FHIRPathExpression, input?: any): any[];
151
+ compile(expression: string | FHIRPathExpression): CompiledExpression;
152
+ analyze(expression: string | FHIRPathExpression): AnalysisResult;
153
+ inspect(expression: string | FHIRPathExpression, input?: any, context?: EvaluationContext): InspectResult;
154
+ registry: RegistryAPI;
155
+ }
156
+
157
+ // Inspect API types
158
+ export interface InspectResult {
159
+ result: any[];
160
+ expression: string;
161
+ ast: ASTNode;
162
+ executionTime: number;
163
+ traces: TraceEntry[];
164
+ evaluationSteps?: EvaluationStep[];
165
+ errors?: ErrorInfo[];
166
+ warnings?: WarningInfo[];
167
+ }
168
+
169
+ export interface TraceEntry {
170
+ name: string;
171
+ values: any[];
172
+ timestamp: number;
173
+ location?: SourceLocation;
174
+ depth: number;
175
+ }
176
+
177
+ export interface EvaluationStep {
178
+ nodeType: string;
179
+ expression: string;
180
+ input: any[];
181
+ output: any[];
182
+ variables: Record<string, any>;
183
+ timestamp: number;
184
+ duration: number;
185
+ }
186
+
187
+ export interface SourceLocation {
188
+ line: number;
189
+ column: number;
190
+ offset: number;
191
+ }
192
+
193
+ export interface ErrorInfo {
194
+ message: string;
195
+ type: string;
196
+ location?: SourceLocation;
197
+ stack?: string;
198
+ }
199
+
200
+ export interface WarningInfo {
201
+ message: string;
202
+ code: string;
203
+ location?: SourceLocation;
204
+ }
205
+
206
+ export interface InspectOptions {
207
+ recordSteps?: boolean;
208
+ maxTraces?: number;
209
+ maxSteps?: number;
210
+ }