Skip to content

Commit

Permalink
Squashed changes to remove Merge Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tcyrus committed Feb 15, 2025
1 parent f1d323a commit fe92c87
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/lex-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"chalk": "^4.1.2",
"commander": "^9.4.0",
"prettier": "^3.2.5",
"ts-morph": "^16.0.0",
"ts-morph": "^24.0.0",
"yesno": "^0.4.0",
"zod": "^3.23.8"
},
Expand Down
16 changes: 8 additions & 8 deletions packages/lex-cli/src/codegen/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
SourceFile,
VariableDeclarationKind,
} from 'ts-morph'
import { LexRecord, LexiconDoc, Lexicons } from '@atproto/lexicon'
import { type LexRecord, type LexiconDoc, Lexicons } from '@atproto/lexicon'
import { NSID } from '@atproto/syntax'
import { GeneratedAPI } from '../types'
import { type GeneratedAPI } from '../types'
import { gen, lexiconsTs, utilTs } from './common'
import {
genCommonImports,
Expand All @@ -18,7 +18,7 @@ import {
genXrpcParams,
} from './lex-gen'
import {
DefTreeNode,
type DefTreeNode,
lexiconsToDefTree,
schemasToNsidTokens,
toCamelCase,
Expand Down Expand Up @@ -61,14 +61,14 @@ const indexTs = (
nsidTokens: Record<string, string[]>,
) =>
gen(project, '/index.ts', async (file) => {
//= import { XrpcClient, FetchHandler, FetchHandlerOptions } from '@atproto/xrpc'
//= import { XrpcClient, type FetchHandler, type FetchHandlerOptions } from '@atproto/xrpc'
const xrpcImport = file.addImportDeclaration({
moduleSpecifier: '@atproto/xrpc',
})
xrpcImport.addNamedImports([
{ name: 'XrpcClient' },
{ name: 'FetchHandler' },
{ name: 'FetchHandlerOptions' },
{ name: 'FetchHandler', isTypeOnly: true },
{ name: 'FetchHandlerOptions', isTypeOnly: true },
])
//= import {schemas} from './lexicons.js'
file
Expand All @@ -81,10 +81,10 @@ const indexTs = (
})
.addNamedImports([{ name: 'CID' }])

//= import {OmitKey} from './util.js'
//= import { type OmitKey, type Un$Typed } from './util.js'
file
.addImportDeclaration({ moduleSpecifier: `./util.js` })
.addNamedImports([{ name: 'OmitKey' }, { name: 'Un$Typed' }])
.addNamedImports([{ name: 'OmitKey', isTypeOnly: true }, { name: 'Un$Typed', isTypeOnly: true }])

// generate type imports and re-exports
for (const lexicon of lexiconDocs) {
Expand Down
16 changes: 8 additions & 8 deletions packages/lex-cli/src/codegen/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Options as PrettierOptions, format } from 'prettier'
import { Project, SourceFile, VariableDeclarationKind } from 'ts-morph'
import { LexiconDoc } from '@atproto/lexicon'
import { GeneratedFile } from '../types'
import { type LexiconDoc } from '@atproto/lexicon'
import { type GeneratedFile } from '../types'

const PRETTIER_OPTS: PrettierOptions = {
parser: 'typescript',
Expand All @@ -14,7 +14,7 @@ const PRETTIER_OPTS: PrettierOptions = {
export const utilTs = (project) =>
gen(project, '/util.ts', async (file) => {
file.replaceWithText(`
import { ValidationResult } from '@atproto/lexicon'
import { type ValidationResult } from '@atproto/lexicon'
export type OmitKey<T, K extends keyof T> = {
[K2 in keyof T as K2 extends K ? never : K2]: T[K2]
Expand Down Expand Up @@ -141,25 +141,25 @@ export const lexiconsTs = (project, lexicons: LexiconDoc[]) =>
.join('')
}

//= import {LexiconDoc} from '@atproto/lexicon'
//= import { type LexiconDoc, Lexicons } from '@atproto/lexicon'
file
.addImportDeclaration({
moduleSpecifier: '@atproto/lexicon',
})
.addNamedImports([
{ name: 'LexiconDoc' },
{ name: 'LexiconDoc', isTypeOnly: true },
{ name: 'Lexicons' },
{ name: 'ValidationError' },
{ name: 'ValidationResult' },
{ name: 'ValidationResult', isTypeOnly: true },
])

//= import {is$typed, maybe$typed, $Typed} from './util'
//= import { is$typed, maybe$typed, type $Typed } from './util'
file
.addImportDeclaration({
moduleSpecifier: './util.js',
})
.addNamedImports([
{ name: '$Typed' },
{ name: '$Typed', isTypeOnly: true },
{ name: 'is$typed' },
{ name: 'maybe$typed' },
])
Expand Down
26 changes: 13 additions & 13 deletions packages/lex-cli/src/codegen/lex-gen.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { relative as getRelativePath } from 'node:path/posix'
import { SourceFile, VariableDeclarationKind } from 'ts-morph'
import {
LexArray,
LexBlob,
LexBytes,
LexCidLink,
LexIpldType,
LexObject,
LexPrimitive,
LexToken,
LexUserType,
type LexArray,
type LexBlob,
type LexBytes,
type LexCidLink,
type LexIpldType,
type LexObject,
type LexPrimitive,
type LexToken,
type LexUserType,
Lexicons,
} from '@atproto/lexicon'
import { toCamelCase, toScreamingSnakeCase, toTitleCase } from './util'
Expand All @@ -33,7 +33,7 @@ export function genCommonImports(file: SourceFile, baseNsid: string) {
.addImportDeclaration({
moduleSpecifier: '@atproto/lexicon',
})
.addNamedImports([{ name: 'ValidationResult' }, { name: 'BlobRef' }])
.addNamedImports([{ name: 'ValidationResult', isTypeOnly: true }, { name: 'BlobRef' }])

//= import {CID} from 'multiformats/cid'
file
Expand All @@ -52,7 +52,7 @@ export function genCommonImports(file: SourceFile, baseNsid: string) {
})
.addNamedImports([{ name: 'validate', alias: '_validate' }])

//= import { $Typed, is$typed as _is$typed, OmitKey } from '../[...]/util.ts'
//= import { type $Typed, is$typed as _is$typed, type OmitKey } from '../[...]/util.ts'
file
.addImportDeclaration({
moduleSpecifier: `${baseNsid
Expand All @@ -61,9 +61,9 @@ export function genCommonImports(file: SourceFile, baseNsid: string) {
.join('/')}/util`,
})
.addNamedImports([
{ name: '$Typed' },
{ name: '$Typed', isTypeOnly: true },
{ name: 'is$typed', alias: '_is$typed' },
{ name: 'OmitKey' },
{ name: 'OmitKey', isTypeOnly: true },
])

// tsc adds protection against circular imports, which hurts bundle size.
Expand Down
11 changes: 6 additions & 5 deletions packages/lex-cli/src/codegen/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
SourceFile,
VariableDeclarationKind,
} from 'ts-morph'
import { LexiconDoc, Lexicons } from '@atproto/lexicon'
import { type LexiconDoc, Lexicons } from '@atproto/lexicon'
import { NSID } from '@atproto/syntax'
import { GeneratedAPI } from '../types'
import { type GeneratedAPI } from '../types'
import { gen, lexiconsTs, utilTs } from './common'
import {
genCommonImports,
Expand All @@ -18,7 +18,7 @@ import {
genXrpcParams,
} from './lex-gen'
import {
DefTreeNode,
type DefTreeNode,
lexiconsToDefTree,
schemasToNsidTokens,
toCamelCase,
Expand Down Expand Up @@ -68,9 +68,10 @@ const indexTs = (
{
name: 'Options',
alias: 'XrpcOptions',
isTypeOnly: true
},
{ name: 'AuthVerifier' },
{ name: 'StreamAuthVerifier' },
{ name: 'AuthVerifier', isTypeOnly: true },
{ name: 'StreamAuthVerifier', isTypeOnly: true },
],
})
//= import {schemas} from './lexicons.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/lex-cli/src/codegen/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LexUserType, LexiconDoc } from '@atproto/lexicon'
import { type LexUserType, type LexiconDoc } from '@atproto/lexicon'
import { NSID } from '@atproto/syntax'

export interface DefTreeNodeUserType {
Expand Down
2 changes: 1 addition & 1 deletion packages/lex-cli/src/mdgen/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs'
import { LexiconDoc } from '@atproto/lexicon'
import { type LexiconDoc } from '@atproto/lexicon'

const INSERT_START = [
'<!-- START lex generated content. Please keep comment here to allow auto update -->',
Expand Down
6 changes: 3 additions & 3 deletions packages/lex-cli/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'node:fs'
import { join } from 'node:path'
import chalk from 'chalk'
import { ZodError, ZodFormattedError } from 'zod'
import { LexiconDoc, parseLexiconDoc } from '@atproto/lexicon'
import { FileDiff, GeneratedAPI } from './types'
import { ZodError, type ZodFormattedError } from 'zod'
import { type LexiconDoc, parseLexiconDoc } from '@atproto/lexicon'
import { type FileDiff, type GeneratedAPI } from './types'

export function readAllLexicons(paths: string[]): LexiconDoc[] {
const docs: LexiconDoc[] = []
Expand Down
Loading

0 comments on commit fe92c87

Please sign in to comment.