@jotx-labs/core 2.2.0 → 2.4.82
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/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/links/LinkIndexer.d.ts +85 -0
- package/dist/links/LinkIndexer.d.ts.map +1 -0
- package/dist/links/LinkIndexer.js +238 -0
- package/dist/links/LinkIndexer.js.map +1 -0
- package/dist/links/LinkParser.d.ts +41 -0
- package/dist/links/LinkParser.d.ts.map +1 -0
- package/dist/links/LinkParser.js +162 -0
- package/dist/links/LinkParser.js.map +1 -0
- package/dist/links/index.d.ts +12 -0
- package/dist/links/index.d.ts.map +1 -0
- package/dist/links/index.js +28 -0
- package/dist/links/index.js.map +1 -0
- package/dist/links/types.d.ts +66 -0
- package/dist/links/types.d.ts.map +1 -0
- package/dist/links/types.js +7 -0
- package/dist/links/types.js.map +1 -0
- package/dist/parser/serializer.d.ts.map +1 -1
- package/dist/parser/serializer.js +11 -5
- package/dist/parser/serializer.js.map +1 -1
- package/dist/parser/tokenizer.new.d.ts +1 -0
- package/dist/parser/tokenizer.new.d.ts.map +1 -1
- package/dist/parser/tokenizer.new.js +14 -0
- package/dist/parser/tokenizer.new.js.map +1 -1
- package/dist/parser/v3/BlockParser.js +1 -1
- package/dist/parser/v3/BlockParser.js.map +1 -1
- package/dist/parser/v3/DocumentParser.d.ts.map +1 -1
- package/dist/parser/v3/DocumentParser.js +7 -0
- package/dist/parser/v3/DocumentParser.js.map +1 -1
- package/dist/parser/validator.js +1 -1
- package/dist/parser/validator.js.map +1 -1
- package/dist/types/ast.d.ts.map +1 -1
- package/dist/types/ast.js +48 -1
- package/dist/types/ast.js.map +1 -1
- package/dist/types/enums.d.ts +2 -2
- package/dist/types/enums.d.ts.map +1 -1
- package/dist/types/enums.js +9 -2
- package/dist/types/enums.js.map +1 -1
- package/dist/types/nodeManager.d.ts +86 -0
- package/dist/types/nodeManager.d.ts.map +1 -0
- package/dist/types/nodeManager.js +7 -0
- package/dist/types/nodeManager.js.map +1 -0
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* jotx 2.0 Core - Pure functional parser and validator
|
|
3
|
-
* @module @jotx/core
|
|
3
|
+
* @module @jotx-labs/core
|
|
4
4
|
*
|
|
5
5
|
* Zero dependencies, works everywhere (Node, Browser, Mobile)
|
|
6
6
|
* Pure functions only: parse, serialize, validate
|
|
7
7
|
*/
|
|
8
8
|
export * from './types/enums';
|
|
9
9
|
export * from './types/ast';
|
|
10
|
+
export * from './types/nodeManager';
|
|
10
11
|
import { Tokenizer } from './parser/tokenizer.new';
|
|
11
12
|
import { Parser } from './parser/v3/Parser';
|
|
12
13
|
import { Serializer } from './parser/serializer';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AAKnC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,CAAA;AAKpE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAK7E,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE1H;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,6BAGjC;AAMD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,UAGjC;AAMD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,2CAGhC;AAMD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM;;;;EAS5C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9C;AACD,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* jotx 2.0 Core - Pure functional parser and validator
|
|
4
|
-
* @module @jotx/core
|
|
4
|
+
* @module @jotx-labs/core
|
|
5
5
|
*
|
|
6
6
|
* Zero dependencies, works everywhere (Node, Browser, Mobile)
|
|
7
7
|
* Pure functions only: parse, serialize, validate
|
|
@@ -27,11 +27,11 @@ exports.serialize = serialize;
|
|
|
27
27
|
exports.validate = validate;
|
|
28
28
|
exports.parseAndValidate = parseAndValidate;
|
|
29
29
|
exports.roundTrip = roundTrip;
|
|
30
|
-
// ============================================================================
|
|
31
30
|
// TYPES - Data structures only
|
|
32
31
|
// ============================================================================
|
|
33
32
|
__exportStar(require("./types/enums"), exports);
|
|
34
33
|
__exportStar(require("./types/ast"), exports);
|
|
34
|
+
__exportStar(require("./types/nodeManager"), exports);
|
|
35
35
|
// ============================================================================
|
|
36
36
|
// PARSER - Text → AST
|
|
37
37
|
// ============================================================================
|
|
@@ -114,5 +114,5 @@ function roundTrip(text) {
|
|
|
114
114
|
return serialize(ast);
|
|
115
115
|
}
|
|
116
116
|
__exportStar(require("./platform"), exports);
|
|
117
|
-
// V2 blocks removed - use @jotx/standard-lib instead
|
|
117
|
+
// V2 blocks removed - use @jotx-labs/standard-lib instead
|
|
118
118
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;AAgCH,sBAGC;AAUD,8BAGC;AAUD,4BAGC;AAUD,4CASC;AAMD,8BAGC;AAvFD,+
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;AAgCH,sBAGC;AAUD,8BAGC;AAUD,4BAGC;AAUD,4CASC;AAMD,8BAGC;AAvFD,+BAA+B;AAC/B,+EAA+E;AAC/E,gDAA6B;AAC7B,8CAA2B;AAC3B,sDAAmC;AAEnC,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAC/E,0DAAkD;AAKzC,0FALA,yBAAS,OAKA;AAJlB,+CAA2C;AAIvB,uFAJX,eAAM,OAIW;AAH1B,oDAAgD;AAGpB,2FAHnB,uBAAU,OAGmB;AAFtC,kDAA+D;AAEvB,0FAF/B,qBAAS,OAE+B;AAAE,gGAF/B,2BAAe,OAE+B;AAElE,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAC/E,oEAA6E;AAApE,kHAAA,aAAa,OAAA;AAAE,kHAAA,aAAa,OAAA;AAErC,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAC/E,mDAA0H;AAAjH,8GAAA,eAAe,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,0GAAA,WAAW,OAAA;AAAE,mHAAA,oBAAoB,OAAA;AAE7F;;;GAGG;AACH,SAAgB,KAAK,CAAC,IAAY;IAChC,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAA;IAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC3B,CAAC;AAED,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E;;;GAGG;AACH,SAAgB,SAAS,CAAC,GAAQ;IAChC,MAAM,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAA;IACnC,OAAO,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;AAClC,CAAC;AAED,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E;;;GAGG;AACH,SAAgB,QAAQ,CAAC,GAAQ;IAC/B,MAAM,SAAS,GAAG,IAAA,2BAAe,GAAE,CAAA;IACnC,OAAO,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAChC,CAAC;AAED,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;IACvB,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;IAE5B,OAAO;QACL,GAAG;QACH,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACP,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,IAAY;IACpC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;IACvB,OAAO,SAAS,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC;AACD,6CAA0B;AAC1B,0DAA0D"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Link Indexer - Build and maintain link index for documents
|
|
3
|
+
*
|
|
4
|
+
* Tracks:
|
|
5
|
+
* - Outgoing links from each document
|
|
6
|
+
* - Incoming links (backlinks) to each document
|
|
7
|
+
* - Tags used across documents
|
|
8
|
+
* - Orphaned documents (no links)
|
|
9
|
+
*
|
|
10
|
+
* Updates incrementally when documents change
|
|
11
|
+
*/
|
|
12
|
+
import { AST } from '../types/ast';
|
|
13
|
+
import { LinkIndex, LinkIndexEntry, DocumentLink, ParsedLink } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* Link Indexer class
|
|
16
|
+
*/
|
|
17
|
+
export declare class LinkIndexer {
|
|
18
|
+
private index;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Index a document and extract all links
|
|
22
|
+
*/
|
|
23
|
+
indexDocument(documentPath: string, ast: AST): void;
|
|
24
|
+
/**
|
|
25
|
+
* Remove a document from the index
|
|
26
|
+
*/
|
|
27
|
+
removeDocument(documentPath: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get all links from a document
|
|
30
|
+
*/
|
|
31
|
+
getDocumentLinks(documentPath: string): LinkIndexEntry | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Get backlinks for a document (who links to this doc)
|
|
34
|
+
*/
|
|
35
|
+
getBacklinks(documentPath: string): DocumentLink[];
|
|
36
|
+
/**
|
|
37
|
+
* Get outgoing links from a document (where this doc links to)
|
|
38
|
+
*/
|
|
39
|
+
getOutgoingLinks(documentPath: string): ParsedLink[];
|
|
40
|
+
/**
|
|
41
|
+
* Get all documents using a specific tag
|
|
42
|
+
*/
|
|
43
|
+
getDocumentsByTag(tag: string): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Get all orphaned documents (no incoming or outgoing links)
|
|
46
|
+
*/
|
|
47
|
+
getOrphans(): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Get the complete index
|
|
50
|
+
*/
|
|
51
|
+
getIndex(): LinkIndex;
|
|
52
|
+
/**
|
|
53
|
+
* Clear the entire index
|
|
54
|
+
*/
|
|
55
|
+
clear(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Extract links from AST blocks recursively
|
|
58
|
+
*/
|
|
59
|
+
private extractLinksFromAST;
|
|
60
|
+
/**
|
|
61
|
+
* Extract links from a single block and its children
|
|
62
|
+
*/
|
|
63
|
+
private extractLinksFromBlock;
|
|
64
|
+
/**
|
|
65
|
+
* Update backlinks for all documents
|
|
66
|
+
*/
|
|
67
|
+
private updateBacklinks;
|
|
68
|
+
/**
|
|
69
|
+
* Find target document by name (handles .jot extension)
|
|
70
|
+
*/
|
|
71
|
+
private findTargetDocument;
|
|
72
|
+
/**
|
|
73
|
+
* Extract context around a link for backlinks display
|
|
74
|
+
*/
|
|
75
|
+
private extractContext;
|
|
76
|
+
/**
|
|
77
|
+
* Update orphans list (documents with no links in/out)
|
|
78
|
+
*/
|
|
79
|
+
private updateOrphans;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create a global link indexer instance
|
|
83
|
+
*/
|
|
84
|
+
export declare function createLinkIndexer(): LinkIndexer;
|
|
85
|
+
//# sourceMappingURL=LinkIndexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkIndexer.d.ts","sourceRoot":"","sources":["../../src/links/LinkIndexer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,GAAG,EAAa,MAAM,cAAc,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE7E;;GAEG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,KAAK,CAAW;;IAUxB;;OAEG;IACH,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI;IA+BnD;;OAEG;IACH,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAyB1C;;OAEG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIlE;;OAEG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,EAAE;IAKlD;;OAEG;IACH,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,EAAE;IAKpD;;OAEG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE;IAIxC;;OAEG;IACH,UAAU,IAAI,MAAM,EAAE;IAItB;;OAEG;IACH,QAAQ,IAAI,SAAS;IAIrB;;OAEG;IACH,KAAK,IAAI,IAAI;IAQb;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAW3B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAqB7B;;OAEG;IACH,OAAO,CAAC,eAAe;IA0BvB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoB1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAMtB;;OAEG;IACH,OAAO,CAAC,aAAa;CAYxB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,WAAW,CAE/C"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Link Indexer - Build and maintain link index for documents
|
|
4
|
+
*
|
|
5
|
+
* Tracks:
|
|
6
|
+
* - Outgoing links from each document
|
|
7
|
+
* - Incoming links (backlinks) to each document
|
|
8
|
+
* - Tags used across documents
|
|
9
|
+
* - Orphaned documents (no links)
|
|
10
|
+
*
|
|
11
|
+
* Updates incrementally when documents change
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.LinkIndexer = void 0;
|
|
15
|
+
exports.createLinkIndexer = createLinkIndexer;
|
|
16
|
+
const LinkParser_1 = require("./LinkParser");
|
|
17
|
+
/**
|
|
18
|
+
* Link Indexer class
|
|
19
|
+
*/
|
|
20
|
+
class LinkIndexer {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.index = {
|
|
23
|
+
documents: new Map(),
|
|
24
|
+
tagIndex: new Map(),
|
|
25
|
+
orphans: []
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Index a document and extract all links
|
|
30
|
+
*/
|
|
31
|
+
indexDocument(documentPath, ast) {
|
|
32
|
+
const links = this.extractLinksFromAST(ast);
|
|
33
|
+
const tags = links.filter(l => l.type === 'tag').map(l => l.documentName);
|
|
34
|
+
// Create or update document entry
|
|
35
|
+
const entry = {
|
|
36
|
+
documentPath,
|
|
37
|
+
outgoingLinks: links,
|
|
38
|
+
incomingLinks: [], // Will be populated during backlink calculation
|
|
39
|
+
tags,
|
|
40
|
+
lastUpdated: new Date()
|
|
41
|
+
};
|
|
42
|
+
this.index.documents.set(documentPath, entry);
|
|
43
|
+
// Update tag index
|
|
44
|
+
for (const tag of tags) {
|
|
45
|
+
const tagDocs = this.index.tagIndex.get(tag) || [];
|
|
46
|
+
if (!tagDocs.includes(documentPath)) {
|
|
47
|
+
tagDocs.push(documentPath);
|
|
48
|
+
this.index.tagIndex.set(tag, tagDocs);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Recalculate backlinks for all documents
|
|
52
|
+
this.updateBacklinks();
|
|
53
|
+
// Update orphans list
|
|
54
|
+
this.updateOrphans();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Remove a document from the index
|
|
58
|
+
*/
|
|
59
|
+
removeDocument(documentPath) {
|
|
60
|
+
const entry = this.index.documents.get(documentPath);
|
|
61
|
+
if (!entry)
|
|
62
|
+
return;
|
|
63
|
+
// Remove from tag index
|
|
64
|
+
for (const tag of entry.tags) {
|
|
65
|
+
const tagDocs = this.index.tagIndex.get(tag) || [];
|
|
66
|
+
const filtered = tagDocs.filter(d => d !== documentPath);
|
|
67
|
+
if (filtered.length === 0) {
|
|
68
|
+
this.index.tagIndex.delete(tag);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.index.tagIndex.set(tag, filtered);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Remove from documents
|
|
75
|
+
this.index.documents.delete(documentPath);
|
|
76
|
+
// Recalculate backlinks
|
|
77
|
+
this.updateBacklinks();
|
|
78
|
+
// Update orphans
|
|
79
|
+
this.updateOrphans();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get all links from a document
|
|
83
|
+
*/
|
|
84
|
+
getDocumentLinks(documentPath) {
|
|
85
|
+
return this.index.documents.get(documentPath);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get backlinks for a document (who links to this doc)
|
|
89
|
+
*/
|
|
90
|
+
getBacklinks(documentPath) {
|
|
91
|
+
const entry = this.index.documents.get(documentPath);
|
|
92
|
+
return entry?.incomingLinks || [];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get outgoing links from a document (where this doc links to)
|
|
96
|
+
*/
|
|
97
|
+
getOutgoingLinks(documentPath) {
|
|
98
|
+
const entry = this.index.documents.get(documentPath);
|
|
99
|
+
return entry?.outgoingLinks || [];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get all documents using a specific tag
|
|
103
|
+
*/
|
|
104
|
+
getDocumentsByTag(tag) {
|
|
105
|
+
return this.index.tagIndex.get(tag) || [];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get all orphaned documents (no incoming or outgoing links)
|
|
109
|
+
*/
|
|
110
|
+
getOrphans() {
|
|
111
|
+
return this.index.orphans;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get the complete index
|
|
115
|
+
*/
|
|
116
|
+
getIndex() {
|
|
117
|
+
return this.index;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Clear the entire index
|
|
121
|
+
*/
|
|
122
|
+
clear() {
|
|
123
|
+
this.index = {
|
|
124
|
+
documents: new Map(),
|
|
125
|
+
tagIndex: new Map(),
|
|
126
|
+
orphans: []
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Extract links from AST blocks recursively
|
|
131
|
+
*/
|
|
132
|
+
extractLinksFromAST(ast) {
|
|
133
|
+
const links = [];
|
|
134
|
+
const doc = ast.document;
|
|
135
|
+
for (const block of doc.blocks) {
|
|
136
|
+
this.extractLinksFromBlock(block, links);
|
|
137
|
+
}
|
|
138
|
+
return links;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Extract links from a single block and its children
|
|
142
|
+
*/
|
|
143
|
+
extractLinksFromBlock(block, links) {
|
|
144
|
+
// Extract from text property
|
|
145
|
+
if (block.properties?.text && typeof block.properties.text === 'string') {
|
|
146
|
+
const textLinks = (0, LinkParser_1.extractLinks)(block.properties.text);
|
|
147
|
+
links.push(...textLinks);
|
|
148
|
+
}
|
|
149
|
+
// Extract from title property (for toggles, sections)
|
|
150
|
+
if (block.properties?.title && typeof block.properties.title === 'string') {
|
|
151
|
+
const titleLinks = (0, LinkParser_1.extractLinks)(block.properties.title);
|
|
152
|
+
links.push(...titleLinks);
|
|
153
|
+
}
|
|
154
|
+
// Recursively process children
|
|
155
|
+
if (block.children && Array.isArray(block.children)) {
|
|
156
|
+
for (const child of block.children) {
|
|
157
|
+
this.extractLinksFromBlock(child, links);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Update backlinks for all documents
|
|
163
|
+
*/
|
|
164
|
+
updateBacklinks() {
|
|
165
|
+
// Clear all backlinks first
|
|
166
|
+
for (const entry of this.index.documents.values()) {
|
|
167
|
+
entry.incomingLinks = [];
|
|
168
|
+
}
|
|
169
|
+
// For each document, create backlinks in targets
|
|
170
|
+
for (const [sourcePath, sourceEntry] of this.index.documents.entries()) {
|
|
171
|
+
for (const link of sourceEntry.outgoingLinks) {
|
|
172
|
+
// Skip tags
|
|
173
|
+
if (link.type === 'tag')
|
|
174
|
+
continue;
|
|
175
|
+
// Find target document (need to resolve .jot extension)
|
|
176
|
+
const targetEntry = this.findTargetDocument(link.documentName);
|
|
177
|
+
if (targetEntry) {
|
|
178
|
+
const backlink = {
|
|
179
|
+
sourceDocument: sourcePath,
|
|
180
|
+
target: link,
|
|
181
|
+
context: this.extractContext(sourceEntry, link)
|
|
182
|
+
};
|
|
183
|
+
targetEntry.incomingLinks.push(backlink);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Find target document by name (handles .jot extension)
|
|
190
|
+
*/
|
|
191
|
+
findTargetDocument(documentName) {
|
|
192
|
+
// Try exact match
|
|
193
|
+
let entry = this.index.documents.get(documentName);
|
|
194
|
+
if (entry)
|
|
195
|
+
return entry;
|
|
196
|
+
// Try with .jot extension
|
|
197
|
+
entry = this.index.documents.get(`${documentName}.jot`);
|
|
198
|
+
if (entry)
|
|
199
|
+
return entry;
|
|
200
|
+
// Try finding by basename
|
|
201
|
+
for (const [path, docEntry] of this.index.documents.entries()) {
|
|
202
|
+
const basename = path.replace(/\.jot$/, '').split('/').pop() || '';
|
|
203
|
+
if (basename === documentName) {
|
|
204
|
+
return docEntry;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Extract context around a link for backlinks display
|
|
211
|
+
*/
|
|
212
|
+
extractContext(entry, link) {
|
|
213
|
+
// For now, return the link source
|
|
214
|
+
// TODO: Extract surrounding text from the block
|
|
215
|
+
return link.src;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Update orphans list (documents with no links in/out)
|
|
219
|
+
*/
|
|
220
|
+
updateOrphans() {
|
|
221
|
+
this.index.orphans = [];
|
|
222
|
+
for (const [path, entry] of this.index.documents.entries()) {
|
|
223
|
+
const hasOutgoing = entry.outgoingLinks.filter(l => l.type !== 'tag').length > 0;
|
|
224
|
+
const hasIncoming = entry.incomingLinks.length > 0;
|
|
225
|
+
if (!hasOutgoing && !hasIncoming) {
|
|
226
|
+
this.index.orphans.push(path);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.LinkIndexer = LinkIndexer;
|
|
232
|
+
/**
|
|
233
|
+
* Create a global link indexer instance
|
|
234
|
+
*/
|
|
235
|
+
function createLinkIndexer() {
|
|
236
|
+
return new LinkIndexer();
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=LinkIndexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkIndexer.js","sourceRoot":"","sources":["../../src/links/LinkIndexer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAgQH,8CAEC;AA/PD,6CAA2C;AAG3C;;GAEG;AACH,MAAa,WAAW;IAGpB;QACI,IAAI,CAAC,KAAK,GAAG;YACT,SAAS,EAAE,IAAI,GAAG,EAAE;YACpB,QAAQ,EAAE,IAAI,GAAG,EAAE;YACnB,OAAO,EAAE,EAAE;SACd,CAAA;IACL,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,YAAoB,EAAE,GAAQ;QACxC,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;QAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;QAEzE,kCAAkC;QAClC,MAAM,KAAK,GAAmB;YAC1B,YAAY;YACZ,aAAa,EAAE,KAAK;YACpB,aAAa,EAAE,EAAE,EAAE,gDAAgD;YACnE,IAAI;YACJ,WAAW,EAAE,IAAI,IAAI,EAAE;SAC1B,CAAA;QAED,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;QAE7C,mBAAmB;QACnB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;YAClD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,Y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AS,CAAA;IACpB,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,KAAqB,EAAE,IAAgB;QAC1D,kCAAkC;QAClC,gDAAgD;QAChD,OAAO,IAAI,CAAC,GAAG,CAAA;IACnB,CAAC;IAED;;OAEG;IACK,aAAa;QACjB,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAA;QAEvB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YACzD,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;YAChF,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAA;YAElD,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACjC,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAlPD,kCAkPC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC7B,OAAO,IAAI,WAAW,EAAE,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Link Parser - Extract and parse links from Jotx documents
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - Wikilinks: [[Document Name]]
|
|
6
|
+
* - Block links: [[Document#block-id]]
|
|
7
|
+
* - Tags: #tag-name
|
|
8
|
+
*
|
|
9
|
+
* Follows Jotx V3 architecture
|
|
10
|
+
*/
|
|
11
|
+
import { ParsedLink } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Extract all links from text
|
|
14
|
+
* Returns both wikilinks and tags
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractLinks(text: string): ParsedLink[];
|
|
17
|
+
/**
|
|
18
|
+
* Validate if a string is a valid wikilink
|
|
19
|
+
*/
|
|
20
|
+
export declare function isValidWikilink(text: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Validate if a string is a valid tag
|
|
23
|
+
*/
|
|
24
|
+
export declare function isValidTag(text: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Format a link for display
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatLink(link: ParsedLink): string;
|
|
29
|
+
/**
|
|
30
|
+
* Create a link to a document
|
|
31
|
+
*/
|
|
32
|
+
export declare function createDocumentLink(documentName: string, displayText?: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Create a link to a specific block
|
|
35
|
+
*/
|
|
36
|
+
export declare function createBlockLink(documentName: string, blockId: string, displayText?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Create a tag reference
|
|
39
|
+
*/
|
|
40
|
+
export declare function createTag(tagName: string): string;
|
|
41
|
+
//# sourceMappingURL=LinkParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkParser.d.ts","sourceRoot":"","sources":["../../src/links/LinkParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAY,MAAM,SAAS,CAAA;AAyD9C;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CA8CvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAYnD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAKrF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAMnG;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Link Parser - Extract and parse links from Jotx documents
|
|
4
|
+
*
|
|
5
|
+
* Supports:
|
|
6
|
+
* - Wikilinks: [[Document Name]]
|
|
7
|
+
* - Block links: [[Document#block-id]]
|
|
8
|
+
* - Tags: #tag-name
|
|
9
|
+
*
|
|
10
|
+
* Follows Jotx V3 architecture
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.extractLinks = extractLinks;
|
|
14
|
+
exports.isValidWikilink = isValidWikilink;
|
|
15
|
+
exports.isValidTag = isValidTag;
|
|
16
|
+
exports.formatLink = formatLink;
|
|
17
|
+
exports.createDocumentLink = createDocumentLink;
|
|
18
|
+
exports.createBlockLink = createBlockLink;
|
|
19
|
+
exports.createTag = createTag;
|
|
20
|
+
/**
|
|
21
|
+
* Wikilink patterns
|
|
22
|
+
* [[Document Name]] - Link to document
|
|
23
|
+
* [[Document#block-id]] - Link to specific block
|
|
24
|
+
* [[Document|Display Text]] - Link with custom text
|
|
25
|
+
*/
|
|
26
|
+
const WIKILINK_PATTERN = /\[\[([^\]]+)\]\]/g;
|
|
27
|
+
/**
|
|
28
|
+
* Tag pattern
|
|
29
|
+
* #tag-name or #multi-word-tag
|
|
30
|
+
*/
|
|
31
|
+
const TAG_PATTERN = /#([a-zA-Z0-9_-]+)/g;
|
|
32
|
+
/**
|
|
33
|
+
* Parse wikilink syntax into components
|
|
34
|
+
*/
|
|
35
|
+
function parseWikilink(content) {
|
|
36
|
+
if (!content || content.trim().length === 0) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
// Check for custom display text: [[Target|Display]]
|
|
40
|
+
const pipeIndex = content.indexOf('|');
|
|
41
|
+
let target = content;
|
|
42
|
+
let displayText;
|
|
43
|
+
if (pipeIndex > -1) {
|
|
44
|
+
target = content.substring(0, pipeIndex).trim();
|
|
45
|
+
displayText = content.substring(pipeIndex + 1).trim();
|
|
46
|
+
}
|
|
47
|
+
// Check for block reference: [[Document#block-id]]
|
|
48
|
+
const hashIndex = target.indexOf('#');
|
|
49
|
+
let documentName = target;
|
|
50
|
+
let blockId;
|
|
51
|
+
if (hashIndex > -1) {
|
|
52
|
+
documentName = target.substring(0, hashIndex).trim();
|
|
53
|
+
blockId = target.substring(hashIndex + 1).trim();
|
|
54
|
+
}
|
|
55
|
+
if (!documentName) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
type: blockId ? 'block' : 'document',
|
|
60
|
+
src: target,
|
|
61
|
+
text: displayText,
|
|
62
|
+
documentName,
|
|
63
|
+
blockId
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Extract all links from text
|
|
68
|
+
* Returns both wikilinks and tags
|
|
69
|
+
*/
|
|
70
|
+
function extractLinks(text) {
|
|
71
|
+
if (!text || typeof text !== 'string') {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const links = [];
|
|
75
|
+
// Extract wikilinks
|
|
76
|
+
const wikilinkMatches = text.matchAll(WIKILINK_PATTERN);
|
|
77
|
+
for (const match of wikilinkMatches) {
|
|
78
|
+
const parsed = parseWikilink(match[1]);
|
|
79
|
+
if (parsed) {
|
|
80
|
+
if (match.index !== undefined) {
|
|
81
|
+
parsed.position = {
|
|
82
|
+
start: match.index,
|
|
83
|
+
end: match.index + match[0].length
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
links.push(parsed);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Extract tags
|
|
90
|
+
const tagMatches = text.matchAll(TAG_PATTERN);
|
|
91
|
+
for (const match of tagMatches) {
|
|
92
|
+
const tagName = match[1];
|
|
93
|
+
if (tagName) {
|
|
94
|
+
const link = {
|
|
95
|
+
type: 'tag',
|
|
96
|
+
src: `#${tagName}`,
|
|
97
|
+
documentName: tagName, // For tags, documentName is the tag itself
|
|
98
|
+
text: tagName
|
|
99
|
+
};
|
|
100
|
+
if (match.index !== undefined) {
|
|
101
|
+
link.position = {
|
|
102
|
+
start: match.index,
|
|
103
|
+
end: match.index + match[0].length
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
links.push(link);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return links;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Validate if a string is a valid wikilink
|
|
113
|
+
*/
|
|
114
|
+
function isValidWikilink(text) {
|
|
115
|
+
return WIKILINK_PATTERN.test(text);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Validate if a string is a valid tag
|
|
119
|
+
*/
|
|
120
|
+
function isValidTag(text) {
|
|
121
|
+
return TAG_PATTERN.test(text);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Format a link for display
|
|
125
|
+
*/
|
|
126
|
+
function formatLink(link) {
|
|
127
|
+
if (link.type === 'tag') {
|
|
128
|
+
return `#${link.documentName}`;
|
|
129
|
+
}
|
|
130
|
+
if (link.type === 'block') {
|
|
131
|
+
const display = link.text || link.documentName;
|
|
132
|
+
return `[[${link.src}|${display}]]`;
|
|
133
|
+
}
|
|
134
|
+
const display = link.text || link.documentName;
|
|
135
|
+
return link.text ? `[[${link.documentName}|${display}]]` : `[[${link.documentName}]]`;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create a link to a document
|
|
139
|
+
*/
|
|
140
|
+
function createDocumentLink(documentName, displayText) {
|
|
141
|
+
if (displayText && displayText !== documentName) {
|
|
142
|
+
return `[[${documentName}|${displayText}]]`;
|
|
143
|
+
}
|
|
144
|
+
return `[[${documentName}]]`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create a link to a specific block
|
|
148
|
+
*/
|
|
149
|
+
function createBlockLink(documentName, blockId, displayText) {
|
|
150
|
+
const target = `${documentName}#${blockId}`;
|
|
151
|
+
if (displayText) {
|
|
152
|
+
return `[[${target}|${displayText}]]`;
|
|
153
|
+
}
|
|
154
|
+
return `[[${target}]]`;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create a tag reference
|
|
158
|
+
*/
|
|
159
|
+
function createTag(tagName) {
|
|
160
|
+
return `#${tagName}`;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=LinkParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkParser.js","sourceRoot":"","sources":["../../src/links/LinkParser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AA+DH,oCA8CC;AAKD,0CAEC;AAKD,gCAEC;AAKD,gCAYC;AAKD,gDAKC;AAKD,0CAMC;AAKD,8BAEC;AApKD;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,mBAAmB,CAAA;AAE5C;;;GAGG;AACH,MAAM,WAAW,GAAG,oBAAoB,CAAA;AAExC;;GAEG;AACH,SAAS,aAAa,CAAC,OAAe;IAClC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAA;IACf,CAAC;IAED,oDAAoD;IACpD,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACtC,IAAI,MAAM,GAAG,OAAO,CAAA;IACpB,IAAI,WAA+B,CAAA;IAEnC,IAAI,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC;QACjB,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,IAAI,EAAE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- Link parser (extract wikilinks and tags)
|
|
7
|
+
* - Link indexer (track connections and backlinks)
|
|
8
|
+
*/
|
|
9
|
+
export * from './types';
|
|
10
|
+
export * from './LinkParser';
|
|
11
|
+
export * from './LinkIndexer';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/links/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Links Module - Link parsing and indexing for Jotx documents
|
|
4
|
+
*
|
|
5
|
+
* Exports:
|
|
6
|
+
* - Link types and interfaces
|
|
7
|
+
* - Link parser (extract wikilinks and tags)
|
|
8
|
+
* - Link indexer (track connections and backlinks)
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
__exportStar(require("./types"), exports);
|
|
26
|
+
__exportStar(require("./LinkParser"), exports);
|
|
27
|
+
__exportStar(require("./LinkIndexer"), exports);
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/links/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;AAEH,0CAAuB;AACvB,+CAA4B;AAC5B,gDAA6B"}
|