From eadc58eeaa92b8e5699afa1fe921d6068fc161a4 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 12 Jul 2025 12:10:52 +0100 Subject: [PATCH] Re-declare public API's enums --- reconcile-js/package-lock.json | 2 +- reconcile-js/src/index.ts | 42 +++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/reconcile-js/package-lock.json b/reconcile-js/package-lock.json index ae081ce..f02abcf 100644 --- a/reconcile-js/package-lock.json +++ b/reconcile-js/package-lock.json @@ -24,7 +24,7 @@ }, "../pkg": { "name": "reconcile-text", - "version": "0.4.9", + "version": "0.4.10", "dev": true, "license": "MIT" }, diff --git a/reconcile-js/src/index.ts b/reconcile-js/src/index.ts index 1fcbb7b..f86aeac 100644 --- a/reconcile-js/src/index.ts +++ b/reconcile-js/src/index.ts @@ -3,17 +3,36 @@ import { reconcile as wasmReconcile, TextWithCursors as wasmTextWithCursors, SpanWithHistory as wasmSpanWithHistory, - BuiltinTokenizer, reconcileWithHistory as wasmReconcileWithHistory, isBinary as wasmIsBinary, - History, initSync, } from 'reconcile-text'; import wasmBytes from 'reconcile-text/reconcile_text_bg.wasm'; -// Re-export types from the WASM module as these are part of our API -export { History, BuiltinTokenizer }; +// Define the enum values as const arrays to avoid duplication +const BUILTIN_TOKENIZERS = ['Character', 'Line', 'Word'] as const; +const HISTORY_VALUES = [ + 'Unchanged', + 'AddedFromLeft', + 'AddedFromRight', + 'RemovedFromLeft', + 'RemovedFromRight', +] as const; + +/** + * Tokenisation strategies for text merging. + * + * These correspond to the built-in tokenizers available in the underlying WASM module. + */ +export type BuiltinTokenizer = (typeof BUILTIN_TOKENIZERS)[number]; + +/** + * History classification for text spans in merge results. + * + * Indicates the origin of each text span in the merged document. + */ +export type History = (typeof HISTORY_VALUES)[number]; /** * Represents a text document with associated cursor positions. @@ -84,16 +103,7 @@ export interface SpanWithHistory { history: History; } -/** - * Tokenisation strategies for text merging. - * - * - "Word": Splits text on word boundaries (recommended for prose and most text) - * - "Character": Splits text into individual characters (fine-grained control) - * - "Line": Splits text into lines (similar to git merge or diff3) - */ -const TOKENIZERS = ['Line', 'Word', 'Character']; - -const UNSUPPORTED_TOKENIZER_ERROR = `Unsupported tokenizer. Only ${TOKENIZERS.join( +const UNSUPPORTED_TOKENIZER_ERROR = `Unsupported tokenizer. Only ${BUILTIN_TOKENIZERS.join( ', ' )} are supported.`; @@ -131,7 +141,7 @@ export function reconcile( ): TextWithCursors { init(); - if (!TOKENIZERS.includes(tokenizer)) { + if (!BUILTIN_TOKENIZERS.includes(tokenizer)) { throw new Error(UNSUPPORTED_TOKENIZER_ERROR); } @@ -185,7 +195,7 @@ export function reconcileWithHistory( ): TextWithCursorsAndHistory { init(); - if (!TOKENIZERS.includes(tokenizer)) { + if (!BUILTIN_TOKENIZERS.includes(tokenizer)) { throw new Error(UNSUPPORTED_TOKENIZER_ERROR); }