Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Importing with .ts extensions #42

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/examples/customSchema/radians.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class RadiansSchema extends Schema<number> {
const low = discrete & 0xff;
const high = (discrete >> 8) & 0xff;

output.writeByte(low);
output.writeByte(high);
output.writeUint8(low);
output.writeUint8(high);
}

measure(
Expand Down
141 changes: 0 additions & 141 deletions packages/typed-binary/src/describe/index.ts

This file was deleted.

48 changes: 43 additions & 5 deletions packages/typed-binary/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
import * as bin from './main-api';
export * from './main-api';
import * as bin from './main-api.ts';
export * from './main-api.ts';
export { bin };
export default bin;

export * from './structure';
export { getSystemEndianness } from './util';
export type { ParseUnwrapped } from './utilityTypes';
export { getSystemEndianness } from './util.ts';
export { MaxValue, SubTypeKey } from './structure/types.ts';
export {
BoolSchema,
Float16Schema,
Float32Schema,
Int16Schema,
Int32Schema,
Int8Schema,
StringSchema,
Uint16Schema,
Uint32Schema,
Uint8Schema,
/** @deprecated Use Uint8Schema instead. */
Uint8Schema as ByteSchema,
} from './structure/baseTypes.ts';
export { ArraySchema } from './structure/array.ts';
export { CharsSchema } from './structure/chars.ts';
export { DynamicArraySchema } from './structure/dynamicArray.ts';
export { KeyedSchema } from './structure/keyed.ts';
export { ObjectSchema, GenericObjectSchema } from './structure/object.ts';
export { OptionalSchema } from './structure/optional.ts';
export { TupleSchema } from './structure/tuple.ts';
export { TypedArraySchema } from './structure/typedArray.ts';

export type { AnyObjectSchema } from './structure/object.ts';
export type {
Unwrap,
UnwrapRecord,
UnwrapArray,
IKeyedSchema,
Ref,
IRefResolver,
Schema,
ISchema,
AnyKeyedSchema,
AnySchema,
AnySchemaWithProperties,
ISchemaWithProperties,
} from './structure/types.ts';
export type { ParseUnwrapped } from './utilityTypes.ts';
6 changes: 3 additions & 3 deletions packages/typed-binary/src/io/bufferIOBase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSystemEndianness } from '../util';
import type { Endianness } from './types';
import { unwrapBuffer } from './unwrapBuffer';
import { getSystemEndianness } from '../util.ts';
import type { Endianness } from './types.ts';
import { unwrapBuffer } from './unwrapBuffer.ts';

export type BufferIOOptions = {
/**
Expand Down
8 changes: 4 additions & 4 deletions packages/typed-binary/src/io/bufferReader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BufferIOBase } from './bufferIOBase';
import { float16ToNumber } from './float16converter';
import type { ISerialInput } from './types';
import { unwrapBuffer } from './unwrapBuffer';
import { BufferIOBase } from './bufferIOBase.ts';
import { float16ToNumber } from './float16converter.ts';
import type { ISerialInput } from './types.ts';
import { unwrapBuffer } from './unwrapBuffer.ts';

export class BufferReader extends BufferIOBase implements ISerialInput {
private _cachedTextDecoder: TextDecoder | undefined;
Expand Down
18 changes: 10 additions & 8 deletions packages/typed-binary/src/io/bufferReaderWriter.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Buffer } from 'node:buffer';

import { describe, expect, it } from 'vitest';
import { randBetween, randIntBetween } from '../test/random';
import { getSystemEndianness } from '../util';
import { BufferReader } from './bufferReader';
import { BufferWriter } from './bufferWriter';
import { randBetween, randIntBetween } from '../test/random.ts';
import { getSystemEndianness } from '../util.ts';
import { BufferReader } from './bufferReader.ts';
import { BufferWriter } from './bufferWriter.ts';

describe('BufferWriter', () => {
it('should encode a Uint8Array', () => {
Expand Down Expand Up @@ -97,10 +99,10 @@ describe('BufferReader', () => {
it('should decode a Uint8Array', () => {
const buffer = Buffer.alloc(4);
const writer = new BufferWriter(buffer);
writer.writeByte(0);
writer.writeByte(15);
writer.writeByte(64);
writer.writeByte(255);
writer.writeUint8(0);
writer.writeUint8(15);
writer.writeUint8(64);
writer.writeUint8(255);

const destBuffer = new ArrayBuffer(4);
const destU8 = new Uint8Array(destBuffer);
Expand Down
8 changes: 4 additions & 4 deletions packages/typed-binary/src/io/bufferWriter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BufferIOBase } from './bufferIOBase';
import { numberToFloat16 } from './float16converter';
import type { ISerialOutput } from './types';
import { unwrapBuffer } from './unwrapBuffer';
import { BufferIOBase } from './bufferIOBase.ts';
import { numberToFloat16 } from './float16converter.ts';
import type { ISerialOutput } from './types.ts';
import { unwrapBuffer } from './unwrapBuffer.ts';

export class BufferWriter extends BufferIOBase implements ISerialOutput {
private _cachedTextEncoder: TextEncoder | undefined;
Expand Down
4 changes: 0 additions & 4 deletions packages/typed-binary/src/io/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/typed-binary/src/io/measurer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IMeasurer } from './types';
import type { IMeasurer } from './types.ts';

class UnboundedMeasurer implements IMeasurer {
size = Number.NaN;
Expand Down
2 changes: 1 addition & 1 deletion packages/typed-binary/src/io/unwrapBuffer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { unwrapBuffer } from './unwrapBuffer';
import { unwrapBuffer } from './unwrapBuffer.ts';

describe('unwrapBuffer', () => {
it('returns the input if given an array buffer', () => {
Expand Down
53 changes: 48 additions & 5 deletions packages/typed-binary/src/main-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
export { MaxValue } from './structure';
export * from './describe';
export * from './io';
export * from './error';
export { arrayOf } from './structure/array.ts';
export {
bool,
byte,
i8,
u8,
i16,
u16,
i32,
u32,
f16,
f32,
string,
} from './structure/baseTypes.ts';
export { chars } from './structure/chars.ts';
export { concat } from './structure/concat.ts';
export { dynamicArrayOf } from './structure/dynamicArray.ts';
export { keyed } from './structure/keyed.ts';
export { object, generic, genericEnum } from './structure/object.ts';
export { optional } from './structure/optional.ts';
export { tupleOf } from './structure/tuple.ts';
export {
f32Array,
f64Array,
i16Array,
i32Array,
i8Array,
u16Array,
u32Array,
u8Array,
u8ClampedArray,
} from './structure/typedArray.ts';
export { MaxValue } from './structure/types.ts';

export type { Parsed } from './utilityTypes';
export { BufferReader } from './io/bufferReader.ts';
export { BufferWriter } from './io/bufferWriter.ts';
export { Measurer } from './io/measurer.ts';
export {
UnresolvedReferenceError,
ValidationError,
} from './error.ts';

export type {
Endianness,
IMeasurer,
ISerialInput,
ISerialOutput,
} from './io/types.ts';
export type { Parsed } from './utilityTypes.ts';
10 changes: 0 additions & 10 deletions packages/typed-binary/src/structure/_internal.ts

This file was deleted.

Loading
Loading