@livon/schema 0.27.0-rc.5 → 0.28.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -41
- package/THIRD_PARTY_NOTICES.md +28 -0
- package/dist/SchemaValidationError.cjs +26 -49
- package/dist/SchemaValidationError.d.ts +1 -1
- package/dist/SchemaValidationError.js +1 -14
- package/dist/after.cjs +26 -62
- package/dist/after.d.ts +1 -1
- package/dist/after.js +1 -27
- package/dist/and.cjs +48 -69
- package/dist/and.d.ts +31 -5
- package/dist/and.js +23 -34
- package/dist/api.cjs +71 -140
- package/dist/api.d.ts +3 -3
- package/dist/api.js +36 -94
- package/dist/array.cjs +31 -72
- package/dist/array.d.ts +1 -1
- package/dist/array.js +6 -34
- package/dist/before.cjs +26 -62
- package/dist/before.d.ts +1 -1
- package/dist/before.js +1 -27
- package/dist/binary.cjs +30 -71
- package/dist/binary.d.ts +1 -1
- package/dist/binary.js +5 -33
- package/dist/boolean.cjs +30 -71
- package/dist/boolean.d.ts +1 -1
- package/dist/boolean.js +5 -33
- package/dist/combinatorName.cjs +28 -45
- package/dist/combinatorName.js +3 -10
- package/dist/context.cjs +49 -121
- package/dist/context.d.ts +6 -6
- package/dist/context.js +14 -81
- package/dist/date.cjs +30 -71
- package/dist/date.d.ts +1 -1
- package/dist/date.js +5 -33
- package/dist/doc.cjs +37 -82
- package/dist/doc.d.ts +2 -2
- package/dist/doc.js +10 -46
- package/dist/enumeration.cjs +43 -84
- package/dist/enumeration.d.ts +4 -4
- package/dist/enumeration.js +17 -44
- package/dist/hydrate.cjs +13 -24
- package/dist/hydrate.js +0 -4
- package/dist/index.cjs +81 -121
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -76
- package/dist/literal.cjs +30 -69
- package/dist/literal.d.ts +1 -1
- package/dist/literal.js +5 -30
- package/dist/number.cjs +52 -101
- package/dist/number.d.ts +6 -6
- package/dist/number.js +27 -63
- package/dist/object.cjs +33 -85
- package/dist/object.d.ts +1 -1
- package/dist/object.js +8 -47
- package/dist/operation.cjs +64 -142
- package/dist/operation.d.ts +6 -6
- package/dist/operation.js +26 -96
- package/dist/or.cjs +37 -85
- package/dist/or.d.ts +1 -1
- package/dist/or.js +10 -45
- package/dist/schema.cjs +71 -173
- package/dist/schema.d.ts +7 -7
- package/dist/schema.js +27 -123
- package/dist/schemaFactory.cjs +40 -85
- package/dist/schemaFactory.d.ts +6 -6
- package/dist/schemaFactory.js +5 -38
- package/dist/schemaModule.cjs +81 -147
- package/dist/schemaModule.d.ts +1 -1
- package/dist/schemaModule.js +52 -106
- package/dist/string.cjs +55 -104
- package/dist/string.d.ts +6 -6
- package/dist/string.js +30 -66
- package/dist/tuple.cjs +31 -78
- package/dist/tuple.d.ts +1 -1
- package/dist/tuple.js +6 -40
- package/dist/typeGuards.cjs +44 -121
- package/dist/typeGuards.d.ts +7 -7
- package/dist/typeGuards.js +7 -80
- package/dist/types.cjs +13 -24
- package/dist/types.d.ts +7 -7
- package/dist/types.js +0 -4
- package/dist/union.cjs +26 -46
- package/dist/union.d.ts +1 -1
- package/dist/union.js +0 -6
- package/package.json +26 -33
- package/PROMPT.md +0 -21
- package/SCHEMA.md +0 -13
- package/dist/mini/SchemaValidationError.cjs +0 -1
- package/dist/mini/SchemaValidationError.d.ts +0 -20
- package/dist/mini/SchemaValidationError.js +0 -1
- package/dist/mini/after.cjs +0 -1
- package/dist/mini/after.d.ts +0 -30
- package/dist/mini/after.js +0 -1
- package/dist/mini/and.cjs +0 -1
- package/dist/mini/and.d.ts +0 -37
- package/dist/mini/and.js +0 -1
- package/dist/mini/api.cjs +0 -1
- package/dist/mini/api.d.ts +0 -107
- package/dist/mini/api.js +0 -1
- package/dist/mini/array.cjs +0 -1
- package/dist/mini/array.d.ts +0 -25
- package/dist/mini/array.js +0 -1
- package/dist/mini/before.cjs +0 -1
- package/dist/mini/before.d.ts +0 -30
- package/dist/mini/before.js +0 -1
- package/dist/mini/binary.cjs +0 -1
- package/dist/mini/binary.d.ts +0 -24
- package/dist/mini/binary.js +0 -1
- package/dist/mini/boolean.cjs +0 -1
- package/dist/mini/boolean.d.ts +0 -24
- package/dist/mini/boolean.js +0 -1
- package/dist/mini/combinatorName.cjs +0 -1
- package/dist/mini/combinatorName.d.ts +0 -8
- package/dist/mini/combinatorName.js +0 -1
- package/dist/mini/context.cjs +0 -1
- package/dist/mini/context.d.ts +0 -101
- package/dist/mini/context.js +0 -1
- package/dist/mini/date.cjs +0 -1
- package/dist/mini/date.d.ts +0 -24
- package/dist/mini/date.js +0 -1
- package/dist/mini/doc.cjs +0 -1
- package/dist/mini/doc.d.ts +0 -25
- package/dist/mini/doc.js +0 -1
- package/dist/mini/enumeration.cjs +0 -1
- package/dist/mini/enumeration.d.ts +0 -50
- package/dist/mini/enumeration.js +0 -1
- package/dist/mini/hydrate.cjs +0 -1
- package/dist/mini/hydrate.d.ts +0 -1
- package/dist/mini/hydrate.js +0 -0
- package/dist/mini/index.cjs +0 -1
- package/dist/mini/index.d.ts +0 -34
- package/dist/mini/index.js +0 -1
- package/dist/mini/literal.cjs +0 -1
- package/dist/mini/literal.d.ts +0 -25
- package/dist/mini/literal.js +0 -1
- package/dist/mini/number.cjs +0 -1
- package/dist/mini/number.d.ts +0 -84
- package/dist/mini/number.js +0 -1
- package/dist/mini/object.cjs +0 -1
- package/dist/mini/object.d.ts +0 -37
- package/dist/mini/object.js +0 -1
- package/dist/mini/operation.cjs +0 -1
- package/dist/mini/operation.d.ts +0 -197
- package/dist/mini/operation.js +0 -1
- package/dist/mini/or.cjs +0 -1
- package/dist/mini/or.d.ts +0 -36
- package/dist/mini/or.js +0 -1
- package/dist/mini/schema.cjs +0 -1
- package/dist/mini/schema.d.ts +0 -132
- package/dist/mini/schema.js +0 -1
- package/dist/mini/schemaFactory.cjs +0 -1
- package/dist/mini/schemaFactory.d.ts +0 -97
- package/dist/mini/schemaFactory.js +0 -1
- package/dist/mini/schemaModule.cjs +0 -1
- package/dist/mini/schemaModule.d.ts +0 -80
- package/dist/mini/schemaModule.js +0 -1
- package/dist/mini/string.cjs +0 -1
- package/dist/mini/string.d.ts +0 -85
- package/dist/mini/string.js +0 -1
- package/dist/mini/tuple.cjs +0 -1
- package/dist/mini/tuple.d.ts +0 -33
- package/dist/mini/tuple.js +0 -1
- package/dist/mini/typeGuards.cjs +0 -1
- package/dist/mini/typeGuards.d.ts +0 -93
- package/dist/mini/typeGuards.js +0 -1
- package/dist/mini/types.cjs +0 -1
- package/dist/mini/types.d.ts +0 -293
- package/dist/mini/types.js +0 -0
- package/dist/mini/union.cjs +0 -1
- package/dist/mini/union.d.ts +0 -30
- package/dist/mini/union.js +0 -1
- /package/{LICENCE.md → LICENSE.md} +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
<!-- Generated from website/docs/packages/*.md. Do not edit directly. -->
|
|
2
|
+
|
|
1
3
|
# @livon/schema
|
|
2
4
|
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@livon/schema)
|
|
7
|
+
[](https://libraries.io/npm/%40livon%2Fschema)
|
|
8
|
+
[](https://github.com/live-input-vector-output-node/livon-ts/actions/workflows/code-quality.yml)
|
|
9
|
+
[](https://www.npmjs.com/package/@livon/schema)
|
|
10
|
+
[](https://github.com/live-input-vector-output-node/livon-ts)
|
|
11
|
+
|
|
3
12
|
## Install
|
|
4
13
|
|
|
5
14
|
```sh
|
|
@@ -8,48 +17,52 @@ pnpm add @livon/schema
|
|
|
8
17
|
|
|
9
18
|
## Purpose
|
|
10
19
|
|
|
11
|
-
[@livon/schema](https://
|
|
20
|
+
[@livon/schema](https://livon.tech/docs/packages/schema) defines:
|
|
12
21
|
|
|
13
|
-
- [value schemas](https://
|
|
22
|
+
- [value schemas](https://livon.tech/docs/schema) (`string`, `number`, `object`, `array`, `or`, `union`, ...)
|
|
14
23
|
- operation schemas
|
|
15
24
|
- subscription schemas
|
|
16
|
-
- [schema
|
|
25
|
+
- [schema module](https://livon.tech/docs/technical/runtime-design) (`schemaModule`)
|
|
26
|
+
|
|
27
|
+
## Best for
|
|
28
|
+
|
|
29
|
+
Use this package when you want a single schema source for validation, typing, and generated client APIs.
|
|
17
30
|
|
|
18
31
|
## Schema API docs
|
|
19
32
|
|
|
20
33
|
Each schema/combinator has its own usage page:
|
|
21
34
|
|
|
22
|
-
- [Schema APIs overview](https://
|
|
23
|
-
- [Schema Type Safety](https://
|
|
24
|
-
- [Schema Context](https://
|
|
25
|
-
- [string](https://
|
|
26
|
-
- [number](https://
|
|
27
|
-
- [boolean](https://
|
|
28
|
-
- [date](https://
|
|
29
|
-
- [enumeration](https://
|
|
30
|
-
- [object](https://
|
|
31
|
-
- [array](https://
|
|
32
|
-
- [tuple](https://
|
|
33
|
-
- [literal](https://
|
|
34
|
-
- [union](https://
|
|
35
|
-
- [or](https://
|
|
36
|
-
- [binary](https://
|
|
37
|
-
- [before](https://
|
|
38
|
-
- [after](https://
|
|
39
|
-
- [and](https://
|
|
40
|
-
- [api](https://
|
|
41
|
-
- [operation](https://
|
|
42
|
-
- [subscription](https://
|
|
43
|
-
- [fieldResolver](https://
|
|
44
|
-
- [schemaFactory](https://
|
|
45
|
-
- [typeGuards](https://
|
|
35
|
+
- [Schema APIs overview](https://livon.tech/docs/schema)
|
|
36
|
+
- [Schema Type Safety](https://livon.tech/docs/schema/type-safety)
|
|
37
|
+
- [Schema Context](https://livon.tech/docs/schema/context)
|
|
38
|
+
- [string](https://livon.tech/docs/schema/string)
|
|
39
|
+
- [number](https://livon.tech/docs/schema/number)
|
|
40
|
+
- [boolean](https://livon.tech/docs/schema/boolean)
|
|
41
|
+
- [date](https://livon.tech/docs/schema/date)
|
|
42
|
+
- [enumeration](https://livon.tech/docs/schema/enumeration)
|
|
43
|
+
- [object](https://livon.tech/docs/schema/object)
|
|
44
|
+
- [array](https://livon.tech/docs/schema/array)
|
|
45
|
+
- [tuple](https://livon.tech/docs/schema/tuple)
|
|
46
|
+
- [literal](https://livon.tech/docs/schema/literal)
|
|
47
|
+
- [union](https://livon.tech/docs/schema/union)
|
|
48
|
+
- [or](https://livon.tech/docs/schema/or)
|
|
49
|
+
- [binary](https://livon.tech/docs/schema/binary)
|
|
50
|
+
- [before](https://livon.tech/docs/schema/before)
|
|
51
|
+
- [after](https://livon.tech/docs/schema/after)
|
|
52
|
+
- [and](https://livon.tech/docs/schema/and)
|
|
53
|
+
- [api](https://livon.tech/docs/schema/api)
|
|
54
|
+
- [operation](https://livon.tech/docs/schema/operation)
|
|
55
|
+
- [subscription](https://livon.tech/docs/schema/subscription)
|
|
56
|
+
- [fieldResolver](https://livon.tech/docs/schema/field-resolver)
|
|
57
|
+
- [schemaFactory](https://livon.tech/docs/schema/schema-factory)
|
|
58
|
+
- [typeGuards](https://livon.tech/docs/schema/type-guards)
|
|
46
59
|
|
|
47
60
|
## Type safety model
|
|
48
61
|
|
|
49
|
-
LIVON [schemas](https://
|
|
62
|
+
LIVON [schemas](https://livon.tech/docs/schema) are both runtime validators and type sources.
|
|
50
63
|
Primitive schema names are optional, so `string()` and `number()` are valid defaults.
|
|
51
64
|
|
|
52
|
-
1. Define payload shape once in [schema](https://
|
|
65
|
+
1. Define payload shape once in [schema](https://livon.tech/docs/schema).
|
|
53
66
|
2. Validate unknown input with `parse()`.
|
|
54
67
|
3. Reuse schema entrypoint with `typed()`.
|
|
55
68
|
4. Derive types with `Infer` instead of hand-written payload interfaces.
|
|
@@ -97,7 +110,7 @@ const typed = User.typed(typedInput);
|
|
|
97
110
|
```ts
|
|
98
111
|
import {api} from '@livon/schema';
|
|
99
112
|
|
|
100
|
-
const
|
|
113
|
+
const ApiSchema = api({
|
|
101
114
|
type: User,
|
|
102
115
|
operations: {
|
|
103
116
|
sendMessage,
|
|
@@ -110,9 +123,12 @@ const apiSchema = api({
|
|
|
110
123
|
},
|
|
111
124
|
});
|
|
112
125
|
|
|
113
|
-
export const serverSchema =
|
|
126
|
+
export const serverSchema = ApiSchema;
|
|
114
127
|
```
|
|
115
128
|
|
|
129
|
+
Use the `api(...)` (or `composeApi(...)`) result directly in `schemaModule(...)`.
|
|
130
|
+
No additional schema-module input factory is required.
|
|
131
|
+
|
|
116
132
|
### Parameters in this example
|
|
117
133
|
|
|
118
134
|
`api({...})`:
|
|
@@ -124,10 +140,10 @@ export const serverSchema = apiSchema;
|
|
|
124
140
|
|
|
125
141
|
For focused usage patterns:
|
|
126
142
|
|
|
127
|
-
- [api](https://
|
|
128
|
-
- [operation](https://
|
|
129
|
-
- [subscription](https://
|
|
130
|
-
- [fieldResolver](https://
|
|
143
|
+
- [api](https://livon.tech/docs/schema/api)
|
|
144
|
+
- [operation](https://livon.tech/docs/schema/operation)
|
|
145
|
+
- [subscription](https://livon.tech/docs/schema/subscription)
|
|
146
|
+
- [fieldResolver](https://livon.tech/docs/schema/field-resolver)
|
|
131
147
|
|
|
132
148
|
## Mount schema module into runtime
|
|
133
149
|
|
|
@@ -147,12 +163,12 @@ runtime(schemaModule(serverSchema, {explain: true}));
|
|
|
147
163
|
|
|
148
164
|
## Explain endpoint
|
|
149
165
|
|
|
150
|
-
If `explain: true`, [schema module](https://
|
|
166
|
+
If `explain: true`, [schema module](https://livon.tech/docs/technical/runtime-design) responds to `$explain` with AST/checksum metadata.
|
|
151
167
|
|
|
152
168
|
## Related pages
|
|
153
169
|
|
|
154
|
-
- [Validated by Default](https://
|
|
155
|
-
- [parse vs typed](https://
|
|
156
|
-
- [Schema APIs overview](https://
|
|
157
|
-
- [Runtime Design](https://
|
|
158
|
-
- [Architecture](https://
|
|
170
|
+
- [Validated by Default](https://livon.tech/docs/core/validated-by-default)
|
|
171
|
+
- [parse vs typed](https://livon.tech/docs/core/parse-vs-typed)
|
|
172
|
+
- [Schema APIs overview](https://livon.tech/docs/schema)
|
|
173
|
+
- [Runtime Design](https://livon.tech/docs/technical/runtime-design)
|
|
174
|
+
- [Architecture](https://livon.tech/docs/technical/architecture)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Third-Party Notices
|
|
2
|
+
|
|
3
|
+
This package includes third-party software. The following licenses apply:
|
|
4
|
+
|
|
5
|
+
------------------------------------------------------------------------------
|
|
6
|
+
msgpackr
|
|
7
|
+
------------------------------------------------------------------------------
|
|
8
|
+
License: MIT
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2020 Kris Zyp
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
@@ -1,64 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
-
return typeof document === 'undefined'
|
|
4
|
-
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
-
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
-
new URL('main.js', document.baseURI).href;
|
|
7
|
-
})();
|
|
8
|
-
;
|
|
9
|
-
// The require scope
|
|
10
2
|
var __webpack_require__ = {};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
21
10
|
})();
|
|
22
|
-
|
|
23
|
-
(
|
|
24
|
-
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
13
|
})();
|
|
26
|
-
|
|
27
|
-
(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
35
23
|
})();
|
|
36
24
|
var __webpack_exports__ = {};
|
|
37
25
|
__webpack_require__.r(__webpack_exports__);
|
|
38
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
39
|
-
|
|
27
|
+
createSchemaValidationError: ()=>createSchemaValidationError
|
|
40
28
|
});
|
|
41
|
-
|
|
42
|
-
* createSchemaValidationError is part of the public LIVON API.
|
|
43
|
-
*
|
|
44
|
-
* @remarks
|
|
45
|
-
* Parameter and return types are defined in the TypeScript signature.
|
|
46
|
-
*
|
|
47
|
-
* @see https://live-input-vector-output-node.github.io/livon-ts/docs/schema/type-safety
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* const result = createSchemaValidationError(undefined as never);
|
|
51
|
-
*/ const createSchemaValidationError = ({ issues, meta })=>{
|
|
29
|
+
const createSchemaValidationError = ({ issues, meta })=>{
|
|
52
30
|
const error = new Error('Schema validation failed');
|
|
53
31
|
error.issues = issues;
|
|
54
32
|
error.meta = meta;
|
|
55
33
|
return error;
|
|
56
34
|
};
|
|
57
|
-
|
|
58
35
|
exports.createSchemaValidationError = __webpack_exports__.createSchemaValidationError;
|
|
59
|
-
for(var __rspack_i in __webpack_exports__)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
36
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
37
|
+
"createSchemaValidationError"
|
|
38
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
39
|
+
Object.defineProperty(exports, '__esModule', {
|
|
40
|
+
value: true
|
|
41
|
+
});
|
|
@@ -9,7 +9,7 @@ export type SchemaValidationError = Error & {
|
|
|
9
9
|
* @remarks
|
|
10
10
|
* Parameter and return types are defined in the TypeScript signature.
|
|
11
11
|
*
|
|
12
|
-
* @see https://
|
|
12
|
+
* @see https://livon.tech/docs/schema/type-safety
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* const result = createSchemaValidationError(undefined as never);
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
;// CONCATENATED MODULE: ./src/SchemaValidationError.ts
|
|
3
|
-
/**
|
|
4
|
-
* createSchemaValidationError is part of the public LIVON API.
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Parameter and return types are defined in the TypeScript signature.
|
|
8
|
-
*
|
|
9
|
-
* @see https://live-input-vector-output-node.github.io/livon-ts/docs/schema/type-safety
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const result = createSchemaValidationError(undefined as never);
|
|
13
|
-
*/ const createSchemaValidationError = ({ issues, meta })=>{
|
|
1
|
+
const createSchemaValidationError = ({ issues, meta })=>{
|
|
14
2
|
const error = new Error('Schema validation failed');
|
|
15
3
|
error.issues = issues;
|
|
16
4
|
error.meta = meta;
|
|
17
5
|
return error;
|
|
18
6
|
};
|
|
19
|
-
|
|
20
7
|
export { createSchemaValidationError };
|
package/dist/after.cjs
CHANGED
|
@@ -1,72 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
-
return typeof document === 'undefined'
|
|
4
|
-
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
-
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
-
new URL('main.js', document.baseURI).href;
|
|
7
|
-
})();
|
|
8
|
-
;
|
|
9
|
-
// The require scope
|
|
10
2
|
var __webpack_require__ = {};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
21
10
|
})();
|
|
22
|
-
|
|
23
|
-
(
|
|
24
|
-
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
13
|
})();
|
|
26
|
-
|
|
27
|
-
(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
35
23
|
})();
|
|
36
24
|
var __webpack_exports__ = {};
|
|
37
25
|
__webpack_require__.r(__webpack_exports__);
|
|
38
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
39
|
-
|
|
27
|
+
after: ()=>after
|
|
40
28
|
});
|
|
41
|
-
|
|
42
|
-
* after is part of the public LIVON API.
|
|
43
|
-
*
|
|
44
|
-
* @remarks
|
|
45
|
-
* Parameter and return types are defined in the TypeScript signature.
|
|
46
|
-
*
|
|
47
|
-
* @see https://live-input-vector-output-node.github.io/livon-ts/docs/schema/after
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* // Postprocesses validated string output by converting it to uppercase.
|
|
51
|
-
* const UppercaseName = after({
|
|
52
|
-
* schema: string(),
|
|
53
|
-
* hook: (value: string) => value.toUpperCase(),
|
|
54
|
-
* });
|
|
55
|
-
* UppercaseName.parse('alice');
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* // Extends the postprocessed schema to also allow undefined.
|
|
59
|
-
* const MaybeUppercaseName = after({
|
|
60
|
-
* schema: string(),
|
|
61
|
-
* hook: (value: string) => value.toUpperCase(),
|
|
62
|
-
* }).optional();
|
|
63
|
-
* MaybeUppercaseName.parse(undefined);
|
|
64
|
-
*/ const after = ({ schema, hook })=>schema.after(hook);
|
|
65
|
-
|
|
29
|
+
const after = ({ schema, hook })=>schema.after(hook);
|
|
66
30
|
exports.after = __webpack_exports__.after;
|
|
67
|
-
for(var __rspack_i in __webpack_exports__)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
31
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
32
|
+
"after"
|
|
33
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
34
|
+
Object.defineProperty(exports, '__esModule', {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
package/dist/after.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface AfterInput<T> {
|
|
|
9
9
|
* @remarks
|
|
10
10
|
* Parameter and return types are defined in the TypeScript signature.
|
|
11
11
|
*
|
|
12
|
-
* @see https://
|
|
12
|
+
* @see https://livon.tech/docs/schema/after
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* // Postprocesses validated string output by converting it to uppercase.
|
package/dist/after.js
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
;// CONCATENATED MODULE: ./src/after.ts
|
|
3
|
-
/**
|
|
4
|
-
* after is part of the public LIVON API.
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Parameter and return types are defined in the TypeScript signature.
|
|
8
|
-
*
|
|
9
|
-
* @see https://live-input-vector-output-node.github.io/livon-ts/docs/schema/after
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* // Postprocesses validated string output by converting it to uppercase.
|
|
13
|
-
* const UppercaseName = after({
|
|
14
|
-
* schema: string(),
|
|
15
|
-
* hook: (value: string) => value.toUpperCase(),
|
|
16
|
-
* });
|
|
17
|
-
* UppercaseName.parse('alice');
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // Extends the postprocessed schema to also allow undefined.
|
|
21
|
-
* const MaybeUppercaseName = after({
|
|
22
|
-
* schema: string(),
|
|
23
|
-
* hook: (value: string) => value.toUpperCase(),
|
|
24
|
-
* }).optional();
|
|
25
|
-
* MaybeUppercaseName.parse(undefined);
|
|
26
|
-
*/ const after = ({ schema, hook })=>schema.after(hook);
|
|
27
|
-
|
|
1
|
+
const after = ({ schema, hook })=>schema.after(hook);
|
|
28
2
|
export { after };
|
package/dist/and.cjs
CHANGED
|
@@ -1,80 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
-
return typeof document === 'undefined'
|
|
4
|
-
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
-
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
-
new URL('main.js', document.baseURI).href;
|
|
7
|
-
})();
|
|
8
|
-
;
|
|
9
|
-
// The require scope
|
|
10
2
|
var __webpack_require__ = {};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
21
10
|
})();
|
|
22
|
-
|
|
23
|
-
(
|
|
24
|
-
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
13
|
})();
|
|
26
|
-
|
|
27
|
-
(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
35
23
|
})();
|
|
36
24
|
var __webpack_exports__ = {};
|
|
37
25
|
__webpack_require__.r(__webpack_exports__);
|
|
38
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
39
|
-
|
|
27
|
+
and: ()=>and
|
|
40
28
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* @example
|
|
63
|
-
* // Uses explicit naming for generated type surfaces.
|
|
64
|
-
* const MessageWithId = and({
|
|
65
|
-
* left: messageInput,
|
|
66
|
-
* right: withId,
|
|
67
|
-
* name: 'MessageWithId',
|
|
68
|
-
* });
|
|
69
|
-
* MessageWithId.parse({ text: 'Hello', id: 'm-1' });
|
|
70
|
-
*/ const and = ({ left, right, name })=>name === undefined ? left.and(right) : left.and(right, {
|
|
71
|
-
name
|
|
29
|
+
const isLegacyInput = (input)=>'left' in input && 'right' in input;
|
|
30
|
+
function and(input) {
|
|
31
|
+
if (isLegacyInput(input)) {
|
|
32
|
+
const { left, right, name } = input;
|
|
33
|
+
return void 0 === name ? left.and(right) : left.and(right, {
|
|
34
|
+
name
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const { schemas, name } = input;
|
|
38
|
+
if (schemas.length < 2) throw new Error('and() requires at least 2 schemas in the schemas array');
|
|
39
|
+
const [first, ...rest] = schemas;
|
|
40
|
+
const initial = first;
|
|
41
|
+
const lastIndex = rest.length - 1;
|
|
42
|
+
const reduced = rest.reduce((state, schema)=>({
|
|
43
|
+
schema: void 0 !== name && state.index === lastIndex ? state.schema.and(schema, {
|
|
44
|
+
name
|
|
45
|
+
}) : state.schema.and(schema),
|
|
46
|
+
index: state.index + 1
|
|
47
|
+
}), {
|
|
48
|
+
schema: initial,
|
|
49
|
+
index: 0
|
|
72
50
|
});
|
|
73
|
-
|
|
74
|
-
exports.and = __webpack_exports__.and;
|
|
75
|
-
for(var __rspack_i in __webpack_exports__) {
|
|
76
|
-
if(["and"].indexOf(__rspack_i) === -1) {
|
|
77
|
-
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
78
|
-
}
|
|
51
|
+
return reduced.schema;
|
|
79
52
|
}
|
|
80
|
-
|
|
53
|
+
exports.and = __webpack_exports__.and;
|
|
54
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
55
|
+
"and"
|
|
56
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
57
|
+
Object.defineProperty(exports, '__esModule', {
|
|
58
|
+
value: true
|
|
59
|
+
});
|
package/dist/and.d.ts
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { Schema } from './types.js';
|
|
2
|
-
|
|
2
|
+
type InferSchemasTuple<T extends readonly Schema<unknown>[]> = {
|
|
3
|
+
[K in keyof T]: T[K] extends Schema<infer U> ? U : never;
|
|
4
|
+
};
|
|
5
|
+
type IntersectTuple<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Tail] ? Head & IntersectTuple<Tail> : unknown;
|
|
6
|
+
export interface AndSchemaInput<TSchemas extends readonly Schema<unknown>[]> {
|
|
7
|
+
name?: string;
|
|
8
|
+
schemas: TSchemas;
|
|
9
|
+
}
|
|
10
|
+
export interface AndLegacyInput<T, U> {
|
|
3
11
|
left: Schema<T>;
|
|
4
12
|
right: Schema<U>;
|
|
5
13
|
name?: string;
|
|
6
14
|
}
|
|
15
|
+
type VariadicSchemaTuple = readonly [Schema<any>, Schema<any>, ...Schema<any>[]];
|
|
7
16
|
/**
|
|
8
17
|
* and is part of the public LIVON API.
|
|
9
18
|
*
|
|
10
19
|
* @remarks
|
|
11
20
|
* Parameter and return types are defined in the TypeScript signature.
|
|
12
21
|
*
|
|
13
|
-
* @see https://
|
|
22
|
+
* @see https://livon.tech/docs/schema/and
|
|
14
23
|
*
|
|
15
24
|
* @example
|
|
16
|
-
* // Extends a base message input schema with an id field.
|
|
25
|
+
* // Extends a base message input schema with an id field (legacy API).
|
|
17
26
|
* const messageInput = object({
|
|
18
27
|
* name: 'MessageInput',
|
|
19
28
|
* shape: { text: string() },
|
|
@@ -26,12 +35,29 @@ export interface AndInput<T, U> {
|
|
|
26
35
|
* MessageWithId.parse({ text: 'Hello', id: 'm-1' });
|
|
27
36
|
*
|
|
28
37
|
* @example
|
|
29
|
-
* // Uses explicit naming for generated type surfaces.
|
|
38
|
+
* // Uses explicit naming for generated type surfaces (legacy API).
|
|
30
39
|
* const MessageWithId = and({
|
|
31
40
|
* left: messageInput,
|
|
32
41
|
* right: withId,
|
|
33
42
|
* name: 'MessageWithId',
|
|
34
43
|
* });
|
|
35
44
|
* MessageWithId.parse({ text: 'Hello', id: 'm-1' });
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // Composes multiple schemas using the schemas array (new API).
|
|
48
|
+
* const MessageWithId = and({
|
|
49
|
+
* name: 'MessageWithId',
|
|
50
|
+
* schemas: [messageInput, withId],
|
|
51
|
+
* });
|
|
52
|
+
* MessageWithId.parse({ text: 'Hello', id: 'm-1' });
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Composes three schemas using the schemas array.
|
|
56
|
+
* const MessageComplete = and({
|
|
57
|
+
* schemas: [messageInput, withId, withTimestamp],
|
|
58
|
+
* });
|
|
59
|
+
* MessageComplete.parse({ text: 'Hello', id: 'm-1', timestamp: Date.now() });
|
|
36
60
|
*/
|
|
37
|
-
export declare
|
|
61
|
+
export declare function and<TSchemas extends VariadicSchemaTuple>(input: AndSchemaInput<TSchemas>): Schema<IntersectTuple<InferSchemasTuple<TSchemas>>>;
|
|
62
|
+
export declare function and<T, U>(input: AndLegacyInput<T, U>): Schema<T & U>;
|
|
63
|
+
export {};
|