Skip to main content

Crate asc_hap

Crate asc_hap 

Source
Expand description

HarmonyOS package metadata: the descriptors at the root of a HAP/HSP, read from bytes the caller supplies (no zip or file IO here).

  • ModuleJson: module.json, the manifest. Abilities and extension abilities with their exported flag, required permissions, skills and deep-link URIs; requested and defined permissions.
  • PackInfo: pack.info, the packing tool’s digest of the bundle.
  • PkgContextInfo: pkgContextInfo.json, the package table that .abc record names and import requests refer to.
  • PageList and RouterMap: the page list and the navigation route table module.json names ($profile:main_pages, $profile:router_map).
  • ResourceIndex: resources.index, the compiled resource table: what the ids in compiled $r(...) calls and the $string:name references of module.json stand for.
  • SourceMaps: ets/sourceMaps.map of a debug build, from the lines of the compiled files the code was made from to the source.

Every JSON type offers the same two texts: summary(), one fact per line for grep, and pretty(), the document itself re-indented. The summaries state what the documents say and pass no judgement.

Parsing the JSON documents is tolerant: only input that is not a JSON object is an error. A wrongly typed field is skipped and recorded in notes; a field the model does not cover is listed in unmodelled and stays reachable through raw().

use asc_hap::ModuleJson;

let manifest = ModuleJson::parse(
    br#"{"app": {"bundleName": "com.x.y"},
         "module": {"name": "entry", "abilities": [{
             "name": "EntryAbility", "exported": true, "srcEntry": "./ets/entryability/EntryAbility.ets",
             "skills": [{"actions": ["ohos.want.action.viewData"], "uris": [{"scheme": "xy", "host": "open"}]}]}]}}"#,
)?;
let ability = &manifest.module.abilities[0];
assert!(ability.is_exported());
assert_eq!(ability.deep_links(), ["xy://open"]);
assert!(manifest.summary().contains("deeplink EntryAbility xy://open\n"));
let records = manifest.record_names("./ets/entryability/EntryAbility.ets", None);
assert_eq!(records.candidates(), ["com.x.y/entry/ets/entryability/EntryAbility", "&entry/src/main/ets/entryability/EntryAbility&"]);

Structs§

Ability
An entry of abilities or extensionAbilities.
ApiVersion
minAPIVersion / targetAPIVersion as written.
App
The app object: bundle-wide facts.
AtomicService
atomicService.
Attr
A name with its value: a plural form, or an attribute of a theme or pattern.
DefinePermission
An entry of definePermissions.
Dependency
A shared package (HSP) the module depends on.
Metadata
A metadata entry: a literal value, a $profile: resource, or both.
Module
The module object.
ModuleJson
A parsed module.json.
ModuleMap
The source map of one module: which source line each line of the compiled file comes from.
MultiAppMode
multiAppMode of the app object.
NameValue
A name / value pair (appEnvironments).
Note
A field that was present but could not be used.
PackAbility
An entry of a module’s abilities.
PackApp
summary.app: bundle-wide facts.
PackExtension
An entry of a module’s extensionAbilities.
PackForm
An entry of an extension’s forms: one service widget.
PackInfo
A parsed pack.info.
PackModule
An entry of summary.modules.
PackPackage
An entry of packages: one HAP/HSP file of the bundle.
PageList
A parsed page list: {"src": ["pages/Index", …]}.
PkgContext
One package. Strings the file leaves empty stay empty here: the file itself writes "" for “none”.
PkgContextInfo
A parsed pkgContextInfo.json.
ProxyData
A proxyData entry: data shared through the data-share proxy.
Qualifier
One key of a qualifier set with its stored value.
Qualifiers
The qualifiers one value of a resource was defined under. Empty is the base directory, the value used when nothing more specific matches.
RecordNames
The record names a manifest srcEntry can compile to. Which spelling a package uses is a build option (normalized OHM URLs); packages built with it carry a pkgContextInfo.json.
RecordOwner
A normalized record name split against the package table.
RequestPermission
An entry of requestPermissions.
Resource
One value of one resource: its id, type, name, the qualifier set the value is for, and the value.
ResourceIndex
A parsed resources.index, borrowing the bytes it was read from.
ResourceRef
A reference to a resource by type and name, as module.json writes it ($string:app_name) or as source code does (app.string.app_name).
Resources
Values of an index, from ResourceIndex::iter or one of its lookups.
Route
One route: a name the navigation stack is pushed with, and the builder function that makes its page.
RouterMap
A parsed route table: {"routerMap": [{…}, …]}.
Skill
One entry of skills: the implicit wants an ability accepts.
SkillUri
One entry of a skill’s uris.
SourceLine
A line of one of the source files of a module.
SourceMaps
The modules of an ets/sourceMaps.map, by the record compiled from each. It holds no part of the file: the bytes are passed again to read a module.
TestRunner
testRunner.
UnknownResourceType
The text was not the name of a resource type.

Enums§

AbilityKind
Which array of the module an Ability comes from.
HapError
Why a metadata document could not be read at all.
IndexFormat
Which of the two layouts an index uses.
QualifierKey
What a qualifier restricts.
ResourceIndexError
Why a resources.index could not be read. Offsets are file offsets.
ResourceType
The type of a resource: the string of $string:app_name and of $r('app.string.app_name').
ResourceValue
What the index stores for one resource under one qualifier set. Every value is text in the file; text that is not UTF-8 is read lossily.
SourceMapError
Why a source map table could not be read.