@pod-network/trade-sdk 0.1.0-rc.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 +113 -0
- package/dist/client.d.ts +93 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +168 -0
- package/dist/client.js.map +1 -0
- package/dist/codec/decode.d.ts +22 -0
- package/dist/codec/decode.d.ts.map +1 -0
- package/dist/codec/decode.js +251 -0
- package/dist/codec/decode.js.map +1 -0
- package/dist/codec/fixed.d.ts +11 -0
- package/dist/codec/fixed.d.ts.map +1 -0
- package/dist/codec/fixed.js +37 -0
- package/dist/codec/fixed.js.map +1 -0
- package/dist/codec/resolution.d.ts +14 -0
- package/dist/codec/resolution.d.ts.map +1 -0
- package/dist/codec/resolution.js +35 -0
- package/dist/codec/resolution.js.map +1 -0
- package/dist/codec/units.d.ts +35 -0
- package/dist/codec/units.d.ts.map +1 -0
- package/dist/codec/units.js +86 -0
- package/dist/codec/units.js.map +1 -0
- package/dist/datafeed.d.ts +4 -0
- package/dist/datafeed.d.ts.map +1 -0
- package/dist/datafeed.js +73 -0
- package/dist/datafeed.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/stores/resource.d.ts +50 -0
- package/dist/stores/resource.d.ts.map +1 -0
- package/dist/stores/resource.js +154 -0
- package/dist/stores/resource.js.map +1 -0
- package/dist/sync/account-metrics.d.ts +26 -0
- package/dist/sync/account-metrics.d.ts.map +1 -0
- package/dist/sync/account-metrics.js +41 -0
- package/dist/sync/account-metrics.js.map +1 -0
- package/dist/sync/candles.d.ts +68 -0
- package/dist/sync/candles.d.ts.map +1 -0
- package/dist/sync/candles.js +318 -0
- package/dist/sync/candles.js.map +1 -0
- package/dist/sync/order-preview.d.ts +74 -0
- package/dist/sync/order-preview.d.ts.map +1 -0
- package/dist/sync/order-preview.js +86 -0
- package/dist/sync/order-preview.js.map +1 -0
- package/dist/sync/orders.d.ts +49 -0
- package/dist/sync/orders.d.ts.map +1 -0
- package/dist/sync/orders.js +210 -0
- package/dist/sync/orders.js.map +1 -0
- package/dist/sync/positions-live.d.ts +3 -0
- package/dist/sync/positions-live.d.ts.map +1 -0
- package/dist/sync/positions-live.js +86 -0
- package/dist/sync/positions-live.js.map +1 -0
- package/dist/sync/sources.d.ts +40 -0
- package/dist/sync/sources.d.ts.map +1 -0
- package/dist/sync/sources.js +197 -0
- package/dist/sync/sources.js.map +1 -0
- package/dist/transport/rest.d.ts +83 -0
- package/dist/transport/rest.d.ts.map +1 -0
- package/dist/transport/rest.js +146 -0
- package/dist/transport/rest.js.map +1 -0
- package/dist/transport/ws.d.ts +60 -0
- package/dist/transport/ws.d.ts.map +1 -0
- package/dist/transport/ws.js +235 -0
- package/dist/transport/ws.js.map +1 -0
- package/dist/types/public.d.ts +292 -0
- package/dist/types/public.d.ts.map +1 -0
- package/dist/types/public.js +4 -0
- package/dist/types/public.js.map +1 -0
- package/dist/types/wire.d.ts +283 -0
- package/dist/types/wire.d.ts.map +1 -0
- package/dist/types/wire.js +6 -0
- package/dist/types/wire.js.map +1 -0
- package/dist/write/delegation.d.ts +54 -0
- package/dist/write/delegation.d.ts.map +1 -0
- package/dist/write/delegation.js +81 -0
- package/dist/write/delegation.js.map +1 -0
- package/dist/write/index.d.ts +261 -0
- package/dist/write/index.d.ts.map +1 -0
- package/dist/write/index.js +428 -0
- package/dist/write/index.js.map +1 -0
- package/package.json +43 -0
- package/src/client.ts +229 -0
- package/src/codec/decode.ts +277 -0
- package/src/codec/fixed.ts +41 -0
- package/src/codec/resolution.ts +39 -0
- package/src/codec/units.ts +100 -0
- package/src/datafeed.ts +94 -0
- package/src/index.ts +49 -0
- package/src/stores/resource.ts +172 -0
- package/src/sync/account-metrics.ts +71 -0
- package/src/sync/candles.ts +326 -0
- package/src/sync/order-preview.ts +152 -0
- package/src/sync/orders.ts +205 -0
- package/src/sync/positions-live.ts +102 -0
- package/src/sync/sources.ts +239 -0
- package/src/transport/rest.ts +213 -0
- package/src/transport/ws.ts +255 -0
- package/src/types/public.ts +335 -0
- package/src/types/wire.ts +301 -0
- package/src/write/delegation.ts +113 -0
- package/src/write/index.ts +642 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/codec/decode.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,oEAAoE;AAYpE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,UAAU,YAAY,CAAC,CAAa;IACxC,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC;AACjD,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,kBAAkB,CAAC,CAAmB;IACpD,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,IAAI,EAAE,CAAC,CAAC,WAAW;QACnB,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,eAAe,EAAE;QAC7F,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,mBAAmB,EAAE,MAAM,EAAE,CAAC,CAAC,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC,gBAAgB,EAAE;QACjG,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC;QACpC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;QACxB,WAAW,EAAE,CAAC,CAAC,YAAY;QAC3B,eAAe,EAAE,CAAC,CAAC,iBAAiB;QACpC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1B,QAAQ,EAAE,G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C;QACrB,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC;KAC7B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Decimal `*`: (a*b)/1e18 truncated toward zero. */
|
|
2
|
+
export declare function mul(a: bigint, b: bigint): bigint;
|
|
3
|
+
/** Decimal `/`: (a*1e18)/b truncated toward zero. */
|
|
4
|
+
export declare function div(a: bigint, b: bigint): bigint;
|
|
5
|
+
/** Decimal `mul_floor`: (a*b)/1e18 rounded toward -infinity. */
|
|
6
|
+
export declare function mulFloor(a: bigint, b: bigint): bigint;
|
|
7
|
+
/** Decimal `mul_div_ceil`: (a*b)/d; positive magnitudes round up, negative truncate. */
|
|
8
|
+
export declare function mulDivCeil(a: bigint, b: bigint, d: bigint): bigint;
|
|
9
|
+
/** initial_margin = UDecimal::ONE / max_leverage = floor(1e18 / L). */
|
|
10
|
+
export declare function imRate(maxLeverage: number): bigint;
|
|
11
|
+
//# sourceMappingURL=fixed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixed.d.ts","sourceRoot":"","sources":["../../src/codec/fixed.ts"],"names":[],"mappings":"AAOA,qDAAqD;AACrD,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED,qDAAqD;AACrD,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wFAAwF;AACxF,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAQlE;AAED,uEAAuE;AACvE,wBAAgB,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Fixed-point (1e18) integer ops matching pod's trading/src/decimal.rs, shared
|
|
2
|
+
// by the account-math replications so they all round identically.
|
|
3
|
+
import { WAD } from "./units.js";
|
|
4
|
+
const absB = (x) => (x < 0n ? -x : x);
|
|
5
|
+
/** Decimal `*`: (a*b)/1e18 truncated toward zero. */
|
|
6
|
+
export function mul(a, b) {
|
|
7
|
+
const n = a * b;
|
|
8
|
+
return n >= 0n ? n / WAD : -((-n) / WAD);
|
|
9
|
+
}
|
|
10
|
+
/** Decimal `/`: (a*1e18)/b truncated toward zero. */
|
|
11
|
+
export function div(a, b) {
|
|
12
|
+
if (b === 0n)
|
|
13
|
+
return 0n;
|
|
14
|
+
const n = a * WAD;
|
|
15
|
+
return n >= 0n ? n / b : -((-n) / b);
|
|
16
|
+
}
|
|
17
|
+
/** Decimal `mul_floor`: (a*b)/1e18 rounded toward -infinity. */
|
|
18
|
+
export function mulFloor(a, b) {
|
|
19
|
+
const n = a * b;
|
|
20
|
+
return n >= 0n ? n / WAD : -((-n + WAD - 1n) / WAD);
|
|
21
|
+
}
|
|
22
|
+
/** Decimal `mul_div_ceil`: (a*b)/d; positive magnitudes round up, negative truncate. */
|
|
23
|
+
export function mulDivCeil(a, b, d) {
|
|
24
|
+
if (d <= 0n)
|
|
25
|
+
return 0n;
|
|
26
|
+
const prod = absB(a) * absB(b);
|
|
27
|
+
const q = prod / d;
|
|
28
|
+
const r = prod % d;
|
|
29
|
+
const negative = a < 0n !== b < 0n; // d is positive
|
|
30
|
+
const mag = !negative && r !== 0n ? q + 1n : q;
|
|
31
|
+
return negative ? -mag : mag;
|
|
32
|
+
}
|
|
33
|
+
/** initial_margin = UDecimal::ONE / max_leverage = floor(1e18 / L). */
|
|
34
|
+
export function imRate(maxLeverage) {
|
|
35
|
+
return maxLeverage > 0 ? WAD / BigInt(maxLeverage) : 0n;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMapp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wF;AACxF,MAAM,UAAU,UAAU,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;IACxD,IAAI,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IACnB,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IACnB,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,gBAAgB;IACpD,MAAM,GAAG,GAAG,CAAC,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAC/B,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,MAAM,CAAC,WAAmB;IACxC,OAAO,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Resolution } from "../types/public.js";
|
|
2
|
+
/** Bucket width per resolution, in seconds. 1M is calendar-variable; see pages. */
|
|
3
|
+
export declare const RESOLUTION_SECONDS: Record<Resolution, number>;
|
|
4
|
+
/**
|
|
5
|
+
* Canonical page size K (number of buckets per cached page), chosen as the
|
|
6
|
+
* largest value <= 500 (the server's hard cap) for the resolution. Pages are
|
|
7
|
+
* epoch-anchored (pageIndex = floor(bucketIndex / K)) so every client computes
|
|
8
|
+
* identical, settled-aligned page boundaries -> high cache-hit rate + the
|
|
9
|
+
* server flags fully-past pages `immutable`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const RESOLUTION_PAGE_BUCKETS: Record<Resolution, number>;
|
|
12
|
+
export declare const RESOLUTIONS: Resolution[];
|
|
13
|
+
export declare function isResolution(x: string): x is Resolution;
|
|
14
|
+
//# sourceMappingURL=resolution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../../src/codec/resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,mFAAmF;AACnF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAUzD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAU9D,CAAC;AAEF,eAAO,MAAM,WAAW,EAAsC,UAAU,EAAE,CAAC;AAE3E,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,IAAI,UAAU,CAEvD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Bucket width per resolution, in seconds. 1M is calendar-variable; see pages. */
|
|
2
|
+
export const RESOLUTION_SECONDS = {
|
|
3
|
+
"1m": 60,
|
|
4
|
+
"5m": 300,
|
|
5
|
+
"15m": 900,
|
|
6
|
+
"30m": 1_800,
|
|
7
|
+
"1h": 3_600,
|
|
8
|
+
"4h": 14_400,
|
|
9
|
+
"1d": 86_400,
|
|
10
|
+
"1W": 604_800,
|
|
11
|
+
"1M": 2_592_000, // nominal 30d; only used as a hint, pages use calendar months
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Canonical page size K (number of buckets per cached page), chosen as the
|
|
15
|
+
* largest value <= 500 (the server's hard cap) for the resolution. Pages are
|
|
16
|
+
* epoch-anchored (pageIndex = floor(bucketIndex / K)) so every client computes
|
|
17
|
+
* identical, settled-aligned page boundaries -> high cache-hit rate + the
|
|
18
|
+
* server flags fully-past pages `immutable`.
|
|
19
|
+
*/
|
|
20
|
+
export const RESOLUTION_PAGE_BUCKETS = {
|
|
21
|
+
"1m": 360, // 6h
|
|
22
|
+
"5m": 288, // 1 day
|
|
23
|
+
"15m": 96, // 1 day
|
|
24
|
+
"30m": 336, // 1 week
|
|
25
|
+
"1h": 168, // 1 week
|
|
26
|
+
"4h": 180, // ~30 days
|
|
27
|
+
"1d": 365, // ~1 year
|
|
28
|
+
"1W": 260, // ~5 years
|
|
29
|
+
"1M": 120, // ~decade (calendar-month buckets)
|
|
30
|
+
};
|
|
31
|
+
export const RESOLUTIONS = Object.keys(RESOLUTION_SECONDS);
|
|
32
|
+
export function isResolution(x) {
|
|
33
|
+
return x in RESOLUTION_SECONDS;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolution.js","sourceRoot":"","sources":["../../src/codec/resolution.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,MAAM,CAAC,MAAM,kBAAkB,GAA+B;IAC5D,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,GAAG;IACT,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,SAAS,EAAE,8DAA8D;CAChF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA+B;IACjE,IAAI,EAAE,GAAG,EAAE,KAAK;IAChB,IAAI,EAAE,GAAG,EAAE,QAAQ;IACnB,KAAK,EAAE,EAAE,EAAE,QAAQ;IACnB,KAAK,EAAE,GAAG,EAAE,SAAS;IACrB,IAAI,EAAE,GAAG,EAAE,SAAS;IACpB,IAAI,EAAE,GAAG,EAAE,WAAW;IACtB,IAAI,EAAE,GAAG,EAAE,UAAU;IACrB,IAAI,EAAE,GAAG,EAAE,WAAW;IACtB,IAAI,EAAE,GAAG,EAAE,mCAAmC;CAC/C,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAiB,CAAC;AAE3E,MAAM,UAAU,YAAY,CAAC,CAAS;IACpC,OAAO,CAAC,IAAI,kBAAkB,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const WAD = 1000000000000000000n;
|
|
2
|
+
export declare const WAD_DECIMALS = 18;
|
|
3
|
+
/**
|
|
4
|
+
* Parse a wire numeric (possibly null) into a 1e18-scaled bigint. Handles both
|
|
5
|
+
* decimal (`"50000…"`, markets/stats) and hex (`"0x0"`, candles/orderbook)
|
|
6
|
+
* encodings, signed values (`"-5"` / `"-0x5"`), and tolerates a fraction.
|
|
7
|
+
*/
|
|
8
|
+
export declare function dec(value: string | null | undefined): bigint;
|
|
9
|
+
/** Parse an optional wire decimal; returns undefined when absent/null. */
|
|
10
|
+
export declare function decOpt(value: string | null | undefined): bigint | undefined;
|
|
11
|
+
/** Microseconds (number) -> milliseconds (number). */
|
|
12
|
+
export declare function usToMs(us: number | string): number;
|
|
13
|
+
export declare function usToMsOpt(us: number | string | null | undefined): number | undefined;
|
|
14
|
+
/** Milliseconds -> microseconds (for request params that take micros). */
|
|
15
|
+
export declare function msToUs(ms: number): number;
|
|
16
|
+
/** Milliseconds -> unix seconds (REST candle/orders/stats query params). */
|
|
17
|
+
export declare function msToSecs(ms: number): number;
|
|
18
|
+
export declare function secsToMs(secs: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Format a 1e18-scaled bigint as a decimal string with up to `precision` dp.
|
|
21
|
+
* By default trailing zeros are trimmed; pass `{ trim: false }` for fixed
|
|
22
|
+
* decimals (stable column widths in tables).
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatAmount(value: bigint, decimals?: number, precision?: number, opts?: {
|
|
25
|
+
trim?: boolean;
|
|
26
|
+
}): string;
|
|
27
|
+
/** Decimals implied by a market's 1e18-scaled tick (e.g. tick 1e16 → 2 dp). */
|
|
28
|
+
export declare function decimalsForTick(tick: bigint): number;
|
|
29
|
+
/** Format a price with fixed decimals derived from the market's tick precision. */
|
|
30
|
+
export declare function formatPrice(value: bigint, tickPrecision: bigint): string;
|
|
31
|
+
/** Convert a 1e18-scaled bigint to a JS number (lossy; charts/PnL display). */
|
|
32
|
+
export declare function toNumber(value: bigint, decimals?: number): number;
|
|
33
|
+
/** Parse a human decimal string into a 1e18-scaled bigint. */
|
|
34
|
+
export declare function parseAmount(value: string, decimals?: number): bigint;
|
|
35
|
+
//# sourceMappingURL=units.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/codec/units.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,GAAG,uBAA6B,CAAC;AAC9C,eAAO,MAAM,YAAY,KAAK,CAAC;AAE/B;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAO5D;AAED,0EAA0E;AAC1E,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAE3E;AAED,sDAAsD;AACtD,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAGlD;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAEpF;AAED,0EAA0E;AAC1E,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAID;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAqB,EAC/B,SAAS,CAAC,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GACxB,MAAM,CAWR;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,+EAA+E;AAC/E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,MAAM,CAE/E;AAED,8DAA8D;AAC9D,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,MAAM,CAOlF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Unit conversions at the SDK boundary. Wire numerics are 1e18-scaled decimal
|
|
2
|
+
// strings; wire timestamps are microseconds. Public surface uses `bigint`
|
|
3
|
+
// (1e18-scaled) and millisecond `number` timestamps.
|
|
4
|
+
export const WAD = 1000000000000000000n; // 1e18
|
|
5
|
+
export const WAD_DECIMALS = 18;
|
|
6
|
+
/**
|
|
7
|
+
* Parse a wire numeric (possibly null) into a 1e18-scaled bigint. Handles both
|
|
8
|
+
* decimal (`"50000…"`, markets/stats) and hex (`"0x0"`, candles/orderbook)
|
|
9
|
+
* encodings, signed values (`"-5"` / `"-0x5"`), and tolerates a fraction.
|
|
10
|
+
*/
|
|
11
|
+
export function dec(value) {
|
|
12
|
+
if (value === null || value === undefined || value === "")
|
|
13
|
+
return 0n;
|
|
14
|
+
const neg = value[0] === "-";
|
|
15
|
+
const body = neg ? value.slice(1) : value;
|
|
16
|
+
const dot = body.indexOf(".");
|
|
17
|
+
const n = BigInt(dot === -1 ? body : body.slice(0, dot));
|
|
18
|
+
return neg ? -n : n;
|
|
19
|
+
}
|
|
20
|
+
/** Parse an optional wire decimal; returns undefined when absent/null. */
|
|
21
|
+
export function decOpt(value) {
|
|
22
|
+
return value === null || value === undefined ? undefined : dec(value);
|
|
23
|
+
}
|
|
24
|
+
/** Microseconds (number) -> milliseconds (number). */
|
|
25
|
+
export function usToMs(us) {
|
|
26
|
+
const n = typeof us === "string" ? Number(us) : us;
|
|
27
|
+
return Math.trunc(n / 1000);
|
|
28
|
+
}
|
|
29
|
+
export function usToMsOpt(us) {
|
|
30
|
+
return us === null || us === undefined ? undefined : usToMs(us);
|
|
31
|
+
}
|
|
32
|
+
/** Milliseconds -> microseconds (for request params that take micros). */
|
|
33
|
+
export function msToUs(ms) {
|
|
34
|
+
return ms * 1000;
|
|
35
|
+
}
|
|
36
|
+
/** Milliseconds -> unix seconds (REST candle/orders/stats query params). */
|
|
37
|
+
export function msToSecs(ms) {
|
|
38
|
+
return Math.trunc(ms / 1000);
|
|
39
|
+
}
|
|
40
|
+
export function secsToMs(secs) {
|
|
41
|
+
return secs * 1000;
|
|
42
|
+
}
|
|
43
|
+
// --- display helpers (lossy, for UI) ---
|
|
44
|
+
/**
|
|
45
|
+
* Format a 1e18-scaled bigint as a decimal string with up to `precision` dp.
|
|
46
|
+
* By default trailing zeros are trimmed; pass `{ trim: false }` for fixed
|
|
47
|
+
* decimals (stable column widths in tables).
|
|
48
|
+
*/
|
|
49
|
+
export function formatAmount(value, decimals = WAD_DECIMALS, precision, opts) {
|
|
50
|
+
const trim = opts?.trim ?? true;
|
|
51
|
+
const scale = 10n ** BigInt(decimals);
|
|
52
|
+
const neg = value < 0n;
|
|
53
|
+
const abs = neg ? -value : value;
|
|
54
|
+
const whole = abs / scale;
|
|
55
|
+
let frac = (abs % scale).toString().padStart(decimals, "0");
|
|
56
|
+
if (precision !== undefined)
|
|
57
|
+
frac = frac.slice(0, precision);
|
|
58
|
+
if (trim)
|
|
59
|
+
frac = frac.replace(/0+$/, "");
|
|
60
|
+
const sign = neg ? "-" : "";
|
|
61
|
+
return frac.length ? `${sign}${whole}.${frac}` : `${sign}${whole}`;
|
|
62
|
+
}
|
|
63
|
+
/** Decimals implied by a market's 1e18-scaled tick (e.g. tick 1e16 → 2 dp). */
|
|
64
|
+
export function decimalsForTick(tick) {
|
|
65
|
+
if (tick <= 0n)
|
|
66
|
+
return 2;
|
|
67
|
+
return Math.max(0, Math.min(8, WAD_DECIMALS + 1 - tick.toString().length));
|
|
68
|
+
}
|
|
69
|
+
/** Format a price with fixed decimals derived from the market's tick precision. */
|
|
70
|
+
export function formatPrice(value, tickPrecision) {
|
|
71
|
+
return formatAmount(value, WAD_DECIMALS, decimalsForTick(tickPrecision), { trim: false });
|
|
72
|
+
}
|
|
73
|
+
/** Convert a 1e18-scaled bigint to a JS number (lossy; charts/PnL display). */
|
|
74
|
+
export function toNumber(value, decimals = WAD_DECIMALS) {
|
|
75
|
+
return Number(value) / 10 ** decimals;
|
|
76
|
+
}
|
|
77
|
+
/** Parse a human decimal string into a 1e18-scaled bigint. */
|
|
78
|
+
export function parseAmount(value, decimals = WAD_DECIMALS) {
|
|
79
|
+
const neg = value.trim().startsWith("-");
|
|
80
|
+
const clean = neg ? value.trim().slice(1) : value.trim();
|
|
81
|
+
const [whole = "0", frac = ""] = clean.split(".");
|
|
82
|
+
const fracPadded = (frac + "0".repeat(decimals)).slice(0, decimals);
|
|
83
|
+
const scaled = BigInt(whole) * 10n ** BigInt(decimals) + BigInt(fracPadded || "0");
|
|
84
|
+
return neg ? -scaled : scaled;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/codec/units.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,0EAA0E;AAC1E,qDAAqD;AAErD,MAAM,CAAC,MAAM,GAAG,GAAG,oBAA0B,CAAC,CAAC,OAAO;AACtD,MAAM,CAAC,MAAM,YAAY,GAAG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MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;IACnF,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datafeed.d.ts","sourceRoot":"","sources":["../src/datafeed.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAsBlD,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAkEjE"}
|
package/dist/datafeed.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Minimal TradingView Charting Library datafeed (IDatafeedChartApi-shaped),
|
|
2
|
+
// backed by the SDK's CandleSeries. Typed loosely so the SDK takes no
|
|
3
|
+
// dependency on the (private) charting library types.
|
|
4
|
+
import { toNumber } from "./codec/units.js";
|
|
5
|
+
const TV_TO_RESOLUTION = {
|
|
6
|
+
"1": "1m", "5": "5m", "15": "15m", "30": "30m",
|
|
7
|
+
"60": "1h", "240": "4h", "1D": "1d", "1W": "1W", "1M": "1M",
|
|
8
|
+
};
|
|
9
|
+
function toTvBar(b, quoteDecimals = 18) {
|
|
10
|
+
return {
|
|
11
|
+
time: b.time,
|
|
12
|
+
open: toNumber(b.open, quoteDecimals),
|
|
13
|
+
high: toNumber(b.high, quoteDecimals),
|
|
14
|
+
low: toNumber(b.low, quoteDecimals),
|
|
15
|
+
close: toNumber(b.close, quoteDecimals),
|
|
16
|
+
volume: toNumber(b.volume),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Returns an object implementing the TradingView IDatafeedChartApi surface. */
|
|
20
|
+
export function createPodDatafeed(client) {
|
|
21
|
+
const subs = new Map();
|
|
22
|
+
return {
|
|
23
|
+
onReady(cb) {
|
|
24
|
+
setTimeout(() => cb({
|
|
25
|
+
supported_resolutions: Object.keys(TV_TO_RESOLUTION),
|
|
26
|
+
supports_time: true,
|
|
27
|
+
}), 0);
|
|
28
|
+
},
|
|
29
|
+
resolveSymbol(symbolName, onResolve) {
|
|
30
|
+
setTimeout(() => onResolve({
|
|
31
|
+
name: symbolName, ticker: symbolName, description: symbolName,
|
|
32
|
+
type: "crypto", session: "24x7", timezone: "Etc/UTC",
|
|
33
|
+
minmov: 1, pricescale: 100_000_000, has_intraday: true,
|
|
34
|
+
supported_resolutions: Object.keys(TV_TO_RESOLUTION),
|
|
35
|
+
volume_precision: 2, data_status: "streaming",
|
|
36
|
+
}), 0);
|
|
37
|
+
},
|
|
38
|
+
async getBars(symbolInfo, resolution, periodParams, onResult, onError) {
|
|
39
|
+
try {
|
|
40
|
+
const id = (symbolInfo.ticker ?? symbolInfo.name);
|
|
41
|
+
const res = TV_TO_RESOLUTION[resolution] ?? "1h";
|
|
42
|
+
const series = client.candles(id, res, {
|
|
43
|
+
from: periodParams.from * 1000,
|
|
44
|
+
to: periodParams.to * 1000,
|
|
45
|
+
});
|
|
46
|
+
const bars = await series.ready();
|
|
47
|
+
const inRange = bars
|
|
48
|
+
.filter((b) => b.time >= periodParams.from * 1000 && b.time < periodParams.to * 1000)
|
|
49
|
+
.map((b) => toTvBar(b));
|
|
50
|
+
onResult(inRange, { noData: inRange.length === 0 });
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
onError(String(e));
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
subscribeBars(symbolInfo, resolution, onTick, listenerGuid) {
|
|
57
|
+
const id = (symbolInfo.ticker ?? symbolInfo.name);
|
|
58
|
+
const res = TV_TO_RESOLUTION[resolution] ?? "1h";
|
|
59
|
+
const series = client.candles(id, res);
|
|
60
|
+
const unsub = series.subscribe(() => {
|
|
61
|
+
const bars = series.get();
|
|
62
|
+
if (bars && bars.length)
|
|
63
|
+
onTick(toTvBar(bars[bars.length - 1]));
|
|
64
|
+
});
|
|
65
|
+
subs.set(listenerGuid, unsub);
|
|
66
|
+
},
|
|
67
|
+
unsubscribeBars(listenerGuid) {
|
|
68
|
+
subs.get(listenerGuid)?.();
|
|
69
|
+
subs.delete(listenerGuid);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=datafeed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datafeed.js","sourceRoot":"","sources":["../src/datafeed.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,sEAAsE;AACtE,sDAAsD;AAItD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,MAAM,gBAAgB,GAA+B;IACnD,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK;IAC9C,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CAC5D,CAAC;AAIF,SAAS,OAAO,CAAC,CAAM,EAAE,aAAa,GAAG,EAAE;IACzC,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,aAAa,CAAC;QACrC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,aAAa,CAAC;QACrC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,aAAa,CAAC;QACnC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,aAAa,CAAC;QACvC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,MAA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AE,KAAK,CAAC,CAAC;QAChC,CAAC;QAED,eAAe,CAAC,YAAoB;YAClC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { PodTradeClient } from "./client.js";
|
|
2
|
+
export type { PodTradeClientOptions } from "./client.js";
|
|
3
|
+
export type { MarketsCache } from "./sync/sources.js";
|
|
4
|
+
export { PodRestClient, PodHttpError } from "./transport/rest.js";
|
|
5
|
+
export type { MarketDynamicsPatch, MarketStatsPage, OrdersPage, BackstopPage, TriggersPage, CandlesPage, OrdersQueryRest, TriggersQueryRest, RestClientOptions, } from "./transport/rest.js";
|
|
6
|
+
export { PodWsClient } from "./transport/ws.js";
|
|
7
|
+
export type { Channel, SubParams, Subscription, ConnectionState, WsEvent, WebSocketCtor, WsClientOptions, } from "./transport/ws.js";
|
|
8
|
+
export type { Resource } from "./stores/resource.js";
|
|
9
|
+
export { combineResources, derivedResource } from "./stores/resource.js";
|
|
10
|
+
export { enrichPositions } from "./sync/positions-live.js";
|
|
11
|
+
export { accountMetrics, type AccountMetrics, perpPositionTotals, type PerpPositionTotals, } from "./sync/account-metrics.js";
|
|
12
|
+
export { previewOrder, type OrderPreview, type OrderPreviewInput, closePreview, type ClosePreview, priceForReturn, type ReturnPriceInput, closestTriggers, } from "./sync/order-preview.js";
|
|
13
|
+
export type { SeriesResource } from "./sync/candles.js";
|
|
14
|
+
export { CandleSeries } from "./sync/candles.js";
|
|
15
|
+
export { OrderHistory } from "./sync/orders.js";
|
|
16
|
+
export { createPodDatafeed } from "./datafeed.js";
|
|
17
|
+
export * from "./types/public.js";
|
|
18
|
+
export { formatAmount, formatPrice, decimalsForTick, toNumber, parseAmount, dec, WAD, WAD_DECIMALS, } from "./codec/units.js";
|
|
19
|
+
export { RESOLUTION_SECONDS, RESOLUTION_PAGE_BUCKETS, RESOLUTIONS, isResolution, } from "./codec/resolution.js";
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,YAAY,EACV,mBAAmB,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAC5E,WAAW,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,GACnE,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EACV,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,EACzE,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,cAAc,EAAE,KAAK,cAAc,EACnC,kBAAkB,EAAE,KAAK,kBAAkB,GAC5C,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,iBAAiB,EACvD,YAAY,EAAE,KAAK,YAAY,EAC/B,cAAc,EAAE,KAAK,gBAAgB,EACrC,eAAe,GAChB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,cAAc,mBAAmB,CAAC;AAGlC,OAAO,EACL,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,YAAY,GAC1F,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAAE,uBAAuB,EAAE,WAAW,EAAE,YAAY,GACvE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @pod-network/trade-sdk — read/stream market-data SDK for the pod indexer.
|
|
2
|
+
export { PodTradeClient } from "./client.js";
|
|
3
|
+
// Layer 1 — low-level transports (exposed for one-shot reads & debugging)
|
|
4
|
+
export { PodRestClient, PodHttpError } from "./transport/rest.js";
|
|
5
|
+
export { PodWsClient } from "./transport/ws.js";
|
|
6
|
+
export { combineResources, derivedResource } from "./stores/resource.js";
|
|
7
|
+
export { enrichPositions } from "./sync/positions-live.js";
|
|
8
|
+
export { accountMetrics, perpPositionTotals, } from "./sync/account-metrics.js";
|
|
9
|
+
export { previewOrder, closePreview, priceForReturn, closestTriggers, } from "./sync/order-preview.js";
|
|
10
|
+
export { CandleSeries } from "./sync/candles.js";
|
|
11
|
+
export { OrderHistory } from "./sync/orders.js";
|
|
12
|
+
// Framework-agnostic TradingView Charting Library datafeed (no React needed).
|
|
13
|
+
export { createPodDatafeed } from "./datafeed.js";
|
|
14
|
+
// Public data types
|
|
15
|
+
export * from "./types/public.js";
|
|
16
|
+
// Codec helpers
|
|
17
|
+
export { formatAmount, formatPrice, decimalsForTick, toNumber, parseAmount, dec, WAD, WAD_DECIMALS, } from "./codec/units.js";
|
|
18
|
+
export { RESOLUTION_SECONDS, RESOLUTION_PAGE_BUCKETS, RESOLUTIONS, isResolution, } from "./codec/resolution.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C,0EAA0E;AAC1E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAKlE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQhD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,8EAA8E;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,oBAAoB;AACpB,cAAc,mBAAmB,CAAC;AAElC,gBAAgB;AAChB,OAAO,EACL,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,YAAY,GAC1F,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAAE,uBAAuB,EAAE,WAAW,EAAE,YAAY,GACvE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface Resource<T> {
|
|
2
|
+
get(): T | undefined;
|
|
3
|
+
subscribe(listener: () => void): () => void;
|
|
4
|
+
ready(): Promise<T>;
|
|
5
|
+
/** Restart the source for a fresh seed (optional — see BaseResource). */
|
|
6
|
+
refresh?(): void;
|
|
7
|
+
readonly error?: Error;
|
|
8
|
+
}
|
|
9
|
+
export interface ResourceHandle<T> {
|
|
10
|
+
set(value: T): void;
|
|
11
|
+
update(fn: (prev: T | undefined) => T): void;
|
|
12
|
+
current(): T | undefined;
|
|
13
|
+
fail(err: Error): void;
|
|
14
|
+
}
|
|
15
|
+
/** A source seeds + subscribes and returns a teardown function. */
|
|
16
|
+
export type ResourceSource<T> = (handle: ResourceHandle<T>) => () => void;
|
|
17
|
+
export declare class BaseResource<T> implements Resource<T> {
|
|
18
|
+
private readonly source;
|
|
19
|
+
private value;
|
|
20
|
+
private _error;
|
|
21
|
+
private readonly listeners;
|
|
22
|
+
private teardown;
|
|
23
|
+
private started;
|
|
24
|
+
private readyPromise;
|
|
25
|
+
private readyResolve;
|
|
26
|
+
private readyReject;
|
|
27
|
+
constructor(source: ResourceSource<T>);
|
|
28
|
+
get(): T | undefined;
|
|
29
|
+
get error(): Error | undefined;
|
|
30
|
+
subscribe(listener: () => void): () => void;
|
|
31
|
+
ready(): Promise<T>;
|
|
32
|
+
/** Force teardown (used by the client on close). */
|
|
33
|
+
destroy(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Tear down and restart the source, forcing a fresh seed while keeping
|
|
36
|
+
* subscribers and the current value (no flicker — the old snapshot stays
|
|
37
|
+
* until the new seed lands). No-op when the resource isn't running. For
|
|
38
|
+
* out-of-band mutations the streams don't announce (e.g. a faucet mint).
|
|
39
|
+
*/
|
|
40
|
+
refresh(): void;
|
|
41
|
+
private ensureStarted;
|
|
42
|
+
private stop;
|
|
43
|
+
private commit;
|
|
44
|
+
private emit;
|
|
45
|
+
}
|
|
46
|
+
/** A read-only view derived from several resources; recomputes on any change. */
|
|
47
|
+
export declare function combineResources<T>(parents: Resource<unknown>[], compute: () => T | undefined): Resource<T>;
|
|
48
|
+
/** A read-only view derived from another resource. */
|
|
49
|
+
export declare function derivedResource<S, T>(parent: Resource<S>, select: (s: S | undefined) => T | undefined): Resource<T>;
|
|
50
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/stores/resource.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IACrB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,yEAAyE;IACzE,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AAED,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,IAAI,CAAC;IAC7C,OAAO,IAAI,CAAC,GAAG,SAAS,CAAC;IACzB,IAAI,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC;CACxB;AAED,mEAAmE;AACnE,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC;AAE1E,qBAAa,YAAY,CAAC,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;IAUrC,OAAO,CAAC,QAAQ,CAAC,MAAM;IATnC,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;IACnD,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,WAAW,CAAmC;gBAEzB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAEtD,GAAG,IAAI,CAAC,GAAG,SAAS;IAIpB,IAAI,KAAK,IAAI,KAAK,GAAG,SAAS,CAE7B;IAED,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAS3C,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC;IAYnB,oDAAoD;IACpD,OAAO,IAAI,IAAI;IAIf;;;;;OAKG;IACH,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,aAAa;IA2BrB,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,IAAI;CAKb;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,EAC5B,OAAO,EAAE,MAAM,CAAC,GAAG,SAAS,GAC3B,QAAQ,CAAC,CAAC,CAAC,CAYb;AAED,sDAAsD;AACtD,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAClC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,SAAS,GAC1C,QAAQ,CAAC,CAAC,CAAC,CAeb"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// The core observable abstraction. A Resource holds an in-memory value, is
|
|
2
|
+
// ref-counted (its source starts on the first subscriber and tears down after
|
|
3
|
+
// the last leaves), and exposes the useSyncExternalStore-shaped contract.
|
|
4
|
+
export class BaseResource {
|
|
5
|
+
source;
|
|
6
|
+
value;
|
|
7
|
+
_error;
|
|
8
|
+
listeners = new Set();
|
|
9
|
+
teardown;
|
|
10
|
+
started = false;
|
|
11
|
+
readyPromise;
|
|
12
|
+
readyResolve;
|
|
13
|
+
readyReject;
|
|
14
|
+
constructor(source) {
|
|
15
|
+
this.source = source;
|
|
16
|
+
}
|
|
17
|
+
get() {
|
|
18
|
+
return this.value;
|
|
19
|
+
}
|
|
20
|
+
get error() {
|
|
21
|
+
return this._error;
|
|
22
|
+
}
|
|
23
|
+
subscribe(listener) {
|
|
24
|
+
this.listeners.add(listener);
|
|
25
|
+
this.ensureStarted();
|
|
26
|
+
return () => {
|
|
27
|
+
this.listeners.delete(listener);
|
|
28
|
+
if (this.listeners.size === 0)
|
|
29
|
+
this.stop();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
ready() {
|
|
33
|
+
if (this.value !== undefined)
|
|
34
|
+
return Promise.resolve(this.value);
|
|
35
|
+
if (!this.readyPromise) {
|
|
36
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
37
|
+
this.readyResolve = resolve;
|
|
38
|
+
this.readyReject = reject;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
this.ensureStarted();
|
|
42
|
+
return this.readyPromise;
|
|
43
|
+
}
|
|
44
|
+
/** Force teardown (used by the client on close). */
|
|
45
|
+
destroy() {
|
|
46
|
+
this.stop();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Tear down and restart the source, forcing a fresh seed while keeping
|
|
50
|
+
* subscribers and the current value (no flicker — the old snapshot stays
|
|
51
|
+
* until the new seed lands). No-op when the resource isn't running. For
|
|
52
|
+
* out-of-band mutations the streams don't announce (e.g. a faucet mint).
|
|
53
|
+
*/
|
|
54
|
+
refresh() {
|
|
55
|
+
if (!this.started)
|
|
56
|
+
return;
|
|
57
|
+
this.stop();
|
|
58
|
+
this.ensureStarted();
|
|
59
|
+
}
|
|
60
|
+
ensureStarted() {
|
|
61
|
+
if (this.started)
|
|
62
|
+
return;
|
|
63
|
+
this.started = true;
|
|
64
|
+
const handle = {
|
|
65
|
+
set: (v) => this.commit(v),
|
|
66
|
+
update: (fn) => this.commit(fn(this.value)),
|
|
67
|
+
current: () => this.value,
|
|
68
|
+
fail: (err) => {
|
|
69
|
+
this._error = err;
|
|
70
|
+
if (this.readyReject) {
|
|
71
|
+
this.readyReject(err);
|
|
72
|
+
this.readyResolve = undefined;
|
|
73
|
+
this.readyReject = undefined;
|
|
74
|
+
this.readyPromise = undefined; // allow a later ready() to retry
|
|
75
|
+
}
|
|
76
|
+
this.emit();
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
this.teardown = this.source(handle);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
this._error = err;
|
|
84
|
+
this.started = false;
|
|
85
|
+
this.emit();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
stop() {
|
|
89
|
+
if (!this.started)
|
|
90
|
+
return;
|
|
91
|
+
this.started = false;
|
|
92
|
+
const t = this.teardown;
|
|
93
|
+
this.teardown = undefined;
|
|
94
|
+
if (t)
|
|
95
|
+
try {
|
|
96
|
+
t();
|
|
97
|
+
}
|
|
98
|
+
catch { /* ignore */ }
|
|
99
|
+
}
|
|
100
|
+
commit(v) {
|
|
101
|
+
this.value = v;
|
|
102
|
+
this._error = undefined;
|
|
103
|
+
if (this.readyResolve) {
|
|
104
|
+
this.readyResolve(v);
|
|
105
|
+
this.readyResolve = undefined;
|
|
106
|
+
this.readyReject = undefined;
|
|
107
|
+
}
|
|
108
|
+
this.emit();
|
|
109
|
+
}
|
|
110
|
+
emit() {
|
|
111
|
+
this.listeners.forEach((l) => {
|
|
112
|
+
try {
|
|
113
|
+
l();
|
|
114
|
+
}
|
|
115
|
+
catch { /* ignore */ }
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** A read-only view derived from several resources; recomputes on any change. */
|
|
120
|
+
export function combineResources(parents, compute) {
|
|
121
|
+
return new BaseResource((handle) => {
|
|
122
|
+
let alive = true;
|
|
123
|
+
const apply = () => {
|
|
124
|
+
if (!alive)
|
|
125
|
+
return;
|
|
126
|
+
const next = compute();
|
|
127
|
+
if (next !== undefined)
|
|
128
|
+
handle.set(next);
|
|
129
|
+
};
|
|
130
|
+
const unsubs = parents.map((p) => p.subscribe(apply));
|
|
131
|
+
queueMicrotask(apply);
|
|
132
|
+
return () => { alive = false; unsubs.forEach((u) => u()); };
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/** A read-only view derived from another resource. */
|
|
136
|
+
export function derivedResource(parent, select) {
|
|
137
|
+
return new BaseResource((handle) => {
|
|
138
|
+
let alive = true;
|
|
139
|
+
const apply = () => {
|
|
140
|
+
if (!alive)
|
|
141
|
+
return;
|
|
142
|
+
const next = select(parent.get());
|
|
143
|
+
if (next !== undefined)
|
|
144
|
+
handle.set(next);
|
|
145
|
+
};
|
|
146
|
+
const unsub = parent.subscribe(apply);
|
|
147
|
+
// Defer the initial emit: never call handle.set synchronously inside
|
|
148
|
+
// subscribe() — a synchronous store notification during a useSyncExternalStore
|
|
149
|
+
// subscribe can loop if the subscribe closure is unstable.
|
|
150
|
+
queueMicrotask(apply);
|
|
151
|
+
return () => { alive = false; unsub(); };
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=resource.js.map
|