| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.WorkerClient = exports.Client = exports.ACTIONS = void 0;
|
|---|
| 7 | var _LocalClient, _handleMessage;
|
|---|
| 8 | function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|---|
| 9 | function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|---|
| 10 | function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|---|
| 11 | function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|---|
| 12 | function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|---|
| 13 | const path = require("path");
|
|---|
| 14 | const ACTIONS = exports.ACTIONS = {
|
|---|
| 15 | GET_VERSION: "GET_VERSION",
|
|---|
| 16 | GET_TYPES_INFO: "GET_TYPES_INFO",
|
|---|
| 17 | GET_VISITOR_KEYS: "GET_VISITOR_KEYS",
|
|---|
| 18 | GET_TOKEN_LABELS: "GET_TOKEN_LABELS",
|
|---|
| 19 | MAYBE_PARSE: "MAYBE_PARSE",
|
|---|
| 20 | MAYBE_PARSE_SYNC: "MAYBE_PARSE_SYNC"
|
|---|
| 21 | };
|
|---|
| 22 | var _send = new WeakMap();
|
|---|
| 23 | var _vCache = new WeakMap();
|
|---|
| 24 | var _tiCache = new WeakMap();
|
|---|
| 25 | var _vkCache = new WeakMap();
|
|---|
| 26 | var _tlCache = new WeakMap();
|
|---|
| 27 | class Client {
|
|---|
| 28 | constructor(send) {
|
|---|
| 29 | _classPrivateFieldInitSpec(this, _send, void 0);
|
|---|
| 30 | _classPrivateFieldInitSpec(this, _vCache, void 0);
|
|---|
| 31 | _classPrivateFieldInitSpec(this, _tiCache, void 0);
|
|---|
| 32 | _classPrivateFieldInitSpec(this, _vkCache, void 0);
|
|---|
| 33 | _classPrivateFieldInitSpec(this, _tlCache, void 0);
|
|---|
| 34 | _classPrivateFieldSet(_send, this, send);
|
|---|
| 35 | }
|
|---|
| 36 | getVersion() {
|
|---|
| 37 | var _classPrivateFieldGet2;
|
|---|
| 38 | return (_classPrivateFieldGet2 = _classPrivateFieldGet(_vCache, this)) != null ? _classPrivateFieldGet2 : _classPrivateFieldSet(_vCache, this, _classPrivateFieldGet(_send, this).call(this, ACTIONS.GET_VERSION, undefined));
|
|---|
| 39 | }
|
|---|
| 40 | getTypesInfo() {
|
|---|
| 41 | var _classPrivateFieldGet3;
|
|---|
| 42 | return (_classPrivateFieldGet3 = _classPrivateFieldGet(_tiCache, this)) != null ? _classPrivateFieldGet3 : _classPrivateFieldSet(_tiCache, this, _classPrivateFieldGet(_send, this).call(this, ACTIONS.GET_TYPES_INFO, undefined));
|
|---|
| 43 | }
|
|---|
| 44 | getVisitorKeys() {
|
|---|
| 45 | var _classPrivateFieldGet4;
|
|---|
| 46 | return (_classPrivateFieldGet4 = _classPrivateFieldGet(_vkCache, this)) != null ? _classPrivateFieldGet4 : _classPrivateFieldSet(_vkCache, this, _classPrivateFieldGet(_send, this).call(this, ACTIONS.GET_VISITOR_KEYS, undefined));
|
|---|
| 47 | }
|
|---|
| 48 | getTokLabels() {
|
|---|
| 49 | var _classPrivateFieldGet5;
|
|---|
| 50 | return (_classPrivateFieldGet5 = _classPrivateFieldGet(_tlCache, this)) != null ? _classPrivateFieldGet5 : _classPrivateFieldSet(_tlCache, this, _classPrivateFieldGet(_send, this).call(this, ACTIONS.GET_TOKEN_LABELS, undefined));
|
|---|
| 51 | }
|
|---|
| 52 | maybeParse(code, options) {
|
|---|
| 53 | return _classPrivateFieldGet(_send, this).call(this, ACTIONS.MAYBE_PARSE, {
|
|---|
| 54 | code,
|
|---|
| 55 | options
|
|---|
| 56 | });
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 | exports.Client = Client;
|
|---|
| 60 | var _worker = new WeakMap();
|
|---|
| 61 | class WorkerClient extends Client {
|
|---|
| 62 | constructor() {
|
|---|
| 63 | super((action, payload) => {
|
|---|
| 64 | const signal = new Int32Array(new SharedArrayBuffer(8));
|
|---|
| 65 | const subChannel = new (_get_worker_threads(WorkerClient).MessageChannel)();
|
|---|
| 66 | _classPrivateFieldGet(_worker, this).postMessage({
|
|---|
| 67 | signal,
|
|---|
| 68 | port: subChannel.port1,
|
|---|
| 69 | action,
|
|---|
| 70 | payload
|
|---|
| 71 | }, [subChannel.port1]);
|
|---|
| 72 | Atomics.wait(signal, 0, 0);
|
|---|
| 73 | const {
|
|---|
| 74 | message
|
|---|
| 75 | } = _get_worker_threads(WorkerClient).receiveMessageOnPort(subChannel.port2);
|
|---|
| 76 | if (message.error) throw Object.assign(message.error, message.errorData);else return message.result;
|
|---|
| 77 | });
|
|---|
| 78 | _classPrivateFieldInitSpec(this, _worker, new (_get_worker_threads(WorkerClient).Worker)(path.resolve(__dirname, "../lib/worker/index.cjs"), {
|
|---|
| 79 | env: _get_worker_threads(WorkerClient).SHARE_ENV
|
|---|
| 80 | }));
|
|---|
| 81 | _classPrivateFieldGet(_worker, this).unref();
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 | exports.WorkerClient = WorkerClient;
|
|---|
| 85 | function _get_worker_threads(_this) {
|
|---|
| 86 | var _worker_threads_cache2;
|
|---|
| 87 | return (_worker_threads_cache2 = _worker_threads_cache._) != null ? _worker_threads_cache2 : _worker_threads_cache._ = require("worker_threads");
|
|---|
| 88 | }
|
|---|
| 89 | var _worker_threads_cache = {
|
|---|
| 90 | _: void 0
|
|---|
| 91 | };
|
|---|
| 92 | exports.LocalClient = (_LocalClient = class LocalClient extends Client {
|
|---|
| 93 | constructor() {
|
|---|
| 94 | var _assertClassBrand$_;
|
|---|
| 95 | (_assertClassBrand$_ = _assertClassBrand(_LocalClient, LocalClient, _handleMessage)._) != null ? _assertClassBrand$_ : _handleMessage._ = _assertClassBrand(_LocalClient, LocalClient, require("./worker/handle-message.cjs"));
|
|---|
| 96 | super((action, payload) => {
|
|---|
| 97 | return _assertClassBrand(_LocalClient, LocalClient, _handleMessage)._.call(LocalClient, action === ACTIONS.MAYBE_PARSE ? ACTIONS.MAYBE_PARSE_SYNC : action, payload);
|
|---|
| 98 | });
|
|---|
| 99 | }
|
|---|
| 100 | }, _handleMessage = {
|
|---|
| 101 | _: void 0
|
|---|
| 102 | }, _LocalClient);
|
|---|
| 103 |
|
|---|
| 104 | //# sourceMappingURL=client.cjs.map
|
|---|