ajanuw-context 1.0.0
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/README.md +152 -0
- package/dist/esm/context.d.ts +21 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +95 -0
- package/dist/esm/interface.d.ts +43 -0
- package/dist/umd/context.d.ts +21 -0
- package/dist/umd/index.d.ts +2 -0
- package/dist/umd/index.js +1 -0
- package/dist/umd/interface.d.ts +43 -0
- package/package.json +71 -0
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# ajanuw-context
|
|
2
|
+
|
|
3
|
+
A modern, lightweight TypeScript implementation of Go's `context` pattern, designed to manage propagation of deadlines, cancellation signals, and request-scoped values across asynchronous operations.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Go-Style Context API**: Fully models Go's structured concurrency control.
|
|
8
|
+
- 📦 **Modern Bundle**: Offers built-in ESM (with tree-shaking support) and UMD targets.
|
|
9
|
+
- ⏱️ **Automatic Cleanups**: Clean propagation of timeouts and manual cancellations down the context tree.
|
|
10
|
+
- 🔒 **Type-Safe**: Written in TypeScript with complete auto-generated type definitions.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Using pnpm
|
|
18
|
+
pnpm add ajanuw-context
|
|
19
|
+
|
|
20
|
+
# Using npm
|
|
21
|
+
npm install ajanuw-context
|
|
22
|
+
|
|
23
|
+
# Using yarn
|
|
24
|
+
yarn add ajanuw-context
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick Start & Examples
|
|
30
|
+
|
|
31
|
+
### 1. Basic Cancellation (`WithCancel`)
|
|
32
|
+
|
|
33
|
+
Perfect for stopping pending tasks when an operation is cancelled or no longer needed.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { Background, WithCancel } from "ajanuw-context";
|
|
37
|
+
|
|
38
|
+
// Create a cancellable context from the root Background context
|
|
39
|
+
const [ctx, cancel] = WithCancel(Background);
|
|
40
|
+
|
|
41
|
+
async function performTask(ctx) {
|
|
42
|
+
// Simulating an async loop
|
|
43
|
+
for (let i = 0; i < 10; i++) {
|
|
44
|
+
if (ctx.err()) {
|
|
45
|
+
console.log("Task aborted:", ctx.err().message); // "context canceled"
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.log(`Processing step ${i}...`);
|
|
49
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
performTask(ctx);
|
|
54
|
+
|
|
55
|
+
// Trigger cancellation after 1.2 seconds
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
cancel();
|
|
58
|
+
}, 1200);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. Time-Bound Execution (`WithTimeout` / `WithDeadline`)
|
|
62
|
+
|
|
63
|
+
Useful for preventing tasks from hanging indefinitely (e.g. HTTP requests, DB queries).
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { Background, WithTimeout } from "ajanuw-context";
|
|
67
|
+
|
|
68
|
+
const [ctx, cancel] = WithTimeout(Background, 2000); // 2-second timeout
|
|
69
|
+
|
|
70
|
+
async function fetchWithContext(ctx, url) {
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
|
|
73
|
+
// Abort the fetch request if context gets cancelled/timed out
|
|
74
|
+
ctx.done().then(() => {
|
|
75
|
+
controller.abort();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
80
|
+
return await response.json();
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (ctx.err()) {
|
|
83
|
+
throw new Error(`Request timed out: ${ctx.err().message}`); // "context deadline exceeded"
|
|
84
|
+
}
|
|
85
|
+
throw error;
|
|
86
|
+
} finally {
|
|
87
|
+
// Release resources
|
|
88
|
+
cancel();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 3. Request-Scoped Value Propagation (`WithValue`)
|
|
94
|
+
|
|
95
|
+
Pass request-specific values (like Trace ID, Auth Tokens) down the call stack.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { Background, WithValue } from "ajanuw-context";
|
|
99
|
+
|
|
100
|
+
const TRACE_ID_KEY = Symbol("TraceID");
|
|
101
|
+
|
|
102
|
+
// Attach value to the context tree
|
|
103
|
+
const rootCtx = WithValue(Background, TRACE_ID_KEY, "req-123456");
|
|
104
|
+
|
|
105
|
+
function handleRequest(ctx) {
|
|
106
|
+
// Retrieve value from context anywhere in the call hierarchy
|
|
107
|
+
const traceId = ctx.value(TRACE_ID_KEY);
|
|
108
|
+
console.log("Current Trace ID:", traceId); // "req-123456"
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
handleRequest(rootCtx);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## API Reference
|
|
117
|
+
|
|
118
|
+
### Interfaces
|
|
119
|
+
|
|
120
|
+
#### `Context`
|
|
121
|
+
The core interface that passes deadlines, cancellation signals, and key-value attributes.
|
|
122
|
+
- **`deadline(): [Date, boolean]`**: Returns the time when work done on behalf of this context should be cancelled.
|
|
123
|
+
- **`done(): Promise<void>`**: Returns a promise that resolves when work done on behalf of this context is cancelled.
|
|
124
|
+
- **`err(): Error | null`**: Returns `Canceled` or `DeadlineExceeded` if the context has been cancelled. Returns `null` if the context is still active.
|
|
125
|
+
- **`value<T>(key: unknown): T | null`**: Looks up a key-value pair associated with the context tree.
|
|
126
|
+
|
|
127
|
+
### Core Helpers
|
|
128
|
+
|
|
129
|
+
#### `Background: Context`
|
|
130
|
+
Returns a non-null, empty `Context`. It is never cancelled, has no values, and has no deadline. Usually used as the root context.
|
|
131
|
+
|
|
132
|
+
#### `WithCancel(parent: Context): [Context, CancelFunc]`
|
|
133
|
+
Returns a copy of `parent` with a new `done` promise. The returned context's `done` promise is resolved when the returned `CancelFunc` is called or when the parent context's `done` promise is resolved, whichever happens first.
|
|
134
|
+
|
|
135
|
+
#### `WithValue(parent: Context, key: unknown, val: unknown): Context`
|
|
136
|
+
Returns a copy of `parent` in which the association of `key` with `val` is stored.
|
|
137
|
+
|
|
138
|
+
#### `WithDeadline(parent: Context, deadline: Date): [Context, CancelFunc]`
|
|
139
|
+
Returns a copy of `parent` with the deadline adjusted to be no later than `deadline`.
|
|
140
|
+
|
|
141
|
+
#### `WithTimeout(parent: Context, timeoutMs: number): [Context, CancelFunc]`
|
|
142
|
+
Returns `WithDeadline(parent, new Date(Date.now() + timeoutMs))`.
|
|
143
|
+
|
|
144
|
+
### Error Instances
|
|
145
|
+
- **`Canceled`**: An `Error` indicating the context was cancelled manually (`new Error("context canceled")`).
|
|
146
|
+
- **`DeadlineExceeded`**: An `Error` indicating the context timed out (`new Error("context deadline exceeded")`).
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CancelFunc, Context, ContextKey } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* Background 返回一个非空的、空的 Context。它永远不会被取消,没有值,也没有截止日期。
|
|
4
|
+
*/
|
|
5
|
+
export declare const Background: Context;
|
|
6
|
+
/**
|
|
7
|
+
* WithCancel 返回父级 Context 的副本,并带有一个新的 Done Promise。
|
|
8
|
+
*/
|
|
9
|
+
export declare function WithCancel(parent: Context): [Context, CancelFunc];
|
|
10
|
+
/**
|
|
11
|
+
* WithValue 返回父级 Context 的副本,并带有新的键值对。
|
|
12
|
+
*/
|
|
13
|
+
export declare function WithValue(parent: Context, key: ContextKey, val: unknown): Context;
|
|
14
|
+
/**
|
|
15
|
+
* WithDeadline 返回父级 Context 的副本,并带有截止日期。
|
|
16
|
+
*/
|
|
17
|
+
export declare function WithDeadline(parent: Context, deadline: Date): [Context, CancelFunc];
|
|
18
|
+
/**
|
|
19
|
+
* WithTimeout 返回 WithDeadline(parent, new Date(Date.now() + timeoutMs))。
|
|
20
|
+
*/
|
|
21
|
+
export declare function WithTimeout(parent: Context, timeoutMs: number): [Context, CancelFunc];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//#region src/interface.ts
|
|
2
|
+
var e = /* @__PURE__ */ Error("context canceled"), t = /* @__PURE__ */ Error("context deadline exceeded"), n = new class {
|
|
3
|
+
deadline() {
|
|
4
|
+
return [/* @__PURE__ */ new Date(0), !1];
|
|
5
|
+
}
|
|
6
|
+
done() {
|
|
7
|
+
return new Promise(() => {});
|
|
8
|
+
}
|
|
9
|
+
err() {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
value(e) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}(), r = class e {
|
|
16
|
+
constructor(t) {
|
|
17
|
+
this._err = null, this._children = /* @__PURE__ */ new Set(), this._parent = t, this._done = new Promise((e) => {
|
|
18
|
+
this._resolveDone = e;
|
|
19
|
+
}), t instanceof e && t.addChild(this), this.propagateCancel(t);
|
|
20
|
+
}
|
|
21
|
+
deadline() {
|
|
22
|
+
return this._parent.deadline();
|
|
23
|
+
}
|
|
24
|
+
done() {
|
|
25
|
+
return this._done;
|
|
26
|
+
}
|
|
27
|
+
err() {
|
|
28
|
+
return this._err;
|
|
29
|
+
}
|
|
30
|
+
value(e) {
|
|
31
|
+
return this._parent.value(e);
|
|
32
|
+
}
|
|
33
|
+
propagateCancel(e) {
|
|
34
|
+
e.done().then(() => {
|
|
35
|
+
let t = e.err();
|
|
36
|
+
t && this.cancel(!1, t);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
cancel(t, n) {
|
|
40
|
+
if (this._err === null) {
|
|
41
|
+
this._err = n, this._resolveDone();
|
|
42
|
+
for (let e of this._children) e.cancel(!1, n);
|
|
43
|
+
this._children.clear(), t && this._parent instanceof e && this._parent.removeChild(this);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
addChild(e) {
|
|
47
|
+
this._children.add(e);
|
|
48
|
+
}
|
|
49
|
+
removeChild(e) {
|
|
50
|
+
this._children.delete(e);
|
|
51
|
+
}
|
|
52
|
+
}, i = class {
|
|
53
|
+
constructor(e, t, n) {
|
|
54
|
+
this.parent = e, this.key = t, this.val = n;
|
|
55
|
+
}
|
|
56
|
+
deadline() {
|
|
57
|
+
return this.parent.deadline();
|
|
58
|
+
}
|
|
59
|
+
done() {
|
|
60
|
+
return this.parent.done();
|
|
61
|
+
}
|
|
62
|
+
err() {
|
|
63
|
+
return this.parent.err();
|
|
64
|
+
}
|
|
65
|
+
value(e) {
|
|
66
|
+
return this.key === e ? this.val : this.parent.value(e);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
function a(t) {
|
|
70
|
+
let n = new r(t);
|
|
71
|
+
return [n, () => n.cancel(!0, e)];
|
|
72
|
+
}
|
|
73
|
+
function o(e, t, n) {
|
|
74
|
+
if (t == null) throw Error("nil key");
|
|
75
|
+
return new i(e, t, n);
|
|
76
|
+
}
|
|
77
|
+
function s(n, i) {
|
|
78
|
+
let [o, s] = n.deadline();
|
|
79
|
+
if (s && o < i) return a(n);
|
|
80
|
+
let c = new r(n), l = i.getTime() - Date.now();
|
|
81
|
+
if (l <= 0) return c.cancel(!0, t), [c, () => {}];
|
|
82
|
+
let u = setTimeout(() => {
|
|
83
|
+
c.cancel(!0, t);
|
|
84
|
+
}, l);
|
|
85
|
+
return [new Proxy(c, { get(e, t, n) {
|
|
86
|
+
return t === "deadline" ? () => [i, !0] : Reflect.get(e, t, n);
|
|
87
|
+
} }), () => {
|
|
88
|
+
clearTimeout(u), c.cancel(!0, e);
|
|
89
|
+
}];
|
|
90
|
+
}
|
|
91
|
+
function c(e, t) {
|
|
92
|
+
return s(e, new Date(Date.now() + t));
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { n as Background, e as Canceled, t as DeadlineExceeded, a as WithCancel, s as WithDeadline, c as WithTimeout, o as WithValue };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type ContextKey = unknown;
|
|
2
|
+
/**
|
|
3
|
+
* Canceled 是当 Context 被取消时,Context.err 返回的错误内容。
|
|
4
|
+
*/
|
|
5
|
+
export declare const Canceled: Error;
|
|
6
|
+
/**
|
|
7
|
+
* DeadlineExceeded 是当 Context 的截止日期过期时,Context.err 返回的错误内容。
|
|
8
|
+
*/
|
|
9
|
+
export declare const DeadlineExceeded: Error;
|
|
10
|
+
/**
|
|
11
|
+
* Context 跨 API 边界传递截止日期、取消信号和其他值。
|
|
12
|
+
*/
|
|
13
|
+
export interface Context {
|
|
14
|
+
/**
|
|
15
|
+
* deadline 返回代表此 Context 完成的工作应被取消的时间。
|
|
16
|
+
* 未设置截止日期时,deadline 返回 [Date(0), false]。
|
|
17
|
+
* 连续调用 deadline 返回相同的结果。
|
|
18
|
+
*/
|
|
19
|
+
deadline(): [Date, boolean];
|
|
20
|
+
/**
|
|
21
|
+
* done 返回一个 Promise,当代表此 Context 完成的工作应被取消时,该 Promise 将被 resolve。
|
|
22
|
+
* 如果此 Context 永远无法被取消,done 可能会返回一个永远不会 resolve 的 Promise。
|
|
23
|
+
* 连续调用 done 返回相同的值。
|
|
24
|
+
*/
|
|
25
|
+
done(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 如果 done 尚未 resolve,err 返回 null。
|
|
28
|
+
* 如果 done 已 resolve,err 返回一个非空错误说明原因:
|
|
29
|
+
* 如果 Context 被取消,则返回 Canceled;
|
|
30
|
+
* 如果 Context 的截止日期过期,则返回 DeadlineExceeded。
|
|
31
|
+
* 在 err 返回非空错误后,连续调用 err 返回同一个错误。
|
|
32
|
+
*/
|
|
33
|
+
err(): Error | null;
|
|
34
|
+
/**
|
|
35
|
+
* value 返回此 Context 中与 key 关联的值,如果没有与 key 关联的值,则返回 null。
|
|
36
|
+
* 使用相同的 key 连续调用 value 返回相同的结果。
|
|
37
|
+
*/
|
|
38
|
+
value<T = unknown>(key: ContextKey): T | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* CancelFunc 指示操作放弃其工作。
|
|
42
|
+
*/
|
|
43
|
+
export type CancelFunc = () => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CancelFunc, Context, ContextKey } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* Background 返回一个非空的、空的 Context。它永远不会被取消,没有值,也没有截止日期。
|
|
4
|
+
*/
|
|
5
|
+
export declare const Background: Context;
|
|
6
|
+
/**
|
|
7
|
+
* WithCancel 返回父级 Context 的副本,并带有一个新的 Done Promise。
|
|
8
|
+
*/
|
|
9
|
+
export declare function WithCancel(parent: Context): [Context, CancelFunc];
|
|
10
|
+
/**
|
|
11
|
+
* WithValue 返回父级 Context 的副本,并带有新的键值对。
|
|
12
|
+
*/
|
|
13
|
+
export declare function WithValue(parent: Context, key: ContextKey, val: unknown): Context;
|
|
14
|
+
/**
|
|
15
|
+
* WithDeadline 返回父级 Context 的副本,并带有截止日期。
|
|
16
|
+
*/
|
|
17
|
+
export declare function WithDeadline(parent: Context, deadline: Date): [Context, CancelFunc];
|
|
18
|
+
/**
|
|
19
|
+
* WithTimeout 返回 WithDeadline(parent, new Date(Date.now() + timeoutMs))。
|
|
20
|
+
*/
|
|
21
|
+
export declare function WithTimeout(parent: Context, timeoutMs: number): [Context, CancelFunc];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.AjanuwContext={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Error(`context canceled`),n=Error(`context deadline exceeded`),r=new class{deadline(){return[new Date(0),!1]}done(){return new Promise(()=>{})}err(){return null}value(e){return null}},i=class e{constructor(t){this._err=null,this._children=new Set,this._parent=t,this._done=new Promise(e=>{this._resolveDone=e}),t instanceof e&&t.addChild(this),this.propagateCancel(t)}deadline(){return this._parent.deadline()}done(){return this._done}err(){return this._err}value(e){return this._parent.value(e)}propagateCancel(e){e.done().then(()=>{let t=e.err();t&&this.cancel(!1,t)})}cancel(t,n){if(this._err===null){this._err=n,this._resolveDone();for(let e of this._children)e.cancel(!1,n);this._children.clear(),t&&this._parent instanceof e&&this._parent.removeChild(this)}}addChild(e){this._children.add(e)}removeChild(e){this._children.delete(e)}},a=class{constructor(e,t,n){this.parent=e,this.key=t,this.val=n}deadline(){return this.parent.deadline()}done(){return this.parent.done()}err(){return this.parent.err()}value(e){return this.key===e?this.val:this.parent.value(e)}};function o(e){let n=new i(e);return[n,()=>n.cancel(!0,t)]}function s(e,t,n){if(t==null)throw Error(`nil key`);return new a(e,t,n)}function c(e,r){let[a,s]=e.deadline();if(s&&a<r)return o(e);let c=new i(e),l=r.getTime()-Date.now();if(l<=0)return c.cancel(!0,n),[c,()=>{}];let u=setTimeout(()=>{c.cancel(!0,n)},l);return[new Proxy(c,{get(e,t,n){return t===`deadline`?()=>[r,!0]:Reflect.get(e,t,n)}}),()=>{clearTimeout(u),c.cancel(!0,t)}]}function l(e,t){return c(e,new Date(Date.now()+t))}e.Background=r,e.Canceled=t,e.DeadlineExceeded=n,e.WithCancel=o,e.WithDeadline=c,e.WithTimeout=l,e.WithValue=s});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type ContextKey = unknown;
|
|
2
|
+
/**
|
|
3
|
+
* Canceled 是当 Context 被取消时,Context.err 返回的错误内容。
|
|
4
|
+
*/
|
|
5
|
+
export declare const Canceled: Error;
|
|
6
|
+
/**
|
|
7
|
+
* DeadlineExceeded 是当 Context 的截止日期过期时,Context.err 返回的错误内容。
|
|
8
|
+
*/
|
|
9
|
+
export declare const DeadlineExceeded: Error;
|
|
10
|
+
/**
|
|
11
|
+
* Context 跨 API 边界传递截止日期、取消信号和其他值。
|
|
12
|
+
*/
|
|
13
|
+
export interface Context {
|
|
14
|
+
/**
|
|
15
|
+
* deadline 返回代表此 Context 完成的工作应被取消的时间。
|
|
16
|
+
* 未设置截止日期时,deadline 返回 [Date(0), false]。
|
|
17
|
+
* 连续调用 deadline 返回相同的结果。
|
|
18
|
+
*/
|
|
19
|
+
deadline(): [Date, boolean];
|
|
20
|
+
/**
|
|
21
|
+
* done 返回一个 Promise,当代表此 Context 完成的工作应被取消时,该 Promise 将被 resolve。
|
|
22
|
+
* 如果此 Context 永远无法被取消,done 可能会返回一个永远不会 resolve 的 Promise。
|
|
23
|
+
* 连续调用 done 返回相同的值。
|
|
24
|
+
*/
|
|
25
|
+
done(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 如果 done 尚未 resolve,err 返回 null。
|
|
28
|
+
* 如果 done 已 resolve,err 返回一个非空错误说明原因:
|
|
29
|
+
* 如果 Context 被取消,则返回 Canceled;
|
|
30
|
+
* 如果 Context 的截止日期过期,则返回 DeadlineExceeded。
|
|
31
|
+
* 在 err 返回非空错误后,连续调用 err 返回同一个错误。
|
|
32
|
+
*/
|
|
33
|
+
err(): Error | null;
|
|
34
|
+
/**
|
|
35
|
+
* value 返回此 Context 中与 key 关联的值,如果没有与 key 关联的值,则返回 null。
|
|
36
|
+
* 使用相同的 key 连续调用 value 返回相同的结果。
|
|
37
|
+
*/
|
|
38
|
+
value<T = unknown>(key: ContextKey): T | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* CancelFunc 指示操作放弃其工作。
|
|
42
|
+
*/
|
|
43
|
+
export type CancelFunc = () => void;
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ajanuw-context",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A lightweight and robust Go-style Context implementation in TypeScript to propagate deadlines, cancellation signals, and request-scoped values.",
|
|
6
|
+
"main": "./dist/umd/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/esm/index.d.ts",
|
|
9
|
+
"unpkg": "./dist/umd/index.js",
|
|
10
|
+
"jsdelivr": "./dist/umd/index.js",
|
|
11
|
+
"homepage": "https://github.com/januwA/ajanuw-context#readme",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/januwA/ajanuw-context.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/januwA/ajanuw-context/issues"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/esm/index.d.ts",
|
|
22
|
+
"import": "./dist/esm/index.js",
|
|
23
|
+
"require": "./dist/umd/index.js",
|
|
24
|
+
"default": "./dist/esm/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "npm run build:esm && npm run build:umd",
|
|
32
|
+
"build:esm": "vite build",
|
|
33
|
+
"build:umd": "cross-env BUILD_UMD=true vite build",
|
|
34
|
+
"build:prod": "npm run build:esm:prod && npm run build:umd:prod",
|
|
35
|
+
"build:esm:prod": "vite build --mode production",
|
|
36
|
+
"build:umd:prod": "cross-env BUILD_UMD=true vite build --mode production",
|
|
37
|
+
"dev": "vite build --watch",
|
|
38
|
+
"preview": "vite preview",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:coverage": "vitest run --coverage",
|
|
41
|
+
"lint": "biome check .",
|
|
42
|
+
"format": "biome check --write .",
|
|
43
|
+
"prepare": "npm run build:prod",
|
|
44
|
+
"prepublishOnly": "npm run test:coverage && npm run build:prod"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=16.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@biomejs/biome": "^2.5.2",
|
|
51
|
+
"@types/node": "^25.5.0",
|
|
52
|
+
"@vitest/coverage-v8": "^3.2.7",
|
|
53
|
+
"cross-env": "^7.0.3",
|
|
54
|
+
"lefthook": "^2.1.9",
|
|
55
|
+
"typescript": "^6.0.2",
|
|
56
|
+
"vite": "^8.0.3",
|
|
57
|
+
"vite-plugin-dts": "^4.5.4",
|
|
58
|
+
"vitest": "^3.0.0"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"typescript",
|
|
62
|
+
"esm",
|
|
63
|
+
"javascript",
|
|
64
|
+
"context"
|
|
65
|
+
],
|
|
66
|
+
"author": {
|
|
67
|
+
"name": "januwA",
|
|
68
|
+
"url": "https://github.com/januwA"
|
|
69
|
+
},
|
|
70
|
+
"license": "MIT"
|
|
71
|
+
}
|