@axiumine/koa-utils 9.1.0 → 9.2.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/README.md +10 -10
- package/dist/files/GLB_POLICY_DEFAULTS.d.mts +49 -0
- package/dist/files/GLB_POLICY_DEFAULTS.mjs +45 -0
- package/dist/files/GLB_REJECT_CODES.d.mts +29 -0
- package/dist/files/GLB_REJECT_CODES.mjs +51 -0
- package/dist/files/IGlbContainer.d.mts +12 -0
- package/dist/files/IGlbContainer.mjs +2 -0
- package/dist/files/IGlbSanitiseResult.d.mts +56 -0
- package/dist/files/IGlbSanitiseResult.mjs +2 -0
- package/dist/files/checkGlbContainer.d.mts +11 -0
- package/dist/files/checkGlbContainer.mjs +68 -0
- package/dist/files/sanitiseGlb.d.mts +22 -0
- package/dist/files/sanitiseGlb.mjs +66 -0
- package/dist/files/sanitiseGlbFile.d.mts +16 -0
- package/dist/files/sanitiseGlbFile.mjs +36 -0
- package/dist/files/validateGlbExtension.d.mts +1 -0
- package/dist/files/validateGlbExtension.mjs +9 -0
- package/dist/files/validateMimeTypeGlb.d.mts +5 -0
- package/dist/files/validateMimeTypeGlb.mjs +9 -0
- package/dist/private/glb/IImageSize.d.mts +5 -0
- package/dist/private/glb/IImageSize.mjs +2 -0
- package/dist/private/glb/checkGlbCounts.d.mts +15 -0
- package/dist/private/glb/checkGlbCounts.mjs +53 -0
- package/dist/private/glb/checkGlbExtensions.d.mts +7 -0
- package/dist/private/glb/checkGlbExtensions.mjs +26 -0
- package/dist/private/glb/checkGlbGeometry.d.mts +9 -0
- package/dist/private/glb/checkGlbGeometry.mjs +56 -0
- package/dist/private/glb/checkGlbImages.d.mts +10 -0
- package/dist/private/glb/checkGlbImages.mjs +60 -0
- package/dist/private/glb/checkGlbUris.d.mts +7 -0
- package/dist/private/glb/checkGlbUris.mjs +25 -0
- package/dist/private/glb/glbExtensions.d.mts +7 -0
- package/dist/private/glb/glbExtensions.mjs +13 -0
- package/dist/private/glb/glbIo.d.mts +7 -0
- package/dist/private/glb/glbIo.mjs +16 -0
- package/dist/private/glb/glbReason.d.mts +7 -0
- package/dist/private/glb/glbReason.mjs +14 -0
- package/dist/private/glb/glbStats.d.mts +5 -0
- package/dist/private/glb/glbStats.mjs +24 -0
- package/dist/private/glb/inspectGlbJson.d.mts +8 -0
- package/dist/private/glb/inspectGlbJson.mjs +21 -0
- package/dist/private/glb/jsonAccess.d.mts +17 -0
- package/dist/private/glb/jsonAccess.mjs +24 -0
- package/dist/private/glb/parseGlbJson.d.mts +11 -0
- package/dist/private/glb/parseGlbJson.mjs +14 -0
- package/dist/private/glb/reEncodeImage.d.mts +13 -0
- package/dist/private/glb/reEncodeImage.mjs +24 -0
- package/dist/private/glb/readImageHeader.d.mts +25 -0
- package/dist/private/glb/readImageHeader.mjs +68 -0
- package/dist/private/glb/readJpegSize.d.mts +3 -0
- package/dist/private/glb/readJpegSize.mjs +27 -0
- package/dist/private/glb/readKtx2Size.d.mts +3 -0
- package/dist/private/glb/readKtx2Size.mjs +23 -0
- package/dist/private/glb/reencodeTextures.d.mts +9 -0
- package/dist/private/glb/reencodeTextures.mjs +34 -0
- package/dist/private/glb/resolveGlbPolicy.d.mts +6 -0
- package/dist/private/glb/resolveGlbPolicy.mjs +48 -0
- package/dist/private/glb/rewriteGlb.d.mts +16 -0
- package/dist/private/glb/rewriteGlb.mjs +49 -0
- package/dist/private/glb/stripExtras.d.mts +8 -0
- package/dist/private/glb/stripExtras.mjs +16 -0
- package/dist/private/glb/validateKhronos.d.mts +12 -0
- package/dist/private/glb/validateKhronos.mjs +32 -0
- package/dist/private/glb/verifyGlbOutput.d.mts +8 -0
- package/dist/private/glb/verifyGlbOutput.mjs +20 -0
- package/package.json +77 -20
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const isStartOfFrame = (marker) => marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc;
|
|
2
|
+
const hasNoLength = (marker) => marker === 0x01 || (marker >= 0xd0 && marker <= 0xd8);
|
|
3
|
+
/** Width and height from the first start-of-frame segment. Throws when the file is cut short. */
|
|
4
|
+
export function readJpeg(view) {
|
|
5
|
+
let offset = 2;
|
|
6
|
+
while (offset < view.byteLength) {
|
|
7
|
+
const marker = view.getUint8(offset + 1);
|
|
8
|
+
if (view.getUint8(offset) !== 0xff || marker === 0xd9) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (marker === 0xff) {
|
|
12
|
+
offset += 1;
|
|
13
|
+
}
|
|
14
|
+
else if (hasNoLength(marker)) {
|
|
15
|
+
offset += 2;
|
|
16
|
+
}
|
|
17
|
+
else if (isStartOfFrame(marker)) {
|
|
18
|
+
return { width: view.getUint16(offset + 7), height: view.getUint16(offset + 5) };
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// a length under 2 lands inside the length field itself, which is never 0xff, so the next pass ends the walk
|
|
22
|
+
offset += 2 + view.getUint16(offset + 2);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=readJpegSize.mjs.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const KTX2_LEVEL_INDEX = 80;
|
|
2
|
+
const KTX2_LEVEL_BYTES = 24;
|
|
3
|
+
const KTX2_MAX_LEVELS = 32;
|
|
4
|
+
/** Every level of the index (64 bit byte offset, then 64 bit byte length) must end inside the file. */
|
|
5
|
+
function ktx2LevelsFit(view, levels) {
|
|
6
|
+
const size = BigInt(view.byteLength);
|
|
7
|
+
for (let level = 0; level < levels; level++) {
|
|
8
|
+
const at = KTX2_LEVEL_INDEX + level * KTX2_LEVEL_BYTES;
|
|
9
|
+
if (view.getBigUint64(at, true) + view.getBigUint64(at + 8, true) > size) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
/** Width and height from the KTX2 header, once the level index checks out. Throws when the header is cut short. */
|
|
16
|
+
export function readKtx2(view) {
|
|
17
|
+
const levels = view.getUint32(40, true);
|
|
18
|
+
if (levels < 1 || levels > KTX2_MAX_LEVELS || !ktx2LevelsFit(view, levels)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return { width: view.getUint32(20, true), height: view.getUint32(24, true) };
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=readKtx2Size.mjs.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Document } from '@gltf-transform/core';
|
|
2
|
+
import type { IGlbPolicy } from '../../files/GLB_POLICY_DEFAULTS.mjs';
|
|
3
|
+
import type { IGlbReason, IGlbStats } from '../../files/IGlbSanitiseResult.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Decode and re-encode every PNG, JPEG and WebP texture with `sharp`, and put the new bytes in the document. A texture
|
|
6
|
+
* that does not decode is a reason, never a throw. KTX2 textures (`KHR_texture_basisu`) cannot be decoded here: their
|
|
7
|
+
* header and level index were checked before, and the bytes go through untouched. Counts into `stats.texturesReencoded`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function reencodeTextures(document: Document, policy: IGlbPolicy, stats: IGlbStats): Promise<IGlbReason[]>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { detectImageFormat } from './readImageHeader.mjs';
|
|
2
|
+
import { reEncodeImage } from './reEncodeImage.mjs';
|
|
3
|
+
async function tryReEncode(image, format, policy) {
|
|
4
|
+
try {
|
|
5
|
+
return await reEncodeImage(image, format, policy.textureQuality, policy.maxTextureSide);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Decode and re-encode every PNG, JPEG and WebP texture with `sharp`, and put the new bytes in the document. A texture
|
|
13
|
+
* that does not decode is a reason, never a throw. KTX2 textures (`KHR_texture_basisu`) cannot be decoded here: their
|
|
14
|
+
* header and level index were checked before, and the bytes go through untouched. Counts into `stats.texturesReencoded`.
|
|
15
|
+
*/
|
|
16
|
+
export async function reencodeTextures(document, policy, stats) {
|
|
17
|
+
const reasons = [];
|
|
18
|
+
for (const [position, texture] of document.getRoot().listTextures().entries()) {
|
|
19
|
+
const image = texture.getImage() ?? new Uint8Array();
|
|
20
|
+
const format = detectImageFormat(image);
|
|
21
|
+
if (format !== null && format.name === 'ktx2') {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const bytes = format === null ? null : await tryReEncode(image, format, policy);
|
|
25
|
+
if (bytes === null) {
|
|
26
|
+
reasons.push({ code: 'IMAGE_DECODE_FAILED', message: `texture ${position} could not be decoded and re-encoded` });
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
texture.setImage(bytes);
|
|
30
|
+
stats.texturesReencoded += 1;
|
|
31
|
+
}
|
|
32
|
+
return reasons;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=reencodeTextures.mjs.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type IGlbPolicy } from '../../files/GLB_POLICY_DEFAULTS.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* The defaults with the caller's options on top. Throws on misuse: an unknown option, a limit that is not a positive
|
|
4
|
+
* integer, a quality out of range, or an extension the sanitiser has no code for. A field set to `undefined` keeps its default.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveGlbPolicy(options: Partial<IGlbPolicy>): IGlbPolicy;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { GLB_POLICY_DEFAULTS } from '../../files/GLB_POLICY_DEFAULTS.mjs';
|
|
2
|
+
import { GLB_SUPPORTED_EXTENSIONS } from './glbExtensions.mjs';
|
|
3
|
+
function assertKnownKeys(options) {
|
|
4
|
+
for (const key of Object.keys(options)) {
|
|
5
|
+
if (!Object.hasOwn(GLB_POLICY_DEFAULTS, key)) {
|
|
6
|
+
throw new TypeError(`sanitiseGlb: unknown option ${key}`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const NOT_LIMITS = new Set(['allowedExtensions', 'textureQuality']);
|
|
11
|
+
function assertLimits(policy) {
|
|
12
|
+
const fields = { ...policy };
|
|
13
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
14
|
+
if (!NOT_LIMITS.has(name) && (!Number.isSafeInteger(value) || value <= 0)) {
|
|
15
|
+
throw new TypeError(`sanitiseGlb: option ${name} must be a positive integer`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function assertQuality(quality) {
|
|
20
|
+
if (!Number.isInteger(quality) || quality < 1 || quality > 100) {
|
|
21
|
+
throw new TypeError('sanitiseGlb: option textureQuality must be an integer from 1 to 100');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const isSupported = (name) => typeof name === 'string' && GLB_SUPPORTED_EXTENSIONS.includes(name);
|
|
25
|
+
function assertExtensions(allowed) {
|
|
26
|
+
if (!Array.isArray(allowed)) {
|
|
27
|
+
throw new TypeError('sanitiseGlb: option allowedExtensions must be an array of names');
|
|
28
|
+
}
|
|
29
|
+
const unsupported = allowed.filter((name) => !isSupported(name));
|
|
30
|
+
if (unsupported.length > 0) {
|
|
31
|
+
throw new RangeError(`sanitiseGlb: allowedExtensions holds names the sanitiser cannot rewrite: ${unsupported.map(String).join(', ')}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The defaults with the caller's options on top. Throws on misuse: an unknown option, a limit that is not a positive
|
|
36
|
+
* integer, a quality out of range, or an extension the sanitiser has no code for. A field set to `undefined` keeps its default.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveGlbPolicy(options) {
|
|
39
|
+
assertKnownKeys(options);
|
|
40
|
+
const given = { ...options };
|
|
41
|
+
const defined = Object.fromEntries(Object.entries(given).filter(([, value]) => value !== undefined));
|
|
42
|
+
const policy = { ...GLB_POLICY_DEFAULTS, ...defined };
|
|
43
|
+
assertLimits(policy);
|
|
44
|
+
assertQuality(policy.textureQuality);
|
|
45
|
+
assertExtensions(policy.allowedExtensions);
|
|
46
|
+
return policy;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=resolveGlbPolicy.mjs.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WebIO } from '@gltf-transform/core';
|
|
2
|
+
import type { IGlbPolicy } from '../../files/GLB_POLICY_DEFAULTS.mjs';
|
|
3
|
+
import type { IGlbReason, IGlbStats } from '../../files/IGlbSanitiseResult.mjs';
|
|
4
|
+
export type IRewriteResult = {
|
|
5
|
+
glb: Uint8Array;
|
|
6
|
+
reasons: [];
|
|
7
|
+
} | {
|
|
8
|
+
glb: null;
|
|
9
|
+
reasons: IGlbReason[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Read the file with glTF Transform (which decodes the meshopt data, so a stream that does not decode is rejected
|
|
13
|
+
* here), then write a new one: no `extras`, no extension nobody allowed, no unused data, textures re-encoded by
|
|
14
|
+
* `sharp`, one embedded buffer. Never throws on a hostile file.
|
|
15
|
+
*/
|
|
16
|
+
export declare function rewriteGlb(io: WebIO, input: Uint8Array, policy: IGlbPolicy, stats: IGlbStats): Promise<IRewriteResult>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EXTMeshoptCompression } from '@gltf-transform/extensions';
|
|
2
|
+
import { prune } from '@gltf-transform/functions';
|
|
3
|
+
import { reencodeTextures } from './reencodeTextures.mjs';
|
|
4
|
+
import { stripExtras } from './stripExtras.mjs';
|
|
5
|
+
const failed = (reasons) => ({ glb: null, reasons });
|
|
6
|
+
/** The meshopt decoder throws "Malformed buffer data: <code>" on a stream it cannot decode. */
|
|
7
|
+
const isMeshoptFailure = (error) => /malformed buffer data/i.test(String(error));
|
|
8
|
+
async function readDocument(io, input) {
|
|
9
|
+
try {
|
|
10
|
+
return { document: await io.readBinary(input) };
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
return isMeshoptFailure(error)
|
|
14
|
+
? { reason: { code: 'MESHOPT_DECODE_FAILED', message: 'the EXT_meshopt_compression data does not decode' } }
|
|
15
|
+
: { reason: { code: 'READ_FAILED', message: 'the glTF reader could not read the file' } };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A file that came in with meshopt compression goes out with it: required, and encoded again from the decoded data.
|
|
20
|
+
* Without it the geometry of a 10 MB model would grow several times over.
|
|
21
|
+
*/
|
|
22
|
+
function keepMeshopt(document) {
|
|
23
|
+
document
|
|
24
|
+
.getRoot()
|
|
25
|
+
.listExtensionsUsed()
|
|
26
|
+
.find((extension) => extension.extensionName === EXTMeshoptCompression.EXTENSION_NAME)
|
|
27
|
+
?.setRequired(true);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read the file with glTF Transform (which decodes the meshopt data, so a stream that does not decode is rejected
|
|
31
|
+
* here), then write a new one: no `extras`, no extension nobody allowed, no unused data, textures re-encoded by
|
|
32
|
+
* `sharp`, one embedded buffer. Never throws on a hostile file.
|
|
33
|
+
*/
|
|
34
|
+
export async function rewriteGlb(io, input, policy, stats) {
|
|
35
|
+
const read = await readDocument(io, input);
|
|
36
|
+
if ('reason' in read) {
|
|
37
|
+
return failed([read.reason]);
|
|
38
|
+
}
|
|
39
|
+
const { document } = read;
|
|
40
|
+
stripExtras(document);
|
|
41
|
+
await document.transform(prune({ keepLeaves: true, keepAttributes: true, keepSolidTextures: true }));
|
|
42
|
+
const reasons = await reencodeTextures(document, policy, stats);
|
|
43
|
+
if (reasons.length > 0) {
|
|
44
|
+
return failed(reasons);
|
|
45
|
+
}
|
|
46
|
+
keepMeshopt(document);
|
|
47
|
+
return { glb: await io.writeBinary(document), reasons: [] };
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=rewriteGlb.mjs.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Document } from '@gltf-transform/core';
|
|
2
|
+
/**
|
|
3
|
+
* Empty the `extras` of the root and of every property in the graph: scenes, nodes, meshes, primitives, accessors,
|
|
4
|
+
* materials, texture infos, animations, skins, cameras, buffers and the extension properties. `extras` is free-form
|
|
5
|
+
* JSON that tools and users fill with anything. The writer only reaches a property through the edge of its parent, so
|
|
6
|
+
* the children of the edges, plus the root, are every property that is written.
|
|
7
|
+
*/
|
|
8
|
+
export declare function stripExtras(document: Document): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Empty the `extras` of the root and of every property in the graph: scenes, nodes, meshes, primitives, accessors,
|
|
3
|
+
* materials, texture infos, animations, skins, cameras, buffers and the extension properties. `extras` is free-form
|
|
4
|
+
* JSON that tools and users fill with anything. The writer only reaches a property through the edge of its parent, so
|
|
5
|
+
* the children of the edges, plus the root, are every property that is written.
|
|
6
|
+
*/
|
|
7
|
+
export function stripExtras(document) {
|
|
8
|
+
const properties = new Set([document.getRoot()]);
|
|
9
|
+
for (const edge of document.getGraph().listEdges()) {
|
|
10
|
+
properties.add(edge.getChild());
|
|
11
|
+
}
|
|
12
|
+
for (const property of properties) {
|
|
13
|
+
property.setExtras({});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=stripExtras.mjs.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import validator from 'gltf-validator';
|
|
2
|
+
import type { IGlbReason } from '../../files/IGlbSanitiseResult.mjs';
|
|
3
|
+
type IValidate = typeof validator.validateBytes;
|
|
4
|
+
/**
|
|
5
|
+
* Run the Khronos glTF Validator on a whole GLB. Every error (severity 0) becomes a `VALIDATOR_ERROR` reason, up to
|
|
6
|
+
* `MAX_REASONS`. Warnings, infos and hints never reject. A crash of the validator is `VALIDATOR_FAILED`, not a throw.
|
|
7
|
+
*
|
|
8
|
+
* @param glb the whole GLB file, container and chunks
|
|
9
|
+
* @param validate the validator entry point, a parameter so a spec can make it fail
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateKhronos(glb: Uint8Array, validate?: IValidate): Promise<IGlbReason[]>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import validator from 'gltf-validator';
|
|
2
|
+
import { MAX_REASONS } from './glbReason.mjs';
|
|
3
|
+
/** Messages the validator collects before it stops. Errors come with the structure checks, so they come early. */
|
|
4
|
+
const MAX_ISSUES = 100;
|
|
5
|
+
/**
|
|
6
|
+
* Run the Khronos glTF Validator on a whole GLB. Every error (severity 0) becomes a `VALIDATOR_ERROR` reason, up to
|
|
7
|
+
* `MAX_REASONS`. Warnings, infos and hints never reject. A crash of the validator is `VALIDATOR_FAILED`, not a throw.
|
|
8
|
+
*
|
|
9
|
+
* @param glb the whole GLB file, container and chunks
|
|
10
|
+
* @param validate the validator entry point, a parameter so a spec can make it fail
|
|
11
|
+
*/
|
|
12
|
+
export async function validateKhronos(glb, validate = (bytes, options) => validator.validateBytes(bytes, options)) {
|
|
13
|
+
let issues;
|
|
14
|
+
try {
|
|
15
|
+
issues = (await validate(glb, { maxIssues: MAX_ISSUES })).issues;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return [{ code: 'VALIDATOR_FAILED', message: 'the glTF Validator crashed on the file' }];
|
|
19
|
+
}
|
|
20
|
+
const errors = issues.messages
|
|
21
|
+
.filter((issue) => issue.severity === 0)
|
|
22
|
+
.slice(0, MAX_REASONS)
|
|
23
|
+
.map((issue) => ({
|
|
24
|
+
code: 'VALIDATOR_ERROR',
|
|
25
|
+
message: `${issue.code}: ${issue.message}`,
|
|
26
|
+
...(issue.pointer === undefined ? {} : { pointer: issue.pointer })
|
|
27
|
+
}));
|
|
28
|
+
return errors.length === 0 && issues.numErrors > 0
|
|
29
|
+
? [{ code: 'VALIDATOR_ERROR', message: `the glTF Validator reported ${issues.numErrors} errors` }]
|
|
30
|
+
: errors;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=validateKhronos.mjs.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WebIO } from '@gltf-transform/core';
|
|
2
|
+
import type { IGlbReason } from '../../files/IGlbSanitiseResult.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Check the file the sanitiser wrote the way an outsider would: the Khronos validator must find no error, and glTF
|
|
5
|
+
* Transform must read it back, meshopt decoding included. Every output must decode, so a file that fails here is never
|
|
6
|
+
* returned, whatever the input looked like.
|
|
7
|
+
*/
|
|
8
|
+
export declare function verifyGlbOutput(io: WebIO, glb: Uint8Array): Promise<IGlbReason[]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { validateKhronos } from './validateKhronos.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Check the file the sanitiser wrote the way an outsider would: the Khronos validator must find no error, and glTF
|
|
4
|
+
* Transform must read it back, meshopt decoding included. Every output must decode, so a file that fails here is never
|
|
5
|
+
* returned, whatever the input looked like.
|
|
6
|
+
*/
|
|
7
|
+
export async function verifyGlbOutput(io, glb) {
|
|
8
|
+
const problems = await validateKhronos(glb);
|
|
9
|
+
if (problems.length > 0) {
|
|
10
|
+
return problems.map((problem) => ({ ...problem, code: 'OUTPUT_INVALID' }));
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
await io.readBinary(glb);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return [{ code: 'OUTPUT_INVALID', message: 'the sanitised file does not decode' }];
|
|
17
|
+
}
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=verifyGlbOutput.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiumine/koa-utils",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"description": "Koa Utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -13,16 +13,13 @@
|
|
|
13
13
|
"homepage": "https://github.com/Axiumine/koa-utils/tree/main/docs/code",
|
|
14
14
|
"license": "AGPL-3.0-or-later",
|
|
15
15
|
"author": "Giovanni Manzoni <dev@giovannimanzoni.com> (https://www.giovannimanzoni.com)",
|
|
16
|
-
"
|
|
16
|
+
"packageManager": "yarn@4.18.1+sha512.b2e1e7524f654f2749d32b4ebcb4622473cb5bcbc485df2007e12a154e50162a4d795526768bc5f5b8f81717bfd79deb2472813d86fb5ae2eb551fa9c872b08f",
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"prepare": "yarn run hooks:install && rm -rf dist && yarn run build",
|
|
22
22
|
"hooks:install": "git rev-parse --git-dir > /dev/null 2>&1 && git config core.hooksPath .githooks || true",
|
|
23
|
-
"registry:mirror": "node scripts/registry-rewrite.mjs mirror",
|
|
24
|
-
"registry:canonical": "node scripts/registry-rewrite.mjs canonical",
|
|
25
|
-
"registry:check": "node scripts/registry-rewrite.mjs check",
|
|
26
23
|
"build": "yarn clean && yarn run build:esm",
|
|
27
24
|
"prepare:all": "echo 'read REAMDE' && rm -rf dist && yarn run build:all",
|
|
28
25
|
"build:all": "yarn run build:cjs && yarn run build:esm",
|
|
@@ -51,12 +48,11 @@
|
|
|
51
48
|
"test:coverage": "yarn build && yarn build:tests && c8 mocha",
|
|
52
49
|
"qodana": "yarn test:coverage && mkdir -p .qodana/results && docker run --rm --env-file .env -v \"$PWD\":/data/project -v \"$PWD\"/.qodana/results:/data/results jetbrains/qodana-js:2026.2 --show-report",
|
|
53
50
|
"qodana:cli": "yarn test:coverage && set -a && . ./.env && set +a && qodana scan --show-report",
|
|
54
|
-
"reindex": "node .gitnexus/run.cjs analyze --no-stats",
|
|
55
51
|
"semgrep": "./scripts/semgrep.sh",
|
|
56
52
|
"semgrep:all": "./scripts/semgrep.sh --registry",
|
|
57
53
|
"semgrep:canary": "./scripts/semgrep-canary.sh",
|
|
58
54
|
"upload": "npm publish --registry=https://registry.npmjs.org/",
|
|
59
|
-
"update": "yarn upgrade-interactive
|
|
55
|
+
"update": "yarn upgrade-interactive",
|
|
60
56
|
"cloc": "cloc . --exclude-dir=node_modules,dist,.git,upload",
|
|
61
57
|
"scc": "scc . --exclude-dir=node_modules,dist,.git -w --sort --directory-walker-job-workers=8 --count-as=mts:TypeScript"
|
|
62
58
|
},
|
|
@@ -210,6 +206,42 @@
|
|
|
210
206
|
"import": "./dist/files/validatePdfExtension.mjs",
|
|
211
207
|
"types": "./dist/files/validatePdfExtension.d.mts"
|
|
212
208
|
},
|
|
209
|
+
"./files/validateGlbExtension": {
|
|
210
|
+
"import": "./dist/files/validateGlbExtension.mjs",
|
|
211
|
+
"types": "./dist/files/validateGlbExtension.d.mts"
|
|
212
|
+
},
|
|
213
|
+
"./files/validateMimeTypeGlb": {
|
|
214
|
+
"import": "./dist/files/validateMimeTypeGlb.mjs",
|
|
215
|
+
"types": "./dist/files/validateMimeTypeGlb.d.mts"
|
|
216
|
+
},
|
|
217
|
+
"./files/checkGlbContainer": {
|
|
218
|
+
"import": "./dist/files/checkGlbContainer.mjs",
|
|
219
|
+
"types": "./dist/files/checkGlbContainer.d.mts"
|
|
220
|
+
},
|
|
221
|
+
"./files/sanitiseGlb": {
|
|
222
|
+
"import": "./dist/files/sanitiseGlb.mjs",
|
|
223
|
+
"types": "./dist/files/sanitiseGlb.d.mts"
|
|
224
|
+
},
|
|
225
|
+
"./files/sanitiseGlbFile": {
|
|
226
|
+
"import": "./dist/files/sanitiseGlbFile.mjs",
|
|
227
|
+
"types": "./dist/files/sanitiseGlbFile.d.mts"
|
|
228
|
+
},
|
|
229
|
+
"./files/GLB_POLICY_DEFAULTS": {
|
|
230
|
+
"import": "./dist/files/GLB_POLICY_DEFAULTS.mjs",
|
|
231
|
+
"types": "./dist/files/GLB_POLICY_DEFAULTS.d.mts"
|
|
232
|
+
},
|
|
233
|
+
"./files/GLB_REJECT_CODES": {
|
|
234
|
+
"import": "./dist/files/GLB_REJECT_CODES.mjs",
|
|
235
|
+
"types": "./dist/files/GLB_REJECT_CODES.d.mts"
|
|
236
|
+
},
|
|
237
|
+
"./files/IGlbSanitiseResult": {
|
|
238
|
+
"import": "./dist/files/IGlbSanitiseResult.mjs",
|
|
239
|
+
"types": "./dist/files/IGlbSanitiseResult.d.mts"
|
|
240
|
+
},
|
|
241
|
+
"./files/IGlbContainer": {
|
|
242
|
+
"import": "./dist/files/IGlbContainer.mjs",
|
|
243
|
+
"types": "./dist/files/IGlbContainer.d.mts"
|
|
244
|
+
},
|
|
213
245
|
"./graphQL/schema/types/MidNameType": {
|
|
214
246
|
"import": "./dist/graphQL/schema/types/MidNameType.mjs",
|
|
215
247
|
"types": "./dist/graphQL/schema/types/MidNameType.d.mts"
|
|
@@ -1216,8 +1248,10 @@
|
|
|
1216
1248
|
"!dist/**/*.mjs.map",
|
|
1217
1249
|
"!dist/**/*.js.map"
|
|
1218
1250
|
],
|
|
1219
|
-
"dependencies": {},
|
|
1220
1251
|
"peerDependencies": {
|
|
1252
|
+
"@gltf-transform/core": "<5",
|
|
1253
|
+
"@gltf-transform/extensions": "<5",
|
|
1254
|
+
"@gltf-transform/functions": "<5",
|
|
1221
1255
|
"@node-rs/bcrypt": "<2",
|
|
1222
1256
|
"@sentry/node": "<11",
|
|
1223
1257
|
"@socketlabs/email": "<2",
|
|
@@ -1225,10 +1259,12 @@
|
|
|
1225
1259
|
"dotenv": "<18",
|
|
1226
1260
|
"file-type": "<23",
|
|
1227
1261
|
"fs-extra": "<12",
|
|
1262
|
+
"gltf-validator": ">=2.0.0-0 <3",
|
|
1228
1263
|
"graphql": "<18",
|
|
1229
1264
|
"keygrip": "^1.1.0",
|
|
1230
1265
|
"koa": "<4",
|
|
1231
1266
|
"mariadb": "<4",
|
|
1267
|
+
"meshoptimizer": "<2",
|
|
1232
1268
|
"mongoose": "<10",
|
|
1233
1269
|
"pg": "<9",
|
|
1234
1270
|
"redis": "<7",
|
|
@@ -1238,6 +1274,15 @@
|
|
|
1238
1274
|
"sharp": "<1"
|
|
1239
1275
|
},
|
|
1240
1276
|
"peerDependenciesMeta": {
|
|
1277
|
+
"@gltf-transform/core": {
|
|
1278
|
+
"optional": true
|
|
1279
|
+
},
|
|
1280
|
+
"@gltf-transform/extensions": {
|
|
1281
|
+
"optional": true
|
|
1282
|
+
},
|
|
1283
|
+
"@gltf-transform/functions": {
|
|
1284
|
+
"optional": true
|
|
1285
|
+
},
|
|
1241
1286
|
"@node-rs/bcrypt": {
|
|
1242
1287
|
"optional": true
|
|
1243
1288
|
},
|
|
@@ -1259,6 +1304,9 @@
|
|
|
1259
1304
|
"fs-extra": {
|
|
1260
1305
|
"optional": true
|
|
1261
1306
|
},
|
|
1307
|
+
"gltf-validator": {
|
|
1308
|
+
"optional": true
|
|
1309
|
+
},
|
|
1262
1310
|
"graphql": {
|
|
1263
1311
|
"optional": true
|
|
1264
1312
|
},
|
|
@@ -1271,6 +1319,9 @@
|
|
|
1271
1319
|
"mariadb": {
|
|
1272
1320
|
"optional": true
|
|
1273
1321
|
},
|
|
1322
|
+
"meshoptimizer": {
|
|
1323
|
+
"optional": true
|
|
1324
|
+
},
|
|
1274
1325
|
"mongoose": {
|
|
1275
1326
|
"optional": true
|
|
1276
1327
|
},
|
|
@@ -1298,6 +1349,9 @@
|
|
|
1298
1349
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.8.1",
|
|
1299
1350
|
"@eslint/eslintrc": "^3.3.7",
|
|
1300
1351
|
"@eslint/js": "^10.0.1",
|
|
1352
|
+
"@gltf-transform/core": "^4.5.1",
|
|
1353
|
+
"@gltf-transform/extensions": "^4.5.1",
|
|
1354
|
+
"@gltf-transform/functions": "^4.5.1",
|
|
1301
1355
|
"@node-rs/bcrypt": "^1.10.9",
|
|
1302
1356
|
"@sentry/node": "^10.78.0",
|
|
1303
1357
|
"@socketlabs/email": "^1.4.4",
|
|
@@ -1318,7 +1372,7 @@
|
|
|
1318
1372
|
"chai": "^6.3.0",
|
|
1319
1373
|
"clamscan": "^2.4.0",
|
|
1320
1374
|
"dotenv": "^17.4.2",
|
|
1321
|
-
"eslint": "^10.
|
|
1375
|
+
"eslint": "^10.14.0",
|
|
1322
1376
|
"eslint-config-prettier": "^10.1.8",
|
|
1323
1377
|
"eslint-import-resolver-typescript": "^4.4.5",
|
|
1324
1378
|
"eslint-plugin-n": "^18.5.0",
|
|
@@ -1327,16 +1381,19 @@
|
|
|
1327
1381
|
"eslint-plugin-simple-import-sort": "^14.0.0",
|
|
1328
1382
|
"eslint-plugin-sonarjs": "^4.2.2",
|
|
1329
1383
|
"fast-check": "^4.10.2",
|
|
1330
|
-
"file-type": "^22.
|
|
1384
|
+
"file-type": "^22.3.0",
|
|
1331
1385
|
"fs-extra": "^11.4.1",
|
|
1332
1386
|
"fta-cli": "^3.1.0",
|
|
1333
|
-
"
|
|
1334
|
-
"
|
|
1335
|
-
"
|
|
1336
|
-
"
|
|
1387
|
+
"gltf-validator": "^2.0.0-dev.3.10",
|
|
1388
|
+
"graphql": "^16.15.0",
|
|
1389
|
+
"keygrip": "^1.1.0",
|
|
1390
|
+
"knip": "^6.44.2",
|
|
1391
|
+
"koa": "^3.3.0",
|
|
1392
|
+
"mariadb": "^3.5.5",
|
|
1393
|
+
"meshoptimizer": "^1.3.0",
|
|
1337
1394
|
"mocha": "^12.0.3",
|
|
1338
1395
|
"mongodb-memory-server": "^11.3.0",
|
|
1339
|
-
"mongoose": "^9.
|
|
1396
|
+
"mongoose": "^9.12.1",
|
|
1340
1397
|
"patch-package": "8.0.1",
|
|
1341
1398
|
"pg": "^8.23.1",
|
|
1342
1399
|
"prettier": "^3.9.10",
|
|
@@ -1348,17 +1405,17 @@
|
|
|
1348
1405
|
"sinon": "^22.1.0",
|
|
1349
1406
|
"ts-node": "^10.9.2",
|
|
1350
1407
|
"ts-patch": "^4.0.1",
|
|
1351
|
-
"type-coverage": "^2.
|
|
1408
|
+
"type-coverage": "^2.31.2",
|
|
1352
1409
|
"typescript": "^6.0.3",
|
|
1353
|
-
"typescript-eslint": "8.72.
|
|
1410
|
+
"typescript-eslint": "8.72.2",
|
|
1354
1411
|
"typescript-transform-paths": "^4.0.0",
|
|
1355
1412
|
"uuid": "^14.0.3"
|
|
1356
1413
|
},
|
|
1357
1414
|
"resolutions": {
|
|
1358
1415
|
"@socketlabs/email/axios": "^1.21.0",
|
|
1359
1416
|
"sequelize/uuid": "^11.1.1",
|
|
1360
|
-
"
|
|
1361
|
-
"
|
|
1362
|
-
"
|
|
1417
|
+
"typed-rest-client/qs": "^6.16.1",
|
|
1418
|
+
"glob": "^14.0.2",
|
|
1419
|
+
"minimatch": "^11.0.3"
|
|
1363
1420
|
}
|
|
1364
1421
|
}
|