@hoardodile/sdk-types 0.0.0
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/LICENSE +18 -0
- package/README.md +59 -0
- package/dist/image-variant.d.ts +90 -0
- package/dist/image-variant.js +115 -0
- package/dist/image-variant.js.map +1 -0
- package/dist/index.d.ts +772 -0
- package/dist/index.js +353 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest-Dk6_xyNy.d.ts +204 -0
- package/dist/media-exts.d.ts +92 -0
- package/dist/media-exts.js +160 -0
- package/dist/media-exts.js.map +1 -0
- package/dist/plugin-asset-limits.d.ts +16 -0
- package/dist/plugin-asset-limits.js +13 -0
- package/dist/plugin-asset-limits.js.map +1 -0
- package/dist/plugin-capabilities.d.ts +64 -0
- package/dist/plugin-capabilities.js +37 -0
- package/dist/plugin-capabilities.js.map +1 -0
- package/dist/plugin.d.ts +49 -0
- package/dist/plugin.js +12 -0
- package/dist/plugin.js.map +1 -0
- package/dist/resource.d.ts +26 -0
- package/dist/resource.js +9 -0
- package/dist/resource.js.map +1 -0
- package/dist/result.d.ts +47 -0
- package/dist/result.js +20 -0
- package/dist/result.js.map +1 -0
- package/dist/schema.d.ts +29 -0
- package/dist/schema.js +124 -0
- package/dist/schema.js.map +1 -0
- package/dist/template.d.ts +67 -0
- package/dist/template.js +137 -0
- package/dist/template.js.map +1 -0
- package/dist/text-limits.d.ts +11 -0
- package/dist/text-limits.js +7 -0
- package/dist/text-limits.js.map +1 -0
- package/package.json +102 -0
- package/src/file-list.ts +14 -0
- package/src/image-variant.test.ts +140 -0
- package/src/image-variant.ts +234 -0
- package/src/index.ts +115 -0
- package/src/manifest.ts +186 -0
- package/src/media-exts.ts +245 -0
- package/src/plugin-asset-limits.ts +23 -0
- package/src/plugin-asset.ts +127 -0
- package/src/plugin-capabilities.ts +91 -0
- package/src/plugin-definition.test.ts +117 -0
- package/src/plugin-definition.ts +902 -0
- package/src/plugin.ts +54 -0
- package/src/read-range.ts +12 -0
- package/src/resource.ts +28 -0
- package/src/result.test.ts +64 -0
- package/src/result.ts +73 -0
- package/src/schema.ts +29 -0
- package/src/template.test.ts +116 -0
- package/src/template.ts +199 -0
- package/src/text-limits.ts +11 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { describe, expect, expectTypeOf, test } from "vitest"
|
|
2
|
+
import type { Detection, FileType } from "./plugin-definition.ts"
|
|
3
|
+
import { createResourceAPIFixture } from "./plugin-definition.ts"
|
|
4
|
+
|
|
5
|
+
const JPEG: FileType = {
|
|
6
|
+
mime: "image/jpeg",
|
|
7
|
+
ext: ".jpg",
|
|
8
|
+
kind: "image",
|
|
9
|
+
source: "magic",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const PNG: FileType = {
|
|
13
|
+
mime: "image/png",
|
|
14
|
+
ext: ".png",
|
|
15
|
+
kind: "image",
|
|
16
|
+
source: "magic",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe("createResourceAPIFixture path matching", () => {
|
|
20
|
+
test("an exact key beats the empty-key default", async () => {
|
|
21
|
+
const { api } = createResourceAPIFixture({
|
|
22
|
+
files: ["a.jpg", "b.png"],
|
|
23
|
+
types: { "a.jpg": JPEG, "": PNG },
|
|
24
|
+
})
|
|
25
|
+
await expect(api.sniff("a.jpg")).resolves.toEqual(JPEG)
|
|
26
|
+
await expect(api.sniff("b.png")).resolves.toEqual(PNG)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test("dot keys match any path by extension suffix", async () => {
|
|
30
|
+
const { api } = createResourceAPIFixture({
|
|
31
|
+
files: ["01.mp4", "02.mp3", "03.webp"],
|
|
32
|
+
types: {
|
|
33
|
+
".mp4": JPEG,
|
|
34
|
+
"": PNG,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
await expect(api.sniff("01.mp4")).resolves.toEqual(JPEG)
|
|
38
|
+
await expect(api.sniff("02.mp3")).resolves.toEqual(PNG)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test("the longest dot key wins over shorter fragments", async () => {
|
|
42
|
+
const { api } = createResourceAPIFixture({
|
|
43
|
+
files: ["a.webp"],
|
|
44
|
+
types: {
|
|
45
|
+
".webp": PNG,
|
|
46
|
+
p: JPEG,
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
// "p" does not start with a dot, so only ".webp" qualifies.
|
|
50
|
+
await expect(api.sniff("a.webp")).resolves.toEqual(PNG)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test("plain-name keys never hijack paths that merely contain them", async () => {
|
|
54
|
+
const { api } = createResourceAPIFixture({
|
|
55
|
+
files: ["a.jpg", "ba.jpg"],
|
|
56
|
+
types: { "a.jpg": JPEG, "": PNG },
|
|
57
|
+
})
|
|
58
|
+
// "ba.jpg" contains "a.jpg" — the plain-name key must keep it on
|
|
59
|
+
// the default instead of hijacking the a.jpg config.
|
|
60
|
+
await expect(api.sniff("ba.jpg")).resolves.toEqual(PNG)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test("probes follow the same rules", async () => {
|
|
64
|
+
const { api } = createResourceAPIFixture({
|
|
65
|
+
files: ["01.mp4", "02.mp3"],
|
|
66
|
+
probes: {
|
|
67
|
+
".mp4": { kind: "video", mime: "video/mp4", width: 640, height: 480 },
|
|
68
|
+
"": { kind: "unknown", reason: "unavailable" },
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
await expect(api.probe("01.mp4")).resolves.toMatchObject({ kind: "video" })
|
|
72
|
+
await expect(api.probe("02.mp3")).resolves.toEqual({
|
|
73
|
+
kind: "unknown",
|
|
74
|
+
reason: "unavailable",
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test("stats prefer the exact key", async () => {
|
|
79
|
+
const { api } = createResourceAPIFixture({
|
|
80
|
+
files: ["a.jpg", "b.png"],
|
|
81
|
+
stats: { "a.jpg": { sizeBytes: 10 }, "": { sizeBytes: 99 } },
|
|
82
|
+
})
|
|
83
|
+
await expect(api.statFile("a.jpg")).resolves.toEqual({ sizeBytes: 10 })
|
|
84
|
+
await expect(api.statFile("b.png")).resolves.toEqual({ sizeBytes: 99 })
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test("context config is exposed as api.context.detect", async () => {
|
|
88
|
+
const { api } = createResourceAPIFixture({
|
|
89
|
+
files: ["a.jpg"],
|
|
90
|
+
context: { detect: { shape: "archive" } },
|
|
91
|
+
})
|
|
92
|
+
expect(api.context.detect).toEqual({ shape: "archive" })
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test("context defaults to an absent detect payload", async () => {
|
|
96
|
+
const { api } = createResourceAPIFixture({ files: ["a.jpg"] })
|
|
97
|
+
expect(api.context.detect).toBeUndefined()
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
describe("Detection type linkage", () => {
|
|
102
|
+
type Shape = { readonly kind: "pages" | "archive" }
|
|
103
|
+
|
|
104
|
+
test("a match carrying the declared shape satisfies the slot type", () => {
|
|
105
|
+
expectTypeOf<{ ok: true; kind: "archive" }>().toMatchTypeOf<
|
|
106
|
+
Detection<Shape>
|
|
107
|
+
>()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test("a payload-less match no longer satisfies a declared shape", () => {
|
|
111
|
+
expectTypeOf<{ ok: true }>().not.toMatchTypeOf<Detection<Shape>>()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test("the bare Detection stays payload-agnostic", () => {
|
|
115
|
+
expectTypeOf<{ ok: true }>().toMatchTypeOf<Detection>()
|
|
116
|
+
})
|
|
117
|
+
})
|