Skip to content

Instantly share code, notes, and snippets.

Avatar
😇
Living the JS life

Vladimir de Turckheim vdeturckheim

😇
Living the JS life
View GitHub Profile
View typescript-js.md

Typescript is not really a superset of JavaScript

Let's consider T(ts: string): string, the function compiling TypeScript code to JavaScript. If TypeScript is a superset of JavaScript, then, for all valid Javascript expression js, T(js) === js as the compiler should consider valide JavaScript expression as valid TypeScript expression that do not need to be changed during compilation (of course, we consider that the JavaScript version of the input of T is the same as the output one).

In order to demonstrate that TypeScript is not a superset of JavaScript, one only need to find a single JavaScript expression jsbreak as of T(jsbreak) !== jsbreak.

View cb.cc
#include <stdlib.h>
#include <nan.h>
#include <v8.h>
#include <iostream>
using namespace v8;
using namespace std;
static string *get_string_from_item(Local<Context> context, Local<Value> item) {
if (!item->IsString()) {
View xray2.js
const AWSXRay = require('aws-xray-sdk');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
AWS.config.update({region: process.env.DEFAULT_AWS_REGION || 'us-west-2'});
AWSXRay.captureHTTPsGlobal(require('https'));
const Wreck = require('@hapi/wreck');
Wreck.get('https://amazon.com/', {})
.then((res) => {
View xray.js
const AWSXRay = require('aws-xray-sdk');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
AWS.config.update({region: process.env.DEFAULT_AWS_REGION || 'us-west-2'});
AWSXRay.captureHTTPsGlobal(require('https'));
const Wreck = require('wreck');
Wreck.get('https://amazon.com/', {}, (err, res) => {
console.log('err', !!err);
View ALS.md

AsyncLocalStorage API

The AsyncLocalStorage class has been introduced in the Async Hooks module.

This API allows keeping a context across asynchronous operations. For instance, if an sequence id is stored within an instance of AsyncLocalStorage for each entering HTTP requests in a server, it will be possible to retrieve this id without knowing the current HTTP request.

const http = require('http');
View fastr.js
'use strict';
const run = function (getStack) {
process.nextTick(() => {
process.nextTick(() => {
process.nextTick(() => {
process.nextTick(() => {
process.nextTick(() => {
process.nextTick(() => {
console.log(getStack());
})
View comparing_async_local_context.md

DISCLAIMER: This was a working document now availabe in nodejs/TSC#807. No comments on the current gist will be accepted

Executive summary: Introducing a CLS-like API to Node.js core

Context: the 3 PRs and 1 consensus

On the TSC meeting of 2020-JAN-22, the TSC reached consensus regarding the need to have an Asynchronous Storage API in core.

View async_storage.md

Most Node.js framework requires to pass an object representing the current HTTP request through every layers of the application. This is most visible in Expressjs-based applications:

// TODO middleware example

Other frameworks, will create an wrapping object around the raw Node.js request:

// TODO hapi link

But at the end of the day, developers end up passing bloated objects representing the requests through their codebase:

View README.md

MongoDB need to be installed and running on localhost (otherwise, edit the value of MONGO_URL in server.js).

For Sqreen to work, create a new application on https://my.sqreen.io and add the sqreen.json file to the root of the project.

Start the server with node server.js

Perform an attack with:

$ curl -X POST \
 http://localhost:3000/login \
View beyond_domains.md

Beyond Domains

Goal

The goal of this document is to analysis the content of the Domain Module Postmortem to define the need for either:

  • a new internal API in Node.js core (SOLUTION 1)
  • a solution to update domain API to have TSC reconsider its deprecation status (SOLUTION 2)
  • an external API to replace domain only in userland (SOLUTION 3)