Skip to content

Commit

Permalink
fix: disable incomplete symbol/function/promise support (leaving Zode…
Browse files Browse the repository at this point in the history
…x schema)
  • Loading branch information
brettz9 committed Aug 14, 2024
1 parent 5116f6d commit 35d4de9
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 226 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGES TO `@es-joy/jsoe`

## 0.20.4

- fix: disable incomplete symbol/function/promise support (leaving Zodex
schema)

## 0.20.3

- fix: require object only if no schema
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,25 @@ Supported types include:
- string
- `undefined`

There are also the following fundamental (Zodex) schema types:
There are also the following fundamental (structured-cloning capable
Zodex) schema types:

- `boolean` (using in place of true/false when schema specifies)
- `catch`
- `enum`
- `function` (not structured cloning)
- `literal`
- `nan` (standalone in Zodex)
- `nativeEnum`
- `promise` (not structured cloning)
- `record`
- `symbol` (not structured cloning)
- `tuple`
- `void` (preferred in Zodex when specified as such)

Work has begun on the following non-structured-cloning Zodex schema types:

- `function`
- `promise`
- `symbol`

## Subtypes

These map to a subset of JavaScript language structures. Note that false and true were common and limited enough in number to justify their own subtype for the sake of having a quick pull-down entry.
Expand Down
2 changes: 1 addition & 1 deletion demo/index-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const schemaInstanceJSONStrings9 = {
// additional validations
// Todo: allow function/promise/symbol to be cloneable albeit not through
// structured cloneable; note that typeson has an issue for
// symbol-iterating keys; then add to regular demo and test
// symbol-iterating keys; then add to regular demo and test; add tests

/**
* @param {string} schema
Expand Down
12 changes: 7 additions & 5 deletions demo/schema-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ const schemaInstanceJSON2 = {
}
}
},
// Todo: Support `symbol`
// {
// description: 'A symbol',
// type: 'symbol'
// },

{
description: 'An array with mins and maxes',
type: 'array',
Expand Down Expand Up @@ -533,6 +529,12 @@ const schemaInstanceJSON7 = {
type: 'never'
}

// Todo: Support `symbol`
// {
// description: 'A symbol',
// type: 'symbol'
// },

// Todo: Support `Promise`
// {
// description: 'A Promise',
Expand Down
132 changes: 30 additions & 102 deletions instrumented/demo/index-schema.js

Large diffs are not rendered by default.

128 changes: 28 additions & 100 deletions instrumented/demo/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@es-joy/jsoe",
"version": "0.20.3",
"version": "0.20.4",
"type": "module",
"types": "./dist/index.d.ts",
"main": "./src/index.js",
Expand Down
7 changes: 3 additions & 4 deletions src/formats/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ const zodexToStructuredCloningTypeMap = new Map([
['map', 'map'],
['set', 'set'],

['symbol', 'symbol'],

['never', 'never'],

// Todo: Allow non-cloning version to return these too, but filter out
// otherwise
['function', 'function'],
['promise', 'promise'],
// ['symbol', 'symbol'],
// ['function', 'function'],
// ['promise', 'promise'],

['catch', 'catch'],
['nativeEnum', 'nativeEnum']
Expand Down
23 changes: 14 additions & 9 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import nullType from './fundamentalTypes/nullType.js';
import trueType from './subTypes/trueType.js';
import falseType from './subTypes/falseType.js';
import nanType from './fundamentalTypes/nanType.js';
import symbolType from './fundamentalTypes/symbolType.js';
import blobHTMLType from './subTypes/blobHTMLType.js';
import booleanType from './fundamentalTypes/booleanType.js';
import numberType from './fundamentalTypes/numberType.js';
Expand Down Expand Up @@ -53,11 +52,14 @@ import dommatrixType from './superTypes/dommatrixType.js';
import buffersourceType from './superTypes/buffersourceType.js';
import noneditableType from './fundamentalTypes/noneditableType.js';
import neverType from './fundamentalTypes/neverType.js';
import promiseType from './fundamentalTypes/promiseType.js';
import functionType from './fundamentalTypes/functionType.js';
import catchType from './fundamentalTypes/catchType.js';
import nativeEnumType from './fundamentalTypes/nativeEnumType.js';

// Todo: Reenable
// import symbolType from './fundamentalTypes/symbolType.js';
// import promiseType from './fundamentalTypes/promiseType.js';
// import functionType from './fundamentalTypes/functionType.js';

/**
* Utility to retrieve the property value given a legend element.
* @param {HTMLLegendElement} legend
Expand Down Expand Up @@ -417,11 +419,11 @@ export const getPropertyValueFromLegend = (legend) => {
* "int32array"|"uint32array"|"float32array"|"float64array"|"ValidDate"|
* "arrayNonindexKeys"|"error"|"errors"|"blob"|"domexception"|"domrect"|
* "dompoint"|"dommatrix"|"resurrectable"|"boolean"|"nan"|"tuple"|
* "record"|"void"|"enum"|"literal"|"symbol"|"never"|"promise"|
* "function"|"catch"|"nativeEnum"
* "record"|"void"|"enum"|"literal"|"never"|"catch"|"nativeEnum"
* } AvailableType
*/
// Todo: When done with function/promise/symbol, move off here
// Todo: Add to own section when ready for these non-structured-cloning:
// "symbol"|"promise"|"function"

/**
* @typedef {TypeObject & {
Expand Down Expand Up @@ -451,7 +453,6 @@ class Types {
true: trueType,
false: falseType,
nan: nanType, // Schema type
symbol: symbolType, // Non-cloning type
boolean: booleanType, // Schema type
number: numberType,
bigint: bigintType,
Expand Down Expand Up @@ -504,8 +505,12 @@ class Types {

resurrectable: noneditableType,
never: neverType,
promise: promiseType,
function: functionType,

// Todo: Reenable
// symbol: symbolType, // Non-cloning type
// promise: promiseType,
// function: functionType,

catch: catchType,
nativeEnum: nativeEnumType,

Expand Down

0 comments on commit 35d4de9

Please sign in to comment.