Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
"typescript.enablePromptUseWorkspaceTsdk": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "dprint.dprint",
"[markdown]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[javascript]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[javascriptreact]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[typescriptreact]": {
"editor.defaultFormatter": "dprint.dprint"
},
"editor.formatOnSaveMode": "file",
"editor.codeActionsOnSave": {
"source.fixAll.oxc": "explicit"
Expand All @@ -23,5 +38,7 @@
"editor.suggestSelection": "recentlyUsed",
"editor.wordBasedSuggestions": "matchingDocuments",
"editor.parameterHints.enabled": true,
"files.insertFinalNewline": true
"files.insertFinalNewline": true,
"deno.enable": true,
"deno.lint": false
}
9 changes: 7 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"$schema": "https://raw.githubusercontent.com/denoland/deno/refs/heads/main/cli/schemas/config-file.v1.json",
"nodeModulesDir": "manual",
"unstable": ["bare-node-builtins", "node-globals"],
"workspace": ["./packages/*"],
"unstable": [
"bare-node-builtins",
"node-globals"
],
"workspace": [
"./packages/*"
],
"exclude": [
"**/*.mjs",
"**/*.cjs",
Expand Down
7 changes: 3 additions & 4 deletions packages/effect/src/Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import type * as Exit from "./Exit.ts"
import type { LazyArg } from "./Function.ts"
import { constant, constTrue, constUndefined, dual, identity } from "./Function.ts"
import * as internalEffect from "./internal/effect.ts"
import type { ErrorWithStackTraceLimit } from "./internal/tracer.ts"
import * as internalTracer from "./internal/tracer.ts"
import { type Pipeable, pipeArguments } from "./Pipeable.ts"
import { hasProperty } from "./Predicate.ts"
Expand Down Expand Up @@ -1690,10 +1689,10 @@ export const mock =
if (prop in target) {
return target[prop as keyof S]
}
const prevLimit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
;(Error as ErrorWithStackTraceLimit).stackTraceLimit = 2
const prevLimit = Error.stackTraceLimit
Error.stackTraceLimit = 2
const error = new Error(`${service.key}: Unimplemented method "${prop.toString()}"`)
;(Error as ErrorWithStackTraceLimit).stackTraceLimit = prevLimit
Error.stackTraceLimit = prevLimit
error.name = "UnimplementedError"
return makeUnimplemented(error)
},
Expand Down
8 changes: 3 additions & 5 deletions packages/effect/src/ServiceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { constant, dual, type LazyArg } from "./Function.ts"
import * as Hash from "./Hash.ts"
import type { Inspectable } from "./Inspectable.ts"
import { exitSucceed, PipeInspectableProto, withFiber, YieldableProto } from "./internal/core.ts"
import type { ErrorWithStackTraceLimit } from "./internal/tracer.ts"
import * as Option from "./Option.ts"
import type { Pipeable } from "./Pipeable.ts"
import { hasProperty } from "./Predicate.ts"
Expand Down Expand Up @@ -145,11 +144,10 @@ export const Service: {
>
& { readonly make: Make }
} = function() {
const prevLimit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
;(Error as ErrorWithStackTraceLimit)
.stackTraceLimit = 2
const prevLimit = Error.stackTraceLimit
Error.stackTraceLimit = 2
const err = new Error()
;(Error as ErrorWithStackTraceLimit).stackTraceLimit = prevLimit
Error.stackTraceLimit = prevLimit
function KeyClass() {}
const self = KeyClass as any as Types.Mutable<Reference<any>>
Object.setPrototypeOf(self, ServiceProto)
Expand Down
9 changes: 4 additions & 5 deletions packages/effect/src/internal/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import {
} from "./core.ts"
import * as doNotation from "./doNotation.ts"
import * as InternalMetric from "./metric.ts"
import { addSpanStackTrace, type ErrorWithStackTraceLimit, makeStackCleaner } from "./tracer.ts"
import { addSpanStackTrace, makeStackCleaner } from "./tracer.ts"
import { version } from "./version.ts"

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -310,9 +310,8 @@ export const causePrettyErrors = <E>(self: Cause.Cause<E>): Array<Error> => {
const interrupts: Array<Cause.Interrupt> = []
if (self.failures.length === 0) return errors

const prevStackLimit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
;(Error as ErrorWithStackTraceLimit)
.stackTraceLimit = 1
const prevStackLimit = Error.stackTraceLimit
Error.stackTraceLimit = 1

for (const failure of self.failures) {
if (failure._tag === "Interrupt") {
Expand All @@ -336,7 +335,7 @@ export const causePrettyErrors = <E>(self: Cause.Cause<E>): Array<Error> => {
errors.push(causePrettyError(error, interrupts[0].annotations))
}

;(Error as ErrorWithStackTraceLimit).stackTraceLimit = prevStackLimit
Error.stackTraceLimit = prevStackLimit
return errors
}

Expand Down
10 changes: 3 additions & 7 deletions packages/effect/src/internal/tracer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type * as Tracer from "../Tracer.ts"

export interface ErrorWithStackTraceLimit {
stackTraceLimit?: number | undefined
}

/** @internal */
export const addSpanStackTrace = <A extends Tracer.TraceOptions>(
options: A | undefined
Expand All @@ -13,10 +9,10 @@ export const addSpanStackTrace = <A extends Tracer.TraceOptions>(
} else if (options?.captureStackTrace !== undefined && typeof options.captureStackTrace !== "boolean") {
return options
}
const limit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
;(Error as ErrorWithStackTraceLimit).stackTraceLimit = 3
const limit = Error.stackTraceLimit
Error.stackTraceLimit = 3
const traceError = new Error()
;(Error as ErrorWithStackTraceLimit).stackTraceLimit = limit
Error.stackTraceLimit = limit
return {
...options,
captureStackTrace: spanCleaner(() => traceError.stack)
Expand Down
10 changes: 9 additions & 1 deletion packages/effect/src/unstable/http/FetchHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ export class RequestInit extends ServiceMap.Service<RequestInit, globalThis.Requ
const fetch: HttpClient.HttpClient = HttpClient.make((request, url, signal, fiber) => {
const fetch = fiber.getRef(Fetch)
const options: globalThis.RequestInit = fiber.services.mapUnsafe.get(RequestInit.key) ?? {}
const headers = options.headers ? Headers.merge(Headers.fromInput(options.headers), request.headers) : request.headers
const headers = options.headers ?
Headers.merge(
Headers.fromInput(
// TODO: Handle Deno correctly
options.headers as ReadonlyArray<[string, string]>
),
request.headers
) :
request.headers
const send = (body: BodyInit | undefined) =>
Effect.map(
Effect.tryPromise({
Expand Down
5 changes: 4 additions & 1 deletion packages/effect/src/unstable/workers/Transferable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,8 @@ export const MessagePort: Transferable<Schema.declare<MessagePort>> = schema(
*/
export const Uint8Array: Transferable<Schema.Uint8Array> = schema(
Schema.Uint8Array,
(_) => [_.buffer]
(_) => [
// TODO: Support SharedArrayBuffer in Schema
_.buffer as ArrayBuffer
]
)
21 changes: 21 additions & 0 deletions packages/platform-deno/LICENSE
Copy link
Contributor Author

@lishaduck lishaduck Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This shouldn't really be necessary but just in case)

This code was originally released as jsr:@lishaduck/effect-platform-deno under the Universal Permissive License v1.0, and was extensively based on the MIT-licensed @effect/platform-browser & @effect/platform-node-shared. I am the sole copyright holder (@pixeleet's single contribution was legally trivial), and I explicitly grant permission to relicense this code under the MIT License for use in this repository and its derivatives.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Effectful Technologies Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions packages/platform-deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# `@effect/platform-deno`

Provides Deno-specific implementations for the abstractions defined in [`@effect/platform`](https://github.com/Effect-TS/effect/tree/main/packages/platform), allowing you to write platform-independent code that runs smoothly in Deno environments.

## Documentation

- **API Reference**: [View the full documentation](https://effect-ts.github.io/effect/docs/platform-deno).
20 changes: 20 additions & 0 deletions packages/platform-deno/docgen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "../../node_modules/@effect/docgen/schema.json",
"srcLink": "https://github.com/Effect-TS/effect/tree/main/packages/platform-deno/src/",
"exclude": ["src/internal/**/*.ts"],
"examplesCompilerOptions": {
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"moduleResolution": "NodeNext",
"module": "NodeNext",
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"rewriteRelativeImportExtensions": true,
"allowImportingTsExtensions": true,
"paths": {
"effect": ["../../../effect/src/index.js"],
"effect/*": ["../../../effect/src/*.js"]
}
}
}
74 changes: 74 additions & 0 deletions packages/platform-deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "@effect/platform-deno",
"type": "module",
"version": "0.77.6",
"license": "MIT",
"description": "Platform specific implementations for the Deno runtime",
"homepage": "https://effect.website",
"repository": {
"type": "git",
"url": "https://github.com/Effect-TS/effect-smol.git",
"directory": "packages/platform-deno"
},
"bugs": {
"url": "https://github.com/Effect-TS/effect-smol/issues"
},
"tags": [
"deno",
"typescript",
"algebraic-data-types",
"functional-programming"
],
"keywords": [
"deno",
"typescript",
"algebraic-data-types",
"functional-programming"
],
"engines": {
"deno": ">=2.5.0"
},
"sideEffects": [],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
"./*": "./src/*.ts",
"./internal/*": null,
"./*/index": null
},
"files": [
"src/**/*.ts",
"dist/**/*.js",
"dist/**/*.js.map",
"dist/**/*.d.ts",
"dist/**/*.d.ts.map"
],
"publishConfig": {
"provenance": true,
"exports": {
"./package.json": "./package.json",
".": "./dist/index.js",
"./*": "./dist/*.js",
"./internal/*": null,
"./*/index": null
}
},
"scripts": {
"codegen": "build-utils prepare-v4",
"build": "tsc -b tsconfig.build.json && babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
"check": "deno check",
"test": "vitest",
"coverage": "vitest --coverage"
},
"dependencies": {
"@std/path": "jsr:^1.1.4"
},
"peerDependencies": {
"effect": "workspace:^"
},
"devDependencies": {
"@types/deno": "^2.5.0",
"@std/assert": "jsr:^1.0.16",
"effect": "workspace:^"
}
}
50 changes: 50 additions & 0 deletions packages/platform-deno/src/DenoKeyValueStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* This module exposes database primitives.
* @module
*
* @since 1.0.0
*/

import * as Layer from "effect/Layer"
import * as KeyValueStore from "effect/unstable/persistence/KeyValueStore"
import { makeKvStore } from "./internal/kv.ts"

/**
* Creates a {@linkcode KeyValueStore} layer that uses the Web-native {@linkcode localStorage} API.
*
* Values are stored between sessions.
*
* @since 1.0.0
* @category layer
*/
export const layerLocalStorage: Layer.Layer<KeyValueStore.KeyValueStore> = KeyValueStore.layerStorage(() =>
localStorage
)

/**
* Creates a {@linkcode KeyValueStore} layer that uses the Web-native {@linkcode sessionStorage} API.
*
* Values are stored only for the current session.
*
* @since 1.0.0
* @category layer
*/
export const layerSessionStorage: Layer.Layer<KeyValueStore.KeyValueStore> = KeyValueStore.layerStorage(() =>
sessionStorage
)

/**
* Creates a {@linkcode KeyValueStore} layer that uses Deno’s cloud-native {@linkcode Deno.Kv} API.
*
* @remarks
* This does not support gradual adoption,
* and will fail semi-gracefully on non-`string` or {@linkcode Uint8Array} values.
* kvStore
* @since 1.0.0
* @category layer
*/
export const layerKv: Layer.Layer<KeyValueStore.KeyValueStore> = Layer.effect(
KeyValueStore.KeyValueStore
)(
makeKvStore()
)
Loading
Loading