k2hdkc 1.0.12 → 2.0.0

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/binding.gyp ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "variables": {
3
+ "coverage": "false",
4
+ "openssl_fips": ""
5
+ },
6
+ "targets": [
7
+ {
8
+ "target_name": "k2hdkc",
9
+ "sources": [
10
+ "src/k2hdkc.cc",
11
+ "src/k2hdkc_node.cc",
12
+ "src/k2hdkc_cbs.cc"
13
+ ],
14
+ "include_dirs": [
15
+ "<!(node -e \"incpath = require('node-addon-api').include; if(incpath.length && incpath[0] === '\\\"' && incpath[incpath.length - 1] === '\\\"') incpath = incpath.slice(1, -1); process.stdout.write(incpath)\")",
16
+ "<(module_root_dir)/node_modules/node-addon-api"
17
+ ],
18
+ "dependencies": [
19
+ "<!(node -p \"require('node-addon-api').gyp\")"
20
+ ],
21
+ "cflags!": [
22
+ "-fno-exceptions"
23
+ ],
24
+ "cflags_cc!": [
25
+ "-fno-exceptions"
26
+ ],
27
+ "cflags_cc": [
28
+ "-std=c++17"
29
+ ],
30
+ "defines": [
31
+ "NAPI_CPP_EXCEPTIONS"
32
+ ],
33
+ "link_settings": {
34
+ "libraries": [
35
+ "-lk2hdkc"
36
+ ]
37
+ }
38
+ }
39
+ ]
40
+ }
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ /*
3
+ * K2HDKC
4
+ *
5
+ * Copyright 2017 Yahoo Japan Corporation.
6
+ *
7
+ * K2HDKC is k2hash based distributed KVS cluster.
8
+ * K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports
9
+ * distributed KVS cluster server program and client libraries.
10
+ *
11
+ * For the full copyright and license information, please view
12
+ * the license file that was distributed with this source code.
13
+ *
14
+ * AUTHOR: Takeshi Nakatani
15
+ * CREATE: Fri 9 Nov 2018
16
+ * REVISION:
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.K2hdkcNode = void 0;
20
+ let _native = undefined;
21
+ let _nativeLoaded = false;
22
+ // [NOTE]
23
+ // Copy properties from native onto the factory(mirrors original runtime
24
+ // normalization)
25
+ // We try to preserve descriptors when possible.
26
+ //
27
+ function copyPropsToFactory(k2hdkcFactory, factory_native) {
28
+ if (!factory_native || (typeof factory_native !== 'object' && typeof factory_native !== 'function')) {
29
+ return;
30
+ }
31
+ try {
32
+ Object.getOwnPropertyNames(factory_native).forEach((name) => {
33
+ if (name === 'prototype') {
34
+ return;
35
+ }
36
+ try {
37
+ const desc = Object.getOwnPropertyDescriptor(factory_native, name);
38
+ if (desc) {
39
+ Object.defineProperty(k2hdkcFactory, name, desc);
40
+ }
41
+ }
42
+ catch {
43
+ try {
44
+ k2hdkcFactory[name] = factory_native[name];
45
+ }
46
+ catch {
47
+ // ignore
48
+ }
49
+ }
50
+ });
51
+ Object.getOwnPropertySymbols(factory_native).forEach((sym) => {
52
+ try {
53
+ const desc = Object.getOwnPropertyDescriptor(factory_native, sym);
54
+ if (desc) {
55
+ Object.defineProperty(k2hdkcFactory, sym, desc);
56
+ }
57
+ }
58
+ catch {
59
+ try {
60
+ k2hdkcFactory[sym] = factory_native[sym];
61
+ }
62
+ catch {
63
+ // ignore
64
+ }
65
+ }
66
+ });
67
+ }
68
+ catch {
69
+ // ignore odd cases(native undefined or primitive)
70
+ }
71
+ try {
72
+ if (factory_native && factory_native.K2hdkcNode) {
73
+ k2hdkcFactory.K2hdkcNode = factory_native.K2hdkcNode;
74
+ }
75
+ }
76
+ catch {
77
+ // ignore
78
+ }
79
+ }
80
+ // [NOTE]
81
+ // Load native on first need. Also call copyPropsToFactory once after
82
+ // loading.
83
+ // require('bindings') may throw if native not present at build/test time
84
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
85
+ //
86
+ function ensureNative() {
87
+ if (_nativeLoaded) {
88
+ return _native;
89
+ }
90
+ _nativeLoaded = true;
91
+ try {
92
+ const bindings = require('bindings');
93
+ _native = bindings('k2hdkc');
94
+ }
95
+ catch {
96
+ _native = undefined;
97
+ }
98
+ // [NOTE]
99
+ // If we successfully loaded native, copy properties onto the factory so
100
+ // default export retains the same shape as before (callable + named
101
+ // properties).
102
+ //
103
+ if (_native) {
104
+ try {
105
+ // [NOTE]
106
+ // k2hdkcFactory is hoisted(function declaration), safe to
107
+ // reference here
108
+ copyPropsToFactory(k2hdkcFactory, _native);
109
+ }
110
+ catch {
111
+ // swallow copy errors to preserve robustness
112
+ }
113
+ }
114
+ return _native;
115
+ }
116
+ // [NOTE]
117
+ // Default factory that mirrors previous behavior
118
+ //
119
+ function k2hdkcFactory(...args) {
120
+ const _factory_native = ensureNative();
121
+ if (typeof _factory_native === 'function') {
122
+ try {
123
+ const retobj = _factory_native.apply(null, args);
124
+ if (retobj !== undefined) {
125
+ return retobj;
126
+ }
127
+ }
128
+ catch {
129
+ // fallthrough to constructor fallback
130
+ }
131
+ }
132
+ if (_factory_native && typeof _factory_native.K2hdkcNode === 'function') {
133
+ try {
134
+ return new _factory_native.K2hdkcNode(...args);
135
+ }
136
+ catch {
137
+ // fallthrough
138
+ }
139
+ }
140
+ // fallback: return native itself (could be an object with properties)
141
+ return _factory_native;
142
+ }
143
+ // [NOTE]
144
+ // Returns a callable & constructible Proxy that forwards to native export
145
+ //
146
+ function createLazyProxy(name) {
147
+ let _cached = undefined;
148
+ function loadActual() {
149
+ if (_cached !== undefined) {
150
+ return _cached;
151
+ }
152
+ const _lazy_native = ensureNative();
153
+ const _actual = _lazy_native && _lazy_native[name] ? _lazy_native[name] : undefined;
154
+ if (!_actual) {
155
+ throw new Error("Native export " + JSON.stringify(name) + " is not available");
156
+ }
157
+ _cached = _actual;
158
+ return _cached;
159
+ }
160
+ const target = function (...args) {
161
+ const _actual = loadActual();
162
+ return _actual.apply(this, args);
163
+ };
164
+ const handler = {
165
+ apply(_t, thisArg, args) {
166
+ const _actual = loadActual();
167
+ return _actual.apply(thisArg, args);
168
+ },
169
+ construct(_t, args, newTarget) {
170
+ const _actual = loadActual();
171
+ return Reflect.construct(_actual, args, newTarget);
172
+ },
173
+ get(_t, prop, receiver) {
174
+ const _actual = loadActual();
175
+ return Reflect.get(_actual, prop, receiver);
176
+ },
177
+ set(_t, prop, value, receiver) {
178
+ const _actual = loadActual();
179
+ return Reflect.set(_actual, prop, value, receiver);
180
+ },
181
+ has(_t, prop) {
182
+ const _actual = loadActual();
183
+ return prop in _actual;
184
+ },
185
+ ownKeys(_t) {
186
+ const _actual = loadActual();
187
+ return Reflect.ownKeys(_actual);
188
+ },
189
+ getOwnPropertyDescriptor(_t, prop) {
190
+ const _actual = loadActual();
191
+ return Object.getOwnPropertyDescriptor(_actual, prop) || undefined;
192
+ },
193
+ getPrototypeOf(_t) {
194
+ const _actual = loadActual();
195
+ return Object.getPrototypeOf(_actual);
196
+ },
197
+ setPrototypeOf(_t, proto) {
198
+ const _actual = loadActual();
199
+ return Object.setPrototypeOf(_actual, proto);
200
+ },
201
+ defineProperty(_t, prop, descriptor) {
202
+ const _actual = loadActual();
203
+ return Reflect.defineProperty(_actual, prop, descriptor);
204
+ },
205
+ deleteProperty(_t, prop) {
206
+ const _actual = loadActual();
207
+ return Reflect.deleteProperty(_actual, prop);
208
+ }
209
+ };
210
+ return new Proxy(target, handler);
211
+ }
212
+ //
213
+ // Export named proxies to keep compatibility with existing consumers
214
+ //
215
+ // Named convenience exports (runtime values).
216
+ // Types are provided by types/index.d.ts.
217
+ //
218
+ exports.K2hdkcNode = createLazyProxy('K2hdkcNode');
219
+ exports.default = k2hdkcFactory;
220
+ try {
221
+ if (typeof module !== 'undefined' && module && module.exports) {
222
+ const own_module_export = module.exports;
223
+ //
224
+ // If module.exports is exactly { default: fn }, replace module.exports with fn.
225
+ //
226
+ if (own_module_export &&
227
+ typeof own_module_export === 'object' &&
228
+ Object.prototype.hasOwnProperty.call(own_module_export, 'default') &&
229
+ typeof own_module_export.default === 'function' &&
230
+ Object.keys(own_module_export).length === 1) {
231
+ module.exports = own_module_export.default;
232
+ }
233
+ else if (own_module_export && typeof own_module_export === 'object' && typeof own_module_export.default === 'function') {
234
+ //
235
+ // If default is a function but other named exports exist,
236
+ // prefer a top-level callable while preserving named props.
237
+ //
238
+ try {
239
+ const defaultFn = own_module_export.default;
240
+ // If top-level is not already callable, make it so.
241
+ if (typeof own_module_export !== 'function') {
242
+ // create a callable wrapper that forwards to defaultFn
243
+ const callable = function (...args) {
244
+ return defaultFn.apply(this, args);
245
+ };
246
+ // copy named properties from original exports except 'default'
247
+ Object.keys(own_module_export).forEach((key) => {
248
+ if (key === 'default') {
249
+ return;
250
+ }
251
+ try {
252
+ callable[key] = own_module_export[key];
253
+ }
254
+ catch {
255
+ // ignore
256
+ }
257
+ });
258
+ // preserve reference to original module
259
+ try {
260
+ callable.__orig_module = own_module_export;
261
+ }
262
+ catch {
263
+ // ignore
264
+ }
265
+ // replace module.exports with callable that also carries named props
266
+ module.exports = callable;
267
+ }
268
+ }
269
+ catch {
270
+ // swallow normalization errors - not critical
271
+ }
272
+ }
273
+ }
274
+ }
275
+ catch {
276
+ // ignore
277
+ }
278
+ /*
279
+ * Local variables:
280
+ * tab-width: 4
281
+ * c-basic-offset: 4
282
+ * End:
283
+ * vim600: noexpandtab sw=4 ts=4 fdm=marker
284
+ * vim<600: noexpandtab sw=4 ts=4
285
+ */
@@ -0,0 +1,282 @@
1
+ /*
2
+ * K2HDKC
3
+ *
4
+ * Copyright 2017 Yahoo Japan Corporation.
5
+ *
6
+ * K2HDKC is k2hash based distributed KVS cluster.
7
+ * K2HDKC uses K2HASH, CHMPX, FULLOCK libraries. K2HDKC supports
8
+ * distributed KVS cluster server program and client libraries.
9
+ *
10
+ * For the full copyright and license information, please view
11
+ * the license file that was distributed with this source code.
12
+ *
13
+ * AUTHOR: Takeshi Nakatani
14
+ * CREATE: Fri 9 Nov 2018
15
+ * REVISION:
16
+ */
17
+ let _native = undefined;
18
+ let _nativeLoaded = false;
19
+ // [NOTE]
20
+ // Copy properties from native onto the factory(mirrors original runtime
21
+ // normalization)
22
+ // We try to preserve descriptors when possible.
23
+ //
24
+ function copyPropsToFactory(k2hdkcFactory, factory_native) {
25
+ if (!factory_native || (typeof factory_native !== 'object' && typeof factory_native !== 'function')) {
26
+ return;
27
+ }
28
+ try {
29
+ Object.getOwnPropertyNames(factory_native).forEach((name) => {
30
+ if (name === 'prototype') {
31
+ return;
32
+ }
33
+ try {
34
+ const desc = Object.getOwnPropertyDescriptor(factory_native, name);
35
+ if (desc) {
36
+ Object.defineProperty(k2hdkcFactory, name, desc);
37
+ }
38
+ }
39
+ catch {
40
+ try {
41
+ k2hdkcFactory[name] = factory_native[name];
42
+ }
43
+ catch {
44
+ // ignore
45
+ }
46
+ }
47
+ });
48
+ Object.getOwnPropertySymbols(factory_native).forEach((sym) => {
49
+ try {
50
+ const desc = Object.getOwnPropertyDescriptor(factory_native, sym);
51
+ if (desc) {
52
+ Object.defineProperty(k2hdkcFactory, sym, desc);
53
+ }
54
+ }
55
+ catch {
56
+ try {
57
+ k2hdkcFactory[sym] = factory_native[sym];
58
+ }
59
+ catch {
60
+ // ignore
61
+ }
62
+ }
63
+ });
64
+ }
65
+ catch {
66
+ // ignore odd cases(native undefined or primitive)
67
+ }
68
+ try {
69
+ if (factory_native && factory_native.K2hdkcNode) {
70
+ k2hdkcFactory.K2hdkcNode = factory_native.K2hdkcNode;
71
+ }
72
+ }
73
+ catch {
74
+ // ignore
75
+ }
76
+ }
77
+ // [NOTE]
78
+ // Load native on first need. Also call copyPropsToFactory once after
79
+ // loading.
80
+ // require('bindings') may throw if native not present at build/test time
81
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
82
+ //
83
+ function ensureNative() {
84
+ if (_nativeLoaded) {
85
+ return _native;
86
+ }
87
+ _nativeLoaded = true;
88
+ try {
89
+ const bindings = require('bindings');
90
+ _native = bindings('k2hdkc');
91
+ }
92
+ catch {
93
+ _native = undefined;
94
+ }
95
+ // [NOTE]
96
+ // If we successfully loaded native, copy properties onto the factory so
97
+ // default export retains the same shape as before (callable + named
98
+ // properties).
99
+ //
100
+ if (_native) {
101
+ try {
102
+ // [NOTE]
103
+ // k2hdkcFactory is hoisted(function declaration), safe to
104
+ // reference here
105
+ copyPropsToFactory(k2hdkcFactory, _native);
106
+ }
107
+ catch {
108
+ // swallow copy errors to preserve robustness
109
+ }
110
+ }
111
+ return _native;
112
+ }
113
+ // [NOTE]
114
+ // Default factory that mirrors previous behavior
115
+ //
116
+ function k2hdkcFactory(...args) {
117
+ const _factory_native = ensureNative();
118
+ if (typeof _factory_native === 'function') {
119
+ try {
120
+ const retobj = _factory_native.apply(null, args);
121
+ if (retobj !== undefined) {
122
+ return retobj;
123
+ }
124
+ }
125
+ catch {
126
+ // fallthrough to constructor fallback
127
+ }
128
+ }
129
+ if (_factory_native && typeof _factory_native.K2hdkcNode === 'function') {
130
+ try {
131
+ return new _factory_native.K2hdkcNode(...args);
132
+ }
133
+ catch {
134
+ // fallthrough
135
+ }
136
+ }
137
+ // fallback: return native itself (could be an object with properties)
138
+ return _factory_native;
139
+ }
140
+ // [NOTE]
141
+ // Returns a callable & constructible Proxy that forwards to native export
142
+ //
143
+ function createLazyProxy(name) {
144
+ let _cached = undefined;
145
+ function loadActual() {
146
+ if (_cached !== undefined) {
147
+ return _cached;
148
+ }
149
+ const _lazy_native = ensureNative();
150
+ const _actual = _lazy_native && _lazy_native[name] ? _lazy_native[name] : undefined;
151
+ if (!_actual) {
152
+ throw new Error("Native export " + JSON.stringify(name) + " is not available");
153
+ }
154
+ _cached = _actual;
155
+ return _cached;
156
+ }
157
+ const target = function (...args) {
158
+ const _actual = loadActual();
159
+ return _actual.apply(this, args);
160
+ };
161
+ const handler = {
162
+ apply(_t, thisArg, args) {
163
+ const _actual = loadActual();
164
+ return _actual.apply(thisArg, args);
165
+ },
166
+ construct(_t, args, newTarget) {
167
+ const _actual = loadActual();
168
+ return Reflect.construct(_actual, args, newTarget);
169
+ },
170
+ get(_t, prop, receiver) {
171
+ const _actual = loadActual();
172
+ return Reflect.get(_actual, prop, receiver);
173
+ },
174
+ set(_t, prop, value, receiver) {
175
+ const _actual = loadActual();
176
+ return Reflect.set(_actual, prop, value, receiver);
177
+ },
178
+ has(_t, prop) {
179
+ const _actual = loadActual();
180
+ return prop in _actual;
181
+ },
182
+ ownKeys(_t) {
183
+ const _actual = loadActual();
184
+ return Reflect.ownKeys(_actual);
185
+ },
186
+ getOwnPropertyDescriptor(_t, prop) {
187
+ const _actual = loadActual();
188
+ return Object.getOwnPropertyDescriptor(_actual, prop) || undefined;
189
+ },
190
+ getPrototypeOf(_t) {
191
+ const _actual = loadActual();
192
+ return Object.getPrototypeOf(_actual);
193
+ },
194
+ setPrototypeOf(_t, proto) {
195
+ const _actual = loadActual();
196
+ return Object.setPrototypeOf(_actual, proto);
197
+ },
198
+ defineProperty(_t, prop, descriptor) {
199
+ const _actual = loadActual();
200
+ return Reflect.defineProperty(_actual, prop, descriptor);
201
+ },
202
+ deleteProperty(_t, prop) {
203
+ const _actual = loadActual();
204
+ return Reflect.deleteProperty(_actual, prop);
205
+ }
206
+ };
207
+ return new Proxy(target, handler);
208
+ }
209
+ //
210
+ // Export named proxies to keep compatibility with existing consumers
211
+ //
212
+ // Named convenience exports (runtime values).
213
+ // Types are provided by types/index.d.ts.
214
+ //
215
+ export const K2hdkcNode = createLazyProxy('K2hdkcNode');
216
+ export default k2hdkcFactory;
217
+ try {
218
+ if (typeof module !== 'undefined' && module && module.exports) {
219
+ const own_module_export = module.exports;
220
+ //
221
+ // If module.exports is exactly { default: fn }, replace module.exports with fn.
222
+ //
223
+ if (own_module_export &&
224
+ typeof own_module_export === 'object' &&
225
+ Object.prototype.hasOwnProperty.call(own_module_export, 'default') &&
226
+ typeof own_module_export.default === 'function' &&
227
+ Object.keys(own_module_export).length === 1) {
228
+ module.exports = own_module_export.default;
229
+ }
230
+ else if (own_module_export && typeof own_module_export === 'object' && typeof own_module_export.default === 'function') {
231
+ //
232
+ // If default is a function but other named exports exist,
233
+ // prefer a top-level callable while preserving named props.
234
+ //
235
+ try {
236
+ const defaultFn = own_module_export.default;
237
+ // If top-level is not already callable, make it so.
238
+ if (typeof own_module_export !== 'function') {
239
+ // create a callable wrapper that forwards to defaultFn
240
+ const callable = function (...args) {
241
+ return defaultFn.apply(this, args);
242
+ };
243
+ // copy named properties from original exports except 'default'
244
+ Object.keys(own_module_export).forEach((key) => {
245
+ if (key === 'default') {
246
+ return;
247
+ }
248
+ try {
249
+ callable[key] = own_module_export[key];
250
+ }
251
+ catch {
252
+ // ignore
253
+ }
254
+ });
255
+ // preserve reference to original module
256
+ try {
257
+ callable.__orig_module = own_module_export;
258
+ }
259
+ catch {
260
+ // ignore
261
+ }
262
+ // replace module.exports with callable that also carries named props
263
+ module.exports = callable;
264
+ }
265
+ }
266
+ catch {
267
+ // swallow normalization errors - not critical
268
+ }
269
+ }
270
+ }
271
+ }
272
+ catch {
273
+ // ignore
274
+ }
275
+ /*
276
+ * Local variables:
277
+ * tab-width: 4
278
+ * c-basic-offset: 4
279
+ * End:
280
+ * vim600: noexpandtab sw=4 ts=4 fdm=marker
281
+ * vim<600: noexpandtab sw=4 ts=4
282
+ */