161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file State management API file 1861847f8eSopenharmony_ci * @kit ArkUI 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ci/** 2261847f8eSopenharmony_ci * Function that returns default creator. 2361847f8eSopenharmony_ci * 2461847f8eSopenharmony_ci * @typedef { function } StorageDefaultCreator<T> 2561847f8eSopenharmony_ci * @returns { T } default creator 2661847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 2761847f8eSopenharmony_ci * @crossplatform 2861847f8eSopenharmony_ci * @atomicservice 2961847f8eSopenharmony_ci * @since 12 3061847f8eSopenharmony_ci */ 3161847f8eSopenharmony_ciexport declare type StorageDefaultCreator<T> = () => T; 3261847f8eSopenharmony_ci 3361847f8eSopenharmony_ci/** 3461847f8eSopenharmony_ci * Define class constructor with arbitrary parameters. 3561847f8eSopenharmony_ci * @interface TypeConstructorWithArgs<T> 3661847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 3761847f8eSopenharmony_ci * @crossplatform 3861847f8eSopenharmony_ci * @atomicservice 3961847f8eSopenharmony_ci * @since 12 4061847f8eSopenharmony_ci */ 4161847f8eSopenharmony_ciexport interface TypeConstructorWithArgs<T> { 4261847f8eSopenharmony_ci /** 4361847f8eSopenharmony_ci * @param { any } args the arguments of the constructor. 4461847f8eSopenharmony_ci * @returns { T } return class instance. 4561847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 4661847f8eSopenharmony_ci * @crossplatform 4761847f8eSopenharmony_ci * @atomicservice 4861847f8eSopenharmony_ci * @since 12 4961847f8eSopenharmony_ci */ 5061847f8eSopenharmony_ci new(...args: any): T; 5161847f8eSopenharmony_ci} 5261847f8eSopenharmony_ci 5361847f8eSopenharmony_ci/** 5461847f8eSopenharmony_ci * AppStorageV2 is for UI state of app-wide access, has same life cycle as the app, 5561847f8eSopenharmony_ci * and saves database content only in memory. 5661847f8eSopenharmony_ci * 5761847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 5861847f8eSopenharmony_ci * @crossplatform 5961847f8eSopenharmony_ci * @atomicservice 6061847f8eSopenharmony_ci * @since 12 6161847f8eSopenharmony_ci */ 6261847f8eSopenharmony_ciexport declare class AppStorageV2 { 6361847f8eSopenharmony_ci /** 6461847f8eSopenharmony_ci * If the value for the given key is already available, return the value. 6561847f8eSopenharmony_ci * If not, add the key with value generated by calling defaultFunc and return it to caller. 6661847f8eSopenharmony_ci * 6761847f8eSopenharmony_ci * @param { TypeConstructorWithArgs<T> } type class type of the stored value. 6861847f8eSopenharmony_ci * @param { string | StorageDefaultCreator<T> } [keyOrDefaultCreator] alias name of the key, or the function generating the default value. 6961847f8eSopenharmony_ci * @param { StorageDefaultCreator<T> } [defaultCreator] the function generating the default value 7061847f8eSopenharmony_ci * @returns { T | undefined } the value of the existed key or the default value 7161847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 7261847f8eSopenharmony_ci * @crossplatform 7361847f8eSopenharmony_ci * @atomicservice 7461847f8eSopenharmony_ci * @since 12 7561847f8eSopenharmony_ci */ 7661847f8eSopenharmony_ci static connect<T extends object>( 7761847f8eSopenharmony_ci type: TypeConstructorWithArgs<T>, 7861847f8eSopenharmony_ci keyOrDefaultCreator?: string | StorageDefaultCreator<T>, 7961847f8eSopenharmony_ci defaultCreator?: StorageDefaultCreator<T> 8061847f8eSopenharmony_ci ): T | undefined; 8161847f8eSopenharmony_ci 8261847f8eSopenharmony_ci /** 8361847f8eSopenharmony_ci * Removes data with the given key or given class type. 8461847f8eSopenharmony_ci * 8561847f8eSopenharmony_ci * @param { string | TypeConstructorWithArgs<T> } keyOrType key or class type removing 8661847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 8761847f8eSopenharmony_ci * @crossplatform 8861847f8eSopenharmony_ci * @atomicservice 8961847f8eSopenharmony_ci * @since 12 9061847f8eSopenharmony_ci */ 9161847f8eSopenharmony_ci static remove<T>(keyOrType: string | TypeConstructorWithArgs<T>): void; 9261847f8eSopenharmony_ci 9361847f8eSopenharmony_ci /** 9461847f8eSopenharmony_ci * Return the array of all keys. 9561847f8eSopenharmony_ci * 9661847f8eSopenharmony_ci * @returns { Array<string> } the array of all keys 9761847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 9861847f8eSopenharmony_ci * @crossplatform 9961847f8eSopenharmony_ci * @atomicservice 10061847f8eSopenharmony_ci * @since 12 10161847f8eSopenharmony_ci */ 10261847f8eSopenharmony_ci static keys(): Array<string>; 10361847f8eSopenharmony_ci} 10461847f8eSopenharmony_ci 10561847f8eSopenharmony_ci/** 10661847f8eSopenharmony_ci * Function that returns reason type when error. 10761847f8eSopenharmony_ci * 10861847f8eSopenharmony_ci * @typedef { function } PersistenceErrorCallback 10961847f8eSopenharmony_ci * @param { string } key persisted key when error 11061847f8eSopenharmony_ci * @param { 'quota' | 'serialization' | 'unknown' } reason reason type when error 11161847f8eSopenharmony_ci * @param { string } message more message when error 11261847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 11361847f8eSopenharmony_ci * @crossplatform 11461847f8eSopenharmony_ci * @atomicservice 11561847f8eSopenharmony_ci * @since 12 11661847f8eSopenharmony_ci */ 11761847f8eSopenharmony_ciexport declare type PersistenceErrorCallback = (key: string, reason: 'quota' | 'serialization' | 'unknown', message: string) => void; 11861847f8eSopenharmony_ci 11961847f8eSopenharmony_ci/** 12061847f8eSopenharmony_ci * PersistenceV2 is for UI state of app-wide access, available on app re-start, 12161847f8eSopenharmony_ci * and saves database content in disk. 12261847f8eSopenharmony_ci * 12361847f8eSopenharmony_ci * @extends AppStorageV2 12461847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 12561847f8eSopenharmony_ci * @crossplatform 12661847f8eSopenharmony_ci * @atomicservice 12761847f8eSopenharmony_ci * @since 12 12861847f8eSopenharmony_ci */ 12961847f8eSopenharmony_ciexport declare class PersistenceV2 extends AppStorageV2 { 13061847f8eSopenharmony_ci /** 13161847f8eSopenharmony_ci * Used to manually persist data changes to disks. 13261847f8eSopenharmony_ci * 13361847f8eSopenharmony_ci * @param { string | TypeConstructorWithArgs<T> } keyOrType key or class type need to persist. 13461847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 13561847f8eSopenharmony_ci * @crossplatform 13661847f8eSopenharmony_ci * @atomicservice 13761847f8eSopenharmony_ci * @since 12 13861847f8eSopenharmony_ci */ 13961847f8eSopenharmony_ci static save<T>(keyOrType: string | TypeConstructorWithArgs<T>): void; 14061847f8eSopenharmony_ci 14161847f8eSopenharmony_ci /** 14261847f8eSopenharmony_ci * Be called when persisting has encountered an error. 14361847f8eSopenharmony_ci * 14461847f8eSopenharmony_ci * @param { PersistenceErrorCallback | undefined } callback called when error 14561847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 14661847f8eSopenharmony_ci * @crossplatform 14761847f8eSopenharmony_ci * @atomicservice 14861847f8eSopenharmony_ci * @since 12 14961847f8eSopenharmony_ci */ 15061847f8eSopenharmony_ci static notifyOnError(callback: PersistenceErrorCallback | undefined): void; 15161847f8eSopenharmony_ci} 15261847f8eSopenharmony_ci 15361847f8eSopenharmony_ci/** 15461847f8eSopenharmony_ci * Define TypeConstructor type. 15561847f8eSopenharmony_ci * 15661847f8eSopenharmony_ci * @interface TypeConstructor<T> 15761847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 15861847f8eSopenharmony_ci * @crossplatform 15961847f8eSopenharmony_ci * @atomicservice 16061847f8eSopenharmony_ci * @since 12 16161847f8eSopenharmony_ci */ 16261847f8eSopenharmony_ciexport interface TypeConstructor<T> { 16361847f8eSopenharmony_ci /** 16461847f8eSopenharmony_ci * @returns { T } 16561847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 16661847f8eSopenharmony_ci * @crossplatform 16761847f8eSopenharmony_ci * @atomicservice 16861847f8eSopenharmony_ci * @since 12 16961847f8eSopenharmony_ci */ 17061847f8eSopenharmony_ci new(): T; 17161847f8eSopenharmony_ci} 17261847f8eSopenharmony_ci 17361847f8eSopenharmony_ci/** 17461847f8eSopenharmony_ci * Function that returns PropertyDecorator. 17561847f8eSopenharmony_ci * 17661847f8eSopenharmony_ci * @typedef { function } TypeDecorator 17761847f8eSopenharmony_ci * @param { TypeConstructor<T> } type type info 17861847f8eSopenharmony_ci * @returns { PropertyDecorator } Type decorator 17961847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 18061847f8eSopenharmony_ci * @crossplatform 18161847f8eSopenharmony_ci * @atomicservice 18261847f8eSopenharmony_ci * @since 12 18361847f8eSopenharmony_ci */ 18461847f8eSopenharmony_ciexport declare type TypeDecorator = <T>(type: TypeConstructor<T>) => PropertyDecorator; 18561847f8eSopenharmony_ci 18661847f8eSopenharmony_ci/** 18761847f8eSopenharmony_ci * Define Type PropertyDecorator, adds type information to an object. 18861847f8eSopenharmony_ci * 18961847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 19061847f8eSopenharmony_ci * @crossplatform 19161847f8eSopenharmony_ci * @atomicservice 19261847f8eSopenharmony_ci * @since 12 19361847f8eSopenharmony_ci */ 19461847f8eSopenharmony_ciexport declare const Type: TypeDecorator; 19561847f8eSopenharmony_ci 19661847f8eSopenharmony_ci/** 19761847f8eSopenharmony_ci * UIUtils is a state management tool class for operating the observed data. 19861847f8eSopenharmony_ci * 19961847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 20061847f8eSopenharmony_ci * @crossplatform 20161847f8eSopenharmony_ci * @atomicservice 20261847f8eSopenharmony_ci * @since 12 20361847f8eSopenharmony_ci */ 20461847f8eSopenharmony_ciexport declare class UIUtils { 20561847f8eSopenharmony_ci /** 20661847f8eSopenharmony_ci * Get raw object from the Object wrapped with an ObservedObject. 20761847f8eSopenharmony_ci * If input parameter is a regular Object without ObservedObject, return Object itself. 20861847f8eSopenharmony_ci * 20961847f8eSopenharmony_ci * @param { T } source input source Object data. 21061847f8eSopenharmony_ci * @returns { T } raw object from the Object wrapped with an ObservedObject. 21161847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 21261847f8eSopenharmony_ci * @crossplatform 21361847f8eSopenharmony_ci * @atomicservice 21461847f8eSopenharmony_ci * @since 12 21561847f8eSopenharmony_ci */ 21661847f8eSopenharmony_ci static getTarget<T extends object>(source: T): T; 21761847f8eSopenharmony_ci 21861847f8eSopenharmony_ci /** 21961847f8eSopenharmony_ci * Make non-observed data into observed data. 22061847f8eSopenharmony_ci * Support non-observed class, JSON.parse Object and Sendable class. 22161847f8eSopenharmony_ci * 22261847f8eSopenharmony_ci * @param { T } source input source object data. 22361847f8eSopenharmony_ci * @returns { T } proxy object from the source object data. 22461847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full 22561847f8eSopenharmony_ci * @crossplatform 22661847f8eSopenharmony_ci * @atomicservice 22761847f8eSopenharmony_ci * @since 12 22861847f8eSopenharmony_ci */ 22961847f8eSopenharmony_ci static makeObserved<T extends object>(source: T): T; 23061847f8eSopenharmony_ci 23161847f8eSopenharmony_ci}