Socket
Socket
Sign inDemoInstall

@lanetix/type-visitor

Package Overview
Dependencies
0
Maintainers
18
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.1 to 4.0.2

45

lib/index.js
/* eslint-disable no-new-wrappers */
/* Suggested by Mike Atkins: use `String` as a crude proxy for `Symbol` */
'use strict';

@@ -9,12 +8,13 @@

var tyfun = {
unit: new String('unit'),
id: new String('id'),
string: new String('string'),
integer: new String('integer'),
decimal: new String('decimal'),
date: new String('date'),
list: new String('list'),
option: new String('option'),
sum: new String('sum'),
product: new String('product')
unit: 'unit',
id: 'id',
string: 'string',
integer: 'integer',
decimal: 'decimal',
date: 'date',
list: 'list',
option: 'option',
sum: 'sum',
product: 'product',
price: 'price'
};

@@ -24,7 +24,7 @@

var visitContext = {
top: new String('top'),
listChild: new String('list'),
optionChild: new String('option'),
sumChild: new String('sum'),
productChild: new String('product')
top: 'top',
listChild: 'list',
optionChild: 'option',
sumChild: 'sum',
productChild: 'product'
};

@@ -76,2 +76,5 @@ exports.visitContext = visitContext;

return varop(down, acc, { fun: tyfun.product, args: args, ctx: ctx });
},
price: function price(acc, ctx) {
return prim(acc, { fun: tyfun.price, ctx: ctx });
}

@@ -93,2 +96,3 @@ };

var product = _ref6.product;
var price = _ref6.price;

@@ -205,2 +209,4 @@ var visitInner = function visitInner(acc, _ref7) {

return check_varop({ tag: visitContext.productChild, check: product });
case tyfun.price:
return check_primitive(price);
default:

@@ -279,2 +285,5 @@ throw new Error('invalid type function');

});
},
price: function price(exp) {
return typeof exp === 'number' && Number.isFinite(exp);
}

@@ -309,2 +318,4 @@ });

return builtin('product');
case tyfun.price:
return builtin('price');
default:

@@ -344,2 +355,4 @@ // should be unreachable since this is only called internally from visit.

return tyfun.product;
case 'price':
return tyfun.price;
default:

@@ -346,0 +359,0 @@ throw new Error('invalid type function name');

{
"name": "@lanetix/type-visitor",
"version": "4.0.1",
"version": "4.0.2",
"description": "visit your types",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -10,2 +10,60 @@ @lanetix/type-visitor

Definitions
-----------
* `prim` = primitive type = type function that takes no args
* `varop` = variatic type = type function that takes >1 arg (such as a set of other types)
* `unop` = uniary type = type function that takes only 1 arg
Lx types (system fields) that exist on every record type (except Lx users). Not nullable, therefor never wrapped in `tyfun.option`
* name = string prim
* created_at = date prim
* updated_at = date prim
* owner_id = id prim
### Primitive Types
#### `tyfun.unit`
* tyfun.unit are values which are empty
* {}
#### `tyfun.decimal`
#### `tyfun.id`
#### `tyfun.integer`
#### `tyfun.date`
#### `tyfun.string`
#### `tyfun.price`
### Uniary Types
#### `tyfun.option`
* always wraps another type
* nullable -- is either null, or it’s type. There is no concept of default values.
* type-checked will be “if optional, traverse down and see what type you are”. See child, and bring back
up value in the `acc`
* The Postgres db interface wraps all nullable fields in `tyfun.option`. If a type shows up in the GUI and it's not wrapped in `tyfun.option`, then it's not nullable.
#### `tyfun.list`
* Only 1 type allowed in a list
* But type can be complex (json, list of lists)
### Variadic Types
#### `tyfun.sum`
* Bools are treated as sum types whose value is one `tyfun.unit` (`true` or `false`)
* The value in the field is only a single value, but the type is of any of the possible types defined
* In `tyfun.sum` there will be multiple tags each mapped to a type - `{ tag: type, tag: type }`, but in any instance of this type only one tag will have an associated value
#### `tyfun.product`
* Tuples with labels `k:v`
* Values are of different types, but are defined types
* can mutate with additive changes `{ k1:int, k2:string } —> { k1:int, k2:string, k3:int }`
* record types themselves are products
[More about sum and product types](https://chadaustin.me/2015/07/sum-types/)
Usage

@@ -18,3 +76,3 @@ -----

An object of Type functions / type constructors. These are the "types of
types" that Lanetix supports internally. When writing a type of the form:
types" that Lanetix supports internally. When writing a type of the form:
`{ fun: `fun`, args: `args` }`, the `fun` part should be one of these

@@ -178,7 +236,7 @@ constants.

structure should be considered an opaque implementation detail--it should not
be used directly, except in order to pass it into intoTy.
be used directly, except in order to pass it into toTy.
### `intoTy`
### `toTy`
Takes a JSON structure created by toJson and parses it into a type tree. It
should only be used on JSON that was previously formed through toJson;
constructing the JSON directly isn't guaranteed to work.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc