expo-tiddlywiki-filesystem-android-external-storage 2.7.0 → 2.9.0

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.
@@ -568,6 +568,10 @@ class ExternalStorageModule : Module() {
568
568
  GitHelper.gitPush(gitRootDir, remoteName, localBranch, remoteBranch, force, headers)
569
569
  }
570
570
 
571
+ AsyncFunction("gitCreateBundle") { gitRootDir: String, remoteName: String, localBranch: String, remoteBranch: String ->
572
+ GitHelper.gitCreateBundle(gitRootDir, remoteName, localBranch, remoteBranch)
573
+ }
574
+
571
575
  AsyncFunction("gitFetch") { gitRootDir: String, remoteName: String, branch: String, headers: String? ->
572
576
  GitHelper.gitFetch(gitRootDir, remoteName, branch, headers)
573
577
  }
@@ -369,6 +369,80 @@ internal object GitHelper {
369
369
  return result.toString()
370
370
  }
371
371
 
372
+ // ─── Git bundle creation (for push via HTTP POST) ───────────────
373
+
374
+ /**
375
+ * Create a git bundle containing commits on localBranch that are ahead of
376
+ * remoteName/remoteBranch. Returns a base64-encoded bundle string, or
377
+ * a JSON error if there's nothing to bundle.
378
+ *
379
+ * This avoids JGit's broken SmartHttpPushConnection (which throws
380
+ * "Starting read stage without written request data pending is not supported"
381
+ * due to MultiRequestService not marking finalRequest=true for push).
382
+ *
383
+ * The bundle is sent by the JS layer via HTTP POST to the desktop's
384
+ * /receive-bundle endpoint, which runs `git fetch <bundle> master:mobile-incoming`.
385
+ */
386
+ fun gitCreateBundle(
387
+ gitRootDir: String,
388
+ remoteName: String,
389
+ localBranch: String,
390
+ remoteBranch: String
391
+ ): String {
392
+ val result = JSONObject()
393
+ try {
394
+ val repo = openRepo(gitRootDir)
395
+ try {
396
+ ensureProtocolV0(repo)
397
+ val localRef = repo.resolve("refs/heads/$localBranch")
398
+ ?: throw Exception("Local branch $localBranch not found")
399
+ val remoteRef = repo.resolve("refs/remotes/$remoteName/$remoteBranch")
400
+
401
+ val revWalk = RevWalk(repo)
402
+ try {
403
+ val localCommit = revWalk.parseCommit(localRef)
404
+
405
+ val bundleWriter = org.eclipse.jgit.transport.BundleWriter(repo)
406
+
407
+ // Include the local branch tip
408
+ bundleWriter.include("refs/heads/$localBranch", localRef)
409
+
410
+ // If we have a remote tracking ref, mark it as assumed (prerequisite).
411
+ // The receiving end must have this commit.
412
+ if (remoteRef != null) {
413
+ val remoteCommit = revWalk.parseCommit(remoteRef)
414
+ bundleWriter.assume(remoteCommit)
415
+ }
416
+
417
+ // Configure pack for low memory (Android)
418
+ val packConfig = org.eclipse.jgit.storage.pack.PackConfig(repo)
419
+ bundleWriter.setPackConfig(packConfig)
420
+
421
+ // Write bundle to memory
422
+ val baos = ByteArrayOutputStream()
423
+ bundleWriter.writeBundle(org.eclipse.jgit.lib.NullProgressMonitor.INSTANCE, baos)
424
+
425
+ val bundleBytes = baos.toByteArray()
426
+ val base64Bundle = Base64.encodeToString(bundleBytes, Base64.NO_WRAP)
427
+
428
+ result.put("ok", true)
429
+ result.put("bundle", base64Bundle)
430
+ result.put("bundleSize", bundleBytes.size)
431
+ android.util.Log.i("GitBundle", "Bundle created: ${bundleBytes.size} bytes, local=$localBranch remote=$remoteName/$remoteBranch")
432
+ } finally {
433
+ revWalk.close()
434
+ }
435
+ } finally {
436
+ repo.close()
437
+ }
438
+ } catch (e: Exception) {
439
+ result.put("ok", false)
440
+ result.put("error", e.message ?: "Unknown bundle error")
441
+ android.util.Log.e("GitBundle", "Bundle creation failed: ${e.message}", e)
442
+ }
443
+ return result.toString()
444
+ }
445
+
372
446
  // ─── Git fetch (JGit) ───────────────────────────────────────────
373
447
 
374
448
  /**
package/build/index.d.ts CHANGED
@@ -162,6 +162,18 @@ interface IExternalStorageModule {
162
162
  * @returns JSON string: `{"ok":true,"updates":[...]}` or `{"ok":false,"error":"..."}`
163
163
  */
164
164
  gitPush(gitRootDir: string, remoteName: string, localBranch: string, remoteBranch: string, force: boolean, headers?: string | null): Promise<string>;
165
+ /**
166
+ * Create a git bundle containing unpushed commits (local branch tip minus remote tracking branch).
167
+ * Returns base64-encoded bundle data that can be HTTP-POSTed to the desktop for unbundling.
168
+ * This avoids JGit's broken HTTP push (SmartHttpPushConnection) entirely.
169
+ *
170
+ * @param gitRootDir Absolute path to the git working directory
171
+ * @param remoteName Remote name (e.g. "origin")
172
+ * @param localBranch Local branch name (e.g. "master")
173
+ * @param remoteBranch Remote branch name (e.g. "master")
174
+ * @returns JSON string: `{"ok":true,"bundleBase64":"..."}` or `{"ok":false,"error":"..."}`
175
+ */
176
+ gitCreateBundle(gitRootDir: string, remoteName: string, localBranch: string, remoteBranch: string): Promise<string>;
165
177
  /**
166
178
  * Fetch from remote using native JGit (efficient pack handling).
167
179
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8BA,UAAU,QAAQ;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,UAAU,gBAAgB;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,oBAAoB;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,2BAA2B;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,mBAAmB;IAC3B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,sBAAsB;IAC9B,MAAM,CAAC,IAAI,EAAE,MAAM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GAIG;AACH,SAAS,eAAe;IACtB,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;IACD,iEAAiE;IACjE,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAsE,CAAC;IAClI,OAAO,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IACjD,OAAO,OAAO,CAAC;AACjB,CAAC;AAyVD,MAAM,CAAC,MAAM,eAAe,GAA2B,IAAI,KAAK,CAAC,EAA4B,EAAE;IAC7F,GAAG,CAAC,OAAO,EAAE,QAAQ;QACnB,MAAM,GAAG,GAAG,eAAe,EAAE,CAAC;QAC9B,OAAQ,GAAmD,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC;CACF,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB;IAC3C,IAAI,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * TypeScript bindings for the ExternalStorage native module.\n *\n * This module uses raw java.io.File on Android to bypass Expo FileSystem's\n * directory whitelist. It allows reading/writing to shared external storage\n * when MANAGE_EXTERNAL_STORAGE permission is granted.\n *\n * All path arguments are plain filesystem paths (e.g. \"/storage/emulated/0/Documents/TidGi/\").\n * Do NOT pass file:// URIs — strip the scheme before calling.\n */\nimport { Platform } from 'react-native';\n\nlet _module: IExternalStorageModule | undefined;\n\n/**\n * Lazily load the native module. Wrapped in a function so that the app does NOT\n * crash at import time if the native module is missing (e.g. on iOS or when the\n * binary was built without it).\n */\nfunction getNativeModule(): IExternalStorageModule {\n if (_module) return _module;\n if (Platform.OS !== 'android' && Platform.OS !== 'ios') {\n throw new Error('ExternalStorage native module is only available on Android and iOS');\n }\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const { requireNativeModule } = require('expo-modules-core') as { requireNativeModule: (name: string) => IExternalStorageModule };\n _module = requireNativeModule('ExternalStorage');\n return _module;\n}\n\ninterface FileInfo {\n exists: boolean;\n isDirectory: boolean;\n size: number;\n /** Milliseconds since epoch */\n modificationTime: number;\n}\n\ninterface BatchWriteResult {\n writtenCount: number;\n}\n\ninterface HttpPostToFileResult {\n statusCode: number;\n headers: Record<string, string>;\n bytesWritten: number;\n}\n\ninterface DownloadFileResumableResult {\n statusCode: number;\n /** Final size of the file on disk after download */\n totalBytes: number;\n /** true if the download resumed from a partial file (HTTP 206) */\n resumed: boolean;\n}\n\ninterface ExtractTarResult {\n filesExtracted: number;\n}\n\ninterface ReadFileChunkResult {\n /** Base64-encoded chunk data */\n data: string;\n bytesRead: number;\n}\n\ninterface IExternalStorageModule {\n exists(path: string): Promise<boolean>;\n getInfo(path: string): Promise<FileInfo>;\n\n mkdir(path: string): Promise<void>;\n readDir(path: string): Promise<string[]>;\n /** Recursively list all files under a directory, returning relative paths. Skips .git etc. */\n readDirRecursive(path: string): Promise<string[]>;\n rmdir(path: string): Promise<void>;\n\n readFileUtf8(path: string): Promise<string>;\n readFileBase64(path: string): Promise<string>;\n writeFileUtf8(path: string, content: string): Promise<void>;\n writeFileBase64(path: string, base64Content: string): Promise<void>;\n /**\n * Append a Base64-encoded chunk to a file, optionally truncating first.\n *\n * Designed for streaming large writes from JS in bounded-memory chunks\n * (e.g. 512 KB each) so the JVM never allocates the full file content,\n * avoiding OOM on 50+ MB git pack files.\n *\n * @param truncateFirst Pass `true` for the first chunk to create/truncate\n * the file, then `false` for subsequent chunks.\n */\n appendFileBase64(path: string, base64Content: string, truncateFirst: boolean): Promise<void>;\n writeFilesBase64(paths: string[], base64Contents: string[]): Promise<BatchWriteResult>;\n deleteFile(path: string): Promise<void>;\n\n isExternalStorageWritable(): Promise<boolean>;\n getExternalStorageDirectory(): Promise<string>;\n /** Android 11+ (API 30): check if MANAGE_EXTERNAL_STORAGE is granted. Pre-30 returns true. */\n isExternalStorageManager(): Promise<boolean>;\n\n /**\n * HTTP POST with the response body streamed directly to a file on disk,\n * **never buffering the full response in JVM/Hermes heap**.\n *\n * Designed for git-upload-pack which can return 100+ MB packfiles.\n *\n * @param url Target URL\n * @param headers HTTP headers as `{ key: value }`\n * @param bodyBase64 Request body encoded as Base64 (binary git protocol data)\n * @param destPath Plain filesystem path to write the response body to\n * @param contentType MIME type for the request body\n */\n httpPostToFile(\n url: string,\n headers: Record<string, string>,\n bodyBase64: string,\n destPath: string,\n contentType: string,\n ): Promise<HttpPostToFileResult>;\n\n /**\n * Read a chunk of a file starting at `offset` for up to `length` bytes.\n * Returns Base64-encoded data and actual bytes read.\n *\n * Use this to stream a large file into JS in bounded-memory chunks.\n */\n readFileChunk(path: string, offset: number, length: number): Promise<ReadFileChunkResult>;\n\n /**\n * Download a file via HTTP GET with resumable download support.\n *\n * If `destPath` already exists on disk (from a previous interrupted download),\n * sends `Range: bytes=<existingSize>-` to resume. The server must respond\n * with 206 Partial Content for resume to work; otherwise the file is\n * overwritten from scratch (200 response).\n *\n * @param url Target URL\n * @param headers Extra HTTP headers (e.g. Authorization, ETag)\n * @param destPath Plain filesystem path for the downloaded file\n */\n downloadFileResumable(\n url: string,\n headers: Record<string, string>,\n destPath: string,\n ): Promise<DownloadFileResumableResult>;\n\n /**\n * Extract an uncompressed tar archive to a destination directory.\n * Uses a native tar parser — no third-party dependency.\n * Supports POSIX ustar and GNU long-name extensions.\n * Validates paths to prevent directory traversal attacks.\n *\n * @param tarPath Path to the .tar file\n * @param destDir Destination directory (created if needed)\n */\n extractTar(tarPath: string, destDir: string): Promise<ExtractTarResult>;\n\n /**\n * Parse a batch of TiddlyWiki tiddler files entirely in native Kotlin.\n *\n * This is the critical performance optimization for initial wiki loading:\n * a single bridge call processes 100+ files in parallel, returning a\n * ready-to-inject JSON array string. Eliminates per-file bridge round-trips.\n *\n * Supports .tid, .json, and .meta files. Applies skinny logic:\n * - System tiddlers ($:/) → always full text\n * - Plugins (application/json + plugin-type) → always full text\n * - Module tiddlers (module-type) → always full text\n * - Small tiddlers (< 10KB body) → full text\n * - Large user tiddlers → skinny (_is_skinny: \"yes\", text omitted)\n *\n * @param filePaths Array of absolute filesystem paths\n * @param quickLoadMode If true, all tiddlers returned as skinny\n * @returns JSON string: serialized array of tiddler field objects\n */\n batchParseTidFiles(filePaths: string[], quickLoadMode: boolean): Promise<string>;\n\n /**\n * Lightweight native git status using direct git-index parsing.\n *\n * Parses `.git/index` to get tracked files and their stat-cache entries,\n * then compares against the working directory using file size and mtime.\n * Orders of magnitude faster than isomorphic-git's `statusMatrix` because:\n * - No JS↔Native bridge round-trips per file\n * - Uses stat-cache (size+mtime) instead of SHA-1 re-hashing\n * - Parallel file walking in Java\n *\n * @param gitRootDir The root directory of the git repository (parent of .git/)\n * @returns JSON string: `[{\"path\":\"tiddlers/foo.tid\",\"type\":\"add\"|\"modify\"|\"delete\"}, ...]`\n */\n gitStatus(gitRootDir: string): Promise<string>;\n\n /**\n * Debug function returning diagnostic info about the git repository state.\n * @returns JSON string with root/gitDir/index existence and git dir children\n */\n gitStatusDebug(gitRootDir: string): Promise<string>;\n\n /**\n * Build `.git/index` natively by reading the HEAD tree from pack files,\n * stat'ing all files on disk, and writing a v2 index file.\n *\n * This is used after archive clone where TidGi Desktop's tar export\n * doesn't include `.git/index`.\n *\n * @param gitRootDir The root directory of the git repository (parent of .git/)\n * @returns JSON string: `{\"ok\":true,\"entries\":N,\"indexSize\":M}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n buildGitIndex(gitRootDir: string): Promise<string>;\n\n /**\n * Push local branch to remote using native JGit (efficient pack building).\n * Avoids OOM from isomorphic-git's JS-based pack construction on large repos.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param remoteName Remote name (e.g. \"origin\")\n * @param localBranch Local branch name (e.g. \"main\")\n * @param remoteBranch Remote branch ref (e.g. \"refs/heads/mobile-incoming\")\n * @param force Whether to force push\n * @param headers Optional HTTP headers as JSON string\n * @returns JSON string: `{\"ok\":true,\"updates\":[...]}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitPush(gitRootDir: string, remoteName: string, localBranch: string, remoteBranch: string, force: boolean, headers?: string | null): Promise<string>;\n\n /**\n * Fetch from remote using native JGit (efficient pack handling).\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param remoteName Remote name (e.g. \"origin\")\n * @param branch Branch to fetch\n * @param headers Optional HTTP headers as JSON string\n * @returns JSON string: `{\"ok\":true,\"updates\":[...]}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitFetch(gitRootDir: string, remoteName: string, branch: string, headers?: string | null): Promise<string>;\n\n /**\n * Compare two commits and checkout only changed/new files to the working tree.\n * Avoids full checkout which OOMs on large repos.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param oldOid Old commit SHA (before fetch)\n * @param newOid New commit SHA (after fetch)\n * @returns JSON string: `{\"ok\":true,\"count\":N,\"files\":[...]}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitCheckoutChangedFiles(gitRootDir: string, oldOid: string, newOid: string): Promise<string>;\n\n /**\n * Stage all changes and commit using native git (JGit on Android).\n * Replaces isomorphic-git's statusMatrix + add/remove loop which OOMs on large repos.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param message Commit message\n * @param authorName Author name\n * @param authorEmail Author email\n * @returns JSON string: `{\"ok\":true,\"commitId\":\"abc123\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitAddAndCommit(gitRootDir: string, message: string, authorName: string, authorEmail: string): Promise<string>;\n\n /**\n * Reset the current branch to a specific ref using native git (JGit on Android).\n * Supports hard, mixed, and soft reset modes.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param ref Target ref (e.g. \"origin/main\", commit SHA)\n * @param mode Reset mode: \"hard\", \"mixed\", or \"soft\"\n * @returns JSON string: `{\"ok\":true,\"ref\":\"abc123\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitReset(gitRootDir: string, ref: string, mode: string): Promise<string>;\n\n /**\n * Clone a remote repository using native JGit.\n *\n * @param url Remote repository URL\n * @param directory Destination directory\n * @param branch Branch to clone (null for default)\n * @param depth Depth for shallow clone (0 for full)\n * @param singleBranch Whether to clone only the specified branch\n * @param noTags Whether to skip fetching tags\n * @param headers Optional HTTP headers as JSON string\n * @returns JSON string: `{\"ok\":true,\"head\":\"abc123\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitClone(url: string, directory: string, branch: string | null, depth: number, singleBranch: boolean, noTags: boolean, headers?: string | null): Promise<string>;\n\n /**\n * Get commit history using native git log.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param ref Branch or ref to start from (null for all)\n * @param maxCount Maximum number of commits to return\n * @returns JSON string: `{\"ok\":true,\"commits\":[{\"oid\",\"message\",\"authorName\",\"authorEmail\",\"timestamp\",\"parentOids\"}]}`\n */\n gitLog(gitRootDir: string, ref: string | null, maxCount: number): Promise<string>;\n\n /**\n * Resolve a git reference to its SHA-1 hash.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param ref Reference to resolve (e.g. \"HEAD\", \"refs/heads/main\", \"origin/main\")\n * @returns JSON string: `{\"ok\":true,\"oid\":\"abc123\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitResolveRef(gitRootDir: string, ref: string): Promise<string>;\n\n /**\n * Get current branch name and branch listings.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @returns JSON string: `{\"ok\":true,\"branch\":\"main\",\"isDetached\":false,\"localBranches\":[],\"remoteBranches\":[]}`\n */\n gitCurrentBranch(gitRootDir: string): Promise<string>;\n\n /**\n * Initialize a new git repository.\n *\n * @param directory Directory to initialize\n * @param defaultBranch Default branch name (e.g. \"main\")\n * @returns JSON string: `{\"ok\":true}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitInit(directory: string, defaultBranch: string): Promise<string>;\n\n /**\n * Set a git config value.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param section Config section (e.g. \"remote\")\n * @param subsection Config subsection (e.g. \"origin\"), null for no subsection\n * @param name Config key (e.g. \"url\")\n * @param value Config value\n * @returns JSON string: `{\"ok\":true}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitSetConfig(gitRootDir: string, section: string, subsection: string | null, name: string, value: string): Promise<string>;\n\n /**\n * Add a remote to the repository.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param remoteName Remote name (e.g. \"origin\")\n * @param url Remote URL\n * @returns JSON string: `{\"ok\":true}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitAddRemote(gitRootDir: string, remoteName: string, url: string): Promise<string>;\n\n /**\n * Read a file (blob) at a specific commit reference.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param ref Commit ref to read from\n * @param filepath Relative path within the repository\n * @param asBase64 If true, return content as base64; otherwise as utf8 string\n * @returns JSON string: `{\"ok\":true,\"content\":\"...\",\"encoding\":\"base64\"|\"utf8\",\"size\":N}`\n */\n gitReadBlob(gitRootDir: string, ref: string, filepath: string, asBase64: boolean): Promise<string>;\n\n /**\n * Diff two commits and return changed files list.\n * Native equivalent of tree-walking diff.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param oldRef Old commit ref\n * @param newRef New commit ref\n * @returns JSON string: `{\"ok\":true,\"files\":[{\"path\":\"...\",\"type\":\"add\"|\"modify\"|\"delete\"}]}`\n */\n gitDiffTrees(gitRootDir: string, oldRef: string, newRef: string): Promise<string>;\n\n /**\n * Discard uncommitted changes for a specific file.\n * Checks out the HEAD version, or deletes the file if it's untracked.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param filepath Relative path of the file to discard\n * @returns JSON string: `{\"ok\":true,\"action\":\"checkout\"|\"delete\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitDiscardFileChanges(gitRootDir: string, filepath: string): Promise<string>;\n}\n\nexport const ExternalStorage: IExternalStorageModule = new Proxy({} as IExternalStorageModule, {\n get(_target, property) {\n const mod = getNativeModule();\n return (mod as unknown as Record<string | symbol, unknown>)[property];\n },\n});\n\n/**\n * Strip file:// prefix from a URI to produce a plain filesystem path.\n * Safe to call on paths that are already plain.\n */\nexport function toPlainPath(uriOrPath: string): string {\n if (uriOrPath.startsWith('file://')) {\n return uriOrPath.slice('file://'.length);\n }\n return uriOrPath;\n}\n\nexport type { BatchWriteResult, DownloadFileResumableResult, ExtractTarResult, FileInfo, HttpPostToFileResult, IExternalStorageModule, ReadFileChunkResult };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,IAAI,OAA2C,CAAC;AAEhD;;;;GAIG;AACH,SAAS,eAAe;IACtB,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;IACD,iEAAiE;IACjE,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAsE,CAAC;IAClI,OAAO,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IACjD,OAAO,OAAO,CAAC;AACjB,CAAC;AAsWD,MAAM,CAAC,MAAM,eAAe,GAA2B,IAAI,KAAK,CAAC,EAA4B,EAAE;IAC7F,GAAG,CAAC,OAAO,EAAE,QAAQ;QACnB,MAAM,GAAG,GAAG,eAAe,EAAE,CAAC;QAC9B,OAAQ,GAAmD,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC;CACF,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB;IAC3C,IAAI,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * TypeScript bindings for the ExternalStorage native module.\n *\n * This module uses raw java.io.File on Android to bypass Expo FileSystem's\n * directory whitelist. It allows reading/writing to shared external storage\n * when MANAGE_EXTERNAL_STORAGE permission is granted.\n *\n * All path arguments are plain filesystem paths (e.g. \"/storage/emulated/0/Documents/TidGi/\").\n * Do NOT pass file:// URIs — strip the scheme before calling.\n */\nimport { Platform } from 'react-native';\n\nlet _module: IExternalStorageModule | undefined;\n\n/**\n * Lazily load the native module. Wrapped in a function so that the app does NOT\n * crash at import time if the native module is missing (e.g. on iOS or when the\n * binary was built without it).\n */\nfunction getNativeModule(): IExternalStorageModule {\n if (_module) return _module;\n if (Platform.OS !== 'android' && Platform.OS !== 'ios') {\n throw new Error('ExternalStorage native module is only available on Android and iOS');\n }\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const { requireNativeModule } = require('expo-modules-core') as { requireNativeModule: (name: string) => IExternalStorageModule };\n _module = requireNativeModule('ExternalStorage');\n return _module;\n}\n\ninterface FileInfo {\n exists: boolean;\n isDirectory: boolean;\n size: number;\n /** Milliseconds since epoch */\n modificationTime: number;\n}\n\ninterface BatchWriteResult {\n writtenCount: number;\n}\n\ninterface HttpPostToFileResult {\n statusCode: number;\n headers: Record<string, string>;\n bytesWritten: number;\n}\n\ninterface DownloadFileResumableResult {\n statusCode: number;\n /** Final size of the file on disk after download */\n totalBytes: number;\n /** true if the download resumed from a partial file (HTTP 206) */\n resumed: boolean;\n}\n\ninterface ExtractTarResult {\n filesExtracted: number;\n}\n\ninterface ReadFileChunkResult {\n /** Base64-encoded chunk data */\n data: string;\n bytesRead: number;\n}\n\ninterface IExternalStorageModule {\n exists(path: string): Promise<boolean>;\n getInfo(path: string): Promise<FileInfo>;\n\n mkdir(path: string): Promise<void>;\n readDir(path: string): Promise<string[]>;\n /** Recursively list all files under a directory, returning relative paths. Skips .git etc. */\n readDirRecursive(path: string): Promise<string[]>;\n rmdir(path: string): Promise<void>;\n\n readFileUtf8(path: string): Promise<string>;\n readFileBase64(path: string): Promise<string>;\n writeFileUtf8(path: string, content: string): Promise<void>;\n writeFileBase64(path: string, base64Content: string): Promise<void>;\n /**\n * Append a Base64-encoded chunk to a file, optionally truncating first.\n *\n * Designed for streaming large writes from JS in bounded-memory chunks\n * (e.g. 512 KB each) so the JVM never allocates the full file content,\n * avoiding OOM on 50+ MB git pack files.\n *\n * @param truncateFirst Pass `true` for the first chunk to create/truncate\n * the file, then `false` for subsequent chunks.\n */\n appendFileBase64(path: string, base64Content: string, truncateFirst: boolean): Promise<void>;\n writeFilesBase64(paths: string[], base64Contents: string[]): Promise<BatchWriteResult>;\n deleteFile(path: string): Promise<void>;\n\n isExternalStorageWritable(): Promise<boolean>;\n getExternalStorageDirectory(): Promise<string>;\n /** Android 11+ (API 30): check if MANAGE_EXTERNAL_STORAGE is granted. Pre-30 returns true. */\n isExternalStorageManager(): Promise<boolean>;\n\n /**\n * HTTP POST with the response body streamed directly to a file on disk,\n * **never buffering the full response in JVM/Hermes heap**.\n *\n * Designed for git-upload-pack which can return 100+ MB packfiles.\n *\n * @param url Target URL\n * @param headers HTTP headers as `{ key: value }`\n * @param bodyBase64 Request body encoded as Base64 (binary git protocol data)\n * @param destPath Plain filesystem path to write the response body to\n * @param contentType MIME type for the request body\n */\n httpPostToFile(\n url: string,\n headers: Record<string, string>,\n bodyBase64: string,\n destPath: string,\n contentType: string,\n ): Promise<HttpPostToFileResult>;\n\n /**\n * Read a chunk of a file starting at `offset` for up to `length` bytes.\n * Returns Base64-encoded data and actual bytes read.\n *\n * Use this to stream a large file into JS in bounded-memory chunks.\n */\n readFileChunk(path: string, offset: number, length: number): Promise<ReadFileChunkResult>;\n\n /**\n * Download a file via HTTP GET with resumable download support.\n *\n * If `destPath` already exists on disk (from a previous interrupted download),\n * sends `Range: bytes=<existingSize>-` to resume. The server must respond\n * with 206 Partial Content for resume to work; otherwise the file is\n * overwritten from scratch (200 response).\n *\n * @param url Target URL\n * @param headers Extra HTTP headers (e.g. Authorization, ETag)\n * @param destPath Plain filesystem path for the downloaded file\n */\n downloadFileResumable(\n url: string,\n headers: Record<string, string>,\n destPath: string,\n ): Promise<DownloadFileResumableResult>;\n\n /**\n * Extract an uncompressed tar archive to a destination directory.\n * Uses a native tar parser — no third-party dependency.\n * Supports POSIX ustar and GNU long-name extensions.\n * Validates paths to prevent directory traversal attacks.\n *\n * @param tarPath Path to the .tar file\n * @param destDir Destination directory (created if needed)\n */\n extractTar(tarPath: string, destDir: string): Promise<ExtractTarResult>;\n\n /**\n * Parse a batch of TiddlyWiki tiddler files entirely in native Kotlin.\n *\n * This is the critical performance optimization for initial wiki loading:\n * a single bridge call processes 100+ files in parallel, returning a\n * ready-to-inject JSON array string. Eliminates per-file bridge round-trips.\n *\n * Supports .tid, .json, and .meta files. Applies skinny logic:\n * - System tiddlers ($:/) → always full text\n * - Plugins (application/json + plugin-type) → always full text\n * - Module tiddlers (module-type) → always full text\n * - Small tiddlers (< 10KB body) → full text\n * - Large user tiddlers → skinny (_is_skinny: \"yes\", text omitted)\n *\n * @param filePaths Array of absolute filesystem paths\n * @param quickLoadMode If true, all tiddlers returned as skinny\n * @returns JSON string: serialized array of tiddler field objects\n */\n batchParseTidFiles(filePaths: string[], quickLoadMode: boolean): Promise<string>;\n\n /**\n * Lightweight native git status using direct git-index parsing.\n *\n * Parses `.git/index` to get tracked files and their stat-cache entries,\n * then compares against the working directory using file size and mtime.\n * Orders of magnitude faster than isomorphic-git's `statusMatrix` because:\n * - No JS↔Native bridge round-trips per file\n * - Uses stat-cache (size+mtime) instead of SHA-1 re-hashing\n * - Parallel file walking in Java\n *\n * @param gitRootDir The root directory of the git repository (parent of .git/)\n * @returns JSON string: `[{\"path\":\"tiddlers/foo.tid\",\"type\":\"add\"|\"modify\"|\"delete\"}, ...]`\n */\n gitStatus(gitRootDir: string): Promise<string>;\n\n /**\n * Debug function returning diagnostic info about the git repository state.\n * @returns JSON string with root/gitDir/index existence and git dir children\n */\n gitStatusDebug(gitRootDir: string): Promise<string>;\n\n /**\n * Build `.git/index` natively by reading the HEAD tree from pack files,\n * stat'ing all files on disk, and writing a v2 index file.\n *\n * This is used after archive clone where TidGi Desktop's tar export\n * doesn't include `.git/index`.\n *\n * @param gitRootDir The root directory of the git repository (parent of .git/)\n * @returns JSON string: `{\"ok\":true,\"entries\":N,\"indexSize\":M}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n buildGitIndex(gitRootDir: string): Promise<string>;\n\n /**\n * Push local branch to remote using native JGit (efficient pack building).\n * Avoids OOM from isomorphic-git's JS-based pack construction on large repos.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param remoteName Remote name (e.g. \"origin\")\n * @param localBranch Local branch name (e.g. \"main\")\n * @param remoteBranch Remote branch ref (e.g. \"refs/heads/mobile-incoming\")\n * @param force Whether to force push\n * @param headers Optional HTTP headers as JSON string\n * @returns JSON string: `{\"ok\":true,\"updates\":[...]}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitPush(gitRootDir: string, remoteName: string, localBranch: string, remoteBranch: string, force: boolean, headers?: string | null): Promise<string>;\n\n /**\n * Create a git bundle containing unpushed commits (local branch tip minus remote tracking branch).\n * Returns base64-encoded bundle data that can be HTTP-POSTed to the desktop for unbundling.\n * This avoids JGit's broken HTTP push (SmartHttpPushConnection) entirely.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param remoteName Remote name (e.g. \"origin\")\n * @param localBranch Local branch name (e.g. \"master\")\n * @param remoteBranch Remote branch name (e.g. \"master\")\n * @returns JSON string: `{\"ok\":true,\"bundleBase64\":\"...\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitCreateBundle(gitRootDir: string, remoteName: string, localBranch: string, remoteBranch: string): Promise<string>;\n\n /**\n * Fetch from remote using native JGit (efficient pack handling).\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param remoteName Remote name (e.g. \"origin\")\n * @param branch Branch to fetch\n * @param headers Optional HTTP headers as JSON string\n * @returns JSON string: `{\"ok\":true,\"updates\":[...]}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitFetch(gitRootDir: string, remoteName: string, branch: string, headers?: string | null): Promise<string>;\n\n /**\n * Compare two commits and checkout only changed/new files to the working tree.\n * Avoids full checkout which OOMs on large repos.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param oldOid Old commit SHA (before fetch)\n * @param newOid New commit SHA (after fetch)\n * @returns JSON string: `{\"ok\":true,\"count\":N,\"files\":[...]}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitCheckoutChangedFiles(gitRootDir: string, oldOid: string, newOid: string): Promise<string>;\n\n /**\n * Stage all changes and commit using native git (JGit on Android).\n * Replaces isomorphic-git's statusMatrix + add/remove loop which OOMs on large repos.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param message Commit message\n * @param authorName Author name\n * @param authorEmail Author email\n * @returns JSON string: `{\"ok\":true,\"commitId\":\"abc123\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitAddAndCommit(gitRootDir: string, message: string, authorName: string, authorEmail: string): Promise<string>;\n\n /**\n * Reset the current branch to a specific ref using native git (JGit on Android).\n * Supports hard, mixed, and soft reset modes.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param ref Target ref (e.g. \"origin/main\", commit SHA)\n * @param mode Reset mode: \"hard\", \"mixed\", or \"soft\"\n * @returns JSON string: `{\"ok\":true,\"ref\":\"abc123\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitReset(gitRootDir: string, ref: string, mode: string): Promise<string>;\n\n /**\n * Clone a remote repository using native JGit.\n *\n * @param url Remote repository URL\n * @param directory Destination directory\n * @param branch Branch to clone (null for default)\n * @param depth Depth for shallow clone (0 for full)\n * @param singleBranch Whether to clone only the specified branch\n * @param noTags Whether to skip fetching tags\n * @param headers Optional HTTP headers as JSON string\n * @returns JSON string: `{\"ok\":true,\"head\":\"abc123\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitClone(url: string, directory: string, branch: string | null, depth: number, singleBranch: boolean, noTags: boolean, headers?: string | null): Promise<string>;\n\n /**\n * Get commit history using native git log.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param ref Branch or ref to start from (null for all)\n * @param maxCount Maximum number of commits to return\n * @returns JSON string: `{\"ok\":true,\"commits\":[{\"oid\",\"message\",\"authorName\",\"authorEmail\",\"timestamp\",\"parentOids\"}]}`\n */\n gitLog(gitRootDir: string, ref: string | null, maxCount: number): Promise<string>;\n\n /**\n * Resolve a git reference to its SHA-1 hash.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param ref Reference to resolve (e.g. \"HEAD\", \"refs/heads/main\", \"origin/main\")\n * @returns JSON string: `{\"ok\":true,\"oid\":\"abc123\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitResolveRef(gitRootDir: string, ref: string): Promise<string>;\n\n /**\n * Get current branch name and branch listings.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @returns JSON string: `{\"ok\":true,\"branch\":\"main\",\"isDetached\":false,\"localBranches\":[],\"remoteBranches\":[]}`\n */\n gitCurrentBranch(gitRootDir: string): Promise<string>;\n\n /**\n * Initialize a new git repository.\n *\n * @param directory Directory to initialize\n * @param defaultBranch Default branch name (e.g. \"main\")\n * @returns JSON string: `{\"ok\":true}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitInit(directory: string, defaultBranch: string): Promise<string>;\n\n /**\n * Set a git config value.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param section Config section (e.g. \"remote\")\n * @param subsection Config subsection (e.g. \"origin\"), null for no subsection\n * @param name Config key (e.g. \"url\")\n * @param value Config value\n * @returns JSON string: `{\"ok\":true}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitSetConfig(gitRootDir: string, section: string, subsection: string | null, name: string, value: string): Promise<string>;\n\n /**\n * Add a remote to the repository.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param remoteName Remote name (e.g. \"origin\")\n * @param url Remote URL\n * @returns JSON string: `{\"ok\":true}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitAddRemote(gitRootDir: string, remoteName: string, url: string): Promise<string>;\n\n /**\n * Read a file (blob) at a specific commit reference.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param ref Commit ref to read from\n * @param filepath Relative path within the repository\n * @param asBase64 If true, return content as base64; otherwise as utf8 string\n * @returns JSON string: `{\"ok\":true,\"content\":\"...\",\"encoding\":\"base64\"|\"utf8\",\"size\":N}`\n */\n gitReadBlob(gitRootDir: string, ref: string, filepath: string, asBase64: boolean): Promise<string>;\n\n /**\n * Diff two commits and return changed files list.\n * Native equivalent of tree-walking diff.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param oldRef Old commit ref\n * @param newRef New commit ref\n * @returns JSON string: `{\"ok\":true,\"files\":[{\"path\":\"...\",\"type\":\"add\"|\"modify\"|\"delete\"}]}`\n */\n gitDiffTrees(gitRootDir: string, oldRef: string, newRef: string): Promise<string>;\n\n /**\n * Discard uncommitted changes for a specific file.\n * Checks out the HEAD version, or deletes the file if it's untracked.\n *\n * @param gitRootDir Absolute path to the git working directory\n * @param filepath Relative path of the file to discard\n * @returns JSON string: `{\"ok\":true,\"action\":\"checkout\"|\"delete\"}` or `{\"ok\":false,\"error\":\"...\"}`\n */\n gitDiscardFileChanges(gitRootDir: string, filepath: string): Promise<string>;\n}\n\nexport const ExternalStorage: IExternalStorageModule = new Proxy({} as IExternalStorageModule, {\n get(_target, property) {\n const mod = getNativeModule();\n return (mod as unknown as Record<string | symbol, unknown>)[property];\n },\n});\n\n/**\n * Strip file:// prefix from a URI to produce a plain filesystem path.\n * Safe to call on paths that are already plain.\n */\nexport function toPlainPath(uriOrPath: string): string {\n if (uriOrPath.startsWith('file://')) {\n return uriOrPath.slice('file://'.length);\n }\n return uriOrPath;\n}\n\nexport type { BatchWriteResult, DownloadFileResumableResult, ExtractTarResult, FileInfo, HttpPostToFileResult, IExternalStorageModule, ReadFileChunkResult };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-tiddlywiki-filesystem-android-external-storage",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "description": "Expo native module for TidGi-Mobile: filesystem I/O + TiddlyWiki .tid/.meta/.json batch parsing + git status in Kotlin (Android) and Swift (iOS)",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
package/src/index.ts CHANGED
@@ -221,6 +221,19 @@ interface IExternalStorageModule {
221
221
  */
222
222
  gitPush(gitRootDir: string, remoteName: string, localBranch: string, remoteBranch: string, force: boolean, headers?: string | null): Promise<string>;
223
223
 
224
+ /**
225
+ * Create a git bundle containing unpushed commits (local branch tip minus remote tracking branch).
226
+ * Returns base64-encoded bundle data that can be HTTP-POSTed to the desktop for unbundling.
227
+ * This avoids JGit's broken HTTP push (SmartHttpPushConnection) entirely.
228
+ *
229
+ * @param gitRootDir Absolute path to the git working directory
230
+ * @param remoteName Remote name (e.g. "origin")
231
+ * @param localBranch Local branch name (e.g. "master")
232
+ * @param remoteBranch Remote branch name (e.g. "master")
233
+ * @returns JSON string: `{"ok":true,"bundleBase64":"..."}` or `{"ok":false,"error":"..."}`
234
+ */
235
+ gitCreateBundle(gitRootDir: string, remoteName: string, localBranch: string, remoteBranch: string): Promise<string>;
236
+
224
237
  /**
225
238
  * Fetch from remote using native JGit (efficient pack handling).
226
239
  *