diff --git a/runtimes/js/examples/bun/index.ts b/runtimes/js/examples/bun/index.ts index 39c6662d3a..95adb2d2e8 100644 --- a/runtimes/js/examples/bun/index.ts +++ b/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"); diff --git a/runtimes/js/examples/node/index.ts b/runtimes/js/examples/node/index.ts index 0c1e8078c1..87edbc346a 100644 --- a/runtimes/js/examples/node/index.ts +++ b/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"); diff --git a/runtimes/js/examples/shared-app/app/pubsubtest.ts b/runtimes/js/examples/shared-app/app/pubsubtest.ts index 64c76cc0ee..e29e81e042 100644 --- a/runtimes/js/examples/shared-app/app/pubsubtest.ts +++ b/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; diff --git a/runtimes/js/packages/bun-runtime/index.ts b/runtimes/js/packages/bun-runtime/index.ts index 64bfe83201..27182887eb 100644 --- a/runtimes/js/packages/bun-runtime/index.ts +++ b/runtimes/js/packages/bun-runtime/index.ts @@ -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"; diff --git a/runtimes/js/packages/bun-runtime/package.json b/runtimes/js/packages/bun-runtime/package.json index e026a9314d..6bc49695be 100644 --- a/runtimes/js/packages/bun-runtime/package.json +++ b/runtimes/js/packages/bun-runtime/package.json @@ -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": { diff --git a/runtimes/js/packages/encore.dev/log/mod.ts b/runtimes/js/packages/encore.dev/log/mod.ts new file mode 100644 index 0000000000..82d268c0ec --- /dev/null +++ b/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"; diff --git a/runtimes/js/packages/encore.dev/package.json b/runtimes/js/packages/encore.dev/package.json index b421733f7e..c101f09145 100644 --- a/runtimes/js/packages/encore.dev/package.json +++ b/runtimes/js/packages/encore.dev/package.json @@ -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", diff --git a/runtimes/js/packages/encore.dev/pubsub/subscription.ts b/runtimes/js/packages/encore.dev/pubsub/subscription.ts index 3284fd0f65..cf6365333f 100644 --- a/runtimes/js/packages/encore.dev/pubsub/subscription.ts +++ b/runtimes/js/packages/encore.dev/pubsub/subscription.ts @@ -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"; diff --git a/runtimes/js/packages/internal-runtime/api.ts b/runtimes/js/packages/internal-runtime/api.ts index 1281acd428..f3d574b901 100644 --- a/runtimes/js/packages/internal-runtime/api.ts +++ b/runtimes/js/packages/internal-runtime/api.ts @@ -1,4 +1,3 @@ -import log from "@encore.dev/log"; import { config, listenURL } from "."; export interface CallParams { diff --git a/runtimes/js/packages/internal-runtime/compat/types.bun.ts b/runtimes/js/packages/internal-runtime/compat/types.bun.ts new file mode 100644 index 0000000000..18cfd758bf --- /dev/null +++ b/runtimes/js/packages/internal-runtime/compat/types.bun.ts @@ -0,0 +1,11 @@ +/// + +import {TypedArray} from "./types.node"; + +type RS = ReadableStream; +type TA = TypedArray; + +export type { + RS as ReadableStream, + TA as TypedArray, +} diff --git a/runtimes/js/packages/internal-runtime/compat/types.node.ts b/runtimes/js/packages/internal-runtime/compat/types.node.ts new file mode 100644 index 0000000000..02e2eb8b98 --- /dev/null +++ b/runtimes/js/packages/internal-runtime/compat/types.node.ts @@ -0,0 +1,16 @@ +/// + +export type { ReadableStream } from "node:stream/web"; + +export type TypedArray = + | Uint8Array + | Int8Array + | Uint8ClampedArray + | Int16Array + | Uint16Array + | Int32Array + | Uint32Array + | Float32Array + | Float64Array + | BigInt64Array + | BigUint64Array; diff --git a/runtimes/js/packages/internal-runtime/http/server.ts b/runtimes/js/packages/internal-runtime/http/server.ts index bf089fca54..5e6f4f305e 100644 --- a/runtimes/js/packages/internal-runtime/http/server.ts +++ b/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"; diff --git a/runtimes/js/packages/internal-runtime/http/types.ts b/runtimes/js/packages/internal-runtime/http/types.ts index c6780050e6..cec9e3e913 100644 --- a/runtimes/js/packages/internal-runtime/http/types.ts +++ b/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 */ @@ -87,7 +89,7 @@ export interface Response { * * @throws {ResponseClosedError} If the response has has been closed */ - write(data: BufferSource | ArrayBuffer | string): Promise; + write(data: TypedArray | DataView | ArrayBufferLike | string): Promise; /** * Flushes the response diff --git a/runtimes/js/packages/internal-runtime/index.ts b/runtimes/js/packages/internal-runtime/index.ts index d499ed09ad..49e30dc312 100644 --- a/runtimes/js/packages/internal-runtime/index.ts +++ b/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"; diff --git a/runtimes/js/packages/internal-runtime/jsruntime.ts b/runtimes/js/packages/internal-runtime/jsruntime.ts index 220597b720..1b8544d726 100644 --- a/runtimes/js/packages/internal-runtime/jsruntime.ts +++ b/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 @@ -51,7 +52,7 @@ export interface Runtime { /** * Fills the array with cryptographically secure random values */ - getRandomValues(array: T): T; + getRandomValues(array: T): T; } /** diff --git a/runtimes/js/packages/log/internal/consolewriter.ts b/runtimes/js/packages/internal-runtime/log/internal/consolewriter.ts similarity index 100% rename from runtimes/js/packages/log/internal/consolewriter.ts rename to runtimes/js/packages/internal-runtime/log/internal/consolewriter.ts diff --git a/runtimes/js/packages/log/internal/globals.ts b/runtimes/js/packages/internal-runtime/log/internal/globals.ts similarity index 100% rename from runtimes/js/packages/log/internal/globals.ts rename to runtimes/js/packages/internal-runtime/log/internal/globals.ts diff --git a/runtimes/js/packages/log/internal/hooks.ts b/runtimes/js/packages/internal-runtime/log/internal/hooks.ts similarity index 94% rename from runtimes/js/packages/log/internal/hooks.ts rename to runtimes/js/packages/internal-runtime/log/internal/hooks.ts index 55c129bafb..343ebb2975 100644 --- a/runtimes/js/packages/log/internal/hooks.ts +++ b/runtimes/js/packages/internal-runtime/log/internal/hooks.ts @@ -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("/") + "/"; diff --git a/runtimes/js/packages/log/internal/levels.ts b/runtimes/js/packages/internal-runtime/log/internal/levels.ts similarity index 100% rename from runtimes/js/packages/log/internal/levels.ts rename to runtimes/js/packages/internal-runtime/log/internal/levels.ts diff --git a/runtimes/js/packages/log/internal/logger.ts b/runtimes/js/packages/internal-runtime/log/internal/logger.ts similarity index 100% rename from runtimes/js/packages/log/internal/logger.ts rename to runtimes/js/packages/internal-runtime/log/internal/logger.ts diff --git a/runtimes/js/packages/log/internal/mod.ts b/runtimes/js/packages/internal-runtime/log/internal/mod.ts similarity index 100% rename from runtimes/js/packages/log/internal/mod.ts rename to runtimes/js/packages/internal-runtime/log/internal/mod.ts diff --git a/runtimes/js/packages/log/internal/stack.ts b/runtimes/js/packages/internal-runtime/log/internal/stack.ts similarity index 100% rename from runtimes/js/packages/log/internal/stack.ts rename to runtimes/js/packages/internal-runtime/log/internal/stack.ts diff --git a/runtimes/js/packages/log/mod.ts b/runtimes/js/packages/internal-runtime/log/mod.ts similarity index 100% rename from runtimes/js/packages/log/mod.ts rename to runtimes/js/packages/internal-runtime/log/mod.ts diff --git a/runtimes/js/packages/internal-runtime/package.json b/runtimes/js/packages/internal-runtime/package.json index 17e045be80..31f06deafc 100644 --- a/runtimes/js/packages/internal-runtime/package.json +++ b/runtimes/js/packages/internal-runtime/package.json @@ -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", @@ -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" } } diff --git a/runtimes/js/packages/internal-runtime/reqtrack/tracecontext.ts b/runtimes/js/packages/internal-runtime/reqtrack/tracecontext.ts index d2f746de22..0bf0387d82 100644 --- a/runtimes/js/packages/internal-runtime/reqtrack/tracecontext.ts +++ b/runtimes/js/packages/internal-runtime/reqtrack/tracecontext.ts @@ -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"; diff --git a/runtimes/js/packages/internal-runtime/tsconfig.json b/runtimes/js/packages/internal-runtime/tsconfig.json index 56e83f90b4..d709995a9e 100644 --- a/runtimes/js/packages/internal-runtime/tsconfig.json +++ b/runtimes/js/packages/internal-runtime/tsconfig.json @@ -5,8 +5,6 @@ "compilerOptions": { "rootDir": ".", "outDir": "./dist", - "types": [ - "bun-types" // add Bun global - ] + "types": [] } } diff --git a/runtimes/js/packages/internal-runtime/utils/timers.test.ts b/runtimes/js/packages/internal-runtime/utils/timers.test.ts index 70182b00ff..86d92d2d33 100644 --- a/runtimes/js/packages/internal-runtime/utils/timers.test.ts +++ b/runtimes/js/packages/internal-runtime/utils/timers.test.ts @@ -1,3 +1,5 @@ +/// + import { describe, expect, test } from "bun:test"; import { parseDuration, toDurationStr } from "./timers"; diff --git a/runtimes/js/packages/log/LICENSE b/runtimes/js/packages/log/LICENSE deleted file mode 100644 index 652c01fc80..0000000000 --- a/runtimes/js/packages/log/LICENSE +++ /dev/null @@ -1,362 +0,0 @@ -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. "Contributor" - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. "Contributor Version" - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. "Incompatible With Secondary Licenses" -means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the terms of - a Secondary License. - -1.6. "Executable Form" - - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - - means a work that combines Covered Software with other material, in a - separate file or files, that is not Covered Software. - -1.8. "License" - - means this document. - -1.9. "Licensable" - - means having the right to grant, to the maximum extent possible, whether - at the time of the initial grant or subsequently, any and all of the - rights conveyed by this License. - -1.10. "Modifications" - - means any of the following: - - a. any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. "Patent Claims" of a Contributor - - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the License, - by the making, using, selling, offering for sale, having made, import, - or transfer of either its Contributions or its Contributor Version. - -1.12. "Secondary License" - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. "Source Code Form" - - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, "control" means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution - become effective for each Contribution on the date the Contributor first - distributes such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under - this License. No additional rights or licenses will be implied from the - distribution or licensing of Covered Software under this License. - Notwithstanding Section 2.1(b) above, no patent license is granted by a - Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of - its Contributions. - - This License does not grant any rights in the trademarks, service marks, - or logos of any Contributor (except as may be necessary to comply with - the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this - License (see Section 10.2) or under the terms of a Secondary License (if - permitted under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its - Contributions are its original creation(s) or it has sufficient rights to - grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under - applicable copyright doctrines of fair use, fair dealing, or other - equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under - the terms of this License. You must inform recipients that the Source - Code Form of the Covered Software is governed by the terms of this - License, and how they can obtain a copy of this License. You may not - attempt to alter or restrict the recipients' rights in the Source Code - Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter the - recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for - the Covered Software. If the Larger Work is a combination of Covered - Software with a work governed by one or more Secondary Licenses, and the - Covered Software is not Incompatible With Secondary Licenses, this - License permits You to additionally distribute such Covered Software - under the terms of such Secondary License(s), so that the recipient of - the Larger Work may, at their option, further distribute the Covered - Software under the terms of either this License or such Secondary - License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices - (including copyright notices, patent notices, disclaimers of warranty, or - limitations of liability) contained within the Source Code Form of the - Covered Software, except that You may alter any license notices to the - extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on - behalf of any Contributor. You must make it absolutely clear that any - such warranty, support, indemnity, or liability obligation is offered by - You alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, - judicial order, or regulation then You must: (a) comply with the terms of - this License to the maximum extent possible; and (b) describe the - limitations and the code they affect. Such description must be placed in a - text file included with all distributions of the Covered Software under - this License. Except to the extent prohibited by statute or regulation, - such description must be sufficiently detailed for a recipient of ordinary - skill to be able to understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You -fail to comply with any of its terms. However, if You become compliant, -then the rights granted under this License from a particular Contributor -are reinstated (a) provisionally, unless and until such Contributor -explicitly and finally terminates Your grants, and (b) on an ongoing -basis, if such Contributor fails to notify You of the non-compliance by -some reasonable means prior to 60 days after You have come back into -compliance. Moreover, Your grants from a particular Contributor are -reinstated on an ongoing basis if such Contributor notifies You of the -non-compliance by some reasonable means, this is the first time You have -received notice of non-compliance with this License from such -Contributor, and You become compliant prior to 30 days after Your receipt -of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent -infringement claim (excluding declaratory judgment actions, -counter-claims, and cross-claims) alleging that a Contributor Version -directly or indirectly infringes any patent, then the rights granted to -You by any and all Contributors for the Covered Software under Section -2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user -license agreements (excluding distributors and resellers) which have been -validly granted by You or Your distributors under this License prior to -termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an "as is" basis, - without warranty of any kind, either expressed, implied, or statutory, - including, without limitation, warranties that the Covered Software is free - of defects, merchantable, fit for a particular purpose or non-infringing. - The entire risk as to the quality and performance of the Covered Software - is with You. Should any Covered Software prove defective in any respect, - You (not any Contributor) assume the cost of any necessary servicing, - repair, or correction. This disclaimer of warranty constitutes an essential - part of this License. No use of any Covered Software is authorized under - this License except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from - such party's negligence to the extent applicable law prohibits such - limitation. Some jurisdictions do not allow the exclusion or limitation of - incidental or consequential damages, so this exclusion and limitation may - not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts - of a jurisdiction where the defendant maintains its principal place of - business and such litigation shall be governed by laws of that - jurisdiction, without reference to its conflict-of-law provisions. Nothing - in this Section shall prevent a party's ability to bring cross-claims or - counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. Any law or regulation which provides that - the language of a contract shall be construed against the drafter shall not - be used to construe this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version - of the License under which You originally received the Covered Software, - or under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a - modified version of this License if you rename the license and remove - any references to the name of the license steward (except to note that - such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary -Licenses If You choose to distribute Source Code Form that is -Incompatible With Secondary Licenses under the terms of this version of -the License, the notice described in Exhibit B of this License must be -attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, -then You may include the notice in a location (such as a LICENSE file in a -relevant directory) where a recipient would be likely to look for such a -notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice - - This Source Code Form is "Incompatible - With Secondary Licenses", as defined by - the Mozilla Public License, v. 2.0. diff --git a/runtimes/js/packages/log/README.md b/runtimes/js/packages/log/README.md deleted file mode 100644 index 9bcad33526..0000000000 --- a/runtimes/js/packages/log/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Encore Sidecar API - -This package contains a typescript implementation of the Encore Sidecar API. It is intended to be used by the -[internal-runtime](../internal-runtime) package. diff --git a/runtimes/js/packages/log/package.json b/runtimes/js/packages/log/package.json deleted file mode 100644 index abc8b2205d..0000000000 --- a/runtimes/js/packages/log/package.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "packageManager": "yarn@3.6.3", - "name": "@encore.dev/log", - "description": "A structured logging library for use in Encore applications", - "version": "0.0.1", - "license": "MPL-2.0", - "bugs": { - "url": "https://github.com/encoredev/encore/issues" - }, - "repository": { - "type": "git", - "url": "https://github.com/encoredev/encore", - "directory": "runtimes/js/packages/log" - }, - "scripts": { - "build": "tsc -b", - "lint": "eslint \"**/*.ts*\"" - }, - "type": "module", - "sideEffects": false, - "exports": { - ".": { - "bun": "./mod.ts", - "default": "./dist/mod.js" - }, - "./internal": { - "bun": "./internal/mod.ts", - "default": "./dist/internal/mod.js" - } - }, - "typesVersions": { - "*": { - ".": [ - "dist/mod.d.ts" - ], - "./*": [ - "dist/*.d.ts" - ] - } - }, - "engines": { - "node": ">=18.0.0" - }, - "files": [ - "dist/", - "README.md", - "LICENSE" - ] -} diff --git a/runtimes/js/packages/log/tsconfig.json b/runtimes/js/packages/log/tsconfig.json deleted file mode 100644 index ef60bdb3e1..0000000000 --- a/runtimes/js/packages/log/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "../../tsconfig.packages.json", - "include": ["**/*.ts"], - "exclude": ["dist/**", "**/*.test.ts"], - "compilerOptions": { - "rootDir": ".", - "outDir": "./dist", - "types": [ - "node", - ] - } -} diff --git a/runtimes/js/packages/node-runtime/http/adapter.ts b/runtimes/js/packages/node-runtime/http/adapter.ts index ae76a38136..72a1a71d81 100644 --- a/runtimes/js/packages/node-runtime/http/adapter.ts +++ b/runtimes/js/packages/node-runtime/http/adapter.ts @@ -5,7 +5,8 @@ import { ResponseClosedError, } from "@encore.dev/internal-runtime/http/errors"; import { IncomingMessage, ServerResponse } from "node:http"; -import { ReadableStream as RSPonyFill } from "web-streams-polyfill/ponyfill/es2018"; +import { ReadableStream, type ReadableStreamDefaultController } from "node:stream/web"; +import type {TypedArray} from "@encore.dev/internal-runtime/compat/types"; /** * adapts a Node.js IncomingMessage and ServerResponse to the Encore internal runtime request and response structs @@ -67,7 +68,7 @@ class NodeRequestAdapter implements http.Request { /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ let controller: ReadableStreamDefaultController; - const stream = new RSPonyFill({ + const stream = new ReadableStream({ start(c) { controller = c; }, @@ -130,7 +131,7 @@ class NodeRequestAdapter implements http.Request { class NodeResponseAdapter implements http.Response { private readonly res: ServerResponse; private statusCode: StatusCode = StatusCode.OK; - private readonly headers: Dict; + private readonly headers: Record; private headersSent = false; /** @@ -173,7 +174,7 @@ class NodeResponseAdapter implements http.Response { this.res.writeHead(this.statusCode, this.headers); } - write(data: BufferSource | ArrayBuffer | string): Promise { + write(data: TypedArray | DataView | ArrayBufferLike | string): Promise { if (this.closed) { throw new ResponseClosedError(); } diff --git a/runtimes/js/packages/node-runtime/index.ts b/runtimes/js/packages/node-runtime/index.ts index 4c85c090e9..b73ed1bea5 100644 --- a/runtimes/js/packages/node-runtime/index.ts +++ b/runtimes/js/packages/node-runtime/index.ts @@ -3,7 +3,7 @@ import type { Transport } from "@connectrpc/connect"; 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 { jsonlWriter, consoleWriter } from "@encore.dev/log/internal"; +import { jsonlWriter, consoleWriter } from "@encore.dev/internal-runtime/log/internal"; import { createInterceptors } from "@encore.dev/sidecar-api"; export { serve } from "@encore.dev/internal-runtime"; @@ -12,6 +12,7 @@ export * from "@encore.dev/internal-runtime/http/types"; import { Server } from "node:http"; import * as crypto from "crypto"; import adapt from "./http/adapter"; +import type {TypedArray} from "@encore.dev/internal-runtime/compat/types"; class NodeRuntime implements Runtime { public readonly name = "node"; @@ -60,7 +61,7 @@ class NodeRuntime implements Runtime { process.stderr.write(this.logFunc(obj)); } - public getRandomValues(array: T): T { + public getRandomValues(array: T): T { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error return crypto.webcrypto.getRandomValues(array) as T; diff --git a/runtimes/js/packages/node-runtime/package.json b/runtimes/js/packages/node-runtime/package.json index fade5820d1..7399630a3e 100644 --- a/runtimes/js/packages/node-runtime/package.json +++ b/runtimes/js/packages/node-runtime/package.json @@ -19,23 +19,16 @@ "type": "module", "exports": { ".": { + "types": "./index.ts", "bun": "./index.ts", "default": "./dist/index.js" } }, - "typesVersions": { - "*": { - ".": [ - "dist/index.d.ts" - ] - } - }, "dependencies": { "@bufbuild/protobuf": "^1.3.3", "@connectrpc/connect": "^1.1.2", "@connectrpc/connect-node": "^1.1.2", "@encore.dev/internal-runtime": "workspace:^", - "@encore.dev/log": "workspace:^", "@encore.dev/sidecar-api": "workspace:^", "web-streams-polyfill": "^3.2.1" }, @@ -48,6 +41,6 @@ "LICENSE" ], "devDependencies": { - "@types/node": "^20.8.2" + "@types/node": "v20.9.0" } } diff --git a/runtimes/js/tsconfig.json b/runtimes/js/tsconfig.json index 6c166cf7e3..990b59f3ba 100644 --- a/runtimes/js/tsconfig.json +++ b/runtimes/js/tsconfig.json @@ -12,7 +12,6 @@ { "path": "./packages/bun-runtime" }, { "path": "./packages/node-runtime" }, { "path": "./packages/internal-runtime" }, - { "path": "./packages/log" }, { "path": "./packages/sidecar-api" }, ] } diff --git a/runtimes/js/tsconfig.packages.json b/runtimes/js/tsconfig.packages.json index cedab649c9..45c5b0c258 100644 --- a/runtimes/js/tsconfig.packages.json +++ b/runtimes/js/tsconfig.packages.json @@ -25,6 +25,6 @@ "skipLibCheck": true, // add Bun type definitions for tests - "types": ["bun-types"] + "types": [] } } diff --git a/runtimes/js/yarn.lock b/runtimes/js/yarn.lock index e6b13a31d2..2e59193d4b 100644 --- a/runtimes/js/yarn.lock +++ b/runtimes/js/yarn.lock @@ -140,7 +140,6 @@ __metadata: "@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:^" bun-types: latest languageName: unknown @@ -150,15 +149,9 @@ __metadata: version: 0.0.0-use.local resolution: "@encore.dev/internal-runtime@workspace:packages/internal-runtime" dependencies: - "@encore.dev/log": "workspace:^" "@encore.dev/sidecar-api": "workspace:^" bun-types: ^1.0.5-canary.20231009T140142 - languageName: unknown - linkType: soft - -"@encore.dev/log@workspace:^, @encore.dev/log@workspace:packages/log": - version: 0.0.0-use.local - resolution: "@encore.dev/log@workspace:packages/log" + web-streams-polyfill: ^3.2.1 languageName: unknown linkType: soft @@ -170,9 +163,8 @@ __metadata: "@connectrpc/connect": ^1.1.2 "@connectrpc/connect-node": ^1.1.2 "@encore.dev/internal-runtime": "workspace:^" - "@encore.dev/log": "workspace:^" "@encore.dev/sidecar-api": "workspace:^" - "@types/node": ^20.8.2 + "@types/node": v20.9.0 web-streams-polyfill: ^3.2.1 languageName: unknown linkType: soft @@ -859,7 +851,7 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:^20.7.1, @types/node@npm:^20.8.2": +"@types/node@npm:*, @types/node@npm:^20.7.1": version: 20.8.2 resolution: "@types/node@npm:20.8.2" checksum: 3da73e25d821bfcdb7de98589027e08bb4848e55408671c4a83ec0341e124b5313a0b20e1e4b4eff1168ea17a86f622ad73fcb04b761abd77496b9a27cbd5de5 @@ -875,6 +867,15 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:v20.9.0": + version: 20.9.0 + resolution: "@types/node@npm:20.9.0" + dependencies: + undici-types: ~5.26.4 + checksum: bfd927da6bff8a32051fa44bb47ca32a56d2c8bc8ba0170770f181cc1fa3c0b05863c9b930f0ba8604a48d5eb0d319166601709ca53bf2deae0025d8b6c6b8a3 + languageName: node + linkType: hard + "@types/pg@npm:^8.10.2": version: 8.10.7 resolution: "@types/pg@npm:8.10.7" @@ -4229,6 +4230,13 @@ __metadata: languageName: node linkType: hard +"undici-types@npm:~5.26.4": + version: 5.26.5 + resolution: "undici-types@npm:5.26.5" + checksum: 3192ef6f3fd5df652f2dc1cd782b49d6ff14dc98e5dced492aa8a8c65425227da5da6aafe22523c67f035a272c599bb89cfe803c1db6311e44bed3042fc25487 + languageName: node + linkType: hard + "undici@npm:^5.25.4": version: 5.25.4 resolution: "undici@npm:5.25.4"