@standardserver/core 0.0.2 → 0.0.4
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.
|
@@ -59,21 +59,20 @@ declare class EventIteratorErrorEvent extends Error {
|
|
|
59
59
|
constructor(data: unknown, options?: EventIteratorErrorEventOptions);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
declare const
|
|
62
|
+
declare const EVENT_ITERATOR_EVENT_META_SYMBOL: symbol;
|
|
63
|
+
declare const EVENT_ITERATOR_EVENT_SOURCE_SYMBOL: symbol;
|
|
63
64
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @info The returned container is a proxy that intercepts access to the meta symbol.
|
|
65
|
+
* Returns a new iterator *event value* with attached, validated metadata.
|
|
67
66
|
*/
|
|
68
67
|
declare function withEventIteratorEventMeta<T extends object>(container: T, meta: EventStreamMessageMeta): T;
|
|
69
68
|
/**
|
|
70
|
-
*
|
|
69
|
+
* Unwraps an iterator event value and extracts its associated metadata.
|
|
71
70
|
*/
|
|
72
|
-
declare function
|
|
71
|
+
declare function unwrapEventIteratorEvent<T>(container: T): [data: T, meta: EventStreamMessageMeta | undefined];
|
|
73
72
|
/**
|
|
74
|
-
* Retrieves
|
|
73
|
+
* Retrieves metadata attached to a single iterator event value.
|
|
75
74
|
*/
|
|
76
75
|
declare function getEventIteratorEventMeta(container: unknown): EventStreamMessageMeta | undefined;
|
|
77
76
|
|
|
78
|
-
export {
|
|
77
|
+
export { EVENT_ITERATOR_EVENT_META_SYMBOL, EVENT_ITERATOR_EVENT_SOURCE_SYMBOL, EventIteratorErrorEvent, EventStreamDecoder, EventStreamDecoderError, EventStreamDecoderStream, EventStreamEncoderError, assertEventStreamMessageComment, assertEventStreamMessageId, assertEventStreamMessageName, assertEventStreamMessageRetry, decodeEventStreamMessage, encodeEventStreamMessage, encodeEventStreamMessageComments, encodeEventStreamMessageData, getEventIteratorEventMeta, unwrapEventIteratorEvent, withEventIteratorEventMeta };
|
|
79
78
|
export type { EventIteratorErrorEventOptions, EventStreamMessage, EventStreamMessageMeta };
|
|
@@ -59,21 +59,20 @@ declare class EventIteratorErrorEvent extends Error {
|
|
|
59
59
|
constructor(data: unknown, options?: EventIteratorErrorEventOptions);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
declare const
|
|
62
|
+
declare const EVENT_ITERATOR_EVENT_META_SYMBOL: symbol;
|
|
63
|
+
declare const EVENT_ITERATOR_EVENT_SOURCE_SYMBOL: symbol;
|
|
63
64
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @info The returned container is a proxy that intercepts access to the meta symbol.
|
|
65
|
+
* Returns a new iterator *event value* with attached, validated metadata.
|
|
67
66
|
*/
|
|
68
67
|
declare function withEventIteratorEventMeta<T extends object>(container: T, meta: EventStreamMessageMeta): T;
|
|
69
68
|
/**
|
|
70
|
-
*
|
|
69
|
+
* Unwraps an iterator event value and extracts its associated metadata.
|
|
71
70
|
*/
|
|
72
|
-
declare function
|
|
71
|
+
declare function unwrapEventIteratorEvent<T>(container: T): [data: T, meta: EventStreamMessageMeta | undefined];
|
|
73
72
|
/**
|
|
74
|
-
* Retrieves
|
|
73
|
+
* Retrieves metadata attached to a single iterator event value.
|
|
75
74
|
*/
|
|
76
75
|
declare function getEventIteratorEventMeta(container: unknown): EventStreamMessageMeta | undefined;
|
|
77
76
|
|
|
78
|
-
export {
|
|
77
|
+
export { EVENT_ITERATOR_EVENT_META_SYMBOL, EVENT_ITERATOR_EVENT_SOURCE_SYMBOL, EventIteratorErrorEvent, EventStreamDecoder, EventStreamDecoderError, EventStreamDecoderStream, EventStreamEncoderError, assertEventStreamMessageComment, assertEventStreamMessageId, assertEventStreamMessageName, assertEventStreamMessageRetry, decodeEventStreamMessage, encodeEventStreamMessage, encodeEventStreamMessageComments, encodeEventStreamMessageData, getEventIteratorEventMeta, unwrapEventIteratorEvent, withEventIteratorEventMeta };
|
|
79
78
|
export type { EventIteratorErrorEventOptions, EventStreamMessage, EventStreamMessageMeta };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getPackageSymbol,
|
|
1
|
+
import { getPackageSymbol, getOrBind, isTypescriptObject } from '@standardserver/shared';
|
|
2
2
|
|
|
3
3
|
class EventStreamEncoderError extends TypeError {
|
|
4
4
|
}
|
|
@@ -147,7 +147,8 @@ function encodeEventStreamMessage(message) {
|
|
|
147
147
|
return output;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
const
|
|
150
|
+
const EVENT_ITERATOR_EVENT_META_SYMBOL = getPackageSymbol("EVENT_ITERATOR_EVENT_META");
|
|
151
|
+
const EVENT_ITERATOR_EVENT_SOURCE_SYMBOL = getPackageSymbol("EVENT_ITERATOR_EVENT_SOURCE");
|
|
151
152
|
function withEventIteratorEventMeta(container, meta) {
|
|
152
153
|
let assertedMeta;
|
|
153
154
|
if (meta.id !== void 0) {
|
|
@@ -170,28 +171,31 @@ function withEventIteratorEventMeta(container, meta) {
|
|
|
170
171
|
if (!assertedMeta) {
|
|
171
172
|
return container;
|
|
172
173
|
}
|
|
173
|
-
return
|
|
174
|
-
get(
|
|
175
|
-
if (prop ===
|
|
174
|
+
return new Proxy(container, {
|
|
175
|
+
get(target, prop, _receiver) {
|
|
176
|
+
if (prop === EVENT_ITERATOR_EVENT_SOURCE_SYMBOL) {
|
|
177
|
+
return target;
|
|
178
|
+
}
|
|
179
|
+
if (prop === EVENT_ITERATOR_EVENT_META_SYMBOL) {
|
|
176
180
|
return assertedMeta;
|
|
177
181
|
}
|
|
178
|
-
return
|
|
182
|
+
return getOrBind(target, prop);
|
|
179
183
|
}
|
|
180
184
|
});
|
|
181
185
|
}
|
|
182
|
-
function
|
|
186
|
+
function unwrapEventIteratorEvent(container) {
|
|
183
187
|
if (!isTypescriptObject(container)) {
|
|
184
188
|
return [container, void 0];
|
|
185
189
|
}
|
|
186
|
-
const meta =
|
|
187
|
-
const target =
|
|
190
|
+
const meta = container[EVENT_ITERATOR_EVENT_META_SYMBOL];
|
|
191
|
+
const target = container[EVENT_ITERATOR_EVENT_SOURCE_SYMBOL] ?? container;
|
|
188
192
|
return [target, meta];
|
|
189
193
|
}
|
|
190
194
|
function getEventIteratorEventMeta(container) {
|
|
191
195
|
if (!isTypescriptObject(container)) {
|
|
192
196
|
return void 0;
|
|
193
197
|
}
|
|
194
|
-
return
|
|
198
|
+
return container[EVENT_ITERATOR_EVENT_META_SYMBOL];
|
|
195
199
|
}
|
|
196
200
|
|
|
197
|
-
export {
|
|
201
|
+
export { EVENT_ITERATOR_EVENT_META_SYMBOL, EVENT_ITERATOR_EVENT_SOURCE_SYMBOL, EventIteratorErrorEvent, EventStreamDecoder, EventStreamDecoderError, EventStreamDecoderStream, EventStreamEncoderError, assertEventStreamMessageComment, assertEventStreamMessageId, assertEventStreamMessageName, assertEventStreamMessageRetry, decodeEventStreamMessage, encodeEventStreamMessage, encodeEventStreamMessageComments, encodeEventStreamMessageData, getEventIteratorEventMeta, unwrapEventIteratorEvent, withEventIteratorEventMeta };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standardserver/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://standardserver.dev",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@standardserver/shared": "0.0.
|
|
28
|
+
"@standardserver/shared": "0.0.4"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "unbuild",
|