effect 4.0.0-beta.50 → 4.0.0-beta.52
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/dist/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +18 -14
- package/dist/BigDecimal.js.map +1 -1
- package/dist/BigInt.d.ts.map +1 -1
- package/dist/BigInt.js +4 -4
- package/dist/BigInt.js.map +1 -1
- package/dist/Brand.d.ts +2 -4
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/Data.js +2 -2
- package/dist/Data.js.map +1 -1
- package/dist/Duration.js +1 -1
- package/dist/Duration.js.map +1 -1
- package/dist/Schema.d.ts +77 -10
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +119 -18
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +6 -0
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +216 -229
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +3 -5
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +3 -2
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.d.ts.map +1 -1
- package/dist/SchemaIssue.js +29 -11
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.js +14 -2
- package/dist/SchemaParser.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +142 -65
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -2
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +37 -0
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +7 -0
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +2 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +2 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cluster/Runners.d.ts.map +1 -1
- package/dist/unstable/cluster/Runners.js +3 -2
- package/dist/unstable/cluster/Runners.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +1 -0
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +6 -6
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.js +9 -8
- package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +6 -5
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +6 -5
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +11 -6
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +5 -6
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +17 -18
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +1 -2
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +28 -8
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +28 -15
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -2
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -10
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +2 -11
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.js +1 -1
- package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
- package/dist/unstable/observability/internal/protobuf.js +4 -4
- package/dist/unstable/observability/internal/protobuf.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.d.ts +11 -0
- package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +14 -9
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/package.json +1 -1
- package/src/BigDecimal.ts +20 -16
- package/src/BigInt.ts +4 -4
- package/src/Brand.ts +2 -4
- package/src/Data.ts +1 -1
- package/src/Duration.ts +1 -1
- package/src/Schema.ts +183 -23
- package/src/SchemaAST.ts +315 -267
- package/src/SchemaGetter.ts +4 -6
- package/src/SchemaIssue.ts +28 -15
- package/src/SchemaParser.ts +8 -2
- package/src/index.ts +3 -0
- package/src/internal/effect.ts +196 -69
- package/src/internal/schema/representation.ts +1 -2
- package/src/internal/schema/schema.ts +43 -0
- package/src/unstable/ai/McpServer.ts +8 -0
- package/src/unstable/cli/index.ts +2 -0
- package/src/unstable/cluster/Runners.ts +8 -5
- package/src/unstable/cluster/SqlMessageStorage.ts +1 -0
- package/src/unstable/cluster/SqlRunnerStorage.ts +12 -6
- package/src/unstable/eventlog/SqlEventJournal.ts +10 -2
- package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +8 -3
- package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +9 -3
- package/src/unstable/httpapi/HttpApi.ts +1 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +13 -6
- package/src/unstable/httpapi/HttpApiClient.ts +5 -6
- package/src/unstable/httpapi/HttpApiEndpoint.ts +6 -7
- package/src/unstable/httpapi/HttpApiError.ts +43 -22
- package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
- package/src/unstable/httpapi/OpenApi.ts +3 -15
- package/src/unstable/observability/OtlpMetrics.ts +1 -1
- package/src/unstable/observability/internal/protobuf.ts +4 -4
- package/src/unstable/rpc/RpcSerialization.ts +41 -36
- package/dist/internal/schema/to-codec.d.ts +0 -2
- package/dist/internal/schema/to-codec.d.ts.map +0 -1
- package/dist/internal/schema/to-codec.js +0 -126
- package/dist/internal/schema/to-codec.js.map +0 -1
- package/src/internal/schema/to-codec.ts +0 -138
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { memoize } from "../../Function.js";
|
|
2
|
-
import * as Predicate from "../../Predicate.js";
|
|
3
|
-
import * as AST from "../../SchemaAST.js";
|
|
4
|
-
import * as InternalSchema from "./schema.js";
|
|
5
|
-
/** @internal */
|
|
6
|
-
export const toCodecJson = /*#__PURE__*/AST.toCodec(ast => {
|
|
7
|
-
const out = toCodecJsonBase(ast);
|
|
8
|
-
if (out !== ast && AST.isOptional(ast)) {
|
|
9
|
-
return AST.optionalKeyLastLink(out);
|
|
10
|
-
}
|
|
11
|
-
return out;
|
|
12
|
-
});
|
|
13
|
-
function toCodecJsonBase(ast) {
|
|
14
|
-
switch (ast._tag) {
|
|
15
|
-
case "Declaration":
|
|
16
|
-
{
|
|
17
|
-
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
|
|
18
|
-
if (Predicate.isFunction(getLink)) {
|
|
19
|
-
const tps = AST.isDeclaration(ast) ? ast.typeParameters.map(tp => InternalSchema.make(AST.toEncoded(tp))) : [];
|
|
20
|
-
const link = getLink(tps);
|
|
21
|
-
const to = toCodecJson(link.to);
|
|
22
|
-
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)]);
|
|
23
|
-
}
|
|
24
|
-
return AST.replaceEncoding(ast, [AST.unknownToNull]);
|
|
25
|
-
}
|
|
26
|
-
case "Unknown":
|
|
27
|
-
case "ObjectKeyword":
|
|
28
|
-
return AST.replaceEncoding(ast, [AST.unknownToJson]);
|
|
29
|
-
case "Undefined":
|
|
30
|
-
case "Void":
|
|
31
|
-
case "Literal":
|
|
32
|
-
case "Number":
|
|
33
|
-
return ast.toCodecJson();
|
|
34
|
-
case "UniqueSymbol":
|
|
35
|
-
case "Symbol":
|
|
36
|
-
case "BigInt":
|
|
37
|
-
return ast.toCodecStringTree();
|
|
38
|
-
case "Objects":
|
|
39
|
-
{
|
|
40
|
-
if (ast.propertySignatures.some(ps => typeof ps.name !== "string")) {
|
|
41
|
-
throw new globalThis.Error("Objects property names must be strings", {
|
|
42
|
-
cause: ast
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return ast.recur(toCodecJson);
|
|
46
|
-
}
|
|
47
|
-
case "Union":
|
|
48
|
-
{
|
|
49
|
-
const sortedTypes = jsonReorder(ast.types);
|
|
50
|
-
if (sortedTypes !== ast.types) {
|
|
51
|
-
return new AST.Union(sortedTypes, ast.mode, ast.annotations, ast.checks, ast.encoding, ast.context).recur(toCodecJson);
|
|
52
|
-
}
|
|
53
|
-
return ast.recur(toCodecJson);
|
|
54
|
-
}
|
|
55
|
-
case "Arrays":
|
|
56
|
-
case "Suspend":
|
|
57
|
-
return ast.recur(toCodecJson);
|
|
58
|
-
}
|
|
59
|
-
// `Schema.Any` is used as an escape hatch
|
|
60
|
-
return ast;
|
|
61
|
-
}
|
|
62
|
-
/** @internal */
|
|
63
|
-
export const jsonReorder = /*#__PURE__*/makeReorder(getJsonPriority);
|
|
64
|
-
function getJsonPriority(ast) {
|
|
65
|
-
switch (ast._tag) {
|
|
66
|
-
case "BigInt":
|
|
67
|
-
case "Symbol":
|
|
68
|
-
case "UniqueSymbol":
|
|
69
|
-
return 0;
|
|
70
|
-
default:
|
|
71
|
-
return 1;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/** @internal */
|
|
75
|
-
export function makeReorder(getPriority) {
|
|
76
|
-
return types => {
|
|
77
|
-
// Create a map of original indices for O(1) lookup
|
|
78
|
-
const indexMap = new Map();
|
|
79
|
-
for (let i = 0; i < types.length; i++) {
|
|
80
|
-
indexMap.set(AST.toEncoded(types[i]), i);
|
|
81
|
-
}
|
|
82
|
-
// Create a sorted copy of the types array
|
|
83
|
-
const sortedTypes = [...types].sort((a, b) => {
|
|
84
|
-
a = AST.toEncoded(a);
|
|
85
|
-
b = AST.toEncoded(b);
|
|
86
|
-
const pa = getPriority(a);
|
|
87
|
-
const pb = getPriority(b);
|
|
88
|
-
if (pa !== pb) return pa - pb;
|
|
89
|
-
// If priorities are equal, maintain original order (stable sort)
|
|
90
|
-
return indexMap.get(a) - indexMap.get(b);
|
|
91
|
-
});
|
|
92
|
-
// Check if order changed by comparing arrays
|
|
93
|
-
const orderChanged = sortedTypes.some((ast, index) => ast !== types[index]);
|
|
94
|
-
if (!orderChanged) return types;
|
|
95
|
-
return sortedTypes;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/** @internal */
|
|
99
|
-
export const toCodecIso = /*#__PURE__*/memoize(ast => {
|
|
100
|
-
const out = toCodecIsoBase(ast);
|
|
101
|
-
if (out !== ast && AST.isOptional(ast)) {
|
|
102
|
-
return AST.optionalKeyLastLink(out);
|
|
103
|
-
}
|
|
104
|
-
return out;
|
|
105
|
-
});
|
|
106
|
-
function toCodecIsoBase(ast) {
|
|
107
|
-
switch (ast._tag) {
|
|
108
|
-
case "Declaration":
|
|
109
|
-
{
|
|
110
|
-
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec;
|
|
111
|
-
if (Predicate.isFunction(getLink)) {
|
|
112
|
-
const link = getLink(ast.typeParameters.map(tp => InternalSchema.make(tp)));
|
|
113
|
-
const to = toCodecIso(link.to);
|
|
114
|
-
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)]);
|
|
115
|
-
}
|
|
116
|
-
return ast;
|
|
117
|
-
}
|
|
118
|
-
case "Arrays":
|
|
119
|
-
case "Objects":
|
|
120
|
-
case "Union":
|
|
121
|
-
case "Suspend":
|
|
122
|
-
return ast.recur(toCodecIso);
|
|
123
|
-
}
|
|
124
|
-
return ast;
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=to-codec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-codec.js","names":["memoize","Predicate","AST","InternalSchema","toCodecJson","toCodec","ast","out","toCodecJsonBase","isOptional","optionalKeyLastLink","_tag","getLink","annotations","isFunction","tps","isDeclaration","typeParameters","map","tp","make","toEncoded","link","to","replaceEncoding","Link","transformation","unknownToNull","unknownToJson","toCodecStringTree","propertySignatures","some","ps","name","globalThis","Error","cause","recur","sortedTypes","jsonReorder","types","Union","mode","checks","encoding","context","makeReorder","getJsonPriority","getPriority","indexMap","Map","i","length","set","sort","a","b","pa","pb","get","orderChanged","index","toCodecIso","toCodecIsoBase"],"sources":["../../../src/internal/schema/to-codec.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,OAAO,KAAKC,SAAS,MAAM,oBAAoB;AAC/C,OAAO,KAAKC,GAAG,MAAM,oBAAoB;AACzC,OAAO,KAAKC,cAAc,MAAM,aAAa;AAE7C;AACA,OAAO,MAAMC,WAAW,gBAAGF,G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,IAAa;EAC1D,MAAMC,GAAG,GAAGwD,cAAc,CAACzD,GAAG,CAAC;EAC/B,IAAIC,GAAG,KAAKD,GAAG,IAAIJ,GAAG,CAACO,UAAU,CAACH,GAAG,CAAC,EAAE;IACtC,OAAOJ,GAAG,CAACQ,mBAAmB,CAACH,GAAG,CAAC;EACrC;EACA,OAAOA,GAAG;AACZ,CAAC,CAAC;AAEF,SAASwD,cAAcA,CAACzD,GAAY;EAClC,QAAQA,GAAG,CAACK,IAAI;IACd,KAAK,aAAa;MAAE;QAClB,MAAMC,OAAO,GAAGN,GAAG,CAACO,WAAW,EAAEiD,UAAU,IAAIxD,GAAG,CAACO,WAAW,EAAER,OAAO;QACvE,IAAIJ,SAAS,CAACa,UAAU,CAACF,OAAO,CAAC,EAAE;UACjC,MAAMU,IAAI,GAAGV,OAAO,CAACN,GAAG,CAACW,cAAc,CAACC,GAAG,CAAEC,EAAE,IAAKhB,cAAc,CAACiB,IAAI,CAACD,EAAE,CAAC,CAAC,CAAC;UAC7E,MAAMI,EAAE,GAAGuC,UAAU,CAACxC,IAAI,CAACC,EAAE,CAAC;UAC9B,OAAOrB,GAAG,CAACsB,eAAe,CAAClB,GAAG,EAAEiB,EAAE,KAAKD,IAAI,CAACC,EAAE,GAAG,CAACD,IAAI,CAAC,GAAG,CAAC,IAAIpB,GAAG,CAACuB,IAAI,CAACF,EAAE,EAAED,IAAI,CAACI,cAAc,CAAC,CAAC,CAAC;QACpG;QACA,OAAOpB,GAAG;MACZ;IACA,KAAK,QAAQ;IACb,KAAK,SAAS;IACd,KAAK,OAAO;IACZ,KAAK,SAAS;MACZ,OAAOA,GAAG,CAAC+B,KAAK,CAACyB,UAAU,CAAC;EAChC;EACA,OAAOxD,GAAG;AACZ","ignoreList":[]}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { memoize } from "../../Function.ts"
|
|
2
|
-
import * as Predicate from "../../Predicate.ts"
|
|
3
|
-
import * as AST from "../../SchemaAST.ts"
|
|
4
|
-
import * as InternalSchema from "./schema.ts"
|
|
5
|
-
|
|
6
|
-
/** @internal */
|
|
7
|
-
export const toCodecJson = AST.toCodec((ast) => {
|
|
8
|
-
const out = toCodecJsonBase(ast)
|
|
9
|
-
if (out !== ast && AST.isOptional(ast)) {
|
|
10
|
-
return AST.optionalKeyLastLink(out)
|
|
11
|
-
}
|
|
12
|
-
return out
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
function toCodecJsonBase(ast: AST.AST): AST.AST {
|
|
16
|
-
switch (ast._tag) {
|
|
17
|
-
case "Declaration": {
|
|
18
|
-
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
|
|
19
|
-
if (Predicate.isFunction(getLink)) {
|
|
20
|
-
const tps = AST.isDeclaration(ast)
|
|
21
|
-
? ast.typeParameters.map((tp) => InternalSchema.make(AST.toEncoded(tp)))
|
|
22
|
-
: []
|
|
23
|
-
const link = getLink(tps)
|
|
24
|
-
const to = toCodecJson(link.to)
|
|
25
|
-
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)])
|
|
26
|
-
}
|
|
27
|
-
return AST.replaceEncoding(ast, [AST.unknownToNull])
|
|
28
|
-
}
|
|
29
|
-
case "Unknown":
|
|
30
|
-
case "ObjectKeyword":
|
|
31
|
-
return AST.replaceEncoding(ast, [AST.unknownToJson])
|
|
32
|
-
case "Undefined":
|
|
33
|
-
case "Void":
|
|
34
|
-
case "Literal":
|
|
35
|
-
case "Number":
|
|
36
|
-
return ast.toCodecJson()
|
|
37
|
-
case "UniqueSymbol":
|
|
38
|
-
case "Symbol":
|
|
39
|
-
case "BigInt":
|
|
40
|
-
return ast.toCodecStringTree()
|
|
41
|
-
case "Objects": {
|
|
42
|
-
if (ast.propertySignatures.some((ps) => typeof ps.name !== "string")) {
|
|
43
|
-
throw new globalThis.Error("Objects property names must be strings", { cause: ast })
|
|
44
|
-
}
|
|
45
|
-
return ast.recur(toCodecJson)
|
|
46
|
-
}
|
|
47
|
-
case "Union": {
|
|
48
|
-
const sortedTypes = jsonReorder(ast.types)
|
|
49
|
-
if (sortedTypes !== ast.types) {
|
|
50
|
-
return new AST.Union(
|
|
51
|
-
sortedTypes,
|
|
52
|
-
ast.mode,
|
|
53
|
-
ast.annotations,
|
|
54
|
-
ast.checks,
|
|
55
|
-
ast.encoding,
|
|
56
|
-
ast.context
|
|
57
|
-
).recur(toCodecJson)
|
|
58
|
-
}
|
|
59
|
-
return ast.recur(toCodecJson)
|
|
60
|
-
}
|
|
61
|
-
case "Arrays":
|
|
62
|
-
case "Suspend":
|
|
63
|
-
return ast.recur(toCodecJson)
|
|
64
|
-
}
|
|
65
|
-
// `Schema.Any` is used as an escape hatch
|
|
66
|
-
return ast
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** @internal */
|
|
70
|
-
export const jsonReorder = makeReorder(getJsonPriority)
|
|
71
|
-
|
|
72
|
-
function getJsonPriority(ast: AST.AST): number {
|
|
73
|
-
switch (ast._tag) {
|
|
74
|
-
case "BigInt":
|
|
75
|
-
case "Symbol":
|
|
76
|
-
case "UniqueSymbol":
|
|
77
|
-
return 0
|
|
78
|
-
default:
|
|
79
|
-
return 1
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** @internal */
|
|
84
|
-
export function makeReorder(getPriority: (ast: AST.AST) => number) {
|
|
85
|
-
return (types: ReadonlyArray<AST.AST>): ReadonlyArray<AST.AST> => {
|
|
86
|
-
// Create a map of original indices for O(1) lookup
|
|
87
|
-
const indexMap = new Map<AST.AST, number>()
|
|
88
|
-
for (let i = 0; i < types.length; i++) {
|
|
89
|
-
indexMap.set(AST.toEncoded(types[i]), i)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Create a sorted copy of the types array
|
|
93
|
-
const sortedTypes = [...types].sort((a, b) => {
|
|
94
|
-
a = AST.toEncoded(a)
|
|
95
|
-
b = AST.toEncoded(b)
|
|
96
|
-
const pa = getPriority(a)
|
|
97
|
-
const pb = getPriority(b)
|
|
98
|
-
if (pa !== pb) return pa - pb
|
|
99
|
-
// If priorities are equal, maintain original order (stable sort)
|
|
100
|
-
return indexMap.get(a)! - indexMap.get(b)!
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
// Check if order changed by comparing arrays
|
|
104
|
-
const orderChanged = sortedTypes.some((ast, index) => ast !== types[index])
|
|
105
|
-
|
|
106
|
-
if (!orderChanged) return types
|
|
107
|
-
return sortedTypes
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** @internal */
|
|
112
|
-
export const toCodecIso = memoize((ast: AST.AST): AST.AST => {
|
|
113
|
-
const out = toCodecIsoBase(ast)
|
|
114
|
-
if (out !== ast && AST.isOptional(ast)) {
|
|
115
|
-
return AST.optionalKeyLastLink(out)
|
|
116
|
-
}
|
|
117
|
-
return out
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
function toCodecIsoBase(ast: AST.AST): AST.AST {
|
|
121
|
-
switch (ast._tag) {
|
|
122
|
-
case "Declaration": {
|
|
123
|
-
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec
|
|
124
|
-
if (Predicate.isFunction(getLink)) {
|
|
125
|
-
const link = getLink(ast.typeParameters.map((tp) => InternalSchema.make(tp)))
|
|
126
|
-
const to = toCodecIso(link.to)
|
|
127
|
-
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)])
|
|
128
|
-
}
|
|
129
|
-
return ast
|
|
130
|
-
}
|
|
131
|
-
case "Arrays":
|
|
132
|
-
case "Objects":
|
|
133
|
-
case "Union":
|
|
134
|
-
case "Suspend":
|
|
135
|
-
return ast.recur(toCodecIso)
|
|
136
|
-
}
|
|
137
|
-
return ast
|
|
138
|
-
}
|