@sneat/structured-data 0.0.0-stage → 0.27.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 +29 -2
- package/assets/hcl-worker.mjs +135 -0
- package/assets/tree-sitter-hcl.LICENSE +201 -0
- package/assets/tree-sitter-hcl.wasm +0 -0
- package/assets/web-tree-sitter.LICENSE +21 -0
- package/assets/web-tree-sitter.js +4081 -0
- package/assets/web-tree-sitter.wasm +0 -0
- package/fesm2022/sneat-structured-data-core.mjs +692 -0
- package/fesm2022/sneat-structured-data-core.mjs.map +1 -0
- package/fesm2022/sneat-structured-data.mjs +1163 -0
- package/fesm2022/sneat-structured-data.mjs.map +1 -0
- package/package.json +32 -3
- package/tsconfig.lib.prod.tsbuildinfo +1 -0
- package/types/sneat-structured-data-core.d.ts +253 -0
- package/types/sneat-structured-data.d.ts +327 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { OnChanges, AfterViewChecked, EventEmitter, SimpleChanges } from '@angular/core';
|
|
3
|
+
|
|
4
|
+
/** Public, transport-independent contract for @sneat/structured-data. */
|
|
5
|
+
type StructuredFormat = 'json' | 'yaml' | 'hcl';
|
|
6
|
+
/** Offsets and columns are UTF-16 code units; lines and columns are zero-based. */
|
|
7
|
+
interface SourcePosition {
|
|
8
|
+
readonly line: number;
|
|
9
|
+
readonly column: number;
|
|
10
|
+
}
|
|
11
|
+
/** Half-open range into the exact, unchanged sourceText of a document. */
|
|
12
|
+
interface SourceRange {
|
|
13
|
+
readonly startOffset: number;
|
|
14
|
+
readonly endOffset: number;
|
|
15
|
+
readonly start: SourcePosition;
|
|
16
|
+
readonly end: SourcePosition;
|
|
17
|
+
}
|
|
18
|
+
interface StructuredNull {
|
|
19
|
+
readonly kind: 'null';
|
|
20
|
+
readonly range?: SourceRange;
|
|
21
|
+
}
|
|
22
|
+
interface StructuredBoolean {
|
|
23
|
+
readonly kind: 'boolean';
|
|
24
|
+
readonly value: boolean;
|
|
25
|
+
readonly range?: SourceRange;
|
|
26
|
+
}
|
|
27
|
+
interface StructuredNumber {
|
|
28
|
+
readonly kind: 'number';
|
|
29
|
+
/** Exact numeric lexeme; the renderer never displays a rounded JS number. */
|
|
30
|
+
readonly sourceText: string;
|
|
31
|
+
/** Only supplied when conversion to a JS number is finite and lossless. */
|
|
32
|
+
readonly value?: number;
|
|
33
|
+
readonly range?: SourceRange;
|
|
34
|
+
}
|
|
35
|
+
interface StructuredString {
|
|
36
|
+
readonly kind: 'string';
|
|
37
|
+
readonly value: string;
|
|
38
|
+
readonly range?: SourceRange;
|
|
39
|
+
}
|
|
40
|
+
/** Never evaluate or silently coerce an HCL expression into a string. */
|
|
41
|
+
interface StructuredExpression {
|
|
42
|
+
readonly kind: 'expression';
|
|
43
|
+
readonly sourceText: string;
|
|
44
|
+
readonly range: SourceRange;
|
|
45
|
+
}
|
|
46
|
+
interface StructuredArray {
|
|
47
|
+
readonly kind: 'array';
|
|
48
|
+
readonly items: readonly StructuredValue[];
|
|
49
|
+
readonly range?: SourceRange;
|
|
50
|
+
}
|
|
51
|
+
interface StructuredObjectEntry {
|
|
52
|
+
readonly key: string;
|
|
53
|
+
readonly value: StructuredValue;
|
|
54
|
+
readonly range?: SourceRange;
|
|
55
|
+
}
|
|
56
|
+
interface StructuredObject {
|
|
57
|
+
readonly kind: 'object';
|
|
58
|
+
readonly entries: readonly StructuredObjectEntry[];
|
|
59
|
+
readonly range?: SourceRange;
|
|
60
|
+
}
|
|
61
|
+
type StructuredValue = StructuredNull | StructuredBoolean | StructuredNumber | StructuredString | StructuredExpression | StructuredArray | StructuredObject;
|
|
62
|
+
interface HclAttribute {
|
|
63
|
+
readonly kind: 'hcl-attribute';
|
|
64
|
+
readonly name: string;
|
|
65
|
+
readonly value: StructuredValue;
|
|
66
|
+
readonly range: SourceRange;
|
|
67
|
+
}
|
|
68
|
+
interface HclBlock {
|
|
69
|
+
readonly kind: 'hcl-block';
|
|
70
|
+
readonly blockType: string;
|
|
71
|
+
readonly labels: readonly string[];
|
|
72
|
+
readonly body: HclBody;
|
|
73
|
+
readonly range: SourceRange;
|
|
74
|
+
}
|
|
75
|
+
/** Members retain exact source order, including repeated blocks and labels. */
|
|
76
|
+
interface HclBody {
|
|
77
|
+
readonly kind: 'hcl-body';
|
|
78
|
+
readonly members: readonly (HclAttribute | HclBlock)[];
|
|
79
|
+
readonly range: SourceRange;
|
|
80
|
+
}
|
|
81
|
+
type StructuredNode = StructuredValue | HclBody | HclBlock | HclAttribute;
|
|
82
|
+
interface StructuredDocument {
|
|
83
|
+
readonly format: StructuredFormat;
|
|
84
|
+
readonly root: StructuredValue | HclBody;
|
|
85
|
+
/** The exact original text. Parsing never rewrites this source snapshot. */
|
|
86
|
+
readonly sourceText: string;
|
|
87
|
+
}
|
|
88
|
+
type StructuredDiagnosticCode = 'invalid_syntax' | 'unsupported_format' | 'unsupported_construct' | 'invalid_config' | 'limit_exceeded' | 'parser_unavailable';
|
|
89
|
+
interface StructuredDiagnostic {
|
|
90
|
+
readonly code: StructuredDiagnosticCode;
|
|
91
|
+
readonly message: string;
|
|
92
|
+
readonly severity: 'error' | 'warning';
|
|
93
|
+
readonly range?: SourceRange;
|
|
94
|
+
readonly source?: string;
|
|
95
|
+
}
|
|
96
|
+
interface StructuredLimits {
|
|
97
|
+
readonly maxSourceBytes?: number;
|
|
98
|
+
readonly maxNodes?: number;
|
|
99
|
+
readonly maxDepth?: number;
|
|
100
|
+
readonly maxRows?: number;
|
|
101
|
+
readonly maxConfigBytes?: number;
|
|
102
|
+
readonly maxRules?: number;
|
|
103
|
+
readonly maxSections?: number;
|
|
104
|
+
readonly maxSelectorLength?: number;
|
|
105
|
+
readonly maxSelectorDepth?: number;
|
|
106
|
+
readonly maxYamlAliases?: number;
|
|
107
|
+
readonly timeoutMs?: number;
|
|
108
|
+
}
|
|
109
|
+
type ParseResult = {
|
|
110
|
+
readonly ok: true;
|
|
111
|
+
readonly document: StructuredDocument;
|
|
112
|
+
readonly diagnostics: readonly StructuredDiagnostic[];
|
|
113
|
+
} | {
|
|
114
|
+
readonly ok: false;
|
|
115
|
+
readonly diagnostics: readonly StructuredDiagnostic[];
|
|
116
|
+
};
|
|
117
|
+
type ScalarListLayout = 'inline' | 'list';
|
|
118
|
+
type CollectionPresentation = 'list' | 'accordion';
|
|
119
|
+
type InitialExpansion = 'first' | 'all' | 'none';
|
|
120
|
+
interface ViewTitle {
|
|
121
|
+
readonly label: string;
|
|
122
|
+
readonly path: string;
|
|
123
|
+
}
|
|
124
|
+
interface ViewField {
|
|
125
|
+
readonly label: string;
|
|
126
|
+
readonly path: string;
|
|
127
|
+
readonly scalarListLayout?: ScalarListLayout;
|
|
128
|
+
}
|
|
129
|
+
interface ViewColumn {
|
|
130
|
+
readonly label: string;
|
|
131
|
+
readonly path: string;
|
|
132
|
+
}
|
|
133
|
+
interface ViewEntryLayout {
|
|
134
|
+
/** $key for dictionary entries; $label/N for HCL block labels. */
|
|
135
|
+
readonly heading: string;
|
|
136
|
+
readonly sections?: readonly ViewSection[];
|
|
137
|
+
}
|
|
138
|
+
interface ViewSectionBase {
|
|
139
|
+
readonly id: string;
|
|
140
|
+
readonly title: string;
|
|
141
|
+
/** Relative JSON Pointer, or empty string for the current value. */
|
|
142
|
+
readonly path: string;
|
|
143
|
+
}
|
|
144
|
+
interface FieldsSection extends ViewSectionBase {
|
|
145
|
+
readonly kind: 'fields';
|
|
146
|
+
readonly fields: readonly ViewField[];
|
|
147
|
+
}
|
|
148
|
+
interface ValueSection extends ViewSectionBase {
|
|
149
|
+
readonly kind: 'value';
|
|
150
|
+
readonly scalarListLayout?: ScalarListLayout;
|
|
151
|
+
}
|
|
152
|
+
interface EntriesSection extends ViewSectionBase {
|
|
153
|
+
readonly kind: 'entries';
|
|
154
|
+
readonly presentation?: CollectionPresentation;
|
|
155
|
+
readonly allowLayoutSwitch?: boolean;
|
|
156
|
+
readonly initiallyExpanded?: InitialExpansion;
|
|
157
|
+
readonly entry?: ViewEntryLayout;
|
|
158
|
+
}
|
|
159
|
+
interface TableSection extends ViewSectionBase {
|
|
160
|
+
readonly kind: 'table';
|
|
161
|
+
readonly rows: 'dictionary' | 'list' | 'blocks';
|
|
162
|
+
readonly blockType?: string;
|
|
163
|
+
readonly columns: readonly ViewColumn[];
|
|
164
|
+
}
|
|
165
|
+
interface BlocksSection extends ViewSectionBase {
|
|
166
|
+
readonly kind: 'blocks';
|
|
167
|
+
readonly blockType: string;
|
|
168
|
+
readonly presentation?: CollectionPresentation;
|
|
169
|
+
readonly allowLayoutSwitch?: boolean;
|
|
170
|
+
readonly initiallyExpanded?: InitialExpansion;
|
|
171
|
+
readonly entry?: ViewEntryLayout;
|
|
172
|
+
}
|
|
173
|
+
type ViewSection = FieldsSection | ValueSection | EntriesSection | TableSection | BlocksSection;
|
|
174
|
+
interface ViewRule {
|
|
175
|
+
readonly id: string;
|
|
176
|
+
readonly match: string;
|
|
177
|
+
readonly parser: StructuredFormat;
|
|
178
|
+
readonly title?: ViewTitle;
|
|
179
|
+
readonly sections?: readonly ViewSection[];
|
|
180
|
+
}
|
|
181
|
+
interface StructuredViewConfig {
|
|
182
|
+
readonly version: 1;
|
|
183
|
+
readonly rules: readonly ViewRule[];
|
|
184
|
+
}
|
|
185
|
+
/** Host supplies these from one pinned revision, root first and nearest last. */
|
|
186
|
+
interface OrderedViewConfigDocument {
|
|
187
|
+
readonly sourcePath: string;
|
|
188
|
+
readonly config: unknown;
|
|
189
|
+
}
|
|
190
|
+
type ValidationResult = {
|
|
191
|
+
readonly ok: true;
|
|
192
|
+
readonly config: StructuredViewConfig;
|
|
193
|
+
} | {
|
|
194
|
+
readonly ok: false;
|
|
195
|
+
readonly diagnostics: readonly StructuredDiagnostic[];
|
|
196
|
+
};
|
|
197
|
+
type ResolutionResult = {
|
|
198
|
+
readonly status: 'matched';
|
|
199
|
+
readonly parser: StructuredFormat;
|
|
200
|
+
readonly view: ViewRule;
|
|
201
|
+
} | {
|
|
202
|
+
readonly status: 'generic';
|
|
203
|
+
readonly parser: StructuredFormat;
|
|
204
|
+
} | {
|
|
205
|
+
readonly status: 'unsupported';
|
|
206
|
+
readonly diagnostics: readonly StructuredDiagnostic[];
|
|
207
|
+
} | {
|
|
208
|
+
readonly status: 'error';
|
|
209
|
+
readonly diagnostics: readonly StructuredDiagnostic[];
|
|
210
|
+
};
|
|
211
|
+
interface ResolveViewOptions {
|
|
212
|
+
readonly repositoryPath: string;
|
|
213
|
+
readonly orderedDocuments: readonly OrderedViewConfigDocument[];
|
|
214
|
+
/** App defaults precede root-to-nearest repository documents. */
|
|
215
|
+
readonly builtInRules?: readonly ViewRule[];
|
|
216
|
+
readonly limits?: StructuredLimits;
|
|
217
|
+
}
|
|
218
|
+
type SelectionResult = {
|
|
219
|
+
readonly found: true;
|
|
220
|
+
readonly value: StructuredNode;
|
|
221
|
+
} | {
|
|
222
|
+
readonly found: false;
|
|
223
|
+
};
|
|
224
|
+
interface ViewRowContext {
|
|
225
|
+
readonly node: StructuredNode;
|
|
226
|
+
readonly key?: string;
|
|
227
|
+
readonly labels?: readonly string[];
|
|
228
|
+
/** Hierarchical, stable section path for nested row links and independent controls. */
|
|
229
|
+
readonly pathId?: string;
|
|
230
|
+
}
|
|
231
|
+
interface StructuredSectionSelection {
|
|
232
|
+
readonly sectionId: string;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
declare const DEFAULT_LIMITS: Required<StructuredLimits>;
|
|
236
|
+
|
|
237
|
+
declare function parseJsonText(sourceText: string, limits?: StructuredLimits): ParseResult;
|
|
238
|
+
|
|
239
|
+
declare function parseYamlText(sourceText: string, limits?: StructuredLimits): ParseResult;
|
|
240
|
+
|
|
241
|
+
/** Loads only same-origin packaged assets, and only when invoked in a browser. */
|
|
242
|
+
declare function parseHclText(sourceText: string, limits?: StructuredLimits): Promise<ParseResult>;
|
|
243
|
+
|
|
244
|
+
/** RFC 6901 without wildcards, evaluation, or prototype traversal. */
|
|
245
|
+
declare function parseRelativePointer(pointer: string, maxLength?: number, maxDepth?: number): readonly string[] | null;
|
|
246
|
+
declare function selectRelative(node: StructuredNode, pointer: string): SelectionResult;
|
|
247
|
+
declare function selectViewPath(context: ViewRowContext, path: string): SelectionResult;
|
|
248
|
+
|
|
249
|
+
declare function validateViewConfig(input: unknown, limits?: StructuredLimits): ValidationResult;
|
|
250
|
+
declare function parseViewConfigText(textSource: string, format: 'json' | 'yaml', sourcePath?: string, limits?: StructuredLimits): ValidationResult;
|
|
251
|
+
declare function resolveViewRule(options: ResolveViewOptions): ResolutionResult;
|
|
252
|
+
|
|
253
|
+
declare function parseStructuredText(sourceText: string, format: StructuredFormat, limits?: StructuredLimits): Promise<ParseResult>;
|
|
254
|
+
|
|
255
|
+
interface StructuredDisplayRow extends ViewRowContext {
|
|
256
|
+
readonly id: string;
|
|
257
|
+
readonly title: string;
|
|
258
|
+
}
|
|
259
|
+
declare class StructuredDataViewerComponent implements OnChanges, AfterViewChecked {
|
|
260
|
+
private readonly host;
|
|
261
|
+
document: StructuredDocument | null;
|
|
262
|
+
view: ViewRule | null;
|
|
263
|
+
activeSectionId: string | null;
|
|
264
|
+
diagnostics: readonly StructuredDiagnostic[];
|
|
265
|
+
sourceText: string;
|
|
266
|
+
showRawFallback: boolean;
|
|
267
|
+
limits: StructuredLimits;
|
|
268
|
+
sourcePositionSelected: EventEmitter<SourceRange>;
|
|
269
|
+
sectionSelected: EventEmitter<StructuredSectionSelection>;
|
|
270
|
+
private readonly expanded;
|
|
271
|
+
private readonly layouts;
|
|
272
|
+
private lastNavigatedId;
|
|
273
|
+
ngOnChanges(changes: SimpleChanges): void;
|
|
274
|
+
ngAfterViewChecked(): void;
|
|
275
|
+
get maxRows(): number;
|
|
276
|
+
get maxDepth(): number;
|
|
277
|
+
get sections(): readonly ViewSection[];
|
|
278
|
+
get rootContext(): ViewRowContext | null;
|
|
279
|
+
get rawFallbackText(): string;
|
|
280
|
+
titleText(): string | null;
|
|
281
|
+
selected(context: ViewRowContext, path: string): StructuredNode | null;
|
|
282
|
+
shortText(node: StructuredNode): string;
|
|
283
|
+
selectSection(sectionId: string): void;
|
|
284
|
+
sectionId(section: ViewSection, context: ViewRowContext): string;
|
|
285
|
+
rowActivated(row: StructuredDisplayRow): void;
|
|
286
|
+
private rowPath;
|
|
287
|
+
rowsFor(section: ViewSection, context: ViewRowContext): StructuredDisplayRow[];
|
|
288
|
+
totalRows(section: ViewSection, context: ViewRowContext): number;
|
|
289
|
+
rowLimitNotice(section: ViewSection, context: ViewRowContext): string | null;
|
|
290
|
+
entryHeading(entry: ViewEntryLayout | undefined, context: ViewRowContext, fallback: string): string;
|
|
291
|
+
entrySections(section: ViewSection): readonly ViewSection[];
|
|
292
|
+
layoutFor(section: ViewSection, context: ViewRowContext): CollectionPresentation;
|
|
293
|
+
setLayout(section: ViewSection, context: ViewRowContext, layout: CollectionPresentation): void;
|
|
294
|
+
expandedValues(section: ViewSection, context: ViewRowContext, rows: readonly StructuredDisplayRow[]): string[];
|
|
295
|
+
setExpandedValues(section: ViewSection, context: ViewRowContext, values: string | number | readonly (string | number)[] | null | undefined): void;
|
|
296
|
+
expandAll(section: ViewSection, context: ViewRowContext, rows: readonly StructuredDisplayRow[]): void;
|
|
297
|
+
collapseAll(section: ViewSection, context: ViewRowContext): void;
|
|
298
|
+
limitedFields(fields: readonly {
|
|
299
|
+
label: string;
|
|
300
|
+
node: StructuredNode;
|
|
301
|
+
}[]): readonly {
|
|
302
|
+
label: string;
|
|
303
|
+
node: StructuredNode;
|
|
304
|
+
}[];
|
|
305
|
+
omittedFields(fields: readonly {
|
|
306
|
+
label: string;
|
|
307
|
+
node: StructuredNode;
|
|
308
|
+
}[]): number;
|
|
309
|
+
otherFields(node: StructuredNode, sections: readonly ViewSection[]): readonly {
|
|
310
|
+
label: string;
|
|
311
|
+
node: StructuredNode;
|
|
312
|
+
}[];
|
|
313
|
+
fieldOther(node: StructuredNode, section: ViewSection): readonly {
|
|
314
|
+
label: string;
|
|
315
|
+
node: StructuredNode;
|
|
316
|
+
}[];
|
|
317
|
+
tableOtherFields(node: StructuredNode, section: ViewSection): readonly {
|
|
318
|
+
label: string;
|
|
319
|
+
node: StructuredNode;
|
|
320
|
+
}[];
|
|
321
|
+
tableFallbackNode(node: StructuredNode): boolean;
|
|
322
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<StructuredDataViewerComponent, never>;
|
|
323
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<StructuredDataViewerComponent, "sneat-structured-data-viewer", never, { "document": { "alias": "document"; "required": false; }; "view": { "alias": "view"; "required": false; }; "activeSectionId": { "alias": "activeSectionId"; "required": false; }; "diagnostics": { "alias": "diagnostics"; "required": false; }; "sourceText": { "alias": "sourceText"; "required": false; }; "showRawFallback": { "alias": "showRawFallback"; "required": false; }; "limits": { "alias": "limits"; "required": false; }; }, { "sourcePositionSelected": "sourcePositionSelected"; "sectionSelected": "sectionSelected"; }, never, never, true, never>;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export { DEFAULT_LIMITS, StructuredDataViewerComponent, parseHclText, parseJsonText, parseRelativePointer, parseStructuredText, parseViewConfigText, parseYamlText, resolveViewRule, selectRelative, selectViewPath, validateViewConfig };
|
|
327
|
+
export type { BlocksSection, CollectionPresentation, EntriesSection, FieldsSection, HclAttribute, HclBlock, HclBody, InitialExpansion, OrderedViewConfigDocument, ParseResult, ResolutionResult, ResolveViewOptions, ScalarListLayout, SelectionResult, SourcePosition, SourceRange, StructuredArray, StructuredBoolean, StructuredDiagnostic, StructuredDiagnosticCode, StructuredDocument, StructuredExpression, StructuredFormat, StructuredLimits, StructuredNode, StructuredNull, StructuredNumber, StructuredObject, StructuredObjectEntry, StructuredSectionSelection, StructuredString, StructuredValue, StructuredViewConfig, TableSection, ValidationResult, ValueSection, ViewColumn, ViewEntryLayout, ViewField, ViewRowContext, ViewRule, ViewSection, ViewSectionBase, ViewTitle };
|