/* * Copyright (C) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file State management API file * @kit ArkUI */ import contextConstant from '@ohos.app.ability.contextConstant'; /** * Function that returns default creator. * * @typedef { function } StorageDefaultCreator * @returns { T } default creator * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export declare type StorageDefaultCreator = () => T; /** * Define class constructor with arbitrary parameters. * @interface TypeConstructorWithArgs * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export interface TypeConstructorWithArgs { /** * @param { any } args the arguments of the constructor. * @returns { T } return class instance. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ new(...args: any): T; } /** * Define ConnectOptions class. * @syscap SystemCapability.ArkUI.ArkUI.Full * @atomicservice * @since 18 */ export class ConnectOptions { /** * @type { TypeConstructorWithArgs } type class type of the stored value. * @syscap SystemCapability.ArkUI.ArkUI.Full * @atomicservice * @since 18 */ type: TypeConstructorWithArgs; /** * Defines alias name of the key, or the function generating the default value. * @type { ?string } * @syscap SystemCapability.ArkUI.ArkUI.Full * @atomicservice * @since 18 */ key?: string; /** * Define the function generating the default value. * @type { ?StorageDefaultCreator} * @syscap SystemCapability.ArkUI.ArkUI.Full * @atomicservice * @since 18 */ defaultCreator?: StorageDefaultCreator; /** * Define encrypted partition for data storage. * if not passed in, the defaule value is El2 * * @type { ?contextConstant.AreaMode} * @syscap SystemCapability.ArkUI.ArkUI.Full * @atomicservice * @since 18 */ areaMode?: contextConstant.AreaMode; } /** * AppStorageV2 is for UI state of app-wide access, has same life cycle as the app, * and saves database content only in memory. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export declare class AppStorageV2 { /** * If used by persistenceV2, module-level storage path, different modules will have their own storage paths. * If the value for the given key is already available, return the value. * If not, add the key with value generated by calling defaultFunc and return it to caller. * * @param { TypeConstructorWithArgs } type class type of the stored value. * @param { string | StorageDefaultCreator } [keyOrDefaultCreator] alias name of the key, or the function generating the default value. * @param { StorageDefaultCreator } [defaultCreator] the function generating the default value * @returns { T | undefined } the value of the existed key or the default value * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ static connect( type: TypeConstructorWithArgs, keyOrDefaultCreator?: string | StorageDefaultCreator, defaultCreator?: StorageDefaultCreator ): T | undefined; /** * Removes data with the given key or given class type. * * @param { string | TypeConstructorWithArgs } keyOrType key or class type removing * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ static remove(keyOrType: string | TypeConstructorWithArgs): void; /** * Return the array of all keys. * * @returns { Array } the array of all keys * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ static keys(): Array; } /** * Function that returns reason type when error. * * @typedef { function } PersistenceErrorCallback * @param { string } key persisted key when error * @param { 'quota' | 'serialization' | 'unknown' } reason reason type when error * @param { string } message more message when error * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export declare type PersistenceErrorCallback = (key: string, reason: 'quota' | 'serialization' | 'unknown', message: string) => void; /** * PersistenceV2 is for UI state of app-wide access, available on app re-start, * and saves database content in disk. * * @extends AppStorageV2 * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export declare class PersistenceV2 extends AppStorageV2 { /** * Application-level storage path, sharing a storage path for all modules under the application. * If the value for the given key is already available, return the value. * If not, add the key with value generated by calling defaultFunc and return it to caller. * * @param { ConnectOptions } type Application level storage parameters. * @returns { T | undefined } the value of the existed key or the default value * @syscap SystemCapability.ArkUI.ArkUI.Full * @atomicservice * @since 18 */ static globalConnect( type: ConnectOptions ): T | undefined; /** * Used to manually persist data changes to disks. * * @param { string | TypeConstructorWithArgs } keyOrType key or class type need to persist. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ static save(keyOrType: string | TypeConstructorWithArgs): void; /** * Be called when persisting has encountered an error. * * @param { PersistenceErrorCallback | undefined } callback called when error * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ static notifyOnError(callback: PersistenceErrorCallback | undefined): void; } /** * Define TypeConstructor type. * * @interface TypeConstructor * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export interface TypeConstructor { /** * @returns { T } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ new(): T; } /** * Function that returns PropertyDecorator. * * @typedef { function } TypeDecorator * @param { TypeConstructor } type type info * @returns { PropertyDecorator } Type decorator * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export declare type TypeDecorator = (type: TypeConstructor) => PropertyDecorator; /** * Define Type PropertyDecorator, adds type information to an object. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export declare const Type: TypeDecorator; /** * UIUtils is a state management tool class for operating the observed data. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ export declare class UIUtils { /** * Get raw object from the Object wrapped with an ObservedObject. * If input parameter is a regular Object without ObservedObject, return Object itself. * * @param { T } source input source Object data. * @returns { T } raw object from the Object wrapped with an ObservedObject. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ static getTarget(source: T): T; /** * Make non-observed data into observed data. * Support non-observed class, JSON.parse Object and Sendable class. * * @param { T } source input source object data. * @returns { T } proxy object from the source object data. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ static makeObserved(source: T): T; }