node-firebird-native-api 3.1.0 → 3.1.3
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.
- package/README.md +8 -6
- package/dist/generate-files/index.js +2 -1
- package/dist/generate-files/index.js.map +1 -1
- package/dist/generate-files/patch.js +31 -94
- package/dist/generate-files/patch.js.map +1 -1
- package/dist/lib/cloop-gen.js +8 -4
- package/dist/lib/cloop-gen.js.map +1 -1
- package/dist/lib/index.js +3 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/test/test.js +12 -16
- package/dist/test/test.js.map +1 -1
- package/package.json +8 -7
- package/src/generate-files/firebird.cloop.json +10436 -7796
- package/src/generate-files/index.ts +5 -5
- package/src/generate-files/patch.ts +148 -221
- package/src/lib/cloop-gen.ts +1494 -925
- package/src/lib/index.ts +13 -13
- package/src/native/classes.h +6 -157
- package/src/test/test.ts +537 -542
- package/tsconfig.json +7 -13
- package/tslint.json +0 -6
package/src/lib/index.ts
CHANGED
|
@@ -2,29 +2,29 @@ import { Attachment, EventCallback, Master } from './cloop-gen';
|
|
|
2
2
|
|
|
3
3
|
import * as os from 'os';
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
/** Gets the default platform Firebird client library filename. */
|
|
7
6
|
export function getDefaultLibraryFilename(): string {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
switch (os.platform()) {
|
|
8
|
+
case 'win32':
|
|
9
|
+
return 'fbclient.dll';
|
|
10
|
+
case 'darwin':
|
|
11
|
+
return '/Library/Frameworks/Firebird.framework/Libraries/libfbclient.dylib';
|
|
12
|
+
default:
|
|
13
|
+
return 'libfbclient.so';
|
|
14
|
+
}
|
|
16
15
|
}
|
|
17
16
|
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
18
18
|
const native = require('bindings')('addon');
|
|
19
19
|
|
|
20
20
|
export const getMaster: (library: string) => Master = native.getMaster;
|
|
21
21
|
export const disposeMaster: (master: Master) => boolean = native.disposeMaster;
|
|
22
22
|
|
|
23
23
|
export const queueEvent: (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
client: Master,
|
|
25
|
+
attachment: Attachment,
|
|
26
|
+
names: string[],
|
|
27
|
+
callBack: (counters: [string, number][]) => Promise<void>,
|
|
28
28
|
) => Promise<EventCallback> = native.queueEvent;
|
|
29
29
|
|
|
30
30
|
export const cancelEvent: (eventCallback: EventCallback) => Promise<void> = native.cancelEvent;
|
package/src/native/classes.h
CHANGED
|
@@ -14,157 +14,6 @@
|
|
|
14
14
|
//----------------------------------------------------------------------------
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
namespace Napi
|
|
18
|
-
{
|
|
19
|
-
// Customize N-API AsyncWorker as the original API is very ugly and
|
|
20
|
-
// with slower unused things.
|
|
21
|
-
class CustomAsyncWorker
|
|
22
|
-
{
|
|
23
|
-
protected:
|
|
24
|
-
explicit CustomAsyncWorker(Env env);
|
|
25
|
-
explicit CustomAsyncWorker(Env env, const char* resource_name);
|
|
26
|
-
|
|
27
|
-
public:
|
|
28
|
-
// An async worker can be moved but cannot be copied.
|
|
29
|
-
CustomAsyncWorker(const CustomAsyncWorker&) = delete;
|
|
30
|
-
CustomAsyncWorker& operator=(CustomAsyncWorker&) = delete;
|
|
31
|
-
|
|
32
|
-
CustomAsyncWorker(CustomAsyncWorker&& other);
|
|
33
|
-
CustomAsyncWorker& operator=(CustomAsyncWorker&& other);
|
|
34
|
-
|
|
35
|
-
virtual ~CustomAsyncWorker();
|
|
36
|
-
|
|
37
|
-
operator napi_async_work() const
|
|
38
|
-
{
|
|
39
|
-
return _work;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
void Queue();
|
|
43
|
-
void Cancel();
|
|
44
|
-
|
|
45
|
-
protected:
|
|
46
|
-
virtual void Execute() = 0;
|
|
47
|
-
virtual void OnOK(Env env) = 0;
|
|
48
|
-
virtual void OnError(Env env, const Error& e) = 0;
|
|
49
|
-
|
|
50
|
-
void SetError(const std::string& error);
|
|
51
|
-
|
|
52
|
-
private:
|
|
53
|
-
static void OnExecute(napi_env env, void* this_pointer);
|
|
54
|
-
static void OnWorkComplete(napi_env env, napi_status status, void* this_pointer);
|
|
55
|
-
|
|
56
|
-
napi_env _env;
|
|
57
|
-
napi_async_work _work;
|
|
58
|
-
std::string _error;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
inline CustomAsyncWorker::CustomAsyncWorker(Env env)
|
|
62
|
-
: CustomAsyncWorker(env, "generic")
|
|
63
|
-
{
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
inline CustomAsyncWorker::CustomAsyncWorker(Env env, const char* resource_name)
|
|
67
|
-
: _env(env)
|
|
68
|
-
{
|
|
69
|
-
napi_value resource_id;
|
|
70
|
-
napi_status status = napi_create_string_latin1(
|
|
71
|
-
_env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
|
|
72
|
-
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
73
|
-
|
|
74
|
-
status = napi_create_async_work(_env, nullptr, resource_id,
|
|
75
|
-
OnExecute, OnWorkComplete, this, &_work);
|
|
76
|
-
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
inline CustomAsyncWorker::CustomAsyncWorker(CustomAsyncWorker&& other)
|
|
80
|
-
{
|
|
81
|
-
_env = other._env;
|
|
82
|
-
other._env = nullptr;
|
|
83
|
-
_work = other._work;
|
|
84
|
-
other._work = nullptr;
|
|
85
|
-
_error = std::move(other._error);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
inline CustomAsyncWorker& CustomAsyncWorker::operator=(CustomAsyncWorker&& other)
|
|
89
|
-
{
|
|
90
|
-
_env = other._env;
|
|
91
|
-
other._env = nullptr;
|
|
92
|
-
_work = other._work;
|
|
93
|
-
other._work = nullptr;
|
|
94
|
-
_error = std::move(other._error);
|
|
95
|
-
return *this;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
inline CustomAsyncWorker::~CustomAsyncWorker()
|
|
99
|
-
{
|
|
100
|
-
if (_work != nullptr)
|
|
101
|
-
{
|
|
102
|
-
napi_delete_async_work(_env, _work);
|
|
103
|
-
_work = nullptr;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
inline void CustomAsyncWorker::Queue()
|
|
108
|
-
{
|
|
109
|
-
napi_status status = napi_queue_async_work(_env, _work);
|
|
110
|
-
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
inline void CustomAsyncWorker::Cancel()
|
|
114
|
-
{
|
|
115
|
-
napi_status status = napi_cancel_async_work(_env, _work);
|
|
116
|
-
NAPI_THROW_IF_FAILED_VOID(_env, status);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
inline void CustomAsyncWorker::SetError(const std::string& error)
|
|
120
|
-
{
|
|
121
|
-
_error = error;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
inline void CustomAsyncWorker::OnExecute(napi_env /*env*/, void* this_pointer)
|
|
125
|
-
{
|
|
126
|
-
CustomAsyncWorker* self = static_cast<CustomAsyncWorker*>(this_pointer);
|
|
127
|
-
#ifdef NAPI_CPP_EXCEPTIONS
|
|
128
|
-
try
|
|
129
|
-
{
|
|
130
|
-
self->Execute();
|
|
131
|
-
}
|
|
132
|
-
catch (const std::exception& e)
|
|
133
|
-
{
|
|
134
|
-
self->SetError(e.what());
|
|
135
|
-
}
|
|
136
|
-
#else // NAPI_CPP_EXCEPTIONS
|
|
137
|
-
self->Execute();
|
|
138
|
-
#endif // NAPI_CPP_EXCEPTIONS
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
inline void CustomAsyncWorker::OnWorkComplete(
|
|
142
|
-
napi_env env, napi_status status, void* this_pointer)
|
|
143
|
-
{
|
|
144
|
-
CustomAsyncWorker* self = static_cast<CustomAsyncWorker*>(this_pointer);
|
|
145
|
-
|
|
146
|
-
if (status != napi_cancelled)
|
|
147
|
-
{
|
|
148
|
-
HandleScope scope(self->_env);
|
|
149
|
-
|
|
150
|
-
details::WrapCallback([&] {
|
|
151
|
-
if (self->_error.size() == 0)
|
|
152
|
-
self->OnOK(env);
|
|
153
|
-
else
|
|
154
|
-
self->OnError(env, Error::New(self->_env, self->_error));
|
|
155
|
-
|
|
156
|
-
return nullptr;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
delete self;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
//----------------------------------------------------------------------------
|
|
166
|
-
|
|
167
|
-
|
|
168
17
|
namespace fb = Firebird;
|
|
169
18
|
|
|
170
19
|
|
|
@@ -206,13 +55,13 @@ using MethodStart = std::function<T ()>;
|
|
|
206
55
|
|
|
207
56
|
|
|
208
57
|
template <typename T>
|
|
209
|
-
class PromiseWorker : public Napi::
|
|
58
|
+
class PromiseWorker : public Napi::AsyncWorker
|
|
210
59
|
{
|
|
211
60
|
protected:
|
|
212
61
|
PromiseWorker(const Napi::Env env,
|
|
213
62
|
MethodStart<T> executeLambda,
|
|
214
63
|
std::function<Napi::Value (const Napi::Env, T)> returnLambda)
|
|
215
|
-
:
|
|
64
|
+
: AsyncWorker(env),
|
|
216
65
|
executeLambda(executeLambda),
|
|
217
66
|
returnLambda(returnLambda),
|
|
218
67
|
deferred(env)
|
|
@@ -246,15 +95,15 @@ protected:
|
|
|
246
95
|
}
|
|
247
96
|
}
|
|
248
97
|
|
|
249
|
-
void OnOK(
|
|
98
|
+
void OnOK() override
|
|
250
99
|
{
|
|
251
100
|
if (!error)
|
|
252
|
-
deferred.Resolve(returnLambda(
|
|
101
|
+
deferred.Resolve(returnLambda(Env(), ret));
|
|
253
102
|
else
|
|
254
|
-
deferred.Reject(Napi::Error::New(
|
|
103
|
+
deferred.Reject(Napi::Error::New(Env(), errorMsg.c_str()).Value());
|
|
255
104
|
}
|
|
256
105
|
|
|
257
|
-
void OnError(
|
|
106
|
+
void OnError(const Napi::Error& e) override
|
|
258
107
|
{
|
|
259
108
|
assert(false);
|
|
260
109
|
}
|