Skip to content

Commit

Permalink
Merge pull request #72 from hopinc/feat/ts@next
Browse files Browse the repository at this point in the history
  • Loading branch information
alii authored Mar 18, 2023
2 parents 9ccae4b + 0b4f018 commit 361bd70
Show file tree
Hide file tree
Showing 44 changed files with 1,434 additions and 900 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-planes-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@onehop/js': patch
---

Converted to .ts imports, added some byte helper fns (from hop-go)
5 changes: 5 additions & 0 deletions .changeset/funny-goats-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@onehop/js': patch
---

Properly JSDoc all symbols
5 changes: 5 additions & 0 deletions .changeset/polite-garlics-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@onehop/js': minor
---

Convert to ts 5, export more symbols, deprecate some others
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ node_modules
.DS_Store
dist
_workbench.ts
docs
.env
temp
.next
docs
package.tgz
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"yaml.schemas": {
"https://json.schemastore.org/github-action.json": "./.github/workflows/build.yml"
},
"typescript.tsdk": "node_modules/typescript/lib"
}
49 changes: 49 additions & 0 deletions api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",

"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts",

"bundledPackages": [],

"compiler": {
"overrideTsconfig": {
"moduleResolution": "NodeNext"
}
},

"apiReport": {
"enabled": true,
"reportFolder": "<projectFolder>/temp"
},

"docModel": {
"enabled": true,
"apiJsonFilePath": "<projectFolder>/temp/js.api.json"
},

"dtsRollup": {
"enabled": false
},

"tsdocMetadata": {},

"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"extractorMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"tsdocMessageReporting": {
"default": {
"logLevel": "warning"
}
}
}
}
19 changes: 19 additions & 0 deletions build/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {copyFileSync, readdirSync} from 'node:fs';
import {join} from 'node:path';
import {fileURLToPath} from 'node:url';

const dist = join(fileURLToPath(import.meta.url), '..', '..', 'dist');

const utils = readdirSync(join(dist, 'utils'));

const copy = (from, to) => {
copyFileSync(join(dist, from), join(dist, to));
};

copy('index.d.ts', 'index.d.cts');

for (const util of utils) {
copy(`utils/${util}/index.d.ts`, `utils/${util}/index.d.cts`);
}

copy('node/index.d.ts', 'node/index.d.cts');
37 changes: 17 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
{
"name": "@onehop/js",
"version": "1.29.0",
"type": "module",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"node": {
"import": "./dist/node/index.js",
"require": "./dist/node/index.cjs",
"types": "./dist/index.d.ts"
"require": "./dist/node/index.cjs"
},
"browser": "./dist/index.js",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"require": "./dist/index.cjs"
},
"./utils/zod": {
"import": "./dist/utils/zod/index.js",
"require": "./dist/utils/zod/index.cjs",
"types": "./dist/utils/zod/index.d.ts"
"require": "./dist/utils/zod/index.cjs"
}
},
"type": "module",
"repository": "https://github.com/hopinc/js.git",
"homepage": "https://hop.io",
"author": "Hop <[email protected]>",
Expand All @@ -40,29 +36,30 @@
"utils"
],
"scripts": {
"build": "rm -rf dist && tsup",
"build": "rm -rf dist && tsup && node ./build/copy.js",
"bench": "HOP_DEBUG=true tsx _workbench.ts",
"release": "yarn build && yarn changeset publish",
"vercel-build": "yarn typedoc --plugin typedoc-plugin-missing-exports src/index.ts",
"test": "tsx tests/index.ts"
"fullbuild": "yarn build && yarn docs",
"test": "tsx tests/index.ts",
"package": "yarn build && yarn pack"
},
"devDependencies": {
"@changesets/cli": "2.26.0",
"@types/glob": "8.0.1",
"@types/node": "18.13.0",
"@types/glob": "8.1.0",
"@types/node": "18.15.3",
"dotenv": "16.0.3",
"glob": "8.1.0",
"glob": "9.3.0",
"prettier": "2.8.4",
"tsup": "6.6.0",
"tsx": "3.12.3",
"typedoc": "0.23.24",
"tsup": "6.6.3",
"tsx": "3.12.5",
"typedoc": "0.23.27",
"typedoc-plugin-markdown": "3.14.0",
"typedoc-plugin-missing-exports": "1.0.0",
"typescript": "^4.9.5"
"typescript": "^5.0.2"
},
"dependencies": {
"@onehop/json-methods": "^1.2.0",
"cross-fetch": "^3.1.5",
"zod": "^3.20.3"
"zod": "^3.21.4"
}
}
6 changes: 2 additions & 4 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"]
}
19 changes: 15 additions & 4 deletions src/hop.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import {APIAuthentication, APIClient, APIClientOptions} from './rest/client.js';
import {
type APIAuthentication,
APIClient,
type APIClientOptions,
} from './rest/client.ts';
import {
channels,
ignite,
pipe,
projects,
registry,
users,
} from './sdks/index.js';
import {DEFAULT_BASE_URL} from './util/constants.js';
} from './sdks/index.ts';
import {DEFAULT_BASE_URL} from './util/constants.ts';

/**
* Partial options for the Hop client
* @public
*/
export type PartialAPIOptions = Partial<
Omit<APIClientOptions, 'authentication'>
> &
Pick<APIClientOptions, 'authentication'>;

/**
* Constructs a new instance of Hop and all of its SDKs.
* Root class containing all methods and types for interacting with the Hop platform.
* This will be the entrypoint for most users of the Hop SDK.
*
* @public
*
* @example
* ```ts
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * from './hop.js';
export * from './permissions.js';
export * from './rest/index.js';
export {type APIAuthentication} from './rest/index.js';
export {ChannelType} from './rest/types/channels.js';
export * from './hop.ts';
export * from './permissions.ts';
export * from './rest/index.ts';
export {type APIAuthentication} from './rest/index.ts';
export {ChannelType} from './rest/types/channels.ts';
export {
BuildMethod,
BuildState,
Expand All @@ -13,5 +13,5 @@ export {
RuntimeType,
VolumeFormat,
type BuildEnvironment,
} from './rest/types/ignite.js';
export * from './util/index.js';
} from './rest/types/ignite.ts';
export * from './util/index.ts';
20 changes: 20 additions & 0 deletions src/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* A list of all permissions and their representative names
* @public
*/
export enum PROJECT_PERMISSION {
ADD_MEMBER = 'add_member',
REMOVE_MEMBER = 'remove_member',
Expand Down Expand Up @@ -47,6 +51,10 @@ export enum PROJECT_PERMISSION {
TUNNEL_DEPLOYMENT = 'tunnel_deployment',
}

/**
* Individual bitwise permissions
* @public
*/
export const permissionsMap = {
[PROJECT_PERMISSION.ADD_MEMBER]: 1n << 0n,
[PROJECT_PERMISSION.REMOVE_MEMBER]: 1n << 1n,
Expand Down Expand Up @@ -96,6 +104,10 @@ export const permissionsMap = {
[PROJECT_PERMISSION.TUNNEL_DEPLOYMENT]: 1n << 46n,
};

/**
* Broader permission map
* @public
*/
export const BROAD_PERMISSIONS_MAP = {
MANAGE_MEMBERS:
permissionsMap.add_member |
Expand Down Expand Up @@ -160,6 +172,10 @@ export const BROAD_PERMISSIONS_MAP = {
MANAGE_BILLING: permissionsMap.read_billing,
};

/**
* Bitwise role flags that a user can be as part of a project
* @public
*/
export const roles = {
viewer: BROAD_PERMISSIONS_MAP.READ_ONLY,
editor:
Expand Down Expand Up @@ -192,6 +208,10 @@ export const roles = {
BROAD_PERMISSIONS_MAP.MANAGE_BILLING,
};

/**
* Permission utility functions
* @public
*/
export const permissions = {
add(value: bigint, flag: bigint) {
return BigInt(value) | BigInt(flag);
Expand Down
Loading

0 comments on commit 361bd70

Please sign in to comment.