ballerina-core 1.0.192 → 1.0.193

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ballerina-core",
3
3
  "author": "Dr. Giuseppe Maggiore",
4
4
  "private": false,
5
- "version": "1.0.192",
5
+ "version": "1.0.193",
6
6
  "main": "main.ts",
7
7
  "scripts": {
8
8
  "prettier": "prettier --write ."
@@ -1324,30 +1324,15 @@ export const dispatchFromAPIRawValue =
1324
1324
  )}`,
1325
1325
  );
1326
1326
 
1327
- if (caseType.kind != "record" && caseType.kind != "lookup")
1328
- return ValueOrErrors.Default.throwOne(
1329
- `union case ${
1330
- result.caseName
1331
- } expected record or lookup type, got ${JSON.stringify(caseType)}`,
1332
- );
1333
-
1334
1327
  return dispatchFromAPIRawValue(
1335
1328
  caseType,
1336
1329
  types,
1337
1330
  converters,
1338
1331
  injectedPrimitives,
1339
1332
  )(result.fields).Then((value) =>
1340
- PredicateValue.Operations.IsRecord(value)
1341
- ? ValueOrErrors.Default.return(
1342
- PredicateValue.Default.unionCase(result.caseName, value),
1343
- )
1344
- : ValueOrErrors.Default.throwOne(
1345
- `union case ${
1346
- result.caseName
1347
- } expected record, got ${PredicateValue.Operations.GetKind(
1348
- value,
1349
- )}`,
1350
- ),
1333
+ ValueOrErrors.Default.return(
1334
+ PredicateValue.Default.unionCase(result.caseName, value),
1335
+ ),
1351
1336
  );
1352
1337
  }
1353
1338
 
@@ -191,6 +191,8 @@ export const SerializedType = {
191
191
  SerializedType.isApplication(_) &&
192
192
  _.fun == "ReadOnly" &&
193
193
  _.args.length == 1,
194
+ isRecordFields: (_: unknown) =>
195
+ typeof _ == "object" && _ != null && !("fun" in _) && !("args" in _),
194
196
  };
195
197
 
196
198
  export type StringSerializedType = string;
@@ -1042,41 +1044,25 @@ export const DispatchParsedType = {
1042
1044
  return ValueOrErrors.Operations.All(
1043
1045
  List<ValueOrErrors<[string, DispatchParsedType<T>], string>>(
1044
1046
  rawType.args.map((unionCase) =>
1045
- typeof unionCase.fields == "string" // lookup case
1046
- ? serializedTypes[unionCase.fields] == undefined // probably dont need this
1047
- ? ValueOrErrors.Default.throwOne(
1048
- `Cannot find union case type: ${JSON.stringify(
1049
- unionCase.fields,
1050
- )} in types`,
1051
- )
1052
- : DispatchParsedType.Operations.ParseRawType(
1053
- `Union:Case ${unionCase.caseName}`,
1054
- unionCase.fields,
1055
- typeNames,
1056
- serializedTypes,
1057
- alreadyParsedTypes,
1058
- injectedPrimitives,
1059
- ).Then((parsedType) =>
1060
- ValueOrErrors.Default.return([
1061
- unionCase.caseName,
1062
- parsedType[0],
1063
- ]),
1064
- )
1065
- : DispatchParsedType.Operations.ParseRawType(
1066
- `Union:Case ${unionCase.caseName}`,
1067
- unionCase.fields == undefined
1068
- ? { fields: {} }
1069
- : unionCase,
1070
- typeNames,
1071
- serializedTypes,
1072
- alreadyParsedTypes,
1073
- injectedPrimitives,
1074
- ).Then((parsedType) =>
1075
- ValueOrErrors.Default.return([
1076
- unionCase.caseName,
1077
- parsedType[0],
1078
- ]),
1079
- ),
1047
+ DispatchParsedType.Operations.ParseRawType(
1048
+ `Union:Case ${unionCase.caseName}`,
1049
+ unionCase.fields == undefined
1050
+ ? { fields: {} }
1051
+ : // we allow the record fields to be defined directly in the spec instead of
1052
+ // inside a fields key
1053
+ SerializedType.isRecordFields(unionCase.fields)
1054
+ ? { fields: unionCase.fields }
1055
+ : unionCase.fields,
1056
+ typeNames,
1057
+ serializedTypes,
1058
+ alreadyParsedTypes,
1059
+ injectedPrimitives,
1060
+ ).Then((parsedType) =>
1061
+ ValueOrErrors.Default.return([
1062
+ unionCase.caseName,
1063
+ parsedType[0],
1064
+ ]),
1065
+ ),
1080
1066
  ),
1081
1067
  ),
1082
1068
  ).Then((parsedUnionCases) =>
@@ -425,7 +425,7 @@ export const PredicateValue = {
425
425
  kind: "record",
426
426
  fields,
427
427
  }),
428
- unionCase: (caseName: string, fields: ValueRecord): ValueUnionCase => ({
428
+ unionCase: (caseName: string, fields: PredicateValue): ValueUnionCase => ({
429
429
  kind: "unionCase",
430
430
  caseName,
431
431
  fields,