@rybosome/tspice 0.0.1 → 0.0.2-alpha

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.
Files changed (79) hide show
  1. package/backend-contract/dist/.tsbuildinfo +1 -1
  2. package/backend-contract/dist/domains/coords-vectors.d.ts +30 -0
  3. package/backend-contract/dist/domains/coords-vectors.js +2 -0
  4. package/backend-contract/dist/domains/ephemeris.d.ts +8 -0
  5. package/backend-contract/dist/domains/ephemeris.js +2 -0
  6. package/backend-contract/dist/domains/frames.d.ts +33 -0
  7. package/backend-contract/dist/domains/frames.js +2 -0
  8. package/backend-contract/dist/domains/geometry.d.ts +14 -0
  9. package/backend-contract/dist/domains/geometry.js +2 -0
  10. package/backend-contract/dist/domains/ids-names.d.ts +10 -0
  11. package/backend-contract/dist/domains/ids-names.js +2 -0
  12. package/backend-contract/dist/domains/kernels.d.ts +22 -0
  13. package/backend-contract/dist/domains/kernels.js +2 -0
  14. package/backend-contract/dist/domains/time.d.ts +24 -0
  15. package/backend-contract/dist/domains/time.js +2 -0
  16. package/backend-contract/dist/index.d.ts +17 -222
  17. package/backend-contract/dist/index.js +8 -1
  18. package/backend-contract/dist/shared/types.d.ts +108 -0
  19. package/backend-contract/dist/shared/types.js +2 -0
  20. package/backend-fake/dist/.tsbuildinfo +1 -1
  21. package/backend-node/dist/.tsbuildinfo +1 -1
  22. package/backend-node/dist/codec/errors.d.ts +9 -0
  23. package/backend-node/dist/codec/errors.js +14 -0
  24. package/backend-node/dist/domains/coords-vectors.d.ts +4 -0
  25. package/backend-node/dist/domains/coords-vectors.js +62 -0
  26. package/backend-node/dist/domains/ephemeris.d.ts +4 -0
  27. package/backend-node/dist/domains/ephemeris.js +24 -0
  28. package/backend-node/dist/domains/frames.d.ts +4 -0
  29. package/backend-node/dist/domains/frames.js +74 -0
  30. package/backend-node/dist/domains/geometry.d.ts +4 -0
  31. package/backend-node/dist/domains/geometry.js +67 -0
  32. package/backend-node/dist/domains/ids-names.d.ts +4 -0
  33. package/backend-node/dist/domains/ids-names.js +22 -0
  34. package/backend-node/dist/domains/kernels.d.ts +5 -0
  35. package/backend-node/dist/domains/kernels.js +37 -0
  36. package/backend-node/dist/domains/time.d.ts +4 -0
  37. package/backend-node/dist/domains/time.js +36 -0
  38. package/backend-node/dist/index.js +18 -373
  39. package/backend-node/dist/lowlevel/binding.d.ts +3 -0
  40. package/backend-node/dist/lowlevel/binding.js +44 -0
  41. package/backend-node/dist/native.d.ts +2 -111
  42. package/backend-node/dist/native.js +1 -101
  43. package/backend-node/dist/runtime/addon.d.ts +112 -0
  44. package/backend-node/dist/runtime/addon.js +102 -0
  45. package/backend-node/dist/runtime/kernel-staging.d.ts +9 -0
  46. package/backend-node/dist/runtime/kernel-staging.js +75 -0
  47. package/backend-wasm/dist/.tsbuildinfo +1 -1
  48. package/backend-wasm/dist/codec/calls.d.ts +4 -0
  49. package/backend-wasm/dist/codec/calls.js +41 -0
  50. package/backend-wasm/dist/codec/errors.d.ts +3 -0
  51. package/backend-wasm/dist/codec/errors.js +5 -0
  52. package/backend-wasm/dist/codec/found.d.ts +9 -0
  53. package/backend-wasm/dist/codec/found.js +68 -0
  54. package/backend-wasm/dist/codec/strings.d.ts +3 -0
  55. package/backend-wasm/dist/codec/strings.js +12 -0
  56. package/backend-wasm/dist/domains/coords-vectors.d.ts +4 -0
  57. package/backend-wasm/dist/domains/coords-vectors.js +312 -0
  58. package/backend-wasm/dist/domains/ephemeris.d.ts +4 -0
  59. package/backend-wasm/dist/domains/ephemeris.js +81 -0
  60. package/backend-wasm/dist/domains/frames.d.ts +4 -0
  61. package/backend-wasm/dist/domains/frames.js +239 -0
  62. package/backend-wasm/dist/domains/geometry.d.ts +4 -0
  63. package/backend-wasm/dist/domains/geometry.js +240 -0
  64. package/backend-wasm/dist/domains/ids-names.d.ts +4 -0
  65. package/backend-wasm/dist/domains/ids-names.js +18 -0
  66. package/backend-wasm/dist/domains/kernels.d.ts +5 -0
  67. package/backend-wasm/dist/domains/kernels.js +97 -0
  68. package/backend-wasm/dist/domains/time.d.ts +5 -0
  69. package/backend-wasm/dist/domains/time.js +180 -0
  70. package/backend-wasm/dist/index.d.ts +2 -7
  71. package/backend-wasm/dist/index.js +1 -1504
  72. package/backend-wasm/dist/lowlevel/exports.d.ts +49 -0
  73. package/backend-wasm/dist/lowlevel/exports.js +41 -0
  74. package/backend-wasm/dist/runtime/create-backend.d.ts +8 -0
  75. package/backend-wasm/dist/runtime/create-backend.js +81 -0
  76. package/backend-wasm/dist/runtime/fs.d.ts +9 -0
  77. package/backend-wasm/dist/runtime/fs.js +30 -0
  78. package/dist/.tsbuildinfo +1 -1
  79. package/package.json +4 -4
@@ -1,102 +1,2 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { createRequire } from "node:module";
4
- import { fileURLToPath } from "node:url";
5
- let cachedAddon;
6
- const ADDON_TARGET = "tspice_backend_node";
7
- const ADDON_FILE = `${ADDON_TARGET}.node`;
8
- const NATIVE_PLATFORM_PACKAGES = {
9
- darwin: {
10
- arm64: "@rybosome/tspice-native-darwin-arm64",
11
- x64: "@rybosome/tspice-native-darwin-x64",
12
- },
13
- linux: {
14
- x64: "@rybosome/tspice-native-linux-x64-gnu",
15
- },
16
- };
17
- const BUILD_HINT = "Try rebuilding it: pnpm run fetch:cspice && pnpm -C packages/backend-node build:native. " +
18
- "Or set TSPICE_CSPICE_DIR=/abs/path/to/cspice (containing include/ and lib/). " +
19
- "Or set TSPICE_BACKEND_NODE_BINDING_PATH to an explicit .node path.";
20
- function getPackageRoot(importMetaUrl) {
21
- // Works both in the monorepo layout (`.../backend-node/dist/native.js`) and
22
- // in the published `dist-publish/` layout where this code is vendored into
23
- // `@rybosome/tspice`.
24
- return path.resolve(path.dirname(fileURLToPath(importMetaUrl)), "..");
25
- }
26
- function loadAddon(require, bindingPath) {
27
- const resolved = path.resolve(bindingPath);
28
- try {
29
- return require(resolved);
30
- }
31
- catch (error) {
32
- const errorMessage = error instanceof Error ? error.message : String(error);
33
- const { arch, platform } = process;
34
- throw new Error(`Failed to load tspice native backend at "${resolved}" for ${platform}-${arch}. ` +
35
- `${BUILD_HINT} ` +
36
- `Original error: ${errorMessage}`, { cause: error });
37
- }
38
- }
39
- function tryGetPlatformBindingPath(require) {
40
- const platform = process.platform;
41
- const arch = process.arch;
42
- const pkgName = NATIVE_PLATFORM_PACKAGES[platform]?.[arch];
43
- if (!pkgName) {
44
- return undefined;
45
- }
46
- try {
47
- const mod = require(pkgName);
48
- if (typeof mod === "string") {
49
- return mod;
50
- }
51
- if (typeof mod === "object" &&
52
- mod !== null &&
53
- "bindingPath" in mod &&
54
- typeof mod.bindingPath === "string") {
55
- return mod.bindingPath;
56
- }
57
- return undefined;
58
- }
59
- catch (error) {
60
- // If the platform package isn't installed, that's expected.
61
- if (error?.code === "MODULE_NOT_FOUND") {
62
- return undefined;
63
- }
64
- throw error;
65
- }
66
- }
67
- export function getNativeAddon() {
68
- if (cachedAddon) {
69
- return cachedAddon;
70
- }
71
- const require = createRequire(import.meta.url);
72
- const packageRoot = getPackageRoot(import.meta.url);
73
- const override = process.env.TSPICE_BACKEND_NODE_BINDING_PATH;
74
- if (override) {
75
- const resolvedOverride = path.resolve(packageRoot, override);
76
- if (!fs.existsSync(resolvedOverride)) {
77
- const { arch, platform } = process;
78
- throw new Error(`TSPICE_BACKEND_NODE_BINDING_PATH points to a non-existent file: ${resolvedOverride} (platform=${platform}, arch=${arch}). Ensure it points to a built ${ADDON_FILE}.`);
79
- }
80
- cachedAddon = loadAddon(require, resolvedOverride);
81
- return cachedAddon;
82
- }
83
- const platformBindingPath = tryGetPlatformBindingPath(require);
84
- if (platformBindingPath) {
85
- cachedAddon = loadAddon(require, platformBindingPath);
86
- return cachedAddon;
87
- }
88
- const candidates = [
89
- path.join(packageRoot, "native", "build", "Release", ADDON_FILE),
90
- ];
91
- const existing = candidates.find((p) => fs.existsSync(p));
92
- if (!existing) {
93
- const { arch, platform } = process;
94
- throw new Error(`Native addon ${ADDON_FILE} not found for ${platform}-${arch}. Looked for:\n` +
95
- candidates.map((p) => `- ${p}`).join("\n") +
96
- `\n\nIf you built a Debug addon locally, set TSPICE_BACKEND_NODE_BINDING_PATH to its path.` +
97
- `\n\n${BUILD_HINT}`);
98
- }
99
- cachedAddon = loadAddon(require, existing);
100
- return cachedAddon;
101
- }
1
+ export { getNativeAddon } from "./runtime/addon.js";
102
2
  //# sourceMappingURL=native.js.map
@@ -0,0 +1,112 @@
1
+ export type NativeAddon = {
2
+ spiceVersion(): string;
3
+ furnsh(path: string): void;
4
+ unload(path: string): void;
5
+ kclear(): void;
6
+ ktotal(kind?: string): number;
7
+ kdata(which: number, kind?: string): {
8
+ found: boolean;
9
+ file?: string;
10
+ filtyp?: string;
11
+ source?: string;
12
+ handle?: number;
13
+ };
14
+ str2et(utc: string): number;
15
+ et2utc(et: number, format: string, prec: number): string;
16
+ timout(et: number, picture: string): string;
17
+ bodn2c(name: string): {
18
+ found: boolean;
19
+ code?: number;
20
+ };
21
+ bodc2n(code: number): {
22
+ found: boolean;
23
+ name?: string;
24
+ };
25
+ namfrm(name: string): {
26
+ found: boolean;
27
+ code?: number;
28
+ };
29
+ frmnam(code: number): {
30
+ found: boolean;
31
+ name?: string;
32
+ };
33
+ cidfrm(center: number): {
34
+ found: boolean;
35
+ frcode?: number;
36
+ frname?: string;
37
+ };
38
+ cnmfrm(centerName: string): {
39
+ found: boolean;
40
+ frcode?: number;
41
+ frname?: string;
42
+ };
43
+ scs2e(sc: number, sclkch: string): number;
44
+ sce2s(sc: number, et: number): string;
45
+ ckgp(inst: number, sclkdp: number, tol: number, ref: string): {
46
+ found: boolean;
47
+ cmat?: number[];
48
+ clkout?: number;
49
+ };
50
+ ckgpav(inst: number, sclkdp: number, tol: number, ref: string): {
51
+ found: boolean;
52
+ cmat?: number[];
53
+ av?: number[];
54
+ clkout?: number;
55
+ };
56
+ spkezr(target: string, et: number, ref: string, abcorr: string, obs: string): {
57
+ state: number[];
58
+ lt: number;
59
+ };
60
+ spkpos(target: string, et: number, ref: string, abcorr: string, obs: string): {
61
+ pos: number[];
62
+ lt: number;
63
+ };
64
+ subpnt(method: string, target: string, et: number, fixref: string, abcorr: string, observer: string): {
65
+ spoint: number[];
66
+ trgepc: number;
67
+ srfvec: number[];
68
+ };
69
+ subslr(method: string, target: string, et: number, fixref: string, abcorr: string, observer: string): {
70
+ spoint: number[];
71
+ trgepc: number;
72
+ srfvec: number[];
73
+ };
74
+ sincpt(method: string, target: string, et: number, fixref: string, abcorr: string, observer: string, dref: string, dvec: number[]): {
75
+ found: boolean;
76
+ spoint?: number[];
77
+ trgepc?: number;
78
+ srfvec?: number[];
79
+ };
80
+ ilumin(method: string, target: string, et: number, fixref: string, abcorr: string, observer: string, spoint: number[]): {
81
+ trgepc: number;
82
+ srfvec: number[];
83
+ phase: number;
84
+ incdnc: number;
85
+ emissn: number;
86
+ };
87
+ occult(targ1: string, shape1: string, frame1: string, targ2: string, shape2: string, frame2: string, abcorr: string, observer: string, et: number): number;
88
+ pxform(from: string, to: string, et: number): number[];
89
+ sxform(from: string, to: string, et: number): number[];
90
+ reclat(rect: number[]): {
91
+ radius: number;
92
+ lon: number;
93
+ lat: number;
94
+ };
95
+ latrec(radius: number, lon: number, lat: number): number[];
96
+ recsph(rect: number[]): {
97
+ radius: number;
98
+ colat: number;
99
+ lon: number;
100
+ };
101
+ sphrec(radius: number, colat: number, lon: number): number[];
102
+ vnorm(v: number[]): number;
103
+ vhat(v: number[]): number[];
104
+ vdot(a: number[], b: number[]): number;
105
+ vcrss(a: number[], b: number[]): number[];
106
+ mxv(m: number[], v: number[]): number[];
107
+ mtxv(m: number[], v: number[]): number[];
108
+ /** Internal test helper (not part of the backend contract). */
109
+ __ktotalAll(): number;
110
+ };
111
+ export declare function getNativeAddon(): NativeAddon;
112
+ //# sourceMappingURL=addon.d.ts.map
@@ -0,0 +1,102 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { createRequire } from "node:module";
4
+ import { fileURLToPath } from "node:url";
5
+ let cachedAddon;
6
+ const ADDON_TARGET = "tspice_backend_node";
7
+ const ADDON_FILE = `${ADDON_TARGET}.node`;
8
+ const NATIVE_PLATFORM_PACKAGES = {
9
+ darwin: {
10
+ arm64: "@rybosome/tspice-native-darwin-arm64",
11
+ x64: "@rybosome/tspice-native-darwin-x64",
12
+ },
13
+ linux: {
14
+ x64: "@rybosome/tspice-native-linux-x64-gnu",
15
+ },
16
+ };
17
+ const BUILD_HINT = "Try rebuilding it: pnpm run fetch:cspice && pnpm -C packages/backend-node build:native. " +
18
+ "Or set TSPICE_CSPICE_DIR=/abs/path/to/cspice (containing include/ and lib/). " +
19
+ "Or set TSPICE_BACKEND_NODE_BINDING_PATH to an explicit .node path.";
20
+ function getPackageRoot(importMetaUrl) {
21
+ // Works both in the monorepo layout (`.../backend-node/dist/runtime/addon.js`) and
22
+ // in the published `dist-publish/` layout where this code is vendored into
23
+ // `@rybosome/tspice`.
24
+ return path.resolve(path.dirname(fileURLToPath(importMetaUrl)), "..", "..");
25
+ }
26
+ function loadAddon(require, bindingPath) {
27
+ const resolved = path.resolve(bindingPath);
28
+ try {
29
+ return require(resolved);
30
+ }
31
+ catch (error) {
32
+ const errorMessage = error instanceof Error ? error.message : String(error);
33
+ const { arch, platform } = process;
34
+ throw new Error(`Failed to load tspice native backend at "${resolved}" for ${platform}-${arch}. ` +
35
+ `${BUILD_HINT} ` +
36
+ `Original error: ${errorMessage}`, { cause: error });
37
+ }
38
+ }
39
+ function tryGetPlatformBindingPath(require) {
40
+ const platform = process.platform;
41
+ const arch = process.arch;
42
+ const pkgName = NATIVE_PLATFORM_PACKAGES[platform]?.[arch];
43
+ if (!pkgName) {
44
+ return undefined;
45
+ }
46
+ try {
47
+ const mod = require(pkgName);
48
+ if (typeof mod === "string") {
49
+ return mod;
50
+ }
51
+ if (typeof mod === "object" &&
52
+ mod !== null &&
53
+ "bindingPath" in mod &&
54
+ typeof mod.bindingPath === "string") {
55
+ return mod.bindingPath;
56
+ }
57
+ return undefined;
58
+ }
59
+ catch (error) {
60
+ // If the platform package isn't installed, that's expected.
61
+ if (error?.code === "MODULE_NOT_FOUND") {
62
+ return undefined;
63
+ }
64
+ throw error;
65
+ }
66
+ }
67
+ export function getNativeAddon() {
68
+ if (cachedAddon) {
69
+ return cachedAddon;
70
+ }
71
+ const require = createRequire(import.meta.url);
72
+ const packageRoot = getPackageRoot(import.meta.url);
73
+ const override = process.env.TSPICE_BACKEND_NODE_BINDING_PATH;
74
+ if (override) {
75
+ const resolvedOverride = path.resolve(packageRoot, override);
76
+ if (!fs.existsSync(resolvedOverride)) {
77
+ const { arch, platform } = process;
78
+ throw new Error(`TSPICE_BACKEND_NODE_BINDING_PATH points to a non-existent file: ${resolvedOverride} (platform=${platform}, arch=${arch}). Ensure it points to a built ${ADDON_FILE}.`);
79
+ }
80
+ cachedAddon = loadAddon(require, resolvedOverride);
81
+ return cachedAddon;
82
+ }
83
+ const platformBindingPath = tryGetPlatformBindingPath(require);
84
+ if (platformBindingPath) {
85
+ cachedAddon = loadAddon(require, platformBindingPath);
86
+ return cachedAddon;
87
+ }
88
+ const candidates = [
89
+ path.join(packageRoot, "native", "build", "Release", ADDON_FILE),
90
+ ];
91
+ const existing = candidates.find((p) => fs.existsSync(p));
92
+ if (!existing) {
93
+ const { arch, platform } = process;
94
+ throw new Error(`Native addon ${ADDON_FILE} not found for ${platform}-${arch}. Looked for:\n` +
95
+ candidates.map((p) => `- ${p}`).join("\n") +
96
+ `\n\nIf you built a Debug addon locally, set TSPICE_BACKEND_NODE_BINDING_PATH to its path.` +
97
+ `\n\n${BUILD_HINT}`);
98
+ }
99
+ cachedAddon = loadAddon(require, existing);
100
+ return cachedAddon;
101
+ }
102
+ //# sourceMappingURL=addon.js.map
@@ -0,0 +1,9 @@
1
+ import type { KernelSource } from "#backend-contract";
2
+ import type { NativeAddon } from "./addon.js";
3
+ export type KernelStager = {
4
+ furnsh(kernel: KernelSource, native: NativeAddon): void;
5
+ unload(path: string, native: NativeAddon): void;
6
+ kclear(native: NativeAddon): void;
7
+ };
8
+ export declare function createKernelStager(): KernelStager;
9
+ //# sourceMappingURL=kernel-staging.d.ts.map
@@ -0,0 +1,75 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { randomUUID } from "node:crypto";
5
+ export function createKernelStager() {
6
+ const tempByVirtualPath = new Map();
7
+ let tempKernelRootDir;
8
+ function ensureTempKernelRootDir() {
9
+ if (tempKernelRootDir) {
10
+ return tempKernelRootDir;
11
+ }
12
+ tempKernelRootDir = fs.mkdtempSync(path.join(os.tmpdir(), "tspice-kernels-"));
13
+ return tempKernelRootDir;
14
+ }
15
+ function safeUnlink(filePath) {
16
+ try {
17
+ fs.unlinkSync(filePath);
18
+ }
19
+ catch (error) {
20
+ // Best-effort cleanup.
21
+ if (error?.code !== "ENOENT") {
22
+ throw error;
23
+ }
24
+ }
25
+ }
26
+ return {
27
+ furnsh: (_kernel, native) => {
28
+ const kernel = _kernel;
29
+ if (typeof kernel === "string") {
30
+ native.furnsh(kernel);
31
+ return;
32
+ }
33
+ // For byte-backed kernels, we write to a temp file and load via CSPICE.
34
+ // We then remember the resolved temp path so `unload(kernel.path)` unloads
35
+ // the correct file.
36
+ const existingTemp = tempByVirtualPath.get(kernel.path);
37
+ if (existingTemp) {
38
+ native.unload(existingTemp);
39
+ tempByVirtualPath.delete(kernel.path);
40
+ safeUnlink(existingTemp);
41
+ }
42
+ const rootDir = ensureTempKernelRootDir();
43
+ const fileName = path.basename(kernel.path) || "kernel";
44
+ const tempPath = path.join(rootDir, `${randomUUID()}-${fileName}`);
45
+ fs.writeFileSync(tempPath, kernel.bytes);
46
+ try {
47
+ native.furnsh(tempPath);
48
+ }
49
+ catch (error) {
50
+ safeUnlink(tempPath);
51
+ throw error;
52
+ }
53
+ tempByVirtualPath.set(kernel.path, tempPath);
54
+ },
55
+ unload: (_path, native) => {
56
+ const resolved = tempByVirtualPath.get(_path);
57
+ if (resolved) {
58
+ native.unload(resolved);
59
+ tempByVirtualPath.delete(_path);
60
+ safeUnlink(resolved);
61
+ return;
62
+ }
63
+ native.unload(_path);
64
+ },
65
+ kclear: (native) => {
66
+ native.kclear();
67
+ // Clear any byte-backed kernels we staged to temp files.
68
+ for (const tempPath of tempByVirtualPath.values()) {
69
+ safeUnlink(tempPath);
70
+ }
71
+ tempByVirtualPath.clear();
72
+ },
73
+ };
74
+ }
75
+ //# sourceMappingURL=kernel-staging.js.map