Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,58 @@ To be released.
fetches are retried once, and remaining transport failures are reported as
`FetchError` with the original error as the cause. [[#762], [#763]]

- Fixed a `TypeError` thrown when Activity Vocabulary constructors received
a `Temporal.Instant` or `Temporal.Duration` produced by an implementation
other than the bundled `@js-temporal/polyfill` (for example, the native
`Temporal` shipped with Node.js 26+). Internal `instanceof` checks have
been replaced with `Symbol.toStringTag`-based guards so any spec-conformant
Temporal value is accepted. Generated _\*.d.ts_ declarations no longer
import from `@js-temporal/polyfill`; they reference the ambient `Temporal`
namespace through the `esnext.temporal` lib instead, which removes the
nominal mismatch with native Temporal types. TypeScript 6.0 or later is
required to consume the type declarations. [[#767], [#768]]

[#762]: https://github.com/fedify-dev/fedify/issues/762
[#763]: https://github.com/fedify-dev/fedify/pull/763
[#767]: https://github.com/fedify-dev/fedify/issues/767
[#768]: https://github.com/fedify-dev/fedify/pull/768

### @fedify/vocab-runtime

- Added `isTemporalInstant()` and `isTemporalDuration()` type guards that
accept both polyfill and native `Temporal` values via `Symbol.toStringTag`.
[[#767], [#768]]

- Added the `@fedify/vocab-runtime/temporal` subpath export so consumers
can import the new `Temporal` type guards without pulling in the rest of
the runtime. [[#767], [#768]]

### @fedify/postgres

- Generated _\*.d.ts_ declarations no longer import from
`@js-temporal/polyfill`; they reference the ambient `Temporal` namespace
through the `esnext.temporal` lib instead, so `pollInterval` and
`handlerTimeout` accept native `Temporal.Duration` values from Node.js
26+ without a nominal type mismatch. TypeScript 6.0 or later is
required to consume the type declarations. [[#767], [#768]]

### @fedify/redis

- Generated _\*.d.ts_ declarations no longer import from
`@js-temporal/polyfill`; they reference the ambient `Temporal` namespace
through the `esnext.temporal` lib instead, so `pollInterval` accepts
native `Temporal.Duration` values from Node.js 26+ without a nominal type
mismatch. TypeScript 6.0 or later is required to consume the type
declarations. [[#767], [#768]]

### @fedify/sqlite

- Generated _\*.d.ts_ declarations no longer import from
`@js-temporal/polyfill`; they reference the ambient `Temporal` namespace
through the `esnext.temporal` lib instead, so `pollInterval` accepts
native `Temporal.Duration` values from Node.js 26+ without a nominal type
mismatch. TypeScript 6.0 or later is required to consume the type
declarations. [[#767], [#768]]


Version 2.0.16
Expand Down
4 changes: 3 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 8 additions & 11 deletions packages/debugger/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ export default defineConfig({
/^hono\//,
],
},
outputOptions(outputOptions, format) {
if (format === "cjs") {
outputOptions.intro = `
const { Temporal } = require("@js-temporal/polyfill");
`;
} else {
outputOptions.intro = `
import { Temporal } from "@js-temporal/polyfill";
`;
}
return outputOptions;
banner({ format }) {
const js = format === "cjs"
? `const { Temporal } = require("@js-temporal/polyfill");`
: `import { Temporal } from "@js-temporal/polyfill";`;
return {
js,
dts: `/// <reference lib="esnext.temporal" />`,
};
},
});
5 changes: 2 additions & 3 deletions packages/fedify/src/utils/kv-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
RemoteDocument,
} from "@fedify/vocab-runtime";
import { preloadedContexts } from "@fedify/vocab-runtime";
import { isTemporalDuration } from "@fedify/vocab-runtime/temporal";
import { getLogger } from "@logtape/logtape";
import type {
KvKey,
Expand Down Expand Up @@ -155,9 +156,7 @@ function matchRule(
][],
): Temporal.Duration | null {
for (const [pattern, d] of rules!) {
const duration = d instanceof Temporal.Duration
? d
: Temporal.Duration.from(d);
const duration = isTemporalDuration(d) ? d : Temporal.Duration.from(d);
Comment thread
dahlia marked this conversation as resolved.
Outdated
if (typeof pattern === "string") {
if (url === pattern) return duration;
continue;
Expand Down
27 changes: 14 additions & 13 deletions packages/fedify/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ export default [
format: ["esm", "cjs"],
platform: "neutral",
deps: { neverBundle: [/^node:/] },
outputOptions(outputOptions, format) {
if (format === "cjs") {
outputOptions.intro = `
const { Temporal } = require("@js-temporal/polyfill");
const { URLPattern } = require("urlpattern-polyfill");
`;
} else {
outputOptions.intro = `
import { Temporal } from "@js-temporal/polyfill";
import { URLPattern } from "urlpattern-polyfill";
`;
}
return outputOptions;
banner({ format }) {
const js = format === "cjs"
? [
`const { Temporal } = require("@js-temporal/polyfill");`,
`const { URLPattern } = require("urlpattern-polyfill");`,
].join("\n")
: [
`import { Temporal } from "@js-temporal/polyfill";`,
`import { URLPattern } from "urlpattern-polyfill";`,
].join("\n");
return {
js,
dts: `/// <reference lib="esnext.temporal" />`,
};
},
}),
defineConfig({
Expand Down
19 changes: 8 additions & 11 deletions packages/postgres/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ export default defineConfig({
dts: format === "cjs" ? ".d.cts" : ".d.ts",
};
},
outputOptions(outputOptions, format) {
if (format === "cjs") {
outputOptions.intro = `
const { Temporal } = require("@js-temporal/polyfill");
`;
} else {
outputOptions.intro = `
import { Temporal } from "@js-temporal/polyfill";
`;
}
return outputOptions;
banner({ format }) {
const js = format === "cjs"
? `const { Temporal } = require("@js-temporal/polyfill");`
: `import { Temporal } from "@js-temporal/polyfill";`;
return {
js,
dts: `/// <reference lib="esnext.temporal" />`,
};
},
});
19 changes: 8 additions & 11 deletions packages/redis/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ export default defineConfig({
dts: format === "cjs" ? ".d.cts" : ".d.ts",
};
},
outputOptions(outputOptions, format) {
if (format === "cjs") {
outputOptions.intro = `
const { Temporal } = require("@js-temporal/polyfill");
`;
} else {
outputOptions.intro = `
import { Temporal } from "@js-temporal/polyfill";
`;
}
return outputOptions;
banner({ format }) {
const js = format === "cjs"
? `const { Temporal } = require("@js-temporal/polyfill");`
: `import { Temporal } from "@js-temporal/polyfill";`;
return {
js,
dts: `/// <reference lib="esnext.temporal" />`,
};
},
});
19 changes: 8 additions & 11 deletions packages/relay/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ export default [
dts: format === "cjs" ? ".d.cts" : ".d.ts",
};
},
outputOptions(outputOptions, format) {
if (format === "cjs") {
outputOptions.intro = `
const { Temporal } = require("@js-temporal/polyfill");
`;
} else {
outputOptions.intro = `
import { Temporal } from "@js-temporal/polyfill";
`;
}
return outputOptions;
banner({ format }) {
const js = format === "cjs"
? `const { Temporal } = require("@js-temporal/polyfill");`
: `import { Temporal } from "@js-temporal/polyfill";`;
return {
js,
dts: `/// <reference lib="esnext.temporal" />`,
};
},
}),
defineConfig({
Expand Down
19 changes: 8 additions & 11 deletions packages/sqlite/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@ export default defineConfig({
defaultHandler(warning);
},
},
outputOptions(outputOptions, format) {
if (format === "cjs") {
outputOptions.intro = `
const { Temporal } = require("@js-temporal/polyfill");
`;
} else {
outputOptions.intro = `
import { Temporal } from "@js-temporal/polyfill";
`;
}
return outputOptions;
banner({ format }) {
const js = format === "cjs"
? `const { Temporal } = require("@js-temporal/polyfill");`
: `import { Temporal } from "@js-temporal/polyfill";`;
return {
js,
dts: `/// <reference lib="esnext.temporal" />`,
};
},
});
19 changes: 8 additions & 11 deletions packages/testing/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ export default defineConfig({
"@fedify/vocab-runtime",
],
},
outputOptions(outputOptions, format) {
if (format === "cjs") {
outputOptions.intro = `
const { Temporal } = require("@js-temporal/polyfill");
`;
} else {
outputOptions.intro = `
import { Temporal } from "@js-temporal/polyfill";
`;
}
return outputOptions;
banner({ format }) {
const js = format === "cjs"
? `const { Temporal } = require("@js-temporal/polyfill");`
: `import { Temporal } from "@js-temporal/polyfill";`;
return {
js,
dts: `/// <reference lib="esnext.temporal" />`,
};
},
});
4 changes: 3 additions & 1 deletion packages/vocab-runtime/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"license": "MIT",
"exports": {
".": "./src/mod.ts",
"./jsonld": "./src/jsonld.ts"
"./jsonld": "./src/jsonld.ts",
"./temporal": "./src/temporal.ts"
},
"description": "Runtime library for @fedify/vocab",
"author": {
Expand All @@ -13,6 +14,7 @@
"url": "https://hongminhee.org/"
},
"imports": {
"@js-temporal/polyfill": "npm:@js-temporal/polyfill@^0.5.1",
"@multiformats/base-x": "npm:@multiformats/base-x@^4.0.1",
"asn1js": "npm:asn1js@^3.0.6",
"byte-encodings": "npm:byte-encodings@^1.0.11",
Expand Down
11 changes: 11 additions & 0 deletions packages/vocab-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
"require": "./dist/jsonld.cjs",
"default": "./dist/jsonld.js"
},
"./temporal": {
"types": {
"import": "./dist/temporal.d.ts",
"require": "./dist/temporal.d.cts",
"default": "./dist/temporal.d.ts"
},
"import": "./dist/temporal.js",
"require": "./dist/temporal.cjs",
"default": "./dist/temporal.js"
},
"./package.json": "./package.json"
},
"scripts": {
Expand Down Expand Up @@ -73,6 +83,7 @@
"typescript": "catalog:"
},
"dependencies": {
"@js-temporal/polyfill": "catalog:",
"@logtape/logtape": "catalog:",
"@multiformats/base-x": "catalog:",
"@opentelemetry/api": "catalog:",
Expand Down
71 changes: 71 additions & 0 deletions packages/vocab-runtime/src/temporal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Temporal } from "@js-temporal/polyfill";
import { strictEqual } from "node:assert";
import { test } from "node:test";
import { isTemporalDuration, isTemporalInstant } from "./temporal.ts";
Comment thread
dahlia marked this conversation as resolved.

test("isTemporalInstant() accepts polyfill instances", () => {
strictEqual(
isTemporalInstant(Temporal.Instant.from("2026-05-14T00:00:00Z")),
true,
);
});

test("isTemporalInstant() accepts spec-compliant non-polyfill objects", () => {
// Mimics the shape of a native `Temporal.Instant` from a host that does
// not share class identity with the bundled polyfill.
const nativeLike = Object.create(null, {
[Symbol.toStringTag]: { value: "Temporal.Instant" },
epochNanoseconds: { value: 0n },
});
strictEqual(isTemporalInstant(nativeLike), true);
});

test("isTemporalInstant() rejects unrelated values", () => {
strictEqual(isTemporalInstant(null), false);
strictEqual(isTemporalInstant(undefined), false);
strictEqual(isTemporalInstant("2026-05-14T00:00:00Z"), false);
strictEqual(isTemporalInstant(new Date()), false);
strictEqual(
isTemporalInstant(Temporal.Duration.from({ seconds: 1 })),
false,
);
});

test("isTemporalInstant() rejects bare objects tagged but missing shape", () => {
const decoy = Object.create(null, {
[Symbol.toStringTag]: { value: "Temporal.Instant" },
});
strictEqual(isTemporalInstant(decoy), false);
});

test("isTemporalDuration() accepts polyfill instances", () => {
strictEqual(
isTemporalDuration(Temporal.Duration.from({ hours: 1 })),
true,
);
});

test("isTemporalDuration() accepts spec-compliant non-polyfill objects", () => {
const nativeLike = Object.create(null, {
[Symbol.toStringTag]: { value: "Temporal.Duration" },
sign: { value: 0 },
});
strictEqual(isTemporalDuration(nativeLike), true);
});

test("isTemporalDuration() rejects unrelated values", () => {
strictEqual(isTemporalDuration(null), false);
strictEqual(isTemporalDuration(undefined), false);
strictEqual(isTemporalDuration("PT1H"), false);
strictEqual(
isTemporalDuration(Temporal.Instant.from("2026-05-14T00:00:00Z")),
false,
);
});

test("isTemporalDuration() rejects bare objects tagged but missing shape", () => {
const decoy = Object.create(null, {
[Symbol.toStringTag]: { value: "Temporal.Duration" },
});
strictEqual(isTemporalDuration(decoy), false);
});
Loading
Loading