@lanetix/type-visitor
Advanced tools
Comparing version 4.0.1 to 4.1.0
/* eslint-disable no-new-wrappers */ | ||
/* Suggested by Mike Atkins: use `String` as a crude proxy for `Symbol` */ | ||
'use strict'; | ||
@@ -9,12 +8,12 @@ | ||
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' | ||
}; | ||
@@ -24,7 +23,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' | ||
}; | ||
@@ -31,0 +30,0 @@ exports.visitContext = visitContext; |
{ | ||
"name": "@lanetix/type-visitor", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "visit your types", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -10,2 +10,56 @@ @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` | ||
### 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 +72,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 | ||
@@ -21,0 +75,0 @@ constants. |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21173
236
376