@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,357 @@
1
+ import { withAllocs, WASM_ERR_MAX_BYTES } from "../codec/alloc.js";
2
+ import { throwWasmSpiceError } from "../codec/errors.js";
3
+ import { readFixedWidthCStringArray, writeUtf8CString, } from "../codec/strings.js";
4
+ const UTF8_ENCODER = new TextEncoder();
5
+ const POOL_STRING_MAX_BYTES = 2048;
6
+ const POOL_NAME_MAX_BYTES = 64;
7
+ function assertNonEmptyString(fn, field, value) {
8
+ if (value.trim().length === 0) {
9
+ throw new RangeError(`${fn}(): ${field} must be a non-empty string`);
10
+ }
11
+ }
12
+ function assertStringArrayNoEmptyStrings(fn, field, values) {
13
+ for (const v of values) {
14
+ if (v.trim().length === 0) {
15
+ throw new RangeError(`${fn}(): ${field} must not contain empty strings`);
16
+ }
17
+ }
18
+ }
19
+ function assertAllFinite(fn, field, values) {
20
+ for (const v of values) {
21
+ if (!Number.isFinite(v)) {
22
+ throw new RangeError(`${fn}(): ${field} must contain only finite numbers`);
23
+ }
24
+ }
25
+ }
26
+ function assertAllInt32(fn, field, values) {
27
+ for (const v of values) {
28
+ if (!Number.isInteger(v) || v < -2147483648 || v > 2147483647) {
29
+ throw new RangeError(`${fn}(): ${field} must contain only 32-bit integers (got ${String(v)})`);
30
+ }
31
+ }
32
+ }
33
+ function assertPoolRange(fn, start, room) {
34
+ if (!Number.isFinite(start) || !Number.isInteger(start) || start < 0) {
35
+ throw new RangeError(`${fn}(): start must be an integer >= 0`);
36
+ }
37
+ if (!Number.isFinite(room) || !Number.isInteger(room) || room <= 0) {
38
+ throw new RangeError(`${fn}(): room must be an integer > 0`);
39
+ }
40
+ }
41
+ function writeFixedWidthUtf8CStringArray(module, ptr, width, values) {
42
+ // Zero-initialize to ensure null termination / padding.
43
+ //
44
+ // Even when values is empty (n=0), we may still pass a non-null buffer to CSPICE.
45
+ // Clear one "row" defensively.
46
+ const count = Math.max(1, values.length);
47
+ module.HEAPU8.fill(0, ptr, ptr + count * width);
48
+ for (let i = 0; i < values.length; i++) {
49
+ const encoded = UTF8_ENCODER.encode(values[i]);
50
+ const copyLen = Math.min(encoded.length, width - 1);
51
+ module.HEAPU8.set(encoded.subarray(0, copyLen), ptr + i * width);
52
+ module.HEAPU8[ptr + i * width + copyLen] = 0;
53
+ }
54
+ }
55
+ function tspiceCallGdpool(module, name, start, room) {
56
+ assertNonEmptyString("gdpool", "name", name);
57
+ assertPoolRange("gdpool", start, room);
58
+ const namePtr = writeUtf8CString(module, name);
59
+ try {
60
+ const valuesBytes = Math.max(8, room * 8);
61
+ return withAllocs(module, [
62
+ WASM_ERR_MAX_BYTES,
63
+ 4, // outN
64
+ 4, // found
65
+ valuesBytes + 7, // values (+padding for 8-byte alignment)
66
+ ], (errPtr, outNPtr, foundPtr, rawValuesPtr) => {
67
+ module.HEAP32[outNPtr >> 2] = 0;
68
+ module.HEAP32[foundPtr >> 2] = 0;
69
+ // Ensure 8-byte alignment for `HEAPF64` reads.
70
+ const valuesPtr = (rawValuesPtr + 7) & ~7;
71
+ const result = module._tspice_gdpool(namePtr, start, room, outNPtr, valuesPtr, foundPtr, errPtr, WASM_ERR_MAX_BYTES);
72
+ if (result !== 0) {
73
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
74
+ }
75
+ const found = (module.HEAP32[foundPtr >> 2] ?? 0) !== 0;
76
+ if (!found) {
77
+ return { found: false };
78
+ }
79
+ const n = Math.max(0, module.HEAP32[outNPtr >> 2] ?? 0);
80
+ const base = valuesPtr >> 3;
81
+ const values = Array.from(module.HEAPF64.subarray(base, base + n));
82
+ return { found: true, values };
83
+ });
84
+ }
85
+ finally {
86
+ module._free(namePtr);
87
+ }
88
+ }
89
+ function tspiceCallGipool(module, name, start, room) {
90
+ assertNonEmptyString("gipool", "name", name);
91
+ assertPoolRange("gipool", start, room);
92
+ const namePtr = writeUtf8CString(module, name);
93
+ try {
94
+ const valuesBytes = Math.max(4, room * 4);
95
+ return withAllocs(module, [
96
+ WASM_ERR_MAX_BYTES,
97
+ 4, // outN
98
+ 4, // found
99
+ valuesBytes + 3, // values (+padding for 4-byte alignment)
100
+ ], (errPtr, outNPtr, foundPtr, rawValuesPtr) => {
101
+ module.HEAP32[outNPtr >> 2] = 0;
102
+ module.HEAP32[foundPtr >> 2] = 0;
103
+ // Ensure 4-byte alignment for `HEAP32` reads.
104
+ const valuesPtr = (rawValuesPtr + 3) & ~3;
105
+ const result = module._tspice_gipool(namePtr, start, room, outNPtr, valuesPtr, foundPtr, errPtr, WASM_ERR_MAX_BYTES);
106
+ if (result !== 0) {
107
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
108
+ }
109
+ const found = (module.HEAP32[foundPtr >> 2] ?? 0) !== 0;
110
+ if (!found) {
111
+ return { found: false };
112
+ }
113
+ const n = Math.max(0, module.HEAP32[outNPtr >> 2] ?? 0);
114
+ const base = valuesPtr >> 2;
115
+ const values = Array.from(module.HEAP32.subarray(base, base + n));
116
+ return { found: true, values };
117
+ });
118
+ }
119
+ finally {
120
+ module._free(namePtr);
121
+ }
122
+ }
123
+ function tspiceCallGcpool(module, name, start, room) {
124
+ assertNonEmptyString("gcpool", "name", name);
125
+ assertPoolRange("gcpool", start, room);
126
+ const namePtr = writeUtf8CString(module, name);
127
+ try {
128
+ return withAllocs(module, [
129
+ WASM_ERR_MAX_BYTES,
130
+ 4, // outN
131
+ 4, // found
132
+ Math.max(POOL_STRING_MAX_BYTES, room * POOL_STRING_MAX_BYTES), // values
133
+ ], (errPtr, outNPtr, foundPtr, outPtr) => {
134
+ module.HEAP32[outNPtr >> 2] = 0;
135
+ module.HEAP32[foundPtr >> 2] = 0;
136
+ const result = module._tspice_gcpool(namePtr, start, room, POOL_STRING_MAX_BYTES, outNPtr, outPtr, foundPtr, errPtr, WASM_ERR_MAX_BYTES);
137
+ if (result !== 0) {
138
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
139
+ }
140
+ const found = (module.HEAP32[foundPtr >> 2] ?? 0) !== 0;
141
+ if (!found) {
142
+ return { found: false };
143
+ }
144
+ const n = Math.max(0, module.HEAP32[outNPtr >> 2] ?? 0);
145
+ const values = readFixedWidthCStringArray(module, outPtr, n, POOL_STRING_MAX_BYTES);
146
+ return { found: true, values };
147
+ });
148
+ }
149
+ finally {
150
+ module._free(namePtr);
151
+ }
152
+ }
153
+ function tspiceCallGnpool(module, template, start, room) {
154
+ assertNonEmptyString("gnpool", "template", template);
155
+ assertPoolRange("gnpool", start, room);
156
+ const namePtr = writeUtf8CString(module, template);
157
+ try {
158
+ return withAllocs(module, [
159
+ WASM_ERR_MAX_BYTES,
160
+ 4, // outN
161
+ 4, // found
162
+ Math.max(POOL_NAME_MAX_BYTES, room * POOL_NAME_MAX_BYTES), // values
163
+ ], (errPtr, outNPtr, foundPtr, outPtr) => {
164
+ module.HEAP32[outNPtr >> 2] = 0;
165
+ module.HEAP32[foundPtr >> 2] = 0;
166
+ const result = module._tspice_gnpool(namePtr, start, room, POOL_NAME_MAX_BYTES, outNPtr, outPtr, foundPtr, errPtr, WASM_ERR_MAX_BYTES);
167
+ if (result !== 0) {
168
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
169
+ }
170
+ const found = (module.HEAP32[foundPtr >> 2] ?? 0) !== 0;
171
+ if (!found) {
172
+ return { found: false };
173
+ }
174
+ const n = Math.max(0, module.HEAP32[outNPtr >> 2] ?? 0);
175
+ const values = readFixedWidthCStringArray(module, outPtr, n, POOL_NAME_MAX_BYTES);
176
+ return { found: true, values };
177
+ });
178
+ }
179
+ finally {
180
+ module._free(namePtr);
181
+ }
182
+ }
183
+ function tspiceCallDtpool(module, name) {
184
+ assertNonEmptyString("dtpool", "name", name);
185
+ const namePtr = writeUtf8CString(module, name);
186
+ const outTypeMaxBytes = 2;
187
+ try {
188
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 4, 4, outTypeMaxBytes], (errPtr, foundPtr, outNPtr, outTypePtr) => {
189
+ module.HEAP32[foundPtr >> 2] = 0;
190
+ module.HEAP32[outNPtr >> 2] = 0;
191
+ module.HEAPU8[outTypePtr] = 0;
192
+ const result = module._tspice_dtpool(namePtr, foundPtr, outNPtr, outTypePtr, outTypeMaxBytes, errPtr, WASM_ERR_MAX_BYTES);
193
+ if (result !== 0) {
194
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
195
+ }
196
+ const found = (module.HEAP32[foundPtr >> 2] ?? 0) !== 0;
197
+ if (!found) {
198
+ return { found: false };
199
+ }
200
+ const n = module.HEAP32[outNPtr >> 2] ?? 0;
201
+ const t = module.UTF8ToString(outTypePtr, outTypeMaxBytes).trim();
202
+ if (t !== "C" && t !== "N") {
203
+ throw new Error(`dtpool(): unexpected type '${t}' for ${name}`);
204
+ }
205
+ return { found: true, n, type: t };
206
+ });
207
+ }
208
+ finally {
209
+ module._free(namePtr);
210
+ }
211
+ }
212
+ function tspiceCallPdpool(module, name, values) {
213
+ assertNonEmptyString("pdpool", "name", name);
214
+ assertAllFinite("pdpool", "values", values);
215
+ const namePtr = writeUtf8CString(module, name);
216
+ try {
217
+ const n = values.length;
218
+ const valuesBytes = Math.max(8, n * 8);
219
+ // Ensure 8-byte alignment for `HEAPF64` writes.
220
+ //
221
+ // Emscripten's allocator *usually* returns suitably-aligned pointers, but we
222
+ // don't want to rely on that here (misalignment would cause `valuesPtr >> 3`
223
+ // to truncate and write to the wrong address).
224
+ withAllocs(module, [WASM_ERR_MAX_BYTES, valuesBytes + 7], (errPtr, rawValuesPtr) => {
225
+ const valuesPtr = (rawValuesPtr + 7) & ~7;
226
+ if (n > 0) {
227
+ module.HEAPF64.set(values, valuesPtr >> 3);
228
+ }
229
+ const result = module._tspice_pdpool(namePtr, n, valuesPtr, errPtr, WASM_ERR_MAX_BYTES);
230
+ if (result !== 0) {
231
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
232
+ }
233
+ });
234
+ }
235
+ finally {
236
+ module._free(namePtr);
237
+ }
238
+ }
239
+ function tspiceCallPipool(module, name, values) {
240
+ assertNonEmptyString("pipool", "name", name);
241
+ assertAllInt32("pipool", "values", values);
242
+ const namePtr = writeUtf8CString(module, name);
243
+ try {
244
+ const n = values.length;
245
+ const valuesBytes = Math.max(4, n * 4);
246
+ // Ensure 4-byte alignment for `HEAP32` writes.
247
+ // Mirror the `gdpool` pattern (padding + align) to be safe even if our
248
+ // allocator doesn't guarantee alignment.
249
+ withAllocs(module, [WASM_ERR_MAX_BYTES, valuesBytes + 3], (errPtr, rawValuesPtr) => {
250
+ const valuesPtr = (rawValuesPtr + 3) & ~3;
251
+ if (n > 0) {
252
+ module.HEAP32.set(values, valuesPtr >> 2);
253
+ }
254
+ const result = module._tspice_pipool(namePtr, n, valuesPtr, errPtr, WASM_ERR_MAX_BYTES);
255
+ if (result !== 0) {
256
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
257
+ }
258
+ });
259
+ }
260
+ finally {
261
+ module._free(namePtr);
262
+ }
263
+ }
264
+ function tspiceCallPcpool(module, name, values) {
265
+ assertNonEmptyString("pcpool", "name", name);
266
+ // NAIF's `pcpool_c` allows `n=0` (set an empty value list). We still reject
267
+ // blank strings.
268
+ assertStringArrayNoEmptyStrings("pcpool", "values", values);
269
+ const namePtr = writeUtf8CString(module, name);
270
+ try {
271
+ const n = values.length;
272
+ const lenvals = POOL_STRING_MAX_BYTES;
273
+ const totalBytes = Math.max(lenvals, n * lenvals);
274
+ withAllocs(module, [WASM_ERR_MAX_BYTES, totalBytes], (errPtr, cvalsPtr) => {
275
+ writeFixedWidthUtf8CStringArray(module, cvalsPtr, lenvals, values);
276
+ const result = module._tspice_pcpool(namePtr, n, lenvals, cvalsPtr, errPtr, WASM_ERR_MAX_BYTES);
277
+ if (result !== 0) {
278
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
279
+ }
280
+ });
281
+ }
282
+ finally {
283
+ module._free(namePtr);
284
+ }
285
+ }
286
+ function tspiceCallSwpool(module, agent, names) {
287
+ assertNonEmptyString("swpool", "agent", agent);
288
+ // NAIF's `swpool_c` allows `nnames=0` (watch nothing). We still reject blank strings.
289
+ assertStringArrayNoEmptyStrings("swpool", "names", names);
290
+ const agentPtr = writeUtf8CString(module, agent);
291
+ try {
292
+ const nnames = names.length;
293
+ const namlen = POOL_NAME_MAX_BYTES;
294
+ const totalBytes = Math.max(namlen, nnames * namlen);
295
+ withAllocs(module, [WASM_ERR_MAX_BYTES, totalBytes], (errPtr, namesPtr) => {
296
+ writeFixedWidthUtf8CStringArray(module, namesPtr, namlen, names);
297
+ const result = module._tspice_swpool(agentPtr, nnames, namlen, namesPtr, errPtr, WASM_ERR_MAX_BYTES);
298
+ if (result !== 0) {
299
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
300
+ }
301
+ });
302
+ }
303
+ finally {
304
+ module._free(agentPtr);
305
+ }
306
+ }
307
+ function tspiceCallCvpool(module, agent) {
308
+ assertNonEmptyString("cvpool", "agent", agent);
309
+ const agentPtr = writeUtf8CString(module, agent);
310
+ try {
311
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 4], (errPtr, outUpdatePtr) => {
312
+ module.HEAP32[outUpdatePtr >> 2] = 0;
313
+ const result = module._tspice_cvpool(agentPtr, outUpdatePtr, errPtr, WASM_ERR_MAX_BYTES);
314
+ if (result !== 0) {
315
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
316
+ }
317
+ return (module.HEAP32[outUpdatePtr >> 2] ?? 0) !== 0;
318
+ });
319
+ }
320
+ finally {
321
+ module._free(agentPtr);
322
+ }
323
+ }
324
+ function tspiceCallExpool(module, name) {
325
+ assertNonEmptyString("expool", "name", name);
326
+ const namePtr = writeUtf8CString(module, name);
327
+ try {
328
+ return withAllocs(module, [WASM_ERR_MAX_BYTES, 4], (errPtr, outFoundPtr) => {
329
+ module.HEAP32[outFoundPtr >> 2] = 0;
330
+ const result = module._tspice_expool(namePtr, outFoundPtr, errPtr, WASM_ERR_MAX_BYTES);
331
+ if (result !== 0) {
332
+ throwWasmSpiceError(module, errPtr, WASM_ERR_MAX_BYTES, result);
333
+ }
334
+ return (module.HEAP32[outFoundPtr >> 2] ?? 0) !== 0;
335
+ });
336
+ }
337
+ finally {
338
+ module._free(namePtr);
339
+ }
340
+ }
341
+ /** Create a {@link KernelPoolApi} implementation backed by a WASM Emscripten module. */
342
+ export function createKernelPoolApi(module) {
343
+ return {
344
+ gdpool: (name, start, room) => tspiceCallGdpool(module, name, start, room),
345
+ gipool: (name, start, room) => tspiceCallGipool(module, name, start, room),
346
+ gcpool: (name, start, room) => tspiceCallGcpool(module, name, start, room),
347
+ gnpool: (template, start, room) => tspiceCallGnpool(module, template, start, room),
348
+ dtpool: (name) => tspiceCallDtpool(module, name),
349
+ pdpool: (name, values) => tspiceCallPdpool(module, name, values),
350
+ pipool: (name, values) => tspiceCallPipool(module, name, values),
351
+ pcpool: (name, values) => tspiceCallPcpool(module, name, values),
352
+ swpool: (agent, names) => tspiceCallSwpool(module, agent, names),
353
+ cvpool: (agent) => tspiceCallCvpool(module, agent),
354
+ expool: (name) => tspiceCallExpool(module, name),
355
+ };
356
+ }
357
+ //# sourceMappingURL=kernel-pool.js.map
@@ -1,5 +1,6 @@
1
1
  import type { KernelsApi } from "#backend-contract";
2
2
  import type { EmscriptenModule } from "../lowlevel/exports.js";
3
3
  import type { WasmFsApi } from "../runtime/fs.js";
4
+ /** Create a {@link KernelsApi} implementation backed by a WASM Emscripten module + WASM FS. */
4
5
  export declare function createKernelsApi(module: EmscriptenModule, fs: WasmFsApi): KernelsApi;
5
6
  //# sourceMappingURL=kernels.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { kxtrctJs, matchesKernelKind, nativeKindQueryOrNull, normalizeKindInput, } from "#backend-contract";
1
2
  import { tspiceCall0, tspiceCall1Path } from "../codec/calls.js";
2
3
  import { throwWasmSpiceError } from "../codec/errors.js";
3
4
  import { writeUtf8CString } from "../codec/strings.js";
@@ -78,9 +79,42 @@ function tspiceCallKdata(module, which, kind) {
78
79
  module._free(errPtr);
79
80
  }
80
81
  }
82
+ /** Create a {@link KernelsApi} implementation backed by a WASM Emscripten module + WASM FS. */
81
83
  export function createKernelsApi(module, fs) {
84
+ let kinfoCache = null;
85
+ const clearKinfoCache = () => {
86
+ kinfoCache = null;
87
+ };
88
+ const getKinfoCache = () => {
89
+ if (kinfoCache != null) {
90
+ return kinfoCache;
91
+ }
92
+ const totalAll = tspiceCallKtotal(module, "ALL");
93
+ const map = new Map();
94
+ for (let i = 0; i < totalAll; i++) {
95
+ const kd = tspiceCallKdata(module, i, "ALL");
96
+ if (!kd.found) {
97
+ continue;
98
+ }
99
+ // `kd.file` is already normalized for this backend (see `furnsh` below), but
100
+ // normalize again to safely accept equivalent inputs like `kernels/foo.tls`,
101
+ // `/kernels//foo.tls`, etc.
102
+ const key = resolveKernelPath(kd.file);
103
+ if (map.has(key)) {
104
+ continue;
105
+ }
106
+ map.set(key, {
107
+ filtyp: kd.filtyp.trim(),
108
+ source: kd.source.trim(),
109
+ handle: kd.handle,
110
+ });
111
+ }
112
+ kinfoCache = map;
113
+ return map;
114
+ };
82
115
  return {
83
116
  furnsh: (kernel) => {
117
+ clearKinfoCache();
84
118
  if (typeof kernel === "string") {
85
119
  // String kernels are treated as *WASM-FS paths*.
86
120
  //
@@ -100,13 +134,68 @@ export function createKernelsApi(module, fs) {
100
134
  tspiceCall1Path(module, module._tspice_furnsh, path);
101
135
  },
102
136
  unload: (path) => {
137
+ clearKinfoCache();
103
138
  tspiceCall1Path(module, module._tspice_unload, resolveKernelPath(path));
104
139
  },
105
140
  kclear: () => {
141
+ clearKinfoCache();
106
142
  tspiceCall0(module, module._tspice_kclear);
107
143
  },
108
- ktotal: (kind = "ALL") => tspiceCallKtotal(module, kind),
109
- kdata: (which, kind = "ALL") => tspiceCallKdata(module, which, kind),
144
+ kinfo: (path) => {
145
+ const resolved = resolveKernelPath(path);
146
+ const info = getKinfoCache().get(resolved);
147
+ if (info == null) {
148
+ return { found: false };
149
+ }
150
+ return { found: true, ...info };
151
+ },
152
+ kxtrct: (keywd, terms, wordsq) => {
153
+ return kxtrctJs(keywd, terms, wordsq);
154
+ },
155
+ kplfrm: (_frmcls, _idset) => {
156
+ throw new Error("kplfrm not supported in current WASM bundle");
157
+ },
158
+ ktotal: (kind = "ALL") => {
159
+ const kinds = normalizeKindInput(kind);
160
+ const nativeQuery = nativeKindQueryOrNull(kinds);
161
+ if (nativeQuery != null) {
162
+ return tspiceCallKtotal(module, nativeQuery);
163
+ }
164
+ const requested = new Set(kinds);
165
+ const totalAll = tspiceCallKtotal(module, "ALL");
166
+ let count = 0;
167
+ for (let i = 0; i < totalAll; i++) {
168
+ const kd = tspiceCallKdata(module, i, "ALL");
169
+ if (kd.found && matchesKernelKind(requested, kd)) {
170
+ count++;
171
+ }
172
+ }
173
+ return count;
174
+ },
175
+ kdata: (which, kind = "ALL") => {
176
+ if (which < 0) {
177
+ return { found: false };
178
+ }
179
+ const kinds = normalizeKindInput(kind);
180
+ const nativeQuery = nativeKindQueryOrNull(kinds);
181
+ if (nativeQuery != null) {
182
+ return tspiceCallKdata(module, which, nativeQuery);
183
+ }
184
+ const requested = new Set(kinds);
185
+ const totalAll = tspiceCallKtotal(module, "ALL");
186
+ let matchIndex = 0;
187
+ for (let i = 0; i < totalAll; i++) {
188
+ const kd = tspiceCallKdata(module, i, "ALL");
189
+ if (!kd.found || !matchesKernelKind(requested, kd)) {
190
+ continue;
191
+ }
192
+ if (matchIndex === which) {
193
+ return kd;
194
+ }
195
+ matchIndex++;
196
+ }
197
+ return { found: false };
198
+ },
110
199
  };
111
200
  }
112
201
  //# sourceMappingURL=kernels.js.map
@@ -1,5 +1,7 @@
1
1
  import type { TimeApi } from "#backend-contract";
2
2
  import type { EmscriptenModule } from "../lowlevel/exports.js";
3
+ /** Read the embedded CSPICE toolkit version string from the WASM module. */
3
4
  export declare function getToolkitVersion(module: EmscriptenModule): string;
5
+ /** Create a {@link TimeApi} implementation backed by a WASM Emscripten module. */
4
6
  export declare function createTimeApi(module: EmscriptenModule, toolkitVersion: string): TimeApi;
5
7
  //# sourceMappingURL=time.d.ts.map