@togatherlabs/shared-protos 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/generate-indexes.js +93 -0
- package/package.json +33 -0
- package/tsconfig.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# ๐ฆ ToGather TypeScript Package
|
|
2
|
+
|
|
3
|
+
This package contains a shared **TypeScript package** used across the ToGather ecosystem.
|
|
4
|
+
|
|
5
|
+
It provides reusable modules, types, and utilities that ensure **consistency**, **type safety**, and **faster development** across all ToGather backend and frontend services.
|
|
6
|
+
|
|
7
|
+
## ๐ Overview
|
|
8
|
+
|
|
9
|
+
This package is published to the **ToGather NPM organization** under:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
@togatherr/togather-shared-protos
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
It is designed for internal use within our microservices architecture.
|
|
16
|
+
|
|
17
|
+
## ๐ฆ Installation
|
|
18
|
+
|
|
19
|
+
Install the package using **pnpm**:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @togatherr/togather-shared-protos
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## ๐ง Usage Example
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { LoginRequestSchema } from "@togatherr/togather-shared-protos";
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## ๐งฎ Versioning Rules
|
|
32
|
+
|
|
33
|
+
We use **Semantic Versioning (SemVer)**:
|
|
34
|
+
|
|
35
|
+
| Change Type | Example | Description |
|
|
36
|
+
| ----------- | ------------------- | -------------------------------------------- |
|
|
37
|
+
| **Patch** | `npm version patch` | Fixes or small improvements (no API changes) |
|
|
38
|
+
| **Minor** | `npm version minor` | Adds backward-compatible features |
|
|
39
|
+
| **Major** | `npm version major` | Breaking changes (API or behavior changes) |
|
|
40
|
+
|
|
41
|
+
### ๐ Examples
|
|
42
|
+
|
|
43
|
+
- Added new optional field in proto โ **minor**
|
|
44
|
+
- Fixed type mismatch in existing interface โ **patch**
|
|
45
|
+
- Renamed or removed a field/function โ **major**
|
|
46
|
+
|
|
47
|
+
## ๐ Publishing a New Version
|
|
48
|
+
|
|
49
|
+
After your changes are merged:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Step 1: Bump version
|
|
53
|
+
npm version patch # or minor / major
|
|
54
|
+
|
|
55
|
+
# Step 2: Publish
|
|
56
|
+
npm publish
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Then update dependent services:
|
|
60
|
+
|
|
61
|
+
## โ
Best Practices
|
|
62
|
+
|
|
63
|
+
1. **Never edit generated files manually** โ always regenerate.
|
|
64
|
+
2. **Always bump versions** when a change affects consumers.
|
|
65
|
+
3. **Keep exports minimal** โ expose only whatโs needed.
|
|
66
|
+
4. **Ensure backward compatibility** where possible.
|
|
67
|
+
5. **Document breaking changes** in PR descriptions.
|
|
68
|
+
6. **Verify builds locally** before publishing.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
Made with โค๏ธ by the **ToGather Engineering Team**.
|
|
73
|
+
Please follow the contribution guide and coding standards before submitting PRs.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
|
|
7
|
+
// Find directories
|
|
8
|
+
function findProtoDirectories(dir, baseDir) {
|
|
9
|
+
const results = [];
|
|
10
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
11
|
+
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
if (entry.isDirectory()) {
|
|
14
|
+
const fullPath = path.join(dir, entry.name);
|
|
15
|
+
const files = fs.readdirSync(fullPath);
|
|
16
|
+
|
|
17
|
+
const hasProtoFiles = files.some(
|
|
18
|
+
(f) => f.endsWith("_pb.js") || f.endsWith("_connect.js")
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (hasProtoFiles) {
|
|
22
|
+
const relativePath = path.relative(baseDir, fullPath);
|
|
23
|
+
results.push({ fullPath, relativePath });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
results.push(...findProtoDirectories(fullPath, baseDir));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//generate index.js for barriel export
|
|
34
|
+
function generateIndexFile(dir) {
|
|
35
|
+
const files = fs.readdirSync(dir);
|
|
36
|
+
const exports = [];
|
|
37
|
+
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
if (file.endsWith("_pb.js")) {
|
|
40
|
+
exports.push(`export * from './${file}';`);
|
|
41
|
+
}
|
|
42
|
+
if (file.endsWith("_connect.js")) {
|
|
43
|
+
exports.push(`export * from './${file}';`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
console.log(exports);
|
|
47
|
+
if (exports.length > 0) {
|
|
48
|
+
const indexPath = path.join(dir, "index.js");
|
|
49
|
+
const content = exports.join("\n");
|
|
50
|
+
fs.writeFileSync(indexPath, content);
|
|
51
|
+
const indexDtsPath = path.join(dir, "index.d.ts");
|
|
52
|
+
const contentDts = exports.join("\n");
|
|
53
|
+
fs.writeFileSync(indexDtsPath, contentDts);
|
|
54
|
+
console.log(`created ${path.relative(process.cwd(), indexPath)}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// update package.json
|
|
59
|
+
function updatePackageJsonExports(protoDirs, srcDir) {
|
|
60
|
+
const packageJsonPath = path.join(__dirname, "package.json");
|
|
61
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
62
|
+
const exports = {
|
|
63
|
+
"./*": "./dist/*",
|
|
64
|
+
};
|
|
65
|
+
for (const { relativePath } of protoDirs) {
|
|
66
|
+
const exportPath = "./" + relativePath;
|
|
67
|
+
|
|
68
|
+
exports[exportPath] = {
|
|
69
|
+
types: "./dist/" + relativePath + "/index.d.ts",
|
|
70
|
+
import: "./dist/" + relativePath + "/index.js",
|
|
71
|
+
require:"./dist/" + relativePath + "/index.js",
|
|
72
|
+
default: "./dist/" + relativePath + "/index.js",
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
packageJson.exports = exports;
|
|
76
|
+
|
|
77
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
78
|
+
|
|
79
|
+
console.log("Updated package.json exports");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Main execution
|
|
83
|
+
const srcDir = path.join(__dirname, "dist");
|
|
84
|
+
|
|
85
|
+
const protoDirs = findProtoDirectories(srcDir, srcDir);
|
|
86
|
+
console.log("protoDirs");
|
|
87
|
+
console.log(protoDirs);
|
|
88
|
+
for (const { fullPath } of protoDirs) {
|
|
89
|
+
console.log(fullPath);
|
|
90
|
+
generateIndexFile(fullPath);
|
|
91
|
+
}
|
|
92
|
+
updatePackageJsonExports(protoDirs, srcDir);
|
|
93
|
+
console.log("DONE ..");
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@togatherlabs/shared-protos",
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"description": "Generated TypeScript gRPC definitions for Togather shared protos",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"lint": "buf lint",
|
|
12
|
+
"generate": "tsc && node generate-indexes.js"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"packageManager": "pnpm@10.7.1",
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@bufbuild/protobuf": "^2.9.0",
|
|
20
|
+
"@connectrpc/connect": "^2.1.0"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
"./*": "./dist/*",
|
|
24
|
+
"./authservice/admin/v1": {
|
|
25
|
+
"types": "./dist/authservice/admin/v1/index.d.ts",
|
|
26
|
+
"import": "./dist/authservice/admin/v1/index.js",
|
|
27
|
+
"default": "./dist/authservice/admin/v1/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5.9.3"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"target": "esnext",
|
|
12
|
+
"types": [],
|
|
13
|
+
// For nodejs:
|
|
14
|
+
// "lib": ["esnext"],
|
|
15
|
+
// "types": ["node"],
|
|
16
|
+
// and npm install -D @types/node
|
|
17
|
+
|
|
18
|
+
// Other Outputs
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"declaration": true,
|
|
21
|
+
"declarationMap": true,
|
|
22
|
+
|
|
23
|
+
// Stricter Typechecking Options
|
|
24
|
+
"noUncheckedIndexedAccess": true,
|
|
25
|
+
"exactOptionalPropertyTypes": true,
|
|
26
|
+
|
|
27
|
+
// Style Options
|
|
28
|
+
// "noImplicitReturns": true,
|
|
29
|
+
// "noImplicitOverride": true,
|
|
30
|
+
// "noUnusedLocals": true,
|
|
31
|
+
// "noUnusedParameters": true,
|
|
32
|
+
// "noFallthroughCasesInSwitch": true,
|
|
33
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
34
|
+
|
|
35
|
+
// Recommended Options
|
|
36
|
+
"strict": true,
|
|
37
|
+
"jsx": "react-jsx",
|
|
38
|
+
"verbatimModuleSyntax": true,
|
|
39
|
+
"isolatedModules": true,
|
|
40
|
+
"noUncheckedSideEffectImports": true,
|
|
41
|
+
"moduleDetection": "force",
|
|
42
|
+
"skipLibCheck": true
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
"include": ["src/**/*"],
|
|
46
|
+
"exclude": ["node_modules", "dist"]
|
|
47
|
+
}
|