Skip to content

Commit

Permalink
factor code in packages/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
severo committed Nov 15, 2024
1 parent 556fd03 commit 028eeb2
Show file tree
Hide file tree
Showing 32 changed files with 793 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci_apps_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: npm i
- run: npm run build
working-directory: ./packages/utils
- run: npm run build
working-directory: ./packages/components
- run: tsc
Expand All @@ -46,6 +48,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: npm i
- run: npm run build
working-directory: ./packages/utils
- run: npm run build
working-directory: ./packages/components
- run: npm run build
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci_apps_hyparquet_demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: npm i
- run: npm run build
working-directory: ./packages/utils
- run: tsc

buildcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm i
- run: npm run build
working-directory: ./packages/utils
- run: npm run build
4 changes: 4 additions & 0 deletions .github/workflows/ci_packages_components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: npm i
- run: npm run build
working-directory: ./packages/utils
- run: tsc

test:
Expand All @@ -37,3 +39,5 @@ jobs:
- uses: actions/checkout@v4
- run: npm i
- run: npm run build
working-directory: ./packages/utils
- run: npm run build
39 changes: 39 additions & 0 deletions .github/workflows/ci_packages_utils..yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: packages/utils
on:
push:
paths:
- 'packages/utils/**'
- '.github/workflows/ci_packages_utils.yml'

defaults:
run:
working-directory: ./packages/utils

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm i
- run: npm run lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm i
- run: tsc

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm i
- run: npm run coverage

buildcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm i
- run: npm run build
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This is a monorepo for the Hyperparam project.

It contains the following package:
- [`@hyparam/components`](./packages/components): a library of React components for building Hyperparam UIs.
- [`@hyparam/utils`](./packages/utils): a library of utils.

It also contains the following applications:
- [`hyperparam`](./apps/cli): a cli tool for viewing arbitrarily large datasets in the browser.
Expand Down
1 change: 1 addition & 0 deletions apps/hyparquet-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"@hyparam/utils": "file:../../packages/utils",
"hyparquet": "1.5.0",
"hyparquet-compressors": "0.1.4",
"hightable": "0.7.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/hyparquet-demo/src/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cn } from '@hyparam/utils'
import { ReactNode, useEffect, useRef, useState } from 'react'
import { cn } from './utils.js'

interface DropdownProps {
label?: string
Expand Down
2 changes: 1 addition & 1 deletion apps/hyparquet-demo/src/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cn } from '@hyparam/utils'
import { ReactNode, useEffect } from 'react'
import { cn } from './utils.js'

interface LayoutProps {
children: ReactNode
Expand Down
11 changes: 0 additions & 11 deletions apps/hyparquet-demo/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import { AsyncBuffer, asyncBufferFromUrl, cachedAsyncBuffer } from 'hyparquet'
import { AsyncBufferFrom } from './workers/types'

/**
* Helper function to join class names.
* Filters out falsy values and joins the rest.
*
* @param {...string | undefined | false} names - class name(s) to join
* @returns {string}
*/
export function cn(...names: (string | undefined | false)[]): string {
return names.filter(n => n).join(' ')
}

/**
* Convert AsyncBufferFromUrl to AsyncBuffer.
*/
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"apps/cli",
"apps/hightable-demo",
"apps/hyparquet-demo",
"packages/components"
"packages/components",
"packages/utils"
]
}
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"test": "vitest run"
},
"dependencies": {
"@hyparam/utils": "file:../utils",
"hightable": "0.6.3",
"hyparquet": "1.5.0",
"hyparquet-compressors": "0.1.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Folder.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cn } from '@hyparam/utils'
import { useCallback, useEffect, useRef, useState } from 'react'
import { FileMetadata, getFileDate, getFileDateShort, getFileSize, listFiles } from '../lib/files.js'
import type { FolderKey } from '../lib/key.js'
import { cn } from '../lib/utils.js'
import Layout, { Spinner } from './Layout.js'

interface FolderProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cn } from '@hyparam/utils'
import { ReactNode, useEffect } from 'react'
import { cn } from '../lib/utils.js'

interface LayoutProps {
children: ReactNode
Expand Down
2 changes: 1 addition & 1 deletion packages/components/test/components/Layout.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cn } from '@hyparam/utils'
import { render } from '@testing-library/react'
import React from 'react'
import { describe, expect, it, vi } from 'vitest'
import Layout, { Spinner } from '../../src/components/Layout.js'
import { cn } from '../../src/lib/utils.js'

vi.mock('next-auth/react', () => ({ signOut: vi.fn(), useSession: vi.fn() }))
vi.mock('next/link', () => ({ default: vi.fn() }))
Expand Down
33 changes: 33 additions & 0 deletions packages/utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local
coverage

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

package-lock.json
*.tgz
.vscode
*.parquet
/coverage/

/es
7 changes: 7 additions & 0 deletions packages/utils/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions packages/utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# React components for hyparam apps

This package contains the React components for the hyparam apps.
40 changes: 40 additions & 0 deletions packages/utils/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import js from '@eslint/js'
import globals from 'globals'
import tseslint from 'typescript-eslint'
import { sharedJsRules, sharedTsRules } from '../../shared.eslint.config.js'

export default tseslint.config(
{ ignores: ['coverage/', 'dist/', 'es/'] },
{
extends: [js.configs.recommended, ...tseslint.configs.strictTypeChecked, ...tseslint.configs.stylisticTypeChecked],
files: ['**/*.{ts,js}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
project: ['./tsconfig.json', './tsconfig.eslint.json'],
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
...js.configs.recommended.rules,
...tseslint.configs.recommended.rules,
...sharedJsRules,
...sharedTsRules,
},
},
{
files: ['test/**/*.{ts}', '*.{js,ts}'],
languageOptions: {
ecmaVersion: 2020,
globals: {
...globals.node,
...globals.browser,
},
},
},
{
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
},
)
54 changes: 54 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@hyparam/utils",
"version": "0.1.0",
"description": "Utils for hyparam apps",
"keywords": [
"data",
"javascript"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/hyparam/hyperparam-cli.git",
"directory": "packages/utils"
},
"type": "module",
"main": "dist/index.umd.min.js",
"unpkg": "dist/index.umd.min.js",
"module": "dist/index.es.min.js",
"types": "es/index.d.ts",
"exports": {
".": {
"import": "./dist/index.es.min.js",
"require": "./dist/index.umd.min.js",
"types": "./es/index.d.ts"
}
},
"files": [
"dist",
"es"
],
"scripts": {
"build": "tsc && vite build",
"coverage": "vitest run --coverage --coverage.include=src",
"lint": "eslint .",
"prepublishOnly": "npm run build",
"test": "vitest run"
},
"dependencies": {
"hightable": "0.6.3",
"hyparquet": "1.5.0",
"hyparquet-compressors": "0.1.4"
},
"devDependencies": {
"@eslint/js": "9.14.0",
"@types/node": "22.9.0",
"@vitest/coverage-v8": "2.1.4",
"eslint": "9.14.0",
"globals": "15.11.0",
"typescript": "5.6.3",
"typescript-eslint": "8.13.0",
"vite": "5.4.10",
"vitest": "2.1.4"
}
}
Loading

0 comments on commit 028eeb2

Please sign in to comment.