@fncts/schema 0.0.17 → 0.0.19

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 (114) hide show
  1. package/ParseError.d.ts +3 -3
  2. package/Parser.d.ts +2 -2
  3. package/Schema.d.ts +10 -10
  4. package/_cjs/AST.cjs +29 -29
  5. package/_cjs/AST.cjs.map +1 -1
  6. package/_cjs/ASTAnnotation.cjs +8 -8
  7. package/_cjs/ASTAnnotation.cjs.map +1 -1
  8. package/_cjs/ASTAnnotationMap.cjs +6 -6
  9. package/_cjs/ASTAnnotationMap.cjs.map +1 -1
  10. package/_cjs/Gen.cjs +10 -10
  11. package/_cjs/Gen.cjs.map +1 -1
  12. package/_cjs/Guard.cjs +11 -11
  13. package/_cjs/Guard.cjs.map +1 -1
  14. package/_cjs/InvalidInterpretationError.cjs.map +1 -1
  15. package/_cjs/ParseError/ParseError.cjs.map +1 -1
  16. package/_cjs/ParseError/ParseErrorFormatter.cjs.map +1 -1
  17. package/_cjs/ParseError/PathFormatter.cjs +3 -3
  18. package/_cjs/ParseError/PathFormatter.cjs.map +1 -1
  19. package/_cjs/ParseError/TreeFormatter.cjs +6 -6
  20. package/_cjs/ParseError/TreeFormatter.cjs.map +1 -1
  21. package/_cjs/ParseError.cjs +16 -16
  22. package/_cjs/ParseError.cjs.map +1 -1
  23. package/_cjs/ParseResult.cjs +2 -2
  24. package/_cjs/ParseResult.cjs.map +1 -1
  25. package/_cjs/Parser/api.cjs +6 -6
  26. package/_cjs/Parser/api.cjs.map +1 -1
  27. package/_cjs/Parser/definition.cjs +3 -3
  28. package/_cjs/Parser/definition.cjs.map +1 -1
  29. package/_cjs/Parser/interpreter.cjs +12 -12
  30. package/_cjs/Parser/interpreter.cjs.map +1 -1
  31. package/_cjs/Parser.cjs +8 -8
  32. package/_cjs/Parser.cjs.map +1 -1
  33. package/_cjs/Schema/api/conc.cjs +15 -15
  34. package/_cjs/Schema/api/conc.cjs.map +1 -1
  35. package/_cjs/Schema/api/either.cjs +12 -12
  36. package/_cjs/Schema/api/either.cjs.map +1 -1
  37. package/_cjs/Schema/api/hashMap.cjs +15 -15
  38. package/_cjs/Schema/api/hashMap.cjs.map +1 -1
  39. package/_cjs/Schema/api/hashSet.cjs +15 -15
  40. package/_cjs/Schema/api/hashSet.cjs.map +1 -1
  41. package/_cjs/Schema/api/immutableArray.cjs +13 -13
  42. package/_cjs/Schema/api/immutableArray.cjs.map +1 -1
  43. package/_cjs/Schema/api/list.cjs +16 -16
  44. package/_cjs/Schema/api/list.cjs.map +1 -1
  45. package/_cjs/Schema/api/map.cjs +13 -13
  46. package/_cjs/Schema/api/map.cjs.map +1 -1
  47. package/_cjs/Schema/api/maybe.cjs +14 -14
  48. package/_cjs/Schema/api/maybe.cjs.map +1 -1
  49. package/_cjs/Schema/api/set.cjs +13 -13
  50. package/_cjs/Schema/api/set.cjs.map +1 -1
  51. package/_cjs/Schema/api.cjs +12 -12
  52. package/_cjs/Schema/api.cjs.map +1 -1
  53. package/_cjs/Schema/definition.cjs +2 -2
  54. package/_cjs/Schema/definition.cjs.map +1 -1
  55. package/_cjs/Schema/derivations.cjs +10 -10
  56. package/_cjs/Schema/derivations.cjs.map +1 -1
  57. package/_cjs/Schema.cjs +40 -40
  58. package/_cjs/Schema.cjs.map +1 -1
  59. package/_cjs/Show.cjs +8 -8
  60. package/_cjs/Show.cjs.map +1 -1
  61. package/_cjs/global.cjs.map +1 -1
  62. package/_cjs/index.cjs.map +1 -1
  63. package/_cjs/utils.cjs +3 -3
  64. package/_cjs/utils.cjs.map +1 -1
  65. package/_mjs/AST.mjs +13 -13
  66. package/_mjs/AST.mjs.map +1 -1
  67. package/_mjs/ASTAnnotation.mjs.map +1 -1
  68. package/_mjs/ASTAnnotationMap.mjs +1 -1
  69. package/_mjs/ASTAnnotationMap.mjs.map +1 -1
  70. package/_mjs/Gen.mjs.map +1 -1
  71. package/_mjs/Guard.mjs +1 -1
  72. package/_mjs/Guard.mjs.map +1 -1
  73. package/_mjs/InvalidInterpretationError.mjs.map +1 -1
  74. package/_mjs/ParseError/ParseError.mjs.map +1 -1
  75. package/_mjs/ParseError/ParseErrorFormatter.mjs.map +1 -1
  76. package/_mjs/ParseError/PathFormatter.mjs.map +1 -1
  77. package/_mjs/ParseError/TreeFormatter.mjs.map +1 -1
  78. package/_mjs/ParseError.mjs +3 -4
  79. package/_mjs/ParseError.mjs.map +1 -1
  80. package/_mjs/ParseResult.mjs.map +1 -1
  81. package/_mjs/Parser/api.mjs.map +1 -1
  82. package/_mjs/Parser/definition.mjs.map +1 -1
  83. package/_mjs/Parser/interpreter.mjs +2 -2
  84. package/_mjs/Parser/interpreter.mjs.map +1 -1
  85. package/_mjs/Parser.mjs +2 -3
  86. package/_mjs/Parser.mjs.map +1 -1
  87. package/_mjs/Schema/api/conc.mjs.map +1 -1
  88. package/_mjs/Schema/api/either.mjs.map +1 -1
  89. package/_mjs/Schema/api/hashMap.mjs.map +1 -1
  90. package/_mjs/Schema/api/hashSet.mjs.map +1 -1
  91. package/_mjs/Schema/api/immutableArray.mjs.map +1 -1
  92. package/_mjs/Schema/api/list.mjs.map +1 -1
  93. package/_mjs/Schema/api/map.mjs.map +1 -1
  94. package/_mjs/Schema/api/maybe.mjs.map +1 -1
  95. package/_mjs/Schema/api/set.mjs.map +1 -1
  96. package/_mjs/Schema/api.mjs +1 -1
  97. package/_mjs/Schema/api.mjs.map +1 -1
  98. package/_mjs/Schema/definition.mjs.map +1 -1
  99. package/_mjs/Schema/derivations.mjs.map +1 -1
  100. package/_mjs/Schema.mjs +10 -12
  101. package/_mjs/Schema.mjs.map +1 -1
  102. package/_mjs/Show.mjs +2 -2
  103. package/_mjs/Show.mjs.map +1 -1
  104. package/_mjs/global.mjs.map +1 -1
  105. package/_mjs/index.mjs.map +1 -1
  106. package/_mjs/utils.mjs.map +1 -1
  107. package/_src/AST.ts +6 -6
  108. package/_src/Gen.ts +8 -8
  109. package/_src/ParseError.ts +3 -4
  110. package/_src/Parser.ts +2 -3
  111. package/_src/Schema.ts +10 -12
  112. package/_src/Show.ts +5 -5
  113. package/_src/utils.ts +2 -1
  114. package/package.json +3 -3
package/_src/AST.ts CHANGED
@@ -725,7 +725,7 @@ export class TypeLiteral extends AST {
725
725
  ) {
726
726
  super();
727
727
  this.propertySignatures = sortByAscendingCardinality(propertySignatures);
728
- this.indexSignatures = sortByAscendingCardinality(indexSignatures);
728
+ this.indexSignatures = sortByAscendingCardinality(indexSignatures);
729
729
  }
730
730
 
731
731
  clone(newProperties: Partial<this>): AST {
@@ -1232,7 +1232,7 @@ export function keyof(self: AST): AST {
1232
1232
  */
1233
1233
  export function createRecord(key: AST, value: AST, isReadonly: boolean): TypeLiteral {
1234
1234
  const propertySignatures: MutableVector<PropertySignature> = Vector.emptyPushable();
1235
- const indexSignatures: MutableVector<IndexSignature> = Vector.emptyPushable();
1235
+ const indexSignatures: MutableVector<IndexSignature> = Vector.emptyPushable();
1236
1236
 
1237
1237
  function go(key: AST): void {
1238
1238
  concrete(key);
@@ -1466,13 +1466,13 @@ export function getSearchTree(
1466
1466
  const otherwise: Array<AST> = [];
1467
1467
  for (let i = 0; i < members.length; i++) {
1468
1468
  const member = members[i]!;
1469
- const tags = getLiterals(member, isDecoding);
1469
+ const tags = getLiterals(member, isDecoding);
1470
1470
  if (tags.length > 0) {
1471
1471
  for (let j = 0; j < tags.length; j++) {
1472
1472
  const [key, literal] = tags[j]!;
1473
- const hash = String(literal.literal);
1474
- keys[key]! ||= { buckets: {}, ast: AST.neverKeyword, literals: [] };
1475
- const buckets = keys[key]!.buckets;
1473
+ const hash = String(literal.literal);
1474
+ keys[key]! ||= { buckets: {}, ast: AST.neverKeyword, literals: [] };
1475
+ const buckets = keys[key]!.buckets;
1476
1476
  if (Object.prototype.hasOwnProperty.call(buckets, hash)) {
1477
1477
  if (j < tags.length - 1) {
1478
1478
  continue;
package/_src/Gen.ts CHANGED
@@ -86,8 +86,8 @@ const go = memoize(function go(ast: AST): Gen<Sized, any> {
86
86
  }
87
87
  case ASTTag.Tuple: {
88
88
  const elements = ast.elements.map((e) => go(e.type));
89
- const rest = ast.rest.map((restElement) => restElement.map(go));
90
- let output = Gen.tuple(...elements);
89
+ const rest = ast.rest.map((restElement) => restElement.map(go));
90
+ let output = Gen.tuple(...elements);
91
91
  if (elements.length > 0 && rest.isNothing()) {
92
92
  const firstOptionalIndex = ast.elements.findIndex((e) => e.isOptional);
93
93
  if (firstOptionalIndex !== -1) {
@@ -99,7 +99,7 @@ const go = memoize(function go(ast: AST): Gen<Sized, any> {
99
99
  if (rest.isJust()) {
100
100
  const head = rest.value.unsafeHead!;
101
101
  const tail = rest.value.tail;
102
- output = output.flatMap((as) => head.arrayWith({ maxLength: 5 }).map((rest) => [...as, ...rest]));
102
+ output = output.flatMap((as) => head.arrayWith({ maxLength: 5 }).map((rest) => [...as, ...rest]));
103
103
  for (let j = 0; j < tail.length; j++) {
104
104
  output = output.flatMap((as) => tail[j]!.map((a) => [...as, a]));
105
105
  }
@@ -108,11 +108,11 @@ const go = memoize(function go(ast: AST): Gen<Sized, any> {
108
108
  }
109
109
  case ASTTag.TypeLiteral: {
110
110
  const propertySignatureTypes = ast.propertySignatures.map((ps) => go(ps.type));
111
- const indexSignatures = ast.indexSignatures.map((is) => [go(is.parameter), go(is.type)] as const);
111
+ const indexSignatures = ast.indexSignatures.map((is) => [go(is.parameter), go(is.type)] as const);
112
112
  const requiredGens: Record<PropertyKey, Gen<any, any>> = {};
113
113
  const optionalGens: Record<PropertyKey, Gen<any, any>> = {};
114
114
  for (let i = 0; i < propertySignatureTypes.length; i++) {
115
- const ps = ast.propertySignatures[i]!;
115
+ const ps = ast.propertySignatures[i]!;
116
116
  const name = ps.name;
117
117
  if (!ps.isOptional) {
118
118
  requiredGens[name] = propertySignatureTypes[i]!;
@@ -123,8 +123,8 @@ const go = memoize(function go(ast: AST): Gen<Sized, any> {
123
123
  let output = Gen.struct(requiredGens).zipWith(Gen.partial(optionalGens), (a, b) => ({ ...a, ...b }));
124
124
  for (let i = 0; i < indexSignatures.length; i++) {
125
125
  const parameter = indexSignatures[i]![0]!;
126
- const type = indexSignatures[i]![1]!;
127
- output = output.flatMap((o) => {
126
+ const type = indexSignatures[i]![1]!;
127
+ output = output.flatMap((o) => {
128
128
  return record(parameter, type).map((d) => ({ ...d, ...o }));
129
129
  });
130
130
  }
@@ -137,7 +137,7 @@ const go = memoize(function go(ast: AST): Gen<Sized, any> {
137
137
  case ASTTag.Lazy: {
138
138
  return getHook(ast).match(
139
139
  () => {
140
- const f = () => go(ast.getAST());
140
+ const f = () => go(ast.getAST());
141
141
  const get = memoize<typeof f, Gen<any, any>>(f);
142
142
  return Gen.defer(() => get(f));
143
143
  },
@@ -1,7 +1,6 @@
1
- /* eslint-disable simple-import-sort/exports */
2
1
  // codegen:start { preset: barrel, include: ./ParseError/*.ts }
3
- export * from "./ParseError/TreeFormatter.js";
4
- export * from "./ParseError/PathFormatter.js";
5
- export * from "./ParseError/ParseErrorFormatter.js";
6
2
  export * from "./ParseError/ParseError.js";
3
+ export * from "./ParseError/ParseErrorFormatter.js";
4
+ export * from "./ParseError/PathFormatter.js";
5
+ export * from "./ParseError/TreeFormatter.js";
7
6
  // codegen:end
package/_src/Parser.ts CHANGED
@@ -1,6 +1,5 @@
1
- /* eslint-disable simple-import-sort/exports */
2
1
  // codegen:start { preset: barrel, include: ./Parser/*.ts }
3
- export * from "./Parser/interpreter.js";
4
- export * from "./Parser/definition.js";
5
2
  export * from "./Parser/api.js";
3
+ export * from "./Parser/definition.js";
4
+ export * from "./Parser/interpreter.js";
6
5
  // codegen:end
package/_src/Schema.ts CHANGED
@@ -1,21 +1,19 @@
1
- /* eslint-disable simple-import-sort/exports */
2
1
  // codegen:start { preset: barrel, include: ./Schema/*.ts }
3
- export * from "./Schema/derivations.js";
4
- export * from "./Schema/definition.js";
5
2
  export * from "./Schema/api.js";
3
+ export * from "./Schema/definition.js";
4
+ export * from "./Schema/derivations.js";
6
5
  // codegen:end
7
6
 
8
- /* eslint-disable simple-import-sort/exports */
9
7
  // codegen:start { preset: barrel, include: ./Schema/api/*.ts }
10
- export * from "./Schema/api/set.js";
11
- export * from "./Schema/api/maybe.js";
12
- export * from "./Schema/api/map.js";
13
- export * from "./Schema/api/list.js";
14
- export * from "./Schema/api/immutableArray.js";
15
- export * from "./Schema/api/hashSet.js";
16
- export * from "./Schema/api/hashMap.js";
17
- export * from "./Schema/api/either.js";
18
8
  export * from "./Schema/api/conc.js";
9
+ export * from "./Schema/api/either.js";
10
+ export * from "./Schema/api/hashMap.js";
11
+ export * from "./Schema/api/hashSet.js";
12
+ export * from "./Schema/api/immutableArray.js";
13
+ export * from "./Schema/api/list.js";
14
+ export * from "./Schema/api/map.js";
15
+ export * from "./Schema/api/maybe.js";
16
+ export * from "./Schema/api/set.js";
19
17
  // codegen:end
20
18
 
21
19
  export type {} from "./Parser.js";
package/_src/Show.ts CHANGED
@@ -13,7 +13,7 @@ import { globalValue } from "@fncts/base/data/Global";
13
13
  import { ASTTag } from "@fncts/schema/AST";
14
14
  import { formatUnknown } from "@fncts/schema/utils";
15
15
 
16
- const showMemoMap = globalValue(Symbol.for("fncts.schema.Guard.showMemoMap"), () => new WeakMap<AST, string>());
16
+ const showMemoMap = globalValue(Symbol.for("fncts.schema.Guard.showMemoMap"), () => new WeakMap<AST, string>());
17
17
  const showMemoMapVerbose = globalValue(
18
18
  Symbol.for("fncts.schema.Guard.showMemoMapVerbose"),
19
19
  () => new WeakMap<AST, string>(),
@@ -21,7 +21,7 @@ const showMemoMapVerbose = globalValue(
21
21
 
22
22
  function goMemo(ast: AST, verbose: boolean): string {
23
23
  const memoMap = verbose ? showMemoMapVerbose : showMemoMap;
24
- const memo = memoMap.get(ast);
24
+ const memo = memoMap.get(ast);
25
25
  if (memo) {
26
26
  return memo;
27
27
  }
@@ -153,10 +153,10 @@ function formatTuple(ast: Tuple, verbose: boolean): string {
153
153
  .match(
154
154
  () => `${ast.isReadonly ? "readonly " : ""}[${formattedElements}]`,
155
155
  (rest) => {
156
- const head = rest.unsafeHead!;
157
- const tail = rest.tail;
156
+ const head = rest.unsafeHead!;
157
+ const tail = rest.tail;
158
158
  const formattedHead = goMemo(head, verbose);
159
- const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead;
159
+ const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead;
160
160
 
161
161
  if (tail.length > 0) {
162
162
  const formattedTail = tail.map((ast) => goMemo(ast, verbose)).join(", ");
package/_src/utils.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { IndexSignature, TemplateLiteral } from "./AST";
2
2
 
3
- import { ASTTag } from "./AST.js";
4
3
  import { showWithOptions } from "@fncts/base/data/Showable";
5
4
 
5
+ import { ASTTag } from "./AST.js";
6
+
6
7
  export function memoize<A, B>(f: (a: A) => B): (a: A) => B {
7
8
  const cache = new Map();
8
9
  return (a) => {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fncts/schema",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "dependencies": {
5
- "@fncts/base": "0.0.36",
6
- "@fncts/typelevel": "0.0.18"
5
+ "@fncts/base": "0.0.38",
6
+ "@fncts/typelevel": "0.0.19"
7
7
  },
8
8
  "exports": {
9
9
  "./*": {