client.cjs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. var _class, _worker, _signal, _temp, _worker_threads, _worker_threads_cache;
  2. function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  3. function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  4. function _classCheckPrivateStaticFieldDescriptor(descriptor, action) { if (descriptor === undefined) { throw new TypeError("attempted to " + action + " private static field before its declaration"); } }
  5. function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } }
  6. function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
  7. function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
  8. function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
  9. function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
  10. function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
  11. function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
  12. 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; } }
  13. const path = require("path");
  14. const 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, {
  30. writable: true,
  31. value: void 0
  32. });
  33. _classPrivateFieldInitSpec(this, _vCache, {
  34. writable: true,
  35. value: void 0
  36. });
  37. _classPrivateFieldInitSpec(this, _tiCache, {
  38. writable: true,
  39. value: void 0
  40. });
  41. _classPrivateFieldInitSpec(this, _vkCache, {
  42. writable: true,
  43. value: void 0
  44. });
  45. _classPrivateFieldInitSpec(this, _tlCache, {
  46. writable: true,
  47. value: void 0
  48. });
  49. _classPrivateFieldSet(this, _send, send);
  50. }
  51. getVersion() {
  52. var _classPrivateFieldGet2;
  53. return (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _vCache)) != null ? _classPrivateFieldGet2 : _classPrivateFieldSet(this, _vCache, _classPrivateFieldGet(this, _send).call(this, ACTIONS.GET_VERSION, undefined));
  54. }
  55. getTypesInfo() {
  56. var _classPrivateFieldGet3;
  57. return (_classPrivateFieldGet3 = _classPrivateFieldGet(this, _tiCache)) != null ? _classPrivateFieldGet3 : _classPrivateFieldSet(this, _tiCache, _classPrivateFieldGet(this, _send).call(this, ACTIONS.GET_TYPES_INFO, undefined));
  58. }
  59. getVisitorKeys() {
  60. var _classPrivateFieldGet4;
  61. return (_classPrivateFieldGet4 = _classPrivateFieldGet(this, _vkCache)) != null ? _classPrivateFieldGet4 : _classPrivateFieldSet(this, _vkCache, _classPrivateFieldGet(this, _send).call(this, ACTIONS.GET_VISITOR_KEYS, undefined));
  62. }
  63. getTokLabels() {
  64. var _classPrivateFieldGet5;
  65. return (_classPrivateFieldGet5 = _classPrivateFieldGet(this, _tlCache)) != null ? _classPrivateFieldGet5 : _classPrivateFieldSet(this, _tlCache, _classPrivateFieldGet(this, _send).call(this, ACTIONS.GET_TOKEN_LABELS, undefined));
  66. }
  67. maybeParse(code, options) {
  68. return _classPrivateFieldGet(this, _send).call(this, ACTIONS.MAYBE_PARSE, {
  69. code,
  70. options
  71. });
  72. }
  73. }
  74. exports.WorkerClient = (_temp = (_worker = new WeakMap(), _signal = new WeakMap(), _class = class WorkerClient extends Client {
  75. constructor() {
  76. super((action, payload) => {
  77. _classPrivateFieldGet(this, _signal)[0] = 0;
  78. const subChannel = new (_classStaticPrivateFieldSpecGet(WorkerClient, _class, _worker_threads).MessageChannel)();
  79. _classPrivateFieldGet(this, _worker).postMessage({
  80. signal: _classPrivateFieldGet(this, _signal),
  81. port: subChannel.port1,
  82. action,
  83. payload
  84. }, [subChannel.port1]);
  85. Atomics.wait(_classPrivateFieldGet(this, _signal), 0, 0);
  86. const {
  87. message
  88. } = _classStaticPrivateFieldSpecGet(WorkerClient, _class, _worker_threads).receiveMessageOnPort(subChannel.port2);
  89. if (message.error) throw Object.assign(message.error, message.errorData);else return message.result;
  90. });
  91. _classPrivateFieldInitSpec(this, _worker, {
  92. writable: true,
  93. value: new (_classStaticPrivateFieldSpecGet(WorkerClient, _class, _worker_threads).Worker)(path.resolve(__dirname, "../lib/worker/index.cjs"), {
  94. env: _classStaticPrivateFieldSpecGet(WorkerClient, _class, _worker_threads).SHARE_ENV
  95. })
  96. });
  97. _classPrivateFieldInitSpec(this, _signal, {
  98. writable: true,
  99. value: new Int32Array(new SharedArrayBuffer(4))
  100. });
  101. _classPrivateFieldGet(this, _worker).unref();
  102. }
  103. }), _worker_threads = {
  104. get: _get_worker_threads,
  105. set: void 0
  106. }, _worker_threads_cache = {
  107. writable: true,
  108. value: void 0
  109. }, _temp);
  110. function _get_worker_threads() {
  111. var _classStaticPrivateFi2;
  112. return (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_class, _class, _worker_threads_cache)) != null ? _classStaticPrivateFi2 : _classStaticPrivateFieldSpecSet(_class, _class, _worker_threads_cache, require("worker_threads"));
  113. }
  114. {
  115. var _class2, _temp2, _handleMessage;
  116. exports.LocalClient = (_temp2 = _class2 = class LocalClient extends Client {
  117. constructor() {
  118. var _classStaticPrivateFi;
  119. (_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(LocalClient, _class2, _handleMessage)) != null ? _classStaticPrivateFi : _classStaticPrivateFieldSpecSet(LocalClient, _class2, _handleMessage, require("./worker/handle-message.cjs"));
  120. super((action, payload) => {
  121. return _classStaticPrivateFieldSpecGet(LocalClient, _class2, _handleMessage).call(LocalClient, action === ACTIONS.MAYBE_PARSE ? ACTIONS.MAYBE_PARSE_SYNC : action, payload);
  122. });
  123. }
  124. }, _handleMessage = {
  125. writable: true,
  126. value: void 0
  127. }, _temp2);
  128. }