@rybosome/tspice 0.0.7 → 0.0.8

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 (214) hide show
  1. package/README.md +140 -78
  2. package/backend-contract/dist/.tsbuildinfo +1 -1
  3. package/backend-contract/dist/domains/cells-windows.d.ts +94 -0
  4. package/backend-contract/dist/domains/cells-windows.js +10 -0
  5. package/backend-contract/dist/domains/coords-vectors.d.ts +50 -0
  6. package/backend-contract/dist/domains/dsk.d.ts +49 -0
  7. package/backend-contract/dist/domains/dsk.js +2 -0
  8. package/backend-contract/dist/domains/ek.d.ts +186 -0
  9. package/backend-contract/dist/domains/ek.js +8 -0
  10. package/backend-contract/dist/domains/ephemeris.d.ts +141 -3
  11. package/backend-contract/dist/domains/error.d.ts +42 -0
  12. package/backend-contract/dist/domains/error.js +33 -0
  13. package/backend-contract/dist/domains/file-io.d.ts +114 -0
  14. package/backend-contract/dist/domains/file-io.js +8 -0
  15. package/backend-contract/dist/domains/frames.d.ts +40 -0
  16. package/backend-contract/dist/domains/geometry-gf.d.ts +44 -0
  17. package/backend-contract/dist/domains/geometry-gf.js +14 -0
  18. package/backend-contract/dist/domains/geometry.d.ts +21 -1
  19. package/backend-contract/dist/domains/ids-names-normalize.d.ts +3 -0
  20. package/backend-contract/dist/domains/ids-names-normalize.js +74 -0
  21. package/backend-contract/dist/domains/ids-names.d.ts +37 -0
  22. package/backend-contract/dist/domains/kernel-pool.d.ts +134 -0
  23. package/backend-contract/dist/domains/kernel-pool.js +2 -0
  24. package/backend-contract/dist/domains/kernels-utils.d.ts +44 -0
  25. package/backend-contract/dist/domains/kernels-utils.js +265 -0
  26. package/backend-contract/dist/domains/kernels.d.ts +39 -3
  27. package/backend-contract/dist/domains/time.d.ts +102 -0
  28. package/backend-contract/dist/index.d.ts +31 -3
  29. package/backend-contract/dist/index.js +15 -1
  30. package/backend-contract/dist/shared/errors.d.ts +6 -0
  31. package/backend-contract/dist/shared/errors.js +8 -0
  32. package/backend-contract/dist/shared/mat3.d.ts +26 -14
  33. package/backend-contract/dist/shared/mat3.js +46 -17
  34. package/backend-contract/dist/shared/mat6.d.ts +34 -0
  35. package/backend-contract/dist/shared/mat6.js +116 -0
  36. package/backend-contract/dist/shared/spice-handles.d.ts +20 -0
  37. package/backend-contract/dist/shared/spice-handles.js +82 -0
  38. package/backend-contract/dist/shared/spice-int.d.ts +32 -0
  39. package/backend-contract/dist/shared/spice-int.js +41 -0
  40. package/backend-contract/dist/shared/types.d.ts +106 -1
  41. package/backend-contract/dist/shared/vec.d.ts +54 -0
  42. package/backend-contract/dist/shared/vec.js +162 -0
  43. package/backend-fake/dist/.tsbuildinfo +1 -1
  44. package/backend-fake/dist/index.d.ts +19 -1
  45. package/backend-fake/dist/index.js +1103 -18
  46. package/backend-node/dist/.tsbuildinfo +1 -1
  47. package/backend-node/dist/codec/arrays.d.ts +9 -0
  48. package/backend-node/dist/codec/arrays.js +36 -0
  49. package/backend-node/dist/codec/errors.d.ts +6 -6
  50. package/backend-node/dist/codec/errors.js +6 -6
  51. package/backend-node/dist/domains/cells-windows.d.ts +5 -0
  52. package/backend-node/dist/domains/cells-windows.js +112 -0
  53. package/backend-node/dist/domains/coords-vectors.d.ts +1 -0
  54. package/backend-node/dist/domains/coords-vectors.js +64 -1
  55. package/backend-node/dist/domains/dsk.d.ts +6 -0
  56. package/backend-node/dist/domains/dsk.js +108 -0
  57. package/backend-node/dist/domains/ek.d.ts +10 -0
  58. package/backend-node/dist/domains/ek.js +100 -0
  59. package/backend-node/dist/domains/ephemeris.d.ts +5 -1
  60. package/backend-node/dist/domains/ephemeris.js +150 -1
  61. package/backend-node/dist/domains/error.d.ts +5 -0
  62. package/backend-node/dist/domains/error.js +34 -0
  63. package/backend-node/dist/domains/file-io.d.ts +7 -0
  64. package/backend-node/dist/domains/file-io.js +105 -0
  65. package/backend-node/dist/domains/frames.d.ts +1 -0
  66. package/backend-node/dist/domains/frames.js +52 -0
  67. package/backend-node/dist/domains/geometry-gf.d.ts +5 -0
  68. package/backend-node/dist/domains/geometry-gf.js +74 -0
  69. package/backend-node/dist/domains/geometry.d.ts +1 -0
  70. package/backend-node/dist/domains/geometry.js +62 -0
  71. package/backend-node/dist/domains/ids-names.d.ts +2 -1
  72. package/backend-node/dist/domains/ids-names.js +30 -0
  73. package/backend-node/dist/domains/kernel-pool.d.ts +5 -0
  74. package/backend-node/dist/domains/kernel-pool.js +74 -0
  75. package/backend-node/dist/domains/kernels.d.ts +1 -0
  76. package/backend-node/dist/domains/kernels.js +100 -13
  77. package/backend-node/dist/domains/time.d.ts +1 -0
  78. package/backend-node/dist/domains/time.js +75 -1
  79. package/backend-node/dist/index.d.ts +2 -0
  80. package/backend-node/dist/index.js +62 -1
  81. package/backend-node/dist/lowlevel/binding.d.ts +3 -0
  82. package/backend-node/dist/lowlevel/binding.js +115 -0
  83. package/backend-node/dist/runtime/addon.d.ts +271 -0
  84. package/backend-node/dist/runtime/addon.js +3 -0
  85. package/backend-node/dist/runtime/kernel-staging.d.ts +17 -0
  86. package/backend-node/dist/runtime/kernel-staging.js +80 -7
  87. package/backend-node/dist/runtime/spice-handles.d.ts +3 -0
  88. package/backend-node/dist/runtime/spice-handles.js +2 -0
  89. package/backend-node/dist/runtime/virtual-output-staging.d.ts +16 -0
  90. package/backend-node/dist/runtime/virtual-output-staging.js +148 -0
  91. package/backend-wasm/dist/.tsbuildinfo +1 -1
  92. package/backend-wasm/dist/codec/alloc.d.ts +19 -0
  93. package/backend-wasm/dist/codec/alloc.js +64 -0
  94. package/backend-wasm/dist/codec/calls.d.ts +2 -0
  95. package/backend-wasm/dist/codec/calls.js +13 -24
  96. package/backend-wasm/dist/codec/errors.d.ts +6 -0
  97. package/backend-wasm/dist/codec/errors.js +34 -2
  98. package/backend-wasm/dist/codec/found.d.ts +2 -0
  99. package/backend-wasm/dist/codec/found.js +20 -43
  100. package/backend-wasm/dist/codec/strings.d.ts +31 -1
  101. package/backend-wasm/dist/codec/strings.js +93 -6
  102. package/backend-wasm/dist/domains/cells-windows.d.ts +9 -0
  103. package/backend-wasm/dist/domains/cells-windows.js +392 -0
  104. package/backend-wasm/dist/domains/coords-vectors.d.ts +1 -0
  105. package/backend-wasm/dist/domains/coords-vectors.js +377 -187
  106. package/backend-wasm/dist/domains/dsk.d.ts +6 -0
  107. package/backend-wasm/dist/domains/dsk.js +179 -0
  108. package/backend-wasm/dist/domains/ek.d.ts +6 -0
  109. package/backend-wasm/dist/domains/ek.js +543 -0
  110. package/backend-wasm/dist/domains/ephemeris.d.ts +4 -1
  111. package/backend-wasm/dist/domains/ephemeris.js +405 -46
  112. package/backend-wasm/dist/domains/error.d.ts +5 -0
  113. package/backend-wasm/dist/domains/error.js +109 -0
  114. package/backend-wasm/dist/domains/file-io.d.ts +7 -0
  115. package/backend-wasm/dist/domains/file-io.js +462 -0
  116. package/backend-wasm/dist/domains/frames.d.ts +1 -0
  117. package/backend-wasm/dist/domains/frames.js +136 -4
  118. package/backend-wasm/dist/domains/geometry-gf.d.ts +5 -0
  119. package/backend-wasm/dist/domains/geometry-gf.js +178 -0
  120. package/backend-wasm/dist/domains/geometry.d.ts +1 -0
  121. package/backend-wasm/dist/domains/geometry.js +210 -0
  122. package/backend-wasm/dist/domains/ids-names.d.ts +2 -1
  123. package/backend-wasm/dist/domains/ids-names.js +89 -0
  124. package/backend-wasm/dist/domains/kernel-pool.d.ts +5 -0
  125. package/backend-wasm/dist/domains/kernel-pool.js +357 -0
  126. package/backend-wasm/dist/domains/kernels.d.ts +1 -0
  127. package/backend-wasm/dist/domains/kernels.js +91 -2
  128. package/backend-wasm/dist/domains/time.d.ts +2 -0
  129. package/backend-wasm/dist/domains/time.js +235 -133
  130. package/backend-wasm/dist/lowlevel/exports.d.ts +215 -1
  131. package/backend-wasm/dist/lowlevel/exports.js +217 -38
  132. package/backend-wasm/dist/runtime/create-backend-options.d.ts +21 -0
  133. package/backend-wasm/dist/runtime/create-backend.node.d.ts +7 -0
  134. package/backend-wasm/dist/runtime/create-backend.node.js +283 -12
  135. package/backend-wasm/dist/runtime/create-backend.web.d.ts +1 -0
  136. package/backend-wasm/dist/runtime/create-backend.web.js +40 -4
  137. package/backend-wasm/dist/runtime/fs.d.ts +5 -0
  138. package/backend-wasm/dist/runtime/fs.js +5 -0
  139. package/backend-wasm/dist/runtime/spice-handles.d.ts +3 -0
  140. package/backend-wasm/dist/runtime/spice-handles.js +2 -0
  141. package/backend-wasm/dist/runtime/virtual-outputs.d.ts +16 -0
  142. package/backend-wasm/dist/runtime/virtual-outputs.js +35 -0
  143. package/backend-wasm/dist/tspice_backend_wasm.node.js +3 -3
  144. package/backend-wasm/dist/tspice_backend_wasm.wasm +0 -0
  145. package/backend-wasm/dist/tspice_backend_wasm.web.js +1 -1
  146. package/core/dist/.tsbuildinfo +1 -1
  147. package/core/dist/index.d.ts +19 -8
  148. package/core/dist/index.js +19 -8
  149. package/dist/.tsbuildinfo +1 -1
  150. package/dist/backend.d.ts +5 -0
  151. package/dist/clients/createSpiceAsyncFromTransport.d.ts +5 -0
  152. package/dist/clients/createSpiceAsyncFromTransport.js +90 -0
  153. package/dist/clients/createSpiceSyncFromTransport.d.ts +5 -0
  154. package/dist/clients/createSpiceSyncFromTransport.js +88 -0
  155. package/dist/clients/spiceClients.d.ts +59 -0
  156. package/dist/clients/spiceClients.js +292 -0
  157. package/dist/errors.d.ts +4 -0
  158. package/dist/errors.js +4 -0
  159. package/dist/index.d.ts +10 -7
  160. package/dist/index.js +4 -3
  161. package/dist/kernels/defaultKernelPathFromUrl.d.ts +8 -0
  162. package/dist/kernels/defaultKernelPathFromUrl.js +32 -0
  163. package/dist/kernels/kernelPack.d.ts +88 -0
  164. package/dist/kernels/kernelPack.js +122 -0
  165. package/dist/kernels/kernels.d.ts +98 -0
  166. package/dist/kernels/kernels.js +217 -0
  167. package/dist/kernels/naifKernelId.d.ts +2 -0
  168. package/dist/kernels/naifKernelId.js +2 -0
  169. package/dist/kit/math/mat3.d.ts +9 -1
  170. package/dist/kit/math/mat3.js +9 -1
  171. package/dist/kit/spice/create-kit.d.ts +1 -0
  172. package/dist/kit/spice/create-kit.js +1 -0
  173. package/dist/kit/spice/frames.d.ts +1 -0
  174. package/dist/kit/spice/frames.js +1 -0
  175. package/dist/kit/spice/kernels.d.ts +1 -0
  176. package/dist/kit/spice/kernels.js +1 -0
  177. package/dist/kit/spice/state.d.ts +2 -1
  178. package/dist/kit/spice/state.js +8 -4
  179. package/dist/kit/spice/time.d.ts +1 -0
  180. package/dist/kit/spice/time.js +1 -0
  181. package/dist/kit/types/spice-types.d.ts +18 -1
  182. package/dist/spice.d.ts +10 -1
  183. package/dist/spice.js +41 -0
  184. package/dist/transport/caching/policy.d.ts +16 -0
  185. package/dist/transport/caching/policy.js +77 -0
  186. package/dist/transport/caching/withCaching.d.ts +125 -0
  187. package/dist/transport/caching/withCaching.js +335 -0
  188. package/dist/transport/caching/withCachingSync.d.ts +24 -0
  189. package/dist/transport/caching/withCachingSync.js +161 -0
  190. package/dist/transport/rpc/protocol.d.ts +35 -0
  191. package/dist/transport/rpc/protocol.js +56 -0
  192. package/dist/transport/rpc/taskScheduling.d.ts +20 -0
  193. package/dist/transport/rpc/taskScheduling.js +98 -0
  194. package/dist/transport/rpc/valueCodec.d.ts +5 -0
  195. package/dist/transport/rpc/valueCodec.js +106 -0
  196. package/dist/transport/types.d.ts +7 -0
  197. package/dist/transport/types.js +2 -0
  198. package/dist/types.d.ts +8 -5
  199. package/dist/types.js +2 -1
  200. package/dist/worker/browser/createSpiceWorker.d.ts +22 -0
  201. package/dist/worker/browser/createSpiceWorker.js +41 -0
  202. package/dist/worker/browser/createSpiceWorkerClient.d.ts +40 -0
  203. package/dist/worker/browser/createSpiceWorkerClient.js +99 -0
  204. package/dist/worker/browser/spiceWorkerEntry.d.ts +2 -0
  205. package/dist/worker/browser/spiceWorkerEntry.js +129 -0
  206. package/dist/worker/browser/spiceWorkerInlineSource.d.ts +2 -0
  207. package/dist/worker/browser/spiceWorkerInlineSource.js +4 -0
  208. package/dist/worker/index.d.ts +10 -0
  209. package/dist/worker/index.js +7 -0
  210. package/dist/worker/transport/createWorkerTransport.d.ts +69 -0
  211. package/dist/worker/transport/createWorkerTransport.js +398 -0
  212. package/dist/worker/transport/exposeTransportToWorker.d.ts +51 -0
  213. package/dist/worker/transport/exposeTransportToWorker.js +196 -0
  214. package/package.json +4 -4
@@ -0,0 +1,74 @@
1
+ import { assertSpiceInt32 } from "#backend-contract";
2
+ import { invariant } from "#core";
3
+ const UINT32_MAX = 0xffff_ffff;
4
+ // Opaque window handles are represented as branded numbers in the backend
5
+ // contract, but we still validate them at runtime to keep error behavior
6
+ // consistent across backends.
7
+ function assertOpaqueHandle(handle, context) {
8
+ if (typeof handle !== "number" || !Number.isFinite(handle) || !Number.isInteger(handle)) {
9
+ throw new TypeError(`${context}: expected handle to be an integer number (got ${handle})`);
10
+ }
11
+ if (handle <= 0) {
12
+ throw new RangeError(`${context}: expected handle to be > 0 (got ${handle})`);
13
+ }
14
+ if (!Number.isSafeInteger(handle) || handle > UINT32_MAX) {
15
+ throw new RangeError(`${context}: expected handle to be a non-zero uint32 (got ${handle})`);
16
+ }
17
+ }
18
+ function assertFiniteNumber(value, context) {
19
+ if (typeof value !== "number" || !Number.isFinite(value)) {
20
+ throw new RangeError(`${context}: expected a finite number (got ${value})`);
21
+ }
22
+ }
23
+ /** Create a {@link GeometryGfApi} implementation backed by the native Node addon. */
24
+ export function createGeometryGfApi(native) {
25
+ return {
26
+ gfsstp: (step) => {
27
+ assertFiniteNumber(step, "gfsstp(step)");
28
+ native.gfsstp(step);
29
+ },
30
+ gfstep: (time) => {
31
+ assertFiniteNumber(time, "gfstep(time)");
32
+ const out = native.gfstep(time);
33
+ invariant(typeof out === "number" && Number.isFinite(out), "Expected gfstep() to return a finite number");
34
+ return out;
35
+ },
36
+ gfstol: (value) => {
37
+ assertFiniteNumber(value, "gfstol(value)");
38
+ native.gfstol(value);
39
+ },
40
+ gfrefn: (t1, t2, s1, s2) => {
41
+ assertFiniteNumber(t1, "gfrefn(t1)");
42
+ assertFiniteNumber(t2, "gfrefn(t2)");
43
+ const out = native.gfrefn(t1, t2, s1, s2);
44
+ invariant(typeof out === "number" && Number.isFinite(out), "Expected gfrefn() to return a finite number");
45
+ return out;
46
+ },
47
+ gfrepi: (window, begmss, endmss) => {
48
+ assertOpaqueHandle(window, "gfrepi(window)");
49
+ native.gfrepi(window, begmss, endmss);
50
+ },
51
+ gfrepf: () => {
52
+ native.gfrepf();
53
+ },
54
+ gfsep: (targ1, shape1, frame1, targ2, shape2, frame2, abcorr, obsrvr, relate, refval, adjust, step, nintvls, cnfine, result) => {
55
+ assertSpiceInt32(nintvls, "gfsep(nintvls)", { min: 1 });
56
+ assertFiniteNumber(refval, "gfsep(refval)");
57
+ assertFiniteNumber(adjust, "gfsep(adjust)");
58
+ assertFiniteNumber(step, "gfsep(step)");
59
+ assertOpaqueHandle(cnfine, "gfsep(cnfine)");
60
+ assertOpaqueHandle(result, "gfsep(result)");
61
+ native.gfsep(targ1, shape1, frame1, targ2, shape2, frame2, abcorr, obsrvr, relate, refval, adjust, step, nintvls, cnfine, result);
62
+ },
63
+ gfdist: (target, abcorr, obsrvr, relate, refval, adjust, step, nintvls, cnfine, result) => {
64
+ assertSpiceInt32(nintvls, "gfdist(nintvls)", { min: 1 });
65
+ assertFiniteNumber(refval, "gfdist(refval)");
66
+ assertFiniteNumber(adjust, "gfdist(adjust)");
67
+ assertFiniteNumber(step, "gfdist(step)");
68
+ assertOpaqueHandle(cnfine, "gfdist(cnfine)");
69
+ assertOpaqueHandle(result, "gfdist(result)");
70
+ native.gfdist(target, abcorr, obsrvr, relate, refval, adjust, step, nintvls, cnfine, result);
71
+ },
72
+ };
73
+ }
74
+ //# sourceMappingURL=geometry-gf.js.map
@@ -1,4 +1,5 @@
1
1
  import type { GeometryApi } from "#backend-contract";
2
2
  import type { NativeAddon } from "../runtime/addon.js";
3
+ /** Create a {@link GeometryApi} implementation backed by the native Node addon. */
3
4
  export declare function createGeometryApi(native: NativeAddon): GeometryApi;
4
5
  //# sourceMappingURL=geometry.d.ts.map
@@ -1,4 +1,12 @@
1
1
  import { invariant } from "#core";
2
+ function assertFiniteNumberArrayFixed(value, expectedLength, label) {
3
+ invariant(Array.isArray(value) && value.length === expectedLength, `Expected ${label} to be a length-${expectedLength} array`);
4
+ for (let i = 0; i < expectedLength; i++) {
5
+ const v = value[i];
6
+ invariant(typeof v === "number" && Number.isFinite(v), `Expected ${label}[${i}] to be a finite number`);
7
+ }
8
+ }
9
+ /** Create a {@link GeometryApi} implementation backed by the native Node addon. */
2
10
  export function createGeometryApi(native) {
3
11
  return {
4
12
  subpnt: (method, target, et, fixref, abcorr, observer) => {
@@ -57,11 +65,65 @@ export function createGeometryApi(native) {
57
65
  emissn: out.emissn,
58
66
  };
59
67
  },
68
+ illumg: (method, target, ilusrc, et, fixref, abcorr, observer, spoint) => {
69
+ const out = native.illumg(method, target, ilusrc, et, fixref, abcorr, observer, spoint);
70
+ invariant(out && typeof out === "object", "Expected illumg() to return an object");
71
+ invariant(typeof out.trgepc === "number", "Expected illumg().trgepc to be a number");
72
+ invariant(Array.isArray(out.srfvec) && out.srfvec.length === 3, "Expected illumg().srfvec to be a length-3 array");
73
+ invariant(typeof out.phase === "number", "Expected illumg().phase to be a number");
74
+ invariant(typeof out.incdnc === "number", "Expected illumg().incdnc to be a number");
75
+ invariant(typeof out.emissn === "number", "Expected illumg().emissn to be a number");
76
+ return {
77
+ trgepc: out.trgepc,
78
+ srfvec: out.srfvec,
79
+ phase: out.phase,
80
+ incdnc: out.incdnc,
81
+ emissn: out.emissn,
82
+ };
83
+ },
84
+ illumf: (method, target, ilusrc, et, fixref, abcorr, observer, spoint) => {
85
+ const out = native.illumf(method, target, ilusrc, et, fixref, abcorr, observer, spoint);
86
+ invariant(out && typeof out === "object", "Expected illumf() to return an object");
87
+ invariant(typeof out.trgepc === "number", "Expected illumf().trgepc to be a number");
88
+ invariant(Array.isArray(out.srfvec) && out.srfvec.length === 3, "Expected illumf().srfvec to be a length-3 array");
89
+ invariant(typeof out.phase === "number", "Expected illumf().phase to be a number");
90
+ invariant(typeof out.incdnc === "number", "Expected illumf().incdnc to be a number");
91
+ invariant(typeof out.emissn === "number", "Expected illumf().emissn to be a number");
92
+ invariant(typeof out.visibl === "boolean", "Expected illumf().visibl to be a boolean");
93
+ invariant(typeof out.lit === "boolean", "Expected illumf().lit to be a boolean");
94
+ return {
95
+ trgepc: out.trgepc,
96
+ srfvec: out.srfvec,
97
+ phase: out.phase,
98
+ incdnc: out.incdnc,
99
+ emissn: out.emissn,
100
+ visibl: out.visibl,
101
+ lit: out.lit,
102
+ };
103
+ },
60
104
  occult: (targ1, shape1, frame1, targ2, shape2, frame2, abcorr, observer, et) => {
61
105
  const out = native.occult(targ1, shape1, frame1, targ2, shape2, frame2, abcorr, observer, et);
62
106
  invariant(typeof out === "number", "Expected occult() to return a number");
63
107
  return out;
64
108
  },
109
+ nvc2pl: (normal, konst) => {
110
+ assertFiniteNumberArrayFixed(normal, 3, "nvc2pl(): normal");
111
+ invariant(typeof konst === "number" && Number.isFinite(konst), "Expected nvc2pl(): konst to be a finite number");
112
+ const out = native.nvc2pl(normal, konst);
113
+ assertFiniteNumberArrayFixed(out, 4, "nvc2pl(): result");
114
+ return out;
115
+ },
116
+ pl2nvc: (plane) => {
117
+ assertFiniteNumberArrayFixed(plane, 4, "pl2nvc(): plane");
118
+ const out = native.pl2nvc(plane);
119
+ invariant(out && typeof out === "object", "Expected pl2nvc() to return an object");
120
+ assertFiniteNumberArrayFixed(out.normal, 3, "pl2nvc(): normal");
121
+ invariant(typeof out.konst === "number" && Number.isFinite(out.konst), "Expected pl2nvc().konst to be a finite number");
122
+ return {
123
+ normal: out.normal,
124
+ konst: out.konst,
125
+ };
126
+ },
65
127
  };
66
128
  }
67
129
  //# sourceMappingURL=geometry.js.map
@@ -1,4 +1,5 @@
1
- import type { IdsNamesApi } from "#backend-contract";
1
+ import { type IdsNamesApi } from "#backend-contract";
2
2
  import type { NativeAddon } from "../runtime/addon.js";
3
+ /** Create an {@link IdsNamesApi} implementation backed by the native Node addon. */
3
4
  export declare function createIdsNamesApi(native: NativeAddon): IdsNamesApi;
4
5
  //# sourceMappingURL=ids-names.d.ts.map
@@ -1,4 +1,6 @@
1
+ import {} from "#backend-contract";
1
2
  import { invariant } from "#core";
3
+ /** Create an {@link IdsNamesApi} implementation backed by the native Node addon. */
2
4
  export function createIdsNamesApi(native) {
3
5
  return {
4
6
  bodn2c: (name) => {
@@ -17,6 +19,34 @@ export function createIdsNamesApi(native) {
17
19
  invariant(typeof out.name === "string", "Expected bodc2n().name to be a string");
18
20
  return { found: true, name: out.name };
19
21
  },
22
+ bodc2s: (code) => {
23
+ const out = native.bodc2s(code);
24
+ invariant(typeof out === "string", "Expected bodc2s() to return a string");
25
+ return out;
26
+ },
27
+ bods2c: (name) => {
28
+ const out = native.bods2c(name);
29
+ if (!out.found) {
30
+ return { found: false };
31
+ }
32
+ invariant(typeof out.code === "number", "Expected bods2c().code to be a number");
33
+ return { found: true, code: out.code };
34
+ },
35
+ boddef: (name, code) => {
36
+ native.boddef(name, code);
37
+ },
38
+ bodfnd: (body, item) => {
39
+ // `item` normalization is handled by the native addon.
40
+ const out = native.bodfnd(body, item);
41
+ invariant(typeof out === "boolean", "Expected bodfnd() to return a boolean");
42
+ return out;
43
+ },
44
+ bodvar: (body, item) => {
45
+ // `item` normalization is handled by the native addon.
46
+ const out = native.bodvar(body, item);
47
+ invariant(Array.isArray(out), "Expected bodvar() to return an array");
48
+ return out;
49
+ },
20
50
  };
21
51
  }
22
52
  //# sourceMappingURL=ids-names.js.map
@@ -0,0 +1,5 @@
1
+ import type { KernelPoolApi } from "#backend-contract";
2
+ import type { NativeAddon } from "../runtime/addon.js";
3
+ /** Create a {@link KernelPoolApi} implementation backed by the native Node addon. */
4
+ export declare function createKernelPoolApi(native: NativeAddon): KernelPoolApi;
5
+ //# sourceMappingURL=kernel-pool.d.ts.map
@@ -0,0 +1,74 @@
1
+ import { invariant } from "#core";
2
+ /** Create a {@link KernelPoolApi} implementation backed by the native Node addon. */
3
+ export function createKernelPoolApi(native) {
4
+ return {
5
+ gdpool: (name, start, room) => {
6
+ const out = native.gdpool(name, start, room);
7
+ if (!out.found) {
8
+ return { found: false };
9
+ }
10
+ invariant(Array.isArray(out.values), "Expected gdpool().values to be an array");
11
+ return { found: true, values: out.values };
12
+ },
13
+ gipool: (name, start, room) => {
14
+ const out = native.gipool(name, start, room);
15
+ if (!out.found) {
16
+ return { found: false };
17
+ }
18
+ invariant(Array.isArray(out.values), "Expected gipool().values to be an array");
19
+ return { found: true, values: out.values };
20
+ },
21
+ gcpool: (name, start, room) => {
22
+ const out = native.gcpool(name, start, room);
23
+ if (!out.found) {
24
+ return { found: false };
25
+ }
26
+ invariant(Array.isArray(out.values), "Expected gcpool().values to be an array");
27
+ return { found: true, values: out.values };
28
+ },
29
+ gnpool: (template, start, room) => {
30
+ const out = native.gnpool(template, start, room);
31
+ if (!out.found) {
32
+ return { found: false };
33
+ }
34
+ invariant(Array.isArray(out.values), "Expected gnpool().values to be an array");
35
+ return { found: true, values: out.values };
36
+ },
37
+ dtpool: (name) => {
38
+ const out = native.dtpool(name);
39
+ if (!out.found) {
40
+ return { found: false };
41
+ }
42
+ invariant(typeof out.n === "number", "Expected dtpool().n to be a number");
43
+ invariant(typeof out.type === "string", "Expected dtpool().type to be a string");
44
+ const t = out.type.trim();
45
+ if (t !== "C" && t !== "N") {
46
+ throw new Error(`dtpool(): unexpected type '${t}' for ${name}`);
47
+ }
48
+ return { found: true, n: out.n, type: t };
49
+ },
50
+ pdpool: (name, values) => {
51
+ native.pdpool(name, values);
52
+ },
53
+ pipool: (name, values) => {
54
+ native.pipool(name, values);
55
+ },
56
+ pcpool: (name, values) => {
57
+ native.pcpool(name, values);
58
+ },
59
+ swpool: (agent, names) => {
60
+ native.swpool(agent, names);
61
+ },
62
+ cvpool: (agent) => {
63
+ const out = native.cvpool(agent);
64
+ invariant(typeof out === "boolean", "Expected cvpool() to return a boolean");
65
+ return out;
66
+ },
67
+ expool: (name) => {
68
+ const out = native.expool(name);
69
+ invariant(typeof out === "boolean", "Expected expool() to return a boolean");
70
+ return out;
71
+ },
72
+ };
73
+ }
74
+ //# sourceMappingURL=kernel-pool.js.map
@@ -1,5 +1,6 @@
1
1
  import type { KernelsApi } from "#backend-contract";
2
2
  import type { NativeAddon } from "../runtime/addon.js";
3
3
  import type { KernelStager } from "../runtime/kernel-staging.js";
4
+ /** Create a {@link KernelsApi} implementation backed by the native Node addon + kernel staging. */
4
5
  export declare function createKernelsApi(native: NativeAddon, stager: KernelStager): KernelsApi;
5
6
  //# sourceMappingURL=kernels.d.ts.map
@@ -1,5 +1,27 @@
1
+ import { matchesKernelKind, nativeKindQueryOrNull, normalizeKindInput, } from "#backend-contract";
1
2
  import { invariant } from "#core";
3
+ /** Create a {@link KernelsApi} implementation backed by the native Node addon + kernel staging. */
2
4
  export function createKernelsApi(native, stager) {
5
+ const kernelKindProbeFromNative = (result) => {
6
+ invariant(typeof result.file === "string", "Expected kdata().file to be a string");
7
+ invariant(typeof result.filtyp === "string", "Expected kdata().filtyp to be a string");
8
+ return {
9
+ file: stager.virtualizePathFromSpice(result.file),
10
+ filtyp: result.filtyp,
11
+ };
12
+ };
13
+ const kernelDataFromNative = (result) => {
14
+ invariant(typeof result.file === "string", "Expected kdata().file to be a string");
15
+ invariant(typeof result.filtyp === "string", "Expected kdata().filtyp to be a string");
16
+ invariant(typeof result.source === "string", "Expected kdata().source to be a string");
17
+ invariant(typeof result.handle === "number", "Expected kdata().handle to be a number");
18
+ return {
19
+ file: stager.virtualizePathFromSpice(result.file),
20
+ filtyp: result.filtyp,
21
+ source: stager.virtualizePathFromSpice(result.source),
22
+ handle: result.handle,
23
+ };
24
+ };
3
25
  return {
4
26
  furnsh: (kernel) => {
5
27
  stager.furnsh(kernel, native);
@@ -10,28 +32,93 @@ export function createKernelsApi(native, stager) {
10
32
  kclear: () => {
11
33
  stager.kclear(native);
12
34
  },
13
- ktotal: (kind = "ALL") => {
14
- const total = native.ktotal(kind);
15
- invariant(typeof total === "number", "Expected native backend ktotal() to return a number");
16
- return total;
17
- },
18
- kdata: (which, kind = "ALL") => {
19
- const result = native.kdata(which, kind);
35
+ kinfo: (path) => {
36
+ const resolved = stager.resolvePathForSpice(path);
37
+ const result = native.kinfo(resolved);
20
38
  if (!result.found) {
21
39
  return { found: false };
22
40
  }
23
- invariant(typeof result.file === "string", "Expected kdata().file to be a string");
24
- invariant(typeof result.filtyp === "string", "Expected kdata().filtyp to be a string");
25
- invariant(typeof result.source === "string", "Expected kdata().source to be a string");
26
- invariant(typeof result.handle === "number", "Expected kdata().handle to be a number");
41
+ invariant(typeof result.filtyp === "string", "Expected kinfo().filtyp to be a string");
42
+ invariant(typeof result.source === "string", "Expected kinfo().source to be a string");
43
+ invariant(typeof result.handle === "number", "Expected kinfo().handle to be a number");
27
44
  return {
28
45
  found: true,
29
- file: result.file,
30
46
  filtyp: result.filtyp,
31
- source: result.source,
47
+ source: stager.virtualizePathFromSpice(result.source),
32
48
  handle: result.handle,
33
49
  };
34
50
  },
51
+ kxtrct: (keywd, terms, wordsq) => {
52
+ const result = native.kxtrct(keywd, terms, wordsq);
53
+ if (!result.found) {
54
+ return { found: false };
55
+ }
56
+ invariant(typeof result.wordsq === "string", "Expected kxtrct().wordsq to be a string");
57
+ invariant(typeof result.substr === "string", "Expected kxtrct().substr to be a string");
58
+ return { found: true, wordsq: result.wordsq, substr: result.substr };
59
+ },
60
+ kplfrm: (frmcls, idset) => {
61
+ native.kplfrm(frmcls, idset);
62
+ },
63
+ ktotal: (kind = "ALL") => {
64
+ const kinds = normalizeKindInput(kind);
65
+ const nativeQuery = nativeKindQueryOrNull(kinds);
66
+ if (nativeQuery != null) {
67
+ const total = native.ktotal(nativeQuery);
68
+ invariant(typeof total === "number", "Expected native backend ktotal() to return a number");
69
+ return total;
70
+ }
71
+ const requested = new Set(kinds);
72
+ const totalAll = native.ktotal("ALL");
73
+ invariant(typeof totalAll === "number", "Expected native backend ktotal() to return a number");
74
+ let count = 0;
75
+ for (let i = 0; i < totalAll; i++) {
76
+ const result = native.kdata(i, "ALL");
77
+ if (!result.found) {
78
+ continue;
79
+ }
80
+ const probe = kernelKindProbeFromNative(result);
81
+ if (matchesKernelKind(requested, probe)) {
82
+ count++;
83
+ }
84
+ }
85
+ return count;
86
+ },
87
+ kdata: (which, kind = "ALL") => {
88
+ if (which < 0) {
89
+ return { found: false };
90
+ }
91
+ const kinds = normalizeKindInput(kind);
92
+ const nativeQuery = nativeKindQueryOrNull(kinds);
93
+ if (nativeQuery != null) {
94
+ const result = native.kdata(which, nativeQuery);
95
+ if (!result.found) {
96
+ return { found: false };
97
+ }
98
+ const kernel = kernelDataFromNative(result);
99
+ return { found: true, ...kernel };
100
+ }
101
+ const requested = new Set(kinds);
102
+ const totalAll = native.ktotal("ALL");
103
+ invariant(typeof totalAll === "number", "Expected native backend ktotal() to return a number");
104
+ let matchIndex = 0;
105
+ for (let i = 0; i < totalAll; i++) {
106
+ const result = native.kdata(i, "ALL");
107
+ if (!result.found) {
108
+ continue;
109
+ }
110
+ const probe = kernelKindProbeFromNative(result);
111
+ if (!matchesKernelKind(requested, probe)) {
112
+ continue;
113
+ }
114
+ if (matchIndex === which) {
115
+ const kernel = kernelDataFromNative(result);
116
+ return { found: true, ...kernel };
117
+ }
118
+ matchIndex++;
119
+ }
120
+ return { found: false };
121
+ },
35
122
  };
36
123
  }
37
124
  //# sourceMappingURL=kernels.js.map
@@ -1,4 +1,5 @@
1
1
  import type { TimeApi } from "#backend-contract";
2
2
  import type { NativeAddon } from "../runtime/addon.js";
3
+ /** Create a {@link TimeApi} implementation backed by the native Node addon. */
3
4
  export declare function createTimeApi(native: NativeAddon): TimeApi;
4
5
  //# sourceMappingURL=time.d.ts.map
@@ -1,5 +1,28 @@
1
- import { invariant } from "#core";
1
+ import { assertNever, invariant } from "#core";
2
+ /** Create a {@link TimeApi} implementation backed by the native Node addon. */
2
3
  export function createTimeApi(native) {
4
+ function timdef(action, item, value) {
5
+ if (item.length === 0) {
6
+ throw new RangeError("timdef(): item must be a non-empty string");
7
+ }
8
+ switch (action) {
9
+ case "GET": {
10
+ const out = native.timdefGet(item);
11
+ invariant(typeof out === "string", "Expected timdef(GET) to return a string");
12
+ return out;
13
+ }
14
+ case "SET": {
15
+ invariant(typeof value === "string", "timdef(SET) requires a string value");
16
+ if (value.length === 0) {
17
+ throw new RangeError("timdef(SET)(): value must be a non-empty string");
18
+ }
19
+ native.timdefSet(item, value);
20
+ return;
21
+ }
22
+ default:
23
+ return assertNever(action, "Unsupported timdef action");
24
+ }
25
+ }
3
26
  return {
4
27
  spiceVersion: () => {
5
28
  const version = native.spiceVersion();
@@ -21,6 +44,37 @@ export function createTimeApi(native) {
21
44
  timout: (et, picture) => {
22
45
  return native.timout(et, picture);
23
46
  },
47
+ deltet: (epoch, eptype) => {
48
+ invariant(eptype === "ET" || eptype === "UTC", `Unsupported deltet eptype: ${eptype}`);
49
+ const delta = native.deltet(epoch, eptype);
50
+ invariant(typeof delta === "number", "Expected deltet() to return a number");
51
+ return delta;
52
+ },
53
+ unitim: (epoch, insys, outsys) => {
54
+ const out = native.unitim(epoch, insys, outsys);
55
+ invariant(typeof out === "number", "Expected unitim() to return a number");
56
+ return out;
57
+ },
58
+ tparse: (timstr) => {
59
+ if (timstr.length === 0) {
60
+ throw new RangeError("tparse(): timstr must be a non-empty string");
61
+ }
62
+ const et = native.tparse(timstr);
63
+ invariant(typeof et === "number", "Expected tparse() to return a number");
64
+ return et;
65
+ },
66
+ tpictr: (sample, pictur) => {
67
+ if (sample.length === 0) {
68
+ throw new RangeError("tpictr(): sample must be a non-empty string");
69
+ }
70
+ if (pictur.length === 0) {
71
+ throw new RangeError("tpictr(): pictur must be a non-empty string");
72
+ }
73
+ const out = native.tpictr(sample, pictur);
74
+ invariant(typeof out === "string", "Expected tpictr() to return a string");
75
+ return out;
76
+ },
77
+ timdef,
24
78
  scs2e: (sc, sclkch) => {
25
79
  const et = native.scs2e(sc, sclkch);
26
80
  invariant(typeof et === "number", "Expected scs2e() to return a number");
@@ -31,6 +85,26 @@ export function createTimeApi(native) {
31
85
  invariant(typeof out === "string", "Expected sce2s() to return a string");
32
86
  return out;
33
87
  },
88
+ scencd: (sc, sclkch) => {
89
+ const out = native.scencd(sc, sclkch);
90
+ invariant(typeof out === "number", "Expected scencd() to return a number");
91
+ return out;
92
+ },
93
+ scdecd: (sc, sclkdp) => {
94
+ const out = native.scdecd(sc, sclkdp);
95
+ invariant(typeof out === "string", "Expected scdecd() to return a string");
96
+ return out;
97
+ },
98
+ sct2e: (sc, sclkdp) => {
99
+ const out = native.sct2e(sc, sclkdp);
100
+ invariant(typeof out === "number", "Expected sct2e() to return a number");
101
+ return out;
102
+ },
103
+ sce2c: (sc, et) => {
104
+ const out = native.sce2c(sc, et);
105
+ invariant(typeof out === "number", "Expected sce2c() to return a number");
106
+ return out;
107
+ },
34
108
  };
35
109
  }
36
110
  //# sourceMappingURL=time.js.map
@@ -1,5 +1,7 @@
1
1
  import type { SpiceBackend } from "#backend-contract";
2
+ /** Return the SPICE toolkit version exposed by the native Node addon. */
2
3
  export declare function spiceVersion(): string;
4
+ /** Create a {@link SpiceBackend} implementation backed by the native Node addon. */
3
5
  export declare function createNodeBackend(): SpiceBackend & {
4
6
  kind: "node";
5
7
  };
@@ -2,33 +2,94 @@ import { invariant } from "#core";
2
2
  import { getNativeAddon } from "./native.js";
3
3
  import { getNodeBinding } from "./lowlevel/binding.js";
4
4
  import { createKernelStager } from "./runtime/kernel-staging.js";
5
+ import { createVirtualOutputStager } from "./runtime/virtual-output-staging.js";
6
+ import { createSpiceHandleRegistry } from "./runtime/spice-handles.js";
5
7
  import { createCoordsVectorsApi } from "./domains/coords-vectors.js";
6
8
  import { createEphemerisApi } from "./domains/ephemeris.js";
7
9
  import { createFramesApi } from "./domains/frames.js";
8
10
  import { createGeometryApi } from "./domains/geometry.js";
11
+ import { createGeometryGfApi } from "./domains/geometry-gf.js";
9
12
  import { createIdsNamesApi } from "./domains/ids-names.js";
10
13
  import { createKernelsApi } from "./domains/kernels.js";
14
+ import { createKernelPoolApi } from "./domains/kernel-pool.js";
11
15
  import { createTimeApi } from "./domains/time.js";
16
+ import { createFileIoApi } from "./domains/file-io.js";
17
+ import { createErrorApi } from "./domains/error.js";
18
+ import { createCellsWindowsApi } from "./domains/cells-windows.js";
19
+ import { createDskApi } from "./domains/dsk.js";
20
+ import { createEkApi } from "./domains/ek.js";
21
+ /** Return the SPICE toolkit version exposed by the native Node addon. */
12
22
  export function spiceVersion() {
13
23
  const version = getNativeAddon().spiceVersion();
14
24
  invariant(typeof version === "string", "Expected native backend spiceVersion() to return a string");
15
25
  return version;
16
26
  }
27
+ /** Create a {@link SpiceBackend} implementation backed by the native Node addon. */
17
28
  export function createNodeBackend() {
18
29
  const native = getNodeBinding();
19
30
  const stager = createKernelStager();
31
+ const spiceHandles = createSpiceHandleRegistry();
32
+ const outputs = createVirtualOutputStager();
20
33
  const backend = {
21
34
  kind: "node",
22
35
  ...createTimeApi(native),
23
36
  ...createKernelsApi(native, stager),
37
+ ...createKernelPoolApi(native),
24
38
  ...createIdsNamesApi(native),
25
39
  ...createFramesApi(native),
26
- ...createEphemerisApi(native),
40
+ ...createEphemerisApi(native, spiceHandles, stager, outputs),
27
41
  ...createGeometryApi(native),
42
+ ...createGeometryGfApi(native),
28
43
  ...createCoordsVectorsApi(native),
44
+ ...createFileIoApi(native, spiceHandles, outputs),
45
+ ...createErrorApi(native),
46
+ ...createCellsWindowsApi(native),
47
+ ...createEkApi(native, spiceHandles, stager),
48
+ ...createDskApi(native, spiceHandles),
29
49
  };
30
50
  // Internal testing hook (not part of the public backend contract).
31
51
  backend.__ktotalAll = () => native.__ktotalAll();
52
+ // Internal best-effort cleanup hook (not part of the public backend contract).
53
+ // Closes all currently-registered DAF/DAS/DLA/EK/SPK handles and throws an AggregateError if any closes fail.
54
+ Object.defineProperty(backend, "disposeAll", {
55
+ value: () => {
56
+ const errors = [];
57
+ const entries = spiceHandles.__entries?.() ?? [];
58
+ for (const [handle, entry] of entries) {
59
+ try {
60
+ if (entry.kind === "SPK") {
61
+ // Ensure VirtualOutputStager bookkeeping stays consistent.
62
+ backend.spkcls(handle);
63
+ continue;
64
+ }
65
+ if (entry.kind === "DAF") {
66
+ spiceHandles.close(handle, ["DAF"], (e) => native.dafcls(e.nativeHandle), "disposeAll:dafcls");
67
+ }
68
+ else if (entry.kind === "EK") {
69
+ spiceHandles.close(handle, ["EK"], (e) => native.ekcls(e.nativeHandle), "disposeAll:ekcls");
70
+ }
71
+ else {
72
+ // In CSPICE, dascls_c closes both DAS and DLA handles (dlacls_c is an alias).
73
+ spiceHandles.close(handle, ["DAS", "DLA"], (e) => native.dascls(e.nativeHandle), "disposeAll:dascls");
74
+ }
75
+ }
76
+ catch (err) {
77
+ errors.push(err);
78
+ }
79
+ }
80
+ // Best-effort cleanup for any staged virtual outputs.
81
+ try {
82
+ outputs.dispose();
83
+ }
84
+ catch (err) {
85
+ errors.push(err);
86
+ }
87
+ if (errors.length > 0) {
88
+ throw new AggregateError(errors, `disposeAll(): failed to close ${errors.length} handle(s)`);
89
+ }
90
+ },
91
+ enumerable: false,
92
+ });
32
93
  return backend;
33
94
  }
34
95
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,6 @@
1
1
  import type { NativeAddon } from "../runtime/addon.js";
2
+ /**
3
+ * Get the loaded native addon binding and assert it provides the expected entrypoints.
4
+ */
2
5
  export declare function getNodeBinding(): NativeAddon;
3
6
  //# sourceMappingURL=binding.d.ts.map