Skip to content

Commit

Permalink
organize exports
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Oct 15, 2024
1 parent 971282f commit 7401123
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 30 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# typescript-type-introspection

Reason with TypeScript code via
[type introspection](https://en.wikipedia.org/wiki/Type_introspection).
[_type introspection_](https://en.wikipedia.org/wiki/Type_introspection),
powered by [Tree-Sitter](https://tree-sitter.github.io/tree-sitter/).

## Introspection

Expand All @@ -13,7 +14,7 @@ dynamic type handling in your TypeScript projects.
## Installation

```sh
# TODO: Publish on JSR.io
deno add @fartlabs/typescript-type-introspection
```

## TypeBox
Expand All @@ -38,9 +39,7 @@ dynamic type handling in your TypeScript projects.
Instantiate a TypeBox schema at runtime using introspection via
`@sinclair/typebox/compiler`.

```ts
// TODO: Add TypeBox example.
```
<https://github.com/FartLabs/typescript-type-introspector/blob/971282f7ff863a84cb43af1e1725961c62cc54b3/examples/schema-from-introspection.test.ts#L1-L13>

## Development

Expand Down
6 changes: 6 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"name": "@fartlabs/typescript-type-introspector",
"version": "0.0.1",
"exports": {
".": "./lib/introspector/mod.ts",
"./typebox": "./lib/typebox/mod.ts",
"./tree-sitter/tree-sitter": "./lib/tree-sitter/tree-sitter.ts",
"./tree-sitter/tree-sitter-introspector": "./lib/tree-sitter/tree-sitter-introspector.ts"
},
"lock": false,
"tasks": {
"dev": "deno test --watch -A"
Expand Down
4 changes: 2 additions & 2 deletions examples/tree-sitter-introspector.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertEquals } from "@std/assert";
import { TreeSitterIntrospector } from "#/lib/introspector/tree-sitter-introspector.ts";
import { EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER } from "../lib/example/tree-sitter-parser.ts";
import { TreeSitterIntrospector } from "#/lib/tree-sitter/tree-sitter-introspector.ts";
import { EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER } from "#/lib/example/tree-sitter-parser.ts";
import {
EXAMPLE_PERSON_INTROSPECTION,
EXAMPLE_PERSON_SOURCE_CODE,
Expand Down
5 changes: 3 additions & 2 deletions lib/example/book.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { queryRootNode } from "#/lib/tree-sitter/tree-sitter.ts";
import { makeTreeSitterTypeScriptClassPattern } from "#/lib/introspector/tree-sitter-introspector.ts";
import { makeTreeSitterTypeScriptClassPattern } from "#/lib/tree-sitter/tree-sitter-introspector.ts";
import {
EXAMPLE_TYPESCRIPT_CLASS_TREE_SITTER_CAPTURE_NAME_MAP,
EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER,
} from "./tree-sitter-parser.ts";
import { EXAMPLE_PERSON, Person } from "./person.ts";
import type { Person } from "./person.ts";
import { EXAMPLE_PERSON } from "./person.ts";

/**
* Book is an example class that represents a book.
Expand Down
3 changes: 3 additions & 0 deletions lib/example/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./book.ts";
export * from "./person.ts";
export * from "./tree-sitter-parser.ts";
2 changes: 1 addition & 1 deletion lib/example/person.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { queryRootNode } from "#/lib/tree-sitter/tree-sitter.ts";
import type { Introspection } from "#/lib/introspector/introspector.ts";
import { makeTreeSitterTypeScriptClassPattern } from "#/lib/introspector/tree-sitter-introspector.ts";
import { makeTreeSitterTypeScriptClassPattern } from "#/lib/tree-sitter/tree-sitter-introspector.ts";
import {
EXAMPLE_TYPESCRIPT_CLASS_TREE_SITTER_CAPTURE_NAME_MAP,
EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER,
Expand Down
2 changes: 1 addition & 1 deletion lib/example/tree-sitter-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parserFromWasm } from "deno-tree-sitter/main.js";
import typescript from "common-tree-sitter-languages/typescript.js";
import { defaultClassTreeSitterCaptureNameMap } from "#/lib/introspector/tree-sitter-introspector.ts";
import { defaultClassTreeSitterCaptureNameMap } from "#/lib/tree-sitter/tree-sitter-introspector.ts";

/**
* EXAMPLE_TYPESCRIPT_TREE_SITTER_PARSER is a tree-sitter parser for TypeScript.
Expand Down
1 change: 1 addition & 0 deletions lib/introspector/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./introspector.ts";
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import type {
NamedCapture,
Parser,
Tree,
} from "#/lib/tree-sitter/tree-sitter.ts";
import {
findCaptureString,
queryRootNode,
} from "#/lib/tree-sitter/tree-sitter.ts";
import type {
IntrospectedProperty,
Introspection,
Introspector,
} from "./introspector.ts";
} from "#/lib/introspector/introspector.ts";
import type { NamedCapture, Parser, Tree } from "./tree-sitter.ts";
import { findCaptureString, queryRootNode } from "./tree-sitter.ts";

/**
* TreeSitterTypeScriptTypeIntrospector is a TypeScript type introspector that
* uses Tree Sitter to introspect TypeScript types.
* TreeSitterIntrospector is a TypeScript type introspector that uses Tree
* Sitter to introspect TypeScript types.
*/
export class TreeSitterIntrospector implements Introspector {
public constructor(
Expand Down Expand Up @@ -149,13 +142,14 @@ export const typeScriptTypeAnnotationPrefix = ": ";
/**
* defaultClassTreeSitterCaptureNameMap is the default class capture name map.
*/
export const defaultClassTreeSitterCaptureNameMap = {
PROPERTY_IDENTIFIER: "property-identifier",
PUBLIC_FIELD_DEFINITION: "public-field-definition",
TYPE_ANNOTATION: "type-annotation",
TYPE_IDENTIFIER: "type-identifier",
VALUE: "value",
} as const satisfies ClassTreeSitterCaptureNameMap;
export const defaultClassTreeSitterCaptureNameMap:
ClassTreeSitterCaptureNameMap = {
PROPERTY_IDENTIFIER: "property-identifier",
PUBLIC_FIELD_DEFINITION: "public-field-definition",
TYPE_ANNOTATION: "type-annotation",
TYPE_IDENTIFIER: "type-identifier",
VALUE: "value",
} as const;

/**
* ClassTreeSitterCaptureNameMap is a map of class capture names to their
Expand Down
1 change: 1 addition & 0 deletions lib/typebox/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./schema-from-introspection.ts";

0 comments on commit 7401123

Please sign in to comment.