@tstdl/base 0.93.117 → 0.93.119

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.
Files changed (42) hide show
  1. package/api/server/gateway.js +2 -2
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/internal.d.ts +1 -0
  5. package/internal.js +1 -0
  6. package/notification/api/notification.api.d.ts +22 -10
  7. package/notification/api/notification.api.js +9 -3
  8. package/notification/client/notification-client.d.ts +2 -0
  9. package/notification/client/notification-client.js +7 -0
  10. package/notification/server/api/notification.api-controller.d.ts +3 -0
  11. package/notification/server/api/notification.api-controller.js +5 -0
  12. package/notification/server/services/notification-type.service.d.ts +1 -0
  13. package/notification/server/services/notification-type.service.js +5 -0
  14. package/notification/server/services/notification.service.d.ts +2 -0
  15. package/notification/server/services/notification.service.js +9 -2
  16. package/notification/tests/notification-api.test.js +8 -0
  17. package/notification/tests/notification-sse.service.test.js +9 -0
  18. package/notification/tests/unit/notification-client.test.d.ts +1 -0
  19. package/notification/tests/unit/notification-client.test.js +112 -0
  20. package/object-storage/object-storage.d.ts +10 -0
  21. package/object-storage/s3/s3.object-storage-provider.d.ts +11 -4
  22. package/object-storage/s3/s3.object-storage-provider.js +29 -26
  23. package/object-storage/s3/s3.object-storage.d.ts +8 -4
  24. package/object-storage/s3/s3.object-storage.js +148 -60
  25. package/object-storage/s3/s3.object.d.ts +6 -0
  26. package/object-storage/s3/s3.object.js +1 -1
  27. package/object-storage/s3/tests/s3.object-storage.integration.test.d.ts +1 -0
  28. package/object-storage/s3/tests/s3.object-storage.integration.test.js +334 -0
  29. package/package.json +3 -2
  30. package/rpc/adapters/readable-stream.adapter.js +27 -22
  31. package/rpc/endpoints/message-port.rpc-endpoint.d.ts +4 -0
  32. package/rpc/endpoints/message-port.rpc-endpoint.js +4 -0
  33. package/rpc/model.d.ts +11 -1
  34. package/rpc/rpc.d.ts +17 -1
  35. package/rpc/rpc.endpoint.js +4 -3
  36. package/rpc/rpc.error.d.ts +5 -1
  37. package/rpc/rpc.error.js +16 -3
  38. package/rpc/rpc.js +89 -15
  39. package/rpc/tests/rpc.integration.test.d.ts +1 -0
  40. package/rpc/tests/rpc.integration.test.js +619 -0
  41. package/unit-test/integration-setup.d.ts +1 -0
  42. package/unit-test/integration-setup.js +12 -0
package/rpc/rpc.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { NotFoundError } from '../errors/not-found.error.js';
4
4
  import { NotImplementedError } from '../errors/not-implemented.error.js';
5
5
  import { NotSupportedError } from '../errors/not-supported.error.js';
6
+ import { internal } from '../internal.js';
6
7
  import { deserialize, registerSerializer, serialize } from '../serializer/index.js';
7
8
  import { valueOfType } from '../utils/helpers.js';
8
9
  import { hasOwnProperty } from '../utils/object/object.js';
@@ -16,31 +17,31 @@ const adapters = new Map();
16
17
  const adapterTargets = new WeakMap();
17
18
  const proxyTargets = new WeakSet();
18
19
  const exposings = new Map();
20
+ const proxyChannels = new WeakMap();
19
21
  const channelFinalizationRegistry = new FinalizationRegistry((data) => data.channel.close());
20
22
  class RpcProxy {
21
23
  }
22
- // eslint-disable-next-line @typescript-eslint/no-redeclare, @typescript-eslint/naming-convention
23
24
  export const Rpc = {
24
25
  listen(endpoint) {
25
26
  const controlChannel = endpoint.getChannel('control');
26
27
  controlChannel.request$.subscribe(async ({ id: messageId, data: message }) => {
27
- switch (message.type) {
28
- case 'connect': {
29
- try {
28
+ try {
29
+ switch (message.type) {
30
+ case 'connect': {
30
31
  const exposing = exposings.get(message.name);
31
32
  if (isUndefined(exposing)) {
32
33
  throw new NotFoundError(`Could not connect to "${message.name}" as nothing with that name is exposed.`);
33
34
  }
34
35
  const value = getAdapterOrProxy(exposing, endpoint);
35
36
  await controlChannel.respond(messageId, value);
37
+ break;
36
38
  }
37
- catch (error) {
38
- await controlChannel.respond(messageId, { type: 'throw', error });
39
- }
40
- break;
39
+ default:
40
+ throw new NotSupportedError(`Message type ${message.type} not supported in listen.`);
41
41
  }
42
- default:
43
- throw new NotSupportedError(`Message type ${message.type} not supported in listen.`);
42
+ }
43
+ catch (error) {
44
+ await controlChannel.respond(messageId, { type: 'throw', error: serialize(error) });
44
45
  }
45
46
  });
46
47
  },
@@ -93,10 +94,37 @@ export const Rpc = {
93
94
  },
94
95
  isProxied(object) {
95
96
  return proxyTargets.has(object);
96
- }
97
+ },
98
+ release(proxy) {
99
+ const channel = proxyChannels.get(proxy);
100
+ if (isDefined(channel)) {
101
+ channel.close();
102
+ proxyChannels.delete(proxy);
103
+ }
104
+ },
105
+ isAlive(proxy) {
106
+ const channel = proxyChannels.get(proxy);
107
+ return isDefined(channel);
108
+ },
109
+ async set(proxy, property, value) {
110
+ await Reflect.set(proxy, property, value);
111
+ },
112
+ async delete(proxy, property) {
113
+ return await Reflect.deleteProperty(proxy, property);
114
+ },
115
+ async has(proxy, property) {
116
+ return await Reflect.has(proxy, property);
117
+ },
118
+ reset() {
119
+ exposings.clear();
120
+ },
121
+ [internal]: {
122
+ parseRpcMessageValue: parseRpcMessageValue,
123
+ adapters: adapters,
124
+ RpcProxy: RpcProxy,
125
+ },
97
126
  };
98
127
  function createProxy(channel, path = []) {
99
- // eslint-disable-next-line prefer-const
100
128
  let proxy;
101
129
  const { endpoint } = channel;
102
130
  const handlers = {
@@ -128,9 +156,25 @@ function createProxy(channel, path = []) {
128
156
  .request({ type: 'set', path: [...path, property], value: postMessageData.value }, postMessageData.transfer)
129
157
  .then((responseValue) => parseRpcMessageValue(responseValue, endpoint));
130
158
  },
159
+ deleteProperty(_target, property) {
160
+ return channel
161
+ .request({ type: 'deleteProperty', path: [...path, property] })
162
+ .then((responseValue) => parseRpcMessageValue(responseValue, endpoint));
163
+ },
164
+ defineProperty(_target, property, attributes) {
165
+ const postMessageData = getPostMessageData(attributes, endpoint);
166
+ return channel
167
+ .request({ type: 'defineProperty', path: [...path, property], attributes: postMessageData.value }, postMessageData.transfer)
168
+ .then((responseValue) => parseRpcMessageValue(responseValue, endpoint));
169
+ },
170
+ has(_target, property) {
171
+ return channel
172
+ .request({ type: 'has', path: [...path, property] })
173
+ .then((responseValue) => parseRpcMessageValue(responseValue, endpoint));
174
+ },
131
175
  getPrototypeOf() {
132
176
  return null;
133
- }
177
+ },
134
178
  };
135
179
  for (const method of reflectMethods) {
136
180
  if (!hasOwnProperty(handlers, method)) {
@@ -172,12 +216,34 @@ function exposeObject(object, channel) {
172
216
  await channel.respond(messageId, postMessageData.value, postMessageData.transfer);
173
217
  break;
174
218
  }
219
+ case 'deleteProperty': {
220
+ const { value } = deref(object, message.path, true);
221
+ const result = Reflect.deleteProperty(value, message.path[message.path.length - 1]);
222
+ const postMessageData = getPostMessageData(result, endpoint);
223
+ await channel.respond(messageId, postMessageData.value, postMessageData.transfer);
224
+ break;
225
+ }
226
+ case 'defineProperty': {
227
+ const { value } = deref(object, message.path, true);
228
+ const attributes = parseRpcMessageValue(message.attributes, channel.endpoint);
229
+ const result = Reflect.defineProperty(value, message.path[message.path.length - 1], attributes);
230
+ const postMessageData = getPostMessageData(result, endpoint);
231
+ await channel.respond(messageId, postMessageData.value, postMessageData.transfer);
232
+ break;
233
+ }
234
+ case 'has': {
235
+ const { parent, value } = deref(object, message.path, true);
236
+ const result = Reflect.has(parent ?? value, message.path[message.path.length - 1]);
237
+ const postMessageData = getPostMessageData(result, endpoint);
238
+ await channel.respond(messageId, postMessageData.value, postMessageData.transfer);
239
+ break;
240
+ }
175
241
  default:
176
242
  throw new NotImplementedError(`Unsupported message type ${message.type}.`);
177
243
  }
178
244
  }
179
245
  catch (error) {
180
- await channel.respond(messageId, { type: 'throw', error });
246
+ await channel.respond(messageId, { type: 'throw', error: serialize(error) });
181
247
  }
182
248
  });
183
249
  }
@@ -240,11 +306,18 @@ function parseRpcMessageValue(value, endpoint) {
240
306
  }
241
307
  case 'throw': {
242
308
  const remoteError = new RpcRemoteError(value.error);
243
- throw new RpcError(`Received error from remote: ${remoteError.message}`, remoteError);
309
+ const rpcError = new RpcError(`Received error from remote: ${remoteError.message}`, remoteError);
310
+ for (const [key, val] of Object.entries(remoteError)) {
311
+ if (!(key in rpcError)) {
312
+ rpcError[key] = val;
313
+ }
314
+ }
315
+ throw rpcError;
244
316
  }
245
317
  case 'proxy': {
246
318
  const channel = endpoint.getChannel(value.channel);
247
319
  const proxy = createProxy(channel);
320
+ proxyChannels.set(proxy, channel);
248
321
  channelFinalizationRegistry.register(proxy, { channel });
249
322
  return proxy;
250
323
  }
@@ -255,6 +328,7 @@ function parseRpcMessageValue(value, endpoint) {
255
328
  throw new NotSupportedError(`No adapter registration for "${value.adapter}" found.`);
256
329
  }
257
330
  const adaptedValue = adapter.adaptTarget(value.data, channel);
331
+ proxyChannels.set(adaptedValue, channel);
258
332
  channelFinalizationRegistry.register(adaptedValue, { channel });
259
333
  return adaptedValue;
260
334
  }
@@ -0,0 +1 @@
1
+ export {};