• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define LOG_TAG "NapiConstProperties"
17 
18 #include "napi_const_properties.h"
19 
20 #include "js_utils.h"
21 #include "napi_error_utils.h"
22 #include "napi_utils.h"
23 #include "rd_type.h"
24 
25 namespace OHOS::CollaborationEdit {
ExportSyncMode(napi_env env)26 static napi_value ExportSyncMode(napi_env env)
27 {
28     napi_value syncMode = nullptr;
29     napi_status status = napi_create_object(env, &syncMode);
30     ASSERT(status == napi_ok, "create syncMode object go wrong.", nullptr);
31     napi_set_named_property(env, syncMode, "SYNC_MODE_PUSH",
32         JSUtils::Convert2JSValue(env, static_cast<int32_t>(SyncMode::PUSH)));
33     napi_set_named_property(env, syncMode, "SYNC_MODE_PULL",
34         JSUtils::Convert2JSValue(env, static_cast<int32_t>(SyncMode::PULL)));
35     napi_set_named_property(env, syncMode, "SYNC_MODE_PULL_PUSH",
36         JSUtils::Convert2JSValue(env, static_cast<int32_t>(SyncMode::PULL_PUSH)));
37     napi_object_freeze(env, syncMode);
38     return syncMode;
39 }
40 
ExportPredicate(napi_env env)41 static napi_value ExportPredicate(napi_env env)
42 {
43     napi_value predicate = nullptr;
44     napi_status status = napi_create_object(env, &predicate);
45     ASSERT(status == napi_ok, "create predicate object go wrong.", nullptr);
46     napi_set_named_property(env, predicate, "EQUAL_TO",
47         JSUtils::Convert2JSValue(env, static_cast<int32_t>(Predicate::EQUAL_TO)));
48     napi_set_named_property(env, predicate, "NOT_EQUAL_TO",
49         JSUtils::Convert2JSValue(env, static_cast<int32_t>(Predicate::NOT_EQUAL_TO)));
50     napi_set_named_property(env, predicate, "GREATER_THAN",
51         JSUtils::Convert2JSValue(env, static_cast<int32_t>(Predicate::GREATER_THAN)));
52     napi_set_named_property(env, predicate, "LESS_THAN",
53         JSUtils::Convert2JSValue(env, static_cast<int32_t>(Predicate::LESS_THAN)));
54     napi_set_named_property(env, predicate, "GREATER_THAN_OR_EQUAL_TO",
55         JSUtils::Convert2JSValue(env, static_cast<int32_t>(Predicate::GREATER_THAN_OR_EQUAL_TO)));
56     napi_set_named_property(env, predicate, "GREATER_THAN_OR_EQUAL_TO",
57         JSUtils::Convert2JSValue(env, static_cast<int32_t>(Predicate::LESS_THAN_OR_EQUAL_TO)));
58     napi_object_freeze(env, predicate);
59     return predicate;
60 }
61 
ExportProgressCode(napi_env env)62 static napi_value ExportProgressCode(napi_env env)
63 {
64     napi_value progressCode = nullptr;
65     napi_status status = napi_create_object(env, &progressCode);
66     ASSERT(status == napi_ok, "create progressCode object go wrong.", nullptr);
67     napi_set_named_property(env, progressCode, "CLOUD_SYNC_SUCCESS",
68         JSUtils::Convert2JSValue(env, static_cast<int32_t>(ProgressCode::CLOUD_SYNC_SUCCESS)));
69     napi_set_named_property(env, progressCode, "CLOUD_NOT_SET",
70         JSUtils::Convert2JSValue(env, static_cast<int32_t>(ProgressCode::CLOUD_NOT_SET)));
71     napi_set_named_property(env, progressCode, "INTERNAL_ERROR",
72         JSUtils::Convert2JSValue(env, static_cast<int32_t>(ProgressCode::SYNC_INTERNAL_ERROR)));
73     napi_set_named_property(env, progressCode, "EXTERNAL_ERROR",
74         JSUtils::Convert2JSValue(env, static_cast<int32_t>(ProgressCode::SYNC_EXTERNAL_ERROR)));
75     napi_object_freeze(env, progressCode);
76     return progressCode;
77 }
78 
InitConstProperties(napi_env env,napi_value exports)79 napi_status InitConstProperties(napi_env env, napi_value exports)
80 {
81     const napi_property_descriptor properties[] = {
82         DECLARE_NAPI_PROPERTY("SyncMode", ExportSyncMode(env)),
83         DECLARE_NAPI_PROPERTY("Predicate", ExportPredicate(env)),
84         DECLARE_NAPI_PROPERTY("ProgressCode", ExportProgressCode(env)),
85     };
86 
87     size_t count = sizeof(properties) / sizeof(properties[0]);
88     return napi_define_properties(env, exports, count, properties);
89 }
90 } // namespace OHOS::CollaborationEdit
91