@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,265 @@
1
+ const SUPPORTED_QUERY_KIND_TOKENS = [
2
+ "ALL",
3
+ "SPK",
4
+ "CK",
5
+ "PCK",
6
+ "DSK",
7
+ "TEXT",
8
+ "LSK",
9
+ "FK",
10
+ "IK",
11
+ "SCLK",
12
+ "EK",
13
+ "META",
14
+ ];
15
+ const SUPPORTED_QUERY_KIND_SET = new Set(SUPPORTED_QUERY_KIND_TOKENS);
16
+ // `KernelData.filtyp` values are a subset of supported query tokens.
17
+ // In particular, `"ALL"` is valid as an input selector but should never be treated as a
18
+ // meaningful kernel-side `filtyp`.
19
+ const SUPPORTED_FILTYPE_TOKENS = SUPPORTED_QUERY_KIND_TOKENS.filter((k) => k !== "ALL");
20
+ const SUPPORTED_FILTYPE_SET = new Set(SUPPORTED_FILTYPE_TOKENS);
21
+ const TEXT_SUBTYPE_SET = new Set(["LSK", "FK", "IK", "SCLK"]);
22
+ const NATIVE_KIND_QUERY_ALLOWLIST = new Set([
23
+ "ALL",
24
+ "SPK",
25
+ "CK",
26
+ "PCK",
27
+ "DSK",
28
+ "TEXT",
29
+ "EK",
30
+ "META",
31
+ ]);
32
+ function normalizeKindTokenOrThrow(raw) {
33
+ const trimmed = raw.trim();
34
+ if (trimmed.length === 0) {
35
+ throw new RangeError("Kernel kind must be a non-empty token");
36
+ }
37
+ const upper = trimmed.toUpperCase();
38
+ if (!SUPPORTED_QUERY_KIND_SET.has(upper)) {
39
+ throw new RangeError(`Unknown kernel kind: ${trimmed}. Expected one of: ${SUPPORTED_QUERY_KIND_TOKENS.join(", ")}`);
40
+ }
41
+ return upper;
42
+ }
43
+ function extLower(path) {
44
+ // Handle both POSIX and Windows separators.
45
+ const base = path.split(/[/\\]/).pop() ?? path;
46
+ const idx = base.lastIndexOf(".");
47
+ if (idx < 0) {
48
+ return "";
49
+ }
50
+ return base.slice(idx).toLowerCase();
51
+ }
52
+ /**
53
+ * Best-effort inference of TEXT-kernel subtypes from the kernel "file" identifier.
54
+ *
55
+ * SPICE reports many text kernels as `filtyp: "TEXT"` even when they're logically
56
+ * subtypes like LSK/FK/IK/SCLK.
57
+ *
58
+ * We infer subtypes from common NAIF filename extensions, but this is inherently
59
+ * best-effort:
60
+ * - some backends expose *virtual* identifiers that aren't real filesystem paths
61
+ * - identifiers can be extension-less (or use non-standard extensions)
62
+ *
63
+ * In those cases, this returns "TEXT".
64
+ */
65
+ function guessTextKernelSubtype(path) {
66
+ switch (extLower(path)) {
67
+ case ".tls":
68
+ case ".lsk":
69
+ return "LSK";
70
+ case ".tf":
71
+ case ".fk":
72
+ return "FK";
73
+ case ".ti":
74
+ case ".ik":
75
+ return "IK";
76
+ case ".tsc":
77
+ case ".sclk":
78
+ return "SCLK";
79
+ default:
80
+ return "TEXT";
81
+ }
82
+ }
83
+ /** Normalize a `ktotal/kdata` kind input into a canonical, non-empty kernel kind list. */
84
+ export function normalizeKindInput(kind) {
85
+ if (kind == null) {
86
+ return ["ALL"];
87
+ }
88
+ const rawTokens = [];
89
+ if (Array.isArray(kind)) {
90
+ if (kind.length === 0) {
91
+ throw new RangeError("Kernel kind array must not be empty");
92
+ }
93
+ rawTokens.push(...kind.map((k) => String(k)));
94
+ }
95
+ else {
96
+ // Allow CSPICE-style multi-kind strings.
97
+ const raw = String(kind);
98
+ if (/\s/.test(raw)) {
99
+ for (const part of raw.trim().split(/\s+/)) {
100
+ if (part)
101
+ rawTokens.push(part);
102
+ }
103
+ }
104
+ else {
105
+ rawTokens.push(raw);
106
+ }
107
+ }
108
+ if (rawTokens.length === 0) {
109
+ throw new RangeError("Kernel kind must not be empty");
110
+ }
111
+ // Normalize + deduplicate while preserving first-seen order.
112
+ const seen = new Set();
113
+ let normalized = [];
114
+ for (const raw of rawTokens) {
115
+ const k = normalizeKindTokenOrThrow(raw);
116
+ if (seen.has(k))
117
+ continue;
118
+ seen.add(k);
119
+ normalized.push(k);
120
+ }
121
+ // Canonicalize ALL as an override: if ALL is present alongside other tokens,
122
+ // downstream callers should treat it as requesting all kinds.
123
+ if (normalized.length > 1 && normalized.includes("ALL")) {
124
+ return ["ALL"];
125
+ }
126
+ // Canonicalize away TEXT subtypes when TEXT is present. Subtype tokens only
127
+ // matter when TEXT is absent (and we must infer subtypes from `kernel.file`).
128
+ if (normalized.includes("TEXT")) {
129
+ normalized = normalized.filter((k) => !TEXT_SUBTYPE_SET.has(k));
130
+ }
131
+ return normalized;
132
+ }
133
+ /**
134
+ * Returns a representable native kind-query string (e.g. `"SPK CK"`) or null.
135
+ *
136
+ * This is used by backends to decide whether they can forward a kind filter to
137
+ * their underlying CSPICE implementation, or whether they must fall back to
138
+ * querying `ALL` and filtering in JS.
139
+ *
140
+ * NOTE: `kinds` is expected to be normalized (via {@link normalizeKindInput}).
141
+ * If non-normalized input slips through (e.g. empty arrays or `ALL` mixed with
142
+ * other tokens), this function is defensive and returns null.
143
+ */
144
+ export function nativeKindQueryOrNull(kinds) {
145
+ // Defensive: callers are expected to pass normalized kinds, but this is an
146
+ // exported helper and should not throw on incidental misuse.
147
+ if (kinds.length === 0)
148
+ return null;
149
+ if (kinds.length === 1 && kinds[0] === "ALL")
150
+ return "ALL";
151
+ // If someone bypasses normalization and includes ALL alongside other tokens,
152
+ // treat it as non-forwardable.
153
+ if (kinds.includes("ALL"))
154
+ return null;
155
+ for (const k of kinds) {
156
+ if (!NATIVE_KIND_QUERY_ALLOWLIST.has(k))
157
+ return null;
158
+ }
159
+ return kinds.join(" ");
160
+ }
161
+ function normalizeRequestedKindSetIfNeeded(requestedRaw) {
162
+ for (const raw of requestedRaw) {
163
+ const trimmed = raw.trim();
164
+ if (!trimmed || trimmed !== raw || trimmed.toUpperCase() !== trimmed) {
165
+ // Normalize the query (trim + uppercase) while filtering out empty tokens.
166
+ const normalized = new Set();
167
+ for (const k of requestedRaw) {
168
+ const token = k.trim();
169
+ if (token)
170
+ normalized.add(token.toUpperCase());
171
+ }
172
+ return normalized;
173
+ }
174
+ }
175
+ return requestedRaw;
176
+ }
177
+ /**
178
+ * Return whether a kernel matches the requested kind filter.
179
+ *
180
+ * Requested kind tokens are treated as trim + case-insensitive. Empty tokens are ignored.
181
+ *
182
+ * NOTE: Unlike {@link normalizeKindInput}, this helper is intentionally lenient:
183
+ * unknown requested tokens are treated as non-matching (and do not throw).
184
+ * Unknown/unsupported `kernel.filtyp` values never match (unless `requested` includes `ALL`).
185
+ *
186
+ * TEXT-kernel subtypes (LSK/FK/IK/SCLK): SPICE reports these as `filtyp: "TEXT"`.
187
+ * When callers request a subtype, we infer it from the `kernel.file` identifier's
188
+ * filename extension (best-effort). If the identifier is virtual or extension-less,
189
+ * subtype matching may fall back to "TEXT".
190
+ */
191
+ export function matchesKernelKind(requestedRaw, kernel) {
192
+ // Normalize the requested set internally so callers can't accidentally pass
193
+ // untrimmed / non-canonical tokens (e.g. "spk", " ALL ").
194
+ //
195
+ // Most call-sites already pass canonical kinds (e.g. via normalizeKindInput),
196
+ // so we avoid allocating a new set unless normalization is needed.
197
+ const requested = normalizeRequestedKindSetIfNeeded(requestedRaw);
198
+ if (requested.size === 0) {
199
+ return false;
200
+ }
201
+ if (requested.has("ALL")) {
202
+ return true;
203
+ }
204
+ const filtyp = kernel.filtyp.trim().toUpperCase();
205
+ if (filtyp.length === 0) {
206
+ return false;
207
+ }
208
+ if (filtyp === "TEXT") {
209
+ if (requested.has("TEXT")) {
210
+ return true;
211
+ }
212
+ const file = kernel.file.trim();
213
+ const subtype = guessTextKernelSubtype(file);
214
+ return requested.has(subtype);
215
+ }
216
+ // Some backends may choose to surface TEXT subtypes directly.
217
+ // Treat those as text kernels for matching purposes.
218
+ if (TEXT_SUBTYPE_SET.has(filtyp)) {
219
+ return requested.has("TEXT") || requested.has(filtyp);
220
+ }
221
+ // Contract-level strictness: unknown `filtyp` values never match.
222
+ if (!SUPPORTED_FILTYPE_SET.has(filtyp)) {
223
+ return false;
224
+ }
225
+ return requested.has(filtyp);
226
+ }
227
+ /**
228
+ * JS implementation of CSPICE `kxtrct`.
229
+ *
230
+ * Notes on return values:
231
+ * - `substr` is right-trimmed (`trimEnd()`).
232
+ * - `wordsq` has the extracted words removed, but otherwise preserves whitespace
233
+ * from the original input (so it may start with blanks).
234
+ */
235
+ export function kxtrctJs(keywd, terms, wordsq) {
236
+ const key = keywd.trim();
237
+ if (key.length === 0) {
238
+ throw new RangeError("kxtrct keywd must be a non-empty string");
239
+ }
240
+ const termSet = new Set(terms.map((t) => t.trim()).filter(Boolean));
241
+ const words = [...wordsq.matchAll(/\S+/g)].map((m) => {
242
+ const text = m[0];
243
+ const start = m.index ?? 0;
244
+ return { text, start, end: start + text.length - 1 };
245
+ });
246
+ const keyIndex = words.findIndex((w) => w.text === key);
247
+ if (keyIndex < 0) {
248
+ return { found: false };
249
+ }
250
+ let termIndex = -1;
251
+ for (let i = keyIndex + 1; i < words.length; i++) {
252
+ if (termSet.has(words[i].text)) {
253
+ termIndex = i;
254
+ break;
255
+ }
256
+ }
257
+ const startSub = words[keyIndex + 1]?.start;
258
+ const endSub = termIndex >= 0 ? words[termIndex].start : wordsq.length;
259
+ const substr = startSub == null ? "" : wordsq.slice(startSub, endSub).trimEnd();
260
+ const removalStart = words[keyIndex].start;
261
+ const removalEnd = termIndex >= 0 ? words[(termIndex - 1)].end + 1 : wordsq.length;
262
+ const newWordsq = wordsq.slice(0, removalStart) + wordsq.slice(removalEnd);
263
+ return { found: true, wordsq: newWordsq, substr };
264
+ }
265
+ //# sourceMappingURL=kernels-utils.js.map
@@ -1,4 +1,26 @@
1
- import type { Found, KernelData, KernelKind, KernelSource } from "../shared/types.js";
1
+ /**
2
+ * Contract conventions:
3
+ * - Inputs are validated at the backend boundary. This package provides shared runtime helpers
4
+ * (e.g. `normalizeKindInput`) that backends can reuse and that throw `RangeError` on invalid tokens.
5
+ * - Methods throw on invalid arguments or SPICE errors.
6
+ * - Lookups that may legitimately miss return `Found<T>` (`{ found: false }`) instead of throwing.
7
+ */
8
+ import type { Found, KernelData, KernelInfo, KernelKind, KernelSource } from "../shared/types.js";
9
+ import type { SpiceIntCell } from "./cells-windows.js";
10
+ /**
11
+ * Kernel kind selector used by `ktotal()` / `kdata()`.
12
+ *
13
+ * Supports:
14
+ * - a single `KernelKind`
15
+ * - an array of `KernelKind` (treated as an OR query)
16
+ * - a CSPICE-style multi-kind string (whitespace-separated, e.g. `"SPK CK"`)
17
+ *
18
+ * Tokens are validated case-insensitively and normalized to canonical uppercase.
19
+ * Unknown/empty tokens throw `RangeError`.
20
+ * An empty array (`[]`) is invalid and throws `RangeError`.
21
+ */
22
+ export type KernelKindInput = KernelKind | readonly KernelKind[] | string;
23
+ /** Backend contract for kernel management and kernel metadata queries. */
2
24
  export interface KernelsApi {
3
25
  /**
4
26
  * Load a SPICE kernel.
@@ -14,9 +36,23 @@ export interface KernelsApi {
14
36
  unload(path: string): void;
15
37
  /** Clear all loaded kernels. */
16
38
  kclear(): void;
39
+ /** Retrieve information about a currently loaded kernel by filename. */
40
+ kinfo(path: string): Found<KernelInfo>;
41
+ /**
42
+ * Extract a substring from a word sequence.
43
+ *
44
+ * This is a string-parsing utility (used by some NAIF kernels and tooling).
45
+ * It does **not** extract kernel bytes.
46
+ */
47
+ kxtrct(keywd: string, terms: readonly string[], wordsq: string): Found<{
48
+ wordsq: string;
49
+ substr: string;
50
+ }>;
51
+ /** Return kernel-pool frame IDs for the given frame class. */
52
+ kplfrm(frmcls: number, idset: SpiceIntCell): void;
17
53
  /** Count loaded kernels of a given kind. */
18
- ktotal(kind?: KernelKind): number;
54
+ ktotal(kind?: KernelKindInput): number;
19
55
  /** Retrieve kernel metadata at position `which` for a given kind. */
20
- kdata(which: number, kind?: KernelKind): Found<KernelData>;
56
+ kdata(which: number, kind?: KernelKindInput): Found<KernelData>;
21
57
  }
22
58
  //# sourceMappingURL=kernels.d.ts.map
@@ -1,4 +1,11 @@
1
+ /**
2
+ * Contract conventions:
3
+ * - Inputs are assumed validated at the backend boundary; the contract itself is primarily type-level.
4
+ * - Methods throw on invalid arguments or SPICE errors.
5
+ * - Lookups that may legitimately miss return `Found<T>` (`{ found: false }`) instead of throwing.
6
+ */
1
7
  export interface TimeApi {
8
+ /** Return the underlying SPICE toolkit version string. */
2
9
  spiceVersion(): string;
3
10
  /**
4
11
  * Thin wrapper over the SPICE primitive `tkvrsn()`.
@@ -16,9 +23,104 @@ export interface TimeApi {
16
23
  * Wrapper around CSPICE `timout_c`.
17
24
  */
18
25
  timout(et: number, picture: string): string;
26
+ /**
27
+ * Return the difference ET - UTC at a given epoch.
28
+ *
29
+ * Kernel prerequisites:
30
+ * - Requires an LSK (leapseconds) kernel to be loaded.
31
+ *
32
+ * Wrapper around CSPICE `deltet_c`.
33
+ */
34
+ deltet(epoch: number, eptype: "ET" | "UTC"): number;
35
+ /**
36
+ * Convert a time epoch from one system to another.
37
+ *
38
+ * Kernel prerequisites:
39
+ * - Requires an LSK (leapseconds) kernel to be loaded.
40
+ *
41
+ * Wrapper around CSPICE `unitim_c`.
42
+ */
43
+ unitim(epoch: number, insys: string, outsys: string): number;
44
+ /**
45
+ * Parse a UTC time string to **UTC seconds past J2000**.
46
+ *
47
+ * This uses SPICE's "formal calendar" (fixed 86400-second days) and does **not**
48
+ * account for leap seconds.
49
+ *
50
+ * Limitations:
51
+ * - UTC-only: `timstr` must not include time system labels (e.g. `TDB`) or
52
+ * time zone designators/offsets (e.g. `PDT`, `UTC+05:00`).
53
+ *
54
+ * Kernel prerequisites:
55
+ * - None.
56
+ *
57
+ * Wrapper around CSPICE `tparse_c`.
58
+ */
59
+ tparse(timstr: string): number;
60
+ /**
61
+ * Transform a NAIF time picture to match a sample time string.
62
+ *
63
+ * Statefulness: this is affected by TIMDEF defaults (SYSTEM/CALENDAR/ZONE),
64
+ * since `sample` is interpreted under the current TIMDEF state.
65
+ *
66
+ * Kernel prerequisites:
67
+ * - None.
68
+ *
69
+ * Wrapper around CSPICE `tpictr_c`.
70
+ */
71
+ tpictr(sample: string, pictur: string): string;
72
+ /**
73
+ * Get or set time conversion defaults.
74
+ *
75
+ * Kernel prerequisites:
76
+ * - None.
77
+ *
78
+ * Wrapper around CSPICE `timdef_c`.
79
+ */
80
+ timdef(action: "GET", item: string): string;
81
+ /** Set a time conversion default (see `timdef_c`). */
82
+ timdef(action: "SET", item: string, value: string): void;
19
83
  /** Convert an encoded SCLK string to ET seconds past J2000. */
20
84
  scs2e(sc: number, sclkch: string): number;
21
85
  /** Convert ET seconds past J2000 to an encoded SCLK string. */
22
86
  sce2s(sc: number, et: number): string;
87
+ /**
88
+ * Encode an SCLK string into "ticks".
89
+ *
90
+ * Kernel prerequisites:
91
+ * - Requires an SCLK kernel to be loaded.
92
+ *
93
+ * Wrapper around CSPICE `scencd_c`.
94
+ */
95
+ scencd(sc: number, sclkch: string): number;
96
+ /**
97
+ * Decode SCLK "ticks" into an SCLK string.
98
+ *
99
+ * Kernel prerequisites:
100
+ * - Requires an SCLK kernel to be loaded.
101
+ *
102
+ * Wrapper around CSPICE `scdecd_c`.
103
+ */
104
+ scdecd(sc: number, sclkdp: number): string;
105
+ /**
106
+ * Convert SCLK "ticks" to ET seconds past J2000.
107
+ *
108
+ * Kernel prerequisites:
109
+ * - Requires an SCLK kernel to be loaded.
110
+ * - Often requires an LSK (leapseconds) kernel as well (see NAIF docs).
111
+ *
112
+ * Wrapper around CSPICE `sct2e_c`.
113
+ */
114
+ sct2e(sc: number, sclkdp: number): number;
115
+ /**
116
+ * Convert ET seconds past J2000 to SCLK "ticks".
117
+ *
118
+ * Kernel prerequisites:
119
+ * - Requires an SCLK kernel to be loaded.
120
+ * - Often requires an LSK (leapseconds) kernel as well (see NAIF docs).
121
+ *
122
+ * Wrapper around CSPICE `sce2c_c`.
123
+ */
124
+ sce2c(sc: number, et: number): number;
23
125
  }
24
126
  //# sourceMappingURL=time.d.ts.map
@@ -1,22 +1,50 @@
1
- export type { AbCorr, Found, IluminResult, KernelData, KernelKind, KernelSource, Mat3ColMajor, Mat3RowMajor, SpiceMatrix6x6, SpiceStateVector, SpiceVector3, SpkezrResult, SpkposResult, SubPointResult, } from "./shared/types.js";
1
+ export type { AbCorr, FixedString, Found, FoundDouble, FoundInt, FoundPayload, FoundString, FoundValue, IllumfResult, IllumgResult, IluminResult, KernelData, KernelInfo, KernelKind, KernelSource, VirtualOutput, Mat6RowMajor, Mat3ColMajor, Mat3RowMajor, Pl2nvcResult, SpiceHandle, SpiceMatrix6x6, SpicePlane, SpiceStateVector, SpiceVector3, SpkezrResult, SpkposResult, StringArrayResult, SubPointResult, Vec3, Vec6, } from "./shared/types.js";
2
2
  export type { BrandMat3Options } from "./shared/mat3.js";
3
- export { assertMat3ArrayLike9, brandMat3ColMajor, brandMat3RowMajor, isMat3ColMajor, isMat3RowMajor, } from "./shared/mat3.js";
3
+ export { assertMat3ArrayLike9, isMat3ArrayLike9, brandMat3ColMajor, brandMat3RowMajor, isBrandedMat3ColMajor, isBrandedMat3RowMajor, } from "./shared/mat3.js";
4
+ export type { BrandVecOptions } from "./shared/vec.js";
5
+ export { assertVec3ArrayLike3, assertVec6ArrayLike6, isVec3ArrayLike3, isVec6ArrayLike6, brandVec3, brandVec6, isBrandedVec3, isBrandedVec6, } from "./shared/vec.js";
6
+ export type { BrandMat6Options } from "./shared/mat6.js";
7
+ export { assertMat6ArrayLike36, isMat6ArrayLike36, brandMat6RowMajor, isBrandedMat6RowMajor, } from "./shared/mat6.js";
8
+ export { SPICE_INT32_MIN, SPICE_INT32_MAX, assertSpiceInt32, assertSpiceInt32NonNegative, } from "./shared/spice-int.js";
9
+ export type { SpiceHandleEntry, SpiceHandleKind, SpiceHandleRegistry } from "./shared/spice-handles.js";
10
+ export { createSpiceHandleRegistry } from "./shared/spice-handles.js";
11
+ export { SpiceBackendContractError } from "./shared/errors.js";
12
+ export type { KernelKindInput, KernelsApi } from "./domains/kernels.js";
4
13
  export * from "./domains/kernels.js";
14
+ export * from "./domains/kernel-pool.js";
15
+ export * from "./domains/ek.js";
16
+ export * from "./domains/kernels-utils.js";
5
17
  export * from "./domains/time.js";
6
18
  export * from "./domains/ids-names.js";
19
+ export * from "./domains/ids-names-normalize.js";
7
20
  export * from "./domains/frames.js";
8
21
  export * from "./domains/ephemeris.js";
9
22
  export * from "./domains/geometry.js";
23
+ export * from "./domains/geometry-gf.js";
10
24
  export * from "./domains/coords-vectors.js";
25
+ export * from "./domains/file-io.js";
26
+ export * from "./domains/error.js";
27
+ export * from "./domains/cells-windows.js";
28
+ export * from "./domains/dsk.js";
11
29
  import type { KernelsApi } from "./domains/kernels.js";
30
+ import type { KernelPoolApi } from "./domains/kernel-pool.js";
31
+ import type { EkApi } from "./domains/ek.js";
12
32
  import type { TimeApi } from "./domains/time.js";
13
33
  import type { IdsNamesApi } from "./domains/ids-names.js";
14
34
  import type { FramesApi } from "./domains/frames.js";
15
35
  import type { EphemerisApi } from "./domains/ephemeris.js";
16
36
  import type { GeometryApi } from "./domains/geometry.js";
37
+ import type { GeometryGfApi } from "./domains/geometry-gf.js";
17
38
  import type { CoordsVectorsApi } from "./domains/coords-vectors.js";
39
+ import type { FileIoApi } from "./domains/file-io.js";
40
+ import type { ErrorApi } from "./domains/error.js";
41
+ import type { CellsWindowsApi } from "./domains/cells-windows.js";
42
+ import type { DskApi } from "./domains/dsk.js";
18
43
  export type SpiceBackendKind = "node" | "wasm" | "fake";
19
- export interface SpiceBackend extends TimeApi, KernelsApi, IdsNamesApi, FramesApi, EphemerisApi, GeometryApi, CoordsVectorsApi {
44
+ /**
45
+ * Unified backend contract (composition of all domain APIs).
46
+ */
47
+ export interface SpiceBackend extends TimeApi, KernelsApi, KernelPoolApi, EkApi, IdsNamesApi, FramesApi, EphemerisApi, GeometryApi, GeometryGfApi, CoordsVectorsApi, FileIoApi, ErrorApi, CellsWindowsApi, DskApi {
20
48
  /** Which backend implementation is in use. */
21
49
  readonly kind: SpiceBackendKind;
22
50
  }
@@ -1,9 +1,23 @@
1
- export { assertMat3ArrayLike9, brandMat3ColMajor, brandMat3RowMajor, isMat3ColMajor, isMat3RowMajor, } from "./shared/mat3.js";
1
+ export { assertMat3ArrayLike9, isMat3ArrayLike9, brandMat3ColMajor, brandMat3RowMajor, isBrandedMat3ColMajor, isBrandedMat3RowMajor, } from "./shared/mat3.js";
2
+ export { assertVec3ArrayLike3, assertVec6ArrayLike6, isVec3ArrayLike3, isVec6ArrayLike6, brandVec3, brandVec6, isBrandedVec3, isBrandedVec6, } from "./shared/vec.js";
3
+ export { assertMat6ArrayLike36, isMat6ArrayLike36, brandMat6RowMajor, isBrandedMat6RowMajor, } from "./shared/mat6.js";
4
+ export { SPICE_INT32_MIN, SPICE_INT32_MAX, assertSpiceInt32, assertSpiceInt32NonNegative, } from "./shared/spice-int.js";
5
+ export { createSpiceHandleRegistry } from "./shared/spice-handles.js";
6
+ export { SpiceBackendContractError } from "./shared/errors.js";
2
7
  export * from "./domains/kernels.js";
8
+ export * from "./domains/kernel-pool.js";
9
+ export * from "./domains/ek.js";
10
+ export * from "./domains/kernels-utils.js";
3
11
  export * from "./domains/time.js";
4
12
  export * from "./domains/ids-names.js";
13
+ export * from "./domains/ids-names-normalize.js";
5
14
  export * from "./domains/frames.js";
6
15
  export * from "./domains/ephemeris.js";
7
16
  export * from "./domains/geometry.js";
17
+ export * from "./domains/geometry-gf.js";
8
18
  export * from "./domains/coords-vectors.js";
19
+ export * from "./domains/file-io.js";
20
+ export * from "./domains/error.js";
21
+ export * from "./domains/cells-windows.js";
22
+ export * from "./domains/dsk.js";
9
23
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
1
+ /** Error thrown when a backend violates a contract invariant or postcondition. */
2
+ export declare class SpiceBackendContractError extends Error {
3
+ name: string;
4
+ constructor(message: string);
5
+ }
6
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,8 @@
1
+ /** Error thrown when a backend violates a contract invariant or postcondition. */
2
+ export class SpiceBackendContractError extends Error {
3
+ name = "SpiceBackendContractError";
4
+ constructor(message) {
5
+ super(message);
6
+ }
7
+ }
8
+ //# sourceMappingURL=errors.js.map
@@ -15,26 +15,38 @@ export type BrandMat3Options = {
15
15
  readonly freeze?: FreezeMode;
16
16
  };
17
17
  /**
18
- * Runtime validation that an input is a length-9 array-like of finite numbers.
19
- *
20
- * This is intentionally layout-agnostic; it is used by both row-major and
21
- * column-major branded types.
22
- */
18
+ * Runtime validation that an input is a length-9 array-like of finite numbers.
19
+ *
20
+ * This is intentionally layout-agnostic; it is used by both row-major and
21
+ * column-major branded types.
22
+ */
23
23
  export declare function assertMat3ArrayLike9(value: unknown, options?: {
24
24
  readonly label?: string;
25
25
  }): asserts value is ArrayLike<number>;
26
26
  /**
27
- * Validate + brand a value as a row-major Mat3.
28
- *
29
- * Used at backend boundaries (node/wasm/fake) to avoid ad-hoc `as Mat3RowMajor`
30
- * casts.
31
- */
27
+ * Structural check: accepts number[] and numeric TypedArrays (excludes DataView).
28
+ *
29
+ * This does **not** assert/require that the value is branded as a row/col-major Mat3.
30
+ */
31
+ export declare function isMat3ArrayLike9(value: unknown): value is ArrayLike<number>;
32
+ /**
33
+ * Validate + brand a value as a row-major Mat3.
34
+ *
35
+ * Used at backend boundaries (node/wasm/fake) to avoid ad-hoc `as Mat3RowMajor`
36
+ * casts.
37
+ */
32
38
  export declare function brandMat3RowMajor(value: unknown, options?: BrandMat3Options): Mat3RowMajor;
33
39
  /**
34
- * Validate + brand a value as a column-major Mat3.
35
- */
40
+ * Validate + brand a value as a column-major Mat3.
41
+ */
36
42
  export declare function brandMat3ColMajor(value: unknown, options?: BrandMat3Options): Mat3ColMajor;
37
- export declare function isMat3RowMajor(value: unknown): value is Mat3RowMajor;
38
- export declare function isMat3ColMajor(value: unknown): value is Mat3ColMajor;
43
+ /**
44
+ * Brand-only check: verifies that a value was produced by `brandMat3RowMajor()`.
45
+ */
46
+ export declare function isBrandedMat3RowMajor(value: unknown): value is Mat3RowMajor;
47
+ /**
48
+ * Brand-only check: verifies that a value was produced by `brandMat3ColMajor()`.
49
+ */
50
+ export declare function isBrandedMat3ColMajor(value: unknown): value is Mat3ColMajor;
39
51
  export {};
40
52
  //# sourceMappingURL=mat3.d.ts.map