Skip to content

Commit

Permalink
Snappy TS to JS
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Jan 4, 2024
1 parent b9efa71 commit e64cbec
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"type": "module",
"types": "dist/hyparquet.d.ts",
"scripts": {
"build": "tsc",
"build": "tsc && cp src/*.js dist",
"coverage": "vitest run --coverage",
"demo": "http-server -o",
"lint": "eslint . --ext .ts",
Expand Down
7 changes: 4 additions & 3 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ export function schemaElement(schema: SchemaElement[], name: string[]): SchemaEl
* @param {unknown} obj object to convert
* @returns {unknown} converted object
*/
export function toJson(obj: unknown): unknown {
export function toJson(obj: any): unknown {
if (typeof obj === 'bigint') {
return Number(obj)
} else if (Array.isArray(obj)) {
return obj.map(toJson)
} else if (typeof obj === 'object') {
const newObj = {}
} else if (obj instanceof Object) {
/** @type {Record<string, unknown>} */
const newObj: Record<string, unknown> = {}
for (const key of Object.keys(obj)) {
newObj[key] = toJson(obj[key])
}
Expand Down
6 changes: 3 additions & 3 deletions src/snappy.ts → src/snappy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const WORD_MASK = [0, 0xff, 0xffff, 0xffffff, 0xffffffff]
* @param {number} length number of bytes to copy
* @returns {void}
*/
function copyBytes(fromArray: Uint8Array, fromPos: number, toArray: Uint8Array, toPos: number, length: number) {
function copyBytes(fromArray, fromPos, toArray, toPos, length) {
for (let i = 0; i < length; i++) {
toArray[toPos + i] = fromArray[fromPos + i]
}
Expand All @@ -25,7 +25,7 @@ function copyBytes(fromArray: Uint8Array, fromPos: number, toArray: Uint8Array,
* @param {number} length number of bytes to copy
* @returns {void}
*/
function selfCopyBytes(array: Uint8Array, pos: number, offset: number, length: number) {
function selfCopyBytes(array, pos, offset, length) {
for (let i = 0; i < length; i++) {
array[pos + i] = array[pos - offset + i]
}
Expand All @@ -39,7 +39,7 @@ function selfCopyBytes(array: Uint8Array, pos: number, offset: number, length: n
* @param {Uint8Array} outputArray output buffer
* @returns {boolean} true if successful
*/
export function snappyUncompress(inputArray: Uint8Array, outputArray: Uint8Array): boolean {
export function snappyUncompress(inputArray, outputArray) {
const inputLength = inputArray.byteLength

let pos = 0
Expand Down
6 changes: 4 additions & 2 deletions src/thrift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export function deserializeTCompactProtocol(arrayBuffer: ArrayBuffer): Decoded<R
const view = new DataView(arrayBuffer)
let byteLength = 0
let lastFid = 0
const value = {}
/** @type {Record<string, any>} */
const value: Record<string, any> = {}

while (byteLength < arrayBuffer.byteLength) {
// Parse each field based on its type and add to the result object
Expand Down Expand Up @@ -91,7 +92,8 @@ function readElement(view: DataView, type: number, index: number): [any, number]
return [listValues, index]
}
case CompactType.STRUCT: {
const structValues = {}
/** @type {Record<string, any>} */
const structValues: Record<string, any> = {}
let structLastFid = 0
while (true) {
let structFieldType, structFid, structIndex
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"compilerOptions": {
"declaration": true,
"allowJs": true,
"checkJs": true,
"lib": ["esnext", "dom"],
"module": "nodenext",
"outDir": "dist",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "esnext",
},
"include": ["src"]
Expand Down

0 comments on commit e64cbec

Please sign in to comment.