@hiraokahypertools/pst-extractor 0.1.0-alpha.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.
- package/dist/BTHeap.d.ts +15 -0
- package/dist/BTHeap.js +76 -0
- package/dist/CollectionAsyncProvider.d.ts +15 -0
- package/dist/CollectionAsyncProvider.js +44 -0
- package/dist/KeyedDelay.d.ts +8 -0
- package/dist/KeyedDelay.js +37 -0
- package/dist/LZFu.class.d.ts +12 -0
- package/dist/LZFu.class.js +95 -0
- package/dist/NodeMap.class.d.ts +35 -0
- package/dist/NodeMap.class.js +86 -0
- package/dist/OutlookProperties.d.ts +278 -0
- package/dist/OutlookProperties.js +284 -0
- package/dist/PAUtil.d.ts +17 -0
- package/dist/PAUtil.js +145 -0
- package/dist/PHNodeHeap.d.ts +16 -0
- package/dist/PHNodeHeap.js +2 -0
- package/dist/PHNodeHeapReader.d.ts +6 -0
- package/dist/PHNodeHeapReader.js +5 -0
- package/dist/PHUtil.d.ts +6 -0
- package/dist/PHUtil.js +103 -0
- package/dist/PLMisc.d.ts +8 -0
- package/dist/PLMisc.js +16 -0
- package/dist/PLNode.d.ts +11 -0
- package/dist/PLNode.js +5 -0
- package/dist/PLStore.d.ts +9 -0
- package/dist/PLStore.js +5 -0
- package/dist/PLSubNode.d.ts +8 -0
- package/dist/PLSubNode.js +5 -0
- package/dist/PLUtil.d.ts +29 -0
- package/dist/PLUtil.js +683 -0
- package/dist/PSTActivity.class.d.ts +103 -0
- package/dist/PSTActivity.class.js +144 -0
- package/dist/PSTAppointment.class.d.ts +275 -0
- package/dist/PSTAppointment.class.js +381 -0
- package/dist/PSTAttachment.class.d.ts +168 -0
- package/dist/PSTAttachment.class.js +286 -0
- package/dist/PSTContact.class.d.ts +900 -0
- package/dist/PSTContact.class.js +1253 -0
- package/dist/PSTFile.class.d.ts +144 -0
- package/dist/PSTFile.class.js +221 -0
- package/dist/PSTFolder.class.d.ts +111 -0
- package/dist/PSTFolder.class.js +269 -0
- package/dist/PSTMessage.class.d.ts +773 -0
- package/dist/PSTMessage.class.js +1264 -0
- package/dist/PSTMessageStore.class.d.ts +16 -0
- package/dist/PSTMessageStore.class.js +18 -0
- package/dist/PSTObject.class.d.ts +107 -0
- package/dist/PSTObject.class.js +208 -0
- package/dist/PSTOpts.d.ts +24 -0
- package/dist/PSTOpts.js +2 -0
- package/dist/PSTRecipient.class.d.ts +68 -0
- package/dist/PSTRecipient.class.js +105 -0
- package/dist/PSTTask.class.d.ts +146 -0
- package/dist/PSTTask.class.js +206 -0
- package/dist/PSTUtil.class.d.ts +134 -0
- package/dist/PSTUtil.class.js +804 -0
- package/dist/Property.d.ts +38 -0
- package/dist/Property.js +2 -0
- package/dist/PropertyContext.d.ts +6 -0
- package/dist/PropertyContext.js +2 -0
- package/dist/PropertyContextUtil.d.ts +4 -0
- package/dist/PropertyContextUtil.js +77 -0
- package/dist/PropertyTypeObject.d.ts +12 -0
- package/dist/PropertyTypeObject.js +21 -0
- package/dist/PropertyValueResolver.d.ts +4 -0
- package/dist/PropertyValueResolver.js +2 -0
- package/dist/PropertyValueResolverV1.d.ts +7 -0
- package/dist/PropertyValueResolverV1.js +253 -0
- package/dist/RawProperty.d.ts +8 -0
- package/dist/RawProperty.js +2 -0
- package/dist/RecurrencePattern.class.d.ts +50 -0
- package/dist/RecurrencePattern.class.js +120 -0
- package/dist/RootProvider.d.ts +12 -0
- package/dist/RootProvider.js +2 -0
- package/dist/SingleAsyncProvider.d.ts +5 -0
- package/dist/SingleAsyncProvider.js +30 -0
- package/dist/TableContext.d.ts +4 -0
- package/dist/TableContext.js +2 -0
- package/dist/TableContextUtil.d.ts +4 -0
- package/dist/TableContextUtil.js +147 -0
- package/dist/TableRow.d.ts +6 -0
- package/dist/TableRow.js +2 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +28 -0
- package/dist/msftUuidStringify.d.ts +17 -0
- package/dist/msftUuidStringify.js +48 -0
- package/dist/openPstFile.d.ts +19 -0
- package/dist/openPstFile.js +67 -0
- package/package.json +105 -0
- package/readme.md +16 -0
package/dist/BTHeap.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PHNodeHeapReader } from "./PHNodeHeapReader";
|
|
2
|
+
export declare function getBTHeapReaderFrom(heap: PHNodeHeapReader, hnid: number): Promise<BTHeapReader>;
|
|
3
|
+
export interface BTHeapReader {
|
|
4
|
+
list(): Promise<BTHeapEntry[]>;
|
|
5
|
+
}
|
|
6
|
+
export interface BTHeapEntry {
|
|
7
|
+
/**
|
|
8
|
+
* 2, 4, 8, or 16
|
|
9
|
+
*/
|
|
10
|
+
key: ArrayBuffer;
|
|
11
|
+
/**
|
|
12
|
+
* 1 ~ 32
|
|
13
|
+
*/
|
|
14
|
+
data: ArrayBuffer;
|
|
15
|
+
}
|
package/dist/BTHeap.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getBTHeapReaderFrom = void 0;
|
|
13
|
+
function getBTHeapReaderFrom(heap, hnid) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const header = yield heap.getHeapBuffers(hnid);
|
|
16
|
+
if (header.length !== 1) {
|
|
17
|
+
throw new Error(`btree heap buffer must be single`);
|
|
18
|
+
}
|
|
19
|
+
const headerView = new DataView(header[0]);
|
|
20
|
+
const bTypeBTH = 0xB5;
|
|
21
|
+
if (headerView.getUint8(0) !== bTypeBTH) {
|
|
22
|
+
throw new Error(`signature must be bTypeBTH`);
|
|
23
|
+
}
|
|
24
|
+
const cbKey = headerView.getUint8(1);
|
|
25
|
+
const cbEnt = headerView.getUint8(2);
|
|
26
|
+
const bIdxLevels = headerView.getUint8(3);
|
|
27
|
+
const hidRoot = headerView.getUint32(4, true);
|
|
28
|
+
const list = [];
|
|
29
|
+
function recursive(hid, level) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
if (hid !== 0) {
|
|
32
|
+
if (level === 0) {
|
|
33
|
+
const recordSize = cbKey + cbEnt;
|
|
34
|
+
const records = (yield heap.getHeapBuffers(hid));
|
|
35
|
+
if (records.length !== 1) {
|
|
36
|
+
throw new Error(`btree heap record must be single`);
|
|
37
|
+
}
|
|
38
|
+
const record = records[0];
|
|
39
|
+
const numRecords = Math.floor(record.byteLength / recordSize);
|
|
40
|
+
for (let x = 0; x < numRecords; x++) {
|
|
41
|
+
const top = recordSize * x;
|
|
42
|
+
list.push({
|
|
43
|
+
key: record.slice(top, top + cbKey),
|
|
44
|
+
data: record.slice(top + cbKey, top + recordSize),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const recordSize = cbKey + 4;
|
|
50
|
+
const records = (yield heap.getHeapBuffers(hid));
|
|
51
|
+
if (records.length !== 1) {
|
|
52
|
+
throw new Error(`btree intermediate record must be single`);
|
|
53
|
+
}
|
|
54
|
+
const record = records[0];
|
|
55
|
+
const recordView = new DataView(record);
|
|
56
|
+
const numRecords = Math.floor(record.byteLength / recordSize);
|
|
57
|
+
for (let x = 0; x < numRecords; x++) {
|
|
58
|
+
const top = recordSize * x;
|
|
59
|
+
const hidInner = recordView.getUint32(top + cbKey, true);
|
|
60
|
+
yield recursive(hidInner, level - 1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
yield recursive(hidRoot, bIdxLevels);
|
|
67
|
+
return {
|
|
68
|
+
list() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
return list;
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.getBTHeapReaderFrom = getBTHeapReaderFrom;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export declare class CollectionAsyncProvider<T> {
|
|
5
|
+
private _cache;
|
|
6
|
+
private _count;
|
|
7
|
+
private _itemProvider;
|
|
8
|
+
constructor(count: number, itemProvider: (index: number) => Promise<T>);
|
|
9
|
+
get count(): number;
|
|
10
|
+
get(index: number): Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* get all of the children
|
|
13
|
+
*/
|
|
14
|
+
all(): Promise<T[]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CollectionAsyncProvider = void 0;
|
|
13
|
+
const KeyedDelay_1 = require("./KeyedDelay");
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
class CollectionAsyncProvider {
|
|
18
|
+
constructor(count, itemProvider) {
|
|
19
|
+
this._cache = new KeyedDelay_1.KeyedDelay();
|
|
20
|
+
this._count = count;
|
|
21
|
+
this._itemProvider = itemProvider;
|
|
22
|
+
}
|
|
23
|
+
get count() {
|
|
24
|
+
return this._count;
|
|
25
|
+
}
|
|
26
|
+
get(index) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
return yield this._cache.getOrCreate(index.toString(), () => __awaiter(this, void 0, void 0, function* () { return yield this._itemProvider(index); }));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* get all of the children
|
|
33
|
+
*/
|
|
34
|
+
all() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const array = [];
|
|
37
|
+
for (let x = 0; x < this._count; x++) {
|
|
38
|
+
array.push(yield this.get(x));
|
|
39
|
+
}
|
|
40
|
+
return array;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.CollectionAsyncProvider = CollectionAsyncProvider;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.KeyedDelay = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
class KeyedDelay {
|
|
17
|
+
constructor() {
|
|
18
|
+
this._map = new Map();
|
|
19
|
+
}
|
|
20
|
+
getOrCreate(key, provider) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (this._map.has(key)) {
|
|
23
|
+
const value = this._map.get(key);
|
|
24
|
+
if (value === undefined) {
|
|
25
|
+
throw new Error("provider must provide a non-undefined value");
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const value = yield provider();
|
|
31
|
+
this._map.set(key, value);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.KeyedDelay = KeyedDelay;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class LZFu {
|
|
3
|
+
private static LZFU_HEADER;
|
|
4
|
+
/**
|
|
5
|
+
* Decompress the buffer of RTF content using LZ
|
|
6
|
+
* @static
|
|
7
|
+
* @param {Buffer} data
|
|
8
|
+
* @returns {string}
|
|
9
|
+
* @memberof LZFu
|
|
10
|
+
*/
|
|
11
|
+
static decode(data: Buffer): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LZFu = void 0;
|
|
4
|
+
const PSTUtil_class_1 = require("./PSTUtil.class");
|
|
5
|
+
// An implementation of the LZFu algorithm to decompress RTF content
|
|
6
|
+
class LZFu {
|
|
7
|
+
/**
|
|
8
|
+
* Decompress the buffer of RTF content using LZ
|
|
9
|
+
* @static
|
|
10
|
+
* @param {Buffer} data
|
|
11
|
+
* @returns {string}
|
|
12
|
+
* @memberof LZFu
|
|
13
|
+
*/
|
|
14
|
+
static decode(data) {
|
|
15
|
+
// const compressedSize: number = PSTUtil.convertLittleEndianBytesToLong(
|
|
16
|
+
// data,
|
|
17
|
+
// 0,
|
|
18
|
+
// 4
|
|
19
|
+
// ).toNumber()
|
|
20
|
+
const uncompressedSize = PSTUtil_class_1.PSTUtil.convertLittleEndianBytesToLong(data, 4, 8).toNumber();
|
|
21
|
+
const compressionSig = PSTUtil_class_1.PSTUtil.convertLittleEndianBytesToLong(data, 8, 12).toNumber();
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
|
+
const compressedCRC = PSTUtil_class_1.PSTUtil.convertLittleEndianBytesToLong(data, 12, 16).toNumber();
|
|
24
|
+
if (compressionSig == 0x75465a4c) {
|
|
25
|
+
// we are compressed...
|
|
26
|
+
const output = Buffer.alloc(uncompressedSize);
|
|
27
|
+
let outputPosition = 0;
|
|
28
|
+
const lzBuffer = Buffer.alloc(4096);
|
|
29
|
+
// preload our buffer.
|
|
30
|
+
try {
|
|
31
|
+
const bytes = Buffer.from(LZFu.LZFU_HEADER); //getBytes("US-ASCII");
|
|
32
|
+
PSTUtil_class_1.PSTUtil.arraycopy(bytes, 0, lzBuffer, 0, LZFu.LZFU_HEADER.length);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
console.error('LZFu::decode cant preload buffer\n' + err);
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
38
|
+
let bufferPosition = LZFu.LZFU_HEADER.length;
|
|
39
|
+
let currentDataPosition = 16;
|
|
40
|
+
// next byte is the flags,
|
|
41
|
+
while (currentDataPosition < data.length - 2 &&
|
|
42
|
+
outputPosition < output.length) {
|
|
43
|
+
let flags = data[currentDataPosition++] & 0xff;
|
|
44
|
+
for (let x = 0; x < 8 && outputPosition < output.length; x++) {
|
|
45
|
+
const isRef = (flags & 1) == 1;
|
|
46
|
+
flags >>= 1;
|
|
47
|
+
if (isRef) {
|
|
48
|
+
// get the starting point for the buffer and the length to read
|
|
49
|
+
const refOffsetOrig = data[currentDataPosition++] & 0xff;
|
|
50
|
+
const refSizeOrig = data[currentDataPosition++] & 0xff;
|
|
51
|
+
const refOffset = (refOffsetOrig << 4) | (refSizeOrig >>> 4);
|
|
52
|
+
const refSize = (refSizeOrig & 0xf) + 2;
|
|
53
|
+
try {
|
|
54
|
+
// copy the data from the buffer
|
|
55
|
+
let index = refOffset;
|
|
56
|
+
for (let y = 0; y < refSize && outputPosition < output.length; y++) {
|
|
57
|
+
output[outputPosition++] = lzBuffer[index];
|
|
58
|
+
lzBuffer[bufferPosition] = lzBuffer[index];
|
|
59
|
+
bufferPosition++;
|
|
60
|
+
bufferPosition %= 4096;
|
|
61
|
+
++index;
|
|
62
|
+
index %= 4096;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error('LZFu::decode copy the data from the buffer\n' + err);
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// copy the byte over
|
|
72
|
+
lzBuffer[bufferPosition] = data[currentDataPosition];
|
|
73
|
+
bufferPosition++;
|
|
74
|
+
bufferPosition %= 4096;
|
|
75
|
+
output[outputPosition++] = data[currentDataPosition++];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (outputPosition != uncompressedSize) {
|
|
80
|
+
throw new Error('LZFu::constructor decode Error decompressing RTF');
|
|
81
|
+
}
|
|
82
|
+
return new String(output).trim();
|
|
83
|
+
}
|
|
84
|
+
else if (compressionSig == 0x414c454d) {
|
|
85
|
+
// we are not compressed!
|
|
86
|
+
// just return the rest of the contents as a string
|
|
87
|
+
const output = Buffer.alloc(data.length - 16);
|
|
88
|
+
PSTUtil_class_1.PSTUtil.arraycopy(data, 16, output, 0, data.length - 16);
|
|
89
|
+
return new String(output).trim();
|
|
90
|
+
}
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.LZFu = LZFu;
|
|
95
|
+
LZFu.LZFU_HEADER = '{\\rtf1\\ansi\\mac\\deff0\\deftab720{\\fonttbl;}{\\f0\\fnil \\froman \\fswiss \\fmodern \\fscript \\fdecor MS Sans SerifSymbolArialTimes New RomanCourier{\\colortbl\\red0\\green0\\blue0\n\r\\par \\pard\\plain\\f0\\fs20\\b\\i\\u\\tab\\tx';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Long from 'long';
|
|
2
|
+
/**
|
|
3
|
+
* Stores node names (both alpha and numeric) in node maps for quick lookup.
|
|
4
|
+
* @export
|
|
5
|
+
* @class NodeMap
|
|
6
|
+
*/
|
|
7
|
+
export declare class NodeMap {
|
|
8
|
+
private nameToId;
|
|
9
|
+
private idToNumericName;
|
|
10
|
+
private idToStringName;
|
|
11
|
+
/**
|
|
12
|
+
* Set a node into the map.
|
|
13
|
+
* @param {*} key
|
|
14
|
+
* @param {number} propId
|
|
15
|
+
* @param {number} [idx]
|
|
16
|
+
* @memberof NodeMap
|
|
17
|
+
*/
|
|
18
|
+
setId(key: any, propId: number, idx?: number): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get a node from the map.
|
|
21
|
+
* @param {*} key
|
|
22
|
+
* @param {number} [idx]
|
|
23
|
+
* @returns {number}
|
|
24
|
+
* @memberof NodeMap
|
|
25
|
+
*/
|
|
26
|
+
getId(key: any, idx?: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Get a node from the map.
|
|
29
|
+
* @param {number} propId
|
|
30
|
+
* @returns {long}
|
|
31
|
+
* @memberof NodeMap
|
|
32
|
+
*/
|
|
33
|
+
getNumericName(propId: number): Long | undefined;
|
|
34
|
+
private transformKey;
|
|
35
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NodeMap = void 0;
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
const long_1 = __importDefault(require("long"));
|
|
9
|
+
/**
|
|
10
|
+
* Stores node names (both alpha and numeric) in node maps for quick lookup.
|
|
11
|
+
* @export
|
|
12
|
+
* @class NodeMap
|
|
13
|
+
*/
|
|
14
|
+
class NodeMap {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.nameToId = new Map();
|
|
17
|
+
this.idToNumericName = new Map();
|
|
18
|
+
this.idToStringName = new Map();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Set a node into the map.
|
|
22
|
+
* @param {*} key
|
|
23
|
+
* @param {number} propId
|
|
24
|
+
* @param {number} [idx]
|
|
25
|
+
* @memberof NodeMap
|
|
26
|
+
*/
|
|
27
|
+
setId(key, propId, idx) {
|
|
28
|
+
if (typeof key === 'number' && idx !== undefined) {
|
|
29
|
+
const lkey = this.transformKey(key, idx);
|
|
30
|
+
this.nameToId.set(lkey.toString(), propId);
|
|
31
|
+
this.idToNumericName.set(propId, lkey);
|
|
32
|
+
// console.log('NodeMap::setId: propId = ' + propId + ', lkey = ' + lkey.toString());
|
|
33
|
+
}
|
|
34
|
+
else if (typeof key === 'string') {
|
|
35
|
+
this.nameToId.set(key, propId);
|
|
36
|
+
this.idToStringName.set(propId, key);
|
|
37
|
+
// console.log('NodeMap::setId: propId = ' + propId + ', key = ' + key);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new Error('NodeMap::setId bad param type ' + typeof key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get a node from the map.
|
|
45
|
+
* @param {*} key
|
|
46
|
+
* @param {number} [idx]
|
|
47
|
+
* @returns {number}
|
|
48
|
+
* @memberof NodeMap
|
|
49
|
+
*/
|
|
50
|
+
getId(key, idx) {
|
|
51
|
+
let id = undefined;
|
|
52
|
+
if (typeof key === 'number' && idx) {
|
|
53
|
+
id = this.nameToId.get(this.transformKey(key, idx).toString());
|
|
54
|
+
}
|
|
55
|
+
else if (typeof key === 'string') {
|
|
56
|
+
id = this.nameToId.get(key);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error('NodeMap::getId bad param type ' + typeof key);
|
|
60
|
+
}
|
|
61
|
+
if (!id) {
|
|
62
|
+
return -1;
|
|
63
|
+
}
|
|
64
|
+
return id;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get a node from the map.
|
|
68
|
+
* @param {number} propId
|
|
69
|
+
* @returns {long}
|
|
70
|
+
* @memberof NodeMap
|
|
71
|
+
*/
|
|
72
|
+
getNumericName(propId) {
|
|
73
|
+
const lkey = this.idToNumericName.get(propId);
|
|
74
|
+
if (!lkey) {
|
|
75
|
+
// console.log("NodeMap::getNumericName Name to Id mapping not found, propId = " + propId);
|
|
76
|
+
}
|
|
77
|
+
return lkey;
|
|
78
|
+
}
|
|
79
|
+
transformKey(key, idx) {
|
|
80
|
+
let lidx = long_1.default.fromNumber(idx);
|
|
81
|
+
lidx = lidx.shiftLeft(32);
|
|
82
|
+
lidx = lidx.or(key);
|
|
83
|
+
return lidx;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.NodeMap = NodeMap;
|