Skip to content

Commit

Permalink
refactor: enable verbatimModuleSyntax
Browse files Browse the repository at this point in the history
  • Loading branch information
andipaetzold committed Nov 28, 2023
1 parent 642cda0 commit 38d32ed
Show file tree
Hide file tree
Showing 33 changed files with 67 additions and 66 deletions.
6 changes: 3 additions & 3 deletions src/Database.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CodecHandler, createCodecHandler } from "./codec-handler/index.js";
import { type CodecHandler, createCodecHandler } from "./codec-handler/index.js";
import { decryptRC4 } from "./crypto/index.js";
import { readDateTime } from "./data/datetime.js";
import { getJetFormat, JetFormat } from "./JetFormat/index.js";
import { getJetFormat, type JetFormat } from "./JetFormat/index.js";
import { PageType, assertPageType } from "./PageType.js";
import { SortOrder } from "./types.js";
import type { SortOrder } from "./types.js";
import { uncompressText } from "./unicodeCompression.js";
import { isEmptyBuffer, xor } from "./util.js";

Expand Down
4 changes: 2 additions & 2 deletions src/JetFormat/Jet12Format.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jet4Format } from "./Jet4Format.js";
import { CodecType, JetFormat } from "./types.js";
import { CodecType, type JetFormat } from "./types.js";

export const jet12Format: JetFormat = {
...jet4Format,
codecType: CodecType.OFFICE,
};
};
2 changes: 1 addition & 1 deletion src/JetFormat/Jet14Format.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GENERAL_SORT_ORDER } from "../SortOrder.js";
import { jet12Format } from "./Jet12Format.js";
import { JetFormat } from "./types.js";
import type { JetFormat } from "./types.js";

export const jet14Format: JetFormat = {
...jet12Format,
Expand Down
2 changes: 1 addition & 1 deletion src/JetFormat/Jet15Format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jet14Format } from "./Jet14Format.js";
import { JetFormat } from "./types.js";
import type { JetFormat } from "./types.js";

export const jet15Format: JetFormat = jet14Format;
2 changes: 1 addition & 1 deletion src/JetFormat/Jet16Format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jet15Format } from "./Jet15Format.js";
import { JetFormat } from "./types.js";
import type { JetFormat } from "./types.js";

export const jet16Format: JetFormat = jet15Format;
2 changes: 1 addition & 1 deletion src/JetFormat/Jet17Format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jet16Format } from "./Jet16Format.js";
import { JetFormat } from "./types.js";
import type { JetFormat } from "./types.js";

export const jet17Format: JetFormat = jet16Format;
2 changes: 1 addition & 1 deletion src/JetFormat/Jet3Format.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GENERAL_97_SORT_ORDER } from "../SortOrder.js";
import { CodecType, JetFormat } from "./types.js";
import { CodecType, type JetFormat } from "./types.js";

export const jet3Format: JetFormat = {
codecType: CodecType.JET,
Expand Down
4 changes: 2 additions & 2 deletions src/JetFormat/Jet4Format.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GENERAL_LEGACY_SORT_ORDER } from "../SortOrder.js";
import { CodecType, JetFormat } from "./types.js";
import { CodecType, type JetFormat } from "./types.js";

export const jet4Format: JetFormat = {
codecType: CodecType.JET,

pageSize: 4096,

textEncoding: "ucs-2",
Expand Down
2 changes: 1 addition & 1 deletion src/JetFormat/MSISAMFormat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jet4Format } from "./Jet4Format.js";
import { CodecType, JetFormat } from "./types.js";
import { CodecType, type JetFormat } from "./types.js";

export const msisamFormat: JetFormat = {
...jet4Format,
Expand Down
2 changes: 1 addition & 1 deletion src/JetFormat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { jet17Format } from "./Jet17Format.js";
import { jet3Format } from "./Jet3Format.js";
import { jet4Format } from "./Jet4Format.js";
import { msisamFormat } from "./MSISAMFormat.js";
import { JetFormat } from "./types.js";
import type { JetFormat } from "./types.js";

export type { JetFormat } from "./types.js";

Expand Down
2 changes: 1 addition & 1 deletion src/JetFormat/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SortOrder } from "../types.js";
import type { SortOrder } from "../types.js";

export interface JetFormat {
codecType: CodecType;
Expand Down
4 changes: 2 additions & 2 deletions src/MDBReader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Database } from "./Database.js";
import { PageType, assertPageType } from "./PageType.js";
import { SysObject, isSysObjectType, isSystemObject, SysObjectTypes } from "./SysObject.js";
import { type SysObject, isSysObjectType, isSystemObject, SysObjectTypes } from "./SysObject.js";
import { Table } from "./Table.js";
import { SortOrder } from "./types.js";
import type { SortOrder } from "./types.js";

const MSYS_OBJECTS_TABLE = "MSysObjects";
const MSYS_OBJECTS_PAGE = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/SortOrder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SortOrder } from "./types.js";
import type { SortOrder } from "./types.js";

const GENERAL_SORT_ORDER_VALUE = 1033;

Expand Down
4 changes: 2 additions & 2 deletions src/Table.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ColumnTypes } from "./index.js";
import { Column, ColumnDefinition, getColumnType, parseColumnFlags } from "./column.js";
import { type Column, type ColumnDefinition, getColumnType, parseColumnFlags } from "./column.js";
import { readFieldValue } from "./data/index.js";
import { Database } from "./Database.js";
import { PageType, assertPageType } from "./PageType.js";
import { Value } from "./types.js";
import type { Value } from "./types.js";
import { uncompressText } from "./unicodeCompression.js";
import { findMapPages } from "./usage-map.js";
import { getBitmapValue, roundToFullByte } from "./util.js";
Expand Down
2 changes: 1 addition & 1 deletion src/codec-handler/create.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodecHandler } from "./index.js";
import type { CodecHandler } from "./index.js";
import { getJetFormat } from "../JetFormat/index.js";
import { CodecType } from "../JetFormat/types.js";
import { createIdentityHandler } from "./handlers/identity.js";
Expand Down
4 changes: 2 additions & 2 deletions src/codec-handler/handlers/identity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CodecHandler } from "../types.js";
import type { CodecHandler } from "../types.js";

export function createIdentityHandler(): CodecHandler {
return {
decryptPage: (b) => b,
verifyPassword: () => true
verifyPassword: () => true,
};
}
4 changes: 2 additions & 2 deletions src/codec-handler/handlers/jet.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CodecHandler } from "../index.js";
import type { CodecHandler } from "../index.js";
import { decryptRC4 } from "../../crypto/index.js";
import { isEmptyBuffer } from "../../util.js";
import { createIdentityHandler } from "./identity.js";
import { DecryptPage } from "../types.js";
import type { DecryptPage } from "../types.js";
import { getPageEncodingKey } from "../util.js";

const KEY_OFFSET = 0x3e; // 62
Expand Down
4 changes: 2 additions & 2 deletions src/codec-handler/handlers/office/EncryptionHeader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isInRange } from "../../../util.js";
import { CryptoAlgorithm, CRYPTO_ALGORITHMS } from "./CryptoAlgorithm.js";
import { HashAlgorithm, HASH_ALGORITHMS } from "./HashAlgorithm.js";
import { type CryptoAlgorithm, CRYPTO_ALGORITHMS } from "./CryptoAlgorithm.js";
import { type HashAlgorithm, HASH_ALGORITHMS } from "./HashAlgorithm.js";

const FLAGS_OFFSET = 0;
const CRYPTO_OFFSET = 8;
Expand Down
2 changes: 1 addition & 1 deletion src/codec-handler/handlers/office/EncryptionVerifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CryptoAlgorithm } from "./CryptoAlgorithm.js";
import type { CryptoAlgorithm } from "./CryptoAlgorithm.js";

// are those the same values for ECMA Standard?
const SALT_SIZE_OFFSET = 138;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { XMLParser } from "fast-xml-parser";
import { EncryptionDescriptor } from "./types.js";
import type { EncryptionDescriptor } from "./types.js";

const xmlParser = new XMLParser({
ignoreAttributes: false,
Expand Down
6 changes: 3 additions & 3 deletions src/codec-handler/handlers/office/agile/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CodecHandler, VerifyPassword } from "../../../index.js";
import type { CodecHandler, VerifyPassword } from "../../../index.js";
import { blockDecrypt, deriveKey, hash } from "../../../../crypto/index.js";
import { fixBufferLength, roundToFullByte } from "../../../../util.js";
import { DecryptPage } from "../../../types.js";
import type { DecryptPage } from "../../../types.js";
import { getPageEncodingKey } from "../../../util.js";
import { parseEncryptionDescriptor } from "./EncryptionDescriptor.js";
import { PasswordKeyEncryptor } from "./types.js";
import type { PasswordKeyEncryptor } from "./types.js";

const ENC_VERIFIER_INPUT_BLOCK = [0xfe, 0xa7, 0xd2, 0x76, 0x3b, 0x4b, 0x9e, 0x79];
const ENC_VERIFIER_VALUE_BLOCK = [0xd7, 0xaa, 0x0f, 0x6d, 0x30, 0x61, 0x34, 0x4e];
Expand Down
37 changes: 18 additions & 19 deletions src/codec-handler/handlers/office/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createIdentityHandler } from "../identity.js";
import { createAgileCodecHandler } from "./agile/index.js";
import { EncryptionHeaderFlags, isFlagSet } from "./EncryptionHeader.js";
import { createRC4CryptoAPICodecHandler } from "./rc4-cryptoapi.js";
import { CodecHandler } from "../../types.js";
import type { CodecHandler } from "../../types.js";

const MAX_PASSWORD_LENGTH = 255;
const CRYPT_STRUCTURE_OFFSET = 0x299;
Expand Down Expand Up @@ -41,27 +41,26 @@ export function createOfficeCodecHandler(databaseDefinitionPage: Buffer, passwor

case "4.2":
case "3.2":
case "2.2":
{
const flags = encryptionProviderBuffer.readInt32LE(4);
if (isFlagSet(flags, EncryptionHeaderFlags.FCRYPTO_API_FLAG)) {
if (isFlagSet(flags, EncryptionHeaderFlags.FAES_FLAG)) {
// Standard Encryption
throw new Error("Not implemented yet");
} else {
try {
// RC4 CryptoAPI Encryption
return createRC4CryptoAPICodecHandler(encodingKey, encryptionProviderBuffer, passwordBuffer);
} catch (e) {
// Non Standard Encryption
}

throw new Error("Not implemented yet");
}
case "2.2": {
const flags = encryptionProviderBuffer.readInt32LE(4);
if (isFlagSet(flags, EncryptionHeaderFlags.FCRYPTO_API_FLAG)) {
if (isFlagSet(flags, EncryptionHeaderFlags.FAES_FLAG)) {
// Standard Encryption
throw new Error("Not implemented yet");
} else {
throw new Error("Unknown encryption");
try {
// RC4 CryptoAPI Encryption
return createRC4CryptoAPICodecHandler(encodingKey, encryptionProviderBuffer, passwordBuffer);
} catch (e) {
// Non Standard Encryption
}

throw new Error("Not implemented yet");
}
} else {
throw new Error("Unknown encryption");
}
}

case "1.1":
// RC4 Encryption: 1.1
Expand Down
8 changes: 4 additions & 4 deletions src/codec-handler/handlers/office/rc4-cryptoapi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createRC4Decrypter, decryptRC4, hash } from "../../../crypto/index.js";
import { fixBufferLength, intToBuffer, roundToFullByte } from "../../../util.js";
import { CodecHandler, DecryptPage } from "../../types.js";
import type { CodecHandler, DecryptPage } from "../../types.js";
import { getPageEncodingKey } from "../../util.js";
import { CryptoAlgorithm, CRYPTO_ALGORITHMS } from "./CryptoAlgorithm.js";
import { EncryptionHeader, parseEncryptionHeader } from "./EncryptionHeader.js";
import { type CryptoAlgorithm, CRYPTO_ALGORITHMS } from "./CryptoAlgorithm.js";
import { type EncryptionHeader, parseEncryptionHeader } from "./EncryptionHeader.js";
import { parseEncryptionVerifier } from "./EncryptionVerifier.js";
import { HashAlgorithm, HASH_ALGORITHMS } from "./HashAlgorithm.js";
import { type HashAlgorithm, HASH_ALGORITHMS } from "./HashAlgorithm.js";

const VALID_CRYPTO_ALGORITHMS: CryptoAlgorithm[] = [CRYPTO_ALGORITHMS.RC4];
const VALID_HASH_ALGORITHMS: HashAlgorithm[] = [HASH_ALGORITHMS.SHA1];
Expand Down
2 changes: 1 addition & 1 deletion src/column.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColumnType, ColumnTypes } from "./types.js";
import { type ColumnType, ColumnTypes } from "./types.js";

export interface Column {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/blockDecrypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createDecipheriv } from "../environment/index.js";
import { Cipher } from "./types.js";
import type { Cipher } from "./types.js";

export function blockDecrypt(cipher: Cipher, key: Buffer, iv: Buffer, data: Buffer): Buffer {
const algorithm = `${cipher.algorithm}-${key.length * 8}-${cipher.chaining.slice(-3)}`;
Expand Down
4 changes: 2 additions & 2 deletions src/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Column, ColumnDefinition } from "../column.js";
import type { Column, ColumnDefinition } from "../column.js";
import { Database } from "../Database.js";
import { ColumnType, ColumnTypes, Value, ValueMap } from "../types.js";
import { type ColumnType, ColumnTypes, type Value, type ValueMap } from "../types.js";
import { readBigInt } from "./bigint.js";
import { readBinary } from "./binary.js";
import { readByte } from "./byte.js";
Expand Down
2 changes: 1 addition & 1 deletion src/data/memo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column } from "../index.js";
import type { Column } from "../index.js";
import { Database } from "../Database.js";
import { uncompressText } from "../unicodeCompression.js";

Expand Down
2 changes: 1 addition & 1 deletion src/data/numeric.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addArray, multiplyArray, toArray } from "../array.js";
import { Column } from "../column.js";
import type { Column } from "../column.js";
import { buildValue } from "./util.js";

const MAX_PRECISION = 40;
Expand Down
2 changes: 1 addition & 1 deletion src/data/ole.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column } from "../column.js";
import type { Column } from "../column.js";
import { Database } from "../Database.js";

/**
Expand Down
2 changes: 1 addition & 1 deletion src/data/text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column } from "../index.js";
import type { Column } from "../index.js";
import { Database } from "../Database.js";
import { uncompressText } from "../unicodeCompression.js";

Expand Down
2 changes: 1 addition & 1 deletion src/unicodeCompression.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JetFormat } from "./JetFormat/index.js";
import type { JetFormat } from "./JetFormat/index.js";
import { decodeWindows1252 } from "./dependencies/iconv-lite/index.js";

/**
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.browser.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"outDir": "lib/browser",
"module": "Node16",
"moduleResolution": "node16",
"declaration": false
"declaration": false,
"verbatimModuleSyntax": true
},
"files": ["src/index.ts", "typings/browserify-aes.d.ts", "typings/create-hash.d.ts"]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"module": "Node16",
"moduleResolution": "node16",
"declaration": true,
"declarationDir": "lib/types"
"declarationDir": "lib/types",
"verbatimModuleSyntax": true
},
"files": ["src/index.ts"]
}

0 comments on commit 38d32ed

Please sign in to comment.