Added Type for the real useages of pdf Operations

This commit is contained in:
Saud Fatayerji 2023-11-13 03:50:02 +03:00
parent 4a832942f2
commit 77274e6117
4 changed files with 23 additions and 13 deletions

View File

@ -1,6 +1,6 @@
import { readBinaryFile, writeBinaryFile, removeDir, BaseDirectory } from '@tauri-apps/api/fs'; import { readBinaryFile, writeBinaryFile, removeDir, BaseDirectory } from '@tauri-apps/api/fs';
import { PdfFile, fromUint8Array } from '@stirling-pdf/shared-operations/wrappers/PdfFile' import { PdfFile, fromUint8Array } from '@stirling-pdf/shared-operations/src/wrappers/PdfFile'
import { runShell } from './tauri-wrapper'; import { runShell } from './tauri-wrapper';
export async function fileToPdf(byteArray: Uint8Array, filename: string): Promise<PdfFile> { export async function fileToPdf(byteArray: Uint8Array, filename: string): Promise<PdfFile> {

View File

@ -1,5 +1,5 @@
import SharedOperations from '@stirling-pdf/shared-operations' import SharedOperations, { OperationsUseages } from '@stirling-pdf/shared-operations/src'
// Import injected libraries here! // Import injected libraries here!
import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js"; import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js";
@ -8,7 +8,8 @@ async function impose(snapshot: any, nup: number, format: string) {
return SharedOperations.impose(snapshot, nup, format, pdfcpuWrapper) return SharedOperations.impose(snapshot, nup, format, pdfcpuWrapper)
} }
export default { const toExport: OperationsUseages = {
...SharedOperations, ...SharedOperations,
impose, impose,
} }
export default toExport;

View File

@ -1,14 +1,15 @@
import SharedOperations from "@stirling-pdf/shared-operations/src"; import SharedOperations, { OperationsUseages } from "@stirling-pdf/shared-operations/src";
// Import injected libraries here! // Import injected libraries here!
//import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-node.js"; //import * as pdfcpuWrapper from "@stirling-pdf/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-node.js";
/*async function impose(snapshot: any, nup: number, format: string) { async function impose(snapshot: any, nup: number, format: string) {
return SharedOperations.impose(snapshot, nup, format, pdfcpuWrapper); return SharedOperations.impose(snapshot, nup, format, null); // TODO change null to pdfcpuWrapper
}*/
export default {
...SharedOperations,
//impose,
} }
const toExport: OperationsUseages = {
...SharedOperations,
impose,
}
export default toExport;

View File

@ -11,7 +11,7 @@ import { splitOn } from './functions/splitOn';
import { splitPDF } from './functions/splitPDF'; import { splitPDF } from './functions/splitPDF';
import { updateMetadata } from "./functions/updateMetadata"; import { updateMetadata } from "./functions/updateMetadata";
export default { const toExport = {
sortPagesWithPreset, rearrangePages, selectPages, removePages, removeBlankPages, sortPagesWithPreset, rearrangePages, selectPages, removePages, removeBlankPages,
impose, impose,
mergePDFs, mergePDFs,
@ -21,4 +21,12 @@ export default {
splitOn, splitOn,
splitPDF, splitPDF,
updateMetadata, updateMetadata,
} }
export default toExport;
// Overide fields in the type of toExport, with the given fields and types. This seems to magically work!
// https://dev.to/vborodulin/ts-how-to-override-properties-with-type-intersection-554l
type Override<T1, T2> = Omit<T1, keyof T2> & T2;
export type OperationsUseages = Override<typeof toExport, {
impose: (snapshot: any, nup: number, format: string) => any;
}>;