@atomic-ehr/fhirpath 0.0.1-canary.1825db0.20250725140030
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 +400 -0
- package/dist/index.d.ts +398 -0
- package/dist/index.js +8372 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
- package/src/analyzer/analyzer.ts +486 -0
- package/src/analyzer/model-provider.ts +244 -0
- package/src/analyzer/schemas/index.ts +2 -0
- package/src/analyzer/schemas/types.ts +40 -0
- package/src/analyzer/types.ts +142 -0
- package/src/api/builder.ts +155 -0
- package/src/api/errors.ts +134 -0
- package/src/api/expression.ts +156 -0
- package/src/api/index.ts +70 -0
- package/src/api/inspect.ts +96 -0
- package/src/api/registry.ts +128 -0
- package/src/api/types.ts +210 -0
- package/src/compiler/compiler.ts +546 -0
- package/src/compiler/index.ts +2 -0
- package/src/compiler/prototype-context-adapter.ts +99 -0
- package/src/compiler/types.ts +24 -0
- package/src/index.ts +76 -0
- package/src/interpreter/README.md +78 -0
- package/src/interpreter/interpreter.ts +463 -0
- package/src/interpreter/types.ts +108 -0
- package/src/lexer/char-tables.ts +37 -0
- package/src/lexer/errors.ts +31 -0
- package/src/lexer/index.ts +5 -0
- package/src/lexer/lexer.ts +745 -0
- package/src/lexer/token.ts +104 -0
- package/src/parser/ast.ts +123 -0
- package/src/parser/index.ts +3 -0
- package/src/parser/parser.ts +701 -0
- package/src/parser/pprint.ts +169 -0
- package/src/registry/default-analyzers.ts +257 -0
- package/src/registry/default-compilers.ts +31 -0
- package/src/registry/index.ts +94 -0
- package/src/registry/operations/arithmetic.ts +506 -0
- package/src/registry/operations/collection.ts +425 -0
- package/src/registry/operations/comparison.ts +432 -0
- package/src/registry/operations/existence.ts +703 -0
- package/src/registry/operations/filtering.ts +358 -0
- package/src/registry/operations/literals.ts +341 -0
- package/src/registry/operations/logical.ts +439 -0
- package/src/registry/operations/math.ts +128 -0
- package/src/registry/operations/membership.ts +132 -0
- package/src/registry/operations/string.ts +507 -0
- package/src/registry/operations/subsetting.ts +174 -0
- package/src/registry/operations/type-checking.ts +162 -0
- package/src/registry/operations/type-conversion.ts +404 -0
- package/src/registry/operations/type-operators.ts +308 -0
- package/src/registry/operations/utility.ts +644 -0
- package/src/registry/registry.ts +146 -0
- package/src/registry/types.ts +161 -0
- package/src/registry/utils/evaluation-helpers.ts +93 -0
- package/src/registry/utils/index.ts +3 -0
- package/src/registry/utils/type-system.ts +173 -0
- package/src/runtime/context.ts +158 -0
- package/src/runtime/debug-context.ts +135 -0
package/src/api/types.ts
ADDED
|
@@ -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
|
+
}
|