1 /* 2 * Copyright (c) 2022 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 #ifndef OHOS_SCHEMA_H 16 #define OHOS_SCHEMA_H 17 #include <string> 18 19 #include "js_util.h" 20 #include "js_field_node.h" 21 #include "napi_queue.h" 22 23 namespace OHOS::DistributedData { 24 class JsSchema { 25 public: 26 explicit JsSchema(napi_env env); 27 ~JsSchema(); 28 29 static napi_value Constructor(napi_env env); 30 31 static napi_value New(napi_env env, napi_callback_info info); 32 33 static napi_status ToJson(napi_env env, napi_value inner, JsSchema*& out); 34 std::string Dump(); 35 private: 36 static napi_value GetRootNode(napi_env env, napi_callback_info info); 37 static napi_value SetRootNode(napi_env env, napi_callback_info info); 38 static napi_value GetMode(napi_env env, napi_callback_info info); 39 static napi_value SetMode(napi_env env, napi_callback_info info); 40 static napi_value GetSkip(napi_env env, napi_callback_info info); 41 static napi_value SetSkip(napi_env env, napi_callback_info info); 42 static napi_value GetIndexes(napi_env env, napi_callback_info info); 43 static napi_value SetIndexes(napi_env env, napi_callback_info info); 44 45 template <typename T> 46 static napi_value GetContextValue(napi_env env, std::shared_ptr<ContextBase>& ctxt, T &value); 47 static JsSchema* GetSchema(napi_env env, napi_callback_info info, std::shared_ptr<ContextBase> &ctxt); 48 49 enum { 50 SCHEMA_MODE_SLOPPY, 51 SCHEMA_MODE_STRICT, 52 }; 53 JsFieldNode* rootNode_ = nullptr; 54 napi_env env_ = nullptr; // manage the root. set/get. 55 napi_ref ref_ = nullptr; // manage the root. set/get. 56 57 std::vector<std::string> indexes_; 58 uint32_t mode_ = SCHEMA_MODE_SLOPPY; 59 uint32_t skip_ = 0; 60 }; 61 } // namespace OHOS::DistributedData 62 #endif // OHOS_SCHEMA_H 63