@fncts/schema 0.0.20 → 0.0.22

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 (93) hide show
  1. package/AST.d.ts +4 -4
  2. package/ASTAnnotation.d.ts +7 -0
  3. package/Eq.d.ts +13 -0
  4. package/Schema/derivations.d.ts +12 -4
  5. package/Schema.d.ts +0 -1
  6. package/_cjs/AST.cjs +4 -5
  7. package/_cjs/AST.cjs.map +1 -1
  8. package/_cjs/ASTAnnotation.cjs +7 -3
  9. package/_cjs/ASTAnnotation.cjs.map +1 -1
  10. package/_cjs/ASTAnnotationMap.cjs +1 -2
  11. package/_cjs/ASTAnnotationMap.cjs.map +1 -1
  12. package/_cjs/Eq.cjs +156 -0
  13. package/_cjs/Eq.cjs.map +1 -0
  14. package/_cjs/Gen.cjs +1 -2
  15. package/_cjs/Gen.cjs.map +1 -1
  16. package/_cjs/Guard.cjs +1 -2
  17. package/_cjs/Guard.cjs.map +1 -1
  18. package/_cjs/ParseError/ParseErrorFormatter.cjs +0 -4
  19. package/_cjs/ParseError/PathFormatter.cjs +1 -2
  20. package/_cjs/ParseError/PathFormatter.cjs.map +1 -1
  21. package/_cjs/ParseError/TreeFormatter.cjs +1 -2
  22. package/_cjs/ParseError/TreeFormatter.cjs.map +1 -1
  23. package/_cjs/ParseResult.cjs +1 -2
  24. package/_cjs/ParseResult.cjs.map +1 -1
  25. package/_cjs/Parser/api.cjs +1 -2
  26. package/_cjs/Parser/api.cjs.map +1 -1
  27. package/_cjs/Parser/definition.cjs +1 -2
  28. package/_cjs/Parser/definition.cjs.map +1 -1
  29. package/_cjs/Parser/interpreter.cjs +1 -2
  30. package/_cjs/Parser/interpreter.cjs.map +1 -1
  31. package/_cjs/Schema/api/conc.cjs +1 -2
  32. package/_cjs/Schema/api/conc.cjs.map +1 -1
  33. package/_cjs/Schema/api/either.cjs +1 -2
  34. package/_cjs/Schema/api/either.cjs.map +1 -1
  35. package/_cjs/Schema/api/hashMap.cjs +1 -2
  36. package/_cjs/Schema/api/hashMap.cjs.map +1 -1
  37. package/_cjs/Schema/api/hashSet.cjs +1 -2
  38. package/_cjs/Schema/api/hashSet.cjs.map +1 -1
  39. package/_cjs/Schema/api/list.cjs +1 -2
  40. package/_cjs/Schema/api/list.cjs.map +1 -1
  41. package/_cjs/Schema/api/map.cjs +1 -2
  42. package/_cjs/Schema/api/map.cjs.map +1 -1
  43. package/_cjs/Schema/api/maybe.cjs +1 -2
  44. package/_cjs/Schema/api/maybe.cjs.map +1 -1
  45. package/_cjs/Schema/api/set.cjs +1 -2
  46. package/_cjs/Schema/api/set.cjs.map +1 -1
  47. package/_cjs/Schema/api.cjs +1 -2
  48. package/_cjs/Schema/api.cjs.map +1 -1
  49. package/_cjs/Schema/definition.cjs +1 -2
  50. package/_cjs/Schema/definition.cjs.map +1 -1
  51. package/_cjs/Schema/derivations.cjs +9 -6
  52. package/_cjs/Schema/derivations.cjs.map +1 -1
  53. package/_cjs/Schema.cjs +0 -11
  54. package/_cjs/Schema.cjs.map +1 -1
  55. package/_cjs/Show.cjs +2 -2
  56. package/_cjs/Show.cjs.map +1 -1
  57. package/_cjs/global.cjs +0 -4
  58. package/_cjs/index.cjs +0 -4
  59. package/_cjs/utils.cjs +2 -2
  60. package/_cjs/utils.cjs.map +1 -1
  61. package/_mjs/AST.mjs +3 -3
  62. package/_mjs/AST.mjs.map +1 -1
  63. package/_mjs/ASTAnnotation.mjs +5 -0
  64. package/_mjs/ASTAnnotation.mjs.map +1 -1
  65. package/_mjs/Eq.mjs +148 -0
  66. package/_mjs/Eq.mjs.map +1 -0
  67. package/_mjs/ParseError/ParseErrorFormatter.mjs +1 -1
  68. package/_mjs/Schema/derivations.mjs +8 -4
  69. package/_mjs/Schema/derivations.mjs.map +1 -1
  70. package/_mjs/Schema.mjs +0 -1
  71. package/_mjs/Schema.mjs.map +1 -1
  72. package/_mjs/Show.mjs +1 -0
  73. package/_mjs/Show.mjs.map +1 -1
  74. package/_mjs/global.mjs +1 -1
  75. package/_mjs/index.mjs +1 -1
  76. package/_mjs/utils.mjs +1 -0
  77. package/_mjs/utils.mjs.map +1 -1
  78. package/_src/AST.ts +5 -3
  79. package/_src/ASTAnnotation.ts +7 -0
  80. package/_src/Eq.ts +156 -0
  81. package/_src/Schema/derivations.ts +17 -6
  82. package/_src/Schema.ts +0 -1
  83. package/_src/Show.ts +4 -2
  84. package/_src/global.ts +4 -0
  85. package/_src/utils.ts +1 -0
  86. package/global.d.ts +4 -0
  87. package/package.json +3 -3
  88. package/Schema/api/immutableArray.d.ts +0 -22
  89. package/_cjs/Schema/api/immutableArray.cjs +0 -62
  90. package/_cjs/Schema/api/immutableArray.cjs.map +0 -1
  91. package/_mjs/Schema/api/immutableArray.mjs +0 -53
  92. package/_mjs/Schema/api/immutableArray.mjs.map +0 -1
  93. package/_src/Schema/api/immutableArray.ts +0 -58
package/_src/AST.ts CHANGED
@@ -693,7 +693,7 @@ export function createPropertySignature(
693
693
 
694
694
  export class IndexSignature {
695
695
  constructor(
696
- readonly parameter: StringKeyword | SymbolKeyword | TemplateLiteral | Refinement,
696
+ readonly parameter: StringKeyword | SymbolKeyword | TemplateLiteral | NumberKeyword | Refinement,
697
697
  readonly type: AST,
698
698
  readonly isReadonly: boolean,
699
699
  ) {}
@@ -703,7 +703,7 @@ export class IndexSignature {
703
703
  * @tsplus static fncts.schema.ASTOps createIndexSignature
704
704
  */
705
705
  export function createIndexSignature(
706
- parameter: StringKeyword | SymbolKeyword | TemplateLiteral | Refinement,
706
+ parameter: StringKeyword | SymbolKeyword | TemplateLiteral | NumberKeyword | Refinement,
707
707
  type: AST,
708
708
  isReadonly: boolean,
709
709
  ): IndexSignature {
@@ -1136,7 +1136,9 @@ export function appendElement(element: Element) {
1136
1136
  };
1137
1137
  }
1138
1138
 
1139
- export function getParameter(x: IndexSignature["parameter"]): StringKeyword | SymbolKeyword | TemplateLiteral {
1139
+ export function getParameter(
1140
+ x: IndexSignature["parameter"],
1141
+ ): StringKeyword | NumberKeyword | SymbolKeyword | TemplateLiteral {
1140
1142
  return isRefinement(x) ? getParameter(x.from as any) : x;
1141
1143
  }
1142
1144
 
@@ -107,3 +107,10 @@ export const GenHookTag = Tag<Hook<any>>();
107
107
  * @tsplus static fncts.schema.ASTAnnotationOps GenHook
108
108
  */
109
109
  export const GenHook = new ASTAnnotation(GenHookTag, "GenHook", (_, b) => b);
110
+
111
+ export const EqHookTag = Tag<Hook<Eq<any>>>();
112
+
113
+ /**
114
+ * @tsplus static fncts.schema.ASTAnnotationOps EqHook
115
+ */
116
+ export const EqHook = new ASTAnnotation(EqHookTag, "EqHook", (_, b) => b);
package/_src/Eq.ts ADDED
@@ -0,0 +1,156 @@
1
+ import { globalValue } from "@fncts/base/data/Global";
2
+
3
+ import { ASTTag } from "./AST.js";
4
+ import { getKeysForIndexSignature, memoize } from "./utils.js";
5
+
6
+ /**
7
+ * @tsplus getter fncts.schema.Schema equals
8
+ */
9
+ export function equals<A>(self: Schema<A>): (a: A, b: A) => boolean {
10
+ const eq = self.eq;
11
+ return (a, b) => eq.equals(b)(a);
12
+ }
13
+
14
+ /**
15
+ * @tsplus getter fncts.schema.Schema eq
16
+ */
17
+ export function eq<A>(self: Schema<A>): Eq<A> {
18
+ return goMemo(self.ast);
19
+ }
20
+
21
+ const eqMemoMap = globalValue(Symbol.for("fncts.schema.Eq.eqMemoMap"), () => new WeakMap<AST, Eq<any>>());
22
+
23
+ function goMemo(ast: AST): Eq<any> {
24
+ const memo = eqMemoMap.get(ast);
25
+ if (memo) {
26
+ return memo;
27
+ }
28
+ const eq = go(ast);
29
+ eqMemoMap.set(ast, eq);
30
+ return eq;
31
+ }
32
+
33
+ function go(ast: AST): Eq<any> {
34
+ AST.concrete(ast);
35
+ switch (ast._tag) {
36
+ case ASTTag.Declaration:
37
+ return ast.annotations
38
+ .get(ASTAnnotation.EqHook)
39
+ .map((eq) => eq(...ast.typeParameters.map(go)))
40
+ .getOrElse(Eq.strict);
41
+ case ASTTag.Literal:
42
+ case ASTTag.UniqueSymbol:
43
+ case ASTTag.UndefinedKeyword:
44
+ case ASTTag.VoidKeyword:
45
+ case ASTTag.UnknownKeyword:
46
+ case ASTTag.AnyKeyword:
47
+ case ASTTag.NumberKeyword:
48
+ case ASTTag.BooleanKeyword:
49
+ case ASTTag.BigIntKeyword:
50
+ case ASTTag.SymbolKeyword:
51
+ case ASTTag.ObjectKeyword:
52
+ case ASTTag.TemplateLiteral:
53
+ case ASTTag.StringKeyword:
54
+ return Eq.strict;
55
+ case ASTTag.NeverKeyword:
56
+ return Eq.never as Eq<any>;
57
+ case ASTTag.Tuple: {
58
+ const elements = ast.elements.map((element) => goMemo(element.type));
59
+ const rest = ast.rest.map((rest) => rest.map((ast) => goMemo(ast)));
60
+ return Eq<Array<any>>({
61
+ equals: (y) => (x) => {
62
+ if (x.length !== y.length) {
63
+ return false;
64
+ }
65
+
66
+ let i = 0;
67
+
68
+ for (; i < elements.length; i++) {
69
+ const eq = elements[i]!;
70
+ const xi = x[i];
71
+ const yi = y[i];
72
+ if (!eq.equals(yi)(xi)) {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ if (rest.isJust()) {
78
+ const head = rest.value.unsafeHead!;
79
+ const tail = rest.value.tail;
80
+ for (; i < x.length - tail.length; i++) {
81
+ if (!head.equals(y[i])(x[i])) {
82
+ return false;
83
+ }
84
+ }
85
+ for (let j = 0; j < tail.length; j++) {
86
+ i += j;
87
+ const eq = elements[i]!;
88
+ const xi = x[i];
89
+ const yi = y[i];
90
+ if (!eq.equals(yi)(xi)) {
91
+ return false;
92
+ }
93
+ }
94
+ }
95
+
96
+ return true;
97
+ },
98
+ });
99
+ }
100
+ case ASTTag.TypeLiteral: {
101
+ const propertySignatureTypes = ast.propertySignatures.map((ps) => go(ps.type));
102
+ const indexSignatures = ast.indexSignatures.map((is) => [go(is.parameter), go(is.type)] as const);
103
+ const requiredEqs: Record<PropertyKey, Eq<any>> = {};
104
+ const optionalEqs: Record<PropertyKey, Eq<any>> = {};
105
+ for (let i = 0; i < propertySignatureTypes.length; i++) {
106
+ const ps = ast.propertySignatures[i]!;
107
+ const name = ps.name;
108
+ if (!ps.isOptional) {
109
+ requiredEqs[name] = propertySignatureTypes[i]!;
110
+ } else {
111
+ optionalEqs[name] = propertySignatureTypes[i]!;
112
+ }
113
+ }
114
+ let output = Eq.struct(requiredEqs, optionalEqs);
115
+
116
+ for (let i = 0; i < indexSignatures.length; i++) {
117
+ const [, type] = indexSignatures[i]!;
118
+
119
+ output = output.intersection(
120
+ Eq<Record<PropertyKey, any>>({
121
+ equals: (y) => (x) => {
122
+ for (const key of getKeysForIndexSignature(x, ast.indexSignatures[i]!.parameter)) {
123
+ if (key in requiredEqs || key in optionalEqs) {
124
+ continue;
125
+ }
126
+ if (!type.equals(y[key])(x[key])) {
127
+ return false;
128
+ }
129
+ }
130
+
131
+ return true;
132
+ },
133
+ }),
134
+ );
135
+ }
136
+ return output;
137
+ }
138
+ case ASTTag.Union:
139
+ return Eq.union(ast.types.map(goMemo).toArray);
140
+ case ASTTag.Lazy: {
141
+ const f = () => goMemo(ast.getAST());
142
+ const get = memoize<typeof f, Eq<any>>(f);
143
+ return Eq({
144
+ equals: (y) => (x) => get(f).equals(y)(x),
145
+ });
146
+ }
147
+ case ASTTag.Enum:
148
+ return Eq.strict;
149
+ case ASTTag.Transform:
150
+ return goMemo(ast.to);
151
+ case ASTTag.Refinement:
152
+ return goMemo(ast.from);
153
+ case ASTTag.Validation:
154
+ return goMemo(ast.from);
155
+ }
156
+ }
@@ -1,4 +1,5 @@
1
1
  import type { TypeLiteral } from "@fncts/schema/AST";
2
+ import type { Union } from "@fncts/typelevel";
2
3
  import type { OptionalKeys, RequiredKeys } from "@fncts/typelevel/Object";
3
4
 
4
5
  import { ownKeys } from "@fncts/schema/utils";
@@ -36,11 +37,17 @@ export function deriveLiteral<A extends LiteralValue>(
36
37
 
37
38
  type MaybeKeys<A> = { [K in keyof A]: A[K] extends Maybe<any> ? K : never }[keyof A];
38
39
 
40
+ type IndexSignatures<A extends Record<PropertyKey, any>> = Union.ListOf<
41
+ {
42
+ [K in keyof A]: Check<Check.IsLiteral<K>> extends Check.True ? never : { key: Schema<K>; value: Schema<A[K]> };
43
+ }[keyof A]
44
+ >;
45
+
39
46
  /**
40
47
  * @tsplus derive fncts.schema.Schema<_> 20
41
48
  */
42
49
  export function deriveStruct<A extends Record<string, any>>(
43
- ...[requiredFields, optionalFields, maybeFields]: Check<Check.IsStruct<A>> extends Check.True
50
+ ...[requiredFields, optionalFields, maybeFields, indexSchema]: Check<Check.IsStruct<A>> extends Check.True
44
51
  ? [
45
52
  ...[
46
53
  requiredFields: {
@@ -55,12 +62,13 @@ export function deriveStruct<A extends Record<string, any>>(
55
62
  },
56
63
  ]),
57
64
  ...([MaybeKeys<A>] extends [never]
58
- ? []
65
+ ? [maybeFields: {}]
59
66
  : [
60
67
  maybeFields: {
61
68
  [k in MaybeKeys<A>]: [A[k]] extends [Maybe<infer _A>] ? Schema<_A> : never;
62
69
  },
63
70
  ]),
71
+ ...[indexSchema: IndexSignatures<A>],
64
72
  ]
65
73
  : never
66
74
  ): Schema<A> {
@@ -69,6 +77,9 @@ export function deriveStruct<A extends Record<string, any>>(
69
77
  // @ts-expect-error
70
78
  AST.createPropertySignature(key, requiredFields[key]!.ast, false, true),
71
79
  );
80
+ const indexSignatures = (indexSchema as ReadonlyArray<{ key: Schema<any>; value: Schema<any> }>).map(
81
+ ({ key, value }) => AST.createIndexSignature(key.ast as any, value.ast, false),
82
+ );
72
83
 
73
84
  if (optionalFields) {
74
85
  propertySignatures = propertySignatures.concat(
@@ -77,7 +88,7 @@ export function deriveStruct<A extends Record<string, any>>(
77
88
  );
78
89
  }
79
90
 
80
- const struct = Schema.fromAST(AST.createTypeLiteral(propertySignatures, Vector.empty()));
91
+ const struct = Schema.fromAST(AST.createTypeLiteral(propertySignatures, Vector.from(indexSignatures)));
81
92
 
82
93
  if (maybeFieldsKeys.isEmpty()) {
83
94
  return struct as Schema<any>;
@@ -98,7 +109,7 @@ export function deriveStruct<A extends Record<string, any>>(
98
109
  ),
99
110
  ),
100
111
  ),
101
- Vector.empty(),
112
+ Vector.from(indexSignatures),
102
113
  ),
103
114
  );
104
115
 
@@ -110,7 +121,7 @@ export function deriveStruct<A extends Record<string, any>>(
110
121
  AST.createPropertySignature(key, Schema.maybe(maybeFields![key]!).ast, false, true),
111
122
  ),
112
123
  ),
113
- Vector.empty(),
124
+ Vector.from(indexSignatures),
114
125
  ),
115
126
  );
116
127
 
@@ -141,7 +152,7 @@ export function deriveStruct<A extends Record<string, any>>(
141
152
  /**
142
153
  * @tsplus derive fncts.schema.Schema<_> 10
143
154
  */
144
- export function deriveTuple<A extends ReadonlyArray<unknown>>(
155
+ export function deriveTuple<A extends ReadonlyArray<any>>(
145
156
  ...[components]: Check<Check.IsTuple<A>> extends Check.True ? [components: { [K in keyof A]: Schema<A[K]> }] : never
146
157
  ): Schema<A> {
147
158
  return unsafeCoerce(Schema.tuple(...components));
package/_src/Schema.ts CHANGED
@@ -9,7 +9,6 @@ export * from "./Schema/api/conc.js";
9
9
  export * from "./Schema/api/either.js";
10
10
  export * from "./Schema/api/hashMap.js";
11
11
  export * from "./Schema/api/hashSet.js";
12
- export * from "./Schema/api/immutableArray.js";
13
12
  export * from "./Schema/api/list.js";
14
13
  export * from "./Schema/api/map.js";
15
14
  export * from "./Schema/api/maybe.js";
package/_src/Show.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  Element,
3
+ NumberKeyword,
3
4
  Refinement,
4
5
  StringKeyword,
5
6
  SymbolKeyword,
@@ -134,9 +135,10 @@ function formatElement(ast: Element, verbose: boolean): string {
134
135
  }
135
136
 
136
137
  function getParameterBase(
137
- self: StringKeyword | SymbolKeyword | TemplateLiteral | Refinement,
138
- ): StringKeyword | SymbolKeyword | TemplateLiteral {
138
+ self: StringKeyword | NumberKeyword | SymbolKeyword | TemplateLiteral | Refinement,
139
+ ): StringKeyword | SymbolKeyword | NumberKeyword | TemplateLiteral {
139
140
  switch (self._tag) {
141
+ case ASTTag.NumberKeyword:
140
142
  case ASTTag.StringKeyword:
141
143
  case ASTTag.SymbolKeyword:
142
144
  case ASTTag.TemplateLiteral:
package/_src/global.ts CHANGED
@@ -35,6 +35,10 @@ import { ASTAnnotation } from "@fncts/schema/ASTAnnotation";
35
35
  * @tsplus global
36
36
  */
37
37
  import { ASTAnnotationMap } from "@fncts/schema/ASTAnnotationMap";
38
+ /**
39
+ * @tsplus global
40
+ */
41
+ import {} from "@fncts/schema/Eq";
38
42
  /**
39
43
  * @tsplus global
40
44
  */
package/_src/utils.ts CHANGED
@@ -39,6 +39,7 @@ export function getKeysForIndexSignature(
39
39
  parameter: IndexSignature["parameter"],
40
40
  ): Vector<string> | Vector<symbol> {
41
41
  switch (parameter._tag) {
42
+ case ASTTag.NumberKeyword:
42
43
  case ASTTag.StringKeyword:
43
44
  case ASTTag.TemplateLiteral:
44
45
  return Vector.from(Object.keys(input));
package/global.d.ts CHANGED
@@ -34,6 +34,10 @@ import { ASTAnnotation } from "@fncts/schema/ASTAnnotation";
34
34
  * @tsplus global
35
35
  */
36
36
  import { ASTAnnotationMap } from "@fncts/schema/ASTAnnotationMap";
37
+ /**
38
+ * @tsplus global
39
+ */
40
+ import {} from "@fncts/schema/Eq";
37
41
  /**
38
42
  * @tsplus global
39
43
  */
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fncts/schema",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "dependencies": {
5
- "@fncts/base": "0.0.39",
6
- "@fncts/typelevel": "0.0.20"
5
+ "@fncts/base": "0.0.41",
6
+ "@fncts/typelevel": "0.0.22"
7
7
  },
8
8
  "exports": {
9
9
  "./*": {
@@ -1,22 +0,0 @@
1
- import { Schema } from "@fncts/schema/Schema/definition";
2
- import { Check } from "@fncts/typelevel";
3
- import { Parser } from "@fncts/schema/Parser/definition";
4
- import { Gen } from "@fncts/test/control/Gen";
5
- import { ImmutableArray } from "@fncts/base/collection/immutable/ImmutableArray";
6
- /**
7
- * @tsplus getter fncts.schema.Schema immutableArray
8
- * @tsplus static fncts.schema.SchemaOps immutableArray
9
- * @tsplus location "@fncts/schema/Schema/api/immutableArray"
10
- */
11
- export declare function immutableArray<A>(value: Schema<A>): Schema<ImmutableArray<A>>;
12
- /**
13
- * @tsplus getter fncts.schema.Schema immutableArrayFromArray
14
- * @tsplus static fncts.schema.SchemaOps immutableArrayFromArray
15
- * @tsplus location "@fncts/schema/Schema/api/immutableArray"
16
- */
17
- export declare function immutableArrayFromArray<A>(value: Schema<A>): Schema<ImmutableArray<A>>;
18
- /**
19
- * @tsplus derive fncts.schema.Schema[fncts.ImmutableArray]<_> 10
20
- * @tsplus location "@fncts/schema/Schema/api/immutableArray"
21
- */
22
- export declare function deriveImmutableArray<A extends ImmutableArray<any>>(...[value]: [A] extends [ImmutableArray<infer _A>] ? Check<Check.IsEqual<A, ImmutableArray<_A>>> extends Check.True ? [value: Schema<_A>] : never : never): Schema<A>;
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.deriveImmutableArray = deriveImmutableArray;
7
- exports.immutableArrayFromArray = exports.immutableArray = void 0;
8
- var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/schema/ASTAnnotation"));
9
- var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/schema/Show"));
10
- var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/base/collection/immutable/Vector/api"));
11
- var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/schema/Schema/api"));
12
- var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/base/data/function/api"));
13
- var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/schema/Parser/api"));
14
- var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/base/collection/immutable/ImmutableArray/definition"));
15
- var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/schema/ParseError/ParseError"));
16
- var tsplus_module_9 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/schema/ParseResult"));
17
- var tsplus_module_10 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/base/data/Either/api"));
18
- var tsplus_module_11 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/schema/Parser/definition"));
19
- var tsplus_module_12 = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@fncts/test/control/Gen/api"));
20
- var _ImmutableArray = /*#__PURE__*/require("@fncts/base/collection/immutable/ImmutableArray");
21
- var _Vector = /*#__PURE__*/require("@fncts/base/collection/immutable/Vector");
22
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
23
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
24
- const immutableArray = exports.immutableArray = immutableArray_1;
25
- const immutableArrayFromArray = exports.immutableArrayFromArray = immutableArrayFromArray_1;
26
- /**
27
- * @tsplus getter fncts.schema.Schema immutableArray
28
- * @tsplus static fncts.schema.SchemaOps immutableArray
29
- */
30
- function immutableArray_1(value) {
31
- return tsplus_module_4.annotate(tsplus_module_1.GenHook, gen)(tsplus_module_4.annotate(tsplus_module_1.Identifier, `ImmutableArray<${tsplus_module_2.show()(value)}>`)(tsplus_module_4.declaration(tsplus_module_3.vector(value), parser(true), parser(false))));
32
- }
33
- /**
34
- * @tsplus getter fncts.schema.Schema immutableArrayFromArray
35
- * @tsplus static fncts.schema.SchemaOps immutableArrayFromArray
36
- */
37
- function immutableArrayFromArray_1(value) {
38
- return tsplus_module_4.transform(immutableArray_1(value), input => new _ImmutableArray.ImmutableArray(input), input => input._array)(tsplus_module_4.array(value));
39
- }
40
- /**
41
- * @tsplus derive fncts.schema.Schema[fncts.ImmutableArray]<_> 10
42
- */
43
- function deriveImmutableArray(...[value]) {
44
- return immutableArrayFromArray_1(value);
45
- }
46
- function parser(isDecoding) {
47
- return value => {
48
- const schema = immutableArray_1(value);
49
- const arraySchema = tsplus_module_4.array(value);
50
- const parse = isDecoding ? tsplus_module_6.decode(arraySchema) : tsplus_module_6.encode(arraySchema);
51
- return tsplus_module_11.make((u, options) => {
52
- if (!tsplus_module_7.isImmutableArray(u)) {
53
- return tsplus_module_9.fail(tsplus_module_8.typeError(schema.ast, u));
54
- }
55
- return tsplus_module_10.map(out => new _ImmutableArray.ImmutableArray(out))(parse(u, options));
56
- });
57
- };
58
- }
59
- function gen(value) {
60
- return tsplus_module_12.map(array => new _ImmutableArray.ImmutableArray(array))(tsplus_module_12.array(value));
61
- }
62
- //# sourceMappingURL=immutableArray.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"immutableArray.cjs","names":["_ImmutableArray","require","_Vector","_getRequireWildcardCache","e","WeakMap","r","t","_interopRequireWildcard","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","immutableArray","exports","immutableArray_1","immutableArrayFromArray","immutableArrayFromArray_1","value","tsplus_module_4","annotate","tsplus_module_1","GenHook","gen","Identifier","tsplus_module_2","show","declaration","tsplus_module_3","vector","parser","transform","input","ImmutableArray","_array","array","deriveImmutableArray","isDecoding","schema","arraySchema","parse","tsplus_module_6","decode","encode","tsplus_module_11","make","options","tsplus_module_7","isImmutableArray","tsplus_module_9","fail","tsplus_module_8","typeError","ast","tsplus_module_10","map","out","tsplus_module_12"],"sources":["../../../_src/Schema/api/immutableArray.ts"],"sourcesContent":[null],"mappings":"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","ignoreList":[]}
@@ -1,53 +0,0 @@
1
- import * as tsplus_module_1 from "@fncts/schema/ASTAnnotation";
2
- import * as tsplus_module_2 from "@fncts/schema/Show";
3
- import * as tsplus_module_3 from "@fncts/base/collection/immutable/Vector/api";
4
- import * as tsplus_module_4 from "@fncts/schema/Schema/api";
5
- import * as tsplus_module_5 from "@fncts/base/data/function/api";
6
- import * as tsplus_module_6 from "@fncts/schema/Parser/api";
7
- import * as tsplus_module_7 from "@fncts/base/collection/immutable/ImmutableArray/definition";
8
- import * as tsplus_module_8 from "@fncts/schema/ParseError/ParseError";
9
- import * as tsplus_module_9 from "@fncts/schema/ParseResult";
10
- import * as tsplus_module_10 from "@fncts/base/data/Either/api";
11
- import * as tsplus_module_11 from "@fncts/schema/Parser/definition";
12
- import * as tsplus_module_12 from "@fncts/test/control/Gen/api";
13
- export const immutableArray = immutableArray_1;
14
- export const immutableArrayFromArray = immutableArrayFromArray_1;
15
- import { ImmutableArray } from "@fncts/base/collection/immutable/ImmutableArray";
16
- import { Vector } from "@fncts/base/collection/immutable/Vector";
17
- /**
18
- * @tsplus getter fncts.schema.Schema immutableArray
19
- * @tsplus static fncts.schema.SchemaOps immutableArray
20
- */
21
- function immutableArray_1(value) {
22
- return tsplus_module_4.annotate(tsplus_module_1.GenHook, gen)(tsplus_module_4.annotate(tsplus_module_1.Identifier, `ImmutableArray<${tsplus_module_2.show()(value)}>`)(tsplus_module_4.declaration(tsplus_module_3.vector(value), parser(true), parser(false))));
23
- }
24
- /**
25
- * @tsplus getter fncts.schema.Schema immutableArrayFromArray
26
- * @tsplus static fncts.schema.SchemaOps immutableArrayFromArray
27
- */
28
- function immutableArrayFromArray_1(value) {
29
- return tsplus_module_4.transform(immutableArray_1(value), input => new ImmutableArray(input), input => input._array)(tsplus_module_4.array(value));
30
- }
31
- /**
32
- * @tsplus derive fncts.schema.Schema[fncts.ImmutableArray]<_> 10
33
- */
34
- export function deriveImmutableArray(...[value]) {
35
- return immutableArrayFromArray_1(value);
36
- }
37
- function parser(isDecoding) {
38
- return value => {
39
- const schema = immutableArray_1(value);
40
- const arraySchema = tsplus_module_4.array(value);
41
- const parse = isDecoding ? tsplus_module_6.decode(arraySchema) : tsplus_module_6.encode(arraySchema);
42
- return tsplus_module_11.make((u, options) => {
43
- if (!tsplus_module_7.isImmutableArray(u)) {
44
- return tsplus_module_9.fail(tsplus_module_8.typeError(schema.ast, u));
45
- }
46
- return tsplus_module_10.map(out => new ImmutableArray(out))(parse(u, options));
47
- });
48
- };
49
- }
50
- function gen(value) {
51
- return tsplus_module_12.map(array => new ImmutableArray(array))(tsplus_module_12.array(value));
52
- }
53
- //# sourceMappingURL=immutableArray.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"immutableArray.mjs","names":["immutableArray","immutableArray_1","immutableArrayFromArray","immutableArrayFromArray_1","ImmutableArray","Vector","value","tsplus_module_4","annotate","tsplus_module_1","GenHook","gen","Identifier","tsplus_module_2","show","declaration","tsplus_module_3","vector","parser","transform","input","_array","array","deriveImmutableArray","isDecoding","schema","arraySchema","parse","tsplus_module_6","decode","encode","tsplus_module_11","make","u","options","tsplus_module_7","isImmutableArray","tsplus_module_9","fail","tsplus_module_8","typeError","ast","tsplus_module_10","map","out","tsplus_module_12"],"sources":["../../../_src/Schema/api/immutableArray.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;aASgBA,cAAc,GAAAC,gBAAA;aAUdC,uBAAuB,GAAAC,yBAAA;AAjBvC,SAASC,cAAc,QAAQ,iDAAiD;AAChF,SAASC,MAAM,QAAQ,yCAAyC;AAEhE;;;;AAIA,SAAAJ,iBAAkCK,KAAgB;EAChD,OAAOC,eAAA,CAAAC,QAAA,CAAAC,eAAA,CAAAC,OAAA,EAE4BC,GAAG,EAF/BJ,eAAA,CAAAC,QAAA,CAAAC,eAAA,CAAAG,UAAA,EAC+B,kBAAkBC,eAAA,CAAAC,IAAA,GAAAR,KAAK,CAAO,GAAG,EADhEC,eAAA,CAAAQ,WAAA,CAAmBC,eAAA,CAAAC,MAAA,CAAOX,KAAK,CAAC,EAAEY,MAAM,CAAC,IAAI,CAAC,EAAEA,MAAM,CAAC,KAAK,CAAC,CAAC,CACG,CACjC;AACzC;AAEA;;;;AAIA,SAAAf,0BAA2CG,KAAgB;EACzD,OAAOC,eAAA,CAAAY,SAAA,CACLlB,gBAAA,CAAeK,KAAK,CAAC,EACpBc,KAAK,IAAK,IAAIhB,cAAc,CAACgB,KAAK,CAAC,EACnCA,KAAK,IAAKA,KAAK,CAACC,MAAM,EAHlBd,eAAA,CAAAe,KAAA,CAAahB,KAAK,CAAC,CAIzB;AACH;AAEA;;;AAGA,OAAM,SAAUiB,oBAAoBA,CAClC,GAAG,CAACjB,KAAK,CAIA;EAET,OAAoBH,yBAAA,CAAwBG,KAAK,CAAC;AACpD;AAEA,SAASY,MAAMA,CAACM,UAAmB;EACjC,OAAWlB,KAAgB,IAAqC;IAC9D,MAAMmB,MAAM,GAAQxB,gBAAA,CAAeK,KAAK,CAAC;IACzC,MAAMoB,WAAW,GAAAnB,eAAA,CAAAe,KAAA,CAAGhB,KAAK,CAAM;IAC/B,MAAMqB,KAAK,GAASH,UAAU,GAAEI,eAAA,CAAAC,MAAA,CAACH,WAAW,IAASE,eAAA,CAAAE,MAAA,CAACJ,WAAW,CAAO;IACxE,OAAOK,gBAAA,CAAAC,IAAA,CAAY,CAACC,CAAC,EAAEC,OAAO,KAAI;MAChC,IAAI,CAACC,eAAA,CAAAC,gBAAA,CAAkBH,CAAC,CAAC,EAAE;QACzB,OAAOI,eAAA,CAAAC,IAAA,CAAiBC,eAAA,CAAAC,SAAA,CAAqBf,MAAM,CAACgB,GAAG,EAAER,CAAC,CAAC,CAAC;MAC9D;MAEA,OAAOS,gBAAA,CAAAC,GAAA,CAAuBC,GAAG,IAAK,IAAIxC,cAAc,CAACwC,GAAqB,CAAC,EAAxEjB,KAAK,CAACM,CAAC,EAAEC,OAAO,CAAC,CAAwD;IAClF,CAAC,CAAC;EACJ,CAAC;AACH;AAEA,SAASvB,GAAGA,CAAIL,KAAoB;EAClC,OAAOuC,gBAAA,CAAAF,GAAA,CAAsBrB,KAAK,IAAK,IAAIlB,cAAc,CAACkB,KAAK,CAAC,EAAzDuB,gBAAA,CAAAvB,KAAA,CAAUhB,KAAK,CAAC,CAA0C;AACnE","ignoreList":[]}
@@ -1,58 +0,0 @@
1
- import type { Sized } from "@fncts/test/control/Sized";
2
-
3
- import { ImmutableArray } from "@fncts/base/collection/immutable/ImmutableArray";
4
- import { Vector } from "@fncts/base/collection/immutable/Vector";
5
-
6
- /**
7
- * @tsplus getter fncts.schema.Schema immutableArray
8
- * @tsplus static fncts.schema.SchemaOps immutableArray
9
- */
10
- export function immutableArray<A>(value: Schema<A>): Schema<ImmutableArray<A>> {
11
- return Schema.declaration(Vector(value), parser(true), parser(false))
12
- .annotate(ASTAnnotation.Identifier, `ImmutableArray<${value.show()}>`)
13
- .annotate(ASTAnnotation.GenHook, gen);
14
- }
15
-
16
- /**
17
- * @tsplus getter fncts.schema.Schema immutableArrayFromArray
18
- * @tsplus static fncts.schema.SchemaOps immutableArrayFromArray
19
- */
20
- export function immutableArrayFromArray<A>(value: Schema<A>): Schema<ImmutableArray<A>> {
21
- return Schema.array(value).transform(
22
- immutableArray(value),
23
- (input) => new ImmutableArray(input),
24
- (input) => input._array,
25
- );
26
- }
27
-
28
- /**
29
- * @tsplus derive fncts.schema.Schema[fncts.ImmutableArray]<_> 10
30
- */
31
- export function deriveImmutableArray<A extends ImmutableArray<any>>(
32
- ...[value]: [A] extends [ImmutableArray<infer _A>]
33
- ? Check<Check.IsEqual<A, ImmutableArray<_A>>> extends Check.True
34
- ? [value: Schema<_A>]
35
- : never
36
- : never
37
- ): Schema<A> {
38
- return unsafeCoerce(immutableArrayFromArray(value));
39
- }
40
-
41
- function parser(isDecoding: boolean) {
42
- return <A>(value: Schema<A>): Parser<ImmutableArray<unknown>> => {
43
- const schema = immutableArray(value);
44
- const arraySchema = value.array;
45
- const parse = isDecoding ? arraySchema.decode : arraySchema.encode;
46
- return Parser.make((u, options) => {
47
- if (!ImmutableArray.is(u)) {
48
- return ParseResult.fail(ParseError.TypeError(schema.ast, u));
49
- }
50
-
51
- return parse(u, options).map((out) => new ImmutableArray(out as Array<unknown>));
52
- });
53
- };
54
- }
55
-
56
- function gen<A>(value: Gen<Sized, A>): Gen<Sized, ImmutableArray<A>> {
57
- return Gen.array(value).map((array) => new ImmutableArray(array));
58
- }