Skip to content

test: 修改call变更callAsync beta包 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-oh-tpl/async-storage",
"version": "1.21.0-0.1.6",
"version": "1.21.0-0.1.6-beta",
"private": true,
"workspaces": [
"packages/*"
Expand Down
Binary file modified packages/default-storage/harmony/async_storage.har
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"author": "",
"name": "@react-native-oh-tpl/async-storage",
"version": "1.21.0-0.1.6",
"version": "1.21.0-0.1.6-beta",
"description": "",
"main": "ts.ts",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ using namespace rnoh;
using namespace facebook;

static jsi::Value __hostFunction_RNAsyncStorageTurboModule_multiGet(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args, size_t count) {
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "multiGet", args, count);
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "multiGet", args, count);
}

static jsi::Value __hostFunction_RNAsyncStorageTurboModule_multiSet(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args, size_t count) {
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "multiSet", args, count);
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "multiSet", args, count);
}

static jsi::Value __hostFunction_RNAsyncStorageTurboModule_multiRemove(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args, size_t count) {
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "multiRemove", args, count);
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "multiRemove", args, count);
}

static jsi::Value __hostFunction_RNAsyncStorageTurboModule_multiMerge(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args, size_t count) {
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "multiMerge", args, count);
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "multiMerge", args, count);
}

static jsi::Value __hostFunction_RNAsyncStorageTurboModule_getAllKeys(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args, size_t count) {
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "getAllKeys", args, count);
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "getAllKeys", args, count);
}

static jsi::Value __hostFunction_RNAsyncStorageTurboModule_clear(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args, size_t count) {
return static_cast<ArkTSTurboModule &>(turboModule).call(rt, "clear", args, count);
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "clear", args, count);
}

RNAsyncStorageTurboModule::RNAsyncStorageTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ export class AsyncStorageTurboModule extends TurboModule {
* Given an array of keys, this returns a map of (key, value) pairs for the keys found, and
* (key, null) for the keys that haven't been found.
*/
multiGet(keys: string[], callback: (error?: Object, result?: [string, string][] | null) => void) {
multiGet(keys: string[], callback: (error?: Object, result?: [string, string][] | null) => void): Promise<void> {
Logger.debug(CommonConstants.TAG, `Module multiGet() Call!`);
this.runMultiGet(keys).then((result) => { callback(result[0], result[1]) }).catch((e: Error) => {
Logger.debug(CommonConstants.TAG, `Module multiGet() Call Fail!${e.message}`);
})
Logger.debug(CommonConstants.TAG, `Module multiGet() End!`);
return Promise.resolve();
}

async runMultiGet(keys: string[]): Promise<[Object, [string, string][] | null]> {
Expand Down Expand Up @@ -129,12 +130,13 @@ export class AsyncStorageTurboModule extends TurboModule {
* return AsyncLocalStorageFailure, but all other pairs will have been inserted.
* The insertion will replace conflicting (key, value) pairs.
*/
multiSet(keyValueArray: [string, string][], callback: (error?: Object) => void) {
multiSet(keyValueArray: [string, string][], callback: (error?: Object) => void): Promise<void> {
Logger.debug(CommonConstants.TAG, `Module multiSet() Call!`);
this.runMultiSet(keyValueArray).then((error) => { callback(error) }).catch((e: Error) => {
Logger.debug(CommonConstants.TAG, `Module multiSet() Call Fail!${e.message}`);
})
Logger.debug(CommonConstants.TAG, `Module multiSet() End!`);
return Promise.resolve();
}

async runMultiSet(keyValueArray: [string, string][], hasError = false): Promise<Object> {
Expand Down Expand Up @@ -200,7 +202,7 @@ export class AsyncStorageTurboModule extends TurboModule {
}
}
}
if(error !== null) {
if (error !== null) {
return error;
} else {
return null;
Expand All @@ -210,12 +212,13 @@ export class AsyncStorageTurboModule extends TurboModule {
/**
* Removes all rows of the keys given.
*/
multiRemove(keys: string[], callback: (error?:Object) => void) {
multiRemove(keys: string[], callback: (error?: Object) => void): Promise<void> {
Logger.debug(CommonConstants.TAG, `Module multiRemove() Call!`);
this.runMultiRemove(keys).then((error)=>{callback(error)}).catch((e:Error)=>{
this.runMultiRemove(keys).then((error) => { callback(error) }).catch((e: Error) => {
Logger.debug(CommonConstants.TAG, `Module multiRemove() Call Fail!${e.message}`);
})
Logger.debug(CommonConstants.TAG, `Module multiRemove() End!`);
return Promise.resolve();
}

async runMultiRemove(keys: string[]): Promise<Object> {
Expand All @@ -237,7 +240,7 @@ export class AsyncStorageTurboModule extends TurboModule {

async asyncMultiRemove(keys: string[]): Promise<Object> {
Logger.debug(CommonConstants.TAG, `ModuleSub asyncMultiRemove() Call!`);
if(keys.length === 0) {
if (keys.length === 0) {
return null;
}
if (!await this.table.ensureDatabase(this.ctx.uiAbilityContext)) {
Expand Down Expand Up @@ -269,12 +272,13 @@ export class AsyncStorageTurboModule extends TurboModule {
* Given an array of (key, value) pairs, this will merge the given values with the stored values
* of the given keys, if they exist.
*/
multiMerge(keyValueArray: [string, string][], callback: (error?: Object) => void) {
multiMerge(keyValueArray: [string, string][], callback: (error?: Object) => void): Promise<void> {
Logger.debug(CommonConstants.TAG, `Module multiMerge() Call!`);
this.runMultiMerge(keyValueArray).then((error)=>{callback(error)}).catch((e:Error)=>{
this.runMultiMerge(keyValueArray).then((error) => { callback(error) }).catch((e: Error) => {
Logger.debug(CommonConstants.TAG, `Module multiMerge() Call Fail!${e.message}`);
})
Logger.debug(CommonConstants.TAG, `Module multiMerge() End!`);
return Promise.resolve();
}

async runMultiMerge(keyValueArray: [string, string][]): Promise<Object> {
Expand Down Expand Up @@ -314,16 +318,16 @@ export class AsyncStorageTurboModule extends TurboModule {
error = AsyncStorageErrorUtil.getInvalidValueError(null)
return error;
}
if(!await AsyncLocalStorageUtil.mergeImpl(this.table.rdbStore, keyValueArray[idx][0], keyValueArray[idx][1])){
if (!await AsyncLocalStorageUtil.mergeImpl(this.table.rdbStore, keyValueArray[idx][0], keyValueArray[idx][1])) {
error = AsyncStorageErrorUtil.getDBError(null)
return error;
}
}
} catch (e) {
Logger.warn(CommonConstants.TAG, e.message);
error = AsyncStorageErrorUtil.getError(null, e.message);
}
if(error != null) {
}
if (error != null) {
return error;
} else {
return null;
Expand All @@ -333,12 +337,13 @@ export class AsyncStorageTurboModule extends TurboModule {
/**
* Clears the database.
*/
clear(callback: (error?: Object) => void) {
clear(callback: (error?: Object) => void): Promise<void> {
Logger.debug(CommonConstants.TAG, `Module clear() Call!`);
this.runClear().then((error)=>{callback(error)}).catch((e:Error)=>{
this.runClear().then((error) => { callback(error) }).catch((e: Error) => {
Logger.debug(CommonConstants.TAG, `Module clear() Call Fail!${e.message}`);
})
Logger.debug(CommonConstants.TAG, `Module clear() End!`);
return Promise.resolve();
}

async runClear(): Promise<Object> {
Expand Down Expand Up @@ -375,12 +380,13 @@ export class AsyncStorageTurboModule extends TurboModule {
/**
* Returns an array with all keys from the database.
*/
getAllKeys(callback: (error?: Object, result?: string[] | null) => void) {
getAllKeys(callback: (error?: Object, result?: string[] | null) => void): Promise<void> {
Logger.debug(CommonConstants.TAG, `Module getAllKeys() Call!`);
this.runGetAllKeys().then((result)=>{callback(result[0], result[1])}).catch((e:Error)=>{
this.runGetAllKeys().then((result) => { callback(result[0], result[1]) }).catch((e: Error) => {
Logger.debug(CommonConstants.TAG, `Module getAllKeys() Call Fail!${e.message}`);
})
Logger.debug(CommonConstants.TAG, `Module getAllKeys() End!`);
return Promise.resolve();
}

async runGetAllKeys(): Promise<[Object, string[] | null]> {
Expand Down Expand Up @@ -410,14 +416,14 @@ export class AsyncStorageTurboModule extends TurboModule {
predicates.isNotNull(ReactDatabaseSupplier.KEY_COLUMN);
let cursor = await this.table.rdbStore.query(predicates);
try {
if(cursor.goToFirstRow()){
if (cursor.goToFirstRow()) {
do {
data.push(cursor.getString(cursor.getColumnIndex('KEY')));
} while (cursor.goToNextRow())
}
} catch (e) {
Logger.warn(CommonConstants.TAG, `Module GetAllKeys() error: ${e.message}`);
return [AsyncStorageErrorUtil.getError(null, e.message),null];
return [AsyncStorageErrorUtil.getError(null, e.message), null];
} finally {
cursor.close();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/default-storage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-oh-tpl/async-storage",
"version": "1.21.0-0.1.6",
"version": "1.21.0-0.1.6-beta",
"description": "Asynchronous, persistent, key-value storage system for React Native.",
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
Expand Down