@livon/schema 0.27.0-rc.1

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.
Files changed (169) hide show
  1. package/PROMPT.md +21 -0
  2. package/README.md +13 -0
  3. package/SCHEMA.md +13 -0
  4. package/dist/SchemaValidationError.cjs +41 -0
  5. package/dist/SchemaValidationError.d.ts +20 -0
  6. package/dist/SchemaValidationError.js +7 -0
  7. package/dist/SchemaValidationError.spec.cjs +65 -0
  8. package/dist/SchemaValidationError.spec.d.ts +1 -0
  9. package/dist/SchemaValidationError.spec.js +59 -0
  10. package/dist/after.cjs +36 -0
  11. package/dist/after.d.ts +30 -0
  12. package/dist/after.js +2 -0
  13. package/dist/after.spec.cjs +54 -0
  14. package/dist/after.spec.d.ts +1 -0
  15. package/dist/after.spec.js +48 -0
  16. package/dist/and.cjs +36 -0
  17. package/dist/and.d.ts +26 -0
  18. package/dist/and.js +2 -0
  19. package/dist/and.spec.cjs +57 -0
  20. package/dist/and.spec.d.ts +1 -0
  21. package/dist/and.spec.js +51 -0
  22. package/dist/api.cjs +317 -0
  23. package/dist/api.d.ts +107 -0
  24. package/dist/api.js +277 -0
  25. package/dist/api.spec.cjs +512 -0
  26. package/dist/api.spec.d.ts +1 -0
  27. package/dist/api.spec.js +506 -0
  28. package/dist/array.cjs +74 -0
  29. package/dist/array.d.ts +25 -0
  30. package/dist/array.js +40 -0
  31. package/dist/array.spec.cjs +167 -0
  32. package/dist/array.spec.d.ts +1 -0
  33. package/dist/array.spec.js +161 -0
  34. package/dist/before.cjs +36 -0
  35. package/dist/before.d.ts +30 -0
  36. package/dist/before.js +2 -0
  37. package/dist/before.spec.cjs +54 -0
  38. package/dist/before.spec.d.ts +1 -0
  39. package/dist/before.spec.js +48 -0
  40. package/dist/binary.cjs +53 -0
  41. package/dist/binary.d.ts +24 -0
  42. package/dist/binary.js +19 -0
  43. package/dist/binary.spec.cjs +107 -0
  44. package/dist/binary.spec.d.ts +1 -0
  45. package/dist/binary.spec.js +101 -0
  46. package/dist/boolean.cjs +53 -0
  47. package/dist/boolean.d.ts +24 -0
  48. package/dist/boolean.js +19 -0
  49. package/dist/boolean.spec.cjs +96 -0
  50. package/dist/boolean.spec.d.ts +1 -0
  51. package/dist/boolean.spec.js +90 -0
  52. package/dist/context.cjs +125 -0
  53. package/dist/context.d.ts +101 -0
  54. package/dist/context.js +76 -0
  55. package/dist/context.spec.cjs +244 -0
  56. package/dist/context.spec.d.ts +1 -0
  57. package/dist/context.spec.js +238 -0
  58. package/dist/date.cjs +53 -0
  59. package/dist/date.d.ts +24 -0
  60. package/dist/date.js +19 -0
  61. package/dist/date.spec.cjs +97 -0
  62. package/dist/date.spec.d.ts +1 -0
  63. package/dist/date.spec.js +91 -0
  64. package/dist/doc.cjs +54 -0
  65. package/dist/doc.d.ts +25 -0
  66. package/dist/doc.js +17 -0
  67. package/dist/doc.spec.cjs +99 -0
  68. package/dist/doc.spec.d.ts +1 -0
  69. package/dist/doc.spec.js +93 -0
  70. package/dist/enumeration.cjs +74 -0
  71. package/dist/enumeration.d.ts +50 -0
  72. package/dist/enumeration.js +40 -0
  73. package/dist/enumeration.spec.cjs +110 -0
  74. package/dist/enumeration.spec.d.ts +1 -0
  75. package/dist/enumeration.spec.js +104 -0
  76. package/dist/hydrate.cjs +18 -0
  77. package/dist/hydrate.d.ts +1 -0
  78. package/dist/hydrate.js +0 -0
  79. package/dist/index.cjs +145 -0
  80. package/dist/index.d.ts +34 -0
  81. package/dist/index.js +24 -0
  82. package/dist/index.spec.cjs +43 -0
  83. package/dist/index.spec.d.ts +1 -0
  84. package/dist/index.spec.js +37 -0
  85. package/dist/literal.cjs +55 -0
  86. package/dist/literal.d.ts +25 -0
  87. package/dist/literal.js +21 -0
  88. package/dist/literal.spec.cjs +93 -0
  89. package/dist/literal.spec.d.ts +1 -0
  90. package/dist/literal.spec.js +87 -0
  91. package/dist/number.cjs +89 -0
  92. package/dist/number.d.ts +84 -0
  93. package/dist/number.js +55 -0
  94. package/dist/number.spec.cjs +155 -0
  95. package/dist/number.spec.d.ts +1 -0
  96. package/dist/number.spec.js +149 -0
  97. package/dist/object.cjs +66 -0
  98. package/dist/object.d.ts +37 -0
  99. package/dist/object.js +32 -0
  100. package/dist/object.spec.cjs +171 -0
  101. package/dist/object.spec.d.ts +1 -0
  102. package/dist/object.spec.js +165 -0
  103. package/dist/operation.cjs +182 -0
  104. package/dist/operation.d.ts +197 -0
  105. package/dist/operation.js +133 -0
  106. package/dist/operation.spec.cjs +454 -0
  107. package/dist/operation.spec.d.ts +1 -0
  108. package/dist/operation.spec.js +448 -0
  109. package/dist/or.cjs +85 -0
  110. package/dist/or.d.ts +37 -0
  111. package/dist/or.js +51 -0
  112. package/dist/or.spec.cjs +204 -0
  113. package/dist/or.spec.d.ts +1 -0
  114. package/dist/or.spec.js +198 -0
  115. package/dist/schema.cjs +285 -0
  116. package/dist/schema.d.ts +132 -0
  117. package/dist/schema.js +233 -0
  118. package/dist/schema.spec.cjs +587 -0
  119. package/dist/schema.spec.d.ts +1 -0
  120. package/dist/schema.spec.js +581 -0
  121. package/dist/schemaFactory.cjs +125 -0
  122. package/dist/schemaFactory.d.ts +97 -0
  123. package/dist/schemaFactory.js +88 -0
  124. package/dist/schemaFactory.spec.cjs +197 -0
  125. package/dist/schemaFactory.spec.d.ts +1 -0
  126. package/dist/schemaFactory.spec.js +191 -0
  127. package/dist/schemaModule.cjs +280 -0
  128. package/dist/schemaModule.d.ts +97 -0
  129. package/dist/schemaModule.js +243 -0
  130. package/dist/schemaModule.spec.cjs +355 -0
  131. package/dist/schemaModule.spec.d.ts +1 -0
  132. package/dist/schemaModule.spec.js +349 -0
  133. package/dist/string.cjs +93 -0
  134. package/dist/string.d.ts +85 -0
  135. package/dist/string.js +59 -0
  136. package/dist/string.spec.cjs +158 -0
  137. package/dist/string.spec.d.ts +1 -0
  138. package/dist/string.spec.js +152 -0
  139. package/dist/testing/mocks/assertions.mock.cjs +48 -0
  140. package/dist/testing/mocks/assertions.mock.d.ts +5 -0
  141. package/dist/testing/mocks/assertions.mock.js +14 -0
  142. package/dist/testing/mocks/index.cjs +52 -0
  143. package/dist/testing/mocks/index.d.ts +4 -0
  144. package/dist/testing/mocks/index.js +3 -0
  145. package/dist/testing/mocks/schema.mock.cjs +120 -0
  146. package/dist/testing/mocks/schema.mock.d.ts +37 -0
  147. package/dist/testing/mocks/schema.mock.js +74 -0
  148. package/dist/tuple.cjs +58 -0
  149. package/dist/tuple.d.ts +33 -0
  150. package/dist/tuple.js +24 -0
  151. package/dist/tuple.spec.cjs +162 -0
  152. package/dist/tuple.spec.d.ts +1 -0
  153. package/dist/tuple.spec.js +156 -0
  154. package/dist/typeGuards.cjs +60 -0
  155. package/dist/typeGuards.d.ts +93 -0
  156. package/dist/typeGuards.js +8 -0
  157. package/dist/typeGuards.spec.cjs +101 -0
  158. package/dist/typeGuards.spec.d.ts +1 -0
  159. package/dist/typeGuards.spec.js +95 -0
  160. package/dist/types.cjs +18 -0
  161. package/dist/types.d.ts +289 -0
  162. package/dist/types.js +0 -0
  163. package/dist/union.cjs +74 -0
  164. package/dist/union.d.ts +33 -0
  165. package/dist/union.js +40 -0
  166. package/dist/union.spec.cjs +159 -0
  167. package/dist/union.spec.d.ts +1 -0
  168. package/dist/union.spec.js +153 -0
  169. package/package.json +47 -0
package/PROMPT.md ADDED
@@ -0,0 +1,21 @@
1
+ <!-- @agent.entry -->
2
+ <!-- @agent.load: ../../PROMPT.md -->
3
+ <!-- @agent.load: ../../PROMPTS.md -->
4
+ <!-- @agent.load: ../../AGENTS.md -->
5
+ <!-- @agent.load: ../../website/docs/core/testing-and-quality.md -->
6
+ <!-- @agent.load: ../../website/docs/packages/schema.md -->
7
+ <!-- @agent.load: ../../website/docs/schema/index.md -->
8
+ <!-- @agent.load: ../../website/docs/schema/schema-factory.md -->
9
+ <!-- @agent.load: ../../website/docs/schema/type-safety.md -->
10
+
11
+ # @livon/schema Prompt
12
+
13
+ This prompt applies only to the schema package.
14
+
15
+ Canonical sources:
16
+
17
+ - `/docs/packages/schema`
18
+ - `/docs/schema`
19
+ - `/docs/core/testing-and-quality` (test structure, mocking, executable documentation rules)
20
+
21
+ Read the schema docs before making changes in this package.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @livon/schema Redirect
2
+
3
+ Canonical sources moved to Docusaurus:
4
+
5
+ - `/docs/packages/schema`
6
+ - `/docs/schema`
7
+
8
+ File sources:
9
+
10
+ - `website/docs/packages/schema.md`
11
+ - `website/docs/schema/index.md`
12
+
13
+ This file is a compatibility redirect only.
package/SCHEMA.md ADDED
@@ -0,0 +1,13 @@
1
+ # Schema System Redirect
2
+
3
+ Canonical sources moved to Docusaurus:
4
+
5
+ - `/docs/packages/schema`
6
+ - `/docs/schema`
7
+
8
+ File sources:
9
+
10
+ - `website/docs/packages/schema.md`
11
+ - `website/docs/schema/index.md`
12
+
13
+ This file is a compatibility redirect only.
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
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
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
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
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ createSchemaValidationError: ()=>createSchemaValidationError
28
+ });
29
+ const createSchemaValidationError = ({ issues, meta })=>{
30
+ const error = new Error('Schema validation failed');
31
+ error.issues = issues;
32
+ error.meta = meta;
33
+ return error;
34
+ };
35
+ exports.createSchemaValidationError = __webpack_exports__.createSchemaValidationError;
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
+ });
@@ -0,0 +1,20 @@
1
+ import { SchemaIssue, SchemaErrorMeta } from './types.js';
2
+ export type SchemaValidationError = Error & {
3
+ issues: readonly SchemaIssue[];
4
+ meta?: SchemaErrorMeta;
5
+ };
6
+ /**
7
+ * createSchemaValidationError is part of the public LIVON API.
8
+ *
9
+ * @remarks
10
+ * Parameter and return types are defined in the TypeScript signature.
11
+ *
12
+ * @see https://live-input-vector-output-node.github.io/livon-ts/docs/schema/type-safety
13
+ *
14
+ * @example
15
+ * const result = createSchemaValidationError(undefined as never);
16
+ */
17
+ export declare const createSchemaValidationError: ({ issues, meta, }: {
18
+ issues: readonly SchemaIssue[];
19
+ meta?: SchemaErrorMeta;
20
+ }) => SchemaValidationError;
@@ -0,0 +1,7 @@
1
+ const createSchemaValidationError = ({ issues, meta })=>{
2
+ const error = new Error('Schema validation failed');
3
+ error.issues = issues;
4
+ error.meta = meta;
5
+ return error;
6
+ };
7
+ export { createSchemaValidationError };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __webpack_exports__ = {};
3
+ const external_vitest_namespaceObject = require("vitest");
4
+ const external_SchemaValidationError_cjs_namespaceObject = require("./SchemaValidationError.cjs");
5
+ (0, external_vitest_namespaceObject.describe)('createSchemaValidationError()', ()=>{
6
+ let issues;
7
+ let meta;
8
+ (0, external_vitest_namespaceObject.beforeAll)(()=>{
9
+ issues = [];
10
+ meta = {};
11
+ });
12
+ (0, external_vitest_namespaceObject.beforeEach)(()=>{
13
+ issues = [
14
+ {
15
+ path: [
16
+ 'user',
17
+ 'name'
18
+ ],
19
+ message: 'Expected non-empty value',
20
+ code: 'string.min'
21
+ }
22
+ ];
23
+ meta = {
24
+ type: 'string',
25
+ name: 'UserName'
26
+ };
27
+ });
28
+ (0, external_vitest_namespaceObject.afterEach)(()=>{
29
+ issues = [];
30
+ meta = {};
31
+ });
32
+ (0, external_vitest_namespaceObject.afterAll)(()=>{
33
+ issues = [];
34
+ meta = {};
35
+ });
36
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
37
+ (0, external_vitest_namespaceObject.it)('should create error instance when issues are provided', ()=>{
38
+ const error = (0, external_SchemaValidationError_cjs_namespaceObject.createSchemaValidationError)({
39
+ issues
40
+ });
41
+ (0, external_vitest_namespaceObject.expect)(error).toBeInstanceOf(Error);
42
+ (0, external_vitest_namespaceObject.expect)(error.message).toBe('Schema validation failed');
43
+ (0, external_vitest_namespaceObject.expect)(error.issues).toEqual(issues);
44
+ });
45
+ (0, external_vitest_namespaceObject.it)('should attach meta when meta is provided', ()=>{
46
+ const error = (0, external_SchemaValidationError_cjs_namespaceObject.createSchemaValidationError)({
47
+ issues,
48
+ meta
49
+ });
50
+ (0, external_vitest_namespaceObject.expect)(error.meta).toEqual(meta);
51
+ });
52
+ });
53
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
54
+ (0, external_vitest_namespaceObject.it)('should keep meta undefined when meta is omitted', ()=>{
55
+ const error = (0, external_SchemaValidationError_cjs_namespaceObject.createSchemaValidationError)({
56
+ issues
57
+ });
58
+ (0, external_vitest_namespaceObject.expect)(error.meta).toBeUndefined();
59
+ });
60
+ });
61
+ });
62
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
63
+ Object.defineProperty(exports, '__esModule', {
64
+ value: true
65
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
2
+ import { createSchemaValidationError } from "./SchemaValidationError.js";
3
+ describe('createSchemaValidationError()', ()=>{
4
+ let issues;
5
+ let meta;
6
+ beforeAll(()=>{
7
+ issues = [];
8
+ meta = {};
9
+ });
10
+ beforeEach(()=>{
11
+ issues = [
12
+ {
13
+ path: [
14
+ 'user',
15
+ 'name'
16
+ ],
17
+ message: 'Expected non-empty value',
18
+ code: 'string.min'
19
+ }
20
+ ];
21
+ meta = {
22
+ type: 'string',
23
+ name: 'UserName'
24
+ };
25
+ });
26
+ afterEach(()=>{
27
+ issues = [];
28
+ meta = {};
29
+ });
30
+ afterAll(()=>{
31
+ issues = [];
32
+ meta = {};
33
+ });
34
+ describe('happy', ()=>{
35
+ it('should create error instance when issues are provided', ()=>{
36
+ const error = createSchemaValidationError({
37
+ issues
38
+ });
39
+ expect(error).toBeInstanceOf(Error);
40
+ expect(error.message).toBe('Schema validation failed');
41
+ expect(error.issues).toEqual(issues);
42
+ });
43
+ it('should attach meta when meta is provided', ()=>{
44
+ const error = createSchemaValidationError({
45
+ issues,
46
+ meta
47
+ });
48
+ expect(error.meta).toEqual(meta);
49
+ });
50
+ });
51
+ describe('sad', ()=>{
52
+ it('should keep meta undefined when meta is omitted', ()=>{
53
+ const error = createSchemaValidationError({
54
+ issues
55
+ });
56
+ expect(error.meta).toBeUndefined();
57
+ });
58
+ });
59
+ });
package/dist/after.cjs ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
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
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
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
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ after: ()=>after
28
+ });
29
+ const after = ({ schema, hook })=>schema.after(hook);
30
+ exports.after = __webpack_exports__.after;
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
+ });
@@ -0,0 +1,30 @@
1
+ import { Schema } from './types.js';
2
+ export interface AfterInput<T> {
3
+ schema: Schema<T>;
4
+ hook: Parameters<Schema<T>['after']>[0];
5
+ }
6
+ /**
7
+ * after is part of the public LIVON API.
8
+ *
9
+ * @remarks
10
+ * Parameter and return types are defined in the TypeScript signature.
11
+ *
12
+ * @see https://live-input-vector-output-node.github.io/livon-ts/docs/schema/after
13
+ *
14
+ * @example
15
+ * // Postprocesses validated string output by converting it to uppercase.
16
+ * const UppercaseName = after({
17
+ * schema: string(),
18
+ * hook: (value: string) => value.toUpperCase(),
19
+ * });
20
+ * UppercaseName.parse('alice');
21
+ *
22
+ * @example
23
+ * // Extends the postprocessed schema to also allow undefined.
24
+ * const MaybeUppercaseName = after({
25
+ * schema: string(),
26
+ * hook: (value: string) => value.toUpperCase(),
27
+ * }).optional();
28
+ * MaybeUppercaseName.parse(undefined);
29
+ */
30
+ export declare const after: <T>({ schema, hook }: AfterInput<T>) => Schema<unknown>;
package/dist/after.js ADDED
@@ -0,0 +1,2 @@
1
+ const after = ({ schema, hook })=>schema.after(hook);
2
+ export { after };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __webpack_exports__ = {};
3
+ const external_vitest_namespaceObject = require("vitest");
4
+ const external_after_cjs_namespaceObject = require("./after.cjs");
5
+ const index_cjs_namespaceObject = require("./testing/mocks/index.cjs");
6
+ const schemaMock = (0, index_cjs_namespaceObject.createBaseSchemaMock)();
7
+ const nextSchemaMock = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
8
+ name: 'next.after.schema'
9
+ });
10
+ const hookMock = external_vitest_namespaceObject.vi.fn((value)=>value.length);
11
+ (0, external_vitest_namespaceObject.describe)('after()', ()=>{
12
+ (0, external_vitest_namespaceObject.beforeAll)(()=>{
13
+ external_vitest_namespaceObject.vi.mocked(schemaMock.after).mockImplementation(()=>nextSchemaMock);
14
+ });
15
+ (0, external_vitest_namespaceObject.beforeEach)(()=>{
16
+ external_vitest_namespaceObject.vi.mocked(schemaMock.after).mockClear();
17
+ hookMock.mockClear();
18
+ });
19
+ (0, external_vitest_namespaceObject.afterEach)(()=>{
20
+ external_vitest_namespaceObject.vi.mocked(schemaMock.after).mockClear();
21
+ });
22
+ (0, external_vitest_namespaceObject.afterAll)(()=>{
23
+ external_vitest_namespaceObject.vi.mocked(schemaMock.after).mockReset();
24
+ });
25
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
26
+ (0, external_vitest_namespaceObject.it)('should delegate to schema.after when hook is provided', ()=>{
27
+ const result = (0, external_after_cjs_namespaceObject.after)({
28
+ schema: schemaMock,
29
+ hook: hookMock
30
+ });
31
+ (0, external_vitest_namespaceObject.expect)(schemaMock.after).toHaveBeenCalledTimes(1);
32
+ (0, external_vitest_namespaceObject.expect)(schemaMock.after).toHaveBeenCalledWith(hookMock);
33
+ (0, external_vitest_namespaceObject.expect)(result).toBe(nextSchemaMock);
34
+ });
35
+ });
36
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
37
+ (0, external_vitest_namespaceObject.it)('should rethrow error when schema.after throws', ()=>{
38
+ const afterError = new Error('after hook failed');
39
+ external_vitest_namespaceObject.vi.mocked(schemaMock.after).mockImplementationOnce(()=>{
40
+ throw afterError;
41
+ });
42
+ const thrown = (0, index_cjs_namespaceObject.captureThrow)(()=>(0, external_after_cjs_namespaceObject.after)({
43
+ schema: schemaMock,
44
+ hook: hookMock
45
+ }));
46
+ (0, external_vitest_namespaceObject.expect)(thrown.threw).toBe(true);
47
+ (0, external_vitest_namespaceObject.expect)(thrown.value).toBe(afterError);
48
+ });
49
+ });
50
+ });
51
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
52
+ Object.defineProperty(exports, '__esModule', {
53
+ value: true
54
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { after } from "./after.js";
3
+ import { captureThrow, createBaseSchemaMock } from "./testing/mocks/index.js";
4
+ const schemaMock = createBaseSchemaMock();
5
+ const nextSchemaMock = createBaseSchemaMock({
6
+ name: 'next.after.schema'
7
+ });
8
+ const hookMock = vi.fn((value)=>value.length);
9
+ describe('after()', ()=>{
10
+ beforeAll(()=>{
11
+ vi.mocked(schemaMock.after).mockImplementation(()=>nextSchemaMock);
12
+ });
13
+ beforeEach(()=>{
14
+ vi.mocked(schemaMock.after).mockClear();
15
+ hookMock.mockClear();
16
+ });
17
+ afterEach(()=>{
18
+ vi.mocked(schemaMock.after).mockClear();
19
+ });
20
+ afterAll(()=>{
21
+ vi.mocked(schemaMock.after).mockReset();
22
+ });
23
+ describe('happy', ()=>{
24
+ it('should delegate to schema.after when hook is provided', ()=>{
25
+ const result = after({
26
+ schema: schemaMock,
27
+ hook: hookMock
28
+ });
29
+ expect(schemaMock.after).toHaveBeenCalledTimes(1);
30
+ expect(schemaMock.after).toHaveBeenCalledWith(hookMock);
31
+ expect(result).toBe(nextSchemaMock);
32
+ });
33
+ });
34
+ describe('sad', ()=>{
35
+ it('should rethrow error when schema.after throws', ()=>{
36
+ const afterError = new Error('after hook failed');
37
+ vi.mocked(schemaMock.after).mockImplementationOnce(()=>{
38
+ throw afterError;
39
+ });
40
+ const thrown = captureThrow(()=>after({
41
+ schema: schemaMock,
42
+ hook: hookMock
43
+ }));
44
+ expect(thrown.threw).toBe(true);
45
+ expect(thrown.value).toBe(afterError);
46
+ });
47
+ });
48
+ });
package/dist/and.cjs ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
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
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
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
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ and: ()=>and
28
+ });
29
+ const and = ({ left, right })=>left.and(right);
30
+ exports.and = __webpack_exports__.and;
31
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
32
+ "and"
33
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
34
+ Object.defineProperty(exports, '__esModule', {
35
+ value: true
36
+ });
package/dist/and.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { Schema } from './types.js';
2
+ export interface AndInput<T, U> {
3
+ left: Schema<T>;
4
+ right: Schema<U>;
5
+ }
6
+ /**
7
+ * and is part of the public LIVON API.
8
+ *
9
+ * @remarks
10
+ * Parameter and return types are defined in the TypeScript signature.
11
+ *
12
+ * @see https://live-input-vector-output-node.github.io/livon-ts/docs/schema/and
13
+ *
14
+ * @example
15
+ * // Combines two object schemas into one schema that requires both shapes.
16
+ * const WithId = object({ name: 'withId', shape: { id: string() } });
17
+ * const WithAge = object({ name: 'withAge', shape: { age: number() } });
18
+ * const User = and({ left: WithId, right: WithAge });
19
+ * User.parse({ id: 'u1', age: 21 });
20
+ *
21
+ * @example
22
+ * // Extends the combined schema to also allow undefined.
23
+ * const OptionalUser = and({ left: WithId, right: WithAge }).optional();
24
+ * OptionalUser.parse(undefined);
25
+ */
26
+ export declare const and: <T, U>({ left, right }: AndInput<T, U>) => Schema<T & U>;
package/dist/and.js ADDED
@@ -0,0 +1,2 @@
1
+ const and = ({ left, right })=>left.and(right);
2
+ export { and };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __webpack_exports__ = {};
3
+ const external_vitest_namespaceObject = require("vitest");
4
+ const external_and_cjs_namespaceObject = require("./and.cjs");
5
+ const index_cjs_namespaceObject = require("./testing/mocks/index.cjs");
6
+ const leftSchemaMock = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
7
+ name: 'left'
8
+ });
9
+ const rightSchemaMock = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
10
+ name: 'right'
11
+ });
12
+ const mergedSchemaMock = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
13
+ name: 'merged'
14
+ });
15
+ (0, external_vitest_namespaceObject.describe)('and()', ()=>{
16
+ (0, external_vitest_namespaceObject.beforeAll)(()=>{
17
+ external_vitest_namespaceObject.vi.mocked(leftSchemaMock.and).mockImplementation(()=>mergedSchemaMock);
18
+ });
19
+ (0, external_vitest_namespaceObject.beforeEach)(()=>{
20
+ external_vitest_namespaceObject.vi.mocked(leftSchemaMock.and).mockClear();
21
+ });
22
+ (0, external_vitest_namespaceObject.afterEach)(()=>{
23
+ external_vitest_namespaceObject.vi.mocked(leftSchemaMock.and).mockClear();
24
+ });
25
+ (0, external_vitest_namespaceObject.afterAll)(()=>{
26
+ external_vitest_namespaceObject.vi.mocked(leftSchemaMock.and).mockReset();
27
+ });
28
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
29
+ (0, external_vitest_namespaceObject.it)('should delegate to left.and when right schema is provided', ()=>{
30
+ const result = (0, external_and_cjs_namespaceObject.and)({
31
+ left: leftSchemaMock,
32
+ right: rightSchemaMock
33
+ });
34
+ (0, external_vitest_namespaceObject.expect)(leftSchemaMock.and).toHaveBeenCalledTimes(1);
35
+ (0, external_vitest_namespaceObject.expect)(leftSchemaMock.and).toHaveBeenCalledWith(rightSchemaMock);
36
+ (0, external_vitest_namespaceObject.expect)(result).toBe(mergedSchemaMock);
37
+ });
38
+ });
39
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
40
+ (0, external_vitest_namespaceObject.it)('should rethrow error when left.and throws', ()=>{
41
+ const andError = new Error('and failed');
42
+ external_vitest_namespaceObject.vi.mocked(leftSchemaMock.and).mockImplementationOnce(()=>{
43
+ throw andError;
44
+ });
45
+ const thrown = (0, index_cjs_namespaceObject.captureThrow)(()=>(0, external_and_cjs_namespaceObject.and)({
46
+ left: leftSchemaMock,
47
+ right: rightSchemaMock
48
+ }));
49
+ (0, external_vitest_namespaceObject.expect)(thrown.threw).toBe(true);
50
+ (0, external_vitest_namespaceObject.expect)(thrown.value).toBe(andError);
51
+ });
52
+ });
53
+ });
54
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
55
+ Object.defineProperty(exports, '__esModule', {
56
+ value: true
57
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { and } from "./and.js";
3
+ import { captureThrow, createBaseSchemaMock } from "./testing/mocks/index.js";
4
+ const leftSchemaMock = createBaseSchemaMock({
5
+ name: 'left'
6
+ });
7
+ const rightSchemaMock = createBaseSchemaMock({
8
+ name: 'right'
9
+ });
10
+ const mergedSchemaMock = createBaseSchemaMock({
11
+ name: 'merged'
12
+ });
13
+ describe('and()', ()=>{
14
+ beforeAll(()=>{
15
+ vi.mocked(leftSchemaMock.and).mockImplementation(()=>mergedSchemaMock);
16
+ });
17
+ beforeEach(()=>{
18
+ vi.mocked(leftSchemaMock.and).mockClear();
19
+ });
20
+ afterEach(()=>{
21
+ vi.mocked(leftSchemaMock.and).mockClear();
22
+ });
23
+ afterAll(()=>{
24
+ vi.mocked(leftSchemaMock.and).mockReset();
25
+ });
26
+ describe('happy', ()=>{
27
+ it('should delegate to left.and when right schema is provided', ()=>{
28
+ const result = and({
29
+ left: leftSchemaMock,
30
+ right: rightSchemaMock
31
+ });
32
+ expect(leftSchemaMock.and).toHaveBeenCalledTimes(1);
33
+ expect(leftSchemaMock.and).toHaveBeenCalledWith(rightSchemaMock);
34
+ expect(result).toBe(mergedSchemaMock);
35
+ });
36
+ });
37
+ describe('sad', ()=>{
38
+ it('should rethrow error when left.and throws', ()=>{
39
+ const andError = new Error('and failed');
40
+ vi.mocked(leftSchemaMock.and).mockImplementationOnce(()=>{
41
+ throw andError;
42
+ });
43
+ const thrown = captureThrow(()=>and({
44
+ left: leftSchemaMock,
45
+ right: rightSchemaMock
46
+ }));
47
+ expect(thrown.threw).toBe(true);
48
+ expect(thrown.value).toBe(andError);
49
+ });
50
+ });
51
+ });