client.cjs
6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
var _class, _worker, _worker_threads, _worker_threads_cache;
function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
function _classCheckPrivateStaticFieldDescriptor(descriptor, action) { if (descriptor === undefined) { throw new TypeError("attempted to " + action + " private static field before its declaration"); } }
function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } }
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
const path = require("path");
const ACTIONS = {
GET_VERSION: "GET_VERSION",
GET_TYPES_INFO: "GET_TYPES_INFO",
GET_VISITOR_KEYS: "GET_VISITOR_KEYS",
GET_TOKEN_LABELS: "GET_TOKEN_LABELS",
MAYBE_PARSE: "MAYBE_PARSE",
MAYBE_PARSE_SYNC: "MAYBE_PARSE_SYNC"
};
var _send = new WeakMap();
var _vCache = new WeakMap();
var _tiCache = new WeakMap();
var _vkCache = new WeakMap();
var _tlCache = new WeakMap();
class Client {
constructor(send) {
_classPrivateFieldInitSpec(this, _send, {
writable: true,
value: void 0
});
_classPrivateFieldInitSpec(this, _vCache, {
writable: true,
value: void 0
});
_classPrivateFieldInitSpec(this, _tiCache, {
writable: true,
value: void 0
});
_classPrivateFieldInitSpec(this, _vkCache, {
writable: true,
value: void 0
});
_classPrivateFieldInitSpec(this, _tlCache, {
writable: true,
value: void 0
});
_classPrivateFieldSet(this, _send, send);
}
getVersion() {
var _classPrivateFieldGet2;
return (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _vCache)) != null ? _classPrivateFieldGet2 : _classPrivateFieldSet(this, _vCache, _classPrivateFieldGet(this, _send).call(this, ACTIONS.GET_VERSION, undefined));
}
getTypesInfo() {
var _classPrivateFieldGet3;
return (_classPrivateFieldGet3 = _classPrivateFieldGet(this, _tiCache)) != null ? _classPrivateFieldGet3 : _classPrivateFieldSet(this, _tiCache, _classPrivateFieldGet(this, _send).call(this, ACTIONS.GET_TYPES_INFO, undefined));
}
getVisitorKeys() {
var _classPrivateFieldGet4;
return (_classPrivateFieldGet4 = _classPrivateFieldGet(this, _vkCache)) != null ? _classPrivateFieldGet4 : _classPrivateFieldSet(this, _vkCache, _classPrivateFieldGet(this, _send).call(this, ACTIONS.GET_VISITOR_KEYS, undefined));
}
getTokLabels() {
var _classPrivateFieldGet5;
return (_classPrivateFieldGet5 = _classPrivateFieldGet(this, _tlCache)) != null ? _classPrivateFieldGet5 : _classPrivateFieldSet(this, _tlCache, _classPrivateFieldGet(this, _send).call(this, ACTIONS.GET_TOKEN_LABELS, undefined));
}
maybeParse(code, options) {
return _classPrivateFieldGet(this, _send).call(this, ACTIONS.MAYBE_PARSE, {
code,
options
});
}
}
exports.WorkerClient = (_worker = new WeakMap(), (_class = class WorkerClient extends Client {
constructor() {
super((action, payload) => {
const signal = new Int32Array(new SharedArrayBuffer(8));
const subChannel = new (_classStaticPrivateFieldSpecGet(WorkerClient, _class, _worker_threads).MessageChannel)();
_classPrivateFieldGet(this, _worker).postMessage({
signal,
port: subChannel.port1,
action,
payload
}, [subChannel.port1]);
Atomics.wait(signal, 0, 0);
const {
message
} = _classStaticPrivateFieldSpecGet(WorkerClient, _class, _worker_threads).receiveMessageOnPort(subChannel.port2);
if (message.error) throw Object.assign(message.error, message.errorData);else return message.result;
});
_classPrivateFieldInitSpec(this, _worker, {
writable: true,
value: new (_classStaticPrivateFieldSpecGet(WorkerClient, _class, _worker_threads).Worker)(path.resolve(__dirname, "../lib/worker/index.cjs"), {
env: _classStaticPrivateFieldSpecGet(WorkerClient, _class, _worker_threads).SHARE_ENV
})
});
_classPrivateFieldGet(this, _worker).unref();
}
}, _worker_threads = {
get: _get_worker_threads,
set: void 0
}, _worker_threads_cache = {
writable: true,
value: void 0
}, _class));
function _get_worker_threads() {
var _classStaticPrivateFi2;
return (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_class, _class, _worker_threads_cache)) != null ? _classStaticPrivateFi2 : _classStaticPrivateFieldSpecSet(_class, _class, _worker_threads_cache, require("worker_threads"));
}
{
var _class2, _handleMessage;
exports.LocalClient = (_class2 = class LocalClient extends Client {
constructor() {
var _classStaticPrivateFi;
(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(LocalClient, _class2, _handleMessage)) != null ? _classStaticPrivateFi : _classStaticPrivateFieldSpecSet(LocalClient, _class2, _handleMessage, require("./worker/handle-message.cjs"));
super((action, payload) => {
return _classStaticPrivateFieldSpecGet(LocalClient, _class2, _handleMessage).call(LocalClient, action === ACTIONS.MAYBE_PARSE ? ACTIONS.MAYBE_PARSE_SYNC : action, payload);
});
}
}, _handleMessage = {
writable: true,
value: void 0
}, _class2);
}
//# sourceMappingURL=client.cjs.map