diff --git a/api/@ohos.arkui.stateManagement.static.d.ets b/api/@ohos.arkui.stateManagement.static.d.ets index 4f8e84173bb4dfc78d7b79441a86a0b14a756fd6..27c252dff69ceda35b385f02c1c72d93de9ee2dc 100644 --- a/api/@ohos.arkui.stateManagement.static.d.ets +++ b/api/@ohos.arkui.stateManagement.static.d.ets @@ -24,8 +24,10 @@ export * from './arkui/stateManagement/decorator'; export * from './arkui/stateManagement/remember'; export * from './arkui/stateManagement/runtime'; export * from './arkui/stateManagement/storage/appStorage'; +export * from './arkui/stateManagement/storage/appStorageV2'; export * from './arkui/stateManagement/storage/environment'; export * from './arkui/stateManagement/storage/localStorage'; +export * from './arkui/stateManagement/storage/persistenceV2'; export * from './arkui/stateManagement/storage/persistentStorage'; export * from './arkui/stateManagement/storage/storageProperty'; export * from './arkui/stateManagement/utils'; \ No newline at end of file diff --git a/api/arkui/stateManagement/storage/appStorageV2.static.d.ets b/api/arkui/stateManagement/storage/appStorageV2.static.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..0c0abf11b65256bbd8f776986dd3c07c77becd19 --- /dev/null +++ b/api/arkui/stateManagement/storage/appStorageV2.static.d.ets @@ -0,0 +1,88 @@ +'use static' +/* + * Copyright (c) 2025 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 + * @kit ArkUI + * @arkts 1.2 + */ + +import { StorageDefaultCreator } from './persistenceV2'; + +/** + * 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 + * @since 20 + */ +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 { Type } ttype class type of the stored value. + * @param { string } key alias name of the key + * @param { StorageDefaultCreator } [defaultCreator] the function generating the default value + * @returns { T | undefined } the value of the existed key or the default value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static connect( + ttype: Type, + key: string, + defaultCreator?: StorageDefaultCreator + ): T | undefined; + + /** + * 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 { Type } ttype class type of the stored value. + * @param { StorageDefaultCreator } [defaultCreator] the function generating the default value + * @returns { T | undefined } the value of the existed key or the default value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static connect( + ttype: Type, + defaultCreator?: StorageDefaultCreator + ): T | undefined; + + /** + * Removes data with the given key or given class type. + * + * @param { string | Type } keyOrType key or class type removing + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static remove(keyOrType: string | Type): void; + + /** + * Return the array of all keys. + * + * @returns { Array } the array of all keys + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static keys(): Array; +} \ No newline at end of file diff --git a/api/arkui/stateManagement/storage/persistenceV2.static.d.ets b/api/arkui/stateManagement/storage/persistenceV2.static.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..505235edf662d032c3ca2a906dae7a2e8d404125 --- /dev/null +++ b/api/arkui/stateManagement/storage/persistenceV2.static.d.ets @@ -0,0 +1,257 @@ +'use static' +/* + * Copyright (c) 2025 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 + * @kit ArkUI + * @arkts 1.2 + */ + +import { ToJSONType, FromJSONType } from './persistentStorage'; +import contextConstant from '@ohos.app.ability.contextConstant'; + +/** + * Function that returns default creator. + * + * @typedef { function } StorageDefaultCreator + * @returns { T } default creator + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare type StorageDefaultCreator = () => T; + +/** + * Define ConnectOptions class. + * @typedef ConnectOptions + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare interface ConnectOptions { + + /** + * Define class constructor + * @type { Type } type class type of the stored value. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + type: Type; + + /** + * Defines alias name of the key, or the function generating the default value. + * @type { ?string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + key?: string; + + /** + * Define the function generating the default value. + * @type { ?StorageDefaultCreator} + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + 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 + * @since 20 + */ + areaMode?: contextConstant.AreaMode; +} + +/** + * 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 + * @since 20 + */ +export declare type PersistenceErrorCallback = (key: string, reason: 'quota' | 'serialization' | 'unknown', message: string) => void; + +/** + * Defines Serializable object + * + * @extends jsonx.JsonElementSerializable, jsonx.JsonElementDeserializable + * @interface SerializableObject + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export interface SerializableObject extends jsonx.JsonElementSerializable, jsonx.JsonElementDeserializable {} + +/** + * PersistenceV2 is for UI state of app-wide access, available on app re-start, + * and saves database content in disk. + * + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare class PersistenceV2 { + /** + * 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 { Type } ttype class type of the stored value. + * @param { ToJSONType } toJson to Json function. + * @param { FromJSONType } fromJson serializable function. + * @param { StorageDefaultCreator } [defaultCreator] the function generating the default value + * @returns { T | undefined } the value of the existed key or the default value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static connect( + ttype: Type, + toJson: ToJSONType, + fromJson: FromJSONType, + defaultCreator?: StorageDefaultCreator + ): T | undefined; + + /** + * 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 { Type } ttype class type of the stored value. + * @param { string } key - alias name of the key. + * @param { ToJSONType } toJson to Json function. + * @param { FromJSONType } fromJson serializable function. + * @param { StorageDefaultCreator } [defaultCreator] the function generating the default value + * @returns { T | undefined } the value of the existed key or the default value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static connect( + ttype: Type, + key: string, + toJson: ToJSONType, + fromJson: FromJSONType, + defaultCreator?: StorageDefaultCreator + ): T | undefined; + + /** + * 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 { Type } ttype class type of the stored value. + * @param { StorageDefaultCreator } [defaultCreator] the function generating the default value. + * @returns { T | undefined } the value of the existed key or the default value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static connect( + ttype: Type, + defaultCreator?: StorageDefaultCreator + ): T | undefined; + + /** + * 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 { Type } ttype class type of the stored value. + * @param { string } key - alias name of the key. + * @param { StorageDefaultCreator } [defaultCreator] the function generating the default value + * @returns { T | undefined } the value of the existed key or the default value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static connect( + ttype: Type, + key: string, + defaultCreator?: StorageDefaultCreator + ): T | undefined; + + /** + * 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 } connectOptions Application level storage parameters. + * @returns { T | undefined } the value of the existed key or the default value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static globalConnect(connectOptions: ConnectOptions): T | undefined; + + /** + * 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 } connectOptions Application level storage parameters. + * @param { ToJSONType } toJson to Json function. + * @param { FromJSONType } fromJson serializable function. + * @returns { T | undefined } the value of the existed key or the default value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static globalConnect(connectOptions: ConnectOptions, + toJson: ToJSONType, fromJson: FromJSONType): T | undefined; + + /** + * Used to manually persist data changes to disks. + * + * @param { string | Type } keyOrType key or class type need to persist. + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static save(keyOrType: string | Type): void; + + /** + * Be called when persisting has encountered an error. + * + * @param { PersistenceErrorCallback | undefined } callback called when error + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static notifyOnError(callback: PersistenceErrorCallback | undefined): void; + + /** + * Removes data with the given key or given class type. + * + * @param { string | Type } keyOrType key or class type removing + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static remove(keyOrType: string | Type): void; + + /** + * Return the array of all keys. + * + * @returns { Array } the array of all keys + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static keys(): Array; +} \ No newline at end of file