@dxos/context 0.8.4-main.fffef41 → 0.8.4-staging.ac66bdf99f
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.
- package/dist/lib/browser/index.mjs +57 -6
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +57 -6
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/context.d.ts +4 -3
- package/dist/types/src/context.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/resource.d.ts +1 -0
- package/dist/types/src/resource.d.ts.map +1 -1
- package/dist/types/src/trace-context.d.ts +54 -0
- package/dist/types/src/trace-context.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -6
- package/src/context.ts +17 -4
- package/src/index.ts +1 -0
- package/src/resource.ts +6 -1
- package/src/trace-context.ts +72 -0
|
@@ -2,7 +2,7 @@ import { inspect } from 'node:util';
|
|
|
2
2
|
import { type CallMetadata } from '@dxos/log';
|
|
3
3
|
export type ContextErrorHandler = (error: Error, ctx: Context) => void;
|
|
4
4
|
export type DisposeCallback = () => any | Promise<any>;
|
|
5
|
-
export type
|
|
5
|
+
export type CreateContextProps = {
|
|
6
6
|
name?: string;
|
|
7
7
|
parent?: Context;
|
|
8
8
|
attributes?: Record<string, any>;
|
|
@@ -15,9 +15,10 @@ export declare class Context {
|
|
|
15
15
|
#private;
|
|
16
16
|
static default(): Context;
|
|
17
17
|
maxSafeDisposeCallbacks: number;
|
|
18
|
-
constructor(params?:
|
|
18
|
+
constructor(params?: CreateContextProps, callMeta?: Partial<CallMetadata>);
|
|
19
19
|
get disposed(): boolean;
|
|
20
20
|
get disposeCallbacksLength(): number;
|
|
21
|
+
get signal(): AbortSignal;
|
|
21
22
|
/**
|
|
22
23
|
* Schedules a callback to run when the context is disposed.
|
|
23
24
|
* May be async, in this case the disposer might choose to wait for all resource to released.
|
|
@@ -43,7 +44,7 @@ export declare class Context {
|
|
|
43
44
|
* IF the error handler is not set, the error will dispose the context and cause an unhandled rejection.
|
|
44
45
|
*/
|
|
45
46
|
raise(error: Error): void;
|
|
46
|
-
derive({ onError, attributes }?:
|
|
47
|
+
derive({ onError, attributes }?: CreateContextProps): Context;
|
|
47
48
|
getAttribute(key: string): any;
|
|
48
49
|
[Symbol.toStringTag]: string;
|
|
49
50
|
[inspect.custom]: () => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/context.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,KAAK,YAAY,EAAO,MAAM,WAAW,CAAC;AAKnD,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;AAEvE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAEvD,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/context.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,KAAK,YAAY,EAAO,MAAM,WAAW,CAAC;AAKnD,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;AAEvE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAEvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B,CAAC;AA6BF;;GAEG;AACH,qBACa,OAAO;;IAClB,MAAM,CAAC,OAAO,IAAI,OAAO;IAgBlB,uBAAuB,SAA8B;gBAEhD,MAAM,GAAE,kBAAuB,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC;IAuB7E,IAAI,QAAQ,YAEX;IAED,IAAI,sBAAsB,WAEzB;IAED,IAAI,MAAM,IAAI,WAAW,CAQxB;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAgChD;;;;;;;OAOG;IACG,OAAO,CAAC,YAAY,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAqDrD;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAezB,MAAM,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,GAAE,kBAAuB,GAAG,OAAO;IAuBjE,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IAW9B,CAAC,MAAM,CAAC,WAAW,CAAC,SAAa;IACjC,CAAC,OAAO,CAAC,MAAM,CAAC,eAAyB;IAEzC,QAAQ,IAAI,MAAM;IAIZ,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/resource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/resource.ts"],"names":[],"mappings":"AAIA,OAAO,kCAAkC,CAAC;AAI1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,oBAAY,cAAc;IACxB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACzC,KAAK,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;CAC9B;AAKD;;GAEG;AACH,8BAAsB,QAAS,YAAW,SAAS;;IAmBjD;;;;;;OAMG;IACG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5C,IAAI,MAAM,YAET;IAED,SAAS,KAAK,eAAe,mBAE5B;IAED,SAAS,KAAK,IAAI,YAEjB;IAED;;OAEG;cACa,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnD;;OAEG;cACa,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAEpD;;;OAGG;cACa,MAAM,CAAC,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjD;;;;OAIG;IACG,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAS5D;;;;;;OAMG;IACG,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAcxC;;;OAGG;IACG,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IASzC;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAiDrC;AAED,eAAO,MAAM,aAAa,GAAU,CAAC,SAAS,SAAS,EAAE,KAAK,OAAO,EAAE,UAAU,CAAC,KAAG,OAAO,CAAC,CAAC,CAI7F,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Context } from './context';
|
|
2
|
+
/**
|
|
3
|
+
* Context attribute key for trace context data.
|
|
4
|
+
* Stores {@link TraceContextData} (W3C traceparent/tracestate strings).
|
|
5
|
+
*/
|
|
6
|
+
export declare const TRACE_SPAN_ATTRIBUTE = "dxos.trace-span";
|
|
7
|
+
/**
|
|
8
|
+
* W3C Trace Context wire format for propagating trace identity.
|
|
9
|
+
* Stored on DXOS {@link Context} attributes and carried across RPC boundaries.
|
|
10
|
+
*
|
|
11
|
+
* Because these are plain strings (not live runtime objects), they remain valid
|
|
12
|
+
* after the originating span ends — enabling long-lived contexts (`this._ctx`)
|
|
13
|
+
* to serve as parents for later child spans without a retention cache.
|
|
14
|
+
*
|
|
15
|
+
* @see https://www.w3.org/TR/trace-context/
|
|
16
|
+
*/
|
|
17
|
+
export type TraceContextData = {
|
|
18
|
+
/**
|
|
19
|
+
* W3C `traceparent` header value.
|
|
20
|
+
* Format: `{version}-{traceId}-{spanId}-{traceFlags}` (e.g., `00-abc...def-012...789-01`).
|
|
21
|
+
*/
|
|
22
|
+
traceparent: string;
|
|
23
|
+
/** Optional W3C `tracestate` header value carrying vendor-specific trace data. */
|
|
24
|
+
tracestate?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Codec for propagating trace identity across RPC boundaries.
|
|
28
|
+
*
|
|
29
|
+
* Hardcoded in `RpcPeer` — every outgoing request calls {@link encode} to
|
|
30
|
+
* extract W3C trace context from the DXOS `Context`, and every incoming
|
|
31
|
+
* request calls {@link decode} to reconstruct a DXOS `Context` carrying the
|
|
32
|
+
* caller's trace context.
|
|
33
|
+
*
|
|
34
|
+
* This works because `TRACE_SPAN_ATTRIBUTE` stores serializable
|
|
35
|
+
* {@link TraceContextData} strings, not opaque runtime objects.
|
|
36
|
+
*/
|
|
37
|
+
export declare class ContextRpcCodec {
|
|
38
|
+
/**
|
|
39
|
+
* Read the W3C trace context from a DXOS `Context` for an outgoing RPC.
|
|
40
|
+
*
|
|
41
|
+
* @returns `TraceContextData` to attach to the wire message, or `undefined`
|
|
42
|
+
* if the context has no active trace.
|
|
43
|
+
*/
|
|
44
|
+
static encode(ctx: Context): TraceContextData | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Reconstruct a DXOS `Context` from W3C trace context received in an
|
|
47
|
+
* incoming RPC request.
|
|
48
|
+
*
|
|
49
|
+
* @returns A `Context` carrying the trace context, or `Context.default()`
|
|
50
|
+
* if the data is missing/invalid.
|
|
51
|
+
*/
|
|
52
|
+
static decode(traceContext: TraceContextData): Context;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=trace-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-context.d.ts","sourceRoot":"","sources":["../../../src/trace-context.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,qBAAa,eAAe;IAC1B;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS;IAQzD;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,gBAAgB,GAAG,OAAO;CAMvD"}
|