pi-para 0.7.7 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/node_modules/better-sqlite3/LICENSE +21 -0
  3. package/node_modules/better-sqlite3/README.md +99 -0
  4. package/node_modules/better-sqlite3/binding.gyp +60 -0
  5. package/node_modules/better-sqlite3/deps/common.gypi +68 -0
  6. package/node_modules/better-sqlite3/deps/copy.js +31 -0
  7. package/node_modules/better-sqlite3/deps/defines.gypi +42 -0
  8. package/node_modules/better-sqlite3/deps/download.sh +123 -0
  9. package/node_modules/better-sqlite3/deps/patches/1208.patch +15 -0
  10. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.c +269668 -0
  11. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.h +14349 -0
  12. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3ext.h +739 -0
  13. package/node_modules/better-sqlite3/deps/sqlite3.gyp +80 -0
  14. package/node_modules/better-sqlite3/deps/test_extension.c +21 -0
  15. package/node_modules/better-sqlite3/lib/binding.js +62 -0
  16. package/node_modules/better-sqlite3/lib/darwin-arm64.js +3 -0
  17. package/node_modules/better-sqlite3/lib/darwin-x64.js +3 -0
  18. package/node_modules/better-sqlite3/lib/database.js +109 -0
  19. package/node_modules/better-sqlite3/lib/index.js +3 -0
  20. package/node_modules/better-sqlite3/lib/linux-arm64.js +3 -0
  21. package/node_modules/better-sqlite3/lib/linux-x64.js +3 -0
  22. package/node_modules/better-sqlite3/lib/linuxmusl-arm64.js +4 -0
  23. package/node_modules/better-sqlite3/lib/linuxmusl-x64.js +4 -0
  24. package/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
  25. package/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
  26. package/node_modules/better-sqlite3/lib/methods/explain.js +9 -0
  27. package/node_modules/better-sqlite3/lib/methods/function.js +31 -0
  28. package/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
  29. package/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
  30. package/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
  31. package/node_modules/better-sqlite3/lib/methods/table.js +195 -0
  32. package/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
  33. package/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
  34. package/node_modules/better-sqlite3/lib/sqlite-error.js +25 -0
  35. package/node_modules/better-sqlite3/lib/util.js +12 -0
  36. package/node_modules/better-sqlite3/lib/win32-arm64.js +3 -0
  37. package/node_modules/better-sqlite3/lib/win32-x64.js +3 -0
  38. package/node_modules/better-sqlite3/package.json +67 -0
  39. package/node_modules/better-sqlite3/prebuilds/darwin-arm64.node +0 -0
  40. package/node_modules/better-sqlite3/prebuilds/darwin-x64.node +0 -0
  41. package/node_modules/better-sqlite3/prebuilds/linux-arm64.node +0 -0
  42. package/node_modules/better-sqlite3/prebuilds/linux-x64.node +0 -0
  43. package/node_modules/better-sqlite3/prebuilds/linuxmusl-arm64.node +0 -0
  44. package/node_modules/better-sqlite3/prebuilds/linuxmusl-x64.node +0 -0
  45. package/node_modules/better-sqlite3/prebuilds/win32-arm64.node +0 -0
  46. package/node_modules/better-sqlite3/prebuilds/win32-x64.node +0 -0
  47. package/node_modules/better-sqlite3/src/addon.cpp +59 -0
  48. package/node_modules/better-sqlite3/src/better_sqlite3.cpp +73 -0
  49. package/node_modules/better-sqlite3/src/objects/backup.cpp +121 -0
  50. package/node_modules/better-sqlite3/src/objects/backup.hpp +32 -0
  51. package/node_modules/better-sqlite3/src/objects/database.cpp +432 -0
  52. package/node_modules/better-sqlite3/src/objects/database.hpp +100 -0
  53. package/node_modules/better-sqlite3/src/objects/statement-iterator.cpp +119 -0
  54. package/node_modules/better-sqlite3/src/objects/statement-iterator.hpp +71 -0
  55. package/node_modules/better-sqlite3/src/objects/statement.cpp +380 -0
  56. package/node_modules/better-sqlite3/src/objects/statement.hpp +65 -0
  57. package/node_modules/better-sqlite3/src/util/bind-map.cpp +73 -0
  58. package/node_modules/better-sqlite3/src/util/binder.cpp +210 -0
  59. package/node_modules/better-sqlite3/src/util/constants.cpp +172 -0
  60. package/node_modules/better-sqlite3/src/util/custom-aggregate.cpp +121 -0
  61. package/node_modules/better-sqlite3/src/util/custom-function.cpp +59 -0
  62. package/node_modules/better-sqlite3/src/util/custom-table.cpp +406 -0
  63. package/node_modules/better-sqlite3/src/util/data-converter.cpp +17 -0
  64. package/node_modules/better-sqlite3/src/util/data.cpp +134 -0
  65. package/node_modules/better-sqlite3/src/util/helpers.cpp +190 -0
  66. package/node_modules/better-sqlite3/src/util/macros.cpp +74 -0
  67. package/node_modules/better-sqlite3/src/util/query-macros.cpp +71 -0
  68. package/node_modules/better-sqlite3/src/util/row-builder.cpp +53 -0
  69. package/node_modules/better-sqlite3/src/util/row-builder.hpp +22 -0
  70. package/node_modules/node-addon-api/LICENSE.md +9 -0
  71. package/node_modules/node-addon-api/README.md +95 -0
  72. package/node_modules/node-addon-api/common.gypi +21 -0
  73. package/node_modules/node-addon-api/except.gypi +25 -0
  74. package/node_modules/node-addon-api/index.js +14 -0
  75. package/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
  76. package/node_modules/node-addon-api/napi-inl.h +7165 -0
  77. package/node_modules/node-addon-api/napi.h +3364 -0
  78. package/node_modules/node-addon-api/node_addon_api.gyp +42 -0
  79. package/node_modules/node-addon-api/node_api.gyp +9 -0
  80. package/node_modules/node-addon-api/noexcept.gypi +26 -0
  81. package/node_modules/node-addon-api/nothing.c +0 -0
  82. package/node_modules/node-addon-api/package-support.json +21 -0
  83. package/node_modules/node-addon-api/package.json +480 -0
  84. package/node_modules/node-addon-api/tools/README.md +73 -0
  85. package/node_modules/node-addon-api/tools/check-napi.js +99 -0
  86. package/node_modules/node-addon-api/tools/clang-format.js +71 -0
  87. package/node_modules/node-addon-api/tools/conversion.js +301 -0
  88. package/package.json +6 -3
@@ -0,0 +1,190 @@
1
+ inline Napi::String StringFromUtf8(Napi::Env env, const char* data, int length) {
2
+ if (length < 0) return Napi::String::New(env, data);
3
+ return Napi::String::New(env, data, length);
4
+ }
5
+
6
+ // Node-API has no equivalent of V8's internalized strings, so these are simple
7
+ // aliases of StringFromUtf8; the names are kept to preserve the intent of call
8
+ // sites (strings that are used repeatedly as property keys). If Node-API ever
9
+ // gains this functionality, we can easily restore it here.
10
+ inline Napi::String InternalizedFromUtf8(Napi::Env env, const char* data, int length) {
11
+ return StringFromUtf8(env, data, length);
12
+ }
13
+
14
+ inline Napi::Value InternalizedFromUtf8OrNull(Napi::Env env, const char* data, int length) {
15
+ if (data == NULL) return env.Null();
16
+ return InternalizedFromUtf8(env, data, length);
17
+ }
18
+
19
+ inline Napi::String InternalizedFromLatin1(Napi::Env env, const char* str) {
20
+ return Napi::String::New(env, str);
21
+ }
22
+
23
+ // Replicates the semantics of v8::Value::IsInt32() (an integral number within
24
+ // the range of a 32-bit signed integer, excluding -0), which has no direct
25
+ // Node-API equivalent.
26
+ inline bool IsInt32(Napi::Value value) {
27
+ if (!value.IsNumber()) return false;
28
+ double num = value.As<Napi::Number>().DoubleValue();
29
+ if (!(num >= INT_MIN && num <= INT_MAX)) return false;
30
+ if (num == 0) return !std::signbit(num);
31
+ return static_cast<double>(static_cast<int32_t>(num)) == num;
32
+ }
33
+
34
+ inline void SetFrozen(Napi::Env env, Napi::Object obj, const Napi::Reference<Napi::String>& key, Napi::Value value) {
35
+ obj.DefineProperty(Napi::PropertyDescriptor::Value(key.Value(), value, napi_enumerable));
36
+ }
37
+
38
+ // The following helpers perform JavaScript operations that can execute
39
+ // arbitrary user code (functions, proxies, getters). If the user code throws,
40
+ // the exception is left pending in the environment and an empty value is
41
+ // returned. The node-addon-api equivalents (Napi::Function::Call,
42
+ // Napi::Object::Get, etc.) must NOT be used for such operations, because their
43
+ // failure paths re-throw the pending exception through Napi::Error, which
44
+ // aborts the process when the thrown value is null or undefined (a
45
+ // node-addon-api bug, present as of v8.9.0, triggered by Node-API version 10).
46
+
47
+ inline Napi::Value SafeCall(Napi::Env env, Napi::Function fn, napi_value recv, size_t argc, const napi_value* args) {
48
+ napi_value result;
49
+ if (napi_call_function(env, recv, fn, argc, args, &result) != napi_ok) return Napi::Value();
50
+ return Napi::Value(env, result);
51
+ }
52
+
53
+ inline Napi::Object SafeConstruct(Napi::Env env, Napi::Function constructor) {
54
+ napi_value result;
55
+ if (napi_new_instance(env, constructor, 0, NULL, &result) != napi_ok) return Napi::Object();
56
+ return Napi::Object(env, result);
57
+ }
58
+
59
+ inline Napi::Value SafeGet(Napi::Env env, Napi::Object obj, napi_value key) {
60
+ napi_value result;
61
+ if (napi_get_property(env, obj, key, &result) != napi_ok) return Napi::Value();
62
+ return Napi::Value(env, result);
63
+ }
64
+
65
+ inline Napi::Value SafeGetElement(Napi::Env env, Napi::Object obj, uint32_t index) {
66
+ napi_value result;
67
+ if (napi_get_element(env, obj, index, &result) != napi_ok) return Napi::Value();
68
+ return Napi::Value(env, result);
69
+ }
70
+
71
+ // Returns false if the check itself failed (leaving an exception pending).
72
+ inline bool SafeHasOwnProperty(Napi::Env env, Napi::Object obj, napi_value key, bool* result) {
73
+ return napi_has_own_property(env, obj, key, result) == napi_ok;
74
+ }
75
+
76
+ Napi::Value ThrowError(Napi::Env env, const char* message) {
77
+ Napi::Error::New(env, message).ThrowAsJavaScriptException();
78
+ return env.Undefined();
79
+ }
80
+ Napi::Value ThrowTypeError(Napi::Env env, const char* message) {
81
+ Napi::TypeError::New(env, message).ThrowAsJavaScriptException();
82
+ return env.Undefined();
83
+ }
84
+ Napi::Value ThrowRangeError(Napi::Env env, const char* message) {
85
+ Napi::RangeError::New(env, message).ThrowAsJavaScriptException();
86
+ return env.Undefined();
87
+ }
88
+
89
+ // Unwraps a native-backed object into its associated C++ instance. This must
90
+ // only be used on values that are already known to be backed by the given
91
+ // class (e.g., a receiver that was validated by TypeSafeCallback below, or a
92
+ // value produced by our own code), because napi_unwrap does not check the
93
+ // object's type. Returns NULL if the environment can no longer run JavaScript
94
+ // (e.g., worker.terminate()), so callers should use UNWRAP_OR_RETURN, which
95
+ // checks for that case.
96
+ template <typename T> inline T* Unwrap(Napi::Value value) {
97
+ return T::Unwrap(value.As<Napi::Object>());
98
+ }
99
+
100
+ // Generates a random type tag when the addon is loaded. Type tags must not be
101
+ // hardcoded, because multiple copies (or even different versions) of the addon
102
+ // can be loaded into a single process (see the "nativeBinding" option), and
103
+ // objects created by one copy must not be accepted by another copy's methods,
104
+ // whose class layouts may differ.
105
+ inline napi_type_tag RandomTypeTag() {
106
+ std::random_device rd;
107
+ auto random64 = [&rd]() {
108
+ return (static_cast<uint64_t>(rd()) << 32) | static_cast<uint64_t>(rd());
109
+ };
110
+ return { random64(), random64() };
111
+ }
112
+
113
+ // Determines whether the given value is an object that is backed by the given
114
+ // native class. Each native class is identified by a unique type tag, which
115
+ // gets applied to each of its instances upon construction.
116
+ template <typename T> inline bool IsInstanceOf(Napi::Env env, Napi::Value value) {
117
+ bool result = false;
118
+ napi_status status = napi_check_object_type_tag(env, value.As<Napi::Object>(), &T::TYPE_TAG, &result);
119
+ return status == napi_ok && result;
120
+ }
121
+
122
+ // Wraps a native method so that it can only be invoked on a receiver that is
123
+ // backed by the expected native class. Node-API has no equivalent of
124
+ // v8::Signature, and napi_unwrap alone does not check the object's type, so
125
+ // without this check, a method borrowed onto a foreign wrapped object (e.g.,
126
+ // db.exec.call(stmt)) would reinterpret the wrapped pointer as the wrong type.
127
+ template <typename T, Napi::Value (*method)(const Napi::CallbackInfo&)>
128
+ napi_value TypeSafeCallback(napi_env env, napi_callback_info info) {
129
+ Napi::CallbackInfo cbinfo(env, info);
130
+ if (!IsInstanceOf<T>(env, cbinfo.This())) {
131
+ Napi::TypeError::New(env, "Illegal invocation").ThrowAsJavaScriptException();
132
+ return NULL;
133
+ }
134
+ return method(cbinfo);
135
+ }
136
+
137
+ // These match the default attributes of properties created by a V8 template.
138
+ constexpr napi_property_attributes DEFAULT_ATTRIBUTES =
139
+ static_cast<napi_property_attributes>(napi_writable | napi_enumerable | napi_configurable);
140
+
141
+ template <typename T, Napi::Value (*method)(const Napi::CallbackInfo&)>
142
+ napi_property_descriptor PrototypeMethod(const char* name, Addon* addon) {
143
+ napi_property_descriptor desc = {};
144
+ desc.utf8name = name;
145
+ desc.method = TypeSafeCallback<T, method>;
146
+ desc.attributes = DEFAULT_ATTRIBUTES;
147
+ desc.data = addon;
148
+ return desc;
149
+ }
150
+
151
+ template <typename T, Napi::Value (*method)(const Napi::CallbackInfo&)>
152
+ napi_property_descriptor PrototypeSymbolMethod(Napi::Symbol symbol, Addon* addon) {
153
+ napi_property_descriptor desc = {};
154
+ desc.name = symbol;
155
+ desc.method = TypeSafeCallback<T, method>;
156
+ desc.attributes = DEFAULT_ATTRIBUTES;
157
+ desc.data = addon;
158
+ return desc;
159
+ }
160
+
161
+ // Defines a getter as an own property of the given object. V8 exposed these
162
+ // getters as native data properties on each instance, which made them visible
163
+ // to console.log(); Node-API has no native data properties, so an own accessor
164
+ // property is the closest equivalent (unlike a prototype accessor, it is still
165
+ // displayed by console.log(), albeit as [Getter]).
166
+ template <typename T, Napi::Value (*method)(const Napi::CallbackInfo&)>
167
+ void SetInstanceGetter(Napi::Object obj, const char* name, Addon* addon) {
168
+ napi_property_descriptor desc = {};
169
+ desc.utf8name = name;
170
+ desc.getter = TypeSafeCallback<T, method>;
171
+ desc.attributes = napi_enumerable;
172
+ desc.data = addon;
173
+ napi_status status = napi_define_properties(obj.Env(), obj, 1, &desc);
174
+ assert(status == napi_ok || status == napi_cannot_run_js); ((void)status);
175
+ }
176
+
177
+ // Determines whether to skip the given character at the start of an SQL string.
178
+ inline bool IS_SKIPPED(char c) {
179
+ return c == ' ' || c == ';' || (c >= '\t' && c <= '\r');
180
+ }
181
+
182
+ // Allocates an empty array, without calling constructors/initializers.
183
+ template<class T> inline T* ALLOC_ARRAY(size_t count) {
184
+ return static_cast<T*>(::operator new[](count * sizeof(T)));
185
+ }
186
+
187
+ // Deallocates an array, without calling destructors.
188
+ template<class T> inline void FREE_ARRAY(T* array_pointer) {
189
+ ::operator delete[](array_pointer);
190
+ }
@@ -0,0 +1,74 @@
1
+ #define NODE_ARGUMENTS const Napi::CallbackInfo&
2
+ #define NODE_ARGUMENTS_POINTER const Napi::CallbackInfo*
3
+ #define NODE_METHOD(name) Napi::Value name(const Napi::CallbackInfo& info)
4
+ #define NODE_GETTER(name) Napi::Value name(const Napi::CallbackInfo& info)
5
+ #define INIT(name) Napi::Function name(Napi::Env env, Addon* addon)
6
+
7
+ #define OnlyAddon (static_cast<Addon*>(info.Data()))
8
+ #define UseIsolate Napi::Env env = info.Env()
9
+ #define UseAddon Addon* addon = static_cast<Addon*>(info.Data())
10
+
11
+ // Type-tag an object, but bail if the thread is terminating, to avoid
12
+ // undesirable side-effects in the subsequent JS_new call (e.g, sqlite3_open()).
13
+ #define TYPE_TAG_CONSTRUCTOR(info) \
14
+ napi_status status = \
15
+ napi_type_tag_object((info).Env(), (info).This(), &TYPE_TAG); \
16
+ assert(status == napi_ok || status == napi_cannot_run_js); \
17
+ if (status != napi_ok) return
18
+
19
+ // Unwrap a native-backed object (see ::Unwrap in helpers.cpp), but bail if the
20
+ // the unwrap fails (which should only happen if the thread is terminating).
21
+ #define UNWRAP_OR_RETURN(T, var, value) \
22
+ T* var = ::Unwrap<T>(value); \
23
+ if (var == NULL) return info.Env().Undefined()
24
+
25
+ #define REQUIRE_ARGUMENT_ANY(at, var) \
26
+ if (info.Length() <= (at())) \
27
+ return ThrowTypeError(info.Env(), "Expected a "#at" argument"); \
28
+ var = info[at()]
29
+
30
+ #define _REQUIRE_ARGUMENT(at, var, Type, message, ...) \
31
+ if (info.Length() <= (at()) || !info[at()].Is##Type()) \
32
+ return ThrowTypeError(info.Env(), "Expected "#at" argument to be "#message); \
33
+ var = (info[at()].As<Napi::Type>())__VA_ARGS__
34
+
35
+ #define REQUIRE_ARGUMENT_INT32(at, var) \
36
+ if (info.Length() <= (at()) || !IsInt32(info[at()])) \
37
+ return ThrowTypeError(info.Env(), "Expected "#at" argument to be a 32-bit signed integer"); \
38
+ var = info[at()].As<Napi::Number>().Int32Value()
39
+ #define REQUIRE_ARGUMENT_BOOLEAN(at, var) \
40
+ _REQUIRE_ARGUMENT(at, var, Boolean, a boolean, .Value())
41
+ #define REQUIRE_ARGUMENT_STRING(at, var) \
42
+ _REQUIRE_ARGUMENT(at, var, String, a string)
43
+ #define REQUIRE_ARGUMENT_OBJECT(at, var) \
44
+ _REQUIRE_ARGUMENT(at, var, Object, an object)
45
+ #define REQUIRE_ARGUMENT_FUNCTION(at, var) \
46
+ _REQUIRE_ARGUMENT(at, var, Function, a function)
47
+
48
+ #define REQUIRE_DATABASE_OPEN(db) \
49
+ if (!db->open) \
50
+ return ThrowTypeError(info.Env(), "The database connection is not open")
51
+ #define REQUIRE_DATABASE_NOT_BUSY(db) \
52
+ if (db->busy) \
53
+ return ThrowTypeError(info.Env(), "This database connection is busy executing a query")
54
+ #define REQUIRE_DATABASE_NO_ITERATORS(db) \
55
+ if (db->iterators) \
56
+ return ThrowTypeError(info.Env(), "This database connection is busy executing a query")
57
+ #define REQUIRE_DATABASE_NO_ITERATORS_UNLESS_UNSAFE(db) \
58
+ if (!db->unsafe_mode) { \
59
+ REQUIRE_DATABASE_NO_ITERATORS(db); \
60
+ } ((void)0)
61
+ #define REQUIRE_STATEMENT_NOT_LOCKED(stmt) \
62
+ if (stmt->locked) \
63
+ return ThrowTypeError(info.Env(), "This statement is busy executing a query")
64
+
65
+ #define first() 0
66
+ #define second() 1
67
+ #define third() 2
68
+ #define fourth() 3
69
+ #define fifth() 4
70
+ #define sixth() 5
71
+ #define seventh() 6
72
+ #define eighth() 7
73
+ #define ninth() 8
74
+ #define tenth() 9
@@ -0,0 +1,71 @@
1
+ #define STATEMENT_BIND(handle) \
2
+ Binder binder(handle); \
3
+ if (!binder.Bind(info, info.Length(), stmt)) { \
4
+ sqlite3_clear_bindings(handle); \
5
+ return info.Env().Undefined(); \
6
+ } ((void)0)
7
+
8
+ #define STATEMENT_THROW_LOGIC() \
9
+ db->ThrowDatabaseError(env); \
10
+ if (!bound) { sqlite3_clear_bindings(handle); } \
11
+ return env.Undefined()
12
+
13
+ #define STATEMENT_RETURN_LOGIC(return_value) \
14
+ Napi::Value _return_value = (return_value); \
15
+ if (!bound) { sqlite3_clear_bindings(handle); } \
16
+ return _return_value
17
+
18
+ #define STATEMENT_START_LOGIC(RETURNS_DATA_CHECK, MUTATE_CHECK) \
19
+ UNWRAP_OR_RETURN(Statement, stmt, info.This()); \
20
+ RETURNS_DATA_CHECK(); \
21
+ sqlite3_stmt* handle = stmt->handle; \
22
+ Database* db = stmt->db; \
23
+ REQUIRE_DATABASE_OPEN(db->GetState()); \
24
+ REQUIRE_DATABASE_NOT_BUSY(db->GetState()); \
25
+ MUTATE_CHECK(); \
26
+ const bool bound = stmt->bound; \
27
+ if (!bound) { \
28
+ STATEMENT_BIND(handle); \
29
+ } else if (info.Length() > 0) { \
30
+ return ThrowTypeError(info.Env(), "This statement already has bound parameters"); \
31
+ } ((void)0)
32
+
33
+
34
+ #define STATEMENT_THROW() db->GetState()->busy = false; STATEMENT_THROW_LOGIC()
35
+ #define STATEMENT_RETURN(x) db->GetState()->busy = false; STATEMENT_RETURN_LOGIC(x)
36
+ #define STATEMENT_START(x, y) \
37
+ STATEMENT_START_LOGIC(x, y); \
38
+ db->GetState()->busy = true; \
39
+ UseIsolate; \
40
+ if (db->Log(env, handle)) { \
41
+ STATEMENT_THROW(); \
42
+ } ((void)0)
43
+
44
+
45
+ #define DOES_NOT_MUTATE() REQUIRE_STATEMENT_NOT_LOCKED(stmt)
46
+ #define DOES_MUTATE() \
47
+ REQUIRE_STATEMENT_NOT_LOCKED(stmt); \
48
+ REQUIRE_DATABASE_NO_ITERATORS_UNLESS_UNSAFE(db->GetState())
49
+ #define DOES_ADD_ITERATOR() \
50
+ DOES_NOT_MUTATE(); \
51
+ if (db->GetState()->iterators == USHRT_MAX) \
52
+ return ThrowRangeError(info.Env(), "Too many active database iterators")
53
+ #define REQUIRE_STATEMENT_RETURNS_DATA() \
54
+ if (!stmt->returns_data) \
55
+ return ThrowTypeError(info.Env(), "This statement does not return data. Use run() instead")
56
+ #define ALLOW_ANY_STATEMENT() \
57
+ ((void)0)
58
+
59
+
60
+ #define _FUNCTION_START(type) \
61
+ type* self = static_cast<type*>(sqlite3_user_data(invocation)); \
62
+ Napi::Env env = self->env; \
63
+ Napi::HandleScope scope(env)
64
+
65
+ #define FUNCTION_START() \
66
+ _FUNCTION_START(CustomFunction)
67
+
68
+ #define AGGREGATE_START() \
69
+ _FUNCTION_START(CustomAggregate); \
70
+ Accumulator* acc = self->GetAccumulator(invocation); \
71
+ if (acc->value.IsEmpty()) return
@@ -0,0 +1,53 @@
1
+ RowBuilder::RowBuilder(
2
+ Napi::Env env,
3
+ Napi::Function row_factory,
4
+ Napi::Function array_factory
5
+ ) :
6
+ row_factory(Napi::Persistent(row_factory)),
7
+ array_factory(Napi::Persistent(array_factory)),
8
+ column_count(-1),
9
+ reprepare_count(-1) {}
10
+
11
+ Napi::Value RowBuilder::GetRowJS(Napi::Env env, sqlite3_stmt* handle, bool safe_ints) {
12
+ int current_reprepare_count = sqlite3_stmt_status(handle, SQLITE_STMTSTATUS_REPREPARE, false);
13
+ if (current_reprepare_count != reprepare_count) {
14
+ column_count = sqlite3_column_count(handle);
15
+ std::vector<napi_value> keys(column_count);
16
+ for (int i = 0; i < column_count; ++i) {
17
+ keys[i] = InternalizedFromUtf8(env, sqlite3_column_name(handle, i), -1);
18
+ }
19
+ create_row = Napi::Persistent(
20
+ SafeCall(env, row_factory.Value(), env.Undefined(), column_count, keys.data())
21
+ .As<Napi::Function>()
22
+ );
23
+ reprepare_count = current_reprepare_count;
24
+ }
25
+
26
+ napi_value value_storage[16];
27
+ std::vector<napi_value> extra_values;
28
+ napi_value* values = value_storage;
29
+ if (column_count > 16) {
30
+ extra_values.resize(column_count);
31
+ values = extra_values.data();
32
+ }
33
+ for (int i = 0; i < column_count; ++i) {
34
+ values[i] = Data::GetValueJS(env, handle, i, safe_ints);
35
+ }
36
+
37
+ return SafeCall(env, create_row.Value(), env.Undefined(), column_count, values);
38
+ }
39
+
40
+ Napi::Value RowBuilder::GetRawRowJS(Napi::Env env, sqlite3_stmt* handle, bool safe_ints) {
41
+ column_count = sqlite3_column_count(handle);
42
+ napi_value arg_storage[16];
43
+ std::vector<napi_value> extra_args;
44
+ napi_value* args = arg_storage;
45
+ if (column_count > 16) {
46
+ extra_args.resize(column_count);
47
+ args = extra_args.data();
48
+ }
49
+ for (int i = 0; i < column_count; ++i) {
50
+ args[i] = Data::GetValueJS(env, handle, i, safe_ints);
51
+ }
52
+ return SafeCall(env, array_factory.Value(), env.Undefined(), column_count, args);
53
+ }
@@ -0,0 +1,22 @@
1
+ // Builds row objects efficiently by utilizing a factory function in JS land.
2
+ // The column names are initialized only once and reused for every row/query.
3
+ // The cache is rebuilt if SQLite reparses the statement after a schema change.
4
+ class RowBuilder {
5
+ public:
6
+
7
+ explicit RowBuilder(
8
+ Napi::Env env,
9
+ Napi::Function row_factory,
10
+ Napi::Function array_factory
11
+ );
12
+
13
+ Napi::Value GetRowJS(Napi::Env env, sqlite3_stmt* handle, bool safe_ints);
14
+ Napi::Value GetRawRowJS(Napi::Env env, sqlite3_stmt* handle, bool safe_ints);
15
+
16
+ private:
17
+ Napi::FunctionReference row_factory;
18
+ Napi::FunctionReference create_row;
19
+ Napi::FunctionReference array_factory;
20
+ int column_count;
21
+ int reprepare_count;
22
+ };
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 [Node.js API collaborators](https://github.com/nodejs/node-addon-api#collaborators)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,95 @@
1
+ # **node-addon-api module**
2
+
3
+ [![codecov](https://codecov.io/gh/nodejs/node-addon-api/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nodejs/node-addon-api/tree/main)
4
+
5
+ [![NPM](https://nodei.co/npm/node-addon-api.png?downloads=true&downloadRank=true)](https://nodei.co/npm/node-addon-api/) [![NPM](https://nodei.co/npm-dl/node-addon-api.png?months=6&height=1)](https://nodei.co/npm/node-addon-api/)
6
+
7
+ This module contains **header-only C++ wrapper classes** which simplify
8
+ the use of the C based [Node-API](https://nodejs.org/dist/latest/docs/api/n-api.html)
9
+ provided by Node.js when using C++. It provides a C++ object model
10
+ and exception handling semantics with low overhead.
11
+
12
+ - [API References](doc/README.md)
13
+ - [Badges](#badges)
14
+ - [Contributing](#contributing)
15
+ - [License](#license)
16
+
17
+ ## API References
18
+
19
+ API references are available in the [doc](doc/README.md) directory.
20
+
21
+ <!-- x-release-please-start-version -->
22
+ ## Current version: 8.7.0
23
+ <!-- x-release-please-end -->
24
+
25
+ (See [CHANGELOG.md](CHANGELOG.md) for complete Changelog)
26
+
27
+ node-addon-api is based on [Node-API](https://nodejs.org/api/n-api.html) and supports using different Node-API versions.
28
+ This allows addons built with it to run with Node.js versions which support the targeted Node-API version.
29
+ **However** the node-addon-api support model is to support only the active LTS Node.js versions. This means that
30
+ every year there will be a new major which drops support for the Node.js LTS version which has gone out of service.
31
+
32
+ The oldest Node.js version supported by the current version of node-addon-api is Node.js 18.x.
33
+
34
+ ## Badges
35
+
36
+ The use of badges is recommended to indicate the minimum version of Node-API
37
+ required for the module. This helps to determine which Node.js major versions are
38
+ supported. Addon maintainers can consult the [Node-API support matrix][] to determine
39
+ which Node.js versions provide a given Node-API version. The following badges are
40
+ available:
41
+
42
+ ![Node-API v1 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v1%20Badge.svg)
43
+ ![Node-API v2 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v2%20Badge.svg)
44
+ ![Node-API v3 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v3%20Badge.svg)
45
+ ![Node-API v4 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v4%20Badge.svg)
46
+ ![Node-API v5 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v5%20Badge.svg)
47
+ ![Node-API v6 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v6%20Badge.svg)
48
+ ![Node-API v7 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v7%20Badge.svg)
49
+ ![Node-API v8 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v8%20Badge.svg)
50
+ ![Node-API v9 Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20v9%20Badge.svg)
51
+ ![Node-API Experimental Version Badge](https://github.com/nodejs/abi-stable-node/blob/doc/assets/Node-API%20Experimental%20Version%20Badge.svg)
52
+
53
+ ## Contributing
54
+
55
+ We love contributions from the community to **node-addon-api**!
56
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on our philosophy around extending this module.
57
+
58
+ ## Team members
59
+
60
+ ### Active
61
+
62
+ | Name | GitHub Link |
63
+ | ------------------- | ----------------------------------------------------- |
64
+ | Anna Henningsen | [addaleax](https://github.com/addaleax) |
65
+ | Chengzhong Wu | [legendecas](https://github.com/legendecas) |
66
+ | Jack Xia | [JckXia](https://github.com/JckXia) |
67
+ | Kevin Eady | [KevinEady](https://github.com/KevinEady) |
68
+ | Michael Dawson | [mhdawson](https://github.com/mhdawson) |
69
+ | Nicola Del Gobbo | [NickNaso](https://github.com/NickNaso) |
70
+ | Vladimir Morozov | [vmoroz](https://github.com/vmoroz) |
71
+
72
+ <details>
73
+
74
+ <summary>Emeritus</summary>
75
+
76
+ ### Emeritus
77
+
78
+ | Name | GitHub Link |
79
+ | ------------------- | ----------------------------------------------------- |
80
+ | Arunesh Chandra | [aruneshchandra](https://github.com/aruneshchandra) |
81
+ | Benjamin Byholm | [kkoopa](https://github.com/kkoopa) |
82
+ | Gabriel Schulhof | [gabrielschulhof](https://github.com/gabrielschulhof) |
83
+ | Hitesh Kanwathirtha | [digitalinfinity](https://github.com/digitalinfinity) |
84
+ | Jason Ginchereau | [jasongin](https://github.com/jasongin) |
85
+ | Jim Schlight | [jschlight](https://github.com/jschlight) |
86
+ | Sampson Gao | [sampsongao](https://github.com/sampsongao) |
87
+ | Taylor Woll | [boingoing](https://github.com/boingoing) |
88
+
89
+ </details>
90
+
91
+ ## License
92
+
93
+ Licensed under [MIT](./LICENSE.md)
94
+
95
+ [Node-API support matrix]: https://nodejs.org/dist/latest/docs/api/n-api.html#node-api-version-matrix
@@ -0,0 +1,21 @@
1
+ {
2
+ 'variables': {
3
+ 'NAPI_VERSION%': "<!(node -p \"process.env.NAPI_VERSION || process.versions.napi\")",
4
+ 'disable_deprecated': "<!(node -p \"process.env['npm_config_disable_deprecated']\")"
5
+ },
6
+ 'conditions': [
7
+ ['NAPI_VERSION!=""', { 'defines': ['NAPI_VERSION=<@(NAPI_VERSION)'] } ],
8
+ ['NAPI_VERSION==2147483647', { 'defines': ['NAPI_EXPERIMENTAL', 'NODE_API_EXPERIMENTAL_NO_WARNING'] } ],
9
+ ['disable_deprecated=="true"', {
10
+ 'defines': ['NODE_ADDON_API_DISABLE_DEPRECATED']
11
+ }],
12
+ ['OS=="mac"', {
13
+ 'cflags+': ['-fvisibility=hidden'],
14
+ 'xcode_settings': {
15
+ 'OTHER_CFLAGS': ['-fvisibility=hidden']
16
+ }
17
+ }]
18
+ ],
19
+ 'cflags': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ],
20
+ 'cflags_cc': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ]
21
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ 'defines': [ 'NAPI_CPP_EXCEPTIONS' ],
3
+ 'cflags!': [ '-fno-exceptions' ],
4
+ 'cflags_cc!': [ '-fno-exceptions' ],
5
+ 'conditions': [
6
+ ["OS=='win'", {
7
+ "defines": [
8
+ "_HAS_EXCEPTIONS=1"
9
+ ],
10
+ "msvs_settings": {
11
+ "VCCLCompilerTool": {
12
+ "ExceptionHandling": 1,
13
+ 'EnablePREfast': 'true',
14
+ },
15
+ },
16
+ }],
17
+ ["OS=='mac'", {
18
+ 'xcode_settings': {
19
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
20
+ 'CLANG_CXX_LIBRARY': 'libc++',
21
+ 'MACOSX_DEPLOYMENT_TARGET': '10.7',
22
+ },
23
+ }],
24
+ ],
25
+ }
@@ -0,0 +1,14 @@
1
+ const path = require('path');
2
+ const { version } = require('./package.json');
3
+
4
+ const includeDir = path.relative('.', __dirname);
5
+
6
+ module.exports = {
7
+ include: `"${__dirname}"`, // deprecated, can be removed as part of 4.0.0
8
+ include_dir: includeDir,
9
+ gyp: path.join(includeDir, 'node_api.gyp:nothing'), // deprecated.
10
+ targets: path.join(includeDir, 'node_addon_api.gyp'),
11
+ version,
12
+ isNodeApiBuiltin: true,
13
+ needsFlag: false
14
+ };