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

feat(bytes): add bytes package #2

Merged
merged 6 commits into from
Feb 22, 2025
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
11 changes: 11 additions & 0 deletions .github/workflows/pull_request_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ jobs:
permissions:
pull-requests: read
outputs:
bytes: ${{ steps.filter.outputs.bytes }}
uuid: ${{ steps.filter.outputs.uuid }}
steps:
- name: "πŸ“₯ Filter"
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
bytes:
- 'packages/bytes/**'
uuid:
- 'packages/uuid/**'

Expand Down Expand Up @@ -47,6 +50,14 @@ jobs:
# package specific
##

bytes:
name: "@agoralabs-sh/bytes"
needs: [changed_files, validate_pr_title]
if: ${{ needs.changed_files.outputs.bytes == 'true' }}
uses: ./.github/workflows/lint_build_test.yml
with:
package_name: "@agoralabs-sh/bytes"

uuid:
name: "@agoralabs-sh/uuid"
needs: [changed_files, validate_pr_title]
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ permissions:
packages: write # to be able to publish packages
pull-requests: write # to be able to comment on released pull requests

# each job **MUST** run sequentially as a potential release will alter commit and push a CHANGELOG and bump its package version
jobs:
bytes:
name: "@agoralabs-sh/bytes"
uses: ./.github/workflows/publish_release.yml
with:
package_dir: "bytes"
package_name: "@agoralabs-sh/bytes"
secrets:
NPM_TOKEN: ${{ secrets.PUBLISH_PUBLIC_PACKAGES_TOKEN }}

uuid:
needs: [bytes]
name: "@agoralabs-sh/uuid"
uses: ./.github/workflows/publish_release.yml
with:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ pnpm install

### 3.1. Packages

| Name | Visibility | Description | Package |
|--------------------------------------|------------|-------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| [`uuid`](./packages/types/README.md) | `public` | A UUID v4 utility package that allows generation and encoding/decoding. | [![NPM Version](https://img.shields.io/npm/v/%40agoralabs-sh%2Fuuid)](https://www.npmjs.com/package/%40agoralabs-sh/uuid) |
| Name | Visibility | Description | Package |
|--------------------------------------------------|------------|-------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| [`@agoralabs/bytes`](./packages/bytes/README.md) | `public` | Utilities for handling byte arrays. | [![NPM Version](https://img.shields.io/npm/v/%40agoralabs-sh%2Fbytes)](https://www.npmjs.com/package/%40agoralabs-sh/bytes) |
| [`@agoralabs/uuid`](./packages/uuid/README.md) | `public` | A UUID v4 utility package that allows generation and encoding/decoding. | [![NPM Version](https://img.shields.io/npm/v/%40agoralabs-sh%2Fuuid)](https://www.npmjs.com/package/%40agoralabs-sh/uuid) |

<sup>[Back to top ^][table-of-contents]</sup>

Expand Down
12 changes: 12 additions & 0 deletions packages/bytes/.lintstagedrc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { resolve } from 'node:path';

export default (() => {
const packageName = 'bytes';

return {
'**/*.{cjs,js,json,mjs,ts}': (filenames) => [
`sh -c 'pnpm -F @agoralabs-sh/${packageName} run generate:index && git add ${resolve(process.cwd(), 'packages', packageName, 'src', 'index.ts')}'`,
`prettier --write ${filenames.join(' ')}`, // exclude this file
],
};
})();
2 changes: 2 additions & 0 deletions packages/bytes/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
116 changes: 116 additions & 0 deletions packages/bytes/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
CC0 1.0 Universal

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator and
subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for the
purpose of contributing to a commons of creative, cultural and scientific
works ("Commons") that the public can reliably and without fear of later
claims of infringement build upon, modify, incorporate in other works, reuse
and redistribute as freely as possible in any form whatsoever and for any
purposes, including without limitation commercial purposes. These owners may
contribute to the Commons to promote the ideal of a free culture and the
further production of creative, cultural and scientific works, or to gain
reputation or greater distribution for their Work in part through the use and
efforts of others.

For these and/or other purposes and motivations, and without any expectation
of additional consideration or compensation, the person associating CC0 with a
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
and publicly distribute the Work under its terms, with knowledge of his or her
Copyright and Related Rights in the Work and the meaning and intended legal
effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not limited
to, the following:

i. the right to reproduce, adapt, distribute, perform, display, communicate,
and translate a Work;

ii. moral rights retained by the original author(s) and/or performer(s);

iii. publicity and privacy rights pertaining to a person's image or likeness
depicted in a Work;

iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;

v. rights protecting the extraction, dissemination, use and reuse of data in
a Work;

vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation thereof,
including any amended or successor version of such directive); and

vii. other similar, equivalent or corresponding rights throughout the world
based on applicable law or treaty, and any national implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention of,
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
and Related Rights and associated claims and causes of action, whether now
known or unknown (including existing as well as future claims and causes of
action), in the Work (i) in all territories worldwide, (ii) for the maximum
duration provided by applicable law or treaty (including future time
extensions), (iii) in any current or future medium and for any number of
copies, and (iv) for any purpose whatsoever, including without limitation
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
the Waiver for the benefit of each member of the public at large and to the
detriment of Affirmer's heirs and successors, fully intending that such Waiver
shall not be subject to revocation, rescission, cancellation, termination, or
any other legal or equitable action to disrupt the quiet enjoyment of the Work
by the public as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason be
judged legally invalid or ineffective under applicable law, then the Waiver
shall be preserved to the maximum extent permitted taking into account
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
is so judged Affirmer hereby grants to each affected person a royalty-free,
non transferable, non sublicensable, non exclusive, irrevocable and
unconditional license to exercise Affirmer's Copyright and Related Rights in
the Work (i) in all territories worldwide, (ii) for the maximum duration
provided by applicable law or treaty (including future time extensions), (iii)
in any current or future medium and for any number of copies, and (iv) for any
purpose whatsoever, including without limitation commercial, advertising or
promotional purposes (the "License"). The License shall be deemed effective as
of the date CC0 was applied by Affirmer to the Work. Should any part of the
License for any reason be judged legally invalid or ineffective under
applicable law, such partial invalidity or ineffectiveness shall not
invalidate the remainder of the License, and in such case Affirmer hereby
affirms that he or she will not (i) exercise any of his or her remaining
Copyright and Related Rights in the Work or (ii) assert any associated claims
and causes of action with respect to the Work, in either case contrary to
Affirmer's express Statement of Purpose.

4. Limitations and Disclaimers.

a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.

b. Affirmer offers the Work as-is and makes no representations or warranties
of any kind concerning the Work, express, implied, statutory or otherwise,
including without limitation warranties of title, merchantability, fitness
for a particular purpose, non infringement, or the absence of latent or
other defects, accuracy, or the present or absence of errors, whether or not
discoverable, all to the greatest extent permissible under applicable law.

c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without limitation
any person's Copyright and Related Rights in the Work. Further, Affirmer
disclaims responsibility for obtaining any necessary consents, permissions
or other rights required for any use of the Work.

d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to this
CC0 or use of the Work.

For more information, please see
<http://creativecommons.org/publicdomain/zero/1.0/>
76 changes: 76 additions & 0 deletions packages/bytes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<div align="center">

[![License: CC0-1.0](https://img.shields.io/badge/License-CC0_1.0-brightgreen.svg)](./LICENSE)
[![NPM Version](https://img.shields.io/npm/v/%40agoralabs-sh%2Fbytes)](https://www.npmjs.com/package/%40agoralabs-sh/bytes)

</div>

<div align="center">

![GitHub Release](https://img.shields.io/github/v/release/agoralabs-sh/instrumentum?filter=%40agoralabs-sh%2Fbytes*)
![GitHub Release](https://img.shields.io/github/v/release/agoralabs-sh/instrumentum?include_prereleases&filter=%40agoralabs-sh%2Fbytes*&label=pre-release)

</div>

<h1 align="center">
@agoralabs/bytes
</h1>

<p align="center">
Utilities for handling byte arrays.
</p>

---

### Table Of Contents

* [1. Getting Started](#-2-getting-started)
- [1.1. Installation](#12-installation)
* [2. Appendix](#-2-appendix)
- [2.1. Useful Commands](#21-useful-commands)
* [3. How To Contribute](#-3-how-to-contribute)
* [4. License](#-4-license)

## πŸͺ„ 1. Getting Started

### 1.1. Installation

You can install the types using:
```shell
pnpm add @agoralabs-sh/bytes
```

<sup>[Back to top ^][table-of-contents]</sup>

## πŸ“‘ 2. Appendix

### 2.1. Useful Commands

| Command | Description |
|-----------------------|-----------------------------------------------------------------------------|
| `pnpm build` | Generates build and TypeScript declaration files to the `dist/` directory. |
| `pnpm clean` | Deletes the `dist/` directory and the `tsconfig.*.tsbuildinfo` files. |
| `pnpm generate:index` | Generates/overwrites the main `index.ts` file used for exporting all files. |
| `pnpm lint` | Runs the linter based on the rules in `eslint.config.mjs`. |
| `pnpm prettier` | Runs the prettier based on the rules in `prettier.config.mjs`. |
| `pnpm test` | Runs Vitest. |

<sup>[Back to top ^][table-of-contents]</sup>

## πŸ‘ 3. How To Contribute

Please read the [**Contributing Guide**][contribute] to learn about the development process.

<sup>[Back to top ^][table-of-contents]</sup>

## πŸ“„ 4. License

Please refer to the [LICENSE][license] file.

<sup>[Back to top ^][table-of-contents]</sup>

<!-- links -->
[contribute]: ../../CONTRIBUTING.md
[license]: LICENSE
[table-of-contents]: #table-of-contents

33 changes: 33 additions & 0 deletions packages/bytes/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import eslint from '@eslint/js';
import globals from 'globals';
import prettierConfig from 'eslint-config-prettier';
import typescriptConfig from 'typescript-eslint';

/**
* @type {import('eslint').Linter.Config[]}
**/
export default [
eslint.configs.recommended,
...typescriptConfig.configs.recommended,
prettierConfig,
// custom config
{
files: ['**/*.{js,mjs,cjs,ts}'],
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
},
},
{
ignores: ['dist/', 'node_modules/'],
},
{
rules: {
'prefer-const': 'off',
},
},
];
52 changes: 52 additions & 0 deletions packages/bytes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@agoralabs-sh/bytes",
"version": "1.0.0",
"description": "Utilities for handling byte arrays.",
"repository": {
"type": "git",
"url": "https://github.com/agoralabs-sh/avm-tools"
},
"author": {
"name": "Kieran O'Neill",
"email": "hello@kieranoneill.com",
"url": "https://github.com/kieranroneill"
},
"license": "CC0-1.0",
"private": false,
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"LICENSE"
],
"scripts": {
"build": "pnpm run clean && vite build",
"build:dependencies": "exit 0",
"clean": "shx rm -rf dist && shx rm -rf tsconfig.*.tsbuildinfo",
"generate:index": "tsx ./scripts/generate-index.ts",
"lint": "eslint .",
"prettier": "prettier --write \"**/*.{cjs,js,json,mjs,ts}\"",
"test": "vitest run --config vitest.config.ts"
},
"dependencies": {
"@stablelib/bytes": "^2.0.1"
},
"devDependencies": {
"@eslint/js": "catalog:",
"@types/node": "catalog:",
"chalk": "catalog:",
"eslint": "catalog:",
"eslint-config-prettier": "catalog:",
"globals": "catalog:",
"prettier": "catalog:",
"shx": "catalog:",
"tsx": "catalog:",
"typescript": "catalog:",
"typescript-eslint": "catalog:",
"vite": "catalog:",
"vite-plugin-dts": "catalog:",
"vite-tsconfig-paths": "catalog:",
"vitest": "catalog:"
}
}
3 changes: 3 additions & 0 deletions packages/bytes/prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import defaultConfig from '../../prettier.config.mjs';

export default defaultConfig;
Loading