Skip to content

Commit 3e58943

Browse files
author
Frank
committed
sync
1 parent 1cd7b03 commit 3e58943

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

packages/openauth/src/subject.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import type { v1 } from "@standard-schema/spec"
22
import { Prettify } from "./util.js"
33

4+
/**
5+
* Subject schema is a map of types that are used to define the subjects.
6+
*/
47
export type SubjectSchema = Record<string, v1.StandardSchema>
58

9+
/** @internal */
610
export type SubjectPayload<T extends SubjectSchema> = Prettify<
711
{
812
[type in keyof T & string]: {
@@ -14,8 +18,6 @@ export type SubjectPayload<T extends SubjectSchema> = Prettify<
1418

1519
export function createSubjects<Schema extends SubjectSchema = {}>(
1620
types: Schema,
17-
) {
18-
return {
19-
...types,
20-
} as Schema
21+
): Schema {
22+
return { ...types }
2123
}

www/generate.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ function renderSubject() {
240240
}),
241241
`<div class="tsdoc">`,
242242
renderFunctions(module),
243+
renderInterfaces(module),
243244
`</div>`,
244245
])
245246
}
@@ -558,6 +559,8 @@ function renderType(type: TypeDoc.SomeType): Text {
558559
if (type.type === "reference") {
559560
if (type.package === "typescript") return renderTypescriptType(type)
560561
if (type.package === "@openauthjs/openauth") return renderOpenAuthType(type)
562+
if (type.package === "@standard-schema/spec")
563+
return renderStandardSchemaType(type)
561564
return `<code class="type">${type.name}</code>`
562565
}
563566
if (
@@ -662,7 +665,7 @@ function renderType(type: TypeDoc.SomeType): Text {
662665
].join("")
663666
}
664667
function renderTypescriptType(type: TypeDoc.ReferenceType) {
665-
// ie. Partial<>T
668+
// ie. Partial<Foo> => just render Foo
666669
if (type.name === "Partial") return renderType(type.typeArguments![0])
667670

668671
// ie. Record<string, string>
@@ -674,33 +677,41 @@ function renderType(type: TypeDoc.SomeType): Text {
674677
].join("")
675678
}
676679
function renderOpenAuthType(type: TypeDoc.ReferenceType) {
677-
// Reference to a generic type, ie. T
678-
if (type.refersToTypeParameter) return `<code class="primitive">any</code>`
679-
680680
// Reference to a non-documented type, ie. FetchLike
681681
if (!type.reflection) return `<code class="type">${type.name}</code>`
682682

683-
if (type.reflection?.kind === TypeDoc.ReflectionKind.Class) {
684-
const r = type.reflection as TypeDoc.DeclarationReflection
685-
if (r.sources?.[0]?.fileName.endsWith("error.ts"))
686-
return `[<code class="type">${r.name}</code>](/docs/issuer#${r.name.toLowerCase()})`
683+
// Reference to a generic type
684+
// ie.
685+
// export function createSubjects<Schema extends SubjectSchema>(types: Schema): Schema {
686+
// return { ...types }
687+
// }
688+
if (type.reflection.kind === TypeDoc.ReflectionKind.TypeParameter) {
689+
const t = (type.reflection as TypeDoc.TypeParameterReflection).type
690+
if (t) return renderType(t)
687691
}
688692

689-
if (type.reflection?.kind === TypeDoc.ReflectionKind.Interface) {
690-
const r = type.reflection as TypeDoc.DeclarationReflection
691-
if (
692-
r.sources?.[0]?.fileName.startsWith("packages/openauth/src/provider/")
693-
) {
694-
const provider = r.sources?.[0]?.fileName
695-
.split("/")
696-
.pop()
697-
?.split(".")[0]
698-
return `[<code class="type">${r.name}</code>](/docs/provider/${provider}#${r.name.toLowerCase()})`
693+
if (
694+
type.reflection.kind === TypeDoc.ReflectionKind.TypeAlias ||
695+
type.reflection.kind === TypeDoc.ReflectionKind.Interface ||
696+
type.reflection.kind === TypeDoc.ReflectionKind.Class
697+
) {
698+
const t = type.reflection as TypeDoc.DeclarationReflection
699+
const fileName = t.sources?.[0]?.fileName
700+
if (fileName?.startsWith("packages/openauth/src/subject.ts"))
701+
return `[<code class="type">${t.name}</code>](/docs/subject#${t.name.toLowerCase()})`
702+
if (fileName?.startsWith("packages/openauth/src/error.ts"))
703+
return `[<code class="type">${t.name}</code>](/docs/issuer#${t.name.toLowerCase()})`
704+
if (fileName?.startsWith("packages/openauth/src/provider/")) {
705+
const provider = fileName.split("/").pop()?.split(".")[0]
706+
return `[<code class="type">${t.name}</code>](/docs/provider/${provider}#${t.name.toLowerCase()})`
699707
}
700708
}
701709

702710
return `[<code class="type">${type.name}</code>](#${type.name.toLowerCase()})`
703711
}
712+
function renderStandardSchemaType(type: TypeDoc.ReferenceType) {
713+
return `[<code class="type">${type.name}</code>](https://github.com/standard-schema/standard-schema)`
714+
}
704715
}
705716

706717
function render(condition: any, content: Text) {
@@ -829,4 +840,8 @@ async function build() {
829840
return project
830841
}
831842

832-
async function generate() {}
843+
function print(type: TypeDoc.SomeType) {
844+
// @ts-ignore
845+
delete type._project
846+
console.log(type)
847+
}

0 commit comments

Comments
 (0)