effect 3.9.2 → 3.10.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.
- package/Arbitrary/package.json +6 -0
- package/FastCheck/package.json +6 -0
- package/JSONSchema/package.json +6 -0
- package/ParseResult/package.json +6 -0
- package/Pretty/package.json +6 -0
- package/Schema/package.json +6 -0
- package/SchemaAST/package.json +6 -0
- package/TSubscriptionRef/package.json +6 -0
- package/dist/cjs/Arbitrary.js +490 -0
- package/dist/cjs/Arbitrary.js.map +1 -0
- package/dist/cjs/Effect.js +247 -16
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/FastCheck.js +17 -0
- package/dist/cjs/FastCheck.js.map +1 -0
- package/dist/cjs/Inspectable.js +43 -3
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/JSONSchema.js +418 -0
- package/dist/cjs/JSONSchema.js.map +1 -0
- package/dist/cjs/ParseResult.js +1539 -0
- package/dist/cjs/ParseResult.js.map +1 -0
- package/dist/cjs/Predicate.js +3 -1
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Pretty.js +183 -0
- package/dist/cjs/Pretty.js.map +1 -0
- package/dist/cjs/Schema.js +5529 -0
- package/dist/cjs/Schema.js.map +1 -0
- package/dist/cjs/SchemaAST.js +2365 -0
- package/dist/cjs/SchemaAST.js.map +1 -0
- package/dist/cjs/Stream.js +17 -3
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/TPubSub.js +9 -1
- package/dist/cjs/TPubSub.js.map +1 -1
- package/dist/cjs/TQueue.js.map +1 -1
- package/dist/cjs/TRef.js.map +1 -1
- package/dist/cjs/TSubscriptionRef.js +96 -0
- package/dist/cjs/TSubscriptionRef.js.map +1 -0
- package/dist/cjs/index.js +18 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/cause.js +2 -2
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/channel/channelExecutor.js +160 -161
- package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
- package/dist/cjs/internal/core.js +4 -4
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +14 -12
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/logger.js +7 -6
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/redacted.js +4 -0
- package/dist/cjs/internal/redacted.js.map +1 -1
- package/dist/cjs/internal/schema/errors.js +116 -0
- package/dist/cjs/internal/schema/errors.js.map +1 -0
- package/dist/cjs/internal/schema/filters.js +41 -0
- package/dist/cjs/internal/schema/filters.js.map +1 -0
- package/dist/cjs/internal/schema/util.js +96 -0
- package/dist/cjs/internal/schema/util.js.map +1 -0
- package/dist/cjs/internal/stm/core.js +2 -3
- package/dist/cjs/internal/stm/core.js.map +1 -1
- package/dist/cjs/internal/stm/tPubSub.js.map +1 -1
- package/dist/cjs/internal/stm/tQueue.js +1 -2
- package/dist/cjs/internal/stm/tQueue.js.map +1 -1
- package/dist/cjs/internal/stm/tRef.js +6 -2
- package/dist/cjs/internal/stm/tRef.js.map +1 -1
- package/dist/cjs/internal/stm/tSubscriptionRef.js +178 -0
- package/dist/cjs/internal/stm/tSubscriptionRef.js.map +1 -0
- package/dist/cjs/internal/stream.js +36 -16
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/Arbitrary.d.ts +45 -0
- package/dist/dts/Arbitrary.d.ts.map +1 -0
- package/dist/dts/Effect.d.ts +298 -30
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/FastCheck.d.ts +9 -0
- package/dist/dts/FastCheck.d.ts.map +1 -0
- package/dist/dts/Inspectable.d.ts +28 -0
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/JSONSchema.d.ts +181 -0
- package/dist/dts/JSONSchema.d.ts.map +1 -0
- package/dist/dts/ParseResult.d.ts +551 -0
- package/dist/dts/ParseResult.d.ts.map +1 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Pretty.d.ts +26 -0
- package/dist/dts/Pretty.d.ts.map +1 -0
- package/dist/dts/Schema.d.ts +4562 -0
- package/dist/dts/Schema.d.ts.map +1 -0
- package/dist/dts/SchemaAST.d.ts +1321 -0
- package/dist/dts/SchemaAST.d.ts.map +1 -0
- package/dist/dts/Stream.d.ts +67 -2
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/TPubSub.d.ts +8 -0
- package/dist/dts/TPubSub.d.ts.map +1 -1
- package/dist/dts/TQueue.d.ts +7 -7
- package/dist/dts/TQueue.d.ts.map +1 -1
- package/dist/dts/TRef.d.ts +2 -1
- package/dist/dts/TRef.d.ts.map +1 -1
- package/dist/dts/TSubscriptionRef.d.ts +251 -0
- package/dist/dts/TSubscriptionRef.d.ts.map +1 -0
- package/dist/dts/index.d.ts +32 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/dts/internal/schema/errors.d.ts +2 -0
- package/dist/dts/internal/schema/errors.d.ts.map +1 -0
- package/dist/dts/internal/schema/filters.d.ts +2 -0
- package/dist/dts/internal/schema/filters.d.ts.map +1 -0
- package/dist/dts/internal/schema/util.d.ts +2 -0
- package/dist/dts/internal/schema/util.d.ts.map +1 -0
- package/dist/dts/internal/stm/tRef.d.ts +3 -1
- package/dist/dts/internal/stm/tRef.d.ts.map +1 -1
- package/dist/dts/internal/stm/tSubscriptionRef.d.ts +2 -0
- package/dist/dts/internal/stm/tSubscriptionRef.d.ts.map +1 -0
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Arbitrary.js +472 -0
- package/dist/esm/Arbitrary.js.map +1 -0
- package/dist/esm/Effect.js +256 -18
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/FastCheck.js +9 -0
- package/dist/esm/FastCheck.js.map +1 -0
- package/dist/esm/Inspectable.js +39 -2
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/JSONSchema.js +408 -0
- package/dist/esm/JSONSchema.js.map +1 -0
- package/dist/esm/ParseResult.js +1503 -0
- package/dist/esm/ParseResult.js.map +1 -0
- package/dist/esm/Predicate.js +2 -1
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Pretty.js +173 -0
- package/dist/esm/Pretty.js.map +1 -0
- package/dist/esm/Schema.js +5328 -0
- package/dist/esm/Schema.js.map +1 -0
- package/dist/esm/SchemaAST.js +2300 -0
- package/dist/esm/SchemaAST.js.map +1 -0
- package/dist/esm/Stream.js +14 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/TPubSub.js +8 -0
- package/dist/esm/TPubSub.js.map +1 -1
- package/dist/esm/TQueue.js.map +1 -1
- package/dist/esm/TRef.js.map +1 -1
- package/dist/esm/TSubscriptionRef.js +87 -0
- package/dist/esm/TSubscriptionRef.js.map +1 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/cause.js +3 -3
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/channel/channelExecutor.js +160 -161
- package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
- package/dist/esm/internal/core.js +4 -4
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +14 -12
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/logger.js +7 -6
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/redacted.js +4 -0
- package/dist/esm/internal/redacted.js.map +1 -1
- package/dist/esm/internal/schema/errors.js +87 -0
- package/dist/esm/internal/schema/errors.js.map +1 -0
- package/dist/esm/internal/schema/filters.js +35 -0
- package/dist/esm/internal/schema/filters.js.map +1 -0
- package/dist/esm/internal/schema/util.js +78 -0
- package/dist/esm/internal/schema/util.js.map +1 -0
- package/dist/esm/internal/stm/core.js +1 -2
- package/dist/esm/internal/stm/core.js.map +1 -1
- package/dist/esm/internal/stm/tPubSub.js.map +1 -1
- package/dist/esm/internal/stm/tQueue.js +1 -2
- package/dist/esm/internal/stm/tQueue.js.map +1 -1
- package/dist/esm/internal/stm/tRef.js +5 -1
- package/dist/esm/internal/stm/tRef.js.map +1 -1
- package/dist/esm/internal/stm/tSubscriptionRef.js +166 -0
- package/dist/esm/internal/stm/tSubscriptionRef.js.map +1 -0
- package/dist/esm/internal/stream.js +33 -15
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +68 -1
- package/src/Arbitrary.ts +563 -0
- package/src/Effect.ts +302 -31
- package/src/FastCheck.ts +9 -0
- package/src/Inspectable.ts +56 -2
- package/src/JSONSchema.ts +601 -0
- package/src/ParseResult.ts +2027 -0
- package/src/Predicate.ts +3 -1
- package/src/Pretty.ts +204 -0
- package/src/Schema.ts +10388 -0
- package/src/SchemaAST.ts +2827 -0
- package/src/Stream.ts +77 -9
- package/src/TPubSub.ts +9 -0
- package/src/TQueue.ts +7 -7
- package/src/TRef.ts +2 -1
- package/src/TSubscriptionRef.ts +284 -0
- package/src/index.ts +40 -0
- package/src/internal/cause.ts +3 -3
- package/src/internal/channel/channelExecutor.ts +213 -214
- package/src/internal/core-effect.ts +2 -2
- package/src/internal/core.ts +4 -4
- package/src/internal/fiberRuntime.ts +14 -12
- package/src/internal/logger.ts +7 -6
- package/src/internal/redacted.ts +4 -0
- package/src/internal/schema/errors.ts +189 -0
- package/src/internal/schema/filters.ts +86 -0
- package/src/internal/schema/util.ts +113 -0
- package/src/internal/stm/core.ts +1 -2
- package/src/internal/stm/tPubSub.ts +1 -0
- package/src/internal/stm/tQueue.ts +2 -2
- package/src/internal/stm/tRef.ts +7 -2
- package/src/internal/stm/tSubscriptionRef.ts +286 -0
- package/src/internal/stream.ts +97 -20
- package/src/internal/version.ts +1 -1
|
@@ -0,0 +1,2365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isLiteral = exports.isFinalTransformation = exports.isEnums = exports.isDeclaration = exports.isComposeTransformation = exports.isBooleanKeyword = exports.isBigIntKeyword = exports.isAnyKeyword = exports.hasStableFilter = exports.getTitleAnnotation = exports.getTemplateLiteralRegExp = exports.getTemplateLiteralCapturingRegExp = exports.getSurrogateAnnotation = exports.getPropertySignatures = exports.getPropertyKeyIndexedAccess = exports.getParseOptionsAnnotation = exports.getParseIssueTitleAnnotation = exports.getParameterBase = exports.getNumberIndexedAccess = exports.getMissingMessageAnnotation = exports.getMessageAnnotation = exports.getJSONSchemaAnnotation = exports.getJSONIdentifierAnnotation = exports.getJSONIdentifier = exports.getIdentifierAnnotation = exports.getExamplesAnnotation = exports.getDocumentationAnnotation = exports.getDescriptionAnnotation = exports.getDefaultAnnotation = exports.getDecodingFallbackAnnotation = exports.getConcurrencyAnnotation = exports.getCompiler = exports.getBrandAnnotation = exports.getBatchingAnnotation = exports.getAnnotation = exports.flatten = exports.encodedBoundAST = exports.encodedAST = exports.defaultParseOption = exports.composeTransformation = exports.compose = exports.booleanKeyword = exports.blackListAnnotations = exports.bigIntKeyword = exports.anyKeyword = exports.annotations = exports.VoidKeyword = exports.UnknownKeyword = exports.UniqueSymbol = exports.Union = exports.UndefinedKeyword = exports.TypeLiteralTransformation = exports.TypeLiteral = exports.Type = exports.TupleType = exports.Transformation = exports.TitleAnnotationId = exports.TemplateLiteralSpan = exports.TemplateLiteral = exports.SymbolKeyword = exports.Suspend = exports.SurrogateAnnotationId = exports.StringKeyword = exports.StableFilterAnnotationId = exports.SchemaIdAnnotationId = exports.Refinement = exports.PropertySignatureTransformation = exports.PropertySignature = exports.PrettyAnnotationId = exports.ParseOptionsAnnotationId = exports.ParseJsonSchemaId = exports.ParseIssueTitleAnnotationId = exports.OptionalType = exports.ObjectKeyword = exports.NumberKeyword = exports.NeverKeyword = exports.MissingMessageAnnotationId = exports.MessageAnnotationId = exports.Literal = exports.JSONSchemaAnnotationId = exports.JSONIdentifierAnnotationId = exports.IndexSignature = exports.IdentifierAnnotationId = exports.FinalTransformation = exports.ExamplesAnnotationId = exports.EquivalenceAnnotationId = exports.Enums = exports.DocumentationAnnotationId = exports.DescriptionAnnotationId = exports.DefaultAnnotationId = exports.DecodingFallbackAnnotationId = exports.Declaration = exports.ConcurrencyAnnotationId = exports.ComposeTransformation = exports.BrandAnnotationId = exports.BooleanKeyword = exports.BigIntKeyword = exports.BatchingAnnotationId = exports.ArbitraryAnnotationId = exports.AnyKeyword = void 0;
|
|
7
|
+
exports.whiteListAnnotations = exports.voidKeyword = exports.unknownKeyword = exports.unify = exports.undefinedKeyword = exports.typeAST = exports.symbolKeyword = exports.stringKeyword = exports.required = exports.rename = exports.record = exports.pick = exports.partial = exports.orUndefined = exports.omit = exports.objectKeyword = exports.numberKeyword = exports.null = exports.neverKeyword = exports.mutable = exports.mapMembers = exports.keyof = exports.isVoidKeyword = exports.isUnknownKeyword = exports.isUniqueSymbol = exports.isUnion = exports.isUndefinedKeyword = exports.isTypeLiteralTransformation = exports.isTypeLiteral = exports.isTupleType = exports.isTransformation = exports.isTemplateLiteral = exports.isSymbolKeyword = exports.isSuspend = exports.isStringKeyword = exports.isRefinement = exports.isParameter = exports.isObjectKeyword = exports.isNumberKeyword = exports.isNeverKeyword = exports.isMembers = void 0;
|
|
8
|
+
var Arr = _interopRequireWildcard(require("./Array.js"));
|
|
9
|
+
var _Function = require("./Function.js");
|
|
10
|
+
var _GlobalValue = require("./GlobalValue.js");
|
|
11
|
+
var errors_ = _interopRequireWildcard(require("./internal/schema/errors.js"));
|
|
12
|
+
var util_ = _interopRequireWildcard(require("./internal/schema/util.js"));
|
|
13
|
+
var Number = _interopRequireWildcard(require("./Number.js"));
|
|
14
|
+
var Option = _interopRequireWildcard(require("./Option.js"));
|
|
15
|
+
var Order = _interopRequireWildcard(require("./Order.js"));
|
|
16
|
+
var Predicate = _interopRequireWildcard(require("./Predicate.js"));
|
|
17
|
+
var regexp = _interopRequireWildcard(require("./RegExp.js"));
|
|
18
|
+
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); }
|
|
19
|
+
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; }
|
|
20
|
+
/**
|
|
21
|
+
* @since 3.10.0
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @category annotations
|
|
26
|
+
* @since 3.10.0
|
|
27
|
+
*/
|
|
28
|
+
const BrandAnnotationId = exports.BrandAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Brand");
|
|
29
|
+
/**
|
|
30
|
+
* @category annotations
|
|
31
|
+
* @since 3.10.0
|
|
32
|
+
*/
|
|
33
|
+
const SchemaIdAnnotationId = exports.SchemaIdAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/SchemaId");
|
|
34
|
+
/**
|
|
35
|
+
* @category annotations
|
|
36
|
+
* @since 3.10.0
|
|
37
|
+
*/
|
|
38
|
+
const MessageAnnotationId = exports.MessageAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Message");
|
|
39
|
+
/**
|
|
40
|
+
* @category annotations
|
|
41
|
+
* @since 3.10.0
|
|
42
|
+
*/
|
|
43
|
+
const MissingMessageAnnotationId = exports.MissingMessageAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/MissingMessage");
|
|
44
|
+
/**
|
|
45
|
+
* @category annotations
|
|
46
|
+
* @since 3.10.0
|
|
47
|
+
*/
|
|
48
|
+
const IdentifierAnnotationId = exports.IdentifierAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Identifier");
|
|
49
|
+
/**
|
|
50
|
+
* @category annotations
|
|
51
|
+
* @since 3.10.0
|
|
52
|
+
*/
|
|
53
|
+
const TitleAnnotationId = exports.TitleAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Title");
|
|
54
|
+
/**
|
|
55
|
+
* @category annotations
|
|
56
|
+
* @since 3.10.0
|
|
57
|
+
*/
|
|
58
|
+
const DescriptionAnnotationId = exports.DescriptionAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Description");
|
|
59
|
+
/**
|
|
60
|
+
* @category annotations
|
|
61
|
+
* @since 3.10.0
|
|
62
|
+
*/
|
|
63
|
+
const ExamplesAnnotationId = exports.ExamplesAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Examples");
|
|
64
|
+
/**
|
|
65
|
+
* @category annotations
|
|
66
|
+
* @since 3.10.0
|
|
67
|
+
*/
|
|
68
|
+
const DefaultAnnotationId = exports.DefaultAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Default");
|
|
69
|
+
/**
|
|
70
|
+
* @category annotations
|
|
71
|
+
* @since 3.10.0
|
|
72
|
+
*/
|
|
73
|
+
const JSONSchemaAnnotationId = exports.JSONSchemaAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/JSONSchema");
|
|
74
|
+
/**
|
|
75
|
+
* @category annotations
|
|
76
|
+
* @since 3.10.0
|
|
77
|
+
*/
|
|
78
|
+
const ArbitraryAnnotationId = exports.ArbitraryAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Arbitrary");
|
|
79
|
+
/**
|
|
80
|
+
* @category annotations
|
|
81
|
+
* @since 3.10.0
|
|
82
|
+
*/
|
|
83
|
+
const PrettyAnnotationId = exports.PrettyAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Pretty");
|
|
84
|
+
/**
|
|
85
|
+
* @category annotations
|
|
86
|
+
* @since 3.10.0
|
|
87
|
+
*/
|
|
88
|
+
const EquivalenceAnnotationId = exports.EquivalenceAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Equivalence");
|
|
89
|
+
/**
|
|
90
|
+
* @category annotations
|
|
91
|
+
* @since 3.10.0
|
|
92
|
+
*/
|
|
93
|
+
const DocumentationAnnotationId = exports.DocumentationAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Documentation");
|
|
94
|
+
/**
|
|
95
|
+
* @category annotations
|
|
96
|
+
* @since 3.10.0
|
|
97
|
+
*/
|
|
98
|
+
const ConcurrencyAnnotationId = exports.ConcurrencyAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Concurrency");
|
|
99
|
+
/**
|
|
100
|
+
* @category annotations
|
|
101
|
+
* @since 3.10.0
|
|
102
|
+
*/
|
|
103
|
+
const BatchingAnnotationId = exports.BatchingAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Batching");
|
|
104
|
+
/**
|
|
105
|
+
* @category annotations
|
|
106
|
+
* @since 3.10.0
|
|
107
|
+
*/
|
|
108
|
+
const ParseIssueTitleAnnotationId = exports.ParseIssueTitleAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/ParseIssueTitle");
|
|
109
|
+
/**
|
|
110
|
+
* @category annotations
|
|
111
|
+
* @since 3.10.0
|
|
112
|
+
*/
|
|
113
|
+
const ParseOptionsAnnotationId = exports.ParseOptionsAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/ParseOptions");
|
|
114
|
+
/**
|
|
115
|
+
* @category annotations
|
|
116
|
+
* @since 3.10.0
|
|
117
|
+
*/
|
|
118
|
+
const DecodingFallbackAnnotationId = exports.DecodingFallbackAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/DecodingFallback");
|
|
119
|
+
/**
|
|
120
|
+
* @category annotations
|
|
121
|
+
* @since 3.10.0
|
|
122
|
+
*/
|
|
123
|
+
const SurrogateAnnotationId = exports.SurrogateAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/Surrogate");
|
|
124
|
+
/** @internal */
|
|
125
|
+
const StableFilterAnnotationId = exports.StableFilterAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/StableFilter");
|
|
126
|
+
/**
|
|
127
|
+
* @category annotations
|
|
128
|
+
* @since 3.10.0
|
|
129
|
+
*/
|
|
130
|
+
const getAnnotation = exports.getAnnotation = /*#__PURE__*/(0, _Function.dual)(2, (annotated, key) => Object.prototype.hasOwnProperty.call(annotated.annotations, key) ? Option.some(annotated.annotations[key]) : Option.none());
|
|
131
|
+
/**
|
|
132
|
+
* @category annotations
|
|
133
|
+
* @since 3.10.0
|
|
134
|
+
*/
|
|
135
|
+
const getBrandAnnotation = exports.getBrandAnnotation = /*#__PURE__*/getAnnotation(BrandAnnotationId);
|
|
136
|
+
/**
|
|
137
|
+
* @category annotations
|
|
138
|
+
* @since 3.10.0
|
|
139
|
+
*/
|
|
140
|
+
const getMessageAnnotation = exports.getMessageAnnotation = /*#__PURE__*/getAnnotation(MessageAnnotationId);
|
|
141
|
+
/**
|
|
142
|
+
* @category annotations
|
|
143
|
+
* @since 3.10.0
|
|
144
|
+
*/
|
|
145
|
+
const getMissingMessageAnnotation = exports.getMissingMessageAnnotation = /*#__PURE__*/getAnnotation(MissingMessageAnnotationId);
|
|
146
|
+
/**
|
|
147
|
+
* @category annotations
|
|
148
|
+
* @since 3.10.0
|
|
149
|
+
*/
|
|
150
|
+
const getTitleAnnotation = exports.getTitleAnnotation = /*#__PURE__*/getAnnotation(TitleAnnotationId);
|
|
151
|
+
/**
|
|
152
|
+
* @category annotations
|
|
153
|
+
* @since 3.10.0
|
|
154
|
+
*/
|
|
155
|
+
const getIdentifierAnnotation = exports.getIdentifierAnnotation = /*#__PURE__*/getAnnotation(IdentifierAnnotationId);
|
|
156
|
+
/**
|
|
157
|
+
* @category annotations
|
|
158
|
+
* @since 3.10.0
|
|
159
|
+
*/
|
|
160
|
+
const getDescriptionAnnotation = exports.getDescriptionAnnotation = /*#__PURE__*/getAnnotation(DescriptionAnnotationId);
|
|
161
|
+
/**
|
|
162
|
+
* @category annotations
|
|
163
|
+
* @since 3.10.0
|
|
164
|
+
*/
|
|
165
|
+
const getExamplesAnnotation = exports.getExamplesAnnotation = /*#__PURE__*/getAnnotation(ExamplesAnnotationId);
|
|
166
|
+
/**
|
|
167
|
+
* @category annotations
|
|
168
|
+
* @since 3.10.0
|
|
169
|
+
*/
|
|
170
|
+
const getDefaultAnnotation = exports.getDefaultAnnotation = /*#__PURE__*/getAnnotation(DefaultAnnotationId);
|
|
171
|
+
/**
|
|
172
|
+
* @category annotations
|
|
173
|
+
* @since 3.10.0
|
|
174
|
+
*/
|
|
175
|
+
const getJSONSchemaAnnotation = exports.getJSONSchemaAnnotation = /*#__PURE__*/getAnnotation(JSONSchemaAnnotationId);
|
|
176
|
+
/**
|
|
177
|
+
* @category annotations
|
|
178
|
+
* @since 3.10.0
|
|
179
|
+
*/
|
|
180
|
+
const getDocumentationAnnotation = exports.getDocumentationAnnotation = /*#__PURE__*/getAnnotation(DocumentationAnnotationId);
|
|
181
|
+
/**
|
|
182
|
+
* @category annotations
|
|
183
|
+
* @since 3.10.0
|
|
184
|
+
*/
|
|
185
|
+
const getConcurrencyAnnotation = exports.getConcurrencyAnnotation = /*#__PURE__*/getAnnotation(ConcurrencyAnnotationId);
|
|
186
|
+
/**
|
|
187
|
+
* @category annotations
|
|
188
|
+
* @since 3.10.0
|
|
189
|
+
*/
|
|
190
|
+
const getBatchingAnnotation = exports.getBatchingAnnotation = /*#__PURE__*/getAnnotation(BatchingAnnotationId);
|
|
191
|
+
/**
|
|
192
|
+
* @category annotations
|
|
193
|
+
* @since 3.10.0
|
|
194
|
+
*/
|
|
195
|
+
const getParseIssueTitleAnnotation = exports.getParseIssueTitleAnnotation = /*#__PURE__*/getAnnotation(ParseIssueTitleAnnotationId);
|
|
196
|
+
/**
|
|
197
|
+
* @category annotations
|
|
198
|
+
* @since 3.10.0
|
|
199
|
+
*/
|
|
200
|
+
const getParseOptionsAnnotation = exports.getParseOptionsAnnotation = /*#__PURE__*/getAnnotation(ParseOptionsAnnotationId);
|
|
201
|
+
/**
|
|
202
|
+
* @category annotations
|
|
203
|
+
* @since 3.10.0
|
|
204
|
+
*/
|
|
205
|
+
const getDecodingFallbackAnnotation = exports.getDecodingFallbackAnnotation = /*#__PURE__*/getAnnotation(DecodingFallbackAnnotationId);
|
|
206
|
+
/**
|
|
207
|
+
* @category annotations
|
|
208
|
+
* @since 3.10.0
|
|
209
|
+
*/
|
|
210
|
+
const getSurrogateAnnotation = exports.getSurrogateAnnotation = /*#__PURE__*/getAnnotation(SurrogateAnnotationId);
|
|
211
|
+
const getStableFilterAnnotation = /*#__PURE__*/getAnnotation(StableFilterAnnotationId);
|
|
212
|
+
/** @internal */
|
|
213
|
+
const hasStableFilter = annotated => Option.exists(getStableFilterAnnotation(annotated), b => b === true);
|
|
214
|
+
/**
|
|
215
|
+
* @category annotations
|
|
216
|
+
* @since 3.10.0
|
|
217
|
+
*/
|
|
218
|
+
exports.hasStableFilter = hasStableFilter;
|
|
219
|
+
const JSONIdentifierAnnotationId = exports.JSONIdentifierAnnotationId = /*#__PURE__*/Symbol.for("effect/annotation/JSONIdentifier");
|
|
220
|
+
/**
|
|
221
|
+
* @category annotations
|
|
222
|
+
* @since 3.10.0
|
|
223
|
+
*/
|
|
224
|
+
const getJSONIdentifierAnnotation = exports.getJSONIdentifierAnnotation = /*#__PURE__*/getAnnotation(JSONIdentifierAnnotationId);
|
|
225
|
+
/**
|
|
226
|
+
* @category annotations
|
|
227
|
+
* @since 3.10.0
|
|
228
|
+
*/
|
|
229
|
+
const getJSONIdentifier = annotated => Option.orElse(getJSONIdentifierAnnotation(annotated), () => getIdentifierAnnotation(annotated));
|
|
230
|
+
// -------------------------------------------------------------------------------------
|
|
231
|
+
// schema ids
|
|
232
|
+
// -------------------------------------------------------------------------------------
|
|
233
|
+
/**
|
|
234
|
+
* @category schema id
|
|
235
|
+
* @since 3.10.0
|
|
236
|
+
*/
|
|
237
|
+
exports.getJSONIdentifier = getJSONIdentifier;
|
|
238
|
+
const ParseJsonSchemaId = exports.ParseJsonSchemaId = /*#__PURE__*/Symbol.for("effect/schema/ParseJson");
|
|
239
|
+
/**
|
|
240
|
+
* @category model
|
|
241
|
+
* @since 3.10.0
|
|
242
|
+
*/
|
|
243
|
+
class Declaration {
|
|
244
|
+
typeParameters;
|
|
245
|
+
decodeUnknown;
|
|
246
|
+
encodeUnknown;
|
|
247
|
+
annotations;
|
|
248
|
+
/**
|
|
249
|
+
* @since 3.10.0
|
|
250
|
+
*/
|
|
251
|
+
_tag = "Declaration";
|
|
252
|
+
constructor(typeParameters, decodeUnknown, encodeUnknown, annotations = {}) {
|
|
253
|
+
this.typeParameters = typeParameters;
|
|
254
|
+
this.decodeUnknown = decodeUnknown;
|
|
255
|
+
this.encodeUnknown = encodeUnknown;
|
|
256
|
+
this.annotations = annotations;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* @since 3.10.0
|
|
260
|
+
*/
|
|
261
|
+
toString() {
|
|
262
|
+
return Option.getOrElse(getExpected(this), () => "<declaration schema>");
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* @since 3.10.0
|
|
266
|
+
*/
|
|
267
|
+
toJSON() {
|
|
268
|
+
return {
|
|
269
|
+
_tag: this._tag,
|
|
270
|
+
typeParameters: this.typeParameters.map(ast => ast.toJSON()),
|
|
271
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.Declaration = Declaration;
|
|
276
|
+
const createASTGuard = tag => ast => ast._tag === tag;
|
|
277
|
+
/**
|
|
278
|
+
* @category guards
|
|
279
|
+
* @since 3.10.0
|
|
280
|
+
*/
|
|
281
|
+
const isDeclaration = exports.isDeclaration = /*#__PURE__*/createASTGuard("Declaration");
|
|
282
|
+
/**
|
|
283
|
+
* @category model
|
|
284
|
+
* @since 3.10.0
|
|
285
|
+
*/
|
|
286
|
+
class Literal {
|
|
287
|
+
literal;
|
|
288
|
+
annotations;
|
|
289
|
+
/**
|
|
290
|
+
* @since 3.10.0
|
|
291
|
+
*/
|
|
292
|
+
_tag = "Literal";
|
|
293
|
+
constructor(literal, annotations = {}) {
|
|
294
|
+
this.literal = literal;
|
|
295
|
+
this.annotations = annotations;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* @since 3.10.0
|
|
299
|
+
*/
|
|
300
|
+
toString() {
|
|
301
|
+
return Option.getOrElse(getExpected(this), () => util_.formatUnknown(this.literal));
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* @since 3.10.0
|
|
305
|
+
*/
|
|
306
|
+
toJSON() {
|
|
307
|
+
return {
|
|
308
|
+
_tag: this._tag,
|
|
309
|
+
literal: Predicate.isBigInt(this.literal) ? String(this.literal) : this.literal,
|
|
310
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* @category guards
|
|
316
|
+
* @since 3.10.0
|
|
317
|
+
*/
|
|
318
|
+
exports.Literal = Literal;
|
|
319
|
+
const isLiteral = exports.isLiteral = /*#__PURE__*/createASTGuard("Literal");
|
|
320
|
+
const $null = exports.null = /*#__PURE__*/new Literal(null);
|
|
321
|
+
/**
|
|
322
|
+
* @category model
|
|
323
|
+
* @since 3.10.0
|
|
324
|
+
*/
|
|
325
|
+
class UniqueSymbol {
|
|
326
|
+
symbol;
|
|
327
|
+
annotations;
|
|
328
|
+
/**
|
|
329
|
+
* @since 3.10.0
|
|
330
|
+
*/
|
|
331
|
+
_tag = "UniqueSymbol";
|
|
332
|
+
constructor(symbol, annotations = {}) {
|
|
333
|
+
this.symbol = symbol;
|
|
334
|
+
this.annotations = annotations;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* @since 3.10.0
|
|
338
|
+
*/
|
|
339
|
+
toString() {
|
|
340
|
+
return Option.getOrElse(getExpected(this), () => util_.formatUnknown(this.symbol));
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* @since 3.10.0
|
|
344
|
+
*/
|
|
345
|
+
toJSON() {
|
|
346
|
+
return {
|
|
347
|
+
_tag: this._tag,
|
|
348
|
+
symbol: String(this.symbol),
|
|
349
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* @category guards
|
|
355
|
+
* @since 3.10.0
|
|
356
|
+
*/
|
|
357
|
+
exports.UniqueSymbol = UniqueSymbol;
|
|
358
|
+
const isUniqueSymbol = exports.isUniqueSymbol = /*#__PURE__*/createASTGuard("UniqueSymbol");
|
|
359
|
+
/**
|
|
360
|
+
* @category model
|
|
361
|
+
* @since 3.10.0
|
|
362
|
+
*/
|
|
363
|
+
class UndefinedKeyword {
|
|
364
|
+
annotations;
|
|
365
|
+
/**
|
|
366
|
+
* @since 3.10.0
|
|
367
|
+
*/
|
|
368
|
+
_tag = "UndefinedKeyword";
|
|
369
|
+
constructor(annotations = {}) {
|
|
370
|
+
this.annotations = annotations;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* @since 3.10.0
|
|
374
|
+
*/
|
|
375
|
+
toString() {
|
|
376
|
+
return formatKeyword(this);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* @since 3.10.0
|
|
380
|
+
*/
|
|
381
|
+
toJSON() {
|
|
382
|
+
return {
|
|
383
|
+
_tag: this._tag,
|
|
384
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* @category constructors
|
|
390
|
+
* @since 3.10.0
|
|
391
|
+
*/
|
|
392
|
+
exports.UndefinedKeyword = UndefinedKeyword;
|
|
393
|
+
const undefinedKeyword = exports.undefinedKeyword = /*#__PURE__*/new UndefinedKeyword({
|
|
394
|
+
[TitleAnnotationId]: "undefined"
|
|
395
|
+
});
|
|
396
|
+
/**
|
|
397
|
+
* @category guards
|
|
398
|
+
* @since 3.10.0
|
|
399
|
+
*/
|
|
400
|
+
const isUndefinedKeyword = exports.isUndefinedKeyword = /*#__PURE__*/createASTGuard("UndefinedKeyword");
|
|
401
|
+
/**
|
|
402
|
+
* @category model
|
|
403
|
+
* @since 3.10.0
|
|
404
|
+
*/
|
|
405
|
+
class VoidKeyword {
|
|
406
|
+
annotations;
|
|
407
|
+
/**
|
|
408
|
+
* @since 3.10.0
|
|
409
|
+
*/
|
|
410
|
+
_tag = "VoidKeyword";
|
|
411
|
+
constructor(annotations = {}) {
|
|
412
|
+
this.annotations = annotations;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* @since 3.10.0
|
|
416
|
+
*/
|
|
417
|
+
toString() {
|
|
418
|
+
return formatKeyword(this);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* @since 3.10.0
|
|
422
|
+
*/
|
|
423
|
+
toJSON() {
|
|
424
|
+
return {
|
|
425
|
+
_tag: this._tag,
|
|
426
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* @category constructors
|
|
432
|
+
* @since 3.10.0
|
|
433
|
+
*/
|
|
434
|
+
exports.VoidKeyword = VoidKeyword;
|
|
435
|
+
const voidKeyword = exports.voidKeyword = /*#__PURE__*/new VoidKeyword({
|
|
436
|
+
[TitleAnnotationId]: "void"
|
|
437
|
+
});
|
|
438
|
+
/**
|
|
439
|
+
* @category guards
|
|
440
|
+
* @since 3.10.0
|
|
441
|
+
*/
|
|
442
|
+
const isVoidKeyword = exports.isVoidKeyword = /*#__PURE__*/createASTGuard("VoidKeyword");
|
|
443
|
+
/**
|
|
444
|
+
* @category model
|
|
445
|
+
* @since 3.10.0
|
|
446
|
+
*/
|
|
447
|
+
class NeverKeyword {
|
|
448
|
+
annotations;
|
|
449
|
+
/**
|
|
450
|
+
* @since 3.10.0
|
|
451
|
+
*/
|
|
452
|
+
_tag = "NeverKeyword";
|
|
453
|
+
constructor(annotations = {}) {
|
|
454
|
+
this.annotations = annotations;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* @since 3.10.0
|
|
458
|
+
*/
|
|
459
|
+
toString() {
|
|
460
|
+
return formatKeyword(this);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* @since 3.10.0
|
|
464
|
+
*/
|
|
465
|
+
toJSON() {
|
|
466
|
+
return {
|
|
467
|
+
_tag: this._tag,
|
|
468
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* @category constructors
|
|
474
|
+
* @since 3.10.0
|
|
475
|
+
*/
|
|
476
|
+
exports.NeverKeyword = NeverKeyword;
|
|
477
|
+
const neverKeyword = exports.neverKeyword = /*#__PURE__*/new NeverKeyword({
|
|
478
|
+
[TitleAnnotationId]: "never"
|
|
479
|
+
});
|
|
480
|
+
/**
|
|
481
|
+
* @category guards
|
|
482
|
+
* @since 3.10.0
|
|
483
|
+
*/
|
|
484
|
+
const isNeverKeyword = exports.isNeverKeyword = /*#__PURE__*/createASTGuard("NeverKeyword");
|
|
485
|
+
/**
|
|
486
|
+
* @category model
|
|
487
|
+
* @since 3.10.0
|
|
488
|
+
*/
|
|
489
|
+
class UnknownKeyword {
|
|
490
|
+
annotations;
|
|
491
|
+
/**
|
|
492
|
+
* @since 3.10.0
|
|
493
|
+
*/
|
|
494
|
+
_tag = "UnknownKeyword";
|
|
495
|
+
constructor(annotations = {}) {
|
|
496
|
+
this.annotations = annotations;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* @since 3.10.0
|
|
500
|
+
*/
|
|
501
|
+
toString() {
|
|
502
|
+
return formatKeyword(this);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* @since 3.10.0
|
|
506
|
+
*/
|
|
507
|
+
toJSON() {
|
|
508
|
+
return {
|
|
509
|
+
_tag: this._tag,
|
|
510
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* @category constructors
|
|
516
|
+
* @since 3.10.0
|
|
517
|
+
*/
|
|
518
|
+
exports.UnknownKeyword = UnknownKeyword;
|
|
519
|
+
const unknownKeyword = exports.unknownKeyword = /*#__PURE__*/new UnknownKeyword({
|
|
520
|
+
[TitleAnnotationId]: "unknown"
|
|
521
|
+
});
|
|
522
|
+
/**
|
|
523
|
+
* @category guards
|
|
524
|
+
* @since 3.10.0
|
|
525
|
+
*/
|
|
526
|
+
const isUnknownKeyword = exports.isUnknownKeyword = /*#__PURE__*/createASTGuard("UnknownKeyword");
|
|
527
|
+
/**
|
|
528
|
+
* @category model
|
|
529
|
+
* @since 3.10.0
|
|
530
|
+
*/
|
|
531
|
+
class AnyKeyword {
|
|
532
|
+
annotations;
|
|
533
|
+
/**
|
|
534
|
+
* @since 3.10.0
|
|
535
|
+
*/
|
|
536
|
+
_tag = "AnyKeyword";
|
|
537
|
+
constructor(annotations = {}) {
|
|
538
|
+
this.annotations = annotations;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* @since 3.10.0
|
|
542
|
+
*/
|
|
543
|
+
toString() {
|
|
544
|
+
return formatKeyword(this);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* @since 3.10.0
|
|
548
|
+
*/
|
|
549
|
+
toJSON() {
|
|
550
|
+
return {
|
|
551
|
+
_tag: this._tag,
|
|
552
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* @category constructors
|
|
558
|
+
* @since 3.10.0
|
|
559
|
+
*/
|
|
560
|
+
exports.AnyKeyword = AnyKeyword;
|
|
561
|
+
const anyKeyword = exports.anyKeyword = /*#__PURE__*/new AnyKeyword({
|
|
562
|
+
[TitleAnnotationId]: "any"
|
|
563
|
+
});
|
|
564
|
+
/**
|
|
565
|
+
* @category guards
|
|
566
|
+
* @since 3.10.0
|
|
567
|
+
*/
|
|
568
|
+
const isAnyKeyword = exports.isAnyKeyword = /*#__PURE__*/createASTGuard("AnyKeyword");
|
|
569
|
+
/**
|
|
570
|
+
* @category model
|
|
571
|
+
* @since 3.10.0
|
|
572
|
+
*/
|
|
573
|
+
class StringKeyword {
|
|
574
|
+
annotations;
|
|
575
|
+
/**
|
|
576
|
+
* @since 3.10.0
|
|
577
|
+
*/
|
|
578
|
+
_tag = "StringKeyword";
|
|
579
|
+
constructor(annotations = {}) {
|
|
580
|
+
this.annotations = annotations;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* @since 3.10.0
|
|
584
|
+
*/
|
|
585
|
+
toString() {
|
|
586
|
+
return formatKeyword(this);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* @since 3.10.0
|
|
590
|
+
*/
|
|
591
|
+
toJSON() {
|
|
592
|
+
return {
|
|
593
|
+
_tag: this._tag,
|
|
594
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* @category constructors
|
|
600
|
+
* @since 3.10.0
|
|
601
|
+
*/
|
|
602
|
+
exports.StringKeyword = StringKeyword;
|
|
603
|
+
const stringKeyword = exports.stringKeyword = /*#__PURE__*/new StringKeyword({
|
|
604
|
+
[TitleAnnotationId]: "string",
|
|
605
|
+
[DescriptionAnnotationId]: "a string"
|
|
606
|
+
});
|
|
607
|
+
/**
|
|
608
|
+
* @category guards
|
|
609
|
+
* @since 3.10.0
|
|
610
|
+
*/
|
|
611
|
+
const isStringKeyword = exports.isStringKeyword = /*#__PURE__*/createASTGuard("StringKeyword");
|
|
612
|
+
/**
|
|
613
|
+
* @category model
|
|
614
|
+
* @since 3.10.0
|
|
615
|
+
*/
|
|
616
|
+
class NumberKeyword {
|
|
617
|
+
annotations;
|
|
618
|
+
/**
|
|
619
|
+
* @since 3.10.0
|
|
620
|
+
*/
|
|
621
|
+
_tag = "NumberKeyword";
|
|
622
|
+
constructor(annotations = {}) {
|
|
623
|
+
this.annotations = annotations;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* @since 3.10.0
|
|
627
|
+
*/
|
|
628
|
+
toString() {
|
|
629
|
+
return formatKeyword(this);
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* @since 3.10.0
|
|
633
|
+
*/
|
|
634
|
+
toJSON() {
|
|
635
|
+
return {
|
|
636
|
+
_tag: this._tag,
|
|
637
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* @category constructors
|
|
643
|
+
* @since 3.10.0
|
|
644
|
+
*/
|
|
645
|
+
exports.NumberKeyword = NumberKeyword;
|
|
646
|
+
const numberKeyword = exports.numberKeyword = /*#__PURE__*/new NumberKeyword({
|
|
647
|
+
[TitleAnnotationId]: "number",
|
|
648
|
+
[DescriptionAnnotationId]: "a number"
|
|
649
|
+
});
|
|
650
|
+
/**
|
|
651
|
+
* @category guards
|
|
652
|
+
* @since 3.10.0
|
|
653
|
+
*/
|
|
654
|
+
const isNumberKeyword = exports.isNumberKeyword = /*#__PURE__*/createASTGuard("NumberKeyword");
|
|
655
|
+
/**
|
|
656
|
+
* @category model
|
|
657
|
+
* @since 3.10.0
|
|
658
|
+
*/
|
|
659
|
+
class BooleanKeyword {
|
|
660
|
+
annotations;
|
|
661
|
+
/**
|
|
662
|
+
* @since 3.10.0
|
|
663
|
+
*/
|
|
664
|
+
_tag = "BooleanKeyword";
|
|
665
|
+
constructor(annotations = {}) {
|
|
666
|
+
this.annotations = annotations;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* @since 3.10.0
|
|
670
|
+
*/
|
|
671
|
+
toString() {
|
|
672
|
+
return formatKeyword(this);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* @since 3.10.0
|
|
676
|
+
*/
|
|
677
|
+
toJSON() {
|
|
678
|
+
return {
|
|
679
|
+
_tag: this._tag,
|
|
680
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* @category constructors
|
|
686
|
+
* @since 3.10.0
|
|
687
|
+
*/
|
|
688
|
+
exports.BooleanKeyword = BooleanKeyword;
|
|
689
|
+
const booleanKeyword = exports.booleanKeyword = /*#__PURE__*/new BooleanKeyword({
|
|
690
|
+
[TitleAnnotationId]: "boolean",
|
|
691
|
+
[DescriptionAnnotationId]: "a boolean"
|
|
692
|
+
});
|
|
693
|
+
/**
|
|
694
|
+
* @category guards
|
|
695
|
+
* @since 3.10.0
|
|
696
|
+
*/
|
|
697
|
+
const isBooleanKeyword = exports.isBooleanKeyword = /*#__PURE__*/createASTGuard("BooleanKeyword");
|
|
698
|
+
/**
|
|
699
|
+
* @category model
|
|
700
|
+
* @since 3.10.0
|
|
701
|
+
*/
|
|
702
|
+
class BigIntKeyword {
|
|
703
|
+
annotations;
|
|
704
|
+
/**
|
|
705
|
+
* @since 3.10.0
|
|
706
|
+
*/
|
|
707
|
+
_tag = "BigIntKeyword";
|
|
708
|
+
constructor(annotations = {}) {
|
|
709
|
+
this.annotations = annotations;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* @since 3.10.0
|
|
713
|
+
*/
|
|
714
|
+
toString() {
|
|
715
|
+
return formatKeyword(this);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* @since 3.10.0
|
|
719
|
+
*/
|
|
720
|
+
toJSON() {
|
|
721
|
+
return {
|
|
722
|
+
_tag: this._tag,
|
|
723
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* @category constructors
|
|
729
|
+
* @since 3.10.0
|
|
730
|
+
*/
|
|
731
|
+
exports.BigIntKeyword = BigIntKeyword;
|
|
732
|
+
const bigIntKeyword = exports.bigIntKeyword = /*#__PURE__*/new BigIntKeyword({
|
|
733
|
+
[TitleAnnotationId]: "bigint",
|
|
734
|
+
[DescriptionAnnotationId]: "a bigint"
|
|
735
|
+
});
|
|
736
|
+
/**
|
|
737
|
+
* @category guards
|
|
738
|
+
* @since 3.10.0
|
|
739
|
+
*/
|
|
740
|
+
const isBigIntKeyword = exports.isBigIntKeyword = /*#__PURE__*/createASTGuard("BigIntKeyword");
|
|
741
|
+
/**
|
|
742
|
+
* @category model
|
|
743
|
+
* @since 3.10.0
|
|
744
|
+
*/
|
|
745
|
+
class SymbolKeyword {
|
|
746
|
+
annotations;
|
|
747
|
+
/**
|
|
748
|
+
* @since 3.10.0
|
|
749
|
+
*/
|
|
750
|
+
_tag = "SymbolKeyword";
|
|
751
|
+
constructor(annotations = {}) {
|
|
752
|
+
this.annotations = annotations;
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* @since 3.10.0
|
|
756
|
+
*/
|
|
757
|
+
toString() {
|
|
758
|
+
return formatKeyword(this);
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* @since 3.10.0
|
|
762
|
+
*/
|
|
763
|
+
toJSON() {
|
|
764
|
+
return {
|
|
765
|
+
_tag: this._tag,
|
|
766
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* @category constructors
|
|
772
|
+
* @since 3.10.0
|
|
773
|
+
*/
|
|
774
|
+
exports.SymbolKeyword = SymbolKeyword;
|
|
775
|
+
const symbolKeyword = exports.symbolKeyword = /*#__PURE__*/new SymbolKeyword({
|
|
776
|
+
[TitleAnnotationId]: "symbol",
|
|
777
|
+
[DescriptionAnnotationId]: "a symbol"
|
|
778
|
+
});
|
|
779
|
+
/**
|
|
780
|
+
* @category guards
|
|
781
|
+
* @since 3.10.0
|
|
782
|
+
*/
|
|
783
|
+
const isSymbolKeyword = exports.isSymbolKeyword = /*#__PURE__*/createASTGuard("SymbolKeyword");
|
|
784
|
+
/**
|
|
785
|
+
* @category model
|
|
786
|
+
* @since 3.10.0
|
|
787
|
+
*/
|
|
788
|
+
class ObjectKeyword {
|
|
789
|
+
annotations;
|
|
790
|
+
/**
|
|
791
|
+
* @since 3.10.0
|
|
792
|
+
*/
|
|
793
|
+
_tag = "ObjectKeyword";
|
|
794
|
+
constructor(annotations = {}) {
|
|
795
|
+
this.annotations = annotations;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* @since 3.10.0
|
|
799
|
+
*/
|
|
800
|
+
toString() {
|
|
801
|
+
return formatKeyword(this);
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* @since 3.10.0
|
|
805
|
+
*/
|
|
806
|
+
toJSON() {
|
|
807
|
+
return {
|
|
808
|
+
_tag: this._tag,
|
|
809
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* @category constructors
|
|
815
|
+
* @since 3.10.0
|
|
816
|
+
*/
|
|
817
|
+
exports.ObjectKeyword = ObjectKeyword;
|
|
818
|
+
const objectKeyword = exports.objectKeyword = /*#__PURE__*/new ObjectKeyword({
|
|
819
|
+
[TitleAnnotationId]: "object",
|
|
820
|
+
[DescriptionAnnotationId]: "an object in the TypeScript meaning, i.e. the `object` type"
|
|
821
|
+
});
|
|
822
|
+
/**
|
|
823
|
+
* @category guards
|
|
824
|
+
* @since 3.10.0
|
|
825
|
+
*/
|
|
826
|
+
const isObjectKeyword = exports.isObjectKeyword = /*#__PURE__*/createASTGuard("ObjectKeyword");
|
|
827
|
+
/**
|
|
828
|
+
* @category model
|
|
829
|
+
* @since 3.10.0
|
|
830
|
+
*/
|
|
831
|
+
class Enums {
|
|
832
|
+
enums;
|
|
833
|
+
annotations;
|
|
834
|
+
/**
|
|
835
|
+
* @since 3.10.0
|
|
836
|
+
*/
|
|
837
|
+
_tag = "Enums";
|
|
838
|
+
constructor(enums, annotations = {}) {
|
|
839
|
+
this.enums = enums;
|
|
840
|
+
this.annotations = annotations;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* @since 3.10.0
|
|
844
|
+
*/
|
|
845
|
+
toString() {
|
|
846
|
+
return Option.getOrElse(getExpected(this), () => `<enum ${this.enums.length} value(s): ${this.enums.map((_, value) => JSON.stringify(value)).join(" | ")}>`);
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* @since 3.10.0
|
|
850
|
+
*/
|
|
851
|
+
toJSON() {
|
|
852
|
+
return {
|
|
853
|
+
_tag: this._tag,
|
|
854
|
+
enums: this.enums,
|
|
855
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* @category guards
|
|
861
|
+
* @since 3.10.0
|
|
862
|
+
*/
|
|
863
|
+
exports.Enums = Enums;
|
|
864
|
+
const isEnums = exports.isEnums = /*#__PURE__*/createASTGuard("Enums");
|
|
865
|
+
/**
|
|
866
|
+
* @category model
|
|
867
|
+
* @since 3.10.0
|
|
868
|
+
*/
|
|
869
|
+
class TemplateLiteralSpan {
|
|
870
|
+
type;
|
|
871
|
+
literal;
|
|
872
|
+
constructor(type, literal) {
|
|
873
|
+
this.type = type;
|
|
874
|
+
this.literal = literal;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* @since 3.10.0
|
|
878
|
+
*/
|
|
879
|
+
toString() {
|
|
880
|
+
const type = "${" + String(this.type) + "}";
|
|
881
|
+
return type + this.literal;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* @since 3.10.0
|
|
885
|
+
*/
|
|
886
|
+
toJSON() {
|
|
887
|
+
return {
|
|
888
|
+
type: this.type.toJSON(),
|
|
889
|
+
literal: this.literal
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* @category model
|
|
895
|
+
* @since 3.10.0
|
|
896
|
+
*/
|
|
897
|
+
exports.TemplateLiteralSpan = TemplateLiteralSpan;
|
|
898
|
+
class TemplateLiteral {
|
|
899
|
+
head;
|
|
900
|
+
spans;
|
|
901
|
+
annotations;
|
|
902
|
+
/**
|
|
903
|
+
* @since 3.10.0
|
|
904
|
+
*/
|
|
905
|
+
_tag = "TemplateLiteral";
|
|
906
|
+
constructor(head, spans, annotations = {}) {
|
|
907
|
+
this.head = head;
|
|
908
|
+
this.spans = spans;
|
|
909
|
+
this.annotations = annotations;
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* @since 3.10.0
|
|
913
|
+
*/
|
|
914
|
+
toString() {
|
|
915
|
+
return Option.getOrElse(getExpected(this), () => formatTemplateLiteral(this));
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* @since 3.10.0
|
|
919
|
+
*/
|
|
920
|
+
toJSON() {
|
|
921
|
+
return {
|
|
922
|
+
_tag: this._tag,
|
|
923
|
+
head: this.head,
|
|
924
|
+
spans: this.spans.map(span => span.toJSON()),
|
|
925
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
exports.TemplateLiteral = TemplateLiteral;
|
|
930
|
+
const formatTemplateLiteral = ast => "`" + ast.head + ast.spans.map(span => String(span)).join("") + "`";
|
|
931
|
+
/**
|
|
932
|
+
* @category guards
|
|
933
|
+
* @since 3.10.0
|
|
934
|
+
*/
|
|
935
|
+
const isTemplateLiteral = exports.isTemplateLiteral = /*#__PURE__*/createASTGuard("TemplateLiteral");
|
|
936
|
+
/**
|
|
937
|
+
* @category model
|
|
938
|
+
* @since 3.10.0
|
|
939
|
+
*/
|
|
940
|
+
class Type {
|
|
941
|
+
type;
|
|
942
|
+
annotations;
|
|
943
|
+
constructor(type, annotations = {}) {
|
|
944
|
+
this.type = type;
|
|
945
|
+
this.annotations = annotations;
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* @since 3.10.0
|
|
949
|
+
*/
|
|
950
|
+
toJSON() {
|
|
951
|
+
return {
|
|
952
|
+
type: this.type.toJSON(),
|
|
953
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* @since 3.10.0
|
|
958
|
+
*/
|
|
959
|
+
toString() {
|
|
960
|
+
return String(this.type);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* @category model
|
|
965
|
+
* @since 3.10.0
|
|
966
|
+
*/
|
|
967
|
+
exports.Type = Type;
|
|
968
|
+
class OptionalType extends Type {
|
|
969
|
+
isOptional;
|
|
970
|
+
constructor(type, isOptional, annotations = {}) {
|
|
971
|
+
super(type, annotations);
|
|
972
|
+
this.isOptional = isOptional;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* @since 3.10.0
|
|
976
|
+
*/
|
|
977
|
+
toJSON() {
|
|
978
|
+
return {
|
|
979
|
+
type: this.type.toJSON(),
|
|
980
|
+
isOptional: this.isOptional,
|
|
981
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* @since 3.10.0
|
|
986
|
+
*/
|
|
987
|
+
toString() {
|
|
988
|
+
return String(this.type) + (this.isOptional ? "?" : "");
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
exports.OptionalType = OptionalType;
|
|
992
|
+
const getRestASTs = rest => rest.map(annotatedAST => annotatedAST.type);
|
|
993
|
+
/**
|
|
994
|
+
* @category model
|
|
995
|
+
* @since 3.10.0
|
|
996
|
+
*/
|
|
997
|
+
class TupleType {
|
|
998
|
+
elements;
|
|
999
|
+
rest;
|
|
1000
|
+
isReadonly;
|
|
1001
|
+
annotations;
|
|
1002
|
+
/**
|
|
1003
|
+
* @since 3.10.0
|
|
1004
|
+
*/
|
|
1005
|
+
_tag = "TupleType";
|
|
1006
|
+
constructor(elements, rest, isReadonly, annotations = {}) {
|
|
1007
|
+
this.elements = elements;
|
|
1008
|
+
this.rest = rest;
|
|
1009
|
+
this.isReadonly = isReadonly;
|
|
1010
|
+
this.annotations = annotations;
|
|
1011
|
+
let hasOptionalElement = false;
|
|
1012
|
+
let hasIllegalRequiredElement = false;
|
|
1013
|
+
for (const e of elements) {
|
|
1014
|
+
if (e.isOptional) {
|
|
1015
|
+
hasOptionalElement = true;
|
|
1016
|
+
} else if (hasOptionalElement) {
|
|
1017
|
+
hasIllegalRequiredElement = true;
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (hasIllegalRequiredElement || hasOptionalElement && rest.length > 1) {
|
|
1022
|
+
throw new Error(errors_.getASTRequiredElementFollowinAnOptionalElementErrorMessage);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* @since 3.10.0
|
|
1027
|
+
*/
|
|
1028
|
+
toString() {
|
|
1029
|
+
return Option.getOrElse(getExpected(this), () => formatTuple(this));
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* @since 3.10.0
|
|
1033
|
+
*/
|
|
1034
|
+
toJSON() {
|
|
1035
|
+
return {
|
|
1036
|
+
_tag: this._tag,
|
|
1037
|
+
elements: this.elements.map(e => e.toJSON()),
|
|
1038
|
+
rest: this.rest.map(ast => ast.toJSON()),
|
|
1039
|
+
isReadonly: this.isReadonly,
|
|
1040
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
exports.TupleType = TupleType;
|
|
1045
|
+
const formatTuple = ast => {
|
|
1046
|
+
const formattedElements = ast.elements.map(String).join(", ");
|
|
1047
|
+
return Arr.matchLeft(ast.rest, {
|
|
1048
|
+
onEmpty: () => `readonly [${formattedElements}]`,
|
|
1049
|
+
onNonEmpty: (head, tail) => {
|
|
1050
|
+
const formattedHead = String(head);
|
|
1051
|
+
const wrappedHead = formattedHead.includes(" | ") ? `(${formattedHead})` : formattedHead;
|
|
1052
|
+
if (tail.length > 0) {
|
|
1053
|
+
const formattedTail = tail.map(String).join(", ");
|
|
1054
|
+
if (ast.elements.length > 0) {
|
|
1055
|
+
return `readonly [${formattedElements}, ...${wrappedHead}[], ${formattedTail}]`;
|
|
1056
|
+
} else {
|
|
1057
|
+
return `readonly [...${wrappedHead}[], ${formattedTail}]`;
|
|
1058
|
+
}
|
|
1059
|
+
} else {
|
|
1060
|
+
if (ast.elements.length > 0) {
|
|
1061
|
+
return `readonly [${formattedElements}, ...${wrappedHead}[]]`;
|
|
1062
|
+
} else {
|
|
1063
|
+
return `ReadonlyArray<${formattedHead}>`;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
};
|
|
1069
|
+
/**
|
|
1070
|
+
* @category guards
|
|
1071
|
+
* @since 3.10.0
|
|
1072
|
+
*/
|
|
1073
|
+
const isTupleType = exports.isTupleType = /*#__PURE__*/createASTGuard("TupleType");
|
|
1074
|
+
/**
|
|
1075
|
+
* @category model
|
|
1076
|
+
* @since 3.10.0
|
|
1077
|
+
*/
|
|
1078
|
+
class PropertySignature extends OptionalType {
|
|
1079
|
+
name;
|
|
1080
|
+
isReadonly;
|
|
1081
|
+
constructor(name, type, isOptional, isReadonly, annotations) {
|
|
1082
|
+
super(type, isOptional, annotations);
|
|
1083
|
+
this.name = name;
|
|
1084
|
+
this.isReadonly = isReadonly;
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* @since 3.10.0
|
|
1088
|
+
*/
|
|
1089
|
+
toString() {
|
|
1090
|
+
return (this.isReadonly ? "readonly " : "") + String(this.name) + (this.isOptional ? "?" : "") + ": " + this.type;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* @since 3.10.0
|
|
1094
|
+
*/
|
|
1095
|
+
toJSON() {
|
|
1096
|
+
return {
|
|
1097
|
+
name: String(this.name),
|
|
1098
|
+
type: this.type.toJSON(),
|
|
1099
|
+
isOptional: this.isOptional,
|
|
1100
|
+
isReadonly: this.isReadonly,
|
|
1101
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* @since 3.10.0
|
|
1107
|
+
*/
|
|
1108
|
+
exports.PropertySignature = PropertySignature;
|
|
1109
|
+
const isParameter = ast => {
|
|
1110
|
+
switch (ast._tag) {
|
|
1111
|
+
case "StringKeyword":
|
|
1112
|
+
case "SymbolKeyword":
|
|
1113
|
+
case "TemplateLiteral":
|
|
1114
|
+
return true;
|
|
1115
|
+
case "Refinement":
|
|
1116
|
+
return isParameter(ast.from);
|
|
1117
|
+
}
|
|
1118
|
+
return false;
|
|
1119
|
+
};
|
|
1120
|
+
/**
|
|
1121
|
+
* @category model
|
|
1122
|
+
* @since 3.10.0
|
|
1123
|
+
*/
|
|
1124
|
+
exports.isParameter = isParameter;
|
|
1125
|
+
class IndexSignature {
|
|
1126
|
+
type;
|
|
1127
|
+
isReadonly;
|
|
1128
|
+
/**
|
|
1129
|
+
* @since 3.10.0
|
|
1130
|
+
*/
|
|
1131
|
+
parameter;
|
|
1132
|
+
constructor(parameter, type, isReadonly) {
|
|
1133
|
+
this.type = type;
|
|
1134
|
+
this.isReadonly = isReadonly;
|
|
1135
|
+
if (isParameter(parameter)) {
|
|
1136
|
+
this.parameter = parameter;
|
|
1137
|
+
} else {
|
|
1138
|
+
throw new Error(errors_.getASTIndexSignatureParameterErrorMessage);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* @since 3.10.0
|
|
1143
|
+
*/
|
|
1144
|
+
toString() {
|
|
1145
|
+
return (this.isReadonly ? "readonly " : "") + `[x: ${this.parameter}]: ${this.type}`;
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* @since 3.10.0
|
|
1149
|
+
*/
|
|
1150
|
+
toJSON() {
|
|
1151
|
+
return {
|
|
1152
|
+
parameter: this.parameter.toJSON(),
|
|
1153
|
+
type: this.type.toJSON(),
|
|
1154
|
+
isReadonly: this.isReadonly
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* @category model
|
|
1160
|
+
* @since 3.10.0
|
|
1161
|
+
*/
|
|
1162
|
+
exports.IndexSignature = IndexSignature;
|
|
1163
|
+
class TypeLiteral {
|
|
1164
|
+
annotations;
|
|
1165
|
+
/**
|
|
1166
|
+
* @since 3.10.0
|
|
1167
|
+
*/
|
|
1168
|
+
_tag = "TypeLiteral";
|
|
1169
|
+
/**
|
|
1170
|
+
* @since 3.10.0
|
|
1171
|
+
*/
|
|
1172
|
+
propertySignatures;
|
|
1173
|
+
/**
|
|
1174
|
+
* @since 3.10.0
|
|
1175
|
+
*/
|
|
1176
|
+
indexSignatures;
|
|
1177
|
+
constructor(propertySignatures, indexSignatures, annotations = {}) {
|
|
1178
|
+
this.annotations = annotations;
|
|
1179
|
+
// check for duplicate property signatures
|
|
1180
|
+
const keys = {};
|
|
1181
|
+
for (let i = 0; i < propertySignatures.length; i++) {
|
|
1182
|
+
const name = propertySignatures[i].name;
|
|
1183
|
+
if (Object.prototype.hasOwnProperty.call(keys, name)) {
|
|
1184
|
+
throw new Error(errors_.getASTDuplicatePropertySignatureErrorMessage(name));
|
|
1185
|
+
}
|
|
1186
|
+
keys[name] = null;
|
|
1187
|
+
}
|
|
1188
|
+
// check for duplicate index signatures
|
|
1189
|
+
const parameters = {
|
|
1190
|
+
string: false,
|
|
1191
|
+
symbol: false
|
|
1192
|
+
};
|
|
1193
|
+
for (let i = 0; i < indexSignatures.length; i++) {
|
|
1194
|
+
const parameter = getParameterBase(indexSignatures[i].parameter);
|
|
1195
|
+
if (isStringKeyword(parameter)) {
|
|
1196
|
+
if (parameters.string) {
|
|
1197
|
+
throw new Error(errors_.getASTDuplicateIndexSignatureErrorMessage("string"));
|
|
1198
|
+
}
|
|
1199
|
+
parameters.string = true;
|
|
1200
|
+
} else if (isSymbolKeyword(parameter)) {
|
|
1201
|
+
if (parameters.symbol) {
|
|
1202
|
+
throw new Error(errors_.getASTDuplicateIndexSignatureErrorMessage("symbol"));
|
|
1203
|
+
}
|
|
1204
|
+
parameters.symbol = true;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
this.propertySignatures = propertySignatures;
|
|
1208
|
+
this.indexSignatures = indexSignatures;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* @since 3.10.0
|
|
1212
|
+
*/
|
|
1213
|
+
toString() {
|
|
1214
|
+
return Option.getOrElse(getExpected(this), () => formatTypeLiteral(this));
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* @since 3.10.0
|
|
1218
|
+
*/
|
|
1219
|
+
toJSON() {
|
|
1220
|
+
return {
|
|
1221
|
+
_tag: this._tag,
|
|
1222
|
+
propertySignatures: this.propertySignatures.map(ps => ps.toJSON()),
|
|
1223
|
+
indexSignatures: this.indexSignatures.map(ps => ps.toJSON()),
|
|
1224
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
exports.TypeLiteral = TypeLiteral;
|
|
1229
|
+
const formatIndexSignatures = iss => iss.map(String).join("; ");
|
|
1230
|
+
const formatTypeLiteral = ast => {
|
|
1231
|
+
if (ast.propertySignatures.length > 0) {
|
|
1232
|
+
const pss = ast.propertySignatures.map(String).join("; ");
|
|
1233
|
+
if (ast.indexSignatures.length > 0) {
|
|
1234
|
+
return `{ ${pss}; ${formatIndexSignatures(ast.indexSignatures)} }`;
|
|
1235
|
+
} else {
|
|
1236
|
+
return `{ ${pss} }`;
|
|
1237
|
+
}
|
|
1238
|
+
} else {
|
|
1239
|
+
if (ast.indexSignatures.length > 0) {
|
|
1240
|
+
return `{ ${formatIndexSignatures(ast.indexSignatures)} }`;
|
|
1241
|
+
} else {
|
|
1242
|
+
return "{}";
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1246
|
+
/**
|
|
1247
|
+
* @category guards
|
|
1248
|
+
* @since 3.10.0
|
|
1249
|
+
*/
|
|
1250
|
+
const isTypeLiteral = exports.isTypeLiteral = /*#__PURE__*/createASTGuard("TypeLiteral");
|
|
1251
|
+
const sortCandidates = /*#__PURE__*/Arr.sort( /*#__PURE__*/Order.mapInput(Number.Order, ast => {
|
|
1252
|
+
switch (ast._tag) {
|
|
1253
|
+
case "AnyKeyword":
|
|
1254
|
+
return 0;
|
|
1255
|
+
case "UnknownKeyword":
|
|
1256
|
+
return 1;
|
|
1257
|
+
case "ObjectKeyword":
|
|
1258
|
+
return 2;
|
|
1259
|
+
case "StringKeyword":
|
|
1260
|
+
case "NumberKeyword":
|
|
1261
|
+
case "BooleanKeyword":
|
|
1262
|
+
case "BigIntKeyword":
|
|
1263
|
+
case "SymbolKeyword":
|
|
1264
|
+
return 3;
|
|
1265
|
+
}
|
|
1266
|
+
return 4;
|
|
1267
|
+
}));
|
|
1268
|
+
const literalMap = {
|
|
1269
|
+
string: "StringKeyword",
|
|
1270
|
+
number: "NumberKeyword",
|
|
1271
|
+
boolean: "BooleanKeyword",
|
|
1272
|
+
bigint: "BigIntKeyword"
|
|
1273
|
+
};
|
|
1274
|
+
/** @internal */
|
|
1275
|
+
const flatten = candidates => Arr.flatMap(candidates, ast => isUnion(ast) ? flatten(ast.types) : [ast]);
|
|
1276
|
+
/** @internal */
|
|
1277
|
+
exports.flatten = flatten;
|
|
1278
|
+
const unify = candidates => {
|
|
1279
|
+
const cs = sortCandidates(candidates);
|
|
1280
|
+
const out = [];
|
|
1281
|
+
const uniques = {};
|
|
1282
|
+
const literals = [];
|
|
1283
|
+
for (const ast of cs) {
|
|
1284
|
+
switch (ast._tag) {
|
|
1285
|
+
case "NeverKeyword":
|
|
1286
|
+
break;
|
|
1287
|
+
case "AnyKeyword":
|
|
1288
|
+
return [anyKeyword];
|
|
1289
|
+
case "UnknownKeyword":
|
|
1290
|
+
return [unknownKeyword];
|
|
1291
|
+
// uniques
|
|
1292
|
+
case "ObjectKeyword":
|
|
1293
|
+
case "UndefinedKeyword":
|
|
1294
|
+
case "VoidKeyword":
|
|
1295
|
+
case "StringKeyword":
|
|
1296
|
+
case "NumberKeyword":
|
|
1297
|
+
case "BooleanKeyword":
|
|
1298
|
+
case "BigIntKeyword":
|
|
1299
|
+
case "SymbolKeyword":
|
|
1300
|
+
{
|
|
1301
|
+
if (!uniques[ast._tag]) {
|
|
1302
|
+
uniques[ast._tag] = ast;
|
|
1303
|
+
out.push(ast);
|
|
1304
|
+
}
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
case "Literal":
|
|
1308
|
+
{
|
|
1309
|
+
const type = typeof ast.literal;
|
|
1310
|
+
switch (type) {
|
|
1311
|
+
case "string":
|
|
1312
|
+
case "number":
|
|
1313
|
+
case "bigint":
|
|
1314
|
+
case "boolean":
|
|
1315
|
+
{
|
|
1316
|
+
const _tag = literalMap[type];
|
|
1317
|
+
if (!uniques[_tag] && !literals.includes(ast.literal)) {
|
|
1318
|
+
literals.push(ast.literal);
|
|
1319
|
+
out.push(ast);
|
|
1320
|
+
}
|
|
1321
|
+
break;
|
|
1322
|
+
}
|
|
1323
|
+
// null
|
|
1324
|
+
case "object":
|
|
1325
|
+
{
|
|
1326
|
+
if (!literals.includes(ast.literal)) {
|
|
1327
|
+
literals.push(ast.literal);
|
|
1328
|
+
out.push(ast);
|
|
1329
|
+
}
|
|
1330
|
+
break;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
break;
|
|
1334
|
+
}
|
|
1335
|
+
case "UniqueSymbol":
|
|
1336
|
+
{
|
|
1337
|
+
if (!uniques["SymbolKeyword"] && !literals.includes(ast.symbol)) {
|
|
1338
|
+
literals.push(ast.symbol);
|
|
1339
|
+
out.push(ast);
|
|
1340
|
+
}
|
|
1341
|
+
break;
|
|
1342
|
+
}
|
|
1343
|
+
case "TupleType":
|
|
1344
|
+
{
|
|
1345
|
+
if (!uniques["ObjectKeyword"]) {
|
|
1346
|
+
out.push(ast);
|
|
1347
|
+
}
|
|
1348
|
+
break;
|
|
1349
|
+
}
|
|
1350
|
+
case "TypeLiteral":
|
|
1351
|
+
{
|
|
1352
|
+
if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) {
|
|
1353
|
+
if (!uniques["{}"]) {
|
|
1354
|
+
uniques["{}"] = ast;
|
|
1355
|
+
out.push(ast);
|
|
1356
|
+
}
|
|
1357
|
+
} else if (!uniques["ObjectKeyword"]) {
|
|
1358
|
+
out.push(ast);
|
|
1359
|
+
}
|
|
1360
|
+
break;
|
|
1361
|
+
}
|
|
1362
|
+
default:
|
|
1363
|
+
out.push(ast);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
return out;
|
|
1367
|
+
};
|
|
1368
|
+
/**
|
|
1369
|
+
* @category model
|
|
1370
|
+
* @since 3.10.0
|
|
1371
|
+
*/
|
|
1372
|
+
exports.unify = unify;
|
|
1373
|
+
class Union {
|
|
1374
|
+
types;
|
|
1375
|
+
annotations;
|
|
1376
|
+
static make = (types, annotations) => {
|
|
1377
|
+
return isMembers(types) ? new Union(types, annotations) : types.length === 1 ? types[0] : neverKeyword;
|
|
1378
|
+
};
|
|
1379
|
+
/** @internal */
|
|
1380
|
+
static unify = (candidates, annotations) => {
|
|
1381
|
+
return Union.make(unify(flatten(candidates)), annotations);
|
|
1382
|
+
};
|
|
1383
|
+
/**
|
|
1384
|
+
* @since 3.10.0
|
|
1385
|
+
*/
|
|
1386
|
+
_tag = "Union";
|
|
1387
|
+
constructor(types, annotations = {}) {
|
|
1388
|
+
this.types = types;
|
|
1389
|
+
this.annotations = annotations;
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* @since 3.10.0
|
|
1393
|
+
*/
|
|
1394
|
+
toString() {
|
|
1395
|
+
return Option.getOrElse(getExpected(this), () => this.types.map(String).join(" | "));
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* @since 3.10.0
|
|
1399
|
+
*/
|
|
1400
|
+
toJSON() {
|
|
1401
|
+
return {
|
|
1402
|
+
_tag: this._tag,
|
|
1403
|
+
types: this.types.map(ast => ast.toJSON()),
|
|
1404
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
/** @internal */
|
|
1409
|
+
exports.Union = Union;
|
|
1410
|
+
const mapMembers = (members, f) => members.map(f);
|
|
1411
|
+
/** @internal */
|
|
1412
|
+
exports.mapMembers = mapMembers;
|
|
1413
|
+
const isMembers = as => as.length > 1;
|
|
1414
|
+
/**
|
|
1415
|
+
* @category guards
|
|
1416
|
+
* @since 3.10.0
|
|
1417
|
+
*/
|
|
1418
|
+
exports.isMembers = isMembers;
|
|
1419
|
+
const isUnion = exports.isUnion = /*#__PURE__*/createASTGuard("Union");
|
|
1420
|
+
const toJSONMemoMap = /*#__PURE__*/(0, _GlobalValue.globalValue)( /*#__PURE__*/Symbol.for("effect/Schema/AST/toJSONMemoMap"), () => new WeakMap());
|
|
1421
|
+
/**
|
|
1422
|
+
* @category model
|
|
1423
|
+
* @since 3.10.0
|
|
1424
|
+
*/
|
|
1425
|
+
class Suspend {
|
|
1426
|
+
f;
|
|
1427
|
+
annotations;
|
|
1428
|
+
/**
|
|
1429
|
+
* @since 3.10.0
|
|
1430
|
+
*/
|
|
1431
|
+
_tag = "Suspend";
|
|
1432
|
+
constructor(f, annotations = {}) {
|
|
1433
|
+
this.f = f;
|
|
1434
|
+
this.annotations = annotations;
|
|
1435
|
+
this.f = util_.memoizeThunk(f);
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* @since 3.10.0
|
|
1439
|
+
*/
|
|
1440
|
+
toString() {
|
|
1441
|
+
return getExpected(this).pipe(Option.orElse(() => Option.flatMap(Option.liftThrowable(this.f)(), ast => getExpected(ast))), Option.getOrElse(() => "<suspended schema>"));
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* @since 3.10.0
|
|
1445
|
+
*/
|
|
1446
|
+
toJSON() {
|
|
1447
|
+
const ast = this.f();
|
|
1448
|
+
let out = toJSONMemoMap.get(ast);
|
|
1449
|
+
if (out) {
|
|
1450
|
+
return out;
|
|
1451
|
+
}
|
|
1452
|
+
toJSONMemoMap.set(ast, {
|
|
1453
|
+
_tag: this._tag
|
|
1454
|
+
});
|
|
1455
|
+
out = {
|
|
1456
|
+
_tag: this._tag,
|
|
1457
|
+
ast: ast.toJSON(),
|
|
1458
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1459
|
+
};
|
|
1460
|
+
toJSONMemoMap.set(ast, out);
|
|
1461
|
+
return out;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* @category guards
|
|
1466
|
+
* @since 3.10.0
|
|
1467
|
+
*/
|
|
1468
|
+
exports.Suspend = Suspend;
|
|
1469
|
+
const isSuspend = exports.isSuspend = /*#__PURE__*/createASTGuard("Suspend");
|
|
1470
|
+
/**
|
|
1471
|
+
* @category model
|
|
1472
|
+
* @since 3.10.0
|
|
1473
|
+
*/
|
|
1474
|
+
class Refinement {
|
|
1475
|
+
from;
|
|
1476
|
+
filter;
|
|
1477
|
+
annotations;
|
|
1478
|
+
/**
|
|
1479
|
+
* @since 3.10.0
|
|
1480
|
+
*/
|
|
1481
|
+
_tag = "Refinement";
|
|
1482
|
+
constructor(from, filter, annotations = {}) {
|
|
1483
|
+
this.from = from;
|
|
1484
|
+
this.filter = filter;
|
|
1485
|
+
this.annotations = annotations;
|
|
1486
|
+
}
|
|
1487
|
+
/**
|
|
1488
|
+
* @since 3.10.0
|
|
1489
|
+
*/
|
|
1490
|
+
toString() {
|
|
1491
|
+
return Option.getOrElse(getExpected(this), () => `{ ${this.from} | filter }`);
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* @since 3.10.0
|
|
1495
|
+
*/
|
|
1496
|
+
toJSON() {
|
|
1497
|
+
return {
|
|
1498
|
+
_tag: this._tag,
|
|
1499
|
+
from: this.from.toJSON(),
|
|
1500
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* @category guards
|
|
1506
|
+
* @since 3.10.0
|
|
1507
|
+
*/
|
|
1508
|
+
exports.Refinement = Refinement;
|
|
1509
|
+
const isRefinement = exports.isRefinement = /*#__PURE__*/createASTGuard("Refinement");
|
|
1510
|
+
/**
|
|
1511
|
+
* @since 3.10.0
|
|
1512
|
+
*/
|
|
1513
|
+
const defaultParseOption = exports.defaultParseOption = {};
|
|
1514
|
+
/**
|
|
1515
|
+
* @category model
|
|
1516
|
+
* @since 3.10.0
|
|
1517
|
+
*/
|
|
1518
|
+
class Transformation {
|
|
1519
|
+
from;
|
|
1520
|
+
to;
|
|
1521
|
+
transformation;
|
|
1522
|
+
annotations;
|
|
1523
|
+
/**
|
|
1524
|
+
* @since 3.10.0
|
|
1525
|
+
*/
|
|
1526
|
+
_tag = "Transformation";
|
|
1527
|
+
constructor(from, to, transformation, annotations = {}) {
|
|
1528
|
+
this.from = from;
|
|
1529
|
+
this.to = to;
|
|
1530
|
+
this.transformation = transformation;
|
|
1531
|
+
this.annotations = annotations;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* @since 3.10.0
|
|
1535
|
+
*/
|
|
1536
|
+
toString() {
|
|
1537
|
+
return Option.getOrElse(getExpected(this), () => `(${String(this.from)} <-> ${String(this.to)})`);
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* @since 3.10.0
|
|
1541
|
+
*/
|
|
1542
|
+
toJSON() {
|
|
1543
|
+
return {
|
|
1544
|
+
_tag: this._tag,
|
|
1545
|
+
from: this.from.toJSON(),
|
|
1546
|
+
to: this.to.toJSON(),
|
|
1547
|
+
annotations: toJSONAnnotations(this.annotations)
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* @category guards
|
|
1553
|
+
* @since 3.10.0
|
|
1554
|
+
*/
|
|
1555
|
+
exports.Transformation = Transformation;
|
|
1556
|
+
const isTransformation = exports.isTransformation = /*#__PURE__*/createASTGuard("Transformation");
|
|
1557
|
+
/**
|
|
1558
|
+
* @category model
|
|
1559
|
+
* @since 3.10.0
|
|
1560
|
+
*/
|
|
1561
|
+
class FinalTransformation {
|
|
1562
|
+
decode;
|
|
1563
|
+
encode;
|
|
1564
|
+
/**
|
|
1565
|
+
* @since 3.10.0
|
|
1566
|
+
*/
|
|
1567
|
+
_tag = "FinalTransformation";
|
|
1568
|
+
constructor(decode, encode) {
|
|
1569
|
+
this.decode = decode;
|
|
1570
|
+
this.encode = encode;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
exports.FinalTransformation = FinalTransformation;
|
|
1574
|
+
const createTransformationGuard = tag => ast => ast._tag === tag;
|
|
1575
|
+
/**
|
|
1576
|
+
* @category guards
|
|
1577
|
+
* @since 3.10.0
|
|
1578
|
+
*/
|
|
1579
|
+
const isFinalTransformation = exports.isFinalTransformation = /*#__PURE__*/createTransformationGuard("FinalTransformation");
|
|
1580
|
+
/**
|
|
1581
|
+
* @category model
|
|
1582
|
+
* @since 3.10.0
|
|
1583
|
+
*/
|
|
1584
|
+
class ComposeTransformation {
|
|
1585
|
+
/**
|
|
1586
|
+
* @since 3.10.0
|
|
1587
|
+
*/
|
|
1588
|
+
_tag = "ComposeTransformation";
|
|
1589
|
+
}
|
|
1590
|
+
/**
|
|
1591
|
+
* @category constructors
|
|
1592
|
+
* @since 3.10.0
|
|
1593
|
+
*/
|
|
1594
|
+
exports.ComposeTransformation = ComposeTransformation;
|
|
1595
|
+
const composeTransformation = exports.composeTransformation = /*#__PURE__*/new ComposeTransformation();
|
|
1596
|
+
/**
|
|
1597
|
+
* @category guards
|
|
1598
|
+
* @since 3.10.0
|
|
1599
|
+
*/
|
|
1600
|
+
const isComposeTransformation = exports.isComposeTransformation = /*#__PURE__*/createTransformationGuard("ComposeTransformation");
|
|
1601
|
+
/**
|
|
1602
|
+
* Represents a `PropertySignature -> PropertySignature` transformation
|
|
1603
|
+
*
|
|
1604
|
+
* The semantic of `decode` is:
|
|
1605
|
+
* - `none()` represents the absence of the key/value pair
|
|
1606
|
+
* - `some(value)` represents the presence of the key/value pair
|
|
1607
|
+
*
|
|
1608
|
+
* The semantic of `encode` is:
|
|
1609
|
+
* - `none()` you don't want to output the key/value pair
|
|
1610
|
+
* - `some(value)` you want to output the key/value pair
|
|
1611
|
+
*
|
|
1612
|
+
* @category model
|
|
1613
|
+
* @since 3.10.0
|
|
1614
|
+
*/
|
|
1615
|
+
class PropertySignatureTransformation {
|
|
1616
|
+
from;
|
|
1617
|
+
to;
|
|
1618
|
+
decode;
|
|
1619
|
+
encode;
|
|
1620
|
+
constructor(from, to, decode, encode) {
|
|
1621
|
+
this.from = from;
|
|
1622
|
+
this.to = to;
|
|
1623
|
+
this.decode = decode;
|
|
1624
|
+
this.encode = encode;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
exports.PropertySignatureTransformation = PropertySignatureTransformation;
|
|
1628
|
+
const isRenamingPropertySignatureTransformation = t => t.decode === _Function.identity && t.encode === _Function.identity;
|
|
1629
|
+
/**
|
|
1630
|
+
* @category model
|
|
1631
|
+
* @since 3.10.0
|
|
1632
|
+
*/
|
|
1633
|
+
class TypeLiteralTransformation {
|
|
1634
|
+
propertySignatureTransformations;
|
|
1635
|
+
/**
|
|
1636
|
+
* @since 3.10.0
|
|
1637
|
+
*/
|
|
1638
|
+
_tag = "TypeLiteralTransformation";
|
|
1639
|
+
constructor(propertySignatureTransformations) {
|
|
1640
|
+
this.propertySignatureTransformations = propertySignatureTransformations;
|
|
1641
|
+
// check for duplicate property signature transformations
|
|
1642
|
+
const fromKeys = {};
|
|
1643
|
+
const toKeys = {};
|
|
1644
|
+
for (const pst of propertySignatureTransformations) {
|
|
1645
|
+
const from = pst.from;
|
|
1646
|
+
if (fromKeys[from]) {
|
|
1647
|
+
throw new Error(errors_.getASTDuplicatePropertySignatureTransformationErrorMessage(from));
|
|
1648
|
+
}
|
|
1649
|
+
fromKeys[from] = true;
|
|
1650
|
+
const to = pst.to;
|
|
1651
|
+
if (toKeys[to]) {
|
|
1652
|
+
throw new Error(errors_.getASTDuplicatePropertySignatureTransformationErrorMessage(to));
|
|
1653
|
+
}
|
|
1654
|
+
toKeys[to] = true;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* @category guards
|
|
1660
|
+
* @since 3.10.0
|
|
1661
|
+
*/
|
|
1662
|
+
exports.TypeLiteralTransformation = TypeLiteralTransformation;
|
|
1663
|
+
const isTypeLiteralTransformation = exports.isTypeLiteralTransformation = /*#__PURE__*/createTransformationGuard("TypeLiteralTransformation");
|
|
1664
|
+
// -------------------------------------------------------------------------------------
|
|
1665
|
+
// API
|
|
1666
|
+
// -------------------------------------------------------------------------------------
|
|
1667
|
+
/**
|
|
1668
|
+
* Merges a set of new annotations with existing ones, potentially overwriting
|
|
1669
|
+
* any duplicates.
|
|
1670
|
+
*
|
|
1671
|
+
* @since 3.10.0
|
|
1672
|
+
*/
|
|
1673
|
+
const annotations = (ast, annotations) => {
|
|
1674
|
+
const d = Object.getOwnPropertyDescriptors(ast);
|
|
1675
|
+
d.annotations.value = {
|
|
1676
|
+
...ast.annotations,
|
|
1677
|
+
...annotations
|
|
1678
|
+
};
|
|
1679
|
+
return Object.create(Object.getPrototypeOf(ast), d);
|
|
1680
|
+
};
|
|
1681
|
+
/**
|
|
1682
|
+
* Equivalent at runtime to the TypeScript type-level `keyof` operator.
|
|
1683
|
+
*
|
|
1684
|
+
* @since 3.10.0
|
|
1685
|
+
*/
|
|
1686
|
+
exports.annotations = annotations;
|
|
1687
|
+
const keyof = ast => Union.unify(_keyof(ast));
|
|
1688
|
+
exports.keyof = keyof;
|
|
1689
|
+
const STRING_KEYWORD_PATTERN = ".*";
|
|
1690
|
+
const NUMBER_KEYWORD_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";
|
|
1691
|
+
/**
|
|
1692
|
+
* @since 3.10.0
|
|
1693
|
+
*/
|
|
1694
|
+
const getTemplateLiteralRegExp = ast => {
|
|
1695
|
+
let pattern = `^${regexp.escape(ast.head)}`;
|
|
1696
|
+
for (const span of ast.spans) {
|
|
1697
|
+
if (isStringKeyword(span.type)) {
|
|
1698
|
+
pattern += STRING_KEYWORD_PATTERN;
|
|
1699
|
+
} else if (isNumberKeyword(span.type)) {
|
|
1700
|
+
pattern += NUMBER_KEYWORD_PATTERN;
|
|
1701
|
+
}
|
|
1702
|
+
pattern += regexp.escape(span.literal);
|
|
1703
|
+
}
|
|
1704
|
+
pattern += "$";
|
|
1705
|
+
return new RegExp(pattern);
|
|
1706
|
+
};
|
|
1707
|
+
/**
|
|
1708
|
+
* @since 3.10.0
|
|
1709
|
+
*/
|
|
1710
|
+
exports.getTemplateLiteralRegExp = getTemplateLiteralRegExp;
|
|
1711
|
+
const getTemplateLiteralCapturingRegExp = ast => {
|
|
1712
|
+
let pattern = `^`;
|
|
1713
|
+
if (ast.head !== "") {
|
|
1714
|
+
pattern += `(${regexp.escape(ast.head)})`;
|
|
1715
|
+
}
|
|
1716
|
+
for (const span of ast.spans) {
|
|
1717
|
+
if (isStringKeyword(span.type)) {
|
|
1718
|
+
pattern += `(${STRING_KEYWORD_PATTERN})`;
|
|
1719
|
+
} else if (isNumberKeyword(span.type)) {
|
|
1720
|
+
pattern += `(${NUMBER_KEYWORD_PATTERN})`;
|
|
1721
|
+
}
|
|
1722
|
+
if (span.literal !== "") {
|
|
1723
|
+
pattern += `(${regexp.escape(span.literal)})`;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
pattern += "$";
|
|
1727
|
+
return new RegExp(pattern);
|
|
1728
|
+
};
|
|
1729
|
+
/**
|
|
1730
|
+
* @since 3.10.0
|
|
1731
|
+
*/
|
|
1732
|
+
exports.getTemplateLiteralCapturingRegExp = getTemplateLiteralCapturingRegExp;
|
|
1733
|
+
const getPropertySignatures = ast => {
|
|
1734
|
+
switch (ast._tag) {
|
|
1735
|
+
case "Declaration":
|
|
1736
|
+
{
|
|
1737
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
1738
|
+
if (Option.isSome(annotation)) {
|
|
1739
|
+
return getPropertySignatures(annotation.value);
|
|
1740
|
+
}
|
|
1741
|
+
break;
|
|
1742
|
+
}
|
|
1743
|
+
case "TypeLiteral":
|
|
1744
|
+
return ast.propertySignatures.slice();
|
|
1745
|
+
case "Suspend":
|
|
1746
|
+
return getPropertySignatures(ast.f());
|
|
1747
|
+
}
|
|
1748
|
+
return getPropertyKeys(ast).map(name => getPropertyKeyIndexedAccess(ast, name));
|
|
1749
|
+
};
|
|
1750
|
+
/** @internal */
|
|
1751
|
+
exports.getPropertySignatures = getPropertySignatures;
|
|
1752
|
+
const getNumberIndexedAccess = ast => {
|
|
1753
|
+
switch (ast._tag) {
|
|
1754
|
+
case "TupleType":
|
|
1755
|
+
{
|
|
1756
|
+
let hasOptional = false;
|
|
1757
|
+
let out = [];
|
|
1758
|
+
for (const e of ast.elements) {
|
|
1759
|
+
if (e.isOptional) {
|
|
1760
|
+
hasOptional = true;
|
|
1761
|
+
}
|
|
1762
|
+
out.push(e.type);
|
|
1763
|
+
}
|
|
1764
|
+
if (hasOptional) {
|
|
1765
|
+
out.push(undefinedKeyword);
|
|
1766
|
+
}
|
|
1767
|
+
out = out.concat(getRestASTs(ast.rest));
|
|
1768
|
+
return Union.make(out);
|
|
1769
|
+
}
|
|
1770
|
+
case "Refinement":
|
|
1771
|
+
return getNumberIndexedAccess(ast.from);
|
|
1772
|
+
case "Union":
|
|
1773
|
+
return Union.make(ast.types.map(getNumberIndexedAccess));
|
|
1774
|
+
case "Suspend":
|
|
1775
|
+
return getNumberIndexedAccess(ast.f());
|
|
1776
|
+
}
|
|
1777
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1778
|
+
};
|
|
1779
|
+
exports.getNumberIndexedAccess = getNumberIndexedAccess;
|
|
1780
|
+
const getTypeLiteralPropertySignature = (ast, name) => {
|
|
1781
|
+
// from property signatures...
|
|
1782
|
+
const ops = Arr.findFirst(ast.propertySignatures, ps => ps.name === name);
|
|
1783
|
+
if (Option.isSome(ops)) {
|
|
1784
|
+
return ops.value;
|
|
1785
|
+
}
|
|
1786
|
+
// from index signatures...
|
|
1787
|
+
if (Predicate.isString(name)) {
|
|
1788
|
+
let out = undefined;
|
|
1789
|
+
for (const is of ast.indexSignatures) {
|
|
1790
|
+
const parameterBase = getParameterBase(is.parameter);
|
|
1791
|
+
switch (parameterBase._tag) {
|
|
1792
|
+
case "TemplateLiteral":
|
|
1793
|
+
{
|
|
1794
|
+
const regex = getTemplateLiteralRegExp(parameterBase);
|
|
1795
|
+
if (regex.test(name)) {
|
|
1796
|
+
return new PropertySignature(name, is.type, false, true);
|
|
1797
|
+
}
|
|
1798
|
+
break;
|
|
1799
|
+
}
|
|
1800
|
+
case "StringKeyword":
|
|
1801
|
+
{
|
|
1802
|
+
if (out === undefined) {
|
|
1803
|
+
out = new PropertySignature(name, is.type, false, true);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
if (out) {
|
|
1809
|
+
return out;
|
|
1810
|
+
}
|
|
1811
|
+
} else if (Predicate.isSymbol(name)) {
|
|
1812
|
+
for (const is of ast.indexSignatures) {
|
|
1813
|
+
const parameterBase = getParameterBase(is.parameter);
|
|
1814
|
+
if (isSymbolKeyword(parameterBase)) {
|
|
1815
|
+
return new PropertySignature(name, is.type, false, true);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
/** @internal */
|
|
1821
|
+
const getPropertyKeyIndexedAccess = (ast, name) => {
|
|
1822
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
1823
|
+
if (Option.isSome(annotation)) {
|
|
1824
|
+
return getPropertyKeyIndexedAccess(annotation.value, name);
|
|
1825
|
+
}
|
|
1826
|
+
switch (ast._tag) {
|
|
1827
|
+
case "TypeLiteral":
|
|
1828
|
+
{
|
|
1829
|
+
const ps = getTypeLiteralPropertySignature(ast, name);
|
|
1830
|
+
if (ps) {
|
|
1831
|
+
return ps;
|
|
1832
|
+
}
|
|
1833
|
+
break;
|
|
1834
|
+
}
|
|
1835
|
+
case "Union":
|
|
1836
|
+
return new PropertySignature(name, Union.make(ast.types.map(ast => getPropertyKeyIndexedAccess(ast, name).type)), false, true);
|
|
1837
|
+
case "Suspend":
|
|
1838
|
+
return getPropertyKeyIndexedAccess(ast.f(), name);
|
|
1839
|
+
case "Refinement":
|
|
1840
|
+
return getPropertyKeyIndexedAccess(ast.from, name);
|
|
1841
|
+
}
|
|
1842
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1843
|
+
};
|
|
1844
|
+
exports.getPropertyKeyIndexedAccess = getPropertyKeyIndexedAccess;
|
|
1845
|
+
const getPropertyKeys = ast => {
|
|
1846
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
1847
|
+
if (Option.isSome(annotation)) {
|
|
1848
|
+
return getPropertyKeys(annotation.value);
|
|
1849
|
+
}
|
|
1850
|
+
switch (ast._tag) {
|
|
1851
|
+
case "TypeLiteral":
|
|
1852
|
+
return ast.propertySignatures.map(ps => ps.name);
|
|
1853
|
+
case "Suspend":
|
|
1854
|
+
return getPropertyKeys(ast.f());
|
|
1855
|
+
case "Union":
|
|
1856
|
+
return ast.types.slice(1).reduce((out, ast) => Arr.intersection(out, getPropertyKeys(ast)), getPropertyKeys(ast.types[0]));
|
|
1857
|
+
case "Transformation":
|
|
1858
|
+
return getPropertyKeys(ast.to);
|
|
1859
|
+
}
|
|
1860
|
+
return [];
|
|
1861
|
+
};
|
|
1862
|
+
/** @internal */
|
|
1863
|
+
const record = (key, value) => {
|
|
1864
|
+
const propertySignatures = [];
|
|
1865
|
+
const indexSignatures = [];
|
|
1866
|
+
const go = key => {
|
|
1867
|
+
switch (key._tag) {
|
|
1868
|
+
case "NeverKeyword":
|
|
1869
|
+
break;
|
|
1870
|
+
case "StringKeyword":
|
|
1871
|
+
case "SymbolKeyword":
|
|
1872
|
+
case "TemplateLiteral":
|
|
1873
|
+
case "Refinement":
|
|
1874
|
+
indexSignatures.push(new IndexSignature(key, value, true));
|
|
1875
|
+
break;
|
|
1876
|
+
case "Literal":
|
|
1877
|
+
if (Predicate.isString(key.literal) || Predicate.isNumber(key.literal)) {
|
|
1878
|
+
propertySignatures.push(new PropertySignature(key.literal, value, false, true));
|
|
1879
|
+
} else {
|
|
1880
|
+
throw new Error(errors_.getASTUnsupportedLiteral(key.literal));
|
|
1881
|
+
}
|
|
1882
|
+
break;
|
|
1883
|
+
case "Enums":
|
|
1884
|
+
{
|
|
1885
|
+
for (const [_, name] of key.enums) {
|
|
1886
|
+
propertySignatures.push(new PropertySignature(name, value, false, true));
|
|
1887
|
+
}
|
|
1888
|
+
break;
|
|
1889
|
+
}
|
|
1890
|
+
case "UniqueSymbol":
|
|
1891
|
+
propertySignatures.push(new PropertySignature(key.symbol, value, false, true));
|
|
1892
|
+
break;
|
|
1893
|
+
case "Union":
|
|
1894
|
+
key.types.forEach(go);
|
|
1895
|
+
break;
|
|
1896
|
+
default:
|
|
1897
|
+
throw new Error(errors_.getASTUnsupportedKeySchema(key));
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
go(key);
|
|
1901
|
+
return {
|
|
1902
|
+
propertySignatures,
|
|
1903
|
+
indexSignatures
|
|
1904
|
+
};
|
|
1905
|
+
};
|
|
1906
|
+
/**
|
|
1907
|
+
* Equivalent at runtime to the built-in TypeScript utility type `Pick`.
|
|
1908
|
+
*
|
|
1909
|
+
* @since 3.10.0
|
|
1910
|
+
*/
|
|
1911
|
+
exports.record = record;
|
|
1912
|
+
const pick = (ast, keys) => {
|
|
1913
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
1914
|
+
if (Option.isSome(annotation)) {
|
|
1915
|
+
return pick(annotation.value, keys);
|
|
1916
|
+
}
|
|
1917
|
+
switch (ast._tag) {
|
|
1918
|
+
case "TypeLiteral":
|
|
1919
|
+
{
|
|
1920
|
+
const pss = [];
|
|
1921
|
+
const names = {};
|
|
1922
|
+
for (const ps of ast.propertySignatures) {
|
|
1923
|
+
names[ps.name] = null;
|
|
1924
|
+
if (keys.includes(ps.name)) {
|
|
1925
|
+
pss.push(ps);
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
for (const key of keys) {
|
|
1929
|
+
if (!(key in names)) {
|
|
1930
|
+
const ps = getTypeLiteralPropertySignature(ast, key);
|
|
1931
|
+
if (ps) {
|
|
1932
|
+
pss.push(ps);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
return new TypeLiteral(pss, []);
|
|
1937
|
+
}
|
|
1938
|
+
case "Union":
|
|
1939
|
+
return new TypeLiteral(keys.map(name => getPropertyKeyIndexedAccess(ast, name)), []);
|
|
1940
|
+
case "Suspend":
|
|
1941
|
+
return pick(ast.f(), keys);
|
|
1942
|
+
case "Refinement":
|
|
1943
|
+
return pick(ast.from, keys);
|
|
1944
|
+
case "Transformation":
|
|
1945
|
+
{
|
|
1946
|
+
switch (ast.transformation._tag) {
|
|
1947
|
+
case "ComposeTransformation":
|
|
1948
|
+
return new Transformation(pick(ast.from, keys), pick(ast.to, keys), composeTransformation);
|
|
1949
|
+
case "TypeLiteralTransformation":
|
|
1950
|
+
{
|
|
1951
|
+
const ts = [];
|
|
1952
|
+
const fromKeys = [];
|
|
1953
|
+
for (const k of keys) {
|
|
1954
|
+
const t = ast.transformation.propertySignatureTransformations.find(t => t.to === k);
|
|
1955
|
+
if (t) {
|
|
1956
|
+
ts.push(t);
|
|
1957
|
+
fromKeys.push(t.from);
|
|
1958
|
+
} else {
|
|
1959
|
+
fromKeys.push(k);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
return Arr.isNonEmptyReadonlyArray(ts) ? new Transformation(pick(ast.from, fromKeys), pick(ast.to, keys), new TypeLiteralTransformation(ts)) : pick(ast.from, fromKeys);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
1968
|
+
};
|
|
1969
|
+
/**
|
|
1970
|
+
* Equivalent at runtime to the built-in TypeScript utility type `Omit`.
|
|
1971
|
+
*
|
|
1972
|
+
* @since 3.10.0
|
|
1973
|
+
*/
|
|
1974
|
+
exports.pick = pick;
|
|
1975
|
+
const omit = (ast, keys) => pick(ast, getPropertyKeys(ast).filter(name => !keys.includes(name)));
|
|
1976
|
+
/** @internal */
|
|
1977
|
+
exports.omit = omit;
|
|
1978
|
+
const orUndefined = ast => Union.make([ast, undefinedKeyword]);
|
|
1979
|
+
/**
|
|
1980
|
+
* Equivalent at runtime to the built-in TypeScript utility type `Partial`.
|
|
1981
|
+
*
|
|
1982
|
+
* @since 3.10.0
|
|
1983
|
+
*/
|
|
1984
|
+
exports.orUndefined = orUndefined;
|
|
1985
|
+
const partial = (ast, options) => {
|
|
1986
|
+
const exact = options?.exact === true;
|
|
1987
|
+
switch (ast._tag) {
|
|
1988
|
+
case "TupleType":
|
|
1989
|
+
return new TupleType(ast.elements.map(e => new OptionalType(exact ? e.type : orUndefined(e.type), true)), Arr.match(ast.rest, {
|
|
1990
|
+
onEmpty: () => ast.rest,
|
|
1991
|
+
onNonEmpty: rest => [new Type(Union.make([...getRestASTs(rest), undefinedKeyword]))]
|
|
1992
|
+
}), ast.isReadonly);
|
|
1993
|
+
case "TypeLiteral":
|
|
1994
|
+
return new TypeLiteral(ast.propertySignatures.map(ps => new PropertySignature(ps.name, exact ? ps.type : orUndefined(ps.type), true, ps.isReadonly, ps.annotations)), ast.indexSignatures.map(is => new IndexSignature(is.parameter, orUndefined(is.type), is.isReadonly)));
|
|
1995
|
+
case "Union":
|
|
1996
|
+
return Union.make(ast.types.map(member => partial(member, options)));
|
|
1997
|
+
case "Suspend":
|
|
1998
|
+
return new Suspend(() => partial(ast.f(), options));
|
|
1999
|
+
case "Declaration":
|
|
2000
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
2001
|
+
case "Refinement":
|
|
2002
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
2003
|
+
case "Transformation":
|
|
2004
|
+
{
|
|
2005
|
+
if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) {
|
|
2006
|
+
return new Transformation(partial(ast.from, options), partial(ast.to, options), ast.transformation);
|
|
2007
|
+
}
|
|
2008
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
return ast;
|
|
2012
|
+
};
|
|
2013
|
+
/**
|
|
2014
|
+
* Equivalent at runtime to the built-in TypeScript utility type `Required`.
|
|
2015
|
+
*
|
|
2016
|
+
* @since 3.10.0
|
|
2017
|
+
*/
|
|
2018
|
+
exports.partial = partial;
|
|
2019
|
+
const required = ast => {
|
|
2020
|
+
switch (ast._tag) {
|
|
2021
|
+
case "TupleType":
|
|
2022
|
+
return new TupleType(ast.elements.map(e => new OptionalType(e.type, false)), ast.rest, ast.isReadonly);
|
|
2023
|
+
case "TypeLiteral":
|
|
2024
|
+
return new TypeLiteral(ast.propertySignatures.map(f => new PropertySignature(f.name, f.type, false, f.isReadonly, f.annotations)), ast.indexSignatures);
|
|
2025
|
+
case "Union":
|
|
2026
|
+
return Union.make(ast.types.map(member => required(member)));
|
|
2027
|
+
case "Suspend":
|
|
2028
|
+
return new Suspend(() => required(ast.f()));
|
|
2029
|
+
case "Declaration":
|
|
2030
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
2031
|
+
case "Refinement":
|
|
2032
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
2033
|
+
case "Transformation":
|
|
2034
|
+
{
|
|
2035
|
+
if (isTypeLiteralTransformation(ast.transformation) && ast.transformation.propertySignatureTransformations.every(isRenamingPropertySignatureTransformation)) {
|
|
2036
|
+
return new Transformation(required(ast.from), required(ast.to), ast.transformation);
|
|
2037
|
+
}
|
|
2038
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
return ast;
|
|
2042
|
+
};
|
|
2043
|
+
/**
|
|
2044
|
+
* Creates a new AST with shallow mutability applied to its properties.
|
|
2045
|
+
*
|
|
2046
|
+
* @param ast - The original AST to make properties mutable (shallowly).
|
|
2047
|
+
*
|
|
2048
|
+
* @since 3.10.0
|
|
2049
|
+
*/
|
|
2050
|
+
exports.required = required;
|
|
2051
|
+
const mutable = ast => {
|
|
2052
|
+
switch (ast._tag) {
|
|
2053
|
+
case "TupleType":
|
|
2054
|
+
return ast.isReadonly === false ? ast : new TupleType(ast.elements, ast.rest, false, ast.annotations);
|
|
2055
|
+
case "TypeLiteral":
|
|
2056
|
+
{
|
|
2057
|
+
const propertySignatures = changeMap(ast.propertySignatures, ps => ps.isReadonly === false ? ps : new PropertySignature(ps.name, ps.type, ps.isOptional, false, ps.annotations));
|
|
2058
|
+
const indexSignatures = changeMap(ast.indexSignatures, is => is.isReadonly === false ? is : new IndexSignature(is.parameter, is.type, false));
|
|
2059
|
+
return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations);
|
|
2060
|
+
}
|
|
2061
|
+
case "Union":
|
|
2062
|
+
{
|
|
2063
|
+
const types = changeMap(ast.types, mutable);
|
|
2064
|
+
return types === ast.types ? ast : Union.make(types, ast.annotations);
|
|
2065
|
+
}
|
|
2066
|
+
case "Suspend":
|
|
2067
|
+
return new Suspend(() => mutable(ast.f()), ast.annotations);
|
|
2068
|
+
case "Refinement":
|
|
2069
|
+
{
|
|
2070
|
+
const from = mutable(ast.from);
|
|
2071
|
+
return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations);
|
|
2072
|
+
}
|
|
2073
|
+
case "Transformation":
|
|
2074
|
+
{
|
|
2075
|
+
const from = mutable(ast.from);
|
|
2076
|
+
const to = mutable(ast.to);
|
|
2077
|
+
return from === ast.from && to === ast.to ? ast : new Transformation(from, to, ast.transformation, ast.annotations);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
return ast;
|
|
2081
|
+
};
|
|
2082
|
+
/**
|
|
2083
|
+
* @since 3.10.0
|
|
2084
|
+
*/
|
|
2085
|
+
exports.mutable = mutable;
|
|
2086
|
+
const getCompiler = match => {
|
|
2087
|
+
const compile = (ast, path) => match[ast._tag](ast, compile, path);
|
|
2088
|
+
return compile;
|
|
2089
|
+
};
|
|
2090
|
+
/**
|
|
2091
|
+
* @since 3.10.0
|
|
2092
|
+
*/
|
|
2093
|
+
exports.getCompiler = getCompiler;
|
|
2094
|
+
const typeAST = ast => {
|
|
2095
|
+
switch (ast._tag) {
|
|
2096
|
+
case "Declaration":
|
|
2097
|
+
{
|
|
2098
|
+
const typeParameters = changeMap(ast.typeParameters, typeAST);
|
|
2099
|
+
return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations);
|
|
2100
|
+
}
|
|
2101
|
+
case "TupleType":
|
|
2102
|
+
{
|
|
2103
|
+
const elements = changeMap(ast.elements, e => {
|
|
2104
|
+
const type = typeAST(e.type);
|
|
2105
|
+
return type === e.type ? e : new OptionalType(type, e.isOptional);
|
|
2106
|
+
});
|
|
2107
|
+
const restASTs = getRestASTs(ast.rest);
|
|
2108
|
+
const rest = changeMap(restASTs, typeAST);
|
|
2109
|
+
return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map(type => new Type(type)), ast.isReadonly, ast.annotations);
|
|
2110
|
+
}
|
|
2111
|
+
case "TypeLiteral":
|
|
2112
|
+
{
|
|
2113
|
+
const propertySignatures = changeMap(ast.propertySignatures, p => {
|
|
2114
|
+
const type = typeAST(p.type);
|
|
2115
|
+
return type === p.type ? p : new PropertySignature(p.name, type, p.isOptional, p.isReadonly);
|
|
2116
|
+
});
|
|
2117
|
+
const indexSignatures = changeMap(ast.indexSignatures, is => {
|
|
2118
|
+
const type = typeAST(is.type);
|
|
2119
|
+
return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly);
|
|
2120
|
+
});
|
|
2121
|
+
return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, ast.annotations);
|
|
2122
|
+
}
|
|
2123
|
+
case "Union":
|
|
2124
|
+
{
|
|
2125
|
+
const types = changeMap(ast.types, typeAST);
|
|
2126
|
+
return types === ast.types ? ast : Union.make(types, ast.annotations);
|
|
2127
|
+
}
|
|
2128
|
+
case "Suspend":
|
|
2129
|
+
return new Suspend(() => typeAST(ast.f()), ast.annotations);
|
|
2130
|
+
case "Refinement":
|
|
2131
|
+
{
|
|
2132
|
+
const from = typeAST(ast.from);
|
|
2133
|
+
return from === ast.from ? ast : new Refinement(from, ast.filter, ast.annotations);
|
|
2134
|
+
}
|
|
2135
|
+
case "Transformation":
|
|
2136
|
+
return typeAST(ast.to);
|
|
2137
|
+
}
|
|
2138
|
+
return ast;
|
|
2139
|
+
};
|
|
2140
|
+
/** @internal */
|
|
2141
|
+
exports.typeAST = typeAST;
|
|
2142
|
+
const whiteListAnnotations = annotationIds => annotated => {
|
|
2143
|
+
let out = undefined;
|
|
2144
|
+
for (const id of annotationIds) {
|
|
2145
|
+
if (Object.prototype.hasOwnProperty.call(annotated.annotations, id)) {
|
|
2146
|
+
if (out === undefined) {
|
|
2147
|
+
out = {};
|
|
2148
|
+
}
|
|
2149
|
+
out[id] = annotated.annotations[id];
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
return out;
|
|
2153
|
+
};
|
|
2154
|
+
/** @internal */
|
|
2155
|
+
exports.whiteListAnnotations = whiteListAnnotations;
|
|
2156
|
+
const blackListAnnotations = annotationIds => annotated => {
|
|
2157
|
+
const out = {
|
|
2158
|
+
...annotated.annotations
|
|
2159
|
+
};
|
|
2160
|
+
for (const id of annotationIds) {
|
|
2161
|
+
delete out[id];
|
|
2162
|
+
}
|
|
2163
|
+
return out;
|
|
2164
|
+
};
|
|
2165
|
+
// To generate a JSON Schema from a recursive schema, an `identifier` annotation
|
|
2166
|
+
// is required. So, when we calculate the encodedAST, we need to preserve the
|
|
2167
|
+
// annotation in the form of an internal custom annotation that acts as a
|
|
2168
|
+
// surrogate for the identifier, which the JSON Schema compiler can then read.
|
|
2169
|
+
exports.blackListAnnotations = blackListAnnotations;
|
|
2170
|
+
const createJSONIdentifierAnnotation = annotated => Option.match(getJSONIdentifier(annotated), {
|
|
2171
|
+
onNone: () => undefined,
|
|
2172
|
+
onSome: identifier => ({
|
|
2173
|
+
[JSONIdentifierAnnotationId]: identifier
|
|
2174
|
+
})
|
|
2175
|
+
});
|
|
2176
|
+
function changeMap(as, f) {
|
|
2177
|
+
let changed = false;
|
|
2178
|
+
const out = Arr.allocate(as.length);
|
|
2179
|
+
for (let i = 0; i < as.length; i++) {
|
|
2180
|
+
const a = as[i];
|
|
2181
|
+
const fa = f(a);
|
|
2182
|
+
if (fa !== a) {
|
|
2183
|
+
changed = true;
|
|
2184
|
+
}
|
|
2185
|
+
out[i] = fa;
|
|
2186
|
+
}
|
|
2187
|
+
return changed ? out : as;
|
|
2188
|
+
}
|
|
2189
|
+
const encodedAST_ = (ast, isBound) => {
|
|
2190
|
+
switch (ast._tag) {
|
|
2191
|
+
case "Declaration":
|
|
2192
|
+
{
|
|
2193
|
+
const typeParameters = changeMap(ast.typeParameters, ast => encodedAST_(ast, isBound));
|
|
2194
|
+
return typeParameters === ast.typeParameters ? ast : new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown, ast.annotations);
|
|
2195
|
+
}
|
|
2196
|
+
case "TupleType":
|
|
2197
|
+
{
|
|
2198
|
+
const elements = changeMap(ast.elements, e => {
|
|
2199
|
+
const type = encodedAST_(e.type, isBound);
|
|
2200
|
+
return type === e.type ? e : new OptionalType(type, e.isOptional);
|
|
2201
|
+
});
|
|
2202
|
+
const restASTs = getRestASTs(ast.rest);
|
|
2203
|
+
const rest = changeMap(restASTs, ast => encodedAST_(ast, isBound));
|
|
2204
|
+
return elements === ast.elements && rest === restASTs ? ast : new TupleType(elements, rest.map(ast => new Type(ast)), ast.isReadonly, createJSONIdentifierAnnotation(ast));
|
|
2205
|
+
}
|
|
2206
|
+
case "TypeLiteral":
|
|
2207
|
+
{
|
|
2208
|
+
const propertySignatures = changeMap(ast.propertySignatures, ps => {
|
|
2209
|
+
const type = encodedAST_(ps.type, isBound);
|
|
2210
|
+
return type === ps.type ? ps : new PropertySignature(ps.name, type, ps.isOptional, ps.isReadonly);
|
|
2211
|
+
});
|
|
2212
|
+
const indexSignatures = changeMap(ast.indexSignatures, is => {
|
|
2213
|
+
const type = encodedAST_(is.type, isBound);
|
|
2214
|
+
return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly);
|
|
2215
|
+
});
|
|
2216
|
+
return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ? ast : new TypeLiteral(propertySignatures, indexSignatures, createJSONIdentifierAnnotation(ast));
|
|
2217
|
+
}
|
|
2218
|
+
case "Union":
|
|
2219
|
+
{
|
|
2220
|
+
const types = changeMap(ast.types, ast => encodedAST_(ast, isBound));
|
|
2221
|
+
return types === ast.types ? ast : Union.make(types, createJSONIdentifierAnnotation(ast));
|
|
2222
|
+
}
|
|
2223
|
+
case "Suspend":
|
|
2224
|
+
return new Suspend(() => encodedAST_(ast.f(), isBound), createJSONIdentifierAnnotation(ast));
|
|
2225
|
+
case "Refinement":
|
|
2226
|
+
{
|
|
2227
|
+
const from = encodedAST_(ast.from, isBound);
|
|
2228
|
+
if (isBound) {
|
|
2229
|
+
if (from === ast.from) {
|
|
2230
|
+
return ast;
|
|
2231
|
+
}
|
|
2232
|
+
if (!isTransformation(ast.from) && hasStableFilter(ast)) {
|
|
2233
|
+
return new Refinement(from, ast.filter);
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
return from;
|
|
2237
|
+
}
|
|
2238
|
+
case "Transformation":
|
|
2239
|
+
return encodedAST_(ast.from, isBound);
|
|
2240
|
+
}
|
|
2241
|
+
return ast;
|
|
2242
|
+
};
|
|
2243
|
+
/**
|
|
2244
|
+
* @since 3.10.0
|
|
2245
|
+
*/
|
|
2246
|
+
const encodedAST = ast => encodedAST_(ast, false);
|
|
2247
|
+
/**
|
|
2248
|
+
* @since 3.10.0
|
|
2249
|
+
*/
|
|
2250
|
+
exports.encodedAST = encodedAST;
|
|
2251
|
+
const encodedBoundAST = ast => encodedAST_(ast, true);
|
|
2252
|
+
exports.encodedBoundAST = encodedBoundAST;
|
|
2253
|
+
const toJSONAnnotations = annotations => {
|
|
2254
|
+
const out = {};
|
|
2255
|
+
for (const k of Object.getOwnPropertySymbols(annotations)) {
|
|
2256
|
+
out[String(k)] = annotations[k];
|
|
2257
|
+
}
|
|
2258
|
+
return out;
|
|
2259
|
+
};
|
|
2260
|
+
/** @internal */
|
|
2261
|
+
const getParameterBase = ast => {
|
|
2262
|
+
switch (ast._tag) {
|
|
2263
|
+
case "StringKeyword":
|
|
2264
|
+
case "SymbolKeyword":
|
|
2265
|
+
case "TemplateLiteral":
|
|
2266
|
+
return ast;
|
|
2267
|
+
case "Refinement":
|
|
2268
|
+
return getParameterBase(ast.from);
|
|
2269
|
+
}
|
|
2270
|
+
};
|
|
2271
|
+
exports.getParameterBase = getParameterBase;
|
|
2272
|
+
const equalsTemplateLiteralSpan = /*#__PURE__*/Arr.getEquivalence((self, that) => self.type._tag === that.type._tag && self.literal === that.literal);
|
|
2273
|
+
const equalsEnums = /*#__PURE__*/Arr.getEquivalence((self, that) => that[0] === self[0] && that[1] === self[1]);
|
|
2274
|
+
const equals = (self, that) => {
|
|
2275
|
+
switch (self._tag) {
|
|
2276
|
+
case "Literal":
|
|
2277
|
+
return isLiteral(that) && that.literal === self.literal;
|
|
2278
|
+
case "UniqueSymbol":
|
|
2279
|
+
return isUniqueSymbol(that) && that.symbol === self.symbol;
|
|
2280
|
+
case "UndefinedKeyword":
|
|
2281
|
+
case "VoidKeyword":
|
|
2282
|
+
case "NeverKeyword":
|
|
2283
|
+
case "UnknownKeyword":
|
|
2284
|
+
case "AnyKeyword":
|
|
2285
|
+
case "StringKeyword":
|
|
2286
|
+
case "NumberKeyword":
|
|
2287
|
+
case "BooleanKeyword":
|
|
2288
|
+
case "BigIntKeyword":
|
|
2289
|
+
case "SymbolKeyword":
|
|
2290
|
+
case "ObjectKeyword":
|
|
2291
|
+
return that._tag === self._tag;
|
|
2292
|
+
case "TemplateLiteral":
|
|
2293
|
+
return isTemplateLiteral(that) && that.head === self.head && equalsTemplateLiteralSpan(that.spans, self.spans);
|
|
2294
|
+
case "Enums":
|
|
2295
|
+
return isEnums(that) && equalsEnums(that.enums, self.enums);
|
|
2296
|
+
case "Refinement":
|
|
2297
|
+
case "TupleType":
|
|
2298
|
+
case "TypeLiteral":
|
|
2299
|
+
case "Union":
|
|
2300
|
+
case "Suspend":
|
|
2301
|
+
case "Transformation":
|
|
2302
|
+
case "Declaration":
|
|
2303
|
+
return self === that;
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
const intersection = /*#__PURE__*/Arr.intersectionWith(equals);
|
|
2307
|
+
const _keyof = ast => {
|
|
2308
|
+
switch (ast._tag) {
|
|
2309
|
+
case "Declaration":
|
|
2310
|
+
{
|
|
2311
|
+
const annotation = getSurrogateAnnotation(ast);
|
|
2312
|
+
if (Option.isSome(annotation)) {
|
|
2313
|
+
return _keyof(annotation.value);
|
|
2314
|
+
}
|
|
2315
|
+
break;
|
|
2316
|
+
}
|
|
2317
|
+
case "TypeLiteral":
|
|
2318
|
+
return ast.propertySignatures.map(p => Predicate.isSymbol(p.name) ? new UniqueSymbol(p.name) : new Literal(p.name)).concat(ast.indexSignatures.map(is => getParameterBase(is.parameter)));
|
|
2319
|
+
case "Suspend":
|
|
2320
|
+
return _keyof(ast.f());
|
|
2321
|
+
case "Union":
|
|
2322
|
+
return ast.types.slice(1).reduce((out, ast) => intersection(out, _keyof(ast)), _keyof(ast.types[0]));
|
|
2323
|
+
case "Transformation":
|
|
2324
|
+
return _keyof(ast.to);
|
|
2325
|
+
}
|
|
2326
|
+
throw new Error(errors_.getASTUnsupportedSchema(ast));
|
|
2327
|
+
};
|
|
2328
|
+
/** @internal */
|
|
2329
|
+
const compose = (ab, cd) => new Transformation(ab, cd, composeTransformation);
|
|
2330
|
+
/** @internal */
|
|
2331
|
+
exports.compose = compose;
|
|
2332
|
+
const rename = (ast, mapping) => {
|
|
2333
|
+
switch (ast._tag) {
|
|
2334
|
+
case "TypeLiteral":
|
|
2335
|
+
{
|
|
2336
|
+
const propertySignatureTransformations = [];
|
|
2337
|
+
for (const key of util_.ownKeys(mapping)) {
|
|
2338
|
+
const name = mapping[key];
|
|
2339
|
+
if (name !== undefined) {
|
|
2340
|
+
propertySignatureTransformations.push(new PropertySignatureTransformation(key, name, _Function.identity, _Function.identity));
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
if (propertySignatureTransformations.length === 0) {
|
|
2344
|
+
return ast;
|
|
2345
|
+
}
|
|
2346
|
+
return new Transformation(ast, new TypeLiteral(ast.propertySignatures.map(ps => {
|
|
2347
|
+
const name = mapping[ps.name];
|
|
2348
|
+
return new PropertySignature(name === undefined ? ps.name : name, typeAST(ps.type), ps.isOptional, ps.isReadonly, ps.annotations);
|
|
2349
|
+
}), ast.indexSignatures), new TypeLiteralTransformation(propertySignatureTransformations));
|
|
2350
|
+
}
|
|
2351
|
+
case "Union":
|
|
2352
|
+
return Union.make(ast.types.map(ast => rename(ast, mapping)));
|
|
2353
|
+
case "Suspend":
|
|
2354
|
+
return new Suspend(() => rename(ast.f(), mapping));
|
|
2355
|
+
case "Transformation":
|
|
2356
|
+
return compose(ast, rename(typeAST(ast), mapping));
|
|
2357
|
+
}
|
|
2358
|
+
throw new Error(errors_.getASTUnsupportedRenameSchema(ast));
|
|
2359
|
+
};
|
|
2360
|
+
exports.rename = rename;
|
|
2361
|
+
const formatKeyword = ast => Option.getOrElse(getExpected(ast), () => ast._tag);
|
|
2362
|
+
const getExpected = ast => {
|
|
2363
|
+
return getIdentifierAnnotation(ast).pipe(Option.orElse(() => getTitleAnnotation(ast)), Option.orElse(() => getDescriptionAnnotation(ast)));
|
|
2364
|
+
};
|
|
2365
|
+
//# sourceMappingURL=SchemaAST.js.map
|