@uniflowed/temporal 0.0.0-alpha.35

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 (2) hide show
  1. package/index.js +76 -0
  2. package/package.json +23 -0
package/index.js ADDED
@@ -0,0 +1,76 @@
1
+ // @flow
2
+ //
3
+ // `@uniflowed/temporal`: the name an application imports Temporal by.
4
+ //
5
+ // The implementation is `@uniflowed/core/temporal` and this file is the front
6
+ // door, which is not indirection: `uf_lib`'s registry promises the specifier
7
+ // `@uniflowed/temporal`, and where the code lives is a packaging question that
8
+ // an application should not have to know the answer to. It lives in
9
+ // `@uniflowed/core` because `@uniflowed/hooks` reads the same clock and is on
10
+ // npm, and a published package may not depend on one that is not.
11
+ //
12
+ // # What still needs the native runtime
13
+ //
14
+ // One thing, and it is not an oversight. Temporal's calendar surface — a
15
+ // Japanese era, a Hebrew month, an Islamic date — is the CLDR calendar tables,
16
+ // and those are megabytes of data that a JavaScript implementation would have
17
+ // to carry into every bundle to answer a question most applications never ask.
18
+ // uf's binary already has them.
19
+ //
20
+ // So `withCalendar` raises `NativeRuntimeRequiredError`, naming itself, which
21
+ // is what every uf declaration does for a binding that needs the binary. A
22
+ // caller who never mentions a calendar never reaches it: everything in
23
+ // `Temporal` below is ISO 8601, which is what a timestamp on a page is.
24
+ //
25
+ // That is also why this package is on the release bootstrap's pending list
26
+ // rather than private. The useful Temporal surface is implemented and should
27
+ // have its own installable name; the one non-ISO calendar seam remains an
28
+ // explicit native-runtime boundary instead of pretending to work.
29
+
30
+ import { nativeRuntimeRequired } from "@uniflowed/core/native";
31
+ import { Temporal as implementation, isLite } from "@uniflowed/core/temporal";
32
+
33
+ const MODULE = "@uniflowed/temporal";
34
+
35
+ export type {
36
+ DateTimeFormatOptions,
37
+ Duration,
38
+ DurationLike,
39
+ Instant,
40
+ PlainDate,
41
+ PlainTime,
42
+ TemporalApi,
43
+ TemporalNow,
44
+ ZonedDateTime,
45
+ } from "@uniflowed/core/temporal";
46
+
47
+ /**
48
+ * Whether the five types are uf's own rather than the host's.
49
+ *
50
+ * Worth exporting because it is the honest answer to "will this behave the same
51
+ * everywhere": on a host with native Temporal an application gets the whole
52
+ * standard, and on one without it gets the subset `@uniflowed/core/temporal`
53
+ * documents. A page that needs to know can ask; most do not.
54
+ */
55
+ export { isLite };
56
+
57
+ /** `Temporal`, with the clock uf injects. See `@uniflowed/core/temporal`. */
58
+ export const Temporal: typeof implementation = implementation;
59
+
60
+ /**
61
+ * Re-express a date in a non-ISO calendar.
62
+ *
63
+ * The one binding here that the native runtime owns. It takes a calendar
64
+ * identifier — `japanese`, `hebrew`, `islamic-umalqura` — and there is no
65
+ * honest way to answer it from JavaScript without shipping the tables that
66
+ * define those calendars.
67
+ *
68
+ * `toLocaleString` is not this, and is the thing most callers actually want: a
69
+ * `ZonedDateTime` formatted with `{ calendar: "japanese" }` goes through `Intl`,
70
+ * which has the tables already, and prints a Japanese era without any of this.
71
+ * What is missing is *arithmetic* in another calendar — the next month in the
72
+ * Hebrew year — and that is what waits for the binary.
73
+ */
74
+ export function withCalendar<T>(value: T, calendar: string): T {
75
+ return nativeRuntimeRequired(MODULE, "withCalendar");
76
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@uniflowed/temporal",
3
+ "version": "0.0.0-alpha.35",
4
+ "description": "Temporal, with uf's clock and a native-runtime calendar seam, for the Unified Toolchain for Flow.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/ubugeeei-prod/uf.git",
11
+ "directory": "packages/temporal"
12
+ },
13
+ "exports": {
14
+ ".": "./index.js"
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "!*.test.js"
19
+ ],
20
+ "dependencies": {
21
+ "@uniflowed/core": "0.0.0-alpha.35"
22
+ }
23
+ }