1 /*
2 * Copyright (c) 2024 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 #include "napi_gdb_const_properties.h"
17
18 #include "gdb_common.h"
19 #include "gdb_store.h"
20 #include "js_utils.h"
21
22 namespace OHOS::GraphStoreJsKit {
23 using namespace AppDataMgrJsKit;
24 using namespace DistributedDataAip;
25 #define SET_NAPI_PROPERTY(object, prop, value) \
26 napi_set_named_property((env), (object), (prop), JSUtils::Convert2JSValue((env), (value)))
27
ExportSecurityLevel(napi_env env)28 static napi_value ExportSecurityLevel(napi_env env)
29 {
30 napi_value securityLevel = nullptr;
31 napi_create_object(env, &securityLevel);
32
33 SET_NAPI_PROPERTY(securityLevel, "S1", 1);
34 SET_NAPI_PROPERTY(securityLevel, "S2", 2);
35 SET_NAPI_PROPERTY(securityLevel, "S3", 3);
36 SET_NAPI_PROPERTY(securityLevel, "S4", 4);
37
38 napi_object_freeze(env, securityLevel);
39 return securityLevel;
40 }
41
InitConstProperties(napi_env env,napi_value exports)42 napi_status InitConstProperties(napi_env env, napi_value exports)
43 {
44 const napi_property_descriptor properties[] = {
45 DECLARE_NAPI_PROPERTY("SecurityLevel", ExportSecurityLevel(env)),
46 };
47
48 size_t count = sizeof(properties) / sizeof(properties[0]);
49 return napi_define_properties(env, exports, count, properties);
50 }
51 } // namespace OHOS::GraphStoreJsKit