Skip to content

Commit

Permalink
chore: better type system.
Browse files Browse the repository at this point in the history
  • Loading branch information
eser committed Mar 23, 2024
1 parent 1c52ced commit 6f5f49e
Show file tree
Hide file tree
Showing 51 changed files with 235 additions and 257 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ repos:
- id: check-toml
- id: check-xml
- id: check-yaml
args: [--allow-multiple-documents]
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: forbid-new-submodules
- id: mixed-line-ending
args: ["--fix=lf"]
- id: pretty-format-json
args: ["--autofix", "--no-ensure-ascii", "--no-sort-keys"]
- id: trailing-whitespace
- repo: https://github.com/crate-ci/typos
rev: v1.16.23
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
deno 1.39.2
pre-commit 3.6.0
deno 1.41.3
pre-commit 3.6.2
2 changes: 1 addition & 1 deletion _etc/tasks/deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export * as walk from "jsr:@std/fs@0.216/walk";
export * as walk from "jsr:@std/fs@0.220/walk";
2 changes: 1 addition & 1 deletion appserver/appserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class AppServer {
}

setAsDefaultAppServer() {
this.di.register(AppServer.default, this);
this.di.set(AppServer.default, this);
}

async awaitAll() {
Expand Down
4 changes: 2 additions & 2 deletions appserver/channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export interface Channel {
export type Channel = {
name?: string;
}
};
2 changes: 1 addition & 1 deletion appserver/deps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export * as semver from "jsr:@std/semver@0.216";
export * as semver from "jsr:@std/semver@0.220";
4 changes: 2 additions & 2 deletions appserver/module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export interface Module {
export type Module = {
name?: string;

manifest: unknown; // TODO(@eser) type this
Expand All @@ -9,4 +9,4 @@ export interface Module {
provides: ReadonlyArray<unknown>; // TODO(@eser) type this

entrypoint: () => void; // TODO(@eser) type this
}
};
10 changes: 5 additions & 5 deletions bundler/deps.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export * as colors from "jsr:@std/fmt@0.216/colors";
export * as hex from "jsr:@std/encoding@0.216/hex";
export * as path from "jsr:@std/path@0.216";
export * as regexpEscape from "jsr:@std/regexp@0.216/escape";
export * as colors from "jsr:@std/fmt@0.220/colors";
export * as hex from "jsr:@std/encoding@0.220/hex";
export * as path from "jsr:@std/path@0.220";
export * as regexpEscape from "jsr:@std/regexp@0.220/escape";

export * as esbuild from "npm:esbuild@0.20";
// Import the WASM build on platforms where running subprocesses is not
// permitted, such as Deno Deploy, or when running without `--allow-run`.
// export * as esbuild from "npm:esbuild-wasm@0.20";

export { denoPlugins as esbuildDenoPlugins } from "jsr:@luca/esbuild-deno-loader@0.9";
export { denoPlugins as esbuildDenoPlugins } from "jsr:@luca/esbuild-deno-loader@0.10";
4 changes: 2 additions & 2 deletions bundler/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { esbuild, esbuildDenoPlugins, path, regexpEscape } from "./deps.ts";
import { Builder, BuildSnapshot } from "./mod.ts";
// import { BUNDLE_PUBLIC_PATH } from "../server/constants.ts";

export interface EsbuildBuilderOptions {
export type EsbuildBuilderOptions = {
/** The build ID. */
buildID: string;
/** The entrypoints, mapped from name to URL. */
Expand All @@ -20,7 +20,7 @@ export interface EsbuildBuilderOptions {
target: string | Array<string>;
absoluteWorkingDir: string;
basePath?: string;
}
};

export class EsbuildBuilder implements Builder {
#options: EsbuildBuilderOptions;
Expand Down
9 changes: 5 additions & 4 deletions bundler/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export {
EsbuildSnapshot,
} from "./esbuild.ts";
export { AotSnapshot } from "./aot-snapshot.ts";

export interface Builder {
build(): Promise<BuildSnapshot>;
}

export interface BuildSnapshot {
export type BuildSnapshot = {
/** The list of files contained in this snapshot, not prefixed by a slash. */
readonly paths: Array<string>;

Expand All @@ -28,9 +29,9 @@ export interface BuildSnapshot {
*
* Returns an empty array if the entrypoint does not exist. */
dependencies(pathStr: string): Array<string>;
}
};

export interface BuildSnapshotJson {
export type BuildSnapshotJson = {
build_id: string;
files: Record<string, Array<string>>;
}
};
4 changes: 2 additions & 2 deletions collector/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export async function* walkFiles(
}
}

export interface CollectExportsOptions {
export type CollectExportsOptions = {
baseDir: string;
globFilter?: string;
exportFilter?: (entries: [string, unknown][]) => Promise<[string, unknown][]>;
ignoreFilePattern?: RegExp;
}
};

export const collectExports = async (options: CollectExportsOptions) => {
// const mainModule = runtime.current.getMainModule();
Expand Down
4 changes: 2 additions & 2 deletions collector/deps-dev.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export * as assert from "jsr:@std/assert@0.216";
export * as bdd from "jsr:@std/testing@0.216/bdd";
export * as assert from "jsr:@std/assert@0.220";
export * as bdd from "jsr:@std/testing@0.220/bdd";
6 changes: 3 additions & 3 deletions collector/deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export * as path from "jsr:@std/path@0.216";
export * as posix from "jsr:@std/path@0.216/posix";
export * as walk from "jsr:@std/fs@0.216/walk";
export * as path from "jsr:@std/path@0.220";
export * as posix from "jsr:@std/path@0.220/posix";
export * as walk from "jsr:@std/fs@0.220/walk";
62 changes: 22 additions & 40 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@
"kv",
"temporal"
],
"imports": {
"$cool/jsx-runtime": "./jsx-runtime/mod.ts",
"$cool/": "./"
"tasks": {
"cleanup": "rm -rf ./_etc/coverage/ ./_etc/coverage.lcov ./deno.lock && deno cache --reload ./mod.ts",
"check:license": "deno run --allow-read --allow-write ./_etc/tasks/check-license.ts",
"check:mod": "deno run --check --reload ./mod.ts",
"doc:lint": "deno doc --lint ./mod.ts",
"doc:generate": "rm -rf ./docs/ && deno doc --name='cool' --output=./docs/ --html ./mod.ts",
"test": "DENO_KV_PATH=:memory: deno test --allow-sys --allow-net --allow-env --allow-read --allow-write --allow-run --parallel --watch",
"test:run": "DENO_KV_PATH=:memory: deno test --allow-sys --allow-net --allow-env --allow-read --allow-write --allow-run --parallel --trace-ops --coverage=./_etc/coverage/",
"test:coverage": "deno coverage ./_etc/coverage/ --exclude='\\.(j|t)sx$'",
"test:coverage-gen": "deno coverage ./_etc/coverage --exclude='\\.(j|t)sx$' --lcov --output=./_etc/coverage.lcov",
"ok": "deno fmt --check && deno lint && deno task check:license --check && deno task check:mod && deno task test:run",
"repl": "deno repl --unstable-cron --unstable-kv --unstable-temporal --allow-all --eval-file=./repl-init.ts",
"container:build": "docker build -t cool .",
"container:run": "docker run --interactive --tty --rm cool"
},
"compilerOptions": {
"jsx": "precompile",
Expand All @@ -29,43 +40,14 @@
"tags": [
"recommended"
]
},
"exclude": [
"_etc/temp/",
"docs/"
]
},
"fmt": {
"exclude": [
"_etc/temp/",
"docs/"
]
},
"test": {
"exclude": [
"_etc/",
"docs/"
]
}
},
"bench": {
"exclude": [
"_etc/",
"docs/"
]
},
"tasks": {
"cleanup": "rm -rf ./_etc/coverage/ ./_etc/coverage.lcov ./deno.lock && deno cache --reload ./mod.ts",
"check:license": "deno run --allow-read --allow-write ./_etc/tasks/check-license.ts",
"check:mod": "deno run --check --reload ./mod.ts",
"doc:lint": "deno doc --lint ./mod.ts",
"doc:generate": "rm -rf ./docs/ && deno doc --name='cool' --output=./docs/ --html ./mod.ts",
"test": "deno test --allow-sys --allow-net --allow-env --allow-read --allow-write --allow-run --parallel --watch",
"test:run": "deno test --allow-sys --allow-net --allow-env --allow-read --allow-write --allow-run --parallel --trace-ops --coverage=./_etc/coverage/",
"test:coverage": "deno coverage ./_etc/coverage/ --exclude='\\.(j|t)sx$'",
"test:coverage-gen": "deno coverage ./_etc/coverage --exclude='\\.(j|t)sx$' --lcov --output=./_etc/coverage.lcov",
"ok": "deno fmt --check && deno lint && deno task check:license --check && deno task check:mod && deno task test:run",
"repl": "deno repl --unstable-cron --unstable-kv --unstable-temporal --allow-all --eval-file=./repl-init.ts",
"container:build": "docker build -t cool .",
"container:run": "docker run --interactive --tty --rm cool"
"exclude": [
"_etc/temp/",
"docs/"
],
"imports": {
"$cool/jsx-runtime": "./jsx-runtime/mod.ts",
"$cool/": "./"
}
}
4 changes: 2 additions & 2 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export * as posix from "jsr:@std/path@0.216/posix";
export * as jsonc from "jsr:@std/jsonc@0.216";
export * as posix from "jsr:@std/path@0.220/posix";
export * as jsonc from "jsr:@std/jsonc@0.220";
10 changes: 5 additions & 5 deletions di/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Alternatively, retrieve multiple services at once:
```js
import { services } from "$cool/di/mod.ts";

const [dns, mns, db, users] = di.many(
const [dns, mns, db, users] = di.getMany(
"mailService",
"notifyService",
"dbConnection",
Expand All @@ -108,8 +108,8 @@ parameters:
```js
import { registry } from "$cool/di/mod.ts";

di.register("serviceA", () => console.log("Service A"));
di.register("serviceB", () => console.log("Service B"));
di.set("serviceA", () => console.log("Service A"));
di.set("serviceB", () => console.log("Service B"));

function myFunction(serviceA, serviceB) {
serviceA();
Expand All @@ -128,8 +128,8 @@ dependencies.
```js
import { registry } from "$cool/di/mod.ts";

di.register("serviceA", () => console.log("Service A"));
di.register("serviceB", () => console.log("Service B"));
di.set("serviceA", () => console.log("Service A"));
di.set("serviceB", () => console.log("Service B"));

di`first: ${"serviceA"} second: ${"serviceB"}`; // This will log "first: Service A second: Service B"
```
Expand Down
14 changes: 10 additions & 4 deletions di/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { registry } from "./services.ts";

// Symbol.metadata ??= Symbol("metadata");

export const injectable = (key?: ServiceKey) => {
export const injectable = (
key?: ServiceKey,
// deno-lint-ignore no-explicit-any
return (source: any, context?: ClassDecoratorContext) => {
): (source: any, context?: ClassDecoratorContext) => void => {
// deno-lint-ignore no-explicit-any
return (source: any, context?: ClassDecoratorContext): void => {
if (context !== undefined && context.kind !== "class") {
return;
}
Expand All @@ -26,9 +29,12 @@ export const injectable = (key?: ServiceKey) => {
};
};

export const inject = (_key: ServiceKey) => {
export const inject = (
_key: ServiceKey,
// deno-lint-ignore no-explicit-any
): (_source: any, _context?: ClassMemberDecoratorContext) => void => {
// deno-lint-ignore no-explicit-any
return (_source: any, _context?: ClassMemberDecoratorContext) => {
return (_source: any, _context?: ClassMemberDecoratorContext): void => {
// context.addInitializer((instance) => {
// instance[key] = services.get(key);
// });
Expand Down
6 changes: 3 additions & 3 deletions di/deps-dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.

export * as assert from "jsr:@std/assert@0.216";
export * as bdd from "jsr:@std/testing@0.216/bdd";
export * as mock from "jsr:@std/testing@0.216/mock";
export * as assert from "jsr:@std/assert@0.220";
export * as bdd from "jsr:@std/testing@0.220/bdd";
export * as mock from "jsr:@std/testing@0.220/mock";
Loading

0 comments on commit 6f5f49e

Please sign in to comment.