Skip to content

Commit 7ef4e6e

Browse files
committed
feat(lexicon): add TypeScript build setup with lex-cli generated types
- Create src/ directory structure following monorepo patterns - Add tsconfig.json extending root config - Add rollup.config.js for ESM/CJS builds - Add eslint.config.mjs with package-specific settings - Update package.json with proper exports and build scripts - Generate TypeScript types from lexicons using @atproto/lex-cli - Export namespaced types to avoid naming conflicts - Export lexicon schemas, validation utilities, and IDs
1 parent 7e930a3 commit 7ef4e6e

File tree

19 files changed

+1456
-126
lines changed

19 files changed

+1456
-126
lines changed

packages/lexicon/eslint.config.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import baseConfig from "../../eslint.config.mjs";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
7+
/**
8+
* Lexicon package ESLint configuration.
9+
* Extends the shared base config with package-specific settings.
10+
*/
11+
export default [
12+
...baseConfig,
13+
{
14+
files: ["**/*.ts", "**/*.tsx"],
15+
languageOptions: {
16+
parserOptions: {
17+
project: path.resolve(__dirname, "./tsconfig.json"),
18+
tsconfigRootDir: __dirname,
19+
},
20+
},
21+
},
22+
{
23+
// Ignore generated files from lex-cli
24+
ignores: ["src/types/**", "src/lexicons.ts", "src/util.ts"],
25+
},
26+
];

packages/lexicon/index.ts

Lines changed: 0 additions & 101 deletions
This file was deleted.

packages/lexicon/package.json

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,61 @@
33
"version": "0.1.0",
44
"description": "ATProto lexicon definitions and TypeScript types for the Hypercerts protocol",
55
"type": "module",
6-
"main": "./index.js",
7-
"types": "./index.ts",
6+
"main": "dist/index.cjs",
7+
"module": "dist/index.mjs",
8+
"types": "dist/index.d.ts",
89
"exports": {
910
".": {
10-
"types": "./index.ts",
11-
"import": "./index.ts"
11+
"types": "./dist/index.d.ts",
12+
"import": "./dist/index.mjs",
13+
"require": "./dist/index.cjs"
1214
}
1315
},
1416
"files": [
15-
"index.ts",
16-
"types",
17-
"lexicons"
17+
"dist",
18+
"lexicons",
19+
"src"
1820
],
1921
"keywords": [
2022
"hypercerts",
2123
"atproto",
2224
"lexicon",
2325
"typescript"
2426
],
25-
"author": "",
27+
"author": "Hypercerts Foundation",
2628
"license": "MIT",
2729
"repository": {
2830
"type": "git",
29-
"url": ""
31+
"url": "[email protected]:hypercerts-org/hypercerts-sdk.git"
3032
},
3133
"scripts": {
32-
"list": "find ./lexicons -name '*.json'",
33-
"check": "npm run gen-api",
34-
"gen-api": "find ./lexicons -name '*.json' | xargs lex gen-api --yes ./types",
34+
"build": "rollup -c",
35+
"typecheck": "tsc --noEmit",
36+
"clean": "rm -rf dist",
37+
"lint": "eslint .",
38+
"format": "prettier --write .",
39+
"gen-api": "find ./lexicons -name '*.json' | xargs lex gen-api --yes ./src",
3540
"gen-md": "find ./lexicons -name '*.json' | xargs lex gen-md --yes ./lexicons.md",
36-
"gen-ts": "find ./lexicons -name '*.json' | xargs lex gen-ts-obj > lexicons.ts",
41+
"gen-ts": "find ./lexicons -name '*.json' | xargs lex gen-ts-obj > src/lexicons.ts",
3742
"lex": "lex",
38-
"prepublishOnly": "npm run check"
43+
"prepublishOnly": "pnpm run build"
3944
},
4045
"dependencies": {
41-
"@atproto/lex-cli": "^0.9.5"
42-
},
43-
"peerDependencies": {
44-
"@atproto/xrpc": "*",
45-
"@atproto/lexicon": "*"
46+
"@atproto/lexicon": "^0.5.1",
47+
"multiformats": "^13.3.6"
4648
},
4749
"devDependencies": {
50+
"@atproto/lex-cli": "^0.9.5",
4851
"@atproto/xrpc": "^0.7.5",
49-
"@atproto/lexicon": "^0.5.1"
50-
}
52+
"@rollup/plugin-commonjs": "^29.0.0",
53+
"@rollup/plugin-json": "^6.1.0",
54+
"@rollup/plugin-node-resolve": "^16.0.3",
55+
"@rollup/plugin-typescript": "^12.3.0",
56+
"rollup": "^4.53.3",
57+
"rollup-plugin-dts": "^6.2.3"
58+
},
59+
"peerDependencies": {
60+
"@atproto/xrpc": "*"
61+
},
62+
"sideEffects": false
5163
}

packages/lexicon/rollup.config.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { fileURLToPath } from "node:url";
2+
import { dirname, resolve } from "node:path";
3+
import typescript from "@rollup/plugin-typescript";
4+
import nodeResolve from "@rollup/plugin-node-resolve";
5+
import commonjs from "@rollup/plugin-commonjs";
6+
import json from "@rollup/plugin-json";
7+
import dts from "rollup-plugin-dts";
8+
9+
const __dirname = dirname(fileURLToPath(import.meta.url));
10+
11+
// Entrypoints for the package
12+
const entrypoints = [{ name: "index", input: "src/index.ts" }];
13+
14+
// Common plugins for JS builds
15+
const getPlugins = () => [
16+
json(),
17+
typescript({
18+
tsconfig: resolve(__dirname, "tsconfig.json"),
19+
declaration: false,
20+
declarationMap: false,
21+
rootDir: resolve(__dirname, "src"),
22+
outDir: resolve(__dirname, "dist"),
23+
}),
24+
nodeResolve({
25+
preferBuiltins: true,
26+
}),
27+
commonjs(),
28+
];
29+
30+
// External dependencies check
31+
const external = (id) => !id.startsWith(".") && !id.startsWith("/");
32+
33+
// Generate JS builds (ESM and CJS) for each entrypoint
34+
const jsBuild = entrypoints.map(({ name, input }) => ({
35+
input: resolve(__dirname, input),
36+
output: [
37+
{
38+
file: resolve(__dirname, `dist/${name}.mjs`),
39+
format: "es",
40+
sourcemap: true,
41+
},
42+
{
43+
file: resolve(__dirname, `dist/${name}.cjs`),
44+
format: "cjs",
45+
sourcemap: true,
46+
exports: "named",
47+
},
48+
],
49+
plugins: getPlugins(),
50+
external,
51+
}));
52+
53+
// Generate type declaration builds for each entrypoint
54+
const dtsBuild = entrypoints.map(({ name, input }) => ({
55+
input: resolve(__dirname, input),
56+
output: {
57+
file: resolve(__dirname, `dist/${name}.d.ts`),
58+
format: "es",
59+
},
60+
plugins: [
61+
dts({
62+
tsconfig: resolve(__dirname, "tsconfig.json"),
63+
}),
64+
],
65+
external,
66+
}));
67+
68+
export default [...jsBuild, ...dtsBuild];

packages/lexicon/src/index.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* Hypercert lexicon definitions for AT Protocol.
3+
*
4+
* This module exports the lexicon documents, collection names,
5+
* and generated TypeScript types for all hypercert-related record types.
6+
*
7+
* @packageDocumentation
8+
*/
9+
10+
import defsLexicon from "../lexicons/app/certified/defs.json";
11+
import locationLexicon from "../lexicons/app/certified/location.json";
12+
import claimLexicon from "../lexicons/org/hypercerts/claim.json";
13+
import contributionLexicon from "../lexicons/org/hypercerts/claim/contribution.json";
14+
import evaluationLexicon from "../lexicons/org/hypercerts/claim/evaluation.json";
15+
import evidenceLexicon from "../lexicons/org/hypercerts/claim/evidence.json";
16+
import measurementLexicon from "../lexicons/org/hypercerts/claim/measurement.json";
17+
import rightsLexicon from "../lexicons/org/hypercerts/claim/rights.json";
18+
import strongRefLexicon from "../lexicons/com/atproto/repo/strongRef.json";
19+
import collectionLexicon from "../lexicons/org/hypercerts/collection.json";
20+
import type { LexiconDoc } from "@atproto/lexicon";
21+
22+
/**
23+
* All hypercert-related lexicons for registration with AT Protocol Agent.
24+
*
25+
* This array contains all lexicon documents needed to work with
26+
* hypercert records.
27+
*/
28+
export const HYPERCERT_LEXICONS: LexiconDoc[] = [
29+
defsLexicon as LexiconDoc,
30+
locationLexicon as LexiconDoc,
31+
claimLexicon as LexiconDoc,
32+
rightsLexicon as LexiconDoc,
33+
contributionLexicon as LexiconDoc,
34+
measurementLexicon as LexiconDoc,
35+
evaluationLexicon as LexiconDoc,
36+
evidenceLexicon as LexiconDoc,
37+
collectionLexicon as LexiconDoc,
38+
];
39+
40+
/**
41+
* Collection NSIDs (Namespaced Identifiers) for hypercert records.
42+
*
43+
* Use these constants when performing record operations to ensure
44+
* correct collection names.
45+
*/
46+
export const HYPERCERT_COLLECTIONS = {
47+
/**
48+
* Main hypercert claim record collection.
49+
*/
50+
CLAIM: "org.hypercerts.claim",
51+
52+
/**
53+
* Rights record collection.
54+
*/
55+
RIGHTS: "org.hypercerts.claim.rights",
56+
57+
/**
58+
* Location record collection (shared certified lexicon).
59+
*/
60+
LOCATION: "app.certified.location",
61+
62+
/**
63+
* Contribution record collection.
64+
*/
65+
CONTRIBUTION: "org.hypercerts.claim.contribution",
66+
67+
/**
68+
* Measurement record collection.
69+
*/
70+
MEASUREMENT: "org.hypercerts.claim.measurement",
71+
72+
/**
73+
* Evaluation record collection.
74+
*/
75+
EVALUATION: "org.hypercerts.claim.evaluation",
76+
77+
/**
78+
* Evidence record collection.
79+
*/
80+
EVIDENCE: "org.hypercerts.claim.evidence",
81+
82+
/**
83+
* Collection record collection (groups of hypercerts).
84+
*/
85+
COLLECTION: "org.hypercerts.collection",
86+
} as const;
87+
88+
// Re-export individual lexicons for direct access
89+
export {
90+
defsLexicon,
91+
locationLexicon,
92+
strongRefLexicon,
93+
claimLexicon,
94+
contributionLexicon,
95+
evaluationLexicon,
96+
evidenceLexicon,
97+
measurementLexicon,
98+
rightsLexicon,
99+
collectionLexicon,
100+
};
101+
102+
// Re-export generated types as namespaces (avoiding conflicts)
103+
export * as AppCertifiedDefs from "./types/app/certified/defs.js";
104+
export * as AppCertifiedLocation from "./types/app/certified/location.js";
105+
export * as ComAtprotoRepoStrongRef from "./types/com/atproto/repo/strongRef.js";
106+
export * as OrgHypercertsClaim from "./types/org/hypercerts/claim.js";
107+
export * as OrgHypercertsClaimContribution from "./types/org/hypercerts/claim/contribution.js";
108+
export * as OrgHypercertsClaimEvaluation from "./types/org/hypercerts/claim/evaluation.js";
109+
export * as OrgHypercertsClaimEvidence from "./types/org/hypercerts/claim/evidence.js";
110+
export * as OrgHypercertsClaimMeasurement from "./types/org/hypercerts/claim/measurement.js";
111+
export * as OrgHypercertsClaimRights from "./types/org/hypercerts/claim/rights.js";
112+
export * as OrgHypercertsCollection from "./types/org/hypercerts/collection.js";
113+
114+
// Re-export lexicon schemas, validation, and IDs
115+
export { schemas, schemaDict, lexicons, validate, ids } from "./lexicons.js";
116+
117+
// Re-export utilities
118+
export * from "./util.js";

0 commit comments

Comments
 (0)