fix: fix master tag type

This commit is contained in:
master 2025-03-18 02:46:18 +08:00
parent 11fdb0f2fc
commit 9a5d025f40
24 changed files with 880 additions and 905 deletions

View File

@ -1,8 +1,6 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"extends": [
"ultracite"
],
"extends": ["ultracite"],
"linter": {
"rules": {
"style": {
@ -34,22 +32,13 @@
}
},
"files": {
"ignore": [
".vscode/*.json"
]
"ignore": [".vscode/*.json"]
},
"overrides": [
{
"include": [
"tests/**"
],
"include": ["tests/**"],
"javascript": {
"globals": [
"describe",
"beforeEach",
"it",
"expect"
]
"globals": ["describe", "beforeEach", "it", "expect"]
},
"linter": {
"rules": {

View File

@ -1,8 +1,8 @@
import fs from 'node:fs/promises';
import {
ReadableStream,
WritableStream,
type TransformStream,
WritableStream,
} from 'node:stream/web';
import { EbmlStreamDecoder } from 'konoebml';

View File

@ -1,6 +1,6 @@
{
"name": "konoebml",
"version": "0.1.0-rc.4",
"version": "0.1.0-rc.5",
"description": "A modern JavaScript implementation of EBML RFC8794",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@ -20,8 +20,8 @@
"test": "vitest --coverage",
"test-ci": "vitest --watch=false --coverage",
"prepublishOnly": "npm run build",
"lint": "ultracite lint",
"format": "ultracite format",
"lint": "biome lint",
"lint-fix": "biome lint --fix",
"playground": "tsx --tsconfig=./tsconfig.example.json ./examples/playground.ts"
},
"repository": "github:dumtruck/konoebml",

View File

@ -1,17 +1,17 @@
import { type EbmlTagIdType, isEbmlMasterTagId } from './models/enums';
import type { DecodeContentOptions, EbmlTagTrait } from './models/tag-trait';
import type { FileDataViewController } from './adapters';
import { UnreachableOrLogicError } from './errors';
import { createEbmlTag } from './factory';
import { type EbmlTagIdType, isEbmlMasterTagId } from './models/enums';
import { EbmlTagPosition } from './models/enums';
import type { DecodeContentOptions, EbmlTagTrait } from './models/tag-trait';
import {
type SafeSizeVint,
checkVintSafeSize,
dataViewSlice,
readUnsigned,
readVint,
readVintLength,
type SafeSizeVint,
} from './tools';
import { EbmlTagPosition } from './models/enums';
import { createEbmlTag } from './factory';
import { UnreachableOrLogicError } from './errors';
export async function decodeEbmlTagHeader(
controller: FileDataViewController

View File

@ -1,13 +1,13 @@
import { Queue } from 'mnemonist';
import type { FileDataViewController } from './adapters';
import { decodeEbmlContent } from './decode-utils';
import { StreamFlushReason, UnreachableOrLogicError } from './errors';
import type { EbmlTagType } from './models/tag';
import type {
DecodeContentCollectChildPredicate,
EbmlTagTrait,
} from './models/tag-trait';
import { decodeEbmlContent } from './decode-utils';
import { StreamFlushReason, UnreachableOrLogicError } from './errors';
import { dataViewSlice } from './tools';
import type { EbmlTagType } from './models/tag';
export type EbmlStreamDecoderChunkType =
| Uint8Array

View File

@ -1,9 +1,9 @@
import { Queue, Stack } from 'mnemonist';
import { EbmlTagTrait } from './models/tag-trait';
import { EbmlTagPosition } from './models/enums';
import { EbmlMasterTag } from './models/tag-master';
import { EbmlTreeMasterNotMatchError, UnreachableOrLogicError } from './errors';
import { EbmlTagPosition } from './models/enums';
import type { EbmlTagType } from './models/tag';
import { EbmlMasterTag } from './models/tag-master';
import { EbmlTagTrait } from './models/tag-trait';
export class EbmlEncodeStreamTransformer
implements Transformer<EbmlTagTrait | EbmlTagType, Uint8Array>

View File

@ -1,21 +1,21 @@
import { InconsistentWellKnownEbmlTagTypeError } from './errors';
import {
type EbmlMasterTagIdType,
type EbmlDataTagIdType,
type EbmlBlockTagIdType,
type EbmlSimpleBlockTagIdType,
type EbmlDataTagIdType,
EbmlElementType,
type EbmlMasterTagIdType,
type EbmlSimpleBlockTagIdType,
EbmlTagIdEnum,
isEbmlBlockTagId,
isEbmlSimpleBlockTagId,
isEbmlMasterTagId,
isEbmlUintDataTagId,
isEbmlIntDataTagId,
isEbmlFloatDataTagId,
isEbmlStringDataTagId,
isEbmlUtf8DataTagId,
isEbmlDateDataTagId,
isEbmlBinaryDataTagId,
isEbmlBlockTagId,
isEbmlDateDataTagId,
isEbmlFloatDataTagId,
isEbmlIntDataTagId,
isEbmlMasterTagId,
isEbmlSimpleBlockTagId,
isEbmlStringDataTagId,
isEbmlUintDataTagId,
isEbmlUtf8DataTagId,
} from './models/enums';
import {
type CreateEbmlBlockTagOptions,

View File

@ -1,5 +1,3 @@
import { type CreateEbmlDataTagOptions, EbmlDataTag } from './tag-data';
import { EbmlBlockLacing } from './enums';
import {
dataViewSlice,
dataViewSliceToBuf,
@ -8,12 +6,14 @@ import {
writeSigned,
writeVint,
} from '../tools';
import { EbmlBlockLacing } from './enums';
import {
type EbmlBlockTagIdType,
type EbmlSimpleBlockTagIdType,
EbmlTagIdEnum,
} from './enums';
import { EbmlElementType } from './enums';
import { type CreateEbmlDataTagOptions, EbmlDataTag } from './tag-data';
import type { DecodeContentOptions } from './tag-trait';
export interface CreateEbmlBlockTagOptions

View File

@ -1,9 +1,3 @@
import {
type CreateEbmlTagOptions,
type DecodeContentOptions,
EbmlTagTrait,
} from './tag-trait';
import { EbmlElementType } from './enums';
import {
dataViewSliceToBuf,
readAscii,
@ -17,7 +11,13 @@ import {
writeUnsigned,
writeUtf8,
} from '../tools';
import { EbmlElementType } from './enums';
import { EbmlTagPosition } from './enums';
import {
type CreateEbmlTagOptions,
type DecodeContentOptions,
EbmlTagTrait,
} from './tag-trait';
export type CreateEbmlDataTagOptions = Omit<CreateEbmlTagOptions, 'position'>;

View File

@ -1,12 +1,12 @@
import { createEbmlTag } from 'src/factory';
import { decodeEbmlTagHeader } from '../decode-utils';
import { EbmlElementType, EbmlTagPosition, isEbmlMasterTagId } from './enums';
import type { EbmlMasterTagIdType } from './enums';
import {
type CreateEbmlTagOptions,
type DecodeContentOptions,
EbmlTagTrait,
} from './tag-trait';
import { EbmlElementType, EbmlTagPosition, isEbmlMasterTagId } from './enums';
import { decodeEbmlTagHeader } from '../decode-utils';
import { createEbmlTag } from 'src/factory';
import type { EbmlMasterTagIdType } from './enums';
export interface CreateEbmlMasterTagOptions
extends Omit<CreateEbmlTagOptions, 'position' | 'type' | 'id'> {

View File

@ -1,6 +1,6 @@
import { readVint } from '../tools';
import { type CreateEbmlBlockTagOptions, EbmlBlockTag } from './tag-block';
import type { EbmlSimpleBlockTagIdType } from './enums';
import { type CreateEbmlBlockTagOptions, EbmlBlockTag } from './tag-block';
import type { DecodeContentOptions } from './tag-trait';
export interface CreateEbmlSimpleBlockTagOptions

View File

@ -1,9 +1,9 @@
import type { FileDataViewController } from '../adapters';
import { InconsistentOffsetOnDecodingContentError } from '../errors';
import { UNKNOWN_SIZE_VINT_BUF, hexStringToBuf, writeVint } from '../tools';
import { EbmlTagPosition } from './enums';
import { EbmlTagIdEnum, type EbmlTagIdType } from './enums';
import type { EbmlElementType } from './enums';
import { hexStringToBuf, UNKNOWN_SIZE_VINT_BUF, writeVint } from '../tools';
import type { FileDataViewController } from '../adapters';
import { InconsistentOffsetOnDecodingContentError } from '../errors';
import type { EbmlMasterTag } from './tag-master';
export interface CreateEbmlTagOptions {

View File

@ -23,7 +23,8 @@ export type EbmlTagExcludeField =
| 'position'
| 'parent'
| 'type'
| 'data';
| 'data'
| 'children';
export type EbmlUintTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
id: EbmlUintDataTagIdType;
@ -31,6 +32,7 @@ export type EbmlUintTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type: EbmlElementType.UnsignedInt;
data: number | bigint;
children?: [];
};
export type EbmlIntTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
@ -39,6 +41,7 @@ export type EbmlIntTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type: EbmlElementType.Integer;
data: number | bigint;
children?: [];
};
export type EbmlUtf8TagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
@ -47,6 +50,7 @@ export type EbmlUtf8TagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type: EbmlElementType.UTF8;
data: string;
children?: [];
};
export type EbmlAsciiTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
@ -55,6 +59,7 @@ export type EbmlAsciiTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type: EbmlElementType.Ascii;
data: string;
children?: [];
};
export type EbmlDateTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
@ -63,6 +68,7 @@ export type EbmlDateTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type: EbmlElementType.Date;
data: Uint8Array;
children?: [];
};
export type EbmlFloatTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
@ -71,6 +77,7 @@ export type EbmlFloatTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type: EbmlElementType.Float;
data: number;
children?: [];
};
export type EbmlBinaryTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
@ -79,6 +86,7 @@ export type EbmlBinaryTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type: EbmlElementType.Binary;
data: Uint8Array;
children?: [];
};
export type EbmlUnknownTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
@ -87,6 +95,7 @@ export type EbmlUnknownTagType = Omit<EbmlDataTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type?: undefined;
data: Uint8Array;
children?: [];
};
export type EbmlDataTagType =
@ -104,6 +113,7 @@ export type EbmlBlockTagType = Omit<EbmlBlockTag, EbmlTagExcludeField> & {
parent?: EbmlMasterTag;
type?: undefined;
data?: undefined;
children?: [];
};
export type EbmlSimpleBlockTagType = Omit<
@ -115,6 +125,7 @@ export type EbmlSimpleBlockTagType = Omit<
parent?: EbmlMasterTag;
type?: undefined;
data?: undefined;
children?: [];
};
export type EbmlMasterTagType = Omit<EbmlMasterTag, EbmlTagExcludeField> & {

View File

@ -1,13 +1,13 @@
import {
VintOutOfRangeError,
VintLengthOutOfRangeError,
ElementIdVintDataAllOnesError,
ElementIdVintDataAllZerosError,
ElementIdVintDataNotShortestError,
UnsupportLengthForElementTypeError,
OutOfRangeForElementTypeError,
SizeUnitOutOfSafeIntegerRangeError,
UnreachableOrLogicError,
UnsupportLengthForElementTypeError,
VintLengthOutOfRangeError,
VintOutOfRangeError,
} from './errors';
import {
EbmlElementType,

View File

@ -1,11 +1,11 @@
import { assert, describe, it } from 'vitest';
import {
EbmlTagPosition,
EbmlElementType,
EbmlStreamDecoder as Decoder,
EbmlDataTag,
EbmlElementType,
EbmlTagPosition,
type EbmlTagType,
} from 'konoebml';
import { assert, describe, it } from 'vitest';
const bufFrom = (data: Uint8Array | readonly number[]): ArrayBuffer =>
new Uint8Array(data).buffer;

View File

@ -1,11 +1,11 @@
import { assert, expect, describe, it } from 'vitest';
import {
EbmlStreamEncoder,
EbmlTagIdEnum,
EbmlTagPosition,
type EbmlTagTrait,
EbmlTagIdEnum,
createEbmlTagForManuallyBuild,
EbmlStreamEncoder,
} from 'konoebml';
import { assert, describe, expect, it } from 'vitest';
const invalidTag: EbmlTagTrait = <EbmlTagTrait>(<any>{
id: undefined,

View File

@ -1,14 +1,14 @@
import { assert, describe, it, expect } from 'vitest';
import {
type EbmlBlockTag,
EbmlStreamDecoder,
EbmlStreamEncoder,
type EbmlTagTrait,
EbmlTagIdEnum,
type EbmlBlockTag,
createEbmlTagForManuallyBuild,
type EbmlTagTrait,
type EbmlTagType,
createEbmlTagForManuallyBuild,
} from 'konoebml';
import { concatArrayBuffers } from 'konoebml/tools';
import { assert, describe, expect, it } from 'vitest';
describe('EBML Pipeline', () => {
async function assertPipelineOutputEquals(

View File

@ -1,4 +1,3 @@
import { assert, describe, it } from 'vitest';
import {
readAscii,
readElementIdVint,
@ -9,6 +8,7 @@ import {
readVint,
writeVint,
} from 'konoebml/tools';
import { assert, describe, it } from 'vitest';
function bufFrom(data: Uint8Array | readonly number[]): Uint8Array {
return new Uint8Array(data);

View File

@ -1,14 +1,14 @@
import fs from 'node:fs';
import { assert, describe, it } from 'vitest';
import {
EbmlStreamDecoder,
EbmlTagIdEnum,
EbmlSimpleBlockTag as SimpleBlock,
EbmlDataTag,
type EbmlTagType,
} from 'konoebml';
import { Readable } from 'node:stream';
import { WritableStream } from 'node:stream/web';
import {
EbmlDataTag,
EbmlStreamDecoder,
EbmlTagIdEnum,
type EbmlTagType,
EbmlSimpleBlockTag as SimpleBlock,
} from 'konoebml';
import { assert, describe, it } from 'vitest';
process.setMaxListeners(Number.POSITIVE_INFINITY);

View File

@ -10,10 +10,6 @@
"moduleResolution": "bundler",
"target": "ES2021",
"module": "ESNext",
"lib": [
"ES2021",
"DOM",
"DOM.Iterable"
]
"lib": ["ES2021", "DOM", "DOM.Iterable"]
}
}

View File

@ -3,23 +3,15 @@
"compilerOptions": {
"composite": true,
"rootDir": ".",
"types": [
"node"
],
"types": ["node"],
"noEmit": true,
"paths": {
"konoebml": [
"./src/index.ts"
],
"konoebml/*": [
"./src/*"
]
"konoebml": ["./src/index.ts"],
"konoebml/*": ["./src/*"]
}
},
"files": [],
"include": [
"examples/*"
],
"include": ["examples/*"],
"references": [
{
"path": "./tsconfig.lib.json"

View File

@ -2,9 +2,7 @@
"extends": "./tsconfig.base.json",
"files": [],
"include": [],
"exclude": [
"node_modules"
],
"exclude": ["node_modules"],
"references": [
{
"path": "./tsconfig.lib.json"

View File

@ -10,8 +10,6 @@
"declarationMap": true,
"emitDeclarationOnly": true
},
"include": [
"src"
],
"include": ["src"],
"exclude": []
}

View File

@ -3,24 +3,15 @@
"compilerOptions": {
"composite": true,
"rootDir": ".",
"types": [
"vitest/globals",
"node"
],
"types": ["vitest/globals", "node"],
"noEmit": true,
"paths": {
"konoebml": [
"./src/index.ts"
],
"konoebml/*": [
"./src/*"
]
"konoebml": ["./src/index.ts"],
"konoebml/*": ["./src/*"]
}
},
"files": [],
"include": [
"tests/*"
],
"include": ["tests/*"],
"references": [
{
"path": "./tsconfig.lib.json"