@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/dist/date.cjs ADDED
@@ -0,0 +1,53 @@
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
+ date: ()=>date
28
+ });
29
+ const external_schemaFactory_cjs_namespaceObject = require("./schemaFactory.cjs");
30
+ const external_typeGuards_cjs_namespaceObject = require("./typeGuards.cjs");
31
+ const date = ({ name = 'date', doc } = {})=>(0, external_schemaFactory_cjs_namespaceObject.schemaFactory)({
32
+ name,
33
+ type: 'date',
34
+ doc,
35
+ ast: ()=>({
36
+ type: 'date',
37
+ name
38
+ }),
39
+ validate: (input)=>{
40
+ if (!(0, external_typeGuards_cjs_namespaceObject.isDate)(input)) throw {
41
+ message: 'Expected Date',
42
+ code: 'date.type'
43
+ };
44
+ return input;
45
+ }
46
+ });
47
+ exports.date = __webpack_exports__.date;
48
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
49
+ "date"
50
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
51
+ Object.defineProperty(exports, '__esModule', {
52
+ value: true
53
+ });
package/dist/date.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import type { SchemaDoc } from './types.js';
2
+ export interface DateFactoryInput {
3
+ name?: string;
4
+ doc?: SchemaDoc;
5
+ }
6
+ /**
7
+ * date 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/date
13
+ *
14
+ * @example
15
+ * // Creates a date schema and validates a Date object.
16
+ * const CreatedAt = date();
17
+ * CreatedAt.parse(new Date());
18
+ *
19
+ * @example
20
+ * // Extends date validation to also allow null.
21
+ * const MaybeCreatedAt = date().nullable();
22
+ * MaybeCreatedAt.parse(null);
23
+ */
24
+ export declare const date: ({ name, doc }?: DateFactoryInput) => import("./schemaFactory.js").SchemaWithChain<Date, import("./schemaFactory.js").SchemaFactoryChainDefinition<Date>>;
package/dist/date.js ADDED
@@ -0,0 +1,19 @@
1
+ import { schemaFactory } from "./schemaFactory.js";
2
+ import { isDate } from "./typeGuards.js";
3
+ const date = ({ name = 'date', doc } = {})=>schemaFactory({
4
+ name,
5
+ type: 'date',
6
+ doc,
7
+ ast: ()=>({
8
+ type: 'date',
9
+ name
10
+ }),
11
+ validate: (input)=>{
12
+ if (!isDate(input)) throw {
13
+ message: 'Expected Date',
14
+ code: 'date.type'
15
+ };
16
+ return input;
17
+ }
18
+ });
19
+ export { date };
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __webpack_exports__ = {};
3
+ const external_vitest_namespaceObject = require("vitest");
4
+ const external_date_cjs_namespaceObject = require("./date.cjs");
5
+ const external_schemaFactory_cjs_namespaceObject = require("./schemaFactory.cjs");
6
+ const external_typeGuards_cjs_namespaceObject = require("./typeGuards.cjs");
7
+ const index_cjs_namespaceObject = require("./testing/mocks/index.cjs");
8
+ external_vitest_namespaceObject.vi.mock('./schemaFactory.js', ()=>({
9
+ schemaFactory: external_vitest_namespaceObject.vi.fn()
10
+ }));
11
+ external_vitest_namespaceObject.vi.mock('./typeGuards.js', ()=>({
12
+ isDate: external_vitest_namespaceObject.vi.fn()
13
+ }));
14
+ const schemaFactoryMock = external_vitest_namespaceObject.vi.mocked(external_schemaFactory_cjs_namespaceObject.schemaFactory);
15
+ const isDateMock = external_vitest_namespaceObject.vi.mocked(external_typeGuards_cjs_namespaceObject.isDate);
16
+ const schemaContextMock = (0, index_cjs_namespaceObject.createSchemaContextMock)();
17
+ const schemaFactoryImplementation = (0, index_cjs_namespaceObject.createSchemaFactoryMock)();
18
+ const getFactoryInput = ()=>{
19
+ const call = schemaFactoryMock.mock.calls[0];
20
+ if (!call) throw new Error('schemaFactory should be called once before reading input');
21
+ return call[0];
22
+ };
23
+ (0, external_vitest_namespaceObject.describe)('date()', ()=>{
24
+ (0, external_vitest_namespaceObject.beforeAll)(()=>{
25
+ schemaFactoryMock.mockImplementation(schemaFactoryImplementation);
26
+ });
27
+ (0, external_vitest_namespaceObject.beforeEach)(()=>{
28
+ schemaFactoryMock.mockClear();
29
+ schemaFactoryImplementation.mockClear();
30
+ isDateMock.mockReset();
31
+ isDateMock.mockReturnValue(true);
32
+ });
33
+ (0, external_vitest_namespaceObject.afterEach)(()=>{
34
+ isDateMock.mockClear();
35
+ });
36
+ (0, external_vitest_namespaceObject.afterAll)(()=>{
37
+ schemaFactoryMock.mockReset();
38
+ schemaFactoryImplementation.mockReset();
39
+ isDateMock.mockReset();
40
+ });
41
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
42
+ (0, external_vitest_namespaceObject.it)('should delegate to schemaFactory when using default metadata', ()=>{
43
+ const result = (0, external_date_cjs_namespaceObject.date)();
44
+ (0, external_vitest_namespaceObject.expect)(schemaFactoryMock).toHaveBeenCalledTimes(1);
45
+ const factoryInput = getFactoryInput();
46
+ (0, external_vitest_namespaceObject.expect)(factoryInput.name).toBe('date');
47
+ (0, external_vitest_namespaceObject.expect)(factoryInput.type).toBe('date');
48
+ (0, external_vitest_namespaceObject.expect)(factoryInput.doc).toBeUndefined();
49
+ (0, external_vitest_namespaceObject.expect)(factoryInput.ast(schemaContextMock)).toEqual({
50
+ type: 'date',
51
+ name: 'date'
52
+ });
53
+ (0, external_vitest_namespaceObject.expect)(result).toBe(schemaFactoryMock.mock.results[0]?.value);
54
+ });
55
+ (0, external_vitest_namespaceObject.it)('should pass custom metadata to schemaFactory when options are provided', ()=>{
56
+ const doc = {
57
+ summary: 'date doc'
58
+ };
59
+ (0, external_date_cjs_namespaceObject.date)({
60
+ name: 'CreatedAt',
61
+ doc
62
+ });
63
+ const factoryInput = getFactoryInput();
64
+ (0, external_vitest_namespaceObject.expect)(factoryInput.name).toBe('CreatedAt');
65
+ (0, external_vitest_namespaceObject.expect)(factoryInput.doc).toEqual(doc);
66
+ (0, external_vitest_namespaceObject.expect)(factoryInput.ast(schemaContextMock)).toEqual({
67
+ type: 'date',
68
+ name: 'CreatedAt'
69
+ });
70
+ });
71
+ (0, external_vitest_namespaceObject.it)('should validate input through isDate when input is Date', ()=>{
72
+ const input = new Date('2025-02-01T00:00:00.000Z');
73
+ (0, external_date_cjs_namespaceObject.date)();
74
+ const factoryInput = getFactoryInput();
75
+ const parsed = factoryInput.validate(input, schemaContextMock);
76
+ (0, external_vitest_namespaceObject.expect)(parsed).toBe(input);
77
+ (0, external_vitest_namespaceObject.expect)(isDateMock).toHaveBeenCalledWith(input);
78
+ });
79
+ });
80
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
81
+ (0, external_vitest_namespaceObject.it)('should throw schema error payload when input is not Date', ()=>{
82
+ isDateMock.mockReturnValue(false);
83
+ (0, external_date_cjs_namespaceObject.date)();
84
+ const factoryInput = getFactoryInput();
85
+ const thrown = (0, index_cjs_namespaceObject.captureThrow)(()=>factoryInput.validate('x', schemaContextMock));
86
+ (0, external_vitest_namespaceObject.expect)(thrown.threw).toBe(true);
87
+ (0, external_vitest_namespaceObject.expect)(thrown.value).toEqual({
88
+ message: 'Expected Date',
89
+ code: 'date.type'
90
+ });
91
+ });
92
+ });
93
+ });
94
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
95
+ Object.defineProperty(exports, '__esModule', {
96
+ value: true
97
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,91 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { date } from "./date.js";
3
+ import { schemaFactory } from "./schemaFactory.js";
4
+ import { isDate } from "./typeGuards.js";
5
+ import { captureThrow, createSchemaContextMock, createSchemaFactoryMock } from "./testing/mocks/index.js";
6
+ vi.mock('./schemaFactory.js', ()=>({
7
+ schemaFactory: vi.fn()
8
+ }));
9
+ vi.mock('./typeGuards.js', ()=>({
10
+ isDate: vi.fn()
11
+ }));
12
+ const schemaFactoryMock = vi.mocked(schemaFactory);
13
+ const isDateMock = vi.mocked(isDate);
14
+ const schemaContextMock = createSchemaContextMock();
15
+ const schemaFactoryImplementation = createSchemaFactoryMock();
16
+ const getFactoryInput = ()=>{
17
+ const call = schemaFactoryMock.mock.calls[0];
18
+ if (!call) throw new Error('schemaFactory should be called once before reading input');
19
+ return call[0];
20
+ };
21
+ describe('date()', ()=>{
22
+ beforeAll(()=>{
23
+ schemaFactoryMock.mockImplementation(schemaFactoryImplementation);
24
+ });
25
+ beforeEach(()=>{
26
+ schemaFactoryMock.mockClear();
27
+ schemaFactoryImplementation.mockClear();
28
+ isDateMock.mockReset();
29
+ isDateMock.mockReturnValue(true);
30
+ });
31
+ afterEach(()=>{
32
+ isDateMock.mockClear();
33
+ });
34
+ afterAll(()=>{
35
+ schemaFactoryMock.mockReset();
36
+ schemaFactoryImplementation.mockReset();
37
+ isDateMock.mockReset();
38
+ });
39
+ describe('happy', ()=>{
40
+ it('should delegate to schemaFactory when using default metadata', ()=>{
41
+ const result = date();
42
+ expect(schemaFactoryMock).toHaveBeenCalledTimes(1);
43
+ const factoryInput = getFactoryInput();
44
+ expect(factoryInput.name).toBe('date');
45
+ expect(factoryInput.type).toBe('date');
46
+ expect(factoryInput.doc).toBeUndefined();
47
+ expect(factoryInput.ast(schemaContextMock)).toEqual({
48
+ type: 'date',
49
+ name: 'date'
50
+ });
51
+ expect(result).toBe(schemaFactoryMock.mock.results[0]?.value);
52
+ });
53
+ it('should pass custom metadata to schemaFactory when options are provided', ()=>{
54
+ const doc = {
55
+ summary: 'date doc'
56
+ };
57
+ date({
58
+ name: 'CreatedAt',
59
+ doc
60
+ });
61
+ const factoryInput = getFactoryInput();
62
+ expect(factoryInput.name).toBe('CreatedAt');
63
+ expect(factoryInput.doc).toEqual(doc);
64
+ expect(factoryInput.ast(schemaContextMock)).toEqual({
65
+ type: 'date',
66
+ name: 'CreatedAt'
67
+ });
68
+ });
69
+ it('should validate input through isDate when input is Date', ()=>{
70
+ const input = new Date('2025-02-01T00:00:00.000Z');
71
+ date();
72
+ const factoryInput = getFactoryInput();
73
+ const parsed = factoryInput.validate(input, schemaContextMock);
74
+ expect(parsed).toBe(input);
75
+ expect(isDateMock).toHaveBeenCalledWith(input);
76
+ });
77
+ });
78
+ describe('sad', ()=>{
79
+ it('should throw schema error payload when input is not Date', ()=>{
80
+ isDateMock.mockReturnValue(false);
81
+ date();
82
+ const factoryInput = getFactoryInput();
83
+ const thrown = captureThrow(()=>factoryInput.validate('x', schemaContextMock));
84
+ expect(thrown.threw).toBe(true);
85
+ expect(thrown.value).toEqual({
86
+ message: 'Expected Date',
87
+ code: 'date.type'
88
+ });
89
+ });
90
+ });
91
+ });
package/dist/doc.cjs ADDED
@@ -0,0 +1,54 @@
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
+ mergeDoc: ()=>mergeDoc,
28
+ normalizeDoc: ()=>normalizeDoc
29
+ });
30
+ const normalizeDoc = (doc)=>{
31
+ if (!doc) return;
32
+ if ('string' == typeof doc) return {
33
+ description: doc
34
+ };
35
+ if ('object' == typeof doc && !Array.isArray(doc)) return doc;
36
+ };
37
+ const mergeDoc = (existing, next)=>{
38
+ if (!existing && !next) return;
39
+ if (!existing) return next;
40
+ if (!next) return existing;
41
+ return {
42
+ ...existing,
43
+ ...next
44
+ };
45
+ };
46
+ exports.mergeDoc = __webpack_exports__.mergeDoc;
47
+ exports.normalizeDoc = __webpack_exports__.normalizeDoc;
48
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
49
+ "mergeDoc",
50
+ "normalizeDoc"
51
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
52
+ Object.defineProperty(exports, '__esModule', {
53
+ value: true
54
+ });
package/dist/doc.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { SchemaDoc } from './types.js';
2
+ /**
3
+ * normalizeDoc is part of the public LIVON API.
4
+ *
5
+ * @remarks
6
+ * Parameter and return types are defined in the TypeScript signature.
7
+ *
8
+ * @see https://live-input-vector-output-node.github.io/livon-ts/docs/packages/schema
9
+ *
10
+ * @example
11
+ * const result = normalizeDoc(undefined as never);
12
+ */
13
+ export declare const normalizeDoc: (doc?: SchemaDoc) => Readonly<Record<string, unknown>> | undefined;
14
+ /**
15
+ * mergeDoc is part of the public LIVON API.
16
+ *
17
+ * @remarks
18
+ * Parameter and return types are defined in the TypeScript signature.
19
+ *
20
+ * @see https://live-input-vector-output-node.github.io/livon-ts/docs/packages/schema
21
+ *
22
+ * @example
23
+ * const result = mergeDoc(undefined as never);
24
+ */
25
+ export declare const mergeDoc: (existing?: Readonly<Record<string, unknown>>, next?: Readonly<Record<string, unknown>>) => Readonly<Record<string, unknown>> | undefined;
package/dist/doc.js ADDED
@@ -0,0 +1,17 @@
1
+ const normalizeDoc = (doc)=>{
2
+ if (!doc) return;
3
+ if ('string' == typeof doc) return {
4
+ description: doc
5
+ };
6
+ if ('object' == typeof doc && !Array.isArray(doc)) return doc;
7
+ };
8
+ const mergeDoc = (existing, next)=>{
9
+ if (!existing && !next) return;
10
+ if (!existing) return next;
11
+ if (!next) return existing;
12
+ return {
13
+ ...existing,
14
+ ...next
15
+ };
16
+ };
17
+ export { mergeDoc, normalizeDoc };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __webpack_exports__ = {};
3
+ const external_vitest_namespaceObject = require("vitest");
4
+ const external_doc_cjs_namespaceObject = require("./doc.cjs");
5
+ (0, external_vitest_namespaceObject.describe)('doc utilities', ()=>{
6
+ let stringDoc;
7
+ let objectDoc;
8
+ let existingDoc;
9
+ let nextDoc;
10
+ (0, external_vitest_namespaceObject.beforeAll)(()=>{
11
+ stringDoc = '';
12
+ objectDoc = {};
13
+ existingDoc = {};
14
+ nextDoc = {};
15
+ });
16
+ (0, external_vitest_namespaceObject.beforeEach)(()=>{
17
+ stringDoc = 'User schema documentation';
18
+ objectDoc = {
19
+ summary: 'User',
20
+ details: 'Contains user payload fields'
21
+ };
22
+ existingDoc = {
23
+ summary: 'Existing summary',
24
+ stable: true
25
+ };
26
+ nextDoc = {
27
+ summary: 'Next summary',
28
+ deprecated: false
29
+ };
30
+ });
31
+ (0, external_vitest_namespaceObject.afterEach)(()=>{
32
+ stringDoc = '';
33
+ objectDoc = {};
34
+ existingDoc = {};
35
+ nextDoc = {};
36
+ });
37
+ (0, external_vitest_namespaceObject.afterAll)(()=>{
38
+ stringDoc = '';
39
+ objectDoc = {};
40
+ existingDoc = {};
41
+ nextDoc = {};
42
+ });
43
+ (0, external_vitest_namespaceObject.describe)('normalizeDoc()', ()=>{
44
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
45
+ (0, external_vitest_namespaceObject.it)("should return description record when doc is string", ()=>{
46
+ const normalized = (0, external_doc_cjs_namespaceObject.normalizeDoc)(stringDoc);
47
+ (0, external_vitest_namespaceObject.expect)(normalized).toEqual({
48
+ description: stringDoc
49
+ });
50
+ });
51
+ (0, external_vitest_namespaceObject.it)('should return same record when doc is object', ()=>{
52
+ const normalized = (0, external_doc_cjs_namespaceObject.normalizeDoc)(objectDoc);
53
+ (0, external_vitest_namespaceObject.expect)(normalized).toBe(objectDoc);
54
+ });
55
+ });
56
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
57
+ (0, external_vitest_namespaceObject.it)('should return undefined when doc is missing', ()=>{
58
+ const normalized = (0, external_doc_cjs_namespaceObject.normalizeDoc)(void 0);
59
+ (0, external_vitest_namespaceObject.expect)(normalized).toBeUndefined();
60
+ });
61
+ (0, external_vitest_namespaceObject.it)('should return undefined when doc is array', ()=>{
62
+ const normalized = (0, external_doc_cjs_namespaceObject.normalizeDoc)([
63
+ 'invalid'
64
+ ]);
65
+ (0, external_vitest_namespaceObject.expect)(normalized).toBeUndefined();
66
+ });
67
+ });
68
+ });
69
+ (0, external_vitest_namespaceObject.describe)('mergeDoc()', ()=>{
70
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
71
+ (0, external_vitest_namespaceObject.it)('should merge both records when existing and next are provided', ()=>{
72
+ const merged = (0, external_doc_cjs_namespaceObject.mergeDoc)(existingDoc, nextDoc);
73
+ (0, external_vitest_namespaceObject.expect)(merged).toEqual({
74
+ summary: 'Next summary',
75
+ stable: true,
76
+ deprecated: false
77
+ });
78
+ });
79
+ (0, external_vitest_namespaceObject.it)('should return next when only next is provided', ()=>{
80
+ const merged = (0, external_doc_cjs_namespaceObject.mergeDoc)(void 0, nextDoc);
81
+ (0, external_vitest_namespaceObject.expect)(merged).toBe(nextDoc);
82
+ });
83
+ (0, external_vitest_namespaceObject.it)('should return existing when only existing is provided', ()=>{
84
+ const merged = (0, external_doc_cjs_namespaceObject.mergeDoc)(existingDoc, void 0);
85
+ (0, external_vitest_namespaceObject.expect)(merged).toBe(existingDoc);
86
+ });
87
+ });
88
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
89
+ (0, external_vitest_namespaceObject.it)('should return undefined when both values are missing', ()=>{
90
+ const merged = (0, external_doc_cjs_namespaceObject.mergeDoc)(void 0, void 0);
91
+ (0, external_vitest_namespaceObject.expect)(merged).toBeUndefined();
92
+ });
93
+ });
94
+ });
95
+ });
96
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
97
+ Object.defineProperty(exports, '__esModule', {
98
+ value: true
99
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
2
+ import { mergeDoc, normalizeDoc } from "./doc.js";
3
+ describe('doc utilities', ()=>{
4
+ let stringDoc;
5
+ let objectDoc;
6
+ let existingDoc;
7
+ let nextDoc;
8
+ beforeAll(()=>{
9
+ stringDoc = '';
10
+ objectDoc = {};
11
+ existingDoc = {};
12
+ nextDoc = {};
13
+ });
14
+ beforeEach(()=>{
15
+ stringDoc = 'User schema documentation';
16
+ objectDoc = {
17
+ summary: 'User',
18
+ details: 'Contains user payload fields'
19
+ };
20
+ existingDoc = {
21
+ summary: 'Existing summary',
22
+ stable: true
23
+ };
24
+ nextDoc = {
25
+ summary: 'Next summary',
26
+ deprecated: false
27
+ };
28
+ });
29
+ afterEach(()=>{
30
+ stringDoc = '';
31
+ objectDoc = {};
32
+ existingDoc = {};
33
+ nextDoc = {};
34
+ });
35
+ afterAll(()=>{
36
+ stringDoc = '';
37
+ objectDoc = {};
38
+ existingDoc = {};
39
+ nextDoc = {};
40
+ });
41
+ describe('normalizeDoc()', ()=>{
42
+ describe('happy', ()=>{
43
+ it("should return description record when doc is string", ()=>{
44
+ const normalized = normalizeDoc(stringDoc);
45
+ expect(normalized).toEqual({
46
+ description: stringDoc
47
+ });
48
+ });
49
+ it('should return same record when doc is object', ()=>{
50
+ const normalized = normalizeDoc(objectDoc);
51
+ expect(normalized).toBe(objectDoc);
52
+ });
53
+ });
54
+ describe('sad', ()=>{
55
+ it('should return undefined when doc is missing', ()=>{
56
+ const normalized = normalizeDoc(void 0);
57
+ expect(normalized).toBeUndefined();
58
+ });
59
+ it('should return undefined when doc is array', ()=>{
60
+ const normalized = normalizeDoc([
61
+ 'invalid'
62
+ ]);
63
+ expect(normalized).toBeUndefined();
64
+ });
65
+ });
66
+ });
67
+ describe('mergeDoc()', ()=>{
68
+ describe('happy', ()=>{
69
+ it('should merge both records when existing and next are provided', ()=>{
70
+ const merged = mergeDoc(existingDoc, nextDoc);
71
+ expect(merged).toEqual({
72
+ summary: 'Next summary',
73
+ stable: true,
74
+ deprecated: false
75
+ });
76
+ });
77
+ it('should return next when only next is provided', ()=>{
78
+ const merged = mergeDoc(void 0, nextDoc);
79
+ expect(merged).toBe(nextDoc);
80
+ });
81
+ it('should return existing when only existing is provided', ()=>{
82
+ const merged = mergeDoc(existingDoc, void 0);
83
+ expect(merged).toBe(existingDoc);
84
+ });
85
+ });
86
+ describe('sad', ()=>{
87
+ it('should return undefined when both values are missing', ()=>{
88
+ const merged = mergeDoc(void 0, void 0);
89
+ expect(merged).toBeUndefined();
90
+ });
91
+ });
92
+ });
93
+ });
@@ -0,0 +1,74 @@
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
+ enumeration: ()=>enumeration
28
+ });
29
+ const external_schemaFactory_cjs_namespaceObject = require("./schemaFactory.cjs");
30
+ const enumeration = (name, doc)=>({
31
+ values: (...values)=>(0, external_schemaFactory_cjs_namespaceObject.schemaFactory)({
32
+ name: `enum:${name}`,
33
+ type: 'enum',
34
+ doc,
35
+ ast: ()=>({
36
+ type: 'enum',
37
+ name,
38
+ constraints: {
39
+ values
40
+ }
41
+ }),
42
+ validate: (input)=>{
43
+ if (!values.includes(input)) throw {
44
+ message: `Input "${String(input)}" is not valid for enum "${name}". Valid values: ${values.join(', ')}`,
45
+ code: 'enum.value',
46
+ context: {
47
+ name,
48
+ values
49
+ }
50
+ };
51
+ return input;
52
+ },
53
+ chain: {
54
+ literal: (data)=>(only)=>{
55
+ if (data !== only) throw {
56
+ message: `Input "${String(data)}" does not match literal "${String(only)}" for enum "${name}".`,
57
+ code: 'enum.literal',
58
+ context: {
59
+ name,
60
+ only
61
+ }
62
+ };
63
+ return data;
64
+ }
65
+ }
66
+ })
67
+ });
68
+ exports.enumeration = __webpack_exports__.enumeration;
69
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
70
+ "enumeration"
71
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
72
+ Object.defineProperty(exports, '__esModule', {
73
+ value: true
74
+ });