sec-edgar-api 0.5.12 → 1.0.1

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.
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Practical examples of working with XBRL relationships using your existing types
3
+ */
4
+ import type { XbrlInstance, XbrlLinkbase } from '../types';
5
+ /**
6
+ * Example 1: Extract presentation hierarchy from your XBRL data
7
+ */
8
+ export declare function extractPresentationHierarchy(presentationLinkbase: XbrlLinkbase): Record<string, ConceptNode>;
9
+ /**
10
+ * Example 2: Extract calculation relationships
11
+ */
12
+ export declare function extractCalculationRelationships(calculationLinkbase: XbrlLinkbase): Record<string, CalculationRule>;
13
+ /**
14
+ * Example 3: Extract dimensional relationships (axis/member mappings)
15
+ */
16
+ export declare function extractDimensionalRelationships(definitionLinkbase: XbrlLinkbase): Record<string, DimensionStructure>;
17
+ /**
18
+ * Example 4: Find facts with specific dimensional context
19
+ */
20
+ export declare function findFactsWithDimensions(instance: XbrlInstance, conceptName: string, dimensionFilters?: {
21
+ dimension: string;
22
+ member?: string;
23
+ }[]): {
24
+ fact: import("../types").XbrlElement;
25
+ context: import("../types").XbrlContext;
26
+ dimensions: {
27
+ dimension: string;
28
+ member: string;
29
+ }[];
30
+ }[];
31
+ /**
32
+ * Example 5: Build a complete concept map with all relationships
33
+ */
34
+ export declare function buildCompleteConceptMap(linkbases: {
35
+ presentation: XbrlLinkbase;
36
+ calculation: XbrlLinkbase;
37
+ definition: XbrlLinkbase;
38
+ label: XbrlLinkbase;
39
+ }): Map<string, CompleteConcept>;
40
+ interface ConceptNode {
41
+ concept: string;
42
+ children: ConceptChild[];
43
+ role: string;
44
+ order: number;
45
+ }
46
+ interface ConceptChild {
47
+ concept: string;
48
+ order: number;
49
+ preferredLabel?: string;
50
+ }
51
+ interface CalculationRule {
52
+ summationItem: string;
53
+ contributingItems: CalculationItem[];
54
+ }
55
+ interface CalculationItem {
56
+ concept: string;
57
+ weight: number;
58
+ order: number;
59
+ }
60
+ interface DimensionStructure {
61
+ concept: string;
62
+ type: string;
63
+ dimensions?: string[];
64
+ domains?: string[];
65
+ members?: string[];
66
+ }
67
+ interface ConceptLabel {
68
+ text: string;
69
+ role: string;
70
+ lang: string;
71
+ }
72
+ interface CompleteConcept {
73
+ name: string;
74
+ labels: ConceptLabel[];
75
+ presentation: ConceptNode | null;
76
+ calculation: CalculationRule | null;
77
+ dimensions: DimensionStructure | null;
78
+ }
79
+ export declare function usageExamples(): {
80
+ segmentRevenue: {
81
+ fact: import("../types").XbrlElement;
82
+ context: import("../types").XbrlContext;
83
+ dimensions: {
84
+ dimension: string;
85
+ member: string;
86
+ }[];
87
+ }[];
88
+ northAmericaRevenue: {
89
+ fact: import("../types").XbrlElement;
90
+ context: import("../types").XbrlContext;
91
+ dimensions: {
92
+ dimension: string;
93
+ member: string;
94
+ }[];
95
+ }[];
96
+ };
97
+ export {};
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ /**
3
+ * Practical examples of working with XBRL relationships using your existing types
4
+ */
5
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
6
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
7
+ if (ar || !(i in from)) {
8
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
9
+ ar[i] = from[i];
10
+ }
11
+ }
12
+ return to.concat(ar || Array.prototype.slice.call(from));
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.usageExamples = exports.buildCompleteConceptMap = exports.findFactsWithDimensions = exports.extractDimensionalRelationships = exports.extractCalculationRelationships = exports.extractPresentationHierarchy = void 0;
16
+ /**
17
+ * Example 1: Extract presentation hierarchy from your XBRL data
18
+ */
19
+ function extractPresentationHierarchy(presentationLinkbase) {
20
+ var _a;
21
+ var hierarchy = {};
22
+ // Process each presentation link (usually one per role/statement)
23
+ (_a = presentationLinkbase.presentationLink) === null || _a === void 0 ? void 0 : _a.forEach(function (link) {
24
+ var roleUri = link.role || 'default';
25
+ // Get all concept locators and relationship arcs
26
+ var locators = (link.loc || []);
27
+ var arcs = (link.presentationArc || []);
28
+ // Build concept reference map
29
+ var conceptMap = new Map();
30
+ locators.forEach(function (loc) {
31
+ var concept = extractConceptFromHref(loc.href);
32
+ conceptMap.set(loc.label, concept);
33
+ });
34
+ // Build parent-child relationships
35
+ arcs.forEach(function (arc) {
36
+ var parent = conceptMap.get(arc.from);
37
+ var child = conceptMap.get(arc.to);
38
+ if (parent && child) {
39
+ // Initialize parent node if it doesn't exist
40
+ if (!hierarchy[parent]) {
41
+ hierarchy[parent] = {
42
+ concept: parent,
43
+ children: [],
44
+ role: roleUri,
45
+ order: 0,
46
+ };
47
+ }
48
+ // Add child with ordering information
49
+ hierarchy[parent].children.push({
50
+ concept: child,
51
+ order: arc.order || 0,
52
+ preferredLabel: arc.preferredLabel,
53
+ });
54
+ // Sort children by order
55
+ hierarchy[parent].children.sort(function (a, b) { return a.order - b.order; });
56
+ }
57
+ });
58
+ });
59
+ return hierarchy;
60
+ }
61
+ exports.extractPresentationHierarchy = extractPresentationHierarchy;
62
+ /**
63
+ * Example 2: Extract calculation relationships
64
+ */
65
+ function extractCalculationRelationships(calculationLinkbase) {
66
+ var _a;
67
+ var calculations = {};
68
+ (_a = calculationLinkbase.calculationLink) === null || _a === void 0 ? void 0 : _a.forEach(function (link) {
69
+ var locators = (link.loc || []);
70
+ var arcs = (link.calculationArc || []);
71
+ // Build concept reference map
72
+ var conceptMap = new Map();
73
+ locators.forEach(function (loc) {
74
+ var concept = extractConceptFromHref(loc.href);
75
+ conceptMap.set(loc.label, concept);
76
+ });
77
+ // Group arcs by summation item (the 'to' end of the arc)
78
+ var summationGroups = new Map();
79
+ arcs.forEach(function (arc) {
80
+ var summationConcept = conceptMap.get(arc.to);
81
+ if (summationConcept) {
82
+ if (!summationGroups.has(summationConcept)) {
83
+ summationGroups.set(summationConcept, []);
84
+ }
85
+ summationGroups.get(summationConcept).push(arc);
86
+ }
87
+ });
88
+ // Build calculation rules
89
+ summationGroups.forEach(function (contributingArcs, summationConcept) {
90
+ calculations[summationConcept] = {
91
+ summationItem: summationConcept,
92
+ contributingItems: contributingArcs.map(function (arc) { return ({
93
+ concept: conceptMap.get(arc.from) || '',
94
+ weight: arc.weight || 1,
95
+ order: arc.order || 0,
96
+ }); }),
97
+ };
98
+ });
99
+ });
100
+ return calculations;
101
+ }
102
+ exports.extractCalculationRelationships = extractCalculationRelationships;
103
+ /**
104
+ * Example 3: Extract dimensional relationships (axis/member mappings)
105
+ */
106
+ function extractDimensionalRelationships(definitionLinkbase) {
107
+ var _a;
108
+ var dimensions = {};
109
+ (_a = definitionLinkbase.definitionLink) === null || _a === void 0 ? void 0 : _a.forEach(function (link) {
110
+ var locators = (link.loc || []);
111
+ var arcs = (link.definitionArc || []);
112
+ // Build concept reference map
113
+ var conceptMap = new Map();
114
+ locators.forEach(function (loc) {
115
+ var concept = extractConceptFromHref(loc.href);
116
+ conceptMap.set(loc.label, concept);
117
+ });
118
+ // Process dimensional arcs based on their arcrole
119
+ arcs.forEach(function (arc) {
120
+ var fromConcept = conceptMap.get(arc.from);
121
+ var toConcept = conceptMap.get(arc.to);
122
+ var arcrole = arc.arcrole || '';
123
+ if (fromConcept && toConcept) {
124
+ switch (arcrole) {
125
+ case 'http://xbrl.org/int/dim/arcrole/hypercube-dimension':
126
+ // Hypercube contains dimension
127
+ initializeDimension(dimensions, fromConcept, 'hypercube');
128
+ dimensions[fromConcept].dimensions = dimensions[fromConcept].dimensions || [];
129
+ dimensions[fromConcept].dimensions.push(toConcept);
130
+ break;
131
+ case 'http://xbrl.org/int/dim/arcrole/dimension-domain':
132
+ // Dimension has domain
133
+ initializeDimension(dimensions, fromConcept, 'dimension');
134
+ dimensions[fromConcept].domains = dimensions[fromConcept].domains || [];
135
+ dimensions[fromConcept].domains.push(toConcept);
136
+ break;
137
+ case 'http://xbrl.org/int/dim/arcrole/domain-member':
138
+ // Domain has member
139
+ initializeDimension(dimensions, fromConcept, 'domain');
140
+ dimensions[fromConcept].members = dimensions[fromConcept].members || [];
141
+ dimensions[fromConcept].members.push(toConcept);
142
+ break;
143
+ }
144
+ }
145
+ });
146
+ });
147
+ return dimensions;
148
+ }
149
+ exports.extractDimensionalRelationships = extractDimensionalRelationships;
150
+ /**
151
+ * Example 4: Find facts with specific dimensional context
152
+ */
153
+ function findFactsWithDimensions(instance, conceptName, dimensionFilters) {
154
+ var matchingFacts = [];
155
+ // Filter facts by concept name
156
+ var conceptFacts = instance.factElements.filter(function (fact) { return fact.name === conceptName; });
157
+ var _loop_1 = function (fact) {
158
+ // Get the context for this fact
159
+ var context = instance.contexts.find(function (ctx) { return ctx.id === fact.contextRef; });
160
+ if (!context)
161
+ return "continue";
162
+ // Check if this fact matches our dimensional filters
163
+ if (dimensionFilters) {
164
+ var matchesFilters = dimensionFilters.every(function (filter) {
165
+ var matchingSegment = context.entity.segment.find(function (seg) { return seg.dimension === filter.dimension; });
166
+ if (!matchingSegment)
167
+ return false;
168
+ // If specific member is required, check for it
169
+ if (filter.member && matchingSegment.value !== filter.member) {
170
+ return false;
171
+ }
172
+ return true;
173
+ });
174
+ if (!matchesFilters)
175
+ return "continue";
176
+ }
177
+ matchingFacts.push({
178
+ fact: fact,
179
+ context: context,
180
+ dimensions: context.entity.segment.map(function (seg) { return ({
181
+ dimension: seg.dimension,
182
+ member: seg.value,
183
+ }); }),
184
+ });
185
+ };
186
+ for (var _i = 0, conceptFacts_1 = conceptFacts; _i < conceptFacts_1.length; _i++) {
187
+ var fact = conceptFacts_1[_i];
188
+ _loop_1(fact);
189
+ }
190
+ return matchingFacts;
191
+ }
192
+ exports.findFactsWithDimensions = findFactsWithDimensions;
193
+ /**
194
+ * Example 5: Build a complete concept map with all relationships
195
+ */
196
+ function buildCompleteConceptMap(linkbases) {
197
+ var conceptMap = new Map();
198
+ // Extract all relationships
199
+ var presentationHierarchy = extractPresentationHierarchy(linkbases.presentation);
200
+ var calculationRelationships = extractCalculationRelationships(linkbases.calculation);
201
+ var dimensionalRelationships = extractDimensionalRelationships(linkbases.definition);
202
+ var labels = extractLabels(linkbases.label);
203
+ // Combine all concepts
204
+ var allConcepts = new Set(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], Object.keys(presentationHierarchy), true), Object.keys(calculationRelationships), true), Object.keys(dimensionalRelationships), true), Object.keys(labels), true));
205
+ // Build complete concept entries
206
+ allConcepts.forEach(function (concept) {
207
+ conceptMap.set(concept, {
208
+ name: concept,
209
+ labels: labels[concept] || [],
210
+ presentation: presentationHierarchy[concept] || null,
211
+ calculation: calculationRelationships[concept] || null,
212
+ dimensions: dimensionalRelationships[concept] || null,
213
+ });
214
+ });
215
+ return conceptMap;
216
+ }
217
+ exports.buildCompleteConceptMap = buildCompleteConceptMap;
218
+ // Helper functions and types
219
+ function extractConceptFromHref(href) {
220
+ var match = href.match(/#(.+)$/);
221
+ return match ? match[1] : '';
222
+ }
223
+ function initializeDimension(dimensions, concept, type) {
224
+ if (!dimensions[concept]) {
225
+ dimensions[concept] = {
226
+ concept: concept,
227
+ type: type,
228
+ dimensions: [],
229
+ domains: [],
230
+ members: [],
231
+ };
232
+ }
233
+ }
234
+ function extractLabels(labelLinkbase) {
235
+ var _a;
236
+ var labels = {};
237
+ (_a = labelLinkbase.labelLink) === null || _a === void 0 ? void 0 : _a.forEach(function (link) {
238
+ var locators = (link.loc || []);
239
+ var arcs = (link.labelArc || []);
240
+ var labelResources = link.label || [];
241
+ // Build concept reference map
242
+ var conceptMap = new Map();
243
+ locators.forEach(function (loc) {
244
+ var concept = extractConceptFromHref(loc.href);
245
+ conceptMap.set(loc.label, concept);
246
+ });
247
+ // Connect labels to concepts
248
+ arcs.forEach(function (arc) {
249
+ var concept = conceptMap.get(arc.from);
250
+ var labelResource = labelResources.find(function (r) { return r.label === arc.to; });
251
+ if (concept && labelResource) {
252
+ labels[concept] = labels[concept] || [];
253
+ labels[concept].push({
254
+ text: labelResource.text || '',
255
+ role: labelResource.role || '',
256
+ lang: labelResource.lang || 'en',
257
+ });
258
+ }
259
+ });
260
+ });
261
+ return labels;
262
+ }
263
+ // Usage examples:
264
+ function usageExamples() {
265
+ // Example: Get all revenue facts broken down by segment
266
+ var segmentRevenue = findFactsWithDimensions({}, // Your XBRL instance
267
+ 'us-gaap:Revenues', [{ dimension: 'us-gaap:SegmentDomain' }]);
268
+ // Example: Get specific segment revenue
269
+ var northAmericaRevenue = findFactsWithDimensions({}, 'us-gaap:Revenues', [
270
+ {
271
+ dimension: 'us-gaap:SegmentDomain',
272
+ member: 'us-gaap:NorthAmericaSegmentMember',
273
+ },
274
+ ]);
275
+ return { segmentRevenue: segmentRevenue, northAmericaRevenue: northAmericaRevenue };
276
+ }
277
+ exports.usageExamples = usageExamples;
@@ -0,0 +1,145 @@
1
+ import type { XbrlInstance, XbrlLinkbase, XbrlSchema } from '../types';
2
+ export declare class XbrlRelationshipBuilder {
3
+ private instance;
4
+ private schema;
5
+ private presentationLinkbase;
6
+ private calculationLinkbase;
7
+ private definitionLinkbase;
8
+ private labelLinkbase;
9
+ constructor(data: {
10
+ instance: XbrlInstance;
11
+ schema: XbrlSchema;
12
+ presentationLinkbase: XbrlLinkbase;
13
+ calculationLinkbase: XbrlLinkbase;
14
+ definitionLinkbase: XbrlLinkbase;
15
+ labelLinkbase: XbrlLinkbase;
16
+ });
17
+ /**
18
+ * 1. PRESENTATION LINKBASE - Defines hierarchical structure
19
+ * Shows how concepts are organized in financial statements
20
+ */
21
+ buildPresentationHierarchy(): Record<string, ConceptHierarchy>;
22
+ /**
23
+ * 2. CALCULATION LINKBASE - Defines mathematical relationships
24
+ * Shows how concepts add up to totals
25
+ */
26
+ buildCalculationRelationships(): Record<string, CalculationRelationship>;
27
+ /**
28
+ * 3. DEFINITION LINKBASE - Defines dimensional relationships
29
+ * Shows axis, members, domains, and hypercubes
30
+ */
31
+ buildDimensionalRelationships(): Record<string, DimensionalRelationship>;
32
+ /**
33
+ * 4. LABEL LINKBASE - Provides human-readable labels
34
+ * Maps concepts to their display labels
35
+ */
36
+ buildLabelMappings(): Record<string, ConceptLabel[]>;
37
+ /**
38
+ * 5. RELATING FACTS TO DIMENSIONS
39
+ * Shows how actual data values relate to dimensional context
40
+ */
41
+ buildFactDimensionalMappings(): FactDimensionalMapping[];
42
+ /**
43
+ * 6. COMPREHENSIVE TAXONOMY MAPPING
44
+ * Combines all relationships into a unified structure
45
+ */
46
+ buildComprehensiveTaxonomyMap(): {
47
+ presentation: Record<string, ConceptHierarchy>;
48
+ calculations: Record<string, CalculationRelationship>;
49
+ dimensions: Record<string, DimensionalRelationship>;
50
+ labels: Record<string, ConceptLabel[]>;
51
+ factMappings: FactDimensionalMapping[];
52
+ getConceptChildren: (concept: string) => ConceptChild[];
53
+ getConceptCalculation: (concept: string) => CalculationRelationship;
54
+ getConceptLabels: (concept: string) => ConceptLabel[];
55
+ getFactsForConcept: (concept: string) => FactDimensionalMapping[];
56
+ getDimensionsForConcept: (concept: string) => DimensionalRelationship;
57
+ };
58
+ private getLocators;
59
+ private getPresentationArcs;
60
+ private getCalculationArcs;
61
+ private getDefinitionArcs;
62
+ private getLabelArcs;
63
+ private getLabelResources;
64
+ private getConceptFromLocator;
65
+ private addHypercubeDimension;
66
+ private addDimensionDomain;
67
+ private addDomainMember;
68
+ private addAllRelationship;
69
+ }
70
+ interface ConceptHierarchy {
71
+ concept: string;
72
+ children: ConceptChild[];
73
+ order: number;
74
+ role: string;
75
+ }
76
+ interface ConceptChild {
77
+ concept: string;
78
+ order: number;
79
+ preferredLabel?: string;
80
+ }
81
+ interface CalculationRelationship {
82
+ summationItem: string;
83
+ contributingItems: CalculationItem[];
84
+ }
85
+ interface CalculationItem {
86
+ concept: string;
87
+ weight: number;
88
+ order: number;
89
+ }
90
+ interface DimensionalRelationship {
91
+ type: 'hypercube' | 'dimension' | 'domain' | 'member';
92
+ concept: string;
93
+ dimensions?: DimensionalItem[];
94
+ domains?: DimensionalItem[];
95
+ members?: DimensionalItem[];
96
+ all?: DimensionalItem[];
97
+ }
98
+ interface DimensionalItem {
99
+ concept: string;
100
+ type: string;
101
+ }
102
+ interface ConceptLabel {
103
+ text: string;
104
+ role: string;
105
+ lang: string;
106
+ }
107
+ interface FactDimensionalMapping {
108
+ factName: string;
109
+ value: string;
110
+ unit: string;
111
+ context: DimensionalContext;
112
+ contextRef: string;
113
+ }
114
+ interface DimensionalContext {
115
+ entity: string;
116
+ period: {
117
+ startDate?: string;
118
+ endDate?: string;
119
+ instant?: string;
120
+ };
121
+ dimensions: {
122
+ dimension: string;
123
+ member: string;
124
+ }[];
125
+ }
126
+ export declare function exampleUsage(xbrlData: {
127
+ instance: XbrlInstance;
128
+ schema: XbrlSchema;
129
+ presentationLinkbase: XbrlLinkbase;
130
+ calculationLinkbase: XbrlLinkbase;
131
+ definitionLinkbase: XbrlLinkbase;
132
+ labelLinkbase: XbrlLinkbase;
133
+ }): {
134
+ presentation: Record<string, ConceptHierarchy>;
135
+ calculations: Record<string, CalculationRelationship>;
136
+ dimensions: Record<string, DimensionalRelationship>;
137
+ labels: Record<string, ConceptLabel[]>;
138
+ factMappings: FactDimensionalMapping[];
139
+ getConceptChildren: (concept: string) => ConceptChild[];
140
+ getConceptCalculation: (concept: string) => CalculationRelationship;
141
+ getConceptLabels: (concept: string) => ConceptLabel[];
142
+ getFactsForConcept: (concept: string) => FactDimensionalMapping[];
143
+ getDimensionsForConcept: (concept: string) => DimensionalRelationship;
144
+ };
145
+ export {};