feat: convert to Node.js compatible ES Module

This commit is contained in:
Simon Chan 2022-03-15 16:53:07 +08:00
parent 730aac8da2
commit d9212b4dac
No known key found for this signature in database
GPG key ID: 8F75717685A974FB
94 changed files with 429 additions and 466 deletions

View file

@ -42,6 +42,6 @@
"@types/react": "17.0.27",
"eslint": "8.8.0",
"eslint-config-next": "12.1.0",
"typescript": "^4.6.2"
"typescript": "next"
}
}

View file

@ -23,7 +23,7 @@
},
"license": "MIT",
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -31,7 +31,7 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"typescript": "^4.6.2",
"typescript": "next",
"@types/jest": "^27.4.0",
"@yume-chan/ts-package-builder": "^1.0.0"
},

View file

@ -22,7 +22,7 @@
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -37,7 +37,7 @@
},
"devDependencies": {
"jest": "^26.6.3",
"typescript": "^4.6.2",
"typescript": "next",
"@yume-chan/ts-package-builder": "^1.0.0"
}
}

View file

@ -1,3 +1,3 @@
export * from './backend';
export { AdbWebUsbBackend as default } from './backend';
export * from './watcher';
export * from './backend.js';
export { AdbWebUsbBackend as default } from './backend.js';
export * from './watcher.js';

View file

@ -23,7 +23,7 @@
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -31,7 +31,7 @@
},
"devDependencies": {
"jest": "^26.6.3",
"typescript": "^4.6.2",
"typescript": "next",
"@yume-chan/ts-package-builder": "^1.0.0"
},
"dependencies": {

View file

@ -21,7 +21,7 @@
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -29,7 +29,7 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"typescript": "^4.6.2",
"typescript": "next",
"@yume-chan/ts-package-builder": "^1.0.0"
},
"dependencies": {

View file

@ -22,7 +22,7 @@
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -39,7 +39,7 @@
},
"devDependencies": {
"jest": "^26.6.3",
"typescript": "^4.6.2",
"typescript": "next",
"@yume-chan/ts-package-builder": "^1.0.0"
}
}

View file

@ -1,11 +1,11 @@
import { PromiseResolver } from '@yume-chan/async';
import { AdbAuthenticationHandler, AdbDefaultAuthenticators, type AdbCredentialStore } from './auth';
import { AdbPower, AdbReverseCommand, AdbSubprocess, AdbSync, AdbTcpIpCommand, escapeArg, framebuffer, install, type AdbFrameBuffer } from './commands';
import { AdbFeatures } from './features';
import { AdbCommand, AdbPacket, AdbPacketSerializeStream, calculateChecksum, type AdbPacketCore, type AdbPacketInit } from './packet';
import { AdbPacketDispatcher, AdbSocket } from './socket';
import { AbortController, DecodeUtf8Stream, GatherStringStream, pipeFrom, StructDeserializeStream, WritableStream, type ReadableWritablePair } from "./stream";
import { decodeUtf8, encodeUtf8 } from "./utils";
import { AdbAuthenticationHandler, AdbDefaultAuthenticators, type AdbCredentialStore } from './auth.js';
import { AdbPower, AdbReverseCommand, AdbSubprocess, AdbSync, AdbTcpIpCommand, escapeArg, framebuffer, install, type AdbFrameBuffer } from './commands/index.js';
import { AdbFeatures } from './features.js';
import { AdbCommand, AdbPacket, AdbPacketSerializeStream, calculateChecksum, type AdbPacketCore, type AdbPacketInit } from './packet.js';
import { AdbPacketDispatcher, AdbSocket } from './socket/index.js';
import { AbortController, DecodeUtf8Stream, GatherStringStream, pipeFrom, StructDeserializeStream, WritableStream, type ReadableWritablePair } from "./stream/index.js";
import { decodeUtf8, encodeUtf8 } from "./utils/index.js";
export enum AdbPropKey {
Product = 'ro.product.name',

View file

@ -1,9 +1,9 @@
import { PromiseResolver } from '@yume-chan/async';
import type { Disposable } from '@yume-chan/event';
import type { ValueOrPromise } from '@yume-chan/struct';
import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto';
import { AdbCommand, AdbPacket, type AdbPacketCore } from './packet';
import { calculateBase64EncodedLength, encodeBase64 } from './utils';
import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto.js';
import { AdbCommand, AdbPacket, type AdbPacketCore } from './packet.js';
import { calculateBase64EncodedLength, encodeBase64 } from './utils/index.js';
export type AdbKeyIterable = Iterable<Uint8Array> | AsyncIterable<Uint8Array>;

View file

@ -1,5 +1,5 @@
import type { ValueOrPromise } from '@yume-chan/struct';
import type { ReadableWritablePair } from "./stream";
import type { ReadableWritablePair } from "./stream/index.js";
export interface AdbBackend {
readonly serial: string;

View file

@ -1,5 +1,5 @@
import { AutoDisposable } from '@yume-chan/event';
import type { Adb } from '../adb';
import type { Adb } from '../adb.js';
export class AdbCommandBase extends AutoDisposable {
protected adb: Adb;

View file

@ -1,6 +1,6 @@
import Struct from "@yume-chan/struct";
import type { Adb } from '../adb';
import { AdbBufferedStream } from '../stream';
import type { Adb } from '../adb.js';
import { AdbBufferedStream } from '../stream/index.js';
const Version =
new Struct({ littleEndian: true })

View file

@ -1,8 +1,8 @@
export * from './base';
export * from './framebuffer';
export * from './install';
export * from './power';
export * from './reverse';
export * from './subprocess';
export * from './sync';
export * from './tcpip';
export * from './base.js';
export * from './framebuffer.js';
export * from './install.js';
export * from './power.js';
export * from './reverse.js';
export * from './subprocess/index.js';
export * from './sync/index.js';
export * from './tcpip.js';

View file

@ -1,7 +1,7 @@
import type { Adb } from "../adb";
import { WrapWritableStream, WritableStream } from "../stream";
import { escapeArg } from "./subprocess";
import type { AdbSync } from "./sync";
import type { Adb } from "../adb.js";
import { WrapWritableStream, WritableStream } from "../stream/index.js";
import { escapeArg } from "./subprocess/index.js";
import type { AdbSync } from "./sync/index.js";
export function install(
adb: Adb,

View file

@ -3,7 +3,7 @@
// cspell: ignore keyevent
// cspell: ignore longpress
import { AdbCommandBase } from "./base";
import { AdbCommandBase } from "./base.js";
export class AdbPower extends AdbCommandBase {
public reboot(name: string = '') {

View file

@ -2,10 +2,10 @@
import { AutoDisposable } from '@yume-chan/event';
import Struct from '@yume-chan/struct';
import type { AdbPacket } from '../packet';
import type { AdbIncomingSocketEventArgs, AdbPacketDispatcher, AdbSocket } from '../socket';
import { AdbBufferedStream } from '../stream';
import { decodeUtf8 } from "../utils";
import type { AdbPacket } from '../packet.js';
import type { AdbIncomingSocketEventArgs, AdbPacketDispatcher, AdbSocket } from '../socket/index.js';
import { AdbBufferedStream } from '../stream/index.js';
import { decodeUtf8 } from "../utils/index.js";
export interface AdbReverseHandler {
onSocket(packet: AdbPacket, socket: AdbSocket): void;

View file

@ -1,13 +1,13 @@
import type { Adb } from '../../adb';
import { DecodeUtf8Stream, GatherStringStream } from "../../stream";
import { AdbNoneSubprocessProtocol } from './legacy';
import { AdbShellSubprocessProtocol } from './protocol';
import type { AdbSubprocessProtocol, AdbSubprocessProtocolConstructor } from './types';
import type { Adb } from '../../adb.js';
import { DecodeUtf8Stream, GatherStringStream } from "../../stream/index.js";
import { AdbNoneSubprocessProtocol } from './legacy.js';
import { AdbShellSubprocessProtocol } from './protocol.js';
import type { AdbSubprocessProtocol, AdbSubprocessProtocolConstructor } from './types.js';
export * from './legacy';
export * from './protocol';
export * from './types';
export * from './utils';
export * from './legacy.js';
export * from './protocol.js';
export * from './types.js';
export * from './utils.js';
export interface AdbSubprocessOptions {
/**

View file

@ -1,7 +1,7 @@
import type { Adb } from "../../adb";
import type { AdbSocket } from "../../socket";
import { DuplexStreamFactory, type ReadableStream } from "../../stream";
import type { AdbSubprocessProtocol } from "./types";
import type { Adb } from "../../adb.js";
import type { AdbSocket } from "../../socket/index.js";
import { DuplexStreamFactory, type ReadableStream } from "../../stream/index.js";
import type { AdbSubprocessProtocol } from "./types.js";
/**
* The legacy shell

View file

@ -1,11 +1,11 @@
import { PromiseResolver } from "@yume-chan/async";
import Struct, { placeholder, type StructValueType } from "@yume-chan/struct";
import type { Adb } from "../../adb";
import { AdbFeatures } from "../../features";
import type { AdbSocket } from "../../socket";
import { PushReadableStream, ReadableStream, StructDeserializeStream, StructSerializeStream, TransformStream, WritableStream, WritableStreamDefaultWriter, type PushReadableStreamController } from "../../stream";
import { encodeUtf8 } from "../../utils";
import type { AdbSubprocessProtocol } from "./types";
import type { Adb } from "../../adb.js";
import { AdbFeatures } from "../../features.js";
import type { AdbSocket } from "../../socket/index.js";
import { PushReadableStream, ReadableStream, StructDeserializeStream, StructSerializeStream, TransformStream, WritableStream, WritableStreamDefaultWriter, type PushReadableStreamController } from "../../stream/index.js";
import { encodeUtf8 } from "../../utils/index.js";
import type { AdbSubprocessProtocol } from "./types.js";
export enum AdbShellProtocolId {
Stdin,

View file

@ -1,7 +1,7 @@
import type { ValueOrPromise } from "@yume-chan/struct";
import type { Adb } from "../../adb";
import type { AdbSocket } from "../../socket";
import type { ReadableStream, WritableStream } from "../../stream";
import type { Adb } from "../../adb.js";
import type { AdbSocket } from "../../socket/index.js";
import type { ReadableStream, WritableStream } from "../../stream/index.js";
export interface AdbSubprocessProtocol {
/**

View file

@ -1,7 +1,7 @@
export * from './list';
export * from './pull';
export * from './request';
export * from './response';
export * from './push';
export * from './stat';
export * from './sync';
export * from './list.js';
export * from './pull.js';
export * from './request.js';
export * from './response.js';
export * from './push.js';
export * from './stat.js';
export * from './sync.js';

View file

@ -1,8 +1,8 @@
import Struct from '@yume-chan/struct';
import type { AdbBufferedStream, WritableStreamDefaultWriter } from '../../stream';
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
import { AdbSyncLstatResponse } from './stat';
import type { AdbBufferedStream, WritableStreamDefaultWriter } from '../../stream/index.js';
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response.js';
import { AdbSyncLstatResponse } from './stat.js';
export const AdbSyncEntryResponse =
new Struct({ littleEndian: true })

View file

@ -1,7 +1,7 @@
import Struct from '@yume-chan/struct';
import { AdbBufferedStream, ReadableStream, WritableStreamDefaultWriter } from '../../stream';
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response';
import { AdbBufferedStream, ReadableStream, WritableStreamDefaultWriter } from '../../stream/index.js';
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
import { AdbSyncDoneResponse, adbSyncReadResponse, AdbSyncResponseId } from './response.js';
export const AdbSyncDataResponse =
new Struct({ littleEndian: true })

View file

@ -1,8 +1,8 @@
import Struct from '@yume-chan/struct';
import { AdbBufferedStream, ChunkStream, pipeFrom, WritableStream, WritableStreamDefaultWriter } from '../../stream';
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
import { adbSyncReadResponse, AdbSyncResponseId } from './response';
import { LinuxFileType } from './stat';
import { AdbBufferedStream, ChunkStream, pipeFrom, WritableStream, WritableStreamDefaultWriter } from '../../stream/index.js';
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
import { adbSyncReadResponse, AdbSyncResponseId } from './response.js';
import { LinuxFileType } from './stat.js';
export const AdbSyncOkResponse =
new Struct({ littleEndian: true })

View file

@ -1,6 +1,6 @@
import Struct from '@yume-chan/struct';
import type { WritableStreamDefaultWriter } from "../../stream";
import { encodeUtf8 } from "../../utils";
import type { WritableStreamDefaultWriter } from "../../stream/index.js";
import { encodeUtf8 } from "../../utils/index.js";
export enum AdbSyncRequestId {
List = 'LIST',

View file

@ -1,6 +1,6 @@
import Struct, { type StructAsyncDeserializeStream, type StructLike, type StructValueType } from '@yume-chan/struct';
import type { AdbBufferedStream } from '../../stream';
import { decodeUtf8 } from "../../utils";
import type { AdbBufferedStream } from '../../stream/index.js';
import { decodeUtf8 } from "../../utils/index.js";
export enum AdbSyncResponseId {
Entry = 'DENT',

View file

@ -1,7 +1,7 @@
import Struct, { placeholder } from '@yume-chan/struct';
import type { AdbBufferedStream, WritableStreamDefaultWriter } from '../../stream';
import { AdbSyncRequestId, adbSyncWriteRequest } from './request';
import { adbSyncReadResponse, AdbSyncResponseId } from './response';
import type { AdbBufferedStream, WritableStreamDefaultWriter } from '../../stream/index.js';
import { AdbSyncRequestId, adbSyncWriteRequest } from './request.js';
import { adbSyncReadResponse, AdbSyncResponseId } from './response.js';
// https://github.com/python/cpython/blob/4e581d64b8aff3e2eda99b12f080c877bb78dfca/Lib/stat.py#L36
export enum LinuxFileType {

View file

@ -1,13 +1,13 @@
import { AutoDisposable } from '@yume-chan/event';
import type { Adb } from '../../adb';
import { AdbFeatures } from '../../features';
import type { AdbSocket } from '../../socket';
import { AdbBufferedStream, ReadableStream, WrapReadableStream, WrapWritableStream, WritableStream, WritableStreamDefaultWriter } from '../../stream';
import { AutoResetEvent } from '../../utils';
import { AdbSyncEntryResponse, adbSyncOpenDir } from './list';
import { adbSyncPull } from './pull';
import { adbSyncPush } from './push';
import { adbSyncLstat, adbSyncStat } from './stat';
import type { Adb } from '../../adb.js';
import { AdbFeatures } from '../../features.js';
import type { AdbSocket } from '../../socket/index.js';
import { AdbBufferedStream, ReadableStream, WrapReadableStream, WrapWritableStream, WritableStream, WritableStreamDefaultWriter } from '../../stream/index.js';
import { AutoResetEvent } from '../../utils/index.js';
import { AdbSyncEntryResponse, adbSyncOpenDir } from './list.js';
import { adbSyncPull } from './pull.js';
import { adbSyncPush } from './push.js';
import { adbSyncLstat, adbSyncStat } from './stat.js';
export class AdbSync extends AutoDisposable {
protected adb: Adb;

View file

@ -1,4 +1,4 @@
import { AdbCommandBase } from './base';
import { AdbCommandBase } from './base.js';
export class AdbTcpIpCommand extends AdbCommandBase {
public async setPort(port: number): Promise<void> {

View file

@ -1,4 +1,4 @@
import { getBigUint64, setBigUint64 } from '@yume-chan/dataview-bigint-polyfill/esm/fallback';
import { getBigUint64, setBigUint64 } from '@yume-chan/dataview-bigint-polyfill/esm/fallback.js';
const BigInt0 = BigInt(0);
const BigInt1 = BigInt(1);

View file

@ -1,5 +1,5 @@
import Struct from '@yume-chan/struct';
import { TransformStream } from "./stream";
import { TransformStream } from "./stream/index.js";
export enum AdbCommand {
Auth = 0x48545541, // 'AUTH'

View file

@ -1,9 +1,9 @@
import { AsyncOperationManager } from '@yume-chan/async';
import { AutoDisposable, EventEmitter } from '@yume-chan/event';
import { AdbCommand, AdbPacket, calculateChecksum, type AdbPacketCore, type AdbPacketInit } from '../packet';
import { AbortController, WritableStream, WritableStreamDefaultWriter, type ReadableWritablePair } from '../stream';
import { decodeUtf8, encodeUtf8 } from '../utils';
import { AdbSocket } from './socket';
import { AdbCommand, AdbPacket, calculateChecksum, type AdbPacketCore, type AdbPacketInit } from '../packet.js';
import { AbortController, WritableStream, WritableStreamDefaultWriter, type ReadableWritablePair } from '../stream/index.js';
import { decodeUtf8, encodeUtf8 } from '../utils/index.js';
import { AdbSocket } from './socket.js';
export interface AdbIncomingSocketEventArgs {
handled: boolean;

View file

@ -1,2 +1,2 @@
export * from './socket';
export * from './dispatcher';
export * from './socket.js';
export * from './dispatcher.js';

View file

@ -1,7 +1,7 @@
import { PromiseResolver } from "@yume-chan/async";
import { AdbCommand } from '../packet';
import { ChunkStream, DuplexStreamFactory, pipeFrom, ReadableStream, WritableStream, type PushReadableStreamController } from '../stream';
import type { AdbPacketDispatcher } from './dispatcher';
import { AdbCommand } from '../packet.js';
import { ChunkStream, DuplexStreamFactory, pipeFrom, ReadableStream, WritableStream, type PushReadableStreamController } from '../stream/index.js';
import type { AdbPacketDispatcher } from './dispatcher.js';
export interface AdbSocketInfo {
localId: number;

View file

@ -1,7 +1,7 @@
import type { StructAsyncDeserializeStream } from '@yume-chan/struct';
import type { AdbSocket, AdbSocketInfo } from '../socket';
import type { ReadableStream, ReadableStreamDefaultReader } from './detect';
import { PushReadableStream } from "./transform";
import type { AdbSocket, AdbSocketInfo } from '../socket/index.js';
import type { ReadableStream, ReadableStreamDefaultReader } from './detect.js';
import { PushReadableStream } from "./transform.js";
export class BufferedStreamEndedError extends Error {
public constructor() {

View file

@ -1,3 +1,3 @@
export * from './buffered';
export * from './detect';
export * from './transform';
export * from './buffered.js';
export * from './detect.js';
export * from './transform.js';

View file

@ -1,9 +1,9 @@
import { PromiseResolver } from "@yume-chan/async";
import type Struct from "@yume-chan/struct";
import type { StructValueType } from "@yume-chan/struct";
import { decodeUtf8 } from "../utils";
import { BufferedStream, BufferedStreamEndedError } from "./buffered";
import { AbortController, AbortSignal, ReadableStream, ReadableStreamDefaultReader, TransformStream, WritableStream, WritableStreamDefaultWriter, type QueuingStrategy, type ReadableStreamController, type ReadableWritablePair, type UnderlyingSink, type UnderlyingSource } from "./detect";
import { decodeUtf8 } from "../utils/index.js";
import { BufferedStream, BufferedStreamEndedError } from "./buffered.js";
import { AbortController, AbortSignal, ReadableStream, ReadableStreamDefaultReader, TransformStream, WritableStream, WritableStreamDefaultWriter, type QueuingStrategy, type ReadableStreamController, type ReadableWritablePair, type UnderlyingSink, type UnderlyingSource } from "./detect.js";
export interface DuplexStreamFactoryOptions {
preventCloseReadableStreams?: boolean | undefined;

View file

@ -1,3 +1,3 @@
export * from './auto-reset-event';
export * from './base64';
export * from './encoding';
export * from './auto-reset-event.js';
export * from './base64.js';
export * from './encoding.js';

View file

@ -22,7 +22,7 @@
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -30,7 +30,7 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"typescript": "^4.6.2",
"typescript": "next",
"@yume-chan/ts-package-builder": "^1.0.0"
},
"dependencies": {

View file

@ -5,7 +5,7 @@
// cspell: ignore sysui
import { Adb, AdbCommandBase } from '@yume-chan/adb';
import { Settings } from "./settings";
import { Settings } from "./settings.js";
export enum DemoModeSignalStrength {
Hidden = 'null',

View file

@ -1,3 +1,3 @@
export * from './bug-report';
export * from './demo-mode';
export * from './settings';
export * from './bug-report.js';
export * from './demo-mode.js';
export * from './settings.js';

View file

@ -26,7 +26,7 @@
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -39,7 +39,7 @@
},
"devDependencies": {
"jest": "^26.6.3",
"typescript": "^4.6.2",
"typescript": "next",
"@yume-chan/ts-package-builder": "^1.0.0"
}
}

View file

@ -1,4 +1,4 @@
import { getBigInt64 as fallbackGetBigInt64, getBigUint64 as fallbackGetBigUint64, setBigInt64 as fallbackSetBigInt64, setBigUint64 as fallbackSetBigUint64 } from './pure';
import { getBigInt64 as fallbackGetBigInt64, getBigUint64 as fallbackGetBigUint64, setBigInt64 as fallbackSetBigInt64, setBigUint64 as fallbackSetBigUint64 } from './pure.js';
export const getBigInt64 =
'getBigInt64' in DataView.prototype ?

View file

@ -1 +1 @@
export * from './pure';
export * from './pure.js';

View file

@ -1,4 +1,4 @@
import { getBigInt64, getBigUint64, setBigInt64, setBigUint64 } from './pure';
import { getBigInt64, getBigUint64, setBigInt64, setBigUint64 } from './pure.js';
if (!('getBigInt64' in DataView)) {
DataView.prototype.getBigInt64 = function (byteOffset, littleEndian) {

View file

@ -23,7 +23,7 @@
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -37,7 +37,7 @@
},
"devDependencies": {
"jest": "^26.6.3",
"typescript": "^4.6.2",
"typescript": "next",
"@yume-chan/ts-package-builder": "^1.0.0"
}
}

View file

@ -1,4 +1,4 @@
import { AutoDisposable, Disposable } from './disposable';
import { AutoDisposable, Disposable } from './disposable.js';
describe('Event', () => {
describe('AutoDisposable', () => {

View file

@ -1,5 +1,5 @@
import type { Disposable } from './disposable';
import type { EventListener, RemoveEventListener } from './event';
import type { Disposable } from './disposable.js';
import type { EventListener, RemoveEventListener } from './event.js';
export interface EventListenerInfo<TEvent, TResult = unknown> {
listener: EventListener<TEvent, any, any, TResult>;

View file

@ -1,4 +1,4 @@
import type { Disposable } from './disposable';
import type { Disposable } from './disposable.js';
export interface EventListener<TEvent, TThis, TArgs extends unknown[], TResult> {
(this: TThis, e: TEvent, ...args: TArgs): TResult;

View file

@ -1,4 +1,4 @@
export * from './disposable';
export * from './event';
export * from './event-emitter';
export * from './utils';
export * from './disposable.js';
export * from './event.js';
export * from './event-emitter.js';
export * from './utils.js';

View file

@ -1,5 +1,5 @@
import { PromiseResolver } from '@yume-chan/async';
import type { Event } from './event';
import type { Event } from './event.js';
export async function once<T>(event: Event<T, any>): Promise<T> {
const resolver = new PromiseResolver<T>();

View file

@ -48,7 +48,8 @@ Scrcpy server has no backward compatibility on options input format. Currently t
| --------- | ------------------- |
| 1.16~1.17 | `ScrcpyOptions1_16` |
| 1.18~1.20 | `ScrcpyOptions1_18` |
| 1.21~1.22 | `ScrcpyOptions1_21` |
| 1.21 | `ScrcpyOptions1_21` |
| 1.22 | `ScrcpyOptions1_22` |
You must use the correct type according to the server version.

View file

@ -26,7 +26,7 @@
"fetch-scrcpy-server": "scripts/fetch-server.cjs"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -48,7 +48,7 @@
"gh-release-fetch": "^2.0.4",
"jest": "^26.6.3",
"tinyh264": "^0.0.7",
"typescript": "^4.6.2",
"typescript": "next",
"yuv-buffer": "^1.0.0",
"yuv-canvas": "^1.2.7"
},

View file

@ -1,8 +1,8 @@
import { Adb, AdbBufferedStream, AdbNoneSubprocessProtocol, AdbSocket, DecodeUtf8Stream, InspectStream, ReadableStream, TransformStream, WritableStreamDefaultWriter, type AdbSubprocessProtocol } from '@yume-chan/adb';
import { EventEmitter } from '@yume-chan/event';
import Struct from '@yume-chan/struct';
import { AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage, type AndroidKeyEventAction } from './message';
import type { ScrcpyInjectScrollControlMessage1_22, ScrcpyOptions, VideoStreamPacket } from "./options";
import { AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage, type AndroidKeyEventAction } from './message.js';
import type { ScrcpyInjectScrollControlMessage1_22, ScrcpyOptions, VideoStreamPacket } from "./options/index.js";
function* splitLines(text: string): Generator<string, void, void> {
let start = 0;

View file

@ -1,7 +1,7 @@
import { Adb, AdbBufferedStream, AdbSocket } from "@yume-chan/adb";
import type { Disposable } from "@yume-chan/event";
import type { ValueOrPromise } from "@yume-chan/struct";
import { delay } from "./utils";
import { delay } from "./utils.js";
export interface ScrcpyClientConnectionOptions {
control: boolean;

View file

@ -1,7 +1,7 @@
import type { WritableStream } from '@yume-chan/adb';
import type { Disposable } from "@yume-chan/event";
import type { AndroidCodecLevel, AndroidCodecProfile } from "../codec";
import type { VideoStreamPacket } from "../options";
import type { AndroidCodecLevel, AndroidCodecProfile } from "../codec.js";
import type { VideoStreamPacket } from "../options/index.js";
export interface H264Configuration {
profileIndex: number;

View file

@ -1,3 +1,3 @@
export * from './common';
export * from './tinyh264';
export * from './web-codecs';
export * from './common.js';
export * from './tinyh264/index.js';
export * from './web-codecs/index.js';

View file

@ -1,9 +1,9 @@
import { WritableStream } from "@yume-chan/adb";
import { PromiseResolver } from "@yume-chan/async";
import { AndroidCodecLevel, AndroidCodecProfile } from "../../codec";
import type { VideoStreamPacket } from "../../options";
import type { H264Configuration, H264Decoder } from '../common';
import { createTinyH264Wrapper, type TinyH264Wrapper } from "./wrapper";
import { AndroidCodecLevel, AndroidCodecProfile } from "../../codec.js";
import type { VideoStreamPacket } from "../../options/index.js";
import type { H264Configuration, H264Decoder } from "../common.js";
import { createTinyH264Wrapper, type TinyH264Wrapper } from "./wrapper.js";
let cachedInitializePromise: Promise<{ YuvBuffer: typeof import('yuv-buffer'), YuvCanvas: typeof import('yuv-canvas').default; }> | undefined;
function initialize() {

View file

@ -1,5 +1,5 @@
import type { VideoStreamPacket } from "../../options";
import type { H264Configuration, H264Decoder } from "../common";
import type { VideoStreamPacket } from "../../options/index.js";
import type { H264Configuration, H264Decoder } from "../common.js";
function toHex(value: number) {
return value.toString(16).padStart(2, '0').toUpperCase();

View file

@ -1,8 +1,8 @@
export * from './client';
export * from './codec';
export * from './connection';
export * from './decoder';
export * from './message';
export * from './options';
export * from './push-server';
export * from './utils';
export * from './client.js';
export * from './codec.js';
export * from './connection.js';
export * from './decoder/index.js';
export * from './message.js';
export * from './options/index.js';
export * from './push-server.js';
export * from './utils.js';

View file

@ -1,12 +1,12 @@
import { BufferedStreamEndedError, ReadableStream, TransformStream, type Adb, type AdbBufferedStream } from "@yume-chan/adb";
import Struct, { placeholder } from "@yume-chan/struct";
import type { AndroidCodecLevel, AndroidCodecProfile } from "../../codec";
import { ScrcpyClientConnection, ScrcpyClientForwardConnection, ScrcpyClientReverseConnection, type ScrcpyClientConnectionOptions } from "../../connection";
import { AndroidKeyEventAction, ScrcpyControlMessageType } from "../../message";
import type { ScrcpyBackOrScreenOnEvent1_18 } from "../1_18";
import type { ScrcpyInjectScrollControlMessage1_22 } from "../1_22";
import { toScrcpyOptionValue, type ScrcpyOptions, type ScrcpyOptionValue, type VideoStreamPacket } from "../common";
import { parse_sequence_parameter_set } from "./sps";
import type { AndroidCodecLevel, AndroidCodecProfile } from "../../codec.js";
import { ScrcpyClientConnection, ScrcpyClientForwardConnection, ScrcpyClientReverseConnection, type ScrcpyClientConnectionOptions } from "../../connection.js";
import { AndroidKeyEventAction, ScrcpyControlMessageType } from "../../message.js";
import type { ScrcpyBackOrScreenOnEvent1_18 } from "../1_18.js";
import type { ScrcpyInjectScrollControlMessage1_22 } from "../1_22.js";
import { toScrcpyOptionValue, type ScrcpyOptions, type ScrcpyOptionValue, type VideoStreamPacket } from "../common.js";
import { parse_sequence_parameter_set } from "./sps.js";
export enum ScrcpyLogLevel {
Verbose = 'verbose',

View file

@ -1,6 +1,6 @@
import Struct, { placeholder } from "@yume-chan/struct";
import type { AndroidKeyEventAction } from "../message";
import { ScrcpyBackOrScreenOnEvent1_16, ScrcpyOptions1_16, type ScrcpyOptionsInit1_16 } from "./1_16";
import type { AndroidKeyEventAction } from "../message.js";
import { ScrcpyBackOrScreenOnEvent1_16, ScrcpyOptions1_16, type ScrcpyOptionsInit1_16 } from "./1_16/index.js";
export interface ScrcpyOptionsInit1_18 extends ScrcpyOptionsInit1_16 {
powerOffOnClose: boolean;

View file

@ -1,7 +1,7 @@
// cspell: ignore autosync
import { ScrcpyOptions1_18, type ScrcpyOptionsInit1_18 } from './1_18';
import { toScrcpyOptionValue } from "./common";
import { ScrcpyOptions1_18, type ScrcpyOptionsInit1_18 } from './1_18.js';
import { toScrcpyOptionValue } from "./common.js";
export interface ScrcpyOptionsInit1_21 extends ScrcpyOptionsInit1_18 {
clipboardAutosync?: boolean;

View file

@ -1,8 +1,8 @@
import type { Adb } from "@yume-chan/adb";
import Struct from "@yume-chan/struct";
import { ScrcpyClientForwardConnection, ScrcpyClientReverseConnection, type ScrcpyClientConnection, type ScrcpyClientConnectionOptions } from "../connection";
import { ScrcpyInjectScrollControlMessage1_16 } from "./1_16";
import { ScrcpyOptions1_21, type ScrcpyOptionsInit1_21 } from "./1_21";
import { ScrcpyClientForwardConnection, ScrcpyClientReverseConnection, type ScrcpyClientConnection, type ScrcpyClientConnectionOptions } from "../connection.js";
import { ScrcpyInjectScrollControlMessage1_16 } from "./1_16/index.js";
import { ScrcpyOptions1_21, type ScrcpyOptionsInit1_21 } from "./1_21.js";
export interface ScrcpyOptionsInit1_22 extends ScrcpyOptionsInit1_21 {
downsizeOnError: boolean;

View file

@ -1,8 +1,8 @@
import type { Adb, AdbBufferedStream, ReadableStream } from "@yume-chan/adb";
import type { ScrcpyClientConnection } from "../connection";
import type { H264Configuration } from "../decoder";
import type { ScrcpyBackOrScreenOnEvent1_18 } from "./1_18";
import type { ScrcpyInjectScrollControlMessage1_22 } from "./1_22";
import type { ScrcpyClientConnection } from "../connection.js";
import type { H264Configuration } from "../decoder/index.js";
import type { ScrcpyBackOrScreenOnEvent1_18 } from "./1_18.js";
import type { ScrcpyInjectScrollControlMessage1_22 } from "./1_22.js";
export const DEFAULT_SERVER_PATH = '/data/local/tmp/scrcpy-server.jar';

View file

@ -1,5 +1,5 @@
export * from './1_16';
export * from './1_18';
export * from './1_21';
export * from './1_22';
export * from './common';
export * from './1_16/index.js';
export * from './1_18.js';
export * from './1_21.js';
export * from './1_22.js';
export * from './common.js';

View file

@ -1,5 +1,5 @@
import { Adb, AdbSync, WrapWritableStream, WritableStream } from "@yume-chan/adb";
import { DEFAULT_SERVER_PATH } from "./options";
import { DEFAULT_SERVER_PATH } from "./options/index.js";
export interface PushServerOptions {
path?: string;

View file

@ -24,7 +24,7 @@
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"type": "module",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "esm/index.d.ts",
"scripts": {
"build": "build-ts-package",
@ -39,7 +39,7 @@
},
"devDependencies": {
"jest": "^26.6.3",
"typescript": "^4.6.2",
"typescript": "next",
"@yume-chan/ts-package-builder": "^1.0.0",
"@types/jest": "^27.4.0",
"@types/bluebird": "^3.5.36"

View file

@ -1,9 +1,9 @@
import type { ValueOrPromise } from '../utils';
import { StructFieldDefinition } from './definition';
import type { StructFieldValue } from './field-value';
import type { StructOptions } from './options';
import type { StructAsyncDeserializeStream, StructDeserializeStream } from './stream';
import type { StructValue } from './struct-value';
import type { ValueOrPromise } from '../utils.js';
import { StructFieldDefinition } from './definition.js';
import type { StructFieldValue } from './field-value.js';
import type { StructOptions } from './options.js';
import type { StructAsyncDeserializeStream, StructDeserializeStream } from './stream.js';
import type { StructValue } from './struct-value.js';
describe('StructFieldDefinition', () => {
describe('.constructor', () => {

View file

@ -1,9 +1,9 @@
// cspell: ignore Syncbird
import type { StructAsyncDeserializeStream, StructDeserializeStream } from './stream';
import type { StructFieldValue } from './field-value';
import type { StructValue } from './struct-value';
import type { StructOptions } from "./options";
import type { StructAsyncDeserializeStream, StructDeserializeStream } from "./stream.js";
import type { StructFieldValue } from "./field-value.js";
import type { StructValue } from "./struct-value.js";
import type { StructOptions } from "./options.js";
/**
* A field definition defines how to deserialize a field.

View file

@ -1,9 +1,9 @@
import type { ValueOrPromise } from '../utils';
import { StructFieldDefinition } from './definition';
import { StructFieldValue } from './field-value';
import type { StructOptions } from './options';
import type { StructAsyncDeserializeStream, StructDeserializeStream } from './stream';
import type { StructValue } from './struct-value';
import type { ValueOrPromise } from "../utils.js";
import { StructFieldDefinition } from "./definition.js";
import { StructFieldValue } from "./field-value.js";
import type { StructOptions } from "./options.js";
import type { StructAsyncDeserializeStream, StructDeserializeStream } from "./stream.js";
import type { StructValue } from "./struct-value.js";
describe('StructFieldValue', () => {
describe('.constructor', () => {

View file

@ -1,6 +1,6 @@
import type { StructFieldDefinition } from './definition';
import type { StructOptions } from './options';
import type { StructValue } from './struct-value';
import type { StructFieldDefinition } from "./definition.js";
import type { StructOptions } from "./options.js";
import type { StructValue } from "./struct-value.js";
/**
* A field value defines how to serialize a field.

View file

@ -1,5 +1,5 @@
export * from './definition';
export * from './field-value';
export * from './options';
export * from './stream';
export * from './struct-value';
export * from './definition.js';
export * from './field-value.js';
export * from './options.js';
export * from './stream.js';
export * from './struct-value.js';

View file

@ -1,4 +1,4 @@
import { StructDefaultOptions } from './options';
import { StructDefaultOptions } from './options.js';
describe('StructDefaultOptions', () => {
describe('.littleEndian', () => {

View file

@ -1,4 +1,4 @@
import { StructValue } from './struct-value';
import { StructValue } from "./struct-value.js";
describe('StructValue', () => {
describe('.constructor', () => {

View file

@ -1,4 +1,4 @@
import type { StructFieldValue } from './field-value';
import type { StructFieldValue } from "./field-value.js";
/**
* A struct value is a map between keys in a struct and their field values.

View file

@ -1,4 +1,4 @@
import Struct from './index';
import Struct from './index.js';
describe('Struct', () => {
describe("Index", () => {

View file

@ -10,8 +10,8 @@ declare global {
}
}
export * from './basic';
export * from './struct';
export { Struct as default } from './struct';
export * from './types';
export * from './utils';
export * from './basic/index.js';
export * from './struct.js';
export { Struct as default } from './struct.js';
export * from './types/index.js';
export * from './utils.js';

View file

@ -1,7 +1,7 @@
import { StructAsyncDeserializeStream, StructDefaultOptions, StructDeserializeStream, StructFieldDefinition, StructFieldValue, StructOptions, StructValue } from './basic';
import { Struct } from './struct';
import { ArrayBufferFieldType, BigIntFieldDefinition, BigIntFieldType, FixedLengthArrayBufferLikeFieldDefinition, NumberFieldDefinition, NumberFieldType, StringFieldType, ArrayBufferViewFieldType, VariableLengthArrayBufferLikeFieldDefinition } from './types';
import { ValueOrPromise } from './utils';
import { StructAsyncDeserializeStream, StructDefaultOptions, StructDeserializeStream, StructFieldDefinition, StructFieldValue, StructOptions, StructValue } from './basic/index.js';
import { Struct } from './struct.js';
import { ArrayBufferFieldType, BigIntFieldDefinition, BigIntFieldType, FixedLengthArrayBufferLikeFieldDefinition, NumberFieldDefinition, NumberFieldType, StringFieldType, ArrayBufferViewFieldType, VariableLengthArrayBufferLikeFieldDefinition } from './types/index.js';
import { ValueOrPromise } from './utils.js';
class MockDeserializationStream implements StructDeserializeStream {
public buffer = new ArrayBuffer(0);

View file

@ -1,10 +1,10 @@
// cspell: ignore Syncbird
import type { StructAsyncDeserializeStream, StructDeserializeStream, StructFieldDefinition, StructFieldValue, StructOptions } from './basic';
import { StructDefaultOptions, StructValue } from './basic';
import { Syncbird } from "./syncbird";
import { BigIntFieldDefinition, BigIntFieldType, BufferFieldSubType, FixedLengthBufferLikeFieldDefinition, NumberFieldDefinition, NumberFieldType, StringBufferFieldSubType, Uint8ArrayBufferFieldSubType, VariableLengthBufferLikeFieldDefinition, type FixedLengthBufferLikeFieldOptions, type LengthField, type VariableLengthBufferLikeFieldOptions } from './types';
import type { Evaluate, Identity, Overwrite, ValueOrPromise } from "./utils";
import type { StructAsyncDeserializeStream, StructDeserializeStream, StructFieldDefinition, StructFieldValue, StructOptions } from './basic/index.js';
import { StructDefaultOptions, StructValue } from './basic/index.js';
import { Syncbird } from "./syncbird.js";
import { BigIntFieldDefinition, BigIntFieldType, BufferFieldSubType, FixedLengthBufferLikeFieldDefinition, NumberFieldDefinition, NumberFieldType, StringBufferFieldSubType, Uint8ArrayBufferFieldSubType, VariableLengthBufferLikeFieldDefinition, type FixedLengthBufferLikeFieldOptions, type LengthField, type VariableLengthBufferLikeFieldOptions } from './types/index.js';
import type { Evaluate, Identity, Overwrite, ValueOrPromise } from "./utils.js";
export interface StructLike<TValue> {
deserialize(stream: StructDeserializeStream | StructAsyncDeserializeStream): Promise<TValue>;

View file

@ -1,9 +1,9 @@
// cspell: ignore syncbird
import { getBigInt64, getBigUint64, setBigInt64, setBigUint64 } from '@yume-chan/dataview-bigint-polyfill/esm/fallback';
import { StructFieldDefinition, StructFieldValue, StructValue, type StructAsyncDeserializeStream, type StructDeserializeStream, type StructOptions } from "../basic";
import { Syncbird } from "../syncbird";
import type { ValueOrPromise } from "../utils";
import { getBigInt64, getBigUint64, setBigInt64, setBigUint64 } from '@yume-chan/dataview-bigint-polyfill/esm/fallback.js';
import { StructFieldDefinition, StructFieldValue, StructValue, type StructAsyncDeserializeStream, type StructDeserializeStream, type StructOptions } from "../basic/index.js";
import { Syncbird } from "../syncbird.js";
import type { ValueOrPromise } from "../utils.js";
type DataViewBigInt64Getter = (dataView: DataView, byteOffset: number, littleEndian: boolean | undefined) => bigint;

View file

@ -1,5 +1,5 @@
import { StructDefaultOptions, StructDeserializeStream, StructValue } from '../../basic';
import { BufferFieldSubType, BufferLikeFieldDefinition, StringBufferFieldSubType, Uint8ArrayBufferFieldSubType } from './base';
import { StructDefaultOptions, StructDeserializeStream, StructValue } from '../../basic/index.js';
import { BufferFieldSubType, BufferLikeFieldDefinition, StringBufferFieldSubType, Uint8ArrayBufferFieldSubType } from './base.js';
class MockDeserializationStream implements StructDeserializeStream {
public array = new Uint8Array(0);

View file

@ -1,8 +1,8 @@
// cspell: ignore syncbird
import { StructFieldDefinition, StructFieldValue, StructValue, type StructAsyncDeserializeStream, type StructDeserializeStream, type StructOptions } from '../../basic';
import { Syncbird } from "../../syncbird";
import { decodeUtf8, encodeUtf8, type ValueOrPromise } from "../../utils";
import { StructFieldDefinition, StructFieldValue, StructValue, type StructAsyncDeserializeStream, type StructDeserializeStream, type StructOptions } from '../../basic/index.js';
import { Syncbird } from "../../syncbird.js";
import { decodeUtf8, encodeUtf8, type ValueOrPromise } from "../../utils.js";
/**
* Base class for all types that

View file

@ -1,10 +1,10 @@
import { Uint8ArrayBufferFieldSubType } from './base';
import { FixedLengthBufferLikeFieldDefinition } from './fixed-length';
import { Uint8ArrayBufferFieldSubType } from "./base.js";
import { FixedLengthBufferLikeFieldDefinition } from "./fixed-length.js";
describe('Types', () => {
describe('FixedLengthArrayBufferLikeFieldDefinition', () => {
describe('#getSize', () => {
it('should return size in its options', () => {
describe("Types", () => {
describe("FixedLengthArrayBufferLikeFieldDefinition", () => {
describe("#getSize", () => {
it("should return size in its options", () => {
const definition = new FixedLengthBufferLikeFieldDefinition(
Uint8ArrayBufferFieldSubType.Instance,
{ length: 10 },

View file

@ -1,4 +1,4 @@
import { BufferLikeFieldDefinition, type BufferFieldSubType } from './base';
import { BufferLikeFieldDefinition, type BufferFieldSubType } from "./base.js";
export interface FixedLengthBufferLikeFieldOptions {
length: number;

View file

@ -1,3 +1,3 @@
export * from './base';
export * from './fixed-length';
export * from './variable-length';
export * from "./base.js";
export * from "./fixed-length.js";
export * from "./variable-length.js";

View file

@ -1,6 +1,6 @@
import { StructDefaultOptions, StructFieldValue, StructValue } from '../../basic';
import { BufferFieldSubType, Uint8ArrayBufferFieldSubType } from './base';
import { VariableLengthBufferLikeFieldDefinition, VariableLengthBufferLikeFieldLengthValue, VariableLengthBufferLikeStructFieldValue } from './variable-length';
import { StructDefaultOptions, StructFieldValue, StructValue } from "../../basic/index.js";
import { BufferFieldSubType, Uint8ArrayBufferFieldSubType } from "./base.js";
import { VariableLengthBufferLikeFieldDefinition, VariableLengthBufferLikeFieldLengthValue, VariableLengthBufferLikeStructFieldValue } from "./variable-length.js";
class MockOriginalFieldValue extends StructFieldValue {
public constructor() {
@ -20,8 +20,8 @@ class MockOriginalFieldValue extends StructFieldValue {
public serialize = jest.fn((dataView: DataView, offset: number): void => { });
}
describe('Types', () => {
describe('VariableLengthArrayBufferLikeFieldLengthValue', () => {
describe("Types", () => {
describe("VariableLengthArrayBufferLikeFieldLengthValue", () => {
class MockArrayBufferFieldValue extends StructFieldValue {
public constructor() {
super({ options: {} } as any, {} as any, {} as any, {});
@ -32,12 +32,12 @@ describe('Types', () => {
public override getSize = jest.fn(() => this.size);
public serialize(dataView: DataView, offset: number): void {
throw new Error('Method not implemented.');
throw new Error("Method not implemented.");
}
}
describe('#getSize', () => {
it('should return size of its original field value', () => {
describe("#getSize", () => {
it("should return size of its original field value", () => {
const mockOriginalFieldValue = new MockOriginalFieldValue();
const mockArrayBufferFieldValue = new MockArrayBufferFieldValue();
const lengthFieldValue = new VariableLengthBufferLikeFieldLengthValue(
@ -56,8 +56,8 @@ describe('Types', () => {
});
});
describe('#get', () => {
it('should return size of its `arrayBufferField`', async () => {
describe("#get", () => {
it("should return size of its `arrayBufferField`", async () => {
const mockOriginalFieldValue = new MockOriginalFieldValue();
const mockArrayBufferFieldValue = new MockArrayBufferFieldValue();
const lengthFieldValue = new VariableLengthBufferLikeFieldLengthValue(
@ -79,7 +79,7 @@ describe('Types', () => {
expect(mockOriginalFieldValue.get).toBeCalledTimes(1);
});
it('should return size of its `arrayBufferField` as string', async () => {
it("should return size of its `arrayBufferField` as string", async () => {
const mockOriginalFieldValue = new MockOriginalFieldValue();
const mockArrayBufferFieldValue = new MockArrayBufferFieldValue();
const lengthFieldValue = new VariableLengthBufferLikeFieldLengthValue(
@ -87,23 +87,23 @@ describe('Types', () => {
mockArrayBufferFieldValue,
);
mockOriginalFieldValue.value = '0';
mockOriginalFieldValue.value = "0";
mockArrayBufferFieldValue.size = 0;
expect(lengthFieldValue.get()).toBe('0');
expect(lengthFieldValue.get()).toBe("0");
expect(mockArrayBufferFieldValue.getSize).toBeCalledTimes(1);
expect(mockOriginalFieldValue.get).toBeCalledTimes(1);
mockArrayBufferFieldValue.getSize.mockClear();
mockOriginalFieldValue.get.mockClear();
mockArrayBufferFieldValue.size = 100;
expect(lengthFieldValue.get()).toBe('100');
expect(lengthFieldValue.get()).toBe("100");
expect(mockArrayBufferFieldValue.getSize).toBeCalledTimes(1);
expect(mockOriginalFieldValue.get).toBeCalledTimes(1);
});
});
describe('#set', () => {
it('should does nothing', async () => {
describe("#set", () => {
it("should does nothing", async () => {
const mockOriginalFieldValue = new MockOriginalFieldValue();
const mockArrayBufferFieldValue = new MockArrayBufferFieldValue();
const lengthFieldValue = new VariableLengthBufferLikeFieldLengthValue(
@ -120,8 +120,8 @@ describe('Types', () => {
});
});
describe('#serialize', () => {
it('should call `serialize` of its `originalField`', async () => {
describe("#serialize", () => {
it("should call `serialize` of its `originalField`", async () => {
const mockOriginalFieldValue = new MockOriginalFieldValue();
const mockArrayBufferFieldValue = new MockArrayBufferFieldValue();
const lengthFieldValue = new VariableLengthBufferLikeFieldLengthValue(
@ -152,7 +152,7 @@ describe('Types', () => {
expect(mockOriginalFieldValue.serialize).toBeCalledWith(dataView, offset);
});
it('should stringify its length if `originalField` is a string', async () => {
it("should stringify its length if `originalField` is a string", async () => {
const mockOriginalFieldValue = new MockOriginalFieldValue();
const mockArrayBufferFieldValue = new MockArrayBufferFieldValue();
const lengthFieldValue = new VariableLengthBufferLikeFieldLengthValue(
@ -163,13 +163,13 @@ describe('Types', () => {
let dataView = 0 as any;
let offset = 1 as any;
mockOriginalFieldValue.value = '10';
mockOriginalFieldValue.value = "10";
mockArrayBufferFieldValue.size = 0;
lengthFieldValue.serialize(dataView, offset);
expect(mockOriginalFieldValue.get).toBeCalledTimes(1);
expect(mockOriginalFieldValue.get).toReturnWith('10');
expect(mockOriginalFieldValue.get).toReturnWith("10");
expect(mockOriginalFieldValue.set).toBeCalledTimes(1);
expect(mockOriginalFieldValue.set).toBeCalledWith('0');
expect(mockOriginalFieldValue.set).toBeCalledWith("0");
expect(mockOriginalFieldValue.serialize).toBeCalledTimes(1);
expect(mockOriginalFieldValue.serialize).toBeCalledWith(dataView, offset);
@ -178,12 +178,12 @@ describe('Types', () => {
mockArrayBufferFieldValue.size = 100;
lengthFieldValue.serialize(dataView, offset);
expect(mockOriginalFieldValue.set).toBeCalledTimes(1);
expect(mockOriginalFieldValue.set).toBeCalledWith('100');
expect(mockOriginalFieldValue.set).toBeCalledWith("100");
expect(mockOriginalFieldValue.serialize).toBeCalledTimes(1);
expect(mockOriginalFieldValue.serialize).toBeCalledWith(dataView, offset);
});
it('should stringify its length in specified base if `originalField` is a string', async () => {
it("should stringify its length in specified base if `originalField` is a string", async () => {
const mockOriginalFieldValue = new MockOriginalFieldValue();
const mockArrayBufferFieldValue = new MockArrayBufferFieldValue();
const lengthFieldValue = new VariableLengthBufferLikeFieldLengthValue(
@ -197,13 +197,13 @@ describe('Types', () => {
let dataView = 0 as any;
let offset = 1 as any;
mockOriginalFieldValue.value = '10';
mockOriginalFieldValue.value = "10";
mockArrayBufferFieldValue.size = 0;
lengthFieldValue.serialize(dataView, offset);
expect(mockOriginalFieldValue.get).toBeCalledTimes(1);
expect(mockOriginalFieldValue.get).toReturnWith('10');
expect(mockOriginalFieldValue.get).toReturnWith("10");
expect(mockOriginalFieldValue.set).toBeCalledTimes(1);
expect(mockOriginalFieldValue.set).toBeCalledWith('0');
expect(mockOriginalFieldValue.set).toBeCalledWith("0");
expect(mockOriginalFieldValue.serialize).toBeCalledTimes(1);
expect(mockOriginalFieldValue.serialize).toBeCalledWith(dataView, offset);
@ -219,12 +219,12 @@ describe('Types', () => {
});
});
describe('VariableLengthArrayBufferLikeStructFieldValue', () => {
describe('.constructor', () => {
it('should forward parameters', () => {
describe("VariableLengthArrayBufferLikeStructFieldValue", () => {
describe(".constructor", () => {
it("should forward parameters", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -242,18 +242,18 @@ describe('Types', () => {
value,
);
expect(arrayBufferFieldValue).toHaveProperty('definition', arrayBufferFieldDefinition);
expect(arrayBufferFieldValue).toHaveProperty('options', StructDefaultOptions);
expect(arrayBufferFieldValue).toHaveProperty('struct', struct);
expect(arrayBufferFieldValue).toHaveProperty('value', value);
expect(arrayBufferFieldValue).toHaveProperty('arrayBuffer', undefined);
expect(arrayBufferFieldValue).toHaveProperty('length', undefined);
expect(arrayBufferFieldValue).toHaveProperty("definition", arrayBufferFieldDefinition);
expect(arrayBufferFieldValue).toHaveProperty("options", StructDefaultOptions);
expect(arrayBufferFieldValue).toHaveProperty("struct", struct);
expect(arrayBufferFieldValue).toHaveProperty("value", value);
expect(arrayBufferFieldValue).toHaveProperty("arrayBuffer", undefined);
expect(arrayBufferFieldValue).toHaveProperty("length", undefined);
});
it('should forward parameters with `arrayBuffer`', () => {
it("should forward parameters with `arrayBuffer`", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -272,18 +272,18 @@ describe('Types', () => {
value,
);
expect(arrayBufferFieldValue).toHaveProperty('definition', arrayBufferFieldDefinition);
expect(arrayBufferFieldValue).toHaveProperty('options', StructDefaultOptions);
expect(arrayBufferFieldValue).toHaveProperty('struct', struct);
expect(arrayBufferFieldValue).toHaveProperty('value', value);
expect(arrayBufferFieldValue).toHaveProperty('array', value);
expect(arrayBufferFieldValue).toHaveProperty('length', 100);
expect(arrayBufferFieldValue).toHaveProperty("definition", arrayBufferFieldDefinition);
expect(arrayBufferFieldValue).toHaveProperty("options", StructDefaultOptions);
expect(arrayBufferFieldValue).toHaveProperty("struct", struct);
expect(arrayBufferFieldValue).toHaveProperty("value", value);
expect(arrayBufferFieldValue).toHaveProperty("array", value);
expect(arrayBufferFieldValue).toHaveProperty("length", 100);
});
it('should replace `lengthField` on `struct`', () => {
it("should replace `lengthField` on `struct`", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -301,12 +301,12 @@ describe('Types', () => {
value,
);
expect(arrayBufferFieldValue['lengthFieldValue']).toBeInstanceOf(StructFieldValue);
expect(struct.fieldValues[lengthField]).toBe(arrayBufferFieldValue['lengthFieldValue']);
expect(arrayBufferFieldValue["lengthFieldValue"]).toBeInstanceOf(StructFieldValue);
expect(struct.fieldValues[lengthField]).toBe(arrayBufferFieldValue["lengthFieldValue"]);
});
});
describe('#getSize', () => {
describe("#getSize", () => {
class MockArrayBufferFieldType extends BufferFieldSubType<Uint8Array> {
public override toBuffer = jest.fn((value: Uint8Array): Uint8Array => {
return value;
@ -323,10 +323,10 @@ describe('Types', () => {
});
}
it('should return cached size if exist', async () => {
it("should return cached size if exist", async () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -352,10 +352,10 @@ describe('Types', () => {
expect(arrayBufferFieldType.getSize).toBeCalledTimes(0);
});
it('should call `getSize` of its `type`', () => {
it("should call `getSize` of its `type`", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -379,14 +379,14 @@ describe('Types', () => {
expect(arrayBufferFieldType.toValue).toBeCalledTimes(0);
expect(arrayBufferFieldType.toBuffer).toBeCalledTimes(0);
expect(arrayBufferFieldType.getSize).toBeCalledTimes(1);
expect(arrayBufferFieldValue).toHaveProperty('arrayBuffer', undefined);
expect(arrayBufferFieldValue).toHaveProperty('length', 100);
expect(arrayBufferFieldValue).toHaveProperty("arrayBuffer", undefined);
expect(arrayBufferFieldValue).toHaveProperty("length", 100);
});
it('should call `toArrayBuffer` of its `type` if it does not support `getSize`', () => {
it("should call `toArrayBuffer` of its `type` if it does not support `getSize`", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -410,16 +410,16 @@ describe('Types', () => {
expect(arrayBufferFieldType.toValue).toBeCalledTimes(0);
expect(arrayBufferFieldType.toBuffer).toBeCalledTimes(1);
expect(arrayBufferFieldType.getSize).toBeCalledTimes(1);
expect(arrayBufferFieldValue).toHaveProperty('arrayBuffer', value);
expect(arrayBufferFieldValue).toHaveProperty('length', 100);
expect(arrayBufferFieldValue).toHaveProperty("arrayBuffer", value);
expect(arrayBufferFieldValue).toHaveProperty("length", 100);
});
});
describe('#set', () => {
it('should call `ArrayBufferLikeFieldValue#set`', () => {
describe("#set", () => {
it("should call `ArrayBufferLikeFieldValue#set`", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -441,13 +441,13 @@ describe('Types', () => {
const newValue = new ArrayBuffer(100);
arrayBufferFieldValue.set(newValue);
expect(arrayBufferFieldValue.get()).toBe(newValue);
expect(arrayBufferFieldValue).toHaveProperty('arrayBuffer', undefined);
expect(arrayBufferFieldValue).toHaveProperty("arrayBuffer", undefined);
});
it('should clear length', () => {
it("should clear length", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -468,27 +468,27 @@ describe('Types', () => {
const newValue = new ArrayBuffer(100);
arrayBufferFieldValue.set(newValue);
expect(arrayBufferFieldValue).toHaveProperty('length', undefined);
expect(arrayBufferFieldValue).toHaveProperty("length", undefined);
});
});
});
describe('VariableLengthArrayBufferLikeFieldDefinition', () => {
describe('#getSize', () => {
it('should always return `0`', () => {
describe("VariableLengthArrayBufferLikeFieldDefinition", () => {
describe("#getSize", () => {
it("should always return `0`", () => {
const definition = new VariableLengthBufferLikeFieldDefinition(
Uint8ArrayBufferFieldSubType.Instance,
{ lengthField: 'foo' },
{ lengthField: "foo" },
);
expect(definition.getSize()).toBe(0);
});
});
describe('#getDeserializeSize', () => {
it('should return value of its `lengthField`', async () => {
describe("#getDeserializeSize", () => {
it("should return value of its `lengthField`", async () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -498,19 +498,19 @@ describe('Types', () => {
);
originalLengthFieldValue.value = 0;
expect(definition['getDeserializeSize'](struct)).toBe(0);
expect(definition["getDeserializeSize"](struct)).toBe(0);
expect(originalLengthFieldValue.get).toBeCalledTimes(1);
originalLengthFieldValue.get.mockClear();
originalLengthFieldValue.value = 100;
expect(definition['getDeserializeSize'](struct)).toBe(100);
expect(definition["getDeserializeSize"](struct)).toBe(100);
expect(originalLengthFieldValue.get).toBeCalledTimes(1);
});
it('should return value of its `lengthField` as number', async () => {
it("should return value of its `lengthField` as number", async () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -519,20 +519,20 @@ describe('Types', () => {
{ lengthField },
);
originalLengthFieldValue.value = '0';
expect(definition['getDeserializeSize'](struct)).toBe(0);
originalLengthFieldValue.value = "0";
expect(definition["getDeserializeSize"](struct)).toBe(0);
expect(originalLengthFieldValue.get).toBeCalledTimes(1);
originalLengthFieldValue.get.mockClear();
originalLengthFieldValue.value = '100';
expect(definition['getDeserializeSize'](struct)).toBe(100);
originalLengthFieldValue.value = "100";
expect(definition["getDeserializeSize"](struct)).toBe(100);
expect(originalLengthFieldValue.get).toBeCalledTimes(1);
});
it('should return value of its `lengthField` as number with specified base', async () => {
it("should return value of its `lengthField` as number with specified base", async () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -542,22 +542,22 @@ describe('Types', () => {
{ lengthField, lengthFieldBase: base },
);
originalLengthFieldValue.value = '0';
expect(definition['getDeserializeSize'](struct)).toBe(0);
originalLengthFieldValue.value = "0";
expect(definition["getDeserializeSize"](struct)).toBe(0);
expect(originalLengthFieldValue.get).toBeCalledTimes(1);
originalLengthFieldValue.get.mockClear();
originalLengthFieldValue.value = '100';
expect(definition['getDeserializeSize'](struct)).toBe(Number.parseInt('100', base));
originalLengthFieldValue.value = "100";
expect(definition["getDeserializeSize"](struct)).toBe(Number.parseInt("100", base));
expect(originalLengthFieldValue.get).toBeCalledTimes(1);
});
});
describe('#create', () => {
it('should create a `VariableLengthArrayBufferLikeFieldValue`', () => {
describe("#create", () => {
it("should create a `VariableLengthArrayBufferLikeFieldValue`", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -573,18 +573,18 @@ describe('Types', () => {
value,
);
expect(arrayBufferFieldValue).toHaveProperty('definition', definition);
expect(arrayBufferFieldValue).toHaveProperty('options', StructDefaultOptions);
expect(arrayBufferFieldValue).toHaveProperty('struct', struct);
expect(arrayBufferFieldValue).toHaveProperty('value', value);
expect(arrayBufferFieldValue).toHaveProperty('arrayBuffer', undefined);
expect(arrayBufferFieldValue).toHaveProperty('length', undefined);
expect(arrayBufferFieldValue).toHaveProperty("definition", definition);
expect(arrayBufferFieldValue).toHaveProperty("options", StructDefaultOptions);
expect(arrayBufferFieldValue).toHaveProperty("struct", struct);
expect(arrayBufferFieldValue).toHaveProperty("value", value);
expect(arrayBufferFieldValue).toHaveProperty("arrayBuffer", undefined);
expect(arrayBufferFieldValue).toHaveProperty("length", undefined);
});
it('should create a `VariableLengthArrayBufferLikeFieldValue` with `arrayBuffer`', () => {
it("should create a `VariableLengthArrayBufferLikeFieldValue` with `arrayBuffer`", () => {
const struct = new StructValue();
const lengthField = 'foo';
const lengthField = "foo";
const originalLengthFieldValue = new MockOriginalFieldValue();
struct.set(lengthField, originalLengthFieldValue);
@ -601,12 +601,12 @@ describe('Types', () => {
value,
);
expect(arrayBufferFieldValue).toHaveProperty('definition', definition);
expect(arrayBufferFieldValue).toHaveProperty('options', StructDefaultOptions);
expect(arrayBufferFieldValue).toHaveProperty('struct', struct);
expect(arrayBufferFieldValue).toHaveProperty('value', value);
expect(arrayBufferFieldValue).toHaveProperty('arrayBuffer', value);
expect(arrayBufferFieldValue).toHaveProperty('length', 100);
expect(arrayBufferFieldValue).toHaveProperty("definition", definition);
expect(arrayBufferFieldValue).toHaveProperty("options", StructDefaultOptions);
expect(arrayBufferFieldValue).toHaveProperty("struct", struct);
expect(arrayBufferFieldValue).toHaveProperty("value", value);
expect(arrayBufferFieldValue).toHaveProperty("arrayBuffer", value);
expect(arrayBufferFieldValue).toHaveProperty("length", 100);
});
});
});

View file

@ -1,6 +1,6 @@
import { StructFieldValue, type StructFieldDefinition, type StructOptions, type StructValue } from '../../basic';
import type { KeysOfType } from '../../utils';
import { BufferLikeFieldDefinition, BufferLikeFieldValue, type BufferFieldSubType } from './base';
import { StructFieldValue, type StructFieldDefinition, type StructOptions, type StructValue } from '../../basic/index.js';
import type { KeysOfType } from '../../utils.js';
import { BufferLikeFieldDefinition, BufferLikeFieldValue, type BufferFieldSubType } from './base.js';
export type LengthField<TFields> = KeysOfType<TFields, number | string>;

View file

@ -1,3 +1,3 @@
export * from './bigint';
export * from './buffer';
export * from './number';
export * from "./bigint.js";
export * from "./buffer/index.js";
export * from "./number.js";

View file

@ -1,83 +1,67 @@
import { StructDefaultOptions, StructDeserializeStream, StructValue } from '../basic';
import { NumberFieldDefinition, NumberFieldType } from './number';
import { StructDefaultOptions, StructDeserializeStream, StructValue } from "../basic/index.js";
import { NumberFieldDefinition, NumberFieldType } from "./number.js";
describe('Types', () => {
describe('Number', () => {
describe('NumberFieldType', () => {
it('Int8 validation', () => {
const key = 'Int8';
expect(NumberFieldType[key]).toHaveProperty('size', 1);
expect(NumberFieldType[key]).toHaveProperty('dataViewGetter', 'get' + key);
expect(NumberFieldType[key]).toHaveProperty('dataViewSetter', 'set' + key);
describe("Types", () => {
describe("Number", () => {
describe("NumberFieldType", () => {
it("Int8 validation", () => {
const key = "Int8";
expect(NumberFieldType[key]).toHaveProperty("size", 1);
expect(NumberFieldType[key]).toHaveProperty("dataViewGetter", "get" + key);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
it('Uint8 validation', () => {
const key = 'Uint8';
expect(NumberFieldType[key]).toHaveProperty('size', 1);
expect(NumberFieldType[key]).toHaveProperty('dataViewGetter', 'get' + key);
expect(NumberFieldType[key]).toHaveProperty('dataViewSetter', 'set' + key);
it("Uint8 validation", () => {
const key = "Uint8";
expect(NumberFieldType[key]).toHaveProperty("size", 1);
expect(NumberFieldType[key]).toHaveProperty("dataViewGetter", "get" + key);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
it('Int16 validation', () => {
const key = 'Int16';
expect(NumberFieldType[key]).toHaveProperty('size', 2);
expect(NumberFieldType[key]).toHaveProperty('dataViewGetter', 'get' + key);
expect(NumberFieldType[key]).toHaveProperty('dataViewSetter', 'set' + key);
it("Int16 validation", () => {
const key = "Int16";
expect(NumberFieldType[key]).toHaveProperty("size", 2);
expect(NumberFieldType[key]).toHaveProperty("dataViewGetter", "get" + key);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
it('Uint16 validation', () => {
const key = 'Uint16';
expect(NumberFieldType[key]).toHaveProperty('size', 2);
expect(NumberFieldType[key]).toHaveProperty('dataViewGetter', 'get' + key);
expect(NumberFieldType[key]).toHaveProperty('dataViewSetter', 'set' + key);
it("Uint16 validation", () => {
const key = "Uint16";
expect(NumberFieldType[key]).toHaveProperty("size", 2);
expect(NumberFieldType[key]).toHaveProperty("dataViewGetter", "get" + key);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
it('Int32 validation', () => {
const key = 'Int32';
expect(NumberFieldType[key]).toHaveProperty('size', 4);
expect(NumberFieldType[key]).toHaveProperty('dataViewGetter', 'get' + key);
expect(NumberFieldType[key]).toHaveProperty('dataViewSetter', 'set' + key);
it("Int32 validation", () => {
const key = "Int32";
expect(NumberFieldType[key]).toHaveProperty("size", 4);
expect(NumberFieldType[key]).toHaveProperty("dataViewGetter", "get" + key);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
it('Uint32 validation', () => {
const key = 'Uint32';
expect(NumberFieldType[key]).toHaveProperty('size', 4);
expect(NumberFieldType[key]).toHaveProperty('dataViewGetter', 'get' + key);
expect(NumberFieldType[key]).toHaveProperty('dataViewSetter', 'set' + key);
});
it('Int64 validation', () => {
const key = 'Int64';
expect(NumberFieldType[key]).toHaveProperty('size', 8);
expect(NumberFieldType[key]).toHaveProperty('dataViewGetter', 'getBig' + key);
expect(NumberFieldType[key]).toHaveProperty('dataViewSetter', 'setBig' + key);
});
it('Uint64 validation', () => {
const key = 'Uint64';
expect(NumberFieldType[key]).toHaveProperty('size', 8);
expect(NumberFieldType[key]).toHaveProperty('dataViewGetter', 'getBig' + key);
expect(NumberFieldType[key]).toHaveProperty('dataViewSetter', 'setBig' + key);
it("Uint32 validation", () => {
const key = "Uint32";
expect(NumberFieldType[key]).toHaveProperty("size", 4);
expect(NumberFieldType[key]).toHaveProperty("dataViewGetter", "get" + key);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
});
describe('NumberFieldDefinition', () => {
describe('#getSize', () => {
it('should return size of its type', () => {
describe("NumberFieldDefinition", () => {
describe("#getSize", () => {
it("should return size of its type", () => {
expect(new NumberFieldDefinition(NumberFieldType.Int8).getSize()).toBe(1);
expect(new NumberFieldDefinition(NumberFieldType.Uint8).getSize()).toBe(1);
expect(new NumberFieldDefinition(NumberFieldType.Int16).getSize()).toBe(2);
expect(new NumberFieldDefinition(NumberFieldType.Uint16).getSize()).toBe(2);
expect(new NumberFieldDefinition(NumberFieldType.Int32).getSize()).toBe(4);
expect(new NumberFieldDefinition(NumberFieldType.Uint32).getSize()).toBe(4);
expect(new NumberFieldDefinition(NumberFieldType.Int64).getSize()).toBe(8);
expect(new NumberFieldDefinition(NumberFieldType.Uint64).getSize()).toBe(8);
});
});
describe('#deserialize', () => {
it('should deserialize Uint8', async () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]).buffer);
describe("#deserialize", () => {
it("should deserialize Uint8", async () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]));
const stream: StructDeserializeStream = { read };
const definition = new NumberFieldDefinition(NumberFieldType.Uint8);
@ -93,8 +77,8 @@ describe('Types', () => {
expect(read).lastCalledWith(NumberFieldType.Uint8.size);
});
it('should deserialize Uint16', async () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]).buffer);
it("should deserialize Uint16", async () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]));
const stream: StructDeserializeStream = { read };
const definition = new NumberFieldDefinition(NumberFieldType.Uint16);
@ -110,8 +94,8 @@ describe('Types', () => {
expect(read).lastCalledWith(NumberFieldType.Uint16.size);
});
it('should deserialize Uint16LE', async () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]).buffer);
it("should deserialize Uint16LE", async () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]));
const stream: StructDeserializeStream = { read };
const definition = new NumberFieldDefinition(NumberFieldType.Uint16);
@ -129,9 +113,9 @@ describe('Types', () => {
});
});
describe('NumberFieldValue', () => {
describe('#getSize', () => {
it('should return size of its definition', () => {
describe("NumberFieldValue", () => {
describe("#getSize", () => {
it("should return size of its definition", () => {
const struct = new StructValue();
expect(
@ -193,31 +177,11 @@ describe('Types', () => {
)
.getSize()
).toBe(4);
expect(
new NumberFieldDefinition(NumberFieldType.Int64)
.create(
StructDefaultOptions,
struct,
BigInt(100),
)
.getSize()
).toBe(8);
expect(
new NumberFieldDefinition(NumberFieldType.Uint64)
.create(
StructDefaultOptions,
struct,
BigInt(100),
)
.getSize()
).toBe(8);
});
});
describe('#serialize', () => {
it('should serialize uint8', () => {
describe("#serialize", () => {
it("should serialize uint8", () => {
const definition = new NumberFieldDefinition(NumberFieldType.Int8);
const struct = new StructValue();
const value = definition.create(

View file

@ -1,8 +1,8 @@
// cspell: ignore syncbird
import { StructFieldDefinition, StructFieldValue, StructValue, type StructAsyncDeserializeStream, type StructDeserializeStream, type StructOptions } from '../basic';
import { Syncbird } from "../syncbird";
import type { ValueOrPromise } from "../utils";
import { StructFieldDefinition, StructFieldValue, StructValue, type StructAsyncDeserializeStream, type StructDeserializeStream, type StructOptions } from '../basic/index.js';
import { Syncbird } from "../syncbird.js";
import type { ValueOrPromise } from "../utils.js";
export type DataViewGetters =
{ [TKey in keyof DataView]: TKey extends `get${string}` ? TKey : never }[keyof DataView];

View file

@ -1,4 +1,4 @@
import { placeholder } from './utils';
import { placeholder } from './utils.js';
describe('placeholder', () => {
it('should return `undefined`', () => {

View file

@ -79,11 +79,10 @@ Or add a script to `package.json`
}
```
The builder compiles for both CommonJS and ESModule, also generates source maps, TypeScript declarations, and declaration maps.
The builder outputs Node.js compatible ES Module, with source maps, TypeScript declarations, and declaration maps.
| Module | Output Directory | Excluded Files | Excluded Types |
| ------------------ | ---------------- | -------------- | -------------- |
| CommonJS | `cjs` | - | - |
| ESModule | `esm` | `*.spec.ts` | `@types/jest` |
| Declaration (d.ts) | `dts` | `*.spec.ts` | `@types/jest` |
@ -91,8 +90,7 @@ Example `package.json`:
```json
{
"main": "cjs/index.js",
"module": "esm/index.js",
"main": "esm/index.js",
"types": "dts/index.d.ts",
}
```

View file

@ -3,7 +3,7 @@
"composite": true,
/* Basic Options */
"target": "ESNext", // /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "ESNext", // /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"module": "Node12", // /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": [ // /* Specify library files to be included in the compilation. */
"ESNext"
],
@ -35,7 +35,7 @@
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
/* Module Resolution Options */
"moduleResolution": "Node", // /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"moduleResolution": "Node12", // /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */