Skip to content

Commit

Permalink
Remove S_JsApi in favor of S_Core
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Oct 10, 2023
1 parent 9846bfa commit ba64497
Show file tree
Hide file tree
Showing 29 changed files with 759 additions and 1,130 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Highlights:
- Strict mode for object structs to prevent excessive fields and many more built-in helpers
- Works with plain JavaScript/TypeScript too! You don't need to use ReScript
- The **fastest** composable validation library in the entire JavaScript ecosystem ([benchmark](https://moltar.github.io/typescript-runtime-type-benchmarks/))
- Small and tree-shakable: [8.5kB minified + zipped](https://bundlephobia.com/package/rescript-struct)
- Small and tree-shakable: [9.5kB minified + zipped](https://bundlephobia.com/package/rescript-struct)

Also, it has declarative API allowing you to use **rescript-struct** as a building block for other tools, such as:

Expand Down
16 changes: 8 additions & 8 deletions docs/js-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,11 @@ Besides the individual bundle size, the overall size of the library is also sign

At the same time **rescript-struct** is the fastest composable validation library in the entire JavaScript ecosystem. This is achieved because of the JIT approach when an ultra optimized validator is created using `eval`.

| | rescript-struct@5.0.1 | [email protected] | [email protected] |
| ---------------------------------------- | --------------------- | --------------- | -------------- |
| **Total size** (minified + gzipped) | 8.5 kB | 13.2 kB | 6.6 kB |
| **Example size** (minified + gzipped) | 6.08 kB | 12.8 kB | 965 B |
| **Performance** (Example parsing) | 1,030,417 ops/ms | 376 ops/ms | 24,034 ops/ms |
| **Eval-free** ||||
| **Codegen-free** (Doesn't need compiler) ||||
| **Ecosystem** | ⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️ |
| | rescript-struct@5.1.0 (unreleased) | [email protected] | [email protected] |
| ---------------------------------------- | ---------------------------------- | --------------- | -------------- |
| **Total size** (minified + gzipped) | 9.68 kB | 13.4 kB | 6.73 kB |
| **Example size** (minified + gzipped) | 5.92 kB | 12.8 kB | 965 B |
| **Performance** (Example parsing) | 1,030,417 ops/ms | 376 ops/ms | 24,034 ops/ms |
| **Eval-free** | |||
| **Codegen-free** (Doesn't need compiler) | |||
| **Ecosystem** | ⭐️ | ⭐️⭐️⭐️⭐️⭐️ | ⭐️⭐️ |
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
"type": "module",
"main": "./dist/S.js",
"module": "./dist/S.mjs",
"types": "./src/S_JsApi.d.ts",
"types": "./src/S.d.ts",
"files": [
"dist",
"src/S_Core.res",
"src/S_Core.bs.js",
"src/S_Core.bs.mjs",
"src/S.res",
"src/S.resi",
"src/S_JsApi.d.ts",
"src/S.d.ts",
"RescriptStruct.gen.ts",
"bsconfig.json"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/artifacts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Highlights:
- Strict mode for object structs to prevent excessive fields and many more built-in helpers
- Works with plain JavaScript/TypeScript too! You don't need to use ReScript
- The **fastest** composable validation library in the entire JavaScript ecosystem ([benchmark](https://moltar.github.io/typescript-runtime-type-benchmarks/))
- Small and tree-shakable: [8.5kB minified + zipped](https://bundlephobia.com/package/rescript-struct)
- Small and tree-shakable: [9.5kB minified + zipped](https://bundlephobia.com/package/rescript-struct)

Also, it has declarative API allowing you to use **rescript-struct** as a building block for other tools, such as:

Expand Down
186 changes: 26 additions & 160 deletions packages/artifacts/dist/S.js
Original file line number Diff line number Diff line change
@@ -1,160 +1,26 @@
'use strict';

var Caml_option = require('rescript/lib/js/caml_option.js');
var S = require('./../src/S_Core.bs.js');

function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}

var Caml_option__namespace = /*#__PURE__*/_interopNamespaceDefault(Caml_option);
var S__namespace = /*#__PURE__*/_interopNamespaceDefault(S);

// Generated by ReScript, PLEASE EDIT WITH CARE

function toJsResult(result) {
if (result.TAG === "Ok") {
return {
success: true,
value: result._0
};
} else {
return {
success: false,
error: result._0
};
}
}

function transform$1(struct, maybeParser, maybeSerializer) {
return S__namespace.transform(struct, (function (s) {
return {
p: maybeParser !== undefined ? (function (v) {
return maybeParser(v, s);
}) : undefined,
s: maybeSerializer !== undefined ? (function (v) {
return maybeSerializer(v, s);
}) : undefined
};
}));
}

function refine$1(struct, refiner) {
return S__namespace.refine(struct, (function (s) {
return function (v) {
refiner(v, s);
};
}));
}

function noop(a) {
return a;
}

function asyncParserRefine$1(struct, refine) {
return S__namespace.transform(struct, (function (s) {
return {
a: (function (v) {
return function () {
return refine(v, s).then(function () {
return v;
});
};
}),
s: noop
};
}));
}

function optional$1(struct, maybeOr) {
var struct$1 = S__namespace.option(struct);
if (maybeOr === undefined) {
return struct$1;
}
var or = Caml_option__namespace.valFromOption(maybeOr);
if (typeof or === "function") {
return S__namespace.$$Option.getOrWith(struct$1, or);
} else {
return S__namespace.$$Option.getOr(struct$1, or);
}
}

function tuple$1(definer) {
if (typeof definer === "function") {
return S__namespace.tuple(definer);
} else {
return S__namespace.tuple(function (s) {
return definer.map(function (struct, idx) {
return s.i(idx, struct);
});
});
}
}

function custom$1(name, maybeParser, maybeSerializer, param) {
return S__namespace.custom(name, (function (s) {
return {
p: maybeParser !== undefined ? (function (v) {
return maybeParser(v, s);
}) : undefined,
s: maybeSerializer !== undefined ? (function (v) {
return maybeSerializer(v, s);
}) : undefined
};
}));
}

function object$1(definer) {
if (typeof definer === "function") {
return S__namespace.object(definer);
} else {
return S__namespace.object(function (s) {
var definition = {};
var fieldNames = Object.keys(definer);
for(var idx = 0 ,idx_finish = fieldNames.length; idx < idx_finish; ++idx){
var fieldName = fieldNames[idx];
var struct = definer[fieldName];
definition[fieldName] = s.f(fieldName, struct);
}
return definition;
});
}
}

function parse$1(struct, data) {
return toJsResult(S__namespace.parseAnyWith(data, struct));
}

function parseOrThrow$1(struct, data) {
return S__namespace.parseAnyOrRaiseWith(data, struct);
}

function parseAsync$1(struct, data) {
return S__namespace.parseAnyAsyncWith(data, struct).then(toJsResult);
}

function serialize$1(struct, value) {
return toJsResult(S__namespace.serializeToUnknownWith(value, struct));
}

function serializeOrThrow$1(struct, value) {
return S__namespace.serializeToUnknownOrRaiseWith(value, struct);
}
/* S_Core-RescriptStruct Not a pure module */

const Error = S__namespace.$$Error.$$class;
const string = S__namespace.string;
const boolean = S__namespace.bool;
Expand All @@ -164,30 +30,30 @@ const json = S__namespace.json;
const never = S__namespace.never;
const unknown = S__namespace.unknown;
const undefined$1 = S__namespace.unit;
const optional = optional$1;
const optional = S__namespace.js_optional;
const nullable = S__namespace.$$null;
const array = S__namespace.array;
const record = S__namespace.dict;
const jsonString = S__namespace.jsonString;
const union = S__namespace.union;
const object = object$1;
const object = S__namespace.js_object;
const Object$1 = S__namespace.$$Object;
const String = S__namespace.$$String;
const Number = S__namespace.Float;
const Array = S__namespace.$$Array;
const custom = custom$1;
const custom = S__namespace.js_custom;
const literal = S__namespace.literal;
const tuple = tuple$1;
const asyncParserRefine = asyncParserRefine$1;
const refine = refine$1;
const transform = transform$1;
const tuple = S__namespace.js_tuple;
const asyncParserRefine = S__namespace.js_asyncParserRefine;
const refine = S__namespace.js_refine;
const transform = S__namespace.js_transform;
const description = S__namespace.description;
const describe = S__namespace.describe;
const parse = parse$1;
const parseOrThrow = parseOrThrow$1;
const parseAsync = parseAsync$1;
const serialize = serialize$1;
const serializeOrThrow = serializeOrThrow$1;
const parse = S__namespace.js_parse;
const parseOrThrow = S__namespace.js_parseOrThrow;
const parseAsync = S__namespace.js_parseAsync;
const serialize = S__namespace.js_serialize;
const serializeOrThrow = S__namespace.js_serializeOrThrow;

exports.Array = Array;
exports.Error = Error;
Expand Down
Loading

0 comments on commit ba64497

Please sign in to comment.