@zodiacs/engine 0.1.1-rc.14
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.
- package/CHANGELOG.md +502 -0
- package/LICENSE +21 -0
- package/LICENSING.md +99 -0
- package/NOTICE +58 -0
- package/README.md +785 -0
- package/dist/chunk-4OSOCZY2.js +340 -0
- package/dist/chunk-AECKV73C.js +231 -0
- package/dist/chunk-CPALRSPC.js +35 -0
- package/dist/chunk-GFT24GFR.js +25 -0
- package/dist/chunk-NAJ735VN.js +219 -0
- package/dist/chunk-ONBZ4HK7.js +285 -0
- package/dist/chunk-PFGUCNOK.js +87 -0
- package/dist/chunk-RETEVD4F.js +681 -0
- package/dist/crossings.d.ts +91 -0
- package/dist/crossings.js +8 -0
- package/dist/deltat.d.ts +73 -0
- package/dist/deltat.js +12 -0
- package/dist/geo.d.ts +58 -0
- package/dist/geo.js +312 -0
- package/dist/index.d.ts +478 -0
- package/dist/index.js +682 -0
- package/dist/internal-math-BE2hcSHd.d.ts +271 -0
- package/dist/internal-math.d.ts +3 -0
- package/dist/internal-math.js +76 -0
- package/dist/internal.d.ts +9 -0
- package/dist/internal.js +16 -0
- package/dist/receipt.d.ts +224 -0
- package/dist/receipt.js +824 -0
- package/dist/types-CeafogFp.d.ts +197 -0
- package/package.json +94 -0
package/dist/receipt.js
ADDED
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dateFrom
|
|
3
|
+
} from "./chunk-CPALRSPC.js";
|
|
4
|
+
import {
|
|
5
|
+
outsideReferenceSpan
|
|
6
|
+
} from "./chunk-GFT24GFR.js";
|
|
7
|
+
import {
|
|
8
|
+
DELTA_T_MODEL,
|
|
9
|
+
DELTA_T_TABLE,
|
|
10
|
+
deltaTAt
|
|
11
|
+
} from "./chunk-ONBZ4HK7.js";
|
|
12
|
+
import {
|
|
13
|
+
ASPECTS,
|
|
14
|
+
ASPECT_BODIES,
|
|
15
|
+
ASPECT_TYPES,
|
|
16
|
+
EPHEMERIS,
|
|
17
|
+
SIGNS,
|
|
18
|
+
aspectMotion
|
|
19
|
+
} from "./chunk-NAJ735VN.js";
|
|
20
|
+
|
|
21
|
+
// src/receipt-json.ts
|
|
22
|
+
function parseReceiptJson(json, limits) {
|
|
23
|
+
if (typeof json !== "string") return { ok: false, code: "invalid_json" };
|
|
24
|
+
if (!Number.isSafeInteger(limits.depth) || limits.depth < 0 || !Number.isSafeInteger(limits.nodes) || limits.nodes < 1)
|
|
25
|
+
return { ok: false, code: "complexity_limit" };
|
|
26
|
+
let cursor = 0;
|
|
27
|
+
let nodes = 0;
|
|
28
|
+
let code = "invalid_json";
|
|
29
|
+
const stack = [];
|
|
30
|
+
const number2 = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/y;
|
|
31
|
+
const reject = (reason = "invalid_json") => {
|
|
32
|
+
code = reason;
|
|
33
|
+
throw new Error();
|
|
34
|
+
};
|
|
35
|
+
const whitespace = () => {
|
|
36
|
+
while (cursor < json.length && " \r\n".includes(json[cursor])) cursor += 1;
|
|
37
|
+
};
|
|
38
|
+
const string = (decode) => {
|
|
39
|
+
const start = cursor;
|
|
40
|
+
if (json[cursor++] !== '"') reject();
|
|
41
|
+
while (cursor < json.length) {
|
|
42
|
+
const character = json[cursor++];
|
|
43
|
+
if (character === '"') {
|
|
44
|
+
return decode ? JSON.parse(json.slice(start, cursor)) : void 0;
|
|
45
|
+
}
|
|
46
|
+
if (character.charCodeAt(0) < 32) reject();
|
|
47
|
+
if (character !== "\\") continue;
|
|
48
|
+
const escape = json[cursor++];
|
|
49
|
+
if (escape === "u") {
|
|
50
|
+
const digits = json.slice(cursor, cursor + 4);
|
|
51
|
+
if (!/^[0-9a-fA-F]{4}$/.test(digits)) reject();
|
|
52
|
+
cursor += 4;
|
|
53
|
+
} else if (escape === void 0 || !'"\\/bfnrt'.includes(escape)) reject();
|
|
54
|
+
}
|
|
55
|
+
return reject();
|
|
56
|
+
};
|
|
57
|
+
const value = (depth) => {
|
|
58
|
+
if (++nodes > limits.nodes || depth > limits.depth) reject("complexity_limit");
|
|
59
|
+
whitespace();
|
|
60
|
+
const token = json[cursor];
|
|
61
|
+
if (token === "{" || token === "[") {
|
|
62
|
+
cursor += 1;
|
|
63
|
+
stack.push({
|
|
64
|
+
kind: token === "{" ? "object" : "array",
|
|
65
|
+
state: "first",
|
|
66
|
+
...token === "{" ? { keys: /* @__PURE__ */ new Set() } : {}
|
|
67
|
+
});
|
|
68
|
+
} else if (token === '"') string(false);
|
|
69
|
+
else if (token === "-" || token !== void 0 && token >= "0" && token <= "9") {
|
|
70
|
+
number2.lastIndex = cursor;
|
|
71
|
+
if (!number2.exec(json)) reject();
|
|
72
|
+
cursor = number2.lastIndex;
|
|
73
|
+
} else {
|
|
74
|
+
const literal = ["true", "false", "null"].find(
|
|
75
|
+
(candidate) => json.startsWith(candidate, cursor)
|
|
76
|
+
);
|
|
77
|
+
if (!literal) return reject();
|
|
78
|
+
cursor += literal.length;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
try {
|
|
82
|
+
value(0);
|
|
83
|
+
while (stack.length > 0) {
|
|
84
|
+
const frame = stack[stack.length - 1];
|
|
85
|
+
whitespace();
|
|
86
|
+
const end = frame.kind === "object" ? "}" : "]";
|
|
87
|
+
if (frame.state === "separator") {
|
|
88
|
+
if (json[cursor] === end) {
|
|
89
|
+
cursor += 1;
|
|
90
|
+
stack.pop();
|
|
91
|
+
} else if (json[cursor] === ",") {
|
|
92
|
+
cursor += 1;
|
|
93
|
+
frame.state = "next";
|
|
94
|
+
} else reject();
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (frame.state === "first" && json[cursor] === end) {
|
|
98
|
+
cursor += 1;
|
|
99
|
+
stack.pop();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (frame.kind === "object") {
|
|
103
|
+
const key = string(true);
|
|
104
|
+
if (frame.keys.has(key)) reject();
|
|
105
|
+
frame.keys.add(key);
|
|
106
|
+
whitespace();
|
|
107
|
+
if (json[cursor++] !== ":") reject();
|
|
108
|
+
}
|
|
109
|
+
frame.state = "separator";
|
|
110
|
+
value(stack.length);
|
|
111
|
+
}
|
|
112
|
+
whitespace();
|
|
113
|
+
if (cursor !== json.length) reject();
|
|
114
|
+
return { ok: true, value: JSON.parse(json) };
|
|
115
|
+
} catch {
|
|
116
|
+
return { ok: false, code };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/receipt.ts
|
|
121
|
+
var NATAL_ENVELOPE_SCHEMA = "zodiacs.natal-envelope.draft-v1";
|
|
122
|
+
var NATAL_RECEIPT_SCHEMA = "zodiacs.calculation-receipt.draft-v1";
|
|
123
|
+
var NATAL_DIAGNOSTIC_SCHEMA = "zodiacs.natal-diagnostic.draft-v1";
|
|
124
|
+
var NATAL_ENVELOPE_LIMITS = Object.freeze({ bytes: 65536, depth: 12, nodes: 4096 });
|
|
125
|
+
var ERROR_CODES = /* @__PURE__ */ new Set([
|
|
126
|
+
"invalid_json",
|
|
127
|
+
"invalid_shape",
|
|
128
|
+
"invalid_value",
|
|
129
|
+
"inconsistent_result",
|
|
130
|
+
"invalid_context",
|
|
131
|
+
"size_limit",
|
|
132
|
+
"complexity_limit",
|
|
133
|
+
"unsupported_version",
|
|
134
|
+
"unsupported_feature"
|
|
135
|
+
]);
|
|
136
|
+
var ERROR_BRAND = /* @__PURE__ */ new WeakMap();
|
|
137
|
+
var NatalEnvelopeError = class extends Error {
|
|
138
|
+
code;
|
|
139
|
+
constructor(code) {
|
|
140
|
+
const fixed = ERROR_CODES.has(code) ? code : "invalid_shape";
|
|
141
|
+
super(`Natal envelope rejected: ${fixed}.`);
|
|
142
|
+
this.code = fixed;
|
|
143
|
+
this.name = "NatalEnvelopeError";
|
|
144
|
+
ERROR_BRAND.set(this, fixed);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var CONVENTIONS_RC3 = Object.freeze({
|
|
148
|
+
calendar: "proleptic-gregorian",
|
|
149
|
+
zodiac: "tropical",
|
|
150
|
+
planetPositions: "apparent-geocentric-ecliptic-of-date",
|
|
151
|
+
moonPosition: "astronomy-engine-ecliptic-geo-moon",
|
|
152
|
+
moonNodes: "instantaneous-geocentric-moon-orbit-plane",
|
|
153
|
+
angles: "gast-and-mean-obliquity",
|
|
154
|
+
longitudeUnit: "degrees-[0,360)",
|
|
155
|
+
speed: "degrees-per-day;central-difference-plus-minus-0.25-day",
|
|
156
|
+
aspects: "major-aspects;sun-moon-eight-planets;no-nodes"
|
|
157
|
+
});
|
|
158
|
+
var CONVENTIONS_RC7 = Object.freeze({
|
|
159
|
+
...CONVENTIONS_RC3,
|
|
160
|
+
angles: "gast-and-true-obliquity",
|
|
161
|
+
speed: "degrees-per-day;central-difference-plus-minus-0.001-day;nodes-plus-minus-0.25-day",
|
|
162
|
+
aspects: "major-aspects;sun-moon-eight-planets;no-nodes;applying-instantaneous-orb-rate"
|
|
163
|
+
});
|
|
164
|
+
var CONVENTIONS = Object.freeze({
|
|
165
|
+
...CONVENTIONS_RC7,
|
|
166
|
+
planetPositions: "aberrated-geocentric-ecliptic-of-date;no-deflection",
|
|
167
|
+
moonPosition: "astronomy-engine-ecliptic-geo-moon;no-light-time;no-aberration",
|
|
168
|
+
deltaT: "tt-minus-ut1;ut1-read-as-utc;value-in-result"
|
|
169
|
+
});
|
|
170
|
+
var NATAL_RECEIPT_CONVENTION_SETS = Object.freeze([
|
|
171
|
+
CONVENTIONS,
|
|
172
|
+
CONVENTIONS_RC7,
|
|
173
|
+
CONVENTIONS_RC3
|
|
174
|
+
]);
|
|
175
|
+
var RC3_TO_RC6 = /^0\.1\.1-rc\.[3-6](?:\+[A-Za-z0-9.-]+)?$/;
|
|
176
|
+
var RC7 = /^0\.1\.1-rc\.7(?:\+[A-Za-z0-9.-]+)?$/;
|
|
177
|
+
var BEFORE_RC9 = /^0\.(?:0\.\d+(?:-[A-Za-z0-9.-]+)?|1\.0(?:-[A-Za-z0-9.-]+)?|1\.1-rc\.[0-8])(?:\+[A-Za-z0-9.-]+)?$/;
|
|
178
|
+
var BEFORE_RC10 = /^0\.(?:0\.\d+(?:-[A-Za-z0-9.-]+)?|1\.0(?:-[A-Za-z0-9.-]+)?|1\.1-rc\.[0-9])(?:\+[A-Za-z0-9.-]+)?$/;
|
|
179
|
+
var BEFORE_RC8 = /^0\.(?:0\.\d+(?:-[A-Za-z0-9.-]+)?|1\.0(?:-[A-Za-z0-9.-]+)?|1\.1-rc\.[0-7])(?:\+[A-Za-z0-9.-]+)?$/;
|
|
180
|
+
var COVERAGE = Object.freeze({
|
|
181
|
+
assessment: "finite-reference-cases-only",
|
|
182
|
+
broadDateRange: "not-certified",
|
|
183
|
+
angleExclusions: "exact-geographic-poles-and-ecliptic-horizon-coincidence",
|
|
184
|
+
inputSyntax: "not-an-astronomical-accuracy-guarantee"
|
|
185
|
+
});
|
|
186
|
+
var BODIES = [
|
|
187
|
+
"Sun",
|
|
188
|
+
"Moon",
|
|
189
|
+
"Mercury",
|
|
190
|
+
"Venus",
|
|
191
|
+
"Mars",
|
|
192
|
+
"Jupiter",
|
|
193
|
+
"Saturn",
|
|
194
|
+
"Uranus",
|
|
195
|
+
"Neptune",
|
|
196
|
+
"Pluto",
|
|
197
|
+
"North Node",
|
|
198
|
+
"South Node"
|
|
199
|
+
];
|
|
200
|
+
var FLAGS_RC7 = ["dst-gap", "dst-fold", "lmt", "no-time", "polar-fallback"];
|
|
201
|
+
var FLAGS = [...FLAGS_RC7, "outside-reference-span"];
|
|
202
|
+
var TIME_FLAGS = ["dst-gap", "dst-fold", "lmt"];
|
|
203
|
+
var HOUSE_SYSTEMS = [
|
|
204
|
+
"whole",
|
|
205
|
+
"placidus",
|
|
206
|
+
"porphyry",
|
|
207
|
+
"equal",
|
|
208
|
+
"equal-mc",
|
|
209
|
+
"vehlow",
|
|
210
|
+
"koch",
|
|
211
|
+
"regiomontanus",
|
|
212
|
+
"campanus",
|
|
213
|
+
"topocentric",
|
|
214
|
+
"alcabitius",
|
|
215
|
+
"morinus",
|
|
216
|
+
"meridian"
|
|
217
|
+
];
|
|
218
|
+
var HOUSE_SYSTEMS_BEFORE_RC9 = ["whole", "placidus", "porphyry"];
|
|
219
|
+
var HOUSE_SYSTEMS_BEFORE_RC10 = HOUSE_SYSTEMS.filter(
|
|
220
|
+
(system) => system !== "equal-mc"
|
|
221
|
+
);
|
|
222
|
+
var POLAR_UNDEFINED = ["placidus", "koch"];
|
|
223
|
+
var TURNING_WITH_ASCENDANT = ["regiomontanus", "campanus", "topocentric"];
|
|
224
|
+
var HOSTILE_KEYS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
225
|
+
function fail(code) {
|
|
226
|
+
throw new NatalEnvelopeError(code);
|
|
227
|
+
}
|
|
228
|
+
function guarded(action) {
|
|
229
|
+
try {
|
|
230
|
+
return action();
|
|
231
|
+
} catch (error) {
|
|
232
|
+
return fail(errorCode(error));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function errorCode(error) {
|
|
236
|
+
return (error !== null && typeof error === "object" ? ERROR_BRAND.get(error) : void 0) ?? "invalid_shape";
|
|
237
|
+
}
|
|
238
|
+
function cloneData(value, allowDates = false) {
|
|
239
|
+
const seen = /* @__PURE__ */ new Set();
|
|
240
|
+
let nodes = 0;
|
|
241
|
+
let stringBytes = 0;
|
|
242
|
+
const countString = (text2) => {
|
|
243
|
+
if (text2.length > NATAL_ENVELOPE_LIMITS.bytes) fail("size_limit");
|
|
244
|
+
stringBytes += new TextEncoder().encode(text2).length;
|
|
245
|
+
if (stringBytes > NATAL_ENVELOPE_LIMITS.bytes) fail("size_limit");
|
|
246
|
+
};
|
|
247
|
+
const visit = (item, depth) => {
|
|
248
|
+
if (++nodes > NATAL_ENVELOPE_LIMITS.nodes || depth > NATAL_ENVELOPE_LIMITS.depth)
|
|
249
|
+
fail("complexity_limit");
|
|
250
|
+
if (item === null || typeof item === "boolean") return item;
|
|
251
|
+
if (typeof item === "string") {
|
|
252
|
+
countString(item);
|
|
253
|
+
return item;
|
|
254
|
+
}
|
|
255
|
+
if (typeof item === "number") {
|
|
256
|
+
if (!Number.isFinite(item)) fail("invalid_value");
|
|
257
|
+
return Object.is(item, -0) ? 0 : item;
|
|
258
|
+
}
|
|
259
|
+
if (typeof item !== "object") fail("invalid_shape");
|
|
260
|
+
if (seen.has(item)) fail("invalid_shape");
|
|
261
|
+
const prototype = Object.getPrototypeOf(item);
|
|
262
|
+
const keys = Reflect.ownKeys(item);
|
|
263
|
+
if (keys.length > NATAL_ENVELOPE_LIMITS.nodes) fail("complexity_limit");
|
|
264
|
+
if (allowDates && prototype === Date.prototype) {
|
|
265
|
+
if (keys.length !== 0) fail("invalid_shape");
|
|
266
|
+
const ms = Date.prototype.getTime.call(item);
|
|
267
|
+
if (!Number.isFinite(ms)) fail("invalid_value");
|
|
268
|
+
return new Date(ms);
|
|
269
|
+
}
|
|
270
|
+
const array = Array.isArray(item);
|
|
271
|
+
if (prototype !== (array ? Array.prototype : Object.prototype) && !(prototype === null && !array))
|
|
272
|
+
fail("invalid_shape");
|
|
273
|
+
seen.add(item);
|
|
274
|
+
const out = array ? [] : {};
|
|
275
|
+
const length = array ? Object.getOwnPropertyDescriptor(item, "length")?.value : 0;
|
|
276
|
+
if (array && (length > NATAL_ENVELOPE_LIMITS.nodes || keys.length !== length + 1))
|
|
277
|
+
fail("invalid_shape");
|
|
278
|
+
if (keys.some((key) => typeof key !== "string" || HOSTILE_KEYS.has(key))) fail("invalid_shape");
|
|
279
|
+
for (const key of keys.sort()) {
|
|
280
|
+
if (array && key === "length") continue;
|
|
281
|
+
if (array && (!/^(0|[1-9]\d*)$/.test(key) || Number(key) >= length)) fail("invalid_shape");
|
|
282
|
+
const descriptor = Object.getOwnPropertyDescriptor(item, key);
|
|
283
|
+
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) fail("invalid_shape");
|
|
284
|
+
countString(key);
|
|
285
|
+
Object.defineProperty(out, key, {
|
|
286
|
+
value: visit(descriptor.value, depth + 1),
|
|
287
|
+
enumerable: true,
|
|
288
|
+
writable: true,
|
|
289
|
+
configurable: true
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
seen.delete(item);
|
|
293
|
+
return out;
|
|
294
|
+
};
|
|
295
|
+
return visit(value, 0);
|
|
296
|
+
}
|
|
297
|
+
function record(value) {
|
|
298
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || value instanceof Date)
|
|
299
|
+
fail("invalid_shape");
|
|
300
|
+
return value;
|
|
301
|
+
}
|
|
302
|
+
function fields(value, required, optional = []) {
|
|
303
|
+
if (required.some((key) => !Object.hasOwn(value, key)) || Object.keys(value).some((key) => !required.includes(key) && !optional.includes(key)))
|
|
304
|
+
fail("invalid_shape");
|
|
305
|
+
}
|
|
306
|
+
function choice(value, choices) {
|
|
307
|
+
if (typeof value !== "string" || !choices.includes(value)) fail("invalid_value");
|
|
308
|
+
return value;
|
|
309
|
+
}
|
|
310
|
+
function number(value, min, max, exclusiveMax = false) {
|
|
311
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < min || (exclusiveMax ? value >= max : value > max))
|
|
312
|
+
fail("invalid_value");
|
|
313
|
+
return value;
|
|
314
|
+
}
|
|
315
|
+
function bool(value) {
|
|
316
|
+
if (typeof value !== "boolean") fail("invalid_shape");
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
319
|
+
function text(value, maximum = 128) {
|
|
320
|
+
if (typeof value !== "string" || value.length === 0 || value.length > maximum || value.trim() !== value || /[\p{Cc}\p{Cf}]/u.test(value))
|
|
321
|
+
fail("invalid_value");
|
|
322
|
+
return value;
|
|
323
|
+
}
|
|
324
|
+
function version(value) {
|
|
325
|
+
const parsed = text(value, 64);
|
|
326
|
+
if (!/^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?(?:\+[A-Za-z0-9.-]+)?$/.test(parsed))
|
|
327
|
+
fail("invalid_value");
|
|
328
|
+
return parsed;
|
|
329
|
+
}
|
|
330
|
+
function canonicalInstant(value) {
|
|
331
|
+
if (typeof value !== "string" || value.length > 32) fail("invalid_value");
|
|
332
|
+
try {
|
|
333
|
+
if (dateFrom(value, "instant").toISOString() !== value) fail("invalid_value");
|
|
334
|
+
} catch {
|
|
335
|
+
fail("invalid_value");
|
|
336
|
+
}
|
|
337
|
+
return value;
|
|
338
|
+
}
|
|
339
|
+
function flagList(value, allowed) {
|
|
340
|
+
if (!Array.isArray(value) || value.length > allowed.length) fail("invalid_value");
|
|
341
|
+
const flags = value.map((flag) => choice(flag, allowed));
|
|
342
|
+
if (new Set(flags).size !== flags.length || flags.includes("dst-gap") && flags.includes("dst-fold"))
|
|
343
|
+
fail("inconsistent_result");
|
|
344
|
+
return flags;
|
|
345
|
+
}
|
|
346
|
+
function sameFlags(a, b) {
|
|
347
|
+
return a.length === b.length && a.every((flag) => b.includes(flag));
|
|
348
|
+
}
|
|
349
|
+
function fixedFields(value, expected) {
|
|
350
|
+
const actual = record(value);
|
|
351
|
+
fields(actual, Object.keys(expected));
|
|
352
|
+
if (Object.keys(expected).some((key) => actual[key] !== expected[key]))
|
|
353
|
+
fail("unsupported_feature");
|
|
354
|
+
}
|
|
355
|
+
function conventionSet(value) {
|
|
356
|
+
const actual = record(value);
|
|
357
|
+
const keys = Object.keys(actual);
|
|
358
|
+
const match = NATAL_RECEIPT_CONVENTION_SETS.find(
|
|
359
|
+
(set) => keys.length === Object.keys(set).length && Object.entries(set).every(([key, expected]) => Object.hasOwn(actual, key) && actual[key] === expected)
|
|
360
|
+
);
|
|
361
|
+
if (!match) fail("unsupported_feature");
|
|
362
|
+
return match;
|
|
363
|
+
}
|
|
364
|
+
function longitude(value) {
|
|
365
|
+
return number(value, 0, 360, true);
|
|
366
|
+
}
|
|
367
|
+
function close(a, b) {
|
|
368
|
+
return Math.abs(a - b) <= 1e-8;
|
|
369
|
+
}
|
|
370
|
+
function wrap(value) {
|
|
371
|
+
return (value % 360 + 360) % 360;
|
|
372
|
+
}
|
|
373
|
+
function angularClose(a, b) {
|
|
374
|
+
return Math.min(wrap(a - b), wrap(b - a)) <= 1e-8;
|
|
375
|
+
}
|
|
376
|
+
var DELTA_T_SEGMENTS = [
|
|
377
|
+
"long-term",
|
|
378
|
+
"reconstructed",
|
|
379
|
+
"observed",
|
|
380
|
+
"predicted",
|
|
381
|
+
"extrapolated"
|
|
382
|
+
];
|
|
383
|
+
var J2000_MS = Date.UTC(2e3, 0, 1, 12);
|
|
384
|
+
function validateDeltaT(value, instant) {
|
|
385
|
+
const deltaT = record(value);
|
|
386
|
+
fields(deltaT, ["seconds", "sigma", "model", "table", "tableDigest", "segment"]);
|
|
387
|
+
const seconds = number(deltaT.seconds, -1e10, 1e10);
|
|
388
|
+
if (deltaT.model === "pinned") {
|
|
389
|
+
if (deltaT.sigma !== null || deltaT.table !== null || deltaT.tableDigest !== null || deltaT.segment !== "pinned")
|
|
390
|
+
fail("inconsistent_result");
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (deltaT.model !== DELTA_T_MODEL) fail("unsupported_feature");
|
|
394
|
+
number(deltaT.sigma, 0, 1e10);
|
|
395
|
+
if (typeof deltaT.table !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(deltaT.table))
|
|
396
|
+
fail("invalid_value");
|
|
397
|
+
if (typeof deltaT.tableDigest !== "string" || !/^[a-f0-9]{16}$/.test(deltaT.tableDigest))
|
|
398
|
+
fail("invalid_value");
|
|
399
|
+
const segment = choice(deltaT.segment, DELTA_T_SEGMENTS);
|
|
400
|
+
if (deltaT.tableDigest === DELTA_T_TABLE.digest) {
|
|
401
|
+
const expected = deltaTAt((Date.parse(instant) - J2000_MS) / 864e5);
|
|
402
|
+
if (deltaT.table !== expected.table || segment !== expected.segment || Math.abs(seconds - expected.seconds) > 1e-9 || Math.abs(deltaT.sigma - expected.sigma) > 1e-9)
|
|
403
|
+
fail("inconsistent_result");
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function validateResult(value, instantaneousApplying, instant) {
|
|
407
|
+
const result = record(value);
|
|
408
|
+
fields(result, ["bodies", "angles", "houses", "aspects", ...instant === null ? [] : ["deltaT"]]);
|
|
409
|
+
if (instant !== null) validateDeltaT(result.deltaT, instant);
|
|
410
|
+
if (!Array.isArray(result.bodies) || result.bodies.length !== 12) fail("invalid_shape");
|
|
411
|
+
const names = /* @__PURE__ */ new Set();
|
|
412
|
+
const longitudes = /* @__PURE__ */ new Map();
|
|
413
|
+
const speeds = /* @__PURE__ */ new Map();
|
|
414
|
+
for (const item of result.bodies) {
|
|
415
|
+
const body = record(item);
|
|
416
|
+
fields(body, ["body", "lon", "lat", "speed", "retrograde", "sign", "degree"]);
|
|
417
|
+
const name = choice(body.body, BODIES);
|
|
418
|
+
if (names.has(name)) fail("invalid_value");
|
|
419
|
+
names.add(name);
|
|
420
|
+
const lon = longitude(body.lon);
|
|
421
|
+
longitudes.set(name, lon);
|
|
422
|
+
number(body.lat, -90, 90);
|
|
423
|
+
const speed = number(body.speed, -Number.MAX_VALUE, Number.MAX_VALUE);
|
|
424
|
+
speeds.set(name, speed);
|
|
425
|
+
const degree = number(body.degree, 0, 30, true);
|
|
426
|
+
if (bool(body.retrograde) !== speed < 0 || body.sign !== SIGNS[Math.floor(lon / 30)]?.slug || !close(degree, lon % 30))
|
|
427
|
+
fail("inconsistent_result");
|
|
428
|
+
}
|
|
429
|
+
if (result.angles === null !== (result.houses === null)) fail("inconsistent_result");
|
|
430
|
+
if (result.angles !== null) {
|
|
431
|
+
const angles = record(result.angles);
|
|
432
|
+
fields(angles, ["asc", "mc", "dsc", "ic"]);
|
|
433
|
+
for (const angle of Object.values(angles)) longitude(angle);
|
|
434
|
+
if (!angularClose(angles.dsc, angles.asc + 180) || !angularClose(angles.ic, angles.mc + 180))
|
|
435
|
+
fail("inconsistent_result");
|
|
436
|
+
const houses = record(result.houses);
|
|
437
|
+
fields(houses, ["system", "cusps"]);
|
|
438
|
+
const system = choice(houses.system, HOUSE_SYSTEMS);
|
|
439
|
+
if (!Array.isArray(houses.cusps) || houses.cusps.length !== 12) fail("invalid_shape");
|
|
440
|
+
const cusps = houses.cusps.map(longitude);
|
|
441
|
+
if (new Set(cusps).size !== 12) fail("inconsistent_result");
|
|
442
|
+
const asc = angles.asc;
|
|
443
|
+
const mc = angles.mc;
|
|
444
|
+
const opposite = cusps.slice(0, 6).every((cusp, index) => angularClose(cusps[index + 6], cusp + 180));
|
|
445
|
+
const thirtyFrom = (start) => cusps.every((cusp, index) => angularClose(cusp, start + index * 30));
|
|
446
|
+
let consistent;
|
|
447
|
+
switch (system) {
|
|
448
|
+
case "whole":
|
|
449
|
+
consistent = thirtyFrom(Math.floor(asc / 30) * 30);
|
|
450
|
+
break;
|
|
451
|
+
case "equal":
|
|
452
|
+
consistent = thirtyFrom(asc);
|
|
453
|
+
break;
|
|
454
|
+
// The 10th cusp is the midheaven, so the 1st is 90° past it.
|
|
455
|
+
case "equal-mc":
|
|
456
|
+
consistent = thirtyFrom(mc + 90);
|
|
457
|
+
break;
|
|
458
|
+
case "vehlow":
|
|
459
|
+
consistent = thirtyFrom(asc - 15);
|
|
460
|
+
break;
|
|
461
|
+
// Neither angle is a Morinus cusp; the meridian system keeps the midheaven.
|
|
462
|
+
case "morinus":
|
|
463
|
+
consistent = opposite;
|
|
464
|
+
break;
|
|
465
|
+
case "meridian":
|
|
466
|
+
consistent = opposite && angularClose(cusps[9], mc);
|
|
467
|
+
break;
|
|
468
|
+
default:
|
|
469
|
+
consistent = opposite && angularClose(cusps[0], asc) && (angularClose(cusps[9], mc) || TURNING_WITH_ASCENDANT.includes(system) && angularClose(cusps[9], mc + 180));
|
|
470
|
+
}
|
|
471
|
+
if (!consistent) fail("inconsistent_result");
|
|
472
|
+
if (system === "porphyry") {
|
|
473
|
+
const upper = wrap(angles.asc - angles.mc);
|
|
474
|
+
const lower = 180 - upper;
|
|
475
|
+
if (upper >= 180 || !angularClose(cusps[10], angles.mc + upper / 3) || !angularClose(cusps[11], angles.mc + 2 * upper / 3) || !angularClose(cusps[1], angles.asc + lower / 3) || !angularClose(cusps[2], angles.asc + 2 * lower / 3))
|
|
476
|
+
fail("inconsistent_result");
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (!Array.isArray(result.aspects) || result.aspects.length > 45) fail("invalid_shape");
|
|
480
|
+
const pairs = /* @__PURE__ */ new Set();
|
|
481
|
+
for (const item of result.aspects) {
|
|
482
|
+
const aspect = record(item);
|
|
483
|
+
fields(aspect, ["a", "b", "type", "orb", "applying"]);
|
|
484
|
+
const a = choice(
|
|
485
|
+
aspect.a,
|
|
486
|
+
BODIES.filter((body) => ASPECT_BODIES.has(body))
|
|
487
|
+
);
|
|
488
|
+
const b = choice(
|
|
489
|
+
aspect.b,
|
|
490
|
+
BODIES.filter((body) => ASPECT_BODIES.has(body))
|
|
491
|
+
);
|
|
492
|
+
const key = [a, b].sort().join("/");
|
|
493
|
+
if (a === b || pairs.has(key)) fail("inconsistent_result");
|
|
494
|
+
pairs.add(key);
|
|
495
|
+
const type = choice(aspect.type, ASPECT_TYPES);
|
|
496
|
+
const definition = ASPECTS.find((aspect2) => aspect2.type === type);
|
|
497
|
+
const luminary = a === "Sun" || a === "Moon" || b === "Sun" || b === "Moon";
|
|
498
|
+
const orb = number(aspect.orb, 0, luminary ? definition.luminaryOrb : definition.orb);
|
|
499
|
+
const distance = Math.abs(longitudes.get(a) - longitudes.get(b));
|
|
500
|
+
if (!close(orb, Math.abs(Math.min(distance, 360 - distance) - definition.angle)))
|
|
501
|
+
fail("inconsistent_result");
|
|
502
|
+
const applying = bool(aspect.applying);
|
|
503
|
+
if (instantaneousApplying && applying !== (aspectMotion(
|
|
504
|
+
{ lon: longitudes.get(a), speed: speeds.get(a) },
|
|
505
|
+
{ lon: longitudes.get(b), speed: speeds.get(b) },
|
|
506
|
+
definition.angle
|
|
507
|
+
) === "applying"))
|
|
508
|
+
fail("inconsistent_result");
|
|
509
|
+
}
|
|
510
|
+
return result;
|
|
511
|
+
}
|
|
512
|
+
function validateLocal(value, receipt) {
|
|
513
|
+
if (value === null) {
|
|
514
|
+
if (receipt.reference === "local-noon") fail("invalid_context");
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const local = record(value);
|
|
518
|
+
fields(local, ["date", "time", "timeZone", "offsetMinutes", "gapShiftMinutes", "policy"]);
|
|
519
|
+
const date = text(local.date, 10), time = text(local.time, 5);
|
|
520
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date) || !/^(?:[01]\d|2[0-3]):[0-5]\d$/.test(time))
|
|
521
|
+
fail("invalid_context");
|
|
522
|
+
let wall;
|
|
523
|
+
try {
|
|
524
|
+
wall = dateFrom(`${date}T${time}:00Z`, "wall").getTime();
|
|
525
|
+
} catch {
|
|
526
|
+
fail("invalid_context");
|
|
527
|
+
}
|
|
528
|
+
const zone = text(local.timeZone, 128);
|
|
529
|
+
if (!/^[A-Za-z][A-Za-z0-9._+-]*(?:\/[A-Za-z0-9._+-]+){0,3}$/.test(zone)) fail("invalid_context");
|
|
530
|
+
const offset = number(local.offsetMinutes, -1440, 1440);
|
|
531
|
+
const shift = number(local.gapShiftMinutes, 0, 2880);
|
|
532
|
+
const offsetMs = offset * 6e4, shiftMs = shift * 6e4;
|
|
533
|
+
if (Math.abs(offsetMs - Math.round(offsetMs)) > 1e-6 || Math.abs(shiftMs - Math.round(shiftMs)) > 1e-6)
|
|
534
|
+
fail("invalid_context");
|
|
535
|
+
if (wall + Math.round(shiftMs) - Math.round(offsetMs) !== dateFrom(receipt.instant, "instant").getTime())
|
|
536
|
+
fail("invalid_context");
|
|
537
|
+
fixedFields(local.policy, { fold: "earlier", gap: "shift-forward" });
|
|
538
|
+
if (receipt.inputFlags.includes("dst-gap") !== shift > 0 || receipt.inputFlags.includes("lmt") !== Math.abs(offset % 1) > 1e-9)
|
|
539
|
+
fail("invalid_context");
|
|
540
|
+
if (receipt.reference === "local-noon" && time !== "12:00") fail("invalid_context");
|
|
541
|
+
}
|
|
542
|
+
function repository(value) {
|
|
543
|
+
const input = text(value, 256);
|
|
544
|
+
let url;
|
|
545
|
+
try {
|
|
546
|
+
url = new URL(input);
|
|
547
|
+
} catch {
|
|
548
|
+
return fail("invalid_value");
|
|
549
|
+
}
|
|
550
|
+
if (url.protocol !== "https:" || !url.hostname || url.username || url.password || url.search || url.hash)
|
|
551
|
+
fail("invalid_value");
|
|
552
|
+
}
|
|
553
|
+
function commit(value) {
|
|
554
|
+
if (typeof value !== "string" || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value))
|
|
555
|
+
fail("invalid_value");
|
|
556
|
+
}
|
|
557
|
+
function validateProvenance(value, engineVersion) {
|
|
558
|
+
if (value === null) return;
|
|
559
|
+
const facts = record(value);
|
|
560
|
+
fields(facts, ["status"], ["source", "artifact", "runtime", "ephemeris"]);
|
|
561
|
+
if (facts.status !== "claimed" || Object.keys(facts).length === 1) fail("invalid_shape");
|
|
562
|
+
if (facts.source !== void 0) {
|
|
563
|
+
const source = record(facts.source);
|
|
564
|
+
fields(source, ["repository", "commit"]);
|
|
565
|
+
repository(source.repository);
|
|
566
|
+
commit(source.commit);
|
|
567
|
+
}
|
|
568
|
+
if (facts.artifact !== void 0) {
|
|
569
|
+
const artifact = record(facts.artifact);
|
|
570
|
+
fields(
|
|
571
|
+
artifact,
|
|
572
|
+
["sha256", "packageVersion"],
|
|
573
|
+
["distributionRepository", "distributionCommit"]
|
|
574
|
+
);
|
|
575
|
+
if (typeof artifact.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(artifact.sha256))
|
|
576
|
+
fail("invalid_value");
|
|
577
|
+
if (version(artifact.packageVersion) !== engineVersion) fail("invalid_context");
|
|
578
|
+
if (artifact.distributionRepository === void 0 !== (artifact.distributionCommit === void 0))
|
|
579
|
+
fail("invalid_context");
|
|
580
|
+
if (artifact.distributionRepository !== void 0) {
|
|
581
|
+
repository(artifact.distributionRepository);
|
|
582
|
+
commit(artifact.distributionCommit);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (facts.runtime !== void 0) {
|
|
586
|
+
const runtime = record(facts.runtime);
|
|
587
|
+
fields(runtime, ["name"], ["version", "icuVersion", "tzdbVersion"]);
|
|
588
|
+
for (const item of Object.values(runtime)) text(item, 64);
|
|
589
|
+
}
|
|
590
|
+
if (facts.ephemeris !== void 0) {
|
|
591
|
+
const ephemeris = record(facts.ephemeris);
|
|
592
|
+
fields(ephemeris, ["name", "version"]);
|
|
593
|
+
if (ephemeris.name !== "astronomy-engine") fail("unsupported_feature");
|
|
594
|
+
version(ephemeris.version);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function validateEnvelope(input) {
|
|
598
|
+
const envelope = record(input);
|
|
599
|
+
if (envelope.schema !== NATAL_ENVELOPE_SCHEMA) fail("unsupported_version");
|
|
600
|
+
fields(envelope, ["schema", "requiredFeatures", "receipt", "result"], ["extensions"]);
|
|
601
|
+
if (!Array.isArray(envelope.requiredFeatures)) fail("invalid_shape");
|
|
602
|
+
if (envelope.requiredFeatures.length !== 0) fail("unsupported_feature");
|
|
603
|
+
const receipt = record(envelope.receipt);
|
|
604
|
+
if (receipt.schema !== NATAL_RECEIPT_SCHEMA) fail("unsupported_version");
|
|
605
|
+
fields(receipt, [
|
|
606
|
+
"schema",
|
|
607
|
+
"instant",
|
|
608
|
+
"sourceInstant",
|
|
609
|
+
"timeKnown",
|
|
610
|
+
"reference",
|
|
611
|
+
"localResolution",
|
|
612
|
+
"coordinates",
|
|
613
|
+
"houses",
|
|
614
|
+
"inputFlags",
|
|
615
|
+
"resultFlags",
|
|
616
|
+
"engine",
|
|
617
|
+
"provenance",
|
|
618
|
+
"conventions",
|
|
619
|
+
"coverage"
|
|
620
|
+
]);
|
|
621
|
+
canonicalInstant(receipt.instant);
|
|
622
|
+
if (receipt.sourceInstant !== null) {
|
|
623
|
+
if (typeof receipt.sourceInstant !== "string" || receipt.sourceInstant.length > 40)
|
|
624
|
+
fail("invalid_context");
|
|
625
|
+
try {
|
|
626
|
+
if (dateFrom(receipt.sourceInstant, "source").toISOString() !== receipt.instant)
|
|
627
|
+
fail("invalid_context");
|
|
628
|
+
} catch {
|
|
629
|
+
fail("invalid_context");
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const timeKnown = bool(receipt.timeKnown);
|
|
633
|
+
const reference = choice(receipt.reference, ["supplied-instant", "utc-noon", "local-noon"]);
|
|
634
|
+
if (reference !== "supplied-instant" && timeKnown) fail("invalid_context");
|
|
635
|
+
if (reference === "utc-noon" && !receipt.instant.endsWith("T12:00:00.000Z"))
|
|
636
|
+
fail("invalid_context");
|
|
637
|
+
if (receipt.coordinates !== null) {
|
|
638
|
+
const coords = record(receipt.coordinates);
|
|
639
|
+
fields(coords, ["latitude", "longitude"]);
|
|
640
|
+
number(coords.latitude, -90, 90);
|
|
641
|
+
number(coords.longitude, -180, 180);
|
|
642
|
+
if (timeKnown && Math.abs(coords.latitude) === 90) fail("unsupported_feature");
|
|
643
|
+
}
|
|
644
|
+
const conventions = conventionSet(receipt.conventions);
|
|
645
|
+
const result = validateResult(
|
|
646
|
+
envelope.result,
|
|
647
|
+
conventions !== CONVENTIONS_RC3,
|
|
648
|
+
conventions === CONVENTIONS ? receipt.instant : null
|
|
649
|
+
);
|
|
650
|
+
const house = record(receipt.houses);
|
|
651
|
+
fields(house, ["requested", "actual", "absenceReason"]);
|
|
652
|
+
const requested = choice(house.requested, HOUSE_SYSTEMS);
|
|
653
|
+
const reason = !timeKnown ? "unknown-time" : receipt.coordinates === null ? "missing-location" : null;
|
|
654
|
+
if (house.absenceReason !== reason || result.houses === null !== (reason !== null) || house.actual !== (result.houses?.system ?? null))
|
|
655
|
+
fail("inconsistent_result");
|
|
656
|
+
const actual = result.houses?.system;
|
|
657
|
+
if (actual !== void 0 && actual !== requested && !(POLAR_UNDEFINED.includes(requested) && actual === "whole") || conventions === CONVENTIONS_RC3 && requested === "porphyry")
|
|
658
|
+
fail("inconsistent_result");
|
|
659
|
+
if (result.houses && result.angles && TURNING_WITH_ASCENDANT.includes(result.houses.system) && !angularClose(result.houses.cusps[9], result.angles.mc) && Math.abs(receipt.coordinates.latitude) < 65)
|
|
660
|
+
fail("inconsistent_result");
|
|
661
|
+
const inputFlags = flagList(receipt.inputFlags, TIME_FLAGS);
|
|
662
|
+
const current = conventions === CONVENTIONS;
|
|
663
|
+
const resultFlags = flagList(receipt.resultFlags, current ? FLAGS : FLAGS_RC7);
|
|
664
|
+
const expected = [...inputFlags];
|
|
665
|
+
if (!timeKnown) expected.push("no-time");
|
|
666
|
+
if (POLAR_UNDEFINED.includes(requested) && result.houses?.system === "whole")
|
|
667
|
+
expected.push("polar-fallback");
|
|
668
|
+
if (current && outsideReferenceSpan(new Date(receipt.instant)))
|
|
669
|
+
expected.push("outside-reference-span");
|
|
670
|
+
if (!sameFlags(expected, resultFlags)) fail("inconsistent_result");
|
|
671
|
+
const engine = record(receipt.engine);
|
|
672
|
+
fields(engine, current ? ["name", "version", "ephemeris"] : ["name", "version"]);
|
|
673
|
+
if (engine.name !== "@zodiacs/engine") fail("unsupported_feature");
|
|
674
|
+
const engineVersion = version(engine.version);
|
|
675
|
+
if (current) {
|
|
676
|
+
const ephemeris = record(engine.ephemeris);
|
|
677
|
+
fields(ephemeris, ["name", "version"]);
|
|
678
|
+
if (ephemeris.name !== "astronomy-engine") fail("unsupported_feature");
|
|
679
|
+
version(ephemeris.version);
|
|
680
|
+
}
|
|
681
|
+
validateProvenance(receipt.provenance, engineVersion);
|
|
682
|
+
validateLocal(receipt.localResolution, receipt);
|
|
683
|
+
if (conventions === CONVENTIONS_RC3 && !RC3_TO_RC6.test(engineVersion) || conventions === CONVENTIONS_RC7 && !RC7.test(engineVersion) || current && BEFORE_RC8.test(engineVersion) || !HOUSE_SYSTEMS_BEFORE_RC9.includes(requested) && BEFORE_RC9.test(engineVersion) || !HOUSE_SYSTEMS_BEFORE_RC10.includes(requested) && BEFORE_RC10.test(engineVersion))
|
|
684
|
+
fail("inconsistent_result");
|
|
685
|
+
fixedFields(receipt.coverage, COVERAGE);
|
|
686
|
+
if (envelope.extensions !== void 0) record(envelope.extensions);
|
|
687
|
+
return envelope;
|
|
688
|
+
}
|
|
689
|
+
function encoded(envelope) {
|
|
690
|
+
const json = JSON.stringify(envelope);
|
|
691
|
+
if (new TextEncoder().encode(json).length > NATAL_ENVELOPE_LIMITS.bytes) fail("size_limit");
|
|
692
|
+
return json;
|
|
693
|
+
}
|
|
694
|
+
function checked(input) {
|
|
695
|
+
const envelope = validateEnvelope(cloneData(input));
|
|
696
|
+
encoded(envelope);
|
|
697
|
+
return envelope;
|
|
698
|
+
}
|
|
699
|
+
function createNatalEnvelope(chart, context = {}) {
|
|
700
|
+
return guarded(() => {
|
|
701
|
+
const source = record(cloneData(chart, true));
|
|
702
|
+
fields(source, [
|
|
703
|
+
"input",
|
|
704
|
+
"bodies",
|
|
705
|
+
"angles",
|
|
706
|
+
"houses",
|
|
707
|
+
"aspects",
|
|
708
|
+
"flags",
|
|
709
|
+
"deltaT",
|
|
710
|
+
"engineVersion"
|
|
711
|
+
]);
|
|
712
|
+
const input = record(source.input);
|
|
713
|
+
fields(
|
|
714
|
+
input,
|
|
715
|
+
["utc", "houseSystem", "timeKnown"],
|
|
716
|
+
["latitude", "longitude", "flags", "deltaT"]
|
|
717
|
+
);
|
|
718
|
+
if (!(input.utc instanceof Date)) fail("invalid_value");
|
|
719
|
+
const supplied = record(cloneData(context));
|
|
720
|
+
fields(
|
|
721
|
+
supplied,
|
|
722
|
+
[],
|
|
723
|
+
["reference", "sourceInstant", "localResolution", "provenance", "extensions"]
|
|
724
|
+
);
|
|
725
|
+
if (supplied.provenance !== void 0)
|
|
726
|
+
fields(record(supplied.provenance), [], ["source", "artifact", "runtime", "ephemeris"]);
|
|
727
|
+
if (input.latitude === void 0 !== (input.longitude === void 0)) fail("invalid_value");
|
|
728
|
+
const houses = source.houses === null ? null : record(source.houses);
|
|
729
|
+
const envelope = {
|
|
730
|
+
schema: NATAL_ENVELOPE_SCHEMA,
|
|
731
|
+
requiredFeatures: [],
|
|
732
|
+
receipt: {
|
|
733
|
+
schema: NATAL_RECEIPT_SCHEMA,
|
|
734
|
+
instant: Date.prototype.toISOString.call(input.utc),
|
|
735
|
+
sourceInstant: supplied.sourceInstant === void 0 ? null : supplied.sourceInstant,
|
|
736
|
+
timeKnown: input.timeKnown,
|
|
737
|
+
reference: supplied.reference === void 0 ? "supplied-instant" : supplied.reference,
|
|
738
|
+
localResolution: supplied.localResolution ?? null,
|
|
739
|
+
coordinates: input.latitude === void 0 ? null : { latitude: input.latitude, longitude: input.longitude },
|
|
740
|
+
houses: {
|
|
741
|
+
requested: input.houseSystem,
|
|
742
|
+
actual: houses?.system ?? null,
|
|
743
|
+
absenceReason: !input.timeKnown ? "unknown-time" : input.latitude === void 0 ? "missing-location" : null
|
|
744
|
+
},
|
|
745
|
+
inputFlags: input.flags ?? [],
|
|
746
|
+
resultFlags: source.flags,
|
|
747
|
+
engine: {
|
|
748
|
+
name: "@zodiacs/engine",
|
|
749
|
+
version: source.engineVersion,
|
|
750
|
+
ephemeris: { ...EPHEMERIS }
|
|
751
|
+
},
|
|
752
|
+
provenance: supplied.provenance === void 0 ? null : { ...record(supplied.provenance), status: "claimed" },
|
|
753
|
+
conventions: { ...CONVENTIONS },
|
|
754
|
+
coverage: { ...COVERAGE }
|
|
755
|
+
},
|
|
756
|
+
result: {
|
|
757
|
+
bodies: source.bodies,
|
|
758
|
+
angles: source.angles,
|
|
759
|
+
houses: source.houses,
|
|
760
|
+
aspects: source.aspects,
|
|
761
|
+
deltaT: source.deltaT
|
|
762
|
+
},
|
|
763
|
+
...supplied.extensions === void 0 ? {} : { extensions: supplied.extensions }
|
|
764
|
+
};
|
|
765
|
+
return checked(envelope);
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
function parseNatalEnvelope(json) {
|
|
769
|
+
try {
|
|
770
|
+
if (typeof json !== "string") fail("invalid_shape");
|
|
771
|
+
if (json.length > NATAL_ENVELOPE_LIMITS.bytes || new TextEncoder().encode(json).length > NATAL_ENVELOPE_LIMITS.bytes)
|
|
772
|
+
fail("size_limit");
|
|
773
|
+
const parsed = parseReceiptJson(json, {
|
|
774
|
+
depth: NATAL_ENVELOPE_LIMITS.depth,
|
|
775
|
+
nodes: NATAL_ENVELOPE_LIMITS.nodes
|
|
776
|
+
});
|
|
777
|
+
if (!parsed.ok) return parsed;
|
|
778
|
+
return { ok: true, envelope: guarded(() => checked(parsed.value)) };
|
|
779
|
+
} catch (error) {
|
|
780
|
+
return { ok: false, code: errorCode(error) };
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function serializeNatalEnvelope(envelope) {
|
|
784
|
+
return guarded(() => encoded(checked(envelope)));
|
|
785
|
+
}
|
|
786
|
+
function natalReplayInput(envelope) {
|
|
787
|
+
return guarded(() => {
|
|
788
|
+
const { receipt, result } = checked(envelope);
|
|
789
|
+
return {
|
|
790
|
+
utc: receipt.instant,
|
|
791
|
+
houseSystem: receipt.houses.requested,
|
|
792
|
+
timeKnown: receipt.timeKnown,
|
|
793
|
+
flags: [...receipt.inputFlags],
|
|
794
|
+
...receipt.coordinates === null ? {} : { ...receipt.coordinates },
|
|
795
|
+
...result.deltaT?.model === "pinned" ? { deltaT: result.deltaT.seconds } : {}
|
|
796
|
+
};
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
function redactNatalEnvelope(envelope) {
|
|
800
|
+
return guarded(() => {
|
|
801
|
+
const { receipt } = checked(envelope);
|
|
802
|
+
return {
|
|
803
|
+
schema: NATAL_DIAGNOSTIC_SCHEMA,
|
|
804
|
+
status: "redacted-not-anonymous",
|
|
805
|
+
timeKnown: receipt.timeKnown,
|
|
806
|
+
houses: { ...receipt.houses },
|
|
807
|
+
inputFlags: [...receipt.inputFlags],
|
|
808
|
+
resultFlags: [...receipt.resultFlags]
|
|
809
|
+
};
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
export {
|
|
813
|
+
NATAL_DIAGNOSTIC_SCHEMA,
|
|
814
|
+
NATAL_ENVELOPE_LIMITS,
|
|
815
|
+
NATAL_ENVELOPE_SCHEMA,
|
|
816
|
+
NATAL_RECEIPT_CONVENTION_SETS,
|
|
817
|
+
NATAL_RECEIPT_SCHEMA,
|
|
818
|
+
NatalEnvelopeError,
|
|
819
|
+
createNatalEnvelope,
|
|
820
|
+
natalReplayInput,
|
|
821
|
+
parseNatalEnvelope,
|
|
822
|
+
redactNatalEnvelope,
|
|
823
|
+
serializeNatalEnvelope
|
|
824
|
+
};
|