@oniroproject/core 0.12.0 → 0.14.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.
- package/README.md +26 -13
- package/dist/index.cjs +1227 -311
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +483 -27
- package/dist/index.d.ts +483 -27
- package/dist/index.js +1187 -311
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -172,11 +172,14 @@ The injection-safe primitives every device operation builds on (`spawn` with `sh
|
|
|
172
172
|
| `listDevices` | `(config, opts?) => Promise<DeviceInfo[]>` | Parse `hdc list targets -v`. |
|
|
173
173
|
| `selectDevice` | `(config, serial?, opts?) => Promise<string>` | Resolve the target: explicit serial → `ONIRO_DEVICE_SERIAL`/`DEVICE_SERIAL` env → the single connected device (throws on ambiguity). |
|
|
174
174
|
| `parseDeviceList` | `(stdout) => DeviceInfo[]` | Pure parser (unit-testable). |
|
|
175
|
-
| `
|
|
175
|
+
| `resolveDeviceSerial` / `hdcTargetArgsFor` | `(explicit?) => string \| undefined` / `(args, explicit?) => string[]` | The serial (explicit → `ONIRO_DEVICE_SERIAL` → none) and the `-t` prefix `hdcExec` uses; hdc server commands only take an explicit one. |
|
|
176
|
+
| `hdcClientFailure` | `(output) => string \| null` | The `[Fail]…` line hdc printed while exiting 0; `hdcExec` reports it as exit code 1. |
|
|
177
|
+
| `paramGet` / `paramSet` | `(config, key[, value], opts?) => Promise<…>` | Read/write system properties via `param get`/`set`. `paramGet` throws for an unset property. |
|
|
178
|
+
| `paramGetMany` | `(config, keys, opts?) => Promise<Record<string, string \| undefined>>` | Read several properties in one round trip. |
|
|
176
179
|
|
|
177
180
|
### hdc — files
|
|
178
181
|
|
|
179
|
-
`sendFile(SendFileOptions)` / `recvFile(RecvFileOptions)` — push/pull a file via `hdc file send`/`recv`.
|
|
182
|
+
`sendFile(SendFileOptions)` / `recvFile(RecvFileOptions)` — push/pull a file via `hdc file send`/`recv`. Local paths are normalised for hdc (`normaliseLocalPath`); a device path a Windows shell rewrote is rejected (`assertDevicePath`). `sendFile` with `bundle` writes into that app's sandbox (`appSandboxDir`) and chowns the file to the app.
|
|
180
183
|
|
|
181
184
|
### hdc — lifecycle & waiting
|
|
182
185
|
|
|
@@ -191,7 +194,9 @@ The injection-safe primitives every device operation builds on (`spawn` with `sh
|
|
|
191
194
|
|
|
192
195
|
| Export | Signature | Description |
|
|
193
196
|
| --- | --- | --- |
|
|
194
|
-
| `installApp` | `(InstallAppOptions) => Promise<InstallAppResult>` | Install
|
|
197
|
+
| `installApp` | `(InstallAppOptions) => Promise<InstallAppResult>` | Install a `.hap` (`hapPath` / config / the signed entry HAP / the newest built one, unsigned as a last resort). Throws when the bundle manager rejects it, with the reason and the signing to do when it refuses an unsigned HAP (`unsignedHapRejection`). |
|
|
198
|
+
| `detectInstallFailure` / `ensureInstallOk` | — | Spot a bundle-manager rejection in `hdc install` output, which exits 0 either way. |
|
|
199
|
+
| `isBundleInstalled` | `(BundleOptions) => Promise<boolean>` | `bm dump -n` check. |
|
|
195
200
|
| `launchApp` | `(LaunchAppOptions) => Promise<void>` | `aa start` the entry ability (or an explicit `abilityName`). |
|
|
196
201
|
| `uninstallApp` / `forceStop` | `(BundleOptions) => Promise<void>` | Uninstall / force-stop by bundle name. |
|
|
197
202
|
| `findRunningProcess` | `(BundleOptions) => Promise<RunningProcess \| null>` | Non-throwing `pidof` check. |
|
|
@@ -206,17 +211,23 @@ The injection-safe primitives every device operation builds on (`spawn` with `sh
|
|
|
206
211
|
| `takeScreenshot` | `(ScreenshotOptions) => Promise<Screenshot>` | `{ pixels: Buffer, width, height }` — raw JPEG, no decode. |
|
|
207
212
|
| `captureBurst` | `(CaptureBurstOptions) => Promise<Buffer[]>` | N frames `intervalMs` apart, pulled back in order. |
|
|
208
213
|
| `getDisplaySize` | `(config, opts?) => Promise<DisplaySize \| null>` | Render resolution from `hidumper` (no image work). |
|
|
209
|
-
| `dumpLayout` | `(DumpLayoutOptions) => Promise<DumpLayoutResult>` | `uitest dumpLayout` → pruned, 0–1-normalized `LayoutNode` tree. |
|
|
210
|
-
| `parseBounds` / `pruneLayout` | — | Pure helpers behind `dumpLayout`. |
|
|
214
|
+
| `dumpLayout` | `(DumpLayoutOptions) => Promise<DumpLayoutResult>` | `uitest dumpLayout` → pruned, 0–1-normalized `LayoutNode` tree, with `hint`, `disabled`, and `covered` (painted over by a later filled layer). `detectKeyboard` adds `keyboard: KeyboardState`. |
|
|
215
|
+
| `parseBounds` / `pruneLayout` / `findCoveredNodes` | — | Pure helpers behind `dumpLayout`. |
|
|
216
|
+
| `flattenLayout` / `findLayoutNodes` / `pickTarget` | — | Pure: flatten a tree (nodes tagged with their `window`), match a `LayoutSelector` (`text` / `id` / `type`), and choose one uncovered, preferably clickable node (throws `TargetNotFoundError` with `reason` `none` / `covered` / `ambiguous`). |
|
|
217
|
+
| `getImeBundles` / `parseImeBundles` / `findKeyboardWindow` | — | Installed input methods (`hidumper -s 3703`) and the soft-keyboard window in a layout. |
|
|
211
218
|
|
|
212
219
|
### hdc — input injection
|
|
213
220
|
|
|
214
221
|
| Export | Signature | Description |
|
|
215
222
|
| --- | --- | --- |
|
|
216
|
-
| `sendInput` | `(SendInputOptions) => Promise<void>` | One `uitest uiInput` action in **pixel** space (`InputType`: click/doubleClick/longClick/swipe/drag/fling/keyEvent/inputText). |
|
|
223
|
+
| `sendInput` | `(SendInputOptions) => Promise<void>` | One `uitest uiInput` action in **pixel** space (`InputType`: click/doubleClick/longClick/swipe/drag/fling/keyEvent/inputText). `key` accepts names and combos (see `resolveKeyEvent`). |
|
|
224
|
+
| `performInput` | `(PerformInputOptions) => Promise<PerformInputResult>` | `sendInput` plus a start point from an element selector (`target`), 0–1 fractions, or pixels; `clearText`, `inputText` with `clear`, and keyboard-aware `hideKeyboard`. |
|
|
225
|
+
| `locateTarget` | `(LocateTargetOptions) => Promise<LocatedTarget>` | Resolve a selector against the live layout to one element and its pixel center, dismissing the keyboard if it hides the element. |
|
|
226
|
+
| `hideKeyboard` | `(opts) => Promise<boolean>` | Press Back only when the soft keyboard is shown. |
|
|
227
|
+
| `waitForTarget` | `(WaitForTargetOptions) => Promise<FlatLayoutNode \| null>` | Poll the layout until an uncovered element matches (or, with `gone`, until none does). |
|
|
217
228
|
| `sendGesture` | `(SendGestureOptions) => Promise<void>` | Multi-`Waypoint` path; routes through `uinput` when `holdStartMs`/`holdEndMs` need real press timing. |
|
|
218
229
|
| `sendRawTouch` | `(SendRawTouchOptions) => Promise<void>` | Low-level `uinput -T` down/move/up events. |
|
|
219
|
-
| `buildInputCommand` / `buildGestureCommands` / `buildRawTouchCommand` | — | Pure command builders (unit-testable). |
|
|
230
|
+
| `buildInputCommand` / `buildGestureCommands` / `buildRawTouchCommand` / `resolveKeyEvent` | — | Pure command builders (unit-testable). |
|
|
220
231
|
|
|
221
232
|
### hdc — logging (hilog)
|
|
222
233
|
|
|
@@ -225,6 +236,7 @@ The injection-safe primitives every device operation builds on (`spawn` with `sh
|
|
|
225
236
|
| `waitForLog` | `(WaitForLogOptions) => Promise<HilogEntry>` | First entry matching a regex; auto-respawns the stream so it survives a reboot. |
|
|
226
237
|
| `watchLog` | `(WatchLogOptions) => Promise<HilogEntry[]>` | Collect matches for a duration (deduped by default). |
|
|
227
238
|
| `dumpLog` | `(DumpLogOptions) => Promise<HilogEntry[]>` | One-shot `hilog -x` filtered by domain/bundle/grep, capped to the last N lines. |
|
|
239
|
+
| `captureLog` | `(CaptureLogOptions) => Promise<CaptureLogResult>` | Stream hilog into a file until a deadline or abort, writing each line as it arrives and reconnecting after a reboot, so the small ring buffer cannot drop lines. |
|
|
228
240
|
| `streamHilog` | `(StreamHilogOptions) => ChildProcessWithoutNullStreams` | Raw long-lived hilog stream (caller owns the process). |
|
|
229
241
|
| `setHilogLevel` | `(SetHilogLevelOptions) => Promise<void>` | Set the buffer level. |
|
|
230
242
|
| `parseHilogLine` / `dedupEntries` | — | Pure helpers; `HilogEntry` / `HilogLevel` types. |
|
|
@@ -233,12 +245,13 @@ The injection-safe primitives every device operation builds on (`spawn` with `sh
|
|
|
233
245
|
|
|
234
246
|
| Export | Signature | Description |
|
|
235
247
|
| --- | --- | --- |
|
|
236
|
-
| `buildHap` | `(BuildHapOptions) => Promise<BuildHapResult>` | High-level orchestration: ensure deps → `hvigorw` → discover built HAPs. The call most consumers want. |
|
|
248
|
+
| `buildHap` | `(BuildHapOptions) => Promise<BuildHapResult>` | High-level orchestration: ensure deps → `hvigorw` → discover built HAPs. The call most consumers want. Throws `SdkNotInstalledError` (with the `version` to install) up front when an OpenHarmony project's SDK is missing; `diagnoseBuildFailure` adds a hint for system-API errors. |
|
|
237
249
|
| `runHvigorw` | `(RunHvigorwOptions) => Promise<RunHvigorwResult>` | Raw single `hvigorw` spawn. Parallel by default; `parallel: false` adds `--no-parallel`. |
|
|
238
250
|
| `buildHvigorwArgs` | `(opts) => string[]` | Pure argv builder (unit-testable). |
|
|
239
|
-
| `discoverHaps` | `(DiscoverHapsOptions) => Promise<Record<string, ModuleHaps>>` | Group `*-signed`/`*-unsigned` HAPs by module. |
|
|
251
|
+
| `discoverHaps` | `(DiscoverHapsOptions) => Promise<Record<string, ModuleHaps>>` | Group `*-signed`/`*-unsigned` HAPs by module, newest first. |
|
|
252
|
+
| `pickHap` | `(haps, module?) => PickedHap \| null` | The HAP to install: a signed one, else unsigned (`signed: false`). |
|
|
240
253
|
| `runOhpm` / `ensureOhModules` | — | Run `ohpm`; install `--all` only when `oh_modules/` is missing. |
|
|
241
|
-
| `runCodelinter` / `parseCodelinterFindings` | — | Run the codelinter → `CodelinterResult { code, findings, raw }
|
|
254
|
+
| `runCodelinter` / `parseCodelinterReport` / `parseCodelinterFindings` | — | Run the codelinter → `CodelinterResult { code, findings, summary, notices, incomplete, raw }`; the parsers read its per-file table and `-Defects:` totals. |
|
|
242
255
|
|
|
243
256
|
### Project scaffolding & inspection
|
|
244
257
|
|
|
@@ -255,13 +268,13 @@ The injection-safe primitives every device operation builds on (`spawn` with `sh
|
|
|
255
268
|
|
|
256
269
|
### Device info
|
|
257
270
|
|
|
258
|
-
`getDeviceInfo(GetDeviceInfoOptions) => Promise<DeviceFullInfo>` collates device properties
|
|
271
|
+
`getDeviceInfo(GetDeviceInfoOptions) => Promise<DeviceFullInfo>` collates device properties (model, `osFamily` HarmonyOS / OpenHarmony, `osDistVersion`, API level, `abi`, `deviceType`, …) in one round trip, plus the display resolution. `dumpScreen` / `dumpWindow` / `dumpRenderService` wrap the corresponding `hidumper` services.
|
|
259
272
|
|
|
260
273
|
### Install orchestration
|
|
261
274
|
|
|
262
275
|
| Export | Signature | Description |
|
|
263
276
|
| --- | --- | --- |
|
|
264
|
-
| `applyChanges` | `(ApplyChangesOptions) => Promise<ApplyChangesResult>` | Install a HAP **and verify
|
|
277
|
+
| `applyChanges` | `(ApplyChangesOptions) => Promise<ApplyChangesResult>` | Install a HAP **and verify it took**: throws on a bundle-manager rejection or when `bm dump` does not list the bundle afterwards; handles sign-info mismatch, asset-cache invalidation (reboot), and persistent-bundle restart. |
|
|
265
278
|
| `decideInstallMethod` / `decideReboot` | — | The pure (tested) decision functions behind `applyChanges`. |
|
|
266
279
|
| `diffHapAssets` / `diffEntryNames` | — | Diff two HAP archives' file manifests (drives the cache-invalidation reboot). |
|
|
267
280
|
|
|
@@ -302,7 +315,7 @@ DevEco Studio. Parts of this subtree are adapted from the MIT-licensed
|
|
|
302
315
|
|
|
303
316
|
- **Configuration.** Pass a `ConfigProvider`. `staticConfig({...})` is the quick path; a frontend can read settings, env vars, etc. Unset keys fall back to `defaultPaths`.
|
|
304
317
|
- **Logging & progress are opt-in.** Omit `logger`/`progress` for silence, or pass `consoleLogger` / your own. Nothing is written to `console` by default.
|
|
305
|
-
- **Device targeting.** Pass `deviceSerial` to address a specific target
|
|
318
|
+
- **Device targeting.** Pass `deviceSerial` to address a specific target. Without it, every device operation addresses `ONIRO_DEVICE_SERIAL` / `DEVICE_SERIAL` when set, else hdc's single connected device. hdc's `[Fail]` lines (exit code 0 from hdc) surface as failures.
|
|
306
319
|
- **Timeouts & cancellation.** Device ops take `timeoutMs` (sane per-op defaults) and `abortSignal`; aborting rejects with `CancelledError`.
|
|
307
320
|
- **Error model.** Exec primitives (`runProcess`/`hdcExec`/`shell`) resolve for any exit code — call `ensureOk` to throw `CommandFailedError`. Everything else throws a typed `OniroError` subclass.
|
|
308
321
|
- **No surprises in returns.** Functions return plain JSON-safe data; screenshots/bursts return raw `Buffer`s. No image decoding, no `sharp`-style dependency.
|