Skip to content

Commit

Permalink
Fix type definitions (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre committed Nov 14, 2023
1 parent ef0210e commit 90ffbea
Show file tree
Hide file tree
Showing 37 changed files with 106 additions and 480 deletions.
2 changes: 1 addition & 1 deletion runtimes/js/examples/bun/index.ts
@@ -1,5 +1,5 @@
import { serve } from "@encore.dev/bun-runtime";
import log from "@encore.dev/log";
import log from "encore.dev/log";
import { routes } from "shared-app/app/routes";

log.info("Starting to serve routes for Bun example");
Expand Down
2 changes: 1 addition & 1 deletion runtimes/js/examples/node/index.ts
@@ -1,5 +1,5 @@
import { serve } from "@encore.dev/node-runtime";
import log from "@encore.dev/log";
import log from "encore.dev/log";
import { routes } from "shared-app/app/routes";

log.info("Starting to serve routes for Node example");
Expand Down
2 changes: 1 addition & 1 deletion runtimes/js/examples/shared-app/app/pubsubtest.ts
@@ -1,5 +1,5 @@
import { Attribute, Subscription, Topic } from "encore.dev/pubsub";
import log from "@encore.dev/log";
import log from "encore.dev/log";

const topic = new Topic<{
name: Attribute<string>;
Expand Down
4 changes: 2 additions & 2 deletions runtimes/js/packages/bun-runtime/index.ts
Expand Up @@ -3,8 +3,8 @@ import { createConnectTransport } from "@connectrpc/connect-web";
import type { Runtime } from "@encore.dev/internal-runtime";
import type * as http from "@encore.dev/internal-runtime/http/types";
import { initRuntime as initInternalRuntime } from "@encore.dev/internal-runtime";
import log from "@encore.dev/log";
import { consoleWriter, jsonlWriter } from "@encore.dev/log/internal";
import log from "@encore.dev/internal-runtime/log";
import { consoleWriter, jsonlWriter } from "@encore.dev/internal-runtime/log/internal";
import { createInterceptors } from "@encore.dev/sidecar-api";
import * as Bun from "bun";
import adapt from "./http/adapter";
Expand Down
1 change: 0 additions & 1 deletion runtimes/js/packages/bun-runtime/package.json
Expand Up @@ -26,7 +26,6 @@
"@connectrpc/connect": "^1.1.2",
"@connectrpc/connect-web": "^1.1.2",
"@encore.dev/internal-runtime": "workspace:^",
"@encore.dev/log": "workspace:^",
"@encore.dev/sidecar-api": "workspace:^"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions runtimes/js/packages/encore.dev/log/mod.ts
@@ -0,0 +1,4 @@
import log from "@encore.dev/internal-runtime/log";

export default log;
export * from "@encore.dev/internal-runtime/log";
5 changes: 5 additions & 0 deletions runtimes/js/packages/encore.dev/package.json
Expand Up @@ -40,6 +40,11 @@
"bun": "./cron/mod.ts",
"default": "./dist/cron/mod.js"
},
"./log": {
"types": "./log/mod.ts",
"bun": "./log/mod.ts",
"default": "./dist/log/mod.js"
},
"./pubsub": {
"types": "./pubsub/mod.ts",
"bun": "./pubsub/mod.ts",
Expand Down
3 changes: 1 addition & 2 deletions runtimes/js/packages/encore.dev/pubsub/subscription.ts
Expand Up @@ -16,8 +16,7 @@ import {
toDurationStr,
} from "@encore.dev/internal-runtime/utils/timers";
import { runtime } from "@encore.dev/internal-runtime/jsruntime";
import log from "@encore.dev/log";
import type { Logger } from "@encore.dev/log";
import log, { type Logger } from "../log/mod";
import { PubSub } from "@encore.dev/sidecar-api";
import { DurationString } from "../internal/types/mod";
import { Acker } from "./acker";
Expand Down
1 change: 0 additions & 1 deletion runtimes/js/packages/internal-runtime/api.ts
@@ -1,4 +1,3 @@
import log from "@encore.dev/log";
import { config, listenURL } from ".";

export interface CallParams {
Expand Down
11 changes: 11 additions & 0 deletions runtimes/js/packages/internal-runtime/compat/types.bun.ts
@@ -0,0 +1,11 @@
/// <reference types="bun-types" />

import {TypedArray} from "./types.node";

type RS = ReadableStream;
type TA = TypedArray;

export type {
RS as ReadableStream,
TA as TypedArray,
}
16 changes: 16 additions & 0 deletions runtimes/js/packages/internal-runtime/compat/types.node.ts
@@ -0,0 +1,16 @@
/// <reference types="node" />

export type { ReadableStream } from "node:stream/web";

export type TypedArray =
| Uint8Array
| Int8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array
| BigInt64Array
| BigUint64Array;
2 changes: 1 addition & 1 deletion runtimes/js/packages/internal-runtime/http/server.ts
@@ -1,4 +1,4 @@
import log from "@encore.dev/log";
import log from "../log/mod";
import { Version } from "../conf/version";
import reqtrack, { Context } from "../reqtrack";
import { traceIDToString } from "../reqtrack/encoding";
Expand Down
4 changes: 3 additions & 1 deletion runtimes/js/packages/internal-runtime/http/types.ts
@@ -1,3 +1,5 @@
import type {TypedArray, ReadableStream} from "@encore.dev/internal-runtime/compat/types";

/**
* HTTP methods
*/
Expand Down Expand Up @@ -87,7 +89,7 @@ export interface Response {
*
* @throws {ResponseClosedError} If the response has has been closed
*/
write(data: BufferSource | ArrayBuffer | string): Promise<void>;
write(data: TypedArray | DataView | ArrayBufferLike | string): Promise<void>;

/**
* Flushes the response
Expand Down
4 changes: 2 additions & 2 deletions runtimes/js/packages/internal-runtime/index.ts
@@ -1,6 +1,6 @@
import API, { Meta } from "@encore.dev/sidecar-api";
import log from "@encore.dev/log";
import { setRuntimeForLogging_encoreInternal } from "@encore.dev/log/internal";
import log from "./log/mod";
import { setRuntimeForLogging_encoreInternal } from "./log/internal/mod";
import { createEncoreInternalRouter } from "./http/encore-routes";
import ServerHandler, { createApiRouter } from "./http/server";
import { ApiRoute } from "./http/types";
Expand Down
3 changes: 2 additions & 1 deletion runtimes/js/packages/internal-runtime/jsruntime.ts
@@ -1,5 +1,6 @@
import type { Request, Response } from "./http/types";
import type { Transport } from "@connectrpc/connect";
import type {TypedArray} from "@encore.dev/internal-runtime/compat/types";

/**
* The runtime interface is used by this package to interact with the javascript runtime
Expand Down Expand Up @@ -51,7 +52,7 @@ export interface Runtime {
/**
* Fills the array with cryptographically secure random values
*/
getRandomValues<T extends BufferSource>(array: T): T;
getRandomValues<T extends TypedArray | DataView | ArrayBufferLike>(array: T): T;
}

/**
Expand Down
Expand Up @@ -65,17 +65,17 @@ function encorePackagesPath(): string {
// Drop the "internal" folder
components.pop();

// Drop the "log" folder
components.pop();

// Drop the dist folder, if this is the compiled js output
if (last() === "dist") {
components.pop();
}

// Drop the "log" folder
components.pop();

const suffix = last();
if (suffix !== "@encore.dev" && suffix !== "packages") {
throw new Error("unable to determine @encore.dev folder path");
if (suffix !== "encore.dev" && suffix !== "packages") {
throw new Error("unable to determine encore.dev folder path");
}

return components.join("/") + "/";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 17 additions & 2 deletions runtimes/js/packages/internal-runtime/package.json
Expand Up @@ -26,6 +26,21 @@
"bun": "./index.ts",
"default": "./dist/index.js"
},
"./log": {
"types": "./log/mod.ts",
"bun": "./log/mod.ts",
"default": "./dist/log/mod.js"
},
"./log/internal": {
"types": "./log/internal/mod.ts",
"bun": "./log/internal/mod.ts",
"default": "./dist/log/internal/mod.js"
},
"./compat/*": {
"bun": "./compat/*.bun.ts",
"types": "./compat/*.node.ts",
"default": "./dist/compat/*.node.js"
},
"./*": {
"types": "./*.ts",
"bun": "./*.ts",
Expand All @@ -41,10 +56,10 @@
"LICENSE"
],
"dependencies": {
"@encore.dev/log": "workspace:^",
"@encore.dev/sidecar-api": "workspace:^"
},
"devDependencies": {
"bun-types": "^1.0.5-canary.20231009T140142"
"bun-types": "^1.0.5-canary.20231009T140142",
"web-streams-polyfill": "^3.2.1"
}
}
Expand Up @@ -3,7 +3,7 @@
https://www.w3.org/TR/trace-context/
*/
import log from "@encore.dev/log";
import log from "../log/mod";
import { runtime } from "../jsruntime";

type TraceVersion = "00";
Expand Down
4 changes: 1 addition & 3 deletions runtimes/js/packages/internal-runtime/tsconfig.json
Expand Up @@ -5,8 +5,6 @@
"compilerOptions": {
"rootDir": ".",
"outDir": "./dist",
"types": [
"bun-types" // add Bun global
]
"types": []
}
}
2 changes: 2 additions & 0 deletions runtimes/js/packages/internal-runtime/utils/timers.test.ts
@@ -1,3 +1,5 @@
/// <reference types="bun-types" />

import { describe, expect, test } from "bun:test";
import { parseDuration, toDurationStr } from "./timers";

Expand Down

0 comments on commit 90ffbea

Please sign in to comment.