@rybosome/tspice 0.0.1
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/LICENSE +21 -0
- package/NOTICE +65 -0
- package/README.md +151 -0
- package/backend-contract/LICENSE +21 -0
- package/backend-contract/dist/.tsbuildinfo +1 -0
- package/backend-contract/dist/index.d.ts +237 -0
- package/backend-contract/dist/index.js +2 -0
- package/backend-fake/dist/.tsbuildinfo +1 -0
- package/backend-fake/dist/index.d.ts +4 -0
- package/backend-fake/dist/index.js +627 -0
- package/backend-node/LICENSE +21 -0
- package/backend-node/NOTICE +32 -0
- package/backend-node/dist/.tsbuildinfo +1 -0
- package/backend-node/dist/index.d.ts +4 -0
- package/backend-node/dist/index.js +389 -0
- package/backend-node/dist/native.d.ts +112 -0
- package/backend-node/dist/native.js +102 -0
- package/backend-wasm/LICENSE +21 -0
- package/backend-wasm/NOTICE +32 -0
- package/backend-wasm/dist/.tsbuildinfo +1 -0
- package/backend-wasm/dist/index.d.ts +8 -0
- package/backend-wasm/dist/index.js +1505 -0
- package/backend-wasm/dist/tspice_backend_wasm.js +19 -0
- package/backend-wasm/dist/tspice_backend_wasm.wasm +0 -0
- package/core/LICENSE +21 -0
- package/core/dist/.tsbuildinfo +1 -0
- package/core/dist/index.d.ts +6 -0
- package/core/dist/index.js +15 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/backend.d.ts +18 -0
- package/dist/backend.js +37 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +16 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4 -0
- package/dist/spice-types.d.ts +36 -0
- package/dist/spice-types.js +2 -0
- package/dist/spice.d.ts +13 -0
- package/dist/spice.js +84 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.js +2 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { BackendKind, KernelSource, SpiceBackend, SpiceBackendWasm, } from "#backend-contract";
|
|
2
|
+
export type { CreateBackendOptions } from "./backend.js";
|
|
3
|
+
export { createBackend } from "./backend.js";
|
|
4
|
+
export type { AberrationCorrection, FrameName, GetStateArgs, Mat3, SpiceTime, StateVector, Vec3, Vec6, } from "./types.js";
|
|
5
|
+
export { SpiceError } from "./errors.js";
|
|
6
|
+
export type { Spice, SpiceKit } from "./spice-types.js";
|
|
7
|
+
export type { CreateSpiceOptions } from "./spice.js";
|
|
8
|
+
export { createSpice } from "./spice.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { KernelSource, SpiceBackend } from "#backend-contract";
|
|
2
|
+
import type { FrameName, GetStateArgs, Mat3, SpiceTime, StateVector } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Low-level CSPICE-like primitive surface.
|
|
5
|
+
*
|
|
6
|
+
* This is the raw backend contract (node addon, wasm backend, etc.).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Higher-level helpers and convenience APIs built on top of the raw backend.
|
|
10
|
+
*/
|
|
11
|
+
export type SpiceKit = {
|
|
12
|
+
/** Load a SPICE kernel. */
|
|
13
|
+
loadKernel(kernel: KernelSource): void;
|
|
14
|
+
/** Unload a previously-loaded SPICE kernel. */
|
|
15
|
+
unloadKernel(path: string): void;
|
|
16
|
+
/** Convenience wrapper around `tkvrsn(\"TOOLKIT\")`. */
|
|
17
|
+
toolkitVersion(): string;
|
|
18
|
+
/** Convert UTC time string to ET seconds past J2000. */
|
|
19
|
+
utcToEt(utc: string): SpiceTime;
|
|
20
|
+
/** Convert ET seconds past J2000 to a formatted UTC string. */
|
|
21
|
+
etToUtc(et: SpiceTime, format?: string, prec?: number): string;
|
|
22
|
+
/** Compute a 3x3 frame transformation matrix (row-major). */
|
|
23
|
+
frameTransform(from: FrameName, to: FrameName, et: SpiceTime): Mat3;
|
|
24
|
+
/** Convenience wrapper around `spkezr` that returns a structured state vector. */
|
|
25
|
+
getState(args: GetStateArgs): StateVector;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Top-level `createSpice()` return type.
|
|
29
|
+
*/
|
|
30
|
+
export type Spice = {
|
|
31
|
+
/** Raw backend primitives (verbatim). */
|
|
32
|
+
cspice: SpiceBackend;
|
|
33
|
+
/** Higher-level helpers and typed conveniences. */
|
|
34
|
+
kit: SpiceKit;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=spice-types.d.ts.map
|
package/dist/spice.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SpiceBackend } from "#backend-contract";
|
|
2
|
+
import type { CreateBackendOptions } from "./backend.js";
|
|
3
|
+
import type { Spice } from "./spice-types.js";
|
|
4
|
+
export type CreateSpiceOptions = CreateBackendOptions & {
|
|
5
|
+
/**
|
|
6
|
+
* If provided, `createSpice()` will wrap this backend instead of creating a new one.
|
|
7
|
+
*
|
|
8
|
+
* Useful for testing or advanced callers.
|
|
9
|
+
*/
|
|
10
|
+
backendInstance?: SpiceBackend;
|
|
11
|
+
};
|
|
12
|
+
export declare function createSpice(options: CreateSpiceOptions): Promise<Spice>;
|
|
13
|
+
//# sourceMappingURL=spice.d.ts.map
|
package/dist/spice.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createBackend } from "./backend.js";
|
|
2
|
+
import { wrapSpiceError } from "./errors.js";
|
|
3
|
+
const DEFAULT_FRAME = "J2000";
|
|
4
|
+
const DEFAULT_ABERRATION = "NONE";
|
|
5
|
+
function splitState(state) {
|
|
6
|
+
const position = [state[0], state[1], state[2]];
|
|
7
|
+
const velocity = [state[3], state[4], state[5]];
|
|
8
|
+
return { position, velocity };
|
|
9
|
+
}
|
|
10
|
+
export async function createSpice(options) {
|
|
11
|
+
const backend = options.backendInstance ?? (await createBackend(options));
|
|
12
|
+
const cspice = backend;
|
|
13
|
+
const kit = {
|
|
14
|
+
loadKernel: (kernel) => {
|
|
15
|
+
try {
|
|
16
|
+
cspice.furnsh(kernel);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
throw wrapSpiceError("loadKernel", error);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
unloadKernel: (path) => {
|
|
23
|
+
try {
|
|
24
|
+
cspice.unload(path);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw wrapSpiceError("unloadKernel", error);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
toolkitVersion: () => {
|
|
31
|
+
try {
|
|
32
|
+
return cspice.tkvrsn("TOOLKIT");
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw wrapSpiceError("toolkitVersion", error);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
utcToEt: (utc) => {
|
|
39
|
+
try {
|
|
40
|
+
return cspice.str2et(utc);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw wrapSpiceError("utcToEt", error);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
etToUtc: (et, format = "C", prec = 3) => {
|
|
47
|
+
try {
|
|
48
|
+
return cspice.et2utc(et, format, prec);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw wrapSpiceError("etToUtc", error);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
frameTransform: (from, to, et) => {
|
|
55
|
+
try {
|
|
56
|
+
return cspice.pxform(from, to, et);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw wrapSpiceError("frameTransform", error);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
getState: ({ target, observer, at, frame = DEFAULT_FRAME, aberration = DEFAULT_ABERRATION }) => {
|
|
63
|
+
try {
|
|
64
|
+
const { state, lt } = cspice.spkezr(target, at, frame, aberration, observer);
|
|
65
|
+
const { position, velocity } = splitState(state);
|
|
66
|
+
return {
|
|
67
|
+
et: at,
|
|
68
|
+
frame,
|
|
69
|
+
target,
|
|
70
|
+
observer,
|
|
71
|
+
aberration,
|
|
72
|
+
position,
|
|
73
|
+
velocity,
|
|
74
|
+
lightTime: lt,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw wrapSpiceError("getState", error);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
return { cspice, kit };
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=spice.js.map
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** 3-vector, typically kilometers or km/s depending on context. */
|
|
2
|
+
export type Vec3 = readonly [number, number, number];
|
|
3
|
+
/** 6-vector, typically (x,y,z,vx,vy,vz). */
|
|
4
|
+
export type Vec6 = readonly [
|
|
5
|
+
number,
|
|
6
|
+
number,
|
|
7
|
+
number,
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
number
|
|
11
|
+
];
|
|
12
|
+
/** 3x3 matrix, row-major. */
|
|
13
|
+
export type Mat3 = readonly [
|
|
14
|
+
number,
|
|
15
|
+
number,
|
|
16
|
+
number,
|
|
17
|
+
number,
|
|
18
|
+
number,
|
|
19
|
+
number,
|
|
20
|
+
number,
|
|
21
|
+
number,
|
|
22
|
+
number
|
|
23
|
+
];
|
|
24
|
+
/** SPICE frame name (e.g. "J2000", "IAU_EARTH"). */
|
|
25
|
+
export type FrameName = string;
|
|
26
|
+
/** Aberration correction string accepted by `spkezr`. */
|
|
27
|
+
export type AberrationCorrection = "NONE" | "LT" | "LT+S" | "CN" | "CN+S" | "XLT" | "XLT+S" | "XCN" | "XCN+S";
|
|
28
|
+
export type SpiceTime = number & {
|
|
29
|
+
readonly __tspiceBrand: "SpiceTime";
|
|
30
|
+
};
|
|
31
|
+
export type StateVector = {
|
|
32
|
+
/** Seconds past J2000 (ET). */
|
|
33
|
+
et: SpiceTime;
|
|
34
|
+
/** Reference frame used for `position`/`velocity`. */
|
|
35
|
+
frame: FrameName;
|
|
36
|
+
/** Target body/ID string used for the query. */
|
|
37
|
+
target: string;
|
|
38
|
+
/** Observer body/ID string used for the query. */
|
|
39
|
+
observer: string;
|
|
40
|
+
/** Aberration correction used for the query. */
|
|
41
|
+
aberration: AberrationCorrection;
|
|
42
|
+
position: Vec3;
|
|
43
|
+
velocity: Vec3;
|
|
44
|
+
/** One-way light time (seconds). */
|
|
45
|
+
lightTime: number;
|
|
46
|
+
};
|
|
47
|
+
export type GetStateArgs = {
|
|
48
|
+
target: string;
|
|
49
|
+
observer: string;
|
|
50
|
+
at: SpiceTime;
|
|
51
|
+
frame?: FrameName;
|
|
52
|
+
aberration?: AberrationCorrection;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rybosome/tspice",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"imports": {
|
|
7
|
+
"#core": "./core/dist/index.js",
|
|
8
|
+
"#backend-contract": "./backend-contract/dist/index.js",
|
|
9
|
+
"#backend-fake": "./backend-fake/dist/index.js",
|
|
10
|
+
"#backend-wasm": "./backend-wasm/dist/index.js",
|
|
11
|
+
"#backend-node": "./backend-node/dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"optionalDependencies": {
|
|
22
|
+
"@rybosome/tspice-native-darwin-arm64": "0.0.1",
|
|
23
|
+
"@rybosome/tspice-native-darwin-x64": "0.0.1",
|
|
24
|
+
"@rybosome/tspice-native-linux-x64-gnu": "0.0.1"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"backend-contract",
|
|
29
|
+
"core",
|
|
30
|
+
"backend-fake",
|
|
31
|
+
"backend-wasm",
|
|
32
|
+
"backend-node",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"NOTICE"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|