Skip to content

Commit

Permalink
produce TS types
Browse files Browse the repository at this point in the history
  • Loading branch information
evgnomon committed Nov 1, 2023
1 parent 37c9e3e commit ac1c457
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
npm ci
npm run fmt:check
npm run lint
npm run build
npm run test
- run: npm publish
env:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
npm ci
npm run fmt:check
npm run lint
npm run build
npm run test
./clapp migrate down
- run: ./clapp deinit -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/node_modules
/coverage
/types

# misc
.DS_Store
Expand Down
30 changes: 29 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import util from "node:util";
import Redis from "ioredis";
import mysql from "mysql";

/**
* @typedef {import('ioredis').Cluster} RedisCluster
*/

function resolveEndpoint(shard) {
let portNum = 3306 - 1 + shard;
if (process.env[`DB_SHARD_${shard}_INTERNAL_PORT`]) {
Expand Down Expand Up @@ -79,8 +83,32 @@ export class DB {
}
}

//eslint-disable-next-line no-unused-vars
class MEMConfig {
/**
* @type {string}
*/
MEM_SHARD_1_INTERNAL_HOST;
/**
* @type {string}
*/
MEM_SHARD_2_INTERNAL_HOST;
/**
* @type {string}
*/
MEM_SHARD_3_INTERNAL_HOST;
/**
* @type {number}
*/
MEM_INTERNAL_PORT;
}

export class MEM {
#conf;
/**
* constructor.
* @param {MEMConfig} [conf]
*/
constructor(conf) {
if (!conf) {
conf = {
Expand All @@ -107,7 +135,7 @@ export class MEM {

/**
* connect.
* @returns {Promise<Redis.Cluster>}
* @returns {Promise<RedisCluster>}
*/
async connect() {
const ports = [
Expand Down
18 changes: 6 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "@clusterlean/clusterlean-sdk-js",
"version": "0.3.5",
"main": "lib/index.js",
"main": "./lib/index.js",
"type": "module",
"types": "./types/index.d.ts",
"scripts": {
"lint": "eslint --max-warnings=0 '{src,test}/**/*.{js,jsx}' && tsc -p ./jsconfig.json",
"build": "tsc --declaration --emitDeclarationOnly --outDir types --allowJs --declarationMap lib/index.js",
"lint": "eslint --max-warnings=0 '{src,test}/**/*.{js,jsx}' && tsc --noEmit -p ./tsconfig.json",
"test": "mocha 'test/**/*.spec.{js,jsx}'",
"test:watch": "npm run test -- --watch --watch-files src,test",
"fmt:base": "prettier '{src,test}/**/*.{js,jsx}'",
Expand Down Expand Up @@ -43,14 +45,6 @@
},
"license": "MIT",
"description": "Clusterlean App SDK for JavaScript",
"files": [
"lib"
],
"keywords": [
"api",
"clusterlean",
"db",
"memory",
"sql"
]
"files": ["lib", "types"],
"keywords": ["api", "clusterlean", "db", "memory", "sql"]
}
6 changes: 3 additions & 3 deletions jsconfig.json → tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"compilerOptions": {
"typeRoots": ["./types", "./node_modules/@types"],
"baseUrl": ".",
"moduleResolution": "nodenext",
"checkJs": true,
"explainFiles": false,
"target": "esnext",
"module": "nodenext",
"strictNullChecks": true,
"resolveJsonModule": true,
"noEmit": true
"resolveJsonModule": true
},
"exclude": ["node_modules"]
"exclude": ["node_modules", "types"]
}

0 comments on commit ac1c457

Please sign in to comment.