@rybosome/tspice 0.0.3 → 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 (221) hide show
  1. package/README.md +145 -84
  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 +53 -3
  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 +44 -4
  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 +34 -15
  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 +52 -0
  33. package/backend-contract/dist/shared/mat3.js +150 -0
  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 +136 -5
  41. package/backend-contract/dist/shared/types.js +1 -1
  42. package/backend-contract/dist/shared/vec.d.ts +54 -0
  43. package/backend-contract/dist/shared/vec.js +162 -0
  44. package/backend-fake/dist/.tsbuildinfo +1 -1
  45. package/backend-fake/dist/index.d.ts +21 -1
  46. package/backend-fake/dist/index.js +1112 -33
  47. package/backend-node/dist/.tsbuildinfo +1 -1
  48. package/backend-node/dist/codec/arrays.d.ts +9 -0
  49. package/backend-node/dist/codec/arrays.js +36 -0
  50. package/backend-node/dist/codec/errors.d.ts +6 -6
  51. package/backend-node/dist/codec/errors.js +6 -6
  52. package/backend-node/dist/domains/cells-windows.d.ts +5 -0
  53. package/backend-node/dist/domains/cells-windows.js +112 -0
  54. package/backend-node/dist/domains/coords-vectors.d.ts +1 -0
  55. package/backend-node/dist/domains/coords-vectors.js +66 -0
  56. package/backend-node/dist/domains/dsk.d.ts +6 -0
  57. package/backend-node/dist/domains/dsk.js +108 -0
  58. package/backend-node/dist/domains/ek.d.ts +10 -0
  59. package/backend-node/dist/domains/ek.js +100 -0
  60. package/backend-node/dist/domains/ephemeris.d.ts +5 -1
  61. package/backend-node/dist/domains/ephemeris.js +150 -1
  62. package/backend-node/dist/domains/error.d.ts +5 -0
  63. package/backend-node/dist/domains/error.js +34 -0
  64. package/backend-node/dist/domains/file-io.d.ts +7 -0
  65. package/backend-node/dist/domains/file-io.js +105 -0
  66. package/backend-node/dist/domains/frames.d.ts +1 -0
  67. package/backend-node/dist/domains/frames.js +58 -6
  68. package/backend-node/dist/domains/geometry-gf.d.ts +5 -0
  69. package/backend-node/dist/domains/geometry-gf.js +74 -0
  70. package/backend-node/dist/domains/geometry.d.ts +1 -0
  71. package/backend-node/dist/domains/geometry.js +62 -0
  72. package/backend-node/dist/domains/ids-names.d.ts +2 -1
  73. package/backend-node/dist/domains/ids-names.js +30 -0
  74. package/backend-node/dist/domains/kernel-pool.d.ts +5 -0
  75. package/backend-node/dist/domains/kernel-pool.js +74 -0
  76. package/backend-node/dist/domains/kernels.d.ts +1 -0
  77. package/backend-node/dist/domains/kernels.js +100 -13
  78. package/backend-node/dist/domains/time.d.ts +1 -0
  79. package/backend-node/dist/domains/time.js +75 -1
  80. package/backend-node/dist/index.d.ts +5 -1
  81. package/backend-node/dist/index.js +62 -1
  82. package/backend-node/dist/lowlevel/binding.d.ts +3 -0
  83. package/backend-node/dist/lowlevel/binding.js +115 -0
  84. package/backend-node/dist/runtime/addon.d.ts +273 -2
  85. package/backend-node/dist/runtime/addon.js +3 -0
  86. package/backend-node/dist/runtime/kernel-staging.d.ts +17 -0
  87. package/backend-node/dist/runtime/kernel-staging.js +80 -7
  88. package/backend-node/dist/runtime/spice-handles.d.ts +3 -0
  89. package/backend-node/dist/runtime/spice-handles.js +2 -0
  90. package/backend-node/dist/runtime/virtual-output-staging.d.ts +16 -0
  91. package/backend-node/dist/runtime/virtual-output-staging.js +148 -0
  92. package/backend-wasm/dist/.tsbuildinfo +1 -1
  93. package/backend-wasm/dist/codec/alloc.d.ts +19 -0
  94. package/backend-wasm/dist/codec/alloc.js +64 -0
  95. package/backend-wasm/dist/codec/calls.d.ts +2 -0
  96. package/backend-wasm/dist/codec/calls.js +13 -24
  97. package/backend-wasm/dist/codec/errors.d.ts +6 -0
  98. package/backend-wasm/dist/codec/errors.js +34 -2
  99. package/backend-wasm/dist/codec/found.d.ts +2 -0
  100. package/backend-wasm/dist/codec/found.js +20 -43
  101. package/backend-wasm/dist/codec/strings.d.ts +31 -1
  102. package/backend-wasm/dist/codec/strings.js +93 -6
  103. package/backend-wasm/dist/domains/cells-windows.d.ts +9 -0
  104. package/backend-wasm/dist/domains/cells-windows.js +392 -0
  105. package/backend-wasm/dist/domains/coords-vectors.d.ts +1 -0
  106. package/backend-wasm/dist/domains/coords-vectors.js +377 -184
  107. package/backend-wasm/dist/domains/dsk.d.ts +6 -0
  108. package/backend-wasm/dist/domains/dsk.js +179 -0
  109. package/backend-wasm/dist/domains/ek.d.ts +6 -0
  110. package/backend-wasm/dist/domains/ek.js +543 -0
  111. package/backend-wasm/dist/domains/ephemeris.d.ts +4 -1
  112. package/backend-wasm/dist/domains/ephemeris.js +405 -46
  113. package/backend-wasm/dist/domains/error.d.ts +5 -0
  114. package/backend-wasm/dist/domains/error.js +109 -0
  115. package/backend-wasm/dist/domains/file-io.d.ts +7 -0
  116. package/backend-wasm/dist/domains/file-io.js +462 -0
  117. package/backend-wasm/dist/domains/frames.d.ts +1 -0
  118. package/backend-wasm/dist/domains/frames.js +139 -6
  119. package/backend-wasm/dist/domains/geometry-gf.d.ts +5 -0
  120. package/backend-wasm/dist/domains/geometry-gf.js +178 -0
  121. package/backend-wasm/dist/domains/geometry.d.ts +1 -0
  122. package/backend-wasm/dist/domains/geometry.js +210 -0
  123. package/backend-wasm/dist/domains/ids-names.d.ts +2 -1
  124. package/backend-wasm/dist/domains/ids-names.js +89 -0
  125. package/backend-wasm/dist/domains/kernel-pool.d.ts +5 -0
  126. package/backend-wasm/dist/domains/kernel-pool.js +357 -0
  127. package/backend-wasm/dist/domains/kernels.d.ts +1 -0
  128. package/backend-wasm/dist/domains/kernels.js +108 -4
  129. package/backend-wasm/dist/domains/time.d.ts +2 -0
  130. package/backend-wasm/dist/domains/time.js +235 -133
  131. package/backend-wasm/dist/index.d.ts +4 -2
  132. package/backend-wasm/dist/lowlevel/exports.d.ts +215 -1
  133. package/backend-wasm/dist/lowlevel/exports.js +217 -38
  134. package/backend-wasm/dist/runtime/create-backend-options.d.ts +21 -0
  135. package/backend-wasm/dist/runtime/create-backend.node.d.ts +11 -2
  136. package/backend-wasm/dist/runtime/create-backend.node.js +283 -14
  137. package/backend-wasm/dist/runtime/create-backend.web.d.ts +5 -2
  138. package/backend-wasm/dist/runtime/create-backend.web.js +40 -6
  139. package/backend-wasm/dist/runtime/fs.d.ts +6 -0
  140. package/backend-wasm/dist/runtime/fs.js +29 -3
  141. package/backend-wasm/dist/runtime/spice-handles.d.ts +3 -0
  142. package/backend-wasm/dist/runtime/spice-handles.js +2 -0
  143. package/backend-wasm/dist/runtime/virtual-outputs.d.ts +16 -0
  144. package/backend-wasm/dist/runtime/virtual-outputs.js +35 -0
  145. package/backend-wasm/dist/tspice_backend_wasm.node.js +3 -3
  146. package/backend-wasm/dist/tspice_backend_wasm.wasm +0 -0
  147. package/backend-wasm/dist/tspice_backend_wasm.web.js +1 -1
  148. package/core/dist/.tsbuildinfo +1 -1
  149. package/core/dist/index.d.ts +21 -0
  150. package/core/dist/index.js +57 -0
  151. package/dist/.tsbuildinfo +1 -1
  152. package/dist/backend.d.ts +15 -6
  153. package/dist/backend.js +3 -6
  154. package/dist/clients/createSpiceAsyncFromTransport.d.ts +5 -0
  155. package/dist/clients/createSpiceAsyncFromTransport.js +90 -0
  156. package/dist/clients/createSpiceSyncFromTransport.d.ts +5 -0
  157. package/dist/clients/createSpiceSyncFromTransport.js +88 -0
  158. package/dist/clients/spiceClients.d.ts +59 -0
  159. package/dist/clients/spiceClients.js +292 -0
  160. package/dist/errors.d.ts +4 -0
  161. package/dist/errors.js +4 -0
  162. package/dist/index.d.ts +12 -7
  163. package/dist/index.js +5 -2
  164. package/dist/kernels/defaultKernelPathFromUrl.d.ts +8 -0
  165. package/dist/kernels/defaultKernelPathFromUrl.js +32 -0
  166. package/dist/kernels/kernelPack.d.ts +88 -0
  167. package/dist/kernels/kernelPack.js +122 -0
  168. package/dist/kernels/kernels.d.ts +98 -0
  169. package/dist/kernels/kernels.js +217 -0
  170. package/dist/kernels/naifKernelId.d.ts +2 -0
  171. package/dist/kernels/naifKernelId.js +2 -0
  172. package/dist/kit/index.d.ts +4 -0
  173. package/dist/kit/index.js +3 -0
  174. package/dist/kit/math/mat3.d.ts +31 -0
  175. package/dist/kit/math/mat3.js +82 -0
  176. package/dist/kit/spice/create-kit.d.ts +12 -0
  177. package/dist/kit/spice/create-kit.js +23 -0
  178. package/dist/kit/spice/frames.d.ts +8 -0
  179. package/dist/kit/spice/frames.js +16 -0
  180. package/dist/kit/spice/kernels.d.ts +14 -0
  181. package/dist/kit/spice/kernels.js +39 -0
  182. package/dist/kit/spice/state.d.ts +7 -0
  183. package/dist/kit/spice/state.js +36 -0
  184. package/dist/kit/spice/time.d.ts +9 -0
  185. package/dist/kit/spice/time.js +31 -0
  186. package/dist/kit/types/spice-types.d.ts +51 -0
  187. package/dist/spice.d.ts +10 -1
  188. package/dist/spice.js +84 -72
  189. package/dist/transport/caching/policy.d.ts +16 -0
  190. package/dist/transport/caching/policy.js +77 -0
  191. package/dist/transport/caching/withCaching.d.ts +125 -0
  192. package/dist/transport/caching/withCaching.js +335 -0
  193. package/dist/transport/caching/withCachingSync.d.ts +24 -0
  194. package/dist/transport/caching/withCachingSync.js +161 -0
  195. package/dist/transport/rpc/protocol.d.ts +35 -0
  196. package/dist/transport/rpc/protocol.js +56 -0
  197. package/dist/transport/rpc/taskScheduling.d.ts +20 -0
  198. package/dist/transport/rpc/taskScheduling.js +98 -0
  199. package/dist/transport/rpc/valueCodec.d.ts +5 -0
  200. package/dist/transport/rpc/valueCodec.js +106 -0
  201. package/dist/transport/types.d.ts +7 -0
  202. package/dist/transport/types.js +2 -0
  203. package/dist/types.d.ts +8 -17
  204. package/dist/types.js +2 -1
  205. package/dist/worker/browser/createSpiceWorker.d.ts +22 -0
  206. package/dist/worker/browser/createSpiceWorker.js +41 -0
  207. package/dist/worker/browser/createSpiceWorkerClient.d.ts +40 -0
  208. package/dist/worker/browser/createSpiceWorkerClient.js +99 -0
  209. package/dist/worker/browser/spiceWorkerEntry.d.ts +2 -0
  210. package/dist/worker/browser/spiceWorkerEntry.js +129 -0
  211. package/dist/worker/browser/spiceWorkerInlineSource.d.ts +2 -0
  212. package/dist/worker/browser/spiceWorkerInlineSource.js +4 -0
  213. package/dist/worker/index.d.ts +10 -0
  214. package/dist/worker/index.js +7 -0
  215. package/dist/worker/transport/createWorkerTransport.d.ts +69 -0
  216. package/dist/worker/transport/createWorkerTransport.js +398 -0
  217. package/dist/worker/transport/exposeTransportToWorker.d.ts +51 -0
  218. package/dist/worker/transport/exposeTransportToWorker.js +196 -0
  219. package/package.json +4 -4
  220. package/dist/spice-types.d.ts +0 -36
  221. /package/dist/{spice-types.js → kit/types/spice-types.js} +0 -0
@@ -1,166 +1,222 @@
1
+ import { assertNever } from "#core";
2
+ import { WASM_ERR_MAX_BYTES, withAllocs, withMalloc } from "../codec/alloc.js";
1
3
  import { throwWasmSpiceError } from "../codec/errors.js";
2
- import { writeUtf8CString } from "../codec/strings.js";
3
- function tspiceCallStr2et(module, utc) {
4
- const errMaxBytes = 2048;
5
- const errPtr = module._malloc(errMaxBytes);
6
- const utcPtr = writeUtf8CString(module, utc);
7
- const outEtPtr = module._malloc(8);
8
- if (!errPtr || !utcPtr || !outEtPtr) {
9
- for (const ptr of [outEtPtr, utcPtr, errPtr]) {
10
- if (ptr)
11
- module._free(ptr);
12
- }
13
- throw new Error("WASM malloc failed");
14
- }
4
+ import { readFixedWidthCString, writeUtf8CString } from "../codec/strings.js";
5
+ /**
6
+ * Max byte size for string outputs from CSPICE time calls (`et2utc_c`, `timout_c`).
7
+ *
8
+ * This intentionally differs from `WASM_ERR_MAX_BYTES`:
9
+ * - time formatting outputs can be much larger than error messages (esp. with long TIMOUT pictures)
10
+ * - we want a stable, explicit cap for output allocations
11
+ */
12
+ const WASM_TIME_OUT_MAX_BYTES = 16 * 1024; // 16 KiB
13
+ const WASM_TIME_SMALL_OUT_MAX_BYTES = 2048;
14
+ /** Max byte size for SCLK string outputs (sce2s/scdecd). */
15
+ const WASM_SCLK_OUT_MAX_BYTES = 2048;
16
+ function withUtf8CString(module, value, fn) {
17
+ const ptr = writeUtf8CString(module, value);
15
18
  try {
16
- module.HEAPF64[outEtPtr >> 3] = 0;
17
- const result = module._tspice_str2et(utcPtr, outEtPtr, errPtr, errMaxBytes);
18
- if (result !== 0) {
19
- throwWasmSpiceError(module, errPtr, errMaxBytes, result);
20
- }
21
- return module.HEAPF64[outEtPtr >> 3] ?? 0;
19
+ return fn(ptr);
22
20
  }
23
21
  finally {
24
- module._free(outEtPtr);
25
- module._free(utcPtr);
26
- module._free(errPtr);
22
+ module._free(ptr);
27
23
  }
28
24
  }
25
+ function tspiceCallStr2et(module, utc) {
26
+ return withUtf8CString(module, utc, (utcPtr) => {
27
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 8], (errPtr, outEtPtr) => {
28
+ module.HEAPF64[outEtPtr >> 3] = 0;
29
+ const result = module._tspice_str2et(utcPtr, outEtPtr, errPtr, WASM_ERR_MAX_BYTES);
30
+ if (result !== 0) {
31
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
32
+ }
33
+ return module.HEAPF64[outEtPtr >> 3] ?? 0;
34
+ });
35
+ });
36
+ }
29
37
  function tspiceCallEt2utc(module, et, format, prec) {
30
- const errMaxBytes = 2048;
31
- const errPtr = module._malloc(errMaxBytes);
32
- const formatPtr = writeUtf8CString(module, format);
33
- // Buffer size includes terminating NUL.
34
- const outMaxBytes = 2048;
35
- const outPtr = module._malloc(outMaxBytes);
36
- if (!errPtr || !formatPtr || !outPtr) {
37
- for (const ptr of [outPtr, formatPtr, errPtr]) {
38
- if (ptr)
39
- module._free(ptr);
40
- }
41
- throw new Error("WASM malloc failed");
42
- }
43
- try {
38
+ const outMaxBytes = WASM_TIME_OUT_MAX_BYTES;
39
+ return withUtf8CString(module, format, (formatPtr) => {
40
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, outMaxBytes], (errPtr, outPtr) => {
41
+ module.HEAPU8[outPtr] = 0;
42
+ const result = module._tspice_et2utc(et, formatPtr, prec, outPtr, outMaxBytes, errPtr, WASM_ERR_MAX_BYTES);
43
+ if (result !== 0) {
44
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
45
+ }
46
+ return readFixedWidthCString(module, outPtr, outMaxBytes);
47
+ });
48
+ });
49
+ }
50
+ function tspiceCallTimout(module, et, picture) {
51
+ const outMaxBytes = WASM_TIME_OUT_MAX_BYTES;
52
+ return withUtf8CString(module, picture, (picturePtr) => {
53
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, outMaxBytes], (errPtr, outPtr) => {
54
+ module.HEAPU8[outPtr] = 0;
55
+ const result = module._tspice_timout(et, picturePtr, outPtr, outMaxBytes, errPtr, WASM_ERR_MAX_BYTES);
56
+ if (result !== 0) {
57
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
58
+ }
59
+ return readFixedWidthCString(module, outPtr, outMaxBytes);
60
+ });
61
+ });
62
+ }
63
+ function tspiceCallDeltet(module, epoch, eptype) {
64
+ return withUtf8CString(module, eptype, (eptypePtr) => {
65
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 8], (errPtr, outDeltaPtr) => {
66
+ module.HEAPF64[outDeltaPtr >> 3] = 0;
67
+ const result = module._tspice_deltet(epoch, eptypePtr, outDeltaPtr, errPtr, WASM_ERR_MAX_BYTES);
68
+ if (result !== 0) {
69
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
70
+ }
71
+ return module.HEAPF64[outDeltaPtr >> 3] ?? 0;
72
+ });
73
+ });
74
+ }
75
+ function tspiceCallUnitim(module, epoch, insys, outsys) {
76
+ return withUtf8CString(module, insys, (insysPtr) => {
77
+ return withUtf8CString(module, outsys, (outsysPtr) => {
78
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 8], (errPtr, outEpochPtr) => {
79
+ module.HEAPF64[outEpochPtr >> 3] = 0;
80
+ const result = module._tspice_unitim(epoch, insysPtr, outsysPtr, outEpochPtr, errPtr, WASM_ERR_MAX_BYTES);
81
+ if (result !== 0) {
82
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
83
+ }
84
+ return module.HEAPF64[outEpochPtr >> 3] ?? 0;
85
+ });
86
+ });
87
+ });
88
+ }
89
+ function tspiceCallTparse(module, timstr) {
90
+ return withUtf8CString(module, timstr, (timstrPtr) => {
91
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 8], (errPtr, outEtPtr) => {
92
+ module.HEAPF64[outEtPtr >> 3] = 0;
93
+ const result = module._tspice_tparse(timstrPtr, outEtPtr, errPtr, WASM_ERR_MAX_BYTES);
94
+ if (result !== 0) {
95
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
96
+ }
97
+ return module.HEAPF64[outEtPtr >> 3] ?? 0;
98
+ });
99
+ });
100
+ }
101
+ function tspiceCallTpictr(module, sample, picturIn) {
102
+ const outMaxBytes = WASM_TIME_OUT_MAX_BYTES;
103
+ return withUtf8CString(module, sample, (samplePtr) => {
104
+ return withUtf8CString(module, picturIn, (picturInPtr) => {
105
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, outMaxBytes], (errPtr, outPtr) => {
106
+ module.HEAPU8[outPtr] = 0;
107
+ const result = module._tspice_tpictr(samplePtr, picturInPtr, outPtr, outMaxBytes, errPtr, WASM_ERR_MAX_BYTES);
108
+ if (result !== 0) {
109
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
110
+ }
111
+ return readFixedWidthCString(module, outPtr, outMaxBytes);
112
+ });
113
+ });
114
+ });
115
+ }
116
+ function tspiceCallTimdefGet(module, item) {
117
+ const outMaxBytes = WASM_TIME_SMALL_OUT_MAX_BYTES;
118
+ return withUtf8CString(module, item, (itemPtr) => {
119
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, outMaxBytes], (errPtr, outPtr) => {
120
+ module.HEAPU8[outPtr] = 0;
121
+ const result = module._tspice_timdef_get(itemPtr, outPtr, outMaxBytes, errPtr, WASM_ERR_MAX_BYTES);
122
+ if (result !== 0) {
123
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
124
+ }
125
+ return readFixedWidthCString(module, outPtr, outMaxBytes);
126
+ });
127
+ });
128
+ }
129
+ function tspiceCallTimdefSet(module, item, value) {
130
+ withUtf8CString(module, item, (itemPtr) => {
131
+ withUtf8CString(module, value, (valuePtr) => {
132
+ withMalloc(module, WASM_ERR_MAX_BYTES, (errPtr) => {
133
+ const result = module._tspice_timdef_set(itemPtr, valuePtr, errPtr, WASM_ERR_MAX_BYTES);
134
+ if (result !== 0) {
135
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
136
+ }
137
+ });
138
+ });
139
+ });
140
+ }
141
+ function tspiceCallScs2e(module, sc, sclkch) {
142
+ return withUtf8CString(module, sclkch, (sclkchPtr) => {
143
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 8], (errPtr, outEtPtr) => {
144
+ module.HEAPF64[outEtPtr >> 3] = 0;
145
+ const result = module._tspice_scs2e(sc, sclkchPtr, outEtPtr, errPtr, WASM_ERR_MAX_BYTES);
146
+ if (result !== 0) {
147
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
148
+ }
149
+ return module.HEAPF64[outEtPtr >> 3] ?? 0;
150
+ });
151
+ });
152
+ }
153
+ function tspiceCallSce2s(module, sc, et) {
154
+ const outMaxBytes = WASM_SCLK_OUT_MAX_BYTES;
155
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, outMaxBytes], (errPtr, outPtr) => {
44
156
  module.HEAPU8[outPtr] = 0;
45
- const result = module._tspice_et2utc(et, formatPtr, prec, outPtr, outMaxBytes, errPtr, errMaxBytes);
157
+ const result = module._tspice_sce2s(sc, et, outPtr, outMaxBytes, errPtr, WASM_ERR_MAX_BYTES);
46
158
  if (result !== 0) {
47
- throwWasmSpiceError(module, errPtr, errMaxBytes, result);
159
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
48
160
  }
49
- return module.UTF8ToString(outPtr, outMaxBytes).trim();
50
- }
51
- finally {
52
- module._free(outPtr);
53
- module._free(formatPtr);
54
- module._free(errPtr);
55
- }
161
+ return readFixedWidthCString(module, outPtr, outMaxBytes);
162
+ });
56
163
  }
57
- function tspiceCallTimout(module, et, picture) {
58
- const errMaxBytes = 2048;
59
- const errPtr = module._malloc(errMaxBytes);
60
- const picturePtr = writeUtf8CString(module, picture);
61
- // Buffer size includes terminating NUL.
62
- const outMaxBytes = 2048;
63
- const outPtr = module._malloc(outMaxBytes);
64
- if (!errPtr || !picturePtr || !outPtr) {
65
- for (const ptr of [outPtr, picturePtr, errPtr]) {
66
- if (ptr)
67
- module._free(ptr);
68
- }
69
- throw new Error("WASM malloc failed");
70
- }
71
- try {
164
+ function tspiceCallScencd(module, sc, sclkch) {
165
+ return withUtf8CString(module, sclkch, (sclkchPtr) => {
166
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 8], (errPtr, outSclkdpPtr) => {
167
+ module.HEAPF64[outSclkdpPtr >> 3] = 0;
168
+ const result = module._tspice_scencd(sc, sclkchPtr, outSclkdpPtr, errPtr, WASM_ERR_MAX_BYTES);
169
+ if (result !== 0) {
170
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
171
+ }
172
+ return module.HEAPF64[outSclkdpPtr >> 3] ?? 0;
173
+ });
174
+ });
175
+ }
176
+ function tspiceCallScdecd(module, sc, sclkdp) {
177
+ const outMaxBytes = WASM_SCLK_OUT_MAX_BYTES;
178
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, outMaxBytes], (errPtr, outPtr) => {
72
179
  module.HEAPU8[outPtr] = 0;
73
- const result = module._tspice_timout(et, picturePtr, outPtr, outMaxBytes, errPtr, errMaxBytes);
180
+ const result = module._tspice_scdecd(sc, sclkdp, outPtr, outMaxBytes, errPtr, WASM_ERR_MAX_BYTES);
74
181
  if (result !== 0) {
75
- throwWasmSpiceError(module, errPtr, errMaxBytes, result);
182
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
76
183
  }
77
- return module.UTF8ToString(outPtr, outMaxBytes).trim();
78
- }
79
- finally {
80
- module._free(outPtr);
81
- module._free(picturePtr);
82
- module._free(errPtr);
83
- }
184
+ return readFixedWidthCString(module, outPtr, outMaxBytes);
185
+ });
84
186
  }
85
- function tspiceCallScs2e(module, sc, sclkch) {
86
- const errMaxBytes = 2048;
87
- const errPtr = module._malloc(errMaxBytes);
88
- const sclkchPtr = writeUtf8CString(module, sclkch);
89
- const outEtPtr = module._malloc(8);
90
- if (!errPtr || !sclkchPtr || !outEtPtr) {
91
- for (const ptr of [outEtPtr, sclkchPtr, errPtr]) {
92
- if (ptr)
93
- module._free(ptr);
94
- }
95
- throw new Error("WASM malloc failed");
96
- }
97
- try {
187
+ function tspiceCallSct2e(module, sc, sclkdp) {
188
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 8], (errPtr, outEtPtr) => {
98
189
  module.HEAPF64[outEtPtr >> 3] = 0;
99
- const result = module._tspice_scs2e(sc, sclkchPtr, outEtPtr, errPtr, errMaxBytes);
190
+ const result = module._tspice_sct2e(sc, sclkdp, outEtPtr, errPtr, WASM_ERR_MAX_BYTES);
100
191
  if (result !== 0) {
101
- throwWasmSpiceError(module, errPtr, errMaxBytes, result);
192
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
102
193
  }
103
194
  return module.HEAPF64[outEtPtr >> 3] ?? 0;
104
- }
105
- finally {
106
- module._free(outEtPtr);
107
- module._free(sclkchPtr);
108
- module._free(errPtr);
109
- }
195
+ });
110
196
  }
111
- function tspiceCallSce2s(module, sc, et) {
112
- const errMaxBytes = 2048;
113
- const errPtr = module._malloc(errMaxBytes);
114
- // Buffer size includes terminating NUL.
115
- const outMaxBytes = 2048;
116
- const outPtr = module._malloc(outMaxBytes);
117
- if (!errPtr || !outPtr) {
118
- for (const ptr of [outPtr, errPtr]) {
119
- if (ptr)
120
- module._free(ptr);
121
- }
122
- throw new Error("WASM malloc failed");
123
- }
124
- try {
125
- module.HEAPU8[outPtr] = 0;
126
- const result = module._tspice_sce2s(sc, et, outPtr, outMaxBytes, errPtr, errMaxBytes);
197
+ function tspiceCallSce2c(module, sc, et) {
198
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 8], (errPtr, outSclkdpPtr) => {
199
+ module.HEAPF64[outSclkdpPtr >> 3] = 0;
200
+ const result = module._tspice_sce2c(sc, et, outSclkdpPtr, errPtr, WASM_ERR_MAX_BYTES);
127
201
  if (result !== 0) {
128
- throwWasmSpiceError(module, errPtr, errMaxBytes, result);
202
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
129
203
  }
130
- return module.UTF8ToString(outPtr, outMaxBytes).trim();
131
- }
132
- finally {
133
- module._free(outPtr);
134
- module._free(errPtr);
135
- }
204
+ return module.HEAPF64[outSclkdpPtr >> 3] ?? 0;
205
+ });
136
206
  }
207
+ /** Read the embedded CSPICE toolkit version string from the WASM module. */
137
208
  export function getToolkitVersion(module) {
138
209
  const outMaxBytes = 256;
139
- const errMaxBytes = 2048;
140
- const outPtr = module._malloc(outMaxBytes);
141
- const errPtr = module._malloc(errMaxBytes);
142
- if (!outPtr || !errPtr) {
143
- if (errPtr) {
144
- module._free(errPtr);
145
- }
146
- if (outPtr) {
147
- module._free(outPtr);
148
- }
149
- throw new Error("WASM malloc failed");
150
- }
151
- try {
152
- const result = module._tspice_tkvrsn_toolkit(outPtr, outMaxBytes, errPtr, errMaxBytes);
210
+ return withAllocs(module, [outMaxBytes, WASM_ERR_MAX_BYTES], (outPtr, errPtr) => {
211
+ const result = module._tspice_tkvrsn_toolkit(outPtr, outMaxBytes, errPtr, WASM_ERR_MAX_BYTES);
153
212
  if (result !== 0) {
154
- const message = module.UTF8ToString(errPtr, errMaxBytes).trim();
213
+ const message = module.UTF8ToString(errPtr, WASM_ERR_MAX_BYTES).trim();
155
214
  throw new Error(message || `CSPICE call failed with code ${result}`);
156
215
  }
157
216
  return module.UTF8ToString(outPtr, outMaxBytes);
158
- }
159
- finally {
160
- module._free(errPtr);
161
- module._free(outPtr);
162
- }
217
+ });
163
218
  }
219
+ /** Create a {@link TimeApi} implementation backed by a WASM Emscripten module. */
164
220
  export function createTimeApi(module, toolkitVersion) {
165
221
  return {
166
222
  spiceVersion: () => toolkitVersion,
@@ -170,11 +226,57 @@ export function createTimeApi(module, toolkitVersion) {
170
226
  }
171
227
  return toolkitVersion;
172
228
  },
229
+ timdef: (() => {
230
+ function timdef(action, item, value) {
231
+ if (item.length === 0) {
232
+ throw new RangeError("timdef(): item must be a non-empty string");
233
+ }
234
+ switch (action) {
235
+ case "GET": {
236
+ return tspiceCallTimdefGet(module, item);
237
+ }
238
+ case "SET": {
239
+ if (typeof value !== "string") {
240
+ throw new TypeError("timdef(SET) requires a string value");
241
+ }
242
+ if (value.length === 0) {
243
+ throw new RangeError("timdef(SET)(): value must be a non-empty string");
244
+ }
245
+ tspiceCallTimdefSet(module, item, value);
246
+ return;
247
+ }
248
+ default:
249
+ return assertNever(action, "Unsupported timdef action");
250
+ }
251
+ }
252
+ return timdef;
253
+ })(),
173
254
  str2et: (utc) => tspiceCallStr2et(module, utc),
174
255
  et2utc: (et, format, prec) => tspiceCallEt2utc(module, et, format, prec),
175
256
  timout: (et, picture) => tspiceCallTimout(module, et, picture),
257
+ deltet: (epoch, eptype) => tspiceCallDeltet(module, epoch, eptype),
258
+ unitim: (epoch, insys, outsys) => tspiceCallUnitim(module, epoch, insys, outsys),
259
+ tparse: (timstr) => {
260
+ if (timstr.length === 0) {
261
+ throw new RangeError("tparse(): timstr must be a non-empty string");
262
+ }
263
+ return tspiceCallTparse(module, timstr);
264
+ },
265
+ tpictr: (sample, pictur) => {
266
+ if (sample.length === 0) {
267
+ throw new RangeError("tpictr(): sample must be a non-empty string");
268
+ }
269
+ if (pictur.length === 0) {
270
+ throw new RangeError("tpictr(): pictur must be a non-empty string");
271
+ }
272
+ return tspiceCallTpictr(module, sample, pictur);
273
+ },
176
274
  scs2e: (sc, sclkch) => tspiceCallScs2e(module, sc, sclkch),
177
275
  sce2s: (sc, et) => tspiceCallSce2s(module, sc, et),
276
+ scencd: (sc, sclkch) => tspiceCallScencd(module, sc, sclkch),
277
+ scdecd: (sc, sclkdp) => tspiceCallScdecd(module, sc, sclkdp),
278
+ sct2e: (sc, sclkdp) => tspiceCallSct2e(module, sc, sclkdp),
279
+ sce2c: (sc, et) => tspiceCallSce2c(module, sc, et),
178
280
  };
179
281
  }
180
282
  //# sourceMappingURL=time.js.map
@@ -1,7 +1,9 @@
1
- import type { SpiceBackendWasm } from "#backend-contract";
1
+ import type { SpiceBackend } from "#backend-contract";
2
2
  export type { CreateWasmBackendOptions } from "./runtime/create-backend-options.js";
3
3
  import type { CreateWasmBackendOptions } from "./runtime/create-backend-options.js";
4
4
  export declare const WASM_BINARY_FILENAME: "tspice_backend_wasm.wasm";
5
5
  export declare const WASM_JS_FILENAME: string;
6
- export declare function createWasmBackend(options?: CreateWasmBackendOptions): Promise<SpiceBackendWasm>;
6
+ export declare function createWasmBackend(options?: CreateWasmBackendOptions): Promise<SpiceBackend & {
7
+ kind: "wasm";
8
+ }>;
7
9
  //# sourceMappingURL=index.d.ts.map