Deno 1.17 Liberate

Deno 1.17 has been
tagged and launched with the next aspects and changes:

For these who already maintain Deno put in, it’s probably you’ll well increase to 1.17 by working:

For these who shall be inserting in Deno for the critical time, it’s probably you’ll well employ one among the solutions
listed below:

curl -fsSL https://deno.land/x/install/install.sh | sh


iwr https://deno.land/x/install/install.ps1 -useb | iex


brew install deno


scoop install deno


choco install deno

Import assertions and JSON modules

Deno v1.17 ships with stout increase for import assertions and JSON modules.

Import assertions is a
Stage 3 proposal that shipped in
V8 earlier this 300 and sixty five days. The principle employ
case of this proposal is to permit imports of JSON modules; which with out import
assertions also can pose
a security vulnerability.

Sooner than this delivery the absolute most practical system to read JSON file turned into once to employ accumulate() or
Deno.readTextFile() in combination with JSON.parse(). Starting up with this
delivery it’s probably you’ll well import JSON files without prolong into your module graph:



const response = sit down up for accumulate("https://example.com/records.json");
const jsonData = sit down up for response.json();
console.log(jsonData);


const textual recount = sit down up for Deno.readTextFile("./records.json");
const jsonData = JSON.parse(textual recount);
console.log(jsonData);




import jsonData from "https://exmaple.com/records.json" hiss { kind:  "json" };
console.log(jsonData);


import jsonData from "./records.json" hiss { kind:  "json" };
console.log(jsonData);

It’s probably you’ll well well seemingly also import JSON modules dynamically the employ of import():

const jsonData = sit down up for import("./records.json", { hiss:  { kind:  "json" } });
console.log(jsonData);

An abet of the employ of import declarations for JSON modules is that you scheme no longer
want to supply permissions to import them; dynamic imports are field to
neatly-liked permissions assessments.

Improvements to the Internet Cryptography API

This delivery once another time adds contemporary aspects to the Internet Cryptography API. With
these additions, the API is now nearing characteristic parity with browsers.

Added in v1.17:

  • crypto.subtle.importKey:
    • increase importing RSA keys in SPKI format
    • increase importing RSA keys in JWK format
    • increase importing AES keys in JWK format
    • increase importing EC keys in PKCS#8 format
    • increase importing EC keys in SPKI format
    • increase importing EC keys in JWK format
  • crypto.subtle.exportKey:
    • increase exporting RSA keys in JWK format
    • increase exporting AES keys in JWK format
  • crypto.subtle.unwrapKey:
    • increase for unwrapping the employ of RSA-OAEP
    • increase for unwrapping the employ of AES-GCM

The closing few aspects (elliptic curve key imports and exports, and more AES
encryption/decryption formats) are aloof in pattern, but are coming alongside
neatly and is all the time readily accessible within the next delivery.

Gape development right here:
denoland/deno#11690

Due to the Yacine Hmito,
Sean Michael Wykes and
Divy Srivastava for contributing these
improvements.

--no-test=faraway flag

One of many neatly-liked challenges with Deno is that once shortly faraway dependencies
scheme no longer kind test properly even supposing they’ve the honest runtime habits.
When kind checking your local code this would well cause diagnostics to be issued and
your program no longer to flee even ought to you’ve gotten no adjust over the faraway
dependencies.

The --no-test=faraway option turned into once added to abet with this. When this flag is
handed, this arrangement will be kind checked as a full, but any diagnostics that
are coming from a faraway module will be discarded. If there are no local
diagnostics, your program will flee.

Trudge the option on the characterize line:

> deno flee --no-test=faraway server.ts

We abet you to experiment with this flag and tale feedback. We think this
mode shall be an even default kind checking configuration for future releases of
Deno.

Unstable increase for negotiating ALPN for Deno.connectTls()

ALPN is a TLS extension that allows a shopper to barter a communication
protocol with a server. Right here is old fashioned when the employ of HTTP/2 for instance, to barter
if the server helps HTTP/2.

Up to now Deno didn’t increase manually negotiating ALPN. This delivery adds that
capability. For these who shall be drawn to this functionality, we would get rid of to listen to your
feedback.

An example:

const conn = sit down up for Deno.connectTls({
  hostname:  "example.com",
  port:  443,
  alpnProtocols:  ["h2", "http/1.1"],
});
const { alpnProtocol } = sit down up for conn.handshake();
if (alpnProtocol !== null) {
  console.log("Negotiated protocol:", alpnProtocol);
} else {
  console.log("No protocol negotiated");
}

Due to the Yury Selivanov for contributing this
characteristic.

Unref timers

This delivery adds two contemporary unstable APIs:

  • Deno.unrefTimer(identification: quantity)
  • Deno.refTimer(identification: quantity)

These APIs will be old fashioned to switch the habits of timers (setTimeout and
setInterval) to block or no longer block the match loop from exiting.

By default all timers block the match loop from exiting unless they’re cleared.

In the next example this arrangement will produce after printing
hello from timeout after 5 seconds.

setTimeout(() => {
  console.log("hello from timeout");
}, 5000);

console.log("hello world!");

Alternatively once shortly or no longer it’s far not desired for timers to cease the match loop from
exiting. An example of this habits is periodic series of telemetry records:

setInterval(() => {
  const records = collectSomeData();
  accumulate("https://example.com/telemetry", { means:  "POST", body:  records })
    .have interaction(() => {});
}, 5000);


sit down up for longRunningTask();

In the above example, we desire our program to exit once longRunningTask
finishes. To provide this habits we are in a position to “unref” the interval:

const intervalId = setInterval(() => {
  const records = collectSomeData();
  accumulate("https://example.com/telemetry", { body:  records }).have interaction(() => {});
}, 5000);


Deno.unrefTimer(intervalId);


sit down up for longRunningTask();

Updates to abort reasons in AbortSignal

The closing delivery added increase for aborting AbortSignals with explicit abort
reasons. These reasons are now accurately propagated thru these APIs:

  • Deno.readFile() and Deno.readTextFile()
  • Deno.writeFile() and Deno.writeTextFile()
  • All of the WHATWG streams APIs (ReadableStream, TransformStream,
    WritableStream, and company).
  • WebSocketStream
  • accumulate, Inquire, and Response

As well we now increase the contemporary throwIfAborted() means on AbortSignal
that will be old fashioned to synchronously throw an error if the signal has already been
aborted.

const controller = contemporary AbortController();
const signal = controller.signal;

strive {
  signal.throwIfAborted();
} have interaction (err) {
  unreachable(); 
}

controller.abort("Good day World");

strive {
  signal.throwIfAborted();
  unreachable(); 
} have interaction (err) {
  assertEquals(err, "Good day World");
}

Due to the Andreu Botella for contributing
these changes.

Updates to the Deno Language Server

The Deno Language Server adds increase for a revised module registry suggestion
protocol. This also can simply permit gigantic equipment registries (cherish NPM) to supply partial
consequence models, luminous incremental search, and documentation details about
packages and modules as fragment of the editing abilities. Adding the contemporary
capabilities to deno.land/x and deno.land/std will occur soon after 1.17
ships.

Another within the back of the scenes enchancment is that the values from the equipment
registries will respect the cache headers supplied. Previously, the outcomes from
a registry had been cached indefinitely and required users to certain the cache
manually to fetch contemporary or changed outcomes.

To get rid of abet of these aspects, accomplish obvious that your editor’s Deno
configuration involves supported registries within the deno.counsel.imports.hosts
are configured. As an illustration:

{
  "deno.counsel.imports.hosts":  {
    "https://deno.land":  honest,
    "https://cdn.nest.land":  honest,
    "https://crux.land":  honest
  }
}

Whereas no longer connected on to the Deno 1.17 delivery,
vscode_deno
is being up up to now to permit identified equipment registries which increase the registry
protocol by default. This also can simply expand visibility of this characteristic, making it
more uncomplicated for parents to gain code to flee below Deno.

With the contemporary aspects of the registry protocol, we hope to work with the likes
of esm.sh, Skypack and
JSPM to supply luminous registries to accomplish it easy to
like code from the broader JavaScript and TypeScript ecosystem.

For these who shall be attempting to maintain with the map to add increase for import completions to your fill registry, it’s probably you’ll well
read more about
the registry protocol
right here.

Also, the Deno Language Server reaches a level of maturity, adding a few
vital aspects, including goto kind definition increase and workspace
symbol looking out
.

Updates to deno test

Deno ships with a constructed-in test runner. It’s probably you’ll well well seemingly register tests the employ of
Deno.test() API. Till now there were two readily accessible overloads of the API –
“shorthand” and “definition” based mostly. The shorthand works neatly for easy tests,
while the definition offers primarily the most adjust, pondering example tests to be
skipped over:

import { assertEquals } from "https://deno.land/std@0.118.0/testing/asserts.ts";

Deno.test("My test description", ():  void => {
  assertEquals("hello", "hello");
});

Deno.test({
  name:  "example test",
  ignore:  Deno.kind.os == "dwelling windows",
  fn():  void {
    assertEquals("world", "world");
  },
});

It becomes quite cumbersome if or no longer it’s important to overlook/focal point a single test that turned into once
written the employ of “shorthand” overload. That it’s probably it is advisable rewrite entire test to employ
the “definition” overload. To alleviate this field and provide more
flexibility in writing tests now we maintain added four more overloads to the
Deno.test() API.

import { assertEquals } from "https://deno.land/std@0.118.0/testing/asserts.ts";

Deno.test(honest myTestName():  void {
  assertEquals("hello", "hello");
});

Deno.test("My test description", { permissions:  { read:  honest } }, ():  void => {
  assertEquals("hello", "hello");
});

Deno.test(
  { name:  "My test description", permissions:  { read:  honest } },
  ():  void => {
    assertEquals("hello", "hello");
  },
);

Deno.test({ permissions:  { read:  honest } }, honest myTestName():  void {
  assertEquals("hello", "hello");
});

It’s probably you’ll well well seemingly now mix both forms, and provide a partial “definition” as the critical or
second argument.

Another update is for users the employ of unstable test steps API. The final test tale
output will now embody selection of test steps with distinction for
handed/skipped over/failed steps. The test step API is scheduled to be stabilized in
v1.18

Deno.test("nested failure", async (t) => {
  const success = sit down up for t.step("step 1", async (t) => {
    let success = sit down up for t.step("internal 1", () => {
      throw contemporary Error("Failed.");
    });
    if (success) throw contemporary Error("Anticipated failure");

    success = sit down up for t.step("internal 2", () => {});
    if (!success) throw contemporary Error("Anticipated success");
  });

  if (success) throw contemporary Error("Anticipated failure");
});
$ deno test --unstable test.ts
working 1 test from file:///dev/test.ts
test nested failure ...
  test step 1 ...
    test internal 1 ... FAILED (11ms)
      Error: Failed.
          at file:///dev/test.ts:4: 13
          at testStepSanitizer (deno:runtime/js/40_testing.js: 187: 13)
          at asyncOpSanitizer (deno:runtime/js/40_testing.js: 68: 15)
          at resourceSanitizer (deno:runtime/js/40_testing.js: 138: 13)
          at exitSanitizer (deno:runtime/js/40_testing.js: 170: 15)
          at TestContext.step (deno:runtime/js/40_testing.js: 800: 19)
          at file:///dev/test.ts:3: 27
          at testStepSanitizer (deno:runtime/js/40_testing.js: 187: 13)
          at asyncOpSanitizer (deno:runtime/js/40_testing.js: 68: 15)
          at resourceSanitizer (deno:runtime/js/40_testing.js: 138: 13)
    test internal 2 ... ok (11ms)
  FAILED (32ms)
FAILED (44ms)

failures:

nested failure
Error: 1 test step failed.
    at runTest (deno:runtime/js/40_testing.js: 432: 11)
    at async Object.runTests (deno:runtime/js/40_testing.js: 541: 22)

failures:

    nested failure

test consequence: FAILED. 0 handed (1 step); 1 failed (2 steps); 0 skipped over; 0 measured; 0 filtered out (66ms)

Updates to the file watcher

Deno ships with a constructed-in file watcher that will be activated the employ of the
--peek flag.

The file watcher mechanically discovers files to peek in step with the files
contained in module graph (for the deno flee subcommand) or file paths handed
as arguments (for subcommands cherish deno lint or deno fmt).

On this delivery the --peek flag for deno flee accepts an optionally accessible checklist of
exterior files that ought to even be watched for changes.

$ deno flee --peek=records/exterior.txt script.ts

Due to the Jasper van den Ende for
contributing this characteristic.

A minute effective of existence enchancment to the watcher is automatic clearing of
terminal screen screen on restart:

Updates to the REPL

Module specifier completions

The REPL (deno repl) now offers completions for relative specifiers on the
file system and absolute specifiers from the deno.land
registry.

These completions will be requested by pressing the key while typing a
module specifier.

Node.js compatibility mode

The REPL can now be flee in
Node.js compatibility mode;
allowing fetch entry to to Node’s world variables (eg. direction of), import CommonJS
modules with require() and offering ESM resolution like minded with Node.js.
To enter REPL in compatibility mode employ deno repl --compat --unstable.

$ deno repl --compat --unstable
Deno 1.17.0
exit the employ of ctrl+d or shut()
> console.log(direction of)
direction of {
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  ...
}

Ignore certificate errors

This delivery adds the --unsafely-ignore-certificate-errors flag to the
deno repl subcommand that allows disabling TLS certificate verification.

Demonstrate that right here’s a unpleasant atmosphere. You mustn’t employ this flag to
silence certificate errors. Disabling TLS certificate verification (ignoring
certificate errors) makes TLS pointless because of it permits MITM assaults. Info
sent over a TLS connection will not be any longer confidential if the certificate has no longer been
verified and relied on.

Learn more in Deno 1.13 Liberate Notes weblog put up.

Due to the VishnuJin for contributing this
characteristic.

Updates to the FFI API

Following
improvements to the FFI API in v1.15
this delivery adds two contemporary APIs for working with pointers all over languages
boundary: Deno.UnsafePointer and Deno.UnsafePointerView. Additionally
buffer parameter kind turned into once renamed to pointer.

Example:

static BUFFER:  [u8; 8] = [1, 2, 3, 4, 5, 6, 7, 8];

#[no_mangle]
pub extern "C" fn return_buffer() -> *const u8 {
  BUFFER.as_ptr()
}

#[no_mangle]
pub extern "C" fn is_null_ptr(ptr:  *const u8) -> u8 {
  ptr.is_null() as u8
}
const [libPrefix, libSuffix] = {
  darwin:  ["lib", "dylib"],
  linux:  ["lib", "so"],
  dwelling windows:  ["", "dll"],
}[Deno.build.os];
const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`;

const dylib = Deno.dlopen(libPath, {
  "return_buffer":  { parameters:  [], consequence:  "pointer" },
  "is_null_ptr":  { parameters:  ["pointer"], consequence:  "u8" },
});

const ptr = dylib.symbols.return_buffer();
dylib.symbols.print_buffer(ptr, 8);
const ptrView = contemporary Deno.UnsafePointerView(ptr);
const into = contemporary Uint8Array(6);
const into2 = contemporary Uint8Array(3);
const into2ptr = Deno.UnsafePointer.of(into2);
const into2ptrView = contemporary Deno.UnsafePointerView(into2ptr);
const into3 = contemporary Uint8Array(3);
ptrView.copyInto(into);
console.log([...into]);
ptrView.copyInto(into2, 3);
console.log([...into2]);
into2ptrView.copyInto(into3);
console.log([...into3]);
const string = contemporary Uint8Array([
  ...new TextEncoder().encode("Hello from pointer!"),
  0,
]);
const stringPtr = Deno.UnsafePointer.of(string);
const stringPtrview = contemporary Deno.UnsafePointerView(stringPtr);
console.log(stringPtrview.getCString());
console.log(stringPtrview.getCString(11));
console.log(Boolean(dylib.symbols.is_null_ptr(ptr)));
console.log(Boolean(dylib.symbols.is_null_ptr(null)));
console.log(Boolean(dylib.symbols.is_null_ptr(Deno.UnsafePointer.of(into))));
$ deno flee --permit-ffi --permit-read --unstable test_ffi.js
[1, 2, 3, 4, 5, 6, 7, 8]
[ 1, 2, 3, 4, 5, 6 ]
[ 4, 5, 6 ]
[ 4, 5, 6 ]
Good day from pointer!
pointer!
unsuitable
honest
unsuitable

We’re already seeing attention-grabbing initiatives the employ of these contemporary APIs, eg. native
bindings to SQLite C API: https://deno.land/x/sqlite3

FFI requires the --permit-ffi and the --unstable flags. Beware that enabling
FFI will successfully disable all security protections in Deno.

Thank you to Elias SjΓΆgreen for contributing
this characteristic.

TypeScript 4.5

Deno 1.17 ships with the newest exact model of TypeScript. This turned into once fragment of
what unlocked the flexibility to increase import assertions. Also, a recent system to
import sorts is supported:

Previously it turned into once instructed to import objects absolute most practical be old fashioned within the kind arrangement
this kind:

import { A } from "https://example.com/mod.ts";
import kind { B } from "https://example.com/mod.ts";

But now these will be mixed into a single import assertion:

import { A, kind B } from "https://example.com/mod.ts";

Also, TypeScript 4.5 added increase for .mts and .d.mts extensions as neatly as
first class increase for .mjs files, which shall be properly handled in Deno 1.17.

For more records on contemporary aspects in TypeScript gaze
TypeScript’s 4.5 weblog put up

Updates to the neatly-liked library

This delivery involves a vary of contemporary aspects and breaking changes to the
neatly-liked library. We’re onerous at work at cleansing up the neatly-liked library to fetch
it into a enlighten the attach it would stabilized.

Breaking changes

In model 0.118.0 of deno_std following APIs undergone breaking changes:

  • ws module turned into once removed – in its place employ Deno.upgradeWebSocket() API
  • assertThrowsAsync from testing/asserts.ts turned into once removed – in its place employ
    assertRejects API from the the same module
  • http/server_legacy.ts turned into once removed – a legacy implementation of HTTP server,
    in its place employ http/server.ts
  • copy API turned into once removed from fs/mod.ts – in its place import this API without prolong
    from fs/copy.ts
  • onSignal turned into once removed from indicators module – in its place employ
    Deno.addSignalListener() API
  • findLast and findLastIndex had been removed from collections module
  • http server module now no longer accepts string tackle, employ
    { host: string, port: quantity } interface in its place

Contemporary HTTP server choices

Previously the abet honest within the std/http module would swallow all
errors produced by the HTTP handler honest. This delivery changes that
habits, so as that the server will log all errors produced by handlers the employ of
console.error. It’s probably you’ll well well seemingly customize the habits by passing a custom onError
honest to the abet choices.

import { Server } from "https://deno.land/std@0.118.0/http/server.ts";

const port = 4505;
const handler = (seek records from:  Inquire) => {
  const body = `Your consumer-agent is:nn${
    seek records from.headers.fetch(
      "consumer-agent",
    ) ?? "Unknown"
  }`;

  return contemporary Response(body, { region:  200 });
};

const onError = (_error:  unknown) => {
  return contemporary Response("custom error page", { region:  500 });
};

const server = contemporary Server({ port, handler, onError });

Additions to std/collections

std/collections is a playground for us to experiment with more fine
choices for iterating over arrays and iterables. This delivery adds
aggregateGroups. It applies the given aggregator to each community within the given
grouping, returning the outcomes alongside with the respective community keys:

import { aggregateGroups } from "https://deno.land/std@0.118.0/collections/mod.ts";
import { assertEquals } from "https://deno.land/std@0.118.0/testing/asserts.ts";
const foodProperties = {
  "Curry":  ["spicy", "vegan"],
  "Omelette":  ["creamy", "vegetarian"],
};
const descriptions = aggregateGroups(
  foodProperties,
  (present, key, first, acc) => {
    if (first) {
      return `${key} is ${present}`;
    }
    return `${acc} and ${present}`;
  },
);
assertEquals(descriptions, {
  "Curry":  "Curry is animated and vegan",
  "Omelette":  "Omelette is creamy and vegetarian",
});

Byte formatting the employ of std/fmt/bytes

A brand contemporary std/fmt/bytes module has been added to the neatly-liked library. It offers
a honest for formatting bytes in a human readable format:

import { prettyBytes } from "https://deno.land/std@0.118.0/fmt/bytes.ts";
import { assertEquals } from "https://deno.land/std@0.118.0/testing/asserts.ts";

assertEquals(prettyBytes(1024), "1.02 kB");
assertEquals(prettyBytes(1024, { binary:  honest }), "1 kiB");

This API is a port of the favored
stunning-bytes npm equipment.

Be a half of the pack! Be a half of 8000+ others registered users, and fetch chat, accomplish teams, put up updates and repair company around the enviornment!
https://www.knowasiak.com/register/

Knowasiak
WRITTEN BY

Knowasiak

Hey! look, i give tutorials to all my users and i help them!